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

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.
package/dist/index.js CHANGED
@@ -408,6 +408,7 @@ __export(index_exports, {
408
408
  expireMiddlewareCacheTag: () => expireMiddlewareCacheTag,
409
409
  findRouteMatch: () => findRouteMatch,
410
410
  getCanvasClient: () => getCanvasClient,
411
+ getCompositionDeliveryClient: () => getCompositionDeliveryClient,
411
412
  getManifest: () => getManifest,
412
413
  getManifestClient: () => getManifestClient,
413
414
  getProjectMapClient: () => getProjectMapClient,
@@ -1242,6 +1243,16 @@ function createLimitPolicy({
1242
1243
  return currentFunc();
1243
1244
  };
1244
1245
  }
1246
+ var ContentClientBase = class extends ApiClient {
1247
+ constructor(options, defaultBypassCache) {
1248
+ var _a, _b;
1249
+ super({
1250
+ ...options,
1251
+ limitPolicy: (_a = options.limitPolicy) != null ? _a : createLimitPolicy({}),
1252
+ bypassCache: (_b = options.bypassCache) != null ? _b : defaultBypassCache
1253
+ });
1254
+ }
1255
+ };
1245
1256
  var SELECT_QUERY_PREFIX = "select.";
1246
1257
  function appendCsv(out, key, values) {
1247
1258
  if (values === void 0) {
@@ -1286,7 +1297,105 @@ function projectionToQuery(spec) {
1286
1297
  }
1287
1298
  return out;
1288
1299
  }
1289
- var CANVAS_URL = "/api/v1/canvas";
1300
+ var CANVAS_PERSONALIZE_TYPE = "$personalization";
1301
+ var CANVAS_TEST_TYPE = "$test";
1302
+ var CANVAS_BLOCK_PARAM_TYPE = "$block";
1303
+ var CANVAS_PERSONALIZE_SLOT = "pz";
1304
+ var CANVAS_TEST_SLOT = "test";
1305
+ var CANVAS_DRAFT_STATE = 0;
1306
+ var CANVAS_PUBLISHED_STATE = 64;
1307
+ var CANVAS_EDITOR_STATE = 63;
1308
+ var CANVAS_PERSONALIZATION_PARAM = "$pzCrit";
1309
+ var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
1310
+ var CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
1311
+ var CANVAS_INTERNAL_PARAM_PREFIX = "$internal_";
1312
+ var CANVAS_COMPONENT_DISPLAY_NAME_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}displayName`;
1313
+ var CANVAS_HYPOTHESIS_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}hypothesis`;
1314
+ var CANVAS_CONTEXTUAL_EDITING_PARAM = "$contextualEditing";
1315
+ var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1316
+ var PLACEHOLDER_ID = "placeholder";
1317
+ var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
1318
+ function resolveCompositionSelector(args) {
1319
+ if ("compositionId" in args) {
1320
+ const { compositionId, editionId, versionId, ...readOptions } = args;
1321
+ return {
1322
+ readOptions,
1323
+ // raw mode matches on composition OR edition id via the compositionId param
1324
+ compositionId: editionId != null ? editionId : compositionId,
1325
+ versionId,
1326
+ hasCompositionId: true,
1327
+ pinnedEdition: editionId !== void 0
1328
+ };
1329
+ }
1330
+ return { readOptions: args, hasCompositionId: false, pinnedEdition: false };
1331
+ }
1332
+ var DEFAULT_EDGE_API_HOST = "https://uniform.global";
1333
+ var DeliveryClientBase = class extends ContentClientBase {
1334
+ constructor(options) {
1335
+ var _a;
1336
+ super(
1337
+ options,
1338
+ /* defaultBypassCache */
1339
+ false
1340
+ );
1341
+ this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : DEFAULT_EDGE_API_HOST;
1342
+ this.edgeRequestInit = options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0;
1343
+ }
1344
+ /** Coerces the `diagnostics` option into the shape the edge endpoints accept. */
1345
+ coerceDiagnostics(diagnostics) {
1346
+ return typeof diagnostics === "boolean" ? diagnostics : diagnostics === "no-data" ? "no-data" : void 0;
1347
+ }
1348
+ };
1349
+ var EDGE_SINGLE_URL = "/api/v1/composition";
1350
+ var EDGE_LIST_URL = "/api/v1/compositions";
1351
+ var CompositionDeliveryClient = class extends DeliveryClientBase {
1352
+ constructor(options) {
1353
+ super(options);
1354
+ }
1355
+ /** Fetches exactly one composition (throws `ApiClientError(404)` if absent). */
1356
+ get(args) {
1357
+ var _a;
1358
+ const { diagnostics, select, ...rest } = args;
1359
+ const { readOptions, compositionId, versionId, pinnedEdition } = resolveCompositionSelector(rest);
1360
+ const url = this.createUrl(
1361
+ EDGE_SINGLE_URL,
1362
+ {
1363
+ ...readOptions,
1364
+ ...projectionToQuery(select),
1365
+ // A pinned edition is folded into compositionId (raw matches edition or
1366
+ // composition id); there is no editionId query param on this endpoint.
1367
+ compositionId,
1368
+ versionId,
1369
+ projectId: this.options.projectId,
1370
+ state: (_a = args.state) != null ? _a : CANVAS_PUBLISHED_STATE,
1371
+ // editionId pins a specific edition for preview; otherwise locale-best.
1372
+ editions: pinnedEdition ? "raw" : "auto",
1373
+ diagnostics: this.coerceDiagnostics(diagnostics)
1374
+ },
1375
+ this.edgeApiHost
1376
+ );
1377
+ return this.apiClient(url, this.edgeRequestInit);
1378
+ }
1379
+ /** Fetches a list of compositions, optionally filtered. */
1380
+ list(args = {}) {
1381
+ var _a;
1382
+ const { diagnostics, filters, select, ...rest } = args;
1383
+ const url = this.createUrl(
1384
+ EDGE_LIST_URL,
1385
+ {
1386
+ ...rest,
1387
+ ...rewriteFiltersForApi(filters),
1388
+ ...projectionToQuery(select),
1389
+ projectId: this.options.projectId,
1390
+ state: (_a = args.state) != null ? _a : CANVAS_PUBLISHED_STATE,
1391
+ diagnostics: this.coerceDiagnostics(diagnostics)
1392
+ },
1393
+ this.edgeApiHost
1394
+ );
1395
+ return this.apiClient(url, this.edgeRequestInit);
1396
+ }
1397
+ };
1398
+ var CANVAS_URL2 = "/api/v1/canvas";
1290
1399
  var CanvasClient = class extends ApiClient {
1291
1400
  constructor(options) {
1292
1401
  var _a;
@@ -1304,7 +1413,7 @@ var CanvasClient = class extends ApiClient {
1304
1413
  const rewrittenFilters = rewriteFiltersForApi(filters);
1305
1414
  const rewrittenSelect = projectionToQuery(select);
1306
1415
  if (!resolveData) {
1307
- const fetchUri = this.createUrl(CANVAS_URL, {
1416
+ const fetchUri = this.createUrl(CANVAS_URL2, {
1308
1417
  ...originParams,
1309
1418
  projectId,
1310
1419
  ...rewrittenFilters,
@@ -1352,7 +1461,7 @@ var CanvasClient = class extends ApiClient {
1352
1461
  }) {
1353
1462
  const { projectId } = this.options;
1354
1463
  if (skipDataResolution) {
1355
- return this.apiClient(this.createUrl(CANVAS_URL, { ...params, projectId }));
1464
+ return this.apiClient(this.createUrl(CANVAS_URL2, { ...params, projectId }));
1356
1465
  }
1357
1466
  const edgeParams = {
1358
1467
  ...params,
@@ -1364,7 +1473,7 @@ var CanvasClient = class extends ApiClient {
1364
1473
  }
1365
1474
  /** Updates or creates a Canvas component definition */
1366
1475
  async updateComposition(body, options) {
1367
- const fetchUri = this.createUrl(CANVAS_URL);
1476
+ const fetchUri = this.createUrl(CANVAS_URL2);
1368
1477
  const headers = {};
1369
1478
  if (options == null ? void 0 : options.ifUnmodifiedSince) {
1370
1479
  headers["x-if-unmodified-since"] = options.ifUnmodifiedSince;
@@ -1379,7 +1488,7 @@ var CanvasClient = class extends ApiClient {
1379
1488
  }
1380
1489
  /** Deletes a Canvas component definition */
1381
1490
  async removeComposition(body) {
1382
- const fetchUri = this.createUrl(CANVAS_URL);
1491
+ const fetchUri = this.createUrl(CANVAS_URL2);
1383
1492
  const { projectId } = this.options;
1384
1493
  await this.apiClient(fetchUri, {
1385
1494
  method: "DELETE",
@@ -1518,14 +1627,18 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1518
1627
  constructor(options) {
1519
1628
  super(options);
1520
1629
  }
1521
- /** Fetches all DataTypes for a project */
1522
- async get(options) {
1630
+ /** Fetches a list of DataTypes for a project */
1631
+ async list(options) {
1523
1632
  const { projectId } = this.options;
1524
1633
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8), { ...options, projectId });
1525
1634
  return await this.apiClient(fetchUri);
1526
1635
  }
1636
+ /** @deprecated Use {@link list} instead. */
1637
+ async get(options) {
1638
+ return this.list(options);
1639
+ }
1527
1640
  /** Updates or creates (based on id) a DataType */
1528
- async upsert(body) {
1641
+ async save(body) {
1529
1642
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
1530
1643
  await this.apiClient(fetchUri, {
1531
1644
  method: "PUT",
@@ -1533,6 +1646,10 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1533
1646
  expectNoContent: true
1534
1647
  });
1535
1648
  }
1649
+ /** @deprecated Use {@link save} instead. */
1650
+ async upsert(body) {
1651
+ return this.save(body);
1652
+ }
1536
1653
  /** Deletes a DataType */
1537
1654
  async remove(body) {
1538
1655
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
@@ -1570,24 +1687,6 @@ function getComponentPath(ancestorsAndSelf) {
1570
1687
  }
1571
1688
  return `.${path.join(".")}`;
1572
1689
  }
1573
- var CANVAS_PERSONALIZE_TYPE = "$personalization";
1574
- var CANVAS_TEST_TYPE = "$test";
1575
- var CANVAS_BLOCK_PARAM_TYPE = "$block";
1576
- var CANVAS_PERSONALIZE_SLOT = "pz";
1577
- var CANVAS_TEST_SLOT = "test";
1578
- var CANVAS_DRAFT_STATE = 0;
1579
- var CANVAS_PUBLISHED_STATE = 64;
1580
- var CANVAS_EDITOR_STATE = 63;
1581
- var CANVAS_PERSONALIZATION_PARAM = "$pzCrit";
1582
- var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
1583
- var CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
1584
- var CANVAS_INTERNAL_PARAM_PREFIX = "$internal_";
1585
- var CANVAS_COMPONENT_DISPLAY_NAME_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}displayName`;
1586
- var CANVAS_HYPOTHESIS_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}hypothesis`;
1587
- var CANVAS_CONTEXTUAL_EDITING_PARAM = "$contextualEditing";
1588
- var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1589
- var PLACEHOLDER_ID = "placeholder";
1590
- var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
1591
1690
  function isRootEntryReference(root) {
1592
1691
  return root.type === "root" && isEntryData(root.node);
1593
1692
  }
@@ -2044,20 +2143,28 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
2044
2143
  * When teamId is provided, returns a single team with its projects.
2045
2144
  * When omitted, returns all accessible teams and their projects.
2046
2145
  */
2047
- async getProjects(options) {
2146
+ async list(options) {
2048
2147
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
2049
2148
  return await this.apiClient(fetchUri);
2050
2149
  }
2150
+ /** @deprecated Use {@link list} instead. */
2151
+ async getProjects(options) {
2152
+ return this.list(options);
2153
+ }
2051
2154
  /** Updates or creates (based on id) a Project */
2052
- async upsert(body) {
2155
+ async save(body) {
2053
2156
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
2054
2157
  return await this.apiClient(fetchUri, {
2055
2158
  method: "PUT",
2056
2159
  body: JSON.stringify({ ...body })
2057
2160
  });
2058
2161
  }
2162
+ /** @deprecated Use {@link save} instead. */
2163
+ async upsert(body) {
2164
+ return this.save(body);
2165
+ }
2059
2166
  /** Deletes a Project */
2060
- async delete(body) {
2167
+ async remove(body) {
2061
2168
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
2062
2169
  await this.apiClient(fetchUri, {
2063
2170
  method: "DELETE",
@@ -2065,6 +2172,10 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
2065
2172
  expectNoContent: true
2066
2173
  });
2067
2174
  }
2175
+ /** @deprecated Use {@link remove} instead. */
2176
+ async delete(body) {
2177
+ return this.remove(body);
2178
+ }
2068
2179
  };
2069
2180
  _url22 = /* @__PURE__ */ new WeakMap();
2070
2181
  _projectsUrl = /* @__PURE__ */ new WeakMap();
@@ -2080,8 +2191,14 @@ var RouteClient = class extends ApiClient {
2080
2191
  super(options);
2081
2192
  this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
2082
2193
  }
2083
- /** Fetches lists of Canvas compositions, optionally by type */
2084
- async getRoute(options) {
2194
+ /**
2195
+ * Resolves a route to a composition, redirect, or not-found result.
2196
+ *
2197
+ * An optional `select` projection applies to the resolved composition when
2198
+ * the route matches one; redirect / notFound responses pass through
2199
+ * untouched.
2200
+ */
2201
+ async get(options) {
2085
2202
  const { projectId } = this.options;
2086
2203
  const { select, ...rest } = options != null ? options : {};
2087
2204
  const rewrittenSelect = projectionToQuery(select);
@@ -2091,6 +2208,10 @@ var RouteClient = class extends ApiClient {
2091
2208
  this.options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0
2092
2209
  );
2093
2210
  }
2211
+ /** @deprecated use {@link RouteClient.get} instead (renamed). */
2212
+ async getRoute(options) {
2213
+ return this.get(options);
2214
+ }
2094
2215
  };
2095
2216
  var getDataSourceVariantFromRouteGetParams = (params, defaultPreviewState) => {
2096
2217
  var _a, _b;
@@ -2397,9 +2518,9 @@ function createLimitPolicy2({
2397
2518
  }
2398
2519
 
2399
2520
  // src/clients/canvas.ts
2400
- var getCanvasClient = (options) => {
2521
+ var buildCanvasClientOptions = (options) => {
2401
2522
  const cache2 = resolveCanvasCache(options);
2402
- return new CanvasClient({
2523
+ return {
2403
2524
  projectId: env.getProjectId(),
2404
2525
  apiHost: env.getApiHost(),
2405
2526
  apiKey: env.getApiKey(),
@@ -2447,7 +2568,13 @@ var getCanvasClient = (options) => {
2447
2568
  }
2448
2569
  });
2449
2570
  }
2450
- });
2571
+ };
2572
+ };
2573
+ var getCanvasClient = (options) => {
2574
+ return new CanvasClient(buildCanvasClientOptions(options));
2575
+ };
2576
+ var getCompositionDeliveryClient = (options) => {
2577
+ return new CompositionDeliveryClient(buildCanvasClientOptions(options));
2451
2578
  };
2452
2579
 
2453
2580
  // src/clients/manifest.ts
@@ -3481,14 +3608,14 @@ var import_react7 = __toESM(require("react"));
3481
3608
  var import_next_app_router_shared5 = require("@uniformdev/next-app-router-shared");
3482
3609
  var resolvePlaygroundRoute = async ({ code }) => {
3483
3610
  const pageState = (0, import_next_app_router_shared5.deserializeEvaluationResult)({ input: code });
3484
- const canvasClient = getCanvasClient({
3611
+ const canvasClient = getCompositionDeliveryClient({
3485
3612
  cache: {
3486
3613
  type: "no-cache"
3487
3614
  }
3488
3615
  });
3489
3616
  let composition = void 0;
3490
3617
  try {
3491
- composition = await canvasClient.getCompositionById({
3618
+ composition = await canvasClient.get({
3492
3619
  compositionId: pageState.routePath,
3493
3620
  state: pageState.compositionState,
3494
3621
  withComponentIDs: true
@@ -3634,7 +3761,7 @@ var createUniformPlaygroundStaticParams = async (options) => {
3634
3761
  const routeClient = getRouteClient({
3635
3762
  state
3636
3763
  });
3637
- route = await routeClient.getRoute({
3764
+ route = await routeClient.get({
3638
3765
  path: firstPath,
3639
3766
  withComponentIDs: true,
3640
3767
  state: CANVAS_DRAFT_STATE
@@ -3687,7 +3814,7 @@ async function processRoutePath({
3687
3814
  });
3688
3815
  const rewrittenPath = await (rewrite == null ? void 0 : rewrite({ path }));
3689
3816
  const resolvedPath = (_a = rewrittenPath == null ? void 0 : rewrittenPath.path) != null ? _a : path;
3690
- const route = await routeClient.getRoute({
3817
+ const route = await routeClient.get({
3691
3818
  path: resolvedPath,
3692
3819
  withComponentIDs: true,
3693
3820
  state: CANVAS_PUBLISHED_STATE
@@ -3940,14 +4067,14 @@ var DefaultDataClient = class {
3940
4067
  if (oldCachedRoute) {
3941
4068
  (0, import_functions.waitUntil)(
3942
4069
  (async () => {
3943
- const result2 = await routeClient.getRoute(route);
4070
+ const result2 = await routeClient.get(route);
3944
4071
  await cacheNewRoute(result2);
3945
4072
  })()
3946
4073
  );
3947
4074
  return oldCachedRoute;
3948
4075
  }
3949
4076
  }
3950
- const result = await routeClient.getRoute(route);
4077
+ const result = await routeClient.get(route);
3951
4078
  (0, import_functions.waitUntil)(
3952
4079
  (async () => {
3953
4080
  await Promise.all([
@@ -4217,6 +4344,7 @@ var createCompositionCache = () => {
4217
4344
  expireMiddlewareCacheTag,
4218
4345
  findRouteMatch,
4219
4346
  getCanvasClient,
4347
+ getCompositionDeliveryClient,
4220
4348
  getManifest,
4221
4349
  getManifestClient,
4222
4350
  getProjectMapClient,