@andesine/sdk 0.1.0 → 0.5.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.
@@ -0,0 +1,1424 @@
1
+ import { n as AndesineAPIError, t as createAnswerStream } from "./answer-stream-7N_gLhVS.js";
2
+ import createFetchClient from "openapi-fetch";
3
+ //#region src/paginate.ts
4
+ /**
5
+ * Iterate cursor-paginated pages, retaining their metadata.
6
+ *
7
+ * @param getPage - Fetch one page for the supplied cursor. The first cursor is undefined unless supplied.
8
+ * Keep filters stable. This generic helper does not bind snapshots; use content.paginateEntryPages()
9
+ * or content.paginateCollectionPages() for automatic published snapshot handling.
10
+ * @param options - Optional cursor from an earlier page to resume processing.
11
+ * @returns A lazy iterator that requests the next page only after the previous page is consumed.
12
+ * Save pagination.nextCursor after processing a page. Break the loop to stop further requests.
13
+ * @throws Error for a missing or repeated next cursor. Callback failures pass through unchanged.
14
+ */
15
+ const paginatePages = async function* (getPage, options = {}) {
16
+ const seen = new Set(options.cursor ? [options.cursor] : []);
17
+ let cursor = options.cursor;
18
+ do {
19
+ const page = await getPage(cursor);
20
+ const next = page.pagination.nextCursor;
21
+ if (page.pagination.hasMore && (!next || seen.has(next))) throw new Error("Pagination returned a missing or repeated cursor");
22
+ yield page;
23
+ if (!page.pagination.hasMore) return;
24
+ seen.add(next);
25
+ cursor = next;
26
+ } while (cursor);
27
+ };
28
+ /**
29
+ * Iterate items across cursor-paginated pages without collecting them in memory.
30
+ *
31
+ * @param getPage - Fetch one page using the cursor. Keep scope and filters stable in this callback.
32
+ * This generic helper does not bind snapshots; content.paginateEntries() and
33
+ * content.paginateCollections() do that automatically for published content.
34
+ * @param options - Optional starting cursor; retain its matching scope and snapshot yourself.
35
+ * @returns Items in API order. Break the loop to prevent further page requests.
36
+ * @throws Pagination errors from paginatePages(), or the original callback error.
37
+ */
38
+ const paginate = async function* (getPage, options = {}) {
39
+ for await (const page of paginatePages(getPage, options)) yield* page.data;
40
+ };
41
+ //#endregion
42
+ //#region src/content-client.ts
43
+ const paginateSnapshotPages = async function* (list, input, options = {}) {
44
+ let query = { ...input };
45
+ yield* paginatePages(async (cursor) => {
46
+ const page = await list({
47
+ ...query,
48
+ cursor
49
+ }, {
50
+ ...options,
51
+ response: "data"
52
+ });
53
+ if (query.snapshotID !== void 0 && page.snapshotID !== query.snapshotID) throw new Error("Pagination returned a different snapshot");
54
+ query = {
55
+ ...query,
56
+ channel: void 0,
57
+ snapshotID: page.snapshotID
58
+ };
59
+ return page;
60
+ }, { cursor: input.cursor });
61
+ };
62
+ const createContentClient = (content) => {
63
+ const paginateEntryPages = (input = {}, options) => paginateSnapshotPages((query, requestOptions) => content.listEntries(query, requestOptions), input, options);
64
+ const paginateCollectionPages = (input = {}, options) => paginateSnapshotPages((query, requestOptions) => content.listCollections(query, requestOptions), input, options);
65
+ return {
66
+ ...content,
67
+ paginateEntryPages,
68
+ async *paginateEntries(input, options) {
69
+ for await (const page of paginateEntryPages(input, options)) yield* page.data;
70
+ },
71
+ paginateCollectionPages,
72
+ async *paginateCollections(input, options) {
73
+ for await (const page of paginateCollectionPages(input, options)) yield* page.data;
74
+ }
75
+ };
76
+ };
77
+ //#endregion
78
+ //#region src/query.ts
79
+ const serializeQuery = (query) => {
80
+ const parameters = new URLSearchParams();
81
+ const escapeKey = (key) => key.replace(/[\\[\]]/g, (character) => `\\${character}`);
82
+ const append = (path, value) => {
83
+ if (value === void 0 || value === null) return;
84
+ if (Array.isArray(value)) value.forEach((item, index) => append(`${path}[${index}]`, item));
85
+ else if (typeof value === "object") for (const [key, item] of Object.entries(value)) append(`${path}[${escapeKey(key)}]`, item);
86
+ else parameters.append(path, String(value));
87
+ };
88
+ for (const [key, value] of Object.entries(query)) append(escapeKey(key), value);
89
+ return parameters.toString();
90
+ };
91
+ //#endregion
92
+ //#region src/operation.ts
93
+ const operation = (request, definition) => {
94
+ return ((input, options) => {
95
+ return request(definition, input || {}, options);
96
+ });
97
+ };
98
+ //#endregion
99
+ //#region src/generated/resources.ts
100
+ const createResources = (request) => ({
101
+ assets: {
102
+ search: operation(request, {
103
+ method: "get",
104
+ path: "/assets/search",
105
+ pathParams: [],
106
+ queryParams: [
107
+ "query",
108
+ "checksum",
109
+ "semantic",
110
+ "limit"
111
+ ],
112
+ body: false,
113
+ multipart: false,
114
+ binary: false,
115
+ anonymous: false
116
+ }),
117
+ importURL: operation(request, {
118
+ method: "post",
119
+ path: "/assets/imports",
120
+ pathParams: [],
121
+ queryParams: [],
122
+ body: true,
123
+ multipart: false,
124
+ binary: false,
125
+ anonymous: false
126
+ }),
127
+ attach: operation(request, {
128
+ method: "post",
129
+ path: "/assets/{assetID}/attachments",
130
+ pathParams: ["assetID"],
131
+ queryParams: [],
132
+ body: true,
133
+ multipart: false,
134
+ binary: false,
135
+ anonymous: false
136
+ }),
137
+ register: operation(request, {
138
+ method: "post",
139
+ path: "/assets/uploads",
140
+ pathParams: [],
141
+ queryParams: [],
142
+ body: true,
143
+ multipart: false,
144
+ binary: false,
145
+ anonymous: false
146
+ }),
147
+ upload: operation(request, {
148
+ method: "put",
149
+ path: "/assets/{assetID}/upload",
150
+ pathParams: ["assetID"],
151
+ queryParams: [],
152
+ body: true,
153
+ multipart: true,
154
+ binary: false,
155
+ anonymous: false
156
+ }),
157
+ get: operation(request, {
158
+ method: "get",
159
+ path: "/assets/{assetID}",
160
+ pathParams: ["assetID"],
161
+ queryParams: ["entryID"],
162
+ body: false,
163
+ multipart: false,
164
+ binary: false,
165
+ anonymous: false
166
+ })
167
+ },
168
+ auth: { getIdentity: operation(request, {
169
+ method: "get",
170
+ path: "/identity",
171
+ pathParams: [],
172
+ queryParams: [],
173
+ body: false,
174
+ multipart: false,
175
+ binary: false,
176
+ anonymous: false
177
+ }) },
178
+ instance: { get: operation(request, {
179
+ method: "get",
180
+ path: "/instance",
181
+ pathParams: [],
182
+ queryParams: [],
183
+ body: false,
184
+ multipart: false,
185
+ binary: false,
186
+ anonymous: false
187
+ }) },
188
+ entries: {
189
+ create: operation(request, {
190
+ method: "post",
191
+ path: "/entries",
192
+ pathParams: [],
193
+ queryParams: [],
194
+ body: true,
195
+ multipart: false,
196
+ binary: false,
197
+ anonymous: false
198
+ }),
199
+ bulkDelete: operation(request, {
200
+ method: "post",
201
+ path: "/entries/bulk/delete",
202
+ pathParams: [],
203
+ queryParams: [],
204
+ body: true,
205
+ multipart: false,
206
+ binary: false,
207
+ anonymous: false
208
+ }),
209
+ delete: operation(request, {
210
+ method: "delete",
211
+ path: "/entries/{id}",
212
+ pathParams: ["id"],
213
+ queryParams: [],
214
+ body: false,
215
+ multipart: false,
216
+ binary: false,
217
+ anonymous: false
218
+ }),
219
+ update: operation(request, {
220
+ method: "put",
221
+ path: "/entries/{id}",
222
+ pathParams: ["id"],
223
+ queryParams: [],
224
+ body: true,
225
+ multipart: false,
226
+ binary: false,
227
+ anonymous: false
228
+ }),
229
+ get: operation(request, {
230
+ method: "get",
231
+ path: "/entries/get",
232
+ pathParams: [],
233
+ queryParams: [
234
+ "id",
235
+ "path",
236
+ "slugPath",
237
+ "expectedSchemaHash"
238
+ ],
239
+ body: false,
240
+ multipart: false,
241
+ binary: false,
242
+ anonymous: false
243
+ }),
244
+ list: operation(request, {
245
+ method: "get",
246
+ path: "/entries/list",
247
+ pathParams: [],
248
+ queryParams: [
249
+ "collectionID",
250
+ "collectionPath",
251
+ "collectionSlugPath",
252
+ "cursor",
253
+ "limit"
254
+ ],
255
+ body: false,
256
+ multipart: false,
257
+ binary: false,
258
+ anonymous: false
259
+ })
260
+ },
261
+ extensions: {
262
+ getSelf: operation(request, {
263
+ method: "get",
264
+ path: "/extensions/self",
265
+ pathParams: [],
266
+ queryParams: [],
267
+ body: false,
268
+ multipart: false,
269
+ binary: false,
270
+ anonymous: false
271
+ }),
272
+ verifySession: operation(request, {
273
+ method: "post",
274
+ path: "/extensions/self/sessions/verify",
275
+ pathParams: [],
276
+ queryParams: [],
277
+ body: true,
278
+ multipart: false,
279
+ binary: false,
280
+ anonymous: false
281
+ }),
282
+ listInstallations: operation(request, {
283
+ method: "get",
284
+ path: "/extensions/self/installations",
285
+ pathParams: [],
286
+ queryParams: ["after", "limit"],
287
+ body: false,
288
+ multipart: false,
289
+ binary: false,
290
+ anonymous: false
291
+ }),
292
+ getSelfDelivery: operation(request, {
293
+ method: "get",
294
+ path: "/extensions/self/deliveries/{deliveryID}",
295
+ pathParams: ["deliveryID"],
296
+ queryParams: [],
297
+ body: false,
298
+ multipart: false,
299
+ binary: false,
300
+ anonymous: false
301
+ }),
302
+ getSelfConfiguration: operation(request, {
303
+ method: "get",
304
+ path: "/extensions/self/configuration",
305
+ pathParams: [],
306
+ queryParams: [],
307
+ body: false,
308
+ multipart: false,
309
+ binary: false,
310
+ anonymous: false
311
+ }),
312
+ getSelfStorageEntry: operation(request, {
313
+ method: "get",
314
+ path: "/extensions/self/storage/entry",
315
+ pathParams: [],
316
+ queryParams: ["key"],
317
+ body: false,
318
+ multipart: false,
319
+ binary: false,
320
+ anonymous: false
321
+ }),
322
+ setSelfStorageEntry: operation(request, {
323
+ method: "put",
324
+ path: "/extensions/self/storage/entry",
325
+ pathParams: [],
326
+ queryParams: [],
327
+ body: true,
328
+ multipart: false,
329
+ binary: false,
330
+ anonymous: false
331
+ }),
332
+ deleteSelfStorageEntry: operation(request, {
333
+ method: "delete",
334
+ path: "/extensions/self/storage/entry",
335
+ pathParams: [],
336
+ queryParams: ["key"],
337
+ body: false,
338
+ multipart: false,
339
+ binary: false,
340
+ anonymous: false
341
+ }),
342
+ listSelfStorageEntries: operation(request, {
343
+ method: "get",
344
+ path: "/extensions/self/storage",
345
+ pathParams: [],
346
+ queryParams: [
347
+ "prefix",
348
+ "after",
349
+ "limit"
350
+ ],
351
+ body: false,
352
+ multipart: false,
353
+ binary: false,
354
+ anonymous: false
355
+ })
356
+ },
357
+ collections: {
358
+ create: operation(request, {
359
+ method: "post",
360
+ path: "/collections",
361
+ pathParams: [],
362
+ queryParams: [],
363
+ body: true,
364
+ multipart: false,
365
+ binary: false,
366
+ anonymous: false
367
+ }),
368
+ bulkDelete: operation(request, {
369
+ method: "post",
370
+ path: "/collections/bulk/delete",
371
+ pathParams: [],
372
+ queryParams: [],
373
+ body: true,
374
+ multipart: false,
375
+ binary: false,
376
+ anonymous: false
377
+ }),
378
+ delete: operation(request, {
379
+ method: "delete",
380
+ path: "/collections/{id}",
381
+ pathParams: ["id"],
382
+ queryParams: [],
383
+ body: false,
384
+ multipart: false,
385
+ binary: false,
386
+ anonymous: false
387
+ }),
388
+ update: operation(request, {
389
+ method: "put",
390
+ path: "/collections/{id}",
391
+ pathParams: ["id"],
392
+ queryParams: [],
393
+ body: true,
394
+ multipart: false,
395
+ binary: false,
396
+ anonymous: false
397
+ }),
398
+ list: operation(request, {
399
+ method: "get",
400
+ path: "/collections/list",
401
+ pathParams: [],
402
+ queryParams: [
403
+ "collectionID",
404
+ "collectionPath",
405
+ "collectionSlugPath",
406
+ "cursor",
407
+ "limit"
408
+ ],
409
+ body: false,
410
+ multipart: false,
411
+ binary: false,
412
+ anonymous: false
413
+ })
414
+ },
415
+ content: {
416
+ listCollections: operation(request, {
417
+ method: "get",
418
+ path: "/content/collections",
419
+ pathParams: [],
420
+ queryParams: [
421
+ "cursor",
422
+ "limit",
423
+ "collectionID",
424
+ "collectionPath",
425
+ "collectionSlugPath",
426
+ "channel",
427
+ "snapshotID"
428
+ ],
429
+ body: false,
430
+ multipart: false,
431
+ binary: false,
432
+ anonymous: false
433
+ }),
434
+ listEntries: operation(request, {
435
+ method: "get",
436
+ path: "/content/entries",
437
+ pathParams: [],
438
+ queryParams: [
439
+ "cursor",
440
+ "limit",
441
+ "collectionID",
442
+ "collectionPath",
443
+ "collectionSlugPath",
444
+ "channel",
445
+ "snapshotID",
446
+ "descendants",
447
+ "includeContent",
448
+ "filters"
449
+ ],
450
+ body: false,
451
+ multipart: false,
452
+ binary: false,
453
+ anonymous: false
454
+ }),
455
+ getSchema: operation(request, {
456
+ method: "get",
457
+ path: "/content/entries/schema",
458
+ pathParams: [],
459
+ queryParams: [
460
+ "entryID",
461
+ "path",
462
+ "slugPath",
463
+ "channel",
464
+ "snapshotID"
465
+ ],
466
+ body: false,
467
+ multipart: false,
468
+ binary: false,
469
+ anonymous: false
470
+ }),
471
+ getAsset: operation(request, {
472
+ method: "get",
473
+ path: "/content/assets/{workspaceID}/{snapshotID}/{entryID}/{assetID}/{variant}",
474
+ pathParams: [
475
+ "workspaceID",
476
+ "snapshotID",
477
+ "entryID",
478
+ "assetID",
479
+ "variant"
480
+ ],
481
+ queryParams: [],
482
+ body: false,
483
+ multipart: false,
484
+ binary: true,
485
+ anonymous: true
486
+ }),
487
+ get: operation(request, {
488
+ method: "get",
489
+ path: "/content/entries/get",
490
+ pathParams: [],
491
+ queryParams: [
492
+ "entryID",
493
+ "path",
494
+ "slugPath",
495
+ "expectedSchemaHash",
496
+ "channel",
497
+ "snapshotID"
498
+ ],
499
+ body: false,
500
+ multipart: false,
501
+ binary: false,
502
+ anonymous: false
503
+ }),
504
+ getTree: operation(request, {
505
+ method: "get",
506
+ path: "/content/tree",
507
+ pathParams: [],
508
+ queryParams: [
509
+ "collectionID",
510
+ "collectionPath",
511
+ "collectionSlugPath",
512
+ "channel",
513
+ "snapshotID"
514
+ ],
515
+ body: false,
516
+ multipart: false,
517
+ binary: false,
518
+ anonymous: false
519
+ })
520
+ },
521
+ webhooks: {
522
+ list: operation(request, {
523
+ method: "get",
524
+ path: "/webhooks",
525
+ pathParams: [],
526
+ queryParams: ["cursor", "limit"],
527
+ body: false,
528
+ multipart: false,
529
+ binary: false,
530
+ anonymous: false
531
+ }),
532
+ create: operation(request, {
533
+ method: "post",
534
+ path: "/webhooks",
535
+ pathParams: [],
536
+ queryParams: [],
537
+ body: true,
538
+ multipart: false,
539
+ binary: false,
540
+ anonymous: false
541
+ }),
542
+ get: operation(request, {
543
+ method: "get",
544
+ path: "/webhooks/{id}",
545
+ pathParams: ["id"],
546
+ queryParams: [],
547
+ body: false,
548
+ multipart: false,
549
+ binary: false,
550
+ anonymous: false
551
+ }),
552
+ update: operation(request, {
553
+ method: "put",
554
+ path: "/webhooks/{id}",
555
+ pathParams: ["id"],
556
+ queryParams: [],
557
+ body: true,
558
+ multipart: false,
559
+ binary: false,
560
+ anonymous: false
561
+ }),
562
+ delete: operation(request, {
563
+ method: "delete",
564
+ path: "/webhooks/{id}",
565
+ pathParams: ["id"],
566
+ queryParams: [],
567
+ body: true,
568
+ multipart: false,
569
+ binary: false,
570
+ anonymous: false
571
+ }),
572
+ bulkSetEnabled: operation(request, {
573
+ method: "post",
574
+ path: "/webhooks/bulk/set-enabled",
575
+ pathParams: [],
576
+ queryParams: [],
577
+ body: true,
578
+ multipart: false,
579
+ binary: false,
580
+ anonymous: false
581
+ }),
582
+ bulkDelete: operation(request, {
583
+ method: "post",
584
+ path: "/webhooks/bulk/delete",
585
+ pathParams: [],
586
+ queryParams: [],
587
+ body: true,
588
+ multipart: false,
589
+ binary: false,
590
+ anonymous: false
591
+ }),
592
+ rotateSecret: operation(request, {
593
+ method: "post",
594
+ path: "/webhooks/{id}/rotate-secret",
595
+ pathParams: ["id"],
596
+ queryParams: [],
597
+ body: true,
598
+ multipart: false,
599
+ binary: false,
600
+ anonymous: false
601
+ }),
602
+ sendTest: operation(request, {
603
+ method: "post",
604
+ path: "/webhooks/{id}/test",
605
+ pathParams: ["id"],
606
+ queryParams: [],
607
+ body: true,
608
+ multipart: false,
609
+ binary: false,
610
+ anonymous: false
611
+ }),
612
+ listDeliveries: operation(request, {
613
+ method: "get",
614
+ path: "/webhooks/{id}/deliveries",
615
+ pathParams: ["id"],
616
+ queryParams: [
617
+ "cursor",
618
+ "limit",
619
+ "type",
620
+ "state",
621
+ "createdAfter",
622
+ "createdBefore"
623
+ ],
624
+ body: false,
625
+ multipart: false,
626
+ binary: false,
627
+ anonymous: false
628
+ }),
629
+ getDelivery: operation(request, {
630
+ method: "get",
631
+ path: "/webhooks/{id}/deliveries/{deliveryID}",
632
+ pathParams: ["id", "deliveryID"],
633
+ queryParams: [],
634
+ body: false,
635
+ multipart: false,
636
+ binary: false,
637
+ anonymous: false
638
+ }),
639
+ listRuns: operation(request, {
640
+ method: "get",
641
+ path: "/webhooks/{id}/deliveries/{deliveryID}/runs",
642
+ pathParams: ["id", "deliveryID"],
643
+ queryParams: ["cursor", "limit"],
644
+ body: false,
645
+ multipart: false,
646
+ binary: false,
647
+ anonymous: false
648
+ }),
649
+ listAttempts: operation(request, {
650
+ method: "get",
651
+ path: "/webhooks/{id}/deliveries/{deliveryID}/runs/{runID}/attempts",
652
+ pathParams: [
653
+ "id",
654
+ "deliveryID",
655
+ "runID"
656
+ ],
657
+ queryParams: ["cursor", "limit"],
658
+ body: false,
659
+ multipart: false,
660
+ binary: false,
661
+ anonymous: false
662
+ }),
663
+ redeliver: operation(request, {
664
+ method: "post",
665
+ path: "/webhooks/{id}/deliveries/{deliveryID}/redeliver",
666
+ pathParams: ["id", "deliveryID"],
667
+ queryParams: [],
668
+ body: true,
669
+ multipart: false,
670
+ binary: false,
671
+ anonymous: false
672
+ }),
673
+ bulkRedeliver: operation(request, {
674
+ method: "post",
675
+ path: "/webhooks/{id}/deliveries/bulk/redeliver",
676
+ pathParams: ["id"],
677
+ queryParams: [],
678
+ body: true,
679
+ multipart: false,
680
+ binary: false,
681
+ anonymous: false
682
+ })
683
+ },
684
+ roles: {
685
+ list: operation(request, {
686
+ method: "get",
687
+ path: "/roles",
688
+ pathParams: [],
689
+ queryParams: [],
690
+ body: false,
691
+ multipart: false,
692
+ binary: false,
693
+ anonymous: false
694
+ }),
695
+ create: operation(request, {
696
+ method: "post",
697
+ path: "/roles",
698
+ pathParams: [],
699
+ queryParams: [],
700
+ body: true,
701
+ multipart: false,
702
+ binary: false,
703
+ anonymous: false
704
+ }),
705
+ update: operation(request, {
706
+ method: "put",
707
+ path: "/roles/{id}",
708
+ pathParams: ["id"],
709
+ queryParams: [],
710
+ body: true,
711
+ multipart: false,
712
+ binary: false,
713
+ anonymous: false
714
+ }),
715
+ delete: operation(request, {
716
+ method: "delete",
717
+ path: "/roles/{id}",
718
+ pathParams: ["id"],
719
+ queryParams: [],
720
+ body: false,
721
+ multipart: false,
722
+ binary: false,
723
+ anonymous: false
724
+ })
725
+ },
726
+ search: {
727
+ current: operation(request, {
728
+ method: "post",
729
+ path: "/search/current",
730
+ pathParams: [],
731
+ queryParams: [],
732
+ body: true,
733
+ multipart: false,
734
+ binary: false,
735
+ anonymous: false
736
+ }),
737
+ published: operation(request, {
738
+ method: "post",
739
+ path: "/search/published",
740
+ pathParams: [],
741
+ queryParams: [],
742
+ body: true,
743
+ multipart: false,
744
+ binary: false,
745
+ anonymous: false
746
+ }),
747
+ askCurrent: operation(request, {
748
+ method: "post",
749
+ path: "/search/current/ask",
750
+ pathParams: [],
751
+ queryParams: [],
752
+ body: true,
753
+ multipart: false,
754
+ binary: false,
755
+ anonymous: false
756
+ }),
757
+ askPublished: operation(request, {
758
+ method: "post",
759
+ path: "/search/published/ask",
760
+ pathParams: [],
761
+ queryParams: [],
762
+ body: true,
763
+ multipart: false,
764
+ binary: false,
765
+ anonymous: false
766
+ }),
767
+ askCurrentStream: operation(request, {
768
+ streaming: true,
769
+ method: "post",
770
+ path: "/search/current/ask/stream",
771
+ pathParams: [],
772
+ queryParams: [],
773
+ body: true,
774
+ multipart: false,
775
+ binary: false,
776
+ anonymous: false
777
+ }),
778
+ askPublishedStream: operation(request, {
779
+ streaming: true,
780
+ method: "post",
781
+ path: "/search/published/ask/stream",
782
+ pathParams: [],
783
+ queryParams: [],
784
+ body: true,
785
+ multipart: false,
786
+ binary: false,
787
+ anonymous: false
788
+ })
789
+ },
790
+ schemas: {
791
+ create: operation(request, {
792
+ method: "post",
793
+ path: "/collections/{collectionID}/schema",
794
+ pathParams: ["collectionID"],
795
+ queryParams: [],
796
+ body: false,
797
+ multipart: false,
798
+ binary: false,
799
+ anonymous: false
800
+ }),
801
+ delete: operation(request, {
802
+ method: "delete",
803
+ path: "/schemas/{schemaID}",
804
+ pathParams: ["schemaID"],
805
+ queryParams: [],
806
+ body: true,
807
+ multipart: false,
808
+ binary: false,
809
+ anonymous: false
810
+ }),
811
+ getRevision: operation(request, {
812
+ method: "get",
813
+ path: "/schema-revisions/{revisionID}",
814
+ pathParams: ["revisionID"],
815
+ queryParams: [],
816
+ body: false,
817
+ multipart: false,
818
+ binary: false,
819
+ anonymous: false
820
+ }),
821
+ get: operation(request, {
822
+ method: "get",
823
+ path: "/schemas/collection",
824
+ pathParams: [],
825
+ queryParams: [
826
+ "collectionID",
827
+ "collectionPath",
828
+ "collectionSlugPath"
829
+ ],
830
+ body: false,
831
+ multipart: false,
832
+ binary: false,
833
+ anonymous: false
834
+ }),
835
+ apply: operation(request, {
836
+ method: "post",
837
+ path: "/schemas/{schemaID}/apply",
838
+ pathParams: ["schemaID"],
839
+ queryParams: [],
840
+ body: true,
841
+ multipart: false,
842
+ binary: false,
843
+ anonymous: false
844
+ })
845
+ },
846
+ schemaMigrations: {
847
+ listContentLossEntries: operation(request, {
848
+ method: "get",
849
+ path: "/schema-migrations/{id}/content-loss-entries",
850
+ pathParams: ["id"],
851
+ queryParams: ["cursor", "limit"],
852
+ body: false,
853
+ multipart: false,
854
+ binary: false,
855
+ anonymous: false
856
+ }),
857
+ getActive: operation(request, {
858
+ method: "get",
859
+ path: "/collections/{collectionID}/schema-migration",
860
+ pathParams: ["collectionID"],
861
+ queryParams: [],
862
+ body: false,
863
+ multipart: false,
864
+ binary: false,
865
+ anonymous: false
866
+ }),
867
+ get: operation(request, {
868
+ method: "get",
869
+ path: "/schema-migrations/{id}",
870
+ pathParams: ["id"],
871
+ queryParams: [],
872
+ body: false,
873
+ multipart: false,
874
+ binary: false,
875
+ anonymous: false
876
+ })
877
+ },
878
+ schemaVersions: {
879
+ list: operation(request, {
880
+ method: "get",
881
+ path: "/schemas/{schemaID}/versions",
882
+ pathParams: ["schemaID"],
883
+ queryParams: ["cursor", "limit"],
884
+ body: false,
885
+ multipart: false,
886
+ binary: false,
887
+ anonymous: false
888
+ }),
889
+ get: operation(request, {
890
+ method: "get",
891
+ path: "/schema-versions/{id}",
892
+ pathParams: ["id"],
893
+ queryParams: [],
894
+ body: false,
895
+ multipart: false,
896
+ binary: false,
897
+ anonymous: false
898
+ }),
899
+ update: operation(request, {
900
+ method: "patch",
901
+ path: "/schema-versions/{id}",
902
+ pathParams: ["id"],
903
+ queryParams: [],
904
+ body: true,
905
+ multipart: false,
906
+ binary: false,
907
+ anonymous: false
908
+ }),
909
+ revert: operation(request, {
910
+ method: "post",
911
+ path: "/schema-versions/{id}/revert",
912
+ pathParams: ["id"],
913
+ queryParams: [],
914
+ body: true,
915
+ multipart: false,
916
+ binary: false,
917
+ anonymous: false
918
+ })
919
+ },
920
+ memberships: {
921
+ list: operation(request, {
922
+ method: "get",
923
+ path: "/memberships",
924
+ pathParams: [],
925
+ queryParams: ["cursor", "limit"],
926
+ body: false,
927
+ multipart: false,
928
+ binary: false,
929
+ anonymous: false
930
+ }),
931
+ invite: operation(request, {
932
+ method: "post",
933
+ path: "/memberships",
934
+ pathParams: [],
935
+ queryParams: [],
936
+ body: true,
937
+ multipart: false,
938
+ binary: false,
939
+ anonymous: false
940
+ }),
941
+ update: operation(request, {
942
+ method: "patch",
943
+ path: "/memberships/{id}",
944
+ pathParams: ["id"],
945
+ queryParams: [],
946
+ body: true,
947
+ multipart: false,
948
+ binary: false,
949
+ anonymous: false
950
+ }),
951
+ remove: operation(request, {
952
+ method: "delete",
953
+ path: "/memberships/{id}",
954
+ pathParams: ["id"],
955
+ queryParams: [],
956
+ body: false,
957
+ multipart: false,
958
+ binary: false,
959
+ anonymous: false
960
+ }),
961
+ listInvites: operation(request, {
962
+ method: "get",
963
+ path: "/memberships/invites",
964
+ pathParams: [],
965
+ queryParams: ["cursor", "limit"],
966
+ body: false,
967
+ multipart: false,
968
+ binary: false,
969
+ anonymous: false
970
+ }),
971
+ resendInvite: operation(request, {
972
+ method: "post",
973
+ path: "/memberships/invites/{id}/resend",
974
+ pathParams: ["id"],
975
+ queryParams: [],
976
+ body: false,
977
+ multipart: false,
978
+ binary: false,
979
+ anonymous: false
980
+ }),
981
+ revokeInvite: operation(request, {
982
+ method: "delete",
983
+ path: "/memberships/invites/{id}",
984
+ pathParams: ["id"],
985
+ queryParams: [],
986
+ body: false,
987
+ multipart: false,
988
+ binary: false,
989
+ anonymous: false
990
+ })
991
+ },
992
+ publishing: {
993
+ setCollection: operation(request, {
994
+ method: "put",
995
+ path: "/publishing/collections/{collectionID}",
996
+ pathParams: ["collectionID"],
997
+ queryParams: [],
998
+ body: true,
999
+ multipart: false,
1000
+ binary: false,
1001
+ anonymous: false
1002
+ }),
1003
+ publishCollection: operation(request, {
1004
+ method: "post",
1005
+ path: "/publishing/collections/{collectionID}",
1006
+ pathParams: ["collectionID"],
1007
+ queryParams: [],
1008
+ body: true,
1009
+ multipart: false,
1010
+ binary: false,
1011
+ anonymous: false
1012
+ }),
1013
+ unpublishCollection: operation(request, {
1014
+ method: "delete",
1015
+ path: "/publishing/collections/{collectionID}",
1016
+ pathParams: ["collectionID"],
1017
+ queryParams: [],
1018
+ body: true,
1019
+ multipart: false,
1020
+ binary: false,
1021
+ anonymous: false
1022
+ }),
1023
+ bulkSetCollections: operation(request, {
1024
+ method: "post",
1025
+ path: "/publishing/collections/bulk/set",
1026
+ pathParams: [],
1027
+ queryParams: [],
1028
+ body: true,
1029
+ multipart: false,
1030
+ binary: false,
1031
+ anonymous: false
1032
+ }),
1033
+ bulkPublishCollections: operation(request, {
1034
+ method: "post",
1035
+ path: "/publishing/collections/bulk/publish",
1036
+ pathParams: [],
1037
+ queryParams: [],
1038
+ body: true,
1039
+ multipart: false,
1040
+ binary: false,
1041
+ anonymous: false
1042
+ }),
1043
+ bulkUnpublishCollections: operation(request, {
1044
+ method: "post",
1045
+ path: "/publishing/collections/bulk/unpublish",
1046
+ pathParams: [],
1047
+ queryParams: [],
1048
+ body: true,
1049
+ multipart: false,
1050
+ binary: false,
1051
+ anonymous: false
1052
+ }),
1053
+ publishEntry: operation(request, {
1054
+ method: "post",
1055
+ path: "/publishing/entries/{entryID}",
1056
+ pathParams: ["entryID"],
1057
+ queryParams: [],
1058
+ body: true,
1059
+ multipart: false,
1060
+ binary: false,
1061
+ anonymous: false
1062
+ }),
1063
+ unpublishEntry: operation(request, {
1064
+ method: "delete",
1065
+ path: "/publishing/entries/{entryID}",
1066
+ pathParams: ["entryID"],
1067
+ queryParams: [],
1068
+ body: true,
1069
+ multipart: false,
1070
+ binary: false,
1071
+ anonymous: false
1072
+ }),
1073
+ bulkPublishEntries: operation(request, {
1074
+ method: "post",
1075
+ path: "/publishing/entries/bulk/publish",
1076
+ pathParams: [],
1077
+ queryParams: [],
1078
+ body: true,
1079
+ multipart: false,
1080
+ binary: false,
1081
+ anonymous: false
1082
+ }),
1083
+ bulkUnpublishEntries: operation(request, {
1084
+ method: "post",
1085
+ path: "/publishing/entries/bulk/unpublish",
1086
+ pathParams: [],
1087
+ queryParams: [],
1088
+ body: true,
1089
+ multipart: false,
1090
+ binary: false,
1091
+ anonymous: false
1092
+ }),
1093
+ revertChanges: operation(request, {
1094
+ method: "post",
1095
+ path: "/publishing/changes/revert",
1096
+ pathParams: [],
1097
+ queryParams: [],
1098
+ body: true,
1099
+ multipart: false,
1100
+ binary: false,
1101
+ anonymous: false
1102
+ }),
1103
+ getEntryVersion: operation(request, {
1104
+ method: "get",
1105
+ path: "/publishing/entries/{entryID}/version",
1106
+ pathParams: ["entryID"],
1107
+ queryParams: [
1108
+ "channel",
1109
+ "expectedSchemaHash",
1110
+ "snapshotID"
1111
+ ],
1112
+ body: false,
1113
+ multipart: false,
1114
+ binary: false,
1115
+ anonymous: false
1116
+ }),
1117
+ listEntryPublications: operation(request, {
1118
+ method: "get",
1119
+ path: "/publishing/entries/{entryID}/publications",
1120
+ pathParams: ["entryID"],
1121
+ queryParams: [],
1122
+ body: false,
1123
+ multipart: false,
1124
+ binary: false,
1125
+ anonymous: false
1126
+ }),
1127
+ listChannels: operation(request, {
1128
+ method: "get",
1129
+ path: "/publishing/channels",
1130
+ pathParams: [],
1131
+ queryParams: ["includeAssignmentCount"],
1132
+ body: false,
1133
+ multipart: false,
1134
+ binary: false,
1135
+ anonymous: false
1136
+ }),
1137
+ createChannel: operation(request, {
1138
+ method: "post",
1139
+ path: "/publishing/channels",
1140
+ pathParams: [],
1141
+ queryParams: [],
1142
+ body: true,
1143
+ multipart: false,
1144
+ binary: false,
1145
+ anonymous: false
1146
+ }),
1147
+ getChannelContent: operation(request, {
1148
+ method: "get",
1149
+ path: "/publishing/channels/{channel}/content",
1150
+ pathParams: ["channel"],
1151
+ queryParams: ["collectionID"],
1152
+ body: false,
1153
+ multipart: false,
1154
+ binary: false,
1155
+ anonymous: false
1156
+ }),
1157
+ deleteChannel: operation(request, {
1158
+ method: "delete",
1159
+ path: "/publishing/channels/{code}",
1160
+ pathParams: ["code"],
1161
+ queryParams: [],
1162
+ body: true,
1163
+ multipart: false,
1164
+ binary: false,
1165
+ anonymous: false
1166
+ })
1167
+ },
1168
+ workspaces: { list: operation(request, {
1169
+ method: "get",
1170
+ path: "/workspaces",
1171
+ pathParams: [],
1172
+ queryParams: [],
1173
+ body: false,
1174
+ multipart: false,
1175
+ binary: false,
1176
+ anonymous: false
1177
+ }) },
1178
+ versions: {
1179
+ create: operation(request, {
1180
+ method: "post",
1181
+ path: "/entries/{entryID}/versions",
1182
+ pathParams: ["entryID"],
1183
+ queryParams: [],
1184
+ body: true,
1185
+ multipart: false,
1186
+ binary: false,
1187
+ anonymous: false
1188
+ }),
1189
+ list: operation(request, {
1190
+ method: "get",
1191
+ path: "/entries/{entryID}/versions",
1192
+ pathParams: ["entryID"],
1193
+ queryParams: ["cursor", "limit"],
1194
+ body: false,
1195
+ multipart: false,
1196
+ binary: false,
1197
+ anonymous: false
1198
+ }),
1199
+ get: operation(request, {
1200
+ method: "get",
1201
+ path: "/versions/{id}",
1202
+ pathParams: ["id"],
1203
+ queryParams: ["expectedSchemaHash"],
1204
+ body: false,
1205
+ multipart: false,
1206
+ binary: false,
1207
+ anonymous: false
1208
+ }),
1209
+ update: operation(request, {
1210
+ method: "patch",
1211
+ path: "/versions/{id}",
1212
+ pathParams: ["id"],
1213
+ queryParams: [],
1214
+ body: true,
1215
+ multipart: false,
1216
+ binary: false,
1217
+ anonymous: false
1218
+ }),
1219
+ revert: operation(request, {
1220
+ method: "post",
1221
+ path: "/versions/{id}/revert",
1222
+ pathParams: ["id"],
1223
+ queryParams: [],
1224
+ body: false,
1225
+ multipart: false,
1226
+ binary: false,
1227
+ anonymous: false
1228
+ })
1229
+ },
1230
+ typeMetadata: {
1231
+ getCurrent: operation(request, {
1232
+ method: "post",
1233
+ path: "/type-metadata/current",
1234
+ pathParams: [],
1235
+ queryParams: [],
1236
+ body: true,
1237
+ multipart: false,
1238
+ binary: false,
1239
+ anonymous: false
1240
+ }),
1241
+ getPublished: operation(request, {
1242
+ method: "post",
1243
+ path: "/type-metadata/published",
1244
+ pathParams: [],
1245
+ queryParams: [],
1246
+ body: true,
1247
+ multipart: false,
1248
+ binary: false,
1249
+ anonymous: false
1250
+ })
1251
+ }
1252
+ });
1253
+ //#endregion
1254
+ //#region src/retry.ts
1255
+ const wait = (delay, signal) => {
1256
+ signal.throwIfAborted();
1257
+ return new Promise((resolve, reject) => {
1258
+ const abort = () => {
1259
+ clearTimeout(timer);
1260
+ reject(signal.reason);
1261
+ };
1262
+ const timer = setTimeout(() => {
1263
+ signal.removeEventListener("abort", abort);
1264
+ resolve();
1265
+ }, delay);
1266
+ signal.addEventListener("abort", abort, { once: true });
1267
+ });
1268
+ };
1269
+ const retryDelay = (attempt, response) => {
1270
+ const value = response?.headers.get("Retry-After");
1271
+ const seconds = value === null || value === void 0 ? NaN : Number(value);
1272
+ const date = value ? Date.parse(value) : NaN;
1273
+ if (Number.isFinite(seconds)) return Math.max(0, seconds * 1e3);
1274
+ if (Number.isFinite(date)) return Math.max(0, date - Date.now());
1275
+ return Math.min(1e3 * 2 ** attempt, 3e4) + Math.random() * 250;
1276
+ };
1277
+ const fetchWithRetries = async (fetcher, request, retries) => {
1278
+ const signal = request.signal;
1279
+ for (let attempt = 0;; attempt += 1) {
1280
+ let response;
1281
+ signal.throwIfAborted();
1282
+ try {
1283
+ response = await fetcher(request.clone());
1284
+ } catch (error) {
1285
+ if (signal.aborted || attempt >= retries || !(error instanceof TypeError)) throw error;
1286
+ await wait(retryDelay(attempt), signal);
1287
+ continue;
1288
+ }
1289
+ if (attempt >= retries || ![
1290
+ 429,
1291
+ 500,
1292
+ 502,
1293
+ 503,
1294
+ 504
1295
+ ].includes(response.status)) return response;
1296
+ const delay = retryDelay(attempt, response);
1297
+ await response.body?.cancel();
1298
+ await wait(delay, signal);
1299
+ }
1300
+ };
1301
+ //#endregion
1302
+ //#region src/client.ts
1303
+ /**
1304
+ * Create a typed API client for a hosted or self-hosted Andesine instance.
1305
+ *
1306
+ * Methods return response data by default. Use response: "full" for status and headers,
1307
+ * including conditional reads that can return 304. Creation does not make a request.
1308
+ * An optional Workspace type map narrows known content selectors at compile time only.
1309
+ * It does not choose credentials, a workspace, a channel, or a snapshot, or check response schemas.
1310
+ * @param config - Optional API root, credentials, transport, and request defaults.
1311
+ * Defaults to https://api.andesine.app and process.env.ANDESINE_API_KEY when available.
1312
+ * Runtimes without process.env use no default key. No environment files are loaded.
1313
+ * @returns API resources and helpers for published-content snapshots and pagination.
1314
+ * @throws TypeError if both credential options are set, or if baseURL is not HTTP(S) or includes credentials, a query, or a fragment.
1315
+ * Request failures throw AndesineAPIError; abort and timeout reasons are preserved.
1316
+ * @example
1317
+ * const client = createClient();
1318
+ * const page = await client.content.get({ path: "/Docs/Welcome" });
1319
+ */
1320
+ const createClient = (config = {}) => {
1321
+ const baseURL = (config.baseURL ?? "https://api.andesine.app").replace(/\/+$/, "");
1322
+ const credential = config.accessToken ?? config.apiKey ?? globalThis.process?.env?.ANDESINE_API_KEY;
1323
+ const url = new URL(baseURL);
1324
+ const fetcher = config.fetch ?? globalThis.fetch;
1325
+ if (config.accessToken !== void 0 && config.apiKey !== void 0) throw new TypeError("Use either accessToken or apiKey, not both");
1326
+ if (!["http:", "https:"].includes(url.protocol) || url.search || url.hash || url.username || url.password) throw new TypeError("baseURL must be an HTTP(S) URL without credentials, query, or fragment");
1327
+ const request = async (definition, input, options = {}) => {
1328
+ const controller = new AbortController();
1329
+ const signal = options.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
1330
+ const timeout = options.timeout ?? config.timeout ?? 3e4;
1331
+ const retries = options.retries ?? config.retries ?? 0;
1332
+ const headers = new Headers(config.headers);
1333
+ const path = Object.fromEntries(definition.pathParams.map((key) => [key, input[key]]));
1334
+ const query = Object.fromEntries(definition.queryParams.map((key) => [key, input[key]]));
1335
+ const body = Object.fromEntries(Object.entries(input).filter(([key]) => !definition.pathParams.includes(key) && !definition.queryParams.includes(key)));
1336
+ const client = createFetchClient({
1337
+ baseUrl: baseURL,
1338
+ querySerializer: serializeQuery
1339
+ });
1340
+ if (!Number.isFinite(timeout) || timeout < 0 || !Number.isInteger(retries) || retries < 0) throw new TypeError("timeout and retries must be nonnegative; retries must be an integer");
1341
+ if (query.channel !== void 0 && query.snapshotID !== void 0) throw new TypeError("Use either channel or snapshotID, not both");
1342
+ for (const key of definition.pathParams) if (input[key] === void 0 || input[key] === null) throw new TypeError(`Missing path parameter: ${key}`);
1343
+ new Headers(options.headers).forEach((value, key) => headers.set(key, value));
1344
+ if (definition.streaming && !headers.has("Accept")) headers.set("Accept", "text/event-stream");
1345
+ if (credential && !definition.anonymous) headers.set("Authorization", `Bearer ${credential}`);
1346
+ const timer = timeout > 0 ? setTimeout(() => controller.abort(new DOMException("Request timed out", "TimeoutError")), timeout) : void 0;
1347
+ let streamOwnsRequest = false;
1348
+ try {
1349
+ const result = await client.request(definition.method, definition.path, {
1350
+ params: {
1351
+ path,
1352
+ query
1353
+ },
1354
+ headers,
1355
+ signal,
1356
+ body: definition.body ? body : void 0,
1357
+ parseAs: "stream",
1358
+ bodySerializer: definition.multipart ? (value) => {
1359
+ const form = new FormData();
1360
+ for (const [key, item] of Object.entries(value)) if (item instanceof Blob) form.append(key, item);
1361
+ else if (item !== void 0) form.append(key, typeof item === "string" ? item : JSON.stringify(item));
1362
+ return form;
1363
+ } : void 0,
1364
+ fetch: (request) => fetchWithRetries(fetcher, request, definition.method === "get" ? retries : 0)
1365
+ });
1366
+ const response = result.response;
1367
+ if (response.status === 304) {
1368
+ if (options.response !== "full") throw new TypeError("Use response: 'full' for conditional requests that can return 304");
1369
+ return {
1370
+ status: 304,
1371
+ headers: response.headers,
1372
+ data: void 0,
1373
+ notModified: true
1374
+ };
1375
+ }
1376
+ if (!response.ok) throw new AndesineAPIError(response, result.error);
1377
+ if (definition.streaming) {
1378
+ const data = createAnswerStream(response, {
1379
+ signal,
1380
+ cancel: () => controller.abort(),
1381
+ cleanup: () => {
1382
+ if (timer !== void 0) clearTimeout(timer);
1383
+ }
1384
+ });
1385
+ streamOwnsRequest = true;
1386
+ return options.response === "full" ? {
1387
+ status: response.status,
1388
+ headers: response.headers,
1389
+ data,
1390
+ notModified: false
1391
+ } : data;
1392
+ }
1393
+ const text = definition.binary || response.status === 204 ? void 0 : await response.text();
1394
+ const data = definition.binary ? await response.blob() : text ? JSON.parse(text) : void 0;
1395
+ return options.response === "full" ? {
1396
+ status: response.status,
1397
+ headers: response.headers,
1398
+ data,
1399
+ notModified: false
1400
+ } : data;
1401
+ } finally {
1402
+ if (!streamOwnsRequest && timer !== void 0) clearTimeout(timer);
1403
+ }
1404
+ };
1405
+ const resources = createResources(request);
1406
+ return {
1407
+ ...resources,
1408
+ content: createContentClient(resources.content),
1409
+ atSnapshot(snapshotID) {
1410
+ return createContentClient(createResources((definition, input, options) => {
1411
+ const pinned = definition.path.startsWith("/content/") && definition.queryParams.includes("snapshotID");
1412
+ if (pinned && (input.channel !== void 0 || input.snapshotID !== void 0 && input.snapshotID !== snapshotID)) throw new TypeError("Cannot override a pinned snapshot");
1413
+ return request(definition, pinned ? {
1414
+ ...input,
1415
+ snapshotID
1416
+ } : input, options);
1417
+ }).content);
1418
+ }
1419
+ };
1420
+ };
1421
+ //#endregion
1422
+ export { paginate as n, paginatePages as r, createClient as t };
1423
+
1424
+ //# sourceMappingURL=client-DioqVOxl.js.map