@uniformdev/next-app-router 20.77.0 → 20.77.1-alpha.10.sha-3381091ae6

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.
@@ -2999,7 +2999,9 @@ var DefaultDataClient = class {
2999
2999
  source: "middleware",
3000
3000
  route: options.route,
3001
3001
  routeClient,
3002
- enableRuntimeCache: options.route.state === CANVAS_PUBLISHED_STATE && getMiddlewareRuntimeCache(),
3002
+ // The runtime cache is keyed on the route path. Development bypasses it so an author sees
3003
+ // an edit right away, the same way the fetch cache is bypassed for development.
3004
+ enableRuntimeCache: options.route.state === CANVAS_PUBLISHED_STATE && getMiddlewareRuntimeCache() && !isDevelopmentEnvironment(),
3003
3005
  disableSwrCache: getDisableSwrMiddlewareCache()
3004
3006
  });
3005
3007
  if (resolvedRoute.type === "composition") {
@@ -3056,6 +3058,75 @@ var DefaultDataClient = class {
3056
3058
  }
3057
3059
  };
3058
3060
 
3061
+ // src/middleware/composition/evaluate/evaluateRunnables.ts
3062
+ import {
3063
+ evaluatePersonalization,
3064
+ evaluateTest
3065
+ } from "@uniformdev/next-app-router-shared";
3066
+ var evaluateRunnables = async ({
3067
+ runnables,
3068
+ context,
3069
+ compositionContext,
3070
+ isPrefetch
3071
+ }) => {
3072
+ var _a;
3073
+ const result = {
3074
+ components: {},
3075
+ rules: void 0
3076
+ };
3077
+ const runnablesToProcess = runnables.filter((item2) => item2.variantId === void 0);
3078
+ let item;
3079
+ while (item = runnablesToProcess.shift()) {
3080
+ if (item.type === "test" && isPrefetch) {
3081
+ continue;
3082
+ }
3083
+ if (item.type === "test") {
3084
+ const testResult = evaluateTest({
3085
+ context,
3086
+ test: item.result,
3087
+ compositionContext
3088
+ });
3089
+ if (testResult.index !== null) {
3090
+ result.components[item._id] = {
3091
+ indexes: [testResult.index]
3092
+ };
3093
+ if (testResult.componentId) {
3094
+ const dependentRunnables = runnables.filter((r) => r.variantId === testResult.componentId);
3095
+ runnablesToProcess.push(...dependentRunnables);
3096
+ }
3097
+ }
3098
+ } else if (item.type === "personalization") {
3099
+ const personalizationResult = evaluatePersonalization({
3100
+ context,
3101
+ personalization: item.result,
3102
+ compositionContext
3103
+ });
3104
+ if (personalizationResult.indexes.length) {
3105
+ result.components[item._id] = {
3106
+ indexes: personalizationResult.indexes
3107
+ };
3108
+ }
3109
+ if (personalizationResult.componentIds.length) {
3110
+ const dependentRunnables = runnables.filter(
3111
+ (r) => r.variantId && personalizationResult.componentIds.includes(r.variantId)
3112
+ );
3113
+ runnablesToProcess.push(...dependentRunnables);
3114
+ }
3115
+ } else if (item.type === "visibility") {
3116
+ const rules = createQuirksVisibilityRule(context.quirks);
3117
+ const isVisible = evaluateNodeVisibilityParameter({
3118
+ rules,
3119
+ parameter: item.rules
3120
+ });
3121
+ if (isVisible !== null) {
3122
+ result.rules = (_a = result.rules) != null ? _a : {};
3123
+ result.rules[item._id] = isVisible;
3124
+ }
3125
+ }
3126
+ }
3127
+ return result;
3128
+ };
3129
+
3059
3130
  // src/data/extract/extractRunnables.ts
3060
3131
  import { getRuleId } from "@uniformdev/next-app-router-shared";
3061
3132
 
@@ -3172,6 +3243,41 @@ var extractRunnables = (composition) => {
3172
3243
  return runnable;
3173
3244
  };
3174
3245
 
3246
+ // src/data/evaluate/evaluatePageState.ts
3247
+ var evaluatePageState = async ({
3248
+ composition,
3249
+ matchedRoute,
3250
+ dynamicInputs,
3251
+ pageState,
3252
+ context
3253
+ }) => {
3254
+ const extracted = extractRunnables(composition);
3255
+ const result = await evaluateRunnables({
3256
+ runnables: extracted,
3257
+ context,
3258
+ isPrefetch: pageState.isPrefetch,
3259
+ compositionContext: {
3260
+ _id: composition._id,
3261
+ type: composition.type,
3262
+ state: pageState.compositionState,
3263
+ isContextualEditing: pageState.compositionState === CANVAS_EDITOR_STATE,
3264
+ matchedRoute,
3265
+ dynamicInputs,
3266
+ pageState: {
3267
+ ...pageState,
3268
+ // empty for now, we need to pass composition metadata down to evaluateRunnables for Context events enrichment
3269
+ components: {},
3270
+ rules: void 0
3271
+ }
3272
+ }
3273
+ });
3274
+ const allComponentIds = extracted.filter((r) => r.type === "test" || r.type === "personalization").map((r) => r._id);
3275
+ return {
3276
+ ...result,
3277
+ allComponentIds
3278
+ };
3279
+ };
3280
+
3175
3281
  // src/data/routes.ts
3176
3282
  var findRouteMatch = (routes, path) => {
3177
3283
  const pieces = path.split("/").filter(Boolean);
@@ -3203,75 +3309,6 @@ var findRouteMatch = (routes, path) => {
3203
3309
  return void 0;
3204
3310
  };
3205
3311
 
3206
- // src/middleware/composition/evaluate/evaluateRunnables.ts
3207
- import {
3208
- evaluatePersonalization,
3209
- evaluateTest
3210
- } from "@uniformdev/next-app-router-shared";
3211
- var evaluateRunnables = async ({
3212
- runnables,
3213
- context,
3214
- compositionContext,
3215
- isPrefetch
3216
- }) => {
3217
- var _a;
3218
- const result = {
3219
- components: {},
3220
- rules: void 0
3221
- };
3222
- const runnablesToProcess = runnables.filter((item2) => item2.variantId === void 0);
3223
- let item;
3224
- while (item = runnablesToProcess.shift()) {
3225
- if (item.type === "test" && isPrefetch) {
3226
- continue;
3227
- }
3228
- if (item.type === "test") {
3229
- const testResult = evaluateTest({
3230
- context,
3231
- test: item.result,
3232
- compositionContext
3233
- });
3234
- if (testResult.index !== null) {
3235
- result.components[item._id] = {
3236
- indexes: [testResult.index]
3237
- };
3238
- if (testResult.componentId) {
3239
- const dependentRunnables = runnables.filter((r) => r.variantId === testResult.componentId);
3240
- runnablesToProcess.push(...dependentRunnables);
3241
- }
3242
- }
3243
- } else if (item.type === "personalization") {
3244
- const personalizationResult = evaluatePersonalization({
3245
- context,
3246
- personalization: item.result,
3247
- compositionContext
3248
- });
3249
- if (personalizationResult.indexes.length) {
3250
- result.components[item._id] = {
3251
- indexes: personalizationResult.indexes
3252
- };
3253
- }
3254
- if (personalizationResult.componentIds.length) {
3255
- const dependentRunnables = runnables.filter(
3256
- (r) => r.variantId && personalizationResult.componentIds.includes(r.variantId)
3257
- );
3258
- runnablesToProcess.push(...dependentRunnables);
3259
- }
3260
- } else if (item.type === "visibility") {
3261
- const rules = createQuirksVisibilityRule(context.quirks);
3262
- const isVisible = evaluateNodeVisibilityParameter({
3263
- rules,
3264
- parameter: item.rules
3265
- });
3266
- if (isVisible !== null) {
3267
- result.rules = (_a = result.rules) != null ? _a : {};
3268
- result.rules[item._id] = isVisible;
3269
- }
3270
- }
3271
- }
3272
- return result;
3273
- };
3274
-
3275
3312
  // ../../node_modules/.pnpm/dequal@2.0.3/node_modules/dequal/lite/index.mjs
3276
3313
  var has = Object.prototype.hasOwnProperty;
3277
3314
  function dequal(foo, bar) {
@@ -5480,7 +5517,8 @@ var dc2 = (0, import_rfdc3.default)();
5480
5517
 
5481
5518
  // src/middleware/context/index.ts
5482
5519
  var createOnDemandContext = async (options) => {
5483
- const manifest = await options.dataClient.getManifest({ source: "middleware" });
5520
+ var _a;
5521
+ const manifest = await options.dataClient.getManifest({ source: (_a = options.source) != null ? _a : "middleware" });
5484
5522
  if (!manifest) {
5485
5523
  console.error("Uniform manifest not found, falling back to empty manifest");
5486
5524
  }
@@ -5604,6 +5642,22 @@ var determineState = async ({
5604
5642
  return isDraftMode ? (isCanvasEditing ? [CANVAS_EDITOR_STATE] : []).concat([CANVAS_DRAFT_STATE]) : [CANVAS_PUBLISHED_STATE];
5605
5643
  };
5606
5644
 
5645
+ // src/utils/quirks.ts
5646
+ var buildQuirksFromHeaders = (headers) => {
5647
+ const headerToQuirkKey = {
5648
+ "x-vercel-ip-country": "vc-country",
5649
+ "x-vercel-ip-country-region": "vc-region",
5650
+ "x-vercel-ip-city": "vc-city"
5651
+ };
5652
+ return Object.entries(headerToQuirkKey).reduce((acc, [headerName, quirkKey]) => {
5653
+ const value = headers.get(headerName);
5654
+ if (value) {
5655
+ acc[quirkKey] = value;
5656
+ }
5657
+ return acc;
5658
+ }, {});
5659
+ };
5660
+
5607
5661
  // src/middleware.ts
5608
5662
  var uniformMiddleware = (options) => {
5609
5663
  return async (request) => {
@@ -5642,26 +5696,11 @@ var isPlaygroundPath = (path) => {
5642
5696
  );
5643
5697
  return (match == null ? void 0 : match.route.id) === PLAYGROUND_ID ? match : void 0;
5644
5698
  };
5645
- var buildQuirksFromHeaders = (headers) => {
5646
- const headerToQuirkKey = {
5647
- "x-vercel-ip-country": "vc-country",
5648
- "x-vercel-ip-country-region": "vc-region",
5649
- "x-vercel-ip-city": "vc-city"
5650
- };
5651
- return Object.entries(headerToQuirkKey).reduce((acc, [headerName, quirkKey]) => {
5652
- const value = headers.get(headerName);
5653
- if (value) {
5654
- acc[quirkKey] = value;
5655
- }
5656
- return acc;
5657
- }, {});
5658
- };
5659
5699
  var handlePlaygroundRequest = async ({
5660
5700
  request,
5661
- options,
5662
- dataClient
5701
+ options
5663
5702
  }) => {
5664
- var _a, _b;
5703
+ var _a;
5665
5704
  const id = request.nextUrl.searchParams.get("id");
5666
5705
  if (!id) {
5667
5706
  return NextResponse.json(
@@ -5703,41 +5742,12 @@ var handlePlaygroundRequest = async ({
5703
5742
  }
5704
5743
  const serverConfig = getServerConfig();
5705
5744
  const playgroundPath = getPlaygroundPath();
5706
- const onDemandContext = await createOnDemandContext({
5707
- cookies: request.cookies,
5708
- dataClient,
5709
- defaultConsent: determineDefaultConsent({
5710
- serverConfig,
5711
- defaultConsent: options.defaultConsent
5712
- })
5713
- });
5714
- const context = await onDemandContext.getContext();
5715
- const { components, rules, allComponentIds } = await extractAndEvaluateRunnables({
5716
- composition: composition.composition,
5717
- routePath: id,
5718
- state: composition.state,
5719
- context,
5720
- matchedRoute: id,
5721
- dynamicInputs: {},
5722
- releaseId: (_a = options.release) == null ? void 0 : _a.id,
5723
- defaultConsent: determineDefaultConsent({
5724
- serverConfig,
5725
- defaultConsent: options.defaultConsent
5726
- }),
5727
- keys: void 0,
5728
- previewMode: determinePreviewMode({
5729
- searchParams: request.nextUrl.searchParams,
5730
- isDraftModeEnabled: true
5731
- // this is checked above
5732
- }),
5733
- isPrefetch: false
5734
- });
5735
5745
  const pageState = {
5736
5746
  routePath: id,
5737
5747
  compositionState: composition.state,
5738
- components,
5748
+ components: {},
5739
5749
  keys: void 0,
5740
- releaseId: (_b = options.release) == null ? void 0 : _b.id,
5750
+ releaseId: (_a = options.release) == null ? void 0 : _a.id,
5741
5751
  defaultConsent: determineDefaultConsent({
5742
5752
  serverConfig,
5743
5753
  defaultConsent: options.defaultConsent
@@ -5747,13 +5757,13 @@ var handlePlaygroundRequest = async ({
5747
5757
  isDraftModeEnabled: true
5748
5758
  // this is checked above
5749
5759
  }),
5750
- rules,
5760
+ rules: void 0,
5751
5761
  locale: options.locale,
5752
- isPrefetch: void 0
5762
+ isPrefetch: void 0,
5763
+ requestPath: `${request.nextUrl.pathname}${request.nextUrl.search}`
5753
5764
  };
5754
5765
  const code = serializeEvaluationResult({
5755
- payload: pageState,
5756
- allComponentIds
5766
+ payload: pageState
5757
5767
  });
5758
5768
  let pathToRewriteTo = await (options.rewriteDestinationPath ? options.rewriteDestinationPath({ code, pageState, source: "playground" }) : void 0);
5759
5769
  if (!pathToRewriteTo) {
@@ -5836,30 +5846,10 @@ var handleRouteRequest = async ({
5836
5846
  isDraftModeEnabled: draftModeEnabled
5837
5847
  });
5838
5848
  const isPrefetch = isPrefetchRequest(request);
5839
- const { components, rules, allComponentIds } = await extractAndEvaluateRunnables({
5840
- composition: route.compositionApiResponse.composition,
5841
- routePath,
5842
- state,
5843
- context,
5844
- matchedRoute: route.matchedRoute,
5845
- dynamicInputs: (_g = route.dynamicInputs) != null ? _g : {},
5846
- releaseId,
5847
- defaultConsent: determineDefaultConsent({
5848
- serverConfig,
5849
- defaultConsent: options.defaultConsent
5850
- }),
5851
- keys: requestPath.keys,
5852
- previewMode: determinePreviewMode({
5853
- searchParams: request.nextUrl.searchParams,
5854
- isDraftModeEnabled: true
5855
- // this is checked above
5856
- }),
5857
- isPrefetch
5858
- });
5859
- const pageState = {
5849
+ const basePageState = {
5860
5850
  routePath,
5861
5851
  compositionState: state,
5862
- components,
5852
+ components: {},
5863
5853
  keys: requestPath.keys,
5864
5854
  releaseId,
5865
5855
  defaultConsent: determineDefaultConsent({
@@ -5867,10 +5857,32 @@ var handleRouteRequest = async ({
5867
5857
  defaultConsent: options.defaultConsent
5868
5858
  }),
5869
5859
  previewMode,
5870
- rules,
5860
+ rules: void 0,
5871
5861
  locale: options.locale,
5872
- isPrefetch: isPrefetch || void 0
5862
+ isPrefetch: isPrefetch || void 0,
5863
+ // Draft requests evaluate while the page renders, so they carry with them the inputs that
5864
+ // cannot be derived again there: the request path, and any custom quirks the consumer
5865
+ // supplied to the middleware. Quirks from request headers are rebuilt at render time.
5866
+ requestPath: draftModeEnabled ? `${request.nextUrl.pathname}${request.nextUrl.search}` : void 0,
5867
+ quirks: draftModeEnabled ? options.quirks : void 0
5873
5868
  };
5869
+ let pageState = basePageState;
5870
+ let allComponentIds = void 0;
5871
+ if (!draftModeEnabled) {
5872
+ const evaluated = await evaluatePageState({
5873
+ composition: route.compositionApiResponse.composition,
5874
+ matchedRoute: route.matchedRoute,
5875
+ dynamicInputs: (_g = route.dynamicInputs) != null ? _g : {},
5876
+ pageState: basePageState,
5877
+ context
5878
+ });
5879
+ pageState = {
5880
+ ...basePageState,
5881
+ components: evaluated.components,
5882
+ rules: evaluated.rules
5883
+ };
5884
+ allComponentIds = evaluated.allComponentIds;
5885
+ }
5874
5886
  const code = serializeEvaluationResult({
5875
5887
  payload: pageState,
5876
5888
  allComponentIds
@@ -5893,49 +5905,6 @@ var handleRouteRequest = async ({
5893
5905
  var isPrefetchRequest = (request) => {
5894
5906
  return request.headers.has("next-url");
5895
5907
  };
5896
- var extractAndEvaluateRunnables = async ({
5897
- composition,
5898
- routePath,
5899
- context,
5900
- state,
5901
- matchedRoute,
5902
- dynamicInputs,
5903
- releaseId,
5904
- defaultConsent,
5905
- keys,
5906
- previewMode,
5907
- isPrefetch
5908
- }) => {
5909
- const extracted = extractRunnables(composition);
5910
- const result = await evaluateRunnables({
5911
- runnables: extracted,
5912
- context,
5913
- isPrefetch,
5914
- compositionContext: {
5915
- _id: composition._id,
5916
- type: composition.type,
5917
- state,
5918
- isContextualEditing: state === CANVAS_EDITOR_STATE,
5919
- matchedRoute,
5920
- dynamicInputs,
5921
- pageState: {
5922
- routePath,
5923
- compositionState: state,
5924
- // empty for now, we need to pass composition metadata down to evaluateRunnables for Context events enrichment
5925
- components: {},
5926
- keys,
5927
- releaseId,
5928
- defaultConsent,
5929
- previewMode,
5930
- rules: void 0,
5931
- locale: void 0,
5932
- isPrefetch: isPrefetch || void 0
5933
- }
5934
- }
5935
- });
5936
- const allComponentIds = extracted.filter((r) => r.type === "test" || r.type === "personalization").map((r) => r._id);
5937
- return { ...result, allComponentIds };
5938
- };
5939
5908
  var handleRedirect = ({ request, route }) => {
5940
5909
  const href = resolveRedirectHref({
5941
5910
  resolveResult: route,
@@ -5958,7 +5927,7 @@ var buildRoutePath = ({
5958
5927
  pathname,
5959
5928
  route
5960
5929
  }) => {
5961
- var _a, _b, _c;
5930
+ var _a, _b, _c, _d;
5962
5931
  const [routePath, search] = pathname.split("?");
5963
5932
  const locale = (_a = route.dynamicInputs) == null ? void 0 : _a.locale;
5964
5933
  const projectMapNode = (_b = route.compositionApiResponse.composition.projectMapNodes) == null ? void 0 : _b.find((node) => {
@@ -5973,22 +5942,12 @@ var buildRoutePath = ({
5973
5942
  });
5974
5943
  const searchParams = new URLSearchParams();
5975
5944
  if ((_c = projectMapNode == null ? void 0 : projectMapNode.data) == null ? void 0 : _c.queryStrings) {
5976
- if (search) {
5977
- const existingSearchParams = new URLSearchParams(search);
5978
- for (const [key, value] of existingSearchParams.entries()) {
5979
- searchParams.set(key, value);
5980
- }
5981
- }
5945
+ const existingSearchParams = search ? new URLSearchParams(search) : void 0;
5982
5946
  for (const qs of projectMapNode.data.queryStrings) {
5983
- if (!searchParams.has(qs.name)) {
5984
- const qsValue = qs.value;
5985
- searchParams.set(qs.name, qsValue != null ? qsValue : "");
5986
- }
5947
+ const existingValue = existingSearchParams == null ? void 0 : existingSearchParams.get(qs.name);
5948
+ searchParams.set(qs.name, (_d = existingValue != null ? existingValue : qs.value) != null ? _d : "");
5987
5949
  }
5988
5950
  }
5989
- if (process.env.NODE_ENV === "development") {
5990
- searchParams.set("cache", (/* @__PURE__ */ new Date()).valueOf().toString());
5991
- }
5992
5951
  if (searchParams.size) {
5993
5952
  return `${routePath}?${searchParams.toString()}`;
5994
5953
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/next-app-router",
3
- "version": "20.77.0",
3
+ "version": "20.77.1-alpha.10.sha-3381091ae6",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "scripts": {
6
6
  "build": "tsup",
@@ -100,12 +100,12 @@
100
100
  "vitest": "4.1.11"
101
101
  },
102
102
  "dependencies": {
103
- "@uniformdev/canvas-react": "20.77.0",
104
- "@uniformdev/next-app-router-client": "20.77.0",
105
- "@uniformdev/next-app-router-shared": "20.77.0",
106
- "@uniformdev/redirect": "20.77.0",
107
- "@uniformdev/richtext": "20.77.0",
108
- "@uniformdev/webhooks": "20.77.0",
103
+ "@uniformdev/canvas-react": "20.77.1-alpha.10.sha-3381091ae6",
104
+ "@uniformdev/next-app-router-client": "20.77.1-alpha.10.sha-3381091ae6",
105
+ "@uniformdev/next-app-router-shared": "20.77.1-alpha.10.sha-3381091ae6",
106
+ "@uniformdev/redirect": "20.77.1-alpha.10.sha-3381091ae6",
107
+ "@uniformdev/richtext": "20.77.1-alpha.10.sha-3381091ae6",
108
+ "@uniformdev/webhooks": "20.77.1-alpha.10.sha-3381091ae6",
109
109
  "@vercel/functions": "^3.7.2",
110
110
  "encoding": "^0.1.13",
111
111
  "server-only": "^0.0.1",
@@ -122,5 +122,5 @@
122
122
  "publishConfig": {
123
123
  "access": "public"
124
124
  },
125
- "gitHead": "f994c88e282d803eae476fb5078e106ab66c38e0"
125
+ "gitHead": "3381091ae65d8f50effdea93e6971c369203ecaf"
126
126
  }