@dragonmastery/tamer 0.31.0 → 0.31.4

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.
Files changed (46) hide show
  1. package/dist/{apply-BjrYbyHn.mjs → apply-C_70Hgcf.mjs} +7 -7
  2. package/dist/{apply-BjrYbyHn.mjs.map → apply-C_70Hgcf.mjs.map} +1 -1
  3. package/dist/{bootstrap-D__dHw1w.mjs → bootstrap-CQS5s33A.mjs} +2 -2
  4. package/dist/{bootstrap-D__dHw1w.mjs.map → bootstrap-CQS5s33A.mjs.map} +1 -1
  5. package/dist/{cloudflareSnapshot-C6cF8GG8.mjs → cloudflareSnapshot-CFErW72O.mjs} +3 -3
  6. package/dist/{cloudflareSnapshot-C6cF8GG8.mjs.map → cloudflareSnapshot-CFErW72O.mjs.map} +1 -1
  7. package/dist/{deploy-C6fX9td0.mjs → deploy-D-GXzsWR.mjs} +4 -4
  8. package/dist/{deploy-C6fX9td0.mjs.map → deploy-D-GXzsWR.mjs.map} +1 -1
  9. package/dist/{destroy-vfk2Zbfj.mjs → destroy-DJRw_qLX.mjs} +7 -7
  10. package/dist/{destroy-vfk2Zbfj.mjs.map → destroy-DJRw_qLX.mjs.map} +1 -1
  11. package/dist/{destroy-tenant-T_94ed9x.mjs → destroy-tenant-DFHfNImL.mjs} +2 -2
  12. package/dist/{destroy-tenant-T_94ed9x.mjs.map → destroy-tenant-DFHfNImL.mjs.map} +1 -1
  13. package/dist/{dev-BLthyLml.mjs → dev-caJxohHI.mjs} +4 -4
  14. package/dist/{dev-BLthyLml.mjs.map → dev-caJxohHI.mjs.map} +1 -1
  15. package/dist/{dns-records.sync-DqYROe07.mjs → dns-records.sync-Ck0Q2OK3.mjs} +2 -2
  16. package/dist/{dns-records.sync-DqYROe07.mjs.map → dns-records.sync-Ck0Q2OK3.mjs.map} +1 -1
  17. package/dist/{drift-BCxWdYHG.mjs → drift-5_LwAdZo.mjs} +3 -3
  18. package/dist/{drift-CeemyFqL.mjs → drift-C-qnJ-mH.mjs} +4 -4
  19. package/dist/{drift-CeemyFqL.mjs.map → drift-C-qnJ-mH.mjs.map} +1 -1
  20. package/dist/{events-otk0l3aJ.mjs → events-Bor7XgLC.mjs} +2 -2
  21. package/dist/{events-otk0l3aJ.mjs.map → events-Bor7XgLC.mjs.map} +1 -1
  22. package/dist/{import-OvohE-H2.mjs → import-Vn9lhWic.mjs} +2 -2
  23. package/dist/{import-OvohE-H2.mjs.map → import-Vn9lhWic.mjs.map} +1 -1
  24. package/dist/{migrate-CroDjbJz.mjs → migrate-skvsDG6d.mjs} +2 -2
  25. package/dist/{migrate-CroDjbJz.mjs.map → migrate-skvsDG6d.mjs.map} +1 -1
  26. package/dist/{plan-C2urqJOz.mjs → plan-BLy8FaE2.mjs} +6 -6
  27. package/dist/{plan-C2urqJOz.mjs.map → plan-BLy8FaE2.mjs.map} +1 -1
  28. package/dist/{provision-tenant-BJ1KugON.mjs → provision-tenant-CleOYFwr.mjs} +2 -2
  29. package/dist/{provision-tenant-BJ1KugON.mjs.map → provision-tenant-CleOYFwr.mjs.map} +1 -1
  30. package/dist/{stackOutputs-Cltzl2g0.mjs → stackOutputs-BLvUMsQO.mjs} +2 -2
  31. package/dist/{stackOutputs-Cltzl2g0.mjs.map → stackOutputs-BLvUMsQO.mjs.map} +1 -1
  32. package/dist/{status-DkkS5lc9.mjs → status-BxStsax8.mjs} +3 -3
  33. package/dist/{status-DkkS5lc9.mjs.map → status-BxStsax8.mjs.map} +1 -1
  34. package/dist/{sync-CpfxqlOx.mjs → sync-KTzMVc_o.mjs} +4 -4
  35. package/dist/{sync-CpfxqlOx.mjs.map → sync-KTzMVc_o.mjs.map} +1 -1
  36. package/dist/tamer.mjs +325 -250
  37. package/dist/tamer.mjs.map +1 -1
  38. package/dist/{types-BzzHwIdw.mjs → types-D7qKnGsm.mjs} +2 -2
  39. package/dist/{types-BzzHwIdw.mjs.map → types-D7qKnGsm.mjs.map} +1 -1
  40. package/dist/{verifyPlanFile-BmEadIqm.mjs → verifyPlanFile-CR2bELdE.mjs} +2 -2
  41. package/dist/{verifyPlanFile-BmEadIqm.mjs.map → verifyPlanFile-CR2bELdE.mjs.map} +1 -1
  42. package/dist/{worker-route-x8q3K4-z.mjs → worker-route-tOqVbhv3.mjs} +2 -2
  43. package/dist/{worker-route-x8q3K4-z.mjs.map → worker-route-tOqVbhv3.mjs.map} +1 -1
  44. package/dist/{workers-D3Ekf3mF.mjs → workers-6r2ONF9J.mjs} +2 -2
  45. package/dist/{workers-D3Ekf3mF.mjs.map → workers-6r2ONF9J.mjs.map} +1 -1
  46. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"plan-C2urqJOz.mjs","names":["items: PlanItem[]","byKind: Record<PlanResourceKind, number>","byAction: Record<PlanAction, number>","attestation"],"sources":["../src/core/plan/computePlan.ts","../src/core/plan/plan.types.ts","../src/cli/commands/plan.ts"],"sourcesContent":["import { loadConfig, getWorkers } from \"../config/loader.js\";\nimport { cloudflareAccountIdFromEnv } from \"../cloudflareEnv.js\";\nimport { namingFromConfig } from \"../config/namingFromConfig.js\";\nimport { StateManager } from \"../state/StateManager.js\";\nimport { stackNameForConfig } from \"../state/stackName.js\";\nimport { fetchStackImports } from \"../imports/fetchStackImports.js\";\nimport { CFApiClient } from \"../api/CFApiClient.js\";\nimport { computeDriftReport } from \"../../cli/commands/drift.js\";\nimport { resolveWorkerConfig } from \"../config/resolver.js\";\nimport { resourceModules } from \"../registry/registry.js\";\nimport { logicalNamesForResourceKind } from \"../config/resourcesFromConfig.js\";\nimport { resolveDeployedWorkerName } from \"../config/resolver.js\";\nimport { requiredSecretsForWorker } from \"../secrets/declared.js\";\nimport {\n reconcileSecrets,\n secretsPlanItems,\n vaultReaderFromMap,\n type SecretsVaultReader,\n type VaultSecretMeta,\n} from \"../secrets/reconcile.js\";\nimport { getDispatchNamespaces, getDnsRecords, getLogpushJobs } from \"../../types.js\";\nimport { logpushJobStateKey } from \"../../features/logpush-job/logpush-job.resolve.js\";\nimport { logpushJobDiffPlanItems } from \"../../features/logpush-job/logpush-job.diff.js\";\nimport {\n dnsRecordDiffPlanItems,\n} from \"../../features/dns-records/dns-records.diff.js\";\nimport { dnsRecordStateKey } from \"../../features/dns-records/dns-records.resolve.js\";\nimport type { StateEntry } from \"../../types.js\";\nimport type { PlanItem, PlanReport, PlanResourceKind } from \"./plan.types.js\";\nimport {\n filterPlanItemsForTarget,\n type ApplyTarget,\n} from \"../apply/applyTarget.js\";\n\n/**\n * Compute the planned set of changes for `env` given the current\n * `tamer.config.ts` and recorded state. Read-only: hits the Cloudflare API to\n * detect what is missing but never writes.\n *\n * The \"would create\" set is derived from `computeDriftReport().undeployed`:\n * declared in config, present neither in state nor on Cloudflare. Worker\n * **scripts** are queried directly (`workersScriptGet`) since they are not\n * tracked as state resources today.\n */\nexport async function computePlan(options: {\n env?: string;\n configPath?: string;\n /** When set, only plan items for this `kind:logical` are returned. */\n target?: ApplyTarget;\n /** Optional vault reader for secret reconciliation (defaults to empty). */\n secretsVault?: SecretsVaultReader;\n}): Promise<PlanReport> {\n const env = options.env ?? \"local\";\n const configPath = options.configPath;\n const baseDir = process.cwd();\n const target = options.target;\n\n const config = await loadConfig(configPath, { env });\n const accountId = config.account_id ?? cloudflareAccountIdFromEnv();\n if (!accountId) {\n throw new Error(\n \"account_id required in config or CLOUDFLARE_ACCOUNT_ID env var\",\n );\n }\n\n const drift = await computeDriftReport({ env, configPath });\n\n const items: PlanItem[] = [];\n\n for (const r of drift.resources) {\n const kind = mapDriftKind(r.kind);\n if (!kind) continue;\n for (const e of r.undeployed) {\n items.push({\n kind,\n action: \"create\",\n logicalName: e.logicalName,\n derivedName: e.derivedName,\n detail: e.detail,\n });\n }\n }\n\n if (env !== \"local\") {\n const api = new CFApiClient(accountId);\n const naming = namingFromConfig(config);\n const state = new StateManager(\n config.tenant.id,\n env,\n stackNameForConfig(config),\n );\n await state.hydrate(api);\n // Tolerant pre-fetch: missing sibling state isn't fatal here (plan\n // is read-only) but populating imports lets the resolver substitute\n // real values instead of leaving placeholders.\n const imports = await fetchStackImports(api, config, env);\n\n const dnsItems = dnsRecordDiffPlanItems({\n resources: getDnsRecords(config),\n tenant: config.tenant,\n env,\n state,\n });\n items.push(...dnsItems);\n\n const logpushPlanItems = await logpushJobDiffPlanItems({\n resources: getLogpushJobs(config),\n tenant: config.tenant,\n env,\n state,\n api,\n accountId,\n });\n items.push(...logpushPlanItems);\n\n const workers = await getWorkers(config, baseDir);\n for (const [workerKey, wc] of workers) {\n const resolved = await resolveWorkerConfig(\n config,\n workerKey,\n wc,\n env,\n baseDir,\n accountId,\n naming,\n state,\n { referencesMode: \"tolerant\", imports },\n );\n if (resolved.dispatchNamespace) continue;\n\n const deployedName = resolveDeployedWorkerName(\n config,\n workerKey,\n wc,\n env,\n naming,\n );\n for (const mod of resourceModules) {\n if (!mod.diff) continue;\n const resources = mod.pickResources(wc);\n if (resources.length === 0) continue;\n const diffItems = mod.diff({\n resources,\n tenant: config.tenant,\n env,\n state,\n naming,\n worker: { workerKey, deployedName },\n });\n items.push(...diffItems);\n }\n\n let script;\n try {\n script = await api.workersScriptGet(resolved.workerName);\n } catch {\n continue;\n }\n if (!script) {\n items.push({\n kind: \"worker_script\",\n action: \"create\",\n logicalName: workerKey,\n derivedName: resolved.workerName,\n });\n }\n\n const required = requiredSecretsForWorker(wc);\n if (required.length > 0) {\n const workerSecretNames = await safeWorkersSecretsList(\n api,\n resolved.workerName,\n );\n const secretEntries = await reconcileSecrets({\n workers: [\n {\n workerKey,\n required,\n workerSecretNames,\n },\n ],\n vault: options.secretsVault ?? emptySecretsVault(),\n state,\n });\n items.push(...secretsPlanItems(secretEntries));\n }\n }\n }\n\n const filtered = target ? filterPlanItemsForTarget(items, target) : items;\n\n return {\n tenantId: config.tenant.id,\n env,\n generatedAt: new Date().toISOString(),\n items: filtered,\n hasChanges: filtered.some((i) => i.action !== \"no_change\"),\n mode: \"forward\",\n };\n}\n\n/**\n * Compute the planned set of **deletions** for `env` — what `tamer destroy`\n * would remove given the current `tamer.config.ts` and recorded state.\n *\n * Read-only: hits the Cloudflare API only to confirm worker scripts exist,\n * never writes. Items are stack-scoped: only state entries whose\n * `logicalName` is declared on a worker in the current config are emitted —\n * resources owned by another stack sharing the same `tamer-state-{env}` row\n * are **not** included (matches `runDestroy` semantics).\n *\n * Worker scripts are listed when the deployed name actually exists on\n * Cloudflare; dispatch-namespace tenant scripts are intentionally excluded\n * (they are managed via `provision-tenant` / `destroy-tenant`).\n */\nexport async function computeDestroyPlan(options: {\n env?: string;\n configPath?: string;\n target?: ApplyTarget;\n}): Promise<PlanReport> {\n const env = options.env ?? \"local\";\n const configPath = options.configPath;\n const baseDir = process.cwd();\n const target = options.target;\n\n const config = await loadConfig(configPath, { env });\n const accountId = config.account_id ?? cloudflareAccountIdFromEnv();\n if (!accountId) {\n throw new Error(\n \"account_id required in config or CLOUDFLARE_ACCOUNT_ID env var\",\n );\n }\n\n const items: PlanItem[] = [];\n const generatedAt = new Date().toISOString();\n\n if (env === \"local\") {\n return {\n tenantId: config.tenant.id,\n env,\n generatedAt,\n items,\n hasChanges: false,\n mode: \"destroy\",\n };\n }\n\n const api = new CFApiClient(accountId);\n const naming = namingFromConfig(config);\n const state = new StateManager(\n config.tenant.id,\n env,\n stackNameForConfig(config),\n );\n await state.hydrate(api);\n const imports = await fetchStackImports(api, config, env);\n\n const stateEntries = state.getAll();\n\n for (const mod of resourceModules) {\n const owned = await logicalNamesForResourceKind(config, baseDir, mod.kind);\n if (owned.size === 0) continue;\n const kind = mapDriftKind(mod.kind);\n if (!kind) continue;\n for (const [, entry] of Object.entries(stateEntries)) {\n if (entry.type !== mod.stateEntryType) continue;\n const logicalName = (entry as { logicalName?: string }).logicalName;\n if (!logicalName || !owned.has(logicalName)) continue;\n items.push({\n kind,\n action: \"delete\",\n logicalName,\n derivedName: derivedNameOf(entry),\n });\n }\n }\n\n for (const [, entry] of Object.entries(stateEntries)) {\n if (entry.type !== \"worker_route\") continue;\n items.push({\n kind: \"worker_route\",\n action: \"delete\",\n logicalName: entry.workerKey,\n derivedName: entry.pattern,\n detail: entry.zoneName,\n });\n }\n\n for (const ns of getDispatchNamespaces(config)) {\n const stateKey = `dispatch_namespace:${ns.logicalName}`;\n const entry = stateEntries[stateKey];\n if (!entry || entry.type !== \"dispatch_namespace\") continue;\n items.push({\n kind: \"dispatch_namespace\",\n action: \"delete\",\n logicalName: ns.logicalName,\n derivedName: entry.derivedName,\n });\n }\n\n for (const dns of getDnsRecords(config)) {\n if (dns.preserveOnDestroy) continue;\n const key = dnsRecordStateKey(dns.zoneId, dns.type, dns.name);\n const entry = stateEntries[key];\n if (!entry || entry.type !== \"dns_record\") continue;\n items.push({\n kind: \"dns_record\",\n action: \"delete\",\n logicalName: dns.logicalName,\n derivedName: `${entry.recordType} ${entry.name}`,\n detail: entry.recordId,\n });\n }\n\n for (const lp of getLogpushJobs(config)) {\n const key = logpushJobStateKey(config.tenant.id, lp.logicalName, env);\n const entry = stateEntries[key];\n if (!entry || entry.type !== \"logpush_job\") continue;\n items.push({\n kind: \"logpush_job\",\n action: \"delete\",\n logicalName: lp.logicalName,\n derivedName: entry.derivedName,\n detail: String(entry.cfJobId),\n });\n }\n\n const workers = await getWorkers(config, baseDir);\n for (const [workerKey, wc] of workers) {\n const resolved = await resolveWorkerConfig(\n config,\n workerKey,\n wc,\n env,\n baseDir,\n accountId,\n naming,\n state,\n { referencesMode: \"tolerant\", imports },\n );\n if (resolved.dispatchNamespace) continue;\n const deployedName = resolveDeployedWorkerName(\n config,\n workerKey,\n wc,\n env,\n naming,\n );\n let script;\n try {\n script = await api.workersScriptGet(deployedName);\n } catch {\n continue;\n }\n if (script) {\n items.push({\n kind: \"worker_script\",\n action: \"delete\",\n logicalName: workerKey,\n derivedName: deployedName,\n });\n }\n }\n\n const filtered = target ? filterPlanItemsForTarget(items, target) : items;\n\n return {\n tenantId: config.tenant.id,\n env,\n generatedAt,\n items: filtered,\n hasChanges: filtered.length > 0,\n mode: \"destroy\",\n };\n}\n\nfunction derivedNameOf(entry: StateEntry): string {\n switch (entry.type) {\n case \"d1_database\":\n case \"r2_bucket\":\n case \"kv_namespace\":\n case \"queue\":\n case \"hyperdrive\":\n case \"vectorize\":\n case \"ai_gateway\":\n case \"pipeline\":\n case \"workflow\":\n case \"secrets_store\":\n case \"dispatch_namespace\":\n return entry.derivedName;\n case \"dns_record\":\n return `${entry.recordType} ${entry.name}`;\n case \"worker_route\":\n return entry.pattern;\n case \"logpush_job\":\n return entry.derivedName;\n case \"logpush_pipelines\":\n return entry.pipelineName;\n case \"secret\":\n return `${entry.worker}:${entry.name}`;\n }\n}\n\nfunction emptySecretsVault(): SecretsVaultReader {\n return vaultReaderFromMap({});\n}\n\nasync function safeWorkersSecretsList(\n api: CFApiClient,\n scriptName: string,\n): Promise<string[]> {\n try {\n return await api.workersSecretsList(scriptName);\n } catch {\n return [];\n }\n}\n\nfunction mapDriftKind(kind: string): PlanResourceKind | undefined {\n switch (kind) {\n case \"d1\":\n case \"r2\":\n case \"kv\":\n case \"queue\":\n case \"hyperdrive\":\n case \"vectorize\":\n case \"ai_gateway\":\n case \"pipeline\":\n case \"workflow\":\n case \"secret_store\":\n case \"secret\":\n case \"dns_record\":\n case \"dispatch_namespace\":\n case \"logpush_job\":\n case \"worker_route\":\n return kind;\n default:\n return undefined;\n }\n}\n","/**\n * Read-only \"plan\" — the CloudFormation-style preview of changes Tamer would\n * make if you ran `apply` and then `deploy` against the current state +\n * config. Pure: never writes to state or to Cloudflare.\n */\n\nexport type PlanResourceKind =\n | \"d1\"\n | \"r2\"\n | \"kv\"\n | \"queue\"\n | \"hyperdrive\"\n | \"vectorize\"\n | \"ai_gateway\"\n | \"pipeline\"\n | \"workflow\"\n | \"secret_store\"\n | \"secret\"\n | \"dns_record\"\n | \"dispatch_namespace\"\n | \"logpush_job\"\n | \"worker_route\"\n | \"worker_script\";\n\n/**\n * Plan actions, in CloudFormation / Terraform terms:\n *\n * - `create` — declared in config, missing on Cloudflare and in state.\n * - `update` — tracked + present, but **mutable** fields drifted from config →\n * `apply` would PATCH in place. No replacement.\n * - `replace` — tracked + present, but **immutable** fields drifted from\n * config → `apply` must delete + recreate (Cloudflare APIs that reject\n * PATCH on the changed field, e.g. DNS record `type`, Vectorize\n * `dimensions` / `metric`, Pipelines V1 `sql`). The state row's `cfId`\n * will change.\n * - `delete` — destroy-plan only.\n * - `no_change` — declared, present, fully in sync.\n */\nexport type PlanAction =\n | \"create\"\n | \"update\"\n | \"replace\"\n | \"delete\"\n | \"no_change\";\n\n/**\n * Direction of the plan: forward (the default — what `apply` + `deploy` would\n * change) or destroy (what `destroy` would remove). Plans are mutually\n * exclusive: a forward plan never includes `delete`, and a destroy plan\n * never includes `create` / `update` / `replace`.\n */\nexport type PlanMode = \"forward\" | \"destroy\";\n\n/**\n * Describes one drifted field in an `update` / `replace` plan item — the\n * field path, what state currently holds, and what config wants. Surfaced in\n * `tamer plan --json` so reviewers can audit the change exactly the way\n * `terraform plan` shows attribute diffs.\n */\nexport interface PlanFieldChange {\n field: string;\n from: unknown;\n to: unknown;\n /**\n * `mutable` → would patch in place; `immutable` → forces `replace` (the\n * underlying Cloudflare resource will be destroyed + recreated, and the\n * state row's `cfId` will change).\n */\n kind: \"mutable\" | \"immutable\";\n}\n\nexport interface PlanItem {\n kind: PlanResourceKind;\n action: PlanAction;\n /** Logical name from `tamer.config.ts` (or worker key for scripts/routes). */\n logicalName: string;\n /** Cloudflare-side identifier (resource name or pattern). */\n derivedName: string;\n /** Optional human-readable detail. */\n detail?: string;\n /**\n * Field-level diff for `update` / `replace` items. Empty for `create` /\n * `delete` / `no_change`. Each entry shows what state has (`from`) and what\n * config asks for (`to`).\n */\n changes?: PlanFieldChange[];\n}\n\nexport interface PlanReport {\n tenantId: string;\n env: string;\n generatedAt: string;\n items: PlanItem[];\n /** True iff at least one item has `action !== \"no_change\"`. */\n hasChanges: boolean;\n /** Plan direction. Defaults to `\"forward\"` for back-compat with v0.11 plans. */\n mode?: PlanMode;\n}\n\nexport function planSummary(items: PlanItem[]): {\n byKind: Record<PlanResourceKind, number>;\n byAction: Record<PlanAction, number>;\n} {\n const byKind: Record<PlanResourceKind, number> = {\n d1: 0,\n r2: 0,\n kv: 0,\n queue: 0,\n hyperdrive: 0,\n vectorize: 0,\n ai_gateway: 0,\n pipeline: 0,\n workflow: 0,\n secret_store: 0,\n secret: 0,\n dns_record: 0,\n dispatch_namespace: 0,\n logpush_job: 0,\n worker_route: 0,\n worker_script: 0,\n };\n const byAction: Record<PlanAction, number> = {\n create: 0,\n update: 0,\n replace: 0,\n delete: 0,\n no_change: 0,\n };\n for (const it of items) {\n if (it.action === \"no_change\") continue;\n byKind[it.kind]++;\n byAction[it.action]++;\n }\n return { byKind, byAction };\n}\n","import { computePlan, computeDestroyPlan } from \"../../core/plan/computePlan.js\";\nimport { planSummary } from \"../../core/plan/plan.types.js\";\nimport type {\n PlanItem,\n PlanReport,\n PlanResourceKind,\n} from \"../../core/plan/plan.types.js\";\nimport { formatPlanFieldChanges, signFor } from \"../../core/plan/planFormat.js\";\nimport { loadConfig } from \"../../core/config/loader.js\";\nimport { cloudflareAccountIdFromEnv } from \"../../core/cloudflareEnv.js\";\nimport { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { StateManager } from \"../../core/state/StateManager.js\";\nimport { stackNameForConfig } from \"../../core/state/stackName.js\";\nimport {\n PLAN_FILE_FORMAT,\n computeAttestation,\n writePlanFile,\n} from \"../../core/plan/planFile.js\";\nimport { createEmptyCfiState } from \"../../core/state/tamerStateDb.js\";\nimport { buildCloudflareSnapshot } from \"../../core/plan/cloudflareSnapshot.js\";\nimport {\n parseApplyTarget,\n assertApplyTargetDeclared,\n} from \"../../core/apply/applyTarget.js\";\n\n/**\n * `tamer plan` — print a CloudFormation-style preview of `apply` + `deploy`\n * against the current state, config, and Cloudflare reality. Never mutates.\n *\n * Exit codes:\n * 0 — plan succeeded; with `--detailed-exitcode`, also \"no changes\".\n * 2 — plan succeeded **and** has at least one create/update (with\n * `--detailed-exitcode`); useful for CI gates that want to fail when\n * infra would change.\n */\nexport async function runPlan(options: {\n env?: string;\n configPath?: string;\n json?: boolean;\n detailedExitcode?: boolean;\n /** When set, write the plan + attestation hashes to this path. */\n out?: string;\n /**\n * When true, compute a **destroy plan** (what `tamer destroy` would remove\n * from state and Cloudflare) instead of the default forward plan. Mutually\n * exclusive with the forward plan — destroy plans only contain `delete`\n * items, never `create` / `update`. Read-only.\n */\n destroy?: boolean;\n /** `kind:logicalName` — restrict plan items to that resource. */\n target?: string;\n}): Promise<number> {\n if (options.out && options.target) {\n throw new Error(\n \"Cannot combine --out with --target: saved plans must cover the full stack.\",\n );\n }\n\n const target = options.target\n ? parseApplyTarget(options.target)\n : undefined;\n if (target) {\n const config = await loadConfig(options.configPath, {\n env: options.env ?? \"local\",\n });\n await assertApplyTargetDeclared(config, process.cwd(), target);\n }\n\n const report = options.destroy\n ? await computeDestroyPlan({\n env: options.env,\n configPath: options.configPath,\n target,\n })\n : await computePlan({\n env: options.env,\n configPath: options.configPath,\n target,\n });\n\n if (options.out) {\n await writePlanForApply(options.out, report, options.configPath);\n }\n\n if (options.json) {\n console.log(JSON.stringify(report, null, 2));\n } else {\n printHumanPlan(report);\n if (options.out) {\n console.log(`Plan written to ${options.out}\\n`);\n }\n }\n\n if (options.detailedExitcode && report.hasChanges) {\n return 2;\n }\n return 0;\n}\n\n/**\n * Hydrate the same `(config, state)` pair `computePlan` consumed and write\n * a {@link PlanFile} with the attestation hashes pinned. `apply --plan`\n * recomputes both hashes and refuses to proceed if either drifted, so a\n * stale plan can never silently apply against changed inputs.\n */\nasync function writePlanForApply(\n outPath: string,\n report: PlanReport,\n configPath: string | undefined,\n): Promise<void> {\n const config = await loadConfig(configPath, { env: report.env });\n if (report.env === \"local\") {\n const attestation = computeAttestation(\n config,\n createEmptyCfiState(config.tenant.id, \"local\"),\n );\n writePlanFile(outPath, {\n format: PLAN_FILE_FORMAT,\n tenantId: config.tenant.id,\n env: report.env,\n generatedAt: report.generatedAt,\n report,\n attestation,\n });\n return;\n }\n\n const accountId = config.account_id ?? cloudflareAccountIdFromEnv();\n if (!accountId) {\n throw new Error(\n \"account_id required in config or CLOUDFLARE_ACCOUNT_ID env var\",\n );\n }\n const api = new CFApiClient(accountId);\n const state = new StateManager(\n config.tenant.id,\n report.env,\n stackNameForConfig(config),\n );\n await state.hydrate(api);\n const cloudflareSnapshot = await buildCloudflareSnapshot({\n config,\n env: report.env,\n api,\n baseDir: process.cwd(),\n });\n const attestation = computeAttestation(\n config,\n state.load(),\n cloudflareSnapshot,\n );\n writePlanFile(outPath, {\n format: PLAN_FILE_FORMAT,\n tenantId: config.tenant.id,\n env: report.env,\n generatedAt: report.generatedAt,\n report,\n attestation,\n });\n}\n\nfunction printHumanPlan(report: PlanReport): void {\n const isDestroy = report.mode === \"destroy\";\n const heading = isDestroy ? \"Destroy plan\" : \"Plan\";\n console.log(\n `\\n${heading} — tenant ${report.tenantId}, env ${report.env}\\n`,\n );\n if (report.items.length === 0) {\n if (isDestroy) {\n console.log(\" (nothing to destroy — no managed resources in state)\\n\");\n } else {\n console.log(\" (no changes — infrastructure matches config)\\n\");\n }\n return;\n }\n const grouped = new Map<PlanResourceKind, PlanItem[]>();\n for (const it of report.items) {\n const arr = grouped.get(it.kind) ?? [];\n arr.push(it);\n grouped.set(it.kind, arr);\n }\n for (const [kind, items] of grouped) {\n console.log(`${labelFor(kind)} (${items.length}):`);\n for (const it of items) {\n const sign = signFor(it.action);\n // Suppress `detail` on update/replace items when we have a structured\n // `changes[]` block — the per-field renderer below already shows the\n // same drift in terraform-style form, and printing both duplicates\n // the diff and clutters the output.\n const hasChanges = it.changes && it.changes.length > 0;\n const detail = it.detail && !hasChanges ? ` (${it.detail})` : \"\";\n console.log(` ${sign} ${it.logicalName} -> ${it.derivedName}${detail}`);\n for (const line of formatPlanFieldChanges(it.changes)) {\n console.log(line);\n }\n }\n }\n const { byAction } = planSummary(report.items);\n if (isDestroy) {\n console.log(`\\nSummary: ${byAction.delete} to delete.\\n`);\n } else {\n console.log(\n `\\nSummary: ${byAction.create} to create, ${byAction.update} to update, ${byAction.replace} to replace.\\n`,\n );\n }\n}\n\nfunction labelFor(kind: PlanResourceKind): string {\n switch (kind) {\n case \"d1\":\n return \"D1\";\n case \"r2\":\n return \"R2\";\n case \"kv\":\n return \"KV\";\n case \"queue\":\n return \"Queues\";\n case \"hyperdrive\":\n return \"Hyperdrive\";\n case \"vectorize\":\n return \"Vectorize\";\n case \"ai_gateway\":\n return \"AI Gateway\";\n case \"pipeline\":\n return \"Pipeline\";\n case \"workflow\":\n return \"Workflow\";\n case \"secret_store\":\n return \"Secrets Store\";\n case \"secret\":\n return \"Worker secrets\";\n case \"dns_record\":\n return \"DNS records\";\n case \"dispatch_namespace\":\n return \"Dispatch namespaces\";\n case \"logpush_job\":\n return \"Logpush jobs\";\n case \"worker_route\":\n return \"Workers zone routes\";\n case \"worker_script\":\n return \"Worker scripts\";\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA4CA,eAAsB,YAAY,SAOV;CACtB,MAAM,MAAM,QAAQ,OAAO;CAC3B,MAAM,aAAa,QAAQ;CAC3B,MAAM,UAAU,QAAQ,KAAK;CAC7B,MAAM,SAAS,QAAQ;CAEvB,MAAM,SAAS,MAAM,WAAW,YAAY,EAAE,KAAK,CAAC;CACpD,MAAM,YAAY,OAAO,cAAc,4BAA4B;AACnE,KAAI,CAAC,UACH,OAAM,IAAI,MACR,iEACD;CAGH,MAAM,QAAQ,MAAM,mBAAmB;EAAE;EAAK;EAAY,CAAC;CAE3D,MAAMA,QAAoB,EAAE;AAE5B,MAAK,MAAM,KAAK,MAAM,WAAW;EAC/B,MAAM,OAAO,aAAa,EAAE,KAAK;AACjC,MAAI,CAAC,KAAM;AACX,OAAK,MAAM,KAAK,EAAE,WAChB,OAAM,KAAK;GACT;GACA,QAAQ;GACR,aAAa,EAAE;GACf,aAAa,EAAE;GACf,QAA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O;EACT,KAAK,SACH,QAAO;EACT,KAAK,aACH,QAAO;EACT,KAAK,qBACH,QAAO;EACT,KAAK,cACH,QAAO;EACT,KAAK,eACH,QAAO;EACT,KAAK,gBACH,QAAO"}
1
+ {"version":3,"file":"plan-BLy8FaE2.mjs","names":["items: PlanItem[]","byKind: Record<PlanResourceKind, number>","byAction: Record<PlanAction, number>","attestation"],"sources":["../src/core/plan/computePlan.ts","../src/core/plan/plan.types.ts","../src/cli/commands/plan.ts"],"sourcesContent":["import { loadConfig, getWorkers } from \"../config/loader.js\";\nimport { cloudflareAccountIdFromEnv } from \"../cloudflareEnv.js\";\nimport { namingFromConfig } from \"../config/namingFromConfig.js\";\nimport { StateManager } from \"../state/StateManager.js\";\nimport { stackNameForConfig } from \"../state/stackName.js\";\nimport { fetchStackImports } from \"../imports/fetchStackImports.js\";\nimport { CFApiClient } from \"../api/CFApiClient.js\";\nimport { computeDriftReport } from \"../../cli/commands/drift.js\";\nimport { resolveWorkerConfig } from \"../config/resolver.js\";\nimport { resourceModules } from \"../registry/registry.js\";\nimport { logicalNamesForResourceKind } from \"../config/resourcesFromConfig.js\";\nimport { resolveDeployedWorkerName } from \"../config/resolver.js\";\nimport { requiredSecretsForWorker } from \"../secrets/declared.js\";\nimport {\n reconcileSecrets,\n secretsPlanItems,\n vaultReaderFromMap,\n type SecretsVaultReader,\n type VaultSecretMeta,\n} from \"../secrets/reconcile.js\";\nimport { getDispatchNamespaces, getDnsRecords, getLogpushJobs } from \"../../types.js\";\nimport { logpushJobStateKey } from \"../../features/logpush-job/logpush-job.resolve.js\";\nimport { logpushJobDiffPlanItems } from \"../../features/logpush-job/logpush-job.diff.js\";\nimport {\n dnsRecordDiffPlanItems,\n} from \"../../features/dns-records/dns-records.diff.js\";\nimport { dnsRecordStateKey } from \"../../features/dns-records/dns-records.resolve.js\";\nimport type { StateEntry } from \"../../types.js\";\nimport type { PlanItem, PlanReport, PlanResourceKind } from \"./plan.types.js\";\nimport {\n filterPlanItemsForTarget,\n type ApplyTarget,\n} from \"../apply/applyTarget.js\";\n\n/**\n * Compute the planned set of changes for `env` given the current\n * `tamer.config.ts` and recorded state. Read-only: hits the Cloudflare API to\n * detect what is missing but never writes.\n *\n * The \"would create\" set is derived from `computeDriftReport().undeployed`:\n * declared in config, present neither in state nor on Cloudflare. Worker\n * **scripts** are queried directly (`workersScriptGet`) since they are not\n * tracked as state resources today.\n */\nexport async function computePlan(options: {\n env?: string;\n configPath?: string;\n /** When set, only plan items for this `kind:logical` are returned. */\n target?: ApplyTarget;\n /** Optional vault reader for secret reconciliation (defaults to empty). */\n secretsVault?: SecretsVaultReader;\n}): Promise<PlanReport> {\n const env = options.env ?? \"local\";\n const configPath = options.configPath;\n const baseDir = process.cwd();\n const target = options.target;\n\n const config = await loadConfig(configPath, { env });\n const accountId = config.account_id ?? cloudflareAccountIdFromEnv();\n if (!accountId) {\n throw new Error(\n \"account_id required in config or CLOUDFLARE_ACCOUNT_ID env var\",\n );\n }\n\n const drift = await computeDriftReport({ env, configPath });\n\n const items: PlanItem[] = [];\n\n for (const r of drift.resources) {\n const kind = mapDriftKind(r.kind);\n if (!kind) continue;\n for (const e of r.undeployed) {\n items.push({\n kind,\n action: \"create\",\n logicalName: e.logicalName,\n derivedName: e.derivedName,\n detail: e.detail,\n });\n }\n }\n\n if (env !== \"local\") {\n const api = new CFApiClient(accountId);\n const naming = namingFromConfig(config);\n const state = new StateManager(\n config.tenant.id,\n env,\n stackNameForConfig(config),\n );\n await state.hydrate(api);\n // Tolerant pre-fetch: missing sibling state isn't fatal here (plan\n // is read-only) but populating imports lets the resolver substitute\n // real values instead of leaving placeholders.\n const imports = await fetchStackImports(api, config, env);\n\n const dnsItems = dnsRecordDiffPlanItems({\n resources: getDnsRecords(config),\n tenant: config.tenant,\n env,\n state,\n });\n items.push(...dnsItems);\n\n const logpushPlanItems = await logpushJobDiffPlanItems({\n resources: getLogpushJobs(config),\n tenant: config.tenant,\n env,\n state,\n api,\n accountId,\n });\n items.push(...logpushPlanItems);\n\n const workers = await getWorkers(config, baseDir);\n for (const [workerKey, wc] of workers) {\n const resolved = await resolveWorkerConfig(\n config,\n workerKey,\n wc,\n env,\n baseDir,\n accountId,\n naming,\n state,\n { referencesMode: \"tolerant\", imports },\n );\n if (resolved.dispatchNamespace) continue;\n\n const deployedName = resolveDeployedWorkerName(\n config,\n workerKey,\n wc,\n env,\n naming,\n );\n for (const mod of resourceModules) {\n if (!mod.diff) continue;\n const resources = mod.pickResources(wc);\n if (resources.length === 0) continue;\n const diffItems = mod.diff({\n resources,\n tenant: config.tenant,\n env,\n state,\n naming,\n worker: { workerKey, deployedName },\n });\n items.push(...diffItems);\n }\n\n let script;\n try {\n script = await api.workersScriptGet(resolved.workerName);\n } catch {\n continue;\n }\n if (!script) {\n items.push({\n kind: \"worker_script\",\n action: \"create\",\n logicalName: workerKey,\n derivedName: resolved.workerName,\n });\n }\n\n const required = requiredSecretsForWorker(wc);\n if (required.length > 0) {\n const workerSecretNames = await safeWorkersSecretsList(\n api,\n resolved.workerName,\n );\n const secretEntries = await reconcileSecrets({\n workers: [\n {\n workerKey,\n required,\n workerSecretNames,\n },\n ],\n vault: options.secretsVault ?? emptySecretsVault(),\n state,\n });\n items.push(...secretsPlanItems(secretEntries));\n }\n }\n }\n\n const filtered = target ? filterPlanItemsForTarget(items, target) : items;\n\n return {\n tenantId: config.tenant.id,\n env,\n generatedAt: new Date().toISOString(),\n items: filtered,\n hasChanges: filtered.some((i) => i.action !== \"no_change\"),\n mode: \"forward\",\n };\n}\n\n/**\n * Compute the planned set of **deletions** for `env` — what `tamer destroy`\n * would remove given the current `tamer.config.ts` and recorded state.\n *\n * Read-only: hits the Cloudflare API only to confirm worker scripts exist,\n * never writes. Items are stack-scoped: only state entries whose\n * `logicalName` is declared on a worker in the current config are emitted —\n * resources owned by another stack sharing the same `tamer-state-{env}` row\n * are **not** included (matches `runDestroy` semantics).\n *\n * Worker scripts are listed when the deployed name actually exists on\n * Cloudflare; dispatch-namespace tenant scripts are intentionally excluded\n * (they are managed via `provision-tenant` / `destroy-tenant`).\n */\nexport async function computeDestroyPlan(options: {\n env?: string;\n configPath?: string;\n target?: ApplyTarget;\n}): Promise<PlanReport> {\n const env = options.env ?? \"local\";\n const configPath = options.configPath;\n const baseDir = process.cwd();\n const target = options.target;\n\n const config = await loadConfig(configPath, { env });\n const accountId = config.account_id ?? cloudflareAccountIdFromEnv();\n if (!accountId) {\n throw new Error(\n \"account_id required in config or CLOUDFLARE_ACCOUNT_ID env var\",\n );\n }\n\n const items: PlanItem[] = [];\n const generatedAt = new Date().toISOString();\n\n if (env === \"local\") {\n return {\n tenantId: config.tenant.id,\n env,\n generatedAt,\n items,\n hasChanges: false,\n mode: \"destroy\",\n };\n }\n\n const api = new CFApiClient(accountId);\n const naming = namingFromConfig(config);\n const state = new StateManager(\n config.tenant.id,\n env,\n stackNameForConfig(config),\n );\n await state.hydrate(api);\n const imports = await fetchStackImports(api, config, env);\n\n const stateEntries = state.getAll();\n\n for (const mod of resourceModules) {\n const owned = await logicalNamesForResourceKind(config, baseDir, mod.kind);\n if (owned.size === 0) continue;\n const kind = mapDriftKind(mod.kind);\n if (!kind) continue;\n for (const [, entry] of Object.entries(stateEntries)) {\n if (entry.type !== mod.stateEntryType) continue;\n const logicalName = (entry as { logicalName?: string }).logicalName;\n if (!logicalName || !owned.has(logicalName)) continue;\n items.push({\n kind,\n action: \"delete\",\n logicalName,\n derivedName: derivedNameOf(entry),\n });\n }\n }\n\n for (const [, entry] of Object.entries(stateEntries)) {\n if (entry.type !== \"worker_route\") continue;\n items.push({\n kind: \"worker_route\",\n action: \"delete\",\n logicalName: entry.workerKey,\n derivedName: entry.pattern,\n detail: entry.zoneName,\n });\n }\n\n for (const ns of getDispatchNamespaces(config)) {\n const stateKey = `dispatch_namespace:${ns.logicalName}`;\n const entry = stateEntries[stateKey];\n if (!entry || entry.type !== \"dispatch_namespace\") continue;\n items.push({\n kind: \"dispatch_namespace\",\n action: \"delete\",\n logicalName: ns.logicalName,\n derivedName: entry.derivedName,\n });\n }\n\n for (const dns of getDnsRecords(config)) {\n if (dns.preserveOnDestroy) continue;\n const key = dnsRecordStateKey(dns.zoneId, dns.type, dns.name);\n const entry = stateEntries[key];\n if (!entry || entry.type !== \"dns_record\") continue;\n items.push({\n kind: \"dns_record\",\n action: \"delete\",\n logicalName: dns.logicalName,\n derivedName: `${entry.recordType} ${entry.name}`,\n detail: entry.recordId,\n });\n }\n\n for (const lp of getLogpushJobs(config)) {\n const key = logpushJobStateKey(config.tenant.id, lp.logicalName, env);\n const entry = stateEntries[key];\n if (!entry || entry.type !== \"logpush_job\") continue;\n items.push({\n kind: \"logpush_job\",\n action: \"delete\",\n logicalName: lp.logicalName,\n derivedName: entry.derivedName,\n detail: String(entry.cfJobId),\n });\n }\n\n const workers = await getWorkers(config, baseDir);\n for (const [workerKey, wc] of workers) {\n const resolved = await resolveWorkerConfig(\n config,\n workerKey,\n wc,\n env,\n baseDir,\n accountId,\n naming,\n state,\n { referencesMode: \"tolerant\", imports },\n );\n if (resolved.dispatchNamespace) continue;\n const deployedName = resolveDeployedWorkerName(\n config,\n workerKey,\n wc,\n env,\n naming,\n );\n let script;\n try {\n script = await api.workersScriptGet(deployedName);\n } catch {\n continue;\n }\n if (script) {\n items.push({\n kind: \"worker_script\",\n action: \"delete\",\n logicalName: workerKey,\n derivedName: deployedName,\n });\n }\n }\n\n const filtered = target ? filterPlanItemsForTarget(items, target) : items;\n\n return {\n tenantId: config.tenant.id,\n env,\n generatedAt,\n items: filtered,\n hasChanges: filtered.length > 0,\n mode: \"destroy\",\n };\n}\n\nfunction derivedNameOf(entry: StateEntry): string {\n switch (entry.type) {\n case \"d1_database\":\n case \"r2_bucket\":\n case \"kv_namespace\":\n case \"queue\":\n case \"hyperdrive\":\n case \"vectorize\":\n case \"ai_gateway\":\n case \"pipeline\":\n case \"workflow\":\n case \"secrets_store\":\n case \"dispatch_namespace\":\n return entry.derivedName;\n case \"dns_record\":\n return `${entry.recordType} ${entry.name}`;\n case \"worker_route\":\n return entry.pattern;\n case \"logpush_job\":\n return entry.derivedName;\n case \"logpush_pipelines\":\n return entry.pipelineName;\n case \"secret\":\n return `${entry.worker}:${entry.name}`;\n }\n}\n\nfunction emptySecretsVault(): SecretsVaultReader {\n return vaultReaderFromMap({});\n}\n\nasync function safeWorkersSecretsList(\n api: CFApiClient,\n scriptName: string,\n): Promise<string[]> {\n try {\n return await api.workersSecretsList(scriptName);\n } catch {\n return [];\n }\n}\n\nfunction mapDriftKind(kind: string): PlanResourceKind | undefined {\n switch (kind) {\n case \"d1\":\n case \"r2\":\n case \"kv\":\n case \"queue\":\n case \"hyperdrive\":\n case \"vectorize\":\n case \"ai_gateway\":\n case \"pipeline\":\n case \"workflow\":\n case \"secret_store\":\n case \"secret\":\n case \"dns_record\":\n case \"dispatch_namespace\":\n case \"logpush_job\":\n case \"worker_route\":\n return kind;\n default:\n return undefined;\n }\n}\n","/**\n * Read-only \"plan\" — the CloudFormation-style preview of changes Tamer would\n * make if you ran `apply` and then `deploy` against the current state +\n * config. Pure: never writes to state or to Cloudflare.\n */\n\nexport type PlanResourceKind =\n | \"d1\"\n | \"r2\"\n | \"kv\"\n | \"queue\"\n | \"hyperdrive\"\n | \"vectorize\"\n | \"ai_gateway\"\n | \"pipeline\"\n | \"workflow\"\n | \"secret_store\"\n | \"secret\"\n | \"dns_record\"\n | \"dispatch_namespace\"\n | \"logpush_job\"\n | \"worker_route\"\n | \"worker_script\";\n\n/**\n * Plan actions, in CloudFormation / Terraform terms:\n *\n * - `create` — declared in config, missing on Cloudflare and in state.\n * - `update` — tracked + present, but **mutable** fields drifted from config →\n * `apply` would PATCH in place. No replacement.\n * - `replace` — tracked + present, but **immutable** fields drifted from\n * config → `apply` must delete + recreate (Cloudflare APIs that reject\n * PATCH on the changed field, e.g. DNS record `type`, Vectorize\n * `dimensions` / `metric`, Pipelines V1 `sql`). The state row's `cfId`\n * will change.\n * - `delete` — destroy-plan only.\n * - `no_change` — declared, present, fully in sync.\n */\nexport type PlanAction =\n | \"create\"\n | \"update\"\n | \"replace\"\n | \"delete\"\n | \"no_change\";\n\n/**\n * Direction of the plan: forward (the default — what `apply` + `deploy` would\n * change) or destroy (what `destroy` would remove). Plans are mutually\n * exclusive: a forward plan never includes `delete`, and a destroy plan\n * never includes `create` / `update` / `replace`.\n */\nexport type PlanMode = \"forward\" | \"destroy\";\n\n/**\n * Describes one drifted field in an `update` / `replace` plan item — the\n * field path, what state currently holds, and what config wants. Surfaced in\n * `tamer plan --json` so reviewers can audit the change exactly the way\n * `terraform plan` shows attribute diffs.\n */\nexport interface PlanFieldChange {\n field: string;\n from: unknown;\n to: unknown;\n /**\n * `mutable` → would patch in place; `immutable` → forces `replace` (the\n * underlying Cloudflare resource will be destroyed + recreated, and the\n * state row's `cfId` will change).\n */\n kind: \"mutable\" | \"immutable\";\n}\n\nexport interface PlanItem {\n kind: PlanResourceKind;\n action: PlanAction;\n /** Logical name from `tamer.config.ts` (or worker key for scripts/routes). */\n logicalName: string;\n /** Cloudflare-side identifier (resource name or pattern). */\n derivedName: string;\n /** Optional human-readable detail. */\n detail?: string;\n /**\n * Field-level diff for `update` / `replace` items. Empty for `create` /\n * `delete` / `no_change`. Each entry shows what state has (`from`) and what\n * config asks for (`to`).\n */\n changes?: PlanFieldChange[];\n}\n\nexport interface PlanReport {\n tenantId: string;\n env: string;\n generatedAt: string;\n items: PlanItem[];\n /** True iff at least one item has `action !== \"no_change\"`. */\n hasChanges: boolean;\n /** Plan direction. Defaults to `\"forward\"` for back-compat with v0.11 plans. */\n mode?: PlanMode;\n}\n\nexport function planSummary(items: PlanItem[]): {\n byKind: Record<PlanResourceKind, number>;\n byAction: Record<PlanAction, number>;\n} {\n const byKind: Record<PlanResourceKind, number> = {\n d1: 0,\n r2: 0,\n kv: 0,\n queue: 0,\n hyperdrive: 0,\n vectorize: 0,\n ai_gateway: 0,\n pipeline: 0,\n workflow: 0,\n secret_store: 0,\n secret: 0,\n dns_record: 0,\n dispatch_namespace: 0,\n logpush_job: 0,\n worker_route: 0,\n worker_script: 0,\n };\n const byAction: Record<PlanAction, number> = {\n create: 0,\n update: 0,\n replace: 0,\n delete: 0,\n no_change: 0,\n };\n for (const it of items) {\n if (it.action === \"no_change\") continue;\n byKind[it.kind]++;\n byAction[it.action]++;\n }\n return { byKind, byAction };\n}\n","import { computePlan, computeDestroyPlan } from \"../../core/plan/computePlan.js\";\nimport { planSummary } from \"../../core/plan/plan.types.js\";\nimport type {\n PlanItem,\n PlanReport,\n PlanResourceKind,\n} from \"../../core/plan/plan.types.js\";\nimport { formatPlanFieldChanges, signFor } from \"../../core/plan/planFormat.js\";\nimport { loadConfig } from \"../../core/config/loader.js\";\nimport { cloudflareAccountIdFromEnv } from \"../../core/cloudflareEnv.js\";\nimport { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { StateManager } from \"../../core/state/StateManager.js\";\nimport { stackNameForConfig } from \"../../core/state/stackName.js\";\nimport {\n PLAN_FILE_FORMAT,\n computeAttestation,\n writePlanFile,\n} from \"../../core/plan/planFile.js\";\nimport { createEmptyCfiState } from \"../../core/state/tamerStateDb.js\";\nimport { buildCloudflareSnapshot } from \"../../core/plan/cloudflareSnapshot.js\";\nimport {\n parseApplyTarget,\n assertApplyTargetDeclared,\n} from \"../../core/apply/applyTarget.js\";\n\n/**\n * `tamer plan` — print a CloudFormation-style preview of `apply` + `deploy`\n * against the current state, config, and Cloudflare reality. Never mutates.\n *\n * Exit codes:\n * 0 — plan succeeded; with `--detailed-exitcode`, also \"no changes\".\n * 2 — plan succeeded **and** has at least one create/update (with\n * `--detailed-exitcode`); useful for CI gates that want to fail when\n * infra would change.\n */\nexport async function runPlan(options: {\n env?: string;\n configPath?: string;\n json?: boolean;\n detailedExitcode?: boolean;\n /** When set, write the plan + attestation hashes to this path. */\n out?: string;\n /**\n * When true, compute a **destroy plan** (what `tamer destroy` would remove\n * from state and Cloudflare) instead of the default forward plan. Mutually\n * exclusive with the forward plan — destroy plans only contain `delete`\n * items, never `create` / `update`. Read-only.\n */\n destroy?: boolean;\n /** `kind:logicalName` — restrict plan items to that resource. */\n target?: string;\n}): Promise<number> {\n if (options.out && options.target) {\n throw new Error(\n \"Cannot combine --out with --target: saved plans must cover the full stack.\",\n );\n }\n\n const target = options.target\n ? parseApplyTarget(options.target)\n : undefined;\n if (target) {\n const config = await loadConfig(options.configPath, {\n env: options.env ?? \"local\",\n });\n await assertApplyTargetDeclared(config, process.cwd(), target);\n }\n\n const report = options.destroy\n ? await computeDestroyPlan({\n env: options.env,\n configPath: options.configPath,\n target,\n })\n : await computePlan({\n env: options.env,\n configPath: options.configPath,\n target,\n });\n\n if (options.out) {\n await writePlanForApply(options.out, report, options.configPath);\n }\n\n if (options.json) {\n console.log(JSON.stringify(report, null, 2));\n } else {\n printHumanPlan(report);\n if (options.out) {\n console.log(`Plan written to ${options.out}\\n`);\n }\n }\n\n if (options.detailedExitcode && report.hasChanges) {\n return 2;\n }\n return 0;\n}\n\n/**\n * Hydrate the same `(config, state)` pair `computePlan` consumed and write\n * a {@link PlanFile} with the attestation hashes pinned. `apply --plan`\n * recomputes both hashes and refuses to proceed if either drifted, so a\n * stale plan can never silently apply against changed inputs.\n */\nasync function writePlanForApply(\n outPath: string,\n report: PlanReport,\n configPath: string | undefined,\n): Promise<void> {\n const config = await loadConfig(configPath, { env: report.env });\n if (report.env === \"local\") {\n const attestation = computeAttestation(\n config,\n createEmptyCfiState(config.tenant.id, \"local\"),\n );\n writePlanFile(outPath, {\n format: PLAN_FILE_FORMAT,\n tenantId: config.tenant.id,\n env: report.env,\n generatedAt: report.generatedAt,\n report,\n attestation,\n });\n return;\n }\n\n const accountId = config.account_id ?? cloudflareAccountIdFromEnv();\n if (!accountId) {\n throw new Error(\n \"account_id required in config or CLOUDFLARE_ACCOUNT_ID env var\",\n );\n }\n const api = new CFApiClient(accountId);\n const state = new StateManager(\n config.tenant.id,\n report.env,\n stackNameForConfig(config),\n );\n await state.hydrate(api);\n const cloudflareSnapshot = await buildCloudflareSnapshot({\n config,\n env: report.env,\n api,\n baseDir: process.cwd(),\n });\n const attestation = computeAttestation(\n config,\n state.load(),\n cloudflareSnapshot,\n );\n writePlanFile(outPath, {\n format: PLAN_FILE_FORMAT,\n tenantId: config.tenant.id,\n env: report.env,\n generatedAt: report.generatedAt,\n report,\n attestation,\n });\n}\n\nfunction printHumanPlan(report: PlanReport): void {\n const isDestroy = report.mode === \"destroy\";\n const heading = isDestroy ? \"Destroy plan\" : \"Plan\";\n console.log(\n `\\n${heading} — tenant ${report.tenantId}, env ${report.env}\\n`,\n );\n if (report.items.length === 0) {\n if (isDestroy) {\n console.log(\" (nothing to destroy — no managed resources in state)\\n\");\n } else {\n console.log(\" (no changes — infrastructure matches config)\\n\");\n }\n return;\n }\n const grouped = new Map<PlanResourceKind, PlanItem[]>();\n for (const it of report.items) {\n const arr = grouped.get(it.kind) ?? [];\n arr.push(it);\n grouped.set(it.kind, arr);\n }\n for (const [kind, items] of grouped) {\n console.log(`${labelFor(kind)} (${items.length}):`);\n for (const it of items) {\n const sign = signFor(it.action);\n // Suppress `detail` on update/replace items when we have a structured\n // `changes[]` block — the per-field renderer below already shows the\n // same drift in terraform-style form, and printing both duplicates\n // the diff and clutters the output.\n const hasChanges = it.changes && it.changes.length > 0;\n const detail = it.detail && !hasChanges ? ` (${it.detail})` : \"\";\n console.log(` ${sign} ${it.logicalName} -> ${it.derivedName}${detail}`);\n for (const line of formatPlanFieldChanges(it.changes)) {\n console.log(line);\n }\n }\n }\n const { byAction } = planSummary(report.items);\n if (isDestroy) {\n console.log(`\\nSummary: ${byAction.delete} to delete.\\n`);\n } else {\n console.log(\n `\\nSummary: ${byAction.create} to create, ${byAction.update} to update, ${byAction.replace} to replace.\\n`,\n );\n }\n}\n\nfunction labelFor(kind: PlanResourceKind): string {\n switch (kind) {\n case \"d1\":\n return \"D1\";\n case \"r2\":\n return \"R2\";\n case \"kv\":\n return \"KV\";\n case \"queue\":\n return \"Queues\";\n case \"hyperdrive\":\n return \"Hyperdrive\";\n case \"vectorize\":\n return \"Vectorize\";\n case \"ai_gateway\":\n return \"AI Gateway\";\n case \"pipeline\":\n return \"Pipeline\";\n case \"workflow\":\n return \"Workflow\";\n case \"secret_store\":\n return \"Secrets Store\";\n case \"secret\":\n return \"Worker secrets\";\n case \"dns_record\":\n return \"DNS records\";\n case \"dispatch_namespace\":\n return \"Dispatch namespaces\";\n case \"logpush_job\":\n return \"Logpush jobs\";\n case \"worker_route\":\n return \"Workers zone routes\";\n case \"worker_script\":\n return \"Worker scripts\";\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA4CA,eAAsB,YAAY,SAOV;CACtB,MAAM,MAAM,QAAQ,OAAO;CAC3B,MAAM,aAAa,QAAQ;CAC3B,MAAM,UAAU,QAAQ,KAAK;CAC7B,MAAM,SAAS,QAAQ;CAEvB,MAAM,SAAS,MAAM,WAAW,YAAY,EAAE,KAAK,CAAC;CACpD,MAAM,YAAY,OAAO,cAAc,4BAA4B;AACnE,KAAI,CAAC,UACH,OAAM,IAAI,MACR,iEACD;CAGH,MAAM,QAAQ,MAAM,mBAAmB;EAAE;EAAK;EAAY,CAAC;CAE3D,MAAMA,QAAoB,EAAE;AAE5B,MAAK,MAAM,KAAK,MAAM,WAAW;EAC/B,MAAM,OAAO,aAAa,EAAE,KAAK;AACjC,MAAI,CAAC,KAAM;AACX,OAAK,MAAM,KAAK,EAAE,WAChB,OAAM,KAAK;GACT;GACA,QAAQ;GACR,aAAa,EAAE;GACf,aAAa,EAAE;GACf,QAAQ,EAAE;GACX,CAAC;;AAIN,KAAI,QAAQ,SAAS;EACnB,MAAM,MAAM,IAAI,YAAY,UAAU;EACtC,MAAM,SAAS,iBAAiB,OAAO;EACvC,MAAM,QAAQ,IAAI,aAChB,OAAO,OAAO,IACd,KACA,mBAAmB,OAAO,CAC3B;AACD,QAAM,MAAM,QAAQ,IAAI;EAIxB,MAAM,UAAU,MAAM,kBAAkB,KAAK,QAAQ,I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AK,IAAI,EAAE;AACtC,MAAI,KAAK,GAAG;AACZ,UAAQ,IAAI,GAAG,MAAM,IAAI;;AAE3B,MAAK,MAAM,CAAC,MAAM,UAAU,SAAS;AACnC,UAAQ,IAAI,GAAG,SAAS,KAAK,CAAC,IAAI,MAAM,OAAO,IAAI;AACnD,OAAK,MAAM,MAAM,OAAO;GACtB,MAAM,OAAO,QAAQ,GAAG,OAAO;GAK/B,MAAM,aAAa,GAAG,WAAW,GAAG,QAAQ,SAAS;GACrD,MAAM,SAAS,GAAG,UAAU,CAAC,aAAa,KAAK,GAAG,OAAO,KAAK;AAC9D,WAAQ,IAAI,KAAK,KAAK,GAAG,GAAG,YAAY,MAAM,GAAG,cAAc,SAAS;AACxE,QAAK,MAAM,QAAQ,uBAAuB,GAAG,QAAQ,CACnD,SAAQ,IAAI,KAAK;;;CAIvB,MAAM,EAAE,aAAa,YAAY,OAAO,MAAM;AAC9C,KAAI,UACF,SAAQ,IAAI,cAAc,SAAS,OAAO,eAAe;KAEzD,SAAQ,IACN,cAAc,SAAS,OAAO,cAAc,SAAS,OAAO,cAAc,SAAS,QAAQ,gBAC5F;;AAIL,SAAS,SAAS,MAAgC;AAChD,SAAQ,MAAR;EACE,KAAK,KACH,QAAO;EACT,KAAK,KACH,QAAO;EACT,KAAK,KACH,QAAO;EACT,KAAK,QACH,QAAO;EACT,KAAK,aACH,QAAO;EACT,KAAK,YACH,QAAO;EACT,KAAK,aACH,QAAO;EACT,KAAK,WACH,QAAO;EACT,KAAK,WACH,QAAO;EACT,KAAK,eACH,QAAO;EACT,KAAK,SACH,QAAO;EACT,KAAK,aACH,QAAO;EACT,KAAK,qBACH,QAAO;EACT,KAAK,cACH,QAAO;EACT,KAAK,eACH,QAAO;EACT,KAAK,gBACH,QAAO"}
@@ -1,5 +1,5 @@
1
1
  import { f as getDispatchNamespaces } from "./normalize-DVSTRZhO.mjs";
2
- import { C as stackNameForConfig, L as CFApiClient, M as effectiveDispatchNamespaceName, R as cloudflareAccountIdFromEnv, V as loadConfig, _ as tenantShardDatabaseName, g as tenantDispatchScriptName, h as parseTenantShardRoles, m as StateManager, v as tenantStateKey } from "./tamer.mjs";
2
+ import { L as CFApiClient, N as effectiveDispatchNamespaceName, R as cloudflareAccountIdFromEnv, V as loadConfig, _ as tenantDispatchScriptName, g as parseTenantShardRoles, h as StateManager, v as tenantShardDatabaseName, w as stackNameForConfig, y as tenantStateKey } from "./tamer.mjs";
3
3
  import "./r2S3EmptyBucket-B9_pHfvB.mjs";
4
4
  import { n as logApplyChange } from "./planFormat-5XMJK879.mjs";
5
5
  import { r as tamerArtifactsBucketName } from "./tamerArtifactsR2-DnUJmxnO.mjs";
@@ -187,4 +187,4 @@ async function provisionTenantInner(options) {
187
187
 
188
188
  //#endregion
189
189
  export { runProvisionTenant };
190
- //# sourceMappingURL=provision-tenant-BJ1KugON.mjs.map
190
+ //# sourceMappingURL=provision-tenant-CleOYFwr.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"provision-tenant-BJ1KugON.mjs","names":["result: ProvisionTenantResult","allD1: Awaited<ReturnType<typeof api.d1ListAll>> | null","shards: TenantD1ShardRef[]","form: FormData"],"sources":["../src/cli/commands/provision-tenant.ts"],"sourcesContent":["import { basename, resolve } from \"path\";\nimport { loadConfig } from \"../../core/config/loader.js\";\nimport { cloudflareAccountIdFromEnv } from \"../../core/cloudflareEnv.js\";\nimport { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { StateManager } from \"../../core/state/StateManager.js\";\nimport { stackNameForConfig } from \"../../core/state/stackName.js\";\nimport { getDispatchNamespaces } from \"../../types.js\";\nimport { effectiveDispatchNamespaceName } from \"../../features/dispatch-namespace/dispatch-namespace.resolve.js\";\nimport {\n parseTenantShardRoles,\n tenantDispatchScriptName,\n tenantShardDatabaseName,\n tenantStateKey,\n} from \"../../core/tenant/tenantKeys.js\";\nimport {\n buildSingleModuleDispatchForm,\n buildSingleModuleDispatchFormFromBuffer,\n} from \"../../core/wfp/buildDispatchUploadForm.js\";\nimport { tamerArtifactsBucketName } from \"../../core/state/tamerArtifactsR2.js\";\nimport { logApplyChange } from \"../../core/plan/planFormat.js\";\nimport type { TenantD1ShardRef, TenantStateEntry } from \"../../types.js\";\n\nconst now = (): string => new Date().toISOString();\n\nfunction buildTenantEntry(\n options: {\n product: string;\n workspace: string;\n dispatchNamespaceName: string;\n scriptName: string;\n },\n status: TenantStateEntry[\"provisioningStatus\"],\n existing: TenantStateEntry | undefined,\n patch?: Partial<Pick<TenantStateEntry, \"d1Shards\">>,\n): TenantStateEntry {\n return {\n product: options.product,\n workspace: options.workspace,\n provisioningStatus: status,\n dispatchNamespaceName: options.dispatchNamespaceName,\n scriptName: options.scriptName,\n d1Shards: patch?.d1Shards ?? existing?.d1Shards,\n createdAt: existing?.createdAt ?? now(),\n updatedAt: now(),\n };\n}\n\n/**\n * Resolve the effective shard set for this provision call.\n *\n * 1. The configured layout (`tenant.d1Shards` in `tamer.config.ts`)\n * is the source of truth — any role used by `--shards` must\n * appear here, and `apply` / `drift` / other operators read the\n * same shape.\n * 2. When `--shards a,b` is passed, trim to that subset (preserving\n * configured order so plan/provision logs stay deterministic).\n * Extending the layout is an edit to `tamer.config.ts`, not a\n * CLI flag — that's why `parseTenantShardRoles` rejects roles\n * outside the configured set.\n * 3. When the config has no `tenant.d1Shards`, the resolved set is\n * empty: `provision-tenant` only uploads the dispatch script\n * (truly generic single-Worker tenant case).\n */\nfunction resolveShardRoles(\n configured: readonly string[],\n shardsRaw: string | undefined,\n): string[] {\n if (shardsRaw == null || shardsRaw.trim() === \"\") return [...configured];\n return parseTenantShardRoles(shardsRaw, configured);\n}\n\n/**\n * Idempotent tenant provisioning. Each call:\n *\n * 1. Marks the tenant `pending` if there's no record yet.\n * 2. For every shard role declared in `tenant.d1Shards` in\n * `tamer.config.ts` (or a `--shards` subset): looks up an\n * existing D1 by derived name (`tenantShardDatabaseName(role,\n * …)`), creating it via `d1Create` only when missing. Persists\n * the `(role, derivedName, cfId)` triple to\n * `state.tenants[…].d1Shards[]`.\n * 3. Marks the tenant `d1_created` once *all* requested shards\n * exist in state.\n * 4. Uploads the dispatch script (from `--main` or `--artifact-key`)\n * via the WFP dispatch namespace.\n * 5. Marks the tenant `ready`.\n *\n * When `tenant.d1Shards` is omitted, step 2/3 collapse to a no-op\n * (truly generic single-Worker tenant — only the dispatch script is\n * provisioned). Re-running with the same shard set is a no-op (state\n * already has those rows). Editing `tamer.config.ts` to **extend**\n * the layout (e.g. adding a new role) and re-running picks up the\n * missing shards without disturbing existing ones, so a tenant\n * created with `[\"app\"]` can be migrated to `[\"system\",\"app\",\n * \"history\"]` (or `[\"primary\",\"audit\"]`, or any other set) with one\n * config edit + one `provision-tenant` invocation. Re-running after\n * a config that **shrinks** the layout never deletes shards (use\n * `destroy-tenant` for that).\n */\n/**\n * Machine-readable result envelope emitted on the final stdout line\n * when `--json` is passed. Designed for the Cloudflare Container caller\n * (`provision-workflow`, see `docs/handoff.md` §7) so the Worker can\n * parse the result without scraping human logs. On success the Workflow\n * sees `status: \"ready\"` plus the materialized tenant shape; on\n * failure it sees `status: \"failed\"` with `error` + best-effort\n * `partial` state, and the process exits non-zero.\n */\nexport interface ProvisionTenantResult {\n status: \"ready\" | \"failed\" | \"noop\";\n tenantKey: string;\n product: string;\n workspace: string;\n env: string;\n scriptName: string;\n dispatchNamespaceName: string;\n shards: { role: string; derivedName: string; cfId: string }[];\n error?: string;\n}\n\nexport async function runProvisionTenant(options: {\n env: string;\n product: string;\n workspace: string;\n main?: string;\n artifactKey?: string;\n moduleName?: string;\n configPath?: string;\n compatibilityDate?: string;\n compatibilityFlags?: string[];\n /**\n * Raw `--shards` value (`\"system,app\"` etc.) — validated against\n * `tenant.d1Shards` from the loaded config. Omit to provision every\n * configured shard.\n */\n shardsRaw?: string;\n json?: boolean;\n}): Promise<void> {\n const env = options.env;\n if (env === \"local\") {\n throw new Error(\n \"provision-tenant requires a non-local --env (Cloudflare-backed state).\",\n );\n }\n\n try {\n await provisionTenantInner(options);\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n if (options.json) {\n // Failure envelope: we may have died before loadConfig, so we\n // can't ask `tenant.ephemeralEnvPattern` whether `env` would\n // get the `-{env}` suffix. Emit the non-ephemeral form as a\n // best-effort hint — `error` carries the real signal.\n const result: ProvisionTenantResult = {\n status: \"failed\",\n tenantKey: tenantStateKey(options.product, options.workspace),\n product: options.product,\n workspace: options.workspace,\n env,\n scriptName: `${options.product}-${options.workspace}`,\n dispatchNamespaceName: \"\",\n shards: [],\n error: msg,\n };\n process.stdout.write(JSON.stringify(result) + \"\\n\");\n }\n // Container caller (provision-workflow) reads exit code as\n // primary success/failure signal; JSON envelope on stdout is\n // secondary detail. Re-throw so the CLI surfaces the original\n // error in human mode.\n throw err;\n }\n}\n\nasync function provisionTenantInner(options: {\n env: string;\n product: string;\n workspace: string;\n main?: string;\n artifactKey?: string;\n moduleName?: string;\n configPath?: string;\n compatibilityDate?: string;\n compatibilityFlags?: string[];\n shardsRaw?: string;\n json?: boolean;\n}): Promise<void> {\n const env = options.env;\n const config = await loadConfig(options.configPath, { env });\n const accountId = config.account_id ?? cloudflareAccountIdFromEnv();\n if (!accountId) {\n throw new Error(\n \"account_id required in config or CLOUDFLARE_ACCOUNT_ID env var\",\n );\n }\n\n const dns = getDispatchNamespaces(config);\n if (dns.length === 0) {\n throw new Error(\n \"provision-tenant requires at least one dispatch namespace in the Tamer project config (dispatchNamespaces).\",\n );\n }\n const nsConfig = dns[0]!;\n const dispatchNamespaceName = effectiveDispatchNamespaceName(\n nsConfig,\n env,\n config.tenant,\n );\n const scriptName = tenantDispatchScriptName(\n options.product,\n options.workspace,\n env,\n config.tenant,\n );\n const desiredRoles = resolveShardRoles(\n config.tenant.d1Shards ?? [],\n options.shardsRaw,\n );\n\n const api = new CFApiClient(accountId);\n const state = new StateManager(\n config.tenant.id,\n env,\n stackNameForConfig(config),\n );\n await state.hydrate(api);\n\n let existing = state.getTenant(options.product, options.workspace);\n // \"ready\" is a no-op only when the existing layout already covers\n // every requested shard role. Adding a new role re-opens the tenant\n // for incremental provisioning without forcing a full re-deploy.\n if (existing?.provisioningStatus === \"ready\") {\n const have = new Set((existing.d1Shards ?? []).map((s) => s.role));\n const missing = desiredRoles.filter((r) => !have.has(r));\n if (missing.length === 0) {\n console.log(\n `Tenant ${tenantStateKey(options.product, options.workspace)} already ready; nothing to do.`,\n );\n if (options.json) {\n const result: ProvisionTenantResult = {\n status: \"noop\",\n tenantKey: tenantStateKey(options.product, options.workspace),\n product: options.product,\n workspace: options.workspace,\n env,\n scriptName,\n dispatchNamespaceName,\n shards: (existing.d1Shards ?? []).map((s) => ({\n role: s.role,\n derivedName: s.derivedName,\n cfId: s.cfId,\n })),\n };\n process.stdout.write(JSON.stringify(result) + \"\\n\");\n }\n return;\n }\n console.log(\n `Tenant ${tenantStateKey(options.product, options.workspace)} ready but missing shards: ${missing.join(\", \")}; extending layout.`,\n );\n }\n\n const compatDate =\n options.compatibilityDate ??\n config.compatibility_date ??\n new Date().toISOString().slice(0, 10);\n\n const entryOpts = {\n product: options.product,\n workspace: options.workspace,\n dispatchNamespaceName,\n scriptName,\n };\n\n if (!existing) {\n state.setTenant(buildTenantEntry(entryOpts, \"pending\", undefined));\n await state.persist(api);\n existing = state.getTenant(options.product, options.workspace)!;\n }\n\n // Reconcile each requested shard role. We list D1 once per call when\n // we need to (some role is missing from state) and reuse the result\n // for every subsequent role.\n let allD1: Awaited<ReturnType<typeof api.d1ListAll>> | null = null;\n const shards: TenantD1ShardRef[] = [...(existing.d1Shards ?? [])];\n\n for (const role of desiredRoles) {\n if (shards.find((s) => s.role === role)) continue;\n const derivedName = tenantShardDatabaseName(\n role,\n options.workspace,\n options.product,\n config.tenant.id,\n env,\n );\n if (allD1 === null) {\n allD1 = await api.d1ListAll();\n }\n let cfId = allD1.find((d) => d.name === derivedName)?.uuid;\n if (cfId) {\n // Adopt an existing D1 (e.g. partial-failure resume, or\n // operator created it out-of-band) without re-issuing POST.\n logApplyChange({\n kind: \"d1\",\n action: \"no_change\",\n logical: `${role}-shard`,\n derived: derivedName,\n });\n } else {\n logApplyChange({\n kind: \"d1\",\n action: \"create\",\n logical: `${role}-shard`,\n derived: derivedName,\n });\n const created = await api.d1Create(derivedName);\n cfId = created.uuid;\n }\n shards.push({ role, derivedName, cfId });\n // Persist after each shard so a network failure mid-loop leaves\n // the already-created shards recorded — `provision-tenant` is\n // resumable role-by-role.\n state.setTenant(\n buildTenantEntry(entryOpts, \"d1_created\", existing, { d1Shards: shards }),\n );\n await state.persist(api);\n existing = state.getTenant(options.product, options.workspace)!;\n }\n\n let form: FormData;\n if (options.main) {\n const mainPath = resolve(process.cwd(), options.main);\n form = buildSingleModuleDispatchForm(mainPath, {\n compatibility_date: compatDate,\n compatibility_flags: options.compatibilityFlags,\n });\n } else if (options.artifactKey) {\n const bucket = tamerArtifactsBucketName(env);\n const body = await api.r2GetObject(bucket, options.artifactKey);\n const mod =\n options.moduleName?.trim() ||\n basename(options.artifactKey).replace(/\\.(zip|tar|gz)$/i, \"\") ||\n \"worker.js\";\n form = buildSingleModuleDispatchFormFromBuffer(mod, body, {\n compatibility_date: compatDate,\n compatibility_flags: options.compatibilityFlags,\n });\n } else {\n throw new Error(\"provision-tenant: provide --main or --artifact-key\");\n }\n\n await api.dispatchNamespaceScriptPut(dispatchNamespaceName, scriptName, form);\n\n state.setTenant(\n buildTenantEntry(entryOpts, \"ready\", existing, { d1Shards: shards }),\n );\n await state.persist(api);\n\n const shardsSummary =\n shards.length > 0\n ? `shards: ${shards.map((s) => s.role).join(\", \")}`\n : \"no shards declared\";\n console.log(\n `Provisioned tenant ${tenantStateKey(options.product, options.workspace)} → script ${scriptName} in ${dispatchNamespaceName} (${shardsSummary})`,\n );\n\n if (options.json) {\n const result: ProvisionTenantResult = {\n status: \"ready\",\n tenantKey: tenantStateKey(options.product, options.workspace),\n product: options.product,\n workspace: options.workspace,\n env,\n scriptName,\n dispatchNamespaceName,\n shards: shards.map((s) => ({\n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AoB;EACpB,qBAAqB,QAAQ;EAC9B,CAAC;UACO,QAAQ,aAAa;EAC9B,MAAM,SAAS,yBAAyB,IAAI;EAC5C,MAAM,OAAO,MAAM,IAAI,YAAY,QAAQ,QAAQ,YAAY;AAK/D,SAAO,wCAHL,QAAQ,YAAY,MAAM,IAC1B,SAAS,QAAQ,YAAY,CAAC,QAAQ,oBAAoB,GAAG,IAC7D,aACkD,MAAM;GACxD,oBAAoB;GACpB,qBAAqB,QAAQ;GAC9B,CAAC;OAEF,OAAM,IAAI,MAAM,qDAAqD;AAGvE,OAAM,IAAI,2BAA2B,uBAAuB,YAAY,KAAK;AAE7E,OAAM,UACJ,iBAAiB,WAAW,SAAS,UAAU,EAAE,UAAU,QAAQ,CAAC,CACrE;AACD,OAAM,MAAM,QAAQ,IAAI;CAExB,MAAM,gBACJ,OAAO,SAAS,IACZ,WAAW,OAAO,KAAK,MAAM,EAAE,KAAK,CAAC,KAAK,KAAK,KAC/C;AACN,SAAQ,IACN,sBAAsB,eAAe,QAAQ,SAAS,QAAQ,UAAU,CAAC,YAAY,WAAW,MAAM,sBAAsB,IAAI,cAAc,GAC/I;AAED,KAAI,QAAQ,MAAM;EAChB,MAAMH,SAAgC;GACpC,QAAQ;GACR,WAAW,eAAe,QAAQ,SAAS,QAAQ,UAAU;GAC7D,SAAS,QAAQ;GACjB,WAAW,QAAQ;GACnB;GACA;GACA;GACA,QAAQ,OAAO,KAAK,OAAO;IACzB,MAAM,EAAE;IACR,aAAa,EAAE;IACf,MAAM,EAAE;IACT,EAAE;GACJ;AACD,UAAQ,OAAO,MAAM,KAAK,UAAU,OAAO,GAAG,KAAK"}
1
+ {"version":3,"file":"provision-tenant-CleOYFwr.mjs","names":["result: ProvisionTenantResult","allD1: Awaited<ReturnType<typeof api.d1ListAll>> | null","shards: TenantD1ShardRef[]","form: FormData"],"sources":["../src/cli/commands/provision-tenant.ts"],"sourcesContent":["import { basename, resolve } from \"path\";\nimport { loadConfig } from \"../../core/config/loader.js\";\nimport { cloudflareAccountIdFromEnv } from \"../../core/cloudflareEnv.js\";\nimport { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { StateManager } from \"../../core/state/StateManager.js\";\nimport { stackNameForConfig } from \"../../core/state/stackName.js\";\nimport { getDispatchNamespaces } from \"../../types.js\";\nimport { effectiveDispatchNamespaceName } from \"../../features/dispatch-namespace/dispatch-namespace.resolve.js\";\nimport {\n parseTenantShardRoles,\n tenantDispatchScriptName,\n tenantShardDatabaseName,\n tenantStateKey,\n} from \"../../core/tenant/tenantKeys.js\";\nimport {\n buildSingleModuleDispatchForm,\n buildSingleModuleDispatchFormFromBuffer,\n} from \"../../core/wfp/buildDispatchUploadForm.js\";\nimport { tamerArtifactsBucketName } from \"../../core/state/tamerArtifactsR2.js\";\nimport { logApplyChange } from \"../../core/plan/planFormat.js\";\nimport type { TenantD1ShardRef, TenantStateEntry } from \"../../types.js\";\n\nconst now = (): string => new Date().toISOString();\n\nfunction buildTenantEntry(\n options: {\n product: string;\n workspace: string;\n dispatchNamespaceName: string;\n scriptName: string;\n },\n status: TenantStateEntry[\"provisioningStatus\"],\n existing: TenantStateEntry | undefined,\n patch?: Partial<Pick<TenantStateEntry, \"d1Shards\">>,\n): TenantStateEntry {\n return {\n product: options.product,\n workspace: options.workspace,\n provisioningStatus: status,\n dispatchNamespaceName: options.dispatchNamespaceName,\n scriptName: options.scriptName,\n d1Shards: patch?.d1Shards ?? existing?.d1Shards,\n createdAt: existing?.createdAt ?? now(),\n updatedAt: now(),\n };\n}\n\n/**\n * Resolve the effective shard set for this provision call.\n *\n * 1. The configured layout (`tenant.d1Shards` in `tamer.config.ts`)\n * is the source of truth — any role used by `--shards` must\n * appear here, and `apply` / `drift` / other operators read the\n * same shape.\n * 2. When `--shards a,b` is passed, trim to that subset (preserving\n * configured order so plan/provision logs stay deterministic).\n * Extending the layout is an edit to `tamer.config.ts`, not a\n * CLI flag — that's why `parseTenantShardRoles` rejects roles\n * outside the configured set.\n * 3. When the config has no `tenant.d1Shards`, the resolved set is\n * empty: `provision-tenant` only uploads the dispatch script\n * (truly generic single-Worker tenant case).\n */\nfunction resolveShardRoles(\n configured: readonly string[],\n shardsRaw: string | undefined,\n): string[] {\n if (shardsRaw == null || shardsRaw.trim() === \"\") return [...configured];\n return parseTenantShardRoles(shardsRaw, configured);\n}\n\n/**\n * Idempotent tenant provisioning. Each call:\n *\n * 1. Marks the tenant `pending` if there's no record yet.\n * 2. For every shard role declared in `tenant.d1Shards` in\n * `tamer.config.ts` (or a `--shards` subset): looks up an\n * existing D1 by derived name (`tenantShardDatabaseName(role,\n * …)`), creating it via `d1Create` only when missing. Persists\n * the `(role, derivedName, cfId)` triple to\n * `state.tenants[…].d1Shards[]`.\n * 3. Marks the tenant `d1_created` once *all* requested shards\n * exist in state.\n * 4. Uploads the dispatch script (from `--main` or `--artifact-key`)\n * via the WFP dispatch namespace.\n * 5. Marks the tenant `ready`.\n *\n * When `tenant.d1Shards` is omitted, step 2/3 collapse to a no-op\n * (truly generic single-Worker tenant — only the dispatch script is\n * provisioned). Re-running with the same shard set is a no-op (state\n * already has those rows). Editing `tamer.config.ts` to **extend**\n * the layout (e.g. adding a new role) and re-running picks up the\n * missing shards without disturbing existing ones, so a tenant\n * created with `[\"app\"]` can be migrated to `[\"system\",\"app\",\n * \"history\"]` (or `[\"primary\",\"audit\"]`, or any other set) with one\n * config edit + one `provision-tenant` invocation. Re-running after\n * a config that **shrinks** the layout never deletes shards (use\n * `destroy-tenant` for that).\n */\n/**\n * Machine-readable result envelope emitted on the final stdout line\n * when `--json` is passed. Designed for the Cloudflare Container caller\n * (`provision-workflow`, see `docs/handoff.md` §7) so the Worker can\n * parse the result without scraping human logs. On success the Workflow\n * sees `status: \"ready\"` plus the materialized tenant shape; on\n * failure it sees `status: \"failed\"` with `error` + best-effort\n * `partial` state, and the process exits non-zero.\n */\nexport interface ProvisionTenantResult {\n status: \"ready\" | \"failed\" | \"noop\";\n tenantKey: string;\n product: string;\n workspace: string;\n env: string;\n scriptName: string;\n dispatchNamespaceName: string;\n shards: { role: string; derivedName: string; cfId: string }[];\n error?: string;\n}\n\nexport async function runProvisionTenant(options: {\n env: string;\n product: string;\n workspace: string;\n main?: string;\n artifactKey?: string;\n moduleName?: string;\n configPath?: string;\n compatibilityDate?: string;\n compatibilityFlags?: string[];\n /**\n * Raw `--shards` value (`\"system,app\"` etc.) — validated against\n * `tenant.d1Shards` from the loaded config. Omit to provision every\n * configured shard.\n */\n shardsRaw?: string;\n json?: boolean;\n}): Promise<void> {\n const env = options.env;\n if (env === \"local\") {\n throw new Error(\n \"provision-tenant requires a non-local --env (Cloudflare-backed state).\",\n );\n }\n\n try {\n await provisionTenantInner(options);\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n if (options.json) {\n // Failure envelope: we may have died before loadConfig, so we\n // can't ask `tenant.ephemeralEnvPattern` whether `env` would\n // get the `-{env}` suffix. Emit the non-ephemeral form as a\n // best-effort hint — `error` carries the real signal.\n const result: ProvisionTenantResult = {\n status: \"failed\",\n tenantKey: tenantStateKey(options.product, options.workspace),\n product: options.product,\n workspace: options.workspace,\n env,\n scriptName: `${options.product}-${options.workspace}`,\n dispatchNamespaceName: \"\",\n shards: [],\n error: msg,\n };\n process.stdout.write(JSON.stringify(result) + \"\\n\");\n }\n // Container caller (provision-workflow) reads exit code as\n // primary success/failure signal; JSON envelope on stdout is\n // secondary detail. Re-throw so the CLI surfaces the original\n // error in human mode.\n throw err;\n }\n}\n\nasync function provisionTenantInner(options: {\n env: string;\n product: string;\n workspace: string;\n main?: string;\n artifactKey?: string;\n moduleName?: string;\n configPath?: string;\n compatibilityDate?: string;\n compatibilityFlags?: string[];\n shardsRaw?: string;\n json?: boolean;\n}): Promise<void> {\n const env = options.env;\n const config = await loadConfig(options.configPath, { env });\n const accountId = config.account_id ?? cloudflareAccountIdFromEnv();\n if (!accountId) {\n throw new Error(\n \"account_id required in config or CLOUDFLARE_ACCOUNT_ID env var\",\n );\n }\n\n const dns = getDispatchNamespaces(config);\n if (dns.length === 0) {\n throw new Error(\n \"provision-tenant requires at least one dispatch namespace in the Tamer project config (dispatchNamespaces).\",\n );\n }\n const nsConfig = dns[0]!;\n const dispatchNamespaceName = effectiveDispatchNamespaceName(\n nsConfig,\n env,\n config.tenant,\n );\n const scriptName = tenantDispatchScriptName(\n options.product,\n options.workspace,\n env,\n config.tenant,\n );\n const desiredRoles = resolveShardRoles(\n config.tenant.d1Shards ?? [],\n options.shardsRaw,\n );\n\n const api = new CFApiClient(accountId);\n const state = new StateManager(\n config.tenant.id,\n env,\n stackNameForConfig(config),\n );\n await state.hydrate(api);\n\n let existing = state.getTenant(options.product, options.workspace);\n // \"ready\" is a no-op only when the existing layout already covers\n // every requested shard role. Adding a new role re-opens the tenant\n // for incremental provisioning without forcing a full re-deploy.\n if (existing?.provisioningStatus === \"ready\") {\n const have = new Set((existing.d1Shards ?? []).map((s) => s.role));\n const missing = desiredRoles.filter((r) => !have.has(r));\n if (missing.length === 0) {\n console.log(\n `Tenant ${tenantStateKey(options.product, options.workspace)} already ready; nothing to do.`,\n );\n if (options.json) {\n const result: ProvisionTenantResult = {\n status: \"noop\",\n tenantKey: tenantStateKey(options.product, options.workspace),\n product: options.product,\n workspace: options.workspace,\n env,\n scriptName,\n dispatchNamespaceName,\n shards: (existing.d1Shards ?? []).map((s) => ({\n role: s.role,\n derivedName: s.derivedName,\n cfId: s.cfId,\n })),\n };\n process.stdout.write(JSON.stringify(result) + \"\\n\");\n }\n return;\n }\n console.log(\n `Tenant ${tenantStateKey(options.product, options.workspace)} ready but missing shards: ${missing.join(\", \")}; extending layout.`,\n );\n }\n\n const compatDate =\n options.compatibilityDate ??\n config.compatibility_date ??\n new Date().toISOString().slice(0, 10);\n\n const entryOpts = {\n product: options.product,\n workspace: options.workspace,\n dispatchNamespaceName,\n scriptName,\n };\n\n if (!existing) {\n state.setTenant(buildTenantEntry(entryOpts, \"pending\", undefined));\n await state.persist(api);\n existing = state.getTenant(options.product, options.workspace)!;\n }\n\n // Reconcile each requested shard role. We list D1 once per call when\n // we need to (some role is missing from state) and reuse the result\n // for every subsequent role.\n let allD1: Awaited<ReturnType<typeof api.d1ListAll>> | null = null;\n const shards: TenantD1ShardRef[] = [...(existing.d1Shards ?? [])];\n\n for (const role of desiredRoles) {\n if (shards.find((s) => s.role === role)) continue;\n const derivedName = tenantShardDatabaseName(\n role,\n options.workspace,\n options.product,\n config.tenant.id,\n env,\n );\n if (allD1 === null) {\n allD1 = await api.d1ListAll();\n }\n let cfId = allD1.find((d) => d.name === derivedName)?.uuid;\n if (cfId) {\n // Adopt an existing D1 (e.g. partial-failure resume, or\n // operator created it out-of-band) without re-issuing POST.\n logApplyChange({\n kind: \"d1\",\n action: \"no_change\",\n logical: `${role}-shard`,\n derived: derivedName,\n });\n } else {\n logApplyChange({\n kind: \"d1\",\n action: \"create\",\n logical: `${role}-shard`,\n derived: derivedName,\n });\n const created = await api.d1Create(derivedName);\n cfId = created.uuid;\n }\n shards.push({ role, derivedName, cfId });\n // Persist after each shard so a network failure mid-loop leaves\n // the already-created shards recorded — `provision-tenant` is\n // resumable role-by-role.\n state.setTenant(\n buildTenantEntry(entryOpts, \"d1_created\", existing, { d1Shards: shards }),\n );\n await state.persist(api);\n existing = state.getTenant(options.product, options.workspace)!;\n }\n\n let form: FormData;\n if (options.main) {\n const mainPath = resolve(process.cwd(), options.main);\n form = buildSingleModuleDispatchForm(mainPath, {\n compatibility_date: compatDate,\n compatibility_flags: options.compatibilityFlags,\n });\n } else if (options.artifactKey) {\n const bucket = tamerArtifactsBucketName(env);\n const body = await api.r2GetObject(bucket, options.artifactKey);\n const mod =\n options.moduleName?.trim() ||\n basename(options.artifactKey).replace(/\\.(zip|tar|gz)$/i, \"\") ||\n \"worker.js\";\n form = buildSingleModuleDispatchFormFromBuffer(mod, body, {\n compatibility_date: compatDate,\n compatibility_flags: options.compatibilityFlags,\n });\n } else {\n throw new Error(\"provision-tenant: provide --main or --artifact-key\");\n }\n\n await api.dispatchNamespaceScriptPut(dispatchNamespaceName, scriptName, form);\n\n state.setTenant(\n buildTenantEntry(entryOpts, \"ready\", existing, { d1Shards: shards }),\n );\n await state.persist(api);\n\n const shardsSummary =\n shards.length > 0\n ? `shards: ${shards.map((s) => s.role).join(\", \")}`\n : \"no shards declared\";\n console.log(\n `Provisioned tenant ${tenantStateKey(options.product, options.workspace)} → script ${scriptName} in ${dispatchNamespaceName} (${shardsSummary})`,\n );\n\n if (options.json) {\n const result: ProvisionTenantResult = {\n status: \"ready\",\n tenantKey: tenantStateKey(options.product, options.workspace),\n product: options.product,\n workspace: options.workspace,\n env,\n scriptName,\n dispatchNamespaceName,\n shards: shards.map((s) => ({\n role: s.role,\n derivedName: s.derivedName,\n cfId: s.cfId,\n })),\n };\n process.stdout.write(JSON.stringify(result) + \"\\n\");\n }\n}\n"],"mappings":";;;;;;;;;AAsBA,MAAM,6BAAoB,IAAI,MAAM,EAAC,aAAa;AAElD,SAAS,iBACP,SAMA,QACA,UACA,OACkB;AAClB,QAAO;EACL,SAAS,QAAQ;EACjB,WAAW,QAAQ;EACnB,oBAAoB;EACpB,uBAAuB,QAAQ;EAC/B,YAAY,QAAQ;EACpB,UAAU,OAAO,YAAY,UAAU;EACvC,WAAW,UAAU,aAAa,KAAK;EACvC,WAAW,KAAK;EACjB;;;;;;;;;;;;;;;;;;AAmBH,SAAS,kBACP,YACA,WACU;AACV,KAAI,aAAa,QAAQ,UAAU,MAAM,KAAK,GAAI,QAAO,CAAC,GAAG,WAAW;AACxE,QAAO,sBAAsB,WAAW,WAAW;;AAoDrD,eAAsB,mBAAmB,SAiBvB;CAChB,MAAM,MAAM,QAAQ;AACpB,KAAI,QAAQ,QACV,OAAM,IAAI,MACR,yEACD;AAGH,KAAI;AACF,QAAM,qBAAqB,QAAQ;UAC5B,KAAK;EACZ,MAAM,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI;AAC5D,MAAI,QAAQ,MAAM;GAKhB,MAAMA,SAAgC;IACpC,Q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;GAC7D,SAAS,QAAQ;GACjB,WAAW,QAAQ;GACnB;GACA;GACA;GACA,QAAQ,OAAO,KAAK,OAAO;IACzB,MAAM,EAAE;IACR,aAAa,EAAE;IACf,MAAM,EAAE;IACT,EAAE;GACJ;AACD,UAAQ,OAAO,MAAM,KAAK,UAAU,OAAO,GAAG,KAAK"}
@@ -1,5 +1,5 @@
1
1
  import { n as materializeTamerResolvable } from "./normalize-DVSTRZhO.mjs";
2
- import { A as resolveReferencesInString } from "./tamer.mjs";
2
+ import { j as resolveReferencesInString } from "./tamer.mjs";
3
3
 
4
4
  //#region src/core/outputs/stackOutputs.ts
5
5
  /**
@@ -66,4 +66,4 @@ function buildOutputsView(config, state) {
66
66
 
67
67
  //#endregion
68
68
  export { resolveStackOutputs as n, buildOutputsView as t };
69
- //# sourceMappingURL=stackOutputs-Cltzl2g0.mjs.map
69
+ //# sourceMappingURL=stackOutputs-BLvUMsQO.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"stackOutputs-Cltzl2g0.mjs","names":["out: Record<string, CfiStackOutputValue>","rows: StackOutputRow[]","status: StackOutputRow[\"status\"]"],"sources":["../src/core/outputs/stackOutputs.ts"],"sourcesContent":["/**\n * Tamer's CloudFormation `Outputs` analogue.\n *\n * `tamer.config.ts > outputs` declares named exports as Tamer reference\n * strings (e.g. `\"${tamer:d1:users.id}\"`). After a successful `apply` the\n * engine resolves every entry against the just-completed state and persists\n * the literal under {@link CfiState.stackOutputs}. Sibling stacks consume\n * them via `${tamer:import:<stackName>.<outputName>}` (added separately).\n *\n * Resolution is **strict**: any unresolved/unknown reference fails the\n * apply (and rolls back when `--rollback-on-failure` is set). Read-only\n * commands like `status` use {@link buildOutputsView} which is tolerant\n * and shows the placeholder verbatim alongside the persisted value.\n */\nimport type {\n CfiConfig,\n CfiStackOutputValue,\n} from \"../../types.js\";\nimport { materializeTamerResolvable } from \"../../dx/normalize.js\";\nimport type { NamingEngine } from \"../naming/NamingEngine.js\";\nimport type { StateManager } from \"../state/StateManager.js\";\nimport {\n resolveReferencesInString,\n TamerReferenceError,\n} from \"../references/references.js\";\n\n/**\n * Resolve every `outputs:` entry against the current state. Throws\n * {@link TamerReferenceError} on the first unresolved reference so a failed\n * apply can roll back instead of silently persisting half-resolved values.\n *\n * Pass an explicit `now` only from tests — production code should let it\n * default to wall-clock so `resolvedAt` reflects the real persist time.\n */\nexport function resolveStackOutputs(\n config: CfiConfig,\n ctx: {\n env: string;\n state: StateManager;\n naming: NamingEngine;\n /**\n * Outputs from sibling stacks pre-fetched by `fetchStackImports`.\n * An output may chain through an import (e.g.\n * `outputs: { region: \"${tamer:import:net.region}\" }`) — strict\n * resolution requires the sibling row to be hydrated already.\n */\n imports?: Record<string, Record<string, string>>;\n /** Same as wrangler / apply `accountId` (for `${tamer:config:stack.account_id}` in outputs). */\n accountId?: string;\n },\n now: () => string = () => new Date().toISOString(),\n): Record<string, CfiStackOutputValue> {\n const outputs = config.outputs;\n if (!outputs || Object.keys(outputs).length === 0) return {};\n const refCtx = {\n config,\n env: ctx.env,\n state: ctx.state,\n naming: ctx.naming,\n tolerant: false,\n imports: ctx.imports,\n accountId: ctx.accountId,\n };\n const resolvedAt = now();\n const out: Record<string, CfiStackOutputValue> = {};\n for (const [name, source] of Object.entries(outputs)) {\n const sourceStr = materializeTamerResolvable(source);\n const value = resolveReferencesInString(\n sourceStr,\n refCtx,\n `outputs.${name}`,\n );\n out[name] = { value, source: sourceStr, resolvedAt };\n }\n return out;\n}\n\n/**\n * One row in the `tamer status` outputs panel. Combines the *declared*\n * source (from `tamer.config.ts`) with the *persisted* value (from state)\n * so operators can see drift between \"what the config says\" and \"what we\n * last resolved\". `value` is `null` when the output is declared but has\n * never been resolved (no `apply` yet), or when a stale persisted entry\n * exists for an output that has since been removed from config.\n */\nexport interface StackOutputRow {\n name: string;\n /** Live source from `tamer.config.ts > outputs[name]`, if still declared. */\n declaredSource: string | undefined;\n /** Persisted resolved literal, if `apply` has run for this output. */\n value: string | null;\n /** Source string at last persist (drifts vs. `declaredSource` after edits). */\n persistedSource: string | undefined;\n /** ISO timestamp of last persist (undefined when never resolved). */\n resolvedAt: string | undefined;\n /**\n * `\"resolved\"` when persisted matches declared source, `\"stale\"` when\n * source has drifted since persist (re-run apply), `\"orphan\"` when\n * persisted but no longer declared, `\"pending\"` when declared but never\n * resolved.\n */\n status: \"resolved\" | \"stale\" | \"orphan\" | \"pending\";\n}\n\n/**\n * Tolerant union of declared + persisted outputs for `tamer status` and the\n * machine-readable `--json` envelope. Never throws.\n */\nexport function buildOutputsView(\n config: CfiConfig,\n state: StateManager,\n): StackOutputRow[] {\n const declared = config.outputs ?? {};\n const persisted = state.getStackOutputs();\n const names = new Set<string>([\n ...Object.keys(declared),\n ...Object.keys(persisted),\n ]);\n const rows: StackOutputRow[] = [];\n for (const name of [...names].sort()) {\n const rawDeclared = declared[name];\n const declaredSource =\n rawDeclared !== undefined ? materializeTamerResolvable(rawDeclared) : undefined;\n const p = persisted[name];\n let status: StackOutputRow[\"status\"];\n if (declaredSource && !p) status = \"pending\";\n else if (!declaredSource && p) status = \"orphan\";\n else if (declaredSource && p && declaredSource !== p.source) status = \"stale\";\n else status = \"resolved\";\n rows.push({\n name,\n declaredSource,\n value: p?.value ?? null,\n persistedSource: p?.source,\n resolvedAt: p?.resolvedAt,\n status,\n });\n }\n return rows;\n}\n\nexport { TamerReferenceError };\n"],"mappings":";;;;;;;;;;;;AAkCA,SAAgB,oBACd,QACA,KAcA,6BAA0B,IAAI,MAAM,EAAC,aAAa,EACb;CACrC,MAAM,UAAU,OAAO;AACvB,KAAI,CAAC,WAAW,OAAO,KAAK,QAAQ,CAAC,WAAW,EAAG,QAAO,EAAE;CAC5D,MAAM,SAAS;EACb;EACA,KAAK,IAAI;EACT,OAAO,IAAI;EACX,QAAQ,IAAI;EACZ,UAAU;EACV,SAAS,IAAI;EACb,WAAW,IAAI;EAChB;CACD,MAAM,aAAa,KAAK;CACxB,MAAMA,MAA2C,EAAE;AACnD,MAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,QAAQ,EAAE;EACpD,MAAM,YAAY,2BAA2B,OAAO;AAMpD,MAAI,QAAQ;GAAE,OALA,0BACZ,WACA,QACA,WAAW,OACZ;GACoB,QAAQ;GAAW;GAAY;;AAEtD,QAAO;;;;;;AAkCT,SAAgB,iBACd,QACA,OACkB;CAClB,MAAM,WAAW,OAAO,WAAW,EAAE;CACrC,MAAM,YAAY,MAAM,iBAAiB;CACzC,MAAM,QAAQ,IAAI,IAAY,CAC5B,GAAG,OAAO,KAAK,SAAS,EACxB,GAAG,OAAO,KAAK,UAAU,CAC1B,CAAC;CACF,MAAMC,OAAyB,EAAE;AACjC,MAAK,MAAM,QAAQ,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE;EACpC,MAAM,cAAc,SAAS;EAC7B,MAAM,iBACJ,gBAAgB,SAAY,2BAA2B,YAAY,GAAG;EACxE,MAAM,IAAI,UAAU;EACpB,IAAIC;AACJ,MAAI,kBAAkB,CAAC,EAAG,UAAS;WAC1B,CAAC,kBAAkB,EAAG,UAAS;WAC/B,kBAAkB,KAAK,mBAAmB,EAAE,OAAQ,UAAS;MACjE,UAAS;AACd,OAAK,KAAK;GACR;GACA;GACA,OAAO,GAAG,SAAS;GACnB,iBAAiB,GAAG;GACpB,YAAY,GAAG;GACf;GACD,CAAC;;AAEJ,QAAO"}
1
+ {"version":3,"file":"stackOutputs-BLvUMsQO.mjs","names":["out: Record<string, CfiStackOutputValue>","rows: StackOutputRow[]","status: StackOutputRow[\"status\"]"],"sources":["../src/core/outputs/stackOutputs.ts"],"sourcesContent":["/**\n * Tamer's CloudFormation `Outputs` analogue.\n *\n * `tamer.config.ts > outputs` declares named exports as Tamer reference\n * strings (e.g. `\"${tamer:d1:users.id}\"`). After a successful `apply` the\n * engine resolves every entry against the just-completed state and persists\n * the literal under {@link CfiState.stackOutputs}. Sibling stacks consume\n * them via `${tamer:import:<stackName>.<outputName>}` (added separately).\n *\n * Resolution is **strict**: any unresolved/unknown reference fails the\n * apply (and rolls back when `--rollback-on-failure` is set). Read-only\n * commands like `status` use {@link buildOutputsView} which is tolerant\n * and shows the placeholder verbatim alongside the persisted value.\n */\nimport type {\n CfiConfig,\n CfiStackOutputValue,\n} from \"../../types.js\";\nimport { materializeTamerResolvable } from \"../../dx/normalize.js\";\nimport type { NamingEngine } from \"../naming/NamingEngine.js\";\nimport type { StateManager } from \"../state/StateManager.js\";\nimport {\n resolveReferencesInString,\n TamerReferenceError,\n} from \"../references/references.js\";\n\n/**\n * Resolve every `outputs:` entry against the current state. Throws\n * {@link TamerReferenceError} on the first unresolved reference so a failed\n * apply can roll back instead of silently persisting half-resolved values.\n *\n * Pass an explicit `now` only from tests — production code should let it\n * default to wall-clock so `resolvedAt` reflects the real persist time.\n */\nexport function resolveStackOutputs(\n config: CfiConfig,\n ctx: {\n env: string;\n state: StateManager;\n naming: NamingEngine;\n /**\n * Outputs from sibling stacks pre-fetched by `fetchStackImports`.\n * An output may chain through an import (e.g.\n * `outputs: { region: \"${tamer:import:net.region}\" }`) — strict\n * resolution requires the sibling row to be hydrated already.\n */\n imports?: Record<string, Record<string, string>>;\n /** Same as wrangler / apply `accountId` (for `${tamer:config:stack.account_id}` in outputs). */\n accountId?: string;\n },\n now: () => string = () => new Date().toISOString(),\n): Record<string, CfiStackOutputValue> {\n const outputs = config.outputs;\n if (!outputs || Object.keys(outputs).length === 0) return {};\n const refCtx = {\n config,\n env: ctx.env,\n state: ctx.state,\n naming: ctx.naming,\n tolerant: false,\n imports: ctx.imports,\n accountId: ctx.accountId,\n };\n const resolvedAt = now();\n const out: Record<string, CfiStackOutputValue> = {};\n for (const [name, source] of Object.entries(outputs)) {\n const sourceStr = materializeTamerResolvable(source);\n const value = resolveReferencesInString(\n sourceStr,\n refCtx,\n `outputs.${name}`,\n );\n out[name] = { value, source: sourceStr, resolvedAt };\n }\n return out;\n}\n\n/**\n * One row in the `tamer status` outputs panel. Combines the *declared*\n * source (from `tamer.config.ts`) with the *persisted* value (from state)\n * so operators can see drift between \"what the config says\" and \"what we\n * last resolved\". `value` is `null` when the output is declared but has\n * never been resolved (no `apply` yet), or when a stale persisted entry\n * exists for an output that has since been removed from config.\n */\nexport interface StackOutputRow {\n name: string;\n /** Live source from `tamer.config.ts > outputs[name]`, if still declared. */\n declaredSource: string | undefined;\n /** Persisted resolved literal, if `apply` has run for this output. */\n value: string | null;\n /** Source string at last persist (drifts vs. `declaredSource` after edits). */\n persistedSource: string | undefined;\n /** ISO timestamp of last persist (undefined when never resolved). */\n resolvedAt: string | undefined;\n /**\n * `\"resolved\"` when persisted matches declared source, `\"stale\"` when\n * source has drifted since persist (re-run apply), `\"orphan\"` when\n * persisted but no longer declared, `\"pending\"` when declared but never\n * resolved.\n */\n status: \"resolved\" | \"stale\" | \"orphan\" | \"pending\";\n}\n\n/**\n * Tolerant union of declared + persisted outputs for `tamer status` and the\n * machine-readable `--json` envelope. Never throws.\n */\nexport function buildOutputsView(\n config: CfiConfig,\n state: StateManager,\n): StackOutputRow[] {\n const declared = config.outputs ?? {};\n const persisted = state.getStackOutputs();\n const names = new Set<string>([\n ...Object.keys(declared),\n ...Object.keys(persisted),\n ]);\n const rows: StackOutputRow[] = [];\n for (const name of [...names].sort()) {\n const rawDeclared = declared[name];\n const declaredSource =\n rawDeclared !== undefined ? materializeTamerResolvable(rawDeclared) : undefined;\n const p = persisted[name];\n let status: StackOutputRow[\"status\"];\n if (declaredSource && !p) status = \"pending\";\n else if (!declaredSource && p) status = \"orphan\";\n else if (declaredSource && p && declaredSource !== p.source) status = \"stale\";\n else status = \"resolved\";\n rows.push({\n name,\n declaredSource,\n value: p?.value ?? null,\n persistedSource: p?.source,\n resolvedAt: p?.resolvedAt,\n status,\n });\n }\n return rows;\n}\n\nexport { TamerReferenceError };\n"],"mappings":";;;;;;;;;;;;AAkCA,SAAgB,oBACd,QACA,KAcA,6BAA0B,IAAI,MAAM,EAAC,aAAa,EACb;CACrC,MAAM,UAAU,OAAO;AACvB,KAAI,CAAC,WAAW,OAAO,KAAK,QAAQ,CAAC,WAAW,EAAG,QAAO,EAAE;CAC5D,MAAM,SAAS;EACb;EACA,KAAK,IAAI;EACT,OAAO,IAAI;EACX,QAAQ,IAAI;EACZ,UAAU;EACV,SAAS,IAAI;EACb,WAAW,IAAI;EAChB;CACD,MAAM,aAAa,KAAK;CACxB,MAAMA,MAA2C,EAAE;AACnD,MAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,QAAQ,EAAE;EACpD,MAAM,YAAY,2BAA2B,OAAO;AAMpD,MAAI,QAAQ;GAAE,OALA,0BACZ,WACA,QACA,WAAW,OACZ;GACoB,QAAQ;GAAW;GAAY;;AAEtD,QAAO;;;;;;AAkCT,SAAgB,iBACd,QACA,OACkB;CAClB,MAAM,WAAW,OAAO,WAAW,EAAE;CACrC,MAAM,YAAY,MAAM,iBAAiB;CACzC,MAAM,QAAQ,IAAI,IAAY,CAC5B,GAAG,OAAO,KAAK,SAAS,EACxB,GAAG,OAAO,KAAK,UAAU,CAC1B,CAAC;CACF,MAAMC,OAAyB,EAAE;AACjC,MAAK,MAAM,QAAQ,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE;EACpC,MAAM,cAAc,SAAS;EAC7B,MAAM,iBACJ,gBAAgB,SAAY,2BAA2B,YAAY,GAAG;EACxE,MAAM,IAAI,UAAU;EACpB,IAAIC;AACJ,MAAI,kBAAkB,CAAC,EAAG,UAAS;WAC1B,CAAC,kBAAkB,EAAG,UAAS;WAC/B,kBAAkB,KAAK,mBAAmB,EAAE,OAAQ,UAAS;MACjE,UAAS;AACd,OAAK,KAAK;GACR;GACA;GACA,OAAO,GAAG,SAAS;GACnB,iBAAiB,GAAG;GACpB,YAAY,GAAG;GACf;GACD,CAAC;;AAEJ,QAAO"}
@@ -1,10 +1,10 @@
1
1
  import { f as getDispatchNamespaces, m as getLogpushJobs, p as getDnsRecords } from "./normalize-DVSTRZhO.mjs";
2
- import { B as getWorkers, C as stackNameForConfig, D as resolveDeployedWorkerName, L as CFApiClient, P as namingFromConfig, R as cloudflareAccountIdFromEnv, T as mergeWorkerConfigForResourcePick, V as loadConfig, d as fetchStackImports, m as StateManager, p as scanConfigForImports, v as tenantStateKey } from "./tamer.mjs";
2
+ import { B as getWorkers, E as mergeWorkerConfigForResourcePick, L as CFApiClient, O as resolveDeployedWorkerName, R as cloudflareAccountIdFromEnv, V as loadConfig, f as fetchStackImports, h as StateManager, m as scanConfigForImports, u as namingFromConfig, w as stackNameForConfig, y as tenantStateKey } from "./tamer.mjs";
3
3
  import { n as resourceModules } from "./registry-EWWdkLf7.mjs";
4
4
  import "./r2S3EmptyBucket-B9_pHfvB.mjs";
5
5
  import { r as dnsRecordStateKey, t as dnsRecordAppliesToEnv } from "./dns-records.resolve-BB2agPAb.mjs";
6
6
  import { t as logpushJobStatus } from "./logpush-job-DJPlpnRu.mjs";
7
- import { t as buildOutputsView } from "./stackOutputs-Cltzl2g0.mjs";
7
+ import { t as buildOutputsView } from "./stackOutputs-BLvUMsQO.mjs";
8
8
 
9
9
  //#region src/features/dispatch-namespace/dispatch-namespace.status.ts
10
10
  function dispatchNamespaceStatus(resources, _env, state, _naming) {
@@ -193,4 +193,4 @@ async function runStatus(options) {
193
193
 
194
194
  //#endregion
195
195
  export { runStatus };
196
- //# sourceMappingURL=status-DkkS5lc9.mjs.map
196
+ //# sourceMappingURL=status-BxStsax8.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"status-DkkS5lc9.mjs","names":["results: Array<{\n logicalName: string;\n namespace: string;\n status: ResourceStatus;\n }>","rows: DnsRecordStatusRow[]","meta: string[]","siblingImports: Record<string, Record<string, string>>","logpushLive:\n | Awaited<ReturnType<CFApiClient[\"logpushAccountJobsList\"]>>\n | undefined","hints: string[]"],"sources":["../src/features/dispatch-namespace/dispatch-namespace.status.ts","../src/features/dns-records/dns-records.status.ts","../src/cli/commands/status.ts"],"sourcesContent":["import type { DispatchNamespaceResourceConfig } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { ResourceStatus } from \"../../types.js\";\n\nexport function dispatchNamespaceStatus(\n resources: DispatchNamespaceResourceConfig[],\n _env: string,\n state: StateManager,\n _naming: NamingEngine,\n): Array<{ logicalName: string; namespace: string; status: ResourceStatus }> {\n const results: Array<{\n logicalName: string;\n namespace: string;\n status: ResourceStatus;\n }> = [];\n\n for (const config of resources) {\n const key = `dispatch_ns:${config.namespace}`;\n const entry = state.get(key);\n results.push({\n logicalName: config.logicalName,\n namespace: config.namespace,\n status:\n entry?.type === \"dispatch_namespace\" ? \"ok\" : \"missing\",\n });\n }\n\n return results;\n}\n","import type { DnsRecordResourceConfig, ResourceStatus } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport {\n dnsRecordAppliesToEnv,\n dnsRecordStateKey,\n} from \"./dns-records.resolve.js\";\n\nexport interface DnsRecordStatusRow {\n logicalName: string;\n type: string;\n name: string;\n recordId?: string;\n status: ResourceStatus;\n}\n\nexport function dnsRecordStatus(\n resources: DnsRecordResourceConfig[],\n env: string,\n state: StateManager,\n): DnsRecordStatusRow[] {\n const rows: DnsRecordStatusRow[] = [];\n for (const config of resources) {\n if (!dnsRecordAppliesToEnv(config, env)) {\n rows.push({\n logicalName: config.logicalName,\n type: config.type,\n name: config.name,\n status: \"ok\",\n });\n continue;\n }\n const entry = state.get(\n dnsRecordStateKey(config.zoneId, config.type, config.name),\n );\n if (entry?.type === \"dns_record\") {\n rows.push({\n logicalName: config.logicalName,\n type: entry.recordType,\n name: entry.name,\n recordId: entry.recordId,\n status: \"ok\",\n });\n } else {\n rows.push({\n logicalName: config.logicalName,\n type: config.type,\n name: config.name,\n status: \"missing\",\n });\n }\n }\n return rows;\n}\n","import { loadConfig, getWorkers } from \"../../core/config/loader.js\";\nimport { cloudflareAccountIdFromEnv } from \"../../core/cloudflareEnv.js\";\nimport { namingFromConfig } from \"../../core/config/namingFromConfig.js\";\nimport { StateManager } from \"../../core/state/StateManager.js\";\nimport { stackNameForConfig } from \"../../core/state/stackName.js\";\nimport { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { dispatchNamespaceStatus } from \"../../features/dispatch-namespace/index.js\";\nimport { dnsRecordStatus } from \"../../features/dns-records/index.js\";\nimport { getDispatchNamespaces, getDnsRecords, getLogpushJobs } from \"../../types.js\";\nimport { logpushJobStatus } from \"../../features/logpush-job/index.js\";\nimport { tenantStateKey } from \"../../core/tenant/tenantKeys.js\";\nimport { resourceModules } from \"../../core/registry/registry.js\";\nimport {\n resolveDeployedWorkerName,\n mergeWorkerConfigForResourcePick,\n} from \"../../core/config/resolver.js\";\nimport { buildOutputsView } from \"../../core/outputs/stackOutputs.js\";\nimport {\n fetchStackImports,\n scanConfigForImports,\n} from \"../../core/imports/fetchStackImports.js\";\n\nexport async function runStatus(options: {\n env?: string;\n configPath?: string;\n /** `product:workspace` — show only this workspace tenant from state. */\n tenant?: string;\n}): Promise<void> {\n const env = options.env ?? \"local\";\n const configPath = options.configPath;\n const baseDir = process.cwd();\n\n const config = await loadConfig(configPath, { env });\n const accountId =\n config.account_id ?? cloudflareAccountIdFromEnv();\n if (!accountId) {\n throw new Error(\n \"account_id required in config or CLOUDFLARE_ACCOUNT_ID env var\",\n );\n }\n const naming = namingFromConfig(config);\n const api = new CFApiClient(accountId);\n const state = new StateManager(\n config.tenant.id,\n env,\n stackNameForConfig(config),\n );\n await state.hydrate(api);\n\n const workers = await getWorkers(config, baseDir);\n console.log(\n `\\nStatus for ${config.tenant.name} (${config.tenant.slug}) — env: ${env}\\n`,\n );\n\n if (options.tenant?.trim()) {\n const raw = options.tenant.trim();\n const colon = raw.indexOf(\":\");\n if (colon < 1) {\n throw new Error(\n 'status --tenant expects \"product:workspace\" (e.g. todo:acme)',\n );\n }\n const product = raw.slice(0, colon);\n const workspace = raw.slice(colon + 1);\n const t = state.getTenant(product, workspace);\n console.log(`Workspace tenant ${tenantStateKey(product, workspace)}:`);\n if (!t) {\n console.log(\" (no record in tamer state)\\n\");\n return;\n }\n console.log(` status: ${t.provisioningStatus}`);\n console.log(` dispatch namespace: ${t.dispatchNamespaceName}`);\n console.log(` script: ${t.scriptName}`);\n if (t.d1Shards?.length) {\n console.log(\" D1 shards:\");\n for (const s of t.d1Shards) {\n console.log(` ${s.role}: ${s.derivedName} [${s.cfId}]`);\n }\n }\n console.log();\n return;\n }\n\n const outputRows = buildOutputsView(config, state);\n if (outputRows.length > 0) {\n console.log(\"Stack outputs:\");\n for (const r of outputRows) {\n const valueText =\n r.value === null\n ? \"(unresolved — run apply)\"\n : r.value;\n const meta: string[] = [r.status];\n if (r.status === \"stale\" && r.declaredSource) {\n meta.push(`source drifted → ${r.declaredSource}`);\n }\n console.log(` ${r.name}: ${valueText} [${meta.join(\", \")}]`);\n }\n console.log();\n }\n\n // Inbound imports — show every `${tamer:import:<stack>.<output>}`\n // referenced by config, grouped by source stack. We tolerate fetch\n // failures so `tamer status` still works in offline / partial-cred\n // environments; a missing sibling row just displays \"(unresolved)\".\n const importRefs = scanConfigForImports(config);\n let siblingImports: Record<string, Record<string, string>> = {};\n try {\n siblingImports = await fetchStackImports(api, config, env);\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n console.warn(`(could not pre-fetch imported stacks: ${msg})`);\n }\n if (importRefs.length > 0) {\n console.log(\"Stack imports:\");\n const byStack = new Map<string, Set<string>>();\n for (const r of importRefs) {\n if (!byStack.has(r.stack)) byStack.set(r.stack, new Set());\n byStack.get(r.stack)!.add(r.output);\n }\n for (const [stack, outputs] of [...byStack].sort(([a], [b]) =>\n a.localeCompare(b),\n )) {\n console.log(` from stack \"${stack}\":`);\n const stackOutputs = siblingImports[stack] ?? {};\n for (const out of [...outputs].sort()) {\n const v = stackOutputs[out];\n const status = v === undefined ? \"unresolved\" : \"resolved\";\n const value = v ?? \"(missing — run `tamer apply` on that stack)\";\n console.log(` ${out}: ${value} [${status}]`);\n }\n }\n console.log();\n }\n\n const dns = dispatchNamespaceStatus(\n getDispatchNamespaces(config),\n env,\n state,\n naming,\n );\n if (dns.length > 0) {\n console.log(\"Dispatch namespaces:\");\n for (const r of dns) {\n console.log(` ${r.logicalName} (${r.namespace}) [${r.status}]`);\n }\n console.log();\n }\n\n const dnsRows = dnsRecordStatus(getDnsRecords(config), env, state);\n if (dnsRows.length > 0) {\n console.log(\"DNS records:\");\n for (const r of dnsRows) {\n const id = r.recordId ? ` [${r.recordId}]` : \"\";\n console.log(` ${r.logicalName}: ${r.type} ${r.name}${id} [${r.status}]`);\n }\n console.log();\n }\n\n let logpushLive:\n | Awaited<ReturnType<CFApiClient[\"logpushAccountJobsList\"]>>\n | undefined;\n if (env !== \"local\") {\n try {\n logpushLive = await api.logpushAccountJobsList();\n } catch {\n // Token may lack Logpush list; state-only rows still print.\n }\n }\n const logpushRows = logpushJobStatus(\n getLogpushJobs(config),\n config.tenant,\n env,\n state,\n logpushLive,\n );\n if (logpushRows.length > 0) {\n console.log(\"Logpush jobs:\");\n for (const r of logpushRows) {\n const id = r.cfJobId != null ? ` [id ${r.cfJobId}]` : \"\";\n const hints: string[] = [];\n if (r.cfEnabled === false) hints.push(\"disabled on Cloudflare\");\n if (r.cfError) hints.push(`CF error: ${r.cfError}`);\n const hint = hints.length > 0 ? ` — ${hints.join(\"; \")}` : \"\";\n console.log(` ${r.logicalName}: ${r.jobName}${id} [${r.status}]${hint}`);\n }\n console.log();\n }\n\n for (const [workerKey, workerConfig] of workers) {\n console.log(`Worker: ${workerKey}`);\n const deployedName = resolveDeployedWorkerName(\n config,\n workerKey,\n workerConfig,\n env,\n naming,\n );\n const mergedWorker = mergeWorkerConfigForResourcePick(\n config,\n workerKey,\n workerConfig,\n env,\n accountId,\n naming,\n state,\n { referencesMode: \"tolerant\", imports: siblingImports },\n );\n let printedAny = false;\n for (const mod of resourceModules) {\n const resources = mod.pickResources(mergedWorker);\n if (resources.length === 0) continue;\n const rows = mod.status({\n resources,\n env,\n state,\n naming,\n worker: { workerKey, deployedName },\n });\n if (rows.length === 0) continue;\n printedAny = true;\n console.log(` ${mod.label}:`);\n for (const r of rows) {\n console.log(` ${r.binding}: ${r.name} [${r.status}]`);\n }\n }\n if (!printedAny) console.log(\" (no resources)\");\n console.log();\n }\n}\n"],"mappings":";;;;;;;;;AAKA,SAAgB,wBACd,WACA,MACA,OACA,SAC2E;CAC3E,MAAMA,UAID,EAAE;AAEP,MAAK,MAAM,UAAU,WAAW;EAC9B,MAAM,MAAM,eAAe,OAAO;EAClC,MAAM,QAAQ,MAAM,IAAI,IAAI;AAC5B,UAAQ,KAAK;GACX,aAAa,OAAO;GACpB,WAAW,OAAO;GAClB,QACE,OAAO,SAAS,uBAAuB,OAAO;GACjD,CAAC;;AAGJ,QAAO;;;;;ACbT,SAAgB,gBACd,WACA,KACA,OACsB;CACtB,MAAMC,OAA6B,EAAE;AACrC,MAAK,MAAM,UAAU,WAAW;AAC9B,MAAI,CAAC,sBAAsB,QAAQ,IAAI,EAAE;AACvC,QAAK,KAAK;IACR,aAAa,OAAO;IACpB,MAAM,OAAO;IACb,MAAM,OAAO;IACb,QAAQ;IACT,CAAC;AACF;;EAEF,MAAM,QAAQ,MAAM,IAClB,kBAAkB,OAAO,QAAQ,OAAO,MAAM,OAAO,KAAK,CAC3D;AACD,MAAI,OAAO,SAAS,aAClB,MAAK,KAAK;GACR,aAAa,OAAO;GACpB,MAAM,MAAM;GACZ,MAAM,MAAM;GACZ,UAAU,MAAM;GAChB,QAAQ;GACT,CAAC;MAEF,MAAK,KAAK;GACR,aAAa,OAAO;GACpB,MAAM,OAAO;GACb,MAAM,OAAO;GACb,QAAQ;GACT,CAAC;;AAGN,QAAO;;;;;AC7BT,eAAsB,UAAU,SAKd;CAChB,MAAM,MAAM,QAAQ,OAAO;CAC3B,MAAM,aAAa,QAAQ;CAC3B,MAAM,UAAU,QAAQ,KAAK;CAE7B,MAAM,SAAS,MAAM,WAAW,YAAY,EAAE,KAAK,CAAC;CACpD,MAA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W,YAAY;EACnC,MAAM,eAAe,0BACnB,QACA,WACA,cACA,KACA,OACD;EACD,MAAM,eAAe,iCACnB,QACA,WACA,cACA,KACA,WACA,QACA,OACA;GAAE,gBAAgB;GAAY,SAAS;GAAgB,CACxD;EACD,IAAI,aAAa;AACjB,OAAK,MAAM,OAAO,iBAAiB;GACjC,MAAM,YAAY,IAAI,cAAc,aAAa;AACjD,OAAI,UAAU,WAAW,EAAG;GAC5B,MAAM,OAAO,IAAI,OAAO;IACtB;IACA;IACA;IACA;IACA,QAAQ;KAAE;KAAW;KAAc;IACpC,CAAC;AACF,OAAI,KAAK,WAAW,EAAG;AACvB,gBAAa;AACb,WAAQ,IAAI,KAAK,IAAI,MAAM,GAAG;AAC9B,QAAK,MAAM,KAAK,KACd,SAAQ,IAAI,OAAO,EAAE,QAAQ,IAAI,EAAE,KAAK,IAAI,EAAE,OAAO,GAAG;;AAG5D,MAAI,CAAC,WAAY,SAAQ,IAAI,mBAAmB;AAChD,UAAQ,KAAK"}
1
+ {"version":3,"file":"status-BxStsax8.mjs","names":["results: Array<{\n logicalName: string;\n namespace: string;\n status: ResourceStatus;\n }>","rows: DnsRecordStatusRow[]","meta: string[]","siblingImports: Record<string, Record<string, string>>","logpushLive:\n | Awaited<ReturnType<CFApiClient[\"logpushAccountJobsList\"]>>\n | undefined","hints: string[]"],"sources":["../src/features/dispatch-namespace/dispatch-namespace.status.ts","../src/features/dns-records/dns-records.status.ts","../src/cli/commands/status.ts"],"sourcesContent":["import type { DispatchNamespaceResourceConfig } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { ResourceStatus } from \"../../types.js\";\n\nexport function dispatchNamespaceStatus(\n resources: DispatchNamespaceResourceConfig[],\n _env: string,\n state: StateManager,\n _naming: NamingEngine,\n): Array<{ logicalName: string; namespace: string; status: ResourceStatus }> {\n const results: Array<{\n logicalName: string;\n namespace: string;\n status: ResourceStatus;\n }> = [];\n\n for (const config of resources) {\n const key = `dispatch_ns:${config.namespace}`;\n const entry = state.get(key);\n results.push({\n logicalName: config.logicalName,\n namespace: config.namespace,\n status:\n entry?.type === \"dispatch_namespace\" ? \"ok\" : \"missing\",\n });\n }\n\n return results;\n}\n","import type { DnsRecordResourceConfig, ResourceStatus } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport {\n dnsRecordAppliesToEnv,\n dnsRecordStateKey,\n} from \"./dns-records.resolve.js\";\n\nexport interface DnsRecordStatusRow {\n logicalName: string;\n type: string;\n name: string;\n recordId?: string;\n status: ResourceStatus;\n}\n\nexport function dnsRecordStatus(\n resources: DnsRecordResourceConfig[],\n env: string,\n state: StateManager,\n): DnsRecordStatusRow[] {\n const rows: DnsRecordStatusRow[] = [];\n for (const config of resources) {\n if (!dnsRecordAppliesToEnv(config, env)) {\n rows.push({\n logicalName: config.logicalName,\n type: config.type,\n name: config.name,\n status: \"ok\",\n });\n continue;\n }\n const entry = state.get(\n dnsRecordStateKey(config.zoneId, config.type, config.name),\n );\n if (entry?.type === \"dns_record\") {\n rows.push({\n logicalName: config.logicalName,\n type: entry.recordType,\n name: entry.name,\n recordId: entry.recordId,\n status: \"ok\",\n });\n } else {\n rows.push({\n logicalName: config.logicalName,\n type: config.type,\n name: config.name,\n status: \"missing\",\n });\n }\n }\n return rows;\n}\n","import { loadConfig, getWorkers } from \"../../core/config/loader.js\";\nimport { cloudflareAccountIdFromEnv } from \"../../core/cloudflareEnv.js\";\nimport { namingFromConfig } from \"../../core/config/namingFromConfig.js\";\nimport { StateManager } from \"../../core/state/StateManager.js\";\nimport { stackNameForConfig } from \"../../core/state/stackName.js\";\nimport { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { dispatchNamespaceStatus } from \"../../features/dispatch-namespace/index.js\";\nimport { dnsRecordStatus } from \"../../features/dns-records/index.js\";\nimport { getDispatchNamespaces, getDnsRecords, getLogpushJobs } from \"../../types.js\";\nimport { logpushJobStatus } from \"../../features/logpush-job/index.js\";\nimport { tenantStateKey } from \"../../core/tenant/tenantKeys.js\";\nimport { resourceModules } from \"../../core/registry/registry.js\";\nimport {\n resolveDeployedWorkerName,\n mergeWorkerConfigForResourcePick,\n} from \"../../core/config/resolver.js\";\nimport { buildOutputsView } from \"../../core/outputs/stackOutputs.js\";\nimport {\n fetchStackImports,\n scanConfigForImports,\n} from \"../../core/imports/fetchStackImports.js\";\n\nexport async function runStatus(options: {\n env?: string;\n configPath?: string;\n /** `product:workspace` — show only this workspace tenant from state. */\n tenant?: string;\n}): Promise<void> {\n const env = options.env ?? \"local\";\n const configPath = options.configPath;\n const baseDir = process.cwd();\n\n const config = await loadConfig(configPath, { env });\n const accountId =\n config.account_id ?? cloudflareAccountIdFromEnv();\n if (!accountId) {\n throw new Error(\n \"account_id required in config or CLOUDFLARE_ACCOUNT_ID env var\",\n );\n }\n const naming = namingFromConfig(config);\n const api = new CFApiClient(accountId);\n const state = new StateManager(\n config.tenant.id,\n env,\n stackNameForConfig(config),\n );\n await state.hydrate(api);\n\n const workers = await getWorkers(config, baseDir);\n console.log(\n `\\nStatus for ${config.tenant.name} (${config.tenant.slug}) — env: ${env}\\n`,\n );\n\n if (options.tenant?.trim()) {\n const raw = options.tenant.trim();\n const colon = raw.indexOf(\":\");\n if (colon < 1) {\n throw new Error(\n 'status --tenant expects \"product:workspace\" (e.g. todo:acme)',\n );\n }\n const product = raw.slice(0, colon);\n const workspace = raw.slice(colon + 1);\n const t = state.getTenant(product, workspace);\n console.log(`Workspace tenant ${tenantStateKey(product, workspace)}:`);\n if (!t) {\n console.log(\" (no record in tamer state)\\n\");\n return;\n }\n console.log(` status: ${t.provisioningStatus}`);\n console.log(` dispatch namespace: ${t.dispatchNamespaceName}`);\n console.log(` script: ${t.scriptName}`);\n if (t.d1Shards?.length) {\n console.log(\" D1 shards:\");\n for (const s of t.d1Shards) {\n console.log(` ${s.role}: ${s.derivedName} [${s.cfId}]`);\n }\n }\n console.log();\n return;\n }\n\n const outputRows = buildOutputsView(config, state);\n if (outputRows.length > 0) {\n console.log(\"Stack outputs:\");\n for (const r of outputRows) {\n const valueText =\n r.value === null\n ? \"(unresolved — run apply)\"\n : r.value;\n const meta: string[] = [r.status];\n if (r.status === \"stale\" && r.declaredSource) {\n meta.push(`source drifted → ${r.declaredSource}`);\n }\n console.log(` ${r.name}: ${valueText} [${meta.join(\", \")}]`);\n }\n console.log();\n }\n\n // Inbound imports — show every `${tamer:import:<stack>.<output>}`\n // referenced by config, grouped by source stack. We tolerate fetch\n // failures so `tamer status` still works in offline / partial-cred\n // environments; a missing sibling row just displays \"(unresolved)\".\n const importRefs = scanConfigForImports(config);\n let siblingImports: Record<string, Record<string, string>> = {};\n try {\n siblingImports = await fetchStackImports(api, config, env);\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n console.warn(`(could not pre-fetch imported stacks: ${msg})`);\n }\n if (importRefs.length > 0) {\n console.log(\"Stack imports:\");\n const byStack = new Map<string, Set<string>>();\n for (const r of importRefs) {\n if (!byStack.has(r.stack)) byStack.set(r.stack, new Set());\n byStack.get(r.stack)!.add(r.output);\n }\n for (const [stack, outputs] of [...byStack].sort(([a], [b]) =>\n a.localeCompare(b),\n )) {\n console.log(` from stack \"${stack}\":`);\n const stackOutputs = siblingImports[stack] ?? {};\n for (const out of [...outputs].sort()) {\n const v = stackOutputs[out];\n const status = v === undefined ? \"unresolved\" : \"resolved\";\n const value = v ?? \"(missing — run `tamer apply` on that stack)\";\n console.log(` ${out}: ${value} [${status}]`);\n }\n }\n console.log();\n }\n\n const dns = dispatchNamespaceStatus(\n getDispatchNamespaces(config),\n env,\n state,\n naming,\n );\n if (dns.length > 0) {\n console.log(\"Dispatch namespaces:\");\n for (const r of dns) {\n console.log(` ${r.logicalName} (${r.namespace}) [${r.status}]`);\n }\n console.log();\n }\n\n const dnsRows = dnsRecordStatus(getDnsRecords(config), env, state);\n if (dnsRows.length > 0) {\n console.log(\"DNS records:\");\n for (const r of dnsRows) {\n const id = r.recordId ? ` [${r.recordId}]` : \"\";\n console.log(` ${r.logicalName}: ${r.type} ${r.name}${id} [${r.status}]`);\n }\n console.log();\n }\n\n let logpushLive:\n | Awaited<ReturnType<CFApiClient[\"logpushAccountJobsList\"]>>\n | undefined;\n if (env !== \"local\") {\n try {\n logpushLive = await api.logpushAccountJobsList();\n } catch {\n // Token may lack Logpush list; state-only rows still print.\n }\n }\n const logpushRows = logpushJobStatus(\n getLogpushJobs(config),\n config.tenant,\n env,\n state,\n logpushLive,\n );\n if (logpushRows.length > 0) {\n console.log(\"Logpush jobs:\");\n for (const r of logpushRows) {\n const id = r.cfJobId != null ? ` [id ${r.cfJobId}]` : \"\";\n const hints: string[] = [];\n if (r.cfEnabled === false) hints.push(\"disabled on Cloudflare\");\n if (r.cfError) hints.push(`CF error: ${r.cfError}`);\n const hint = hints.length > 0 ? ` — ${hints.join(\"; \")}` : \"\";\n console.log(` ${r.logicalName}: ${r.jobName}${id} [${r.status}]${hint}`);\n }\n console.log();\n }\n\n for (const [workerKey, workerConfig] of workers) {\n console.log(`Worker: ${workerKey}`);\n const deployedName = resolveDeployedWorkerName(\n config,\n workerKey,\n workerConfig,\n env,\n naming,\n );\n const mergedWorker = mergeWorkerConfigForResourcePick(\n config,\n workerKey,\n workerConfig,\n env,\n accountId,\n naming,\n state,\n { referencesMode: \"tolerant\", imports: siblingImports },\n );\n let printedAny = false;\n for (const mod of resourceModules) {\n const resources = mod.pickResources(mergedWorker);\n if (resources.length === 0) continue;\n const rows = mod.status({\n resources,\n env,\n state,\n naming,\n worker: { workerKey, deployedName },\n });\n if (rows.length === 0) continue;\n printedAny = true;\n console.log(` ${mod.label}:`);\n for (const r of rows) {\n console.log(` ${r.binding}: ${r.name} [${r.status}]`);\n }\n }\n if (!printedAny) console.log(\" (no resources)\");\n console.log();\n }\n}\n"],"mappings":";;;;;;;;;AAKA,SAAgB,wBACd,WACA,MACA,OACA,SAC2E;CAC3E,MAAMA,UAID,EAAE;AAE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,EAAG;GAC5B,MAAM,OAAO,IAAI,OAAO;IACtB;IACA;IACA;IACA;IACA,QAAQ;KAAE;KAAW;KAAc;IACpC,CAAC;AACF,OAAI,KAAK,WAAW,EAAG;AACvB,gBAAa;AACb,WAAQ,IAAI,KAAK,IAAI,MAAM,GAAG;AAC9B,QAAK,MAAM,KAAK,KACd,SAAQ,IAAI,OAAO,EAAE,QAAQ,IAAI,EAAE,KAAK,IAAI,EAAE,OAAO,GAAG;;AAG5D,MAAI,CAAC,WAAY,SAAQ,IAAI,mBAAmB;AAChD,UAAQ,KAAK"}
@@ -1,10 +1,10 @@
1
1
  import { f as getDispatchNamespaces, m as getLogpushJobs, p as getDnsRecords } from "./normalize-DVSTRZhO.mjs";
2
- import { B as getWorkers, C as stackNameForConfig, L as CFApiClient, P as namingFromConfig, R as cloudflareAccountIdFromEnv, T as mergeWorkerConfigForResourcePick, V as loadConfig, d as fetchStackImports, m as StateManager } from "./tamer.mjs";
2
+ import { B as getWorkers, E as mergeWorkerConfigForResourcePick, L as CFApiClient, R as cloudflareAccountIdFromEnv, V as loadConfig, f as fetchStackImports, h as StateManager, u as namingFromConfig, w as stackNameForConfig } from "./tamer.mjs";
3
3
  import { n as resourceModules } from "./registry-EWWdkLf7.mjs";
4
4
  import "./r2S3EmptyBucket-B9_pHfvB.mjs";
5
- import { n as dispatchNamespaceSync, t as dnsRecordSync } from "./dns-records.sync-DqYROe07.mjs";
5
+ import { n as dispatchNamespaceSync, t as dnsRecordSync } from "./dns-records.sync-Ck0Q2OK3.mjs";
6
6
  import { i as logpushJobSync } from "./logpush-job-DJPlpnRu.mjs";
7
- import { i as workerRouteSync } from "./worker-route-x8q3K4-z.mjs";
7
+ import { i as workerRouteSync } from "./worker-route-tOqVbhv3.mjs";
8
8
 
9
9
  //#region src/cli/commands/sync.ts
10
10
  async function runSync(options) {
@@ -85,4 +85,4 @@ async function runSync(options) {
85
85
 
86
86
  //#endregion
87
87
  export { runSync };
88
- //# sourceMappingURL=sync-CpfxqlOx.mjs.map
88
+ //# sourceMappingURL=sync-KTzMVc_o.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"sync-CpfxqlOx.mjs","names":[],"sources":["../src/cli/commands/sync.ts"],"sourcesContent":["import { loadConfig, getWorkers } from \"../../core/config/loader.js\";\nimport { cloudflareAccountIdFromEnv } from \"../../core/cloudflareEnv.js\";\nimport { namingFromConfig } from \"../../core/config/namingFromConfig.js\";\nimport { StateManager } from \"../../core/state/StateManager.js\";\nimport { stackNameForConfig } from \"../../core/state/stackName.js\";\nimport { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { dispatchNamespaceSync } from \"../../features/dispatch-namespace/index.js\";\nimport { dnsRecordSync } from \"../../features/dns-records/index.js\";\nimport { getDispatchNamespaces, getDnsRecords, getLogpushJobs } from \"../../types.js\";\nimport { logpushJobSync } from \"../../features/logpush-job/index.js\";\nimport { workerRouteSync } from \"../../features/worker-route/index.js\";\nimport { resourceModules } from \"../../core/registry/registry.js\";\nimport { fetchStackImports } from \"../../core/imports/fetchStackImports.js\";\nimport { mergeWorkerConfigForResourcePick } from \"../../core/config/resolver.js\";\n\nexport async function runSync(options: {\n env?: string;\n configPath?: string;\n}): Promise<void> {\n const env = options.env ?? \"local\";\n const configPath = options.configPath;\n const baseDir = process.cwd();\n\n const config = await loadConfig(configPath, { env });\n const accountId =\n config.account_id ?? cloudflareAccountIdFromEnv();\n if (!accountId) {\n throw new Error(\n \"account_id required in config or CLOUDFLARE_ACCOUNT_ID env var\",\n );\n }\n\n const api = new CFApiClient(accountId);\n const naming = namingFromConfig(config);\n const state = new StateManager(\n config.tenant.id,\n env,\n stackNameForConfig(config),\n );\n await state.hydrate(api);\n // Tolerant pre-fetch: sync runs against existing cloud state, so we\n // pass real import values into worker-route resolution to avoid\n // matching against `${tamer:import:…}` placeholders.\n const imports = await fetchStackImports(api, config, env).catch((err) => {\n const msg = err instanceof Error ? err.message : String(err);\n console.warn(`[sync] skipping cross-stack imports: ${msg}`);\n return {} as Record<string, Record<string, string>>;\n });\n\n async function safeList<T>(\n label: string,\n fn: () => Promise<T[]>,\n ): Promise<T[]> {\n try {\n return await fn();\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n console.warn(`[sync] skipping ${label}: ${msg}`);\n return [];\n }\n }\n\n const lists = await Promise.all(\n resourceModules.map((m) =>\n safeList(`${m.label} list`, () => m.fetchAll(api)),\n ),\n );\n\n if (getDispatchNamespaces(config).length > 0) {\n try {\n await dispatchNamespaceSync(\n getDispatchNamespaces(config),\n config.tenant,\n env,\n api,\n state,\n );\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n console.warn(`[sync] skipping dispatch namespaces: ${msg}`);\n }\n }\n\n if (getDnsRecords(config).length > 0) {\n try {\n await dnsRecordSync(\n getDnsRecords(config),\n config.tenant,\n env,\n api,\n state,\n );\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n console.warn(`[sync] skipping dns records: ${msg}`);\n }\n }\n\n if (getLogpushJobs(config).length > 0 && env !== \"local\") {\n try {\n await logpushJobSync(\n getLogpushJobs(config),\n config.tenant,\n env,\n api,\n state,\n );\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n console.warn(`[sync] skipping logpush jobs: ${msg}`);\n }\n }\n\n const workers = await getWorkers(config, baseDir);\n for (const [workerKey, workerConfig] of workers) {\n const mergedWorker = mergeWorkerConfigForResourcePick(\n config,\n workerKey,\n workerConfig,\n env,\n accountId,\n naming,\n state,\n { referencesMode: \"tolerant\", imports },\n );\n resourceModules.forEach((mod, i) => {\n const resources = mod.pickResources(mergedWorker);\n if (resources.length === 0) return;\n mod.sync({\n resources,\n all: lists[i],\n tenant: config.tenant,\n env,\n api,\n state,\n naming,\n config,\n baseDir,\n });\n });\n }\n\n try {\n await workerRouteSync(env, config, baseDir, accountId, naming, state, api, {\n imports,\n });\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n console.warn(`[sync] skipping worker routes: ${msg}`);\n }\n\n await state.pers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CAAC,SAAS,EACjC,KAAI;AACF,QAAM,cACJ,cAAc,OAAO,EACrB,OAAO,QACP,KACA,KACA,MACD;UACM,KAAK;EACZ,MAAM,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI;AAC5D,UAAQ,KAAK,gCAAgC,MAAM;;AAIvD,KAAI,eAAe,OAAO,CAAC,SAAS,KAAK,QAAQ,QAC/C,KAAI;AACF,QAAM,eACJ,eAAe,OAAO,EACtB,OAAO,QACP,KACA,KACA,MACD;UACM,KAAK;EACZ,MAAM,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI;AAC5D,UAAQ,KAAK,iCAAiC,MAAM;;CAIxD,MAAM,UAAU,MAAM,WAAW,QAAQ,QAAQ;AACjD,MAAK,MAAM,CAAC,WAAW,iBAAiB,SAAS;EAC/C,MAAM,eAAe,iCACnB,QACA,WACA,cACA,KACA,WACA,QACA,OACA;GAAE,gBAAgB;GAAY;GAAS,CACxC;AACD,kBAAgB,SAAS,KAAK,MAAM;GAClC,MAAM,YAAY,IAAI,cAAc,aAAa;AACjD,OAAI,UAAU,WAAW,EAAG;AAC5B,OAAI,KAAK;IACP;IACA,KAAK,MAAM;IACX,QAAQ,OAAO;IACf;IACA;IACA;IACA;IACA;IACA;IACD,CAAC;IACF;;AAGJ,KAAI;AACF,QAAM,gBAAgB,KAAK,QAAQ,SAAS,WAAW,QAAQ,OAAO,KAAK,EACzE,SACD,CAAC;UACK,KAAK;EACZ,MAAM,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI;AAC5D,UAAQ,KAAK,kCAAkC,MAAM;;AAGvD,OAAM,MAAM,QAAQ,IAAI;AACxB,SAAQ,IAAI,yBAAyB,MAAM"}
1
+ {"version":3,"file":"sync-KTzMVc_o.mjs","names":[],"sources":["../src/cli/commands/sync.ts"],"sourcesContent":["import { loadConfig, getWorkers } from \"../../core/config/loader.js\";\nimport { cloudflareAccountIdFromEnv } from \"../../core/cloudflareEnv.js\";\nimport { namingFromConfig } from \"../../core/config/namingFromConfig.js\";\nimport { StateManager } from \"../../core/state/StateManager.js\";\nimport { stackNameForConfig } from \"../../core/state/stackName.js\";\nimport { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { dispatchNamespaceSync } from \"../../features/dispatch-namespace/index.js\";\nimport { dnsRecordSync } from \"../../features/dns-records/index.js\";\nimport { getDispatchNamespaces, getDnsRecords, getLogpushJobs } from \"../../types.js\";\nimport { logpushJobSync } from \"../../features/logpush-job/index.js\";\nimport { workerRouteSync } from \"../../features/worker-route/index.js\";\nimport { resourceModules } from \"../../core/registry/registry.js\";\nimport { fetchStackImports } from \"../../core/imports/fetchStackImports.js\";\nimport { mergeWorkerConfigForResourcePick } from \"../../core/config/resolver.js\";\n\nexport async function runSync(options: {\n env?: string;\n configPath?: string;\n}): Promise<void> {\n const env = options.env ?? \"local\";\n const configPath = options.configPath;\n const baseDir = process.cwd();\n\n const config = await loadConfig(configPath, { env });\n const accountId =\n config.account_id ?? cloudflareAccountIdFromEnv();\n if (!accountId) {\n throw new Error(\n \"account_id required in config or CLOUDFLARE_ACCOUNT_ID env var\",\n );\n }\n\n const api = new CFApiClient(accountId);\n const naming = namingFromConfig(config);\n const state = new StateManager(\n config.tenant.id,\n env,\n stackNameForConfig(config),\n );\n await state.hydrate(api);\n // Tolerant pre-fetch: sync runs against existing cloud state, so we\n // pass real import values into worker-route resolution to avoid\n // matching against `${tamer:import:…}` placeholders.\n const imports = await fetchStackImports(api, config, env).catch((err) => {\n const msg = err instanceof Error ? err.message : String(err);\n console.warn(`[sync] skipping cross-stack imports: ${msg}`);\n return {} as Record<string, Record<string, string>>;\n });\n\n async function safeList<T>(\n label: string,\n fn: () => Promise<T[]>,\n ): Promise<T[]> {\n try {\n return await fn();\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n console.warn(`[sync] skipping ${label}: ${msg}`);\n return [];\n }\n }\n\n const lists = await Promise.all(\n resourceModules.map((m) =>\n safeList(`${m.label} list`, () => m.fetchAll(api)),\n ),\n );\n\n if (getDispatchNamespaces(config).length > 0) {\n try {\n await dispatchNamespaceSync(\n getDispatchNamespaces(config),\n config.tenant,\n env,\n api,\n state,\n );\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n console.warn(`[sync] skipping dispatch namespaces: ${msg}`);\n }\n }\n\n if (getDnsRecords(config).length > 0) {\n try {\n await dnsRecordSync(\n getDnsRecords(config),\n config.tenant,\n env,\n api,\n state,\n );\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n console.warn(`[sync] skipping dns records: ${msg}`);\n }\n }\n\n if (getLogpushJobs(config).length > 0 && env !== \"local\") {\n try {\n await logpushJobSync(\n getLogpushJobs(config),\n config.tenant,\n env,\n api,\n state,\n );\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n console.warn(`[sync] skipping logpush jobs: ${msg}`);\n }\n }\n\n const workers = await getWorkers(config, baseDir);\n for (const [workerKey, workerConfig] of workers) {\n const mergedWorker = mergeWorkerConfigForResourcePick(\n config,\n workerKey,\n workerConfig,\n env,\n accountId,\n naming,\n state,\n { referencesMode: \"tolerant\", imports },\n );\n resourceModules.forEach((mod, i) => {\n const resources = mod.pickResources(mergedWorker);\n if (resources.length === 0) return;\n mod.sync({\n resources,\n all: lists[i],\n tenant: config.tenant,\n env,\n api,\n state,\n naming,\n config,\n baseDir,\n });\n });\n }\n\n try {\n await workerRouteSync(env, config, baseDir, accountId, naming, state, api, {\n imports,\n });\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n console.warn(`[sync] skipping worker routes: ${msg}`);\n }\n\n await state.persist(api);\n console.log(`Synced state for env: ${env}`);\n}\n"],"mappings":";;;;;;;;;AAeA,eAAsB,QAAQ,SAGZ;CAChB,MAAM,MAAM,QAAQ,OAAO;CAC3B,MAAM,aAAa,QAAQ;CAC3B,MAAM,UAAU,QAAQ,KAAK;CAE7B,MAAM,SAAS,MAAM,WAAW,YAAY,EAAE,KAAK,CAAC;CACpD,MAAM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