@uniformdev/next-app-router 20.7.1-alpha.123 → 20.7.1-alpha.136

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.
@@ -1608,6 +1608,9 @@ var CANVAS_PUBLISHED_STATE = 64;
1608
1608
  var CANVAS_EDITOR_STATE = 63;
1609
1609
  var CANVAS_PERSONALIZATION_PARAM = "$pzCrit";
1610
1610
  var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
1611
+ var CANVAS_INTERNAL_PARAM_PREFIX = "$internal_";
1612
+ var CANVAS_COMPONENT_DISPLAY_NAME_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}displayName`;
1613
+ var CANVAS_HYPOTHESIS_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}hypothesis`;
1611
1614
  var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1612
1615
  var IN_CONTEXT_EDITOR_FORCED_SETTINGS_QUERY_STRING_PARAM = "is_incontext_editing_forced_settings";
1613
1616
  var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
@@ -2288,19 +2291,19 @@ var buildCompositionTag = (compositionId) => {
2288
2291
  return `composition:${compositionId}`.toLowerCase();
2289
2292
  };
2290
2293
 
2291
- // src/config/helpers.ts
2292
- var import_uniform_server = __toESM(require("uniform.server.config"));
2293
- var getServerConfig = () => {
2294
- return import_uniform_server.default;
2295
- };
2296
-
2297
2294
  // src/utils/draft.ts
2298
2295
  var isDraftModeEnabled = ({
2299
2296
  draftModeEnabled
2300
2297
  }) => {
2301
2298
  return draftModeEnabled;
2302
2299
  };
2303
- var isIncontextEditingEnabled = ({ searchParams }) => {
2300
+ var isIncontextEditingEnabled = ({
2301
+ isDraftModeEnabled: isDraftModeEnabled2,
2302
+ searchParams
2303
+ }) => {
2304
+ if (!isDraftModeEnabled2) {
2305
+ return false;
2306
+ }
2304
2307
  const containsKey = searchParams.has(IN_CONTEXT_EDITOR_QUERY_STRING_PARAM);
2305
2308
  return containsKey;
2306
2309
  };
@@ -2309,9 +2312,6 @@ var isDevelopmentEnvironment = () => {
2309
2312
  };
2310
2313
 
2311
2314
  // src/clients/cache.ts
2312
- var isSpecificCacheMode = (options) => {
2313
- return "cache" in options;
2314
- };
2315
2315
  var isStateCacheMode = (options) => {
2316
2316
  return "state" in options;
2317
2317
  };
@@ -2320,25 +2320,20 @@ var isDetectCacheMode = (options) => {
2320
2320
  };
2321
2321
  var resolveManifestCache = (options) => {
2322
2322
  return resolveCache({
2323
- options,
2324
- defaultCache: getServerConfig().manifestCache
2323
+ options
2325
2324
  });
2326
2325
  };
2327
2326
  var resolveCanvasCache = (options) => {
2328
2327
  return resolveCache({
2329
- options,
2330
- defaultCache: getServerConfig().canvasCache
2328
+ options
2331
2329
  });
2332
2330
  };
2333
2331
  var resolveCache = ({
2334
- options,
2335
- defaultCache
2332
+ options
2336
2333
  }) => {
2337
- let cache = defaultCache;
2334
+ let cache = void 0;
2338
2335
  if (options) {
2339
- if (isSpecificCacheMode(options)) {
2340
- cache = options.cache;
2341
- } else if (isStateCacheMode(options)) {
2336
+ if (isStateCacheMode(options)) {
2342
2337
  if (options.state === CANVAS_DRAFT_STATE || options.state === CANVAS_EDITOR_STATE) {
2343
2338
  cache = {
2344
2339
  type: "no-cache",
@@ -2363,7 +2358,10 @@ var shouldCacheBeDisabled = (options) => {
2363
2358
  if (isDraftModeEnabled(options)) {
2364
2359
  return { disabled: true, reason: "DRAFT" };
2365
2360
  }
2366
- if (isIncontextEditingEnabled(options)) {
2361
+ if (isIncontextEditingEnabled({
2362
+ isDraftModeEnabled: options.draftModeEnabled,
2363
+ searchParams: options.searchParams
2364
+ })) {
2367
2365
  return { disabled: true, reason: "INCONTEXT" };
2368
2366
  }
2369
2367
  if (isDevelopmentEnvironment()) {
@@ -2564,10 +2562,47 @@ var getCanvasClient = (options) => {
2564
2562
  });
2565
2563
  };
2566
2564
 
2565
+ // src/config/helpers.ts
2566
+ var import_resolved = __toESM(require("@uniformdev/next-app-router/config/resolved"));
2567
+ var getServerConfig = () => {
2568
+ return import_resolved.default;
2569
+ };
2570
+ var getDefaultConsent = () => {
2571
+ if (typeof import_resolved.default.defaultConsent === "boolean") {
2572
+ return import_resolved.default.defaultConsent;
2573
+ }
2574
+ return false;
2575
+ };
2576
+ var getQuirkSerialization = () => {
2577
+ if (typeof import_resolved.default.quirkSerialization === "boolean") {
2578
+ return import_resolved.default.quirkSerialization;
2579
+ }
2580
+ return true;
2581
+ };
2582
+ var getMiddlewareRuntimeCache = () => {
2583
+ if (typeof import_resolved.default.middlewareRuntimeCache === "boolean") {
2584
+ return import_resolved.default.middlewareRuntimeCache;
2585
+ }
2586
+ return true;
2587
+ };
2588
+ var getPlaygroundPath = () => {
2589
+ if (typeof import_resolved.default.playgroundPath === "string") {
2590
+ return import_resolved.default.playgroundPath;
2591
+ }
2592
+ return "/uniform/playground";
2593
+ };
2594
+ var getDisableSwrMiddlewareCache = () => {
2595
+ var _a;
2596
+ if (typeof ((_a = import_resolved.default.experimental) == null ? void 0 : _a.disableSwrMiddlewareCache) === "boolean") {
2597
+ return import_resolved.default.experimental.disableSwrMiddlewareCache;
2598
+ }
2599
+ return false;
2600
+ };
2601
+
2567
2602
  // src/data/client.ts
2568
2603
  var import_functions = require("@vercel/functions");
2569
2604
 
2570
- // src/clients/route.ts
2605
+ // src/clients/manifest.ts
2571
2606
  var import_server_only2 = require("server-only");
2572
2607
 
2573
2608
  // src/clients/tags.ts
@@ -2588,7 +2623,47 @@ var generateManifestCacheTags = () => {
2588
2623
  return ["manifest"];
2589
2624
  };
2590
2625
 
2626
+ // src/clients/manifest.ts
2627
+ var getManifestClient = (options) => {
2628
+ const cache = resolveManifestCache(options);
2629
+ const manifestClient = new ManifestClient({
2630
+ apiHost: env.getApiHost(),
2631
+ apiKey: env.getApiKey(),
2632
+ projectId: env.getProjectId(),
2633
+ limitPolicy: createLimitPolicy2({
2634
+ limit: 6
2635
+ }),
2636
+ fetch: (req, init2) => {
2637
+ const { cache: fetchCache, revalidate } = determineFetchCacheOptions(cache);
2638
+ return fetch(req, {
2639
+ ...init2,
2640
+ headers: {
2641
+ ...init2 == null ? void 0 : init2.headers,
2642
+ "x-bypass-cache": typeof cache.bypassCache !== "undefined" ? cache.bypassCache.toString() : "false"
2643
+ },
2644
+ cache: fetchCache,
2645
+ next: {
2646
+ revalidate,
2647
+ tags: generateManifestCacheTags()
2648
+ }
2649
+ });
2650
+ }
2651
+ });
2652
+ return manifestClient;
2653
+ };
2654
+ var getManifest = async (options) => {
2655
+ let preview = false;
2656
+ if (options && isStateCacheMode(options)) {
2657
+ preview = options.state === CANVAS_DRAFT_STATE || options.state === CANVAS_EDITOR_STATE;
2658
+ }
2659
+ const manifestClient = getManifestClient(options);
2660
+ return manifestClient.get({
2661
+ preview
2662
+ });
2663
+ };
2664
+
2591
2665
  // src/clients/route.ts
2666
+ var import_server_only3 = require("server-only");
2592
2667
  var getRouteCacheTags = (requestedUrl) => {
2593
2668
  const tags = ["route"];
2594
2669
  if (requestedUrl) {
@@ -2638,52 +2713,11 @@ var getRouteClient = (options) => {
2638
2713
  return client;
2639
2714
  };
2640
2715
 
2641
- // src/clients/manifest.ts
2642
- var import_server_only3 = require("server-only");
2643
- var getManifestClient = (options) => {
2644
- const cache = resolveManifestCache(options);
2645
- const manifestClient = new ManifestClient({
2646
- apiHost: env.getApiHost(),
2647
- apiKey: env.getApiKey(),
2648
- projectId: env.getProjectId(),
2649
- limitPolicy: createLimitPolicy2({
2650
- limit: 6
2651
- }),
2652
- fetch: (req, init2) => {
2653
- const { cache: fetchCache, revalidate } = determineFetchCacheOptions(cache);
2654
- return fetch(req, {
2655
- ...init2,
2656
- headers: {
2657
- ...init2 == null ? void 0 : init2.headers,
2658
- "x-bypass-cache": typeof cache.bypassCache !== "undefined" ? cache.bypassCache.toString() : "false"
2659
- },
2660
- cache: fetchCache,
2661
- next: {
2662
- revalidate,
2663
- tags: generateManifestCacheTags()
2664
- }
2665
- });
2666
- }
2667
- });
2668
- return manifestClient;
2669
- };
2670
- var getManifest = async (options) => {
2671
- let preview = false;
2672
- if (options && isStateCacheMode(options)) {
2673
- preview = options.state === CANVAS_DRAFT_STATE || options.state === CANVAS_EDITOR_STATE;
2674
- }
2675
- const manifestClient = getManifestClient(options);
2676
- return manifestClient.get({
2677
- preview
2678
- });
2679
- };
2680
-
2681
2716
  // src/data/client.ts
2682
2717
  var MANIFEST_CACHE_KEY = "uniform-manifest";
2683
2718
  var DefaultDataClient = class {
2684
2719
  async getManifest(options) {
2685
- var _a, _b;
2686
- const cache = options.source === "middleware" && ((_b = (_a = getServerConfig().experimental) == null ? void 0 : _a.middlewareRuntimeCache) != null ? _b : false) ? (0, import_functions.getCache)() : null;
2720
+ const cache = options.source === "middleware" && getMiddlewareRuntimeCache() ? (0, import_functions.getCache)() : null;
2687
2721
  if (cache) {
2688
2722
  const cachedManifest = await cache.get(MANIFEST_CACHE_KEY);
2689
2723
  if (cachedManifest) {
@@ -2769,18 +2803,16 @@ var DefaultDataClient = class {
2769
2803
  async enhanceRoute(_options3) {
2770
2804
  }
2771
2805
  async getRouteMiddleware(options) {
2772
- var _a, _b, _c, _d;
2773
2806
  const routeClient = getRouteClient({
2774
2807
  searchParams: options.searchParams,
2775
2808
  draftModeEnabled: options.draftModeEnabled
2776
2809
  });
2777
- const config = getServerConfig();
2778
2810
  const resolvedRoute = await this.getRouteFromApi({
2779
2811
  source: "middleware",
2780
2812
  route: options.route,
2781
2813
  routeClient,
2782
- enableRuntimeCache: options.route.state === CANVAS_PUBLISHED_STATE && ((_b = (_a = config.experimental) == null ? void 0 : _a.middlewareRuntimeCache) != null ? _b : false),
2783
- disableSwrCache: (_d = (_c = config.experimental) == null ? void 0 : _c.disableSwrMiddlewareCache) != null ? _d : false
2814
+ enableRuntimeCache: options.route.state === CANVAS_PUBLISHED_STATE && getMiddlewareRuntimeCache(),
2815
+ disableSwrCache: getDisableSwrMiddlewareCache()
2784
2816
  });
2785
2817
  if (resolvedRoute.type === "composition") {
2786
2818
  await this.enhanceRoute({
@@ -2796,12 +2828,12 @@ var DefaultDataClient = class {
2796
2828
  };
2797
2829
  }
2798
2830
  async getRoutePageState(options) {
2799
- var _a;
2800
2831
  const routeClient = getRouteClient({
2801
- cache: options.pageState.compositionState === CANVAS_PUBLISHED_STATE ? (_a = getServerConfig().canvasCache) != null ? _a : {
2832
+ cache: options.pageState.compositionState === CANVAS_PUBLISHED_STATE ? {
2802
2833
  type: "force-cache"
2803
2834
  } : {
2804
- type: "no-cache"
2835
+ type: "no-cache",
2836
+ bypassCache: true
2805
2837
  }
2806
2838
  });
2807
2839
  const originalRoute = {
@@ -5265,18 +5297,17 @@ var OnDemandContext = class {
5265
5297
  __privateSet(this, _options2, options);
5266
5298
  }
5267
5299
  async getContext() {
5268
- var _a, _b, _c, _d, _e;
5300
+ var _a, _b, _c;
5269
5301
  if (!this._context) {
5270
5302
  const uniformCookie = __privateGet(this, _options2).cookies.get(UNIFORM_DEFAULT_COOKIE_NAME);
5271
5303
  const quirkCookie = __privateGet(this, _options2).cookies.get(UNIFORM_DEFAULT_QUIRK_COOKIE_NAME);
5272
- const serverConfig2 = getServerConfig();
5273
5304
  this._context = new Context({
5274
5305
  manifest: __privateGet(this, _options2).manifest,
5275
- defaultConsent: (_b = (_a = __privateGet(this, _options2).defaultConsent) != null ? _a : serverConfig2.defaultConsent) != null ? _b : false,
5306
+ defaultConsent: (_a = __privateGet(this, _options2).defaultConsent) != null ? _a : getDefaultConsent(),
5276
5307
  transitionStore: new CookieTransitionDataStore({
5277
- serverCookieValue: (_c = uniformCookie == null ? void 0 : uniformCookie.value) != null ? _c : "",
5278
- experimental_quirksEnabled: (_d = serverConfig2.experimental) == null ? void 0 : _d.quirkSerialization,
5279
- quirkCookieValue: (_e = quirkCookie == null ? void 0 : quirkCookie.value) != null ? _e : ""
5308
+ serverCookieValue: (_b = uniformCookie == null ? void 0 : uniformCookie.value) != null ? _b : "",
5309
+ experimental_quirksEnabled: getQuirkSerialization(),
5310
+ quirkCookieValue: (_c = quirkCookie == null ? void 0 : quirkCookie.value) != null ? _c : ""
5280
5311
  })
5281
5312
  });
5282
5313
  }
@@ -5368,6 +5399,7 @@ var determineState = async ({
5368
5399
  draftModeEnabled
5369
5400
  });
5370
5401
  const isCanvasEditing = isIncontextEditingEnabled({
5402
+ isDraftModeEnabled: draftModeEnabled,
5371
5403
  searchParams
5372
5404
  });
5373
5405
  return isDraftMode ? (isCanvasEditing ? [CANVAS_EDITOR_STATE] : []).concat([CANVAS_DRAFT_STATE]) : [CANVAS_PUBLISHED_STATE];
@@ -5430,7 +5462,7 @@ var handlePlaygroundRequest = async ({
5430
5462
  options,
5431
5463
  dataClient
5432
5464
  }) => {
5433
- var _a, _b, _c;
5465
+ var _a, _b;
5434
5466
  const id = request.nextUrl.searchParams.get("id");
5435
5467
  if (!id) {
5436
5468
  return import_server.NextResponse.json(
@@ -5470,12 +5502,13 @@ var handlePlaygroundRequest = async ({
5470
5502
  { status: 404 }
5471
5503
  );
5472
5504
  }
5473
- const serverConfig2 = getServerConfig();
5505
+ const serverConfig = getServerConfig();
5506
+ const playgroundPath = getPlaygroundPath();
5474
5507
  const onDemandContext = await createOnDemandContext({
5475
5508
  cookies: request.cookies,
5476
5509
  dataClient,
5477
5510
  defaultConsent: determineDefaultConsent({
5478
- serverConfig: serverConfig2,
5511
+ serverConfig,
5479
5512
  defaultConsent: options.defaultConsent
5480
5513
  })
5481
5514
  });
@@ -5489,7 +5522,7 @@ var handlePlaygroundRequest = async ({
5489
5522
  dynamicInputs: {},
5490
5523
  releaseId: (_a = options.release) == null ? void 0 : _a.id,
5491
5524
  defaultConsent: determineDefaultConsent({
5492
- serverConfig: serverConfig2,
5525
+ serverConfig,
5493
5526
  defaultConsent: options.defaultConsent
5494
5527
  }),
5495
5528
  keys: void 0,
@@ -5506,7 +5539,7 @@ var handlePlaygroundRequest = async ({
5506
5539
  keys: void 0,
5507
5540
  releaseId: (_b = options.release) == null ? void 0 : _b.id,
5508
5541
  defaultConsent: determineDefaultConsent({
5509
- serverConfig: serverConfig2,
5542
+ serverConfig,
5510
5543
  defaultConsent: options.defaultConsent
5511
5544
  }),
5512
5545
  previewMode: determinePreviewMode({
@@ -5522,7 +5555,7 @@ var handlePlaygroundRequest = async ({
5522
5555
  });
5523
5556
  let pathToRewriteTo = await (options.rewriteDestinationPath ? options.rewriteDestinationPath({ code, pageState, source: "playground" }) : void 0);
5524
5557
  if (!pathToRewriteTo) {
5525
- pathToRewriteTo = `${serverConfig2.playgroundPath}${((_c = serverConfig2.playgroundPath) == null ? void 0 : _c.endsWith("/")) ? "" : "/"}${code}`;
5558
+ pathToRewriteTo = `${playgroundPath}${(playgroundPath == null ? void 0 : playgroundPath.endsWith("/")) ? "" : "/"}${code}`;
5526
5559
  }
5527
5560
  return import_server.NextResponse.rewrite(new URL(pathToRewriteTo, request.nextUrl.origin));
5528
5561
  };
@@ -5543,7 +5576,7 @@ var handleRouteRequest = async ({
5543
5576
  }))) != null ? _b : {
5544
5577
  path: `${request.nextUrl.pathname}${request.nextUrl.search}`
5545
5578
  };
5546
- const serverConfig2 = getServerConfig();
5579
+ const serverConfig = getServerConfig();
5547
5580
  const [routeResult, onDemandContext] = await Promise.all([
5548
5581
  resolveRoute({
5549
5582
  path: requestPath.path,
@@ -5558,7 +5591,7 @@ var handleRouteRequest = async ({
5558
5591
  cookies: request.cookies,
5559
5592
  dataClient,
5560
5593
  defaultConsent: determineDefaultConsent({
5561
- serverConfig: serverConfig2,
5594
+ serverConfig,
5562
5595
  defaultConsent: options.defaultConsent
5563
5596
  })
5564
5597
  })
@@ -5608,7 +5641,7 @@ var handleRouteRequest = async ({
5608
5641
  dynamicInputs: (_f = route.dynamicInputs) != null ? _f : {},
5609
5642
  releaseId: (_g = options.release) == null ? void 0 : _g.id,
5610
5643
  defaultConsent: determineDefaultConsent({
5611
- serverConfig: serverConfig2,
5644
+ serverConfig,
5612
5645
  defaultConsent: options.defaultConsent
5613
5646
  }),
5614
5647
  keys: requestPath.keys,
@@ -5625,7 +5658,7 @@ var handleRouteRequest = async ({
5625
5658
  keys: requestPath.keys,
5626
5659
  releaseId: (_h = options.release) == null ? void 0 : _h.id,
5627
5660
  defaultConsent: determineDefaultConsent({
5628
- serverConfig: serverConfig2,
5661
+ serverConfig,
5629
5662
  defaultConsent: options.defaultConsent
5630
5663
  }),
5631
5664
  previewMode,
@@ -5724,8 +5757,8 @@ var buildRoutePath = ({
5724
5757
  }
5725
5758
  return ((_b2 = (_a2 = node.locales) == null ? void 0 : _a2[locale]) == null ? void 0 : _b2.path) === route.matchedRoute;
5726
5759
  });
5760
+ const searchParams = new URLSearchParams();
5727
5761
  if ((_c = projectMapNode == null ? void 0 : projectMapNode.data) == null ? void 0 : _c.queryStrings) {
5728
- const searchParams = new URLSearchParams();
5729
5762
  if (search) {
5730
5763
  const existingSearchParams = new URLSearchParams(search);
5731
5764
  for (const [key, value] of existingSearchParams.entries()) {
@@ -5738,17 +5771,20 @@ var buildRoutePath = ({
5738
5771
  searchParams.set(qs.name, qsValue != null ? qsValue : "");
5739
5772
  }
5740
5773
  }
5741
- if (searchParams.size) {
5742
- return `${routePath}?${searchParams.toString()}`;
5743
- }
5774
+ }
5775
+ if (process.env.NODE_ENV === "development") {
5776
+ searchParams.set("cache", (/* @__PURE__ */ new Date()).valueOf().toString());
5777
+ }
5778
+ if (searchParams.size) {
5779
+ return `${routePath}?${searchParams.toString()}`;
5744
5780
  }
5745
5781
  return routePath;
5746
5782
  };
5747
5783
  var determineDefaultConsent = ({
5748
- serverConfig: serverConfig2,
5784
+ serverConfig,
5749
5785
  defaultConsent
5750
5786
  }) => {
5751
- return defaultConsent !== serverConfig2.defaultConsent ? defaultConsent : void 0;
5787
+ return defaultConsent !== serverConfig.defaultConsent ? defaultConsent : void 0;
5752
5788
  };
5753
5789
  var determinePreviewMode = ({
5754
5790
  searchParams,
@@ -5768,7 +5804,7 @@ var determinePreviewMode = ({
5768
5804
  if (previewSettings == null ? void 0 : previewSettings.isVisualEditingDisabled) {
5769
5805
  return "preview";
5770
5806
  }
5771
- const isInContextEditingEnabled = isIncontextEditingEnabled({ searchParams });
5807
+ const isInContextEditingEnabled = isIncontextEditingEnabled({ isDraftModeEnabled: isDraftModeEnabled2, searchParams });
5772
5808
  if (isInContextEditingEnabled) {
5773
5809
  return "editor";
5774
5810
  }