@uniformdev/next-app-router 20.72.3-alpha.2 → 20.72.3-alpha.23

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/handler.mjs CHANGED
@@ -402,6 +402,7 @@ var __accessCheck2 = (obj, member, msg) => member.has(obj) || __typeError2("Cann
402
402
  var __privateGet2 = (obj, member, getter) => (__accessCheck2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
403
403
  var __privateAdd2 = (obj, member, value) => member.has(obj) ? __typeError2("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
404
404
  var defaultLimitPolicy = (0, import_p_limit.default)(6);
405
+ var UNIFORM_BEARER_TOKEN_NOT_VALID_OR_EXPIRED_MESSAGE = "Bearer token not valid or expired";
405
406
  var ApiClientError = class _ApiClientError extends Error {
406
407
  constructor(errorMessage, fetchMethod, fetchUri, statusCode, statusText, requestId) {
407
408
  super(
@@ -417,6 +418,12 @@ var ApiClientError = class _ApiClientError extends Error {
417
418
  Object.setPrototypeOf(this, _ApiClientError.prototype);
418
419
  }
419
420
  };
421
+ var BearerTokenNotValidOrExpiredError = class _BearerTokenNotValidOrExpiredError extends ApiClientError {
422
+ constructor(errorMessage, fetchMethod, fetchUri, statusCode, statusText, requestId) {
423
+ super(errorMessage, fetchMethod, fetchUri, statusCode, statusText, requestId);
424
+ Object.setPrototypeOf(this, _BearerTokenNotValidOrExpiredError.prototype);
425
+ }
426
+ };
420
427
  var ApiClient = class _ApiClient {
421
428
  constructor(options) {
422
429
  __publicField2(this, "options");
@@ -450,7 +457,7 @@ var ApiClient = class _ApiClient {
450
457
  }
451
458
  async apiClientWithResponse(fetchUri, options) {
452
459
  return this.options.limitPolicy(async () => {
453
- var _a;
460
+ var _a, _b;
454
461
  const coreHeaders = this.options.apiKey ? {
455
462
  "x-api-key": this.options.apiKey
456
463
  } : {
@@ -486,9 +493,19 @@ var ApiClient = class _ApiClient {
486
493
  } catch (e) {
487
494
  message = `General error`;
488
495
  }
496
+ if (apiResponse.status === 401 && message === UNIFORM_BEARER_TOKEN_NOT_VALID_OR_EXPIRED_MESSAGE) {
497
+ throw new BearerTokenNotValidOrExpiredError(
498
+ message,
499
+ (_a = options == null ? void 0 : options.method) != null ? _a : "GET",
500
+ fetchUri.toString(),
501
+ apiResponse.status,
502
+ apiResponse.statusText,
503
+ _ApiClient.getRequestId(apiResponse)
504
+ );
505
+ }
489
506
  throw new ApiClientError(
490
507
  message,
491
- (_a = options == null ? void 0 : options.method) != null ? _a : "GET",
508
+ (_b = options == null ? void 0 : options.method) != null ? _b : "GET",
492
509
  fetchUri.toString(),
493
510
  apiResponse.status,
494
511
  apiResponse.statusText,
@@ -1191,6 +1208,16 @@ function createLimitPolicy({
1191
1208
  return currentFunc();
1192
1209
  };
1193
1210
  }
1211
+ var ContentClientBase = class extends ApiClient {
1212
+ constructor(options, defaultBypassCache) {
1213
+ var _a, _b;
1214
+ super({
1215
+ ...options,
1216
+ limitPolicy: (_a = options.limitPolicy) != null ? _a : createLimitPolicy({}),
1217
+ bypassCache: (_b = options.bypassCache) != null ? _b : defaultBypassCache
1218
+ });
1219
+ }
1220
+ };
1194
1221
  var SELECT_QUERY_PREFIX = "select.";
1195
1222
  function appendCsv(out, key, values) {
1196
1223
  if (values === void 0) {
@@ -1235,130 +1262,94 @@ function projectionToQuery(spec) {
1235
1262
  }
1236
1263
  return out;
1237
1264
  }
1238
- var CANVAS_URL = "/api/v1/canvas";
1239
- var CanvasClient = class extends ApiClient {
1240
- constructor(options) {
1241
- var _a;
1242
- if (!options.limitPolicy) {
1243
- options.limitPolicy = createLimitPolicy({});
1244
- }
1245
- super(options);
1246
- this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
1247
- this.edgeApiRequestInit = options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0;
1248
- }
1249
- /** Fetches lists of Canvas compositions, optionally by type */
1250
- async getCompositionList(params = {}) {
1251
- const { projectId } = this.options;
1252
- const { resolveData, filters, select, ...originParams } = params;
1253
- const rewrittenFilters = rewriteFiltersForApi(filters);
1254
- const rewrittenSelect = projectionToQuery(select);
1255
- if (!resolveData) {
1256
- const fetchUri = this.createUrl(CANVAS_URL, {
1257
- ...originParams,
1258
- projectId,
1259
- ...rewrittenFilters,
1260
- ...rewrittenSelect
1261
- });
1262
- return this.apiClient(fetchUri);
1263
- }
1264
- const edgeParams = {
1265
- ...originParams,
1266
- projectId,
1267
- diagnostics: typeof params.diagnostics === "boolean" ? params.diagnostics : params.diagnostics === "no-data" ? "no-data" : void 0,
1268
- ...rewrittenFilters,
1269
- ...rewrittenSelect
1270
- };
1271
- const edgeUrl = this.createUrl("/api/v1/compositions", edgeParams, this.edgeApiHost);
1272
- return this.apiClient(edgeUrl, this.edgeApiRequestInit);
1273
- }
1274
- getCompositionByNodePath(options) {
1275
- return this.getOneComposition(options);
1276
- }
1277
- getCompositionByNodeId(options) {
1278
- return this.getOneComposition(options);
1279
- }
1280
- getCompositionBySlug(options) {
1281
- return this.getOneComposition(options);
1282
- }
1283
- getCompositionById(options) {
1284
- return this.getOneComposition(options);
1285
- }
1286
- getCompositionDefaults(options) {
1287
- return this.getOneComposition(options);
1288
- }
1289
- /** Fetches historical versions of a composition or pattern */
1290
- async getCompositionHistory(options) {
1291
- const historyUrl = this.createUrl("/api/v1/canvas-history", {
1292
- ...options,
1293
- projectId: this.options.projectId
1294
- });
1295
- return this.apiClient(historyUrl);
1296
- }
1297
- getOneComposition({
1298
- skipDataResolution,
1299
- diagnostics,
1300
- ...params
1301
- }) {
1302
- const { projectId } = this.options;
1303
- if (skipDataResolution) {
1304
- return this.apiClient(this.createUrl(CANVAS_URL, { ...params, projectId }));
1305
- }
1306
- const edgeParams = {
1307
- ...params,
1308
- projectId,
1309
- diagnostics: typeof diagnostics === "boolean" ? diagnostics : diagnostics === "no-data" ? "no-data" : void 0
1265
+ var CANVAS_DRAFT_STATE = 0;
1266
+ var CANVAS_PUBLISHED_STATE = 64;
1267
+ var CANVAS_EDITOR_STATE = 63;
1268
+ var CANVAS_INTERNAL_PARAM_PREFIX = "$internal_";
1269
+ var CANVAS_COMPONENT_DISPLAY_NAME_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}displayName`;
1270
+ var CANVAS_HYPOTHESIS_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}hypothesis`;
1271
+ var SECRET_QUERY_STRING_PARAM = "secret";
1272
+ var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1273
+ var IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM = "is_incontext_editing_playground";
1274
+ var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
1275
+ function resolveCompositionSelector(args) {
1276
+ if ("compositionId" in args) {
1277
+ const { compositionId, editionId, versionId, ...readOptions } = args;
1278
+ return {
1279
+ readOptions,
1280
+ // raw mode matches on composition OR edition id via the compositionId param
1281
+ compositionId: editionId != null ? editionId : compositionId,
1282
+ versionId,
1283
+ hasCompositionId: true,
1284
+ pinnedEdition: editionId !== void 0
1310
1285
  };
1311
- const edgeUrl = this.createUrl("/api/v1/composition", edgeParams, this.edgeApiHost);
1312
- return this.apiClient(edgeUrl, this.edgeApiRequestInit);
1313
1286
  }
1314
- /** Updates or creates a Canvas component definition */
1315
- async updateComposition(body, options) {
1316
- const fetchUri = this.createUrl(CANVAS_URL);
1317
- const headers = {};
1318
- if (options == null ? void 0 : options.ifUnmodifiedSince) {
1319
- headers["x-if-unmodified-since"] = options.ifUnmodifiedSince;
1320
- }
1321
- const { response } = await this.apiClientWithResponse(fetchUri, {
1322
- method: "PUT",
1323
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1324
- expectNoContent: true,
1325
- headers
1326
- });
1327
- return { modified: response.headers.get("x-modified-at") };
1287
+ return { readOptions: args, hasCompositionId: false, pinnedEdition: false };
1288
+ }
1289
+ var DEFAULT_EDGE_API_HOST = "https://uniform.global";
1290
+ var DeliveryClientBase = class extends ContentClientBase {
1291
+ constructor(options) {
1292
+ var _a;
1293
+ super(
1294
+ options,
1295
+ /* defaultBypassCache */
1296
+ false
1297
+ );
1298
+ this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : DEFAULT_EDGE_API_HOST;
1299
+ this.edgeRequestInit = options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0;
1328
1300
  }
1329
- /** Deletes a Canvas component definition */
1330
- async removeComposition(body) {
1331
- const fetchUri = this.createUrl(CANVAS_URL);
1332
- const { projectId } = this.options;
1333
- await this.apiClient(fetchUri, {
1334
- method: "DELETE",
1335
- body: JSON.stringify({ ...body, projectId }),
1336
- expectNoContent: true
1337
- });
1301
+ /** Coerces the `diagnostics` option into the shape the edge endpoints accept. */
1302
+ coerceDiagnostics(diagnostics) {
1303
+ return typeof diagnostics === "boolean" ? diagnostics : diagnostics === "no-data" ? "no-data" : void 0;
1338
1304
  }
1339
- /** Fetches all Canvas component definitions */
1340
- async getComponentDefinitions(options) {
1341
- const { projectId } = this.options;
1342
- const fetchUri = this.createUrl("/api/v1/canvas-definitions", { ...options, projectId });
1343
- return this.apiClient(fetchUri);
1305
+ };
1306
+ var EDGE_SINGLE_URL = "/api/v1/composition";
1307
+ var EDGE_LIST_URL = "/api/v1/compositions";
1308
+ var CompositionDeliveryClient = class extends DeliveryClientBase {
1309
+ constructor(options) {
1310
+ super(options);
1344
1311
  }
1345
- /** Updates or creates a Canvas component definition */
1346
- async updateComponentDefinition(body) {
1347
- const fetchUri = this.createUrl("/api/v1/canvas-definitions");
1348
- await this.apiClient(fetchUri, {
1349
- method: "PUT",
1350
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1351
- expectNoContent: true
1352
- });
1312
+ /** Fetches exactly one composition (throws `ApiClientError(404)` if absent). */
1313
+ get(args) {
1314
+ var _a;
1315
+ const { diagnostics, select, ...rest } = args;
1316
+ const { readOptions, compositionId, versionId, pinnedEdition } = resolveCompositionSelector(rest);
1317
+ const url = this.createUrl(
1318
+ EDGE_SINGLE_URL,
1319
+ {
1320
+ ...readOptions,
1321
+ ...projectionToQuery(select),
1322
+ // A pinned edition is folded into compositionId (raw matches edition or
1323
+ // composition id); there is no editionId query param on this endpoint.
1324
+ compositionId,
1325
+ versionId,
1326
+ projectId: this.options.projectId,
1327
+ state: (_a = args.state) != null ? _a : CANVAS_PUBLISHED_STATE,
1328
+ // editionId pins a specific edition for preview; otherwise locale-best.
1329
+ editions: pinnedEdition ? "raw" : "auto",
1330
+ diagnostics: this.coerceDiagnostics(diagnostics)
1331
+ },
1332
+ this.edgeApiHost
1333
+ );
1334
+ return this.apiClient(url, this.edgeRequestInit);
1353
1335
  }
1354
- /** Deletes a Canvas component definition */
1355
- async removeComponentDefinition(body) {
1356
- const fetchUri = this.createUrl("/api/v1/canvas-definitions");
1357
- await this.apiClient(fetchUri, {
1358
- method: "DELETE",
1359
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1360
- expectNoContent: true
1361
- });
1336
+ /** Fetches a list of compositions, optionally filtered. */
1337
+ list(args = {}) {
1338
+ var _a;
1339
+ const { diagnostics, filters, select, ...rest } = args;
1340
+ const url = this.createUrl(
1341
+ EDGE_LIST_URL,
1342
+ {
1343
+ ...rest,
1344
+ ...rewriteFiltersForApi(filters),
1345
+ ...projectionToQuery(select),
1346
+ projectId: this.options.projectId,
1347
+ state: (_a = args.state) != null ? _a : CANVAS_PUBLISHED_STATE,
1348
+ diagnostics: this.coerceDiagnostics(diagnostics)
1349
+ },
1350
+ this.edgeApiHost
1351
+ );
1352
+ return this.apiClient(url, this.edgeRequestInit);
1362
1353
  }
1363
1354
  };
1364
1355
  var _contentTypesUrl;
@@ -1467,14 +1458,18 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1467
1458
  constructor(options) {
1468
1459
  super(options);
1469
1460
  }
1470
- /** Fetches all DataTypes for a project */
1471
- async get(options) {
1461
+ /** Fetches a list of DataTypes for a project */
1462
+ async list(options) {
1472
1463
  const { projectId } = this.options;
1473
1464
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8), { ...options, projectId });
1474
1465
  return await this.apiClient(fetchUri);
1475
1466
  }
1467
+ /** @deprecated Use {@link list} instead. */
1468
+ async get(options) {
1469
+ return this.list(options);
1470
+ }
1476
1471
  /** Updates or creates (based on id) a DataType */
1477
- async upsert(body) {
1472
+ async save(body) {
1478
1473
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
1479
1474
  await this.apiClient(fetchUri, {
1480
1475
  method: "PUT",
@@ -1482,6 +1477,10 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1482
1477
  expectNoContent: true
1483
1478
  });
1484
1479
  }
1480
+ /** @deprecated Use {@link save} instead. */
1481
+ async upsert(body) {
1482
+ return this.save(body);
1483
+ }
1485
1484
  /** Deletes a DataType */
1486
1485
  async remove(body) {
1487
1486
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
@@ -1494,15 +1493,6 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1494
1493
  };
1495
1494
  _url8 = /* @__PURE__ */ new WeakMap();
1496
1495
  __privateAdd3(_DataTypeClient, _url8, "/api/v1/data-types");
1497
- var CANVAS_DRAFT_STATE = 0;
1498
- var CANVAS_EDITOR_STATE = 63;
1499
- var CANVAS_INTERNAL_PARAM_PREFIX = "$internal_";
1500
- var CANVAS_COMPONENT_DISPLAY_NAME_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}displayName`;
1501
- var CANVAS_HYPOTHESIS_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}hypothesis`;
1502
- var SECRET_QUERY_STRING_PARAM = "secret";
1503
- var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1504
- var IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM = "is_incontext_editing_playground";
1505
- var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
1506
1496
  var escapeCharacter = "\\";
1507
1497
  var variablePrefix = "${";
1508
1498
  var variableSuffix = "}";
@@ -1513,9 +1503,9 @@ function parseVariableExpression(serialized, onToken) {
1513
1503
  let bufferStartIndex = 0;
1514
1504
  let bufferEndIndex = 0;
1515
1505
  let tokenCount = 0;
1516
- const handleToken = (token, type) => {
1506
+ const handleToken = (token, type, offset) => {
1517
1507
  tokenCount++;
1518
- return onToken == null ? void 0 : onToken(token, type);
1508
+ return onToken == null ? void 0 : onToken(token, type, offset);
1519
1509
  };
1520
1510
  let state = "text";
1521
1511
  for (let index = 0; index < serialized.length; index++) {
@@ -1526,7 +1516,7 @@ function parseVariableExpression(serialized, onToken) {
1526
1516
  if (char === variablePrefix[0] && serialized[index + 1] === variablePrefix[1]) {
1527
1517
  if (serialized[index - 1] === escapeCharacter) {
1528
1518
  bufferEndIndex -= escapeCharacter.length;
1529
- if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text") === false) {
1519
+ if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text", bufferStartIndex) === false) {
1530
1520
  return tokenCount;
1531
1521
  }
1532
1522
  bufferStartIndex = index;
@@ -1535,12 +1525,12 @@ function parseVariableExpression(serialized, onToken) {
1535
1525
  }
1536
1526
  if (state === "variable") {
1537
1527
  const textStart = bufferStartIndex - variablePrefix.length;
1538
- if (handleToken(serialized.substring(textStart, bufferEndIndex), "text") === false) {
1528
+ if (handleToken(serialized.substring(textStart, bufferEndIndex), "text", textStart) === false) {
1539
1529
  return tokenCount;
1540
1530
  }
1541
1531
  bufferStartIndex = bufferEndIndex;
1542
1532
  } else if (bufferEndIndex > bufferStartIndex) {
1543
- if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text") === false) {
1533
+ if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text", bufferStartIndex) === false) {
1544
1534
  return tokenCount;
1545
1535
  }
1546
1536
  bufferStartIndex = bufferEndIndex;
@@ -1558,7 +1548,7 @@ function parseVariableExpression(serialized, onToken) {
1558
1548
  state = "text";
1559
1549
  if (bufferEndIndex > bufferStartIndex) {
1560
1550
  const unescapedVariableName = serialized.substring(bufferStartIndex, bufferEndIndex).replace(/\\([${}])/g, "$1");
1561
- if (handleToken(unescapedVariableName, "variable") === false) {
1551
+ if (handleToken(unescapedVariableName, "variable", bufferStartIndex) === false) {
1562
1552
  return tokenCount;
1563
1553
  }
1564
1554
  bufferStartIndex = bufferEndIndex + variableSuffix.length;
@@ -1572,7 +1562,7 @@ function parseVariableExpression(serialized, onToken) {
1572
1562
  bufferStartIndex -= variablePrefix.length;
1573
1563
  }
1574
1564
  if (bufferStartIndex < serialized.length) {
1575
- handleToken(serialized.substring(bufferStartIndex), state);
1565
+ handleToken(serialized.substring(bufferStartIndex), state, bufferStartIndex);
1576
1566
  }
1577
1567
  return tokenCount;
1578
1568
  }
@@ -1636,20 +1626,28 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
1636
1626
  * When teamId is provided, returns a single team with its projects.
1637
1627
  * When omitted, returns all accessible teams and their projects.
1638
1628
  */
1639
- async getProjects(options) {
1629
+ async list(options) {
1640
1630
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
1641
1631
  return await this.apiClient(fetchUri);
1642
1632
  }
1633
+ /** @deprecated Use {@link list} instead. */
1634
+ async getProjects(options) {
1635
+ return this.list(options);
1636
+ }
1643
1637
  /** Updates or creates (based on id) a Project */
1644
- async upsert(body) {
1638
+ async save(body) {
1645
1639
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
1646
1640
  return await this.apiClient(fetchUri, {
1647
1641
  method: "PUT",
1648
1642
  body: JSON.stringify({ ...body })
1649
1643
  });
1650
1644
  }
1645
+ /** @deprecated Use {@link save} instead. */
1646
+ async upsert(body) {
1647
+ return this.save(body);
1648
+ }
1651
1649
  /** Deletes a Project */
1652
- async delete(body) {
1650
+ async remove(body) {
1653
1651
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
1654
1652
  await this.apiClient(fetchUri, {
1655
1653
  method: "DELETE",
@@ -1657,13 +1655,19 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
1657
1655
  expectNoContent: true
1658
1656
  });
1659
1657
  }
1658
+ /** @deprecated Use {@link remove} instead. */
1659
+ async delete(body) {
1660
+ return this.remove(body);
1661
+ }
1660
1662
  };
1661
1663
  _url22 = /* @__PURE__ */ new WeakMap();
1662
1664
  _projectsUrl = /* @__PURE__ */ new WeakMap();
1663
1665
  __privateAdd3(_ProjectClient, _url22, "/api/v1/project");
1664
1666
  __privateAdd3(_ProjectClient, _projectsUrl, "/api/v1/projects");
1665
1667
  var isAllowedReferrer = (referrer) => {
1666
- return Boolean(referrer == null ? void 0 : referrer.match(/(^https:\/\/|\.)(uniform.app|uniform.wtf|localhost:\d{4})\//));
1668
+ return Boolean(
1669
+ referrer == null ? void 0 : referrer.match(/(^https:\/\/|\.)(uniform.app|uniform.wtf|uniformcode.ai|localhost:\d{4})\//)
1670
+ );
1667
1671
  };
1668
1672
 
1669
1673
  // src/handler/createPreviewGETRouteHandler.ts
@@ -2115,9 +2119,9 @@ function createLimitPolicy2({
2115
2119
  }
2116
2120
 
2117
2121
  // src/clients/canvas.ts
2118
- var getCanvasClient = (options) => {
2122
+ var buildCanvasClientOptions = (options) => {
2119
2123
  const cache = resolveCanvasCache(options);
2120
- return new CanvasClient({
2124
+ return {
2121
2125
  projectId: env.getProjectId(),
2122
2126
  apiHost: env.getApiHost(),
2123
2127
  apiKey: env.getApiKey(),
@@ -2165,7 +2169,10 @@ var getCanvasClient = (options) => {
2165
2169
  }
2166
2170
  });
2167
2171
  }
2168
- });
2172
+ };
2173
+ };
2174
+ var getCompositionDeliveryClient = (options) => {
2175
+ return new CompositionDeliveryClient(buildCanvasClientOptions(options));
2169
2176
  };
2170
2177
 
2171
2178
  // src/clients/projectMap.ts
@@ -2414,18 +2421,15 @@ var _Route = class _Route2 {
2414
2421
  */
2415
2422
  static splitFragment(path) {
2416
2423
  let fragmentIndex = -1;
2417
- let length = 0;
2418
- parseVariableExpression(path, (token, type) => {
2424
+ parseVariableExpression(path, (token, type, offset) => {
2419
2425
  if (type === "variable") {
2420
- length += createVariableReference(token).length;
2421
2426
  return;
2422
2427
  }
2423
2428
  const hashOffset = token.indexOf("#");
2424
2429
  if (hashOffset === -1) {
2425
- length += token.length;
2426
2430
  return;
2427
2431
  }
2428
- fragmentIndex = length + hashOffset;
2432
+ fragmentIndex = offset + hashOffset;
2429
2433
  return false;
2430
2434
  });
2431
2435
  if (fragmentIndex === -1) {
@@ -2564,13 +2568,13 @@ var processCompositionChange = async (compositionId) => {
2564
2568
  };
2565
2569
  };
2566
2570
  var getComposition = async ({ compositionId }) => {
2567
- const canvasClient = getCanvasClient({
2571
+ const canvasClient = getCompositionDeliveryClient({
2568
2572
  cache: {
2569
2573
  type: "no-cache"
2570
2574
  }
2571
2575
  });
2572
2576
  try {
2573
- const composition = await canvasClient.getCompositionById({
2577
+ const composition = await canvasClient.get({
2574
2578
  compositionId
2575
2579
  });
2576
2580
  return composition;
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { CanvasClient, RouteClient, ComponentInstance } from '@uniformdev/canvas';
1
+ import { CanvasClient, CompositionDeliveryClient, RouteClient, ComponentInstance } from '@uniformdev/canvas';
2
2
  import { CacheMode, CanvasCacheMode, ManifestCacheMode, ProjectMapCacheMode, RewriteRequestPathResult } from '@uniformdev/next-app-router-shared';
3
3
  import { ManifestClient } from '@uniformdev/context/api';
4
4
  import { ProjectMapClient } from '@uniformdev/project-map';
@@ -24,7 +24,12 @@ type DetectCacheMode = {
24
24
  type ResolvableCacheOptions<TCacheMode extends CacheMode> = SpecificCacheMode<TCacheMode> | StateCacheMode | DetectCacheMode;
25
25
 
26
26
  type GetCanvasClientOptions = ResolvableCacheOptions<CanvasCacheMode>;
27
+ type GetCompositionDeliveryClientOptions = GetCanvasClientOptions;
28
+ /**
29
+ * @deprecated Use {@link getCompositionDeliveryClient} instead
30
+ */
27
31
  declare const getCanvasClient: (options?: GetCanvasClientOptions) => CanvasClient;
32
+ declare const getCompositionDeliveryClient: (options?: GetCompositionDeliveryClientOptions) => CompositionDeliveryClient;
28
33
 
29
34
  type GetManifestClientOptions = ResolvableCacheOptions<ManifestCacheMode>;
30
35
  declare const getManifestClient: (options?: GetManifestClientOptions) => ManifestClient;
@@ -271,4 +276,4 @@ declare const findRouteMatch: (routes: CustomRoute[], path: string) => RouteMatc
271
276
 
272
277
  declare const serverContext: <T>(defaultValue?: T) => [() => T | undefined, (v: T) => void];
273
278
 
274
- export { type AwaitedUniformPageParameters, type CreateStaticParamsOptions, type CustomRoute, type GetCanvasClientOptions, type GetManifestClientOptions, type GetProjectMapClientOptions, type GetRouteClientOptions, type PlaygroundParameters, type RouteMatch, UniformCompositionProps, type UniformPageParameters, UniformPlayground, createUniformPlaygroundStaticParams, createUniformStaticParams, findRouteMatch, getCanvasClient, getManifest, getManifestClient, getProjectMapClient, getRouteClient, precomputeComposition, resolvePlaygroundRoute, serverContext };
279
+ export { type AwaitedUniformPageParameters, type CreateStaticParamsOptions, type CustomRoute, type GetCanvasClientOptions, type GetCompositionDeliveryClientOptions, type GetManifestClientOptions, type GetProjectMapClientOptions, type GetRouteClientOptions, type PlaygroundParameters, type RouteMatch, UniformCompositionProps, type UniformPageParameters, UniformPlayground, createUniformPlaygroundStaticParams, createUniformStaticParams, findRouteMatch, getCanvasClient, getCompositionDeliveryClient, getManifest, getManifestClient, getProjectMapClient, getRouteClient, precomputeComposition, resolvePlaygroundRoute, serverContext };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CanvasClient, RouteClient, ComponentInstance } from '@uniformdev/canvas';
1
+ import { CanvasClient, CompositionDeliveryClient, RouteClient, ComponentInstance } from '@uniformdev/canvas';
2
2
  import { CacheMode, CanvasCacheMode, ManifestCacheMode, ProjectMapCacheMode, RewriteRequestPathResult } from '@uniformdev/next-app-router-shared';
3
3
  import { ManifestClient } from '@uniformdev/context/api';
4
4
  import { ProjectMapClient } from '@uniformdev/project-map';
@@ -24,7 +24,12 @@ type DetectCacheMode = {
24
24
  type ResolvableCacheOptions<TCacheMode extends CacheMode> = SpecificCacheMode<TCacheMode> | StateCacheMode | DetectCacheMode;
25
25
 
26
26
  type GetCanvasClientOptions = ResolvableCacheOptions<CanvasCacheMode>;
27
+ type GetCompositionDeliveryClientOptions = GetCanvasClientOptions;
28
+ /**
29
+ * @deprecated Use {@link getCompositionDeliveryClient} instead
30
+ */
27
31
  declare const getCanvasClient: (options?: GetCanvasClientOptions) => CanvasClient;
32
+ declare const getCompositionDeliveryClient: (options?: GetCompositionDeliveryClientOptions) => CompositionDeliveryClient;
28
33
 
29
34
  type GetManifestClientOptions = ResolvableCacheOptions<ManifestCacheMode>;
30
35
  declare const getManifestClient: (options?: GetManifestClientOptions) => ManifestClient;
@@ -271,4 +276,4 @@ declare const findRouteMatch: (routes: CustomRoute[], path: string) => RouteMatc
271
276
 
272
277
  declare const serverContext: <T>(defaultValue?: T) => [() => T | undefined, (v: T) => void];
273
278
 
274
- export { type AwaitedUniformPageParameters, type CreateStaticParamsOptions, type CustomRoute, type GetCanvasClientOptions, type GetManifestClientOptions, type GetProjectMapClientOptions, type GetRouteClientOptions, type PlaygroundParameters, type RouteMatch, UniformCompositionProps, type UniformPageParameters, UniformPlayground, createUniformPlaygroundStaticParams, createUniformStaticParams, findRouteMatch, getCanvasClient, getManifest, getManifestClient, getProjectMapClient, getRouteClient, precomputeComposition, resolvePlaygroundRoute, serverContext };
279
+ export { type AwaitedUniformPageParameters, type CreateStaticParamsOptions, type CustomRoute, type GetCanvasClientOptions, type GetCompositionDeliveryClientOptions, type GetManifestClientOptions, type GetProjectMapClientOptions, type GetRouteClientOptions, type PlaygroundParameters, type RouteMatch, UniformCompositionProps, type UniformPageParameters, UniformPlayground, createUniformPlaygroundStaticParams, createUniformStaticParams, findRouteMatch, getCanvasClient, getCompositionDeliveryClient, getManifest, getManifestClient, getProjectMapClient, getRouteClient, precomputeComposition, resolvePlaygroundRoute, serverContext };