@uniformdev/next-app-router 20.81.0 → 20.81.1-alpha.10.sha-def425616f

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.
Files changed (48) hide show
  1. package/dist/{UniformComposition-DBO-oo7J.d.ts → UniformComposition-ChDH4dMd.d.ts} +12 -31
  2. package/dist/{UniformComposition-le6UEB_r.d.mts → UniformComposition-Doa1kKRm.d.mts} +12 -31
  3. package/dist/cache.d.mts +24 -6
  4. package/dist/cache.d.ts +24 -6
  5. package/dist/cache.js +396 -832
  6. package/dist/cache.mjs +391 -830
  7. package/dist/compat.d.mts +2 -4
  8. package/dist/compat.d.ts +2 -4
  9. package/dist/component.d.mts +10 -1
  10. package/dist/component.d.ts +10 -1
  11. package/dist/component.js +113 -617
  12. package/dist/component.mjs +112 -640
  13. package/dist/composition-CGU7iH-k.d.mts +37 -0
  14. package/dist/composition-CGU7iH-k.d.ts +37 -0
  15. package/dist/config/default.js +0 -1
  16. package/dist/config/default.mjs +0 -1
  17. package/dist/createCachedManifestProvider-2-2u3PYd.d.mts +84 -0
  18. package/dist/createCachedManifestProvider-BoorKD15.d.ts +84 -0
  19. package/dist/edge.d.mts +80 -0
  20. package/dist/edge.d.ts +80 -0
  21. package/dist/edge.js +1225 -0
  22. package/dist/edge.mjs +1191 -0
  23. package/dist/handler.d.mts +15 -2
  24. package/dist/handler.d.ts +15 -2
  25. package/dist/handler.js +134 -628
  26. package/dist/handler.mjs +132 -626
  27. package/dist/index.d.mts +81 -41
  28. package/dist/index.d.ts +81 -41
  29. package/dist/index.esm.js +2051 -5614
  30. package/dist/index.js +2092 -5651
  31. package/dist/index.mjs +2051 -5614
  32. package/dist/middleware.d.mts +60 -13
  33. package/dist/middleware.d.ts +60 -13
  34. package/dist/middleware.js +415 -5746
  35. package/dist/middleware.mjs +422 -5776
  36. package/dist/models-C8OdCO44.d.mts +72 -0
  37. package/dist/models-C8OdCO44.d.ts +72 -0
  38. package/dist/resolveRouteFromPath-CnfnaxY2.d.ts +80 -0
  39. package/dist/resolveRouteFromPath-_rauUskz.d.mts +80 -0
  40. package/dist/vercel.d.mts +37 -0
  41. package/dist/vercel.d.ts +37 -0
  42. package/dist/vercel.js +788 -0
  43. package/dist/vercel.mjs +759 -0
  44. package/package.json +37 -9
  45. package/dist/client-BElN_CWD.d.mts +0 -786
  46. package/dist/client-BElN_CWD.d.ts +0 -786
  47. package/dist/resolveRouteFromCode-BOvjIvM2.d.ts +0 -18
  48. package/dist/resolveRouteFromCode-CuJ4JHeb.d.mts +0 -18
package/dist/cache.mjs CHANGED
@@ -41,124 +41,6 @@ var __privateWrapper = (obj, member, setter, getter) => ({
41
41
  }
42
42
  });
43
43
 
44
- // ../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js
45
- var require_yocto_queue = __commonJS({
46
- "../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js"(exports, module) {
47
- "use strict";
48
- var Node2 = class {
49
- /// value;
50
- /// next;
51
- constructor(value) {
52
- this.value = value;
53
- this.next = void 0;
54
- }
55
- };
56
- var Queue2 = class {
57
- // TODO: Use private class fields when targeting Node.js 12.
58
- // #_head;
59
- // #_tail;
60
- // #_size;
61
- constructor() {
62
- this.clear();
63
- }
64
- enqueue(value) {
65
- const node = new Node2(value);
66
- if (this._head) {
67
- this._tail.next = node;
68
- this._tail = node;
69
- } else {
70
- this._head = node;
71
- this._tail = node;
72
- }
73
- this._size++;
74
- }
75
- dequeue() {
76
- const current = this._head;
77
- if (!current) {
78
- return;
79
- }
80
- this._head = this._head.next;
81
- this._size--;
82
- return current.value;
83
- }
84
- clear() {
85
- this._head = void 0;
86
- this._tail = void 0;
87
- this._size = 0;
88
- }
89
- get size() {
90
- return this._size;
91
- }
92
- *[Symbol.iterator]() {
93
- let current = this._head;
94
- while (current) {
95
- yield current.value;
96
- current = current.next;
97
- }
98
- }
99
- };
100
- module.exports = Queue2;
101
- }
102
- });
103
-
104
- // ../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js
105
- var require_p_limit = __commonJS({
106
- "../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js"(exports, module) {
107
- "use strict";
108
- var Queue2 = require_yocto_queue();
109
- var pLimit3 = (concurrency) => {
110
- if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
111
- throw new TypeError("Expected `concurrency` to be a number from 1 and up");
112
- }
113
- const queue = new Queue2();
114
- let activeCount = 0;
115
- const next = () => {
116
- activeCount--;
117
- if (queue.size > 0) {
118
- queue.dequeue()();
119
- }
120
- };
121
- const run = async (fn, resolve, ...args) => {
122
- activeCount++;
123
- const result = (async () => fn(...args))();
124
- resolve(result);
125
- try {
126
- await result;
127
- } catch (e) {
128
- }
129
- next();
130
- };
131
- const enqueue = (fn, resolve, ...args) => {
132
- queue.enqueue(run.bind(null, fn, resolve, ...args));
133
- (async () => {
134
- await Promise.resolve();
135
- if (activeCount < concurrency && queue.size > 0) {
136
- queue.dequeue()();
137
- }
138
- })();
139
- };
140
- const generator = (fn, ...args) => new Promise((resolve) => {
141
- enqueue(fn, resolve, ...args);
142
- });
143
- Object.defineProperties(generator, {
144
- activeCount: {
145
- get: () => activeCount
146
- },
147
- pendingCount: {
148
- get: () => queue.size
149
- },
150
- clearQueue: {
151
- value: () => {
152
- queue.clear();
153
- }
154
- }
155
- });
156
- return generator;
157
- };
158
- module.exports = pLimit3;
159
- }
160
- });
161
-
162
44
  // ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js
163
45
  var require_retry_operation = __commonJS({
164
46
  "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js"(exports, module) {
@@ -390,436 +272,9 @@ var require_retry2 = __commonJS({
390
272
  }
391
273
  });
392
274
 
393
- // src/data/resolveRouteFromCode.ts
394
- import { deserializeEvaluationResult } from "@uniformdev/next-app-router-shared";
395
-
396
- // ../context/dist/api/api.mjs
397
- var import_p_limit = __toESM(require_p_limit(), 1);
398
- var __defProp2 = Object.defineProperty;
399
- var __typeError2 = (msg) => {
400
- throw TypeError(msg);
401
- };
402
- var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
403
- var __publicField2 = (obj, key, value) => __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
404
- var __accessCheck2 = (obj, member, msg) => member.has(obj) || __typeError2("Cannot " + msg);
405
- var __privateGet2 = (obj, member, getter) => (__accessCheck2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
406
- var __privateAdd2 = (obj, member, value) => member.has(obj) ? __typeError2("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
407
- var defaultLimitPolicy = (0, import_p_limit.default)(6);
408
- var UNIFORM_BEARER_TOKEN_NOT_VALID_OR_EXPIRED_MESSAGE = "Bearer token not valid or expired";
409
- var ApiClientError = class _ApiClientError extends Error {
410
- constructor(errorMessage, fetchMethod, fetchUri, statusCode, statusText, requestId) {
411
- super(
412
- `${errorMessage}
413
- ${statusCode}${statusText ? " " + statusText : ""} (${fetchMethod} ${fetchUri}${requestId ? ` Request ID: ${requestId}` : ""})`
414
- );
415
- __publicField2(this, "errorMessage", errorMessage);
416
- __publicField2(this, "fetchMethod", fetchMethod);
417
- __publicField2(this, "fetchUri", fetchUri);
418
- __publicField2(this, "statusCode", statusCode);
419
- __publicField2(this, "statusText", statusText);
420
- __publicField2(this, "requestId", requestId);
421
- Object.setPrototypeOf(this, _ApiClientError.prototype);
422
- }
423
- };
424
- var BearerTokenNotValidOrExpiredError = class _BearerTokenNotValidOrExpiredError extends ApiClientError {
425
- constructor(errorMessage, fetchMethod, fetchUri, statusCode, statusText, requestId) {
426
- super(errorMessage, fetchMethod, fetchUri, statusCode, statusText, requestId);
427
- Object.setPrototypeOf(this, _BearerTokenNotValidOrExpiredError.prototype);
428
- }
429
- };
430
- var ApiClient = class _ApiClient {
431
- constructor(options) {
432
- __publicField2(this, "options");
433
- var _a, _b, _c, _d, _e;
434
- if (!options.apiKey && !options.bearerToken) {
435
- throw new Error("You must provide an API key or a bearer token");
436
- }
437
- let leFetch = options.fetch;
438
- if (!leFetch) {
439
- if (typeof window !== "undefined") {
440
- leFetch = window.fetch.bind(window);
441
- } else if (typeof fetch !== "undefined") {
442
- leFetch = fetch;
443
- } else {
444
- throw new Error("You must provide or polyfill a fetch implementation when not in a browser");
445
- }
446
- }
447
- this.options = {
448
- ...options,
449
- fetch: leFetch,
450
- apiHost: this.ensureApiHost(options.apiHost),
451
- apiKey: (_a = options.apiKey) != null ? _a : null,
452
- projectId: (_b = options.projectId) != null ? _b : null,
453
- bearerToken: (_c = options.bearerToken) != null ? _c : null,
454
- limitPolicy: (_d = options.limitPolicy) != null ? _d : defaultLimitPolicy,
455
- bypassCache: (_e = options.bypassCache) != null ? _e : false
456
- };
457
- }
458
- async apiClient(fetchUri, options) {
459
- return (await this.apiClientWithResponse(fetchUri, options)).body;
460
- }
461
- async apiClientWithResponse(fetchUri, options) {
462
- return this.options.limitPolicy(async () => {
463
- var _a, _b;
464
- const coreHeaders = this.options.apiKey ? {
465
- "x-api-key": this.options.apiKey
466
- } : {
467
- Authorization: `Bearer ${this.options.bearerToken}`
468
- };
469
- if (this.options.bypassCache) {
470
- coreHeaders["x-bypass-cache"] = "true";
471
- }
472
- const { fetch: fetch2, signal } = this.options;
473
- const callApi = () => fetch2(fetchUri.toString(), {
474
- ...options,
475
- signal,
476
- headers: {
477
- ...options == null ? void 0 : options.headers,
478
- ...coreHeaders
479
- }
480
- });
481
- const apiResponse = await handleRateLimits(callApi);
482
- if (!apiResponse.ok) {
483
- let message = "";
484
- try {
485
- const responseText = await apiResponse.text();
486
- try {
487
- const parsed = JSON.parse(responseText);
488
- if (parsed.errorMessage) {
489
- message = Array.isArray(parsed.errorMessage) ? parsed.errorMessage.join(", ") : parsed.errorMessage;
490
- } else {
491
- message = responseText;
492
- }
493
- } catch (e) {
494
- message = responseText;
495
- }
496
- } catch (e) {
497
- message = `General error`;
498
- }
499
- if (apiResponse.status === 401 && message === UNIFORM_BEARER_TOKEN_NOT_VALID_OR_EXPIRED_MESSAGE) {
500
- throw new BearerTokenNotValidOrExpiredError(
501
- message,
502
- (_a = options == null ? void 0 : options.method) != null ? _a : "GET",
503
- fetchUri.toString(),
504
- apiResponse.status,
505
- apiResponse.statusText,
506
- _ApiClient.getRequestId(apiResponse)
507
- );
508
- }
509
- throw new ApiClientError(
510
- message,
511
- (_b = options == null ? void 0 : options.method) != null ? _b : "GET",
512
- fetchUri.toString(),
513
- apiResponse.status,
514
- apiResponse.statusText,
515
- _ApiClient.getRequestId(apiResponse)
516
- );
517
- }
518
- if (options == null ? void 0 : options.expectNoContent) {
519
- return { response: apiResponse, body: null };
520
- }
521
- return {
522
- response: apiResponse,
523
- body: await apiResponse.json()
524
- };
525
- });
526
- }
527
- createUrl(path, queryParams, hostOverride) {
528
- const url = new URL(`${hostOverride != null ? hostOverride : this.options.apiHost}${path}`);
529
- Object.entries(queryParams != null ? queryParams : {}).forEach(([key, value]) => {
530
- var _a;
531
- if (typeof value !== "undefined" && value !== null) {
532
- url.searchParams.append(key, Array.isArray(value) ? value.join(",") : (_a = value == null ? void 0 : value.toString()) != null ? _a : "");
533
- }
534
- });
535
- return url;
536
- }
537
- ensureApiHost(apiHost) {
538
- if (!apiHost) return "https://uniform.app";
539
- if (!(apiHost == null ? void 0 : apiHost.startsWith("http"))) {
540
- throw new Error('Your apiHost must start with "http"');
541
- }
542
- if (apiHost.indexOf("/", 8) > -1) {
543
- throw new Error("Your apiHost must not contain a path element after the domain");
544
- }
545
- if (apiHost.indexOf("?") > -1) {
546
- throw new Error("Your apiHost must not contain a query string");
547
- }
548
- if (apiHost == null ? void 0 : apiHost.endsWith("/")) {
549
- apiHost = apiHost.substring(0, apiHost.length - 1);
550
- }
551
- return apiHost;
552
- }
553
- static getRequestId(response) {
554
- const apigRequestId = response.headers.get("apigw-requestid");
555
- if (apigRequestId) {
556
- return apigRequestId;
557
- }
558
- return void 0;
559
- }
560
- };
561
- async function handleRateLimits(callApi) {
562
- var _a;
563
- const backoffRetries = 5;
564
- let backoffRetriesLeft = backoffRetries;
565
- let response;
566
- while (backoffRetriesLeft > 0) {
567
- response = await callApi();
568
- if (response.status !== 429) {
569
- break;
570
- }
571
- let resetWait = 0;
572
- try {
573
- const responseClone = response.clone();
574
- const dateHeader = responseClone.headers.get("date");
575
- const serverTime = dateHeader ? new Date(dateHeader).getTime() : void 0;
576
- const body = await responseClone.json();
577
- const resetTime = (_a = body == null ? void 0 : body.info) == null ? void 0 : _a.reset;
578
- if (typeof serverTime === "number" && typeof resetTime === "number") {
579
- resetWait = Math.max(0, Math.min(Math.round(1.1 * (resetTime - serverTime)), 1e4));
580
- }
581
- } catch (e) {
582
- }
583
- const base = Math.pow(2, backoffRetries - backoffRetriesLeft) * 333;
584
- const backoffWait = base + Math.round(Math.random() * (base / 2)) * (Math.random() > 0.5 ? 1 : -1);
585
- await new Promise((resolve) => setTimeout(resolve, Math.max(0, resetWait + backoffWait)));
586
- backoffRetriesLeft -= 1;
587
- }
588
- return response;
589
- }
590
- var isPlainObject = (obj) => typeof obj === "object" && obj !== null && !Array.isArray(obj);
591
- function rewriteFiltersForApi(filters) {
592
- return Object.entries(filters != null ? filters : {}).reduce(
593
- (acc, [key, value]) => {
594
- const lhs = `filters.${key}` + (isPlainObject(value) ? `[${Object.keys(value)[0]}]` : "");
595
- const rhs = isPlainObject(value) ? Object.values(value)[0] : value;
596
- return {
597
- ...acc,
598
- [lhs]: Array.isArray(rhs) ? rhs.map((v) => `${v}`.trim()).join(",") : `${rhs}`.trim()
599
- };
600
- },
601
- {}
602
- );
603
- }
604
- var _url;
605
- var _AggregateClient = class _AggregateClient2 extends ApiClient {
606
- constructor(options) {
607
- super(options);
608
- }
609
- /** Fetches all aggregates for a project */
610
- async get(options) {
611
- const { projectId } = this.options;
612
- const fetchUri = this.createUrl(__privateGet2(_AggregateClient2, _url), { ...options, projectId });
613
- return await this.apiClient(fetchUri);
614
- }
615
- /** Updates or creates (based on id) an Aggregate */
616
- async upsert(body) {
617
- const fetchUri = this.createUrl(__privateGet2(_AggregateClient2, _url));
618
- await this.apiClient(fetchUri, {
619
- method: "PUT",
620
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
621
- expectNoContent: true
622
- });
623
- }
624
- /** Deletes an Aggregate */
625
- async remove(body) {
626
- const fetchUri = this.createUrl(__privateGet2(_AggregateClient2, _url));
627
- await this.apiClient(fetchUri, {
628
- method: "DELETE",
629
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
630
- expectNoContent: true
631
- });
632
- }
633
- };
634
- _url = /* @__PURE__ */ new WeakMap();
635
- __privateAdd2(_AggregateClient, _url, "/api/v2/aggregate");
636
- var _url2;
637
- var _DimensionClient = class _DimensionClient2 extends ApiClient {
638
- constructor(options) {
639
- super(options);
640
- }
641
- /** Fetches the known score dimensions for a project */
642
- async get(options) {
643
- const { projectId } = this.options;
644
- const fetchUri = this.createUrl(__privateGet2(_DimensionClient2, _url2), { ...options, projectId });
645
- return await this.apiClient(fetchUri);
646
- }
647
- };
648
- _url2 = /* @__PURE__ */ new WeakMap();
649
- __privateAdd2(_DimensionClient, _url2, "/api/v2/dimension");
650
- var _url3;
651
- var _valueUrl;
652
- var _EnrichmentClient = class _EnrichmentClient2 extends ApiClient {
653
- constructor(options) {
654
- super(options);
655
- }
656
- /** Fetches all enrichments and values for a project, grouped by category */
657
- async get(options) {
658
- const { projectId } = this.options;
659
- const fetchUri = this.createUrl(__privateGet2(_EnrichmentClient2, _url3), { ...options, projectId });
660
- return await this.apiClient(fetchUri);
661
- }
662
- /** Updates or creates (based on id) an enrichment category */
663
- async upsertCategory(body) {
664
- const fetchUri = this.createUrl(__privateGet2(_EnrichmentClient2, _url3));
665
- await this.apiClient(fetchUri, {
666
- method: "PUT",
667
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
668
- expectNoContent: true
669
- });
670
- }
671
- /** Deletes an enrichment category */
672
- async removeCategory(body) {
673
- const fetchUri = this.createUrl(__privateGet2(_EnrichmentClient2, _url3));
674
- await this.apiClient(fetchUri, {
675
- method: "DELETE",
676
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
677
- expectNoContent: true
678
- });
679
- }
680
- /** Updates or creates (based on id) an enrichment value within an enrichment category */
681
- async upsertValue(body) {
682
- const fetchUri = this.createUrl(__privateGet2(_EnrichmentClient2, _valueUrl));
683
- await this.apiClient(fetchUri, {
684
- method: "PUT",
685
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
686
- expectNoContent: true
687
- });
688
- }
689
- /** Deletes an enrichment value within an enrichment category. The category is left alone. */
690
- async removeValue(body) {
691
- const fetchUri = this.createUrl(__privateGet2(_EnrichmentClient2, _valueUrl));
692
- await this.apiClient(fetchUri, {
693
- method: "DELETE",
694
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
695
- expectNoContent: true
696
- });
697
- }
698
- };
699
- _url3 = /* @__PURE__ */ new WeakMap();
700
- _valueUrl = /* @__PURE__ */ new WeakMap();
701
- __privateAdd2(_EnrichmentClient, _url3, "/api/v1/enrichments");
702
- __privateAdd2(_EnrichmentClient, _valueUrl, "/api/v1/enrichment-values");
703
- var _url4;
704
- var _ManifestClient = class _ManifestClient2 extends ApiClient {
705
- constructor(options) {
706
- super(options);
707
- }
708
- /** Fetches the Context manifest for a project */
709
- async get(options) {
710
- const { projectId } = this.options;
711
- const fetchUri = this.createUrl(__privateGet2(_ManifestClient2, _url4), { ...options, projectId });
712
- return await this.apiClient(fetchUri);
713
- }
714
- /** Publishes the Context manifest for a project */
715
- async publish() {
716
- const { projectId } = this.options;
717
- const fetchUri = this.createUrl("/api/v1/publish", { siteId: projectId });
718
- await this.apiClient(fetchUri, {
719
- method: "POST",
720
- expectNoContent: true
721
- });
722
- }
723
- };
724
- _url4 = /* @__PURE__ */ new WeakMap();
725
- __privateAdd2(_ManifestClient, _url4, "/api/v2/manifest");
726
- var ManifestClient = _ManifestClient;
727
- var _url5;
728
- var _QuirkClient = class _QuirkClient2 extends ApiClient {
729
- constructor(options) {
730
- super(options);
731
- }
732
- /** Fetches all Quirks for a project */
733
- async get(options) {
734
- const { projectId } = this.options;
735
- const fetchUri = this.createUrl(__privateGet2(_QuirkClient2, _url5), { ...options, projectId });
736
- return await this.apiClient(fetchUri);
737
- }
738
- /** Updates or creates (based on id) a Quirk */
739
- async upsert(body) {
740
- const fetchUri = this.createUrl(__privateGet2(_QuirkClient2, _url5));
741
- await this.apiClient(fetchUri, {
742
- method: "PUT",
743
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
744
- expectNoContent: true
745
- });
746
- }
747
- /** Deletes a Quirk */
748
- async remove(body) {
749
- const fetchUri = this.createUrl(__privateGet2(_QuirkClient2, _url5));
750
- await this.apiClient(fetchUri, {
751
- method: "DELETE",
752
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
753
- expectNoContent: true
754
- });
755
- }
756
- };
757
- _url5 = /* @__PURE__ */ new WeakMap();
758
- __privateAdd2(_QuirkClient, _url5, "/api/v2/quirk");
759
- var _url6;
760
- var _SignalClient = class _SignalClient2 extends ApiClient {
761
- constructor(options) {
762
- super(options);
763
- }
764
- /** Fetches all Signals for a project */
765
- async get(options) {
766
- const { projectId } = this.options;
767
- const fetchUri = this.createUrl(__privateGet2(_SignalClient2, _url6), { ...options, projectId });
768
- return await this.apiClient(fetchUri);
769
- }
770
- /** Updates or creates (based on id) a Signal */
771
- async upsert(body) {
772
- const fetchUri = this.createUrl(__privateGet2(_SignalClient2, _url6));
773
- await this.apiClient(fetchUri, {
774
- method: "PUT",
775
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
776
- expectNoContent: true
777
- });
778
- }
779
- /** Deletes a Signal */
780
- async remove(body) {
781
- const fetchUri = this.createUrl(__privateGet2(_SignalClient2, _url6));
782
- await this.apiClient(fetchUri, {
783
- method: "DELETE",
784
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
785
- expectNoContent: true
786
- });
787
- }
788
- };
789
- _url6 = /* @__PURE__ */ new WeakMap();
790
- __privateAdd2(_SignalClient, _url6, "/api/v2/signal");
791
- var _url7;
792
- var _TestClient = class _TestClient2 extends ApiClient {
793
- constructor(options) {
794
- super(options);
795
- }
796
- /** Fetches all Tests for a project */
797
- async get(options) {
798
- const { projectId } = this.options;
799
- const fetchUri = this.createUrl(__privateGet2(_TestClient2, _url7), { ...options, projectId });
800
- return await this.apiClient(fetchUri);
801
- }
802
- /** Updates or creates (based on id) a Test */
803
- async upsert(body) {
804
- const fetchUri = this.createUrl(__privateGet2(_TestClient2, _url7));
805
- await this.apiClient(fetchUri, {
806
- method: "PUT",
807
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
808
- expectNoContent: true
809
- });
810
- }
811
- /** Deletes a Test */
812
- async remove(body) {
813
- const fetchUri = this.createUrl(__privateGet2(_TestClient2, _url7));
814
- await this.apiClient(fetchUri, {
815
- method: "DELETE",
816
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
817
- expectNoContent: true
818
- });
819
- }
820
- };
821
- _url7 = /* @__PURE__ */ new WeakMap();
822
- __privateAdd2(_TestClient, _url7, "/api/v2/test");
275
+ // ../canvas/dist/index.mjs
276
+ import { ApiClient } from "@uniformdev/context/api";
277
+ import { ApiClientError } from "@uniformdev/context/api";
823
278
 
824
279
  // ../../node_modules/.pnpm/yocto-queue@1.2.2/node_modules/yocto-queue/index.js
825
280
  var Node = class {
@@ -892,7 +347,7 @@ _tail = new WeakMap();
892
347
  _size = new WeakMap();
893
348
 
894
349
  // ../../node_modules/.pnpm/p-limit@6.2.0/node_modules/p-limit/index.js
895
- function pLimit2(concurrency) {
350
+ function pLimit(concurrency) {
896
351
  validateConcurrency(concurrency);
897
352
  const queue = new Queue();
898
353
  let activeCount = 0;
@@ -1172,19 +627,44 @@ function pThrottle({ limit, interval, strict, onDelay }) {
1172
627
  }
1173
628
 
1174
629
  // ../canvas/dist/index.mjs
1175
- var __typeError3 = (msg) => {
630
+ import { ApiClientError as ApiClientError2 } from "@uniformdev/context/api";
631
+ import { ApiClient as ApiClient2 } from "@uniformdev/context/api";
632
+ import { rewriteFiltersForApi } from "@uniformdev/context/api";
633
+ import { rewriteFiltersForApi as rewriteFiltersForApi2 } from "@uniformdev/context/api";
634
+ import { ApiClientError as ApiClientError3 } from "@uniformdev/context/api";
635
+ import { rewriteFiltersForApi as rewriteFiltersForApi3 } from "@uniformdev/context/api";
636
+ import { ApiClientError as ApiClientError4 } from "@uniformdev/context/api";
637
+ import { rewriteFiltersForApi as rewriteFiltersForApi4 } from "@uniformdev/context/api";
638
+ import { ApiClient as ApiClient3, rewriteFiltersForApi as rewriteFiltersForApi5 } from "@uniformdev/context/api";
639
+ import { ApiClient as ApiClient4, rewriteFiltersForApi as rewriteFiltersForApi6 } from "@uniformdev/context/api";
640
+ import { ApiClient as ApiClient5 } from "@uniformdev/context/api";
641
+ import { ApiClient as ApiClient6 } from "@uniformdev/context/api";
642
+ import { ApiClient as ApiClient7 } from "@uniformdev/context/api";
643
+ import { ApiClient as ApiClient8 } from "@uniformdev/context/api";
644
+ import { ApiClient as ApiClient9 } from "@uniformdev/context/api";
645
+ import { ApiClient as ApiClient10 } from "@uniformdev/context/api";
646
+ import { ApiClient as ApiClient11 } from "@uniformdev/context/api";
647
+ import { ApiClient as ApiClient12 } from "@uniformdev/context/api";
648
+ import { ApiClient as ApiClient13 } from "@uniformdev/context/api";
649
+ import { ApiClient as ApiClient14 } from "@uniformdev/context/api";
650
+ import { ApiClient as ApiClient15 } from "@uniformdev/context/api";
651
+ import { ApiClient as ApiClient16 } from "@uniformdev/context/api";
652
+ import { ApiClient as ApiClient17 } from "@uniformdev/context/api";
653
+ import { ApiClientError as ApiClientError5 } from "@uniformdev/context/api";
654
+ import { ApiClient as ApiClient18 } from "@uniformdev/context/api";
655
+ var __typeError2 = (msg) => {
1176
656
  throw TypeError(msg);
1177
657
  };
1178
- var __accessCheck3 = (obj, member, msg) => member.has(obj) || __typeError3("Cannot " + msg);
1179
- var __privateGet3 = (obj, member, getter) => (__accessCheck3(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
1180
- var __privateAdd3 = (obj, member, value) => member.has(obj) ? __typeError3("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
658
+ var __accessCheck2 = (obj, member, msg) => member.has(obj) || __typeError2("Cannot " + msg);
659
+ var __privateGet2 = (obj, member, getter) => (__accessCheck2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
660
+ var __privateAdd2 = (obj, member, value) => member.has(obj) ? __typeError2("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1181
661
  function createLimitPolicy({
1182
662
  throttle = { interval: 1e3, limit: 10 },
1183
663
  retry: retry3 = { retries: 1, factor: 1.66 },
1184
664
  limit = 10
1185
665
  }) {
1186
666
  const throttler = throttle ? pThrottle(throttle) : null;
1187
- const limiter = limit ? pLimit2(limit) : null;
667
+ const limiter = limit ? pLimit(limit) : null;
1188
668
  return function limitPolicy(func) {
1189
669
  let currentFunc = async () => await func();
1190
670
  if (throttler) {
@@ -1212,6 +692,16 @@ function createLimitPolicy({
1212
692
  return currentFunc();
1213
693
  };
1214
694
  }
695
+ var ContentClientBase = class extends ApiClient2 {
696
+ constructor(options, defaultBypassCache) {
697
+ var _a, _b;
698
+ super({
699
+ ...options,
700
+ limitPolicy: (_a = options.limitPolicy) != null ? _a : createLimitPolicy({}),
701
+ bypassCache: (_b = options.bypassCache) != null ? _b : defaultBypassCache
702
+ });
703
+ }
704
+ };
1215
705
  var SELECT_QUERY_PREFIX = "select.";
1216
706
  function appendCsv(out, key, values) {
1217
707
  if (values === void 0) {
@@ -1264,9 +754,89 @@ var CANVAS_COMPONENT_DISPLAY_NAME_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}displa
1264
754
  var CANVAS_HYPOTHESIS_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}hypothesis`;
1265
755
  var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1266
756
  var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
757
+ function resolveCompositionSelector(args) {
758
+ if ("compositionId" in args) {
759
+ const { compositionId, editionId, versionId, ...readOptions } = args;
760
+ return {
761
+ readOptions,
762
+ // raw mode matches on composition OR edition id via the compositionId param
763
+ compositionId: editionId != null ? editionId : compositionId,
764
+ versionId,
765
+ hasCompositionId: true,
766
+ pinnedEdition: editionId !== void 0
767
+ };
768
+ }
769
+ return { readOptions: args, hasCompositionId: false, pinnedEdition: false };
770
+ }
771
+ var DEFAULT_EDGE_API_HOST = "https://uniform.global";
772
+ var DeliveryClientBase = class extends ContentClientBase {
773
+ constructor(options) {
774
+ var _a;
775
+ super(
776
+ options,
777
+ /* defaultBypassCache */
778
+ false
779
+ );
780
+ this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : DEFAULT_EDGE_API_HOST;
781
+ this.edgeRequestInit = options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0;
782
+ }
783
+ /** Coerces the `diagnostics` option into the shape the edge endpoints accept. */
784
+ coerceDiagnostics(diagnostics) {
785
+ return typeof diagnostics === "boolean" ? diagnostics : diagnostics === "no-data" ? "no-data" : void 0;
786
+ }
787
+ };
788
+ var EDGE_SINGLE_URL = "/api/v1/composition";
789
+ var EDGE_LIST_URL = "/api/v1/compositions";
790
+ var CompositionDeliveryClient = class extends DeliveryClientBase {
791
+ constructor(options) {
792
+ super(options);
793
+ }
794
+ /** Fetches exactly one composition (throws `ApiClientError(404)` if absent). */
795
+ get(args) {
796
+ var _a;
797
+ const { diagnostics, select, ...rest } = args;
798
+ const { readOptions, compositionId, versionId, pinnedEdition } = resolveCompositionSelector(rest);
799
+ const url = this.createUrl(
800
+ EDGE_SINGLE_URL,
801
+ {
802
+ ...readOptions,
803
+ ...projectionToQuery(select),
804
+ // A pinned edition is folded into compositionId (raw matches edition or
805
+ // composition id); there is no editionId query param on this endpoint.
806
+ compositionId,
807
+ versionId,
808
+ projectId: this.options.projectId,
809
+ state: (_a = args.state) != null ? _a : CANVAS_PUBLISHED_STATE,
810
+ // editionId pins a specific edition for preview; otherwise locale-best.
811
+ editions: pinnedEdition ? "raw" : "auto",
812
+ diagnostics: this.coerceDiagnostics(diagnostics)
813
+ },
814
+ this.edgeApiHost
815
+ );
816
+ return this.apiClient(url, this.edgeRequestInit);
817
+ }
818
+ /** Fetches a list of compositions, optionally filtered. */
819
+ list(args = {}) {
820
+ var _a;
821
+ const { diagnostics, filters, select, ...rest } = args;
822
+ const url = this.createUrl(
823
+ EDGE_LIST_URL,
824
+ {
825
+ ...rest,
826
+ ...rewriteFiltersForApi(filters),
827
+ ...projectionToQuery(select),
828
+ projectId: this.options.projectId,
829
+ state: (_a = args.state) != null ? _a : CANVAS_PUBLISHED_STATE,
830
+ diagnostics: this.coerceDiagnostics(diagnostics)
831
+ },
832
+ this.edgeApiHost
833
+ );
834
+ return this.apiClient(url, this.edgeRequestInit);
835
+ }
836
+ };
1267
837
  var _contentTypesUrl;
1268
838
  var _entriesUrl;
1269
- var _ContentClient = class _ContentClient2 extends ApiClient {
839
+ var _ContentClient = class _ContentClient2 extends ApiClient4 {
1270
840
  constructor(options) {
1271
841
  var _a;
1272
842
  super(options);
@@ -1274,16 +844,16 @@ var _ContentClient = class _ContentClient2 extends ApiClient {
1274
844
  }
1275
845
  getContentTypes(options) {
1276
846
  const { projectId } = this.options;
1277
- const fetchUri = this.createUrl(__privateGet3(_ContentClient2, _contentTypesUrl), { ...options, projectId });
847
+ const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _contentTypesUrl), { ...options, projectId });
1278
848
  return this.apiClient(fetchUri);
1279
849
  }
1280
850
  getEntries(options) {
1281
851
  const { projectId } = this.options;
1282
852
  const { skipDataResolution, filters, select, ...params } = options;
1283
- const rewrittenFilters = rewriteFiltersForApi(filters);
853
+ const rewrittenFilters = rewriteFiltersForApi6(filters);
1284
854
  const rewrittenSelect = projectionToQuery(select);
1285
855
  if (skipDataResolution) {
1286
- const url = this.createUrl(__privateGet3(_ContentClient2, _entriesUrl), {
856
+ const url = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl), {
1287
857
  ...params,
1288
858
  ...rewrittenFilters,
1289
859
  ...rewrittenSelect,
@@ -1292,7 +862,7 @@ var _ContentClient = class _ContentClient2 extends ApiClient {
1292
862
  return this.apiClient(url);
1293
863
  }
1294
864
  const edgeUrl = this.createUrl(
1295
- __privateGet3(_ContentClient2, _entriesUrl),
865
+ __privateGet2(_ContentClient2, _entriesUrl),
1296
866
  { ...this.getEdgeOptions(params), ...rewrittenFilters, ...rewrittenSelect },
1297
867
  this.edgeApiHost
1298
868
  );
@@ -1310,7 +880,7 @@ var _ContentClient = class _ContentClient2 extends ApiClient {
1310
880
  return this.apiClient(historyUrl);
1311
881
  }
1312
882
  async upsertContentType(body, opts = {}) {
1313
- const fetchUri = this.createUrl(__privateGet3(_ContentClient2, _contentTypesUrl));
883
+ const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _contentTypesUrl));
1314
884
  if (typeof body.contentType.slugSettings === "object" && body.contentType.slugSettings !== null && Object.keys(body.contentType.slugSettings).length === 0) {
1315
885
  delete body.contentType.slugSettings;
1316
886
  }
@@ -1322,7 +892,7 @@ var _ContentClient = class _ContentClient2 extends ApiClient {
1322
892
  });
1323
893
  }
1324
894
  async upsertEntry(body, options) {
1325
- const fetchUri = this.createUrl(__privateGet3(_ContentClient2, _entriesUrl));
895
+ const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl));
1326
896
  const headers = {};
1327
897
  if (options == null ? void 0 : options.ifUnmodifiedSince) {
1328
898
  headers["x-if-unmodified-since"] = options.ifUnmodifiedSince;
@@ -1336,7 +906,7 @@ var _ContentClient = class _ContentClient2 extends ApiClient {
1336
906
  return { modified: response.headers.get("x-modified-at") };
1337
907
  }
1338
908
  async deleteContentType(body) {
1339
- const fetchUri = this.createUrl(__privateGet3(_ContentClient2, _contentTypesUrl));
909
+ const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _contentTypesUrl));
1340
910
  await this.apiClient(fetchUri, {
1341
911
  method: "DELETE",
1342
912
  body: JSON.stringify({ ...body, projectId: this.options.projectId }),
@@ -1344,7 +914,7 @@ var _ContentClient = class _ContentClient2 extends ApiClient {
1344
914
  });
1345
915
  }
1346
916
  async deleteEntry(body) {
1347
- const fetchUri = this.createUrl(__privateGet3(_ContentClient2, _entriesUrl));
917
+ const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl));
1348
918
  await this.apiClient(fetchUri, {
1349
919
  method: "DELETE",
1350
920
  body: JSON.stringify({ ...body, projectId: this.options.projectId }),
@@ -1363,17 +933,17 @@ var _ContentClient = class _ContentClient2 extends ApiClient {
1363
933
  };
1364
934
  _contentTypesUrl = /* @__PURE__ */ new WeakMap();
1365
935
  _entriesUrl = /* @__PURE__ */ new WeakMap();
1366
- __privateAdd3(_ContentClient, _contentTypesUrl, "/api/v1/content-types");
1367
- __privateAdd3(_ContentClient, _entriesUrl, "/api/v1/entries");
1368
- var _url8;
1369
- var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
936
+ __privateAdd2(_ContentClient, _contentTypesUrl, "/api/v1/content-types");
937
+ __privateAdd2(_ContentClient, _entriesUrl, "/api/v1/entries");
938
+ var _url;
939
+ var _DataTypeClient = class _DataTypeClient2 extends ApiClient6 {
1370
940
  constructor(options) {
1371
941
  super(options);
1372
942
  }
1373
943
  /** Fetches a list of DataTypes for a project */
1374
944
  async list(options) {
1375
945
  const { projectId } = this.options;
1376
- const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8), { ...options, projectId });
946
+ const fetchUri = this.createUrl(__privateGet2(_DataTypeClient2, _url), { ...options, projectId });
1377
947
  return await this.apiClient(fetchUri);
1378
948
  }
1379
949
  /** @deprecated Use {@link list} instead. */
@@ -1382,7 +952,7 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1382
952
  }
1383
953
  /** Updates or creates (based on id) a DataType */
1384
954
  async save(body) {
1385
- const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
955
+ const fetchUri = this.createUrl(__privateGet2(_DataTypeClient2, _url));
1386
956
  await this.apiClient(fetchUri, {
1387
957
  method: "PUT",
1388
958
  body: JSON.stringify({ ...body, projectId: this.options.projectId }),
@@ -1395,7 +965,7 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1395
965
  }
1396
966
  /** Deletes a DataType */
1397
967
  async remove(body) {
1398
- const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
968
+ const fetchUri = this.createUrl(__privateGet2(_DataTypeClient2, _url));
1399
969
  await this.apiClient(fetchUri, {
1400
970
  method: "DELETE",
1401
971
  body: JSON.stringify({ ...body, projectId: this.options.projectId }),
@@ -1403,10 +973,10 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1403
973
  });
1404
974
  }
1405
975
  };
1406
- _url8 = /* @__PURE__ */ new WeakMap();
1407
- __privateAdd3(_DataTypeClient, _url8, "/api/v1/data-types");
976
+ _url = /* @__PURE__ */ new WeakMap();
977
+ __privateAdd2(_DataTypeClient, _url, "/api/v1/data-types");
1408
978
  var _baseUrl;
1409
- var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2 extends ApiClient {
979
+ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2 extends ApiClient8 {
1410
980
  constructor(options) {
1411
981
  super(options);
1412
982
  this.teamId = options.teamId;
@@ -1415,7 +985,7 @@ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2
1415
985
  * Gets a list of property type and hook names for the current team, including public integrations' hooks.
1416
986
  */
1417
987
  get(options) {
1418
- const fetchUri = this.createUrl(__privateGet3(_IntegrationPropertyEditorsClient2, _baseUrl), {
988
+ const fetchUri = this.createUrl(__privateGet2(_IntegrationPropertyEditorsClient2, _baseUrl), {
1419
989
  ...options,
1420
990
  teamId: this.teamId
1421
991
  });
@@ -1425,7 +995,7 @@ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2
1425
995
  * Creates or updates a custom AI property editor on a Mesh app.
1426
996
  */
1427
997
  async deploy(body) {
1428
- const fetchUri = this.createUrl(__privateGet3(_IntegrationPropertyEditorsClient2, _baseUrl));
998
+ const fetchUri = this.createUrl(__privateGet2(_IntegrationPropertyEditorsClient2, _baseUrl));
1429
999
  await this.apiClient(fetchUri, {
1430
1000
  method: "PUT",
1431
1001
  body: JSON.stringify({ ...body, teamId: this.teamId }),
@@ -1436,7 +1006,7 @@ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2
1436
1006
  * Removes a custom AI property editor from a Mesh app.
1437
1007
  */
1438
1008
  async delete(body) {
1439
- const fetchUri = this.createUrl(__privateGet3(_IntegrationPropertyEditorsClient2, _baseUrl));
1009
+ const fetchUri = this.createUrl(__privateGet2(_IntegrationPropertyEditorsClient2, _baseUrl));
1440
1010
  await this.apiClient(fetchUri, {
1441
1011
  method: "DELETE",
1442
1012
  body: JSON.stringify({ ...body, teamId: this.teamId }),
@@ -1445,16 +1015,16 @@ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2
1445
1015
  }
1446
1016
  };
1447
1017
  _baseUrl = /* @__PURE__ */ new WeakMap();
1448
- __privateAdd3(_IntegrationPropertyEditorsClient, _baseUrl, "/api/v1/integration-property-editors");
1449
- var _url22;
1018
+ __privateAdd2(_IntegrationPropertyEditorsClient, _baseUrl, "/api/v1/integration-property-editors");
1019
+ var _url2;
1450
1020
  var _projectsUrl;
1451
- var _ProjectClient = class _ProjectClient2 extends ApiClient {
1021
+ var _ProjectClient = class _ProjectClient2 extends ApiClient12 {
1452
1022
  constructor(options) {
1453
1023
  super({ ...options, bypassCache: true });
1454
1024
  }
1455
1025
  /** Fetches single Project */
1456
1026
  async get(options) {
1457
- const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22), { ...options });
1027
+ const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _url2), { ...options });
1458
1028
  return await this.apiClient(fetchUri);
1459
1029
  }
1460
1030
  /**
@@ -1463,7 +1033,7 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
1463
1033
  * When omitted, returns all accessible teams and their projects.
1464
1034
  */
1465
1035
  async list(options) {
1466
- const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
1036
+ const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
1467
1037
  return await this.apiClient(fetchUri);
1468
1038
  }
1469
1039
  /** @deprecated Use {@link list} instead. */
@@ -1472,7 +1042,7 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
1472
1042
  }
1473
1043
  /** Updates or creates (based on id) a Project */
1474
1044
  async save(body) {
1475
- const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
1045
+ const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _url2));
1476
1046
  return await this.apiClient(fetchUri, {
1477
1047
  method: "PUT",
1478
1048
  body: JSON.stringify({ ...body })
@@ -1484,7 +1054,7 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
1484
1054
  }
1485
1055
  /** Deletes a Project */
1486
1056
  async remove(body) {
1487
- const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
1057
+ const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _url2));
1488
1058
  await this.apiClient(fetchUri, {
1489
1059
  method: "DELETE",
1490
1060
  body: JSON.stringify({ ...body }),
@@ -1496,12 +1066,12 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
1496
1066
  return this.remove(body);
1497
1067
  }
1498
1068
  };
1499
- _url22 = /* @__PURE__ */ new WeakMap();
1069
+ _url2 = /* @__PURE__ */ new WeakMap();
1500
1070
  _projectsUrl = /* @__PURE__ */ new WeakMap();
1501
- __privateAdd3(_ProjectClient, _url22, "/api/v1/project");
1502
- __privateAdd3(_ProjectClient, _projectsUrl, "/api/v1/projects");
1071
+ __privateAdd2(_ProjectClient, _url2, "/api/v1/project");
1072
+ __privateAdd2(_ProjectClient, _projectsUrl, "/api/v1/projects");
1503
1073
  var ROUTE_URL = "/api/v1/route";
1504
- var RouteClient = class extends ApiClient {
1074
+ var RouteClient = class extends ApiClient17 {
1505
1075
  constructor(options) {
1506
1076
  var _a;
1507
1077
  if (!options.limitPolicy) {
@@ -1544,10 +1114,38 @@ var getDataSourceVariantFromRouteGetParams = (params, defaultPreviewState) => {
1544
1114
  return dataSourceVariant;
1545
1115
  };
1546
1116
 
1547
- // src/data/client.ts
1548
- import { getCache, waitUntil } from "@vercel/functions";
1117
+ // src/cache.ts
1118
+ import { cacheTag } from "next/cache";
1119
+
1120
+ // src/utils/tag.ts
1121
+ var encodePathForTag = (path) => path.split("/").map((segment) => /[^\x00-\x7F]/.test(segment) ? encodeURIComponent(segment) : segment).join("/");
1122
+ var buildPathTag = (path) => {
1123
+ const actualPath = path.startsWith("/") ? path : `/${path}`;
1124
+ return `path:${encodePathForTag(actualPath)}`.toLowerCase();
1125
+ };
1126
+ var buildCompositionTag = (compositionId) => {
1127
+ return `composition:${compositionId}`.toLowerCase();
1128
+ };
1129
+ var buildCompositionSlugTag = (slug) => {
1130
+ return `composition-slug:${encodePathForTag(slug)}`.toLowerCase();
1131
+ };
1549
1132
 
1550
- // src/clients/manifest.ts
1133
+ // src/clients/tags.ts
1134
+ var generateRouteCacheTags = ({ path }) => {
1135
+ const tags = ["route"];
1136
+ if (path) {
1137
+ const pathWithoutQuery = path.split("?")[0];
1138
+ const pieces = pathWithoutQuery.split("/");
1139
+ for (let i = 0; i < pieces.length; i++) {
1140
+ const segmentPieces = pieces.slice(0, i + 1);
1141
+ const segment = segmentPieces.join("/");
1142
+ tags.push(buildPathTag(segment));
1143
+ }
1144
+ }
1145
+ return tags;
1146
+ };
1147
+
1148
+ // src/clients/canvas.ts
1551
1149
  import "server-only";
1552
1150
 
1553
1151
  // src/utils/env.ts
@@ -1600,11 +1198,6 @@ var isStateCacheMode = (options) => {
1600
1198
  var isDetectCacheMode = (options) => {
1601
1199
  return "searchParams" in options && "draftModeEnabled" in options;
1602
1200
  };
1603
- var resolveManifestCache = (options) => {
1604
- return resolveCache({
1605
- options
1606
- });
1607
- };
1608
1201
  var resolveCanvasCache = (options) => {
1609
1202
  return resolveCache({
1610
1203
  options
@@ -1672,6 +1265,7 @@ var determineFetchCacheOptions = (mode) => {
1672
1265
  };
1673
1266
 
1674
1267
  // src/clients/retry.ts
1268
+ import { ApiClientError as ApiClientError6 } from "@uniformdev/context/api";
1675
1269
  function createThrottler(limit, interval) {
1676
1270
  let available = limit;
1677
1271
  let refillScheduled = false;
@@ -1782,7 +1376,7 @@ function createLimitPolicy2({
1782
1376
  if (retryOptions.onFailedAttempt) {
1783
1377
  await retryOptions.onFailedAttempt(error);
1784
1378
  }
1785
- if (error instanceof ApiClientError && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
1379
+ if (error instanceof ApiClientError6 && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
1786
1380
  throw error;
1787
1381
  }
1788
1382
  }
@@ -1792,67 +1386,66 @@ function createLimitPolicy2({
1792
1386
  };
1793
1387
  }
1794
1388
 
1795
- // src/utils/tag.ts
1796
- var buildPathTag = (path) => {
1797
- const actualPath = path.startsWith("/") ? path : `/${path}`;
1798
- return `path:${actualPath}`.toLowerCase();
1799
- };
1800
-
1801
- // src/clients/tags.ts
1802
- var generateRouteCacheTags = ({ path, old }) => {
1803
- const tags = old ? ["route-old"] : ["route"];
1804
- if (path) {
1805
- const pathWithoutQuery = path.split("?")[0];
1806
- const pieces = pathWithoutQuery.split("/");
1807
- for (let i = 0; i < pieces.length; i++) {
1808
- const segmentPieces = pieces.slice(0, i + 1);
1809
- const segment = segmentPieces.join("/");
1810
- tags.push(buildPathTag(segment));
1811
- }
1812
- }
1813
- return tags;
1814
- };
1815
- var generateManifestCacheTags = () => {
1816
- return ["manifest"];
1817
- };
1818
-
1819
- // src/clients/manifest.ts
1820
- var getManifestClient = (options) => {
1821
- const cache = resolveManifestCache(options);
1822
- const manifestClient = new ManifestClient({
1389
+ // src/clients/canvas.ts
1390
+ var buildCanvasClientOptions = (options) => {
1391
+ const cache = resolveCanvasCache(options);
1392
+ return {
1393
+ projectId: env.getProjectId(),
1823
1394
  apiHost: env.getApiHost(),
1824
1395
  apiKey: env.getApiKey(),
1825
- projectId: env.getProjectId(),
1396
+ edgeApiHost: env.getEdgeApiHost(),
1397
+ disableSWR: typeof cache.disableSWR !== "undefined" ? cache.disableSWR : true,
1826
1398
  limitPolicy: createLimitPolicy2({
1827
1399
  limit: 6
1828
1400
  }),
1829
1401
  fetch: (req, init) => {
1402
+ let requestedUrl;
1403
+ if (typeof req === "string") {
1404
+ requestedUrl = new URL(req);
1405
+ } else if (req instanceof URL) {
1406
+ requestedUrl = req;
1407
+ } else {
1408
+ requestedUrl = new URL(req.url);
1409
+ }
1410
+ const tags = [];
1411
+ if (requestedUrl) {
1412
+ const compositionIdKey = "compositionId";
1413
+ const compositionIdsKey = "compositionIDs";
1414
+ const slugKey = "slug";
1415
+ const compositionId = requestedUrl.searchParams.get(compositionIdKey);
1416
+ const compositionIds = requestedUrl.searchParams.get(compositionIdsKey);
1417
+ const slug = requestedUrl.searchParams.get(slugKey);
1418
+ if (compositionId) {
1419
+ tags.push(buildCompositionTag(compositionId));
1420
+ }
1421
+ if (slug) {
1422
+ tags.push(buildCompositionSlugTag(slug));
1423
+ }
1424
+ if (compositionIds) {
1425
+ const ids = compositionIds.split(",");
1426
+ for (let i = 0; i < ids.length; i++) {
1427
+ tags.push(buildCompositionTag(ids[i]));
1428
+ }
1429
+ }
1430
+ }
1830
1431
  const { cache: fetchCache, revalidate } = determineFetchCacheOptions(cache);
1831
1432
  return fetch(req, {
1832
1433
  ...init,
1434
+ cache: fetchCache,
1833
1435
  headers: {
1834
1436
  ...init == null ? void 0 : init.headers,
1835
1437
  "x-bypass-cache": typeof cache.bypassCache !== "undefined" ? cache.bypassCache.toString() : "false"
1836
1438
  },
1837
- cache: fetchCache,
1838
1439
  next: {
1839
1440
  revalidate,
1840
- tags: generateManifestCacheTags()
1441
+ tags: tags.length ? tags : void 0
1841
1442
  }
1842
1443
  });
1843
1444
  }
1844
- });
1845
- return manifestClient;
1445
+ };
1846
1446
  };
1847
- var getManifest = async (options) => {
1848
- let preview = false;
1849
- if (options && isStateCacheMode(options)) {
1850
- preview = options.state === CANVAS_DRAFT_STATE || options.state === CANVAS_EDITOR_STATE;
1851
- }
1852
- const manifestClient = getManifestClient(options);
1853
- return manifestClient.get({
1854
- preview
1855
- });
1447
+ var getCompositionDeliveryClient = (options) => {
1448
+ return new CompositionDeliveryClient(buildCanvasClientOptions(options));
1856
1449
  };
1857
1450
 
1858
1451
  // src/clients/route.ts
@@ -1906,217 +1499,185 @@ var getRouteClient = (options) => {
1906
1499
  return client;
1907
1500
  };
1908
1501
 
1909
- // src/config/helpers.ts
1910
- import config from "@uniformdev/next-app-router/config/resolved";
1911
- var getMiddlewareRuntimeCache = () => {
1912
- if (process.env.NODE_ENV === "development" && !process.env.RUNTIME_CACHE_ENDPOINT) {
1913
- return false;
1914
- }
1915
- if (typeof config.middlewareRuntimeCache === "boolean") {
1916
- return config.middlewareRuntimeCache;
1917
- }
1918
- return true;
1919
- };
1920
- var getDisableSwrMiddlewareCache = () => {
1921
- var _a;
1922
- if (typeof ((_a = config.experimental) == null ? void 0 : _a.disableSwrMiddlewareCache) === "boolean") {
1923
- return config.experimental.disableSwrMiddlewareCache;
1924
- }
1925
- return false;
1926
- };
1927
-
1928
1502
  // src/data/client.ts
1929
- var MANIFEST_CACHE_KEY = "uniform-manifest";
1930
- var DefaultDataClient = class {
1931
- async getManifest(options) {
1932
- const cache = options.source === "middleware" && getMiddlewareRuntimeCache() ? getCache() : null;
1933
- if (cache) {
1934
- const cachedManifest = await cache.get(MANIFEST_CACHE_KEY);
1935
- if (cachedManifest) {
1936
- return cachedManifest;
1937
- }
1938
- }
1939
- const manifest = await getManifest({
1940
- cache: isDevelopmentEnvironment() ? {
1941
- type: "no-cache",
1942
- bypassCache: true
1943
- } : {
1944
- type: "force-cache"
1945
- }
1946
- });
1947
- if (cache) {
1948
- waitUntil(
1949
- (async () => {
1950
- await cache.set(MANIFEST_CACHE_KEY, manifest, {
1951
- tags: generateManifestCacheTags()
1952
- });
1953
- })()
1954
- );
1955
- }
1956
- return manifest;
1503
+ var DataClient = class {
1504
+ constructor({ fetchCache = true } = {}) {
1505
+ this.fetchCache = fetchCache;
1506
+ }
1507
+ async getRoute({ pageState }) {
1508
+ const routeClient = getRouteClient({ cache: this.resolveCache(pageState) });
1509
+ const parameters = {
1510
+ path: pageState.routePath,
1511
+ state: pageState.compositionState,
1512
+ dataSourceVariant: getDataSourceVariantFromRouteGetParams({}, pageState.compositionState),
1513
+ withComponentIDs: true,
1514
+ releaseId: pageState.releaseId,
1515
+ locale: pageState.locale,
1516
+ ignoreRedirects: shouldIgnoreRedirects({ state: pageState.compositionState })
1517
+ };
1518
+ return routeClient.get(parameters);
1957
1519
  }
1958
- async getRouteFromApi({
1959
- route,
1960
- routeClient,
1961
- enableRuntimeCache,
1962
- disableSwrCache
1520
+ /** Returns `null` when no composition matches the selector in the page state's composition state. */
1521
+ async getComposition({
1522
+ pageState,
1523
+ selector
1963
1524
  }) {
1964
- const newCacheKey = `uniform-route-${route.state}-${route.releaseId}-${route.path}`;
1965
- const oldCacheKey = `uniform-route-old-${route.state}-${route.releaseId}-${route.path}`;
1966
- const cache = enableRuntimeCache ? getCache() : null;
1967
- const cacheNewRoute = async (result2) => {
1968
- if (cache && result2.type === "composition") {
1969
- const tags = generateRouteCacheTags({ path: route.path });
1970
- await cache.set(newCacheKey, result2, {
1971
- tags
1972
- });
1973
- }
1974
- };
1975
- const cacheOldRoute = async (result2) => {
1976
- if (cache && result2.type === "composition" && !disableSwrCache) {
1977
- const tags = generateRouteCacheTags({ path: route.path, old: true });
1978
- await cache.set(oldCacheKey, result2, {
1979
- tags
1980
- });
1981
- }
1982
- };
1983
- if (cache) {
1984
- const [cachedRoute, oldCachedRoute] = await Promise.all([
1985
- cache.get(newCacheKey),
1986
- disableSwrCache ? null : cache.get(oldCacheKey)
1987
- ]);
1988
- if (cachedRoute) {
1989
- return cachedRoute;
1990
- }
1991
- if (oldCachedRoute) {
1992
- waitUntil(
1993
- (async () => {
1994
- const result2 = await routeClient.get(route);
1995
- await cacheNewRoute(result2);
1996
- })()
1997
- );
1998
- return oldCachedRoute;
1525
+ const client = getCompositionDeliveryClient({ cache: this.resolveCache(pageState) });
1526
+ try {
1527
+ return await client.get({
1528
+ ...selector,
1529
+ state: pageState.compositionState,
1530
+ withComponentIDs: true,
1531
+ releaseId: pageState.releaseId,
1532
+ locale: pageState.locale
1533
+ });
1534
+ } catch (e) {
1535
+ if (e instanceof ApiClientError5 && e.statusCode === 404) {
1536
+ return null;
1999
1537
  }
1538
+ throw e;
2000
1539
  }
2001
- const result = await routeClient.get(route);
2002
- waitUntil(
2003
- (async () => {
2004
- await Promise.all([
2005
- cacheNewRoute(result),
2006
- disableSwrCache ? Promise.resolve() : cacheOldRoute(result)
2007
- ]);
2008
- })()
2009
- );
2010
- return result;
2011
1540
  }
2012
- async getRoute(options) {
2013
- if (options.source === "middleware") {
2014
- return this.getRouteMiddleware(options);
1541
+ resolveCache(pageState) {
1542
+ if (pageState.compositionState !== CANVAS_PUBLISHED_STATE || isDevelopmentEnvironment()) {
1543
+ return { type: "no-cache", bypassCache: true };
2015
1544
  }
2016
- return this.getRoutePageState(options);
2017
- }
2018
- async enhanceRoute(_options) {
1545
+ return this.fetchCache ? { type: "force-cache" } : { type: "no-cache" };
2019
1546
  }
2020
- async getRouteMiddleware(options) {
2021
- const routeClient = getRouteClient({
2022
- searchParams: options.searchParams,
2023
- draftModeEnabled: options.draftModeEnabled
2024
- });
2025
- const resolvedRoute = await this.getRouteFromApi({
2026
- source: "middleware",
2027
- route: options.route,
2028
- routeClient,
2029
- // The runtime cache is keyed on the route path. Development bypasses it so an author sees
2030
- // an edit right away, the same way the fetch cache is bypassed for development.
2031
- enableRuntimeCache: options.route.state === CANVAS_PUBLISHED_STATE && getMiddlewareRuntimeCache() && !isDevelopmentEnvironment(),
2032
- disableSwrCache: getDisableSwrMiddlewareCache()
2033
- });
2034
- if (resolvedRoute.type === "composition") {
2035
- await this.enhanceRoute({
2036
- source: "middleware",
2037
- parameters: options.route,
2038
- route: resolvedRoute,
2039
- routeClient,
2040
- keys: void 0
1547
+ };
1548
+
1549
+ // src/data/deserializePageState.ts
1550
+ import { deserializeEvaluationResult } from "@uniformdev/next-app-router-shared";
1551
+ var deserializePageState = ({ code }) => deserializeEvaluationResult({ input: code });
1552
+
1553
+ // src/data/pageStateFromSource.ts
1554
+ var pageStateFromSource = (source) => {
1555
+ var _a;
1556
+ return (_a = source.pageState) != null ? _a : deserializePageState({ code: source.code });
1557
+ };
1558
+
1559
+ // src/data/resolveCompositionForPageState.ts
1560
+ var resolveCompositionForPageState = async ({
1561
+ pageState,
1562
+ selector,
1563
+ matchedRoute,
1564
+ dataClient = new DataClient()
1565
+ }) => {
1566
+ const states = pageState.compositionState === CANVAS_EDITOR_STATE ? [CANVAS_EDITOR_STATE, CANVAS_DRAFT_STATE] : [pageState.compositionState];
1567
+ let composition = null;
1568
+ for (const state of states) {
1569
+ try {
1570
+ composition = await dataClient.getComposition({
1571
+ pageState: { ...pageState, compositionState: state },
1572
+ selector
2041
1573
  });
1574
+ } catch (e) {
1575
+ console.warn(`Failed to get composition ${JSON.stringify(selector)} with state ${state}`, e);
2042
1576
  }
2043
- return {
2044
- route: resolvedRoute
2045
- };
2046
- }
2047
- async getRoutePageState(options) {
2048
- const shouldBypassCache = options.pageState.compositionState !== CANVAS_PUBLISHED_STATE || isDevelopmentEnvironment();
2049
- const routeClient = getRouteClient({
2050
- cache: shouldBypassCache ? {
2051
- type: "no-cache",
2052
- bypassCache: true
2053
- } : {
2054
- type: "force-cache"
2055
- }
2056
- });
2057
- const originalRoute = {
2058
- path: options.pageState.routePath,
2059
- state: options.pageState.compositionState,
2060
- dataSourceVariant: getDataSourceVariantFromRouteGetParams({}, options.pageState.compositionState),
2061
- withComponentIDs: true,
2062
- releaseId: options.pageState.releaseId,
2063
- locale: options.pageState.locale,
2064
- ignoreRedirects: shouldIgnoreRedirects({ state: options.pageState.compositionState })
2065
- };
2066
- const resolvedRoute = await this.getRouteFromApi({
2067
- source: "pageState",
2068
- route: originalRoute,
2069
- routeClient,
2070
- enableRuntimeCache: false,
2071
- disableSwrCache: false
2072
- });
2073
- if (resolvedRoute.type === "composition") {
2074
- await this.enhanceRoute({
2075
- source: "pageState",
2076
- parameters: originalRoute,
2077
- route: resolvedRoute,
2078
- routeClient,
2079
- keys: options.pageState.keys
2080
- });
1577
+ if (composition) {
1578
+ break;
2081
1579
  }
2082
- return {
2083
- route: resolvedRoute
2084
- };
2085
1580
  }
1581
+ if (!composition) {
1582
+ return { pageState, route: void 0 };
1583
+ }
1584
+ return {
1585
+ pageState: { ...pageState, compositionState: composition.state },
1586
+ route: {
1587
+ type: "composition",
1588
+ compositionApiResponse: composition,
1589
+ matchedRoute
1590
+ }
1591
+ };
2086
1592
  };
2087
1593
 
2088
- // src/data/resolveRouteFromCode.ts
2089
- var resolveRouteFromCode = async ({
2090
- code,
2091
- dataClient: providedDataClient
1594
+ // src/data/resolveRouteForPageState.ts
1595
+ var resolveRouteForPageState = async ({
1596
+ pageState: providedPageState,
1597
+ dataClient = new DataClient()
2092
1598
  }) => {
2093
- const pageState = deserializeEvaluationResult({ input: code });
2094
- const dataClient = providedDataClient != null ? providedDataClient : new DefaultDataClient();
2095
- const { route } = await dataClient.getRoute({
2096
- source: "pageState",
2097
- pageState
2098
- });
2099
- return {
2100
- pageState,
2101
- // suppress the route if it's not a composition
2102
- route: (route == null ? void 0 : route.type) === "composition" ? route : void 0,
2103
- // the code that was used to resolve the route
2104
- code
2105
- };
1599
+ var _a, _b;
1600
+ const states = providedPageState.compositionState === CANVAS_EDITOR_STATE ? [CANVAS_EDITOR_STATE, CANVAS_DRAFT_STATE] : [providedPageState.compositionState];
1601
+ let pageState = providedPageState;
1602
+ let route = null;
1603
+ for (const state of states) {
1604
+ pageState = { ...providedPageState, compositionState: state };
1605
+ try {
1606
+ route = await dataClient.getRoute({ pageState });
1607
+ } catch (e) {
1608
+ console.warn(`Failed to retrieve route by path: ${pageState.routePath} with state ${state}`, e);
1609
+ }
1610
+ if (route && route.type !== "notFound") {
1611
+ break;
1612
+ }
1613
+ }
1614
+ if ((route == null ? void 0 : route.type) === "composition") {
1615
+ return { pageState: { ...pageState, locale: (_b = pageState.locale) != null ? _b : (_a = route.dynamicInputs) == null ? void 0 : _a.locale }, route };
1616
+ }
1617
+ if ((route == null ? void 0 : route.type) === "redirect") {
1618
+ return { pageState, route };
1619
+ }
1620
+ return { pageState, route: void 0 };
2106
1621
  };
2107
1622
 
2108
1623
  // src/cache.ts
2109
- var resolveRouteFromCode2 = async ({
2110
- code,
2111
- dataClient: providedDataClient
2112
- }) => {
2113
- "use cache";
2114
- const result = await resolveRouteFromCode({
2115
- code,
2116
- dataClient: providedDataClient
2117
- });
1624
+ var tagScope = (result, requestedTags) => {
1625
+ var _a;
1626
+ const tags = [...requestedTags];
1627
+ if (((_a = result.route) == null ? void 0 : _a.type) === "composition") {
1628
+ tags.push(buildCompositionTag(result.route.compositionApiResponse.composition._id));
1629
+ }
1630
+ cacheTag(...tags);
2118
1631
  return result;
2119
1632
  };
1633
+ var createScopeDataClient = () => new DataClient({ fetchCache: false });
1634
+ var isPublished = (pageState) => pageState.compositionState === CANVAS_PUBLISHED_STATE;
1635
+ var resolveRouteCached = async (pageState) => {
1636
+ "use cache";
1637
+ return tagScope(
1638
+ await resolveRouteForPageState({ pageState, dataClient: createScopeDataClient() }),
1639
+ generateRouteCacheTags({ path: pageState.routePath })
1640
+ );
1641
+ };
1642
+ var resolveCompositionCached = async (pageState, selector, matchedRoute) => {
1643
+ "use cache";
1644
+ return tagScope(
1645
+ await resolveCompositionForPageState({
1646
+ pageState,
1647
+ selector,
1648
+ matchedRoute,
1649
+ dataClient: createScopeDataClient()
1650
+ }),
1651
+ [
1652
+ "compositionId" in selector ? buildCompositionTag(selector.compositionId) : buildCompositionSlugTag(selector.slug)
1653
+ ]
1654
+ );
1655
+ };
1656
+ var resolveRoute = (pageState) => isPublished(pageState) ? resolveRouteCached(pageState) : resolveRouteForPageState({ pageState });
1657
+ var resolveComposition = (pageState, selector, matchedRoute) => {
1658
+ const route = matchedRoute != null ? matchedRoute : pageState.routePath;
1659
+ return isPublished(pageState) ? resolveCompositionCached(pageState, selector, route) : resolveCompositionForPageState({ pageState, selector, matchedRoute: route });
1660
+ };
1661
+ var resolveRouteFromCode = async ({
1662
+ code
1663
+ }) => resolveRoute(deserializePageState({ code }));
1664
+ var resolveRouteFromPath = async ({
1665
+ path,
1666
+ ...source
1667
+ }) => resolveRoute({ ...pageStateFromSource(source), routePath: path });
1668
+ var resolveCompositionById = async ({
1669
+ compositionId,
1670
+ matchedRoute,
1671
+ ...source
1672
+ }) => resolveComposition(pageStateFromSource(source), { compositionId }, matchedRoute);
1673
+ var resolveCompositionBySlug = async ({
1674
+ slug,
1675
+ matchedRoute,
1676
+ ...source
1677
+ }) => resolveComposition(pageStateFromSource(source), { slug }, matchedRoute);
2120
1678
  export {
2121
- resolveRouteFromCode2 as resolveRouteFromCode
1679
+ resolveCompositionById,
1680
+ resolveCompositionBySlug,
1681
+ resolveRouteFromCode,
1682
+ resolveRouteFromPath
2122
1683
  };