@outseta/n8n-nodes-outseta 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,835 +44,29 @@ __export(exports_Outseta_node, {
44
44
  module.exports = __toCommonJS(exports_Outseta_node);
45
45
  var import_n8n_workflow = require("n8n-workflow");
46
46
 
47
- // ../../node_modules/ky/distribution/errors/HTTPError.js
48
- class HTTPError extends Error {
49
- response;
50
- request;
51
- options;
52
- constructor(response, request, options) {
53
- const code = response.status || response.status === 0 ? response.status : "";
54
- const title = response.statusText ?? "";
55
- const status = `${code} ${title}`.trim();
56
- const reason = status ? `status code ${status}` : "an unknown error";
57
- super(`Request failed with ${reason}: ${request.method} ${request.url}`);
58
- this.name = "HTTPError";
59
- this.response = response;
60
- this.request = request;
61
- this.options = options;
62
- }
63
- }
64
-
65
- // ../../node_modules/ky/distribution/errors/NonError.js
66
- class NonError extends Error {
67
- name = "NonError";
68
- value;
69
- constructor(value) {
70
- let message = "Non-error value was thrown";
71
- try {
72
- if (typeof value === "string") {
73
- message = value;
74
- } else if (value && typeof value === "object" && "message" in value && typeof value.message === "string") {
75
- message = value.message;
76
- }
77
- } catch {}
78
- super(message);
79
- this.value = value;
80
- }
81
- }
82
-
83
- // ../../node_modules/ky/distribution/errors/ForceRetryError.js
84
- class ForceRetryError extends Error {
85
- name = "ForceRetryError";
86
- customDelay;
87
- code;
88
- customRequest;
89
- constructor(options) {
90
- const cause = options?.cause ? options.cause instanceof Error ? options.cause : new NonError(options.cause) : undefined;
91
- super(options?.code ? `Forced retry: ${options.code}` : "Forced retry", cause ? { cause } : undefined);
92
- this.customDelay = options?.delay;
93
- this.code = options?.code;
94
- this.customRequest = options?.request;
95
- }
96
- }
97
-
98
- // ../../node_modules/ky/distribution/core/constants.js
99
- var supportsRequestStreams = (() => {
100
- let duplexAccessed = false;
101
- let hasContentType = false;
102
- const supportsReadableStream = typeof globalThis.ReadableStream === "function";
103
- const supportsRequest = typeof globalThis.Request === "function";
104
- if (supportsReadableStream && supportsRequest) {
105
- try {
106
- hasContentType = new globalThis.Request("https://empty.invalid", {
107
- body: new globalThis.ReadableStream,
108
- method: "POST",
109
- get duplex() {
110
- duplexAccessed = true;
111
- return "half";
112
- }
113
- }).headers.has("Content-Type");
114
- } catch (error) {
115
- if (error instanceof Error && error.message === "unsupported BodyInit type") {
116
- return false;
117
- }
118
- throw error;
119
- }
120
- }
121
- return duplexAccessed && !hasContentType;
122
- })();
123
- var supportsAbortController = typeof globalThis.AbortController === "function";
124
- var supportsAbortSignal = typeof globalThis.AbortSignal === "function" && typeof globalThis.AbortSignal.any === "function";
125
- var supportsResponseStreams = typeof globalThis.ReadableStream === "function";
126
- var supportsFormData = typeof globalThis.FormData === "function";
127
- var requestMethods = ["get", "post", "put", "patch", "head", "delete"];
128
- var validate = () => {
129
- return;
130
- };
131
- validate();
132
- var responseTypes = {
133
- json: "application/json",
134
- text: "text/*",
135
- formData: "multipart/form-data",
136
- arrayBuffer: "*/*",
137
- blob: "*/*",
138
- bytes: "*/*"
139
- };
140
- var maxSafeTimeout = 2147483647;
141
- var usualFormBoundarySize = new TextEncoder().encode("------WebKitFormBoundaryaxpyiPgbbPti10Rw").length;
142
- var stop = Symbol("stop");
143
-
144
- class RetryMarker {
145
- options;
146
- constructor(options) {
147
- this.options = options;
148
- }
149
- }
150
- var retry = (options) => new RetryMarker(options);
151
- var kyOptionKeys = {
152
- json: true,
153
- parseJson: true,
154
- stringifyJson: true,
155
- searchParams: true,
156
- prefixUrl: true,
157
- retry: true,
158
- timeout: true,
159
- hooks: true,
160
- throwHttpErrors: true,
161
- onDownloadProgress: true,
162
- onUploadProgress: true,
163
- fetch: true,
164
- context: true
165
- };
166
- var vendorSpecificOptions = {
167
- next: true
168
- };
169
- var requestOptionsRegistry = {
170
- method: true,
171
- headers: true,
172
- body: true,
173
- mode: true,
174
- credentials: true,
175
- cache: true,
176
- redirect: true,
177
- referrer: true,
178
- referrerPolicy: true,
179
- integrity: true,
180
- keepalive: true,
181
- signal: true,
182
- window: true,
183
- duplex: true
184
- };
185
-
186
- // ../../node_modules/ky/distribution/utils/body.js
187
- var getBodySize = (body) => {
188
- if (!body) {
189
- return 0;
190
- }
191
- if (body instanceof FormData) {
192
- let size = 0;
193
- for (const [key, value] of body) {
194
- size += usualFormBoundarySize;
195
- size += new TextEncoder().encode(`Content-Disposition: form-data; name="${key}"`).length;
196
- size += typeof value === "string" ? new TextEncoder().encode(value).length : value.size;
197
- }
198
- return size;
199
- }
200
- if (body instanceof Blob) {
201
- return body.size;
202
- }
203
- if (body instanceof ArrayBuffer) {
204
- return body.byteLength;
205
- }
206
- if (typeof body === "string") {
207
- return new TextEncoder().encode(body).length;
208
- }
209
- if (body instanceof URLSearchParams) {
210
- return new TextEncoder().encode(body.toString()).length;
211
- }
212
- if ("byteLength" in body) {
213
- return body.byteLength;
214
- }
215
- if (typeof body === "object" && body !== null) {
216
- try {
217
- const jsonString = JSON.stringify(body);
218
- return new TextEncoder().encode(jsonString).length;
219
- } catch {
220
- return 0;
221
- }
222
- }
223
- return 0;
224
- };
225
- var withProgress = (stream, totalBytes, onProgress) => {
226
- let previousChunk;
227
- let transferredBytes = 0;
228
- return stream.pipeThrough(new TransformStream({
229
- transform(currentChunk, controller) {
230
- controller.enqueue(currentChunk);
231
- if (previousChunk) {
232
- transferredBytes += previousChunk.byteLength;
233
- let percent = totalBytes === 0 ? 0 : transferredBytes / totalBytes;
234
- if (percent >= 1) {
235
- percent = 1 - Number.EPSILON;
236
- }
237
- onProgress?.({ percent, totalBytes: Math.max(totalBytes, transferredBytes), transferredBytes }, previousChunk);
238
- }
239
- previousChunk = currentChunk;
240
- },
241
- flush() {
242
- if (previousChunk) {
243
- transferredBytes += previousChunk.byteLength;
244
- onProgress?.({ percent: 1, totalBytes: Math.max(totalBytes, transferredBytes), transferredBytes }, previousChunk);
245
- }
246
- }
247
- }));
248
- };
249
- var streamResponse = (response, onDownloadProgress) => {
250
- if (!response.body) {
251
- return response;
252
- }
253
- if (response.status === 204) {
254
- return new Response(null, {
255
- status: response.status,
256
- statusText: response.statusText,
257
- headers: response.headers
258
- });
259
- }
260
- const totalBytes = Math.max(0, Number(response.headers.get("content-length")) || 0);
261
- return new Response(withProgress(response.body, totalBytes, onDownloadProgress), {
262
- status: response.status,
263
- statusText: response.statusText,
264
- headers: response.headers
265
- });
266
- };
267
- var streamRequest = (request, onUploadProgress, originalBody) => {
268
- if (!request.body) {
269
- return request;
270
- }
271
- const totalBytes = getBodySize(originalBody ?? request.body);
272
- return new Request(request, {
273
- duplex: "half",
274
- body: withProgress(request.body, totalBytes, onUploadProgress)
275
- });
276
- };
277
-
278
- // ../../node_modules/ky/distribution/utils/is.js
279
- var isObject = (value) => value !== null && typeof value === "object";
280
-
281
- // ../../node_modules/ky/distribution/utils/merge.js
282
- var validateAndMerge = (...sources) => {
283
- for (const source of sources) {
284
- if ((!isObject(source) || Array.isArray(source)) && source !== undefined) {
285
- throw new TypeError("The `options` argument must be an object");
286
- }
287
- }
288
- return deepMerge({}, ...sources);
289
- };
290
- var mergeHeaders = (source1 = {}, source2 = {}) => {
291
- const result = new globalThis.Headers(source1);
292
- const isHeadersInstance = source2 instanceof globalThis.Headers;
293
- const source = new globalThis.Headers(source2);
294
- for (const [key, value] of source.entries()) {
295
- if (isHeadersInstance && value === "undefined" || value === undefined) {
296
- result.delete(key);
297
- } else {
298
- result.set(key, value);
299
- }
47
+ // ../api-client/dist/index.js
48
+ function getAuthorization(creds) {
49
+ if ("accessToken" in creds) {
50
+ return `Bearer ${creds.accessToken}`;
300
51
  }
301
- return result;
302
- };
303
- function newHookValue(original, incoming, property) {
304
- return Object.hasOwn(incoming, property) && incoming[property] === undefined ? [] : deepMerge(original[property] ?? [], incoming[property] ?? []);
52
+ return `Outseta ${creds.apiKey}:${creds.apiSecret}`;
305
53
  }
306
- var mergeHooks = (original = {}, incoming = {}) => ({
307
- beforeRequest: newHookValue(original, incoming, "beforeRequest"),
308
- beforeRetry: newHookValue(original, incoming, "beforeRetry"),
309
- afterResponse: newHookValue(original, incoming, "afterResponse"),
310
- beforeError: newHookValue(original, incoming, "beforeError")
311
- });
312
- var appendSearchParameters = (target, source) => {
313
- const result = new URLSearchParams;
314
- for (const input of [target, source]) {
315
- if (input === undefined) {
316
- continue;
317
- }
318
- if (input instanceof URLSearchParams) {
319
- for (const [key, value] of input.entries()) {
320
- result.append(key, value);
321
- }
322
- } else if (Array.isArray(input)) {
323
- for (const pair of input) {
324
- if (!Array.isArray(pair) || pair.length !== 2) {
325
- throw new TypeError("Array search parameters must be provided in [[key, value], ...] format");
326
- }
327
- result.append(String(pair[0]), String(pair[1]));
328
- }
329
- } else if (isObject(input)) {
330
- for (const [key, value] of Object.entries(input)) {
331
- if (value !== undefined) {
332
- result.append(key, String(value));
333
- }
334
- }
335
- } else {
336
- const parameters = new URLSearchParams(input);
337
- for (const [key, value] of parameters.entries()) {
338
- result.append(key, value);
339
- }
340
- }
341
- }
342
- return result;
343
- };
344
- var deepMerge = (...sources) => {
345
- let returnValue = {};
346
- let headers = {};
347
- let hooks = {};
348
- let searchParameters;
349
- const signals = [];
350
- for (const source of sources) {
351
- if (Array.isArray(source)) {
352
- if (!Array.isArray(returnValue)) {
353
- returnValue = [];
354
- }
355
- returnValue = [...returnValue, ...source];
356
- } else if (isObject(source)) {
357
- for (let [key, value] of Object.entries(source)) {
358
- if (key === "signal" && value instanceof globalThis.AbortSignal) {
359
- signals.push(value);
360
- continue;
361
- }
362
- if (key === "context") {
363
- if (value !== undefined && value !== null && (!isObject(value) || Array.isArray(value))) {
364
- throw new TypeError("The `context` option must be an object");
365
- }
366
- returnValue = {
367
- ...returnValue,
368
- context: value === undefined || value === null ? {} : { ...returnValue.context, ...value }
369
- };
370
- continue;
371
- }
372
- if (key === "searchParams") {
373
- if (value === undefined || value === null) {
374
- searchParameters = undefined;
375
- } else {
376
- searchParameters = searchParameters === undefined ? value : appendSearchParameters(searchParameters, value);
377
- }
378
- continue;
379
- }
380
- if (isObject(value) && key in returnValue) {
381
- value = deepMerge(returnValue[key], value);
382
- }
383
- returnValue = { ...returnValue, [key]: value };
384
- }
385
- if (isObject(source.hooks)) {
386
- hooks = mergeHooks(hooks, source.hooks);
387
- returnValue.hooks = hooks;
388
- }
389
- if (isObject(source.headers)) {
390
- headers = mergeHeaders(headers, source.headers);
391
- returnValue.headers = headers;
392
- }
393
- }
394
- }
395
- if (searchParameters !== undefined) {
396
- returnValue.searchParams = searchParameters;
397
- }
398
- if (signals.length > 0) {
399
- if (signals.length === 1) {
400
- returnValue.signal = signals[0];
401
- } else if (supportsAbortSignal) {
402
- returnValue.signal = AbortSignal.any(signals);
403
- } else {
404
- returnValue.signal = signals.at(-1);
405
- }
406
- }
407
- return returnValue;
408
- };
409
-
410
- // ../../node_modules/ky/distribution/utils/normalize.js
411
- var normalizeRequestMethod = (input) => requestMethods.includes(input) ? input.toUpperCase() : input;
412
- var retryMethods = ["get", "put", "head", "delete", "options", "trace"];
413
- var retryStatusCodes = [408, 413, 429, 500, 502, 503, 504];
414
- var retryAfterStatusCodes = [413, 429, 503];
415
- var defaultRetryOptions = {
416
- limit: 2,
417
- methods: retryMethods,
418
- statusCodes: retryStatusCodes,
419
- afterStatusCodes: retryAfterStatusCodes,
420
- maxRetryAfter: Number.POSITIVE_INFINITY,
421
- backoffLimit: Number.POSITIVE_INFINITY,
422
- delay: (attemptCount) => 0.3 * 2 ** (attemptCount - 1) * 1000,
423
- jitter: undefined,
424
- retryOnTimeout: false
425
- };
426
- var normalizeRetryOptions = (retry2 = {}) => {
427
- if (typeof retry2 === "number") {
428
- return {
429
- ...defaultRetryOptions,
430
- limit: retry2
431
- };
432
- }
433
- if (retry2.methods && !Array.isArray(retry2.methods)) {
434
- throw new Error("retry.methods must be an array");
435
- }
436
- retry2.methods &&= retry2.methods.map((method) => method.toLowerCase());
437
- if (retry2.statusCodes && !Array.isArray(retry2.statusCodes)) {
438
- throw new Error("retry.statusCodes must be an array");
439
- }
440
- const normalizedRetry = Object.fromEntries(Object.entries(retry2).filter(([, value]) => value !== undefined));
441
- return {
442
- ...defaultRetryOptions,
443
- ...normalizedRetry
444
- };
445
- };
446
-
447
- // ../../node_modules/ky/distribution/errors/TimeoutError.js
448
- class TimeoutError extends Error {
449
- request;
450
- constructor(request) {
451
- super(`Request timed out: ${request.method} ${request.url}`);
452
- this.name = "TimeoutError";
453
- this.request = request;
54
+ function getRequestUrl(subdomain, path) {
55
+ if (/^https?:\/\//.test(path)) {
56
+ return path;
454
57
  }
58
+ const normalizedPath = path.startsWith("/api/v1/") ? path : `/api/v1/${path.replace(/^\/+/, "")}`;
59
+ return new URL(normalizedPath, `https://${subdomain}.outseta.com`).toString();
455
60
  }
456
-
457
- // ../../node_modules/ky/distribution/utils/timeout.js
458
- async function timeout(request, init, abortController, options) {
459
- return new Promise((resolve, reject) => {
460
- const timeoutId = setTimeout(() => {
461
- if (abortController) {
462
- abortController.abort();
463
- }
464
- reject(new TimeoutError(request));
465
- }, options.timeout);
466
- options.fetch(request, init).then(resolve).catch(reject).then(() => {
467
- clearTimeout(timeoutId);
468
- });
469
- });
470
- }
471
-
472
- // ../../node_modules/ky/distribution/utils/delay.js
473
- async function delay(ms, { signal }) {
474
- return new Promise((resolve, reject) => {
475
- if (signal) {
476
- signal.throwIfAborted();
477
- signal.addEventListener("abort", abortHandler, { once: true });
478
- }
479
- function abortHandler() {
480
- clearTimeout(timeoutId);
481
- reject(signal.reason);
482
- }
483
- const timeoutId = setTimeout(() => {
484
- signal?.removeEventListener("abort", abortHandler);
485
- resolve();
486
- }, ms);
487
- });
488
- }
489
-
490
- // ../../node_modules/ky/distribution/utils/options.js
491
- var findUnknownOptions = (request, options) => {
492
- const unknownOptions = {};
493
- for (const key in options) {
494
- if (!Object.hasOwn(options, key)) {
495
- continue;
496
- }
497
- if (!(key in requestOptionsRegistry) && !(key in kyOptionKeys) && (!(key in request) || (key in vendorSpecificOptions))) {
498
- unknownOptions[key] = options[key];
499
- }
500
- }
501
- return unknownOptions;
502
- };
503
- var hasSearchParameters = (search) => {
504
- if (search === undefined) {
505
- return false;
506
- }
507
- if (Array.isArray(search)) {
508
- return search.length > 0;
509
- }
510
- if (search instanceof URLSearchParams) {
511
- return search.size > 0;
512
- }
513
- if (typeof search === "object") {
514
- return Object.keys(search).length > 0;
515
- }
516
- if (typeof search === "string") {
517
- return search.trim().length > 0;
518
- }
519
- return Boolean(search);
520
- };
521
-
522
- // ../../node_modules/ky/distribution/utils/type-guards.js
523
- function isHTTPError(error) {
524
- return error instanceof HTTPError || error?.name === HTTPError.name;
525
- }
526
- function isTimeoutError(error) {
527
- return error instanceof TimeoutError || error?.name === TimeoutError.name;
528
- }
529
-
530
- // ../../node_modules/ky/distribution/core/Ky.js
531
- class Ky {
532
- static create(input, options) {
533
- const ky = new Ky(input, options);
534
- const function_ = async () => {
535
- if (typeof ky.#options.timeout === "number" && ky.#options.timeout > maxSafeTimeout) {
536
- throw new RangeError(`The \`timeout\` option cannot be greater than ${maxSafeTimeout}`);
537
- }
538
- await Promise.resolve();
539
- let response = await ky.#fetch();
540
- for (const hook of ky.#options.hooks.afterResponse) {
541
- const clonedResponse = ky.#decorateResponse(response.clone());
542
- let modifiedResponse;
543
- try {
544
- modifiedResponse = await hook(ky.request, ky.#getNormalizedOptions(), clonedResponse, { retryCount: ky.#retryCount });
545
- } catch (error) {
546
- ky.#cancelResponseBody(clonedResponse);
547
- ky.#cancelResponseBody(response);
548
- throw error;
549
- }
550
- if (modifiedResponse instanceof RetryMarker) {
551
- ky.#cancelResponseBody(clonedResponse);
552
- ky.#cancelResponseBody(response);
553
- throw new ForceRetryError(modifiedResponse.options);
554
- }
555
- const nextResponse = modifiedResponse instanceof globalThis.Response ? modifiedResponse : response;
556
- if (clonedResponse !== nextResponse) {
557
- ky.#cancelResponseBody(clonedResponse);
558
- }
559
- if (response !== nextResponse) {
560
- ky.#cancelResponseBody(response);
561
- }
562
- response = nextResponse;
563
- }
564
- ky.#decorateResponse(response);
565
- if (!response.ok && (typeof ky.#options.throwHttpErrors === "function" ? ky.#options.throwHttpErrors(response.status) : ky.#options.throwHttpErrors)) {
566
- let error = new HTTPError(response, ky.request, ky.#getNormalizedOptions());
567
- for (const hook of ky.#options.hooks.beforeError) {
568
- error = await hook(error, { retryCount: ky.#retryCount });
569
- }
570
- throw error;
571
- }
572
- if (ky.#options.onDownloadProgress) {
573
- if (typeof ky.#options.onDownloadProgress !== "function") {
574
- throw new TypeError("The `onDownloadProgress` option must be a function");
575
- }
576
- if (!supportsResponseStreams) {
577
- throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
578
- }
579
- const progressResponse = response.clone();
580
- ky.#cancelResponseBody(response);
581
- return streamResponse(progressResponse, ky.#options.onDownloadProgress);
582
- }
583
- return response;
584
- };
585
- const result = ky.#retry(function_).finally(() => {
586
- const originalRequest = ky.#originalRequest;
587
- ky.#cancelBody(originalRequest?.body ?? undefined);
588
- ky.#cancelBody(ky.request.body ?? undefined);
589
- });
590
- for (const [type, mimeType] of Object.entries(responseTypes)) {
591
- if (type === "bytes" && typeof globalThis.Response?.prototype?.bytes !== "function") {
592
- continue;
593
- }
594
- result[type] = async () => {
595
- ky.request.headers.set("accept", ky.request.headers.get("accept") || mimeType);
596
- const response = await result;
597
- if (type === "json") {
598
- if (response.status === 204) {
599
- return "";
600
- }
601
- const text = await response.text();
602
- if (text === "") {
603
- return "";
604
- }
605
- if (options.parseJson) {
606
- return options.parseJson(text);
607
- }
608
- return JSON.parse(text);
609
- }
610
- return response[type]();
611
- };
612
- }
613
- return result;
614
- }
615
- static #normalizeSearchParams(searchParams) {
616
- if (searchParams && typeof searchParams === "object" && !Array.isArray(searchParams) && !(searchParams instanceof URLSearchParams)) {
617
- return Object.fromEntries(Object.entries(searchParams).filter(([, value]) => value !== undefined));
618
- }
619
- return searchParams;
620
- }
621
- request;
622
- #abortController;
623
- #retryCount = 0;
624
- #input;
625
- #options;
626
- #originalRequest;
627
- #userProvidedAbortSignal;
628
- #cachedNormalizedOptions;
629
- constructor(input, options = {}) {
630
- this.#input = input;
631
- this.#options = {
632
- ...options,
633
- headers: mergeHeaders(this.#input.headers, options.headers),
634
- hooks: mergeHooks({
635
- beforeRequest: [],
636
- beforeRetry: [],
637
- beforeError: [],
638
- afterResponse: []
639
- }, options.hooks),
640
- method: normalizeRequestMethod(options.method ?? this.#input.method ?? "GET"),
641
- prefixUrl: String(options.prefixUrl || ""),
642
- retry: normalizeRetryOptions(options.retry),
643
- throwHttpErrors: options.throwHttpErrors ?? true,
644
- timeout: options.timeout ?? 1e4,
645
- fetch: options.fetch ?? globalThis.fetch.bind(globalThis),
646
- context: options.context ?? {}
647
- };
648
- if (typeof this.#input !== "string" && !(this.#input instanceof URL || this.#input instanceof globalThis.Request)) {
649
- throw new TypeError("`input` must be a string, URL, or Request");
650
- }
651
- if (this.#options.prefixUrl && typeof this.#input === "string") {
652
- if (this.#input.startsWith("/")) {
653
- throw new Error("`input` must not begin with a slash when using `prefixUrl`");
654
- }
655
- if (!this.#options.prefixUrl.endsWith("/")) {
656
- this.#options.prefixUrl += "/";
657
- }
658
- this.#input = this.#options.prefixUrl + this.#input;
659
- }
660
- if (supportsAbortController && supportsAbortSignal) {
661
- this.#userProvidedAbortSignal = this.#options.signal ?? this.#input.signal;
662
- this.#abortController = new globalThis.AbortController;
663
- this.#options.signal = this.#userProvidedAbortSignal ? AbortSignal.any([this.#userProvidedAbortSignal, this.#abortController.signal]) : this.#abortController.signal;
664
- }
665
- if (supportsRequestStreams) {
666
- this.#options.duplex = "half";
667
- }
668
- if (this.#options.json !== undefined) {
669
- this.#options.body = this.#options.stringifyJson?.(this.#options.json) ?? JSON.stringify(this.#options.json);
670
- this.#options.headers.set("content-type", this.#options.headers.get("content-type") ?? "application/json");
671
- }
672
- const userProvidedContentType = options.headers && new globalThis.Headers(options.headers).has("content-type");
673
- if (this.#input instanceof globalThis.Request && (supportsFormData && this.#options.body instanceof globalThis.FormData || this.#options.body instanceof URLSearchParams) && !userProvidedContentType) {
674
- this.#options.headers.delete("content-type");
675
- }
676
- this.request = new globalThis.Request(this.#input, this.#options);
677
- if (hasSearchParameters(this.#options.searchParams)) {
678
- const textSearchParams = typeof this.#options.searchParams === "string" ? this.#options.searchParams.replace(/^\?/, "") : new URLSearchParams(Ky.#normalizeSearchParams(this.#options.searchParams)).toString();
679
- const searchParams = "?" + textSearchParams;
680
- const url = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, searchParams);
681
- this.request = new globalThis.Request(url, this.#options);
682
- }
683
- if (this.#options.onUploadProgress) {
684
- if (typeof this.#options.onUploadProgress !== "function") {
685
- throw new TypeError("The `onUploadProgress` option must be a function");
686
- }
687
- if (!supportsRequestStreams) {
688
- throw new Error("Request streams are not supported in your environment. The `duplex` option for `Request` is not available.");
689
- }
690
- this.request = this.#wrapRequestWithUploadProgress(this.request, this.#options.body ?? undefined);
691
- }
692
- }
693
- #calculateDelay() {
694
- const retryDelay = this.#options.retry.delay(this.#retryCount);
695
- let jitteredDelay = retryDelay;
696
- if (this.#options.retry.jitter === true) {
697
- jitteredDelay = Math.random() * retryDelay;
698
- } else if (typeof this.#options.retry.jitter === "function") {
699
- jitteredDelay = this.#options.retry.jitter(retryDelay);
700
- if (!Number.isFinite(jitteredDelay) || jitteredDelay < 0) {
701
- jitteredDelay = retryDelay;
702
- }
703
- }
704
- const backoffLimit = this.#options.retry.backoffLimit ?? Number.POSITIVE_INFINITY;
705
- return Math.min(backoffLimit, jitteredDelay);
706
- }
707
- async#calculateRetryDelay(error) {
708
- this.#retryCount++;
709
- if (this.#retryCount > this.#options.retry.limit) {
710
- throw error;
711
- }
712
- const errorObject = error instanceof Error ? error : new NonError(error);
713
- if (errorObject instanceof ForceRetryError) {
714
- return errorObject.customDelay ?? this.#calculateDelay();
715
- }
716
- if (!this.#options.retry.methods.includes(this.request.method.toLowerCase())) {
717
- throw error;
718
- }
719
- if (this.#options.retry.shouldRetry !== undefined) {
720
- const result = await this.#options.retry.shouldRetry({ error: errorObject, retryCount: this.#retryCount });
721
- if (result === false) {
722
- throw error;
723
- }
724
- if (result === true) {
725
- return this.#calculateDelay();
726
- }
727
- }
728
- if (isTimeoutError(error) && !this.#options.retry.retryOnTimeout) {
729
- throw error;
730
- }
731
- if (isHTTPError(error)) {
732
- if (!this.#options.retry.statusCodes.includes(error.response.status)) {
733
- throw error;
734
- }
735
- const retryAfter = error.response.headers.get("Retry-After") ?? error.response.headers.get("RateLimit-Reset") ?? error.response.headers.get("X-RateLimit-Retry-After") ?? error.response.headers.get("X-RateLimit-Reset") ?? error.response.headers.get("X-Rate-Limit-Reset");
736
- if (retryAfter && this.#options.retry.afterStatusCodes.includes(error.response.status)) {
737
- let after = Number(retryAfter) * 1000;
738
- if (Number.isNaN(after)) {
739
- after = Date.parse(retryAfter) - Date.now();
740
- } else if (after >= Date.parse("2024-01-01")) {
741
- after -= Date.now();
742
- }
743
- const max = this.#options.retry.maxRetryAfter ?? after;
744
- return after < max ? after : max;
745
- }
746
- if (error.response.status === 413) {
747
- throw error;
748
- }
749
- }
750
- return this.#calculateDelay();
751
- }
752
- #decorateResponse(response) {
753
- if (this.#options.parseJson) {
754
- response.json = async () => this.#options.parseJson(await response.text());
755
- }
756
- return response;
757
- }
758
- #cancelBody(body) {
759
- if (!body) {
760
- return;
761
- }
762
- body.cancel().catch(() => {
763
- return;
61
+ function createClient(creds) {
62
+ return (path, init = {}) => {
63
+ const headers = new Headers(init.headers);
64
+ headers.set("Authorization", getAuthorization(creds));
65
+ return fetch(getRequestUrl(creds.subdomain, path), {
66
+ ...init,
67
+ headers
764
68
  });
765
- }
766
- #cancelResponseBody(response) {
767
- this.#cancelBody(response.body ?? undefined);
768
- }
769
- async#retry(function_) {
770
- try {
771
- return await function_();
772
- } catch (error) {
773
- const ms = Math.min(await this.#calculateRetryDelay(error), maxSafeTimeout);
774
- if (this.#retryCount < 1) {
775
- throw error;
776
- }
777
- await delay(ms, this.#userProvidedAbortSignal ? { signal: this.#userProvidedAbortSignal } : {});
778
- if (error instanceof ForceRetryError && error.customRequest) {
779
- const managedRequest = this.#options.signal ? new globalThis.Request(error.customRequest, { signal: this.#options.signal }) : new globalThis.Request(error.customRequest);
780
- this.#assignRequest(managedRequest);
781
- }
782
- for (const hook of this.#options.hooks.beforeRetry) {
783
- const hookResult = await hook({
784
- request: this.request,
785
- options: this.#getNormalizedOptions(),
786
- error,
787
- retryCount: this.#retryCount
788
- });
789
- if (hookResult instanceof globalThis.Request) {
790
- this.#assignRequest(hookResult);
791
- break;
792
- }
793
- if (hookResult instanceof globalThis.Response) {
794
- return hookResult;
795
- }
796
- if (hookResult === stop) {
797
- return;
798
- }
799
- }
800
- return this.#retry(function_);
801
- }
802
- }
803
- async#fetch() {
804
- if (this.#abortController?.signal.aborted) {
805
- this.#abortController = new globalThis.AbortController;
806
- this.#options.signal = this.#userProvidedAbortSignal ? AbortSignal.any([this.#userProvidedAbortSignal, this.#abortController.signal]) : this.#abortController.signal;
807
- this.request = new globalThis.Request(this.request, { signal: this.#options.signal });
808
- }
809
- for (const hook of this.#options.hooks.beforeRequest) {
810
- const result = await hook(this.request, this.#getNormalizedOptions(), { retryCount: this.#retryCount });
811
- if (result instanceof Response) {
812
- return result;
813
- }
814
- if (result instanceof globalThis.Request) {
815
- this.#assignRequest(result);
816
- break;
817
- }
818
- }
819
- const nonRequestOptions = findUnknownOptions(this.request, this.#options);
820
- this.#originalRequest = this.request;
821
- this.request = this.#originalRequest.clone();
822
- if (this.#options.timeout === false) {
823
- return this.#options.fetch(this.#originalRequest, nonRequestOptions);
824
- }
825
- return timeout(this.#originalRequest, nonRequestOptions, this.#abortController, this.#options);
826
- }
827
- #getNormalizedOptions() {
828
- if (!this.#cachedNormalizedOptions) {
829
- const { hooks, ...normalizedOptions } = this.#options;
830
- this.#cachedNormalizedOptions = Object.freeze(normalizedOptions);
831
- }
832
- return this.#cachedNormalizedOptions;
833
- }
834
- #assignRequest(request) {
835
- this.#cachedNormalizedOptions = undefined;
836
- this.request = this.#wrapRequestWithUploadProgress(request);
837
- }
838
- #wrapRequestWithUploadProgress(request, originalBody) {
839
- if (!this.#options.onUploadProgress || !request.body) {
840
- return request;
841
- }
842
- return streamRequest(request, this.#options.onUploadProgress, originalBody ?? this.#options.body ?? undefined);
843
- }
844
- }
845
-
846
- // ../../node_modules/ky/distribution/index.js
847
- /*! MIT License © Sindre Sorhus */
848
- var createInstance = (defaults) => {
849
- const ky = (input, options) => Ky.create(input, validateAndMerge(defaults, options));
850
- for (const method of requestMethods) {
851
- ky[method] = (input, options) => Ky.create(input, validateAndMerge(defaults, options, { method }));
852
- }
853
- ky.create = (newDefaults) => createInstance(validateAndMerge(newDefaults));
854
- ky.extend = (newDefaults) => {
855
- if (typeof newDefaults === "function") {
856
- newDefaults = newDefaults(defaults ?? {});
857
- }
858
- return createInstance(validateAndMerge(defaults, newDefaults));
859
69
  };
860
- ky.stop = stop;
861
- ky.retry = retry;
862
- return ky;
863
- };
864
- var ky = createInstance();
865
- var distribution_default = ky;
866
-
867
- // ../api-client/dist/index.js
868
- function createClient(creds) {
869
- return distribution_default.create({
870
- prefixUrl: `https://${creds.subdomain}.outseta.com/api/v1/`,
871
- headers: {
872
- Authorization: `Outseta ${creds.apiKey}:${creds.apiSecret}`
873
- },
874
- retry: { limit: 3, statusCodes: [408, 429, 500, 502, 503, 504] }
875
- });
876
70
  }
877
71
 
878
72
  // src/nodes/Outseta/Outseta.node.ts
@@ -1586,12 +780,20 @@ class Outseta {
1586
780
  }
1587
781
  }
1588
782
  async function request(client, method, endpoint, body, searchParams) {
1589
- const options = {};
1590
- if (body)
1591
- options.json = body;
1592
- if (searchParams)
1593
- options.searchParams = searchParams;
1594
- return await client[method](endpoint, options).json();
783
+ const query = searchParams ? new URLSearchParams(searchParams).toString() : "";
784
+ const response = await client(query ? `${endpoint}?${query}` : endpoint, {
785
+ method: method.toUpperCase(),
786
+ headers: body ? { "Content-Type": "application/json" } : undefined,
787
+ body: body ? JSON.stringify(body) : undefined
788
+ });
789
+ if (!response.ok) {
790
+ const message = await response.text();
791
+ throw new Error(message || `Outseta request failed with status ${response.status}`);
792
+ }
793
+ if (response.status === 204) {
794
+ return {};
795
+ }
796
+ return await response.json();
1595
797
  }
1596
798
  async function makeListRequest(client, ctx, itemIndex, endpoint) {
1597
799
  const searchParams = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@outseta/n8n-nodes-outseta",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "n8n community node for the Outseta REST API",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",
@@ -26,13 +26,8 @@
26
26
  "dist/nodes/Outseta/Outseta.node.js"
27
27
  ]
28
28
  },
29
- "scripts": {
30
- "build": "bun build src/credentials/OutsetaApi.credentials.ts --outdir dist/credentials --format cjs --target node --external n8n-workflow && bun build src/nodes/Outseta/Outseta.node.ts --outdir dist/nodes/Outseta --format cjs --target node --external n8n-workflow && cp src/nodes/Outseta/outseta.svg dist/nodes/Outseta/",
31
- "typecheck": "tsc --noEmit",
32
- "lint": "eslint src"
33
- },
34
29
  "dependencies": {
35
- "@outseta/api-client": "*"
30
+ "@outseta/api-client": "0.2.4"
36
31
  },
37
32
  "devDependencies": {
38
33
  "n8n-workflow": "^1.0.0",
@@ -47,5 +42,10 @@
47
42
  "publishConfig": {
48
43
  "access": "public",
49
44
  "provenance": false
45
+ },
46
+ "scripts": {
47
+ "build": "rimraf dist && bun build src/credentials/OutsetaApi.credentials.ts --outdir dist/credentials --format cjs --target node --external n8n-workflow && bun build src/nodes/Outseta/Outseta.node.ts --outdir dist/nodes/Outseta --format cjs --target node --external n8n-workflow && node -e \"require('fs').cpSync('src/nodes/Outseta/outseta.svg','dist/nodes/Outseta/outseta.svg')\"",
48
+ "typecheck": "tsc --noEmit",
49
+ "lint": "eslint src"
50
50
  }
51
- }
51
+ }