@ikas/storefront 0.1.22 → 0.1.23-alpha.2

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.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { makeAutoObservable, configure, makeObservable, observable, runInAction, reaction, computed, action } from 'mobx';
1
+ import { makeAutoObservable, runInAction, reaction, makeObservable, computed, observable, action, configure } from 'mobx';
2
2
  import fs from 'fs';
3
3
  import path$1 from 'path';
4
4
  import getConfig from 'next/config';
@@ -23049,424 +23049,6 @@ var CreditCardData = /** @class */ (function () {
23049
23049
  return CreditCardData;
23050
23050
  }());
23051
23051
 
23052
- /**
23053
- * Flattens `array` a single level deep.
23054
- *
23055
- * @static
23056
- * @memberOf _
23057
- * @since 0.1.0
23058
- * @category Array
23059
- * @param {Array} array The array to flatten.
23060
- * @returns {Array} Returns the new flattened array.
23061
- * @example
23062
- *
23063
- * _.flatten([1, [2, [3, [4]], 5]]);
23064
- * // => [1, 2, [3, [4]], 5]
23065
- */
23066
- function flatten(array) {
23067
- var length = array == null ? 0 : array.length;
23068
- return length ? _baseFlatten(array, 1) : [];
23069
- }
23070
-
23071
- var flatten_1 = flatten;
23072
-
23073
- var CART_LS_KEY = "cartId";
23074
- var CHECKOUT_LS_KEY = "checkoutId";
23075
- var IkasCartStore = /** @class */ (function () {
23076
- function IkasCartStore(baseStore) {
23077
- var _this = this;
23078
- this.cart = null;
23079
- this._checkoutId = null;
23080
- this._isLoadingCart = false;
23081
- this._cartLoadFinished = false;
23082
- this.getCart = function () { return __awaiter(_this, void 0, void 0, function () {
23083
- var customerId, cartId, cart, err_1;
23084
- var _a, _b;
23085
- return __generator(this, function (_c) {
23086
- switch (_c.label) {
23087
- case 0:
23088
- if (!this.isBrowser)
23089
- return [2 /*return*/];
23090
- _c.label = 1;
23091
- case 1:
23092
- _c.trys.push([1, 6, 7, 8]);
23093
- this._isLoadingCart = true;
23094
- customerId = (_a = this.baseStore.customerStore.customer) === null || _a === void 0 ? void 0 : _a.id;
23095
- cartId = ((_b = this.cart) === null || _b === void 0 ? void 0 : _b.id) || localStorage.getItem(CART_LS_KEY);
23096
- if (!cartId && !customerId)
23097
- return [2 /*return*/];
23098
- return [4 /*yield*/, IkasCartAPI.getCart(cartId || undefined
23099
- // customerId || undefined // TODO reopen this when we have a way of telling backend that we cleared a cart
23100
- )];
23101
- case 2:
23102
- cart = _c.sent();
23103
- if (!cart) return [3 /*break*/, 4];
23104
- return [4 /*yield*/, this.setCart(cart)];
23105
- case 3:
23106
- _c.sent();
23107
- return [3 /*break*/, 5];
23108
- case 4:
23109
- this.removeCart();
23110
- _c.label = 5;
23111
- case 5: return [3 /*break*/, 8];
23112
- case 6:
23113
- err_1 = _c.sent();
23114
- console.log(err_1);
23115
- return [3 /*break*/, 8];
23116
- case 7:
23117
- this._isLoadingCart = false;
23118
- this._cartLoadFinished = true;
23119
- return [7 /*endfinally*/];
23120
- case 8: return [2 /*return*/];
23121
- }
23122
- });
23123
- }); };
23124
- this.setCart = function (cart) { return __awaiter(_this, void 0, void 0, function () {
23125
- var checkoutId;
23126
- return __generator(this, function (_a) {
23127
- switch (_a.label) {
23128
- case 0:
23129
- localStorage.setItem(CART_LS_KEY, cart.id);
23130
- this.cart = cart;
23131
- if (!this._checkoutId)
23132
- this._checkoutId = localStorage.getItem(CHECKOUT_LS_KEY) || undefined;
23133
- if (!!this._checkoutId) return [3 /*break*/, 2];
23134
- return [4 /*yield*/, IkasCheckoutAPI.getCheckoutId(cart.id)];
23135
- case 1:
23136
- checkoutId = _a.sent();
23137
- this._checkoutId = checkoutId;
23138
- if (checkoutId)
23139
- localStorage.setItem(CHECKOUT_LS_KEY, checkoutId);
23140
- _a.label = 2;
23141
- case 2: return [2 /*return*/];
23142
- }
23143
- });
23144
- }); };
23145
- this.beforeCartOperationCheck = function () { return __awaiter(_this, void 0, void 0, function () {
23146
- var cartId;
23147
- return __generator(this, function (_a) {
23148
- switch (_a.label) {
23149
- case 0:
23150
- cartId = localStorage.getItem(CART_LS_KEY);
23151
- if (!(this.cart && !cartId)) return [3 /*break*/, 1];
23152
- this.removeCart();
23153
- return [3 /*break*/, 3];
23154
- case 1:
23155
- if (!(!this.cart && !!cartId)) return [3 /*break*/, 3];
23156
- return [4 /*yield*/, this.getCart()];
23157
- case 2:
23158
- _a.sent();
23159
- _a.label = 3;
23160
- case 3: return [2 /*return*/];
23161
- }
23162
- });
23163
- }); };
23164
- this.addItem = function (variant, product, initialQuantity) {
23165
- if (initialQuantity === void 0) { initialQuantity = 1; }
23166
- return __awaiter(_this, void 0, void 0, function () {
23167
- var existingItem, cartId, input, cart, eventId, item, err_2;
23168
- var _a, _b, _c;
23169
- return __generator(this, function (_d) {
23170
- switch (_d.label) {
23171
- case 0:
23172
- _d.trys.push([0, 5, , 6]);
23173
- return [4 /*yield*/, this.beforeCartOperationCheck()];
23174
- case 1:
23175
- _d.sent();
23176
- if (this.cart) {
23177
- existingItem = this.cart.items.find(function (item) { return item.variant.id === variant.id; });
23178
- if (existingItem) {
23179
- return [2 /*return*/, this.changeItemQuantity(existingItem, existingItem.quantity + 1)];
23180
- }
23181
- }
23182
- cartId = ((_a = this.cart) === null || _a === void 0 ? void 0 : _a.id) || localStorage.getItem(CART_LS_KEY);
23183
- input = {
23184
- cartId: cartId,
23185
- 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) ||
23186
- null,
23187
- item: {
23188
- id: null,
23189
- quantity: initialQuantity,
23190
- variant: {
23191
- id: variant.id,
23192
- name: product.name,
23193
- },
23194
- },
23195
- priceListId: IkasStorefrontConfig.priceListId || null,
23196
- salesChannelId: IkasStorefrontConfig.salesChannelId,
23197
- storefrontId: IkasStorefrontConfig.storefrontId,
23198
- storefrontRoutingId: IkasStorefrontConfig.storefrontRoutingId,
23199
- storefrontThemeId: IkasStorefrontConfig.storefrontThemeId,
23200
- };
23201
- return [4 /*yield*/, IkasCartAPI.saveItemToCart(input)];
23202
- case 2:
23203
- cart = _d.sent();
23204
- if (!cart) return [3 /*break*/, 4];
23205
- return [4 /*yield*/, this.setCart(cart)];
23206
- case 3:
23207
- _d.sent();
23208
- _d.label = 4;
23209
- case 4:
23210
- if (this.cart) {
23211
- eventId = this.cart.id + "-" + this.cart.updatedAt;
23212
- item = this.cart.items.find(function (i) { return i.variant.id; });
23213
- if (item) {
23214
- Analytics.addToCart(item, initialQuantity, eventId, this.cart);
23215
- }
23216
- }
23217
- return [3 /*break*/, 6];
23218
- case 5:
23219
- err_2 = _d.sent();
23220
- console.log(err_2);
23221
- return [3 /*break*/, 6];
23222
- case 6: return [2 /*return*/];
23223
- }
23224
- });
23225
- });
23226
- };
23227
- this.changeItemQuantity = function (item, quantity) { return __awaiter(_this, void 0, void 0, function () {
23228
- var input, cart, eventId, oldQuantity, err_3;
23229
- var _a, _b, _c;
23230
- return __generator(this, function (_d) {
23231
- switch (_d.label) {
23232
- case 0:
23233
- _d.trys.push([0, 5, , 6]);
23234
- return [4 /*yield*/, this.beforeCartOperationCheck()];
23235
- case 1:
23236
- _d.sent();
23237
- input = {
23238
- cartId: ((_a = this.cart) === null || _a === void 0 ? void 0 : _a.id) || null,
23239
- 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) ||
23240
- null,
23241
- item: {
23242
- id: item.id,
23243
- quantity: quantity,
23244
- variant: {
23245
- id: item.variant.id,
23246
- name: item.variant.name,
23247
- },
23248
- },
23249
- priceListId: IkasStorefrontConfig.priceListId || null,
23250
- salesChannelId: IkasStorefrontConfig.salesChannelId,
23251
- storefrontId: IkasStorefrontConfig.storefrontId,
23252
- storefrontRoutingId: IkasStorefrontConfig.storefrontRoutingId,
23253
- storefrontThemeId: IkasStorefrontConfig.storefrontThemeId,
23254
- };
23255
- return [4 /*yield*/, IkasCartAPI.saveItemToCart(input)];
23256
- case 2:
23257
- cart = _d.sent();
23258
- if (!cart) return [3 /*break*/, 4];
23259
- return [4 /*yield*/, this.setCart(cart)];
23260
- case 3:
23261
- _d.sent();
23262
- _d.label = 4;
23263
- case 4:
23264
- this.removeCardIfEmpty();
23265
- if (this.cart) {
23266
- eventId = this.cart.id + "-" + this.cart.updatedAt;
23267
- oldQuantity = item.quantity;
23268
- if (oldQuantity > quantity) {
23269
- Analytics.removeFromCart(item, oldQuantity - quantity, this.cart);
23270
- }
23271
- else {
23272
- Analytics.addToCart(item, quantity - oldQuantity, eventId, this.cart);
23273
- }
23274
- }
23275
- return [3 /*break*/, 6];
23276
- case 5:
23277
- err_3 = _d.sent();
23278
- console.log(err_3);
23279
- return [3 /*break*/, 6];
23280
- case 6: return [2 /*return*/];
23281
- }
23282
- });
23283
- }); };
23284
- this.removeItem = function (item) { return __awaiter(_this, void 0, void 0, function () {
23285
- return __generator(this, function (_a) {
23286
- switch (_a.label) {
23287
- case 0: return [4 /*yield*/, this.changeItemQuantity(item, 0)];
23288
- case 1:
23289
- _a.sent();
23290
- return [2 /*return*/];
23291
- }
23292
- });
23293
- }); };
23294
- this.removeCardIfEmpty = function () {
23295
- var _a;
23296
- if (((_a = _this.cart) === null || _a === void 0 ? void 0 : _a.itemCount) === 0) {
23297
- _this.removeCart();
23298
- }
23299
- };
23300
- this.removeCart = function () {
23301
- localStorage.removeItem(CART_LS_KEY);
23302
- localStorage.removeItem(CHECKOUT_LS_KEY);
23303
- _this.cart = undefined;
23304
- _this._checkoutId = undefined;
23305
- };
23306
- this.waitUntilInitialized = function () {
23307
- return new Promise(function (resolve) {
23308
- var interval = setInterval(function () {
23309
- if (_this.cartLoadFinished) {
23310
- clearInterval(interval);
23311
- resolve(null);
23312
- }
23313
- }, 100);
23314
- });
23315
- };
23316
- this.baseStore = baseStore;
23317
- makeAutoObservable(this);
23318
- }
23319
- Object.defineProperty(IkasCartStore.prototype, "isBrowser", {
23320
- get: function () {
23321
- return typeof localStorage !== "undefined";
23322
- },
23323
- enumerable: false,
23324
- configurable: true
23325
- });
23326
- Object.defineProperty(IkasCartStore.prototype, "isLoadingCart", {
23327
- get: function () {
23328
- return this._isLoadingCart;
23329
- },
23330
- enumerable: false,
23331
- configurable: true
23332
- });
23333
- Object.defineProperty(IkasCartStore.prototype, "cartLoadFinished", {
23334
- get: function () {
23335
- return this._cartLoadFinished;
23336
- },
23337
- enumerable: false,
23338
- configurable: true
23339
- });
23340
- Object.defineProperty(IkasCartStore.prototype, "checkoutId", {
23341
- get: function () {
23342
- return this._checkoutId;
23343
- },
23344
- enumerable: false,
23345
- configurable: true
23346
- });
23347
- Object.defineProperty(IkasCartStore.prototype, "checkoutUrl", {
23348
- get: function () {
23349
- if (this._checkoutId)
23350
- return "/checkout?id=" + this._checkoutId + "&step=info";
23351
- },
23352
- enumerable: false,
23353
- configurable: true
23354
- });
23355
- return IkasCartStore;
23356
- }());
23357
-
23358
- configure({
23359
- enforceActions: "never",
23360
- });
23361
- var IkasBaseStore = /** @class */ (function () {
23362
- function IkasBaseStore() {
23363
- this.currentPageType = null;
23364
- this.localeOptions = [];
23365
- this.showLocaleOptions = false;
23366
- this.currentCountryCode = null;
23367
- this.localeChecked = false;
23368
- this.settingsSet = false;
23369
- this.customerStore = new IkasCustomerStore(this);
23370
- this.cartStore = new IkasCartStore(this);
23371
- makeObservable(this, {
23372
- currentPageType: observable,
23373
- localeOptions: observable,
23374
- showLocaleOptions: observable,
23375
- currentCountryCode: observable,
23376
- });
23377
- }
23378
- IkasBaseStore.prototype.checkLocalization = function () {
23379
- return __awaiter(this, void 0, void 0, function () {
23380
- var myCountryCode, currentRouting, isCorrectLocale, myCountryRouting, otherCountriesRouting, iso2Codes, countries_1, localeOptions_1;
23381
- return __generator(this, function (_a) {
23382
- switch (_a.label) {
23383
- case 0:
23384
- if (this.localeChecked)
23385
- return [2 /*return*/];
23386
- if (typeof window === undefined) {
23387
- console.warn("checkLocalization should be called on the client side!");
23388
- return [2 /*return*/];
23389
- }
23390
- return [4 /*yield*/, IkasCountryAPI.getMyCountry()];
23391
- case 1:
23392
- myCountryCode = _a.sent();
23393
- currentRouting = IkasStorefrontConfig.routings.find(function (r) { return r.id === IkasStorefrontConfig.storefrontRoutingId; });
23394
- this.currentCountryCode = myCountryCode;
23395
- if (!(currentRouting && myCountryCode)) return [3 /*break*/, 3];
23396
- isCorrectLocale = true;
23397
- myCountryRouting = IkasStorefrontConfig.routings.find(function (r) { var _a; return (_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.includes(myCountryCode); });
23398
- otherCountriesRouting = IkasStorefrontConfig.routings.find(function (r) { var _a; return !((_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.length); });
23399
- // Current country has spefic routing
23400
- if (myCountryRouting) {
23401
- if (currentRouting.id !== myCountryRouting.id) {
23402
- isCorrectLocale = false;
23403
- }
23404
- }
23405
- // Current country does not have specific routing
23406
- else {
23407
- if (otherCountriesRouting &&
23408
- currentRouting.id !== otherCountriesRouting.id) {
23409
- isCorrectLocale = false;
23410
- }
23411
- }
23412
- iso2Codes = flatten_1(IkasStorefrontConfig.routings.map(function (r) { return r.countryCodes || []; }));
23413
- return [4 /*yield*/, IkasCountryAPI.listCountries(iso2Codes)];
23414
- case 2:
23415
- countries_1 = _a.sent();
23416
- localeOptions_1 = [];
23417
- IkasStorefrontConfig.routings.map(function (r) {
23418
- var _a;
23419
- if ((_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.length) {
23420
- r.countryCodes.forEach(function (countryCode) {
23421
- var _a;
23422
- var country = countries_1.find(function (c) { return c.iso2 === countryCode; });
23423
- localeOptions_1.push({
23424
- id: v4(),
23425
- countryName: (country === null || country === void 0 ? void 0 : country.native) || (country === null || country === void 0 ? void 0 : country.name) || "",
23426
- routing: r,
23427
- isRecommended: ((_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.includes(myCountryCode)) || false,
23428
- });
23429
- });
23430
- }
23431
- else {
23432
- localeOptions_1.push({
23433
- id: v4(),
23434
- routing: r,
23435
- isRecommended: !IkasStorefrontConfig.routings.some(function (r) { var _a; return (_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.includes(myCountryCode); }),
23436
- });
23437
- }
23438
- });
23439
- this.localeOptions = sortBy_1(localeOptions_1, "countryName");
23440
- if (!isCorrectLocale) {
23441
- this.showLocaleOptions = true;
23442
- }
23443
- this.localeChecked = true;
23444
- _a.label = 3;
23445
- case 3: return [2 /*return*/];
23446
- }
23447
- });
23448
- });
23449
- };
23450
- IkasBaseStore.prototype.setLocalization = function (localeOption) {
23451
- if (localeOption.routing.domain) {
23452
- window.location.replace("https://" + localeOption.routing.domain);
23453
- }
23454
- else {
23455
- window.location.replace(window.location.origin +
23456
- (localeOption.routing.path ? "/" + localeOption.routing.path : ""));
23457
- }
23458
- };
23459
- IkasBaseStore.prototype.setSettings = function (settingsStr) {
23460
- if (this.settingsSet)
23461
- return;
23462
- var settings = new IkasThemeSettings(JSON.parse(settingsStr));
23463
- settings.colors.map(function (sc) {
23464
- return document.documentElement.style.setProperty(sc.key, sc.color);
23465
- });
23466
- };
23467
- return IkasBaseStore;
23468
- }());
23469
-
23470
23052
  var NUMBER_ONLY_REGEX = /^\d+$/;
23471
23053
  var MAX_CARD_NUMBER_LENGTH = 16;
23472
23054
  var MAX_CVC_LENGTH = 4;
@@ -23478,7 +23060,7 @@ var CheckoutViewModel = /** @class */ (function () {
23478
23060
  this.checkout = new IkasCheckout();
23479
23061
  this.checkoutSettings = new IkasCheckoutSettings();
23480
23062
  this.storefront = null;
23481
- this.store = new IkasBaseStore();
23063
+ this.store = IkasStorefrontConfig.store;
23482
23064
  this.isCheckoutLoaded = false;
23483
23065
  this.isErrorsVisible = false;
23484
23066
  this.isStepLoading = false;
@@ -23898,6 +23480,28 @@ var CheckoutViewModel = /** @class */ (function () {
23898
23480
  }
23899
23481
  });
23900
23482
  }); };
23483
+ this.onCouponCodeDelete = function () { return __awaiter(_this, void 0, void 0, function () {
23484
+ var newCheckout;
23485
+ return __generator(this, function (_b) {
23486
+ switch (_b.label) {
23487
+ case 0:
23488
+ _b.trys.push([0, 3, , 4]);
23489
+ return [4 /*yield*/, this.saveCheckout()];
23490
+ case 1:
23491
+ _b.sent();
23492
+ return [4 /*yield*/, IkasCheckoutAPI.getCheckoutById(this.checkout.id)];
23493
+ case 2:
23494
+ newCheckout = _b.sent();
23495
+ if (newCheckout)
23496
+ this.checkout = newCheckout;
23497
+ return [3 /*break*/, 4];
23498
+ case 3:
23499
+ _b.sent();
23500
+ return [3 /*break*/, 4];
23501
+ case 4: return [2 /*return*/];
23502
+ }
23503
+ });
23504
+ }); };
23901
23505
  this.onSelectedShippingAddressIdChange = function (value) {
23902
23506
  var _a;
23903
23507
  _this.selectedShippingAddressId = value;
@@ -33969,8 +33573,10 @@ var IkasCustomerStore = /** @class */ (function () {
33969
33573
  });
33970
33574
  };
33971
33575
  IkasCustomerStore.prototype.routeChangeInit = function () {
33972
- if (!this.customer)
33973
- this.init();
33576
+ if (!this.customer) {
33577
+ this.loadToken();
33578
+ this.getCustomer();
33579
+ }
33974
33580
  };
33975
33581
  IkasCustomerStore.prototype.getCustomer = function () {
33976
33582
  return __awaiter(this, void 0, void 0, function () {
@@ -45616,8 +45222,6 @@ var IkasPage = observer(function (_a) {
45616
45222
  IkasStorefrontConfig.store.customerStore.routeChangeInit();
45617
45223
  };
45618
45224
  router.events.on("routeChangeStart", handleRouteChange);
45619
- // If the component is unmounted, unsubscribe
45620
- // from the event with the `off` method:
45621
45225
  return function () {
45622
45226
  router.events.off("routeChangeStart", handleRouteChange);
45623
45227
  };
@@ -70027,7 +69631,7 @@ var Coupon = observer(function (_a) {
70027
69631
  case 0:
70028
69632
  vm.checkout.couponCode = null;
70029
69633
  setLoadingCoupon(true);
70030
- return [4 /*yield*/, vm.onCouponCodeApply()];
69634
+ return [4 /*yield*/, vm.onCouponCodeDelete()];
70031
69635
  case 1:
70032
69636
  _a.sent();
70033
69637
  setLoadingCoupon(false);
@@ -70084,6 +69688,291 @@ var Note = observer(function (_a) {
70084
69688
  isSuccessStep ? (createElement("div", { className: styles$g.CheckoutNoteDisplay }, vm.checkout.note)) : (createElement(FormItem, { style: { width: "100%" }, type: FormItemType.TEXT_AREA, disableResize: true, label: "", value: vm.checkout.note || "", onChange: onCheckoutNoteChange }))))));
70085
69689
  });
70086
69690
 
69691
+ var CART_LS_KEY = "cartId";
69692
+ var CHECKOUT_LS_KEY = "checkoutId";
69693
+ var IkasCartStore = /** @class */ (function () {
69694
+ function IkasCartStore(baseStore) {
69695
+ var _this = this;
69696
+ this.cart = null;
69697
+ this._checkoutId = null;
69698
+ this._isLoadingCart = false;
69699
+ this._cartLoadFinished = false;
69700
+ this.getCart = function () { return __awaiter(_this, void 0, void 0, function () {
69701
+ var customerId, cartId, cart, err_1;
69702
+ var _a, _b;
69703
+ return __generator(this, function (_c) {
69704
+ switch (_c.label) {
69705
+ case 0:
69706
+ if (!this.isBrowser)
69707
+ return [2 /*return*/];
69708
+ _c.label = 1;
69709
+ case 1:
69710
+ _c.trys.push([1, 6, 7, 8]);
69711
+ this._isLoadingCart = true;
69712
+ customerId = (_a = this.baseStore.customerStore.customer) === null || _a === void 0 ? void 0 : _a.id;
69713
+ cartId = ((_b = this.cart) === null || _b === void 0 ? void 0 : _b.id) || localStorage.getItem(CART_LS_KEY);
69714
+ if (!cartId && !customerId)
69715
+ return [2 /*return*/];
69716
+ return [4 /*yield*/, IkasCartAPI.getCart(cartId || undefined
69717
+ // customerId || undefined // TODO reopen this when we have a way of telling backend that we cleared a cart
69718
+ )];
69719
+ case 2:
69720
+ cart = _c.sent();
69721
+ if (!cart) return [3 /*break*/, 4];
69722
+ return [4 /*yield*/, this.setCart(cart)];
69723
+ case 3:
69724
+ _c.sent();
69725
+ return [3 /*break*/, 5];
69726
+ case 4:
69727
+ this.removeCart();
69728
+ _c.label = 5;
69729
+ case 5: return [3 /*break*/, 8];
69730
+ case 6:
69731
+ err_1 = _c.sent();
69732
+ console.log(err_1);
69733
+ return [3 /*break*/, 8];
69734
+ case 7:
69735
+ this._isLoadingCart = false;
69736
+ this._cartLoadFinished = true;
69737
+ return [7 /*endfinally*/];
69738
+ case 8: return [2 /*return*/];
69739
+ }
69740
+ });
69741
+ }); };
69742
+ this.setCart = function (cart) { return __awaiter(_this, void 0, void 0, function () {
69743
+ var checkoutId;
69744
+ return __generator(this, function (_a) {
69745
+ switch (_a.label) {
69746
+ case 0:
69747
+ localStorage.setItem(CART_LS_KEY, cart.id);
69748
+ this.cart = cart;
69749
+ if (!this._checkoutId)
69750
+ this._checkoutId = localStorage.getItem(CHECKOUT_LS_KEY) || undefined;
69751
+ if (!!this._checkoutId) return [3 /*break*/, 2];
69752
+ return [4 /*yield*/, IkasCheckoutAPI.getCheckoutId(cart.id)];
69753
+ case 1:
69754
+ checkoutId = _a.sent();
69755
+ this._checkoutId = checkoutId;
69756
+ if (checkoutId)
69757
+ localStorage.setItem(CHECKOUT_LS_KEY, checkoutId);
69758
+ _a.label = 2;
69759
+ case 2: return [2 /*return*/];
69760
+ }
69761
+ });
69762
+ }); };
69763
+ this.beforeCartOperationCheck = function () { return __awaiter(_this, void 0, void 0, function () {
69764
+ var cartId;
69765
+ return __generator(this, function (_a) {
69766
+ switch (_a.label) {
69767
+ case 0:
69768
+ cartId = localStorage.getItem(CART_LS_KEY);
69769
+ if (!(this.cart && !cartId)) return [3 /*break*/, 1];
69770
+ this.removeCart();
69771
+ return [3 /*break*/, 3];
69772
+ case 1:
69773
+ if (!(!this.cart && !!cartId)) return [3 /*break*/, 3];
69774
+ return [4 /*yield*/, this.getCart()];
69775
+ case 2:
69776
+ _a.sent();
69777
+ _a.label = 3;
69778
+ case 3: return [2 /*return*/];
69779
+ }
69780
+ });
69781
+ }); };
69782
+ this.addItem = function (variant, product, initialQuantity) {
69783
+ if (initialQuantity === void 0) { initialQuantity = 1; }
69784
+ return __awaiter(_this, void 0, void 0, function () {
69785
+ var existingItem, cartId, input, cart, eventId, item, err_2;
69786
+ var _a, _b, _c;
69787
+ return __generator(this, function (_d) {
69788
+ switch (_d.label) {
69789
+ case 0:
69790
+ _d.trys.push([0, 5, , 6]);
69791
+ return [4 /*yield*/, this.beforeCartOperationCheck()];
69792
+ case 1:
69793
+ _d.sent();
69794
+ if (this.cart) {
69795
+ existingItem = this.cart.items.find(function (item) { return item.variant.id === variant.id; });
69796
+ if (existingItem) {
69797
+ return [2 /*return*/, this.changeItemQuantity(existingItem, existingItem.quantity + 1)];
69798
+ }
69799
+ }
69800
+ cartId = ((_a = this.cart) === null || _a === void 0 ? void 0 : _a.id) || localStorage.getItem(CART_LS_KEY);
69801
+ input = {
69802
+ cartId: cartId,
69803
+ 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) ||
69804
+ null,
69805
+ item: {
69806
+ id: null,
69807
+ quantity: initialQuantity,
69808
+ variant: {
69809
+ id: variant.id,
69810
+ name: product.name,
69811
+ },
69812
+ },
69813
+ priceListId: IkasStorefrontConfig.priceListId || null,
69814
+ salesChannelId: IkasStorefrontConfig.salesChannelId,
69815
+ storefrontId: IkasStorefrontConfig.storefrontId,
69816
+ storefrontRoutingId: IkasStorefrontConfig.storefrontRoutingId,
69817
+ storefrontThemeId: IkasStorefrontConfig.storefrontThemeId,
69818
+ };
69819
+ return [4 /*yield*/, IkasCartAPI.saveItemToCart(input)];
69820
+ case 2:
69821
+ cart = _d.sent();
69822
+ if (!cart) return [3 /*break*/, 4];
69823
+ return [4 /*yield*/, this.setCart(cart)];
69824
+ case 3:
69825
+ _d.sent();
69826
+ _d.label = 4;
69827
+ case 4:
69828
+ if (this.cart) {
69829
+ eventId = this.cart.id + "-" + this.cart.updatedAt;
69830
+ item = this.cart.items.find(function (i) { return i.variant.id; });
69831
+ if (item) {
69832
+ Analytics.addToCart(item, initialQuantity, eventId, this.cart);
69833
+ }
69834
+ }
69835
+ return [3 /*break*/, 6];
69836
+ case 5:
69837
+ err_2 = _d.sent();
69838
+ console.log(err_2);
69839
+ return [3 /*break*/, 6];
69840
+ case 6: return [2 /*return*/];
69841
+ }
69842
+ });
69843
+ });
69844
+ };
69845
+ this.changeItemQuantity = function (item, quantity) { return __awaiter(_this, void 0, void 0, function () {
69846
+ var input, cart, eventId, oldQuantity, err_3;
69847
+ var _a, _b, _c;
69848
+ return __generator(this, function (_d) {
69849
+ switch (_d.label) {
69850
+ case 0:
69851
+ _d.trys.push([0, 5, , 6]);
69852
+ return [4 /*yield*/, this.beforeCartOperationCheck()];
69853
+ case 1:
69854
+ _d.sent();
69855
+ input = {
69856
+ cartId: ((_a = this.cart) === null || _a === void 0 ? void 0 : _a.id) || null,
69857
+ 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) ||
69858
+ null,
69859
+ item: {
69860
+ id: item.id,
69861
+ quantity: quantity,
69862
+ variant: {
69863
+ id: item.variant.id,
69864
+ name: item.variant.name,
69865
+ },
69866
+ },
69867
+ priceListId: IkasStorefrontConfig.priceListId || null,
69868
+ salesChannelId: IkasStorefrontConfig.salesChannelId,
69869
+ storefrontId: IkasStorefrontConfig.storefrontId,
69870
+ storefrontRoutingId: IkasStorefrontConfig.storefrontRoutingId,
69871
+ storefrontThemeId: IkasStorefrontConfig.storefrontThemeId,
69872
+ };
69873
+ return [4 /*yield*/, IkasCartAPI.saveItemToCart(input)];
69874
+ case 2:
69875
+ cart = _d.sent();
69876
+ if (!cart) return [3 /*break*/, 4];
69877
+ return [4 /*yield*/, this.setCart(cart)];
69878
+ case 3:
69879
+ _d.sent();
69880
+ _d.label = 4;
69881
+ case 4:
69882
+ this.removeCardIfEmpty();
69883
+ if (this.cart) {
69884
+ eventId = this.cart.id + "-" + this.cart.updatedAt;
69885
+ oldQuantity = item.quantity;
69886
+ if (oldQuantity > quantity) {
69887
+ Analytics.removeFromCart(item, oldQuantity - quantity, this.cart);
69888
+ }
69889
+ else {
69890
+ Analytics.addToCart(item, quantity - oldQuantity, eventId, this.cart);
69891
+ }
69892
+ }
69893
+ return [3 /*break*/, 6];
69894
+ case 5:
69895
+ err_3 = _d.sent();
69896
+ console.log(err_3);
69897
+ return [3 /*break*/, 6];
69898
+ case 6: return [2 /*return*/];
69899
+ }
69900
+ });
69901
+ }); };
69902
+ this.removeItem = function (item) { return __awaiter(_this, void 0, void 0, function () {
69903
+ return __generator(this, function (_a) {
69904
+ switch (_a.label) {
69905
+ case 0: return [4 /*yield*/, this.changeItemQuantity(item, 0)];
69906
+ case 1:
69907
+ _a.sent();
69908
+ return [2 /*return*/];
69909
+ }
69910
+ });
69911
+ }); };
69912
+ this.removeCardIfEmpty = function () {
69913
+ var _a;
69914
+ if (((_a = _this.cart) === null || _a === void 0 ? void 0 : _a.itemCount) === 0) {
69915
+ _this.removeCart();
69916
+ }
69917
+ };
69918
+ this.removeCart = function () {
69919
+ localStorage.removeItem(CART_LS_KEY);
69920
+ localStorage.removeItem(CHECKOUT_LS_KEY);
69921
+ _this.cart = undefined;
69922
+ _this._checkoutId = undefined;
69923
+ };
69924
+ this.waitUntilInitialized = function () {
69925
+ return new Promise(function (resolve) {
69926
+ var interval = setInterval(function () {
69927
+ if (_this.cartLoadFinished) {
69928
+ clearInterval(interval);
69929
+ resolve(null);
69930
+ }
69931
+ }, 100);
69932
+ });
69933
+ };
69934
+ this.baseStore = baseStore;
69935
+ makeAutoObservable(this);
69936
+ }
69937
+ Object.defineProperty(IkasCartStore.prototype, "isBrowser", {
69938
+ get: function () {
69939
+ return typeof localStorage !== "undefined";
69940
+ },
69941
+ enumerable: false,
69942
+ configurable: true
69943
+ });
69944
+ Object.defineProperty(IkasCartStore.prototype, "isLoadingCart", {
69945
+ get: function () {
69946
+ return this._isLoadingCart;
69947
+ },
69948
+ enumerable: false,
69949
+ configurable: true
69950
+ });
69951
+ Object.defineProperty(IkasCartStore.prototype, "cartLoadFinished", {
69952
+ get: function () {
69953
+ return this._cartLoadFinished;
69954
+ },
69955
+ enumerable: false,
69956
+ configurable: true
69957
+ });
69958
+ Object.defineProperty(IkasCartStore.prototype, "checkoutId", {
69959
+ get: function () {
69960
+ return this._checkoutId;
69961
+ },
69962
+ enumerable: false,
69963
+ configurable: true
69964
+ });
69965
+ Object.defineProperty(IkasCartStore.prototype, "checkoutUrl", {
69966
+ get: function () {
69967
+ if (this._checkoutId)
69968
+ return "/checkout?id=" + this._checkoutId + "&step=info";
69969
+ },
69970
+ enumerable: false,
69971
+ configurable: true
69972
+ });
69973
+ return IkasCartStore;
69974
+ }());
69975
+
70087
69976
  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"};
70088
69977
 
70089
69978
  var SVGSuccessCircle = function (_a) {
@@ -71660,6 +71549,139 @@ var _slug_$3 = /*#__PURE__*/Object.freeze({
71660
71549
  getStaticProps: getStaticProps$h
71661
71550
  });
71662
71551
 
71552
+ /**
71553
+ * Flattens `array` a single level deep.
71554
+ *
71555
+ * @static
71556
+ * @memberOf _
71557
+ * @since 0.1.0
71558
+ * @category Array
71559
+ * @param {Array} array The array to flatten.
71560
+ * @returns {Array} Returns the new flattened array.
71561
+ * @example
71562
+ *
71563
+ * _.flatten([1, [2, [3, [4]], 5]]);
71564
+ * // => [1, 2, [3, [4]], 5]
71565
+ */
71566
+ function flatten(array) {
71567
+ var length = array == null ? 0 : array.length;
71568
+ return length ? _baseFlatten(array, 1) : [];
71569
+ }
71570
+
71571
+ var flatten_1 = flatten;
71572
+
71573
+ configure({
71574
+ enforceActions: "never",
71575
+ });
71576
+ var IkasBaseStore = /** @class */ (function () {
71577
+ function IkasBaseStore() {
71578
+ this.currentPageType = null;
71579
+ this.localeOptions = [];
71580
+ this.showLocaleOptions = false;
71581
+ this.currentCountryCode = null;
71582
+ this.localeChecked = false;
71583
+ this.settingsSet = false;
71584
+ this.customerStore = new IkasCustomerStore(this);
71585
+ this.cartStore = new IkasCartStore(this);
71586
+ makeObservable(this, {
71587
+ currentPageType: observable,
71588
+ localeOptions: observable,
71589
+ showLocaleOptions: observable,
71590
+ currentCountryCode: observable,
71591
+ });
71592
+ }
71593
+ IkasBaseStore.prototype.checkLocalization = function () {
71594
+ return __awaiter(this, void 0, void 0, function () {
71595
+ var myCountryCode, currentRouting, isCorrectLocale, myCountryRouting, otherCountriesRouting, iso2Codes, countries_1, localeOptions_1;
71596
+ return __generator(this, function (_a) {
71597
+ switch (_a.label) {
71598
+ case 0:
71599
+ if (this.localeChecked)
71600
+ return [2 /*return*/];
71601
+ if (typeof window === undefined) {
71602
+ console.warn("checkLocalization should be called on the client side!");
71603
+ return [2 /*return*/];
71604
+ }
71605
+ return [4 /*yield*/, IkasCountryAPI.getMyCountry()];
71606
+ case 1:
71607
+ myCountryCode = _a.sent();
71608
+ currentRouting = IkasStorefrontConfig.routings.find(function (r) { return r.id === IkasStorefrontConfig.storefrontRoutingId; });
71609
+ this.currentCountryCode = myCountryCode;
71610
+ if (!(currentRouting && myCountryCode)) return [3 /*break*/, 3];
71611
+ isCorrectLocale = true;
71612
+ myCountryRouting = IkasStorefrontConfig.routings.find(function (r) { var _a; return (_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.includes(myCountryCode); });
71613
+ otherCountriesRouting = IkasStorefrontConfig.routings.find(function (r) { var _a; return !((_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.length); });
71614
+ // Current country has spefic routing
71615
+ if (myCountryRouting) {
71616
+ if (currentRouting.id !== myCountryRouting.id) {
71617
+ isCorrectLocale = false;
71618
+ }
71619
+ }
71620
+ // Current country does not have specific routing
71621
+ else {
71622
+ if (otherCountriesRouting &&
71623
+ currentRouting.id !== otherCountriesRouting.id) {
71624
+ isCorrectLocale = false;
71625
+ }
71626
+ }
71627
+ iso2Codes = flatten_1(IkasStorefrontConfig.routings.map(function (r) { return r.countryCodes || []; }));
71628
+ return [4 /*yield*/, IkasCountryAPI.listCountries(iso2Codes)];
71629
+ case 2:
71630
+ countries_1 = _a.sent();
71631
+ localeOptions_1 = [];
71632
+ IkasStorefrontConfig.routings.map(function (r) {
71633
+ var _a;
71634
+ if ((_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.length) {
71635
+ r.countryCodes.forEach(function (countryCode) {
71636
+ var _a;
71637
+ var country = countries_1.find(function (c) { return c.iso2 === countryCode; });
71638
+ localeOptions_1.push({
71639
+ id: v4(),
71640
+ countryName: (country === null || country === void 0 ? void 0 : country.native) || (country === null || country === void 0 ? void 0 : country.name) || "",
71641
+ routing: r,
71642
+ isRecommended: ((_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.includes(myCountryCode)) || false,
71643
+ });
71644
+ });
71645
+ }
71646
+ else {
71647
+ localeOptions_1.push({
71648
+ id: v4(),
71649
+ routing: r,
71650
+ isRecommended: !IkasStorefrontConfig.routings.some(function (r) { var _a; return (_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.includes(myCountryCode); }),
71651
+ });
71652
+ }
71653
+ });
71654
+ this.localeOptions = sortBy_1(localeOptions_1, "countryName");
71655
+ if (!isCorrectLocale) {
71656
+ this.showLocaleOptions = true;
71657
+ }
71658
+ this.localeChecked = true;
71659
+ _a.label = 3;
71660
+ case 3: return [2 /*return*/];
71661
+ }
71662
+ });
71663
+ });
71664
+ };
71665
+ IkasBaseStore.prototype.setLocalization = function (localeOption) {
71666
+ if (localeOption.routing.domain) {
71667
+ window.location.replace("https://" + localeOption.routing.domain);
71668
+ }
71669
+ else {
71670
+ window.location.replace(window.location.origin +
71671
+ (localeOption.routing.path ? "/" + localeOption.routing.path : ""));
71672
+ }
71673
+ };
71674
+ IkasBaseStore.prototype.setSettings = function (settingsStr) {
71675
+ if (this.settingsSet)
71676
+ return;
71677
+ var settings = new IkasThemeSettings(JSON.parse(settingsStr));
71678
+ settings.colors.map(function (sc) {
71679
+ return document.documentElement.style.setProperty(sc.key, sc.color);
71680
+ });
71681
+ };
71682
+ return IkasBaseStore;
71683
+ }());
71684
+
71663
71685
  var tr = {
71664
71686
  actions: {
71665
71687
  login: "Giriş Yap",