@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
|
@@ -1,132 +1,164 @@
|
|
|
1
|
-
import { BentoBatch, BentoCommands, BentoExperimental, BentoFields, BentoForms, BentoSubscribers, BentoTags } from '../../sdk';
|
|
2
|
-
import type { AnalyticsOptions } from '../../sdk/interfaces';
|
|
3
|
-
import type { AddSubscriberParameters, RemoveSubscriberParameters, TagSubscriberParameters, TrackParameters, TrackPurchaseParameters, UpdateFieldsParameters } from './types';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
readonly
|
|
11
|
-
readonly
|
|
12
|
-
readonly
|
|
13
|
-
readonly
|
|
14
|
-
readonly
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
*
|
|
36
|
-
* `
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
*
|
|
57
|
-
* `
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
*
|
|
77
|
-
* `
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
1
|
+
import { BentoBatch, BentoCommands, BentoEmailTemplates, BentoExperimental, BentoFields, BentoForms, BentoSequences, BentoSubscribers, BentoTags, BentoWorkflows } from '../../sdk';
|
|
2
|
+
import type { AnalyticsOptions } from '../../sdk/interfaces';
|
|
3
|
+
import type { AddSubscriberParameters, RemoveSubscriberParameters, TagSubscriberParameters, TrackParameters, TrackPurchaseParameters, UpdateFieldsParameters } from './types';
|
|
4
|
+
import { BentoBroadcasts } from '../../sdk/broadcasts';
|
|
5
|
+
import { BentoStats } from '../../sdk/stats';
|
|
6
|
+
import { Subscriber } from '../../sdk/subscribers/types';
|
|
7
|
+
export declare class BentoAPIV1<S = {
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}, E extends string = '$custom'> {
|
|
10
|
+
private readonly _client;
|
|
11
|
+
readonly Broadcasts: BentoBroadcasts;
|
|
12
|
+
readonly EmailTemplates: BentoEmailTemplates;
|
|
13
|
+
readonly Stats: BentoStats;
|
|
14
|
+
readonly Batch: BentoBatch<S, E>;
|
|
15
|
+
readonly Commands: BentoCommands<S>;
|
|
16
|
+
readonly Experimental: BentoExperimental;
|
|
17
|
+
readonly Fields: BentoFields;
|
|
18
|
+
readonly Forms: BentoForms;
|
|
19
|
+
readonly Sequences: BentoSequences;
|
|
20
|
+
readonly Subscribers: BentoSubscribers<S>;
|
|
21
|
+
readonly Tags: BentoTags;
|
|
22
|
+
readonly Workflows: BentoWorkflows;
|
|
23
|
+
constructor(options: AnalyticsOptions);
|
|
24
|
+
/**
|
|
25
|
+
* **This TRIGGERS automations!** - If you do not wish to trigger automations, please use the
|
|
26
|
+
* `Commands.addTag` method.
|
|
27
|
+
*
|
|
28
|
+
* Tags a subscriber with the specified email and tag. If either the tag or the user
|
|
29
|
+
* do not exist, they will be created in the system. If the user already has the tag,
|
|
30
|
+
* another tag event will be sent, triggering any automations that take place upon a
|
|
31
|
+
* tag being added to a subscriber. Please be aware of the potential consequences.
|
|
32
|
+
*
|
|
33
|
+
* Because this method uses the batch API, the tag may take between 1 and 3 minutes
|
|
34
|
+
* to appear in the system.
|
|
35
|
+
*
|
|
36
|
+
* Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
|
|
37
|
+
*
|
|
38
|
+
* @param parameters TagSubscriberParameters
|
|
39
|
+
* @returns Promise\<boolean\>
|
|
40
|
+
*/
|
|
41
|
+
tagSubscriber(parameters: TagSubscriberParameters): Promise<boolean>;
|
|
42
|
+
/**
|
|
43
|
+
* **This TRIGGERS automations!** - If you do not wish to trigger automations, please use the
|
|
44
|
+
* `Commands.subscribe` method.
|
|
45
|
+
*
|
|
46
|
+
* Creates a subscriber in the system. If the subscriber already exists, another subscribe event
|
|
47
|
+
* will be sent, triggering any automations that take place upon subscription. Please be aware
|
|
48
|
+
* of the potential consequences.
|
|
49
|
+
*
|
|
50
|
+
* You may optionally pass any fields that you wish to be set on the subscriber during creation
|
|
51
|
+
* as well as a `Date` which will backdate the event. If no date is supplied, then the event will
|
|
52
|
+
* default to the current time.
|
|
53
|
+
*
|
|
54
|
+
* Because this method uses the batch API, the tag may take between 1 and 3 minutes
|
|
55
|
+
* to appear in the system.
|
|
56
|
+
*
|
|
57
|
+
* Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
|
|
58
|
+
*
|
|
59
|
+
* @param parameters AddSubscriberParameters
|
|
60
|
+
* @returns Promise\<boolean\>
|
|
61
|
+
*/
|
|
62
|
+
addSubscriber(parameters: AddSubscriberParameters<S>): Promise<boolean>;
|
|
63
|
+
/**
|
|
64
|
+
* **This TRIGGERS automations!** - If you do not wish to trigger automations, please use the
|
|
65
|
+
* `Commands.unsubscribe` method.
|
|
66
|
+
*
|
|
67
|
+
* Unsubscribes an email in the system. If the email is already unsubscribed, another unsubscribe event
|
|
68
|
+
* will be sent, triggering any automations that take place upon an unsubscribe happening. Please be aware
|
|
69
|
+
* of the potential consequences.
|
|
70
|
+
*
|
|
71
|
+
* You may optionally pass a `Date` which will backdate the event. If no date is supplied, then the event
|
|
72
|
+
* will default to the current time.
|
|
73
|
+
*
|
|
74
|
+
* Because this method uses the batch API, the tag may take between 1 and 3 minutes
|
|
75
|
+
* to appear in the system.
|
|
76
|
+
*
|
|
77
|
+
* Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
|
|
78
|
+
*
|
|
79
|
+
* @param parameters RemoveSubscriberParameters
|
|
80
|
+
* @returns Promise\<boolean\>
|
|
81
|
+
*/
|
|
82
|
+
removeSubscriber(parameters: RemoveSubscriberParameters): Promise<boolean>;
|
|
83
|
+
/**
|
|
84
|
+
* **This TRIGGERS automations!** - If you do not wish to trigger automations, please use the
|
|
85
|
+
* `Commands.addField` method.
|
|
86
|
+
*
|
|
87
|
+
* Sets the passed-in custom fields on the subscriber, creating the subscriber if it does not exist.
|
|
88
|
+
* If the fields are already set on the subscriber, the event will be sent, triggering any automations
|
|
89
|
+
* that take place upon fields being updated. Please be aware of the potential consequences.
|
|
90
|
+
*
|
|
91
|
+
* You may optionally pass a `Date` which will backdate the event. If no date is supplied, then the event
|
|
92
|
+
* will default to the current time.
|
|
93
|
+
*
|
|
94
|
+
* Because this method uses the batch API, the tag may take between 1 and 3 minutes
|
|
95
|
+
* to appear in the system.
|
|
96
|
+
*
|
|
97
|
+
* Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
|
|
98
|
+
*
|
|
99
|
+
* @param parameters UpdateFieldsParameters\<S\>
|
|
100
|
+
* @returns Promise\<boolean\>
|
|
101
|
+
*/
|
|
102
|
+
updateFields(parameters: UpdateFieldsParameters<S>): Promise<boolean>;
|
|
103
|
+
/**
|
|
104
|
+
* **This TRIGGERS automations!** - There is no way to achieve this same behavior without triggering
|
|
105
|
+
* automations.
|
|
106
|
+
*
|
|
107
|
+
* Tracks a purchase in Bento, used to calculate LTV for your subscribers. The values that are received
|
|
108
|
+
* should be numbers, in cents. For example, `$1.00` should be `100`.
|
|
109
|
+
*
|
|
110
|
+
* You may optionally pass a `Date` which will backdate the event. If no date is supplied, then the event
|
|
111
|
+
* will default to the current time.
|
|
112
|
+
*
|
|
113
|
+
* Because this method uses the batch API, the tag may take between 1 and 3 minutes
|
|
114
|
+
* to appear in the system.
|
|
115
|
+
*
|
|
116
|
+
* Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
|
|
117
|
+
*
|
|
118
|
+
* @param parameters TrackPurchaseParameters
|
|
119
|
+
* @returns Promise\<boolean\>
|
|
120
|
+
*/
|
|
121
|
+
trackPurchase(parameters: TrackPurchaseParameters): Promise<boolean>;
|
|
122
|
+
/**
|
|
123
|
+
* **This TRIGGERS automations!** - There is no way to achieve this same behavior without triggering
|
|
124
|
+
* automations.
|
|
125
|
+
*
|
|
126
|
+
* Tracks a custom event in Bento.
|
|
127
|
+
*
|
|
128
|
+
* You may optionally pass a `Date` which will backdate the event. If no date is supplied, then the event
|
|
129
|
+
* will default to the current time.
|
|
130
|
+
*
|
|
131
|
+
* Because this method uses the batch API, the tag may take between 1 and 3 minutes
|
|
132
|
+
* to appear in the system.
|
|
133
|
+
*
|
|
134
|
+
* Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
|
|
135
|
+
*
|
|
136
|
+
* @param parameters TrackParameters<S, E>
|
|
137
|
+
* @returns Promise\<boolean\>
|
|
138
|
+
*/
|
|
139
|
+
track(parameters: TrackParameters<S, E>): Promise<boolean>;
|
|
140
|
+
/**
|
|
141
|
+
* Upserts a subscriber in Bento. If the subscriber exists, their data will be updated.
|
|
142
|
+
* If they don't exist, they will be created with the provided data.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* await analytics.V1.upsertSubscriber({
|
|
147
|
+
* email: 'user@example.com',
|
|
148
|
+
* fields: {
|
|
149
|
+
* firstName: 'John',
|
|
150
|
+
* lastName: 'Doe'
|
|
151
|
+
* },
|
|
152
|
+
* tags: 'lead,mql',
|
|
153
|
+
* remove_tags: 'customer'
|
|
154
|
+
* });
|
|
155
|
+
* ```
|
|
156
|
+
*
|
|
157
|
+
* @param parameters Object containing subscriber data including email, fields, and tags
|
|
158
|
+
* @returns Promise<Subscriber<S>> The created or updated subscriber
|
|
159
|
+
*/
|
|
160
|
+
upsertSubscriber(parameters: Omit<AddSubscriberParameters<S>, 'date'> & {
|
|
161
|
+
tags?: string;
|
|
162
|
+
remove_tags?: string;
|
|
163
|
+
}): Promise<Subscriber<S> | null>;
|
|
164
|
+
}
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import type { BaseEvent, PurchaseDetails } from '../../sdk/batch/events';
|
|
2
|
-
/**
|
|
3
|
-
* API Method Parameter Types
|
|
4
|
-
*/
|
|
5
|
-
export type TagSubscriberParameters = {
|
|
6
|
-
date?: Date;
|
|
7
|
-
email: string;
|
|
8
|
-
tagName: string;
|
|
9
|
-
};
|
|
10
|
-
export type AddSubscriberParameters<S> = {
|
|
11
|
-
date?: Date;
|
|
12
|
-
email: string;
|
|
13
|
-
fields?: Partial<S>;
|
|
14
|
-
};
|
|
15
|
-
export type RemoveSubscriberParameters = {
|
|
16
|
-
date?: Date;
|
|
17
|
-
email: string;
|
|
18
|
-
};
|
|
19
|
-
export type TrackPurchaseParameters = {
|
|
20
|
-
date?: Date;
|
|
21
|
-
email: string;
|
|
22
|
-
purchaseDetails: PurchaseDetails;
|
|
23
|
-
};
|
|
24
|
-
export type UpdateFieldsParameters<S> = {
|
|
25
|
-
date?: Date;
|
|
26
|
-
email: string;
|
|
27
|
-
fields: Partial<S>;
|
|
28
|
-
};
|
|
29
|
-
export type TrackParameters<S, E extends string> = BaseEvent<E> & {
|
|
30
|
-
fields: Partial<S>;
|
|
31
|
-
};
|
|
1
|
+
import type { BaseEvent, PurchaseDetails } from '../../sdk/batch/events';
|
|
2
|
+
/**
|
|
3
|
+
* API Method Parameter Types
|
|
4
|
+
*/
|
|
5
|
+
export type TagSubscriberParameters = {
|
|
6
|
+
date?: Date;
|
|
7
|
+
email: string;
|
|
8
|
+
tagName: string;
|
|
9
|
+
};
|
|
10
|
+
export type AddSubscriberParameters<S> = {
|
|
11
|
+
date?: Date;
|
|
12
|
+
email: string;
|
|
13
|
+
fields?: Partial<S>;
|
|
14
|
+
};
|
|
15
|
+
export type RemoveSubscriberParameters = {
|
|
16
|
+
date?: Date;
|
|
17
|
+
email: string;
|
|
18
|
+
};
|
|
19
|
+
export type TrackPurchaseParameters = {
|
|
20
|
+
date?: Date;
|
|
21
|
+
email: string;
|
|
22
|
+
purchaseDetails: PurchaseDetails;
|
|
23
|
+
};
|
|
24
|
+
export type UpdateFieldsParameters<S> = {
|
|
25
|
+
date?: Date;
|
|
26
|
+
email: string;
|
|
27
|
+
fields: Partial<S>;
|
|
28
|
+
};
|
|
29
|
+
export type TrackParameters<S, E extends string> = BaseEvent<E> & {
|
|
30
|
+
fields: Partial<S>;
|
|
31
|
+
};
|
package/package.json
CHANGED
|
@@ -1,34 +1,29 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
2
|
+
"name": "@bentonow/bento-node-sdk",
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"description": "🍱 Bento Node.JS SDK and tracking library",
|
|
5
|
+
"author": "Backpack Internet",
|
|
3
6
|
"license": "MIT",
|
|
4
7
|
"main": "dist/index.js",
|
|
5
|
-
"
|
|
8
|
+
"module": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
6
10
|
"files": [
|
|
7
11
|
"dist",
|
|
8
12
|
"src"
|
|
9
13
|
],
|
|
10
14
|
"engines": {
|
|
11
|
-
"node": ">=
|
|
15
|
+
"node": ">=18"
|
|
12
16
|
},
|
|
13
17
|
"scripts": {
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"test": "
|
|
17
|
-
"lint": "
|
|
18
|
-
"
|
|
18
|
+
"build": "bun build ./src/index.ts --outdir dist && tsc --emitDeclarationOnly",
|
|
19
|
+
"test": "bun test",
|
|
20
|
+
"test:coverage": "bun test --coverage",
|
|
21
|
+
"lint": "eslint src/**/*.ts",
|
|
22
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
23
|
+
"prepublishOnly": "bun run build",
|
|
19
24
|
"size": "size-limit",
|
|
20
25
|
"analyze": "size-limit --why"
|
|
21
26
|
},
|
|
22
|
-
"peerDependencies": {},
|
|
23
|
-
"husky": {
|
|
24
|
-
"hooks": {
|
|
25
|
-
"pre-commit": "tsdx lint"
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
"name": "@bentonow/bento-node-sdk",
|
|
29
|
-
"author": "Backpack Internet",
|
|
30
|
-
"module": "dist/bento-node-sdk.esm.js",
|
|
31
|
-
"description": "🍱 Bento Node.JS SDK and tracking library",
|
|
32
27
|
"repository": {
|
|
33
28
|
"type": "git",
|
|
34
29
|
"url": "git://github.com/bentonow/bento-node-sdk.git"
|
|
@@ -37,32 +32,24 @@
|
|
|
37
32
|
"url": "https://github.com/bentonow/bento-node-sdk/issues"
|
|
38
33
|
},
|
|
39
34
|
"homepage": "https://bentonow.com",
|
|
40
|
-
"size-limit": [
|
|
41
|
-
{
|
|
42
|
-
"path": "dist/bento-node-sdk.cjs.production.min.js",
|
|
43
|
-
"limit": "10 KB"
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
"path": "dist/bento-node-sdk.esm.js",
|
|
47
|
-
"limit": "10 KB"
|
|
48
|
-
}
|
|
49
|
-
],
|
|
50
35
|
"devDependencies": {
|
|
51
|
-
"@size-limit/preset-small-lib": "^
|
|
52
|
-
"@types/
|
|
53
|
-
"@
|
|
54
|
-
"@typescript-eslint/
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"prettier": "^2.7.1",
|
|
61
|
-
"size-limit": "^5.0.3",
|
|
62
|
-
"tslib": "^2.3.1",
|
|
63
|
-
"typescript": "^4.3.5"
|
|
36
|
+
"@size-limit/preset-small-lib": "^11.1.5",
|
|
37
|
+
"@types/node": "^22.10.5",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^8.19.1",
|
|
39
|
+
"@typescript-eslint/parser": "^8.24.0",
|
|
40
|
+
"bun-types": "latest",
|
|
41
|
+
"eslint": "^9.20.1",
|
|
42
|
+
"prettier": "^3.4.2",
|
|
43
|
+
"size-limit": "^11.1.6",
|
|
44
|
+
"typescript": "^5.7.2"
|
|
64
45
|
},
|
|
65
46
|
"dependencies": {
|
|
66
|
-
"cross-fetch": "^4.
|
|
67
|
-
}
|
|
68
|
-
|
|
47
|
+
"cross-fetch": "^4.1.0"
|
|
48
|
+
},
|
|
49
|
+
"size-limit": [
|
|
50
|
+
{
|
|
51
|
+
"path": "dist/index.js",
|
|
52
|
+
"limit": "15 KB"
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
}
|
package/src/sdk/batch/events.ts
CHANGED
package/src/sdk/batch/index.ts
CHANGED
|
@@ -41,19 +41,13 @@ export class BentoBatch<S, E extends string> {
|
|
|
41
41
|
* @param parameters
|
|
42
42
|
* @returns Promise\<number\>
|
|
43
43
|
*/
|
|
44
|
-
public async importSubscribers(
|
|
45
|
-
parameters: BatchImportSubscribersParameter<S>
|
|
46
|
-
): Promise<number> {
|
|
44
|
+
public async importSubscribers(parameters: BatchImportSubscribersParameter<S>): Promise<number> {
|
|
47
45
|
if (parameters.subscribers.length === 0) {
|
|
48
|
-
throw new TooFewSubscribersError(
|
|
49
|
-
`You must send between 1 and 1,000 subscribers.`
|
|
50
|
-
);
|
|
46
|
+
throw new TooFewSubscribersError(`You must send between 1 and 1,000 subscribers.`);
|
|
51
47
|
}
|
|
52
48
|
|
|
53
49
|
if (parameters.subscribers.length > this._maxBatchSize) {
|
|
54
|
-
throw new TooManySubscribersError(
|
|
55
|
-
`You must send between 1 and 1,000 subscribers.`
|
|
56
|
-
);
|
|
50
|
+
throw new TooManySubscribersError(`You must send between 1 and 1,000 subscribers.`);
|
|
57
51
|
}
|
|
58
52
|
|
|
59
53
|
const result = await this._client.post<BatchImportSubscribersResponse>(
|
|
@@ -77,9 +71,7 @@ export class BentoBatch<S, E extends string> {
|
|
|
77
71
|
* @param parameters
|
|
78
72
|
* @returns Promise\<number\>
|
|
79
73
|
*/
|
|
80
|
-
public async importEvents(
|
|
81
|
-
parameters: BatchImportEventsParameter<S, E>
|
|
82
|
-
): Promise<number> {
|
|
74
|
+
public async importEvents(parameters: BatchImportEventsParameter<S, E>): Promise<number> {
|
|
83
75
|
if (parameters.events.length === 0) {
|
|
84
76
|
throw new TooFewEventsError(`You must send between 1 and 1,000 events.`);
|
|
85
77
|
}
|
|
@@ -88,12 +80,9 @@ export class BentoBatch<S, E extends string> {
|
|
|
88
80
|
throw new TooManyEventsError(`You must send between 1 and 1,000 events.`);
|
|
89
81
|
}
|
|
90
82
|
|
|
91
|
-
const result = await this._client.post<BatchImportEventsResponse>(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
events: parameters.events,
|
|
95
|
-
}
|
|
96
|
-
);
|
|
83
|
+
const result = await this._client.post<BatchImportEventsResponse>(`${this._url}/events`, {
|
|
84
|
+
events: parameters.events,
|
|
85
|
+
});
|
|
97
86
|
|
|
98
87
|
return result.results;
|
|
99
88
|
}
|
|
@@ -123,13 +112,12 @@ export class BentoBatch<S, E extends string> {
|
|
|
123
112
|
throw new TooManyEmailsError(`You must send between 1 and 100 emails.`);
|
|
124
113
|
}
|
|
125
114
|
|
|
126
|
-
const result =
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
);
|
|
115
|
+
const result = await this._client.post<BatchsendTransactionalEmailsResponse>(
|
|
116
|
+
`${this._url}/emails`,
|
|
117
|
+
{
|
|
118
|
+
emails: parameters.emails,
|
|
119
|
+
}
|
|
120
|
+
);
|
|
133
121
|
|
|
134
122
|
return result.results;
|
|
135
123
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { BentoClient } from '../client';
|
|
2
|
+
import type { DataResponse } from '../client/types';
|
|
3
|
+
import type { Broadcast, CreateBroadcastInput, EmailData } from './types';
|
|
4
|
+
|
|
5
|
+
export class BentoBroadcasts {
|
|
6
|
+
private readonly _url = '/broadcasts';
|
|
7
|
+
private readonly _emailsUrl = '/emails';
|
|
8
|
+
|
|
9
|
+
constructor(private readonly _client: BentoClient) {}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates transactional emails in batch
|
|
13
|
+
* @param emails Array of email data to send
|
|
14
|
+
* @returns Promise<number> Number of emails successfully created
|
|
15
|
+
*/
|
|
16
|
+
public async createEmails(emails: EmailData[]): Promise<number> {
|
|
17
|
+
const result = await this._client.post<{ results: number }>(this._emailsUrl, {
|
|
18
|
+
emails
|
|
19
|
+
});
|
|
20
|
+
return result.results;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Retrieves all broadcasts for the site
|
|
25
|
+
* @returns Promise<Broadcast[]>
|
|
26
|
+
*/
|
|
27
|
+
public async getBroadcasts(): Promise<Broadcast[]> {
|
|
28
|
+
const result = await this._client.get<DataResponse<Broadcast[]>>(this._url);
|
|
29
|
+
return result.data ?? [];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Creates new broadcast campaigns
|
|
34
|
+
* @param broadcasts Array of broadcast data to create
|
|
35
|
+
* @returns Promise<Broadcast[]>
|
|
36
|
+
*/
|
|
37
|
+
public async createBroadcast(broadcasts: CreateBroadcastInput[]): Promise<Broadcast[]> {
|
|
38
|
+
const result = await this._client.post<DataResponse<Broadcast[]>>(this._url, {
|
|
39
|
+
broadcasts
|
|
40
|
+
});
|
|
41
|
+
return result.data ?? [];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { BaseEntity } from '../types';
|
|
2
|
+
|
|
3
|
+
export type BroadcastType = 'plain' | 'html' | 'markdown';
|
|
4
|
+
|
|
5
|
+
export type ContactData = {
|
|
6
|
+
name: string;
|
|
7
|
+
email: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type BroadcastAttributes = {
|
|
11
|
+
name: string;
|
|
12
|
+
subject: string;
|
|
13
|
+
content: string;
|
|
14
|
+
type: BroadcastType;
|
|
15
|
+
from: ContactData;
|
|
16
|
+
inclusive_tags?: string;
|
|
17
|
+
exclusive_tags?: string;
|
|
18
|
+
segment_id?: string;
|
|
19
|
+
batch_size_per_hour: number;
|
|
20
|
+
created_at: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type Broadcast = BaseEntity<BroadcastAttributes>;
|
|
24
|
+
|
|
25
|
+
export type CreateBroadcastInput = Omit<BroadcastAttributes, 'created_at'>;
|
|
26
|
+
|
|
27
|
+
export type EmailData = {
|
|
28
|
+
to: string;
|
|
29
|
+
from: string;
|
|
30
|
+
subject: string;
|
|
31
|
+
html_body: string;
|
|
32
|
+
transactional: boolean;
|
|
33
|
+
personalizations?: Record<string, string | number | boolean>;
|
|
34
|
+
};
|
package/src/sdk/client/errors.ts
CHANGED
|
@@ -11,3 +11,10 @@ export class RateLimitedError extends Error {
|
|
|
11
11
|
this.name = 'RateLimitedError';
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
+
|
|
15
|
+
export class AuthorNotAuthorizedError extends Error {
|
|
16
|
+
constructor(message = 'Author not authorized to send on this account') {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = 'AuthorNotAuthorizedError';
|
|
19
|
+
}
|
|
20
|
+
}
|