supersendtx 0.1.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/dist/index.d.ts +103 -0
- package/dist/index.js +102 -0
- package/package.json +49 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
type SendEmailParams = {
|
|
2
|
+
from: string | {
|
|
3
|
+
email: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
};
|
|
6
|
+
to: string | string[];
|
|
7
|
+
subject: string;
|
|
8
|
+
html?: string;
|
|
9
|
+
text?: string;
|
|
10
|
+
replyTo?: string;
|
|
11
|
+
reply_to?: string;
|
|
12
|
+
cc?: string | string[];
|
|
13
|
+
bcc?: string | string[];
|
|
14
|
+
};
|
|
15
|
+
type SendEmailResult = {
|
|
16
|
+
id: string;
|
|
17
|
+
status: string;
|
|
18
|
+
};
|
|
19
|
+
type EmailListItem = {
|
|
20
|
+
id: string;
|
|
21
|
+
from: string;
|
|
22
|
+
to: string[];
|
|
23
|
+
subject: string;
|
|
24
|
+
status: string;
|
|
25
|
+
last_event: string | null;
|
|
26
|
+
bounce_reason: string | null;
|
|
27
|
+
created_at: string;
|
|
28
|
+
sent_at: string | null;
|
|
29
|
+
delivered_at: string | null;
|
|
30
|
+
bounced_at: string | null;
|
|
31
|
+
};
|
|
32
|
+
type ListEmailsParams = {
|
|
33
|
+
limit?: number;
|
|
34
|
+
};
|
|
35
|
+
type WebhookEventType = 'email.delivered' | 'email.bounced';
|
|
36
|
+
type WebhookEndpoint = {
|
|
37
|
+
id: string;
|
|
38
|
+
url: string;
|
|
39
|
+
events: string[];
|
|
40
|
+
enabled: boolean;
|
|
41
|
+
created_at: string;
|
|
42
|
+
updated_at: string;
|
|
43
|
+
};
|
|
44
|
+
type CreateWebhookParams = {
|
|
45
|
+
url: string;
|
|
46
|
+
events?: WebhookEventType[];
|
|
47
|
+
};
|
|
48
|
+
type WebhookEndpointWithSecret = {
|
|
49
|
+
webhook: WebhookEndpoint;
|
|
50
|
+
secret: string;
|
|
51
|
+
};
|
|
52
|
+
type SuperSendTXOptions = {
|
|
53
|
+
baseUrl?: string;
|
|
54
|
+
fetch?: typeof fetch;
|
|
55
|
+
};
|
|
56
|
+
type ApiErrorBody = {
|
|
57
|
+
error?: {
|
|
58
|
+
message?: string;
|
|
59
|
+
details?: unknown;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
declare class EmailsResource {
|
|
64
|
+
private readonly client;
|
|
65
|
+
constructor(client: SuperSendTX);
|
|
66
|
+
list(params?: ListEmailsParams): Promise<{
|
|
67
|
+
emails: EmailListItem[];
|
|
68
|
+
}>;
|
|
69
|
+
send(params: SendEmailParams): Promise<SendEmailResult>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
declare class WebhooksResource {
|
|
73
|
+
private readonly client;
|
|
74
|
+
constructor(client: SuperSendTX);
|
|
75
|
+
list(): Promise<{
|
|
76
|
+
webhooks: WebhookEndpoint[];
|
|
77
|
+
}>;
|
|
78
|
+
create(params: CreateWebhookParams): Promise<WebhookEndpointWithSecret>;
|
|
79
|
+
delete(id: string): Promise<{
|
|
80
|
+
ok: boolean;
|
|
81
|
+
}>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
declare const DEFAULT_API_BASE_URL = "https://api.supersendtx.com";
|
|
85
|
+
declare class SuperSendTX {
|
|
86
|
+
private readonly apiKey;
|
|
87
|
+
private readonly options;
|
|
88
|
+
readonly emails: EmailsResource;
|
|
89
|
+
readonly webhooks: WebhooksResource;
|
|
90
|
+
constructor(apiKey: string, options?: SuperSendTXOptions);
|
|
91
|
+
get baseUrl(): string;
|
|
92
|
+
get fetchImpl(): typeof fetch;
|
|
93
|
+
request<T>(path: string, init: RequestInit): Promise<T>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
declare class SuperSendTXError extends Error {
|
|
97
|
+
readonly status: number;
|
|
98
|
+
readonly details?: unknown;
|
|
99
|
+
constructor(message: string, status: number, details?: unknown);
|
|
100
|
+
static fromResponse(status: number, body: ApiErrorBody): SuperSendTXError;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { type CreateWebhookParams, DEFAULT_API_BASE_URL, type EmailListItem, type ListEmailsParams, type SendEmailParams, type SendEmailResult, SuperSendTX, SuperSendTXError, type SuperSendTXOptions, type WebhookEndpoint, type WebhookEndpointWithSecret, type WebhookEventType };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var SuperSendTXError = class _SuperSendTXError extends Error {
|
|
3
|
+
constructor(message, status, details) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "SuperSendTXError";
|
|
6
|
+
this.status = status;
|
|
7
|
+
this.details = details;
|
|
8
|
+
}
|
|
9
|
+
static fromResponse(status, body) {
|
|
10
|
+
const message = body.error?.message || `Request failed with status ${status}`;
|
|
11
|
+
return new _SuperSendTXError(message, status, body.error?.details);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// src/emails.ts
|
|
16
|
+
var EmailsResource = class {
|
|
17
|
+
constructor(client) {
|
|
18
|
+
this.client = client;
|
|
19
|
+
}
|
|
20
|
+
async list(params = {}) {
|
|
21
|
+
const query = params.limit ? `?limit=${params.limit}` : "";
|
|
22
|
+
return this.client.request(`/emails${query}`, {
|
|
23
|
+
method: "GET"
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async send(params) {
|
|
27
|
+
const payload = {
|
|
28
|
+
from: params.from,
|
|
29
|
+
to: params.to,
|
|
30
|
+
subject: params.subject
|
|
31
|
+
};
|
|
32
|
+
if (params.html) payload.html = params.html;
|
|
33
|
+
if (params.text) payload.text = params.text;
|
|
34
|
+
const replyTo = params.replyTo ?? params.reply_to;
|
|
35
|
+
if (replyTo) payload.reply_to = replyTo;
|
|
36
|
+
if (params.cc) payload.cc = params.cc;
|
|
37
|
+
if (params.bcc) payload.bcc = params.bcc;
|
|
38
|
+
return this.client.request("/emails", {
|
|
39
|
+
method: "POST",
|
|
40
|
+
body: JSON.stringify(payload)
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// src/webhooks.ts
|
|
46
|
+
var WebhooksResource = class {
|
|
47
|
+
constructor(client) {
|
|
48
|
+
this.client = client;
|
|
49
|
+
}
|
|
50
|
+
async list() {
|
|
51
|
+
return this.client.request("/webhooks", { method: "GET" });
|
|
52
|
+
}
|
|
53
|
+
async create(params) {
|
|
54
|
+
return this.client.request("/webhooks", {
|
|
55
|
+
method: "POST",
|
|
56
|
+
body: JSON.stringify(params)
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async delete(id) {
|
|
60
|
+
return this.client.request(`/webhooks/${id}`, { method: "DELETE" });
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// src/client.ts
|
|
65
|
+
var DEFAULT_API_BASE_URL = "https://api.supersendtx.com";
|
|
66
|
+
var SuperSendTX = class {
|
|
67
|
+
constructor(apiKey, options = {}) {
|
|
68
|
+
this.apiKey = apiKey;
|
|
69
|
+
this.options = options;
|
|
70
|
+
if (!apiKey?.startsWith("stx_")) {
|
|
71
|
+
throw new Error("SuperSend TX API key must start with stx_");
|
|
72
|
+
}
|
|
73
|
+
this.emails = new EmailsResource(this);
|
|
74
|
+
this.webhooks = new WebhooksResource(this);
|
|
75
|
+
}
|
|
76
|
+
get baseUrl() {
|
|
77
|
+
return (this.options.baseUrl || DEFAULT_API_BASE_URL).replace(/\/$/, "");
|
|
78
|
+
}
|
|
79
|
+
get fetchImpl() {
|
|
80
|
+
return this.options.fetch || fetch;
|
|
81
|
+
}
|
|
82
|
+
async request(path, init) {
|
|
83
|
+
const response = await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
84
|
+
...init,
|
|
85
|
+
headers: {
|
|
86
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
87
|
+
"Content-Type": "application/json",
|
|
88
|
+
...init.headers || {}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
const body = await response.json().catch(() => ({}));
|
|
92
|
+
if (!response.ok) {
|
|
93
|
+
throw SuperSendTXError.fromResponse(response.status, body);
|
|
94
|
+
}
|
|
95
|
+
return body;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
export {
|
|
99
|
+
DEFAULT_API_BASE_URL,
|
|
100
|
+
SuperSendTX,
|
|
101
|
+
SuperSendTXError
|
|
102
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "supersendtx",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "SuperSend TX transactional email API client",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": ["dist"],
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/Super-Send/superTX-app.git",
|
|
19
|
+
"directory": "packages/supersendtx"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://supersendtx.com",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/Super-Send/superTX-app/issues"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"email",
|
|
27
|
+
"transactional",
|
|
28
|
+
"supersend",
|
|
29
|
+
"supersendtx",
|
|
30
|
+
"postal"
|
|
31
|
+
],
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=18"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
40
|
+
"test": "vitest run",
|
|
41
|
+
"typecheck": "tsc --noEmit",
|
|
42
|
+
"prepublishOnly": "npm run build"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"tsup": "^8.5.0",
|
|
46
|
+
"typescript": "^5",
|
|
47
|
+
"vitest": "^3.2.4"
|
|
48
|
+
}
|
|
49
|
+
}
|