UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

1 lines • 22.7 kB
{"version":3,"file":"preflight.cjs","names":["fetchResponse","join","existsSync","readFileSync","colors","getNetworkIdForAccount","buildRegistryConfigUrlForNetwork","readSessionHandle","resolveSigningStrategy","describeSigningStrategy","resolveCdnDeployInputs","process","probeStorageOrigin","fetchPublishedConfigFromFastKv","getRegistryNamespaceForNetwork","selectWorkspaceTargets"],"sources":["../../../src/services/deploy/preflight.ts"],"sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport process from \"node:process\";\nimport { selectWorkspaceTargets } from \"../../services/workspace/build-train\";\nimport type { BosConfig, PublishConfig } from \"../../types\";\nimport { fetchResponse } from \"../../utils/http-client\";\nimport { getNetworkIdForAccount } from \"../../utils/network\";\nimport { colors } from \"../../utils/theme\";\nimport {\n describeSigningStrategy,\n resolveSigningStrategy,\n type SigningStrategy,\n} from \"../auth/near-signer\";\nimport type { CustodyWalletRecord, SessionCredential } from \"../auth/session\";\nimport { readSessionHandle } from \"../auth/session\";\nimport {\n buildRegistryConfigUrlForNetwork,\n fetchPublishedConfigFromFastKv,\n getRegistryNamespaceForNetwork,\n type NetworkId,\n} from \"../registry/fastkv\";\nimport { type CdnDeployInputs, probeStorageOrigin, resolveCdnDeployInputs } from \"./cdn\";\n\n/**\n * Pure publish preflight (resolve, don't mutate) — every failure returns\n * before the build train runs (issue #287). Dry-run exits after the auth\n * guards, before any signing (keychain/TTY side effects).\n *\n * The validated auth handles are captured on the plan (guards once per run,\n * ticket #422): the train's submit phase consumes `plan.custodyWallet` /\n * `plan.credential` instead of re-reading and re-validating the session file.\n */\n\nexport type PublishedConfigState = \"fetched\" | \"missing\" | \"unreachable\";\n\nexport interface PublishPreflightPlan {\n isStaging: boolean;\n account: string;\n gateway: string;\n network: NetworkId;\n registryUrl: string;\n registryNamespace: string;\n targets: string[];\n useWallet: boolean;\n useCustody: boolean;\n strategy?: SigningStrategy;\n cdnOrigin: string | undefined;\n storageOrigin: string;\n storageApiKey?: string;\n /** The config currently published to FastKV (null when missing or unreachable). */\n publishedConfig: Record<string, unknown> | null;\n /** Whether the preflight FastKV read succeeded, found nothing, or failed. */\n publishedConfigState: PublishedConfigState;\n /** Validated by the custody guard — present iff useCustody. */\n custodyWallet?: CustodyWalletRecord;\n /** Validated by the session guard — present iff useWallet. */\n credential?: SessionCredential;\n}\n\nexport type PublishPreflight =\n | { kind: \"dry-run\"; registryUrl: string }\n | { kind: \"error\"; registryUrl: string; error: string }\n | { kind: \"ready\"; plan: PublishPreflightPlan };\n\nconst FRAMEWORK_PACKAGE_NAMES = [\"better-near-auth\", \"every-plugin\", \"everything-dev\"] as const;\n\n/**\n * Whether npm serves `name@version` (true), definitively does not (404 —\n * false), or whether publishability could not be determined (network error,\n * unexpected status — null; callers must not block on that).\n */\nexport async function npmVersionPublished(\n name: string,\n version: string,\n options: { bustCache?: boolean } = {},\n): Promise<boolean | null> {\n try {\n // Cache-buster query on the polled path: the registry CDN read-serves\n // <name>/<version> endpoints, so a freshly published version can 404\n // from a stale edge cache; a unique query string always misses it.\n const suffix = options.bustCache ? `?bust=${Date.now()}-${Math.random()}` : \"\";\n const res = await fetchResponse(`https://registry.npmjs.org/${name}/${version}${suffix}`, {\n headers: { Accept: \"application/json\" },\n });\n if (res.status === 200) return true;\n if (res.status === 404) return false;\n return null;\n } catch {\n return null;\n }\n}\n\n/**\n * The npm-publish gate: a workspace that vendors the framework packages'\n * sources must not ship bundles ahead of npm — the update check, child\n * scaffolds (`bos init`), and template syncs all read those versions from\n * the registry. Reads only apply when the sources are workspace-local (the\n * parent repo); child projects install the framework from npm and are\n * inherently in sync.\n */\nexport async function findUnpublishedFrameworkPackages(\n configDir: string,\n options: { probe?: (name: string, version: string) => Promise<boolean | null> } = {},\n): Promise<Array<{ name: string; version: string }>> {\n const probe = options.probe ?? npmVersionPublished;\n const results = await probePackages(readFrameworkPackageManifests(configDir), probe);\n return results\n .filter((entry) => entry.state === false)\n .map((entry) => ({ name: entry.pkg.name, version: entry.pkg.version }));\n}\n\ninterface FrameworkManifest {\n name: (typeof FRAMEWORK_PACKAGE_NAMES)[number];\n version: string;\n}\n\nfunction readFrameworkPackageManifests(configDir: string): Array<FrameworkManifest> {\n const manifests: Array<FrameworkManifest> = [];\n for (const name of FRAMEWORK_PACKAGE_NAMES) {\n const manifestPath = join(configDir, \"packages\", name, \"package.json\");\n if (!existsSync(manifestPath)) continue;\n const version = (JSON.parse(readFileSync(manifestPath, \"utf-8\")) as { version?: string })\n .version;\n if (version) manifests.push({ name, version });\n }\n return manifests;\n}\n\n/** A manifest npm does not (yet) serve, as tracked by the wait loop. */\ninterface UnpublishedPackage {\n name: string;\n version: string;\n}\n\nexport interface FrameworkPublishWaitOptions {\n /** Poll cadence. Default 15s. */\n intervalMs?: number;\n /** Total time to wait for the Release train's publish. Default 15 min. */\n budgetMs?: number;\n /** Injectable sleep (unit tests fast-forward the wait). */\n sleep?: (ms: number) => Promise<void>;\n /** Injectable clock (unit tests drive the budget deterministically). */\n now?: () => number;\n /** Injectable registry probe (unit tests bypass the network). */\n probe?: (name: string, version: string) => Promise<boolean | null>;\n}\n\nexport type FrameworkPublishWait = { kind: \"ok\" } | { kind: \"error\"; error: string };\n\nconst DEFAULT_PUBLISH_WAIT = { intervalMs: 15_000, budgetMs: 15 * 60_000 };\n\n/**\n * Waits out the Deploy/Release race on version-bump merges: both trains\n * trigger on the same push, and the Release workflow needs minutes to\n * publish the bumped versions. Instead of refusing (bundles never ship\n * ahead of the registry — that invariant stands), preflight parks here\n * until every workspace framework version is on npm, up to a bounded\n * budget; a timeout keeps the original fail-loud behavior with a pointer\n * at the Release run.\n */\nexport async function waitForFrameworkPackages(\n configDir: string,\n options: FrameworkPublishWaitOptions = {},\n): Promise<FrameworkPublishWait> {\n const intervalMs = options.intervalMs ?? DEFAULT_PUBLISH_WAIT.intervalMs;\n const budgetMs = options.budgetMs ?? DEFAULT_PUBLISH_WAIT.budgetMs;\n const sleep =\n options.sleep ?? ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms)));\n const now = options.now ?? Date.now;\n const probe =\n options.probe ?? ((name, version) => npmVersionPublished(name, version, { bustCache: true }));\n\n const manifests = readFrameworkPackageManifests(configDir);\n if (manifests.length === 0) return { kind: \"ok\" };\n\n const listing = (packages: Array<UnpublishedPackage>) =>\n packages.map((pkg) => `${pkg.name}@${pkg.version}`).join(\", \");\n\n const states = await probePackages(manifests, probe);\n if (states.every((entry) => entry.state === true)) return { kind: \"ok\" };\n let pending = states.filter((entry) => entry.state === false).map((entry) => entry.pkg);\n\n console.log(\n ` Waiting for the Release workflow to publish ${colors.cyan(listing(pending))} to npm ` +\n `(polling every ${Math.round(intervalMs / 1000)}s, budget ${Math.round(budgetMs / 60_000)} min)`,\n );\n\n const startedAt = now();\n const deadline = startedAt + budgetMs;\n let lastProgressLog = startedAt;\n while (true) {\n await sleep(intervalMs);\n const results = await probePackages(pending, probe);\n for (const entry of results.filter((check) => check.state === true)) {\n console.log(` ✓ ${entry.pkg.name}@${entry.pkg.version} published`);\n }\n pending = results.filter((check) => check.state === false).map((check) => check.pkg);\n if (pending.length === 0) {\n console.log(\" ✓ framework packages cleared the npm gate — resuming the deploy train\");\n return { kind: \"ok\" };\n }\n if (now() >= deadline) {\n return {\n kind: \"error\",\n error:\n `Framework package(s) ${listing(pending)} were not published to npm within ` +\n `${Math.round(budgetMs / 60_000)} min — deploys must not ship bundles ahead of the ` +\n \"registry (child scaffolds and update checks read these versions). The Release \" +\n \"workflow for this commit may still be publishing or may have failed — check its \" +\n \"run, then re-run the deploy once the packages are on npm.\",\n };\n }\n if (now() - lastProgressLog >= 60_000) {\n lastProgressLog = now();\n console.log(\n ` Still unpublished: ${listing(pending)} (${Math.round((now() - startedAt) / 1000)}s elapsed)`,\n );\n }\n }\n}\n\nasync function probePackages(\n packages: Array<UnpublishedPackage>,\n probe: (name: string, version: string) => Promise<boolean | null>,\n): Promise<Array<{ pkg: UnpublishedPackage; state: boolean | null }>> {\n const results: Array<{ pkg: UnpublishedPackage; state: boolean | null }> = [];\n for (const pkg of packages) {\n const state = await probe(pkg.name, pkg.version);\n if (state === null) {\n // Original gate semantics: an unverifiable state never blocks the\n // deploy (registry outage stays a warn-and-continue path).\n console.log(\n colors.yellow(\n ` ! Could not verify ${pkg.name}@${pkg.version} on npm (registry unreachable) — continuing`,\n ),\n );\n }\n results.push({ pkg, state });\n }\n return results;\n}\n\ninterface PreflightInput {\n bosConfig: BosConfig;\n configDir: string;\n env: \"production\" | \"staging\";\n build: boolean;\n dryRun: boolean;\n packages: string;\n network?: \"mainnet\" | \"testnet\";\n privateKey?: string;\n wallet?: boolean;\n registry?: string;\n}\n\nexport async function preflightPublish(input: PreflightInput): Promise<PublishPreflight> {\n const { configDir } = input;\n const bosConfig = input.bosConfig;\n\n const isStaging = input.env === \"staging\";\n const account = isStaging ? (bosConfig.staging?.account ?? bosConfig.account) : bosConfig.account;\n const gateway = isStaging ? (bosConfig.staging?.domain ?? bosConfig.domain) : bosConfig.domain;\n if (!gateway) {\n return {\n kind: \"error\",\n registryUrl: \"\",\n error: \"authored config must define domain to publish\",\n };\n }\n\n const network: NetworkId = input.network ?? getNetworkIdForAccount(account);\n const registryUrl = buildRegistryConfigUrlForNetwork(network, account, gateway, input.registry);\n const fail = (error: string): PublishPreflight => ({ kind: \"error\", registryUrl, error });\n\n // One session-file read for the whole run (guards once, ticket #422): the\n // wallet/custody guards validate + capture their handles on the plan, and\n // CDN credential derivation consumes the raw credential as before.\n const sessionFile = readSessionHandle(configDir);\n const publishAuth: PublishConfig[\"auth\"] = bosConfig.publish?.auth;\n const governsWalletPublish = (publishAuth === \"session\" || input.wallet) && !input.privateKey;\n let credential: SessionCredential | undefined;\n if (governsWalletPublish) {\n if (!sessionFile?.credential) {\n return fail(\n (input.wallet\n ? \"--wallet requires\"\n : 'the authored config sets publish.auth = \"session\", but') +\n \" no CLI session is stored in .bos/ for this project. Run bos login to create one.\",\n );\n }\n if (sessionFile.credential.accountId && sessionFile.credential.accountId !== account) {\n return fail(\n `The CLI session was created for ${sessionFile.credential.accountId}, but the configured ` +\n `account is ${account}. Gasless wallet publish relays the FastKV write under the session's ` +\n \"NEAR account. Run bos login again under the matching account.\",\n );\n }\n credential = sessionFile.credential;\n }\n const useCustody = publishAuth === \"custody\" && !input.privateKey && !input.wallet;\n let custodyWallet: CustodyWalletRecord | undefined;\n if (useCustody) {\n const wallet = sessionFile?.custodyWallet;\n if (!wallet) {\n return fail(\n 'the authored config sets publish.auth = \"custody\", but no custody wallet is stored in ' +\n \".bos/. Run `bos login --custody` first.\",\n );\n }\n if (wallet.network !== network) {\n return fail(\n `The custody wallet was registered on ${wallet.network}, but this project publishes ` +\n `on ${network}. Run \\`bos login --custody\\` from a ${network} account.`,\n );\n }\n if (wallet.nearAccountId !== account) {\n return fail(\n `publish.auth = \"custody\" publishes under the custody wallet's account, but the configured ` +\n `account is ${account} and the custody wallet account is ${wallet.nearAccountId}. ` +\n \"Set the authored config's account to the custody wallet account.\",\n );\n }\n custodyWallet = wallet;\n }\n\n if (input.dryRun) {\n return { kind: \"dry-run\", registryUrl };\n }\n\n const useWallet = input.wallet === true;\n let strategy: SigningStrategy | undefined;\n if (useWallet) {\n console.log(\n ` Signing via ${colors.cyan(\"gasless NEP-366 delegate action (relayed by the platform relayer)\")}`,\n );\n } else {\n try {\n strategy = await resolveSigningStrategy({ privateKey: input.privateKey, account, network });\n console.log(` Signing via ${colors.cyan(describeSigningStrategy(strategy))}`);\n } catch (error) {\n return fail(error instanceof Error ? error.message : \"Unknown error\");\n }\n }\n\n // CDN deploy credentials (ADR 0020) — resolved before the build train so a\n // missing bundle origin or BOS_STORAGE_API_KEY fails fast instead of after\n // the full build. Config-only publishes ship the committed config verbatim;\n // nothing is uploaded, so no deploy origins are required.\n let cdnDeploy: CdnDeployInputs = {\n cdnOrigin: undefined,\n storageOrigin: \"\",\n apiKey: undefined,\n };\n if (input.build) {\n const wait = await waitForFrameworkPackages(configDir);\n if (wait.kind === \"error\") {\n return fail(wait.error);\n }\n\n cdnDeploy = resolveCdnDeployInputs({\n env: process.env as Record<string, string | undefined>,\n bosConfig,\n session: sessionFile?.credential ?? null,\n custodyAccount: useCustody ? custodyWallet?.nearAccountId : undefined,\n account,\n gateway,\n uploadsPlanned: input.build,\n });\n if (cdnDeploy.error) {\n return fail(cdnDeploy.error);\n }\n if (cdnDeploy.warning) {\n console.log(colors.yellow(` ! ${cdnDeploy.warning}`));\n }\n const cdnOrigin = cdnDeploy.cdnOrigin;\n if (!cdnOrigin) {\n return fail(\"CDN deploy resolved no bundle origin\");\n }\n const probeError = await probeStorageOrigin(cdnDeploy.storageOrigin);\n if (probeError) {\n return fail(\n `The bundle upload origin ${cdnDeploy.storageOrigin} is not running the platform API — ` +\n `${probeError}. Check BOS_STORAGE_ORIGIN / the bos login session, then re-run.`,\n );\n }\n }\n\n // Registry reachability + published-state capture: one FastKV read. A\n // missing config is fine for a first publish — an early signal, not a hard\n // gate. The captured config is the merge base for a config-only publish on\n // a TS-form project (authored hand-edits win; live pipeline state carries).\n let publishedConfig: Record<string, unknown> | null = null;\n let publishedConfigState: PublishedConfigState = \"missing\";\n try {\n publishedConfig = await fetchPublishedConfigFromFastKv<Record<string, unknown>>(registryUrl);\n publishedConfigState = \"fetched\";\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n if (message.startsWith(\"No config found\")) {\n console.log(colors.dim(\" Note: no published config found yet (first publish) — continuing\"));\n } else {\n publishedConfigState = \"unreachable\";\n console.log(colors.dim(\" Note: registry read failed — continuing\"));\n }\n }\n\n return {\n kind: \"ready\",\n plan: {\n isStaging,\n account,\n gateway,\n network,\n registryUrl,\n registryNamespace: getRegistryNamespaceForNetwork(network, input.registry),\n targets: selectWorkspaceTargets(input.packages, bosConfig),\n useWallet,\n useCustody,\n strategy,\n cdnOrigin: cdnDeploy.cdnOrigin,\n storageOrigin: cdnDeploy.storageOrigin,\n storageApiKey: cdnDeploy.apiK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