@bentonow/bento-node-sdk 0.2.1 → 1.0.5

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.
Files changed (76) hide show
  1. package/{LICENSE → LICENSE.md} +1 -1
  2. package/README.md +604 -1031
  3. package/dist/index.d.ts +9 -9
  4. package/dist/index.js +1306 -5
  5. package/dist/sdk/batch/enums.d.ts +8 -8
  6. package/dist/sdk/batch/errors.d.ts +18 -18
  7. package/dist/sdk/batch/events.d.ts +71 -71
  8. package/dist/sdk/batch/index.d.ts +55 -55
  9. package/dist/sdk/batch/types.d.ts +37 -37
  10. package/dist/sdk/broadcasts/index.d.ts +26 -0
  11. package/dist/sdk/broadcasts/types.d.ts +32 -0
  12. package/dist/sdk/client/errors.d.ts +12 -6
  13. package/dist/sdk/client/index.d.ts +94 -64
  14. package/dist/sdk/client/types.d.ts +3 -3
  15. package/dist/sdk/commands/enums.d.ts +12 -12
  16. package/dist/sdk/commands/index.d.ts +79 -79
  17. package/dist/sdk/commands/types.d.ts +32 -32
  18. package/dist/sdk/email-templates/index.d.ts +21 -0
  19. package/dist/sdk/email-templates/types.d.ts +23 -0
  20. package/dist/sdk/enums.d.ts +12 -9
  21. package/dist/sdk/errors.d.ts +2 -2
  22. package/dist/sdk/experimental/index.d.ts +75 -57
  23. package/dist/sdk/experimental/types.d.ts +71 -41
  24. package/dist/sdk/fields/index.d.ts +29 -29
  25. package/dist/sdk/fields/types.d.ts +17 -17
  26. package/dist/sdk/forms/index.d.ts +14 -14
  27. package/dist/sdk/forms/types.d.ts +28 -28
  28. package/dist/sdk/index.d.ts +11 -8
  29. package/dist/sdk/interfaces.d.ts +17 -13
  30. package/dist/sdk/sequences/index.d.ts +13 -0
  31. package/dist/sdk/sequences/types.d.ts +18 -0
  32. package/dist/sdk/stats/index.d.ts +24 -0
  33. package/dist/sdk/stats/types.d.ts +26 -0
  34. package/dist/sdk/subscribers/index.d.ts +20 -20
  35. package/dist/sdk/subscribers/types.d.ts +25 -25
  36. package/dist/sdk/tags/index.d.ts +20 -20
  37. package/dist/sdk/tags/types.d.ts +17 -17
  38. package/dist/sdk/types.d.ts +41 -41
  39. package/dist/sdk/workflows/index.d.ts +13 -0
  40. package/dist/sdk/workflows/types.d.ts +18 -0
  41. package/dist/versions/v1/index.d.ts +168 -132
  42. package/dist/versions/v1/types.d.ts +31 -31
  43. package/package.json +31 -44
  44. package/src/sdk/batch/events.ts +1 -1
  45. package/src/sdk/batch/index.ts +15 -22
  46. package/src/sdk/broadcasts/index.ts +44 -0
  47. package/src/sdk/broadcasts/types.ts +38 -0
  48. package/src/sdk/client/errors.ts +14 -0
  49. package/src/sdk/client/index.ts +205 -49
  50. package/src/sdk/commands/index.ts +54 -89
  51. package/src/sdk/email-templates/index.ts +39 -0
  52. package/src/sdk/email-templates/types.ts +27 -0
  53. package/src/sdk/enums.ts +3 -0
  54. package/src/sdk/experimental/index.ts +44 -26
  55. package/src/sdk/experimental/types.ts +35 -0
  56. package/src/sdk/fields/index.ts +1 -3
  57. package/src/sdk/forms/index.ts +4 -9
  58. package/src/sdk/forms/types.ts +1 -7
  59. package/src/sdk/index.ts +3 -0
  60. package/src/sdk/interfaces.ts +4 -0
  61. package/src/sdk/sequences/index.ts +21 -0
  62. package/src/sdk/sequences/types.ts +21 -0
  63. package/src/sdk/stats/index.ts +37 -0
  64. package/src/sdk/stats/types.ts +28 -0
  65. package/src/sdk/subscribers/index.ts +5 -15
  66. package/src/sdk/tags/index.ts +1 -3
  67. package/src/sdk/types.ts +1 -1
  68. package/src/sdk/workflows/index.ts +21 -0
  69. package/src/sdk/workflows/types.ts +21 -0
  70. package/src/versions/v1/index.ts +65 -10
  71. package/dist/bento-node-sdk.cjs.development.js +0 -2071
  72. package/dist/bento-node-sdk.cjs.development.js.map +0 -1
  73. package/dist/bento-node-sdk.cjs.production.min.js +0 -2
  74. package/dist/bento-node-sdk.cjs.production.min.js.map +0 -1
  75. package/dist/bento-node-sdk.esm.js +0 -2063
  76. package/dist/bento-node-sdk.esm.js.map +0 -1
@@ -1,132 +1,168 @@
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
- export declare class BentoAPIV1<S = {
5
- [key: string]: unknown;
6
- }, E extends string = '$custom'> {
7
- private readonly _client;
8
- readonly Batch: BentoBatch<S, E>;
9
- readonly Commands: BentoCommands<S>;
10
- readonly Experimental: BentoExperimental;
11
- readonly Fields: BentoFields;
12
- readonly Forms: BentoForms;
13
- readonly Subscribers: BentoSubscribers<S>;
14
- readonly Tags: BentoTags;
15
- constructor(options: AnalyticsOptions);
16
- /**
17
- * **This TRIGGERS automations!** - If you do not wish to trigger automations, please use the
18
- * `Commands.addTag` method.
19
- *
20
- * Tags a subscriber with the specified email and tag. If either the tag or the user
21
- * do not exist, they will be created in the system. If the user already has the tag,
22
- * another tag event will be sent, triggering any automations that take place upon a
23
- * tag being added to a subscriber. Please be aware of the potential consequences.
24
- *
25
- * Because this method uses the batch API, the tag may take between 1 and 3 minutes
26
- * to appear in the system.
27
- *
28
- * Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
29
- *
30
- * @param parameters TagSubscriberParameters
31
- * @returns Promise\<boolean\>
32
- */
33
- tagSubscriber(parameters: TagSubscriberParameters): Promise<boolean>;
34
- /**
35
- * **This TRIGGERS automations!** - If you do not wish to trigger automations, please use the
36
- * `Commands.subscribe` method.
37
- *
38
- * Creates a subscriber in the system. If the subscriber already exists, another subscribe event
39
- * will be sent, triggering any automations that take place upon subscription. Please be aware
40
- * of the potential consequences.
41
- *
42
- * You may optionally pass any fields that you wish to be set on the subscriber during creation
43
- * as well as a `Date` which will backdate the event. If no date is supplied, then the event will
44
- * default to the current time.
45
- *
46
- * Because this method uses the batch API, the tag may take between 1 and 3 minutes
47
- * to appear in the system.
48
- *
49
- * Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
50
- *
51
- * @param parameters AddSubscriberParameters
52
- * @returns Promise\<boolean\>
53
- */
54
- addSubscriber(parameters: AddSubscriberParameters<S>): Promise<boolean>;
55
- /**
56
- * **This TRIGGERS automations!** - If you do not wish to trigger automations, please use the
57
- * `Commands.unsubscribe` method.
58
- *
59
- * Unsubscribes an email in the system. If the email is already unsubscribed, another unsubscribe event
60
- * will be sent, triggering any automations that take place upon an unsubscribe happening. Please be aware
61
- * of the potential consequences.
62
- *
63
- * You may optionally pass a `Date` which will backdate the event. If no date is supplied, then the event
64
- * will default to the current time.
65
- *
66
- * Because this method uses the batch API, the tag may take between 1 and 3 minutes
67
- * to appear in the system.
68
- *
69
- * Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
70
- *
71
- * @param parameters RemoveSubscriberParameters
72
- * @returns Promise\<boolean\>
73
- */
74
- removeSubscriber(parameters: RemoveSubscriberParameters): Promise<boolean>;
75
- /**
76
- * **This TRIGGERS automations!** - If you do not wish to trigger automations, please use the
77
- * `Commands.addField` method.
78
- *
79
- * Sets the passed-in custom fields on the subscriber, creating the subscriber if it does not exist.
80
- * If the fields are already set on the subscriber, the event will be sent, triggering any automations
81
- * that take place upon fields being updated. Please be aware of the potential consequences.
82
- *
83
- * You may optionally pass a `Date` which will backdate the event. If no date is supplied, then the event
84
- * will default to the current time.
85
- *
86
- * Because this method uses the batch API, the tag may take between 1 and 3 minutes
87
- * to appear in the system.
88
- *
89
- * Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
90
- *
91
- * @param parameters UpdateFieldsParameters\<S\>
92
- * @returns Promise\<boolean\>
93
- */
94
- updateFields(parameters: UpdateFieldsParameters<S>): Promise<boolean>;
95
- /**
96
- * **This TRIGGERS automations!** - There is no way to achieve this same behavior without triggering
97
- * automations.
98
- *
99
- * Tracks a purchase in Bento, used to calculate LTV for your subscribers. The values that are received
100
- * should be numbers, in cents. For example, `$1.00` should be `100`.
101
- *
102
- * You may optionally pass a `Date` which will backdate the event. If no date is supplied, then the event
103
- * will default to the current time.
104
- *
105
- * Because this method uses the batch API, the tag may take between 1 and 3 minutes
106
- * to appear in the system.
107
- *
108
- * Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
109
- *
110
- * @param parameters TrackPurchaseParameters
111
- * @returns Promise\<boolean\>
112
- */
113
- trackPurchase(parameters: TrackPurchaseParameters): Promise<boolean>;
114
- /**
115
- * **This TRIGGERS automations!** - There is no way to achieve this same behavior without triggering
116
- * automations.
117
- *
118
- * Tracks a custom event in Bento.
119
- *
120
- * You may optionally pass a `Date` which will backdate the event. If no date is supplied, then the event
121
- * will default to the current time.
122
- *
123
- * Because this method uses the batch API, the tag may take between 1 and 3 minutes
124
- * to appear in the system.
125
- *
126
- * Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
127
- *
128
- * @param parameters TrackParameters<S, E>
129
- * @returns Promise\<boolean\>
130
- */
131
- track(parameters: TrackParameters<S, E>): Promise<boolean>;
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 type { 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
+ * This method still relies on the batch import queue (which can take 1-5 minutes to
145
+ * finish processing), but it automatically attempts to fetch and return the subscriber
146
+ * record after the import has been queued.
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * const subscriber = await analytics.V1.upsertSubscriber({
151
+ * email: 'user@example.com',
152
+ * fields: {
153
+ * firstName: 'John',
154
+ * lastName: 'Doe'
155
+ * },
156
+ * tags: 'lead,mql',
157
+ * remove_tags: 'customer'
158
+ * });
159
+ * ```
160
+ *
161
+ * @param parameters Object containing subscriber data including email, fields, and tags
162
+ * @returns Promise<Subscriber<S> | null> The created or updated subscriber
163
+ */
164
+ upsertSubscriber(parameters: Omit<AddSubscriberParameters<S>, 'date'> & {
165
+ tags?: string;
166
+ remove_tags?: string;
167
+ }): Promise<Subscriber<S> | null>;
168
+ }
@@ -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
- "version": "0.2.1",
2
+ "name": "@bentonow/bento-node-sdk",
3
+ "version": "1.0.5",
4
+ "description": "🍱 Bento Node.JS SDK and tracking library",
5
+ "author": "Backpack Internet",
3
6
  "license": "MIT",
4
7
  "main": "dist/index.js",
5
- "typings": "dist/index.d.ts",
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": ">=12"
15
+ "node": ">=18"
12
16
  },
13
17
  "scripts": {
14
- "start": "tsdx watch",
15
- "build": "tsdx build",
16
- "test": "tsdx test",
17
- "lint": "tsdx lint",
18
- "prepare": "tsdx build",
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": "^5.0.3",
52
- "@types/isomorphic-fetch": "^0.0.35",
53
- "@types/jest": "^27.0.1",
54
- "@typescript-eslint/eslint-plugin": "^5.30.7",
55
- "@typescript-eslint/parser": "^5.30.7",
56
- "@weiran.zsd/tsdx": "^0.15.2",
57
- "eslint": "^7.32.0",
58
- "husky": "^7.0.1",
59
- "msw": "^0.34.0",
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.0.0"
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
+ }
@@ -6,7 +6,7 @@ export type PurchaseItem = {
6
6
  quantity?: number;
7
7
  product_price?: number;
8
8
  product_id?: string;
9
- } & { [key: string]: string };
9
+ } & { [key: string]: string | number };
10
10
 
11
11
  export type PurchaseCart = {
12
12
  abandoned_checkout_url?: string;
@@ -41,26 +41,21 @@ 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>(
60
54
  `${this._url}/subscribers`,
61
55
  {
62
56
  subscribers: parameters.subscribers,
63
- }
57
+ },
58
+ { timeout: null }
64
59
  );
65
60
 
66
61
  return result.results;
@@ -77,9 +72,7 @@ export class BentoBatch<S, E extends string> {
77
72
  * @param parameters
78
73
  * @returns Promise\<number\>
79
74
  */
80
- public async importEvents(
81
- parameters: BatchImportEventsParameter<S, E>
82
- ): Promise<number> {
75
+ public async importEvents(parameters: BatchImportEventsParameter<S, E>): Promise<number> {
83
76
  if (parameters.events.length === 0) {
84
77
  throw new TooFewEventsError(`You must send between 1 and 1,000 events.`);
85
78
  }
@@ -92,7 +85,8 @@ export class BentoBatch<S, E extends string> {
92
85
  `${this._url}/events`,
93
86
  {
94
87
  events: parameters.events,
95
- }
88
+ },
89
+ { timeout: null }
96
90
  );
97
91
 
98
92
  return result.results;
@@ -105,7 +99,7 @@ export class BentoBatch<S, E extends string> {
105
99
  * Each email must have a `to` address, a `from` address, a `subject`, an `html_body`
106
100
  * and `transactional: true`.
107
101
  * In addition you can add a `personalizations` object to provide
108
- * liquid tsags that will be injected into the email.
102
+ * liquid tags that will be injected into the email.
109
103
  *
110
104
  * Returns the number of events that were imported.
111
105
  *
@@ -123,13 +117,12 @@ export class BentoBatch<S, E extends string> {
123
117
  throw new TooManyEmailsError(`You must send between 1 and 100 emails.`);
124
118
  }
125
119
 
126
- const result =
127
- await this._client.post<BatchsendTransactionalEmailsResponse>(
128
- `${this._url}/emails`,
129
- {
130
- emails: parameters.emails,
131
- }
132
- );
120
+ const result = await this._client.post<BatchsendTransactionalEmailsResponse>(
121
+ `${this._url}/emails`,
122
+ {
123
+ emails: parameters.emails,
124
+ }
125
+ );
133
126
 
134
127
  return result.results;
135
128
  }
@@ -0,0 +1,44 @@
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 _fetchUrl = '/fetch/broadcasts';
7
+ private readonly _batchUrl = '/batch/broadcasts';
8
+ private readonly _emailsUrl = '/batch/emails';
9
+
10
+ constructor(private readonly _client: BentoClient) {}
11
+
12
+ /**
13
+ * Creates transactional emails in batch
14
+ * @param emails Array of email data to send
15
+ * @returns Promise<number> Number of emails successfully created
16
+ */
17
+ public async createEmails(emails: EmailData[]): Promise<number> {
18
+ const result = await this._client.post<{ results: number }>(this._emailsUrl, {
19
+ emails,
20
+ });
21
+ return result.results;
22
+ }
23
+
24
+ /**
25
+ * Retrieves all broadcasts for the site
26
+ * @returns Promise<Broadcast[]>
27
+ */
28
+ public async getBroadcasts(): Promise<Broadcast[]> {
29
+ const result = await this._client.get<DataResponse<Broadcast[]>>(this._fetchUrl);
30
+ return result.data ?? [];
31
+ }
32
+
33
+ /**
34
+ * Creates new broadcast campaigns
35
+ * @param broadcasts Array of broadcast data to create
36
+ * @returns Promise<Broadcast[]>
37
+ */
38
+ public async createBroadcast(broadcasts: CreateBroadcastInput[]): Promise<Broadcast[]> {
39
+ const result = await this._client.post<DataResponse<Broadcast[]>>(this._batchUrl, {
40
+ broadcasts,
41
+ });
42
+ return result.data ?? [];
43
+ }
44
+ }
@@ -0,0 +1,38 @@
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
+ /**
28
+ * Email data for transactional emails.
29
+ * Note: This is the same structure as TransactionalEmail in batch/types.ts
30
+ */
31
+ export type EmailData = {
32
+ to: string;
33
+ from: string;
34
+ subject: string;
35
+ html_body: string;
36
+ transactional: boolean;
37
+ personalizations?: Record<string, string | number | boolean>;
38
+ };