@bentonow/bento-node-sdk 0.2.1 → 1.0.5

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.
Files changed (76) hide show
  1. package/{LICENSE → LICENSE.md} +1 -1
  2. package/README.md +604 -1031
  3. package/dist/index.d.ts +9 -9
  4. package/dist/index.js +1306 -5
  5. package/dist/sdk/batch/enums.d.ts +8 -8
  6. package/dist/sdk/batch/errors.d.ts +18 -18
  7. package/dist/sdk/batch/events.d.ts +71 -71
  8. package/dist/sdk/batch/index.d.ts +55 -55
  9. package/dist/sdk/batch/types.d.ts +37 -37
  10. package/dist/sdk/broadcasts/index.d.ts +26 -0
  11. package/dist/sdk/broadcasts/types.d.ts +32 -0
  12. package/dist/sdk/client/errors.d.ts +12 -6
  13. package/dist/sdk/client/index.d.ts +94 -64
  14. package/dist/sdk/client/types.d.ts +3 -3
  15. package/dist/sdk/commands/enums.d.ts +12 -12
  16. package/dist/sdk/commands/index.d.ts +79 -79
  17. package/dist/sdk/commands/types.d.ts +32 -32
  18. package/dist/sdk/email-templates/index.d.ts +21 -0
  19. package/dist/sdk/email-templates/types.d.ts +23 -0
  20. package/dist/sdk/enums.d.ts +12 -9
  21. package/dist/sdk/errors.d.ts +2 -2
  22. package/dist/sdk/experimental/index.d.ts +75 -57
  23. package/dist/sdk/experimental/types.d.ts +71 -41
  24. package/dist/sdk/fields/index.d.ts +29 -29
  25. package/dist/sdk/fields/types.d.ts +17 -17
  26. package/dist/sdk/forms/index.d.ts +14 -14
  27. package/dist/sdk/forms/types.d.ts +28 -28
  28. package/dist/sdk/index.d.ts +11 -8
  29. package/dist/sdk/interfaces.d.ts +17 -13
  30. package/dist/sdk/sequences/index.d.ts +13 -0
  31. package/dist/sdk/sequences/types.d.ts +18 -0
  32. package/dist/sdk/stats/index.d.ts +24 -0
  33. package/dist/sdk/stats/types.d.ts +26 -0
  34. package/dist/sdk/subscribers/index.d.ts +20 -20
  35. package/dist/sdk/subscribers/types.d.ts +25 -25
  36. package/dist/sdk/tags/index.d.ts +20 -20
  37. package/dist/sdk/tags/types.d.ts +17 -17
  38. package/dist/sdk/types.d.ts +41 -41
  39. package/dist/sdk/workflows/index.d.ts +13 -0
  40. package/dist/sdk/workflows/types.d.ts +18 -0
  41. package/dist/versions/v1/index.d.ts +168 -132
  42. package/dist/versions/v1/types.d.ts +31 -31
  43. package/package.json +31 -44
  44. package/src/sdk/batch/events.ts +1 -1
  45. package/src/sdk/batch/index.ts +15 -22
  46. package/src/sdk/broadcasts/index.ts +44 -0
  47. package/src/sdk/broadcasts/types.ts +38 -0
  48. package/src/sdk/client/errors.ts +14 -0
  49. package/src/sdk/client/index.ts +205 -49
  50. package/src/sdk/commands/index.ts +54 -89
  51. package/src/sdk/email-templates/index.ts +39 -0
  52. package/src/sdk/email-templates/types.ts +27 -0
  53. package/src/sdk/enums.ts +3 -0
  54. package/src/sdk/experimental/index.ts +44 -26
  55. package/src/sdk/experimental/types.ts +35 -0
  56. package/src/sdk/fields/index.ts +1 -3
  57. package/src/sdk/forms/index.ts +4 -9
  58. package/src/sdk/forms/types.ts +1 -7
  59. package/src/sdk/index.ts +3 -0
  60. package/src/sdk/interfaces.ts +4 -0
  61. package/src/sdk/sequences/index.ts +21 -0
  62. package/src/sdk/sequences/types.ts +21 -0
  63. package/src/sdk/stats/index.ts +37 -0
  64. package/src/sdk/stats/types.ts +28 -0
  65. package/src/sdk/subscribers/index.ts +5 -15
  66. package/src/sdk/tags/index.ts +1 -3
  67. package/src/sdk/types.ts +1 -1
  68. package/src/sdk/workflows/index.ts +21 -0
  69. package/src/sdk/workflows/types.ts +21 -0
  70. package/src/versions/v1/index.ts +65 -10
  71. package/dist/bento-node-sdk.cjs.development.js +0 -2071
  72. package/dist/bento-node-sdk.cjs.development.js.map +0 -1
  73. package/dist/bento-node-sdk.cjs.production.min.js +0 -2
  74. package/dist/bento-node-sdk.cjs.production.min.js.map +0 -1
  75. package/dist/bento-node-sdk.esm.js +0 -2063
  76. package/dist/bento-node-sdk.esm.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,8 +1,1309 @@
1
+ var __create = Object.create;
2
+ var __getProtoOf = Object.getPrototypeOf;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __toESM = (mod, isNodeMode, target) => {
7
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
8
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
9
+ for (let key of __getOwnPropNames(mod))
10
+ if (!__hasOwnProp.call(to, key))
11
+ __defProp(to, key, {
12
+ get: () => mod[key],
13
+ enumerable: true
14
+ });
15
+ return to;
16
+ };
17
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
1
18
 
2
- 'use strict'
19
+ // node_modules/cross-fetch/dist/browser-ponyfill.js
20
+ var require_browser_ponyfill = __commonJS((exports, module) => {
21
+ var __global__ = typeof globalThis !== "undefined" && globalThis || typeof self !== "undefined" && self || typeof global !== "undefined" && global;
22
+ var __globalThis__ = function() {
23
+ function F() {
24
+ this.fetch = false;
25
+ this.DOMException = __global__.DOMException;
26
+ }
27
+ F.prototype = __global__;
28
+ return new F;
29
+ }();
30
+ (function(globalThis2) {
31
+ var irrelevant = function(exports2) {
32
+ var g = typeof globalThis2 !== "undefined" && globalThis2 || typeof self !== "undefined" && self || typeof global !== "undefined" && global || {};
33
+ var support = {
34
+ searchParams: "URLSearchParams" in g,
35
+ iterable: "Symbol" in g && "iterator" in Symbol,
36
+ blob: "FileReader" in g && "Blob" in g && function() {
37
+ try {
38
+ new Blob;
39
+ return true;
40
+ } catch (e) {
41
+ return false;
42
+ }
43
+ }(),
44
+ formData: "FormData" in g,
45
+ arrayBuffer: "ArrayBuffer" in g
46
+ };
47
+ function isDataView(obj) {
48
+ return obj && DataView.prototype.isPrototypeOf(obj);
49
+ }
50
+ if (support.arrayBuffer) {
51
+ var viewClasses = [
52
+ "[object Int8Array]",
53
+ "[object Uint8Array]",
54
+ "[object Uint8ClampedArray]",
55
+ "[object Int16Array]",
56
+ "[object Uint16Array]",
57
+ "[object Int32Array]",
58
+ "[object Uint32Array]",
59
+ "[object Float32Array]",
60
+ "[object Float64Array]"
61
+ ];
62
+ var isArrayBufferView = ArrayBuffer.isView || function(obj) {
63
+ return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1;
64
+ };
65
+ }
66
+ function normalizeName(name) {
67
+ if (typeof name !== "string") {
68
+ name = String(name);
69
+ }
70
+ if (/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(name) || name === "") {
71
+ throw new TypeError('Invalid character in header field name: "' + name + '"');
72
+ }
73
+ return name.toLowerCase();
74
+ }
75
+ function normalizeValue(value) {
76
+ if (typeof value !== "string") {
77
+ value = String(value);
78
+ }
79
+ return value;
80
+ }
81
+ function iteratorFor(items) {
82
+ var iterator = {
83
+ next: function() {
84
+ var value = items.shift();
85
+ return { done: value === undefined, value };
86
+ }
87
+ };
88
+ if (support.iterable) {
89
+ iterator[Symbol.iterator] = function() {
90
+ return iterator;
91
+ };
92
+ }
93
+ return iterator;
94
+ }
95
+ function Headers(headers) {
96
+ this.map = {};
97
+ if (headers instanceof Headers) {
98
+ headers.forEach(function(value, name) {
99
+ this.append(name, value);
100
+ }, this);
101
+ } else if (Array.isArray(headers)) {
102
+ headers.forEach(function(header) {
103
+ if (header.length != 2) {
104
+ throw new TypeError("Headers constructor: expected name/value pair to be length 2, found" + header.length);
105
+ }
106
+ this.append(header[0], header[1]);
107
+ }, this);
108
+ } else if (headers) {
109
+ Object.getOwnPropertyNames(headers).forEach(function(name) {
110
+ this.append(name, headers[name]);
111
+ }, this);
112
+ }
113
+ }
114
+ Headers.prototype.append = function(name, value) {
115
+ name = normalizeName(name);
116
+ value = normalizeValue(value);
117
+ var oldValue = this.map[name];
118
+ this.map[name] = oldValue ? oldValue + ", " + value : value;
119
+ };
120
+ Headers.prototype["delete"] = function(name) {
121
+ delete this.map[normalizeName(name)];
122
+ };
123
+ Headers.prototype.get = function(name) {
124
+ name = normalizeName(name);
125
+ return this.has(name) ? this.map[name] : null;
126
+ };
127
+ Headers.prototype.has = function(name) {
128
+ return this.map.hasOwnProperty(normalizeName(name));
129
+ };
130
+ Headers.prototype.set = function(name, value) {
131
+ this.map[normalizeName(name)] = normalizeValue(value);
132
+ };
133
+ Headers.prototype.forEach = function(callback, thisArg) {
134
+ for (var name in this.map) {
135
+ if (this.map.hasOwnProperty(name)) {
136
+ callback.call(thisArg, this.map[name], name, this);
137
+ }
138
+ }
139
+ };
140
+ Headers.prototype.keys = function() {
141
+ var items = [];
142
+ this.forEach(function(value, name) {
143
+ items.push(name);
144
+ });
145
+ return iteratorFor(items);
146
+ };
147
+ Headers.prototype.values = function() {
148
+ var items = [];
149
+ this.forEach(function(value) {
150
+ items.push(value);
151
+ });
152
+ return iteratorFor(items);
153
+ };
154
+ Headers.prototype.entries = function() {
155
+ var items = [];
156
+ this.forEach(function(value, name) {
157
+ items.push([name, value]);
158
+ });
159
+ return iteratorFor(items);
160
+ };
161
+ if (support.iterable) {
162
+ Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
163
+ }
164
+ function consumed(body) {
165
+ if (body._noBody)
166
+ return;
167
+ if (body.bodyUsed) {
168
+ return Promise.reject(new TypeError("Already read"));
169
+ }
170
+ body.bodyUsed = true;
171
+ }
172
+ function fileReaderReady(reader) {
173
+ return new Promise(function(resolve, reject) {
174
+ reader.onload = function() {
175
+ resolve(reader.result);
176
+ };
177
+ reader.onerror = function() {
178
+ reject(reader.error);
179
+ };
180
+ });
181
+ }
182
+ function readBlobAsArrayBuffer(blob) {
183
+ var reader = new FileReader;
184
+ var promise = fileReaderReady(reader);
185
+ reader.readAsArrayBuffer(blob);
186
+ return promise;
187
+ }
188
+ function readBlobAsText(blob) {
189
+ var reader = new FileReader;
190
+ var promise = fileReaderReady(reader);
191
+ var match = /charset=([A-Za-z0-9_-]+)/.exec(blob.type);
192
+ var encoding = match ? match[1] : "utf-8";
193
+ reader.readAsText(blob, encoding);
194
+ return promise;
195
+ }
196
+ function readArrayBufferAsText(buf) {
197
+ var view = new Uint8Array(buf);
198
+ var chars = new Array(view.length);
199
+ for (var i = 0;i < view.length; i++) {
200
+ chars[i] = String.fromCharCode(view[i]);
201
+ }
202
+ return chars.join("");
203
+ }
204
+ function bufferClone(buf) {
205
+ if (buf.slice) {
206
+ return buf.slice(0);
207
+ } else {
208
+ var view = new Uint8Array(buf.byteLength);
209
+ view.set(new Uint8Array(buf));
210
+ return view.buffer;
211
+ }
212
+ }
213
+ function Body() {
214
+ this.bodyUsed = false;
215
+ this._initBody = function(body) {
216
+ this.bodyUsed = this.bodyUsed;
217
+ this._bodyInit = body;
218
+ if (!body) {
219
+ this._noBody = true;
220
+ this._bodyText = "";
221
+ } else if (typeof body === "string") {
222
+ this._bodyText = body;
223
+ } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
224
+ this._bodyBlob = body;
225
+ } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
226
+ this._bodyFormData = body;
227
+ } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
228
+ this._bodyText = body.toString();
229
+ } else if (support.arrayBuffer && support.blob && isDataView(body)) {
230
+ this._bodyArrayBuffer = bufferClone(body.buffer);
231
+ this._bodyInit = new Blob([this._bodyArrayBuffer]);
232
+ } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
233
+ this._bodyArrayBuffer = bufferClone(body);
234
+ } else {
235
+ this._bodyText = body = Object.prototype.toString.call(body);
236
+ }
237
+ if (!this.headers.get("content-type")) {
238
+ if (typeof body === "string") {
239
+ this.headers.set("content-type", "text/plain;charset=UTF-8");
240
+ } else if (this._bodyBlob && this._bodyBlob.type) {
241
+ this.headers.set("content-type", this._bodyBlob.type);
242
+ } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
243
+ this.headers.set("content-type", "application/x-www-form-urlencoded;charset=UTF-8");
244
+ }
245
+ }
246
+ };
247
+ if (support.blob) {
248
+ this.blob = function() {
249
+ var rejected = consumed(this);
250
+ if (rejected) {
251
+ return rejected;
252
+ }
253
+ if (this._bodyBlob) {
254
+ return Promise.resolve(this._bodyBlob);
255
+ } else if (this._bodyArrayBuffer) {
256
+ return Promise.resolve(new Blob([this._bodyArrayBuffer]));
257
+ } else if (this._bodyFormData) {
258
+ throw new Error("could not read FormData body as blob");
259
+ } else {
260
+ return Promise.resolve(new Blob([this._bodyText]));
261
+ }
262
+ };
263
+ }
264
+ this.arrayBuffer = function() {
265
+ if (this._bodyArrayBuffer) {
266
+ var isConsumed = consumed(this);
267
+ if (isConsumed) {
268
+ return isConsumed;
269
+ } else if (ArrayBuffer.isView(this._bodyArrayBuffer)) {
270
+ return Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset, this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength));
271
+ } else {
272
+ return Promise.resolve(this._bodyArrayBuffer);
273
+ }
274
+ } else if (support.blob) {
275
+ return this.blob().then(readBlobAsArrayBuffer);
276
+ } else {
277
+ throw new Error("could not read as ArrayBuffer");
278
+ }
279
+ };
280
+ this.text = function() {
281
+ var rejected = consumed(this);
282
+ if (rejected) {
283
+ return rejected;
284
+ }
285
+ if (this._bodyBlob) {
286
+ return readBlobAsText(this._bodyBlob);
287
+ } else if (this._bodyArrayBuffer) {
288
+ return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer));
289
+ } else if (this._bodyFormData) {
290
+ throw new Error("could not read FormData body as text");
291
+ } else {
292
+ return Promise.resolve(this._bodyText);
293
+ }
294
+ };
295
+ if (support.formData) {
296
+ this.formData = function() {
297
+ return this.text().then(decode);
298
+ };
299
+ }
300
+ this.json = function() {
301
+ return this.text().then(JSON.parse);
302
+ };
303
+ return this;
304
+ }
305
+ var methods = ["CONNECT", "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT", "TRACE"];
306
+ function normalizeMethod(method) {
307
+ var upcased = method.toUpperCase();
308
+ return methods.indexOf(upcased) > -1 ? upcased : method;
309
+ }
310
+ function Request(input, options) {
311
+ if (!(this instanceof Request)) {
312
+ throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');
313
+ }
314
+ options = options || {};
315
+ var body = options.body;
316
+ if (input instanceof Request) {
317
+ if (input.bodyUsed) {
318
+ throw new TypeError("Already read");
319
+ }
320
+ this.url = input.url;
321
+ this.credentials = input.credentials;
322
+ if (!options.headers) {
323
+ this.headers = new Headers(input.headers);
324
+ }
325
+ this.method = input.method;
326
+ this.mode = input.mode;
327
+ this.signal = input.signal;
328
+ if (!body && input._bodyInit != null) {
329
+ body = input._bodyInit;
330
+ input.bodyUsed = true;
331
+ }
332
+ } else {
333
+ this.url = String(input);
334
+ }
335
+ this.credentials = options.credentials || this.credentials || "same-origin";
336
+ if (options.headers || !this.headers) {
337
+ this.headers = new Headers(options.headers);
338
+ }
339
+ this.method = normalizeMethod(options.method || this.method || "GET");
340
+ this.mode = options.mode || this.mode || null;
341
+ this.signal = options.signal || this.signal || function() {
342
+ if ("AbortController" in g) {
343
+ var ctrl = new AbortController;
344
+ return ctrl.signal;
345
+ }
346
+ }();
347
+ this.referrer = null;
348
+ if ((this.method === "GET" || this.method === "HEAD") && body) {
349
+ throw new TypeError("Body not allowed for GET or HEAD requests");
350
+ }
351
+ this._initBody(body);
352
+ if (this.method === "GET" || this.method === "HEAD") {
353
+ if (options.cache === "no-store" || options.cache === "no-cache") {
354
+ var reParamSearch = /([?&])_=[^&]*/;
355
+ if (reParamSearch.test(this.url)) {
356
+ this.url = this.url.replace(reParamSearch, "$1_=" + new Date().getTime());
357
+ } else {
358
+ var reQueryString = /\?/;
359
+ this.url += (reQueryString.test(this.url) ? "&" : "?") + "_=" + new Date().getTime();
360
+ }
361
+ }
362
+ }
363
+ }
364
+ Request.prototype.clone = function() {
365
+ return new Request(this, { body: this._bodyInit });
366
+ };
367
+ function decode(body) {
368
+ var form = new FormData;
369
+ body.trim().split("&").forEach(function(bytes) {
370
+ if (bytes) {
371
+ var split = bytes.split("=");
372
+ var name = split.shift().replace(/\+/g, " ");
373
+ var value = split.join("=").replace(/\+/g, " ");
374
+ form.append(decodeURIComponent(name), decodeURIComponent(value));
375
+ }
376
+ });
377
+ return form;
378
+ }
379
+ function parseHeaders(rawHeaders) {
380
+ var headers = new Headers;
381
+ var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, " ");
382
+ preProcessedHeaders.split("\r").map(function(header) {
383
+ return header.indexOf(`
384
+ `) === 0 ? header.substr(1, header.length) : header;
385
+ }).forEach(function(line) {
386
+ var parts = line.split(":");
387
+ var key = parts.shift().trim();
388
+ if (key) {
389
+ var value = parts.join(":").trim();
390
+ try {
391
+ headers.append(key, value);
392
+ } catch (error) {
393
+ console.warn("Response " + error.message);
394
+ }
395
+ }
396
+ });
397
+ return headers;
398
+ }
399
+ Body.call(Request.prototype);
400
+ function Response(bodyInit, options) {
401
+ if (!(this instanceof Response)) {
402
+ throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');
403
+ }
404
+ if (!options) {
405
+ options = {};
406
+ }
407
+ this.type = "default";
408
+ this.status = options.status === undefined ? 200 : options.status;
409
+ if (this.status < 200 || this.status > 599) {
410
+ throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].");
411
+ }
412
+ this.ok = this.status >= 200 && this.status < 300;
413
+ this.statusText = options.statusText === undefined ? "" : "" + options.statusText;
414
+ this.headers = new Headers(options.headers);
415
+ this.url = options.url || "";
416
+ this._initBody(bodyInit);
417
+ }
418
+ Body.call(Response.prototype);
419
+ Response.prototype.clone = function() {
420
+ return new Response(this._bodyInit, {
421
+ status: this.status,
422
+ statusText: this.statusText,
423
+ headers: new Headers(this.headers),
424
+ url: this.url
425
+ });
426
+ };
427
+ Response.error = function() {
428
+ var response = new Response(null, { status: 200, statusText: "" });
429
+ response.ok = false;
430
+ response.status = 0;
431
+ response.type = "error";
432
+ return response;
433
+ };
434
+ var redirectStatuses = [301, 302, 303, 307, 308];
435
+ Response.redirect = function(url, status) {
436
+ if (redirectStatuses.indexOf(status) === -1) {
437
+ throw new RangeError("Invalid status code");
438
+ }
439
+ return new Response(null, { status, headers: { location: url } });
440
+ };
441
+ exports2.DOMException = g.DOMException;
442
+ try {
443
+ new exports2.DOMException;
444
+ } catch (err) {
445
+ exports2.DOMException = function(message, name) {
446
+ this.message = message;
447
+ this.name = name;
448
+ var error = Error(message);
449
+ this.stack = error.stack;
450
+ };
451
+ exports2.DOMException.prototype = Object.create(Error.prototype);
452
+ exports2.DOMException.prototype.constructor = exports2.DOMException;
453
+ }
454
+ function fetch(input, init) {
455
+ return new Promise(function(resolve, reject) {
456
+ var request = new Request(input, init);
457
+ if (request.signal && request.signal.aborted) {
458
+ return reject(new exports2.DOMException("Aborted", "AbortError"));
459
+ }
460
+ var xhr = new XMLHttpRequest;
461
+ function abortXhr() {
462
+ xhr.abort();
463
+ }
464
+ xhr.onload = function() {
465
+ var options = {
466
+ statusText: xhr.statusText,
467
+ headers: parseHeaders(xhr.getAllResponseHeaders() || "")
468
+ };
469
+ if (request.url.indexOf("file://") === 0 && (xhr.status < 200 || xhr.status > 599)) {
470
+ options.status = 200;
471
+ } else {
472
+ options.status = xhr.status;
473
+ }
474
+ options.url = "responseURL" in xhr ? xhr.responseURL : options.headers.get("X-Request-URL");
475
+ var body = "response" in xhr ? xhr.response : xhr.responseText;
476
+ setTimeout(function() {
477
+ resolve(new Response(body, options));
478
+ }, 0);
479
+ };
480
+ xhr.onerror = function() {
481
+ setTimeout(function() {
482
+ reject(new TypeError("Network request failed"));
483
+ }, 0);
484
+ };
485
+ xhr.ontimeout = function() {
486
+ setTimeout(function() {
487
+ reject(new TypeError("Network request timed out"));
488
+ }, 0);
489
+ };
490
+ xhr.onabort = function() {
491
+ setTimeout(function() {
492
+ reject(new exports2.DOMException("Aborted", "AbortError"));
493
+ }, 0);
494
+ };
495
+ function fixUrl(url) {
496
+ try {
497
+ return url === "" && g.location.href ? g.location.href : url;
498
+ } catch (e) {
499
+ return url;
500
+ }
501
+ }
502
+ xhr.open(request.method, fixUrl(request.url), true);
503
+ if (request.credentials === "include") {
504
+ xhr.withCredentials = true;
505
+ } else if (request.credentials === "omit") {
506
+ xhr.withCredentials = false;
507
+ }
508
+ if ("responseType" in xhr) {
509
+ if (support.blob) {
510
+ xhr.responseType = "blob";
511
+ } else if (support.arrayBuffer) {
512
+ xhr.responseType = "arraybuffer";
513
+ }
514
+ }
515
+ if (init && typeof init.headers === "object" && !(init.headers instanceof Headers || g.Headers && init.headers instanceof g.Headers)) {
516
+ var names = [];
517
+ Object.getOwnPropertyNames(init.headers).forEach(function(name) {
518
+ names.push(normalizeName(name));
519
+ xhr.setRequestHeader(name, normalizeValue(init.headers[name]));
520
+ });
521
+ request.headers.forEach(function(value, name) {
522
+ if (names.indexOf(name) === -1) {
523
+ xhr.setRequestHeader(name, value);
524
+ }
525
+ });
526
+ } else {
527
+ request.headers.forEach(function(value, name) {
528
+ xhr.setRequestHeader(name, value);
529
+ });
530
+ }
531
+ if (request.signal) {
532
+ request.signal.addEventListener("abort", abortXhr);
533
+ xhr.onreadystatechange = function() {
534
+ if (xhr.readyState === 4) {
535
+ request.signal.removeEventListener("abort", abortXhr);
536
+ }
537
+ };
538
+ }
539
+ xhr.send(typeof request._bodyInit === "undefined" ? null : request._bodyInit);
540
+ });
541
+ }
542
+ fetch.polyfill = true;
543
+ if (!g.fetch) {
544
+ g.fetch = fetch;
545
+ g.Headers = Headers;
546
+ g.Request = Request;
547
+ g.Response = Response;
548
+ }
549
+ exports2.Headers = Headers;
550
+ exports2.Request = Request;
551
+ exports2.Response = Response;
552
+ exports2.fetch = fetch;
553
+ return exports2;
554
+ }({});
555
+ })(__globalThis__);
556
+ __globalThis__.fetch.ponyfill = true;
557
+ delete __globalThis__.fetch.polyfill;
558
+ var ctx = __global__.fetch ? __global__ : __globalThis__;
559
+ exports = ctx.fetch;
560
+ exports.default = ctx.fetch;
561
+ exports.fetch = ctx.fetch;
562
+ exports.Headers = ctx.Headers;
563
+ exports.Request = ctx.Request;
564
+ exports.Response = ctx.Response;
565
+ module.exports = exports;
566
+ });
3
567
 
4
- if (process.env.NODE_ENV === 'production') {
5
- module.exports = require('./bento-node-sdk.cjs.production.min.js')
6
- } else {
7
- module.exports = require('./bento-node-sdk.cjs.development.js')
568
+ // src/sdk/batch/errors.ts
569
+ class TooFewSubscribersError extends Error {
570
+ constructor(message = "Too few subscribers") {
571
+ super(message);
572
+ this.name = "TooFewSubscribersError";
573
+ }
8
574
  }
575
+
576
+ class TooManySubscribersError extends Error {
577
+ constructor(message = "Too many subscribers") {
578
+ super(message);
579
+ this.name = "TooManySubscribersError";
580
+ }
581
+ }
582
+
583
+ class TooFewEventsError extends Error {
584
+ constructor(message = "Too few events") {
585
+ super(message);
586
+ this.name = "TooFewEventsError";
587
+ }
588
+ }
589
+
590
+ class TooManyEventsError extends Error {
591
+ constructor(message = "Too many events") {
592
+ super(message);
593
+ this.name = "TooManyEventsError";
594
+ }
595
+ }
596
+
597
+ class TooFewEmailsError extends Error {
598
+ constructor(message = "Too few emails") {
599
+ super(message);
600
+ this.name = "TooFewEmailsError";
601
+ }
602
+ }
603
+
604
+ class TooManyEmailsError extends Error {
605
+ constructor(message = "Too many emails") {
606
+ super(message);
607
+ this.name = "TooManyEmailsError";
608
+ }
609
+ }
610
+
611
+ // src/sdk/batch/index.ts
612
+ class BentoBatch {
613
+ _client;
614
+ _maxEmailBatchSize = 100;
615
+ _maxBatchSize = 1000;
616
+ _url = "/batch";
617
+ constructor(_client) {
618
+ this._client = _client;
619
+ }
620
+ async importSubscribers(parameters) {
621
+ if (parameters.subscribers.length === 0) {
622
+ throw new TooFewSubscribersError(`You must send between 1 and 1,000 subscribers.`);
623
+ }
624
+ if (parameters.subscribers.length > this._maxBatchSize) {
625
+ throw new TooManySubscribersError(`You must send between 1 and 1,000 subscribers.`);
626
+ }
627
+ const result = await this._client.post(`${this._url}/subscribers`, {
628
+ subscribers: parameters.subscribers
629
+ }, { timeout: null });
630
+ return result.results;
631
+ }
632
+ async importEvents(parameters) {
633
+ if (parameters.events.length === 0) {
634
+ throw new TooFewEventsError(`You must send between 1 and 1,000 events.`);
635
+ }
636
+ if (parameters.events.length > this._maxBatchSize) {
637
+ throw new TooManyEventsError(`You must send between 1 and 1,000 events.`);
638
+ }
639
+ const result = await this._client.post(`${this._url}/events`, {
640
+ events: parameters.events
641
+ }, { timeout: null });
642
+ return result.results;
643
+ }
644
+ async sendTransactionalEmails(parameters) {
645
+ if (parameters.emails.length === 0) {
646
+ throw new TooFewEmailsError(`You must send between 1 and 100 emails.`);
647
+ }
648
+ if (parameters.emails.length > this._maxEmailBatchSize) {
649
+ throw new TooManyEmailsError(`You must send between 1 and 100 emails.`);
650
+ }
651
+ const result = await this._client.post(`${this._url}/emails`, {
652
+ emails: parameters.emails
653
+ });
654
+ return result.results;
655
+ }
656
+ }
657
+ // src/sdk/client/index.ts
658
+ var import_cross_fetch = __toESM(require_browser_ponyfill(), 1);
659
+
660
+ // src/sdk/client/errors.ts
661
+ class NotAuthorizedError extends Error {
662
+ constructor(message = "Not authorized") {
663
+ super(message);
664
+ this.name = "NotAuthorizedError";
665
+ }
666
+ }
667
+
668
+ class RateLimitedError extends Error {
669
+ constructor(message = "You are being rate limited") {
670
+ super(message);
671
+ this.name = "RateLimitedError";
672
+ }
673
+ }
674
+
675
+ class AuthorNotAuthorizedError extends Error {
676
+ constructor(message = "Author not authorized to send on this account") {
677
+ super(message);
678
+ this.name = "AuthorNotAuthorizedError";
679
+ }
680
+ }
681
+
682
+ class RequestTimeoutError extends Error {
683
+ constructor(message = "Request timed out") {
684
+ super(message);
685
+ this.name = "RequestTimeoutError";
686
+ }
687
+ }
688
+
689
+ // src/sdk/client/index.ts
690
+ function encodeBase64(str) {
691
+ if (typeof btoa === "function") {
692
+ return btoa(str);
693
+ } else if (typeof Buffer !== "undefined") {
694
+ return Buffer.from(str).toString("base64");
695
+ } else {
696
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
697
+ let output = "";
698
+ for (let block = 0, charCode, i = 0, map = chars;str.charAt(i | 0) || (map = "=", i % 1); output += map.charAt(63 & block >> 8 - i % 1 * 8)) {
699
+ charCode = str.charCodeAt(i += 3 / 4);
700
+ if (charCode > 255) {
701
+ throw new Error("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");
702
+ }
703
+ block = block << 8 | charCode;
704
+ }
705
+ return output;
706
+ }
707
+ }
708
+
709
+ class BentoClient {
710
+ _headers = {};
711
+ _baseUrl = "https://app.bentonow.com/api/v1";
712
+ _siteUuid = "";
713
+ _logErrors = false;
714
+ _timeout = 30000;
715
+ constructor(options) {
716
+ this._baseUrl = options.clientOptions?.baseUrl || this._baseUrl;
717
+ this._siteUuid = options.siteUuid;
718
+ this._headers = this._extractHeaders(options.authentication, options.siteUuid);
719
+ this._logErrors = options.logErrors || false;
720
+ this._timeout = options.clientOptions?.timeout ?? this._timeout;
721
+ }
722
+ async get(endpoint, payload = {}, requestOptions = {}) {
723
+ const queryParameters = this._getQueryParameters(payload);
724
+ const url = `${this._baseUrl}${endpoint}?${queryParameters}`;
725
+ const timeoutMs = requestOptions.timeout === undefined ? this._timeout : requestOptions.timeout;
726
+ const response = await this._fetchWithTimeout(url, {
727
+ method: "GET",
728
+ headers: this._headers
729
+ }, timeoutMs);
730
+ return this._handleResponse(response);
731
+ }
732
+ async post(endpoint, payload = {}, requestOptions = {}) {
733
+ const body = this._getBody(payload);
734
+ const url = `${this._baseUrl}${endpoint}`;
735
+ const timeoutMs = requestOptions.timeout === undefined ? this._timeout : requestOptions.timeout;
736
+ const response = await this._fetchWithTimeout(url, {
737
+ method: "POST",
738
+ headers: {
739
+ ...this._headers,
740
+ "Content-Type": "application/json"
741
+ },
742
+ body
743
+ }, timeoutMs);
744
+ return this._handleResponse(response);
745
+ }
746
+ async patch(endpoint, payload = {}, requestOptions = {}) {
747
+ const body = this._getBody(payload);
748
+ const url = `${this._baseUrl}${endpoint}`;
749
+ const timeoutMs = requestOptions.timeout === undefined ? this._timeout : requestOptions.timeout;
750
+ const response = await this._fetchWithTimeout(url, {
751
+ method: "PATCH",
752
+ headers: {
753
+ ...this._headers,
754
+ "Content-Type": "application/json"
755
+ },
756
+ body
757
+ }, timeoutMs);
758
+ return this._handleResponse(response);
759
+ }
760
+ async _fetchWithTimeout(url, options, timeout) {
761
+ if (timeout === null) {
762
+ return import_cross_fetch.default(url, options);
763
+ }
764
+ const controller = new AbortController;
765
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
766
+ try {
767
+ const response = await import_cross_fetch.default(url, {
768
+ ...options,
769
+ signal: controller.signal
770
+ });
771
+ return response;
772
+ } catch (error) {
773
+ if (error instanceof Error && error.name === "AbortError") {
774
+ throw new RequestTimeoutError(`Request timed out after ${timeout}ms`);
775
+ }
776
+ throw error;
777
+ } finally {
778
+ clearTimeout(timeoutId);
779
+ }
780
+ }
781
+ async _handleResponse(response) {
782
+ if (this._isSuccessfulStatus(response.status)) {
783
+ try {
784
+ const data = await response.json();
785
+ return data;
786
+ } catch {
787
+ throw new Error(`[${response.status}] - Invalid JSON response from server`);
788
+ }
789
+ }
790
+ throw await this._getErrorForResponse(response);
791
+ }
792
+ _extractHeaders(authentication, siteUuid) {
793
+ const authenticationKey = encodeBase64(`${authentication.publishableKey}:${authentication.secretKey}`);
794
+ return {
795
+ Authorization: `Basic ${authenticationKey}`,
796
+ "User-Agent": `bento-node-${siteUuid}`
797
+ };
798
+ }
799
+ _getBody(payload) {
800
+ return JSON.stringify({
801
+ ...payload,
802
+ site_uuid: this._siteUuid
803
+ });
804
+ }
805
+ _getQueryParameters(payload) {
806
+ const body = {
807
+ ...payload,
808
+ site_uuid: this._siteUuid
809
+ };
810
+ const queryParameters = new URLSearchParams;
811
+ for (const [key, value] of Object.entries(body)) {
812
+ queryParameters.append(key, String(value));
813
+ }
814
+ return queryParameters.toString();
815
+ }
816
+ _isSuccessfulStatus(statusCode) {
817
+ const validStatusCodes = [200, 201];
818
+ return validStatusCodes.includes(statusCode);
819
+ }
820
+ async _getErrorForResponse(response) {
821
+ if (this._logErrors) {
822
+ console.error(response);
823
+ }
824
+ if (response.status === 401)
825
+ return new NotAuthorizedError;
826
+ if (response.status === 429)
827
+ return new RateLimitedError;
828
+ const contentType = response.headers.get("Content-Type");
829
+ let responseMessage = "";
830
+ let json = null;
831
+ try {
832
+ if (contentType?.toLowerCase().includes("application/json")) {
833
+ try {
834
+ json = await response.json();
835
+ } catch {
836
+ responseMessage = "Unable to parse JSON response";
837
+ }
838
+ } else if (contentType?.toLowerCase().includes("text/plain")) {
839
+ try {
840
+ responseMessage = await response.text();
841
+ } catch {
842
+ responseMessage = "Unable to read text response";
843
+ }
844
+ } else {
845
+ responseMessage = "Unknown response from the Bento API.";
846
+ }
847
+ } catch {
848
+ responseMessage = "Unable to read response body";
849
+ }
850
+ if (json && json.error === "Author not authorized to send on this account") {
851
+ return new AuthorNotAuthorizedError(json.error);
852
+ }
853
+ if (json) {
854
+ responseMessage = JSON.stringify(json);
855
+ }
856
+ if (!responseMessage) {
857
+ responseMessage = "Unknown response from the Bento API.";
858
+ }
859
+ return new Error(`[${response.status}] - ${responseMessage}`);
860
+ }
861
+ }
862
+ // src/sdk/commands/index.ts
863
+ class BentoCommands {
864
+ _client;
865
+ _url = "/fetch/commands";
866
+ constructor(_client) {
867
+ this._client = _client;
868
+ }
869
+ async addTag(parameters) {
870
+ const result = await this._client.post(this._url, {
871
+ command: {
872
+ command: "add_tag" /* ADD_TAG */,
873
+ email: parameters.email,
874
+ query: parameters.tagName
875
+ }
876
+ });
877
+ if (Object.keys(result).length === 0 || !result.data)
878
+ return null;
879
+ return result.data;
880
+ }
881
+ async removeTag(parameters) {
882
+ const result = await this._client.post(this._url, {
883
+ command: {
884
+ command: "remove_tag" /* REMOVE_TAG */,
885
+ email: parameters.email,
886
+ query: parameters.tagName
887
+ }
888
+ });
889
+ if (Object.keys(result).length === 0 || !result.data)
890
+ return null;
891
+ return result.data;
892
+ }
893
+ async addField(parameters) {
894
+ const result = await this._client.post(this._url, {
895
+ command: {
896
+ command: "add_field" /* ADD_FIELD */,
897
+ email: parameters.email,
898
+ query: parameters.field
899
+ }
900
+ });
901
+ if (Object.keys(result).length === 0 || !result.data)
902
+ return null;
903
+ return result.data;
904
+ }
905
+ async removeField(parameters) {
906
+ const result = await this._client.post(this._url, {
907
+ command: {
908
+ command: "remove_field" /* REMOVE_FIELD */,
909
+ email: parameters.email,
910
+ query: parameters.fieldName
911
+ }
912
+ });
913
+ if (Object.keys(result).length === 0 || !result.data)
914
+ return null;
915
+ return result.data;
916
+ }
917
+ async subscribe(parameters) {
918
+ const result = await this._client.post(this._url, {
919
+ command: {
920
+ command: "subscribe" /* SUBSCRIBE */,
921
+ email: parameters.email
922
+ }
923
+ });
924
+ if (Object.keys(result).length === 0 || !result.data)
925
+ return null;
926
+ return result.data;
927
+ }
928
+ async unsubscribe(parameters) {
929
+ const result = await this._client.post(this._url, {
930
+ command: {
931
+ command: "unsubscribe" /* UNSUBSCRIBE */,
932
+ email: parameters.email
933
+ }
934
+ });
935
+ if (Object.keys(result).length === 0 || !result.data)
936
+ return null;
937
+ return result.data;
938
+ }
939
+ async changeEmail(parameters) {
940
+ const result = await this._client.post(this._url, {
941
+ command: {
942
+ command: "change_email" /* CHANGE_EMAIL */,
943
+ email: parameters.oldEmail,
944
+ query: parameters.newEmail
945
+ }
946
+ });
947
+ if (Object.keys(result).length === 0 || !result.data)
948
+ return null;
949
+ return result.data;
950
+ }
951
+ }
952
+ // src/sdk/email-templates/index.ts
953
+ class BentoEmailTemplates {
954
+ _client;
955
+ _url = "/fetch/emails/templates";
956
+ constructor(_client) {
957
+ this._client = _client;
958
+ }
959
+ async getEmailTemplate(parameters) {
960
+ const result = await this._client.get(`${this._url}/${parameters.id}`);
961
+ if (Object.keys(result).length === 0 || !result.data)
962
+ return null;
963
+ return result.data;
964
+ }
965
+ async updateEmailTemplate(parameters) {
966
+ const { id, ...updateFields } = parameters;
967
+ const result = await this._client.patch(`${this._url}/${id}`, {
968
+ email_template: updateFields
969
+ });
970
+ if (Object.keys(result).length === 0 || !result.data)
971
+ return null;
972
+ return result.data;
973
+ }
974
+ }
975
+ // src/sdk/experimental/index.ts
976
+ class BentoExperimental {
977
+ _client;
978
+ _url = "/experimental";
979
+ constructor(_client) {
980
+ this._client = _client;
981
+ }
982
+ async validateEmail(parameters) {
983
+ const result = await this._client.post(`${this._url}/validation`, {
984
+ email: parameters.email,
985
+ ip: parameters.ip,
986
+ name: parameters.name,
987
+ user_agent: parameters.userAgent
988
+ });
989
+ return result.valid;
990
+ }
991
+ async guessGender(parameters) {
992
+ const result = await this._client.post(`${this._url}/gender`, parameters);
993
+ return result;
994
+ }
995
+ async geolocate(parameters) {
996
+ const result = await this._client.get(`${this._url}/geolocation`, parameters);
997
+ if (Object.keys(result).length === 0)
998
+ return null;
999
+ return result;
1000
+ }
1001
+ async checkBlacklist(parameters) {
1002
+ const result = await this._client.get(`${this._url}/blacklist.json`, parameters);
1003
+ return result;
1004
+ }
1005
+ async getBlacklistStatus(input) {
1006
+ return this._client.get(`${this._url}/blacklist`, input);
1007
+ }
1008
+ async getContentModeration(content) {
1009
+ return this._client.post(`${this._url}/moderation`, {
1010
+ content
1011
+ });
1012
+ }
1013
+ async geoLocateIP(ipAddress) {
1014
+ return this._client.get(`${this._url}/geolocation`, {
1015
+ ip: ipAddress
1016
+ });
1017
+ }
1018
+ }
1019
+ // src/sdk/fields/index.ts
1020
+ class BentoFields {
1021
+ _client;
1022
+ _url = "/fetch/fields";
1023
+ constructor(_client) {
1024
+ this._client = _client;
1025
+ }
1026
+ async getFields() {
1027
+ const result = await this._client.get(this._url);
1028
+ if (Object.keys(result).length === 0 || !result.data)
1029
+ return null;
1030
+ return result.data;
1031
+ }
1032
+ async createField(parameters) {
1033
+ const result = await this._client.post(this._url, {
1034
+ field: parameters
1035
+ });
1036
+ if (Object.keys(result).length === 0 || !result.data)
1037
+ return null;
1038
+ return result.data;
1039
+ }
1040
+ }
1041
+ // src/sdk/forms/index.ts
1042
+ class BentoForms {
1043
+ _client;
1044
+ _url = "/fetch/responses";
1045
+ constructor(_client) {
1046
+ this._client = _client;
1047
+ }
1048
+ async getResponses(formIdentifier) {
1049
+ const result = await this._client.get(this._url, {
1050
+ id: formIdentifier
1051
+ });
1052
+ if (Object.keys(result).length === 0 || !result.data)
1053
+ return null;
1054
+ return result.data;
1055
+ }
1056
+ }
1057
+ // src/sdk/sequences/index.ts
1058
+ class BentoSequences {
1059
+ _client;
1060
+ _url = "/fetch/sequences";
1061
+ constructor(_client) {
1062
+ this._client = _client;
1063
+ }
1064
+ async getSequences() {
1065
+ const result = await this._client.get(this._url);
1066
+ if (!result || Object.keys(result).length === 0)
1067
+ return [];
1068
+ return result.data ?? [];
1069
+ }
1070
+ }
1071
+ // src/sdk/subscribers/index.ts
1072
+ class BentoSubscribers {
1073
+ _client;
1074
+ _url = "/fetch/subscribers";
1075
+ constructor(_client) {
1076
+ this._client = _client;
1077
+ }
1078
+ async getSubscribers(parameters) {
1079
+ const result = await this._client.get(this._url, parameters);
1080
+ if (Object.keys(result).length === 0 || !result.data)
1081
+ return null;
1082
+ return result.data;
1083
+ }
1084
+ async createSubscriber(parameters) {
1085
+ const result = await this._client.post(this._url, {
1086
+ subscriber: parameters
1087
+ });
1088
+ if (Object.keys(result).length === 0 || !result.data)
1089
+ return null;
1090
+ return result.data;
1091
+ }
1092
+ }
1093
+ // src/sdk/tags/index.ts
1094
+ class BentoTags {
1095
+ _client;
1096
+ _url = "/fetch/tags";
1097
+ constructor(_client) {
1098
+ this._client = _client;
1099
+ }
1100
+ async getTags() {
1101
+ const result = await this._client.get(this._url);
1102
+ if (Object.keys(result).length === 0 || !result.data)
1103
+ return null;
1104
+ return result.data;
1105
+ }
1106
+ async createTag(parameters) {
1107
+ const result = await this._client.post(this._url, {
1108
+ tag: parameters
1109
+ });
1110
+ if (Object.keys(result).length === 0 || !result.data)
1111
+ return null;
1112
+ return result.data;
1113
+ }
1114
+ }
1115
+ // src/sdk/workflows/index.ts
1116
+ class BentoWorkflows {
1117
+ _client;
1118
+ _url = "/fetch/workflows";
1119
+ constructor(_client) {
1120
+ this._client = _client;
1121
+ }
1122
+ async getWorkflows() {
1123
+ const result = await this._client.get(this._url);
1124
+ if (!result || Object.keys(result).length === 0)
1125
+ return [];
1126
+ return result.data ?? [];
1127
+ }
1128
+ }
1129
+ // src/sdk/broadcasts/index.ts
1130
+ class BentoBroadcasts {
1131
+ _client;
1132
+ _fetchUrl = "/fetch/broadcasts";
1133
+ _batchUrl = "/batch/broadcasts";
1134
+ _emailsUrl = "/batch/emails";
1135
+ constructor(_client) {
1136
+ this._client = _client;
1137
+ }
1138
+ async createEmails(emails) {
1139
+ const result = await this._client.post(this._emailsUrl, {
1140
+ emails
1141
+ });
1142
+ return result.results;
1143
+ }
1144
+ async getBroadcasts() {
1145
+ const result = await this._client.get(this._fetchUrl);
1146
+ return result.data ?? [];
1147
+ }
1148
+ async createBroadcast(broadcasts) {
1149
+ const result = await this._client.post(this._batchUrl, {
1150
+ broadcasts
1151
+ });
1152
+ return result.data ?? [];
1153
+ }
1154
+ }
1155
+
1156
+ // src/sdk/stats/index.ts
1157
+ class BentoStats {
1158
+ _client;
1159
+ _url = "/stats";
1160
+ constructor(_client) {
1161
+ this._client = _client;
1162
+ }
1163
+ async getSiteStats() {
1164
+ const result = await this._client.get(`${this._url}/site`);
1165
+ return result;
1166
+ }
1167
+ async getSegmentStats(segmentId) {
1168
+ const result = await this._client.get(`${this._url}/segments/${segmentId}`);
1169
+ return result;
1170
+ }
1171
+ async getReportStats(reportId) {
1172
+ const result = await this._client.get(`${this._url}/reports/${reportId}`);
1173
+ return result;
1174
+ }
1175
+ }
1176
+
1177
+ // src/versions/v1/index.ts
1178
+ class BentoAPIV1 {
1179
+ _client;
1180
+ Broadcasts;
1181
+ EmailTemplates;
1182
+ Stats;
1183
+ Batch;
1184
+ Commands;
1185
+ Experimental;
1186
+ Fields;
1187
+ Forms;
1188
+ Sequences;
1189
+ Subscribers;
1190
+ Tags;
1191
+ Workflows;
1192
+ constructor(options) {
1193
+ this._client = new BentoClient(options);
1194
+ this.Broadcasts = new BentoBroadcasts(this._client);
1195
+ this.EmailTemplates = new BentoEmailTemplates(this._client);
1196
+ this.Stats = new BentoStats(this._client);
1197
+ this.Batch = new BentoBatch(this._client);
1198
+ this.Commands = new BentoCommands(this._client);
1199
+ this.Experimental = new BentoExperimental(this._client);
1200
+ this.Fields = new BentoFields(this._client);
1201
+ this.Forms = new BentoForms(this._client);
1202
+ this.Sequences = new BentoSequences(this._client);
1203
+ this.Subscribers = new BentoSubscribers(this._client);
1204
+ this.Tags = new BentoTags(this._client);
1205
+ this.Workflows = new BentoWorkflows(this._client);
1206
+ }
1207
+ async tagSubscriber(parameters) {
1208
+ const result = await this.Batch.importEvents({
1209
+ events: [
1210
+ {
1211
+ date: parameters.date,
1212
+ details: {
1213
+ tag: parameters.tagName
1214
+ },
1215
+ email: parameters.email,
1216
+ type: "$tag" /* TAG */
1217
+ }
1218
+ ]
1219
+ });
1220
+ return result === 1;
1221
+ }
1222
+ async addSubscriber(parameters) {
1223
+ const result = await this.Batch.importEvents({
1224
+ events: [
1225
+ {
1226
+ date: parameters.date,
1227
+ email: parameters.email,
1228
+ type: "$subscribe" /* SUBSCRIBE */,
1229
+ fields: parameters.fields || {}
1230
+ }
1231
+ ]
1232
+ });
1233
+ return result === 1;
1234
+ }
1235
+ async removeSubscriber(parameters) {
1236
+ const result = await this.Batch.importEvents({
1237
+ events: [
1238
+ {
1239
+ date: parameters.date,
1240
+ email: parameters.email,
1241
+ type: "$unsubscribe" /* UNSUBSCRIBE */
1242
+ }
1243
+ ]
1244
+ });
1245
+ return result === 1;
1246
+ }
1247
+ async updateFields(parameters) {
1248
+ const result = await this.Batch.importEvents({
1249
+ events: [
1250
+ {
1251
+ date: parameters.date,
1252
+ email: parameters.email,
1253
+ type: "$update_fields" /* UPDATE_FIELDS */,
1254
+ fields: parameters.fields
1255
+ }
1256
+ ]
1257
+ });
1258
+ return result === 1;
1259
+ }
1260
+ async trackPurchase(parameters) {
1261
+ const result = await this.Batch.importEvents({
1262
+ events: [
1263
+ {
1264
+ date: parameters.date,
1265
+ email: parameters.email,
1266
+ type: "$purchase" /* PURCHASE */,
1267
+ details: parameters.purchaseDetails
1268
+ }
1269
+ ]
1270
+ });
1271
+ return result === 1;
1272
+ }
1273
+ async track(parameters) {
1274
+ const result = await this.Batch.importEvents({
1275
+ events: [parameters]
1276
+ });
1277
+ return result === 1;
1278
+ }
1279
+ async upsertSubscriber(parameters) {
1280
+ await this.Batch.importSubscribers({
1281
+ subscribers: [
1282
+ {
1283
+ email: parameters.email,
1284
+ ...parameters.fields,
1285
+ ...parameters.tags && { tags: parameters.tags },
1286
+ ...parameters.remove_tags && { remove_tags: parameters.remove_tags }
1287
+ }
1288
+ ]
1289
+ });
1290
+ return this.Subscribers.getSubscribers({
1291
+ email: parameters.email
1292
+ });
1293
+ }
1294
+ }
1295
+
1296
+ // src/index.ts
1297
+ class Analytics {
1298
+ V1;
1299
+ constructor(options) {
1300
+ this.V1 = new BentoAPIV1(options);
1301
+ }
1302
+ }
1303
+ export {
1304
+ RequestTimeoutError,
1305
+ RateLimitedError,
1306
+ NotAuthorizedError,
1307
+ AuthorNotAuthorizedError,
1308
+ Analytics
1309
+ };