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

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
@@ -1208,6 +1208,16 @@ function createLimitPolicy({
1208
1208
  return currentFunc();
1209
1209
  };
1210
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
+ };
1211
1221
  var SELECT_QUERY_PREFIX = "select.";
1212
1222
  function appendCsv(out, key, values) {
1213
1223
  if (values === void 0) {
@@ -1252,130 +1262,94 @@ function projectionToQuery(spec) {
1252
1262
  }
1253
1263
  return out;
1254
1264
  }
1255
- var CANVAS_URL = "/api/v1/canvas";
1256
- var CanvasClient = class extends ApiClient {
1257
- constructor(options) {
1258
- var _a;
1259
- if (!options.limitPolicy) {
1260
- options.limitPolicy = createLimitPolicy({});
1261
- }
1262
- super(options);
1263
- this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
1264
- this.edgeApiRequestInit = options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0;
1265
- }
1266
- /** Fetches lists of Canvas compositions, optionally by type */
1267
- async getCompositionList(params = {}) {
1268
- const { projectId } = this.options;
1269
- const { resolveData, filters, select, ...originParams } = params;
1270
- const rewrittenFilters = rewriteFiltersForApi(filters);
1271
- const rewrittenSelect = projectionToQuery(select);
1272
- if (!resolveData) {
1273
- const fetchUri = this.createUrl(CANVAS_URL, {
1274
- ...originParams,
1275
- projectId,
1276
- ...rewrittenFilters,
1277
- ...rewrittenSelect
1278
- });
1279
- return this.apiClient(fetchUri);
1280
- }
1281
- const edgeParams = {
1282
- ...originParams,
1283
- projectId,
1284
- diagnostics: typeof params.diagnostics === "boolean" ? params.diagnostics : params.diagnostics === "no-data" ? "no-data" : void 0,
1285
- ...rewrittenFilters,
1286
- ...rewrittenSelect
1287
- };
1288
- const edgeUrl = this.createUrl("/api/v1/compositions", edgeParams, this.edgeApiHost);
1289
- return this.apiClient(edgeUrl, this.edgeApiRequestInit);
1290
- }
1291
- getCompositionByNodePath(options) {
1292
- return this.getOneComposition(options);
1293
- }
1294
- getCompositionByNodeId(options) {
1295
- return this.getOneComposition(options);
1296
- }
1297
- getCompositionBySlug(options) {
1298
- return this.getOneComposition(options);
1299
- }
1300
- getCompositionById(options) {
1301
- return this.getOneComposition(options);
1302
- }
1303
- getCompositionDefaults(options) {
1304
- return this.getOneComposition(options);
1305
- }
1306
- /** Fetches historical versions of a composition or pattern */
1307
- async getCompositionHistory(options) {
1308
- const historyUrl = this.createUrl("/api/v1/canvas-history", {
1309
- ...options,
1310
- projectId: this.options.projectId
1311
- });
1312
- return this.apiClient(historyUrl);
1313
- }
1314
- getOneComposition({
1315
- skipDataResolution,
1316
- diagnostics,
1317
- ...params
1318
- }) {
1319
- const { projectId } = this.options;
1320
- if (skipDataResolution) {
1321
- return this.apiClient(this.createUrl(CANVAS_URL, { ...params, projectId }));
1322
- }
1323
- const edgeParams = {
1324
- ...params,
1325
- projectId,
1326
- 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
1327
1285
  };
1328
- const edgeUrl = this.createUrl("/api/v1/composition", edgeParams, this.edgeApiHost);
1329
- return this.apiClient(edgeUrl, this.edgeApiRequestInit);
1330
1286
  }
1331
- /** Updates or creates a Canvas component definition */
1332
- async updateComposition(body, options) {
1333
- const fetchUri = this.createUrl(CANVAS_URL);
1334
- const headers = {};
1335
- if (options == null ? void 0 : options.ifUnmodifiedSince) {
1336
- headers["x-if-unmodified-since"] = options.ifUnmodifiedSince;
1337
- }
1338
- const { response } = await this.apiClientWithResponse(fetchUri, {
1339
- method: "PUT",
1340
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1341
- expectNoContent: true,
1342
- headers
1343
- });
1344
- 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;
1345
1300
  }
1346
- /** Deletes a Canvas component definition */
1347
- async removeComposition(body) {
1348
- const fetchUri = this.createUrl(CANVAS_URL);
1349
- const { projectId } = this.options;
1350
- await this.apiClient(fetchUri, {
1351
- method: "DELETE",
1352
- body: JSON.stringify({ ...body, projectId }),
1353
- expectNoContent: true
1354
- });
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;
1355
1304
  }
1356
- /** Fetches all Canvas component definitions */
1357
- async getComponentDefinitions(options) {
1358
- const { projectId } = this.options;
1359
- const fetchUri = this.createUrl("/api/v1/canvas-definitions", { ...options, projectId });
1360
- 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);
1361
1311
  }
1362
- /** Updates or creates a Canvas component definition */
1363
- async updateComponentDefinition(body) {
1364
- const fetchUri = this.createUrl("/api/v1/canvas-definitions");
1365
- await this.apiClient(fetchUri, {
1366
- method: "PUT",
1367
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1368
- expectNoContent: true
1369
- });
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);
1370
1335
  }
1371
- /** Deletes a Canvas component definition */
1372
- async removeComponentDefinition(body) {
1373
- const fetchUri = this.createUrl("/api/v1/canvas-definitions");
1374
- await this.apiClient(fetchUri, {
1375
- method: "DELETE",
1376
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1377
- expectNoContent: true
1378
- });
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);
1379
1353
  }
1380
1354
  };
1381
1355
  var _contentTypesUrl;
@@ -1484,14 +1458,18 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1484
1458
  constructor(options) {
1485
1459
  super(options);
1486
1460
  }
1487
- /** Fetches all DataTypes for a project */
1488
- async get(options) {
1461
+ /** Fetches a list of DataTypes for a project */
1462
+ async list(options) {
1489
1463
  const { projectId } = this.options;
1490
1464
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8), { ...options, projectId });
1491
1465
  return await this.apiClient(fetchUri);
1492
1466
  }
1467
+ /** @deprecated Use {@link list} instead. */
1468
+ async get(options) {
1469
+ return this.list(options);
1470
+ }
1493
1471
  /** Updates or creates (based on id) a DataType */
1494
- async upsert(body) {
1472
+ async save(body) {
1495
1473
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
1496
1474
  await this.apiClient(fetchUri, {
1497
1475
  method: "PUT",
@@ -1499,6 +1477,10 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1499
1477
  expectNoContent: true
1500
1478
  });
1501
1479
  }
1480
+ /** @deprecated Use {@link save} instead. */
1481
+ async upsert(body) {
1482
+ return this.save(body);
1483
+ }
1502
1484
  /** Deletes a DataType */
1503
1485
  async remove(body) {
1504
1486
  const fetchUri = this.createUrl(__privateGet3(_DataTypeClient2, _url8));
@@ -1511,15 +1493,6 @@ var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
1511
1493
  };
1512
1494
  _url8 = /* @__PURE__ */ new WeakMap();
1513
1495
  __privateAdd3(_DataTypeClient, _url8, "/api/v1/data-types");
1514
- var CANVAS_DRAFT_STATE = 0;
1515
- var CANVAS_EDITOR_STATE = 63;
1516
- var CANVAS_INTERNAL_PARAM_PREFIX = "$internal_";
1517
- var CANVAS_COMPONENT_DISPLAY_NAME_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}displayName`;
1518
- var CANVAS_HYPOTHESIS_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}hypothesis`;
1519
- var SECRET_QUERY_STRING_PARAM = "secret";
1520
- var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1521
- var IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM = "is_incontext_editing_playground";
1522
- var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
1523
1496
  var escapeCharacter = "\\";
1524
1497
  var variablePrefix = "${";
1525
1498
  var variableSuffix = "}";
@@ -1653,20 +1626,28 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
1653
1626
  * When teamId is provided, returns a single team with its projects.
1654
1627
  * When omitted, returns all accessible teams and their projects.
1655
1628
  */
1656
- async getProjects(options) {
1629
+ async list(options) {
1657
1630
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
1658
1631
  return await this.apiClient(fetchUri);
1659
1632
  }
1633
+ /** @deprecated Use {@link list} instead. */
1634
+ async getProjects(options) {
1635
+ return this.list(options);
1636
+ }
1660
1637
  /** Updates or creates (based on id) a Project */
1661
- async upsert(body) {
1638
+ async save(body) {
1662
1639
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
1663
1640
  return await this.apiClient(fetchUri, {
1664
1641
  method: "PUT",
1665
1642
  body: JSON.stringify({ ...body })
1666
1643
  });
1667
1644
  }
1645
+ /** @deprecated Use {@link save} instead. */
1646
+ async upsert(body) {
1647
+ return this.save(body);
1648
+ }
1668
1649
  /** Deletes a Project */
1669
- async delete(body) {
1650
+ async remove(body) {
1670
1651
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
1671
1652
  await this.apiClient(fetchUri, {
1672
1653
  method: "DELETE",
@@ -1674,6 +1655,10 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
1674
1655
  expectNoContent: true
1675
1656
  });
1676
1657
  }
1658
+ /** @deprecated Use {@link remove} instead. */
1659
+ async delete(body) {
1660
+ return this.remove(body);
1661
+ }
1677
1662
  };
1678
1663
  _url22 = /* @__PURE__ */ new WeakMap();
1679
1664
  _projectsUrl = /* @__PURE__ */ new WeakMap();
@@ -2134,9 +2119,9 @@ function createLimitPolicy2({
2134
2119
  }
2135
2120
 
2136
2121
  // src/clients/canvas.ts
2137
- var getCanvasClient = (options) => {
2122
+ var buildCanvasClientOptions = (options) => {
2138
2123
  const cache = resolveCanvasCache(options);
2139
- return new CanvasClient({
2124
+ return {
2140
2125
  projectId: env.getProjectId(),
2141
2126
  apiHost: env.getApiHost(),
2142
2127
  apiKey: env.getApiKey(),
@@ -2184,7 +2169,10 @@ var getCanvasClient = (options) => {
2184
2169
  }
2185
2170
  });
2186
2171
  }
2187
- });
2172
+ };
2173
+ };
2174
+ var getCompositionDeliveryClient = (options) => {
2175
+ return new CompositionDeliveryClient(buildCanvasClientOptions(options));
2188
2176
  };
2189
2177
 
2190
2178
  // src/clients/projectMap.ts
@@ -2580,13 +2568,13 @@ var processCompositionChange = async (compositionId) => {
2580
2568
  };
2581
2569
  };
2582
2570
  var getComposition = async ({ compositionId }) => {
2583
- const canvasClient = getCanvasClient({
2571
+ const canvasClient = getCompositionDeliveryClient({
2584
2572
  cache: {
2585
2573
  type: "no-cache"
2586
2574
  }
2587
2575
  });
2588
2576
  try {
2589
- const composition = await canvasClient.getCompositionById({
2577
+ const composition = await canvasClient.get({
2590
2578
  compositionId
2591
2579
  });
2592
2580
  return composition;
@@ -2849,7 +2837,7 @@ var handleSvixMessage = async (request) => {
2849
2837
  const cache = getMiddlewareRuntimeCache() ? getCache() : void 0;
2850
2838
  for (let i = 0; i < tags.length; i++) {
2851
2839
  const tag = tags[i];
2852
- revalidateTag(tag);
2840
+ revalidateTag(tag, "max");
2853
2841
  if (cache) {
2854
2842
  await cache.expireTag(tag);
2855
2843
  }
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 };