@unsent/sdk 1.0.1 → 1.0.2
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 +3 -3
- package/dist/index.js +19 -5
- package/dist/index.mjs +19 -5
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ bun add @unsent/sdk
|
|
|
38
38
|
```typescript
|
|
39
39
|
import { unsent } from "@unsent/sdk";
|
|
40
40
|
|
|
41
|
-
const client = new unsent("
|
|
41
|
+
const client = new unsent("un_xxxx");
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
### Environment Variables
|
|
@@ -303,7 +303,7 @@ Create and manage email campaigns:
|
|
|
303
303
|
```typescript
|
|
304
304
|
import { unsent } from "@unsent/sdk";
|
|
305
305
|
|
|
306
|
-
const client = new unsent("
|
|
306
|
+
const client = new unsent("un_xxxx");
|
|
307
307
|
|
|
308
308
|
// Create a campaign
|
|
309
309
|
const campaign = await client.campaigns.create({
|
|
@@ -390,7 +390,7 @@ The SDK is fully typed with TypeScript:
|
|
|
390
390
|
```typescript
|
|
391
391
|
import { unsent } from "@unsent/sdk";
|
|
392
392
|
|
|
393
|
-
const client = new unsent("
|
|
393
|
+
const client = new unsent("un_xxxx");
|
|
394
394
|
|
|
395
395
|
// Full type inference and autocomplete
|
|
396
396
|
const result = await client.emails.send({
|
package/dist/index.js
CHANGED
|
@@ -222,12 +222,12 @@ var unsent = class {
|
|
|
222
222
|
}
|
|
223
223
|
if (!this.key) {
|
|
224
224
|
throw new Error(
|
|
225
|
-
'Missing API key. Pass it to the constructor `new unsent("
|
|
225
|
+
'Missing API key. Pass it to the constructor `new unsent("un_xxxx")`'
|
|
226
226
|
);
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
229
|
if (url) {
|
|
230
|
-
this.url = `${url}/
|
|
230
|
+
this.url = `${url}/v1`;
|
|
231
231
|
}
|
|
232
232
|
this.headers = new Headers({
|
|
233
233
|
Authorization: `Bearer ${this.key}`,
|
|
@@ -241,7 +241,8 @@ var unsent = class {
|
|
|
241
241
|
campaigns = new Campaigns(this);
|
|
242
242
|
url = baseUrl;
|
|
243
243
|
async fetchRequest(path, options = {}) {
|
|
244
|
-
const
|
|
244
|
+
const fullUrl = `${this.url}${path}`;
|
|
245
|
+
const response = await fetch(fullUrl, options);
|
|
245
246
|
const defaultError = {
|
|
246
247
|
code: "INTERNAL_SERVER_ERROR",
|
|
247
248
|
message: response.statusText
|
|
@@ -263,8 +264,21 @@ var unsent = class {
|
|
|
263
264
|
return { data: null, error: defaultError };
|
|
264
265
|
}
|
|
265
266
|
}
|
|
266
|
-
|
|
267
|
-
|
|
267
|
+
try {
|
|
268
|
+
const data = await response.json();
|
|
269
|
+
return { data, error: null };
|
|
270
|
+
} catch (err) {
|
|
271
|
+
if (err instanceof Error && err.message.includes("JSON")) {
|
|
272
|
+
return {
|
|
273
|
+
data: null,
|
|
274
|
+
error: {
|
|
275
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
276
|
+
message: "Invalid JSON response from server"
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
throw err;
|
|
281
|
+
}
|
|
268
282
|
}
|
|
269
283
|
async post(path, body, options) {
|
|
270
284
|
const headers = new Headers(this.headers);
|
package/dist/index.mjs
CHANGED
|
@@ -195,12 +195,12 @@ var unsent = class {
|
|
|
195
195
|
}
|
|
196
196
|
if (!this.key) {
|
|
197
197
|
throw new Error(
|
|
198
|
-
'Missing API key. Pass it to the constructor `new unsent("
|
|
198
|
+
'Missing API key. Pass it to the constructor `new unsent("un_xxxx")`'
|
|
199
199
|
);
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
202
|
if (url) {
|
|
203
|
-
this.url = `${url}/
|
|
203
|
+
this.url = `${url}/v1`;
|
|
204
204
|
}
|
|
205
205
|
this.headers = new Headers({
|
|
206
206
|
Authorization: `Bearer ${this.key}`,
|
|
@@ -214,7 +214,8 @@ var unsent = class {
|
|
|
214
214
|
campaigns = new Campaigns(this);
|
|
215
215
|
url = baseUrl;
|
|
216
216
|
async fetchRequest(path, options = {}) {
|
|
217
|
-
const
|
|
217
|
+
const fullUrl = `${this.url}${path}`;
|
|
218
|
+
const response = await fetch(fullUrl, options);
|
|
218
219
|
const defaultError = {
|
|
219
220
|
code: "INTERNAL_SERVER_ERROR",
|
|
220
221
|
message: response.statusText
|
|
@@ -236,8 +237,21 @@ var unsent = class {
|
|
|
236
237
|
return { data: null, error: defaultError };
|
|
237
238
|
}
|
|
238
239
|
}
|
|
239
|
-
|
|
240
|
-
|
|
240
|
+
try {
|
|
241
|
+
const data = await response.json();
|
|
242
|
+
return { data, error: null };
|
|
243
|
+
} catch (err) {
|
|
244
|
+
if (err instanceof Error && err.message.includes("JSON")) {
|
|
245
|
+
return {
|
|
246
|
+
data: null,
|
|
247
|
+
error: {
|
|
248
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
249
|
+
message: "Invalid JSON response from server"
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
throw err;
|
|
254
|
+
}
|
|
241
255
|
}
|
|
242
256
|
async post(path, body, options) {
|
|
243
257
|
const headers = new Headers(this.headers);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unsent/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
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",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@types/node": "^24.7.0",
|
|
32
32
|
"@types/react": "^19.1.2",
|
|
33
33
|
"openapi-typescript": "^7.6.1",
|
|
34
|
-
"tsup": "^8.
|
|
34
|
+
"tsup": "^8.5.0",
|
|
35
35
|
"typescript": "^5.8.3",
|
|
36
36
|
"@unsent/typescript-config": "0.0.0"
|
|
37
37
|
},
|