@uniformdev/next-app-router 20.73.1-alpha.13 → 20.74.2-alpha.26

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.js CHANGED
@@ -1223,6 +1223,16 @@ function createLimitPolicy({
1223
1223
  return currentFunc();
1224
1224
  };
1225
1225
  }
1226
+ var ContentClientBase = class extends ApiClient {
1227
+ constructor(options, defaultBypassCache) {
1228
+ var _a, _b;
1229
+ super({
1230
+ ...options,
1231
+ limitPolicy: (_a = options.limitPolicy) != null ? _a : createLimitPolicy({}),
1232
+ bypassCache: (_b = options.bypassCache) != null ? _b : defaultBypassCache
1233
+ });
1234
+ }
1235
+ };
1226
1236
  var SELECT_QUERY_PREFIX = "select.";
1227
1237
  function appendCsv(out, key, values) {
1228
1238
  if (values === void 0) {
@@ -1267,130 +1277,94 @@ function projectionToQuery(spec) {
1267
1277
  }
1268
1278
  return out;
1269
1279
  }
1270
- var CANVAS_URL = "/api/v1/canvas";
1271
- var CanvasClient = class extends ApiClient {
1272
- constructor(options) {
1273
- var _a;
1274
- if (!options.limitPolicy) {
1275
- options.limitPolicy = createLimitPolicy({});
1276
- }
1277
- super(options);
1278
- this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
1279
- this.edgeApiRequestInit = options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0;
1280
- }
1281
- /** Fetches lists of Canvas compositions, optionally by type */
1282
- async getCompositionList(params = {}) {
1283
- const { projectId } = this.options;
1284
- const { resolveData, filters, select, ...originParams } = params;
1285
- const rewrittenFilters = rewriteFiltersForApi(filters);
1286
- const rewrittenSelect = projectionToQuery(select);
1287
- if (!resolveData) {
1288
- const fetchUri = this.createUrl(CANVAS_URL, {
1289
- ...originParams,
1290
- projectId,
1291
- ...rewrittenFilters,
1292
- ...rewrittenSelect
1293
- });
1294
- return this.apiClient(fetchUri);
1295
- }
1296
- const edgeParams = {
1297
- ...originParams,
1298
- projectId,
1299
- diagnostics: typeof params.diagnostics === "boolean" ? params.diagnostics : params.diagnostics === "no-data" ? "no-data" : void 0,
1300
- ...rewrittenFilters,
1301
- ...rewrittenSelect
1302
- };
1303
- const edgeUrl = this.createUrl("/api/v1/compositions", edgeParams, this.edgeApiHost);
1304
- return this.apiClient(edgeUrl, this.edgeApiRequestInit);
1305
- }
1306
- getCompositionByNodePath(options) {
1307
- return this.getOneComposition(options);
1308
- }
1309
- getCompositionByNodeId(options) {
1310
- return this.getOneComposition(options);
1311
- }
1312
- getCompositionBySlug(options) {
1313
- return this.getOneComposition(options);
1314
- }
1315
- getCompositionById(options) {
1316
- return this.getOneComposition(options);
1317
- }
1318
- getCompositionDefaults(options) {
1319
- return this.getOneComposition(options);
1320
- }
1321
- /** Fetches historical versions of a composition or pattern */
1322
- async getCompositionHistory(options) {
1323
- const historyUrl = this.createUrl("/api/v1/canvas-history", {
1324
- ...options,
1325
- projectId: this.options.projectId
1326
- });
1327
- return this.apiClient(historyUrl);
1328
- }
1329
- getOneComposition({
1330
- skipDataResolution,
1331
- diagnostics,
1332
- ...params
1333
- }) {
1334
- const { projectId } = this.options;
1335
- if (skipDataResolution) {
1336
- return this.apiClient(this.createUrl(CANVAS_URL, { ...params, projectId }));
1337
- }
1338
- const edgeParams = {
1339
- ...params,
1340
- projectId,
1341
- diagnostics: typeof diagnostics === "boolean" ? diagnostics : diagnostics === "no-data" ? "no-data" : void 0
1280
+ var CANVAS_DRAFT_STATE = 0;
1281
+ var CANVAS_PUBLISHED_STATE = 64;
1282
+ var CANVAS_EDITOR_STATE = 63;
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 SECRET_QUERY_STRING_PARAM = "secret";
1287
+ var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1288
+ var IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM = "is_incontext_editing_playground";
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
1342
1300
  };
1343
- const edgeUrl = this.createUrl("/api/v1/composition", edgeParams, this.edgeApiHost);
1344
- return this.apiClient(edgeUrl, this.edgeApiRequestInit);
1345
1301
  }
1346
- /** Updates or creates a Canvas component definition */
1347
- async updateComposition(body, options) {
1348
- const fetchUri = this.createUrl(CANVAS_URL);
1349
- const headers = {};
1350
- if (options == null ? void 0 : options.ifUnmodifiedSince) {
1351
- headers["x-if-unmodified-since"] = options.ifUnmodifiedSince;
1352
- }
1353
- const { response } = await this.apiClientWithResponse(fetchUri, {
1354
- method: "PUT",
1355
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1356
- expectNoContent: true,
1357
- headers
1358
- });
1359
- return { modified: response.headers.get("x-modified-at") };
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;
1360
1315
  }
1361
- /** Deletes a Canvas component definition */
1362
- async removeComposition(body) {
1363
- const fetchUri = this.createUrl(CANVAS_URL);
1364
- const { projectId } = this.options;
1365
- await this.apiClient(fetchUri, {
1366
- method: "DELETE",
1367
- body: JSON.stringify({ ...body, projectId }),
1368
- expectNoContent: true
1369
- });
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;
1370
1319
  }
1371
- /** Fetches all Canvas component definitions */
1372
- async getComponentDefinitions(options) {
1373
- const { projectId } = this.options;
1374
- const fetchUri = this.createUrl("/api/v1/canvas-definitions", { ...options, projectId });
1375
- return this.apiClient(fetchUri);
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);
1376
1326
  }
1377
- /** Updates or creates a Canvas component definition */
1378
- async updateComponentDefinition(body) {
1379
- const fetchUri = this.createUrl("/api/v1/canvas-definitions");
1380
- await this.apiClient(fetchUri, {
1381
- method: "PUT",
1382
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1383
- expectNoContent: true
1384
- });
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);
1385
1350
  }
1386
- /** Deletes a Canvas component definition */
1387
- async removeComponentDefinition(body) {
1388
- const fetchUri = this.createUrl("/api/v1/canvas-definitions");
1389
- await this.apiClient(fetchUri, {
1390
- method: "DELETE",
1391
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1392
- expectNoContent: true
1393
- });
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);
1394
1368
  }
1395
1369
  };
1396
1370
  var _contentTypesUrl;
@@ -1499,14 +1473,18 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1499
1473
  constructor(options) {
1500
1474
  super(options);
1501
1475
  }
1502
- /** Fetches all DataTypes for a project */
1503
- async get(options) {
1476
+ /** Fetches a list of DataTypes for a project */
1477
+ async list(options) {
1504
1478
  const { projectId } = this.options;
1505
1479
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8), { ...options, projectId });
1506
1480
  return await this.apiClient(fetchUri);
1507
1481
  }
1482
+ /** @deprecated Use {@link list} instead. */
1483
+ async get(options) {
1484
+ return this.list(options);
1485
+ }
1508
1486
  /** Updates or creates (based on id) a DataType */
1509
- async upsert(body) {
1487
+ async save(body) {
1510
1488
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
1511
1489
  await this.apiClient(fetchUri, {
1512
1490
  method: "PUT",
@@ -1514,6 +1492,10 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1514
1492
  expectNoContent: true
1515
1493
  });
1516
1494
  }
1495
+ /** @deprecated Use {@link save} instead. */
1496
+ async upsert(body) {
1497
+ return this.save(body);
1498
+ }
1517
1499
  /** Deletes a DataType */
1518
1500
  async remove(body) {
1519
1501
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
@@ -1526,15 +1508,6 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1526
1508
  };
1527
1509
  _url8 = /* @__PURE__ */ new WeakMap();
1528
1510
  __privateAdd3(_DataTypeClient, _url8, "/api/v1/data-types");
1529
- var CANVAS_DRAFT_STATE = 0;
1530
- var CANVAS_EDITOR_STATE = 63;
1531
- var CANVAS_INTERNAL_PARAM_PREFIX = "$internal_";
1532
- var CANVAS_COMPONENT_DISPLAY_NAME_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}displayName`;
1533
- var CANVAS_HYPOTHESIS_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}hypothesis`;
1534
- var SECRET_QUERY_STRING_PARAM = "secret";
1535
- var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1536
- var IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM = "is_incontext_editing_playground";
1537
- var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
1538
1511
  var escapeCharacter = "\\";
1539
1512
  var variablePrefix = "${";
1540
1513
  var variableSuffix = "}";
@@ -1668,20 +1641,28 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
1668
1641
  * When teamId is provided, returns a single team with its projects.
1669
1642
  * When omitted, returns all accessible teams and their projects.
1670
1643
  */
1671
- async getProjects(options) {
1644
+ async list(options) {
1672
1645
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
1673
1646
  return await this.apiClient(fetchUri);
1674
1647
  }
1648
+ /** @deprecated Use {@link list} instead. */
1649
+ async getProjects(options) {
1650
+ return this.list(options);
1651
+ }
1675
1652
  /** Updates or creates (based on id) a Project */
1676
- async upsert(body) {
1653
+ async save(body) {
1677
1654
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
1678
1655
  return await this.apiClient(fetchUri, {
1679
1656
  method: "PUT",
1680
1657
  body: JSON.stringify({ ...body })
1681
1658
  });
1682
1659
  }
1660
+ /** @deprecated Use {@link save} instead. */
1661
+ async upsert(body) {
1662
+ return this.save(body);
1663
+ }
1683
1664
  /** Deletes a Project */
1684
- async delete(body) {
1665
+ async remove(body) {
1685
1666
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
1686
1667
  await this.apiClient(fetchUri, {
1687
1668
  method: "DELETE",
@@ -1689,13 +1670,19 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
1689
1670
  expectNoContent: true
1690
1671
  });
1691
1672
  }
1673
+ /** @deprecated Use {@link remove} instead. */
1674
+ async delete(body) {
1675
+ return this.remove(body);
1676
+ }
1692
1677
  };
1693
1678
  _url22 = /* @__PURE__ */ new WeakMap();
1694
1679
  _projectsUrl = /* @__PURE__ */ new WeakMap();
1695
1680
  __privateAdd3(_ProjectClient, _url22, "/api/v1/project");
1696
1681
  __privateAdd3(_ProjectClient, _projectsUrl, "/api/v1/projects");
1697
1682
  var isAllowedReferrer = (referrer) => {
1698
- return Boolean(referrer == null ? void 0 : referrer.match(/(^https:\/\/|\.)(uniform.app|uniform.wtf|localhost:\d{4})\//));
1683
+ return Boolean(
1684
+ referrer == null ? void 0 : referrer.match(/(^https:\/\/|\.)(uniform.app|uniform.wtf|uniformcode.ai|localhost:\d{4})\//)
1685
+ );
1699
1686
  };
1700
1687
 
1701
1688
  // src/handler/createPreviewGETRouteHandler.ts
@@ -2147,9 +2134,9 @@ function createLimitPolicy2({
2147
2134
  }
2148
2135
 
2149
2136
  // src/clients/canvas.ts
2150
- var getCanvasClient = (options) => {
2137
+ var buildCanvasClientOptions = (options) => {
2151
2138
  const cache = resolveCanvasCache(options);
2152
- return new CanvasClient({
2139
+ return {
2153
2140
  projectId: env.getProjectId(),
2154
2141
  apiHost: env.getApiHost(),
2155
2142
  apiKey: env.getApiKey(),
@@ -2197,7 +2184,10 @@ var getCanvasClient = (options) => {
2197
2184
  }
2198
2185
  });
2199
2186
  }
2200
- });
2187
+ };
2188
+ };
2189
+ var getCompositionDeliveryClient = (options) => {
2190
+ return new CompositionDeliveryClient(buildCanvasClientOptions(options));
2201
2191
  };
2202
2192
 
2203
2193
  // src/clients/projectMap.ts
@@ -2593,13 +2583,13 @@ var processCompositionChange = async (compositionId) => {
2593
2583
  };
2594
2584
  };
2595
2585
  var getComposition = async ({ compositionId }) => {
2596
- const canvasClient = getCanvasClient({
2586
+ const canvasClient = getCompositionDeliveryClient({
2597
2587
  cache: {
2598
2588
  type: "no-cache"
2599
2589
  }
2600
2590
  });
2601
2591
  try {
2602
- const composition = await canvasClient.getCompositionById({
2592
+ const composition = await canvasClient.get({
2603
2593
  compositionId
2604
2594
  });
2605
2595
  return composition;