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

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.esm.js CHANGED
@@ -1215,6 +1215,16 @@ function createLimitPolicy({
1215
1215
  return currentFunc();
1216
1216
  };
1217
1217
  }
1218
+ var ContentClientBase = class extends ApiClient {
1219
+ constructor(options, defaultBypassCache) {
1220
+ var _a, _b;
1221
+ super({
1222
+ ...options,
1223
+ limitPolicy: (_a = options.limitPolicy) != null ? _a : createLimitPolicy({}),
1224
+ bypassCache: (_b = options.bypassCache) != null ? _b : defaultBypassCache
1225
+ });
1226
+ }
1227
+ };
1218
1228
  var SELECT_QUERY_PREFIX = "select.";
1219
1229
  function appendCsv(out, key, values) {
1220
1230
  if (values === void 0) {
@@ -1259,7 +1269,105 @@ function projectionToQuery(spec) {
1259
1269
  }
1260
1270
  return out;
1261
1271
  }
1262
- var CANVAS_URL = "/api/v1/canvas";
1272
+ var CANVAS_PERSONALIZE_TYPE = "$personalization";
1273
+ var CANVAS_TEST_TYPE = "$test";
1274
+ var CANVAS_BLOCK_PARAM_TYPE = "$block";
1275
+ var CANVAS_PERSONALIZE_SLOT = "pz";
1276
+ var CANVAS_TEST_SLOT = "test";
1277
+ var CANVAS_DRAFT_STATE = 0;
1278
+ var CANVAS_PUBLISHED_STATE = 64;
1279
+ var CANVAS_EDITOR_STATE = 63;
1280
+ var CANVAS_PERSONALIZATION_PARAM = "$pzCrit";
1281
+ var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
1282
+ var CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
1283
+ var CANVAS_INTERNAL_PARAM_PREFIX = "$internal_";
1284
+ var CANVAS_COMPONENT_DISPLAY_NAME_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}displayName`;
1285
+ var CANVAS_HYPOTHESIS_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}hypothesis`;
1286
+ var CANVAS_CONTEXTUAL_EDITING_PARAM = "$contextualEditing";
1287
+ var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1288
+ var PLACEHOLDER_ID = "placeholder";
1289
+ var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
1290
+ function resolveCompositionSelector(args) {
1291
+ if ("compositionId" in args) {
1292
+ const { compositionId, editionId, versionId, ...readOptions } = args;
1293
+ return {
1294
+ readOptions,
1295
+ // raw mode matches on composition OR edition id via the compositionId param
1296
+ compositionId: editionId != null ? editionId : compositionId,
1297
+ versionId,
1298
+ hasCompositionId: true,
1299
+ pinnedEdition: editionId !== void 0
1300
+ };
1301
+ }
1302
+ return { readOptions: args, hasCompositionId: false, pinnedEdition: false };
1303
+ }
1304
+ var DEFAULT_EDGE_API_HOST = "https://uniform.global";
1305
+ var DeliveryClientBase = class extends ContentClientBase {
1306
+ constructor(options) {
1307
+ var _a;
1308
+ super(
1309
+ options,
1310
+ /* defaultBypassCache */
1311
+ false
1312
+ );
1313
+ this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : DEFAULT_EDGE_API_HOST;
1314
+ this.edgeRequestInit = options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0;
1315
+ }
1316
+ /** Coerces the `diagnostics` option into the shape the edge endpoints accept. */
1317
+ coerceDiagnostics(diagnostics) {
1318
+ return typeof diagnostics === "boolean" ? diagnostics : diagnostics === "no-data" ? "no-data" : void 0;
1319
+ }
1320
+ };
1321
+ var EDGE_SINGLE_URL = "/api/v1/composition";
1322
+ var EDGE_LIST_URL = "/api/v1/compositions";
1323
+ var CompositionDeliveryClient = class extends DeliveryClientBase {
1324
+ constructor(options) {
1325
+ super(options);
1326
+ }
1327
+ /** Fetches exactly one composition (throws `ApiClientError(404)` if absent). */
1328
+ get(args) {
1329
+ var _a;
1330
+ const { diagnostics, select, ...rest } = args;
1331
+ const { readOptions, compositionId, versionId, pinnedEdition } = resolveCompositionSelector(rest);
1332
+ const url = this.createUrl(
1333
+ EDGE_SINGLE_URL,
1334
+ {
1335
+ ...readOptions,
1336
+ ...projectionToQuery(select),
1337
+ // A pinned edition is folded into compositionId (raw matches edition or
1338
+ // composition id); there is no editionId query param on this endpoint.
1339
+ compositionId,
1340
+ versionId,
1341
+ projectId: this.options.projectId,
1342
+ state: (_a = args.state) != null ? _a : CANVAS_PUBLISHED_STATE,
1343
+ // editionId pins a specific edition for preview; otherwise locale-best.
1344
+ editions: pinnedEdition ? "raw" : "auto",
1345
+ diagnostics: this.coerceDiagnostics(diagnostics)
1346
+ },
1347
+ this.edgeApiHost
1348
+ );
1349
+ return this.apiClient(url, this.edgeRequestInit);
1350
+ }
1351
+ /** Fetches a list of compositions, optionally filtered. */
1352
+ list(args = {}) {
1353
+ var _a;
1354
+ const { diagnostics, filters, select, ...rest } = args;
1355
+ const url = this.createUrl(
1356
+ EDGE_LIST_URL,
1357
+ {
1358
+ ...rest,
1359
+ ...rewriteFiltersForApi(filters),
1360
+ ...projectionToQuery(select),
1361
+ projectId: this.options.projectId,
1362
+ state: (_a = args.state) != null ? _a : CANVAS_PUBLISHED_STATE,
1363
+ diagnostics: this.coerceDiagnostics(diagnostics)
1364
+ },
1365
+ this.edgeApiHost
1366
+ );
1367
+ return this.apiClient(url, this.edgeRequestInit);
1368
+ }
1369
+ };
1370
+ var CANVAS_URL2 = "/api/v1/canvas";
1263
1371
  var CanvasClient = class extends ApiClient {
1264
1372
  constructor(options) {
1265
1373
  var _a;
@@ -1277,7 +1385,7 @@ var CanvasClient = class extends ApiClient {
1277
1385
  const rewrittenFilters = rewriteFiltersForApi(filters);
1278
1386
  const rewrittenSelect = projectionToQuery(select);
1279
1387
  if (!resolveData) {
1280
- const fetchUri = this.createUrl(CANVAS_URL, {
1388
+ const fetchUri = this.createUrl(CANVAS_URL2, {
1281
1389
  ...originParams,
1282
1390
  projectId,
1283
1391
  ...rewrittenFilters,
@@ -1325,7 +1433,7 @@ var CanvasClient = class extends ApiClient {
1325
1433
  }) {
1326
1434
  const { projectId } = this.options;
1327
1435
  if (skipDataResolution) {
1328
- return this.apiClient(this.createUrl(CANVAS_URL, { ...params, projectId }));
1436
+ return this.apiClient(this.createUrl(CANVAS_URL2, { ...params, projectId }));
1329
1437
  }
1330
1438
  const edgeParams = {
1331
1439
  ...params,
@@ -1337,7 +1445,7 @@ var CanvasClient = class extends ApiClient {
1337
1445
  }
1338
1446
  /** Updates or creates a Canvas component definition */
1339
1447
  async updateComposition(body, options) {
1340
- const fetchUri = this.createUrl(CANVAS_URL);
1448
+ const fetchUri = this.createUrl(CANVAS_URL2);
1341
1449
  const headers = {};
1342
1450
  if (options == null ? void 0 : options.ifUnmodifiedSince) {
1343
1451
  headers["x-if-unmodified-since"] = options.ifUnmodifiedSince;
@@ -1352,7 +1460,7 @@ var CanvasClient = class extends ApiClient {
1352
1460
  }
1353
1461
  /** Deletes a Canvas component definition */
1354
1462
  async removeComposition(body) {
1355
- const fetchUri = this.createUrl(CANVAS_URL);
1463
+ const fetchUri = this.createUrl(CANVAS_URL2);
1356
1464
  const { projectId } = this.options;
1357
1465
  await this.apiClient(fetchUri, {
1358
1466
  method: "DELETE",
@@ -1491,14 +1599,18 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1491
1599
  constructor(options) {
1492
1600
  super(options);
1493
1601
  }
1494
- /** Fetches all DataTypes for a project */
1495
- async get(options) {
1602
+ /** Fetches a list of DataTypes for a project */
1603
+ async list(options) {
1496
1604
  const { projectId } = this.options;
1497
1605
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8), { ...options, projectId });
1498
1606
  return await this.apiClient(fetchUri);
1499
1607
  }
1608
+ /** @deprecated Use {@link list} instead. */
1609
+ async get(options) {
1610
+ return this.list(options);
1611
+ }
1500
1612
  /** Updates or creates (based on id) a DataType */
1501
- async upsert(body) {
1613
+ async save(body) {
1502
1614
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
1503
1615
  await this.apiClient(fetchUri, {
1504
1616
  method: "PUT",
@@ -1506,6 +1618,10 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1506
1618
  expectNoContent: true
1507
1619
  });
1508
1620
  }
1621
+ /** @deprecated Use {@link save} instead. */
1622
+ async upsert(body) {
1623
+ return this.save(body);
1624
+ }
1509
1625
  /** Deletes a DataType */
1510
1626
  async remove(body) {
1511
1627
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
@@ -1543,24 +1659,6 @@ function getComponentPath(ancestorsAndSelf) {
1543
1659
  }
1544
1660
  return `.${path.join(".")}`;
1545
1661
  }
1546
- var CANVAS_PERSONALIZE_TYPE = "$personalization";
1547
- var CANVAS_TEST_TYPE = "$test";
1548
- var CANVAS_BLOCK_PARAM_TYPE = "$block";
1549
- var CANVAS_PERSONALIZE_SLOT = "pz";
1550
- var CANVAS_TEST_SLOT = "test";
1551
- var CANVAS_DRAFT_STATE = 0;
1552
- var CANVAS_PUBLISHED_STATE = 64;
1553
- var CANVAS_EDITOR_STATE = 63;
1554
- var CANVAS_PERSONALIZATION_PARAM = "$pzCrit";
1555
- var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
1556
- var CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
1557
- var CANVAS_INTERNAL_PARAM_PREFIX = "$internal_";
1558
- var CANVAS_COMPONENT_DISPLAY_NAME_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}displayName`;
1559
- var CANVAS_HYPOTHESIS_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}hypothesis`;
1560
- var CANVAS_CONTEXTUAL_EDITING_PARAM = "$contextualEditing";
1561
- var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1562
- var PLACEHOLDER_ID = "placeholder";
1563
- var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
1564
1662
  function isRootEntryReference(root) {
1565
1663
  return root.type === "root" && isEntryData(root.node);
1566
1664
  }
@@ -2017,20 +2115,28 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
2017
2115
  * When teamId is provided, returns a single team with its projects.
2018
2116
  * When omitted, returns all accessible teams and their projects.
2019
2117
  */
2020
- async getProjects(options) {
2118
+ async list(options) {
2021
2119
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
2022
2120
  return await this.apiClient(fetchUri);
2023
2121
  }
2122
+ /** @deprecated Use {@link list} instead. */
2123
+ async getProjects(options) {
2124
+ return this.list(options);
2125
+ }
2024
2126
  /** Updates or creates (based on id) a Project */
2025
- async upsert(body) {
2127
+ async save(body) {
2026
2128
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
2027
2129
  return await this.apiClient(fetchUri, {
2028
2130
  method: "PUT",
2029
2131
  body: JSON.stringify({ ...body })
2030
2132
  });
2031
2133
  }
2134
+ /** @deprecated Use {@link save} instead. */
2135
+ async upsert(body) {
2136
+ return this.save(body);
2137
+ }
2032
2138
  /** Deletes a Project */
2033
- async delete(body) {
2139
+ async remove(body) {
2034
2140
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
2035
2141
  await this.apiClient(fetchUri, {
2036
2142
  method: "DELETE",
@@ -2038,6 +2144,10 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
2038
2144
  expectNoContent: true
2039
2145
  });
2040
2146
  }
2147
+ /** @deprecated Use {@link remove} instead. */
2148
+ async delete(body) {
2149
+ return this.remove(body);
2150
+ }
2041
2151
  };
2042
2152
  _url22 = /* @__PURE__ */ new WeakMap();
2043
2153
  _projectsUrl = /* @__PURE__ */ new WeakMap();
@@ -2053,8 +2163,14 @@ var RouteClient = class extends ApiClient {
2053
2163
  super(options);
2054
2164
  this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
2055
2165
  }
2056
- /** Fetches lists of Canvas compositions, optionally by type */
2057
- async getRoute(options) {
2166
+ /**
2167
+ * Resolves a route to a composition, redirect, or not-found result.
2168
+ *
2169
+ * An optional `select` projection applies to the resolved composition when
2170
+ * the route matches one; redirect / notFound responses pass through
2171
+ * untouched.
2172
+ */
2173
+ async get(options) {
2058
2174
  const { projectId } = this.options;
2059
2175
  const { select, ...rest } = options != null ? options : {};
2060
2176
  const rewrittenSelect = projectionToQuery(select);
@@ -2064,6 +2180,10 @@ var RouteClient = class extends ApiClient {
2064
2180
  this.options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0
2065
2181
  );
2066
2182
  }
2183
+ /** @deprecated use {@link RouteClient.get} instead (renamed). */
2184
+ async getRoute(options) {
2185
+ return this.get(options);
2186
+ }
2067
2187
  };
2068
2188
  var getDataSourceVariantFromRouteGetParams = (params, defaultPreviewState) => {
2069
2189
  var _a, _b;
@@ -2370,9 +2490,9 @@ function createLimitPolicy2({
2370
2490
  }
2371
2491
 
2372
2492
  // src/clients/canvas.ts
2373
- var getCanvasClient = (options) => {
2493
+ var buildCanvasClientOptions = (options) => {
2374
2494
  const cache2 = resolveCanvasCache(options);
2375
- return new CanvasClient({
2495
+ return {
2376
2496
  projectId: env.getProjectId(),
2377
2497
  apiHost: env.getApiHost(),
2378
2498
  apiKey: env.getApiKey(),
@@ -2420,7 +2540,13 @@ var getCanvasClient = (options) => {
2420
2540
  }
2421
2541
  });
2422
2542
  }
2423
- });
2543
+ };
2544
+ };
2545
+ var getCanvasClient = (options) => {
2546
+ return new CanvasClient(buildCanvasClientOptions(options));
2547
+ };
2548
+ var getCompositionDeliveryClient = (options) => {
2549
+ return new CompositionDeliveryClient(buildCanvasClientOptions(options));
2424
2550
  };
2425
2551
 
2426
2552
  // src/clients/manifest.ts
@@ -3458,14 +3584,14 @@ import React6 from "react";
3458
3584
  import { deserializeEvaluationResult as deserializeEvaluationResult2 } from "@uniformdev/next-app-router-shared";
3459
3585
  var resolvePlaygroundRoute = async ({ code }) => {
3460
3586
  const pageState = deserializeEvaluationResult2({ input: code });
3461
- const canvasClient = getCanvasClient({
3587
+ const canvasClient = getCompositionDeliveryClient({
3462
3588
  cache: {
3463
3589
  type: "no-cache"
3464
3590
  }
3465
3591
  });
3466
3592
  let composition = void 0;
3467
3593
  try {
3468
- composition = await canvasClient.getCompositionById({
3594
+ composition = await canvasClient.get({
3469
3595
  compositionId: pageState.routePath,
3470
3596
  state: pageState.compositionState,
3471
3597
  withComponentIDs: true
@@ -3613,7 +3739,7 @@ var createUniformPlaygroundStaticParams = async (options) => {
3613
3739
  const routeClient = getRouteClient({
3614
3740
  state
3615
3741
  });
3616
- route = await routeClient.getRoute({
3742
+ route = await routeClient.get({
3617
3743
  path: firstPath,
3618
3744
  withComponentIDs: true,
3619
3745
  state: CANVAS_DRAFT_STATE
@@ -3666,7 +3792,7 @@ async function processRoutePath({
3666
3792
  });
3667
3793
  const rewrittenPath = await (rewrite == null ? void 0 : rewrite({ path }));
3668
3794
  const resolvedPath = (_a = rewrittenPath == null ? void 0 : rewrittenPath.path) != null ? _a : path;
3669
- const route = await routeClient.getRoute({
3795
+ const route = await routeClient.get({
3670
3796
  path: resolvedPath,
3671
3797
  withComponentIDs: true,
3672
3798
  state: CANVAS_PUBLISHED_STATE
@@ -3919,14 +4045,14 @@ var DefaultDataClient = class {
3919
4045
  if (oldCachedRoute) {
3920
4046
  waitUntil(
3921
4047
  (async () => {
3922
- const result2 = await routeClient.getRoute(route);
4048
+ const result2 = await routeClient.get(route);
3923
4049
  await cacheNewRoute(result2);
3924
4050
  })()
3925
4051
  );
3926
4052
  return oldCachedRoute;
3927
4053
  }
3928
4054
  }
3929
- const result = await routeClient.getRoute(route);
4055
+ const result = await routeClient.get(route);
3930
4056
  waitUntil(
3931
4057
  (async () => {
3932
4058
  await Promise.all([
@@ -4199,6 +4325,7 @@ export {
4199
4325
  expireMiddlewareCacheTag,
4200
4326
  findRouteMatch,
4201
4327
  getCanvasClient,
4328
+ getCompositionDeliveryClient,
4202
4329
  getManifest,
4203
4330
  getManifestClient,
4204
4331
  getProjectMapClient,