@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.
@@ -510,11 +510,25 @@ async function handleRateLimits(callApi) {
510
510
  }
511
511
  const base = Math.pow(2, backoffRetries - backoffRetriesLeft) * 333;
512
512
  const backoffWait = base + Math.round(Math.random() * (base / 2)) * (Math.random() > 0.5 ? 1 : -1);
513
- await new Promise((resolve) => setTimeout(resolve, resetWait + backoffWait));
513
+ await new Promise((resolve) => setTimeout(resolve, Math.max(0, resetWait + backoffWait)));
514
514
  backoffRetriesLeft -= 1;
515
515
  }
516
516
  return response;
517
517
  }
518
+ var isPlainObject = (obj) => typeof obj === "object" && obj !== null && !Array.isArray(obj);
519
+ function rewriteFiltersForApi(filters) {
520
+ return Object.entries(filters != null ? filters : {}).reduce(
521
+ (acc, [key, value]) => {
522
+ const lhs = `filters.${key}` + (isPlainObject(value) ? `[${Object.keys(value)[0]}]` : "");
523
+ const rhs = isPlainObject(value) ? Object.values(value)[0] : value;
524
+ return {
525
+ ...acc,
526
+ [lhs]: Array.isArray(rhs) ? rhs.map((v) => `${v}`.trim()).join(",") : `${rhs}`.trim()
527
+ };
528
+ },
529
+ {}
530
+ );
531
+ }
518
532
  var _url;
519
533
  var _AggregateClient = class _AggregateClient2 extends ApiClient {
520
534
  constructor(options) {
@@ -1298,20 +1312,6 @@ function createLimitPolicy({
1298
1312
  return currentFunc();
1299
1313
  };
1300
1314
  }
1301
- var isPlainObject = (obj) => typeof obj === "object" && obj !== null && !Array.isArray(obj);
1302
- function rewriteFilters(filters) {
1303
- return Object.entries(filters != null ? filters : {}).reduce(
1304
- (acc, [key, value]) => {
1305
- const lhs = `filters.${key}` + (isPlainObject(value) ? `[${Object.keys(value)[0]}]` : "");
1306
- const rhs = isPlainObject(value) ? Object.values(value)[0] : value;
1307
- return {
1308
- ...acc,
1309
- [lhs]: Array.isArray(rhs) ? rhs.map((v) => `${v}`.trim()).join(",") : `${rhs}`.trim()
1310
- };
1311
- },
1312
- {}
1313
- );
1314
- }
1315
1315
  var CANVAS_URL = "/api/v1/canvas";
1316
1316
  var CanvasClient = class extends ApiClient {
1317
1317
  constructor(options) {
@@ -1327,7 +1327,7 @@ var CanvasClient = class extends ApiClient {
1327
1327
  async getCompositionList(params = {}) {
1328
1328
  const { projectId } = this.options;
1329
1329
  const { resolveData, filters, ...originParams } = params;
1330
- const rewrittenFilters = rewriteFilters(filters);
1330
+ const rewrittenFilters = rewriteFiltersForApi(filters);
1331
1331
  if (!resolveData) {
1332
1332
  const fetchUri = this.createUrl(CANVAS_URL, { ...originParams, projectId, ...rewrittenFilters });
1333
1333
  return this.apiClient(fetchUri);
@@ -1447,7 +1447,7 @@ var _ContentClient = class _ContentClient2 extends ApiClient {
1447
1447
  getEntries(options) {
1448
1448
  const { projectId } = this.options;
1449
1449
  const { skipDataResolution, filters, ...params } = options;
1450
- const rewrittenFilters = rewriteFilters(filters);
1450
+ const rewrittenFilters = rewriteFiltersForApi(filters);
1451
1451
  if (skipDataResolution) {
1452
1452
  const url = this.createUrl(__privateGet3(_ContentClient2, _entriesUrl), { ...params, ...rewrittenFilters, projectId });
1453
1453
  return this.apiClient(url);
@@ -1638,13 +1638,19 @@ function parseVariableExpression(serialized, onToken) {
1638
1638
  bufferEndIndex = index + 1;
1639
1639
  continue;
1640
1640
  }
1641
- state = "variable";
1642
- if (bufferEndIndex > bufferStartIndex) {
1641
+ if (state === "variable") {
1642
+ const textStart = bufferStartIndex - variablePrefix.length;
1643
+ if (handleToken(serialized.substring(textStart, bufferEndIndex), "text") === false) {
1644
+ return tokenCount;
1645
+ }
1646
+ bufferStartIndex = bufferEndIndex;
1647
+ } else if (bufferEndIndex > bufferStartIndex) {
1643
1648
  if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text") === false) {
1644
1649
  return tokenCount;
1645
1650
  }
1646
1651
  bufferStartIndex = bufferEndIndex;
1647
1652
  }
1653
+ state = "variable";
1648
1654
  index += variablePrefix.length - 1;
1649
1655
  bufferStartIndex += variablePrefix.length;
1650
1656
  continue;
@@ -1666,11 +1672,11 @@ function parseVariableExpression(serialized, onToken) {
1666
1672
  }
1667
1673
  bufferEndIndex++;
1668
1674
  }
1669
- if (bufferEndIndex > bufferStartIndex) {
1670
- if (state === "variable") {
1671
- state = "text";
1672
- bufferStartIndex -= variablePrefix.length;
1673
- }
1675
+ if (state === "variable") {
1676
+ state = "text";
1677
+ bufferStartIndex -= variablePrefix.length;
1678
+ }
1679
+ if (bufferStartIndex < serialized.length) {
1674
1680
  handleToken(serialized.substring(bufferStartIndex), state);
1675
1681
  }
1676
1682
  return tokenCount;
@@ -2072,11 +2078,34 @@ var stringOperatorEvaluators = {
2072
2078
  endswith: endsWithEvaluator,
2073
2079
  empty: emptyEvaluator
2074
2080
  };
2081
+ var numericOperatorEvaluators = {
2082
+ gt: (left, right) => left > right,
2083
+ lt: (left, right) => left < right
2084
+ };
2085
+ function evaluateNumericOperator(criteria, matchValue) {
2086
+ const { op, value } = criteria;
2087
+ const evaluator = numericOperatorEvaluators[op];
2088
+ if (!evaluator) {
2089
+ return null;
2090
+ }
2091
+ if (typeof matchValue === "string" && matchValue.trim() === "" || typeof value === "string" && value.trim() === "") {
2092
+ return false;
2093
+ }
2094
+ const leftNum = Number(matchValue);
2095
+ const rightNum = Number(value);
2096
+ if (isNaN(leftNum) || isNaN(rightNum)) {
2097
+ return false;
2098
+ }
2099
+ return evaluator(leftNum, rightNum);
2100
+ }
2075
2101
  function evaluateStringMatch(criteria, matchValue, allow) {
2076
2102
  const { op, value } = criteria;
2077
2103
  if (allow && !allow.has(op)) {
2078
2104
  return null;
2079
2105
  }
2106
+ if (op in numericOperatorEvaluators) {
2107
+ return evaluateNumericOperator(criteria, matchValue);
2108
+ }
2080
2109
  let opMatch = op;
2081
2110
  const negation = op.startsWith("!");
2082
2111
  if (negation) {
@@ -2153,6 +2182,7 @@ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2
2153
2182
  _baseUrl = /* @__PURE__ */ new WeakMap();
2154
2183
  __privateAdd3(_IntegrationPropertyEditorsClient, _baseUrl, "/api/v1/integration-property-editors");
2155
2184
  var _url22;
2185
+ var _projectsUrl;
2156
2186
  var _ProjectClient = class _ProjectClient2 extends ApiClient {
2157
2187
  constructor(options) {
2158
2188
  super({ ...options, bypassCache: true });
@@ -2162,6 +2192,15 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
2162
2192
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22), { ...options });
2163
2193
  return await this.apiClient(fetchUri);
2164
2194
  }
2195
+ /**
2196
+ * Fetches projects grouped by team.
2197
+ * When teamId is provided, returns a single team with its projects.
2198
+ * When omitted, returns all accessible teams and their projects.
2199
+ */
2200
+ async getProjects(options) {
2201
+ const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
2202
+ return await this.apiClient(fetchUri);
2203
+ }
2165
2204
  /** Updates or creates (based on id) a Project */
2166
2205
  async upsert(body) {
2167
2206
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
@@ -2181,7 +2220,9 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
2181
2220
  }
2182
2221
  };
2183
2222
  _url22 = /* @__PURE__ */ new WeakMap();
2223
+ _projectsUrl = /* @__PURE__ */ new WeakMap();
2184
2224
  __privateAdd3(_ProjectClient, _url22, "/api/v1/project");
2225
+ __privateAdd3(_ProjectClient, _projectsUrl, "/api/v1/projects");
2185
2226
  var ROUTE_URL = "/api/v1/route";
2186
2227
  var RouteClient = class extends ApiClient {
2187
2228
  constructor(options) {
@@ -2297,8 +2338,15 @@ var isIncontextEditingEnabled = ({
2297
2338
  var isDevelopmentEnvironment = () => {
2298
2339
  return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
2299
2340
  };
2341
+ var shouldIgnoreRedirects = ({ state }) => {
2342
+ const isNotPublished = state !== CANVAS_PUBLISHED_STATE;
2343
+ return isNotPublished ? true : void 0;
2344
+ };
2300
2345
 
2301
2346
  // src/clients/cache.ts
2347
+ var isSpecificCacheMode = (options) => {
2348
+ return "cache" in options;
2349
+ };
2302
2350
  var isStateCacheMode = (options) => {
2303
2351
  return "state" in options;
2304
2352
  };
@@ -2320,7 +2368,9 @@ var resolveCache = ({
2320
2368
  }) => {
2321
2369
  let cache = void 0;
2322
2370
  if (options) {
2323
- if (isStateCacheMode(options)) {
2371
+ if (isSpecificCacheMode(options)) {
2372
+ cache = options.cache;
2373
+ } else if (isStateCacheMode(options)) {
2324
2374
  if (options.state === CANVAS_DRAFT_STATE || options.state === CANVAS_EDITOR_STATE) {
2325
2375
  cache = {
2326
2376
  type: "no-cache",
@@ -2567,6 +2617,9 @@ var getQuirkSerialization = () => {
2567
2617
  return true;
2568
2618
  };
2569
2619
  var getMiddlewareRuntimeCache = () => {
2620
+ if (process.env.NODE_ENV === "development" && !process.env.RUNTIME_CACHE_ENDPOINT) {
2621
+ return false;
2622
+ }
2570
2623
  if (typeof config.middlewareRuntimeCache === "boolean") {
2571
2624
  return config.middlewareRuntimeCache;
2572
2625
  }
@@ -2712,7 +2765,10 @@ var DefaultDataClient = class {
2712
2765
  }
2713
2766
  }
2714
2767
  const manifest = await getManifest({
2715
- cache: {
2768
+ cache: isDevelopmentEnvironment() ? {
2769
+ type: "no-cache",
2770
+ bypassCache: true
2771
+ } : {
2716
2772
  type: "force-cache"
2717
2773
  }
2718
2774
  });
@@ -2815,12 +2871,13 @@ var DefaultDataClient = class {
2815
2871
  };
2816
2872
  }
2817
2873
  async getRoutePageState(options) {
2874
+ const shouldBypassCache = options.pageState.compositionState !== CANVAS_PUBLISHED_STATE || isDevelopmentEnvironment();
2818
2875
  const routeClient = getRouteClient({
2819
- cache: options.pageState.compositionState === CANVAS_PUBLISHED_STATE ? {
2820
- type: "force-cache"
2821
- } : {
2876
+ cache: shouldBypassCache ? {
2822
2877
  type: "no-cache",
2823
2878
  bypassCache: true
2879
+ } : {
2880
+ type: "force-cache"
2824
2881
  }
2825
2882
  });
2826
2883
  const originalRoute = {
@@ -2828,7 +2885,8 @@ var DefaultDataClient = class {
2828
2885
  state: options.pageState.compositionState,
2829
2886
  withComponentIDs: true,
2830
2887
  releaseId: options.pageState.releaseId,
2831
- locale: options.pageState.locale
2888
+ locale: options.pageState.locale,
2889
+ ignoreRedirects: shouldIgnoreRedirects({ state: options.pageState.compositionState })
2832
2890
  };
2833
2891
  const resolvedRoute = await this.getRouteFromApi({
2834
2892
  source: "pageState",
@@ -3007,7 +3065,8 @@ import {
3007
3065
  var evaluateRunnables = async ({
3008
3066
  runnables,
3009
3067
  context,
3010
- compositionContext
3068
+ compositionContext,
3069
+ isPrefetch
3011
3070
  }) => {
3012
3071
  var _a;
3013
3072
  const result = {
@@ -3017,6 +3076,9 @@ var evaluateRunnables = async ({
3017
3076
  const runnablesToProcess = runnables.filter((item2) => item2.variantId === void 0);
3018
3077
  let item;
3019
3078
  while (item = runnablesToProcess.shift()) {
3079
+ if (item.type === "test" && isPrefetch) {
3080
+ continue;
3081
+ }
3020
3082
  if (item.type === "test") {
3021
3083
  const testResult = evaluateTest({
3022
3084
  context,
@@ -5378,7 +5440,8 @@ var retrieveRouteByPath = async ({
5378
5440
  withComponentIDs: true,
5379
5441
  withContentSourceMap: (_a = getServerConfig().experimental) == null ? void 0 : _a.vercelVisualEditing,
5380
5442
  releaseId,
5381
- locale
5443
+ locale,
5444
+ ignoreRedirects: shouldIgnoreRedirects({ state })
5382
5445
  }
5383
5446
  });
5384
5447
  };
@@ -5522,7 +5585,8 @@ var handlePlaygroundRequest = async ({
5522
5585
  searchParams: request.nextUrl.searchParams,
5523
5586
  isDraftModeEnabled: true
5524
5587
  // this is checked above
5525
- })
5588
+ }),
5589
+ isPrefetch: false
5526
5590
  });
5527
5591
  const pageState = {
5528
5592
  routePath: id,
@@ -5540,7 +5604,8 @@ var handlePlaygroundRequest = async ({
5540
5604
  // this is checked above
5541
5605
  }),
5542
5606
  rules,
5543
- locale: options.locale
5607
+ locale: options.locale,
5608
+ isPrefetch: void 0
5544
5609
  };
5545
5610
  const code = serializeEvaluationResult({
5546
5611
  payload: pageState
@@ -5589,7 +5654,7 @@ var handleRouteRequest = async ({
5589
5654
  })
5590
5655
  ]);
5591
5656
  if (!(routeResult == null ? void 0 : routeResult.route) || ((_d = routeResult == null ? void 0 : routeResult.route) == null ? void 0 : _d.type) === "notFound") {
5592
- return NextResponse.next();
5657
+ return NextResponse.rewrite(new URL("/404", request.url));
5593
5658
  }
5594
5659
  if (((_e = routeResult == null ? void 0 : routeResult.route) == null ? void 0 : _e.type) === "redirect") {
5595
5660
  return handleRedirect({ request, route: routeResult.route });
@@ -5624,6 +5689,7 @@ var handleRouteRequest = async ({
5624
5689
  searchParams: request.nextUrl.searchParams,
5625
5690
  isDraftModeEnabled: draftModeEnabled
5626
5691
  });
5692
+ const isPrefetch = isPrefetchRequest(request);
5627
5693
  const { components, rules } = await extractAndEvaluateRunnables({
5628
5694
  composition: route.compositionApiResponse.composition,
5629
5695
  routePath,
@@ -5641,7 +5707,8 @@ var handleRouteRequest = async ({
5641
5707
  searchParams: request.nextUrl.searchParams,
5642
5708
  isDraftModeEnabled: true
5643
5709
  // this is checked above
5644
- })
5710
+ }),
5711
+ isPrefetch
5645
5712
  });
5646
5713
  const pageState = {
5647
5714
  routePath,
@@ -5655,7 +5722,8 @@ var handleRouteRequest = async ({
5655
5722
  }),
5656
5723
  previewMode,
5657
5724
  rules,
5658
- locale: options.locale
5725
+ locale: options.locale,
5726
+ isPrefetch: isPrefetch || void 0
5659
5727
  };
5660
5728
  const code = serializeEvaluationResult({
5661
5729
  payload: pageState
@@ -5675,6 +5743,9 @@ var handleRouteRequest = async ({
5675
5743
  headers
5676
5744
  });
5677
5745
  };
5746
+ var isPrefetchRequest = (request) => {
5747
+ return request.headers.has("next-url");
5748
+ };
5678
5749
  var extractAndEvaluateRunnables = async ({
5679
5750
  composition,
5680
5751
  routePath,
@@ -5685,12 +5756,14 @@ var extractAndEvaluateRunnables = async ({
5685
5756
  releaseId,
5686
5757
  defaultConsent,
5687
5758
  keys,
5688
- previewMode
5759
+ previewMode,
5760
+ isPrefetch
5689
5761
  }) => {
5690
5762
  const extracted = extractRunnables(composition);
5691
5763
  const result = await evaluateRunnables({
5692
5764
  runnables: extracted,
5693
5765
  context,
5766
+ isPrefetch,
5694
5767
  compositionContext: {
5695
5768
  _id: composition._id,
5696
5769
  type: composition.type,
@@ -5708,7 +5781,8 @@ var extractAndEvaluateRunnables = async ({
5708
5781
  defaultConsent,
5709
5782
  previewMode,
5710
5783
  rules: void 0,
5711
- locale: void 0
5784
+ locale: void 0,
5785
+ isPrefetch: isPrefetch || void 0
5712
5786
  }
5713
5787
  }
5714
5788
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/next-app-router",
3
- "version": "20.7.1-alpha.136+b24fc21071",
3
+ "version": "20.48.1-alpha.11+129de094d4",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "scripts": {
6
6
  "build": "tsup",
@@ -99,12 +99,12 @@
99
99
  "vitest": "3.2.4"
100
100
  },
101
101
  "dependencies": {
102
- "@uniformdev/canvas-react": "20.7.1-alpha.136+b24fc21071",
103
- "@uniformdev/next-app-router-client": "20.7.1-alpha.136+b24fc21071",
104
- "@uniformdev/next-app-router-shared": "20.7.1-alpha.136+b24fc21071",
105
- "@uniformdev/redirect": "20.7.1-alpha.136+b24fc21071",
106
- "@uniformdev/richtext": "20.7.1-alpha.136+b24fc21071",
107
- "@uniformdev/webhooks": "20.7.1-alpha.136+b24fc21071",
102
+ "@uniformdev/canvas-react": "20.48.1-alpha.11+129de094d4",
103
+ "@uniformdev/next-app-router-client": "20.48.1-alpha.11+129de094d4",
104
+ "@uniformdev/next-app-router-shared": "20.48.1-alpha.11+129de094d4",
105
+ "@uniformdev/redirect": "20.48.1-alpha.11+129de094d4",
106
+ "@uniformdev/richtext": "20.48.1-alpha.11+129de094d4",
107
+ "@uniformdev/webhooks": "20.48.1-alpha.11+129de094d4",
108
108
  "@vercel/functions": "^2.2.2",
109
109
  "encoding": "^0.1.13",
110
110
  "server-only": "^0.0.1",
@@ -121,5 +121,5 @@
121
121
  "publishConfig": {
122
122
  "access": "public"
123
123
  },
124
- "gitHead": "b24fc21071984f3e41cf7d2e46345c122182a185"
124
+ "gitHead": "129de094d4db58d4adfcae07d6ab0fe506ca739e"
125
125
  }