@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
@@ -1,2063 +0,0 @@
1
- import fetch from 'cross-fetch';
2
-
3
- function asyncGeneratorStep(n, t, e, r, o, a, c) {
4
- try {
5
- var i = n[a](c),
6
- u = i.value;
7
- } catch (n) {
8
- return void e(n);
9
- }
10
- i.done ? t(u) : Promise.resolve(u).then(r, o);
11
- }
12
- function _asyncToGenerator(n) {
13
- return function () {
14
- var t = this,
15
- e = arguments;
16
- return new Promise(function (r, o) {
17
- var a = n.apply(t, e);
18
- function _next(n) {
19
- asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
20
- }
21
- function _throw(n) {
22
- asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
23
- }
24
- _next(void 0);
25
- });
26
- };
27
- }
28
- function _construct(t, e, r) {
29
- if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
30
- var o = [null];
31
- o.push.apply(o, e);
32
- var p = new (t.bind.apply(t, o))();
33
- return r && _setPrototypeOf(p, r.prototype), p;
34
- }
35
- function _extends() {
36
- return _extends = Object.assign ? Object.assign.bind() : function (n) {
37
- for (var e = 1; e < arguments.length; e++) {
38
- var t = arguments[e];
39
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
40
- }
41
- return n;
42
- }, _extends.apply(null, arguments);
43
- }
44
- function _getPrototypeOf(t) {
45
- return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
46
- return t.__proto__ || Object.getPrototypeOf(t);
47
- }, _getPrototypeOf(t);
48
- }
49
- function _inheritsLoose(t, o) {
50
- t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
51
- }
52
- function _isNativeFunction(t) {
53
- try {
54
- return -1 !== Function.toString.call(t).indexOf("[native code]");
55
- } catch (n) {
56
- return "function" == typeof t;
57
- }
58
- }
59
- function _isNativeReflectConstruct() {
60
- try {
61
- var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
62
- } catch (t) {}
63
- return (_isNativeReflectConstruct = function () {
64
- return !!t;
65
- })();
66
- }
67
- function _regeneratorRuntime() {
68
- _regeneratorRuntime = function () {
69
- return e;
70
- };
71
- var t,
72
- e = {},
73
- r = Object.prototype,
74
- n = r.hasOwnProperty,
75
- o = Object.defineProperty || function (t, e, r) {
76
- t[e] = r.value;
77
- },
78
- i = "function" == typeof Symbol ? Symbol : {},
79
- a = i.iterator || "@@iterator",
80
- c = i.asyncIterator || "@@asyncIterator",
81
- u = i.toStringTag || "@@toStringTag";
82
- function define(t, e, r) {
83
- return Object.defineProperty(t, e, {
84
- value: r,
85
- enumerable: !0,
86
- configurable: !0,
87
- writable: !0
88
- }), t[e];
89
- }
90
- try {
91
- define({}, "");
92
- } catch (t) {
93
- define = function (t, e, r) {
94
- return t[e] = r;
95
- };
96
- }
97
- function wrap(t, e, r, n) {
98
- var i = e && e.prototype instanceof Generator ? e : Generator,
99
- a = Object.create(i.prototype),
100
- c = new Context(n || []);
101
- return o(a, "_invoke", {
102
- value: makeInvokeMethod(t, r, c)
103
- }), a;
104
- }
105
- function tryCatch(t, e, r) {
106
- try {
107
- return {
108
- type: "normal",
109
- arg: t.call(e, r)
110
- };
111
- } catch (t) {
112
- return {
113
- type: "throw",
114
- arg: t
115
- };
116
- }
117
- }
118
- e.wrap = wrap;
119
- var h = "suspendedStart",
120
- l = "suspendedYield",
121
- f = "executing",
122
- s = "completed",
123
- y = {};
124
- function Generator() {}
125
- function GeneratorFunction() {}
126
- function GeneratorFunctionPrototype() {}
127
- var p = {};
128
- define(p, a, function () {
129
- return this;
130
- });
131
- var d = Object.getPrototypeOf,
132
- v = d && d(d(values([])));
133
- v && v !== r && n.call(v, a) && (p = v);
134
- var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
135
- function defineIteratorMethods(t) {
136
- ["next", "throw", "return"].forEach(function (e) {
137
- define(t, e, function (t) {
138
- return this._invoke(e, t);
139
- });
140
- });
141
- }
142
- function AsyncIterator(t, e) {
143
- function invoke(r, o, i, a) {
144
- var c = tryCatch(t[r], t, o);
145
- if ("throw" !== c.type) {
146
- var u = c.arg,
147
- h = u.value;
148
- return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
149
- invoke("next", t, i, a);
150
- }, function (t) {
151
- invoke("throw", t, i, a);
152
- }) : e.resolve(h).then(function (t) {
153
- u.value = t, i(u);
154
- }, function (t) {
155
- return invoke("throw", t, i, a);
156
- });
157
- }
158
- a(c.arg);
159
- }
160
- var r;
161
- o(this, "_invoke", {
162
- value: function (t, n) {
163
- function callInvokeWithMethodAndArg() {
164
- return new e(function (e, r) {
165
- invoke(t, n, e, r);
166
- });
167
- }
168
- return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
169
- }
170
- });
171
- }
172
- function makeInvokeMethod(e, r, n) {
173
- var o = h;
174
- return function (i, a) {
175
- if (o === f) throw Error("Generator is already running");
176
- if (o === s) {
177
- if ("throw" === i) throw a;
178
- return {
179
- value: t,
180
- done: !0
181
- };
182
- }
183
- for (n.method = i, n.arg = a;;) {
184
- var c = n.delegate;
185
- if (c) {
186
- var u = maybeInvokeDelegate(c, n);
187
- if (u) {
188
- if (u === y) continue;
189
- return u;
190
- }
191
- }
192
- if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
193
- if (o === h) throw o = s, n.arg;
194
- n.dispatchException(n.arg);
195
- } else "return" === n.method && n.abrupt("return", n.arg);
196
- o = f;
197
- var p = tryCatch(e, r, n);
198
- if ("normal" === p.type) {
199
- if (o = n.done ? s : l, p.arg === y) continue;
200
- return {
201
- value: p.arg,
202
- done: n.done
203
- };
204
- }
205
- "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
206
- }
207
- };
208
- }
209
- function maybeInvokeDelegate(e, r) {
210
- var n = r.method,
211
- o = e.iterator[n];
212
- if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
213
- var i = tryCatch(o, e.iterator, r.arg);
214
- if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
215
- var a = i.arg;
216
- return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
217
- }
218
- function pushTryEntry(t) {
219
- var e = {
220
- tryLoc: t[0]
221
- };
222
- 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
223
- }
224
- function resetTryEntry(t) {
225
- var e = t.completion || {};
226
- e.type = "normal", delete e.arg, t.completion = e;
227
- }
228
- function Context(t) {
229
- this.tryEntries = [{
230
- tryLoc: "root"
231
- }], t.forEach(pushTryEntry, this), this.reset(!0);
232
- }
233
- function values(e) {
234
- if (e || "" === e) {
235
- var r = e[a];
236
- if (r) return r.call(e);
237
- if ("function" == typeof e.next) return e;
238
- if (!isNaN(e.length)) {
239
- var o = -1,
240
- i = function next() {
241
- for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
242
- return next.value = t, next.done = !0, next;
243
- };
244
- return i.next = i;
245
- }
246
- }
247
- throw new TypeError(typeof e + " is not iterable");
248
- }
249
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
250
- value: GeneratorFunctionPrototype,
251
- configurable: !0
252
- }), o(GeneratorFunctionPrototype, "constructor", {
253
- value: GeneratorFunction,
254
- configurable: !0
255
- }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
256
- var e = "function" == typeof t && t.constructor;
257
- return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
258
- }, e.mark = function (t) {
259
- return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
260
- }, e.awrap = function (t) {
261
- return {
262
- __await: t
263
- };
264
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
265
- return this;
266
- }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
267
- void 0 === i && (i = Promise);
268
- var a = new AsyncIterator(wrap(t, r, n, o), i);
269
- return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
270
- return t.done ? t.value : a.next();
271
- });
272
- }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
273
- return this;
274
- }), define(g, "toString", function () {
275
- return "[object Generator]";
276
- }), e.keys = function (t) {
277
- var e = Object(t),
278
- r = [];
279
- for (var n in e) r.push(n);
280
- return r.reverse(), function next() {
281
- for (; r.length;) {
282
- var t = r.pop();
283
- if (t in e) return next.value = t, next.done = !1, next;
284
- }
285
- return next.done = !0, next;
286
- };
287
- }, e.values = values, Context.prototype = {
288
- constructor: Context,
289
- reset: function (e) {
290
- if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
291
- },
292
- stop: function () {
293
- this.done = !0;
294
- var t = this.tryEntries[0].completion;
295
- if ("throw" === t.type) throw t.arg;
296
- return this.rval;
297
- },
298
- dispatchException: function (e) {
299
- if (this.done) throw e;
300
- var r = this;
301
- function handle(n, o) {
302
- return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
303
- }
304
- for (var o = this.tryEntries.length - 1; o >= 0; --o) {
305
- var i = this.tryEntries[o],
306
- a = i.completion;
307
- if ("root" === i.tryLoc) return handle("end");
308
- if (i.tryLoc <= this.prev) {
309
- var c = n.call(i, "catchLoc"),
310
- u = n.call(i, "finallyLoc");
311
- if (c && u) {
312
- if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
313
- if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
314
- } else if (c) {
315
- if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
316
- } else {
317
- if (!u) throw Error("try statement without catch or finally");
318
- if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
319
- }
320
- }
321
- }
322
- },
323
- abrupt: function (t, e) {
324
- for (var r = this.tryEntries.length - 1; r >= 0; --r) {
325
- var o = this.tryEntries[r];
326
- if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
327
- var i = o;
328
- break;
329
- }
330
- }
331
- i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
332
- var a = i ? i.completion : {};
333
- return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
334
- },
335
- complete: function (t, e) {
336
- if ("throw" === t.type) throw t.arg;
337
- return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
338
- },
339
- finish: function (t) {
340
- for (var e = this.tryEntries.length - 1; e >= 0; --e) {
341
- var r = this.tryEntries[e];
342
- if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
343
- }
344
- },
345
- catch: function (t) {
346
- for (var e = this.tryEntries.length - 1; e >= 0; --e) {
347
- var r = this.tryEntries[e];
348
- if (r.tryLoc === t) {
349
- var n = r.completion;
350
- if ("throw" === n.type) {
351
- var o = n.arg;
352
- resetTryEntry(r);
353
- }
354
- return o;
355
- }
356
- }
357
- throw Error("illegal catch attempt");
358
- },
359
- delegateYield: function (e, r, n) {
360
- return this.delegate = {
361
- iterator: values(e),
362
- resultName: r,
363
- nextLoc: n
364
- }, "next" === this.method && (this.arg = t), y;
365
- }
366
- }, e;
367
- }
368
- function _setPrototypeOf(t, e) {
369
- return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
370
- return t.__proto__ = e, t;
371
- }, _setPrototypeOf(t, e);
372
- }
373
- function _wrapNativeSuper(t) {
374
- var r = "function" == typeof Map ? new Map() : void 0;
375
- return _wrapNativeSuper = function (t) {
376
- if (null === t || !_isNativeFunction(t)) return t;
377
- if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
378
- if (void 0 !== r) {
379
- if (r.has(t)) return r.get(t);
380
- r.set(t, Wrapper);
381
- }
382
- function Wrapper() {
383
- return _construct(t, arguments, _getPrototypeOf(this).constructor);
384
- }
385
- return Wrapper.prototype = Object.create(t.prototype, {
386
- constructor: {
387
- value: Wrapper,
388
- enumerable: !1,
389
- writable: !0,
390
- configurable: !0
391
- }
392
- }), _setPrototypeOf(Wrapper, t);
393
- }, _wrapNativeSuper(t);
394
- }
395
-
396
- var TooFewSubscribersError = /*#__PURE__*/function (_Error) {
397
- function TooFewSubscribersError(message) {
398
- var _this;
399
- if (message === void 0) {
400
- message = 'Too few subscribers';
401
- }
402
- _this = _Error.call(this, message) || this;
403
- _this.name = 'TooFewSubscribersError';
404
- return _this;
405
- }
406
- _inheritsLoose(TooFewSubscribersError, _Error);
407
- return TooFewSubscribersError;
408
- }( /*#__PURE__*/_wrapNativeSuper(Error));
409
- var TooManySubscribersError = /*#__PURE__*/function (_Error2) {
410
- function TooManySubscribersError(message) {
411
- var _this2;
412
- if (message === void 0) {
413
- message = 'Too many subscribers';
414
- }
415
- _this2 = _Error2.call(this, message) || this;
416
- _this2.name = 'TooManySubscribersError';
417
- return _this2;
418
- }
419
- _inheritsLoose(TooManySubscribersError, _Error2);
420
- return TooManySubscribersError;
421
- }( /*#__PURE__*/_wrapNativeSuper(Error));
422
- var TooFewEventsError = /*#__PURE__*/function (_Error3) {
423
- function TooFewEventsError(message) {
424
- var _this3;
425
- if (message === void 0) {
426
- message = 'Too few events';
427
- }
428
- _this3 = _Error3.call(this, message) || this;
429
- _this3.name = 'TooFewEventsError';
430
- return _this3;
431
- }
432
- _inheritsLoose(TooFewEventsError, _Error3);
433
- return TooFewEventsError;
434
- }( /*#__PURE__*/_wrapNativeSuper(Error));
435
- var TooManyEventsError = /*#__PURE__*/function (_Error4) {
436
- function TooManyEventsError(message) {
437
- var _this4;
438
- if (message === void 0) {
439
- message = 'Too many events';
440
- }
441
- _this4 = _Error4.call(this, message) || this;
442
- _this4.name = 'TooManyEventsError';
443
- return _this4;
444
- }
445
- _inheritsLoose(TooManyEventsError, _Error4);
446
- return TooManyEventsError;
447
- }( /*#__PURE__*/_wrapNativeSuper(Error));
448
- var TooFewEmailsError = /*#__PURE__*/function (_Error5) {
449
- function TooFewEmailsError(message) {
450
- var _this5;
451
- if (message === void 0) {
452
- message = 'Too few emails';
453
- }
454
- _this5 = _Error5.call(this, message) || this;
455
- _this5.name = 'TooFewEmailsError';
456
- return _this5;
457
- }
458
- _inheritsLoose(TooFewEmailsError, _Error5);
459
- return TooFewEmailsError;
460
- }( /*#__PURE__*/_wrapNativeSuper(Error));
461
- var TooManyEmailsError = /*#__PURE__*/function (_Error6) {
462
- function TooManyEmailsError(message) {
463
- var _this6;
464
- if (message === void 0) {
465
- message = 'Too many emails';
466
- }
467
- _this6 = _Error6.call(this, message) || this;
468
- _this6.name = 'TooManyEmailsError';
469
- return _this6;
470
- }
471
- _inheritsLoose(TooManyEmailsError, _Error6);
472
- return TooManyEmailsError;
473
- }( /*#__PURE__*/_wrapNativeSuper(Error));
474
-
475
- var BentoBatch = /*#__PURE__*/function () {
476
- function BentoBatch(_client) {
477
- this._client = void 0;
478
- this._maxEmailBatchSize = 100;
479
- this._maxBatchSize = 1000;
480
- this._url = '/batch';
481
- this._client = _client;
482
- }
483
- /**
484
- * **This does not trigger automations!** - If you wish to trigger automations, please batch import
485
- * events with the type set to `BentoEvents.SUBSCRIBE`, or `$subscribe`. Note that the batch event import
486
- * cannot attach custom fields and will ignore everything except the email.
487
- *
488
- * Creates a batch job to import subscribers into the system. You can pass in
489
- * between 1 and 1,000 subscribers to import. Each subscriber must have an email,
490
- * and may optionally have any additional fields. The additional fields are added
491
- * as custom fields on the subscriber.
492
- *
493
- * This method is processed by the Bento import queues and it may take between 1 and
494
- * 5 minutes for the results to appear in your dashboard.
495
- *
496
- * Returns the number of subscribers that were imported.
497
- *
498
- * @param parameters
499
- * @returns Promise\<number\>
500
- */
501
- var _proto = BentoBatch.prototype;
502
- _proto.importSubscribers =
503
- /*#__PURE__*/
504
- function () {
505
- var _importSubscribers = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(parameters) {
506
- var result;
507
- return _regeneratorRuntime().wrap(function _callee$(_context) {
508
- while (1) switch (_context.prev = _context.next) {
509
- case 0:
510
- if (!(parameters.subscribers.length === 0)) {
511
- _context.next = 2;
512
- break;
513
- }
514
- throw new TooFewSubscribersError("You must send between 1 and 1,000 subscribers.");
515
- case 2:
516
- if (!(parameters.subscribers.length > this._maxBatchSize)) {
517
- _context.next = 4;
518
- break;
519
- }
520
- throw new TooManySubscribersError("You must send between 1 and 1,000 subscribers.");
521
- case 4:
522
- _context.next = 6;
523
- return this._client.post(this._url + "/subscribers", {
524
- subscribers: parameters.subscribers
525
- });
526
- case 6:
527
- result = _context.sent;
528
- return _context.abrupt("return", result.results);
529
- case 8:
530
- case "end":
531
- return _context.stop();
532
- }
533
- }, _callee, this);
534
- }));
535
- function importSubscribers(_x) {
536
- return _importSubscribers.apply(this, arguments);
537
- }
538
- return importSubscribers;
539
- }()
540
- /**
541
- * Creates a batch job to import events into the system. You can pass in
542
- * between 1 and 1,000 events to import. Each event must have an email and
543
- * a type. In addition to this, you my pass in additional data in the
544
- * `details` property.
545
- *
546
- * Returns the number of events that were imported.
547
- *
548
- * @param parameters
549
- * @returns Promise\<number\>
550
- */
551
- ;
552
- _proto.importEvents =
553
- /*#__PURE__*/
554
- function () {
555
- var _importEvents = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(parameters) {
556
- var result;
557
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
558
- while (1) switch (_context2.prev = _context2.next) {
559
- case 0:
560
- if (!(parameters.events.length === 0)) {
561
- _context2.next = 2;
562
- break;
563
- }
564
- throw new TooFewEventsError("You must send between 1 and 1,000 events.");
565
- case 2:
566
- if (!(parameters.events.length > this._maxBatchSize)) {
567
- _context2.next = 4;
568
- break;
569
- }
570
- throw new TooManyEventsError("You must send between 1 and 1,000 events.");
571
- case 4:
572
- _context2.next = 6;
573
- return this._client.post(this._url + "/events", {
574
- events: parameters.events
575
- });
576
- case 6:
577
- result = _context2.sent;
578
- return _context2.abrupt("return", result.results);
579
- case 8:
580
- case "end":
581
- return _context2.stop();
582
- }
583
- }, _callee2, this);
584
- }));
585
- function importEvents(_x2) {
586
- return _importEvents.apply(this, arguments);
587
- }
588
- return importEvents;
589
- }()
590
- /**
591
- * Creates a batch job to send transactional emails from Bento's infrastructure. You can pass in
592
- * between 1 and 100 emails to send.
593
- *
594
- * Each email must have a `to` address, a `from` address, a `subject`, an `html_body`
595
- * and `transactional: true`.
596
- * In addition you can add a `personalizations` object to provide
597
- * liquid tsags that will be injected into the email.
598
- *
599
- * Returns the number of events that were imported.
600
- *
601
- * @param parameters
602
- * @returns Promise\<number\>
603
- */
604
- ;
605
- _proto.sendTransactionalEmails =
606
- /*#__PURE__*/
607
- function () {
608
- var _sendTransactionalEmails = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(parameters) {
609
- var result;
610
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
611
- while (1) switch (_context3.prev = _context3.next) {
612
- case 0:
613
- if (!(parameters.emails.length === 0)) {
614
- _context3.next = 2;
615
- break;
616
- }
617
- throw new TooFewEmailsError("You must send between 1 and 100 emails.");
618
- case 2:
619
- if (!(parameters.emails.length > this._maxEmailBatchSize)) {
620
- _context3.next = 4;
621
- break;
622
- }
623
- throw new TooManyEmailsError("You must send between 1 and 100 emails.");
624
- case 4:
625
- _context3.next = 6;
626
- return this._client.post(this._url + "/emails", {
627
- emails: parameters.emails
628
- });
629
- case 6:
630
- result = _context3.sent;
631
- return _context3.abrupt("return", result.results);
632
- case 8:
633
- case "end":
634
- return _context3.stop();
635
- }
636
- }, _callee3, this);
637
- }));
638
- function sendTransactionalEmails(_x3) {
639
- return _sendTransactionalEmails.apply(this, arguments);
640
- }
641
- return sendTransactionalEmails;
642
- }();
643
- return BentoBatch;
644
- }();
645
-
646
- var NotAuthorizedError = /*#__PURE__*/function (_Error) {
647
- function NotAuthorizedError(message) {
648
- var _this;
649
- if (message === void 0) {
650
- message = 'Not authorized';
651
- }
652
- _this = _Error.call(this, message) || this;
653
- _this.name = 'NotAuthorizedError';
654
- return _this;
655
- }
656
- _inheritsLoose(NotAuthorizedError, _Error);
657
- return NotAuthorizedError;
658
- }( /*#__PURE__*/_wrapNativeSuper(Error));
659
- var RateLimitedError = /*#__PURE__*/function (_Error2) {
660
- function RateLimitedError(message) {
661
- var _this2;
662
- if (message === void 0) {
663
- message = 'You are being rate limited';
664
- }
665
- _this2 = _Error2.call(this, message) || this;
666
- _this2.name = 'RateLimitedError';
667
- return _this2;
668
- }
669
- _inheritsLoose(RateLimitedError, _Error2);
670
- return RateLimitedError;
671
- }( /*#__PURE__*/_wrapNativeSuper(Error));
672
-
673
- var BentoClient = /*#__PURE__*/function () {
674
- function BentoClient(options) {
675
- var _options$clientOption;
676
- this._headers = {};
677
- this._baseUrl = 'https://app.bentonow.com/api/v1';
678
- this._siteUuid = '';
679
- this._logErrors = false;
680
- this._baseUrl = ((_options$clientOption = options.clientOptions) == null ? void 0 : _options$clientOption.baseUrl) || this._baseUrl;
681
- this._siteUuid = options.siteUuid;
682
- this._headers = this._extractHeaders(options.authentication);
683
- this._logErrors = options.logErrors || false;
684
- }
685
- /**
686
- * Wraps a GET request to the Bento API and automatically adds the required
687
- * headers.
688
- *
689
- * @param endpoint string
690
- * @param payload object
691
- * @returns Promise\<T\>
692
- * */
693
- var _proto = BentoClient.prototype;
694
- _proto.get = function get(endpoint, payload) {
695
- var _this = this;
696
- if (payload === void 0) {
697
- payload = {};
698
- }
699
- return new Promise(function (resolve, reject) {
700
- var queryParameters = _this._getQueryParameters(payload);
701
- fetch("" + _this._baseUrl + endpoint + "?" + queryParameters, {
702
- method: 'GET',
703
- headers: _this._headers
704
- }).then( /*#__PURE__*/function () {
705
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(result) {
706
- return _regeneratorRuntime().wrap(function _callee$(_context) {
707
- while (1) switch (_context.prev = _context.next) {
708
- case 0:
709
- if (!_this._isSuccessfulStatus(result.status)) {
710
- _context.next = 2;
711
- break;
712
- }
713
- return _context.abrupt("return", result.json());
714
- case 2:
715
- _context.next = 4;
716
- return _this._getErrorForResponse(result);
717
- case 4:
718
- throw _context.sent;
719
- case 5:
720
- case "end":
721
- return _context.stop();
722
- }
723
- }, _callee);
724
- }));
725
- return function (_x) {
726
- return _ref.apply(this, arguments);
727
- };
728
- }()).then(function (data) {
729
- return resolve(data);
730
- })["catch"](function (error) {
731
- return reject(error);
732
- });
733
- });
734
- }
735
- /**
736
- * Wraps a POST request to the Bento API and automatically adds the required
737
- * headers.
738
- *
739
- * @param endpoint string
740
- * @param payload object
741
- * @returns Promise\<T\>
742
- * */;
743
- _proto.post = function post(endpoint, payload) {
744
- var _this2 = this;
745
- if (payload === void 0) {
746
- payload = {};
747
- }
748
- return new Promise(function (resolve, reject) {
749
- var body = _this2._getBody(payload);
750
- fetch("" + _this2._baseUrl + endpoint, {
751
- method: 'POST',
752
- headers: _extends({}, _this2._headers, {
753
- 'Content-Type': 'application/json'
754
- }),
755
- body: body
756
- }).then( /*#__PURE__*/function () {
757
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(result) {
758
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
759
- while (1) switch (_context2.prev = _context2.next) {
760
- case 0:
761
- if (!_this2._isSuccessfulStatus(result.status)) {
762
- _context2.next = 2;
763
- break;
764
- }
765
- return _context2.abrupt("return", result.json());
766
- case 2:
767
- _context2.next = 4;
768
- return _this2._getErrorForResponse(result);
769
- case 4:
770
- throw _context2.sent;
771
- case 5:
772
- case "end":
773
- return _context2.stop();
774
- }
775
- }, _callee2);
776
- }));
777
- return function (_x2) {
778
- return _ref2.apply(this, arguments);
779
- };
780
- }()).then(function (data) {
781
- return resolve(data);
782
- })["catch"](function (error) {
783
- return reject(error);
784
- });
785
- });
786
- }
787
- /**
788
- * Extracts the `publishableKey` and `secretKey` from the `authentication` options and
789
- * adds the `Authorization` header.
790
- *
791
- * @param authentication AuthenticationOptions
792
- * @returns HeadersInit
793
- */;
794
- _proto._extractHeaders = function _extractHeaders(authentication) {
795
- var authenticationKey = Buffer.from(authentication.publishableKey + ":" + authentication.secretKey).toString('base64');
796
- return {
797
- Authorization: "Basic " + authenticationKey
798
- };
799
- }
800
- /**
801
- * Takes the existing payload and adds the `site_uuid` to it, then returns
802
- * it out as a JSON string so that it can be sent alongside the request.
803
- *
804
- * @param payload object
805
- * @returns string
806
- */;
807
- _proto._getBody = function _getBody(payload) {
808
- return JSON.stringify(_extends({}, payload, {
809
- site_uuid: this._siteUuid
810
- }));
811
- }
812
- /**
813
- * Takes the existing payload and adds the `site_uuid` to it, converts the
814
- * object to a query string so that it can be sent alongside a GET request.
815
- *
816
- * @param payload object
817
- * @returns string
818
- */;
819
- _proto._getQueryParameters = function _getQueryParameters(payload) {
820
- var body = _extends({}, payload, {
821
- site_uuid: this._siteUuid
822
- });
823
- var queryParameters = new URLSearchParams();
824
- for (var _i = 0, _Object$entries = Object.entries(body); _i < _Object$entries.length; _i++) {
825
- var _Object$entries$_i = _Object$entries[_i],
826
- key = _Object$entries$_i[0],
827
- value = _Object$entries$_i[1];
828
- queryParameters.append(key, value);
829
- }
830
- return queryParameters.toString();
831
- }
832
- /**
833
- * Filters down the status codes to those that are considered a 'success'.
834
- *
835
- * @param statusCode number
836
- * @returns boolean
837
- */;
838
- _proto._isSuccessfulStatus = function _isSuccessfulStatus(statusCode) {
839
- var validStatusCodes = [200, 201];
840
- return validStatusCodes.includes(statusCode);
841
- }
842
- /**
843
- * Returns an appropriate error to be thrown given the received response.
844
- *
845
- * @param response Response
846
- * @returns Error
847
- */;
848
- _proto._getErrorForResponse =
849
- /*#__PURE__*/
850
- function () {
851
- var _getErrorForResponse2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(response) {
852
- var contentType, responseMessage;
853
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
854
- while (1) switch (_context3.prev = _context3.next) {
855
- case 0:
856
- if (this._logErrors) {
857
- console.error(response);
858
- }
859
- if (!(response.status === 401)) {
860
- _context3.next = 3;
861
- break;
862
- }
863
- return _context3.abrupt("return", new NotAuthorizedError());
864
- case 3:
865
- if (!(response.status === 429)) {
866
- _context3.next = 5;
867
- break;
868
- }
869
- return _context3.abrupt("return", new RateLimitedError());
870
- case 5:
871
- contentType = response.headers.get('Content-Type');
872
- responseMessage = '';
873
- _context3.t0 = contentType == null ? void 0 : contentType.toLocaleLowerCase();
874
- _context3.next = _context3.t0 === 'text/plain' ? 10 : _context3.t0 === 'application/json' ? 14 : 20;
875
- break;
876
- case 10:
877
- _context3.next = 12;
878
- return response.text();
879
- case 12:
880
- responseMessage = _context3.sent;
881
- return _context3.abrupt("break", 22);
882
- case 14:
883
- _context3.t1 = JSON;
884
- _context3.next = 17;
885
- return response.json();
886
- case 17:
887
- _context3.t2 = _context3.sent;
888
- responseMessage = _context3.t1.stringify.call(_context3.t1, _context3.t2);
889
- return _context3.abrupt("break", 22);
890
- case 20:
891
- responseMessage = 'Unknown response from the Bento API.';
892
- return _context3.abrupt("break", 22);
893
- case 22:
894
- return _context3.abrupt("return", new Error("[" + response.status + "] - " + responseMessage));
895
- case 23:
896
- case "end":
897
- return _context3.stop();
898
- }
899
- }, _callee3, this);
900
- }));
901
- function _getErrorForResponse(_x3) {
902
- return _getErrorForResponse2.apply(this, arguments);
903
- }
904
- return _getErrorForResponse;
905
- }();
906
- return BentoClient;
907
- }();
908
-
909
- /**
910
- * Command Enums
911
- */
912
- var CommandTypes;
913
- (function (CommandTypes) {
914
- CommandTypes["ADD_FIELD"] = "add_field";
915
- CommandTypes["ADD_TAG"] = "add_tag";
916
- CommandTypes["CHANGE_EMAIL"] = "change_email";
917
- CommandTypes["REMOVE_FIELD"] = "remove_field";
918
- CommandTypes["REMOVE_TAG"] = "remove_tag";
919
- CommandTypes["SUBSCRIBE"] = "subscribe";
920
- CommandTypes["UNSUBSCRIBE"] = "unsubscribe";
921
- })(CommandTypes || (CommandTypes = {}));
922
-
923
- var BentoCommands = /*#__PURE__*/function () {
924
- function BentoCommands(_client) {
925
- this._client = void 0;
926
- this._url = '/fetch/commands';
927
- this._client = _client;
928
- }
929
- /**
930
- * **This does not trigger automations!** - If you wish to trigger automations, please use the
931
- * core module's `tagSubscriber` method.
932
- *
933
- * Adds a tag to the subscriber with the matching email.
934
- *
935
- * Note that both the tag and the subscriber will be created if either is missing
936
- * from system.
937
- *
938
- *
939
- * @param parameters \{ email: string, tagName: string \}
940
- * @returns Promise\<Subscriber | null\>
941
- */
942
- var _proto = BentoCommands.prototype;
943
- _proto.addTag =
944
- /*#__PURE__*/
945
- function () {
946
- var _addTag = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(parameters) {
947
- var result;
948
- return _regeneratorRuntime().wrap(function _callee$(_context) {
949
- while (1) switch (_context.prev = _context.next) {
950
- case 0:
951
- _context.next = 2;
952
- return this._client.post(this._url, {
953
- command: {
954
- command: CommandTypes.ADD_TAG,
955
- email: parameters.email,
956
- query: parameters.tagName
957
- }
958
- });
959
- case 2:
960
- result = _context.sent;
961
- if (!(Object.keys(result).length === 0 || !result.data)) {
962
- _context.next = 5;
963
- break;
964
- }
965
- return _context.abrupt("return", null);
966
- case 5:
967
- return _context.abrupt("return", result.data);
968
- case 6:
969
- case "end":
970
- return _context.stop();
971
- }
972
- }, _callee, this);
973
- }));
974
- function addTag(_x) {
975
- return _addTag.apply(this, arguments);
976
- }
977
- return addTag;
978
- }()
979
- /**
980
- * Removes the specified tag from the subscriber with the matching email.
981
- *
982
- * @param parameters \{ email: string, tagName: string \}
983
- * @returns Promise\<Subscriber | null\>
984
- */
985
- ;
986
- _proto.removeTag =
987
- /*#__PURE__*/
988
- function () {
989
- var _removeTag = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(parameters) {
990
- var result;
991
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
992
- while (1) switch (_context2.prev = _context2.next) {
993
- case 0:
994
- _context2.next = 2;
995
- return this._client.post(this._url, {
996
- command: {
997
- command: CommandTypes.REMOVE_TAG,
998
- email: parameters.email,
999
- query: parameters.tagName
1000
- }
1001
- });
1002
- case 2:
1003
- result = _context2.sent;
1004
- if (!(Object.keys(result).length === 0 || !result.data)) {
1005
- _context2.next = 5;
1006
- break;
1007
- }
1008
- return _context2.abrupt("return", null);
1009
- case 5:
1010
- return _context2.abrupt("return", result.data);
1011
- case 6:
1012
- case "end":
1013
- return _context2.stop();
1014
- }
1015
- }, _callee2, this);
1016
- }));
1017
- function removeTag(_x2) {
1018
- return _removeTag.apply(this, arguments);
1019
- }
1020
- return removeTag;
1021
- }()
1022
- /**
1023
- * **This does not trigger automations!** - If you wish to trigger automations, please use the
1024
- * core module's `updateFields` method.
1025
- *
1026
- * Adds a field to the subscriber with the matching email.
1027
- *
1028
- * Note that both the field and the subscriber will be created if either is missing
1029
- * from system.
1030
- *
1031
- * @param parameters \{ email: string, field: \{ key: string; value: string; \} \}
1032
- * @returns Promise\<Subscriber | null\>
1033
- */
1034
- ;
1035
- _proto.addField =
1036
- /*#__PURE__*/
1037
- function () {
1038
- var _addField = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(parameters) {
1039
- var result;
1040
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1041
- while (1) switch (_context3.prev = _context3.next) {
1042
- case 0:
1043
- _context3.next = 2;
1044
- return this._client.post(this._url, {
1045
- command: {
1046
- command: CommandTypes.ADD_FIELD,
1047
- email: parameters.email,
1048
- query: parameters.field
1049
- }
1050
- });
1051
- case 2:
1052
- result = _context3.sent;
1053
- if (!(Object.keys(result).length === 0 || !result.data)) {
1054
- _context3.next = 5;
1055
- break;
1056
- }
1057
- return _context3.abrupt("return", null);
1058
- case 5:
1059
- return _context3.abrupt("return", result.data);
1060
- case 6:
1061
- case "end":
1062
- return _context3.stop();
1063
- }
1064
- }, _callee3, this);
1065
- }));
1066
- function addField(_x3) {
1067
- return _addField.apply(this, arguments);
1068
- }
1069
- return addField;
1070
- }()
1071
- /**
1072
- * Removes a field to the subscriber with the matching email.
1073
- *
1074
- * @param parameters \{ email: string, fieldName: string \}
1075
- * @returns Promise\<Subscriber | null\>
1076
- */
1077
- ;
1078
- _proto.removeField =
1079
- /*#__PURE__*/
1080
- function () {
1081
- var _removeField = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(parameters) {
1082
- var result;
1083
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
1084
- while (1) switch (_context4.prev = _context4.next) {
1085
- case 0:
1086
- _context4.next = 2;
1087
- return this._client.post(this._url, {
1088
- command: {
1089
- command: CommandTypes.REMOVE_FIELD,
1090
- email: parameters.email,
1091
- query: parameters.fieldName
1092
- }
1093
- });
1094
- case 2:
1095
- result = _context4.sent;
1096
- if (!(Object.keys(result).length === 0 || !result.data)) {
1097
- _context4.next = 5;
1098
- break;
1099
- }
1100
- return _context4.abrupt("return", null);
1101
- case 5:
1102
- return _context4.abrupt("return", result.data);
1103
- case 6:
1104
- case "end":
1105
- return _context4.stop();
1106
- }
1107
- }, _callee4, this);
1108
- }));
1109
- function removeField(_x4) {
1110
- return _removeField.apply(this, arguments);
1111
- }
1112
- return removeField;
1113
- }()
1114
- /**
1115
- * **This does not trigger automations!** - If you wish to trigger automations, please use the
1116
- * core module's `addSubscriber` method.
1117
- *
1118
- * Subscribes the supplied email to Bento. If the email does not exist, it is created.
1119
- * If the subscriber had previously unsubscribed, they will be re-subscribed.
1120
- *
1121
- * @param parameters \{ email: string \}
1122
- * @returns Promise\<Subscriber | null\>
1123
- */
1124
- ;
1125
- _proto.subscribe =
1126
- /*#__PURE__*/
1127
- function () {
1128
- var _subscribe = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(parameters) {
1129
- var result;
1130
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
1131
- while (1) switch (_context5.prev = _context5.next) {
1132
- case 0:
1133
- _context5.next = 2;
1134
- return this._client.post(this._url, {
1135
- command: {
1136
- command: CommandTypes.SUBSCRIBE,
1137
- email: parameters.email
1138
- }
1139
- });
1140
- case 2:
1141
- result = _context5.sent;
1142
- if (!(Object.keys(result).length === 0 || !result.data)) {
1143
- _context5.next = 5;
1144
- break;
1145
- }
1146
- return _context5.abrupt("return", null);
1147
- case 5:
1148
- return _context5.abrupt("return", result.data);
1149
- case 6:
1150
- case "end":
1151
- return _context5.stop();
1152
- }
1153
- }, _callee5, this);
1154
- }));
1155
- function subscribe(_x5) {
1156
- return _subscribe.apply(this, arguments);
1157
- }
1158
- return subscribe;
1159
- }()
1160
- /**
1161
- * **This does not trigger automations!** - If you wish to trigger automations, please use the
1162
- * core module's `removeSubscriber` method.
1163
- *
1164
- * Unsubscribes the supplied email to Bento. If the email does not exist, it is created and
1165
- * immediately unsubscribed. If they had already unsubscribed, the `unsubscribed_at` property
1166
- * is updated.
1167
- *
1168
- * @param parameters \{ email: string \}
1169
- * @returns Promise\<Subscriber | null\>
1170
- */
1171
- ;
1172
- _proto.unsubscribe =
1173
- /*#__PURE__*/
1174
- function () {
1175
- var _unsubscribe = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(parameters) {
1176
- var result;
1177
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
1178
- while (1) switch (_context6.prev = _context6.next) {
1179
- case 0:
1180
- _context6.next = 2;
1181
- return this._client.post(this._url, {
1182
- command: {
1183
- command: CommandTypes.UNSUBSCRIBE,
1184
- email: parameters.email
1185
- }
1186
- });
1187
- case 2:
1188
- result = _context6.sent;
1189
- if (!(Object.keys(result).length === 0 || !result.data)) {
1190
- _context6.next = 5;
1191
- break;
1192
- }
1193
- return _context6.abrupt("return", null);
1194
- case 5:
1195
- return _context6.abrupt("return", result.data);
1196
- case 6:
1197
- case "end":
1198
- return _context6.stop();
1199
- }
1200
- }, _callee6, this);
1201
- }));
1202
- function unsubscribe(_x6) {
1203
- return _unsubscribe.apply(this, arguments);
1204
- }
1205
- return unsubscribe;
1206
- }()
1207
- /**
1208
- * Updates the email of a user in Bento.
1209
- *
1210
- * @param parameters \{ oldEmail: string, newEmail: string \}
1211
- * @returns Promise\<Subscriber | null\>
1212
- */
1213
- ;
1214
- _proto.changeEmail =
1215
- /*#__PURE__*/
1216
- function () {
1217
- var _changeEmail = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(parameters) {
1218
- var result;
1219
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
1220
- while (1) switch (_context7.prev = _context7.next) {
1221
- case 0:
1222
- _context7.next = 2;
1223
- return this._client.post(this._url, {
1224
- command: {
1225
- command: CommandTypes.CHANGE_EMAIL,
1226
- email: parameters.oldEmail,
1227
- query: parameters.newEmail
1228
- }
1229
- });
1230
- case 2:
1231
- result = _context7.sent;
1232
- if (!(Object.keys(result).length === 0 || !result.data)) {
1233
- _context7.next = 5;
1234
- break;
1235
- }
1236
- return _context7.abrupt("return", null);
1237
- case 5:
1238
- return _context7.abrupt("return", result.data);
1239
- case 6:
1240
- case "end":
1241
- return _context7.stop();
1242
- }
1243
- }, _callee7, this);
1244
- }));
1245
- function changeEmail(_x7) {
1246
- return _changeEmail.apply(this, arguments);
1247
- }
1248
- return changeEmail;
1249
- }();
1250
- return BentoCommands;
1251
- }();
1252
-
1253
- var BentoExperimental = /*#__PURE__*/function () {
1254
- function BentoExperimental(_client) {
1255
- this._client = void 0;
1256
- this._url = '/experimental';
1257
- this._client = _client;
1258
- }
1259
- /**
1260
- * **EXPERIMENTAL** -
1261
- * This functionality is experimental and may change or stop working at any time.
1262
- *
1263
- * Attempts to validate the email. You can provide additional information to further
1264
- * refine the validation.
1265
- *
1266
- * If a name is provided, it compares it against the US Census Data, and so the results
1267
- * may be biased.
1268
- *
1269
- * @param parameters
1270
- * @returns Promise\<boolean\>
1271
- */
1272
- var _proto = BentoExperimental.prototype;
1273
- _proto.validateEmail =
1274
- /*#__PURE__*/
1275
- function () {
1276
- var _validateEmail = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(parameters) {
1277
- var result;
1278
- return _regeneratorRuntime().wrap(function _callee$(_context) {
1279
- while (1) switch (_context.prev = _context.next) {
1280
- case 0:
1281
- _context.next = 2;
1282
- return this._client.post(this._url + "/validation", {
1283
- email: parameters.email,
1284
- ip: parameters.ip,
1285
- name: parameters.name,
1286
- user_agent: parameters.userAgent
1287
- });
1288
- case 2:
1289
- result = _context.sent;
1290
- return _context.abrupt("return", result.valid);
1291
- case 4:
1292
- case "end":
1293
- return _context.stop();
1294
- }
1295
- }, _callee, this);
1296
- }));
1297
- function validateEmail(_x) {
1298
- return _validateEmail.apply(this, arguments);
1299
- }
1300
- return validateEmail;
1301
- }()
1302
- /**
1303
- * **EXPERIMENTAL** -
1304
- * This functionality is experimental and may change or stop working at any time.
1305
- *
1306
- * Attempts to guess the gender of the person given a provided name. It compares
1307
- * the name against the US Census Data, and so the results may be biased.
1308
- *
1309
- * It is possible for the gender to be unknown if the system cannot confidently
1310
- * conclude what gender it may be.
1311
- *
1312
- * @param parameters
1313
- * @returns Promise\<GuessGenderResponse\>
1314
- */
1315
- ;
1316
- _proto.guessGender =
1317
- /*#__PURE__*/
1318
- function () {
1319
- var _guessGender = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(parameters) {
1320
- var result;
1321
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1322
- while (1) switch (_context2.prev = _context2.next) {
1323
- case 0:
1324
- _context2.next = 2;
1325
- return this._client.post(this._url + "/gender", parameters);
1326
- case 2:
1327
- result = _context2.sent;
1328
- return _context2.abrupt("return", result);
1329
- case 4:
1330
- case "end":
1331
- return _context2.stop();
1332
- }
1333
- }, _callee2, this);
1334
- }));
1335
- function guessGender(_x2) {
1336
- return _guessGender.apply(this, arguments);
1337
- }
1338
- return guessGender;
1339
- }()
1340
- /**
1341
- * **EXPERIMENTAL** -
1342
- * This functionality is experimental and may change or stop working at any time.
1343
- *
1344
- * Attempts to provide location data given a provided IP address.
1345
- *
1346
- * @param parameters
1347
- * @returns Promise\<GeolocateResponse\>
1348
- */
1349
- ;
1350
- _proto.geolocate =
1351
- /*#__PURE__*/
1352
- function () {
1353
- var _geolocate = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(parameters) {
1354
- var result;
1355
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1356
- while (1) switch (_context3.prev = _context3.next) {
1357
- case 0:
1358
- _context3.next = 2;
1359
- return this._client.get(this._url + "/geolocation", parameters);
1360
- case 2:
1361
- result = _context3.sent;
1362
- if (!(Object.keys(result).length === 0)) {
1363
- _context3.next = 5;
1364
- break;
1365
- }
1366
- return _context3.abrupt("return", null);
1367
- case 5:
1368
- return _context3.abrupt("return", result);
1369
- case 6:
1370
- case "end":
1371
- return _context3.stop();
1372
- }
1373
- }, _callee3, this);
1374
- }));
1375
- function geolocate(_x3) {
1376
- return _geolocate.apply(this, arguments);
1377
- }
1378
- return geolocate;
1379
- }()
1380
- /**
1381
- * **EXPERIMENTAL** -
1382
- * This functionality is experimental and may change or stop working at any time.
1383
- *
1384
- * Looks up the provided URL or IP Address against various blacklists to see if the site has been
1385
- * blacklisted anywhere.
1386
- *
1387
- * @param parameters
1388
- * @returns Promise\<BlacklistResponse\>
1389
- */
1390
- ;
1391
- _proto.checkBlacklist =
1392
- /*#__PURE__*/
1393
- function () {
1394
- var _checkBlacklist = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(parameters) {
1395
- var result;
1396
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
1397
- while (1) switch (_context4.prev = _context4.next) {
1398
- case 0:
1399
- _context4.next = 2;
1400
- return this._client.get(this._url + "/blacklist.json", parameters);
1401
- case 2:
1402
- result = _context4.sent;
1403
- return _context4.abrupt("return", result);
1404
- case 4:
1405
- case "end":
1406
- return _context4.stop();
1407
- }
1408
- }, _callee4, this);
1409
- }));
1410
- function checkBlacklist(_x4) {
1411
- return _checkBlacklist.apply(this, arguments);
1412
- }
1413
- return checkBlacklist;
1414
- }();
1415
- return BentoExperimental;
1416
- }();
1417
-
1418
- var BentoFields = /*#__PURE__*/function () {
1419
- function BentoFields(_client) {
1420
- this._client = void 0;
1421
- this._url = '/fetch/fields';
1422
- this._client = _client;
1423
- }
1424
- /**
1425
- * Returns all of the fields for the site.
1426
- *
1427
- * @returns Promise<Field[]>
1428
- */
1429
- var _proto = BentoFields.prototype;
1430
- _proto.getFields =
1431
- /*#__PURE__*/
1432
- function () {
1433
- var _getFields = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1434
- var result;
1435
- return _regeneratorRuntime().wrap(function _callee$(_context) {
1436
- while (1) switch (_context.prev = _context.next) {
1437
- case 0:
1438
- _context.next = 2;
1439
- return this._client.get(this._url);
1440
- case 2:
1441
- result = _context.sent;
1442
- if (!(Object.keys(result).length === 0 || !result.data)) {
1443
- _context.next = 5;
1444
- break;
1445
- }
1446
- return _context.abrupt("return", null);
1447
- case 5:
1448
- return _context.abrupt("return", result.data);
1449
- case 6:
1450
- case "end":
1451
- return _context.stop();
1452
- }
1453
- }, _callee, this);
1454
- }));
1455
- function getFields() {
1456
- return _getFields.apply(this, arguments);
1457
- }
1458
- return getFields;
1459
- }()
1460
- /**
1461
- * Creates a field inside of Bento. The name of the field is automatically generated
1462
- * from the key that is passed in upon creation. For example
1463
- * - Key: `thisIsAKey`
1464
- * Name: `This Is A Key`
1465
- * - Key: `this is a key`
1466
- * Name: `This Is A Key`
1467
- * - Key: `this-is-a-key`
1468
- * Name: `This Is A Key`
1469
- * - Key: `this_is_a_key`
1470
- * Name: `This Is A Key`
1471
- *
1472
- * @param parameters \{ key: string \}
1473
- * @returns Promise<Field[]>
1474
- */
1475
- ;
1476
- _proto.createField =
1477
- /*#__PURE__*/
1478
- function () {
1479
- var _createField = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(parameters) {
1480
- var result;
1481
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1482
- while (1) switch (_context2.prev = _context2.next) {
1483
- case 0:
1484
- _context2.next = 2;
1485
- return this._client.post(this._url, {
1486
- field: parameters
1487
- });
1488
- case 2:
1489
- result = _context2.sent;
1490
- if (!(Object.keys(result).length === 0 || !result.data)) {
1491
- _context2.next = 5;
1492
- break;
1493
- }
1494
- return _context2.abrupt("return", null);
1495
- case 5:
1496
- return _context2.abrupt("return", result.data);
1497
- case 6:
1498
- case "end":
1499
- return _context2.stop();
1500
- }
1501
- }, _callee2, this);
1502
- }));
1503
- function createField(_x) {
1504
- return _createField.apply(this, arguments);
1505
- }
1506
- return createField;
1507
- }();
1508
- return BentoFields;
1509
- }();
1510
-
1511
- var BentoForms = /*#__PURE__*/function () {
1512
- function BentoForms(_client) {
1513
- this._client = void 0;
1514
- this._url = '/fetch/responses';
1515
- this._client = _client;
1516
- }
1517
- /**
1518
- * Returns all of the responses for the form with the specified identifier.
1519
- *
1520
- * @param formIdentifier string
1521
- * @returns Promise\<FormResponse[] | null\>
1522
- */
1523
- var _proto = BentoForms.prototype;
1524
- _proto.getResponses =
1525
- /*#__PURE__*/
1526
- function () {
1527
- var _getResponses = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(formIdentifier) {
1528
- var result;
1529
- return _regeneratorRuntime().wrap(function _callee$(_context) {
1530
- while (1) switch (_context.prev = _context.next) {
1531
- case 0:
1532
- _context.next = 2;
1533
- return this._client.get(this._url, {
1534
- id: formIdentifier
1535
- });
1536
- case 2:
1537
- result = _context.sent;
1538
- if (!(Object.keys(result).length === 0 || !result.data)) {
1539
- _context.next = 5;
1540
- break;
1541
- }
1542
- return _context.abrupt("return", null);
1543
- case 5:
1544
- return _context.abrupt("return", result.data);
1545
- case 6:
1546
- case "end":
1547
- return _context.stop();
1548
- }
1549
- }, _callee, this);
1550
- }));
1551
- function getResponses(_x) {
1552
- return _getResponses.apply(this, arguments);
1553
- }
1554
- return getResponses;
1555
- }();
1556
- return BentoForms;
1557
- }();
1558
-
1559
- var BentoSubscribers = /*#__PURE__*/function () {
1560
- function BentoSubscribers(_client) {
1561
- this._client = void 0;
1562
- this._url = '/fetch/subscribers';
1563
- this._client = _client;
1564
- }
1565
- /**
1566
- * Returns the subscriber with the specified email or UUID.
1567
- *
1568
- * @returns Promise\<Subscriber\<S\> | null\>
1569
- */
1570
- var _proto = BentoSubscribers.prototype;
1571
- _proto.getSubscribers =
1572
- /*#__PURE__*/
1573
- function () {
1574
- var _getSubscribers = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(parameters) {
1575
- var result;
1576
- return _regeneratorRuntime().wrap(function _callee$(_context) {
1577
- while (1) switch (_context.prev = _context.next) {
1578
- case 0:
1579
- _context.next = 2;
1580
- return this._client.get(this._url, parameters);
1581
- case 2:
1582
- result = _context.sent;
1583
- if (!(Object.keys(result).length === 0 || !result.data)) {
1584
- _context.next = 5;
1585
- break;
1586
- }
1587
- return _context.abrupt("return", null);
1588
- case 5:
1589
- return _context.abrupt("return", result.data);
1590
- case 6:
1591
- case "end":
1592
- return _context.stop();
1593
- }
1594
- }, _callee, this);
1595
- }));
1596
- function getSubscribers(_x) {
1597
- return _getSubscribers.apply(this, arguments);
1598
- }
1599
- return getSubscribers;
1600
- }()
1601
- /**
1602
- * Creates a subscriber inside of Bento.
1603
- *
1604
- * @param parameters CreateSubscriberParameters
1605
- * @returns Promise\<Subscriber\<S\> | null\>
1606
- */
1607
- ;
1608
- _proto.createSubscriber =
1609
- /*#__PURE__*/
1610
- function () {
1611
- var _createSubscriber = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(parameters) {
1612
- var result;
1613
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1614
- while (1) switch (_context2.prev = _context2.next) {
1615
- case 0:
1616
- _context2.next = 2;
1617
- return this._client.post(this._url, {
1618
- subscriber: parameters
1619
- });
1620
- case 2:
1621
- result = _context2.sent;
1622
- if (!(Object.keys(result).length === 0 || !result.data)) {
1623
- _context2.next = 5;
1624
- break;
1625
- }
1626
- return _context2.abrupt("return", null);
1627
- case 5:
1628
- return _context2.abrupt("return", result.data);
1629
- case 6:
1630
- case "end":
1631
- return _context2.stop();
1632
- }
1633
- }, _callee2, this);
1634
- }));
1635
- function createSubscriber(_x2) {
1636
- return _createSubscriber.apply(this, arguments);
1637
- }
1638
- return createSubscriber;
1639
- }();
1640
- return BentoSubscribers;
1641
- }();
1642
-
1643
- var BentoTags = /*#__PURE__*/function () {
1644
- function BentoTags(_client) {
1645
- this._client = void 0;
1646
- this._url = '/fetch/tags';
1647
- this._client = _client;
1648
- }
1649
- /**
1650
- * Returns all of the fields for the site.
1651
- *
1652
- * @returns Promise\<Tag[] | null\>
1653
- */
1654
- var _proto = BentoTags.prototype;
1655
- _proto.getTags =
1656
- /*#__PURE__*/
1657
- function () {
1658
- var _getTags = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1659
- var result;
1660
- return _regeneratorRuntime().wrap(function _callee$(_context) {
1661
- while (1) switch (_context.prev = _context.next) {
1662
- case 0:
1663
- _context.next = 2;
1664
- return this._client.get(this._url);
1665
- case 2:
1666
- result = _context.sent;
1667
- if (!(Object.keys(result).length === 0 || !result.data)) {
1668
- _context.next = 5;
1669
- break;
1670
- }
1671
- return _context.abrupt("return", null);
1672
- case 5:
1673
- return _context.abrupt("return", result.data);
1674
- case 6:
1675
- case "end":
1676
- return _context.stop();
1677
- }
1678
- }, _callee, this);
1679
- }));
1680
- function getTags() {
1681
- return _getTags.apply(this, arguments);
1682
- }
1683
- return getTags;
1684
- }()
1685
- /**
1686
- * Creates a tag inside of Bento.
1687
- *
1688
- * @param parameters CreateTagParameters
1689
- * @returns Promise\<Tag[] | null\>
1690
- */
1691
- ;
1692
- _proto.createTag =
1693
- /*#__PURE__*/
1694
- function () {
1695
- var _createTag = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(parameters) {
1696
- var result;
1697
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1698
- while (1) switch (_context2.prev = _context2.next) {
1699
- case 0:
1700
- _context2.next = 2;
1701
- return this._client.post(this._url, {
1702
- tag: parameters
1703
- });
1704
- case 2:
1705
- result = _context2.sent;
1706
- if (!(Object.keys(result).length === 0 || !result.data)) {
1707
- _context2.next = 5;
1708
- break;
1709
- }
1710
- return _context2.abrupt("return", null);
1711
- case 5:
1712
- return _context2.abrupt("return", result.data);
1713
- case 6:
1714
- case "end":
1715
- return _context2.stop();
1716
- }
1717
- }, _callee2, this);
1718
- }));
1719
- function createTag(_x) {
1720
- return _createTag.apply(this, arguments);
1721
- }
1722
- return createTag;
1723
- }();
1724
- return BentoTags;
1725
- }();
1726
-
1727
- var BentoEvents;
1728
- (function (BentoEvents) {
1729
- BentoEvents["PURCHASE"] = "$purchase";
1730
- BentoEvents["SUBSCRIBE"] = "$subscribe";
1731
- BentoEvents["TAG"] = "$tag";
1732
- BentoEvents["REMOVE_TAG"] = "$remove_tag";
1733
- BentoEvents["UNSUBSCRIBE"] = "$unsubscribe";
1734
- BentoEvents["UPDATE_FIELDS"] = "$update_fields";
1735
- })(BentoEvents || (BentoEvents = {}));
1736
-
1737
- var BentoAPIV1 = /*#__PURE__*/function () {
1738
- function BentoAPIV1(options) {
1739
- this._client = void 0;
1740
- this.Batch = void 0;
1741
- this.Commands = void 0;
1742
- this.Experimental = void 0;
1743
- this.Fields = void 0;
1744
- this.Forms = void 0;
1745
- this.Subscribers = void 0;
1746
- this.Tags = void 0;
1747
- this._client = new BentoClient(options);
1748
- this.Batch = new BentoBatch(this._client);
1749
- this.Commands = new BentoCommands(this._client);
1750
- this.Experimental = new BentoExperimental(this._client);
1751
- this.Fields = new BentoFields(this._client);
1752
- this.Forms = new BentoForms(this._client);
1753
- this.Subscribers = new BentoSubscribers(this._client);
1754
- this.Tags = new BentoTags(this._client);
1755
- }
1756
- /**
1757
- * **This TRIGGERS automations!** - If you do not wish to trigger automations, please use the
1758
- * `Commands.addTag` method.
1759
- *
1760
- * Tags a subscriber with the specified email and tag. If either the tag or the user
1761
- * do not exist, they will be created in the system. If the user already has the tag,
1762
- * another tag event will be sent, triggering any automations that take place upon a
1763
- * tag being added to a subscriber. Please be aware of the potential consequences.
1764
- *
1765
- * Because this method uses the batch API, the tag may take between 1 and 3 minutes
1766
- * to appear in the system.
1767
- *
1768
- * Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
1769
- *
1770
- * @param parameters TagSubscriberParameters
1771
- * @returns Promise\<boolean\>
1772
- */
1773
- var _proto = BentoAPIV1.prototype;
1774
- _proto.tagSubscriber =
1775
- /*#__PURE__*/
1776
- function () {
1777
- var _tagSubscriber = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(parameters) {
1778
- var result;
1779
- return _regeneratorRuntime().wrap(function _callee$(_context) {
1780
- while (1) switch (_context.prev = _context.next) {
1781
- case 0:
1782
- _context.next = 2;
1783
- return this.Batch.importEvents({
1784
- events: [{
1785
- date: parameters.date,
1786
- details: {
1787
- tag: parameters.tagName
1788
- },
1789
- email: parameters.email,
1790
- type: BentoEvents.TAG
1791
- }]
1792
- });
1793
- case 2:
1794
- result = _context.sent;
1795
- return _context.abrupt("return", result === 1);
1796
- case 4:
1797
- case "end":
1798
- return _context.stop();
1799
- }
1800
- }, _callee, this);
1801
- }));
1802
- function tagSubscriber(_x) {
1803
- return _tagSubscriber.apply(this, arguments);
1804
- }
1805
- return tagSubscriber;
1806
- }()
1807
- /**
1808
- * **This TRIGGERS automations!** - If you do not wish to trigger automations, please use the
1809
- * `Commands.subscribe` method.
1810
- *
1811
- * Creates a subscriber in the system. If the subscriber already exists, another subscribe event
1812
- * will be sent, triggering any automations that take place upon subscription. Please be aware
1813
- * of the potential consequences.
1814
- *
1815
- * You may optionally pass any fields that you wish to be set on the subscriber during creation
1816
- * as well as a `Date` which will backdate the event. If no date is supplied, then the event will
1817
- * default to the current time.
1818
- *
1819
- * Because this method uses the batch API, the tag may take between 1 and 3 minutes
1820
- * to appear in the system.
1821
- *
1822
- * Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
1823
- *
1824
- * @param parameters AddSubscriberParameters
1825
- * @returns Promise\<boolean\>
1826
- */
1827
- ;
1828
- _proto.addSubscriber =
1829
- /*#__PURE__*/
1830
- function () {
1831
- var _addSubscriber = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(parameters) {
1832
- var result;
1833
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1834
- while (1) switch (_context2.prev = _context2.next) {
1835
- case 0:
1836
- _context2.next = 2;
1837
- return this.Batch.importEvents({
1838
- events: [{
1839
- date: parameters.date,
1840
- email: parameters.email,
1841
- type: BentoEvents.SUBSCRIBE,
1842
- fields: parameters.fields || {}
1843
- }]
1844
- });
1845
- case 2:
1846
- result = _context2.sent;
1847
- return _context2.abrupt("return", result === 1);
1848
- case 4:
1849
- case "end":
1850
- return _context2.stop();
1851
- }
1852
- }, _callee2, this);
1853
- }));
1854
- function addSubscriber(_x2) {
1855
- return _addSubscriber.apply(this, arguments);
1856
- }
1857
- return addSubscriber;
1858
- }()
1859
- /**
1860
- * **This TRIGGERS automations!** - If you do not wish to trigger automations, please use the
1861
- * `Commands.unsubscribe` method.
1862
- *
1863
- * Unsubscribes an email in the system. If the email is already unsubscribed, another unsubscribe event
1864
- * will be sent, triggering any automations that take place upon an unsubscribe happening. Please be aware
1865
- * of the potential consequences.
1866
- *
1867
- * You may optionally pass a `Date` which will backdate the event. If no date is supplied, then the event
1868
- * will default to the current time.
1869
- *
1870
- * Because this method uses the batch API, the tag may take between 1 and 3 minutes
1871
- * to appear in the system.
1872
- *
1873
- * Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
1874
- *
1875
- * @param parameters RemoveSubscriberParameters
1876
- * @returns Promise\<boolean\>
1877
- */
1878
- ;
1879
- _proto.removeSubscriber =
1880
- /*#__PURE__*/
1881
- function () {
1882
- var _removeSubscriber = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(parameters) {
1883
- var result;
1884
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1885
- while (1) switch (_context3.prev = _context3.next) {
1886
- case 0:
1887
- _context3.next = 2;
1888
- return this.Batch.importEvents({
1889
- events: [{
1890
- date: parameters.date,
1891
- email: parameters.email,
1892
- type: BentoEvents.UNSUBSCRIBE
1893
- }]
1894
- });
1895
- case 2:
1896
- result = _context3.sent;
1897
- return _context3.abrupt("return", result === 1);
1898
- case 4:
1899
- case "end":
1900
- return _context3.stop();
1901
- }
1902
- }, _callee3, this);
1903
- }));
1904
- function removeSubscriber(_x3) {
1905
- return _removeSubscriber.apply(this, arguments);
1906
- }
1907
- return removeSubscriber;
1908
- }()
1909
- /**
1910
- * **This TRIGGERS automations!** - If you do not wish to trigger automations, please use the
1911
- * `Commands.addField` method.
1912
- *
1913
- * Sets the passed-in custom fields on the subscriber, creating the subscriber if it does not exist.
1914
- * If the fields are already set on the subscriber, the event will be sent, triggering any automations
1915
- * that take place upon fields being updated. Please be aware of the potential consequences.
1916
- *
1917
- * You may optionally pass a `Date` which will backdate the event. If no date is supplied, then the event
1918
- * will default to the current time.
1919
- *
1920
- * Because this method uses the batch API, the tag may take between 1 and 3 minutes
1921
- * to appear in the system.
1922
- *
1923
- * Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
1924
- *
1925
- * @param parameters UpdateFieldsParameters\<S\>
1926
- * @returns Promise\<boolean\>
1927
- */
1928
- ;
1929
- _proto.updateFields =
1930
- /*#__PURE__*/
1931
- function () {
1932
- var _updateFields = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(parameters) {
1933
- var result;
1934
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
1935
- while (1) switch (_context4.prev = _context4.next) {
1936
- case 0:
1937
- _context4.next = 2;
1938
- return this.Batch.importEvents({
1939
- events: [{
1940
- date: parameters.date,
1941
- email: parameters.email,
1942
- type: BentoEvents.UPDATE_FIELDS,
1943
- fields: parameters.fields
1944
- }]
1945
- });
1946
- case 2:
1947
- result = _context4.sent;
1948
- return _context4.abrupt("return", result === 1);
1949
- case 4:
1950
- case "end":
1951
- return _context4.stop();
1952
- }
1953
- }, _callee4, this);
1954
- }));
1955
- function updateFields(_x4) {
1956
- return _updateFields.apply(this, arguments);
1957
- }
1958
- return updateFields;
1959
- }()
1960
- /**
1961
- * **This TRIGGERS automations!** - There is no way to achieve this same behavior without triggering
1962
- * automations.
1963
- *
1964
- * Tracks a purchase in Bento, used to calculate LTV for your subscribers. The values that are received
1965
- * should be numbers, in cents. For example, `$1.00` should be `100`.
1966
- *
1967
- * You may optionally pass a `Date` which will backdate the event. If no date is supplied, then the event
1968
- * will default to the current time.
1969
- *
1970
- * Because this method uses the batch API, the tag may take between 1 and 3 minutes
1971
- * to appear in the system.
1972
- *
1973
- * Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
1974
- *
1975
- * @param parameters TrackPurchaseParameters
1976
- * @returns Promise\<boolean\>
1977
- */
1978
- ;
1979
- _proto.trackPurchase =
1980
- /*#__PURE__*/
1981
- function () {
1982
- var _trackPurchase = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(parameters) {
1983
- var result;
1984
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
1985
- while (1) switch (_context5.prev = _context5.next) {
1986
- case 0:
1987
- _context5.next = 2;
1988
- return this.Batch.importEvents({
1989
- events: [{
1990
- date: parameters.date,
1991
- email: parameters.email,
1992
- type: BentoEvents.PURCHASE,
1993
- details: parameters.purchaseDetails
1994
- }]
1995
- });
1996
- case 2:
1997
- result = _context5.sent;
1998
- return _context5.abrupt("return", result === 1);
1999
- case 4:
2000
- case "end":
2001
- return _context5.stop();
2002
- }
2003
- }, _callee5, this);
2004
- }));
2005
- function trackPurchase(_x5) {
2006
- return _trackPurchase.apply(this, arguments);
2007
- }
2008
- return trackPurchase;
2009
- }()
2010
- /**
2011
- * **This TRIGGERS automations!** - There is no way to achieve this same behavior without triggering
2012
- * automations.
2013
- *
2014
- * Tracks a custom event in Bento.
2015
- *
2016
- * You may optionally pass a `Date` which will backdate the event. If no date is supplied, then the event
2017
- * will default to the current time.
2018
- *
2019
- * Because this method uses the batch API, the tag may take between 1 and 3 minutes
2020
- * to appear in the system.
2021
- *
2022
- * Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
2023
- *
2024
- * @param parameters TrackParameters<S, E>
2025
- * @returns Promise\<boolean\>
2026
- */
2027
- ;
2028
- _proto.track =
2029
- /*#__PURE__*/
2030
- function () {
2031
- var _track = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(parameters) {
2032
- var result;
2033
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
2034
- while (1) switch (_context6.prev = _context6.next) {
2035
- case 0:
2036
- _context6.next = 2;
2037
- return this.Batch.importEvents({
2038
- events: [parameters]
2039
- });
2040
- case 2:
2041
- result = _context6.sent;
2042
- return _context6.abrupt("return", result === 1);
2043
- case 4:
2044
- case "end":
2045
- return _context6.stop();
2046
- }
2047
- }, _callee6, this);
2048
- }));
2049
- function track(_x6) {
2050
- return _track.apply(this, arguments);
2051
- }
2052
- return track;
2053
- }();
2054
- return BentoAPIV1;
2055
- }();
2056
-
2057
- var Analytics = function Analytics(options) {
2058
- this.V1 = void 0;
2059
- this.V1 = new BentoAPIV1(options);
2060
- };
2061
-
2062
- export { Analytics, NotAuthorizedError, RateLimitedError };
2063
- //# sourceMappingURL=bento-node-sdk.esm.js.map