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

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,124 +47,6 @@ 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
-
168
50
  // ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js
169
51
  var require_retry_operation = __commonJS({
170
52
  "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js"(exports2, module2) {
@@ -403,436 +285,9 @@ __export(cache_exports, {
403
285
  });
404
286
  module.exports = __toCommonJS(cache_exports);
405
287
 
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");
288
+ // ../canvas/dist/index.mjs
289
+ var import_api = require("@uniformdev/context/api");
290
+ var import_api2 = require("@uniformdev/context/api");
836
291
 
837
292
  // ../../node_modules/.pnpm/yocto-queue@1.2.2/node_modules/yocto-queue/index.js
838
293
  var Node = class {
@@ -905,7 +360,7 @@ _tail = new WeakMap();
905
360
  _size = new WeakMap();
906
361
 
907
362
  // ../../node_modules/.pnpm/p-limit@6.2.0/node_modules/p-limit/index.js
908
- function pLimit2(concurrency) {
363
+ function pLimit(concurrency) {
909
364
  validateConcurrency(concurrency);
910
365
  const queue = new Queue();
911
366
  let activeCount = 0;
@@ -1185,19 +640,44 @@ function pThrottle({ limit, interval, strict, onDelay }) {
1185
640
  }
1186
641
 
1187
642
  // ../canvas/dist/index.mjs
1188
- var __typeError3 = (msg) => {
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) => {
1189
669
  throw TypeError(msg);
1190
670
  };
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);
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);
1194
674
  function createLimitPolicy({
1195
675
  throttle = { interval: 1e3, limit: 10 },
1196
676
  retry: retry3 = { retries: 1, factor: 1.66 },
1197
677
  limit = 10
1198
678
  }) {
1199
679
  const throttler = throttle ? pThrottle(throttle) : null;
1200
- const limiter = limit ? pLimit2(limit) : null;
680
+ const limiter = limit ? pLimit(limit) : null;
1201
681
  return function limitPolicy(func) {
1202
682
  let currentFunc = async () => await func();
1203
683
  if (throttler) {
@@ -1216,7 +696,7 @@ function createLimitPolicy({
1216
696
  if (retry3.onFailedAttempt) {
1217
697
  await retry3.onFailedAttempt(error);
1218
698
  }
1219
- if (error instanceof ApiClientError && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
699
+ if (error instanceof import_api2.ApiClientError && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
1220
700
  throw error;
1221
701
  }
1222
702
  }
@@ -1279,7 +759,7 @@ var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1279
759
  var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
1280
760
  var _contentTypesUrl;
1281
761
  var _entriesUrl;
1282
- var _ContentClient = class _ContentClient2 extends ApiClient {
762
+ var _ContentClient = class _ContentClient2 extends import_api12.ApiClient {
1283
763
  constructor(options) {
1284
764
  var _a;
1285
765
  super(options);
@@ -1287,16 +767,16 @@ var _ContentClient = class _ContentClient2 extends ApiClient {
1287
767
  }
1288
768
  getContentTypes(options) {
1289
769
  const { projectId } = this.options;
1290
- const fetchUri = this.createUrl(__privateGet3(_ContentClient2, _contentTypesUrl), { ...options, projectId });
770
+ const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _contentTypesUrl), { ...options, projectId });
1291
771
  return this.apiClient(fetchUri);
1292
772
  }
1293
773
  getEntries(options) {
1294
774
  const { projectId } = this.options;
1295
775
  const { skipDataResolution, filters, select, ...params } = options;
1296
- const rewrittenFilters = rewriteFiltersForApi(filters);
776
+ const rewrittenFilters = (0, import_api12.rewriteFiltersForApi)(filters);
1297
777
  const rewrittenSelect = projectionToQuery(select);
1298
778
  if (skipDataResolution) {
1299
- const url = this.createUrl(__privateGet3(_ContentClient2, _entriesUrl), {
779
+ const url = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl), {
1300
780
  ...params,
1301
781
  ...rewrittenFilters,
1302
782
  ...rewrittenSelect,
@@ -1305,7 +785,7 @@ var _ContentClient = class _ContentClient2 extends ApiClient {
1305
785
  return this.apiClient(url);
1306
786
  }
1307
787
  const edgeUrl = this.createUrl(
1308
- __privateGet3(_ContentClient2, _entriesUrl),
788
+ __privateGet2(_ContentClient2, _entriesUrl),
1309
789
  { ...this.getEdgeOptions(params), ...rewrittenFilters, ...rewrittenSelect },
1310
790
  this.edgeApiHost
1311
791
  );
@@ -1323,7 +803,7 @@ var _ContentClient = class _ContentClient2 extends ApiClient {
1323
803
  return this.apiClient(historyUrl);
1324
804
  }
1325
805
  async upsertContentType(body, opts = {}) {
1326
- const fetchUri = this.createUrl(__privateGet3(_ContentClient2, _contentTypesUrl));
806
+ const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _contentTypesUrl));
1327
807
  if (typeof body.contentType.slugSettings === "object" && body.contentType.slugSettings !== null && Object.keys(body.contentType.slugSettings).length === 0) {
1328
808
  delete body.contentType.slugSettings;
1329
809
  }
@@ -1335,7 +815,7 @@ var _ContentClient = class _ContentClient2 extends ApiClient {
1335
815
  });
1336
816
  }
1337
817
  async upsertEntry(body, options) {
1338
- const fetchUri = this.createUrl(__privateGet3(_ContentClient2, _entriesUrl));
818
+ const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl));
1339
819
  const headers = {};
1340
820
  if (options == null ? void 0 : options.ifUnmodifiedSince) {
1341
821
  headers["x-if-unmodified-since"] = options.ifUnmodifiedSince;
@@ -1349,7 +829,7 @@ var _ContentClient = class _ContentClient2 extends ApiClient {
1349
829
  return { modified: response.headers.get("x-modified-at") };
1350
830
  }
1351
831
  async deleteContentType(body) {
1352
- const fetchUri = this.createUrl(__privateGet3(_ContentClient2, _contentTypesUrl));
832
+ const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _contentTypesUrl));
1353
833
  await this.apiClient(fetchUri, {
1354
834
  method: "DELETE",
1355
835
  body: JSON.stringify({ ...body, projectId: this.options.projectId }),
@@ -1357,7 +837,7 @@ var _ContentClient = class _ContentClient2 extends ApiClient {
1357
837
  });
1358
838
  }
1359
839
  async deleteEntry(body) {
1360
- const fetchUri = this.createUrl(__privateGet3(_ContentClient2, _entriesUrl));
840
+ const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl));
1361
841
  await this.apiClient(fetchUri, {
1362
842
  method: "DELETE",
1363
843
  body: JSON.stringify({ ...body, projectId: this.options.projectId }),
@@ -1376,17 +856,17 @@ var _ContentClient = class _ContentClient2 extends ApiClient {
1376
856
  };
1377
857
  _contentTypesUrl = /* @__PURE__ */ new WeakMap();
1378
858
  _entriesUrl = /* @__PURE__ */ new WeakMap();
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 {
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 {
1383
863
  constructor(options) {
1384
864
  super(options);
1385
865
  }
1386
866
  /** Fetches a list of DataTypes for a project */
1387
867
  async list(options) {
1388
868
  const { projectId } = this.options;
1389
- const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8), { ...options, projectId });
869
+ const fetchUri = this.createUrl(__privateGet2(_DataTypeClient2, _url), { ...options, projectId });
1390
870
  return await this.apiClient(fetchUri);
1391
871
  }
1392
872
  /** @deprecated Use {@link list} instead. */
@@ -1395,7 +875,7 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1395
875
  }
1396
876
  /** Updates or creates (based on id) a DataType */
1397
877
  async save(body) {
1398
- const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
878
+ const fetchUri = this.createUrl(__privateGet2(_DataTypeClient2, _url));
1399
879
  await this.apiClient(fetchUri, {
1400
880
  method: "PUT",
1401
881
  body: JSON.stringify({ ...body, projectId: this.options.projectId }),
@@ -1408,7 +888,7 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1408
888
  }
1409
889
  /** Deletes a DataType */
1410
890
  async remove(body) {
1411
- const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
891
+ const fetchUri = this.createUrl(__privateGet2(_DataTypeClient2, _url));
1412
892
  await this.apiClient(fetchUri, {
1413
893
  method: "DELETE",
1414
894
  body: JSON.stringify({ ...body, projectId: this.options.projectId }),
@@ -1416,10 +896,10 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1416
896
  });
1417
897
  }
1418
898
  };
1419
- _url8 = /* @__PURE__ */ new WeakMap();
1420
- __privateAdd3(_DataTypeClient, _url8, "/api/v1/data-types");
899
+ _url = /* @__PURE__ */ new WeakMap();
900
+ __privateAdd2(_DataTypeClient, _url, "/api/v1/data-types");
1421
901
  var _baseUrl;
1422
- var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2 extends ApiClient {
902
+ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2 extends import_api16.ApiClient {
1423
903
  constructor(options) {
1424
904
  super(options);
1425
905
  this.teamId = options.teamId;
@@ -1428,7 +908,7 @@ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2
1428
908
  * Gets a list of property type and hook names for the current team, including public integrations' hooks.
1429
909
  */
1430
910
  get(options) {
1431
- const fetchUri = this.createUrl(__privateGet3(_IntegrationPropertyEditorsClient2, _baseUrl), {
911
+ const fetchUri = this.createUrl(__privateGet2(_IntegrationPropertyEditorsClient2, _baseUrl), {
1432
912
  ...options,
1433
913
  teamId: this.teamId
1434
914
  });
@@ -1438,7 +918,7 @@ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2
1438
918
  * Creates or updates a custom AI property editor on a Mesh app.
1439
919
  */
1440
920
  async deploy(body) {
1441
- const fetchUri = this.createUrl(__privateGet3(_IntegrationPropertyEditorsClient2, _baseUrl));
921
+ const fetchUri = this.createUrl(__privateGet2(_IntegrationPropertyEditorsClient2, _baseUrl));
1442
922
  await this.apiClient(fetchUri, {
1443
923
  method: "PUT",
1444
924
  body: JSON.stringify({ ...body, teamId: this.teamId }),
@@ -1449,7 +929,7 @@ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2
1449
929
  * Removes a custom AI property editor from a Mesh app.
1450
930
  */
1451
931
  async delete(body) {
1452
- const fetchUri = this.createUrl(__privateGet3(_IntegrationPropertyEditorsClient2, _baseUrl));
932
+ const fetchUri = this.createUrl(__privateGet2(_IntegrationPropertyEditorsClient2, _baseUrl));
1453
933
  await this.apiClient(fetchUri, {
1454
934
  method: "DELETE",
1455
935
  body: JSON.stringify({ ...body, teamId: this.teamId }),
@@ -1458,16 +938,16 @@ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2
1458
938
  }
1459
939
  };
1460
940
  _baseUrl = /* @__PURE__ */ new WeakMap();
1461
- __privateAdd3(_IntegrationPropertyEditorsClient, _baseUrl, "/api/v1/integration-property-editors");
1462
- var _url22;
941
+ __privateAdd2(_IntegrationPropertyEditorsClient, _baseUrl, "/api/v1/integration-property-editors");
942
+ var _url2;
1463
943
  var _projectsUrl;
1464
- var _ProjectClient = class _ProjectClient2 extends ApiClient {
944
+ var _ProjectClient = class _ProjectClient2 extends import_api20.ApiClient {
1465
945
  constructor(options) {
1466
946
  super({ ...options, bypassCache: true });
1467
947
  }
1468
948
  /** Fetches single Project */
1469
949
  async get(options) {
1470
- const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22), { ...options });
950
+ const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _url2), { ...options });
1471
951
  return await this.apiClient(fetchUri);
1472
952
  }
1473
953
  /**
@@ -1476,7 +956,7 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
1476
956
  * When omitted, returns all accessible teams and their projects.
1477
957
  */
1478
958
  async list(options) {
1479
- const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
959
+ const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
1480
960
  return await this.apiClient(fetchUri);
1481
961
  }
1482
962
  /** @deprecated Use {@link list} instead. */
@@ -1485,7 +965,7 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
1485
965
  }
1486
966
  /** Updates or creates (based on id) a Project */
1487
967
  async save(body) {
1488
- const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
968
+ const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _url2));
1489
969
  return await this.apiClient(fetchUri, {
1490
970
  method: "PUT",
1491
971
  body: JSON.stringify({ ...body })
@@ -1497,7 +977,7 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
1497
977
  }
1498
978
  /** Deletes a Project */
1499
979
  async remove(body) {
1500
- const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
980
+ const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _url2));
1501
981
  await this.apiClient(fetchUri, {
1502
982
  method: "DELETE",
1503
983
  body: JSON.stringify({ ...body }),
@@ -1509,12 +989,12 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
1509
989
  return this.remove(body);
1510
990
  }
1511
991
  };
1512
- _url22 = /* @__PURE__ */ new WeakMap();
992
+ _url2 = /* @__PURE__ */ new WeakMap();
1513
993
  _projectsUrl = /* @__PURE__ */ new WeakMap();
1514
- __privateAdd3(_ProjectClient, _url22, "/api/v1/project");
1515
- __privateAdd3(_ProjectClient, _projectsUrl, "/api/v1/projects");
994
+ __privateAdd2(_ProjectClient, _url2, "/api/v1/project");
995
+ __privateAdd2(_ProjectClient, _projectsUrl, "/api/v1/projects");
1516
996
  var ROUTE_URL = "/api/v1/route";
1517
- var RouteClient = class extends ApiClient {
997
+ var RouteClient = class extends import_api25.ApiClient {
1518
998
  constructor(options) {
1519
999
  var _a;
1520
1000
  if (!options.limitPolicy) {
@@ -1557,10 +1037,12 @@ var getDataSourceVariantFromRouteGetParams = (params, defaultPreviewState) => {
1557
1037
  return dataSourceVariant;
1558
1038
  };
1559
1039
 
1560
- // src/data/client.ts
1561
- var import_functions = require("@vercel/functions");
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");
1562
1044
 
1563
- // src/clients/manifest.ts
1045
+ // src/clients/route.ts
1564
1046
  var import_server_only = require("server-only");
1565
1047
 
1566
1048
  // src/utils/env.ts
@@ -1613,11 +1095,6 @@ var isStateCacheMode = (options) => {
1613
1095
  var isDetectCacheMode = (options) => {
1614
1096
  return "searchParams" in options && "draftModeEnabled" in options;
1615
1097
  };
1616
- var resolveManifestCache = (options) => {
1617
- return resolveCache({
1618
- options
1619
- });
1620
- };
1621
1098
  var resolveCanvasCache = (options) => {
1622
1099
  return resolveCache({
1623
1100
  options
@@ -1685,6 +1162,7 @@ var determineFetchCacheOptions = (mode) => {
1685
1162
  };
1686
1163
 
1687
1164
  // src/clients/retry.ts
1165
+ var import_api28 = require("@uniformdev/context/api");
1688
1166
  function createThrottler(limit, interval) {
1689
1167
  let available = limit;
1690
1168
  let refillScheduled = false;
@@ -1795,7 +1273,7 @@ function createLimitPolicy2({
1795
1273
  if (retryOptions.onFailedAttempt) {
1796
1274
  await retryOptions.onFailedAttempt(error);
1797
1275
  }
1798
- if (error instanceof ApiClientError && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
1276
+ if (error instanceof import_api28.ApiClientError && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
1799
1277
  throw error;
1800
1278
  }
1801
1279
  }
@@ -1812,8 +1290,8 @@ var buildPathTag = (path) => {
1812
1290
  };
1813
1291
 
1814
1292
  // src/clients/tags.ts
1815
- var generateRouteCacheTags = ({ path, old }) => {
1816
- const tags = old ? ["route-old"] : ["route"];
1293
+ var generateRouteCacheTags = ({ path }) => {
1294
+ const tags = ["route"];
1817
1295
  if (path) {
1818
1296
  const pathWithoutQuery = path.split("?")[0];
1819
1297
  const pieces = pathWithoutQuery.split("/");
@@ -1825,51 +1303,8 @@ var generateRouteCacheTags = ({ path, old }) => {
1825
1303
  }
1826
1304
  return tags;
1827
1305
  };
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
- };
1870
1306
 
1871
1307
  // src/clients/route.ts
1872
- var import_server_only2 = require("server-only");
1873
1308
  var getRouteCacheTags = (requestedUrl) => {
1874
1309
  const tags = ["route"];
1875
1310
  if (requestedUrl) {
@@ -1919,146 +1354,10 @@ var getRouteClient = (options) => {
1919
1354
  return client;
1920
1355
  };
1921
1356
 
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
-
1941
1357
  // src/data/client.ts
1942
- var MANIFEST_CACHE_KEY = "uniform-manifest";
1943
1358
  var DefaultDataClient = class {
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();
1359
+ async getRoute({ pageState }) {
1360
+ const shouldBypassCache = pageState.compositionState !== CANVAS_PUBLISHED_STATE || isDevelopmentEnvironment();
2062
1361
  const routeClient = getRouteClient({
2063
1362
  cache: shouldBypassCache ? {
2064
1363
  type: "no-cache",
@@ -2067,56 +1366,73 @@ var DefaultDataClient = class {
2067
1366
  type: "force-cache"
2068
1367
  }
2069
1368
  });
2070
- const originalRoute = {
2071
- path: options.pageState.routePath,
2072
- state: options.pageState.compositionState,
2073
- dataSourceVariant: getDataSourceVariantFromRouteGetParams({}, options.pageState.compositionState),
1369
+ const parameters = {
1370
+ path: pageState.routePath,
1371
+ state: pageState.compositionState,
1372
+ dataSourceVariant: getDataSourceVariantFromRouteGetParams({}, pageState.compositionState),
2074
1373
  withComponentIDs: true,
2075
- releaseId: options.pageState.releaseId,
2076
- locale: options.pageState.locale,
2077
- ignoreRedirects: shouldIgnoreRedirects({ state: options.pageState.compositionState })
1374
+ releaseId: pageState.releaseId,
1375
+ locale: pageState.locale,
1376
+ ignoreRedirects: shouldIgnoreRedirects({ state: pageState.compositionState })
2078
1377
  };
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") {
1378
+ const route = await routeClient.get(parameters);
1379
+ if (route.type === "composition") {
2087
1380
  await this.enhanceRoute({
2088
- source: "pageState",
2089
- parameters: originalRoute,
2090
- route: resolvedRoute,
1381
+ parameters,
1382
+ route,
2091
1383
  routeClient,
2092
- keys: options.pageState.keys
1384
+ keys: pageState.keys
2093
1385
  });
2094
1386
  }
2095
1387
  return {
2096
- route: resolvedRoute
1388
+ route
2097
1389
  };
2098
1390
  }
1391
+ async enhanceRoute(_options) {
1392
+ }
2099
1393
  };
2100
1394
 
2101
1395
  // src/data/resolveRouteFromCode.ts
2102
- var resolveRouteFromCode = async ({
2103
- code,
2104
- dataClient: providedDataClient
2105
- }) => {
2106
- const pageState = (0, import_next_app_router_shared.deserializeEvaluationResult)({ input: code });
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 });
2107
1399
  const dataClient = providedDataClient != null ? providedDataClient : new DefaultDataClient();
2108
- const { route } = await dataClient.getRoute({
2109
- source: "pageState",
2110
- pageState
2111
- });
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
+ }
2112
1417
  return {
2113
1418
  pageState,
2114
- // suppress the route if it's not a composition
2115
1419
  route: (route == null ? void 0 : route.type) === "composition" ? route : void 0,
2116
- // the code that was used to resolve the route
2117
1420
  code
2118
1421
  };
2119
1422
  };
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
+ };
2120
1436
 
2121
1437
  // src/cache.ts
2122
1438
  var resolveRouteFromCode2 = async ({