@digisglobal/omnivox-sdk 0.6.1 → 0.8.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.js CHANGED
@@ -183,9 +183,15 @@ var getChannelsControllerVerifyUrl = (id, channelId) => {
183
183
  var getWhatsAppBusinessAccountsControllerListUrl = (id) => {
184
184
  return `/api/v1/tenants/${id}/whatsapp-business-accounts`;
185
185
  };
186
+ var getWhatsAppBusinessAccountsControllerCreateUrl = (id) => {
187
+ return `/api/v1/tenants/${id}/whatsapp-business-accounts`;
188
+ };
186
189
  var getWhatsAppBusinessAccountsControllerFindOneUrl = (id, wabaRowId) => {
187
190
  return `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaRowId}`;
188
191
  };
192
+ var getWhatsAppBusinessAccountsControllerUpdateNameUrl = (id, wabaRowId) => {
193
+ return `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaRowId}`;
194
+ };
189
195
  var getAgentsControllerCreateUrl = () => {
190
196
  return `/api/v1/agents`;
191
197
  };
@@ -205,12 +211,25 @@ var getAgentsControllerFindOneUrl = (id) => {
205
211
  var getTemplatesControllerAuthorDraftUrl = (id, wabaId) => {
206
212
  return `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaId}/templates`;
207
213
  };
214
+ var getTemplatesControllerListUrl = (id, wabaId, params) => {
215
+ const normalizedParams = new URLSearchParams();
216
+ Object.entries(params || {}).forEach(([key, value]) => {
217
+ if (value !== void 0) {
218
+ normalizedParams.append(key, value === null ? "null" : String(value));
219
+ }
220
+ });
221
+ const stringifiedParams = normalizedParams.toString();
222
+ return stringifiedParams.length > 0 ? `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaId}/templates?${stringifiedParams}` : `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaId}/templates`;
223
+ };
208
224
  var getTemplatesControllerImportApprovedUrl = (id, wabaId) => {
209
225
  return `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaId}/templates/import`;
210
226
  };
211
227
  var getTemplatesControllerForkDraftUrl = (id, wabaId, templateId) => {
212
228
  return `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaId}/templates/${templateId}`;
213
229
  };
230
+ var getTemplatesControllerGetByIdUrl = (id, wabaId, templateId) => {
231
+ return `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaId}/templates/${templateId}`;
232
+ };
214
233
  var getTemplatesControllerGetHistoryUrl = (id, wabaId, templateId) => {
215
234
  return `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaId}/templates/${templateId}/history`;
216
235
  };
@@ -356,7 +375,7 @@ function createTenantsModule(options) {
356
375
  url,
357
376
  buildInit("POST", { body: JSON.stringify(body) })
358
377
  );
359
- return parseResponse(res);
378
+ return parseEnvelopedResponse(res);
360
379
  },
361
380
  /**
362
381
  * Revoke an existing API key immediately.
@@ -366,7 +385,7 @@ function createTenantsModule(options) {
366
385
  const path = getApiKeysControllerRevokeUrl(tenantId, keyId);
367
386
  const url = `${baseUrl}${path}`;
368
387
  const res = await fetch(url, buildInit("DELETE"));
369
- return parseResponse(res);
388
+ return parseEnvelopedResponse(res);
370
389
  }
371
390
  }
372
391
  };
@@ -395,7 +414,7 @@ function createAgentsModule(options) {
395
414
  const path = getAgentsControllerCreateUrl();
396
415
  const url = `${baseUrl}${path}`;
397
416
  const res = await fetch(url, buildInit("POST", input));
398
- return parseResponse(res);
417
+ return parseEnvelopedResponse(res);
399
418
  },
400
419
  /**
401
420
  * List agents for the authenticated tenant (paginated, sorted deterministically).
@@ -417,7 +436,7 @@ function createAgentsModule(options) {
417
436
  const path = getAgentsControllerFindOneUrl(id);
418
437
  const url = `${baseUrl}${path}`;
419
438
  const res = await fetch(url, buildInit("GET"));
420
- return parseResponse(res);
439
+ return parseEnvelopedResponse(res);
421
440
  }
422
441
  };
423
442
  }
@@ -447,7 +466,7 @@ function createChannelsModule(options) {
447
466
  const path = getChannelsControllerCreateUrl(tenantId);
448
467
  const url = `${baseUrl}${path}`;
449
468
  const res = await fetch(url, buildInit("POST", body));
450
- return parseResponse(res);
469
+ return parseEnvelopedResponse(res);
451
470
  },
452
471
  /**
453
472
  * Get a single channel by id (config + name/status/isDefault/type +
@@ -458,7 +477,7 @@ function createChannelsModule(options) {
458
477
  const path = getChannelsControllerFindOneUrl(tenantId, channelId);
459
478
  const url = `${baseUrl}${path}`;
460
479
  const res = await fetch(url, buildInit("GET"));
461
- return parseResponse(res);
480
+ return parseEnvelopedResponse(res);
462
481
  },
463
482
  /**
464
483
  * Update a channel (name/status/isDefault/config; Email may rotate secret).
@@ -468,7 +487,7 @@ function createChannelsModule(options) {
468
487
  const path = getChannelsControllerUpdateUrl(tenantId, channelId);
469
488
  const url = `${baseUrl}${path}`;
470
489
  const res = await fetch(url, buildInit("PATCH", body));
471
- return parseResponse(res);
490
+ return parseEnvelopedResponse(res);
472
491
  },
473
492
  /**
474
493
  * Verify a channel through its adapter; on success sets lastVerifiedAt.
@@ -506,7 +525,7 @@ function createContactsModule(options) {
506
525
  const path = getContactsControllerCreateUrl();
507
526
  const url = `${baseUrl}${path}`;
508
527
  const res = await fetch(url, buildInit("POST", input));
509
- return parseResponse(res);
528
+ return parseEnvelopedResponse(res);
510
529
  },
511
530
  /**
512
531
  * Search contacts by display name or raw identifier.
@@ -533,7 +552,7 @@ function createContactsModule(options) {
533
552
  const path = getContactsControllerGetDetailUrl(id);
534
553
  const url = `${baseUrl}${path}`;
535
554
  const res = await fetch(url, buildInit("GET"));
536
- return parseResponse(res);
555
+ return parseEnvelopedResponse(res);
537
556
  },
538
557
  /**
539
558
  * Return the tenant's tag catalog and custom-field definitions.
@@ -543,7 +562,7 @@ function createContactsModule(options) {
543
562
  const path = getContactsControllerGetMetadataUrl();
544
563
  const url = `${baseUrl}${path}`;
545
564
  const res = await fetch(url, buildInit("GET"));
546
- return parseResponse(res);
565
+ return parseEnvelopedResponse(res);
547
566
  },
548
567
  /**
549
568
  * Partially update a contact.
@@ -553,7 +572,7 @@ function createContactsModule(options) {
553
572
  const path = getContactsControllerPatchUrl(id);
554
573
  const url = `${baseUrl}${path}`;
555
574
  const res = await fetch(url, buildInit("PATCH", input));
556
- return parseResponse(res);
575
+ return parseEnvelopedResponse(res);
557
576
  },
558
577
  /**
559
578
  * Add a channel identity to an existing contact.
@@ -563,7 +582,7 @@ function createContactsModule(options) {
563
582
  const path = getContactsControllerAddIdentityUrl(id);
564
583
  const url = `${baseUrl}${path}`;
565
584
  const res = await fetch(url, buildInit("POST", input));
566
- return parseResponse(res);
585
+ return parseEnvelopedResponse(res);
567
586
  }
568
587
  };
569
588
  }
@@ -592,7 +611,7 @@ function createConversationsModule(options) {
592
611
  const path = getConversationsControllerReopenOrCreateUrl();
593
612
  const url = `${baseUrl}${path}`;
594
613
  const res = await fetch(url, buildInit("POST", input));
595
- return parseResponse(res);
614
+ return parseEnvelopedResponse(res);
596
615
  },
597
616
  /**
598
617
  * List conversations with optional filters (paginated, sorted deterministically).
@@ -620,7 +639,7 @@ function createConversationsModule(options) {
620
639
  const path = getConversationsControllerUpdateStatusUrl(id);
621
640
  const url = `${baseUrl}${path}`;
622
641
  const res = await fetch(url, buildInit("PATCH", input));
623
- return parseResponse(res);
642
+ return parseEnvelopedResponse(res);
624
643
  },
625
644
  /**
626
645
  * Assign a conversation to an agent.
@@ -630,7 +649,7 @@ function createConversationsModule(options) {
630
649
  const path = getConversationsControllerAssignUrl(id);
631
650
  const url = `${baseUrl}${path}`;
632
651
  const res = await fetch(url, buildInit("PATCH", input));
633
- return parseResponse(res);
652
+ return parseEnvelopedResponse(res);
634
653
  },
635
654
  /**
636
655
  * List lobby entries awaiting pickup (paginated, sorted by receivedAt DESC).
@@ -652,18 +671,18 @@ function createConversationsModule(options) {
652
671
  const path = getConversationsControllerFindOneUrl(id);
653
672
  const url = `${baseUrl}${path}`;
654
673
  const res = await fetch(url, buildInit("GET"));
655
- return parseResponse(res);
674
+ return parseEnvelopedResponse(res);
656
675
  },
657
676
  /**
658
677
  * Pick up a lobby entry (atomic 4-step transaction).
659
- * Returns the resulting conversation.
678
+ * Returns the resulting conversation + entry ids.
660
679
  * Calls POST /api/v1/conversations/lobby/:entryId/pickup.
661
680
  */
662
681
  async pickup(entryId, input) {
663
682
  const path = getConversationsControllerPickupLobbyEntryUrl(entryId);
664
683
  const url = `${baseUrl}${path}`;
665
684
  const res = await fetch(url, buildInit("POST", input));
666
- return parseResponse(res);
685
+ return parseEnvelopedResponse(res);
667
686
  },
668
687
  /**
669
688
  * List APPROVED + SENDABLE WhatsApp templates eligible to re-open an
@@ -675,7 +694,7 @@ function createConversationsModule(options) {
675
694
  const path = getConversationsControllerGetWhatsAppRecoveryOptionsUrl(id);
676
695
  const url = `${baseUrl}${path}`;
677
696
  const res = await fetch(url, buildInit("GET"));
678
- return parseResponse(res);
697
+ return parseEnvelopedResponse(res);
679
698
  }
680
699
  };
681
700
  }
@@ -703,7 +722,7 @@ function createMessagesModule(options) {
703
722
  const path = getMessagesControllerSendUrl();
704
723
  const url = `${baseUrl}${path}`;
705
724
  const res = await fetch(url, buildInit("POST", input));
706
- return parseResponse(res);
725
+ return parseEnvelopedResponse(res);
707
726
  },
708
727
  /**
709
728
  * List messages in a conversation (newest first, paginated).
@@ -731,7 +750,7 @@ function createMessagesModule(options) {
731
750
  const path = getMessagesControllerGetByIdUrl(id);
732
751
  const url = `${baseUrl}${path}`;
733
752
  const res = await fetch(url, buildInit("GET"));
734
- return parseResponse(res);
753
+ return parseEnvelopedResponse(res);
735
754
  },
736
755
  /**
737
756
  * Soft-delete a message (sets deletedAt; row preserved).
@@ -753,7 +772,7 @@ function createMessagesModule(options) {
753
772
  const path = getMessagesControllerSendTemplateUrl();
754
773
  const url = `${baseUrl}${path}`;
755
774
  const res = await fetch(url, buildInit("POST", input));
756
- return parseResponse(res);
775
+ return parseEnvelopedResponse(res);
757
776
  }
758
777
  };
759
778
  }
@@ -777,6 +796,38 @@ function createTemplatesModule(options) {
777
796
  * WhatsApp template submodule — WABA-scoped operations.
778
797
  */
779
798
  whatsapp: {
799
+ /**
800
+ * List a WhatsApp Business Account's templates (paginated, optionally status-filtered and name-searchable).
801
+ * Calls GET /api/v1/tenants/:id/whatsapp-business-accounts/:wabaId/templates.
802
+ */
803
+ async list(tenantId, wabaId, opts) {
804
+ const { page, pageSize } = buildPageParams(opts);
805
+ const path = getTemplatesControllerListUrl(tenantId, wabaId, {
806
+ page,
807
+ pageSize,
808
+ ...opts.status ? { status: opts.status } : {},
809
+ ...opts.q ? { q: opts.q } : {}
810
+ });
811
+ const url = `${baseUrl}${path}`;
812
+ const res = await fetch(url, buildInit("GET"));
813
+ return parseResponse(res);
814
+ },
815
+ /**
816
+ * Get a single template together with its current (latest) version.
817
+ * Language/status and other version-scoped fields are nested under
818
+ * `currentVersion` — not at the top level (see WhatsAppTemplateDetail).
819
+ * Calls GET /api/v1/tenants/:id/whatsapp-business-accounts/:wabaId/templates/:templateId.
820
+ */
821
+ async getById(tenantId, wabaId, templateId) {
822
+ const path = getTemplatesControllerGetByIdUrl(
823
+ tenantId,
824
+ wabaId,
825
+ templateId
826
+ );
827
+ const url = `${baseUrl}${path}`;
828
+ const res = await fetch(url, buildInit("GET"));
829
+ return parseEnvelopedResponse(res);
830
+ },
780
831
  /**
781
832
  * Author a new DRAFT template (version 1) under a WhatsApp Business Account.
782
833
  * Calls POST /api/v1/tenants/:id/whatsapp-business-accounts/:wabaId/templates.
@@ -812,7 +863,11 @@ function createTemplatesModule(options) {
812
863
  return parseEnvelopedResponse(res);
813
864
  },
814
865
  /**
815
- * List all versions and status events for a template in chronological order.
866
+ * Get the full version + status-event history for a template.
867
+ *
868
+ * Returns a single OBJECT (see WhatsAppTemplateHistory) — template-level
869
+ * fields plus a `versions` array ordered by versionNumber ascending, each
870
+ * version carrying its own `statusEvents`. NOT a flat array of events.
816
871
  * Calls GET /api/v1/tenants/:id/whatsapp-business-accounts/:wabaId/templates/:templateId/history.
817
872
  */
818
873
  async history(tenantId, wabaId, templateId) {
@@ -860,7 +915,11 @@ function createTemplatesModule(options) {
860
915
  */
861
916
  async list(opts) {
862
917
  const { page, pageSize } = buildPageParams(opts);
863
- const path = getEmailTemplatesControllerListUrl({ page, pageSize });
918
+ const path = getEmailTemplatesControllerListUrl({
919
+ page,
920
+ pageSize,
921
+ ...opts.q ? { q: opts.q } : {}
922
+ });
864
923
  const url = `${baseUrl}${path}`;
865
924
  const res = await fetch(url, buildInit("GET"));
866
925
  return parseResponse(res);
@@ -952,7 +1011,7 @@ function createCannedResponsesModule(options) {
952
1011
  const path = getCannedResponsesControllerCreateUrl();
953
1012
  const url = `${baseUrl}${path}`;
954
1013
  const res = await fetch(url, buildInit("POST", input));
955
- return parseResponse(res);
1014
+ return parseEnvelopedResponse(res);
956
1015
  },
957
1016
  /**
958
1017
  * Partially update a canned response — title, body, and/or keywords.
@@ -962,7 +1021,7 @@ function createCannedResponsesModule(options) {
962
1021
  const path = getCannedResponsesControllerPatchUrl(id);
963
1022
  const url = `${baseUrl}${path}`;
964
1023
  const res = await fetch(url, buildInit("PATCH", input));
965
- return parseResponse(res);
1024
+ return parseEnvelopedResponse(res);
966
1025
  },
967
1026
  /**
968
1027
  * Delete a canned response by id.
@@ -1007,7 +1066,7 @@ function createAttachmentsModule(options) {
1007
1066
  },
1008
1067
  body: form
1009
1068
  });
1010
- return parseResponse(res);
1069
+ return parseEnvelopedResponse(res);
1011
1070
  },
1012
1071
  /**
1013
1072
  * Get a short-lived presigned download URL for a stored attachment.
@@ -1025,7 +1084,7 @@ function createAttachmentsModule(options) {
1025
1084
  ...options.getHeaders()
1026
1085
  }
1027
1086
  });
1028
- return parseResponse(res);
1087
+ return parseEnvelopedResponse(res);
1029
1088
  }
1030
1089
  };
1031
1090
  }
@@ -1033,14 +1092,15 @@ function createAttachmentsModule(options) {
1033
1092
  // src/whatsapp-business-accounts/whatsapp-business-accounts.ts
1034
1093
  function createWhatsAppBusinessAccountsModule(options) {
1035
1094
  const baseUrl = options.baseUrl;
1036
- function buildInit(method) {
1095
+ function buildInit(method, body) {
1037
1096
  return {
1038
1097
  method,
1039
1098
  credentials: options.getCredentials(),
1040
1099
  headers: {
1041
1100
  "Content-Type": "application/json",
1042
1101
  ...options.getHeaders()
1043
- }
1102
+ },
1103
+ ...body !== void 0 ? { body: JSON.stringify(body) } : {}
1044
1104
  };
1045
1105
  }
1046
1106
  return {
@@ -1075,6 +1135,44 @@ function createWhatsAppBusinessAccountsModule(options) {
1075
1135
  const url = `${baseUrl}${path}`;
1076
1136
  const res = await fetch(url, buildInit("GET"));
1077
1137
  return parseEnvelopedResponse(res);
1138
+ },
1139
+ /**
1140
+ * Create a WhatsApp Business Account — writes the secret to the
1141
+ * SecretsProvider and the non-secret row to the DB; returns the
1142
+ * non-secret view (no `secretRef` exposed).
1143
+ * Calls POST /api/v1/tenants/:id/whatsapp-business-accounts.
1144
+ *
1145
+ * @example
1146
+ * const waba = await sdk.whatsappBusinessAccounts.create('ten_acmecorp', {
1147
+ * wabaId: '123456789012345',
1148
+ * name: 'Acme WhatsApp',
1149
+ * secret: { accessToken, appSecret, webhookVerifyToken },
1150
+ * })
1151
+ */
1152
+ async create(tenantId, body) {
1153
+ const path = getWhatsAppBusinessAccountsControllerCreateUrl(tenantId);
1154
+ const url = `${baseUrl}${path}`;
1155
+ const res = await fetch(url, buildInit("POST", body));
1156
+ return parseEnvelopedResponse(res);
1157
+ },
1158
+ /**
1159
+ * Rename a WhatsApp Business Account (name only — secret material is
1160
+ * immutable through this endpoint).
1161
+ * Calls PATCH /api/v1/tenants/:id/whatsapp-business-accounts/:wabaRowId.
1162
+ *
1163
+ * @example
1164
+ * await sdk.whatsappBusinessAccounts.update('ten_acmecorp', 'waba_row_001', {
1165
+ * name: 'Renamed WhatsApp',
1166
+ * })
1167
+ */
1168
+ async update(tenantId, wabaRowId, body) {
1169
+ const path = getWhatsAppBusinessAccountsControllerUpdateNameUrl(
1170
+ tenantId,
1171
+ wabaRowId
1172
+ );
1173
+ const url = `${baseUrl}${path}`;
1174
+ const res = await fetch(url, buildInit("PATCH", body));
1175
+ return parseEnvelopedResponse(res);
1078
1176
  }
1079
1177
  };
1080
1178
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digisglobal/omnivox-sdk",
3
- "version": "0.6.1",
3
+ "version": "0.8.0",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "exports": {
@@ -38,6 +38,7 @@
38
38
  "scripts": {
39
39
  "codegen": "orval --config orval.config.ts && prettier --write src/_generated",
40
40
  "build": "tsup",
41
+ "dev": "tsup --watch",
41
42
  "typecheck": "tsc --noEmit",
42
43
  "test": "vitest run",
43
44
  "lint": "eslint .",