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