@hipnation-truth/sdk 0.17.1 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -266,6 +266,19 @@ interface SetConversationTaskStatusInput {
266
266
  status: ConversationTaskStatus;
267
267
  resolvedBy?: string;
268
268
  }
269
+ interface UpdateConversationTaskInput {
270
+ taskId: string;
271
+ /** Conversation the task belongs to. Truth requires this on PATCH. */
272
+ conversationId: string;
273
+ /** Required by the Truth task router — see `messages/procedures/tasks.ts`. */
274
+ author: string;
275
+ description: string;
276
+ /** Optional patch fields — pass only the ones you want to change. */
277
+ priority?: ConversationTaskPriority;
278
+ status?: ConversationTaskStatus;
279
+ assignee?: string;
280
+ type?: string;
281
+ }
269
282
  interface SendConversationMessageInput {
270
283
  fromNumber: string;
271
284
  toNumber: string;
@@ -291,7 +304,8 @@ declare class ConversationNotesSubresource {
291
304
  }
292
305
  declare class ConversationTasksSubresource {
293
306
  private readonly post;
294
- constructor(post: <T>(path: string, body: unknown) => Promise<T>);
307
+ private readonly patch;
308
+ constructor(post: <T>(path: string, body: unknown) => Promise<T>, patch: <T>(path: string, body: unknown) => Promise<T>);
295
309
  /** Create a task on a conversation. */
296
310
  create(input: CreateConversationTaskInput): Promise<{
297
311
  id: string;
@@ -300,6 +314,14 @@ declare class ConversationTasksSubresource {
300
314
  setStatus(input: SetConversationTaskStatusInput): Promise<{
301
315
  ok: true;
302
316
  }>;
317
+ /**
318
+ * Update task fields (priority, assignee, description, type). Wraps
319
+ * `PATCH /api/conversations/tasks/{id}` so CommHub doesn't have to
320
+ * direct-fetch for non-status field edits.
321
+ */
322
+ update(input: UpdateConversationTaskInput): Promise<{
323
+ ok: true;
324
+ }>;
303
325
  }
304
326
  declare class ConversationMessagesSubresource {
305
327
  private readonly post;
@@ -354,6 +376,13 @@ declare class ConversationsResource {
354
376
  cleared: number;
355
377
  }>;
356
378
  private postRequest;
379
+ /**
380
+ * PATCH variant of `postRequest`. Mirrors the timeout + API-key
381
+ * handling so callers like `tasks.update()` don't need to roll their
382
+ * own fetch. The Truth task router treats unknown methods as 405, so
383
+ * a dedicated PATCH path is required.
384
+ */
385
+ private patchRequest;
357
386
  }
358
387
 
359
388
  /**
package/dist/index.d.ts CHANGED
@@ -266,6 +266,19 @@ interface SetConversationTaskStatusInput {
266
266
  status: ConversationTaskStatus;
267
267
  resolvedBy?: string;
268
268
  }
269
+ interface UpdateConversationTaskInput {
270
+ taskId: string;
271
+ /** Conversation the task belongs to. Truth requires this on PATCH. */
272
+ conversationId: string;
273
+ /** Required by the Truth task router — see `messages/procedures/tasks.ts`. */
274
+ author: string;
275
+ description: string;
276
+ /** Optional patch fields — pass only the ones you want to change. */
277
+ priority?: ConversationTaskPriority;
278
+ status?: ConversationTaskStatus;
279
+ assignee?: string;
280
+ type?: string;
281
+ }
269
282
  interface SendConversationMessageInput {
270
283
  fromNumber: string;
271
284
  toNumber: string;
@@ -291,7 +304,8 @@ declare class ConversationNotesSubresource {
291
304
  }
292
305
  declare class ConversationTasksSubresource {
293
306
  private readonly post;
294
- constructor(post: <T>(path: string, body: unknown) => Promise<T>);
307
+ private readonly patch;
308
+ constructor(post: <T>(path: string, body: unknown) => Promise<T>, patch: <T>(path: string, body: unknown) => Promise<T>);
295
309
  /** Create a task on a conversation. */
296
310
  create(input: CreateConversationTaskInput): Promise<{
297
311
  id: string;
@@ -300,6 +314,14 @@ declare class ConversationTasksSubresource {
300
314
  setStatus(input: SetConversationTaskStatusInput): Promise<{
301
315
  ok: true;
302
316
  }>;
317
+ /**
318
+ * Update task fields (priority, assignee, description, type). Wraps
319
+ * `PATCH /api/conversations/tasks/{id}` so CommHub doesn't have to
320
+ * direct-fetch for non-status field edits.
321
+ */
322
+ update(input: UpdateConversationTaskInput): Promise<{
323
+ ok: true;
324
+ }>;
303
325
  }
304
326
  declare class ConversationMessagesSubresource {
305
327
  private readonly post;
@@ -354,6 +376,13 @@ declare class ConversationsResource {
354
376
  cleared: number;
355
377
  }>;
356
378
  private postRequest;
379
+ /**
380
+ * PATCH variant of `postRequest`. Mirrors the timeout + API-key
381
+ * handling so callers like `tasks.update()` don't need to roll their
382
+ * own fetch. The Truth task router treats unknown methods as 405, so
383
+ * a dedicated PATCH path is required.
384
+ */
385
+ private patchRequest;
357
386
  }
358
387
 
359
388
  /**
package/dist/index.js CHANGED
@@ -312,6 +312,15 @@ var ConversationsError = class extends Error {
312
312
  this.status = status;
313
313
  }
314
314
  };
315
+ function assertConversationAddress(operation, input) {
316
+ if (!input.conversationId && !input.phonePair) {
317
+ throw new ConversationsError(
318
+ operation,
319
+ 0,
320
+ "Either `conversationId` or `phonePair` is required"
321
+ );
322
+ }
323
+ }
315
324
  var ConversationNotesSubresource = class {
316
325
  constructor(post) {
317
326
  this.post = post;
@@ -319,17 +328,20 @@ var ConversationNotesSubresource = class {
319
328
  /** Create a note on a conversation (addressed by id or phonePair). */
320
329
  create(input) {
321
330
  return __async(this, null, function* () {
331
+ assertConversationAddress("notes.create", input);
322
332
  return this.post("/conversations/notes", input);
323
333
  });
324
334
  }
325
335
  };
326
336
  var ConversationTasksSubresource = class {
327
- constructor(post) {
337
+ constructor(post, patch) {
328
338
  this.post = post;
339
+ this.patch = patch;
329
340
  }
330
341
  /** Create a task on a conversation. */
331
342
  create(input) {
332
343
  return __async(this, null, function* () {
344
+ assertConversationAddress("tasks.create", input);
333
345
  return this.post("/conversations/tasks", input);
334
346
  });
335
347
  }
@@ -345,6 +357,24 @@ var ConversationTasksSubresource = class {
345
357
  );
346
358
  });
347
359
  }
360
+ /**
361
+ * Update task fields (priority, assignee, description, type). Wraps
362
+ * `PATCH /api/conversations/tasks/{id}` so CommHub doesn't have to
363
+ * direct-fetch for non-status field edits.
364
+ */
365
+ update(input) {
366
+ return __async(this, null, function* () {
367
+ return this.patch(
368
+ `/conversations/tasks/${encodeURIComponent(input.taskId)}`,
369
+ __spreadValues(__spreadValues(__spreadValues(__spreadValues({
370
+ id: input.taskId,
371
+ conversationId: input.conversationId,
372
+ author: input.author,
373
+ description: input.description
374
+ }, input.priority ? { priority: input.priority } : {}), input.status ? { status: input.status } : {}), input.assignee !== void 0 ? { assignee: input.assignee } : {}), input.type !== void 0 ? { type: input.type } : {})
375
+ );
376
+ });
377
+ }
348
378
  };
349
379
  var ConversationMessagesSubresource = class {
350
380
  constructor(post) {
@@ -379,8 +409,9 @@ var _ConversationsResource = class _ConversationsResource {
379
409
  this.apiKey = apiKey;
380
410
  this.convex = convex != null ? convex : null;
381
411
  const post = (path, body) => this.postRequest(path, body);
412
+ const patch = (path, body) => this.patchRequest(path, body);
382
413
  this.notes = new ConversationNotesSubresource(post);
383
- this.tasks = new ConversationTasksSubresource(post);
414
+ this.tasks = new ConversationTasksSubresource(post, patch);
384
415
  this.messages = new ConversationMessagesSubresource(post);
385
416
  }
386
417
  /**
@@ -480,6 +511,56 @@ var _ConversationsResource = class _ConversationsResource {
480
511
  return yield res.json();
481
512
  });
482
513
  }
514
+ /**
515
+ * PATCH variant of `postRequest`. Mirrors the timeout + API-key
516
+ * handling so callers like `tasks.update()` don't need to roll their
517
+ * own fetch. The Truth task router treats unknown methods as 405, so
518
+ * a dedicated PATCH path is required.
519
+ */
520
+ patchRequest(path, body) {
521
+ return __async(this, null, function* () {
522
+ if (!this.apiKey) {
523
+ throw new ConversationsError(
524
+ path,
525
+ 0,
526
+ "Truth API key not configured \u2014 request blocked"
527
+ );
528
+ }
529
+ const controller = new AbortController();
530
+ const timeout = setTimeout(
531
+ () => controller.abort(),
532
+ _ConversationsResource.REQUEST_TIMEOUT_MS
533
+ );
534
+ let res;
535
+ try {
536
+ res = yield fetch(`${this.baseUrl}/api${path}`, {
537
+ method: "PATCH",
538
+ headers: {
539
+ "Content-Type": "application/json",
540
+ Accept: "application/json",
541
+ "X-API-Key": this.apiKey
542
+ },
543
+ body: JSON.stringify(body),
544
+ signal: controller.signal
545
+ });
546
+ } catch (err) {
547
+ const isAbort = err instanceof Error && (err.name === "AbortError" || err.name === "TimeoutError");
548
+ const message = isAbort ? `Conversations ${path} timed out after ${_ConversationsResource.REQUEST_TIMEOUT_MS}ms` : err instanceof Error ? err.message : String(err);
549
+ throw new ConversationsError(path, 0, message);
550
+ } finally {
551
+ clearTimeout(timeout);
552
+ }
553
+ if (!res.ok) {
554
+ const text = yield res.text().catch(() => "");
555
+ throw new ConversationsError(
556
+ path,
557
+ res.status,
558
+ `Conversations ${path} failed: ${text.slice(0, 200)}`
559
+ );
560
+ }
561
+ return yield res.json();
562
+ });
563
+ }
483
564
  };
484
565
  /** 30s upstream timeout — matches NotesResource for consistency. */
485
566
  _ConversationsResource.REQUEST_TIMEOUT_MS = 3e4;
@@ -731,18 +812,15 @@ var MessagesResource = class {
731
812
  */
732
813
  getVoicemailUrl(voicemailLink) {
733
814
  return __async(this, null, function* () {
734
- const res = yield fetch(
735
- `${this.baseUrl}/api/conversations/voicemail/url`,
736
- {
737
- method: "POST",
738
- headers: {
739
- "Content-Type": "application/json",
740
- Accept: "application/json",
741
- "X-API-Key": this.apiKey
742
- },
743
- body: JSON.stringify({ voicemailLink })
744
- }
745
- );
815
+ const res = yield fetch(`${this.baseUrl}/api/conversations/voicemail/url`, {
816
+ method: "POST",
817
+ headers: {
818
+ "Content-Type": "application/json",
819
+ Accept: "application/json",
820
+ "X-API-Key": this.apiKey
821
+ },
822
+ body: JSON.stringify({ voicemailLink })
823
+ });
746
824
  if (!res.ok) {
747
825
  const text = yield res.text().catch(() => "");
748
826
  throw new Error(