@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.mjs CHANGED
@@ -1198,16 +1198,6 @@ function createLimitPolicy({
1198
1198
  return currentFunc();
1199
1199
  };
1200
1200
  }
1201
- var ContentClientBase = class extends ApiClient {
1202
- constructor(options, defaultBypassCache) {
1203
- var _a, _b;
1204
- super({
1205
- ...options,
1206
- limitPolicy: (_a = options.limitPolicy) != null ? _a : createLimitPolicy({}),
1207
- bypassCache: (_b = options.bypassCache) != null ? _b : defaultBypassCache
1208
- });
1209
- }
1210
- };
1211
1201
  var SELECT_QUERY_PREFIX = "select.";
1212
1202
  function appendCsv(out, key, values) {
1213
1203
  if (values === void 0) {
@@ -1249,102 +1239,130 @@ function projectionToQuery(spec) {
1249
1239
  }
1250
1240
  return out;
1251
1241
  }
1252
- var CANVAS_PERSONALIZE_TYPE = "$personalization";
1253
- var CANVAS_TEST_TYPE = "$test";
1254
- var CANVAS_BLOCK_PARAM_TYPE = "$block";
1255
- var CANVAS_PERSONALIZE_SLOT = "pz";
1256
- var CANVAS_TEST_SLOT = "test";
1257
- var CANVAS_DRAFT_STATE = 0;
1258
- var CANVAS_PUBLISHED_STATE = 64;
1259
- var CANVAS_EDITOR_STATE = 63;
1260
- var CANVAS_PERSONALIZATION_PARAM = "$pzCrit";
1261
- var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
1262
- var CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
1263
- var CANVAS_INTERNAL_PARAM_PREFIX = "$internal_";
1264
- var CANVAS_COMPONENT_DISPLAY_NAME_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}displayName`;
1265
- var CANVAS_HYPOTHESIS_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}hypothesis`;
1266
- var CANVAS_CONTEXTUAL_EDITING_PARAM = "$contextualEditing";
1267
- var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1268
- var PLACEHOLDER_ID = "placeholder";
1269
- var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
1270
- function resolveCompositionSelector(args) {
1271
- if ("compositionId" in args) {
1272
- const { compositionId, editionId, versionId, ...readOptions } = args;
1273
- return {
1274
- readOptions,
1275
- // raw mode matches on composition OR edition id via the compositionId param
1276
- compositionId: editionId != null ? editionId : compositionId,
1277
- versionId,
1278
- hasCompositionId: true,
1279
- pinnedEdition: editionId !== void 0
1280
- };
1281
- }
1282
- return { readOptions: args, hasCompositionId: false, pinnedEdition: false };
1283
- }
1284
- var DEFAULT_EDGE_API_HOST = "https://uniform.global";
1285
- var DeliveryClientBase = class extends ContentClientBase {
1242
+ var CANVAS_URL = "/api/v1/canvas";
1243
+ var CanvasClient = class extends ApiClient {
1286
1244
  constructor(options) {
1287
1245
  var _a;
1288
- super(
1289
- options,
1290
- /* defaultBypassCache */
1291
- false
1292
- );
1293
- this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : DEFAULT_EDGE_API_HOST;
1294
- this.edgeRequestInit = options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0;
1246
+ if (!options.limitPolicy) {
1247
+ options.limitPolicy = createLimitPolicy({});
1248
+ }
1249
+ super(options);
1250
+ this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
1251
+ this.edgeApiRequestInit = options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0;
1252
+ }
1253
+ /** Fetches lists of Canvas compositions, optionally by type */
1254
+ async getCompositionList(params = {}) {
1255
+ const { projectId } = this.options;
1256
+ const { resolveData, filters, select, ...originParams } = params;
1257
+ const rewrittenFilters = rewriteFiltersForApi(filters);
1258
+ const rewrittenSelect = projectionToQuery(select);
1259
+ if (!resolveData) {
1260
+ const fetchUri = this.createUrl(CANVAS_URL, {
1261
+ ...originParams,
1262
+ projectId,
1263
+ ...rewrittenFilters,
1264
+ ...rewrittenSelect
1265
+ });
1266
+ return this.apiClient(fetchUri);
1267
+ }
1268
+ const edgeParams = {
1269
+ ...originParams,
1270
+ projectId,
1271
+ diagnostics: typeof params.diagnostics === "boolean" ? params.diagnostics : params.diagnostics === "no-data" ? "no-data" : void 0,
1272
+ ...rewrittenFilters,
1273
+ ...rewrittenSelect
1274
+ };
1275
+ const edgeUrl = this.createUrl("/api/v1/compositions", edgeParams, this.edgeApiHost);
1276
+ return this.apiClient(edgeUrl, this.edgeApiRequestInit);
1295
1277
  }
1296
- /** Coerces the `diagnostics` option into the shape the edge endpoints accept. */
1297
- coerceDiagnostics(diagnostics) {
1298
- return typeof diagnostics === "boolean" ? diagnostics : diagnostics === "no-data" ? "no-data" : void 0;
1278
+ getCompositionByNodePath(options) {
1279
+ return this.getOneComposition(options);
1299
1280
  }
1300
- };
1301
- var EDGE_SINGLE_URL = "/api/v1/composition";
1302
- var EDGE_LIST_URL = "/api/v1/compositions";
1303
- var CompositionDeliveryClient = class extends DeliveryClientBase {
1304
- constructor(options) {
1305
- super(options);
1281
+ getCompositionByNodeId(options) {
1282
+ return this.getOneComposition(options);
1306
1283
  }
1307
- /** Fetches exactly one composition (throws `ApiClientError(404)` if absent). */
1308
- get(args) {
1309
- var _a;
1310
- const { diagnostics, select, ...rest } = args;
1311
- const { readOptions, compositionId, versionId, pinnedEdition } = resolveCompositionSelector(rest);
1312
- const url = this.createUrl(
1313
- EDGE_SINGLE_URL,
1314
- {
1315
- ...readOptions,
1316
- ...projectionToQuery(select),
1317
- // A pinned edition is folded into compositionId (raw matches edition or
1318
- // composition id); there is no editionId query param on this endpoint.
1319
- compositionId,
1320
- versionId,
1321
- projectId: this.options.projectId,
1322
- state: (_a = args.state) != null ? _a : CANVAS_PUBLISHED_STATE,
1323
- // editionId pins a specific edition for preview; otherwise locale-best.
1324
- editions: pinnedEdition ? "raw" : "auto",
1325
- diagnostics: this.coerceDiagnostics(diagnostics)
1326
- },
1327
- this.edgeApiHost
1328
- );
1329
- return this.apiClient(url, this.edgeRequestInit);
1284
+ getCompositionBySlug(options) {
1285
+ return this.getOneComposition(options);
1330
1286
  }
1331
- /** Fetches a list of compositions, optionally filtered. */
1332
- list(args = {}) {
1333
- var _a;
1334
- const { diagnostics, filters, select, ...rest } = args;
1335
- const url = this.createUrl(
1336
- EDGE_LIST_URL,
1337
- {
1338
- ...rest,
1339
- ...rewriteFiltersForApi(filters),
1340
- ...projectionToQuery(select),
1341
- projectId: this.options.projectId,
1342
- state: (_a = args.state) != null ? _a : CANVAS_PUBLISHED_STATE,
1343
- diagnostics: this.coerceDiagnostics(diagnostics)
1344
- },
1345
- this.edgeApiHost
1346
- );
1347
- return this.apiClient(url, this.edgeRequestInit);
1287
+ getCompositionById(options) {
1288
+ return this.getOneComposition(options);
1289
+ }
1290
+ getCompositionDefaults(options) {
1291
+ return this.getOneComposition(options);
1292
+ }
1293
+ /** Fetches historical versions of a composition or pattern */
1294
+ async getCompositionHistory(options) {
1295
+ const historyUrl = this.createUrl("/api/v1/canvas-history", {
1296
+ ...options,
1297
+ projectId: this.options.projectId
1298
+ });
1299
+ return this.apiClient(historyUrl);
1300
+ }
1301
+ getOneComposition({
1302
+ skipDataResolution,
1303
+ diagnostics,
1304
+ ...params
1305
+ }) {
1306
+ const { projectId } = this.options;
1307
+ if (skipDataResolution) {
1308
+ return this.apiClient(this.createUrl(CANVAS_URL, { ...params, projectId }));
1309
+ }
1310
+ const edgeParams = {
1311
+ ...params,
1312
+ projectId,
1313
+ diagnostics: typeof diagnostics === "boolean" ? diagnostics : diagnostics === "no-data" ? "no-data" : void 0
1314
+ };
1315
+ const edgeUrl = this.createUrl("/api/v1/composition", edgeParams, this.edgeApiHost);
1316
+ return this.apiClient(edgeUrl, this.edgeApiRequestInit);
1317
+ }
1318
+ /** Updates or creates a Canvas component definition */
1319
+ async updateComposition(body, options) {
1320
+ const fetchUri = this.createUrl(CANVAS_URL);
1321
+ const headers = {};
1322
+ if (options == null ? void 0 : options.ifUnmodifiedSince) {
1323
+ headers["x-if-unmodified-since"] = options.ifUnmodifiedSince;
1324
+ }
1325
+ const { response } = await this.apiClientWithResponse(fetchUri, {
1326
+ method: "PUT",
1327
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1328
+ expectNoContent: true,
1329
+ headers
1330
+ });
1331
+ return { modified: response.headers.get("x-modified-at") };
1332
+ }
1333
+ /** Deletes a Canvas component definition */
1334
+ async removeComposition(body) {
1335
+ const fetchUri = this.createUrl(CANVAS_URL);
1336
+ const { projectId } = this.options;
1337
+ await this.apiClient(fetchUri, {
1338
+ method: "DELETE",
1339
+ body: JSON.stringify({ ...body, projectId }),
1340
+ expectNoContent: true
1341
+ });
1342
+ }
1343
+ /** Fetches all Canvas component definitions */
1344
+ async getComponentDefinitions(options) {
1345
+ const { projectId } = this.options;
1346
+ const fetchUri = this.createUrl("/api/v1/canvas-definitions", { ...options, projectId });
1347
+ return this.apiClient(fetchUri);
1348
+ }
1349
+ /** Updates or creates a Canvas component definition */
1350
+ async updateComponentDefinition(body) {
1351
+ const fetchUri = this.createUrl("/api/v1/canvas-definitions");
1352
+ await this.apiClient(fetchUri, {
1353
+ method: "PUT",
1354
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1355
+ expectNoContent: true
1356
+ });
1357
+ }
1358
+ /** Deletes a Canvas component definition */
1359
+ async removeComponentDefinition(body) {
1360
+ const fetchUri = this.createUrl("/api/v1/canvas-definitions");
1361
+ await this.apiClient(fetchUri, {
1362
+ method: "DELETE",
1363
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1364
+ expectNoContent: true
1365
+ });
1348
1366
  }
1349
1367
  };
1350
1368
  var _contentTypesUrl;
@@ -1453,18 +1471,14 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1453
1471
  constructor(options) {
1454
1472
  super(options);
1455
1473
  }
1456
- /** Fetches a list of DataTypes for a project */
1457
- async list(options) {
1474
+ /** Fetches all DataTypes for a project */
1475
+ async get(options) {
1458
1476
  const { projectId } = this.options;
1459
1477
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8), { ...options, projectId });
1460
1478
  return await this.apiClient(fetchUri);
1461
1479
  }
1462
- /** @deprecated Use {@link list} instead. */
1463
- async get(options) {
1464
- return this.list(options);
1465
- }
1466
1480
  /** Updates or creates (based on id) a DataType */
1467
- async save(body) {
1481
+ async upsert(body) {
1468
1482
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
1469
1483
  await this.apiClient(fetchUri, {
1470
1484
  method: "PUT",
@@ -1472,10 +1486,6 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1472
1486
  expectNoContent: true
1473
1487
  });
1474
1488
  }
1475
- /** @deprecated Use {@link save} instead. */
1476
- async upsert(body) {
1477
- return this.save(body);
1478
- }
1479
1489
  /** Deletes a DataType */
1480
1490
  async remove(body) {
1481
1491
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
@@ -1513,6 +1523,24 @@ function getComponentPath(ancestorsAndSelf) {
1513
1523
  }
1514
1524
  return `.${path.join(".")}`;
1515
1525
  }
1526
+ var CANVAS_PERSONALIZE_TYPE = "$personalization";
1527
+ var CANVAS_TEST_TYPE = "$test";
1528
+ var CANVAS_BLOCK_PARAM_TYPE = "$block";
1529
+ var CANVAS_PERSONALIZE_SLOT = "pz";
1530
+ var CANVAS_TEST_SLOT = "test";
1531
+ var CANVAS_DRAFT_STATE = 0;
1532
+ var CANVAS_PUBLISHED_STATE = 64;
1533
+ var CANVAS_EDITOR_STATE = 63;
1534
+ var CANVAS_PERSONALIZATION_PARAM = "$pzCrit";
1535
+ var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
1536
+ var CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
1537
+ var CANVAS_INTERNAL_PARAM_PREFIX = "$internal_";
1538
+ var CANVAS_COMPONENT_DISPLAY_NAME_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}displayName`;
1539
+ var CANVAS_HYPOTHESIS_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}hypothesis`;
1540
+ var CANVAS_CONTEXTUAL_EDITING_PARAM = "$contextualEditing";
1541
+ var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1542
+ var PLACEHOLDER_ID = "placeholder";
1543
+ var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
1516
1544
  function isRootEntryReference(root) {
1517
1545
  return root.type === "root" && isEntryData(root.node);
1518
1546
  }
@@ -1969,28 +1997,20 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
1969
1997
  * When teamId is provided, returns a single team with its projects.
1970
1998
  * When omitted, returns all accessible teams and their projects.
1971
1999
  */
1972
- async list(options) {
2000
+ async getProjects(options) {
1973
2001
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
1974
2002
  return await this.apiClient(fetchUri);
1975
2003
  }
1976
- /** @deprecated Use {@link list} instead. */
1977
- async getProjects(options) {
1978
- return this.list(options);
1979
- }
1980
2004
  /** Updates or creates (based on id) a Project */
1981
- async save(body) {
2005
+ async upsert(body) {
1982
2006
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
1983
2007
  return await this.apiClient(fetchUri, {
1984
2008
  method: "PUT",
1985
2009
  body: JSON.stringify({ ...body })
1986
2010
  });
1987
2011
  }
1988
- /** @deprecated Use {@link save} instead. */
1989
- async upsert(body) {
1990
- return this.save(body);
1991
- }
1992
2012
  /** Deletes a Project */
1993
- async remove(body) {
2013
+ async delete(body) {
1994
2014
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
1995
2015
  await this.apiClient(fetchUri, {
1996
2016
  method: "DELETE",
@@ -1998,10 +2018,6 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
1998
2018
  expectNoContent: true
1999
2019
  });
2000
2020
  }
2001
- /** @deprecated Use {@link remove} instead. */
2002
- async delete(body) {
2003
- return this.remove(body);
2004
- }
2005
2021
  };
2006
2022
  _url22 = /* @__PURE__ */ new WeakMap();
2007
2023
  _projectsUrl = /* @__PURE__ */ new WeakMap();
@@ -2017,14 +2033,8 @@ var RouteClient = class extends ApiClient {
2017
2033
  super(options);
2018
2034
  this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
2019
2035
  }
2020
- /**
2021
- * Resolves a route to a composition, redirect, or not-found result.
2022
- *
2023
- * An optional `select` projection applies to the resolved composition when
2024
- * the route matches one; redirect / notFound responses pass through
2025
- * untouched.
2026
- */
2027
- async get(options) {
2036
+ /** Fetches lists of Canvas compositions, optionally by type */
2037
+ async getRoute(options) {
2028
2038
  const { projectId } = this.options;
2029
2039
  const { select, ...rest } = options != null ? options : {};
2030
2040
  const rewrittenSelect = projectionToQuery(select);
@@ -2034,10 +2044,6 @@ var RouteClient = class extends ApiClient {
2034
2044
  this.options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0
2035
2045
  );
2036
2046
  }
2037
- /** @deprecated use {@link RouteClient.get} instead (renamed). */
2038
- async getRoute(options) {
2039
- return this.get(options);
2040
- }
2041
2047
  };
2042
2048
  function mapSlotToPersonalizedVariations(slot) {
2043
2049
  if (!slot) return [];
@@ -2335,7 +2341,7 @@ function createLimitPolicy2({
2335
2341
  // src/clients/canvas.ts
2336
2342
  var getCanvasClient = (options) => {
2337
2343
  const cache2 = resolveCanvasCache(options);
2338
- return new CompositionDeliveryClient({
2344
+ return new CanvasClient({
2339
2345
  projectId: env.getProjectId(),
2340
2346
  apiHost: env.getApiHost(),
2341
2347
  apiKey: env.getApiKey(),
@@ -3399,7 +3405,7 @@ var resolvePlaygroundRoute = async ({ code }) => {
3399
3405
  });
3400
3406
  let composition = void 0;
3401
3407
  try {
3402
- composition = await canvasClient.get({
3408
+ composition = await canvasClient.getCompositionById({
3403
3409
  compositionId: pageState.routePath,
3404
3410
  state: pageState.compositionState,
3405
3411
  withComponentIDs: true
@@ -3547,7 +3553,7 @@ var createUniformPlaygroundStaticParams = async (options) => {
3547
3553
  const routeClient = getRouteClient({
3548
3554
  state
3549
3555
  });
3550
- route = await routeClient.get({
3556
+ route = await routeClient.getRoute({
3551
3557
  path: firstPath,
3552
3558
  withComponentIDs: true,
3553
3559
  state: CANVAS_DRAFT_STATE
@@ -3600,7 +3606,7 @@ async function processRoutePath({
3600
3606
  });
3601
3607
  const rewrittenPath = await (rewrite == null ? void 0 : rewrite({ path }));
3602
3608
  const resolvedPath = (_a = rewrittenPath == null ? void 0 : rewrittenPath.path) != null ? _a : path;
3603
- const route = await routeClient.get({
3609
+ const route = await routeClient.getRoute({
3604
3610
  path: resolvedPath,
3605
3611
  withComponentIDs: true,
3606
3612
  state: CANVAS_PUBLISHED_STATE
@@ -3853,14 +3859,14 @@ var DefaultDataClient = class {
3853
3859
  if (oldCachedRoute) {
3854
3860
  waitUntil(
3855
3861
  (async () => {
3856
- const result2 = await routeClient.get(route);
3862
+ const result2 = await routeClient.getRoute(route);
3857
3863
  await cacheNewRoute(result2);
3858
3864
  })()
3859
3865
  );
3860
3866
  return oldCachedRoute;
3861
3867
  }
3862
3868
  }
3863
- const result = await routeClient.get(route);
3869
+ const result = await routeClient.getRoute(route);
3864
3870
  waitUntil(
3865
3871
  (async () => {
3866
3872
  await Promise.all([