@bentonow/bento-node-sdk 0.2.1 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{LICENSE → LICENSE.md} +1 -1
- package/README.md +494 -1077
- package/dist/index.d.ts +9 -9
- package/dist/index.js +1273 -5
- package/dist/sdk/batch/enums.d.ts +8 -8
- package/dist/sdk/batch/errors.d.ts +18 -18
- package/dist/sdk/batch/events.d.ts +71 -71
- package/dist/sdk/batch/index.d.ts +55 -55
- package/dist/sdk/batch/types.d.ts +37 -37
- package/dist/sdk/broadcasts/index.d.ts +25 -0
- package/dist/sdk/broadcasts/types.d.ts +28 -0
- package/dist/sdk/client/errors.d.ts +9 -6
- package/dist/sdk/client/index.d.ts +74 -64
- package/dist/sdk/client/types.d.ts +3 -3
- package/dist/sdk/commands/enums.d.ts +12 -12
- package/dist/sdk/commands/index.d.ts +79 -79
- package/dist/sdk/commands/types.d.ts +32 -32
- package/dist/sdk/email-templates/index.d.ts +21 -0
- package/dist/sdk/email-templates/types.d.ts +23 -0
- package/dist/sdk/enums.d.ts +12 -9
- package/dist/sdk/errors.d.ts +2 -2
- package/dist/sdk/experimental/index.d.ts +75 -57
- package/dist/sdk/experimental/types.d.ts +71 -41
- package/dist/sdk/fields/index.d.ts +29 -29
- package/dist/sdk/fields/types.d.ts +17 -17
- package/dist/sdk/forms/index.d.ts +14 -14
- package/dist/sdk/forms/types.d.ts +28 -28
- package/dist/sdk/index.d.ts +11 -8
- package/dist/sdk/interfaces.d.ts +13 -13
- package/dist/sdk/sequences/index.d.ts +13 -0
- package/dist/sdk/sequences/types.d.ts +18 -0
- package/dist/sdk/stats/index.d.ts +24 -0
- package/dist/sdk/stats/types.d.ts +26 -0
- package/dist/sdk/subscribers/index.d.ts +20 -20
- package/dist/sdk/subscribers/types.d.ts +25 -25
- package/dist/sdk/tags/index.d.ts +20 -20
- package/dist/sdk/tags/types.d.ts +17 -17
- package/dist/sdk/types.d.ts +41 -41
- package/dist/sdk/workflows/index.d.ts +13 -0
- package/dist/sdk/workflows/types.d.ts +18 -0
- package/dist/versions/v1/index.d.ts +164 -132
- package/dist/versions/v1/types.d.ts +31 -31
- package/package.json +31 -44
- package/src/sdk/batch/events.ts +1 -1
- package/src/sdk/batch/index.ts +13 -25
- package/src/sdk/broadcasts/index.ts +43 -0
- package/src/sdk/broadcasts/types.ts +34 -0
- package/src/sdk/client/errors.ts +7 -0
- package/src/sdk/client/index.ts +113 -30
- package/src/sdk/commands/index.ts +54 -89
- package/src/sdk/email-templates/index.ts +39 -0
- package/src/sdk/email-templates/types.ts +27 -0
- package/src/sdk/enums.ts +3 -0
- package/src/sdk/experimental/index.ts +44 -26
- package/src/sdk/experimental/types.ts +35 -0
- package/src/sdk/fields/index.ts +1 -3
- package/src/sdk/forms/index.ts +4 -9
- package/src/sdk/forms/types.ts +1 -7
- package/src/sdk/index.ts +3 -0
- package/src/sdk/sequences/index.ts +21 -0
- package/src/sdk/sequences/types.ts +21 -0
- package/src/sdk/stats/index.ts +37 -0
- package/src/sdk/stats/types.ts +28 -0
- package/src/sdk/subscribers/index.ts +5 -15
- package/src/sdk/tags/index.ts +1 -3
- package/src/sdk/types.ts +1 -1
- package/src/sdk/workflows/index.ts +21 -0
- package/src/sdk/workflows/types.ts +21 -0
- package/src/versions/v1/index.ts +59 -10
- package/dist/bento-node-sdk.cjs.development.js +0 -2071
- package/dist/bento-node-sdk.cjs.development.js.map +0 -1
- package/dist/bento-node-sdk.cjs.production.min.js +0 -2
- package/dist/bento-node-sdk.cjs.production.min.js.map +0 -1
- package/dist/bento-node-sdk.esm.js +0 -2063
- package/dist/bento-node-sdk.esm.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,8 +1,1276 @@
|
|
|
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
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
+
});
|
|
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
|
+
});
|
|
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
|
+
// src/sdk/client/index.ts
|
|
683
|
+
function encodeBase64(str) {
|
|
684
|
+
if (typeof btoa === "function") {
|
|
685
|
+
return btoa(str);
|
|
686
|
+
} else if (typeof Buffer !== "undefined") {
|
|
687
|
+
return Buffer.from(str).toString("base64");
|
|
688
|
+
} else {
|
|
689
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
690
|
+
let output = "";
|
|
691
|
+
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)) {
|
|
692
|
+
charCode = str.charCodeAt(i += 3 / 4);
|
|
693
|
+
if (charCode > 255) {
|
|
694
|
+
throw new Error("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");
|
|
695
|
+
}
|
|
696
|
+
block = block << 8 | charCode;
|
|
697
|
+
}
|
|
698
|
+
return output;
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
class BentoClient {
|
|
703
|
+
_headers = {};
|
|
704
|
+
_baseUrl = "https://app.bentonow.com/api/v1";
|
|
705
|
+
_siteUuid = "";
|
|
706
|
+
_logErrors = false;
|
|
707
|
+
constructor(options) {
|
|
708
|
+
this._baseUrl = options.clientOptions?.baseUrl || this._baseUrl;
|
|
709
|
+
this._siteUuid = options.siteUuid;
|
|
710
|
+
this._headers = this._extractHeaders(options.authentication, options.siteUuid);
|
|
711
|
+
this._logErrors = options.logErrors || false;
|
|
712
|
+
}
|
|
713
|
+
get(endpoint, payload = {}) {
|
|
714
|
+
return new Promise((resolve, reject) => {
|
|
715
|
+
const queryParameters = this._getQueryParameters(payload);
|
|
716
|
+
import_cross_fetch.default(`${this._baseUrl}${endpoint}?${queryParameters}`, {
|
|
717
|
+
method: "GET",
|
|
718
|
+
headers: this._headers
|
|
719
|
+
}).then(async (result) => {
|
|
720
|
+
if (this._isSuccessfulStatus(result.status)) {
|
|
721
|
+
return result.json();
|
|
722
|
+
}
|
|
723
|
+
throw await this._getErrorForResponse(result);
|
|
724
|
+
}).then((data) => resolve(data)).catch((error) => reject(error));
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
post(endpoint, payload = {}) {
|
|
728
|
+
return new Promise((resolve, reject) => {
|
|
729
|
+
const body = this._getBody(payload);
|
|
730
|
+
import_cross_fetch.default(`${this._baseUrl}${endpoint}`, {
|
|
731
|
+
method: "POST",
|
|
732
|
+
headers: {
|
|
733
|
+
...this._headers,
|
|
734
|
+
"Content-Type": "application/json"
|
|
735
|
+
},
|
|
736
|
+
body
|
|
737
|
+
}).then(async (result) => {
|
|
738
|
+
if (this._isSuccessfulStatus(result.status)) {
|
|
739
|
+
return result.json();
|
|
740
|
+
}
|
|
741
|
+
throw await this._getErrorForResponse(result);
|
|
742
|
+
}).then((data) => resolve(data)).catch((error) => reject(error));
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
patch(endpoint, payload = {}) {
|
|
746
|
+
return new Promise((resolve, reject) => {
|
|
747
|
+
const body = this._getBody(payload);
|
|
748
|
+
import_cross_fetch.default(`${this._baseUrl}${endpoint}`, {
|
|
749
|
+
method: "PATCH",
|
|
750
|
+
headers: {
|
|
751
|
+
...this._headers,
|
|
752
|
+
"Content-Type": "application/json"
|
|
753
|
+
},
|
|
754
|
+
body
|
|
755
|
+
}).then(async (result) => {
|
|
756
|
+
if (this._isSuccessfulStatus(result.status)) {
|
|
757
|
+
return result.json();
|
|
758
|
+
}
|
|
759
|
+
throw await this._getErrorForResponse(result);
|
|
760
|
+
}).then((data) => resolve(data)).catch((error) => reject(error));
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
_extractHeaders(authentication, siteUuid) {
|
|
764
|
+
const authenticationKey = encodeBase64(`${authentication.publishableKey}:${authentication.secretKey}`);
|
|
765
|
+
return {
|
|
766
|
+
Authorization: `Basic ${authenticationKey}`,
|
|
767
|
+
"User-Agent": `bento-node-${siteUuid}`
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
_getBody(payload) {
|
|
771
|
+
return JSON.stringify({
|
|
772
|
+
...payload,
|
|
773
|
+
site_uuid: this._siteUuid
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
_getQueryParameters(payload) {
|
|
777
|
+
const body = {
|
|
778
|
+
...payload,
|
|
779
|
+
site_uuid: this._siteUuid
|
|
780
|
+
};
|
|
781
|
+
const queryParameters = new URLSearchParams;
|
|
782
|
+
for (const [key, value] of Object.entries(body)) {
|
|
783
|
+
queryParameters.append(key, value);
|
|
784
|
+
}
|
|
785
|
+
return queryParameters.toString();
|
|
786
|
+
}
|
|
787
|
+
_isSuccessfulStatus(statusCode) {
|
|
788
|
+
const validStatusCodes = [200, 201];
|
|
789
|
+
return validStatusCodes.includes(statusCode);
|
|
790
|
+
}
|
|
791
|
+
async _getErrorForResponse(response) {
|
|
792
|
+
if (this._logErrors) {
|
|
793
|
+
console.error(response);
|
|
794
|
+
}
|
|
795
|
+
if (response.status === 401)
|
|
796
|
+
return new NotAuthorizedError;
|
|
797
|
+
if (response.status === 429)
|
|
798
|
+
return new RateLimitedError;
|
|
799
|
+
const contentType = response.headers.get("Content-Type");
|
|
800
|
+
let responseMessage = "";
|
|
801
|
+
let json = null;
|
|
802
|
+
try {
|
|
803
|
+
if (contentType?.toLowerCase().includes("application/json")) {
|
|
804
|
+
try {
|
|
805
|
+
json = await response.json();
|
|
806
|
+
} catch {
|
|
807
|
+
responseMessage = "Unable to parse JSON response";
|
|
808
|
+
}
|
|
809
|
+
} else if (contentType?.toLowerCase().includes("text/plain")) {
|
|
810
|
+
try {
|
|
811
|
+
responseMessage = await response.text();
|
|
812
|
+
} catch {
|
|
813
|
+
responseMessage = "Unable to read text response";
|
|
814
|
+
}
|
|
815
|
+
} else {
|
|
816
|
+
responseMessage = "Unknown response from the Bento API.";
|
|
817
|
+
}
|
|
818
|
+
} catch {
|
|
819
|
+
responseMessage = "Unable to read response body";
|
|
820
|
+
}
|
|
821
|
+
if (json && json.error === "Author not authorized to send on this account") {
|
|
822
|
+
return new AuthorNotAuthorizedError(json.error);
|
|
823
|
+
}
|
|
824
|
+
if (json) {
|
|
825
|
+
responseMessage = JSON.stringify(json);
|
|
826
|
+
}
|
|
827
|
+
if (!responseMessage) {
|
|
828
|
+
responseMessage = "Unknown response from the Bento API.";
|
|
829
|
+
}
|
|
830
|
+
return new Error(`[${response.status}] - ${responseMessage}`);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
// src/sdk/commands/index.ts
|
|
834
|
+
class BentoCommands {
|
|
835
|
+
_client;
|
|
836
|
+
_url = "/fetch/commands";
|
|
837
|
+
constructor(_client) {
|
|
838
|
+
this._client = _client;
|
|
839
|
+
}
|
|
840
|
+
async addTag(parameters) {
|
|
841
|
+
const result = await this._client.post(this._url, {
|
|
842
|
+
command: {
|
|
843
|
+
command: "add_tag" /* ADD_TAG */,
|
|
844
|
+
email: parameters.email,
|
|
845
|
+
query: parameters.tagName
|
|
846
|
+
}
|
|
847
|
+
});
|
|
848
|
+
if (Object.keys(result).length === 0 || !result.data)
|
|
849
|
+
return null;
|
|
850
|
+
return result.data;
|
|
851
|
+
}
|
|
852
|
+
async removeTag(parameters) {
|
|
853
|
+
const result = await this._client.post(this._url, {
|
|
854
|
+
command: {
|
|
855
|
+
command: "remove_tag" /* REMOVE_TAG */,
|
|
856
|
+
email: parameters.email,
|
|
857
|
+
query: parameters.tagName
|
|
858
|
+
}
|
|
859
|
+
});
|
|
860
|
+
if (Object.keys(result).length === 0 || !result.data)
|
|
861
|
+
return null;
|
|
862
|
+
return result.data;
|
|
863
|
+
}
|
|
864
|
+
async addField(parameters) {
|
|
865
|
+
const result = await this._client.post(this._url, {
|
|
866
|
+
command: {
|
|
867
|
+
command: "add_field" /* ADD_FIELD */,
|
|
868
|
+
email: parameters.email,
|
|
869
|
+
query: parameters.field
|
|
870
|
+
}
|
|
871
|
+
});
|
|
872
|
+
if (Object.keys(result).length === 0 || !result.data)
|
|
873
|
+
return null;
|
|
874
|
+
return result.data;
|
|
875
|
+
}
|
|
876
|
+
async removeField(parameters) {
|
|
877
|
+
const result = await this._client.post(this._url, {
|
|
878
|
+
command: {
|
|
879
|
+
command: "remove_field" /* REMOVE_FIELD */,
|
|
880
|
+
email: parameters.email,
|
|
881
|
+
query: parameters.fieldName
|
|
882
|
+
}
|
|
883
|
+
});
|
|
884
|
+
if (Object.keys(result).length === 0 || !result.data)
|
|
885
|
+
return null;
|
|
886
|
+
return result.data;
|
|
887
|
+
}
|
|
888
|
+
async subscribe(parameters) {
|
|
889
|
+
const result = await this._client.post(this._url, {
|
|
890
|
+
command: {
|
|
891
|
+
command: "subscribe" /* SUBSCRIBE */,
|
|
892
|
+
email: parameters.email
|
|
893
|
+
}
|
|
894
|
+
});
|
|
895
|
+
if (Object.keys(result).length === 0 || !result.data)
|
|
896
|
+
return null;
|
|
897
|
+
return result.data;
|
|
898
|
+
}
|
|
899
|
+
async unsubscribe(parameters) {
|
|
900
|
+
const result = await this._client.post(this._url, {
|
|
901
|
+
command: {
|
|
902
|
+
command: "unsubscribe" /* UNSUBSCRIBE */,
|
|
903
|
+
email: parameters.email
|
|
904
|
+
}
|
|
905
|
+
});
|
|
906
|
+
if (Object.keys(result).length === 0 || !result.data)
|
|
907
|
+
return null;
|
|
908
|
+
return result.data;
|
|
909
|
+
}
|
|
910
|
+
async changeEmail(parameters) {
|
|
911
|
+
const result = await this._client.post(this._url, {
|
|
912
|
+
command: {
|
|
913
|
+
command: "change_email" /* CHANGE_EMAIL */,
|
|
914
|
+
email: parameters.oldEmail,
|
|
915
|
+
query: parameters.newEmail
|
|
916
|
+
}
|
|
917
|
+
});
|
|
918
|
+
if (Object.keys(result).length === 0 || !result.data)
|
|
919
|
+
return null;
|
|
920
|
+
return result.data;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
// src/sdk/email-templates/index.ts
|
|
924
|
+
class BentoEmailTemplates {
|
|
925
|
+
_client;
|
|
926
|
+
_url = "/fetch/emails/templates";
|
|
927
|
+
constructor(_client) {
|
|
928
|
+
this._client = _client;
|
|
929
|
+
}
|
|
930
|
+
async getEmailTemplate(parameters) {
|
|
931
|
+
const result = await this._client.get(`${this._url}/${parameters.id}`);
|
|
932
|
+
if (Object.keys(result).length === 0 || !result.data)
|
|
933
|
+
return null;
|
|
934
|
+
return result.data;
|
|
935
|
+
}
|
|
936
|
+
async updateEmailTemplate(parameters) {
|
|
937
|
+
const { id, ...updateFields } = parameters;
|
|
938
|
+
const result = await this._client.patch(`${this._url}/${id}`, {
|
|
939
|
+
email_template: updateFields
|
|
940
|
+
});
|
|
941
|
+
if (Object.keys(result).length === 0 || !result.data)
|
|
942
|
+
return null;
|
|
943
|
+
return result.data;
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
// src/sdk/experimental/index.ts
|
|
947
|
+
class BentoExperimental {
|
|
948
|
+
_client;
|
|
949
|
+
_url = "/experimental";
|
|
950
|
+
constructor(_client) {
|
|
951
|
+
this._client = _client;
|
|
952
|
+
}
|
|
953
|
+
async validateEmail(parameters) {
|
|
954
|
+
const result = await this._client.post(`${this._url}/validation`, {
|
|
955
|
+
email: parameters.email,
|
|
956
|
+
ip: parameters.ip,
|
|
957
|
+
name: parameters.name,
|
|
958
|
+
user_agent: parameters.userAgent
|
|
959
|
+
});
|
|
960
|
+
return result.valid;
|
|
961
|
+
}
|
|
962
|
+
async guessGender(parameters) {
|
|
963
|
+
const result = await this._client.post(`${this._url}/gender`, parameters);
|
|
964
|
+
return result;
|
|
965
|
+
}
|
|
966
|
+
async geolocate(parameters) {
|
|
967
|
+
const result = await this._client.get(`${this._url}/geolocation`, parameters);
|
|
968
|
+
if (Object.keys(result).length === 0)
|
|
969
|
+
return null;
|
|
970
|
+
return result;
|
|
971
|
+
}
|
|
972
|
+
async checkBlacklist(parameters) {
|
|
973
|
+
const result = await this._client.get(`${this._url}/blacklist.json`, parameters);
|
|
974
|
+
return result;
|
|
975
|
+
}
|
|
976
|
+
async getBlacklistStatus(input) {
|
|
977
|
+
return this._client.get(`${this._url}/blacklist`, input);
|
|
978
|
+
}
|
|
979
|
+
async getContentModeration(content) {
|
|
980
|
+
return this._client.post(`${this._url}/moderation`, {
|
|
981
|
+
content
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
async geoLocateIP(ipAddress) {
|
|
985
|
+
return this._client.get(`${this._url}/geolocation`, {
|
|
986
|
+
ip: ipAddress
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
// src/sdk/fields/index.ts
|
|
991
|
+
class BentoFields {
|
|
992
|
+
_client;
|
|
993
|
+
_url = "/fetch/fields";
|
|
994
|
+
constructor(_client) {
|
|
995
|
+
this._client = _client;
|
|
996
|
+
}
|
|
997
|
+
async getFields() {
|
|
998
|
+
const result = await this._client.get(this._url);
|
|
999
|
+
if (Object.keys(result).length === 0 || !result.data)
|
|
1000
|
+
return null;
|
|
1001
|
+
return result.data;
|
|
1002
|
+
}
|
|
1003
|
+
async createField(parameters) {
|
|
1004
|
+
const result = await this._client.post(this._url, {
|
|
1005
|
+
field: parameters
|
|
1006
|
+
});
|
|
1007
|
+
if (Object.keys(result).length === 0 || !result.data)
|
|
1008
|
+
return null;
|
|
1009
|
+
return result.data;
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
// src/sdk/forms/index.ts
|
|
1013
|
+
class BentoForms {
|
|
1014
|
+
_client;
|
|
1015
|
+
_url = "/fetch/responses";
|
|
1016
|
+
constructor(_client) {
|
|
1017
|
+
this._client = _client;
|
|
1018
|
+
}
|
|
1019
|
+
async getResponses(formIdentifier) {
|
|
1020
|
+
const result = await this._client.get(this._url, {
|
|
1021
|
+
id: formIdentifier
|
|
1022
|
+
});
|
|
1023
|
+
if (Object.keys(result).length === 0 || !result.data)
|
|
1024
|
+
return null;
|
|
1025
|
+
return result.data;
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
// src/sdk/sequences/index.ts
|
|
1029
|
+
class BentoSequences {
|
|
1030
|
+
_client;
|
|
1031
|
+
_url = "/fetch/sequences";
|
|
1032
|
+
constructor(_client) {
|
|
1033
|
+
this._client = _client;
|
|
1034
|
+
}
|
|
1035
|
+
async getSequences() {
|
|
1036
|
+
const result = await this._client.get(this._url);
|
|
1037
|
+
if (Object.keys(result).length === 0 || !result.data)
|
|
1038
|
+
return null;
|
|
1039
|
+
return result.data;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
// src/sdk/subscribers/index.ts
|
|
1043
|
+
class BentoSubscribers {
|
|
1044
|
+
_client;
|
|
1045
|
+
_url = "/fetch/subscribers";
|
|
1046
|
+
constructor(_client) {
|
|
1047
|
+
this._client = _client;
|
|
1048
|
+
}
|
|
1049
|
+
async getSubscribers(parameters) {
|
|
1050
|
+
const result = await this._client.get(this._url, parameters);
|
|
1051
|
+
if (Object.keys(result).length === 0 || !result.data)
|
|
1052
|
+
return null;
|
|
1053
|
+
return result.data;
|
|
1054
|
+
}
|
|
1055
|
+
async createSubscriber(parameters) {
|
|
1056
|
+
const result = await this._client.post(this._url, {
|
|
1057
|
+
subscriber: parameters
|
|
1058
|
+
});
|
|
1059
|
+
if (Object.keys(result).length === 0 || !result.data)
|
|
1060
|
+
return null;
|
|
1061
|
+
return result.data;
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
// src/sdk/tags/index.ts
|
|
1065
|
+
class BentoTags {
|
|
1066
|
+
_client;
|
|
1067
|
+
_url = "/fetch/tags";
|
|
1068
|
+
constructor(_client) {
|
|
1069
|
+
this._client = _client;
|
|
1070
|
+
}
|
|
1071
|
+
async getTags() {
|
|
1072
|
+
const result = await this._client.get(this._url);
|
|
1073
|
+
if (Object.keys(result).length === 0 || !result.data)
|
|
1074
|
+
return null;
|
|
1075
|
+
return result.data;
|
|
1076
|
+
}
|
|
1077
|
+
async createTag(parameters) {
|
|
1078
|
+
const result = await this._client.post(this._url, {
|
|
1079
|
+
tag: parameters
|
|
1080
|
+
});
|
|
1081
|
+
if (Object.keys(result).length === 0 || !result.data)
|
|
1082
|
+
return null;
|
|
1083
|
+
return result.data;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
// src/sdk/workflows/index.ts
|
|
1087
|
+
class BentoWorkflows {
|
|
1088
|
+
_client;
|
|
1089
|
+
_url = "/fetch/workflows";
|
|
1090
|
+
constructor(_client) {
|
|
1091
|
+
this._client = _client;
|
|
1092
|
+
}
|
|
1093
|
+
async getWorkflows() {
|
|
1094
|
+
const result = await this._client.get(this._url);
|
|
1095
|
+
if (Object.keys(result).length === 0 || !result.data)
|
|
1096
|
+
return null;
|
|
1097
|
+
return result.data;
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
// src/sdk/broadcasts/index.ts
|
|
1101
|
+
class BentoBroadcasts {
|
|
1102
|
+
_client;
|
|
1103
|
+
_url = "/broadcasts";
|
|
1104
|
+
_emailsUrl = "/emails";
|
|
1105
|
+
constructor(_client) {
|
|
1106
|
+
this._client = _client;
|
|
1107
|
+
}
|
|
1108
|
+
async createEmails(emails) {
|
|
1109
|
+
const result = await this._client.post(this._emailsUrl, {
|
|
1110
|
+
emails
|
|
1111
|
+
});
|
|
1112
|
+
return result.results;
|
|
1113
|
+
}
|
|
1114
|
+
async getBroadcasts() {
|
|
1115
|
+
const result = await this._client.get(this._url);
|
|
1116
|
+
return result.data ?? [];
|
|
1117
|
+
}
|
|
1118
|
+
async createBroadcast(broadcasts) {
|
|
1119
|
+
const result = await this._client.post(this._url, {
|
|
1120
|
+
broadcasts
|
|
1121
|
+
});
|
|
1122
|
+
return result.data ?? [];
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
// src/sdk/stats/index.ts
|
|
1127
|
+
class BentoStats {
|
|
1128
|
+
_client;
|
|
1129
|
+
_url = "/stats";
|
|
1130
|
+
constructor(_client) {
|
|
1131
|
+
this._client = _client;
|
|
1132
|
+
}
|
|
1133
|
+
async getSiteStats() {
|
|
1134
|
+
const result = await this._client.get(`${this._url}/site`);
|
|
1135
|
+
return result;
|
|
1136
|
+
}
|
|
1137
|
+
async getSegmentStats(segmentId) {
|
|
1138
|
+
const result = await this._client.get(`${this._url}/segments/${segmentId}`);
|
|
1139
|
+
return result;
|
|
1140
|
+
}
|
|
1141
|
+
async getReportStats(reportId) {
|
|
1142
|
+
const result = await this._client.get(`${this._url}/reports/${reportId}`);
|
|
1143
|
+
return result;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
// src/versions/v1/index.ts
|
|
1148
|
+
class BentoAPIV1 {
|
|
1149
|
+
_client;
|
|
1150
|
+
Broadcasts;
|
|
1151
|
+
EmailTemplates;
|
|
1152
|
+
Stats;
|
|
1153
|
+
Batch;
|
|
1154
|
+
Commands;
|
|
1155
|
+
Experimental;
|
|
1156
|
+
Fields;
|
|
1157
|
+
Forms;
|
|
1158
|
+
Sequences;
|
|
1159
|
+
Subscribers;
|
|
1160
|
+
Tags;
|
|
1161
|
+
Workflows;
|
|
1162
|
+
constructor(options) {
|
|
1163
|
+
this._client = new BentoClient(options);
|
|
1164
|
+
this.Broadcasts = new BentoBroadcasts(this._client);
|
|
1165
|
+
this.EmailTemplates = new BentoEmailTemplates(this._client);
|
|
1166
|
+
this.Stats = new BentoStats(this._client);
|
|
1167
|
+
this.Batch = new BentoBatch(this._client);
|
|
1168
|
+
this.Commands = new BentoCommands(this._client);
|
|
1169
|
+
this.Experimental = new BentoExperimental(this._client);
|
|
1170
|
+
this.Fields = new BentoFields(this._client);
|
|
1171
|
+
this.Forms = new BentoForms(this._client);
|
|
1172
|
+
this.Sequences = new BentoSequences(this._client);
|
|
1173
|
+
this.Subscribers = new BentoSubscribers(this._client);
|
|
1174
|
+
this.Tags = new BentoTags(this._client);
|
|
1175
|
+
this.Workflows = new BentoWorkflows(this._client);
|
|
1176
|
+
}
|
|
1177
|
+
async tagSubscriber(parameters) {
|
|
1178
|
+
const result = await this.Batch.importEvents({
|
|
1179
|
+
events: [
|
|
1180
|
+
{
|
|
1181
|
+
date: parameters.date,
|
|
1182
|
+
details: {
|
|
1183
|
+
tag: parameters.tagName
|
|
1184
|
+
},
|
|
1185
|
+
email: parameters.email,
|
|
1186
|
+
type: "$tag" /* TAG */
|
|
1187
|
+
}
|
|
1188
|
+
]
|
|
1189
|
+
});
|
|
1190
|
+
return result === 1;
|
|
1191
|
+
}
|
|
1192
|
+
async addSubscriber(parameters) {
|
|
1193
|
+
const result = await this.Batch.importEvents({
|
|
1194
|
+
events: [
|
|
1195
|
+
{
|
|
1196
|
+
date: parameters.date,
|
|
1197
|
+
email: parameters.email,
|
|
1198
|
+
type: "$subscribe" /* SUBSCRIBE */,
|
|
1199
|
+
fields: parameters.fields || {}
|
|
1200
|
+
}
|
|
1201
|
+
]
|
|
1202
|
+
});
|
|
1203
|
+
return result === 1;
|
|
1204
|
+
}
|
|
1205
|
+
async removeSubscriber(parameters) {
|
|
1206
|
+
const result = await this.Batch.importEvents({
|
|
1207
|
+
events: [
|
|
1208
|
+
{
|
|
1209
|
+
date: parameters.date,
|
|
1210
|
+
email: parameters.email,
|
|
1211
|
+
type: "$unsubscribe" /* UNSUBSCRIBE */
|
|
1212
|
+
}
|
|
1213
|
+
]
|
|
1214
|
+
});
|
|
1215
|
+
return result === 1;
|
|
1216
|
+
}
|
|
1217
|
+
async updateFields(parameters) {
|
|
1218
|
+
const result = await this.Batch.importEvents({
|
|
1219
|
+
events: [
|
|
1220
|
+
{
|
|
1221
|
+
date: parameters.date,
|
|
1222
|
+
email: parameters.email,
|
|
1223
|
+
type: "$update_fields" /* UPDATE_FIELDS */,
|
|
1224
|
+
fields: parameters.fields
|
|
1225
|
+
}
|
|
1226
|
+
]
|
|
1227
|
+
});
|
|
1228
|
+
return result === 1;
|
|
1229
|
+
}
|
|
1230
|
+
async trackPurchase(parameters) {
|
|
1231
|
+
const result = await this.Batch.importEvents({
|
|
1232
|
+
events: [
|
|
1233
|
+
{
|
|
1234
|
+
date: parameters.date,
|
|
1235
|
+
email: parameters.email,
|
|
1236
|
+
type: "$purchase" /* PURCHASE */,
|
|
1237
|
+
details: parameters.purchaseDetails
|
|
1238
|
+
}
|
|
1239
|
+
]
|
|
1240
|
+
});
|
|
1241
|
+
return result === 1;
|
|
1242
|
+
}
|
|
1243
|
+
async track(parameters) {
|
|
1244
|
+
const result = await this.Batch.importEvents({
|
|
1245
|
+
events: [parameters]
|
|
1246
|
+
});
|
|
1247
|
+
return result === 1;
|
|
1248
|
+
}
|
|
1249
|
+
async upsertSubscriber(parameters) {
|
|
1250
|
+
await this.Batch.importSubscribers({
|
|
1251
|
+
subscribers: [{
|
|
1252
|
+
email: parameters.email,
|
|
1253
|
+
...parameters.fields,
|
|
1254
|
+
...parameters.tags && { tags: parameters.tags },
|
|
1255
|
+
...parameters.remove_tags && { remove_tags: parameters.remove_tags }
|
|
1256
|
+
}]
|
|
1257
|
+
});
|
|
1258
|
+
return this.Subscribers.getSubscribers({
|
|
1259
|
+
email: parameters.email
|
|
1260
|
+
});
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
// src/index.ts
|
|
1265
|
+
class Analytics {
|
|
1266
|
+
V1;
|
|
1267
|
+
constructor(options) {
|
|
1268
|
+
this.V1 = new BentoAPIV1(options);
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
export {
|
|
1272
|
+
RateLimitedError,
|
|
1273
|
+
NotAuthorizedError,
|
|
1274
|
+
AuthorNotAuthorizedError,
|
|
1275
|
+
Analytics
|
|
1276
|
+
};
|