@ikas/storefront-providers 4.0.0-alpha.5 → 4.0.0-alpha.50

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront-providers",
3
- "version": "4.0.0-alpha.5",
3
+ "version": "4.0.0-alpha.50",
4
4
  "description": "Data providers for ikas storefront theme components.",
5
5
  "author": "Umut Ozan Yıldırım",
6
6
  "license": "ISC",
@@ -17,10 +17,10 @@
17
17
  },
18
18
  "devDependencies": {
19
19
  "@rollup/plugin-commonjs": "^22.0.0",
20
- "@ikas/storefront-api": "^4.0.0-alpha.5",
21
- "@ikas/storefront-config": "^4.0.0-alpha.5",
22
- "@ikas/storefront-model-functions": "^4.0.0-alpha.5",
23
- "@ikas/storefront-models": "^4.0.0-alpha.5",
20
+ "@ikas/storefront-api": "^4.0.0-alpha.50",
21
+ "@ikas/storefront-config": "^4.0.0-alpha.50",
22
+ "@ikas/storefront-model-functions": "^4.0.0-alpha.50",
23
+ "@ikas/storefront-models": "^4.0.0-alpha.50",
24
24
  "@rollup/plugin-node-resolve": "^13.3.0",
25
25
  "@types/lodash": "^4.14.168",
26
26
  "@types/react": "^16.9.55",
@@ -37,10 +37,10 @@
37
37
  },
38
38
  "peerDependencies": {
39
39
  "mobx": "^6.1.3",
40
- "@ikas/storefront-api": "^4.0.0-alpha.5",
41
- "@ikas/storefront-config": "^4.0.0-alpha.5",
42
- "@ikas/storefront-model-functions": "^4.0.0-alpha.5",
43
- "@ikas/storefront-models": "^4.0.0-alpha.5",
40
+ "@ikas/storefront-api": "^4.0.0-alpha.50",
41
+ "@ikas/storefront-config": "^4.0.0-alpha.50",
42
+ "@ikas/storefront-model-functions": "^4.0.0-alpha.50",
43
+ "@ikas/storefront-models": "^4.0.0-alpha.50",
44
44
  "lodash": "^4.17.20"
45
45
  }
46
46
  }
@@ -1,4 +1,4 @@
1
- import { listRaffle } from "@ikas/storefront-api";
1
+ import { listStorefrontRaffle } from "@ikas/storefront-api";
2
2
  import { IkasRaffleList } from ".";
3
3
  import { populateRaffleProducts } from "../../../providers/helpers/raffle";
4
4
 
@@ -25,7 +25,7 @@ async function getRaffleList(
25
25
  page: number,
26
26
  limit: number
27
27
  ) {
28
- const response = await listRaffle({
28
+ const response = await listStorefrontRaffle({
29
29
  start: list.start ? { eq: list.start } : undefined,
30
30
  end: list.end ? { eq: list.end } : undefined,
31
31
  includeDeleted: list.includeDeleted || false,
@@ -62,7 +62,7 @@ import {
62
62
  listHTMLMetaData,
63
63
  listMerchantSettings,
64
64
  listProductOptionSet,
65
- listRaffle,
65
+ listStorefrontRaffle,
66
66
  listRaffleMetaData,
67
67
  searchProducts,
68
68
  } from "@ikas/storefront-api";
@@ -80,7 +80,7 @@ export class IkasPageDataProvider {
80
80
  theme: IkasThemeJson;
81
81
  pageType?: IkasThemeJsonPageType | null = null;
82
82
  pageParams: Record<string, any> = {};
83
- pageComponentPropValues: IkasPageComponentPropValue[] = [];
83
+ private pageComponentPropValues: IkasPageComponentPropValue[] = [];
84
84
  pageSpecificData?: any | null = null;
85
85
  merchantSettings?: IkasMerchantSettings | null = null;
86
86
  possiblePageTypes?: IkasThemeJsonPageType[] = []; // Used for distinguishing blog slug page from main slug page
@@ -154,6 +154,10 @@ export class IkasPageDataProvider {
154
154
  return this.page?.components || [];
155
155
  }
156
156
 
157
+ get $pageComponentPropValues() {
158
+ return this.pageComponentPropValues;
159
+ }
160
+
157
161
  async getMerchantSettings() {
158
162
  const merchantSettingsResponse = await listMerchantSettings({});
159
163
 
@@ -345,11 +349,12 @@ export class IkasPageDataProvider {
345
349
  };
346
350
 
347
351
  const handleBlogPage = async () => {
348
- const blog = await listBlog({
352
+ const blogsResponse = await listBlog({
349
353
  id: { eq: metaData.targetId },
350
354
  });
351
- if (!blog) return;
355
+ if (!blogsResponse.isSuccess || !blogsResponse.data?.data?.length) return;
352
356
 
357
+ const blog = blogsResponse.data.data[0];
353
358
  this.pageSpecificData = blog;
354
359
  this.pageType = IkasThemeJsonPageType.BLOG;
355
360
  this.setPageMetaData(metaData);
@@ -371,14 +376,13 @@ export class IkasPageDataProvider {
371
376
  return;
372
377
 
373
378
  const blogCategory = blogCategoriesResponse.data.data[0];
374
-
375
379
  this.pageSpecificData = blogCategory;
376
380
  this.pageType = IkasThemeJsonPageType.BLOG_CATEGORY;
377
381
  this.setPageMetaData(metaData);
378
382
  };
379
383
 
380
384
  const handleRafflePage = async () => {
381
- const response = await listRaffle({
385
+ const response = await listStorefrontRaffle({
382
386
  id: { eq: metaData.targetId },
383
387
  });
384
388
 
@@ -670,21 +674,21 @@ export class IkasPageDataProvider {
670
674
  switch (type) {
671
675
  case "DEFAULT":
672
676
  const htmlMetaDataResponse = await listHTMLMetaData({
673
- id: { in: idList },
677
+ targetId: { in: idList },
674
678
  });
675
679
  results = htmlMetaDataResponse.data || [];
676
680
  break;
677
681
 
678
682
  case "BLOG":
679
683
  const blogMetaDataResponse = await listBlogMetaData({
680
- id: { in: idList },
684
+ targetId: { in: idList },
681
685
  });
682
686
  results = blogMetaDataResponse.data?.data || [];
683
687
  break;
684
688
 
685
689
  case "RAFFLE":
686
690
  const raffleMetaDataResponse = await listRaffleMetaData({
687
- id: { in: idList },
691
+ targetId: { in: idList },
688
692
  });
689
693
  results = raffleMetaDataResponse.data || [];
690
694
  break;
@@ -25,6 +25,7 @@ export function getPlaceholderProduct() {
25
25
  attributes: [],
26
26
  variantTypes: [],
27
27
  productOptionSetId: null,
28
+ baseUnit: null,
28
29
  };
29
30
  return product;
30
31
  }
@@ -112,13 +113,11 @@ export function getPlaceholderRaffle(): IkasRaffle {
112
113
  dateRange: null,
113
114
  metadata: null,
114
115
  name: "",
115
- participantCount: null,
116
116
  requiredCustomerAccount: false,
117
117
  status: false,
118
118
  variants: [],
119
119
  products: [],
120
120
  verificationType: IkasRaffleVerificationType.EMAIL,
121
- isCustomerWinner: false,
122
121
  };
123
122
  }
124
123
 
@@ -7,11 +7,11 @@ export type IkasLinkMetaDataType = "DEFAULT" | "BLOG" | "RAFFLE";
7
7
  export type IkasLinkMetaDataTargetId = {
8
8
  type: IkasLinkMetaDataType;
9
9
  id: string;
10
- navigationLink: IkasNavigationLink;
10
+ navigationLink: NavigationLink;
11
11
  };
12
12
 
13
13
  export class IkasLinkPropValueProvider
14
- implements IkasPropValueProvider<IkasNavigationLink | IkasNavigationLink[]>
14
+ implements IkasPropValueProvider<NavigationLink | NavigationLink[]>
15
15
  {
16
16
  private linkPropValue: IkasLinkPropValue | IkasLinkPropValue[];
17
17
  private theme: IkasThemeJson;
@@ -29,89 +29,89 @@ export class IkasLinkPropValueProvider
29
29
 
30
30
  private async getNavigationLink(
31
31
  linkPropValue: IkasLinkPropValue
32
- ): Promise<IkasNavigationLink> {
33
- let navigationLink: IkasNavigationLink | undefined;
32
+ ): Promise<NavigationLink> {
33
+ let navigationLink: NavigationLink | undefined;
34
34
 
35
35
  if (linkPropValue.linkType === IkasLinkType.PAGE) {
36
36
  // INDEX PAGE
37
37
  if (linkPropValue.pageType === IkasThemeJsonPageType.INDEX) {
38
- navigationLink = {
38
+ navigationLink = new NavigationLink({
39
39
  href: "/",
40
40
  label: linkPropValue.label || "",
41
41
  subLinks: [],
42
- };
42
+ });
43
43
  } else if (linkPropValue.pageType === IkasThemeJsonPageType.ACCOUNT) {
44
- navigationLink = {
44
+ navigationLink = new NavigationLink({
45
45
  href: "/account",
46
46
  label: linkPropValue.label || "",
47
47
  subLinks: [],
48
- };
48
+ });
49
49
  } else if (linkPropValue.pageType === IkasThemeJsonPageType.ADDRESSES) {
50
- navigationLink = {
50
+ navigationLink = new NavigationLink({
51
51
  href: "/account/addresses",
52
52
  label: linkPropValue.label || "",
53
53
  subLinks: [],
54
- };
54
+ });
55
55
  } else if (linkPropValue.pageType === IkasThemeJsonPageType.ORDERS) {
56
- navigationLink = {
56
+ navigationLink = new NavigationLink({
57
57
  href: "/account/orders",
58
58
  label: linkPropValue.label || "",
59
59
  subLinks: [],
60
- };
60
+ });
61
61
  } else if (
62
62
  linkPropValue.pageType === IkasThemeJsonPageType.FAVORITE_PRODUCTS
63
63
  ) {
64
- navigationLink = {
64
+ navigationLink = new NavigationLink({
65
65
  href: "/account/favorite-products",
66
66
  label: linkPropValue.label || "",
67
67
  subLinks: [],
68
- };
68
+ });
69
69
  } else if (linkPropValue.pageType === IkasThemeJsonPageType.LOGIN) {
70
- navigationLink = {
70
+ navigationLink = new NavigationLink({
71
71
  href: "/account/login",
72
72
  label: linkPropValue.label || "",
73
73
  subLinks: [],
74
- };
74
+ });
75
75
  } else if (linkPropValue.pageType === IkasThemeJsonPageType.REGISTER) {
76
- navigationLink = {
76
+ navigationLink = new NavigationLink({
77
77
  href: "/account/register",
78
78
  label: linkPropValue.label || "",
79
79
  subLinks: [],
80
- };
80
+ });
81
81
  } else if (
82
82
  linkPropValue.pageType === IkasThemeJsonPageType.FORGOT_PASSWORD
83
83
  ) {
84
- navigationLink = {
84
+ navigationLink = new NavigationLink({
85
85
  href: "/account/forgot-password",
86
86
  label: linkPropValue.label || "",
87
87
  subLinks: [],
88
- };
88
+ });
89
89
  } else if (
90
90
  linkPropValue.pageType === IkasThemeJsonPageType.RECOVER_PASSWORD
91
91
  ) {
92
- navigationLink = {
92
+ navigationLink = new NavigationLink({
93
93
  href: "/account/recover-password",
94
94
  label: linkPropValue.label || "",
95
95
  subLinks: [],
96
- };
96
+ });
97
97
  } else if (linkPropValue.pageType === IkasThemeJsonPageType.BLOG_INDEX) {
98
- navigationLink = {
98
+ navigationLink = new NavigationLink({
99
99
  href: "/blog",
100
100
  label: linkPropValue.label || "",
101
101
  subLinks: [],
102
- };
102
+ });
103
103
  } else if (linkPropValue.pageType === IkasThemeJsonPageType.CART) {
104
- navigationLink = {
104
+ navigationLink = new NavigationLink({
105
105
  href: "/cart",
106
106
  label: linkPropValue.label || "",
107
107
  subLinks: [],
108
- };
108
+ });
109
109
  } else if (linkPropValue.pageType === IkasThemeJsonPageType.SEARCH) {
110
- navigationLink = {
110
+ navigationLink = new NavigationLink({
111
111
  href: "/search",
112
112
  label: linkPropValue.label || "",
113
113
  subLinks: [],
114
- };
114
+ });
115
115
  }
116
116
  // CUSTOM PAGE
117
117
  else if (linkPropValue.pageType === IkasThemeJsonPageType.CUSTOM) {
@@ -119,11 +119,11 @@ export class IkasLinkPropValueProvider
119
119
  (p) => p.id === linkPropValue.pageId
120
120
  );
121
121
  if (themePage) {
122
- navigationLink = {
122
+ navigationLink = new NavigationLink({
123
123
  href: "/pages/" + themePage.slug,
124
124
  label: linkPropValue.label || "",
125
125
  subLinks: [],
126
- };
126
+ });
127
127
  }
128
128
  }
129
129
  // ITEM PAGES
@@ -135,11 +135,11 @@ export class IkasLinkPropValueProvider
135
135
  ].includes(linkPropValue.pageType!)
136
136
  ) {
137
137
  if (linkPropValue.itemId) {
138
- navigationLink = {
138
+ navigationLink = new NavigationLink({
139
139
  href: "/",
140
140
  label: linkPropValue.label || "",
141
141
  subLinks: [],
142
- };
142
+ });
143
143
  this.linkMetaDataTargetIds.push({
144
144
  type: "DEFAULT",
145
145
  id: linkPropValue.itemId,
@@ -155,11 +155,11 @@ export class IkasLinkPropValueProvider
155
155
  ].includes(linkPropValue.pageType!)
156
156
  ) {
157
157
  if (linkPropValue.itemId) {
158
- navigationLink = {
158
+ navigationLink = new NavigationLink({
159
159
  href: "/blog/",
160
160
  label: linkPropValue.label || "",
161
161
  subLinks: [],
162
- };
162
+ });
163
163
  this.linkMetaDataTargetIds.push({
164
164
  type: "BLOG",
165
165
  id: linkPropValue.itemId,
@@ -170,11 +170,11 @@ export class IkasLinkPropValueProvider
170
170
  // RAFFLE ITEM PAGE
171
171
  else if (linkPropValue.pageType === IkasThemeJsonPageType.RAFFLE_DETAIL) {
172
172
  if (linkPropValue.itemId) {
173
- navigationLink = {
173
+ navigationLink = new NavigationLink({
174
174
  href: "/raffle/",
175
175
  label: linkPropValue.label || "",
176
176
  subLinks: [],
177
- };
177
+ });
178
178
  this.linkMetaDataTargetIds.push({
179
179
  type: "RAFFLE",
180
180
  id: linkPropValue.itemId,
@@ -200,12 +200,12 @@ export class IkasLinkPropValueProvider
200
200
  }
201
201
  // EXTERNAL LINK
202
202
  else if (linkPropValue.linkType === IkasLinkType.EXTERNAL) {
203
- navigationLink = {
203
+ navigationLink = new NavigationLink({
204
204
  href: linkPropValue.externalLink || "",
205
205
  label: linkPropValue.label || "",
206
206
  subLinks: [],
207
207
  isExternal: true,
208
- };
208
+ });
209
209
  }
210
210
 
211
211
  if (navigationLink) {
@@ -244,7 +244,7 @@ export class IkasLinkPropValueProvider
244
244
  return navigationLink;
245
245
  }
246
246
 
247
- return { href: "", label: "", subLinks: [] } as IkasNavigationLink;
247
+ return new NavigationLink({ href: "", label: "", subLinks: [] });
248
248
  }
249
249
 
250
250
  async getValue(): Promise<IkasNavigationLink | IkasNavigationLink[]> {
@@ -257,3 +257,20 @@ export class IkasLinkPropValueProvider
257
257
  }
258
258
  }
259
259
  }
260
+
261
+ // This is a class by choice, mobx creates clones of plain JSON objects, but not class instances
262
+ export class NavigationLink implements IkasNavigationLink {
263
+ href: string;
264
+ label: string;
265
+ subLinks: IkasNavigationLink[];
266
+ isExternal?: boolean | null;
267
+ itemId?: string;
268
+
269
+ constructor(data: IkasNavigationLink) {
270
+ this.href = data.href;
271
+ this.label = data.label;
272
+ this.subLinks = data.subLinks;
273
+ this.isExternal = data.isExternal;
274
+ this.itemId = data.itemId;
275
+ }
276
+ }
@@ -81,15 +81,13 @@ export class IkasProductListPropValueProvider
81
81
  IkasRelatedProductsType.CATEGORY
82
82
  ) {
83
83
  this.relatedProductData.categoryIds =
84
- this.pageSpecificData.product.categories.map(
84
+ this.pageSpecificData.categories.map(
85
85
  (category: IkasCategory) => category.id
86
86
  );
87
87
  } else {
88
- this.relatedProductData.brandIds = [
89
- this.pageSpecificData.product?.brand?.id,
90
- ];
88
+ this.relatedProductData.brandIds = [this.pageSpecificData?.brand?.id];
91
89
  }
92
- this.relatedProductData.productId = this.pageSpecificData.product.id;
90
+ this.relatedProductData.productId = this.pageSpecificData.id;
93
91
  }
94
92
 
95
93
  const productList: IkasProductList = {
@@ -1,4 +1,4 @@
1
- import { listRaffle } from "@ikas/storefront-api";
1
+ import { listStorefrontRaffle } from "@ikas/storefront-api";
2
2
  import IkasPropValueProvider from ".";
3
3
  import { IkasRafflePropValue } from "../../models/prop-value/raffle";
4
4
  import { populateRaffleProducts } from "../helpers/raffle";
@@ -23,7 +23,7 @@ export class IkasRafflePropValueProvider
23
23
  }
24
24
  if (!this.rafflePropValue.raffleId) return null;
25
25
 
26
- const rafflesResponse = await listRaffle({
26
+ const rafflesResponse = await listStorefrontRaffle({
27
27
  id: { eq: this.rafflePropValue.raffleId },
28
28
  });
29
29
 
@@ -19,6 +19,7 @@ import { IkasBrandPropValue } from "../models/prop-value/brand";
19
19
  import { IkasCategoryPropValue } from "../models/prop-value/category";
20
20
  import { IkasProductPropValue } from "../models/prop-value/product";
21
21
  import { IkasRafflePropValue } from "../models/prop-value/raffle";
22
+ import { makeAutoObservable } from "mobx";
22
23
 
23
24
  export class IkasPageComponentPropValue {
24
25
  pageComponent: IkasThemeJsonPageComponent;
@@ -29,6 +30,8 @@ export class IkasPageComponentPropValue {
29
30
  this.pageComponent = data.pageComponent;
30
31
  this.component = data.component;
31
32
  this.propValues = data.propValues || {};
33
+
34
+ makeAutoObservable(this);
32
35
  }
33
36
  }
34
37