@bentonow/bento-node-sdk 0.1.14 → 0.2.0
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 +37 -4
- package/dist/bento-node-sdk.cjs.development.js +99 -0
- package/dist/bento-node-sdk.cjs.development.js.map +1 -1
- package/dist/bento-node-sdk.cjs.production.min.js +1 -1
- package/dist/bento-node-sdk.cjs.production.min.js.map +1 -1
- package/dist/bento-node-sdk.esm.js +99 -0
- package/dist/bento-node-sdk.esm.js.map +1 -1
- package/dist/sdk/batch/errors.d.ts +6 -0
- package/dist/sdk/batch/index.d.ts +17 -1
- package/dist/sdk/batch/types.d.ts +16 -0
- package/package.json +1 -7
- package/src/sdk/batch/errors.ts +14 -0
- package/src/sdk/batch/index.ts +41 -0
- package/src/sdk/batch/types.ts +19 -0
package/src/sdk/batch/index.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import type { BentoClient } from '../client';
|
|
2
2
|
import {
|
|
3
|
+
TooFewEmailsError,
|
|
3
4
|
TooFewEventsError,
|
|
4
5
|
TooFewSubscribersError,
|
|
6
|
+
TooManyEmailsError,
|
|
5
7
|
TooManyEventsError,
|
|
6
8
|
TooManySubscribersError,
|
|
7
9
|
} from './errors';
|
|
8
10
|
import type {
|
|
11
|
+
BatchSendTransactionalEmailsParameter,
|
|
12
|
+
BatchsendTransactionalEmailsResponse,
|
|
9
13
|
BatchImportEventsParameter,
|
|
10
14
|
BatchImportEventsResponse,
|
|
11
15
|
BatchImportSubscribersParameter,
|
|
@@ -13,6 +17,7 @@ import type {
|
|
|
13
17
|
} from './types';
|
|
14
18
|
|
|
15
19
|
export class BentoBatch<S, E extends string> {
|
|
20
|
+
private readonly _maxEmailBatchSize = 100;
|
|
16
21
|
private readonly _maxBatchSize = 1000;
|
|
17
22
|
private readonly _url = '/batch';
|
|
18
23
|
|
|
@@ -92,4 +97,40 @@ export class BentoBatch<S, E extends string> {
|
|
|
92
97
|
|
|
93
98
|
return result.results;
|
|
94
99
|
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Creates a batch job to send transactional emails from Bento's infrastructure. You can pass in
|
|
103
|
+
* between 1 and 100 emails to send.
|
|
104
|
+
*
|
|
105
|
+
* Each email must have a `to` address, a `from` address, a `subject`, an `html_body`
|
|
106
|
+
* and `transactional: true`.
|
|
107
|
+
* In addition you can add a `personalizations` object to provide
|
|
108
|
+
* liquid tsags that will be injected into the email.
|
|
109
|
+
*
|
|
110
|
+
* Returns the number of events that were imported.
|
|
111
|
+
*
|
|
112
|
+
* @param parameters
|
|
113
|
+
* @returns Promise\<number\>
|
|
114
|
+
*/
|
|
115
|
+
public async sendTransactionalEmails(
|
|
116
|
+
parameters: BatchSendTransactionalEmailsParameter
|
|
117
|
+
): Promise<number> {
|
|
118
|
+
if (parameters.emails.length === 0) {
|
|
119
|
+
throw new TooFewEmailsError(`You must send between 1 and 100 emails.`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (parameters.emails.length > this._maxEmailBatchSize) {
|
|
123
|
+
throw new TooManyEmailsError(`You must send between 1 and 100 emails.`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const result =
|
|
127
|
+
await this._client.post<BatchsendTransactionalEmailsResponse>(
|
|
128
|
+
`${this._url}/emails`,
|
|
129
|
+
{
|
|
130
|
+
emails: parameters.emails,
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
return result.results;
|
|
135
|
+
}
|
|
95
136
|
}
|
package/src/sdk/batch/types.ts
CHANGED
|
@@ -13,6 +13,21 @@ export type BatchImportEventsParameter<S, E extends string> = {
|
|
|
13
13
|
events: BentoEvent<S, E>[];
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
export type TransactionalEmail = {
|
|
17
|
+
to: string;
|
|
18
|
+
from: string;
|
|
19
|
+
subject: string;
|
|
20
|
+
html_body: string;
|
|
21
|
+
transactional: boolean;
|
|
22
|
+
personalizations?: {
|
|
23
|
+
[key: string]: string | number | boolean;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type BatchSendTransactionalEmailsParameter = {
|
|
28
|
+
emails: TransactionalEmail[];
|
|
29
|
+
};
|
|
30
|
+
|
|
16
31
|
/**
|
|
17
32
|
* Batch Method Response Types
|
|
18
33
|
*/
|
|
@@ -23,3 +38,7 @@ export type BatchImportSubscribersResponse = {
|
|
|
23
38
|
export type BatchImportEventsResponse = {
|
|
24
39
|
results: number;
|
|
25
40
|
};
|
|
41
|
+
|
|
42
|
+
export type BatchsendTransactionalEmailsResponse = {
|
|
43
|
+
results: number;
|
|
44
|
+
};
|