@devicecloud.dev/dcd 5.8.0 → 5.9.0
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/dist/commands/artifacts.d.ts +4 -0
- package/dist/commands/artifacts.js +21 -6
- package/dist/commands/cloud.js +2 -4
- package/dist/commands/list.js +1 -2
- package/dist/commands/live.js +159 -56
- package/dist/commands/login.d.ts +8 -0
- package/dist/commands/login.js +74 -14
- package/dist/commands/logout.d.ts +6 -1
- package/dist/commands/logout.js +17 -5
- package/dist/commands/status.js +5 -8
- package/dist/commands/switch-org.d.ts +4 -0
- package/dist/commands/switch-org.js +26 -23
- package/dist/commands/upgrade.d.ts +6 -1
- package/dist/commands/upgrade.js +24 -3
- package/dist/commands/upload.js +1 -2
- package/dist/commands/whoami.d.ts +4 -0
- package/dist/commands/whoami.js +17 -0
- package/dist/config/environments.d.ts +6 -9
- package/dist/config/environments.js +4 -8
- package/dist/config/flags/output.flags.d.ts +8 -0
- package/dist/config/flags/output.flags.js +8 -0
- package/dist/config/supabase-key.d.ts +27 -0
- package/dist/config/supabase-key.js +54 -0
- package/dist/gateways/cli-auth-gateway.d.ts +3 -2
- package/dist/gateways/cli-auth-gateway.js +16 -6
- package/dist/gateways/realtime-gateway.js +48 -34
- package/dist/gateways/supabase-gateway.d.ts +1 -1
- package/dist/gateways/supabase-gateway.js +8 -6
- package/dist/index.js +6 -2
- package/dist/services/report-download.service.d.ts +12 -5
- package/dist/services/report-download.service.js +15 -10
- package/dist/utils/auth.js +1 -3
- package/dist/utils/ci.d.ts +9 -0
- package/dist/utils/ci.js +9 -0
- package/dist/utils/cli.d.ts +7 -0
- package/dist/utils/cli.js +23 -6
- package/dist/utils/orgs.d.ts +38 -1
- package/dist/utils/orgs.js +59 -3
- package/package.json +3 -3
package/dist/utils/orgs.d.ts
CHANGED
|
@@ -1,11 +1,48 @@
|
|
|
1
|
+
import type { Readable, Writable } from 'node:stream';
|
|
1
2
|
export interface OrgListItem {
|
|
2
3
|
id: string;
|
|
3
4
|
name: string;
|
|
4
5
|
slug?: string;
|
|
5
6
|
}
|
|
6
7
|
export declare function fetchOrgs(apiUrl: string, headers: Record<string, string>): Promise<OrgListItem[]>;
|
|
8
|
+
/**
|
|
9
|
+
* Match a user-supplied string to an org. Prefers case-insensitive name match.
|
|
10
|
+
* Falls back to slug / id so existing scripts keep working, but error output
|
|
11
|
+
* only surfaces names. `pickCommand` is how to pick interactively instead,
|
|
12
|
+
* for when two orgs share a name.
|
|
13
|
+
*/
|
|
14
|
+
export declare function matchOrg(orgs: OrgListItem[], target: string, pickCommand: string): OrgListItem;
|
|
15
|
+
export interface PickOrgOptions {
|
|
16
|
+
message?: string;
|
|
17
|
+
/** Org to start the picker on, so Enter confirms it. Ignored if not listed. */
|
|
18
|
+
initialId?: string;
|
|
19
|
+
input?: Readable;
|
|
20
|
+
output?: Writable;
|
|
21
|
+
}
|
|
7
22
|
/**
|
|
8
23
|
* Interactive org picker. Auto-selects when there's only one org (returns it
|
|
9
24
|
* without prompting). Throws on zero orgs or user cancellation.
|
|
10
25
|
*/
|
|
11
|
-
export declare function pickOrg(orgs: OrgListItem[], message?:
|
|
26
|
+
export declare function pickOrg(orgs: OrgListItem[], { message, initialId, input, output, }?: PickOrgOptions): Promise<OrgListItem>;
|
|
27
|
+
export interface SelectOrgOptions {
|
|
28
|
+
/** `dcd login --org`: a name, slug or id. Skips the picker. */
|
|
29
|
+
requested?: string;
|
|
30
|
+
/** The org the last login chose. */
|
|
31
|
+
lastOrgId?: string;
|
|
32
|
+
/** Whether anyone can answer the picker (see canPrompt). */
|
|
33
|
+
interactive: boolean;
|
|
34
|
+
input?: Readable;
|
|
35
|
+
output?: Writable;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Choose the org for `dcd login`: `--org` if given, else the only org, else
|
|
39
|
+
* the picker starting on the last login's org. Without a TTY nobody can
|
|
40
|
+
* answer the picker, so the last login's org is used without asking, and
|
|
41
|
+
* when there isn't one the error names `--org` instead of hanging.
|
|
42
|
+
* `fromLastLogin` is set when that fallback chose the org, so the caller
|
|
43
|
+
* can say so.
|
|
44
|
+
*/
|
|
45
|
+
export declare function selectOrg(orgs: OrgListItem[], { requested, lastOrgId, interactive, input, output }: SelectOrgOptions): Promise<{
|
|
46
|
+
org: OrgListItem;
|
|
47
|
+
fromLastLogin: boolean;
|
|
48
|
+
}>;
|
package/dist/utils/orgs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared helpers for fetching and picking from /me/orgs. Used by
|
|
3
|
-
* `dcd login` (after the PKCE claim returns a session) and `dcd switch-org`.
|
|
2
|
+
* Shared helpers for fetching, matching and picking from /me/orgs. Used by
|
|
3
|
+
* both `dcd login` (after the PKCE claim returns a session) and `dcd switch-org`.
|
|
4
4
|
*/
|
|
5
5
|
import * as p from '@clack/prompts';
|
|
6
6
|
import { CliError } from './cli.js';
|
|
@@ -13,11 +13,29 @@ export async function fetchOrgs(apiUrl, headers) {
|
|
|
13
13
|
const body = (await res.json());
|
|
14
14
|
return body.orgs ?? [];
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Match a user-supplied string to an org. Prefers case-insensitive name match.
|
|
18
|
+
* Falls back to slug / id so existing scripts keep working, but error output
|
|
19
|
+
* only surfaces names. `pickCommand` is how to pick interactively instead,
|
|
20
|
+
* for when two orgs share a name.
|
|
21
|
+
*/
|
|
22
|
+
export function matchOrg(orgs, target, pickCommand) {
|
|
23
|
+
const needle = target.toLowerCase();
|
|
24
|
+
const nameMatches = orgs.filter((o) => o.name.toLowerCase() === needle);
|
|
25
|
+
if (nameMatches.length > 1) {
|
|
26
|
+
throw new CliError(`Multiple orgs named "${target}". Run ${pickCommand} to pick interactively.`);
|
|
27
|
+
}
|
|
28
|
+
const chosen = nameMatches[0] ?? orgs.find((o) => o.slug === target || o.id === target);
|
|
29
|
+
if (!chosen) {
|
|
30
|
+
throw new CliError(`No org named "${target}". Available: ${orgs.map((o) => o.name).join(', ')}`);
|
|
31
|
+
}
|
|
32
|
+
return chosen;
|
|
33
|
+
}
|
|
16
34
|
/**
|
|
17
35
|
* Interactive org picker. Auto-selects when there's only one org (returns it
|
|
18
36
|
* without prompting). Throws on zero orgs or user cancellation.
|
|
19
37
|
*/
|
|
20
|
-
export async function pickOrg(orgs, message = 'Pick an organization') {
|
|
38
|
+
export async function pickOrg(orgs, { message = 'Pick an organization', initialId, input, output, } = {}) {
|
|
21
39
|
if (orgs.length === 0) {
|
|
22
40
|
throw new CliError('No organizations found for this user.');
|
|
23
41
|
}
|
|
@@ -25,7 +43,11 @@ export async function pickOrg(orgs, message = 'Pick an organization') {
|
|
|
25
43
|
return orgs[0];
|
|
26
44
|
const picked = await p.select({
|
|
27
45
|
message,
|
|
46
|
+
input,
|
|
47
|
+
output,
|
|
28
48
|
options: orgs.map((o) => ({ value: o.id, label: o.name })),
|
|
49
|
+
// clack starts on the first option when this isn't one of them.
|
|
50
|
+
initialValue: initialId,
|
|
29
51
|
});
|
|
30
52
|
if (p.isCancel(picked))
|
|
31
53
|
throw new CliError('Cancelled.');
|
|
@@ -34,3 +56,37 @@ export async function pickOrg(orgs, message = 'Pick an organization') {
|
|
|
34
56
|
throw new CliError('No organization selected.');
|
|
35
57
|
return chosen;
|
|
36
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Choose the org for `dcd login`: `--org` if given, else the only org, else
|
|
61
|
+
* the picker starting on the last login's org. Without a TTY nobody can
|
|
62
|
+
* answer the picker, so the last login's org is used without asking, and
|
|
63
|
+
* when there isn't one the error names `--org` instead of hanging.
|
|
64
|
+
* `fromLastLogin` is set when that fallback chose the org, so the caller
|
|
65
|
+
* can say so.
|
|
66
|
+
*/
|
|
67
|
+
export async function selectOrg(orgs, { requested, lastOrgId, interactive, input, output }) {
|
|
68
|
+
if (orgs.length === 0) {
|
|
69
|
+
throw new CliError('No organizations found for this user.');
|
|
70
|
+
}
|
|
71
|
+
if (requested !== undefined) {
|
|
72
|
+
return {
|
|
73
|
+
org: matchOrg(orgs, requested, '`dcd login` without --org'),
|
|
74
|
+
fromLastLogin: false,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
if (orgs.length === 1)
|
|
78
|
+
return { org: orgs[0], fromLastLogin: false };
|
|
79
|
+
if (!interactive) {
|
|
80
|
+
const last = orgs.find((o) => o.id === lastOrgId);
|
|
81
|
+
if (last)
|
|
82
|
+
return { org: last, fromLastLogin: true };
|
|
83
|
+
const reason = lastOrgId
|
|
84
|
+
? "The organization from your last login is no longer available, and there's no terminal to pick another in."
|
|
85
|
+
: "You belong to more than one organization, and there's no terminal to pick one in.";
|
|
86
|
+
throw new CliError(`${reason} Run \`dcd login --org <name>\` with one of: ${orgs.map((o) => o.name).join(', ')}`);
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
org: await pickOrg(orgs, { initialId: lastOrgId, input, output }),
|
|
90
|
+
fromLastLogin: false,
|
|
91
|
+
};
|
|
92
|
+
}
|
package/package.json
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"chai": "^6.2.2",
|
|
31
31
|
"eslint": "^10.5.0",
|
|
32
32
|
"eslint-config-prettier": "^10.1.8",
|
|
33
|
-
"eslint-plugin-unicorn": "^
|
|
33
|
+
"eslint-plugin-unicorn": "^78.0.0",
|
|
34
34
|
"husky": "^9.1.7",
|
|
35
35
|
"mocha": "^12.0.0",
|
|
36
36
|
"prettier": "^3.8.4",
|
|
@@ -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.
|
|
71
|
+
"version": "5.9.0",
|
|
72
72
|
"bugs": {
|
|
73
73
|
"url": "https://discord.gg/gm3mJwcNw8"
|
|
74
74
|
},
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
"esbuild@<0.28.1": ">=0.28.1",
|
|
111
111
|
"qs@<6.16.0": "6.16.0",
|
|
112
112
|
"fast-uri@>=3.0.0 <3.1.8": "3.1.8",
|
|
113
|
-
"hono@>=4.0.0 <4.13.
|
|
113
|
+
"hono@>=4.0.0 <4.13.11": "4.13.11",
|
|
114
114
|
"source-map-js@<1.2.2": "1.2.2",
|
|
115
115
|
"micromatch>picomatch": "^2.3.2",
|
|
116
116
|
"tinyglobby>picomatch": "^4.0.4"
|