@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.js CHANGED
@@ -47,6 +47,124 @@ var __privateWrapper = (obj, member, setter, getter) => ({
47
47
  }
48
48
  });
49
49
 
50
+ // ../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js
51
+ var require_yocto_queue = __commonJS({
52
+ "../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js"(exports2, module2) {
53
+ "use strict";
54
+ var Node2 = class {
55
+ /// value;
56
+ /// next;
57
+ constructor(value) {
58
+ this.value = value;
59
+ this.next = void 0;
60
+ }
61
+ };
62
+ var Queue2 = class {
63
+ // TODO: Use private class fields when targeting Node.js 12.
64
+ // #_head;
65
+ // #_tail;
66
+ // #_size;
67
+ constructor() {
68
+ this.clear();
69
+ }
70
+ enqueue(value) {
71
+ const node = new Node2(value);
72
+ if (this._head) {
73
+ this._tail.next = node;
74
+ this._tail = node;
75
+ } else {
76
+ this._head = node;
77
+ this._tail = node;
78
+ }
79
+ this._size++;
80
+ }
81
+ dequeue() {
82
+ const current = this._head;
83
+ if (!current) {
84
+ return;
85
+ }
86
+ this._head = this._head.next;
87
+ this._size--;
88
+ return current.value;
89
+ }
90
+ clear() {
91
+ this._head = void 0;
92
+ this._tail = void 0;
93
+ this._size = 0;
94
+ }
95
+ get size() {
96
+ return this._size;
97
+ }
98
+ *[Symbol.iterator]() {
99
+ let current = this._head;
100
+ while (current) {
101
+ yield current.value;
102
+ current = current.next;
103
+ }
104
+ }
105
+ };
106
+ module2.exports = Queue2;
107
+ }
108
+ });
109
+
110
+ // ../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js
111
+ var require_p_limit = __commonJS({
112
+ "../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js"(exports2, module2) {
113
+ "use strict";
114
+ var Queue2 = require_yocto_queue();
115
+ var pLimit3 = (concurrency) => {
116
+ if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
117
+ throw new TypeError("Expected `concurrency` to be a number from 1 and up");
118
+ }
119
+ const queue = new Queue2();
120
+ let activeCount = 0;
121
+ const next = () => {
122
+ activeCount--;
123
+ if (queue.size > 0) {
124
+ queue.dequeue()();
125
+ }
126
+ };
127
+ const run = async (fn, resolve, ...args) => {
128
+ activeCount++;
129
+ const result = (async () => fn(...args))();
130
+ resolve(result);
131
+ try {
132
+ await result;
133
+ } catch (e) {
134
+ }
135
+ next();
136
+ };
137
+ const enqueue = (fn, resolve, ...args) => {
138
+ queue.enqueue(run.bind(null, fn, resolve, ...args));
139
+ (async () => {
140
+ await Promise.resolve();
141
+ if (activeCount < concurrency && queue.size > 0) {
142
+ queue.dequeue()();
143
+ }
144
+ })();
145
+ };
146
+ const generator = (fn, ...args) => new Promise((resolve) => {
147
+ enqueue(fn, resolve, ...args);
148
+ });
149
+ Object.defineProperties(generator, {
150
+ activeCount: {
151
+ get: () => activeCount
152
+ },
153
+ pendingCount: {
154
+ get: () => queue.size
155
+ },
156
+ clearQueue: {
157
+ value: () => {
158
+ queue.clear();
159
+ }
160
+ }
161
+ });
162
+ return generator;
163
+ };
164
+ module2.exports = pLimit3;
165
+ }
166
+ });
167
+
50
168
  // ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js
51
169
  var require_retry_operation = __commonJS({
52
170
  "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js"(exports2, module2) {
@@ -285,9 +403,436 @@ __export(cache_exports, {
285
403
  });
286
404
  module.exports = __toCommonJS(cache_exports);
287
405
 
288
- // ../canvas/dist/index.mjs
289
- var import_api = require("@uniformdev/context/api");
290
- var import_api2 = require("@uniformdev/context/api");
406
+ // src/data/resolveRouteFromCode.ts
407
+ var import_next_app_router_shared = require("@uniformdev/next-app-router-shared");
408
+
409
+ // ../context/dist/api/api.mjs
410
+ var import_p_limit = __toESM(require_p_limit(), 1);
411
+ var __defProp2 = Object.defineProperty;
412
+ var __typeError2 = (msg) => {
413
+ throw TypeError(msg);
414
+ };
415
+ var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
416
+ var __publicField2 = (obj, key, value) => __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
417
+ var __accessCheck2 = (obj, member, msg) => member.has(obj) || __typeError2("Cannot " + msg);
418
+ var __privateGet2 = (obj, member, getter) => (__accessCheck2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
419
+ 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);
420
+ var defaultLimitPolicy = (0, import_p_limit.default)(6);
421
+ var UNIFORM_BEARER_TOKEN_NOT_VALID_OR_EXPIRED_MESSAGE = "Bearer token not valid or expired";
422
+ var ApiClientError = class _ApiClientError extends Error {
423
+ constructor(errorMessage, fetchMethod, fetchUri, statusCode, statusText, requestId) {
424
+ super(
425
+ `${errorMessage}
426
+ ${statusCode}${statusText ? " " + statusText : ""} (${fetchMethod} ${fetchUri}${requestId ? ` Request ID: ${requestId}` : ""})`
427
+ );
428
+ __publicField2(this, "errorMessage", errorMessage);
429
+ __publicField2(this, "fetchMethod", fetchMethod);
430
+ __publicField2(this, "fetchUri", fetchUri);
431
+ __publicField2(this, "statusCode", statusCode);
432
+ __publicField2(this, "statusText", statusText);
433
+ __publicField2(this, "requestId", requestId);
434
+ Object.setPrototypeOf(this, _ApiClientError.prototype);
435
+ }
436
+ };
437
+ var BearerTokenNotValidOrExpiredError = class _BearerTokenNotValidOrExpiredError extends ApiClientError {
438
+ constructor(errorMessage, fetchMethod, fetchUri, statusCode, statusText, requestId) {
439
+ super(errorMessage, fetchMethod, fetchUri, statusCode, statusText, requestId);
440
+ Object.setPrototypeOf(this, _BearerTokenNotValidOrExpiredError.prototype);
441
+ }
442
+ };
443
+ var ApiClient = class _ApiClient {
444
+ constructor(options) {
445
+ __publicField2(this, "options");
446
+ var _a, _b, _c, _d, _e;
447
+ if (!options.apiKey && !options.bearerToken) {
448
+ throw new Error("You must provide an API key or a bearer token");
449
+ }
450
+ let leFetch = options.fetch;
451
+ if (!leFetch) {
452
+ if (typeof window !== "undefined") {
453
+ leFetch = window.fetch.bind(window);
454
+ } else if (typeof fetch !== "undefined") {
455
+ leFetch = fetch;
456
+ } else {
457
+ throw new Error("You must provide or polyfill a fetch implementation when not in a browser");
458
+ }
459
+ }
460
+ this.options = {
461
+ ...options,
462
+ fetch: leFetch,
463
+ apiHost: this.ensureApiHost(options.apiHost),
464
+ apiKey: (_a = options.apiKey) != null ? _a : null,
465
+ projectId: (_b = options.projectId) != null ? _b : null,
466
+ bearerToken: (_c = options.bearerToken) != null ? _c : null,
467
+ limitPolicy: (_d = options.limitPolicy) != null ? _d : defaultLimitPolicy,
468
+ bypassCache: (_e = options.bypassCache) != null ? _e : false
469
+ };
470
+ }
471
+ async apiClient(fetchUri, options) {
472
+ return (await this.apiClientWithResponse(fetchUri, options)).body;
473
+ }
474
+ async apiClientWithResponse(fetchUri, options) {
475
+ return this.options.limitPolicy(async () => {
476
+ var _a, _b;
477
+ const coreHeaders = this.options.apiKey ? {
478
+ "x-api-key": this.options.apiKey
479
+ } : {
480
+ Authorization: `Bearer ${this.options.bearerToken}`
481
+ };
482
+ if (this.options.bypassCache) {
483
+ coreHeaders["x-bypass-cache"] = "true";
484
+ }
485
+ const { fetch: fetch2, signal } = this.options;
486
+ const callApi = () => fetch2(fetchUri.toString(), {
487
+ ...options,
488
+ signal,
489
+ headers: {
490
+ ...options == null ? void 0 : options.headers,
491
+ ...coreHeaders
492
+ }
493
+ });
494
+ const apiResponse = await handleRateLimits(callApi);
495
+ if (!apiResponse.ok) {
496
+ let message = "";
497
+ try {
498
+ const responseText = await apiResponse.text();
499
+ try {
500
+ const parsed = JSON.parse(responseText);
501
+ if (parsed.errorMessage) {
502
+ message = Array.isArray(parsed.errorMessage) ? parsed.errorMessage.join(", ") : parsed.errorMessage;
503
+ } else {
504
+ message = responseText;
505
+ }
506
+ } catch (e) {
507
+ message = responseText;
508
+ }
509
+ } catch (e) {
510
+ message = `General error`;
511
+ }
512
+ if (apiResponse.status === 401 && message === UNIFORM_BEARER_TOKEN_NOT_VALID_OR_EXPIRED_MESSAGE) {
513
+ throw new BearerTokenNotValidOrExpiredError(
514
+ message,
515
+ (_a = options == null ? void 0 : options.method) != null ? _a : "GET",
516
+ fetchUri.toString(),
517
+ apiResponse.status,
518
+ apiResponse.statusText,
519
+ _ApiClient.getRequestId(apiResponse)
520
+ );
521
+ }
522
+ throw new ApiClientError(
523
+ message,
524
+ (_b = options == null ? void 0 : options.method) != null ? _b : "GET",
525
+ fetchUri.toString(),
526
+ apiResponse.status,
527
+ apiResponse.statusText,
528
+ _ApiClient.getRequestId(apiResponse)
529
+ );
530
+ }
531
+ if (options == null ? void 0 : options.expectNoContent) {
532
+ return { response: apiResponse, body: null };
533
+ }
534
+ return {
535
+ response: apiResponse,
536
+ body: await apiResponse.json()
537
+ };
538
+ });
539
+ }
540
+ createUrl(path, queryParams, hostOverride) {
541
+ const url = new URL(`${hostOverride != null ? hostOverride : this.options.apiHost}${path}`);
542
+ Object.entries(queryParams != null ? queryParams : {}).forEach(([key, value]) => {
543
+ var _a;
544
+ if (typeof value !== "undefined" && value !== null) {
545
+ url.searchParams.append(key, Array.isArray(value) ? value.join(",") : (_a = value == null ? void 0 : value.toString()) != null ? _a : "");
546
+ }
547
+ });
548
+ return url;
549
+ }
550
+ ensureApiHost(apiHost) {
551
+ if (!apiHost) return "https://uniform.app";
552
+ if (!(apiHost == null ? void 0 : apiHost.startsWith("http"))) {
553
+ throw new Error('Your apiHost must start with "http"');
554
+ }
555
+ if (apiHost.indexOf("/", 8) > -1) {
556
+ throw new Error("Your apiHost must not contain a path element after the domain");
557
+ }
558
+ if (apiHost.indexOf("?") > -1) {
559
+ throw new Error("Your apiHost must not contain a query string");
560
+ }
561
+ if (apiHost == null ? void 0 : apiHost.endsWith("/")) {
562
+ apiHost = apiHost.substring(0, apiHost.length - 1);
563
+ }
564
+ return apiHost;
565
+ }
566
+ static getRequestId(response) {
567
+ const apigRequestId = response.headers.get("apigw-requestid");
568
+ if (apigRequestId) {
569
+ return apigRequestId;
570
+ }
571
+ return void 0;
572
+ }
573
+ };
574
+ async function handleRateLimits(callApi) {
575
+ var _a;
576
+ const backoffRetries = 5;
577
+ let backoffRetriesLeft = backoffRetries;
578
+ let response;
579
+ while (backoffRetriesLeft > 0) {
580
+ response = await callApi();
581
+ if (response.status !== 429) {
582
+ break;
583
+ }
584
+ let resetWait = 0;
585
+ try {
586
+ const responseClone = response.clone();
587
+ const dateHeader = responseClone.headers.get("date");
588
+ const serverTime = dateHeader ? new Date(dateHeader).getTime() : void 0;
589
+ const body = await responseClone.json();
590
+ const resetTime = (_a = body == null ? void 0 : body.info) == null ? void 0 : _a.reset;
591
+ if (typeof serverTime === "number" && typeof resetTime === "number") {
592
+ resetWait = Math.max(0, Math.min(Math.round(1.1 * (resetTime - serverTime)), 1e4));
593
+ }
594
+ } catch (e) {
595
+ }
596
+ const base = Math.pow(2, backoffRetries - backoffRetriesLeft) * 333;
597
+ const backoffWait = base + Math.round(Math.random() * (base / 2)) * (Math.random() > 0.5 ? 1 : -1);
598
+ await new Promise((resolve) => setTimeout(resolve, Math.max(0, resetWait + backoffWait)));
599
+ backoffRetriesLeft -= 1;
600
+ }
601
+ return response;
602
+ }
603
+ var isPlainObject = (obj) => typeof obj === "object" && obj !== null && !Array.isArray(obj);
604
+ function rewriteFiltersForApi(filters) {
605
+ return Object.entries(filters != null ? filters : {}).reduce(
606
+ (acc, [key, value]) => {
607
+ const lhs = `filters.${key}` + (isPlainObject(value) ? `[${Object.keys(value)[0]}]` : "");
608
+ const rhs = isPlainObject(value) ? Object.values(value)[0] : value;
609
+ return {
610
+ ...acc,
611
+ [lhs]: Array.isArray(rhs) ? rhs.map((v) => `${v}`.trim()).join(",") : `${rhs}`.trim()
612
+ };
613
+ },
614
+ {}
615
+ );
616
+ }
617
+ var _url;
618
+ var _AggregateClient = class _AggregateClient2 extends ApiClient {
619
+ constructor(options) {
620
+ super(options);
621
+ }
622
+ /** Fetches all aggregates for a project */
623
+ async get(options) {
624
+ const { projectId } = this.options;
625
+ const fetchUri = this.createUrl(__privateGet2(_AggregateClient2, _url), { ...options, projectId });
626
+ return await this.apiClient(fetchUri);
627
+ }
628
+ /** Updates or creates (based on id) an Aggregate */
629
+ async upsert(body) {
630
+ const fetchUri = this.createUrl(__privateGet2(_AggregateClient2, _url));
631
+ await this.apiClient(fetchUri, {
632
+ method: "PUT",
633
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
634
+ expectNoContent: true
635
+ });
636
+ }
637
+ /** Deletes an Aggregate */
638
+ async remove(body) {
639
+ const fetchUri = this.createUrl(__privateGet2(_AggregateClient2, _url));
640
+ await this.apiClient(fetchUri, {
641
+ method: "DELETE",
642
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
643
+ expectNoContent: true
644
+ });
645
+ }
646
+ };
647
+ _url = /* @__PURE__ */ new WeakMap();
648
+ __privateAdd2(_AggregateClient, _url, "/api/v2/aggregate");
649
+ var _url2;
650
+ var _DimensionClient = class _DimensionClient2 extends ApiClient {
651
+ constructor(options) {
652
+ super(options);
653
+ }
654
+ /** Fetches the known score dimensions for a project */
655
+ async get(options) {
656
+ const { projectId } = this.options;
657
+ const fetchUri = this.createUrl(__privateGet2(_DimensionClient2, _url2), { ...options, projectId });
658
+ return await this.apiClient(fetchUri);
659
+ }
660
+ };
661
+ _url2 = /* @__PURE__ */ new WeakMap();
662
+ __privateAdd2(_DimensionClient, _url2, "/api/v2/dimension");
663
+ var _url3;
664
+ var _valueUrl;
665
+ var _EnrichmentClient = class _EnrichmentClient2 extends ApiClient {
666
+ constructor(options) {
667
+ super(options);
668
+ }
669
+ /** Fetches all enrichments and values for a project, grouped by category */
670
+ async get(options) {
671
+ const { projectId } = this.options;
672
+ const fetchUri = this.createUrl(__privateGet2(_EnrichmentClient2, _url3), { ...options, projectId });
673
+ return await this.apiClient(fetchUri);
674
+ }
675
+ /** Updates or creates (based on id) an enrichment category */
676
+ async upsertCategory(body) {
677
+ const fetchUri = this.createUrl(__privateGet2(_EnrichmentClient2, _url3));
678
+ await this.apiClient(fetchUri, {
679
+ method: "PUT",
680
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
681
+ expectNoContent: true
682
+ });
683
+ }
684
+ /** Deletes an enrichment category */
685
+ async removeCategory(body) {
686
+ const fetchUri = this.createUrl(__privateGet2(_EnrichmentClient2, _url3));
687
+ await this.apiClient(fetchUri, {
688
+ method: "DELETE",
689
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
690
+ expectNoContent: true
691
+ });
692
+ }
693
+ /** Updates or creates (based on id) an enrichment value within an enrichment category */
694
+ async upsertValue(body) {
695
+ const fetchUri = this.createUrl(__privateGet2(_EnrichmentClient2, _valueUrl));
696
+ await this.apiClient(fetchUri, {
697
+ method: "PUT",
698
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
699
+ expectNoContent: true
700
+ });
701
+ }
702
+ /** Deletes an enrichment value within an enrichment category. The category is left alone. */
703
+ async removeValue(body) {
704
+ const fetchUri = this.createUrl(__privateGet2(_EnrichmentClient2, _valueUrl));
705
+ await this.apiClient(fetchUri, {
706
+ method: "DELETE",
707
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
708
+ expectNoContent: true
709
+ });
710
+ }
711
+ };
712
+ _url3 = /* @__PURE__ */ new WeakMap();
713
+ _valueUrl = /* @__PURE__ */ new WeakMap();
714
+ __privateAdd2(_EnrichmentClient, _url3, "/api/v1/enrichments");
715
+ __privateAdd2(_EnrichmentClient, _valueUrl, "/api/v1/enrichment-values");
716
+ var _url4;
717
+ var _ManifestClient = class _ManifestClient2 extends ApiClient {
718
+ constructor(options) {
719
+ super(options);
720
+ }
721
+ /** Fetches the Context manifest for a project */
722
+ async get(options) {
723
+ const { projectId } = this.options;
724
+ const fetchUri = this.createUrl(__privateGet2(_ManifestClient2, _url4), { ...options, projectId });
725
+ return await this.apiClient(fetchUri);
726
+ }
727
+ /** Publishes the Context manifest for a project */
728
+ async publish() {
729
+ const { projectId } = this.options;
730
+ const fetchUri = this.createUrl("/api/v1/publish", { siteId: projectId });
731
+ await this.apiClient(fetchUri, {
732
+ method: "POST",
733
+ expectNoContent: true
734
+ });
735
+ }
736
+ };
737
+ _url4 = /* @__PURE__ */ new WeakMap();
738
+ __privateAdd2(_ManifestClient, _url4, "/api/v2/manifest");
739
+ var ManifestClient = _ManifestClient;
740
+ var _url5;
741
+ var _QuirkClient = class _QuirkClient2 extends ApiClient {
742
+ constructor(options) {
743
+ super(options);
744
+ }
745
+ /** Fetches all Quirks for a project */
746
+ async get(options) {
747
+ const { projectId } = this.options;
748
+ const fetchUri = this.createUrl(__privateGet2(_QuirkClient2, _url5), { ...options, projectId });
749
+ return await this.apiClient(fetchUri);
750
+ }
751
+ /** Updates or creates (based on id) a Quirk */
752
+ async upsert(body) {
753
+ const fetchUri = this.createUrl(__privateGet2(_QuirkClient2, _url5));
754
+ await this.apiClient(fetchUri, {
755
+ method: "PUT",
756
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
757
+ expectNoContent: true
758
+ });
759
+ }
760
+ /** Deletes a Quirk */
761
+ async remove(body) {
762
+ const fetchUri = this.createUrl(__privateGet2(_QuirkClient2, _url5));
763
+ await this.apiClient(fetchUri, {
764
+ method: "DELETE",
765
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
766
+ expectNoContent: true
767
+ });
768
+ }
769
+ };
770
+ _url5 = /* @__PURE__ */ new WeakMap();
771
+ __privateAdd2(_QuirkClient, _url5, "/api/v2/quirk");
772
+ var _url6;
773
+ var _SignalClient = class _SignalClient2 extends ApiClient {
774
+ constructor(options) {
775
+ super(options);
776
+ }
777
+ /** Fetches all Signals for a project */
778
+ async get(options) {
779
+ const { projectId } = this.options;
780
+ const fetchUri = this.createUrl(__privateGet2(_SignalClient2, _url6), { ...options, projectId });
781
+ return await this.apiClient(fetchUri);
782
+ }
783
+ /** Updates or creates (based on id) a Signal */
784
+ async upsert(body) {
785
+ const fetchUri = this.createUrl(__privateGet2(_SignalClient2, _url6));
786
+ await this.apiClient(fetchUri, {
787
+ method: "PUT",
788
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
789
+ expectNoContent: true
790
+ });
791
+ }
792
+ /** Deletes a Signal */
793
+ async remove(body) {
794
+ const fetchUri = this.createUrl(__privateGet2(_SignalClient2, _url6));
795
+ await this.apiClient(fetchUri, {
796
+ method: "DELETE",
797
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
798
+ expectNoContent: true
799
+ });
800
+ }
801
+ };
802
+ _url6 = /* @__PURE__ */ new WeakMap();
803
+ __privateAdd2(_SignalClient, _url6, "/api/v2/signal");
804
+ var _url7;
805
+ var _TestClient = class _TestClient2 extends ApiClient {
806
+ constructor(options) {
807
+ super(options);
808
+ }
809
+ /** Fetches all Tests for a project */
810
+ async get(options) {
811
+ const { projectId } = this.options;
812
+ const fetchUri = this.createUrl(__privateGet2(_TestClient2, _url7), { ...options, projectId });
813
+ return await this.apiClient(fetchUri);
814
+ }
815
+ /** Updates or creates (based on id) a Test */
816
+ async upsert(body) {
817
+ const fetchUri = this.createUrl(__privateGet2(_TestClient2, _url7));
818
+ await this.apiClient(fetchUri, {
819
+ method: "PUT",
820
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
821
+ expectNoContent: true
822
+ });
823
+ }
824
+ /** Deletes a Test */
825
+ async remove(body) {
826
+ const fetchUri = this.createUrl(__privateGet2(_TestClient2, _url7));
827
+ await this.apiClient(fetchUri, {
828
+ method: "DELETE",
829
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
830
+ expectNoContent: true
831
+ });
832
+ }
833
+ };
834
+ _url7 = /* @__PURE__ */ new WeakMap();
835
+ __privateAdd2(_TestClient, _url7, "/api/v2/test");
291
836
 
292
837
  // ../../node_modules/.pnpm/yocto-queue@1.2.2/node_modules/yocto-queue/index.js
293
838
  var Node = class {
@@ -360,7 +905,7 @@ _tail = new WeakMap();
360
905
  _size = new WeakMap();
361
906
 
362
907
  // ../../node_modules/.pnpm/p-limit@6.2.0/node_modules/p-limit/index.js
363
- function pLimit(concurrency) {
908
+ function pLimit2(concurrency) {
364
909
  validateConcurrency(concurrency);
365
910
  const queue = new Queue();
366
911
  let activeCount = 0;
@@ -640,44 +1185,19 @@ function pThrottle({ limit, interval, strict, onDelay }) {
640
1185
  }
641
1186
 
642
1187
  // ../canvas/dist/index.mjs
643
- var import_api3 = require("@uniformdev/context/api");
644
- var import_api4 = require("@uniformdev/context/api");
645
- var import_api5 = require("@uniformdev/context/api");
646
- var import_api6 = require("@uniformdev/context/api");
647
- var import_api7 = require("@uniformdev/context/api");
648
- var import_api8 = require("@uniformdev/context/api");
649
- var import_api9 = require("@uniformdev/context/api");
650
- var import_api10 = require("@uniformdev/context/api");
651
- var import_api11 = require("@uniformdev/context/api");
652
- var import_api12 = require("@uniformdev/context/api");
653
- var import_api13 = require("@uniformdev/context/api");
654
- var import_api14 = require("@uniformdev/context/api");
655
- var import_api15 = require("@uniformdev/context/api");
656
- var import_api16 = require("@uniformdev/context/api");
657
- var import_api17 = require("@uniformdev/context/api");
658
- var import_api18 = require("@uniformdev/context/api");
659
- var import_api19 = require("@uniformdev/context/api");
660
- var import_api20 = require("@uniformdev/context/api");
661
- var import_api21 = require("@uniformdev/context/api");
662
- var import_api22 = require("@uniformdev/context/api");
663
- var import_api23 = require("@uniformdev/context/api");
664
- var import_api24 = require("@uniformdev/context/api");
665
- var import_api25 = require("@uniformdev/context/api");
666
- var import_api26 = require("@uniformdev/context/api");
667
- var import_api27 = require("@uniformdev/context/api");
668
- var __typeError2 = (msg) => {
1188
+ var __typeError3 = (msg) => {
669
1189
  throw TypeError(msg);
670
1190
  };
671
- var __accessCheck2 = (obj, member, msg) => member.has(obj) || __typeError2("Cannot " + msg);
672
- var __privateGet2 = (obj, member, getter) => (__accessCheck2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
673
- 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);
1191
+ var __accessCheck3 = (obj, member, msg) => member.has(obj) || __typeError3("Cannot " + msg);
1192
+ var __privateGet3 = (obj, member, getter) => (__accessCheck3(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
1193
+ 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);
674
1194
  function createLimitPolicy({
675
1195
  throttle = { interval: 1e3, limit: 10 },
676
1196
  retry: retry3 = { retries: 1, factor: 1.66 },
677
1197
  limit = 10
678
1198
  }) {
679
1199
  const throttler = throttle ? pThrottle(throttle) : null;
680
- const limiter = limit ? pLimit(limit) : null;
1200
+ const limiter = limit ? pLimit2(limit) : null;
681
1201
  return function limitPolicy(func) {
682
1202
  let currentFunc = async () => await func();
683
1203
  if (throttler) {
@@ -696,7 +1216,7 @@ function createLimitPolicy({
696
1216
  if (retry3.onFailedAttempt) {
697
1217
  await retry3.onFailedAttempt(error);
698
1218
  }
699
- if (error instanceof import_api2.ApiClientError && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
1219
+ if (error instanceof ApiClientError && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
700
1220
  throw error;
701
1221
  }
702
1222
  }
@@ -759,7 +1279,7 @@ var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
759
1279
  var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
760
1280
  var _contentTypesUrl;
761
1281
  var _entriesUrl;
762
- var _ContentClient = class _ContentClient2 extends import_api12.ApiClient {
1282
+ var _ContentClient = class _ContentClient2 extends ApiClient {
763
1283
  constructor(options) {
764
1284
  var _a;
765
1285
  super(options);
@@ -767,16 +1287,16 @@ var _ContentClient = class _ContentClient2 extends import_api12.ApiClient {
767
1287
  }
768
1288
  getContentTypes(options) {
769
1289
  const { projectId } = this.options;
770
- const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _contentTypesUrl), { ...options, projectId });
1290
+ const fetchUri = this.createUrl(__privateGet3(_ContentClient2, _contentTypesUrl), { ...options, projectId });
771
1291
  return this.apiClient(fetchUri);
772
1292
  }
773
1293
  getEntries(options) {
774
1294
  const { projectId } = this.options;
775
1295
  const { skipDataResolution, filters, select, ...params } = options;
776
- const rewrittenFilters = (0, import_api12.rewriteFiltersForApi)(filters);
1296
+ const rewrittenFilters = rewriteFiltersForApi(filters);
777
1297
  const rewrittenSelect = projectionToQuery(select);
778
1298
  if (skipDataResolution) {
779
- const url = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl), {
1299
+ const url = this.createUrl(__privateGet3(_ContentClient2, _entriesUrl), {
780
1300
  ...params,
781
1301
  ...rewrittenFilters,
782
1302
  ...rewrittenSelect,
@@ -785,7 +1305,7 @@ var _ContentClient = class _ContentClient2 extends import_api12.ApiClient {
785
1305
  return this.apiClient(url);
786
1306
  }
787
1307
  const edgeUrl = this.createUrl(
788
- __privateGet2(_ContentClient2, _entriesUrl),
1308
+ __privateGet3(_ContentClient2, _entriesUrl),
789
1309
  { ...this.getEdgeOptions(params), ...rewrittenFilters, ...rewrittenSelect },
790
1310
  this.edgeApiHost
791
1311
  );
@@ -803,7 +1323,7 @@ var _ContentClient = class _ContentClient2 extends import_api12.ApiClient {
803
1323
  return this.apiClient(historyUrl);
804
1324
  }
805
1325
  async upsertContentType(body, opts = {}) {
806
- const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _contentTypesUrl));
1326
+ const fetchUri = this.createUrl(__privateGet3(_ContentClient2, _contentTypesUrl));
807
1327
  if (typeof body.contentType.slugSettings === "object" && body.contentType.slugSettings !== null && Object.keys(body.contentType.slugSettings).length === 0) {
808
1328
  delete body.contentType.slugSettings;
809
1329
  }
@@ -815,7 +1335,7 @@ var _ContentClient = class _ContentClient2 extends import_api12.ApiClient {
815
1335
  });
816
1336
  }
817
1337
  async upsertEntry(body, options) {
818
- const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl));
1338
+ const fetchUri = this.createUrl(__privateGet3(_ContentClient2, _entriesUrl));
819
1339
  const headers = {};
820
1340
  if (options == null ? void 0 : options.ifUnmodifiedSince) {
821
1341
  headers["x-if-unmodified-since"] = options.ifUnmodifiedSince;
@@ -829,7 +1349,7 @@ var _ContentClient = class _ContentClient2 extends import_api12.ApiClient {
829
1349
  return { modified: response.headers.get("x-modified-at") };
830
1350
  }
831
1351
  async deleteContentType(body) {
832
- const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _contentTypesUrl));
1352
+ const fetchUri = this.createUrl(__privateGet3(_ContentClient2, _contentTypesUrl));
833
1353
  await this.apiClient(fetchUri, {
834
1354
  method: "DELETE",
835
1355
  body: JSON.stringify({ ...body, projectId: this.options.projectId }),
@@ -837,7 +1357,7 @@ var _ContentClient = class _ContentClient2 extends import_api12.ApiClient {
837
1357
  });
838
1358
  }
839
1359
  async deleteEntry(body) {
840
- const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl));
1360
+ const fetchUri = this.createUrl(__privateGet3(_ContentClient2, _entriesUrl));
841
1361
  await this.apiClient(fetchUri, {
842
1362
  method: "DELETE",
843
1363
  body: JSON.stringify({ ...body, projectId: this.options.projectId }),
@@ -856,17 +1376,17 @@ var _ContentClient = class _ContentClient2 extends import_api12.ApiClient {
856
1376
  };
857
1377
  _contentTypesUrl = /* @__PURE__ */ new WeakMap();
858
1378
  _entriesUrl = /* @__PURE__ */ new WeakMap();
859
- __privateAdd2(_ContentClient, _contentTypesUrl, "/api/v1/content-types");
860
- __privateAdd2(_ContentClient, _entriesUrl, "/api/v1/entries");
861
- var _url;
862
- var _DataTypeClient = class _DataTypeClient2 extends import_api14.ApiClient {
1379
+ __privateAdd3(_ContentClient, _contentTypesUrl, "/api/v1/content-types");
1380
+ __privateAdd3(_ContentClient, _entriesUrl, "/api/v1/entries");
1381
+ var _url8;
1382
+ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
863
1383
  constructor(options) {
864
1384
  super(options);
865
1385
  }
866
1386
  /** Fetches a list of DataTypes for a project */
867
1387
  async list(options) {
868
1388
  const { projectId } = this.options;
869
- const fetchUri = this.createUrl(__privateGet2(_DataTypeClient2, _url), { ...options, projectId });
1389
+ const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8), { ...options, projectId });
870
1390
  return await this.apiClient(fetchUri);
871
1391
  }
872
1392
  /** @deprecated Use {@link list} instead. */
@@ -875,7 +1395,7 @@ var _DataTypeClient = class _DataTypeClient2 extends import_api14.ApiClient {
875
1395
  }
876
1396
  /** Updates or creates (based on id) a DataType */
877
1397
  async save(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: "PUT",
881
1401
  body: JSON.stringify({ ...body, projectId: this.options.projectId }),
@@ -888,7 +1408,7 @@ var _DataTypeClient = class _DataTypeClient2 extends import_api14.ApiClient {
888
1408
  }
889
1409
  /** Deletes a DataType */
890
1410
  async remove(body) {
891
- const fetchUri = this.createUrl(__privateGet2(_DataTypeClient2, _url));
1411
+ const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
892
1412
  await this.apiClient(fetchUri, {
893
1413
  method: "DELETE",
894
1414
  body: JSON.stringify({ ...body, projectId: this.options.projectId }),
@@ -896,10 +1416,10 @@ var _DataTypeClient = class _DataTypeClient2 extends import_api14.ApiClient {
896
1416
  });
897
1417
  }
898
1418
  };
899
- _url = /* @__PURE__ */ new WeakMap();
900
- __privateAdd2(_DataTypeClient, _url, "/api/v1/data-types");
1419
+ _url8 = /* @__PURE__ */ new WeakMap();
1420
+ __privateAdd3(_DataTypeClient, _url8, "/api/v1/data-types");
901
1421
  var _baseUrl;
902
- var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2 extends import_api16.ApiClient {
1422
+ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2 extends ApiClient {
903
1423
  constructor(options) {
904
1424
  super(options);
905
1425
  this.teamId = options.teamId;
@@ -908,7 +1428,7 @@ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2
908
1428
  * Gets a list of property type and hook names for the current team, including public integrations' hooks.
909
1429
  */
910
1430
  get(options) {
911
- const fetchUri = this.createUrl(__privateGet2(_IntegrationPropertyEditorsClient2, _baseUrl), {
1431
+ const fetchUri = this.createUrl(__privateGet3(_IntegrationPropertyEditorsClient2, _baseUrl), {
912
1432
  ...options,
913
1433
  teamId: this.teamId
914
1434
  });
@@ -918,7 +1438,7 @@ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2
918
1438
  * Creates or updates a custom AI property editor on a Mesh app.
919
1439
  */
920
1440
  async deploy(body) {
921
- const fetchUri = this.createUrl(__privateGet2(_IntegrationPropertyEditorsClient2, _baseUrl));
1441
+ const fetchUri = this.createUrl(__privateGet3(_IntegrationPropertyEditorsClient2, _baseUrl));
922
1442
  await this.apiClient(fetchUri, {
923
1443
  method: "PUT",
924
1444
  body: JSON.stringify({ ...body, teamId: this.teamId }),
@@ -929,7 +1449,7 @@ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2
929
1449
  * Removes a custom AI property editor from a Mesh app.
930
1450
  */
931
1451
  async delete(body) {
932
- const fetchUri = this.createUrl(__privateGet2(_IntegrationPropertyEditorsClient2, _baseUrl));
1452
+ const fetchUri = this.createUrl(__privateGet3(_IntegrationPropertyEditorsClient2, _baseUrl));
933
1453
  await this.apiClient(fetchUri, {
934
1454
  method: "DELETE",
935
1455
  body: JSON.stringify({ ...body, teamId: this.teamId }),
@@ -938,16 +1458,16 @@ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2
938
1458
  }
939
1459
  };
940
1460
  _baseUrl = /* @__PURE__ */ new WeakMap();
941
- __privateAdd2(_IntegrationPropertyEditorsClient, _baseUrl, "/api/v1/integration-property-editors");
942
- var _url2;
1461
+ __privateAdd3(_IntegrationPropertyEditorsClient, _baseUrl, "/api/v1/integration-property-editors");
1462
+ var _url22;
943
1463
  var _projectsUrl;
944
- var _ProjectClient = class _ProjectClient2 extends import_api20.ApiClient {
1464
+ var _ProjectClient = class _ProjectClient2 extends ApiClient {
945
1465
  constructor(options) {
946
1466
  super({ ...options, bypassCache: true });
947
1467
  }
948
1468
  /** Fetches single Project */
949
1469
  async get(options) {
950
- const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _url2), { ...options });
1470
+ const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22), { ...options });
951
1471
  return await this.apiClient(fetchUri);
952
1472
  }
953
1473
  /**
@@ -956,7 +1476,7 @@ var _ProjectClient = class _ProjectClient2 extends import_api20.ApiClient {
956
1476
  * When omitted, returns all accessible teams and their projects.
957
1477
  */
958
1478
  async list(options) {
959
- const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
1479
+ const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
960
1480
  return await this.apiClient(fetchUri);
961
1481
  }
962
1482
  /** @deprecated Use {@link list} instead. */
@@ -965,7 +1485,7 @@ var _ProjectClient = class _ProjectClient2 extends import_api20.ApiClient {
965
1485
  }
966
1486
  /** Updates or creates (based on id) a Project */
967
1487
  async save(body) {
968
- const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _url2));
1488
+ const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
969
1489
  return await this.apiClient(fetchUri, {
970
1490
  method: "PUT",
971
1491
  body: JSON.stringify({ ...body })
@@ -977,7 +1497,7 @@ var _ProjectClient = class _ProjectClient2 extends import_api20.ApiClient {
977
1497
  }
978
1498
  /** Deletes a Project */
979
1499
  async remove(body) {
980
- const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _url2));
1500
+ const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
981
1501
  await this.apiClient(fetchUri, {
982
1502
  method: "DELETE",
983
1503
  body: JSON.stringify({ ...body }),
@@ -989,12 +1509,12 @@ var _ProjectClient = class _ProjectClient2 extends import_api20.ApiClient {
989
1509
  return this.remove(body);
990
1510
  }
991
1511
  };
992
- _url2 = /* @__PURE__ */ new WeakMap();
1512
+ _url22 = /* @__PURE__ */ new WeakMap();
993
1513
  _projectsUrl = /* @__PURE__ */ new WeakMap();
994
- __privateAdd2(_ProjectClient, _url2, "/api/v1/project");
995
- __privateAdd2(_ProjectClient, _projectsUrl, "/api/v1/projects");
1514
+ __privateAdd3(_ProjectClient, _url22, "/api/v1/project");
1515
+ __privateAdd3(_ProjectClient, _projectsUrl, "/api/v1/projects");
996
1516
  var ROUTE_URL = "/api/v1/route";
997
- var RouteClient = class extends import_api25.ApiClient {
1517
+ var RouteClient = class extends ApiClient {
998
1518
  constructor(options) {
999
1519
  var _a;
1000
1520
  if (!options.limitPolicy) {
@@ -1037,12 +1557,10 @@ var getDataSourceVariantFromRouteGetParams = (params, defaultPreviewState) => {
1037
1557
  return dataSourceVariant;
1038
1558
  };
1039
1559
 
1040
- // src/data/resolveRouteFromCode.ts
1041
- var import_next_app_router_shared = require("@uniformdev/next-app-router-shared");
1042
- var import_redirect = require("@uniformdev/redirect");
1043
- var import_navigation = require("next/navigation");
1560
+ // src/data/client.ts
1561
+ var import_functions = require("@vercel/functions");
1044
1562
 
1045
- // src/clients/route.ts
1563
+ // src/clients/manifest.ts
1046
1564
  var import_server_only = require("server-only");
1047
1565
 
1048
1566
  // src/utils/env.ts
@@ -1095,6 +1613,11 @@ var isStateCacheMode = (options) => {
1095
1613
  var isDetectCacheMode = (options) => {
1096
1614
  return "searchParams" in options && "draftModeEnabled" in options;
1097
1615
  };
1616
+ var resolveManifestCache = (options) => {
1617
+ return resolveCache({
1618
+ options
1619
+ });
1620
+ };
1098
1621
  var resolveCanvasCache = (options) => {
1099
1622
  return resolveCache({
1100
1623
  options
@@ -1162,7 +1685,6 @@ var determineFetchCacheOptions = (mode) => {
1162
1685
  };
1163
1686
 
1164
1687
  // src/clients/retry.ts
1165
- var import_api28 = require("@uniformdev/context/api");
1166
1688
  function createThrottler(limit, interval) {
1167
1689
  let available = limit;
1168
1690
  let refillScheduled = false;
@@ -1273,7 +1795,7 @@ function createLimitPolicy2({
1273
1795
  if (retryOptions.onFailedAttempt) {
1274
1796
  await retryOptions.onFailedAttempt(error);
1275
1797
  }
1276
- if (error instanceof import_api28.ApiClientError && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
1798
+ if (error instanceof ApiClientError && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
1277
1799
  throw error;
1278
1800
  }
1279
1801
  }
@@ -1290,8 +1812,8 @@ var buildPathTag = (path) => {
1290
1812
  };
1291
1813
 
1292
1814
  // src/clients/tags.ts
1293
- var generateRouteCacheTags = ({ path }) => {
1294
- const tags = ["route"];
1815
+ var generateRouteCacheTags = ({ path, old }) => {
1816
+ const tags = old ? ["route-old"] : ["route"];
1295
1817
  if (path) {
1296
1818
  const pathWithoutQuery = path.split("?")[0];
1297
1819
  const pieces = pathWithoutQuery.split("/");
@@ -1303,8 +1825,51 @@ var generateRouteCacheTags = ({ path }) => {
1303
1825
  }
1304
1826
  return tags;
1305
1827
  };
1828
+ var generateManifestCacheTags = () => {
1829
+ return ["manifest"];
1830
+ };
1831
+
1832
+ // src/clients/manifest.ts
1833
+ var getManifestClient = (options) => {
1834
+ const cache = resolveManifestCache(options);
1835
+ const manifestClient = new ManifestClient({
1836
+ apiHost: env.getApiHost(),
1837
+ apiKey: env.getApiKey(),
1838
+ projectId: env.getProjectId(),
1839
+ limitPolicy: createLimitPolicy2({
1840
+ limit: 6
1841
+ }),
1842
+ fetch: (req, init) => {
1843
+ const { cache: fetchCache, revalidate } = determineFetchCacheOptions(cache);
1844
+ return fetch(req, {
1845
+ ...init,
1846
+ headers: {
1847
+ ...init == null ? void 0 : init.headers,
1848
+ "x-bypass-cache": typeof cache.bypassCache !== "undefined" ? cache.bypassCache.toString() : "false"
1849
+ },
1850
+ cache: fetchCache,
1851
+ next: {
1852
+ revalidate,
1853
+ tags: generateManifestCacheTags()
1854
+ }
1855
+ });
1856
+ }
1857
+ });
1858
+ return manifestClient;
1859
+ };
1860
+ var getManifest = async (options) => {
1861
+ let preview = false;
1862
+ if (options && isStateCacheMode(options)) {
1863
+ preview = options.state === CANVAS_DRAFT_STATE || options.state === CANVAS_EDITOR_STATE;
1864
+ }
1865
+ const manifestClient = getManifestClient(options);
1866
+ return manifestClient.get({
1867
+ preview
1868
+ });
1869
+ };
1306
1870
 
1307
1871
  // src/clients/route.ts
1872
+ var import_server_only2 = require("server-only");
1308
1873
  var getRouteCacheTags = (requestedUrl) => {
1309
1874
  const tags = ["route"];
1310
1875
  if (requestedUrl) {
@@ -1354,10 +1919,146 @@ var getRouteClient = (options) => {
1354
1919
  return client;
1355
1920
  };
1356
1921
 
1922
+ // src/config/helpers.ts
1923
+ var import_resolved = __toESM(require("@uniformdev/next-app-router/config/resolved"));
1924
+ var getMiddlewareRuntimeCache = () => {
1925
+ if (process.env.NODE_ENV === "development" && !process.env.RUNTIME_CACHE_ENDPOINT) {
1926
+ return false;
1927
+ }
1928
+ if (typeof import_resolved.default.middlewareRuntimeCache === "boolean") {
1929
+ return import_resolved.default.middlewareRuntimeCache;
1930
+ }
1931
+ return true;
1932
+ };
1933
+ var getDisableSwrMiddlewareCache = () => {
1934
+ var _a;
1935
+ if (typeof ((_a = import_resolved.default.experimental) == null ? void 0 : _a.disableSwrMiddlewareCache) === "boolean") {
1936
+ return import_resolved.default.experimental.disableSwrMiddlewareCache;
1937
+ }
1938
+ return false;
1939
+ };
1940
+
1357
1941
  // src/data/client.ts
1942
+ var MANIFEST_CACHE_KEY = "uniform-manifest";
1358
1943
  var DefaultDataClient = class {
1359
- async getRoute({ pageState }) {
1360
- const shouldBypassCache = pageState.compositionState !== CANVAS_PUBLISHED_STATE || isDevelopmentEnvironment();
1944
+ async getManifest(options) {
1945
+ const cache = options.source === "middleware" && getMiddlewareRuntimeCache() ? (0, import_functions.getCache)() : null;
1946
+ if (cache) {
1947
+ const cachedManifest = await cache.get(MANIFEST_CACHE_KEY);
1948
+ if (cachedManifest) {
1949
+ return cachedManifest;
1950
+ }
1951
+ }
1952
+ const manifest = await getManifest({
1953
+ cache: isDevelopmentEnvironment() ? {
1954
+ type: "no-cache",
1955
+ bypassCache: true
1956
+ } : {
1957
+ type: "force-cache"
1958
+ }
1959
+ });
1960
+ if (cache) {
1961
+ (0, import_functions.waitUntil)(
1962
+ (async () => {
1963
+ await cache.set(MANIFEST_CACHE_KEY, manifest, {
1964
+ tags: generateManifestCacheTags()
1965
+ });
1966
+ })()
1967
+ );
1968
+ }
1969
+ return manifest;
1970
+ }
1971
+ async getRouteFromApi({
1972
+ route,
1973
+ routeClient,
1974
+ enableRuntimeCache,
1975
+ disableSwrCache
1976
+ }) {
1977
+ const newCacheKey = `uniform-route-${route.state}-${route.releaseId}-${route.path}`;
1978
+ const oldCacheKey = `uniform-route-old-${route.state}-${route.releaseId}-${route.path}`;
1979
+ const cache = enableRuntimeCache ? (0, import_functions.getCache)() : null;
1980
+ const cacheNewRoute = async (result2) => {
1981
+ if (cache && result2.type === "composition") {
1982
+ const tags = generateRouteCacheTags({ path: route.path });
1983
+ await cache.set(newCacheKey, result2, {
1984
+ tags
1985
+ });
1986
+ }
1987
+ };
1988
+ const cacheOldRoute = async (result2) => {
1989
+ if (cache && result2.type === "composition" && !disableSwrCache) {
1990
+ const tags = generateRouteCacheTags({ path: route.path, old: true });
1991
+ await cache.set(oldCacheKey, result2, {
1992
+ tags
1993
+ });
1994
+ }
1995
+ };
1996
+ if (cache) {
1997
+ const [cachedRoute, oldCachedRoute] = await Promise.all([
1998
+ cache.get(newCacheKey),
1999
+ disableSwrCache ? null : cache.get(oldCacheKey)
2000
+ ]);
2001
+ if (cachedRoute) {
2002
+ return cachedRoute;
2003
+ }
2004
+ if (oldCachedRoute) {
2005
+ (0, import_functions.waitUntil)(
2006
+ (async () => {
2007
+ const result2 = await routeClient.get(route);
2008
+ await cacheNewRoute(result2);
2009
+ })()
2010
+ );
2011
+ return oldCachedRoute;
2012
+ }
2013
+ }
2014
+ const result = await routeClient.get(route);
2015
+ (0, import_functions.waitUntil)(
2016
+ (async () => {
2017
+ await Promise.all([
2018
+ cacheNewRoute(result),
2019
+ disableSwrCache ? Promise.resolve() : cacheOldRoute(result)
2020
+ ]);
2021
+ })()
2022
+ );
2023
+ return result;
2024
+ }
2025
+ async getRoute(options) {
2026
+ if (options.source === "middleware") {
2027
+ return this.getRouteMiddleware(options);
2028
+ }
2029
+ return this.getRoutePageState(options);
2030
+ }
2031
+ async enhanceRoute(_options) {
2032
+ }
2033
+ async getRouteMiddleware(options) {
2034
+ const routeClient = getRouteClient({
2035
+ searchParams: options.searchParams,
2036
+ draftModeEnabled: options.draftModeEnabled
2037
+ });
2038
+ const resolvedRoute = await this.getRouteFromApi({
2039
+ source: "middleware",
2040
+ route: options.route,
2041
+ routeClient,
2042
+ // The runtime cache is keyed on the route path. Development bypasses it so an author sees
2043
+ // an edit right away, the same way the fetch cache is bypassed for development.
2044
+ enableRuntimeCache: options.route.state === CANVAS_PUBLISHED_STATE && getMiddlewareRuntimeCache() && !isDevelopmentEnvironment(),
2045
+ disableSwrCache: getDisableSwrMiddlewareCache()
2046
+ });
2047
+ if (resolvedRoute.type === "composition") {
2048
+ await this.enhanceRoute({
2049
+ source: "middleware",
2050
+ parameters: options.route,
2051
+ route: resolvedRoute,
2052
+ routeClient,
2053
+ keys: void 0
2054
+ });
2055
+ }
2056
+ return {
2057
+ route: resolvedRoute
2058
+ };
2059
+ }
2060
+ async getRoutePageState(options) {
2061
+ const shouldBypassCache = options.pageState.compositionState !== CANVAS_PUBLISHED_STATE || isDevelopmentEnvironment();
1361
2062
  const routeClient = getRouteClient({
1362
2063
  cache: shouldBypassCache ? {
1363
2064
  type: "no-cache",
@@ -1366,73 +2067,56 @@ var DefaultDataClient = class {
1366
2067
  type: "force-cache"
1367
2068
  }
1368
2069
  });
1369
- const parameters = {
1370
- path: pageState.routePath,
1371
- state: pageState.compositionState,
1372
- dataSourceVariant: getDataSourceVariantFromRouteGetParams({}, pageState.compositionState),
2070
+ const originalRoute = {
2071
+ path: options.pageState.routePath,
2072
+ state: options.pageState.compositionState,
2073
+ dataSourceVariant: getDataSourceVariantFromRouteGetParams({}, options.pageState.compositionState),
1373
2074
  withComponentIDs: true,
1374
- releaseId: pageState.releaseId,
1375
- locale: pageState.locale,
1376
- ignoreRedirects: shouldIgnoreRedirects({ state: pageState.compositionState })
2075
+ releaseId: options.pageState.releaseId,
2076
+ locale: options.pageState.locale,
2077
+ ignoreRedirects: shouldIgnoreRedirects({ state: options.pageState.compositionState })
1377
2078
  };
1378
- const route = await routeClient.get(parameters);
1379
- if (route.type === "composition") {
2079
+ const resolvedRoute = await this.getRouteFromApi({
2080
+ source: "pageState",
2081
+ route: originalRoute,
2082
+ routeClient,
2083
+ enableRuntimeCache: false,
2084
+ disableSwrCache: false
2085
+ });
2086
+ if (resolvedRoute.type === "composition") {
1380
2087
  await this.enhanceRoute({
1381
- parameters,
1382
- route,
2088
+ source: "pageState",
2089
+ parameters: originalRoute,
2090
+ route: resolvedRoute,
1383
2091
  routeClient,
1384
- keys: pageState.keys
2092
+ keys: options.pageState.keys
1385
2093
  });
1386
2094
  }
1387
2095
  return {
1388
- route
2096
+ route: resolvedRoute
1389
2097
  };
1390
2098
  }
1391
- async enhanceRoute(_options) {
1392
- }
1393
2099
  };
1394
2100
 
1395
2101
  // src/data/resolveRouteFromCode.ts
1396
- var REDIRECT_ORIGIN_PLACEHOLDER = "http://uniform.local";
1397
- var resolveRouteFromCode = async ({ code, dataClient: providedDataClient }) => {
1398
- const codePageState = (0, import_next_app_router_shared.deserializeEvaluationResult)({ input: code });
2102
+ var resolveRouteFromCode = async ({
2103
+ code,
2104
+ dataClient: providedDataClient
2105
+ }) => {
2106
+ const pageState = (0, import_next_app_router_shared.deserializeEvaluationResult)({ input: code });
1399
2107
  const dataClient = providedDataClient != null ? providedDataClient : new DefaultDataClient();
1400
- const states = codePageState.compositionState === CANVAS_EDITOR_STATE ? [CANVAS_EDITOR_STATE, CANVAS_DRAFT_STATE] : [codePageState.compositionState];
1401
- let pageState = codePageState;
1402
- let route = null;
1403
- for (const state of states) {
1404
- pageState = { ...codePageState, compositionState: state };
1405
- try {
1406
- ({ route } = await dataClient.getRoute({ pageState }));
1407
- } catch (e) {
1408
- console.warn(`Failed to retrieve route by path: ${pageState.routePath} with state ${state}`, e);
1409
- }
1410
- if (route && route.type !== "notFound") {
1411
- break;
1412
- }
1413
- }
1414
- if ((route == null ? void 0 : route.type) === "redirect") {
1415
- redirectToTarget({ route, routePath: pageState.routePath });
1416
- }
2108
+ const { route } = await dataClient.getRoute({
2109
+ source: "pageState",
2110
+ pageState
2111
+ });
1417
2112
  return {
1418
2113
  pageState,
2114
+ // suppress the route if it's not a composition
1419
2115
  route: (route == null ? void 0 : route.type) === "composition" ? route : void 0,
2116
+ // the code that was used to resolve the route
1420
2117
  code
1421
2118
  };
1422
2119
  };
1423
- var redirectToTarget = ({ route, routePath }) => {
1424
- const expanded = (0, import_redirect.getTargetVariableExpandedUrl)(
1425
- new URL(routePath, REDIRECT_ORIGIN_PLACEHOLDER).toString(),
1426
- route.redirect,
1427
- (pathSegment) => pathSegment.startsWith(":")
1428
- );
1429
- const href = expanded.startsWith(REDIRECT_ORIGIN_PLACEHOLDER) ? expanded.slice(REDIRECT_ORIGIN_PLACEHOLDER.length) || "/" : expanded;
1430
- const statusCode = route.redirect.targetStatusCode;
1431
- if (statusCode === 301 || statusCode === 308) {
1432
- (0, import_navigation.permanentRedirect)(href);
1433
- }
1434
- (0, import_navigation.redirect)(href);
1435
- };
1436
2120
 
1437
2121
  // src/cache.ts
1438
2122
  var resolveRouteFromCode2 = async ({