@sortlist/cli 0.36.0 → 0.37.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/bin/sl.mjs +20 -7
- package/dist/index.js +1579 -0
- package/dist/index.js.map +1 -0
- package/package.json +8 -7
- package/src/codegen.ts +0 -34
- package/src/commands/config.ts +0 -95
- package/src/commands/dynamic.test.ts +0 -87
- package/src/commands/dynamic.ts +0 -569
- package/src/commands/login.ts +0 -155
- package/src/commands/logout.ts +0 -45
- package/src/commands/token.ts +0 -23
- package/src/commands/whoami.ts +0 -55
- package/src/graphql/client.ts +0 -259
- package/src/graphql/generated/gql.ts +0 -70
- package/src/graphql/generated/graphql.ts +0 -4757
- package/src/graphql/generated/index.ts +0 -1
- package/src/graphql/introspection.ts +0 -240
- package/src/graphql/operations/common.ts +0 -16
- package/src/graphql/operations/hermes.ts +0 -54
- package/src/graphql/query-builder.test.ts +0 -114
- package/src/graphql/query-builder.ts +0 -239
- package/src/index.ts +0 -186
- package/src/lib/auth.test.ts +0 -30
- package/src/lib/auth.ts +0 -58
- package/src/lib/browser.ts +0 -11
- package/src/lib/company.ts +0 -15
- package/src/lib/config.ts +0 -80
- package/src/lib/env.ts +0 -10
- package/src/lib/output.ts +0 -58
- package/src/lib/sentry.ts +0 -70
- package/src/lib/version-check.ts +0 -88
package/dist/index.js
ADDED
|
@@ -0,0 +1,1579 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { Command as Command7 } from "commander";
|
|
3
|
+
|
|
4
|
+
// src/commands/config.ts
|
|
5
|
+
import { Command } from "commander";
|
|
6
|
+
|
|
7
|
+
// src/lib/auth.ts
|
|
8
|
+
import fs from "fs";
|
|
9
|
+
import os from "os";
|
|
10
|
+
import path from "path";
|
|
11
|
+
|
|
12
|
+
// src/lib/output.ts
|
|
13
|
+
function colorEnabled() {
|
|
14
|
+
return process.stderr.isTTY === true && !process.env.NO_COLOR;
|
|
15
|
+
}
|
|
16
|
+
var ansi = {
|
|
17
|
+
reset: "\x1B[0m",
|
|
18
|
+
dim: "\x1B[2m",
|
|
19
|
+
red: "\x1B[31m",
|
|
20
|
+
green: "\x1B[32m",
|
|
21
|
+
yellow: "\x1B[33m"
|
|
22
|
+
};
|
|
23
|
+
function c(code, text) {
|
|
24
|
+
if (!colorEnabled()) return text;
|
|
25
|
+
return `${ansi[code]}${text}${ansi.reset}`;
|
|
26
|
+
}
|
|
27
|
+
function isJsonMode(options) {
|
|
28
|
+
if (options.json) return true;
|
|
29
|
+
return !process.stdout.isTTY;
|
|
30
|
+
}
|
|
31
|
+
function printJson(data) {
|
|
32
|
+
process.stdout.write(JSON.stringify(data, null, 2) + "\n");
|
|
33
|
+
}
|
|
34
|
+
function info(msg) {
|
|
35
|
+
process.stderr.write(`${msg}
|
|
36
|
+
`);
|
|
37
|
+
}
|
|
38
|
+
function success(msg) {
|
|
39
|
+
process.stderr.write(`${c("green", "\u2713")} ${msg}
|
|
40
|
+
`);
|
|
41
|
+
}
|
|
42
|
+
function warn(msg) {
|
|
43
|
+
process.stderr.write(`${c("yellow", "\u26A0")} ${msg}
|
|
44
|
+
`);
|
|
45
|
+
}
|
|
46
|
+
function error(msg) {
|
|
47
|
+
process.stderr.write(`${c("red", "\u2717")} Error: ${msg}
|
|
48
|
+
`);
|
|
49
|
+
}
|
|
50
|
+
function hint(msg) {
|
|
51
|
+
process.stderr.write(`${c("dim", " " + msg)}
|
|
52
|
+
`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/lib/auth.ts
|
|
56
|
+
var CREDENTIALS_PATH = path.join(os.homedir(), ".sortlist", "credentials.json");
|
|
57
|
+
function ensureDir() {
|
|
58
|
+
const dir = path.dirname(CREDENTIALS_PATH);
|
|
59
|
+
if (!fs.existsSync(dir)) {
|
|
60
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function saveCredentials(creds) {
|
|
64
|
+
ensureDir();
|
|
65
|
+
fs.writeFileSync(CREDENTIALS_PATH, JSON.stringify(creds, null, 2) + "\n", { mode: 384 });
|
|
66
|
+
}
|
|
67
|
+
function loadCredentials() {
|
|
68
|
+
try {
|
|
69
|
+
const raw = fs.readFileSync(CREDENTIALS_PATH, "utf-8");
|
|
70
|
+
return JSON.parse(raw);
|
|
71
|
+
} catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function clearCredentials() {
|
|
76
|
+
try {
|
|
77
|
+
fs.unlinkSync(CREDENTIALS_PATH);
|
|
78
|
+
} catch {
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function isExpired(creds) {
|
|
82
|
+
return Date.now() >= (creds.expiresAt - 60) * 1e3;
|
|
83
|
+
}
|
|
84
|
+
function ensureAuthenticated() {
|
|
85
|
+
const creds = loadCredentials();
|
|
86
|
+
if (!creds) {
|
|
87
|
+
error("You are not logged in.");
|
|
88
|
+
hint("Run `sl login` to authenticate with your Sortlist account.");
|
|
89
|
+
process.exit(2);
|
|
90
|
+
}
|
|
91
|
+
return creds;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// src/lib/config.ts
|
|
95
|
+
import fs2 from "fs";
|
|
96
|
+
import os2 from "os";
|
|
97
|
+
import path2 from "path";
|
|
98
|
+
var SORTLIST_DIR = path2.join(os2.homedir(), ".sortlist");
|
|
99
|
+
var CONFIG_PATH = path2.join(SORTLIST_DIR, "config.json");
|
|
100
|
+
var DEFAULT_CONFIG = {
|
|
101
|
+
endpoint: "https://federation.sortlist.com/graphql"
|
|
102
|
+
};
|
|
103
|
+
function ensureDir2() {
|
|
104
|
+
if (!fs2.existsSync(SORTLIST_DIR)) {
|
|
105
|
+
fs2.mkdirSync(SORTLIST_DIR, { recursive: true });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function loadConfig() {
|
|
109
|
+
try {
|
|
110
|
+
const raw = fs2.readFileSync(CONFIG_PATH, "utf-8");
|
|
111
|
+
return { ...DEFAULT_CONFIG, ...JSON.parse(raw) };
|
|
112
|
+
} catch {
|
|
113
|
+
return { ...DEFAULT_CONFIG };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function saveConfig(config) {
|
|
117
|
+
ensureDir2();
|
|
118
|
+
const current = loadConfig();
|
|
119
|
+
const merged = { ...current, ...config };
|
|
120
|
+
fs2.writeFileSync(CONFIG_PATH, JSON.stringify(merged, null, 2) + "\n");
|
|
121
|
+
}
|
|
122
|
+
function resetConfig() {
|
|
123
|
+
try {
|
|
124
|
+
fs2.unlinkSync(CONFIG_PATH);
|
|
125
|
+
} catch {
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function clearIdentity() {
|
|
129
|
+
const { endpoint } = loadConfig();
|
|
130
|
+
ensureDir2();
|
|
131
|
+
fs2.writeFileSync(CONFIG_PATH, JSON.stringify({ endpoint }, null, 2) + "\n");
|
|
132
|
+
}
|
|
133
|
+
function getEndpoint(override) {
|
|
134
|
+
if (override) return override;
|
|
135
|
+
if (process.env.SL_ENDPOINT) return process.env.SL_ENDPOINT;
|
|
136
|
+
return loadConfig().endpoint;
|
|
137
|
+
}
|
|
138
|
+
function getUserContext() {
|
|
139
|
+
const config = loadConfig();
|
|
140
|
+
return {
|
|
141
|
+
oauthId: config.oauthId,
|
|
142
|
+
companyId: config.companyId
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// src/lib/env.ts
|
|
147
|
+
import fs4 from "fs";
|
|
148
|
+
import path4 from "path";
|
|
149
|
+
|
|
150
|
+
// src/lib/package-root.ts
|
|
151
|
+
import fs3 from "fs";
|
|
152
|
+
import path3 from "path";
|
|
153
|
+
import { fileURLToPath } from "url";
|
|
154
|
+
function findPackageRoot() {
|
|
155
|
+
let dir = path3.dirname(fileURLToPath(import.meta.url));
|
|
156
|
+
while (true) {
|
|
157
|
+
const pkgPath = path3.join(dir, "package.json");
|
|
158
|
+
if (fs3.existsSync(pkgPath)) {
|
|
159
|
+
try {
|
|
160
|
+
const parsed = JSON.parse(fs3.readFileSync(pkgPath, "utf-8"));
|
|
161
|
+
if (parsed.name === "@sortlist/cli") return dir;
|
|
162
|
+
} catch {
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const parent = path3.dirname(dir);
|
|
166
|
+
if (parent === dir) throw new Error("Could not locate the @sortlist/cli package root");
|
|
167
|
+
dir = parent;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
var packageRoot = findPackageRoot();
|
|
171
|
+
var pkg = JSON.parse(fs3.readFileSync(path3.join(packageRoot, "package.json"), "utf-8"));
|
|
172
|
+
|
|
173
|
+
// src/lib/env.ts
|
|
174
|
+
var isLocalDev = !fs4.existsSync(path4.join(packageRoot, ".published"));
|
|
175
|
+
|
|
176
|
+
// src/commands/config.ts
|
|
177
|
+
var PRODUCTION_ENDPOINT = "https://federation.sortlist.com/graphql";
|
|
178
|
+
var STAGING_ENDPOINT = "https://federation.sortlist-test.com/graphql";
|
|
179
|
+
var LOCAL_ENDPOINT = "http://localhost:4020/graphql";
|
|
180
|
+
var configCommand = new Command("config").summary("View or update CLI configuration").description(
|
|
181
|
+
"View or update CLI configuration\n\nManage your company context and credentials.\n\nExamples:\n sl config show See current endpoint and company\n" + (isLocalDev ? " sl config set endpoint <url> Point to a custom endpoint\n" : "") + " sl config reset Clear all config and credentials"
|
|
182
|
+
);
|
|
183
|
+
configCommand.command("show").description("Show current configuration").action(function() {
|
|
184
|
+
const opts = this.optsWithGlobals();
|
|
185
|
+
const config = loadConfig();
|
|
186
|
+
if (isJsonMode(opts)) {
|
|
187
|
+
printJson(config);
|
|
188
|
+
} else {
|
|
189
|
+
info(`Endpoint: ${config.endpoint}`);
|
|
190
|
+
if (config.oauthId) info(`User: ${config.oauthId}`);
|
|
191
|
+
if (config.companyId) info(`Company ID: ${config.companyId}`);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
configCommand.command("set <key> <value>").description(`Set a config value (${isLocalDev ? "endpoint, " : ""}companyId)`).action((key, value) => {
|
|
195
|
+
const allowed = [...isLocalDev ? ["endpoint"] : [], "companyId", "oauthId"];
|
|
196
|
+
if (!allowed.includes(key)) {
|
|
197
|
+
error(`Unknown config key: "${key}".`);
|
|
198
|
+
info("");
|
|
199
|
+
info(" Allowed keys:");
|
|
200
|
+
for (const k of allowed) {
|
|
201
|
+
info(` ${k}`);
|
|
202
|
+
}
|
|
203
|
+
hint("Usage: sl config set <key> <value>");
|
|
204
|
+
process.exit(1);
|
|
205
|
+
}
|
|
206
|
+
saveConfig({ [key]: value });
|
|
207
|
+
success(`Set ${key} = ${value}`);
|
|
208
|
+
});
|
|
209
|
+
if (isLocalDev) {
|
|
210
|
+
configCommand.command("use-production").description("Point CLI to production (federation.sortlist.com)").action(() => {
|
|
211
|
+
saveConfig({ endpoint: PRODUCTION_ENDPOINT });
|
|
212
|
+
success(`Endpoint set to ${PRODUCTION_ENDPOINT}`);
|
|
213
|
+
hint("Run `sl login` to authenticate against production.");
|
|
214
|
+
});
|
|
215
|
+
configCommand.command("use-staging").description("Point CLI to staging (federation.sortlist-test.com)").action(() => {
|
|
216
|
+
saveConfig({ endpoint: STAGING_ENDPOINT });
|
|
217
|
+
success(`Endpoint set to ${STAGING_ENDPOINT}`);
|
|
218
|
+
hint("Run `sl login` to authenticate against staging.");
|
|
219
|
+
});
|
|
220
|
+
configCommand.command("use-local").description("Point CLI to local development (localhost:4020)").action(() => {
|
|
221
|
+
saveConfig({ endpoint: LOCAL_ENDPOINT });
|
|
222
|
+
success(`Endpoint set to ${LOCAL_ENDPOINT}`);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
configCommand.command("reset").description("Reset all config and credentials").action(() => {
|
|
226
|
+
resetConfig();
|
|
227
|
+
clearCredentials();
|
|
228
|
+
success("Config and credentials cleared.");
|
|
229
|
+
hint("Run `sl login` to re-authenticate.");
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// src/commands/dynamic.ts
|
|
233
|
+
import { Command as Command2 } from "commander";
|
|
234
|
+
import {
|
|
235
|
+
isEnumType as isEnumType2,
|
|
236
|
+
isInputObjectType,
|
|
237
|
+
isInterfaceType as isInterfaceType2,
|
|
238
|
+
isListType as isListType2,
|
|
239
|
+
isNonNullType as isNonNullType2,
|
|
240
|
+
isObjectType as isObjectType2,
|
|
241
|
+
isScalarType as isScalarType2,
|
|
242
|
+
isUnionType as isUnionType2
|
|
243
|
+
} from "graphql";
|
|
244
|
+
|
|
245
|
+
// src/graphql/client.ts
|
|
246
|
+
import { print } from "graphql";
|
|
247
|
+
|
|
248
|
+
// src/lib/sentry.ts
|
|
249
|
+
import * as Sentry from "@sentry/node";
|
|
250
|
+
var SENTRY_DSN = "https://306d2e4389b8baa0bf14e587c2ceff04@o27611.ingest.us.sentry.io/4511229468409856";
|
|
251
|
+
var SENTRY_ENVIRONMENT = process.env.SL_SENTRY_ENV ?? (isLocalDev ? "development" : "production");
|
|
252
|
+
var IGNORED_ERRORS = [
|
|
253
|
+
/Network Error/i,
|
|
254
|
+
/Failed to fetch/i,
|
|
255
|
+
/fetch failed/i,
|
|
256
|
+
/ECONNREFUSED/i,
|
|
257
|
+
/ENOTFOUND/i,
|
|
258
|
+
/ETIMEDOUT/i,
|
|
259
|
+
/Request aborted/i
|
|
260
|
+
];
|
|
261
|
+
function isIgnoredError(message) {
|
|
262
|
+
return IGNORED_ERRORS.some(
|
|
263
|
+
(pattern) => typeof pattern === "string" ? message.includes(pattern) : pattern.test(message)
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
function initSentry() {
|
|
267
|
+
if (isLocalDev) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
Sentry.init({
|
|
271
|
+
dsn: SENTRY_DSN,
|
|
272
|
+
environment: SENTRY_ENVIRONMENT,
|
|
273
|
+
release: `${pkg.name}@${pkg.version}`,
|
|
274
|
+
tracesSampleRate: 0,
|
|
275
|
+
maxBreadcrumbs: 50,
|
|
276
|
+
attachStacktrace: true,
|
|
277
|
+
beforeSend(event) {
|
|
278
|
+
const message = event.exception?.values?.[0]?.value ?? "";
|
|
279
|
+
if (isIgnoredError(message)) {
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
return event;
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
Sentry.setTag("cli_version", pkg.version);
|
|
286
|
+
}
|
|
287
|
+
function captureException2(error2, extra) {
|
|
288
|
+
if (isLocalDev) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
Sentry.captureException(error2, extra ? { extra } : void 0);
|
|
292
|
+
}
|
|
293
|
+
function addBreadcrumb2(breadcrumb) {
|
|
294
|
+
if (isLocalDev) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
Sentry.addBreadcrumb(breadcrumb);
|
|
298
|
+
}
|
|
299
|
+
async function flushSentry(timeout = 2e3) {
|
|
300
|
+
if (isLocalDev) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
await Sentry.flush(timeout);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// src/graphql/generated/graphql.ts
|
|
307
|
+
var MeDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "query", "name": { "kind": "Name", "value": "Me" }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "me" }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "sub" } }, { "kind": "Field", "name": { "kind": "Name", "value": "email" } }, { "kind": "Field", "name": { "kind": "Name", "value": "firstName" } }, { "kind": "Field", "name": { "kind": "Name", "value": "lastName" } }] } }] } }] };
|
|
308
|
+
var LogoutUrlDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "query", "name": { "kind": "Name", "value": "LogoutUrl" }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "logoutUrl" } }] } }] };
|
|
309
|
+
var DeviceAuthorizeDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "DeviceAuthorize" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "DeviceAuthorizeInput" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "deviceAuthorize" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "input" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "deviceCode" } }, { "kind": "Field", "name": { "kind": "Name", "value": "expiresIn" } }, { "kind": "Field", "name": { "kind": "Name", "value": "interval" } }, { "kind": "Field", "name": { "kind": "Name", "value": "userCode" } }, { "kind": "Field", "name": { "kind": "Name", "value": "verificationUri" } }, { "kind": "Field", "name": { "kind": "Name", "value": "verificationUriComplete" } }] } }] } }] };
|
|
310
|
+
var DeviceTokenDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "DeviceToken" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "DeviceTokenInput" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "deviceToken" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "input" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "accessToken" } }, { "kind": "Field", "name": { "kind": "Name", "value": "error" } }, { "kind": "Field", "name": { "kind": "Name", "value": "expiresIn" } }, { "kind": "Field", "name": { "kind": "Name", "value": "idToken" } }, { "kind": "Field", "name": { "kind": "Name", "value": "refreshToken" } }, { "kind": "Field", "name": { "kind": "Name", "value": "tokenType" } }] } }] } }] };
|
|
311
|
+
var RefreshTokenDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "RefreshToken" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "RefreshTokenInput" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "refreshToken" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "input" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "accessToken" } }, { "kind": "Field", "name": { "kind": "Name", "value": "error" } }, { "kind": "Field", "name": { "kind": "Name", "value": "expiresIn" } }, { "kind": "Field", "name": { "kind": "Name", "value": "idToken" } }, { "kind": "Field", "name": { "kind": "Name", "value": "refreshToken" } }, { "kind": "Field", "name": { "kind": "Name", "value": "tokenType" } }] } }] } }] };
|
|
312
|
+
|
|
313
|
+
// src/graphql/generated/gql.ts
|
|
314
|
+
var documents = {
|
|
315
|
+
"\n query Me {\n me {\n sub\n email\n firstName\n lastName\n }\n }\n": MeDocument,
|
|
316
|
+
"\n query LogoutUrl {\n logoutUrl\n }\n": LogoutUrlDocument,
|
|
317
|
+
"\n mutation DeviceAuthorize($input: DeviceAuthorizeInput!) {\n deviceAuthorize(input: $input) {\n deviceCode\n expiresIn\n interval\n userCode\n verificationUri\n verificationUriComplete\n }\n }\n": DeviceAuthorizeDocument,
|
|
318
|
+
"\n mutation DeviceToken($input: DeviceTokenInput!) {\n deviceToken(input: $input) {\n accessToken\n error\n expiresIn\n idToken\n refreshToken\n tokenType\n }\n }\n": DeviceTokenDocument,
|
|
319
|
+
"\n mutation RefreshToken($input: RefreshTokenInput!) {\n refreshToken(input: $input) {\n accessToken\n error\n expiresIn\n idToken\n refreshToken\n tokenType\n }\n }\n": RefreshTokenDocument
|
|
320
|
+
};
|
|
321
|
+
function gql(source) {
|
|
322
|
+
return documents[source] ?? {};
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// src/graphql/operations/hermes.ts
|
|
326
|
+
var LogoutUrl = gql(`
|
|
327
|
+
query LogoutUrl {
|
|
328
|
+
logoutUrl
|
|
329
|
+
}
|
|
330
|
+
`);
|
|
331
|
+
var DeviceAuthorize = gql(`
|
|
332
|
+
mutation DeviceAuthorize($input: DeviceAuthorizeInput!) {
|
|
333
|
+
deviceAuthorize(input: $input) {
|
|
334
|
+
deviceCode
|
|
335
|
+
expiresIn
|
|
336
|
+
interval
|
|
337
|
+
userCode
|
|
338
|
+
verificationUri
|
|
339
|
+
verificationUriComplete
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
`);
|
|
343
|
+
var DeviceToken = gql(`
|
|
344
|
+
mutation DeviceToken($input: DeviceTokenInput!) {
|
|
345
|
+
deviceToken(input: $input) {
|
|
346
|
+
accessToken
|
|
347
|
+
error
|
|
348
|
+
expiresIn
|
|
349
|
+
idToken
|
|
350
|
+
refreshToken
|
|
351
|
+
tokenType
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
`);
|
|
355
|
+
var RefreshToken = gql(`
|
|
356
|
+
mutation RefreshToken($input: RefreshTokenInput!) {
|
|
357
|
+
refreshToken(input: $input) {
|
|
358
|
+
accessToken
|
|
359
|
+
error
|
|
360
|
+
expiresIn
|
|
361
|
+
idToken
|
|
362
|
+
refreshToken
|
|
363
|
+
tokenType
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
`);
|
|
367
|
+
|
|
368
|
+
// src/graphql/client.ts
|
|
369
|
+
function extractOperationName(query) {
|
|
370
|
+
const match = query.match(/(?:mutation|query|subscription)\s+(\w+)/);
|
|
371
|
+
return match?.[1] ?? "UnknownOperation";
|
|
372
|
+
}
|
|
373
|
+
var GraphQLRequestError = class extends Error {
|
|
374
|
+
operationName;
|
|
375
|
+
httpStatus;
|
|
376
|
+
graphqlErrors;
|
|
377
|
+
constructor(message, details) {
|
|
378
|
+
super(message);
|
|
379
|
+
this.name = "GraphQLRequestError";
|
|
380
|
+
this.operationName = details.operationName;
|
|
381
|
+
this.httpStatus = details.httpStatus;
|
|
382
|
+
this.graphqlErrors = details.graphqlErrors;
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
async function refreshAccessToken(creds, endpoint) {
|
|
386
|
+
const res = await fetch(endpoint, {
|
|
387
|
+
method: "POST",
|
|
388
|
+
headers: { "Content-Type": "application/json", "X-API-Client": "sl-cli" },
|
|
389
|
+
body: JSON.stringify({
|
|
390
|
+
query: print(RefreshToken),
|
|
391
|
+
variables: { input: { refreshToken: creds.refreshToken } }
|
|
392
|
+
})
|
|
393
|
+
});
|
|
394
|
+
const json = await res.json();
|
|
395
|
+
const token = json.data?.refreshToken;
|
|
396
|
+
if (!token || token.error) return null;
|
|
397
|
+
const newCreds = {
|
|
398
|
+
accessToken: token.accessToken,
|
|
399
|
+
refreshToken: token.refreshToken,
|
|
400
|
+
idToken: token.idToken,
|
|
401
|
+
expiresAt: Math.floor(Date.now() / 1e3) + token.expiresIn
|
|
402
|
+
};
|
|
403
|
+
saveCredentials(newCreds);
|
|
404
|
+
return newCreds;
|
|
405
|
+
}
|
|
406
|
+
async function executeQuery(query, variables, options = {}) {
|
|
407
|
+
const endpoint = getEndpoint(options.endpoint);
|
|
408
|
+
const authenticated = options.authenticated ?? true;
|
|
409
|
+
const throwOnError = options.throwOnError ?? false;
|
|
410
|
+
const operationName = extractOperationName(query);
|
|
411
|
+
const verbose = process.env.SL_DEBUG === "1";
|
|
412
|
+
addBreadcrumb2({
|
|
413
|
+
category: "graphql",
|
|
414
|
+
message: operationName,
|
|
415
|
+
data: { endpoint, authenticated },
|
|
416
|
+
level: "info"
|
|
417
|
+
});
|
|
418
|
+
if (verbose) {
|
|
419
|
+
info(`[debug] ${operationName} \u2192 ${endpoint}`);
|
|
420
|
+
info(`[debug] Query:
|
|
421
|
+
${query}`);
|
|
422
|
+
if (variables) {
|
|
423
|
+
info(`[debug] Variables: ${JSON.stringify(variables, null, 2)}`);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
const headers = {
|
|
427
|
+
"Content-Type": "application/json",
|
|
428
|
+
"X-API-Client": "sl-cli"
|
|
429
|
+
};
|
|
430
|
+
if (authenticated) {
|
|
431
|
+
let creds = ensureAuthenticated();
|
|
432
|
+
if (isExpired(creds)) {
|
|
433
|
+
const refreshed = await refreshAccessToken(creds, endpoint);
|
|
434
|
+
if (!refreshed) {
|
|
435
|
+
if (throwOnError) {
|
|
436
|
+
throw new GraphQLRequestError("Session expired and could not be refreshed.", { operationName });
|
|
437
|
+
}
|
|
438
|
+
error("Your session has expired and could not be refreshed.");
|
|
439
|
+
hint("Run `sl login` to re-authenticate.");
|
|
440
|
+
process.exit(2);
|
|
441
|
+
}
|
|
442
|
+
creds = refreshed;
|
|
443
|
+
}
|
|
444
|
+
headers["Authorization"] = `Bearer ${creds.accessToken}`;
|
|
445
|
+
if (verbose) {
|
|
446
|
+
info(`[debug] JWT: ...${creds.accessToken.slice(-8)}`);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
const res = await fetch(endpoint, {
|
|
450
|
+
method: "POST",
|
|
451
|
+
headers,
|
|
452
|
+
body: JSON.stringify({ query, variables })
|
|
453
|
+
});
|
|
454
|
+
if (!res.ok) {
|
|
455
|
+
const body = await res.text();
|
|
456
|
+
captureException2(new Error(`${operationName} failed: HTTP ${res.status}`), {
|
|
457
|
+
operationName,
|
|
458
|
+
httpStatus: res.status,
|
|
459
|
+
endpoint
|
|
460
|
+
});
|
|
461
|
+
if (throwOnError) {
|
|
462
|
+
throw new GraphQLRequestError(`${operationName} failed: HTTP ${res.status} ${res.statusText}`, {
|
|
463
|
+
operationName,
|
|
464
|
+
httpStatus: res.status
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
error(`${operationName} failed: HTTP ${res.status} ${res.statusText}`);
|
|
468
|
+
hint("Check your network connection and endpoint: sl config show");
|
|
469
|
+
if (verbose) {
|
|
470
|
+
info(`[debug] Response body: ${body}`);
|
|
471
|
+
}
|
|
472
|
+
process.exit(3);
|
|
473
|
+
}
|
|
474
|
+
const json = await res.json();
|
|
475
|
+
if (json.errors?.length) {
|
|
476
|
+
if (json.data) {
|
|
477
|
+
for (const gqlError of json.errors) {
|
|
478
|
+
warn(gqlError.message);
|
|
479
|
+
}
|
|
480
|
+
const hasFieldError2 = json.errors.some(
|
|
481
|
+
(e) => e.message.includes("Failed to implement") || e.message.includes("undefined method")
|
|
482
|
+
);
|
|
483
|
+
if (hasFieldError2) {
|
|
484
|
+
hint("Use --fields to select specific fields, or --exclude to skip broken ones.");
|
|
485
|
+
}
|
|
486
|
+
return json.data;
|
|
487
|
+
}
|
|
488
|
+
captureException2(new Error(`${operationName} GraphQL errors`), {
|
|
489
|
+
operationName,
|
|
490
|
+
errors: json.errors.map((e) => e.message)
|
|
491
|
+
});
|
|
492
|
+
if (throwOnError) {
|
|
493
|
+
throw new GraphQLRequestError(`${operationName} failed: ${json.errors.map((e) => e.message).join("; ")}`, {
|
|
494
|
+
operationName,
|
|
495
|
+
graphqlErrors: json.errors
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
error(`${operationName} failed:`);
|
|
499
|
+
for (const gqlError of json.errors) {
|
|
500
|
+
info(` ${gqlError.message}`);
|
|
501
|
+
if (verbose && gqlError.extensions) {
|
|
502
|
+
info(`[debug] Extensions: ${JSON.stringify(gqlError.extensions)}`);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
const hasFieldError = json.errors.some(
|
|
506
|
+
(e) => e.message.includes("Failed to implement") || e.message.includes("undefined method")
|
|
507
|
+
);
|
|
508
|
+
if (hasFieldError) {
|
|
509
|
+
hint("Use --fields to select specific fields, or --exclude to skip broken ones.");
|
|
510
|
+
hint(`Example: sl ${operationName.toLowerCase()} --fields id,title,status`);
|
|
511
|
+
}
|
|
512
|
+
process.exit(1);
|
|
513
|
+
}
|
|
514
|
+
if (!json.data) {
|
|
515
|
+
if (throwOnError) {
|
|
516
|
+
throw new GraphQLRequestError(`${operationName}: no data returned from API.`, { operationName });
|
|
517
|
+
}
|
|
518
|
+
error(`${operationName}: no data returned from API.`);
|
|
519
|
+
hint("This usually means the server returned an empty response.");
|
|
520
|
+
hint("Verify your endpoint: sl config show");
|
|
521
|
+
process.exit(1);
|
|
522
|
+
}
|
|
523
|
+
return json.data;
|
|
524
|
+
}
|
|
525
|
+
async function graphql(document, variables, options = {}) {
|
|
526
|
+
return executeQuery(print(document), variables, options);
|
|
527
|
+
}
|
|
528
|
+
async function graphqlRaw(query, variables, options = {}) {
|
|
529
|
+
return executeQuery(query, variables, options);
|
|
530
|
+
}
|
|
531
|
+
async function graphqlUnauthenticated(document, variables, endpoint) {
|
|
532
|
+
return graphql(document, variables, { endpoint, authenticated: false });
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// src/graphql/query-builder.ts
|
|
536
|
+
import {
|
|
537
|
+
isEnumType,
|
|
538
|
+
isInterfaceType,
|
|
539
|
+
isListType,
|
|
540
|
+
isNonNullType,
|
|
541
|
+
isObjectType,
|
|
542
|
+
isScalarType,
|
|
543
|
+
isUnionType
|
|
544
|
+
} from "graphql";
|
|
545
|
+
function unwrap(type) {
|
|
546
|
+
if (isNonNullType(type)) return unwrap(type.ofType);
|
|
547
|
+
if (isListType(type)) return unwrap(type.ofType);
|
|
548
|
+
return type;
|
|
549
|
+
}
|
|
550
|
+
function isLeaf(type) {
|
|
551
|
+
return isScalarType(type) || isEnumType(type);
|
|
552
|
+
}
|
|
553
|
+
function ucfirst(s) {
|
|
554
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
555
|
+
}
|
|
556
|
+
var PAYLOAD_TYPE_PATTERN = /(?:Response|Payload|MutationPayload)$/;
|
|
557
|
+
function buildSelections(type, schema, depth, exclude, prefix, visited) {
|
|
558
|
+
if (!isObjectType(type)) return [];
|
|
559
|
+
if (visited.has(type.name)) return [];
|
|
560
|
+
visited.add(type.name);
|
|
561
|
+
const fields = type.getFields();
|
|
562
|
+
const lines = [];
|
|
563
|
+
const isPayload = PAYLOAD_TYPE_PATTERN.test(type.name);
|
|
564
|
+
if (type.name.endsWith("Connection") && fields.nodes && fields.pageInfo) {
|
|
565
|
+
const nodesType = unwrap(fields.nodes.type);
|
|
566
|
+
const nodeSelections = buildSelections(nodesType, schema, depth, exclude, `${prefix}nodes.`, new Set(visited));
|
|
567
|
+
if (nodeSelections.length === 0) return [];
|
|
568
|
+
lines.push(`nodes {`);
|
|
569
|
+
for (const sel of nodeSelections) lines.push(` ${sel}`);
|
|
570
|
+
lines.push(`}`);
|
|
571
|
+
lines.push(`pageInfo {`);
|
|
572
|
+
lines.push(` hasNextPage`);
|
|
573
|
+
lines.push(` endCursor`);
|
|
574
|
+
lines.push(`}`);
|
|
575
|
+
if (fields.totalCount) lines.push(`totalCount`);
|
|
576
|
+
return lines;
|
|
577
|
+
}
|
|
578
|
+
for (const [name, field] of Object.entries(fields)) {
|
|
579
|
+
if (name.startsWith("__")) continue;
|
|
580
|
+
if (name === "id" && isPayload) continue;
|
|
581
|
+
const fullPath = `${prefix}${name}`;
|
|
582
|
+
if (exclude.has(fullPath) || exclude.has(name)) continue;
|
|
583
|
+
const hasRequiredArgs = field.args.some((a) => isNonNullType(a.type) && a.defaultValue === void 0);
|
|
584
|
+
if (hasRequiredArgs) continue;
|
|
585
|
+
const namedType = unwrap(field.type);
|
|
586
|
+
if (isLeaf(namedType)) {
|
|
587
|
+
lines.push(name);
|
|
588
|
+
} else if (isObjectType(namedType) && depth > 0) {
|
|
589
|
+
const subSelections = buildSelections(namedType, schema, depth - 1, exclude, `${fullPath}.`, new Set(visited));
|
|
590
|
+
if (subSelections.length > 0) {
|
|
591
|
+
lines.push(`${name} {`);
|
|
592
|
+
for (const sel of subSelections) lines.push(` ${sel}`);
|
|
593
|
+
lines.push(`}`);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
return lines;
|
|
598
|
+
}
|
|
599
|
+
function buildQuery(schema, kind, fieldName, variables, options = {}) {
|
|
600
|
+
const rootType = kind === "query" ? schema.getQueryType() : schema.getMutationType();
|
|
601
|
+
if (!rootType) throw new Error(`No ${kind} type in schema`);
|
|
602
|
+
const field = rootType.getFields()[fieldName];
|
|
603
|
+
if (!field) throw new Error(`Unknown ${kind} field: ${fieldName}`);
|
|
604
|
+
const depth = options.depth ?? 0;
|
|
605
|
+
const exclude = new Set(options.exclude ?? []);
|
|
606
|
+
const returnType = unwrap(field.type);
|
|
607
|
+
const allArgs = field.args;
|
|
608
|
+
const varDefsInner = allArgs.map((a) => `$${a.name}: ${a.type.toString()}`).join(", ");
|
|
609
|
+
const fieldArgsInner = allArgs.map((a) => `${a.name}: $${a.name}`).join(", ");
|
|
610
|
+
const varDefs = allArgs.length > 0 ? `(${varDefsInner})` : "";
|
|
611
|
+
const fieldArgs = allArgs.length > 0 ? `(${fieldArgsInner})` : "";
|
|
612
|
+
let selectionBody;
|
|
613
|
+
if (isLeaf(returnType) || isInterfaceType(returnType) || isUnionType(returnType)) {
|
|
614
|
+
selectionBody = ` ${fieldName}${fieldArgs}`;
|
|
615
|
+
} else {
|
|
616
|
+
let selections;
|
|
617
|
+
if (options.fields && options.fields.length > 0) {
|
|
618
|
+
selections = buildFieldsFromList(returnType, schema, options.fields);
|
|
619
|
+
} else {
|
|
620
|
+
selections = buildSelections(returnType, schema, depth, exclude, "", /* @__PURE__ */ new Set());
|
|
621
|
+
}
|
|
622
|
+
if (selections.length === 0) {
|
|
623
|
+
selectionBody = ` ${fieldName}${fieldArgs} {
|
|
624
|
+
__typename
|
|
625
|
+
}`;
|
|
626
|
+
} else {
|
|
627
|
+
const indent = " ";
|
|
628
|
+
const body = selections.map((s) => `${indent}${s}`).join("\n");
|
|
629
|
+
selectionBody = ` ${fieldName}${fieldArgs} {
|
|
630
|
+
${body}
|
|
631
|
+
}`;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
const opName = ucfirst(fieldName);
|
|
635
|
+
const query = `${kind} ${opName}${varDefs} {
|
|
636
|
+
${selectionBody}
|
|
637
|
+
}`;
|
|
638
|
+
return { query, variables, fieldName };
|
|
639
|
+
}
|
|
640
|
+
function buildFieldsFromList(type, schema, fieldPaths) {
|
|
641
|
+
if (!isObjectType(type)) return [];
|
|
642
|
+
const fields = type.getFields();
|
|
643
|
+
if (type.name.endsWith("Connection") && fields.nodes && fields.pageInfo) {
|
|
644
|
+
const nodesType = unwrap(fields.nodes.type);
|
|
645
|
+
const nodeSelections = buildFieldsFromList(nodesType, schema, fieldPaths);
|
|
646
|
+
if (nodeSelections.length === 0) return [];
|
|
647
|
+
const lines2 = [];
|
|
648
|
+
lines2.push("nodes {");
|
|
649
|
+
for (const sel of nodeSelections) lines2.push(` ${sel}`);
|
|
650
|
+
lines2.push("}");
|
|
651
|
+
lines2.push("pageInfo {");
|
|
652
|
+
lines2.push(" hasNextPage");
|
|
653
|
+
lines2.push(" endCursor");
|
|
654
|
+
lines2.push("}");
|
|
655
|
+
if (fields.totalCount) lines2.push("totalCount");
|
|
656
|
+
return lines2;
|
|
657
|
+
}
|
|
658
|
+
const lines = [];
|
|
659
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
660
|
+
for (const fp of fieldPaths) {
|
|
661
|
+
const [top, ...rest] = fp.split(".");
|
|
662
|
+
if (!grouped.has(top)) grouped.set(top, []);
|
|
663
|
+
if (rest.length > 0) grouped.get(top).push(rest.join("."));
|
|
664
|
+
}
|
|
665
|
+
for (const [name, subPaths] of grouped) {
|
|
666
|
+
const field = fields[name];
|
|
667
|
+
if (!field) continue;
|
|
668
|
+
const namedType = unwrap(field.type);
|
|
669
|
+
if (isLeaf(namedType)) {
|
|
670
|
+
lines.push(name);
|
|
671
|
+
} else if (isObjectType(namedType) && subPaths.length > 0) {
|
|
672
|
+
const subSelections = buildFieldsFromList(namedType, schema, subPaths);
|
|
673
|
+
if (subSelections.length > 0) {
|
|
674
|
+
lines.push(`${name} {`);
|
|
675
|
+
for (const sel of subSelections) lines.push(` ${sel}`);
|
|
676
|
+
lines.push(`}`);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
return lines;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
// src/lib/company.ts
|
|
684
|
+
function resolveCompanyId(opts) {
|
|
685
|
+
return opts.companyId || opts.ctx?.companyId;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
// src/commands/dynamic.ts
|
|
689
|
+
var CONTEXT_FIELDS = {
|
|
690
|
+
companyId: "companyId",
|
|
691
|
+
oauthId: "oauthId"
|
|
692
|
+
};
|
|
693
|
+
var SKIP_FIELDS = /* @__PURE__ */ new Set(["node", "nodes", "id", "_entities", "_service"]);
|
|
694
|
+
function unwrap2(type) {
|
|
695
|
+
if (isNonNullType2(type)) return unwrap2(type.ofType);
|
|
696
|
+
if (isListType2(type)) return unwrap2(type.ofType);
|
|
697
|
+
return type;
|
|
698
|
+
}
|
|
699
|
+
function kebab(s) {
|
|
700
|
+
return s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
701
|
+
}
|
|
702
|
+
function ucfirst2(s) {
|
|
703
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
704
|
+
}
|
|
705
|
+
function getInputFields(field) {
|
|
706
|
+
if (field.args.length !== 1) return null;
|
|
707
|
+
const arg = field.args[0];
|
|
708
|
+
if (arg.name !== "input") return null;
|
|
709
|
+
const argType = unwrap2(arg.type);
|
|
710
|
+
if (!argType || !isInputObjectType(argType)) return null;
|
|
711
|
+
const fields = argType.getFields();
|
|
712
|
+
return Object.entries(fields).map(([name, f]) => ({
|
|
713
|
+
name,
|
|
714
|
+
type: f.type,
|
|
715
|
+
required: isNonNullType2(f.type),
|
|
716
|
+
description: f.description
|
|
717
|
+
}));
|
|
718
|
+
}
|
|
719
|
+
function renderType(type) {
|
|
720
|
+
if (isNonNullType2(type)) return `${renderType(type.ofType)}!`;
|
|
721
|
+
if (isListType2(type)) return `[${renderType(type.ofType)}]`;
|
|
722
|
+
return type.name;
|
|
723
|
+
}
|
|
724
|
+
function isStructuredInput(type) {
|
|
725
|
+
if (isNonNullType2(type)) return isStructuredInput(type.ofType);
|
|
726
|
+
if (isListType2(type)) return true;
|
|
727
|
+
return isInputObjectType(type);
|
|
728
|
+
}
|
|
729
|
+
function coerceValue(raw, type, flagName) {
|
|
730
|
+
if (isStructuredInput(type)) {
|
|
731
|
+
try {
|
|
732
|
+
return JSON.parse(raw);
|
|
733
|
+
} catch (parseError) {
|
|
734
|
+
throw new Error(
|
|
735
|
+
`--${flagName} expects JSON for type ${renderType(type)}, but the value could not be parsed: ${parseError.message}`
|
|
736
|
+
);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
const typeName = unwrap2(type).name;
|
|
740
|
+
if (typeName === "Int") {
|
|
741
|
+
const parsed = parseInt(raw, 10);
|
|
742
|
+
if (Number.isNaN(parsed)) throw new Error(`--${flagName} expects an integer, got "${raw}".`);
|
|
743
|
+
return parsed;
|
|
744
|
+
}
|
|
745
|
+
if (typeName === "Float") {
|
|
746
|
+
const parsed = parseFloat(raw);
|
|
747
|
+
if (Number.isNaN(parsed)) throw new Error(`--${flagName} expects a number, got "${raw}".`);
|
|
748
|
+
return parsed;
|
|
749
|
+
}
|
|
750
|
+
if (typeName === "Boolean") {
|
|
751
|
+
if (raw !== "true" && raw !== "false") {
|
|
752
|
+
throw new Error(`--${flagName} expects "true" or "false", got "${raw}".`);
|
|
753
|
+
}
|
|
754
|
+
return raw === "true";
|
|
755
|
+
}
|
|
756
|
+
return raw;
|
|
757
|
+
}
|
|
758
|
+
function describeStructuredType(named) {
|
|
759
|
+
if (isInputObjectType(named)) {
|
|
760
|
+
const fields = Object.values(named.getFields());
|
|
761
|
+
const parts = fields.map((f) => `${f.name}: ${renderType(f.type)}`);
|
|
762
|
+
return `{ ${parts.join(", ")} }`;
|
|
763
|
+
}
|
|
764
|
+
if (isEnumType2(named)) {
|
|
765
|
+
const values = named.getValues().map((v) => v.name);
|
|
766
|
+
return `one of: ${values.join(" | ")}`;
|
|
767
|
+
}
|
|
768
|
+
return null;
|
|
769
|
+
}
|
|
770
|
+
function isInspectable(named) {
|
|
771
|
+
return isInputObjectType(named) || isEnumType2(named) || isObjectType2(named);
|
|
772
|
+
}
|
|
773
|
+
function oneLineDescription(text) {
|
|
774
|
+
return (text ?? "").replace(/\s+/g, " ").trim();
|
|
775
|
+
}
|
|
776
|
+
function formatTypeInspection(schema, typeName) {
|
|
777
|
+
const named = schema.getType(typeName);
|
|
778
|
+
if (!named) return null;
|
|
779
|
+
const lines = [];
|
|
780
|
+
const suffix = oneLineDescription(named.description);
|
|
781
|
+
const header = (kind) => {
|
|
782
|
+
const label = kind ? `${kind} ${named.name}` : named.name;
|
|
783
|
+
return suffix ? `${label} \u2014 ${suffix}` : label;
|
|
784
|
+
};
|
|
785
|
+
const pushFields = (entries) => {
|
|
786
|
+
const width = Math.max(...entries.map((entry) => `${entry.name}: ${entry.typeSig}`.length), 0);
|
|
787
|
+
for (const entry of entries) {
|
|
788
|
+
const signature = `${entry.name}: ${entry.typeSig}`;
|
|
789
|
+
const note = oneLineDescription(entry.description);
|
|
790
|
+
lines.push(note ? ` ${signature.padEnd(width)} ${note}` : ` ${signature}`);
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
if (isInputObjectType(named) || isObjectType2(named)) {
|
|
794
|
+
lines.push(header(isInputObjectType(named) ? "input" : "type"));
|
|
795
|
+
pushFields(
|
|
796
|
+
Object.values(named.getFields()).map((f) => ({
|
|
797
|
+
name: f.name,
|
|
798
|
+
typeSig: renderType(f.type),
|
|
799
|
+
description: f.description
|
|
800
|
+
}))
|
|
801
|
+
);
|
|
802
|
+
} else if (isEnumType2(named)) {
|
|
803
|
+
lines.push(header("enum"));
|
|
804
|
+
for (const value of named.getValues()) {
|
|
805
|
+
const note = oneLineDescription(value.description);
|
|
806
|
+
lines.push(note ? ` ${value.name.padEnd(20)} ${note}` : ` ${value.name}`);
|
|
807
|
+
}
|
|
808
|
+
} else if (isScalarType2(named)) {
|
|
809
|
+
lines.push(header("scalar"));
|
|
810
|
+
lines.push(" (scalar \u2014 pass a plain value)");
|
|
811
|
+
} else {
|
|
812
|
+
lines.push(header(""));
|
|
813
|
+
}
|
|
814
|
+
const nested = /* @__PURE__ */ new Set();
|
|
815
|
+
if (isInputObjectType(named) || isObjectType2(named)) {
|
|
816
|
+
for (const field of Object.values(named.getFields())) {
|
|
817
|
+
const fieldType = unwrap2(field.type);
|
|
818
|
+
if (isInspectable(fieldType) && fieldType.name !== named.name) nested.add(fieldType.name);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
if (nested.size > 0) {
|
|
822
|
+
lines.push("");
|
|
823
|
+
lines.push(
|
|
824
|
+
`Inspect nested types: ${[...nested].sort().map((n) => `sl schema inspect ${n}`).join(", ")}`
|
|
825
|
+
);
|
|
826
|
+
}
|
|
827
|
+
return lines.join("\n");
|
|
828
|
+
}
|
|
829
|
+
function describeArg(arg) {
|
|
830
|
+
const parts = [];
|
|
831
|
+
if (arg.description) parts.push(arg.description.replace(/\s+/g, " ").trim());
|
|
832
|
+
const typeSig = renderType(arg.type);
|
|
833
|
+
parts.push(isStructuredInput(arg.type) ? `${typeSig} (JSON)` : typeSig);
|
|
834
|
+
const named = unwrap2(arg.type);
|
|
835
|
+
const shape = describeStructuredType(named);
|
|
836
|
+
if (shape) parts.push(shape);
|
|
837
|
+
if (isInputObjectType(named) || isEnumType2(named)) {
|
|
838
|
+
parts.push(`details: sl schema inspect ${named.name}`);
|
|
839
|
+
}
|
|
840
|
+
return parts.join(" \u2014 ");
|
|
841
|
+
}
|
|
842
|
+
function buildCommand(schema, fieldName, kind, description) {
|
|
843
|
+
const rootType = kind === "query" ? schema.getQueryType() : schema.getMutationType();
|
|
844
|
+
if (!rootType) throw new Error(`No ${kind} type in schema`);
|
|
845
|
+
const field = rootType.getFields()[fieldName];
|
|
846
|
+
if (!field) throw new Error(`Unknown ${kind} field: ${fieldName}`);
|
|
847
|
+
const inputFields = getInputFields(field);
|
|
848
|
+
const useInputWrapper = inputFields != null;
|
|
849
|
+
const cliArgs = useInputWrapper ? inputFields : field.args.map((a) => ({
|
|
850
|
+
name: a.name,
|
|
851
|
+
type: a.type,
|
|
852
|
+
required: isNonNullType2(a.type),
|
|
853
|
+
description: a.description
|
|
854
|
+
}));
|
|
855
|
+
const cmd = new Command2(kebab(fieldName)).description(description);
|
|
856
|
+
const acceptsCompanyId = cliArgs.some((a) => a.name === "companyId");
|
|
857
|
+
for (const a of cliArgs) {
|
|
858
|
+
const placeholder = isStructuredInput(a.type) ? "json" : kebab(a.name);
|
|
859
|
+
const flag = `--${kebab(a.name)} <${placeholder}>`;
|
|
860
|
+
const isContext = a.name in CONTEXT_FIELDS;
|
|
861
|
+
if (isContext) {
|
|
862
|
+
cmd.option(flag, `${describeArg(a)} (from context if omitted)`);
|
|
863
|
+
} else if (a.required) {
|
|
864
|
+
cmd.requiredOption(flag, describeArg(a));
|
|
865
|
+
} else {
|
|
866
|
+
cmd.option(flag, describeArg(a));
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
cmd.option("--depth <depth>", "Selection depth (default: 0)", parseInt).option("--fields <fields>", "Comma-separated fields to include").option("--exclude <fields>", "Comma-separated fields to exclude");
|
|
870
|
+
cmd.action(async function() {
|
|
871
|
+
const opts = this.optsWithGlobals();
|
|
872
|
+
const needsContext = cliArgs.some((a) => a.name in CONTEXT_FIELDS);
|
|
873
|
+
const ctx = needsContext ? getUserContext() : void 0;
|
|
874
|
+
if (acceptsCompanyId) {
|
|
875
|
+
const resolved = resolveCompanyId({
|
|
876
|
+
companyId: typeof opts.companyId === "string" ? opts.companyId : void 0,
|
|
877
|
+
ctx
|
|
878
|
+
});
|
|
879
|
+
if (!resolved) {
|
|
880
|
+
error("No company selected.");
|
|
881
|
+
hint("Pass --company-id <id> or set one with `sl config set companyId <id>`.");
|
|
882
|
+
process.exit(2);
|
|
883
|
+
}
|
|
884
|
+
opts.companyId = resolved;
|
|
885
|
+
}
|
|
886
|
+
const collectArgs = () => {
|
|
887
|
+
const out = {};
|
|
888
|
+
for (const a of cliArgs) {
|
|
889
|
+
const raw = opts[a.name];
|
|
890
|
+
const ctxProp = CONTEXT_FIELDS[a.name];
|
|
891
|
+
if (raw != null) {
|
|
892
|
+
try {
|
|
893
|
+
out[a.name] = coerceValue(raw, a.type, kebab(a.name));
|
|
894
|
+
} catch (coerceError) {
|
|
895
|
+
error(coerceError.message);
|
|
896
|
+
hint("Run the command with --help to see the expected shape of each argument.");
|
|
897
|
+
process.exit(2);
|
|
898
|
+
}
|
|
899
|
+
} else if (ctxProp && ctx) {
|
|
900
|
+
out[a.name] = ctx[ctxProp];
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
return out;
|
|
904
|
+
};
|
|
905
|
+
const variables = useInputWrapper ? { input: collectArgs() } : collectArgs();
|
|
906
|
+
const { query, fieldName: fName } = buildQuery(schema, kind, fieldName, variables, {
|
|
907
|
+
depth: opts.depth,
|
|
908
|
+
fields: opts.fields?.split(","),
|
|
909
|
+
exclude: opts.exclude?.split(",")
|
|
910
|
+
});
|
|
911
|
+
const data = await graphqlRaw(query, variables, { endpoint: opts.endpoint });
|
|
912
|
+
const result = data[fName];
|
|
913
|
+
if (result == null) {
|
|
914
|
+
warn("No results returned.");
|
|
915
|
+
hint("The query succeeded but the server returned null.");
|
|
916
|
+
hint("Try different arguments or check that the resource exists.");
|
|
917
|
+
} else {
|
|
918
|
+
printJson(result);
|
|
919
|
+
}
|
|
920
|
+
});
|
|
921
|
+
return cmd;
|
|
922
|
+
}
|
|
923
|
+
var useColor = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
924
|
+
var ansi2 = {
|
|
925
|
+
reset: "\x1B[0m",
|
|
926
|
+
bold: "\x1B[1m",
|
|
927
|
+
dim: "\x1B[2m",
|
|
928
|
+
cyan: "\x1B[36m",
|
|
929
|
+
yellow: "\x1B[33m"
|
|
930
|
+
};
|
|
931
|
+
function formatCommandList(commands) {
|
|
932
|
+
if (commands.length === 0) return "";
|
|
933
|
+
const maxLen = Math.max(...commands.map((c2) => c2.name().length + (c2.options.length > 0 ? 10 : 0)));
|
|
934
|
+
const padWidth = Math.max(maxLen, 20);
|
|
935
|
+
return commands.map((c2) => {
|
|
936
|
+
const name = c2.options.length > 0 ? `${c2.name()} [options]` : c2.name();
|
|
937
|
+
const desc = c2.description();
|
|
938
|
+
const padding = " ".repeat(Math.max(2, padWidth - name.length + 2));
|
|
939
|
+
if (desc) {
|
|
940
|
+
return ` ${name}${padding}${desc}`;
|
|
941
|
+
}
|
|
942
|
+
const noDesc = useColor ? `${ansi2.yellow}No description provided${ansi2.reset}` : "No description provided";
|
|
943
|
+
return ` ${name}${padding}${noDesc}`;
|
|
944
|
+
}).join("\n");
|
|
945
|
+
}
|
|
946
|
+
function deriveServiceMap(schema, fieldServices) {
|
|
947
|
+
const map = /* @__PURE__ */ new Map();
|
|
948
|
+
function ensure(service) {
|
|
949
|
+
if (!map.has(service)) map.set(service, { queries: [], mutations: [] });
|
|
950
|
+
return map.get(service);
|
|
951
|
+
}
|
|
952
|
+
const rootTypes = [
|
|
953
|
+
{ kind: "queries", type: schema.getQueryType() },
|
|
954
|
+
{ kind: "mutations", type: schema.getMutationType() }
|
|
955
|
+
];
|
|
956
|
+
for (const { kind, type } of rootTypes) {
|
|
957
|
+
if (!type) continue;
|
|
958
|
+
const services = fieldServices.get(type.name);
|
|
959
|
+
if (!services) continue;
|
|
960
|
+
for (const [fieldName, field] of Object.entries(type.getFields())) {
|
|
961
|
+
if (SKIP_FIELDS.has(fieldName) || fieldName.startsWith("__")) continue;
|
|
962
|
+
const returnType = unwrap2(field.type);
|
|
963
|
+
if (isInterfaceType2(returnType) || isUnionType2(returnType)) continue;
|
|
964
|
+
const service = services.get(fieldName);
|
|
965
|
+
if (!service) continue;
|
|
966
|
+
ensure(service)[kind].push({ fieldName, description: field.description ?? "" });
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
for (const entry of map.values()) {
|
|
970
|
+
entry.queries.sort((a, b) => a.fieldName.localeCompare(b.fieldName));
|
|
971
|
+
entry.mutations.sort((a, b) => a.fieldName.localeCompare(b.fieldName));
|
|
972
|
+
}
|
|
973
|
+
return map;
|
|
974
|
+
}
|
|
975
|
+
var SERVICE_DESCRIPTIONS = {
|
|
976
|
+
atlas: "Atlas service (contacts, orgs)",
|
|
977
|
+
marketplace: "Marketplace service",
|
|
978
|
+
hermes: "Hermes service"
|
|
979
|
+
};
|
|
980
|
+
function serviceDescription(service) {
|
|
981
|
+
return SERVICE_DESCRIPTIONS[service] ?? `${ucfirst2(service)} service operations`;
|
|
982
|
+
}
|
|
983
|
+
function buildServiceCommands(schema, fieldServices) {
|
|
984
|
+
const serviceMap = deriveServiceMap(schema, fieldServices);
|
|
985
|
+
const commands = /* @__PURE__ */ new Map();
|
|
986
|
+
const allNames = /* @__PURE__ */ new Map();
|
|
987
|
+
for (const entry of serviceMap.values()) {
|
|
988
|
+
for (const op of [...entry.queries, ...entry.mutations]) {
|
|
989
|
+
allNames.set(op.fieldName, (allNames.get(op.fieldName) ?? 0) + 1);
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
for (const [service, entry] of serviceMap) {
|
|
993
|
+
const subCmd = new Command2(service).description(serviceDescription(service));
|
|
994
|
+
const queryCommands = [];
|
|
995
|
+
const mutationCommands = [];
|
|
996
|
+
for (const op of entry.queries) {
|
|
997
|
+
try {
|
|
998
|
+
const cmd = buildCommand(schema, op.fieldName, "query", op.description);
|
|
999
|
+
if ((allNames.get(op.fieldName) ?? 0) > 1) {
|
|
1000
|
+
cmd.name(`${kebab(op.fieldName)}-query`);
|
|
1001
|
+
}
|
|
1002
|
+
subCmd.addCommand(cmd, { hidden: true });
|
|
1003
|
+
queryCommands.push(cmd);
|
|
1004
|
+
} catch {
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
for (const op of entry.mutations) {
|
|
1008
|
+
try {
|
|
1009
|
+
const cmd = buildCommand(schema, op.fieldName, "mutation", op.description);
|
|
1010
|
+
if ((allNames.get(op.fieldName) ?? 0) > 1) {
|
|
1011
|
+
cmd.name(`${kebab(op.fieldName)}-mutation`);
|
|
1012
|
+
}
|
|
1013
|
+
subCmd.addCommand(cmd, { hidden: true });
|
|
1014
|
+
mutationCommands.push(cmd);
|
|
1015
|
+
} catch {
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
subCmd.configureHelp({
|
|
1019
|
+
formatHelp: () => {
|
|
1020
|
+
const lines = [];
|
|
1021
|
+
lines.push(`Usage: sl ${service} [command] [options]
|
|
1022
|
+
`);
|
|
1023
|
+
lines.push(`${serviceDescription(service)}
|
|
1024
|
+
`);
|
|
1025
|
+
if (queryCommands.length > 0) {
|
|
1026
|
+
lines.push(`Queries:`);
|
|
1027
|
+
lines.push(formatCommandList(queryCommands));
|
|
1028
|
+
lines.push("");
|
|
1029
|
+
}
|
|
1030
|
+
if (mutationCommands.length > 0) {
|
|
1031
|
+
lines.push(`Mutations:`);
|
|
1032
|
+
lines.push(formatCommandList(mutationCommands));
|
|
1033
|
+
lines.push("");
|
|
1034
|
+
}
|
|
1035
|
+
lines.push(`Options:`);
|
|
1036
|
+
lines.push(` -h, --help display help for command
|
|
1037
|
+
`);
|
|
1038
|
+
return lines.join("\n");
|
|
1039
|
+
}
|
|
1040
|
+
});
|
|
1041
|
+
if (queryCommands.length > 0 || mutationCommands.length > 0) {
|
|
1042
|
+
commands.set(service, {
|
|
1043
|
+
command: subCmd,
|
|
1044
|
+
exampleQuery: queryCommands[0]?.name() ?? null
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
return commands;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
// src/commands/login.ts
|
|
1052
|
+
import { Command as Command3 } from "commander";
|
|
1053
|
+
|
|
1054
|
+
// src/graphql/operations/common.ts
|
|
1055
|
+
var Me = gql(`
|
|
1056
|
+
query Me {
|
|
1057
|
+
me {
|
|
1058
|
+
sub
|
|
1059
|
+
email
|
|
1060
|
+
firstName
|
|
1061
|
+
lastName
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
`);
|
|
1065
|
+
|
|
1066
|
+
// src/lib/browser.ts
|
|
1067
|
+
import { execFile } from "child_process";
|
|
1068
|
+
function openBrowser(url) {
|
|
1069
|
+
if (process.platform === "win32") {
|
|
1070
|
+
execFile("cmd", ["/c", "start", "", url], () => {
|
|
1071
|
+
});
|
|
1072
|
+
return;
|
|
1073
|
+
}
|
|
1074
|
+
const cmd = process.platform === "darwin" ? "open" : "xdg-open";
|
|
1075
|
+
execFile(cmd, [url], () => {
|
|
1076
|
+
});
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
// src/commands/login.ts
|
|
1080
|
+
var API_SCOPES = [
|
|
1081
|
+
"atlas/*:*",
|
|
1082
|
+
"atlas/*:read",
|
|
1083
|
+
"core/*:*",
|
|
1084
|
+
"core/*:read",
|
|
1085
|
+
"signals/*:*",
|
|
1086
|
+
"signals/*:read",
|
|
1087
|
+
"billing/*:*",
|
|
1088
|
+
"billing/*:read",
|
|
1089
|
+
"billing/offer:*"
|
|
1090
|
+
];
|
|
1091
|
+
var DEFAULT_SCOPE = `openid profile email offline_access ${API_SCOPES.join(" ")}`;
|
|
1092
|
+
function sleep(ms) {
|
|
1093
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1094
|
+
}
|
|
1095
|
+
async function setupUserContext(endpoint) {
|
|
1096
|
+
const userData = await graphql(Me, void 0, { endpoint });
|
|
1097
|
+
const user = userData.me;
|
|
1098
|
+
if (!user) return;
|
|
1099
|
+
saveConfig({ oauthId: user.sub ?? void 0 });
|
|
1100
|
+
info("");
|
|
1101
|
+
info(` User: ${user.firstName} ${user.lastName} <${user.email}>`);
|
|
1102
|
+
hint("Run `sl whoami` to verify.");
|
|
1103
|
+
}
|
|
1104
|
+
var loginCommand = new Command3("login").summary("Log in to your Sortlist account").description(
|
|
1105
|
+
"Log in to your Sortlist account\n\nOpens a browser to complete authentication, then saves your\ncredentials locally. If you belong to multiple companies, you'll\nbe prompted to pick one.\n\nExamples:\n sl login Log in with default settings\n sl login --no-browser Print the login URL instead of opening it"
|
|
1106
|
+
).option("--scope <scope>", "OAuth scope", DEFAULT_SCOPE).option("--no-browser", "Print the login URL instead of opening a browser").action(async function() {
|
|
1107
|
+
const opts = this.optsWithGlobals();
|
|
1108
|
+
info("Starting device authorization...");
|
|
1109
|
+
const authData = await graphqlUnauthenticated(DeviceAuthorize, { input: { scope: opts.scope } }, opts.endpoint);
|
|
1110
|
+
const device = authData.deviceAuthorize;
|
|
1111
|
+
if (!device) {
|
|
1112
|
+
error("Device authorization failed \u2014 the server returned an empty response.");
|
|
1113
|
+
hint("Check your network connection and try again.");
|
|
1114
|
+
hint("If the problem persists, verify the endpoint: sl config show");
|
|
1115
|
+
process.exit(2);
|
|
1116
|
+
}
|
|
1117
|
+
const url = device.verificationUriComplete ?? device.verificationUri;
|
|
1118
|
+
info("");
|
|
1119
|
+
info(` Open this URL in your browser:`);
|
|
1120
|
+
info(` ${url}`);
|
|
1121
|
+
info("");
|
|
1122
|
+
info(` Enter code: ${device.userCode}`);
|
|
1123
|
+
info("");
|
|
1124
|
+
if (opts.browser) {
|
|
1125
|
+
openBrowser(url);
|
|
1126
|
+
info(" (Browser opened automatically)");
|
|
1127
|
+
info("");
|
|
1128
|
+
}
|
|
1129
|
+
info("Waiting for you to complete login in the browser...");
|
|
1130
|
+
let interval = device.interval * 1e3;
|
|
1131
|
+
const deadline = Date.now() + device.expiresIn * 1e3;
|
|
1132
|
+
while (Date.now() < deadline) {
|
|
1133
|
+
await sleep(interval);
|
|
1134
|
+
const tokenData = await graphqlUnauthenticated(
|
|
1135
|
+
DeviceToken,
|
|
1136
|
+
{ input: { deviceCode: device.deviceCode } },
|
|
1137
|
+
opts.endpoint
|
|
1138
|
+
);
|
|
1139
|
+
const token = tokenData.deviceToken;
|
|
1140
|
+
if (!token) {
|
|
1141
|
+
error("Token exchange failed \u2014 the server returned an empty response.");
|
|
1142
|
+
hint("Try running `sl login` again.");
|
|
1143
|
+
process.exit(2);
|
|
1144
|
+
}
|
|
1145
|
+
if (token.error === "authorization_pending") {
|
|
1146
|
+
continue;
|
|
1147
|
+
}
|
|
1148
|
+
if (token.error === "slow_down") {
|
|
1149
|
+
interval += 5e3;
|
|
1150
|
+
continue;
|
|
1151
|
+
}
|
|
1152
|
+
if (token.error === "expired_token") {
|
|
1153
|
+
error("The login code expired before you completed authentication.");
|
|
1154
|
+
hint("Run `sl login` to generate a new code.");
|
|
1155
|
+
process.exit(2);
|
|
1156
|
+
}
|
|
1157
|
+
if (token.error === "access_denied") {
|
|
1158
|
+
error("Access was denied during authentication.");
|
|
1159
|
+
hint("Make sure you approved the request in the browser.");
|
|
1160
|
+
hint("If you denied it by mistake, run `sl login` to try again.");
|
|
1161
|
+
process.exit(2);
|
|
1162
|
+
}
|
|
1163
|
+
if (token.error) {
|
|
1164
|
+
error(`Authentication failed (${token.error}).`);
|
|
1165
|
+
hint("Run `sl login` to try again.");
|
|
1166
|
+
process.exit(2);
|
|
1167
|
+
}
|
|
1168
|
+
if (token.accessToken && token.refreshToken && token.idToken && token.expiresIn) {
|
|
1169
|
+
saveCredentials({
|
|
1170
|
+
accessToken: token.accessToken,
|
|
1171
|
+
refreshToken: token.refreshToken,
|
|
1172
|
+
idToken: token.idToken,
|
|
1173
|
+
expiresAt: Math.floor(Date.now() / 1e3) + token.expiresIn
|
|
1174
|
+
});
|
|
1175
|
+
success("Logged in successfully.");
|
|
1176
|
+
await setupUserContext(opts.endpoint);
|
|
1177
|
+
return;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
error("Authentication timed out \u2014 no response from the browser.");
|
|
1181
|
+
hint("Run `sl login` to start a new session.");
|
|
1182
|
+
process.exit(2);
|
|
1183
|
+
});
|
|
1184
|
+
|
|
1185
|
+
// src/commands/logout.ts
|
|
1186
|
+
import { Command as Command4 } from "commander";
|
|
1187
|
+
var logoutCommand = new Command4("logout").summary("Log out and remove stored credentials").description(
|
|
1188
|
+
"Log out and remove stored credentials\n\nDeletes the saved tokens from ~/.sortlist/credentials.json and\nopens the Auth0 logout URL in your browser so the next `sl login`\ndoesn't silently reuse the previous account.\n\nExamples:\n sl logout Clear credentials and log out of Auth0\n sl logout --no-browser Only clear local credentials"
|
|
1189
|
+
).option("--no-browser", "Skip opening the Auth0 logout URL in a browser").action(async function() {
|
|
1190
|
+
const opts = this.optsWithGlobals();
|
|
1191
|
+
clearCredentials();
|
|
1192
|
+
clearIdentity();
|
|
1193
|
+
success("Logged out \u2014 credentials removed.");
|
|
1194
|
+
if (!opts.browser) {
|
|
1195
|
+
hint("Run `sl login` to authenticate again.");
|
|
1196
|
+
return;
|
|
1197
|
+
}
|
|
1198
|
+
try {
|
|
1199
|
+
const data = await graphqlUnauthenticated(LogoutUrl, {}, opts.endpoint);
|
|
1200
|
+
if (data.logoutUrl) {
|
|
1201
|
+
openBrowser(data.logoutUrl);
|
|
1202
|
+
info("Opened Auth0 logout in your browser.");
|
|
1203
|
+
}
|
|
1204
|
+
} catch {
|
|
1205
|
+
warn("Could not fetch the Auth0 logout URL \u2014 skipped browser logout.");
|
|
1206
|
+
}
|
|
1207
|
+
hint("Run `sl login` to authenticate again.");
|
|
1208
|
+
});
|
|
1209
|
+
|
|
1210
|
+
// src/commands/token.ts
|
|
1211
|
+
import { Command as Command5 } from "commander";
|
|
1212
|
+
var tokenCommand = new Command5("token").summary("Print your current access token to stdout").description(
|
|
1213
|
+
'Print your current access token to stdout\n\nUseful for piping into other tools or scripts.\n\nExamples:\n sl token Print the token\n curl -H "Authorization: Bearer $(sl token)" ...'
|
|
1214
|
+
).action(() => {
|
|
1215
|
+
const creds = ensureAuthenticated();
|
|
1216
|
+
if (isExpired(creds)) {
|
|
1217
|
+
error("Your access token has expired.");
|
|
1218
|
+
hint("Run `sl login` to re-authenticate.");
|
|
1219
|
+
process.exit(2);
|
|
1220
|
+
}
|
|
1221
|
+
process.stdout.write(creds.accessToken);
|
|
1222
|
+
});
|
|
1223
|
+
|
|
1224
|
+
// src/commands/whoami.ts
|
|
1225
|
+
import { Command as Command6 } from "commander";
|
|
1226
|
+
var whoamiCommand = new Command6("whoami").summary("Show who you're currently logged in as").description(
|
|
1227
|
+
"Show who you're currently logged in as\n\nDisplays your name and email. Use --json for machine-readable output.\n\nExamples:\n sl whoami Show your identity\n sl whoami --json Output full user object as JSON"
|
|
1228
|
+
).action(async function() {
|
|
1229
|
+
const opts = this.optsWithGlobals();
|
|
1230
|
+
let data;
|
|
1231
|
+
try {
|
|
1232
|
+
data = await graphql(Me, void 0, {
|
|
1233
|
+
endpoint: opts.endpoint,
|
|
1234
|
+
throwOnError: true
|
|
1235
|
+
});
|
|
1236
|
+
} catch (err) {
|
|
1237
|
+
if (err instanceof GraphQLRequestError) {
|
|
1238
|
+
error("Could not verify your identity \u2014 the API returned an error:");
|
|
1239
|
+
const messages = err.graphqlErrors?.map((e) => e.message) ?? [err.message];
|
|
1240
|
+
for (const message of messages) info(` ${message}`);
|
|
1241
|
+
hint("This is a server-side or authorization error, not necessarily an expired session.");
|
|
1242
|
+
hint("Retry in a moment; if it persists, re-run `sl login` or report it.");
|
|
1243
|
+
process.exit(1);
|
|
1244
|
+
}
|
|
1245
|
+
throw err;
|
|
1246
|
+
}
|
|
1247
|
+
const user = data.me;
|
|
1248
|
+
if (!user) {
|
|
1249
|
+
error("The API did not return your user identity.");
|
|
1250
|
+
hint("This is usually a temporary backend issue rather than an expired session.");
|
|
1251
|
+
hint("Retry in a moment; if it persists, re-run `sl login` or report it.");
|
|
1252
|
+
process.exit(1);
|
|
1253
|
+
}
|
|
1254
|
+
if (isJsonMode(opts)) {
|
|
1255
|
+
printJson(user);
|
|
1256
|
+
return;
|
|
1257
|
+
}
|
|
1258
|
+
info(`${user.firstName} ${user.lastName} <${user.email}> (sub: ${user.sub})`);
|
|
1259
|
+
});
|
|
1260
|
+
|
|
1261
|
+
// src/graphql/introspection.ts
|
|
1262
|
+
import { createHash } from "crypto";
|
|
1263
|
+
import fs5 from "fs";
|
|
1264
|
+
import os3 from "os";
|
|
1265
|
+
import path5 from "path";
|
|
1266
|
+
import { buildClientSchema, getIntrospectionQuery } from "graphql";
|
|
1267
|
+
var CACHE_DIR = path5.join(os3.homedir(), ".sortlist");
|
|
1268
|
+
var CACHE_PATH = path5.join(CACHE_DIR, "schema.json");
|
|
1269
|
+
var CACHE_TTL_MS = 60 * 60 * 1e3;
|
|
1270
|
+
var cached = null;
|
|
1271
|
+
function tokenFingerprint(token) {
|
|
1272
|
+
if (!token) return "anonymous";
|
|
1273
|
+
return createHash("sha256").update(token).digest("hex").slice(0, 16);
|
|
1274
|
+
}
|
|
1275
|
+
function readCache(endpoint, token) {
|
|
1276
|
+
try {
|
|
1277
|
+
const text = fs5.readFileSync(CACHE_PATH, "utf-8");
|
|
1278
|
+
const envelope = JSON.parse(text);
|
|
1279
|
+
if (envelope.endpoint !== endpoint) return null;
|
|
1280
|
+
if (envelope.tokenFingerprint !== tokenFingerprint(token)) return null;
|
|
1281
|
+
if (Date.now() - envelope.fetchedAt > CACHE_TTL_MS) return null;
|
|
1282
|
+
if (!envelope.raw) return null;
|
|
1283
|
+
return { introspection: envelope.introspection, raw: envelope.raw };
|
|
1284
|
+
} catch {
|
|
1285
|
+
return null;
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
function writeCache(endpoint, token, introspection, raw) {
|
|
1289
|
+
try {
|
|
1290
|
+
if (!fs5.existsSync(CACHE_DIR)) {
|
|
1291
|
+
fs5.mkdirSync(CACHE_DIR, { recursive: true });
|
|
1292
|
+
}
|
|
1293
|
+
const envelope = {
|
|
1294
|
+
endpoint,
|
|
1295
|
+
fetchedAt: Date.now(),
|
|
1296
|
+
tokenFingerprint: tokenFingerprint(token),
|
|
1297
|
+
introspection,
|
|
1298
|
+
raw
|
|
1299
|
+
};
|
|
1300
|
+
fs5.writeFileSync(CACHE_PATH, JSON.stringify(envelope));
|
|
1301
|
+
} catch {
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
async function fetchIntrospection(endpoint, token) {
|
|
1305
|
+
const headers = {
|
|
1306
|
+
"Content-Type": "application/json",
|
|
1307
|
+
"X-API-Client": "sl-cli"
|
|
1308
|
+
};
|
|
1309
|
+
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
1310
|
+
const res = await fetch(endpoint, {
|
|
1311
|
+
method: "POST",
|
|
1312
|
+
headers,
|
|
1313
|
+
body: JSON.stringify({ query: getIntrospectionQuery() })
|
|
1314
|
+
});
|
|
1315
|
+
if (!res.ok) {
|
|
1316
|
+
throw new Error(`Introspection failed: HTTP ${res.status} ${res.statusText}`);
|
|
1317
|
+
}
|
|
1318
|
+
const json = await res.json();
|
|
1319
|
+
if (json.errors?.length) {
|
|
1320
|
+
throw new Error(`Introspection errors: ${json.errors.map((e) => e.message).join(", ")}`);
|
|
1321
|
+
}
|
|
1322
|
+
if (!json.data) {
|
|
1323
|
+
throw new Error("Introspection returned no data");
|
|
1324
|
+
}
|
|
1325
|
+
return { introspection: json.data, raw: json.data };
|
|
1326
|
+
}
|
|
1327
|
+
function parseIntrospection(raw) {
|
|
1328
|
+
const fieldServices = /* @__PURE__ */ new Map();
|
|
1329
|
+
const services = /* @__PURE__ */ new Set();
|
|
1330
|
+
for (const type of raw.__schema.types ?? []) {
|
|
1331
|
+
if (!type.fields?.length) continue;
|
|
1332
|
+
let fieldMap = null;
|
|
1333
|
+
for (const field of type.fields) {
|
|
1334
|
+
const directive = field.appliedDirectives?.find((d) => d.name === "join__field");
|
|
1335
|
+
if (!directive) continue;
|
|
1336
|
+
const graphArg = directive.args.find((a) => a.name === "graph");
|
|
1337
|
+
if (!graphArg || typeof graphArg.value !== "string") continue;
|
|
1338
|
+
services.add(graphArg.value);
|
|
1339
|
+
if (!fieldMap) fieldMap = /* @__PURE__ */ new Map();
|
|
1340
|
+
fieldMap.set(field.name, graphArg.value);
|
|
1341
|
+
}
|
|
1342
|
+
if (fieldMap) fieldServices.set(type.name, fieldMap);
|
|
1343
|
+
}
|
|
1344
|
+
return { fieldServices, services };
|
|
1345
|
+
}
|
|
1346
|
+
function currentAccessToken() {
|
|
1347
|
+
return loadCredentials()?.accessToken ?? null;
|
|
1348
|
+
}
|
|
1349
|
+
async function getIntrospectedSchema(endpointOverride2) {
|
|
1350
|
+
if (cached) return cached;
|
|
1351
|
+
const endpoint = getEndpoint(endpointOverride2);
|
|
1352
|
+
const token = currentAccessToken();
|
|
1353
|
+
const fromCache = readCache(endpoint, token);
|
|
1354
|
+
if (fromCache) {
|
|
1355
|
+
const { fieldServices: fieldServices2, services: services2 } = parseIntrospection(fromCache.raw);
|
|
1356
|
+
cached = {
|
|
1357
|
+
schema: buildClientSchema(fromCache.introspection),
|
|
1358
|
+
fieldServices: fieldServices2,
|
|
1359
|
+
services: services2
|
|
1360
|
+
};
|
|
1361
|
+
return cached;
|
|
1362
|
+
}
|
|
1363
|
+
const { introspection, raw } = await fetchIntrospection(endpoint, token);
|
|
1364
|
+
writeCache(endpoint, token, introspection, raw);
|
|
1365
|
+
const { fieldServices, services } = parseIntrospection(raw);
|
|
1366
|
+
cached = {
|
|
1367
|
+
schema: buildClientSchema(introspection),
|
|
1368
|
+
fieldServices,
|
|
1369
|
+
services
|
|
1370
|
+
};
|
|
1371
|
+
return cached;
|
|
1372
|
+
}
|
|
1373
|
+
async function refreshSchema(endpointOverride2) {
|
|
1374
|
+
cached = null;
|
|
1375
|
+
try {
|
|
1376
|
+
fs5.unlinkSync(CACHE_PATH);
|
|
1377
|
+
} catch {
|
|
1378
|
+
}
|
|
1379
|
+
const endpoint = getEndpoint(endpointOverride2);
|
|
1380
|
+
const token = currentAccessToken();
|
|
1381
|
+
const { introspection, raw } = await fetchIntrospection(endpoint, token);
|
|
1382
|
+
writeCache(endpoint, token, introspection, raw);
|
|
1383
|
+
const { fieldServices, services } = parseIntrospection(raw);
|
|
1384
|
+
cached = {
|
|
1385
|
+
schema: buildClientSchema(introspection),
|
|
1386
|
+
fieldServices,
|
|
1387
|
+
services
|
|
1388
|
+
};
|
|
1389
|
+
return cached;
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
// src/lib/version-check.ts
|
|
1393
|
+
import { execFileSync } from "child_process";
|
|
1394
|
+
var PACKAGE_NAME = "@sortlist/cli";
|
|
1395
|
+
function getCurrentVersion() {
|
|
1396
|
+
return pkg.version;
|
|
1397
|
+
}
|
|
1398
|
+
async function fetchLatestVersion() {
|
|
1399
|
+
try {
|
|
1400
|
+
const controller = new AbortController();
|
|
1401
|
+
const timeout = setTimeout(() => controller.abort(), 3e3);
|
|
1402
|
+
const res = await fetch(`https://registry.npmjs.org/${encodeURIComponent(PACKAGE_NAME)}/latest`, {
|
|
1403
|
+
signal: controller.signal
|
|
1404
|
+
});
|
|
1405
|
+
clearTimeout(timeout);
|
|
1406
|
+
if (!res.ok) return null;
|
|
1407
|
+
const data = await res.json();
|
|
1408
|
+
return data.version;
|
|
1409
|
+
} catch {
|
|
1410
|
+
return null;
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
function parseSemver(version) {
|
|
1414
|
+
const [major, minor, patch] = version.split(".").map(Number);
|
|
1415
|
+
return [major ?? 0, minor ?? 0, patch ?? 0];
|
|
1416
|
+
}
|
|
1417
|
+
function autoUpdate(current, latest) {
|
|
1418
|
+
info(`Updating ${PACKAGE_NAME}: ${current} \u2192 ${latest}...`);
|
|
1419
|
+
try {
|
|
1420
|
+
const prefix = execFileSync("npm", ["prefix", "-g"], { stdio: "pipe", encoding: "utf-8" }).trim();
|
|
1421
|
+
const lastSlash = PACKAGE_NAME.lastIndexOf("/");
|
|
1422
|
+
const scope = lastSlash === -1 ? "" : `${PACKAGE_NAME.slice(0, lastSlash)}/`;
|
|
1423
|
+
const name = lastSlash === -1 ? PACKAGE_NAME : PACKAGE_NAME.slice(lastSlash + 1);
|
|
1424
|
+
const staleDir = `${prefix}/lib/node_modules/${scope}.${name}-`;
|
|
1425
|
+
execFileSync("sh", ["-c", `rm -rf "${staleDir}"* 2>/dev/null || true`], { stdio: "pipe" });
|
|
1426
|
+
execFileSync("npm", ["install", "-g", "--prefer-online", `${PACKAGE_NAME}@${latest}`], {
|
|
1427
|
+
stdio: "pipe"
|
|
1428
|
+
});
|
|
1429
|
+
success(`Updated to ${latest}. Restart \`sl\` to use the new version.`);
|
|
1430
|
+
} catch (err) {
|
|
1431
|
+
const stderr = err && typeof err === "object" && "stderr" in err ? String(err.stderr).trim() : "";
|
|
1432
|
+
const detail = stderr ? ` (${stderr.split("\n")[0]})` : "";
|
|
1433
|
+
warn(`Auto-update failed${detail}.`);
|
|
1434
|
+
hint(`Run \`npm i -g ${PACKAGE_NAME}\` to update manually.`);
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
async function checkForUpdates() {
|
|
1438
|
+
if (isLocalDev) return;
|
|
1439
|
+
const current = getCurrentVersion();
|
|
1440
|
+
const latest = await fetchLatestVersion();
|
|
1441
|
+
if (!latest || latest === current) return;
|
|
1442
|
+
const [curMajor] = parseSemver(current);
|
|
1443
|
+
const [latMajor] = parseSemver(latest);
|
|
1444
|
+
if (latMajor > curMajor) {
|
|
1445
|
+
error(`Breaking update: ${current} \u2192 ${latest}`);
|
|
1446
|
+
info("");
|
|
1447
|
+
info(" Your CLI is incompatible with the current API.");
|
|
1448
|
+
info(" Update before continuing:");
|
|
1449
|
+
info("");
|
|
1450
|
+
info(` npm i -g ${PACKAGE_NAME}`);
|
|
1451
|
+
info("");
|
|
1452
|
+
process.exit(1);
|
|
1453
|
+
}
|
|
1454
|
+
autoUpdate(current, latest);
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
// src/index.ts
|
|
1458
|
+
initSentry();
|
|
1459
|
+
var useColor2 = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
1460
|
+
var ansi3 = {
|
|
1461
|
+
reset: "\x1B[0m",
|
|
1462
|
+
bold: "\x1B[1m",
|
|
1463
|
+
dim: "\x1B[2m",
|
|
1464
|
+
cyan: "\x1B[36m",
|
|
1465
|
+
yellow: "\x1B[33m",
|
|
1466
|
+
green: "\x1B[32m"
|
|
1467
|
+
};
|
|
1468
|
+
function colorizeHelp(text) {
|
|
1469
|
+
if (!useColor2) return text;
|
|
1470
|
+
return text.replace(
|
|
1471
|
+
/^(Usage|Options|Commands|Arguments|Quick start|Services|Examples|Queries|Mutations):(.*)$/gm,
|
|
1472
|
+
`${ansi3.cyan}${ansi3.bold}$1:$2${ansi3.reset}`
|
|
1473
|
+
);
|
|
1474
|
+
}
|
|
1475
|
+
var colorOutput = {
|
|
1476
|
+
writeOut: (str) => process.stdout.write(colorizeHelp(str)),
|
|
1477
|
+
writeErr: (str) => process.stderr.write(colorizeHelp(str))
|
|
1478
|
+
};
|
|
1479
|
+
function applyColorToAllCommands(cmd) {
|
|
1480
|
+
cmd.configureOutput(colorOutput);
|
|
1481
|
+
for (const sub of cmd.commands) {
|
|
1482
|
+
applyColorToAllCommands(sub);
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
var BASE_DESCRIPTION = "Sortlist CLI \u2014 query and manage the Sortlist platform from your terminal\n\nQuick start:\n sl login Authenticate with your Sortlist account\n sl whoami Check who you're logged in as";
|
|
1486
|
+
function buildRootDescription(services) {
|
|
1487
|
+
const parts = [BASE_DESCRIPTION];
|
|
1488
|
+
if (services.size > 0) {
|
|
1489
|
+
const entries = [...services.entries()];
|
|
1490
|
+
const labels = entries.map(([name]) => `sl ${name} <operation>`);
|
|
1491
|
+
const pad = Math.max(...labels.map((l) => l.length));
|
|
1492
|
+
parts.push(
|
|
1493
|
+
"Services:\n" + entries.map(([name, info2], i) => ` ${labels[i].padEnd(pad)} ${info2.description}`).join("\n")
|
|
1494
|
+
);
|
|
1495
|
+
const examples = [];
|
|
1496
|
+
for (const [name, info2] of entries) {
|
|
1497
|
+
if (info2.exampleQuery) examples.push(` sl ${name} ${info2.exampleQuery}`);
|
|
1498
|
+
if (examples.length >= 2) break;
|
|
1499
|
+
}
|
|
1500
|
+
examples.push(" sl config show View current endpoint and agency context");
|
|
1501
|
+
parts.push("Examples:\n" + examples.join("\n"));
|
|
1502
|
+
}
|
|
1503
|
+
return parts.join("\n\n");
|
|
1504
|
+
}
|
|
1505
|
+
var program = new Command7().name("sl").configureOutput({
|
|
1506
|
+
writeOut: (str) => process.stdout.write(colorizeHelp(str)),
|
|
1507
|
+
writeErr: (str) => process.stderr.write(colorizeHelp(str))
|
|
1508
|
+
}).description(BASE_DESCRIPTION).version(pkg.version).option("--endpoint <url>", "Override the federation endpoint URL").option("--json", "Output as JSON (auto-enabled when stdout is not a TTY)").option("--no-color", "Disable colored output");
|
|
1509
|
+
program.addCommand(loginCommand);
|
|
1510
|
+
program.addCommand(logoutCommand);
|
|
1511
|
+
program.addCommand(whoamiCommand);
|
|
1512
|
+
program.addCommand(tokenCommand);
|
|
1513
|
+
program.addCommand(configCommand);
|
|
1514
|
+
var schemaCommand = new Command7("schema").description("Manage the cached GraphQL schema");
|
|
1515
|
+
schemaCommand.command("refresh").description("Force-refresh the cached schema from the federation endpoint").action(async function() {
|
|
1516
|
+
const opts = this.optsWithGlobals();
|
|
1517
|
+
try {
|
|
1518
|
+
await refreshSchema(opts.endpoint);
|
|
1519
|
+
info("Schema refreshed successfully.");
|
|
1520
|
+
} catch (err) {
|
|
1521
|
+
error(`Failed to refresh schema: ${err.message}`);
|
|
1522
|
+
hint("Check your network connection and endpoint: sl config show");
|
|
1523
|
+
process.exit(1);
|
|
1524
|
+
}
|
|
1525
|
+
});
|
|
1526
|
+
schemaCommand.command("inspect <type>").description("Show the fields/values of a schema type (e.g. an input filter or enum)").action(async function(typeName) {
|
|
1527
|
+
const opts = this.optsWithGlobals();
|
|
1528
|
+
try {
|
|
1529
|
+
const { schema } = await getIntrospectedSchema(opts.endpoint);
|
|
1530
|
+
const formatted = formatTypeInspection(schema, typeName);
|
|
1531
|
+
if (!formatted) {
|
|
1532
|
+
error(`No type named "${typeName}" in the schema.`);
|
|
1533
|
+
hint("Type names are case-sensitive, e.g. `sl schema inspect OrganizationFilterInput`.");
|
|
1534
|
+
hint("Find argument types in any command\u2019s --help output.");
|
|
1535
|
+
process.exit(1);
|
|
1536
|
+
}
|
|
1537
|
+
info(formatted);
|
|
1538
|
+
} catch (err) {
|
|
1539
|
+
error(`Could not read the schema: ${err.message}`);
|
|
1540
|
+
hint("Check your network connection and endpoint: sl config show");
|
|
1541
|
+
process.exit(1);
|
|
1542
|
+
}
|
|
1543
|
+
});
|
|
1544
|
+
program.addCommand(schemaCommand);
|
|
1545
|
+
var endpointIdx = process.argv.indexOf("--endpoint");
|
|
1546
|
+
var endpointOverride = endpointIdx !== -1 ? process.argv[endpointIdx + 1] : void 0;
|
|
1547
|
+
try {
|
|
1548
|
+
const { schema, fieldServices } = await getIntrospectedSchema(endpointOverride);
|
|
1549
|
+
const serviceCommands = buildServiceCommands(schema, fieldServices);
|
|
1550
|
+
const servicesForHelp = /* @__PURE__ */ new Map();
|
|
1551
|
+
for (const [name, entry] of serviceCommands) {
|
|
1552
|
+
const cmd = entry.command;
|
|
1553
|
+
program.addCommand(cmd);
|
|
1554
|
+
servicesForHelp.set(name, {
|
|
1555
|
+
exampleQuery: entry.exampleQuery,
|
|
1556
|
+
description: cmd.description()
|
|
1557
|
+
});
|
|
1558
|
+
}
|
|
1559
|
+
program.description(buildRootDescription(servicesForHelp));
|
|
1560
|
+
} catch (err) {
|
|
1561
|
+
const message = err.message;
|
|
1562
|
+
if (!process.argv.some((a) => ["login", "logout", "config", "token", "whoami", "schema"].includes(a))) {
|
|
1563
|
+
error(`Could not fetch schema: ${message}`);
|
|
1564
|
+
hint("Check your network connection and endpoint: sl config show");
|
|
1565
|
+
hint("You can still use: sl login, sl config, sl schema refresh");
|
|
1566
|
+
process.exit(1);
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
applyColorToAllCommands(program);
|
|
1570
|
+
await checkForUpdates();
|
|
1571
|
+
try {
|
|
1572
|
+
await program.parseAsync(process.argv);
|
|
1573
|
+
} catch (err) {
|
|
1574
|
+
captureException2(err);
|
|
1575
|
+
await flushSentry();
|
|
1576
|
+
throw err;
|
|
1577
|
+
}
|
|
1578
|
+
await flushSentry();
|
|
1579
|
+
//# sourceMappingURL=index.js.map
|