@digisglobal/omnivox-sdk 0.7.0 → 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.cjs CHANGED
@@ -226,9 +226,15 @@ var getChannelsControllerVerifyUrl = (id, channelId) => {
226
226
  var getWhatsAppBusinessAccountsControllerListUrl = (id) => {
227
227
  return `/api/v1/tenants/${id}/whatsapp-business-accounts`;
228
228
  };
229
+ var getWhatsAppBusinessAccountsControllerCreateUrl = (id) => {
230
+ return `/api/v1/tenants/${id}/whatsapp-business-accounts`;
231
+ };
229
232
  var getWhatsAppBusinessAccountsControllerFindOneUrl = (id, wabaRowId) => {
230
233
  return `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaRowId}`;
231
234
  };
235
+ var getWhatsAppBusinessAccountsControllerUpdateNameUrl = (id, wabaRowId) => {
236
+ return `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaRowId}`;
237
+ };
232
238
  var getAgentsControllerCreateUrl = () => {
233
239
  return `/api/v1/agents`;
234
240
  };
@@ -248,12 +254,25 @@ var getAgentsControllerFindOneUrl = (id) => {
248
254
  var getTemplatesControllerAuthorDraftUrl = (id, wabaId) => {
249
255
  return `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaId}/templates`;
250
256
  };
257
+ var getTemplatesControllerListUrl = (id, wabaId, params) => {
258
+ const normalizedParams = new URLSearchParams();
259
+ Object.entries(params || {}).forEach(([key, value]) => {
260
+ if (value !== void 0) {
261
+ normalizedParams.append(key, value === null ? "null" : String(value));
262
+ }
263
+ });
264
+ const stringifiedParams = normalizedParams.toString();
265
+ return stringifiedParams.length > 0 ? `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaId}/templates?${stringifiedParams}` : `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaId}/templates`;
266
+ };
251
267
  var getTemplatesControllerImportApprovedUrl = (id, wabaId) => {
252
268
  return `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaId}/templates/import`;
253
269
  };
254
270
  var getTemplatesControllerForkDraftUrl = (id, wabaId, templateId) => {
255
271
  return `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaId}/templates/${templateId}`;
256
272
  };
273
+ var getTemplatesControllerGetByIdUrl = (id, wabaId, templateId) => {
274
+ return `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaId}/templates/${templateId}`;
275
+ };
257
276
  var getTemplatesControllerGetHistoryUrl = (id, wabaId, templateId) => {
258
277
  return `/api/v1/tenants/${id}/whatsapp-business-accounts/${wabaId}/templates/${templateId}/history`;
259
278
  };
@@ -399,7 +418,7 @@ function createTenantsModule(options) {
399
418
  url,
400
419
  buildInit("POST", { body: JSON.stringify(body) })
401
420
  );
402
- return parseResponse(res);
421
+ return parseEnvelopedResponse(res);
403
422
  },
404
423
  /**
405
424
  * Revoke an existing API key immediately.
@@ -409,7 +428,7 @@ function createTenantsModule(options) {
409
428
  const path = getApiKeysControllerRevokeUrl(tenantId, keyId);
410
429
  const url = `${baseUrl}${path}`;
411
430
  const res = await fetch(url, buildInit("DELETE"));
412
- return parseResponse(res);
431
+ return parseEnvelopedResponse(res);
413
432
  }
414
433
  }
415
434
  };
@@ -438,7 +457,7 @@ function createAgentsModule(options) {
438
457
  const path = getAgentsControllerCreateUrl();
439
458
  const url = `${baseUrl}${path}`;
440
459
  const res = await fetch(url, buildInit("POST", input));
441
- return parseResponse(res);
460
+ return parseEnvelopedResponse(res);
442
461
  },
443
462
  /**
444
463
  * List agents for the authenticated tenant (paginated, sorted deterministically).
@@ -460,7 +479,7 @@ function createAgentsModule(options) {
460
479
  const path = getAgentsControllerFindOneUrl(id);
461
480
  const url = `${baseUrl}${path}`;
462
481
  const res = await fetch(url, buildInit("GET"));
463
- return parseResponse(res);
482
+ return parseEnvelopedResponse(res);
464
483
  }
465
484
  };
466
485
  }
@@ -490,7 +509,7 @@ function createChannelsModule(options) {
490
509
  const path = getChannelsControllerCreateUrl(tenantId);
491
510
  const url = `${baseUrl}${path}`;
492
511
  const res = await fetch(url, buildInit("POST", body));
493
- return parseResponse(res);
512
+ return parseEnvelopedResponse(res);
494
513
  },
495
514
  /**
496
515
  * Get a single channel by id (config + name/status/isDefault/type +
@@ -501,7 +520,7 @@ function createChannelsModule(options) {
501
520
  const path = getChannelsControllerFindOneUrl(tenantId, channelId);
502
521
  const url = `${baseUrl}${path}`;
503
522
  const res = await fetch(url, buildInit("GET"));
504
- return parseResponse(res);
523
+ return parseEnvelopedResponse(res);
505
524
  },
506
525
  /**
507
526
  * Update a channel (name/status/isDefault/config; Email may rotate secret).
@@ -511,7 +530,7 @@ function createChannelsModule(options) {
511
530
  const path = getChannelsControllerUpdateUrl(tenantId, channelId);
512
531
  const url = `${baseUrl}${path}`;
513
532
  const res = await fetch(url, buildInit("PATCH", body));
514
- return parseResponse(res);
533
+ return parseEnvelopedResponse(res);
515
534
  },
516
535
  /**
517
536
  * Verify a channel through its adapter; on success sets lastVerifiedAt.
@@ -549,7 +568,7 @@ function createContactsModule(options) {
549
568
  const path = getContactsControllerCreateUrl();
550
569
  const url = `${baseUrl}${path}`;
551
570
  const res = await fetch(url, buildInit("POST", input));
552
- return parseResponse(res);
571
+ return parseEnvelopedResponse(res);
553
572
  },
554
573
  /**
555
574
  * Search contacts by display name or raw identifier.
@@ -576,7 +595,7 @@ function createContactsModule(options) {
576
595
  const path = getContactsControllerGetDetailUrl(id);
577
596
  const url = `${baseUrl}${path}`;
578
597
  const res = await fetch(url, buildInit("GET"));
579
- return parseResponse(res);
598
+ return parseEnvelopedResponse(res);
580
599
  },
581
600
  /**
582
601
  * Return the tenant's tag catalog and custom-field definitions.
@@ -586,7 +605,7 @@ function createContactsModule(options) {
586
605
  const path = getContactsControllerGetMetadataUrl();
587
606
  const url = `${baseUrl}${path}`;
588
607
  const res = await fetch(url, buildInit("GET"));
589
- return parseResponse(res);
608
+ return parseEnvelopedResponse(res);
590
609
  },
591
610
  /**
592
611
  * Partially update a contact.
@@ -596,7 +615,7 @@ function createContactsModule(options) {
596
615
  const path = getContactsControllerPatchUrl(id);
597
616
  const url = `${baseUrl}${path}`;
598
617
  const res = await fetch(url, buildInit("PATCH", input));
599
- return parseResponse(res);
618
+ return parseEnvelopedResponse(res);
600
619
  },
601
620
  /**
602
621
  * Add a channel identity to an existing contact.
@@ -606,7 +625,7 @@ function createContactsModule(options) {
606
625
  const path = getContactsControllerAddIdentityUrl(id);
607
626
  const url = `${baseUrl}${path}`;
608
627
  const res = await fetch(url, buildInit("POST", input));
609
- return parseResponse(res);
628
+ return parseEnvelopedResponse(res);
610
629
  }
611
630
  };
612
631
  }
@@ -635,7 +654,7 @@ function createConversationsModule(options) {
635
654
  const path = getConversationsControllerReopenOrCreateUrl();
636
655
  const url = `${baseUrl}${path}`;
637
656
  const res = await fetch(url, buildInit("POST", input));
638
- return parseResponse(res);
657
+ return parseEnvelopedResponse(res);
639
658
  },
640
659
  /**
641
660
  * List conversations with optional filters (paginated, sorted deterministically).
@@ -663,7 +682,7 @@ function createConversationsModule(options) {
663
682
  const path = getConversationsControllerUpdateStatusUrl(id);
664
683
  const url = `${baseUrl}${path}`;
665
684
  const res = await fetch(url, buildInit("PATCH", input));
666
- return parseResponse(res);
685
+ return parseEnvelopedResponse(res);
667
686
  },
668
687
  /**
669
688
  * Assign a conversation to an agent.
@@ -673,7 +692,7 @@ function createConversationsModule(options) {
673
692
  const path = getConversationsControllerAssignUrl(id);
674
693
  const url = `${baseUrl}${path}`;
675
694
  const res = await fetch(url, buildInit("PATCH", input));
676
- return parseResponse(res);
695
+ return parseEnvelopedResponse(res);
677
696
  },
678
697
  /**
679
698
  * List lobby entries awaiting pickup (paginated, sorted by receivedAt DESC).
@@ -695,18 +714,18 @@ function createConversationsModule(options) {
695
714
  const path = getConversationsControllerFindOneUrl(id);
696
715
  const url = `${baseUrl}${path}`;
697
716
  const res = await fetch(url, buildInit("GET"));
698
- return parseResponse(res);
717
+ return parseEnvelopedResponse(res);
699
718
  },
700
719
  /**
701
720
  * Pick up a lobby entry (atomic 4-step transaction).
702
- * Returns the resulting conversation.
721
+ * Returns the resulting conversation + entry ids.
703
722
  * Calls POST /api/v1/conversations/lobby/:entryId/pickup.
704
723
  */
705
724
  async pickup(entryId, input) {
706
725
  const path = getConversationsControllerPickupLobbyEntryUrl(entryId);
707
726
  const url = `${baseUrl}${path}`;
708
727
  const res = await fetch(url, buildInit("POST", input));
709
- return parseResponse(res);
728
+ return parseEnvelopedResponse(res);
710
729
  },
711
730
  /**
712
731
  * List APPROVED + SENDABLE WhatsApp templates eligible to re-open an
@@ -718,7 +737,7 @@ function createConversationsModule(options) {
718
737
  const path = getConversationsControllerGetWhatsAppRecoveryOptionsUrl(id);
719
738
  const url = `${baseUrl}${path}`;
720
739
  const res = await fetch(url, buildInit("GET"));
721
- return parseResponse(res);
740
+ return parseEnvelopedResponse(res);
722
741
  }
723
742
  };
724
743
  }
@@ -746,7 +765,7 @@ function createMessagesModule(options) {
746
765
  const path = getMessagesControllerSendUrl();
747
766
  const url = `${baseUrl}${path}`;
748
767
  const res = await fetch(url, buildInit("POST", input));
749
- return parseResponse(res);
768
+ return parseEnvelopedResponse(res);
750
769
  },
751
770
  /**
752
771
  * List messages in a conversation (newest first, paginated).
@@ -774,7 +793,7 @@ function createMessagesModule(options) {
774
793
  const path = getMessagesControllerGetByIdUrl(id);
775
794
  const url = `${baseUrl}${path}`;
776
795
  const res = await fetch(url, buildInit("GET"));
777
- return parseResponse(res);
796
+ return parseEnvelopedResponse(res);
778
797
  },
779
798
  /**
780
799
  * Soft-delete a message (sets deletedAt; row preserved).
@@ -796,7 +815,7 @@ function createMessagesModule(options) {
796
815
  const path = getMessagesControllerSendTemplateUrl();
797
816
  const url = `${baseUrl}${path}`;
798
817
  const res = await fetch(url, buildInit("POST", input));
799
- return parseResponse(res);
818
+ return parseEnvelopedResponse(res);
800
819
  }
801
820
  };
802
821
  }
@@ -820,6 +839,38 @@ function createTemplatesModule(options) {
820
839
  * WhatsApp template submodule — WABA-scoped operations.
821
840
  */
822
841
  whatsapp: {
842
+ /**
843
+ * List a WhatsApp Business Account's templates (paginated, optionally status-filtered and name-searchable).
844
+ * Calls GET /api/v1/tenants/:id/whatsapp-business-accounts/:wabaId/templates.
845
+ */
846
+ async list(tenantId, wabaId, opts) {
847
+ const { page, pageSize } = buildPageParams(opts);
848
+ const path = getTemplatesControllerListUrl(tenantId, wabaId, {
849
+ page,
850
+ pageSize,
851
+ ...opts.status ? { status: opts.status } : {},
852
+ ...opts.q ? { q: opts.q } : {}
853
+ });
854
+ const url = `${baseUrl}${path}`;
855
+ const res = await fetch(url, buildInit("GET"));
856
+ return parseResponse(res);
857
+ },
858
+ /**
859
+ * Get a single template together with its current (latest) version.
860
+ * Language/status and other version-scoped fields are nested under
861
+ * `currentVersion` — not at the top level (see WhatsAppTemplateDetail).
862
+ * Calls GET /api/v1/tenants/:id/whatsapp-business-accounts/:wabaId/templates/:templateId.
863
+ */
864
+ async getById(tenantId, wabaId, templateId) {
865
+ const path = getTemplatesControllerGetByIdUrl(
866
+ tenantId,
867
+ wabaId,
868
+ templateId
869
+ );
870
+ const url = `${baseUrl}${path}`;
871
+ const res = await fetch(url, buildInit("GET"));
872
+ return parseEnvelopedResponse(res);
873
+ },
823
874
  /**
824
875
  * Author a new DRAFT template (version 1) under a WhatsApp Business Account.
825
876
  * Calls POST /api/v1/tenants/:id/whatsapp-business-accounts/:wabaId/templates.
@@ -855,7 +906,11 @@ function createTemplatesModule(options) {
855
906
  return parseEnvelopedResponse(res);
856
907
  },
857
908
  /**
858
- * List all versions and status events for a template in chronological order.
909
+ * Get the full version + status-event history for a template.
910
+ *
911
+ * Returns a single OBJECT (see WhatsAppTemplateHistory) — template-level
912
+ * fields plus a `versions` array ordered by versionNumber ascending, each
913
+ * version carrying its own `statusEvents`. NOT a flat array of events.
859
914
  * Calls GET /api/v1/tenants/:id/whatsapp-business-accounts/:wabaId/templates/:templateId/history.
860
915
  */
861
916
  async history(tenantId, wabaId, templateId) {
@@ -903,7 +958,11 @@ function createTemplatesModule(options) {
903
958
  */
904
959
  async list(opts) {
905
960
  const { page, pageSize } = buildPageParams(opts);
906
- const path = getEmailTemplatesControllerListUrl({ page, pageSize });
961
+ const path = getEmailTemplatesControllerListUrl({
962
+ page,
963
+ pageSize,
964
+ ...opts.q ? { q: opts.q } : {}
965
+ });
907
966
  const url = `${baseUrl}${path}`;
908
967
  const res = await fetch(url, buildInit("GET"));
909
968
  return parseResponse(res);
@@ -995,7 +1054,7 @@ function createCannedResponsesModule(options) {
995
1054
  const path = getCannedResponsesControllerCreateUrl();
996
1055
  const url = `${baseUrl}${path}`;
997
1056
  const res = await fetch(url, buildInit("POST", input));
998
- return parseResponse(res);
1057
+ return parseEnvelopedResponse(res);
999
1058
  },
1000
1059
  /**
1001
1060
  * Partially update a canned response — title, body, and/or keywords.
@@ -1005,7 +1064,7 @@ function createCannedResponsesModule(options) {
1005
1064
  const path = getCannedResponsesControllerPatchUrl(id);
1006
1065
  const url = `${baseUrl}${path}`;
1007
1066
  const res = await fetch(url, buildInit("PATCH", input));
1008
- return parseResponse(res);
1067
+ return parseEnvelopedResponse(res);
1009
1068
  },
1010
1069
  /**
1011
1070
  * Delete a canned response by id.
@@ -1050,7 +1109,7 @@ function createAttachmentsModule(options) {
1050
1109
  },
1051
1110
  body: form
1052
1111
  });
1053
- return parseResponse(res);
1112
+ return parseEnvelopedResponse(res);
1054
1113
  },
1055
1114
  /**
1056
1115
  * Get a short-lived presigned download URL for a stored attachment.
@@ -1068,7 +1127,7 @@ function createAttachmentsModule(options) {
1068
1127
  ...options.getHeaders()
1069
1128
  }
1070
1129
  });
1071
- return parseResponse(res);
1130
+ return parseEnvelopedResponse(res);
1072
1131
  }
1073
1132
  };
1074
1133
  }
@@ -1076,14 +1135,15 @@ function createAttachmentsModule(options) {
1076
1135
  // src/whatsapp-business-accounts/whatsapp-business-accounts.ts
1077
1136
  function createWhatsAppBusinessAccountsModule(options) {
1078
1137
  const baseUrl = options.baseUrl;
1079
- function buildInit(method) {
1138
+ function buildInit(method, body) {
1080
1139
  return {
1081
1140
  method,
1082
1141
  credentials: options.getCredentials(),
1083
1142
  headers: {
1084
1143
  "Content-Type": "application/json",
1085
1144
  ...options.getHeaders()
1086
- }
1145
+ },
1146
+ ...body !== void 0 ? { body: JSON.stringify(body) } : {}
1087
1147
  };
1088
1148
  }
1089
1149
  return {
@@ -1118,6 +1178,44 @@ function createWhatsAppBusinessAccountsModule(options) {
1118
1178
  const url = `${baseUrl}${path}`;
1119
1179
  const res = await fetch(url, buildInit("GET"));
1120
1180
  return parseEnvelopedResponse(res);
1181
+ },
1182
+ /**
1183
+ * Create a WhatsApp Business Account — writes the secret to the
1184
+ * SecretsProvider and the non-secret row to the DB; returns the
1185
+ * non-secret view (no `secretRef` exposed).
1186
+ * Calls POST /api/v1/tenants/:id/whatsapp-business-accounts.
1187
+ *
1188
+ * @example
1189
+ * const waba = await sdk.whatsappBusinessAccounts.create('ten_acmecorp', {
1190
+ * wabaId: '123456789012345',
1191
+ * name: 'Acme WhatsApp',
1192
+ * secret: { accessToken, appSecret, webhookVerifyToken },
1193
+ * })
1194
+ */
1195
+ async create(tenantId, body) {
1196
+ const path = getWhatsAppBusinessAccountsControllerCreateUrl(tenantId);
1197
+ const url = `${baseUrl}${path}`;
1198
+ const res = await fetch(url, buildInit("POST", body));
1199
+ return parseEnvelopedResponse(res);
1200
+ },
1201
+ /**
1202
+ * Rename a WhatsApp Business Account (name only — secret material is
1203
+ * immutable through this endpoint).
1204
+ * Calls PATCH /api/v1/tenants/:id/whatsapp-business-accounts/:wabaRowId.
1205
+ *
1206
+ * @example
1207
+ * await sdk.whatsappBusinessAccounts.update('ten_acmecorp', 'waba_row_001', {
1208
+ * name: 'Renamed WhatsApp',
1209
+ * })
1210
+ */
1211
+ async update(tenantId, wabaRowId, body) {
1212
+ const path = getWhatsAppBusinessAccountsControllerUpdateNameUrl(
1213
+ tenantId,
1214
+ wabaRowId
1215
+ );
1216
+ const url = `${baseUrl}${path}`;
1217
+ const res = await fetch(url, buildInit("PATCH", body));
1218
+ return parseEnvelopedResponse(res);
1121
1219
  }
1122
1220
  };
1123
1221
  }