@ikas/storefront 0.1.22-alpha.8 → 0.1.23-alpha.1

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.
package/build/index.js CHANGED
@@ -23056,424 +23056,6 @@ var CreditCardData = /** @class */ (function () {
23056
23056
  return CreditCardData;
23057
23057
  }());
23058
23058
 
23059
- /**
23060
- * Flattens `array` a single level deep.
23061
- *
23062
- * @static
23063
- * @memberOf _
23064
- * @since 0.1.0
23065
- * @category Array
23066
- * @param {Array} array The array to flatten.
23067
- * @returns {Array} Returns the new flattened array.
23068
- * @example
23069
- *
23070
- * _.flatten([1, [2, [3, [4]], 5]]);
23071
- * // => [1, 2, [3, [4]], 5]
23072
- */
23073
- function flatten(array) {
23074
- var length = array == null ? 0 : array.length;
23075
- return length ? _baseFlatten(array, 1) : [];
23076
- }
23077
-
23078
- var flatten_1 = flatten;
23079
-
23080
- var CART_LS_KEY = "cartId";
23081
- var CHECKOUT_LS_KEY = "checkoutId";
23082
- var IkasCartStore = /** @class */ (function () {
23083
- function IkasCartStore(baseStore) {
23084
- var _this = this;
23085
- this.cart = null;
23086
- this._checkoutId = null;
23087
- this._isLoadingCart = false;
23088
- this._cartLoadFinished = false;
23089
- this.getCart = function () { return __awaiter(_this, void 0, void 0, function () {
23090
- var customerId, cartId, cart, err_1;
23091
- var _a, _b;
23092
- return __generator(this, function (_c) {
23093
- switch (_c.label) {
23094
- case 0:
23095
- if (!this.isBrowser)
23096
- return [2 /*return*/];
23097
- _c.label = 1;
23098
- case 1:
23099
- _c.trys.push([1, 6, 7, 8]);
23100
- this._isLoadingCart = true;
23101
- customerId = (_a = this.baseStore.customerStore.customer) === null || _a === void 0 ? void 0 : _a.id;
23102
- cartId = ((_b = this.cart) === null || _b === void 0 ? void 0 : _b.id) || localStorage.getItem(CART_LS_KEY);
23103
- if (!cartId && !customerId)
23104
- return [2 /*return*/];
23105
- return [4 /*yield*/, IkasCartAPI.getCart(cartId || undefined
23106
- // customerId || undefined // TODO reopen this when we have a way of telling backend that we cleared a cart
23107
- )];
23108
- case 2:
23109
- cart = _c.sent();
23110
- if (!cart) return [3 /*break*/, 4];
23111
- return [4 /*yield*/, this.setCart(cart)];
23112
- case 3:
23113
- _c.sent();
23114
- return [3 /*break*/, 5];
23115
- case 4:
23116
- this.removeCart();
23117
- _c.label = 5;
23118
- case 5: return [3 /*break*/, 8];
23119
- case 6:
23120
- err_1 = _c.sent();
23121
- console.log(err_1);
23122
- return [3 /*break*/, 8];
23123
- case 7:
23124
- this._isLoadingCart = false;
23125
- this._cartLoadFinished = true;
23126
- return [7 /*endfinally*/];
23127
- case 8: return [2 /*return*/];
23128
- }
23129
- });
23130
- }); };
23131
- this.setCart = function (cart) { return __awaiter(_this, void 0, void 0, function () {
23132
- var checkoutId;
23133
- return __generator(this, function (_a) {
23134
- switch (_a.label) {
23135
- case 0:
23136
- localStorage.setItem(CART_LS_KEY, cart.id);
23137
- this.cart = cart;
23138
- if (!this._checkoutId)
23139
- this._checkoutId = localStorage.getItem(CHECKOUT_LS_KEY) || undefined;
23140
- if (!!this._checkoutId) return [3 /*break*/, 2];
23141
- return [4 /*yield*/, IkasCheckoutAPI.getCheckoutId(cart.id)];
23142
- case 1:
23143
- checkoutId = _a.sent();
23144
- this._checkoutId = checkoutId;
23145
- if (checkoutId)
23146
- localStorage.setItem(CHECKOUT_LS_KEY, checkoutId);
23147
- _a.label = 2;
23148
- case 2: return [2 /*return*/];
23149
- }
23150
- });
23151
- }); };
23152
- this.beforeCartOperationCheck = function () { return __awaiter(_this, void 0, void 0, function () {
23153
- var cartId;
23154
- return __generator(this, function (_a) {
23155
- switch (_a.label) {
23156
- case 0:
23157
- cartId = localStorage.getItem(CART_LS_KEY);
23158
- if (!(this.cart && !cartId)) return [3 /*break*/, 1];
23159
- this.removeCart();
23160
- return [3 /*break*/, 3];
23161
- case 1:
23162
- if (!(!this.cart && !!cartId)) return [3 /*break*/, 3];
23163
- return [4 /*yield*/, this.getCart()];
23164
- case 2:
23165
- _a.sent();
23166
- _a.label = 3;
23167
- case 3: return [2 /*return*/];
23168
- }
23169
- });
23170
- }); };
23171
- this.addItem = function (variant, product, initialQuantity) {
23172
- if (initialQuantity === void 0) { initialQuantity = 1; }
23173
- return __awaiter(_this, void 0, void 0, function () {
23174
- var existingItem, cartId, input, cart, eventId, item, err_2;
23175
- var _a, _b, _c;
23176
- return __generator(this, function (_d) {
23177
- switch (_d.label) {
23178
- case 0:
23179
- _d.trys.push([0, 5, , 6]);
23180
- return [4 /*yield*/, this.beforeCartOperationCheck()];
23181
- case 1:
23182
- _d.sent();
23183
- if (this.cart) {
23184
- existingItem = this.cart.items.find(function (item) { return item.variant.id === variant.id; });
23185
- if (existingItem) {
23186
- return [2 /*return*/, this.changeItemQuantity(existingItem, existingItem.quantity + 1)];
23187
- }
23188
- }
23189
- cartId = ((_a = this.cart) === null || _a === void 0 ? void 0 : _a.id) || localStorage.getItem(CART_LS_KEY);
23190
- input = {
23191
- cartId: cartId,
23192
- customerId: ((_b = this.cart) === null || _b === void 0 ? void 0 : _b.customerId) || ((_c = this.baseStore.customerStore.customer) === null || _c === void 0 ? void 0 : _c.id) ||
23193
- null,
23194
- item: {
23195
- id: null,
23196
- quantity: initialQuantity,
23197
- variant: {
23198
- id: variant.id,
23199
- name: product.name,
23200
- },
23201
- },
23202
- priceListId: IkasStorefrontConfig.priceListId || null,
23203
- salesChannelId: IkasStorefrontConfig.salesChannelId,
23204
- storefrontId: IkasStorefrontConfig.storefrontId,
23205
- storefrontRoutingId: IkasStorefrontConfig.storefrontRoutingId,
23206
- storefrontThemeId: IkasStorefrontConfig.storefrontThemeId,
23207
- };
23208
- return [4 /*yield*/, IkasCartAPI.saveItemToCart(input)];
23209
- case 2:
23210
- cart = _d.sent();
23211
- if (!cart) return [3 /*break*/, 4];
23212
- return [4 /*yield*/, this.setCart(cart)];
23213
- case 3:
23214
- _d.sent();
23215
- _d.label = 4;
23216
- case 4:
23217
- if (this.cart) {
23218
- eventId = this.cart.id + "-" + this.cart.updatedAt;
23219
- item = this.cart.items.find(function (i) { return i.variant.id; });
23220
- if (item) {
23221
- Analytics.addToCart(item, initialQuantity, eventId, this.cart);
23222
- }
23223
- }
23224
- return [3 /*break*/, 6];
23225
- case 5:
23226
- err_2 = _d.sent();
23227
- console.log(err_2);
23228
- return [3 /*break*/, 6];
23229
- case 6: return [2 /*return*/];
23230
- }
23231
- });
23232
- });
23233
- };
23234
- this.changeItemQuantity = function (item, quantity) { return __awaiter(_this, void 0, void 0, function () {
23235
- var input, cart, eventId, oldQuantity, err_3;
23236
- var _a, _b, _c;
23237
- return __generator(this, function (_d) {
23238
- switch (_d.label) {
23239
- case 0:
23240
- _d.trys.push([0, 5, , 6]);
23241
- return [4 /*yield*/, this.beforeCartOperationCheck()];
23242
- case 1:
23243
- _d.sent();
23244
- input = {
23245
- cartId: ((_a = this.cart) === null || _a === void 0 ? void 0 : _a.id) || null,
23246
- customerId: ((_b = this.cart) === null || _b === void 0 ? void 0 : _b.customerId) || ((_c = this.baseStore.customerStore.customer) === null || _c === void 0 ? void 0 : _c.id) ||
23247
- null,
23248
- item: {
23249
- id: item.id,
23250
- quantity: quantity,
23251
- variant: {
23252
- id: item.variant.id,
23253
- name: item.variant.name,
23254
- },
23255
- },
23256
- priceListId: IkasStorefrontConfig.priceListId || null,
23257
- salesChannelId: IkasStorefrontConfig.salesChannelId,
23258
- storefrontId: IkasStorefrontConfig.storefrontId,
23259
- storefrontRoutingId: IkasStorefrontConfig.storefrontRoutingId,
23260
- storefrontThemeId: IkasStorefrontConfig.storefrontThemeId,
23261
- };
23262
- return [4 /*yield*/, IkasCartAPI.saveItemToCart(input)];
23263
- case 2:
23264
- cart = _d.sent();
23265
- if (!cart) return [3 /*break*/, 4];
23266
- return [4 /*yield*/, this.setCart(cart)];
23267
- case 3:
23268
- _d.sent();
23269
- _d.label = 4;
23270
- case 4:
23271
- this.removeCardIfEmpty();
23272
- if (this.cart) {
23273
- eventId = this.cart.id + "-" + this.cart.updatedAt;
23274
- oldQuantity = item.quantity;
23275
- if (oldQuantity > quantity) {
23276
- Analytics.removeFromCart(item, oldQuantity - quantity, this.cart);
23277
- }
23278
- else {
23279
- Analytics.addToCart(item, quantity - oldQuantity, eventId, this.cart);
23280
- }
23281
- }
23282
- return [3 /*break*/, 6];
23283
- case 5:
23284
- err_3 = _d.sent();
23285
- console.log(err_3);
23286
- return [3 /*break*/, 6];
23287
- case 6: return [2 /*return*/];
23288
- }
23289
- });
23290
- }); };
23291
- this.removeItem = function (item) { return __awaiter(_this, void 0, void 0, function () {
23292
- return __generator(this, function (_a) {
23293
- switch (_a.label) {
23294
- case 0: return [4 /*yield*/, this.changeItemQuantity(item, 0)];
23295
- case 1:
23296
- _a.sent();
23297
- return [2 /*return*/];
23298
- }
23299
- });
23300
- }); };
23301
- this.removeCardIfEmpty = function () {
23302
- var _a;
23303
- if (((_a = _this.cart) === null || _a === void 0 ? void 0 : _a.itemCount) === 0) {
23304
- _this.removeCart();
23305
- }
23306
- };
23307
- this.removeCart = function () {
23308
- localStorage.removeItem(CART_LS_KEY);
23309
- localStorage.removeItem(CHECKOUT_LS_KEY);
23310
- _this.cart = undefined;
23311
- _this._checkoutId = undefined;
23312
- };
23313
- this.waitUntilInitialized = function () {
23314
- return new Promise(function (resolve) {
23315
- var interval = setInterval(function () {
23316
- if (_this.cartLoadFinished) {
23317
- clearInterval(interval);
23318
- resolve(null);
23319
- }
23320
- }, 100);
23321
- });
23322
- };
23323
- this.baseStore = baseStore;
23324
- mobx.makeAutoObservable(this);
23325
- }
23326
- Object.defineProperty(IkasCartStore.prototype, "isBrowser", {
23327
- get: function () {
23328
- return typeof localStorage !== "undefined";
23329
- },
23330
- enumerable: false,
23331
- configurable: true
23332
- });
23333
- Object.defineProperty(IkasCartStore.prototype, "isLoadingCart", {
23334
- get: function () {
23335
- return this._isLoadingCart;
23336
- },
23337
- enumerable: false,
23338
- configurable: true
23339
- });
23340
- Object.defineProperty(IkasCartStore.prototype, "cartLoadFinished", {
23341
- get: function () {
23342
- return this._cartLoadFinished;
23343
- },
23344
- enumerable: false,
23345
- configurable: true
23346
- });
23347
- Object.defineProperty(IkasCartStore.prototype, "checkoutId", {
23348
- get: function () {
23349
- return this._checkoutId;
23350
- },
23351
- enumerable: false,
23352
- configurable: true
23353
- });
23354
- Object.defineProperty(IkasCartStore.prototype, "checkoutUrl", {
23355
- get: function () {
23356
- if (this._checkoutId)
23357
- return "/checkout?id=" + this._checkoutId + "&step=info";
23358
- },
23359
- enumerable: false,
23360
- configurable: true
23361
- });
23362
- return IkasCartStore;
23363
- }());
23364
-
23365
- mobx.configure({
23366
- enforceActions: "never",
23367
- });
23368
- var IkasBaseStore = /** @class */ (function () {
23369
- function IkasBaseStore() {
23370
- this.currentPageType = null;
23371
- this.localeOptions = [];
23372
- this.showLocaleOptions = false;
23373
- this.currentCountryCode = null;
23374
- this.localeChecked = false;
23375
- this.settingsSet = false;
23376
- this.customerStore = new IkasCustomerStore(this);
23377
- this.cartStore = new IkasCartStore(this);
23378
- mobx.makeObservable(this, {
23379
- currentPageType: mobx.observable,
23380
- localeOptions: mobx.observable,
23381
- showLocaleOptions: mobx.observable,
23382
- currentCountryCode: mobx.observable,
23383
- });
23384
- }
23385
- IkasBaseStore.prototype.checkLocalization = function () {
23386
- return __awaiter(this, void 0, void 0, function () {
23387
- var myCountryCode, currentRouting, isCorrectLocale, myCountryRouting, otherCountriesRouting, iso2Codes, countries_1, localeOptions_1;
23388
- return __generator(this, function (_a) {
23389
- switch (_a.label) {
23390
- case 0:
23391
- if (this.localeChecked)
23392
- return [2 /*return*/];
23393
- if (typeof window === undefined) {
23394
- console.warn("checkLocalization should be called on the client side!");
23395
- return [2 /*return*/];
23396
- }
23397
- return [4 /*yield*/, IkasCountryAPI.getMyCountry()];
23398
- case 1:
23399
- myCountryCode = _a.sent();
23400
- currentRouting = IkasStorefrontConfig.routings.find(function (r) { return r.id === IkasStorefrontConfig.storefrontRoutingId; });
23401
- this.currentCountryCode = myCountryCode;
23402
- if (!(currentRouting && myCountryCode)) return [3 /*break*/, 3];
23403
- isCorrectLocale = true;
23404
- myCountryRouting = IkasStorefrontConfig.routings.find(function (r) { var _a; return (_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.includes(myCountryCode); });
23405
- otherCountriesRouting = IkasStorefrontConfig.routings.find(function (r) { var _a; return !((_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.length); });
23406
- // Current country has spefic routing
23407
- if (myCountryRouting) {
23408
- if (currentRouting.id !== myCountryRouting.id) {
23409
- isCorrectLocale = false;
23410
- }
23411
- }
23412
- // Current country does not have specific routing
23413
- else {
23414
- if (otherCountriesRouting &&
23415
- currentRouting.id !== otherCountriesRouting.id) {
23416
- isCorrectLocale = false;
23417
- }
23418
- }
23419
- iso2Codes = flatten_1(IkasStorefrontConfig.routings.map(function (r) { return r.countryCodes || []; }));
23420
- return [4 /*yield*/, IkasCountryAPI.listCountries(iso2Codes)];
23421
- case 2:
23422
- countries_1 = _a.sent();
23423
- localeOptions_1 = [];
23424
- IkasStorefrontConfig.routings.map(function (r) {
23425
- var _a;
23426
- if ((_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.length) {
23427
- r.countryCodes.forEach(function (countryCode) {
23428
- var _a;
23429
- var country = countries_1.find(function (c) { return c.iso2 === countryCode; });
23430
- localeOptions_1.push({
23431
- id: v4(),
23432
- countryName: (country === null || country === void 0 ? void 0 : country.native) || (country === null || country === void 0 ? void 0 : country.name) || "",
23433
- routing: r,
23434
- isRecommended: ((_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.includes(myCountryCode)) || false,
23435
- });
23436
- });
23437
- }
23438
- else {
23439
- localeOptions_1.push({
23440
- id: v4(),
23441
- routing: r,
23442
- isRecommended: !IkasStorefrontConfig.routings.some(function (r) { var _a; return (_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.includes(myCountryCode); }),
23443
- });
23444
- }
23445
- });
23446
- this.localeOptions = sortBy_1(localeOptions_1, "countryName");
23447
- if (!isCorrectLocale) {
23448
- this.showLocaleOptions = true;
23449
- }
23450
- this.localeChecked = true;
23451
- _a.label = 3;
23452
- case 3: return [2 /*return*/];
23453
- }
23454
- });
23455
- });
23456
- };
23457
- IkasBaseStore.prototype.setLocalization = function (localeOption) {
23458
- if (localeOption.routing.domain) {
23459
- window.location.replace("https://" + localeOption.routing.domain);
23460
- }
23461
- else {
23462
- window.location.replace(window.location.origin +
23463
- (localeOption.routing.path ? "/" + localeOption.routing.path : ""));
23464
- }
23465
- };
23466
- IkasBaseStore.prototype.setSettings = function (settingsStr) {
23467
- if (this.settingsSet)
23468
- return;
23469
- var settings = new IkasThemeSettings(JSON.parse(settingsStr));
23470
- settings.colors.map(function (sc) {
23471
- return document.documentElement.style.setProperty(sc.key, sc.color);
23472
- });
23473
- };
23474
- return IkasBaseStore;
23475
- }());
23476
-
23477
23059
  var NUMBER_ONLY_REGEX = /^\d+$/;
23478
23060
  var MAX_CARD_NUMBER_LENGTH = 16;
23479
23061
  var MAX_CVC_LENGTH = 4;
@@ -23485,7 +23067,7 @@ var CheckoutViewModel = /** @class */ (function () {
23485
23067
  this.checkout = new IkasCheckout();
23486
23068
  this.checkoutSettings = new IkasCheckoutSettings();
23487
23069
  this.storefront = null;
23488
- this.store = new IkasBaseStore();
23070
+ this.store = IkasStorefrontConfig.store;
23489
23071
  this.isCheckoutLoaded = false;
23490
23072
  this.isErrorsVisible = false;
23491
23073
  this.isStepLoading = false;
@@ -33976,8 +33558,10 @@ var IkasCustomerStore = /** @class */ (function () {
33976
33558
  });
33977
33559
  };
33978
33560
  IkasCustomerStore.prototype.routeChangeInit = function () {
33979
- if (!this.customer)
33980
- this.init();
33561
+ if (!this.customer) {
33562
+ this.loadToken();
33563
+ this.getCustomer();
33564
+ }
33981
33565
  };
33982
33566
  IkasCustomerStore.prototype.getCustomer = function () {
33983
33567
  return __awaiter(this, void 0, void 0, function () {
@@ -45595,8 +45179,6 @@ var IkasPage = mobxReactLite.observer(function (_a) {
45595
45179
  IkasStorefrontConfig.store.customerStore.routeChangeInit();
45596
45180
  };
45597
45181
  router$1.events.on("routeChangeStart", handleRouteChange);
45598
- // If the component is unmounted, unsubscribe
45599
- // from the event with the `off` method:
45600
45182
  return function () {
45601
45183
  router$1.events.off("routeChangeStart", handleRouteChange);
45602
45184
  };
@@ -70006,7 +69588,7 @@ var Coupon = mobxReactLite.observer(function (_a) {
70006
69588
  case 0:
70007
69589
  vm.checkout.couponCode = null;
70008
69590
  setLoadingCoupon(true);
70009
- return [4 /*yield*/, vm.onCouponCodeApply()];
69591
+ return [4 /*yield*/, vm.saveCheckout()];
70010
69592
  case 1:
70011
69593
  _a.sent();
70012
69594
  setLoadingCoupon(false);
@@ -70063,6 +69645,291 @@ var Note = mobxReactLite.observer(function (_a) {
70063
69645
  isSuccessStep ? (React.createElement("div", { className: styles$g.CheckoutNoteDisplay }, vm.checkout.note)) : (React.createElement(FormItem, { style: { width: "100%" }, type: FormItemType.TEXT_AREA, disableResize: true, label: "", value: vm.checkout.note || "", onChange: onCheckoutNoteChange }))))));
70064
69646
  });
70065
69647
 
69648
+ var CART_LS_KEY = "cartId";
69649
+ var CHECKOUT_LS_KEY = "checkoutId";
69650
+ var IkasCartStore = /** @class */ (function () {
69651
+ function IkasCartStore(baseStore) {
69652
+ var _this = this;
69653
+ this.cart = null;
69654
+ this._checkoutId = null;
69655
+ this._isLoadingCart = false;
69656
+ this._cartLoadFinished = false;
69657
+ this.getCart = function () { return __awaiter(_this, void 0, void 0, function () {
69658
+ var customerId, cartId, cart, err_1;
69659
+ var _a, _b;
69660
+ return __generator(this, function (_c) {
69661
+ switch (_c.label) {
69662
+ case 0:
69663
+ if (!this.isBrowser)
69664
+ return [2 /*return*/];
69665
+ _c.label = 1;
69666
+ case 1:
69667
+ _c.trys.push([1, 6, 7, 8]);
69668
+ this._isLoadingCart = true;
69669
+ customerId = (_a = this.baseStore.customerStore.customer) === null || _a === void 0 ? void 0 : _a.id;
69670
+ cartId = ((_b = this.cart) === null || _b === void 0 ? void 0 : _b.id) || localStorage.getItem(CART_LS_KEY);
69671
+ if (!cartId && !customerId)
69672
+ return [2 /*return*/];
69673
+ return [4 /*yield*/, IkasCartAPI.getCart(cartId || undefined
69674
+ // customerId || undefined // TODO reopen this when we have a way of telling backend that we cleared a cart
69675
+ )];
69676
+ case 2:
69677
+ cart = _c.sent();
69678
+ if (!cart) return [3 /*break*/, 4];
69679
+ return [4 /*yield*/, this.setCart(cart)];
69680
+ case 3:
69681
+ _c.sent();
69682
+ return [3 /*break*/, 5];
69683
+ case 4:
69684
+ this.removeCart();
69685
+ _c.label = 5;
69686
+ case 5: return [3 /*break*/, 8];
69687
+ case 6:
69688
+ err_1 = _c.sent();
69689
+ console.log(err_1);
69690
+ return [3 /*break*/, 8];
69691
+ case 7:
69692
+ this._isLoadingCart = false;
69693
+ this._cartLoadFinished = true;
69694
+ return [7 /*endfinally*/];
69695
+ case 8: return [2 /*return*/];
69696
+ }
69697
+ });
69698
+ }); };
69699
+ this.setCart = function (cart) { return __awaiter(_this, void 0, void 0, function () {
69700
+ var checkoutId;
69701
+ return __generator(this, function (_a) {
69702
+ switch (_a.label) {
69703
+ case 0:
69704
+ localStorage.setItem(CART_LS_KEY, cart.id);
69705
+ this.cart = cart;
69706
+ if (!this._checkoutId)
69707
+ this._checkoutId = localStorage.getItem(CHECKOUT_LS_KEY) || undefined;
69708
+ if (!!this._checkoutId) return [3 /*break*/, 2];
69709
+ return [4 /*yield*/, IkasCheckoutAPI.getCheckoutId(cart.id)];
69710
+ case 1:
69711
+ checkoutId = _a.sent();
69712
+ this._checkoutId = checkoutId;
69713
+ if (checkoutId)
69714
+ localStorage.setItem(CHECKOUT_LS_KEY, checkoutId);
69715
+ _a.label = 2;
69716
+ case 2: return [2 /*return*/];
69717
+ }
69718
+ });
69719
+ }); };
69720
+ this.beforeCartOperationCheck = function () { return __awaiter(_this, void 0, void 0, function () {
69721
+ var cartId;
69722
+ return __generator(this, function (_a) {
69723
+ switch (_a.label) {
69724
+ case 0:
69725
+ cartId = localStorage.getItem(CART_LS_KEY);
69726
+ if (!(this.cart && !cartId)) return [3 /*break*/, 1];
69727
+ this.removeCart();
69728
+ return [3 /*break*/, 3];
69729
+ case 1:
69730
+ if (!(!this.cart && !!cartId)) return [3 /*break*/, 3];
69731
+ return [4 /*yield*/, this.getCart()];
69732
+ case 2:
69733
+ _a.sent();
69734
+ _a.label = 3;
69735
+ case 3: return [2 /*return*/];
69736
+ }
69737
+ });
69738
+ }); };
69739
+ this.addItem = function (variant, product, initialQuantity) {
69740
+ if (initialQuantity === void 0) { initialQuantity = 1; }
69741
+ return __awaiter(_this, void 0, void 0, function () {
69742
+ var existingItem, cartId, input, cart, eventId, item, err_2;
69743
+ var _a, _b, _c;
69744
+ return __generator(this, function (_d) {
69745
+ switch (_d.label) {
69746
+ case 0:
69747
+ _d.trys.push([0, 5, , 6]);
69748
+ return [4 /*yield*/, this.beforeCartOperationCheck()];
69749
+ case 1:
69750
+ _d.sent();
69751
+ if (this.cart) {
69752
+ existingItem = this.cart.items.find(function (item) { return item.variant.id === variant.id; });
69753
+ if (existingItem) {
69754
+ return [2 /*return*/, this.changeItemQuantity(existingItem, existingItem.quantity + 1)];
69755
+ }
69756
+ }
69757
+ cartId = ((_a = this.cart) === null || _a === void 0 ? void 0 : _a.id) || localStorage.getItem(CART_LS_KEY);
69758
+ input = {
69759
+ cartId: cartId,
69760
+ customerId: ((_b = this.cart) === null || _b === void 0 ? void 0 : _b.customerId) || ((_c = this.baseStore.customerStore.customer) === null || _c === void 0 ? void 0 : _c.id) ||
69761
+ null,
69762
+ item: {
69763
+ id: null,
69764
+ quantity: initialQuantity,
69765
+ variant: {
69766
+ id: variant.id,
69767
+ name: product.name,
69768
+ },
69769
+ },
69770
+ priceListId: IkasStorefrontConfig.priceListId || null,
69771
+ salesChannelId: IkasStorefrontConfig.salesChannelId,
69772
+ storefrontId: IkasStorefrontConfig.storefrontId,
69773
+ storefrontRoutingId: IkasStorefrontConfig.storefrontRoutingId,
69774
+ storefrontThemeId: IkasStorefrontConfig.storefrontThemeId,
69775
+ };
69776
+ return [4 /*yield*/, IkasCartAPI.saveItemToCart(input)];
69777
+ case 2:
69778
+ cart = _d.sent();
69779
+ if (!cart) return [3 /*break*/, 4];
69780
+ return [4 /*yield*/, this.setCart(cart)];
69781
+ case 3:
69782
+ _d.sent();
69783
+ _d.label = 4;
69784
+ case 4:
69785
+ if (this.cart) {
69786
+ eventId = this.cart.id + "-" + this.cart.updatedAt;
69787
+ item = this.cart.items.find(function (i) { return i.variant.id; });
69788
+ if (item) {
69789
+ Analytics.addToCart(item, initialQuantity, eventId, this.cart);
69790
+ }
69791
+ }
69792
+ return [3 /*break*/, 6];
69793
+ case 5:
69794
+ err_2 = _d.sent();
69795
+ console.log(err_2);
69796
+ return [3 /*break*/, 6];
69797
+ case 6: return [2 /*return*/];
69798
+ }
69799
+ });
69800
+ });
69801
+ };
69802
+ this.changeItemQuantity = function (item, quantity) { return __awaiter(_this, void 0, void 0, function () {
69803
+ var input, cart, eventId, oldQuantity, err_3;
69804
+ var _a, _b, _c;
69805
+ return __generator(this, function (_d) {
69806
+ switch (_d.label) {
69807
+ case 0:
69808
+ _d.trys.push([0, 5, , 6]);
69809
+ return [4 /*yield*/, this.beforeCartOperationCheck()];
69810
+ case 1:
69811
+ _d.sent();
69812
+ input = {
69813
+ cartId: ((_a = this.cart) === null || _a === void 0 ? void 0 : _a.id) || null,
69814
+ customerId: ((_b = this.cart) === null || _b === void 0 ? void 0 : _b.customerId) || ((_c = this.baseStore.customerStore.customer) === null || _c === void 0 ? void 0 : _c.id) ||
69815
+ null,
69816
+ item: {
69817
+ id: item.id,
69818
+ quantity: quantity,
69819
+ variant: {
69820
+ id: item.variant.id,
69821
+ name: item.variant.name,
69822
+ },
69823
+ },
69824
+ priceListId: IkasStorefrontConfig.priceListId || null,
69825
+ salesChannelId: IkasStorefrontConfig.salesChannelId,
69826
+ storefrontId: IkasStorefrontConfig.storefrontId,
69827
+ storefrontRoutingId: IkasStorefrontConfig.storefrontRoutingId,
69828
+ storefrontThemeId: IkasStorefrontConfig.storefrontThemeId,
69829
+ };
69830
+ return [4 /*yield*/, IkasCartAPI.saveItemToCart(input)];
69831
+ case 2:
69832
+ cart = _d.sent();
69833
+ if (!cart) return [3 /*break*/, 4];
69834
+ return [4 /*yield*/, this.setCart(cart)];
69835
+ case 3:
69836
+ _d.sent();
69837
+ _d.label = 4;
69838
+ case 4:
69839
+ this.removeCardIfEmpty();
69840
+ if (this.cart) {
69841
+ eventId = this.cart.id + "-" + this.cart.updatedAt;
69842
+ oldQuantity = item.quantity;
69843
+ if (oldQuantity > quantity) {
69844
+ Analytics.removeFromCart(item, oldQuantity - quantity, this.cart);
69845
+ }
69846
+ else {
69847
+ Analytics.addToCart(item, quantity - oldQuantity, eventId, this.cart);
69848
+ }
69849
+ }
69850
+ return [3 /*break*/, 6];
69851
+ case 5:
69852
+ err_3 = _d.sent();
69853
+ console.log(err_3);
69854
+ return [3 /*break*/, 6];
69855
+ case 6: return [2 /*return*/];
69856
+ }
69857
+ });
69858
+ }); };
69859
+ this.removeItem = function (item) { return __awaiter(_this, void 0, void 0, function () {
69860
+ return __generator(this, function (_a) {
69861
+ switch (_a.label) {
69862
+ case 0: return [4 /*yield*/, this.changeItemQuantity(item, 0)];
69863
+ case 1:
69864
+ _a.sent();
69865
+ return [2 /*return*/];
69866
+ }
69867
+ });
69868
+ }); };
69869
+ this.removeCardIfEmpty = function () {
69870
+ var _a;
69871
+ if (((_a = _this.cart) === null || _a === void 0 ? void 0 : _a.itemCount) === 0) {
69872
+ _this.removeCart();
69873
+ }
69874
+ };
69875
+ this.removeCart = function () {
69876
+ localStorage.removeItem(CART_LS_KEY);
69877
+ localStorage.removeItem(CHECKOUT_LS_KEY);
69878
+ _this.cart = undefined;
69879
+ _this._checkoutId = undefined;
69880
+ };
69881
+ this.waitUntilInitialized = function () {
69882
+ return new Promise(function (resolve) {
69883
+ var interval = setInterval(function () {
69884
+ if (_this.cartLoadFinished) {
69885
+ clearInterval(interval);
69886
+ resolve(null);
69887
+ }
69888
+ }, 100);
69889
+ });
69890
+ };
69891
+ this.baseStore = baseStore;
69892
+ mobx.makeAutoObservable(this);
69893
+ }
69894
+ Object.defineProperty(IkasCartStore.prototype, "isBrowser", {
69895
+ get: function () {
69896
+ return typeof localStorage !== "undefined";
69897
+ },
69898
+ enumerable: false,
69899
+ configurable: true
69900
+ });
69901
+ Object.defineProperty(IkasCartStore.prototype, "isLoadingCart", {
69902
+ get: function () {
69903
+ return this._isLoadingCart;
69904
+ },
69905
+ enumerable: false,
69906
+ configurable: true
69907
+ });
69908
+ Object.defineProperty(IkasCartStore.prototype, "cartLoadFinished", {
69909
+ get: function () {
69910
+ return this._cartLoadFinished;
69911
+ },
69912
+ enumerable: false,
69913
+ configurable: true
69914
+ });
69915
+ Object.defineProperty(IkasCartStore.prototype, "checkoutId", {
69916
+ get: function () {
69917
+ return this._checkoutId;
69918
+ },
69919
+ enumerable: false,
69920
+ configurable: true
69921
+ });
69922
+ Object.defineProperty(IkasCartStore.prototype, "checkoutUrl", {
69923
+ get: function () {
69924
+ if (this._checkoutId)
69925
+ return "/checkout?id=" + this._checkoutId + "&step=info";
69926
+ },
69927
+ enumerable: false,
69928
+ configurable: true
69929
+ });
69930
+ return IkasCartStore;
69931
+ }());
69932
+
70066
69933
  var styles$h = {"StepSuccess":"style-module_StepSuccess__36Zg4","SuccessTitleContainer":"style-module_SuccessTitleContainer__3fT9P","SuccessTitle":"style-module_SuccessTitle__2cVxj","SuccessSubTitle":"style-module_SuccessSubTitle__2UvWI","InfoGrid":"style-module_InfoGrid__2VYXk","InfoTitle":"style-module_InfoTitle__2Whku","InfoText":"style-module_InfoText__1LHFw","InfoTextBold":"style-module_InfoTextBold__21977","WithBorder":"style-module_WithBorder__1aBHw","CardLogoContainer":"style-module_CardLogoContainer__3tymO","Actions":"style-module_Actions__3ZXaJ","HelpText":"style-module_HelpText__39LA1","Cta":"style-module_Cta__3sxNK","OrderStatus":"style-module_OrderStatus__CPd7s","Yellow":"style-module_Yellow__1mZZm","Green":"style-module_Green__2qwNg","Red":"style-module_Red__TKRy8"};
70067
69934
 
70068
69935
  var SVGSuccessCircle = function (_a) {
@@ -71639,6 +71506,139 @@ var _slug_$3 = /*#__PURE__*/Object.freeze({
71639
71506
  getStaticProps: getStaticProps$h
71640
71507
  });
71641
71508
 
71509
+ /**
71510
+ * Flattens `array` a single level deep.
71511
+ *
71512
+ * @static
71513
+ * @memberOf _
71514
+ * @since 0.1.0
71515
+ * @category Array
71516
+ * @param {Array} array The array to flatten.
71517
+ * @returns {Array} Returns the new flattened array.
71518
+ * @example
71519
+ *
71520
+ * _.flatten([1, [2, [3, [4]], 5]]);
71521
+ * // => [1, 2, [3, [4]], 5]
71522
+ */
71523
+ function flatten(array) {
71524
+ var length = array == null ? 0 : array.length;
71525
+ return length ? _baseFlatten(array, 1) : [];
71526
+ }
71527
+
71528
+ var flatten_1 = flatten;
71529
+
71530
+ mobx.configure({
71531
+ enforceActions: "never",
71532
+ });
71533
+ var IkasBaseStore = /** @class */ (function () {
71534
+ function IkasBaseStore() {
71535
+ this.currentPageType = null;
71536
+ this.localeOptions = [];
71537
+ this.showLocaleOptions = false;
71538
+ this.currentCountryCode = null;
71539
+ this.localeChecked = false;
71540
+ this.settingsSet = false;
71541
+ this.customerStore = new IkasCustomerStore(this);
71542
+ this.cartStore = new IkasCartStore(this);
71543
+ mobx.makeObservable(this, {
71544
+ currentPageType: mobx.observable,
71545
+ localeOptions: mobx.observable,
71546
+ showLocaleOptions: mobx.observable,
71547
+ currentCountryCode: mobx.observable,
71548
+ });
71549
+ }
71550
+ IkasBaseStore.prototype.checkLocalization = function () {
71551
+ return __awaiter(this, void 0, void 0, function () {
71552
+ var myCountryCode, currentRouting, isCorrectLocale, myCountryRouting, otherCountriesRouting, iso2Codes, countries_1, localeOptions_1;
71553
+ return __generator(this, function (_a) {
71554
+ switch (_a.label) {
71555
+ case 0:
71556
+ if (this.localeChecked)
71557
+ return [2 /*return*/];
71558
+ if (typeof window === undefined) {
71559
+ console.warn("checkLocalization should be called on the client side!");
71560
+ return [2 /*return*/];
71561
+ }
71562
+ return [4 /*yield*/, IkasCountryAPI.getMyCountry()];
71563
+ case 1:
71564
+ myCountryCode = _a.sent();
71565
+ currentRouting = IkasStorefrontConfig.routings.find(function (r) { return r.id === IkasStorefrontConfig.storefrontRoutingId; });
71566
+ this.currentCountryCode = myCountryCode;
71567
+ if (!(currentRouting && myCountryCode)) return [3 /*break*/, 3];
71568
+ isCorrectLocale = true;
71569
+ myCountryRouting = IkasStorefrontConfig.routings.find(function (r) { var _a; return (_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.includes(myCountryCode); });
71570
+ otherCountriesRouting = IkasStorefrontConfig.routings.find(function (r) { var _a; return !((_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.length); });
71571
+ // Current country has spefic routing
71572
+ if (myCountryRouting) {
71573
+ if (currentRouting.id !== myCountryRouting.id) {
71574
+ isCorrectLocale = false;
71575
+ }
71576
+ }
71577
+ // Current country does not have specific routing
71578
+ else {
71579
+ if (otherCountriesRouting &&
71580
+ currentRouting.id !== otherCountriesRouting.id) {
71581
+ isCorrectLocale = false;
71582
+ }
71583
+ }
71584
+ iso2Codes = flatten_1(IkasStorefrontConfig.routings.map(function (r) { return r.countryCodes || []; }));
71585
+ return [4 /*yield*/, IkasCountryAPI.listCountries(iso2Codes)];
71586
+ case 2:
71587
+ countries_1 = _a.sent();
71588
+ localeOptions_1 = [];
71589
+ IkasStorefrontConfig.routings.map(function (r) {
71590
+ var _a;
71591
+ if ((_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.length) {
71592
+ r.countryCodes.forEach(function (countryCode) {
71593
+ var _a;
71594
+ var country = countries_1.find(function (c) { return c.iso2 === countryCode; });
71595
+ localeOptions_1.push({
71596
+ id: v4(),
71597
+ countryName: (country === null || country === void 0 ? void 0 : country.native) || (country === null || country === void 0 ? void 0 : country.name) || "",
71598
+ routing: r,
71599
+ isRecommended: ((_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.includes(myCountryCode)) || false,
71600
+ });
71601
+ });
71602
+ }
71603
+ else {
71604
+ localeOptions_1.push({
71605
+ id: v4(),
71606
+ routing: r,
71607
+ isRecommended: !IkasStorefrontConfig.routings.some(function (r) { var _a; return (_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.includes(myCountryCode); }),
71608
+ });
71609
+ }
71610
+ });
71611
+ this.localeOptions = sortBy_1(localeOptions_1, "countryName");
71612
+ if (!isCorrectLocale) {
71613
+ this.showLocaleOptions = true;
71614
+ }
71615
+ this.localeChecked = true;
71616
+ _a.label = 3;
71617
+ case 3: return [2 /*return*/];
71618
+ }
71619
+ });
71620
+ });
71621
+ };
71622
+ IkasBaseStore.prototype.setLocalization = function (localeOption) {
71623
+ if (localeOption.routing.domain) {
71624
+ window.location.replace("https://" + localeOption.routing.domain);
71625
+ }
71626
+ else {
71627
+ window.location.replace(window.location.origin +
71628
+ (localeOption.routing.path ? "/" + localeOption.routing.path : ""));
71629
+ }
71630
+ };
71631
+ IkasBaseStore.prototype.setSettings = function (settingsStr) {
71632
+ if (this.settingsSet)
71633
+ return;
71634
+ var settings = new IkasThemeSettings(JSON.parse(settingsStr));
71635
+ settings.colors.map(function (sc) {
71636
+ return document.documentElement.style.setProperty(sc.key, sc.color);
71637
+ });
71638
+ };
71639
+ return IkasBaseStore;
71640
+ }());
71641
+
71642
71642
  var tr = {
71643
71643
  actions: {
71644
71644
  login: "Giriş Yap",