@package-broker/cli 0.19.8 → 2.0.0-rc.1

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 (181) hide show
  1. package/LICENSE +661 -0
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/bin.d.ts +3 -0
  4. package/dist/bin.d.ts.map +1 -0
  5. package/dist/bin.js +12 -0
  6. package/dist/bin.js.map +1 -0
  7. package/dist/build-artifacts.d.ts +27 -0
  8. package/dist/build-artifacts.d.ts.map +1 -0
  9. package/dist/build-artifacts.js +169 -0
  10. package/dist/build-artifacts.js.map +1 -0
  11. package/dist/build-assets.d.ts +36 -0
  12. package/dist/build-assets.d.ts.map +1 -0
  13. package/dist/build-assets.js +224 -0
  14. package/dist/build-assets.js.map +1 -0
  15. package/dist/build.d.ts +31 -0
  16. package/dist/build.d.ts.map +1 -0
  17. package/dist/build.js +277 -0
  18. package/dist/build.js.map +1 -0
  19. package/dist/cli.d.ts +2 -0
  20. package/dist/cli.d.ts.map +1 -0
  21. package/dist/cli.js +801 -0
  22. package/dist/cli.js.map +1 -0
  23. package/dist/cloudflare/d1-http-executor.d.ts +30 -0
  24. package/dist/cloudflare/d1-http-executor.d.ts.map +1 -0
  25. package/dist/cloudflare/d1-http-executor.js +230 -0
  26. package/dist/cloudflare/d1-http-executor.js.map +1 -0
  27. package/dist/cloudflare/d1-http-response.d.ts +4 -0
  28. package/dist/cloudflare/d1-http-response.d.ts.map +1 -0
  29. package/dist/cloudflare/d1-http-response.js +113 -0
  30. package/dist/cloudflare/d1-http-response.js.map +1 -0
  31. package/dist/commands/admin.d.ts +47 -0
  32. package/dist/commands/admin.d.ts.map +1 -0
  33. package/dist/commands/admin.js +447 -0
  34. package/dist/commands/admin.js.map +1 -0
  35. package/dist/commands/built-manifest.d.ts +13 -0
  36. package/dist/commands/built-manifest.d.ts.map +1 -0
  37. package/dist/commands/built-manifest.js +197 -0
  38. package/dist/commands/built-manifest.js.map +1 -0
  39. package/dist/commands/cloudflare/api.d.ts +129 -0
  40. package/dist/commands/cloudflare/api.d.ts.map +1 -0
  41. package/dist/commands/cloudflare/api.js +480 -0
  42. package/dist/commands/cloudflare/api.js.map +1 -0
  43. package/dist/commands/cloudflare/deploy.d.ts +81 -0
  44. package/dist/commands/cloudflare/deploy.d.ts.map +1 -0
  45. package/dist/commands/cloudflare/deploy.js +1848 -0
  46. package/dist/commands/cloudflare/deploy.js.map +1 -0
  47. package/dist/commands/cloudflare/inventory.d.ts +243 -0
  48. package/dist/commands/cloudflare/inventory.d.ts.map +1 -0
  49. package/dist/commands/cloudflare/inventory.js +786 -0
  50. package/dist/commands/cloudflare/inventory.js.map +1 -0
  51. package/dist/commands/cloudflare/janitor.d.ts +10 -0
  52. package/dist/commands/cloudflare/janitor.d.ts.map +1 -0
  53. package/dist/commands/cloudflare/janitor.js +84 -0
  54. package/dist/commands/cloudflare/janitor.js.map +1 -0
  55. package/dist/commands/cloudflare/migrations-check.d.ts +5 -0
  56. package/dist/commands/cloudflare/migrations-check.d.ts.map +1 -0
  57. package/dist/commands/cloudflare/migrations-check.js +10 -0
  58. package/dist/commands/cloudflare/migrations-check.js.map +1 -0
  59. package/dist/commands/cloudflare/provision.d.ts +79 -0
  60. package/dist/commands/cloudflare/provision.d.ts.map +1 -0
  61. package/dist/commands/cloudflare/provision.js +961 -0
  62. package/dist/commands/cloudflare/provision.js.map +1 -0
  63. package/dist/commands/cloudflare/queue-consumer.d.ts +4 -0
  64. package/dist/commands/cloudflare/queue-consumer.d.ts.map +1 -0
  65. package/dist/commands/cloudflare/queue-consumer.js +57 -0
  66. package/dist/commands/cloudflare/queue-consumer.js.map +1 -0
  67. package/dist/commands/cloudflare/setup.d.ts +48 -0
  68. package/dist/commands/cloudflare/setup.d.ts.map +1 -0
  69. package/dist/commands/cloudflare/setup.js +836 -0
  70. package/dist/commands/cloudflare/setup.js.map +1 -0
  71. package/dist/commands/cloudflare/smoke.d.ts +29 -0
  72. package/dist/commands/cloudflare/smoke.d.ts.map +1 -0
  73. package/dist/commands/cloudflare/smoke.js +715 -0
  74. package/dist/commands/cloudflare/smoke.js.map +1 -0
  75. package/dist/commands/cloudflare/teardown.d.ts +62 -0
  76. package/dist/commands/cloudflare/teardown.d.ts.map +1 -0
  77. package/dist/commands/cloudflare/teardown.js +906 -0
  78. package/dist/commands/cloudflare/teardown.js.map +1 -0
  79. package/dist/commands/cloudflare/worker-settings.d.ts +4 -0
  80. package/dist/commands/cloudflare/worker-settings.d.ts.map +1 -0
  81. package/dist/commands/cloudflare/worker-settings.js +93 -0
  82. package/dist/commands/cloudflare/worker-settings.js.map +1 -0
  83. package/dist/commands/cloudflare.d.ts +55 -0
  84. package/dist/commands/cloudflare.d.ts.map +1 -0
  85. package/dist/commands/cloudflare.js +393 -0
  86. package/dist/commands/cloudflare.js.map +1 -0
  87. package/dist/commands/import-cutover.d.ts +5 -0
  88. package/dist/commands/import-cutover.d.ts.map +1 -0
  89. package/dist/commands/import-cutover.js +25 -0
  90. package/dist/commands/import-cutover.js.map +1 -0
  91. package/dist/commands/import-private-packagist.d.ts +38 -0
  92. package/dist/commands/import-private-packagist.d.ts.map +1 -0
  93. package/dist/commands/import-private-packagist.js +232 -0
  94. package/dist/commands/import-private-packagist.js.map +1 -0
  95. package/dist/commands/import-satis.d.ts +11 -0
  96. package/dist/commands/import-satis.d.ts.map +1 -0
  97. package/dist/commands/import-satis.js +112 -0
  98. package/dist/commands/import-satis.js.map +1 -0
  99. package/dist/commands/import.d.ts +22 -0
  100. package/dist/commands/import.d.ts.map +1 -0
  101. package/dist/commands/import.js +343 -0
  102. package/dist/commands/import.js.map +1 -0
  103. package/dist/commands/openapi-specs.d.ts +4 -0
  104. package/dist/commands/openapi-specs.d.ts.map +1 -0
  105. package/dist/commands/openapi-specs.js +94 -0
  106. package/dist/commands/openapi-specs.js.map +1 -0
  107. package/dist/commands/openapi.d.ts +12 -0
  108. package/dist/commands/openapi.d.ts.map +1 -0
  109. package/dist/commands/openapi.js +44 -0
  110. package/dist/commands/openapi.js.map +1 -0
  111. package/dist/commands/source.d.ts +8 -0
  112. package/dist/commands/source.d.ts.map +1 -0
  113. package/dist/commands/source.js +61 -0
  114. package/dist/commands/source.js.map +1 -0
  115. package/dist/commands/sqlite.d.ts +11 -0
  116. package/dist/commands/sqlite.d.ts.map +1 -0
  117. package/dist/commands/sqlite.js +76 -0
  118. package/dist/commands/sqlite.js.map +1 -0
  119. package/dist/import/client.d.ts +71 -0
  120. package/dist/import/client.d.ts.map +1 -0
  121. package/dist/import/client.js +348 -0
  122. package/dist/import/client.js.map +1 -0
  123. package/dist/import/credential-refs.d.ts +2 -0
  124. package/dist/import/credential-refs.d.ts.map +1 -0
  125. package/dist/import/credential-refs.js +22 -0
  126. package/dist/import/credential-refs.js.map +1 -0
  127. package/dist/import/cutover.d.ts +64 -0
  128. package/dist/import/cutover.d.ts.map +1 -0
  129. package/dist/import/cutover.js +544 -0
  130. package/dist/import/cutover.js.map +1 -0
  131. package/dist/import/private-packagist/api.d.ts +57 -0
  132. package/dist/import/private-packagist/api.d.ts.map +1 -0
  133. package/dist/import/private-packagist/api.js +246 -0
  134. package/dist/import/private-packagist/api.js.map +1 -0
  135. package/dist/import/private-packagist/dates.d.ts +30 -0
  136. package/dist/import/private-packagist/dates.d.ts.map +1 -0
  137. package/dist/import/private-packagist/dates.js +189 -0
  138. package/dist/import/private-packagist/dates.js.map +1 -0
  139. package/dist/import/private-packagist/map.d.ts +48 -0
  140. package/dist/import/private-packagist/map.d.ts.map +1 -0
  141. package/dist/import/private-packagist/map.js +162 -0
  142. package/dist/import/private-packagist/map.js.map +1 -0
  143. package/dist/import/private-packagist/plan.d.ts +61 -0
  144. package/dist/import/private-packagist/plan.d.ts.map +1 -0
  145. package/dist/import/private-packagist/plan.js +936 -0
  146. package/dist/import/private-packagist/plan.js.map +1 -0
  147. package/dist/import/private-packagist/snapshot.d.ts +31 -0
  148. package/dist/import/private-packagist/snapshot.d.ts.map +1 -0
  149. package/dist/import/private-packagist/snapshot.js +406 -0
  150. package/dist/import/private-packagist/snapshot.js.map +1 -0
  151. package/dist/import/satis.d.ts +93 -0
  152. package/dist/import/satis.d.ts.map +1 -0
  153. package/dist/import/satis.js +873 -0
  154. package/dist/import/satis.js.map +1 -0
  155. package/dist/index.d.ts +3 -2
  156. package/dist/index.d.ts.map +1 -1
  157. package/dist/index.js +3 -96
  158. package/dist/index.js.map +1 -1
  159. package/dist/manifest.d.ts +55 -0
  160. package/dist/manifest.d.ts.map +1 -0
  161. package/dist/manifest.js +125 -0
  162. package/dist/manifest.js.map +1 -0
  163. package/dist/migrations-collect.d.ts +6 -0
  164. package/dist/migrations-collect.d.ts.map +1 -0
  165. package/dist/migrations-collect.js +39 -0
  166. package/dist/migrations-collect.js.map +1 -0
  167. package/dist/prebuilt-expected.json +7 -0
  168. package/dist/prebuilt.d.ts +27 -0
  169. package/dist/prebuilt.d.ts.map +1 -0
  170. package/dist/prebuilt.js +391 -0
  171. package/dist/prebuilt.js.map +1 -0
  172. package/package.json +21 -25
  173. package/README.md +0 -29
  174. package/dist/__tests__/migrate.test.d.ts +0 -2
  175. package/dist/__tests__/migrate.test.d.ts.map +0 -1
  176. package/dist/__tests__/migrate.test.js +0 -116
  177. package/dist/__tests__/migrate.test.js.map +0 -1
  178. package/dist/migrate.d.ts +0 -40
  179. package/dist/migrate.d.ts.map +0 -1
  180. package/dist/migrate.js +0 -335
  181. package/dist/migrate.js.map +0 -1
package/dist/cli.js ADDED
@@ -0,0 +1,801 @@
1
+ import { createRequire } from 'node:module';
2
+ import { parseArgs } from 'node:util';
3
+ import { build, BuildDiagnosticsError } from './build.js';
4
+ import { assertPrebuiltConfiguration } from './prebuilt.js';
5
+ import { runAdminBootstrap, runAdminRebindProvider, runAdminResetLocal, runAdminShowProviderBinding, runGenerateMasterKey, } from './commands/admin.js';
6
+ import { runCloudflareBootstrap, runCloudflareMigrate } from './commands/cloudflare.js';
7
+ import { runCloudflareProvision } from './commands/cloudflare/provision.js';
8
+ import { runCloudflareDeploy } from './commands/cloudflare/deploy.js';
9
+ import { runCloudflareSetup } from './commands/cloudflare/setup.js';
10
+ import { runCloudflareSmoke } from './commands/cloudflare/smoke.js';
11
+ import { runCloudflareTeardown } from './commands/cloudflare/teardown.js';
12
+ import { runCloudflareJanitor } from './commands/cloudflare/janitor.js';
13
+ import { commandEnvelope, failCommand, CloudflareError } from './commands/cloudflare/api.js';
14
+ import { runImport } from './commands/import.js';
15
+ import { runImportCutover } from './commands/import-cutover.js';
16
+ import { runImportSatisPlan } from './commands/import-satis.js';
17
+ import { runImportPrivatePackagistFetch, runImportPrivatePackagistPlan, runImportPrivatePackagistDates, } from './commands/import-private-packagist.js';
18
+ import { runSourceAcceptRemoval } from './commands/source.js';
19
+ import { runOpenApi } from './commands/openapi.js';
20
+ import { runBootstrapSqlite, runMigrateSqlite } from './commands/sqlite.js';
21
+ const USAGE = 'Usage: pb build [--config <file>] [--target cloudflare|node] [--out <dir>]\n' +
22
+ ' pb migrate --sqlite <file> [--out <dir> (default .pb/node)] [--dry-run]\n' +
23
+ ' pb bootstrap --sqlite <file> --slug <slug> --name <name>\n' +
24
+ ' pb cloudflare setup [--prebuilt] --worker-name <slug> --org-slug <slug> --org-name <name> --admin-email <email> [--key-file <path> | --master-key-env <name>] [--token-file <path>] [--non-interactive] [--yes] [--refresh-setup-token] [--json] [--dry-run]\n' +
25
+ ' pb cloudflare provision [--prebuilt] --worker-name <slug> [--config <file>] [--environment <slug>] [--jurisdiction eu|default] [--inventory <file>] [--out <dir>] [--adopt-resource <kind:id>] [--abandon-intent <op-id>] [--domain <hostname>] [--yes] [--json] [--dry-run]\n' +
26
+ ' pb cloudflare deploy [--prebuilt] --worker-name <slug> [--out <dir>] [--rollout <1..100>] [--domain <hostname>] [--public-url <https-origin>] [--routes <zone:pattern\n...>] [--secret <ENV_NAME>] [--secrets <ENV_NAMES>] [--json] [--dry-run]\n' +
27
+ ' pb cloudflare smoke --worker-name <slug> [--project <slug>] [--smoke-token-env <name>] [--deadline-seconds <1..300>] [--no-rollback] [--json] [--dry-run]\n' +
28
+ ' pb cloudflare teardown --inventory <file> [--config <file>] [--project <dir>] [--inventory-id <owner_digest> --i-understand-this-deletes] [--json] [--dry-run]\n' +
29
+ ' pb cloudflare janitor --repository-id <numeric-id> [--inventory <file>] [--config <file>] [--project <dir>] [--json] [--dry-run]\n' +
30
+ ' pb cloudflare migrate [--prebuilt] --database-id <id> [--out <dir> (default .pb/cloudflare)] [--dry-run]\n' +
31
+ ' pb cloudflare bootstrap --database-id <id> --slug <slug> --name <name>\n' +
32
+ ' pb secrets generate-master-key [--key-version <n> (default 1)]\n' +
33
+ ' pb admin bootstrap --email <e> (--sqlite <file> | --cloudflare --database-id <id>) [--token-file <path>]\n' +
34
+ ' pb admin reset-local --email <e> (--sqlite <file> | --cloudflare --database-id <id>) [--token-file <path>]\n' +
35
+ ' pb admin rebind-provider --provider <id> --confirm <id> --expected-anchor <anchor> --new-anchor <anchor> (--sqlite <file> | --cloudflare --database-id <id>)\n' +
36
+ ' pb admin show-provider-binding --provider <id> (--sqlite <file> | --cloudflare --database-id <id>)\n' +
37
+ ' pb import cutover-check --project-dir <dir> --old-repository <url> --new-repository <url> --old-auth-env <VAR> --new-auth-env <VAR> [--lock <file>]... [--timeout-seconds <seconds>] [--json]\n' +
38
+ ' pb import private-packagist fetch --org <short-name> --snapshot <out.json> [--api-key-file <path>] [--api-secret-file <path>] [--versions] [--require-org-match] (or PP_API_KEY_FILE/PP_API_SECRET_FILE)\n' +
39
+ ' pb import private-packagist plan --snapshot <file> --map <file> --out <manifest> --credentials-out <file> [--members <csv>] [--baseline <manifest>] [--mode merge|override] [--include-org-admins] [--runtime workers|node] [--packagist existing:<name>] [--compact-selection --compact-vendor <vendor>...] [--accept-project-widening <slug>...] [--quiet]\n' +
40
+ ' pb import private-packagist dates --snapshot <file> --map <file> --baseline <manifest> --out <manifest> [--package <name>...] [--quiet]\n' +
41
+ ' pb import satis plan --config <satis.json> --out <manifest> [--project <slug>] [--repository-map <file>] [--credentials <file>] [--baseline <manifest>] [--mode merge|override]\n' +
42
+ ' pb import submit --manifest <file> --receipt <file> --principal <label> --broker <origin> [--resume] [--token-file <path>]\n' +
43
+ ' pb import status <run> --broker <origin> [--wait | --wait-seconds <0..300>] [--token-file <path>]\n' +
44
+ ' pb import credentials <run> --manifest <file> --credentials <map> --broker <origin> [--token-file <path>]\n' +
45
+ ' pb import verify <run> --broker <origin> [--wait | --wait-seconds <0..300>] [--token-file <path>]\n' +
46
+ ' pb import accept <run> --broker <origin> [--wait | --wait-seconds <0..300>] [--token-file <path>]\n' +
47
+ ' pb source accept-removal --url <https-origin> --source <id> (PB_SESSION and PB_CSRF_TOKEN)\n' +
48
+ ' pb version\n' +
49
+ 'Exit codes: 0 success; 1 error; 2 usage, invalid slug or invalid build configuration; 3 checksum mismatch; 4 migration locked; 5 already bootstrapped with another slug; 6 outcome unknown (response lost after the request was sent)\n' +
50
+ 'Exit codes for pb cloudflare smoke: 8 concurrent deployment or ownership conflict; 9 smoke failed on an existing deployment; 10 rollback failed or unknown; 11 contract migration blocks rollback; 12 first-deployment smoke failed with no prior release\n' +
51
+ 'Exit codes for pb cloudflare teardown/janitor: 0 cleaned or skipped; 1 cleanup failed; 2 invalid inventory, wrong inventory id or missing destructive confirmation; 4 inventory locked; 6 unresolved resource or deletion outcome; 8 ownership conflict. Production confirmation uses identity.owner_digest as --inventory-id. Adopted D1 and R2 resources always require --i-understand-this-deletes; janitor retains them. Inventory schema version 2 records deployment history and lifecycle baselines. Janitor requires run_identity pb-e2e-<repository-id>-<epoch-seconds> (optional run suffix) and a matching worker_name stem; Worker stems may encode both numbers in lowercase base 36 to fit name limits. Both the run and inventory update must be older than 6 hours. Deleting a Worker removes its versions.\n' +
52
+ 'Import commands use PB_IMPORT_TOKEN or --token-file. --resume requires the same token (idempotency principal); --principal is only a non-secret receipt label. Approval, apply and accept stay in the UI. Import exit codes: 0 success; 1 API or run failure; 2 local validation; 3 pending UI action or wait timeout; 6 outcome unknown.\n' +
53
+ 'Exit codes for pb admin bootstrap/reset-local: 0 success; 1 error; 2 usage, invalid e-mail or existing token file; 5 organization not bootstrapped; 6 already_set_up (bootstrap) or not_found (reset-local); 7 outcome unknown (D1 request sent, no usable response, re-running is safe); 8 admin_role_missing (reset-local); SIGINT or SIGTERM received during a synchronous SQLite batch is handled after the batch returns\n' +
54
+ 'Exit codes for pb admin rebind-provider: 0 success; 1 error; 2 usage, --confirm not equal to --provider, or invalid provider or anchor; 5 organization not bootstrapped; 6 anchor_mismatch (no binding with that provider and expected anchor; nothing changed); 7 outcome unknown (D1 response lost; the swap may have applied; a re-run that reports anchor_mismatch means it did or the anchor is wrong)\n' +
55
+ 'Exit codes for pb admin show-provider-binding: 0 success; 1 error; 2 usage or invalid provider; 5 organization not bootstrapped; 6 no_binding; nothing is bound for that provider; 7 outcome unknown (D1 response lost, re-running is safe)';
56
+ function parseCliArgs(argv) {
57
+ try {
58
+ return parseArgs({
59
+ args: argv,
60
+ allowPositionals: true,
61
+ options: {
62
+ url: { type: 'string' },
63
+ broker: { type: 'string' },
64
+ 'project-dir': { type: 'string' },
65
+ 'old-repository': { type: 'string' },
66
+ 'new-repository': { type: 'string' },
67
+ 'old-auth-env': { type: 'string' },
68
+ 'new-auth-env': { type: 'string' },
69
+ 'timeout-seconds': { type: 'string' },
70
+ lock: { type: 'string', multiple: true },
71
+ org: { type: 'string' },
72
+ snapshot: { type: 'string' },
73
+ map: { type: 'string' },
74
+ package: { type: 'string', multiple: true },
75
+ 'credentials-out': { type: 'string' },
76
+ members: { type: 'string' },
77
+ 'include-org-admins': { type: 'boolean' },
78
+ runtime: { type: 'string' },
79
+ packagist: { type: 'string' },
80
+ 'compact-selection': { type: 'boolean' },
81
+ 'compact-vendor': { type: 'string', multiple: true },
82
+ 'accept-project-widening': { type: 'string', multiple: true },
83
+ quiet: { type: 'boolean' },
84
+ 'api-key-file': { type: 'string' },
85
+ 'api-secret-file': { type: 'string' },
86
+ versions: { type: 'boolean' },
87
+ 'require-org-match': { type: 'boolean' },
88
+ manifest: { type: 'string' },
89
+ receipt: { type: 'string' },
90
+ principal: { type: 'string' },
91
+ resume: { type: 'boolean' },
92
+ wait: { type: 'boolean' },
93
+ 'wait-seconds': { type: 'string' },
94
+ source: { type: 'string' },
95
+ config: { type: 'string' },
96
+ target: { type: 'string' },
97
+ out: { type: 'string' },
98
+ sqlite: { type: 'string' },
99
+ slug: { type: 'string' },
100
+ name: { type: 'string' },
101
+ 'database-id': { type: 'string' },
102
+ email: { type: 'string' },
103
+ provider: { type: 'string' },
104
+ confirm: { type: 'string' },
105
+ 'expected-anchor': { type: 'string' },
106
+ 'new-anchor': { type: 'string' },
107
+ cloudflare: { type: 'boolean' },
108
+ prebuilt: { type: 'boolean' },
109
+ 'token-file': { type: 'string' },
110
+ 'key-file': { type: 'string' },
111
+ 'master-key-env': { type: 'string' },
112
+ 'org-slug': { type: 'string' },
113
+ 'org-name': { type: 'string' },
114
+ 'admin-email': { type: 'string' },
115
+ 'non-interactive': { type: 'boolean' },
116
+ 'refresh-setup-token': { type: 'boolean' },
117
+ migrate: { type: 'string' },
118
+ 'key-version': { type: 'string' },
119
+ 'dry-run': { type: 'boolean' },
120
+ 'worker-name': { type: 'string' },
121
+ environment: { type: 'string' },
122
+ 'deployment-id': { type: 'string' },
123
+ inventory: { type: 'string' },
124
+ 'inventory-id': { type: 'string' },
125
+ 'i-understand-this-deletes': { type: 'boolean' },
126
+ 'repository-id': { type: 'string' },
127
+ jurisdiction: { type: 'string' },
128
+ 'location-hint': { type: 'string' },
129
+ 'adopt-resource': { type: 'string', multiple: true },
130
+ 'abandon-intent': { type: 'string' },
131
+ 'allow-contract': { type: 'string', multiple: true },
132
+ domain: { type: 'string' },
133
+ rollout: { type: 'string' },
134
+ 'public-url': { type: 'string' },
135
+ routes: { type: 'string' },
136
+ secret: { type: 'string', multiple: true },
137
+ secrets: { type: 'string' },
138
+ yes: { type: 'boolean' },
139
+ json: { type: 'boolean' },
140
+ project: { type: 'string' },
141
+ 'smoke-token-env': { type: 'string' },
142
+ 'deadline-seconds': { type: 'string' },
143
+ 'no-rollback': { type: 'boolean' },
144
+ credentials: { type: 'string' },
145
+ 'repository-map': { type: 'string' },
146
+ baseline: { type: 'string' },
147
+ mode: { type: 'string' },
148
+ },
149
+ });
150
+ }
151
+ catch {
152
+ return null;
153
+ }
154
+ }
155
+ const ALLOWED_FLAGS = {
156
+ build: ['config', 'target', 'out'],
157
+ migrate: ['sqlite', 'out', 'dry-run'],
158
+ bootstrap: ['sqlite', 'slug', 'name'],
159
+ 'cloudflare setup': [
160
+ 'prebuilt',
161
+ 'worker-name',
162
+ 'config',
163
+ 'out',
164
+ 'environment',
165
+ 'deployment-id',
166
+ 'inventory',
167
+ 'jurisdiction',
168
+ 'location-hint',
169
+ 'adopt-resource',
170
+ 'abandon-intent',
171
+ 'domain',
172
+ 'public-url',
173
+ 'routes',
174
+ 'rollout',
175
+ 'allow-contract',
176
+ 'secret',
177
+ 'secrets',
178
+ 'org-slug',
179
+ 'org-name',
180
+ 'admin-email',
181
+ 'key-file',
182
+ 'master-key-env',
183
+ 'token-file',
184
+ 'non-interactive',
185
+ 'refresh-setup-token',
186
+ 'migrate',
187
+ 'yes',
188
+ 'json',
189
+ 'dry-run',
190
+ 'project',
191
+ 'smoke-token-env',
192
+ 'deadline-seconds',
193
+ ],
194
+ 'cloudflare provision': [
195
+ 'prebuilt',
196
+ 'worker-name',
197
+ 'config',
198
+ 'environment',
199
+ 'deployment-id',
200
+ 'inventory',
201
+ 'out',
202
+ 'jurisdiction',
203
+ 'location-hint',
204
+ 'adopt-resource',
205
+ 'abandon-intent',
206
+ 'domain',
207
+ 'yes',
208
+ 'json',
209
+ 'dry-run',
210
+ ],
211
+ 'cloudflare deploy': [
212
+ 'prebuilt',
213
+ 'worker-name',
214
+ 'config',
215
+ 'environment',
216
+ 'deployment-id',
217
+ 'inventory',
218
+ 'out',
219
+ 'jurisdiction',
220
+ 'rollout',
221
+ 'public-url',
222
+ 'routes',
223
+ 'domain',
224
+ 'secret',
225
+ 'secrets',
226
+ 'allow-contract',
227
+ 'json',
228
+ 'dry-run',
229
+ ],
230
+ 'cloudflare smoke': [
231
+ 'worker-name',
232
+ 'config',
233
+ 'environment',
234
+ 'deployment-id',
235
+ 'inventory',
236
+ 'out',
237
+ 'jurisdiction',
238
+ 'public-url',
239
+ 'project',
240
+ 'smoke-token-env',
241
+ 'deadline-seconds',
242
+ 'no-rollback',
243
+ 'json',
244
+ 'dry-run',
245
+ ],
246
+ 'cloudflare migrate': [
247
+ 'prebuilt',
248
+ 'database-id',
249
+ 'out',
250
+ 'dry-run',
251
+ 'json',
252
+ 'worker-name',
253
+ 'config',
254
+ 'environment',
255
+ 'deployment-id',
256
+ 'inventory',
257
+ 'jurisdiction',
258
+ 'allow-contract',
259
+ ],
260
+ 'cloudflare bootstrap': ['database-id', 'slug', 'name'],
261
+ 'cloudflare teardown': [
262
+ 'inventory',
263
+ 'inventory-id',
264
+ 'i-understand-this-deletes',
265
+ 'config',
266
+ 'project',
267
+ 'out',
268
+ 'json',
269
+ 'dry-run',
270
+ ],
271
+ 'cloudflare janitor': [
272
+ 'repository-id',
273
+ 'inventory',
274
+ 'config',
275
+ 'project',
276
+ 'out',
277
+ 'json',
278
+ 'dry-run',
279
+ ],
280
+ 'secrets generate-master-key': ['key-version'],
281
+ 'admin bootstrap': ['email', 'sqlite', 'cloudflare', 'database-id', 'token-file'],
282
+ 'admin reset-local': ['email', 'sqlite', 'cloudflare', 'database-id', 'token-file'],
283
+ 'admin rebind-provider': [
284
+ 'provider',
285
+ 'confirm',
286
+ 'expected-anchor',
287
+ 'new-anchor',
288
+ 'sqlite',
289
+ 'cloudflare',
290
+ 'database-id',
291
+ ],
292
+ 'admin show-provider-binding': ['provider', 'sqlite', 'cloudflare', 'database-id'],
293
+ 'import cutover-check': [
294
+ 'project-dir',
295
+ 'old-repository',
296
+ 'new-repository',
297
+ 'old-auth-env',
298
+ 'new-auth-env',
299
+ 'timeout-seconds',
300
+ 'lock',
301
+ 'json',
302
+ ],
303
+ 'import satis plan': [
304
+ 'config',
305
+ 'out',
306
+ 'project',
307
+ 'credentials',
308
+ 'repository-map',
309
+ 'baseline',
310
+ 'mode',
311
+ ],
312
+ 'import private-packagist plan': [
313
+ 'snapshot',
314
+ 'map',
315
+ 'out',
316
+ 'credentials-out',
317
+ 'members',
318
+ 'baseline',
319
+ 'mode',
320
+ 'include-org-admins',
321
+ 'runtime',
322
+ 'packagist',
323
+ 'compact-selection',
324
+ 'compact-vendor',
325
+ 'accept-project-widening',
326
+ 'quiet',
327
+ ],
328
+ 'import private-packagist fetch': [
329
+ 'org',
330
+ 'snapshot',
331
+ 'api-key-file',
332
+ 'api-secret-file',
333
+ 'versions',
334
+ 'require-org-match',
335
+ ],
336
+ 'import private-packagist dates': ['snapshot', 'map', 'baseline', 'out', 'package', 'quiet'],
337
+ 'import submit': ['manifest', 'receipt', 'principal', 'broker', 'resume', 'token-file'],
338
+ 'import status': ['broker', 'token-file', 'wait', 'wait-seconds'],
339
+ 'import credentials': ['broker', 'token-file', 'manifest', 'credentials'],
340
+ 'import verify': ['broker', 'token-file', 'wait', 'wait-seconds'],
341
+ 'import accept': ['broker', 'token-file', 'wait', 'wait-seconds'],
342
+ 'source accept-removal': ['url', 'source'],
343
+ openapi: ['out'],
344
+ version: [],
345
+ };
346
+ function acceptsInvocation(positionals, flags) {
347
+ const isImportRun = positionals[0] === 'import' &&
348
+ ['status', 'credentials', 'verify', 'accept'].includes(positionals[1] ?? '');
349
+ if (isImportRun && positionals.length !== 3)
350
+ return false;
351
+ const allowed = ALLOWED_FLAGS[(isImportRun ? positionals.slice(0, 2) : positionals).join(' ')];
352
+ return allowed !== undefined && flags.every((flag) => allowed.includes(flag));
353
+ }
354
+ function adminTarget(values) {
355
+ const databaseId = values['database-id'];
356
+ if (values.sqlite !== undefined && values.cloudflare !== true && databaseId === undefined) {
357
+ return { kind: 'sqlite', file: values.sqlite };
358
+ }
359
+ if (values.sqlite === undefined && values.cloudflare === true && databaseId !== undefined) {
360
+ return { kind: 'cloudflare', databaseId, env: process.env };
361
+ }
362
+ return null;
363
+ }
364
+ export async function run(argv) {
365
+ if (argv.includes('--help') || argv.includes('-h')) {
366
+ console.log(USAGE);
367
+ return 0;
368
+ }
369
+ const parsed = parseCliArgs([...argv]);
370
+ const usageError = () => {
371
+ const cloudflareIndex = argv.findIndex((value, index) => value === 'cloudflare' &&
372
+ ['setup', 'provision', 'migrate', 'deploy', 'smoke', 'teardown', 'janitor'].includes(argv[index + 1] ?? ''));
373
+ if (cloudflareIndex >= 0 && argv.includes('--json')) {
374
+ console.log(JSON.stringify(failCommand(commandEnvelope(argv[cloudflareIndex + 1], argv.includes('--dry-run')), new CloudflareError('invalid_input', 2, false, argv[cloudflareIndex + 1])).output));
375
+ }
376
+ else
377
+ console.error(USAGE);
378
+ return 2;
379
+ };
380
+ if (parsed === null)
381
+ return usageError();
382
+ const { positionals, values } = parsed;
383
+ if (!acceptsInvocation(positionals, Object.keys(values))) {
384
+ return usageError();
385
+ }
386
+ const [command, subcommand] = positionals;
387
+ if (command === 'cloudflare' && values.prebuilt) {
388
+ try {
389
+ await assertPrebuiltConfiguration(process.cwd(), values.config);
390
+ }
391
+ catch (error) {
392
+ const result = failCommand(commandEnvelope(subcommand, values['dry-run']), error);
393
+ if (values.json)
394
+ console.log(JSON.stringify(result.output));
395
+ else
396
+ console.error(result.output.error?.message);
397
+ return result.exitCode;
398
+ }
399
+ }
400
+ if (command === 'cloudflare' && (subcommand === 'teardown' || subcommand === 'janitor')) {
401
+ const options = {
402
+ env: process.env,
403
+ ...(values.config === undefined ? {} : { configPath: values.config }),
404
+ ...(values.project === undefined ? {} : { project: values.project }),
405
+ ...(values.out === undefined ? {} : { outDir: values.out }),
406
+ dryRun: values['dry-run'] ?? false,
407
+ json: values.json ?? false,
408
+ };
409
+ if (subcommand === 'teardown') {
410
+ if (!values.inventory)
411
+ return usageError();
412
+ return runCloudflareTeardown({
413
+ ...options,
414
+ inventory: values.inventory,
415
+ ...(values['inventory-id'] === undefined ? {} : { inventoryId: values['inventory-id'] }),
416
+ iUnderstandThisDeletes: values['i-understand-this-deletes'] ?? false,
417
+ });
418
+ }
419
+ if (!values['repository-id'])
420
+ return usageError();
421
+ return runCloudflareJanitor({
422
+ ...options,
423
+ repositoryId: values['repository-id'],
424
+ ...(values.inventory === undefined ? {} : { inventory: values.inventory }),
425
+ });
426
+ }
427
+ if (command === 'source' && subcommand === 'accept-removal') {
428
+ if (!values.url || !values.source)
429
+ return usageError();
430
+ return runSourceAcceptRemoval({
431
+ url: values.url,
432
+ source: values.source,
433
+ env: process.env,
434
+ });
435
+ }
436
+ if (command === 'openapi')
437
+ return runOpenApi(values.out);
438
+ if (command === 'import' &&
439
+ ['submit', 'status', 'credentials', 'verify', 'accept'].includes(subcommand ?? '')) {
440
+ if (!values.broker ||
441
+ (values.wait === true && values['wait-seconds'] !== undefined) ||
442
+ (values['wait-seconds'] !== undefined &&
443
+ !/^(?:0|[1-9][0-9]?|[12][0-9]{2}|300)$/.test(values['wait-seconds'])))
444
+ return usageError();
445
+ return runImport({
446
+ command: subcommand,
447
+ broker: values.broker,
448
+ env: process.env,
449
+ ...(positionals[2] === undefined ? {} : { run: positionals[2] }),
450
+ ...(values.manifest === undefined ? {} : { manifest: values.manifest }),
451
+ ...(values.credentials === undefined ? {} : { credentials: values.credentials }),
452
+ ...(values.receipt === undefined ? {} : { receipt: values.receipt }),
453
+ ...(values.principal === undefined ? {} : { principal: values.principal }),
454
+ ...(values.resume === undefined ? {} : { resume: values.resume }),
455
+ ...(values['token-file'] === undefined ? {} : { tokenFile: values['token-file'] }),
456
+ ...(values['wait-seconds'] === undefined
457
+ ? values.wait
458
+ ? { waitSeconds: 300 }
459
+ : {}
460
+ : { waitSeconds: Number(values['wait-seconds']) }),
461
+ });
462
+ }
463
+ if (command === 'import' && subcommand === 'cutover-check') {
464
+ if (!values['project-dir'] ||
465
+ !values['old-repository'] ||
466
+ !values['new-repository'] ||
467
+ !values['old-auth-env'] ||
468
+ !values['new-auth-env'] ||
469
+ (values['timeout-seconds'] !== undefined && !/^\d+$/.test(values['timeout-seconds'])))
470
+ return usageError();
471
+ return runImportCutover({
472
+ projectDir: values['project-dir'],
473
+ oldRepository: values['old-repository'],
474
+ newRepository: values['new-repository'],
475
+ oldAuthEnv: values['old-auth-env'],
476
+ newAuthEnv: values['new-auth-env'],
477
+ historicLocks: values.lock ?? [],
478
+ timeoutSeconds: values['timeout-seconds'] === undefined ? 1800 : Number(values['timeout-seconds']),
479
+ json: values.json ?? false,
480
+ });
481
+ }
482
+ if (command === 'import' && subcommand === 'private-packagist') {
483
+ if (positionals[2] === 'dates') {
484
+ if (!values.snapshot || !values.map || !values.baseline || !values.out)
485
+ return usageError();
486
+ return runImportPrivatePackagistDates({
487
+ snapshot: values.snapshot,
488
+ map: values.map,
489
+ baseline: values.baseline,
490
+ out: values.out,
491
+ packages: values.package ?? [],
492
+ quiet: values.quiet ?? false,
493
+ });
494
+ }
495
+ if (positionals[2] === 'plan') {
496
+ if (!values.snapshot ||
497
+ !values.map ||
498
+ !values.out ||
499
+ !values['credentials-out'] ||
500
+ (values.mode !== undefined && values.mode !== 'merge' && values.mode !== 'override') ||
501
+ (values.runtime !== undefined && values.runtime !== 'workers' && values.runtime !== 'node'))
502
+ return usageError();
503
+ return runImportPrivatePackagistPlan({
504
+ snapshot: values.snapshot,
505
+ map: values.map,
506
+ out: values.out,
507
+ credentialsOut: values['credentials-out'],
508
+ ...(values.members === undefined ? {} : { members: values.members }),
509
+ ...(values.baseline === undefined ? {} : { baseline: values.baseline }),
510
+ ...(values.mode === undefined ? {} : { mode: values.mode }),
511
+ ...(values.runtime === undefined ? {} : { runtime: values.runtime }),
512
+ ...(values.packagist === undefined ? {} : { packagist: values.packagist }),
513
+ includeOrgAdmins: values['include-org-admins'] ?? false,
514
+ compactSelection: values['compact-selection'] ?? false,
515
+ compactVendors: values['compact-vendor'] ?? [],
516
+ acceptProjectWidening: values['accept-project-widening'] ?? [],
517
+ quiet: values.quiet ?? false,
518
+ });
519
+ }
520
+ if (!values.org || !values.snapshot)
521
+ return usageError();
522
+ return runImportPrivatePackagistFetch({
523
+ org: values.org,
524
+ snapshot: values.snapshot,
525
+ env: process.env,
526
+ ...(values['api-key-file'] === undefined ? {} : { apiKeyFile: values['api-key-file'] }),
527
+ ...(values['api-secret-file'] === undefined
528
+ ? {}
529
+ : { apiSecretFile: values['api-secret-file'] }),
530
+ versions: values.versions ?? false,
531
+ requireOrgMatch: values['require-org-match'] ?? false,
532
+ });
533
+ }
534
+ if (command === 'import' && subcommand === 'satis') {
535
+ const { config, out, mode } = values;
536
+ if (config === undefined ||
537
+ out === undefined ||
538
+ (mode !== undefined && mode !== 'merge' && mode !== 'override')) {
539
+ return usageError();
540
+ }
541
+ return runImportSatisPlan({
542
+ config,
543
+ out,
544
+ ...(values.project === undefined ? {} : { project: values.project }),
545
+ ...(values.credentials === undefined ? {} : { credentials: values.credentials }),
546
+ ...(values['repository-map'] === undefined
547
+ ? {}
548
+ : { repositoryMap: values['repository-map'] }),
549
+ ...(values.baseline === undefined ? {} : { baseline: values.baseline }),
550
+ ...(mode === undefined ? {} : { mode }),
551
+ });
552
+ }
553
+ if (command === 'cloudflare' && subcommand === 'setup') {
554
+ if ((values.migrate !== undefined && !['true', 'false'].includes(values.migrate)) ||
555
+ (values.jurisdiction !== undefined && !['eu', 'default'].includes(values.jurisdiction)))
556
+ return usageError();
557
+ return runCloudflareSetup({
558
+ prebuilt: values.prebuilt ?? false,
559
+ workerName: values['worker-name'] ?? '',
560
+ env: process.env,
561
+ ...(values.config === undefined ? {} : { configPath: values.config }),
562
+ ...(values.out === undefined ? {} : { outDir: values.out }),
563
+ ...(values.environment === undefined ? {} : { environment: values.environment }),
564
+ ...(values['deployment-id'] === undefined ? {} : { deploymentId: values['deployment-id'] }),
565
+ ...(values.inventory === undefined ? {} : { inventory: values.inventory }),
566
+ ...(values.jurisdiction === undefined
567
+ ? {}
568
+ : { jurisdiction: values.jurisdiction }),
569
+ ...(values['location-hint'] === undefined ? {} : { locationHint: values['location-hint'] }),
570
+ ...(values['adopt-resource'] === undefined
571
+ ? {}
572
+ : { adoptResource: values['adopt-resource'] }),
573
+ ...(values['abandon-intent'] === undefined
574
+ ? {}
575
+ : { abandonIntent: values['abandon-intent'] }),
576
+ ...(values.domain === undefined ? {} : { domain: values.domain }),
577
+ ...(values['public-url'] === undefined ? {} : { publicUrl: values['public-url'] }),
578
+ ...(values.routes === undefined ? {} : { routes: values.routes }),
579
+ ...(values.rollout === undefined ? {} : { rollout: Number(values.rollout) }),
580
+ ...(values['allow-contract'] === undefined
581
+ ? {}
582
+ : { allowContract: values['allow-contract'] }),
583
+ ...(values.secret === undefined ? {} : { secret: values.secret }),
584
+ ...(values.secrets === undefined ? {} : { secrets: values.secrets }),
585
+ ...(values['org-slug'] === undefined ? {} : { orgSlug: values['org-slug'] }),
586
+ ...(values['org-name'] === undefined ? {} : { orgName: values['org-name'] }),
587
+ ...(values['admin-email'] === undefined ? {} : { adminEmail: values['admin-email'] }),
588
+ ...(values['key-file'] === undefined ? {} : { keyFile: values['key-file'] }),
589
+ ...(values['master-key-env'] === undefined ? {} : { masterKeyEnv: values['master-key-env'] }),
590
+ ...(values['token-file'] === undefined ? {} : { tokenFile: values['token-file'] }),
591
+ ...(values.project === undefined ? {} : { smokeProject: values.project }),
592
+ ...(values['smoke-token-env'] === undefined
593
+ ? {}
594
+ : { smokeTokenEnv: values['smoke-token-env'] }),
595
+ ...(values['deadline-seconds'] === undefined
596
+ ? {}
597
+ : { deadlineSeconds: Number(values['deadline-seconds']) }),
598
+ migrate: values.migrate !== 'false',
599
+ nonInteractive: values['non-interactive'] ?? false,
600
+ refreshSetupToken: values['refresh-setup-token'] ?? false,
601
+ yes: values.yes ?? false,
602
+ json: values.json ?? false,
603
+ dryRun: values['dry-run'] ?? false,
604
+ });
605
+ }
606
+ if (command === 'cloudflare' && subcommand === 'smoke') {
607
+ if (!values['worker-name'] ||
608
+ (values.jurisdiction !== undefined && !['eu', 'default'].includes(values.jurisdiction)) ||
609
+ (values['deadline-seconds'] !== undefined &&
610
+ !/^(?:[1-9]|[1-9][0-9]|[12][0-9]{2}|300)$/.test(values['deadline-seconds'])))
611
+ return usageError();
612
+ return runCloudflareSmoke({
613
+ workerName: values['worker-name'],
614
+ env: process.env,
615
+ ...(values.config === undefined ? {} : { configPath: values.config }),
616
+ ...(values.out === undefined ? {} : { outDir: values.out }),
617
+ ...(values.environment === undefined ? {} : { environment: values.environment }),
618
+ ...(values['deployment-id'] === undefined ? {} : { deploymentId: values['deployment-id'] }),
619
+ ...(values.inventory === undefined ? {} : { inventory: values.inventory }),
620
+ ...(values.jurisdiction === undefined
621
+ ? {}
622
+ : { jurisdiction: values.jurisdiction }),
623
+ ...(values['public-url'] === undefined ? {} : { publicUrl: values['public-url'] }),
624
+ ...(values.project === undefined ? {} : { project: values.project }),
625
+ ...(values['smoke-token-env'] === undefined
626
+ ? {}
627
+ : { smokeTokenEnv: values['smoke-token-env'] }),
628
+ ...(values['deadline-seconds'] === undefined
629
+ ? {}
630
+ : { deadlineSeconds: Number(values['deadline-seconds']) }),
631
+ noRollback: values['no-rollback'] ?? false,
632
+ json: values.json ?? false,
633
+ dryRun: values['dry-run'] ?? false,
634
+ });
635
+ }
636
+ if (command === 'cloudflare' && subcommand === 'deploy') {
637
+ if (!values['worker-name'] ||
638
+ (values.jurisdiction !== undefined && !['eu', 'default'].includes(values.jurisdiction)) ||
639
+ (values.rollout !== undefined && !/^(?:[1-9]|[1-9][0-9]|100)$/.test(values.rollout)))
640
+ return usageError();
641
+ return runCloudflareDeploy({
642
+ prebuilt: values.prebuilt ?? false,
643
+ workerName: values['worker-name'],
644
+ env: process.env,
645
+ ...(values.config === undefined ? {} : { configPath: values.config }),
646
+ ...(values.out === undefined ? {} : { outDir: values.out }),
647
+ ...(values.environment === undefined ? {} : { environment: values.environment }),
648
+ ...(values['deployment-id'] === undefined ? {} : { deploymentId: values['deployment-id'] }),
649
+ ...(values.inventory === undefined ? {} : { inventory: values.inventory }),
650
+ ...(values.jurisdiction === undefined
651
+ ? {}
652
+ : { jurisdiction: values.jurisdiction }),
653
+ ...(values.rollout === undefined ? {} : { rollout: Number(values.rollout) }),
654
+ ...(values['public-url'] === undefined ? {} : { publicUrl: values['public-url'] }),
655
+ ...(values.domain === undefined ? {} : { domain: values.domain }),
656
+ ...(values.routes === undefined ? {} : { routes: values.routes }),
657
+ ...(values.secret === undefined ? {} : { secret: values.secret }),
658
+ ...(values.secrets === undefined ? {} : { secrets: values.secrets }),
659
+ ...(values['allow-contract'] === undefined
660
+ ? {}
661
+ : { allowContract: values['allow-contract'] }),
662
+ json: values.json ?? false,
663
+ dryRun: values['dry-run'] ?? false,
664
+ });
665
+ }
666
+ if (command === 'cloudflare' && subcommand === 'provision') {
667
+ if (!values['worker-name'] ||
668
+ (values.jurisdiction !== undefined && !['eu', 'default'].includes(values.jurisdiction)))
669
+ return usageError();
670
+ return runCloudflareProvision({
671
+ prebuilt: values.prebuilt ?? false,
672
+ workerName: values['worker-name'],
673
+ env: process.env,
674
+ ...(values.config === undefined ? {} : { configPath: values.config }),
675
+ ...(values.out === undefined ? {} : { outDir: values.out }),
676
+ ...(values.environment === undefined ? {} : { environment: values.environment }),
677
+ ...(values['deployment-id'] === undefined ? {} : { deploymentId: values['deployment-id'] }),
678
+ ...(values.inventory === undefined ? {} : { inventory: values.inventory }),
679
+ ...(values.jurisdiction === undefined
680
+ ? {}
681
+ : { jurisdiction: values.jurisdiction }),
682
+ ...(values['location-hint'] === undefined ? {} : { locationHint: values['location-hint'] }),
683
+ ...(values['adopt-resource'] === undefined
684
+ ? {}
685
+ : { adoptResource: values['adopt-resource'] }),
686
+ ...(values['abandon-intent'] === undefined
687
+ ? {}
688
+ : { abandonIntent: values['abandon-intent'] }),
689
+ ...(values.domain === undefined ? {} : { domain: values.domain }),
690
+ yes: values.yes ?? false,
691
+ json: values.json ?? false,
692
+ dryRun: values['dry-run'] ?? false,
693
+ });
694
+ }
695
+ if (command === 'cloudflare') {
696
+ if (subcommand === 'migrate' && (values['database-id'] || values['worker-name'])) {
697
+ if (values.jurisdiction !== undefined && !['eu', 'default'].includes(values.jurisdiction))
698
+ return usageError();
699
+ return runCloudflareMigrate({
700
+ prebuilt: values.prebuilt ?? false,
701
+ ...(values['database-id'] === undefined ? {} : { databaseId: values['database-id'] }),
702
+ ...(values['worker-name'] === undefined ? {} : { workerName: values['worker-name'] }),
703
+ ...(values.config === undefined ? {} : { configPath: values.config }),
704
+ ...(values.environment === undefined ? {} : { environment: values.environment }),
705
+ ...(values['deployment-id'] === undefined ? {} : { deploymentId: values['deployment-id'] }),
706
+ ...(values.inventory === undefined ? {} : { inventory: values.inventory }),
707
+ ...(values.jurisdiction === undefined
708
+ ? {}
709
+ : { jurisdiction: values.jurisdiction }),
710
+ ...(values['allow-contract'] === undefined
711
+ ? {}
712
+ : { allowContract: values['allow-contract'] }),
713
+ json: values.json ?? false,
714
+ outDir: values.out || (values.prebuilt ? '.pb/prebuilt/cloudflare' : '.pb/cloudflare'),
715
+ dryRun: values['dry-run'] ?? false,
716
+ env: process.env,
717
+ });
718
+ }
719
+ if (subcommand === 'bootstrap' && values['database-id'] && values.slug && values.name) {
720
+ return runCloudflareBootstrap({
721
+ databaseId: values['database-id'],
722
+ slug: values.slug,
723
+ name: values.name,
724
+ env: process.env,
725
+ });
726
+ }
727
+ }
728
+ if (command === 'secrets' && subcommand === 'generate-master-key') {
729
+ return runGenerateMasterKey({ keyVersion: values['key-version'] });
730
+ }
731
+ if (command === 'admin' && (subcommand === 'bootstrap' || subcommand === 'reset-local')) {
732
+ const target = adminTarget(values);
733
+ if (values.email !== undefined && target !== null) {
734
+ const options = { email: values.email, target, tokenFile: values['token-file'] };
735
+ return subcommand === 'bootstrap' ? runAdminBootstrap(options) : runAdminResetLocal(options);
736
+ }
737
+ }
738
+ if (command === 'admin' && subcommand === 'rebind-provider') {
739
+ const target = adminTarget(values);
740
+ const { provider, confirm } = values;
741
+ const expectedAnchor = values['expected-anchor'];
742
+ const newAnchor = values['new-anchor'];
743
+ if (target !== null &&
744
+ provider !== undefined &&
745
+ confirm !== undefined &&
746
+ expectedAnchor !== undefined &&
747
+ newAnchor !== undefined) {
748
+ return runAdminRebindProvider({ provider, confirm, expectedAnchor, newAnchor, target });
749
+ }
750
+ }
751
+ if (command === 'admin' && subcommand === 'show-provider-binding') {
752
+ const target = adminTarget(values);
753
+ const { provider } = values;
754
+ if (target !== null && provider !== undefined) {
755
+ return runAdminShowProviderBinding({ provider, target });
756
+ }
757
+ }
758
+ if (command === 'migrate' && values.sqlite) {
759
+ return runMigrateSqlite({
760
+ file: values.sqlite,
761
+ outDir: values.out || '.pb/node',
762
+ dryRun: values['dry-run'] ?? false,
763
+ });
764
+ }
765
+ if (command === 'bootstrap' && values.sqlite && values.slug && values.name) {
766
+ return runBootstrapSqlite({ file: values.sqlite, slug: values.slug, name: values.name });
767
+ }
768
+ if (command === 'version') {
769
+ const pkg = createRequire(import.meta.url)('../package.json');
770
+ console.log(pkg.version);
771
+ return 0;
772
+ }
773
+ if (command === 'build') {
774
+ const target = values.target;
775
+ if (target !== undefined && target !== 'cloudflare' && target !== 'node') {
776
+ console.error(`unknown target "${target}"`);
777
+ return 2;
778
+ }
779
+ let result;
780
+ try {
781
+ result = await build({
782
+ configPath: values.config ?? 'broker.config.ts',
783
+ ...(target === undefined ? {} : { target: target }),
784
+ ...(values.out === undefined ? {} : { outDir: values.out }),
785
+ });
786
+ }
787
+ catch (error) {
788
+ if (!(error instanceof BuildDiagnosticsError))
789
+ throw error;
790
+ for (const problem of error.problems) {
791
+ console.error(`error: ${problem}`.replace(/[\r\n]+/g, ' '));
792
+ }
793
+ return 2;
794
+ }
795
+ console.log(`manifest: ${result.manifestJson}`);
796
+ console.log(`bundle: ${result.bundle}`);
797
+ return 0;
798
+ }
799
+ return usageError();
800
+ }
801
+ //# sourceMappingURL=cli.js.map