@3dsource/metabox-modular-configurator-api 2.0.4 → 3.0.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
@@ -2,15 +2,25 @@ import { Observable } from 'rxjs';
2
2
 
3
3
  type ApplicationDeviceTypes = 'deviceTypeAuto' | 'deviceTypeMobile' | 'deviceTypeDesktop';
4
4
 
5
- declare const Metabox_V2 = "metabox_v2";
6
- declare const MetaboxHost_V2 = "metaboxHost_v2";
7
- declare const MetaboxData_V2 = "metaboxData_v2";
8
- declare const AppLoaded_V2 = "appLoaded_v2";
5
+ declare const Metabox = "metabox_v3";
6
+ declare const MetaboxHost = "metaboxHost_v3";
7
+ declare const MetaboxData = "metaboxData_v3";
8
+ declare const AppLoaded = "appLoaded_v3";
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 = "3.0.0";
11
13
 
12
- type FromMetaboxApiAction = 'bridge' | typeof AppLoaded_V2;
14
+ type FromMetaboxApiAction = 'bridge' | typeof AppLoaded;
13
15
 
16
+ interface IntegrateMetaboxConfig {
17
+ standalone?: boolean;
18
+ loadingImage?: string;
19
+ introVideo?: string;
20
+ introImage?: string;
21
+ state?: string;
22
+ domain?: string;
23
+ }
14
24
  interface MetaboxCommandConfig {
15
25
  standalone?: boolean;
16
26
  hostUrl: string;
@@ -105,7 +115,7 @@ interface ToMetaBoxMessageEnvelope {
105
115
  payload?: ToMetaboxMessagePayload | never;
106
116
  }
107
117
  interface ToMetaBoxMessage {
108
- host: typeof MetaboxHost_V2;
118
+ host: typeof MetaboxHost;
109
119
  payload: ToMetaBoxMessageEnvelope;
110
120
  }
111
121
 
@@ -554,7 +564,7 @@ type MetaboxEnvironment = 'metabox' | 'host';
554
564
  * Used for signaling that the app is loaded and ready to open api.
555
565
  */
556
566
  interface MCAppLoaded {
557
- action: typeof AppLoaded_V2;
567
+ action: typeof AppLoaded;
558
568
  eventType?: unknown;
559
569
  payload: {
560
570
  appId: string;
@@ -570,7 +580,7 @@ type FromMetaBoxAPIEnvelope = {
570
580
  [K in keyof FromMetaboxMessagePayloads]: MetaBoxApiEnvelope<K>;
571
581
  }[keyof FromMetaboxMessagePayloads] | MCAppLoaded;
572
582
  interface FromMetaBoxMessage {
573
- host: typeof Metabox_V2;
583
+ host: typeof Metabox;
574
584
  envelope: FromMetaBoxAPIEnvelope;
575
585
  }
576
586
 
@@ -591,8 +601,8 @@ declare class CommandBase {
591
601
  * @example
592
602
  * import { ApplyZoom, Communicator } from '@3dsource/metabox-modular-configurator-api';
593
603
  * window.env3DSource.apiReady = (api: Communicator) => {
594
- * api.sendCommandToMetaBox(new ApplyZoom(10));
595
- * api.sendCommandToMetaBox(new ApplyZoom(-10));
604
+ * api.sendCommandToMetabox(new ApplyZoom(10));
605
+ * api.sendCommandToMetabox(new ApplyZoom(-10));
596
606
  * };
597
607
  */
598
608
  declare class ApplyZoom extends CommandBase {
@@ -685,7 +695,7 @@ declare class Communicator extends EventDispatcher {
685
695
  * Posts a command to the Metabox iframe.
686
696
  * @param command - An action command containing data to send.
687
697
  */
688
- sendCommandToMetaBox<T extends CommandBase>(command: T): void;
698
+ sendCommandToMetabox<T extends CommandBase>(command: T): void;
689
699
  /**
690
700
  * Registers an event listener for messages dispatched by Metabox.
691
701
  * @override
@@ -710,35 +720,51 @@ declare class Communicator extends EventDispatcher {
710
720
  }
711
721
 
712
722
  /**
713
- * Integrates Metabox Modular Configurator into the provided layout.
723
+ * Integrates the Metabox Modular Configurator into the page by injecting an iframe and
724
+ * initializing a Communicator instance for host-to-iframe messaging.
714
725
  *
715
726
  * @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.
727
+ * - Builds a secure iframe URL using the provided configuratorId and config options.
728
+ * - Ensures the resulting URL uses HTTPS and that the target container exists.
729
+ * - Removes any previously embedded iframe with id "embeddedContent" before inserting a new one.
730
+ *
731
+ * @param {string} configuratorId - The Modular Configurator ID (not a full URL). It is appended to
732
+ * `https://{domain}/metabox-configurator/modular/{configuratorId}` to form the iframe src.
718
733
  *
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
734
+ * @param {string} [containerId='embed3DSource'] - The id of the container element where the iframe will be injected.
725
735
  *
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.
736
+ * @param {(api: Communicator) => void} apiReadyCallback - Called when the Communicator instance is created on the host side.
737
+ *
738
+ * @param {IntegrateMetaboxConfig} config - Optional configuration used to build the iframe URL and initialize the communicator.
739
+ * Supported fields:
740
+ * - standalone?: boolean — if true, disables Metabox custom template and related logic.
741
+ * - introImage?: string — URL to an image shown on the intro screen (added as ?introImage=...).
742
+ * - introVideo?: string — URL to a video shown on the intro screen (added as ?introVideo=...).
743
+ * - loadingImage?: string — URL to an image displayed while loading (added as ?loadingImage=...).
744
+ * - state?: string — Predefined state for configurator for initial loading (added as ?state=...).
745
+ * - domain?: string — custom domain for testing (defaults to metabox.3dsource.com). HTTPS is enforced.
746
+ *
747
+ * @throws Error If configuratorId or containerId are empty strings.
748
+ * @throws Error If the computed iframe URL is invalid or does not use HTTPS.
749
+ * @throws Error If the container element with the provided id cannot be found.
730
750
  *
731
751
  * @example
732
- * import {
733
- * integrateMetabox,
734
- * } from '@3dsource/metabox-modular-configurator-api';
752
+ * import { integrateMetabox } from '@3dsource/metabox-modular-configurator-api';
735
753
  *
736
754
  * integrateMetabox(
737
- * 'https://metabox.3dsource.com/metabox-configurator/modular/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp',
738
- * 'embed3DSource'
755
+ * 'configurator-id',
756
+ * 'embed3DSource',
757
+ * (api) => {
758
+ * // Communicator is ready to use
759
+ * },
760
+ * {
761
+ * standalone: false,
762
+ * introImage: 'https://example.com/intro.png',
763
+ * loadingImage: 'https://example.com/loading.png',
764
+ * },
739
765
  * );
740
766
  */
741
- declare function integrateMetabox(iframeSrc: string, containerId: string | undefined, apiReadyCallback: (api: Communicator) => void, config?: Partial<MetaboxCommandConfig>): void;
767
+ declare function integrateMetabox(configuratorId: string, containerId: string | undefined, apiReadyCallback: (api: Communicator) => void, config?: IntegrateMetaboxConfig): void;
742
768
 
743
769
  /**
744
770
  * Saves an image by triggering a download.
@@ -752,6 +778,8 @@ declare function integrateMetabox(iframeSrc: string, containerId: string | undef
752
778
  */
753
779
  declare function saveImage(imageUrl: string, filename: string): void;
754
780
 
781
+ declare const prepareIframeSrc: (configuratorId: string, config?: IntegrateMetaboxConfig) => string;
782
+
755
783
  /**
756
784
  * Wrapper helper function to use it with rxJs the same as `fromEvent` to listen to events from the Communicator.
757
785
  * @param {Communicator} target
@@ -770,7 +798,7 @@ declare function fromCommunicatorEvent<T extends FromMetaBoxApiEvents>(target: C
770
798
  * @example
771
799
  * import { GetCallToActionInformation, Communicator } from '@3dsource/metabox-modular-configurator-api';
772
800
  * window.env3DSource.apiReady = (api: Communicator) => {
773
- * api.sendCommandToMetaBox(new GetCallToActionInformation());
801
+ * api.sendCommandToMetabox(new GetCallToActionInformation());
774
802
  * };
775
803
  */
776
804
  declare class GetCallToActionInformation extends CommandBase {
@@ -794,7 +822,7 @@ declare class GetCallToActionInformation extends CommandBase {
794
822
  * @example
795
823
  * import { GetPdf, Communicator } from '@3dsource/metabox-modular-configurator-api';
796
824
  * window.env3DSource.apiReady = (api: Communicator) => {
797
- * api.sendCommandToMetaBox(new GetPdf());
825
+ * api.sendCommandToMetabox(new GetPdf());
798
826
  * };
799
827
  */
800
828
  declare class GetPdf extends CommandBase {
@@ -818,7 +846,7 @@ declare class GetPdf extends CommandBase {
818
846
  * @example
819
847
  * import { ResetCamera, Communicator } from '@3dsource/metabox-modular-configurator-api';
820
848
  * window.env3DSource.apiReady = (api: Communicator) => {
821
- * api.sendCommandToMetaBox(new ResetCamera());
849
+ * api.sendCommandToMetabox(new ResetCamera());
822
850
  * };
823
851
  */
824
852
  declare class ResetCamera extends CommandBase {
@@ -845,7 +873,7 @@ declare class ResetCamera extends CommandBase {
845
873
  * ```typescript
846
874
  * import { InitShowcase, Communicator } from '@3dsource/metabox-modular-configurator-api';
847
875
  * window.env3DSource.apiReady = (api: Communicator) => {
848
- * api.sendCommandToMetaBox(new InitShowcase();
876
+ * api.sendCommandToMetabox(new InitShowcase();
849
877
  * };
850
878
  */
851
879
  declare class InitShowcase extends CommandBase {
@@ -877,7 +905,7 @@ declare class UnrealCommand extends CommandBase {
877
905
  * @example
878
906
  * import { PlayShowcase, Communicator } from '@3dsource/metabox-modular-configurator-api';
879
907
  * window.env3DSource.apiReady = (api: Communicator) => {
880
- * api.sendCommandToMetaBox(new PlayShowcase());
908
+ * api.sendCommandToMetabox(new PlayShowcase());
881
909
  * };
882
910
  */
883
911
  declare class PlayShowcase extends CommandBase {
@@ -900,7 +928,7 @@ declare class PlayShowcase extends CommandBase {
900
928
  * @example
901
929
  * import { PauseShowcase, Communicator } from '@3dsource/metabox-modular-configurator-api';
902
930
  * window.env3DSource.apiReady = (api: Communicator) => {
903
- * api.sendCommandToMetaBox(new PauseShowcase());
931
+ * api.sendCommandToMetabox(new PauseShowcase());
904
932
  * };
905
933
  */
906
934
  declare class PauseShowcase extends CommandBase {
@@ -923,7 +951,7 @@ declare class PauseShowcase extends CommandBase {
923
951
  * @example
924
952
  * import { StopShowcase, Communicator } from '@3dsource/metabox-modular-configurator-api';
925
953
  * window.env3DSource.apiReady = (api: Communicator) => {
926
- * api.sendCommandToMetaBox(new StopShowcase());
954
+ * api.sendCommandToMetabox(new StopShowcase());
927
955
  * };
928
956
  */
929
957
  declare class StopShowcase extends CommandBase {
@@ -955,7 +983,7 @@ type MimeType = 'image/png' | 'image/jpeg' | 'image/webp';
955
983
  * // Process the get screenshot response
956
984
  * saveImage(data, 'Render.png');
957
985
  * });
958
- * api.sendCommandToMetaBox(new GetScreenshot('image/png', { x: 1024, y: 1024 }));
986
+ * api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1024, y: 1024 }));
959
987
  * };
960
988
  */
961
989
  declare class GetScreenshot extends CommandBase {
@@ -1005,7 +1033,7 @@ declare class SetComponent extends CommandBase {
1005
1033
  *
1006
1034
  * //...Assume that the integration is already implemented
1007
1035
  * window.env3DSource.apiReady = (api: Communicator) => {
1008
- * api.sendCommandToMetaBox(new SetComponentMaterial(
1036
+ * api.sendCommandToMetabox(new SetComponentMaterial(
1009
1037
  * 'carpaint',
1010
1038
  * 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
1011
1039
  * ));
@@ -1055,7 +1083,7 @@ declare class SetComponentType extends CommandBase {
1055
1083
  * //...Assume that the integration is already implemented
1056
1084
  * window.env3DSource.apiReady = (api: Communicator) => {
1057
1085
  * // Change the environment to '55555555-1234-1234-1234-01234567890'
1058
- * api.sendCommandToMetaBox(new SetEnvironment('55555555-1234-1234-1234-01234567890'));
1086
+ * api.sendCommandToMetabox(new SetEnvironment('55555555-1234-1234-1234-01234567890'));
1059
1087
  * };
1060
1088
  */
1061
1089
  declare class SetEnvironment extends CommandBase {
@@ -1075,7 +1103,7 @@ declare class SetEnvironment extends CommandBase {
1075
1103
  *
1076
1104
  * //...Assume that the integration is already implemented
1077
1105
  * window.env3DSource.apiReady = (api: Communicator) => {
1078
- * api.sendCommandToMetaBox(new SetEnvironmentMaterial(
1106
+ * api.sendCommandToMetabox(new SetEnvironmentMaterial(
1079
1107
  * 'carpaint',
1080
1108
  * 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
1081
1109
  * ));
@@ -1148,5 +1176,5 @@ declare class MetaboxConfig extends CommandBase {
1148
1176
  constructor(appId: string, config: MetaboxCommandConfig);
1149
1177
  }
1150
1178
 
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 };
1179
+ export { AppLoaded, ApplyZoom, BasicRouteUrl, CommandBase, Communicator, EventDispatcher, GetCallToActionInformation, GetPdf, GetScreenshot, InitShowcase, Metabox, MetaboxConfig, MetaboxData, MetaboxDomain, MetaboxHost, MetaboxModularConfiguratorActions, PauseShowcase, PlayShowcase, ResetCamera, SetComponent, SetComponentMaterial, SetComponentType, SetEnvironment, SetEnvironmentMaterial, ShowEmbeddedMenu, ShowOverlayInterface, StopShowcase, UnrealCommand, VERSION, fromCommunicatorEvent, integrateMetabox, prepareIframeSrc, saveImage };
1180
+ 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": "3.0.0",
4
4
  "description": "API for Metabox MODULAR configurator",
5
5
  "keywords": [
6
6
  "metabox",