@perceptimagery/dita-configurator-staging 0.2.0 → 0.2.1205

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 +29 -36
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -18,7 +18,7 @@ var __publicField = (obj, key, value) => {
18
18
  return value;
19
19
  };
20
20
  (function() {
21
- var _a;
21
+ var _a, _b;
22
22
  "use strict";
23
23
  class FetcherServiceFactory {
24
24
  constructor(config2) {
@@ -112,7 +112,7 @@ var __publicField = (obj, key, value) => {
112
112
  host: "https://api.sprie.io"
113
113
  };
114
114
  const config$1 = Object.freeze(Config$2);
115
- const version$1 = "0.2.0000";
115
+ const version$1 = "0.2.1205";
116
116
  function modifyLensArr$1(arr, element) {
117
117
  const index = arr.findIndex((e) => e["sku"] === element["sku"]);
118
118
  if (index !== -1) {
@@ -214,23 +214,18 @@ var __publicField = (obj, key, value) => {
214
214
  }
215
215
  async HandleShopifyAddToCart(items) {
216
216
  let formData = {
217
- "items": items
217
+ "items": items,
218
+ "sections": "mini-cart"
218
219
  };
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
- // }
220
+ const responseData = await this.shopifyAPI.Post(formData);
221
+ if (responseData) {
222
+ const cart = await this.shopifyAPI.Get();
223
+ document.querySelector("#shopify-section-mini-cart").outerHTML = responseData.sections["mini-cart"];
224
+ document.querySelector(".header__cart-count").textContent = cart.item_count;
225
+ document.querySelector(".drawer.drawer--full").removeAttribute("open");
226
+ document.querySelector(".mini-cart.drawer.drawer--large").setAttribute("open", "");
227
+ }
228
+ }
234
229
  }
235
230
  var ESDKStatus = /* @__PURE__ */ ((ESDKStatus2) => {
236
231
  ESDKStatus2["Init"] = "init";
@@ -51256,7 +51251,8 @@ bool bvhIntersectFirstHit(
51256
51251
  });
51257
51252
  let CustomEventEmitter = _CustomEventEmitter2;
51258
51253
  const ShopifyConfig = {
51259
- cartUrl: ((_a = window.Shopify) == null ? void 0 : _a.routes.root) + "/cart/add.js"
51254
+ getCartUrl: ((_a = window.Shopify) == null ? void 0 : _a.routes.root) + "/cart.js",
51255
+ addToCartUrl: ((_b = window.Shopify) == null ? void 0 : _b.routes.root) + "/cart/add.js"
51260
51256
  };
51261
51257
  const configShopify = Object.freeze(ShopifyConfig);
51262
51258
  class ShopifyServiceFactory {
@@ -51277,28 +51273,24 @@ bool bvhIntersectFirstHit(
51277
51273
  }
51278
51274
  };
51279
51275
  }
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
- // }
51276
+ /**
51277
+ * @description nice and tidy reuqest wrapper
51278
+ * @returns
51279
+ */
51280
+ async Get() {
51281
+ const response = await fetch(this.config.getCartUrl, this.RequestOptions("GET"));
51282
+ const result = response.json();
51283
+ return result;
51284
+ }
51290
51285
  /**
51291
51286
  * @description nice and tidy reuqest wrapper
51292
51287
  * @param {object} data body Data
51293
51288
  * @returns
51294
51289
  */
51295
51290
  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
- });
51291
+ const response = await fetch(this.config.addToCartUrl, this.RequestOptions("POST", data || {}));
51292
+ const result = response.json();
51293
+ return result;
51302
51294
  }
51303
51295
  }
51304
51296
  const { log, error } = console;
@@ -51311,7 +51303,8 @@ bool bvhIntersectFirstHit(
51311
51303
  STORE_PREFIX: config$1.storePrefix
51312
51304
  };
51313
51305
  const shopifyConfig = {
51314
- cartUrl: configShopify.cartUrl
51306
+ addToCartUrl: configShopify.addToCartUrl,
51307
+ getCartUrl: configShopify.getCartUrl
51315
51308
  };
51316
51309
  class DitaConfiguratorPublicAPI {
51317
51310
  constructor() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perceptimagery/dita-configurator-staging",
3
- "version": "0.2.0000",
3
+ "version": "0.2.1205",
4
4
  "author": "Rohan Satpute <rohan@perceptimagery.com>",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",