@threekit-tools/treble 0.0.87 → 0.0.89

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,5 +1,5 @@
1
1
  import threekitAPI from '../api';
2
- import { IThreekitPlayer, IThreekitPrivatePlayer, IConfiguration, ISetConfiguration, IThreekitPrivateConfigurator } from '../types';
2
+ import { IThreekitPlayer, IThreekitPrivatePlayer, IThreekitPrivateConfigurator } from '../types';
3
3
  import { IWishlist } from './wishlist';
4
4
  import snapshots from './snapshots';
5
5
  import { ISaveConfiguration } from '../api/configurations';
@@ -8,7 +8,6 @@ import { ICartItem } from '../http/orders';
8
8
  interface ITreble {
9
9
  player: IThreekitPlayer;
10
10
  orgId: string;
11
- initialConfiguration: IConfiguration;
12
11
  }
13
12
  interface IEmailShareCredentials {
14
13
  to: string;
@@ -22,11 +21,10 @@ declare class Treble {
22
21
  _api: typeof threekitAPI;
23
22
  _player: IThreekitPrivatePlayer;
24
23
  wishlist: IWishlist;
25
- private _initialConfiguration;
26
24
  private _snapshots;
27
25
  takeSnapshots: typeof snapshots['takeSnapshots'];
28
26
  _debugMode: boolean;
29
- constructor({ player, orgId, initialConfiguration }: ITreble);
27
+ constructor({ player, orgId }: ITreble);
30
28
  createOrder: (order?: IOrder) => Promise<import("../http/orders").IOrderResponse>;
31
29
  saveConfiguration: (config?: Partial<Omit<ISaveConfiguration, 'configuration'>>) => Promise<{
32
30
  resumableUrl: string;
@@ -34,7 +32,6 @@ declare class Treble {
34
32
  thumbnail: string;
35
33
  }>;
36
34
  getNestedConfigurator: (address: string | Array<string>) => undefined | IThreekitPrivateConfigurator;
37
- resetConfiguration: (configuration?: ISetConfiguration) => void;
38
35
  sendEmail: (credentials: IEmailShareCredentials, templateData: Record<string, any>) => Promise<import("../http/server").IPostEmailResponse>;
39
36
  }
40
37
  export default Treble;
@@ -48,7 +48,7 @@ var wishlist_1 = __importDefault(require("./wishlist"));
48
48
  var snapshots_1 = __importDefault(require("./snapshots"));
49
49
  var Treble = (function () {
50
50
  function Treble(_a) {
51
- var player = _a.player, orgId = _a.orgId, initialConfiguration = _a.initialConfiguration;
51
+ var player = _a.player, orgId = _a.orgId;
52
52
  var _this = this;
53
53
  this.createOrder = function (order) { return __awaiter(_this, void 0, void 0, function () {
54
54
  var updatedOrder, configuration, response;
@@ -129,11 +129,6 @@ var Treble = (function () {
129
129
  })) === null || _a === void 0 ? void 0 : _a.configurator;
130
130
  }, player.getConfigurator());
131
131
  };
132
- this.resetConfiguration = function (configuration) {
133
- var initialConfiguration = JSON.parse(_this._initialConfiguration);
134
- var updateConfiguration = Object.assign(initialConfiguration, configuration);
135
- window.threekit.configurator.setConfiguration(updateConfiguration);
136
- };
137
132
  this.sendEmail = function (credentials, templateData) {
138
133
  if (!credentials)
139
134
  throw new Error('sendEmail is missing credentials object');
@@ -155,7 +150,6 @@ var Treble = (function () {
155
150
  this._snapshots = snapshots_1.default;
156
151
  this.takeSnapshots = this._snapshots.takeSnapshots;
157
152
  this._player = player.enableApi(types_1.PRIVATE_APIS.PLAYER);
158
- this._initialConfiguration = JSON.stringify(initialConfiguration);
159
153
  this._debugMode = constants_1.TREBLE_DEBUG;
160
154
  }
161
155
  return Treble;
@@ -1,9 +1,11 @@
1
+ import { ICacheParameters } from './types';
1
2
  export interface IConnectionConfig {
2
3
  authToken?: string;
3
4
  orgId?: string;
4
5
  assetId?: string;
5
6
  threekitDomain?: string;
6
7
  serverUrl?: string;
8
+ cacheParameters?: ICacheParameters;
7
9
  }
8
10
  export declare class ThreekitConnection {
9
11
  _authToken: string;
@@ -11,6 +13,7 @@ export declare class ThreekitConnection {
11
13
  _assetId: string;
12
14
  _threekitDomain: string;
13
15
  _serverUrl: string;
16
+ _cacheParameters?: ICacheParameters;
14
17
  constructor();
15
18
  connect(config: IConnectionConfig): Promise<void>;
16
19
  getConnection(): {
@@ -19,6 +22,7 @@ export declare class ThreekitConnection {
19
22
  assetId: string;
20
23
  threekitDomain: string;
21
24
  serverUrl: string;
25
+ cacheParameters: ICacheParameters | undefined;
22
26
  };
23
27
  }
24
28
  declare const _default: ThreekitConnection;
@@ -58,6 +58,8 @@ var ThreekitConnection = (function () {
58
58
  this._serverUrl = config.serverUrl;
59
59
  if (config.threekitDomain)
60
60
  this._threekitDomain = "https://".concat(config.threekitDomain);
61
+ if (config.cacheParameters)
62
+ this._cacheParameters = config.cacheParameters;
61
63
  return [2];
62
64
  });
63
65
  });
@@ -72,6 +74,7 @@ var ThreekitConnection = (function () {
72
74
  assetId: this._assetId,
73
75
  threekitDomain: this._threekitDomain,
74
76
  serverUrl: this._serverUrl,
77
+ cacheParameters: this._cacheParameters,
75
78
  };
76
79
  };
77
80
  return ThreekitConnection;
@@ -1,6 +1,6 @@
1
1
  import { CachedProduct, LoadProductConfig } from '../../store/product';
2
2
  import { IReloadConfig } from '../../store/treble';
3
- interface HydratedCacheProduct extends Pick<CachedProduct, 'name' | 'label' | 'thumbnail'> {
3
+ interface HydratedCacheProduct extends Pick<CachedProduct, 'id' | 'name' | 'label' | 'thumbnail'> {
4
4
  selected: boolean;
5
5
  handleSelect: () => Promise<void>;
6
6
  handleRemove: () => Promise<void>;
@@ -14,6 +14,7 @@ interface UseProductCache {
14
14
  cache: Array<HydratedCacheProduct>;
15
15
  products: Array<ISelectableProduct>;
16
16
  onLoadNewProduct: (config?: string | IReloadConfig) => Promise<void>;
17
+ onResetProduct: () => Promise<void>;
17
18
  }
18
19
  declare const useProductCache: () => UseProductCache;
19
20
  export default useProductCache;
@@ -1,4 +1,40 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
2
38
  Object.defineProperty(exports, "__esModule", { value: true });
3
39
  var product_1 = require("../../store/product");
4
40
  var store_1 = require("../../store");
@@ -9,6 +45,12 @@ var useProductCache = function () {
9
45
  var onLoadNewProduct = function (config) {
10
46
  return dispatch((0, product_1.loadNewProduct)(config));
11
47
  };
48
+ var onResetProduct = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
49
+ switch (_a.label) {
50
+ case 0: return [4, dispatch((0, product_1.resetProductConfiguration)())];
51
+ case 1: return [2, _a.sent()];
52
+ }
53
+ }); }); };
12
54
  var hydratedCache = cache.map(function (el, i) {
13
55
  return Object.assign({}, el, {
14
56
  selected: activeProductIdx === i,
@@ -25,6 +67,6 @@ var useProductCache = function () {
25
67
  return dispatch((0, product_1.loadProduct)(prod, config));
26
68
  },
27
69
  }); });
28
- return { cache: hydratedCache, products: products, onLoadNewProduct: onLoadNewProduct };
70
+ return { cache: hydratedCache, products: products, onLoadNewProduct: onLoadNewProduct, onResetProduct: onResetProduct };
29
71
  };
30
72
  exports.default = useProductCache;
@@ -0,0 +1,3 @@
1
+ declare type UseShareHook = undefined | (() => Promise<void>);
2
+ declare const useResetProduct: () => UseShareHook;
3
+ export default useResetProduct;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var store_1 = require("../../store");
40
+ var treble_1 = require("../../store/treble");
41
+ var product_1 = require("../../store/product");
42
+ var useResetProduct = function () {
43
+ var isLoaded = (0, store_1.useThreekitSelector)(treble_1.isThreekitInitialized);
44
+ var dispatch = (0, store_1.useThreekitDispatch)();
45
+ if (!isLoaded)
46
+ return undefined;
47
+ var handleReset = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
48
+ switch (_a.label) {
49
+ case 0: return [4, dispatch((0, product_1.resetProductConfiguration)())];
50
+ case 1: return [2, _a.sent()];
51
+ }
52
+ }); }); };
53
+ return handleReset;
54
+ };
55
+ exports.default = useResetProduct;
@@ -14,11 +14,14 @@ var prepRequest = function (request, connection) {
14
14
  formData: undefined,
15
15
  config: undefined,
16
16
  }, request), url = _a.url, data = _a.data, formData = _a.formData, params = _a.params, config = _a.config, includeOrgId = _a.includeOrgId;
17
- var _b = connection.getConnection(), authToken = _b.authToken, orgId = _b.orgId, threekitDomain = _b.threekitDomain;
17
+ var _b = connection.getConnection(), authToken = _b.authToken, orgId = _b.orgId, threekitDomain = _b.threekitDomain, cacheParameters = _b.cacheParameters;
18
18
  var urlRaw = "".concat(threekitDomain).concat(url);
19
19
  var query = (0, utils_1.objectToQueryStr)(Object.assign({}, includeOrgId ? { orgId: orgId } : {}, params));
20
20
  var urlPrepped = "".concat(urlRaw).concat(query);
21
21
  urlPrepped += "".concat(query.length ? "&" : "?", "bearer_token=").concat(authToken);
22
+ if (cacheParameters) {
23
+ urlPrepped += "&cacheMaxAge=".concat(cacheParameters.maxAge, "&cacheScope=").concat(cacheParameters.scope);
24
+ }
22
25
  return { url: urlPrepped, data: formData || data, config: config };
23
26
  };
24
27
  var get = function (request) {
@@ -16,8 +16,7 @@ export interface LoadProductConfig {
16
16
  export interface CachedProductState extends Pick<CachedProduct, 'id' | 'name' | 'label' | 'thumbnail'> {
17
17
  data: string;
18
18
  }
19
- interface IEnvConfig extends Record<string, Partial<IProduct>> {
20
- }
19
+ declare type IEnvConfig = Record<string, Partial<IProduct>>;
21
20
  export interface IHydratedProducts extends Record<string, IEnvConfig> {
22
21
  }
23
22
  export interface ProductState {
@@ -42,8 +41,9 @@ export declare const getProductId: (state: RootState) => undefined | string;
42
41
  export declare const getName: (state: RootState) => undefined | string;
43
42
  export declare const getMetadata: (state: RootState) => undefined | IMetadata;
44
43
  export declare const getActiveCacheIdx: (state: RootState) => number;
45
- export declare const getProductCache: (state: RootState) => Array<Pick<CachedProduct, 'name' | 'label' | 'thumbnail'>>;
46
- export declare const initProduct: (prods?: IHydratedProducts) => (dispatch: ThreekitDispatch, getState: () => RootState) => void;
44
+ export declare const getProductCache: (state: RootState) => Array<Pick<CachedProduct, 'id' | 'name' | 'label' | 'thumbnail'>>;
45
+ export declare const setProducts: (products: IHydratedProducts) => IHydratedProducts;
46
+ export declare const initProduct: () => (dispatch: ThreekitDispatch, getState: () => RootState) => void;
47
47
  export declare const cacheActiveProduct: (config?: Pick<IReloadConfig, 'label' | 'thumbnail'>) => (dispatch: ThreekitDispatch, getState: () => RootState) => {
48
48
  payload: CachedProductState;
49
49
  type: string;
@@ -52,4 +52,5 @@ export declare const loadProduct: (id: string, config?: LoadProductConfig) => (d
52
52
  export declare const loadNewProduct: (config: undefined | string | IReloadConfig) => (dispatch: ThreekitDispatch) => Promise<void>;
53
53
  export declare const changeActiveCacheIdx: (idx: number) => (dispatch: ThreekitDispatch, getState: () => RootState) => Promise<void>;
54
54
  export declare const removeProductIdx: (idx?: number) => (dispatch: ThreekitDispatch, getState: () => RootState) => Promise<void>;
55
+ export declare const resetProductConfiguration: () => (dispatch: ThreekitDispatch, getState: () => RootState) => Promise<void>;
55
56
  export default reducer;
@@ -50,11 +50,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
50
50
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
51
  };
52
52
  Object.defineProperty(exports, "__esModule", { value: true });
53
- exports.removeProductIdx = exports.changeActiveCacheIdx = exports.loadNewProduct = exports.loadProduct = exports.cacheActiveProduct = exports.initProduct = exports.getProductCache = exports.getActiveCacheIdx = exports.getMetadata = exports.getName = exports.getProductId = exports.decrementActiveCacheIdx = exports.incrementActiveCacheIdx = exports.setActiveCacheIdx = exports.removeFromCache = exports.updateActiveProductCache = exports.appendToCache = exports.setMetadata = exports.setName = exports.setProductId = exports.PRODUCTS = void 0;
53
+ exports.resetProductConfiguration = exports.removeProductIdx = exports.changeActiveCacheIdx = exports.loadNewProduct = exports.loadProduct = exports.cacheActiveProduct = exports.initProduct = exports.setProducts = exports.getProductCache = exports.getActiveCacheIdx = exports.getMetadata = exports.getName = exports.getProductId = exports.decrementActiveCacheIdx = exports.incrementActiveCacheIdx = exports.setActiveCacheIdx = exports.removeFromCache = exports.updateActiveProductCache = exports.appendToCache = exports.setMetadata = exports.setName = exports.setProductId = exports.PRODUCTS = void 0;
54
54
  var toolkit_1 = require("@reduxjs/toolkit");
55
55
  var types_1 = require("../types");
56
56
  var connection_1 = __importDefault(require("../connection"));
57
57
  var treble_1 = require("./treble");
58
+ var attributes_1 = require("./attributes");
59
+ var INITIAL_CONFIGURATIONS = {};
58
60
  exports.setProductId = (0, toolkit_1.createAction)('treble/set-product-id');
59
61
  exports.setName = (0, toolkit_1.createAction)('treble/set-product-name');
60
62
  exports.setMetadata = (0, toolkit_1.createAction)('treble/set-metadata');
@@ -137,30 +139,35 @@ exports.getActiveCacheIdx = getActiveCacheIdx;
137
139
  var getProductCache = function (state) {
138
140
  return state.product.cache.map(function (prod) {
139
141
  return Object.assign({
142
+ id: prod.id,
140
143
  name: prod.name,
141
144
  }, prod.label ? { label: prod.label } : {}, prod.thumbnail ? { thumbnail: prod.thumbnail } : {});
142
145
  });
143
146
  };
144
147
  exports.getProductCache = getProductCache;
145
- var initProduct = function (prods) {
146
- return function (dispatch, getState) {
147
- if (prods)
148
- exports.PRODUCTS = prods;
149
- if (!window.threekit)
150
- return;
151
- var state = getState();
152
- var name = window.threekit.player.scene.get({
153
- id: window.threekit.player.assetId,
154
- }).name;
155
- var metadata = window.threekit.configurator.getMetadata();
156
- dispatch((0, exports.setName)(name));
157
- dispatch((0, exports.setMetadata)(metadata));
158
- if (!state.product.cache.length) {
159
- dispatch((0, exports.setActiveCacheIdx)(0));
160
- dispatch((0, exports.cacheActiveProduct)());
161
- }
162
- };
148
+ var setProducts = function (products) {
149
+ return (exports.PRODUCTS = products);
163
150
  };
151
+ exports.setProducts = setProducts;
152
+ var initProduct = function () { return function (dispatch, getState) {
153
+ var state = getState();
154
+ var name = window.threekit.player.scene.get({
155
+ id: window.threekit.player.assetId,
156
+ }).name;
157
+ var metadata = window.threekit.configurator.getMetadata();
158
+ var productId = state.product.id;
159
+ if (productId && !INITIAL_CONFIGURATIONS[productId]) {
160
+ var player = window.threekit.player.enableApi(types_1.PRIVATE_APIS.PLAYER);
161
+ var configuration = player.configurator.getFullConfiguration();
162
+ INITIAL_CONFIGURATIONS[productId] = JSON.stringify(configuration);
163
+ }
164
+ dispatch((0, exports.setName)(name));
165
+ dispatch((0, exports.setMetadata)(metadata));
166
+ if (!state.product.cache.length) {
167
+ dispatch((0, exports.setActiveCacheIdx)(0));
168
+ dispatch((0, exports.cacheActiveProduct)());
169
+ }
170
+ }; };
164
171
  exports.initProduct = initProduct;
165
172
  var cacheActiveProduct = function (config) {
166
173
  return function (dispatch, getState) {
@@ -199,10 +206,9 @@ var loadProduct = function (id, config) {
199
206
  return [4, dispatch((0, treble_1.reloadPlayer)(productConfig))];
200
207
  case 1:
201
208
  _a.sent();
202
- if (cacheProduct) {
209
+ if (cacheProduct)
203
210
  dispatch((0, exports.incrementActiveCacheIdx)());
204
- dispatch((0, exports.cacheActiveProduct)());
205
- }
211
+ dispatch((0, exports.cacheActiveProduct)());
206
212
  return [2];
207
213
  }
208
214
  });
@@ -223,16 +229,15 @@ var loadNewProduct = function (config) {
223
229
  shouldCacheProduct = false;
224
230
  }
225
231
  if (shouldCacheProduct)
226
- dispatch((0, exports.cacheActiveProduct)({ label: label, thumbnail: thumbnail }));
232
+ dispatch((0, exports.cacheActiveProduct)());
227
233
  if (config)
228
234
  dispatch((0, exports.setProductId)(undefined));
229
235
  return [4, dispatch((0, treble_1.reloadPlayer)(config))];
230
236
  case 1:
231
237
  _a.sent();
232
- if (shouldCacheProduct) {
238
+ if (shouldCacheProduct)
233
239
  dispatch((0, exports.incrementActiveCacheIdx)());
234
- dispatch((0, exports.cacheActiveProduct)({ label: label, thumbnail: thumbnail }));
235
- }
240
+ dispatch((0, exports.cacheActiveProduct)({ label: label, thumbnail: thumbnail }));
236
241
  return [2];
237
242
  }
238
243
  });
@@ -306,4 +311,16 @@ var removeProductIdx = function (idx) {
306
311
  }); };
307
312
  };
308
313
  exports.removeProductIdx = removeProductIdx;
314
+ var resetProductConfiguration = function () { return function (dispatch, getState) { return __awaiter(void 0, void 0, void 0, function () {
315
+ var state, initialConfiguration;
316
+ return __generator(this, function (_a) {
317
+ state = getState();
318
+ if (!state.product.id)
319
+ return [2];
320
+ initialConfiguration = INITIAL_CONFIGURATIONS[state.product.id];
321
+ dispatch((0, attributes_1.setConfiguration)(JSON.parse(initialConfiguration)));
322
+ return [2];
323
+ });
324
+ }); }; };
325
+ exports.resetProductConfiguration = resetProductConfiguration;
309
326
  exports.default = reducer;
@@ -167,7 +167,7 @@ var getPlayerInteraction = function (state) {
167
167
  exports.getPlayerInteraction = getPlayerInteraction;
168
168
  var initPlayer = function (config) {
169
169
  return function (dispatch, getState) { return __awaiter(void 0, void 0, void 0, function () {
170
- var el, authToken, assetId, stageId, playerConfig, initialConfiguration, player, configurator, orgId, ruleName;
170
+ var el, authToken, assetId, stageId, playerConfig, initialConfiguration, player, configurator, orgId, cacheParameters, ruleName;
171
171
  return __generator(this, function (_a) {
172
172
  switch (_a.label) {
173
173
  case 0:
@@ -185,6 +185,10 @@ var initPlayer = function (config) {
185
185
  configurator = _a.sent();
186
186
  orgId = player.enableApi(types_1.PRIVATE_APIS.PLAYER).orgId;
187
187
  connection_1.default.connect({ orgId: orgId });
188
+ cacheParameters = player.cacheParameters;
189
+ if (cacheParameters) {
190
+ connection_1.default.connect({ cacheParameters: cacheParameters });
191
+ }
188
192
  if (window.threekit) {
189
193
  window.threekit = Object.assign(window.threekit, {
190
194
  player: player,
@@ -199,7 +203,6 @@ var initPlayer = function (config) {
199
203
  treble: new Treble_1.default({
200
204
  player: player,
201
205
  orgId: orgId,
202
- initialConfiguration: configurator.getConfiguration(),
203
206
  }),
204
207
  };
205
208
  dispatch((0, exports.setThreekitInitialized)(true));
@@ -306,7 +309,7 @@ var launch = function (launchConfig) {
306
309
  }, {});
307
310
  if (!Object.keys(credentials).length || !Object.keys(products).length)
308
311
  return [2, console.error('Missing credentials')];
309
- dispatch((0, product_1.initProduct)(products));
312
+ (0, product_1.setProducts)(products);
310
313
  dispatch((0, product_1.setProductId)(productId));
311
314
  threekitEnv = (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.threekitEnv) || process.env.THREEKIT_ENV || 'preview';
312
315
  serverUrl = (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.serverUrl) || ((_g = config === null || config === void 0 ? void 0 : config.project) === null || _g === void 0 ? void 0 : _g.serverUrl);
package/dist/types.d.ts CHANGED
@@ -266,6 +266,10 @@ export interface IThreekitCamera {
266
266
  setQuaternion: (quaternion: IQuaternion) => void;
267
267
  zoom: (delta: number) => void;
268
268
  }
269
+ export interface ICacheParameters {
270
+ maxAge: number;
271
+ scope: string;
272
+ }
269
273
  export interface IThreekitPlayer {
270
274
  assetId: string;
271
275
  instanceId: string;
@@ -279,6 +283,7 @@ export interface IThreekitPlayer {
279
283
  enableApi: <T extends PRIVATE_APIS>(api: T) => T extends PRIVATE_APIS.PLAYER ? IThreekitPrivatePlayer : any;
280
284
  snapshotAsync: (snapshotConfig: ISnapshotConfig) => Promise<string>;
281
285
  unload: () => Promise<string>;
286
+ cacheParameters: ICacheParameters;
282
287
  }
283
288
  export interface IThreekitPrivateConfigurator extends IThreekitConfigurator {
284
289
  name: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threekit-tools/treble",
3
- "version": "0.0.87",
3
+ "version": "0.0.89",
4
4
  "author": "Amaan Saeed",
5
5
  "license": "MIT",
6
6
  "files": [