@fabrika/cli 0.5.2 → 0.5.3

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 (2) hide show
  1. package/package.json +12 -12
  2. package/src/control.ts +43 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabrika/cli",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -30,19 +30,19 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "zod": "^3.25.76",
33
- "@fabrika/app": "0.5.2",
34
- "@fabrika/auth-core": "0.5.2",
35
- "@fabrika/control-contract": "0.5.2",
36
- "@fabrika/provider-contract": "0.5.2",
37
- "@fabrika/db": "0.5.2",
38
- "@fabrika/platform": "0.5.2",
39
- "@fabrika/platform-node": "0.5.2",
40
- "@fabrika/check": "0.5.2"
33
+ "@fabrika/app": "0.5.3",
34
+ "@fabrika/auth-core": "0.5.3",
35
+ "@fabrika/control-contract": "0.5.3",
36
+ "@fabrika/provider-contract": "0.5.3",
37
+ "@fabrika/db": "0.5.3",
38
+ "@fabrika/platform": "0.5.3",
39
+ "@fabrika/platform-node": "0.5.3",
40
+ "@fabrika/check": "0.5.3"
41
41
  },
42
42
  "peerDependencies": {
43
- "@fabrika/builder": "0.5.2",
44
- "@fabrika/provider-cloudflare": "0.5.2",
45
- "@fabrika/provider-zerops": "0.5.2"
43
+ "@fabrika/builder": "0.5.3",
44
+ "@fabrika/provider-cloudflare": "0.5.3",
45
+ "@fabrika/provider-zerops": "0.5.3"
46
46
  },
47
47
  "peerDependenciesMeta": {
48
48
  "@fabrika/builder": {
package/src/control.ts CHANGED
@@ -13,6 +13,7 @@ import { createRpcClient, type InferRpcClient, RpcError } from '@fabrika/app'
13
13
  import { type IssueKeyInput, type IssueKeyResult, MAX_KEY_LIFETIME_SECONDS } from '@fabrika/auth-core'
14
14
  import type {
15
15
  AppDto,
16
+ AppEnvDto,
16
17
  AppSecretDto,
17
18
  ControlRpcContract,
18
19
  DeploymentNamespaceDetailDto,
@@ -55,6 +56,7 @@ Usage:
55
56
  fabrika control apps environments list --app=<id>
56
57
  fabrika control apps environments put --provider=<name> --app=<id> --env=<name> --manifest=<path>
57
58
  [--domain=<host>] [--public-origin=<url>] [--trigger-ref=<ref>] [--namespace=<id>]
59
+ [--cross-origin=<origin> ...]
58
60
  fabrika control apps variables list --app=<id>
59
61
  fabrika control apps variables put --app=<id> --name=<name> --value=<text> [--env=<name>]
60
62
  fabrika control apps variables delete --app=<id> --name=<name> [--env=<name>]
@@ -63,7 +65,7 @@ Usage:
63
65
  fabrika control apps secrets delete --app=<id> --name=<name> [--env=<name>]
64
66
  fabrika control register --provider=<name> --app=<id> --repo=<url> --env=<name> --manifest=<path>
65
67
  [--domain=<host>] [--public-origin=<url>] [--trigger-ref=<ref>]
66
- [--namespace=<id>] [--installation-id=<n|none>]
68
+ [--namespace=<id>] [--installation-id=<n|none>] [--cross-origin=<origin> ...]
67
69
  fabrika control namespaces list
68
70
  fabrika control namespaces get --namespace=<id>
69
71
  fabrika control namespaces plan --namespace=<id> --env=<name> --preset=<cheap|mid|full> [placement]
@@ -97,6 +99,13 @@ storage only. Generate one in the pipe:
97
99
  refused. When \`register\` is given none and the namespace lists \`--domain\` among its hosts, it sets
98
100
  \`https://<domain>\` and says so on stderr. A custom domain needs the flag.
99
101
 
102
+ \`--cross-origin\` names an origin whose pages may call the environment's cross-origin endpoints (ADR-0022), and
103
+ repeats: the flags given are the environment's whole list. Each is an exact origin with a literal host
104
+ (\`https://app.example.com\`; \`http://\` only for a local one), never the environment's own domain, at most 16.
105
+ \`apps environments put\` without the flag keeps the stored list, and a lone empty \`--cross-origin=\` clears it.
106
+ On Zerops the change reaches the namespace proxy at once; on Cloudflare the next deploy of the environment
107
+ applies it.
108
+
100
109
  \`--installation-id\` has three states: omitted resolves the installation from the organization's
101
110
  connected GitHub App, \`none\` registers an anonymous PUBLIC repository source, and a number names one
102
111
  installation outright. With \`none\`, control reads the repository once without a token and refuses one
@@ -162,6 +171,8 @@ const DEFAULT_CONTROL_APP_ID = 'vozka'
162
171
 
163
172
  interface Flags {
164
173
  readonly values: ReadonlyMap<string, string>
174
+ /** Every value of every option, in order; `values` keeps the last. Only a repeatable option reads it. */
175
+ readonly repeated: ReadonlyMap<string, readonly string[]>
165
176
  readonly json: boolean
166
177
  readonly positional: readonly string[]
167
178
  }
@@ -169,6 +180,7 @@ interface Flags {
169
180
  /** Split `--key=value` options from positional words; `--json` is the one flag every verb shares. */
170
181
  export const parseControlFlags = (argv: readonly string[]): Flags => {
171
182
  const values = new Map<string, string>()
183
+ const repeated = new Map<string, string[]>()
172
184
  const positional: string[] = []
173
185
  let json = false
174
186
  for (const arg of argv) {
@@ -179,12 +191,15 @@ export const parseControlFlags = (argv: readonly string[]): Flags => {
179
191
  if (eq === -1) {
180
192
  throw new Error(`Option ${arg} needs a value: ${arg}=<value>`)
181
193
  }
182
- values.set(arg.slice(2, eq), arg.slice(eq + 1))
194
+ const name = arg.slice(2, eq)
195
+ const value = arg.slice(eq + 1)
196
+ values.set(name, value)
197
+ repeated.set(name, [...(repeated.get(name) ?? []), value])
183
198
  } else {
184
199
  positional.push(arg)
185
200
  }
186
201
  }
187
- return { values, json, positional }
202
+ return { values, repeated, json, positional }
188
203
  }
189
204
 
190
205
  const required = (flags: Flags, name: string): string => {
@@ -200,6 +215,20 @@ const optional = (flags: Flags, name: string): string | undefined => {
200
215
  return value === undefined || value === '' ? undefined : value
201
216
  }
202
217
 
218
+ /**
219
+ * `--cross-origin=<origin>`, repeatable: the environment's whole list. Omitted keeps the stored list on
220
+ * `apps environments put`; a lone empty `--cross-origin=` sends an empty list, which clears it.
221
+ */
222
+ const crossOrigins = (flags: Flags): string[] | undefined => {
223
+ const given = flags.repeated.get('cross-origin')
224
+ if (given === undefined) return undefined
225
+ if (given.length === 1 && given[0] === '') return []
226
+ if (given.includes('')) {
227
+ throw new Error('An empty --cross-origin= clears the list and takes no other --cross-origin')
228
+ }
229
+ return [...given]
230
+ }
231
+
203
232
  const positiveInteger = (raw: string, name: string): number => {
204
233
  const parsed = Number(raw)
205
234
  if (!Number.isSafeInteger(parsed) || parsed <= 0) {
@@ -386,6 +415,7 @@ const registrationInputs = (flags: Flags): RegistrationInputs => {
386
415
  const anonymousSource = installationId === 'none'
387
416
  const domain = optional(flags, 'domain')
388
417
  const publicOrigin = optional(flags, 'public-origin')
418
+ const origins = crossOrigins(flags)
389
419
  const triggerRef = optional(flags, 'trigger-ref')
390
420
  const namespaceId = optional(flags, 'namespace')
391
421
  return {
@@ -400,6 +430,7 @@ const registrationInputs = (flags: Flags): RegistrationInputs => {
400
430
  : { githubInstallationId: positiveInteger(installationId, 'installation-id') }),
401
431
  ...(domain === undefined ? {} : { domain }),
402
432
  ...(publicOrigin === undefined ? {} : { publicOrigin }),
433
+ ...(origins === undefined ? {} : { crossOrigins: origins }),
403
434
  ...(triggerRef === undefined ? {} : { triggerRef }),
404
435
  ...(namespaceId === undefined ? {} : { namespaceId }),
405
436
  }
@@ -531,7 +562,7 @@ const runEnvironments = async (
531
562
  if (verb === 'list') {
532
563
  const appId = required(flags, 'app')
533
564
  const result = await client.apps.environments.list({ appId })
534
- emitList(flags, result, (item) => `${item.appId}\t${item.env}\t${item.provider}\t${item.domain ?? '-'}`, `app ${appId} has no environments`)
565
+ emitList(flags, result, environmentLine, `app ${appId} has no environments`)
535
566
  return
536
567
  }
537
568
  if (verb === 'put') {
@@ -543,6 +574,7 @@ const runEnvironments = async (
543
574
  const version = manifestVersion(manifest, manifestPath)
544
575
  const domain = optional(flags, 'domain')
545
576
  const publicOrigin = optional(flags, 'public-origin')
577
+ const origins = crossOrigins(flags)
546
578
  const triggerRef = optional(flags, 'trigger-ref')
547
579
  const namespaceId = optional(flags, 'namespace')
548
580
  const environment: PutAppEnvRequest = {
@@ -551,6 +583,7 @@ const runEnvironments = async (
551
583
  artifact: { provider, version, payload: manifest },
552
584
  ...(domain === undefined ? {} : { domain }),
553
585
  ...(publicOrigin === undefined ? {} : { publicOrigin }),
586
+ ...(origins === undefined ? {} : { crossOrigins: origins }),
554
587
  ...(triggerRef === undefined ? {} : { triggerRef }),
555
588
  ...(namespaceId === undefined ? {} : { namespaceId }),
556
589
  }
@@ -561,6 +594,12 @@ const runEnvironments = async (
561
594
  throw new Error(`Unknown \`control apps environments\` verb: ${verb ?? '(missing)'}`)
562
595
  }
563
596
 
597
+ /** One environment per line; the cross origins are comma-joined, `-` when it lists none (a Control older than the field included). */
598
+ export const environmentLine = (item: Pick<AppEnvDto, 'appId' | 'env' | 'provider' | 'domain'> & Partial<Pick<AppEnvDto, 'crossOrigins'>>): string =>
599
+ `${item.appId}\t${item.env}\t${item.provider}\t${item.domain ?? '-'}\t${
600
+ item.crossOrigins === undefined || item.crossOrigins.length === 0 ? '-' : item.crossOrigins.join(',')
601
+ }`
602
+
564
603
  /**
565
604
  * A variable is NOT a secret: its value is stored and read back in clear, so it takes a flag. The one
566
605
  * thing an app cannot commit and fabrika cannot infer — an installation's IAM issuer, say — is written