@sortlist/cli 0.53.0 → 0.54.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/README.md +20 -14
- package/dist/index.js +137 -36
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,34 +49,38 @@ The cause is a role assignment in the tenant you logged into, not a CLI setting:
|
|
|
49
49
|
|
|
50
50
|
## Acting as an application locally
|
|
51
51
|
|
|
52
|
-
`sl use application <
|
|
52
|
+
`sl use application <application>` creates a credential, exchanges it for a token, and **revokes the credential immediately**. Nothing reusable is stored: what lands in `~/.sortlist/` is a bearer token that expires, and a subgraph verifies it by signature against Hermes' published keys rather than by asking whether the credential still lives.
|
|
53
53
|
|
|
54
54
|
```bash
|
|
55
|
-
sl use application
|
|
56
|
-
sl
|
|
57
|
-
sl use
|
|
55
|
+
sl use application ci # by slug, in the company you act for (your personal one by default)
|
|
56
|
+
sl use application acme/ci # by slug, naming the company
|
|
57
|
+
sl use application <id> # by the application's id
|
|
58
|
+
sl whoami # confirms: person or application
|
|
59
|
+
sl use me # go back to acting as yourself
|
|
58
60
|
```
|
|
59
61
|
|
|
62
|
+
An application's slug is derived from its name when it is created (`Organization importer` → `organization-importer`) and stays the same if it is renamed. It is unique within its company, so two companies can each own a `ci`. `sl hermes applications` lists the applications of every company you belong to, with their slugs, and the developer portal shows both the slug and the id on the application's page.
|
|
63
|
+
|
|
60
64
|
When the token expires, renewing needs your own login again — so this is a local convenience, never a path to unattended use. For that, see below.
|
|
61
65
|
|
|
62
66
|
## Acting for a company
|
|
63
67
|
|
|
64
|
-
A person can belong to several companies, and a subgraph that counts usage — Atlas records which contact details it hands out — needs to know which one a call is for. Every authenticated request carries that company as an `X-Company-Id` header, taken from `--company` or from `sl config set company`. Both take the company's slug or its GraphQL `id`, as `sl companies` lists them; a slug costs one lookup per command, and a raw uuid is refused. The subgraph checks it against the companies your token lists and refuses the request outright when it names one you do not belong to. Without either, no company is named
|
|
68
|
+
A person can belong to several companies, and a subgraph that counts usage — Atlas records which contact details it hands out — needs to know which one a call is for. Every authenticated request carries that company as an `X-Company-Id` header, taken from `--company` or from `sl config set company`. Both take the company's slug or its GraphQL `id`, as `sl hermes companies` lists them; a slug costs one lookup per command, and a raw uuid is refused. The subgraph checks it against the companies your token lists and refuses the request outright when it names one you do not belong to. Without either, no company is named, and Atlas refuses any person who names none, staff included; the CLI then retries the call once for your personal company, so that is where it is counted. An application belongs to exactly one company, so acting as one needs no header.
|
|
65
69
|
|
|
66
70
|
```bash
|
|
67
|
-
sl config set company
|
|
68
|
-
sl atlas find-contacts --company
|
|
71
|
+
sl config set company acme # for every command from now on
|
|
72
|
+
sl atlas find-contacts --company acme … # for one call
|
|
69
73
|
```
|
|
70
74
|
|
|
71
75
|
## Revealing contact details
|
|
72
76
|
|
|
73
|
-
Finding a contact shows only the reach details your company already owns — a name, an email, a phone, a LinkedIn profile each come back empty until revealed — and Atlas says so beside every row. Revealing is explicit, in the same command, with `--reveal`: a comma-separated list of dimensions named after what they unlock (`contactIdentity`, `contactEmailAddress`, `contactPhoneNumber`, `contactLinkedinUrl`, and `organization…` for organizations).
|
|
77
|
+
Finding a contact shows only the reach details your company already owns — a name, an email, a phone, a LinkedIn profile each come back empty until revealed — and Atlas says so beside every row. Revealing is explicit, in the same command, with `--reveal`: a comma-separated list of dimensions named after what they unlock (`contactIdentity`, `contactEmailAddress`, `contactPhoneNumber`, `contactLinkedinUrl`, and `organization…` for organizations). Finding and revealing need no scope, only a company to act for: a reveal made while acting for none is refused with `FORBIDDEN_COMPANY`, and `sl` retries it once on your personal company. Each reveal is charged to the company's credits. When you name a company, Atlas checks with Hermes first: you must still be a member of it, or the application must belong to it, otherwise the whole command is refused with a 403 and nothing is recorded — the token's claim was stamped at login and can outlive a membership.
|
|
74
78
|
|
|
75
79
|
```bash
|
|
76
80
|
sl atlas find-contacts --page '{"first":5}' --wait \
|
|
77
|
-
--fields
|
|
81
|
+
--fields firstName,emailAddress # what you own
|
|
78
82
|
sl atlas find-contacts --page '{"first":5}' --wait --reveal contactIdentity,contactEmailAddress \
|
|
79
|
-
--fields
|
|
83
|
+
--fields firstName,emailAddress # reveal, once per window
|
|
80
84
|
```
|
|
81
85
|
|
|
82
86
|
The finds are searches: the mutation is acknowledged at once and the page arrives on a subscription, which `--wait` listens to. Atlas sends a page again as it fills it, and `--wait` prints its last, `COMPLETE`, version. Each edge's `reveals` says what happened to every dimension: `REVEALED` was recorded by this call, `OWNED` means the window is still running and nothing was counted again, `LOCKED` means Atlas has it and nobody asked, `UNAVAILABLE` means Atlas has nothing, and nothing is counted. The page's `credits` is the bill: `held` is the ceiling reserved before the page was read (rows × dimensions asked), `used` what it actually consumed, one unit per dimension revealed on one row. Nothing is charged yet — these are the figures that would be. Every list argument typed as an enum accepts the same comma-separated shorthand.
|
|
@@ -87,7 +91,7 @@ The finds are searches: the mutation is acknowledged at once and the page arrive
|
|
|
87
91
|
|
|
88
92
|
```bash
|
|
89
93
|
# Create a credential — the secret is in the response and shown only once
|
|
90
|
-
sl create-application-credential --application-id <id> --name continuous-integration
|
|
94
|
+
sl hermes create-application-credential --application-id <id> --name continuous-integration
|
|
91
95
|
|
|
92
96
|
export SORTLIST_CLIENT_ID=slc_...
|
|
93
97
|
export SORTLIST_CLIENT_SECRET=sl_live_...
|
|
@@ -97,7 +101,7 @@ With both set, **every** command authenticates as the application instead of as
|
|
|
97
101
|
|
|
98
102
|
The secret is shown exactly once, because only its digest is stored. Revoking stops new tokens immediately; a token already issued stays valid until it expires.
|
|
99
103
|
|
|
100
|
-
A credential
|
|
104
|
+
A credential's token carries **no scope**. It reaches what a plain login does: Atlas's `find-contacts` and `find-organizations`, whose reveals are charged to the application's company, Mercator's geography and the billing plan catalog. The unmetered `contacts` and `organizations` lists, Signals operations and every staff read stay out of reach. Hermes' own management API is **not** part of what a credential reaches: Hermes refuses the tokens it mints, which is what stops a leaked secret from minting more. The derivation is in `backend/hermes/docs/api.md` in the platform monorepo, under "What a minted token reaches".
|
|
101
105
|
|
|
102
106
|
The token endpoint is a different host from the federation endpoint, so it cannot be derived. `sl config use-production` / `use-staging` / `use-local` set both together; `sl config set tokenEndpoint <url>` sets it on its own.
|
|
103
107
|
|
|
@@ -105,7 +109,7 @@ The token endpoint is a different host from the federation endpoint, so it canno
|
|
|
105
109
|
|
|
106
110
|
The CLI offers an operation only when its subgraph tags the root field for it, with `@tag(name: "cli")` (`tags: [{ name: "cli" }]` on the Ruby field). Every other query, mutation and subscription stays reachable through the API, but has no command. Exposing one more is a backend change: tag the field, and the command appears within the hour, with no CLI release.
|
|
107
111
|
|
|
108
|
-
Commands are discovered at runtime through introspection and grouped under the subgraph that serves them
|
|
112
|
+
Commands are discovered at runtime through introspection and grouped under the subgraph that serves them, Hermes's account and company operations included: `sl hermes companies`, `sl hermes applications`, `sl hermes create-application`. Every Hermes operation a person can call is offered. The names they had at the top level before (`sl companies`, `sl create-application-credential`) still work, but are no longer listed.
|
|
109
113
|
|
|
110
114
|
```bash
|
|
111
115
|
sl operations # list them all, grouped by queries, mutations and subscriptions
|
|
@@ -113,8 +117,10 @@ sl operations --search organization # filter by operation or subgraph name
|
|
|
113
117
|
sl <service> <operation> --help # flags for one operation
|
|
114
118
|
```
|
|
115
119
|
|
|
120
|
+
An operation whose subgraph declares a scope for it (`@requiresScopes`) is listed as `privileged: <scopes>`, and its `--help` opens with the same line. Everything else works with a plain login. The router hides a privileged operation from a token that lacks the scope, so it may be missing from the list rather than marked.
|
|
121
|
+
|
|
116
122
|
```bash
|
|
117
|
-
sl companies
|
|
123
|
+
sl hermes companies
|
|
118
124
|
sl atlas find-organizations --help
|
|
119
125
|
sl mercator resolve-locations --query brussels
|
|
120
126
|
```
|
package/dist/index.js
CHANGED
|
@@ -447,7 +447,7 @@ async function lookupCompanyId(slug) {
|
|
|
447
447
|
const id = data.company?.id;
|
|
448
448
|
if (typeof id === "string") return id;
|
|
449
449
|
error(`No company with slug "${slug}" among yours.`);
|
|
450
|
-
hint("`sl companies` lists the companies you belong to, with their slugs and ids.");
|
|
450
|
+
hint("`sl hermes companies` lists the companies you belong to, with their slugs and ids.");
|
|
451
451
|
process.exit(2);
|
|
452
452
|
}
|
|
453
453
|
async function resolveCompanyId(opts) {
|
|
@@ -701,6 +701,7 @@ function codeOf(errors) {
|
|
|
701
701
|
}
|
|
702
702
|
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
703
703
|
var CALLBACK_STATUS_NOT_OK = "SUBGRAPH_HTTP_CALLBACK_STATUS_CODE_NOT_OK";
|
|
704
|
+
var FORBIDDEN_COMPANY = "FORBIDDEN_COMPANY";
|
|
704
705
|
function subrequestStatus(errors) {
|
|
705
706
|
for (const { message, extensions } of errors) {
|
|
706
707
|
const http = extensions?.http;
|
|
@@ -780,7 +781,7 @@ function refusedForNamingNoCompany(errors, namedNoCompany) {
|
|
|
780
781
|
if (!namedNoCompany) return false;
|
|
781
782
|
const status = subrequestStatus(errors);
|
|
782
783
|
const maskedCallbackRefusal = status === null && codeOf(errors) === CALLBACK_STATUS_NOT_OK;
|
|
783
|
-
return status === 403 || maskedCallbackRefusal;
|
|
784
|
+
return status === 403 || maskedCallbackRefusal || codeOf(errors) === FORBIDDEN_COMPANY;
|
|
784
785
|
}
|
|
785
786
|
function hasResolvedField(data) {
|
|
786
787
|
if (data === null || data === void 0) return false;
|
|
@@ -832,10 +833,10 @@ function reportGraphqlErrors(errors, options, attempt) {
|
|
|
832
833
|
error(`${where} refused to act for your personal company.`);
|
|
833
834
|
hint("It was tried because the request named no company, and your token does not list it as yours.");
|
|
834
835
|
hint("On a local stack the token comes from a shared tenant and lists that environment's companies.");
|
|
835
|
-
hint("Pass --company <slug|id>, or `sl config set company <slug|id>`; `sl companies` lists them.");
|
|
836
|
+
hint("Pass --company <slug|id>, or `sl config set company <slug|id>`; `sl hermes companies` lists them.");
|
|
836
837
|
} else if (company && UUID.test(company)) {
|
|
837
838
|
error(`${where} refused ${company}: that is a raw uuid, not a company id.`);
|
|
838
|
-
hint("Pass its slug, or the id `sl companies` lists.");
|
|
839
|
+
hint("Pass its slug, or the id `sl hermes companies` lists.");
|
|
839
840
|
} else if (company) {
|
|
840
841
|
error(`${where} refused to act for company ${company}.`);
|
|
841
842
|
hint("Your token does not list that company, or Hermes no longer knows you as one of its members.");
|
|
@@ -844,7 +845,7 @@ function reportGraphqlErrors(errors, options, attempt) {
|
|
|
844
845
|
} else {
|
|
845
846
|
error(`${where} refused this request: it names no company to act for.`);
|
|
846
847
|
hint("Pick one of your companies with --company or `sl config set company <slug|id>`;");
|
|
847
|
-
hint("`sl companies` lists them. Join one first if the list is empty.");
|
|
848
|
+
hint("`sl hermes companies` lists them. Join one first if the list is empty.");
|
|
848
849
|
}
|
|
849
850
|
if (verbose) for (const gqlError of errors) info(`[debug] ${JSON.stringify(gqlError)}`);
|
|
850
851
|
process.exit(4);
|
|
@@ -2061,21 +2062,19 @@ function deriveServiceMap(schema, fieldServices) {
|
|
|
2061
2062
|
}
|
|
2062
2063
|
return map;
|
|
2063
2064
|
}
|
|
2064
|
-
|
|
2065
|
+
function describeScopes(scopes) {
|
|
2066
|
+
return scopes.map((alternative) => alternative.join(" + ")).join(" or ");
|
|
2067
|
+
}
|
|
2068
|
+
var LEGACY_TOP_LEVEL_SERVICE = "hermes";
|
|
2065
2069
|
function invocation(service, commandName) {
|
|
2066
|
-
return
|
|
2070
|
+
return `${service} ${commandName}`;
|
|
2067
2071
|
}
|
|
2068
2072
|
function invocationOf(operation) {
|
|
2069
2073
|
return invocation(operation.service, operation.command.name());
|
|
2070
2074
|
}
|
|
2071
2075
|
function groupOperationCommands(operations) {
|
|
2072
|
-
const topLevel = [];
|
|
2073
2076
|
const services = /* @__PURE__ */ new Map();
|
|
2074
2077
|
for (const operation of operations) {
|
|
2075
|
-
if (operation.service === TOP_LEVEL_SERVICE) {
|
|
2076
|
-
topLevel.push(operation.command);
|
|
2077
|
-
continue;
|
|
2078
|
-
}
|
|
2079
2078
|
let group = services.get(operation.service);
|
|
2080
2079
|
if (!group) {
|
|
2081
2080
|
group = new Command2(operation.service).description(`Operations served by ${operation.service}`);
|
|
@@ -2083,13 +2082,18 @@ function groupOperationCommands(operations) {
|
|
|
2083
2082
|
}
|
|
2084
2083
|
group.addCommand(operation.command);
|
|
2085
2084
|
}
|
|
2086
|
-
return
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2085
|
+
return [...services.values()].sort((a, b) => a.name().localeCompare(b.name()));
|
|
2086
|
+
}
|
|
2087
|
+
function legacyTopLevelCommands(schema, fieldServices, fieldScopes = /* @__PURE__ */ new Map()) {
|
|
2088
|
+
return buildOperationCommands(schema, fieldServices, fieldScopes).filter((operation) => operation.service === LEGACY_TOP_LEVEL_SERVICE).map((operation) => operation.command);
|
|
2090
2089
|
}
|
|
2091
|
-
function buildOperationCommands(schema, fieldServices) {
|
|
2090
|
+
function buildOperationCommands(schema, fieldServices, fieldScopes = /* @__PURE__ */ new Map()) {
|
|
2092
2091
|
const serviceMap = deriveServiceMap(schema, fieldServices);
|
|
2092
|
+
const rootTypeNames = {
|
|
2093
|
+
query: schema.getQueryType()?.name,
|
|
2094
|
+
mutation: schema.getMutationType()?.name,
|
|
2095
|
+
subscription: schema.getSubscriptionType()?.name
|
|
2096
|
+
};
|
|
2093
2097
|
const pairs = resultSubscriptions(schema);
|
|
2094
2098
|
const operations = [];
|
|
2095
2099
|
for (const [service, entry] of serviceMap) {
|
|
@@ -2112,7 +2116,14 @@ function buildOperationCommands(schema, fieldServices) {
|
|
|
2112
2116
|
if ((nameCounts.get(op.fieldName) ?? 0) > 1) {
|
|
2113
2117
|
command.name(`${kebab(op.fieldName)}-${kind}`);
|
|
2114
2118
|
}
|
|
2115
|
-
|
|
2119
|
+
const rootTypeName = rootTypeNames[kind];
|
|
2120
|
+
const scopes = rootTypeName ? fieldScopes.get(rootTypeName)?.get(op.fieldName) : void 0;
|
|
2121
|
+
if (scopes) {
|
|
2122
|
+
command.description(`Privileged: requires ${describeScopes(scopes)}.
|
|
2123
|
+
|
|
2124
|
+
${command.description()}`);
|
|
2125
|
+
}
|
|
2126
|
+
operations.push({ command, fieldName: op.fieldName, kind, service, ...scopes ? { scopes } : {} });
|
|
2116
2127
|
} catch {
|
|
2117
2128
|
}
|
|
2118
2129
|
}
|
|
@@ -2135,12 +2146,17 @@ function formatOperationList(operations, search) {
|
|
|
2135
2146
|
for (const kind of ["query", "mutation", "subscription"]) {
|
|
2136
2147
|
const group = matching.filter((op) => op.kind === kind);
|
|
2137
2148
|
if (group.length === 0) continue;
|
|
2138
|
-
const rows = group.map((op) => ({
|
|
2149
|
+
const rows = group.map((op) => ({
|
|
2150
|
+
invocation: invocationOf(op),
|
|
2151
|
+
service: op.service,
|
|
2152
|
+
privilege: op.scopes ? `privileged: ${describeScopes(op.scopes)}` : ""
|
|
2153
|
+
}));
|
|
2139
2154
|
rows.sort((a, b) => a.invocation.localeCompare(b.invocation));
|
|
2140
2155
|
const width = Math.max(...rows.map((row) => row.invocation.length));
|
|
2156
|
+
const serviceWidth = Math.max(...rows.map((row) => row.service.length));
|
|
2141
2157
|
lines.push(`${headings[kind]}:`);
|
|
2142
2158
|
for (const row of rows) {
|
|
2143
|
-
lines.push(` ${row.invocation.padEnd(width)} ${row.service}
|
|
2159
|
+
lines.push(` ${row.invocation.padEnd(width)} ${row.service.padEnd(serviceWidth)} ${row.privilege}`.trimEnd());
|
|
2144
2160
|
}
|
|
2145
2161
|
lines.push("");
|
|
2146
2162
|
}
|
|
@@ -2402,6 +2418,49 @@ Examples:
|
|
|
2402
2418
|
|
|
2403
2419
|
// src/commands/use.ts
|
|
2404
2420
|
import { Command as Command6 } from "commander";
|
|
2421
|
+
|
|
2422
|
+
// src/lib/application.ts
|
|
2423
|
+
function isApplicationId(value) {
|
|
2424
|
+
try {
|
|
2425
|
+
return Buffer.from(value, "base64url").toString("utf8").startsWith("Application/");
|
|
2426
|
+
} catch {
|
|
2427
|
+
return false;
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2430
|
+
function parseApplicationReference(value) {
|
|
2431
|
+
const separator = value.indexOf("/");
|
|
2432
|
+
if (separator === -1) return { company: void 0, slug: value };
|
|
2433
|
+
return { company: value.slice(0, separator), slug: value.slice(separator + 1) };
|
|
2434
|
+
}
|
|
2435
|
+
var APPLICATION_BY_SLUG = `
|
|
2436
|
+
query ApplicationBySlug($slug: String!) {
|
|
2437
|
+
me {
|
|
2438
|
+
companies(first: 50) {
|
|
2439
|
+
nodes { id slug personal application(slug: $slug) { id } }
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
`;
|
|
2444
|
+
function pickApplication(data, company) {
|
|
2445
|
+
const me = data.me;
|
|
2446
|
+
const companies = me?.companies?.nodes ?? [];
|
|
2447
|
+
const match = companies.find((candidate) => {
|
|
2448
|
+
if (company === void 0) return candidate.personal === true;
|
|
2449
|
+
return isCompanyId(company) ? candidate.id === company : candidate.slug === company;
|
|
2450
|
+
});
|
|
2451
|
+
return { company: match ?? null, applicationId: match?.application?.id };
|
|
2452
|
+
}
|
|
2453
|
+
async function lookupApplicationId(reference, opts) {
|
|
2454
|
+
const company = reference.company ?? opts.company ?? opts.ctx?.company;
|
|
2455
|
+
const data = await graphqlRaw(
|
|
2456
|
+
APPLICATION_BY_SLUG,
|
|
2457
|
+
{ slug: reference.slug },
|
|
2458
|
+
{ endpoint: opts.endpoint, throwOnError: true, asPerson: true, withoutCompany: true }
|
|
2459
|
+
);
|
|
2460
|
+
return pickApplication(data, company);
|
|
2461
|
+
}
|
|
2462
|
+
|
|
2463
|
+
// src/commands/use.ts
|
|
2405
2464
|
var CREATE = `
|
|
2406
2465
|
mutation UseApplication($applicationId: ID!, $name: String!) {
|
|
2407
2466
|
createApplicationCredential(input: { applicationId: $applicationId, name: $name, session: true }) {
|
|
@@ -2411,16 +2470,20 @@ var CREATE = `
|
|
|
2411
2470
|
}
|
|
2412
2471
|
}
|
|
2413
2472
|
`;
|
|
2473
|
+
var APPLICATIONS_HINT = "`sl hermes applications` lists the applications you can act as, with their slugs.";
|
|
2414
2474
|
var REVOKE = `
|
|
2415
2475
|
mutation ReleaseSessionCredential($credentialId: ID!) {
|
|
2416
2476
|
revokeApplicationCredential(input: { credentialId: $credentialId }) { revokedAt }
|
|
2417
2477
|
}
|
|
2418
2478
|
`;
|
|
2419
2479
|
var useCommand = new Command6("use").summary("Act as an application, or go back to acting as yourself").description(
|
|
2420
|
-
"Act as an application, or go back to acting as yourself\n\nExamples:\n sl use application
|
|
2480
|
+
"Act as an application, or go back to acting as yourself\n\nExamples:\n sl use application testapp Act as your application testapp for one token lifetime\n sl use application acme/testapp The same, naming the company it belongs to\n sl use application <id> The same, by the application's id\n sl use me Go back to acting as yourself"
|
|
2421
2481
|
);
|
|
2422
|
-
useCommand.command("application <
|
|
2482
|
+
useCommand.command("application <application>").description(
|
|
2483
|
+
"Act as an application for one token lifetime. Name it by slug, which is looked up in the company you act for, by <company>/<slug>, or by its id"
|
|
2484
|
+
).action(async function(reference) {
|
|
2423
2485
|
const opts = this.optsWithGlobals();
|
|
2486
|
+
const id = await applicationIdFor(reference, opts);
|
|
2424
2487
|
const asPerson = { endpoint: opts.endpoint, throwOnError: true, asPerson: true };
|
|
2425
2488
|
let credential = null;
|
|
2426
2489
|
try {
|
|
@@ -2428,12 +2491,12 @@ useCommand.command("application <id>").description("Act as an application for on
|
|
|
2428
2491
|
credential = issued.createApplicationCredential;
|
|
2429
2492
|
} catch (err) {
|
|
2430
2493
|
error(`Could not create a session credential: ${err.message}`);
|
|
2431
|
-
hint(
|
|
2494
|
+
hint(APPLICATIONS_HINT);
|
|
2432
2495
|
process.exit(1);
|
|
2433
2496
|
}
|
|
2434
2497
|
if (!credential) {
|
|
2435
2498
|
error("The server did not return a session credential.");
|
|
2436
|
-
hint(
|
|
2499
|
+
hint(APPLICATIONS_HINT);
|
|
2437
2500
|
process.exit(1);
|
|
2438
2501
|
}
|
|
2439
2502
|
let accessToken = null;
|
|
@@ -2475,6 +2538,29 @@ useCommand.command("me").description("Go back to acting as yourself").action(()
|
|
|
2475
2538
|
function sessionName() {
|
|
2476
2539
|
return `cli-session-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 19).replace(/[:T]/g, "")}`;
|
|
2477
2540
|
}
|
|
2541
|
+
async function applicationIdFor(reference, opts) {
|
|
2542
|
+
if (isApplicationId(reference)) return reference;
|
|
2543
|
+
const named = parseApplicationReference(reference);
|
|
2544
|
+
let found;
|
|
2545
|
+
try {
|
|
2546
|
+
found = await lookupApplicationId(named, { company: opts.company, ctx: getUserContext(), endpoint: opts.endpoint });
|
|
2547
|
+
} catch (err) {
|
|
2548
|
+
error(`Could not look up the application "${reference}": ${err.message}`);
|
|
2549
|
+
process.exit(1);
|
|
2550
|
+
}
|
|
2551
|
+
if (found.applicationId) return found.applicationId;
|
|
2552
|
+
if (found.company === null) {
|
|
2553
|
+
const company = named.company ?? opts.company ?? getUserContext().company;
|
|
2554
|
+
error(
|
|
2555
|
+
company ? `You do not belong to a company "${company}".` : "You have no personal company to look the application up in."
|
|
2556
|
+
);
|
|
2557
|
+
hint("`sl hermes companies` lists the companies you belong to, with their slugs.");
|
|
2558
|
+
} else {
|
|
2559
|
+
error(`No application "${named.slug}" in ${found.company.slug ?? "that company"}.`);
|
|
2560
|
+
hint(APPLICATIONS_HINT);
|
|
2561
|
+
}
|
|
2562
|
+
process.exit(2);
|
|
2563
|
+
}
|
|
2478
2564
|
|
|
2479
2565
|
// src/commands/whoami.ts
|
|
2480
2566
|
import { Command as Command7 } from "commander";
|
|
@@ -2655,12 +2741,20 @@ function isTaggedForCli(field) {
|
|
|
2655
2741
|
(d) => d.name === "tag" && d.args.some((a) => a.name === "name" && a.value === CLI_TAG)
|
|
2656
2742
|
) ?? false;
|
|
2657
2743
|
}
|
|
2744
|
+
function requiredScopes(field) {
|
|
2745
|
+
const value = field.appliedDirectives?.find((directive) => directive.name === "requiresScopes")?.args.find((arg) => arg.name === "scopes")?.value;
|
|
2746
|
+
const parsed = typeof value === "string" ? JSON.parse(value) : value;
|
|
2747
|
+
if (!Array.isArray(parsed)) return void 0;
|
|
2748
|
+
return parsed.filter(Array.isArray).map((alternative) => alternative.map(String));
|
|
2749
|
+
}
|
|
2658
2750
|
function parseIntrospection(raw) {
|
|
2659
2751
|
const fieldServices = /* @__PURE__ */ new Map();
|
|
2752
|
+
const fieldScopes = /* @__PURE__ */ new Map();
|
|
2660
2753
|
const services = /* @__PURE__ */ new Set();
|
|
2661
2754
|
for (const type of raw.__schema.types ?? []) {
|
|
2662
2755
|
if (!type.fields?.length) continue;
|
|
2663
2756
|
let fieldMap = null;
|
|
2757
|
+
let scopeMap = null;
|
|
2664
2758
|
for (const field of type.fields) {
|
|
2665
2759
|
const directive = field.appliedDirectives?.find((d) => d.name === "join__field");
|
|
2666
2760
|
if (!directive) continue;
|
|
@@ -2670,10 +2764,16 @@ function parseIntrospection(raw) {
|
|
|
2670
2764
|
if (!isTaggedForCli(field)) continue;
|
|
2671
2765
|
fieldMap ??= /* @__PURE__ */ new Map();
|
|
2672
2766
|
fieldMap.set(field.name, graphArg.value);
|
|
2767
|
+
const scopes = requiredScopes(field);
|
|
2768
|
+
if (scopes?.length) {
|
|
2769
|
+
scopeMap ??= /* @__PURE__ */ new Map();
|
|
2770
|
+
scopeMap.set(field.name, scopes);
|
|
2771
|
+
}
|
|
2673
2772
|
}
|
|
2674
2773
|
if (fieldMap) fieldServices.set(type.name, fieldMap);
|
|
2774
|
+
if (scopeMap) fieldScopes.set(type.name, scopeMap);
|
|
2675
2775
|
}
|
|
2676
|
-
return { fieldServices, services };
|
|
2776
|
+
return { fieldServices, fieldScopes, services };
|
|
2677
2777
|
}
|
|
2678
2778
|
async function currentAccessToken() {
|
|
2679
2779
|
const machine = clientCredentials();
|
|
@@ -2706,8 +2806,8 @@ async function getIntrospectedSchema(endpointOverride2) {
|
|
|
2706
2806
|
}
|
|
2707
2807
|
function build(introspection, raw) {
|
|
2708
2808
|
try {
|
|
2709
|
-
const { fieldServices, services } = parseIntrospection(raw);
|
|
2710
|
-
return { schema: buildClientSchema(introspection), fieldServices, services };
|
|
2809
|
+
const { fieldServices, fieldScopes, services } = parseIntrospection(raw);
|
|
2810
|
+
return { schema: buildClientSchema(introspection), fieldServices, fieldScopes, services };
|
|
2711
2811
|
} catch {
|
|
2712
2812
|
return null;
|
|
2713
2813
|
}
|
|
@@ -2834,12 +2934,14 @@ function buildRootDescription(operationCount) {
|
|
|
2834
2934
|
if (operationCount > 0) {
|
|
2835
2935
|
parts.push(
|
|
2836
2936
|
`Every federation operation exposed to the CLI is a command (${operationCount} available),
|
|
2837
|
-
grouped under the service that serves it
|
|
2937
|
+
grouped under the service that serves it, Hermes's account and company operations included:
|
|
2838
2938
|
sl operations List them all
|
|
2839
2939
|
sl operations --search organization
|
|
2840
2940
|
sl <service> <operation> --help Flags for one operation`
|
|
2841
2941
|
);
|
|
2842
|
-
parts.push(
|
|
2942
|
+
parts.push(
|
|
2943
|
+
"Examples:\n sl hermes companies\n sl atlas find-organizations --help\n sl config show"
|
|
2944
|
+
);
|
|
2843
2945
|
}
|
|
2844
2946
|
return parts.join("\n\n");
|
|
2845
2947
|
}
|
|
@@ -2887,15 +2989,14 @@ program.addCommand(schemaCommand);
|
|
|
2887
2989
|
var endpointIdx = process.argv.indexOf("--endpoint");
|
|
2888
2990
|
var endpointOverride = endpointIdx !== -1 ? process.argv[endpointIdx + 1] : void 0;
|
|
2889
2991
|
try {
|
|
2890
|
-
const { schema, fieldServices } = await getIntrospectedSchema(endpointOverride);
|
|
2891
|
-
const operations = buildOperationCommands(schema, fieldServices);
|
|
2892
|
-
const
|
|
2893
|
-
for (const command of topLevel) {
|
|
2894
|
-
program.addCommand(command, { hidden: true });
|
|
2895
|
-
}
|
|
2896
|
-
for (const command of services) {
|
|
2992
|
+
const { schema, fieldServices, fieldScopes } = await getIntrospectedSchema(endpointOverride);
|
|
2993
|
+
const operations = buildOperationCommands(schema, fieldServices, fieldScopes);
|
|
2994
|
+
for (const command of groupOperationCommands(operations)) {
|
|
2897
2995
|
program.addCommand(command);
|
|
2898
2996
|
}
|
|
2997
|
+
for (const command of legacyTopLevelCommands(schema, fieldServices, fieldScopes)) {
|
|
2998
|
+
program.addCommand(command, { hidden: true });
|
|
2999
|
+
}
|
|
2899
3000
|
const operationsCommand = new Command8("operations").summary("List every federation operation available as a command").option("--search <text>", "Filter by operation or subgraph name").action(function() {
|
|
2900
3001
|
info(formatOperationList(operations, this.opts().search));
|
|
2901
3002
|
});
|