@threekit-tools/treble 0.0.88 → 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,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,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) {
@@ -7,28 +7,21 @@ declare const store: import("@reduxjs/toolkit").EnhancedStore<{
7
7
  translations: import("./translations").TranslationsState;
8
8
  wishlist: import("../Treble").WishlistArray;
9
9
  price: import("./price").PriceState;
10
- }, import("redux").AnyAction, import("@reduxjs/toolkit").MiddlewareArray<import("redux-thunk").ThunkMiddleware<{
10
+ }, import("redux").AnyAction, import("@reduxjs/toolkit").MiddlewareArray<[import("redux-thunk").ThunkMiddleware<{
11
11
  treble: import("./treble").TrebleState;
12
12
  product: import("./product").ProductState;
13
13
  attributes: import("./attributes").AttributesState;
14
14
  translations: import("./translations").TranslationsState;
15
15
  wishlist: import("../Treble").WishlistArray;
16
16
  price: import("./price").PriceState;
17
- }, import("redux").AnyAction, null> | import("redux-thunk").ThunkMiddleware<{
17
+ }, import("redux").AnyAction, undefined>]> | import("@reduxjs/toolkit").MiddlewareArray<[import("redux-thunk").ThunkMiddleware<{
18
18
  treble: import("./treble").TrebleState;
19
19
  product: import("./product").ProductState;
20
20
  attributes: import("./attributes").AttributesState;
21
21
  translations: import("./translations").TranslationsState;
22
22
  wishlist: import("../Treble").WishlistArray;
23
23
  price: import("./price").PriceState;
24
- }, import("redux").AnyAction, undefined> | import("redux").Middleware<{}, {
25
- treble: import("./treble").TrebleState;
26
- product: import("./product").ProductState;
27
- attributes: import("./attributes").AttributesState;
28
- translations: import("./translations").TranslationsState;
29
- wishlist: import("../Treble").WishlistArray;
30
- price: import("./price").PriceState;
31
- }, import("redux").Dispatch<import("redux").AnyAction>>>>;
24
+ }, import("redux").AnyAction, undefined>, import("redux").Middleware<{}, any, import("redux").Dispatch<import("redux").AnyAction>>]>>;
32
25
  export declare const createStore: (reducer?: Record<string, Reducer>) => import("@reduxjs/toolkit").EnhancedStore<{
33
26
  treble: import("./treble").TrebleState;
34
27
  product: import("./product").ProductState;
@@ -36,44 +29,30 @@ export declare const createStore: (reducer?: Record<string, Reducer>) => import(
36
29
  translations: import("./translations").TranslationsState;
37
30
  wishlist: import("../Treble").WishlistArray;
38
31
  price: import("./price").PriceState;
39
- }, import("redux").AnyAction, import("@reduxjs/toolkit").MiddlewareArray<import("redux-thunk").ThunkMiddleware<{
40
- treble: import("./treble").TrebleState;
41
- product: import("./product").ProductState;
42
- attributes: import("./attributes").AttributesState;
43
- translations: import("./translations").TranslationsState;
44
- wishlist: import("../Treble").WishlistArray;
45
- price: import("./price").PriceState;
46
- }, import("redux").AnyAction, null> | import("redux-thunk").ThunkMiddleware<{
32
+ }, import("redux").AnyAction, import("@reduxjs/toolkit").MiddlewareArray<[import("redux-thunk").ThunkMiddleware<{
47
33
  treble: import("./treble").TrebleState;
48
34
  product: import("./product").ProductState;
49
35
  attributes: import("./attributes").AttributesState;
50
36
  translations: import("./translations").TranslationsState;
51
37
  wishlist: import("../Treble").WishlistArray;
52
38
  price: import("./price").PriceState;
53
- }, import("redux").AnyAction, undefined> | import("redux").Middleware<{}, {
39
+ }, import("redux").AnyAction, undefined>]> | import("@reduxjs/toolkit").MiddlewareArray<[import("redux-thunk").ThunkMiddleware<{
54
40
  treble: import("./treble").TrebleState;
55
41
  product: import("./product").ProductState;
56
42
  attributes: import("./attributes").AttributesState;
57
43
  translations: import("./translations").TranslationsState;
58
44
  wishlist: import("../Treble").WishlistArray;
59
45
  price: import("./price").PriceState;
60
- }, import("redux").Dispatch<import("redux").AnyAction>>>>;
46
+ }, import("redux").AnyAction, undefined>, import("redux").Middleware<{}, any, import("redux").Dispatch<import("redux").AnyAction>>]>>;
61
47
  export declare type RootState = ReturnType<typeof store.getState>;
62
48
  export declare type ThreekitDispatch = typeof store.dispatch;
63
- export declare const useThreekitDispatch: () => import("redux").Dispatch<import("redux").AnyAction> & import("@reduxjs/toolkit").ThunkDispatch<{
64
- treble: import("./treble").TrebleState;
65
- product: import("./product").ProductState;
66
- attributes: import("./attributes").AttributesState;
67
- translations: import("./translations").TranslationsState;
68
- wishlist: import("../Treble").WishlistArray;
69
- price: import("./price").PriceState;
70
- }, null, import("redux").AnyAction> & import("@reduxjs/toolkit").ThunkDispatch<{
49
+ export declare const useThreekitDispatch: () => import("@reduxjs/toolkit").ThunkDispatch<{
71
50
  treble: import("./treble").TrebleState;
72
51
  product: import("./product").ProductState;
73
52
  attributes: import("./attributes").AttributesState;
74
53
  translations: import("./translations").TranslationsState;
75
54
  wishlist: import("../Treble").WishlistArray;
76
55
  price: import("./price").PriceState;
77
- }, undefined, import("redux").AnyAction>;
56
+ }, undefined, import("redux").AnyAction> & import("redux").Dispatch<import("redux").AnyAction>;
78
57
  export declare const useThreekitSelector: TypedUseSelectorHook<RootState>;
79
58
  export default createStore;
@@ -41,7 +41,7 @@ export declare const getProductId: (state: RootState) => undefined | string;
41
41
  export declare const getName: (state: RootState) => undefined | string;
42
42
  export declare const getMetadata: (state: RootState) => undefined | IMetadata;
43
43
  export declare const getActiveCacheIdx: (state: RootState) => number;
44
- export declare const getProductCache: (state: RootState) => Array<Pick<CachedProduct, 'name' | 'label' | 'thumbnail'>>;
44
+ export declare const getProductCache: (state: RootState) => Array<Pick<CachedProduct, 'id' | 'name' | 'label' | 'thumbnail'>>;
45
45
  export declare const setProducts: (products: IHydratedProducts) => IHydratedProducts;
46
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) => {
@@ -139,6 +139,7 @@ exports.getActiveCacheIdx = getActiveCacheIdx;
139
139
  var getProductCache = function (state) {
140
140
  return state.product.cache.map(function (prod) {
141
141
  return Object.assign({
142
+ id: prod.id,
142
143
  name: prod.name,
143
144
  }, prod.label ? { label: prod.label } : {}, prod.thumbnail ? { thumbnail: prod.thumbnail } : {});
144
145
  });
@@ -205,10 +206,9 @@ var loadProduct = function (id, config) {
205
206
  return [4, dispatch((0, treble_1.reloadPlayer)(productConfig))];
206
207
  case 1:
207
208
  _a.sent();
208
- if (cacheProduct) {
209
+ if (cacheProduct)
209
210
  dispatch((0, exports.incrementActiveCacheIdx)());
210
- dispatch((0, exports.cacheActiveProduct)());
211
- }
211
+ dispatch((0, exports.cacheActiveProduct)());
212
212
  return [2];
213
213
  }
214
214
  });
@@ -229,16 +229,15 @@ var loadNewProduct = function (config) {
229
229
  shouldCacheProduct = false;
230
230
  }
231
231
  if (shouldCacheProduct)
232
- dispatch((0, exports.cacheActiveProduct)({ label: label, thumbnail: thumbnail }));
232
+ dispatch((0, exports.cacheActiveProduct)());
233
233
  if (config)
234
234
  dispatch((0, exports.setProductId)(undefined));
235
235
  return [4, dispatch((0, treble_1.reloadPlayer)(config))];
236
236
  case 1:
237
237
  _a.sent();
238
- if (shouldCacheProduct) {
238
+ if (shouldCacheProduct)
239
239
  dispatch((0, exports.incrementActiveCacheIdx)());
240
- dispatch((0, exports.cacheActiveProduct)({ label: label, thumbnail: thumbnail }));
241
- }
240
+ dispatch((0, exports.cacheActiveProduct)({ label: label, thumbnail: thumbnail }));
242
241
  return [2];
243
242
  }
244
243
  });
@@ -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,
package/dist/types.d.ts CHANGED
@@ -86,7 +86,7 @@ export interface ISceneResult {
86
86
  }
87
87
  export interface IConfigurationAsset {
88
88
  assetId: string;
89
- configuration?: IConfiguration | string;
89
+ configuration?: string;
90
90
  type?: string;
91
91
  }
92
92
  export interface IConfigurationColor {
@@ -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.88",
3
+ "version": "0.0.89",
4
4
  "author": "Amaan Saeed",
5
5
  "license": "MIT",
6
6
  "files": [