@curviate/cli 0.49.0 → 0.50.0-next.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.
Files changed (70) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +12 -5
  3. package/dist/{account-2BH2Q6VG.js → account-KGCGUYKF.js} +668 -116
  4. package/dist/analytics-HRAD4ABO.js +27 -0
  5. package/dist/beta-consent-364JI6IL.js +81 -0
  6. package/dist/billing-3SSVRS2Y.js +124 -0
  7. package/dist/{chunk-V7FJWTZW.js → chunk-25MO7BYN.js} +4 -4
  8. package/dist/{chunk-RXWODUWA.js → chunk-2W4RN5ON.js} +18 -2
  9. package/dist/chunk-5S3MJVI5.js +22 -0
  10. package/dist/chunk-67S4JHZZ.js +339 -0
  11. package/dist/chunk-73DJ3KNE.js +54 -0
  12. package/dist/chunk-CQGDMARG.js +525 -0
  13. package/dist/{chunk-JYKYD57J.js → chunk-DOHBOYXN.js} +1 -1
  14. package/dist/{chunk-3RCW7URJ.js → chunk-DSGKYZDK.js} +1 -1
  15. package/dist/{chunk-YLSJ4HKU.js → chunk-ENBIMEKS.js} +26 -1
  16. package/dist/{chunk-LCGXJGPB.js → chunk-GHMRPX5H.js} +7 -1
  17. package/dist/chunk-GOICALYQ.js +28 -0
  18. package/dist/chunk-L4CIJT6F.js +144 -0
  19. package/dist/{chunk-PQWDDSV7.js → chunk-L7JH3W56.js} +1 -1
  20. package/dist/{chunk-Z7OQSWBD.js → chunk-OE6YFYUM.js} +85 -10
  21. package/dist/chunk-PPGKQJKU.js +38 -0
  22. package/dist/{chunk-SA2QHAXG.js → chunk-QM57YDJE.js} +13 -201
  23. package/dist/{chunk-Y7MZZRYR.js → chunk-RYWWSZUH.js} +14 -2
  24. package/dist/{chunk-MGB6FE4A.js → chunk-T6GBS5SS.js} +6 -6
  25. package/dist/{chunk-TEAWYLPO.js → chunk-TE3WBPW6.js} +43 -17
  26. package/dist/chunk-UL53T4O6.js +52 -0
  27. package/dist/chunk-UWQPX4AE.js +20 -0
  28. package/dist/{chunk-5ZGTU4VD.js → chunk-YXVF5UST.js} +77 -4
  29. package/dist/cli.js +34 -18
  30. package/dist/{comment-MRDPDA33.js → comment-5JKGNYOY.js} +90 -11
  31. package/dist/{company-2AEHSGHA.js → company-TXST2VXW.js} +65 -15
  32. package/dist/{config-NRBKHXES.js → config-TVIQUVNK.js} +53 -4
  33. package/dist/{connect-4XEBV5V3.js → connect-RBL6U4KV.js} +63 -18
  34. package/dist/contact-YAHC5QFX.js +32 -0
  35. package/dist/contact-groups-DKOIBC57.js +399 -0
  36. package/dist/contact-import-ITSJQV7K.js +336 -0
  37. package/dist/core-PWMJPPRG.js +46 -0
  38. package/dist/do-not-contact-WDYIBWYA.js +200 -0
  39. package/dist/{doctor-BZ4DA7DV.js → doctor-F7JLPTED.js} +65 -11
  40. package/dist/{document-RKHRWXNT.js → document-BHYAUJ6F.js} +1 -1
  41. package/dist/{draft-C5N6EOO5.js → draft-TDJJUXLH.js} +60 -14
  42. package/dist/{enrollment-BNQOUKI7.js → enrollment-Q6UOKHPY.js} +31 -19
  43. package/dist/{examples-NIMSIXMV.js → examples-DQSVIIXZ.js} +2 -2
  44. package/dist/{exit-codes-TLMKTLRI.js → exit-codes-7DBETBDT.js} +1 -1
  45. package/dist/export-HIJSCJS6.js +96 -0
  46. package/dist/{feed-DFUU7SUJ.js → feed-W56ZTA4Z.js} +13 -10
  47. package/dist/{group-CSD2OWOZ.js → group-AUALYK5H.js} +18 -10
  48. package/dist/{inbox-SNSPWI7J.js → inbox-HLZR2ZPV.js} +31 -12
  49. package/dist/{inboxes-RIRHPS4H.js → inboxes-IZTRD6FE.js} +14 -10
  50. package/dist/incoming-ULB2RNV4.js +218 -0
  51. package/dist/{job-6PNXXZNF.js → job-55IKS6LP.js} +65 -13
  52. package/dist/{login-Y7JBAHCW.js → login-DPZ6CXNO.js} +13 -4
  53. package/dist/{message-2IK4MBBG.js → message-J44YKRDS.js} +9 -7
  54. package/dist/{motion-7ATUXO6R.js → motion-SQI5F2EK.js} +39 -117
  55. package/dist/network-K4QD7APQ.js +235 -0
  56. package/dist/{notification-VYK5NDEB.js → notification-SEDXZHXO.js} +38 -11
  57. package/dist/notifications-HGIBRUNQ.js +231 -0
  58. package/dist/{post-AN6T2OJF.js → post-L467SKIG.js} +92 -12
  59. package/dist/{profile-UQY64642.js → profile-A2N6RMR2.js} +76 -20
  60. package/dist/{recruiter-OY4RN5HH.js → recruiter-AR75RHBO.js} +133 -22
  61. package/dist/{sales-nav-KLODLYMW.js → sales-nav-C2AYFXPV.js} +74 -19
  62. package/dist/{search-NWP5S6CF.js → search-Z4DZIG4X.js} +55 -23
  63. package/dist/{setup-YPPFLH2N.js → setup-45BEVX6B.js} +69 -17
  64. package/dist/team-6QWY4IFP.js +450 -0
  65. package/dist/tier-2HS3BXDF.js +61 -0
  66. package/dist/unibox-DHUKG65Z.js +402 -0
  67. package/dist/{webhook-OHKBL3YS.js → webhook-Q53WUAI2.js} +257 -27
  68. package/package.json +2 -2
  69. package/dist/chunk-D2S5OCYU.js +0 -38
  70. package/dist/core-RGU2SCBN.js +0 -46
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/lib/write-atomic.ts
4
+ import { closeSync, openSync, renameSync, unlinkSync, writeSync, fchmodSync } from "fs";
5
+ import { basename, dirname, join } from "path";
6
+ function writeAtomic(path, bytes) {
7
+ const tmp = join(dirname(path), `.${basename(path)}.${process.pid}.tmp`);
8
+ let fd;
9
+ try {
10
+ fd = openSync(tmp, "wx", 384);
11
+ fchmodSync(fd, 384);
12
+ writeSync(fd, bytes);
13
+ closeSync(fd);
14
+ fd = void 0;
15
+ renameSync(tmp, path);
16
+ } catch (err) {
17
+ if (fd !== void 0) closeSync(fd);
18
+ try {
19
+ unlinkSync(tmp);
20
+ } catch {
21
+ }
22
+ throw err;
23
+ }
24
+ }
25
+
26
+ export {
27
+ writeAtomic
28
+ };
@@ -0,0 +1,144 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ renderNotices,
4
+ renderProvenanceNote
5
+ } from "./chunk-QM57YDJE.js";
6
+ import {
7
+ isPlainObject
8
+ } from "./chunk-YXVF5UST.js";
9
+
10
+ // src/lib/paginate.ts
11
+ import { CurviateError } from "@curviate/sdk";
12
+ function readablePage(page) {
13
+ const list = isPlainObject(page) ? page["items"] === void 0 ? page["data"] : page["items"] : void 0;
14
+ if (!Array.isArray(list)) throw unreadable("list page");
15
+ return { ...page, items: list };
16
+ }
17
+ function readableId(entity) {
18
+ const id = isPlainObject(entity) ? entity["id"] : void 0;
19
+ if ((typeof id !== "string" || id === "") && !(typeof id === "number" && Number.isFinite(id))) throw unreadable("id");
20
+ return String(id);
21
+ }
22
+ function readableObject(data) {
23
+ if (!isPlainObject(data) || Object.keys(data).length === 0) throw unreadable("object");
24
+ return data;
25
+ }
26
+ function rejectPaginationModifiersWithoutAll(flags, out) {
27
+ if (flags.all) return;
28
+ const offender = flags["max-pages"] !== void 0 ? "--max-pages" : flags["page-delay"] !== void 0 ? "--page-delay" : null;
29
+ if (!offender) return;
30
+ out.stderr.write(`error: ${offender} requires --all; without it, streaming never engages so the flag does nothing.
31
+ `);
32
+ process.exit(2);
33
+ }
34
+ var DEFAULT_MAX_PAGES = 100;
35
+ function readCursorFlag(flags, out) {
36
+ const raw = flags.cursor;
37
+ if (raw === void 0) return void 0;
38
+ if (raw.trim() === "") {
39
+ out.stderr.write(
40
+ "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"
41
+ );
42
+ process.exit(2);
43
+ }
44
+ return raw;
45
+ }
46
+ function readMaxPagesFlag(flags, out) {
47
+ const raw = flags["max-pages"];
48
+ if (raw === void 0) return DEFAULT_MAX_PAGES;
49
+ if (!/^\d+$/.test(raw) || Number(raw) < 1) {
50
+ out.stderr.write(
51
+ `error: --max-pages must be a positive integer (got ${JSON.stringify(raw)}); it is the number of pages --all may fetch.
52
+ `
53
+ );
54
+ process.exit(2);
55
+ }
56
+ return Number(raw);
57
+ }
58
+ function unreadable(what) {
59
+ return new CurviateError({
60
+ code: "PLATFORM_ERROR",
61
+ message: `The API answered without a readable ${what}.`,
62
+ // The status the client gives every synthesized unreadable-2xx fault.
63
+ httpStatus: 502,
64
+ userFixable: false,
65
+ retryLikelyToSucceed: true
66
+ });
67
+ }
68
+ function truncationProseNote(pagesFetched) {
69
+ return `Streaming truncated at ${pagesFetched} page(s). Use --all --max-pages or --cursor for manual paging.
70
+ `;
71
+ }
72
+ function ndjsonModeNotice() {
73
+ return "--all streams NDJSON: one object per line; the {items,cursor} envelope is not used\n";
74
+ }
75
+ var DEFAULT_PAGE_DELAY_MS = 400;
76
+ function pageDelayFrom(raw) {
77
+ if (raw === void 0 || raw === "") return void 0;
78
+ const n = Number(raw);
79
+ if (!Number.isInteger(n) || n < 0) return void 0;
80
+ return n;
81
+ }
82
+ function pageDelayFromFlags(flags) {
83
+ return pageDelayFrom(flags["page-delay"]);
84
+ }
85
+ var realSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
86
+ function truncationSentinelLine(pagesFetched, hasMore) {
87
+ return JSON.stringify({ object: "stream_truncated", pages_fetched: pagesFetched, has_more: hasMore }) + "\n";
88
+ }
89
+ async function* streamAll(fn, params, opts = {}) {
90
+ const maxPages = opts.maxPages ?? DEFAULT_MAX_PAGES;
91
+ const pageDelayMs = opts.pageDelayMs ?? DEFAULT_PAGE_DELAY_MS;
92
+ const sleep = opts.sleep ?? realSleep;
93
+ let cursor = void 0;
94
+ let pageCount = 0;
95
+ let firstPage = true;
96
+ while (true) {
97
+ const pageParams = cursor !== void 0 && cursor !== null ? { ...params, cursor } : params;
98
+ const page = readablePage(await fn(pageParams));
99
+ pageCount++;
100
+ const items = page.items;
101
+ if (firstPage) {
102
+ if (opts.out) opts.out.stderr.write(ndjsonModeNotice());
103
+ firstPage = false;
104
+ }
105
+ if (opts.out) {
106
+ const pageNotices = renderNotices(page.notices);
107
+ if (pageNotices) opts.out.stderr.write(pageNotices + "\n");
108
+ const pageProvenance = renderProvenanceNote(page);
109
+ if (pageProvenance) opts.out.stderr.write(pageProvenance);
110
+ }
111
+ if (Array.isArray(items)) {
112
+ for (const item of items) {
113
+ yield item;
114
+ }
115
+ }
116
+ cursor = page.cursor;
117
+ if (!cursor) break;
118
+ if (pageCount >= maxPages) {
119
+ const hasMore = cursor !== null && cursor !== void 0;
120
+ if (opts.out) {
121
+ opts.out.stdout.write(truncationSentinelLine(pageCount, hasMore));
122
+ opts.out.stderr.write(truncationProseNote(pageCount));
123
+ }
124
+ if (opts.onTruncated) {
125
+ opts.onTruncated(pageCount, hasMore);
126
+ }
127
+ break;
128
+ }
129
+ if (pageDelayMs > 0) await sleep(pageDelayMs);
130
+ }
131
+ }
132
+
133
+ export {
134
+ readablePage,
135
+ readableId,
136
+ readableObject,
137
+ rejectPaginationModifiersWithoutAll,
138
+ readCursorFlag,
139
+ readMaxPagesFlag,
140
+ ndjsonModeNotice,
141
+ DEFAULT_PAGE_DELAY_MS,
142
+ pageDelayFromFlags,
143
+ streamAll
144
+ };
@@ -6,7 +6,7 @@ var MAX_AGE_CEILING_SECONDS = 31536e3;
6
6
  var RETRIEVAL_FLAGS = {
7
7
  mode: {
8
8
  type: "string",
9
- description: "How willing this read is to reach LinkedIn: auto (default, a stored copy while it is fresh), live (always fetch), refill (a stored copy at any age, fetch only when nothing is stored), cache_only (never fetch; a store miss is refused rather than fetched). Not combinable with --max-age under cache_only."
9
+ description: "How willing this read is to reach LinkedIn: auto (default, a stored copy while it is fresh), live (always fetch), refill (a stored copy at any age: fetches at most once, until swept; a record nothing links to and nobody has read lately is deleted, and the next read fetches it again), cache_only (never fetch; a store miss is refused rather than fetched). Not combinable with --max-age under cache_only."
10
10
  },
11
11
  "max-age": {
12
12
  type: "string",
@@ -8,36 +8,43 @@ import {
8
8
  BinaryOutputError,
9
9
  writeBinaryOutput
10
10
  } from "./chunk-UWO2D4HW.js";
11
+ import {
12
+ AS_ACCOUNT,
13
+ BUDGET,
14
+ TARGET
15
+ } from "./chunk-UWQPX4AE.js";
11
16
  import {
12
17
  normalizeChatId,
13
18
  resolveIdentifier
14
19
  } from "./chunk-UEAX6KUB.js";
15
20
  import {
16
21
  requireAccount
17
- } from "./chunk-V7FJWTZW.js";
22
+ } from "./chunk-25MO7BYN.js";
18
23
  import {
19
24
  buildPreviewOutput
20
25
  } from "./chunk-TCUYH5GO.js";
21
26
  import {
22
27
  readableId,
23
- readableObject,
28
+ readableObject
29
+ } from "./chunk-L4CIJT6F.js";
30
+ import {
24
31
  renderError,
25
32
  renderSuccess,
26
- renderUnexpectedError,
27
- resolveEffectiveConfig
28
- } from "./chunk-SA2QHAXG.js";
33
+ renderUnexpectedError
34
+ } from "./chunk-QM57YDJE.js";
29
35
  import {
30
36
  createClient,
31
- downloadBinary
32
- } from "./chunk-5ZGTU4VD.js";
37
+ downloadBinary,
38
+ resolveEffectiveConfig
39
+ } from "./chunk-YXVF5UST.js";
33
40
  import {
34
41
  READ_SINGLE_FLAGS,
35
42
  WRITE_FLAGS,
36
43
  readOnly
37
- } from "./chunk-Y7MZZRYR.js";
44
+ } from "./chunk-RYWWSZUH.js";
38
45
  import {
39
46
  DESCRIPTIONS
40
- } from "./chunk-D2S5OCYU.js";
47
+ } from "./chunk-73DJ3KNE.js";
41
48
  import {
42
49
  looksLikeCommandWord,
43
50
  nearestSubcommand
@@ -110,7 +117,7 @@ var MEMBER_PROVIDER_ID_RE = /^A[CDE][A-Za-z0-9_-]{4,}$/;
110
117
  async function handleSdkError(err, outOpts, out) {
111
118
  const { CurviateError } = await import("@curviate/sdk");
112
119
  if (err instanceof CurviateError) {
113
- const { getExitCode } = await import("./exit-codes-TLMKTLRI.js");
120
+ const { getExitCode } = await import("./exit-codes-7DBETBDT.js");
114
121
  renderError(err, outOpts, out);
115
122
  process.exit(getExitCode(err));
116
123
  }
@@ -421,6 +428,15 @@ var messageNewCommand = defineCommand({
421
428
  meta: {
422
429
  name: "new",
423
430
  description: "Start a new chat with one or more members.",
431
+ risk: "write",
432
+ rules: {
433
+ changes: "Starts a chat with the recipient and sends the opening message from your Account.",
434
+ visible_to: "The recipient, in their LinkedIn inbox.",
435
+ budget_rows: ["messages_first_degree"],
436
+ retry: "Not safe: requests carry no idempotency key, so a retry after a timeout can repeat it. Read `curviate core inbox list` first.",
437
+ undo: "`curviate core message delete <chat_id> <message_id>` removes the message; the chat stays and the recipient may have read it."
438
+ },
439
+ errors: { ...AS_ACCOUNT, ...BUDGET, ...TARGET, RECIPIENT_UNREACHABLE: "LinkedIn will not let the Account message this person." },
424
440
  examples: [
425
441
  'curviate core message new --to janesmith "Hi Jane, enjoyed your post on agent evals."'
426
442
  ]
@@ -462,6 +478,7 @@ var messageGetCommand = defineCommand({
462
478
  meta: {
463
479
  name: "get",
464
480
  description: "Get a message by ID.",
481
+ risk: "read",
465
482
  examples: [
466
483
  "curviate core message get 2-YTQ3ODU3Njgt MSG_ID"
467
484
  ]
@@ -494,6 +511,15 @@ var messageEditCommand = defineCommand({
494
511
  meta: {
495
512
  name: "edit",
496
513
  description: "Edit a message (within the allowed window).",
514
+ risk: "write",
515
+ rules: {
516
+ changes: "Replaces the text of one of your messages.",
517
+ visible_to: "The other participants of the chat.",
518
+ budget_rows: [],
519
+ retry: "Safe: the same text written again leaves the message the same.",
520
+ undo: "Edit it again with the previous text, while LinkedIn still allows edits."
521
+ },
522
+ errors: { ...AS_ACCOUNT, ...TARGET },
497
523
  examples: [
498
524
  'curviate core message edit 2-YTQ3ODU3Njgt MSG_ID "Thanks, that makes sense to me."'
499
525
  ]
@@ -527,6 +553,17 @@ var messageDeleteCommand = defineCommand({
527
553
  meta: {
528
554
  name: "delete",
529
555
  description: "Delete a message.",
556
+ risk: "high",
557
+ rules: {
558
+ changes: "Deletes one message from the chat.",
559
+ visible_to: "The other participants no longer see it.",
560
+ budget_rows: [],
561
+ retry: "Safe: a deleted message is gone, so a repeat has nothing to delete.",
562
+ undo: "Cannot be undone.",
563
+ blast_radius: "One message."
564
+ },
565
+ errors: { ...AS_ACCOUNT, ...TARGET },
566
+ seeAlso: ["curviate core inbox messages"],
530
567
  examples: [
531
568
  "curviate core message delete 2-YTQ3ODU3Njgt MSG_ID"
532
569
  ]
@@ -559,6 +596,15 @@ var messageReactCommand = defineCommand({
559
596
  meta: {
560
597
  name: "react",
561
598
  description: "Add an emoji reaction to a message.",
599
+ risk: "write",
600
+ rules: {
601
+ changes: "Adds your emoji reaction to the message.",
602
+ visible_to: "The other participants of the chat.",
603
+ budget_rows: ["post_likes"],
604
+ retry: "Read the message first: a repeat with the same emoji may count against the budget again.",
605
+ undo: "React again to change it; the CLI has no command to remove a reaction."
606
+ },
607
+ errors: { ...AS_ACCOUNT, ...BUDGET, ...TARGET },
562
608
  examples: [
563
609
  "curviate core message react 2-YTQ3ODU3Njgt MSG_ID \u{1F44D}"
564
610
  ],
@@ -600,6 +646,7 @@ var messageAttachmentCommand = defineCommand({
600
646
  meta: {
601
647
  name: "attachment",
602
648
  description: "Download a message attachment.",
649
+ risk: "read",
603
650
  examples: [
604
651
  "curviate core message attachment 2-YTQ3ODU3Njgt MSG_ID ATTACHMENT_ID -o attachment.pdf"
605
652
  ]
@@ -639,6 +686,15 @@ var messageInMailCommand = defineCommand({
639
686
  meta: {
640
687
  name: "inmail",
641
688
  description: "Send an InMail to a member.",
689
+ risk: "write",
690
+ rules: {
691
+ changes: "Sends an InMail to the member.",
692
+ visible_to: "The recipient.",
693
+ budget_rows: ["inmail"],
694
+ retry: "Not safe: requests carry no idempotency key, so a retry after a timeout can repeat it. Read `curviate core inbox list` first.",
695
+ undo: "Cannot be undone."
696
+ },
697
+ errors: { ...AS_ACCOUNT, ...BUDGET, ...TARGET, RECIPIENT_UNREACHABLE: "LinkedIn will not let the Account message this person." },
642
698
  examples: [
643
699
  'curviate core message inmail --to janesmith --subject "Agent tooling" "Hi Jane, a quick question about your eval setup."'
644
700
  ]
@@ -676,6 +732,15 @@ var messageSendCommand = defineCommand({
676
732
  meta: {
677
733
  name: "send",
678
734
  description: 'Send a message to an existing chat. Pass a COMPANY_ chat id (from `curviate core inboxes chats`) to send as that company page instead of yourself, no separate flag needed. The output shows the acting identity: a company-page send prints "Sent as <name> (company page)", a personal send prints nothing new. See also: `curviate core inboxes chats` (discover a COMPANY_ chat id) and the Reply as a company page guide.',
735
+ risk: "write",
736
+ rules: {
737
+ changes: "Sends the text into the chat, as you, or as the page for a COMPANY_ chat id.",
738
+ visible_to: "The other participants of the chat.",
739
+ budget_rows: ["messages_first_degree"],
740
+ retry: "Not safe: requests carry no idempotency key, so a retry after a timeout can repeat it. Read `curviate core inbox messages <chat_id>` first.",
741
+ undo: "`curviate core message delete <chat_id> <message_id>`; it may already have been read."
742
+ },
743
+ errors: { ...AS_ACCOUNT, ...BUDGET, ...TARGET, RECIPIENT_UNREACHABLE: "LinkedIn will not let the Account message this person.", CHAT_NOT_VISIBLE: "the chat is not visible to the Account." },
679
744
  examples: [
680
745
  'curviate core message send 2-YTQ3ODU3Njgt "Thanks, that makes sense."'
681
746
  ]
@@ -712,6 +777,7 @@ var messageInMailBalanceCommand = defineCommand({
712
777
  meta: {
713
778
  name: "inmail-balance",
714
779
  description: "Get InMail credit balance.",
780
+ risk: "read",
715
781
  examples: [
716
782
  "curviate core message inmail-balance"
717
783
  ]
@@ -774,6 +840,15 @@ var messageCommand = defineCommand({
774
840
  meta: {
775
841
  name: "message",
776
842
  description: DESCRIPTIONS.message,
843
+ risk: "write",
844
+ rules: {
845
+ changes: "Sends the text into the chat, as you, or as the page for a COMPANY_ chat id.",
846
+ visible_to: "The other participants of the chat.",
847
+ budget_rows: ["messages_first_degree"],
848
+ retry: "Not safe: requests carry no idempotency key, so a retry after a timeout can repeat it. Read `curviate core inbox messages <chat_id>` first.",
849
+ undo: "`curviate core message delete <chat_id> <message_id>`; it may already have been read."
850
+ },
851
+ errors: { ...AS_ACCOUNT, ...BUDGET, ...TARGET, RECIPIENT_UNREACHABLE: "LinkedIn will not let the Account message this person.", CHAT_NOT_VISIBLE: "the chat is not visible to the Account." },
777
852
  examples: [
778
853
  'curviate core message 2-YTQ3ODU3Njgt "Thanks, that makes sense."',
779
854
  'curviate core message 2-YTQ3ODU3Njgt "See the attached brief." --attach brief.pdf'
@@ -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
+ };
@@ -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 isPlainObject2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
88
+ const isPlainObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
99
89
  if (Array.isArray(data)) {
100
- return data.length > 0 && isPlainObject2(data[0]) ? data[0] : null;
90
+ return data.length > 0 && isPlainObject(data[0]) ? data[0] : null;
101
91
  }
102
- if (isPlainObject2(data)) {
92
+ if (isPlainObject(data)) {
103
93
  const items = data["items"];
104
94
  if (Array.isArray(items)) {
105
- return items.length > 0 && isPlainObject2(items[0]) ? items[0] : null;
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
- let body = items.length === 0 ? "(no items)" : items.map(renderHuman).join("\n");
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
  };