@unsent/sdk 0.25.3 → 1.0.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 +183 -103
- package/dist/index.d.mts +350 -87
- package/dist/index.d.ts +350 -87
- package/dist/index.js +51 -7
- package/dist/index.mjs +50 -7
- package/package.json +24 -5
package/dist/index.mjs
CHANGED
|
@@ -136,10 +136,52 @@ var Domains = class {
|
|
|
136
136
|
}
|
|
137
137
|
};
|
|
138
138
|
|
|
139
|
+
// src/campaign.ts
|
|
140
|
+
var Campaigns = class {
|
|
141
|
+
constructor(unsent2) {
|
|
142
|
+
this.unsent = unsent2;
|
|
143
|
+
this.unsent = unsent2;
|
|
144
|
+
}
|
|
145
|
+
async create(payload) {
|
|
146
|
+
const data = await this.unsent.post(
|
|
147
|
+
`/campaigns`,
|
|
148
|
+
payload
|
|
149
|
+
);
|
|
150
|
+
return data;
|
|
151
|
+
}
|
|
152
|
+
async get(campaignId) {
|
|
153
|
+
const data = await this.unsent.get(
|
|
154
|
+
`/campaigns/${campaignId}`
|
|
155
|
+
);
|
|
156
|
+
return data;
|
|
157
|
+
}
|
|
158
|
+
async schedule(campaignId, payload) {
|
|
159
|
+
const data = await this.unsent.post(
|
|
160
|
+
`/campaigns/${campaignId}/schedule`,
|
|
161
|
+
payload
|
|
162
|
+
);
|
|
163
|
+
return data;
|
|
164
|
+
}
|
|
165
|
+
async pause(campaignId) {
|
|
166
|
+
const data = await this.unsent.post(
|
|
167
|
+
`/campaigns/${campaignId}/pause`,
|
|
168
|
+
{}
|
|
169
|
+
);
|
|
170
|
+
return data;
|
|
171
|
+
}
|
|
172
|
+
async resume(campaignId) {
|
|
173
|
+
const data = await this.unsent.post(
|
|
174
|
+
`/campaigns/${campaignId}/resume`,
|
|
175
|
+
{}
|
|
176
|
+
);
|
|
177
|
+
return data;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
139
181
|
// src/unsent.ts
|
|
140
|
-
var defaultBaseUrl = "https://
|
|
141
|
-
var baseUrl = `${process?.env?.UNSENT_BASE_URL ?? process?.env?.UNSENT_BASE_URL ?? defaultBaseUrl}/
|
|
142
|
-
function
|
|
182
|
+
var defaultBaseUrl = "https://api.unsent.dev";
|
|
183
|
+
var baseUrl = `${process?.env?.UNSENT_BASE_URL ?? process?.env?.UNSENT_BASE_URL ?? defaultBaseUrl}/v1`;
|
|
184
|
+
function isUnsentErrorResponse(error) {
|
|
143
185
|
return error.error.code !== void 0;
|
|
144
186
|
}
|
|
145
187
|
var unsent = class {
|
|
@@ -147,7 +189,7 @@ var unsent = class {
|
|
|
147
189
|
this.key = key;
|
|
148
190
|
if (!key) {
|
|
149
191
|
if (typeof process !== "undefined" && process.env) {
|
|
150
|
-
this.key = process.env.
|
|
192
|
+
this.key = process.env.UNSENT_API_KEY ?? process.env.UNSENT_API_KEY;
|
|
151
193
|
}
|
|
152
194
|
if (!this.key) {
|
|
153
195
|
throw new Error(
|
|
@@ -164,10 +206,10 @@ var unsent = class {
|
|
|
164
206
|
});
|
|
165
207
|
}
|
|
166
208
|
headers;
|
|
167
|
-
// readonly domains = new Domains(this);
|
|
168
|
-
emails = new Emails(this);
|
|
169
209
|
domains = new Domains(this);
|
|
210
|
+
emails = new Emails(this);
|
|
170
211
|
contacts = new Contacts(this);
|
|
212
|
+
campaigns = new Campaigns(this);
|
|
171
213
|
url = baseUrl;
|
|
172
214
|
async fetchRequest(path, options = {}) {
|
|
173
215
|
const response = await fetch(`${this.url}${path}`, options);
|
|
@@ -178,7 +220,7 @@ var unsent = class {
|
|
|
178
220
|
if (!response.ok) {
|
|
179
221
|
try {
|
|
180
222
|
const resp = await response.json();
|
|
181
|
-
if (
|
|
223
|
+
if (isUnsentErrorResponse(resp)) {
|
|
182
224
|
return { data: null, error: resp };
|
|
183
225
|
}
|
|
184
226
|
return { data: null, error: resp.error };
|
|
@@ -236,5 +278,6 @@ var unsent = class {
|
|
|
236
278
|
}
|
|
237
279
|
};
|
|
238
280
|
export {
|
|
281
|
+
Campaigns as campaigns,
|
|
239
282
|
unsent
|
|
240
283
|
};
|
package/package.json
CHANGED
|
@@ -1,20 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unsent/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "TypeScript SDK for the Unsent API - Send transactional emails with ease",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
|
-
"
|
|
9
|
-
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/souravsspace/unsent-typescript.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://unsent.dev",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/souravsspace/unsent-typescript/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"unsent",
|
|
18
|
+
"email",
|
|
19
|
+
"transactional-email",
|
|
20
|
+
"api",
|
|
21
|
+
"sdk",
|
|
22
|
+
"typescript",
|
|
23
|
+
"react-email"
|
|
24
|
+
],
|
|
25
|
+
"author": "sourav",
|
|
10
26
|
"license": "MIT",
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
11
30
|
"devDependencies": {
|
|
12
31
|
"@types/node": "^24.7.0",
|
|
13
32
|
"@types/react": "^19.1.2",
|
|
14
33
|
"openapi-typescript": "^7.6.1",
|
|
15
34
|
"tsup": "^8.4.0",
|
|
16
35
|
"typescript": "^5.8.3",
|
|
17
|
-
"@
|
|
36
|
+
"@unsent/typescript-config": "0.0.0"
|
|
18
37
|
},
|
|
19
38
|
"dependencies": {
|
|
20
39
|
"@react-email/render": "^1.0.6",
|