@uniformdev/next-app-router 20.81.1-alpha.4.sha-de16ebeee7 → 20.81.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cache.mjs CHANGED
@@ -41,6 +41,124 @@ 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
+
44
162
  // ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js
45
163
  var require_retry_operation = __commonJS({
46
164
  "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js"(exports, module) {
@@ -272,9 +390,436 @@ var require_retry2 = __commonJS({
272
390
  }
273
391
  });
274
392
 
275
- // ../canvas/dist/index.mjs
276
- import { ApiClient } from "@uniformdev/context/api";
277
- import { ApiClientError } from "@uniformdev/context/api";
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");
278
823
 
279
824
  // ../../node_modules/.pnpm/yocto-queue@1.2.2/node_modules/yocto-queue/index.js
280
825
  var Node = class {
@@ -347,7 +892,7 @@ _tail = new WeakMap();
347
892
  _size = new WeakMap();
348
893
 
349
894
  // ../../node_modules/.pnpm/p-limit@6.2.0/node_modules/p-limit/index.js
350
- function pLimit(concurrency) {
895
+ function pLimit2(concurrency) {
351
896
  validateConcurrency(concurrency);
352
897
  const queue = new Queue();
353
898
  let activeCount = 0;
@@ -627,44 +1172,19 @@ function pThrottle({ limit, interval, strict, onDelay }) {
627
1172
  }
628
1173
 
629
1174
  // ../canvas/dist/index.mjs
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) => {
1175
+ var __typeError3 = (msg) => {
656
1176
  throw TypeError(msg);
657
1177
  };
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);
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);
661
1181
  function createLimitPolicy({
662
1182
  throttle = { interval: 1e3, limit: 10 },
663
1183
  retry: retry3 = { retries: 1, factor: 1.66 },
664
1184
  limit = 10
665
1185
  }) {
666
1186
  const throttler = throttle ? pThrottle(throttle) : null;
667
- const limiter = limit ? pLimit(limit) : null;
1187
+ const limiter = limit ? pLimit2(limit) : null;
668
1188
  return function limitPolicy(func) {
669
1189
  let currentFunc = async () => await func();
670
1190
  if (throttler) {
@@ -746,7 +1266,7 @@ var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
746
1266
  var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
747
1267
  var _contentTypesUrl;
748
1268
  var _entriesUrl;
749
- var _ContentClient = class _ContentClient2 extends ApiClient4 {
1269
+ var _ContentClient = class _ContentClient2 extends ApiClient {
750
1270
  constructor(options) {
751
1271
  var _a;
752
1272
  super(options);
@@ -754,16 +1274,16 @@ var _ContentClient = class _ContentClient2 extends ApiClient4 {
754
1274
  }
755
1275
  getContentTypes(options) {
756
1276
  const { projectId } = this.options;
757
- const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _contentTypesUrl), { ...options, projectId });
1277
+ const fetchUri = this.createUrl(__privateGet3(_ContentClient2, _contentTypesUrl), { ...options, projectId });
758
1278
  return this.apiClient(fetchUri);
759
1279
  }
760
1280
  getEntries(options) {
761
1281
  const { projectId } = this.options;
762
1282
  const { skipDataResolution, filters, select, ...params } = options;
763
- const rewrittenFilters = rewriteFiltersForApi6(filters);
1283
+ const rewrittenFilters = rewriteFiltersForApi(filters);
764
1284
  const rewrittenSelect = projectionToQuery(select);
765
1285
  if (skipDataResolution) {
766
- const url = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl), {
1286
+ const url = this.createUrl(__privateGet3(_ContentClient2, _entriesUrl), {
767
1287
  ...params,
768
1288
  ...rewrittenFilters,
769
1289
  ...rewrittenSelect,
@@ -772,7 +1292,7 @@ var _ContentClient = class _ContentClient2 extends ApiClient4 {
772
1292
  return this.apiClient(url);
773
1293
  }
774
1294
  const edgeUrl = this.createUrl(
775
- __privateGet2(_ContentClient2, _entriesUrl),
1295
+ __privateGet3(_ContentClient2, _entriesUrl),
776
1296
  { ...this.getEdgeOptions(params), ...rewrittenFilters, ...rewrittenSelect },
777
1297
  this.edgeApiHost
778
1298
  );
@@ -790,7 +1310,7 @@ var _ContentClient = class _ContentClient2 extends ApiClient4 {
790
1310
  return this.apiClient(historyUrl);
791
1311
  }
792
1312
  async upsertContentType(body, opts = {}) {
793
- const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _contentTypesUrl));
1313
+ const fetchUri = this.createUrl(__privateGet3(_ContentClient2, _contentTypesUrl));
794
1314
  if (typeof body.contentType.slugSettings === "object" && body.contentType.slugSettings !== null && Object.keys(body.contentType.slugSettings).length === 0) {
795
1315
  delete body.contentType.slugSettings;
796
1316
  }
@@ -802,7 +1322,7 @@ var _ContentClient = class _ContentClient2 extends ApiClient4 {
802
1322
  });
803
1323
  }
804
1324
  async upsertEntry(body, options) {
805
- const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl));
1325
+ const fetchUri = this.createUrl(__privateGet3(_ContentClient2, _entriesUrl));
806
1326
  const headers = {};
807
1327
  if (options == null ? void 0 : options.ifUnmodifiedSince) {
808
1328
  headers["x-if-unmodified-since"] = options.ifUnmodifiedSince;
@@ -816,7 +1336,7 @@ var _ContentClient = class _ContentClient2 extends ApiClient4 {
816
1336
  return { modified: response.headers.get("x-modified-at") };
817
1337
  }
818
1338
  async deleteContentType(body) {
819
- const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _contentTypesUrl));
1339
+ const fetchUri = this.createUrl(__privateGet3(_ContentClient2, _contentTypesUrl));
820
1340
  await this.apiClient(fetchUri, {
821
1341
  method: "DELETE",
822
1342
  body: JSON.stringify({ ...body, projectId: this.options.projectId }),
@@ -824,7 +1344,7 @@ var _ContentClient = class _ContentClient2 extends ApiClient4 {
824
1344
  });
825
1345
  }
826
1346
  async deleteEntry(body) {
827
- const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl));
1347
+ const fetchUri = this.createUrl(__privateGet3(_ContentClient2, _entriesUrl));
828
1348
  await this.apiClient(fetchUri, {
829
1349
  method: "DELETE",
830
1350
  body: JSON.stringify({ ...body, projectId: this.options.projectId }),
@@ -843,17 +1363,17 @@ var _ContentClient = class _ContentClient2 extends ApiClient4 {
843
1363
  };
844
1364
  _contentTypesUrl = /* @__PURE__ */ new WeakMap();
845
1365
  _entriesUrl = /* @__PURE__ */ new WeakMap();
846
- __privateAdd2(_ContentClient, _contentTypesUrl, "/api/v1/content-types");
847
- __privateAdd2(_ContentClient, _entriesUrl, "/api/v1/entries");
848
- var _url;
849
- var _DataTypeClient = class _DataTypeClient2 extends ApiClient6 {
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 {
850
1370
  constructor(options) {
851
1371
  super(options);
852
1372
  }
853
1373
  /** Fetches a list of DataTypes for a project */
854
1374
  async list(options) {
855
1375
  const { projectId } = this.options;
856
- const fetchUri = this.createUrl(__privateGet2(_DataTypeClient2, _url), { ...options, projectId });
1376
+ const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8), { ...options, projectId });
857
1377
  return await this.apiClient(fetchUri);
858
1378
  }
859
1379
  /** @deprecated Use {@link list} instead. */
@@ -862,7 +1382,7 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient6 {
862
1382
  }
863
1383
  /** Updates or creates (based on id) a DataType */
864
1384
  async save(body) {
865
- const fetchUri = this.createUrl(__privateGet2(_DataTypeClient2, _url));
1385
+ const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
866
1386
  await this.apiClient(fetchUri, {
867
1387
  method: "PUT",
868
1388
  body: JSON.stringify({ ...body, projectId: this.options.projectId }),
@@ -875,7 +1395,7 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient6 {
875
1395
  }
876
1396
  /** Deletes a DataType */
877
1397
  async remove(body) {
878
- const fetchUri = this.createUrl(__privateGet2(_DataTypeClient2, _url));
1398
+ const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
879
1399
  await this.apiClient(fetchUri, {
880
1400
  method: "DELETE",
881
1401
  body: JSON.stringify({ ...body, projectId: this.options.projectId }),
@@ -883,10 +1403,10 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient6 {
883
1403
  });
884
1404
  }
885
1405
  };
886
- _url = /* @__PURE__ */ new WeakMap();
887
- __privateAdd2(_DataTypeClient, _url, "/api/v1/data-types");
1406
+ _url8 = /* @__PURE__ */ new WeakMap();
1407
+ __privateAdd3(_DataTypeClient, _url8, "/api/v1/data-types");
888
1408
  var _baseUrl;
889
- var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2 extends ApiClient8 {
1409
+ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2 extends ApiClient {
890
1410
  constructor(options) {
891
1411
  super(options);
892
1412
  this.teamId = options.teamId;
@@ -895,7 +1415,7 @@ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2
895
1415
  * Gets a list of property type and hook names for the current team, including public integrations' hooks.
896
1416
  */
897
1417
  get(options) {
898
- const fetchUri = this.createUrl(__privateGet2(_IntegrationPropertyEditorsClient2, _baseUrl), {
1418
+ const fetchUri = this.createUrl(__privateGet3(_IntegrationPropertyEditorsClient2, _baseUrl), {
899
1419
  ...options,
900
1420
  teamId: this.teamId
901
1421
  });
@@ -905,7 +1425,7 @@ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2
905
1425
  * Creates or updates a custom AI property editor on a Mesh app.
906
1426
  */
907
1427
  async deploy(body) {
908
- const fetchUri = this.createUrl(__privateGet2(_IntegrationPropertyEditorsClient2, _baseUrl));
1428
+ const fetchUri = this.createUrl(__privateGet3(_IntegrationPropertyEditorsClient2, _baseUrl));
909
1429
  await this.apiClient(fetchUri, {
910
1430
  method: "PUT",
911
1431
  body: JSON.stringify({ ...body, teamId: this.teamId }),
@@ -916,7 +1436,7 @@ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2
916
1436
  * Removes a custom AI property editor from a Mesh app.
917
1437
  */
918
1438
  async delete(body) {
919
- const fetchUri = this.createUrl(__privateGet2(_IntegrationPropertyEditorsClient2, _baseUrl));
1439
+ const fetchUri = this.createUrl(__privateGet3(_IntegrationPropertyEditorsClient2, _baseUrl));
920
1440
  await this.apiClient(fetchUri, {
921
1441
  method: "DELETE",
922
1442
  body: JSON.stringify({ ...body, teamId: this.teamId }),
@@ -925,16 +1445,16 @@ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2
925
1445
  }
926
1446
  };
927
1447
  _baseUrl = /* @__PURE__ */ new WeakMap();
928
- __privateAdd2(_IntegrationPropertyEditorsClient, _baseUrl, "/api/v1/integration-property-editors");
929
- var _url2;
1448
+ __privateAdd3(_IntegrationPropertyEditorsClient, _baseUrl, "/api/v1/integration-property-editors");
1449
+ var _url22;
930
1450
  var _projectsUrl;
931
- var _ProjectClient = class _ProjectClient2 extends ApiClient12 {
1451
+ var _ProjectClient = class _ProjectClient2 extends ApiClient {
932
1452
  constructor(options) {
933
1453
  super({ ...options, bypassCache: true });
934
1454
  }
935
1455
  /** Fetches single Project */
936
1456
  async get(options) {
937
- const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _url2), { ...options });
1457
+ const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22), { ...options });
938
1458
  return await this.apiClient(fetchUri);
939
1459
  }
940
1460
  /**
@@ -943,7 +1463,7 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient12 {
943
1463
  * When omitted, returns all accessible teams and their projects.
944
1464
  */
945
1465
  async list(options) {
946
- const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
1466
+ const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
947
1467
  return await this.apiClient(fetchUri);
948
1468
  }
949
1469
  /** @deprecated Use {@link list} instead. */
@@ -952,7 +1472,7 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient12 {
952
1472
  }
953
1473
  /** Updates or creates (based on id) a Project */
954
1474
  async save(body) {
955
- const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _url2));
1475
+ const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
956
1476
  return await this.apiClient(fetchUri, {
957
1477
  method: "PUT",
958
1478
  body: JSON.stringify({ ...body })
@@ -964,7 +1484,7 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient12 {
964
1484
  }
965
1485
  /** Deletes a Project */
966
1486
  async remove(body) {
967
- const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _url2));
1487
+ const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
968
1488
  await this.apiClient(fetchUri, {
969
1489
  method: "DELETE",
970
1490
  body: JSON.stringify({ ...body }),
@@ -976,12 +1496,12 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient12 {
976
1496
  return this.remove(body);
977
1497
  }
978
1498
  };
979
- _url2 = /* @__PURE__ */ new WeakMap();
1499
+ _url22 = /* @__PURE__ */ new WeakMap();
980
1500
  _projectsUrl = /* @__PURE__ */ new WeakMap();
981
- __privateAdd2(_ProjectClient, _url2, "/api/v1/project");
982
- __privateAdd2(_ProjectClient, _projectsUrl, "/api/v1/projects");
1501
+ __privateAdd3(_ProjectClient, _url22, "/api/v1/project");
1502
+ __privateAdd3(_ProjectClient, _projectsUrl, "/api/v1/projects");
983
1503
  var ROUTE_URL = "/api/v1/route";
984
- var RouteClient = class extends ApiClient17 {
1504
+ var RouteClient = class extends ApiClient {
985
1505
  constructor(options) {
986
1506
  var _a;
987
1507
  if (!options.limitPolicy) {
@@ -1024,12 +1544,10 @@ var getDataSourceVariantFromRouteGetParams = (params, defaultPreviewState) => {
1024
1544
  return dataSourceVariant;
1025
1545
  };
1026
1546
 
1027
- // src/data/resolveRouteFromCode.ts
1028
- import { deserializeEvaluationResult } from "@uniformdev/next-app-router-shared";
1029
- import { getTargetVariableExpandedUrl } from "@uniformdev/redirect";
1030
- import { permanentRedirect, redirect } from "next/navigation";
1547
+ // src/data/client.ts
1548
+ import { getCache, waitUntil } from "@vercel/functions";
1031
1549
 
1032
- // src/clients/route.ts
1550
+ // src/clients/manifest.ts
1033
1551
  import "server-only";
1034
1552
 
1035
1553
  // src/utils/env.ts
@@ -1082,6 +1600,11 @@ var isStateCacheMode = (options) => {
1082
1600
  var isDetectCacheMode = (options) => {
1083
1601
  return "searchParams" in options && "draftModeEnabled" in options;
1084
1602
  };
1603
+ var resolveManifestCache = (options) => {
1604
+ return resolveCache({
1605
+ options
1606
+ });
1607
+ };
1085
1608
  var resolveCanvasCache = (options) => {
1086
1609
  return resolveCache({
1087
1610
  options
@@ -1149,7 +1672,6 @@ var determineFetchCacheOptions = (mode) => {
1149
1672
  };
1150
1673
 
1151
1674
  // src/clients/retry.ts
1152
- import { ApiClientError as ApiClientError6 } from "@uniformdev/context/api";
1153
1675
  function createThrottler(limit, interval) {
1154
1676
  let available = limit;
1155
1677
  let refillScheduled = false;
@@ -1260,7 +1782,7 @@ function createLimitPolicy2({
1260
1782
  if (retryOptions.onFailedAttempt) {
1261
1783
  await retryOptions.onFailedAttempt(error);
1262
1784
  }
1263
- if (error instanceof ApiClientError6 && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
1785
+ if (error instanceof ApiClientError && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
1264
1786
  throw error;
1265
1787
  }
1266
1788
  }
@@ -1277,8 +1799,8 @@ var buildPathTag = (path) => {
1277
1799
  };
1278
1800
 
1279
1801
  // src/clients/tags.ts
1280
- var generateRouteCacheTags = ({ path }) => {
1281
- const tags = ["route"];
1802
+ var generateRouteCacheTags = ({ path, old }) => {
1803
+ const tags = old ? ["route-old"] : ["route"];
1282
1804
  if (path) {
1283
1805
  const pathWithoutQuery = path.split("?")[0];
1284
1806
  const pieces = pathWithoutQuery.split("/");
@@ -1290,8 +1812,51 @@ var generateRouteCacheTags = ({ path }) => {
1290
1812
  }
1291
1813
  return tags;
1292
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({
1823
+ apiHost: env.getApiHost(),
1824
+ apiKey: env.getApiKey(),
1825
+ projectId: env.getProjectId(),
1826
+ limitPolicy: createLimitPolicy2({
1827
+ limit: 6
1828
+ }),
1829
+ fetch: (req, init) => {
1830
+ const { cache: fetchCache, revalidate } = determineFetchCacheOptions(cache);
1831
+ return fetch(req, {
1832
+ ...init,
1833
+ headers: {
1834
+ ...init == null ? void 0 : init.headers,
1835
+ "x-bypass-cache": typeof cache.bypassCache !== "undefined" ? cache.bypassCache.toString() : "false"
1836
+ },
1837
+ cache: fetchCache,
1838
+ next: {
1839
+ revalidate,
1840
+ tags: generateManifestCacheTags()
1841
+ }
1842
+ });
1843
+ }
1844
+ });
1845
+ return manifestClient;
1846
+ };
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
+ });
1856
+ };
1293
1857
 
1294
1858
  // src/clients/route.ts
1859
+ import "server-only";
1295
1860
  var getRouteCacheTags = (requestedUrl) => {
1296
1861
  const tags = ["route"];
1297
1862
  if (requestedUrl) {
@@ -1341,10 +1906,146 @@ var getRouteClient = (options) => {
1341
1906
  return client;
1342
1907
  };
1343
1908
 
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
+
1344
1928
  // src/data/client.ts
1929
+ var MANIFEST_CACHE_KEY = "uniform-manifest";
1345
1930
  var DefaultDataClient = class {
1346
- async getRoute({ pageState }) {
1347
- const shouldBypassCache = pageState.compositionState !== CANVAS_PUBLISHED_STATE || isDevelopmentEnvironment();
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;
1957
+ }
1958
+ async getRouteFromApi({
1959
+ route,
1960
+ routeClient,
1961
+ enableRuntimeCache,
1962
+ disableSwrCache
1963
+ }) {
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;
1999
+ }
2000
+ }
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
+ }
2012
+ async getRoute(options) {
2013
+ if (options.source === "middleware") {
2014
+ return this.getRouteMiddleware(options);
2015
+ }
2016
+ return this.getRoutePageState(options);
2017
+ }
2018
+ async enhanceRoute(_options) {
2019
+ }
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
2041
+ });
2042
+ }
2043
+ return {
2044
+ route: resolvedRoute
2045
+ };
2046
+ }
2047
+ async getRoutePageState(options) {
2048
+ const shouldBypassCache = options.pageState.compositionState !== CANVAS_PUBLISHED_STATE || isDevelopmentEnvironment();
1348
2049
  const routeClient = getRouteClient({
1349
2050
  cache: shouldBypassCache ? {
1350
2051
  type: "no-cache",
@@ -1353,73 +2054,56 @@ var DefaultDataClient = class {
1353
2054
  type: "force-cache"
1354
2055
  }
1355
2056
  });
1356
- const parameters = {
1357
- path: pageState.routePath,
1358
- state: pageState.compositionState,
1359
- dataSourceVariant: getDataSourceVariantFromRouteGetParams({}, pageState.compositionState),
2057
+ const originalRoute = {
2058
+ path: options.pageState.routePath,
2059
+ state: options.pageState.compositionState,
2060
+ dataSourceVariant: getDataSourceVariantFromRouteGetParams({}, options.pageState.compositionState),
1360
2061
  withComponentIDs: true,
1361
- releaseId: pageState.releaseId,
1362
- locale: pageState.locale,
1363
- ignoreRedirects: shouldIgnoreRedirects({ state: pageState.compositionState })
2062
+ releaseId: options.pageState.releaseId,
2063
+ locale: options.pageState.locale,
2064
+ ignoreRedirects: shouldIgnoreRedirects({ state: options.pageState.compositionState })
1364
2065
  };
1365
- const route = await routeClient.get(parameters);
1366
- if (route.type === "composition") {
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") {
1367
2074
  await this.enhanceRoute({
1368
- parameters,
1369
- route,
2075
+ source: "pageState",
2076
+ parameters: originalRoute,
2077
+ route: resolvedRoute,
1370
2078
  routeClient,
1371
- keys: pageState.keys
2079
+ keys: options.pageState.keys
1372
2080
  });
1373
2081
  }
1374
2082
  return {
1375
- route
2083
+ route: resolvedRoute
1376
2084
  };
1377
2085
  }
1378
- async enhanceRoute(_options) {
1379
- }
1380
2086
  };
1381
2087
 
1382
2088
  // src/data/resolveRouteFromCode.ts
1383
- var REDIRECT_ORIGIN_PLACEHOLDER = "http://uniform.local";
1384
- var resolveRouteFromCode = async ({ code, dataClient: providedDataClient }) => {
1385
- const codePageState = deserializeEvaluationResult({ input: code });
2089
+ var resolveRouteFromCode = async ({
2090
+ code,
2091
+ dataClient: providedDataClient
2092
+ }) => {
2093
+ const pageState = deserializeEvaluationResult({ input: code });
1386
2094
  const dataClient = providedDataClient != null ? providedDataClient : new DefaultDataClient();
1387
- const states = codePageState.compositionState === CANVAS_EDITOR_STATE ? [CANVAS_EDITOR_STATE, CANVAS_DRAFT_STATE] : [codePageState.compositionState];
1388
- let pageState = codePageState;
1389
- let route = null;
1390
- for (const state of states) {
1391
- pageState = { ...codePageState, compositionState: state };
1392
- try {
1393
- ({ route } = await dataClient.getRoute({ pageState }));
1394
- } catch (e) {
1395
- console.warn(`Failed to retrieve route by path: ${pageState.routePath} with state ${state}`, e);
1396
- }
1397
- if (route && route.type !== "notFound") {
1398
- break;
1399
- }
1400
- }
1401
- if ((route == null ? void 0 : route.type) === "redirect") {
1402
- redirectToTarget({ route, routePath: pageState.routePath });
1403
- }
2095
+ const { route } = await dataClient.getRoute({
2096
+ source: "pageState",
2097
+ pageState
2098
+ });
1404
2099
  return {
1405
2100
  pageState,
2101
+ // suppress the route if it's not a composition
1406
2102
  route: (route == null ? void 0 : route.type) === "composition" ? route : void 0,
2103
+ // the code that was used to resolve the route
1407
2104
  code
1408
2105
  };
1409
2106
  };
1410
- var redirectToTarget = ({ route, routePath }) => {
1411
- const expanded = getTargetVariableExpandedUrl(
1412
- new URL(routePath, REDIRECT_ORIGIN_PLACEHOLDER).toString(),
1413
- route.redirect,
1414
- (pathSegment) => pathSegment.startsWith(":")
1415
- );
1416
- const href = expanded.startsWith(REDIRECT_ORIGIN_PLACEHOLDER) ? expanded.slice(REDIRECT_ORIGIN_PLACEHOLDER.length) || "/" : expanded;
1417
- const statusCode = route.redirect.targetStatusCode;
1418
- if (statusCode === 301 || statusCode === 308) {
1419
- permanentRedirect(href);
1420
- }
1421
- redirect(href);
1422
- };
1423
2107
 
1424
2108
  // src/cache.ts
1425
2109
  var resolveRouteFromCode2 = async ({