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

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.
@@ -1091,6 +1091,7 @@ var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
1091
1091
  var CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
1092
1092
  var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1093
1093
  var IN_CONTEXT_EDITOR_COMPONENT_START_ROLE = "uniform-component-start";
1094
+ var IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID = "uniform-canvas-preview-script";
1094
1095
  var PLACEHOLDER_ID = "placeholder";
1095
1096
  var EDGE_MIN_CACHE_TTL = 15;
1096
1097
  var EDGE_MAX_CACHE_TTL = 600;
@@ -1383,6 +1384,28 @@ function subscribeToComposition({
1383
1384
  };
1384
1385
  }
1385
1386
 
1387
+ // src/utils/createApiEnhancer.ts
1388
+ var createUniformApiEnhancer = ({ apiUrl }) => {
1389
+ return async (message) => {
1390
+ const response = await fetch(apiUrl, {
1391
+ method: "post",
1392
+ body: JSON.stringify({
1393
+ composition: message.composition,
1394
+ hash: message.hash
1395
+ }),
1396
+ headers: {
1397
+ "Content-Type": "application/json"
1398
+ }
1399
+ });
1400
+ const json = await response.json();
1401
+ if (!response.ok) {
1402
+ throw new Error("Error reading enhanced composition");
1403
+ }
1404
+ const body = json;
1405
+ return body.composition;
1406
+ };
1407
+ };
1408
+
1386
1409
  // src/utils/isSystemComponentDefinition.ts
1387
1410
  var isSystemComponentDefinition = (componentType) => {
1388
1411
  return componentType.startsWith("$");
@@ -1465,6 +1488,7 @@ export {
1465
1488
  CANVAS_ENRICHMENT_TAG_PARAM,
1466
1489
  IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
1467
1490
  IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
1491
+ IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
1468
1492
  PLACEHOLDER_ID,
1469
1493
  EDGE_MIN_CACHE_TTL,
1470
1494
  EDGE_MAX_CACHE_TTL,
@@ -1487,6 +1511,7 @@ export {
1487
1511
  createEventBus,
1488
1512
  getChannelName,
1489
1513
  subscribeToComposition,
1514
+ createUniformApiEnhancer,
1490
1515
  isSystemComponentDefinition,
1491
1516
  mapSlotToPersonalizedVariations,
1492
1517
  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,10 +18087,10 @@ 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", {
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-D45SO56S.mjs";
18
18
 
19
19
  // ../../node_modules/.pnpm/ms@2.1.2/node_modules/ms/index.js
20
20
  var require_ms = __commonJS({
@@ -17806,10 +17806,10 @@ 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", {
@@ -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,7 +1,7 @@
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';
@@ -656,8 +656,10 @@ declare const CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
656
656
  declare const CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
657
657
  /** The name of the query string used to detect if we are in in-context editing mode */
658
658
  declare const IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
659
- /** The value of "data-role" in the component start <script> tag */
659
+ /** The value of "data-role" in the component start `<script>` tag */
660
660
  declare const IN_CONTEXT_EDITOR_COMPONENT_START_ROLE = "uniform-component-start";
661
+ /** The ID of the Contextual Editing script that gets embedded in frontend apps */
662
+ declare const IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID = "uniform-canvas-preview-script";
661
663
  /** The ID we give to placeholder components */
662
664
  declare const PLACEHOLDER_ID = "placeholder";
663
665
  /** Minimal value for Edgehancers Cache TTL (in seconds) */
@@ -675,6 +677,88 @@ declare const EDGE_MAX_L2_CACHE_TTL_IN_HOURS: number;
675
677
  /** Default value for Edgehancers Long Term Cache TTL (in hours) */
676
678
  declare const EDGE_DEFAULT_L2_CACHE_TTL_IN_HOURS = 24;
677
679
 
680
+ /**
681
+ * Creates an enhancer based on an API route.
682
+ * This is mainly used to create an enhancer for Contextual Editing, which can be passed to the `contextualEditingEnhancer` prop of `<UniformComposition />`.
683
+ *
684
+ * @example
685
+ * ```ts
686
+ * const enhance = createUniformApiEnhancer({
687
+ * apiUrl: '/api/preview',
688
+ * });
689
+ * ```
690
+ */
691
+ declare const createUniformApiEnhancer: ({ apiUrl }: {
692
+ apiUrl: string;
693
+ }) => (message: UpdateCompositionMessage) => Promise<{
694
+ type: string;
695
+ parameters?: {
696
+ [key: string]: {
697
+ value: unknown;
698
+ type: string;
699
+ connectedData?: {
700
+ pointer: string;
701
+ syntax: "jptr";
702
+ required?: boolean | undefined;
703
+ } | undefined;
704
+ };
705
+ } | undefined;
706
+ variant?: string | undefined;
707
+ slots?: {
708
+ [key: string]: {
709
+ type: string;
710
+ parameters?: {
711
+ [key: string]: {
712
+ value: unknown;
713
+ type: string;
714
+ connectedData?: {
715
+ pointer: string;
716
+ syntax: "jptr";
717
+ required?: boolean | undefined;
718
+ } | undefined;
719
+ };
720
+ } | undefined;
721
+ variant?: string | undefined;
722
+ slots?: {
723
+ [key: string]: any[];
724
+ } | undefined;
725
+ _id?: string | undefined;
726
+ _pattern?: string | undefined;
727
+ _dataResources?: {
728
+ [key: string]: {
729
+ type: string;
730
+ isPatternParameter?: boolean | undefined;
731
+ variables?: {
732
+ [key: string]: string;
733
+ } | undefined;
734
+ };
735
+ } | undefined;
736
+ _patternDataResources?: {
737
+ [key: string]: {
738
+ type: string;
739
+ isPatternParameter?: boolean | undefined;
740
+ variables?: {
741
+ [key: string]: string;
742
+ } | undefined;
743
+ };
744
+ } | undefined;
745
+ _patternError?: "NOTFOUND" | "CYCLIC" | undefined;
746
+ }[];
747
+ } | undefined;
748
+ _id: string;
749
+ _slug?: string | null | undefined;
750
+ _name: string;
751
+ _dataResources?: {
752
+ [key: string]: {
753
+ type: string;
754
+ isPatternParameter?: boolean | undefined;
755
+ variables?: {
756
+ [key: string]: string;
757
+ } | undefined;
758
+ };
759
+ } | undefined;
760
+ }>;
761
+
678
762
  declare const generateHash: ({ composition, secret, }: {
679
763
  composition: RootComponentInstance;
680
764
  secret: string | undefined;
@@ -697,4 +781,4 @@ declare function mapSlotToTestVariations(slot: ComponentInstance[] | undefined):
697
781
 
698
782
  declare const CanvasClientError: typeof ApiClientError;
699
783
 
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 };
784
+ 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-D45SO56S.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,
@@ -1127,6 +1129,7 @@ var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
1127
1129
  var CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
1128
1130
  var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1129
1131
  var IN_CONTEXT_EDITOR_COMPONENT_START_ROLE = "uniform-component-start";
1132
+ var IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID = "uniform-canvas-preview-script";
1130
1133
  var PLACEHOLDER_ID = "placeholder";
1131
1134
  var EDGE_MIN_CACHE_TTL = 15;
1132
1135
  var EDGE_MAX_CACHE_TTL = 600;
@@ -1419,6 +1422,28 @@ function subscribeToComposition({
1419
1422
  };
1420
1423
  }
1421
1424
 
1425
+ // src/utils/createApiEnhancer.ts
1426
+ var createUniformApiEnhancer = ({ apiUrl }) => {
1427
+ return async (message) => {
1428
+ const response = await fetch(apiUrl, {
1429
+ method: "post",
1430
+ body: JSON.stringify({
1431
+ composition: message.composition,
1432
+ hash: message.hash
1433
+ }),
1434
+ headers: {
1435
+ "Content-Type": "application/json"
1436
+ }
1437
+ });
1438
+ const json = await response.json();
1439
+ if (!response.ok) {
1440
+ throw new Error("Error reading enhanced composition");
1441
+ }
1442
+ const body = json;
1443
+ return body.composition;
1444
+ };
1445
+ };
1446
+
1422
1447
  // src/utils/isSystemComponentDefinition.ts
1423
1448
  var isSystemComponentDefinition = (componentType) => {
1424
1449
  return componentType.startsWith("$");
@@ -1489,6 +1514,7 @@ var CanvasClientError = import_api4.ApiClientError;
1489
1514
  EDGE_MIN_L2_CACHE_TTL_IN_HOURS,
1490
1515
  EnhancerBuilder,
1491
1516
  IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
1517
+ IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
1492
1518
  IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
1493
1519
  PLACEHOLDER_ID,
1494
1520
  UncachedCanvasClient,
@@ -1498,6 +1524,7 @@ var CanvasClientError = import_api4.ApiClientError;
1498
1524
  createCanvasChannel,
1499
1525
  createEventBus,
1500
1526
  createLimitPolicy,
1527
+ createUniformApiEnhancer,
1501
1528
  enhance,
1502
1529
  extractLocales,
1503
1530
  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-D45SO56S.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.4+e9d268bce",
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.4+e9d268bce",
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.4+e9d268bce"
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": "e9d268bcef28fc22632f4968ca988e3b0b92d146"
69
69
  }