@m-kopa/launchpad-cli 0.68.0 → 0.70.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -19,7 +19,7 @@ var __toESM = (mod, isNodeMode, target) => {
19
19
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
20
20
 
21
21
  // src/version.ts
22
- var CLI_VERSION = "0.68.0";
22
+ var CLI_VERSION = "0.70.0";
23
23
 
24
24
  // src/config.ts
25
25
  import { readFileSync } from "node:fs";
@@ -3345,6 +3345,7 @@ var EnvVarSchema = z3.discriminatedUnion("type", [
3345
3345
  z3.object({ type: z3.literal("secret_text"), secret_ref: z3.string().min(1) }).strict(),
3346
3346
  z3.object({ type: z3.literal("plain_text"), value: z3.string() }).strict()
3347
3347
  ]);
3348
+ var MIGRATION_STAGES = ["staged", "flipped"];
3348
3349
  var SpecSchema = z3.object({
3349
3350
  appType: z3.enum(APP_TYPES2),
3350
3351
  display: z3.object({
@@ -3374,6 +3375,7 @@ var SpecSchema = z3.object({
3374
3375
  containers: z3.array(ContainerSchema).min(1).optional(),
3375
3376
  secrets: SecretsSchema.optional(),
3376
3377
  fronted_by_concierge: z3.boolean().optional(),
3378
+ migration: z3.object({ stage: z3.enum(MIGRATION_STAGES) }).strict().optional(),
3377
3379
  bindings: z3.object({
3378
3380
  d1: z3.string().min(1).max(64).regex(ENV_NAME_REGEX, "bindings.d1 must be an UPPER_SNAKE_CASE binding name").optional()
3379
3381
  }).strict().optional()
@@ -3438,7 +3440,7 @@ var SpecSchema = z3.object({
3438
3440
  message: "origin: dispatch requires an explicit auth: gateway (auth defaults to 'access' when omitted). A dispatch-namespace Worker has no public hostname for Cloudflare Access to gate, so the gateway must be the sole gate."
3439
3441
  });
3440
3442
  }
3441
- if (s.confine_origin !== undefined) {
3443
+ if (s.confine_origin !== undefined && s.migration === undefined) {
3442
3444
  ctx.addIssue({
3443
3445
  code: z3.ZodIssueCode.custom,
3444
3446
  path: ["confine_origin"],
@@ -3446,6 +3448,22 @@ var SpecSchema = z3.object({
3446
3448
  });
3447
3449
  }
3448
3450
  }
3451
+ if (s.migration !== undefined) {
3452
+ if (s.origin !== "dispatch") {
3453
+ ctx.addIssue({
3454
+ code: z3.ZodIssueCode.custom,
3455
+ path: ["migration"],
3456
+ message: "migration is only valid with origin: dispatch; the portal-bot writes it while moving a live app."
3457
+ });
3458
+ }
3459
+ if (s.appType !== "static" && s.appType !== "react" && s.appType !== "react+api") {
3460
+ ctx.addIssue({
3461
+ code: z3.ZodIssueCode.custom,
3462
+ path: ["migration"],
3463
+ message: `migration is only valid for static, react and react+api apps (current appType: '${s.appType}')`
3464
+ });
3465
+ }
3466
+ }
3449
3467
  if (s.bindings?.d1 !== undefined) {
3450
3468
  if (s.origin !== "dispatch") {
3451
3469
  ctx.addIssue({
@@ -4894,6 +4912,155 @@ function newAppOrigin(appType, requested) {
4894
4912
  return;
4895
4913
  return requested ?? "dispatch";
4896
4914
  }
4915
+ // ../launchpad-engine/dist/dispatch-functions.js
4916
+ function uncompiledFunctionsWarning(spec, paths) {
4917
+ if (spec.origin !== "dispatch" || spec.appType === "react+api" || spec.appType === "container")
4918
+ return null;
4919
+ const rootDir = spec.build?.root_dir;
4920
+ const root = (typeof rootDir === "string" ? rootDir : "").split("/").filter((part) => part !== "" && part !== ".");
4921
+ const dir = [...root, "functions"].join("/");
4922
+ if (!paths.some((p) => p.startsWith(`${dir}/`)))
4923
+ return null;
4924
+ return `warning: ${dir}/ will NOT be served. This is a ${spec.appType} app on Workers dispatch, and only react+api apps ` + `get their functions compiled, so every route under ${dir}/ returns 404. Running them needs ` + "`appType: react+api` with a package.json and lockfile at the build root. For an app that is already live, " + "that is a runtime change: ask the platform team with `launchpad feature` rather than flipping appType yourself. " + 'See the launchpad-identity skill, "Dispatch rules".';
4925
+ }
4926
+ // ../launchpad-engine/dist/migrate-dispatch.js
4927
+ var PLATFORM_ENV_NAMES = new Set([
4928
+ "GATEWAY_ISSUER",
4929
+ "GATEWAY_AUD",
4930
+ "GATEWAY_JWKS_URL",
4931
+ "CF_ACCESS_TEAM_DOMAIN",
4932
+ "CF_ACCESS_AUD",
4933
+ "JWKS_URL"
4934
+ ]);
4935
+ var PLATFORM_ENV_PREFIXES = ["GATEWAY_", "CF_ACCESS_"];
4936
+ function dispatchManifest(manifest, wrangler = {}) {
4937
+ const v2 = manifest.apiVersion === "launchpad.m-kopa.us/v2";
4938
+ const source = v2 ? manifest.spec : manifest;
4939
+ const appType = v2 ? manifest.spec.appType : manifest.deployment.type;
4940
+ if (appType === "container" || source.containers !== undefined) {
4941
+ throw new Error("Containers use their own runtime and cannot convert to dispatch.");
4942
+ }
4943
+ if (!v2)
4944
+ assertConvertibleV1(manifest);
4945
+ const d1 = d1Binding(v2 ? manifest.spec.bindings?.d1 : pagesTargetD1(manifest), wrangler.d1);
4946
+ const manifestEnv = v2 ? manifest.spec.env_vars : plainTextEnv(manifest.production_env);
4947
+ const plainEnv = withWranglerVars(manifestEnv, wrangler.vars ?? {}, d1);
4948
+ const envVars = { ...plainEnv, ...secretEnv(source.secrets, plainEnv) };
4949
+ const spec = v2 ? { ...manifest.spec, secrets: undefined } : {
4950
+ appType,
4951
+ display: {
4952
+ name: manifest.metadata.name,
4953
+ team: manifest.metadata.team,
4954
+ ...manifest.metadata.description === undefined ? {} : { description: manifest.metadata.description }
4955
+ },
4956
+ owner: { email: manifest.metadata.owner },
4957
+ access: {
4958
+ audience: manifest.access.audience,
4959
+ private_owner: manifest.access.private_owner,
4960
+ allowed_entra_groups: [...allowedEntraGroups(manifest.access)],
4961
+ identity_types: manifest.access.identity_types
4962
+ },
4963
+ build: manifest.build,
4964
+ app: manifest.app,
4965
+ verify: manifest.verify,
4966
+ sensitive: manifest.sensitive,
4967
+ catalogue: manifest.catalogue
4968
+ };
4969
+ const candidate = {
4970
+ apiVersion: "launchpad.m-kopa.us/v2",
4971
+ kind: "App",
4972
+ metadata: v2 ? manifest.metadata : { slug: manifest.metadata.name, schemaVersion: 2 },
4973
+ spec: {
4974
+ ...spec,
4975
+ ...d1 === undefined ? {} : { bindings: { d1 } },
4976
+ env_vars: Object.keys(envVars).length === 0 ? undefined : envVars,
4977
+ origin: "dispatch",
4978
+ auth: "gateway",
4979
+ confine_origin: undefined
4980
+ }
4981
+ };
4982
+ return parseV2OrThrow(candidate, "Cannot convert manifest");
4983
+ }
4984
+ function parseV2OrThrow(candidate, prefix) {
4985
+ const parsed = parseManifestV2(candidate);
4986
+ if (parsed.kind !== "ok") {
4987
+ throw new Error(`${prefix}: ${parsed.issues.map((issue) => `${issue.path}: ${issue.message}`).join("; ")}`);
4988
+ }
4989
+ return parsed.manifest;
4990
+ }
4991
+ function assertConvertibleV1(manifest) {
4992
+ const unsupported2 = [
4993
+ manifest.hostnames !== undefined && "hostnames",
4994
+ manifest.targets !== undefined && pagesTargetD1(manifest) === undefined && "targets",
4995
+ manifest.access.session_duration !== undefined && "access.session_duration",
4996
+ manifest.deployment.runtime !== undefined && "deployment.runtime"
4997
+ ].filter(Boolean);
4998
+ if (unsupported2.length > 0) {
4999
+ throw new Error(`Cannot preserve ${unsupported2.join(", ")} on dispatch. Review these settings with the platform team before migrating.`);
5000
+ }
5001
+ }
5002
+ function d1Binding(declared, wranglerD1) {
5003
+ if (declared !== undefined && wranglerD1 !== undefined && declared !== wranglerD1) {
5004
+ throw new Error(`The manifest binds D1 as ${declared} but the wrangler config binds ${wranglerD1}. Use one name for both.`);
5005
+ }
5006
+ return declared ?? wranglerD1;
5007
+ }
5008
+ function withWranglerVars(env, vars, d1) {
5009
+ const entries = Object.entries(vars);
5010
+ if (entries.length === 0)
5011
+ return env;
5012
+ const out = { ...env };
5013
+ for (const [name, value] of entries) {
5014
+ if (isPlatformEnvName(name)) {
5015
+ throw new Error(`The wrangler var ${name} is set by the platform on dispatch apps. Rename it before converting.`);
5016
+ }
5017
+ if (/_(TOKEN|SECRET)$/.test(name)) {
5018
+ throw new Error(`The wrangler var ${name} is named like a secret. Declare it as an \`env-file\` secret in launchpad.yaml and remove it from the wrangler vars.`);
5019
+ }
5020
+ if (name === d1)
5021
+ throw new Error(`The wrangler var ${name} has the same name as the D1 binding. Rename one of them.`);
5022
+ const existing = out[name];
5023
+ if (existing !== undefined && !(existing.type === "plain_text" && existing.value === value)) {
5024
+ throw new Error(`The wrangler var ${name} differs from the ${name} environment variable in launchpad.yaml. Keep one value.`);
5025
+ }
5026
+ out[name] = { type: "plain_text", value };
5027
+ }
5028
+ return out;
5029
+ }
5030
+ function isPlatformEnvName(name) {
5031
+ return PLATFORM_ENV_NAMES.has(name) || PLATFORM_ENV_PREFIXES.some((prefix) => name.startsWith(prefix));
5032
+ }
5033
+ function plainTextEnv(env) {
5034
+ if (env === undefined)
5035
+ return;
5036
+ return Object.fromEntries(Object.entries(env).map(([name, value]) => [name, { type: "plain_text", value }]));
5037
+ }
5038
+ function secretEnv(secrets, env) {
5039
+ const out = {};
5040
+ for (const binding of secrets?.bindings ?? []) {
5041
+ const refusal = secretRefusal(binding, env);
5042
+ if (refusal !== undefined)
5043
+ throw new Error(`Secret ${binding.name} ${refusal}`);
5044
+ out[binding.name] = { type: "secret_text", secret_ref: binding.name };
5045
+ }
5046
+ return out;
5047
+ }
5048
+ function secretRefusal(binding, env) {
5049
+ const targets = binding.targets === undefined || binding.targets === "all" ? [] : binding.targets;
5050
+ const checks = [
5051
+ [binding.source !== "env-file", "is platform-managed and cannot be converted automatically. Ask the platform team to migrate it."],
5052
+ [targets.some((target) => target !== "primary"), "targets another surface, which dispatch does not have."],
5053
+ [PLATFORM_ENV_NAMES.has(binding.name), "is set by the platform on dispatch apps. Rename it before converting."],
5054
+ [env?.[binding.name] !== undefined, "is also declared as an environment variable. Keep one."]
5055
+ ];
5056
+ return checks.find(([refused]) => refused)?.[1];
5057
+ }
5058
+ function pagesTargetD1(manifest) {
5059
+ const [target, ...rest] = manifest.targets ?? [];
5060
+ if (rest.length > 0 || target?.kind !== "pages")
5061
+ return;
5062
+ return target.d1_binding;
5063
+ }
4897
5064
  // src/bundle/boundary.ts
4898
5065
  var MAX_CONTENT_PROBE_BYTES = 1024 * 1024;
4899
5066
  function applyBoundaryToFiles(args) {
@@ -4974,6 +5141,7 @@ ${lines}`
4974
5141
  }
4975
5142
 
4976
5143
  // src/bundle/orchestrate.ts
5144
+ import { parse as parseYaml3 } from "yaml";
4977
5145
  async function bundleAndDeploy(args) {
4978
5146
  const { cfg, cwd, slug, overrideStale, allowUnguarded = false } = args;
4979
5147
  const manifestPath = join7(cwd, "launchpad.yaml");
@@ -5003,6 +5171,9 @@ async function bundleAndDeploy(args) {
5003
5171
  return { kind: "boundary-error", message: boundary.message };
5004
5172
  }
5005
5173
  const bundleFiles = boundary.files;
5174
+ const functionsWarning = dispatchFunctionsWarning(manifestYaml, bundleFiles);
5175
+ if (functionsWarning !== null)
5176
+ args.onWarning?.(functionsWarning);
5006
5177
  let packResult;
5007
5178
  try {
5008
5179
  packResult = await packTarGz(cwd, bundleFiles);
@@ -5039,6 +5210,17 @@ async function bundleAndDeploy(args) {
5039
5210
  boundaryWarnings: boundary.warnings
5040
5211
  };
5041
5212
  }
5213
+ function dispatchFunctionsWarning(manifestYaml, files) {
5214
+ let raw;
5215
+ try {
5216
+ raw = parseYaml3(manifestYaml);
5217
+ } catch {
5218
+ return null;
5219
+ }
5220
+ if (raw?.apiVersion !== "launchpad.m-kopa.us/v2" || raw.spec === undefined)
5221
+ return null;
5222
+ return uncompiledFunctionsWarning(raw.spec, files);
5223
+ }
5042
5224
 
5043
5225
  // src/deploy/verify-deploy.ts
5044
5226
  import { readFileSync as readFileSync10, existsSync as existsSync4 } from "node:fs";
@@ -5073,6 +5255,13 @@ async function fetchStandingExceptions(cfg, slug, fetcher = fetch) {
5073
5255
  return null;
5074
5256
  return raw.exceptions.filter((e) => typeof e === "object" && e !== null && typeof e.path === "string" && typeof e.rule === "string" && typeof e.detectedAt === "string" && typeof e.deployRef === "string");
5075
5257
  }
5258
+ async function fetchDeploymentStatusBestEffort(cfg, slug) {
5259
+ try {
5260
+ return await fetchDeploymentStatus(cfg, slug);
5261
+ } catch {
5262
+ return null;
5263
+ }
5264
+ }
5076
5265
  async function fetchDeploymentStatus(cfg, slug, fetcher = fetch) {
5077
5266
  let raw;
5078
5267
  try {
@@ -5403,7 +5592,7 @@ async function fetchManifestState(cfg, slug, opts = {}, fetcher = fetch) {
5403
5592
  // src/commands/infer-slug.ts
5404
5593
  import * as path7 from "node:path";
5405
5594
  import { existsSync as existsSync3, readFileSync as readFileSync6 } from "node:fs";
5406
- import { parse as parseYaml3 } from "yaml";
5595
+ import { parse as parseYaml4 } from "yaml";
5407
5596
  var DIRNAME_RE = /^launchpad-app-([a-z0-9][a-z0-9-]*[a-z0-9])$/;
5408
5597
  function inferSlugFromCwd(cwd) {
5409
5598
  const base = path7.basename(cwd);
@@ -5425,7 +5614,7 @@ function inferSlugFromManifestFile(manifestPath) {
5425
5614
  if (!existsSync3(manifestPath))
5426
5615
  return null;
5427
5616
  try {
5428
- return resolveManifestSlug(parseYaml3(readFileSync6(manifestPath, "utf8")));
5617
+ return resolveManifestSlug(parseYaml4(readFileSync6(manifestPath, "utf8")));
5429
5618
  } catch {
5430
5619
  return null;
5431
5620
  }
@@ -6193,7 +6382,7 @@ still provisioning after the watch window — re-run \`launchpad watch ${slug}\`
6193
6382
 
6194
6383
  // src/manifest/load.ts
6195
6384
  import { readFileSync as readFileSync8 } from "node:fs";
6196
- import { parse as parseYaml4, YAMLParseError } from "yaml";
6385
+ import { parse as parseYaml5, YAMLParseError } from "yaml";
6197
6386
  function loadManifest(path8) {
6198
6387
  let raw;
6199
6388
  try {
@@ -6222,7 +6411,7 @@ function loadManifestAnyVersion(path8) {
6222
6411
  function parseManifestAnyVersion(yamlText, path8) {
6223
6412
  let parsed;
6224
6413
  try {
6225
- parsed = parseYaml4(yamlText);
6414
+ parsed = parseYaml5(yamlText);
6226
6415
  } catch (err) {
6227
6416
  const message = err instanceof YAMLParseError ? err.message : err.message ?? String(err);
6228
6417
  return { kind: "yaml-parse-error", path: path8, message };
@@ -6251,7 +6440,7 @@ function parseManifestAnyVersion(yamlText, path8) {
6251
6440
  function parseManifest2(yamlText, path8) {
6252
6441
  let parsed;
6253
6442
  try {
6254
- parsed = parseYaml4(yamlText);
6443
+ parsed = parseYaml5(yamlText);
6255
6444
  } catch (err) {
6256
6445
  const message = err instanceof YAMLParseError ? err.message : err.message ?? String(err);
6257
6446
  return { kind: "yaml-parse-error", path: path8, message };
@@ -6363,7 +6552,7 @@ async function runStatus(args, io) {
6363
6552
  };
6364
6553
  }
6365
6554
  }
6366
- emit4(output, parsed.json, io, lifecycle?.containerRedeploy);
6555
+ emit4(output, parsed.json, io, lifecycle?.containerRedeploy, lifecycle?.migration);
6367
6556
  return 0;
6368
6557
  }
6369
6558
  let localYaml = null;
@@ -6440,7 +6629,7 @@ async function runStatus(args, io) {
6440
6629
  }),
6441
6630
  ...lifecycle?.statusPageUrl !== undefined ? { statusPageUrl: lifecycle.statusPageUrl } : {}
6442
6631
  };
6443
- emit4(out, parsed.json, io, lifecycle?.containerRedeploy);
6632
+ emit4(out, parsed.json, io, lifecycle?.containerRedeploy, lifecycle?.migration);
6444
6633
  return 0;
6445
6634
  }
6446
6635
  if (local === null) {
@@ -6457,7 +6646,7 @@ async function runStatus(args, io) {
6457
6646
  }),
6458
6647
  ...lifecycle?.statusPageUrl !== undefined ? { statusPageUrl: lifecycle.statusPageUrl } : {}
6459
6648
  };
6460
- emit4(out, parsed.json, io, lifecycle?.containerRedeploy);
6649
+ emit4(out, parsed.json, io, lifecycle?.containerRedeploy, lifecycle?.migration);
6461
6650
  if (parsed.strict) {
6462
6651
  if (deployment?.liveDeployment?.buildStatus === "failure" || deployment?.v2?.state === "refused") {
6463
6652
  io.err(`launchpad status: --strict: live build FAILED ` + `(drift not evaluated — no local launchpad.yaml here).`);
@@ -6495,7 +6684,7 @@ async function runStatus(args, io) {
6495
6684
  ...standingExceptions !== null ? { standingExceptions } : {}
6496
6685
  })
6497
6686
  };
6498
- emit4(out, parsed.json, io, lifecycle?.containerRedeploy);
6687
+ emit4(out, parsed.json, io, lifecycle?.containerRedeploy, lifecycle?.migration);
6499
6688
  return 0;
6500
6689
  }
6501
6690
  const localGroups = await resolveStatusGroups({
@@ -6558,7 +6747,7 @@ async function runStatus(args, io) {
6558
6747
  ...groupIssues.length === 0 ? {} : { groupIssues },
6559
6748
  ...lifecycle?.statusPageUrl !== undefined ? { statusPageUrl: lifecycle.statusPageUrl } : {}
6560
6749
  };
6561
- emit4(result, parsed.json, io, lifecycle?.containerRedeploy);
6750
+ emit4(result, parsed.json, io, lifecycle?.containerRedeploy, lifecycle?.migration);
6562
6751
  if (parsed.strict && (result.state === "drift" || accessDrift?.inSync === false || groupIssues.length > 0)) {
6563
6752
  return 1;
6564
6753
  }
@@ -6813,12 +7002,25 @@ function containerRedeployLine(view) {
6813
7002
  }
6814
7003
  return `Container redeploy: ${view.state} (attempt ${view.attemptId})`;
6815
7004
  }
6816
- function emit4(base, asJson, io, containerRedeploy) {
6817
- const out = containerRedeploy === undefined ? base : { ...base, containerRedeploy };
7005
+ function withLifecycleExtras(base, containerRedeploy, migration) {
7006
+ return {
7007
+ ...base,
7008
+ ...containerRedeploy === undefined ? {} : { containerRedeploy },
7009
+ ...migration === undefined ? {} : { migration }
7010
+ };
7011
+ }
7012
+ function printMigrationLine(slug, migration, io) {
7013
+ if (migration === undefined)
7014
+ return;
7015
+ io.out(`Migration to Workers dispatch: ${migration.stage} (users served by ${migration.servingOrigin}). ` + `Details: launchpad migrate --status --slug ${slug}`);
7016
+ }
7017
+ function emit4(base, asJson, io, containerRedeploy, migration) {
7018
+ const out = withLifecycleExtras(base, containerRedeploy, migration);
6818
7019
  if (asJson) {
6819
7020
  io.out(JSON.stringify(out, null, 2));
6820
7021
  return;
6821
7022
  }
7023
+ printMigrationLine(out.slug, migration, io);
6822
7024
  if (out.statusPageUrl !== undefined) {
6823
7025
  io.out(`Status page: ${out.statusPageUrl}`);
6824
7026
  }
@@ -7462,7 +7664,7 @@ async function verifyFirstDeployServed(args, liveUrl, io, deps) {
7462
7664
  }
7463
7665
 
7464
7666
  // src/commands/deploy.ts
7465
- import { parse as parseYaml6 } from "yaml";
7667
+ import { parse as parseYaml7 } from "yaml";
7466
7668
  import { readFileSync as readFileSync12 } from "node:fs";
7467
7669
 
7468
7670
  // src/deploy/git-files.ts
@@ -7523,7 +7725,7 @@ function runGit2(sp, cwd, args) {
7523
7725
  }
7524
7726
 
7525
7727
  // src/deploy/manifest-diff.ts
7526
- import { parse as parseYaml5 } from "yaml";
7728
+ import { parse as parseYaml6 } from "yaml";
7527
7729
  var MASK = "«redacted»";
7528
7730
  var SECRET_KEY_SEGMENT = /(secret|token|api[_-]?key|access[_-]?key|private[_-]?key|secret[_-]?key|password|passwd|pwd|authorization|auth[_-]?token|bearer|client[_-]?secret|session|credential|value)/i;
7529
7731
  function isSecretPath(path8) {
@@ -7614,7 +7816,7 @@ function diffManifests(localYaml, deployedYaml) {
7614
7816
  let local;
7615
7817
  let deployed;
7616
7818
  try {
7617
- local = parseYaml5(localYaml);
7819
+ local = parseYaml6(localYaml);
7618
7820
  } catch (e) {
7619
7821
  return {
7620
7822
  inSync: false,
@@ -7623,7 +7825,7 @@ function diffManifests(localYaml, deployedYaml) {
7623
7825
  };
7624
7826
  }
7625
7827
  try {
7626
- deployed = parseYaml5(deployedYaml);
7828
+ deployed = parseYaml6(deployedYaml);
7627
7829
  } catch (e) {
7628
7830
  return {
7629
7831
  inSync: false,
@@ -9077,142 +9279,6 @@ import { closeSync, existsSync as existsSync7, lstatSync as lstatSync4, mkdirSyn
9077
9279
  import path8 from "node:path";
9078
9280
  import { stringify } from "yaml";
9079
9281
 
9080
- // src/manifest/migrate-dispatch.ts
9081
- var PLATFORM_ENV_NAMES = new Set([
9082
- "GATEWAY_ISSUER",
9083
- "GATEWAY_AUD",
9084
- "GATEWAY_JWKS_URL",
9085
- "CF_ACCESS_TEAM_DOMAIN",
9086
- "CF_ACCESS_AUD",
9087
- "JWKS_URL"
9088
- ]);
9089
- var PLATFORM_ENV_PREFIXES = ["GATEWAY_", "CF_ACCESS_"];
9090
- function dispatchManifest(manifest, wrangler = {}) {
9091
- const v2 = manifest.apiVersion === "launchpad.m-kopa.us/v2";
9092
- const source = v2 ? manifest.spec : manifest;
9093
- const appType = v2 ? manifest.spec.appType : manifest.deployment.type;
9094
- if (appType === "container" || source.containers !== undefined) {
9095
- throw new Error("Containers use their own runtime and cannot convert to dispatch.");
9096
- }
9097
- if (!v2)
9098
- assertConvertibleV1(manifest);
9099
- const d1 = d1Binding(v2 ? manifest.spec.bindings?.d1 : pagesTargetD1(manifest), wrangler.d1);
9100
- const manifestEnv = v2 ? manifest.spec.env_vars : plainTextEnv(manifest.production_env);
9101
- const plainEnv = withWranglerVars(manifestEnv, wrangler.vars ?? {}, d1);
9102
- const envVars = { ...plainEnv, ...secretEnv(source.secrets, plainEnv) };
9103
- const spec = v2 ? { ...manifest.spec, secrets: undefined } : {
9104
- appType,
9105
- display: {
9106
- name: manifest.metadata.name,
9107
- team: manifest.metadata.team,
9108
- ...manifest.metadata.description === undefined ? {} : { description: manifest.metadata.description }
9109
- },
9110
- owner: { email: manifest.metadata.owner },
9111
- access: {
9112
- audience: manifest.access.audience,
9113
- private_owner: manifest.access.private_owner,
9114
- allowed_entra_groups: [...allowedEntraGroups(manifest.access)],
9115
- identity_types: manifest.access.identity_types
9116
- },
9117
- build: manifest.build,
9118
- app: manifest.app,
9119
- verify: manifest.verify,
9120
- sensitive: manifest.sensitive,
9121
- catalogue: manifest.catalogue
9122
- };
9123
- const candidate = {
9124
- apiVersion: "launchpad.m-kopa.us/v2",
9125
- kind: "App",
9126
- metadata: v2 ? manifest.metadata : { slug: manifest.metadata.name, schemaVersion: 2 },
9127
- spec: {
9128
- ...spec,
9129
- ...d1 === undefined ? {} : { bindings: { d1 } },
9130
- env_vars: Object.keys(envVars).length === 0 ? undefined : envVars,
9131
- origin: "dispatch",
9132
- auth: "gateway",
9133
- confine_origin: undefined
9134
- }
9135
- };
9136
- const parsed = parseManifestV2(candidate);
9137
- if (parsed.kind !== "ok") {
9138
- throw new Error(`Cannot convert manifest: ${parsed.issues.map((issue) => `${issue.path}: ${issue.message}`).join("; ")}`);
9139
- }
9140
- return parsed.manifest;
9141
- }
9142
- function assertConvertibleV1(manifest) {
9143
- const unsupported2 = [
9144
- manifest.hostnames !== undefined && "hostnames",
9145
- manifest.targets !== undefined && pagesTargetD1(manifest) === undefined && "targets",
9146
- manifest.access.session_duration !== undefined && "access.session_duration",
9147
- manifest.deployment.runtime !== undefined && "deployment.runtime"
9148
- ].filter(Boolean);
9149
- if (unsupported2.length > 0) {
9150
- throw new Error(`Cannot preserve ${unsupported2.join(", ")} on dispatch. Review these settings with the platform team before migrating.`);
9151
- }
9152
- }
9153
- function d1Binding(declared, wranglerD1) {
9154
- if (declared !== undefined && wranglerD1 !== undefined && declared !== wranglerD1) {
9155
- throw new Error(`The manifest binds D1 as ${declared} but the wrangler config binds ${wranglerD1}. Use one name for both.`);
9156
- }
9157
- return declared ?? wranglerD1;
9158
- }
9159
- function withWranglerVars(env, vars, d1) {
9160
- const entries = Object.entries(vars);
9161
- if (entries.length === 0)
9162
- return env;
9163
- const out = { ...env };
9164
- for (const [name, value] of entries) {
9165
- if (isPlatformEnvName(name)) {
9166
- throw new Error(`The wrangler var ${name} is set by the platform on dispatch apps. Rename it before converting.`);
9167
- }
9168
- if (/_(TOKEN|SECRET)$/.test(name)) {
9169
- throw new Error(`The wrangler var ${name} is named like a secret. Declare it as an \`env-file\` secret in launchpad.yaml and remove it from the wrangler vars.`);
9170
- }
9171
- if (name === d1)
9172
- throw new Error(`The wrangler var ${name} has the same name as the D1 binding. Rename one of them.`);
9173
- const existing = out[name];
9174
- if (existing !== undefined && !(existing.type === "plain_text" && existing.value === value)) {
9175
- throw new Error(`The wrangler var ${name} differs from the ${name} environment variable in launchpad.yaml. Keep one value.`);
9176
- }
9177
- out[name] = { type: "plain_text", value };
9178
- }
9179
- return out;
9180
- }
9181
- function isPlatformEnvName(name) {
9182
- return PLATFORM_ENV_NAMES.has(name) || PLATFORM_ENV_PREFIXES.some((prefix) => name.startsWith(prefix));
9183
- }
9184
- function plainTextEnv(env) {
9185
- if (env === undefined)
9186
- return;
9187
- return Object.fromEntries(Object.entries(env).map(([name, value]) => [name, { type: "plain_text", value }]));
9188
- }
9189
- function secretEnv(secrets, env) {
9190
- const out = {};
9191
- for (const binding of secrets?.bindings ?? []) {
9192
- const refusal = secretRefusal(binding, env);
9193
- if (refusal !== undefined)
9194
- throw new Error(`Secret ${binding.name} ${refusal}`);
9195
- out[binding.name] = { type: "secret_text", secret_ref: binding.name };
9196
- }
9197
- return out;
9198
- }
9199
- function secretRefusal(binding, env) {
9200
- const targets = binding.targets === undefined || binding.targets === "all" ? [] : binding.targets;
9201
- const checks = [
9202
- [binding.source !== "env-file", "is platform-managed and cannot be converted automatically. Ask the platform team to migrate it."],
9203
- [targets.some((target) => target !== "primary"), "targets another surface, which dispatch does not have."],
9204
- [PLATFORM_ENV_NAMES.has(binding.name), "is set by the platform on dispatch apps. Rename it before converting."],
9205
- [env?.[binding.name] !== undefined, "is also declared as an environment variable. Keep one."]
9206
- ];
9207
- return checks.find(([refused]) => refused)?.[1];
9208
- }
9209
- function pagesTargetD1(manifest) {
9210
- const [target, ...rest] = manifest.targets ?? [];
9211
- if (rest.length > 0 || target?.kind !== "pages")
9212
- return;
9213
- return target.d1_binding;
9214
- }
9215
-
9216
9282
  // src/manifest/wrangler-config.ts
9217
9283
  var ALLOWED_KEYS = new Set([
9218
9284
  "name",
@@ -9441,34 +9507,183 @@ function stringEnd(text, start) {
9441
9507
  return text.length;
9442
9508
  }
9443
9509
 
9510
+ // src/commands/migrate-live.ts
9511
+ var WARNINGS = {
9512
+ rollback: "Rolling back serves the app's last Pages build again. Any D1 writes or schema changes made since staging stay as they are.",
9513
+ finalize: "Finalizing deletes the Pages project. Rolling back after this needs a free Pages slot and a rebuild, and every secret has to be pushed again."
9514
+ };
9515
+ async function runLiveMigration(slug, action, options, io) {
9516
+ const warning = WARNINGS[action];
9517
+ if (warning !== undefined && !options.json)
9518
+ io.err(`note: ${warning}`);
9519
+ let res;
9520
+ try {
9521
+ res = await apiRaw(loadConfig(), {
9522
+ method: action === "status" ? "GET" : "POST",
9523
+ path: `/apps/${encodeURIComponent(slug)}/migration`,
9524
+ ...action === "status" ? {} : { jsonBody: { action, ...options.consent === undefined ? {} : { consent: options.consent } } },
9525
+ nonThrowingStatuses: [400, 409, 500, 502, 503]
9526
+ });
9527
+ } catch (error) {
9528
+ if (error instanceof ForbiddenError || error instanceof NotFoundError) {
9529
+ io.err(`launchpad migrate: ${error.message}`);
9530
+ return 1;
9531
+ }
9532
+ throw error;
9533
+ }
9534
+ const body = await res.json().catch(() => ({})) ?? {};
9535
+ if (options.json) {
9536
+ io.out(JSON.stringify({ httpStatus: res.status, ...body }, null, 2));
9537
+ return exitFor(action, res.status, body);
9538
+ }
9539
+ render(slug, action, res.status, body, io);
9540
+ return exitFor(action, res.status, body);
9541
+ }
9542
+ function exitFor(action, status, body) {
9543
+ if (action === "check")
9544
+ return status === 200 && body.eligible === true ? 0 : 1;
9545
+ return status === 200 || status === 202 ? 0 : 1;
9546
+ }
9547
+ function render(slug, action, status, body, io) {
9548
+ const refusals = Array.isArray(body.refusals) ? body.refusals : [];
9549
+ if (action === "check")
9550
+ renderCheck(slug, body, refusals, io);
9551
+ else if (status === 200 || status === 202)
9552
+ renderAccepted(slug, action, body, io);
9553
+ else
9554
+ renderRefused(status, body, refusals, io);
9555
+ }
9556
+ function renderCheck(slug, body, refusals, io) {
9557
+ if (body.eligible === true) {
9558
+ io.out(`${slug}: eligible to move to Workers dispatch. Nothing was changed.`);
9559
+ io.out("Run `launchpad migrate --origin dispatch` to stage it. Users stay on Pages until you flip.");
9560
+ } else {
9561
+ io.out(`${slug}: not eligible to move yet.`);
9562
+ for (const refusal of refusals)
9563
+ io.out(` ${refusal.code}: ${refusal.message}`);
9564
+ }
9565
+ renderLedger(body.migration, io);
9566
+ }
9567
+ function renderAccepted(slug, action, body, io) {
9568
+ if (typeof body.commitSha === "string") {
9569
+ io.out(`${slug}: ${action} committed ${body.commitSha.slice(0, 12)}.`);
9570
+ if (typeof body.prUrl === "string")
9571
+ io.out(`Terraform: ${body.prUrl}`);
9572
+ if (body.reconcile === "pending")
9573
+ io.out("The Terraform change is queued; the platform finishes it automatically.");
9574
+ io.out("Run `launchpad pull` so your local launchpad.yaml matches before your next deploy.");
9575
+ }
9576
+ if (body.migration === null) {
9577
+ io.out(`${slug}: no migration has started. Run \`launchpad migrate --origin dispatch --dry-run\`.`);
9578
+ return;
9579
+ }
9580
+ renderLedger(body.migration, io);
9581
+ }
9582
+ function renderRefused(status, body, refusals, io) {
9583
+ io.err(`launchpad migrate: ${typeof body.message === "string" ? body.message : `the bot answered ${status}`}`);
9584
+ if (refusals.length > 1)
9585
+ for (const refusal of refusals)
9586
+ io.err(` ${refusal.code}: ${refusal.message}`);
9587
+ }
9588
+ function renderLedger(ledger, io) {
9589
+ if (ledger === null || ledger === undefined)
9590
+ return;
9591
+ io.out(`Migration stage: ${ledger.stage}`);
9592
+ if (ledger.delivery !== null && ledger.delivery !== undefined) {
9593
+ io.out(`Dispatch delivery: ${ledger.delivery.state}${ledger.delivery.reason === null ? "" : ` (${ledger.delivery.reason})`}`);
9594
+ if (ledger.delivery.runUrl !== null)
9595
+ io.out(`Build: ${ledger.delivery.runUrl}`);
9596
+ }
9597
+ if (typeof ledger.next === "string")
9598
+ io.out(`Next: ${ledger.next}`);
9599
+ }
9600
+
9444
9601
  // src/commands/migrate.ts
9445
- var USAGE = "usage: launchpad migrate --origin dispatch [--dry-run]";
9602
+ var USAGE = [
9603
+ "usage: launchpad migrate --origin dispatch [--dry-run] [--consent <text>]",
9604
+ " launchpad migrate --status | --flip | --finalize | --rollback [--slug <slug>] [--consent <text>] [--json]"
9605
+ ].join(`
9606
+ `);
9446
9607
  var migrateCommand = {
9447
9608
  name: "migrate",
9448
- summary: "convert an unprovisioned static, React or React API app to Workers dispatch",
9609
+ summary: "move an app to Workers dispatch (unprovisioned: local YAML; live: staged, flipped, finalized)",
9449
9610
  run: runMigrate
9450
9611
  };
9612
+ var LIVE_FLAGS = {
9613
+ "--status": "status",
9614
+ "--flip": "flip",
9615
+ "--finalize": "finalize",
9616
+ "--rollback": "rollback"
9617
+ };
9618
+ function parseMigrateArgs(args) {
9619
+ const seen = new Set;
9620
+ const live = [];
9621
+ let consent;
9622
+ let slug;
9623
+ for (let i = 0;i < args.length; i++) {
9624
+ const arg = args[i];
9625
+ const action = LIVE_FLAGS[arg];
9626
+ if (action !== undefined)
9627
+ live.push(action);
9628
+ else if (arg === "--origin" && args[i + 1] === "dispatch")
9629
+ seen.add(args[i++]);
9630
+ else if (arg === "--consent" && args[i + 1] !== undefined)
9631
+ consent = args[++i];
9632
+ else if (arg === "--slug" && args[i + 1] !== undefined && !args[i + 1].startsWith("-"))
9633
+ slug = args[++i];
9634
+ else if (arg === "--dry-run" || arg === "--json")
9635
+ seen.add(arg);
9636
+ else
9637
+ return null;
9638
+ }
9639
+ const origin = seen.has("--origin");
9640
+ const dryRun = seen.has("--dry-run");
9641
+ const valid = live.length === 0 ? origin && slug === undefined : live.length === 1 && !origin && !dryRun;
9642
+ if (!valid)
9643
+ return null;
9644
+ return {
9645
+ action: live[0] ?? "origin",
9646
+ dryRun,
9647
+ json: seen.has("--json"),
9648
+ ...consent === undefined ? {} : { consent },
9649
+ ...slug === undefined ? {} : { slug }
9650
+ };
9651
+ }
9451
9652
  async function runMigrate(args, io) {
9452
9653
  if (args.length === 1 && (args[0] === "--help" || args[0] === "-h")) {
9453
9654
  io.out(USAGE);
9454
9655
  return 0;
9455
9656
  }
9456
- const flags = args.filter((arg) => arg !== "--dry-run");
9457
- if (flags.length !== 2 || flags[0] !== "--origin" || flags[1] !== "dispatch" || args.length > 3) {
9657
+ const parsed = parseMigrateArgs(args);
9658
+ if (parsed === null) {
9458
9659
  io.err(USAGE);
9459
9660
  return 64;
9460
9661
  }
9461
9662
  try {
9462
- reportMigration(io, await convertToDispatch(process.cwd(), args.includes("--dry-run")));
9463
- return 0;
9663
+ if (parsed.action !== "origin")
9664
+ return await runLive(parsed.action, parsed, io);
9665
+ try {
9666
+ reportMigration(io, await convertToDispatch(process.cwd(), parsed.dryRun));
9667
+ return 0;
9668
+ } catch (error) {
9669
+ if (!(error instanceof RegisteredAppError))
9670
+ throw error;
9671
+ return await runLive(parsed.dryRun ? "check" : "start", parsed, io);
9672
+ }
9464
9673
  } catch (error) {
9465
9674
  io.err(`launchpad migrate: ${error instanceof Error ? error.message : String(error)}`);
9466
9675
  return 1;
9467
9676
  }
9468
9677
  }
9678
+ async function runLive(action, parsed, io) {
9679
+ const slug = parsed.slug ?? inferSlug({ cwd: process.cwd(), warn: (line) => io.err(line) });
9680
+ if (slug === null)
9681
+ throw new Error("run this in the app's directory (next to launchpad.yaml).");
9682
+ return runLiveMigration(slug, action, { json: parsed.json, ...parsed.consent === undefined ? {} : { consent: parsed.consent } }, io);
9683
+ }
9469
9684
  function reportMigration(io, result) {
9470
9685
  if (result.kind === "already") {
9471
- io.out("launchpad.yaml already selects Workers dispatch. Run `launchpad deploy`.");
9686
+ io.out(result.migrating === true ? "This app is mid-migration to Workers dispatch. Run `launchpad migrate --status` for the next step." : "launchpad.yaml already selects Workers dispatch. Run `launchpad deploy`.");
9472
9687
  return;
9473
9688
  }
9474
9689
  if (result.kind === "eligible") {
@@ -9505,8 +9720,9 @@ async function convertToDispatch(cwd, dryRun) {
9505
9720
  if (loaded.kind !== "ok")
9506
9721
  throw new InvalidManifestError;
9507
9722
  const manifest = loaded.manifest;
9508
- if (manifest.apiVersion === "launchpad.m-kopa.us/v2" && manifest.spec.origin === "dispatch")
9509
- return { kind: "already" };
9723
+ if (manifest.apiVersion === "launchpad.m-kopa.us/v2" && manifest.spec.origin === "dispatch") {
9724
+ return { kind: "already", migrating: manifest.spec.migration !== undefined };
9725
+ }
9510
9726
  const slug = manifest.apiVersion === "launchpad.m-kopa.us/v2" ? manifest.metadata.slug : manifest.metadata.name;
9511
9727
  let converted;
9512
9728
  try {
@@ -9586,7 +9802,7 @@ class RegistryUnavailableError extends Error {
9586
9802
 
9587
9803
  class RegisteredAppError extends Error {
9588
9804
  constructor() {
9589
- super("This app is already registered. This command only converts apps that have never provisioned; ask the platform team to migrate an existing app.");
9805
+ super("This app is already registered, so its local launchpad.yaml was not converted. Run `launchpad migrate --origin dispatch --dry-run` to check whether it can move.");
9590
9806
  }
9591
9807
  }
9592
9808
  var WRANGLER_FILES = ["wrangler.toml", "wrangler.json", "wrangler.jsonc"];
@@ -10105,7 +10321,7 @@ async function runModelADeploy(args) {
10105
10321
  return 1;
10106
10322
  }
10107
10323
  try {
10108
- const manifestObj = parseYaml6(readFileSync12(manifestPath, "utf8"));
10324
+ const manifestObj = parseYaml7(readFileSync12(manifestPath, "utf8"));
10109
10325
  const metaSlug = resolveManifestSlug(manifestObj);
10110
10326
  if (metaSlug === null) {
10111
10327
  io.err(`launchpad deploy: launchpad.yaml is missing metadata.slug (v2) / metadata.name (v1). ` + `Run \`launchpad init\` again to regenerate the manifest.`);
@@ -10185,6 +10401,14 @@ async function runModelADeploy(args) {
10185
10401
  } catch {}
10186
10402
  const deployContext = await readDeploymentContext(realCommitWaitDeps(cfg), slug);
10187
10403
  const deployBaseline = noVerify ? null : deployContext.baseline;
10404
+ const shownWarnings = new Set;
10405
+ const onWarning = (warning) => {
10406
+ if (!shownWarnings.has(warning))
10407
+ io.err(warning);
10408
+ shownWarnings.add(warning);
10409
+ };
10410
+ const botMessage = (message) => [...shownWarnings].reduce((m, w) => m.replace(`
10411
+ ${w}`, ""), message);
10188
10412
  let result;
10189
10413
  try {
10190
10414
  if (args.allowUnguarded) {
@@ -10195,7 +10419,8 @@ async function runModelADeploy(args) {
10195
10419
  cfg,
10196
10420
  slug,
10197
10421
  overrideStale: args.overrideStale,
10198
- allowUnguarded: args.allowUnguarded
10422
+ allowUnguarded: args.allowUnguarded,
10423
+ onWarning
10199
10424
  });
10200
10425
  if (result.kind === "upload-error" && result.status === 409 && result.body.error === "main_advanced") {
10201
10426
  io.out("Managed main advanced during validation; recomputing and retrying once ...");
@@ -10204,7 +10429,8 @@ async function runModelADeploy(args) {
10204
10429
  cfg,
10205
10430
  slug,
10206
10431
  overrideStale: args.overrideStale,
10207
- allowUnguarded: args.allowUnguarded
10432
+ allowUnguarded: args.allowUnguarded,
10433
+ onWarning
10208
10434
  });
10209
10435
  }
10210
10436
  if (args.rebaseOntoHead && result.kind === "upload-error" && result.status === 409 && isStaleBlock(result.body)) {
@@ -10212,7 +10438,7 @@ async function runModelADeploy(args) {
10212
10438
  if (typeof head === "string" && isValidBaseSha(head)) {
10213
10439
  await writeBaseShaMarker(cwd, head);
10214
10440
  io.out(`Re-stamped base revision to current head ${head.slice(0, 12)}; retrying deploy …`);
10215
- result = await bundleAndDeploy({ cwd, cfg, slug });
10441
+ result = await bundleAndDeploy({ cwd, cfg, slug, onWarning });
10216
10442
  } else {
10217
10443
  io.err("launchpad deploy: --rebase-onto-head could not read a head SHA from the block; run `launchpad pull` and retry.");
10218
10444
  return 1;
@@ -10379,7 +10605,7 @@ async function runModelADeploy(args) {
10379
10605
  if (success.status === "provisioning_started") {
10380
10606
  const submissionId = typeof success.submissionId === "string" ? success.submissionId : "(missing)";
10381
10607
  const echoedAppType = typeof success.appType === "string" ? success.appType : "(missing)";
10382
- const message = typeof success.message === "string" ? success.message : "Bot accepted the upload and started provisioning.";
10608
+ const message = typeof success.message === "string" ? botMessage(success.message) : "Bot accepted the upload and started provisioning.";
10383
10609
  if (success.mode === "container_redeploy") {
10384
10610
  io.out(`✓ Container redeploy started for ${slug}`);
10385
10611
  io.out(` submission: ${submissionId}`);
@@ -10436,7 +10662,7 @@ async function runModelADeploy(args) {
10436
10662
  io.out(` ${result.walk.skipped.length} entries skipped (.gitignore / default-ignore / symlink)`);
10437
10663
  }
10438
10664
  if (typeof success.message === "string") {
10439
- io.out(` ${success.message}`);
10665
+ io.out(` ${botMessage(success.message)}`);
10440
10666
  }
10441
10667
  surfaceDeployExtras(success, io, slug, args.allowStale);
10442
10668
  io.out("");
@@ -10478,7 +10704,7 @@ async function defaultToDispatch(cwd, manifestPath, io) {
10478
10704
  if (!impliesPagesForGateway(fields))
10479
10705
  return;
10480
10706
  try {
10481
- const result = await convertToDispatch(cwd, false);
10707
+ const result = await convertWithRegistryRetry(cwd);
10482
10708
  if (result.kind === "converted")
10483
10709
  reportConversion(io, result.secrets, result.plainSecretLike);
10484
10710
  } catch (e) {
@@ -10493,6 +10719,32 @@ async function defaultToDispatch(cwd, manifestPath, io) {
10493
10719
  throw new DispatchIneligibleError(describe17(e), fields.v2 === true);
10494
10720
  }
10495
10721
  }
10722
+ var REGISTRY_RETRY_DELAYS_MS = [250, 750];
10723
+ async function convertWithRegistryRetry(cwd) {
10724
+ for (const delay of REGISTRY_RETRY_DELAYS_MS) {
10725
+ try {
10726
+ return await convertToDispatch(cwd, false);
10727
+ } catch (e) {
10728
+ if (!(e instanceof RegistryUnavailableError))
10729
+ throw e;
10730
+ await new Promise((resolve10) => setTimeout(resolve10, delay));
10731
+ }
10732
+ }
10733
+ try {
10734
+ return await convertToDispatch(cwd, false);
10735
+ } catch (e) {
10736
+ if (e instanceof RegistryUnavailableError)
10737
+ throw new RegistryRetriesExhaustedError(e);
10738
+ throw e;
10739
+ }
10740
+ }
10741
+
10742
+ class RegistryRetriesExhaustedError extends RegistryUnavailableError {
10743
+ constructor(last2) {
10744
+ super(last2);
10745
+ this.message = `${last2.message} (tried ${REGISTRY_RETRY_DELAYS_MS.length + 1} times). ` + "This app may already exist; nothing was changed, so running `launchpad deploy` again is safe";
10746
+ }
10747
+ }
10496
10748
 
10497
10749
  class DispatchIneligibleError extends Error {
10498
10750
  constructor(reason, v2) {
@@ -10512,7 +10764,7 @@ function impliesPagesForGateway(fields) {
10512
10764
  function originFields(manifestPath) {
10513
10765
  let raw;
10514
10766
  try {
10515
- raw = parseYaml6(readFileSync12(manifestPath, "utf8")) ?? {};
10767
+ raw = parseYaml7(readFileSync12(manifestPath, "utf8")) ?? {};
10516
10768
  } catch {
10517
10769
  return {};
10518
10770
  }
@@ -10567,7 +10819,7 @@ function pendingReconcileOutcome(body) {
10567
10819
  // src/commands/redeploy.ts
10568
10820
  import { existsSync as existsSync9, readFileSync as readFileSync13 } from "node:fs";
10569
10821
  import { resolve as resolvePath2 } from "node:path";
10570
- import { parse as parseYaml7 } from "yaml";
10822
+ import { parse as parseYaml8 } from "yaml";
10571
10823
  var SLUG_RE6 = /^[a-z0-9][a-z0-9-]*[a-z0-9]$/;
10572
10824
  var DEFAULT_VERIFY_TIMEOUT_MS = 180000;
10573
10825
  var redeployCommand = {
@@ -10646,7 +10898,7 @@ function readLocalAppType(cwd, file) {
10646
10898
  if (!existsSync9(manifestPath))
10647
10899
  return null;
10648
10900
  try {
10649
- const obj = parseYaml7(readFileSync13(manifestPath, "utf8"));
10901
+ const obj = parseYaml8(readFileSync13(manifestPath, "utf8"));
10650
10902
  return coerceAppType(obj?.deployment?.type);
10651
10903
  } catch {
10652
10904
  return null;
@@ -12688,6 +12940,11 @@ async function runLogs(args, io) {
12688
12940
  }
12689
12941
  try {
12690
12942
  const cfg = loadConfig();
12943
+ const status = await fetchDeploymentStatusBestEffort(cfg, slug);
12944
+ if (status?.origin === "dispatch") {
12945
+ renderDispatchNotice(slug, status, io);
12946
+ return 0;
12947
+ }
12691
12948
  const r = await apiJson(cfg, {
12692
12949
  path: `/apps/${slug}/deployments`
12693
12950
  });
@@ -12723,6 +12980,15 @@ async function runLogs(args, io) {
12723
12980
  return 1;
12724
12981
  }
12725
12982
  }
12983
+ function renderDispatchNotice(slug, status, io) {
12984
+ io.out(`launchpad logs: ${slug} runs on Workers dispatch, and logs only covers Cloudflare Pages apps today.`);
12985
+ io.out(` Run \`launchpad status ${slug}\` for the delivery stage and outcome.`);
12986
+ const runUrl = status.v2?.runUrl;
12987
+ if (runUrl !== undefined)
12988
+ io.out(` Latest build run: ${runUrl}`);
12989
+ else
12990
+ io.out(" The build runs as GitHub Actions in the app repo; `launchpad status` links the run when there is one.");
12991
+ }
12726
12992
  function parseArgs7(args) {
12727
12993
  let slug = null;
12728
12994
  let lines = DEFAULT_LINES;
@@ -14010,7 +14276,7 @@ async function runPull(args, io) {
14010
14276
  includeManifest: true
14011
14277
  });
14012
14278
  if (state.manifestYaml === null || state.manifestYaml === undefined) {
14013
- const live = await fetchLiveDeploymentBestEffort(cfg, parsed.slug);
14279
+ const live = await fetchDeploymentStatusBestEffort(cfg, parsed.slug);
14014
14280
  if (live?.liveDeployment != null && (live.liveDeployment.buildStatus === "success" || live.lastSuccessfulDeployment != null)) {
14015
14281
  io.err(`launchpad pull: no platform-tracked manifest for "${parsed.slug}", ` + `but the app HAS live content (last deployment ${live.liveDeployment.createdOn} ` + `via ${live.liveDeployment.trigger === "git-push" ? "git push" : live.liveDeployment.trigger}, ` + `build ${live.liveDeployment.buildStatus}).`);
14016
14282
  io.err(` This app deploys outside \`launchpad deploy\`, so there is no manifest to pull. ` + `Run \`launchpad status ${parsed.slug}\` for the live deployment detail.`);
@@ -14052,13 +14318,6 @@ async function runPull(args, io) {
14052
14318
  return 1;
14053
14319
  }
14054
14320
  }
14055
- async function fetchLiveDeploymentBestEffort(cfg, slug) {
14056
- try {
14057
- return await fetchDeploymentStatus(cfg, slug);
14058
- } catch {
14059
- return null;
14060
- }
14061
- }
14062
14321
  function parseArgs10(args, cwd = process.cwd(), warn) {
14063
14322
  let slug = null;
14064
14323
  let out = null;
@@ -15018,7 +15277,7 @@ async function runSecretsPush(opts, io, deps = {}) {
15018
15277
  try {
15019
15278
  resp = await apiJson(cfg, {
15020
15279
  method: "POST",
15021
- path: `/apps/${slug}/secrets/${b.name}`,
15280
+ path: `/apps/${slug}/secrets/${b.name}${opts.staged === true ? "?target=staged" : ""}`,
15022
15281
  jsonBody: b.targets !== undefined ? { value, targets: b.targets } : { value },
15023
15282
  nonThrowingStatuses: [409]
15024
15283
  }, fetcher);
@@ -15031,7 +15290,7 @@ async function runSecretsPush(opts, io, deps = {}) {
15031
15290
  io.err(`✗ secrets push ${b.name}: invalid bot response (results must be an array)`);
15032
15291
  return 2;
15033
15292
  }
15034
- if (resp.error === "dispatch_script_not_delivered") {
15293
+ if (resp.error === "dispatch_script_not_delivered" || resp.error === "no_staged_migration") {
15035
15294
  io.err(`✗ secrets push ${b.name}: ${resp.message ?? "the dispatch script is not delivered yet"}`);
15036
15295
  io.err(`${pushed} of ${envFileBindings.length} pushed before failure.`);
15037
15296
  return 1;
@@ -15069,7 +15328,9 @@ async function runSecretsPush(opts, io, deps = {}) {
15069
15328
  if (anyPagesUpdated) {
15070
15329
  return offerRedeploy(slug, opts, io, deps);
15071
15330
  }
15072
- if (anyDispatchUpdated) {
15331
+ if (anyDispatchUpdated && opts.staged === true) {
15332
+ io.out("Set on the staged dispatch script. It serves users once you run `launchpad migrate --flip`.");
15333
+ } else if (anyDispatchUpdated) {
15073
15334
  io.out("Set on the app's dispatch Worker and live now - no redeploy needed.");
15074
15335
  } else if (anyWorkerUpdated) {
15075
15336
  io.out("These secrets bind on the app's next invocation — no redeploy needed.");
@@ -15274,7 +15535,7 @@ function renderManifestError5(result, io) {
15274
15535
  // src/secrets/set.ts
15275
15536
  import { existsSync as existsSync14, readFileSync as readFileSync19 } from "node:fs";
15276
15537
  import { resolve as resolvePath6 } from "node:path";
15277
- import { parse as parseYaml8 } from "yaml";
15538
+ import { parse as parseYaml9 } from "yaml";
15278
15539
  var CELL_LABEL2 = {
15279
15540
  present: "PRESENT",
15280
15541
  missing: "MISSING",
@@ -15289,7 +15550,7 @@ function loadSet(fleetFile, setName, io) {
15289
15550
  }
15290
15551
  let obj;
15291
15552
  try {
15292
- obj = parseYaml8(readFileSync19(path15, "utf8"));
15553
+ obj = parseYaml9(readFileSync19(path15, "utf8"));
15293
15554
  } catch (e) {
15294
15555
  io.err(`✗ ${path15}`);
15295
15556
  io.err(` YAML parse error: ${e instanceof Error ? e.message : String(e)}`);
@@ -15700,7 +15961,7 @@ async function runSecrets(args, io) {
15700
15961
  if (typeof parsed === "string") {
15701
15962
  io.err(`launchpad secrets push: ${parsed}`);
15702
15963
  io.err("");
15703
- io.err("usage: launchpad secrets push [--file <manifest>] [--env <.env>] [--dry-run] [--redeploy] [--yes]");
15964
+ io.err("usage: launchpad secrets push [--file <manifest>] [--env <.env>] [--dry-run] [--redeploy | --staged] [--yes]");
15704
15965
  io.err(" launchpad secrets push --set <name> [--fleet-file <path>] [--env <.env>] [--yes]");
15705
15966
  return 64;
15706
15967
  }
@@ -15736,6 +15997,7 @@ function parsePushArgs(args) {
15736
15997
  let fleetFile = null;
15737
15998
  let yes = false;
15738
15999
  let redeploy = false;
16000
+ let staged = false;
15739
16001
  let i = 0;
15740
16002
  while (i < args.length) {
15741
16003
  const a = args[i] ?? "";
@@ -15766,6 +16028,11 @@ function parsePushArgs(args) {
15766
16028
  i += 1;
15767
16029
  continue;
15768
16030
  }
16031
+ if (a === "--staged") {
16032
+ staged = true;
16033
+ i += 1;
16034
+ continue;
16035
+ }
15769
16036
  if (a === "--redeploy") {
15770
16037
  redeploy = true;
15771
16038
  i += 1;
@@ -15778,9 +16045,13 @@ function parsePushArgs(args) {
15778
16045
  return "--file/--dry-run are not valid with --set (use --fleet-file / --yes)";
15779
16046
  if (redeploy)
15780
16047
  return "--redeploy is not valid with --set (a fleet secret-set has no single app to redeploy)";
16048
+ if (staged)
16049
+ return "--staged is not valid with --set (it targets one app's staged migration)";
15781
16050
  return { set, fleetFile, env, yes };
15782
16051
  }
15783
- return { file, env, dryRun, redeploy: redeploy || yes };
16052
+ if (staged && redeploy)
16053
+ return "--redeploy is not valid with --staged (the staged script needs no redeploy)";
16054
+ return { file, env, dryRun, redeploy: redeploy || yes, ...staged ? { staged } : {} };
15784
16055
  }
15785
16056
  function parseStatusArgs(args) {
15786
16057
  let file = null;