@fabrika/cli 0.0.24 → 0.0.26

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabrika/cli",
3
- "version": "0.0.24",
3
+ "version": "0.0.26",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,14 +29,14 @@
29
29
  "test": "bun test"
30
30
  },
31
31
  "dependencies": {
32
- "@fabrika/app": "^0.0.24",
33
- "@fabrika/auth-core": "^0.0.24",
34
- "@fabrika/control-contract": "^0.0.24",
35
- "@fabrika/installation-cloudflare": "^0.0.24",
36
- "@fabrika/installation-contract": "^0.0.24",
37
- "@fabrika/installation-zerops": "^0.0.24",
38
- "@fabrika/provider-cloudflare": "^0.0.24",
39
- "@fabrika/provider-contract": "^0.0.24",
40
- "@fabrika/provider-zerops": "^0.0.24"
32
+ "@fabrika/app": "^0.0.26",
33
+ "@fabrika/auth-core": "^0.0.26",
34
+ "@fabrika/control-contract": "^0.0.26",
35
+ "@fabrika/installation-cloudflare": "^0.0.26",
36
+ "@fabrika/installation-contract": "^0.0.26",
37
+ "@fabrika/installation-zerops": "^0.0.26",
38
+ "@fabrika/provider-cloudflare": "^0.0.26",
39
+ "@fabrika/provider-contract": "^0.0.26",
40
+ "@fabrika/provider-zerops": "^0.0.26"
41
41
  }
42
42
  }
package/src/control.ts CHANGED
@@ -14,6 +14,7 @@ import type { IssueKeyInput, IssueKeyResult } from '@fabrika/auth-core'
14
14
  import type {
15
15
  AppDto,
16
16
  ControlRpcContract,
17
+ DeploymentNamespaceDetailDto,
17
18
  DeploymentNamespaceDto,
18
19
  JsonValue,
19
20
  PlanDeploymentNamespaceRequest,
@@ -26,7 +27,7 @@ import type {
26
27
  const USAGE = `fabrika control — operate the Delivery control plane
27
28
 
28
29
  Usage:
29
- fabrika control key issue --label=<name> --permissions=<a,b,c> [--expires-in=<seconds>]
30
+ fabrika control key issue --label=<name> --permissions=<a,b,c> [--expires-in=<seconds>] [--iam-url=<origin>]
30
31
  fabrika control apps list
31
32
  fabrika control apps get --app=<id>
32
33
  fabrika control apps environments list --app=<id>
@@ -53,6 +54,12 @@ Usage:
53
54
  manifest — a new \`zerops.yaml\`, a new import document — is \`apps environments put\`, which replaces
54
55
  one environment's envelopes and leaves the app row alone.
55
56
 
57
+ A manifest that publishes the app through the namespace proxy is routed by HOST, so \`--domain\` is
58
+ REQUIRED for it — on \`register\` and on \`apps environments put\` alike — and a registration without one is
59
+ refused before anything is created. \`namespaces get\` lists the hosts a \`zerops-subdomain\` namespace
60
+ serves and which of them are still free; a custom-domain namespace serves the domain you bound to its
61
+ proxy. A manifest with no proxy target needs no domain.
62
+
56
63
  \`--installation-id\` has three states: omitted resolves the installation from the organization's
57
64
  connected GitHub App, \`none\` registers an anonymous PUBLIC repository source, and a number names one
58
65
  installation outright.
@@ -60,7 +67,8 @@ installation outright.
60
67
  Namespace placement options, each defaulting to what the preset would choose:
61
68
 
62
69
  --project=<name> the provider project the namespace owns
63
- --core-package=<LIGHT|SERIOUS> defaults to SERIOUS for \`prod\`, LIGHT elsewhere
70
+ --core-package=<LIGHT|SERIOUS> defaults to LIGHT on every environment, \`prod\` included (ADR-0038).
71
+ SERIOUS is a deliberate choice: a project cannot be downgraded again
64
72
  --public-access=<custom-domain|zerops-subdomain>
65
73
  --exclusive-app=<id> required by, and only by, the \`full\` preset
66
74
 
@@ -86,11 +94,16 @@ process listing:
86
94
  installation's IAM RPC key as transport authentication and its provisioning key as the ISSUING
87
95
  credential. Both are read from the environment only:
88
96
 
89
- FABRIKA_IAM_RPC_URL required IAM's own origin (its \`/rpc\` surface), or --iam-url
97
+ FABRIKA_IAM_RPC_URL required IAM's PUBLIC origin, or --iam-url
90
98
  FABRIKA_IAM_RPC_KEY required the installation's IAM RPC key
91
99
  FABRIKA_IAM_PROVISIONING_KEY required the installation's seeded \`px_\` provisioning key
92
100
  FABRIKA_CONTROL_APP_ID optional the control app's IAM id (default \`vozka\`)
93
101
 
102
+ The PUBLIC origin is the \`https://\` address the installation answers on — the one \`platform admin\`
103
+ and \`platform init\` print in their closing block, and the value \`FABRIKA_IAM_ISSUER\` holds on the
104
+ control service. It is NOT the private hostname the services use between themselves: \`http://iam:3000\`
105
+ resolves inside the provider's project and nowhere else, so from here it only ever fails to connect.
106
+
94
107
  Connecting a GitHub source is NOT here and will not be: App creation is a browser flow whose
95
108
  authorization requires a human principal (ADR-0031). Use Settings → Source in the console.
96
109
  `
@@ -145,11 +158,22 @@ const positiveInteger = (raw: string, name: string): number => {
145
158
  return parsed
146
159
  }
147
160
 
148
- /** An origin from the flag, else the environment. Trailing slashes are dropped so paths concatenate. */
149
- const origin = (flags: Flags, flag: string, variable: string, env: Readonly<Record<string, string | undefined>>): string => {
161
+ /**
162
+ * An origin from the flag, else the environment. Trailing slashes are dropped so paths concatenate.
163
+ *
164
+ * `label` names WHICH origin is missing: `key issue` reaches IAM, not the control plane, and a message
165
+ * that says "Control origin" while asking for `--iam-url` sends the operator to the wrong variable.
166
+ */
167
+ const origin = (
168
+ flags: Flags,
169
+ flag: string,
170
+ variable: string,
171
+ env: Readonly<Record<string, string | undefined>>,
172
+ label: string,
173
+ ): string => {
150
174
  const value = flags.values.get(flag) ?? env[variable]
151
175
  if (value === undefined || value.trim() === '') {
152
- throw new Error(`Control origin is required. Pass --${flag}=<origin> or set ${variable}.`)
176
+ throw new Error(`${label} origin is required. Pass --${flag}=<origin> or set ${variable}.`)
153
177
  }
154
178
  return value.trim().replace(/\/+$/, '')
155
179
  }
@@ -164,7 +188,7 @@ const secret = (variable: string, env: Readonly<Record<string, string | undefine
164
188
 
165
189
  /** The console's client with a bearer instead of a cookie, and no SSO bounce: there is no browser to send. */
166
190
  const controlClient = (flags: Flags, env: Readonly<Record<string, string | undefined>>) => {
167
- const base = origin(flags, 'url', 'FABRIKA_CONTROL_URL', env)
191
+ const base = origin(flags, 'url', 'FABRIKA_CONTROL_URL', env, 'Control')
168
192
  const key = secret('FABRIKA_CONTROL_KEY', env)
169
193
  return createRpcClient<ControlRpcContract>({
170
194
  baseUrl: `${base}/api/rpc`,
@@ -227,6 +251,34 @@ const appLine = (app: AppDto): string => `${app.id}\t${app.repoUrl}\t${app.defau
227
251
 
228
252
  const runLine = (run: RunDto): string => `${run.id}\t${run.appId}\t${run.env}\t${run.status}\t${run.ref}`
229
253
 
254
+ /** How the IAM origin was supplied, for a message that must not echo the value itself. */
255
+ const IAM_ORIGIN_SOURCE = '--iam-url / FABRIKA_IAM_RPC_URL'
256
+
257
+ /**
258
+ * The one `key issue` failure whose cause is almost always the address itself.
259
+ *
260
+ * `fetch` rejects only when the request never completed, so this reports what could not be reached and
261
+ * the mistake that produces it. Only the PARSED origin is named: an operator may put userinfo in the
262
+ * value, and `new URL().origin` drops it. A value that does not parse is not echoed at all — the
263
+ * variable is named instead. The cause object may quote anything, so only its short error code is.
264
+ */
265
+ const unreachableIam = (base: string, cause: unknown): string => {
266
+ const code = typeof cause === 'object' && cause !== null ? Reflect.get(cause, 'code') : undefined
267
+ const reason = typeof code === 'string' && code !== '' && code.length <= 40 ? code : 'the connection failed'
268
+ let parsed: string | undefined
269
+ try {
270
+ parsed = new URL(base).origin
271
+ } catch {
272
+ parsed = undefined
273
+ }
274
+ if (parsed === undefined || parsed === 'null' || code === 'ERR_INVALID_URL') {
275
+ return `${IAM_ORIGIN_SOURCE} is not a URL — it needs the \`https://\` scheme and IAM's PUBLIC host, `
276
+ + 'shaped `https://<iam-host>`.'
277
+ }
278
+ return `IAM could not be reached at ${parsed} (${reason}). ${IAM_ORIGIN_SOURCE} must be IAM's PUBLIC origin: `
279
+ + "a private hostname such as `http://iam:3000` answers only inside the provider's project, never from this machine."
280
+ }
281
+
230
282
  const runKeyIssue = async (flags: Flags, env: Readonly<Record<string, string | undefined>>): Promise<void> => {
231
283
  const permissions = required(flags, 'permissions').split(',').map((entry) => entry.trim()).filter((entry) => entry !== '')
232
284
  if (permissions.length === 0) {
@@ -241,11 +293,13 @@ const runKeyIssue = async (flags: Flags, env: Readonly<Record<string, string | u
241
293
  label: required(flags, 'label'),
242
294
  ...(expiresIn === undefined ? {} : { expiresAt: Math.floor(Date.now() / 1000) + positiveInteger(expiresIn, 'expires-in') }),
243
295
  }
244
- const base = origin(flags, 'iam-url', 'FABRIKA_IAM_RPC_URL', env)
296
+ const base = origin(flags, 'iam-url', 'FABRIKA_IAM_RPC_URL', env, 'IAM')
245
297
  const response = await fetch(`${base}/rpc/issueKey`, {
246
298
  method: 'POST',
247
299
  headers: { authorization: `Bearer ${secret('FABRIKA_IAM_RPC_KEY', env)}`, 'content-type': 'application/json' },
248
300
  body: JSON.stringify(body),
301
+ }).catch((cause: unknown) => {
302
+ throw new Error(unreachableIam(base, cause))
249
303
  })
250
304
  if (!response.ok) {
251
305
  // The body can quote what came off the wire, so report the status and nothing else.
@@ -460,6 +514,12 @@ const runRuns = async (verb: string | undefined, flags: Flags, env: Readonly<Rec
460
514
  const namespaceLine = (namespace: DeploymentNamespaceDto): string =>
461
515
  `${namespace.id}\t${namespace.env}\t${namespace.state}\t${namespace.exclusiveAppId ?? '-'}`
462
516
 
517
+ /** One line per host the placement serves: a `free` one is exactly what the next `--domain` accepts. */
518
+ const namespaceHostLines = (namespace: DeploymentNamespaceDetailDto): string[] =>
519
+ (namespace.hosts ?? []).map((entry) =>
520
+ `${entry.host}\t${entry.port}\t${entry.takenBy === undefined ? 'free' : `taken by ${entry.takenBy.appId}/${entry.takenBy.environment}`}`
521
+ )
522
+
463
523
  /** The failure is a DIAGNOSTIC, so it goes to stderr and leaves the data columns above untouched. */
464
524
  const warnNamespaceFailure = (namespace: DeploymentNamespaceDto): void => {
465
525
  // Falsy, not `=== null`: a control plane that omits the field must not print an empty diagnostic.
@@ -496,7 +556,7 @@ const runNamespaces = async (verb: string | undefined, flags: Flags, env: Readon
496
556
  if (verb === 'get') {
497
557
  const result = await client.namespaces.get({ namespaceId: required(flags, 'namespace') })
498
558
  warnNamespaceFailure(result)
499
- emit(flags, result, () => namespaceLine(result))
559
+ emit(flags, result, () => [namespaceLine(result), ...namespaceHostLines(result)].join('\n'))
500
560
  return
501
561
  }
502
562
  if (verb === 'plan') {
package/src/index.ts CHANGED
@@ -13,6 +13,7 @@ Usage:
13
13
  fabrika platform plan --provider=<cloudflare|zerops> [provider options]
14
14
  fabrika platform deploy --provider=<cloudflare|zerops> [provider options]
15
15
  fabrika platform admin --provider=zerops --email=<address> [provider options]
16
+ fabrika platform upgrade --provider=zerops --to=<tag> [<installation>] [--sidecar=<path>|<owner>/<name>]
16
17
  fabrika app deploy [--provider=cloudflare] --env=<env> [--config=<path>] [--dry-run]
17
18
  fabrika app build [--provider=zerops] --env=<env> [--config=<path>] [--output=<path>]
18
19
  fabrika namespace <plan|create|adopt|reconcile> --provider=zerops [provider options]
@@ -27,8 +28,9 @@ provider-neutral, loads no installation package, and speaks the same typed API t
27
28
 
28
29
  Which platform commands exist, and how WIDE each one is, is the provider's own answer — Zerops'
29
30
  \`platform deploy\` owns the whole ordered sequence while Cloudflare's is one step of a scaffolded
30
- workflow (ADR-0027), and only Zerops offers \`platform install\`, the from-scratch bring-up, and
31
- \`platform admin\`, which admits the first human to what that bring-up created. Run
31
+ workflow (ADR-0027), and only Zerops offers \`platform install\`, the from-scratch bring-up,
32
+ \`platform admin\`, which admits the first human to what that bring-up created, and \`platform upgrade\`,
33
+ which rolls a running installation onto a newer published release. Run
32
34
  \`fabrika platform <command> --provider=<name> --help\` for that surface.
33
35
  `
34
36