@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.mjs CHANGED
@@ -247,6 +247,15 @@ var ConversationsError = class extends Error {
247
247
  this.status = status;
248
248
  }
249
249
  };
250
+ function assertConversationAddress(operation, input) {
251
+ if (!input.conversationId && !input.phonePair) {
252
+ throw new ConversationsError(
253
+ operation,
254
+ 0,
255
+ "Either `conversationId` or `phonePair` is required"
256
+ );
257
+ }
258
+ }
250
259
  var ConversationNotesSubresource = class {
251
260
  constructor(post) {
252
261
  this.post = post;
@@ -254,17 +263,20 @@ var ConversationNotesSubresource = class {
254
263
  /** Create a note on a conversation (addressed by id or phonePair). */
255
264
  create(input) {
256
265
  return __async(this, null, function* () {
266
+ assertConversationAddress("notes.create", input);
257
267
  return this.post("/conversations/notes", input);
258
268
  });
259
269
  }
260
270
  };
261
271
  var ConversationTasksSubresource = class {
262
- constructor(post) {
272
+ constructor(post, patch) {
263
273
  this.post = post;
274
+ this.patch = patch;
264
275
  }
265
276
  /** Create a task on a conversation. */
266
277
  create(input) {
267
278
  return __async(this, null, function* () {
279
+ assertConversationAddress("tasks.create", input);
268
280
  return this.post("/conversations/tasks", input);
269
281
  });
270
282
  }
@@ -280,6 +292,24 @@ var ConversationTasksSubresource = class {
280
292
  );
281
293
  });
282
294
  }
295
+ /**
296
+ * Update task fields (priority, assignee, description, type). Wraps
297
+ * `PATCH /api/conversations/tasks/{id}` so CommHub doesn't have to
298
+ * direct-fetch for non-status field edits.
299
+ */
300
+ update(input) {
301
+ return __async(this, null, function* () {
302
+ return this.patch(
303
+ `/conversations/tasks/${encodeURIComponent(input.taskId)}`,
304
+ __spreadValues(__spreadValues(__spreadValues(__spreadValues({
305
+ id: input.taskId,
306
+ conversationId: input.conversationId,
307
+ author: input.author,
308
+ description: input.description
309
+ }, input.priority ? { priority: input.priority } : {}), input.status ? { status: input.status } : {}), input.assignee !== void 0 ? { assignee: input.assignee } : {}), input.type !== void 0 ? { type: input.type } : {})
310
+ );
311
+ });
312
+ }
283
313
  };
284
314
  var ConversationMessagesSubresource = class {
285
315
  constructor(post) {
@@ -314,8 +344,9 @@ var _ConversationsResource = class _ConversationsResource {
314
344
  this.apiKey = apiKey;
315
345
  this.convex = convex != null ? convex : null;
316
346
  const post = (path, body) => this.postRequest(path, body);
347
+ const patch = (path, body) => this.patchRequest(path, body);
317
348
  this.notes = new ConversationNotesSubresource(post);
318
- this.tasks = new ConversationTasksSubresource(post);
349
+ this.tasks = new ConversationTasksSubresource(post, patch);
319
350
  this.messages = new ConversationMessagesSubresource(post);
320
351
  }
321
352
  /**
@@ -415,6 +446,56 @@ var _ConversationsResource = class _ConversationsResource {
415
446
  return yield res.json();
416
447
  });
417
448
  }
449
+ /**
450
+ * PATCH variant of `postRequest`. Mirrors the timeout + API-key
451
+ * handling so callers like `tasks.update()` don't need to roll their
452
+ * own fetch. The Truth task router treats unknown methods as 405, so
453
+ * a dedicated PATCH path is required.
454
+ */
455
+ patchRequest(path, body) {
456
+ return __async(this, null, function* () {
457
+ if (!this.apiKey) {
458
+ throw new ConversationsError(
459
+ path,
460
+ 0,
461
+ "Truth API key not configured \u2014 request blocked"
462
+ );
463
+ }
464
+ const controller = new AbortController();
465
+ const timeout = setTimeout(
466
+ () => controller.abort(),
467
+ _ConversationsResource.REQUEST_TIMEOUT_MS
468
+ );
469
+ let res;
470
+ try {
471
+ res = yield fetch(`${this.baseUrl}/api${path}`, {
472
+ method: "PATCH",
473
+ headers: {
474
+ "Content-Type": "application/json",
475
+ Accept: "application/json",
476
+ "X-API-Key": this.apiKey
477
+ },
478
+ body: JSON.stringify(body),
479
+ signal: controller.signal
480
+ });
481
+ } catch (err) {
482
+ const isAbort = err instanceof Error && (err.name === "AbortError" || err.name === "TimeoutError");
483
+ const message = isAbort ? `Conversations ${path} timed out after ${_ConversationsResource.REQUEST_TIMEOUT_MS}ms` : err instanceof Error ? err.message : String(err);
484
+ throw new ConversationsError(path, 0, message);
485
+ } finally {
486
+ clearTimeout(timeout);
487
+ }
488
+ if (!res.ok) {
489
+ const text = yield res.text().catch(() => "");
490
+ throw new ConversationsError(
491
+ path,
492
+ res.status,
493
+ `Conversations ${path} failed: ${text.slice(0, 200)}`
494
+ );
495
+ }
496
+ return yield res.json();
497
+ });
498
+ }
418
499
  };
419
500
  /** 30s upstream timeout — matches NotesResource for consistency. */
420
501
  _ConversationsResource.REQUEST_TIMEOUT_MS = 3e4;
@@ -666,18 +747,15 @@ var MessagesResource = class {
666
747
  */
667
748
  getVoicemailUrl(voicemailLink) {
668
749
  return __async(this, null, function* () {
669
- const res = yield fetch(
670
- `${this.baseUrl}/api/conversations/voicemail/url`,
671
- {
672
- method: "POST",
673
- headers: {
674
- "Content-Type": "application/json",
675
- Accept: "application/json",
676
- "X-API-Key": this.apiKey
677
- },
678
- body: JSON.stringify({ voicemailLink })
679
- }
680
- );
750
+ const res = yield fetch(`${this.baseUrl}/api/conversations/voicemail/url`, {
751
+ method: "POST",
752
+ headers: {
753
+ "Content-Type": "application/json",
754
+ Accept: "application/json",
755
+ "X-API-Key": this.apiKey
756
+ },
757
+ body: JSON.stringify({ voicemailLink })
758
+ });
681
759
  if (!res.ok) {
682
760
  const text = yield res.text().catch(() => "");
683
761
  throw new Error(