@ikas/storefront-next 4.0.0-alpha.55 → 4.0.0-alpha.57

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.
Files changed (187) hide show
  1. package/build/api/getComponentDirs.d.ts +3 -0
  2. package/build/api/getComponentDirs.js +1 -0
  3. package/build/api/getTheme.d.ts +3 -0
  4. package/build/api/getTheme.js +1 -0
  5. package/{src/api/index.ts → build/api/index.d.ts} +11 -14
  6. package/build/api/index.js +1 -0
  7. package/build/api/middleware.d.ts +3 -0
  8. package/build/api/middleware.js +1 -0
  9. package/build/api/updateTheme.d.ts +9 -0
  10. package/build/api/updateTheme.js +1 -0
  11. package/build/api/uploadTheme.d.ts +3 -0
  12. package/build/api/uploadTheme.js +1 -0
  13. package/build/ext/tslib/tslib.es6.js +1 -0
  14. package/{src/index.ts → build/index.d.ts} +4 -4
  15. package/build/index.js +1 -0
  16. package/build/packages/cmd/build/_virtual/_cloneBuffer.js +1 -0
  17. package/build/packages/cmd/build/_virtual/_commonjsHelpers.js +1 -0
  18. package/build/packages/cmd/build/_virtual/_nodeUtil.js +1 -0
  19. package/build/packages/cmd/build/_virtual/isBuffer.js +1 -0
  20. package/build/packages/cmd/build/ext/lodash/_DataView.js +1 -0
  21. package/build/packages/cmd/build/ext/lodash/_Hash.js +1 -0
  22. package/build/packages/cmd/build/ext/lodash/_ListCache.js +1 -0
  23. package/build/packages/cmd/build/ext/lodash/_Map.js +1 -0
  24. package/build/packages/cmd/build/ext/lodash/_MapCache.js +1 -0
  25. package/build/packages/cmd/build/ext/lodash/_Promise.js +1 -0
  26. package/build/packages/cmd/build/ext/lodash/_Set.js +1 -0
  27. package/build/packages/cmd/build/ext/lodash/_SetCache.js +1 -0
  28. package/build/packages/cmd/build/ext/lodash/_Symbol.js +1 -0
  29. package/build/packages/cmd/build/ext/lodash/_Uint8Array.js +1 -0
  30. package/build/packages/cmd/build/ext/lodash/_WeakMap.js +1 -0
  31. package/build/packages/cmd/build/ext/lodash/_arrayIncludes.js +1 -0
  32. package/build/packages/cmd/build/ext/lodash/_arrayIncludesWith.js +1 -0
  33. package/build/packages/cmd/build/ext/lodash/_arrayLikeKeys.js +1 -0
  34. package/build/packages/cmd/build/ext/lodash/_assocIndexOf.js +1 -0
  35. package/build/packages/cmd/build/ext/lodash/_baseClone.js +1 -0
  36. package/build/packages/cmd/build/ext/lodash/_baseFindIndex.js +1 -0
  37. package/build/packages/cmd/build/ext/lodash/_baseGetTag.js +1 -0
  38. package/build/packages/cmd/build/ext/lodash/_baseIndexOf.js +1 -0
  39. package/build/packages/cmd/build/ext/lodash/_baseIsArguments.js +1 -0
  40. package/build/packages/cmd/build/ext/lodash/_baseIsNaN.js +1 -0
  41. package/build/packages/cmd/build/ext/lodash/_baseIsNative.js +1 -0
  42. package/build/packages/cmd/build/ext/lodash/_baseUniq.js +1 -0
  43. package/build/packages/cmd/build/ext/lodash/_cacheHas.js +1 -0
  44. package/build/packages/cmd/build/ext/lodash/_cloneBuffer.js +1 -0
  45. package/build/packages/cmd/build/ext/lodash/_cloneSymbol.js +1 -0
  46. package/build/packages/cmd/build/ext/lodash/_coreJsData.js +1 -0
  47. package/build/packages/cmd/build/ext/lodash/_createSet.js +1 -0
  48. package/build/packages/cmd/build/ext/lodash/_defineProperty.js +1 -0
  49. package/build/packages/cmd/build/ext/lodash/_freeGlobal.js +1 -0
  50. package/build/packages/cmd/build/ext/lodash/_getMapData.js +1 -0
  51. package/build/packages/cmd/build/ext/lodash/_getNative.js +1 -0
  52. package/build/packages/cmd/build/ext/lodash/_getRawTag.js +1 -0
  53. package/build/packages/cmd/build/ext/lodash/_getTag.js +1 -0
  54. package/build/packages/cmd/build/ext/lodash/_getValue.js +1 -0
  55. package/build/packages/cmd/build/ext/lodash/_hashClear.js +1 -0
  56. package/build/packages/cmd/build/ext/lodash/_hashDelete.js +1 -0
  57. package/build/packages/cmd/build/ext/lodash/_hashGet.js +1 -0
  58. package/build/packages/cmd/build/ext/lodash/_hashHas.js +1 -0
  59. package/build/packages/cmd/build/ext/lodash/_hashSet.js +1 -0
  60. package/build/packages/cmd/build/ext/lodash/_isKeyable.js +1 -0
  61. package/build/packages/cmd/build/ext/lodash/_isMasked.js +1 -0
  62. package/build/packages/cmd/build/ext/lodash/_listCacheClear.js +1 -0
  63. package/build/packages/cmd/build/ext/lodash/_listCacheDelete.js +1 -0
  64. package/build/packages/cmd/build/ext/lodash/_listCacheGet.js +1 -0
  65. package/build/packages/cmd/build/ext/lodash/_listCacheHas.js +1 -0
  66. package/build/packages/cmd/build/ext/lodash/_listCacheSet.js +1 -0
  67. package/build/packages/cmd/build/ext/lodash/_mapCacheClear.js +1 -0
  68. package/build/packages/cmd/build/ext/lodash/_mapCacheDelete.js +1 -0
  69. package/build/packages/cmd/build/ext/lodash/_mapCacheGet.js +1 -0
  70. package/build/packages/cmd/build/ext/lodash/_mapCacheHas.js +1 -0
  71. package/build/packages/cmd/build/ext/lodash/_mapCacheSet.js +1 -0
  72. package/build/packages/cmd/build/ext/lodash/_nativeCreate.js +1 -0
  73. package/build/packages/cmd/build/ext/lodash/_nodeUtil.js +1 -0
  74. package/build/packages/cmd/build/ext/lodash/_objectToString.js +1 -0
  75. package/build/packages/cmd/build/ext/lodash/_root.js +1 -0
  76. package/build/packages/cmd/build/ext/lodash/_setCacheAdd.js +1 -0
  77. package/build/packages/cmd/build/ext/lodash/_setCacheHas.js +1 -0
  78. package/build/packages/cmd/build/ext/lodash/_setToArray.js +1 -0
  79. package/build/packages/cmd/build/ext/lodash/_strictIndexOf.js +1 -0
  80. package/build/packages/cmd/build/ext/lodash/_toSource.js +1 -0
  81. package/build/packages/cmd/build/ext/lodash/eq.js +1 -0
  82. package/build/packages/cmd/build/ext/lodash/isArguments.js +1 -0
  83. package/build/packages/cmd/build/ext/lodash/isBuffer.js +1 -0
  84. package/build/packages/cmd/build/ext/lodash/isFunction.js +1 -0
  85. package/build/packages/cmd/build/ext/lodash/isMap.js +1 -0
  86. package/build/packages/cmd/build/ext/lodash/isObject.js +1 -0
  87. package/build/packages/cmd/build/ext/lodash/isObjectLike.js +1 -0
  88. package/build/packages/cmd/build/ext/lodash/isSet.js +1 -0
  89. package/build/packages/cmd/build/ext/lodash/isTypedArray.js +1 -0
  90. package/build/packages/cmd/build/ext/lodash/noop.js +1 -0
  91. package/build/packages/cmd/build/ext/lodash/stubFalse.js +1 -0
  92. package/build/packages/cmd/build/ext/lodash/uniq.js +1 -0
  93. package/build/packages/cmd/build/ext/tslib/tslib.es6.js +1 -0
  94. package/build/packages/cmd/build/scripts/generators/api/index.js +1 -0
  95. package/build/packages/cmd/build/scripts/generators/api/info.js +1 -0
  96. package/build/packages/cmd/build/scripts/generators/components/index.js +1 -0
  97. package/build/packages/cmd/build/scripts/generators/pages/index.js +1 -0
  98. package/build/packages/cmd/build/scripts/generators/pages/info.js +1 -0
  99. package/build/packages/cmd/build/scripts/generators/theme/index.js +1 -0
  100. package/build/packages/cmd/build/scripts/generators/types/index.js +1 -0
  101. package/build/packages/cmd/build/utils/fs.js +1 -0
  102. package/build/packages/cmd/build/utils/helper.js +1 -0
  103. package/build/pages/404.d.ts +2 -0
  104. package/build/pages/404.js +1 -0
  105. package/build/pages/[slug]/index.d.ts +3 -0
  106. package/build/pages/_slug_/index.js +1 -0
  107. package/build/pages/account/addresses.d.ts +2 -0
  108. package/build/pages/account/addresses.js +1 -0
  109. package/build/pages/account/favorite-products.d.ts +2 -0
  110. package/build/pages/account/favorite-products.js +1 -0
  111. package/build/pages/account/forgot-password.d.ts +2 -0
  112. package/build/pages/account/forgot-password.js +1 -0
  113. package/build/pages/account/index.d.ts +2 -0
  114. package/build/pages/account/index.js +1 -0
  115. package/build/pages/account/login.d.ts +2 -0
  116. package/build/pages/account/login.js +1 -0
  117. package/build/pages/account/orders/[id].d.ts +2 -0
  118. package/build/pages/account/orders/_id_.js +1 -0
  119. package/build/pages/account/orders/index.d.ts +2 -0
  120. package/build/pages/account/orders/index.js +1 -0
  121. package/build/pages/account/raffles.d.ts +2 -0
  122. package/build/pages/account/raffles.js +1 -0
  123. package/build/pages/account/recover-password.d.ts +2 -0
  124. package/build/pages/account/recover-password.js +1 -0
  125. package/build/pages/account/register.d.ts +2 -0
  126. package/build/pages/account/register.js +1 -0
  127. package/build/pages/blog/[slug].d.ts +3 -0
  128. package/build/pages/blog/_slug_.js +1 -0
  129. package/build/pages/blog/index.d.ts +2 -0
  130. package/build/pages/blog/index.js +1 -0
  131. package/build/pages/cart.d.ts +2 -0
  132. package/build/pages/cart.js +1 -0
  133. package/build/pages/checkout.d.ts +2 -0
  134. package/build/pages/checkout.js +1 -0
  135. package/build/pages/editor.d.ts +2 -0
  136. package/build/pages/editor.js +1 -0
  137. package/build/pages/home.d.ts +2 -0
  138. package/build/pages/home.js +1 -0
  139. package/{src/pages/index.ts → build/pages/index.d.ts} +22 -22
  140. package/build/pages/pages/[slug].d.ts +3 -0
  141. package/build/pages/pages/_slug_.js +1 -0
  142. package/build/pages/raffle/[slug].d.ts +3 -0
  143. package/build/pages/raffle/_slug_.js +1 -0
  144. package/build/pages/raffle/index.d.ts +2 -0
  145. package/build/pages/raffle/index.js +1 -0
  146. package/build/pages/search.d.ts +2 -0
  147. package/build/pages/search.js +1 -0
  148. package/build/provider/page-data-next.d.ts +93 -0
  149. package/build/provider/page-data-next.js +1 -0
  150. package/build/utils/fs.d.ts +28 -0
  151. package/build/utils/fs.js +1 -0
  152. package/build/utils/google-fonts.d.ts +2 -0
  153. package/build/utils/google-fonts.js +1 -0
  154. package/build/utils/i18n.d.ts +9 -0
  155. package/build/utils/i18n.js +1 -0
  156. package/package.json +15 -15
  157. package/src/api/getComponentDirs.ts +0 -39
  158. package/src/api/getTheme.ts +0 -22
  159. package/src/api/middleware.ts +0 -24
  160. package/src/api/updateTheme.ts +0 -33
  161. package/src/api/uploadTheme.ts +0 -311
  162. package/src/pages/404.tsx +0 -18
  163. package/src/pages/[slug]/index.tsx +0 -18
  164. package/src/pages/account/addresses.tsx +0 -10
  165. package/src/pages/account/favorite-products.tsx +0 -10
  166. package/src/pages/account/forgot-password.tsx +0 -10
  167. package/src/pages/account/index.tsx +0 -10
  168. package/src/pages/account/login.tsx +0 -10
  169. package/src/pages/account/orders/[id].tsx +0 -10
  170. package/src/pages/account/orders/index.tsx +0 -10
  171. package/src/pages/account/raffles.tsx +0 -10
  172. package/src/pages/account/recover-password.tsx +0 -10
  173. package/src/pages/account/register.tsx +0 -10
  174. package/src/pages/blog/[slug].tsx +0 -17
  175. package/src/pages/blog/index.tsx +0 -10
  176. package/src/pages/cart.tsx +0 -10
  177. package/src/pages/checkout.tsx +0 -10
  178. package/src/pages/editor.tsx +0 -11
  179. package/src/pages/home.tsx +0 -10
  180. package/src/pages/pages/[slug].tsx +0 -72
  181. package/src/pages/raffle/[slug].tsx +0 -17
  182. package/src/pages/raffle/index.tsx +0 -10
  183. package/src/pages/search.tsx +0 -10
  184. package/src/provider/page-data-next.ts +0 -608
  185. package/src/utils/fs.ts +0 -93
  186. package/src/utils/google-fonts.ts +0 -52
  187. package/src/utils/i18n.ts +0 -86
@@ -1,608 +0,0 @@
1
- import fs from "fs";
2
- import getConfig from "next/config.js";
3
- import { GetServerSidePropsContext, GetStaticPropsContext } from "next";
4
- import { ParsedUrlQuery } from "querystring";
5
- import {
6
- IkasCustomerReviewSettings,
7
- IkasMerchantSettings,
8
- IkasProductBackInStockSettings,
9
- IkasSalesChannel,
10
- IkasStorefront,
11
- IkasStorefrontRouting,
12
- IkasStorefrontThemeLocalization,
13
- IkasThemeJson,
14
- IkasThemeJsonFavicon,
15
- IkasThemeJsonPageType,
16
- IkasThemeJsonSettings,
17
- IkasThemeJsonStockPreference,
18
- } from "@ikas/storefront-models";
19
- import { IkasPageDataProvider } from "@ikas/storefront-providers";
20
- import { IkasStorefrontConfig } from "@ikas/storefront-config";
21
- import {
22
- listCheckoutSettings,
23
- listMerchantSettings,
24
- setAPIClientConfig,
25
- getStorefrontSettings,
26
- IkasStorefrontSettings,
27
- } from "@ikas/storefront-api";
28
- import { getGoogleFontHref } from "../utils/google-fonts";
29
- import { I18NFileReader } from "../utils/i18n";
30
- import { createFile, deleteDirContent } from "../utils/fs";
31
-
32
- export class IkasNextPageDataProvider {
33
- static startTime = Date.now();
34
-
35
- static readLocalTheme(): Promise<IkasThemeJson> {
36
- return new Promise((resolve, reject) => {
37
- const themeJSONPath = "./src/theme.json";
38
-
39
- fs.readFile(
40
- themeJSONPath,
41
- {
42
- flag: "a+",
43
- },
44
- function (err, file) {
45
- if (err) {
46
- return reject(err);
47
- }
48
- const result = file.length ? JSON.parse(file.toString()) : {};
49
- resolve(result);
50
- }
51
- );
52
- });
53
- }
54
-
55
- static readSettingsFile(): Promise<SettingsData | null> {
56
- return new Promise((resolve) => {
57
- const { serverRuntimeConfig } = getConfig();
58
- const settingsPath = serverRuntimeConfig.SETTINGS;
59
-
60
- fs.readFile(
61
- settingsPath,
62
- {
63
- flag: "a+",
64
- },
65
- function (err, file) {
66
- if (err) {
67
- console.error("SETTINGS FILE READ ERROR!!!");
68
- console.error(err);
69
- return resolve(null);
70
- }
71
- const result = file.length ? JSON.parse(file.toString()) : {};
72
- resolve(result);
73
- }
74
- );
75
- });
76
- }
77
-
78
- static async cacheLocalSettingsFile(settings: IkasStorefrontSettings) {
79
- const cacheFileFolderPath = ".ikas";
80
- await deleteDirContent(cacheFileFolderPath);
81
-
82
- const cacheFileName = `settings-${this.startTime}.json`;
83
- await createFile(
84
- cacheFileFolderPath,
85
- cacheFileName,
86
- JSON.stringify(settings, null, 2)
87
- );
88
- }
89
-
90
- static readLocalSettingsFile() {
91
- try {
92
- const fileContent = fs.readFileSync(
93
- `.ikas/settings-${this.startTime}.json`
94
- );
95
-
96
- if (fileContent && fileContent.length)
97
- return JSON.parse(fileContent.toString());
98
- } catch {}
99
- }
100
-
101
- static async getLocalSettings(locale: string): Promise<SettingsData | null> {
102
- let settings: IkasStorefrontSettings =
103
- await IkasNextPageDataProvider.readLocalSettingsFile();
104
-
105
- if (!settings) {
106
- const settingsResponse = await getStorefrontSettings();
107
-
108
- if (!settingsResponse.isSuccess || !settingsResponse.data) {
109
- console.error("Storefront settings fetch failed!");
110
- console.error(settingsResponse);
111
- return null;
112
- }
113
-
114
- settings = settingsResponse.data;
115
- await this.cacheLocalSettingsFile(settings);
116
- }
117
-
118
- const storefront = settings.storefront;
119
- const salesChannel = settings.salesChannel;
120
- const storefrontJSScripts = []; // Not using the settings one on purpose, no need to run scripts on localhost
121
- const productBackInStockSettings: IkasProductBackInStockSettings | null =
122
- settings.productBackInStockSettings
123
- ? {
124
- customerLoginRequired:
125
- settings.productBackInStockSettings.customerLoginRequired,
126
- }
127
- : null;
128
- const customerReviewSettings: IkasCustomerReviewSettings | null =
129
- settings.customerReviewSettings
130
- ? {
131
- customerLoginRequired:
132
- settings.customerReviewSettings.customerLoginRequired || false,
133
- customerPurchaseRequired:
134
- settings.customerReviewSettings.customerPurchaseRequired || false,
135
- }
136
- : null;
137
-
138
- const localTheme = await IkasNextPageDataProvider.readLocalTheme();
139
- const colorScript = IkasNextPageDataProvider.createColorScript(
140
- localTheme.settings
141
- );
142
- const fontScript = IkasNextPageDataProvider.createFontScript(
143
- localTheme.settings
144
- );
145
-
146
- if (colorScript) storefrontJSScripts.push(colorScript);
147
- if (fontScript) storefrontJSScripts.push(fontScript);
148
-
149
- return {
150
- storefront: storefront,
151
- themeLocalization: {
152
- id: "",
153
- locale: "en",
154
- privacyPolicy: null,
155
- returnPolicy: null,
156
- storefrontId: storefront.id,
157
- storefrontThemeId: "",
158
- termsOfService: null,
159
- themeJson: localTheme,
160
- },
161
- salesChannel,
162
- routing: storefront.routings.length
163
- ? storefront.routings.find(
164
- (r) => r.locale === locale || r.id === locale
165
- ) || storefront.routings[0]
166
- : {
167
- countryCodes: [],
168
- domain: "",
169
- dynamicCurrencySettings: {
170
- roundingFormat: null,
171
- targetCurrencyCode: "",
172
- },
173
- id: "",
174
- locale: "en",
175
- path: null,
176
- priceListId: null,
177
- currencyCode: "USD",
178
- currencySymbol: "$",
179
- },
180
- favicon: localTheme.settings.favicon,
181
- stockPreference: localTheme.settings.stockPreference,
182
- storefrontJSScripts,
183
- domain: "localhost:3333",
184
- productBackInStockSettings,
185
- customerReviewSettings,
186
- merchantSettings: settings.merchantSettings,
187
- };
188
- }
189
-
190
- static async getProdSettings(locale: string): Promise<SettingsData | null> {
191
- return new Promise(async (resolve) => {
192
- const settings = await IkasNextPageDataProvider.readSettingsFile();
193
- if (!settings || !settings.localizationMap) return resolve(null);
194
-
195
- const storefront = settings.storefront;
196
- const salesChannel = settings.salesChannel;
197
- const localizationMap = settings.localizationMap;
198
- const storefrontJSScripts = settings.storefrontJSScripts || [];
199
- const domain = settings.domain;
200
- const productBackInStockSettings: IkasProductBackInStockSettings | null =
201
- settings.productBackInStockSettings
202
- ? {
203
- customerLoginRequired:
204
- settings.productBackInStockSettings.customerLoginRequired,
205
- }
206
- : null;
207
- const customerReviewSettings: IkasCustomerReviewSettings | null =
208
- settings.customerReviewSettings
209
- ? {
210
- customerLoginRequired:
211
- settings.customerReviewSettings.customerLoginRequired || false,
212
- customerPurchaseRequired:
213
- settings.customerReviewSettings.customerPurchaseRequired ||
214
- false,
215
- }
216
- : null;
217
-
218
- let merchantSettings = settings.merchantSettings;
219
- if (!merchantSettings) {
220
- const response = await listMerchantSettings({});
221
- if (response.isSuccess && response.data) {
222
- merchantSettings = response.data;
223
- } else {
224
- console.error("MERCHANT SETTINGS FETCH FAILED!");
225
- return resolve(null);
226
- }
227
- }
228
-
229
- const themeLocalizationPath = localizationMap[locale];
230
- const routing = storefront.routings.find(
231
- (r) => r.id === locale || r.path === locale
232
- );
233
-
234
- if (!themeLocalizationPath || !routing) {
235
- console.error("THEME LOCALIZATION PATH OR ROUTING MISSING!!!");
236
- return resolve(null);
237
- }
238
-
239
- fs.readFile(
240
- themeLocalizationPath,
241
- {
242
- flag: "a+",
243
- },
244
- function (err, file) {
245
- if (err) {
246
- console.error("THEME LOCALIZATION FILE READ ERROR!!!");
247
- console.error(err);
248
- return resolve(null);
249
- }
250
- const result = file.length ? JSON.parse(file.toString()) : {};
251
- const themeLocalization = result as IkasStorefrontThemeLocalization;
252
- const favicon = themeLocalization.themeJson.settings.favicon;
253
- const stockPreference =
254
- themeLocalization.themeJson.settings.stockPreference;
255
-
256
- if (themeLocalization.themeJson.settings) {
257
- const colorScript = IkasNextPageDataProvider.createColorScript(
258
- themeLocalization.themeJson.settings
259
- );
260
- const fontScript = IkasNextPageDataProvider.createFontScript(
261
- themeLocalization.themeJson.settings
262
- );
263
-
264
- if (colorScript) storefrontJSScripts.push(colorScript);
265
- if (fontScript) storefrontJSScripts.push(fontScript);
266
- }
267
-
268
- resolve({
269
- storefront,
270
- themeLocalization,
271
- salesChannel,
272
- routing,
273
- favicon,
274
- stockPreference,
275
- storefrontJSScripts,
276
- domain,
277
- productBackInStockSettings,
278
- customerReviewSettings,
279
- merchantSettings,
280
- });
281
- }
282
- );
283
- });
284
- }
285
-
286
- static async getSettings(locale: string): Promise<SettingsData | null> {
287
- const isLocal = process.env.NEXT_PUBLIC_ENV === "local";
288
-
289
- if (isLocal) {
290
- return await this.getLocalSettings(locale);
291
- } else {
292
- return await this.getProdSettings(locale);
293
- }
294
- }
295
-
296
- static async setStorefrontConfig(settings: SettingsData) {
297
- const {
298
- storefront,
299
- salesChannel,
300
- routing,
301
- favicon,
302
- stockPreference,
303
- storefrontJSScripts,
304
- domain,
305
- productBackInStockSettings,
306
- customerReviewSettings,
307
- merchantSettings,
308
- } = settings;
309
-
310
- IkasStorefrontConfig.init({
311
- apiUrl: process.env.NEXT_PUBLIC_GQL_URL,
312
- adminApiUrl: process.env.NEXT_PUBLIC_UPLOAD_GQL_URL,
313
- cdnUrl: process.env.NEXT_PUBLIC_IMG_BASE_URL,
314
- storefrontId: storefront.id,
315
- storefrontRoutingId: routing.id,
316
- storefrontThemeId: storefront.mainStorefrontThemeId!,
317
- salesChannelId: storefront.salesChannelId!,
318
- priceListId: routing.priceListId || undefined,
319
- stockLocationIds: salesChannel.stockLocations?.map((sl) => sl.id),
320
- routings: storefront.routings,
321
- paymentGateways: salesChannel.paymentGateways || [],
322
- gtmId: storefront.gtmId || undefined,
323
- fbpId: storefront.fbpId || undefined,
324
- analytics4Id: storefront.analytics4Id || undefined,
325
- universalAnalyticsId: storefront.universalAnalyticsId || undefined,
326
- tiktokPixelId: storefront.tiktokPixelId || undefined,
327
- favicon: favicon || null,
328
- pickUpStockLocationIds: storefront.pickUpStockLocationIds
329
- ? storefront.pickUpStockLocationIds.length
330
- ? storefront.pickUpStockLocationIds
331
- : null
332
- : null,
333
- stockPreference: stockPreference || null,
334
- storefrontJSScripts: storefrontJSScripts || [],
335
- domain: domain,
336
- productBackInStockSettings: productBackInStockSettings,
337
- customerReviewSettings: customerReviewSettings,
338
- merchantSettings,
339
- });
340
-
341
- setAPIClientConfig();
342
- }
343
-
344
- static async setTranslations(
345
- settings: SettingsData,
346
- componentIds: string[],
347
- pageType?: IkasThemeJsonPageType,
348
- isEditor?: boolean
349
- ) {
350
- const { serverRuntimeConfig } = getConfig();
351
- const routing = settings.routing;
352
- const isLocal = process.env.NEXT_PUBLIC_ENV === "local";
353
-
354
- const components = settings.themeLocalization.themeJson.components.filter(
355
- (c) => isEditor || componentIds.includes(c.id)
356
- );
357
- const namespaces = ["common", ...components.map((c) => c.dir)];
358
-
359
- if (pageType === IkasThemeJsonPageType.CHECKOUT || isEditor) {
360
- namespaces.push("checkout-page");
361
- }
362
-
363
- const nextI18nConf = serverRuntimeConfig.nextI18nConf;
364
- const currentLocale = routing.locale;
365
-
366
- const i18nReader = new I18NFileReader(
367
- currentLocale,
368
- namespaces,
369
- isLocal ? undefined : nextI18nConf.localePath
370
- );
371
-
372
- const translations = await i18nReader.read();
373
- IkasStorefrontConfig.init({
374
- translations,
375
- });
376
- }
377
-
378
- static async getExtraProps(
379
- settings: SettingsData,
380
- provider: IkasPageDataProvider,
381
- pageType?: IkasThemeJsonPageType
382
- ) {
383
- const extraProps: Record<string, any> = {};
384
- const themeLocalization = settings.themeLocalization;
385
-
386
- if (pageType === IkasThemeJsonPageType.CHECKOUT) {
387
- const checkoutComponent = provider.page?.components[0];
388
-
389
- if (checkoutComponent) {
390
- const checkoutSettings = await listCheckoutSettings({});
391
- const customizationProps: IkasCheckoutCustomizationProps = {
392
- showTax: checkoutComponent.propValues["showTax"] ?? true,
393
- buttonBgColor: checkoutComponent.propValues["buttonBgColor"],
394
- buttonTextColor: checkoutComponent.propValues["buttonTextColor"],
395
- buttonDisabledBgColor:
396
- checkoutComponent.propValues["buttonDisabledBgColor"],
397
- buttonDisabledTextColor:
398
- checkoutComponent.propValues["buttonDisabledTextColor"],
399
-
400
- primaryTextColor: checkoutComponent.propValues["primaryTextColor"],
401
- secondaryTextColor:
402
- checkoutComponent.propValues["secondaryTextColor"],
403
-
404
- primaryBgColor: checkoutComponent.propValues["primaryBgColor"],
405
- secondaryBgColor: checkoutComponent.propValues["secondaryBgColor"],
406
- borderColor: checkoutComponent.propValues["borderColor"],
407
- cardBgColor: checkoutComponent.propValues["cardBgColor"],
408
-
409
- errorColor: checkoutComponent.propValues["errorColor"],
410
- errorLightColor: checkoutComponent.propValues["errorLightColor"],
411
- warningColor: checkoutComponent.propValues["warningColor"],
412
- warningLightColor: checkoutComponent.propValues["warningLightColor"],
413
- successColor: checkoutComponent.propValues["successColor"],
414
- successLightColor: checkoutComponent.propValues["successLightColor"],
415
- };
416
-
417
- extraProps.customizationProps = customizationProps;
418
- extraProps.returnPolicy = themeLocalization.returnPolicy;
419
- extraProps.privacyPolicy = themeLocalization.privacyPolicy;
420
- extraProps.termsOfService = themeLocalization.termsOfService;
421
- extraProps.checkoutSettings = checkoutSettings?.data?.length
422
- ? checkoutSettings.data[0]
423
- : null;
424
- }
425
- }
426
-
427
- return extraProps;
428
- }
429
-
430
- static async getPageData(
431
- context:
432
- | GetStaticPropsContext<ParsedUrlQuery>
433
- | GetServerSidePropsContext<ParsedUrlQuery>,
434
- isServer: boolean,
435
- pageType?: IkasThemeJsonPageType,
436
- possiblePageTypes?: IkasThemeJsonPageType[],
437
- isEditor?: boolean
438
- ) {
439
- const isLocal = process.env.NEXT_PUBLIC_ENV === "local";
440
- const isProdEditor = !isLocal && isEditor;
441
-
442
- IkasStorefrontConfig.init({
443
- apiUrl: process.env.NEXT_PUBLIC_GQL_URL,
444
- adminApiUrl: process.env.NEXT_PUBLIC_UPLOAD_GQL_URL,
445
- cdnUrl: process.env.NEXT_PUBLIC_IMG_BASE_URL,
446
- });
447
- setAPIClientConfig();
448
-
449
- // Local editor - prod deploy - local build
450
- if (!isProdEditor) {
451
- const locale = context.locale;
452
-
453
- if (!locale) {
454
- return {
455
- props: {},
456
- notFound: true,
457
- };
458
- }
459
-
460
- const settings = await IkasNextPageDataProvider.getSettings(locale);
461
-
462
- if (
463
- !settings ||
464
- !settings.storefront.mainStorefrontThemeId ||
465
- !settings.storefront.salesChannelId
466
- ) {
467
- return {
468
- props: {},
469
- notFound: true,
470
- };
471
- }
472
-
473
- await this.setStorefrontConfig(settings);
474
-
475
- const themeLocalization = settings.themeLocalization;
476
- const provider = new IkasPageDataProvider(
477
- themeLocalization.themeJson,
478
- context.params,
479
- pageType
480
- );
481
- provider.possiblePageTypes =
482
- possiblePageTypes || (pageType ? [pageType] : []);
483
-
484
- if (!isEditor) {
485
- await provider.getPageData();
486
- if (!provider.page) {
487
- return {
488
- props: {},
489
- notFound: true,
490
- };
491
- }
492
- }
493
-
494
- const componentIds = isEditor
495
- ? provider.theme.components.map((c) => c.id)
496
- : provider.page?.components.map((pc) => pc.componentId) || [];
497
- await this.setTranslations(settings, componentIds, pageType, isEditor);
498
-
499
- const extraProps = await this.getExtraProps(settings, provider, pageType);
500
-
501
- if (isServer)
502
- return {
503
- props: {
504
- ...provider.nextPageData.props,
505
- ...extraProps,
506
- },
507
- };
508
- else {
509
- return {
510
- props: {
511
- ...provider.nextPageData.props,
512
- ...extraProps,
513
- },
514
- revalidate: 60,
515
- };
516
- }
517
- } else {
518
- return {
519
- props: {},
520
- };
521
- }
522
- }
523
-
524
- static async getStaticProps(
525
- context: GetStaticPropsContext<ParsedUrlQuery>,
526
- pageType?: IkasThemeJsonPageType,
527
- possiblePageTypes?: IkasThemeJsonPageType[],
528
- isEditor?: boolean
529
- ) {
530
- return await IkasNextPageDataProvider.getPageData(
531
- context,
532
- false,
533
- pageType,
534
- possiblePageTypes,
535
- isEditor
536
- );
537
- }
538
-
539
- static async getServerSideProps(
540
- context: GetServerSidePropsContext<ParsedUrlQuery>,
541
- pageType?: IkasThemeJsonPageType
542
- ) {
543
- return await IkasNextPageDataProvider.getPageData(context, true, pageType);
544
- }
545
-
546
- static createColorScript(settings: IkasThemeJsonSettings) {
547
- if (!settings.colors) return;
548
-
549
- return `<script>${settings.colors
550
- .map(
551
- (sc) =>
552
- `document.documentElement.style.setProperty("${sc.key}","${sc.color}");`
553
- )
554
- .join("\r\n")}</script>
555
- `;
556
- }
557
-
558
- static createFontScript(settings: IkasThemeJsonSettings) {
559
- const fontHref = getGoogleFontHref(settings.fontFamily);
560
-
561
- if (fontHref) {
562
- return `<link id="ikas-font" rel="stylesheet" href="${fontHref}">
563
- <style>
564
- body {
565
- font-family: '${settings.fontFamily.name}', -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
566
- }
567
- </style>`;
568
- }
569
- }
570
- }
571
-
572
- export type SettingsData = {
573
- storefront: IkasStorefront;
574
- themeLocalization: IkasStorefrontThemeLocalization;
575
- salesChannel: IkasSalesChannel;
576
- routing: IkasStorefrontRouting;
577
- localizationMap?: Record<string, any>;
578
- favicon: IkasThemeJsonFavicon;
579
- stockPreference: IkasThemeJsonStockPreference;
580
- storefrontJSScripts: string[];
581
- domain: string;
582
- productBackInStockSettings: IkasProductBackInStockSettings | null;
583
- customerReviewSettings: IkasCustomerReviewSettings | null;
584
- merchantSettings: IkasMerchantSettings;
585
- };
586
-
587
- export type IkasCheckoutCustomizationProps = {
588
- showTax?: boolean;
589
- buttonBgColor?: string;
590
- buttonTextColor?: string;
591
- buttonDisabledBgColor?: string;
592
- buttonDisabledTextColor?: string;
593
-
594
- primaryTextColor?: string;
595
- secondaryTextColor?: string;
596
-
597
- primaryBgColor?: string;
598
- secondaryBgColor?: string;
599
- borderColor?: string;
600
- cardBgColor?: string;
601
-
602
- errorColor?: string;
603
- errorLightColor?: string;
604
- warningColor?: string;
605
- warningLightColor?: string;
606
- successColor?: string;
607
- successLightColor?: string;
608
- };
package/src/utils/fs.ts DELETED
@@ -1,93 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
-
4
- /**
5
- * Divides the given filePath string into directory part and fileName part
6
- * @param path Path for the file
7
- */
8
- export function getFilePathParts(path: string) {
9
- const componentFilePathParts = path.split("/");
10
-
11
- if (componentFilePathParts.length > 1) {
12
- const dirParts = componentFilePathParts.slice(
13
- 0,
14
- componentFilePathParts.length - 1
15
- );
16
- const filePart = componentFilePathParts[componentFilePathParts.length - 1];
17
-
18
- return {
19
- dirParts,
20
- filePart,
21
- };
22
- }
23
-
24
- return {
25
- filePart: path,
26
- };
27
- }
28
-
29
- /**
30
- * Deletes the contents of the given directory, exluding the ignoreFiles
31
- * @param dirPath Path for the directory
32
- * @param ignoreFiles List of files to keep in directory. Does not accept recursive paths, only first level files
33
- *
34
- * @returns true for successfull operation, false otherwise
35
- */
36
- export async function deleteDirContent(
37
- dirPath: string,
38
- ignoreFiles?: string[]
39
- ) {
40
- try {
41
- // const fs = await import("fs-extra");
42
- const files = fs.readdirSync(dirPath);
43
-
44
- files.forEach((file) => {
45
- if (!ignoreFiles?.includes(file)) {
46
- fs.unlinkSync(path.join(dirPath, file));
47
- }
48
- });
49
-
50
- return true;
51
- } catch (err) {
52
- return false;
53
- }
54
- }
55
-
56
- /**
57
- * Creates the given file and directories for the filePath
58
- * @param basePath Base directory path for the file
59
- * @param fileSubPath Filename or the sub directory path for the file to write
60
- * @param fileStr File contents
61
- *
62
- * @returns true for successfull operation, false otherwise
63
- */
64
- export async function createFile(
65
- basePath: string,
66
- fileSubPath: string,
67
- fileStr: string
68
- ) {
69
- try {
70
- // const fs = await import("fs-extra");
71
- let generatedFolderPath = basePath;
72
-
73
- const pageFilePathParts = getFilePathParts(fileSubPath);
74
- if (pageFilePathParts.dirParts?.length) {
75
- generatedFolderPath = path.join(
76
- generatedFolderPath,
77
- ...pageFilePathParts.dirParts
78
- );
79
- }
80
-
81
- if (!fs.existsSync(generatedFolderPath)) {
82
- fs.mkdirSync(generatedFolderPath, { recursive: true });
83
- }
84
-
85
- const filePath = path.join(generatedFolderPath, pageFilePathParts.filePart);
86
- fs.writeFileSync(filePath, fileStr);
87
-
88
- return true;
89
- } catch (err) {
90
- console.error(err);
91
- return false;
92
- }
93
- }