@uniformdev/canvas 18.1.1-alpha.11 → 18.1.2-alpha.7

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.
@@ -475,17 +475,19 @@ function createLimitPolicy({
475
475
  var nullLimitPolicy = async (func) => await func();
476
476
 
477
477
  // src/CanvasClient.ts
478
+ var CANVAS_URL = "/api/v1/canvas";
478
479
  var CanvasClient = class extends ApiClient {
479
480
  constructor(options) {
481
+ var _a;
480
482
  if (!options.limitPolicy) {
481
483
  options.limitPolicy = createLimitPolicy({});
482
484
  }
483
485
  super(options);
484
- this.canvasUrl = "/api/v1/canvas";
486
+ this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
485
487
  }
486
488
  async getCompositionList(options) {
487
489
  const { projectId } = this.options;
488
- const fetchUri = this.createUrl(this.canvasUrl, { ...options, projectId });
490
+ const fetchUri = this.createUrl(CANVAS_URL, { ...options, projectId });
489
491
  return await this.apiClient(fetchUri);
490
492
  }
491
493
  unstable_getCompositionByNodePath(options) {
@@ -507,20 +509,20 @@ var CanvasClient = class extends ApiClient {
507
509
  ...params
508
510
  }) {
509
511
  const { projectId } = this.options;
510
- const url = resolveData ? "/api/edge/v1/composition" : this.canvasUrl;
511
- const dataResolutionParams = {};
512
- if (resolveData) {
513
- if (dynamicVariables) {
514
- dataResolutionParams.dynamicVariables = JSON.stringify(dynamicVariables);
515
- }
516
- if (dataDiagnostics) {
517
- dataResolutionParams.dataDiagnostics = "true";
518
- }
512
+ if (!resolveData) {
513
+ return this.apiClient(this.createUrl(CANVAS_URL, { ...params, projectId }));
519
514
  }
520
- return this.apiClient(this.createUrl(url, { ...params, ...dataResolutionParams, projectId }));
515
+ const edgeParams = {
516
+ ...params,
517
+ projectId,
518
+ ...dynamicVariables ? { dynamicVariables: JSON.stringify(dynamicVariables) } : {},
519
+ ...dataDiagnostics ? { dataDiagnostics: "true" } : {}
520
+ };
521
+ const edgeUrl = this.createUrl("/api/v1/composition", edgeParams, this.edgeApiHost);
522
+ return this.apiClient(edgeUrl);
521
523
  }
522
524
  async updateComposition(body) {
523
- const fetchUri = this.createUrl("/api/v1/canvas");
525
+ const fetchUri = this.createUrl(CANVAS_URL);
524
526
  await this.apiClient(fetchUri, {
525
527
  method: "PUT",
526
528
  body: JSON.stringify({ ...body, projectId: this.options.projectId }),
@@ -528,7 +530,7 @@ var CanvasClient = class extends ApiClient {
528
530
  });
529
531
  }
530
532
  async removeComposition(body) {
531
- const fetchUri = this.createUrl("/api/v1/canvas");
533
+ const fetchUri = this.createUrl(CANVAS_URL);
532
534
  const { projectId } = this.options;
533
535
  await this.apiClient(fetchUri, {
534
536
  method: "DELETE",
@@ -1091,6 +1093,7 @@ var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
1091
1093
  var CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
1092
1094
  var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1093
1095
  var IN_CONTEXT_EDITOR_COMPONENT_START_ROLE = "uniform-component-start";
1096
+ var IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID = "uniform-canvas-preview-script";
1094
1097
  var PLACEHOLDER_ID = "placeholder";
1095
1098
  var EDGE_MIN_CACHE_TTL = 15;
1096
1099
  var EDGE_MAX_CACHE_TTL = 600;
@@ -1383,6 +1386,28 @@ function subscribeToComposition({
1383
1386
  };
1384
1387
  }
1385
1388
 
1389
+ // src/utils/createApiEnhancer.ts
1390
+ var createUniformApiEnhancer = ({ apiUrl }) => {
1391
+ return async (message) => {
1392
+ const response = await fetch(apiUrl, {
1393
+ method: "post",
1394
+ body: JSON.stringify({
1395
+ composition: message.composition,
1396
+ hash: message.hash
1397
+ }),
1398
+ headers: {
1399
+ "Content-Type": "application/json"
1400
+ }
1401
+ });
1402
+ const json = await response.json();
1403
+ if (!response.ok) {
1404
+ throw new Error("Error reading enhanced composition");
1405
+ }
1406
+ const body = json;
1407
+ return body.composition;
1408
+ };
1409
+ };
1410
+
1386
1411
  // src/utils/isSystemComponentDefinition.ts
1387
1412
  var isSystemComponentDefinition = (componentType) => {
1388
1413
  return componentType.startsWith("$");
@@ -1465,6 +1490,7 @@ export {
1465
1490
  CANVAS_ENRICHMENT_TAG_PARAM,
1466
1491
  IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
1467
1492
  IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
1493
+ IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
1468
1494
  PLACEHOLDER_ID,
1469
1495
  EDGE_MIN_CACHE_TTL,
1470
1496
  EDGE_MAX_CACHE_TTL,
@@ -1487,6 +1513,7 @@ export {
1487
1513
  createEventBus,
1488
1514
  getChannelName,
1489
1515
  subscribeToComposition,
1516
+ createUniformApiEnhancer,
1490
1517
  isSystemComponentDefinition,
1491
1518
  mapSlotToPersonalizedVariations,
1492
1519
  mapSlotToTestVariations,
package/dist/cli/cli.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { UniformCLIPlugin } from '@uniformdev/cli';
2
2
  import { UniformPackage } from '@uniformdev/cli/sync';
3
- import { a1 as CanvasDefinitions } from '../createEventBus-fc82f596.js';
3
+ import { a1 as CanvasDefinitions } from '../createEventBus-bd2e0a92.js';
4
4
  import 'pusher-js';
5
5
 
6
6
  type CanvasPackage = UniformPackage & CanvasDefinitions;
package/dist/cli/cli.js CHANGED
@@ -18087,17 +18087,22 @@ async function createArraySyncEngineDataSource({
18087
18087
  }
18088
18088
  var import_chalk = __toESM2(require_source());
18089
18089
  function withApiOptions(yargs) {
18090
- var _a2, _b2, _c2;
18090
+ var _a2, _b2;
18091
18091
  return yargs.option("apiKey", {
18092
- describe: "Uniform API key. Defaults to UNIFORM_CLI_API_KEY or UNIFORM_API_KEY env. Supports dotenv.",
18093
- default: (_c2 = (_b2 = (_a2 = process.env.UNIFORM_CLI_API_KEY) != null ? _a2 : process.env.CANVAS_CLI_API_KEY) != null ? _b2 : process.env.UPM_CLI_API_KEY) != null ? _c2 : process.env.UNIFORM_API_KEY,
18092
+ describe: "Uniform API key. Defaults to CANVAS_CLI_API_KEY or UNIFORM_API_KEY env. Supports dotenv.",
18093
+ default: (_b2 = (_a2 = process.env.CANVAS_CLI_API_KEY) != null ? _a2 : process.env.UPM_CLI_API_KEY) != null ? _b2 : process.env.UNIFORM_API_KEY,
18094
18094
  demandOption: true,
18095
18095
  type: "string"
18096
18096
  }).option("apiHost", {
18097
- describe: "Uniform host. Defaults to UNIFORM_CLI_BASE_URL env or https://uniform.app. Supports dotenv.",
18097
+ describe: "Uniform host. Defaults to UNIFORM_CLI_BASE_URL env var or https://uniform.app. Supports dotenv.",
18098
18098
  default: process.env.UNIFORM_CLI_BASE_URL || "https://uniform.app",
18099
18099
  demandOption: true,
18100
18100
  type: "string"
18101
+ }).option("edgeApiHost", {
18102
+ describe: "Uniform edge host. Defaults to UNIFORM_CLI_BASE_EDGE_URL env var or https://uniform.global. Supports dotenv.",
18103
+ default: process.env.UNIFORM_CLI_BASE_EDGE_URL || "https://uniform.global",
18104
+ demandOption: true,
18105
+ type: "string"
18101
18106
  }).option("proxy", {
18102
18107
  describe: "HTTPS proxy to use for Uniform API calls. Defaults to HTTPS_PROXY, https_proxy, ALL_PROXY, or all_proxy env vars (in that order). Supports dotenv.",
18103
18108
  default: process.env.HTTPS_PROXY || process.env.https_proxy || process.env.ALL_PROXY || process.env.all_proxy,
@@ -18598,17 +18603,19 @@ function createLimitPolicy({
18598
18603
  }
18599
18604
 
18600
18605
  // src/CanvasClient.ts
18606
+ var CANVAS_URL = "/api/v1/canvas";
18601
18607
  var CanvasClient = class extends import_api.ApiClient {
18602
18608
  constructor(options) {
18609
+ var _a2;
18603
18610
  if (!options.limitPolicy) {
18604
18611
  options.limitPolicy = createLimitPolicy({});
18605
18612
  }
18606
18613
  super(options);
18607
- this.canvasUrl = "/api/v1/canvas";
18614
+ this.edgeApiHost = (_a2 = options.edgeApiHost) != null ? _a2 : "https://uniform.global";
18608
18615
  }
18609
18616
  async getCompositionList(options) {
18610
18617
  const { projectId } = this.options;
18611
- const fetchUri = this.createUrl(this.canvasUrl, { ...options, projectId });
18618
+ const fetchUri = this.createUrl(CANVAS_URL, { ...options, projectId });
18612
18619
  return await this.apiClient(fetchUri);
18613
18620
  }
18614
18621
  unstable_getCompositionByNodePath(options) {
@@ -18630,20 +18637,20 @@ var CanvasClient = class extends import_api.ApiClient {
18630
18637
  ...params
18631
18638
  }) {
18632
18639
  const { projectId } = this.options;
18633
- const url = resolveData ? "/api/edge/v1/composition" : this.canvasUrl;
18634
- const dataResolutionParams = {};
18635
- if (resolveData) {
18636
- if (dynamicVariables) {
18637
- dataResolutionParams.dynamicVariables = JSON.stringify(dynamicVariables);
18638
- }
18639
- if (dataDiagnostics) {
18640
- dataResolutionParams.dataDiagnostics = "true";
18641
- }
18640
+ if (!resolveData) {
18641
+ return this.apiClient(this.createUrl(CANVAS_URL, { ...params, projectId }));
18642
18642
  }
18643
- return this.apiClient(this.createUrl(url, { ...params, ...dataResolutionParams, projectId }));
18643
+ const edgeParams = {
18644
+ ...params,
18645
+ projectId,
18646
+ ...dynamicVariables ? { dynamicVariables: JSON.stringify(dynamicVariables) } : {},
18647
+ ...dataDiagnostics ? { dataDiagnostics: "true" } : {}
18648
+ };
18649
+ const edgeUrl = this.createUrl("/api/v1/composition", edgeParams, this.edgeApiHost);
18650
+ return this.apiClient(edgeUrl);
18644
18651
  }
18645
18652
  async updateComposition(body) {
18646
- const fetchUri = this.createUrl("/api/v1/canvas");
18653
+ const fetchUri = this.createUrl(CANVAS_URL);
18647
18654
  await this.apiClient(fetchUri, {
18648
18655
  method: "PUT",
18649
18656
  body: JSON.stringify({ ...body, projectId: this.options.projectId }),
@@ -18651,7 +18658,7 @@ var CanvasClient = class extends import_api.ApiClient {
18651
18658
  });
18652
18659
  }
18653
18660
  async removeComposition(body) {
18654
- const fetchUri = this.createUrl("/api/v1/canvas");
18661
+ const fetchUri = this.createUrl(CANVAS_URL);
18655
18662
  const { projectId } = this.options;
18656
18663
  await this.apiClient(fetchUri, {
18657
18664
  method: "DELETE",
@@ -19146,6 +19153,7 @@ var CompositionGetModule = {
19146
19153
  ),
19147
19154
  handler: async ({
19148
19155
  apiHost,
19156
+ edgeApiHost,
19149
19157
  apiKey,
19150
19158
  proxy,
19151
19159
  id,
@@ -19159,7 +19167,7 @@ var CompositionGetModule = {
19159
19167
  unstableDataDiagnostics
19160
19168
  }) => {
19161
19169
  const fetch2 = nodeFetchProxy(proxy);
19162
- const client = new UncachedCanvasClient({ apiKey, apiHost, fetch: fetch2, projectId });
19170
+ const client = new UncachedCanvasClient({ apiKey, edgeApiHost, apiHost, fetch: fetch2, projectId });
19163
19171
  const res = prepCompositionForDisk(
19164
19172
  await client.getCompositionById({
19165
19173
  compositionId: id,
package/dist/cli/cli.mjs CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  __require,
15
15
  __toCommonJS,
16
16
  __toESM
17
- } from "../chunk-FIKDTGXG.mjs";
17
+ } from "../chunk-RFV573P3.mjs";
18
18
 
19
19
  // ../../node_modules/.pnpm/ms@2.1.2/node_modules/ms/index.js
20
20
  var require_ms = __commonJS({
@@ -17806,17 +17806,22 @@ async function createArraySyncEngineDataSource({
17806
17806
  }
17807
17807
  var import_chalk = __toESM2(require_source());
17808
17808
  function withApiOptions(yargs) {
17809
- var _a2, _b2, _c2;
17809
+ var _a2, _b2;
17810
17810
  return yargs.option("apiKey", {
17811
- describe: "Uniform API key. Defaults to UNIFORM_CLI_API_KEY or UNIFORM_API_KEY env. Supports dotenv.",
17812
- default: (_c2 = (_b2 = (_a2 = process.env.UNIFORM_CLI_API_KEY) != null ? _a2 : process.env.CANVAS_CLI_API_KEY) != null ? _b2 : process.env.UPM_CLI_API_KEY) != null ? _c2 : process.env.UNIFORM_API_KEY,
17811
+ describe: "Uniform API key. Defaults to CANVAS_CLI_API_KEY or UNIFORM_API_KEY env. Supports dotenv.",
17812
+ default: (_b2 = (_a2 = process.env.CANVAS_CLI_API_KEY) != null ? _a2 : process.env.UPM_CLI_API_KEY) != null ? _b2 : process.env.UNIFORM_API_KEY,
17813
17813
  demandOption: true,
17814
17814
  type: "string"
17815
17815
  }).option("apiHost", {
17816
- describe: "Uniform host. Defaults to UNIFORM_CLI_BASE_URL env or https://uniform.app. Supports dotenv.",
17816
+ describe: "Uniform host. Defaults to UNIFORM_CLI_BASE_URL env var or https://uniform.app. Supports dotenv.",
17817
17817
  default: process.env.UNIFORM_CLI_BASE_URL || "https://uniform.app",
17818
17818
  demandOption: true,
17819
17819
  type: "string"
17820
+ }).option("edgeApiHost", {
17821
+ describe: "Uniform edge host. Defaults to UNIFORM_CLI_BASE_EDGE_URL env var or https://uniform.global. Supports dotenv.",
17822
+ default: process.env.UNIFORM_CLI_BASE_EDGE_URL || "https://uniform.global",
17823
+ demandOption: true,
17824
+ type: "string"
17820
17825
  }).option("proxy", {
17821
17826
  describe: "HTTPS proxy to use for Uniform API calls. Defaults to HTTPS_PROXY, https_proxy, ALL_PROXY, or all_proxy env vars (in that order). Supports dotenv.",
17822
17827
  default: process.env.HTTPS_PROXY || process.env.https_proxy || process.env.ALL_PROXY || process.env.all_proxy,
@@ -18591,6 +18596,7 @@ var CompositionGetModule = {
18591
18596
  ),
18592
18597
  handler: async ({
18593
18598
  apiHost,
18599
+ edgeApiHost,
18594
18600
  apiKey,
18595
18601
  proxy,
18596
18602
  id,
@@ -18604,7 +18610,7 @@ var CompositionGetModule = {
18604
18610
  unstableDataDiagnostics
18605
18611
  }) => {
18606
18612
  const fetch2 = nodeFetchProxy(proxy);
18607
- const client = new UncachedCanvasClient({ apiKey, apiHost, fetch: fetch2, projectId });
18613
+ const client = new UncachedCanvasClient({ apiKey, edgeApiHost, apiHost, fetch: fetch2, projectId });
18608
18614
  const res = prepCompositionForDisk(
18609
18615
  await client.getCompositionById({
18610
18616
  compositionId: id,
@@ -2568,14 +2568,8 @@ interface paths$2 {
2568
2568
  data: external$2["uniform-canvas-types.swagger.yml"]["components"]["schemas"]["DataSource"];
2569
2569
  /** Format: uuid */
2570
2570
  projectId: string;
2571
- /**
2572
- * Format: uuid
2573
- * @deprecated
2574
- * @description Do not use. Will be removed in future.
2575
- */
2576
- integrationId?: string;
2577
- /** @description The integration type that the data source is attached to. Must be installed in the project. */
2578
- integrationType?: string;
2571
+ /** Format: uuid */
2572
+ integrationId: string;
2579
2573
  };
2580
2574
  };
2581
2575
  };
package/dist/index.d.ts CHANGED
@@ -1,15 +1,18 @@
1
1
  import { ApiClient, ClientOptions, ExceptProject, ApiClientError } from '@uniformdev/context/api';
2
2
  export { ApiClientError } from '@uniformdev/context/api';
3
- import { C as CompositionGetParameters, a as CompositionGetByNodePathParameters, D as DataResolutionOptionNegative, b as CompositionGetResponse, c as DataResolutionOptionPositive, d as DataResolutionParameters, e as CompositionResolvedGetResponse, f as CompositionGetValidResponses, g as DataResolutionOption, h as CompositionGetByNodeIdParameters, i as CompositionGetBySlugParameters, j as CompositionGetByIdParameters, k as CompositionPutParameters, l as CompositionDeleteParameters, m as ComponentDefinitionGetParameters, n as ComponentDefinitionPutParameters, o as ComponentDefinitionDeleteParameters, p as ComponentInstance, q as ComponentParameter, r as components, s as DataSourceGetParameters, t as DataSourcesGetParameters, u as DataSourcePutParameters, v as DataSourceDeleteParameters, w as DataTypeGetParameters, x as DataTypeGetResponse, y as DataTypePutParameters, z as DataTypeDeleteParameters, R as RootComponentInstance, P as PreviewEventBus } from './createEventBus-fc82f596.js';
4
- export { a1 as CanvasDefinitions, A as ChannelSubscription, O as ComponentDefinition, H as ComponentDefinitionAPIDeleteRequest, G as ComponentDefinitionAPIPutRequest, F as ComponentDefinitionAPIResponse, o as ComponentDefinitionDeleteParameters, m as ComponentDefinitionGetParameters, E as ComponentDefinitionGetResponse, I as ComponentDefinitionListAPIOptions, J as ComponentDefinitionParameter, N as ComponentDefinitionPermission, n as ComponentDefinitionPutParameters, M as ComponentDefinitionSlot, L as ComponentDefinitionSlugSettings, K as ComponentDefinitionVariant, p as ComponentInstance, q as ComponentParameter, W as CompositionAPIDeleteRequest, Y as CompositionAPIOptions, V as CompositionAPIResponse, a8 as CompositionDataDiagnostic, l as CompositionDeleteParameters, j as CompositionGetByIdParameters, h as CompositionGetByNodeIdParameters, a as CompositionGetByNodePathParameters, i as CompositionGetBySlugParameters, U as CompositionGetListResponse, S as CompositionGetOrderBy, C as CompositionGetParameters, b as CompositionGetResponse, f as CompositionGetValidResponses, a2 as CompositionIssue, X as CompositionListAPIResponse, a3 as CompositionPatternIssue, k as CompositionPutParameters, e as CompositionResolvedGetResponse, T as CompositionUIStatus, Q as CreatingComponentDefinition, a4 as DataElementBindingIssue, Z as DataElementConnectionDefinition, a7 as DataResolutionConfigIssue, g as DataResolutionOption, D as DataResolutionOptionNegative, c as DataResolutionOptionPositive, d as DataResolutionParameters, a0 as DataResourceDefinition, $ as DataResourceDefinitions, a5 as DataResourceIssue, a6 as DataResourceVariableIssue, _ as DataResourceVariables, ac as DataSource, v as DataSourceDeleteParameters, s as DataSourceGetParameters, a9 as DataSourceGetResponse, u as DataSourcePutParameters, t as DataSourcesGetParameters, aa as DataSourcesGetResponse, ab as DataType, z as DataTypeDeleteParameters, w as DataTypeGetParameters, x as DataTypeGetResponse, y as DataTypePutParameters, ad as DataVariableDefinition, P as PreviewEventBus, R as RootComponentInstance, B as createEventBus } from './createEventBus-fc82f596.js';
3
+ import { C as CompositionGetParameters, a as CompositionGetByNodePathParameters, D as DataResolutionOptionNegative, b as CompositionGetResponse, c as DataResolutionOptionPositive, d as DataResolutionParameters, e as CompositionResolvedGetResponse, f as CompositionGetValidResponses, g as DataResolutionOption, h as CompositionGetByNodeIdParameters, i as CompositionGetBySlugParameters, j as CompositionGetByIdParameters, k as CompositionPutParameters, l as CompositionDeleteParameters, m as ComponentDefinitionGetParameters, n as ComponentDefinitionPutParameters, o as ComponentDefinitionDeleteParameters, p as ComponentInstance, q as ComponentParameter, r as components, s as DataSourceGetParameters, t as DataSourcesGetParameters, u as DataSourcePutParameters, v as DataSourceDeleteParameters, w as DataTypeGetParameters, x as DataTypeGetResponse, y as DataTypePutParameters, z as DataTypeDeleteParameters, R as RootComponentInstance, P as PreviewEventBus } from './createEventBus-bd2e0a92.js';
4
+ export { a1 as CanvasDefinitions, A as ChannelSubscription, O as ComponentDefinition, H as ComponentDefinitionAPIDeleteRequest, G as ComponentDefinitionAPIPutRequest, F as ComponentDefinitionAPIResponse, o as ComponentDefinitionDeleteParameters, m as ComponentDefinitionGetParameters, E as ComponentDefinitionGetResponse, I as ComponentDefinitionListAPIOptions, J as ComponentDefinitionParameter, N as ComponentDefinitionPermission, n as ComponentDefinitionPutParameters, M as ComponentDefinitionSlot, L as ComponentDefinitionSlugSettings, K as ComponentDefinitionVariant, p as ComponentInstance, q as ComponentParameter, W as CompositionAPIDeleteRequest, Y as CompositionAPIOptions, V as CompositionAPIResponse, a8 as CompositionDataDiagnostic, l as CompositionDeleteParameters, j as CompositionGetByIdParameters, h as CompositionGetByNodeIdParameters, a as CompositionGetByNodePathParameters, i as CompositionGetBySlugParameters, U as CompositionGetListResponse, S as CompositionGetOrderBy, C as CompositionGetParameters, b as CompositionGetResponse, f as CompositionGetValidResponses, a2 as CompositionIssue, X as CompositionListAPIResponse, a3 as CompositionPatternIssue, k as CompositionPutParameters, e as CompositionResolvedGetResponse, T as CompositionUIStatus, Q as CreatingComponentDefinition, a4 as DataElementBindingIssue, Z as DataElementConnectionDefinition, a7 as DataResolutionConfigIssue, g as DataResolutionOption, D as DataResolutionOptionNegative, c as DataResolutionOptionPositive, d as DataResolutionParameters, a0 as DataResourceDefinition, $ as DataResourceDefinitions, a5 as DataResourceIssue, a6 as DataResourceVariableIssue, _ as DataResourceVariables, ac as DataSource, v as DataSourceDeleteParameters, s as DataSourceGetParameters, a9 as DataSourceGetResponse, u as DataSourcePutParameters, t as DataSourcesGetParameters, aa as DataSourcesGetResponse, ab as DataType, z as DataTypeDeleteParameters, w as DataTypeGetParameters, x as DataTypeGetResponse, y as DataTypePutParameters, ad as DataVariableDefinition, P as PreviewEventBus, R as RootComponentInstance, B as createEventBus } from './createEventBus-bd2e0a92.js';
5
5
  import { Options as Options$1 } from 'p-retry';
6
6
  import { Options } from 'p-throttle';
7
7
  import { PersonalizedVariant, TestVariant } from '@uniformdev/context';
8
8
  import 'pusher-js';
9
9
 
10
- declare class CanvasClient extends ApiClient<ClientOptions> {
11
- constructor(options: ClientOptions);
12
- private canvasUrl;
10
+ type CanvasClientOptions = ClientOptions & {
11
+ edgeApiHost?: string;
12
+ };
13
+ declare class CanvasClient extends ApiClient<CanvasClientOptions> {
14
+ private edgeApiHost;
15
+ constructor(options: CanvasClientOptions);
13
16
  /** Fetches lists of Canvas compositions, optionally by type */
14
17
  getCompositionList(options?: Omit<CompositionGetParameters, 'projectId' | 'compositionId' | 'slug'>): Promise<{
15
18
  compositions: {
@@ -199,7 +202,7 @@ declare class CanvasClient extends ApiClient<ClientOptions> {
199
202
  removeComponentDefinition(body: Omit<ComponentDefinitionDeleteParameters, 'projectId'>): Promise<void>;
200
203
  }
201
204
  declare class UncachedCanvasClient extends CanvasClient {
202
- constructor(options: Omit<ClientOptions, 'bypassCache'>);
205
+ constructor(options: Omit<CanvasClientOptions, 'bypassCache'>);
203
206
  }
204
207
 
205
208
  type EnhancerContext = {
@@ -656,8 +659,10 @@ declare const CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
656
659
  declare const CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
657
660
  /** The name of the query string used to detect if we are in in-context editing mode */
658
661
  declare const IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
659
- /** The value of "data-role" in the component start <script> tag */
662
+ /** The value of "data-role" in the component start `<script>` tag */
660
663
  declare const IN_CONTEXT_EDITOR_COMPONENT_START_ROLE = "uniform-component-start";
664
+ /** The ID of the Contextual Editing script that gets embedded in frontend apps */
665
+ declare const IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID = "uniform-canvas-preview-script";
661
666
  /** The ID we give to placeholder components */
662
667
  declare const PLACEHOLDER_ID = "placeholder";
663
668
  /** Minimal value for Edgehancers Cache TTL (in seconds) */
@@ -675,6 +680,88 @@ declare const EDGE_MAX_L2_CACHE_TTL_IN_HOURS: number;
675
680
  /** Default value for Edgehancers Long Term Cache TTL (in hours) */
676
681
  declare const EDGE_DEFAULT_L2_CACHE_TTL_IN_HOURS = 24;
677
682
 
683
+ /**
684
+ * Creates an enhancer based on an API route.
685
+ * This is mainly used to create an enhancer for Contextual Editing, which can be passed to the `contextualEditingEnhancer` prop of `<UniformComposition />`.
686
+ *
687
+ * @example
688
+ * ```ts
689
+ * const enhance = createUniformApiEnhancer({
690
+ * apiUrl: '/api/preview',
691
+ * });
692
+ * ```
693
+ */
694
+ declare const createUniformApiEnhancer: ({ apiUrl }: {
695
+ apiUrl: string;
696
+ }) => (message: UpdateCompositionMessage) => Promise<{
697
+ type: string;
698
+ parameters?: {
699
+ [key: string]: {
700
+ value: unknown;
701
+ type: string;
702
+ connectedData?: {
703
+ pointer: string;
704
+ syntax: "jptr";
705
+ required?: boolean | undefined;
706
+ } | undefined;
707
+ };
708
+ } | undefined;
709
+ variant?: string | undefined;
710
+ slots?: {
711
+ [key: string]: {
712
+ type: string;
713
+ parameters?: {
714
+ [key: string]: {
715
+ value: unknown;
716
+ type: string;
717
+ connectedData?: {
718
+ pointer: string;
719
+ syntax: "jptr";
720
+ required?: boolean | undefined;
721
+ } | undefined;
722
+ };
723
+ } | undefined;
724
+ variant?: string | undefined;
725
+ slots?: {
726
+ [key: string]: any[];
727
+ } | undefined;
728
+ _id?: string | undefined;
729
+ _pattern?: string | undefined;
730
+ _dataResources?: {
731
+ [key: string]: {
732
+ type: string;
733
+ isPatternParameter?: boolean | undefined;
734
+ variables?: {
735
+ [key: string]: string;
736
+ } | undefined;
737
+ };
738
+ } | undefined;
739
+ _patternDataResources?: {
740
+ [key: string]: {
741
+ type: string;
742
+ isPatternParameter?: boolean | undefined;
743
+ variables?: {
744
+ [key: string]: string;
745
+ } | undefined;
746
+ };
747
+ } | undefined;
748
+ _patternError?: "NOTFOUND" | "CYCLIC" | undefined;
749
+ }[];
750
+ } | undefined;
751
+ _id: string;
752
+ _slug?: string | null | undefined;
753
+ _name: string;
754
+ _dataResources?: {
755
+ [key: string]: {
756
+ type: string;
757
+ isPatternParameter?: boolean | undefined;
758
+ variables?: {
759
+ [key: string]: string;
760
+ } | undefined;
761
+ };
762
+ } | undefined;
763
+ }>;
764
+
678
765
  declare const generateHash: ({ composition, secret, }: {
679
766
  composition: RootComponentInstance;
680
767
  secret: string | undefined;
@@ -697,4 +784,4 @@ declare function mapSlotToTestVariations(slot: ComponentInstance[] | undefined):
697
784
 
698
785
  declare const CanvasClientError: typeof ApiClientError;
699
786
 
700
- export { AddComponentMessage, BatchEnhancer, BatchEntry, CANVAS_DRAFT_STATE, CANVAS_ENRICHMENT_TAG_PARAM, CANVAS_INTENT_TAG_PARAM, CANVAS_LOCALE_TAG_PARAM, CANVAS_LOCALIZATION_SLOT, CANVAS_LOCALIZATION_TYPE, CANVAS_PERSONALIZATION_PARAM, CANVAS_PERSONALIZE_SLOT, CANVAS_PERSONALIZE_TYPE, CANVAS_PUBLISHED_STATE, CANVAS_TEST_SLOT, CANVAS_TEST_TYPE, CANVAS_TEST_VARIANT_PARAM, CanvasClient, CanvasClientError, Channel, ChannelMessage, ChildEnhancerBuilder, ComponentEnhancer, ComponentEnhancerFunction, ComponentEnhancerOptions, ComponentLocationReference, ComponentParameterEnhancer, ComponentParameterEnhancerFunction, ComponentParameterEnhancerOptions, DataSourceClient, DataTypeClient, DismissPlaceholderMessage, EDGE_CACHE_DISABLED, EDGE_DEFAULT_CACHE_TTL, EDGE_DEFAULT_L2_CACHE_TTL_IN_HOURS, EDGE_MAX_CACHE_TTL, EDGE_MAX_L2_CACHE_TTL_IN_HOURS, EDGE_MIN_CACHE_TTL, EDGE_MIN_L2_CACHE_TTL_IN_HOURS, EnhancerBuilder, EnhancerContext, EnhancerError, EventNames, IN_CONTEXT_EDITOR_COMPONENT_START_ROLE, IN_CONTEXT_EDITOR_QUERY_STRING_PARAM, InvalidationInput, InvalidationPayload, InvalidationResult, LimitPolicy, MessageHandler, MoveComponentMessage, PLACEHOLDER_ID, ReadyMessage, SelectComponentMessage, SubscribeToCompositionOptions, UncachedCanvasClient, UniqueBatchEntries, UnsubscribeCallback, UpdateCompositionMessage, WalkComponentTreeActions, compose, createBatchEnhancer, createCanvasChannel, createLimitPolicy, enhance, extractLocales, generateHash, getChannelName, getComponentJsonPointer, getComponentPath, isAddComponentMessage, isDismissPlaceholderMessage, isMovingComponentMessage, isReadyMessage, isSelectComponentMessage, isSystemComponentDefinition, isUpdateCompositionMessage, localize, mapSlotToPersonalizedVariations, mapSlotToTestVariations, nullLimitPolicy, subscribeToComposition, walkComponentTree };
787
+ export { AddComponentMessage, BatchEnhancer, BatchEntry, CANVAS_DRAFT_STATE, CANVAS_ENRICHMENT_TAG_PARAM, CANVAS_INTENT_TAG_PARAM, CANVAS_LOCALE_TAG_PARAM, CANVAS_LOCALIZATION_SLOT, CANVAS_LOCALIZATION_TYPE, CANVAS_PERSONALIZATION_PARAM, CANVAS_PERSONALIZE_SLOT, CANVAS_PERSONALIZE_TYPE, CANVAS_PUBLISHED_STATE, CANVAS_TEST_SLOT, CANVAS_TEST_TYPE, CANVAS_TEST_VARIANT_PARAM, CanvasClient, CanvasClientError, Channel, ChannelMessage, ChildEnhancerBuilder, ComponentEnhancer, ComponentEnhancerFunction, ComponentEnhancerOptions, ComponentLocationReference, ComponentParameterEnhancer, ComponentParameterEnhancerFunction, ComponentParameterEnhancerOptions, DataSourceClient, DataTypeClient, DismissPlaceholderMessage, EDGE_CACHE_DISABLED, EDGE_DEFAULT_CACHE_TTL, EDGE_DEFAULT_L2_CACHE_TTL_IN_HOURS, EDGE_MAX_CACHE_TTL, EDGE_MAX_L2_CACHE_TTL_IN_HOURS, EDGE_MIN_CACHE_TTL, EDGE_MIN_L2_CACHE_TTL_IN_HOURS, EnhancerBuilder, EnhancerContext, EnhancerError, EventNames, IN_CONTEXT_EDITOR_COMPONENT_START_ROLE, IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID, IN_CONTEXT_EDITOR_QUERY_STRING_PARAM, InvalidationInput, InvalidationPayload, InvalidationResult, LimitPolicy, MessageHandler, MoveComponentMessage, PLACEHOLDER_ID, ReadyMessage, SelectComponentMessage, SubscribeToCompositionOptions, UncachedCanvasClient, UniqueBatchEntries, UnsubscribeCallback, UpdateCompositionMessage, WalkComponentTreeActions, compose, createBatchEnhancer, createCanvasChannel, createLimitPolicy, createUniformApiEnhancer, enhance, extractLocales, generateHash, getChannelName, getComponentJsonPointer, getComponentPath, isAddComponentMessage, isDismissPlaceholderMessage, isMovingComponentMessage, isReadyMessage, isSelectComponentMessage, isSystemComponentDefinition, isUpdateCompositionMessage, localize, mapSlotToPersonalizedVariations, mapSlotToTestVariations, nullLimitPolicy, subscribeToComposition, walkComponentTree };
package/dist/index.esm.js CHANGED
@@ -28,6 +28,7 @@ import {
28
28
  EDGE_MIN_L2_CACHE_TTL_IN_HOURS,
29
29
  EnhancerBuilder,
30
30
  IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
31
+ IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
31
32
  IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
32
33
  PLACEHOLDER_ID,
33
34
  UncachedCanvasClient,
@@ -37,6 +38,7 @@ import {
37
38
  createCanvasChannel,
38
39
  createEventBus,
39
40
  createLimitPolicy,
41
+ createUniformApiEnhancer,
40
42
  enhance,
41
43
  extractLocales,
42
44
  generateHash,
@@ -56,7 +58,7 @@ import {
56
58
  nullLimitPolicy,
57
59
  subscribeToComposition,
58
60
  walkComponentTree
59
- } from "./chunk-FIKDTGXG.mjs";
61
+ } from "./chunk-RFV573P3.mjs";
60
62
  export {
61
63
  ApiClientError,
62
64
  BatchEntry,
@@ -87,6 +89,7 @@ export {
87
89
  EDGE_MIN_L2_CACHE_TTL_IN_HOURS,
88
90
  EnhancerBuilder,
89
91
  IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
92
+ IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
90
93
  IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
91
94
  PLACEHOLDER_ID,
92
95
  UncachedCanvasClient,
@@ -96,6 +99,7 @@ export {
96
99
  createCanvasChannel,
97
100
  createEventBus,
98
101
  createLimitPolicy,
102
+ createUniformApiEnhancer,
99
103
  enhance,
100
104
  extractLocales,
101
105
  generateHash,
package/dist/index.js CHANGED
@@ -299,6 +299,7 @@ __export(src_exports, {
299
299
  EDGE_MIN_L2_CACHE_TTL_IN_HOURS: () => EDGE_MIN_L2_CACHE_TTL_IN_HOURS,
300
300
  EnhancerBuilder: () => EnhancerBuilder,
301
301
  IN_CONTEXT_EDITOR_COMPONENT_START_ROLE: () => IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
302
+ IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID: () => IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
302
303
  IN_CONTEXT_EDITOR_QUERY_STRING_PARAM: () => IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
303
304
  PLACEHOLDER_ID: () => PLACEHOLDER_ID,
304
305
  UncachedCanvasClient: () => UncachedCanvasClient,
@@ -308,6 +309,7 @@ __export(src_exports, {
308
309
  createCanvasChannel: () => createCanvasChannel,
309
310
  createEventBus: () => createEventBus,
310
311
  createLimitPolicy: () => createLimitPolicy,
312
+ createUniformApiEnhancer: () => createUniformApiEnhancer,
311
313
  enhance: () => enhance,
312
314
  extractLocales: () => extractLocales,
313
315
  generateHash: () => generateHash,
@@ -511,17 +513,19 @@ function createLimitPolicy({
511
513
  var nullLimitPolicy = async (func) => await func();
512
514
 
513
515
  // src/CanvasClient.ts
516
+ var CANVAS_URL = "/api/v1/canvas";
514
517
  var CanvasClient = class extends import_api.ApiClient {
515
518
  constructor(options) {
519
+ var _a;
516
520
  if (!options.limitPolicy) {
517
521
  options.limitPolicy = createLimitPolicy({});
518
522
  }
519
523
  super(options);
520
- this.canvasUrl = "/api/v1/canvas";
524
+ this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
521
525
  }
522
526
  async getCompositionList(options) {
523
527
  const { projectId } = this.options;
524
- const fetchUri = this.createUrl(this.canvasUrl, { ...options, projectId });
528
+ const fetchUri = this.createUrl(CANVAS_URL, { ...options, projectId });
525
529
  return await this.apiClient(fetchUri);
526
530
  }
527
531
  unstable_getCompositionByNodePath(options) {
@@ -543,20 +547,20 @@ var CanvasClient = class extends import_api.ApiClient {
543
547
  ...params
544
548
  }) {
545
549
  const { projectId } = this.options;
546
- const url = resolveData ? "/api/edge/v1/composition" : this.canvasUrl;
547
- const dataResolutionParams = {};
548
- if (resolveData) {
549
- if (dynamicVariables) {
550
- dataResolutionParams.dynamicVariables = JSON.stringify(dynamicVariables);
551
- }
552
- if (dataDiagnostics) {
553
- dataResolutionParams.dataDiagnostics = "true";
554
- }
550
+ if (!resolveData) {
551
+ return this.apiClient(this.createUrl(CANVAS_URL, { ...params, projectId }));
555
552
  }
556
- return this.apiClient(this.createUrl(url, { ...params, ...dataResolutionParams, projectId }));
553
+ const edgeParams = {
554
+ ...params,
555
+ projectId,
556
+ ...dynamicVariables ? { dynamicVariables: JSON.stringify(dynamicVariables) } : {},
557
+ ...dataDiagnostics ? { dataDiagnostics: "true" } : {}
558
+ };
559
+ const edgeUrl = this.createUrl("/api/v1/composition", edgeParams, this.edgeApiHost);
560
+ return this.apiClient(edgeUrl);
557
561
  }
558
562
  async updateComposition(body) {
559
- const fetchUri = this.createUrl("/api/v1/canvas");
563
+ const fetchUri = this.createUrl(CANVAS_URL);
560
564
  await this.apiClient(fetchUri, {
561
565
  method: "PUT",
562
566
  body: JSON.stringify({ ...body, projectId: this.options.projectId }),
@@ -564,7 +568,7 @@ var CanvasClient = class extends import_api.ApiClient {
564
568
  });
565
569
  }
566
570
  async removeComposition(body) {
567
- const fetchUri = this.createUrl("/api/v1/canvas");
571
+ const fetchUri = this.createUrl(CANVAS_URL);
568
572
  const { projectId } = this.options;
569
573
  await this.apiClient(fetchUri, {
570
574
  method: "DELETE",
@@ -1127,6 +1131,7 @@ var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
1127
1131
  var CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
1128
1132
  var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1129
1133
  var IN_CONTEXT_EDITOR_COMPONENT_START_ROLE = "uniform-component-start";
1134
+ var IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID = "uniform-canvas-preview-script";
1130
1135
  var PLACEHOLDER_ID = "placeholder";
1131
1136
  var EDGE_MIN_CACHE_TTL = 15;
1132
1137
  var EDGE_MAX_CACHE_TTL = 600;
@@ -1419,6 +1424,28 @@ function subscribeToComposition({
1419
1424
  };
1420
1425
  }
1421
1426
 
1427
+ // src/utils/createApiEnhancer.ts
1428
+ var createUniformApiEnhancer = ({ apiUrl }) => {
1429
+ return async (message) => {
1430
+ const response = await fetch(apiUrl, {
1431
+ method: "post",
1432
+ body: JSON.stringify({
1433
+ composition: message.composition,
1434
+ hash: message.hash
1435
+ }),
1436
+ headers: {
1437
+ "Content-Type": "application/json"
1438
+ }
1439
+ });
1440
+ const json = await response.json();
1441
+ if (!response.ok) {
1442
+ throw new Error("Error reading enhanced composition");
1443
+ }
1444
+ const body = json;
1445
+ return body.composition;
1446
+ };
1447
+ };
1448
+
1422
1449
  // src/utils/isSystemComponentDefinition.ts
1423
1450
  var isSystemComponentDefinition = (componentType) => {
1424
1451
  return componentType.startsWith("$");
@@ -1489,6 +1516,7 @@ var CanvasClientError = import_api4.ApiClientError;
1489
1516
  EDGE_MIN_L2_CACHE_TTL_IN_HOURS,
1490
1517
  EnhancerBuilder,
1491
1518
  IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
1519
+ IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
1492
1520
  IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
1493
1521
  PLACEHOLDER_ID,
1494
1522
  UncachedCanvasClient,
@@ -1498,6 +1526,7 @@ var CanvasClientError = import_api4.ApiClientError;
1498
1526
  createCanvasChannel,
1499
1527
  createEventBus,
1500
1528
  createLimitPolicy,
1529
+ createUniformApiEnhancer,
1501
1530
  enhance,
1502
1531
  extractLocales,
1503
1532
  generateHash,
package/dist/index.mjs CHANGED
@@ -28,6 +28,7 @@ import {
28
28
  EDGE_MIN_L2_CACHE_TTL_IN_HOURS,
29
29
  EnhancerBuilder,
30
30
  IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
31
+ IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
31
32
  IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
32
33
  PLACEHOLDER_ID,
33
34
  UncachedCanvasClient,
@@ -37,6 +38,7 @@ import {
37
38
  createCanvasChannel,
38
39
  createEventBus,
39
40
  createLimitPolicy,
41
+ createUniformApiEnhancer,
40
42
  enhance,
41
43
  extractLocales,
42
44
  generateHash,
@@ -56,7 +58,7 @@ import {
56
58
  nullLimitPolicy,
57
59
  subscribeToComposition,
58
60
  walkComponentTree
59
- } from "./chunk-FIKDTGXG.mjs";
61
+ } from "./chunk-RFV573P3.mjs";
60
62
  export {
61
63
  ApiClientError,
62
64
  BatchEntry,
@@ -87,6 +89,7 @@ export {
87
89
  EDGE_MIN_L2_CACHE_TTL_IN_HOURS,
88
90
  EnhancerBuilder,
89
91
  IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
92
+ IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
90
93
  IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
91
94
  PLACEHOLDER_ID,
92
95
  UncachedCanvasClient,
@@ -96,6 +99,7 @@ export {
96
99
  createCanvasChannel,
97
100
  createEventBus,
98
101
  createLimitPolicy,
102
+ createUniformApiEnhancer,
99
103
  enhance,
100
104
  extractLocales,
101
105
  generateHash,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas",
3
- "version": "18.1.1-alpha.11+c81a052e2",
3
+ "version": "18.1.2-alpha.7+682b9aac6",
4
4
  "description": "Common functionality and types for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -48,16 +48,16 @@
48
48
  },
49
49
  "devDependencies": {
50
50
  "@types/retry": "0.12.1",
51
- "@types/yargs": "17.0.19",
52
- "@uniformdev/cli": "18.1.1-alpha.11+c81a052e2",
51
+ "@types/yargs": "17.0.20",
52
+ "@uniformdev/cli": "18.1.2-alpha.7+682b9aac6",
53
53
  "p-limit": "4.0.0",
54
54
  "p-retry": "5.1.2",
55
55
  "p-throttle": "5.0.0",
56
- "pusher-js": "8.0.0",
56
+ "pusher-js": "8.0.1",
57
57
  "yargs": "17.6.2"
58
58
  },
59
59
  "dependencies": {
60
- "@uniformdev/context": "18.1.1-alpha.11+c81a052e2"
60
+ "@uniformdev/context": "18.1.2-alpha.7+682b9aac6"
61
61
  },
62
62
  "files": [
63
63
  "/dist"
@@ -65,5 +65,5 @@
65
65
  "publishConfig": {
66
66
  "access": "public"
67
67
  },
68
- "gitHead": "c81a052e2c13c6d3d786d7030f11a7724a52b2da"
68
+ "gitHead": "682b9aac6143d5f462a7126f4ceab55a7c7d0c09"
69
69
  }