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

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
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
1302
1300
  };
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
1301
  }
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
1342
- };
1343
- const edgeUrl = this.createUrl("/api/v1/composition", edgeParams, this.edgeApiHost);
1344
- return this.apiClient(edgeUrl, this.edgeApiRequestInit);
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;
1345
1315
  }
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") };
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;
1360
1319
  }
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
- });
1370
- }
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,15 +1670,22 @@ 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");
1682
+ var ALLOWED_REFERRER_ORIGIN = /^https:\/\/([\w-]+\.)*(uniform\.(app|wtf)|uniformcode\.ai)$|^https?:\/\/localhost:\d{4}$/;
1697
1683
  var isAllowedReferrer = (referrer) => {
1698
- return Boolean(
1699
- referrer == null ? void 0 : referrer.match(/(^https:\/\/|\.)(uniform.app|uniform.wtf|uniformcode.ai|localhost:\d{4})\//)
1700
- );
1684
+ try {
1685
+ return ALLOWED_REFERRER_ORIGIN.test(new URL(referrer != null ? referrer : "").origin);
1686
+ } catch (e) {
1687
+ return false;
1688
+ }
1701
1689
  };
1702
1690
 
1703
1691
  // src/handler/createPreviewGETRouteHandler.ts
@@ -2149,9 +2137,9 @@ function createLimitPolicy2({
2149
2137
  }
2150
2138
 
2151
2139
  // src/clients/canvas.ts
2152
- var getCanvasClient = (options) => {
2140
+ var buildCanvasClientOptions = (options) => {
2153
2141
  const cache = resolveCanvasCache(options);
2154
- return new CanvasClient({
2142
+ return {
2155
2143
  projectId: env.getProjectId(),
2156
2144
  apiHost: env.getApiHost(),
2157
2145
  apiKey: env.getApiKey(),
@@ -2199,7 +2187,10 @@ var getCanvasClient = (options) => {
2199
2187
  }
2200
2188
  });
2201
2189
  }
2202
- });
2190
+ };
2191
+ };
2192
+ var getCompositionDeliveryClient = (options) => {
2193
+ return new CompositionDeliveryClient(buildCanvasClientOptions(options));
2203
2194
  };
2204
2195
 
2205
2196
  // src/clients/projectMap.ts
@@ -2595,13 +2586,13 @@ var processCompositionChange = async (compositionId) => {
2595
2586
  };
2596
2587
  };
2597
2588
  var getComposition = async ({ compositionId }) => {
2598
- const canvasClient = getCanvasClient({
2589
+ const canvasClient = getCompositionDeliveryClient({
2599
2590
  cache: {
2600
2591
  type: "no-cache"
2601
2592
  }
2602
2593
  });
2603
2594
  try {
2604
- const composition = await canvasClient.getCompositionById({
2595
+ const composition = await canvasClient.get({
2605
2596
  compositionId
2606
2597
  });
2607
2598
  return composition;