@bentonow/bento-node-sdk 1.0.6 → 1.0.8

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/README.md CHANGED
@@ -608,24 +608,33 @@ bento.V1.Tags.createTag({
608
608
 
609
609
  ### Sequences
610
610
 
611
- Retrieve sequences and their associated email templates.
611
+ Sequences power drip campaigns, onboarding flows, and other time-based journeys by chaining multiple email templates with configurable delays. The SDK mirrors the public Sequences API for fetching sequences, creating new sequence emails, and updating template content. Refer to the [Sequences API docs](https://docs.bentonow.com/sequences_api#get-sequences) for full request/response details.
612
612
 
613
613
  #### getSequences
614
614
 
615
- Retrieves all sequences for the site, including their email templates.
615
+ Calls `GET /v1/fetch/sequences` and returns every sequence plus the embedded email templates and stats. Pass `{ page }` to paginate through large installs—the SDK appends `site_uuid` automatically.
616
616
 
617
617
  ```javascript
618
- const sequences = await bento.V1.Sequences.getSequences();
619
- // Returns:
620
- // [
618
+ import { Analytics } from '@bentonow/bento-node-sdk';
619
+
620
+ const analytics = new Analytics({
621
+ authentication: {
622
+ publishableKey: process.env.BENTO_PUBLISHABLE_KEY,
623
+ secretKey: process.env.BENTO_SECRET_KEY,
624
+ },
625
+ siteUuid: process.env.BENTO_SITE_UUID,
626
+ });
627
+
628
+ const sequences = await analytics.V1.Sequences.getSequences({ page: 1 });
629
+ // sequences => [
621
630
  // {
622
- // id: '123',
631
+ // id: 'seq-1',
623
632
  // type: 'sequence',
624
633
  // attributes: {
625
634
  // name: 'Welcome Sequence',
626
635
  // created_at: '2024-01-01T00:00:00Z',
627
636
  // email_templates: [
628
- // { id: 1, subject: 'Welcome!', stats: null },
637
+ // { id: 1, subject: 'Welcome!', stats: { opened: 100, clicked: 50 } },
629
638
  // { id: 2, subject: 'Getting Started', stats: null }
630
639
  // ]
631
640
  // }
@@ -635,39 +644,61 @@ const sequences = await bento.V1.Sequences.getSequences();
635
644
 
636
645
  #### createSequenceEmail
637
646
 
638
- Creates a new email template inside a sequence.
647
+ Wraps [`POST /v1/fetch/sequences/:id/emails/templates`](https://docs.bentonow.com/sequences_api#create-sequence-email) so you can add messages to a sequence via code. Pass the sequence prefix ID (e.g., `sequence_abc123`) plus the subject/HTML and any optional delay/snippet/editor fields.
639
648
 
640
649
  ```javascript
641
- const createdTemplate = await bento.V1.Sequences.createSequenceEmail('sequence_abc123', {
650
+ const createdTemplate = await analytics.V1.Sequences.createSequenceEmail('sequence_abc123', {
642
651
  subject: 'Welcome to Bento',
643
652
  html: '<p>Hello {{ visitor.first_name }}</p>',
644
653
  delay_interval: 'days',
645
654
  delay_interval_count: 7,
646
655
  inbox_snippet: 'Welcome to the sequence',
656
+ editor_choice: 'plain',
657
+ });
658
+ ```
659
+
660
+ #### updateSequenceEmail
661
+
662
+ Sequence emails reuse the Email Templates resource, so updates happen through `analytics.V1.EmailTemplates.updateEmailTemplate` (the same helper documented in the [Email Templates](#email-templates) section). Only `subject` and `html` are patchable today, matching [`PATCH /v1/fetch/emails/templates/:id`](https://docs.bentonow.com/sequences_api#update-sequence-email).
663
+
664
+ ```javascript
665
+ await analytics.V1.EmailTemplates.updateEmailTemplate({
666
+ id: 12345,
667
+ subject: 'Updated subject',
668
+ html: '<h1>Updated HTML</h1>',
647
669
  });
648
670
  ```
649
671
 
650
672
  ### Workflows
651
673
 
652
- Retrieve workflows and their associated email templates.
674
+ Workflows (a.k.a. Flows) are Bento’s automation engine for welcome journeys, abandoned-cart nudges, re-engagement loops, and other event-driven campaigns. The SDK surfaces the public Workflows API so you can inspect every flow (including the embedded email templates and their stats) straight from Node. See the [Workflows API reference](https://docs.bentonow.com/workflows_api#get-workflows) for the canonical response schema.
653
675
 
654
676
  #### getWorkflows
655
677
 
656
- Retrieves all workflows for the site, including their email templates.
678
+ Calls `GET /v1/fetch/workflows` and returns an array of workflows. Pass an optional `page` parameter to paginate through large accounts—the SDK automatically injects your `site_uuid` so you only need to provide the page number.
657
679
 
658
680
  ```javascript
659
- const workflows = await bento.V1.Workflows.getWorkflows();
660
- // Returns:
661
- // [
681
+ import { Analytics } from '@bentonow/bento-node-sdk';
682
+
683
+ const analytics = new Analytics({
684
+ authentication: {
685
+ publishableKey: process.env.BENTO_PUBLISHABLE_KEY,
686
+ secretKey: process.env.BENTO_SECRET_KEY,
687
+ },
688
+ siteUuid: process.env.BENTO_SITE_UUID,
689
+ });
690
+
691
+ const workflows = await analytics.V1.Workflows.getWorkflows({ page: 2 });
692
+ // workflows => [
662
693
  // {
663
- // id: '456',
694
+ // id: 'wf-1',
664
695
  // type: 'workflow',
665
696
  // attributes: {
666
- // name: 'Onboarding Workflow',
697
+ // name: 'Abandoned Cart Recovery',
667
698
  // created_at: '2024-01-01T00:00:00Z',
668
699
  // email_templates: [
669
- // { id: 3, subject: 'Step 1', stats: null },
670
- // { id: 4, subject: 'Step 2', stats: null }
700
+ // { id: 3, subject: 'Reminder #1', stats: { opened: 42, clicked: 10 } },
701
+ // { id: 4, subject: 'Reminder #2', stats: null }
671
702
  // ]
672
703
  // }
673
704
  // }
@@ -676,38 +707,63 @@ const workflows = await bento.V1.Workflows.getWorkflows();
676
707
 
677
708
  ### Email Templates
678
709
 
679
- Retrieve and update email templates used in sequences and workflows.
710
+ Retrieve and update email templates used in sequences and workflows. Both helpers call the public Email Templates API (`GET /v1/fetch/emails/templates/:id` and `PATCH /v1/fetch/emails/templates/:id`), and the SDK automatically injects your `site_uuid` and authentication headers. See the [Email Templates API docs](https://docs.bentonow.com/email_templates_api#get-email-template) for the canonical contract.
680
711
 
681
712
  #### getEmailTemplate
682
713
 
683
- Retrieves a single email template by ID.
714
+ Retrieves a single email template by ID and returns `null` when the Bento API responds with an empty payload. Use this to surface subject lines, HTML, and performance stats inside your own tooling.
684
715
 
685
716
  ```javascript
686
- const template = await bento.V1.EmailTemplates.getEmailTemplate({ id: 123 });
687
- // Returns:
688
- // {
689
- // id: '123',
690
- // type: 'email_template',
691
- // attributes: {
692
- // name: 'Welcome Email',
693
- // subject: 'Welcome to our service!',
694
- // html: '<p>Hello {{ name }}, welcome!</p>',
695
- // created_at: '2024-01-01T00:00:00Z',
696
- // stats: null
697
- // }
698
- // }
717
+ import { Analytics } from '@bentonow/bento-node-sdk';
718
+
719
+ const analytics = new Analytics({
720
+ authentication: {
721
+ publishableKey: process.env.BENTO_PUBLISHABLE_KEY,
722
+ secretKey: process.env.BENTO_SECRET_KEY,
723
+ },
724
+ siteUuid: process.env.BENTO_SITE_UUID,
725
+ });
726
+
727
+ const template = await analytics.V1.EmailTemplates.getEmailTemplate({ id: 123 });
728
+ if (!template) {
729
+ console.log('Template not found');
730
+ } else {
731
+ console.log(template.attributes.subject, template.attributes.stats);
732
+ }
699
733
  ```
700
734
 
701
735
  #### updateEmailTemplate
702
736
 
703
- Updates an email template's subject and/or HTML content.
737
+ Updates an email template's subject and/or HTML content via [`PATCH /v1/fetch/emails/templates/:id`](https://docs.bentonow.com/email_templates_api#update-email-template). Only pass the fields you want to change; omitted fields stay untouched. The helper returns the updated template (`null` if Bento responds empty) and bubbles up standard SDK errors such as `NotAuthorizedError`, `RateLimitedError`, or `RequestTimeoutError`.
704
738
 
705
739
  ```javascript
706
- const updatedTemplate = await bento.V1.EmailTemplates.updateEmailTemplate({
707
- id: 123,
708
- subject: 'Updated Subject Line',
709
- html: '<p>Updated HTML content with {{ name }}</p>',
740
+ import { Analytics, NotAuthorizedError } from '@bentonow/bento-node-sdk';
741
+
742
+ const analytics = new Analytics({
743
+ authentication: {
744
+ publishableKey: process.env.BENTO_PUBLISHABLE_KEY,
745
+ secretKey: process.env.BENTO_SECRET_KEY,
746
+ },
747
+ siteUuid: process.env.BENTO_SITE_UUID,
710
748
  });
749
+
750
+ try {
751
+ const updatedTemplate = await analytics.V1.EmailTemplates.updateEmailTemplate({
752
+ id: 123,
753
+ subject: 'Updated Subject Line',
754
+ html: '<p>Updated HTML content with {{ name }}</p>',
755
+ });
756
+
757
+ if (updatedTemplate) {
758
+ console.log(updatedTemplate.attributes.subject);
759
+ }
760
+ } catch (error) {
761
+ if (error instanceof NotAuthorizedError) {
762
+ console.error('Check your Bento credentials or site permissions.');
763
+ } else {
764
+ throw error;
765
+ }
766
+ }
711
767
  ```
712
768
 
713
769
  For detailed information on each module, refer to the [SDK Documentation](https://docs.bentonow.com/subscribers).
package/dist/index.js CHANGED
@@ -1,570 +1,3 @@
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);
18
-
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
- });
567
-
568
1
  // src/sdk/batch/errors.ts
569
2
  class TooFewSubscribersError extends Error {
570
3
  constructor(message = "Too few subscribers") {
@@ -654,9 +87,6 @@ class BentoBatch {
654
87
  return result.results;
655
88
  }
656
89
  }
657
- // src/sdk/client/index.ts
658
- var import_cross_fetch = __toESM(require_browser_ponyfill(), 1);
659
-
660
90
  // src/sdk/client/errors.ts
661
91
  class NotAuthorizedError extends Error {
662
92
  constructor(message = "Not authorized") {
@@ -759,12 +189,12 @@ class BentoClient {
759
189
  }
760
190
  async _fetchWithTimeout(url, options, timeout) {
761
191
  if (timeout === null) {
762
- return import_cross_fetch.default(url, options);
192
+ return fetch(url, options);
763
193
  }
764
194
  const controller = new AbortController;
765
195
  const timeoutId = setTimeout(() => controller.abort(), timeout);
766
196
  try {
767
- const response = await import_cross_fetch.default(url, {
197
+ const response = await fetch(url, {
768
198
  ...options,
769
199
  signal: controller.signal
770
200
  });
@@ -809,6 +239,8 @@ class BentoClient {
809
239
  };
810
240
  const queryParameters = new URLSearchParams;
811
241
  for (const [key, value] of Object.entries(body)) {
242
+ if (value === undefined || value === null)
243
+ continue;
812
244
  queryParameters.append(key, String(value));
813
245
  }
814
246
  return queryParameters.toString();
@@ -1061,8 +493,8 @@ class BentoSequences {
1061
493
  constructor(_client) {
1062
494
  this._client = _client;
1063
495
  }
1064
- async getSequences() {
1065
- const result = await this._client.get(this._url);
496
+ async getSequences(parameters = {}) {
497
+ const result = await this._client.get(this._url, parameters);
1066
498
  if (!result || Object.keys(result).length === 0)
1067
499
  return [];
1068
500
  return result.data ?? [];
@@ -1127,8 +559,8 @@ class BentoWorkflows {
1127
559
  constructor(_client) {
1128
560
  this._client = _client;
1129
561
  }
1130
- async getWorkflows() {
1131
- const result = await this._client.get(this._url);
562
+ async getWorkflows(parameters = {}) {
563
+ const result = await this._client.get(this._url, parameters);
1132
564
  if (!result || Object.keys(result).length === 0)
1133
565
  return [];
1134
566
  return result.data ?? [];
@@ -1,6 +1,6 @@
1
1
  import type { BentoClient } from '../client';
2
2
  import type { EmailTemplate } from '../email-templates/types';
3
- import type { CreateSequenceEmailParameters, Sequence } from './types';
3
+ import type { CreateSequenceEmailParameters, GetSequencesParameters, Sequence } from './types';
4
4
  export declare class BentoSequences {
5
5
  private readonly _client;
6
6
  private readonly _url;
@@ -8,9 +8,10 @@ export declare class BentoSequences {
8
8
  /**
9
9
  * Returns all of the sequences for the site, including their email templates.
10
10
  *
11
+ * @param parameters Optional pagination parameters (e.g., { page: 2 })
11
12
  * @returns Promise\<Sequence[]\>
12
13
  */
13
- getSequences(): Promise<Sequence[]>;
14
+ getSequences(parameters?: GetSequencesParameters): Promise<Sequence[]>;
14
15
  /**
15
16
  * Creates a new email template inside a sequence.
16
17
  *
@@ -18,6 +18,9 @@ export type SequenceAttributes = {
18
18
  };
19
19
  export type Sequence = BaseEntity<SequenceAttributes>;
20
20
  export type SequenceDelayInterval = 'minutes' | 'hours' | 'days' | 'months';
21
+ export type GetSequencesParameters = {
22
+ page?: number;
23
+ };
21
24
  export type CreateSequenceEmailParameters = {
22
25
  subject: string;
23
26
  html: string;
@@ -1,5 +1,5 @@
1
1
  import type { BentoClient } from '../client';
2
- import type { Workflow } from './types';
2
+ import type { GetWorkflowsParameters, Workflow } from './types';
3
3
  export declare class BentoWorkflows {
4
4
  private readonly _client;
5
5
  private readonly _url;
@@ -7,7 +7,8 @@ export declare class BentoWorkflows {
7
7
  /**
8
8
  * Returns all of the workflows for the site, including their email templates.
9
9
  *
10
+ * @param parameters Optional pagination parameters (e.g., { page: 2 })
10
11
  * @returns Promise\<Workflow[]\>
11
12
  */
12
- getWorkflows(): Promise<Workflow[]>;
13
+ getWorkflows(parameters?: GetWorkflowsParameters): Promise<Workflow[]>;
13
14
  }
@@ -12,7 +12,11 @@ export type WorkflowEmailTemplate = {
12
12
  */
13
13
  export type WorkflowAttributes = {
14
14
  name: string;
15
+ status: 'live' | 'draft';
15
16
  created_at: string;
16
17
  email_templates: WorkflowEmailTemplate[];
17
18
  };
18
19
  export type Workflow = BaseEntity<WorkflowAttributes>;
20
+ export type GetWorkflowsParameters = {
21
+ page?: number;
22
+ };
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@bentonow/bento-node-sdk",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "🍱 Bento Node.JS SDK and tracking library",
5
5
  "author": "Backpack Internet",
6
6
  "license": "MIT",
7
+ "type": "module",
7
8
  "main": "dist/index.js",
8
9
  "module": "dist/index.js",
9
10
  "types": "dist/index.d.ts",
@@ -46,9 +47,7 @@
46
47
  "ts-jest": "^29.4.6",
47
48
  "typescript": "^5.7.3"
48
49
  },
49
- "dependencies": {
50
- "cross-fetch": "^4.1.0"
51
- },
50
+ "dependencies": {},
52
51
  "size-limit": [
53
52
  {
54
53
  "path": "dist/index.js",
@@ -1,4 +1,3 @@
1
- import fetch from 'cross-fetch';
2
1
  import type { AnalyticsOptions, AuthenticationOptions } from '../interfaces';
3
2
  import {
4
3
  NotAuthorizedError,
@@ -255,6 +254,7 @@ export class BentoClient {
255
254
 
256
255
  const queryParameters = new URLSearchParams();
257
256
  for (const [key, value] of Object.entries(body)) {
257
+ if (value === undefined || value === null) continue;
258
258
  queryParameters.append(key, String(value));
259
259
  }
260
260
 
@@ -1,7 +1,7 @@
1
1
  import type { BentoClient } from '../client';
2
2
  import type { DataResponse } from '../client/types';
3
3
  import type { EmailTemplate } from '../email-templates/types';
4
- import type { CreateSequenceEmailParameters, Sequence } from './types';
4
+ import type { CreateSequenceEmailParameters, GetSequencesParameters, Sequence } from './types';
5
5
 
6
6
  export class BentoSequences {
7
7
  private readonly _url = '/fetch/sequences';
@@ -11,10 +11,11 @@ export class BentoSequences {
11
11
  /**
12
12
  * Returns all of the sequences for the site, including their email templates.
13
13
  *
14
+ * @param parameters Optional pagination parameters (e.g., { page: 2 })
14
15
  * @returns Promise\<Sequence[]\>
15
16
  */
16
- public async getSequences(): Promise<Sequence[]> {
17
- const result = await this._client.get<DataResponse<Sequence[]>>(this._url);
17
+ public async getSequences(parameters: GetSequencesParameters = {}): Promise<Sequence[]> {
18
+ const result = await this._client.get<DataResponse<Sequence[]>>(this._url, parameters);
18
19
 
19
20
  if (!result || Object.keys(result).length === 0) return [];
20
21
  return result.data ?? [];
@@ -23,6 +23,10 @@ export type Sequence = BaseEntity<SequenceAttributes>;
23
23
 
24
24
  export type SequenceDelayInterval = 'minutes' | 'hours' | 'days' | 'months';
25
25
 
26
+ export type GetSequencesParameters = {
27
+ page?: number;
28
+ };
29
+
26
30
  export type CreateSequenceEmailParameters = {
27
31
  subject: string;
28
32
  html: string;
@@ -1,6 +1,6 @@
1
1
  import type { BentoClient } from '../client';
2
2
  import type { DataResponse } from '../client/types';
3
- import type { Workflow } from './types';
3
+ import type { GetWorkflowsParameters, Workflow } from './types';
4
4
 
5
5
  export class BentoWorkflows {
6
6
  private readonly _url = '/fetch/workflows';
@@ -10,10 +10,11 @@ export class BentoWorkflows {
10
10
  /**
11
11
  * Returns all of the workflows for the site, including their email templates.
12
12
  *
13
+ * @param parameters Optional pagination parameters (e.g., { page: 2 })
13
14
  * @returns Promise\<Workflow[]\>
14
15
  */
15
- public async getWorkflows(): Promise<Workflow[]> {
16
- const result = await this._client.get<DataResponse<Workflow[]>>(this._url);
16
+ public async getWorkflows(parameters: GetWorkflowsParameters = {}): Promise<Workflow[]> {
17
+ const result = await this._client.get<DataResponse<Workflow[]>>(this._url, parameters);
17
18
 
18
19
  if (!result || Object.keys(result).length === 0) return [];
19
20
  return result.data ?? [];
@@ -14,8 +14,13 @@ export type WorkflowEmailTemplate = {
14
14
  */
15
15
  export type WorkflowAttributes = {
16
16
  name: string;
17
+ status: 'live' | 'draft';
17
18
  created_at: string;
18
19
  email_templates: WorkflowEmailTemplate[];
19
20
  };
20
21
 
21
22
  export type Workflow = BaseEntity<WorkflowAttributes>;
23
+
24
+ export type GetWorkflowsParameters = {
25
+ page?: number;
26
+ };