@curviate/cli 0.30.0 → 0.31.1
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/CHANGELOG.md +153 -0
- package/README.md +65 -12
- package/dist/{account-5KGM6EPR.js → account-DZRX4YOK.js} +28 -12
- package/dist/{chunk-GHT2DLZR.js → chunk-A73TUZBK.js} +4 -4
- package/dist/{chunk-LCIUD7S2.js → chunk-JRKM4OV2.js} +1 -1
- package/dist/{chunk-5KANHEBN.js → chunk-KQXYEQAD.js} +0 -56
- package/dist/{chunk-63X3VI3T.js → chunk-LKF5MZIP.js} +1 -1
- package/dist/chunk-PKSKQ3LN.js +68 -0
- package/dist/{chunk-AHYUM2XQ.js → chunk-SKJNLN37.js} +12 -2
- package/dist/chunk-TD2ZIXFR.js +67 -0
- package/dist/{chunk-KTY7R27U.js → chunk-TQJ77SL4.js} +3 -1
- package/dist/chunk-X3YWBMBC.js +151 -0
- package/dist/{chunk-TAOXJNQN.js → chunk-Y3H55OSY.js} +14 -12
- package/dist/cli.js +36 -22
- package/dist/{comment-BLG4WHST.js → comment-6JI4Q6QY.js} +17 -14
- package/dist/{company-ZT65QZ6F.js → company-RLU5SHUO.js} +25 -22
- package/dist/{config-5HB2J3RY.js → config-FUHT23SX.js} +2 -2
- package/dist/{connect-57AUN33D.js → connect-63NUITEZ.js} +22 -19
- package/dist/doctor-KSLZNAKH.js +198 -0
- package/dist/{exit-codes-U5CHA6FT.js → exit-codes-RUKZC4WV.js} +1 -1
- package/dist/{feed-3AWI2URQ.js → feed-PAWXR56T.js} +12 -9
- package/dist/{group-DYC2NX5M.js → group-ZIIWI7JV.js} +12 -9
- package/dist/{inbox-ZRFIFOEP.js → inbox-GIPLWRHQ.js} +14 -11
- package/dist/{inboxes-XQ2B6X3Q.js → inboxes-ECGEMDH7.js} +12 -9
- package/dist/{job-NUT4QMH2.js → job-WPWIAVQY.js} +14 -11
- package/dist/{login-KNNEN4HP.js → login-3OAUY7TG.js} +3 -3
- package/dist/{message-KMNRUD4H.js → message-JQL2XABC.js} +9 -7
- package/dist/{notification-LEM57IBY.js → notification-URSGC7OR.js} +14 -11
- package/dist/{post-FXAANNUB.js → post-2HI6KL73.js} +17 -14
- package/dist/{profile-72V55PZM.js → profile-4BXLUYMH.js} +25 -22
- package/dist/{recruiter-JUNB5AUR.js → recruiter-OUXQ5XYU.js} +24 -18
- package/dist/{sales-nav-BALVVD35.js → sales-nav-MJAMCSBO.js} +22 -16
- package/dist/{search-QCXTK33P.js → search-M3R35BIB.js} +21 -18
- package/dist/setup-YV5PVIU5.js +419 -0
- package/dist/{webhook-D4QRWF7W.js → webhook-3TEYA3B2.js} +10 -7
- package/package.json +2 -2
- package/dist/chunk-2OG6M6ME.js +0 -89
- package/dist/{chunk-H4KV7MIN.js → chunk-YLSJ4HKU.js} +1 -1
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
readlineSync
|
|
4
|
+
} from "./chunk-YLSJ4HKU.js";
|
|
5
|
+
import {
|
|
6
|
+
createClient,
|
|
7
|
+
resolveEffectiveConfig
|
|
8
|
+
} from "./chunk-TD2ZIXFR.js";
|
|
9
|
+
import "./chunk-PKSKQ3LN.js";
|
|
10
|
+
import {
|
|
11
|
+
getConfigPath,
|
|
12
|
+
writeProfile
|
|
13
|
+
} from "./chunk-TQJ77SL4.js";
|
|
14
|
+
import {
|
|
15
|
+
GLOBAL_FLAGS,
|
|
16
|
+
defaultReadStdin,
|
|
17
|
+
isStdinToken,
|
|
18
|
+
resolveTextOrStdin
|
|
19
|
+
} from "./chunk-SKJNLN37.js";
|
|
20
|
+
|
|
21
|
+
// src/commands/setup.ts
|
|
22
|
+
import { defineCommand } from "citty";
|
|
23
|
+
import { createDecipheriv, createECDH, hkdfSync, randomBytes } from "crypto";
|
|
24
|
+
import { chmod, mkdir, readFile, rm, writeFile } from "fs/promises";
|
|
25
|
+
import { dirname, join } from "path";
|
|
26
|
+
var CODE_ALPHABET = "BCDFGHJKLMNPQRSTVWXZ";
|
|
27
|
+
function normaliseCode(raw) {
|
|
28
|
+
let out = "";
|
|
29
|
+
const upper = raw.toUpperCase();
|
|
30
|
+
for (const char of upper) if (CODE_ALPHABET.includes(char)) out += char;
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
var APP_URL_ENV = "CURVIATE_APP_URL";
|
|
34
|
+
function appRoot(baseUrl, override) {
|
|
35
|
+
if (override !== void 0 && override !== "") {
|
|
36
|
+
const explicit = new URL(override);
|
|
37
|
+
return `${explicit.origin}${explicit.pathname.replace(/\/$/, "")}`;
|
|
38
|
+
}
|
|
39
|
+
const parsed = new URL(baseUrl);
|
|
40
|
+
const labels = parsed.hostname.split(".");
|
|
41
|
+
if (labels[0] === "api" && labels.length > 1) {
|
|
42
|
+
labels[0] = "app";
|
|
43
|
+
return `${parsed.protocol}//${labels.join(".")}${parsed.port ? `:${parsed.port}` : ""}`;
|
|
44
|
+
}
|
|
45
|
+
return `${parsed.origin}${parsed.pathname.replace(/\/?api\/?$/, "").replace(/\/$/, "")}`;
|
|
46
|
+
}
|
|
47
|
+
function authorizeUrl(baseUrl, sessionId, publicKey, appUrlOverride) {
|
|
48
|
+
const url = new URL(`${appRoot(baseUrl, appUrlOverride)}/cli`);
|
|
49
|
+
url.searchParams.set("sid", sessionId);
|
|
50
|
+
url.searchParams.set("pk", publicKey);
|
|
51
|
+
return url.toString();
|
|
52
|
+
}
|
|
53
|
+
function exchangeUrl(baseUrl) {
|
|
54
|
+
return `${baseUrl.replace(/\/$/, "")}/api/auth/cli/exchange`;
|
|
55
|
+
}
|
|
56
|
+
var SESSION_ID_BYTES = 18;
|
|
57
|
+
var HKDF_INFO = "curviate-cli-setup-v1";
|
|
58
|
+
var SEAL_ALG = "ECDH-P256-HKDF-SHA256-A256GCM";
|
|
59
|
+
var GCM_TAG_BYTES = 16;
|
|
60
|
+
function generateSessionMaterial() {
|
|
61
|
+
const ecdh = createECDH("prime256v1");
|
|
62
|
+
ecdh.generateKeys();
|
|
63
|
+
return {
|
|
64
|
+
sessionId: randomBytes(SESSION_ID_BYTES).toString("base64url"),
|
|
65
|
+
publicKey: ecdh.getPublicKey().toString("base64url"),
|
|
66
|
+
privateKey: ecdh.getPrivateKey().toString("base64url")
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function unsealApiKey(sealed, privateKey) {
|
|
70
|
+
if (sealed.alg !== SEAL_ALG) {
|
|
71
|
+
throw new Error(`Unsupported sealing algorithm "${sealed.alg}".`);
|
|
72
|
+
}
|
|
73
|
+
const ecdh = createECDH("prime256v1");
|
|
74
|
+
ecdh.setPrivateKey(Buffer.from(privateKey, "base64url"));
|
|
75
|
+
const shared = ecdh.computeSecret(Buffer.from(sealed.epk, "base64url"));
|
|
76
|
+
const key = Buffer.from(
|
|
77
|
+
hkdfSync("sha256", shared, Buffer.alloc(0), Buffer.from(HKDF_INFO, "utf8"), 32)
|
|
78
|
+
);
|
|
79
|
+
const blob = Buffer.from(sealed.ciphertext, "base64url");
|
|
80
|
+
if (blob.length <= GCM_TAG_BYTES) throw new Error("Sealed payload is truncated.");
|
|
81
|
+
const body = blob.subarray(0, blob.length - GCM_TAG_BYTES);
|
|
82
|
+
const tag = blob.subarray(blob.length - GCM_TAG_BYTES);
|
|
83
|
+
const decipher = createDecipheriv("aes-256-gcm", key, Buffer.from(sealed.iv, "base64url"));
|
|
84
|
+
decipher.setAuthTag(tag);
|
|
85
|
+
return Buffer.concat([decipher.update(body), decipher.final()]).toString("utf8");
|
|
86
|
+
}
|
|
87
|
+
function resumeStatePath() {
|
|
88
|
+
return join(dirname(getConfigPath()), "setup-session.json");
|
|
89
|
+
}
|
|
90
|
+
async function writeResumeState(state) {
|
|
91
|
+
const path = resumeStatePath();
|
|
92
|
+
await mkdir(dirname(path), { recursive: true, mode: 448 });
|
|
93
|
+
await writeFile(path, JSON.stringify(state) + "\n", { encoding: "utf8", mode: 384 });
|
|
94
|
+
try {
|
|
95
|
+
await chmod(path, 384);
|
|
96
|
+
} catch {
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async function readResumeState() {
|
|
100
|
+
try {
|
|
101
|
+
return JSON.parse(await readFile(resumeStatePath(), "utf8"));
|
|
102
|
+
} catch {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function clearResumeState() {
|
|
107
|
+
await rm(resumeStatePath(), { force: true });
|
|
108
|
+
}
|
|
109
|
+
function envelopeOf(payload) {
|
|
110
|
+
if (typeof payload !== "object" || payload === null) return {};
|
|
111
|
+
const obj = payload;
|
|
112
|
+
const inner = typeof obj["error"] === "object" && obj["error"] !== null ? obj["error"] : obj;
|
|
113
|
+
return {
|
|
114
|
+
code: typeof inner["code"] === "string" ? inner["code"] : void 0,
|
|
115
|
+
message: typeof inner["message"] === "string" ? inner["message"] : void 0
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
async function exchange(baseUrl, sessionId, code, fetchImpl) {
|
|
119
|
+
let response;
|
|
120
|
+
try {
|
|
121
|
+
response = await fetchImpl(exchangeUrl(baseUrl), {
|
|
122
|
+
method: "POST",
|
|
123
|
+
headers: { "content-type": "application/json" },
|
|
124
|
+
body: JSON.stringify({ session_id: sessionId, verification_code: code })
|
|
125
|
+
});
|
|
126
|
+
} catch {
|
|
127
|
+
return {
|
|
128
|
+
ok: false,
|
|
129
|
+
failure: "unreachable",
|
|
130
|
+
message: `Could not reach the API at ${baseUrl}. Check your network, or the base URL if you overrode it, and run \`curviate setup\` again.`
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
let payload = null;
|
|
134
|
+
try {
|
|
135
|
+
payload = await response.json();
|
|
136
|
+
} catch {
|
|
137
|
+
payload = null;
|
|
138
|
+
}
|
|
139
|
+
if (response.ok) {
|
|
140
|
+
const body = payload;
|
|
141
|
+
if (!body || typeof body !== "object" || !body.sealed_key) {
|
|
142
|
+
return { ok: false, failure: "unexpected", message: "The API returned an unreadable response." };
|
|
143
|
+
}
|
|
144
|
+
return { ok: true, body };
|
|
145
|
+
}
|
|
146
|
+
const { code: errorCode, message } = envelopeOf(payload);
|
|
147
|
+
switch (errorCode) {
|
|
148
|
+
case "CLI_SETUP_INVALID_CODE":
|
|
149
|
+
return { ok: false, failure: "invalid_code", message: "That code was not accepted." };
|
|
150
|
+
case "CLI_SETUP_EXPIRED":
|
|
151
|
+
return {
|
|
152
|
+
ok: false,
|
|
153
|
+
failure: "expired",
|
|
154
|
+
message: "That code has expired. A code is good for ten minutes and for five attempts. Run `curviate setup` again to get a fresh one."
|
|
155
|
+
};
|
|
156
|
+
case "CLI_SETUP_NO_API_KEY":
|
|
157
|
+
return {
|
|
158
|
+
ok: false,
|
|
159
|
+
failure: "no_api_key",
|
|
160
|
+
message: message ?? "This workspace has no API key. Create one in the dashboard, then run `curviate setup` again."
|
|
161
|
+
};
|
|
162
|
+
case "PLATFORM_RATE_LIMIT":
|
|
163
|
+
return {
|
|
164
|
+
ok: false,
|
|
165
|
+
failure: "rate_limited",
|
|
166
|
+
message: message ?? "Too many attempts against this endpoint. Wait a moment and try again."
|
|
167
|
+
};
|
|
168
|
+
default:
|
|
169
|
+
return {
|
|
170
|
+
ok: false,
|
|
171
|
+
failure: "unexpected",
|
|
172
|
+
message: message ?? `The API refused the exchange (HTTP ${response.status}).`
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function exitCodeFor(failure) {
|
|
177
|
+
if (failure === "rate_limited") return 6;
|
|
178
|
+
if (failure === "unreachable") return 7;
|
|
179
|
+
if (failure === "unexpected") return 1;
|
|
180
|
+
return 3;
|
|
181
|
+
}
|
|
182
|
+
function browserAvailable(env, platform) {
|
|
183
|
+
if (env["CI"]) return false;
|
|
184
|
+
if (env["SSH_CONNECTION"] || env["SSH_TTY"] || env["SSH_CLIENT"]) return false;
|
|
185
|
+
if (platform === "linux" && !env["DISPLAY"] && !env["WAYLAND_DISPLAY"]) return false;
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
async function defaultOpen(url) {
|
|
189
|
+
const open = (await import("open")).default;
|
|
190
|
+
return open(url);
|
|
191
|
+
}
|
|
192
|
+
async function defaultVerify(apiKey, baseUrl) {
|
|
193
|
+
await createClient({ apiKey, baseUrl }).accounts.list();
|
|
194
|
+
}
|
|
195
|
+
function resolveSetupIO(io = {}) {
|
|
196
|
+
return {
|
|
197
|
+
stdout: io.stdout ?? { write: (s) => void process.stdout.write(s) },
|
|
198
|
+
stderr: io.stderr ?? { write: (s) => void process.stderr.write(s) },
|
|
199
|
+
isTTY: io.isTTY ?? (process.stdin.isTTY ?? false),
|
|
200
|
+
isOutputTTY: io.isOutputTTY ?? (process.stdout.isTTY ?? false),
|
|
201
|
+
env: io.env ?? process.env,
|
|
202
|
+
platform: io.platform ?? process.platform,
|
|
203
|
+
// The unmasked branch, deliberately: a masked widget swallows bracketed
|
|
204
|
+
// paste, and a pasted code is the whole point of this command.
|
|
205
|
+
prompt: io.prompt ?? ((p) => readlineSync(p, io.stdinStream ? { stdin: io.stdinStream } : {})),
|
|
206
|
+
...io.stdinStream !== void 0 ? { stdinStream: io.stdinStream } : {},
|
|
207
|
+
readStdin: io.readStdin ?? defaultReadStdin,
|
|
208
|
+
open: io.open ?? defaultOpen,
|
|
209
|
+
fetch: io.fetch ?? fetch,
|
|
210
|
+
verify: io.verify ?? defaultVerify,
|
|
211
|
+
generate: io.generate ?? generateSessionMaterial
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
var MAX_ATTEMPTS = 3;
|
|
215
|
+
var NON_TTY_MESSAGE = "error: `curviate setup` needs a terminal to paste the code into.\nhint: set CURVIATE_API_KEY, or pipe an existing key with `curviate login --api-key -`.\n";
|
|
216
|
+
var SECRET_FLAG_WARNING = "Note: a value on the command line is visible to other processes via `ps` and saved in shell history; prefer `--code -` to read it from stdin.\n";
|
|
217
|
+
async function runSetup(args, io) {
|
|
218
|
+
const profileName = args.profile ?? "default";
|
|
219
|
+
const effective = await resolveEffectiveConfig({
|
|
220
|
+
baseUrl: args["base-url"],
|
|
221
|
+
profile: args.profile
|
|
222
|
+
});
|
|
223
|
+
const baseUrl = effective.baseUrl;
|
|
224
|
+
const json = args.json === true || !io.isOutputTTY;
|
|
225
|
+
if (args.code !== void 0) {
|
|
226
|
+
const raw = await resolveTextOrStdin(
|
|
227
|
+
args.code,
|
|
228
|
+
io,
|
|
229
|
+
async () => (await io.readStdin()).trim()
|
|
230
|
+
);
|
|
231
|
+
if (!isStdinToken(args.code)) io.stderr.write(SECRET_FLAG_WARNING);
|
|
232
|
+
const state = await readResumeState();
|
|
233
|
+
if (!state) {
|
|
234
|
+
io.stderr.write(
|
|
235
|
+
"error: no setup is in progress. Run `curviate setup --json` first, open the authorize URL it prints, then pass the code back with `curviate setup --code -`.\n"
|
|
236
|
+
);
|
|
237
|
+
return 2;
|
|
238
|
+
}
|
|
239
|
+
return finishExchange(
|
|
240
|
+
state.baseUrl,
|
|
241
|
+
state,
|
|
242
|
+
normaliseCode(raw),
|
|
243
|
+
state.profile,
|
|
244
|
+
{ json, single: true },
|
|
245
|
+
io
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
const material = io.generate();
|
|
249
|
+
const url = authorizeUrl(
|
|
250
|
+
baseUrl,
|
|
251
|
+
material.sessionId,
|
|
252
|
+
material.publicKey,
|
|
253
|
+
io.env[APP_URL_ENV]
|
|
254
|
+
);
|
|
255
|
+
if (json) {
|
|
256
|
+
await writeResumeState({
|
|
257
|
+
...material,
|
|
258
|
+
baseUrl,
|
|
259
|
+
profile: profileName,
|
|
260
|
+
createdAt: Date.now()
|
|
261
|
+
});
|
|
262
|
+
io.stdout.write(
|
|
263
|
+
JSON.stringify({
|
|
264
|
+
authorize_url: url,
|
|
265
|
+
next_step: "curviate setup --code -",
|
|
266
|
+
instructions: "Open authorize_url in a signed-in browser, press Authorize, then run next_step with the displayed code on stdin."
|
|
267
|
+
}) + "\n"
|
|
268
|
+
);
|
|
269
|
+
return 0;
|
|
270
|
+
}
|
|
271
|
+
io.stdout.write(url + "\n");
|
|
272
|
+
io.stderr.write(
|
|
273
|
+
"Open the link above, press Authorize, and paste the code it shows you.\n"
|
|
274
|
+
);
|
|
275
|
+
if (!io.isTTY) {
|
|
276
|
+
io.stderr.write(NON_TTY_MESSAGE);
|
|
277
|
+
return 2;
|
|
278
|
+
}
|
|
279
|
+
const canOpen = browserAvailable(io.env, io.platform);
|
|
280
|
+
if (args["no-browser"] === true) {
|
|
281
|
+
if (canOpen) {
|
|
282
|
+
io.stderr.write(
|
|
283
|
+
"Not opening a browser because --no-browser was passed, though one appears to be available here.\n"
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
} else if (!canOpen) {
|
|
287
|
+
io.stderr.write(
|
|
288
|
+
"No browser here, so nothing was opened. Open the link on any device you are signed in on.\n"
|
|
289
|
+
);
|
|
290
|
+
} else {
|
|
291
|
+
try {
|
|
292
|
+
await io.open(url);
|
|
293
|
+
} catch {
|
|
294
|
+
io.stderr.write("Could not open a browser. Open the link above by hand.\n");
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
|
|
298
|
+
const label = attempt === 0 ? "Paste the code: " : `Retry (${attempt}/${MAX_ATTEMPTS - 1}): `;
|
|
299
|
+
const typed = normaliseCode(await io.prompt(label));
|
|
300
|
+
const result = await finishExchange(
|
|
301
|
+
baseUrl,
|
|
302
|
+
material,
|
|
303
|
+
typed,
|
|
304
|
+
profileName,
|
|
305
|
+
{ json, single: attempt === MAX_ATTEMPTS - 1 },
|
|
306
|
+
io
|
|
307
|
+
);
|
|
308
|
+
if (result === 0) return 0;
|
|
309
|
+
if (result !== RETRY) return result;
|
|
310
|
+
}
|
|
311
|
+
return 3;
|
|
312
|
+
}
|
|
313
|
+
var RETRY = -1;
|
|
314
|
+
async function finishExchange(baseUrl, material, code, profileName, opts, io) {
|
|
315
|
+
const result = await exchange(baseUrl, material.sessionId, code, io.fetch);
|
|
316
|
+
if (!result.ok) {
|
|
317
|
+
if (result.failure === "invalid_code" && !opts.single) {
|
|
318
|
+
io.stderr.write(result.message + "\n");
|
|
319
|
+
return RETRY;
|
|
320
|
+
}
|
|
321
|
+
if (result.failure === "expired" || result.failure === "invalid_code") {
|
|
322
|
+
await clearResumeState();
|
|
323
|
+
}
|
|
324
|
+
const finalMessage = result.failure === "invalid_code" ? "That code was not accepted. Run `curviate setup` again for a fresh one." : result.message;
|
|
325
|
+
io.stderr.write(`error: ${finalMessage}
|
|
326
|
+
`);
|
|
327
|
+
return exitCodeFor(result.failure);
|
|
328
|
+
}
|
|
329
|
+
let apiKey;
|
|
330
|
+
try {
|
|
331
|
+
apiKey = unsealApiKey(result.body.sealed_key, material.privateKey);
|
|
332
|
+
} catch {
|
|
333
|
+
io.stderr.write(
|
|
334
|
+
"error: the delivered credential could not be opened by this process. Run `curviate setup` again.\n"
|
|
335
|
+
);
|
|
336
|
+
return 1;
|
|
337
|
+
}
|
|
338
|
+
await writeProfile(profileName, {
|
|
339
|
+
apiKey,
|
|
340
|
+
tenant: result.body.tenant_name,
|
|
341
|
+
...result.body.account_id !== void 0 ? { account: result.body.account_id } : {}
|
|
342
|
+
});
|
|
343
|
+
await clearResumeState();
|
|
344
|
+
try {
|
|
345
|
+
await io.verify(apiKey, baseUrl);
|
|
346
|
+
} catch {
|
|
347
|
+
io.stderr.write(
|
|
348
|
+
"error: the credential was saved but a verifying call did not succeed. Run `curviate doctor` for detail.\n"
|
|
349
|
+
);
|
|
350
|
+
return 3;
|
|
351
|
+
}
|
|
352
|
+
const summary = {
|
|
353
|
+
ok: true,
|
|
354
|
+
tenant: result.body.tenant_name,
|
|
355
|
+
profile: profileName,
|
|
356
|
+
...result.body.account_id !== void 0 ? { account_id: result.body.account_id } : {}
|
|
357
|
+
};
|
|
358
|
+
if (opts.json) {
|
|
359
|
+
io.stdout.write(JSON.stringify(summary) + "\n");
|
|
360
|
+
} else {
|
|
361
|
+
io.stderr.write(
|
|
362
|
+
`Authenticated as ${result.body.tenant_name}. Saved to profile "${profileName}".
|
|
363
|
+
`
|
|
364
|
+
);
|
|
365
|
+
if (result.body.account_id !== void 0) {
|
|
366
|
+
io.stderr.write(`Default account set to ${result.body.account_id}.
|
|
367
|
+
`);
|
|
368
|
+
}
|
|
369
|
+
io.stderr.write("Run `curviate doctor` to confirm.\n");
|
|
370
|
+
}
|
|
371
|
+
return 0;
|
|
372
|
+
}
|
|
373
|
+
var setupCommand = defineCommand({
|
|
374
|
+
meta: {
|
|
375
|
+
name: "setup",
|
|
376
|
+
description: "Connect this machine to your workspace: opens the dashboard, takes the code it shows you, and saves an API key."
|
|
377
|
+
},
|
|
378
|
+
args: {
|
|
379
|
+
profile: GLOBAL_FLAGS.profile,
|
|
380
|
+
"base-url": GLOBAL_FLAGS["base-url"],
|
|
381
|
+
json: GLOBAL_FLAGS.json,
|
|
382
|
+
"no-browser": {
|
|
383
|
+
type: "boolean",
|
|
384
|
+
description: "Do not try to open a browser; just print the link.",
|
|
385
|
+
default: false
|
|
386
|
+
},
|
|
387
|
+
code: {
|
|
388
|
+
type: "string",
|
|
389
|
+
stdinArg: true,
|
|
390
|
+
description: 'Verification code from the dashboard. Pass "-" to read it from stdin, which keeps it out of argv, `ps` and shell history.'
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
async run({ args }) {
|
|
394
|
+
const io = resolveSetupIO();
|
|
395
|
+
const code = await runSetup(
|
|
396
|
+
{
|
|
397
|
+
profile: args.profile,
|
|
398
|
+
"base-url": args["base-url"],
|
|
399
|
+
json: args.json,
|
|
400
|
+
"no-browser": args["no-browser"],
|
|
401
|
+
code: args.code
|
|
402
|
+
},
|
|
403
|
+
io
|
|
404
|
+
);
|
|
405
|
+
if (code !== 0) process.exit(code);
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
export {
|
|
409
|
+
APP_URL_ENV,
|
|
410
|
+
authorizeUrl,
|
|
411
|
+
browserAvailable,
|
|
412
|
+
generateSessionMaterial,
|
|
413
|
+
normaliseCode,
|
|
414
|
+
resolveSetupIO,
|
|
415
|
+
resumeStatePath,
|
|
416
|
+
runSetup,
|
|
417
|
+
setupCommand,
|
|
418
|
+
unsealApiKey
|
|
419
|
+
};
|
|
@@ -2,23 +2,26 @@
|
|
|
2
2
|
import {
|
|
3
3
|
pageDelayFromFlags,
|
|
4
4
|
streamAll
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-LKF5MZIP.js";
|
|
6
6
|
import {
|
|
7
7
|
buildPreviewOutput
|
|
8
8
|
} from "./chunk-R3VLWLVV.js";
|
|
9
9
|
import {
|
|
10
|
-
createClient,
|
|
11
10
|
renderError,
|
|
12
11
|
renderSuccess,
|
|
13
|
-
renderUnexpectedError
|
|
12
|
+
renderUnexpectedError
|
|
13
|
+
} from "./chunk-KQXYEQAD.js";
|
|
14
|
+
import {
|
|
15
|
+
createClient,
|
|
14
16
|
resolveEffectiveConfig
|
|
15
|
-
} from "./chunk-
|
|
16
|
-
import "./chunk-
|
|
17
|
+
} from "./chunk-TD2ZIXFR.js";
|
|
18
|
+
import "./chunk-PKSKQ3LN.js";
|
|
19
|
+
import "./chunk-TQJ77SL4.js";
|
|
17
20
|
import {
|
|
18
21
|
GLOBAL_FLAGS,
|
|
19
22
|
defaultReadStdin,
|
|
20
23
|
isStdinToken
|
|
21
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-SKJNLN37.js";
|
|
22
25
|
|
|
23
26
|
// src/commands/webhook.ts
|
|
24
27
|
import { defineCommand } from "citty";
|
|
@@ -51,7 +54,7 @@ function resolveOutputOpts(flags) {
|
|
|
51
54
|
async function handleError(err, outOpts, out) {
|
|
52
55
|
const { CurviateError } = await import("@curviate/sdk");
|
|
53
56
|
if (err instanceof CurviateError) {
|
|
54
|
-
const { getExitCode } = await import("./exit-codes-
|
|
57
|
+
const { getExitCode } = await import("./exit-codes-RUKZC4WV.js");
|
|
55
58
|
renderError(err, outOpts, out);
|
|
56
59
|
process.exit(getExitCode(err.code));
|
|
57
60
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@curviate/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Official command-line interface for the Curviate API.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"clean": "rm -rf dist *.tsbuildinfo"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@curviate/sdk": "0.
|
|
49
|
+
"@curviate/sdk": "0.30.0",
|
|
50
50
|
"citty": "^0.1.6",
|
|
51
51
|
"open": "^10.1.0"
|
|
52
52
|
},
|
package/dist/chunk-2OG6M6ME.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// src/lib/exit-codes.ts
|
|
4
|
-
var EXIT_CODE_MAP = {
|
|
5
|
-
// Auth (3)
|
|
6
|
-
UNAUTHORIZED: 3,
|
|
7
|
-
// Invalid input / usage (2)
|
|
8
|
-
INVALID_REQUEST: 2,
|
|
9
|
-
UNSUPPORTED_MEDIA_TYPE: 2,
|
|
10
|
-
PAYLOAD_TOO_LARGE: 2,
|
|
11
|
-
// 2, found by the SDK-pin gate at the bottom of test/lib/exit-codes.test.ts
|
|
12
|
-
// on its first run. It has been in the SDK's taxonomy and absent from this
|
|
13
|
-
// table, so it fell to the unmapped 1 and read as an internal failure. It is
|
|
14
|
-
// a 422 saying a plain-string search filter matched several LinkedIn
|
|
15
|
-
// taxonomy options: `unresolved[]` names the fields and their candidate ids,
|
|
16
|
-
// it is user_fixable, and it is never retryable AS SENT. Re-send with a
|
|
17
|
-
// chosen id, which is the exit-2 contract exactly.
|
|
18
|
-
FILTER_CANDIDATES_REQUIRED: 2,
|
|
19
|
-
// Not found (4)
|
|
20
|
-
RESOURCE_NOT_FOUND: 4,
|
|
21
|
-
ACCOUNT_NOT_FOUND: 4,
|
|
22
|
-
SUBSCRIPTION_NOT_FOUND: 4,
|
|
23
|
-
SEAT_NOT_FOUND: 4,
|
|
24
|
-
// Tier / entitlement (5)
|
|
25
|
-
TIER_NOT_ACTIVE: 5,
|
|
26
|
-
LINKEDIN_FEATURE_NOT_SUBSCRIBED: 5,
|
|
27
|
-
// Rate-limited (6)
|
|
28
|
-
RATE_LIMIT_ACCOUNT: 6,
|
|
29
|
-
RATE_LIMIT_TENANT: 6,
|
|
30
|
-
PLATFORM_RATE_LIMIT: 6,
|
|
31
|
-
LINKEDIN_RATE_LIMITED: 6,
|
|
32
|
-
RATE_LIMITED: 6,
|
|
33
|
-
// Transient platform (7)
|
|
34
|
-
PLATFORM_ERROR: 7,
|
|
35
|
-
LINKEDIN_SERVICE_UNAVAILABLE: 7,
|
|
36
|
-
// Account / connection state (8)
|
|
37
|
-
ACCOUNT_RESTRICTED: 8,
|
|
38
|
-
RESOURCE_ACCESS_RESTRICTED: 8,
|
|
39
|
-
LINKEDIN_AUTH_FAILED: 8,
|
|
40
|
-
LINKEDIN_SESSION_EVICTED: 8,
|
|
41
|
-
LINKEDIN_COOKIE_INVALID: 8,
|
|
42
|
-
CONNECTION_IN_PROGRESS: 8,
|
|
43
|
-
ACCOUNT_ALREADY_LINKED: 8,
|
|
44
|
-
LINKEDIN_OPERATION_NOT_SUPPORTED: 8,
|
|
45
|
-
CONNECTION_REQUEST_CONFLICT: 8,
|
|
46
|
-
PREMIUM_CONFLICT: 8,
|
|
47
|
-
REAUTH_REQUIRED: 8,
|
|
48
|
-
// Checkpoint flow (9)
|
|
49
|
-
CHECKPOINT_NOT_FOUND: 9,
|
|
50
|
-
CHECKPOINT_EXPIRED: 9,
|
|
51
|
-
CHECKPOINT_INVALID_CODE: 9,
|
|
52
|
-
CHECKPOINT_MAX_ATTEMPTS: 9,
|
|
53
|
-
CHECKPOINT_ALREADY_RESOLVED: 9,
|
|
54
|
-
CHECKPOINT_UNSUPPORTED: 9,
|
|
55
|
-
// Messaging window / recipient (10)
|
|
56
|
-
MESSAGE_WINDOW_EXPIRED: 10,
|
|
57
|
-
RECIPIENT_UNREACHABLE: 10,
|
|
58
|
-
// Billing (11)
|
|
59
|
-
PAYMENT_REQUIRED: 11,
|
|
60
|
-
PAYMENT_FAILED: 11,
|
|
61
|
-
SUBSCRIPTION_BUSY: 11,
|
|
62
|
-
SEAT_CANCELLED: 11,
|
|
63
|
-
// Account-safety budget (13), see the note above for why this is not 6
|
|
64
|
-
BUDGET_EXHAUSTED: 13,
|
|
65
|
-
// Nothing stored (14), A NEW BUCKET, and deliberately not 4.
|
|
66
|
-
// `NOT_STORED` is a 422 answering a `--mode cache_only` read: the resource
|
|
67
|
-
// may exist perfectly well on LinkedIn, and this API simply holds no copy of
|
|
68
|
-
// it, so it is NOT "not found" and re-checking the id is the wrong move. It
|
|
69
|
-
// is not 1 either: nothing failed. It is user_fixable and not retryable AS
|
|
70
|
-
// SENT — the fix is another mode (`refill` fetches it once, `auto` fetches
|
|
71
|
-
// now), which is the same shape as exit 2 but reached without a malformed
|
|
72
|
-
// request, so it earns its own number rather than muddying either.
|
|
73
|
-
// A 502 under cache_only stays 7: "we could not look" and "we hold nothing"
|
|
74
|
-
// are different answers and only one of them is worth retrying.
|
|
75
|
-
NOT_STORED: 14,
|
|
76
|
-
// Internal / uncaught (1), last resort bucket
|
|
77
|
-
INTERNAL: 1,
|
|
78
|
-
PLATFORM_NOT_IMPLEMENTED: 1
|
|
79
|
-
};
|
|
80
|
-
function getExitCode(code) {
|
|
81
|
-
return EXIT_CODE_MAP[code] ?? 1;
|
|
82
|
-
}
|
|
83
|
-
var AUTH_NEEDED = 12;
|
|
84
|
-
|
|
85
|
-
export {
|
|
86
|
-
EXIT_CODE_MAP,
|
|
87
|
-
getExitCode,
|
|
88
|
-
AUTH_NEEDED
|
|
89
|
-
};
|