@usenadia/node 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs ADDED
@@ -0,0 +1,1623 @@
1
+ // src/generated/core/bodySerializer.gen.ts
2
+ var serializeFormDataPair = (data, key, value) => {
3
+ if (typeof value === "string" || value instanceof Blob) {
4
+ data.append(key, value);
5
+ } else if (value instanceof Date) {
6
+ data.append(key, value.toISOString());
7
+ } else {
8
+ data.append(key, JSON.stringify(value));
9
+ }
10
+ };
11
+ var formDataBodySerializer = {
12
+ bodySerializer: (body) => {
13
+ const data = new FormData();
14
+ Object.entries(body).forEach(([key, value]) => {
15
+ if (value === void 0 || value === null) {
16
+ return;
17
+ }
18
+ if (Array.isArray(value)) {
19
+ value.forEach((v) => serializeFormDataPair(data, key, v));
20
+ } else {
21
+ serializeFormDataPair(data, key, value);
22
+ }
23
+ });
24
+ return data;
25
+ }
26
+ };
27
+ var jsonBodySerializer = {
28
+ bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value)
29
+ };
30
+
31
+ // src/generated/core/params.gen.ts
32
+ var extraPrefixesMap = {
33
+ $body_: "body",
34
+ $headers_: "headers",
35
+ $path_: "path",
36
+ $query_: "query"
37
+ };
38
+ var extraPrefixes = Object.entries(extraPrefixesMap);
39
+
40
+ // src/generated/core/serverSentEvents.gen.ts
41
+ function createSseClient({
42
+ onRequest,
43
+ onSseError,
44
+ onSseEvent,
45
+ responseTransformer,
46
+ responseValidator,
47
+ sseDefaultRetryDelay,
48
+ sseMaxRetryAttempts,
49
+ sseMaxRetryDelay,
50
+ sseSleepFn,
51
+ url,
52
+ ...options
53
+ }) {
54
+ let lastEventId;
55
+ const sleep2 = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
56
+ const createStream = async function* () {
57
+ let retryDelay = sseDefaultRetryDelay ?? 3e3;
58
+ let attempt = 0;
59
+ const signal = options.signal ?? new AbortController().signal;
60
+ while (true) {
61
+ if (signal.aborted) break;
62
+ attempt++;
63
+ const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
64
+ if (lastEventId !== void 0) {
65
+ headers.set("Last-Event-ID", lastEventId);
66
+ }
67
+ try {
68
+ const requestInit = {
69
+ redirect: "follow",
70
+ ...options,
71
+ body: options.serializedBody,
72
+ headers,
73
+ signal
74
+ };
75
+ let request = new Request(url, requestInit);
76
+ if (onRequest) {
77
+ request = await onRequest(url, requestInit);
78
+ }
79
+ const _fetch = options.fetch ?? globalThis.fetch;
80
+ const response = await _fetch(request);
81
+ if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
82
+ if (!response.body) throw new Error("No body in SSE response");
83
+ const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
84
+ let buffer = "";
85
+ const abortHandler = () => {
86
+ try {
87
+ reader.cancel();
88
+ } catch {
89
+ }
90
+ };
91
+ signal.addEventListener("abort", abortHandler);
92
+ try {
93
+ while (true) {
94
+ const { done, value } = await reader.read();
95
+ if (done) break;
96
+ buffer += value;
97
+ buffer = buffer.replace(/\r\n?/g, "\n");
98
+ const chunks = buffer.split("\n\n");
99
+ buffer = chunks.pop() ?? "";
100
+ for (const chunk of chunks) {
101
+ const lines = chunk.split("\n");
102
+ const dataLines = [];
103
+ let eventName;
104
+ for (const line of lines) {
105
+ if (line.startsWith("data:")) {
106
+ dataLines.push(line.replace(/^data:\s*/, ""));
107
+ } else if (line.startsWith("event:")) {
108
+ eventName = line.replace(/^event:\s*/, "");
109
+ } else if (line.startsWith("id:")) {
110
+ lastEventId = line.replace(/^id:\s*/, "");
111
+ } else if (line.startsWith("retry:")) {
112
+ const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
113
+ if (!Number.isNaN(parsed)) {
114
+ retryDelay = parsed;
115
+ }
116
+ }
117
+ }
118
+ let data;
119
+ let parsedJson = false;
120
+ if (dataLines.length) {
121
+ const rawData = dataLines.join("\n");
122
+ try {
123
+ data = JSON.parse(rawData);
124
+ parsedJson = true;
125
+ } catch {
126
+ data = rawData;
127
+ }
128
+ }
129
+ if (parsedJson) {
130
+ if (responseValidator) {
131
+ await responseValidator(data);
132
+ }
133
+ if (responseTransformer) {
134
+ data = await responseTransformer(data);
135
+ }
136
+ }
137
+ onSseEvent?.({
138
+ data,
139
+ event: eventName,
140
+ id: lastEventId,
141
+ retry: retryDelay
142
+ });
143
+ if (dataLines.length) {
144
+ yield data;
145
+ }
146
+ }
147
+ }
148
+ } finally {
149
+ signal.removeEventListener("abort", abortHandler);
150
+ reader.releaseLock();
151
+ }
152
+ break;
153
+ } catch (error) {
154
+ onSseError?.(error);
155
+ if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
156
+ break;
157
+ }
158
+ const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
159
+ await sleep2(backoff);
160
+ }
161
+ }
162
+ };
163
+ const stream = createStream();
164
+ return { stream };
165
+ }
166
+
167
+ // src/generated/core/pathSerializer.gen.ts
168
+ var separatorArrayExplode = (style) => {
169
+ switch (style) {
170
+ case "label":
171
+ return ".";
172
+ case "matrix":
173
+ return ";";
174
+ case "simple":
175
+ return ",";
176
+ default:
177
+ return "&";
178
+ }
179
+ };
180
+ var separatorArrayNoExplode = (style) => {
181
+ switch (style) {
182
+ case "form":
183
+ return ",";
184
+ case "pipeDelimited":
185
+ return "|";
186
+ case "spaceDelimited":
187
+ return "%20";
188
+ default:
189
+ return ",";
190
+ }
191
+ };
192
+ var separatorObjectExplode = (style) => {
193
+ switch (style) {
194
+ case "label":
195
+ return ".";
196
+ case "matrix":
197
+ return ";";
198
+ case "simple":
199
+ return ",";
200
+ default:
201
+ return "&";
202
+ }
203
+ };
204
+ var serializeArrayParam = ({
205
+ allowReserved,
206
+ explode,
207
+ name,
208
+ style,
209
+ value
210
+ }) => {
211
+ if (!explode) {
212
+ const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
213
+ switch (style) {
214
+ case "label":
215
+ return `.${joinedValues2}`;
216
+ case "matrix":
217
+ return `;${name}=${joinedValues2}`;
218
+ case "simple":
219
+ return joinedValues2;
220
+ default:
221
+ return `${name}=${joinedValues2}`;
222
+ }
223
+ }
224
+ const separator = separatorArrayExplode(style);
225
+ const joinedValues = value.map((v) => {
226
+ if (style === "label" || style === "simple") {
227
+ return allowReserved ? v : encodeURIComponent(v);
228
+ }
229
+ return serializePrimitiveParam({
230
+ allowReserved,
231
+ name,
232
+ value: v
233
+ });
234
+ }).join(separator);
235
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
236
+ };
237
+ var serializePrimitiveParam = ({
238
+ allowReserved,
239
+ name,
240
+ value
241
+ }) => {
242
+ if (value === void 0 || value === null) {
243
+ return "";
244
+ }
245
+ if (typeof value === "object") {
246
+ throw new Error(
247
+ "Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
248
+ );
249
+ }
250
+ return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
251
+ };
252
+ var serializeObjectParam = ({
253
+ allowReserved,
254
+ explode,
255
+ name,
256
+ style,
257
+ value,
258
+ valueOnly
259
+ }) => {
260
+ if (value instanceof Date) {
261
+ return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
262
+ }
263
+ if (style !== "deepObject" && !explode) {
264
+ let values = [];
265
+ Object.entries(value).forEach(([key, v]) => {
266
+ values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
267
+ });
268
+ const joinedValues2 = values.join(",");
269
+ switch (style) {
270
+ case "form":
271
+ return `${name}=${joinedValues2}`;
272
+ case "label":
273
+ return `.${joinedValues2}`;
274
+ case "matrix":
275
+ return `;${name}=${joinedValues2}`;
276
+ default:
277
+ return joinedValues2;
278
+ }
279
+ }
280
+ const separator = separatorObjectExplode(style);
281
+ const joinedValues = Object.entries(value).map(
282
+ ([key, v]) => serializePrimitiveParam({
283
+ allowReserved,
284
+ name: style === "deepObject" ? `${name}[${key}]` : key,
285
+ value: v
286
+ })
287
+ ).join(separator);
288
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
289
+ };
290
+
291
+ // src/generated/core/utils.gen.ts
292
+ var PATH_PARAM_RE = /\{[^{}]+\}/g;
293
+ var defaultPathSerializer = ({ path, url: _url }) => {
294
+ let url = _url;
295
+ const matches = _url.match(PATH_PARAM_RE);
296
+ if (matches) {
297
+ for (const match of matches) {
298
+ let explode = false;
299
+ let name = match.substring(1, match.length - 1);
300
+ let style = "simple";
301
+ if (name.endsWith("*")) {
302
+ explode = true;
303
+ name = name.substring(0, name.length - 1);
304
+ }
305
+ if (name.startsWith(".")) {
306
+ name = name.substring(1);
307
+ style = "label";
308
+ } else if (name.startsWith(";")) {
309
+ name = name.substring(1);
310
+ style = "matrix";
311
+ }
312
+ const value = path[name];
313
+ if (value === void 0 || value === null) {
314
+ continue;
315
+ }
316
+ if (Array.isArray(value)) {
317
+ url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
318
+ continue;
319
+ }
320
+ if (typeof value === "object") {
321
+ url = url.replace(
322
+ match,
323
+ serializeObjectParam({
324
+ explode,
325
+ name,
326
+ style,
327
+ value,
328
+ valueOnly: true
329
+ })
330
+ );
331
+ continue;
332
+ }
333
+ if (style === "matrix") {
334
+ url = url.replace(
335
+ match,
336
+ `;${serializePrimitiveParam({
337
+ name,
338
+ value
339
+ })}`
340
+ );
341
+ continue;
342
+ }
343
+ const replaceValue = encodeURIComponent(
344
+ style === "label" ? `.${value}` : value
345
+ );
346
+ url = url.replace(match, replaceValue);
347
+ }
348
+ }
349
+ return url;
350
+ };
351
+ var getUrl = ({
352
+ baseUrl,
353
+ path,
354
+ query,
355
+ querySerializer,
356
+ url: _url
357
+ }) => {
358
+ const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
359
+ let url = (baseUrl ?? "") + pathUrl;
360
+ if (path) {
361
+ url = defaultPathSerializer({ path, url });
362
+ }
363
+ let search = query ? querySerializer(query) : "";
364
+ if (search.startsWith("?")) {
365
+ search = search.substring(1);
366
+ }
367
+ if (search) {
368
+ url += `?${search}`;
369
+ }
370
+ return url;
371
+ };
372
+ function getValidRequestBody(options) {
373
+ const hasBody = options.body !== void 0;
374
+ const isSerializedBody = hasBody && options.bodySerializer;
375
+ if (isSerializedBody) {
376
+ if ("serializedBody" in options) {
377
+ const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
378
+ return hasSerializedBody ? options.serializedBody : null;
379
+ }
380
+ return options.body !== "" ? options.body : null;
381
+ }
382
+ if (hasBody) {
383
+ return options.body;
384
+ }
385
+ return void 0;
386
+ }
387
+
388
+ // src/generated/core/auth.gen.ts
389
+ var getAuthToken = async (auth, callback) => {
390
+ const token = typeof callback === "function" ? await callback(auth) : callback;
391
+ if (!token) {
392
+ return;
393
+ }
394
+ if (auth.scheme === "bearer") {
395
+ return `Bearer ${token}`;
396
+ }
397
+ if (auth.scheme === "basic") {
398
+ return `Basic ${btoa(token)}`;
399
+ }
400
+ return token;
401
+ };
402
+
403
+ // src/generated/client/utils.gen.ts
404
+ var createQuerySerializer = ({
405
+ parameters = {},
406
+ ...args
407
+ } = {}) => {
408
+ const querySerializer = (queryParams) => {
409
+ const search = [];
410
+ if (queryParams && typeof queryParams === "object") {
411
+ for (const name in queryParams) {
412
+ const value = queryParams[name];
413
+ if (value === void 0 || value === null) {
414
+ continue;
415
+ }
416
+ const options = parameters[name] || args;
417
+ if (Array.isArray(value)) {
418
+ const serializedArray = serializeArrayParam({
419
+ allowReserved: options.allowReserved,
420
+ explode: true,
421
+ name,
422
+ style: "form",
423
+ value,
424
+ ...options.array
425
+ });
426
+ if (serializedArray) search.push(serializedArray);
427
+ } else if (typeof value === "object") {
428
+ const serializedObject = serializeObjectParam({
429
+ allowReserved: options.allowReserved,
430
+ explode: true,
431
+ name,
432
+ style: "deepObject",
433
+ value,
434
+ ...options.object
435
+ });
436
+ if (serializedObject) search.push(serializedObject);
437
+ } else {
438
+ const serializedPrimitive = serializePrimitiveParam({
439
+ allowReserved: options.allowReserved,
440
+ name,
441
+ value
442
+ });
443
+ if (serializedPrimitive) search.push(serializedPrimitive);
444
+ }
445
+ }
446
+ }
447
+ return search.join("&");
448
+ };
449
+ return querySerializer;
450
+ };
451
+ var getParseAs = (contentType) => {
452
+ if (!contentType) {
453
+ return "stream";
454
+ }
455
+ const cleanContent = contentType.split(";")[0]?.trim();
456
+ if (!cleanContent) {
457
+ return;
458
+ }
459
+ if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
460
+ return "json";
461
+ }
462
+ if (cleanContent === "multipart/form-data") {
463
+ return "formData";
464
+ }
465
+ if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
466
+ return "blob";
467
+ }
468
+ if (cleanContent.startsWith("text/")) {
469
+ return "text";
470
+ }
471
+ return;
472
+ };
473
+ var checkForExistence = (options, name) => {
474
+ if (!name) {
475
+ return false;
476
+ }
477
+ if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
478
+ return true;
479
+ }
480
+ return false;
481
+ };
482
+ async function setAuthParams(options) {
483
+ for (const auth of options.security ?? []) {
484
+ if (checkForExistence(options, auth.name)) {
485
+ continue;
486
+ }
487
+ const token = await getAuthToken(auth, options.auth);
488
+ if (!token) {
489
+ continue;
490
+ }
491
+ const name = auth.name ?? "Authorization";
492
+ switch (auth.in) {
493
+ case "query":
494
+ if (!options.query) {
495
+ options.query = {};
496
+ }
497
+ options.query[name] = token;
498
+ break;
499
+ case "cookie":
500
+ options.headers.append("Cookie", `${name}=${token}`);
501
+ break;
502
+ case "header":
503
+ default:
504
+ options.headers.set(name, token);
505
+ break;
506
+ }
507
+ }
508
+ }
509
+ var buildUrl = (options) => getUrl({
510
+ baseUrl: options.baseUrl,
511
+ path: options.path,
512
+ query: options.query,
513
+ querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
514
+ url: options.url
515
+ });
516
+ var mergeConfigs = (a, b) => {
517
+ const config = { ...a, ...b };
518
+ if (config.baseUrl?.endsWith("/")) {
519
+ config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
520
+ }
521
+ config.headers = mergeHeaders(a.headers, b.headers);
522
+ return config;
523
+ };
524
+ var headersEntries = (headers) => {
525
+ const entries = [];
526
+ headers.forEach((value, key) => {
527
+ entries.push([key, value]);
528
+ });
529
+ return entries;
530
+ };
531
+ var mergeHeaders = (...headers) => {
532
+ const mergedHeaders = new Headers();
533
+ for (const header of headers) {
534
+ if (!header) {
535
+ continue;
536
+ }
537
+ const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
538
+ for (const [key, value] of iterator) {
539
+ if (value === null) {
540
+ mergedHeaders.delete(key);
541
+ } else if (Array.isArray(value)) {
542
+ for (const v of value) {
543
+ mergedHeaders.append(key, v);
544
+ }
545
+ } else if (value !== void 0) {
546
+ mergedHeaders.set(
547
+ key,
548
+ typeof value === "object" ? JSON.stringify(value) : value
549
+ );
550
+ }
551
+ }
552
+ }
553
+ return mergedHeaders;
554
+ };
555
+ var Interceptors = class {
556
+ fns = [];
557
+ clear() {
558
+ this.fns = [];
559
+ }
560
+ eject(id) {
561
+ const index = this.getInterceptorIndex(id);
562
+ if (this.fns[index]) {
563
+ this.fns[index] = null;
564
+ }
565
+ }
566
+ exists(id) {
567
+ const index = this.getInterceptorIndex(id);
568
+ return Boolean(this.fns[index]);
569
+ }
570
+ getInterceptorIndex(id) {
571
+ if (typeof id === "number") {
572
+ return this.fns[id] ? id : -1;
573
+ }
574
+ return this.fns.indexOf(id);
575
+ }
576
+ update(id, fn) {
577
+ const index = this.getInterceptorIndex(id);
578
+ if (this.fns[index]) {
579
+ this.fns[index] = fn;
580
+ return id;
581
+ }
582
+ return false;
583
+ }
584
+ use(fn) {
585
+ this.fns.push(fn);
586
+ return this.fns.length - 1;
587
+ }
588
+ };
589
+ var createInterceptors = () => ({
590
+ error: new Interceptors(),
591
+ request: new Interceptors(),
592
+ response: new Interceptors()
593
+ });
594
+ var defaultQuerySerializer = createQuerySerializer({
595
+ allowReserved: false,
596
+ array: {
597
+ explode: true,
598
+ style: "form"
599
+ },
600
+ object: {
601
+ explode: true,
602
+ style: "deepObject"
603
+ }
604
+ });
605
+ var defaultHeaders = {
606
+ "Content-Type": "application/json"
607
+ };
608
+ var createConfig = (override = {}) => ({
609
+ ...jsonBodySerializer,
610
+ headers: defaultHeaders,
611
+ parseAs: "auto",
612
+ querySerializer: defaultQuerySerializer,
613
+ ...override
614
+ });
615
+
616
+ // src/generated/client/client.gen.ts
617
+ var createClient = (config = {}) => {
618
+ let _config = mergeConfigs(createConfig(), config);
619
+ const getConfig = () => ({ ..._config });
620
+ const setConfig = (config2) => {
621
+ _config = mergeConfigs(_config, config2);
622
+ return getConfig();
623
+ };
624
+ const interceptors = createInterceptors();
625
+ const beforeRequest = async (options) => {
626
+ const opts = {
627
+ ..._config,
628
+ ...options,
629
+ fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
630
+ headers: mergeHeaders(_config.headers, options.headers),
631
+ serializedBody: void 0
632
+ };
633
+ if (opts.security) {
634
+ await setAuthParams(opts);
635
+ }
636
+ if (opts.requestValidator) {
637
+ await opts.requestValidator(opts);
638
+ }
639
+ if (opts.body !== void 0 && opts.bodySerializer) {
640
+ opts.serializedBody = opts.bodySerializer(opts.body);
641
+ }
642
+ if (opts.body === void 0 || opts.serializedBody === "") {
643
+ opts.headers.delete("Content-Type");
644
+ }
645
+ const resolvedOpts = opts;
646
+ const url = buildUrl(resolvedOpts);
647
+ return { opts: resolvedOpts, url };
648
+ };
649
+ const request = async (options) => {
650
+ const throwOnError = options.throwOnError ?? _config.throwOnError;
651
+ const responseStyle = options.responseStyle ?? _config.responseStyle;
652
+ let request2;
653
+ let response;
654
+ try {
655
+ const { opts, url } = await beforeRequest(options);
656
+ const requestInit = {
657
+ redirect: "follow",
658
+ ...opts,
659
+ body: getValidRequestBody(opts)
660
+ };
661
+ request2 = new Request(url, requestInit);
662
+ for (const fn of interceptors.request.fns) {
663
+ if (fn) {
664
+ request2 = await fn(request2, opts);
665
+ }
666
+ }
667
+ const _fetch = opts.fetch;
668
+ response = await _fetch(request2);
669
+ for (const fn of interceptors.response.fns) {
670
+ if (fn) {
671
+ response = await fn(response, request2, opts);
672
+ }
673
+ }
674
+ const result = {
675
+ request: request2,
676
+ response
677
+ };
678
+ if (response.ok) {
679
+ const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
680
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
681
+ let emptyData;
682
+ switch (parseAs) {
683
+ case "arrayBuffer":
684
+ case "blob":
685
+ case "text":
686
+ emptyData = await response[parseAs]();
687
+ break;
688
+ case "formData":
689
+ emptyData = new FormData();
690
+ break;
691
+ case "stream":
692
+ emptyData = response.body;
693
+ break;
694
+ case "json":
695
+ default:
696
+ emptyData = {};
697
+ break;
698
+ }
699
+ return opts.responseStyle === "data" ? emptyData : {
700
+ data: emptyData,
701
+ ...result
702
+ };
703
+ }
704
+ let data;
705
+ switch (parseAs) {
706
+ case "arrayBuffer":
707
+ case "blob":
708
+ case "formData":
709
+ case "text":
710
+ data = await response[parseAs]();
711
+ break;
712
+ case "json": {
713
+ const text = await response.text();
714
+ data = text ? JSON.parse(text) : {};
715
+ break;
716
+ }
717
+ case "stream":
718
+ return opts.responseStyle === "data" ? response.body : {
719
+ data: response.body,
720
+ ...result
721
+ };
722
+ }
723
+ if (parseAs === "json") {
724
+ if (opts.responseValidator) {
725
+ await opts.responseValidator(data);
726
+ }
727
+ if (opts.responseTransformer) {
728
+ data = await opts.responseTransformer(data);
729
+ }
730
+ }
731
+ return opts.responseStyle === "data" ? data : {
732
+ data,
733
+ ...result
734
+ };
735
+ }
736
+ const textError = await response.text();
737
+ let jsonError;
738
+ try {
739
+ jsonError = JSON.parse(textError);
740
+ } catch {
741
+ }
742
+ throw jsonError ?? textError;
743
+ } catch (error) {
744
+ let finalError = error;
745
+ for (const fn of interceptors.error.fns) {
746
+ if (fn) {
747
+ finalError = await fn(finalError, response, request2, options);
748
+ }
749
+ }
750
+ finalError = finalError || {};
751
+ if (throwOnError) {
752
+ throw finalError;
753
+ }
754
+ return responseStyle === "data" ? void 0 : {
755
+ error: finalError,
756
+ request: request2,
757
+ response
758
+ };
759
+ }
760
+ };
761
+ const makeMethodFn = (method) => (options) => request({ ...options, method });
762
+ const makeSseFn = (method) => async (options) => {
763
+ const { opts, url } = await beforeRequest(options);
764
+ return createSseClient({
765
+ ...opts,
766
+ body: opts.body,
767
+ method,
768
+ onRequest: async (url2, init) => {
769
+ let request2 = new Request(url2, init);
770
+ for (const fn of interceptors.request.fns) {
771
+ if (fn) {
772
+ request2 = await fn(request2, opts);
773
+ }
774
+ }
775
+ return request2;
776
+ },
777
+ serializedBody: getValidRequestBody(opts),
778
+ url
779
+ });
780
+ };
781
+ const _buildUrl = (options) => buildUrl({ ..._config, ...options });
782
+ return {
783
+ buildUrl: _buildUrl,
784
+ connect: makeMethodFn("CONNECT"),
785
+ delete: makeMethodFn("DELETE"),
786
+ get: makeMethodFn("GET"),
787
+ getConfig,
788
+ head: makeMethodFn("HEAD"),
789
+ interceptors,
790
+ options: makeMethodFn("OPTIONS"),
791
+ patch: makeMethodFn("PATCH"),
792
+ post: makeMethodFn("POST"),
793
+ put: makeMethodFn("PUT"),
794
+ request,
795
+ setConfig,
796
+ sse: {
797
+ connect: makeSseFn("CONNECT"),
798
+ delete: makeSseFn("DELETE"),
799
+ get: makeSseFn("GET"),
800
+ head: makeSseFn("HEAD"),
801
+ options: makeSseFn("OPTIONS"),
802
+ patch: makeSseFn("PATCH"),
803
+ post: makeSseFn("POST"),
804
+ put: makeSseFn("PUT"),
805
+ trace: makeSseFn("TRACE")
806
+ },
807
+ trace: makeMethodFn("TRACE")
808
+ };
809
+ };
810
+
811
+ // src/generated/client.gen.ts
812
+ var client = createClient(createConfig({ baseUrl: "https://app.usenadia.com/api" }));
813
+
814
+ // src/generated/sdk.gen.ts
815
+ var uploadFile = (options) => (options.client ?? client).post({
816
+ ...formDataBodySerializer,
817
+ security: [{ name: "Authorization", type: "apiKey" }],
818
+ url: "/public/v1/upload",
819
+ ...options,
820
+ headers: {
821
+ "Content-Type": null,
822
+ ...options.headers
823
+ }
824
+ });
825
+ var uploadFromUrl = (options) => (options.client ?? client).post({
826
+ security: [{ name: "Authorization", type: "apiKey" }],
827
+ url: "/public/v1/upload-from-url",
828
+ ...options,
829
+ headers: {
830
+ "Content-Type": "application/json",
831
+ ...options.headers
832
+ }
833
+ });
834
+ var findSlot = (options) => (options.client ?? client).get({
835
+ security: [{ name: "Authorization", type: "apiKey" }],
836
+ url: "/public/v1/find-slot/{id}",
837
+ ...options
838
+ });
839
+ var listPosts = (options) => (options.client ?? client).get({
840
+ security: [{ name: "Authorization", type: "apiKey" }],
841
+ url: "/public/v1/posts",
842
+ ...options
843
+ });
844
+ var createPost = (options) => (options.client ?? client).post({
845
+ security: [{ name: "Authorization", type: "apiKey" }],
846
+ url: "/public/v1/posts",
847
+ ...options,
848
+ headers: {
849
+ "Content-Type": "application/json",
850
+ ...options.headers
851
+ }
852
+ });
853
+ var deletePost = (options) => (options.client ?? client).delete({
854
+ security: [{ name: "Authorization", type: "apiKey" }],
855
+ url: "/public/v1/posts/{id}",
856
+ ...options
857
+ });
858
+ var deletePostGroup = (options) => (options.client ?? client).delete({
859
+ security: [{ name: "Authorization", type: "apiKey" }],
860
+ url: "/public/v1/posts/group/{group}",
861
+ ...options
862
+ });
863
+ var checkConnection = (options) => (options?.client ?? client).get({
864
+ security: [{ name: "Authorization", type: "apiKey" }],
865
+ url: "/public/v1/is-connected",
866
+ ...options
867
+ });
868
+ var listGroups = (options) => (options?.client ?? client).get({
869
+ security: [{ name: "Authorization", type: "apiKey" }],
870
+ url: "/public/v1/groups",
871
+ ...options
872
+ });
873
+ var listChannels = (options) => (options?.client ?? client).get({
874
+ security: [{ name: "Authorization", type: "apiKey" }],
875
+ url: "/public/v1/integrations",
876
+ ...options
877
+ });
878
+ var startChannelConnection = (options) => (options.client ?? client).get({
879
+ security: [{ name: "Authorization", type: "apiKey" }],
880
+ url: "/public/v1/social/{integration}",
881
+ ...options
882
+ });
883
+ var listNotifications = (options) => (options?.client ?? client).get({
884
+ security: [{ name: "Authorization", type: "apiKey" }],
885
+ url: "/public/v1/notifications",
886
+ ...options
887
+ });
888
+ var generateVideo = (options) => (options.client ?? client).post({
889
+ security: [{ name: "Authorization", type: "apiKey" }],
890
+ url: "/public/v1/generate-video",
891
+ ...options,
892
+ headers: {
893
+ "Content-Type": "application/json",
894
+ ...options.headers
895
+ }
896
+ });
897
+ var callVideoFunction = (options) => (options.client ?? client).post({
898
+ security: [{ name: "Authorization", type: "apiKey" }],
899
+ url: "/public/v1/video/function",
900
+ ...options,
901
+ headers: {
902
+ "Content-Type": "application/json",
903
+ ...options.headers
904
+ }
905
+ });
906
+ var deleteChannel = (options) => (options.client ?? client).delete({
907
+ security: [{ name: "Authorization", type: "apiKey" }],
908
+ url: "/public/v1/integrations/{id}",
909
+ ...options
910
+ });
911
+ var getChannelSettings = (options) => (options.client ?? client).get({
912
+ security: [{ name: "Authorization", type: "apiKey" }],
913
+ url: "/public/v1/integration-settings/{id}",
914
+ ...options
915
+ });
916
+ var listMissingMedia = (options) => (options.client ?? client).get({
917
+ security: [{ name: "Authorization", type: "apiKey" }],
918
+ url: "/public/v1/posts/{id}/missing",
919
+ ...options
920
+ });
921
+ var changePostStatus = (options) => (options.client ?? client).put({
922
+ security: [{ name: "Authorization", type: "apiKey" }],
923
+ url: "/public/v1/posts/{id}/status",
924
+ ...options,
925
+ headers: {
926
+ "Content-Type": "application/json",
927
+ ...options.headers
928
+ }
929
+ });
930
+ var setPostReleaseId = (options) => (options.client ?? client).put({
931
+ security: [{ name: "Authorization", type: "apiKey" }],
932
+ url: "/public/v1/posts/{id}/release-id",
933
+ ...options,
934
+ headers: {
935
+ "Content-Type": "application/json",
936
+ ...options.headers
937
+ }
938
+ });
939
+ var getChannelAnalytics = (options) => (options.client ?? client).get({
940
+ security: [{ name: "Authorization", type: "apiKey" }],
941
+ url: "/public/v1/analytics/{integration}",
942
+ ...options
943
+ });
944
+ var listVideoPerformance = (options) => (options.client ?? client).get({
945
+ security: [{ name: "Authorization", type: "apiKey" }],
946
+ url: "/public/v1/video-list/{integrationId}",
947
+ ...options
948
+ });
949
+ var getAccountHistory = (options) => (options.client ?? client).get({
950
+ security: [{ name: "Authorization", type: "apiKey" }],
951
+ url: "/public/v1/analytics-history/{integrationId}",
952
+ ...options
953
+ });
954
+ var getVideoHistory = (options) => (options.client ?? client).get({
955
+ security: [{ name: "Authorization", type: "apiKey" }],
956
+ url: "/public/v1/video-history/{integrationId}",
957
+ ...options
958
+ });
959
+ var getPostAnalytics = (options) => (options.client ?? client).get({
960
+ security: [{ name: "Authorization", type: "apiKey" }],
961
+ url: "/public/v1/analytics/post/{postId}",
962
+ ...options
963
+ });
964
+ var runChannelTool = (options) => (options.client ?? client).post({
965
+ security: [{ name: "Authorization", type: "apiKey" }],
966
+ url: "/public/v1/integration-trigger/{id}",
967
+ ...options,
968
+ headers: {
969
+ "Content-Type": "application/json",
970
+ ...options.headers
971
+ }
972
+ });
973
+ var listChannelMedia = (options) => (options.client ?? client).get({
974
+ security: [{ name: "Authorization", type: "apiKey" }],
975
+ url: "/public/v1/inbox/media/{integrationId}",
976
+ ...options
977
+ });
978
+ var listChannelStories = (options) => (options.client ?? client).get({
979
+ security: [{ name: "Authorization", type: "apiKey" }],
980
+ url: "/public/v1/inbox/stories/{integrationId}",
981
+ ...options
982
+ });
983
+ var listMediaComments = (options) => (options.client ?? client).get({
984
+ security: [{ name: "Authorization", type: "apiKey" }],
985
+ url: "/public/v1/inbox/comments/{integrationId}/{mediaId}",
986
+ ...options
987
+ });
988
+ var replyToComment = (options) => (options.client ?? client).post({
989
+ security: [{ name: "Authorization", type: "apiKey" }],
990
+ url: "/public/v1/inbox/comments/{commentId}/reply",
991
+ ...options,
992
+ headers: {
993
+ "Content-Type": "application/json",
994
+ ...options.headers
995
+ }
996
+ });
997
+ var hideComment = (options) => (options.client ?? client).post({
998
+ security: [{ name: "Authorization", type: "apiKey" }],
999
+ url: "/public/v1/inbox/comments/{integrationId}/{commentId}/hide",
1000
+ ...options,
1001
+ headers: {
1002
+ "Content-Type": "application/json",
1003
+ ...options.headers
1004
+ }
1005
+ });
1006
+ var deleteComment = (options) => (options.client ?? client).delete({
1007
+ security: [{ name: "Authorization", type: "apiKey" }],
1008
+ url: "/public/v1/inbox/comments/{integrationId}/{commentId}",
1009
+ ...options
1010
+ });
1011
+ var listConversations = (options) => (options.client ?? client).get({
1012
+ security: [{ name: "Authorization", type: "apiKey" }],
1013
+ url: "/public/v1/inbox/{integrationId}",
1014
+ ...options
1015
+ });
1016
+ var sendDirectMessage = (options) => (options.client ?? client).post({
1017
+ security: [{ name: "Authorization", type: "apiKey" }],
1018
+ url: "/public/v1/inbox/{integrationId}/send",
1019
+ ...options,
1020
+ headers: {
1021
+ "Content-Type": "application/json",
1022
+ ...options.headers
1023
+ }
1024
+ });
1025
+ var pollInbox = (options) => (options.client ?? client).post({
1026
+ security: [{ name: "Authorization", type: "apiKey" }],
1027
+ url: "/public/v1/inbox/{integrationId}/poll",
1028
+ ...options
1029
+ });
1030
+ var subscribeInboxWebhook = (options) => (options.client ?? client).post({
1031
+ security: [{ name: "Authorization", type: "apiKey" }],
1032
+ url: "/public/v1/inbox/{integrationId}/subscribe-webhook",
1033
+ ...options
1034
+ });
1035
+ var getConversation = (options) => (options.client ?? client).get({
1036
+ security: [{ name: "Authorization", type: "apiKey" }],
1037
+ url: "/public/v1/inbox/{integrationId}/{conversationId}",
1038
+ ...options
1039
+ });
1040
+ var listAutomationFlows = (options) => (options?.client ?? client).get({
1041
+ security: [{ name: "Authorization", type: "apiKey" }],
1042
+ url: "/public/v1/automation-flows",
1043
+ ...options
1044
+ });
1045
+ var createAutomationFlow = (options) => (options.client ?? client).post({
1046
+ security: [{ name: "Authorization", type: "apiKey" }],
1047
+ url: "/public/v1/automation-flows",
1048
+ ...options,
1049
+ headers: {
1050
+ "Content-Type": "application/json",
1051
+ ...options.headers
1052
+ }
1053
+ });
1054
+ var previewAutomationEmail = (options) => (options.client ?? client).post({
1055
+ security: [{ name: "Authorization", type: "apiKey" }],
1056
+ url: "/public/v1/automation-flows/email-preview",
1057
+ ...options,
1058
+ headers: {
1059
+ "Content-Type": "application/json",
1060
+ ...options.headers
1061
+ }
1062
+ });
1063
+ var sendAutomationTestEmail = (options) => (options.client ?? client).post({
1064
+ security: [{ name: "Authorization", type: "apiKey" }],
1065
+ url: "/public/v1/automation-flows/email-test",
1066
+ ...options,
1067
+ headers: {
1068
+ "Content-Type": "application/json",
1069
+ ...options.headers
1070
+ }
1071
+ });
1072
+ var deleteAutomationFlow = (options) => (options.client ?? client).delete({
1073
+ security: [{ name: "Authorization", type: "apiKey" }],
1074
+ url: "/public/v1/automation-flows/{id}",
1075
+ ...options
1076
+ });
1077
+ var getAutomationFlow = (options) => (options.client ?? client).get({
1078
+ security: [{ name: "Authorization", type: "apiKey" }],
1079
+ url: "/public/v1/automation-flows/{id}",
1080
+ ...options
1081
+ });
1082
+ var updateAutomationFlow = (options) => (options.client ?? client).put({
1083
+ security: [{ name: "Authorization", type: "apiKey" }],
1084
+ url: "/public/v1/automation-flows/{id}",
1085
+ ...options,
1086
+ headers: {
1087
+ "Content-Type": "application/json",
1088
+ ...options.headers
1089
+ }
1090
+ });
1091
+ var setAutomationFlowStatus = (options) => (options.client ?? client).put({
1092
+ security: [{ name: "Authorization", type: "apiKey" }],
1093
+ url: "/public/v1/automation-flows/{id}/status",
1094
+ ...options,
1095
+ headers: {
1096
+ "Content-Type": "application/json",
1097
+ ...options.headers
1098
+ }
1099
+ });
1100
+ var listAutomationFlowPoses = (options) => (options.client ?? client).get({
1101
+ security: [{ name: "Authorization", type: "apiKey" }],
1102
+ url: "/public/v1/automation-flows/{id}/poses",
1103
+ ...options
1104
+ });
1105
+ var poseAutomationFlow = (options) => (options.client ?? client).post({
1106
+ security: [{ name: "Authorization", type: "apiKey" }],
1107
+ url: "/public/v1/automation-flows/{id}/poses",
1108
+ ...options,
1109
+ headers: {
1110
+ "Content-Type": "application/json",
1111
+ ...options.headers
1112
+ }
1113
+ });
1114
+ var listChannelAutomationPoses = (options) => (options.client ?? client).get({
1115
+ security: [{ name: "Authorization", type: "apiKey" }],
1116
+ url: "/public/v1/automation-flow-poses",
1117
+ ...options
1118
+ });
1119
+ var deleteAutomationPose = (options) => (options.client ?? client).delete({
1120
+ security: [{ name: "Authorization", type: "apiKey" }],
1121
+ url: "/public/v1/automation-flow-poses/{id}",
1122
+ ...options
1123
+ });
1124
+ var getAutomationPose = (options) => (options.client ?? client).get({
1125
+ security: [{ name: "Authorization", type: "apiKey" }],
1126
+ url: "/public/v1/automation-flow-poses/{id}",
1127
+ ...options
1128
+ });
1129
+ var updateAutomationPose = (options) => (options.client ?? client).put({
1130
+ security: [{ name: "Authorization", type: "apiKey" }],
1131
+ url: "/public/v1/automation-flow-poses/{id}",
1132
+ ...options,
1133
+ headers: {
1134
+ "Content-Type": "application/json",
1135
+ ...options.headers
1136
+ }
1137
+ });
1138
+ var listAutomationPoseRuns = (options) => (options.client ?? client).get({
1139
+ security: [{ name: "Authorization", type: "apiKey" }],
1140
+ url: "/public/v1/automation-flow-poses/{id}/runs",
1141
+ ...options
1142
+ });
1143
+ var pollAutomationPose = (options) => (options.client ?? client).post({
1144
+ security: [{ name: "Authorization", type: "apiKey" }],
1145
+ url: "/public/v1/automation-flow-poses/{id}/poll",
1146
+ ...options
1147
+ });
1148
+ var replayAutomationPose = (options) => (options.client ?? client).post({
1149
+ security: [{ name: "Authorization", type: "apiKey" }],
1150
+ url: "/public/v1/automation-flow-poses/{id}/replay",
1151
+ ...options,
1152
+ headers: {
1153
+ "Content-Type": "application/json",
1154
+ ...options.headers
1155
+ }
1156
+ });
1157
+ var listWebhookEvents = (options) => (options?.client ?? client).get({
1158
+ security: [{ name: "Authorization", type: "apiKey" }],
1159
+ url: "/public/v1/webhooks/events",
1160
+ ...options
1161
+ });
1162
+ var listWebhooks = (options) => (options?.client ?? client).get({
1163
+ security: [{ name: "Authorization", type: "apiKey" }],
1164
+ url: "/public/v1/webhooks",
1165
+ ...options
1166
+ });
1167
+ var createWebhook = (options) => (options.client ?? client).post({
1168
+ security: [{ name: "Authorization", type: "apiKey" }],
1169
+ url: "/public/v1/webhooks",
1170
+ ...options,
1171
+ headers: {
1172
+ "Content-Type": "application/json",
1173
+ ...options.headers
1174
+ }
1175
+ });
1176
+ var deleteWebhook = (options) => (options.client ?? client).delete({
1177
+ security: [{ name: "Authorization", type: "apiKey" }],
1178
+ url: "/public/v1/webhooks/{id}",
1179
+ ...options
1180
+ });
1181
+ var getWebhook = (options) => (options.client ?? client).get({
1182
+ security: [{ name: "Authorization", type: "apiKey" }],
1183
+ url: "/public/v1/webhooks/{id}",
1184
+ ...options
1185
+ });
1186
+ var listContents = (options) => (options?.client ?? client).get({
1187
+ security: [{ name: "Authorization", type: "apiKey" }],
1188
+ url: "/public/v1/contents",
1189
+ ...options
1190
+ });
1191
+ var createContent = (options) => (options.client ?? client).post({
1192
+ security: [{ name: "Authorization", type: "apiKey" }],
1193
+ url: "/public/v1/contents",
1194
+ ...options,
1195
+ headers: {
1196
+ "Content-Type": "application/json",
1197
+ ...options.headers
1198
+ }
1199
+ });
1200
+ var getContentsPerformance = (options) => (options?.client ?? client).get({
1201
+ security: [{ name: "Authorization", type: "apiKey" }],
1202
+ url: "/public/v1/contents/performance",
1203
+ ...options
1204
+ });
1205
+ var deleteContent = (options) => (options.client ?? client).delete({
1206
+ security: [{ name: "Authorization", type: "apiKey" }],
1207
+ url: "/public/v1/contents/{id}",
1208
+ ...options
1209
+ });
1210
+ var getContent = (options) => (options.client ?? client).get({
1211
+ security: [{ name: "Authorization", type: "apiKey" }],
1212
+ url: "/public/v1/contents/{id}",
1213
+ ...options
1214
+ });
1215
+ var updateContent = (options) => (options.client ?? client).put({
1216
+ security: [{ name: "Authorization", type: "apiKey" }],
1217
+ url: "/public/v1/contents/{id}",
1218
+ ...options,
1219
+ headers: {
1220
+ "Content-Type": "application/json",
1221
+ ...options.headers
1222
+ }
1223
+ });
1224
+ var upsertContent = (options) => (options.client ?? client).post({
1225
+ security: [{ name: "Authorization", type: "apiKey" }],
1226
+ url: "/public/v1/contents/upsert",
1227
+ ...options,
1228
+ headers: {
1229
+ "Content-Type": "application/json",
1230
+ ...options.headers
1231
+ }
1232
+ });
1233
+ var moveContent = (options) => (options.client ?? client).put({
1234
+ security: [{ name: "Authorization", type: "apiKey" }],
1235
+ url: "/public/v1/contents/{id}/move",
1236
+ ...options,
1237
+ headers: {
1238
+ "Content-Type": "application/json",
1239
+ ...options.headers
1240
+ }
1241
+ });
1242
+ var linkContentPost = (options) => (options.client ?? client).put({
1243
+ security: [{ name: "Authorization", type: "apiKey" }],
1244
+ url: "/public/v1/contents/{id}/post",
1245
+ ...options,
1246
+ headers: {
1247
+ "Content-Type": "application/json",
1248
+ ...options.headers
1249
+ }
1250
+ });
1251
+ var searchHooks = (options) => (options?.client ?? client).get({
1252
+ security: [{ name: "Authorization", type: "apiKey" }],
1253
+ url: "/public/v1/hooks",
1254
+ ...options
1255
+ });
1256
+ var getHookForms = (options) => (options?.client ?? client).get({
1257
+ security: [{ name: "Authorization", type: "apiKey" }],
1258
+ url: "/public/v1/hooks/forms",
1259
+ ...options
1260
+ });
1261
+ var listHookFamilies = (options) => (options?.client ?? client).get({
1262
+ security: [{ name: "Authorization", type: "apiKey" }],
1263
+ url: "/public/v1/hooks/families",
1264
+ ...options
1265
+ });
1266
+ var replaceHookFamilies = (options) => (options.client ?? client).put({
1267
+ security: [{ name: "Authorization", type: "apiKey" }],
1268
+ url: "/public/v1/hooks/families",
1269
+ ...options,
1270
+ headers: {
1271
+ "Content-Type": "application/json",
1272
+ ...options.headers
1273
+ }
1274
+ });
1275
+ var importHooks = (options) => (options.client ?? client).post({
1276
+ security: [{ name: "Authorization", type: "apiKey" }],
1277
+ url: "/public/v1/hooks/import",
1278
+ ...options,
1279
+ headers: {
1280
+ "Content-Type": "application/json",
1281
+ ...options.headers
1282
+ }
1283
+ });
1284
+ var listMusic = (options) => (options?.client ?? client).get({
1285
+ security: [{ name: "Authorization", type: "apiKey" }],
1286
+ url: "/public/v1/music",
1287
+ ...options
1288
+ });
1289
+ var listMusicPillars = (options) => (options?.client ?? client).get({
1290
+ security: [{ name: "Authorization", type: "apiKey" }],
1291
+ url: "/public/v1/music/pillars",
1292
+ ...options
1293
+ });
1294
+ var getMusicTrack = (options) => (options.client ?? client).get({
1295
+ security: [{ name: "Authorization", type: "apiKey" }],
1296
+ url: "/public/v1/music/{slug}",
1297
+ ...options
1298
+ });
1299
+ var importMusic = (options) => (options.client ?? client).post({
1300
+ security: [{ name: "Authorization", type: "apiKey" }],
1301
+ url: "/public/v1/music/import",
1302
+ ...options,
1303
+ headers: {
1304
+ "Content-Type": "application/json",
1305
+ ...options.headers
1306
+ }
1307
+ });
1308
+ var uploadMusicFile = (options) => (options.client ?? client).put({
1309
+ ...formDataBodySerializer,
1310
+ security: [{ name: "Authorization", type: "apiKey" }],
1311
+ url: "/public/v1/music/{slug}/file",
1312
+ ...options,
1313
+ headers: {
1314
+ "Content-Type": null,
1315
+ ...options.headers
1316
+ }
1317
+ });
1318
+
1319
+ // src/index.ts
1320
+ var DEFAULT_BASE_URL = "https://app.usenadia.com/api";
1321
+ var NadiaError = class _NadiaError extends Error {
1322
+ status;
1323
+ body;
1324
+ constructor(status, body, message) {
1325
+ super(message ?? `UseNadia API responded ${status}`);
1326
+ this.name = "NadiaError";
1327
+ this.status = status;
1328
+ this.body = body;
1329
+ Object.setPrototypeOf(this, _NadiaError.prototype);
1330
+ }
1331
+ /**
1332
+ * True when retrying later could plausibly work: a rate limit, a server
1333
+ * hiccup, or a request that never completed at all (status 0).
1334
+ */
1335
+ get isTransient() {
1336
+ return this.status === 0 || this.status === 429 || this.status >= 500;
1337
+ }
1338
+ };
1339
+ var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
1340
+ var messageOf = (body) => {
1341
+ if (body && typeof body === "object" && "msg" in body) {
1342
+ const msg = body.msg;
1343
+ if (typeof msg === "string") return msg;
1344
+ }
1345
+ return void 0;
1346
+ };
1347
+ var Nadia = class {
1348
+ client;
1349
+ retries;
1350
+ constructor(apiKey, options = {}) {
1351
+ if (!apiKey) {
1352
+ throw new Error("An API key is required.");
1353
+ }
1354
+ const opts = typeof options === "string" ? { baseUrl: options } : options;
1355
+ this.retries = opts.retries ?? 2;
1356
+ this.client = client;
1357
+ this.client.setConfig({
1358
+ baseUrl: opts.baseUrl ?? DEFAULT_BASE_URL,
1359
+ headers: { Authorization: apiKey },
1360
+ ...opts.fetch ? { fetch: opts.fetch } : {}
1361
+ });
1362
+ }
1363
+ /**
1364
+ * Runs a generated operation, turns a non-2xx into a `NadiaError`, and
1365
+ * retries the transient ones. Every method below goes through here — that is
1366
+ * the whole point of the facade.
1367
+ */
1368
+ async call(operation) {
1369
+ let lastError;
1370
+ for (let attempt = 0; attempt <= this.retries; attempt++) {
1371
+ const { data, error, response } = await operation({ client: this.client });
1372
+ if (!response) {
1373
+ lastError = new NadiaError(0, error, "The request did not complete.");
1374
+ } else if (response.ok) {
1375
+ return data;
1376
+ } else {
1377
+ lastError = new NadiaError(response.status, error, messageOf(error));
1378
+ }
1379
+ if (!lastError.isTransient || attempt === this.retries) {
1380
+ throw lastError;
1381
+ }
1382
+ await sleep(2 ** attempt * 500);
1383
+ }
1384
+ throw lastError;
1385
+ }
1386
+ /* --------------------------------------------------------------- *
1387
+ * The five calls upstream had, same names, same shape
1388
+ * --------------------------------------------------------------- */
1389
+ /** Schedule, publish or draft a post on one or more channels. */
1390
+ post(body) {
1391
+ return this.call(
1392
+ (o) => createPost({ ...o, body })
1393
+ );
1394
+ }
1395
+ /** List posts in a date range. */
1396
+ postList(query) {
1397
+ return this.call(
1398
+ (o) => listPosts({ ...o, query })
1399
+ );
1400
+ }
1401
+ /** Upload a file and get a URL usable in a post. */
1402
+ upload(file, filename = "upload") {
1403
+ const form = new FormData();
1404
+ form.append("file", file, filename);
1405
+ return this.call(
1406
+ (o) => uploadFile({
1407
+ ...o,
1408
+ body: form,
1409
+ bodySerializer: (body) => body
1410
+ })
1411
+ );
1412
+ }
1413
+ /** List your connected channels. */
1414
+ integrations() {
1415
+ return this.call((o) => listChannels(o));
1416
+ }
1417
+ /** Delete a post and everything published with it. */
1418
+ deletePost(id) {
1419
+ return this.call(
1420
+ (o) => deletePost({ ...o, path: { id } })
1421
+ );
1422
+ }
1423
+ /* --------------------------------------------------------------- *
1424
+ * The rest of our surface, which upstream never had
1425
+ * --------------------------------------------------------------- */
1426
+ /** Check that the API key is valid. Throws `NadiaError` with status 401 if not. */
1427
+ async isConnected() {
1428
+ await this.call((o) => checkConnection(o));
1429
+ return true;
1430
+ }
1431
+ /** Next free slot in a channel's schedule. */
1432
+ findSlot(integrationId) {
1433
+ return this.call(
1434
+ (o) => findSlot({
1435
+ ...o,
1436
+ path: { id: integrationId }
1437
+ })
1438
+ );
1439
+ }
1440
+ /** List your groups (brands). */
1441
+ groups() {
1442
+ return this.call((o) => listGroups(o));
1443
+ }
1444
+ /** Direct message conversations of a channel. */
1445
+ inbox(integrationId, limit) {
1446
+ return this.call(
1447
+ (o) => listConversations({
1448
+ ...o,
1449
+ path: { integrationId },
1450
+ query: limit ? { limit: String(limit) } : void 0
1451
+ })
1452
+ );
1453
+ }
1454
+ /* --------------------------------------------------------------- *
1455
+ * The content board: one card per video, from the idea to the
1456
+ * numbers after publication
1457
+ * --------------------------------------------------------------- */
1458
+ /**
1459
+ * The cards of the board, with the posts scheduled from each. Filters
1460
+ * combine: `stage`, `tag`, `externalId`; `fields` (`'id,title,stage'`)
1461
+ * leaves the scripts out.
1462
+ */
1463
+ contents(query) {
1464
+ return this.call((o) => listContents({ ...o, query }));
1465
+ }
1466
+ /** One card. */
1467
+ content(id) {
1468
+ return this.call((o) => getContent({ ...o, path: { id } }));
1469
+ }
1470
+ /** Create a card — in IDEA unless `stage` says otherwise. */
1471
+ createContent(body) {
1472
+ return this.call((o) => createContent({ ...o, body }));
1473
+ }
1474
+ /**
1475
+ * Create or update the card holding `externalId` (your own id: a script
1476
+ * file path, a build id). Re-running an import never duplicates; an
1477
+ * existing card keeps its column.
1478
+ */
1479
+ upsertContent(body) {
1480
+ return this.call((o) => upsertContent({ ...o, body }));
1481
+ }
1482
+ /** Update a card: only the fields sent change, `null` clears one. */
1483
+ updateContent(id, body) {
1484
+ return this.call((o) => updateContent({ ...o, path: { id }, body }));
1485
+ }
1486
+ /** Move a card to another column (to the bottom unless `position` is given). */
1487
+ moveContent(id, stage, position) {
1488
+ return this.call(
1489
+ (o) => moveContent({
1490
+ ...o,
1491
+ path: { id },
1492
+ body: position === void 0 ? { stage } : { stage, position }
1493
+ })
1494
+ );
1495
+ }
1496
+ /**
1497
+ * Tie a card to a post scheduled from it — the `group` passed on
1498
+ * {@link Nadia.post}. A card holds several posts (a TikTok draft, an
1499
+ * Instagram post): each call adds one. The card moves to PUBLISHED when
1500
+ * the first of them goes live.
1501
+ */
1502
+ linkContentPost(id, postGroup) {
1503
+ return this.call(
1504
+ (o) => linkContentPost({ ...o, path: { id }, body: { postGroup } })
1505
+ );
1506
+ }
1507
+ /** Delete a card. */
1508
+ deleteContent(id) {
1509
+ return this.call((o) => deleteContent({ ...o, path: { id } }));
1510
+ }
1511
+ /** The numbers of the published cards, keyed by card id. */
1512
+ contentsPerformance() {
1513
+ return this.call((o) => getContentsPerformance(o));
1514
+ }
1515
+ /**
1516
+ * Runs any generated operation with the facade's guarantees — a non-2xx
1517
+ * throws a `NadiaError`, the transient ones are retried. The way to reach
1518
+ * what the facade does not sugar without giving those up.
1519
+ *
1520
+ * import { getChannelAnalytics } from '@usenadia/node';
1521
+ * await nadia.request((o) =>
1522
+ * getChannelAnalytics({ ...o, path: { integration: id }, query: { date: '7' } })
1523
+ * );
1524
+ */
1525
+ request(operation) {
1526
+ return this.call(operation);
1527
+ }
1528
+ /**
1529
+ * The generated client, configured with your key. Use it for any of the
1530
+ * operations the facade does not wrap — nothing here is a dead end.
1531
+ *
1532
+ * import { getChannelAnalytics } from '@usenadia/node';
1533
+ * await getChannelAnalytics({ client: nadia.raw, path: {...} });
1534
+ */
1535
+ get raw() {
1536
+ return this.client;
1537
+ }
1538
+ };
1539
+ var index_default = Nadia;
1540
+ export {
1541
+ DEFAULT_BASE_URL,
1542
+ Nadia,
1543
+ NadiaError,
1544
+ callVideoFunction,
1545
+ changePostStatus,
1546
+ checkConnection,
1547
+ createAutomationFlow,
1548
+ createContent,
1549
+ createPost,
1550
+ createWebhook,
1551
+ index_default as default,
1552
+ deleteAutomationFlow,
1553
+ deleteAutomationPose,
1554
+ deleteChannel,
1555
+ deleteComment,
1556
+ deleteContent,
1557
+ deletePost,
1558
+ deletePostGroup,
1559
+ deleteWebhook,
1560
+ findSlot,
1561
+ generateVideo,
1562
+ getAccountHistory,
1563
+ getAutomationFlow,
1564
+ getAutomationPose,
1565
+ getChannelAnalytics,
1566
+ getChannelSettings,
1567
+ getContent,
1568
+ getContentsPerformance,
1569
+ getConversation,
1570
+ getHookForms,
1571
+ getMusicTrack,
1572
+ getPostAnalytics,
1573
+ getVideoHistory,
1574
+ getWebhook,
1575
+ hideComment,
1576
+ importHooks,
1577
+ importMusic,
1578
+ linkContentPost,
1579
+ listAutomationFlowPoses,
1580
+ listAutomationFlows,
1581
+ listAutomationPoseRuns,
1582
+ listChannelAutomationPoses,
1583
+ listChannelMedia,
1584
+ listChannelStories,
1585
+ listChannels,
1586
+ listContents,
1587
+ listConversations,
1588
+ listGroups,
1589
+ listHookFamilies,
1590
+ listMediaComments,
1591
+ listMissingMedia,
1592
+ listMusic,
1593
+ listMusicPillars,
1594
+ listNotifications,
1595
+ listPosts,
1596
+ listVideoPerformance,
1597
+ listWebhookEvents,
1598
+ listWebhooks,
1599
+ moveContent,
1600
+ pollAutomationPose,
1601
+ pollInbox,
1602
+ poseAutomationFlow,
1603
+ previewAutomationEmail,
1604
+ replaceHookFamilies,
1605
+ replayAutomationPose,
1606
+ replyToComment,
1607
+ runChannelTool,
1608
+ searchHooks,
1609
+ sendAutomationTestEmail,
1610
+ sendDirectMessage,
1611
+ setAutomationFlowStatus,
1612
+ setPostReleaseId,
1613
+ startChannelConnection,
1614
+ subscribeInboxWebhook,
1615
+ updateAutomationFlow,
1616
+ updateAutomationPose,
1617
+ updateContent,
1618
+ uploadFile,
1619
+ uploadFromUrl,
1620
+ uploadMusicFile,
1621
+ upsertContent
1622
+ };
1623
+ //# sourceMappingURL=index.mjs.map