@fabrika/cli 0.9.0-cloudflare.1 → 0.9.0-cloudflare.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.
- package/package.json +12 -12
- package/src/control.ts +73 -8
- package/src/data.ts +444 -0
- package/src/index.ts +15 -1
- package/types/src/control.d.ts +16 -1
- package/types/src/data.d.ts +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/cli",
|
|
3
|
-
"version": "0.9.0-cloudflare.
|
|
3
|
+
"version": "0.9.0-cloudflare.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,19 +31,19 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"zod": "^3.25.76",
|
|
34
|
-
"@fabrika/app": "0.9.0-cloudflare.
|
|
35
|
-
"@fabrika/auth-core": "0.9.0-cloudflare.
|
|
36
|
-
"@fabrika/control-contract": "0.9.0-cloudflare.
|
|
37
|
-
"@fabrika/provider-contract": "0.9.0-cloudflare.
|
|
38
|
-
"@fabrika/db": "0.9.0-cloudflare.
|
|
39
|
-
"@fabrika/platform": "0.9.0-cloudflare.
|
|
40
|
-
"@fabrika/platform-node": "0.9.0-cloudflare.
|
|
41
|
-
"@fabrika/check": "0.9.0-cloudflare.
|
|
34
|
+
"@fabrika/app": "0.9.0-cloudflare.3",
|
|
35
|
+
"@fabrika/auth-core": "0.9.0-cloudflare.3",
|
|
36
|
+
"@fabrika/control-contract": "0.9.0-cloudflare.3",
|
|
37
|
+
"@fabrika/provider-contract": "0.9.0-cloudflare.3",
|
|
38
|
+
"@fabrika/db": "0.9.0-cloudflare.3",
|
|
39
|
+
"@fabrika/platform": "0.9.0-cloudflare.3",
|
|
40
|
+
"@fabrika/platform-node": "0.9.0-cloudflare.3",
|
|
41
|
+
"@fabrika/check": "0.9.0-cloudflare.3"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@fabrika/builder": "0.9.0-cloudflare.
|
|
45
|
-
"@fabrika/provider-cloudflare": "0.9.0-cloudflare.
|
|
46
|
-
"@fabrika/provider-zerops": "0.9.0-cloudflare.
|
|
44
|
+
"@fabrika/builder": "0.9.0-cloudflare.3",
|
|
45
|
+
"@fabrika/provider-cloudflare": "0.9.0-cloudflare.3",
|
|
46
|
+
"@fabrika/provider-zerops": "0.9.0-cloudflare.3"
|
|
47
47
|
},
|
|
48
48
|
"peerDependenciesMeta": {
|
|
49
49
|
"@fabrika/builder": {
|
package/src/control.ts
CHANGED
|
@@ -278,21 +278,85 @@ const secret = (variable: string, env: Readonly<Record<string, string | undefine
|
|
|
278
278
|
}
|
|
279
279
|
|
|
280
280
|
/** The console's client with a bearer instead of a cookie, and no SSO bounce: there is no browser to send. */
|
|
281
|
-
type ControlClient = InferRpcClient<ControlRpcContract>
|
|
281
|
+
export type ControlClient = InferRpcClient<ControlRpcContract>
|
|
282
282
|
|
|
283
|
-
|
|
284
|
-
|
|
283
|
+
/** Plain http may carry the key to loopback only: 127.0.0.0/8, [::1], and the names RFC 6761 reserves for it, `localhost` and `*.localhost`. */
|
|
284
|
+
const LOOPBACK_HOST = /^(?:localhost|.+\.localhost|127\.\d{1,3}\.\d{1,3}\.\d{1,3}|\[::1\])$/
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Control's origin, checked before the key is sent anywhere: https, or http to a loopback host for local development,
|
|
288
|
+
* and nothing but scheme, host and port. A refusal never repeats the value, which may hold userinfo.
|
|
289
|
+
*/
|
|
290
|
+
export const controlOrigin = (raw: string | undefined): string => {
|
|
291
|
+
if (raw === undefined || raw.trim() === '') {
|
|
292
|
+
throw new Error('Control origin is required. Pass --url=<origin> or set FABRIKA_CONTROL_URL.')
|
|
293
|
+
}
|
|
294
|
+
let url: URL
|
|
295
|
+
try {
|
|
296
|
+
url = new URL(raw.trim())
|
|
297
|
+
} catch {
|
|
298
|
+
throw new Error('--url or FABRIKA_CONTROL_URL is not a URL')
|
|
299
|
+
}
|
|
300
|
+
if (url.protocol !== 'https:' && !(url.protocol === 'http:' && LOOPBACK_HOST.test(url.hostname))) {
|
|
301
|
+
throw new Error('--url or FABRIKA_CONTROL_URL must be https; plain http only to localhost, *.localhost, 127.0.0.0/8 or [::1]')
|
|
302
|
+
}
|
|
303
|
+
if (url.username !== '' || url.password !== '' || url.pathname !== '/' || url.search !== '' || url.hash !== '' || /[?#]/.test(raw)) {
|
|
304
|
+
throw new Error('--url or FABRIKA_CONTROL_URL must be an origin only: no credentials, path, query or fragment')
|
|
305
|
+
}
|
|
306
|
+
return url.origin
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const KEY_LABEL = '[FABRIKA_CONTROL_KEY]'
|
|
310
|
+
|
|
311
|
+
/** `text` with the control key cut out: every diagnostic of an area that holds the key passes through it. */
|
|
312
|
+
export const withoutControlKey = (text: string, env: Readonly<Record<string, string | undefined>>): string => {
|
|
313
|
+
const key = env['FABRIKA_CONTROL_KEY']?.trim()
|
|
314
|
+
return key === undefined || key === '' ? text : text.replaceAll(key, KEY_LABEL)
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** Whether a JSON body holds `key`, also behind JSON escapes, which a plain search of the text would miss. */
|
|
318
|
+
const carriesKey = (text: string, key: string): boolean => {
|
|
319
|
+
if (text.includes(key)) return true
|
|
320
|
+
try {
|
|
321
|
+
return JSON.stringify(JSON.parse(text)).includes(JSON.stringify(key).slice(1, -1))
|
|
322
|
+
} catch {
|
|
323
|
+
return false
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* A JSON answer that carries the key is dropped whole, so no row, `--json` output or error can repeat it. Any other
|
|
329
|
+
* body passes: the RPC client reports a non-JSON answer by its status alone.
|
|
330
|
+
*/
|
|
331
|
+
const withoutEchoedKey = async (response: Response, key: string): Promise<Response> => {
|
|
332
|
+
if (!(response.headers.get('content-type') ?? '').includes('application/json')) return response
|
|
333
|
+
const text = await response.text()
|
|
334
|
+
if (carriesKey(text, key)) {
|
|
335
|
+
return Response.json({ error: { type: 'transport', message: `Control's answer carried ${KEY_LABEL}; it was dropped` } }, { status: 502 })
|
|
336
|
+
}
|
|
337
|
+
return new Response(text, { status: response.status, statusText: response.statusText, headers: response.headers })
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* The one client of Control that `fabrika control` and `fabrika env` share: the origin from `url` or
|
|
342
|
+
* FABRIKA_CONTROL_URL, the key from FABRIKA_CONTROL_KEY in the environment only, no redirect followed.
|
|
343
|
+
*/
|
|
344
|
+
export const connectControl = (url: string | undefined, env: Readonly<Record<string, string | undefined>>): ControlClient => {
|
|
345
|
+
const base = controlOrigin(url ?? env['FABRIKA_CONTROL_URL'])
|
|
285
346
|
const key = secret('FABRIKA_CONTROL_KEY', env)
|
|
286
347
|
return createRpcClient<ControlRpcContract>({
|
|
287
348
|
baseUrl: `${base}/api/rpc`,
|
|
288
|
-
fetch: (input, init) => {
|
|
349
|
+
fetch: async (input, init) => {
|
|
289
350
|
const headers = new Headers(init?.headers)
|
|
290
351
|
headers.set('authorization', `Bearer ${key}`)
|
|
291
|
-
|
|
352
|
+
// A redirect would carry the bearer to wherever it points.
|
|
353
|
+
return await withoutEchoedKey(await fetch(input, { ...init, headers, redirect: 'manual' }), key)
|
|
292
354
|
},
|
|
293
355
|
})
|
|
294
356
|
}
|
|
295
357
|
|
|
358
|
+
const controlClient = (flags: Flags, env: Readonly<Record<string, string | undefined>>): ControlClient => connectControl(flags.values.get('url'), env)
|
|
359
|
+
|
|
296
360
|
const readJsonFile = async (path: string): Promise<JsonValue> => {
|
|
297
361
|
const file = Bun.file(path)
|
|
298
362
|
if (!(await file.exists())) {
|
|
@@ -962,9 +1026,9 @@ export const runControlCli = async (
|
|
|
962
1026
|
env: Readonly<Record<string, string | undefined>> = process.env,
|
|
963
1027
|
input: SecretValueInput = processStdin,
|
|
964
1028
|
): Promise<void> => {
|
|
965
|
-
const flags = parseControlFlags(argv)
|
|
966
|
-
const verb = flags.positional[0]
|
|
967
1029
|
try {
|
|
1030
|
+
const flags = parseControlFlags(argv)
|
|
1031
|
+
const verb = flags.positional[0]
|
|
968
1032
|
switch (command) {
|
|
969
1033
|
case undefined:
|
|
970
1034
|
console.info(USAGE)
|
|
@@ -994,7 +1058,8 @@ export const runControlCli = async (
|
|
|
994
1058
|
} catch (error) {
|
|
995
1059
|
// An RPC denial is an ANSWER, not a transport fault; keep its type so a caller can tell "the
|
|
996
1060
|
// control plane said no" from "the control plane was unreachable".
|
|
997
|
-
|
|
1061
|
+
const message = error instanceof RpcError ? `${error.type}: ${error.message}` : error instanceof Error ? error.message : String(error)
|
|
1062
|
+
throw new Error(withoutControlKey(message, env))
|
|
998
1063
|
}
|
|
999
1064
|
}
|
|
1000
1065
|
|
package/src/data.ts
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
// The `fabrika env` command area: an application environment's data as Control serves it (ADR-0069). Every command is
|
|
2
|
+
// one `data.*` procedure of `ControlRpcContract`, reached through the client `fabrika control` uses (`connectControl`).
|
|
3
|
+
|
|
4
|
+
import { RpcError } from '@fabrika/app'
|
|
5
|
+
import {
|
|
6
|
+
OPS_ROW_COUNT_CAP,
|
|
7
|
+
type OpsContentView,
|
|
8
|
+
type OpsView,
|
|
9
|
+
parseApplicationObjectName,
|
|
10
|
+
parseOpsContentView,
|
|
11
|
+
parseOpsView,
|
|
12
|
+
} from '@fabrika/auth-core'
|
|
13
|
+
import { type DataBackupDto, type DataBackupScheduleDto, type DataOperationDto, startDataOperationInputSchema } from '@fabrika/control-contract'
|
|
14
|
+
import { z } from 'zod'
|
|
15
|
+
import { connectControl, type ControlClient, withoutControlKey } from './control.js'
|
|
16
|
+
|
|
17
|
+
const USAGE = `fabrika env — an application environment's data, through the control plane
|
|
18
|
+
|
|
19
|
+
Usage:
|
|
20
|
+
fabrika env inspect <app> <env> [--content] [--json]
|
|
21
|
+
fabrika env maintenance <app> <env> <open|read-only|closed> [--json]
|
|
22
|
+
fabrika env operations <app> <env> [--json]
|
|
23
|
+
fabrika env recover <app> <env> <operationId> <resume|open> [--json]
|
|
24
|
+
fabrika env backups <app> <env> [--json]
|
|
25
|
+
fabrika env backups schedule <app> <env> [on|off] [--json]
|
|
26
|
+
fabrika env restore <app> <env> --at=<time> [--json]
|
|
27
|
+
|
|
28
|
+
\`inspect\` prints the environment's data view: the object's maintenance mode and generation, the database size and
|
|
29
|
+
each table's row count (a count at ${OPS_ROW_COUNT_CAP} reads \`${OPS_ROW_COUNT_CAP}+\`: it is capped), the applied migrations,
|
|
30
|
+
the scheduler's alarm, each job's last run, file and webhook counts, and when the application last failed to boot.
|
|
31
|
+
It needs \`data.read\`. \`--content\` adds the boot failure's message and stack, which are the application's own text,
|
|
32
|
+
and needs \`data.content.read\` granted globally.
|
|
33
|
+
|
|
34
|
+
\`maintenance\` puts the environment into a mode: \`read-only\` refuses writes, \`closed\` refuses every request, and
|
|
35
|
+
\`open\` serves again. It starts a data operation and prints it; \`operations\` follows it. It needs \`data.manage\`.
|
|
36
|
+
|
|
37
|
+
\`operations\` lists the environment's data operations, newest first, one row each:
|
|
38
|
+
<id> <kind> <state> <step> <target mode> <generation> <error code> <created at>.
|
|
39
|
+
|
|
40
|
+
\`recover\` fences an environment whose operation is stuck in \`closed\` at a fresh generation, then \`resume\`s that
|
|
41
|
+
operation from its recorded step, or \`open\`s the environment. A failed operation can only be opened past. It needs
|
|
42
|
+
\`data.manage\`.
|
|
43
|
+
|
|
44
|
+
\`backups\` lists the environment's consistent backups, newest first, one row each:
|
|
45
|
+
<id> <object> <state> <created at> <size bytes> <parts> <tables> <rehearsal> <rehearsal code> <error code> <expired>
|
|
46
|
+
<pre-migration>.
|
|
47
|
+
A backup counts as \`succeeded\` only once its rehearsal, an import into a scratch object, passed. One older than 30
|
|
48
|
+
days is \`expired\` and never offered for a restore. The last column is \`pre-migration\` for the backup a migration
|
|
49
|
+
takes before its deploy, and \`-\` for any other, such as a daily backup or a restore's. It needs \`data.read\`.
|
|
50
|
+
|
|
51
|
+
\`backups schedule\` prints whether the environment takes a daily backup; \`on\` or \`off\` sets it, which needs
|
|
52
|
+
\`data.manage\`. Turning it off stops the daily backup only: the backup before a migration still runs.
|
|
53
|
+
|
|
54
|
+
\`restore\` brings back the environment's data as it was at \`--at\`, an ISO 8601 time with an offset in the past. It
|
|
55
|
+
is a side restore: the serving object is frozen read-only and backed up, the backup is imported into a new clone
|
|
56
|
+
object, ordinary traffic is pointed at the clone, which serves the current data from then on, and the original is
|
|
57
|
+
rewound to that time and kept in \`inspect\`, serving nothing, for inspection. It starts a data operation and prints
|
|
58
|
+
it; \`operations\` follows it. It needs \`data.manage\`.
|
|
59
|
+
|
|
60
|
+
A release of the control plane that does not offer a command answers that it is not available; retrying does not
|
|
61
|
+
change that. An environment the caller may not see answers \`not_found\`, as one that does not exist.
|
|
62
|
+
|
|
63
|
+
stdout carries data only; progress and follow-up commands go to stderr. \`--json\` prints the result as JSON.
|
|
64
|
+
|
|
65
|
+
The control origin takes either form:
|
|
66
|
+
|
|
67
|
+
--url=<origin> FABRIKA_CONTROL_URL
|
|
68
|
+
|
|
69
|
+
The credential is read from the ENVIRONMENT ONLY and has no flag:
|
|
70
|
+
|
|
71
|
+
FABRIKA_CONTROL_KEY required a machine \`px_\` credential for the control app
|
|
72
|
+
`
|
|
73
|
+
|
|
74
|
+
type Environment = Readonly<Record<string, string | undefined>>
|
|
75
|
+
|
|
76
|
+
interface EnvArgs {
|
|
77
|
+
readonly positional: readonly string[]
|
|
78
|
+
readonly json: boolean
|
|
79
|
+
readonly content: boolean
|
|
80
|
+
readonly url: string | undefined
|
|
81
|
+
/** \`''\` when \`--at\` closes the arguments with no time after it. */
|
|
82
|
+
readonly at: string | undefined
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const COMMAND_FORMS: Readonly<Record<string, string>> = {
|
|
86
|
+
inspect: '<app> <env> [--content] [--json]',
|
|
87
|
+
maintenance: '<app> <env> <open|read-only|closed> [--json]',
|
|
88
|
+
operations: '<app> <env> [--json]',
|
|
89
|
+
recover: '<app> <env> <operationId> <resume|open> [--json]',
|
|
90
|
+
backups: '<app> <env> [--json]',
|
|
91
|
+
'backups schedule': '<app> <env> [on|off] [--json]',
|
|
92
|
+
restore: '<app> <env> --at=<time> [--json]',
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const parseEnvArgs = (argv: readonly string[]): EnvArgs => {
|
|
96
|
+
const positional: string[] = []
|
|
97
|
+
let json = false
|
|
98
|
+
let content = false
|
|
99
|
+
let url: string | undefined
|
|
100
|
+
let at: string | undefined
|
|
101
|
+
for (let index = 0; index < argv.length; index++) {
|
|
102
|
+
const arg = argv[index] ?? ''
|
|
103
|
+
if (arg === '--json') json = true
|
|
104
|
+
else if (arg === '--content') content = true
|
|
105
|
+
else if (arg.startsWith('--url=')) url = arg.slice('--url='.length)
|
|
106
|
+
else if (arg.startsWith('--at=')) at = arg.slice('--at='.length)
|
|
107
|
+
else if (arg === '--at') at = argv[++index] ?? ''
|
|
108
|
+
else if (arg.startsWith('-')) throw new Error(`Unknown option: ${arg}`)
|
|
109
|
+
else positional.push(arg)
|
|
110
|
+
}
|
|
111
|
+
return { positional, json, content, url, at }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** The positional words of `command`, exactly `count` of them. */
|
|
115
|
+
const words = (command: string, args: EnvArgs, count: number): readonly string[] => {
|
|
116
|
+
if (args.positional.length !== count || args.positional.some((word) => word.trim() === '')) throw usage(command)
|
|
117
|
+
return args.positional
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const usage = (command: string): Error => new Error(`Usage: fabrika env ${command} ${COMMAND_FORMS[command] ?? ''}`)
|
|
121
|
+
|
|
122
|
+
const controlClient = (args: EnvArgs, env: Environment): ControlClient => connectControl(args.url, env)
|
|
123
|
+
|
|
124
|
+
/** Control's own rule for an operation's or a backup's error code (`db/data-operations.ts`, `db/backups.ts`). */
|
|
125
|
+
const ERROR_CODE = /^[a-z][a-z0-9_]{0,63}$/
|
|
126
|
+
|
|
127
|
+
/** The known fields of an operation, validated; a field a newer Control adds is dropped, never printed. */
|
|
128
|
+
const dataOperationSchema: z.ZodType<DataOperationDto, z.ZodTypeDef, unknown> = z.object({
|
|
129
|
+
id: z.string().uuid(),
|
|
130
|
+
appId: z.string(),
|
|
131
|
+
env: z.string(),
|
|
132
|
+
kind: z.enum(['maintenance', 'backup', 'migrate', 'recovery', 'restore']),
|
|
133
|
+
step: z.enum([
|
|
134
|
+
'reconcile',
|
|
135
|
+
'restrict',
|
|
136
|
+
'backup',
|
|
137
|
+
'verify',
|
|
138
|
+
'deploy',
|
|
139
|
+
'migrate',
|
|
140
|
+
'resume',
|
|
141
|
+
'open',
|
|
142
|
+
'list',
|
|
143
|
+
'import',
|
|
144
|
+
'promote',
|
|
145
|
+
'point',
|
|
146
|
+
'serve',
|
|
147
|
+
'rewind',
|
|
148
|
+
'check',
|
|
149
|
+
'revert',
|
|
150
|
+
]),
|
|
151
|
+
targetMode: z.enum(['open', 'read-only', 'closed', 'inspect']),
|
|
152
|
+
generation: z.number().int().nonnegative(),
|
|
153
|
+
state: z.enum(['running', 'succeeded', 'failed']),
|
|
154
|
+
errorCode: z.string().regex(ERROR_CODE).nullable(),
|
|
155
|
+
actor: z.string(),
|
|
156
|
+
createdAt: z.number().int().nonnegative(),
|
|
157
|
+
updatedAt: z.number().int().nonnegative(),
|
|
158
|
+
finishedAt: z.number().int().nonnegative().nullable(),
|
|
159
|
+
recoversOperationId: z.string().uuid().nullable(),
|
|
160
|
+
resolution: z.enum(['resume', 'open']).nullable(),
|
|
161
|
+
// Absent from a Control before the migration phase.
|
|
162
|
+
runId: z.string().uuid().nullable().default(null),
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
interface Target {
|
|
166
|
+
readonly appId: string
|
|
167
|
+
readonly env: string
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** An answer about the environment asked about, and of no other. */
|
|
171
|
+
const ofTarget = (answer: Target, target: Target): boolean => answer.appId === target.appId && answer.env === target.env
|
|
172
|
+
|
|
173
|
+
const parseOperation = (value: unknown, target: Target): DataOperationDto => {
|
|
174
|
+
const parsed = dataOperationSchema.safeParse(value)
|
|
175
|
+
if (!parsed.success || !ofTarget(parsed.data, target)) throw new Error('Control returned an unreadable data operation')
|
|
176
|
+
return parsed.data
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const dataOperationPageSchema = z.object({ items: z.array(dataOperationSchema), nextCursor: z.string().uuid().nullable() })
|
|
180
|
+
|
|
181
|
+
const parseOperationPage = (value: unknown, target: Target): { items: DataOperationDto[]; nextCursor: string | null } => {
|
|
182
|
+
const parsed = dataOperationPageSchema.safeParse(value)
|
|
183
|
+
if (!parsed.success || !parsed.data.items.every((operation) => ofTarget(operation, target))) {
|
|
184
|
+
throw new Error('Control returned an unreadable list of data operations')
|
|
185
|
+
}
|
|
186
|
+
return parsed.data
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** The known fields of a backup, validated as an operation's are. */
|
|
190
|
+
const dataBackupSchema: z.ZodType<DataBackupDto> = z.object({
|
|
191
|
+
id: z.string().uuid(),
|
|
192
|
+
appId: z.string(),
|
|
193
|
+
env: z.string(),
|
|
194
|
+
operationId: z.string().uuid(),
|
|
195
|
+
object: z.string().refine((name) => parseApplicationObjectName(name) !== null),
|
|
196
|
+
dumpId: z.string().uuid(),
|
|
197
|
+
preMigration: z.boolean(),
|
|
198
|
+
state: z.enum(['running', 'succeeded', 'failed']),
|
|
199
|
+
errorCode: z.string().regex(ERROR_CODE).nullable(),
|
|
200
|
+
createdAt: z.number().int().nonnegative(),
|
|
201
|
+
finishedAt: z.number().int().nonnegative().nullable(),
|
|
202
|
+
bookmark: z.string().nullable(),
|
|
203
|
+
sizeBytes: z.number().int().nonnegative().nullable(),
|
|
204
|
+
parts: z.number().int().nonnegative().nullable(),
|
|
205
|
+
tables: z.number().int().nonnegative().nullable(),
|
|
206
|
+
rehearsal: z.enum(['pending', 'passed', 'failed']),
|
|
207
|
+
rehearsalCode: z.string().regex(ERROR_CODE).nullable(),
|
|
208
|
+
expired: z.boolean(),
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
const dataBackupPageSchema = z.object({ items: z.array(dataBackupSchema), nextCursor: z.string().uuid().nullable() })
|
|
212
|
+
|
|
213
|
+
const parseBackupPage = (value: unknown, target: Target): { items: DataBackupDto[]; nextCursor: string | null } => {
|
|
214
|
+
const parsed = dataBackupPageSchema.safeParse(value)
|
|
215
|
+
if (!parsed.success || !parsed.data.items.every((backup) => ofTarget(backup, target))) {
|
|
216
|
+
throw new Error('Control returned an unreadable list of backups')
|
|
217
|
+
}
|
|
218
|
+
return parsed.data
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const dataBackupScheduleSchema: z.ZodType<DataBackupScheduleDto> = z.object({
|
|
222
|
+
appId: z.string(),
|
|
223
|
+
env: z.string(),
|
|
224
|
+
daily: z.boolean(),
|
|
225
|
+
updatedAt: z.number().int().nonnegative().nullable(),
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
const parseSchedule = (value: unknown, target: Target): DataBackupScheduleDto => {
|
|
229
|
+
const parsed = dataBackupScheduleSchema.safeParse(value)
|
|
230
|
+
if (!parsed.success || !ofTarget(parsed.data, target)) throw new Error('Control returned an unreadable backup schedule')
|
|
231
|
+
return parsed.data
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const MAINTENANCE_MODES = ['open', 'read-only', 'closed'] as const
|
|
235
|
+
const RESOLUTIONS = ['resume', 'open'] as const
|
|
236
|
+
const SCHEDULE_SWITCHES = ['on', 'off'] as const
|
|
237
|
+
|
|
238
|
+
const oneOf = <T extends string>(value: string, allowed: readonly T[]): T | undefined => allowed.find((candidate) => candidate === value)
|
|
239
|
+
|
|
240
|
+
/** Control's timestamps are Unix seconds. */
|
|
241
|
+
const isoSeconds = (seconds: number): string => new Date(seconds * 1000).toISOString()
|
|
242
|
+
|
|
243
|
+
const operationLine = (operation: DataOperationDto): string =>
|
|
244
|
+
[
|
|
245
|
+
operation.id,
|
|
246
|
+
operation.kind,
|
|
247
|
+
operation.state,
|
|
248
|
+
operation.step,
|
|
249
|
+
operation.targetMode,
|
|
250
|
+
String(operation.generation),
|
|
251
|
+
operation.errorCode ?? '-',
|
|
252
|
+
isoSeconds(operation.createdAt),
|
|
253
|
+
].join('\t')
|
|
254
|
+
|
|
255
|
+
const backupLine = (backup: DataBackupDto): string =>
|
|
256
|
+
[
|
|
257
|
+
backup.id,
|
|
258
|
+
backup.object,
|
|
259
|
+
backup.state,
|
|
260
|
+
isoSeconds(backup.createdAt),
|
|
261
|
+
backup.sizeBytes === null ? '-' : String(backup.sizeBytes),
|
|
262
|
+
backup.parts === null ? '-' : String(backup.parts),
|
|
263
|
+
backup.tables === null ? '-' : String(backup.tables),
|
|
264
|
+
backup.rehearsal,
|
|
265
|
+
backup.rehearsalCode ?? '-',
|
|
266
|
+
backup.errorCode ?? '-',
|
|
267
|
+
backup.expired ? 'expired' : '-',
|
|
268
|
+
backup.preMigration ? 'pre-migration' : '-',
|
|
269
|
+
].join('\t')
|
|
270
|
+
|
|
271
|
+
const scheduleLines = (schedule: DataBackupScheduleDto): string =>
|
|
272
|
+
[`daily\t${schedule.daily ? 'on' : 'off'}`, `updatedAt\t${schedule.updatedAt === null ? '-' : isoSeconds(schedule.updatedAt)}`].join('\n')
|
|
273
|
+
|
|
274
|
+
/** Every control character but tab and line feed: an answer must not drive the operator's terminal. */
|
|
275
|
+
const printable = (text: string): string => text.replace(/[^\P{Cc}\t\n]/gu, '')
|
|
276
|
+
|
|
277
|
+
const viewLines = (view: OpsView | OpsContentView): string[] => [
|
|
278
|
+
`release\t${view.release}`,
|
|
279
|
+
`mode\t${view.maintenance.mode}`,
|
|
280
|
+
`generation\t${view.maintenance.generation ?? '-'}`,
|
|
281
|
+
`published\t${view.maintenance.published ? 'yes' : 'no'}`,
|
|
282
|
+
`databaseBytes\t${view.database.sizeBytes}`,
|
|
283
|
+
...view.database.tables.map((table) => `table\t${table.name}\t${table.rows >= OPS_ROW_COUNT_CAP ? `${OPS_ROW_COUNT_CAP}+` : table.rows}`),
|
|
284
|
+
...view.migrations.map((migration) => `migration\t${migration.bundle}\t${migration.name}\t${migration.appliedAt}`),
|
|
285
|
+
`alarm\t${view.scheduler.alarm ?? '-'}`,
|
|
286
|
+
...view.jobs.map((job) =>
|
|
287
|
+
`job\t${job.job}\t${job.lastStatus ?? '-'}\t${job.lastStartedAt ?? '-'}\t${job.lastFinishedAt ?? '-'}\t${job.lastDurationMs ?? '-'}`
|
|
288
|
+
),
|
|
289
|
+
...view.files.map((file) => `file\t${file.kind}\t${file.status}\t${file.count}`),
|
|
290
|
+
...view.webhooks.map((webhook) => `webhook\t${webhook.webhook}\t${webhook.state}\t${webhook.count}`),
|
|
291
|
+
`bootFailure\t${view.bootFailure?.at ?? '-'}`,
|
|
292
|
+
]
|
|
293
|
+
|
|
294
|
+
const contentLines = (view: OpsContentView): string[] => {
|
|
295
|
+
const failure = view.bootFailure
|
|
296
|
+
if (failure === null) return viewLines(view)
|
|
297
|
+
return [...viewLines(view), '', failure.message, ...(failure.stack === null ? [] : [failure.stack])]
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** Human output and every note pass `printable`; `--json` escapes what JSON must. */
|
|
301
|
+
const emit = (args: EnvArgs, result: unknown, render: () => string): void => {
|
|
302
|
+
console.info(args.json ? JSON.stringify(result, null, 2) : printable(render()))
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const note = (text: string): void => {
|
|
306
|
+
console.warn(printable(text))
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** An operation is an answer whatever its state; stderr names what follows it. */
|
|
310
|
+
const emitOperation = (args: EnvArgs, operation: DataOperationDto): void => {
|
|
311
|
+
const coordinates = `${operation.appId} ${operation.env}`
|
|
312
|
+
if (operation.state === 'running') note(`follow it: fabrika env operations ${coordinates}`)
|
|
313
|
+
if (operation.state === 'failed') note(`open the environment past it: fabrika env recover ${coordinates} ${operation.id} open`)
|
|
314
|
+
emit(args, operation, () => operationLine(operation))
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const runInspect = async (args: EnvArgs, env: Environment): Promise<void> => {
|
|
318
|
+
const [appId = '', environment = ''] = words('inspect', args, 2)
|
|
319
|
+
const client = controlClient(args, env)
|
|
320
|
+
if (args.content) {
|
|
321
|
+
const view = parseOpsContentView(await client.data.content({ appId, env: environment }))
|
|
322
|
+
if (view === null) throw new Error('Control returned an unreadable data view')
|
|
323
|
+
emit(args, view, () => contentLines(view).join('\n'))
|
|
324
|
+
return
|
|
325
|
+
}
|
|
326
|
+
const view = parseOpsView(await client.data.view({ appId, env: environment }))
|
|
327
|
+
if (view === null) throw new Error('Control returned an unreadable data view')
|
|
328
|
+
emit(args, view, () => viewLines(view).join('\n'))
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const runMaintenance = async (args: EnvArgs, env: Environment): Promise<void> => {
|
|
332
|
+
const [appId = '', environment = '', requested = ''] = words('maintenance', args, 3)
|
|
333
|
+
const mode = oneOf(requested, MAINTENANCE_MODES)
|
|
334
|
+
if (mode === undefined) throw new Error(`The mode is one of ${MAINTENANCE_MODES.join(', ')}, not "${requested}"`)
|
|
335
|
+
const result = await controlClient(args, env).data.start({ appId, env: environment, kind: 'maintenance', mode })
|
|
336
|
+
emitOperation(args, parseOperation(result, { appId, env: environment }))
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const runOperations = async (args: EnvArgs, env: Environment): Promise<void> => {
|
|
340
|
+
const [appId = '', environment = ''] = words('operations', args, 2)
|
|
341
|
+
const page = parseOperationPage(await controlClient(args, env).data.operations.list({ appId, env: environment }), { appId, env: environment })
|
|
342
|
+
if (page.nextCursor !== null) note(`showing the newest ${page.items.length} operations; older ones exist`)
|
|
343
|
+
if (!args.json && page.items.length === 0) {
|
|
344
|
+
note(`${appId} ${environment} has no data operations`)
|
|
345
|
+
return
|
|
346
|
+
}
|
|
347
|
+
emit(args, page, () => page.items.map(operationLine).join('\n'))
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const runRecover = async (args: EnvArgs, env: Environment): Promise<void> => {
|
|
351
|
+
const [appId = '', environment = '', operationId = '', requested = ''] = words('recover', args, 4)
|
|
352
|
+
const resolution = oneOf(requested, RESOLUTIONS)
|
|
353
|
+
if (resolution === undefined) throw new Error(`The resolution is resume or open, not "${requested}"`)
|
|
354
|
+
const result = await controlClient(args, env).data.recover({ appId, env: environment, operationId, resolution })
|
|
355
|
+
emitOperation(args, parseOperation(result, { appId, env: environment }))
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
const runBackups = async (args: EnvArgs, env: Environment): Promise<void> => {
|
|
359
|
+
if (args.positional[0] === 'schedule' && args.positional.length > 2) {
|
|
360
|
+
await runBackupSchedule(args, env)
|
|
361
|
+
return
|
|
362
|
+
}
|
|
363
|
+
const [appId = '', environment = ''] = words('backups', args, 2)
|
|
364
|
+
const page = parseBackupPage(await controlClient(args, env).data.backups.list({ appId, env: environment }), { appId, env: environment })
|
|
365
|
+
if (page.nextCursor !== null) note(`showing the newest ${page.items.length} backups; older ones exist`)
|
|
366
|
+
if (!args.json && page.items.length === 0) {
|
|
367
|
+
note(`${appId} ${environment} has no backups`)
|
|
368
|
+
return
|
|
369
|
+
}
|
|
370
|
+
emit(args, page, () => page.items.map(backupLine).join('\n'))
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const runBackupSchedule = async (args: EnvArgs, env: Environment): Promise<void> => {
|
|
374
|
+
const [, appId = '', environment = '', requested] = args.positional
|
|
375
|
+
if (args.positional.length > 4 || appId.trim() === '' || environment.trim() === '') throw usage('backups schedule')
|
|
376
|
+
const client = controlClient(args, env)
|
|
377
|
+
const target = { appId, env: environment }
|
|
378
|
+
if (requested === undefined) {
|
|
379
|
+
const schedule = parseSchedule(await client.data.backups.schedule(target), target)
|
|
380
|
+
emit(args, schedule, () => scheduleLines(schedule))
|
|
381
|
+
return
|
|
382
|
+
}
|
|
383
|
+
const daily = oneOf(requested, SCHEDULE_SWITCHES)
|
|
384
|
+
if (daily === undefined) throw new Error(`The schedule is on or off, not "${requested}"`)
|
|
385
|
+
const schedule = parseSchedule(await client.data.backups.setSchedule({ ...target, daily: daily === 'on' }), target)
|
|
386
|
+
if (!schedule.daily) note('the backup before a migration still runs')
|
|
387
|
+
emit(args, schedule, () => scheduleLines(schedule))
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const runRestore = async (args: EnvArgs, env: Environment): Promise<void> => {
|
|
391
|
+
const [appId = '', environment = ''] = words('restore', args, 2)
|
|
392
|
+
if (args.at === undefined || args.at === '') throw usage('restore')
|
|
393
|
+
// The contract's own rule for `at`, checked before anything is sent; whether it lies in the past is Control's to decide.
|
|
394
|
+
const input = startDataOperationInputSchema.safeParse({ appId, env: environment, kind: 'restore', at: args.at })
|
|
395
|
+
if (!input.success) throw new Error(`The time is ISO 8601 with an offset, such as 2026-10-24T12:00:00.000Z, not "${args.at}"`)
|
|
396
|
+
const result = await controlClient(args, env).data.start(input.data)
|
|
397
|
+
emitOperation(args, parseOperation(result, { appId, env: environment }))
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const commandRun = (command: string): ((args: EnvArgs, env: Environment) => Promise<void>) | undefined => {
|
|
401
|
+
switch (command) {
|
|
402
|
+
case 'inspect':
|
|
403
|
+
return runInspect
|
|
404
|
+
case 'maintenance':
|
|
405
|
+
return runMaintenance
|
|
406
|
+
case 'operations':
|
|
407
|
+
return runOperations
|
|
408
|
+
case 'recover':
|
|
409
|
+
return runRecover
|
|
410
|
+
case 'backups':
|
|
411
|
+
return runBackups
|
|
412
|
+
case 'restore':
|
|
413
|
+
return runRestore
|
|
414
|
+
default:
|
|
415
|
+
return undefined
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const diagnostic = (command: string, error: unknown): string => {
|
|
420
|
+
if (!(error instanceof RpcError)) return error instanceof Error ? error.message : String(error)
|
|
421
|
+
// Not offered by this release: a definite answer, unlike an outage, so nothing suggests trying again.
|
|
422
|
+
if (error.httpStatus === 501) return `\`env ${command}\` is not available in this release of the control plane; retrying will not change that`
|
|
423
|
+
// A refusal is an answer, not a transport fault: its type tells "Control said no" from "Control was unreachable".
|
|
424
|
+
return `${error.type}: ${error.message}`
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
export const runEnvCli = async (command: string | undefined, argv: readonly string[], env: Environment = process.env): Promise<void> => {
|
|
428
|
+
if (command === undefined) {
|
|
429
|
+
console.info(USAGE)
|
|
430
|
+
return
|
|
431
|
+
}
|
|
432
|
+
try {
|
|
433
|
+
const run = commandRun(command)
|
|
434
|
+
if (run === undefined) throw new Error(`Unknown env command: ${command}\n\n${USAGE}`)
|
|
435
|
+
const args = parseEnvArgs(argv)
|
|
436
|
+
if (args.content && command !== 'inspect') throw new Error('--content applies to `env inspect` only')
|
|
437
|
+
if (args.at !== undefined && command !== 'restore') throw new Error('--at applies to `env restore` only')
|
|
438
|
+
await run(args, env)
|
|
439
|
+
} catch (error) {
|
|
440
|
+
throw new Error(printable(withoutControlKey(diagnostic(command, error), env)))
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
export { USAGE as ENV_USAGE }
|
package/src/index.ts
CHANGED
|
@@ -26,6 +26,7 @@ Usage:
|
|
|
26
26
|
[--namespace=<id>] [--installation-id=<n|none>] [--url=<origin>] [--json]
|
|
27
27
|
fabrika namespace <plan|create|adopt|reconcile> --provider=zerops [provider options]
|
|
28
28
|
fabrika control <key|apps|namespaces|register|deploy|runs> [options]
|
|
29
|
+
fabrika env <inspect|maintenance|operations|recover|backups|restore> <app> <env> [arguments] [--json]
|
|
29
30
|
fabrika builder <init|next|advance|gate|ensure-daemon|induce|build> [options]
|
|
30
31
|
fabrika db <new|migrate|codegen|test-scaffold|test-isolation> [options]
|
|
31
32
|
fabrika job run <name>
|
|
@@ -62,6 +63,9 @@ environment approved, as Control answers it to FABRIKA_CONTROL_KEY. Run \`fabrik
|
|
|
62
63
|
provider-neutral, loads no installation package, and speaks the same typed API the console does. Run
|
|
63
64
|
\`fabrika control --help\` for its surface.
|
|
64
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
|
+
|
|
65
69
|
Which platform commands exist, and how WIDE each one is, is the provider's own answer — Zerops'
|
|
66
70
|
\`platform deploy\` owns the whole ordered sequence while Cloudflare's is one step of a scaffolded
|
|
67
71
|
workflow (ADR-0027), and only Zerops offers \`platform install\`, the from-scratch bring-up,
|
|
@@ -251,7 +255,7 @@ const runNamespace = async (parsed: ParsedCommand): Promise<void> => {
|
|
|
251
255
|
const { runNamespaceCommand } = await import('./namespace.js')
|
|
252
256
|
await runNamespaceCommand(cli, parsed.command, parsed.rest, {
|
|
253
257
|
source: process.env,
|
|
254
|
-
fetch:
|
|
258
|
+
fetch: (input, init) => fetch(input, init),
|
|
255
259
|
write: (value) => console.info(value.trimEnd()),
|
|
256
260
|
})
|
|
257
261
|
}
|
|
@@ -268,6 +272,11 @@ export const runCli = async (argv: readonly string[]): Promise<void> => {
|
|
|
268
272
|
console.info(CONTROL_USAGE)
|
|
269
273
|
return
|
|
270
274
|
}
|
|
275
|
+
if (parsed.help && parsed.area === 'env') {
|
|
276
|
+
const { ENV_USAGE } = await import('./data.js')
|
|
277
|
+
console.info(ENV_USAGE)
|
|
278
|
+
return
|
|
279
|
+
}
|
|
271
280
|
if (parsed.help && parsed.area === 'namespace') {
|
|
272
281
|
if (parsed.provider !== undefined && parsed.provider !== '') {
|
|
273
282
|
console.info((await namespaceCli(parsed.provider)).usage)
|
|
@@ -323,6 +332,11 @@ export const runCli = async (argv: readonly string[]): Promise<void> => {
|
|
|
323
332
|
await runControlCli(parsed.command, parsed.rest, parsed.provider)
|
|
324
333
|
return
|
|
325
334
|
}
|
|
335
|
+
if (parsed.area === 'env') {
|
|
336
|
+
const { runEnvCli } = await import('./data.js')
|
|
337
|
+
await runEnvCli(parsed.command, parsed.rest)
|
|
338
|
+
return
|
|
339
|
+
}
|
|
326
340
|
if (parsed.area === 'db') {
|
|
327
341
|
const { runDbCli } = await import('./db.js')
|
|
328
342
|
await runDbCli(parsed.command, parsed.rest)
|
package/types/src/control.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type InferRpcClient } from '@fabrika/app';
|
|
2
|
+
import type { AppEnvDto, ControlRpcContract, DeploymentNamespaceDto, PlanDeploymentNamespaceResponse } from '@fabrika/control-contract';
|
|
2
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>;
|
|
@@ -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 };
|