Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: 🛝 Playground #442

Draft
wants to merge 116 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
fce5d2f
Embedded scaffolding wip
stephlow Jan 13, 2025
5be17ca
Modify gitignore for a sec
brettimus Jan 13, 2025
2390651
Add playground folder to monorepo
brettimus Jan 13, 2025
b15084f
Use port 6660 for playground vite server
brettimus Jan 13, 2025
5c99caa
unify the playground into the monorepo setup
keturiosakys Jan 13, 2025
889f539
update react to 19 cause why not
keturiosakys Jan 13, 2025
991a072
Start playing with colors
brettimus Jan 13, 2025
ae6327c
Format
brettimus Jan 13, 2025
9fb9156
set up tanstack router and port the current app to it
keturiosakys Jan 13, 2025
24a265e
stuff
keturiosakys Jan 13, 2025
c1b015a
Rewrite embedded implementation to a middleware handler
stephlow Jan 13, 2025
da476aa
add mount path correction
keturiosakys Jan 13, 2025
f1308fe
Factor out playground component and navigation
brettimus Jan 13, 2025
2079b75
Scaffold the request and response viewer stuff
brettimus Jan 13, 2025
31a5a03
Merge branch 'embedded' into embedded-playground
stephlow Jan 14, 2025
40b64ca
Playground as an embedded app
stephlow Jan 14, 2025
8f306a0
Tidy index.css and run formatter
brettimus Jan 14, 2025
319bf18
Add theme switcher
brettimus Jan 14, 2025
83ce49b
Default to system theme
brettimus Jan 14, 2025
bb13d45
Add CDN support for embedded asset loading
stephlow Jan 14, 2025
18387a2
Add playground dist to the repo
stephlow Jan 14, 2025
b0bc527
Use js deliver cdn for api for now
stephlow Jan 14, 2025
32913bf
Merge remote-tracking branch 'origin/playground' into embedded-playgr…
stephlow Jan 14, 2025
f9fd352
Merge branch 'main' into playground
brettimus Jan 15, 2025
a969114
Update root biome config for playground stuff
brettimus Jan 15, 2025
437bd67
Basic routing setup for embedded
stephlow Jan 15, 2025
e6991a9
Embedded <-> Playground (#424)
stephlow Jan 15, 2025
3a44354
Scaffolding for services
stephlow Jan 15, 2025
907bc57
Garbage part i (SQUASHME)
brettimus Jan 15, 2025
9531b6f
First pass at importing spec
brettimus Jan 16, 2025
6333bd1
Implement settings
brettimus Jan 16, 2025
de4f05f
Build playground
brettimus Jan 16, 2025
88f75c8
Modify API for testing
brettimus Jan 16, 2025
9a55f3b
Update embedded for publishing
brettimus Jan 16, 2025
aa8b526
Update package.json
brettimus Jan 16, 2025
d465a18
Fixing publish
brettimus Jan 16, 2025
1197ae2
One more publishing tweak
brettimus Jan 16, 2025
b4b2adc
Fix options
brettimus Jan 16, 2025
86aa660
Remove nodejs support
brettimus Jan 16, 2025
000c389
Pass through the spec
brettimus Jan 16, 2025
ba69d5f
Remove console.logs
brettimus Jan 16, 2025
4dde98f
Fix favicon
brettimus Jan 16, 2025
aa51666
Make the docs tab work better
brettimus Jan 16, 2025
5cebcd1
Update build
brettimus Jan 16, 2025
bf23d23
Add pragmas to make fp embed work inside our fp api
brettimus Jan 16, 2025
340b678
Publish playground with embed
brettimus Jan 16, 2025
7e0475b
Remove prepublish because it destroys things we need
brettimus Jan 16, 2025
14cf7a1
Merge branch 'main' into playground
brettimus Jan 16, 2025
b41ff5a
Downgrade react because of version mismatch between @fiberplane/hooks…
brettimus Jan 17, 2025
44ffc47
Change mock server default host to fix CORS issues
brettimus Jan 17, 2025
df002c3
Add styles for the StatusCode component
brettimus Jan 17, 2025
4c923df
Tweak some styles that were a little aggressive given our accent color
brettimus Jan 17, 2025
732be6d
Merge remote-tracking branch 'origin/main' into embedded-playground-api
stephlow Jan 17, 2025
2bf0fdf
Add theme switching
brettimus Jan 17, 2025
4f6e454
Persist settings to local storage and fix bg-emphasis-dark
brettimus Jan 17, 2025
5a84e3d
Update playground dist
brettimus Jan 17, 2025
c727342
Add hono as a peer dep?
brettimus Jan 17, 2025
518ac82
Tweak styles on the json viewer
brettimus Jan 17, 2025
c6d7b0a
Update json editor styles
brettimus Jan 17, 2025
e0c8dc9
Bump embedded p.json
brettimus Jan 17, 2025
ad88a99
WIP
stephlow Jan 17, 2025
95a7a7d
Merge remote-tracking branch 'origin/main' into embedded-playground-api
stephlow Jan 17, 2025
ab5bc71
Check in playground dist
brettimus Jan 17, 2025
109ea1c
Update lilo-worker
brettimus Jan 17, 2025
d66b021
Add origin of request as toplevel server
brettimus Jan 17, 2025
84d1e73
Update embedded for lilo
brettimus Jan 17, 2025
472e12a
Update
brettimus Jan 17, 2025
5cf6ce2
Service implementation scaffolding
stephlow Jan 17, 2025
663ae7f
Simplify lilo fp embed
brettimus Jan 17, 2025
1951d75
Ignore playground dist again
brettimus Jan 17, 2025
90d9c7b
Default cdn url for embedded
brettimus Jan 17, 2025
e120b1f
Try something
brettimus Jan 17, 2025
2336b1b
Remove fp-status* classes and use semantic token
brettimus Jan 18, 2025
ec841b1
Simplify colors in use for http methods
brettimus Jan 18, 2025
9be1da8
Format
brettimus Jan 18, 2025
8e7edff
Small tweak
brettimus Jan 18, 2025
f756226
Add geist font
brettimus Jan 18, 2025
a40e5ef
Change default tooltip styles to use white bg instead of primary
brettimus Jan 18, 2025
375b404
Faker first pass and json text editing style updates
brettimus Jan 20, 2025
4d999b6
Add tightknit api spec for testing
brettimus Jan 20, 2025
3917ce0
Update version p.json for embedded
brettimus Jan 20, 2025
63ae84c
Test 0.0.15
brettimus Jan 20, 2025
e17728f
Update embedded in lilo
brettimus Jan 20, 2025
63ba3f8
Services client and temp embedded api routes
stephlow Jan 20, 2025
13191d4
Fix base service exports
stephlow Jan 20, 2025
9dc2502
Fix sidepaneltrigger tooltip styles
brettimus Jan 20, 2025
e4d9561
Style tweaks: Sidebar tooltip, Faker button, tab font weight
brettimus Jan 20, 2025
7bc2383
Add keyboard shortcut to faker
brettimus Jan 20, 2025
a2ecb8d
Fix dark mode json editing styles
brettimus Jan 20, 2025
55a082e
Format
brettimus Jan 20, 2025
01a1ba2
Modify docs tab title styles
brettimus Jan 21, 2025
49074a2
Implement simons more recent docs designs
brettimus Jan 21, 2025
99b9cd6
Update lilo worker snippets
brettimus Jan 21, 2025
9b515b3
Remove cl
brettimus Jan 21, 2025
049e15f
Default to window.location.origin if no servers present
brettimus Jan 21, 2025
b45d8f3
Print warning message if there is an unretryable error in the DOM
brettimus Jan 21, 2025
add16ef
Add some terrible code for clearer error messages to end user when sp…
brettimus Jan 21, 2025
9dd67ce
Merge remote-tracking branch 'origin/playground' into embedded-playgr…
stephlow Jan 21, 2025
aac7903
Merge remote-tracking branch 'origin/playground' into embedded-playgr…
stephlow Jan 21, 2025
121bd02
Specify zod dep
stephlow Jan 21, 2025
b8a8f90
Remove playground dist from scm
stephlow Jan 21, 2025
dac2a8d
Refactor DOM parsing stuff
brettimus Jan 21, 2025
6a413ed
Improve command bar command matching
brettimus Jan 21, 2025
04d5416
Fix merge conflict feedback
stephlow Jan 21, 2025
c72a3f6
Merge branch 'embedded-playground-api' into playground
brettimus Jan 21, 2025
d03e6c6
Refactor routeDocumentation rendering and improve handling of e.g., a…
brettimus Jan 21, 2025
11eec0b
Move zod from peer deps to deps for embedded package
brettimus Jan 21, 2025
749426a
Improve handling of objects and arrays of objects
brettimus Jan 21, 2025
03bb96f
Run formatter and add enums to url parameter docs
brettimus Jan 21, 2025
2d9f95f
Update embedded to 0.0.16
brettimus Jan 21, 2025
1f00582
Oops update the zod dep for embedded again bc i did a dumb
brettimus Jan 21, 2025
480a763
Update lilo-worker to 0.0.16 of embedded
brettimus Jan 21, 2025
a972a1a
Change styles on unknown response body
brettimus Jan 21, 2025
a46534d
Fix up the menu items along the bottom
brettimus Jan 21, 2025
c4641a8
Prepare for 0.0.17 embedded
brettimus Jan 21, 2025
40cdb8d
Update lilo to latest embedded
brettimus Jan 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ shared/dist
.env
.envrc

# To make my life temporarily easier
# temp for my branch
lilo/lilo-worker/.prod.vars
lilo/lilo-worker/.dev.vars
remove_node_modules.sh

# Cursor
.cursorrules
Expand Down
1 change: 1 addition & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@ai-sdk/mistral": "^1.0.3",
"@ai-sdk/openai": "^1.0.5",
"@fiberplane/fpx-types": "workspace:*",
"@fiberplane/embedded": "workspace:*",
"@fiberplane/source-analysis": "workspace:*",
"@hono/node-server": "^1.13.7",
"@hono/zod-validator": "^0.4.1",
Expand Down
8 changes: 8 additions & 0 deletions api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type * as schema from "./db/schema.js";
import type { Bindings, Variables } from "./lib/types.js";
import logger from "./logger/index.js";

import { createMiddleware } from "@fiberplane/embedded";
import { HTTPException } from "hono/http-exception";
import type * as webhoncType from "./lib/webhonc/index.js";
import appRoutes from "./routes/app-routes.js";
Expand Down Expand Up @@ -73,5 +74,12 @@ export function createApp(
app.route("/", settings);
app.route("/", collections);

app.use(
"/fp/*",
createMiddleware({
apiKey: "1234",
}),
);

return app;
}
4 changes: 3 additions & 1 deletion biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
}
},
{
"include": ["studio", "lilo/lilo-frontend"],
"include": ["studio", "lilo/lilo-frontend", "playground"],
"linter": {
"enabled": true,
"rules": {
Expand Down Expand Up @@ -109,6 +109,8 @@
".astro",
// ignore all tsconfig.json files
"tsconfig*.json",
// ignore the autogenerated routeTree.gen.ts file
"playground/src/routeTree.gen.ts",
// ignore any test data files
"test-data/*.js",
// fpx-workers build files
Expand Down
2 changes: 1 addition & 1 deletion lilo/lilo-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@ai-sdk/google": "^1.0.9",
"@ai-sdk/openai": "^1.0.8",
"@fiberplane/embedded": "^0.0.9",
"@fiberplane/embedded": "^0.0.17",
"@hono/oauth-providers": "^0.6.2",
"@hono/zod-openapi": "^0.18.0",
"@hono/zod-validator": "^0.4.1",
Expand Down
53 changes: 31 additions & 22 deletions lilo/lilo-worker/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,43 @@ app.doc("/doc", (c) => ({
],
}));

// Mount the Fiberplane playground to play with the API
// Mount the Fiberplane playground to play with the API
app.use(
"/fp/*",
createMiddleware({
cdn: "https://cdn.jsdelivr.net/npm/@fiberplane/embedded/dist/playground/",
// @ts-expect-error - The imported spec does not match our expected OpenAPIv3 type
spec: app.getOpenAPIDocument({
openapi: "3.0.0",
info: {
title: "Lilo API",
version: "0.0.1",
description: "API documentation for Lilo",
},
servers: [
{
// url: new URL(c.req.url).origin,
url: "http://localhost:6246",
description: "Local",
},
{
// url: new URL(c.req.url).origin,
url: "https://lilo.fp.dev",
description: "Production",
},
],
}),
apiKey: "12345",
spec: "/doc",
}),
);
// app.use(
// "/fp/*",
// createMiddleware({
// // @ts-expect-error - The imported spec does not match our expected OpenAPIv3 type
// spec: app.getOpenAPIDocument({
// openapi: "3.0.0",
// info: {
// title: "Lilo API",
// version: "0.0.1",
// description: "API documentation for Lilo",
// },
// servers: [
// // NOTE - Embedded should add the current origin automatically.
// //
// // {
// // // url: new URL(c.req.url).origin,
// // url: "http://localhost:6246",
// // description: "Local",
// // },
// {
// // url: new URL(c.req.url).origin,
// url: "https://lilo.fp.dev",
// description: "Production",
// },
// ],
// }),
// }),
// );

app.route("/reference", apiReferenceRouter);

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"preinstall": "npx only-allow pnpm",
"postinstall": "pnpm run build:types && pnpm run build:source-analysis",
"build:embedded": "pnpm --filter @fiberplane/playground build && rimraf packages/embedded/dist/playground && pnpm --filter @fiberplane/embedded build && cp -r playground/dist packages/embedded/dist/playground",
"build:types": "pnpm --filter @fiberplane/fpx-types build",
"build:source-analysis": "pnpm --filter @fiberplane/source-analysis build",
"build:fpx-studio": "pnpm clean:fpx-studio && pnpm build:api && pnpm build:frontend",
Expand Down
1 change: 1 addition & 0 deletions packages/embedded/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
69 changes: 69 additions & 0 deletions packages/embedded/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
node_modules
.dev.vars
.dev.vars.example

# do not publish source files, even though we point to them in the package.json
src/

# do not publish biome config
biome.jsonc

# do not publish migrate typescript file
migrate.ts

# Change them to your taste:
package-lock.json
yarn.lock
pnpm-lock.yaml
bun.lockb

# mac
.DS_Store

# dbs
mizu.db
mizu.db*
mizu*.db
fpx.db
fpx.db*
fpx*.db
.fpxconfig
.fpxconfig/*
.fpx
.fpx/*

# Rust targets
**/target
target

.env
.envrc

# VS Code
.vscode/*
*.code-workspace

# CLion
.idea

# TypeScript / Yarn
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
node_modules
package-lock.json
yarn-error.log

# Build tools
.parcel-cache*
.nx/cache
*.tsbuildinfo

.git/*

# Personal files
mizu.boots.code-workspace
start-dev.sh
21 changes: 21 additions & 0 deletions packages/embedded/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Fiberplane

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
22 changes: 22 additions & 0 deletions packages/embedded/biome.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$schema": "../../node_modules/@biomejs/biome/configuration_schema.json",
"extends": ["../../biome.jsonc"],
"files": {
"ignore": ["dist", "node_modules"]
},
"overrides": [
{
"include": ["src"],
"linter": {
"enabled": true,
"rules": {
"suspicious": {
"noConsoleLog": {
"level": "warn"
}
}
}
}
}
]
}
43 changes: 43 additions & 0 deletions packages/embedded/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "@fiberplane/embedded",
"version": "0.0.17",
"type": "module",
"exports": {
".": {
"types": "./src/index.ts",
"import": "./src/index.ts"
}
},
"publishConfig": {
"access": "public",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
}
}
},
"license": "MIT or Apache 2",
"scripts": {
"clean": "rm -rf dist",
"build": "tsc",
"format": "biome check . --write",
"lint": "biome lint .",
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"@types/node": "*",
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.0",
"hono": "^4.6.12",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"peerDependencies": {
"hono": "^4.0"
},
"dependencies": {
"openapi-types": "^12.1.3",
"zod": "^3.23.8"
}
}
2 changes: 2 additions & 0 deletions packages/embedded/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { createMiddleware } from "./middleware.js";
export { FpService } from "./services/index.js";
92 changes: 92 additions & 0 deletions packages/embedded/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import type { Context } from "hono";
import type { Env, MiddlewareHandler } from "hono/types";
import type { OpenAPIV3, OpenAPIV3_1 } from "openapi-types";
import { type RouterSpec, createRouter } from "./router.js";

// HACK - We need to manually update the version in the CDN URL when you release a new version
// Eventually we should do this automagically when building the package (and derive the version from the package.json)
const VERSION = "0.0.17";
const CDN_URL = `https://cdn.jsdelivr.net/npm/@fiberplane/embedded@${VERSION}/dist/playground/`;

export interface EmbeddedMiddlewareOptions {
apiKey: string;
cdn?: string;
spec?: OpenAPIV3_1.Document | OpenAPIV3.Document | string;
}

export const createMiddleware =
<E extends Env>(options: EmbeddedMiddlewareOptions): MiddlewareHandler<E> =>
async (c, next) => {
const { mountedPath, internalPath } = getPaths(c);

const origin = new URL(c.req.url).origin;
const modSpec: RouterSpec = parseSpecParameter(options?.spec, origin);

// Forward request to embedded router, continuing middleware chain if no route matches
const router = createRouter({
...options,
mountedPath,
cdn: options?.cdn ?? CDN_URL,
spec: modSpec,
});

// Create a new request with the corrected (internal) path
const newUrl = new URL(c.req.url);
newUrl.pathname = internalPath;
const newRequest = new Request(newUrl, c.req.raw);
const response = await router.fetch(newRequest);

// Skip the middleware and continue if the embedded router doesn't match
if (response.status === 404) {
return next();
}

return response;
};

// This middleware is designed to be mounted within another Hono app at any path.
// Since the parent app determines the mount path, we need to extract and remove
// this prefix from incoming requests to ensure proper route matching
function getPaths(c: Context): { mountedPath: string; internalPath: string } {
const mountedPath = c.req.routePath.replace("/*", "");
const internalPath = c.req.path.replace(mountedPath, "");

return {
mountedPath,
internalPath,
};
}

function parseSpecParameter(
spec: OpenAPIV3_1.Document | OpenAPIV3.Document | string | undefined,
origin: string,
): RouterSpec {
if (!spec) {
return {
type: "empty",
value: undefined,
origin,
};
}
if (typeof spec === "string" && spec.startsWith("/")) {
return {
type: "path",
value: spec,
origin,
};
}
if (spec && typeof spec === "object") {
return {
type: "raw",
value: spec,
origin,
};
}
// NOTE - We assume the spec is a URL if it's not a path-like string or an object
// TODO - Make this more robust, add an unknown type
return {
type: "url",
value: spec,
origin,
};
}
Loading
Loading