@bentonow/bento-node-sdk 0.1.14 → 0.2.1
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 +56 -21
- package/dist/bento-node-sdk.cjs.development.js +1000 -1773
- 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 +1000 -1773
- package/dist/bento-node-sdk.esm.js.map +1 -1
- package/dist/sdk/batch/errors.d.ts +6 -0
- package/dist/sdk/batch/events.d.ts +12 -12
- package/dist/sdk/batch/index.d.ts +17 -1
- package/dist/sdk/batch/types.d.ts +20 -4
- package/dist/sdk/client/types.d.ts +1 -1
- package/dist/sdk/commands/types.d.ts +7 -7
- package/dist/sdk/experimental/types.d.ts +8 -8
- package/dist/sdk/fields/types.d.ts +3 -3
- package/dist/sdk/forms/types.d.ts +3 -3
- package/dist/sdk/subscribers/types.d.ts +4 -4
- package/dist/sdk/tags/types.d.ts +3 -3
- package/dist/sdk/types.d.ts +5 -5
- package/dist/versions/v1/types.d.ts +6 -6
- package/package.json +3 -9
- 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/client/index.ts +7 -7
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Command Method Parameter Types
|
|
3
3
|
*/
|
|
4
|
-
export
|
|
4
|
+
export type AddTagParameters = {
|
|
5
5
|
email: string;
|
|
6
6
|
tagName: string;
|
|
7
7
|
};
|
|
8
|
-
export
|
|
8
|
+
export type RemoveTagParameters = {
|
|
9
9
|
email: string;
|
|
10
10
|
tagName: string;
|
|
11
11
|
};
|
|
12
|
-
export
|
|
12
|
+
export type AddFieldParameters<S> = {
|
|
13
13
|
email: string;
|
|
14
14
|
field: {
|
|
15
15
|
key: keyof S;
|
|
16
16
|
value: unknown;
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
|
-
export
|
|
19
|
+
export type RemoveFieldParameters<S> = {
|
|
20
20
|
email: string;
|
|
21
21
|
fieldName: keyof S;
|
|
22
22
|
};
|
|
23
|
-
export
|
|
23
|
+
export type SubscribeParameters = {
|
|
24
24
|
email: string;
|
|
25
25
|
};
|
|
26
|
-
export
|
|
26
|
+
export type UnsubscribeParameters = {
|
|
27
27
|
email: string;
|
|
28
28
|
};
|
|
29
|
-
export
|
|
29
|
+
export type ChangeEmailParameters = {
|
|
30
30
|
oldEmail: string;
|
|
31
31
|
newEmail: string;
|
|
32
32
|
};
|
|
@@ -2,19 +2,19 @@ import type { LocationData } from '../types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Experimental Method Parameter Types
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export type ValidateEmailParameters = {
|
|
6
6
|
email: string;
|
|
7
7
|
ip?: string;
|
|
8
8
|
name?: string;
|
|
9
9
|
userAgent?: string;
|
|
10
10
|
};
|
|
11
|
-
export
|
|
11
|
+
export type GuessGenderParameters = {
|
|
12
12
|
name: string;
|
|
13
13
|
};
|
|
14
|
-
export
|
|
14
|
+
export type GeolocateParameters = {
|
|
15
15
|
ip: string;
|
|
16
16
|
};
|
|
17
|
-
export
|
|
17
|
+
export type BlacklistParameters = {
|
|
18
18
|
domain: string;
|
|
19
19
|
ip?: never;
|
|
20
20
|
} | {
|
|
@@ -24,15 +24,15 @@ export declare type BlacklistParameters = {
|
|
|
24
24
|
/**
|
|
25
25
|
* Experimental Method Response Types
|
|
26
26
|
*/
|
|
27
|
-
export
|
|
27
|
+
export type ValidateEmailResponse = {
|
|
28
28
|
valid: boolean;
|
|
29
29
|
};
|
|
30
|
-
export
|
|
30
|
+
export type GuessGenderResponse = {
|
|
31
31
|
confidence: number | null;
|
|
32
32
|
gender: string | null;
|
|
33
33
|
};
|
|
34
|
-
export
|
|
35
|
-
export
|
|
34
|
+
export type GeolocateResponse = Partial<LocationData>;
|
|
35
|
+
export type BlacklistResponse = {
|
|
36
36
|
description: string;
|
|
37
37
|
query: string;
|
|
38
38
|
results: {
|
|
@@ -2,16 +2,16 @@ import type { BaseEntity } from '../types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Field Method Parameter Types
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export type CreateFieldParameters = {
|
|
6
6
|
key: string;
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
9
|
* Core Field Types
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
11
|
+
export type FieldAttributes = {
|
|
12
12
|
created_at: string;
|
|
13
13
|
key: string;
|
|
14
14
|
name: string;
|
|
15
15
|
whitelisted: boolean | null;
|
|
16
16
|
};
|
|
17
|
-
export
|
|
17
|
+
export type Field = BaseEntity<FieldAttributes>;
|
|
@@ -2,7 +2,7 @@ import type { BaseEntity, BrowserData, IdentityData, LocationData, PageData } fr
|
|
|
2
2
|
/**
|
|
3
3
|
* Core Form Types
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export type FormResponseData = {
|
|
6
6
|
browser: BrowserData;
|
|
7
7
|
date: string;
|
|
8
8
|
details: {
|
|
@@ -21,8 +21,8 @@ export declare type FormResponseData = {
|
|
|
21
21
|
visit: string;
|
|
22
22
|
visitor: string;
|
|
23
23
|
};
|
|
24
|
-
export
|
|
24
|
+
export type FormResponseAttributes = {
|
|
25
25
|
data: FormResponseData;
|
|
26
26
|
uuid: string;
|
|
27
27
|
};
|
|
28
|
-
export
|
|
28
|
+
export type FormResponse = BaseEntity<FormResponseAttributes>;
|
|
@@ -2,24 +2,24 @@ import type { BaseEntity } from '../types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Subscriber Method Parameter Types
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export type GetSubscribersParameters = {
|
|
6
6
|
email?: never;
|
|
7
7
|
uuid: string;
|
|
8
8
|
} | {
|
|
9
9
|
email: string;
|
|
10
10
|
uuid?: never;
|
|
11
11
|
} | never;
|
|
12
|
-
export
|
|
12
|
+
export type CreateSubscriberParameters = {
|
|
13
13
|
email: string;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
16
|
* Core Subscriber Types
|
|
17
17
|
*/
|
|
18
|
-
export
|
|
18
|
+
export type SubscriberAttributes<S> = {
|
|
19
19
|
cached_tag_ids: string[];
|
|
20
20
|
email: string;
|
|
21
21
|
fields: S | null;
|
|
22
22
|
unsubscribed_at: string | null;
|
|
23
23
|
uuid: string;
|
|
24
24
|
};
|
|
25
|
-
export
|
|
25
|
+
export type Subscriber<S> = BaseEntity<SubscriberAttributes<S>>;
|
package/dist/sdk/tags/types.d.ts
CHANGED
|
@@ -2,16 +2,16 @@ import type { BaseEntity } from '../types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Tag Method Parameter Types
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export type CreateTagParameters = {
|
|
6
6
|
name: string;
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
9
|
* Core Tag Types
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
11
|
+
export type TagAttributes = {
|
|
12
12
|
created_at: string;
|
|
13
13
|
discarded_at: string | null;
|
|
14
14
|
name: string | null;
|
|
15
15
|
site_id: number;
|
|
16
16
|
};
|
|
17
|
-
export
|
|
17
|
+
export type Tag = BaseEntity<TagAttributes>;
|
package/dist/sdk/types.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Core Types
|
|
3
3
|
*/
|
|
4
4
|
import type { EntityType } from "./enums";
|
|
5
|
-
export
|
|
5
|
+
export type BaseEntity<T> = {
|
|
6
6
|
attributes: T;
|
|
7
7
|
id: string;
|
|
8
8
|
type: EntityType;
|
|
@@ -10,15 +10,15 @@ export declare type BaseEntity<T> = {
|
|
|
10
10
|
/**
|
|
11
11
|
* Utility Types
|
|
12
12
|
*/
|
|
13
|
-
export
|
|
13
|
+
export type BrowserData = {
|
|
14
14
|
height: string;
|
|
15
15
|
user_agent: string;
|
|
16
16
|
width: string;
|
|
17
17
|
};
|
|
18
|
-
export
|
|
18
|
+
export type IdentityData = {
|
|
19
19
|
email: string;
|
|
20
20
|
};
|
|
21
|
-
export
|
|
21
|
+
export type LocationData = {
|
|
22
22
|
city_name: string;
|
|
23
23
|
continent_code: string;
|
|
24
24
|
country_code2: string;
|
|
@@ -32,7 +32,7 @@ export declare type LocationData = {
|
|
|
32
32
|
region_name: string;
|
|
33
33
|
request: string;
|
|
34
34
|
};
|
|
35
|
-
export
|
|
35
|
+
export type PageData = {
|
|
36
36
|
host: string;
|
|
37
37
|
path: string;
|
|
38
38
|
protocol: string;
|
|
@@ -2,30 +2,30 @@ import type { BaseEvent, PurchaseDetails } from '../../sdk/batch/events';
|
|
|
2
2
|
/**
|
|
3
3
|
* API Method Parameter Types
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export type TagSubscriberParameters = {
|
|
6
6
|
date?: Date;
|
|
7
7
|
email: string;
|
|
8
8
|
tagName: string;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
10
|
+
export type AddSubscriberParameters<S> = {
|
|
11
11
|
date?: Date;
|
|
12
12
|
email: string;
|
|
13
13
|
fields?: Partial<S>;
|
|
14
14
|
};
|
|
15
|
-
export
|
|
15
|
+
export type RemoveSubscriberParameters = {
|
|
16
16
|
date?: Date;
|
|
17
17
|
email: string;
|
|
18
18
|
};
|
|
19
|
-
export
|
|
19
|
+
export type TrackPurchaseParameters = {
|
|
20
20
|
date?: Date;
|
|
21
21
|
email: string;
|
|
22
22
|
purchaseDetails: PurchaseDetails;
|
|
23
23
|
};
|
|
24
|
-
export
|
|
24
|
+
export type UpdateFieldsParameters<S> = {
|
|
25
25
|
date?: Date;
|
|
26
26
|
email: string;
|
|
27
27
|
fields: Partial<S>;
|
|
28
28
|
};
|
|
29
|
-
export
|
|
29
|
+
export type TrackParameters<S, E extends string> = BaseEvent<E> & {
|
|
30
30
|
fields: Partial<S>;
|
|
31
31
|
};
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.1
|
|
2
|
+
"version": "0.2.1",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -25,12 +25,6 @@
|
|
|
25
25
|
"pre-commit": "tsdx lint"
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
|
-
"prettier": {
|
|
29
|
-
"printWidth": 80,
|
|
30
|
-
"semi": true,
|
|
31
|
-
"singleQuote": true,
|
|
32
|
-
"trailingComma": "es5"
|
|
33
|
-
},
|
|
34
28
|
"name": "@bentonow/bento-node-sdk",
|
|
35
29
|
"author": "Backpack Internet",
|
|
36
30
|
"module": "dist/bento-node-sdk.esm.js",
|
|
@@ -69,6 +63,6 @@
|
|
|
69
63
|
"typescript": "^4.3.5"
|
|
70
64
|
},
|
|
71
65
|
"dependencies": {
|
|
72
|
-
"
|
|
66
|
+
"cross-fetch": "^4.0.0"
|
|
73
67
|
}
|
|
74
|
-
}
|
|
68
|
+
}
|
package/src/sdk/batch/errors.ts
CHANGED
|
@@ -25,3 +25,17 @@ export class TooManyEventsError extends Error {
|
|
|
25
25
|
this.name = 'TooManyEventsError';
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
export class TooFewEmailsError extends Error {
|
|
30
|
+
constructor(message = 'Too few emails') {
|
|
31
|
+
super(message);
|
|
32
|
+
this.name = 'TooFewEmailsError';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class TooManyEmailsError extends Error {
|
|
37
|
+
constructor(message = 'Too many emails') {
|
|
38
|
+
super(message);
|
|
39
|
+
this.name = 'TooManyEmailsError';
|
|
40
|
+
}
|
|
41
|
+
}
|
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
|
+
};
|
package/src/sdk/client/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import fetch from '
|
|
1
|
+
import fetch from 'cross-fetch';
|
|
2
2
|
import type { AnalyticsOptions, AuthenticationOptions } from '../interfaces';
|
|
3
3
|
import { NotAuthorizedError, RateLimitedError } from './errors';
|
|
4
4
|
|
|
@@ -34,15 +34,15 @@ export class BentoClient {
|
|
|
34
34
|
method: 'GET',
|
|
35
35
|
headers: this._headers,
|
|
36
36
|
})
|
|
37
|
-
.then(async
|
|
37
|
+
.then(async result => {
|
|
38
38
|
if (this._isSuccessfulStatus(result.status)) {
|
|
39
39
|
return result.json();
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
throw await this._getErrorForResponse(result);
|
|
43
43
|
})
|
|
44
|
-
.then(
|
|
45
|
-
.catch(
|
|
44
|
+
.then(data => resolve(data))
|
|
45
|
+
.catch(error => reject(error));
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -69,15 +69,15 @@ export class BentoClient {
|
|
|
69
69
|
},
|
|
70
70
|
body,
|
|
71
71
|
})
|
|
72
|
-
.then(async
|
|
72
|
+
.then(async result => {
|
|
73
73
|
if (this._isSuccessfulStatus(result.status)) {
|
|
74
74
|
return result.json();
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
throw await this._getErrorForResponse(result);
|
|
78
78
|
})
|
|
79
|
-
.then(
|
|
80
|
-
.catch(
|
|
79
|
+
.then(data => resolve(data))
|
|
80
|
+
.catch(error => reject(error));
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
83
|
|