@fabrika/cli 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +12 -12
- package/src/control.ts +49 -4
- package/src/index.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/cli",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -30,19 +30,19 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"zod": "^3.25.76",
|
|
33
|
-
"@fabrika/app": "0.5.
|
|
34
|
-
"@fabrika/auth-core": "0.5.
|
|
35
|
-
"@fabrika/control-contract": "0.5.
|
|
36
|
-
"@fabrika/provider-contract": "0.5.
|
|
37
|
-
"@fabrika/db": "0.5.
|
|
38
|
-
"@fabrika/platform": "0.5.
|
|
39
|
-
"@fabrika/platform-node": "0.5.
|
|
40
|
-
"@fabrika/check": "0.5.
|
|
33
|
+
"@fabrika/app": "0.5.3",
|
|
34
|
+
"@fabrika/auth-core": "0.5.3",
|
|
35
|
+
"@fabrika/control-contract": "0.5.3",
|
|
36
|
+
"@fabrika/provider-contract": "0.5.3",
|
|
37
|
+
"@fabrika/db": "0.5.3",
|
|
38
|
+
"@fabrika/platform": "0.5.3",
|
|
39
|
+
"@fabrika/platform-node": "0.5.3",
|
|
40
|
+
"@fabrika/check": "0.5.3"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@fabrika/builder": "0.5.
|
|
44
|
-
"@fabrika/provider-cloudflare": "0.5.
|
|
45
|
-
"@fabrika/provider-zerops": "0.5.
|
|
43
|
+
"@fabrika/builder": "0.5.3",
|
|
44
|
+
"@fabrika/provider-cloudflare": "0.5.3",
|
|
45
|
+
"@fabrika/provider-zerops": "0.5.3"
|
|
46
46
|
},
|
|
47
47
|
"peerDependenciesMeta": {
|
|
48
48
|
"@fabrika/builder": {
|
package/src/control.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { createRpcClient, type InferRpcClient, RpcError } from '@fabrika/app'
|
|
|
13
13
|
import { type IssueKeyInput, type IssueKeyResult, MAX_KEY_LIFETIME_SECONDS } from '@fabrika/auth-core'
|
|
14
14
|
import type {
|
|
15
15
|
AppDto,
|
|
16
|
+
AppEnvDto,
|
|
16
17
|
AppSecretDto,
|
|
17
18
|
ControlRpcContract,
|
|
18
19
|
DeploymentNamespaceDetailDto,
|
|
@@ -55,6 +56,7 @@ Usage:
|
|
|
55
56
|
fabrika control apps environments list --app=<id>
|
|
56
57
|
fabrika control apps environments put --provider=<name> --app=<id> --env=<name> --manifest=<path>
|
|
57
58
|
[--domain=<host>] [--public-origin=<url>] [--trigger-ref=<ref>] [--namespace=<id>]
|
|
59
|
+
[--cross-origin=<origin> ...]
|
|
58
60
|
fabrika control apps variables list --app=<id>
|
|
59
61
|
fabrika control apps variables put --app=<id> --name=<name> --value=<text> [--env=<name>]
|
|
60
62
|
fabrika control apps variables delete --app=<id> --name=<name> [--env=<name>]
|
|
@@ -63,7 +65,7 @@ Usage:
|
|
|
63
65
|
fabrika control apps secrets delete --app=<id> --name=<name> [--env=<name>]
|
|
64
66
|
fabrika control register --provider=<name> --app=<id> --repo=<url> --env=<name> --manifest=<path>
|
|
65
67
|
[--domain=<host>] [--public-origin=<url>] [--trigger-ref=<ref>]
|
|
66
|
-
[--namespace=<id>] [--installation-id=<n|none>]
|
|
68
|
+
[--namespace=<id>] [--installation-id=<n|none>] [--cross-origin=<origin> ...]
|
|
67
69
|
fabrika control namespaces list
|
|
68
70
|
fabrika control namespaces get --namespace=<id>
|
|
69
71
|
fabrika control namespaces plan --namespace=<id> --env=<name> --preset=<cheap|mid|full> [placement]
|
|
@@ -97,11 +99,24 @@ storage only. Generate one in the pipe:
|
|
|
97
99
|
refused. When \`register\` is given none and the namespace lists \`--domain\` among its hosts, it sets
|
|
98
100
|
\`https://<domain>\` and says so on stderr. A custom domain needs the flag.
|
|
99
101
|
|
|
102
|
+
\`--cross-origin\` names an origin whose pages may call the environment's cross-origin endpoints (ADR-0022), and
|
|
103
|
+
repeats: the flags given are the environment's whole list. Each is an exact origin with a literal host
|
|
104
|
+
(\`https://app.example.com\`; \`http://\` only for a local one), never the environment's own domain, at most 16.
|
|
105
|
+
\`apps environments put\` without the flag keeps the stored list, and a lone empty \`--cross-origin=\` clears it.
|
|
106
|
+
On Zerops the change reaches the namespace proxy at once; on Cloudflare the next deploy of the environment
|
|
107
|
+
applies it.
|
|
108
|
+
|
|
100
109
|
\`--installation-id\` has three states: omitted resolves the installation from the organization's
|
|
101
110
|
connected GitHub App, \`none\` registers an anonymous PUBLIC repository source, and a number names one
|
|
102
111
|
installation outright. With \`none\`, control reads the repository once without a token and refuses one
|
|
103
112
|
GitHub hides: a private repository needs the GitHub App connected in the console first.
|
|
104
113
|
|
|
114
|
+
\`--trigger-ref\` is the git ref whose push deploys the environment; without it the environment deploys only
|
|
115
|
+
on \`deploy\`. A bare name is a branch: \`--trigger-ref=deploy/prod\` is stored as \`refs/heads/deploy/prod\`.
|
|
116
|
+
A full ref is kept as given: \`refs/heads/<branch>\`, \`refs/tags/<tag>\`, or a \`*\` glob such as
|
|
117
|
+
\`refs/tags/v*\`, which deploys every matching tag. A tag always needs the \`refs/tags/\` form. Each
|
|
118
|
+
environment of an app needs its own trigger ref.
|
|
119
|
+
|
|
105
120
|
Namespace placement options, each defaulting to what the preset would choose:
|
|
106
121
|
|
|
107
122
|
--project=<name> the provider project the namespace owns; on Zerops the default is
|
|
@@ -156,6 +171,8 @@ const DEFAULT_CONTROL_APP_ID = 'vozka'
|
|
|
156
171
|
|
|
157
172
|
interface Flags {
|
|
158
173
|
readonly values: ReadonlyMap<string, string>
|
|
174
|
+
/** Every value of every option, in order; `values` keeps the last. Only a repeatable option reads it. */
|
|
175
|
+
readonly repeated: ReadonlyMap<string, readonly string[]>
|
|
159
176
|
readonly json: boolean
|
|
160
177
|
readonly positional: readonly string[]
|
|
161
178
|
}
|
|
@@ -163,6 +180,7 @@ interface Flags {
|
|
|
163
180
|
/** Split `--key=value` options from positional words; `--json` is the one flag every verb shares. */
|
|
164
181
|
export const parseControlFlags = (argv: readonly string[]): Flags => {
|
|
165
182
|
const values = new Map<string, string>()
|
|
183
|
+
const repeated = new Map<string, string[]>()
|
|
166
184
|
const positional: string[] = []
|
|
167
185
|
let json = false
|
|
168
186
|
for (const arg of argv) {
|
|
@@ -173,12 +191,15 @@ export const parseControlFlags = (argv: readonly string[]): Flags => {
|
|
|
173
191
|
if (eq === -1) {
|
|
174
192
|
throw new Error(`Option ${arg} needs a value: ${arg}=<value>`)
|
|
175
193
|
}
|
|
176
|
-
|
|
194
|
+
const name = arg.slice(2, eq)
|
|
195
|
+
const value = arg.slice(eq + 1)
|
|
196
|
+
values.set(name, value)
|
|
197
|
+
repeated.set(name, [...(repeated.get(name) ?? []), value])
|
|
177
198
|
} else {
|
|
178
199
|
positional.push(arg)
|
|
179
200
|
}
|
|
180
201
|
}
|
|
181
|
-
return { values, json, positional }
|
|
202
|
+
return { values, repeated, json, positional }
|
|
182
203
|
}
|
|
183
204
|
|
|
184
205
|
const required = (flags: Flags, name: string): string => {
|
|
@@ -194,6 +215,20 @@ const optional = (flags: Flags, name: string): string | undefined => {
|
|
|
194
215
|
return value === undefined || value === '' ? undefined : value
|
|
195
216
|
}
|
|
196
217
|
|
|
218
|
+
/**
|
|
219
|
+
* `--cross-origin=<origin>`, repeatable: the environment's whole list. Omitted keeps the stored list on
|
|
220
|
+
* `apps environments put`; a lone empty `--cross-origin=` sends an empty list, which clears it.
|
|
221
|
+
*/
|
|
222
|
+
const crossOrigins = (flags: Flags): string[] | undefined => {
|
|
223
|
+
const given = flags.repeated.get('cross-origin')
|
|
224
|
+
if (given === undefined) return undefined
|
|
225
|
+
if (given.length === 1 && given[0] === '') return []
|
|
226
|
+
if (given.includes('')) {
|
|
227
|
+
throw new Error('An empty --cross-origin= clears the list and takes no other --cross-origin')
|
|
228
|
+
}
|
|
229
|
+
return [...given]
|
|
230
|
+
}
|
|
231
|
+
|
|
197
232
|
const positiveInteger = (raw: string, name: string): number => {
|
|
198
233
|
const parsed = Number(raw)
|
|
199
234
|
if (!Number.isSafeInteger(parsed) || parsed <= 0) {
|
|
@@ -380,6 +415,7 @@ const registrationInputs = (flags: Flags): RegistrationInputs => {
|
|
|
380
415
|
const anonymousSource = installationId === 'none'
|
|
381
416
|
const domain = optional(flags, 'domain')
|
|
382
417
|
const publicOrigin = optional(flags, 'public-origin')
|
|
418
|
+
const origins = crossOrigins(flags)
|
|
383
419
|
const triggerRef = optional(flags, 'trigger-ref')
|
|
384
420
|
const namespaceId = optional(flags, 'namespace')
|
|
385
421
|
return {
|
|
@@ -394,6 +430,7 @@ const registrationInputs = (flags: Flags): RegistrationInputs => {
|
|
|
394
430
|
: { githubInstallationId: positiveInteger(installationId, 'installation-id') }),
|
|
395
431
|
...(domain === undefined ? {} : { domain }),
|
|
396
432
|
...(publicOrigin === undefined ? {} : { publicOrigin }),
|
|
433
|
+
...(origins === undefined ? {} : { crossOrigins: origins }),
|
|
397
434
|
...(triggerRef === undefined ? {} : { triggerRef }),
|
|
398
435
|
...(namespaceId === undefined ? {} : { namespaceId }),
|
|
399
436
|
}
|
|
@@ -525,7 +562,7 @@ const runEnvironments = async (
|
|
|
525
562
|
if (verb === 'list') {
|
|
526
563
|
const appId = required(flags, 'app')
|
|
527
564
|
const result = await client.apps.environments.list({ appId })
|
|
528
|
-
emitList(flags, result,
|
|
565
|
+
emitList(flags, result, environmentLine, `app ${appId} has no environments`)
|
|
529
566
|
return
|
|
530
567
|
}
|
|
531
568
|
if (verb === 'put') {
|
|
@@ -537,6 +574,7 @@ const runEnvironments = async (
|
|
|
537
574
|
const version = manifestVersion(manifest, manifestPath)
|
|
538
575
|
const domain = optional(flags, 'domain')
|
|
539
576
|
const publicOrigin = optional(flags, 'public-origin')
|
|
577
|
+
const origins = crossOrigins(flags)
|
|
540
578
|
const triggerRef = optional(flags, 'trigger-ref')
|
|
541
579
|
const namespaceId = optional(flags, 'namespace')
|
|
542
580
|
const environment: PutAppEnvRequest = {
|
|
@@ -545,6 +583,7 @@ const runEnvironments = async (
|
|
|
545
583
|
artifact: { provider, version, payload: manifest },
|
|
546
584
|
...(domain === undefined ? {} : { domain }),
|
|
547
585
|
...(publicOrigin === undefined ? {} : { publicOrigin }),
|
|
586
|
+
...(origins === undefined ? {} : { crossOrigins: origins }),
|
|
548
587
|
...(triggerRef === undefined ? {} : { triggerRef }),
|
|
549
588
|
...(namespaceId === undefined ? {} : { namespaceId }),
|
|
550
589
|
}
|
|
@@ -555,6 +594,12 @@ const runEnvironments = async (
|
|
|
555
594
|
throw new Error(`Unknown \`control apps environments\` verb: ${verb ?? '(missing)'}`)
|
|
556
595
|
}
|
|
557
596
|
|
|
597
|
+
/** One environment per line; the cross origins are comma-joined, `-` when it lists none (a Control older than the field included). */
|
|
598
|
+
export const environmentLine = (item: Pick<AppEnvDto, 'appId' | 'env' | 'provider' | 'domain'> & Partial<Pick<AppEnvDto, 'crossOrigins'>>): string =>
|
|
599
|
+
`${item.appId}\t${item.env}\t${item.provider}\t${item.domain ?? '-'}\t${
|
|
600
|
+
item.crossOrigins === undefined || item.crossOrigins.length === 0 ? '-' : item.crossOrigins.join(',')
|
|
601
|
+
}`
|
|
602
|
+
|
|
558
603
|
/**
|
|
559
604
|
* A variable is NOT a secret: its value is stored and read back in clear, so it takes a flag. The one
|
|
560
605
|
* thing an app cannot commit and fabrika cannot infer — an installation's IAM issuer, say — is written
|
package/src/index.ts
CHANGED
|
@@ -45,6 +45,8 @@ Run \`fabrika app dev --help\` for its surface.
|
|
|
45
45
|
\`app register\` compiles the manifest in memory, exactly as \`app build\` would, and sends the request
|
|
46
46
|
\`control register --manifest=<path>\` sends for it. It writes no file, CREATES only, and reads the
|
|
47
47
|
control credential from FABRIKA_CONTROL_KEY alone; a changed manifest is \`control apps environments put\`.
|
|
48
|
+
A bare \`--trigger-ref\` is a branch (\`deploy/prod\` deploys on a push to \`refs/heads/deploy/prod\`); a tag needs
|
|
49
|
+
\`refs/tags/<tag>\` or a glob such as \`refs/tags/v*\`. \`fabrika control --help\` lists every form.
|
|
48
50
|
|
|
49
51
|
\`fabrika db\` manages an application's Postgres schema: migration files, applying them (the template's
|
|
50
52
|
\`run.initCommands\`), the generated types and the generated isolation tests. Run \`fabrika db --help\` for its surface.
|