@hipnation-truth/sdk 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.
package/dist/index.mjs CHANGED
@@ -229,6 +229,129 @@ var AttachmentsResource = class {
229
229
  }
230
230
  };
231
231
 
232
+ // src/resources/conversations.ts
233
+ var ConversationsError = class extends Error {
234
+ constructor(operation, status, message) {
235
+ super(message != null ? message : `Conversations ${operation} failed (HTTP ${status})`);
236
+ this.name = "ConversationsError";
237
+ this.status = status;
238
+ }
239
+ };
240
+ var ConversationNotesSubresource = class {
241
+ constructor(post) {
242
+ this.post = post;
243
+ }
244
+ /** Create a note on a conversation (addressed by id or phonePair). */
245
+ create(input) {
246
+ return __async(this, null, function* () {
247
+ return this.post("/conversations/notes", input);
248
+ });
249
+ }
250
+ };
251
+ var ConversationTasksSubresource = class {
252
+ constructor(post) {
253
+ this.post = post;
254
+ }
255
+ /** Create a task on a conversation. */
256
+ create(input) {
257
+ return __async(this, null, function* () {
258
+ return this.post("/conversations/tasks", input);
259
+ });
260
+ }
261
+ /** Mark a task pending or completed. */
262
+ setStatus(input) {
263
+ return __async(this, null, function* () {
264
+ return this.post(
265
+ `/conversations/tasks/${encodeURIComponent(input.taskId)}/status`,
266
+ __spreadValues({
267
+ id: input.taskId,
268
+ status: input.status
269
+ }, input.resolvedBy ? { resolvedBy: input.resolvedBy } : {})
270
+ );
271
+ });
272
+ }
273
+ };
274
+ var ConversationMessagesSubresource = class {
275
+ constructor(post) {
276
+ this.post = post;
277
+ }
278
+ /**
279
+ * Send an outbound SMS / MMS via the typed `sendMessage` oRPC procedure.
280
+ *
281
+ * Prefer this over the generic Dialpad proxy (`messages.dialpad.sendSms`)
282
+ * — this hits the validated Truth route and consistently surfaces
283
+ * `ConversationsError` on failure.
284
+ */
285
+ send(input) {
286
+ return __async(this, null, function* () {
287
+ if (!input.message && !input.media) {
288
+ throw new ConversationsError(
289
+ "messages.send",
290
+ 0,
291
+ "send requires `message` or `media`"
292
+ );
293
+ }
294
+ return this.post(
295
+ "/conversations/messages",
296
+ input
297
+ );
298
+ });
299
+ }
300
+ };
301
+ var _ConversationsResource = class _ConversationsResource {
302
+ constructor(apiBaseUrl, apiKey) {
303
+ this.baseUrl = apiBaseUrl;
304
+ this.apiKey = apiKey;
305
+ const post = (path, body) => this.postRequest(path, body);
306
+ this.notes = new ConversationNotesSubresource(post);
307
+ this.tasks = new ConversationTasksSubresource(post);
308
+ this.messages = new ConversationMessagesSubresource(post);
309
+ }
310
+ postRequest(path, body) {
311
+ return __async(this, null, function* () {
312
+ if (!this.apiKey) {
313
+ throw new ConversationsError(
314
+ path,
315
+ 0,
316
+ "Truth API key not configured \u2014 request blocked"
317
+ );
318
+ }
319
+ const controller = new AbortController();
320
+ const timeout = setTimeout(
321
+ () => controller.abort(),
322
+ _ConversationsResource.REQUEST_TIMEOUT_MS
323
+ );
324
+ let res;
325
+ try {
326
+ res = yield fetch(`${this.baseUrl}/api${path}`, {
327
+ method: "POST",
328
+ headers: {
329
+ "Content-Type": "application/json",
330
+ Accept: "application/json",
331
+ "X-API-Key": this.apiKey
332
+ },
333
+ body: JSON.stringify(body),
334
+ signal: controller.signal
335
+ });
336
+ } catch (err) {
337
+ const isAbort = err instanceof Error && (err.name === "AbortError" || err.name === "TimeoutError");
338
+ const message = isAbort ? `Conversations ${path} timed out after ${_ConversationsResource.REQUEST_TIMEOUT_MS}ms` : err instanceof Error ? err.message : "Conversations request failed before response";
339
+ throw new ConversationsError(path, 0, message);
340
+ } finally {
341
+ clearTimeout(timeout);
342
+ }
343
+ if (!res.ok) {
344
+ const text = yield res.text().catch(() => "");
345
+ throw new ConversationsError(path, res.status, text.slice(0, 200));
346
+ }
347
+ return yield res.json();
348
+ });
349
+ }
350
+ };
351
+ /** 30s upstream timeout — matches NotesResource for consistency. */
352
+ _ConversationsResource.REQUEST_TIMEOUT_MS = 3e4;
353
+ var ConversationsResource = _ConversationsResource;
354
+
232
355
  // src/resources/dialpad.ts
233
356
  var DialpadResource = class {
234
357
  constructor(apiBaseUrl, apiKey) {
@@ -1557,6 +1680,7 @@ var TruthClient = class {
1557
1680
  this.notes = new NotesResource(apiUrl, config.apiKey);
1558
1681
  this.physicians = new PhysiciansResource(this.convex);
1559
1682
  this.notifications = new NotificationsResource(apiUrl, config.apiKey);
1683
+ this.conversations = new ConversationsResource(apiUrl, config.apiKey);
1560
1684
  this._serviceWorkerPath = (_h = config.serviceWorkerPath) != null ? _h : "/truth-sw.js";
1561
1685
  if (typeof window !== "undefined" && isWebPushSupported() && config.autoInitServiceWorker !== false) {
1562
1686
  this._webPushReady = this.initWebPush();
@@ -1735,6 +1859,8 @@ export {
1735
1859
  AttachmentsResource,
1736
1860
  CALL_EVENTS,
1737
1861
  CONVERSATION_EVENTS,
1862
+ ConversationsError,
1863
+ ConversationsResource,
1738
1864
  DialpadProxyError,
1739
1865
  DialpadResource,
1740
1866
  ENVIRONMENTS,