@perceptimagery/dita-configurator-staging 0.1.9001 → 0.2.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.
Files changed (2) hide show
  1. package/dist/index.js +101 -31
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ var __publicField = (obj, key, value) => {
18
18
  return value;
19
19
  };
20
20
  (function() {
21
+ var _a;
21
22
  "use strict";
22
23
  class FetcherServiceFactory {
23
24
  constructor(config2) {
@@ -111,7 +112,7 @@ var __publicField = (obj, key, value) => {
111
112
  host: "https://api.sprie.io"
112
113
  };
113
114
  const config$1 = Object.freeze(Config$2);
114
- const version$1 = "0.1.9001";
115
+ const version$1 = "0.2.0000";
115
116
  function modifyLensArr$1(arr, element) {
116
117
  const index = arr.findIndex((e) => e["sku"] === element["sku"]);
117
118
  if (index !== -1) {
@@ -120,13 +121,15 @@ var __publicField = (obj, key, value) => {
120
121
  return arr;
121
122
  }
122
123
  class APIServiceFactory {
123
- constructor(fetcher2) {
124
+ constructor(fetcher2, shopifyAPI) {
124
125
  __publicField(this, "isAuthenticated");
125
126
  __publicField(this, "fetcher");
127
+ __publicField(this, "shopifyAPI");
126
128
  __publicField(this, "org");
127
129
  __publicField(this, "apiKey");
128
130
  this.isAuthenticated = false;
129
131
  this.fetcher = fetcher2;
132
+ this.shopifyAPI = shopifyAPI;
130
133
  }
131
134
  /**
132
135
  *
@@ -209,6 +212,25 @@ var __publicField = (obj, key, value) => {
209
212
  await this.fetcher.Post(url, bodyData);
210
213
  }
211
214
  }
215
+ async HandleShopifyAddToCart(items) {
216
+ let formData = {
217
+ "items": items
218
+ };
219
+ await this.shopifyAPI.Post(formData);
220
+ }
221
+ // async AddToShopifyCart(item: string, iterator: number){
222
+ // setTimeout( async () => {
223
+ // console.log(item);
224
+ // //splitting the available_ids
225
+ // var formContents = item.split('-');
226
+ // //[0] returns the variant id to add to cart
227
+ // //[1] returns the quantity to add to cart
228
+ // const data = 'quantity=' + formContents[1] + '&id=' + formContents[0];
229
+ // await this.shopifyAPI.Post(data);
230
+ // }, 1000 * iterator);
231
+ // //1000 * iterator means this code fires 1 seconds after each iteration which makes sure addition of add to cart is
232
+ // //successful
233
+ // }
212
234
  }
213
235
  var ESDKStatus = /* @__PURE__ */ ((ESDKStatus2) => {
214
236
  ESDKStatus2["Init"] = "init";
@@ -1003,38 +1025,37 @@ var __publicField = (obj, key, value) => {
1003
1025
  (item) => item.key == "baseCurve"
1004
1026
  );
1005
1027
  let lensVariantKey = "variantId";
1006
- if (baseCurve.value == "2B") {
1028
+ if (baseCurve && baseCurve.value == "2B") {
1007
1029
  lensVariantKey = "2bVariantId";
1008
- } else if (baseCurve.value == "6B") {
1030
+ } else if (baseCurve && baseCurve.value == "6B") {
1009
1031
  lensVariantKey = "6bVariantId";
1010
1032
  }
1011
1033
  const lensVariantId = selectedLens.metadata.find(
1012
1034
  (item) => item.key == lensVariantKey
1013
1035
  );
1014
- const frameId = frameVariantId ? frameVariantId.value : null;
1015
- const lensId = lensVariantId ? lensVariantId.value : null;
1036
+ const frameId = frameVariantId ? Number(frameVariantId.value) : null;
1037
+ const lensId = lensVariantId ? Number(lensVariantId.value) : null;
1016
1038
  const eventData = {
1017
1039
  frameIdentifier: frameId,
1018
1040
  lensIdentifier: lensId
1019
1041
  };
1020
1042
  customEvent.emitEvent("onAddToCart", eventData);
1021
- if (frameId) {
1022
- if (lensId) {
1023
- window.open(
1024
- "https://dita.com/cart/" + frameId + ":1," + lensId + ":1",
1025
- "_self"
1026
- );
1027
- } else {
1028
- window.open(
1029
- "https://dita.com/cart/" + frameId + ":1",
1030
- "_self"
1031
- );
1032
- }
1033
- } else {
1034
- console.log(
1035
- "Either the selected frame or the lens has an invalid identifier."
1036
- );
1043
+ var cartItems = [];
1044
+ if (frameVariantId) {
1045
+ var frameItem = {
1046
+ id: frameId,
1047
+ quantity: 1
1048
+ };
1049
+ cartItems.push(frameItem);
1050
+ }
1051
+ if (lensVariantId) {
1052
+ var lensItem = {
1053
+ id: lensId,
1054
+ quantity: 1
1055
+ };
1056
+ cartItems.push(lensItem);
1037
1057
  }
1058
+ apiService2.HandleShopifyAddToCart(cartItems);
1038
1059
  }
1039
1060
  },
1040
1061
  type: "button",
@@ -42895,18 +42916,18 @@ bool bvhIntersectFirstHit(
42895
42916
  this.isInitialised = true;
42896
42917
  }
42897
42918
  resizeRenderer() {
42898
- var _a;
42919
+ var _a2;
42899
42920
  const pixelRatio = Math.min(window.devicePixelRatio, 2);
42900
42921
  const resoWidth = Math.floor(this.canvas.clientWidth * pixelRatio);
42901
42922
  const resoHeight = Math.floor(this.canvas.clientHeight * pixelRatio);
42902
42923
  const needResize = this.canvas.width !== resoWidth || this.canvas.height !== resoHeight;
42903
42924
  if (needResize) {
42904
- (_a = this.renderer) == null ? void 0 : _a.setSize(resoWidth, resoHeight, false);
42925
+ (_a2 = this.renderer) == null ? void 0 : _a2.setSize(resoWidth, resoHeight, false);
42905
42926
  }
42906
42927
  return needResize;
42907
42928
  }
42908
42929
  initGemstoneDependencies() {
42909
- var _a;
42930
+ var _a2;
42910
42931
  rgbeLoader.load(
42911
42932
  "https://sprie-jarvis-public.s3.eu-west-2.amazonaws.com/environment_gemstones.hdr",
42912
42933
  (reflectionMap) => {
@@ -42921,7 +42942,7 @@ bool bvhIntersectFirstHit(
42921
42942
  gemstoneMaterial.uniforms.resolution.value = this.canvasSize;
42922
42943
  const temp5 = {};
42923
42944
  const isCubeMap = isCubeTexture(envMap);
42924
- const w2 = (isCubeMap ? (_a = envMap == null ? void 0 : envMap.image[0]) == null ? void 0 : _a.width : envMap == null ? void 0 : envMap.image.width) ?? 1024;
42945
+ const w2 = (isCubeMap ? (_a2 = envMap == null ? void 0 : envMap.image[0]) == null ? void 0 : _a2.width : envMap == null ? void 0 : envMap.image.width) ?? 1024;
42925
42946
  const cubeSize = w2 / 4;
42926
42947
  const _lodMax = Math.floor(Math.log2(cubeSize));
42927
42948
  const _cubeSize = Math.pow(2, _lodMax);
@@ -43361,11 +43382,11 @@ bool bvhIntersectFirstHit(
43361
43382
  composer.addPass(renderPass);
43362
43383
  composer.addPass(outputPass);
43363
43384
  const animate = () => {
43364
- var _a;
43385
+ var _a2;
43365
43386
  controls.update();
43366
43387
  if (this.resizeRenderer()) {
43367
43388
  this.camera.aspect = this.canvas.clientWidth / this.canvas.clientHeight;
43368
- (_a = this.camera) == null ? void 0 : _a.updateProjectionMatrix();
43389
+ (_a2 = this.camera) == null ? void 0 : _a2.updateProjectionMatrix();
43369
43390
  }
43370
43391
  const initialBackground = this.scene.background;
43371
43392
  this.scene.background = null;
@@ -43537,9 +43558,9 @@ bool bvhIntersectFirstHit(
43537
43558
  const orgName = (settings == null ? void 0 : settings.orgName) || "";
43538
43559
  reactExports.useEffect(() => {
43539
43560
  (async () => {
43540
- var _a;
43561
+ var _a2;
43541
43562
  configurator.current = new ThreeDConfigurator();
43542
- await ((_a = configurator.current) == null ? void 0 : _a.Init(apiService2.apiKey));
43563
+ await ((_a2 = configurator.current) == null ? void 0 : _a2.Init(apiService2.apiKey));
43543
43564
  const apiRes = await apiService2.FetchAssetBySKUOrBarcode({
43544
43565
  sku,
43545
43566
  barcode: null
@@ -51234,6 +51255,52 @@ bool bvhIntersectFirstHit(
51234
51255
  onAddToCart: "add-to-cart"
51235
51256
  });
51236
51257
  let CustomEventEmitter = _CustomEventEmitter2;
51258
+ const ShopifyConfig = {
51259
+ cartUrl: ((_a = window.Shopify) == null ? void 0 : _a.routes.root) + "/cart/add.js"
51260
+ };
51261
+ const configShopify = Object.freeze(ShopifyConfig);
51262
+ class ShopifyServiceFactory {
51263
+ constructor(config2) {
51264
+ __publicField(this, "config");
51265
+ this.config = config2;
51266
+ }
51267
+ RequestOptions(method, data) {
51268
+ const headers = {
51269
+ Accept: "application/json",
51270
+ "Content-Type": "application/json"
51271
+ };
51272
+ return {
51273
+ method,
51274
+ headers,
51275
+ ...method === "POST" && {
51276
+ body: JSON.stringify(data)
51277
+ }
51278
+ };
51279
+ }
51280
+ // /**
51281
+ // * @description nice and tidy reuqest wrapper
51282
+ // * @param {string} url CActual URL
51283
+ // * @returns
51284
+ // */
51285
+ // public async Get<T>(url: RequestInfo) {
51286
+ // const response = await fetch(this.config.HOST + url, this.RequestOptions('GET'));
51287
+ // const result = await response.json();
51288
+ // return result as T;
51289
+ // }
51290
+ /**
51291
+ * @description nice and tidy reuqest wrapper
51292
+ * @param {object} data body Data
51293
+ * @returns
51294
+ */
51295
+ async Post(data) {
51296
+ await fetch(this.config.cartUrl, this.RequestOptions("POST", data || {})).then((response) => {
51297
+ const result = response.json();
51298
+ return result;
51299
+ }).catch((e) => {
51300
+ console.error("Error:", e);
51301
+ });
51302
+ }
51303
+ }
51237
51304
  const { log, error } = console;
51238
51305
  const logErr = (...data) => {
51239
51306
  error("❌ Sprie Error:", ...data);
@@ -51243,6 +51310,9 @@ bool bvhIntersectFirstHit(
51243
51310
  HOST: config$1.host,
51244
51311
  STORE_PREFIX: config$1.storePrefix
51245
51312
  };
51313
+ const shopifyConfig = {
51314
+ cartUrl: configShopify.cartUrl
51315
+ };
51246
51316
  class DitaConfiguratorPublicAPI {
51247
51317
  constructor() {
51248
51318
  __publicField(this, "sdkService");
@@ -51250,7 +51320,7 @@ bool bvhIntersectFirstHit(
51250
51320
  __publicField(this, "uiService");
51251
51321
  __publicField(this, "events");
51252
51322
  this.events = new CustomEventEmitter();
51253
- this.apiService = new APIServiceFactory(new FetcherServiceFactory(fetcherConfig));
51323
+ this.apiService = new APIServiceFactory(new FetcherServiceFactory(fetcherConfig), new ShopifyServiceFactory(shopifyConfig));
51254
51324
  this.uiService = new UIService({
51255
51325
  apiService: this.apiService,
51256
51326
  events: this.events
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perceptimagery/dita-configurator-staging",
3
- "version": "0.1.9001",
3
+ "version": "0.2.0000",
4
4
  "author": "Rohan Satpute <rohan@perceptimagery.com>",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",