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