@threekit-tools/treble 0.0.23 → 0.0.24

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.
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
- interface ProductLayoutProps {
3
- products: string | Array<string> | Record<string, string>;
2
+ import { IProducts } from '../../threekit';
3
+ export interface ProductLayoutProps {
4
+ products: Record<string, IProducts>;
4
5
  }
5
6
  declare const ProductLayout: React.FC<ProductLayoutProps>;
6
7
  export default ProductLayout;
@@ -1,12 +1,7 @@
1
1
  /// <reference types="react" />
2
- /// <reference types="webpack-env" />
3
2
  import { ThreekitProviderProps } from '../ThreekitProvider';
4
- interface IProducts {
5
- ctx: __WebpackModuleApi.RequireContext;
6
- }
7
3
  interface ProductLoaderProps extends Omit<ThreekitProviderProps, 'children'> {
8
4
  productId?: string;
9
- products: IProducts;
10
5
  }
11
6
  export default function ProductLoader(props: ProductLoaderProps): JSX.Element | null;
12
7
  export {};
@@ -25,66 +25,62 @@ Object.defineProperty(exports, "__esModule", { value: true });
25
25
  var react_1 = __importStar(require("react"));
26
26
  var ThreekitProvider_1 = __importDefault(require("../ThreekitProvider"));
27
27
  var utils_1 = require("../../utils");
28
- var productAssetId = {};
28
+ var constants_1 = require("../../constants");
29
+ var productsMap = {};
29
30
  var productComponents = [];
30
31
  var productToComponentMap = {};
31
32
  function ProductLoader(props) {
32
- var productId = props.productId, products = props.products, credentials = props.credentials, playerConfig = props.playerConfig, theme = props.theme, threekitEnv = props.threekitEnv;
33
- if (!products)
33
+ var _a;
34
+ var project = props.project, productId = props.productId, playerConfig = props.playerConfig, threekitEnv = props.threekitEnv, locale = props.locale, theme = props.theme;
35
+ var config = (0, utils_1.loadTrebleConfig)();
36
+ if (!((_a = config.treble) === null || _a === void 0 ? void 0 : _a.productsCtx))
34
37
  return null;
35
38
  if (!productComponents.length) {
36
- products.ctx.keys().forEach(function (fileName) {
39
+ config.treble.productsCtx.keys().forEach(function (fileName) {
40
+ var _a;
37
41
  if (!fileName.includes('product.js'))
38
42
  return;
39
43
  if (fileName.includes('].product.js'))
40
44
  return;
41
- productComponents.push(products.ctx(fileName).default);
45
+ productComponents.push((_a = config.treble) === null || _a === void 0 ? void 0 : _a.productsCtx(fileName).default);
42
46
  });
43
47
  react_1.Children.forEach(Object.values(productComponents).map(function (el) { return el({}); }), function (jsx, i) {
44
- var _a;
45
48
  if (!jsx)
46
49
  return;
47
50
  if (jsx.type.name !== 'ProductLayout')
48
51
  return;
49
52
  if (!jsx.props.products)
50
53
  return;
51
- var products;
52
- if (Array.isArray(jsx.props.products))
53
- products = jsx.props.products.reduce(function (output, id) {
54
- var _a;
55
- return Object.assign(output, (_a = {}, _a[id] = id, _a));
56
- }, {});
57
- else if (typeof jsx.props.products === 'string') {
58
- var prdStr = jsx.props.products;
59
- products = (_a = {}, _a[prdStr] = prdStr, _a);
60
- }
61
- else {
62
- products = jsx.props.products;
63
- }
54
+ var products = jsx.props.products;
64
55
  Object.entries(products).forEach(function (_a) {
65
- var key = _a[0], assetId = _a[1];
66
- productAssetId[key] = assetId;
67
- productToComponentMap[key] = i;
56
+ var prodKey = _a[0], prodObj = _a[1];
57
+ productsMap[prodKey] = prodObj;
58
+ productToComponentMap[prodKey] = i;
68
59
  });
69
60
  });
70
61
  }
71
62
  var params = (0, utils_1.getParams)();
72
63
  var id = productId;
73
- if (!id && params['tkProduct']) {
74
- id = Object.keys(productToComponentMap).find(function (el) { return params['tkProduct'] === el; });
64
+ if (!id && params[constants_1.TK_PRODUCT_ID_PARAM_KEY]) {
65
+ id = Object.keys(productToComponentMap).find(function (el) { return params[constants_1.TK_PRODUCT_ID_PARAM_KEY] === el; });
75
66
  }
76
67
  if (!id)
77
68
  return null;
78
69
  var Product = productComponents[productToComponentMap[id]];
79
70
  if (!Product)
80
71
  return null;
81
- var assetId = productAssetId[id];
82
- var env = threekitEnv || 'preview';
83
- var preppedCredentials = Object.assign({}, credentials);
84
- preppedCredentials[env] = Object.assign(preppedCredentials[env], {
85
- assetId: assetId,
72
+ // const assetId =
73
+ // typeof productAssetId[id] === 'string'
74
+ // ? productAssetId[id]
75
+ // : productAssetId[env][id];
76
+ // const preppedCredentials = Object.assign({}, project?.credentials);
77
+ // preppedCredentials[env] = Object.assign(preppedCredentials[env], {
78
+ // assetId,
79
+ // });
80
+ var preppedProject = Object.assign({}, project, {
81
+ products: productsMap[id],
86
82
  });
87
- return (react_1.default.createElement(ThreekitProvider_1.default, { credentials: preppedCredentials, playerConfig: Object.assign({}, playerConfig), theme: theme },
83
+ return (react_1.default.createElement(ThreekitProvider_1.default, { project: preppedProject, locale: locale, playerConfig: playerConfig, theme: theme, threekitEnv: threekitEnv },
88
84
  react_1.default.createElement(Product, null)));
89
85
  }
90
86
  exports.default = ProductLoader;
@@ -1,17 +1,10 @@
1
1
  import React from 'react';
2
- import { ILaunchConfig, IThreekitCredentials } from '../../store/threekit';
3
- interface ICredentials {
4
- preview: IThreekitCredentials;
5
- 'admin-fts': IThreekitCredentials;
6
- }
2
+ import { ILaunchConfig } from '../../store/threekit';
7
3
  interface Theme {
8
4
  [key: string]: string | number;
9
5
  }
10
- export interface ThreekitProviderProps {
11
- credentials: ICredentials;
12
- playerConfig?: ILaunchConfig;
6
+ export interface ThreekitProviderProps extends Partial<ILaunchConfig> {
13
7
  theme?: Theme;
14
- threekitEnv?: string;
15
8
  children: React.ReactNode;
16
9
  }
17
10
  declare const ThreekitProvider: (props: ThreekitProviderProps) => JSX.Element;
@@ -33,19 +33,18 @@ var App = function (props) {
33
33
  var dispatch = (0, store_1.useThreekitDispatch)();
34
34
  (0, react_1.useEffect)(function () {
35
35
  var init = function () {
36
- var threekitEnv = props.threekitEnv || process.env.THREEKIT_ENV;
37
- var threekitConfig = Object.assign({ threekitEnv: threekitEnv }, props.credentials, props.playerConfig);
38
- dispatch((0, threekit_1.launch)(threekitConfig));
36
+ var playerConfig = props.playerConfig, project = props.project, locale = props.locale, threekitEnv = props.threekitEnv;
37
+ dispatch((0, threekit_1.launch)({ playerConfig: playerConfig, project: project, locale: locale, threekitEnv: threekitEnv }));
39
38
  };
40
39
  init();
41
40
  return;
42
- }, [props.credentials, props.threekitEnv, , props.playerConfig]);
41
+ }, [props.project, props.threekitEnv, , props.playerConfig]);
43
42
  return react_1.default.createElement(react_1.default.Fragment, null, props.children);
44
43
  };
45
44
  var ThreekitProvider = function (props) {
46
45
  return (react_1.default.createElement(react_redux_1.Provider, { store: store_1.default },
47
46
  react_1.default.createElement(styled_components_1.ThemeProvider, { theme: theme_1.default },
48
47
  react_1.default.createElement(GlobalStyles_styles_1.default, null),
49
- react_1.default.createElement(App, { theme: props.theme, credentials: props.credentials, playerConfig: props.playerConfig, threekitEnv: props.threekitEnv }, props.children))));
48
+ react_1.default.createElement(App, { locale: props.locale, project: props.project, playerConfig: props.playerConfig, threekitEnv: props.threekitEnv }, props.children))));
50
49
  };
51
50
  exports.default = ThreekitProvider;
@@ -9,6 +9,10 @@ export declare const LAYOUT_CLASS_NAME: string;
9
9
  export declare const TOOL_CLASS_NAME: string;
10
10
  export declare const DISPLAY_CLASS_NAME: string;
11
11
  export declare const FORM_CLASS_NAME: string;
12
+ /*****************************************************
13
+ * Treble Products Workflow
14
+ ****************************************************/
15
+ export declare const TK_PRODUCT_ID_PARAM_KEY = "tkProduct";
12
16
  /*****************************************************
13
17
  * Saved Configuration Workflow
14
18
  ****************************************************/
package/dist/constants.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Dev-Kit Config
4
4
  ****************************************************/
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.WISHLIST_LOCALSTORAGE_KEY = exports.SNAPSHOT_OUTPUTS = exports.SNAPSHOT_FORMATS = exports.METADATA_RESERVED = exports.ATTRIBUTES_RESERVED = exports.SORT_OPTIONS = exports.ATTRIBUTE_TYPES = exports.DEFAULT_PLAYER_CONFIG = exports.TK_PLAYER_ROOT_DIV = exports.TK_SAVED_CONFIG_PARAM_KEY = exports.FORM_CLASS_NAME = exports.DISPLAY_CLASS_NAME = exports.TOOL_CLASS_NAME = exports.LAYOUT_CLASS_NAME = exports.WIDGET_CLASS_NAME = exports.INPUT_COMPONENT_CLASS_NAME = exports.CLASS_NAME_PREFIX = exports.DEFAULT_CLASS_NAME = void 0;
6
+ exports.WISHLIST_LOCALSTORAGE_KEY = exports.SNAPSHOT_OUTPUTS = exports.SNAPSHOT_FORMATS = exports.METADATA_RESERVED = exports.ATTRIBUTES_RESERVED = exports.SORT_OPTIONS = exports.ATTRIBUTE_TYPES = exports.DEFAULT_PLAYER_CONFIG = exports.TK_PLAYER_ROOT_DIV = exports.TK_SAVED_CONFIG_PARAM_KEY = exports.TK_PRODUCT_ID_PARAM_KEY = exports.FORM_CLASS_NAME = exports.DISPLAY_CLASS_NAME = exports.TOOL_CLASS_NAME = exports.LAYOUT_CLASS_NAME = exports.WIDGET_CLASS_NAME = exports.INPUT_COMPONENT_CLASS_NAME = exports.CLASS_NAME_PREFIX = exports.DEFAULT_CLASS_NAME = void 0;
7
7
  exports.DEFAULT_CLASS_NAME = 'threekit-react';
8
8
  exports.CLASS_NAME_PREFIX = 'tk';
9
9
  exports.INPUT_COMPONENT_CLASS_NAME = "".concat(exports.DEFAULT_CLASS_NAME, " ").concat(exports.CLASS_NAME_PREFIX, "-input");
@@ -12,6 +12,10 @@ exports.LAYOUT_CLASS_NAME = "".concat(exports.DEFAULT_CLASS_NAME, " ").concat(ex
12
12
  exports.TOOL_CLASS_NAME = "".concat(exports.DEFAULT_CLASS_NAME, " ").concat(exports.CLASS_NAME_PREFIX, "-tool");
13
13
  exports.DISPLAY_CLASS_NAME = "".concat(exports.DEFAULT_CLASS_NAME, " ").concat(exports.CLASS_NAME_PREFIX, "-display");
14
14
  exports.FORM_CLASS_NAME = "".concat(exports.DEFAULT_CLASS_NAME, " ").concat(exports.CLASS_NAME_PREFIX, "-form");
15
+ /*****************************************************
16
+ * Treble Products Workflow
17
+ ****************************************************/
18
+ exports.TK_PRODUCT_ID_PARAM_KEY = 'tkProduct';
15
19
  /*****************************************************
16
20
  * Saved Configuration Workflow
17
21
  ****************************************************/
@@ -1,25 +1,15 @@
1
1
  import { RootState, ThreekitDispatch } from './index';
2
- import { ISetConfiguration, IThreekitDisplayAttribute, IMetadata, ThreekitInitConfig } from '../threekit';
2
+ import { ISetConfiguration, IThreekitDisplayAttribute, IMetadata, IProject, IPlayerConfig } from '../threekit';
3
3
  import { ITranslationMap } from '../api/products';
4
4
  import { ISaveConfigurationConfig, WishlistArray } from '../Treble';
5
5
  /*****************************************************
6
6
  * Types and Interfaces
7
7
  ****************************************************/
8
- export interface IThreekitCredentials {
9
- publicToken: string;
10
- assetId: string;
11
- configurationId?: string;
12
- orgId: string;
13
- stageId?: string;
14
- publishStage?: string;
15
- threekitDomain?: string;
16
- }
17
- export interface ILaunchConfig extends Omit<ThreekitInitConfig, 'el' | 'authToken' | 'orgId' | 'assetId' | 'stageId'> {
18
- threekitEnv?: string;
19
- preview: IThreekitCredentials;
20
- 'admin-fts': IThreekitCredentials;
21
- elementId?: string;
22
- language?: string | undefined;
8
+ export interface ILaunchConfig {
9
+ threekitEnv: string;
10
+ locale: string;
11
+ project: IProject;
12
+ playerConfig: IPlayerConfig;
23
13
  }
24
14
  interface IPriceConfig {
25
15
  id: string;
@@ -65,7 +55,7 @@ export declare const getWishlist: (state: RootState) => WishlistArray;
65
55
  /*****************************************************
66
56
  * Complex Actions
67
57
  ****************************************************/
68
- export declare const launch: (launchConfig: ILaunchConfig) => (dispatch: ThreekitDispatch) => Promise<void>;
58
+ export declare const launch: (launchConfig?: Partial<ILaunchConfig> | undefined) => (dispatch: ThreekitDispatch) => Promise<void>;
69
59
  export declare const setConfiguration: (config: ISetConfiguration) => (dispatch: ThreekitDispatch) => Promise<void>;
70
60
  export declare const addToWishlist: (config: ISaveConfigurationConfig) => (dispatch: ThreekitDispatch) => Promise<void>;
71
61
  export declare const removeFromWishlist: (idx: number) => (dispatch: ThreekitDispatch) => void;
@@ -260,124 +260,127 @@ exports.getWishlist = getWishlist;
260
260
  /*****************************************************
261
261
  * Complex Actions
262
262
  ****************************************************/
263
- var launch = function (launchConfig) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
264
- var _a,
265
- // Threekit Env specific credentials,
266
- threekitEnv,
267
- // Threekit Player Init
268
- elementId,
269
- // cache,
270
- showConfigurator, initialConfigurationRaw, showLoadingThumbnail, showLoadingProgress, onLoadingProgress, showAR, showShare, locale, allowMobileVerticalOrbit, publishStage, display, threekitCredentials, threekitDomainRaw, assetId, authToken, orgId, stageId, configurationId, threekitDomain, initialConfiguration, updatedAssetId, params, configId, configuration, el, _b, player, translations, pricebook, _c, priceConfig, productName, wishlistData;
271
- var _d;
272
- var _e;
273
- return __generator(this, function (_f) {
274
- switch (_f.label) {
275
- case 0:
276
- if (window.threekit)
277
- return [2 /*return*/];
278
- _a = Object.assign(constants_1.DEFAULT_PLAYER_CONFIG, launchConfig), threekitEnv = _a.threekitEnv, elementId = _a.elementId, showConfigurator = _a.showConfigurator, initialConfigurationRaw = _a.initialConfiguration, showLoadingThumbnail = _a.showLoadingThumbnail, showLoadingProgress = _a.showLoadingProgress, onLoadingProgress = _a.onLoadingProgress, showAR = _a.showAR, showShare = _a.showShare, locale = _a.locale, allowMobileVerticalOrbit = _a.allowMobileVerticalOrbit, publishStage = _a.publishStage, display = _a.display;
279
- threekitCredentials = launchConfig[threekitEnv || 'preview'];
280
- threekitDomainRaw = threekitCredentials.threekitDomain || "".concat(threekitEnv, ".threekit.com");
281
- assetId = threekitCredentials.assetId, authToken = threekitCredentials.publicToken, orgId = threekitCredentials.orgId, stageId = threekitCredentials.stageId, configurationId = threekitCredentials.configurationId;
282
- // Connection
283
- connection_1.default.connect({
284
- authToken: authToken,
285
- orgId: orgId,
286
- assetId: assetId,
287
- threekitDomain: threekitDomainRaw,
288
- });
289
- threekitDomain = connection_1.default.getConnection().threekitDomain;
290
- initialConfiguration = __assign({}, initialConfigurationRaw);
291
- updatedAssetId = assetId;
292
- params = (0, utils_1.getParams)();
293
- configId = ((_e = params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]) === null || _e === void 0 ? void 0 : _e.length)
294
- ? params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]
295
- : configurationId;
296
- if (!configId) return [3 /*break*/, 2];
297
- return [4 /*yield*/, api_1.default.configurations.fetch(configId)];
298
- case 1:
299
- configuration = _f.sent();
300
- if (configuration) {
301
- initialConfiguration = Object.assign({}, initialConfigurationRaw, configuration.data.variant);
302
- connection_1.default.connect({ assetId: configuration.data.productId });
303
- updatedAssetId = configuration.data.productId;
304
- }
305
- _f.label = 2;
306
- case 2:
307
- if (elementId) {
308
- el = document.getElementById(elementId);
309
- if (el)
310
- dispatch(setPlayerElement(elementId));
311
- }
312
- else {
313
- el = createPlayerLoaderEl(constants_1.TK_PLAYER_ROOT_DIV);
314
- dispatch(setPlayerElement(constants_1.TK_PLAYER_ROOT_DIV));
315
- }
316
- // We create the threekit script
317
- return [4 /*yield*/, (0, utils_1.createThreekitScriptEl)(threekitDomain)];
318
- case 3:
319
- // We create the threekit script
320
- _f.sent();
321
- return [4 /*yield*/, Promise.all([
322
- window.threekitPlayer({
323
- el: el,
324
- authToken: authToken,
325
- // cache,
326
- stageId: stageId,
327
- assetId: updatedAssetId,
328
- showConfigurator: showConfigurator,
329
- initialConfiguration: initialConfiguration,
330
- showLoadingThumbnail: showLoadingThumbnail,
331
- showLoadingProgress: showLoadingProgress,
332
- onLoadingProgress: onLoadingProgress,
333
- showAR: showAR,
334
- showShare: showShare,
335
- locale: locale,
336
- allowMobileVerticalOrbit: allowMobileVerticalOrbit,
337
- publishStage: publishStage,
338
- display: display,
339
- }),
340
- api_1.default.products.fetchTranslations(),
341
- api_1.default.price.getPricebooksList(),
342
- ])];
343
- case 4:
344
- _b = _f.sent(), player = _b[0], translations = _b[1], pricebook = _b[2];
345
- _c = window;
346
- _d = {
347
- player: player
348
- };
349
- return [4 /*yield*/, player.getConfigurator()];
350
- case 5:
351
- _c.threekit = (_d.configurator = _f.sent(),
352
- _d.treble = new Treble_1.default({ player: player }),
353
- _d);
354
- if (launchConfig.language) {
355
- dispatch(setLanguage(launchConfig.language));
356
- dispatch(setTranslations(translations));
357
- }
358
- if (pricebook.length) {
359
- priceConfig = {
360
- id: pricebook[0].id,
361
- currency: pricebook[0].currencies[0],
263
+ var launch = function (launchConfig) {
264
+ return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
265
+ var config, credentials, products, threekitEnv, playerConfig, envCredentials, product, threekitDomainRaw, orgId, authToken, initialConfigurationRaw, assetId, stageId, configurationId, el, threekitDomain, initialConfiguration, updatedAssetId, params, configId, configuration, _a, player, translations, pricebook, _b, priceConfig, productName, wishlistData;
266
+ var _c;
267
+ var _d, _e, _f, _g, _h;
268
+ return __generator(this, function (_j) {
269
+ switch (_j.label) {
270
+ case 0:
271
+ if (window.threekit)
272
+ return [2 /*return*/];
273
+ config = (0, utils_1.loadTrebleConfig)();
274
+ credentials = Object.assign({}, ((_d = config.project) === null || _d === void 0 ? void 0 : _d.credentials) || {}, ((_e = launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.project) === null || _e === void 0 ? void 0 : _e.credentials) || {});
275
+ products = Object.assign({}, ((_f = config.project) === null || _f === void 0 ? void 0 : _f.products) || {}, ((_g = launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.project) === null || _g === void 0 ? void 0 : _g.products) || {});
276
+ if (!Object.keys(credentials).length || !Object.keys(products).length)
277
+ return [2 /*return*/, console.error('Missing credentials')];
278
+ threekitEnv = (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.threekitEnv) || process.env.THREEKIT_ENV || 'preview';
279
+ playerConfig = Object.assign({}, constants_1.DEFAULT_PLAYER_CONFIG, config.player, launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.playerConfig);
280
+ envCredentials = credentials[threekitEnv];
281
+ product = products[threekitEnv];
282
+ threekitDomainRaw = envCredentials.threekitDomain || "".concat(threekitEnv, ".threekit.com");
283
+ orgId = envCredentials.orgId, authToken = envCredentials.publicToken;
284
+ if (typeof product === 'string') {
285
+ if ((0, utils_1.isUuid)(product))
286
+ assetId = product;
287
+ else
288
+ configurationId = product;
289
+ }
290
+ else {
291
+ if ((0, utils_1.isUuid)(product.assetId))
292
+ assetId = product.assetId;
293
+ else
294
+ configurationId = product.assetId;
295
+ stageId = product.stageId;
296
+ }
297
+ if (playerConfig.elementId) {
298
+ el = document.getElementById(playerConfig.elementId);
299
+ if (el)
300
+ dispatch(setPlayerElement(playerConfig.elementId));
301
+ }
302
+ else {
303
+ el = createPlayerLoaderEl(constants_1.TK_PLAYER_ROOT_DIV);
304
+ dispatch(setPlayerElement(constants_1.TK_PLAYER_ROOT_DIV));
305
+ }
306
+ // Connection
307
+ connection_1.default.connect({
308
+ authToken: authToken,
309
+ orgId: orgId,
310
+ assetId: assetId,
311
+ threekitDomain: threekitDomainRaw,
312
+ });
313
+ threekitDomain = connection_1.default.getConnection().threekitDomain;
314
+ initialConfiguration = __assign({}, initialConfigurationRaw);
315
+ updatedAssetId = assetId;
316
+ params = (0, utils_1.getParams)();
317
+ configId = ((_h = params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]) === null || _h === void 0 ? void 0 : _h.length)
318
+ ? params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]
319
+ : configurationId;
320
+ if (!configId) return [3 /*break*/, 2];
321
+ return [4 /*yield*/, api_1.default.configurations.fetch(configId)];
322
+ case 1:
323
+ configuration = _j.sent();
324
+ if (configuration) {
325
+ initialConfiguration = Object.assign({}, initialConfigurationRaw, configuration.data.variant);
326
+ connection_1.default.connect({ assetId: configuration.data.productId });
327
+ updatedAssetId = configuration.data.productId;
328
+ }
329
+ _j.label = 2;
330
+ case 2:
331
+ if (!updatedAssetId)
332
+ return [2 /*return*/, console.error('missing assetId')];
333
+ // We create the threekit script
334
+ return [4 /*yield*/, (0, utils_1.createThreekitScriptEl)(threekitDomain)];
335
+ case 3:
336
+ // We create the threekit script
337
+ _j.sent();
338
+ return [4 /*yield*/, Promise.all([
339
+ window.threekitPlayer(__assign({ el: el,
340
+ // Variables to sort out
341
+ authToken: authToken, stageId: stageId, assetId: updatedAssetId, initialConfiguration: initialConfiguration }, playerConfig)),
342
+ api_1.default.products.fetchTranslations(),
343
+ api_1.default.price.getPricebooksList(),
344
+ ])];
345
+ case 4:
346
+ _a = _j.sent(), player = _a[0], translations = _a[1], pricebook = _a[2];
347
+ _b = window;
348
+ _c = {
349
+ player: player
362
350
  };
363
- dispatch(setPriceConfig(priceConfig));
364
- }
365
- productName = window.threekit.player.scene.get({
366
- id: window.threekit.player.assetId,
367
- }).name;
368
- dispatch(setName(productName));
369
- dispatch(setMetadata(window.threekit.configurator.getMetadata()));
370
- dispatch(setAttributes(window.threekit.configurator.getDisplayAttributes()));
371
- dispatch((0, exports.setThreekitLoaded)(true));
372
- dispatch(setPlayerLoading(false));
373
- return [4 /*yield*/, window.threekit.treble.wishlist.getWishlist()];
374
- case 6:
375
- wishlistData = _f.sent();
376
- dispatch(setWishlist(wishlistData));
377
- return [2 /*return*/];
378
- }
379
- });
380
- }); }; };
351
+ return [4 /*yield*/, player.getConfigurator()];
352
+ case 5:
353
+ _b.threekit = (_c.configurator = _j.sent(),
354
+ _c.treble = new Treble_1.default({ player: player }),
355
+ _c);
356
+ if (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.locale) {
357
+ dispatch(setLanguage(launchConfig.locale));
358
+ dispatch(setTranslations(translations));
359
+ }
360
+ if (pricebook.length) {
361
+ priceConfig = {
362
+ id: pricebook[0].id,
363
+ currency: pricebook[0].currencies[0],
364
+ };
365
+ dispatch(setPriceConfig(priceConfig));
366
+ }
367
+ productName = window.threekit.player.scene.get({
368
+ id: window.threekit.player.assetId,
369
+ }).name;
370
+ dispatch(setName(productName));
371
+ dispatch(setMetadata(window.threekit.configurator.getMetadata()));
372
+ dispatch(setAttributes(window.threekit.configurator.getDisplayAttributes()));
373
+ dispatch((0, exports.setThreekitLoaded)(true));
374
+ dispatch(setPlayerLoading(false));
375
+ return [4 /*yield*/, window.threekit.treble.wishlist.getWishlist()];
376
+ case 6:
377
+ wishlistData = _j.sent();
378
+ dispatch(setWishlist(wishlistData));
379
+ return [2 /*return*/];
380
+ }
381
+ });
382
+ }); };
383
+ };
381
384
  exports.launch = launch;
382
385
  // Configurator
383
386
  var setConfiguration = function (config) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
@@ -1,3 +1,4 @@
1
+ /// <reference types="webpack-env" />
1
2
  import Treble from './Treble';
2
3
  declare type SCENE_PHASES = 'LOADED' | 'PRELOADED' | 'RENDERED';
3
4
  declare type PRIVATE_APIS = 'scene' | 'player';
@@ -207,7 +208,7 @@ export interface ThreekitInitConfig {
207
208
  stageId?: string;
208
209
  orgId?: string;
209
210
  showConfigurator?: boolean;
210
- initialConfiguration?: object;
211
+ initialConfiguration?: Record<string, any>;
211
212
  showAR?: boolean;
212
213
  showShare?: boolean;
213
214
  showLoadingThumbnail?: boolean;
@@ -218,6 +219,36 @@ export interface ThreekitInitConfig {
218
219
  publishStage?: string;
219
220
  display?: DISPLAY_OPTIONS;
220
221
  }
222
+ /***************************************************
223
+ * Treble Declarations
224
+ **************************************************/
225
+ export interface IFrameworkConfig {
226
+ productsCtx: __WebpackModuleApi.RequireContext;
227
+ }
228
+ export interface ICredential {
229
+ orgId: string;
230
+ publicToken: string;
231
+ publishStage?: string;
232
+ threekitDomain?: string;
233
+ }
234
+ export interface ICredentials extends Record<string, ICredential> {
235
+ }
236
+ export interface IPlayerConfig extends Omit<ThreekitInitConfig, 'el' | 'authToken' | 'orgId' | 'assetId' | 'stageId' | 'locale'> {
237
+ elementId?: string;
238
+ }
239
+ export interface IProduct extends Pick<ThreekitInitConfig, 'assetId' | 'stageId' | 'initialConfiguration'> {
240
+ }
241
+ export interface IProducts extends Record<string, string | Partial<IProduct>> {
242
+ }
243
+ export interface IProject {
244
+ credentials: ICredentials;
245
+ products: IProducts;
246
+ }
247
+ export interface ITrebleConfig {
248
+ project: IProject;
249
+ treble: IFrameworkConfig;
250
+ player: IPlayerConfig;
251
+ }
221
252
  /***************************************************
222
253
  * Global Declaration
223
254
  **************************************************/
package/dist/utils.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { ITranslationMap } from './api/products';
2
2
  import { IThreekitCamera, IConfigurationColor, ICoordinates, IQuaternion, IThreekitDisplayAttribute } from './threekit';
3
- interface ICameraPostion {
3
+ import { ITrebleConfig } from './threekit';
4
+ interface ICameraPosition {
4
5
  position: ICoordinates;
5
6
  quaternion: IQuaternion;
6
7
  }
@@ -38,7 +39,7 @@ export declare const getCameraPosition: (cameraApi: IThreekitCamera) => {
38
39
  position: ICoordinates;
39
40
  quaternion: IQuaternion;
40
41
  };
41
- export declare const setCameraPosition: (cameraApi: IThreekitCamera, cameraPosition: ICameraPostion) => void;
42
+ export declare const setCameraPosition: (cameraApi: IThreekitCamera, cameraPosition: ICameraPosition) => void;
42
43
  export declare const dataURItoBlob: (dataURI: string) => Blob;
43
44
  export declare const dataURItoFile: (dataURI: string, filename: string) => File;
44
45
  export declare const copyToClipboard: (data: string | Record<string, string | number | boolean>) => void;
@@ -56,4 +57,6 @@ export declare const selectionToConfiguration: (value: string | number | IConfig
56
57
  assetId: string | number | IConfigurationColor;
57
58
  } | undefined;
58
59
  export declare const filterFormAttributes: (attributes: Record<string, IThreekitDisplayAttribute>, attributeComponentProps: IAttributesComponentProps, includeReservedAttributes: boolean) => IThreekitDisplayAttribute[];
60
+ export declare const isUuid: (str?: string | undefined) => boolean;
61
+ export declare const loadTrebleConfig: () => Partial<ITrebleConfig>;
59
62
  export {};
package/dist/utils.js CHANGED
@@ -9,7 +9,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
9
9
  return to.concat(ar || Array.prototype.slice.call(from));
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.filterFormAttributes = exports.selectionToConfiguration = exports.translateAttribute = exports.createThreekitScriptEl = exports.metadataValueToObject = exports.easeInOutCubic = exports.copyToClipboard = exports.dataURItoFile = exports.dataURItoBlob = exports.setCameraPosition = exports.getCameraPosition = exports.findHitNode = exports.deflateRgb = exports.inflateRgb = exports.rgbToHex = exports.hexToRgb = exports.regularToKebabCase = exports.deepCompare = exports.shallowCompare = exports.getResumableUrl = exports.getParams = exports.objectToQueryStr = exports.IsJsonString = exports.generateFormClassName = exports.generateDisplayClassName = exports.generateToolClassName = exports.generateLayoutClassName = exports.generateWidgetClassName = exports.generateInputClassName = exports.generateClassName = void 0;
12
+ exports.loadTrebleConfig = exports.isUuid = exports.filterFormAttributes = exports.selectionToConfiguration = exports.translateAttribute = exports.createThreekitScriptEl = exports.metadataValueToObject = exports.easeInOutCubic = exports.copyToClipboard = exports.dataURItoFile = exports.dataURItoBlob = exports.setCameraPosition = exports.getCameraPosition = exports.findHitNode = exports.deflateRgb = exports.inflateRgb = exports.rgbToHex = exports.hexToRgb = exports.regularToKebabCase = exports.deepCompare = exports.shallowCompare = exports.getResumableUrl = exports.getParams = exports.objectToQueryStr = exports.IsJsonString = exports.generateFormClassName = exports.generateDisplayClassName = exports.generateToolClassName = exports.generateLayoutClassName = exports.generateWidgetClassName = exports.generateInputClassName = exports.generateClassName = void 0;
13
13
  var constants_1 = require("./constants");
14
14
  var generateClassName = function (baseClass) {
15
15
  return function (component, customClassName, title) {
@@ -342,3 +342,39 @@ var filterFormAttributes = function (attributes, attributeComponentProps, includ
342
342
  });
343
343
  };
344
344
  exports.filterFormAttributes = filterFormAttributes;
345
+ var isUuid = function (str) {
346
+ if (!str || typeof str !== 'string')
347
+ return false;
348
+ var check = new RegExp(/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i);
349
+ return check.test(str);
350
+ };
351
+ exports.isUuid = isUuid;
352
+ var loadTrebleConfig = function () {
353
+ var config = {};
354
+ try {
355
+ var project = require('@app-root/threekit.config.js').default;
356
+ if (project)
357
+ config.project = project;
358
+ }
359
+ catch (e) {
360
+ console.log(e);
361
+ }
362
+ try {
363
+ var player = require('@app-root/.treble/player.config.js').default;
364
+ if (player)
365
+ config.player = player;
366
+ }
367
+ catch (e) {
368
+ console.log(e);
369
+ }
370
+ try {
371
+ var treble = require('@app-root/.treble/treble.config.js').default;
372
+ if (treble)
373
+ config.treble = treble;
374
+ }
375
+ catch (e) {
376
+ console.log(e);
377
+ }
378
+ return config;
379
+ };
380
+ exports.loadTrebleConfig = loadTrebleConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threekit-tools/treble",
3
- "version": "0.0.23",
3
+ "version": "0.0.24",
4
4
  "author": "Amaan Saeed",
5
5
  "license": "MIT",
6
6
  "files": [