ensend 0.0.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/dist/apis/AudienceApi.d.ts +27 -0
- package/dist/apis/AudienceApi.js +12 -0
- package/dist/apis/SendApi.d.ts +169 -0
- package/dist/apis/SendApi.js +72 -0
- package/dist/client.d.ts +10 -0
- package/dist/client.js +40 -0
- package/dist/lib/types.d.ts +19 -0
- package/dist/lib/types.js +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { HttpClient } from "../lib/types";
|
|
2
|
+
export declare class AudienceApi {
|
|
3
|
+
private http;
|
|
4
|
+
constructor(http: HttpClient);
|
|
5
|
+
CreateProfile(dto: TAudienceApi.CreateProfileDto): Promise<{
|
|
6
|
+
data: import("../lib/types").HttpClientResponse<TAudienceApi.CreateProfileResponse>;
|
|
7
|
+
error: import("../lib/types").HttpClientResponse;
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
10
|
+
export declare namespace TAudienceApi {
|
|
11
|
+
type CreateProfileDto = {
|
|
12
|
+
audienceId: string;
|
|
13
|
+
name: string;
|
|
14
|
+
identity: string;
|
|
15
|
+
sendConsentEmail: boolean;
|
|
16
|
+
};
|
|
17
|
+
type CreateProfileResponse = {
|
|
18
|
+
profile: {
|
|
19
|
+
ref: string;
|
|
20
|
+
name: string;
|
|
21
|
+
identity: string;
|
|
22
|
+
type: string;
|
|
23
|
+
status: string;
|
|
24
|
+
createdAt: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import type { HttpClient } from "../lib/types";
|
|
2
|
+
export declare class SendApi<const I extends readonly string[], const T extends readonly string[]> {
|
|
3
|
+
private http;
|
|
4
|
+
constructor(http: HttpClient);
|
|
5
|
+
/**
|
|
6
|
+
* This API method creates and sends a new mail message or notification.
|
|
7
|
+
* @example
|
|
8
|
+
* const ensend = new Client({...})
|
|
9
|
+
* await ensend.SendApi.SendMailMessage({
|
|
10
|
+
* subject: "Hello Ensend!",
|
|
11
|
+
* sender: "noreply@ensend.co",
|
|
12
|
+
* recipients: "tenotea@smtpexpress.com"
|
|
13
|
+
* message: "<i>reach your customers wherever they are</i>",
|
|
14
|
+
* attachments: [{
|
|
15
|
+
* name: "Attachment.pdf",
|
|
16
|
+
* content?: "data:application/pdf;base64,..."
|
|
17
|
+
* url?: "https://link-to-file.pdf"
|
|
18
|
+
* }]
|
|
19
|
+
* });
|
|
20
|
+
* @see {@link https://docs.ensend.co/send/mail-message | More in the documentation}
|
|
21
|
+
*/
|
|
22
|
+
SendMailMessage(dto: TSendApi.SendMailMessageDto<I, T>): Promise<{
|
|
23
|
+
data: import("../lib/types").HttpClientResponse<TSendApi.SendMailMessageResponse>;
|
|
24
|
+
error: import("../lib/types").HttpClientResponse;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* This API method Creates and sends a new mail broadcast.
|
|
28
|
+
* @example
|
|
29
|
+
* const ensend = new Client({...})
|
|
30
|
+
* await ensend.SendApi.SendMailBroadcast({
|
|
31
|
+
* subject: "{{profile.firstName}}, Welcome to Ensend!",
|
|
32
|
+
* sender: "noreply@ensend.co",
|
|
33
|
+
* recipients: ["tenotea@smtpexpress.com"]
|
|
34
|
+
* message: "<i>reach your customers wherever they are</i>",
|
|
35
|
+
* attachments: [{
|
|
36
|
+
* name: "Attachment.pdf",
|
|
37
|
+
* content?: "data:application/pdf;base64,..."
|
|
38
|
+
* url?: "https://link-to-file.pdf"
|
|
39
|
+
* }]
|
|
40
|
+
* });
|
|
41
|
+
* @see {@link https://docs.ensend.co/send/mail-broadast | More about personalization in the documentation}
|
|
42
|
+
*/
|
|
43
|
+
SendMailBroadcast(dto: TSendApi.SendMailBroadcastDto<I, T>): Promise<{
|
|
44
|
+
data: import("../lib/types").HttpClientResponse<TSendApi.SendMailBroadcastResponse>;
|
|
45
|
+
error: import("../lib/types").HttpClientResponse;
|
|
46
|
+
}>;
|
|
47
|
+
/**
|
|
48
|
+
* This API method sends a mail message to new recipients in a broadcast.
|
|
49
|
+
* @example
|
|
50
|
+
* const ensend = new Client({...})
|
|
51
|
+
* await ensend.SendApi.SendExistingMailBroadcast({
|
|
52
|
+
* broadcastRef: "ref of a previously created broadcast",
|
|
53
|
+
* // new recipients to deliver to
|
|
54
|
+
* recipients: ["tenotea@smtpexpress.com"]
|
|
55
|
+
* });
|
|
56
|
+
* // No other modifications can me made to a previously processed broadcast.
|
|
57
|
+
* @see {@link https://docs.ensend.co/send/mail-broadcast | More in the documentation}
|
|
58
|
+
*/
|
|
59
|
+
SendExistingMailBroadcast(dto: TSendApi.SendExistingMailBroadcastDto): Promise<{
|
|
60
|
+
data: import("../lib/types").HttpClientResponse<TSendApi.SendMailBroadcastResponse>;
|
|
61
|
+
error: import("../lib/types").HttpClientResponse;
|
|
62
|
+
}>;
|
|
63
|
+
}
|
|
64
|
+
export declare namespace TSendApi {
|
|
65
|
+
type RequiresAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
|
|
66
|
+
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
|
|
67
|
+
}[Keys];
|
|
68
|
+
export type SendMailMessageDto<I extends readonly string[] = [], T extends readonly string[] = []> = {
|
|
69
|
+
subject: string;
|
|
70
|
+
sender: I[number] | {
|
|
71
|
+
name?: string;
|
|
72
|
+
address: I[number];
|
|
73
|
+
};
|
|
74
|
+
recipients: string | string[] | {
|
|
75
|
+
name?: string;
|
|
76
|
+
address: string;
|
|
77
|
+
} | Array<{
|
|
78
|
+
name?: string;
|
|
79
|
+
address: string;
|
|
80
|
+
}>;
|
|
81
|
+
replyAddress?: string;
|
|
82
|
+
attachments?: Array<{
|
|
83
|
+
name: string;
|
|
84
|
+
} & RequiresAtLeastOne<{
|
|
85
|
+
url: string;
|
|
86
|
+
content: string;
|
|
87
|
+
}, "content" | "url">>;
|
|
88
|
+
invitation?: {
|
|
89
|
+
title: string;
|
|
90
|
+
startDate: Date;
|
|
91
|
+
endDate: Date;
|
|
92
|
+
url?: string | null;
|
|
93
|
+
description?: string | null;
|
|
94
|
+
location?: string | null;
|
|
95
|
+
};
|
|
96
|
+
options?: {
|
|
97
|
+
acquiringAudience?: string | null;
|
|
98
|
+
storeContent?: boolean | null;
|
|
99
|
+
} | null;
|
|
100
|
+
} & RequiresAtLeastOne<{
|
|
101
|
+
message: string;
|
|
102
|
+
template: {
|
|
103
|
+
id: T[number];
|
|
104
|
+
variables?: Record<string, string>;
|
|
105
|
+
};
|
|
106
|
+
}, "message" | "template">;
|
|
107
|
+
export type SendMailMessageResponse = {
|
|
108
|
+
ref: string;
|
|
109
|
+
};
|
|
110
|
+
export type SendMailBroadcastDto<I extends readonly string[] = [], T extends readonly string[] = []> = {
|
|
111
|
+
subject: string;
|
|
112
|
+
sender: I[number] | {
|
|
113
|
+
name?: string;
|
|
114
|
+
address: I[number];
|
|
115
|
+
};
|
|
116
|
+
replyAddress?: string;
|
|
117
|
+
attachments?: Array<{
|
|
118
|
+
name: string;
|
|
119
|
+
} & RequiresAtLeastOne<{
|
|
120
|
+
url: string;
|
|
121
|
+
content: string;
|
|
122
|
+
}, "content" | "url">>;
|
|
123
|
+
invitation?: {
|
|
124
|
+
title: string;
|
|
125
|
+
startDate: Date;
|
|
126
|
+
endDate: Date;
|
|
127
|
+
url?: string | null;
|
|
128
|
+
description?: string | null;
|
|
129
|
+
location?: string | null;
|
|
130
|
+
};
|
|
131
|
+
options?: {
|
|
132
|
+
acquiringAudience?: string | null;
|
|
133
|
+
scheduleFor?: string | null;
|
|
134
|
+
storeContent?: boolean | null;
|
|
135
|
+
} | null;
|
|
136
|
+
} & RequiresAtLeastOne<{
|
|
137
|
+
message: string;
|
|
138
|
+
template: {
|
|
139
|
+
id: T[number];
|
|
140
|
+
variables?: Record<string, string>;
|
|
141
|
+
};
|
|
142
|
+
}, "message" | "template"> & RequiresAtLeastOne<{
|
|
143
|
+
recipients: string | string[] | {
|
|
144
|
+
name?: string;
|
|
145
|
+
address: string;
|
|
146
|
+
} | Array<{
|
|
147
|
+
name?: string;
|
|
148
|
+
address: string;
|
|
149
|
+
}>;
|
|
150
|
+
audience: string[];
|
|
151
|
+
}>;
|
|
152
|
+
export type SendExistingMailBroadcastDto = {
|
|
153
|
+
broadcastRef: string;
|
|
154
|
+
recipients?: string | string[] | {
|
|
155
|
+
name?: string;
|
|
156
|
+
address: string;
|
|
157
|
+
} | Array<{
|
|
158
|
+
name?: string;
|
|
159
|
+
address: string;
|
|
160
|
+
}>;
|
|
161
|
+
};
|
|
162
|
+
export type SendMailBroadcastResponse = {
|
|
163
|
+
broadcast: {
|
|
164
|
+
ref: string;
|
|
165
|
+
status: string;
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
export {};
|
|
169
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export class SendApi {
|
|
2
|
+
constructor(http) {
|
|
3
|
+
this.http = http;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* This API method creates and sends a new mail message or notification.
|
|
7
|
+
* @example
|
|
8
|
+
* const ensend = new Client({...})
|
|
9
|
+
* await ensend.SendApi.SendMailMessage({
|
|
10
|
+
* subject: "Hello Ensend!",
|
|
11
|
+
* sender: "noreply@ensend.co",
|
|
12
|
+
* recipients: "tenotea@smtpexpress.com"
|
|
13
|
+
* message: "<i>reach your customers wherever they are</i>",
|
|
14
|
+
* attachments: [{
|
|
15
|
+
* name: "Attachment.pdf",
|
|
16
|
+
* content?: "data:application/pdf;base64,..."
|
|
17
|
+
* url?: "https://link-to-file.pdf"
|
|
18
|
+
* }]
|
|
19
|
+
* });
|
|
20
|
+
* @see {@link https://docs.ensend.co/send/mail-message | More in the documentation}
|
|
21
|
+
*/
|
|
22
|
+
async SendMailMessage(dto) {
|
|
23
|
+
return this.http({
|
|
24
|
+
method: "POST",
|
|
25
|
+
path: "/send/mail",
|
|
26
|
+
body: dto,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* This API method Creates and sends a new mail broadcast.
|
|
31
|
+
* @example
|
|
32
|
+
* const ensend = new Client({...})
|
|
33
|
+
* await ensend.SendApi.SendMailBroadcast({
|
|
34
|
+
* subject: "{{profile.firstName}}, Welcome to Ensend!",
|
|
35
|
+
* sender: "noreply@ensend.co",
|
|
36
|
+
* recipients: ["tenotea@smtpexpress.com"]
|
|
37
|
+
* message: "<i>reach your customers wherever they are</i>",
|
|
38
|
+
* attachments: [{
|
|
39
|
+
* name: "Attachment.pdf",
|
|
40
|
+
* content?: "data:application/pdf;base64,..."
|
|
41
|
+
* url?: "https://link-to-file.pdf"
|
|
42
|
+
* }]
|
|
43
|
+
* });
|
|
44
|
+
* @see {@link https://docs.ensend.co/send/mail-broadast | More about personalization in the documentation}
|
|
45
|
+
*/
|
|
46
|
+
async SendMailBroadcast(dto) {
|
|
47
|
+
return this.http({
|
|
48
|
+
method: "POST",
|
|
49
|
+
path: "/send/mail/broadast",
|
|
50
|
+
body: dto,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* This API method sends a mail message to new recipients in a broadcast.
|
|
55
|
+
* @example
|
|
56
|
+
* const ensend = new Client({...})
|
|
57
|
+
* await ensend.SendApi.SendExistingMailBroadcast({
|
|
58
|
+
* broadcastRef: "ref of a previously created broadcast",
|
|
59
|
+
* // new recipients to deliver to
|
|
60
|
+
* recipients: ["tenotea@smtpexpress.com"]
|
|
61
|
+
* });
|
|
62
|
+
* // No other modifications can me made to a previously processed broadcast.
|
|
63
|
+
* @see {@link https://docs.ensend.co/send/mail-broadcast | More in the documentation}
|
|
64
|
+
*/
|
|
65
|
+
async SendExistingMailBroadcast(dto) {
|
|
66
|
+
return this.http({
|
|
67
|
+
method: "POST",
|
|
68
|
+
path: "/send/mail/broadast",
|
|
69
|
+
body: dto,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SendApi } from "./apis/SendApi";
|
|
2
|
+
import type { ClientOptions } from "./lib/types";
|
|
3
|
+
export declare class Client<const I extends readonly string[], const T extends readonly string[]> {
|
|
4
|
+
private ENSEND_BASE_URL;
|
|
5
|
+
private PROJECT_SECRET;
|
|
6
|
+
constructor(options?: ClientOptions<I, T>);
|
|
7
|
+
private http;
|
|
8
|
+
SendApi: SendApi<I, T>;
|
|
9
|
+
}
|
|
10
|
+
export type { TSendApi as SendApi } from "./apis/SendApi";
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import fetch from "node-fetch-native";
|
|
2
|
+
import { SendApi } from "./apis/SendApi";
|
|
3
|
+
export class Client {
|
|
4
|
+
constructor(options) {
|
|
5
|
+
this.ENSEND_BASE_URL = process.env.ENSEND_BASE_URL || "https://api.ensend.co";
|
|
6
|
+
this.PROJECT_SECRET = process.env.ENSEND_PROJECT_SECRET;
|
|
7
|
+
this.http = async (options) => {
|
|
8
|
+
let data = null;
|
|
9
|
+
let error = null;
|
|
10
|
+
await fetch(this.ENSEND_BASE_URL + options.path, {
|
|
11
|
+
headers: {
|
|
12
|
+
"Content-Type": "application/json",
|
|
13
|
+
Authorization: `Bearer ${this.PROJECT_SECRET}`,
|
|
14
|
+
},
|
|
15
|
+
method: options.method,
|
|
16
|
+
body: options.method === "POST" ? JSON.stringify(options.body) : undefined,
|
|
17
|
+
})
|
|
18
|
+
.then(async (res) => {
|
|
19
|
+
const responseData = await res.json();
|
|
20
|
+
if (res.status === 200) {
|
|
21
|
+
data = responseData;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
error = responseData;
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
.catch((error) => {
|
|
28
|
+
error = {
|
|
29
|
+
message: error.message,
|
|
30
|
+
statusCode: 500,
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
return { data, error };
|
|
34
|
+
};
|
|
35
|
+
this.SendApi = new SendApi(this.http);
|
|
36
|
+
if (options?.secret) {
|
|
37
|
+
this.PROJECT_SECRET = options.secret;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type HttpClientOptions = {
|
|
2
|
+
method: "POST" | "GET";
|
|
3
|
+
path: string;
|
|
4
|
+
body: Record<string, any>;
|
|
5
|
+
};
|
|
6
|
+
export type HttpClientResponse<T = undefined> = {
|
|
7
|
+
message: string;
|
|
8
|
+
statusCode: number;
|
|
9
|
+
data: T;
|
|
10
|
+
} | null;
|
|
11
|
+
export type HttpClient = <T extends Record<string, any>>(body: HttpClientOptions) => Promise<{
|
|
12
|
+
data: HttpClientResponse<T>;
|
|
13
|
+
error: HttpClientResponse;
|
|
14
|
+
}>;
|
|
15
|
+
export type ClientOptions<I extends readonly string[], T extends readonly string[]> = {
|
|
16
|
+
secret: string;
|
|
17
|
+
identities?: I;
|
|
18
|
+
templates?: T;
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ensend",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"private": false,
|
|
6
|
+
"description": "Official Typescript/Javascript SDK for the new Ensend API. See completed documentation at https://docs.ensend.co",
|
|
7
|
+
"main": "dist/client.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/client.d.ts",
|
|
11
|
+
"import": "./dist/client.js",
|
|
12
|
+
"require": "./dist/client.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"typecheck": "tsc --noEmit",
|
|
17
|
+
"build": "tsc"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"Email",
|
|
21
|
+
"SMS",
|
|
22
|
+
"Push Notifications",
|
|
23
|
+
"SMTP",
|
|
24
|
+
"Ensend"
|
|
25
|
+
],
|
|
26
|
+
"author": "Tenotea (https://github.com/tenotea)",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/ensendco/ensend-ts.git"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/ensendco/ensend-ts/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/ensendco/ensend-ts#readme",
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"node-fetch-native": "^1.6.7"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/node": "^25.2.3",
|
|
41
|
+
"typescript": "^5.9.3"
|
|
42
|
+
}
|
|
43
|
+
}
|