zupost 0.1.0 → 0.2.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.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
6
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
10
  var __typeError = (msg) => {
@@ -23,19 +23,6 @@ var __spreadValues = (a, b) => {
23
23
  }
24
24
  return a;
25
25
  };
26
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
27
- var __objRest = (source, exclude) => {
28
- var target = {};
29
- for (var prop in source)
30
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
31
- target[prop] = source[prop];
32
- if (source != null && __getOwnPropSymbols)
33
- for (var prop of __getOwnPropSymbols(source)) {
34
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
35
- target[prop] = source[prop];
36
- }
37
- return target;
38
- };
39
26
  var __export = (target, all) => {
40
27
  for (var name in all)
41
28
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -48,21 +35,19 @@ var __copyProps = (to, from, except, desc) => {
48
35
  }
49
36
  return to;
50
37
  };
38
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
39
+ // If the importer is in node compatibility mode or this is not an ESM
40
+ // file that has been converted to a CommonJS file using a Babel-
41
+ // compatible transform (i.e. "__esModule" has not been set), then set
42
+ // "default" to the CommonJS "module.exports" for node compatibility.
43
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
44
+ mod
45
+ ));
51
46
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
52
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
53
47
  var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
54
48
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
55
49
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
56
50
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
57
- var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
58
- var __privateWrapper = (obj, member, setter, getter) => ({
59
- set _(value) {
60
- __privateSet(obj, member, value, setter);
61
- },
62
- get _() {
63
- return __privateGet(obj, member, getter);
64
- }
65
- });
66
51
  var __async = (__this, __arguments, generator) => {
67
52
  return new Promise((resolve, reject) => {
68
53
  var fulfilled = (value) => {
@@ -87,900 +72,174 @@ var __async = (__this, __arguments, generator) => {
87
72
  // src/index.ts
88
73
  var index_exports = {};
89
74
  __export(index_exports, {
90
- Zupost: () => Zupost
75
+ Zupost: () => Zupost,
76
+ ZupostError: () => ZupostError
91
77
  });
92
78
  module.exports = __toCommonJS(index_exports);
93
79
 
94
80
  // package.json
95
- var version = "0.1.0";
96
-
97
- // node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/errors/HTTPError.js
98
- var HTTPError = class extends Error {
99
- constructor(response, request, options) {
100
- var _a;
101
- const code = response.status || response.status === 0 ? response.status : "";
102
- const title = (_a = response.statusText) != null ? _a : "";
103
- const status = `${code} ${title}`.trim();
104
- const reason = status ? `status code ${status}` : "an unknown error";
105
- super(`Request failed with ${reason}: ${request.method} ${request.url}`);
106
- __publicField(this, "response");
107
- __publicField(this, "request");
108
- __publicField(this, "options");
109
- this.name = "HTTPError";
110
- this.response = response;
111
- this.request = request;
112
- this.options = options;
113
- }
114
- };
115
-
116
- // node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/errors/NonError.js
117
- var NonError = class extends Error {
118
- constructor(value) {
119
- let message = "Non-error value was thrown";
120
- try {
121
- if (typeof value === "string") {
122
- message = value;
123
- } else if (value && typeof value === "object" && "message" in value && typeof value.message === "string") {
124
- message = value.message;
125
- }
126
- } catch (e) {
127
- }
128
- super(message);
129
- __publicField(this, "name", "NonError");
130
- __publicField(this, "value");
131
- this.value = value;
132
- }
133
- };
134
-
135
- // node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/errors/ForceRetryError.js
136
- var ForceRetryError = class extends Error {
137
- constructor(options) {
138
- const cause = (options == null ? void 0 : options.cause) ? options.cause instanceof Error ? options.cause : new NonError(options.cause) : void 0;
139
- super((options == null ? void 0 : options.code) ? `Forced retry: ${options.code}` : "Forced retry", cause ? { cause } : void 0);
140
- __publicField(this, "name", "ForceRetryError");
141
- __publicField(this, "customDelay");
142
- __publicField(this, "code");
143
- __publicField(this, "customRequest");
144
- this.customDelay = options == null ? void 0 : options.delay;
145
- this.code = options == null ? void 0 : options.code;
146
- this.customRequest = options == null ? void 0 : options.request;
147
- }
148
- };
149
-
150
- // node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/core/constants.js
151
- var supportsRequestStreams = (() => {
152
- let duplexAccessed = false;
153
- let hasContentType = false;
154
- const supportsReadableStream = typeof globalThis.ReadableStream === "function";
155
- const supportsRequest = typeof globalThis.Request === "function";
156
- if (supportsReadableStream && supportsRequest) {
157
- try {
158
- hasContentType = new globalThis.Request("https://empty.invalid", {
159
- body: new globalThis.ReadableStream(),
160
- method: "POST",
161
- // @ts-expect-error - Types are outdated.
162
- get duplex() {
163
- duplexAccessed = true;
164
- return "half";
165
- }
166
- }).headers.has("Content-Type");
167
- } catch (error) {
168
- if (error instanceof Error && error.message === "unsupported BodyInit type") {
169
- return false;
170
- }
171
- throw error;
172
- }
173
- }
174
- return duplexAccessed && !hasContentType;
175
- })();
176
- var supportsAbortController = typeof globalThis.AbortController === "function";
177
- var supportsAbortSignal = typeof globalThis.AbortSignal === "function" && typeof globalThis.AbortSignal.any === "function";
178
- var supportsResponseStreams = typeof globalThis.ReadableStream === "function";
179
- var supportsFormData = typeof globalThis.FormData === "function";
180
- var requestMethods = ["get", "post", "put", "patch", "head", "delete"];
181
- var validate = () => void 0;
182
- validate();
183
- var responseTypes = {
184
- json: "application/json",
185
- text: "text/*",
186
- formData: "multipart/form-data",
187
- arrayBuffer: "*/*",
188
- blob: "*/*",
189
- // Supported in modern Fetch implementations (for example, browsers and recent Node.js/undici).
190
- // We still feature-check at runtime before exposing the shortcut.
191
- bytes: "*/*"
192
- };
193
- var maxSafeTimeout = 2147483647;
194
- var usualFormBoundarySize = new TextEncoder().encode("------WebKitFormBoundaryaxpyiPgbbPti10Rw").length;
195
- var stop = /* @__PURE__ */ Symbol("stop");
196
- var RetryMarker = class {
197
- constructor(options) {
198
- __publicField(this, "options");
199
- this.options = options;
200
- }
201
- };
202
- var retry = (options) => new RetryMarker(options);
203
- var kyOptionKeys = {
204
- json: true,
205
- parseJson: true,
206
- stringifyJson: true,
207
- searchParams: true,
208
- prefixUrl: true,
209
- retry: true,
210
- timeout: true,
211
- hooks: true,
212
- throwHttpErrors: true,
213
- onDownloadProgress: true,
214
- onUploadProgress: true,
215
- fetch: true,
216
- context: true
217
- };
218
- var vendorSpecificOptions = {
219
- next: true
220
- // Next.js cache revalidation (revalidate, tags)
221
- };
222
- var requestOptionsRegistry = {
223
- method: true,
224
- headers: true,
225
- body: true,
226
- mode: true,
227
- credentials: true,
228
- cache: true,
229
- redirect: true,
230
- referrer: true,
231
- referrerPolicy: true,
232
- integrity: true,
233
- keepalive: true,
234
- signal: true,
235
- window: true,
236
- duplex: true
237
- };
81
+ var version = "0.2.0";
238
82
 
239
- // node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/utils/body.js
240
- var getBodySize = (body) => {
241
- if (!body) {
242
- return 0;
243
- }
244
- if (body instanceof FormData) {
245
- let size = 0;
246
- for (const [key, value] of body) {
247
- size += usualFormBoundarySize;
248
- size += new TextEncoder().encode(`Content-Disposition: form-data; name="${key}"`).length;
249
- size += typeof value === "string" ? new TextEncoder().encode(value).length : value.size;
250
- }
251
- return size;
252
- }
253
- if (body instanceof Blob) {
254
- return body.size;
255
- }
256
- if (body instanceof ArrayBuffer) {
257
- return body.byteLength;
258
- }
259
- if (typeof body === "string") {
260
- return new TextEncoder().encode(body).length;
261
- }
262
- if (body instanceof URLSearchParams) {
263
- return new TextEncoder().encode(body.toString()).length;
264
- }
265
- if ("byteLength" in body) {
266
- return body.byteLength;
267
- }
268
- if (typeof body === "object" && body !== null) {
269
- try {
270
- const jsonString = JSON.stringify(body);
271
- return new TextEncoder().encode(jsonString).length;
272
- } catch (e) {
273
- return 0;
274
- }
275
- }
276
- return 0;
277
- };
278
- var withProgress = (stream, totalBytes, onProgress) => {
279
- let previousChunk;
280
- let transferredBytes = 0;
281
- return stream.pipeThrough(new TransformStream({
282
- transform(currentChunk, controller) {
283
- controller.enqueue(currentChunk);
284
- if (previousChunk) {
285
- transferredBytes += previousChunk.byteLength;
286
- let percent = totalBytes === 0 ? 0 : transferredBytes / totalBytes;
287
- if (percent >= 1) {
288
- percent = 1 - Number.EPSILON;
289
- }
290
- onProgress == null ? void 0 : onProgress({ percent, totalBytes: Math.max(totalBytes, transferredBytes), transferredBytes }, previousChunk);
291
- }
292
- previousChunk = currentChunk;
293
- },
294
- flush() {
295
- if (previousChunk) {
296
- transferredBytes += previousChunk.byteLength;
297
- onProgress == null ? void 0 : onProgress({ percent: 1, totalBytes: Math.max(totalBytes, transferredBytes), transferredBytes }, previousChunk);
298
- }
299
- }
300
- }));
301
- };
302
- var streamResponse = (response, onDownloadProgress) => {
303
- if (!response.body) {
304
- return response;
305
- }
306
- if (response.status === 204) {
307
- return new Response(null, {
308
- status: response.status,
309
- statusText: response.statusText,
310
- headers: response.headers
311
- });
312
- }
313
- const totalBytes = Math.max(0, Number(response.headers.get("content-length")) || 0);
314
- return new Response(withProgress(response.body, totalBytes, onDownloadProgress), {
315
- status: response.status,
316
- statusText: response.statusText,
317
- headers: response.headers
318
- });
319
- };
320
- var streamRequest = (request, onUploadProgress, originalBody) => {
321
- if (!request.body) {
322
- return request;
323
- }
324
- const totalBytes = getBodySize(originalBody != null ? originalBody : request.body);
325
- return new Request(request, {
326
- // @ts-expect-error - Types are outdated.
327
- duplex: "half",
328
- body: withProgress(request.body, totalBytes, onUploadProgress)
329
- });
330
- };
331
-
332
- // node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/utils/is.js
333
- var isObject = (value) => value !== null && typeof value === "object";
334
-
335
- // node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/utils/merge.js
336
- var validateAndMerge = (...sources) => {
337
- for (const source of sources) {
338
- if ((!isObject(source) || Array.isArray(source)) && source !== void 0) {
339
- throw new TypeError("The `options` argument must be an object");
340
- }
341
- }
342
- return deepMerge({}, ...sources);
343
- };
344
- var mergeHeaders = (source1 = {}, source2 = {}) => {
345
- const result = new globalThis.Headers(source1);
346
- const isHeadersInstance = source2 instanceof globalThis.Headers;
347
- const source = new globalThis.Headers(source2);
348
- for (const [key, value] of source.entries()) {
349
- if (isHeadersInstance && value === "undefined" || value === void 0) {
350
- result.delete(key);
351
- } else {
352
- result.set(key, value);
353
- }
354
- }
355
- return result;
356
- };
357
- function newHookValue(original, incoming, property) {
358
- var _a, _b;
359
- return Object.hasOwn(incoming, property) && incoming[property] === void 0 ? [] : deepMerge((_a = original[property]) != null ? _a : [], (_b = incoming[property]) != null ? _b : []);
360
- }
361
- var mergeHooks = (original = {}, incoming = {}) => ({
362
- beforeRequest: newHookValue(original, incoming, "beforeRequest"),
363
- beforeRetry: newHookValue(original, incoming, "beforeRetry"),
364
- afterResponse: newHookValue(original, incoming, "afterResponse"),
365
- beforeError: newHookValue(original, incoming, "beforeError")
366
- });
367
- var appendSearchParameters = (target, source) => {
368
- const result = new URLSearchParams();
369
- for (const input of [target, source]) {
370
- if (input === void 0) {
371
- continue;
372
- }
373
- if (input instanceof URLSearchParams) {
374
- for (const [key, value] of input.entries()) {
375
- result.append(key, value);
376
- }
377
- } else if (Array.isArray(input)) {
378
- for (const pair of input) {
379
- if (!Array.isArray(pair) || pair.length !== 2) {
380
- throw new TypeError("Array search parameters must be provided in [[key, value], ...] format");
381
- }
382
- result.append(String(pair[0]), String(pair[1]));
383
- }
384
- } else if (isObject(input)) {
385
- for (const [key, value] of Object.entries(input)) {
386
- if (value !== void 0) {
387
- result.append(key, String(value));
388
- }
389
- }
390
- } else {
391
- const parameters = new URLSearchParams(input);
392
- for (const [key, value] of parameters.entries()) {
393
- result.append(key, value);
394
- }
395
- }
396
- }
397
- return result;
398
- };
399
- var deepMerge = (...sources) => {
400
- let returnValue = {};
401
- let headers = {};
402
- let hooks = {};
403
- let searchParameters;
404
- const signals = [];
405
- for (const source of sources) {
406
- if (Array.isArray(source)) {
407
- if (!Array.isArray(returnValue)) {
408
- returnValue = [];
409
- }
410
- returnValue = [...returnValue, ...source];
411
- } else if (isObject(source)) {
412
- for (let [key, value] of Object.entries(source)) {
413
- if (key === "signal" && value instanceof globalThis.AbortSignal) {
414
- signals.push(value);
415
- continue;
416
- }
417
- if (key === "context") {
418
- if (value !== void 0 && value !== null && (!isObject(value) || Array.isArray(value))) {
419
- throw new TypeError("The `context` option must be an object");
420
- }
421
- returnValue = __spreadProps(__spreadValues({}, returnValue), {
422
- context: value === void 0 || value === null ? {} : __spreadValues(__spreadValues({}, returnValue.context), value)
423
- });
424
- continue;
425
- }
426
- if (key === "searchParams") {
427
- if (value === void 0 || value === null) {
428
- searchParameters = void 0;
429
- } else {
430
- searchParameters = searchParameters === void 0 ? value : appendSearchParameters(searchParameters, value);
431
- }
432
- continue;
433
- }
434
- if (isObject(value) && key in returnValue) {
435
- value = deepMerge(returnValue[key], value);
83
+ // src/errors.ts
84
+ var ZupostError = class _ZupostError extends Error {
85
+ constructor(args) {
86
+ super(args.message);
87
+ this.name = "ZupostError";
88
+ this.status = args.status;
89
+ this.statusText = args.statusText;
90
+ this.body = args.body;
91
+ this.requestId = args.requestId;
92
+ this.code = args.code;
93
+ }
94
+ /** @internal */
95
+ static fromResponse(response) {
96
+ return __async(this, null, function* () {
97
+ var _a, _b, _c;
98
+ const body = yield response.text().catch(() => "");
99
+ let parsedMessage;
100
+ let code;
101
+ if (body) {
102
+ try {
103
+ const parsed = JSON.parse(body);
104
+ parsedMessage = (_a = parsed.message) != null ? _a : parsed.error;
105
+ code = parsed.code;
106
+ } catch (e) {
436
107
  }
437
- returnValue = __spreadProps(__spreadValues({}, returnValue), { [key]: value });
438
- }
439
- if (isObject(source.hooks)) {
440
- hooks = mergeHooks(hooks, source.hooks);
441
- returnValue.hooks = hooks;
442
- }
443
- if (isObject(source.headers)) {
444
- headers = mergeHeaders(headers, source.headers);
445
- returnValue.headers = headers;
446
108
  }
447
- }
448
- }
449
- if (searchParameters !== void 0) {
450
- returnValue.searchParams = searchParameters;
451
- }
452
- if (signals.length > 0) {
453
- if (signals.length === 1) {
454
- returnValue.signal = signals[0];
455
- } else if (supportsAbortSignal) {
456
- returnValue.signal = AbortSignal.any(signals);
457
- } else {
458
- returnValue.signal = signals.at(-1);
459
- }
460
- }
461
- return returnValue;
462
- };
463
-
464
- // node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/utils/normalize.js
465
- var normalizeRequestMethod = (input) => requestMethods.includes(input) ? input.toUpperCase() : input;
466
- var retryMethods = ["get", "put", "head", "delete", "options", "trace"];
467
- var retryStatusCodes = [408, 413, 429, 500, 502, 503, 504];
468
- var retryAfterStatusCodes = [413, 429, 503];
469
- var defaultRetryOptions = {
470
- limit: 2,
471
- methods: retryMethods,
472
- statusCodes: retryStatusCodes,
473
- afterStatusCodes: retryAfterStatusCodes,
474
- maxRetryAfter: Number.POSITIVE_INFINITY,
475
- backoffLimit: Number.POSITIVE_INFINITY,
476
- delay: (attemptCount) => 0.3 * __pow(2, attemptCount - 1) * 1e3,
477
- jitter: void 0,
478
- retryOnTimeout: false
479
- };
480
- var normalizeRetryOptions = (retry2 = {}) => {
481
- if (typeof retry2 === "number") {
482
- return __spreadProps(__spreadValues({}, defaultRetryOptions), {
483
- limit: retry2
109
+ const detail = parsedMessage || response.statusText || body || "unknown error";
110
+ return new _ZupostError({
111
+ message: `Zupost API error ${response.status}: ${detail}`,
112
+ status: response.status,
113
+ statusText: response.statusText,
114
+ body,
115
+ requestId: (_c = (_b = response.headers.get("x-request-id")) != null ? _b : response.headers.get("x-zupost-request-id")) != null ? _c : void 0,
116
+ code
117
+ });
484
118
  });
485
119
  }
486
- if (retry2.methods && !Array.isArray(retry2.methods)) {
487
- throw new Error("retry.methods must be an array");
488
- }
489
- retry2.methods && (retry2.methods = retry2.methods.map((method) => method.toLowerCase()));
490
- if (retry2.statusCodes && !Array.isArray(retry2.statusCodes)) {
491
- throw new Error("retry.statusCodes must be an array");
492
- }
493
- const normalizedRetry = Object.fromEntries(Object.entries(retry2).filter(([, value]) => value !== void 0));
494
- return __spreadValues(__spreadValues({}, defaultRetryOptions), normalizedRetry);
495
- };
496
-
497
- // node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/errors/TimeoutError.js
498
- var TimeoutError = class extends Error {
499
- constructor(request) {
500
- super(`Request timed out: ${request.method} ${request.url}`);
501
- __publicField(this, "request");
502
- this.name = "TimeoutError";
503
- this.request = request;
504
- }
505
120
  };
506
121
 
507
- // node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/utils/timeout.js
508
- function timeout(request, init, abortController, options) {
509
- return __async(this, null, function* () {
510
- return new Promise((resolve, reject) => {
511
- const timeoutId = setTimeout(() => {
512
- if (abortController) {
513
- abortController.abort();
514
- }
515
- reject(new TimeoutError(request));
516
- }, options.timeout);
517
- void options.fetch(request, init).then(resolve).catch(reject).then(() => {
518
- clearTimeout(timeoutId);
519
- });
520
- });
521
- });
122
+ // src/http-client.ts
123
+ var RETRIABLE_STATUSES = /* @__PURE__ */ new Set([408, 413, 429, 500, 502, 503, 504]);
124
+ var MAX_RETRIES = 3;
125
+ var BACKOFF_BASE_MS = 300;
126
+ var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
127
+ function parseRetryAfter(value) {
128
+ if (!value) return null;
129
+ const seconds = Number(value);
130
+ if (Number.isFinite(seconds)) return Math.max(0, seconds * 1e3);
131
+ const date = Date.parse(value);
132
+ if (!Number.isNaN(date)) return Math.max(0, date - Date.now());
133
+ return null;
522
134
  }
523
-
524
- // node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/utils/delay.js
525
- function delay(_0, _1) {
526
- return __async(this, arguments, function* (ms, { signal }) {
527
- return new Promise((resolve, reject) => {
528
- if (signal) {
529
- signal.throwIfAborted();
530
- signal.addEventListener("abort", abortHandler, { once: true });
531
- }
532
- function abortHandler() {
533
- clearTimeout(timeoutId);
534
- reject(signal.reason);
535
- }
536
- const timeoutId = setTimeout(() => {
537
- signal == null ? void 0 : signal.removeEventListener("abort", abortHandler);
538
- resolve();
539
- }, ms);
135
+ var _defaultHeaders, _baseUrl;
136
+ var HttpClient = class {
137
+ constructor(apiKey, baseUrl, userAgent) {
138
+ __privateAdd(this, _defaultHeaders);
139
+ __privateAdd(this, _baseUrl);
140
+ __privateSet(this, _baseUrl, baseUrl.replace(/\/$/, ""));
141
+ __privateSet(this, _defaultHeaders, {
142
+ Authorization: `Bearer ${apiKey}`,
143
+ "Content-Type": "application/json",
144
+ "User-Agent": userAgent
540
145
  });
541
- });
542
- }
543
-
544
- // node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/utils/options.js
545
- var findUnknownOptions = (request, options) => {
546
- const unknownOptions = {};
547
- for (const key in options) {
548
- if (!Object.hasOwn(options, key)) {
549
- continue;
550
- }
551
- if (!(key in requestOptionsRegistry) && !(key in kyOptionKeys) && (!(key in request) || key in vendorSpecificOptions)) {
552
- unknownOptions[key] = options[key];
553
- }
554
- }
555
- return unknownOptions;
556
- };
557
- var hasSearchParameters = (search) => {
558
- if (search === void 0) {
559
- return false;
560
- }
561
- if (Array.isArray(search)) {
562
- return search.length > 0;
563
- }
564
- if (search instanceof URLSearchParams) {
565
- return search.size > 0;
566
146
  }
567
- if (typeof search === "object") {
568
- return Object.keys(search).length > 0;
569
- }
570
- if (typeof search === "string") {
571
- return search.trim().length > 0;
572
- }
573
- return Boolean(search);
574
- };
575
-
576
- // node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/utils/type-guards.js
577
- function isHTTPError(error) {
578
- return error instanceof HTTPError || (error == null ? void 0 : error.name) === HTTPError.name;
579
- }
580
- function isTimeoutError(error) {
581
- return error instanceof TimeoutError || (error == null ? void 0 : error.name) === TimeoutError.name;
582
- }
583
-
584
- // node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/core/Ky.js
585
- var _Ky_static, normalizeSearchParams_fn, _abortController, _retryCount, _input, _options, _originalRequest, _userProvidedAbortSignal, _cachedNormalizedOptions, _Ky_instances, calculateDelay_fn, calculateRetryDelay_fn, decorateResponse_fn, cancelBody_fn, cancelResponseBody_fn, retry_fn, fetch_fn, getNormalizedOptions_fn, assignRequest_fn, wrapRequestWithUploadProgress_fn;
586
- var _Ky = class _Ky {
587
- // eslint-disable-next-line complexity
588
- constructor(input, options = {}) {
589
- __privateAdd(this, _Ky_instances);
590
- __publicField(this, "request");
591
- __privateAdd(this, _abortController);
592
- __privateAdd(this, _retryCount, 0);
593
- // eslint-disable-next-line @typescript-eslint/prefer-readonly -- False positive: #input is reassigned on line 202
594
- __privateAdd(this, _input);
595
- __privateAdd(this, _options);
596
- __privateAdd(this, _originalRequest);
597
- __privateAdd(this, _userProvidedAbortSignal);
598
- __privateAdd(this, _cachedNormalizedOptions);
599
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
600
- __privateSet(this, _input, input);
601
- __privateSet(this, _options, __spreadProps(__spreadValues({}, options), {
602
- headers: mergeHeaders(__privateGet(this, _input).headers, options.headers),
603
- hooks: mergeHooks({
604
- beforeRequest: [],
605
- beforeRetry: [],
606
- beforeError: [],
607
- afterResponse: []
608
- }, options.hooks),
609
- method: normalizeRequestMethod((_b = (_a = options.method) != null ? _a : __privateGet(this, _input).method) != null ? _b : "GET"),
610
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
611
- prefixUrl: String(options.prefixUrl || ""),
612
- retry: normalizeRetryOptions(options.retry),
613
- throwHttpErrors: (_c = options.throwHttpErrors) != null ? _c : true,
614
- timeout: (_d = options.timeout) != null ? _d : 1e4,
615
- fetch: (_e = options.fetch) != null ? _e : globalThis.fetch.bind(globalThis),
616
- context: (_f = options.context) != null ? _f : {}
617
- }));
618
- if (typeof __privateGet(this, _input) !== "string" && !(__privateGet(this, _input) instanceof URL || __privateGet(this, _input) instanceof globalThis.Request)) {
619
- throw new TypeError("`input` must be a string, URL, or Request");
620
- }
621
- if (__privateGet(this, _options).prefixUrl && typeof __privateGet(this, _input) === "string") {
622
- if (__privateGet(this, _input).startsWith("/")) {
623
- throw new Error("`input` must not begin with a slash when using `prefixUrl`");
624
- }
625
- if (!__privateGet(this, _options).prefixUrl.endsWith("/")) {
626
- __privateGet(this, _options).prefixUrl += "/";
627
- }
628
- __privateSet(this, _input, __privateGet(this, _options).prefixUrl + __privateGet(this, _input));
629
- }
630
- if (supportsAbortController && supportsAbortSignal) {
631
- __privateSet(this, _userProvidedAbortSignal, (_g = __privateGet(this, _options).signal) != null ? _g : __privateGet(this, _input).signal);
632
- __privateSet(this, _abortController, new globalThis.AbortController());
633
- __privateGet(this, _options).signal = __privateGet(this, _userProvidedAbortSignal) ? AbortSignal.any([__privateGet(this, _userProvidedAbortSignal), __privateGet(this, _abortController).signal]) : __privateGet(this, _abortController).signal;
634
- }
635
- if (supportsRequestStreams) {
636
- __privateGet(this, _options).duplex = "half";
637
- }
638
- if (__privateGet(this, _options).json !== void 0) {
639
- __privateGet(this, _options).body = (_j = (_i = (_h = __privateGet(this, _options)).stringifyJson) == null ? void 0 : _i.call(_h, __privateGet(this, _options).json)) != null ? _j : JSON.stringify(__privateGet(this, _options).json);
640
- __privateGet(this, _options).headers.set("content-type", (_k = __privateGet(this, _options).headers.get("content-type")) != null ? _k : "application/json");
641
- }
642
- const userProvidedContentType = options.headers && new globalThis.Headers(options.headers).has("content-type");
643
- if (__privateGet(this, _input) instanceof globalThis.Request && (supportsFormData && __privateGet(this, _options).body instanceof globalThis.FormData || __privateGet(this, _options).body instanceof URLSearchParams) && !userProvidedContentType) {
644
- __privateGet(this, _options).headers.delete("content-type");
645
- }
646
- this.request = new globalThis.Request(__privateGet(this, _input), __privateGet(this, _options));
647
- if (hasSearchParameters(__privateGet(this, _options).searchParams)) {
648
- const textSearchParams = typeof __privateGet(this, _options).searchParams === "string" ? __privateGet(this, _options).searchParams.replace(/^\?/, "") : new URLSearchParams(__privateMethod(_l = _Ky, _Ky_static, normalizeSearchParams_fn).call(_l, __privateGet(this, _options).searchParams)).toString();
649
- const searchParams = "?" + textSearchParams;
650
- const url = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, searchParams);
651
- this.request = new globalThis.Request(url, __privateGet(this, _options));
652
- }
653
- if (__privateGet(this, _options).onUploadProgress) {
654
- if (typeof __privateGet(this, _options).onUploadProgress !== "function") {
655
- throw new TypeError("The `onUploadProgress` option must be a function");
656
- }
657
- if (!supportsRequestStreams) {
658
- throw new Error("Request streams are not supported in your environment. The `duplex` option for `Request` is not available.");
147
+ request(path, method, body) {
148
+ return __async(this, null, function* () {
149
+ const url = `${__privateGet(this, _baseUrl)}/${path.replace(/^\//, "")}`;
150
+ const headers = new Headers(__privateGet(this, _defaultHeaders));
151
+ if (method !== "GET") {
152
+ headers.set("Idempotency-Key", crypto.randomUUID());
659
153
  }
660
- this.request = __privateMethod(this, _Ky_instances, wrapRequestWithUploadProgress_fn).call(this, this.request, (_m = __privateGet(this, _options).body) != null ? _m : void 0);
661
- }
662
- }
663
- static create(input, options) {
664
- var _a, _b, _c;
665
- const ky2 = new _Ky(input, options);
666
- const function_ = () => __async(null, null, function* () {
667
- var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l;
668
- if (typeof __privateGet(ky2, _options).timeout === "number" && __privateGet(ky2, _options).timeout > maxSafeTimeout) {
669
- throw new RangeError(`The \`timeout\` option cannot be greater than ${maxSafeTimeout}`);
154
+ const init = { method, headers };
155
+ if (body !== void 0) {
156
+ init.body = JSON.stringify(body);
670
157
  }
671
- yield Promise.resolve();
672
- let response = yield __privateMethod(_a2 = ky2, _Ky_instances, fetch_fn).call(_a2);
673
- for (const hook of __privateGet(ky2, _options).hooks.afterResponse) {
674
- const clonedResponse = __privateMethod(_b2 = ky2, _Ky_instances, decorateResponse_fn).call(_b2, response.clone());
675
- let modifiedResponse;
158
+ for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
159
+ let response;
676
160
  try {
677
- modifiedResponse = yield hook(ky2.request, __privateMethod(_c2 = ky2, _Ky_instances, getNormalizedOptions_fn).call(_c2), clonedResponse, { retryCount: __privateGet(ky2, _retryCount) });
678
- } catch (error) {
679
- __privateMethod(_d = ky2, _Ky_instances, cancelResponseBody_fn).call(_d, clonedResponse);
680
- __privateMethod(_e = ky2, _Ky_instances, cancelResponseBody_fn).call(_e, response);
681
- throw error;
682
- }
683
- if (modifiedResponse instanceof RetryMarker) {
684
- __privateMethod(_f = ky2, _Ky_instances, cancelResponseBody_fn).call(_f, clonedResponse);
685
- __privateMethod(_g = ky2, _Ky_instances, cancelResponseBody_fn).call(_g, response);
686
- throw new ForceRetryError(modifiedResponse.options);
687
- }
688
- const nextResponse = modifiedResponse instanceof globalThis.Response ? modifiedResponse : response;
689
- if (clonedResponse !== nextResponse) {
690
- __privateMethod(_h = ky2, _Ky_instances, cancelResponseBody_fn).call(_h, clonedResponse);
691
- }
692
- if (response !== nextResponse) {
693
- __privateMethod(_i = ky2, _Ky_instances, cancelResponseBody_fn).call(_i, response);
694
- }
695
- response = nextResponse;
696
- }
697
- __privateMethod(_j = ky2, _Ky_instances, decorateResponse_fn).call(_j, response);
698
- if (!response.ok && (typeof __privateGet(ky2, _options).throwHttpErrors === "function" ? __privateGet(ky2, _options).throwHttpErrors(response.status) : __privateGet(ky2, _options).throwHttpErrors)) {
699
- let error = new HTTPError(response, ky2.request, __privateMethod(_k = ky2, _Ky_instances, getNormalizedOptions_fn).call(_k));
700
- for (const hook of __privateGet(ky2, _options).hooks.beforeError) {
701
- error = yield hook(error, { retryCount: __privateGet(ky2, _retryCount) });
161
+ response = yield fetch(url, init);
162
+ } catch (err) {
163
+ if (attempt === MAX_RETRIES) throw err;
164
+ yield sleep(__pow(2, attempt) * BACKOFF_BASE_MS);
165
+ continue;
702
166
  }
703
- throw error;
704
- }
705
- if (__privateGet(ky2, _options).onDownloadProgress) {
706
- if (typeof __privateGet(ky2, _options).onDownloadProgress !== "function") {
707
- throw new TypeError("The `onDownloadProgress` option must be a function");
167
+ if (response.ok) {
168
+ return yield response.json();
708
169
  }
709
- if (!supportsResponseStreams) {
710
- throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
170
+ if (attempt < MAX_RETRIES && RETRIABLE_STATUSES.has(response.status)) {
171
+ const retryAfter = parseRetryAfter(response.headers.get("Retry-After"));
172
+ yield sleep(retryAfter != null ? retryAfter : __pow(2, attempt) * BACKOFF_BASE_MS);
173
+ continue;
711
174
  }
712
- const progressResponse = response.clone();
713
- __privateMethod(_l = ky2, _Ky_instances, cancelResponseBody_fn).call(_l, response);
714
- return streamResponse(progressResponse, __privateGet(ky2, _options).onDownloadProgress);
175
+ throw yield ZupostError.fromResponse(response);
715
176
  }
716
- return response;
177
+ throw new Error("Zupost API: retries exhausted");
717
178
  });
718
- const result = __privateMethod(_a = ky2, _Ky_instances, retry_fn).call(_a, function_).finally(() => {
719
- var _a2, _b2, _c2, _d;
720
- const originalRequest = __privateGet(ky2, _originalRequest);
721
- __privateMethod(_b2 = ky2, _Ky_instances, cancelBody_fn).call(_b2, (_a2 = originalRequest == null ? void 0 : originalRequest.body) != null ? _a2 : void 0);
722
- __privateMethod(_d = ky2, _Ky_instances, cancelBody_fn).call(_d, (_c2 = ky2.request.body) != null ? _c2 : void 0);
723
- });
724
- for (const [type, mimeType] of Object.entries(responseTypes)) {
725
- if (type === "bytes" && typeof ((_c = (_b = globalThis.Response) == null ? void 0 : _b.prototype) == null ? void 0 : _c.bytes) !== "function") {
726
- continue;
727
- }
728
- result[type] = () => __async(null, null, function* () {
729
- ky2.request.headers.set("accept", ky2.request.headers.get("accept") || mimeType);
730
- const response = yield result;
731
- if (type === "json") {
732
- if (response.status === 204) {
733
- return "";
734
- }
735
- const text = yield response.text();
736
- if (text === "") {
737
- return "";
738
- }
739
- if (options.parseJson) {
740
- return options.parseJson(text);
741
- }
742
- return JSON.parse(text);
743
- }
744
- return response[type]();
745
- });
746
- }
747
- return result;
748
- }
749
- };
750
- _Ky_static = new WeakSet();
751
- normalizeSearchParams_fn = function(searchParams) {
752
- if (searchParams && typeof searchParams === "object" && !Array.isArray(searchParams) && !(searchParams instanceof URLSearchParams)) {
753
- return Object.fromEntries(Object.entries(searchParams).filter(([, value]) => value !== void 0));
754
- }
755
- return searchParams;
756
- };
757
- _abortController = new WeakMap();
758
- _retryCount = new WeakMap();
759
- _input = new WeakMap();
760
- _options = new WeakMap();
761
- _originalRequest = new WeakMap();
762
- _userProvidedAbortSignal = new WeakMap();
763
- _cachedNormalizedOptions = new WeakMap();
764
- _Ky_instances = new WeakSet();
765
- calculateDelay_fn = function() {
766
- var _a;
767
- const retryDelay = __privateGet(this, _options).retry.delay(__privateGet(this, _retryCount));
768
- let jitteredDelay = retryDelay;
769
- if (__privateGet(this, _options).retry.jitter === true) {
770
- jitteredDelay = Math.random() * retryDelay;
771
- } else if (typeof __privateGet(this, _options).retry.jitter === "function") {
772
- jitteredDelay = __privateGet(this, _options).retry.jitter(retryDelay);
773
- if (!Number.isFinite(jitteredDelay) || jitteredDelay < 0) {
774
- jitteredDelay = retryDelay;
775
- }
776
179
  }
777
- const backoffLimit = (_a = __privateGet(this, _options).retry.backoffLimit) != null ? _a : Number.POSITIVE_INFINITY;
778
- return Math.min(backoffLimit, jitteredDelay);
779
- };
780
- calculateRetryDelay_fn = function(error) {
781
- return __async(this, null, function* () {
782
- var _a, _b, _c, _d, _e, _f;
783
- __privateWrapper(this, _retryCount)._++;
784
- if (__privateGet(this, _retryCount) > __privateGet(this, _options).retry.limit) {
785
- throw error;
786
- }
787
- const errorObject = error instanceof Error ? error : new NonError(error);
788
- if (errorObject instanceof ForceRetryError) {
789
- return (_a = errorObject.customDelay) != null ? _a : __privateMethod(this, _Ky_instances, calculateDelay_fn).call(this);
790
- }
791
- if (!__privateGet(this, _options).retry.methods.includes(this.request.method.toLowerCase())) {
792
- throw error;
793
- }
794
- if (__privateGet(this, _options).retry.shouldRetry !== void 0) {
795
- const result = yield __privateGet(this, _options).retry.shouldRetry({ error: errorObject, retryCount: __privateGet(this, _retryCount) });
796
- if (result === false) {
797
- throw error;
798
- }
799
- if (result === true) {
800
- return __privateMethod(this, _Ky_instances, calculateDelay_fn).call(this);
801
- }
802
- }
803
- if (isTimeoutError(error) && !__privateGet(this, _options).retry.retryOnTimeout) {
804
- throw error;
805
- }
806
- if (isHTTPError(error)) {
807
- if (!__privateGet(this, _options).retry.statusCodes.includes(error.response.status)) {
808
- throw error;
809
- }
810
- const retryAfter = (_e = (_d = (_c = (_b = error.response.headers.get("Retry-After")) != null ? _b : error.response.headers.get("RateLimit-Reset")) != null ? _c : error.response.headers.get("X-RateLimit-Retry-After")) != null ? _d : error.response.headers.get("X-RateLimit-Reset")) != null ? _e : error.response.headers.get("X-Rate-Limit-Reset");
811
- if (retryAfter && __privateGet(this, _options).retry.afterStatusCodes.includes(error.response.status)) {
812
- let after = Number(retryAfter) * 1e3;
813
- if (Number.isNaN(after)) {
814
- after = Date.parse(retryAfter) - Date.now();
815
- } else if (after >= Date.parse("2024-01-01")) {
816
- after -= Date.now();
817
- }
818
- const max = (_f = __privateGet(this, _options).retry.maxRetryAfter) != null ? _f : after;
819
- return after < max ? after : max;
820
- }
821
- if (error.response.status === 413) {
822
- throw error;
823
- }
824
- }
825
- return __privateMethod(this, _Ky_instances, calculateDelay_fn).call(this);
826
- });
827
- };
828
- decorateResponse_fn = function(response) {
829
- if (__privateGet(this, _options).parseJson) {
830
- response.json = () => __async(this, null, function* () {
831
- return __privateGet(this, _options).parseJson(yield response.text());
180
+ get(path) {
181
+ return __async(this, null, function* () {
182
+ return this.request(path, "GET");
832
183
  });
833
184
  }
834
- return response;
835
- };
836
- cancelBody_fn = function(body) {
837
- if (!body) {
838
- return;
185
+ post(path, body) {
186
+ return __async(this, null, function* () {
187
+ return this.request(path, "POST", body);
188
+ });
839
189
  }
840
- void body.cancel().catch(() => void 0);
841
190
  };
842
- cancelResponseBody_fn = function(response) {
843
- var _a;
844
- __privateMethod(this, _Ky_instances, cancelBody_fn).call(this, (_a = response.body) != null ? _a : void 0);
845
- };
846
- retry_fn = function(function_) {
191
+ _defaultHeaders = new WeakMap();
192
+ _baseUrl = new WeakMap();
193
+
194
+ // src/email/emails.ts
195
+ function loadReactRender() {
847
196
  return __async(this, null, function* () {
848
197
  try {
849
- return yield function_();
850
- } catch (error) {
851
- const ms = Math.min(yield __privateMethod(this, _Ky_instances, calculateRetryDelay_fn).call(this, error), maxSafeTimeout);
852
- if (__privateGet(this, _retryCount) < 1) {
853
- throw error;
854
- }
855
- yield delay(ms, __privateGet(this, _userProvidedAbortSignal) ? { signal: __privateGet(this, _userProvidedAbortSignal) } : {});
856
- if (error instanceof ForceRetryError && error.customRequest) {
857
- const managedRequest = __privateGet(this, _options).signal ? new globalThis.Request(error.customRequest, { signal: __privateGet(this, _options).signal }) : new globalThis.Request(error.customRequest);
858
- __privateMethod(this, _Ky_instances, assignRequest_fn).call(this, managedRequest);
859
- }
860
- for (const hook of __privateGet(this, _options).hooks.beforeRetry) {
861
- const hookResult = yield hook({
862
- request: this.request,
863
- options: __privateMethod(this, _Ky_instances, getNormalizedOptions_fn).call(this),
864
- error,
865
- retryCount: __privateGet(this, _retryCount)
866
- });
867
- if (hookResult instanceof globalThis.Request) {
868
- __privateMethod(this, _Ky_instances, assignRequest_fn).call(this, hookResult);
869
- break;
870
- }
871
- if (hookResult instanceof globalThis.Response) {
872
- return hookResult;
873
- }
874
- if (hookResult === stop) {
875
- return;
876
- }
877
- }
878
- return __privateMethod(this, _Ky_instances, retry_fn).call(this, function_);
879
- }
880
- });
881
- };
882
- fetch_fn = function() {
883
- return __async(this, null, function* () {
884
- var _a;
885
- if ((_a = __privateGet(this, _abortController)) == null ? void 0 : _a.signal.aborted) {
886
- __privateSet(this, _abortController, new globalThis.AbortController());
887
- __privateGet(this, _options).signal = __privateGet(this, _userProvidedAbortSignal) ? AbortSignal.any([__privateGet(this, _userProvidedAbortSignal), __privateGet(this, _abortController).signal]) : __privateGet(this, _abortController).signal;
888
- this.request = new globalThis.Request(this.request, { signal: __privateGet(this, _options).signal });
889
- }
890
- for (const hook of __privateGet(this, _options).hooks.beforeRequest) {
891
- const result = yield hook(this.request, __privateMethod(this, _Ky_instances, getNormalizedOptions_fn).call(this), { retryCount: __privateGet(this, _retryCount) });
892
- if (result instanceof Response) {
893
- return result;
894
- }
895
- if (result instanceof globalThis.Request) {
896
- __privateMethod(this, _Ky_instances, assignRequest_fn).call(this, result);
897
- break;
898
- }
899
- }
900
- const nonRequestOptions = findUnknownOptions(this.request, __privateGet(this, _options));
901
- __privateSet(this, _originalRequest, this.request);
902
- this.request = __privateGet(this, _originalRequest).clone();
903
- if (__privateGet(this, _options).timeout === false) {
904
- return __privateGet(this, _options).fetch(__privateGet(this, _originalRequest), nonRequestOptions);
198
+ const mod = yield import("@react-email/render");
199
+ return mod.render;
200
+ } catch (e) {
201
+ throw new Error(
202
+ "Sending React-based emails requires '@react-email/render' to be installed. Run: npm install @react-email/render react"
203
+ );
905
204
  }
906
- return timeout(__privateGet(this, _originalRequest), nonRequestOptions, __privateGet(this, _abortController), __privateGet(this, _options));
907
205
  });
908
- };
909
- getNormalizedOptions_fn = function() {
910
- if (!__privateGet(this, _cachedNormalizedOptions)) {
911
- const _a = __privateGet(this, _options), { hooks } = _a, normalizedOptions = __objRest(_a, ["hooks"]);
912
- __privateSet(this, _cachedNormalizedOptions, Object.freeze(normalizedOptions));
913
- }
914
- return __privateGet(this, _cachedNormalizedOptions);
915
- };
916
- assignRequest_fn = function(request) {
917
- __privateSet(this, _cachedNormalizedOptions, void 0);
918
- this.request = __privateMethod(this, _Ky_instances, wrapRequestWithUploadProgress_fn).call(this, request);
919
- };
920
- wrapRequestWithUploadProgress_fn = function(request, originalBody) {
921
- var _a;
922
- if (!__privateGet(this, _options).onUploadProgress || !request.body) {
923
- return request;
924
- }
925
- return streamRequest(request, __privateGet(this, _options).onUploadProgress, (_a = originalBody != null ? originalBody : __privateGet(this, _options).body) != null ? _a : void 0);
926
- };
927
- __privateAdd(_Ky, _Ky_static);
928
- var Ky = _Ky;
929
-
930
- // node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/index.js
931
- var createInstance = (defaults) => {
932
- const ky2 = (input, options) => Ky.create(input, validateAndMerge(defaults, options));
933
- for (const method of requestMethods) {
934
- ky2[method] = (input, options) => Ky.create(input, validateAndMerge(defaults, options, { method }));
935
- }
936
- ky2.create = (newDefaults) => createInstance(validateAndMerge(newDefaults));
937
- ky2.extend = (newDefaults) => {
938
- if (typeof newDefaults === "function") {
939
- newDefaults = newDefaults(defaults != null ? defaults : {});
940
- }
941
- return createInstance(validateAndMerge(defaults, newDefaults));
942
- };
943
- ky2.stop = stop;
944
- ky2.retry = retry;
945
- return ky2;
946
- };
947
- var ky = createInstance();
948
- var distribution_default = ky;
949
-
950
- // src/email/emails.ts
951
- var import_render = require("@react-email/render");
206
+ }
952
207
  var Emails = class {
953
- constructor(zupost) {
954
- this.zupost = zupost;
208
+ constructor(http) {
209
+ this.http = http;
955
210
  }
956
211
  /**
957
- * Send an email using template, markdown or HTML content.
212
+ * Send an email.
213
+ *
214
+ * Zupost is template first: prefer sending by `templateId` with `variables`
215
+ * so your content lives in the Zupost dashboard and can be edited without a
216
+ * deploy. Inline `html`, `markdown`, or `react` content is supported as a
217
+ * fallback for ad-hoc or dynamically generated emails.
958
218
  *
959
219
  * @param options - Email options including recipient, sender, and content.
960
- * @returns A promise that resolves to the email response containing emailId.
220
+ * @returns A promise that resolves to the email response containing the email id.
961
221
  *
962
222
  * @example
963
223
  * ```typescript
964
224
  * const zupost = new Zupost('your-api-key');
965
225
  *
966
- * // Send with HTML content
967
- * const { emailId } = await zupost.emails.send({
226
+ * // Recommended: send with a template
227
+ * const { id } = await zupost.emails.send({
968
228
  * from: 'sender@example.com',
969
229
  * to: 'recipient@example.com',
970
- * subject: 'Hello World',
971
- * html: '<h1>Hello!</h1>',
230
+ * templateId: 'welcome-template',
231
+ * variables: { name: 'John' },
972
232
  * });
973
233
  *
974
- * // Send with a template
234
+ * // Fallback: inline HTML
975
235
  * await zupost.emails.send({
976
236
  * from: 'sender@example.com',
977
- * to: ['user1@example.com', 'user2@example.com'],
978
- * subject: 'Welcome!',
979
- * templateId: 'welcome-template',
980
- * variables: { name: 'John' },
237
+ * to: 'recipient@example.com',
238
+ * subject: 'Hello World',
239
+ * html: '<h1>Hello!</h1>',
981
240
  * });
982
241
  *
983
- * // Send with markdown
242
+ * // Fallback: inline markdown
984
243
  * await zupost.emails.send({
985
244
  * from: 'sender@example.com',
986
245
  * to: 'recipient@example.com',
@@ -991,29 +250,31 @@ var Emails = class {
991
250
  */
992
251
  send(options) {
993
252
  return __async(this, null, function* () {
994
- if (options.react) {
995
- options.html = yield (0, import_render.render)(options.react, options.reactOptions);
996
- delete options.react;
997
- delete options.reactOptions;
253
+ const inlineCount = [options.html, options.markdown, options.react].filter(
254
+ (v) => v !== void 0 && v !== null
255
+ ).length;
256
+ if (inlineCount > 1) {
257
+ throw new Error("Provide only one of html, markdown, or react");
998
258
  }
999
- if (!options.html && !options.markdown && !options.react) {
1000
- throw new Error("Either html, markdown or react must be provided");
259
+ if (inlineCount === 0 && !options.templateId) {
260
+ throw new Error("Provide one of html, markdown, react, or templateId");
1001
261
  }
1002
- if (options.html && options.markdown) {
1003
- throw new Error("Either html or markdown must be provided");
1004
- }
1005
- if (options.react && options.html) {
1006
- throw new Error("Either react or html must be provided");
262
+ const payload = __spreadValues({}, options);
263
+ if (options.react) {
264
+ const render = yield loadReactRender();
265
+ payload.html = yield render(options.react, options.reactOptions);
266
+ delete payload.react;
267
+ delete payload.reactOptions;
1007
268
  }
1008
- return this.zupost.post("email/send", options);
269
+ return this.http.post("email/send", payload);
1009
270
  });
1010
271
  }
1011
272
  };
1012
273
 
1013
274
  // src/campaign/campaigns.ts
1014
275
  var Campaigns = class {
1015
- constructor(zupost) {
1016
- this.zupost = zupost;
276
+ constructor(http) {
277
+ this.http = http;
1017
278
  }
1018
279
  /**
1019
280
  * Send a campaign to selected audiences.
@@ -1036,69 +297,29 @@ var Campaigns = class {
1036
297
  */
1037
298
  send(options) {
1038
299
  return __async(this, null, function* () {
1039
- return this.zupost.post("campaign/send", options);
300
+ return this.http.post("campaign/send", options);
1040
301
  });
1041
302
  }
1042
303
  };
1043
304
 
1044
305
  // src/zupost.ts
306
+ var _client;
1045
307
  var Zupost = class {
1046
308
  constructor(apiKey, options) {
1047
- this.baseUrl = "https://api.zupost.com";
309
+ __privateAdd(this, _client);
310
+ var _a;
1048
311
  if (!apiKey) {
1049
312
  throw new Error("API key is required");
1050
313
  }
1051
- if (options == null ? void 0 : options.baseUrl) {
1052
- this.baseUrl = options.baseUrl;
1053
- }
1054
- this.headers = new Headers({
1055
- "Authorization": `Bearer ${apiKey}`,
1056
- "Content-Type": "application/json",
1057
- "User-Agent": `node-sdk@${version}`
1058
- });
1059
- this.emails = new Emails(this);
1060
- this.campaigns = new Campaigns(this);
1061
- }
1062
- /**
1063
- * @internal
1064
- * Makes a request to the Zupost API.
1065
- */
1066
- request(path, method, body) {
1067
- return __async(this, null, function* () {
1068
- return distribution_default(path, {
1069
- headers: this.headers,
1070
- method,
1071
- retry: 3,
1072
- prefixUrl: this.baseUrl,
1073
- json: body
1074
- }).json();
1075
- });
1076
- }
1077
- /**
1078
- * @internal
1079
- * Makes a GET request to the Zupost API.
1080
- */
1081
- get(path) {
1082
- return __async(this, null, function* () {
1083
- return this.request(path, "GET");
1084
- });
1085
- }
1086
- /**
1087
- * @internal
1088
- * Makes a POST request to the Zupost API.
1089
- */
1090
- post(path, body) {
1091
- return __async(this, null, function* () {
1092
- return this.request(path, "POST", body);
1093
- });
314
+ const baseUrl = (_a = options == null ? void 0 : options.baseUrl) != null ? _a : "https://api.zupost.com";
315
+ __privateSet(this, _client, new HttpClient(apiKey, baseUrl, `node-sdk@${version}`));
316
+ this.emails = new Emails(__privateGet(this, _client));
317
+ this.campaigns = new Campaigns(__privateGet(this, _client));
1094
318
  }
1095
319
  };
320
+ _client = new WeakMap();
1096
321
  // Annotate the CommonJS export names for ESM import in node:
1097
322
  0 && (module.exports = {
1098
- Zupost
323
+ Zupost,
324
+ ZupostError
1099
325
  });
1100
- /*! Bundled license information:
1101
-
1102
- ky/distribution/index.js:
1103
- (*! MIT License © Sindre Sorhus *)
1104
- */