@devicecloud.dev/dcd 5.9.0 → 5.10.0-beta.1

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.
@@ -242,8 +242,7 @@ export declare const cloudCommand: import("citty").CommandDef<{
242
242
  };
243
243
  readonly encrypt: {
244
244
  readonly type: "boolean";
245
- readonly hidden: true;
246
- readonly description: "Encrypt the app binary, flow zip, and env vars before upload (client-side envelope encryption; each gets its own key). The binary is still deduplicated across runs, so an unchanged app is not re-uploaded. Also turned on by DCD_ENCRYPT=1, and by default for orgs in the encryption beta; --no-encrypt or DCD_ENCRYPT=0 turns it off.";
245
+ readonly description: "Encrypt the app binary, flow zip, and env vars before upload (client-side envelope encryption; each gets its own key). On by default; --no-encrypt or DCD_ENCRYPT=0 turns it off. The binary is still deduplicated across runs, so an unchanged app is not re-uploaded.";
247
246
  };
248
247
  readonly 'api-key': {
249
248
  readonly type: "string";
@@ -140,7 +140,7 @@ export const cloudCommand = defineCommand({
140
140
  // Client-side envelope encryption of every sensitive artifact: the
141
141
  // binary (#1138), the flow zip (#1151), and env vars (#1152). Kept as
142
142
  // given (--no-encrypt is an explicit false) and resolved once the
143
- // compatibility data, which carries the org's default, is in.
143
+ // compatibility data, which carries the server default, is in.
144
144
  const encryptFlag = args.encrypt;
145
145
  const includeTags = coerceArray(collectRepeatedFlag(rawArgs, ['--include-tags']));
146
146
  // Devices and OS versions are checked against the API's live
@@ -261,7 +261,7 @@ export const cloudCommand = defineCommand({
261
261
  if (debug) {
262
262
  out(`[DEBUG] API URL: ${apiUrl}`);
263
263
  }
264
- const encryption = checkKekForEncryption(resolveEncryption({
264
+ const encryption = await checkKekForEncryption(resolveEncryption({
265
265
  flag: encryptFlag,
266
266
  serverDefault: compatibilityData.encryption?.defaultOn,
267
267
  }), apiUrl);
@@ -537,7 +537,7 @@ export const cloudCommand = defineCommand({
537
537
  return;
538
538
  }
539
539
  if (encrypt && encryption.source === 'server') {
540
- out(ui.note('Encrypting uploads (beta); opt out with --no-encrypt'));
540
+ out(ui.note('Encrypting uploads; opt out with --no-encrypt'));
541
541
  }
542
542
  if (!finalBinaryId) {
543
543
  if (!finalAppFile) {
@@ -9,8 +9,7 @@ export declare const uploadCommand: import("citty").CommandDef<{
9
9
  };
10
10
  readonly encrypt: {
11
11
  readonly type: "boolean";
12
- readonly hidden: true;
13
- readonly description: "Encrypt the app binary, flow zip, and env vars before upload (client-side envelope encryption; each gets its own key). The binary is still deduplicated across runs, so an unchanged app is not re-uploaded. Also turned on by DCD_ENCRYPT=1, and by default for orgs in the encryption beta; --no-encrypt or DCD_ENCRYPT=0 turns it off.";
12
+ readonly description: "Encrypt the app binary, flow zip, and env vars before upload (client-side envelope encryption; each gets its own key). On by default; --no-encrypt or DCD_ENCRYPT=0 turns it off. The binary is still deduplicated across runs, so an unchanged app is not re-uploaded.";
14
13
  };
15
14
  readonly debug: {
16
15
  readonly type: "boolean";
@@ -46,7 +46,7 @@ export const uploadCommand = defineCommand({
46
46
  const appUrl = args['app-url'];
47
47
  const ignoreShaCheck = Boolean(args['ignore-sha-check']);
48
48
  // Kept as given, so --no-encrypt is an explicit false and a missing flag
49
- // leaves DCD_ENCRYPT and then the org's default to decide.
49
+ // leaves DCD_ENCRYPT and then the server default to decide.
50
50
  const encryptFlag = args.encrypt;
51
51
  const debug = Boolean(args.debug);
52
52
  const positional = args.appFile;
@@ -69,7 +69,7 @@ export const uploadCommand = defineCommand({
69
69
  out(`[DEBUG] Failed to fetch compatibility data, so the org's encryption default is off: ${error instanceof Error ? error.message : String(error)}`);
70
70
  }
71
71
  }
72
- const encryption = checkKekForEncryption(resolveEncryption({ flag: encryptFlag, serverDefault }), apiUrl);
72
+ const encryption = await checkKekForEncryption(resolveEncryption({ flag: encryptFlag, serverDefault }), apiUrl);
73
73
  if (encryption.notice)
74
74
  out(ui.note(encryption.notice));
75
75
  telemetry.recordEncryption({ source: encryption.source });
@@ -102,7 +102,7 @@ export const uploadCommand = defineCommand({
102
102
  out(ui.branch([
103
103
  ...ui.fields([['file', colors.highlight(resolvedFile)]]),
104
104
  ...(encryption.enabled && encryption.source === 'server'
105
- ? [ui.note('Encrypting uploads (beta); opt out with --no-encrypt')]
105
+ ? [ui.note('Encrypting uploads; opt out with --no-encrypt')]
106
106
  : []),
107
107
  ]));
108
108
  const appBinaryId = await uploadBinary({
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The dcd API's public `GET /cli-config`: runtime configuration the CLI used to
3
+ * compile in, fetched from the API it talks to so that rotating any of it is an
4
+ * env change on the API rather than a CLI release.
5
+ *
6
+ * - `supabase_publishable_key` (dcd#1112): see ./supabase-key.ts.
7
+ * - `binary_kek_public_key` (dcd#1138): the newest KEK public key the API
8
+ * publishes for client-side envelope encryption, with the version the API
9
+ * unwraps it with. Absent when the API publishes none.
10
+ *
11
+ * Fetched once per process per API URL and kept in memory only. It is
12
+ * deliberately not cached on disk: a stale Supabase key makes GoTrue answer a
13
+ * refresh with a 4xx, which `resolveAuth` treats as a dead session and deletes
14
+ * the user's login, and a stale KEK would wrap uploads the API can no longer
15
+ * unwrap. A failed fetch is not cached, so the next call retries.
16
+ */
17
+ export interface CliConfig {
18
+ supabase_url?: string;
19
+ supabase_publishable_key?: string;
20
+ binary_kek_public_key?: {
21
+ version: number;
22
+ key: string;
23
+ };
24
+ }
25
+ /** `apiUrl` without trailing slashes, so `…/` and `…` share one cache entry. */
26
+ export declare function cliConfigUrl(apiUrl: string): string;
27
+ /** The API's CLI config. A failed fetch is not cached, so the next call retries. */
28
+ export declare function getCliConfig(apiUrl: string): Promise<CliConfig>;
29
+ /** Test seam: forget fetched configs. */
30
+ export declare function resetCliConfigCache(): void;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The dcd API's public `GET /cli-config`: runtime configuration the CLI used to
3
+ * compile in, fetched from the API it talks to so that rotating any of it is an
4
+ * env change on the API rather than a CLI release.
5
+ *
6
+ * - `supabase_publishable_key` (dcd#1112): see ./supabase-key.ts.
7
+ * - `binary_kek_public_key` (dcd#1138): the newest KEK public key the API
8
+ * publishes for client-side envelope encryption, with the version the API
9
+ * unwraps it with. Absent when the API publishes none.
10
+ *
11
+ * Fetched once per process per API URL and kept in memory only. It is
12
+ * deliberately not cached on disk: a stale Supabase key makes GoTrue answer a
13
+ * refresh with a 4xx, which `resolveAuth` treats as a dead session and deletes
14
+ * the user's login, and a stale KEK would wrap uploads the API can no longer
15
+ * unwrap. A failed fetch is not cached, so the next call retries.
16
+ */
17
+ const FETCH_TIMEOUT_MS = 10_000;
18
+ const cache = new Map();
19
+ /** `apiUrl` without trailing slashes, so `…/` and `…` share one cache entry. */
20
+ export function cliConfigUrl(apiUrl) {
21
+ return `${apiUrl.replace(/\/+$/, '')}/cli-config`;
22
+ }
23
+ async function fetchCliConfig(apiUrl) {
24
+ const url = cliConfigUrl(apiUrl);
25
+ const res = await fetch(url, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
26
+ if (!res.ok) {
27
+ throw new Error(`Failed to fetch CLI config from ${url}: HTTP ${res.status}`);
28
+ }
29
+ const body = await res.json();
30
+ if (!body || typeof body !== 'object' || Array.isArray(body)) {
31
+ throw new Error(`CLI config from ${url} is not a JSON object`);
32
+ }
33
+ return body;
34
+ }
35
+ /** The API's CLI config. A failed fetch is not cached, so the next call retries. */
36
+ export function getCliConfig(apiUrl) {
37
+ const key = cliConfigUrl(apiUrl);
38
+ let pending = cache.get(key);
39
+ if (!pending) {
40
+ pending = fetchCliConfig(apiUrl);
41
+ cache.set(key, pending);
42
+ pending.catch(() => cache.delete(key));
43
+ }
44
+ return pending;
45
+ }
46
+ /** Test seam: forget fetched configs. */
47
+ export function resetCliConfigCache() {
48
+ cache.clear();
49
+ }
@@ -2,9 +2,11 @@
2
2
  * Per-env devicecloud.dev coordinates — single source of truth for the URLs
3
3
  * the CLI uses.
4
4
  *
5
- * There is deliberately no Supabase key here. A compiled-in key can never be
6
- * rotated without breaking every pinned CLI version, so it is fetched from the
7
- * API at runtime instead: see `getSupabaseKey` in ./supabase-key.ts (dcd#1112).
5
+ * There is deliberately no Supabase key and no KEK public key here. A
6
+ * compiled-in key can never be rotated without breaking every pinned CLI
7
+ * version, so both are fetched from the API at runtime instead: see
8
+ * ./cli-config.ts (`getSupabaseKey` in ./supabase-key.ts for dcd#1112, and
9
+ * `resolveKekPublicKey` in ../utils/envelope.ts for dcd#1138).
8
10
  */
9
11
  export type DcdEnvName = 'dev' | 'prod';
10
12
  export interface DcdEnvironment {
@@ -14,38 +16,12 @@ export interface DcdEnvironment {
14
16
  url: string;
15
17
  projectRef: string;
16
18
  };
17
- /**
18
- * Pinned KEK public key for client-side binary envelope encryption (dcd#1138).
19
- * `key` is base64 of the raw 32-byte X25519 public key; `version` selects which
20
- * KEK the platform API unwraps with. **Public — safe to embed**: it can only
21
- * *encrypt*; the private half lives solely on the API.
22
- *
23
- * Left `null` until the KEK is generated and provisioned. Generate a keypair
24
- * with, e.g.:
25
- * node -e 'const c=require("crypto");const{publicKey,privateKey}=c.generateKeyPairSync("x25519");const pub=publicKey.export({type:"spki",format:"der"}).subarray(12);const priv=privateKey.export({type:"pkcs8",format:"der"}).subarray(16);console.log("public :",pub.toString("base64"));console.log("private:",priv.toString("base64"))'
26
- * Pin `public` here; set `private` as `BINARY_KEK_PRIVATE_KEYS={"<version>":"<private base64>"}`
27
- * on the API service and keep one offline escrow copy. Until then, encryption
28
- * can be exercised via the `DCD_BINARY_KEK_PUBLIC` env override (see envelope.ts).
29
- */
30
- kekPublicKey: {
31
- version: number;
32
- key: string;
33
- } | null;
34
19
  }
35
20
  export declare const ENVIRONMENTS: Record<DcdEnvName, DcdEnvironment>;
36
21
  /** Exact-match lookup of a known environment by API URL (trailing slashes ignored). */
37
22
  export declare function findEnvByApiUrl(apiUrl: string): DcdEnvironment | undefined;
38
23
  /** Map a caller-supplied API URL to one of the known environments. */
39
24
  export declare function inferEnvFromApiUrl(apiUrl: string): DcdEnvName;
40
- /**
41
- * The environment whose pinned KEK may encrypt uploads to `apiUrl` (dcd#1138),
42
- * or undefined when the URL isn't a known one. Stricter than
43
- * {@link inferEnvFromApiUrl}, which falls back to prod for any URL: that is
44
- * harmless for picking a console link, but an upload encrypted for a KEK its
45
- * API can't unwrap is unusable. Known means the host of a pinned `apiUrl`, or
46
- * `localhost`, which runs against dev.
47
- */
48
- export declare function kekEnvForApiUrl(apiUrl: string): DcdEnvName | undefined;
49
25
  /**
50
26
  * Frontend URL to open for a given API URL. Same as
51
27
  * `ENVIRONMENTS[inferEnvFromApiUrl(apiUrl)].frontendUrl`, except that when the
@@ -2,9 +2,11 @@
2
2
  * Per-env devicecloud.dev coordinates — single source of truth for the URLs
3
3
  * the CLI uses.
4
4
  *
5
- * There is deliberately no Supabase key here. A compiled-in key can never be
6
- * rotated without breaking every pinned CLI version, so it is fetched from the
7
- * API at runtime instead: see `getSupabaseKey` in ./supabase-key.ts (dcd#1112).
5
+ * There is deliberately no Supabase key and no KEK public key here. A
6
+ * compiled-in key can never be rotated without breaking every pinned CLI
7
+ * version, so both are fetched from the API at runtime instead: see
8
+ * ./cli-config.ts (`getSupabaseKey` in ./supabase-key.ts for dcd#1112, and
9
+ * `resolveKekPublicKey` in ../utils/envelope.ts for dcd#1138).
8
10
  */
9
11
  export const ENVIRONMENTS = {
10
12
  prod: {
@@ -14,7 +16,6 @@ export const ENVIRONMENTS = {
14
16
  url: 'https://cloud.devicecloud.dev',
15
17
  projectRef: 'pgydnphbimetinsgfkbo',
16
18
  },
17
- kekPublicKey: { version: 1, key: 'wtfyWEwK7nJzwI4PD+9RAW8jxIR1u8kMQq2IhsrVnH4=' },
18
19
  },
19
20
  dev: {
20
21
  apiUrl: 'https://api.dev.devicecloud.dev',
@@ -23,7 +24,6 @@ export const ENVIRONMENTS = {
23
24
  url: 'https://lbmsowehtjwnqlurpemb.supabase.co',
24
25
  projectRef: 'lbmsowehtjwnqlurpemb',
25
26
  },
26
- kekPublicKey: { version: 1, key: 'RgcToF/OJpcQI9koYvSvtj/WLaebfcN4v5GJoqtr/00=' },
27
27
  },
28
28
  };
29
29
  /** Exact-match lookup of a known environment by API URL (trailing slashes ignored). */
@@ -38,27 +38,6 @@ export function inferEnvFromApiUrl(apiUrl) {
38
38
  return 'dev';
39
39
  return 'prod';
40
40
  }
41
- /**
42
- * The environment whose pinned KEK may encrypt uploads to `apiUrl` (dcd#1138),
43
- * or undefined when the URL isn't a known one. Stricter than
44
- * {@link inferEnvFromApiUrl}, which falls back to prod for any URL: that is
45
- * harmless for picking a console link, but an upload encrypted for a KEK its
46
- * API can't unwrap is unusable. Known means the host of a pinned `apiUrl`, or
47
- * `localhost`, which runs against dev.
48
- */
49
- export function kekEnvForApiUrl(apiUrl) {
50
- let host;
51
- try {
52
- host = new URL(apiUrl).hostname;
53
- }
54
- catch {
55
- return undefined;
56
- }
57
- if (host === 'localhost')
58
- return 'dev';
59
- const names = Object.keys(ENVIRONMENTS);
60
- return names.find((name) => new URL(ENVIRONMENTS[name].apiUrl).hostname === host);
61
- }
62
41
  /**
63
42
  * Frontend URL to open for a given API URL. Same as
64
43
  * `ENVIRONMENTS[inferEnvFromApiUrl(apiUrl)].frontendUrl`, except that when the
@@ -21,7 +21,6 @@ export declare const binaryFlags: {
21
21
  };
22
22
  readonly encrypt: {
23
23
  readonly type: "boolean";
24
- readonly hidden: true;
25
- readonly description: "Encrypt the app binary, flow zip, and env vars before upload (client-side envelope encryption; each gets its own key). The binary is still deduplicated across runs, so an unchanged app is not re-uploaded. Also turned on by DCD_ENCRYPT=1, and by default for orgs in the encryption beta; --no-encrypt or DCD_ENCRYPT=0 turns it off.";
24
+ readonly description: "Encrypt the app binary, flow zip, and env vars before upload (client-side envelope encryption; each gets its own key). On by default; --no-encrypt or DCD_ENCRYPT=0 turns it off. The binary is still deduplicated across runs, so an unchanged app is not re-uploaded.";
26
25
  };
27
26
  };
@@ -21,9 +21,6 @@ export const binaryFlags = {
21
21
  },
22
22
  encrypt: {
23
23
  type: 'boolean',
24
- // Left out of --help while encryption is a per-org beta (dcd#1138); the
25
- // flag still parses, --no-encrypt included.
26
- hidden: true,
27
- description: 'Encrypt the app binary, flow zip, and env vars before upload (client-side envelope encryption; each gets its own key). The binary is still deduplicated across runs, so an unchanged app is not re-uploaded. Also turned on by DCD_ENCRYPT=1, and by default for orgs in the encryption beta; --no-encrypt or DCD_ENCRYPT=0 turns it off.',
24
+ description: 'Encrypt the app binary, flow zip, and env vars before upload (client-side envelope encryption; each gets its own key). On by default; --no-encrypt or DCD_ENCRYPT=0 turns it off. The binary is still deduplicated across runs, so an unchanged app is not re-uploaded.',
28
25
  },
29
26
  };
@@ -1,19 +1,3 @@
1
- /**
2
- * The Supabase publishable key, fetched from the dcd API at runtime (dcd#1112).
3
- *
4
- * Releases up to this one compiled the anon key in, so the key could never be
5
- * rotated without breaking every CLI version pinned in customer CI. The API now
6
- * serves it from the public `GET /cli-config`, and rotating it is an env change
7
- * on the API.
8
- *
9
- * Fetched once per process and kept in memory only. It is deliberately not
10
- * cached on disk: a stale key makes GoTrue answer a refresh with a 4xx, which
11
- * `resolveAuth` treats as a dead session and deletes the user's login.
12
- *
13
- * Only the key comes from the API. The Supabase URLs stay pinned in
14
- * `ENVIRONMENTS`: prod goes through the `cloud.devicecloud.dev` custom domain,
15
- * which customer firewalls may allow-list, not the API's raw `supabase.co` URL.
16
- */
17
1
  import { type DcdEnvName } from './environments.js';
18
2
  /** The publishable key for `env`. A failed fetch is not cached, so the next call retries. */
19
3
  export declare function getSupabaseKey(env: DcdEnvName): Promise<string>;
@@ -3,43 +3,24 @@
3
3
  *
4
4
  * Releases up to this one compiled the anon key in, so the key could never be
5
5
  * rotated without breaking every CLI version pinned in customer CI. The API now
6
- * serves it from the public `GET /cli-config`, and rotating it is an env change
7
- * on the API.
8
- *
9
- * Fetched once per process and kept in memory only. It is deliberately not
10
- * cached on disk: a stale key makes GoTrue answer a refresh with a 4xx, which
11
- * `resolveAuth` treats as a dead session and deletes the user's login.
6
+ * serves it from the public `GET /cli-config` (see ./cli-config.ts for the
7
+ * fetch and its in-memory cache), and rotating it is an env change on the API.
12
8
  *
13
9
  * Only the key comes from the API. The Supabase URLs stay pinned in
14
10
  * `ENVIRONMENTS`: prod goes through the `cloud.devicecloud.dev` custom domain,
15
11
  * which customer firewalls may allow-list, not the API's raw `supabase.co` URL.
16
12
  */
13
+ import { cliConfigUrl, getCliConfig, resetCliConfigCache } from './cli-config.js';
17
14
  import { ENVIRONMENTS } from './environments.js';
18
- const FETCH_TIMEOUT_MS = 10_000;
19
- const cache = new Map();
20
- async function fetchSupabaseKey(env) {
21
- const url = `${ENVIRONMENTS[env].apiUrl}/cli-config`;
22
- const res = await fetch(url, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
23
- if (!res.ok) {
24
- throw new Error(`Failed to fetch CLI config from ${url}: HTTP ${res.status}`);
25
- }
26
- const body = (await res.json());
27
- const key = body.supabase_publishable_key;
15
+ /** The publishable key for `env`. A failed fetch is not cached, so the next call retries. */
16
+ export async function getSupabaseKey(env) {
17
+ const apiUrl = ENVIRONMENTS[env].apiUrl;
18
+ const key = (await getCliConfig(apiUrl)).supabase_publishable_key;
28
19
  if (typeof key !== 'string' || key.length === 0) {
29
- throw new Error(`CLI config from ${url} has no supabase_publishable_key`);
20
+ throw new Error(`CLI config from ${cliConfigUrl(apiUrl)} has no supabase_publishable_key`);
30
21
  }
31
22
  return key;
32
23
  }
33
- /** The publishable key for `env`. A failed fetch is not cached, so the next call retries. */
34
- export function getSupabaseKey(env) {
35
- let pending = cache.get(env);
36
- if (!pending) {
37
- pending = fetchSupabaseKey(env);
38
- cache.set(env, pending);
39
- pending.catch(() => cache.delete(env));
40
- }
41
- return pending;
42
- }
43
24
  /**
44
25
  * Headers that authenticate a raw Storage/Auth request with `key` alone. A
45
26
  * legacy anon key is a JWT and also goes in `Authorization`; an
@@ -50,5 +31,5 @@ export function supabaseKeyHeaders(key) {
50
31
  }
51
32
  /** Test seam: forget fetched keys. */
52
33
  export function resetSupabaseKeyCache() {
53
- cache.clear();
34
+ resetCliConfigCache();
54
35
  }
@@ -228,8 +228,7 @@ export declare const flags: {
228
228
  };
229
229
  readonly encrypt: {
230
230
  readonly type: "boolean";
231
- readonly hidden: true;
232
- readonly description: "Encrypt the app binary, flow zip, and env vars before upload (client-side envelope encryption; each gets its own key). The binary is still deduplicated across runs, so an unchanged app is not re-uploaded. Also turned on by DCD_ENCRYPT=1, and by default for orgs in the encryption beta; --no-encrypt or DCD_ENCRYPT=0 turns it off.";
231
+ readonly description: "Encrypt the app binary, flow zip, and env vars before upload (client-side envelope encryption; each gets its own key). On by default; --no-encrypt or DCD_ENCRYPT=0 turns it off. The binary is still deduplicated across runs, so an unchanged app is not re-uploaded.";
233
232
  };
234
233
  readonly 'api-key': {
235
234
  readonly type: "string";
package/dist/index.js CHANGED
@@ -14,7 +14,6 @@ import { uploadCommand } from './commands/upload.js';
14
14
  import { whoamiCommand } from './commands/whoami.js';
15
15
  import { telemetry } from './services/telemetry.service.js';
16
16
  import { CliError, getCliVersion, logger, wantsJson } from './utils/cli.js';
17
- import { withoutHiddenArgs } from './utils/help.js';
18
17
  // @clack/prompts ships the US spelling ("Canceled") for its built-in
19
18
  // spinner/prompt cancellation message; align it with the British spelling
20
19
  // ("Cancelled") used everywhere else in the CLI.
@@ -66,17 +65,12 @@ async function resolveSubCommand(cmd, rawArgs, parent) {
66
65
  }
67
66
  return [cmd, parent];
68
67
  }
69
- // Usage for the (sub)command named in rawArgs, without the args marked hidden.
70
- async function showHelp(rawArgs) {
71
- const [cmd, parent] = await resolveSubCommand(main, rawArgs);
72
- await showUsage(await withoutHiddenArgs(cmd), parent);
73
- }
74
68
  async function run() {
75
69
  const rawArgs = process.argv.slice(2);
76
70
  telemetry.recordCommandStart();
77
71
  try {
78
72
  if (rawArgs.includes('--help') || rawArgs.includes('-h')) {
79
- await showHelp(rawArgs);
73
+ await showUsage(...(await resolveSubCommand(main, rawArgs)));
80
74
  }
81
75
  else if (rawArgs.length === 1 && rawArgs[0] === '--version') {
82
76
  logger.log(getCliVersion());
@@ -94,7 +88,7 @@ async function run() {
94
88
  // citty throws CLIError (by name — the class isn't exported) for usage
95
89
  // problems like unknown commands or missing required args.
96
90
  if (!json && error instanceof Error && error.name === 'CLIError') {
97
- await showHelp(rawArgs);
91
+ await showUsage(...(await resolveSubCommand(main, rawArgs)));
98
92
  }
99
93
  const exitCode = error instanceof CliError ? error.exitCode : 1;
100
94
  // logger.error prints the message, records failure telemetry, flushes
@@ -84,7 +84,7 @@ export function registerRunCloudTest(server) {
84
84
  encrypt: z
85
85
  .boolean()
86
86
  .optional()
87
- .describe('true encrypts the binary, flow zip and env vars client-side before upload; false never does. Omit to follow DCD_ENCRYPT, then the organization default.'),
87
+ .describe('true encrypts the binary, flow zip and env vars client-side before upload; false never does. Omit to follow DCD_ENCRYPT, then the default, which is on.'),
88
88
  wait: z
89
89
  .boolean()
90
90
  .optional()
@@ -152,8 +152,8 @@ export function registerRunCloudTest(server) {
152
152
  });
153
153
  }
154
154
  // Client-side envelope encryption (binary/flow/env), in the same order
155
- // as `dcd cloud`: the encrypt input, DCD_ENCRYPT, then the org default.
156
- const encryption = checkKekForEncryption(resolveEncryption({
155
+ // as `dcd cloud`: the encrypt input, DCD_ENCRYPT, then the server default.
156
+ const encryption = await checkKekForEncryption(resolveEncryption({
157
157
  flag: args.encrypt,
158
158
  serverDefault: compatibilityData.encryption?.defaultOn,
159
159
  }), apiUrl);
@@ -169,7 +169,7 @@ export function registerRunCloudTest(server) {
169
169
  };
170
170
  telemetryExtra.encrypt = encryptTelemetry;
171
171
  if (encrypt && encryption.source === 'server') {
172
- logStderr('Encrypting uploads (beta); opt out with encrypt: false');
172
+ logStderr('Encrypting uploads; opt out with encrypt: false');
173
173
  }
174
174
  // Resolve the binary: existing id, or upload the local file.
175
175
  let appBinaryId = args.appBinaryId;
package/dist/methods.js CHANGED
@@ -190,15 +190,15 @@ export const uploadBinary = async (config) => {
190
190
  /**
191
191
  * Encrypt the prepared upload source in place (dcd#1138): generate a per-upload
192
192
  * DEK, stream-encrypt `source.diskPath` into a temp ciphertext file, wrap the
193
- * DEK with the environment's pinned KEK public key, and repoint `source` at the
193
+ * DEK with the KEK public key the API publishes, and repoint `source` at the
194
194
  * ciphertext so the SHA, dedup check, and both uploaders operate on ciphertext.
195
195
  * Returns the envelope metadata (for `binaries.metadata.enc`) plus the temp dir
196
196
  * to clean up. Throws if no KEK is available for the environment.
197
197
  */
198
198
  async function encryptUploadSource(source, apiUrl, debug) {
199
- const kek = resolveKekPublicKey(apiUrl);
199
+ const kek = await resolveKekPublicKey(apiUrl);
200
200
  if (!kek) {
201
- throw new Error('Encryption is on (from --encrypt, DCD_ENCRYPT or the organization default) but no KEK public key is configured for this API. ' +
201
+ throw new Error('Encryption is on (from --encrypt, DCD_ENCRYPT or the default) but no KEK public key is configured for this API. ' +
202
202
  'Set DCD_BINARY_KEK_PUBLIC=<version>:<base64>, or pass --no-encrypt to upload without encryption.');
203
203
  }
204
204
  const dek = generateDek();
@@ -78,9 +78,9 @@ export class TestSubmissionService {
78
78
  if (!apiUrl) {
79
79
  throw new Error('Encryption requires apiUrl to resolve the KEK public key');
80
80
  }
81
- const kek = resolveKekPublicKey(apiUrl);
81
+ const kek = await resolveKekPublicKey(apiUrl);
82
82
  if (!kek) {
83
- throw new Error('Encryption is on (from --encrypt, DCD_ENCRYPT or the organization default) but no KEK public key is configured for this API. ' +
83
+ throw new Error('Encryption is on (from --encrypt, DCD_ENCRYPT or the default) but no KEK public key is configured for this API. ' +
84
84
  'Set DCD_BINARY_KEK_PUBLIC=<version>:<base64>, or pass --no-encrypt to upload without encryption.');
85
85
  }
86
86
  const flow = encryptFlowBuffer(plaintextZip, kek);
@@ -12,9 +12,8 @@ export interface CompatibilityData {
12
12
  /** Active CLI notices, piggybacked onto the compatibility response by the API. */
13
13
  notices?: Notice[];
14
14
  /**
15
- * The org's client-side encryption default (dcd#1138): on for orgs in the
16
- * `client_encryption` beta unless the API's kill switch is set. An older API
17
- * omits it, which means off.
15
+ * The client-side encryption default (dcd#1138): on for every org unless the
16
+ * API's kill switch is set. An older API omits it, which means off.
18
17
  */
19
18
  encryption?: {
20
19
  defaultOn: boolean;
@@ -29,7 +29,7 @@ export interface EncryptionDecision {
29
29
  * 1. `flag`: `--encrypt` / `--no-encrypt`, or the MCP tool's `encrypt` input.
30
30
  * 2. `DCD_ENCRYPT`, then its legacy alias `DCD_ENCRYPT_BINARIES`.
31
31
  * 3. `serverDefault`: `encryption.defaultOn` from the compatibility data,
32
- * which the API turns on for orgs in the `client_encryption` beta.
32
+ * which the API turns on for every org unless its kill switch is set.
33
33
  * 4. Off. An API too old to send `encryption` ends up here.
34
34
  * When on, the binary, the flow zip, and the env map are each encrypted with
35
35
  * their **own** per-upload DEK (all wrapped under the same per-env KEK).
@@ -41,26 +41,32 @@ export declare function resolveEncryption(opts: {
41
41
  }): EncryptionDecision;
42
42
  /**
43
43
  * Check that `apiUrl` has a KEK before a run encrypts against it: either
44
- * `DCD_BINARY_KEK_PUBLIC` is set or the URL is a known devicecloud.dev API
45
- * (see kekEnvForApiUrl). Without one, an explicit `--encrypt` is an error,
46
- * while encryption from DCD_ENCRYPT or the org default is skipped with a
47
- * notice, so a run against another API URL uploads in plaintext as before.
44
+ * `DCD_BINARY_KEK_PUBLIC` is set or the API publishes one on `GET /cli-config`
45
+ * (see resolveKekPublicKey). Without one, an explicit `--encrypt` is an error,
46
+ * while encryption from DCD_ENCRYPT or the server default is skipped with a
47
+ * notice, so a run against an API that publishes no KEK uploads in plaintext
48
+ * as before. An API that cannot be asked at all is an error whatever decided
49
+ * encryption: silently falling back to plaintext would be the one outcome the
50
+ * org asked not to have.
48
51
  */
49
- export declare function checkKekForEncryption(decision: EncryptionDecision, apiUrl: string): EncryptionDecision;
50
- /** Pinned KEK public key (base64 raw 32-byte X25519) + version, per env. */
52
+ export declare function checkKekForEncryption(decision: EncryptionDecision, apiUrl: string): Promise<EncryptionDecision>;
53
+ /** KEK public key (raw 32-byte X25519) + the version the API unwraps it with. */
51
54
  interface KekPublicKey {
52
55
  version: number;
53
56
  keyRaw: Buffer;
54
57
  }
55
58
  /**
56
- * Resolve the KEK public key for the environment behind `apiUrl`. Order:
59
+ * Resolve the KEK public key for the API behind `apiUrl`. Order:
57
60
  * 1. `DCD_BINARY_KEK_PUBLIC` env override (`<version>:<base64>`, e.g. `1:AAAA…`)
58
- * — lets the feature be exercised before keys are pinned in the release,
59
- * or against an API URL that isn't a known one.
60
- * 2. the pinned `ENVIRONMENTS[env].kekPublicKey`, only for a known API URL.
61
- * Returns null when no key is available (encryption cannot proceed).
61
+ * — lets the feature be exercised against an API that publishes nothing.
62
+ * 2. `binary_kek_public_key` from the API's own `GET /cli-config` (dcd#1138):
63
+ * the newest KEK the API holds the private half of. Fetched once per
64
+ * process (see ../config/cli-config.ts), so a KEK rotation is an env
65
+ * change on the API and never a CLI release.
66
+ * Returns null when the API publishes no key (encryption cannot proceed).
67
+ * Throws when the API cannot be asked, or publishes something malformed.
62
68
  */
63
- export declare function resolveKekPublicKey(apiUrl: string): KekPublicKey | null;
69
+ export declare function resolveKekPublicKey(apiUrl: string): Promise<KekPublicKey | null>;
64
70
  /**
65
71
  * Wrap a DEK for the given KEK public key (X25519 sealed box). Produces base64 of
66
72
  * `ephPub(32) || iv(12) || ciphertext(32) || tag(16)`.
@@ -1,6 +1,6 @@
1
1
  import { createCipheriv, createPublicKey, diffieHellman, generateKeyPairSync, hkdfSync, randomBytes, } from 'node:crypto';
2
2
  import { open, stat } from 'node:fs/promises';
3
- import { ENVIRONMENTS, kekEnvForApiUrl } from '../config/environments.js';
3
+ import { cliConfigUrl, getCliConfig } from '../config/cli-config.js';
4
4
  /**
5
5
  * Client-side envelope encryption of app binaries before upload (dcd#1138).
6
6
  *
@@ -10,9 +10,9 @@ import { ENVIRONMENTS, kekEnvForApiUrl } from '../config/environments.js';
10
10
  * specified in `dcd/docs/binary-envelope-encryption.md`.
11
11
  *
12
12
  * Scheme: a per-upload random 256-bit DEK encrypts the binary (chunked
13
- * AES-256-GCM); the DEK is wrapped with the environment's pinned X25519 KEK
14
- * public key (sealed box). Only the platform API holds the KEK private half, so
15
- * every storage/transport tier sees ciphertext only.
13
+ * AES-256-GCM); the DEK is wrapped with the X25519 KEK public key the API
14
+ * publishes on `GET /cli-config` (sealed box). Only the platform API holds the
15
+ * KEK private half, so every storage/transport tier sees ciphertext only.
16
16
  */
17
17
  const MAGIC = Buffer.from('DCDE', 'ascii');
18
18
  const CONTAINER_VERSION = 1;
@@ -45,7 +45,7 @@ function parseEncryptEnv(value) {
45
45
  * 1. `flag`: `--encrypt` / `--no-encrypt`, or the MCP tool's `encrypt` input.
46
46
  * 2. `DCD_ENCRYPT`, then its legacy alias `DCD_ENCRYPT_BINARIES`.
47
47
  * 3. `serverDefault`: `encryption.defaultOn` from the compatibility data,
48
- * which the API turns on for orgs in the `client_encryption` beta.
48
+ * which the API turns on for every org unless its kill switch is set.
49
49
  * 4. Off. An API too old to send `encryption` ends up here.
50
50
  * When on, the binary, the flow zip, and the env map are each encrypted with
51
51
  * their **own** per-upload DEK (all wrapped under the same per-env KEK).
@@ -63,21 +63,24 @@ export function resolveEncryption(opts) {
63
63
  }
64
64
  /**
65
65
  * Check that `apiUrl` has a KEK before a run encrypts against it: either
66
- * `DCD_BINARY_KEK_PUBLIC` is set or the URL is a known devicecloud.dev API
67
- * (see kekEnvForApiUrl). Without one, an explicit `--encrypt` is an error,
68
- * while encryption from DCD_ENCRYPT or the org default is skipped with a
69
- * notice, so a run against another API URL uploads in plaintext as before.
66
+ * `DCD_BINARY_KEK_PUBLIC` is set or the API publishes one on `GET /cli-config`
67
+ * (see resolveKekPublicKey). Without one, an explicit `--encrypt` is an error,
68
+ * while encryption from DCD_ENCRYPT or the server default is skipped with a
69
+ * notice, so a run against an API that publishes no KEK uploads in plaintext
70
+ * as before. An API that cannot be asked at all is an error whatever decided
71
+ * encryption: silently falling back to plaintext would be the one outcome the
72
+ * org asked not to have.
70
73
  */
71
- export function checkKekForEncryption(decision, apiUrl) {
72
- if (!decision.enabled || resolveKekPublicKey(apiUrl))
74
+ export async function checkKekForEncryption(decision, apiUrl) {
75
+ if (!decision.enabled || (await resolveKekPublicKey(apiUrl)))
73
76
  return decision;
74
77
  if (decision.source === 'flag') {
75
- throw new Error(`--encrypt needs the KEK public key of the API it uploads to, and ${apiUrl} is not a devicecloud.dev API this CLI has one for. ` +
78
+ throw new Error(`--encrypt needs the KEK public key of the API it uploads to, and ${apiUrl} does not publish one. ` +
76
79
  'Set DCD_BINARY_KEK_PUBLIC=<version>:<base64> to encrypt against it, or drop --encrypt.');
77
80
  }
78
81
  return {
79
82
  enabled: false,
80
- notice: `Not encrypting uploads: ${apiUrl} is not a devicecloud.dev API this CLI has a key for. Set DCD_BINARY_KEK_PUBLIC to encrypt against it.`,
83
+ notice: `Not encrypting uploads: ${apiUrl} does not publish a KEK public key. Set DCD_BINARY_KEK_PUBLIC to encrypt against it.`,
81
84
  source: decision.source,
82
85
  };
83
86
  }
@@ -89,14 +92,17 @@ function x25519PublicFromRaw(raw) {
89
92
  });
90
93
  }
91
94
  /**
92
- * Resolve the KEK public key for the environment behind `apiUrl`. Order:
95
+ * Resolve the KEK public key for the API behind `apiUrl`. Order:
93
96
  * 1. `DCD_BINARY_KEK_PUBLIC` env override (`<version>:<base64>`, e.g. `1:AAAA…`)
94
- * — lets the feature be exercised before keys are pinned in the release,
95
- * or against an API URL that isn't a known one.
96
- * 2. the pinned `ENVIRONMENTS[env].kekPublicKey`, only for a known API URL.
97
- * Returns null when no key is available (encryption cannot proceed).
97
+ * — lets the feature be exercised against an API that publishes nothing.
98
+ * 2. `binary_kek_public_key` from the API's own `GET /cli-config` (dcd#1138):
99
+ * the newest KEK the API holds the private half of. Fetched once per
100
+ * process (see ../config/cli-config.ts), so a KEK rotation is an env
101
+ * change on the API and never a CLI release.
102
+ * Returns null when the API publishes no key (encryption cannot proceed).
103
+ * Throws when the API cannot be asked, or publishes something malformed.
98
104
  */
99
- export function resolveKekPublicKey(apiUrl) {
105
+ export async function resolveKekPublicKey(apiUrl) {
100
106
  const override = process.env.DCD_BINARY_KEK_PUBLIC;
101
107
  if (override) {
102
108
  const [versionPart, b64] = override.split(':');
@@ -108,17 +114,15 @@ export function resolveKekPublicKey(apiUrl) {
108
114
  }
109
115
  throw new Error('DCD_BINARY_KEK_PUBLIC must be "<version>:<base64 32-byte X25519 public key>"');
110
116
  }
111
- const env = kekEnvForApiUrl(apiUrl);
112
- if (!env)
117
+ const published = (await getCliConfig(apiUrl)).binary_kek_public_key;
118
+ if (published === undefined || published === null)
113
119
  return null;
114
- const pinned = ENVIRONMENTS[env].kekPublicKey;
115
- if (!pinned)
116
- return null;
117
- const keyRaw = Buffer.from(pinned.key, 'base64');
118
- if (keyRaw.length !== 32) {
119
- throw new Error(`Pinned KEK public key for ${env} is not a 32-byte key`);
120
+ const { version, key } = published;
121
+ const keyRaw = typeof key === 'string' ? Buffer.from(key, 'base64') : Buffer.alloc(0);
122
+ if (!Number.isInteger(version) || keyRaw.length !== 32) {
123
+ throw new Error(`CLI config from ${cliConfigUrl(apiUrl)} has a malformed binary_kek_public_key; expected { version: integer, key: base64 32-byte X25519 public key }`);
120
124
  }
121
- return { version: pinned.version, keyRaw };
125
+ return { version: version, keyRaw };
122
126
  }
123
127
  /**
124
128
  * Wrap a DEK for the given KEK public key (X25519 sealed box). Produces base64 of
package/package.json CHANGED
@@ -68,7 +68,7 @@
68
68
  "test:unit": "node scripts/test-runner.mjs --unit",
69
69
  "typecheck": "tsc --noEmit -p tsconfig.test.json"
70
70
  },
71
- "version": "5.9.0",
71
+ "version": "5.10.0-beta.1",
72
72
  "bugs": {
73
73
  "url": "https://discord.gg/gm3mJwcNw8"
74
74
  },
@@ -1,12 +0,0 @@
1
- import type { ArgDef, ArgsDef, CommandDef } from 'citty';
2
- /**
3
- * A citty arg definition plus a local `hidden` marker. citty (0.2) can hide a
4
- * command from help (`meta.hidden`) but not an arg, so {@link withoutHiddenArgs}
5
- * drops hidden args before usage is rendered. They still parse as normal.
6
- */
7
- export type CliArgDef = ArgDef & {
8
- hidden?: boolean;
9
- };
10
- export type CliArgsDef = Record<string, CliArgDef>;
11
- /** `cmd` with its hidden args left out, for rendering `--help` only. */
12
- export declare function withoutHiddenArgs<T extends ArgsDef>(cmd: CommandDef<T>): Promise<CommandDef<T>>;
@@ -1,8 +0,0 @@
1
- /** `cmd` with its hidden args left out, for rendering `--help` only. */
2
- export async function withoutHiddenArgs(cmd) {
3
- const args = typeof cmd.args === 'function' ? await cmd.args() : await cmd.args;
4
- if (!args)
5
- return cmd;
6
- const visible = Object.fromEntries(Object.entries(args).filter(([, def]) => !def.hidden));
7
- return { ...cmd, args: visible };
8
- }