@sortlist/cli 0.33.0 → 0.34.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/package.json +1 -1
- package/src/commands/config.ts +3 -4
- package/src/commands/dynamic.ts +2 -13
- package/src/commands/login.ts +3 -58
- package/src/commands/whoami.ts +2 -17
- package/src/graphql/generated/gql.ts +3 -9
- package/src/graphql/generated/graphql.ts +425 -80
- package/src/graphql/operations/common.ts +0 -17
- package/src/index.ts +1 -5
- package/src/lib/company.ts +4 -24
- package/src/lib/config.ts +0 -4
- package/src/commands/offer.ts +0 -96
- package/src/commands/switch.ts +0 -72
package/package.json
CHANGED
package/src/commands/config.ts
CHANGED
|
@@ -31,18 +31,17 @@ configCommand
|
|
|
31
31
|
} else {
|
|
32
32
|
info(`Endpoint: ${config.endpoint}`);
|
|
33
33
|
if (config.oauthId) info(`User: ${config.oauthId}`);
|
|
34
|
-
if (config.
|
|
35
|
-
else if (config.companyId) info(`Company ID: ${config.companyId}`);
|
|
34
|
+
if (config.companyId) info(`Company ID: ${config.companyId}`);
|
|
36
35
|
}
|
|
37
36
|
});
|
|
38
37
|
|
|
39
38
|
configCommand
|
|
40
39
|
.command('set <key> <value>')
|
|
41
|
-
.description(`Set a config value (${isLocalDev ? 'endpoint, ' : ''}companyId
|
|
40
|
+
.description(`Set a config value (${isLocalDev ? 'endpoint, ' : ''}companyId)`)
|
|
42
41
|
.action((key: string, value: string) => {
|
|
43
42
|
// `endpoint` is dev-only — published builds always target production, so the
|
|
44
43
|
// endpoint must not be overridable there (mirrors the gated use-* commands).
|
|
45
|
-
const allowed = [...(isLocalDev ? ['endpoint'] : []), 'companyId', '
|
|
44
|
+
const allowed = [...(isLocalDev ? ['endpoint'] : []), 'companyId', 'oauthId'];
|
|
46
45
|
if (!allowed.includes(key)) {
|
|
47
46
|
error(`Unknown config key: "${key}".`);
|
|
48
47
|
info('');
|
package/src/commands/dynamic.ts
CHANGED
|
@@ -40,7 +40,6 @@ import { error, hint, printJson, warn } from '../lib/output.ts';
|
|
|
40
40
|
// explicitly via `--agency-id`.
|
|
41
41
|
const CONTEXT_FIELDS: Record<string, string> = {
|
|
42
42
|
companyId: 'companyId',
|
|
43
|
-
companySlug: 'companySlug',
|
|
44
43
|
oauthId: 'oauthId',
|
|
45
44
|
};
|
|
46
45
|
|
|
@@ -287,7 +286,6 @@ function buildCommand(
|
|
|
287
286
|
const cmd = new Command(kebab(fieldName)).description(description);
|
|
288
287
|
|
|
289
288
|
const acceptsCompanyId = cliArgs.some((a) => a.name === 'companyId');
|
|
290
|
-
const acceptsCompanySlug = cliArgs.some((a) => a.name === 'companySlug');
|
|
291
289
|
|
|
292
290
|
for (const a of cliArgs) {
|
|
293
291
|
const placeholder = isStructuredInput(a.type) ? 'json' : kebab(a.name);
|
|
@@ -302,13 +300,6 @@ function buildCommand(
|
|
|
302
300
|
}
|
|
303
301
|
}
|
|
304
302
|
|
|
305
|
-
// For company-scoped operations the schema typically only accepts `companyId`.
|
|
306
|
-
// Mirror the chat command's UX: also expose `--company-slug` for convenience,
|
|
307
|
-
// resolved client-side via `me.companies`.
|
|
308
|
-
if (acceptsCompanyId && !acceptsCompanySlug) {
|
|
309
|
-
cmd.option('--company-slug <companySlug>', 'companySlug (resolved to companyId via me.companies)');
|
|
310
|
-
}
|
|
311
|
-
|
|
312
303
|
cmd
|
|
313
304
|
.option('--depth <depth>', 'Selection depth (default: 0)', parseInt)
|
|
314
305
|
.option('--fields <fields>', 'Comma-separated fields to include')
|
|
@@ -320,15 +311,13 @@ function buildCommand(
|
|
|
320
311
|
const ctx = needsContext ? getUserContext() : undefined;
|
|
321
312
|
|
|
322
313
|
if (acceptsCompanyId) {
|
|
323
|
-
const resolved =
|
|
314
|
+
const resolved = resolveCompanyId({
|
|
324
315
|
companyId: typeof opts.companyId === 'string' ? opts.companyId : undefined,
|
|
325
|
-
companySlug: typeof opts.companySlug === 'string' ? opts.companySlug : undefined,
|
|
326
316
|
ctx,
|
|
327
|
-
endpoint: opts.endpoint,
|
|
328
317
|
});
|
|
329
318
|
if (!resolved) {
|
|
330
319
|
error('No company selected.');
|
|
331
|
-
hint('Pass --company-id <id
|
|
320
|
+
hint('Pass --company-id <id> or set one with `sl config set companyId <id>`.');
|
|
332
321
|
process.exit(2);
|
|
333
322
|
}
|
|
334
323
|
opts.companyId = resolved;
|
package/src/commands/login.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createInterface } from 'node:readline';
|
|
2
1
|
import { Command } from 'commander';
|
|
3
2
|
|
|
4
3
|
import { graphql, graphqlUnauthenticated } from '../graphql/client.ts';
|
|
@@ -7,7 +6,7 @@ import { DeviceAuthorize, DeviceToken } from '../graphql/operations/hermes.ts';
|
|
|
7
6
|
import { saveCredentials } from '../lib/auth.ts';
|
|
8
7
|
import { openBrowser } from '../lib/browser.ts';
|
|
9
8
|
import { saveConfig } from '../lib/config.ts';
|
|
10
|
-
import { error, hint, info, success
|
|
9
|
+
import { error, hint, info, success } from '../lib/output.ts';
|
|
11
10
|
|
|
12
11
|
// TODO: fetch the set of available API scopes dynamically (e.g. from Hermes'
|
|
13
12
|
// resource server) once the backend exposes them. For now the CLI requests a
|
|
@@ -22,9 +21,6 @@ const API_SCOPES = [
|
|
|
22
21
|
'atlas/*:read',
|
|
23
22
|
'core/*:*',
|
|
24
23
|
'core/*:read',
|
|
25
|
-
'max/*:*',
|
|
26
|
-
'max/*:read',
|
|
27
|
-
'max/company:write',
|
|
28
24
|
'signals/*:*',
|
|
29
25
|
'signals/*:read',
|
|
30
26
|
'billing/*:*',
|
|
@@ -37,66 +33,15 @@ function sleep(ms: number): Promise<void> {
|
|
|
37
33
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
38
34
|
}
|
|
39
35
|
|
|
40
|
-
interface CompanyChoice {
|
|
41
|
-
id: string;
|
|
42
|
-
name: string;
|
|
43
|
-
slug: string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async function promptCompanySelection(companies: CompanyChoice[]): Promise<CompanyChoice> {
|
|
47
|
-
if (companies.length === 1) {
|
|
48
|
-
info(`Company: ${companies[0].name} (${companies[0].slug})`);
|
|
49
|
-
return companies[0];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
info('\nSelect a company:\n');
|
|
53
|
-
for (let i = 0; i < companies.length; i++) {
|
|
54
|
-
info(` ${i + 1}) ${companies[i].name} (${companies[i].slug})`);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
58
|
-
|
|
59
|
-
return new Promise((resolve) => {
|
|
60
|
-
rl.question(`\nChoice [1-${companies.length}]: `, (answer) => {
|
|
61
|
-
rl.close();
|
|
62
|
-
const idx = parseInt(answer, 10) - 1;
|
|
63
|
-
if (idx >= 0 && idx < companies.length) {
|
|
64
|
-
resolve(companies[idx]);
|
|
65
|
-
} else {
|
|
66
|
-
warn('Invalid choice — defaulting to the first company.');
|
|
67
|
-
resolve(companies[0]);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
36
|
async function setupUserContext(endpoint?: string): Promise<void> {
|
|
74
37
|
const userData = await graphql(Me, undefined, { endpoint });
|
|
75
38
|
const user = userData.me;
|
|
76
39
|
if (!user) return;
|
|
77
40
|
|
|
78
|
-
|
|
79
|
-
.filter((c): c is { id: string; name: string; slug: string } => c != null)
|
|
80
|
-
.map((c) => ({ id: c.id, name: c.name ?? c.slug, slug: c.slug }));
|
|
81
|
-
|
|
82
|
-
const context: Record<string, string | undefined> = {
|
|
83
|
-
oauthId: user.sub ?? undefined,
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
if (companies.length > 0) {
|
|
87
|
-
const selected = await promptCompanySelection(companies);
|
|
88
|
-
context.companyId = selected.id;
|
|
89
|
-
context.companySlug = selected.slug;
|
|
90
|
-
context.companyName = selected.name;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
saveConfig(context);
|
|
41
|
+
saveConfig({ oauthId: user.sub ?? undefined });
|
|
94
42
|
info('');
|
|
95
43
|
info(` User: ${user.firstName} ${user.lastName} <${user.email}>`);
|
|
96
|
-
|
|
97
|
-
info(` Company: ${context.companyName} (${context.companySlug})`);
|
|
98
|
-
}
|
|
99
|
-
hint('Run `sl whoami` to verify, or `sl switch` to change company.');
|
|
44
|
+
hint('Run `sl whoami` to verify.');
|
|
100
45
|
}
|
|
101
46
|
|
|
102
47
|
export const loginCommand = new Command('login')
|
package/src/commands/whoami.ts
CHANGED
|
@@ -2,17 +2,15 @@ import { Command } from 'commander';
|
|
|
2
2
|
|
|
3
3
|
import { graphql, GraphQLRequestError } from '../graphql/client.ts';
|
|
4
4
|
import { Me } from '../graphql/operations/common.ts';
|
|
5
|
-
import { loadConfig } from '../lib/config.ts';
|
|
6
5
|
import { error, hint, info, isJsonMode, printJson } from '../lib/output.ts';
|
|
7
6
|
|
|
8
7
|
export const whoamiCommand = new Command('whoami')
|
|
9
8
|
.summary("Show who you're currently logged in as")
|
|
10
9
|
.description(
|
|
11
10
|
"Show who you're currently logged in as\n\n" +
|
|
12
|
-
'Displays your name
|
|
13
|
-
'(the active one is marked). Use --json for machine-readable output.\n\n' +
|
|
11
|
+
'Displays your name and email. Use --json for machine-readable output.\n\n' +
|
|
14
12
|
'Examples:\n' +
|
|
15
|
-
' sl whoami Show your identity
|
|
13
|
+
' sl whoami Show your identity\n' +
|
|
16
14
|
' sl whoami --json Output full user object as JSON',
|
|
17
15
|
)
|
|
18
16
|
.action(async function (this: Command) {
|
|
@@ -54,17 +52,4 @@ export const whoamiCommand = new Command('whoami')
|
|
|
54
52
|
}
|
|
55
53
|
|
|
56
54
|
info(`${user.firstName} ${user.lastName} <${user.email}> (sub: ${user.sub})`);
|
|
57
|
-
|
|
58
|
-
const companies = (user.companies?.nodes ?? []).filter(
|
|
59
|
-
(c): c is { id: string; name: string; slug: string } => c != null,
|
|
60
|
-
);
|
|
61
|
-
if (companies.length === 0) return;
|
|
62
|
-
|
|
63
|
-
const activeSlug = loadConfig().companySlug;
|
|
64
|
-
info('');
|
|
65
|
-
info('Companies:');
|
|
66
|
-
for (const company of companies) {
|
|
67
|
-
const marker = company.slug === activeSlug ? ' ← active' : '';
|
|
68
|
-
info(` ${company.slug} ${company.name}${marker}`);
|
|
69
|
-
}
|
|
70
55
|
});
|
|
@@ -14,16 +14,14 @@ import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-
|
|
|
14
14
|
* Learn more about it here: https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#reducing-bundle-size
|
|
15
15
|
*/
|
|
16
16
|
type Documents = {
|
|
17
|
-
"\n query Me {\n me {\n sub\n email\n firstName\n lastName\n
|
|
18
|
-
"\n mutation CreateSalesOffer($input: CreateSalesOfferInput!) {\n createSalesOffer(input: $input) {\n inviteUrl\n offerId\n companyId\n }\n }\n": typeof types.CreateSalesOfferDocument,
|
|
17
|
+
"\n query Me {\n me {\n sub\n email\n firstName\n lastName\n }\n }\n": typeof types.MeDocument,
|
|
19
18
|
"\n query LogoutUrl {\n logoutUrl\n }\n": typeof types.LogoutUrlDocument,
|
|
20
19
|
"\n mutation DeviceAuthorize($input: DeviceAuthorizeInput!) {\n deviceAuthorize(input: $input) {\n deviceCode\n expiresIn\n interval\n userCode\n verificationUri\n verificationUriComplete\n }\n }\n": typeof types.DeviceAuthorizeDocument,
|
|
21
20
|
"\n mutation DeviceToken($input: DeviceTokenInput!) {\n deviceToken(input: $input) {\n accessToken\n error\n expiresIn\n idToken\n refreshToken\n tokenType\n }\n }\n": typeof types.DeviceTokenDocument,
|
|
22
21
|
"\n mutation RefreshToken($input: RefreshTokenInput!) {\n refreshToken(input: $input) {\n accessToken\n error\n expiresIn\n idToken\n refreshToken\n tokenType\n }\n }\n": typeof types.RefreshTokenDocument,
|
|
23
22
|
};
|
|
24
23
|
const documents: Documents = {
|
|
25
|
-
"\n query Me {\n me {\n sub\n email\n firstName\n lastName\n
|
|
26
|
-
"\n mutation CreateSalesOffer($input: CreateSalesOfferInput!) {\n createSalesOffer(input: $input) {\n inviteUrl\n offerId\n companyId\n }\n }\n": types.CreateSalesOfferDocument,
|
|
24
|
+
"\n query Me {\n me {\n sub\n email\n firstName\n lastName\n }\n }\n": types.MeDocument,
|
|
27
25
|
"\n query LogoutUrl {\n logoutUrl\n }\n": types.LogoutUrlDocument,
|
|
28
26
|
"\n mutation DeviceAuthorize($input: DeviceAuthorizeInput!) {\n deviceAuthorize(input: $input) {\n deviceCode\n expiresIn\n interval\n userCode\n verificationUri\n verificationUriComplete\n }\n }\n": types.DeviceAuthorizeDocument,
|
|
29
27
|
"\n mutation DeviceToken($input: DeviceTokenInput!) {\n deviceToken(input: $input) {\n accessToken\n error\n expiresIn\n idToken\n refreshToken\n tokenType\n }\n }\n": types.DeviceTokenDocument,
|
|
@@ -47,11 +45,7 @@ export function gql(source: string): unknown;
|
|
|
47
45
|
/**
|
|
48
46
|
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
|
49
47
|
*/
|
|
50
|
-
export function gql(source: "\n query Me {\n me {\n sub\n email\n firstName\n lastName\n
|
|
51
|
-
/**
|
|
52
|
-
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
|
53
|
-
*/
|
|
54
|
-
export function gql(source: "\n mutation CreateSalesOffer($input: CreateSalesOfferInput!) {\n createSalesOffer(input: $input) {\n inviteUrl\n offerId\n companyId\n }\n }\n"): (typeof documents)["\n mutation CreateSalesOffer($input: CreateSalesOfferInput!) {\n createSalesOffer(input: $input) {\n inviteUrl\n offerId\n companyId\n }\n }\n"];
|
|
48
|
+
export function gql(source: "\n query Me {\n me {\n sub\n email\n firstName\n lastName\n }\n }\n"): (typeof documents)["\n query Me {\n me {\n sub\n email\n firstName\n lastName\n }\n }\n"];
|
|
55
49
|
/**
|
|
56
50
|
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
|
57
51
|
*/
|