@uniformdev/next-app-router 20.50.2-alpha.167 → 20.50.2-alpha.180

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.
@@ -1396,16 +1396,6 @@ function createLimitPolicy({
1396
1396
  return currentFunc();
1397
1397
  };
1398
1398
  }
1399
- var ContentClientBase = class extends ApiClient {
1400
- constructor(options, defaultBypassCache) {
1401
- var _a, _b;
1402
- super({
1403
- ...options,
1404
- limitPolicy: (_a = options.limitPolicy) != null ? _a : createLimitPolicy({}),
1405
- bypassCache: (_b = options.bypassCache) != null ? _b : defaultBypassCache
1406
- });
1407
- }
1408
- };
1409
1399
  var SELECT_QUERY_PREFIX = "select.";
1410
1400
  function appendCsv(out, key, values) {
1411
1401
  if (values === void 0) {
@@ -1447,100 +1437,130 @@ function projectionToQuery(spec) {
1447
1437
  }
1448
1438
  return out;
1449
1439
  }
1450
- var CANVAS_PERSONALIZE_TYPE = "$personalization";
1451
- var CANVAS_TEST_TYPE = "$test";
1452
- var CANVAS_BLOCK_PARAM_TYPE = "$block";
1453
- var CANVAS_PERSONALIZE_SLOT = "pz";
1454
- var CANVAS_TEST_SLOT = "test";
1455
- var CANVAS_DRAFT_STATE = 0;
1456
- var CANVAS_PUBLISHED_STATE = 64;
1457
- var CANVAS_EDITOR_STATE = 63;
1458
- var CANVAS_PERSONALIZATION_PARAM = "$pzCrit";
1459
- var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
1460
- var CANVAS_INTERNAL_PARAM_PREFIX = "$internal_";
1461
- var CANVAS_COMPONENT_DISPLAY_NAME_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}displayName`;
1462
- var CANVAS_HYPOTHESIS_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}hypothesis`;
1463
- var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1464
- var IN_CONTEXT_EDITOR_FORCED_SETTINGS_QUERY_STRING_PARAM = "is_incontext_editing_forced_settings";
1465
- var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
1466
- function resolveCompositionSelector(args) {
1467
- if ("compositionId" in args) {
1468
- const { compositionId, editionId, versionId, ...readOptions } = args;
1469
- return {
1470
- readOptions,
1471
- // raw mode matches on composition OR edition id via the compositionId param
1472
- compositionId: editionId != null ? editionId : compositionId,
1473
- versionId,
1474
- hasCompositionId: true,
1475
- pinnedEdition: editionId !== void 0
1476
- };
1477
- }
1478
- return { readOptions: args, hasCompositionId: false, pinnedEdition: false };
1479
- }
1480
- var DEFAULT_EDGE_API_HOST = "https://uniform.global";
1481
- var DeliveryClientBase = class extends ContentClientBase {
1440
+ var CANVAS_URL = "/api/v1/canvas";
1441
+ var CanvasClient = class extends ApiClient {
1482
1442
  constructor(options) {
1483
1443
  var _a;
1484
- super(
1485
- options,
1486
- /* defaultBypassCache */
1487
- false
1488
- );
1489
- this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : DEFAULT_EDGE_API_HOST;
1490
- this.edgeRequestInit = options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0;
1444
+ if (!options.limitPolicy) {
1445
+ options.limitPolicy = createLimitPolicy({});
1446
+ }
1447
+ super(options);
1448
+ this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
1449
+ this.edgeApiRequestInit = options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0;
1491
1450
  }
1492
- /** Coerces the `diagnostics` option into the shape the edge endpoints accept. */
1493
- coerceDiagnostics(diagnostics) {
1494
- return typeof diagnostics === "boolean" ? diagnostics : diagnostics === "no-data" ? "no-data" : void 0;
1451
+ /** Fetches lists of Canvas compositions, optionally by type */
1452
+ async getCompositionList(params = {}) {
1453
+ const { projectId } = this.options;
1454
+ const { resolveData, filters, select, ...originParams } = params;
1455
+ const rewrittenFilters = rewriteFiltersForApi(filters);
1456
+ const rewrittenSelect = projectionToQuery(select);
1457
+ if (!resolveData) {
1458
+ const fetchUri = this.createUrl(CANVAS_URL, {
1459
+ ...originParams,
1460
+ projectId,
1461
+ ...rewrittenFilters,
1462
+ ...rewrittenSelect
1463
+ });
1464
+ return this.apiClient(fetchUri);
1465
+ }
1466
+ const edgeParams = {
1467
+ ...originParams,
1468
+ projectId,
1469
+ diagnostics: typeof params.diagnostics === "boolean" ? params.diagnostics : params.diagnostics === "no-data" ? "no-data" : void 0,
1470
+ ...rewrittenFilters,
1471
+ ...rewrittenSelect
1472
+ };
1473
+ const edgeUrl = this.createUrl("/api/v1/compositions", edgeParams, this.edgeApiHost);
1474
+ return this.apiClient(edgeUrl, this.edgeApiRequestInit);
1495
1475
  }
1496
- };
1497
- var EDGE_SINGLE_URL = "/api/v1/composition";
1498
- var EDGE_LIST_URL = "/api/v1/compositions";
1499
- var CompositionDeliveryClient = class extends DeliveryClientBase {
1500
- constructor(options) {
1501
- super(options);
1476
+ getCompositionByNodePath(options) {
1477
+ return this.getOneComposition(options);
1502
1478
  }
1503
- /** Fetches exactly one composition (throws `ApiClientError(404)` if absent). */
1504
- get(args) {
1505
- var _a;
1506
- const { diagnostics, select, ...rest } = args;
1507
- const { readOptions, compositionId, versionId, pinnedEdition } = resolveCompositionSelector(rest);
1508
- const url = this.createUrl(
1509
- EDGE_SINGLE_URL,
1510
- {
1511
- ...readOptions,
1512
- ...projectionToQuery(select),
1513
- // A pinned edition is folded into compositionId (raw matches edition or
1514
- // composition id); there is no editionId query param on this endpoint.
1515
- compositionId,
1516
- versionId,
1517
- projectId: this.options.projectId,
1518
- state: (_a = args.state) != null ? _a : CANVAS_PUBLISHED_STATE,
1519
- // editionId pins a specific edition for preview; otherwise locale-best.
1520
- editions: pinnedEdition ? "raw" : "auto",
1521
- diagnostics: this.coerceDiagnostics(diagnostics)
1522
- },
1523
- this.edgeApiHost
1524
- );
1525
- return this.apiClient(url, this.edgeRequestInit);
1479
+ getCompositionByNodeId(options) {
1480
+ return this.getOneComposition(options);
1526
1481
  }
1527
- /** Fetches a list of compositions, optionally filtered. */
1528
- list(args = {}) {
1529
- var _a;
1530
- const { diagnostics, filters, select, ...rest } = args;
1531
- const url = this.createUrl(
1532
- EDGE_LIST_URL,
1533
- {
1534
- ...rest,
1535
- ...rewriteFiltersForApi(filters),
1536
- ...projectionToQuery(select),
1537
- projectId: this.options.projectId,
1538
- state: (_a = args.state) != null ? _a : CANVAS_PUBLISHED_STATE,
1539
- diagnostics: this.coerceDiagnostics(diagnostics)
1540
- },
1541
- this.edgeApiHost
1542
- );
1543
- return this.apiClient(url, this.edgeRequestInit);
1482
+ getCompositionBySlug(options) {
1483
+ return this.getOneComposition(options);
1484
+ }
1485
+ getCompositionById(options) {
1486
+ return this.getOneComposition(options);
1487
+ }
1488
+ getCompositionDefaults(options) {
1489
+ return this.getOneComposition(options);
1490
+ }
1491
+ /** Fetches historical versions of a composition or pattern */
1492
+ async getCompositionHistory(options) {
1493
+ const historyUrl = this.createUrl("/api/v1/canvas-history", {
1494
+ ...options,
1495
+ projectId: this.options.projectId
1496
+ });
1497
+ return this.apiClient(historyUrl);
1498
+ }
1499
+ getOneComposition({
1500
+ skipDataResolution,
1501
+ diagnostics,
1502
+ ...params
1503
+ }) {
1504
+ const { projectId } = this.options;
1505
+ if (skipDataResolution) {
1506
+ return this.apiClient(this.createUrl(CANVAS_URL, { ...params, projectId }));
1507
+ }
1508
+ const edgeParams = {
1509
+ ...params,
1510
+ projectId,
1511
+ diagnostics: typeof diagnostics === "boolean" ? diagnostics : diagnostics === "no-data" ? "no-data" : void 0
1512
+ };
1513
+ const edgeUrl = this.createUrl("/api/v1/composition", edgeParams, this.edgeApiHost);
1514
+ return this.apiClient(edgeUrl, this.edgeApiRequestInit);
1515
+ }
1516
+ /** Updates or creates a Canvas component definition */
1517
+ async updateComposition(body, options) {
1518
+ const fetchUri = this.createUrl(CANVAS_URL);
1519
+ const headers = {};
1520
+ if (options == null ? void 0 : options.ifUnmodifiedSince) {
1521
+ headers["x-if-unmodified-since"] = options.ifUnmodifiedSince;
1522
+ }
1523
+ const { response } = await this.apiClientWithResponse(fetchUri, {
1524
+ method: "PUT",
1525
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1526
+ expectNoContent: true,
1527
+ headers
1528
+ });
1529
+ return { modified: response.headers.get("x-modified-at") };
1530
+ }
1531
+ /** Deletes a Canvas component definition */
1532
+ async removeComposition(body) {
1533
+ const fetchUri = this.createUrl(CANVAS_URL);
1534
+ const { projectId } = this.options;
1535
+ await this.apiClient(fetchUri, {
1536
+ method: "DELETE",
1537
+ body: JSON.stringify({ ...body, projectId }),
1538
+ expectNoContent: true
1539
+ });
1540
+ }
1541
+ /** Fetches all Canvas component definitions */
1542
+ async getComponentDefinitions(options) {
1543
+ const { projectId } = this.options;
1544
+ const fetchUri = this.createUrl("/api/v1/canvas-definitions", { ...options, projectId });
1545
+ return this.apiClient(fetchUri);
1546
+ }
1547
+ /** Updates or creates a Canvas component definition */
1548
+ async updateComponentDefinition(body) {
1549
+ const fetchUri = this.createUrl("/api/v1/canvas-definitions");
1550
+ await this.apiClient(fetchUri, {
1551
+ method: "PUT",
1552
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1553
+ expectNoContent: true
1554
+ });
1555
+ }
1556
+ /** Deletes a Canvas component definition */
1557
+ async removeComponentDefinition(body) {
1558
+ const fetchUri = this.createUrl("/api/v1/canvas-definitions");
1559
+ await this.apiClient(fetchUri, {
1560
+ method: "DELETE",
1561
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1562
+ expectNoContent: true
1563
+ });
1544
1564
  }
1545
1565
  };
1546
1566
  var _contentTypesUrl;
@@ -1649,18 +1669,14 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1649
1669
  constructor(options) {
1650
1670
  super(options);
1651
1671
  }
1652
- /** Fetches a list of DataTypes for a project */
1653
- async list(options) {
1672
+ /** Fetches all DataTypes for a project */
1673
+ async get(options) {
1654
1674
  const { projectId } = this.options;
1655
1675
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8), { ...options, projectId });
1656
1676
  return await this.apiClient(fetchUri);
1657
1677
  }
1658
- /** @deprecated Use {@link list} instead. */
1659
- async get(options) {
1660
- return this.list(options);
1661
- }
1662
1678
  /** Updates or creates (based on id) a DataType */
1663
- async save(body) {
1679
+ async upsert(body) {
1664
1680
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
1665
1681
  await this.apiClient(fetchUri, {
1666
1682
  method: "PUT",
@@ -1668,10 +1684,6 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1668
1684
  expectNoContent: true
1669
1685
  });
1670
1686
  }
1671
- /** @deprecated Use {@link save} instead. */
1672
- async upsert(body) {
1673
- return this.save(body);
1674
- }
1675
1687
  /** Deletes a DataType */
1676
1688
  async remove(body) {
1677
1689
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
@@ -1709,6 +1721,22 @@ function getComponentPath(ancestorsAndSelf) {
1709
1721
  }
1710
1722
  return `.${path.join(".")}`;
1711
1723
  }
1724
+ var CANVAS_PERSONALIZE_TYPE = "$personalization";
1725
+ var CANVAS_TEST_TYPE = "$test";
1726
+ var CANVAS_BLOCK_PARAM_TYPE = "$block";
1727
+ var CANVAS_PERSONALIZE_SLOT = "pz";
1728
+ var CANVAS_TEST_SLOT = "test";
1729
+ var CANVAS_DRAFT_STATE = 0;
1730
+ var CANVAS_PUBLISHED_STATE = 64;
1731
+ var CANVAS_EDITOR_STATE = 63;
1732
+ var CANVAS_PERSONALIZATION_PARAM = "$pzCrit";
1733
+ var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
1734
+ var CANVAS_INTERNAL_PARAM_PREFIX = "$internal_";
1735
+ var CANVAS_COMPONENT_DISPLAY_NAME_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}displayName`;
1736
+ var CANVAS_HYPOTHESIS_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}hypothesis`;
1737
+ var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1738
+ var IN_CONTEXT_EDITOR_FORCED_SETTINGS_QUERY_STRING_PARAM = "is_incontext_editing_forced_settings";
1739
+ var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
1712
1740
  function isRootEntryReference(root) {
1713
1741
  return root.type === "root" && isEntryData(root.node);
1714
1742
  }
@@ -2310,28 +2338,20 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
2310
2338
  * When teamId is provided, returns a single team with its projects.
2311
2339
  * When omitted, returns all accessible teams and their projects.
2312
2340
  */
2313
- async list(options) {
2341
+ async getProjects(options) {
2314
2342
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
2315
2343
  return await this.apiClient(fetchUri);
2316
2344
  }
2317
- /** @deprecated Use {@link list} instead. */
2318
- async getProjects(options) {
2319
- return this.list(options);
2320
- }
2321
2345
  /** Updates or creates (based on id) a Project */
2322
- async save(body) {
2346
+ async upsert(body) {
2323
2347
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
2324
2348
  return await this.apiClient(fetchUri, {
2325
2349
  method: "PUT",
2326
2350
  body: JSON.stringify({ ...body })
2327
2351
  });
2328
2352
  }
2329
- /** @deprecated Use {@link save} instead. */
2330
- async upsert(body) {
2331
- return this.save(body);
2332
- }
2333
2353
  /** Deletes a Project */
2334
- async remove(body) {
2354
+ async delete(body) {
2335
2355
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
2336
2356
  await this.apiClient(fetchUri, {
2337
2357
  method: "DELETE",
@@ -2339,10 +2359,6 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
2339
2359
  expectNoContent: true
2340
2360
  });
2341
2361
  }
2342
- /** @deprecated Use {@link remove} instead. */
2343
- async delete(body) {
2344
- return this.remove(body);
2345
- }
2346
2362
  };
2347
2363
  _url22 = /* @__PURE__ */ new WeakMap();
2348
2364
  _projectsUrl = /* @__PURE__ */ new WeakMap();
@@ -2358,14 +2374,8 @@ var RouteClient = class extends ApiClient {
2358
2374
  super(options);
2359
2375
  this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
2360
2376
  }
2361
- /**
2362
- * Resolves a route to a composition, redirect, or not-found result.
2363
- *
2364
- * An optional `select` projection applies to the resolved composition when
2365
- * the route matches one; redirect / notFound responses pass through
2366
- * untouched.
2367
- */
2368
- async get(options) {
2377
+ /** Fetches lists of Canvas compositions, optionally by type */
2378
+ async getRoute(options) {
2369
2379
  const { projectId } = this.options;
2370
2380
  const { select, ...rest } = options != null ? options : {};
2371
2381
  const rewrittenSelect = projectionToQuery(select);
@@ -2375,10 +2385,6 @@ var RouteClient = class extends ApiClient {
2375
2385
  this.options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0
2376
2386
  );
2377
2387
  }
2378
- /** @deprecated use {@link RouteClient.get} instead (renamed). */
2379
- async getRoute(options) {
2380
- return this.get(options);
2381
- }
2382
2388
  };
2383
2389
  var getDataSourceVariantFromRouteGetParams = (params, defaultPreviewState) => {
2384
2390
  var _a, _b;
@@ -2683,7 +2689,7 @@ function createLimitPolicy2({
2683
2689
  // src/clients/canvas.ts
2684
2690
  var getCanvasClient = (options) => {
2685
2691
  const cache = resolveCanvasCache(options);
2686
- return new CompositionDeliveryClient({
2692
+ return new CanvasClient({
2687
2693
  projectId: env.getProjectId(),
2688
2694
  apiHost: env.getApiHost(),
2689
2695
  apiKey: env.getApiKey(),
@@ -2954,14 +2960,14 @@ var DefaultDataClient = class {
2954
2960
  if (oldCachedRoute) {
2955
2961
  (0, import_functions.waitUntil)(
2956
2962
  (async () => {
2957
- const result2 = await routeClient.get(route);
2963
+ const result2 = await routeClient.getRoute(route);
2958
2964
  await cacheNewRoute(result2);
2959
2965
  })()
2960
2966
  );
2961
2967
  return oldCachedRoute;
2962
2968
  }
2963
2969
  }
2964
- const result = await routeClient.get(route);
2970
+ const result = await routeClient.getRoute(route);
2965
2971
  (0, import_functions.waitUntil)(
2966
2972
  (async () => {
2967
2973
  await Promise.all([
@@ -5558,6 +5564,7 @@ var retrieveRouteByPath = async ({
5558
5564
  releaseId,
5559
5565
  locale
5560
5566
  }) => {
5567
+ var _a;
5561
5568
  return await dataClient.getRoute({
5562
5569
  source: "middleware",
5563
5570
  searchParams,
@@ -5567,6 +5574,7 @@ var retrieveRouteByPath = async ({
5567
5574
  state,
5568
5575
  dataSourceVariant: getDataSourceVariantFromRouteGetParams({}, state),
5569
5576
  withComponentIDs: true,
5577
+ withContentSourceMap: (_a = getServerConfig().experimental) == null ? void 0 : _a.vercelVisualEditing,
5570
5578
  releaseId,
5571
5579
  locale,
5572
5580
  ignoreRedirects: shouldIgnoreRedirects({ state })
@@ -5665,7 +5673,7 @@ var handlePlaygroundRequest = async ({
5665
5673
  for (let i = 0; i < possibleStates.length; i++) {
5666
5674
  const state = possibleStates[i];
5667
5675
  try {
5668
- composition = await canvasClient.get({
5676
+ composition = await canvasClient.getCompositionById({
5669
5677
  compositionId: id,
5670
5678
  state,
5671
5679
  withComponentIDs: true