@uniformdev/next-app-router 20.74.6-alpha.3 → 20.74.7-alpha.12

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.
@@ -1413,6 +1413,16 @@ function createLimitPolicy({
1413
1413
  return currentFunc();
1414
1414
  };
1415
1415
  }
1416
+ var ContentClientBase = class extends ApiClient {
1417
+ constructor(options, defaultBypassCache) {
1418
+ var _a, _b;
1419
+ super({
1420
+ ...options,
1421
+ limitPolicy: (_a = options.limitPolicy) != null ? _a : createLimitPolicy({}),
1422
+ bypassCache: (_b = options.bypassCache) != null ? _b : defaultBypassCache
1423
+ });
1424
+ }
1425
+ };
1416
1426
  var SELECT_QUERY_PREFIX = "select.";
1417
1427
  function appendCsv(out, key, values) {
1418
1428
  if (values === void 0) {
@@ -1457,130 +1467,100 @@ function projectionToQuery(spec) {
1457
1467
  }
1458
1468
  return out;
1459
1469
  }
1460
- var CANVAS_URL = "/api/v1/canvas";
1461
- var CanvasClient = class extends ApiClient {
1462
- constructor(options) {
1463
- var _a;
1464
- if (!options.limitPolicy) {
1465
- options.limitPolicy = createLimitPolicy({});
1466
- }
1467
- super(options);
1468
- this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
1469
- this.edgeApiRequestInit = options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0;
1470
- }
1471
- /** Fetches lists of Canvas compositions, optionally by type */
1472
- async getCompositionList(params = {}) {
1473
- const { projectId } = this.options;
1474
- const { resolveData, filters, select, ...originParams } = params;
1475
- const rewrittenFilters = rewriteFiltersForApi(filters);
1476
- const rewrittenSelect = projectionToQuery(select);
1477
- if (!resolveData) {
1478
- const fetchUri = this.createUrl(CANVAS_URL, {
1479
- ...originParams,
1480
- projectId,
1481
- ...rewrittenFilters,
1482
- ...rewrittenSelect
1483
- });
1484
- return this.apiClient(fetchUri);
1485
- }
1486
- const edgeParams = {
1487
- ...originParams,
1488
- projectId,
1489
- diagnostics: typeof params.diagnostics === "boolean" ? params.diagnostics : params.diagnostics === "no-data" ? "no-data" : void 0,
1490
- ...rewrittenFilters,
1491
- ...rewrittenSelect
1492
- };
1493
- const edgeUrl = this.createUrl("/api/v1/compositions", edgeParams, this.edgeApiHost);
1494
- return this.apiClient(edgeUrl, this.edgeApiRequestInit);
1495
- }
1496
- getCompositionByNodePath(options) {
1497
- return this.getOneComposition(options);
1498
- }
1499
- getCompositionByNodeId(options) {
1500
- return this.getOneComposition(options);
1501
- }
1502
- getCompositionBySlug(options) {
1503
- return this.getOneComposition(options);
1504
- }
1505
- getCompositionById(options) {
1506
- return this.getOneComposition(options);
1507
- }
1508
- getCompositionDefaults(options) {
1509
- return this.getOneComposition(options);
1510
- }
1511
- /** Fetches historical versions of a composition or pattern */
1512
- async getCompositionHistory(options) {
1513
- const historyUrl = this.createUrl("/api/v1/canvas-history", {
1514
- ...options,
1515
- projectId: this.options.projectId
1516
- });
1517
- return this.apiClient(historyUrl);
1518
- }
1519
- getOneComposition({
1520
- skipDataResolution,
1521
- diagnostics,
1522
- ...params
1523
- }) {
1524
- const { projectId } = this.options;
1525
- if (skipDataResolution) {
1526
- return this.apiClient(this.createUrl(CANVAS_URL, { ...params, projectId }));
1527
- }
1528
- const edgeParams = {
1529
- ...params,
1530
- projectId,
1531
- diagnostics: typeof diagnostics === "boolean" ? diagnostics : diagnostics === "no-data" ? "no-data" : void 0
1470
+ var CANVAS_PERSONALIZE_TYPE = "$personalization";
1471
+ var CANVAS_TEST_TYPE = "$test";
1472
+ var CANVAS_BLOCK_PARAM_TYPE = "$block";
1473
+ var CANVAS_PERSONALIZE_SLOT = "pz";
1474
+ var CANVAS_TEST_SLOT = "test";
1475
+ var CANVAS_DRAFT_STATE = 0;
1476
+ var CANVAS_PUBLISHED_STATE = 64;
1477
+ var CANVAS_EDITOR_STATE = 63;
1478
+ var CANVAS_PERSONALIZATION_PARAM = "$pzCrit";
1479
+ var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
1480
+ var CANVAS_INTERNAL_PARAM_PREFIX = "$internal_";
1481
+ var CANVAS_COMPONENT_DISPLAY_NAME_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}displayName`;
1482
+ var CANVAS_HYPOTHESIS_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}hypothesis`;
1483
+ var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1484
+ var IN_CONTEXT_EDITOR_FORCED_SETTINGS_QUERY_STRING_PARAM = "is_incontext_editing_forced_settings";
1485
+ var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
1486
+ function resolveCompositionSelector(args) {
1487
+ if ("compositionId" in args) {
1488
+ const { compositionId, editionId, versionId, ...readOptions } = args;
1489
+ return {
1490
+ readOptions,
1491
+ // raw mode matches on composition OR edition id via the compositionId param
1492
+ compositionId: editionId != null ? editionId : compositionId,
1493
+ versionId,
1494
+ hasCompositionId: true,
1495
+ pinnedEdition: editionId !== void 0
1532
1496
  };
1533
- const edgeUrl = this.createUrl("/api/v1/composition", edgeParams, this.edgeApiHost);
1534
- return this.apiClient(edgeUrl, this.edgeApiRequestInit);
1535
1497
  }
1536
- /** Updates or creates a Canvas component definition */
1537
- async updateComposition(body, options) {
1538
- const fetchUri = this.createUrl(CANVAS_URL);
1539
- const headers = {};
1540
- if (options == null ? void 0 : options.ifUnmodifiedSince) {
1541
- headers["x-if-unmodified-since"] = options.ifUnmodifiedSince;
1542
- }
1543
- const { response } = await this.apiClientWithResponse(fetchUri, {
1544
- method: "PUT",
1545
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1546
- expectNoContent: true,
1547
- headers
1548
- });
1549
- return { modified: response.headers.get("x-modified-at") };
1498
+ return { readOptions: args, hasCompositionId: false, pinnedEdition: false };
1499
+ }
1500
+ var DEFAULT_EDGE_API_HOST = "https://uniform.global";
1501
+ var DeliveryClientBase = class extends ContentClientBase {
1502
+ constructor(options) {
1503
+ var _a;
1504
+ super(
1505
+ options,
1506
+ /* defaultBypassCache */
1507
+ false
1508
+ );
1509
+ this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : DEFAULT_EDGE_API_HOST;
1510
+ this.edgeRequestInit = options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0;
1550
1511
  }
1551
- /** Deletes a Canvas component definition */
1552
- async removeComposition(body) {
1553
- const fetchUri = this.createUrl(CANVAS_URL);
1554
- const { projectId } = this.options;
1555
- await this.apiClient(fetchUri, {
1556
- method: "DELETE",
1557
- body: JSON.stringify({ ...body, projectId }),
1558
- expectNoContent: true
1559
- });
1512
+ /** Coerces the `diagnostics` option into the shape the edge endpoints accept. */
1513
+ coerceDiagnostics(diagnostics) {
1514
+ return typeof diagnostics === "boolean" ? diagnostics : diagnostics === "no-data" ? "no-data" : void 0;
1560
1515
  }
1561
- /** Fetches all Canvas component definitions */
1562
- async getComponentDefinitions(options) {
1563
- const { projectId } = this.options;
1564
- const fetchUri = this.createUrl("/api/v1/canvas-definitions", { ...options, projectId });
1565
- return this.apiClient(fetchUri);
1516
+ };
1517
+ var EDGE_SINGLE_URL = "/api/v1/composition";
1518
+ var EDGE_LIST_URL = "/api/v1/compositions";
1519
+ var CompositionDeliveryClient = class extends DeliveryClientBase {
1520
+ constructor(options) {
1521
+ super(options);
1566
1522
  }
1567
- /** Updates or creates a Canvas component definition */
1568
- async updateComponentDefinition(body) {
1569
- const fetchUri = this.createUrl("/api/v1/canvas-definitions");
1570
- await this.apiClient(fetchUri, {
1571
- method: "PUT",
1572
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1573
- expectNoContent: true
1574
- });
1523
+ /** Fetches exactly one composition (throws `ApiClientError(404)` if absent). */
1524
+ get(args) {
1525
+ var _a;
1526
+ const { diagnostics, select, ...rest } = args;
1527
+ const { readOptions, compositionId, versionId, pinnedEdition } = resolveCompositionSelector(rest);
1528
+ const url = this.createUrl(
1529
+ EDGE_SINGLE_URL,
1530
+ {
1531
+ ...readOptions,
1532
+ ...projectionToQuery(select),
1533
+ // A pinned edition is folded into compositionId (raw matches edition or
1534
+ // composition id); there is no editionId query param on this endpoint.
1535
+ compositionId,
1536
+ versionId,
1537
+ projectId: this.options.projectId,
1538
+ state: (_a = args.state) != null ? _a : CANVAS_PUBLISHED_STATE,
1539
+ // editionId pins a specific edition for preview; otherwise locale-best.
1540
+ editions: pinnedEdition ? "raw" : "auto",
1541
+ diagnostics: this.coerceDiagnostics(diagnostics)
1542
+ },
1543
+ this.edgeApiHost
1544
+ );
1545
+ return this.apiClient(url, this.edgeRequestInit);
1575
1546
  }
1576
- /** Deletes a Canvas component definition */
1577
- async removeComponentDefinition(body) {
1578
- const fetchUri = this.createUrl("/api/v1/canvas-definitions");
1579
- await this.apiClient(fetchUri, {
1580
- method: "DELETE",
1581
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1582
- expectNoContent: true
1583
- });
1547
+ /** Fetches a list of compositions, optionally filtered. */
1548
+ list(args = {}) {
1549
+ var _a;
1550
+ const { diagnostics, filters, select, ...rest } = args;
1551
+ const url = this.createUrl(
1552
+ EDGE_LIST_URL,
1553
+ {
1554
+ ...rest,
1555
+ ...rewriteFiltersForApi(filters),
1556
+ ...projectionToQuery(select),
1557
+ projectId: this.options.projectId,
1558
+ state: (_a = args.state) != null ? _a : CANVAS_PUBLISHED_STATE,
1559
+ diagnostics: this.coerceDiagnostics(diagnostics)
1560
+ },
1561
+ this.edgeApiHost
1562
+ );
1563
+ return this.apiClient(url, this.edgeRequestInit);
1584
1564
  }
1585
1565
  };
1586
1566
  var _contentTypesUrl;
@@ -1689,14 +1669,18 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1689
1669
  constructor(options) {
1690
1670
  super(options);
1691
1671
  }
1692
- /** Fetches all DataTypes for a project */
1693
- async get(options) {
1672
+ /** Fetches a list of DataTypes for a project */
1673
+ async list(options) {
1694
1674
  const { projectId } = this.options;
1695
1675
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8), { ...options, projectId });
1696
1676
  return await this.apiClient(fetchUri);
1697
1677
  }
1678
+ /** @deprecated Use {@link list} instead. */
1679
+ async get(options) {
1680
+ return this.list(options);
1681
+ }
1698
1682
  /** Updates or creates (based on id) a DataType */
1699
- async upsert(body) {
1683
+ async save(body) {
1700
1684
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
1701
1685
  await this.apiClient(fetchUri, {
1702
1686
  method: "PUT",
@@ -1704,6 +1688,10 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1704
1688
  expectNoContent: true
1705
1689
  });
1706
1690
  }
1691
+ /** @deprecated Use {@link save} instead. */
1692
+ async upsert(body) {
1693
+ return this.save(body);
1694
+ }
1707
1695
  /** Deletes a DataType */
1708
1696
  async remove(body) {
1709
1697
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
@@ -1741,22 +1729,6 @@ function getComponentPath(ancestorsAndSelf) {
1741
1729
  }
1742
1730
  return `.${path.join(".")}`;
1743
1731
  }
1744
- var CANVAS_PERSONALIZE_TYPE = "$personalization";
1745
- var CANVAS_TEST_TYPE = "$test";
1746
- var CANVAS_BLOCK_PARAM_TYPE = "$block";
1747
- var CANVAS_PERSONALIZE_SLOT = "pz";
1748
- var CANVAS_TEST_SLOT = "test";
1749
- var CANVAS_DRAFT_STATE = 0;
1750
- var CANVAS_PUBLISHED_STATE = 64;
1751
- var CANVAS_EDITOR_STATE = 63;
1752
- var CANVAS_PERSONALIZATION_PARAM = "$pzCrit";
1753
- var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
1754
- var CANVAS_INTERNAL_PARAM_PREFIX = "$internal_";
1755
- var CANVAS_COMPONENT_DISPLAY_NAME_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}displayName`;
1756
- var CANVAS_HYPOTHESIS_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}hypothesis`;
1757
- var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1758
- var IN_CONTEXT_EDITOR_FORCED_SETTINGS_QUERY_STRING_PARAM = "is_incontext_editing_forced_settings";
1759
- var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
1760
1732
  function isRootEntryReference(root) {
1761
1733
  return root.type === "root" && isEntryData(root.node);
1762
1734
  }
@@ -2358,20 +2330,28 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
2358
2330
  * When teamId is provided, returns a single team with its projects.
2359
2331
  * When omitted, returns all accessible teams and their projects.
2360
2332
  */
2361
- async getProjects(options) {
2333
+ async list(options) {
2362
2334
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
2363
2335
  return await this.apiClient(fetchUri);
2364
2336
  }
2337
+ /** @deprecated Use {@link list} instead. */
2338
+ async getProjects(options) {
2339
+ return this.list(options);
2340
+ }
2365
2341
  /** Updates or creates (based on id) a Project */
2366
- async upsert(body) {
2342
+ async save(body) {
2367
2343
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
2368
2344
  return await this.apiClient(fetchUri, {
2369
2345
  method: "PUT",
2370
2346
  body: JSON.stringify({ ...body })
2371
2347
  });
2372
2348
  }
2349
+ /** @deprecated Use {@link save} instead. */
2350
+ async upsert(body) {
2351
+ return this.save(body);
2352
+ }
2373
2353
  /** Deletes a Project */
2374
- async delete(body) {
2354
+ async remove(body) {
2375
2355
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
2376
2356
  await this.apiClient(fetchUri, {
2377
2357
  method: "DELETE",
@@ -2379,6 +2359,10 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
2379
2359
  expectNoContent: true
2380
2360
  });
2381
2361
  }
2362
+ /** @deprecated Use {@link remove} instead. */
2363
+ async delete(body) {
2364
+ return this.remove(body);
2365
+ }
2382
2366
  };
2383
2367
  _url22 = /* @__PURE__ */ new WeakMap();
2384
2368
  _projectsUrl = /* @__PURE__ */ new WeakMap();
@@ -2394,8 +2378,14 @@ var RouteClient = class extends ApiClient {
2394
2378
  super(options);
2395
2379
  this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
2396
2380
  }
2397
- /** Fetches lists of Canvas compositions, optionally by type */
2398
- async getRoute(options) {
2381
+ /**
2382
+ * Resolves a route to a composition, redirect, or not-found result.
2383
+ *
2384
+ * An optional `select` projection applies to the resolved composition when
2385
+ * the route matches one; redirect / notFound responses pass through
2386
+ * untouched.
2387
+ */
2388
+ async get(options) {
2399
2389
  const { projectId } = this.options;
2400
2390
  const { select, ...rest } = options != null ? options : {};
2401
2391
  const rewrittenSelect = projectionToQuery(select);
@@ -2405,6 +2395,10 @@ var RouteClient = class extends ApiClient {
2405
2395
  this.options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0
2406
2396
  );
2407
2397
  }
2398
+ /** @deprecated use {@link RouteClient.get} instead (renamed). */
2399
+ async getRoute(options) {
2400
+ return this.get(options);
2401
+ }
2408
2402
  };
2409
2403
  var getDataSourceVariantFromRouteGetParams = (params, defaultPreviewState) => {
2410
2404
  var _a, _b;
@@ -2707,9 +2701,9 @@ function createLimitPolicy2({
2707
2701
  }
2708
2702
 
2709
2703
  // src/clients/canvas.ts
2710
- var getCanvasClient = (options) => {
2704
+ var buildCanvasClientOptions = (options) => {
2711
2705
  const cache = resolveCanvasCache(options);
2712
- return new CanvasClient({
2706
+ return {
2713
2707
  projectId: env.getProjectId(),
2714
2708
  apiHost: env.getApiHost(),
2715
2709
  apiKey: env.getApiKey(),
@@ -2757,7 +2751,10 @@ var getCanvasClient = (options) => {
2757
2751
  }
2758
2752
  });
2759
2753
  }
2760
- });
2754
+ };
2755
+ };
2756
+ var getCompositionDeliveryClient = (options) => {
2757
+ return new CompositionDeliveryClient(buildCanvasClientOptions(options));
2761
2758
  };
2762
2759
 
2763
2760
  // src/config/helpers.ts
@@ -2980,14 +2977,14 @@ var DefaultDataClient = class {
2980
2977
  if (oldCachedRoute) {
2981
2978
  (0, import_functions.waitUntil)(
2982
2979
  (async () => {
2983
- const result2 = await routeClient.getRoute(route);
2980
+ const result2 = await routeClient.get(route);
2984
2981
  await cacheNewRoute(result2);
2985
2982
  })()
2986
2983
  );
2987
2984
  return oldCachedRoute;
2988
2985
  }
2989
2986
  }
2990
- const result = await routeClient.getRoute(route);
2987
+ const result = await routeClient.get(route);
2991
2988
  (0, import_functions.waitUntil)(
2992
2989
  (async () => {
2993
2990
  await Promise.all([
@@ -5585,7 +5582,6 @@ var retrieveRouteByPath = async ({
5585
5582
  releaseId,
5586
5583
  locale
5587
5584
  }) => {
5588
- var _a;
5589
5585
  return await dataClient.getRoute({
5590
5586
  source: "middleware",
5591
5587
  searchParams,
@@ -5595,7 +5591,6 @@ var retrieveRouteByPath = async ({
5595
5591
  state,
5596
5592
  dataSourceVariant: getDataSourceVariantFromRouteGetParams({}, state),
5597
5593
  withComponentIDs: true,
5598
- withContentSourceMap: (_a = getServerConfig().experimental) == null ? void 0 : _a.vercelVisualEditing,
5599
5594
  releaseId,
5600
5595
  locale,
5601
5596
  ignoreRedirects: shouldIgnoreRedirects({ state })
@@ -5684,7 +5679,7 @@ var handlePlaygroundRequest = async ({
5684
5679
  { status: 400 }
5685
5680
  );
5686
5681
  }
5687
- const canvasClient = getCanvasClient({
5682
+ const canvasClient = getCompositionDeliveryClient({
5688
5683
  cache: {
5689
5684
  type: "no-cache"
5690
5685
  }
@@ -5694,7 +5689,7 @@ var handlePlaygroundRequest = async ({
5694
5689
  for (let i = 0; i < possibleStates.length; i++) {
5695
5690
  const state = possibleStates[i];
5696
5691
  try {
5697
- composition = await canvasClient.getCompositionById({
5692
+ composition = await canvasClient.get({
5698
5693
  compositionId: id,
5699
5694
  state,
5700
5695
  withComponentIDs: true