@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.
package/dist/index.js CHANGED
@@ -1225,16 +1225,6 @@ function createLimitPolicy({
1225
1225
  return currentFunc();
1226
1226
  };
1227
1227
  }
1228
- var ContentClientBase = class extends ApiClient {
1229
- constructor(options, defaultBypassCache) {
1230
- var _a, _b;
1231
- super({
1232
- ...options,
1233
- limitPolicy: (_a = options.limitPolicy) != null ? _a : createLimitPolicy({}),
1234
- bypassCache: (_b = options.bypassCache) != null ? _b : defaultBypassCache
1235
- });
1236
- }
1237
- };
1238
1228
  var SELECT_QUERY_PREFIX = "select.";
1239
1229
  function appendCsv(out, key, values) {
1240
1230
  if (values === void 0) {
@@ -1276,102 +1266,130 @@ function projectionToQuery(spec) {
1276
1266
  }
1277
1267
  return out;
1278
1268
  }
1279
- var CANVAS_PERSONALIZE_TYPE = "$personalization";
1280
- var CANVAS_TEST_TYPE = "$test";
1281
- var CANVAS_BLOCK_PARAM_TYPE = "$block";
1282
- var CANVAS_PERSONALIZE_SLOT = "pz";
1283
- var CANVAS_TEST_SLOT = "test";
1284
- var CANVAS_DRAFT_STATE = 0;
1285
- var CANVAS_PUBLISHED_STATE = 64;
1286
- var CANVAS_EDITOR_STATE = 63;
1287
- var CANVAS_PERSONALIZATION_PARAM = "$pzCrit";
1288
- var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
1289
- var CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
1290
- var CANVAS_INTERNAL_PARAM_PREFIX = "$internal_";
1291
- var CANVAS_COMPONENT_DISPLAY_NAME_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}displayName`;
1292
- var CANVAS_HYPOTHESIS_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}hypothesis`;
1293
- var CANVAS_CONTEXTUAL_EDITING_PARAM = "$contextualEditing";
1294
- var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1295
- var PLACEHOLDER_ID = "placeholder";
1296
- var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
1297
- function resolveCompositionSelector(args) {
1298
- if ("compositionId" in args) {
1299
- const { compositionId, editionId, versionId, ...readOptions } = args;
1300
- return {
1301
- readOptions,
1302
- // raw mode matches on composition OR edition id via the compositionId param
1303
- compositionId: editionId != null ? editionId : compositionId,
1304
- versionId,
1305
- hasCompositionId: true,
1306
- pinnedEdition: editionId !== void 0
1307
- };
1308
- }
1309
- return { readOptions: args, hasCompositionId: false, pinnedEdition: false };
1310
- }
1311
- var DEFAULT_EDGE_API_HOST = "https://uniform.global";
1312
- var DeliveryClientBase = class extends ContentClientBase {
1269
+ var CANVAS_URL = "/api/v1/canvas";
1270
+ var CanvasClient = class extends ApiClient {
1313
1271
  constructor(options) {
1314
1272
  var _a;
1315
- super(
1316
- options,
1317
- /* defaultBypassCache */
1318
- false
1319
- );
1320
- this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : DEFAULT_EDGE_API_HOST;
1321
- this.edgeRequestInit = options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0;
1273
+ if (!options.limitPolicy) {
1274
+ options.limitPolicy = createLimitPolicy({});
1275
+ }
1276
+ super(options);
1277
+ this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
1278
+ this.edgeApiRequestInit = options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0;
1279
+ }
1280
+ /** Fetches lists of Canvas compositions, optionally by type */
1281
+ async getCompositionList(params = {}) {
1282
+ const { projectId } = this.options;
1283
+ const { resolveData, filters, select, ...originParams } = params;
1284
+ const rewrittenFilters = rewriteFiltersForApi(filters);
1285
+ const rewrittenSelect = projectionToQuery(select);
1286
+ if (!resolveData) {
1287
+ const fetchUri = this.createUrl(CANVAS_URL, {
1288
+ ...originParams,
1289
+ projectId,
1290
+ ...rewrittenFilters,
1291
+ ...rewrittenSelect
1292
+ });
1293
+ return this.apiClient(fetchUri);
1294
+ }
1295
+ const edgeParams = {
1296
+ ...originParams,
1297
+ projectId,
1298
+ diagnostics: typeof params.diagnostics === "boolean" ? params.diagnostics : params.diagnostics === "no-data" ? "no-data" : void 0,
1299
+ ...rewrittenFilters,
1300
+ ...rewrittenSelect
1301
+ };
1302
+ const edgeUrl = this.createUrl("/api/v1/compositions", edgeParams, this.edgeApiHost);
1303
+ return this.apiClient(edgeUrl, this.edgeApiRequestInit);
1322
1304
  }
1323
- /** Coerces the `diagnostics` option into the shape the edge endpoints accept. */
1324
- coerceDiagnostics(diagnostics) {
1325
- return typeof diagnostics === "boolean" ? diagnostics : diagnostics === "no-data" ? "no-data" : void 0;
1305
+ getCompositionByNodePath(options) {
1306
+ return this.getOneComposition(options);
1326
1307
  }
1327
- };
1328
- var EDGE_SINGLE_URL = "/api/v1/composition";
1329
- var EDGE_LIST_URL = "/api/v1/compositions";
1330
- var CompositionDeliveryClient = class extends DeliveryClientBase {
1331
- constructor(options) {
1332
- super(options);
1308
+ getCompositionByNodeId(options) {
1309
+ return this.getOneComposition(options);
1333
1310
  }
1334
- /** Fetches exactly one composition (throws `ApiClientError(404)` if absent). */
1335
- get(args) {
1336
- var _a;
1337
- const { diagnostics, select, ...rest } = args;
1338
- const { readOptions, compositionId, versionId, pinnedEdition } = resolveCompositionSelector(rest);
1339
- const url = this.createUrl(
1340
- EDGE_SINGLE_URL,
1341
- {
1342
- ...readOptions,
1343
- ...projectionToQuery(select),
1344
- // A pinned edition is folded into compositionId (raw matches edition or
1345
- // composition id); there is no editionId query param on this endpoint.
1346
- compositionId,
1347
- versionId,
1348
- projectId: this.options.projectId,
1349
- state: (_a = args.state) != null ? _a : CANVAS_PUBLISHED_STATE,
1350
- // editionId pins a specific edition for preview; otherwise locale-best.
1351
- editions: pinnedEdition ? "raw" : "auto",
1352
- diagnostics: this.coerceDiagnostics(diagnostics)
1353
- },
1354
- this.edgeApiHost
1355
- );
1356
- return this.apiClient(url, this.edgeRequestInit);
1311
+ getCompositionBySlug(options) {
1312
+ return this.getOneComposition(options);
1357
1313
  }
1358
- /** Fetches a list of compositions, optionally filtered. */
1359
- list(args = {}) {
1360
- var _a;
1361
- const { diagnostics, filters, select, ...rest } = args;
1362
- const url = this.createUrl(
1363
- EDGE_LIST_URL,
1364
- {
1365
- ...rest,
1366
- ...rewriteFiltersForApi(filters),
1367
- ...projectionToQuery(select),
1368
- projectId: this.options.projectId,
1369
- state: (_a = args.state) != null ? _a : CANVAS_PUBLISHED_STATE,
1370
- diagnostics: this.coerceDiagnostics(diagnostics)
1371
- },
1372
- this.edgeApiHost
1373
- );
1374
- return this.apiClient(url, this.edgeRequestInit);
1314
+ getCompositionById(options) {
1315
+ return this.getOneComposition(options);
1316
+ }
1317
+ getCompositionDefaults(options) {
1318
+ return this.getOneComposition(options);
1319
+ }
1320
+ /** Fetches historical versions of a composition or pattern */
1321
+ async getCompositionHistory(options) {
1322
+ const historyUrl = this.createUrl("/api/v1/canvas-history", {
1323
+ ...options,
1324
+ projectId: this.options.projectId
1325
+ });
1326
+ return this.apiClient(historyUrl);
1327
+ }
1328
+ getOneComposition({
1329
+ skipDataResolution,
1330
+ diagnostics,
1331
+ ...params
1332
+ }) {
1333
+ const { projectId } = this.options;
1334
+ if (skipDataResolution) {
1335
+ return this.apiClient(this.createUrl(CANVAS_URL, { ...params, projectId }));
1336
+ }
1337
+ const edgeParams = {
1338
+ ...params,
1339
+ projectId,
1340
+ diagnostics: typeof diagnostics === "boolean" ? diagnostics : diagnostics === "no-data" ? "no-data" : void 0
1341
+ };
1342
+ const edgeUrl = this.createUrl("/api/v1/composition", edgeParams, this.edgeApiHost);
1343
+ return this.apiClient(edgeUrl, this.edgeApiRequestInit);
1344
+ }
1345
+ /** Updates or creates a Canvas component definition */
1346
+ async updateComposition(body, options) {
1347
+ const fetchUri = this.createUrl(CANVAS_URL);
1348
+ const headers = {};
1349
+ if (options == null ? void 0 : options.ifUnmodifiedSince) {
1350
+ headers["x-if-unmodified-since"] = options.ifUnmodifiedSince;
1351
+ }
1352
+ const { response } = await this.apiClientWithResponse(fetchUri, {
1353
+ method: "PUT",
1354
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1355
+ expectNoContent: true,
1356
+ headers
1357
+ });
1358
+ return { modified: response.headers.get("x-modified-at") };
1359
+ }
1360
+ /** Deletes a Canvas component definition */
1361
+ async removeComposition(body) {
1362
+ const fetchUri = this.createUrl(CANVAS_URL);
1363
+ const { projectId } = this.options;
1364
+ await this.apiClient(fetchUri, {
1365
+ method: "DELETE",
1366
+ body: JSON.stringify({ ...body, projectId }),
1367
+ expectNoContent: true
1368
+ });
1369
+ }
1370
+ /** Fetches all Canvas component definitions */
1371
+ async getComponentDefinitions(options) {
1372
+ const { projectId } = this.options;
1373
+ const fetchUri = this.createUrl("/api/v1/canvas-definitions", { ...options, projectId });
1374
+ return this.apiClient(fetchUri);
1375
+ }
1376
+ /** Updates or creates a Canvas component definition */
1377
+ async updateComponentDefinition(body) {
1378
+ const fetchUri = this.createUrl("/api/v1/canvas-definitions");
1379
+ await this.apiClient(fetchUri, {
1380
+ method: "PUT",
1381
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1382
+ expectNoContent: true
1383
+ });
1384
+ }
1385
+ /** Deletes a Canvas component definition */
1386
+ async removeComponentDefinition(body) {
1387
+ const fetchUri = this.createUrl("/api/v1/canvas-definitions");
1388
+ await this.apiClient(fetchUri, {
1389
+ method: "DELETE",
1390
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1391
+ expectNoContent: true
1392
+ });
1375
1393
  }
1376
1394
  };
1377
1395
  var _contentTypesUrl;
@@ -1480,18 +1498,14 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1480
1498
  constructor(options) {
1481
1499
  super(options);
1482
1500
  }
1483
- /** Fetches a list of DataTypes for a project */
1484
- async list(options) {
1501
+ /** Fetches all DataTypes for a project */
1502
+ async get(options) {
1485
1503
  const { projectId } = this.options;
1486
1504
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8), { ...options, projectId });
1487
1505
  return await this.apiClient(fetchUri);
1488
1506
  }
1489
- /** @deprecated Use {@link list} instead. */
1490
- async get(options) {
1491
- return this.list(options);
1492
- }
1493
1507
  /** Updates or creates (based on id) a DataType */
1494
- async save(body) {
1508
+ async upsert(body) {
1495
1509
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
1496
1510
  await this.apiClient(fetchUri, {
1497
1511
  method: "PUT",
@@ -1499,10 +1513,6 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1499
1513
  expectNoContent: true
1500
1514
  });
1501
1515
  }
1502
- /** @deprecated Use {@link save} instead. */
1503
- async upsert(body) {
1504
- return this.save(body);
1505
- }
1506
1516
  /** Deletes a DataType */
1507
1517
  async remove(body) {
1508
1518
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
@@ -1540,6 +1550,24 @@ function getComponentPath(ancestorsAndSelf) {
1540
1550
  }
1541
1551
  return `.${path.join(".")}`;
1542
1552
  }
1553
+ var CANVAS_PERSONALIZE_TYPE = "$personalization";
1554
+ var CANVAS_TEST_TYPE = "$test";
1555
+ var CANVAS_BLOCK_PARAM_TYPE = "$block";
1556
+ var CANVAS_PERSONALIZE_SLOT = "pz";
1557
+ var CANVAS_TEST_SLOT = "test";
1558
+ var CANVAS_DRAFT_STATE = 0;
1559
+ var CANVAS_PUBLISHED_STATE = 64;
1560
+ var CANVAS_EDITOR_STATE = 63;
1561
+ var CANVAS_PERSONALIZATION_PARAM = "$pzCrit";
1562
+ var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
1563
+ var CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
1564
+ var CANVAS_INTERNAL_PARAM_PREFIX = "$internal_";
1565
+ var CANVAS_COMPONENT_DISPLAY_NAME_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}displayName`;
1566
+ var CANVAS_HYPOTHESIS_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}hypothesis`;
1567
+ var CANVAS_CONTEXTUAL_EDITING_PARAM = "$contextualEditing";
1568
+ var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1569
+ var PLACEHOLDER_ID = "placeholder";
1570
+ var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
1543
1571
  function isRootEntryReference(root) {
1544
1572
  return root.type === "root" && isEntryData(root.node);
1545
1573
  }
@@ -1996,28 +2024,20 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
1996
2024
  * When teamId is provided, returns a single team with its projects.
1997
2025
  * When omitted, returns all accessible teams and their projects.
1998
2026
  */
1999
- async list(options) {
2027
+ async getProjects(options) {
2000
2028
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
2001
2029
  return await this.apiClient(fetchUri);
2002
2030
  }
2003
- /** @deprecated Use {@link list} instead. */
2004
- async getProjects(options) {
2005
- return this.list(options);
2006
- }
2007
2031
  /** Updates or creates (based on id) a Project */
2008
- async save(body) {
2032
+ async upsert(body) {
2009
2033
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
2010
2034
  return await this.apiClient(fetchUri, {
2011
2035
  method: "PUT",
2012
2036
  body: JSON.stringify({ ...body })
2013
2037
  });
2014
2038
  }
2015
- /** @deprecated Use {@link save} instead. */
2016
- async upsert(body) {
2017
- return this.save(body);
2018
- }
2019
2039
  /** Deletes a Project */
2020
- async remove(body) {
2040
+ async delete(body) {
2021
2041
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
2022
2042
  await this.apiClient(fetchUri, {
2023
2043
  method: "DELETE",
@@ -2025,10 +2045,6 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
2025
2045
  expectNoContent: true
2026
2046
  });
2027
2047
  }
2028
- /** @deprecated Use {@link remove} instead. */
2029
- async delete(body) {
2030
- return this.remove(body);
2031
- }
2032
2048
  };
2033
2049
  _url22 = /* @__PURE__ */ new WeakMap();
2034
2050
  _projectsUrl = /* @__PURE__ */ new WeakMap();
@@ -2044,14 +2060,8 @@ var RouteClient = class extends ApiClient {
2044
2060
  super(options);
2045
2061
  this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
2046
2062
  }
2047
- /**
2048
- * Resolves a route to a composition, redirect, or not-found result.
2049
- *
2050
- * An optional `select` projection applies to the resolved composition when
2051
- * the route matches one; redirect / notFound responses pass through
2052
- * untouched.
2053
- */
2054
- async get(options) {
2063
+ /** Fetches lists of Canvas compositions, optionally by type */
2064
+ async getRoute(options) {
2055
2065
  const { projectId } = this.options;
2056
2066
  const { select, ...rest } = options != null ? options : {};
2057
2067
  const rewrittenSelect = projectionToQuery(select);
@@ -2061,10 +2071,6 @@ var RouteClient = class extends ApiClient {
2061
2071
  this.options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0
2062
2072
  );
2063
2073
  }
2064
- /** @deprecated use {@link RouteClient.get} instead (renamed). */
2065
- async getRoute(options) {
2066
- return this.get(options);
2067
- }
2068
2074
  };
2069
2075
  function mapSlotToPersonalizedVariations(slot) {
2070
2076
  if (!slot) return [];
@@ -2362,7 +2368,7 @@ function createLimitPolicy2({
2362
2368
  // src/clients/canvas.ts
2363
2369
  var getCanvasClient = (options) => {
2364
2370
  const cache2 = resolveCanvasCache(options);
2365
- return new CompositionDeliveryClient({
2371
+ return new CanvasClient({
2366
2372
  projectId: env.getProjectId(),
2367
2373
  apiHost: env.getApiHost(),
2368
2374
  apiKey: env.getApiKey(),
@@ -3422,7 +3428,7 @@ var resolvePlaygroundRoute = async ({ code }) => {
3422
3428
  });
3423
3429
  let composition = void 0;
3424
3430
  try {
3425
- composition = await canvasClient.get({
3431
+ composition = await canvasClient.getCompositionById({
3426
3432
  compositionId: pageState.routePath,
3427
3433
  state: pageState.compositionState,
3428
3434
  withComponentIDs: true
@@ -3568,7 +3574,7 @@ var createUniformPlaygroundStaticParams = async (options) => {
3568
3574
  const routeClient = getRouteClient({
3569
3575
  state
3570
3576
  });
3571
- route = await routeClient.get({
3577
+ route = await routeClient.getRoute({
3572
3578
  path: firstPath,
3573
3579
  withComponentIDs: true,
3574
3580
  state: CANVAS_DRAFT_STATE
@@ -3621,7 +3627,7 @@ async function processRoutePath({
3621
3627
  });
3622
3628
  const rewrittenPath = await (rewrite == null ? void 0 : rewrite({ path }));
3623
3629
  const resolvedPath = (_a = rewrittenPath == null ? void 0 : rewrittenPath.path) != null ? _a : path;
3624
- const route = await routeClient.get({
3630
+ const route = await routeClient.getRoute({
3625
3631
  path: resolvedPath,
3626
3632
  withComponentIDs: true,
3627
3633
  state: CANVAS_PUBLISHED_STATE
@@ -3874,14 +3880,14 @@ var DefaultDataClient = class {
3874
3880
  if (oldCachedRoute) {
3875
3881
  (0, import_functions.waitUntil)(
3876
3882
  (async () => {
3877
- const result2 = await routeClient.get(route);
3883
+ const result2 = await routeClient.getRoute(route);
3878
3884
  await cacheNewRoute(result2);
3879
3885
  })()
3880
3886
  );
3881
3887
  return oldCachedRoute;
3882
3888
  }
3883
3889
  }
3884
- const result = await routeClient.get(route);
3890
+ const result = await routeClient.getRoute(route);
3885
3891
  (0, import_functions.waitUntil)(
3886
3892
  (async () => {
3887
3893
  await Promise.all([