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

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.
@@ -525,11 +525,25 @@ async function handleRateLimits(callApi) {
525
525
  }
526
526
  const base = Math.pow(2, backoffRetries - backoffRetriesLeft) * 333;
527
527
  const backoffWait = base + Math.round(Math.random() * (base / 2)) * (Math.random() > 0.5 ? 1 : -1);
528
- await new Promise((resolve) => setTimeout(resolve, resetWait + backoffWait));
528
+ await new Promise((resolve) => setTimeout(resolve, Math.max(0, resetWait + backoffWait)));
529
529
  backoffRetriesLeft -= 1;
530
530
  }
531
531
  return response;
532
532
  }
533
+ var isPlainObject = (obj) => typeof obj === "object" && obj !== null && !Array.isArray(obj);
534
+ function rewriteFiltersForApi(filters) {
535
+ return Object.entries(filters != null ? filters : {}).reduce(
536
+ (acc, [key, value]) => {
537
+ const lhs = `filters.${key}` + (isPlainObject(value) ? `[${Object.keys(value)[0]}]` : "");
538
+ const rhs = isPlainObject(value) ? Object.values(value)[0] : value;
539
+ return {
540
+ ...acc,
541
+ [lhs]: Array.isArray(rhs) ? rhs.map((v) => `${v}`.trim()).join(",") : `${rhs}`.trim()
542
+ };
543
+ },
544
+ {}
545
+ );
546
+ }
533
547
  var _url;
534
548
  var _AggregateClient = class _AggregateClient2 extends ApiClient {
535
549
  constructor(options) {
@@ -1313,20 +1327,6 @@ function createLimitPolicy({
1313
1327
  return currentFunc();
1314
1328
  };
1315
1329
  }
1316
- var isPlainObject = (obj) => typeof obj === "object" && obj !== null && !Array.isArray(obj);
1317
- function rewriteFilters(filters) {
1318
- return Object.entries(filters != null ? filters : {}).reduce(
1319
- (acc, [key, value]) => {
1320
- const lhs = `filters.${key}` + (isPlainObject(value) ? `[${Object.keys(value)[0]}]` : "");
1321
- const rhs = isPlainObject(value) ? Object.values(value)[0] : value;
1322
- return {
1323
- ...acc,
1324
- [lhs]: Array.isArray(rhs) ? rhs.map((v) => `${v}`.trim()).join(",") : `${rhs}`.trim()
1325
- };
1326
- },
1327
- {}
1328
- );
1329
- }
1330
1330
  var CANVAS_URL = "/api/v1/canvas";
1331
1331
  var CanvasClient = class extends ApiClient {
1332
1332
  constructor(options) {
@@ -1342,7 +1342,7 @@ var CanvasClient = class extends ApiClient {
1342
1342
  async getCompositionList(params = {}) {
1343
1343
  const { projectId } = this.options;
1344
1344
  const { resolveData, filters, ...originParams } = params;
1345
- const rewrittenFilters = rewriteFilters(filters);
1345
+ const rewrittenFilters = rewriteFiltersForApi(filters);
1346
1346
  if (!resolveData) {
1347
1347
  const fetchUri = this.createUrl(CANVAS_URL, { ...originParams, projectId, ...rewrittenFilters });
1348
1348
  return this.apiClient(fetchUri);
@@ -1462,7 +1462,7 @@ var _ContentClient = class _ContentClient2 extends ApiClient {
1462
1462
  getEntries(options) {
1463
1463
  const { projectId } = this.options;
1464
1464
  const { skipDataResolution, filters, ...params } = options;
1465
- const rewrittenFilters = rewriteFilters(filters);
1465
+ const rewrittenFilters = rewriteFiltersForApi(filters);
1466
1466
  if (skipDataResolution) {
1467
1467
  const url = this.createUrl(__privateGet3(_ContentClient2, _entriesUrl), { ...params, ...rewrittenFilters, projectId });
1468
1468
  return this.apiClient(url);
@@ -1653,13 +1653,19 @@ function parseVariableExpression(serialized, onToken) {
1653
1653
  bufferEndIndex = index + 1;
1654
1654
  continue;
1655
1655
  }
1656
- state = "variable";
1657
- if (bufferEndIndex > bufferStartIndex) {
1656
+ if (state === "variable") {
1657
+ const textStart = bufferStartIndex - variablePrefix.length;
1658
+ if (handleToken(serialized.substring(textStart, bufferEndIndex), "text") === false) {
1659
+ return tokenCount;
1660
+ }
1661
+ bufferStartIndex = bufferEndIndex;
1662
+ } else if (bufferEndIndex > bufferStartIndex) {
1658
1663
  if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text") === false) {
1659
1664
  return tokenCount;
1660
1665
  }
1661
1666
  bufferStartIndex = bufferEndIndex;
1662
1667
  }
1668
+ state = "variable";
1663
1669
  index += variablePrefix.length - 1;
1664
1670
  bufferStartIndex += variablePrefix.length;
1665
1671
  continue;
@@ -1681,11 +1687,11 @@ function parseVariableExpression(serialized, onToken) {
1681
1687
  }
1682
1688
  bufferEndIndex++;
1683
1689
  }
1684
- if (bufferEndIndex > bufferStartIndex) {
1685
- if (state === "variable") {
1686
- state = "text";
1687
- bufferStartIndex -= variablePrefix.length;
1688
- }
1690
+ if (state === "variable") {
1691
+ state = "text";
1692
+ bufferStartIndex -= variablePrefix.length;
1693
+ }
1694
+ if (bufferStartIndex < serialized.length) {
1689
1695
  handleToken(serialized.substring(bufferStartIndex), state);
1690
1696
  }
1691
1697
  return tokenCount;
@@ -2087,11 +2093,34 @@ var stringOperatorEvaluators = {
2087
2093
  endswith: endsWithEvaluator,
2088
2094
  empty: emptyEvaluator
2089
2095
  };
2096
+ var numericOperatorEvaluators = {
2097
+ gt: (left, right) => left > right,
2098
+ lt: (left, right) => left < right
2099
+ };
2100
+ function evaluateNumericOperator(criteria, matchValue) {
2101
+ const { op, value } = criteria;
2102
+ const evaluator = numericOperatorEvaluators[op];
2103
+ if (!evaluator) {
2104
+ return null;
2105
+ }
2106
+ if (typeof matchValue === "string" && matchValue.trim() === "" || typeof value === "string" && value.trim() === "") {
2107
+ return false;
2108
+ }
2109
+ const leftNum = Number(matchValue);
2110
+ const rightNum = Number(value);
2111
+ if (isNaN(leftNum) || isNaN(rightNum)) {
2112
+ return false;
2113
+ }
2114
+ return evaluator(leftNum, rightNum);
2115
+ }
2090
2116
  function evaluateStringMatch(criteria, matchValue, allow) {
2091
2117
  const { op, value } = criteria;
2092
2118
  if (allow && !allow.has(op)) {
2093
2119
  return null;
2094
2120
  }
2121
+ if (op in numericOperatorEvaluators) {
2122
+ return evaluateNumericOperator(criteria, matchValue);
2123
+ }
2095
2124
  let opMatch = op;
2096
2125
  const negation = op.startsWith("!");
2097
2126
  if (negation) {
@@ -2168,6 +2197,7 @@ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2
2168
2197
  _baseUrl = /* @__PURE__ */ new WeakMap();
2169
2198
  __privateAdd3(_IntegrationPropertyEditorsClient, _baseUrl, "/api/v1/integration-property-editors");
2170
2199
  var _url22;
2200
+ var _projectsUrl;
2171
2201
  var _ProjectClient = class _ProjectClient2 extends ApiClient {
2172
2202
  constructor(options) {
2173
2203
  super({ ...options, bypassCache: true });
@@ -2177,6 +2207,15 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
2177
2207
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22), { ...options });
2178
2208
  return await this.apiClient(fetchUri);
2179
2209
  }
2210
+ /**
2211
+ * Fetches projects grouped by team.
2212
+ * When teamId is provided, returns a single team with its projects.
2213
+ * When omitted, returns all accessible teams and their projects.
2214
+ */
2215
+ async getProjects(options) {
2216
+ const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
2217
+ return await this.apiClient(fetchUri);
2218
+ }
2180
2219
  /** Updates or creates (based on id) a Project */
2181
2220
  async upsert(body) {
2182
2221
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
@@ -2196,7 +2235,9 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
2196
2235
  }
2197
2236
  };
2198
2237
  _url22 = /* @__PURE__ */ new WeakMap();
2238
+ _projectsUrl = /* @__PURE__ */ new WeakMap();
2199
2239
  __privateAdd3(_ProjectClient, _url22, "/api/v1/project");
2240
+ __privateAdd3(_ProjectClient, _projectsUrl, "/api/v1/projects");
2200
2241
  var ROUTE_URL = "/api/v1/route";
2201
2242
  var RouteClient = class extends ApiClient {
2202
2243
  constructor(options) {
@@ -2310,8 +2351,15 @@ var isIncontextEditingEnabled = ({
2310
2351
  var isDevelopmentEnvironment = () => {
2311
2352
  return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
2312
2353
  };
2354
+ var shouldIgnoreRedirects = ({ state }) => {
2355
+ const isNotPublished = state !== CANVAS_PUBLISHED_STATE;
2356
+ return isNotPublished ? true : void 0;
2357
+ };
2313
2358
 
2314
2359
  // src/clients/cache.ts
2360
+ var isSpecificCacheMode = (options) => {
2361
+ return "cache" in options;
2362
+ };
2315
2363
  var isStateCacheMode = (options) => {
2316
2364
  return "state" in options;
2317
2365
  };
@@ -2333,7 +2381,9 @@ var resolveCache = ({
2333
2381
  }) => {
2334
2382
  let cache = void 0;
2335
2383
  if (options) {
2336
- if (isStateCacheMode(options)) {
2384
+ if (isSpecificCacheMode(options)) {
2385
+ cache = options.cache;
2386
+ } else if (isStateCacheMode(options)) {
2337
2387
  if (options.state === CANVAS_DRAFT_STATE || options.state === CANVAS_EDITOR_STATE) {
2338
2388
  cache = {
2339
2389
  type: "no-cache",
@@ -2580,6 +2630,9 @@ var getQuirkSerialization = () => {
2580
2630
  return true;
2581
2631
  };
2582
2632
  var getMiddlewareRuntimeCache = () => {
2633
+ if (process.env.NODE_ENV === "development" && !process.env.RUNTIME_CACHE_ENDPOINT) {
2634
+ return false;
2635
+ }
2583
2636
  if (typeof import_resolved.default.middlewareRuntimeCache === "boolean") {
2584
2637
  return import_resolved.default.middlewareRuntimeCache;
2585
2638
  }
@@ -2725,7 +2778,10 @@ var DefaultDataClient = class {
2725
2778
  }
2726
2779
  }
2727
2780
  const manifest = await getManifest({
2728
- cache: {
2781
+ cache: isDevelopmentEnvironment() ? {
2782
+ type: "no-cache",
2783
+ bypassCache: true
2784
+ } : {
2729
2785
  type: "force-cache"
2730
2786
  }
2731
2787
  });
@@ -2828,12 +2884,13 @@ var DefaultDataClient = class {
2828
2884
  };
2829
2885
  }
2830
2886
  async getRoutePageState(options) {
2887
+ const shouldBypassCache = options.pageState.compositionState !== CANVAS_PUBLISHED_STATE || isDevelopmentEnvironment();
2831
2888
  const routeClient = getRouteClient({
2832
- cache: options.pageState.compositionState === CANVAS_PUBLISHED_STATE ? {
2833
- type: "force-cache"
2834
- } : {
2889
+ cache: shouldBypassCache ? {
2835
2890
  type: "no-cache",
2836
2891
  bypassCache: true
2892
+ } : {
2893
+ type: "force-cache"
2837
2894
  }
2838
2895
  });
2839
2896
  const originalRoute = {
@@ -2841,7 +2898,8 @@ var DefaultDataClient = class {
2841
2898
  state: options.pageState.compositionState,
2842
2899
  withComponentIDs: true,
2843
2900
  releaseId: options.pageState.releaseId,
2844
- locale: options.pageState.locale
2901
+ locale: options.pageState.locale,
2902
+ ignoreRedirects: shouldIgnoreRedirects({ state: options.pageState.compositionState })
2845
2903
  };
2846
2904
  const resolvedRoute = await this.getRouteFromApi({
2847
2905
  source: "pageState",
@@ -3015,7 +3073,8 @@ var import_next_app_router_shared4 = require("@uniformdev/next-app-router-shared
3015
3073
  var evaluateRunnables = async ({
3016
3074
  runnables,
3017
3075
  context,
3018
- compositionContext
3076
+ compositionContext,
3077
+ isPrefetch
3019
3078
  }) => {
3020
3079
  var _a;
3021
3080
  const result = {
@@ -3025,6 +3084,9 @@ var evaluateRunnables = async ({
3025
3084
  const runnablesToProcess = runnables.filter((item2) => item2.variantId === void 0);
3026
3085
  let item;
3027
3086
  while (item = runnablesToProcess.shift()) {
3087
+ if (item.type === "test" && isPrefetch) {
3088
+ continue;
3089
+ }
3028
3090
  if (item.type === "test") {
3029
3091
  const testResult = (0, import_next_app_router_shared4.evaluateTest)({
3030
3092
  context,
@@ -5386,7 +5448,8 @@ var retrieveRouteByPath = async ({
5386
5448
  withComponentIDs: true,
5387
5449
  withContentSourceMap: (_a = getServerConfig().experimental) == null ? void 0 : _a.vercelVisualEditing,
5388
5450
  releaseId,
5389
- locale
5451
+ locale,
5452
+ ignoreRedirects: shouldIgnoreRedirects({ state })
5390
5453
  }
5391
5454
  });
5392
5455
  };
@@ -5530,7 +5593,8 @@ var handlePlaygroundRequest = async ({
5530
5593
  searchParams: request.nextUrl.searchParams,
5531
5594
  isDraftModeEnabled: true
5532
5595
  // this is checked above
5533
- })
5596
+ }),
5597
+ isPrefetch: false
5534
5598
  });
5535
5599
  const pageState = {
5536
5600
  routePath: id,
@@ -5548,7 +5612,8 @@ var handlePlaygroundRequest = async ({
5548
5612
  // this is checked above
5549
5613
  }),
5550
5614
  rules,
5551
- locale: options.locale
5615
+ locale: options.locale,
5616
+ isPrefetch: void 0
5552
5617
  };
5553
5618
  const code = (0, import_next_app_router_shared5.serializeEvaluationResult)({
5554
5619
  payload: pageState
@@ -5597,7 +5662,7 @@ var handleRouteRequest = async ({
5597
5662
  })
5598
5663
  ]);
5599
5664
  if (!(routeResult == null ? void 0 : routeResult.route) || ((_d = routeResult == null ? void 0 : routeResult.route) == null ? void 0 : _d.type) === "notFound") {
5600
- return import_server.NextResponse.next();
5665
+ return import_server.NextResponse.rewrite(new URL("/404", request.url));
5601
5666
  }
5602
5667
  if (((_e = routeResult == null ? void 0 : routeResult.route) == null ? void 0 : _e.type) === "redirect") {
5603
5668
  return handleRedirect({ request, route: routeResult.route });
@@ -5632,6 +5697,7 @@ var handleRouteRequest = async ({
5632
5697
  searchParams: request.nextUrl.searchParams,
5633
5698
  isDraftModeEnabled: draftModeEnabled
5634
5699
  });
5700
+ const isPrefetch = isPrefetchRequest(request);
5635
5701
  const { components, rules } = await extractAndEvaluateRunnables({
5636
5702
  composition: route.compositionApiResponse.composition,
5637
5703
  routePath,
@@ -5649,7 +5715,8 @@ var handleRouteRequest = async ({
5649
5715
  searchParams: request.nextUrl.searchParams,
5650
5716
  isDraftModeEnabled: true
5651
5717
  // this is checked above
5652
- })
5718
+ }),
5719
+ isPrefetch
5653
5720
  });
5654
5721
  const pageState = {
5655
5722
  routePath,
@@ -5663,7 +5730,8 @@ var handleRouteRequest = async ({
5663
5730
  }),
5664
5731
  previewMode,
5665
5732
  rules,
5666
- locale: options.locale
5733
+ locale: options.locale,
5734
+ isPrefetch: isPrefetch || void 0
5667
5735
  };
5668
5736
  const code = (0, import_next_app_router_shared5.serializeEvaluationResult)({
5669
5737
  payload: pageState
@@ -5683,6 +5751,9 @@ var handleRouteRequest = async ({
5683
5751
  headers
5684
5752
  });
5685
5753
  };
5754
+ var isPrefetchRequest = (request) => {
5755
+ return request.headers.has("next-url");
5756
+ };
5686
5757
  var extractAndEvaluateRunnables = async ({
5687
5758
  composition,
5688
5759
  routePath,
@@ -5693,12 +5764,14 @@ var extractAndEvaluateRunnables = async ({
5693
5764
  releaseId,
5694
5765
  defaultConsent,
5695
5766
  keys,
5696
- previewMode
5767
+ previewMode,
5768
+ isPrefetch
5697
5769
  }) => {
5698
5770
  const extracted = extractRunnables(composition);
5699
5771
  const result = await evaluateRunnables({
5700
5772
  runnables: extracted,
5701
5773
  context,
5774
+ isPrefetch,
5702
5775
  compositionContext: {
5703
5776
  _id: composition._id,
5704
5777
  type: composition.type,
@@ -5716,7 +5789,8 @@ var extractAndEvaluateRunnables = async ({
5716
5789
  defaultConsent,
5717
5790
  previewMode,
5718
5791
  rules: void 0,
5719
- locale: void 0
5792
+ locale: void 0,
5793
+ isPrefetch: isPrefetch || void 0
5720
5794
  }
5721
5795
  }
5722
5796
  });