@3dsource/metabox-modular-configurator-api 2.0.4 → 2.0.5-dev.0

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/index.d.ts CHANGED
@@ -6,11 +6,20 @@ declare const Metabox_V2 = "metabox_v2";
6
6
  declare const MetaboxHost_V2 = "metaboxHost_v2";
7
7
  declare const MetaboxData_V2 = "metaboxData_v2";
8
8
  declare const AppLoaded_V2 = "appLoaded_v2";
9
+ declare const MetaboxDomain = "metabox.3dsource.com";
10
+ declare const BasicRouteUrl = "metabox-configurator/modular";
9
11
 
10
- declare const VERSION = "2.0.4";
12
+ declare const VERSION = "2.0.5-dev.0";
11
13
 
12
14
  type FromMetaboxApiAction = 'bridge' | typeof AppLoaded_V2;
13
15
 
16
+ interface IntegrateMetaboxConfig {
17
+ standalone?: boolean;
18
+ loadingImage?: string;
19
+ introVideo?: string;
20
+ introImage?: string;
21
+ domain?: string;
22
+ }
14
23
  interface MetaboxCommandConfig {
15
24
  standalone?: boolean;
16
25
  hostUrl: string;
@@ -591,8 +600,8 @@ declare class CommandBase {
591
600
  * @example
592
601
  * import { ApplyZoom, Communicator } from '@3dsource/metabox-modular-configurator-api';
593
602
  * window.env3DSource.apiReady = (api: Communicator) => {
594
- * api.sendCommandToMetaBox(new ApplyZoom(10));
595
- * api.sendCommandToMetaBox(new ApplyZoom(-10));
603
+ * api.sendCommandToMetabox(new ApplyZoom(10));
604
+ * api.sendCommandToMetabox(new ApplyZoom(-10));
596
605
  * };
597
606
  */
598
607
  declare class ApplyZoom extends CommandBase {
@@ -685,7 +694,7 @@ declare class Communicator extends EventDispatcher {
685
694
  * Posts a command to the Metabox iframe.
686
695
  * @param command - An action command containing data to send.
687
696
  */
688
- sendCommandToMetaBox<T extends CommandBase>(command: T): void;
697
+ sendCommandToMetabox<T extends CommandBase>(command: T): void;
689
698
  /**
690
699
  * Registers an event listener for messages dispatched by Metabox.
691
700
  * @override
@@ -710,35 +719,50 @@ declare class Communicator extends EventDispatcher {
710
719
  }
711
720
 
712
721
  /**
713
- * Integrates Metabox Modular Configurator into the provided layout.
722
+ * Integrates the Metabox Modular Configurator into the page by injecting an iframe and
723
+ * initializing a Communicator instance for host-to-iframe messaging.
714
724
  *
715
725
  * @remarks
716
- * This function injects an iframe into a specified container element in the DOM and initializes
717
- * the communicator for interacting with the Metabox embedded content.
726
+ * - Builds a secure iframe URL using the provided configuratorId and config options.
727
+ * - Ensures the resulting URL uses HTTPS and that the target container exists.
728
+ * - Removes any previously embedded iframe with id "embeddedContent" before inserting a new one.
729
+ *
730
+ * @param {string} configuratorId - The Modular Configurator ID (not a full URL). It is appended to
731
+ * `https://{domain}/metabox-configurator/modular/{configuratorId}` to form the iframe src.
718
732
  *
719
- * @param iframeSrc - The source URL of the Metabox iframe.
720
- * Additional url parameters:
721
- * ```javascript
722
- * introImage=https://example.com/image.png - sets the intro image
723
- * ```
724
- * i.e., a final link will look like https://metabox.3dsource.com/metabox-configurator/modular/your-configurator-id&introImage=https://example.com/image.png
733
+ * @param {string} [containerId='embed3DSource'] - The id of the container element where the iframe will be injected.
725
734
  *
726
- * @param {string} containerId - The ID of the layout element. Defaults to 'embed3DSource'.
727
- * @param apiReadyCallback - Callback after communicator will be created.
728
- * @param {MetaboxCommandConfig} config - optional initial config: standalone - if true - disable metabox custom template and all logic
729
- * @throws Error if the container element with the specified ID is not found.
735
+ * @param {(api: Communicator) => void} apiReadyCallback - Called when the Communicator instance is created on the host side.
736
+ *
737
+ * @param {IntegrateMetaboxConfig} config - Optional configuration used to build the iframe URL and initialize the communicator.
738
+ * Supported fields:
739
+ * - standalone?: boolean — if true, disables Metabox custom template and related logic.
740
+ * - introImage?: string — URL to an image shown on the intro screen (added as ?introImage=...).
741
+ * - introVideo?: string — URL to a video shown on the intro screen (added as ?introVideo=...).
742
+ * - loadingImage?: string — URL to an image displayed while loading (added as ?loadingImage=...).
743
+ * - domain?: string — custom domain for testing (defaults to metabox.3dsource.com). HTTPS is enforced.
744
+ *
745
+ * @throws Error If configuratorId or containerId are empty strings.
746
+ * @throws Error If the computed iframe URL is invalid or does not use HTTPS.
747
+ * @throws Error If the container element with the provided id cannot be found.
730
748
  *
731
749
  * @example
732
- * import {
733
- * integrateMetabox,
734
- * } from '@3dsource/metabox-modular-configurator-api';
750
+ * import { integrateMetabox } from '@3dsource/metabox-modular-configurator-api';
735
751
  *
736
752
  * integrateMetabox(
737
- * 'https://metabox.3dsource.com/metabox-configurator/modular/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp',
738
- * 'embed3DSource'
753
+ * 'configurator-id',
754
+ * 'embed3DSource',
755
+ * (api) => {
756
+ * // Communicator is ready to use
757
+ * },
758
+ * {
759
+ * standalone: false,
760
+ * introImage: 'https://example.com/intro.png',
761
+ * loadingImage: 'https://example.com/loading.png',
762
+ * },
739
763
  * );
740
764
  */
741
- declare function integrateMetabox(iframeSrc: string, containerId: string | undefined, apiReadyCallback: (api: Communicator) => void, config?: Partial<MetaboxCommandConfig>): void;
765
+ declare function integrateMetabox(configuratorId: string, containerId: string | undefined, apiReadyCallback: (api: Communicator) => void, config?: IntegrateMetaboxConfig): void;
742
766
 
743
767
  /**
744
768
  * Saves an image by triggering a download.
@@ -752,6 +776,8 @@ declare function integrateMetabox(iframeSrc: string, containerId: string | undef
752
776
  */
753
777
  declare function saveImage(imageUrl: string, filename: string): void;
754
778
 
779
+ declare const prepareIframeSrc: (configuratorId: string, config?: IntegrateMetaboxConfig) => string;
780
+
755
781
  /**
756
782
  * Wrapper helper function to use it with rxJs the same as `fromEvent` to listen to events from the Communicator.
757
783
  * @param {Communicator} target
@@ -770,7 +796,7 @@ declare function fromCommunicatorEvent<T extends FromMetaBoxApiEvents>(target: C
770
796
  * @example
771
797
  * import { GetCallToActionInformation, Communicator } from '@3dsource/metabox-modular-configurator-api';
772
798
  * window.env3DSource.apiReady = (api: Communicator) => {
773
- * api.sendCommandToMetaBox(new GetCallToActionInformation());
799
+ * api.sendCommandToMetabox(new GetCallToActionInformation());
774
800
  * };
775
801
  */
776
802
  declare class GetCallToActionInformation extends CommandBase {
@@ -794,7 +820,7 @@ declare class GetCallToActionInformation extends CommandBase {
794
820
  * @example
795
821
  * import { GetPdf, Communicator } from '@3dsource/metabox-modular-configurator-api';
796
822
  * window.env3DSource.apiReady = (api: Communicator) => {
797
- * api.sendCommandToMetaBox(new GetPdf());
823
+ * api.sendCommandToMetabox(new GetPdf());
798
824
  * };
799
825
  */
800
826
  declare class GetPdf extends CommandBase {
@@ -818,7 +844,7 @@ declare class GetPdf extends CommandBase {
818
844
  * @example
819
845
  * import { ResetCamera, Communicator } from '@3dsource/metabox-modular-configurator-api';
820
846
  * window.env3DSource.apiReady = (api: Communicator) => {
821
- * api.sendCommandToMetaBox(new ResetCamera());
847
+ * api.sendCommandToMetabox(new ResetCamera());
822
848
  * };
823
849
  */
824
850
  declare class ResetCamera extends CommandBase {
@@ -845,7 +871,7 @@ declare class ResetCamera extends CommandBase {
845
871
  * ```typescript
846
872
  * import { InitShowcase, Communicator } from '@3dsource/metabox-modular-configurator-api';
847
873
  * window.env3DSource.apiReady = (api: Communicator) => {
848
- * api.sendCommandToMetaBox(new InitShowcase();
874
+ * api.sendCommandToMetabox(new InitShowcase();
849
875
  * };
850
876
  */
851
877
  declare class InitShowcase extends CommandBase {
@@ -877,7 +903,7 @@ declare class UnrealCommand extends CommandBase {
877
903
  * @example
878
904
  * import { PlayShowcase, Communicator } from '@3dsource/metabox-modular-configurator-api';
879
905
  * window.env3DSource.apiReady = (api: Communicator) => {
880
- * api.sendCommandToMetaBox(new PlayShowcase());
906
+ * api.sendCommandToMetabox(new PlayShowcase());
881
907
  * };
882
908
  */
883
909
  declare class PlayShowcase extends CommandBase {
@@ -900,7 +926,7 @@ declare class PlayShowcase extends CommandBase {
900
926
  * @example
901
927
  * import { PauseShowcase, Communicator } from '@3dsource/metabox-modular-configurator-api';
902
928
  * window.env3DSource.apiReady = (api: Communicator) => {
903
- * api.sendCommandToMetaBox(new PauseShowcase());
929
+ * api.sendCommandToMetabox(new PauseShowcase());
904
930
  * };
905
931
  */
906
932
  declare class PauseShowcase extends CommandBase {
@@ -923,7 +949,7 @@ declare class PauseShowcase extends CommandBase {
923
949
  * @example
924
950
  * import { StopShowcase, Communicator } from '@3dsource/metabox-modular-configurator-api';
925
951
  * window.env3DSource.apiReady = (api: Communicator) => {
926
- * api.sendCommandToMetaBox(new StopShowcase());
952
+ * api.sendCommandToMetabox(new StopShowcase());
927
953
  * };
928
954
  */
929
955
  declare class StopShowcase extends CommandBase {
@@ -955,7 +981,7 @@ type MimeType = 'image/png' | 'image/jpeg' | 'image/webp';
955
981
  * // Process the get screenshot response
956
982
  * saveImage(data, 'Render.png');
957
983
  * });
958
- * api.sendCommandToMetaBox(new GetScreenshot('image/png', { x: 1024, y: 1024 }));
984
+ * api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1024, y: 1024 }));
959
985
  * };
960
986
  */
961
987
  declare class GetScreenshot extends CommandBase {
@@ -1005,7 +1031,7 @@ declare class SetComponent extends CommandBase {
1005
1031
  *
1006
1032
  * //...Assume that the integration is already implemented
1007
1033
  * window.env3DSource.apiReady = (api: Communicator) => {
1008
- * api.sendCommandToMetaBox(new SetComponentMaterial(
1034
+ * api.sendCommandToMetabox(new SetComponentMaterial(
1009
1035
  * 'carpaint',
1010
1036
  * 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
1011
1037
  * ));
@@ -1055,7 +1081,7 @@ declare class SetComponentType extends CommandBase {
1055
1081
  * //...Assume that the integration is already implemented
1056
1082
  * window.env3DSource.apiReady = (api: Communicator) => {
1057
1083
  * // Change the environment to '55555555-1234-1234-1234-01234567890'
1058
- * api.sendCommandToMetaBox(new SetEnvironment('55555555-1234-1234-1234-01234567890'));
1084
+ * api.sendCommandToMetabox(new SetEnvironment('55555555-1234-1234-1234-01234567890'));
1059
1085
  * };
1060
1086
  */
1061
1087
  declare class SetEnvironment extends CommandBase {
@@ -1075,7 +1101,7 @@ declare class SetEnvironment extends CommandBase {
1075
1101
  *
1076
1102
  * //...Assume that the integration is already implemented
1077
1103
  * window.env3DSource.apiReady = (api: Communicator) => {
1078
- * api.sendCommandToMetaBox(new SetEnvironmentMaterial(
1104
+ * api.sendCommandToMetabox(new SetEnvironmentMaterial(
1079
1105
  * 'carpaint',
1080
1106
  * 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
1081
1107
  * ));
@@ -1148,5 +1174,5 @@ declare class MetaboxConfig extends CommandBase {
1148
1174
  constructor(appId: string, config: MetaboxCommandConfig);
1149
1175
  }
1150
1176
 
1151
- export { AppLoaded_V2, ApplyZoom, CommandBase, Communicator, EventDispatcher, GetCallToActionInformation, GetPdf, GetScreenshot, InitShowcase, MetaboxConfig, MetaboxData_V2, MetaboxHost_V2, MetaboxModularConfiguratorActions, Metabox_V2, PauseShowcase, PlayShowcase, ResetCamera, SetComponent, SetComponentMaterial, SetComponentType, SetEnvironment, SetEnvironmentMaterial, ShowEmbeddedMenu, ShowOverlayInterface, StopShowcase, UnrealCommand, VERSION, fromCommunicatorEvent, integrateMetabox, saveImage };
1152
- export type { ApplicationDeviceTypes, ComponentWithParent, Cta, EcomConfigurator, Environment, FromMetaBoxAPIEnvelope, FromMetaBoxApiEvents, FromMetaBoxMessage, FromMetaboxApiAction, FromMetaboxMessagePayloads, InitialModularConfigurator, Listener, MCAppLoaded, Material, MetaBoxApiEnvelope, MetaProperty, MetaboxCommandConfig, MetaboxEnvironment, MimeType, Model, ModularConfiguratorComponent, ModularConfiguratorComponentType, ModularConfiguratorConnector, ModularConfiguratorEnvelope, ModularConfiguratorEnvironment, ModularConfiguratorVirtualSocketToConnector, Product, SelectedIds, ShowCaseStatus, Showcase, Slot, Test, Thumbnail, Timecode, ToMetaBoxActions, ToMetaBoxMessage, ToMetaBoxMessageEnvelope, ToMetaboxMessagePayload, ToMetaboxMessagePayloads, VideoResolution };
1177
+ export { AppLoaded_V2, ApplyZoom, BasicRouteUrl, CommandBase, Communicator, EventDispatcher, GetCallToActionInformation, GetPdf, GetScreenshot, InitShowcase, MetaboxConfig, MetaboxData_V2, MetaboxDomain, MetaboxHost_V2, MetaboxModularConfiguratorActions, Metabox_V2, PauseShowcase, PlayShowcase, ResetCamera, SetComponent, SetComponentMaterial, SetComponentType, SetEnvironment, SetEnvironmentMaterial, ShowEmbeddedMenu, ShowOverlayInterface, StopShowcase, UnrealCommand, VERSION, fromCommunicatorEvent, integrateMetabox, prepareIframeSrc, saveImage };
1178
+ export type { ApplicationDeviceTypes, ComponentWithParent, Cta, EcomConfigurator, Environment, FromMetaBoxAPIEnvelope, FromMetaBoxApiEvents, FromMetaBoxMessage, FromMetaboxApiAction, FromMetaboxMessagePayloads, InitialModularConfigurator, IntegrateMetaboxConfig, Listener, MCAppLoaded, Material, MetaBoxApiEnvelope, MetaProperty, MetaboxCommandConfig, MetaboxEnvironment, MimeType, Model, ModularConfiguratorComponent, ModularConfiguratorComponentType, ModularConfiguratorConnector, ModularConfiguratorEnvelope, ModularConfiguratorEnvironment, ModularConfiguratorVirtualSocketToConnector, Product, SelectedIds, ShowCaseStatus, Showcase, Slot, Test, Thumbnail, Timecode, ToMetaBoxActions, ToMetaBoxMessage, ToMetaBoxMessageEnvelope, ToMetaboxMessagePayload, ToMetaboxMessagePayloads, VideoResolution };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@3dsource/metabox-modular-configurator-api",
3
- "version": "2.0.4",
3
+ "version": "2.0.5-dev.0",
4
4
  "description": "API for Metabox MODULAR configurator",
5
5
  "keywords": [
6
6
  "metabox",