@fabrika/cli 0.9.0-dev.3 → 0.9.0-dev.5

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/src/index.ts CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { CONTRACT_FILE, type EntryRuntime, writeGeneratedEntry } from '@fabrika/app/build'
4
4
  import { authoredAppProvider } from '@fabrika/provider-contract'
5
+ import { type AppCli, appCliFromModule, type NamespaceCli } from '@fabrika/provider-contract/app-cli'
5
6
  import { installationCliFromModule, isInstallationCommand, supportsInstallationCommand } from '@fabrika/provider-contract/installation'
6
7
  import { dirname, join, relative, resolve } from 'node:path'
7
8
  import { CONTROL_USAGE, registerCompiledManifest, runControlCli } from './control.js'
@@ -25,6 +26,7 @@ Usage:
25
26
  [--namespace=<id>] [--installation-id=<n|none>] [--url=<origin>] [--json]
26
27
  fabrika namespace <plan|create|adopt|reconcile> --provider=zerops [provider options]
27
28
  fabrika control <key|apps|namespaces|register|deploy|runs> [options]
29
+ fabrika env <inspect|maintenance|operations|recover|backups|restore> <app> <env> [arguments] [--json]
28
30
  fabrika builder <init|next|advance|gate|ensure-daemon|induce|build> [options]
29
31
  fabrika db <new|migrate|codegen|test-scaffold|test-isolation> [options]
30
32
  fabrika job run <name>
@@ -61,6 +63,9 @@ environment approved, as Control answers it to FABRIKA_CONTROL_KEY. Run \`fabrik
61
63
  provider-neutral, loads no installation package, and speaks the same typed API the console does. Run
62
64
  \`fabrika control --help\` for its surface.
63
65
 
66
+ \`fabrika env\` shows an application environment's data and backups through the control plane, puts it into
67
+ maintenance, restores its data as of a past time, or recovers a stuck operation. Run \`fabrika env --help\` for its surface.
68
+
64
69
  Which platform commands exist, and how WIDE each one is, is the provider's own answer — Zerops'
65
70
  \`platform deploy\` owns the whole ordered sequence while Cloudflare's is one step of a scaffolded
66
71
  workflow (ADR-0027), and only Zerops offers \`platform install\`, the from-scratch bring-up,
@@ -152,41 +157,33 @@ const requireInstalled = (specifier: string, command: string): void => {
152
157
  }
153
158
  }
154
159
 
160
+ /** A provider id names its package, `@fabrika/provider-<id>`; anything else is a module specifier of its own. */
161
+ const PROVIDER_ID = /^[a-z][a-z0-9-]*$/
162
+
163
+ const installationSpecifier = (provider: string): string => PROVIDER_ID.test(provider) ? `@fabrika/provider-${provider}/installation` : provider
164
+
155
165
  const installationModule = async (provider: string, command: string): Promise<unknown> => {
156
- const specifier = provider === 'cloudflare'
157
- ? '@fabrika/provider-cloudflare/installation'
158
- : provider === 'zerops'
159
- ? '@fabrika/provider-zerops/installation'
160
- : provider
166
+ const specifier = installationSpecifier(provider)
161
167
  requireInstalled(specifier, command)
162
168
  return import(specifier)
163
169
  }
164
170
 
165
- export type AppCliRunner = (argv: readonly string[]) => Promise<void>
166
-
167
- export const appCliRunnerFromModule = (loaded: unknown, packageName: string, exportName: string): AppCliRunner => {
168
- if (typeof loaded !== 'object' || loaded === null || !(exportName in loaded)) {
169
- throw new Error(`${packageName} must export \`${exportName}\``)
170
- }
171
- const runner = Reflect.get(loaded, exportName)
172
- if (typeof runner !== 'function') {
173
- throw new Error(`${packageName} must export \`${exportName}\` as a function`)
174
- }
175
- return runner
171
+ /** App and namespace commands take a provider id only: the module's `appCli` must name the same one. */
172
+ const providerAppCli = async (provider: string, command: string): Promise<AppCli> => {
173
+ if (!PROVIDER_ID.test(provider)) throw new Error(`\`${command}\` takes a provider id ([a-z][a-z0-9-]*), not "${provider}"`)
174
+ const specifier = `@fabrika/provider-${provider}/cli`
175
+ requireInstalled(specifier, command)
176
+ return appCliFromModule(await import(specifier), provider, specifier)
176
177
  }
177
178
 
178
- const appCliRunner = async (packageName: string, exportName: string, command: string): Promise<AppCliRunner> => {
179
- requireInstalled(packageName, command)
180
- const loaded: unknown = await import(packageName)
181
- return appCliRunnerFromModule(loaded, packageName, exportName)
182
- }
179
+ const unsupported = (provider: string, command: string): Error => new Error(`${provider} app tooling does not support \`${command}\``)
183
180
 
184
181
  const runPlatform = async (parsed: ParsedCommand): Promise<void> => {
185
182
  if (!isInstallationCommand(parsed.command)) {
186
183
  throw new Error(`Unknown platform command: ${parsed.command ?? '(missing)'}`)
187
184
  }
188
185
  const provider = requireExplicitProvider(parsed)
189
- const expectedProvider = provider === 'cloudflare' || provider === 'zerops' ? provider : undefined
186
+ const expectedProvider = PROVIDER_ID.test(provider) ? provider : undefined
190
187
  const installation = installationCliFromModule(
191
188
  await installationModule(provider, `fabrika platform ${parsed.command} --provider=${provider}`),
192
189
  expectedProvider,
@@ -202,17 +199,12 @@ const runAppRegister = async (parsed: ParsedCommand): Promise<void> => {
202
199
  const config = configPath(parsed.rest)
203
200
  await registerCompiledManifest(parsed.rest, async (env) => {
204
201
  const provider = await selectedAppProvider(parsed)
205
- if (provider !== 'zerops') {
206
- throw new Error(`${provider} app tooling does not support \`app register\``)
207
- }
208
- requireInstalled('@fabrika/provider-zerops/cli', 'fabrika app register')
209
- const { buildZeropsManifestText } = await import('@fabrika/provider-zerops/cli')
210
- return { provider, text: await buildZeropsManifestText({ config, env }) }
202
+ const cli = await providerAppCli(provider, 'fabrika app register')
203
+ if (cli.registrationManifest === undefined) throw unsupported(provider, 'app register')
204
+ return { provider, text: await cli.registrationManifest({ config, env }) }
211
205
  })
212
206
  }
213
207
 
214
- const ENTRY_RUNTIMES: Readonly<Record<string, EntryRuntime>> = { cloudflare: 'cloudflare', zerops: 'bun' }
215
-
216
208
  /** A contract application gets its generated entrypoint before the provider builds it. False when it is none. */
217
209
  const writeContractEntry = async (argv: readonly string[], runtime: EntryRuntime): Promise<boolean> => {
218
210
  const root = dirname(resolve(process.cwd(), configPath(argv)))
@@ -235,41 +227,37 @@ const runApp = async (parsed: ParsedCommand): Promise<void> => {
235
227
  return
236
228
  }
237
229
  const provider = await selectedAppProvider(parsed)
238
- const runtime = ENTRY_RUNTIMES[provider]
239
- const contract = parsed.command === 'build' && runtime !== undefined && (await writeContractEntry(parsed.rest, runtime))
240
- if (provider === 'cloudflare') {
241
- if (contract) {
242
- return
243
- }
244
- if (parsed.command !== 'deploy') {
245
- throw new Error(`Cloudflare app tooling does not support \`app ${parsed.command ?? '(missing)'}\``)
246
- }
247
- const runCloudflareCli = await appCliRunner('@fabrika/provider-cloudflare/cli', 'runCloudflareCli', 'fabrika app deploy')
248
- await runCloudflareCli(['deploy', ...parsed.rest])
230
+ const command = `app ${parsed.command ?? '(missing)'}`
231
+ const cli = await providerAppCli(provider, `fabrika ${command}`)
232
+ if (parsed.command === 'build' && cli.build !== undefined) {
233
+ await cli.build(parsed.rest, { contract: await writeContractEntry(parsed.rest, cli.entryRuntime) })
249
234
  return
250
235
  }
251
- if (provider === 'zerops') {
252
- if (parsed.command !== 'build') {
253
- throw new Error(`Zerops app tooling does not support \`app ${parsed.command ?? '(missing)'}\``)
254
- }
255
- const runZeropsCli = await appCliRunner('@fabrika/provider-zerops/cli', 'runZeropsCli', 'fabrika app build')
256
- await runZeropsCli(['build', ...parsed.rest])
236
+ if (parsed.command === 'deploy' && cli.deploy !== undefined) {
237
+ await cli.deploy(parsed.rest)
257
238
  return
258
239
  }
259
- throw new Error(`Provider ${provider} does not expose app CLI commands`)
240
+ throw unsupported(provider, command)
241
+ }
242
+
243
+ const namespaceCli = async (provider: string): Promise<NamespaceCli> => {
244
+ const cli = await providerAppCli(provider, 'fabrika namespace')
245
+ if (cli.namespaces === undefined) throw new Error(`Provider ${provider} does not expose deployment namespaces`)
246
+ return cli.namespaces
260
247
  }
261
248
 
262
249
  const runNamespace = async (parsed: ParsedCommand): Promise<void> => {
263
250
  const provider = requireExplicitProvider(parsed)
264
- if (provider !== 'zerops') {
265
- throw new Error(`Provider ${provider} does not expose deployment namespaces`)
266
- }
251
+ const cli = await namespaceCli(provider)
267
252
  if (parsed.command === undefined) {
268
253
  throw new Error('Namespace command is required')
269
254
  }
270
- requireInstalled('@fabrika/provider-zerops', 'fabrika namespace')
271
- const { runZeropsNamespaceCli } = await import('./namespace.js')
272
- await runZeropsNamespaceCli(parsed.command, parsed.rest)
255
+ const { runNamespaceCommand } = await import('./namespace.js')
256
+ await runNamespaceCommand(cli, parsed.command, parsed.rest, {
257
+ source: process.env,
258
+ fetch: (input, init) => fetch(input, init),
259
+ write: (value) => console.info(value.trimEnd()),
260
+ })
273
261
  }
274
262
 
275
263
  export const runCli = async (argv: readonly string[]): Promise<void> => {
@@ -284,8 +272,16 @@ export const runCli = async (argv: readonly string[]): Promise<void> => {
284
272
  console.info(CONTROL_USAGE)
285
273
  return
286
274
  }
275
+ if (parsed.help && parsed.area === 'env') {
276
+ const { ENV_USAGE } = await import('./data.js')
277
+ console.info(ENV_USAGE)
278
+ return
279
+ }
287
280
  if (parsed.help && parsed.area === 'namespace') {
288
- requireInstalled('@fabrika/provider-zerops', 'fabrika namespace')
281
+ if (parsed.provider !== undefined && parsed.provider !== '') {
282
+ console.info((await namespaceCli(parsed.provider)).usage)
283
+ return
284
+ }
289
285
  const { NAMESPACE_USAGE } = await import('./namespace.js')
290
286
  console.info(NAMESPACE_USAGE)
291
287
  return
@@ -336,6 +332,11 @@ export const runCli = async (argv: readonly string[]): Promise<void> => {
336
332
  await runControlCli(parsed.command, parsed.rest, parsed.provider)
337
333
  return
338
334
  }
335
+ if (parsed.area === 'env') {
336
+ const { runEnvCli } = await import('./data.js')
337
+ await runEnvCli(parsed.command, parsed.rest)
338
+ return
339
+ }
339
340
  if (parsed.area === 'db') {
340
341
  const { runDbCli } = await import('./db.js')
341
342
  await runDbCli(parsed.command, parsed.rest)
package/src/namespace.ts CHANGED
@@ -1,60 +1,18 @@
1
1
  import { createRpcClient } from '@fabrika/app'
2
- import type { AdoptDeploymentNamespaceRequest, ControlRpcContract, CreateDeploymentNamespaceRequest } from '@fabrika/control-contract'
3
- import type { JsonValue, ProviderDeploymentNamespace, ProviderNamespacePlan } from '@fabrika/provider-contract'
4
- import {
5
- createZeropsNamespaceOperator,
6
- decodeZeropsNamespaceProxySource,
7
- parseZeropsCliArgs,
8
- verifyZeropsNamespaceProxySource,
9
- type ZeropsCliArgs,
10
- type ZeropsNamespacePostgres,
11
- zeropsNamespacePostgresSchema,
12
- zeropsNamespaceTargetCodec,
13
- } from '@fabrika/provider-zerops'
2
+ import type { ControlRpcContract } from '@fabrika/control-contract'
3
+ import type { NamespaceCli, NamespaceControl } from '@fabrika/provider-contract/app-cli'
14
4
  import { z } from 'zod'
15
5
  import { namespaceLine, namespacePlanLines } from './control'
16
6
 
17
- export const NAMESPACE_USAGE = `fabrika namespace — Zerops deployment namespaces
7
+ export const NAMESPACE_USAGE = `fabrika namespace — deployment namespaces
18
8
 
19
9
  Usage:
20
- fabrika namespace plan --provider=zerops --id=<id> --env=<env> --preset=<cheap|mid|full> [namespace options]
21
- fabrika namespace create --provider=zerops --id=<id> --env=<env> --preset=<cheap|mid|full> [namespace options] [--control-url=<url>]
22
- fabrika namespace adopt --provider=zerops --id=<id> --env=<env> --preset=<cheap|mid|full> --project-id=<id> [namespace options] [--control-url=<url>]
23
- fabrika namespace reconcile --provider=zerops --id=<id> [--control-url=<url>]
10
+ fabrika namespace <plan|create|adopt|reconcile> --provider=<name> [provider options] [--json]
24
11
 
25
- Options:
26
- --id=<id> Namespace id.
27
- --env=<env> Environment.
28
- --preset=<cheap|mid|full> Provider-owned namespace preset.
29
- --exclusive-app=<id> App reserved by a full namespace.
30
- --project-id=<id> Existing Zerops project id for adoption.
31
- --project-name=<name> Zerops project name (create: default fabrika-<env>-<id>;
32
- adopt: the existing project's name, default the namespace id).
33
- --core-package=<tier> LIGHT or SERIOUS.
34
- --public-access=<mode> custom-domain or zerops-subdomain.
35
- --postgres-type=<type> Cheap-tier PostgreSQL type.
36
- --postgres-profile=<profile> Cheap-tier PostgreSQL profile.
37
- --control-url=<url> Control origin; or FABRIKA_CONTROL_URL.
38
- --json Print the result as JSON instead of rows.
39
- -h, --help Show this help.
40
-
41
- \`plan\` prints one \`<path>\\t<value>\` row per field of the plan, keyed by its path in --json; a multi-line
42
- value such as the proxy's descriptor file is shown by size only. The other commands print one
43
- \`<id>\\t<env>\\t<state>\\t<exclusive app>\` row.
44
-
45
- Mutating namespace commands read the Bearer credential from FABRIKA_CONTROL_TOKEN.
46
- Plan/create/adopt require FABRIKA_ZEROPS_PROXY_SOURCE_JSON:
47
- {"repository":{"owner":"...","name":"..."},"commitSha":"...","descriptor":{"path":"zerops.yaml","contents":"...","sha256":"..."}}
48
- Reconcile uses the persisted namespace source.
12
+ The commands and their options are the provider's: \`fabrika namespace --provider=<name> --help\` prints them.
49
13
  `
50
14
 
51
- export interface ZeropsNamespaceCommand {
52
- readonly args: ZeropsCliArgs
53
- /** The result as JSON; otherwise the rows `fabrika control namespaces` prints. */
54
- readonly json: boolean
55
- }
56
-
57
- export interface ZeropsNamespaceCommandDependencies {
15
+ export interface NamespaceCommandDependencies {
58
16
  readonly source: Readonly<Record<string, string | undefined>>
59
17
  readonly fetch: (input: string | URL | Request, init?: RequestInit) => Promise<Response>
60
18
  readonly write: (value: string) => void
@@ -67,64 +25,15 @@ const required = (value: string | undefined, label: string): string => {
67
25
  return value.trim()
68
26
  }
69
27
 
70
- const postgres = (args: ZeropsCliArgs): ZeropsNamespacePostgres | undefined => {
71
- const type = args.postgresType
72
- const profile = args.postgresProfile
73
- if (type === undefined && profile === undefined) return undefined
74
- if (type === undefined) {
75
- throw new Error('--postgres-type is required with --postgres-profile')
76
- }
77
- const result = zeropsNamespacePostgresSchema.safeParse({ type, profile })
78
- if (result.success) return result.data
79
- if (result.error.issues[0]?.path[0] === 'type') throw new Error('--postgres-type must be postgresql:ha@18 or postgresql:single@18')
80
- throw new Error(`--postgres-profile ${profile} is not supported by ${type}`)
81
- }
82
-
83
- const planOptions = (args: ZeropsCliArgs): { [key: string]: JsonValue } | undefined => {
84
- const values: { [key: string]: JsonValue } = {}
85
- if (args.projectName !== undefined) values['projectName'] = required(args.projectName, '--project-name')
86
- if (args.corePackage !== undefined) values['corePackage'] = required(args.corePackage, '--core-package')
87
- if (args.publicAccess !== undefined) values['publicAccess'] = required(args.publicAccess, '--public-access')
88
- const database = postgres(args)
89
- if (database !== undefined) {
90
- values['postgres'] = database.profile === undefined ? { type: database.type } : { type: database.type, profile: database.profile }
91
- }
92
- return Object.keys(values).length === 0 ? undefined : values
93
- }
94
-
95
- const namespacePlan = async (
96
- args: ZeropsCliArgs,
97
- source: Readonly<Record<string, string | undefined>>,
98
- ): Promise<ProviderNamespacePlan> => {
99
- // `FABRIKA_ZEROPS_*` because Zerops reserves the bare `ZEROPS_` prefix and refuses to store a custom
100
- // variable using it (`userDataZeropsPrefixForbidden`).
101
- const serialized = required(source['FABRIKA_ZEROPS_PROXY_SOURCE_JSON'], 'FABRIKA_ZEROPS_PROXY_SOURCE_JSON')
102
- let value: unknown
103
- try {
104
- value = JSON.parse(serialized)
105
- } catch {
106
- throw new Error('FABRIKA_ZEROPS_PROXY_SOURCE_JSON must contain valid JSON')
107
- }
108
- const proxySource = decodeZeropsNamespaceProxySource(value)
109
- await verifyZeropsNamespaceProxySource(proxySource)
110
- const operator = createZeropsNamespaceOperator({ proxySource })
111
- const options = planOptions(args)
112
- return operator.plan({
113
- id: required(args.namespaceId, '--id'),
114
- env: required(args.env, '--env'),
115
- preset: required(args.preset, '--preset'),
116
- ...(args.exclusiveAppId === undefined ? {} : { exclusiveAppId: required(args.exclusiveAppId, '--exclusive-app') }),
117
- ...(options === undefined ? {} : { options }),
118
- })
119
- }
120
-
121
28
  const outputJson = (value: unknown): string => `${JSON.stringify(value, null, '\t')}\n`
122
29
 
30
+ const CONTROL_URL_OPTION = '--control-url='
31
+
123
32
  const controlCoordinates = (
124
- args: ZeropsCliArgs,
33
+ controlUrl: string | undefined,
125
34
  source: Readonly<Record<string, string | undefined>>,
126
35
  ): { baseUrl: URL; token: string } => {
127
- const value = required(args.controlUrl ?? source['FABRIKA_CONTROL_URL'], '--control-url or FABRIKA_CONTROL_URL')
36
+ const value = required(controlUrl ?? source['FABRIKA_CONTROL_URL'], '--control-url or FABRIKA_CONTROL_URL')
128
37
  const token = required(source['FABRIKA_CONTROL_TOKEN'], 'FABRIKA_CONTROL_TOKEN')
129
38
  let baseUrl: URL
130
39
  try {
@@ -139,7 +48,7 @@ const controlCoordinates = (
139
48
  }
140
49
 
141
50
  const controlClient = (
142
- deps: ZeropsNamespaceCommandDependencies,
51
+ deps: NamespaceCommandDependencies,
143
52
  coordinates: { baseUrl: URL; token: string },
144
53
  ) =>
145
54
  createRpcClient<ControlRpcContract>({
@@ -158,6 +67,29 @@ const controlClient = (
158
67
  },
159
68
  })
160
69
 
70
+ const namespaceControl = (deps: NamespaceCommandDependencies, controlUrl: string | undefined): NamespaceControl => {
71
+ const client = controlClient(deps, controlCoordinates(controlUrl, deps.source))
72
+ return {
73
+ create: (namespace) =>
74
+ client.namespaces.create({
75
+ id: namespace.id,
76
+ env: namespace.env,
77
+ ...(namespace.exclusiveAppId === undefined ? {} : { exclusiveAppId: namespace.exclusiveAppId }),
78
+ target: namespace.target,
79
+ }),
80
+ adopt: (namespace) =>
81
+ client.namespaces.adopt({
82
+ namespaceId: namespace.id,
83
+ namespace: {
84
+ env: namespace.env,
85
+ ...(namespace.exclusiveAppId === undefined ? {} : { exclusiveAppId: namespace.exclusiveAppId }),
86
+ target: namespace.target,
87
+ },
88
+ }),
89
+ reconcile: (namespaceId) => client.namespaces.reconcile({ namespaceId }),
90
+ }
91
+ }
92
+
161
93
  // Passthrough on purpose: `--json` shows the operator the whole namespace detail, this only checks it is one.
162
94
  const namespaceResponseSchema = z.object({
163
95
  id: z.string(),
@@ -165,85 +97,30 @@ const namespaceResponseSchema = z.object({
165
97
  state: z.enum(['pending', 'provisioning', 'ready', 'failed']),
166
98
  exclusiveAppId: z.string().nullable(),
167
99
  }).passthrough()
168
- const writeNamespace = (command: ZeropsNamespaceCommand, deps: ZeropsNamespaceCommandDependencies, result: unknown): void => {
169
- const parsed = namespaceResponseSchema.safeParse(result)
170
- if (!parsed.success) {
171
- throw new Error('Control API returned an invalid namespace')
172
- }
173
- deps.write(command.json ? outputJson(parsed.data) : `${namespaceLine(parsed.data)}\n`)
174
- }
175
-
176
- const createBody = (namespace: ProviderDeploymentNamespace): CreateDeploymentNamespaceRequest => ({
177
- id: namespace.id,
178
- env: namespace.env,
179
- ...(namespace.exclusiveAppId === undefined ? {} : { exclusiveAppId: namespace.exclusiveAppId }),
180
- target: namespace.target,
181
- })
182
100
 
183
- const adoptBody = (namespace: ProviderDeploymentNamespace): AdoptDeploymentNamespaceRequest => ({
184
- env: namespace.env,
185
- ...(namespace.exclusiveAppId === undefined ? {} : { exclusiveAppId: namespace.exclusiveAppId }),
186
- target: namespace.target,
187
- })
188
-
189
- /** Execute one namespace command. All command inputs are validated before the first fetch. */
190
- export const runZeropsNamespaceCommand = async (
191
- command: ZeropsNamespaceCommand,
192
- deps: ZeropsNamespaceCommandDependencies,
101
+ /**
102
+ * Run one provider's namespace command and print what it answers. `--json` and `--control-url` are this area's own
103
+ * options, so they are taken out before the provider's parser, which refuses unknown options.
104
+ */
105
+ export const runNamespaceCommand = async (
106
+ cli: NamespaceCli,
107
+ subcommand: string,
108
+ argv: readonly string[],
109
+ deps: NamespaceCommandDependencies,
193
110
  ): Promise<void> => {
194
- const { args } = command
195
- const subcommand = required(args.subcommand, 'namespace command')
196
- if (subcommand === 'plan') {
197
- const plan = await namespacePlan(args, deps.source)
198
- deps.write(command.json ? outputJson(plan) : `${namespacePlanLines(plan).join('\n')}\n`)
199
- return
200
- }
201
- if (subcommand === 'reconcile') {
202
- const id = required(args.namespaceId, '--id')
203
- const control = controlCoordinates(args, deps.source)
204
- writeNamespace(command, deps, await controlClient(deps, control).namespaces.reconcile({ namespaceId: id }))
111
+ const json = argv.includes('--json')
112
+ const controlUrl = argv.filter((arg) => arg.startsWith(CONTROL_URL_OPTION)).at(-1)?.slice(CONTROL_URL_OPTION.length)
113
+ const providerArgv = argv.filter((arg) => arg !== '--json' && !arg.startsWith(CONTROL_URL_OPTION))
114
+ // The Control credential stays here: the provider plans with the rest of the environment.
115
+ const { FABRIKA_CONTROL_TOKEN: _token, ...source } = deps.source
116
+ const result = await cli.run(subcommand, providerArgv, { source, control: () => namespaceControl(deps, controlUrl) })
117
+ if ('plan' in result) {
118
+ deps.write(json ? outputJson(result.plan) : `${namespacePlanLines(result.plan).join('\n')}\n`)
205
119
  return
206
120
  }
207
- if (subcommand !== 'create' && subcommand !== 'adopt') {
208
- throw new Error(`Unknown namespace command: ${subcommand}`)
209
- }
210
-
211
- const planned = await namespacePlan(args, deps.source)
212
- const control = controlCoordinates(args, deps.source)
213
- if (subcommand === 'create') {
214
- writeNamespace(command, deps, await controlClient(deps, control).namespaces.create(createBody(planned.namespace)))
215
- return
216
- }
217
-
218
- const projectId = required(args.projectId, '--project-id')
219
- const decoded = zeropsNamespaceTargetCodec.decode(planned.namespace.target.payload)
220
- const namespace: ProviderDeploymentNamespace = {
221
- ...planned.namespace,
222
- target: {
223
- provider: 'zerops',
224
- version: zeropsNamespaceTargetCodec.version,
225
- payload: zeropsNamespaceTargetCodec.encode({
226
- ...decoded,
227
- // An adopted project keeps its own name, so the plan's default for a created one does not apply.
228
- projectName: args.projectName ?? planned.namespace.id,
229
- managed: false,
230
- projectId,
231
- ready: false,
232
- }),
233
- },
121
+ const parsed = namespaceResponseSchema.safeParse(result.namespace)
122
+ if (!parsed.success) {
123
+ throw new Error('Control API returned an invalid namespace')
234
124
  }
235
- writeNamespace(command, deps, await controlClient(deps, control).namespaces.adopt({ namespaceId: namespace.id, namespace: adoptBody(namespace) }))
125
+ deps.write(json ? outputJson(parsed.data) : `${namespaceLine(parsed.data)}\n`)
236
126
  }
237
-
238
- /** `--json` is this area's own flag, so it is taken out before the provider's parser, which refuses unknown options. */
239
- export const parseZeropsNamespaceCommand = (subcommand: string, argv: readonly string[]): ZeropsNamespaceCommand => ({
240
- args: parseZeropsCliArgs(['namespace', subcommand, ...argv.filter((arg) => arg !== '--json')]),
241
- json: argv.includes('--json'),
242
- })
243
-
244
- export const runZeropsNamespaceCli = (subcommand: string, argv: readonly string[]): Promise<void> =>
245
- runZeropsNamespaceCommand(parseZeropsNamespaceCommand(subcommand, argv), {
246
- source: process.env,
247
- fetch: globalThis.fetch,
248
- write: (value) => console.info(value.trimEnd()),
249
- })
@@ -1,6 +1,6 @@
1
1
  import type { AnyContract } from '@fabrika/app/contract';
2
2
  import { type ContractImplementation } from '@fabrika/app/implement';
3
- export declare const APP_DEV_USAGE = "fabrika app dev \u2014 the application on a local port, to click through its screens\n\nUsage:\n fabrika app dev [--port=<n>] [--host=<loopback address>] [--seed=<module>]\n\nRun from the application root. It serves src/app.ts through its test kit: the production proxy decision,\nthe kit's stand-in IAM, each SPA from its built directory (run the SPA build first; an unbuilt one is an empty page),\nand a throwaway schema of the database in FABRIKA_TEST_POSTGRES_URL, migrated from db/migrations/ and dropped on exit.\nThe seed module (--seed, or dev/seed.ts when it exists) default-exports a DevSeed of @fabrika/app/testing: it\nreceives the kit, writes through the endpoints, and answers the personas, link pages and scope values to offer.\nPick who the browser is at /__fabrika/dev; every SPA page shows a toolbar that switches the caller and lists the\nmail IAM and the application's jobs sent, and the requests the application sent to https://outbox.invalid, the dev\noutbox. A form's challenge passes. The application's own variables come from dev/dev.env (NAME=value lines)\nover the environment. What the seed or a job's handler throws is printed with its stack. It listens on 127.0.0.1\n(or ::1, localhost) only, port 3000 unless --port says otherwise (0 picks a free one), and prints the address it\nserves.\n";
3
+ export declare const APP_DEV_USAGE = "fabrika app dev \u2014 the application on a local port, to click through its screens\n\nUsage:\n fabrika app dev [--port=<n>] [--host=<loopback address>] [--seed=<module>]\n\nRun from the application root. It serves src/app.ts through its test kit: the production proxy decision,\nthe kit's stand-in IAM, each SPA from its built directory (run the SPA build first; an unbuilt one is an empty page),\nand a throwaway schema of the database in FABRIKA_TEST_POSTGRES_URL, migrated from db/migrations/ and dropped on exit; an\napplication on Cloudflare (its fabrika.config.ts is @fabrika/provider-cloudflare's) gets an in-memory SQLite database instead.\nThe seed module (--seed, or dev/seed.ts when it exists) default-exports a DevSeed of @fabrika/app/testing: it\nreceives the kit, writes through the endpoints, and answers the personas, link pages and scope values to offer.\nPick who the browser is at /__fabrika/dev; every SPA page shows a toolbar that switches the caller and lists the\nmail IAM and the application's jobs sent, and the requests the application sent to https://outbox.invalid, the dev\noutbox. A form's challenge passes. The application's own variables come from dev/dev.env (NAME=value lines)\nover the environment. What the seed or a job's handler throws is printed with its stack. It listens on 127.0.0.1\n(or ::1, localhost) only, port 3000 unless --port says otherwise (0 picks a free one), and prints the address it\nserves.\n";
4
4
  /** A refusal of `app dev` itself, whose message names nothing of the environment. */
5
5
  export declare class AppDevError extends Error {
6
6
  readonly name = "AppDevError";
@@ -1,5 +1,6 @@
1
- import type { AppEnvDto, DeploymentNamespaceDto, PlanDeploymentNamespaceResponse } from '@fabrika/control-contract';
2
- declare const USAGE = "fabrika control \u2014 operate the Delivery control plane\n\nUsage:\n fabrika control key issue --label=<name> --permissions=<a,b,c> --expires-in=<seconds> [--iam-url=<origin>]\n fabrika control apps list\n fabrika control apps get --app=<id>\n fabrika control apps environments list --app=<id>\n fabrika control apps environments put --provider=<name> --app=<id> --env=<name> --manifest=<path>\n [--domain=<host>] [--public-origin=<url>] [--trigger-ref=<ref>] [--namespace=<id>]\n [--cross-origin=<origin> ...] [--kind=standard|dev]\n fabrika control apps variables list --app=<id>\n fabrika control apps variables put --app=<id> --name=<name> --value=<text> [--env=<name>]\n fabrika control apps variables delete --app=<id> --name=<name> [--env=<name>]\n fabrika control apps secrets list --app=<id>\n fabrika control apps secrets put --app=<id> --name=<name> [--env=<name>] (the value on stdin)\n fabrika control apps secrets delete --app=<id> --name=<name> [--env=<name>]\n fabrika control register --provider=<name> --app=<id> --repo=<url> --env=<name> --manifest=<path>\n [--domain=<host>] [--public-origin=<url>] [--trigger-ref=<ref>]\n [--namespace=<id>] [--installation-id=<n|none>] [--cross-origin=<origin> ...]\n fabrika control namespaces list\n fabrika control namespaces get --namespace=<id>\n fabrika control namespaces plan --namespace=<id> --env=<name> --preset=<cheap|mid|full> [placement]\n fabrika control namespaces create --namespace=<id> --env=<name> --preset=<cheap|mid|full> [placement]\n fabrika control namespaces reconcile --namespace=<id>\n fabrika control namespaces update --namespace=<id> --proxy-source=current\n fabrika control namespaces remove --namespace=<id>\n fabrika control deploy --app=<id> --env=<name> [--ref=<ref>]\n fabrika control runs list [--app=<id>] [--env=<name>] [--limit=<n>]\n fabrika control runs get --run=<id>\n fabrika control runs log --run=<id>\n\n`register` CREATES an app and refuses a second one with the same id. Re-registering a changed\nmanifest \u2014 a new `zerops.yaml`, a new import document \u2014 is `apps environments put`, which replaces\none environment's envelopes and leaves the app row alone.\n\nA manifest that publishes the app through the namespace proxy is routed by HOST, so `--domain` is\nREQUIRED for it \u2014 on `register` and on `apps environments put` alike \u2014 and a registration without one is\nrefused before anything is created. `namespaces get` lists the hosts a `zerops-subdomain` namespace\nserves and which of them are still free; a custom-domain namespace serves the domain you bound to its\nproxy. A manifest with no proxy target needs no domain.\n\nA variable's value is stored and printed in clear. A secret's value is write-only: `apps secrets put`\nreads it from STDIN, never from a flag, so it reaches neither shell history nor a process listing, and\none trailing newline is dropped. No command prints it back; `apps secrets list` shows names, scope and\nstorage only. Generate one in the pipe:\n\n openssl rand -base64 32 | fabrika control apps secrets put --app=<id> --name=<name>\n\n`--public-origin` is where IAM may return a signed-in person: without one, sign-in to the environment is\nrefused. When `register` is given none and the namespace lists `--domain` among its hosts, it sets\n`https://<domain>` and says so on stderr. A custom domain needs the flag.\n\n`--cross-origin` names an origin whose pages may call the environment's cross-origin endpoints (ADR-0022), and\nrepeats: the flags given are the environment's whole list. Each is an exact origin with a literal host\n(`https://app.example.com`; `http://` only for a local one), never the environment's own domain, at most 16.\n`apps environments put` without the flag keeps the stored list, and a lone empty `--cross-origin=` clears it.\nOn Zerops the change reaches the namespace proxy at once; on Cloudflare the next deploy of the environment\napplies it.\n\n`--installation-id` has three states: omitted resolves the installation from the organization's\nconnected GitHub App, `none` registers an anonymous PUBLIC repository source, and a number names one\ninstallation outright. With `none`, control reads the repository once without a token and refuses one\nGitHub hides: a private repository needs the GitHub App connected in the console first.\n\n`--trigger-ref` is the git ref whose push deploys the environment; without it the environment deploys only\non `deploy`. A bare name is a branch: `--trigger-ref=deploy/prod` is stored as `refs/heads/deploy/prod`.\nA full ref is kept as given: `refs/heads/<branch>`, `refs/tags/<tag>`, or a `*` glob such as\n`refs/tags/v*`, which deploys every matching tag. A tag always needs the `refs/tags/` form. Each\nenvironment of an app needs its own trigger ref.\n\nNamespace placement options, each defaulting to what the preset would choose:\n\n --project=<name> the provider project the namespace owns; on Zerops the default is\n fabrika-<env>-<namespace id>, beside the installation's fabrika-<env>\n --core-package=<LIGHT|SERIOUS> defaults to LIGHT on every environment, `prod` included (ADR-0038).\n SERIOUS is a deliberate choice: a project cannot be downgraded again\n --public-access=<custom-domain|zerops-subdomain>\n --exclusive-app=<id> required by, and only by, the `full` preset\n\n`namespaces plan` is a preview and changes nothing. It prints one `<path>\\t<value>` row per field of\nthe plan, keyed by its path in `--json`; a multi-line value such as the proxy's descriptor file is shown\nby size only. `namespaces create` commits that exact plan \u2014 the\nsame two steps the console's form takes \u2014 and returns as soon as the placement is recorded: provisioning\nruns behind the control queue and takes minutes, so the state comes back `pending`. Follow it with\n`namespaces get` or `namespaces list`; nothing needs to stay connected. `namespaces remove` frees the id\nof a placement no application is registered in. It deletes nothing at the provider and prints, on stderr,\nthe provider resources it stopped tracking. `namespaces update --proxy-source=current` re-pins a placement's\nproxy to the source this control plane deploys new placements from \u2014 a placement keeps the one it was created\nwith until you do \u2014 and queues the reconcile that rebuilds the proxy from it; a `failed` placement accepts it.\n\nEvery command accepts --json, which prints the procedure's result verbatim.\n\nThe control origin is not a credential and takes either form:\n\n --url=<origin> FABRIKA_CONTROL_URL\n\nCredentials are read from the ENVIRONMENT ONLY and have no flag, so they cannot reach a CI log or a\nprocess listing:\n\n FABRIKA_CONTROL_KEY required a machine `px_` credential for the control app\n\n`key issue` mints that credential and therefore authenticates differently \u2014 it presents the\ninstallation's IAM RPC key as transport authentication and its provisioning key as the ISSUING\ncredential. Every key expires: `--expires-in` is required and at most 2592000 (30 days). Both\ncredentials are read from the environment only:\n\n FABRIKA_IAM_RPC_URL required IAM's PUBLIC origin, or --iam-url\n FABRIKA_IAM_RPC_KEY required the installation's IAM RPC key\n FABRIKA_IAM_PROVISIONING_KEY required the installation's seeded `px_` provisioning key\n FABRIKA_CONTROL_APP_ID optional the control app's IAM id (default `vozka`)\n\nThe PUBLIC origin is the `https://` address the installation answers on \u2014 the one `platform admin`\nand `platform init` print in their closing block, and the value `FABRIKA_IAM_ISSUER` holds on the\ncontrol service. It is NOT the private hostname the services use between themselves: `http://iam:3000`\nresolves inside the provider's project and nowhere else, so from here it only ever fails to connect.\n\nConnecting a GitHub source is NOT here and will not be: App creation is a browser flow whose\nauthorization requires a human principal (ADR-0029). Use Settings \u2192 Source in the console.\n";
1
+ import { type InferRpcClient } from '@fabrika/app';
2
+ import type { AppEnvDto, ControlRpcContract, DeploymentNamespaceDto, PlanDeploymentNamespaceResponse } from '@fabrika/control-contract';
3
+ declare const USAGE = "fabrika control \u2014 operate the Delivery control plane\n\nUsage:\n fabrika control key issue --label=<name> --permissions=<a,b,c> --expires-in=<seconds> [--iam-url=<origin>]\n fabrika control apps list\n fabrika control apps get --app=<id>\n fabrika control apps environments list --app=<id>\n fabrika control apps environments put --provider=<name> --app=<id> --env=<name> --manifest=<path>\n [--domain=<host>] [--public-origin=<url>] [--trigger-ref=<ref>] [--namespace=<id>]\n [--cross-origin=<origin> ...] [--kind=standard|dev]\n fabrika control apps variables list --app=<id>\n fabrika control apps variables put --app=<id> --name=<name> --value=<text> [--env=<name>]\n fabrika control apps variables delete --app=<id> --name=<name> [--env=<name>]\n fabrika control apps secrets list --app=<id>\n fabrika control apps secrets put --app=<id> --name=<name> [--env=<name>] (the value on stdin)\n fabrika control apps secrets delete --app=<id> --name=<name> [--env=<name>]\n fabrika control register --provider=<name> --app=<id> --repo=<url> --env=<name> --manifest=<path>\n [--domain=<host>] [--public-origin=<url>] [--trigger-ref=<ref>]\n [--namespace=<id>] [--installation-id=<n|none>] [--cross-origin=<origin> ...]\n fabrika control namespaces list\n fabrika control namespaces get --namespace=<id>\n fabrika control namespaces plan --namespace=<id> --env=<name> --preset=<cheap|mid|full> [placement]\n fabrika control namespaces create --namespace=<id> --env=<name> --preset=<cheap|mid|full> [placement]\n fabrika control namespaces reconcile --namespace=<id>\n fabrika control namespaces update --namespace=<id> --proxy-source=current\n fabrika control namespaces remove --namespace=<id>\n fabrika control namespaces release-claims --namespace=<id> --app=<id> --env=<name>\n fabrika control deploy --app=<id> --env=<name> [--ref=<ref>]\n fabrika control runs list [--app=<id>] [--env=<name>] [--limit=<n>]\n fabrika control runs get --run=<id>\n fabrika control runs log --run=<id>\n\n`register` CREATES an app and refuses a second one with the same id. Re-registering a changed\nmanifest \u2014 a new `zerops.yaml`, a new import document \u2014 is `apps environments put`, which replaces\none environment's envelopes and leaves the app row alone.\n\nA manifest that publishes the app through the namespace proxy is routed by HOST, so `--domain` is\nREQUIRED for it \u2014 on `register` and on `apps environments put` alike \u2014 and a registration without one is\nrefused before anything is created. `namespaces get` lists the hosts a `zerops-subdomain` namespace\nserves and which of them are still free; a custom-domain namespace serves the domain you bound to its\nproxy. A manifest with no proxy target needs no domain.\n\nA variable's value is stored and printed in clear. A secret's value is write-only: `apps secrets put`\nreads it from STDIN, never from a flag, so it reaches neither shell history nor a process listing, and\none trailing newline is dropped. No command prints it back; `apps secrets list` shows names, scope and\nstorage only. Generate one in the pipe:\n\n openssl rand -base64 32 | fabrika control apps secrets put --app=<id> --name=<name>\n\n`--public-origin` is where IAM may return a signed-in person: without one, sign-in to the environment is\nrefused. When `register` is given none and the namespace lists `--domain` among its hosts, it sets\n`https://<domain>` and says so on stderr. A custom domain needs the flag.\n\n`--cross-origin` names an origin whose pages may call the environment's cross-origin endpoints (ADR-0022), and\nrepeats: the flags given are the environment's whole list. Each is an exact origin with a literal host\n(`https://app.example.com`; `http://` only for a local one), never the environment's own domain, at most 16.\n`apps environments put` without the flag keeps the stored list, and a lone empty `--cross-origin=` clears it.\nOn Zerops the change reaches the namespace proxy at once; on Cloudflare the next deploy of the environment\napplies it.\n\n`--installation-id` has three states: omitted resolves the installation from the organization's\nconnected GitHub App, `none` registers an anonymous PUBLIC repository source, and a number names one\ninstallation outright. With `none`, control reads the repository once without a token and refuses one\nGitHub hides: a private repository needs the GitHub App connected in the console first.\n\n`--trigger-ref` is the git ref whose push deploys the environment; without it the environment deploys only\non `deploy`. A bare name is a branch: `--trigger-ref=deploy/prod` is stored as `refs/heads/deploy/prod`.\nA full ref is kept as given: `refs/heads/<branch>`, `refs/tags/<tag>`, or a `*` glob such as\n`refs/tags/v*`, which deploys every matching tag. A tag always needs the `refs/tags/` form. Each\nenvironment of an app needs its own trigger ref.\n\nNamespace placement options, each defaulting to what the preset would choose:\n\n --project=<name> the provider project the namespace owns; on Zerops the default is\n fabrika-<env>-<namespace id>, beside the installation's fabrika-<env>\n --core-package=<LIGHT|SERIOUS> defaults to LIGHT on every environment, `prod` included (ADR-0038).\n SERIOUS is a deliberate choice: a project cannot be downgraded again\n --public-access=<custom-domain|zerops-subdomain>\n --exclusive-app=<id> required by, and only by, the `full` preset\n --postgres-type=<type> the `cheap` preset's shared PostgreSQL; on Zerops postgresql:single@18\n (default) or postgresql:ha@18, which keeps its data through a node loss.\n Fixed once created\n --postgres-profile=<profile> its profile, given together with --postgres-type: oltp-hobby for single,\n oltp-staging (about $11) or oltp-production (about $72) for HA\n\n`namespaces plan` is a preview and changes nothing. It prints one `<path>\\t<value>` row per field of\nthe plan, keyed by its path in `--json`; a multi-line value such as the proxy's descriptor file is shown\nby size only. `namespaces create` commits that exact plan \u2014 the\nsame two steps the console's form takes \u2014 and returns as soon as the placement is recorded: provisioning\nruns behind the control queue and takes minutes, so the state comes back `pending`. Follow it with\n`namespaces get` or `namespaces list`; nothing needs to stay connected. `namespaces remove` frees the id\nof a placement no application is registered in. It deletes nothing at the provider and prints, on stderr,\nthe provider resources it stopped tracking. `namespaces update --proxy-source=current` re-pins a placement's\nproxy to the source this control plane deploys new placements from \u2014 a placement keeps the one it was created\nwith until you do \u2014 and queues the reconcile that rebuilds the proxy from it; a `failed` placement accepts it.\n\n`namespaces release-claims` frees the resource names one app environment holds in a placement, which an\nenvironment or app delete otherwise refuses over. Delete those resources at the provider first: the release\nreads each one back and refuses, naming it, while any still exists. It prints one released key per line.\n\nEvery command accepts --json, which prints the procedure's result verbatim.\n\nThe control origin is not a credential and takes either form:\n\n --url=<origin> FABRIKA_CONTROL_URL\n\nCredentials are read from the ENVIRONMENT ONLY and have no flag, so they cannot reach a CI log or a\nprocess listing:\n\n FABRIKA_CONTROL_KEY required a machine `px_` credential for the control app\n\n`key issue` mints that credential and therefore authenticates differently \u2014 it presents the\ninstallation's IAM RPC key as transport authentication and its provisioning key as the ISSUING\ncredential. Every key expires: `--expires-in` is required and at most 2592000 (30 days). Both\ncredentials are read from the environment only:\n\n FABRIKA_IAM_RPC_URL required IAM's PUBLIC origin, or --iam-url\n FABRIKA_IAM_RPC_KEY required the installation's IAM RPC key\n FABRIKA_IAM_PROVISIONING_KEY required the installation's seeded `px_` provisioning key\n FABRIKA_CONTROL_APP_ID optional the control app's IAM id (default `vozka`)\n\nThe PUBLIC origin is the `https://` address the installation answers on \u2014 the one `platform admin`\nand `platform init` print in their closing block, and the value `FABRIKA_IAM_ISSUER` holds on the\ncontrol service. It is NOT the private hostname the services use between themselves: `http://iam:3000`\nresolves inside the provider's project and nowhere else, so from here it only ever fails to connect.\n\nConnecting a GitHub source is NOT here and will not be: App creation is a browser flow whose\nauthorization requires a human principal (ADR-0029). Use Settings \u2192 Source in the console.\n";
3
4
  interface Flags {
4
5
  readonly values: ReadonlyMap<string, string>;
5
6
  /** Every value of every option, in order; `values` keeps the last. Only a repeatable option reads it. */
@@ -9,6 +10,20 @@ interface Flags {
9
10
  }
10
11
  /** Split `--key=value` options from positional words; `--json` is the one flag every verb shares. */
11
12
  export declare const parseControlFlags: (argv: readonly string[]) => Flags;
13
+ /** The console's client with a bearer instead of a cookie, and no SSO bounce: there is no browser to send. */
14
+ export type ControlClient = InferRpcClient<ControlRpcContract>;
15
+ /**
16
+ * Control's origin, checked before the key is sent anywhere: https, or http to a loopback host for local development,
17
+ * and nothing but scheme, host and port. A refusal never repeats the value, which may hold userinfo.
18
+ */
19
+ export declare const controlOrigin: (raw: string | undefined) => string;
20
+ /** `text` with the control key cut out: every diagnostic of an area that holds the key passes through it. */
21
+ export declare const withoutControlKey: (text: string, env: Readonly<Record<string, string | undefined>>) => string;
22
+ /**
23
+ * The one client of Control that `fabrika control` and `fabrika env` share: the origin from `url` or
24
+ * FABRIKA_CONTROL_URL, the key from FABRIKA_CONTROL_KEY in the environment only, no redirect followed.
25
+ */
26
+ export declare const connectControl: (url: string | undefined, env: Readonly<Record<string, string | undefined>>) => ControlClient;
12
27
  /** The exact text `app build` would write, and the provider whose envelope carries it. */
13
28
  export interface CompiledManifest {
14
29
  readonly provider: string;
@@ -0,0 +1,4 @@
1
+ declare const USAGE = "fabrika env \u2014 an application environment's data, through the control plane\n\nUsage:\n fabrika env inspect <app> <env> [--content] [--json]\n fabrika env maintenance <app> <env> <open|read-only|closed> [--json]\n fabrika env operations <app> <env> [--json]\n fabrika env recover <app> <env> <operationId> <resume|open> [--json]\n fabrika env backups <app> <env> [--json]\n fabrika env backups schedule <app> <env> [on|off] [--json]\n fabrika env restore <app> <env> --at=<time> [--json]\n\n`inspect` prints the environment's data view: the object's maintenance mode and generation, the database size and\neach table's row count (a count at 100000 reads `100000+`: it is capped), the applied migrations,\nthe scheduler's alarm, each job's last run, file and webhook counts, and when the application last failed to boot.\nIt needs `data.read`. `--content` adds the boot failure's message and stack, which are the application's own text,\nand needs `data.content.read` granted globally.\n\n`maintenance` puts the environment into a mode: `read-only` refuses writes, `closed` refuses every request, and\n`open` serves again. It starts a data operation and prints it; `operations` follows it. It needs `data.manage`.\n\n`operations` lists the environment's data operations, newest first, one row each:\n<id> <kind> <state> <step> <target mode> <generation> <error code> <created at>.\n\n`recover` fences an environment whose operation is stuck in `closed` at a fresh generation, then `resume`s that\noperation from its recorded step, or `open`s the environment. A failed operation can only be opened past. It needs\n`data.manage`.\n\n`backups` lists the environment's consistent backups, newest first, one row each:\n<id> <object> <state> <created at> <size bytes> <parts> <tables> <rehearsal> <rehearsal code> <error code> <expired>\n<pre-migration>.\nA backup counts as `succeeded` only once its rehearsal, an import into a scratch object, passed. One older than 30\ndays is `expired` and never offered for a restore. The last column is `pre-migration` for the backup a migration\ntakes before its deploy, and `-` for any other, such as a daily backup or a restore's. It needs `data.read`.\n\n`backups schedule` prints whether the environment takes a daily backup; `on` or `off` sets it, which needs\n`data.manage`. Turning it off stops the daily backup only: the backup before a migration still runs.\n\n`restore` brings back the environment's data as it was at `--at`, an ISO 8601 time with an offset in the past. It\nis a side restore: the serving object is frozen read-only and backed up, the backup is imported into a new clone\nobject, ordinary traffic is pointed at the clone, which serves the current data from then on, and the original is\nrewound to that time and kept in `inspect`, serving nothing, for inspection. It starts a data operation and prints\nit; `operations` follows it. It needs `data.manage`.\n\nA release of the control plane that does not offer a command answers that it is not available; retrying does not\nchange that. An environment the caller may not see answers `not_found`, as one that does not exist.\n\nstdout carries data only; progress and follow-up commands go to stderr. `--json` prints the result as JSON.\n\nThe control origin takes either form:\n\n --url=<origin> FABRIKA_CONTROL_URL\n\nThe credential is read from the ENVIRONMENT ONLY and has no flag:\n\n FABRIKA_CONTROL_KEY required a machine `px_` credential for the control app\n";
2
+ type Environment = Readonly<Record<string, string | undefined>>;
3
+ export declare const runEnvCli: (command: string | undefined, argv: readonly string[], env?: Environment) => Promise<void>;
4
+ export { USAGE as ENV_USAGE };
package/types/src/db.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const DB_USAGE = "fabrika db \u2014 an application's Postgres schema\n\nUsage:\n fabrika db new <slug> Write db/migrations/<UTC YYYYMMDDHHMMSS>_<slug>.sql; the slug is lowercase snake_case.\n fabrika db migrate Apply the framework's tables, then db/migrations, to the application's schema app_<id>.\n fabrika db codegen [--verify] Write src/db/schema.generated.ts from the migrated schema; --verify only fails when it is stale.\n fabrika db test-scaffold Write the generated tests: a policy isolation test per table a store reaches, the endpoint access test.\n fabrika db test-isolation [--verbose] Run the generated tests on a throwaway schema; fail unless every case the scaffold wrote passed.\n\nRun from the application root. `migrate` and `codegen` read FABRIKA_APP_ID and FABRIKA_APP_DATABASE_URL from\nthe environment only. FABRIKA_APP_DATABASE_URL is the provisioning credential: `migrate` uses it only to create\nthe application's roles (app_<id> owns the schema, run_<id> gets DML on its tables) and fails when it cannot create\nroles. It applies the files as app_<id>, holds a lock derived from the application id, runs each file in one\ntransaction with lock_timeout 5000 ms and statement_timeout 60000 ms, and fails when a\nfile that already ran has changed: an applied migration is immutable, so a change is a new file.\n`test-scaffold` reads fabrika.contract.ts and src/db/tables.ts as the checker does, rewrites every generated test and\ndeletes a generated one the scaffold no longer writes, printing each path, or that it wrote none; @fabrika/check refuses\none that is missing, edited or stale.\n`test-isolation` is the platform's run of them: with FABRIKA_APP_DATABASE_URL it creates a throwaway provisioner\n(CREATEROLE, CREATE on the database, nothing of any application) that the tests get instead, ignores the application's\nbunfig.toml, and checks the JUnit report against the case names the scaffold wrote. It first drops the provisioners\nthat killed runs left behind: expired, and without a session of their own or of a role they created. A database at its\nconnection limit (SQLSTATE 53300) is waited for; one that never frees a slot fails the run saying so,\nnever as failed cases.\n";
1
+ export declare const DB_USAGE = "fabrika db \u2014 an application's database schema: Postgres, or SQLite on Cloudflare\n\nUsage:\n fabrika db new <slug> Write db/migrations/<UTC YYYYMMDDHHMMSS>_<slug>.sql; the slug is lowercase snake_case.\n fabrika db migrate Apply the framework's tables, then db/migrations, to the application's schema app_<id>.\n fabrika db codegen [--verify] Write src/db/schema.generated.ts from the migrated schema; --verify only fails when it is stale.\n fabrika db test-scaffold Write the generated tests: a policy isolation test per table a store reaches, the endpoint access test.\n fabrika db test-isolation [--verbose] Run the generated tests on a throwaway schema; fail unless every case the scaffold wrote passed.\n\nRun from the application root. `migrate` and `codegen` read FABRIKA_APP_ID and FABRIKA_APP_DATABASE_URL from\nthe environment only. FABRIKA_APP_DATABASE_URL is the provisioning credential: `migrate` uses it only to create\nthe application's roles (app_<id> owns the schema, run_<id> gets DML on its tables) and fails when it cannot create\nroles. It applies the files as app_<id>, holds a lock derived from the application id, runs each file in one\ntransaction with lock_timeout 5000 ms and statement_timeout 60000 ms, and fails when a\nfile that already ran has changed: an applied migration is immutable, so a change is a new file.\n`test-scaffold` reads fabrika.contract.ts and src/db/tables.ts as the checker does, rewrites every generated test and\ndeletes a generated one the scaffold no longer writes, printing each path, or that it wrote none; @fabrika/check refuses\none that is missing, edited or stale.\n`test-isolation` is the platform's run of them: with FABRIKA_APP_DATABASE_URL it creates a throwaway provisioner\n(CREATEROLE, CREATE on the database, nothing of any application) that the tests get instead, ignores the application's\nbunfig.toml, and checks the JUnit report against the case names the scaffold wrote. It first drops the provisioners\nthat killed runs left behind: expired, and without a session of their own or of a role they created. A database at its\nconnection limit (SQLSTATE 53300) is waited for; one that never frees a slot fails the run saying so,\nnever as failed cases.\n\nAn application whose fabrika.config.ts default-exports @fabrika/provider-cloudflare's defineApp runs on SQLite in its\nDurable Object, which applies the migrations itself when it boots: `migrate` refuses, `codegen` applies them to an\nin-memory database, and the generated tests run on @fabrika/db/testing-sqlite; none of them needs a database URL.\n";
2
2
  export interface DbCommandDependencies {
3
3
  /** The application root. */
4
4
  readonly cwd: string;
@@ -8,6 +8,4 @@ export interface ParsedCommand {
8
8
  }
9
9
  export declare const parseCliArgs: (argv: readonly string[]) => ParsedCommand;
10
10
  export declare const providerFromConfig: (argv: readonly string[]) => Promise<string | undefined>;
11
- export type AppCliRunner = (argv: readonly string[]) => Promise<void>;
12
- export declare const appCliRunnerFromModule: (loaded: unknown, packageName: string, exportName: string) => AppCliRunner;
13
11
  export declare const runCli: (argv: readonly string[]) => Promise<void>;
@@ -1,17 +1,12 @@
1
- import { type ZeropsCliArgs } from '@fabrika/provider-zerops';
2
- export declare const NAMESPACE_USAGE = "fabrika namespace \u2014 Zerops deployment namespaces\n\nUsage:\n fabrika namespace plan --provider=zerops --id=<id> --env=<env> --preset=<cheap|mid|full> [namespace options]\n fabrika namespace create --provider=zerops --id=<id> --env=<env> --preset=<cheap|mid|full> [namespace options] [--control-url=<url>]\n fabrika namespace adopt --provider=zerops --id=<id> --env=<env> --preset=<cheap|mid|full> --project-id=<id> [namespace options] [--control-url=<url>]\n fabrika namespace reconcile --provider=zerops --id=<id> [--control-url=<url>]\n\nOptions:\n --id=<id> Namespace id.\n --env=<env> Environment.\n --preset=<cheap|mid|full> Provider-owned namespace preset.\n --exclusive-app=<id> App reserved by a full namespace.\n --project-id=<id> Existing Zerops project id for adoption.\n --project-name=<name> Zerops project name (create: default fabrika-<env>-<id>;\n adopt: the existing project's name, default the namespace id).\n --core-package=<tier> LIGHT or SERIOUS.\n --public-access=<mode> custom-domain or zerops-subdomain.\n --postgres-type=<type> Cheap-tier PostgreSQL type.\n --postgres-profile=<profile> Cheap-tier PostgreSQL profile.\n --control-url=<url> Control origin; or FABRIKA_CONTROL_URL.\n --json Print the result as JSON instead of rows.\n -h, --help Show this help.\n\n`plan` prints one `<path>\\t<value>` row per field of the plan, keyed by its path in --json; a multi-line\nvalue such as the proxy's descriptor file is shown by size only. The other commands print one\n`<id>\\t<env>\\t<state>\\t<exclusive app>` row.\n\nMutating namespace commands read the Bearer credential from FABRIKA_CONTROL_TOKEN.\nPlan/create/adopt require FABRIKA_ZEROPS_PROXY_SOURCE_JSON:\n {\"repository\":{\"owner\":\"...\",\"name\":\"...\"},\"commitSha\":\"...\",\"descriptor\":{\"path\":\"zerops.yaml\",\"contents\":\"...\",\"sha256\":\"...\"}}\nReconcile uses the persisted namespace source.\n";
3
- export interface ZeropsNamespaceCommand {
4
- readonly args: ZeropsCliArgs;
5
- /** The result as JSON; otherwise the rows `fabrika control namespaces` prints. */
6
- readonly json: boolean;
7
- }
8
- export interface ZeropsNamespaceCommandDependencies {
1
+ import type { NamespaceCli } from '@fabrika/provider-contract/app-cli';
2
+ export declare const NAMESPACE_USAGE = "fabrika namespace \u2014 deployment namespaces\n\nUsage:\n fabrika namespace <plan|create|adopt|reconcile> --provider=<name> [provider options] [--json]\n\nThe commands and their options are the provider's: `fabrika namespace --provider=<name> --help` prints them.\n";
3
+ export interface NamespaceCommandDependencies {
9
4
  readonly source: Readonly<Record<string, string | undefined>>;
10
5
  readonly fetch: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
11
6
  readonly write: (value: string) => void;
12
7
  }
13
- /** Execute one namespace command. All command inputs are validated before the first fetch. */
14
- export declare const runZeropsNamespaceCommand: (command: ZeropsNamespaceCommand, deps: ZeropsNamespaceCommandDependencies) => Promise<void>;
15
- /** `--json` is this area's own flag, so it is taken out before the provider's parser, which refuses unknown options. */
16
- export declare const parseZeropsNamespaceCommand: (subcommand: string, argv: readonly string[]) => ZeropsNamespaceCommand;
17
- export declare const runZeropsNamespaceCli: (subcommand: string, argv: readonly string[]) => Promise<void>;
8
+ /**
9
+ * Run one provider's namespace command and print what it answers. `--json` and `--control-url` are this area's own
10
+ * options, so they are taken out before the provider's parser, which refuses unknown options.
11
+ */
12
+ export declare const runNamespaceCommand: (cli: NamespaceCli, subcommand: string, argv: readonly string[], deps: NamespaceCommandDependencies) => Promise<void>;