@uniformdev/next-app-router 20.50.2-alpha.9 → 20.50.2-alpha.96

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.
@@ -530,6 +530,20 @@ async function handleRateLimits(callApi) {
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);
@@ -1709,7 +1709,7 @@ function hasReferencedVariables(value) {
1709
1709
  return variableTokenCount;
1710
1710
  }
1711
1711
  function walkNodeTree(node, visitor, options) {
1712
- var _a, _b;
1712
+ var _a, _b, _c;
1713
1713
  const componentQueue = [
1714
1714
  {
1715
1715
  ancestorsAndSelf: Array.isArray(node) ? node : [{ node, type: "root" }],
@@ -1717,12 +1717,14 @@ function walkNodeTree(node, visitor, options) {
1717
1717
  }
1718
1718
  ];
1719
1719
  const childContexts = /* @__PURE__ */ new Map();
1720
+ const order = (_a = options == null ? void 0 : options.order) != null ? _a : "dfs";
1721
+ const takeNext = () => order === "bfs" ? componentQueue.shift() : componentQueue.pop();
1720
1722
  do {
1721
- const currentQueueEntry = componentQueue.pop();
1723
+ const currentQueueEntry = takeNext();
1722
1724
  if (!currentQueueEntry) continue;
1723
1725
  const currentComponent = currentQueueEntry.ancestorsAndSelf[0];
1724
1726
  let visitDescendants = true;
1725
- let descendantContext = (_a = childContexts.get(currentComponent.node)) != null ? _a : currentQueueEntry.context;
1727
+ let descendantContext = (_b = childContexts.get(currentComponent.node)) != null ? _b : currentQueueEntry.context;
1726
1728
  let visitorInfo;
1727
1729
  if (currentComponent.type === "root" && isRootEntryReference(currentComponent) || currentComponent.type === "block") {
1728
1730
  visitorInfo = {
@@ -1909,39 +1911,11 @@ function walkNodeTree(node, visitor, options) {
1909
1911
  continue;
1910
1912
  }
1911
1913
  const slots = "slots" in currentComponent.node && currentComponent.node.slots;
1912
- if (slots) {
1913
- const slotKeys = Object.keys(slots);
1914
- for (let slotIndex = slotKeys.length - 1; slotIndex >= 0; slotIndex--) {
1915
- const slotKey = slotKeys[slotIndex];
1916
- const components = slots[slotKey];
1917
- for (let componentIndex = components.length - 1; componentIndex >= 0; componentIndex--) {
1918
- const enqueueingComponent = components[componentIndex];
1919
- const parentSlotIndexFn = () => {
1920
- const result = currentComponent.node.slots[slotKey].findIndex(
1921
- (x) => x === enqueueingComponent
1922
- );
1923
- return result;
1924
- };
1925
- componentQueue.push({
1926
- ancestorsAndSelf: [
1927
- {
1928
- type: "slot",
1929
- node: enqueueingComponent,
1930
- parentSlot: slotKey,
1931
- parentSlotIndexFn
1932
- },
1933
- ...currentQueueEntry.ancestorsAndSelf
1934
- ],
1935
- context: descendantContext
1936
- });
1937
- }
1938
- }
1939
- }
1914
+ const childEntries = [];
1940
1915
  const properties = getPropertiesValue(currentComponent.node);
1941
1916
  if (properties) {
1942
1917
  const propertyEntries = Object.entries(properties);
1943
- for (let propIndex = propertyEntries.length - 1; propIndex >= 0; propIndex--) {
1944
- const [propKey, propObject] = propertyEntries[propIndex];
1918
+ for (const [propKey, propObject] of propertyEntries) {
1945
1919
  if (!isNestedNodeType(propObject.type)) {
1946
1920
  continue;
1947
1921
  }
@@ -1961,13 +1935,12 @@ function walkNodeTree(node, visitor, options) {
1961
1935
  continue;
1962
1936
  }
1963
1937
  }
1964
- const blocks = (_b = propObject.value) != null ? _b : [];
1965
- for (let blockIndex = blocks.length - 1; blockIndex >= 0; blockIndex--) {
1966
- const enqueueingBlock = blocks[blockIndex];
1938
+ const blocks = (_c = propObject.value) != null ? _c : [];
1939
+ for (const enqueueingBlock of blocks) {
1967
1940
  const blockIndexFn = () => {
1968
1941
  return getBlockValue(currentComponent.node, propKey).findIndex((x) => x === enqueueingBlock);
1969
1942
  };
1970
- componentQueue.push({
1943
+ childEntries.push({
1971
1944
  ancestorsAndSelf: [
1972
1945
  {
1973
1946
  type: "block",
@@ -1982,6 +1955,36 @@ function walkNodeTree(node, visitor, options) {
1982
1955
  }
1983
1956
  }
1984
1957
  }
1958
+ if (slots) {
1959
+ const slotKeys = Object.keys(slots);
1960
+ for (const slotKey of slotKeys) {
1961
+ const components = slots[slotKey];
1962
+ for (const enqueueingComponent of components) {
1963
+ const parentSlotIndexFn = () => {
1964
+ const result = currentComponent.node.slots[slotKey].findIndex(
1965
+ (x) => x === enqueueingComponent
1966
+ );
1967
+ return result;
1968
+ };
1969
+ childEntries.push({
1970
+ ancestorsAndSelf: [
1971
+ {
1972
+ type: "slot",
1973
+ node: enqueueingComponent,
1974
+ parentSlot: slotKey,
1975
+ parentSlotIndexFn
1976
+ },
1977
+ ...currentQueueEntry.ancestorsAndSelf
1978
+ ],
1979
+ context: descendantContext
1980
+ });
1981
+ }
1982
+ }
1983
+ }
1984
+ if (order === "dfs") {
1985
+ childEntries.reverse();
1986
+ }
1987
+ componentQueue.push(...childEntries);
1985
1988
  } while (componentQueue.length > 0);
1986
1989
  }
1987
1990
  function isNestedNodeType(type) {
@@ -2197,6 +2200,7 @@ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2
2197
2200
  _baseUrl = /* @__PURE__ */ new WeakMap();
2198
2201
  __privateAdd3(_IntegrationPropertyEditorsClient, _baseUrl, "/api/v1/integration-property-editors");
2199
2202
  var _url22;
2203
+ var _projectsUrl;
2200
2204
  var _ProjectClient = class _ProjectClient2 extends ApiClient {
2201
2205
  constructor(options) {
2202
2206
  super({ ...options, bypassCache: true });
@@ -2206,6 +2210,15 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
2206
2210
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22), { ...options });
2207
2211
  return await this.apiClient(fetchUri);
2208
2212
  }
2213
+ /**
2214
+ * Fetches projects grouped by team.
2215
+ * When teamId is provided, returns a single team with its projects.
2216
+ * When omitted, returns all accessible teams and their projects.
2217
+ */
2218
+ async getProjects(options) {
2219
+ const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
2220
+ return await this.apiClient(fetchUri);
2221
+ }
2209
2222
  /** Updates or creates (based on id) a Project */
2210
2223
  async upsert(body) {
2211
2224
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
@@ -2225,7 +2238,9 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
2225
2238
  }
2226
2239
  };
2227
2240
  _url22 = /* @__PURE__ */ new WeakMap();
2241
+ _projectsUrl = /* @__PURE__ */ new WeakMap();
2228
2242
  __privateAdd3(_ProjectClient, _url22, "/api/v1/project");
2243
+ __privateAdd3(_ProjectClient, _projectsUrl, "/api/v1/projects");
2229
2244
  var ROUTE_URL = "/api/v1/route";
2230
2245
  var RouteClient = class extends ApiClient {
2231
2246
  constructor(options) {
@@ -2339,8 +2354,15 @@ var isIncontextEditingEnabled = ({
2339
2354
  var isDevelopmentEnvironment = () => {
2340
2355
  return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
2341
2356
  };
2357
+ var shouldIgnoreRedirects = ({ state }) => {
2358
+ const isNotPublished = state !== CANVAS_PUBLISHED_STATE;
2359
+ return isNotPublished ? true : void 0;
2360
+ };
2342
2361
 
2343
2362
  // src/clients/cache.ts
2363
+ var isSpecificCacheMode = (options) => {
2364
+ return "cache" in options;
2365
+ };
2344
2366
  var isStateCacheMode = (options) => {
2345
2367
  return "state" in options;
2346
2368
  };
@@ -2362,7 +2384,9 @@ var resolveCache = ({
2362
2384
  }) => {
2363
2385
  let cache = void 0;
2364
2386
  if (options) {
2365
- if (isStateCacheMode(options)) {
2387
+ if (isSpecificCacheMode(options)) {
2388
+ cache = options.cache;
2389
+ } else if (isStateCacheMode(options)) {
2366
2390
  if (options.state === CANVAS_DRAFT_STATE || options.state === CANVAS_EDITOR_STATE) {
2367
2391
  cache = {
2368
2392
  type: "no-cache",
@@ -2757,7 +2781,10 @@ var DefaultDataClient = class {
2757
2781
  }
2758
2782
  }
2759
2783
  const manifest = await getManifest({
2760
- cache: {
2784
+ cache: isDevelopmentEnvironment() ? {
2785
+ type: "no-cache",
2786
+ bypassCache: true
2787
+ } : {
2761
2788
  type: "force-cache"
2762
2789
  }
2763
2790
  });
@@ -2860,12 +2887,13 @@ var DefaultDataClient = class {
2860
2887
  };
2861
2888
  }
2862
2889
  async getRoutePageState(options) {
2890
+ const shouldBypassCache = options.pageState.compositionState !== CANVAS_PUBLISHED_STATE || isDevelopmentEnvironment();
2863
2891
  const routeClient = getRouteClient({
2864
- cache: options.pageState.compositionState === CANVAS_PUBLISHED_STATE ? {
2865
- type: "force-cache"
2866
- } : {
2892
+ cache: shouldBypassCache ? {
2867
2893
  type: "no-cache",
2868
2894
  bypassCache: true
2895
+ } : {
2896
+ type: "force-cache"
2869
2897
  }
2870
2898
  });
2871
2899
  const originalRoute = {
@@ -2873,7 +2901,8 @@ var DefaultDataClient = class {
2873
2901
  state: options.pageState.compositionState,
2874
2902
  withComponentIDs: true,
2875
2903
  releaseId: options.pageState.releaseId,
2876
- locale: options.pageState.locale
2904
+ locale: options.pageState.locale,
2905
+ ignoreRedirects: shouldIgnoreRedirects({ state: options.pageState.compositionState })
2877
2906
  };
2878
2907
  const resolvedRoute = await this.getRouteFromApi({
2879
2908
  source: "pageState",
@@ -3391,7 +3420,6 @@ var ManifestInstance = class {
3391
3420
  constructor({
3392
3421
  manifest,
3393
3422
  evaluator = new GroupCriteriaEvaluator({}),
3394
- // eslint-disable-next-line @typescript-eslint/no-empty-function
3395
3423
  onLogMessage = () => {
3396
3424
  }
3397
3425
  }) {
@@ -5422,7 +5450,8 @@ var retrieveRouteByPath = async ({
5422
5450
  withComponentIDs: true,
5423
5451
  withContentSourceMap: (_a = getServerConfig().experimental) == null ? void 0 : _a.vercelVisualEditing,
5424
5452
  releaseId,
5425
- locale
5453
+ locale,
5454
+ ignoreRedirects: shouldIgnoreRedirects({ state })
5426
5455
  }
5427
5456
  });
5428
5457
  };
@@ -5549,7 +5578,7 @@ var handlePlaygroundRequest = async ({
5549
5578
  })
5550
5579
  });
5551
5580
  const context = await onDemandContext.getContext();
5552
- const { components, rules } = await extractAndEvaluateRunnables({
5581
+ const { components, rules, allComponentIds } = await extractAndEvaluateRunnables({
5553
5582
  composition: composition.composition,
5554
5583
  routePath: id,
5555
5584
  state: composition.state,
@@ -5589,7 +5618,8 @@ var handlePlaygroundRequest = async ({
5589
5618
  isPrefetch: void 0
5590
5619
  };
5591
5620
  const code = (0, import_next_app_router_shared5.serializeEvaluationResult)({
5592
- payload: pageState
5621
+ payload: pageState,
5622
+ allComponentIds
5593
5623
  });
5594
5624
  let pathToRewriteTo = await (options.rewriteDestinationPath ? options.rewriteDestinationPath({ code, pageState, source: "playground" }) : void 0);
5595
5625
  if (!pathToRewriteTo) {
@@ -5603,15 +5633,16 @@ var handleRouteRequest = async ({
5603
5633
  dataClient,
5604
5634
  options
5605
5635
  }) => {
5606
- var _a, _b, _c, _d, _e, _f, _g, _h;
5636
+ var _a, _b, _c, _d, _e, _f, _g;
5637
+ const releaseId = (_b = (_a = options.release) == null ? void 0 : _a.id) != null ? _b : draftModeEnabled ? request.nextUrl.searchParams.get("releaseId") || void 0 : void 0;
5607
5638
  const states = await determineState({
5608
5639
  searchParams: request.nextUrl.searchParams,
5609
5640
  draftModeEnabled
5610
5641
  });
5611
- const requestPath = (_b = await ((_a = options.rewriteRequestPath) == null ? void 0 : _a.call(options, {
5642
+ const requestPath = (_d = await ((_c = options.rewriteRequestPath) == null ? void 0 : _c.call(options, {
5612
5643
  request,
5613
5644
  url: new URL(request.url)
5614
- }))) != null ? _b : {
5645
+ }))) != null ? _d : {
5615
5646
  path: `${request.nextUrl.pathname}${request.nextUrl.search}`
5616
5647
  };
5617
5648
  const serverConfig = getServerConfig();
@@ -5622,7 +5653,7 @@ var handleRouteRequest = async ({
5622
5653
  searchParams: request.nextUrl.searchParams,
5623
5654
  draftModeEnabled,
5624
5655
  dataClient,
5625
- releaseId: (_c = options.release) == null ? void 0 : _c.id,
5656
+ releaseId,
5626
5657
  locale: options.locale
5627
5658
  }),
5628
5659
  createOnDemandContext({
@@ -5634,10 +5665,10 @@ var handleRouteRequest = async ({
5634
5665
  })
5635
5666
  })
5636
5667
  ]);
5637
- if (!(routeResult == null ? void 0 : routeResult.route) || ((_d = routeResult == null ? void 0 : routeResult.route) == null ? void 0 : _d.type) === "notFound") {
5668
+ if (!(routeResult == null ? void 0 : routeResult.route) || ((_e = routeResult == null ? void 0 : routeResult.route) == null ? void 0 : _e.type) === "notFound") {
5638
5669
  return import_server.NextResponse.rewrite(new URL("/404", request.url));
5639
5670
  }
5640
- if (((_e = routeResult == null ? void 0 : routeResult.route) == null ? void 0 : _e.type) === "redirect") {
5671
+ if (((_f = routeResult == null ? void 0 : routeResult.route) == null ? void 0 : _f.type) === "redirect") {
5641
5672
  return handleRedirect({ request, route: routeResult.route });
5642
5673
  }
5643
5674
  const { route } = routeResult;
@@ -5671,14 +5702,14 @@ var handleRouteRequest = async ({
5671
5702
  isDraftModeEnabled: draftModeEnabled
5672
5703
  });
5673
5704
  const isPrefetch = isPrefetchRequest(request);
5674
- const { components, rules } = await extractAndEvaluateRunnables({
5705
+ const { components, rules, allComponentIds } = await extractAndEvaluateRunnables({
5675
5706
  composition: route.compositionApiResponse.composition,
5676
5707
  routePath,
5677
5708
  state,
5678
5709
  context,
5679
5710
  matchedRoute: route.matchedRoute,
5680
- dynamicInputs: (_f = route.dynamicInputs) != null ? _f : {},
5681
- releaseId: (_g = options.release) == null ? void 0 : _g.id,
5711
+ dynamicInputs: (_g = route.dynamicInputs) != null ? _g : {},
5712
+ releaseId,
5682
5713
  defaultConsent: determineDefaultConsent({
5683
5714
  serverConfig,
5684
5715
  defaultConsent: options.defaultConsent
@@ -5696,7 +5727,7 @@ var handleRouteRequest = async ({
5696
5727
  compositionState: state,
5697
5728
  components,
5698
5729
  keys: requestPath.keys,
5699
- releaseId: (_h = options.release) == null ? void 0 : _h.id,
5730
+ releaseId,
5700
5731
  defaultConsent: determineDefaultConsent({
5701
5732
  serverConfig,
5702
5733
  defaultConsent: options.defaultConsent
@@ -5707,7 +5738,8 @@ var handleRouteRequest = async ({
5707
5738
  isPrefetch: isPrefetch || void 0
5708
5739
  };
5709
5740
  const code = (0, import_next_app_router_shared5.serializeEvaluationResult)({
5710
- payload: pageState
5741
+ payload: pageState,
5742
+ allComponentIds
5711
5743
  });
5712
5744
  let pathToRewriteTo = await (options.rewriteDestinationPath ? options.rewriteDestinationPath({ code, pageState, source: "route" }) : void 0);
5713
5745
  if (!pathToRewriteTo) {
@@ -5767,7 +5799,8 @@ var extractAndEvaluateRunnables = async ({
5767
5799
  }
5768
5800
  }
5769
5801
  });
5770
- return result;
5802
+ const allComponentIds = extracted.filter((r) => r.type === "test" || r.type === "personalization").map((r) => r._id);
5803
+ return { ...result, allComponentIds };
5771
5804
  };
5772
5805
  var handleRedirect = ({ request, route }) => {
5773
5806
  const href = resolveRedirectHref({