@3dsource/metabox-front-api 0.0.5 → 0.0.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.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  This package provides an API for interacting with the MetaBox configurator using plain JavaScript.
4
4
 
5
- ### Installation (for using with frameworks like Angular, React, etc.)
5
+ ### Installation (for using with frameworks like Angular, React, etc.) This is recommended method
6
6
 
7
7
  ```sh
8
8
  npm install @3dsource/metabox-front-api --save
@@ -20,6 +20,8 @@ import { FromMetaBoxApiAction, GetFastRender, GetPdf, integrateMetaBox, saveImag
20
20
  import { FromMetaBoxApiAction, GetFastRender, GetPdf, integrateMetaBox, saveImage, SetEnvironment, SetMaterial, SetProduct, ShowEmbeddedMenu,... } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
21
21
  ```
22
22
 
23
+ **WE ARE HIGHLY RECOMMENDING TO USE THE FIRST OPTION WITH NPM, AS THE SECOND ONE CAN RAPIDLY CHANGE AND MAY CAUSE UNEXPECTED BEHAVIOR WITH CODE YOU ARE ALREADY USING.**
24
+
23
25
  ## Usage
24
26
 
25
27
  ### 1. Include Required Scripts
@@ -39,7 +41,7 @@ Insert this code into your HTML file just before the closing `</body>` tag:
39
41
  this.api = api;
40
42
  this.api.addEventListener('metaboxData', (data) => {
41
43
  const { action, payload, eventType } = data;
42
- if (action !== FromMetaboxApiActions.bridge) {
44
+ if (action !== FromMetaboxApiAction.bridge) {
43
45
  return;
44
46
  }
45
47
 
@@ -93,11 +95,12 @@ Insert this code into your HTML file just before the closing `</body>` tag:
93
95
 
94
96
  // Integrate the 3D configurator into your page
95
97
 
98
+ /**
99
+ * Additional url parameters:
100
+ * @see integrateMetaBox
101
+ * @type {string}
102
+ */
96
103
  const url = 'https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id?sidebar=false';
97
- // Additional url parameters:
98
- // sidebar=false - disables the internal MetaBox menu
99
- // introImage=https://example.com/image.png - sets the intro image
100
- // i.e. final link will look like https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id?sidebar=false&introImage=https://example.com/image.png
101
104
  integrateMetaBox(url, 'embed3DSource');
102
105
  </script>
103
106
  ```
@@ -191,7 +194,3 @@ data.eventType === 'viewportReady' && data.payload === true.
191
194
  ```typescript
192
195
  saveImage(renderData: string, fileName: string): void;
193
196
  ```
194
-
195
- ```
196
-
197
- ```
@@ -4,7 +4,7 @@
4
4
  * All Rights Reserved
5
5
  */
6
6
  import { ApiAction } from './ApiAction';
7
- import { ToMetaBoxApiActions } from '../interfaces/ToMetaboxMessagePayloads';
7
+ import { ToMetaBoxApiAction } from '../interfaces/ToMetaboxMessagePayloads';
8
8
  /**
9
9
  * Represents a fast render action.
10
10
  * @remarks
@@ -55,7 +55,7 @@ export class GetFastRender extends ApiAction {
55
55
  format: mimeType,
56
56
  size,
57
57
  },
58
- action: ToMetaBoxApiActions.getFastRender,
58
+ action: ToMetaBoxApiAction.getFastRender,
59
59
  });
60
60
  }
61
61
  }
@@ -4,7 +4,7 @@
4
4
  * All Rights Reserved
5
5
  */
6
6
  import { ApiAction } from './ApiAction';
7
- import { ToMetaBoxApiActions } from '../interfaces/ToMetaboxMessagePayloads';
7
+ import { ToMetaBoxApiAction } from '../interfaces/ToMetaboxMessagePayloads';
8
8
  /**
9
9
  * Represents an action to get a PDF from Metabox.
10
10
  * @remarks
@@ -45,7 +45,7 @@ export class GetPdf extends ApiAction {
45
45
  constructor() {
46
46
  super();
47
47
  this.api.sendMessageToMetaBox({
48
- action: ToMetaBoxApiActions.getPdf,
48
+ action: ToMetaBoxApiAction.getPdf,
49
49
  });
50
50
  }
51
51
  }
@@ -4,7 +4,7 @@
4
4
  * All Rights Reserved
5
5
  */
6
6
  import { ApiAction } from './ApiAction';
7
- import { ToMetaBoxApiActions } from '../interfaces/ToMetaboxMessagePayloads';
7
+ import { ToMetaBoxApiAction } from '../interfaces/ToMetaboxMessagePayloads';
8
8
  /**
9
9
  * Represents an action to set the environment by its ID.
10
10
  * @remarks
@@ -39,7 +39,7 @@ export class SetEnvironment extends ApiAction {
39
39
  payload: {
40
40
  id: environmentId,
41
41
  },
42
- action: ToMetaBoxApiActions.loadLevel,
42
+ action: ToMetaBoxApiAction.loadLevel,
43
43
  });
44
44
  }
45
45
  }
@@ -4,7 +4,7 @@
4
4
  * All Rights Reserved
5
5
  */
6
6
  import { ApiAction } from './ApiAction';
7
- import { ToMetaBoxApiActions } from '../interfaces/ToMetaboxMessagePayloads';
7
+ import { ToMetaBoxApiAction } from '../interfaces/ToMetaboxMessagePayloads';
8
8
  /**
9
9
  * Represents an action to set a material by its ID.
10
10
  *
@@ -59,7 +59,7 @@ export class SetMaterial extends ApiAction {
59
59
  slotId,
60
60
  materialId,
61
61
  },
62
- action: ToMetaBoxApiActions.setMaterialById,
62
+ action: ToMetaBoxApiAction.setMaterialById,
63
63
  });
64
64
  }
65
65
  }
@@ -4,7 +4,7 @@
4
4
  * All Rights Reserved
5
5
  */
6
6
  import { ApiAction } from './ApiAction';
7
- import { ToMetaBoxApiActions } from '../interfaces/ToMetaboxMessagePayloads';
7
+ import { ToMetaBoxApiAction } from '../interfaces/ToMetaboxMessagePayloads';
8
8
  /**
9
9
  * Represents an action to set a product by its ID.
10
10
  *
@@ -23,7 +23,7 @@ export class SetProduct extends ApiAction {
23
23
  payload: {
24
24
  productId,
25
25
  },
26
- action: ToMetaBoxApiActions.setProduct,
26
+ action: ToMetaBoxApiAction.setProduct,
27
27
  });
28
28
  }
29
29
  }
@@ -4,7 +4,7 @@
4
4
  * All Rights Reserved
5
5
  */
6
6
  import { ApiAction } from './ApiAction';
7
- import { ToMetaBoxApiActions } from '../interfaces/ToMetaboxMessagePayloads';
7
+ import { ToMetaBoxApiAction } from '../interfaces/ToMetaboxMessagePayloads';
8
8
  /**
9
9
  * Represents an action to toggle the Embedded Menu in MetaBox.
10
10
  *
@@ -20,7 +20,7 @@ export class ShowEmbeddedMenu extends ApiAction {
20
20
  constructor(visible) {
21
21
  super();
22
22
  this.api.sendMessageToMetaBox({
23
- action: ToMetaBoxApiActions.showEmbeddedMenu,
23
+ action: ToMetaBoxApiAction.showEmbeddedMenu,
24
24
  payload: {
25
25
  visible,
26
26
  },
@@ -4,7 +4,7 @@
4
4
  * All Rights Reserved
5
5
  */
6
6
  import { ApiAction } from './ApiAction';
7
- import { ToMetaBoxApiActions } from '../interfaces/ToMetaboxMessagePayloads';
7
+ import { ToMetaBoxApiAction } from '../interfaces/ToMetaboxMessagePayloads';
8
8
  /**
9
9
  * @internal
10
10
  * Represents an action to watch Unreal callbacks from Unreal engine.
@@ -21,7 +21,7 @@ export class WatchCallbacks extends ApiAction {
21
21
  constructor() {
22
22
  super();
23
23
  this.api.sendMessageToMetaBox({
24
- action: ToMetaBoxApiActions.watchCallbacks,
24
+ action: ToMetaBoxApiAction.watchCallbacks,
25
25
  });
26
26
  }
27
27
  }
package/dist/index.d.ts CHANGED
@@ -14,3 +14,4 @@ export * from './lib/UrlUtils';
14
14
  export * from './interfaces/UniversalConfigurator';
15
15
  export * from './interfaces/ToMetaboxMessagePayloads';
16
16
  export * from './interfaces/FromMetaboxMessagePayloads';
17
+ export * from './interfaces/application-device-types';
package/dist/index.js CHANGED
@@ -18,3 +18,4 @@ export * from './lib/UrlUtils';
18
18
  export * from './interfaces/UniversalConfigurator';
19
19
  export * from './interfaces/ToMetaboxMessagePayloads';
20
20
  export * from './interfaces/FromMetaboxMessagePayloads';
21
+ export * from './interfaces/application-device-types';
@@ -1,8 +1,9 @@
1
1
  import type { ConfiguratorEnvelope } from './UniversalConfigurator';
2
- export declare const FromMetaboxApiActions: {
2
+ export declare const FromMetaboxApiAction: {
3
3
  readonly bridge: "bridge";
4
4
  readonly unrealCallback: "unrealCallback";
5
5
  readonly unrealFeatureBridge: "unrealFeatureBridge";
6
+ readonly appLoaded: "appLoaded";
6
7
  /**
7
8
  * @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
8
9
  */
@@ -29,23 +30,21 @@ export declare const FromMetaboxApiActions: {
29
30
  readonly videoSize: "videoSize";
30
31
  /**
31
32
  * Used in platform, must be removed in future
32
- */
33
- /**
34
- * @deprecated\
33
+ * @deprecated
35
34
  */
36
35
  readonly unrealResponse: "unrealResponse";
37
36
  /**
38
37
  * @deprecated\
39
38
  */
40
39
  readonly getFastRender: "getFastRender";
41
- readonly appLoaded: "appLoaded";
42
40
  };
43
- export type FromMetaBoxAction = (typeof FromMetaboxApiActions)[keyof typeof FromMetaboxApiActions];
41
+ export type FromMetaBoxActions = (typeof FromMetaboxApiAction)[keyof typeof FromMetaboxApiAction];
44
42
  /**
43
+ * @hidden
45
44
  * @internal
46
45
  * Used for signaling that the app is loaded and ready to open api.
47
46
  */
48
- interface MCAppLoaded {
47
+ export interface MCAppLoaded {
49
48
  action: string;
50
49
  eventType?: unknown;
51
50
  payload?: unknown;
@@ -75,7 +74,6 @@ export interface FromMetaboxMessagePayloads {
75
74
  statusMessage: string | null;
76
75
  /**
77
76
  * @internal
78
- * @experimental
79
77
  * Dispatches every time when freeze-frame is arrived or updated.
80
78
  */
81
79
  freezeFrame: {
@@ -127,4 +125,3 @@ export interface FromMetaBoxMessage {
127
125
  host: 'metabox';
128
126
  payload: FromMetaBoxAPIEnvelope;
129
127
  }
130
- export {};
@@ -3,10 +3,11 @@
3
3
  * 3DSource.com, Sergii Karanda steve@3dsource.com
4
4
  * All Rights Reserved
5
5
  */
6
- export const FromMetaboxApiActions = {
6
+ export const FromMetaboxApiAction = {
7
7
  bridge: 'bridge',
8
8
  unrealCallback: 'unrealCallback',
9
9
  unrealFeatureBridge: 'unrealFeatureBridge',
10
+ appLoaded: 'appLoaded',
10
11
  /**
11
12
  * @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
12
13
  */
@@ -33,14 +34,11 @@ export const FromMetaboxApiActions = {
33
34
  videoSize: 'videoSize',
34
35
  /**
35
36
  * Used in platform, must be removed in future
36
- */
37
- /**
38
- * @deprecated\
37
+ * @deprecated
39
38
  */
40
39
  unrealResponse: 'unrealResponse',
41
40
  /**
42
41
  * @deprecated\
43
42
  */
44
43
  getFastRender: 'getFastRender',
45
- appLoaded: 'appLoaded',
46
44
  };
@@ -1,17 +1,21 @@
1
1
  import type { MimeType } from '../actions/GetFastRender';
2
- export declare const ToMetaBoxApiActions: {
2
+ import type { ApplicationDeviceType } from './application-device-types';
3
+ export declare const ToMetaBoxApiAction: {
3
4
  readonly getPdf: "getPdf";
4
5
  readonly loadLevel: "loadLevel";
5
6
  readonly setProduct: "setProduct";
7
+ /**
8
+ * @deprecated, use 'watchCallbacks'"
9
+ * @hidden, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
10
+ */
6
11
  readonly addResponse: "addResponse";
7
12
  readonly getFastRender: "getFastRender";
8
13
  readonly watchCallbacks: "watchCallbacks";
9
- readonly setExternalMode: "setExternalMode";
10
14
  readonly setMaterialById: "setMaterialById";
11
15
  readonly showEmbeddedMenu: "showEmbeddedMenu";
12
16
  readonly forceSetDeviceType: "forceSetDeviceType";
13
17
  };
14
- export type ToMetaBoxAction = (typeof ToMetaBoxApiActions)[keyof typeof ToMetaBoxApiActions];
18
+ export type ToMetaBoxActions = (typeof ToMetaBoxApiAction)[keyof typeof ToMetaBoxApiAction];
15
19
  export type ToMetaboxMessagePayload = ToMetaboxMessagePayloads[keyof ToMetaboxMessagePayloads];
16
20
  export interface ToMetaboxMessagePayloads {
17
21
  getPdf: void;
@@ -21,6 +25,10 @@ export interface ToMetaboxMessagePayloads {
21
25
  setProduct: {
22
26
  productId: string;
23
27
  };
28
+ /**
29
+ * @deprecated
30
+ * @hidden
31
+ */
24
32
  addResponse: void;
25
33
  getFastRender: {
26
34
  format: MimeType;
@@ -30,7 +38,6 @@ export interface ToMetaboxMessagePayloads {
30
38
  };
31
39
  };
32
40
  watchCallbacks: void;
33
- setExternalMode: void;
34
41
  setMaterialById: {
35
42
  productId: string;
36
43
  slotId: string;
@@ -40,11 +47,11 @@ export interface ToMetaboxMessagePayloads {
40
47
  visible: boolean;
41
48
  };
42
49
  forceSetDeviceType: {
43
- deviceType: 'deviceTypeAuto' | 'deviceTypeMobile' | 'deviceTypeDesktop';
50
+ deviceType: ApplicationDeviceType;
44
51
  };
45
52
  }
46
53
  export interface ToMetaBoxMessageEnvelope {
47
- action: ToMetaBoxAction;
54
+ action: ToMetaBoxActions;
48
55
  payload?: ToMetaboxMessagePayload | never;
49
56
  }
50
57
  export interface ToMetaBoxMessage {
@@ -3,14 +3,17 @@
3
3
  * 3DSource.com, Sergii Karanda steve@3dsource.com
4
4
  * All Rights Reserved
5
5
  */
6
- export const ToMetaBoxApiActions = {
6
+ export const ToMetaBoxApiAction = {
7
7
  getPdf: 'getPdf',
8
8
  loadLevel: 'loadLevel',
9
9
  setProduct: 'setProduct',
10
+ /**
11
+ * @deprecated, use 'watchCallbacks'"
12
+ * @hidden, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
13
+ */
10
14
  addResponse: 'addResponse',
11
15
  getFastRender: 'getFastRender',
12
16
  watchCallbacks: 'watchCallbacks',
13
- setExternalMode: 'setExternalMode',
14
17
  setMaterialById: 'setMaterialById',
15
18
  showEmbeddedMenu: 'showEmbeddedMenu',
16
19
  forceSetDeviceType: 'forceSetDeviceType',
@@ -0,0 +1,10 @@
1
+ export declare const APPLICATION_DEVICE_TYPES: {
2
+ readonly deviceTypeAuto: "deviceTypeAuto";
3
+ readonly deviceTypeMobile: "deviceTypeMobile";
4
+ readonly deviceTypeDesktop: "deviceTypeDesktop";
5
+ };
6
+ /**
7
+ * @internal
8
+ * Represents the type of device for the application.
9
+ */
10
+ export type ApplicationDeviceType = (typeof APPLICATION_DEVICE_TYPES)[keyof typeof APPLICATION_DEVICE_TYPES];
@@ -0,0 +1,10 @@
1
+ /*
2
+ * Copyright (c) 2025.
3
+ * 3DSource.com, Sergii Karanda steve@3dsource.com
4
+ * All Rights Reserved
5
+ */
6
+ export const APPLICATION_DEVICE_TYPES = {
7
+ deviceTypeAuto: 'deviceTypeAuto',
8
+ deviceTypeMobile: 'deviceTypeMobile',
9
+ deviceTypeDesktop: 'deviceTypeDesktop',
10
+ };
@@ -6,12 +6,18 @@
6
6
  * the communicator for interacting with the MetaBox embedded content.
7
7
  *
8
8
  * @param iframeSrc - The source URL of the MetaBox iframe.
9
+ * Additional url parameters:
10
+ * ```javascript
11
+ * sidebar=false - disables the internal MetaBox menu
12
+ * introImage=https://example.com/image.png - sets the intro image
13
+ * ```
14
+ * i.e. final link will look like https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id?sidebar=false&introImage=https://example.com/image.png
15
+ *
9
16
  * @param containerId - The ID of the layout element. Defaults to 'embed3DSource'.
10
17
  *
11
18
  * @throws Error if the container element with the specified ID is not found.
12
19
  *
13
20
  * @example
14
- *
15
21
  * import {
16
22
  * integrateMetaBox,
17
23
  * } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
@@ -12,12 +12,18 @@ import { Communicator } from './initializeCommunicator';
12
12
  * the communicator for interacting with the MetaBox embedded content.
13
13
  *
14
14
  * @param iframeSrc - The source URL of the MetaBox iframe.
15
+ * Additional url parameters:
16
+ * ```javascript
17
+ * sidebar=false - disables the internal MetaBox menu
18
+ * introImage=https://example.com/image.png - sets the intro image
19
+ * ```
20
+ * i.e. final link will look like https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id?sidebar=false&introImage=https://example.com/image.png
21
+ *
15
22
  * @param containerId - The ID of the layout element. Defaults to 'embed3DSource'.
16
23
  *
17
24
  * @throws Error if the container element with the specified ID is not found.
18
25
  *
19
26
  * @example
20
- *
21
27
  * import {
22
28
  * integrateMetaBox,
23
29
  * } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@3dsource/metabox-front-api",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "API for MetaBox configurator",
5
5
  "main": "dist/index.ts",
6
6
  "unpkg": "dist/index.js",