@curviate/cli 0.13.0 → 0.15.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.
@@ -1,10 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
- streamAll
4
- } from "./chunk-GXTZION6.js";
3
+ buildPreviewOutput
4
+ } from "./chunk-R3VLWLVV.js";
5
5
  import {
6
6
  normalizeChatId
7
7
  } from "./chunk-DMQZEPQE.js";
8
+ import {
9
+ streamAll
10
+ } from "./chunk-DNTRQZBT.js";
8
11
  import {
9
12
  createClient,
10
13
  renderError,
@@ -14,7 +17,8 @@ import {
14
17
  } from "./chunk-JXF47TRY.js";
15
18
  import {
16
19
  GLOBAL_FLAGS,
17
- READ_SINGLE_FLAGS
20
+ READ_SINGLE_FLAGS,
21
+ WRITE_SINGLE_FLAGS
18
22
  } from "./chunk-4JHGVY7R.js";
19
23
 
20
24
  // src/commands/inbox.ts
@@ -69,7 +73,7 @@ function validateIsoZTimestamp(value, flagName, out) {
69
73
  async function handleSdkError(err, outOpts, out) {
70
74
  const { CurviateError } = await import("@curviate/sdk");
71
75
  if (err instanceof CurviateError) {
72
- const { getExitCode } = await import("./exit-codes-ZTY2NY3X.js");
76
+ const { getExitCode } = await import("./exit-codes-SL3GQF7W.js");
73
77
  renderError(err, outOpts, out);
74
78
  process.exit(getExitCode(err.code));
75
79
  }
@@ -92,8 +96,7 @@ async function runInboxList(client, flags, out) {
92
96
  const fn = (p) => ns.messaging.listChats(p);
93
97
  for await (const item of streamAll(fn, params, {
94
98
  maxPages,
95
- onTruncated: (n) => out.stderr.write(`Streaming truncated at ${n} page(s). Use --all --max-pages or --cursor for manual paging.
96
- `)
99
+ out
97
100
  })) {
98
101
  out.stdout.write(JSON.stringify(item) + "\n");
99
102
  }
@@ -119,6 +122,24 @@ async function runInboxGet(client, flags, out) {
119
122
  await handleSdkError(err, outOpts, out);
120
123
  }
121
124
  }
125
+ async function runInboxMarkRead(client, flags, out) {
126
+ const accountId = requireAccount(flags.account, out);
127
+ const chatId = normalizeChatId(flags.chatId ?? "");
128
+ const body = { read: true };
129
+ if (flags.preview) {
130
+ const preview = buildPreviewOutput({ method: "messaging.markChatRead", args: { chat_id: chatId }, body, account: accountId });
131
+ out.stdout.write(JSON.stringify(preview) + "\n");
132
+ return;
133
+ }
134
+ const ns = client.account(accountId);
135
+ const outOpts = resolveOutputOpts(flags);
136
+ try {
137
+ const result = await ns.messaging.markChatRead(chatId, body);
138
+ renderSuccess(result, outOpts, out);
139
+ } catch (err) {
140
+ await handleSdkError(err, outOpts, out);
141
+ }
142
+ }
122
143
  async function runInboxMessages(client, flags, out) {
123
144
  rejectPreviewOnRead(flags.preview, out);
124
145
  const accountId = requireAccount(flags.account, out);
@@ -141,8 +162,7 @@ async function runInboxMessages(client, flags, out) {
141
162
  const fn = (p) => ns.messaging.listMessages(chatId, p);
142
163
  for await (const item of streamAll(fn, params, {
143
164
  maxPages,
144
- onTruncated: (n) => out.stderr.write(`Streaming truncated at ${n} page(s). Use --all --max-pages or --cursor for manual paging.
145
- `)
165
+ out
146
166
  })) {
147
167
  out.stdout.write(JSON.stringify(item) + "\n");
148
168
  }
@@ -154,61 +174,6 @@ async function runInboxMessages(client, flags, out) {
154
174
  await handleSdkError(err, outOpts, out);
155
175
  }
156
176
  }
157
- async function runInboxSync(client, flags, out) {
158
- rejectPreviewOnRead(flags.preview, out);
159
- rejectAllOnNonPaginated(flags.all, out);
160
- const accountId = requireAccount(flags.account, out);
161
- const ns = client.account(accountId);
162
- const outOpts = resolveOutputOpts(flags);
163
- try {
164
- const result = await ns.messaging.syncMessages();
165
- renderSuccess(result, outOpts, out);
166
- } catch (err) {
167
- await handleSdkError(err, outOpts, out);
168
- }
169
- }
170
- var SYNC_TERMINAL_STATUSES = /* @__PURE__ */ new Set(["done", "error", "chat_deleted"]);
171
- var SYNC_POLL_INTERVAL_MS = 2e3;
172
- async function runInboxSyncChat(client, flags, out, _sleep) {
173
- rejectPreviewOnRead(flags.preview, out);
174
- rejectAllOnNonPaginated(flags.all, out);
175
- const accountId = requireAccount(flags.account, out);
176
- const chatId = normalizeChatId(flags.chatId ?? "");
177
- const ns = client.account(accountId);
178
- const outOpts = resolveOutputOpts(flags);
179
- if (!flags.wait) {
180
- try {
181
- const result = await ns.messaging.syncChat(chatId);
182
- renderSuccess(result, outOpts, out);
183
- } catch (err) {
184
- await handleSdkError(err, outOpts, out);
185
- }
186
- return;
187
- }
188
- const sleep = _sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
189
- const timeoutSecs = parseInt(flags.timeout ?? "30", 10);
190
- const timeoutMs = (Number.isNaN(timeoutSecs) ? 30 : timeoutSecs) * 1e3;
191
- const startTime = Date.now();
192
- while (true) {
193
- let result;
194
- try {
195
- result = await ns.messaging.syncChat(chatId);
196
- } catch (err) {
197
- await handleSdkError(err, outOpts, out);
198
- }
199
- const resp = result;
200
- if (resp.status !== void 0 && SYNC_TERMINAL_STATUSES.has(resp.status)) {
201
- renderSuccess(result, outOpts, out);
202
- return;
203
- }
204
- if (Date.now() - startTime >= timeoutMs) {
205
- renderSuccess(result, outOpts, out);
206
- process.exit(3);
207
- return;
208
- }
209
- await sleep(SYNC_POLL_INTERVAL_MS);
210
- }
211
- }
212
177
  var inboxListCommand = defineCommand({
213
178
  meta: { name: "list", description: "List inbox chats." },
214
179
  args: {
@@ -262,43 +227,12 @@ var inboxGetCommand = defineCommand({
262
227
  await runInboxGet(client, { ...flags, account: flags.account ?? cfg.account }, out);
263
228
  }
264
229
  });
265
- var inboxMessagesCommand = defineCommand({
266
- meta: { name: "messages", description: "List messages in a chat." },
267
- args: {
268
- ...GLOBAL_FLAGS,
269
- chatId: { type: "positional", description: "Chat ID." },
270
- before: {
271
- type: "string",
272
- description: "Return messages before this timestamp (ISO-8601, UTC \u2014 Z suffix required, e.g. 2025-01-01T00:00:00Z)."
273
- },
274
- after: {
275
- type: "string",
276
- description: "Return messages after this timestamp (ISO-8601, UTC \u2014 Z suffix required, e.g. 2025-01-01T00:00:00Z)."
277
- }
278
- },
279
- async run({ args }) {
280
- const flags = args;
281
- const cfg = await resolveEffectiveConfig({
282
- apiKey: flags["api-key"],
283
- baseUrl: flags["base-url"],
284
- timeout: flags.timeout,
285
- account: flags.account,
286
- profile: flags.profile
287
- });
288
- if (!cfg.apiKey) {
289
- process.stderr.write("error: no API key \u2014 run `curviate login` or pass --api-key.\n");
290
- process.exit(3);
291
- }
292
- const client = createClient({ apiKey: cfg.apiKey, baseUrl: cfg.baseUrl, timeout: cfg.timeout });
293
- const out = buildOutputStreams();
294
- await runInboxMessages(client, { ...flags, account: flags.account ?? cfg.account }, out);
295
- }
296
- });
297
- var inboxSyncCommand = defineCommand({
298
- meta: { name: "sync", description: "Re-sync account message history." },
230
+ var inboxMarkReadCommand = defineCommand({
231
+ meta: { name: "mark-read", description: "Mark a chat as read." },
299
232
  args: {
300
- // Single-object read: READ_SINGLE_FLAGS omits pagination flags, keeps --fields
301
- ...READ_SINGLE_FLAGS
233
+ // Write command: WRITE_SINGLE_FLAGS omits pagination flags, keeps --fields
234
+ ...WRITE_SINGLE_FLAGS,
235
+ chatId: { type: "positional", description: "Chat ID or LinkedIn messaging thread URL." }
302
236
  },
303
237
  async run({ args }) {
304
238
  const flags = args;
@@ -315,26 +249,21 @@ var inboxSyncCommand = defineCommand({
315
249
  }
316
250
  const client = createClient({ apiKey: cfg.apiKey, baseUrl: cfg.baseUrl, timeout: cfg.timeout });
317
251
  const out = buildOutputStreams();
318
- await runInboxSync(client, { ...flags, account: flags.account ?? cfg.account }, out);
252
+ await runInboxMarkRead(client, { ...flags, account: flags.account ?? cfg.account }, out);
319
253
  }
320
254
  });
321
- var inboxSyncChatCommand = defineCommand({
322
- meta: { name: "sync-chat", description: "Re-sync a specific chat's message history." },
255
+ var inboxMessagesCommand = defineCommand({
256
+ meta: { name: "messages", description: "List messages in a chat." },
323
257
  args: {
324
- // Single-object read: READ_SINGLE_FLAGS omits pagination flags, keeps --fields.
325
- // The timeout below overrides READ_SINGLE_FLAGS.timeout with a command-specific description.
326
- ...READ_SINGLE_FLAGS,
258
+ ...GLOBAL_FLAGS,
327
259
  chatId: { type: "positional", description: "Chat ID." },
328
- wait: {
329
- type: "boolean",
330
- description: "Poll until sync completes (or --timeout elapses).",
331
- default: false
260
+ before: {
261
+ type: "string",
262
+ description: "Return messages before this timestamp (ISO-8601, UTC \u2014 Z suffix required, e.g. 2025-01-01T00:00:00Z)."
332
263
  },
333
- // Override READ_SINGLE_FLAGS.timeout: here --timeout is the polling wait timeout
334
- // in seconds (default: 30), not the SDK request timeout.
335
- timeout: {
264
+ after: {
336
265
  type: "string",
337
- description: "Polling timeout in seconds (default: 30, requires --wait)."
266
+ description: "Return messages after this timestamp (ISO-8601, UTC \u2014 Z suffix required, e.g. 2025-01-01T00:00:00Z)."
338
267
  }
339
268
  },
340
269
  async run({ args }) {
@@ -342,6 +271,7 @@ var inboxSyncChatCommand = defineCommand({
342
271
  const cfg = await resolveEffectiveConfig({
343
272
  apiKey: flags["api-key"],
344
273
  baseUrl: flags["base-url"],
274
+ timeout: flags.timeout,
345
275
  account: flags.account,
346
276
  profile: flags.profile
347
277
  });
@@ -351,21 +281,20 @@ var inboxSyncChatCommand = defineCommand({
351
281
  }
352
282
  const client = createClient({ apiKey: cfg.apiKey, baseUrl: cfg.baseUrl, timeout: cfg.timeout });
353
283
  const out = buildOutputStreams();
354
- await runInboxSyncChat(client, { ...flags, account: flags.account ?? cfg.account }, out);
284
+ await runInboxMessages(client, { ...flags, account: flags.account ?? cfg.account }, out);
355
285
  }
356
286
  });
357
287
  var inboxCommand = defineCommand({
358
- meta: { name: "inbox", description: "Read and sync LinkedIn message inbox." },
288
+ meta: { name: "inbox", description: "Read LinkedIn message inbox." },
359
289
  subCommands: {
360
290
  list: inboxListCommand,
361
291
  get: inboxGetCommand,
362
- messages: inboxMessagesCommand,
363
- sync: inboxSyncCommand,
364
- "sync-chat": inboxSyncChatCommand
292
+ "mark-read": inboxMarkReadCommand,
293
+ messages: inboxMessagesCommand
365
294
  },
366
295
  async run() {
367
296
  process.stderr.write(
368
- "Usage: curviate inbox <subcommand>\n list\n get <chat_id>\n messages <chat_id>\n sync\n sync-chat <chat_id>\n"
297
+ "Usage: curviate inbox <subcommand>\n list\n get <chat_id>\n mark-read <chat_id>\n messages <chat_id>\n"
369
298
  );
370
299
  }
371
300
  });
@@ -373,7 +302,6 @@ export {
373
302
  inboxCommand,
374
303
  runInboxGet,
375
304
  runInboxList,
376
- runInboxMessages,
377
- runInboxSync,
378
- runInboxSyncChat
305
+ runInboxMarkRead,
306
+ runInboxMessages
379
307
  };