@sortlist/cli 0.32.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.
@@ -11,23 +11,6 @@ export const Me = gql(`
11
11
  email
12
12
  firstName
13
13
  lastName
14
- companies {
15
- nodes {
16
- id
17
- name
18
- slug
19
- }
20
- }
21
- }
22
- }
23
- `);
24
-
25
- export const CreateSalesOffer = gql(`
26
- mutation CreateSalesOffer($input: CreateSalesOfferInput!) {
27
- createSalesOffer(input: $input) {
28
- inviteUrl
29
- offerId
30
- companyId
31
14
  }
32
15
  }
33
16
  `);
@@ -62,10 +62,13 @@ function buildSelections(
62
62
  const lines: string[] = [];
63
63
  const isPayload = PAYLOAD_TYPE_PATTERN.test(type.name);
64
64
 
65
- // Relay Connection pattern
65
+ // Relay Connection pattern. The connection/`nodes` wrapper is not a semantic
66
+ // nesting level, so the node type inherits the caller's `depth` unchanged —
67
+ // otherwise object fields on the node (e.g. Contact.organization) would never
68
+ // be selected regardless of --depth.
66
69
  if (type.name.endsWith('Connection') && fields.nodes && fields.pageInfo) {
67
70
  const nodesType = unwrap(fields.nodes.type);
68
- const nodeSelections = buildSelections(nodesType, schema, 0, exclude, `${prefix}nodes.`, new Set(visited));
71
+ const nodeSelections = buildSelections(nodesType, schema, depth, exclude, `${prefix}nodes.`, new Set(visited));
69
72
  if (nodeSelections.length === 0) return [];
70
73
  lines.push(`nodes {`);
71
74
  for (const sel of nodeSelections) lines.push(` ${sel}`);
package/src/index.ts CHANGED
@@ -5,8 +5,6 @@ import { configCommand } from './commands/config.ts';
5
5
  import { buildServiceCommands, formatTypeInspection } from './commands/dynamic.ts';
6
6
  import { loginCommand } from './commands/login.ts';
7
7
  import { logoutCommand } from './commands/logout.ts';
8
- import { offerCommand } from './commands/offer.ts';
9
- import { switchCommand } from './commands/switch.ts';
10
8
  import { tokenCommand } from './commands/token.ts';
11
9
  import { whoamiCommand } from './commands/whoami.ts';
12
10
  import { getIntrospectedSchema, refreshSchema } from './graphql/introspection.ts';
@@ -96,10 +94,8 @@ const program = new Command()
96
94
  program.addCommand(loginCommand);
97
95
  program.addCommand(logoutCommand);
98
96
  program.addCommand(whoamiCommand);
99
- program.addCommand(switchCommand);
100
97
  program.addCommand(tokenCommand);
101
98
  program.addCommand(configCommand);
102
- program.addCommand(offerCommand);
103
99
 
104
100
  // Schema refresh command
105
101
  const schemaCommand = new Command('schema').description('Manage the cached GraphQL schema');
@@ -167,7 +163,7 @@ try {
167
163
  } catch (err) {
168
164
  // Schema fetch failed — still allow non-subgraph commands (login, config, etc.)
169
165
  const message = (err as Error).message;
170
- if (!process.argv.some((a) => ['login', 'logout', 'config', 'token', 'whoami', 'switch', 'schema'].includes(a))) {
166
+ if (!process.argv.some((a) => ['login', 'logout', 'config', 'token', 'whoami', 'schema'].includes(a))) {
171
167
  error(`Could not fetch schema: ${message}`);
172
168
  hint('Check your network connection and endpoint: sl config show');
173
169
  hint('You can still use: sl login, sl config, sl schema refresh');
@@ -1,5 +1,3 @@
1
- import { graphql } from '../graphql/client.ts';
2
- import { Me } from '../graphql/operations/common.ts';
3
1
  import { type UserContext } from './config.ts';
4
2
 
5
3
  /**
@@ -7,29 +5,11 @@ import { type UserContext } from './config.ts';
7
5
  *
8
6
  * Resolution order:
9
7
  * 1. --company-id flag
10
- * 2. --company-slug flag → resolved via me.companies
11
- * 3. config.companyId
12
- * 4. config.companySlug → resolved via me.companies
13
- * 5. user has exactly one company → that one
8
+ * 2. config.companyId
14
9
  */
15
- export async function resolveCompanyId(opts: {
10
+ export function resolveCompanyId(opts: {
16
11
  companyId?: string | undefined;
17
- companySlug?: string | undefined;
18
12
  ctx: UserContext | undefined;
19
- endpoint?: string | undefined;
20
- }): Promise<string | undefined> {
21
- if (opts.companyId) return opts.companyId;
22
-
23
- const slug = opts.companySlug || opts.ctx?.companySlug;
24
-
25
- if (!slug && opts.ctx?.companyId) return opts.ctx.companyId;
26
-
27
- const data = await graphql(Me, undefined, { endpoint: opts.endpoint });
28
- const companies = (data.me?.companies?.nodes ?? []).filter(
29
- (c): c is { id: string; name: string; slug: string } => c != null,
30
- );
31
-
32
- if (slug) return companies.find((c) => c.slug === slug)?.id;
33
- if (companies.length === 1) return companies[0].id;
34
- return undefined;
13
+ }): string | undefined {
14
+ return opts.companyId || opts.ctx?.companyId;
35
15
  }
package/src/lib/config.ts CHANGED
@@ -9,8 +9,6 @@ export interface CliConfig {
9
9
  endpoint: string;
10
10
  oauthId?: string;
11
11
  companyId?: string;
12
- companySlug?: string;
13
- companyName?: string;
14
12
  }
15
13
 
16
14
  const DEFAULT_CONFIG: CliConfig = {
@@ -71,7 +69,6 @@ export function getEndpoint(override?: string): string {
71
69
  export interface UserContext {
72
70
  oauthId?: string;
73
71
  companyId?: string;
74
- companySlug?: string;
75
72
  }
76
73
 
77
74
  export function getUserContext(): UserContext {
@@ -79,6 +76,5 @@ export function getUserContext(): UserContext {
79
76
  return {
80
77
  oauthId: config.oauthId,
81
78
  companyId: config.companyId,
82
- companySlug: config.companySlug,
83
79
  };
84
80
  }
@@ -1,96 +0,0 @@
1
- import { Command } from 'commander';
2
-
3
- import { graphql } from '../graphql/client.ts';
4
- import { CreateSalesOffer } from '../graphql/operations/common.ts';
5
- import { error, hint, info, isJsonMode, printJson, success } from '../lib/output.ts';
6
-
7
- interface CreateOptions {
8
- company: string;
9
- plan: string;
10
- periodicity: string;
11
- website?: string;
12
- email?: string;
13
- discountPercent?: string;
14
- discountAmount?: string;
15
- extraSeats?: string;
16
- extraCredits?: string;
17
- expiresInDays?: string;
18
- endpoint?: string;
19
- json?: boolean;
20
- }
21
-
22
- const createCommand = new Command('create')
23
- .summary('Create a sales offer and get the prospect invite link')
24
- .description(
25
- 'Pre-provision a sales-led deal and return the invite link to share with the prospect.\n\n' +
26
- 'Creates the prospect company, its billing customer, and a pending offer (a catalog tier\n' +
27
- 'at a negotiated discount), then prints the onboarding invite URL. The deal is attributed\n' +
28
- 'to you. Requires the billing/offer:write and max/company:write scopes (Sortlist admins).\n\n' +
29
- 'Examples:\n' +
30
- ' sl offer create --company "Acme" --website acme.com --plan growth --discount-percent 20 --email buyer@acme.com\n' +
31
- ' sl offer create --company "Acme" --plan scale --periodicity monthly --extra-seats 3 --json',
32
- )
33
- .requiredOption('--company <name>', 'Prospect company name')
34
- .requiredOption('--plan <plan>', 'Catalog tier: starter, growth, or scale')
35
- .option('--periodicity <period>', 'Billing periodicity: monthly or annual', 'annual')
36
- .option('--website <url>', 'Prospect company website (seeds onboarding)')
37
- .option('--email <email>', 'Prospect email (prefills sign-up and is appended to the link)')
38
- .option('--discount-percent <n>', 'Percentage discount, 0-100 (exclusive with --discount-amount)')
39
- .option('--discount-amount <eur>', 'Absolute recurring discount in EUR (exclusive with --discount-percent)')
40
- .option('--extra-seats <n>', 'Extra seats on top of the tier')
41
- .option('--extra-credits <n>', 'Extra credits each period on top of the tier')
42
- .option('--expires-in-days <n>', 'Days until the offer expires (default: never)')
43
- .action(async function (this: Command) {
44
- const opts = this.optsWithGlobals() as CreateOptions;
45
-
46
- if (opts.discountPercent != null && opts.discountAmount != null) {
47
- error('Pass either --discount-percent or --discount-amount, not both.');
48
- process.exit(1);
49
- }
50
-
51
- const expiresAt =
52
- opts.expiresInDays != null
53
- ? new Date(Date.now() + Number(opts.expiresInDays) * 24 * 60 * 60 * 1000).toISOString()
54
- : undefined;
55
-
56
- const input = {
57
- name: opts.company,
58
- plan: opts.plan,
59
- periodicity: opts.periodicity,
60
- website: opts.website,
61
- email: opts.email,
62
- discountPercent: opts.discountPercent != null ? Number(opts.discountPercent) : undefined,
63
- discountAmountEur: opts.discountAmount != null ? Number(opts.discountAmount) : undefined,
64
- extraSeats: opts.extraSeats != null ? Number(opts.extraSeats) : undefined,
65
- extraCredits: opts.extraCredits != null ? Number(opts.extraCredits) : undefined,
66
- expiresAt,
67
- };
68
-
69
- try {
70
- const data = await graphql(CreateSalesOffer, { input }, { endpoint: opts.endpoint });
71
- const offer = data.createSalesOffer;
72
- if (offer == null) {
73
- error('The server did not return an offer.');
74
- process.exit(1);
75
- }
76
-
77
- if (isJsonMode(opts)) {
78
- printJson(offer);
79
- return;
80
- }
81
-
82
- success(`Offer created for ${opts.company}.`);
83
- info('');
84
- info('Invite link (share with the prospect):');
85
- info(` ${offer.inviteUrl}`);
86
- } catch (caught) {
87
- error(`Could not create the offer: ${(caught as Error).message}`);
88
- hint('Check that your account has the billing/offer:write and max/company:write scopes.');
89
- process.exit(1);
90
- }
91
- });
92
-
93
- export const offerCommand = new Command('offer')
94
- .summary('Manage sales-led offers')
95
- .description('Create sales-led offers and get the prospect invite link.')
96
- .addCommand(createCommand);
@@ -1,72 +0,0 @@
1
- import { Command } from 'commander';
2
-
3
- import { graphql } from '../graphql/client.ts';
4
- import { Me } from '../graphql/operations/common.ts';
5
- import { loadConfig, saveConfig } from '../lib/config.ts';
6
- import { error, hint, info, success } from '../lib/output.ts';
7
-
8
- interface CompanyChoice {
9
- id: string;
10
- name: string;
11
- slug: string;
12
- }
13
-
14
- async function fetchCompanies(endpoint?: string): Promise<CompanyChoice[]> {
15
- const data = await graphql(Me, undefined, { endpoint });
16
- return (data.me?.companies?.nodes ?? [])
17
- .filter((c): c is { id: string; name: string; slug: string } => c != null)
18
- .map((c) => ({ id: c.id, name: c.name ?? c.slug, slug: c.slug }));
19
- }
20
-
21
- export const switchCommand = new Command('switch')
22
- .summary("Switch which company you're working with")
23
- .description(
24
- "Switch which company you're working with\n\n" +
25
- 'Run without arguments to see all available companies.\n' +
26
- 'Pass a company slug to switch immediately.\n\n' +
27
- 'Examples:\n' +
28
- ' sl switch List your companies (active one is marked)\n' +
29
- " sl switch acme Switch to the 'acme' company",
30
- )
31
- .argument('[slug]', 'Company slug to switch to (omit to list)')
32
- .action(async function (this: Command, slug?: string) {
33
- const opts = this.optsWithGlobals();
34
- const config = loadConfig();
35
- const companies = await fetchCompanies(opts.endpoint);
36
-
37
- if (companies.length === 0) {
38
- error('No companies found for your account.');
39
- hint('Make sure your Sortlist account is linked to at least one company.');
40
- process.exit(1);
41
- }
42
-
43
- // No slug provided — list companies
44
- if (!slug) {
45
- for (const c of companies) {
46
- const marker = c.slug === config.companySlug ? ' ← active' : '';
47
- info(` ${c.slug} ${c.name}${marker}`);
48
- }
49
- return;
50
- }
51
-
52
- // Switch to the provided slug
53
- const selected = companies.find((c) => c.slug === slug);
54
- if (!selected) {
55
- error(`Company "${slug}" not found.`);
56
- info('');
57
- info(' Available companies:');
58
- for (const c of companies) {
59
- info(` ${c.slug} ${c.name}`);
60
- }
61
- hint('Run `sl switch <slug>` with one of the slugs above.');
62
- process.exit(1);
63
- }
64
-
65
- saveConfig({
66
- companyId: selected.id,
67
- companySlug: selected.slug,
68
- companyName: selected.name,
69
- });
70
-
71
- success(`Switched to ${selected.name} (${selected.slug})`);
72
- });