@bentonow/bento-node-sdk 1.0.5 → 1.0.7

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
  // }
@@ -633,27 +642,63 @@ const sequences = await bento.V1.Sequences.getSequences();
633
642
  // ]
634
643
  ```
635
644
 
645
+ #### createSequenceEmail
646
+
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.
648
+
649
+ ```javascript
650
+ const createdTemplate = await analytics.V1.Sequences.createSequenceEmail('sequence_abc123', {
651
+ subject: 'Welcome to Bento',
652
+ html: '<p>Hello {{ visitor.first_name }}</p>',
653
+ delay_interval: 'days',
654
+ delay_interval_count: 7,
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>',
669
+ });
670
+ ```
671
+
636
672
  ### Workflows
637
673
 
638
- 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.
639
675
 
640
676
  #### getWorkflows
641
677
 
642
- 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.
643
679
 
644
680
  ```javascript
645
- const workflows = await bento.V1.Workflows.getWorkflows();
646
- // Returns:
647
- // [
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 => [
648
693
  // {
649
- // id: '456',
694
+ // id: 'wf-1',
650
695
  // type: 'workflow',
651
696
  // attributes: {
652
- // name: 'Onboarding Workflow',
697
+ // name: 'Abandoned Cart Recovery',
653
698
  // created_at: '2024-01-01T00:00:00Z',
654
699
  // email_templates: [
655
- // { id: 3, subject: 'Step 1', stats: null },
656
- // { 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 }
657
702
  // ]
658
703
  // }
659
704
  // }
@@ -662,38 +707,63 @@ const workflows = await bento.V1.Workflows.getWorkflows();
662
707
 
663
708
  ### Email Templates
664
709
 
665
- 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.
666
711
 
667
712
  #### getEmailTemplate
668
713
 
669
- 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.
670
715
 
671
716
  ```javascript
672
- const template = await bento.V1.EmailTemplates.getEmailTemplate({ id: 123 });
673
- // Returns:
674
- // {
675
- // id: '123',
676
- // type: 'email_template',
677
- // attributes: {
678
- // name: 'Welcome Email',
679
- // subject: 'Welcome to our service!',
680
- // html: '<p>Hello {{ name }}, welcome!</p>',
681
- // created_at: '2024-01-01T00:00:00Z',
682
- // stats: null
683
- // }
684
- // }
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
+ }
685
733
  ```
686
734
 
687
735
  #### updateEmailTemplate
688
736
 
689
- 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`.
690
738
 
691
739
  ```javascript
692
- const updatedTemplate = await bento.V1.EmailTemplates.updateEmailTemplate({
693
- id: 123,
694
- subject: 'Updated Subject Line',
695
- 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,
696
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
+ }
697
767
  ```
698
768
 
699
769
  For detailed information on each module, refer to the [SDK Documentation](https://docs.bentonow.com/subscribers).
package/dist/index.js CHANGED
@@ -809,6 +809,8 @@ class BentoClient {
809
809
  };
810
810
  const queryParameters = new URLSearchParams;
811
811
  for (const [key, value] of Object.entries(body)) {
812
+ if (value === undefined || value === null)
813
+ continue;
812
814
  queryParameters.append(key, String(value));
813
815
  }
814
816
  return queryParameters.toString();
@@ -1061,12 +1063,20 @@ class BentoSequences {
1061
1063
  constructor(_client) {
1062
1064
  this._client = _client;
1063
1065
  }
1064
- async getSequences() {
1065
- const result = await this._client.get(this._url);
1066
+ async getSequences(parameters = {}) {
1067
+ const result = await this._client.get(this._url, parameters);
1066
1068
  if (!result || Object.keys(result).length === 0)
1067
1069
  return [];
1068
1070
  return result.data ?? [];
1069
1071
  }
1072
+ async createSequenceEmail(sequenceId, parameters) {
1073
+ const result = await this._client.post(`${this._url}/${sequenceId}/emails/templates`, {
1074
+ email_template: parameters
1075
+ });
1076
+ if (Object.keys(result).length === 0 || !result.data)
1077
+ return null;
1078
+ return result.data;
1079
+ }
1070
1080
  }
1071
1081
  // src/sdk/subscribers/index.ts
1072
1082
  class BentoSubscribers {
@@ -1119,8 +1129,8 @@ class BentoWorkflows {
1119
1129
  constructor(_client) {
1120
1130
  this._client = _client;
1121
1131
  }
1122
- async getWorkflows() {
1123
- const result = await this._client.get(this._url);
1132
+ async getWorkflows(parameters = {}) {
1133
+ const result = await this._client.get(this._url, parameters);
1124
1134
  if (!result || Object.keys(result).length === 0)
1125
1135
  return [];
1126
1136
  return result.data ?? [];
@@ -1,5 +1,6 @@
1
1
  import type { BentoClient } from '../client';
2
- import type { Sequence } from './types';
2
+ import type { EmailTemplate } from '../email-templates/types';
3
+ import type { CreateSequenceEmailParameters, GetSequencesParameters, Sequence } from './types';
3
4
  export declare class BentoSequences {
4
5
  private readonly _client;
5
6
  private readonly _url;
@@ -7,7 +8,16 @@ export declare class BentoSequences {
7
8
  /**
8
9
  * Returns all of the sequences for the site, including their email templates.
9
10
  *
11
+ * @param parameters Optional pagination parameters (e.g., { page: 2 })
10
12
  * @returns Promise\<Sequence[]\>
11
13
  */
12
- getSequences(): Promise<Sequence[]>;
14
+ getSequences(parameters?: GetSequencesParameters): Promise<Sequence[]>;
15
+ /**
16
+ * Creates a new email template inside a sequence.
17
+ *
18
+ * @param sequenceId string
19
+ * @param parameters CreateSequenceEmailParameters
20
+ * @returns Promise\<EmailTemplate | null\>
21
+ */
22
+ createSequenceEmail(sequenceId: string, parameters: CreateSequenceEmailParameters): Promise<EmailTemplate | null>;
13
23
  }
@@ -1,4 +1,5 @@
1
1
  import type { BaseEntity } from '../types';
2
+ import type { EmailTemplate } from '../email-templates/types';
2
3
  /**
3
4
  * Embedded Email Template in Sequence
4
5
  */
@@ -16,3 +17,19 @@ export type SequenceAttributes = {
16
17
  email_templates: SequenceEmailTemplate[];
17
18
  };
18
19
  export type Sequence = BaseEntity<SequenceAttributes>;
20
+ export type SequenceDelayInterval = 'minutes' | 'hours' | 'days' | 'months';
21
+ export type GetSequencesParameters = {
22
+ page?: number;
23
+ };
24
+ export type CreateSequenceEmailParameters = {
25
+ subject: string;
26
+ html: string;
27
+ inbox_snippet?: string;
28
+ delay_interval?: SequenceDelayInterval;
29
+ delay_interval_count?: number;
30
+ editor_choice?: string;
31
+ cc?: string;
32
+ bcc?: string;
33
+ to?: string;
34
+ };
35
+ export type CreateSequenceEmailResponse = EmailTemplate | null;
@@ -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
  }
@@ -16,3 +16,6 @@ export type WorkflowAttributes = {
16
16
  email_templates: WorkflowEmailTemplate[];
17
17
  };
18
18
  export type Workflow = BaseEntity<WorkflowAttributes>;
19
+ export type GetWorkflowsParameters = {
20
+ page?: number;
21
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bentonow/bento-node-sdk",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "🍱 Bento Node.JS SDK and tracking library",
5
5
  "author": "Backpack Internet",
6
6
  "license": "MIT",
@@ -34,14 +34,17 @@
34
34
  "homepage": "https://bentonow.com",
35
35
  "devDependencies": {
36
36
  "@size-limit/preset-small-lib": "^11.1.5",
37
+ "@types/jest": "^30.0.0",
37
38
  "@types/node": "^22.10.5",
38
39
  "@typescript-eslint/eslint-plugin": "^8.19.1",
39
40
  "@typescript-eslint/parser": "^8.24.0",
40
41
  "bun-types": "latest",
41
42
  "eslint": "^9.20.1",
43
+ "jest": "^30.2.0",
42
44
  "prettier": "^3.4.2",
43
45
  "size-limit": "^11.1.6",
44
- "typescript": "^5.7.2"
46
+ "ts-jest": "^29.4.6",
47
+ "typescript": "^5.7.3"
45
48
  },
46
49
  "dependencies": {
47
50
  "cross-fetch": "^4.1.0"
@@ -255,6 +255,7 @@ export class BentoClient {
255
255
 
256
256
  const queryParameters = new URLSearchParams();
257
257
  for (const [key, value] of Object.entries(body)) {
258
+ if (value === undefined || value === null) continue;
258
259
  queryParameters.append(key, String(value));
259
260
  }
260
261
 
@@ -1,6 +1,7 @@
1
1
  import type { BentoClient } from '../client';
2
2
  import type { DataResponse } from '../client/types';
3
- import type { Sequence } from './types';
3
+ import type { EmailTemplate } from '../email-templates/types';
4
+ import type { CreateSequenceEmailParameters, GetSequencesParameters, Sequence } from './types';
4
5
 
5
6
  export class BentoSequences {
6
7
  private readonly _url = '/fetch/sequences';
@@ -10,12 +11,35 @@ export class BentoSequences {
10
11
  /**
11
12
  * Returns all of the sequences for the site, including their email templates.
12
13
  *
14
+ * @param parameters Optional pagination parameters (e.g., { page: 2 })
13
15
  * @returns Promise\<Sequence[]\>
14
16
  */
15
- public async getSequences(): Promise<Sequence[]> {
16
- 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);
17
19
 
18
20
  if (!result || Object.keys(result).length === 0) return [];
19
21
  return result.data ?? [];
20
22
  }
23
+
24
+ /**
25
+ * Creates a new email template inside a sequence.
26
+ *
27
+ * @param sequenceId string
28
+ * @param parameters CreateSequenceEmailParameters
29
+ * @returns Promise\<EmailTemplate | null\>
30
+ */
31
+ public async createSequenceEmail(
32
+ sequenceId: string,
33
+ parameters: CreateSequenceEmailParameters
34
+ ): Promise<EmailTemplate | null> {
35
+ const result = await this._client.post<DataResponse<EmailTemplate>>(
36
+ `${this._url}/${sequenceId}/emails/templates`,
37
+ {
38
+ email_template: parameters,
39
+ }
40
+ );
41
+
42
+ if (Object.keys(result).length === 0 || !result.data) return null;
43
+ return result.data;
44
+ }
21
45
  }
@@ -1,4 +1,5 @@
1
1
  import type { BaseEntity } from '../types';
2
+ import type { EmailTemplate } from '../email-templates/types';
2
3
 
3
4
  /**
4
5
  * Embedded Email Template in Sequence
@@ -19,3 +20,23 @@ export type SequenceAttributes = {
19
20
  };
20
21
 
21
22
  export type Sequence = BaseEntity<SequenceAttributes>;
23
+
24
+ export type SequenceDelayInterval = 'minutes' | 'hours' | 'days' | 'months';
25
+
26
+ export type GetSequencesParameters = {
27
+ page?: number;
28
+ };
29
+
30
+ export type CreateSequenceEmailParameters = {
31
+ subject: string;
32
+ html: string;
33
+ inbox_snippet?: string;
34
+ delay_interval?: SequenceDelayInterval;
35
+ delay_interval_count?: number;
36
+ editor_choice?: string;
37
+ cc?: string;
38
+ bcc?: string;
39
+ to?: string;
40
+ };
41
+
42
+ export type CreateSequenceEmailResponse = EmailTemplate | null;
@@ -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 ?? [];
@@ -19,3 +19,7 @@ export type WorkflowAttributes = {
19
19
  };
20
20
 
21
21
  export type Workflow = BaseEntity<WorkflowAttributes>;
22
+
23
+ export type GetWorkflowsParameters = {
24
+ page?: number;
25
+ };