@bentonow/bento-node-sdk 1.0.6 → 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
  // }
@@ -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
@@ -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,8 +1063,8 @@ 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 ?? [];
@@ -1127,8 +1129,8 @@ class BentoWorkflows {
1127
1129
  constructor(_client) {
1128
1130
  this._client = _client;
1129
1131
  }
1130
- async getWorkflows() {
1131
- const result = await this._client.get(this._url);
1132
+ async getWorkflows(parameters = {}) {
1133
+ const result = await this._client.get(this._url, parameters);
1132
1134
  if (!result || Object.keys(result).length === 0)
1133
1135
  return [];
1134
1136
  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
  }
@@ -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.6",
3
+ "version": "1.0.7",
4
4
  "description": "🍱 Bento Node.JS SDK and tracking library",
5
5
  "author": "Backpack Internet",
6
6
  "license": "MIT",
@@ -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,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 ?? [];
@@ -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
+ };