unfazed 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +88 -0
- package/README.md +299 -78
- package/REFERENCE.md +284 -0
- package/dist/cli/login.d.ts +129 -0
- package/dist/cli/login.js +596 -0
- package/dist/cli/login.js.map +1 -0
- package/dist/cli/workflow.d.ts +31 -0
- package/dist/cli/workflow.js +157 -0
- package/dist/cli/workflow.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +173 -0
- package/dist/cli.js.map +1 -0
- package/dist/client.d.ts +26 -5
- package/dist/client.js +93 -48
- package/dist/client.js.map +1 -1
- package/dist/credentials.d.ts +123 -0
- package/dist/credentials.js +317 -0
- package/dist/credentials.js.map +1 -0
- package/dist/errors.d.ts +64 -0
- package/dist/errors.js +95 -0
- package/dist/errors.js.map +1 -1
- package/dist/generated/gql.d.ts +78 -2
- package/dist/generated/gql.js +21 -2
- package/dist/generated/gql.js.map +1 -1
- package/dist/generated/graphql.d.ts +505 -6
- package/dist/generated/graphql.js +439 -2
- package/dist/generated/graphql.js.map +1 -1
- package/dist/index.d.ts +25 -6
- package/dist/index.js +23 -5
- package/dist/index.js.map +1 -1
- package/dist/operations.d.ts +116 -5
- package/dist/operations.js +379 -7
- package/dist/operations.js.map +1 -1
- package/dist/reference.d.ts +18 -0
- package/dist/reference.generated.d.ts +2 -0
- package/dist/reference.generated.js +5 -0
- package/dist/reference.generated.js.map +1 -0
- package/dist/reference.js +38 -0
- package/dist/reference.js.map +1 -0
- package/dist/remote/app.js +2 -1
- package/dist/remote/app.js.map +1 -1
- package/dist/remote/world.d.ts +2 -2
- package/dist/remote/world.js +32 -16
- package/dist/remote/world.js.map +1 -1
- package/dist/unfazed.d.ts +545 -68
- package/dist/unfazed.js +688 -64
- package/dist/unfazed.js.map +1 -1
- package/dist/wait.d.ts +7 -0
- package/dist/wait.js.map +1 -1
- package/dist/workflow/nitro.js +5 -3
- package/dist/workflow/nitro.js.map +1 -1
- package/package.json +22 -6
- package/schema/SOURCE.json +4 -4
- package/schema/schema.graphqls +1628 -30
package/dist/wait.d.ts
CHANGED
|
@@ -20,6 +20,13 @@ export interface WaitOptions {
|
|
|
20
20
|
factor?: number;
|
|
21
21
|
/** Cancels the wait; surfaces as {@link UnfazedTimeoutError}. */
|
|
22
22
|
signal?: AbortSignal;
|
|
23
|
+
/**
|
|
24
|
+
* Deployment waits only. `"server"` (the default) waits on the platform
|
|
25
|
+
* (`waitForDeployment`, one request per up to 45 s, answered the moment the
|
|
26
|
+
* status changes); `"poll"` polls with the backoff above. The SDK polls by
|
|
27
|
+
* itself on a platform without the server-side wait.
|
|
28
|
+
*/
|
|
29
|
+
mode?: "server" | "poll";
|
|
23
30
|
/** Injected clock (tests). */
|
|
24
31
|
now?: () => number;
|
|
25
32
|
/** Injected sleep (tests). */
|
package/dist/wait.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wait.js","sourceRoot":"","sources":["../src/wait.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"wait.js","sourceRoot":"","sources":["../src/wait.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AA+ClD,MAAM,UAAU,kBAAkB,CAAC,UAAuB,EAAE;IAC1D,OAAO;QACL,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,OAAO;QACvC,iBAAiB,EAAE,OAAO,CAAC,iBAAiB,IAAI,KAAK;QACrD,aAAa,EAAE,OAAO,CAAC,aAAa,IAAI,MAAM;QAC9C,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,GAAG;QAC7B,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,GAAG,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,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AAI,EAAE,CAAC;QAC9B,IAAI,QAAQ,CAAC,IAAI;YAAE,OAAO,QAAQ,CAAC,KAAK,CAAC;QAEzC,MAAM,SAAS,GAAG,QAAQ,GAAG,GAAG,EAAE,CAAC;QACnC,IAAI,SAAS,IAAI,CAAC;YAAE,MAAM,SAAS,EAAE,CAAC;QAEtC,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,CAAC;QACnD,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,GAAG,MAAM,EAAE,aAAa,CAAC,CAAC;IACxD,CAAC;AACH,CAAC","sourcesContent":["import { UnfazedTimeoutError } from \"./errors.js\";\n\n/**\n * Knobs for any polling wait.\n *\n * `sleep` and `now` are injectable so the test suite can drive multi-minute\n * backoff schedules instantly and assert the exact interval sequence, instead\n * of actually waiting. Production code never passes them.\n */\nexport interface WaitOptions {\n /**\n * Give up after this long. Default 600_000 (10 minutes) — a cold Bun build\n * plus VM boot and health probe routinely runs into minutes, and the build\n * microVM's own ceiling is 600s.\n */\n timeoutMs?: number;\n /** First poll delay in ms. Default 1_000. */\n initialIntervalMs?: number;\n /** Ceiling for the backoff in ms. Default 10_000. */\n maxIntervalMs?: number;\n /** Backoff multiplier. Default 1.5. */\n factor?: number;\n /** Cancels the wait; surfaces as {@link UnfazedTimeoutError}. */\n signal?: AbortSignal;\n /**\n * Deployment waits only. `\"server\"` (the default) waits on the platform\n * (`waitForDeployment`, one request per up to 45 s, answered the moment the\n * status changes); `\"poll\"` polls with the backoff above. The SDK polls by\n * itself on a platform without the server-side wait.\n */\n mode?: \"server\" | \"poll\";\n /** Injected clock (tests). */\n now?: () => number;\n /** Injected sleep (tests). */\n sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;\n}\n\nexport interface ResolvedWaitOptions {\n timeoutMs: number;\n initialIntervalMs: number;\n maxIntervalMs: number;\n factor: number;\n signal: AbortSignal | undefined;\n now: () => number;\n sleep: (ms: number, signal?: AbortSignal) => Promise<void>;\n}\n\nexport function resolveWaitOptions(options: WaitOptions = {}): ResolvedWaitOptions {\n return {\n timeoutMs: options.timeoutMs ?? 600_000,\n initialIntervalMs: options.initialIntervalMs ?? 1_000,\n maxIntervalMs: options.maxIntervalMs ?? 10_000,\n factor: options.factor ?? 1.5,\n signal: options.signal,\n now: options.now ?? (() => Date.now()),\n sleep: options.sleep ?? defaultSleep,\n };\n}\n\nfunction defaultSleep(ms: number, signal?: AbortSignal): Promise<void> {\n return new Promise((resolve, reject) => {\n if (signal?.aborted) {\n reject(new UnfazedTimeoutError(\"unfazed: wait aborted\"));\n return;\n }\n const timer = setTimeout(() => {\n signal?.removeEventListener(\"abort\", onAbort);\n resolve();\n }, ms);\n const onAbort = () => {\n clearTimeout(timer);\n reject(new UnfazedTimeoutError(\"unfazed: wait aborted\"));\n };\n signal?.addEventListener(\"abort\", onAbort, { once: true });\n });\n}\n\n/** What one poll tick decided. */\nexport type PollDecision<T> = { done: true; value: T } | { done: false };\n\n/**\n * Generic exponential-backoff poll loop.\n *\n * Polls immediately (no initial sleep — most callers have just created the\n * thing and a first read is nearly free), then backs off geometrically up to\n * `maxIntervalMs`. The final sleep is clamped so the loop cannot overshoot\n * `timeoutMs`, which keeps `wait: true` honest as a deadline rather than a\n * suggestion.\n *\n * `onTimeout` builds the error so callers can attach their own context (the\n * last deployment snapshot, say) instead of getting a bare timeout.\n */\nexport async function pollWithBackoff<T>(\n poll: () => Promise<PollDecision<T>>,\n options: ResolvedWaitOptions,\n onTimeout: () => Error,\n): Promise<T> {\n const { timeoutMs, initialIntervalMs, maxIntervalMs, factor, signal, now, sleep } = options;\n const deadline = now() + timeoutMs;\n let interval = initialIntervalMs;\n\n for (;;) {\n if (signal?.aborted) throw new UnfazedTimeoutError(\"unfazed: wait aborted\");\n\n const decision = await poll();\n if (decision.done) return decision.value;\n\n const remaining = deadline - now();\n if (remaining <= 0) throw onTimeout();\n\n await sleep(Math.min(interval, remaining), signal);\n interval = Math.min(interval * factor, maxIntervalMs);\n }\n}\n"]}
|
package/dist/workflow/nitro.js
CHANGED
|
@@ -3,14 +3,16 @@
|
|
|
3
3
|
* World in production builds.
|
|
4
4
|
*
|
|
5
5
|
* ```ts
|
|
6
|
-
* // nitro.config.ts
|
|
6
|
+
* // nitro.config.ts — the app is the root server.ts, Nitro's server entry
|
|
7
7
|
* export default defineConfig({
|
|
8
|
-
* preset: "standard",
|
|
9
8
|
* modules: ["workflow/nitro", "unfazed/workflow/nitro"],
|
|
10
|
-
* routes: { "/**": "./src/app.ts" },
|
|
11
9
|
* });
|
|
12
10
|
* ```
|
|
13
11
|
*
|
|
12
|
+
* with `{ "kind": "SERVICE", "build": "nitro build" }` as unfazed.json and no
|
|
13
|
+
* `entry`: unfazed then serves the build's `standard` output,
|
|
14
|
+
* `.output/server/index.mjs`.
|
|
15
|
+
*
|
|
14
16
|
* In a production build it:
|
|
15
17
|
* - registers a server plugin that calls `setWorld(createWorld())` while the
|
|
16
18
|
* app initialises, before the first request (the World is never left to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nitro.js","sourceRoot":"","sources":["../../src/workflow/nitro.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AAEvF,wEAAwE;AACxE,MAAM,gBAAgB,GAA2B;IAC/C,IAAI,EAAE,cAAc;IACpB,UAAU,EAAE,UAAU;IACtB,WAAW,EAAE,WAAW;IACxB,WAAW,EAAE,WAAW;IACxB,cAAc,EAA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CAAC,IAAI,CAAC,yEAAyE,QAAQ,2BAA2B,CAAC,CAAC;AACzH,CAAC","sourcesContent":["/**\n * `unfazed/workflow/nitro` — a Nitro (v3) module that installs the unfazed\n * World in production builds.\n *\n * ```ts\n * // nitro.config.ts\n * export default defineConfig({\n * preset: \"standard\",\n * modules: [\"workflow/nitro\", \"unfazed/workflow/nitro\"],\n * routes: { \"/**\": \"./src/app.ts\" },\n * });\n * ```\n *\n * In a production build it:\n * - registers a server plugin that calls `setWorld(createWorld())` while the\n * app initialises, before the first request (the World is never left to\n * the runtime's `WORKFLOW_TARGET_WORLD` lookup, which needs node_modules);\n * - embeds the SQL migrations of the app's own `@workflow/world-postgres`,\n * so the schema always matches the storage code that is bundled;\n * - guards `/.well-known/workflow/v1/flow`: anything without the platform's\n * queue token gets 401 before the Workflow SDK sees it (including its\n * unauthenticated `?__health` probe);\n * - mounts the workflow inspection route the unfazed dashboard and MCP read\n * runs through (`/.well-known/workflow/v1/unfazed/inspect/v1/*`, the same\n * queue token, see `createInspectHandler`), with the build's workflow list\n * and Workflow SDK version;\n * - sets `noExternals: true`, because a service VM has no node_modules;\n * - builds Nitro's `standard` output (a bundle that default-exports\n * `{ fetch }`, which the unfazed runtime serves) whenever no preset was\n * chosen, whatever Nitro detected on the build machine: `node-server`\n * under Node, `bun` under Bun (the unfazed build VM), `deno-server` under\n * Deno. A preset chosen explicitly (`preset` in nitro.config.ts or\n * .nitrorc, `NITRO_PRESET`, `SERVER_PRESET`) other than `standard` fails\n * the build with a message saying so: those bundles start a server of\n * their own, which unfazed cannot serve properly. Static files are served\n * only when `serveStatic: \"inline\"` embeds them in the bundle.\n *\n * `nitro dev` is left untouched, so local development keeps Workflow SDK's\n * Local World.\n */\nimport { createRequire } from \"node:module\";\nimport { join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { readFile } from \"node:fs/promises\";\nimport { readPackageVersion, readWorldPostgresMigrations } from \"./migration-files.js\";\n\n/** The aliases of Nitro's `standard` preset (nitro 3.0.260903-beta). */\nconst STANDARD_ALIASES: Record<string, string> = {\n srvx: \"srvx/generic\",\n \"srvx/bun\": \"srvx/bun\",\n \"srvx/deno\": \"srvx/deno\",\n \"srvx/node\": \"srvx/node\",\n \"srvx/generic\": \"srvx/generic\",\n \"srvx/tracing\": \"srvx/tracing\",\n \"srvx/body-limit\": \"srvx/body-limit\",\n};\n\n/** Virtual module the plugin reads the app's migrations from. */\nexport const MIGRATIONS_MODULE_ID = \"#unfazed/workflow-migrations\";\n/** The Workflow SDK's flow route, which the guard protects. */\nexport const FLOW_ROUTE = \"/.well-known/workflow/v1/flow\";\n/** Virtual module the inspection route reads the build's workflow list and SDK version from. */\nexport const INSPECT_INFO_MODULE_ID = \"#unfazed/workflow-inspect-info\";\n/** `INSPECT_BASE_PATH` (inspect.ts), repeated so loading this module at build time loads no SDK code. */\nexport const INSPECT_ROUTE = \"/.well-known/workflow/v1/unfazed/inspect/v1\";\n\n/** The slice of Nitro v3's `Nitro` this module reads and writes. */\ninterface NitroLike {\n options: {\n dev: boolean;\n preset: string;\n rootDir: string;\n buildDir: string;\n noExternals?: boolean | unknown[];\n plugins: string[];\n handlers: { route?: string; handler: string; middleware?: boolean }[];\n virtual: Record<string, string | (() => string | Promise<string>)>;\n entry?: string;\n serveStatic?: boolean | string;\n alias: Record<string, string>;\n exportConditions?: string[];\n commands?: Record<string, string | undefined>;\n _config?: { preset?: string };\n _c12?: { layers?: { config?: { preset?: string } | null; configFile?: string }[] };\n };\n logger?: { info(message: string): void; warn(message: string): void };\n}\n\nconst here = (file: string) => fileURLToPath(new URL(file, import.meta.url));\n\nconst unfazedWorkflowNitro = {\n name: \"unfazed/workflow/nitro\",\n async setup(input: { options: object }): Promise<void> {\n const nitro = input as unknown as NitroLike;\n const { options } = nitro;\n const log = nitro.logger ?? console;\n if (options.dev) {\n log.info(\"unfazed/workflow: `nitro dev` keeps Workflow SDK's Local World; production builds use the unfazed World.\");\n return;\n }\n\n options.noExternals = true;\n await applyStandardOutput(nitro, log);\n\n const migrations = await readAppMigrations(options.rootDir);\n if (!migrations) {\n log.warn(\n \"unfazed/workflow: cannot read the app's @workflow/world-postgres migrations; \" +\n \"using the copy embedded in unfazed. Install @workflow/world-postgres in the app.\",\n );\n }\n options.virtual[MIGRATIONS_MODULE_ID] = `export default ${JSON.stringify(migrations ?? null)};`;\n options.plugins.push(here(\"./nitro-plugin.js\"));\n options.handlers.push({ route: FLOW_ROUTE, middleware: true, handler: here(\"./nitro-flow-guard.js\") });\n\n // Rendered when the bundle is built, after `workflow/nitro` has written the\n // build's manifest (its `build:before` hook).\n const { rootDir, buildDir } = options;\n options.virtual[INSPECT_INFO_MODULE_ID] = async () =>\n `export default ${JSON.stringify(await readInspectInfo(rootDir, buildDir))};`;\n options.handlers.push({ route: `${INSPECT_ROUTE}/**`, handler: here(\"./nitro-inspect.js\") });\n },\n};\n\nexport default unfazedWorkflowNitro;\n\n/** What the inspection route's `info` reports about this build. */\nexport interface InspectBuildInfo {\n /** The app's Workflow SDK version, if it could be read. */\n workflow: string | null;\n /** The workflow machine names in the build's manifest. */\n workflows: string[];\n}\n\n/**\n * The app's `workflow` version and the workflows in the manifest\n * `workflow/nitro` writes to `<buildDir>/workflow/manifest.json`\n * (`workflows: { [file]: { [name]: { workflowId } } }`).\n */\nexport async function readInspectInfo(rootDir: string, buildDir: string): Promise<InspectBuildInfo> {\n let workflow: string | null = null;\n try {\n const entry = createRequire(join(rootDir, \"package.json\")).resolve(\"workflow\");\n workflow = (await readPackageVersion(entry, \"workflow\")) ?? null;\n } catch {\n // not resolvable from the app: reported as unknown\n }\n const workflows = new Set<string>();\n try {\n const manifest = JSON.parse(await readFile(join(buildDir, \"workflow\", \"manifest.json\"), \"utf8\")) as {\n workflows?: Record<string, Record<string, { workflowId?: unknown }>>;\n };\n for (const entries of Object.values(manifest.workflows ?? {})) {\n for (const entry of Object.values(entries ?? {})) {\n if (typeof entry?.workflowId === \"string\") workflows.add(entry.workflowId);\n }\n }\n } catch {\n // no manifest: an empty list\n }\n return { workflow, workflows: [...workflows].sort() };\n}\n\nasync function readAppMigrations(rootDir: string) {\n try {\n const entry = createRequire(join(rootDir, \"package.json\")).resolve(\"@workflow/world-postgres\");\n return await readWorldPostgresMigrations(entry);\n } catch {\n return undefined;\n }\n}\n\n/**\n * The presets Nitro picks by itself from the build machine's runtime when it\n * detects no hosting provider, and the export condition each adds.\n */\nconst RUNTIME_DEFAULT_PRESETS: Record<string, string | undefined> = {\n \"node-server\": undefined,\n bun: \"bun\",\n \"deno-server\": \"deno\",\n};\n\n/** A preset the build chose explicitly, and where, or undefined when Nitro picked it. */\nexport function explicitPreset(\n options: Pick<NitroLike[\"options\"], \"_config\" | \"_c12\">,\n env: Record<string, string | undefined> = process.env,\n): { preset: string; from: string } | undefined {\n if (env.NITRO_PRESET) return { preset: env.NITRO_PRESET, from: \"NITRO_PRESET\" };\n if (env.SERVER_PRESET) return { preset: env.SERVER_PRESET, from: \"SERVER_PRESET\" };\n if (options._config?.preset) return { preset: options._config.preset, from: \"the options Nitro was created with\" };\n // Only a config file's layer counts (nitro.config.*, .nitrorc): the first\n // layer carries the preset Nitro detected itself.\n const layer = options._c12?.layers?.find((l) => l?.configFile && l.config?.preset);\n if (layer?.config?.preset) return { preset: layer.config.preset, from: layer.configFile! };\n return undefined;\n}\n\n/**\n * Nitro resolves its preset before modules run, so a module cannot switch\n * presets; it can give the build what the `standard` preset sets. Against\n * the presets Nitro picks by itself (`node-server`, `bun`, `deno-server`)\n * that is: the entry (export `{ fetch }` instead of starting a server: under\n * the `bun` preset the bundle would serve the port itself, with Bun's 10 s\n * idle timeout cutting every quiet stream), not serving static files from\n * disk, no runtime export condition, and the aliases that give h3 srvx's\n * runtime-neutral build (under `node-server`'s `node` condition h3 answers\n * with srvx's Node `Response` stand-in, which `Bun.serve` refuses).\n * `serveStatic: \"inline\"` stays: it embeds the public assets in the bundle\n * and reads nothing from disk, which is how a service VM (the bundle and\n * nothing next to it) can serve a UI.\n *\n * A preset chosen explicitly, or a hosting provider's preset Nitro detected,\n * fails the build: its output is not something unfazed can serve.\n */\nasync function applyStandardOutput(nitro: NitroLike, log: Pick<Console, \"info\">): Promise<void> {\n const { options } = nitro;\n const explicit = explicitPreset(options);\n if (options.preset === \"standard\") return;\n const fix = 'Remove the preset so this module builds \"standard\", or set preset: \"standard\" in nitro.config.ts.';\n if (explicit) {\n throw new Error(\n `unfazed/workflow/nitro: this build uses Nitro preset \"${options.preset}\" (chosen in ${explicit.from}). ` +\n 'unfazed serves a bundle that default-exports { fetch }, which is Nitro\\'s \"standard\" preset; ' +\n `\"${options.preset}\" builds something else (a bundle that starts its own server, whose idle timeout ` +\n `cuts workflow streams). ${fix}`,\n );\n }\n if (!(options.preset in RUNTIME_DEFAULT_PRESETS)) {\n throw new Error(\n `unfazed/workflow/nitro: Nitro chose preset \"${options.preset}\" for this build environment, ` +\n 'and unfazed serves only Nitro\\'s \"standard\" output (a bundle that default-exports { fetch }). ' +\n 'Set preset: \"standard\" in nitro.config.ts.',\n );\n }\n let standardEntry: string;\n try {\n const { presetsDir } = (await import(\"nitro/meta\")) as { presetsDir: string };\n standardEntry = join(presetsDir, \"standard\", \"runtime\", \"server\");\n } catch (error) {\n throw new Error(\n `unfazed/workflow/nitro: cannot locate Nitro's \"standard\" preset (${error instanceof Error ? error.message : String(error)}). ` +\n 'Set preset: \"standard\" in nitro.config.ts.',\n );\n }\n const detected = options.preset;\n options.entry = standardEntry;\n if (options.serveStatic !== \"inline\") options.serveStatic = false;\n const condition = RUNTIME_DEFAULT_PRESETS[detected];\n if (condition && options.exportConditions) {\n options.exportConditions = options.exportConditions.filter((c) => c !== condition);\n }\n // As the standard preset sets them; the subpaths map to themselves so the\n // bare `srvx` alias does not rewrite them.\n options.alias = { ...options.alias, ...STANDARD_ALIASES };\n options.commands = { ...options.commands, preview: \"npx srvx --prod ./\" };\n options.preset = \"standard\";\n log.info(`unfazed/workflow: building Nitro's \"standard\" output (Nitro detected \"${detected}\"; no preset was chosen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OAAO,CAAC,WAAW,GAAG,KAAK,CAAC;IAClE,MAAM,SAAS,GAAG,uBAAuB,CAAC,QAAQ,CAAC,CAAC;IACpD,IAAI,SAAS,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;QAC1C,OAAO,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;IACrF,CAAC;IACD,0EAA0E;IAC1E,2CAA2C;IAC3C,OAAO,CAAC,KAAK,GAAG,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,GAAG,gBAAgB,EAAE,CAAC;IAC1D,OAAO,CAAC,QAAQ,GAAG,EAAE,GAAG,OAAO,CAAC,QAAQ,EAAE,OAAO,EAAE,oBAAoB,EAAE,CAAC;IAC1E,OAAO,CAAC,MAAM,GAAG,UAAU,CAAC;IAC5B,GAAG,CAAC,IAAI,CAAC,yEAAyE,QAAQ,2BAA2B,CAAC,CAAC;AACzH,CAAC","sourcesContent":["/**\n * `unfazed/workflow/nitro` — a Nitro (v3) module that installs the unfazed\n * World in production builds.\n *\n * ```ts\n * // nitro.config.ts — the app is the root server.ts, Nitro's server entry\n * export default defineConfig({\n * modules: [\"workflow/nitro\", \"unfazed/workflow/nitro\"],\n * });\n * ```\n *\n * with `{ \"kind\": \"SERVICE\", \"build\": \"nitro build\" }` as unfazed.json and no\n * `entry`: unfazed then serves the build's `standard` output,\n * `.output/server/index.mjs`.\n *\n * In a production build it:\n * - registers a server plugin that calls `setWorld(createWorld())` while the\n * app initialises, before the first request (the World is never left to\n * the runtime's `WORKFLOW_TARGET_WORLD` lookup, which needs node_modules);\n * - embeds the SQL migrations of the app's own `@workflow/world-postgres`,\n * so the schema always matches the storage code that is bundled;\n * - guards `/.well-known/workflow/v1/flow`: anything without the platform's\n * queue token gets 401 before the Workflow SDK sees it (including its\n * unauthenticated `?__health` probe);\n * - mounts the workflow inspection route the unfazed dashboard and MCP read\n * runs through (`/.well-known/workflow/v1/unfazed/inspect/v1/*`, the same\n * queue token, see `createInspectHandler`), with the build's workflow list\n * and Workflow SDK version;\n * - sets `noExternals: true`, because a service VM has no node_modules;\n * - builds Nitro's `standard` output (a bundle that default-exports\n * `{ fetch }`, which the unfazed runtime serves) whenever no preset was\n * chosen, whatever Nitro detected on the build machine: `node-server`\n * under Node, `bun` under Bun (the unfazed build VM), `deno-server` under\n * Deno. A preset chosen explicitly (`preset` in nitro.config.ts or\n * .nitrorc, `NITRO_PRESET`, `SERVER_PRESET`) other than `standard` fails\n * the build with a message saying so: those bundles start a server of\n * their own, which unfazed cannot serve properly. Static files are served\n * only when `serveStatic: \"inline\"` embeds them in the bundle.\n *\n * `nitro dev` is left untouched, so local development keeps Workflow SDK's\n * Local World.\n */\nimport { createRequire } from \"node:module\";\nimport { join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { readFile } from \"node:fs/promises\";\nimport { readPackageVersion, readWorldPostgresMigrations } from \"./migration-files.js\";\n\n/** The aliases of Nitro's `standard` preset (nitro 3.0.260903-beta). */\nconst STANDARD_ALIASES: Record<string, string> = {\n srvx: \"srvx/generic\",\n \"srvx/bun\": \"srvx/bun\",\n \"srvx/deno\": \"srvx/deno\",\n \"srvx/node\": \"srvx/node\",\n \"srvx/generic\": \"srvx/generic\",\n \"srvx/tracing\": \"srvx/tracing\",\n \"srvx/body-limit\": \"srvx/body-limit\",\n};\n\n/** Virtual module the plugin reads the app's migrations from. */\nexport const MIGRATIONS_MODULE_ID = \"#unfazed/workflow-migrations\";\n/** The Workflow SDK's flow route, which the guard protects. */\nexport const FLOW_ROUTE = \"/.well-known/workflow/v1/flow\";\n/** Virtual module the inspection route reads the build's workflow list and SDK version from. */\nexport const INSPECT_INFO_MODULE_ID = \"#unfazed/workflow-inspect-info\";\n/** `INSPECT_BASE_PATH` (inspect.ts), repeated so loading this module at build time loads no SDK code. */\nexport const INSPECT_ROUTE = \"/.well-known/workflow/v1/unfazed/inspect/v1\";\n\n/** The slice of Nitro v3's `Nitro` this module reads and writes. */\ninterface NitroLike {\n options: {\n dev: boolean;\n preset: string;\n rootDir: string;\n buildDir: string;\n noExternals?: boolean | unknown[];\n plugins: string[];\n handlers: { route?: string; handler: string; middleware?: boolean }[];\n virtual: Record<string, string | (() => string | Promise<string>)>;\n entry?: string;\n serveStatic?: boolean | string;\n alias: Record<string, string>;\n exportConditions?: string[];\n commands?: Record<string, string | undefined>;\n _config?: { preset?: string };\n _c12?: { layers?: { config?: { preset?: string } | null; configFile?: string }[] };\n };\n logger?: { info(message: string): void; warn(message: string): void };\n}\n\nconst here = (file: string) => fileURLToPath(new URL(file, import.meta.url));\n\nconst unfazedWorkflowNitro = {\n name: \"unfazed/workflow/nitro\",\n async setup(input: { options: object }): Promise<void> {\n const nitro = input as unknown as NitroLike;\n const { options } = nitro;\n const log = nitro.logger ?? console;\n if (options.dev) {\n log.info(\"unfazed/workflow: `nitro dev` keeps Workflow SDK's Local World; production builds use the unfazed World.\");\n return;\n }\n\n options.noExternals = true;\n await applyStandardOutput(nitro, log);\n\n const migrations = await readAppMigrations(options.rootDir);\n if (!migrations) {\n log.warn(\n \"unfazed/workflow: cannot read the app's @workflow/world-postgres migrations; \" +\n \"using the copy embedded in unfazed. Install @workflow/world-postgres in the app.\",\n );\n }\n options.virtual[MIGRATIONS_MODULE_ID] = `export default ${JSON.stringify(migrations ?? null)};`;\n options.plugins.push(here(\"./nitro-plugin.js\"));\n options.handlers.push({ route: FLOW_ROUTE, middleware: true, handler: here(\"./nitro-flow-guard.js\") });\n\n // Rendered when the bundle is built, after `workflow/nitro` has written the\n // build's manifest (its `build:before` hook).\n const { rootDir, buildDir } = options;\n options.virtual[INSPECT_INFO_MODULE_ID] = async () =>\n `export default ${JSON.stringify(await readInspectInfo(rootDir, buildDir))};`;\n options.handlers.push({ route: `${INSPECT_ROUTE}/**`, handler: here(\"./nitro-inspect.js\") });\n },\n};\n\nexport default unfazedWorkflowNitro;\n\n/** What the inspection route's `info` reports about this build. */\nexport interface InspectBuildInfo {\n /** The app's Workflow SDK version, if it could be read. */\n workflow: string | null;\n /** The workflow machine names in the build's manifest. */\n workflows: string[];\n}\n\n/**\n * The app's `workflow` version and the workflows in the manifest\n * `workflow/nitro` writes to `<buildDir>/workflow/manifest.json`\n * (`workflows: { [file]: { [name]: { workflowId } } }`).\n */\nexport async function readInspectInfo(rootDir: string, buildDir: string): Promise<InspectBuildInfo> {\n let workflow: string | null = null;\n try {\n const entry = createRequire(join(rootDir, \"package.json\")).resolve(\"workflow\");\n workflow = (await readPackageVersion(entry, \"workflow\")) ?? null;\n } catch {\n // not resolvable from the app: reported as unknown\n }\n const workflows = new Set<string>();\n try {\n const manifest = JSON.parse(await readFile(join(buildDir, \"workflow\", \"manifest.json\"), \"utf8\")) as {\n workflows?: Record<string, Record<string, { workflowId?: unknown }>>;\n };\n for (const entries of Object.values(manifest.workflows ?? {})) {\n for (const entry of Object.values(entries ?? {})) {\n if (typeof entry?.workflowId === \"string\") workflows.add(entry.workflowId);\n }\n }\n } catch {\n // no manifest: an empty list\n }\n return { workflow, workflows: [...workflows].sort() };\n}\n\nasync function readAppMigrations(rootDir: string) {\n try {\n const entry = createRequire(join(rootDir, \"package.json\")).resolve(\"@workflow/world-postgres\");\n return await readWorldPostgresMigrations(entry);\n } catch {\n return undefined;\n }\n}\n\n/**\n * The presets Nitro picks by itself from the build machine's runtime when it\n * detects no hosting provider, and the export condition each adds.\n */\nconst RUNTIME_DEFAULT_PRESETS: Record<string, string | undefined> = {\n \"node-server\": undefined,\n bun: \"bun\",\n \"deno-server\": \"deno\",\n};\n\n/** A preset the build chose explicitly, and where, or undefined when Nitro picked it. */\nexport function explicitPreset(\n options: Pick<NitroLike[\"options\"], \"_config\" | \"_c12\">,\n env: Record<string, string | undefined> = process.env,\n): { preset: string; from: string } | undefined {\n if (env.NITRO_PRESET) return { preset: env.NITRO_PRESET, from: \"NITRO_PRESET\" };\n if (env.SERVER_PRESET) return { preset: env.SERVER_PRESET, from: \"SERVER_PRESET\" };\n if (options._config?.preset) return { preset: options._config.preset, from: \"the options Nitro was created with\" };\n // Only a config file's layer counts (nitro.config.*, .nitrorc): the first\n // layer carries the preset Nitro detected itself.\n const layer = options._c12?.layers?.find((l) => l?.configFile && l.config?.preset);\n if (layer?.config?.preset) return { preset: layer.config.preset, from: layer.configFile! };\n return undefined;\n}\n\n/**\n * Nitro resolves its preset before modules run, so a module cannot switch\n * presets; it can give the build what the `standard` preset sets. Against\n * the presets Nitro picks by itself (`node-server`, `bun`, `deno-server`)\n * that is: the entry (export `{ fetch }` instead of starting a server: under\n * the `bun` preset the bundle would serve the port itself, with Bun's 10 s\n * idle timeout cutting every quiet stream), not serving static files from\n * disk, no runtime export condition, and the aliases that give h3 srvx's\n * runtime-neutral build (under `node-server`'s `node` condition h3 answers\n * with srvx's Node `Response` stand-in, which `Bun.serve` refuses).\n * `serveStatic: \"inline\"` stays: it embeds the public assets in the bundle\n * and reads nothing from disk, which is how a service VM (the bundle and\n * nothing next to it) can serve a UI.\n *\n * A preset chosen explicitly, or a hosting provider's preset Nitro detected,\n * fails the build: its output is not something unfazed can serve.\n */\nasync function applyStandardOutput(nitro: NitroLike, log: Pick<Console, \"info\">): Promise<void> {\n const { options } = nitro;\n const explicit = explicitPreset(options);\n if (options.preset === \"standard\") return;\n const fix = 'Remove the preset so this module builds \"standard\", or set preset: \"standard\" in nitro.config.ts.';\n if (explicit) {\n throw new Error(\n `unfazed/workflow/nitro: this build uses Nitro preset \"${options.preset}\" (chosen in ${explicit.from}). ` +\n 'unfazed serves a bundle that default-exports { fetch }, which is Nitro\\'s \"standard\" preset; ' +\n `\"${options.preset}\" builds something else (a bundle that starts its own server, whose idle timeout ` +\n `cuts workflow streams). ${fix}`,\n );\n }\n if (!(options.preset in RUNTIME_DEFAULT_PRESETS)) {\n throw new Error(\n `unfazed/workflow/nitro: Nitro chose preset \"${options.preset}\" for this build environment, ` +\n 'and unfazed serves only Nitro\\'s \"standard\" output (a bundle that default-exports { fetch }). ' +\n 'Set preset: \"standard\" in nitro.config.ts.',\n );\n }\n let standardEntry: string;\n try {\n const { presetsDir } = (await import(\"nitro/meta\")) as { presetsDir: string };\n standardEntry = join(presetsDir, \"standard\", \"runtime\", \"server\");\n } catch (error) {\n throw new Error(\n `unfazed/workflow/nitro: cannot locate Nitro's \"standard\" preset (${error instanceof Error ? error.message : String(error)}). ` +\n 'Set preset: \"standard\" in nitro.config.ts.',\n );\n }\n const detected = options.preset;\n options.entry = standardEntry;\n if (options.serveStatic !== \"inline\") options.serveStatic = false;\n const condition = RUNTIME_DEFAULT_PRESETS[detected];\n if (condition && options.exportConditions) {\n options.exportConditions = options.exportConditions.filter((c) => c !== condition);\n }\n // As the standard preset sets them; the subpaths map to themselves so the\n // bare `srvx` alias does not rewrite them.\n options.alias = { ...options.alias, ...STANDARD_ALIASES };\n options.commands = { ...options.commands, preview: \"npx srvx --prod ./\" };\n options.preset = \"standard\";\n log.info(`unfazed/workflow: building Nitro's \"standard\" output (Nitro detected \"${detected}\"; no preset was chosen).`);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unfazed",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Official TypeScript SDK for unfazed. The code-mode companion to the unfazed MCP server: deploy, wait, tail logs and roll back from one script. Also ships the unfazed World for Workflow SDK (unfazed/workflow).",
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"description": "Official TypeScript SDK for unfazed. The code-mode companion to the unfazed MCP server: deploy, wait, tail logs and roll back from one script. `npx unfazed login` signs you in. Also ships the unfazed World for Workflow SDK (unfazed/workflow).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"module": "./dist/index.js",
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
|
+
"bin": {
|
|
11
|
+
"unfazed": "dist/cli.js"
|
|
12
|
+
},
|
|
10
13
|
"exports": {
|
|
11
14
|
".": {
|
|
12
15
|
"types": "./dist/index.d.ts",
|
|
13
16
|
"import": "./dist/index.js",
|
|
14
17
|
"default": "./dist/index.js"
|
|
15
18
|
},
|
|
19
|
+
"./credentials": {
|
|
20
|
+
"types": "./dist/credentials.d.ts",
|
|
21
|
+
"import": "./dist/credentials.js",
|
|
22
|
+
"default": "./dist/credentials.js"
|
|
23
|
+
},
|
|
16
24
|
"./workflow": {
|
|
17
25
|
"types": "./dist/workflow/index.d.ts",
|
|
18
26
|
"import": "./dist/workflow/index.js",
|
|
@@ -30,6 +38,8 @@
|
|
|
30
38
|
"schema/schema.graphqls",
|
|
31
39
|
"schema/SOURCE.json",
|
|
32
40
|
"README.md",
|
|
41
|
+
"REFERENCE.md",
|
|
42
|
+
"CHANGELOG.md",
|
|
33
43
|
"LICENSE"
|
|
34
44
|
],
|
|
35
45
|
"sideEffects": false,
|
|
@@ -49,7 +59,9 @@
|
|
|
49
59
|
"bun",
|
|
50
60
|
"workflow",
|
|
51
61
|
"workflow-sdk",
|
|
52
|
-
"durable"
|
|
62
|
+
"durable",
|
|
63
|
+
"cli",
|
|
64
|
+
"login"
|
|
53
65
|
],
|
|
54
66
|
"repository": {
|
|
55
67
|
"type": "git",
|
|
@@ -68,13 +80,17 @@
|
|
|
68
80
|
"codegen": "graphql-codegen --config codegen.ts && bun run scripts/postcodegen.ts",
|
|
69
81
|
"embed-migrations": "bun run scripts/embed-migrations.ts",
|
|
70
82
|
"typecheck": "tsc --noEmit",
|
|
71
|
-
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
83
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json && chmod +x dist/cli.js",
|
|
72
84
|
"test": "bun test",
|
|
73
85
|
"smoke": "bun test/smoke-dist.mjs && node test/smoke-dist.mjs",
|
|
74
|
-
"check": "bun run typecheck && bun run embed-migrations -- --check && bun test && bun run build && bun run smoke",
|
|
86
|
+
"check": "bun run typecheck && bun run embed-migrations -- --check && bun run embed-reference -- --check && bun test && bun run build && bun run smoke && bun run test:bin && bun run check:publish",
|
|
75
87
|
"test:conformance": "bun run build && vitest run --config vitest.config.ts",
|
|
76
88
|
"test:example": "bun run test/workflow/example-e2e.ts",
|
|
77
|
-
"test:
|
|
89
|
+
"test:birthday": "bun run test/workflow/birthday-e2e.ts",
|
|
90
|
+
"test:cli": "bun --no-install test/remote/cli-e2e.ts",
|
|
91
|
+
"test:bin": "bun --no-install test/cli/bin-e2e.ts",
|
|
92
|
+
"embed-reference": "bun run scripts/embed-reference.ts",
|
|
93
|
+
"check:publish": "bun scripts/check-publish-manifest.ts"
|
|
78
94
|
},
|
|
79
95
|
"peerDependencies": {
|
|
80
96
|
"@workflow/core": "^5.2.0",
|
package/schema/SOURCE.json
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"$comment": "Provenance for the vendored copy of graph/schema.graphqls. Written by scripts/sync-schema.ts — do not edit by hand.",
|
|
3
3
|
"repo": "unfazed",
|
|
4
4
|
"path": "graph/schema.graphqls",
|
|
5
|
-
"unfazedCommit": "
|
|
6
|
-
"schemaLastChangedCommit": "
|
|
7
|
-
"sha256": "
|
|
8
|
-
"syncedAt": "2026-
|
|
5
|
+
"unfazedCommit": "4e49289084964f2d7a43be92e8f3690dea2347ad",
|
|
6
|
+
"schemaLastChangedCommit": "4e49289084964f2d7a43be92e8f3690dea2347ad",
|
|
7
|
+
"sha256": "f881d7b1a54925c51d58074da2f9562b8334be98a477aad681a4f80c4e6ff5c2",
|
|
8
|
+
"syncedAt": "2026-10-22"
|
|
9
9
|
}
|