zupost 0.1.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -13
- package/dist/index.d.mts +522 -36
- package/dist/index.d.ts +522 -36
- package/dist/index.js +418 -921
- package/dist/index.mjs +405 -920
- package/package.json +60 -52
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,185 @@ 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,
|
|
77
|
+
defineSequence: () => defineSequence
|
|
91
78
|
});
|
|
92
79
|
module.exports = __toCommonJS(index_exports);
|
|
93
80
|
|
|
94
81
|
// package.json
|
|
95
|
-
var version = "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
|
-
};
|
|
82
|
+
var version = "0.5.1";
|
|
238
83
|
|
|
239
|
-
//
|
|
240
|
-
var
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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;
|
|
84
|
+
// src/errors.ts
|
|
85
|
+
var ZupostError = class _ZupostError extends Error {
|
|
86
|
+
constructor(args) {
|
|
87
|
+
super(args.message);
|
|
88
|
+
this.name = "ZupostError";
|
|
89
|
+
this.status = args.status;
|
|
90
|
+
this.statusText = args.statusText;
|
|
91
|
+
this.body = args.body;
|
|
92
|
+
this.requestId = args.requestId;
|
|
93
|
+
this.code = args.code;
|
|
94
|
+
}
|
|
95
|
+
/** @internal */
|
|
96
|
+
static fromResponse(response) {
|
|
97
|
+
return __async(this, null, function* () {
|
|
98
|
+
var _a, _b, _c;
|
|
99
|
+
const body = yield response.text().catch(() => "");
|
|
100
|
+
let parsedMessage;
|
|
101
|
+
let code;
|
|
102
|
+
if (body) {
|
|
103
|
+
try {
|
|
104
|
+
const parsed = JSON.parse(body);
|
|
105
|
+
parsedMessage = (_a = parsed.message) != null ? _a : parsed.error;
|
|
106
|
+
code = parsed.code;
|
|
107
|
+
} catch (e) {
|
|
289
108
|
}
|
|
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
109
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
status: response.status,
|
|
309
|
-
statusText: response.statusText,
|
|
310
|
-
headers: response.headers
|
|
110
|
+
const detail = parsedMessage || response.statusText || body || "unknown error";
|
|
111
|
+
return new _ZupostError({
|
|
112
|
+
message: `Zupost API error ${response.status}: ${detail}`,
|
|
113
|
+
status: response.status,
|
|
114
|
+
statusText: response.statusText,
|
|
115
|
+
body,
|
|
116
|
+
requestId: (_c = (_b = response.headers.get("x-request-id")) != null ? _b : response.headers.get("x-zupost-request-id")) != null ? _c : void 0,
|
|
117
|
+
code
|
|
118
|
+
});
|
|
311
119
|
});
|
|
312
120
|
}
|
|
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
121
|
};
|
|
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
122
|
|
|
335
|
-
//
|
|
336
|
-
var
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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 : []);
|
|
123
|
+
// src/http-client.ts
|
|
124
|
+
var RETRIABLE_STATUSES = /* @__PURE__ */ new Set([408, 413, 429, 500, 502, 503, 504]);
|
|
125
|
+
var MAX_RETRIES = 3;
|
|
126
|
+
var BACKOFF_BASE_MS = 300;
|
|
127
|
+
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
128
|
+
function parseRetryAfter(value) {
|
|
129
|
+
if (!value) return null;
|
|
130
|
+
const seconds = Number(value);
|
|
131
|
+
if (Number.isFinite(seconds)) return Math.max(0, seconds * 1e3);
|
|
132
|
+
const date = Date.parse(value);
|
|
133
|
+
if (!Number.isNaN(date)) return Math.max(0, date - Date.now());
|
|
134
|
+
return null;
|
|
360
135
|
}
|
|
361
|
-
var
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
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
|
-
}
|
|
136
|
+
var _defaultHeaders, _baseUrl;
|
|
137
|
+
var HttpClient = class {
|
|
138
|
+
constructor(apiKey, baseUrl, userAgent) {
|
|
139
|
+
__privateAdd(this, _defaultHeaders);
|
|
140
|
+
__privateAdd(this, _baseUrl);
|
|
141
|
+
__privateSet(this, _baseUrl, baseUrl.replace(/\/$/, ""));
|
|
142
|
+
__privateSet(this, _defaultHeaders, {
|
|
143
|
+
"Authorization": `Bearer ${apiKey}`,
|
|
144
|
+
"Content-Type": "application/json",
|
|
145
|
+
"User-Agent": userAgent
|
|
146
|
+
});
|
|
396
147
|
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
if (!Array.isArray(returnValue)) {
|
|
408
|
-
returnValue = [];
|
|
148
|
+
request(path, method, body) {
|
|
149
|
+
return __async(this, null, function* () {
|
|
150
|
+
const url = `${__privateGet(this, _baseUrl)}/${path.replace(/^\//, "")}`;
|
|
151
|
+
const headers = new Headers(__privateGet(this, _defaultHeaders));
|
|
152
|
+
if (method !== "GET") {
|
|
153
|
+
headers.set("Idempotency-Key", crypto.randomUUID());
|
|
154
|
+
}
|
|
155
|
+
const init = { method, headers };
|
|
156
|
+
if (body !== void 0) {
|
|
157
|
+
init.body = JSON.stringify(body);
|
|
409
158
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
159
|
+
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
160
|
+
let response;
|
|
161
|
+
try {
|
|
162
|
+
response = yield fetch(url, init);
|
|
163
|
+
} catch (err) {
|
|
164
|
+
if (attempt === MAX_RETRIES) throw err;
|
|
165
|
+
yield sleep(__pow(2, attempt) * BACKOFF_BASE_MS);
|
|
415
166
|
continue;
|
|
416
167
|
}
|
|
417
|
-
if (
|
|
418
|
-
|
|
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;
|
|
168
|
+
if (response.ok) {
|
|
169
|
+
return yield response.json();
|
|
425
170
|
}
|
|
426
|
-
if (
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
} else {
|
|
430
|
-
searchParameters = searchParameters === void 0 ? value : appendSearchParameters(searchParameters, value);
|
|
431
|
-
}
|
|
171
|
+
if (attempt < MAX_RETRIES && RETRIABLE_STATUSES.has(response.status)) {
|
|
172
|
+
const retryAfter = parseRetryAfter(response.headers.get("Retry-After"));
|
|
173
|
+
yield sleep(retryAfter != null ? retryAfter : __pow(2, attempt) * BACKOFF_BASE_MS);
|
|
432
174
|
continue;
|
|
433
175
|
}
|
|
434
|
-
|
|
435
|
-
value = deepMerge(returnValue[key], value);
|
|
436
|
-
}
|
|
437
|
-
returnValue = __spreadProps(__spreadValues({}, returnValue), { [key]: value });
|
|
176
|
+
throw yield ZupostError.fromResponse(response);
|
|
438
177
|
}
|
|
439
|
-
|
|
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
|
-
}
|
|
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
|
|
178
|
+
throw new Error("Zupost API: retries exhausted");
|
|
484
179
|
});
|
|
485
180
|
}
|
|
486
|
-
|
|
487
|
-
|
|
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
|
-
};
|
|
506
|
-
|
|
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
|
-
});
|
|
522
|
-
}
|
|
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);
|
|
181
|
+
get(path) {
|
|
182
|
+
return __async(this, null, function* () {
|
|
183
|
+
return this.request(path, "GET");
|
|
540
184
|
});
|
|
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
185
|
}
|
|
564
|
-
|
|
565
|
-
return
|
|
566
|
-
|
|
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.");
|
|
659
|
-
}
|
|
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}`);
|
|
670
|
-
}
|
|
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;
|
|
676
|
-
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) });
|
|
702
|
-
}
|
|
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");
|
|
708
|
-
}
|
|
709
|
-
if (!supportsResponseStreams) {
|
|
710
|
-
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
|
|
711
|
-
}
|
|
712
|
-
const progressResponse = response.clone();
|
|
713
|
-
__privateMethod(_l = ky2, _Ky_instances, cancelResponseBody_fn).call(_l, response);
|
|
714
|
-
return streamResponse(progressResponse, __privateGet(ky2, _options).onDownloadProgress);
|
|
715
|
-
}
|
|
716
|
-
return response;
|
|
717
|
-
});
|
|
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);
|
|
186
|
+
post(path, body) {
|
|
187
|
+
return __async(this, null, function* () {
|
|
188
|
+
return this.request(path, "POST", body);
|
|
723
189
|
});
|
|
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
190
|
}
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
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
|
-
}
|
|
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());
|
|
191
|
+
patch(path, body) {
|
|
192
|
+
return __async(this, null, function* () {
|
|
193
|
+
return this.request(path, "PATCH", body);
|
|
832
194
|
});
|
|
833
195
|
}
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
return;
|
|
196
|
+
delete(path, body) {
|
|
197
|
+
return __async(this, null, function* () {
|
|
198
|
+
return this.request(path, "DELETE", body);
|
|
199
|
+
});
|
|
839
200
|
}
|
|
840
|
-
void body.cancel().catch(() => void 0);
|
|
841
|
-
};
|
|
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
201
|
};
|
|
846
|
-
|
|
202
|
+
_defaultHeaders = new WeakMap();
|
|
203
|
+
_baseUrl = new WeakMap();
|
|
204
|
+
|
|
205
|
+
// src/email/emails.ts
|
|
206
|
+
function loadReactRender() {
|
|
847
207
|
return __async(this, null, function* () {
|
|
848
208
|
try {
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
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);
|
|
209
|
+
const mod = yield import("@react-email/render");
|
|
210
|
+
return mod.render;
|
|
211
|
+
} catch (e) {
|
|
212
|
+
throw new Error(
|
|
213
|
+
"Sending React-based emails requires '@react-email/render' to be installed. Run: npm install @react-email/render react"
|
|
214
|
+
);
|
|
905
215
|
}
|
|
906
|
-
return timeout(__privateGet(this, _originalRequest), nonRequestOptions, __privateGet(this, _abortController), __privateGet(this, _options));
|
|
907
216
|
});
|
|
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");
|
|
217
|
+
}
|
|
952
218
|
var Emails = class {
|
|
953
|
-
constructor(
|
|
954
|
-
this.
|
|
219
|
+
constructor(http) {
|
|
220
|
+
this.http = http;
|
|
955
221
|
}
|
|
956
222
|
/**
|
|
957
|
-
* Send an email
|
|
223
|
+
* Send an email.
|
|
224
|
+
*
|
|
225
|
+
* Zupost is template first: prefer sending by `templateId` with `variables`
|
|
226
|
+
* so your content lives in the Zupost dashboard and can be edited without a
|
|
227
|
+
* deploy. Inline `html`, `markdown`, or `react` content is supported as a
|
|
228
|
+
* fallback for ad-hoc or dynamically generated emails.
|
|
958
229
|
*
|
|
959
230
|
* @param options - Email options including recipient, sender, and content.
|
|
960
|
-
* @returns A promise that resolves to the email response containing
|
|
231
|
+
* @returns A promise that resolves to the email response containing the email id.
|
|
961
232
|
*
|
|
962
233
|
* @example
|
|
963
234
|
* ```typescript
|
|
964
235
|
* const zupost = new Zupost('your-api-key');
|
|
965
236
|
*
|
|
966
|
-
* //
|
|
967
|
-
* const {
|
|
237
|
+
* // Recommended: send with a template
|
|
238
|
+
* const { id } = await zupost.emails.send({
|
|
968
239
|
* from: 'sender@example.com',
|
|
969
240
|
* to: 'recipient@example.com',
|
|
970
|
-
*
|
|
971
|
-
*
|
|
241
|
+
* templateId: 'welcome-template',
|
|
242
|
+
* variables: { name: 'John' },
|
|
972
243
|
* });
|
|
973
244
|
*
|
|
974
|
-
* //
|
|
245
|
+
* // Fallback: inline HTML
|
|
975
246
|
* await zupost.emails.send({
|
|
976
247
|
* from: 'sender@example.com',
|
|
977
|
-
* to:
|
|
978
|
-
* subject: '
|
|
979
|
-
*
|
|
980
|
-
* variables: { name: 'John' },
|
|
248
|
+
* to: 'recipient@example.com',
|
|
249
|
+
* subject: 'Hello World',
|
|
250
|
+
* html: '<h1>Hello!</h1>',
|
|
981
251
|
* });
|
|
982
252
|
*
|
|
983
|
-
* //
|
|
253
|
+
* // Fallback: inline markdown
|
|
984
254
|
* await zupost.emails.send({
|
|
985
255
|
* from: 'sender@example.com',
|
|
986
256
|
* to: 'recipient@example.com',
|
|
@@ -991,29 +261,31 @@ var Emails = class {
|
|
|
991
261
|
*/
|
|
992
262
|
send(options) {
|
|
993
263
|
return __async(this, null, function* () {
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
if (!options.html && !options.markdown && !options.react && !options.templateId) {
|
|
1000
|
-
throw new Error("Either html, markdown, react or templateId must be provided");
|
|
264
|
+
const inlineCount = [options.html, options.markdown, options.react].filter(
|
|
265
|
+
(v) => v !== void 0 && v !== null
|
|
266
|
+
).length;
|
|
267
|
+
if (inlineCount > 1) {
|
|
268
|
+
throw new Error("Provide only one of html, markdown, or react");
|
|
1001
269
|
}
|
|
1002
|
-
if (
|
|
1003
|
-
throw new Error("
|
|
270
|
+
if (inlineCount === 0 && !options.templateId) {
|
|
271
|
+
throw new Error("Provide one of html, markdown, react, or templateId");
|
|
1004
272
|
}
|
|
1005
|
-
|
|
1006
|
-
|
|
273
|
+
const payload = __spreadValues({}, options);
|
|
274
|
+
if (options.react) {
|
|
275
|
+
const render = yield loadReactRender();
|
|
276
|
+
payload.html = yield render(options.react, options.reactOptions);
|
|
277
|
+
delete payload.react;
|
|
278
|
+
delete payload.reactOptions;
|
|
1007
279
|
}
|
|
1008
|
-
return this.
|
|
280
|
+
return this.http.post("email/send", payload);
|
|
1009
281
|
});
|
|
1010
282
|
}
|
|
1011
283
|
};
|
|
1012
284
|
|
|
1013
285
|
// src/campaign/campaigns.ts
|
|
1014
286
|
var Campaigns = class {
|
|
1015
|
-
constructor(
|
|
1016
|
-
this.
|
|
287
|
+
constructor(http) {
|
|
288
|
+
this.http = http;
|
|
1017
289
|
}
|
|
1018
290
|
/**
|
|
1019
291
|
* Send a campaign to selected audiences.
|
|
@@ -1036,69 +308,294 @@ var Campaigns = class {
|
|
|
1036
308
|
*/
|
|
1037
309
|
send(options) {
|
|
1038
310
|
return __async(this, null, function* () {
|
|
1039
|
-
return this.
|
|
311
|
+
return this.http.post("campaign/send", options);
|
|
1040
312
|
});
|
|
1041
313
|
}
|
|
1042
314
|
};
|
|
1043
315
|
|
|
1044
|
-
// src/
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
if (
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
316
|
+
// src/contact/contacts.ts
|
|
317
|
+
function buildQuery(params) {
|
|
318
|
+
const search = new URLSearchParams();
|
|
319
|
+
for (const [key, value] of Object.entries(params)) {
|
|
320
|
+
if (value === void 0) continue;
|
|
321
|
+
if (Array.isArray(value)) {
|
|
322
|
+
for (const v of value) search.append(key, String(v));
|
|
323
|
+
} else {
|
|
324
|
+
search.set(key, String(value));
|
|
1053
325
|
}
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
326
|
+
}
|
|
327
|
+
const query = search.toString();
|
|
328
|
+
return query ? `?${query}` : "";
|
|
329
|
+
}
|
|
330
|
+
var Contacts = class {
|
|
331
|
+
constructor(http) {
|
|
332
|
+
this.http = http;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Create or upsert a contact by email. Idempotent on (project, email).
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* ```typescript
|
|
339
|
+
* const contact = await zupost.contacts.create({
|
|
340
|
+
* email: 'user@example.com',
|
|
341
|
+
* name: 'Jane Doe',
|
|
342
|
+
* marketingConsent: true,
|
|
343
|
+
* marketingConsentSource: 'signup-form',
|
|
344
|
+
* tags: ['vip', 'beta'],
|
|
345
|
+
* });
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
348
|
+
create(options) {
|
|
349
|
+
return __async(this, null, function* () {
|
|
350
|
+
return this.http.post("/contact", options);
|
|
1058
351
|
});
|
|
1059
|
-
this.emails = new Emails(this);
|
|
1060
|
-
this.campaigns = new Campaigns(this);
|
|
1061
352
|
}
|
|
1062
353
|
/**
|
|
1063
|
-
*
|
|
1064
|
-
* Makes a request to the Zupost API.
|
|
354
|
+
* Get a contact by ID.
|
|
1065
355
|
*/
|
|
1066
|
-
|
|
356
|
+
get(id) {
|
|
1067
357
|
return __async(this, null, function* () {
|
|
1068
|
-
return
|
|
1069
|
-
headers: this.headers,
|
|
1070
|
-
method,
|
|
1071
|
-
retry: 3,
|
|
1072
|
-
prefixUrl: this.baseUrl,
|
|
1073
|
-
json: body
|
|
1074
|
-
}).json();
|
|
358
|
+
return this.http.get(`/contact/${encodeURIComponent(id)}`);
|
|
1075
359
|
});
|
|
1076
360
|
}
|
|
1077
361
|
/**
|
|
1078
|
-
*
|
|
1079
|
-
* Makes a GET request to the Zupost API.
|
|
362
|
+
* List contacts with optional search, consent and tag filters.
|
|
1080
363
|
*/
|
|
1081
|
-
|
|
364
|
+
list() {
|
|
365
|
+
return __async(this, arguments, function* (options = {}) {
|
|
366
|
+
const query = buildQuery({
|
|
367
|
+
skip: options.skip,
|
|
368
|
+
take: options.take,
|
|
369
|
+
search: options.search,
|
|
370
|
+
marketingConsent: options.marketingConsent === void 0 ? void 0 : String(options.marketingConsent),
|
|
371
|
+
tag: options.tag
|
|
372
|
+
});
|
|
373
|
+
return this.http.get(`/contact${query}`);
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Update a contact. Pass only the fields that should change.
|
|
378
|
+
*
|
|
379
|
+
* Toggling `marketingConsent` or `trackingConsent` automatically records
|
|
380
|
+
* a corresponding ContactEvent for the audit trail.
|
|
381
|
+
*/
|
|
382
|
+
update(id, patch) {
|
|
1082
383
|
return __async(this, null, function* () {
|
|
1083
|
-
return this.
|
|
384
|
+
return this.http.patch(`/contact/${encodeURIComponent(id)}`, patch);
|
|
1084
385
|
});
|
|
1085
386
|
}
|
|
1086
387
|
/**
|
|
1087
|
-
*
|
|
1088
|
-
*
|
|
388
|
+
* GDPR right-to-be-forgotten. Anonymises the contact, sets `forgottenAt`
|
|
389
|
+
* and disables consent. Existing email events are anonymised in a
|
|
390
|
+
* follow-up cascade.
|
|
1089
391
|
*/
|
|
1090
|
-
|
|
392
|
+
forget(id) {
|
|
1091
393
|
return __async(this, null, function* () {
|
|
1092
|
-
return this.
|
|
394
|
+
return this.http.delete(`/contact/${encodeURIComponent(id)}`);
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Get the chronological event timeline for a contact.
|
|
399
|
+
*/
|
|
400
|
+
events(_0) {
|
|
401
|
+
return __async(this, arguments, function* (id, options = {}) {
|
|
402
|
+
const query = buildQuery({
|
|
403
|
+
skip: options.skip,
|
|
404
|
+
take: options.take,
|
|
405
|
+
type: options.type
|
|
406
|
+
});
|
|
407
|
+
return this.http.get(`/contact/${encodeURIComponent(id)}/events${query}`);
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* GDPR data access export. Returns the complete record for a contact
|
|
412
|
+
* including all emails, events, subscriptions and tags.
|
|
413
|
+
*/
|
|
414
|
+
export(id) {
|
|
415
|
+
return __async(this, null, function* () {
|
|
416
|
+
return this.http.get(`/contact/${encodeURIComponent(id)}/export`);
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Add a tag to a contact (idempotent).
|
|
421
|
+
*/
|
|
422
|
+
addTag(id, name) {
|
|
423
|
+
return __async(this, null, function* () {
|
|
424
|
+
return this.http.post(`/contact/${encodeURIComponent(id)}/tags`, { name });
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Remove a tag from a contact.
|
|
429
|
+
*/
|
|
430
|
+
removeTag(id, name) {
|
|
431
|
+
return __async(this, null, function* () {
|
|
432
|
+
return this.http.delete(
|
|
433
|
+
`/contact/${encodeURIComponent(id)}/tags/${encodeURIComponent(name)}`
|
|
434
|
+
);
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
// src/sequence/sequences.ts
|
|
440
|
+
function buildQuery2(params) {
|
|
441
|
+
const search = new URLSearchParams();
|
|
442
|
+
for (const [key, value] of Object.entries(params)) {
|
|
443
|
+
if (value === void 0) continue;
|
|
444
|
+
search.set(key, String(value));
|
|
445
|
+
}
|
|
446
|
+
const q = search.toString();
|
|
447
|
+
return q ? `?${q}` : "";
|
|
448
|
+
}
|
|
449
|
+
var Sequences = class {
|
|
450
|
+
constructor(http) {
|
|
451
|
+
this.http = http;
|
|
452
|
+
this.runs = {
|
|
453
|
+
list: (_0, ..._1) => __async(this, [_0, ..._1], function* (sequenceId, options = {}) {
|
|
454
|
+
const query = buildQuery2({
|
|
455
|
+
skip: options.skip,
|
|
456
|
+
take: options.take,
|
|
457
|
+
status: options.status,
|
|
458
|
+
contactId: options.contactId
|
|
459
|
+
});
|
|
460
|
+
return this.http.get(
|
|
461
|
+
`/sequence/${encodeURIComponent(sequenceId)}/runs${query}`
|
|
462
|
+
);
|
|
463
|
+
})
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Create a new sequence (always starts in DRAFT). Pass `definition` to
|
|
468
|
+
* seed the first version, or omit it to create an empty placeholder you
|
|
469
|
+
* can later push versions into.
|
|
470
|
+
*/
|
|
471
|
+
create(options) {
|
|
472
|
+
return __async(this, null, function* () {
|
|
473
|
+
return this.http.post("/sequence", options);
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Get a sequence by ID.
|
|
478
|
+
*/
|
|
479
|
+
get(id) {
|
|
480
|
+
return __async(this, null, function* () {
|
|
481
|
+
return this.http.get(`/sequence/${encodeURIComponent(id)}`);
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* List sequences with filters.
|
|
486
|
+
*/
|
|
487
|
+
list() {
|
|
488
|
+
return __async(this, arguments, function* (options = {}) {
|
|
489
|
+
const query = buildQuery2({
|
|
490
|
+
skip: options.skip,
|
|
491
|
+
take: options.take,
|
|
492
|
+
type: options.type,
|
|
493
|
+
status: options.status,
|
|
494
|
+
search: options.search
|
|
495
|
+
});
|
|
496
|
+
return this.http.get(`/sequence${query}`);
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Delete a sequence and all its versions and runs.
|
|
501
|
+
*/
|
|
502
|
+
delete(id) {
|
|
503
|
+
return __async(this, null, function* () {
|
|
504
|
+
return this.http.delete(`/sequence/${encodeURIComponent(id)}`);
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Change the lifecycle status: DRAFT, ACTIVE, PAUSED, ARCHIVED.
|
|
509
|
+
*/
|
|
510
|
+
setStatus(id, status) {
|
|
511
|
+
return __async(this, null, function* () {
|
|
512
|
+
return this.http.post(`/sequence/${encodeURIComponent(id)}/status`, { status });
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Save a new immutable version of the sequence definition. If `activate`
|
|
517
|
+
* is true (default), the new version becomes the active one for future
|
|
518
|
+
* triggered runs. Existing in-flight runs keep their pinned version.
|
|
519
|
+
*/
|
|
520
|
+
saveVersion(id, options) {
|
|
521
|
+
return __async(this, null, function* () {
|
|
522
|
+
return this.http.post(`/sequence/${encodeURIComponent(id)}/versions`, options);
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Trigger a sequence run for a contact or ad-hoc email. The sequence
|
|
527
|
+
* must be ACTIVE.
|
|
528
|
+
*/
|
|
529
|
+
trigger(id, options) {
|
|
530
|
+
return __async(this, null, function* () {
|
|
531
|
+
if (!options.contactId && !options.email) {
|
|
532
|
+
throw new Error("trigger requires contactId or email");
|
|
533
|
+
}
|
|
534
|
+
return this.http.post(`/sequence/${encodeURIComponent(id)}/runs`, options);
|
|
1093
535
|
});
|
|
1094
536
|
}
|
|
1095
537
|
};
|
|
538
|
+
|
|
539
|
+
// src/zupost.ts
|
|
540
|
+
var _client;
|
|
541
|
+
var Zupost = class {
|
|
542
|
+
constructor(apiKey, options) {
|
|
543
|
+
__privateAdd(this, _client);
|
|
544
|
+
var _a;
|
|
545
|
+
if (!apiKey) {
|
|
546
|
+
throw new Error("API key is required");
|
|
547
|
+
}
|
|
548
|
+
const baseUrl = (_a = options == null ? void 0 : options.baseUrl) != null ? _a : "https://api.zupost.com";
|
|
549
|
+
__privateSet(this, _client, new HttpClient(apiKey, baseUrl, `node-sdk@${version}`));
|
|
550
|
+
this.emails = new Emails(__privateGet(this, _client));
|
|
551
|
+
this.campaigns = new Campaigns(__privateGet(this, _client));
|
|
552
|
+
this.contacts = new Contacts(__privateGet(this, _client));
|
|
553
|
+
this.sequences = new Sequences(__privateGet(this, _client));
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
_client = new WeakMap();
|
|
557
|
+
|
|
558
|
+
// src/sequence/define.ts
|
|
559
|
+
function defineSequence(definition) {
|
|
560
|
+
const issues = [];
|
|
561
|
+
const stepKeys = Object.keys(definition.steps);
|
|
562
|
+
if (!definition.steps[definition.entry]) {
|
|
563
|
+
issues.push(`entry "${String(definition.entry)}" is not a defined step`);
|
|
564
|
+
}
|
|
565
|
+
if (stepKeys.length === 0) issues.push("steps must contain at least one step");
|
|
566
|
+
for (const key of stepKeys) {
|
|
567
|
+
const step = definition.steps[key];
|
|
568
|
+
if (step.key !== key) issues.push(`step.key "${step.key}" does not match object key "${key}"`);
|
|
569
|
+
const checkRef = (ref, where) => {
|
|
570
|
+
if (ref && !definition.steps[ref]) {
|
|
571
|
+
issues.push(`step "${key}" ${where} points at unknown step "${ref}"`);
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
switch (step.type) {
|
|
575
|
+
case "send_email":
|
|
576
|
+
case "wait":
|
|
577
|
+
case "tag_add":
|
|
578
|
+
case "tag_remove":
|
|
579
|
+
case "update_contact":
|
|
580
|
+
case "webhook":
|
|
581
|
+
checkRef(step.next, "next");
|
|
582
|
+
break;
|
|
583
|
+
case "branch":
|
|
584
|
+
checkRef(step.thenNext, "thenNext");
|
|
585
|
+
checkRef(step.elseNext, "elseNext");
|
|
586
|
+
break;
|
|
587
|
+
case "end":
|
|
588
|
+
break;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
if (issues.length > 0) {
|
|
592
|
+
throw new Error(`Invalid sequence definition: ${issues.join("; ")}`);
|
|
593
|
+
}
|
|
594
|
+
return definition;
|
|
595
|
+
}
|
|
1096
596
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1097
597
|
0 && (module.exports = {
|
|
1098
|
-
Zupost
|
|
598
|
+
Zupost,
|
|
599
|
+
ZupostError,
|
|
600
|
+
defineSequence
|
|
1099
601
|
});
|
|
1100
|
-
/*! Bundled license information:
|
|
1101
|
-
|
|
1102
|
-
ky/distribution/index.js:
|
|
1103
|
-
(*! MIT License © Sindre Sorhus *)
|
|
1104
|
-
*/
|