@curviate/cli 0.49.0 → 0.50.0-next.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 +26 -0
- package/README.md +12 -5
- package/dist/{account-2BH2Q6VG.js → account-U7UJIE3H.js} +784 -116
- package/dist/analytics-MZU2WKON.js +27 -0
- package/dist/beta-consent-67IDUV3K.js +81 -0
- package/dist/billing-QAW75YE7.js +124 -0
- package/dist/{chunk-RXWODUWA.js → chunk-2W4RN5ON.js} +18 -2
- package/dist/{chunk-MGB6FE4A.js → chunk-3Z6PXS6N.js} +6 -6
- package/dist/chunk-5S3MJVI5.js +22 -0
- package/dist/{chunk-V7FJWTZW.js → chunk-6LBOGIVE.js} +4 -4
- package/dist/{chunk-Z7OQSWBD.js → chunk-6PLDAEMO.js} +85 -10
- package/dist/chunk-73DJ3KNE.js +54 -0
- package/dist/{chunk-3RCW7URJ.js → chunk-A57ZILRU.js} +1 -1
- package/dist/chunk-AVI7J47S.js +52 -0
- package/dist/{chunk-JYKYD57J.js → chunk-CKVCBGQX.js} +1 -1
- package/dist/chunk-EIA66ESN.js +339 -0
- package/dist/{chunk-YLSJ4HKU.js → chunk-ENBIMEKS.js} +26 -1
- package/dist/{chunk-LCGXJGPB.js → chunk-GHMRPX5H.js} +7 -1
- package/dist/chunk-GOICALYQ.js +28 -0
- package/dist/{chunk-PQWDDSV7.js → chunk-L7JH3W56.js} +1 -1
- package/dist/chunk-LCPPXOPN.js +528 -0
- package/dist/chunk-LRMPS4UQ.js +144 -0
- package/dist/{chunk-5ZGTU4VD.js → chunk-LULN3II2.js} +78 -5
- package/dist/chunk-PPGKQJKU.js +38 -0
- package/dist/chunk-Q3ZPRFUX.js +20 -0
- package/dist/{chunk-SA2QHAXG.js → chunk-QM57YDJE.js} +13 -201
- package/dist/{chunk-Y7MZZRYR.js → chunk-RYWWSZUH.js} +14 -2
- package/dist/{chunk-TEAWYLPO.js → chunk-TYNVJDYK.js} +49 -18
- package/dist/cli.js +34 -18
- package/dist/{comment-MRDPDA33.js → comment-6NRZILAS.js} +90 -11
- package/dist/{company-2AEHSGHA.js → company-VXE7IEPT.js} +65 -15
- package/dist/{config-NRBKHXES.js → config-3WP7OD35.js} +53 -4
- package/dist/{connect-4XEBV5V3.js → connect-FBK6UWZP.js} +63 -18
- package/dist/contact-HFPZ3KGL.js +32 -0
- package/dist/contact-groups-AI4MLGQS.js +399 -0
- package/dist/contact-import-54Y7EMU2.js +336 -0
- package/dist/core-RLMWMQEI.js +46 -0
- package/dist/do-not-contact-LQ5V6SPE.js +200 -0
- package/dist/{doctor-BZ4DA7DV.js → doctor-KKRL7TEF.js} +65 -11
- package/dist/{document-RKHRWXNT.js → document-GFRWPQFV.js} +1 -1
- package/dist/{draft-C5N6EOO5.js → draft-VSWZOCDR.js} +60 -14
- package/dist/{enrollment-BNQOUKI7.js → enrollment-OACCSBM5.js} +31 -19
- package/dist/{examples-NIMSIXMV.js → examples-JJB4DZKK.js} +2 -2
- package/dist/{exit-codes-TLMKTLRI.js → exit-codes-7DBETBDT.js} +1 -1
- package/dist/export-AQHAFVAB.js +96 -0
- package/dist/{feed-DFUU7SUJ.js → feed-HY4HT75U.js} +13 -10
- package/dist/{group-CSD2OWOZ.js → group-A3SMBFU5.js} +18 -10
- package/dist/{inbox-SNSPWI7J.js → inbox-YHUO2RPI.js} +31 -12
- package/dist/{inboxes-RIRHPS4H.js → inboxes-GKLMHPDR.js} +14 -10
- package/dist/incoming-NHROOOIZ.js +218 -0
- package/dist/{job-6PNXXZNF.js → job-QBW3PGWL.js} +65 -13
- package/dist/{login-Y7JBAHCW.js → login-GWIYHKYO.js} +13 -4
- package/dist/{message-2IK4MBBG.js → message-BFLN2VHS.js} +9 -7
- package/dist/{motion-7ATUXO6R.js → motion-LTWU2GPC.js} +39 -117
- package/dist/network-CNSBX2SR.js +235 -0
- package/dist/{notification-VYK5NDEB.js → notification-DCCFJPXU.js} +38 -11
- package/dist/notifications-AQBXBK4K.js +231 -0
- package/dist/{post-AN6T2OJF.js → post-PINZHSPS.js} +92 -12
- package/dist/{profile-UQY64642.js → profile-MJQJSNYR.js} +76 -20
- package/dist/{recruiter-OY4RN5HH.js → recruiter-X6GX4A2G.js} +133 -22
- package/dist/{sales-nav-KLODLYMW.js → sales-nav-44GYWDYE.js} +74 -19
- package/dist/{search-NWP5S6CF.js → search-SULIN6TB.js} +55 -23
- package/dist/{setup-YPPFLH2N.js → setup-ZQRHMRMB.js} +69 -17
- package/dist/team-TM6LRUY5.js +450 -0
- package/dist/tier-Z3U6AT7H.js +61 -0
- package/dist/unibox-BIMI2KY5.js +402 -0
- package/dist/{webhook-OHKBL3YS.js → webhook-EHXRTHBG.js} +257 -27
- package/package.json +2 -2
- package/dist/chunk-D2S5OCYU.js +0 -38
- package/dist/core-RGU2SCBN.js +0 -46
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
import {
|
|
3
3
|
betaOverrideHeader,
|
|
4
4
|
getRecheck,
|
|
5
|
+
getTeamFlag,
|
|
5
6
|
getWriteKind,
|
|
6
7
|
isPoll
|
|
7
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-RYWWSZUH.js";
|
|
8
9
|
import {
|
|
9
|
-
assertNoStdinPlaceholder
|
|
10
|
+
assertNoStdinPlaceholder,
|
|
11
|
+
isStdinToken
|
|
10
12
|
} from "./chunk-ZYURL5VK.js";
|
|
11
13
|
|
|
12
14
|
// src/lib/config.ts
|
|
@@ -30,6 +32,7 @@ var PROFILE_FIELD_TYPES = {
|
|
|
30
32
|
account: "string",
|
|
31
33
|
baseUrl: "string",
|
|
32
34
|
tenant: "string",
|
|
35
|
+
team: "string",
|
|
33
36
|
timeout: "number"
|
|
34
37
|
};
|
|
35
38
|
function isPlainObject(value) {
|
|
@@ -193,13 +196,79 @@ async function updateProfileField(profileName, field, value) {
|
|
|
193
196
|
profile.baseUrl = value !== void 0 ? String(value) : void 0;
|
|
194
197
|
} else if (field === "tenant") {
|
|
195
198
|
profile.tenant = value !== void 0 ? String(value) : void 0;
|
|
199
|
+
} else if (field === "team") {
|
|
200
|
+
profile.team = value !== void 0 ? String(value) : void 0;
|
|
196
201
|
}
|
|
197
202
|
await writeConfig(cfg);
|
|
198
203
|
}
|
|
199
204
|
|
|
205
|
+
// src/lib/resolve.ts
|
|
206
|
+
var lastTeam = () => void 0;
|
|
207
|
+
var resolvedTeam = () => lastTeam();
|
|
208
|
+
var DEFAULT_BASE_URL = "https://api.curviate.com";
|
|
209
|
+
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
210
|
+
async function resolveEffectiveConfig(flags) {
|
|
211
|
+
const file = await readConfigFile();
|
|
212
|
+
const fromProfile = (field) => profileValue(file, flags.profile, field);
|
|
213
|
+
if (isStdinToken(flags.apiKey)) {
|
|
214
|
+
process.stderr.write("error: --api-key - reads stdin only on `curviate login`. Set CURVIATE_API_KEY, or save the key with `curviate login --api-key -`.\n");
|
|
215
|
+
process.exit(2);
|
|
216
|
+
}
|
|
217
|
+
const profileKey = flags.apiKey === void 0 && process.env["CURVIATE_API_KEY"] === void 0 ? fromProfile("apiKey") : void 0;
|
|
218
|
+
const apiKey = flags.apiKey ?? process.env["CURVIATE_API_KEY"] ?? profileKey;
|
|
219
|
+
const apiKeySource = flags.apiKey !== void 0 ? "flag" : process.env["CURVIATE_API_KEY"] !== void 0 ? "env" : profileKey !== void 0 ? "profile" : "none";
|
|
220
|
+
const baseUrl = flags.baseUrl ?? process.env["CURVIATE_BASE_URL"] ?? fromProfile("baseUrl") ?? DEFAULT_BASE_URL;
|
|
221
|
+
const timeoutFlag = flags.timeout === void 0 ? void 0 : /^[1-9]\d*$/.test(flags.timeout) ? Number(flags.timeout) : NaN;
|
|
222
|
+
const keyAndUrlBypassProfile = apiKeySource !== "profile" && apiKeySource !== "none" && (flags.baseUrl ?? process.env["CURVIATE_BASE_URL"]) !== void 0;
|
|
223
|
+
const profileTimeout = () => {
|
|
224
|
+
try {
|
|
225
|
+
return fromProfile("timeout");
|
|
226
|
+
} catch (err) {
|
|
227
|
+
if (keyAndUrlBypassProfile) return void 0;
|
|
228
|
+
throw err;
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
const timeout = timeoutFlag ?? profileTimeout() ?? DEFAULT_TIMEOUT_MS;
|
|
232
|
+
const flagTeam = getTeamFlag();
|
|
233
|
+
if (flagTeam !== void 0 && flagTeam.trim() === "") {
|
|
234
|
+
process.stderr.write("error: --team was given an empty value. Pass a Team id (tnt_...), or leave it out.\n");
|
|
235
|
+
process.exit(2);
|
|
236
|
+
}
|
|
237
|
+
const envTeam = process.env["CURVIATE_TEAM"] || void 0;
|
|
238
|
+
const effective = {
|
|
239
|
+
apiKey,
|
|
240
|
+
baseUrl,
|
|
241
|
+
timeout,
|
|
242
|
+
apiKeySource,
|
|
243
|
+
// Account: flag > env > profile. Read on access: a root-scoped command never
|
|
244
|
+
// takes it, so a broken profile account must not refuse that command.
|
|
245
|
+
get account() {
|
|
246
|
+
return flags.account ?? process.env["CURVIATE_ACCOUNT"] ?? fromProfile("account");
|
|
247
|
+
},
|
|
248
|
+
// Tenant: only meaningful when the key itself came from the profile.
|
|
249
|
+
get tenant() {
|
|
250
|
+
return apiKeySource === "profile" ? fromProfile("tenant") : void 0;
|
|
251
|
+
},
|
|
252
|
+
// Read on access, like `account`: a command that sends nothing never reads it.
|
|
253
|
+
get team() {
|
|
254
|
+
return flagTeam?.trim() ?? envTeam ?? fromProfile("team");
|
|
255
|
+
},
|
|
256
|
+
get teamSource() {
|
|
257
|
+
return flagTeam !== void 0 ? "flag" : envTeam !== void 0 ? "env" : fromProfile("team") !== void 0 ? "profile" : "none";
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
lastTeam = () => effective.team;
|
|
261
|
+
return effective;
|
|
262
|
+
}
|
|
263
|
+
|
|
200
264
|
// src/lib/client.ts
|
|
201
265
|
import { AsyncLocalStorage } from "async_hooks";
|
|
202
266
|
import { Curviate, CurviateError as CurviateError2 } from "@curviate/sdk";
|
|
267
|
+
|
|
268
|
+
// package.json
|
|
269
|
+
var version = "0.50.0-next.1";
|
|
270
|
+
|
|
271
|
+
// src/lib/client.ts
|
|
203
272
|
function headerStrings(headers) {
|
|
204
273
|
if (!headers) return [];
|
|
205
274
|
if (headers instanceof Headers) {
|
|
@@ -283,7 +352,7 @@ function acceptedWrite(res, text, body) {
|
|
|
283
352
|
headers2.delete("content-type");
|
|
284
353
|
return new Response(null, { status: res.status, statusText: res.statusText, headers: headers2 });
|
|
285
354
|
}
|
|
286
|
-
const expected = body !== null && typeof body === "object" && !Array.isArray(body)
|
|
355
|
+
const expected = body !== null && typeof body === "object" && !Array.isArray(body);
|
|
287
356
|
if (!expected) {
|
|
288
357
|
const what = body === void 0 ? "a body that is not JSON" : "a body of an unexpected shape";
|
|
289
358
|
process.stderr.write(`warning: the API accepted this write (HTTP ${res.status}) with ${what}. The write happened: do not retry it.
|
|
@@ -335,17 +404,20 @@ function createClient(config) {
|
|
|
335
404
|
return new Curviate({
|
|
336
405
|
apiKey: config.apiKey.trim(),
|
|
337
406
|
fetch: guardedFetch,
|
|
407
|
+
// Replaces the SDK's own `sdk/<version>`: exactly one Curviate-Client header per request.
|
|
408
|
+
client: `cli/${version}`,
|
|
338
409
|
...config.baseUrl !== void 0 ? { baseUrl: config.baseUrl } : {},
|
|
339
|
-
...config.timeout !== void 0 ? { timeout: config.timeout } : {}
|
|
410
|
+
...config.timeout !== void 0 ? { timeout: config.timeout } : {},
|
|
411
|
+
...teamOption(config.team === void 0 ? resolvedTeam() : config.team)
|
|
340
412
|
});
|
|
341
413
|
}
|
|
414
|
+
var teamOption = (team) => team ? { team } : {};
|
|
342
415
|
|
|
343
416
|
export {
|
|
344
417
|
PROFILE_FIELD_TYPES,
|
|
345
418
|
isPlainObject,
|
|
346
419
|
assertStructure,
|
|
347
420
|
readConfigFile,
|
|
348
|
-
profileValue,
|
|
349
421
|
getConfigPath,
|
|
350
422
|
readConfig,
|
|
351
423
|
writeProfile,
|
|
@@ -353,6 +425,7 @@ export {
|
|
|
353
425
|
renameProfile,
|
|
354
426
|
removeProfile,
|
|
355
427
|
updateProfileField,
|
|
428
|
+
resolveEffectiveConfig,
|
|
356
429
|
downloadBinary,
|
|
357
430
|
baseUrlProblem,
|
|
358
431
|
withoutUserinfo,
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/lib/export-file.ts
|
|
4
|
+
import { chmod, rename, unlink, writeFile } from "fs/promises";
|
|
5
|
+
import { basename, dirname, join } from "path";
|
|
6
|
+
async function writeExport(output, data) {
|
|
7
|
+
if (output === void 0 || output === "-") {
|
|
8
|
+
await new Promise((resolve, reject) => process.stdout.write(data, (e) => e ? reject(e) : resolve()));
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const tmp = join(dirname(output), `.${basename(output)}.${process.pid}.tmp`);
|
|
12
|
+
try {
|
|
13
|
+
await writeFile(tmp, data, { mode: 384 });
|
|
14
|
+
await chmod(tmp, 384);
|
|
15
|
+
await rename(tmp, output);
|
|
16
|
+
} catch (err) {
|
|
17
|
+
await unlink(tmp).catch(() => {
|
|
18
|
+
});
|
|
19
|
+
throw err;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function csvCell(v) {
|
|
23
|
+
if (v === null || v === void 0) return "";
|
|
24
|
+
let s = typeof v === "object" ? JSON.stringify(v) : String(v);
|
|
25
|
+
if (/^[=+\-@\t\r']/.test(s)) s = "'" + s;
|
|
26
|
+
return /[",\r\n]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s;
|
|
27
|
+
}
|
|
28
|
+
function formatRows(rows, fields, format) {
|
|
29
|
+
const pick = (r) => Object.fromEntries(fields.map((f) => [f, r[f] ?? null]));
|
|
30
|
+
if (format === "json") return JSON.stringify(rows.map(pick)) + "\n";
|
|
31
|
+
if (format === "ndjson") return rows.map((r) => JSON.stringify(pick(r)) + "\n").join("");
|
|
32
|
+
return "\uFEFF" + [fields, ...rows.map((r) => fields.map((f) => r[f]))].map((cells) => cells.map(csvCell).join(",") + "\r\n").join("");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
writeExport,
|
|
37
|
+
formatRows
|
|
38
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/lib/help-errors.ts
|
|
4
|
+
var AS_ACCOUNT = {
|
|
5
|
+
ACCOUNT_NOT_FOUND: "the Account is not in your Team.",
|
|
6
|
+
LINKEDIN_AUTH_FAILED: "LinkedIn no longer accepts the Account's sign-in: reconnect it.",
|
|
7
|
+
ACCOUNT_RESTRICTED: "LinkedIn restricts the Account from this action."
|
|
8
|
+
};
|
|
9
|
+
var BUDGET = {
|
|
10
|
+
BUDGET_EXHAUSTED: "the Account's limit for this action is used up; nothing reached LinkedIn. `curviate account get <account_id>` shows when it resets; `curviate account safety update` changes the limit."
|
|
11
|
+
};
|
|
12
|
+
var TARGET = {
|
|
13
|
+
RESOURCE_NOT_FOUND: "the target does not exist, or the Account cannot see it."
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
AS_ACCOUNT,
|
|
18
|
+
BUDGET,
|
|
19
|
+
TARGET
|
|
20
|
+
};
|
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
isPlainObject,
|
|
4
|
-
profileValue,
|
|
5
|
-
readConfigFile
|
|
6
|
-
} from "./chunk-5ZGTU4VD.js";
|
|
7
|
-
import {
|
|
8
|
-
isStdinToken
|
|
9
|
-
} from "./chunk-ZYURL5VK.js";
|
|
10
2
|
|
|
11
3
|
// src/lib/output.ts
|
|
12
4
|
function isJsonMode(opts) {
|
|
@@ -62,8 +54,6 @@ function withPreservedNotices(original, rendered) {
|
|
|
62
54
|
if (Array.isArray(notices) && notices.length > 0 && rendered["notices"] !== notices) {
|
|
63
55
|
out = { ...out, notices };
|
|
64
56
|
}
|
|
65
|
-
const safetyWarning = original["safety_warning"];
|
|
66
|
-
if (isPlain(safetyWarning)) out = { ...out, safety_warning: safetyWarning };
|
|
67
57
|
return withPreservedProvenance(original, out);
|
|
68
58
|
}
|
|
69
59
|
var PROVENANCE_KEYS = ["source", "observed_at", "withdrawn", "withdrawn_at"];
|
|
@@ -95,14 +85,14 @@ function renderProvenanceNote(data) {
|
|
|
95
85
|
return line + "\n";
|
|
96
86
|
}
|
|
97
87
|
function firstProjectableItem(data) {
|
|
98
|
-
const
|
|
88
|
+
const isPlainObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
99
89
|
if (Array.isArray(data)) {
|
|
100
|
-
return data.length > 0 &&
|
|
90
|
+
return data.length > 0 && isPlainObject(data[0]) ? data[0] : null;
|
|
101
91
|
}
|
|
102
|
-
if (
|
|
92
|
+
if (isPlainObject(data)) {
|
|
103
93
|
const items = data["items"];
|
|
104
94
|
if (Array.isArray(items)) {
|
|
105
|
-
return items.length > 0 &&
|
|
95
|
+
return items.length > 0 && isPlainObject(items[0]) ? items[0] : null;
|
|
106
96
|
}
|
|
107
97
|
return data;
|
|
108
98
|
}
|
|
@@ -169,11 +159,7 @@ function renderHuman(data) {
|
|
|
169
159
|
const notices = renderNotices(obj["notices"]);
|
|
170
160
|
if (Array.isArray(obj["items"])) {
|
|
171
161
|
const items = obj["items"];
|
|
172
|
-
|
|
173
|
-
if (isPlain(obj["safety_warning"])) {
|
|
174
|
-
body = `safety_warning: ${JSON.stringify(obj["safety_warning"])}
|
|
175
|
-
${body}`;
|
|
176
|
-
}
|
|
162
|
+
const body = items.length === 0 ? "(no items)" : items.map(renderHuman).join("\n");
|
|
177
163
|
return notices ? `${notices}
|
|
178
164
|
${body}` : body;
|
|
179
165
|
}
|
|
@@ -231,6 +217,12 @@ Paused budget row: ${safety.budgetRow}${wait} (other rows on this account still
|
|
|
231
217
|
const mode = loc.mode === "custom" ? "your own proxy" : loc.mode === "auto" ? "managed" : "mode unknown";
|
|
232
218
|
msg += `
|
|
233
219
|
Connects from now: ${loc.current_country ?? loc.country ?? "unknown"} (${mode}${loc.strict ? ", strict" : ""})`;
|
|
220
|
+
}
|
|
221
|
+
if (errJson.code === "TIER_REQUIRED") {
|
|
222
|
+
msg += `
|
|
223
|
+
Needs: ${errJson.feature ?? "this feature"} is part of ${errJson.requiredTier ?? "a Tier not on sale yet"}; this Team has ${errJson.currentTier ?? "no Tier"}.`;
|
|
224
|
+
msg += errJson.upgradeUrl ? `
|
|
225
|
+
Upgrade: ${errJson.upgradeUrl}` : "\nAsk an Owner of your Team to change the Tier (`curviate team members` lists them).";
|
|
234
226
|
}
|
|
235
227
|
if (errJson.retryAfterMs) {
|
|
236
228
|
msg += `
|
|
@@ -249,192 +241,12 @@ function renderUnexpectedError(err, out) {
|
|
|
249
241
|
`);
|
|
250
242
|
}
|
|
251
243
|
|
|
252
|
-
// src/lib/paginate.ts
|
|
253
|
-
import { CurviateError } from "@curviate/sdk";
|
|
254
|
-
function readablePage(page) {
|
|
255
|
-
const list = isPlainObject(page) ? page["items"] === void 0 ? page["data"] : page["items"] : void 0;
|
|
256
|
-
if (!Array.isArray(list)) throw unreadable("list page");
|
|
257
|
-
return { ...page, items: list };
|
|
258
|
-
}
|
|
259
|
-
function readableId(entity) {
|
|
260
|
-
const id = isPlainObject(entity) ? entity["id"] : void 0;
|
|
261
|
-
if ((typeof id !== "string" || id === "") && !(typeof id === "number" && Number.isFinite(id))) throw unreadable("id");
|
|
262
|
-
return String(id);
|
|
263
|
-
}
|
|
264
|
-
function readableObject(data) {
|
|
265
|
-
if (!isPlainObject(data) || Object.keys(data).length === 0) throw unreadable("object");
|
|
266
|
-
return data;
|
|
267
|
-
}
|
|
268
|
-
function rejectPaginationModifiersWithoutAll(flags, out) {
|
|
269
|
-
if (flags.all) return;
|
|
270
|
-
const offender = flags["max-pages"] !== void 0 ? "--max-pages" : flags["page-delay"] !== void 0 ? "--page-delay" : null;
|
|
271
|
-
if (!offender) return;
|
|
272
|
-
out.stderr.write(`error: ${offender} requires --all; without it, streaming never engages so the flag does nothing.
|
|
273
|
-
`);
|
|
274
|
-
process.exit(2);
|
|
275
|
-
}
|
|
276
|
-
var DEFAULT_MAX_PAGES = 100;
|
|
277
|
-
function readCursorFlag(flags, out) {
|
|
278
|
-
const raw = flags.cursor;
|
|
279
|
-
if (raw === void 0) return void 0;
|
|
280
|
-
if (raw.trim() === "") {
|
|
281
|
-
out.stderr.write(
|
|
282
|
-
"error: --cursor was given an empty value. Pass the cursor from the previous response, or omit the flag entirely to start at the first page.\n"
|
|
283
|
-
);
|
|
284
|
-
process.exit(2);
|
|
285
|
-
}
|
|
286
|
-
return raw;
|
|
287
|
-
}
|
|
288
|
-
function readMaxPagesFlag(flags, out) {
|
|
289
|
-
const raw = flags["max-pages"];
|
|
290
|
-
if (raw === void 0) return DEFAULT_MAX_PAGES;
|
|
291
|
-
if (!/^\d+$/.test(raw) || Number(raw) < 1) {
|
|
292
|
-
out.stderr.write(
|
|
293
|
-
`error: --max-pages must be a positive integer (got ${JSON.stringify(raw)}); it is the number of pages --all may fetch.
|
|
294
|
-
`
|
|
295
|
-
);
|
|
296
|
-
process.exit(2);
|
|
297
|
-
}
|
|
298
|
-
return Number(raw);
|
|
299
|
-
}
|
|
300
|
-
function unreadable(what) {
|
|
301
|
-
return new CurviateError({
|
|
302
|
-
code: "PLATFORM_ERROR",
|
|
303
|
-
message: `The API answered without a readable ${what}.`,
|
|
304
|
-
// The status the client gives every synthesized unreadable-2xx fault.
|
|
305
|
-
httpStatus: 502,
|
|
306
|
-
userFixable: false,
|
|
307
|
-
retryLikelyToSucceed: true
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
function truncationProseNote(pagesFetched) {
|
|
311
|
-
return `Streaming truncated at ${pagesFetched} page(s). Use --all --max-pages or --cursor for manual paging.
|
|
312
|
-
`;
|
|
313
|
-
}
|
|
314
|
-
function ndjsonModeNotice() {
|
|
315
|
-
return "--all streams NDJSON: one object per line; the {items,cursor} envelope is not used\n";
|
|
316
|
-
}
|
|
317
|
-
var DEFAULT_PAGE_DELAY_MS = 400;
|
|
318
|
-
function pageDelayFrom(raw) {
|
|
319
|
-
if (raw === void 0 || raw === "") return void 0;
|
|
320
|
-
const n = Number(raw);
|
|
321
|
-
if (!Number.isInteger(n) || n < 0) return void 0;
|
|
322
|
-
return n;
|
|
323
|
-
}
|
|
324
|
-
function pageDelayFromFlags(flags) {
|
|
325
|
-
return pageDelayFrom(flags["page-delay"]);
|
|
326
|
-
}
|
|
327
|
-
var realSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
328
|
-
function truncationSentinelLine(pagesFetched, hasMore) {
|
|
329
|
-
return JSON.stringify({ object: "stream_truncated", pages_fetched: pagesFetched, has_more: hasMore }) + "\n";
|
|
330
|
-
}
|
|
331
|
-
async function* streamAll(fn, params, opts = {}) {
|
|
332
|
-
const maxPages = opts.maxPages ?? DEFAULT_MAX_PAGES;
|
|
333
|
-
const pageDelayMs = opts.pageDelayMs ?? DEFAULT_PAGE_DELAY_MS;
|
|
334
|
-
const sleep = opts.sleep ?? realSleep;
|
|
335
|
-
let cursor = void 0;
|
|
336
|
-
let pageCount = 0;
|
|
337
|
-
let firstPage = true;
|
|
338
|
-
while (true) {
|
|
339
|
-
const pageParams = cursor !== void 0 && cursor !== null ? { ...params, cursor } : params;
|
|
340
|
-
const page = readablePage(await fn(pageParams));
|
|
341
|
-
pageCount++;
|
|
342
|
-
const items = page.items;
|
|
343
|
-
if (firstPage) {
|
|
344
|
-
if (opts.out) opts.out.stderr.write(ndjsonModeNotice());
|
|
345
|
-
firstPage = false;
|
|
346
|
-
}
|
|
347
|
-
if (opts.out) {
|
|
348
|
-
const pageNotices = renderNotices(page.notices);
|
|
349
|
-
if (pageNotices) opts.out.stderr.write(pageNotices + "\n");
|
|
350
|
-
const pageWarning = page.safety_warning;
|
|
351
|
-
if (typeof pageWarning === "object" && pageWarning !== null && !Array.isArray(pageWarning)) {
|
|
352
|
-
opts.out.stderr.write(`safety_warning: ${JSON.stringify(pageWarning)}
|
|
353
|
-
`);
|
|
354
|
-
}
|
|
355
|
-
const pageProvenance = renderProvenanceNote(page);
|
|
356
|
-
if (pageProvenance) opts.out.stderr.write(pageProvenance);
|
|
357
|
-
}
|
|
358
|
-
if (Array.isArray(items)) {
|
|
359
|
-
for (const item of items) {
|
|
360
|
-
yield item;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
cursor = page.cursor;
|
|
364
|
-
if (!cursor) break;
|
|
365
|
-
if (pageCount >= maxPages) {
|
|
366
|
-
const hasMore = cursor !== null && cursor !== void 0;
|
|
367
|
-
if (opts.out) {
|
|
368
|
-
opts.out.stdout.write(truncationSentinelLine(pageCount, hasMore));
|
|
369
|
-
opts.out.stderr.write(truncationProseNote(pageCount));
|
|
370
|
-
}
|
|
371
|
-
if (opts.onTruncated) {
|
|
372
|
-
opts.onTruncated(pageCount, hasMore);
|
|
373
|
-
}
|
|
374
|
-
break;
|
|
375
|
-
}
|
|
376
|
-
if (pageDelayMs > 0) await sleep(pageDelayMs);
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// src/lib/resolve.ts
|
|
381
|
-
var DEFAULT_BASE_URL = "https://api.curviate.com";
|
|
382
|
-
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
383
|
-
async function resolveEffectiveConfig(flags) {
|
|
384
|
-
const file = await readConfigFile();
|
|
385
|
-
const fromProfile = (field) => profileValue(file, flags.profile, field);
|
|
386
|
-
if (isStdinToken(flags.apiKey)) {
|
|
387
|
-
process.stderr.write("error: --api-key - reads stdin only on `curviate login`. Set CURVIATE_API_KEY, or save the key with `curviate login --api-key -`.\n");
|
|
388
|
-
process.exit(2);
|
|
389
|
-
}
|
|
390
|
-
const profileKey = flags.apiKey === void 0 && process.env["CURVIATE_API_KEY"] === void 0 ? fromProfile("apiKey") : void 0;
|
|
391
|
-
const apiKey = flags.apiKey ?? process.env["CURVIATE_API_KEY"] ?? profileKey;
|
|
392
|
-
const apiKeySource = flags.apiKey !== void 0 ? "flag" : process.env["CURVIATE_API_KEY"] !== void 0 ? "env" : profileKey !== void 0 ? "profile" : "none";
|
|
393
|
-
const baseUrl = flags.baseUrl ?? process.env["CURVIATE_BASE_URL"] ?? fromProfile("baseUrl") ?? DEFAULT_BASE_URL;
|
|
394
|
-
const timeoutFlag = flags.timeout === void 0 ? void 0 : /^[1-9]\d*$/.test(flags.timeout) ? Number(flags.timeout) : NaN;
|
|
395
|
-
const keyAndUrlBypassProfile = apiKeySource !== "profile" && apiKeySource !== "none" && (flags.baseUrl ?? process.env["CURVIATE_BASE_URL"]) !== void 0;
|
|
396
|
-
const profileTimeout = () => {
|
|
397
|
-
try {
|
|
398
|
-
return fromProfile("timeout");
|
|
399
|
-
} catch (err) {
|
|
400
|
-
if (keyAndUrlBypassProfile) return void 0;
|
|
401
|
-
throw err;
|
|
402
|
-
}
|
|
403
|
-
};
|
|
404
|
-
const timeout = timeoutFlag ?? profileTimeout() ?? DEFAULT_TIMEOUT_MS;
|
|
405
|
-
return {
|
|
406
|
-
apiKey,
|
|
407
|
-
baseUrl,
|
|
408
|
-
timeout,
|
|
409
|
-
apiKeySource,
|
|
410
|
-
// Account: flag > env > profile. Read on access: a root-scoped command never
|
|
411
|
-
// takes it, so a broken profile account must not refuse that command.
|
|
412
|
-
get account() {
|
|
413
|
-
return flags.account ?? process.env["CURVIATE_ACCOUNT"] ?? fromProfile("account");
|
|
414
|
-
},
|
|
415
|
-
// Tenant: only meaningful when the key itself came from the profile.
|
|
416
|
-
get tenant() {
|
|
417
|
-
return apiKeySource === "profile" ? fromProfile("tenant") : void 0;
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
}
|
|
421
|
-
|
|
422
244
|
export {
|
|
423
245
|
isJsonMode,
|
|
246
|
+
renderProvenanceNote,
|
|
424
247
|
renderSuccess,
|
|
425
248
|
writeNdjsonItem,
|
|
426
249
|
renderNotices,
|
|
427
250
|
renderError,
|
|
428
|
-
renderUnexpectedError
|
|
429
|
-
readablePage,
|
|
430
|
-
readableId,
|
|
431
|
-
readableObject,
|
|
432
|
-
rejectPaginationModifiersWithoutAll,
|
|
433
|
-
readCursorFlag,
|
|
434
|
-
readMaxPagesFlag,
|
|
435
|
-
ndjsonModeNotice,
|
|
436
|
-
DEFAULT_PAGE_DELAY_MS,
|
|
437
|
-
pageDelayFromFlags,
|
|
438
|
-
streamAll,
|
|
439
|
-
resolveEffectiveConfig
|
|
251
|
+
renderUnexpectedError
|
|
440
252
|
};
|
|
@@ -15,6 +15,10 @@ var GLOBAL_FLAGS = {
|
|
|
15
15
|
type: "string",
|
|
16
16
|
description: "Account id for account-scoped commands. Optional when exactly one account is connected, and required with --preview."
|
|
17
17
|
},
|
|
18
|
+
team: {
|
|
19
|
+
type: "string",
|
|
20
|
+
description: "Team to act in (tnt_...), sent with every request. Overrides CURVIATE_TEAM and the profile's team. Needed with a key that works in all your Teams; a Team key acts only in its own Team."
|
|
21
|
+
},
|
|
18
22
|
"base-url": {
|
|
19
23
|
type: "string",
|
|
20
24
|
description: "Override the API base URL."
|
|
@@ -70,13 +74,14 @@ var GLOBAL_FLAGS = {
|
|
|
70
74
|
// cannot express an optional-valued boolean without silently opting in).
|
|
71
75
|
beta: {
|
|
72
76
|
type: "boolean",
|
|
73
|
-
description: "Allow beta operations for THIS call only (--beta, --beta=false). A gated operation refuses BETA_NOT_ENABLED (exit 5) until
|
|
77
|
+
description: "Allow beta operations for THIS call only (--beta, --beta=false). A gated operation refuses BETA_NOT_ENABLED (exit 5) until beta is enabled for the Team (`curviate beta update --enabled true`, an Owner; `PATCH /v1/tenant/beta`), or you pass --beta for this call. Persists nothing."
|
|
74
78
|
}
|
|
75
79
|
};
|
|
76
80
|
var NON_STREAM_FLAGS = {
|
|
77
81
|
"api-key": GLOBAL_FLAGS["api-key"],
|
|
78
82
|
profile: GLOBAL_FLAGS.profile,
|
|
79
83
|
account: GLOBAL_FLAGS.account,
|
|
84
|
+
team: GLOBAL_FLAGS.team,
|
|
80
85
|
"base-url": GLOBAL_FLAGS["base-url"],
|
|
81
86
|
timeout: GLOBAL_FLAGS.timeout,
|
|
82
87
|
json: GLOBAL_FLAGS.json,
|
|
@@ -91,6 +96,7 @@ var WRITE_FLAGS = {
|
|
|
91
96
|
"api-key": GLOBAL_FLAGS["api-key"],
|
|
92
97
|
profile: GLOBAL_FLAGS.profile,
|
|
93
98
|
account: GLOBAL_FLAGS.account,
|
|
99
|
+
team: GLOBAL_FLAGS.team,
|
|
94
100
|
"base-url": GLOBAL_FLAGS["base-url"],
|
|
95
101
|
timeout: GLOBAL_FLAGS.timeout,
|
|
96
102
|
json: GLOBAL_FLAGS.json,
|
|
@@ -102,6 +108,7 @@ var READ_SINGLE_FLAGS = {
|
|
|
102
108
|
"api-key": GLOBAL_FLAGS["api-key"],
|
|
103
109
|
profile: GLOBAL_FLAGS.profile,
|
|
104
110
|
account: GLOBAL_FLAGS.account,
|
|
111
|
+
team: GLOBAL_FLAGS.team,
|
|
105
112
|
"base-url": GLOBAL_FLAGS["base-url"],
|
|
106
113
|
timeout: GLOBAL_FLAGS.timeout,
|
|
107
114
|
json: GLOBAL_FLAGS.json,
|
|
@@ -131,6 +138,9 @@ var STATE_WRITES = {
|
|
|
131
138
|
// Its answer says whether the Step was resumed, and what to wait for.
|
|
132
139
|
"curviate enrollment retry": "curviate enrollment get <enrollment_id>"
|
|
133
140
|
};
|
|
141
|
+
var teamFlag;
|
|
142
|
+
var setTeamFlag = (v) => void (teamFlag = typeof v === "string" ? v : void 0);
|
|
143
|
+
var getTeamFlag = () => teamFlag;
|
|
134
144
|
|
|
135
145
|
// src/lib/beta.ts
|
|
136
146
|
var BETA_CONSENT_HEADER = "X-Curviate-Beta";
|
|
@@ -212,5 +222,7 @@ export {
|
|
|
212
222
|
isPoll,
|
|
213
223
|
getWriteKind,
|
|
214
224
|
getRecheck,
|
|
215
|
-
STATE_WRITES
|
|
225
|
+
STATE_WRITES,
|
|
226
|
+
setTeamFlag,
|
|
227
|
+
getTeamFlag
|
|
216
228
|
};
|
|
@@ -1035,6 +1035,19 @@ var documents_default = {
|
|
|
1035
1035
|
nullable: true
|
|
1036
1036
|
}
|
|
1037
1037
|
},
|
|
1038
|
+
on_reply_elsewhere: {
|
|
1039
|
+
type: "string",
|
|
1040
|
+
enum: [
|
|
1041
|
+
"stop",
|
|
1042
|
+
"continue"
|
|
1043
|
+
]
|
|
1044
|
+
},
|
|
1045
|
+
withdraw_on_reply_elsewhere: {
|
|
1046
|
+
type: "boolean"
|
|
1047
|
+
},
|
|
1048
|
+
account_gap: {
|
|
1049
|
+
type: "string"
|
|
1050
|
+
},
|
|
1038
1051
|
stop_on_engagement: {
|
|
1039
1052
|
type: "boolean"
|
|
1040
1053
|
}
|
|
@@ -1066,8 +1079,7 @@ var documents_default = {
|
|
|
1066
1079
|
"updated_at",
|
|
1067
1080
|
"started_at",
|
|
1068
1081
|
"completed_at",
|
|
1069
|
-
"archived_at"
|
|
1070
|
-
"safety_warning"
|
|
1082
|
+
"archived_at"
|
|
1071
1083
|
]
|
|
1072
1084
|
},
|
|
1073
1085
|
"motion update": {
|
|
@@ -1210,6 +1222,19 @@ var documents_default = {
|
|
|
1210
1222
|
nullable: true
|
|
1211
1223
|
}
|
|
1212
1224
|
},
|
|
1225
|
+
on_reply_elsewhere: {
|
|
1226
|
+
type: "string",
|
|
1227
|
+
enum: [
|
|
1228
|
+
"stop",
|
|
1229
|
+
"continue"
|
|
1230
|
+
]
|
|
1231
|
+
},
|
|
1232
|
+
withdraw_on_reply_elsewhere: {
|
|
1233
|
+
type: "boolean"
|
|
1234
|
+
},
|
|
1235
|
+
account_gap: {
|
|
1236
|
+
type: "string"
|
|
1237
|
+
},
|
|
1213
1238
|
stop_on_engagement: {
|
|
1214
1239
|
type: "boolean"
|
|
1215
1240
|
}
|
|
@@ -1242,8 +1267,7 @@ var documents_default = {
|
|
|
1242
1267
|
"updated_at",
|
|
1243
1268
|
"started_at",
|
|
1244
1269
|
"completed_at",
|
|
1245
|
-
"archived_at"
|
|
1246
|
-
"safety_warning"
|
|
1270
|
+
"archived_at"
|
|
1247
1271
|
]
|
|
1248
1272
|
}
|
|
1249
1273
|
};
|
|
@@ -1254,11 +1278,16 @@ var ANNOTATIONS = /* @__PURE__ */ new Set(["description", "title", "default", "d
|
|
|
1254
1278
|
function documentSchema(key) {
|
|
1255
1279
|
const s = documents_default[key];
|
|
1256
1280
|
if (!s) throw new Error(`no document schema for ${key}`);
|
|
1257
|
-
return s;
|
|
1281
|
+
return key === "motion create" || key === "motion update" ? withoutScheduleTimezone(s) : s;
|
|
1282
|
+
}
|
|
1283
|
+
function withoutScheduleTimezone(s) {
|
|
1284
|
+
const copy = structuredClone(s);
|
|
1285
|
+
delete copy.properties.schedule.properties["timezone"];
|
|
1286
|
+
return copy;
|
|
1258
1287
|
}
|
|
1259
1288
|
var MAX_DOCUMENT_BYTES = 5 * 1024 * 1024;
|
|
1260
|
-
var TOO_LARGE = (flag) => `--${flag}: larger than ${
|
|
1261
|
-
function readCapped(fd) {
|
|
1289
|
+
var TOO_LARGE = (flag, max = MAX_DOCUMENT_BYTES) => `--${flag}: larger than ${max / 1024 / 1024} MiB, the most a document may be.`;
|
|
1290
|
+
function readCapped(fd, max = MAX_DOCUMENT_BYTES) {
|
|
1262
1291
|
const chunks = [];
|
|
1263
1292
|
let total = 0;
|
|
1264
1293
|
const buf = Buffer.alloc(64 * 1024);
|
|
@@ -1273,24 +1302,26 @@ function readCapped(fd) {
|
|
|
1273
1302
|
}
|
|
1274
1303
|
if (n === 0) break;
|
|
1275
1304
|
total += n;
|
|
1276
|
-
if (total >
|
|
1305
|
+
if (total > max) return null;
|
|
1277
1306
|
chunks.push(Buffer.from(buf.subarray(0, n)));
|
|
1278
1307
|
}
|
|
1279
1308
|
return Buffer.concat(chunks);
|
|
1280
1309
|
}
|
|
1281
|
-
async function readStdinCapped(flag = "file") {
|
|
1310
|
+
async function readStdinCapped(flag = "file", allowBom = false, max = MAX_DOCUMENT_BYTES) {
|
|
1282
1311
|
const chunks = [];
|
|
1283
1312
|
let total = 0;
|
|
1284
1313
|
for await (const chunk of process.stdin) {
|
|
1285
1314
|
const b = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
1286
1315
|
total += b.length;
|
|
1287
|
-
if (total >
|
|
1316
|
+
if (total > max) usage(TOO_LARGE(flag, max));
|
|
1288
1317
|
chunks.push(b);
|
|
1289
1318
|
}
|
|
1290
|
-
return decode(flag, Buffer.concat(chunks)).replace(/\n+$/, "");
|
|
1319
|
+
return decode(flag, Buffer.concat(chunks), allowBom).replace(/\n+$/, "");
|
|
1291
1320
|
}
|
|
1292
|
-
function decode(flag, bytes) {
|
|
1293
|
-
|
|
1321
|
+
function decode(flag, bytes, allowBom = false) {
|
|
1322
|
+
const bom = bytes[0] === 239 && bytes[1] === 187 && bytes[2] === 191;
|
|
1323
|
+
if (bom && allowBom) bytes = bytes.subarray(3);
|
|
1324
|
+
else if (bom) usage(`--${flag}: starts with a byte order mark (BOM). Save it as UTF-8 without a BOM.`);
|
|
1294
1325
|
try {
|
|
1295
1326
|
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
1296
1327
|
} catch {
|
|
@@ -1312,8 +1343,8 @@ async function readFileFlag(flag, value, io = {}) {
|
|
|
1312
1343
|
const second = Object.entries(io.others ?? {}).find(([k, o]) => k !== flag && k !== "_" && isStdinToken(o));
|
|
1313
1344
|
if (second) usage(`--${flag} - and --${second[0]} - both read stdin. Only one input can come from stdin.`);
|
|
1314
1345
|
if (io.stdinIsTTY ?? process.stdin.isTTY) usage(`--${flag} -: stdin is a terminal. Pipe the document in or use a heredoc: --${flag} - <<'EOF' ... EOF`);
|
|
1315
|
-
text = await (io.readStdin ?? (() => readStdinCapped(flag)))();
|
|
1316
|
-
if (Buffer.byteLength(text) > MAX_DOCUMENT_BYTES) usage(TOO_LARGE(flag));
|
|
1346
|
+
text = await (io.readStdin ?? (() => readStdinCapped(flag, io.allowBom, io.maxBytes)))();
|
|
1347
|
+
if (Buffer.byteLength(text) > (io.maxBytes ?? MAX_DOCUMENT_BYTES)) usage(TOO_LARGE(flag, io.maxBytes));
|
|
1317
1348
|
} else {
|
|
1318
1349
|
let isDir = false;
|
|
1319
1350
|
try {
|
|
@@ -1326,15 +1357,15 @@ async function readFileFlag(flag, value, io = {}) {
|
|
|
1326
1357
|
try {
|
|
1327
1358
|
const fd = openSync(value, "r");
|
|
1328
1359
|
try {
|
|
1329
|
-
bytes = readCapped(fd);
|
|
1360
|
+
bytes = readCapped(fd, io.maxBytes);
|
|
1330
1361
|
} finally {
|
|
1331
1362
|
closeSync(fd);
|
|
1332
1363
|
}
|
|
1333
1364
|
} catch (err) {
|
|
1334
1365
|
usage(`--${flag}: cannot read ${value}: ${err.code ?? "read error"}.`);
|
|
1335
1366
|
}
|
|
1336
|
-
if (bytes === null) usage(TOO_LARGE(flag));
|
|
1337
|
-
text = decode(flag, bytes);
|
|
1367
|
+
if (bytes === null) usage(TOO_LARGE(flag, io.maxBytes));
|
|
1368
|
+
text = decode(flag, bytes, io.allowBom);
|
|
1338
1369
|
}
|
|
1339
1370
|
if (text.trim() === "") usage(`--${flag}: empty input.`);
|
|
1340
1371
|
return text;
|