@fabrika/cli 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabrika/cli",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
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.0",
34
- "@fabrika/auth-core": "0.5.0",
35
- "@fabrika/control-contract": "0.5.0",
36
- "@fabrika/provider-contract": "0.5.0",
37
- "@fabrika/db": "0.5.0",
38
- "@fabrika/platform": "0.5.0",
39
- "@fabrika/platform-node": "0.5.0",
40
- "@fabrika/check": "0.5.0"
33
+ "@fabrika/app": "0.5.2",
34
+ "@fabrika/auth-core": "0.5.2",
35
+ "@fabrika/control-contract": "0.5.2",
36
+ "@fabrika/provider-contract": "0.5.2",
37
+ "@fabrika/db": "0.5.2",
38
+ "@fabrika/platform": "0.5.2",
39
+ "@fabrika/platform-node": "0.5.2",
40
+ "@fabrika/check": "0.5.2"
41
41
  },
42
42
  "peerDependencies": {
43
- "@fabrika/builder": "0.5.0",
44
- "@fabrika/provider-cloudflare": "0.5.0",
45
- "@fabrika/provider-zerops": "0.5.0"
43
+ "@fabrika/builder": "0.5.2",
44
+ "@fabrika/provider-cloudflare": "0.5.2",
45
+ "@fabrika/provider-zerops": "0.5.2"
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
+ AppSecretDto,
16
17
  ControlRpcContract,
17
18
  DeploymentNamespaceDetailDto,
18
19
  DeploymentNamespaceDto,
@@ -20,6 +21,7 @@ import type {
20
21
  PlanDeploymentNamespaceRequest,
21
22
  PlanDeploymentNamespaceResponse,
22
23
  PutAppEnvRequest,
24
+ PutAppSecretRequest,
23
25
  PutAppVarRequest,
24
26
  RegisterAppRequest,
25
27
  RegisterAppResponse,
@@ -56,6 +58,9 @@ Usage:
56
58
  fabrika control apps variables list --app=<id>
57
59
  fabrika control apps variables put --app=<id> --name=<name> --value=<text> [--env=<name>]
58
60
  fabrika control apps variables delete --app=<id> --name=<name> [--env=<name>]
61
+ fabrika control apps secrets list --app=<id>
62
+ fabrika control apps secrets put --app=<id> --name=<name> [--env=<name>] (the value on stdin)
63
+ fabrika control apps secrets delete --app=<id> --name=<name> [--env=<name>]
59
64
  fabrika control register --provider=<name> --app=<id> --repo=<url> --env=<name> --manifest=<path>
60
65
  [--domain=<host>] [--public-origin=<url>] [--trigger-ref=<ref>]
61
66
  [--namespace=<id>] [--installation-id=<n|none>]
@@ -81,6 +86,13 @@ refused before anything is created. \`namespaces get\` lists the hosts a \`zerop
81
86
  serves and which of them are still free; a custom-domain namespace serves the domain you bound to its
82
87
  proxy. A manifest with no proxy target needs no domain.
83
88
 
89
+ A variable's value is stored and printed in clear. A secret's value is write-only: \`apps secrets put\`
90
+ reads it from STDIN, never from a flag, so it reaches neither shell history nor a process listing, and
91
+ one trailing newline is dropped. No command prints it back; \`apps secrets list\` shows names, scope and
92
+ storage only. Generate one in the pipe:
93
+
94
+ openssl rand -base64 32 | fabrika control apps secrets put --app=<id> --name=<name>
95
+
84
96
  \`--public-origin\` is where IAM may return a signed-in person: without one, sign-in to the environment is
85
97
  refused. When \`register\` is given none and the namespace lists \`--domain\` among its hosts, it sets
86
98
  \`https://<domain>\` and says so on stderr. A custom domain needs the flag.
@@ -90,6 +102,12 @@ connected GitHub App, \`none\` registers an anonymous PUBLIC repository source,
90
102
  installation outright. With \`none\`, control reads the repository once without a token and refuses one
91
103
  GitHub hides: a private repository needs the GitHub App connected in the console first.
92
104
 
105
+ \`--trigger-ref\` is the git ref whose push deploys the environment; without it the environment deploys only
106
+ on \`deploy\`. A bare name is a branch: \`--trigger-ref=deploy/prod\` is stored as \`refs/heads/deploy/prod\`.
107
+ A full ref is kept as given: \`refs/heads/<branch>\`, \`refs/tags/<tag>\`, or a \`*\` glob such as
108
+ \`refs/tags/v*\`, which deploys every matching tag. A tag always needs the \`refs/tags/\` form. Each
109
+ environment of an app needs its own trigger ref.
110
+
93
111
  Namespace placement options, each defaulting to what the preset would choose:
94
112
 
95
113
  --project=<name> the provider project the namespace owns; on Zerops the default is
@@ -450,10 +468,10 @@ export type ManifestTextCompiler = (environment: string) => Promise<CompiledMani
450
468
 
451
469
  const IN_MEMORY_MANIFEST = 'the compiled manifest'
452
470
 
453
- /** The compile runs repository code that can read the environment, so its message may quote the key. */
454
- const failureMessage = (error: unknown, controlKey: string): string => {
471
+ /** The message of a failure that ran with `value` in reach, with `value` cut out and named by `label`. */
472
+ const failureMessage = (error: unknown, value: string, label: string): string => {
455
473
  const message = error instanceof RpcError ? `${error.type}: ${error.message}` : error instanceof Error ? error.message : String(error)
456
- return message.replaceAll(controlKey, '[FABRIKA_CONTROL_KEY]')
474
+ return message.replaceAll(value, `[${label}]`)
457
475
  }
458
476
 
459
477
  /**
@@ -483,13 +501,15 @@ export const registerCompiledManifest = async (
483
501
  const manifest = parseJsonText(compiled.text, IN_MEMORY_MANIFEST)
484
502
  body = registrationRequest(inputs, compiled.provider, manifest, IN_MEMORY_MANIFEST)
485
503
  } catch (error) {
486
- throw new Error(`Compile phase failed; nothing was registered. ${failureMessage(error, controlKey)}`)
504
+ throw new Error(`Compile phase failed; nothing was registered. ${failureMessage(error, controlKey, 'FABRIKA_CONTROL_KEY')}`)
487
505
  }
488
506
  let result: RegisterAppResponse
489
507
  try {
490
508
  result = await client.register(await withNamespacePublicOrigin(body, client))
491
509
  } catch (error) {
492
- throw new Error(`Register phase failed after a successful compile; no manifest file was written. ${failureMessage(error, controlKey)}`)
510
+ throw new Error(
511
+ `Register phase failed after a successful compile; no manifest file was written. ${failureMessage(error, controlKey, 'FABRIKA_CONTROL_KEY')}`,
512
+ )
493
513
  }
494
514
  emit(flags, result, () => registrationLine(result))
495
515
  }
@@ -573,12 +593,85 @@ const runVariables = async (verb: string | undefined, flags: Flags, env: Readonl
573
593
  throw new Error(`Unknown \`control apps variables\` verb: ${verb ?? '(missing)'}`)
574
594
  }
575
595
 
596
+ /** Where `apps secrets put` reads a secret's value. The CLI reads the process's stdin; a test hands its own. */
597
+ export interface SecretValueInput {
598
+ readonly isTerminal: () => boolean
599
+ readonly text: () => Promise<string>
600
+ }
601
+
602
+ const processStdin: SecretValueInput = {
603
+ isTerminal: () => process.stdin.isTTY === true,
604
+ text: () => Bun.stdin.text(),
605
+ }
606
+
607
+ /** The value piped in, without the one newline `echo` or a heredoc ends it with. */
608
+ const readSecretValue = async (input: SecretValueInput, appId: string, name: string): Promise<string> => {
609
+ if (input.isTerminal()) {
610
+ throw new Error(
611
+ '`apps secrets put` reads the value from stdin, and stdin is a terminal. Pipe the value in, for example: '
612
+ + `openssl rand -base64 32 | fabrika control apps secrets put --app=${appId} --name=${name}`,
613
+ )
614
+ }
615
+ const value = (await input.text()).replace(/\r?\n$/, '')
616
+ if (value === '') {
617
+ throw new Error('`apps secrets put` read an empty value from stdin; nothing was stored')
618
+ }
619
+ return value
620
+ }
621
+
622
+ /**
623
+ * A secret's value is write-only: it comes in on stdin, never as a flag a shell history or a process listing
624
+ * keeps, and no verb prints it. Control seals it and keeps only a reference.
625
+ */
626
+ const runSecrets = async (
627
+ verb: string | undefined,
628
+ flags: Flags,
629
+ env: Readonly<Record<string, string | undefined>>,
630
+ input: SecretValueInput,
631
+ ): Promise<void> => {
632
+ const client = controlClient(flags, env)
633
+ const appId = required(flags, 'app')
634
+ const scope = optional(flags, 'env')
635
+ if (verb === 'list') {
636
+ const result = await client.apps.secrets.list({ appId })
637
+ emitList(flags, result, (item) => `${item.env ?? '*'}\t${item.name}\t${item.storage}`, `app ${appId} has no secrets`)
638
+ return
639
+ }
640
+ if (verb === 'put') {
641
+ if (flags.values.has('value')) {
642
+ throw new Error('`apps secrets put` takes no --value: pipe the value in on stdin, so it stays out of shell history and process listings')
643
+ }
644
+ const name = required(flags, 'name')
645
+ const value = await readSecretValue(input, appId, name)
646
+ const secret: PutAppSecretRequest = { name, value, ...(scope === undefined ? {} : { env: scope }) }
647
+ let result: AppSecretDto
648
+ try {
649
+ result = await client.apps.secrets.put({ appId, secret })
650
+ } catch (error) {
651
+ throw new Error(failureMessage(error, value, 'secret value'))
652
+ }
653
+ emit(flags, result, () => `${result.env ?? '*'}\t${result.name}\tok`)
654
+ return
655
+ }
656
+ if (verb === 'delete') {
657
+ const result = await client.apps.secrets.delete({ appId, name: required(flags, 'name'), ...(scope === undefined ? {} : { env: scope }) })
658
+ emit(flags, result, () => (result.ok ? 'deleted' : 'not deleted'))
659
+ return
660
+ }
661
+ throw new Error(`Unknown \`control apps secrets\` verb: ${verb ?? '(missing)'}`)
662
+ }
663
+
576
664
  const runApps = async (
577
665
  verb: string | undefined,
578
666
  flags: Flags,
579
667
  provider: string | undefined,
580
668
  env: Readonly<Record<string, string | undefined>>,
669
+ input: SecretValueInput,
581
670
  ): Promise<void> => {
671
+ if (verb === 'secrets') {
672
+ await runSecrets(flags.positional[1], flags, env, input)
673
+ return
674
+ }
582
675
  if (verb === 'variables') {
583
676
  await runVariables(flags.positional[1], flags, env)
584
677
  return
@@ -791,6 +884,7 @@ export const runControlCli = async (
791
884
  argv: readonly string[],
792
885
  provider?: string,
793
886
  env: Readonly<Record<string, string | undefined>> = process.env,
887
+ input: SecretValueInput = processStdin,
794
888
  ): Promise<void> => {
795
889
  const flags = parseControlFlags(argv)
796
890
  const verb = flags.positional[0]
@@ -804,7 +898,7 @@ export const runControlCli = async (
804
898
  await runKeyIssue(flags, env)
805
899
  return
806
900
  case 'apps':
807
- await runApps(verb, flags, provider, env)
901
+ await runApps(verb, flags, provider, env, input)
808
902
  return
809
903
  case 'runs':
810
904
  await runRuns(verb, flags, env)
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.