@ikas/storefront 0.1.22 → 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.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;
@@ -33969,8 +33551,10 @@ var IkasCustomerStore = /** @class */ (function () {
33969
33551
  });
33970
33552
  };
33971
33553
  IkasCustomerStore.prototype.routeChangeInit = function () {
33972
- if (!this.customer)
33973
- this.init();
33554
+ if (!this.customer) {
33555
+ this.loadToken();
33556
+ this.getCustomer();
33557
+ }
33974
33558
  };
33975
33559
  IkasCustomerStore.prototype.getCustomer = function () {
33976
33560
  return __awaiter(this, void 0, void 0, function () {
@@ -45616,8 +45200,6 @@ var IkasPage = observer(function (_a) {
45616
45200
  IkasStorefrontConfig.store.customerStore.routeChangeInit();
45617
45201
  };
45618
45202
  router.events.on("routeChangeStart", handleRouteChange);
45619
- // If the component is unmounted, unsubscribe
45620
- // from the event with the `off` method:
45621
45203
  return function () {
45622
45204
  router.events.off("routeChangeStart", handleRouteChange);
45623
45205
  };
@@ -70027,7 +69609,7 @@ var Coupon = observer(function (_a) {
70027
69609
  case 0:
70028
69610
  vm.checkout.couponCode = null;
70029
69611
  setLoadingCoupon(true);
70030
- return [4 /*yield*/, vm.onCouponCodeApply()];
69612
+ return [4 /*yield*/, vm.saveCheckout()];
70031
69613
  case 1:
70032
69614
  _a.sent();
70033
69615
  setLoadingCoupon(false);
@@ -70084,6 +69666,291 @@ var Note = observer(function (_a) {
70084
69666
  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
69667
  });
70086
69668
 
69669
+ var CART_LS_KEY = "cartId";
69670
+ var CHECKOUT_LS_KEY = "checkoutId";
69671
+ var IkasCartStore = /** @class */ (function () {
69672
+ function IkasCartStore(baseStore) {
69673
+ var _this = this;
69674
+ this.cart = null;
69675
+ this._checkoutId = null;
69676
+ this._isLoadingCart = false;
69677
+ this._cartLoadFinished = false;
69678
+ this.getCart = function () { return __awaiter(_this, void 0, void 0, function () {
69679
+ var customerId, cartId, cart, err_1;
69680
+ var _a, _b;
69681
+ return __generator(this, function (_c) {
69682
+ switch (_c.label) {
69683
+ case 0:
69684
+ if (!this.isBrowser)
69685
+ return [2 /*return*/];
69686
+ _c.label = 1;
69687
+ case 1:
69688
+ _c.trys.push([1, 6, 7, 8]);
69689
+ this._isLoadingCart = true;
69690
+ customerId = (_a = this.baseStore.customerStore.customer) === null || _a === void 0 ? void 0 : _a.id;
69691
+ cartId = ((_b = this.cart) === null || _b === void 0 ? void 0 : _b.id) || localStorage.getItem(CART_LS_KEY);
69692
+ if (!cartId && !customerId)
69693
+ return [2 /*return*/];
69694
+ return [4 /*yield*/, IkasCartAPI.getCart(cartId || undefined
69695
+ // customerId || undefined // TODO reopen this when we have a way of telling backend that we cleared a cart
69696
+ )];
69697
+ case 2:
69698
+ cart = _c.sent();
69699
+ if (!cart) return [3 /*break*/, 4];
69700
+ return [4 /*yield*/, this.setCart(cart)];
69701
+ case 3:
69702
+ _c.sent();
69703
+ return [3 /*break*/, 5];
69704
+ case 4:
69705
+ this.removeCart();
69706
+ _c.label = 5;
69707
+ case 5: return [3 /*break*/, 8];
69708
+ case 6:
69709
+ err_1 = _c.sent();
69710
+ console.log(err_1);
69711
+ return [3 /*break*/, 8];
69712
+ case 7:
69713
+ this._isLoadingCart = false;
69714
+ this._cartLoadFinished = true;
69715
+ return [7 /*endfinally*/];
69716
+ case 8: return [2 /*return*/];
69717
+ }
69718
+ });
69719
+ }); };
69720
+ this.setCart = function (cart) { return __awaiter(_this, void 0, void 0, function () {
69721
+ var checkoutId;
69722
+ return __generator(this, function (_a) {
69723
+ switch (_a.label) {
69724
+ case 0:
69725
+ localStorage.setItem(CART_LS_KEY, cart.id);
69726
+ this.cart = cart;
69727
+ if (!this._checkoutId)
69728
+ this._checkoutId = localStorage.getItem(CHECKOUT_LS_KEY) || undefined;
69729
+ if (!!this._checkoutId) return [3 /*break*/, 2];
69730
+ return [4 /*yield*/, IkasCheckoutAPI.getCheckoutId(cart.id)];
69731
+ case 1:
69732
+ checkoutId = _a.sent();
69733
+ this._checkoutId = checkoutId;
69734
+ if (checkoutId)
69735
+ localStorage.setItem(CHECKOUT_LS_KEY, checkoutId);
69736
+ _a.label = 2;
69737
+ case 2: return [2 /*return*/];
69738
+ }
69739
+ });
69740
+ }); };
69741
+ this.beforeCartOperationCheck = function () { return __awaiter(_this, void 0, void 0, function () {
69742
+ var cartId;
69743
+ return __generator(this, function (_a) {
69744
+ switch (_a.label) {
69745
+ case 0:
69746
+ cartId = localStorage.getItem(CART_LS_KEY);
69747
+ if (!(this.cart && !cartId)) return [3 /*break*/, 1];
69748
+ this.removeCart();
69749
+ return [3 /*break*/, 3];
69750
+ case 1:
69751
+ if (!(!this.cart && !!cartId)) return [3 /*break*/, 3];
69752
+ return [4 /*yield*/, this.getCart()];
69753
+ case 2:
69754
+ _a.sent();
69755
+ _a.label = 3;
69756
+ case 3: return [2 /*return*/];
69757
+ }
69758
+ });
69759
+ }); };
69760
+ this.addItem = function (variant, product, initialQuantity) {
69761
+ if (initialQuantity === void 0) { initialQuantity = 1; }
69762
+ return __awaiter(_this, void 0, void 0, function () {
69763
+ var existingItem, cartId, input, cart, eventId, item, err_2;
69764
+ var _a, _b, _c;
69765
+ return __generator(this, function (_d) {
69766
+ switch (_d.label) {
69767
+ case 0:
69768
+ _d.trys.push([0, 5, , 6]);
69769
+ return [4 /*yield*/, this.beforeCartOperationCheck()];
69770
+ case 1:
69771
+ _d.sent();
69772
+ if (this.cart) {
69773
+ existingItem = this.cart.items.find(function (item) { return item.variant.id === variant.id; });
69774
+ if (existingItem) {
69775
+ return [2 /*return*/, this.changeItemQuantity(existingItem, existingItem.quantity + 1)];
69776
+ }
69777
+ }
69778
+ cartId = ((_a = this.cart) === null || _a === void 0 ? void 0 : _a.id) || localStorage.getItem(CART_LS_KEY);
69779
+ input = {
69780
+ cartId: cartId,
69781
+ 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) ||
69782
+ null,
69783
+ item: {
69784
+ id: null,
69785
+ quantity: initialQuantity,
69786
+ variant: {
69787
+ id: variant.id,
69788
+ name: product.name,
69789
+ },
69790
+ },
69791
+ priceListId: IkasStorefrontConfig.priceListId || null,
69792
+ salesChannelId: IkasStorefrontConfig.salesChannelId,
69793
+ storefrontId: IkasStorefrontConfig.storefrontId,
69794
+ storefrontRoutingId: IkasStorefrontConfig.storefrontRoutingId,
69795
+ storefrontThemeId: IkasStorefrontConfig.storefrontThemeId,
69796
+ };
69797
+ return [4 /*yield*/, IkasCartAPI.saveItemToCart(input)];
69798
+ case 2:
69799
+ cart = _d.sent();
69800
+ if (!cart) return [3 /*break*/, 4];
69801
+ return [4 /*yield*/, this.setCart(cart)];
69802
+ case 3:
69803
+ _d.sent();
69804
+ _d.label = 4;
69805
+ case 4:
69806
+ if (this.cart) {
69807
+ eventId = this.cart.id + "-" + this.cart.updatedAt;
69808
+ item = this.cart.items.find(function (i) { return i.variant.id; });
69809
+ if (item) {
69810
+ Analytics.addToCart(item, initialQuantity, eventId, this.cart);
69811
+ }
69812
+ }
69813
+ return [3 /*break*/, 6];
69814
+ case 5:
69815
+ err_2 = _d.sent();
69816
+ console.log(err_2);
69817
+ return [3 /*break*/, 6];
69818
+ case 6: return [2 /*return*/];
69819
+ }
69820
+ });
69821
+ });
69822
+ };
69823
+ this.changeItemQuantity = function (item, quantity) { return __awaiter(_this, void 0, void 0, function () {
69824
+ var input, cart, eventId, oldQuantity, err_3;
69825
+ var _a, _b, _c;
69826
+ return __generator(this, function (_d) {
69827
+ switch (_d.label) {
69828
+ case 0:
69829
+ _d.trys.push([0, 5, , 6]);
69830
+ return [4 /*yield*/, this.beforeCartOperationCheck()];
69831
+ case 1:
69832
+ _d.sent();
69833
+ input = {
69834
+ cartId: ((_a = this.cart) === null || _a === void 0 ? void 0 : _a.id) || null,
69835
+ 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) ||
69836
+ null,
69837
+ item: {
69838
+ id: item.id,
69839
+ quantity: quantity,
69840
+ variant: {
69841
+ id: item.variant.id,
69842
+ name: item.variant.name,
69843
+ },
69844
+ },
69845
+ priceListId: IkasStorefrontConfig.priceListId || null,
69846
+ salesChannelId: IkasStorefrontConfig.salesChannelId,
69847
+ storefrontId: IkasStorefrontConfig.storefrontId,
69848
+ storefrontRoutingId: IkasStorefrontConfig.storefrontRoutingId,
69849
+ storefrontThemeId: IkasStorefrontConfig.storefrontThemeId,
69850
+ };
69851
+ return [4 /*yield*/, IkasCartAPI.saveItemToCart(input)];
69852
+ case 2:
69853
+ cart = _d.sent();
69854
+ if (!cart) return [3 /*break*/, 4];
69855
+ return [4 /*yield*/, this.setCart(cart)];
69856
+ case 3:
69857
+ _d.sent();
69858
+ _d.label = 4;
69859
+ case 4:
69860
+ this.removeCardIfEmpty();
69861
+ if (this.cart) {
69862
+ eventId = this.cart.id + "-" + this.cart.updatedAt;
69863
+ oldQuantity = item.quantity;
69864
+ if (oldQuantity > quantity) {
69865
+ Analytics.removeFromCart(item, oldQuantity - quantity, this.cart);
69866
+ }
69867
+ else {
69868
+ Analytics.addToCart(item, quantity - oldQuantity, eventId, this.cart);
69869
+ }
69870
+ }
69871
+ return [3 /*break*/, 6];
69872
+ case 5:
69873
+ err_3 = _d.sent();
69874
+ console.log(err_3);
69875
+ return [3 /*break*/, 6];
69876
+ case 6: return [2 /*return*/];
69877
+ }
69878
+ });
69879
+ }); };
69880
+ this.removeItem = function (item) { return __awaiter(_this, void 0, void 0, function () {
69881
+ return __generator(this, function (_a) {
69882
+ switch (_a.label) {
69883
+ case 0: return [4 /*yield*/, this.changeItemQuantity(item, 0)];
69884
+ case 1:
69885
+ _a.sent();
69886
+ return [2 /*return*/];
69887
+ }
69888
+ });
69889
+ }); };
69890
+ this.removeCardIfEmpty = function () {
69891
+ var _a;
69892
+ if (((_a = _this.cart) === null || _a === void 0 ? void 0 : _a.itemCount) === 0) {
69893
+ _this.removeCart();
69894
+ }
69895
+ };
69896
+ this.removeCart = function () {
69897
+ localStorage.removeItem(CART_LS_KEY);
69898
+ localStorage.removeItem(CHECKOUT_LS_KEY);
69899
+ _this.cart = undefined;
69900
+ _this._checkoutId = undefined;
69901
+ };
69902
+ this.waitUntilInitialized = function () {
69903
+ return new Promise(function (resolve) {
69904
+ var interval = setInterval(function () {
69905
+ if (_this.cartLoadFinished) {
69906
+ clearInterval(interval);
69907
+ resolve(null);
69908
+ }
69909
+ }, 100);
69910
+ });
69911
+ };
69912
+ this.baseStore = baseStore;
69913
+ makeAutoObservable(this);
69914
+ }
69915
+ Object.defineProperty(IkasCartStore.prototype, "isBrowser", {
69916
+ get: function () {
69917
+ return typeof localStorage !== "undefined";
69918
+ },
69919
+ enumerable: false,
69920
+ configurable: true
69921
+ });
69922
+ Object.defineProperty(IkasCartStore.prototype, "isLoadingCart", {
69923
+ get: function () {
69924
+ return this._isLoadingCart;
69925
+ },
69926
+ enumerable: false,
69927
+ configurable: true
69928
+ });
69929
+ Object.defineProperty(IkasCartStore.prototype, "cartLoadFinished", {
69930
+ get: function () {
69931
+ return this._cartLoadFinished;
69932
+ },
69933
+ enumerable: false,
69934
+ configurable: true
69935
+ });
69936
+ Object.defineProperty(IkasCartStore.prototype, "checkoutId", {
69937
+ get: function () {
69938
+ return this._checkoutId;
69939
+ },
69940
+ enumerable: false,
69941
+ configurable: true
69942
+ });
69943
+ Object.defineProperty(IkasCartStore.prototype, "checkoutUrl", {
69944
+ get: function () {
69945
+ if (this._checkoutId)
69946
+ return "/checkout?id=" + this._checkoutId + "&step=info";
69947
+ },
69948
+ enumerable: false,
69949
+ configurable: true
69950
+ });
69951
+ return IkasCartStore;
69952
+ }());
69953
+
70087
69954
  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
69955
 
70089
69956
  var SVGSuccessCircle = function (_a) {
@@ -71660,6 +71527,139 @@ var _slug_$3 = /*#__PURE__*/Object.freeze({
71660
71527
  getStaticProps: getStaticProps$h
71661
71528
  });
71662
71529
 
71530
+ /**
71531
+ * Flattens `array` a single level deep.
71532
+ *
71533
+ * @static
71534
+ * @memberOf _
71535
+ * @since 0.1.0
71536
+ * @category Array
71537
+ * @param {Array} array The array to flatten.
71538
+ * @returns {Array} Returns the new flattened array.
71539
+ * @example
71540
+ *
71541
+ * _.flatten([1, [2, [3, [4]], 5]]);
71542
+ * // => [1, 2, [3, [4]], 5]
71543
+ */
71544
+ function flatten(array) {
71545
+ var length = array == null ? 0 : array.length;
71546
+ return length ? _baseFlatten(array, 1) : [];
71547
+ }
71548
+
71549
+ var flatten_1 = flatten;
71550
+
71551
+ configure({
71552
+ enforceActions: "never",
71553
+ });
71554
+ var IkasBaseStore = /** @class */ (function () {
71555
+ function IkasBaseStore() {
71556
+ this.currentPageType = null;
71557
+ this.localeOptions = [];
71558
+ this.showLocaleOptions = false;
71559
+ this.currentCountryCode = null;
71560
+ this.localeChecked = false;
71561
+ this.settingsSet = false;
71562
+ this.customerStore = new IkasCustomerStore(this);
71563
+ this.cartStore = new IkasCartStore(this);
71564
+ makeObservable(this, {
71565
+ currentPageType: observable,
71566
+ localeOptions: observable,
71567
+ showLocaleOptions: observable,
71568
+ currentCountryCode: observable,
71569
+ });
71570
+ }
71571
+ IkasBaseStore.prototype.checkLocalization = function () {
71572
+ return __awaiter(this, void 0, void 0, function () {
71573
+ var myCountryCode, currentRouting, isCorrectLocale, myCountryRouting, otherCountriesRouting, iso2Codes, countries_1, localeOptions_1;
71574
+ return __generator(this, function (_a) {
71575
+ switch (_a.label) {
71576
+ case 0:
71577
+ if (this.localeChecked)
71578
+ return [2 /*return*/];
71579
+ if (typeof window === undefined) {
71580
+ console.warn("checkLocalization should be called on the client side!");
71581
+ return [2 /*return*/];
71582
+ }
71583
+ return [4 /*yield*/, IkasCountryAPI.getMyCountry()];
71584
+ case 1:
71585
+ myCountryCode = _a.sent();
71586
+ currentRouting = IkasStorefrontConfig.routings.find(function (r) { return r.id === IkasStorefrontConfig.storefrontRoutingId; });
71587
+ this.currentCountryCode = myCountryCode;
71588
+ if (!(currentRouting && myCountryCode)) return [3 /*break*/, 3];
71589
+ isCorrectLocale = true;
71590
+ myCountryRouting = IkasStorefrontConfig.routings.find(function (r) { var _a; return (_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.includes(myCountryCode); });
71591
+ otherCountriesRouting = IkasStorefrontConfig.routings.find(function (r) { var _a; return !((_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.length); });
71592
+ // Current country has spefic routing
71593
+ if (myCountryRouting) {
71594
+ if (currentRouting.id !== myCountryRouting.id) {
71595
+ isCorrectLocale = false;
71596
+ }
71597
+ }
71598
+ // Current country does not have specific routing
71599
+ else {
71600
+ if (otherCountriesRouting &&
71601
+ currentRouting.id !== otherCountriesRouting.id) {
71602
+ isCorrectLocale = false;
71603
+ }
71604
+ }
71605
+ iso2Codes = flatten_1(IkasStorefrontConfig.routings.map(function (r) { return r.countryCodes || []; }));
71606
+ return [4 /*yield*/, IkasCountryAPI.listCountries(iso2Codes)];
71607
+ case 2:
71608
+ countries_1 = _a.sent();
71609
+ localeOptions_1 = [];
71610
+ IkasStorefrontConfig.routings.map(function (r) {
71611
+ var _a;
71612
+ if ((_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.length) {
71613
+ r.countryCodes.forEach(function (countryCode) {
71614
+ var _a;
71615
+ var country = countries_1.find(function (c) { return c.iso2 === countryCode; });
71616
+ localeOptions_1.push({
71617
+ id: v4(),
71618
+ countryName: (country === null || country === void 0 ? void 0 : country.native) || (country === null || country === void 0 ? void 0 : country.name) || "",
71619
+ routing: r,
71620
+ isRecommended: ((_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.includes(myCountryCode)) || false,
71621
+ });
71622
+ });
71623
+ }
71624
+ else {
71625
+ localeOptions_1.push({
71626
+ id: v4(),
71627
+ routing: r,
71628
+ isRecommended: !IkasStorefrontConfig.routings.some(function (r) { var _a; return (_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.includes(myCountryCode); }),
71629
+ });
71630
+ }
71631
+ });
71632
+ this.localeOptions = sortBy_1(localeOptions_1, "countryName");
71633
+ if (!isCorrectLocale) {
71634
+ this.showLocaleOptions = true;
71635
+ }
71636
+ this.localeChecked = true;
71637
+ _a.label = 3;
71638
+ case 3: return [2 /*return*/];
71639
+ }
71640
+ });
71641
+ });
71642
+ };
71643
+ IkasBaseStore.prototype.setLocalization = function (localeOption) {
71644
+ if (localeOption.routing.domain) {
71645
+ window.location.replace("https://" + localeOption.routing.domain);
71646
+ }
71647
+ else {
71648
+ window.location.replace(window.location.origin +
71649
+ (localeOption.routing.path ? "/" + localeOption.routing.path : ""));
71650
+ }
71651
+ };
71652
+ IkasBaseStore.prototype.setSettings = function (settingsStr) {
71653
+ if (this.settingsSet)
71654
+ return;
71655
+ var settings = new IkasThemeSettings(JSON.parse(settingsStr));
71656
+ settings.colors.map(function (sc) {
71657
+ return document.documentElement.style.setProperty(sc.key, sc.color);
71658
+ });
71659
+ };
71660
+ return IkasBaseStore;
71661
+ }());
71662
+
71663
71663
  var tr = {
71664
71664
  actions: {
71665
71665
  login: "Giriş Yap",