resend 6.2.0 → 6.2.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/dist/index.js CHANGED
@@ -55,26 +55,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
55
55
  mod
56
56
  ));
57
57
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
58
- var __async = (__this, __arguments, generator) => {
59
- return new Promise((resolve, reject) => {
60
- var fulfilled = (value) => {
61
- try {
62
- step(generator.next(value));
63
- } catch (e) {
64
- reject(e);
65
- }
66
- };
67
- var rejected = (value) => {
68
- try {
69
- step(generator.throw(value));
70
- } catch (e) {
71
- reject(e);
72
- }
73
- };
74
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
75
- step((generator = generator.apply(__this, __arguments)).next());
76
- });
77
- };
78
58
 
79
59
  // src/index.ts
80
60
  var index_exports = {};
@@ -84,7 +64,7 @@ __export(index_exports, {
84
64
  module.exports = __toCommonJS(index_exports);
85
65
 
86
66
  // package.json
87
- var version = "6.2.0";
67
+ var version = "6.2.2";
88
68
 
89
69
  // src/common/utils/build-pagination-query.ts
90
70
  function buildPaginationQuery(options) {
@@ -106,31 +86,25 @@ var ApiKeys = class {
106
86
  constructor(resend) {
107
87
  this.resend = resend;
108
88
  }
109
- create(_0) {
110
- return __async(this, arguments, function* (payload, options = {}) {
111
- const data = yield this.resend.post(
112
- "/api-keys",
113
- payload,
114
- options
115
- );
116
- return data;
117
- });
118
- }
119
- list() {
120
- return __async(this, arguments, function* (options = {}) {
121
- const queryString = buildPaginationQuery(options);
122
- const url = queryString ? `/api-keys?${queryString}` : "/api-keys";
123
- const data = yield this.resend.get(url);
124
- return data;
125
- });
126
- }
127
- remove(id) {
128
- return __async(this, null, function* () {
129
- const data = yield this.resend.delete(
130
- `/api-keys/${id}`
131
- );
132
- return data;
133
- });
89
+ async create(payload, options = {}) {
90
+ const data = await this.resend.post(
91
+ "/api-keys",
92
+ payload,
93
+ options
94
+ );
95
+ return data;
96
+ }
97
+ async list(options = {}) {
98
+ const queryString = buildPaginationQuery(options);
99
+ const url = queryString ? `/api-keys?${queryString}` : "/api-keys";
100
+ const data = await this.resend.get(url);
101
+ return data;
102
+ }
103
+ async remove(id) {
104
+ const data = await this.resend.delete(
105
+ `/api-keys/${id}`
106
+ );
107
+ return data;
134
108
  }
135
109
  };
136
110
 
@@ -139,39 +113,31 @@ var Audiences = class {
139
113
  constructor(resend) {
140
114
  this.resend = resend;
141
115
  }
142
- create(_0) {
143
- return __async(this, arguments, function* (payload, options = {}) {
144
- const data = yield this.resend.post(
145
- "/audiences",
146
- payload,
147
- options
148
- );
149
- return data;
150
- });
151
- }
152
- list() {
153
- return __async(this, arguments, function* (options = {}) {
154
- const queryString = buildPaginationQuery(options);
155
- const url = queryString ? `/audiences?${queryString}` : "/audiences";
156
- const data = yield this.resend.get(url);
157
- return data;
158
- });
159
- }
160
- get(id) {
161
- return __async(this, null, function* () {
162
- const data = yield this.resend.get(
163
- `/audiences/${id}`
164
- );
165
- return data;
166
- });
167
- }
168
- remove(id) {
169
- return __async(this, null, function* () {
170
- const data = yield this.resend.delete(
171
- `/audiences/${id}`
172
- );
173
- return data;
174
- });
116
+ async create(payload, options = {}) {
117
+ const data = await this.resend.post(
118
+ "/audiences",
119
+ payload,
120
+ options
121
+ );
122
+ return data;
123
+ }
124
+ async list(options = {}) {
125
+ const queryString = buildPaginationQuery(options);
126
+ const url = queryString ? `/audiences?${queryString}` : "/audiences";
127
+ const data = await this.resend.get(url);
128
+ return data;
129
+ }
130
+ async get(id) {
131
+ const data = await this.resend.get(
132
+ `/audiences/${id}`
133
+ );
134
+ return data;
135
+ }
136
+ async remove(id) {
137
+ const data = await this.resend.delete(
138
+ `/audiences/${id}`
139
+ );
140
+ return data;
175
141
  }
176
142
  };
177
143
 
@@ -203,18 +169,16 @@ function parseEmailToApiOptions(email) {
203
169
  }
204
170
 
205
171
  // src/render.ts
206
- function render(node) {
207
- return new Promise((resolve, reject) => {
208
- import("@react-email/render").then(({ render: render2 }) => {
209
- resolve(render2(node));
210
- }).catch(() => {
211
- reject(
212
- Error(
213
- "Failed to render React component. Make sure to install `@react-email/render` or `@react-email/components`."
214
- )
215
- );
216
- });
217
- });
172
+ async function render(node) {
173
+ let render2;
174
+ try {
175
+ ({ render: render2 } = await import("@react-email/render"));
176
+ } catch (e) {
177
+ throw new Error(
178
+ "Failed to render React component. Make sure to install `@react-email/render` or `@react-email/components`."
179
+ );
180
+ }
181
+ return render2(node);
218
182
  }
219
183
 
220
184
  // src/batch/batch.ts
@@ -222,33 +186,29 @@ var Batch = class {
222
186
  constructor(resend) {
223
187
  this.resend = resend;
224
188
  }
225
- send(payload, options) {
226
- return __async(this, null, function* () {
227
- return this.create(payload, options);
228
- });
189
+ async send(payload, options) {
190
+ return this.create(payload, options);
229
191
  }
230
- create(payload, options) {
231
- return __async(this, null, function* () {
232
- var _a;
233
- const emails = [];
234
- for (const email of payload) {
235
- if (email.react) {
236
- email.html = yield render(email.react);
237
- email.react = void 0;
238
- }
239
- emails.push(parseEmailToApiOptions(email));
192
+ async create(payload, options) {
193
+ var _a;
194
+ const emails = [];
195
+ for (const email of payload) {
196
+ if (email.react) {
197
+ email.html = await render(email.react);
198
+ email.react = void 0;
240
199
  }
241
- const data = yield this.resend.post(
242
- "/emails/batch",
243
- emails,
244
- __spreadProps(__spreadValues({}, options), {
245
- headers: __spreadValues({
246
- "x-batch-validation": (_a = options == null ? void 0 : options.batchValidation) != null ? _a : "strict"
247
- }, options == null ? void 0 : options.headers)
248
- })
249
- );
250
- return data;
251
- });
200
+ emails.push(parseEmailToApiOptions(email));
201
+ }
202
+ const data = await this.resend.post(
203
+ "/emails/batch",
204
+ emails,
205
+ __spreadProps(__spreadValues({}, options), {
206
+ headers: __spreadValues({
207
+ "x-batch-validation": (_a = options == null ? void 0 : options.batchValidation) != null ? _a : "strict"
208
+ }, options == null ? void 0 : options.headers)
209
+ })
210
+ );
211
+ return data;
252
212
  }
253
213
  };
254
214
 
@@ -257,81 +217,69 @@ var Broadcasts = class {
257
217
  constructor(resend) {
258
218
  this.resend = resend;
259
219
  }
260
- create(_0) {
261
- return __async(this, arguments, function* (payload, options = {}) {
262
- if (payload.react) {
263
- payload.html = yield render(payload.react);
264
- }
265
- const data = yield this.resend.post(
266
- "/broadcasts",
267
- {
268
- name: payload.name,
269
- audience_id: payload.audienceId,
270
- preview_text: payload.previewText,
271
- from: payload.from,
272
- html: payload.html,
273
- reply_to: payload.replyTo,
274
- subject: payload.subject,
275
- text: payload.text
276
- },
277
- options
278
- );
279
- return data;
280
- });
281
- }
282
- send(id, payload) {
283
- return __async(this, null, function* () {
284
- const data = yield this.resend.post(
285
- `/broadcasts/${id}/send`,
286
- { scheduled_at: payload == null ? void 0 : payload.scheduledAt }
287
- );
288
- return data;
289
- });
290
- }
291
- list() {
292
- return __async(this, arguments, function* (options = {}) {
293
- const queryString = buildPaginationQuery(options);
294
- const url = queryString ? `/broadcasts?${queryString}` : "/broadcasts";
295
- const data = yield this.resend.get(url);
296
- return data;
297
- });
298
- }
299
- get(id) {
300
- return __async(this, null, function* () {
301
- const data = yield this.resend.get(
302
- `/broadcasts/${id}`
303
- );
304
- return data;
305
- });
306
- }
307
- remove(id) {
308
- return __async(this, null, function* () {
309
- const data = yield this.resend.delete(
310
- `/broadcasts/${id}`
311
- );
312
- return data;
313
- });
314
- }
315
- update(id, payload) {
316
- return __async(this, null, function* () {
317
- if (payload.react) {
318
- payload.html = yield render(payload.react);
220
+ async create(payload, options = {}) {
221
+ if (payload.react) {
222
+ payload.html = await render(payload.react);
223
+ }
224
+ const data = await this.resend.post(
225
+ "/broadcasts",
226
+ {
227
+ name: payload.name,
228
+ audience_id: payload.audienceId,
229
+ preview_text: payload.previewText,
230
+ from: payload.from,
231
+ html: payload.html,
232
+ reply_to: payload.replyTo,
233
+ subject: payload.subject,
234
+ text: payload.text
235
+ },
236
+ options
237
+ );
238
+ return data;
239
+ }
240
+ async send(id, payload) {
241
+ const data = await this.resend.post(
242
+ `/broadcasts/${id}/send`,
243
+ { scheduled_at: payload == null ? void 0 : payload.scheduledAt }
244
+ );
245
+ return data;
246
+ }
247
+ async list(options = {}) {
248
+ const queryString = buildPaginationQuery(options);
249
+ const url = queryString ? `/broadcasts?${queryString}` : "/broadcasts";
250
+ const data = await this.resend.get(url);
251
+ return data;
252
+ }
253
+ async get(id) {
254
+ const data = await this.resend.get(
255
+ `/broadcasts/${id}`
256
+ );
257
+ return data;
258
+ }
259
+ async remove(id) {
260
+ const data = await this.resend.delete(
261
+ `/broadcasts/${id}`
262
+ );
263
+ return data;
264
+ }
265
+ async update(id, payload) {
266
+ if (payload.react) {
267
+ payload.html = await render(payload.react);
268
+ }
269
+ const data = await this.resend.patch(
270
+ `/broadcasts/${id}`,
271
+ {
272
+ name: payload.name,
273
+ audience_id: payload.audienceId,
274
+ from: payload.from,
275
+ html: payload.html,
276
+ text: payload.text,
277
+ subject: payload.subject,
278
+ reply_to: payload.replyTo,
279
+ preview_text: payload.previewText
319
280
  }
320
- const data = yield this.resend.patch(
321
- `/broadcasts/${id}`,
322
- {
323
- name: payload.name,
324
- audience_id: payload.audienceId,
325
- from: payload.from,
326
- html: payload.html,
327
- text: payload.text,
328
- subject: payload.subject,
329
- reply_to: payload.replyTo,
330
- preview_text: payload.previewText
331
- }
332
- );
333
- return data;
334
- });
281
+ );
282
+ return data;
335
283
  }
336
284
  };
337
285
 
@@ -340,85 +288,78 @@ var Contacts = class {
340
288
  constructor(resend) {
341
289
  this.resend = resend;
342
290
  }
343
- create(_0) {
344
- return __async(this, arguments, function* (payload, options = {}) {
345
- const data = yield this.resend.post(
346
- `/audiences/${payload.audienceId}/contacts`,
347
- {
348
- unsubscribed: payload.unsubscribed,
349
- email: payload.email,
350
- first_name: payload.firstName,
351
- last_name: payload.lastName
352
- },
353
- options
354
- );
355
- return data;
356
- });
357
- }
358
- list(options) {
359
- return __async(this, null, function* () {
360
- const _a = options, { audienceId } = _a, paginationOptions = __objRest(_a, ["audienceId"]);
361
- const queryString = buildPaginationQuery(paginationOptions);
362
- const url = queryString ? `/audiences/${audienceId}/contacts?${queryString}` : `/audiences/${audienceId}/contacts`;
363
- const data = yield this.resend.get(url);
364
- return data;
365
- });
366
- }
367
- get(options) {
368
- return __async(this, null, function* () {
369
- if (!options.id && !options.email) {
370
- return {
371
- data: null,
372
- error: {
373
- message: "Missing `id` or `email` field.",
374
- name: "missing_required_field"
375
- }
376
- };
377
- }
378
- const data = yield this.resend.get(
379
- `/audiences/${options.audienceId}/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`
380
- );
381
- return data;
382
- });
383
- }
384
- update(options) {
385
- return __async(this, null, function* () {
386
- if (!options.id && !options.email) {
387
- return {
388
- data: null,
389
- error: {
390
- message: "Missing `id` or `email` field.",
391
- name: "missing_required_field"
392
- }
393
- };
394
- }
395
- const data = yield this.resend.patch(
396
- `/audiences/${options.audienceId}/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`,
397
- {
398
- unsubscribed: options.unsubscribed,
399
- first_name: options.firstName,
400
- last_name: options.lastName
291
+ async create(payload, options = {}) {
292
+ const data = await this.resend.post(
293
+ `/audiences/${payload.audienceId}/contacts`,
294
+ {
295
+ unsubscribed: payload.unsubscribed,
296
+ email: payload.email,
297
+ first_name: payload.firstName,
298
+ last_name: payload.lastName
299
+ },
300
+ options
301
+ );
302
+ return data;
303
+ }
304
+ async list(options) {
305
+ const _a = options, { audienceId } = _a, paginationOptions = __objRest(_a, ["audienceId"]);
306
+ const queryString = buildPaginationQuery(paginationOptions);
307
+ const url = queryString ? `/audiences/${audienceId}/contacts?${queryString}` : `/audiences/${audienceId}/contacts`;
308
+ const data = await this.resend.get(url);
309
+ return data;
310
+ }
311
+ async get(options) {
312
+ if (!options.id && !options.email) {
313
+ return {
314
+ data: null,
315
+ error: {
316
+ message: "Missing `id` or `email` field.",
317
+ statusCode: null,
318
+ name: "missing_required_field"
401
319
  }
402
- );
403
- return data;
404
- });
405
- }
406
- remove(payload) {
407
- return __async(this, null, function* () {
408
- if (!payload.id && !payload.email) {
409
- return {
410
- data: null,
411
- error: {
412
- message: "Missing `id` or `email` field.",
413
- name: "missing_required_field"
414
- }
415
- };
320
+ };
321
+ }
322
+ const data = await this.resend.get(
323
+ `/audiences/${options.audienceId}/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`
324
+ );
325
+ return data;
326
+ }
327
+ async update(options) {
328
+ if (!options.id && !options.email) {
329
+ return {
330
+ data: null,
331
+ error: {
332
+ message: "Missing `id` or `email` field.",
333
+ statusCode: null,
334
+ name: "missing_required_field"
335
+ }
336
+ };
337
+ }
338
+ const data = await this.resend.patch(
339
+ `/audiences/${options.audienceId}/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`,
340
+ {
341
+ unsubscribed: options.unsubscribed,
342
+ first_name: options.firstName,
343
+ last_name: options.lastName
416
344
  }
417
- const data = yield this.resend.delete(
418
- `/audiences/${payload.audienceId}/contacts/${(payload == null ? void 0 : payload.email) ? payload == null ? void 0 : payload.email : payload == null ? void 0 : payload.id}`
419
- );
420
- return data;
421
- });
345
+ );
346
+ return data;
347
+ }
348
+ async remove(payload) {
349
+ if (!payload.id && !payload.email) {
350
+ return {
351
+ data: null,
352
+ error: {
353
+ message: "Missing `id` or `email` field.",
354
+ statusCode: null,
355
+ name: "missing_required_field"
356
+ }
357
+ };
358
+ }
359
+ const data = await this.resend.delete(
360
+ `/audiences/${payload.audienceId}/contacts/${(payload == null ? void 0 : payload.email) ? payload == null ? void 0 : payload.email : payload == null ? void 0 : payload.id}`
361
+ );
362
+ return data;
422
363
  }
423
364
  };
424
365
 
@@ -436,60 +377,48 @@ var Domains = class {
436
377
  constructor(resend) {
437
378
  this.resend = resend;
438
379
  }
439
- create(_0) {
440
- return __async(this, arguments, function* (payload, options = {}) {
441
- const data = yield this.resend.post(
442
- "/domains",
443
- parseDomainToApiOptions(payload),
444
- options
445
- );
446
- return data;
447
- });
448
- }
449
- list() {
450
- return __async(this, arguments, function* (options = {}) {
451
- const queryString = buildPaginationQuery(options);
452
- const url = queryString ? `/domains?${queryString}` : "/domains";
453
- const data = yield this.resend.get(url);
454
- return data;
455
- });
380
+ async create(payload, options = {}) {
381
+ const data = await this.resend.post(
382
+ "/domains",
383
+ parseDomainToApiOptions(payload),
384
+ options
385
+ );
386
+ return data;
387
+ }
388
+ async list(options = {}) {
389
+ const queryString = buildPaginationQuery(options);
390
+ const url = queryString ? `/domains?${queryString}` : "/domains";
391
+ const data = await this.resend.get(url);
392
+ return data;
393
+ }
394
+ async get(id) {
395
+ const data = await this.resend.get(
396
+ `/domains/${id}`
397
+ );
398
+ return data;
399
+ }
400
+ async update(payload) {
401
+ const data = await this.resend.patch(
402
+ `/domains/${payload.id}`,
403
+ {
404
+ click_tracking: payload.clickTracking,
405
+ open_tracking: payload.openTracking,
406
+ tls: payload.tls
407
+ }
408
+ );
409
+ return data;
456
410
  }
457
- get(id) {
458
- return __async(this, null, function* () {
459
- const data = yield this.resend.get(
460
- `/domains/${id}`
461
- );
462
- return data;
463
- });
411
+ async remove(id) {
412
+ const data = await this.resend.delete(
413
+ `/domains/${id}`
414
+ );
415
+ return data;
464
416
  }
465
- update(payload) {
466
- return __async(this, null, function* () {
467
- const data = yield this.resend.patch(
468
- `/domains/${payload.id}`,
469
- {
470
- click_tracking: payload.clickTracking,
471
- open_tracking: payload.openTracking,
472
- tls: payload.tls
473
- }
474
- );
475
- return data;
476
- });
477
- }
478
- remove(id) {
479
- return __async(this, null, function* () {
480
- const data = yield this.resend.delete(
481
- `/domains/${id}`
482
- );
483
- return data;
484
- });
485
- }
486
- verify(id) {
487
- return __async(this, null, function* () {
488
- const data = yield this.resend.post(
489
- `/domains/${id}/verify`
490
- );
491
- return data;
492
- });
417
+ async verify(id) {
418
+ const data = await this.resend.post(
419
+ `/domains/${id}/verify`
420
+ );
421
+ return data;
493
422
  }
494
423
  };
495
424
 
@@ -498,58 +427,46 @@ var Emails = class {
498
427
  constructor(resend) {
499
428
  this.resend = resend;
500
429
  }
501
- send(_0) {
502
- return __async(this, arguments, function* (payload, options = {}) {
503
- return this.create(payload, options);
504
- });
430
+ async send(payload, options = {}) {
431
+ return this.create(payload, options);
505
432
  }
506
- create(_0) {
507
- return __async(this, arguments, function* (payload, options = {}) {
508
- if (payload.react) {
509
- payload.html = yield render(payload.react);
433
+ async create(payload, options = {}) {
434
+ if (payload.react) {
435
+ payload.html = await render(payload.react);
436
+ }
437
+ const data = await this.resend.post(
438
+ "/emails",
439
+ parseEmailToApiOptions(payload),
440
+ options
441
+ );
442
+ return data;
443
+ }
444
+ async get(id) {
445
+ const data = await this.resend.get(
446
+ `/emails/${id}`
447
+ );
448
+ return data;
449
+ }
450
+ async list(options = {}) {
451
+ const queryString = buildPaginationQuery(options);
452
+ const url = queryString ? `/emails?${queryString}` : "/emails";
453
+ const data = await this.resend.get(url);
454
+ return data;
455
+ }
456
+ async update(payload) {
457
+ const data = await this.resend.patch(
458
+ `/emails/${payload.id}`,
459
+ {
460
+ scheduled_at: payload.scheduledAt
510
461
  }
511
- const data = yield this.resend.post(
512
- "/emails",
513
- parseEmailToApiOptions(payload),
514
- options
515
- );
516
- return data;
517
- });
518
- }
519
- get(id) {
520
- return __async(this, null, function* () {
521
- const data = yield this.resend.get(
522
- `/emails/${id}`
523
- );
524
- return data;
525
- });
462
+ );
463
+ return data;
526
464
  }
527
- list() {
528
- return __async(this, arguments, function* (options = {}) {
529
- const queryString = buildPaginationQuery(options);
530
- const url = queryString ? `/emails?${queryString}` : "/emails";
531
- const data = yield this.resend.get(url);
532
- return data;
533
- });
534
- }
535
- update(payload) {
536
- return __async(this, null, function* () {
537
- const data = yield this.resend.patch(
538
- `/emails/${payload.id}`,
539
- {
540
- scheduled_at: payload.scheduledAt
541
- }
542
- );
543
- return data;
544
- });
545
- }
546
- cancel(id) {
547
- return __async(this, null, function* () {
548
- const data = yield this.resend.post(
549
- `/emails/${id}/cancel`
550
- );
551
- return data;
552
- });
465
+ async cancel(id) {
466
+ const data = await this.resend.post(
467
+ `/emails/${id}/cancel`
468
+ );
469
+ return data;
553
470
  }
554
471
  };
555
472
 
@@ -598,126 +515,117 @@ var Resend = class {
598
515
  "Content-Type": "application/json"
599
516
  });
600
517
  }
601
- fetchRequest(_0) {
602
- return __async(this, arguments, function* (path, options = {}) {
603
- try {
604
- const response = yield fetch(`${baseUrl}${path}`, options);
605
- if (!response.ok) {
606
- try {
607
- const rawError = yield response.text();
608
- return { data: null, error: JSON.parse(rawError) };
609
- } catch (err) {
610
- if (err instanceof SyntaxError) {
611
- return {
612
- data: null,
613
- error: {
614
- name: "application_error",
615
- message: "Internal server error. We are unable to process your request right now, please try again later."
616
- }
617
- };
618
- }
619
- const error = {
620
- message: response.statusText,
621
- name: "application_error"
518
+ async fetchRequest(path, options = {}) {
519
+ try {
520
+ const response = await fetch(`${baseUrl}${path}`, options);
521
+ if (!response.ok) {
522
+ try {
523
+ const rawError = await response.text();
524
+ return { data: null, error: JSON.parse(rawError) };
525
+ } catch (err) {
526
+ if (err instanceof SyntaxError) {
527
+ return {
528
+ data: null,
529
+ error: {
530
+ name: "application_error",
531
+ statusCode: response.status,
532
+ message: "Internal server error. We are unable to process your request right now, please try again later."
533
+ }
622
534
  };
623
- if (err instanceof Error) {
624
- return { data: null, error: __spreadProps(__spreadValues({}, error), { message: err.message }) };
625
- }
626
- return { data: null, error };
627
535
  }
628
- }
629
- const data = yield response.json();
630
- return { data, error: null };
631
- } catch (e) {
632
- return {
633
- data: null,
634
- error: {
635
- name: "application_error",
636
- message: "Unable to fetch data. The request could not be resolved."
536
+ const error = {
537
+ message: response.statusText,
538
+ statusCode: response.status,
539
+ name: "application_error"
540
+ };
541
+ if (err instanceof Error) {
542
+ return { data: null, error: __spreadProps(__spreadValues({}, error), { message: err.message }) };
637
543
  }
638
- };
639
- }
640
- });
641
- }
642
- post(_0, _1) {
643
- return __async(this, arguments, function* (path, entity, options = {}) {
644
- const headers = new Headers(this.headers);
645
- if (options.headers) {
646
- for (const [key, value] of new Headers(options.headers).entries()) {
647
- headers.set(key, value);
544
+ return { data: null, error };
648
545
  }
649
546
  }
650
- if (options.idempotencyKey) {
651
- headers.set("Idempotency-Key", options.idempotencyKey);
652
- }
653
- const requestOptions = __spreadProps(__spreadValues({
654
- method: "POST",
655
- body: JSON.stringify(entity)
656
- }, options), {
657
- headers
658
- });
659
- return this.fetchRequest(path, requestOptions);
660
- });
661
- }
662
- get(_0) {
663
- return __async(this, arguments, function* (path, options = {}) {
664
- const headers = new Headers(this.headers);
665
- if (options.headers) {
666
- for (const [key, value] of new Headers(options.headers).entries()) {
667
- headers.set(key, value);
547
+ const data = await response.json();
548
+ return { data, error: null };
549
+ } catch (e) {
550
+ return {
551
+ data: null,
552
+ error: {
553
+ name: "application_error",
554
+ statusCode: null,
555
+ message: "Unable to fetch data. The request could not be resolved."
668
556
  }
669
- }
670
- const requestOptions = __spreadProps(__spreadValues({
671
- method: "GET"
672
- }, options), {
673
- headers
674
- });
675
- return this.fetchRequest(path, requestOptions);
676
- });
557
+ };
558
+ }
677
559
  }
678
- put(_0, _1) {
679
- return __async(this, arguments, function* (path, entity, options = {}) {
680
- const headers = new Headers(this.headers);
681
- if (options.headers) {
682
- for (const [key, value] of new Headers(options.headers).entries()) {
683
- headers.set(key, value);
684
- }
560
+ async post(path, entity, options = {}) {
561
+ const headers = new Headers(this.headers);
562
+ if (options.headers) {
563
+ for (const [key, value] of new Headers(options.headers).entries()) {
564
+ headers.set(key, value);
685
565
  }
686
- const requestOptions = __spreadProps(__spreadValues({
687
- method: "PUT",
688
- body: JSON.stringify(entity)
689
- }, options), {
690
- headers
691
- });
692
- return this.fetchRequest(path, requestOptions);
693
- });
694
- }
695
- patch(_0, _1) {
696
- return __async(this, arguments, function* (path, entity, options = {}) {
697
- const headers = new Headers(this.headers);
698
- if (options.headers) {
699
- for (const [key, value] of new Headers(options.headers).entries()) {
700
- headers.set(key, value);
701
- }
566
+ }
567
+ if (options.idempotencyKey) {
568
+ headers.set("Idempotency-Key", options.idempotencyKey);
569
+ }
570
+ const requestOptions = __spreadProps(__spreadValues({
571
+ method: "POST",
572
+ body: JSON.stringify(entity)
573
+ }, options), {
574
+ headers
575
+ });
576
+ return this.fetchRequest(path, requestOptions);
577
+ }
578
+ async get(path, options = {}) {
579
+ const headers = new Headers(this.headers);
580
+ if (options.headers) {
581
+ for (const [key, value] of new Headers(options.headers).entries()) {
582
+ headers.set(key, value);
702
583
  }
703
- const requestOptions = __spreadProps(__spreadValues({
704
- method: "PATCH",
705
- body: JSON.stringify(entity)
706
- }, options), {
707
- headers
708
- });
709
- return this.fetchRequest(path, requestOptions);
710
- });
711
- }
712
- delete(path, query) {
713
- return __async(this, null, function* () {
714
- const requestOptions = {
715
- method: "DELETE",
716
- body: JSON.stringify(query),
717
- headers: this.headers
718
- };
719
- return this.fetchRequest(path, requestOptions);
720
- });
584
+ }
585
+ const requestOptions = __spreadProps(__spreadValues({
586
+ method: "GET"
587
+ }, options), {
588
+ headers
589
+ });
590
+ return this.fetchRequest(path, requestOptions);
591
+ }
592
+ async put(path, entity, options = {}) {
593
+ const headers = new Headers(this.headers);
594
+ if (options.headers) {
595
+ for (const [key, value] of new Headers(options.headers).entries()) {
596
+ headers.set(key, value);
597
+ }
598
+ }
599
+ const requestOptions = __spreadProps(__spreadValues({
600
+ method: "PUT",
601
+ body: JSON.stringify(entity)
602
+ }, options), {
603
+ headers
604
+ });
605
+ return this.fetchRequest(path, requestOptions);
606
+ }
607
+ async patch(path, entity, options = {}) {
608
+ const headers = new Headers(this.headers);
609
+ if (options.headers) {
610
+ for (const [key, value] of new Headers(options.headers).entries()) {
611
+ headers.set(key, value);
612
+ }
613
+ }
614
+ const requestOptions = __spreadProps(__spreadValues({
615
+ method: "PATCH",
616
+ body: JSON.stringify(entity)
617
+ }, options), {
618
+ headers
619
+ });
620
+ return this.fetchRequest(path, requestOptions);
621
+ }
622
+ async delete(path, query) {
623
+ const requestOptions = {
624
+ method: "DELETE",
625
+ body: JSON.stringify(query),
626
+ headers: this.headers
627
+ };
628
+ return this.fetchRequest(path, requestOptions);
721
629
  }
722
630
  };
723
631
  // Annotate the CommonJS export names for ESM import in node: