@ikas/storefront 0.0.158-alpha.3 → 0.0.158-alpha.5

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.
@@ -73,6 +73,14 @@ export declare enum CustomerAccountStatusesEnum {
73
73
  DISABLED_ACCOUNT = "DISABLED_ACCOUNT",
74
74
  INVITED_TO_CREATE_ACCOUNT = "INVITED_TO_CREATE_ACCOUNT"
75
75
  }
76
+ /**
77
+ * Customer Email Subscription Statuses
78
+ */
79
+ export declare enum CustomerEmailSubscriptionStatusesEnum {
80
+ NOT_SUBSCRIBED = "NOT_SUBSCRIBED",
81
+ PENDING_CONFIRMATION = "PENDING_CONFIRMATION",
82
+ SUBSCRIBED = "SUBSCRIBED"
83
+ }
76
84
  /**
77
85
  * Url Slug Target Type Enum Codes
78
86
  */
@@ -446,6 +454,22 @@ export interface PaymentMethodDetailInput {
446
454
  installmentCount: number;
447
455
  threeDSecure: boolean;
448
456
  }
457
+ export interface ProductItemInput {
458
+ createdAt?: any | null;
459
+ deleted?: boolean | null;
460
+ id?: string | null;
461
+ productId: string;
462
+ updatedAt?: any | null;
463
+ variantId: string;
464
+ }
465
+ export interface ProductLastViewedInput {
466
+ createdAt?: any | null;
467
+ customerId: string;
468
+ deleted?: boolean | null;
469
+ id?: string | null;
470
+ products: ProductItemInput[];
471
+ updatedAt?: any | null;
472
+ }
449
473
  export interface RetrieveInstallmentInfoInput {
450
474
  binNumber: string;
451
475
  paymentGatewayId: string;
@@ -1,4 +1,4 @@
1
- import { CustomerAccountStatusesEnum } from "../../../__generated__/global-types";
1
+ import { CustomerAccountStatusesEnum, CustomerEmailSubscriptionStatusesEnum } from "../../../__generated__/global-types";
2
2
  export interface customerLogin_customerLogin_customer_addresses_city {
3
3
  __typename: "CustomerAddressCity";
4
4
  code: string | null;
@@ -53,6 +53,7 @@ export interface customerLogin_customerLogin_customer {
53
53
  accountStatus: CustomerAccountStatusesEnum | null;
54
54
  email: string | null;
55
55
  firstName: string;
56
+ subscriptionStatus: CustomerEmailSubscriptionStatusesEnum | null;
56
57
  }
57
58
  export interface customerLogin_customerLogin {
58
59
  __typename: "CustomerLoginResponse";
@@ -0,0 +1,15 @@
1
+ export interface getLastViewedProducts_getLastViewedProducts_products {
2
+ __typename: "ProductItem";
3
+ productId: string;
4
+ variantId: string;
5
+ }
6
+ export interface getLastViewedProducts_getLastViewedProducts {
7
+ __typename: "ProductLastViewed";
8
+ products: getLastViewedProducts_getLastViewedProducts_products[];
9
+ }
10
+ export interface getLastViewedProducts {
11
+ getLastViewedProducts: getLastViewedProducts_getLastViewedProducts;
12
+ }
13
+ export interface getLastViewedProductsVariables {
14
+ customerId?: string | null;
15
+ }
@@ -0,0 +1,11 @@
1
+ import { ProductLastViewedInput } from "../../../__generated__/global-types";
2
+ export interface saveLastViewedProducts_saveLastViewedProducts {
3
+ __typename: "ProductLastViewed";
4
+ id: string;
5
+ }
6
+ export interface saveLastViewedProducts {
7
+ saveLastViewedProducts: saveLastViewedProducts_saveLastViewedProducts;
8
+ }
9
+ export interface saveLastViewedProductsVariables {
10
+ input: ProductLastViewedInput;
11
+ }
@@ -1,6 +1,7 @@
1
1
  import { IkasCustomer, IkasOrder } from "../../models/index";
2
- import * as RefreshTokenTypes from "./__generated__/customerRefreshToken";
3
2
  import { IkasRefund } from "../../models/data/order/refund/index";
3
+ import * as RefreshTokenTypes from "./__generated__/customerRefreshToken";
4
+ import * as GetLastViewedProductsTypes from "./__generated__/getLastViewedProducts";
4
5
  export declare class IkasCustomerAPI {
5
6
  static login(email: string, password: string): Promise<{
6
7
  customer: IkasCustomer;
@@ -28,4 +29,15 @@ export declare class IkasCustomerAPI {
28
29
  }): Promise<any>;
29
30
  static saveIkasOrderRefund(input: IkasRefund): Promise<IkasOrder | undefined>;
30
31
  static createCustomerEmailSubscription(email: string): Promise<boolean>;
32
+ static getLastViewedProducts(customerId: string): Promise<GetLastViewedProductsTypes.getLastViewedProducts_getLastViewedProducts_products[]>;
33
+ static saveLastViewedProducts(input: LastViewedProductInput): Promise<boolean>;
31
34
  }
35
+ declare type LastViewedProduct = {
36
+ productId: string;
37
+ variantId: string;
38
+ };
39
+ declare type LastViewedProductInput = {
40
+ customerId: string;
41
+ products: LastViewedProduct[];
42
+ };
43
+ export {};
package/build/index.es.js CHANGED
@@ -11171,7 +11171,7 @@ var IkasOrderAddress = /** @class */ (function () {
11171
11171
  });
11172
11172
  Object.defineProperty(IkasOrderAddress.prototype, "validationResult", {
11173
11173
  get: function () {
11174
- var _a, _b, _c, _d, _e;
11174
+ var _a, _b, _c, _d;
11175
11175
  var isValidPhone = !!this.phone &&
11176
11176
  this.phone.length >= 10 &&
11177
11177
  validatePhoneNumber(this.phone);
@@ -11192,10 +11192,7 @@ var IkasOrderAddress = /** @class */ (function () {
11192
11192
  ? isValidPhone
11193
11193
  : true,
11194
11194
  identityNumber: ((_d = this.checkoutSettings) === null || _d === void 0 ? void 0 : _d.identityNumberRequirement) ===
11195
- IkasCheckoutRequirementEnum.MANDATORY ||
11196
- (((_e = this.checkoutSettings) === null || _e === void 0 ? void 0 : _e.identityNumberRequirement) ===
11197
- IkasCheckoutRequirementEnum.OPTIONAL &&
11198
- this.phone)
11195
+ IkasCheckoutRequirementEnum.MANDATORY
11199
11196
  ? !!this.identityNumber
11200
11197
  : true,
11201
11198
  };
@@ -17475,6 +17472,7 @@ var LS_TOKEN_KEY = "customerToken";
17475
17472
  var LS_TOKEN_EXPIRY = "customerTokenExpiry";
17476
17473
  var LS_CUSTOMER_KEY = "customer";
17477
17474
  var LS_CUSTOMER_SUB_KEY = "customerEmailSubscription";
17475
+ var LS_LAST_VIEWED_PRODUCTS_KEY = "lastViewedProducts";
17478
17476
  var IkasCustomerStore = /** @class */ (function () {
17479
17477
  function IkasCustomerStore(baseStore) {
17480
17478
  var _this = this;
@@ -17484,6 +17482,7 @@ var IkasCustomerStore = /** @class */ (function () {
17484
17482
  this.baseStore = null;
17485
17483
  this._initialized = false;
17486
17484
  this._visitorSubscribedEmail = false;
17485
+ this._lastViewedProducts = [];
17487
17486
  this.login = function (email, password) { return __awaiter(_this, void 0, void 0, function () {
17488
17487
  var response, cart;
17489
17488
  var _a;
@@ -17503,7 +17502,9 @@ var IkasCustomerStore = /** @class */ (function () {
17503
17502
  case 2:
17504
17503
  _b.sent();
17505
17504
  _b.label = 3;
17506
- case 3: return [2 /*return*/, true];
17505
+ case 3:
17506
+ this.saveLocalLastViewedProducts();
17507
+ return [2 /*return*/, true];
17507
17508
  case 4: return [2 /*return*/, false];
17508
17509
  }
17509
17510
  });
@@ -17518,6 +17519,7 @@ var IkasCustomerStore = /** @class */ (function () {
17518
17519
  if (response) {
17519
17520
  this.setToken(response.token, response.tokenExpiry);
17520
17521
  this.setCustomer(response.customer);
17522
+ this.saveLocalLastViewedProducts();
17521
17523
  return [2 /*return*/, true];
17522
17524
  }
17523
17525
  return [2 /*return*/, false];
@@ -17762,6 +17764,7 @@ var IkasCustomerStore = /** @class */ (function () {
17762
17764
  case 0:
17763
17765
  this.loadToken();
17764
17766
  this.loadCustomer();
17767
+ this.loadLastViewedProducts();
17765
17768
  return [4 /*yield*/, this.refreshToken()];
17766
17769
  case 1:
17767
17770
  _a.sent();
@@ -17832,6 +17835,99 @@ var IkasCustomerStore = /** @class */ (function () {
17832
17835
  }
17833
17836
  catch (err) { }
17834
17837
  };
17838
+ IkasCustomerStore.prototype.getLastViewedProducts = function () {
17839
+ return __awaiter(this, void 0, void 0, function () {
17840
+ var _a;
17841
+ return __generator(this, function (_b) {
17842
+ switch (_b.label) {
17843
+ case 0:
17844
+ if (!this.customer) return [3 /*break*/, 2];
17845
+ _a = this;
17846
+ return [4 /*yield*/, IkasCustomerAPI.getLastViewedProducts(this.customer.id)];
17847
+ case 1:
17848
+ _a._lastViewedProducts = _b.sent();
17849
+ return [3 /*break*/, 3];
17850
+ case 2:
17851
+ this.loadLastViewedProducts();
17852
+ _b.label = 3;
17853
+ case 3: return [2 /*return*/, this._lastViewedProducts];
17854
+ }
17855
+ });
17856
+ });
17857
+ };
17858
+ IkasCustomerStore.prototype.saveLastViewedProducts = function () {
17859
+ window.localStorage.setItem(LS_LAST_VIEWED_PRODUCTS_KEY, JSON.stringify(this._lastViewedProducts));
17860
+ };
17861
+ IkasCustomerStore.prototype.loadLastViewedProducts = function () {
17862
+ try {
17863
+ var lvpStr = window.localStorage.getItem(LS_LAST_VIEWED_PRODUCTS_KEY);
17864
+ if (lvpStr)
17865
+ this._lastViewedProducts = JSON.parse(lvpStr);
17866
+ }
17867
+ catch (err) { }
17868
+ };
17869
+ IkasCustomerStore.prototype.removeLastViewedProducts = function () {
17870
+ window.localStorage.removeItem(LS_LAST_VIEWED_PRODUCTS_KEY);
17871
+ };
17872
+ IkasCustomerStore.prototype.onProductView = function (productId, variantId) {
17873
+ return __awaiter(this, void 0, void 0, function () {
17874
+ var isSuccess;
17875
+ return __generator(this, function (_a) {
17876
+ switch (_a.label) {
17877
+ case 0:
17878
+ if (!this.customer) return [3 /*break*/, 2];
17879
+ return [4 /*yield*/, IkasCustomerAPI.saveLastViewedProducts({
17880
+ customerId: this.customer.id,
17881
+ products: [
17882
+ {
17883
+ productId: productId,
17884
+ variantId: variantId,
17885
+ },
17886
+ ],
17887
+ })];
17888
+ case 1:
17889
+ isSuccess = _a.sent();
17890
+ if (isSuccess)
17891
+ this._lastViewedProducts.push({ productId: productId, variantId: variantId });
17892
+ return [3 /*break*/, 3];
17893
+ case 2:
17894
+ this._lastViewedProducts.push({ productId: productId, variantId: variantId });
17895
+ this._lastViewedProducts = this._lastViewedProducts.slice(0, 20);
17896
+ this.saveLastViewedProducts();
17897
+ _a.label = 3;
17898
+ case 3: return [2 /*return*/];
17899
+ }
17900
+ });
17901
+ });
17902
+ };
17903
+ IkasCustomerStore.prototype.saveLocalLastViewedProducts = function () {
17904
+ return __awaiter(this, void 0, void 0, function () {
17905
+ var isSuccess;
17906
+ return __generator(this, function (_a) {
17907
+ switch (_a.label) {
17908
+ case 0:
17909
+ _a.trys.push([0, 3, , 4]);
17910
+ this.loadLastViewedProducts();
17911
+ if (!this._lastViewedProducts.length) return [3 /*break*/, 2];
17912
+ return [4 /*yield*/, IkasCustomerAPI.saveLastViewedProducts({
17913
+ customerId: this.customer.id,
17914
+ products: this._lastViewedProducts,
17915
+ })];
17916
+ case 1:
17917
+ isSuccess = _a.sent();
17918
+ if (isSuccess) {
17919
+ this.removeLastViewedProducts();
17920
+ }
17921
+ _a.label = 2;
17922
+ case 2: return [3 /*break*/, 4];
17923
+ case 3:
17924
+ _a.sent();
17925
+ return [3 /*break*/, 4];
17926
+ case 4: return [2 /*return*/];
17927
+ }
17928
+ });
17929
+ });
17930
+ };
17835
17931
  IkasCustomerStore.prototype.setToken = function (token, tokenExpiry) {
17836
17932
  if (isServer$3)
17837
17933
  return;
@@ -20943,6 +21039,15 @@ var CustomerAccountStatusesEnum;
20943
21039
  CustomerAccountStatusesEnum["DISABLED_ACCOUNT"] = "DISABLED_ACCOUNT";
20944
21040
  CustomerAccountStatusesEnum["INVITED_TO_CREATE_ACCOUNT"] = "INVITED_TO_CREATE_ACCOUNT";
20945
21041
  })(CustomerAccountStatusesEnum || (CustomerAccountStatusesEnum = {}));
21042
+ /**
21043
+ * Customer Email Subscription Statuses
21044
+ */
21045
+ var CustomerEmailSubscriptionStatusesEnum;
21046
+ (function (CustomerEmailSubscriptionStatusesEnum) {
21047
+ CustomerEmailSubscriptionStatusesEnum["NOT_SUBSCRIBED"] = "NOT_SUBSCRIBED";
21048
+ CustomerEmailSubscriptionStatusesEnum["PENDING_CONFIRMATION"] = "PENDING_CONFIRMATION";
21049
+ CustomerEmailSubscriptionStatusesEnum["SUBSCRIBED"] = "SUBSCRIBED";
21050
+ })(CustomerEmailSubscriptionStatusesEnum || (CustomerEmailSubscriptionStatusesEnum = {}));
20946
21051
  /**
20947
21052
  * Url Slug Target Type Enum Codes
20948
21053
  */
@@ -21228,24 +21333,23 @@ var IkasProductList = /** @class */ (function () {
21228
21333
  });
21229
21334
  }); };
21230
21335
  this.getInitial = function (queryParams, isInfiteScrollReturn) { return __awaiter(_this, void 0, void 0, function () {
21231
- var fetchRequestTime, page, limit, response_1, data, err_1;
21232
- var _a;
21233
- return __generator(this, function (_b) {
21234
- switch (_b.label) {
21336
+ var fetchRequestTime, page, limit, productIdList, lastViewedProducts, response_1, data, idList, err_1;
21337
+ return __generator(this, function (_a) {
21338
+ switch (_a.label) {
21235
21339
  case 0:
21236
21340
  this._isLoading = true;
21237
21341
  fetchRequestTime = Date.now();
21238
21342
  this._fetchRequestTime = fetchRequestTime;
21239
- _b.label = 1;
21343
+ _a.label = 1;
21240
21344
  case 1:
21241
- _b.trys.push([1, 5, 6, 7]);
21345
+ _a.trys.push([1, 12, 13, 14]);
21242
21346
  page = isInfiteScrollReturn ? this._page : 1;
21243
21347
  limit = this._limit;
21244
21348
  if (!(this.isFilterable && !this.filters)) return [3 /*break*/, 3];
21245
21349
  return [4 /*yield*/, this.getFilters()];
21246
21350
  case 2:
21247
- _b.sent();
21248
- _b.label = 3;
21351
+ _a.sent();
21352
+ _a.label = 3;
21249
21353
  case 3:
21250
21354
  this.applyQueryParamFilters(queryParams);
21251
21355
  if (this.isSearch && !this.hasAppliedfilter) {
@@ -21256,27 +21360,48 @@ var IkasProductList = /** @class */ (function () {
21256
21360
  this._initialized = true;
21257
21361
  return [2 /*return*/, true];
21258
21362
  }
21259
- if (this.isStatic) {
21260
- page = undefined;
21261
- limit = undefined;
21262
- }
21263
- else if (this.isDiscounted) {
21264
- page = 1;
21265
- limit = 10;
21266
- }
21267
- else if (this.isRecommended) {
21268
- page = 1;
21269
- limit = 10;
21270
- }
21271
- return [4 /*yield*/, this.searchProducts(page || 1, limit || 10)];
21363
+ productIdList = void 0;
21364
+ if (!this.isStatic) return [3 /*break*/, 4];
21365
+ page = undefined;
21366
+ limit = undefined;
21367
+ return [3 /*break*/, 10];
21272
21368
  case 4:
21273
- response_1 = _b.sent();
21369
+ if (!this.isDiscounted) return [3 /*break*/, 5];
21370
+ page = 1;
21371
+ limit = 10;
21372
+ return [3 /*break*/, 10];
21373
+ case 5:
21374
+ if (!this.isRecommended) return [3 /*break*/, 6];
21375
+ page = 1;
21376
+ limit = 10;
21377
+ return [3 /*break*/, 10];
21378
+ case 6:
21379
+ if (!this.isLastViewed) return [3 /*break*/, 10];
21380
+ if (!this.isBrowser()) return [3 /*break*/, 9];
21381
+ return [4 /*yield*/, this.waitForCustomerStoreInit()];
21382
+ case 7:
21383
+ _a.sent();
21384
+ return [4 /*yield*/, IkasStorefrontConfig.store.customerStore.getLastViewedProducts()];
21385
+ case 8:
21386
+ lastViewedProducts = _a.sent();
21387
+ if (lastViewedProducts && lastViewedProducts.length) {
21388
+ productIdList = lastViewedProducts.map(function (p) { return p.productId; });
21389
+ }
21390
+ return [3 /*break*/, 10];
21391
+ case 9: return [2 /*return*/];
21392
+ case 10: return [4 /*yield*/, this.searchProducts(page || 1, limit || 10, productIdList)];
21393
+ case 11:
21394
+ response_1 = _a.sent();
21274
21395
  if (!response_1 || this._fetchRequestTime !== fetchRequestTime)
21275
21396
  return [2 /*return*/];
21276
21397
  data = [];
21277
- if (this.isStatic) {
21398
+ if (this.isStatic || this.isLastViewed) {
21399
+ idList = this.isStatic
21400
+ ? this._productListPropValue.productIds
21401
+ : //@ts-ignore
21402
+ IkasStorefrontConfig.store.customerStore._lastViewedProducts;
21278
21403
  data =
21279
- ((_a = this._productListPropValue.productIds) === null || _a === void 0 ? void 0 : _a.map(function (pID) {
21404
+ (idList === null || idList === void 0 ? void 0 : idList.map(function (pID) {
21280
21405
  var product = response_1.data.find(function (p) { return p.id === pID.productId; });
21281
21406
  var variant = product === null || product === void 0 ? void 0 : product.variants.find(function (v) { return v.id === pID.variantId; });
21282
21407
  if (product && variant)
@@ -21294,16 +21419,18 @@ var IkasProductList = /** @class */ (function () {
21294
21419
  this._initialized = true;
21295
21420
  this._page = page || 1;
21296
21421
  this._minPage = this.page;
21422
+ if (!isInfiteScrollReturn)
21423
+ this._infiniteScrollPage = null;
21297
21424
  return [2 /*return*/, true];
21298
- case 5:
21299
- err_1 = _b.sent();
21425
+ case 12:
21426
+ err_1 = _a.sent();
21300
21427
  console.log(err_1);
21301
- return [3 /*break*/, 7];
21302
- case 6:
21428
+ return [3 /*break*/, 14];
21429
+ case 13:
21303
21430
  if (fetchRequestTime === this._fetchRequestTime)
21304
21431
  this._isLoading = false;
21305
21432
  return [7 /*endfinally*/];
21306
- case 7: return [2 /*return*/];
21433
+ case 14: return [2 /*return*/];
21307
21434
  }
21308
21435
  });
21309
21436
  }); };
@@ -21478,6 +21605,9 @@ var IkasProductList = /** @class */ (function () {
21478
21605
  else if (this._page > 1) {
21479
21606
  this.getInitial(undefined, true);
21480
21607
  }
21608
+ else if (this.isLastViewed) {
21609
+ this.getInitial();
21610
+ }
21481
21611
  }
21482
21612
  }
21483
21613
  Object.defineProperty(IkasProductList.prototype, "id", {
@@ -21602,6 +21732,13 @@ var IkasProductList = /** @class */ (function () {
21602
21732
  enumerable: false,
21603
21733
  configurable: true
21604
21734
  });
21735
+ Object.defineProperty(IkasProductList.prototype, "isLastViewed", {
21736
+ get: function () {
21737
+ return this._type === IkasProductListType.LAST_VIEWED;
21738
+ },
21739
+ enumerable: false,
21740
+ configurable: true
21741
+ });
21605
21742
  Object.defineProperty(IkasProductList.prototype, "isSearch", {
21606
21743
  get: function () {
21607
21744
  return this._type === IkasProductListType.SEARCH;
@@ -21719,7 +21856,7 @@ var IkasProductList = /** @class */ (function () {
21719
21856
  type: type,
21720
21857
  };
21721
21858
  };
21722
- IkasProductList.prototype.searchProducts = function (page, limit) {
21859
+ IkasProductList.prototype.searchProducts = function (page, limit, productIdList) {
21723
21860
  var _a, _b;
21724
21861
  return __awaiter(this, void 0, void 0, function () {
21725
21862
  var filterList;
@@ -21747,7 +21884,7 @@ var IkasProductList = /** @class */ (function () {
21747
21884
  page: page,
21748
21885
  perPage: limit,
21749
21886
  productIdList: this.isStatic
21750
- ? (_b = this._productListPropValue.productIds) === null || _b === void 0 ? void 0 : _b.map(function (p) { return p.productId; }) : undefined,
21887
+ ? (_b = this._productListPropValue.productIds) === null || _b === void 0 ? void 0 : _b.map(function (p) { return p.productId; }) : productIdList,
21751
21888
  filterList: filterList,
21752
21889
  brandId: this._pageType === IkasThemePageType.BRAND &&
21753
21890
  this._type !== IkasProductListType.SEARCH
@@ -21933,6 +22070,16 @@ var IkasProductList = /** @class */ (function () {
21933
22070
  IkasProductList.prototype.isBrowser = function () {
21934
22071
  return typeof window !== "undefined";
21935
22072
  };
22073
+ IkasProductList.prototype.waitForCustomerStoreInit = function () {
22074
+ return new Promise(function (resolve) {
22075
+ var interval = setInterval(function () {
22076
+ if (IkasStorefrontConfig.store.customerStore.initialized) {
22077
+ clearInterval(interval);
22078
+ resolve(null);
22079
+ }
22080
+ }, 1000);
22081
+ });
22082
+ };
21936
22083
  return IkasProductList;
21937
22084
  }());
21938
22085
  var IkasProductListType;
@@ -21943,6 +22090,7 @@ var IkasProductListType;
21943
22090
  IkasProductListType["RECOMMENDED"] = "RECOMMENDED";
21944
22091
  IkasProductListType["CATEGORY"] = "CATEGORY";
21945
22092
  IkasProductListType["SEARCH"] = "SEARCH";
22093
+ IkasProductListType["LAST_VIEWED"] = "LAST_VIEWED";
21946
22094
  })(IkasProductListType || (IkasProductListType = {}));
21947
22095
  var IkasProductListSortType;
21948
22096
  (function (IkasProductListSortType) {
@@ -27699,9 +27847,73 @@ var IkasCustomerAPI = /** @class */ (function () {
27699
27847
  });
27700
27848
  });
27701
27849
  };
27850
+ IkasCustomerAPI.getLastViewedProducts = function (customerId) {
27851
+ return __awaiter(this, void 0, void 0, function () {
27852
+ var QUERY, _a, data, errors, error_2;
27853
+ return __generator(this, function (_b) {
27854
+ switch (_b.label) {
27855
+ case 0:
27856
+ QUERY = src(templateObject_13 || (templateObject_13 = __makeTemplateObject(["\n query getLastViewedProducts($customerId: String) {\n getLastViewedProducts(customerId: $customerId) {\n products {\n productId\n variantId\n }\n }\n }\n "], ["\n query getLastViewedProducts($customerId: String) {\n getLastViewedProducts(customerId: $customerId) {\n products {\n productId\n variantId\n }\n }\n }\n "])));
27857
+ _b.label = 1;
27858
+ case 1:
27859
+ _b.trys.push([1, 3, , 4]);
27860
+ return [4 /*yield*/, apollo
27861
+ .getClient()
27862
+ .query({
27863
+ query: QUERY,
27864
+ variables: {
27865
+ customerId: customerId,
27866
+ },
27867
+ })];
27868
+ case 2:
27869
+ _a = _b.sent(), data = _a.data, errors = _a.errors;
27870
+ if (errors && errors.length)
27871
+ return [2 /*return*/, []];
27872
+ return [2 /*return*/, data.getLastViewedProducts.products];
27873
+ case 3:
27874
+ error_2 = _b.sent();
27875
+ console.log(error_2);
27876
+ return [2 /*return*/, []];
27877
+ case 4: return [2 /*return*/];
27878
+ }
27879
+ });
27880
+ });
27881
+ };
27882
+ IkasCustomerAPI.saveLastViewedProducts = function (input) {
27883
+ return __awaiter(this, void 0, void 0, function () {
27884
+ var MUTATION, errors, err_12;
27885
+ return __generator(this, function (_a) {
27886
+ switch (_a.label) {
27887
+ case 0:
27888
+ MUTATION = src(templateObject_14 || (templateObject_14 = __makeTemplateObject(["\n mutation saveLastViewedProducts($input: ProductLastViewedInput!) {\n saveLastViewedProducts(input: $input) {\n id\n }\n }\n "], ["\n mutation saveLastViewedProducts($input: ProductLastViewedInput!) {\n saveLastViewedProducts(input: $input) {\n id\n }\n }\n "])));
27889
+ _a.label = 1;
27890
+ case 1:
27891
+ _a.trys.push([1, 3, , 4]);
27892
+ return [4 /*yield*/, apollo
27893
+ .getClient()
27894
+ .mutate({
27895
+ mutation: MUTATION,
27896
+ variables: {
27897
+ input: input,
27898
+ },
27899
+ })];
27900
+ case 2:
27901
+ errors = (_a.sent()).errors;
27902
+ if (errors && errors.length)
27903
+ return [2 /*return*/, false];
27904
+ return [3 /*break*/, 4];
27905
+ case 3:
27906
+ err_12 = _a.sent();
27907
+ console.log(err_12);
27908
+ return [2 /*return*/, false];
27909
+ case 4: return [2 /*return*/, true];
27910
+ }
27911
+ });
27912
+ });
27913
+ };
27702
27914
  return IkasCustomerAPI;
27703
27915
  }());
27704
- var templateObject_1$7, templateObject_2$5, templateObject_3$3, templateObject_4$2, templateObject_5$1, templateObject_6$1, templateObject_7$1, templateObject_8$1, templateObject_9, templateObject_10, templateObject_11, templateObject_12;
27916
+ var templateObject_1$7, templateObject_2$5, templateObject_3$3, templateObject_4$2, templateObject_5$1, templateObject_6$1, templateObject_7$1, templateObject_8$1, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14;
27705
27917
 
27706
27918
  var IkasDistrictAPI = /** @class */ (function () {
27707
27919
  function IkasDistrictAPI() {
@@ -30016,7 +30228,7 @@ var style = {
30016
30228
  backgroundColor: "rgba(255, 0, 0, 0.5)",
30017
30229
  };
30018
30230
 
30019
- var PACKAGE_VERSION = "0.0.139";
30231
+ var PACKAGE_VERSION = "0.0.158";
30020
30232
  var PageViewModel = /** @class */ (function () {
30021
30233
  function PageViewModel(router) {
30022
30234
  var _this = this;
@@ -30968,6 +31180,8 @@ function handleAnalytics(page, pageSpecificDataStr) {
30968
31180
  var productDetailParsed = JSON.parse(pageSpecificDataStr);
30969
31181
  var productDetail = new IkasProductDetail(productDetailParsed.product, productDetailParsed.selectedVariantValues);
30970
31182
  Analytics.productView(productDetail);
31183
+ // @ts-ignore
31184
+ IkasStorefrontConfig.store.customerStore.onProductView(productDetail.product.id, productDetail.selectedVariant.id);
30971
31185
  }
30972
31186
  if (page.type === IkasThemePageType.CATEGORY) {
30973
31187
  var category = JSON.parse(pageSpecificDataStr);
package/build/index.js CHANGED
@@ -11185,7 +11185,7 @@ var IkasOrderAddress = /** @class */ (function () {
11185
11185
  });
11186
11186
  Object.defineProperty(IkasOrderAddress.prototype, "validationResult", {
11187
11187
  get: function () {
11188
- var _a, _b, _c, _d, _e;
11188
+ var _a, _b, _c, _d;
11189
11189
  var isValidPhone = !!this.phone &&
11190
11190
  this.phone.length >= 10 &&
11191
11191
  validatePhoneNumber(this.phone);
@@ -11206,10 +11206,7 @@ var IkasOrderAddress = /** @class */ (function () {
11206
11206
  ? isValidPhone
11207
11207
  : true,
11208
11208
  identityNumber: ((_d = this.checkoutSettings) === null || _d === void 0 ? void 0 : _d.identityNumberRequirement) ===
11209
- IkasCheckoutRequirementEnum.MANDATORY ||
11210
- (((_e = this.checkoutSettings) === null || _e === void 0 ? void 0 : _e.identityNumberRequirement) ===
11211
- IkasCheckoutRequirementEnum.OPTIONAL &&
11212
- this.phone)
11209
+ IkasCheckoutRequirementEnum.MANDATORY
11213
11210
  ? !!this.identityNumber
11214
11211
  : true,
11215
11212
  };
@@ -17481,6 +17478,7 @@ var LS_TOKEN_KEY = "customerToken";
17481
17478
  var LS_TOKEN_EXPIRY = "customerTokenExpiry";
17482
17479
  var LS_CUSTOMER_KEY = "customer";
17483
17480
  var LS_CUSTOMER_SUB_KEY = "customerEmailSubscription";
17481
+ var LS_LAST_VIEWED_PRODUCTS_KEY = "lastViewedProducts";
17484
17482
  var IkasCustomerStore = /** @class */ (function () {
17485
17483
  function IkasCustomerStore(baseStore) {
17486
17484
  var _this = this;
@@ -17490,6 +17488,7 @@ var IkasCustomerStore = /** @class */ (function () {
17490
17488
  this.baseStore = null;
17491
17489
  this._initialized = false;
17492
17490
  this._visitorSubscribedEmail = false;
17491
+ this._lastViewedProducts = [];
17493
17492
  this.login = function (email, password) { return __awaiter(_this, void 0, void 0, function () {
17494
17493
  var response, cart;
17495
17494
  var _a;
@@ -17509,7 +17508,9 @@ var IkasCustomerStore = /** @class */ (function () {
17509
17508
  case 2:
17510
17509
  _b.sent();
17511
17510
  _b.label = 3;
17512
- case 3: return [2 /*return*/, true];
17511
+ case 3:
17512
+ this.saveLocalLastViewedProducts();
17513
+ return [2 /*return*/, true];
17513
17514
  case 4: return [2 /*return*/, false];
17514
17515
  }
17515
17516
  });
@@ -17524,6 +17525,7 @@ var IkasCustomerStore = /** @class */ (function () {
17524
17525
  if (response) {
17525
17526
  this.setToken(response.token, response.tokenExpiry);
17526
17527
  this.setCustomer(response.customer);
17528
+ this.saveLocalLastViewedProducts();
17527
17529
  return [2 /*return*/, true];
17528
17530
  }
17529
17531
  return [2 /*return*/, false];
@@ -17768,6 +17770,7 @@ var IkasCustomerStore = /** @class */ (function () {
17768
17770
  case 0:
17769
17771
  this.loadToken();
17770
17772
  this.loadCustomer();
17773
+ this.loadLastViewedProducts();
17771
17774
  return [4 /*yield*/, this.refreshToken()];
17772
17775
  case 1:
17773
17776
  _a.sent();
@@ -17838,6 +17841,99 @@ var IkasCustomerStore = /** @class */ (function () {
17838
17841
  }
17839
17842
  catch (err) { }
17840
17843
  };
17844
+ IkasCustomerStore.prototype.getLastViewedProducts = function () {
17845
+ return __awaiter(this, void 0, void 0, function () {
17846
+ var _a;
17847
+ return __generator(this, function (_b) {
17848
+ switch (_b.label) {
17849
+ case 0:
17850
+ if (!this.customer) return [3 /*break*/, 2];
17851
+ _a = this;
17852
+ return [4 /*yield*/, IkasCustomerAPI.getLastViewedProducts(this.customer.id)];
17853
+ case 1:
17854
+ _a._lastViewedProducts = _b.sent();
17855
+ return [3 /*break*/, 3];
17856
+ case 2:
17857
+ this.loadLastViewedProducts();
17858
+ _b.label = 3;
17859
+ case 3: return [2 /*return*/, this._lastViewedProducts];
17860
+ }
17861
+ });
17862
+ });
17863
+ };
17864
+ IkasCustomerStore.prototype.saveLastViewedProducts = function () {
17865
+ window.localStorage.setItem(LS_LAST_VIEWED_PRODUCTS_KEY, JSON.stringify(this._lastViewedProducts));
17866
+ };
17867
+ IkasCustomerStore.prototype.loadLastViewedProducts = function () {
17868
+ try {
17869
+ var lvpStr = window.localStorage.getItem(LS_LAST_VIEWED_PRODUCTS_KEY);
17870
+ if (lvpStr)
17871
+ this._lastViewedProducts = JSON.parse(lvpStr);
17872
+ }
17873
+ catch (err) { }
17874
+ };
17875
+ IkasCustomerStore.prototype.removeLastViewedProducts = function () {
17876
+ window.localStorage.removeItem(LS_LAST_VIEWED_PRODUCTS_KEY);
17877
+ };
17878
+ IkasCustomerStore.prototype.onProductView = function (productId, variantId) {
17879
+ return __awaiter(this, void 0, void 0, function () {
17880
+ var isSuccess;
17881
+ return __generator(this, function (_a) {
17882
+ switch (_a.label) {
17883
+ case 0:
17884
+ if (!this.customer) return [3 /*break*/, 2];
17885
+ return [4 /*yield*/, IkasCustomerAPI.saveLastViewedProducts({
17886
+ customerId: this.customer.id,
17887
+ products: [
17888
+ {
17889
+ productId: productId,
17890
+ variantId: variantId,
17891
+ },
17892
+ ],
17893
+ })];
17894
+ case 1:
17895
+ isSuccess = _a.sent();
17896
+ if (isSuccess)
17897
+ this._lastViewedProducts.push({ productId: productId, variantId: variantId });
17898
+ return [3 /*break*/, 3];
17899
+ case 2:
17900
+ this._lastViewedProducts.push({ productId: productId, variantId: variantId });
17901
+ this._lastViewedProducts = this._lastViewedProducts.slice(0, 20);
17902
+ this.saveLastViewedProducts();
17903
+ _a.label = 3;
17904
+ case 3: return [2 /*return*/];
17905
+ }
17906
+ });
17907
+ });
17908
+ };
17909
+ IkasCustomerStore.prototype.saveLocalLastViewedProducts = function () {
17910
+ return __awaiter(this, void 0, void 0, function () {
17911
+ var isSuccess;
17912
+ return __generator(this, function (_a) {
17913
+ switch (_a.label) {
17914
+ case 0:
17915
+ _a.trys.push([0, 3, , 4]);
17916
+ this.loadLastViewedProducts();
17917
+ if (!this._lastViewedProducts.length) return [3 /*break*/, 2];
17918
+ return [4 /*yield*/, IkasCustomerAPI.saveLastViewedProducts({
17919
+ customerId: this.customer.id,
17920
+ products: this._lastViewedProducts,
17921
+ })];
17922
+ case 1:
17923
+ isSuccess = _a.sent();
17924
+ if (isSuccess) {
17925
+ this.removeLastViewedProducts();
17926
+ }
17927
+ _a.label = 2;
17928
+ case 2: return [3 /*break*/, 4];
17929
+ case 3:
17930
+ _a.sent();
17931
+ return [3 /*break*/, 4];
17932
+ case 4: return [2 /*return*/];
17933
+ }
17934
+ });
17935
+ });
17936
+ };
17841
17937
  IkasCustomerStore.prototype.setToken = function (token, tokenExpiry) {
17842
17938
  if (isServer$3)
17843
17939
  return;
@@ -20926,6 +21022,15 @@ var CustomerAccountStatusesEnum;
20926
21022
  CustomerAccountStatusesEnum["DISABLED_ACCOUNT"] = "DISABLED_ACCOUNT";
20927
21023
  CustomerAccountStatusesEnum["INVITED_TO_CREATE_ACCOUNT"] = "INVITED_TO_CREATE_ACCOUNT";
20928
21024
  })(CustomerAccountStatusesEnum || (CustomerAccountStatusesEnum = {}));
21025
+ /**
21026
+ * Customer Email Subscription Statuses
21027
+ */
21028
+ var CustomerEmailSubscriptionStatusesEnum;
21029
+ (function (CustomerEmailSubscriptionStatusesEnum) {
21030
+ CustomerEmailSubscriptionStatusesEnum["NOT_SUBSCRIBED"] = "NOT_SUBSCRIBED";
21031
+ CustomerEmailSubscriptionStatusesEnum["PENDING_CONFIRMATION"] = "PENDING_CONFIRMATION";
21032
+ CustomerEmailSubscriptionStatusesEnum["SUBSCRIBED"] = "SUBSCRIBED";
21033
+ })(CustomerEmailSubscriptionStatusesEnum || (CustomerEmailSubscriptionStatusesEnum = {}));
20929
21034
  /**
20930
21035
  * Url Slug Target Type Enum Codes
20931
21036
  */
@@ -21211,24 +21316,23 @@ var IkasProductList = /** @class */ (function () {
21211
21316
  });
21212
21317
  }); };
21213
21318
  this.getInitial = function (queryParams, isInfiteScrollReturn) { return __awaiter(_this, void 0, void 0, function () {
21214
- var fetchRequestTime, page, limit, response_1, data, err_1;
21215
- var _a;
21216
- return __generator(this, function (_b) {
21217
- switch (_b.label) {
21319
+ var fetchRequestTime, page, limit, productIdList, lastViewedProducts, response_1, data, idList, err_1;
21320
+ return __generator(this, function (_a) {
21321
+ switch (_a.label) {
21218
21322
  case 0:
21219
21323
  this._isLoading = true;
21220
21324
  fetchRequestTime = Date.now();
21221
21325
  this._fetchRequestTime = fetchRequestTime;
21222
- _b.label = 1;
21326
+ _a.label = 1;
21223
21327
  case 1:
21224
- _b.trys.push([1, 5, 6, 7]);
21328
+ _a.trys.push([1, 12, 13, 14]);
21225
21329
  page = isInfiteScrollReturn ? this._page : 1;
21226
21330
  limit = this._limit;
21227
21331
  if (!(this.isFilterable && !this.filters)) return [3 /*break*/, 3];
21228
21332
  return [4 /*yield*/, this.getFilters()];
21229
21333
  case 2:
21230
- _b.sent();
21231
- _b.label = 3;
21334
+ _a.sent();
21335
+ _a.label = 3;
21232
21336
  case 3:
21233
21337
  this.applyQueryParamFilters(queryParams);
21234
21338
  if (this.isSearch && !this.hasAppliedfilter) {
@@ -21239,27 +21343,48 @@ var IkasProductList = /** @class */ (function () {
21239
21343
  this._initialized = true;
21240
21344
  return [2 /*return*/, true];
21241
21345
  }
21242
- if (this.isStatic) {
21243
- page = undefined;
21244
- limit = undefined;
21245
- }
21246
- else if (this.isDiscounted) {
21247
- page = 1;
21248
- limit = 10;
21249
- }
21250
- else if (this.isRecommended) {
21251
- page = 1;
21252
- limit = 10;
21253
- }
21254
- return [4 /*yield*/, this.searchProducts(page || 1, limit || 10)];
21346
+ productIdList = void 0;
21347
+ if (!this.isStatic) return [3 /*break*/, 4];
21348
+ page = undefined;
21349
+ limit = undefined;
21350
+ return [3 /*break*/, 10];
21255
21351
  case 4:
21256
- response_1 = _b.sent();
21352
+ if (!this.isDiscounted) return [3 /*break*/, 5];
21353
+ page = 1;
21354
+ limit = 10;
21355
+ return [3 /*break*/, 10];
21356
+ case 5:
21357
+ if (!this.isRecommended) return [3 /*break*/, 6];
21358
+ page = 1;
21359
+ limit = 10;
21360
+ return [3 /*break*/, 10];
21361
+ case 6:
21362
+ if (!this.isLastViewed) return [3 /*break*/, 10];
21363
+ if (!this.isBrowser()) return [3 /*break*/, 9];
21364
+ return [4 /*yield*/, this.waitForCustomerStoreInit()];
21365
+ case 7:
21366
+ _a.sent();
21367
+ return [4 /*yield*/, IkasStorefrontConfig.store.customerStore.getLastViewedProducts()];
21368
+ case 8:
21369
+ lastViewedProducts = _a.sent();
21370
+ if (lastViewedProducts && lastViewedProducts.length) {
21371
+ productIdList = lastViewedProducts.map(function (p) { return p.productId; });
21372
+ }
21373
+ return [3 /*break*/, 10];
21374
+ case 9: return [2 /*return*/];
21375
+ case 10: return [4 /*yield*/, this.searchProducts(page || 1, limit || 10, productIdList)];
21376
+ case 11:
21377
+ response_1 = _a.sent();
21257
21378
  if (!response_1 || this._fetchRequestTime !== fetchRequestTime)
21258
21379
  return [2 /*return*/];
21259
21380
  data = [];
21260
- if (this.isStatic) {
21381
+ if (this.isStatic || this.isLastViewed) {
21382
+ idList = this.isStatic
21383
+ ? this._productListPropValue.productIds
21384
+ : //@ts-ignore
21385
+ IkasStorefrontConfig.store.customerStore._lastViewedProducts;
21261
21386
  data =
21262
- ((_a = this._productListPropValue.productIds) === null || _a === void 0 ? void 0 : _a.map(function (pID) {
21387
+ (idList === null || idList === void 0 ? void 0 : idList.map(function (pID) {
21263
21388
  var product = response_1.data.find(function (p) { return p.id === pID.productId; });
21264
21389
  var variant = product === null || product === void 0 ? void 0 : product.variants.find(function (v) { return v.id === pID.variantId; });
21265
21390
  if (product && variant)
@@ -21277,16 +21402,18 @@ var IkasProductList = /** @class */ (function () {
21277
21402
  this._initialized = true;
21278
21403
  this._page = page || 1;
21279
21404
  this._minPage = this.page;
21405
+ if (!isInfiteScrollReturn)
21406
+ this._infiniteScrollPage = null;
21280
21407
  return [2 /*return*/, true];
21281
- case 5:
21282
- err_1 = _b.sent();
21408
+ case 12:
21409
+ err_1 = _a.sent();
21283
21410
  console.log(err_1);
21284
- return [3 /*break*/, 7];
21285
- case 6:
21411
+ return [3 /*break*/, 14];
21412
+ case 13:
21286
21413
  if (fetchRequestTime === this._fetchRequestTime)
21287
21414
  this._isLoading = false;
21288
21415
  return [7 /*endfinally*/];
21289
- case 7: return [2 /*return*/];
21416
+ case 14: return [2 /*return*/];
21290
21417
  }
21291
21418
  });
21292
21419
  }); };
@@ -21461,6 +21588,9 @@ var IkasProductList = /** @class */ (function () {
21461
21588
  else if (this._page > 1) {
21462
21589
  this.getInitial(undefined, true);
21463
21590
  }
21591
+ else if (this.isLastViewed) {
21592
+ this.getInitial();
21593
+ }
21464
21594
  }
21465
21595
  }
21466
21596
  Object.defineProperty(IkasProductList.prototype, "id", {
@@ -21585,6 +21715,13 @@ var IkasProductList = /** @class */ (function () {
21585
21715
  enumerable: false,
21586
21716
  configurable: true
21587
21717
  });
21718
+ Object.defineProperty(IkasProductList.prototype, "isLastViewed", {
21719
+ get: function () {
21720
+ return this._type === exports.IkasProductListType.LAST_VIEWED;
21721
+ },
21722
+ enumerable: false,
21723
+ configurable: true
21724
+ });
21588
21725
  Object.defineProperty(IkasProductList.prototype, "isSearch", {
21589
21726
  get: function () {
21590
21727
  return this._type === exports.IkasProductListType.SEARCH;
@@ -21702,7 +21839,7 @@ var IkasProductList = /** @class */ (function () {
21702
21839
  type: type,
21703
21840
  };
21704
21841
  };
21705
- IkasProductList.prototype.searchProducts = function (page, limit) {
21842
+ IkasProductList.prototype.searchProducts = function (page, limit, productIdList) {
21706
21843
  var _a, _b;
21707
21844
  return __awaiter(this, void 0, void 0, function () {
21708
21845
  var filterList;
@@ -21730,7 +21867,7 @@ var IkasProductList = /** @class */ (function () {
21730
21867
  page: page,
21731
21868
  perPage: limit,
21732
21869
  productIdList: this.isStatic
21733
- ? (_b = this._productListPropValue.productIds) === null || _b === void 0 ? void 0 : _b.map(function (p) { return p.productId; }) : undefined,
21870
+ ? (_b = this._productListPropValue.productIds) === null || _b === void 0 ? void 0 : _b.map(function (p) { return p.productId; }) : productIdList,
21734
21871
  filterList: filterList,
21735
21872
  brandId: this._pageType === exports.IkasThemePageType.BRAND &&
21736
21873
  this._type !== exports.IkasProductListType.SEARCH
@@ -21916,6 +22053,16 @@ var IkasProductList = /** @class */ (function () {
21916
22053
  IkasProductList.prototype.isBrowser = function () {
21917
22054
  return typeof window !== "undefined";
21918
22055
  };
22056
+ IkasProductList.prototype.waitForCustomerStoreInit = function () {
22057
+ return new Promise(function (resolve) {
22058
+ var interval = setInterval(function () {
22059
+ if (IkasStorefrontConfig.store.customerStore.initialized) {
22060
+ clearInterval(interval);
22061
+ resolve(null);
22062
+ }
22063
+ }, 1000);
22064
+ });
22065
+ };
21919
22066
  return IkasProductList;
21920
22067
  }());
21921
22068
  (function (IkasProductListType) {
@@ -21925,6 +22072,7 @@ var IkasProductList = /** @class */ (function () {
21925
22072
  IkasProductListType["RECOMMENDED"] = "RECOMMENDED";
21926
22073
  IkasProductListType["CATEGORY"] = "CATEGORY";
21927
22074
  IkasProductListType["SEARCH"] = "SEARCH";
22075
+ IkasProductListType["LAST_VIEWED"] = "LAST_VIEWED";
21928
22076
  })(exports.IkasProductListType || (exports.IkasProductListType = {}));
21929
22077
  (function (IkasProductListSortType) {
21930
22078
  // A_Z = "A_Z",
@@ -27678,9 +27826,73 @@ var IkasCustomerAPI = /** @class */ (function () {
27678
27826
  });
27679
27827
  });
27680
27828
  };
27829
+ IkasCustomerAPI.getLastViewedProducts = function (customerId) {
27830
+ return __awaiter(this, void 0, void 0, function () {
27831
+ var QUERY, _a, data, errors, error_2;
27832
+ return __generator(this, function (_b) {
27833
+ switch (_b.label) {
27834
+ case 0:
27835
+ QUERY = src(templateObject_13 || (templateObject_13 = __makeTemplateObject(["\n query getLastViewedProducts($customerId: String) {\n getLastViewedProducts(customerId: $customerId) {\n products {\n productId\n variantId\n }\n }\n }\n "], ["\n query getLastViewedProducts($customerId: String) {\n getLastViewedProducts(customerId: $customerId) {\n products {\n productId\n variantId\n }\n }\n }\n "])));
27836
+ _b.label = 1;
27837
+ case 1:
27838
+ _b.trys.push([1, 3, , 4]);
27839
+ return [4 /*yield*/, apollo
27840
+ .getClient()
27841
+ .query({
27842
+ query: QUERY,
27843
+ variables: {
27844
+ customerId: customerId,
27845
+ },
27846
+ })];
27847
+ case 2:
27848
+ _a = _b.sent(), data = _a.data, errors = _a.errors;
27849
+ if (errors && errors.length)
27850
+ return [2 /*return*/, []];
27851
+ return [2 /*return*/, data.getLastViewedProducts.products];
27852
+ case 3:
27853
+ error_2 = _b.sent();
27854
+ console.log(error_2);
27855
+ return [2 /*return*/, []];
27856
+ case 4: return [2 /*return*/];
27857
+ }
27858
+ });
27859
+ });
27860
+ };
27861
+ IkasCustomerAPI.saveLastViewedProducts = function (input) {
27862
+ return __awaiter(this, void 0, void 0, function () {
27863
+ var MUTATION, errors, err_12;
27864
+ return __generator(this, function (_a) {
27865
+ switch (_a.label) {
27866
+ case 0:
27867
+ MUTATION = src(templateObject_14 || (templateObject_14 = __makeTemplateObject(["\n mutation saveLastViewedProducts($input: ProductLastViewedInput!) {\n saveLastViewedProducts(input: $input) {\n id\n }\n }\n "], ["\n mutation saveLastViewedProducts($input: ProductLastViewedInput!) {\n saveLastViewedProducts(input: $input) {\n id\n }\n }\n "])));
27868
+ _a.label = 1;
27869
+ case 1:
27870
+ _a.trys.push([1, 3, , 4]);
27871
+ return [4 /*yield*/, apollo
27872
+ .getClient()
27873
+ .mutate({
27874
+ mutation: MUTATION,
27875
+ variables: {
27876
+ input: input,
27877
+ },
27878
+ })];
27879
+ case 2:
27880
+ errors = (_a.sent()).errors;
27881
+ if (errors && errors.length)
27882
+ return [2 /*return*/, false];
27883
+ return [3 /*break*/, 4];
27884
+ case 3:
27885
+ err_12 = _a.sent();
27886
+ console.log(err_12);
27887
+ return [2 /*return*/, false];
27888
+ case 4: return [2 /*return*/, true];
27889
+ }
27890
+ });
27891
+ });
27892
+ };
27681
27893
  return IkasCustomerAPI;
27682
27894
  }());
27683
- var templateObject_1$7, templateObject_2$5, templateObject_3$3, templateObject_4$2, templateObject_5$1, templateObject_6$1, templateObject_7$1, templateObject_8$1, templateObject_9, templateObject_10, templateObject_11, templateObject_12;
27895
+ var templateObject_1$7, templateObject_2$5, templateObject_3$3, templateObject_4$2, templateObject_5$1, templateObject_6$1, templateObject_7$1, templateObject_8$1, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14;
27684
27896
 
27685
27897
  var IkasDistrictAPI = /** @class */ (function () {
27686
27898
  function IkasDistrictAPI() {
@@ -29995,7 +30207,7 @@ var style = {
29995
30207
  backgroundColor: "rgba(255, 0, 0, 0.5)",
29996
30208
  };
29997
30209
 
29998
- var PACKAGE_VERSION = "0.0.139";
30210
+ var PACKAGE_VERSION = "0.0.158";
29999
30211
  var PageViewModel = /** @class */ (function () {
30000
30212
  function PageViewModel(router) {
30001
30213
  var _this = this;
@@ -30947,6 +31159,8 @@ function handleAnalytics(page, pageSpecificDataStr) {
30947
31159
  var productDetailParsed = JSON.parse(pageSpecificDataStr);
30948
31160
  var productDetail = new IkasProductDetail(productDetailParsed.product, productDetailParsed.selectedVariantValues);
30949
31161
  Analytics.productView(productDetail);
31162
+ // @ts-ignore
31163
+ IkasStorefrontConfig.store.customerStore.onProductView(productDetail.product.id, productDetail.selectedVariant.id);
30950
31164
  }
30951
31165
  if (page.type === exports.IkasThemePageType.CATEGORY) {
30952
31166
  var category = JSON.parse(pageSpecificDataStr);
@@ -41,6 +41,7 @@ export declare class IkasProductList {
41
41
  get isStatic(): boolean;
42
42
  get isDiscounted(): boolean;
43
43
  get isRecommended(): boolean;
44
+ get isLastViewed(): boolean;
44
45
  get isSearch(): boolean;
45
46
  get hasPrev(): boolean;
46
47
  get hasNext(): boolean;
@@ -83,6 +84,7 @@ export declare class IkasProductList {
83
84
  private restoreInfiniteScrollPage;
84
85
  private getQueryParams;
85
86
  private isBrowser;
87
+ private waitForCustomerStoreInit;
86
88
  private searchDebouncer;
87
89
  private analyticsDebouncer;
88
90
  }
@@ -110,7 +112,8 @@ export declare enum IkasProductListType {
110
112
  DISCOUNTED = "DISCOUNTED",
111
113
  RECOMMENDED = "RECOMMENDED",
112
114
  CATEGORY = "CATEGORY",
113
- SEARCH = "SEARCH"
115
+ SEARCH = "SEARCH",
116
+ LAST_VIEWED = "LAST_VIEWED"
114
117
  }
115
118
  export declare enum IkasProductListSortType {
116
119
  INCREASING_PRICE = "INCREASING_PRICE",
@@ -1,11 +1,5 @@
1
1
  import { IkasCustomer, IkasFavoriteProduct, IkasOrderTransaction, IkasProduct } from "../models/index";
2
2
  import { IkasBaseStore } from "./base";
3
- declare type SaveContactForm = {
4
- firstName: string;
5
- lastName: string;
6
- email: string;
7
- message: string;
8
- };
9
3
  export declare class IkasCustomerStore {
10
4
  customer?: IkasCustomer | null;
11
5
  token?: string | null;
@@ -13,6 +7,7 @@ export declare class IkasCustomerStore {
13
7
  private baseStore?;
14
8
  private _initialized;
15
9
  private _visitorSubscribedEmail;
10
+ private _lastViewedProducts;
16
11
  constructor(baseStore?: IkasBaseStore);
17
12
  get initialized(): boolean;
18
13
  get canCreateEmailSubscription(): boolean;
@@ -42,8 +37,20 @@ export declare class IkasCustomerStore {
42
37
  private refreshToken;
43
38
  private setCustomer;
44
39
  private loadCustomer;
40
+ private getLastViewedProducts;
41
+ private saveLastViewedProducts;
42
+ private loadLastViewedProducts;
43
+ private removeLastViewedProducts;
44
+ private onProductView;
45
+ private saveLocalLastViewedProducts;
45
46
  private setToken;
46
47
  private loadToken;
47
48
  private clearLocalData;
48
49
  }
50
+ declare type SaveContactForm = {
51
+ firstName: string;
52
+ lastName: string;
53
+ email: string;
54
+ message: string;
55
+ };
49
56
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront",
3
- "version": "0.0.158-alpha.3",
3
+ "version": "0.0.158-alpha.5",
4
4
  "main": "./build/index.js",
5
5
  "module": "./build/index.es.js",
6
6
  "author": "Umut Ozan Yıldırım",