@uniformdev/next-app-router 20.50.1 → 20.50.2-alpha.109

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",
@@ -3134,11 +3163,12 @@ function dequal(foo, bar) {
3134
3163
  return foo !== foo && bar !== bar;
3135
3164
  }
3136
3165
 
3137
- // ../../node_modules/.pnpm/js-cookie@3.0.5/node_modules/js-cookie/dist/js.cookie.mjs
3166
+ // ../../node_modules/.pnpm/js-cookie@3.0.7/node_modules/js-cookie/dist/js.cookie.mjs
3138
3167
  function assign(target) {
3139
3168
  for (var i = 1; i < arguments.length; i++) {
3140
3169
  var source = arguments[i];
3141
3170
  for (var key in source) {
3171
+ if (key === "__proto__") continue;
3142
3172
  target[key] = source[key];
3143
3173
  }
3144
3174
  }
@@ -3195,7 +3225,7 @@ function init(converter, defaultAttributes) {
3195
3225
  var value = parts.slice(1).join("=");
3196
3226
  try {
3197
3227
  var found = decodeURIComponent(parts[0]);
3198
- jar[found] = converter.read(value, found);
3228
+ if (!(found in jar)) jar[found] = converter.read(value, found);
3199
3229
  if (name === found) {
3200
3230
  break;
3201
3231
  }
@@ -3391,7 +3421,6 @@ var ManifestInstance = class {
3391
3421
  constructor({
3392
3422
  manifest,
3393
3423
  evaluator = new GroupCriteriaEvaluator({}),
3394
- // eslint-disable-next-line @typescript-eslint/no-empty-function
3395
3424
  onLogMessage = () => {
3396
3425
  }
3397
3426
  }) {
@@ -5422,7 +5451,8 @@ var retrieveRouteByPath = async ({
5422
5451
  withComponentIDs: true,
5423
5452
  withContentSourceMap: (_a = getServerConfig().experimental) == null ? void 0 : _a.vercelVisualEditing,
5424
5453
  releaseId,
5425
- locale
5454
+ locale,
5455
+ ignoreRedirects: shouldIgnoreRedirects({ state })
5426
5456
  }
5427
5457
  });
5428
5458
  };
@@ -5549,7 +5579,7 @@ var handlePlaygroundRequest = async ({
5549
5579
  })
5550
5580
  });
5551
5581
  const context = await onDemandContext.getContext();
5552
- const { components, rules } = await extractAndEvaluateRunnables({
5582
+ const { components, rules, allComponentIds } = await extractAndEvaluateRunnables({
5553
5583
  composition: composition.composition,
5554
5584
  routePath: id,
5555
5585
  state: composition.state,
@@ -5589,7 +5619,8 @@ var handlePlaygroundRequest = async ({
5589
5619
  isPrefetch: void 0
5590
5620
  };
5591
5621
  const code = (0, import_next_app_router_shared5.serializeEvaluationResult)({
5592
- payload: pageState
5622
+ payload: pageState,
5623
+ allComponentIds
5593
5624
  });
5594
5625
  let pathToRewriteTo = await (options.rewriteDestinationPath ? options.rewriteDestinationPath({ code, pageState, source: "playground" }) : void 0);
5595
5626
  if (!pathToRewriteTo) {
@@ -5603,15 +5634,16 @@ var handleRouteRequest = async ({
5603
5634
  dataClient,
5604
5635
  options
5605
5636
  }) => {
5606
- var _a, _b, _c, _d, _e, _f, _g, _h;
5637
+ var _a, _b, _c, _d, _e, _f, _g;
5638
+ const releaseId = (_b = (_a = options.release) == null ? void 0 : _a.id) != null ? _b : draftModeEnabled ? request.nextUrl.searchParams.get("releaseId") || void 0 : void 0;
5607
5639
  const states = await determineState({
5608
5640
  searchParams: request.nextUrl.searchParams,
5609
5641
  draftModeEnabled
5610
5642
  });
5611
- const requestPath = (_b = await ((_a = options.rewriteRequestPath) == null ? void 0 : _a.call(options, {
5643
+ const requestPath = (_d = await ((_c = options.rewriteRequestPath) == null ? void 0 : _c.call(options, {
5612
5644
  request,
5613
5645
  url: new URL(request.url)
5614
- }))) != null ? _b : {
5646
+ }))) != null ? _d : {
5615
5647
  path: `${request.nextUrl.pathname}${request.nextUrl.search}`
5616
5648
  };
5617
5649
  const serverConfig = getServerConfig();
@@ -5622,7 +5654,7 @@ var handleRouteRequest = async ({
5622
5654
  searchParams: request.nextUrl.searchParams,
5623
5655
  draftModeEnabled,
5624
5656
  dataClient,
5625
- releaseId: (_c = options.release) == null ? void 0 : _c.id,
5657
+ releaseId,
5626
5658
  locale: options.locale
5627
5659
  }),
5628
5660
  createOnDemandContext({
@@ -5634,10 +5666,10 @@ var handleRouteRequest = async ({
5634
5666
  })
5635
5667
  })
5636
5668
  ]);
5637
- if (!(routeResult == null ? void 0 : routeResult.route) || ((_d = routeResult == null ? void 0 : routeResult.route) == null ? void 0 : _d.type) === "notFound") {
5669
+ if (!(routeResult == null ? void 0 : routeResult.route) || ((_e = routeResult == null ? void 0 : routeResult.route) == null ? void 0 : _e.type) === "notFound") {
5638
5670
  return import_server.NextResponse.rewrite(new URL("/404", request.url));
5639
5671
  }
5640
- if (((_e = routeResult == null ? void 0 : routeResult.route) == null ? void 0 : _e.type) === "redirect") {
5672
+ if (((_f = routeResult == null ? void 0 : routeResult.route) == null ? void 0 : _f.type) === "redirect") {
5641
5673
  return handleRedirect({ request, route: routeResult.route });
5642
5674
  }
5643
5675
  const { route } = routeResult;
@@ -5671,14 +5703,14 @@ var handleRouteRequest = async ({
5671
5703
  isDraftModeEnabled: draftModeEnabled
5672
5704
  });
5673
5705
  const isPrefetch = isPrefetchRequest(request);
5674
- const { components, rules } = await extractAndEvaluateRunnables({
5706
+ const { components, rules, allComponentIds } = await extractAndEvaluateRunnables({
5675
5707
  composition: route.compositionApiResponse.composition,
5676
5708
  routePath,
5677
5709
  state,
5678
5710
  context,
5679
5711
  matchedRoute: route.matchedRoute,
5680
- dynamicInputs: (_f = route.dynamicInputs) != null ? _f : {},
5681
- releaseId: (_g = options.release) == null ? void 0 : _g.id,
5712
+ dynamicInputs: (_g = route.dynamicInputs) != null ? _g : {},
5713
+ releaseId,
5682
5714
  defaultConsent: determineDefaultConsent({
5683
5715
  serverConfig,
5684
5716
  defaultConsent: options.defaultConsent
@@ -5696,7 +5728,7 @@ var handleRouteRequest = async ({
5696
5728
  compositionState: state,
5697
5729
  components,
5698
5730
  keys: requestPath.keys,
5699
- releaseId: (_h = options.release) == null ? void 0 : _h.id,
5731
+ releaseId,
5700
5732
  defaultConsent: determineDefaultConsent({
5701
5733
  serverConfig,
5702
5734
  defaultConsent: options.defaultConsent
@@ -5707,7 +5739,8 @@ var handleRouteRequest = async ({
5707
5739
  isPrefetch: isPrefetch || void 0
5708
5740
  };
5709
5741
  const code = (0, import_next_app_router_shared5.serializeEvaluationResult)({
5710
- payload: pageState
5742
+ payload: pageState,
5743
+ allComponentIds
5711
5744
  });
5712
5745
  let pathToRewriteTo = await (options.rewriteDestinationPath ? options.rewriteDestinationPath({ code, pageState, source: "route" }) : void 0);
5713
5746
  if (!pathToRewriteTo) {
@@ -5767,7 +5800,8 @@ var extractAndEvaluateRunnables = async ({
5767
5800
  }
5768
5801
  }
5769
5802
  });
5770
- return result;
5803
+ const allComponentIds = extracted.filter((r) => r.type === "test" || r.type === "personalization").map((r) => r._id);
5804
+ return { ...result, allComponentIds };
5771
5805
  };
5772
5806
  var handleRedirect = ({ request, route }) => {
5773
5807
  const href = resolveRedirectHref({
@@ -5866,5 +5900,5 @@ var determinePreviewMode = ({
5866
5900
  /*! Bundled license information:
5867
5901
 
5868
5902
  js-cookie/dist/js.cookie.mjs:
5869
- (*! js-cookie v3.0.5 | MIT *)
5903
+ (*! js-cookie v3.0.7 | MIT *)
5870
5904
  */