@ikas/storefront-config 4.0.0-alpha.79 → 4.0.0-alpha.8

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,11 +1,11 @@
1
1
  {
2
2
  "name": "@ikas/storefront-config",
3
- "version": "4.0.0-alpha.79",
3
+ "version": "4.0.0-alpha.8",
4
4
  "description": "Common configuration for ikas storefront packages.",
5
- "main": "./build/index.js",
6
- "module": "./build/index.js",
5
+ "main": "./src/index.ts",
6
+ "module": "./src/index.ts",
7
7
  "files": [
8
- "./build"
8
+ "./src"
9
9
  ],
10
10
  "type": "module",
11
11
  "scripts": {
@@ -17,7 +17,7 @@
17
17
  "license": "ISC",
18
18
  "dependencies": {},
19
19
  "devDependencies": {
20
- "@ikas/storefront-models": "^4.0.0-alpha.79",
20
+ "@ikas/storefront-models": "^4.0.0-alpha.8",
21
21
  "prettier": "^2.2.1",
22
22
  "rollup": "^2.75.6",
23
23
  "rollup-plugin-terser": "^7.0.2",
@@ -27,6 +27,6 @@
27
27
  "typescript-transform-paths": "^2.2.2"
28
28
  },
29
29
  "peerDependencies": {
30
- "@ikas/storefront-models": "^4.0.0-alpha.79"
30
+ "@ikas/storefront-models": "^4.0.0-alpha.8"
31
31
  }
32
32
  }
package/src/index.ts ADDED
@@ -0,0 +1,317 @@
1
+ import {
2
+ IkasCustomerReviewSettings,
3
+ IkasMerchantSettings,
4
+ IkasProductBackInStockSettings,
5
+ IkasSalesChannelPaymentGateway,
6
+ IkasStorefrontRouting,
7
+ IkasThemeJsonFavicon,
8
+ IkasThemeJsonStockPreference,
9
+ } from "@ikas/storefront-models";
10
+
11
+ export class IkasStorefrontConfig {
12
+ private static themeId?: string;
13
+ private static apiUrl?: string;
14
+ private static adminApiUrl?: string;
15
+ private static cdnUrl?: string;
16
+ private static apiKey?: string;
17
+ private static customerToken?: string;
18
+ private static storefrontId?: string;
19
+ private static storefrontRoutingId?: string;
20
+ private static priceListId?: string;
21
+ private static stockLocationIds?: string[];
22
+ private static loginRequiredCallback?: LoginRequiredCallbackType;
23
+ private static domain?: string;
24
+ private static storefrontThemeId?: string;
25
+ private static salesChannelId?: string;
26
+ private static routings: IkasStorefrontRouting[] = [];
27
+ private static paymentGateways: IkasSalesChannelPaymentGateway[] = [];
28
+ private static gtmId?: string;
29
+ private static fbpId?: string;
30
+ private static analytics4Id?: string;
31
+ private static universalAnalyticsId?: string;
32
+ private static pickUpStockLocationIds?: string[] | null;
33
+ private static tiktokPixelId?: string;
34
+ private static favicon?: IkasThemeJsonFavicon;
35
+ private static stockPreference?: IkasThemeJsonStockPreference;
36
+ private static translations: Record<string, any> = {};
37
+ private static storefrontJSScripts: string[] = [];
38
+ private static customerReviewSettings?: IkasCustomerReviewSettings | null;
39
+ private static productBackInStockSettings?: IkasProductBackInStockSettings | null;
40
+ private static merchantSettings?: IkasMerchantSettings | null;
41
+ private static currentPageComponents?: Record<string, any>;
42
+ private static isEditor = false;
43
+
44
+ private static sessionId?: string;
45
+ private static visitorId?: string;
46
+ private static observers: IkasStorefrontConfigObserver[] = [];
47
+
48
+ static addObserver(observer: IkasStorefrontConfigObserver) {
49
+ const existingObserver = IkasStorefrontConfig.observers.find(
50
+ (o) => o.id === observer.id
51
+ );
52
+
53
+ if (existingObserver) {
54
+ existingObserver.callback = observer.callback;
55
+ } else {
56
+ IkasStorefrontConfig.observers.push(observer);
57
+ }
58
+
59
+ observer.callback(IkasStorefrontConfig);
60
+ }
61
+
62
+ static init(config: Partial<IkasStorefrontConfigParams>) {
63
+ try {
64
+ Object.entries(config).forEach(([key, value]) => {
65
+ //@ts-ignore
66
+ IkasStorefrontConfig[key] = value;
67
+ });
68
+ if (config.token) {
69
+ IkasStorefrontConfig.apiKey = config.token;
70
+ }
71
+ this.notify();
72
+ } catch (err) {
73
+ console.error(err);
74
+ }
75
+ }
76
+
77
+ static async initFromAPI(apiKey: string) {
78
+ // TODO
79
+ }
80
+
81
+ static getCurrentRouting() {
82
+ return IkasStorefrontConfig.routings.find(
83
+ (r) => r.id === IkasStorefrontConfig.storefrontRoutingId
84
+ );
85
+ }
86
+
87
+ static getCurrentLocale() {
88
+ const routing = IkasStorefrontConfig.getCurrentRouting();
89
+ return routing?.locale || "en";
90
+ }
91
+
92
+ private static notify() {
93
+ this.observers.forEach((o) => o.callback(this));
94
+ }
95
+
96
+ // HELPERS
97
+
98
+ static isCustomerReviewEnabled() {
99
+ const customerReviewSettings =
100
+ IkasStorefrontConfig.getCustomerReviewSettings();
101
+
102
+ return (
103
+ !!customerReviewSettings &&
104
+ !customerReviewSettings.customerPurchaseRequired
105
+ );
106
+ }
107
+
108
+ static isCustomerReviewLoginRequired() {
109
+ const customerReviewSettings =
110
+ IkasStorefrontConfig.getCustomerReviewSettings();
111
+
112
+ if (!customerReviewSettings) return true;
113
+
114
+ return customerReviewSettings.customerLoginRequired;
115
+ }
116
+
117
+ static isBackInStockEnabled() {
118
+ return !!IkasStorefrontConfig.getProductBackInStockSettings();
119
+ }
120
+
121
+ static isCustomerLoginRequiredForBackInStock() {
122
+ const productBackInStockSettings =
123
+ IkasStorefrontConfig.getProductBackInStockSettings();
124
+ return (
125
+ productBackInStockSettings &&
126
+ productBackInStockSettings.customerLoginRequired
127
+ );
128
+ }
129
+
130
+ static toJSON() {
131
+ const json = {
132
+ ...this,
133
+ };
134
+
135
+ //@ts-ignore
136
+ delete json.observers;
137
+
138
+ return json;
139
+ }
140
+
141
+ // GETTERS
142
+
143
+ static getThemeId() {
144
+ return IkasStorefrontConfig.themeId;
145
+ }
146
+
147
+ static getApiUrl() {
148
+ return IkasStorefrontConfig.apiUrl;
149
+ }
150
+
151
+ static getAdminApiUrl() {
152
+ return IkasStorefrontConfig.adminApiUrl;
153
+ }
154
+
155
+ static getCdnUrl() {
156
+ return IkasStorefrontConfig.cdnUrl;
157
+ }
158
+
159
+ static getApiKey() {
160
+ return IkasStorefrontConfig.apiKey;
161
+ }
162
+
163
+ static getCustomerToken() {
164
+ return IkasStorefrontConfig.customerToken;
165
+ }
166
+
167
+ static getStorefrontId() {
168
+ return IkasStorefrontConfig.storefrontId;
169
+ }
170
+
171
+ static getStorefrontRoutingId() {
172
+ return IkasStorefrontConfig.storefrontRoutingId;
173
+ }
174
+
175
+ static getPriceListId() {
176
+ return IkasStorefrontConfig.priceListId;
177
+ }
178
+
179
+ static getStockLocationIds() {
180
+ return IkasStorefrontConfig.stockLocationIds;
181
+ }
182
+
183
+ static getLoginRequiredCallback() {
184
+ return IkasStorefrontConfig.loginRequiredCallback;
185
+ }
186
+
187
+ static getDomain() {
188
+ return IkasStorefrontConfig.domain;
189
+ }
190
+
191
+ static getStorefrontThemeId() {
192
+ return IkasStorefrontConfig.storefrontThemeId;
193
+ }
194
+
195
+ static getSalesChannelId() {
196
+ return IkasStorefrontConfig.salesChannelId;
197
+ }
198
+
199
+ static getRoutings() {
200
+ return IkasStorefrontConfig.routings;
201
+ }
202
+
203
+ static getPaymentGateways() {
204
+ return IkasStorefrontConfig.paymentGateways;
205
+ }
206
+
207
+ static getGtmId() {
208
+ return IkasStorefrontConfig.gtmId;
209
+ }
210
+
211
+ static getFbpId() {
212
+ return IkasStorefrontConfig.fbpId;
213
+ }
214
+
215
+ static getAnalytics4Id() {
216
+ return IkasStorefrontConfig.analytics4Id;
217
+ }
218
+
219
+ static getUniversalAnalyticsId() {
220
+ return IkasStorefrontConfig.universalAnalyticsId;
221
+ }
222
+
223
+ static getPickupStockLocationIds() {
224
+ return IkasStorefrontConfig.pickUpStockLocationIds;
225
+ }
226
+
227
+ static getTiktokPixelId() {
228
+ return IkasStorefrontConfig.tiktokPixelId;
229
+ }
230
+
231
+ static getFavicon() {
232
+ return IkasStorefrontConfig.favicon;
233
+ }
234
+
235
+ static getStockPreference() {
236
+ return IkasStorefrontConfig.stockPreference;
237
+ }
238
+
239
+ static getTranslations() {
240
+ return IkasStorefrontConfig.translations;
241
+ }
242
+
243
+ static getStorefrontJSScripts() {
244
+ return IkasStorefrontConfig.storefrontJSScripts;
245
+ }
246
+
247
+ static getCustomerReviewSettings() {
248
+ return IkasStorefrontConfig.customerReviewSettings;
249
+ }
250
+
251
+ static getProductBackInStockSettings() {
252
+ return IkasStorefrontConfig.productBackInStockSettings;
253
+ }
254
+
255
+ static getMerchantSettings() {
256
+ return IkasStorefrontConfig.merchantSettings;
257
+ }
258
+
259
+ static getCurrentPageComponents() {
260
+ return IkasStorefrontConfig.currentPageComponents;
261
+ }
262
+
263
+ static getIsEditor() {
264
+ return IkasStorefrontConfig.isEditor;
265
+ }
266
+
267
+ static getSessionId() {
268
+ return IkasStorefrontConfig.sessionId;
269
+ }
270
+
271
+ static getVisitorId() {
272
+ return IkasStorefrontConfig.visitorId;
273
+ }
274
+ }
275
+
276
+ export type IkasStorefrontConfigObserver = {
277
+ id: string;
278
+ callback: (config: IkasStorefrontConfig) => void;
279
+ };
280
+ export type LoginRequiredCallbackType = () => Promise<void> | void;
281
+
282
+ export type IkasStorefrontConfigParams = {
283
+ themeId?: string;
284
+ apiUrl?: string;
285
+ adminApiUrl?: string;
286
+ cdnUrl?: string;
287
+ apiKey?: string;
288
+ token?: string;
289
+ customerToken?: string;
290
+ storefrontId?: string;
291
+ storefrontRoutingId?: string;
292
+ priceListId?: string;
293
+ stockLocationIds?: string[];
294
+ loginRequiredCallback?: LoginRequiredCallbackType;
295
+ domain?: string;
296
+ storefrontThemeId?: string;
297
+ salesChannelId?: string;
298
+ routings: IkasStorefrontRouting[];
299
+ paymentGateways: IkasSalesChannelPaymentGateway[];
300
+ gtmId?: string;
301
+ fbpId?: string;
302
+ analytics4Id?: string;
303
+ universalAnalyticsId?: string;
304
+ pickUpStockLocationIds?: string[] | null;
305
+ tiktokPixelId?: string;
306
+ favicon?: IkasThemeJsonFavicon;
307
+ stockPreference?: IkasThemeJsonStockPreference;
308
+ translations: Record<string, any>;
309
+ storefrontJSScripts: string[];
310
+ customerReviewSettings?: IkasCustomerReviewSettings | null;
311
+ productBackInStockSettings?: IkasProductBackInStockSettings | null;
312
+ merchantSettings?: IkasMerchantSettings | null;
313
+ currentPageComponents?: Record<string, any>;
314
+ isEditor: boolean;
315
+ sessionId?: string;
316
+ visitorId?: string;
317
+ };
@@ -1 +0,0 @@
1
- var n=function(){return n=Object.assign||function(n){for(var t,e=1,r=arguments.length;e<r;e++)for(var o in t=arguments[e])Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=t[o]);return n},n.apply(this,arguments)};function t(n,t,e,r){return new(e||(e=Promise))((function(o,a){function u(n){try{c(r.next(n))}catch(n){a(n)}}function l(n){try{c(r.throw(n))}catch(n){a(n)}}function c(n){var t;n.done?o(n.value):(t=n.value,t instanceof e?t:new e((function(n){n(t)}))).then(u,l)}c((r=r.apply(n,t||[])).next())}))}function e(n,t){var e,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function l(a){return function(l){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=t.call(n,u)}catch(n){a=[6,n],r=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,l])}}}export{n as __assign,t as __awaiter,e as __generator};
package/build/index.d.ts DELETED
@@ -1,128 +0,0 @@
1
- import { IkasCustomerReviewSettings, IkasCustomerSettings, IkasMerchantSettings, IkasProductBackInStockSettings, IkasSalesChannelPaymentGateway, IkasStorefontMetaTemplates, IkasStorefrontRouting, IkasThemeJsonFavicon, IkasThemeJsonStockPreference } from "@ikas/storefront-models";
2
- export declare class IkasStorefrontConfig {
3
- private static themeId?;
4
- private static apiUrl?;
5
- private static adminApiUrl?;
6
- private static cdnUrl?;
7
- private static apiKey?;
8
- private static customerToken?;
9
- private static storefrontId?;
10
- private static storefrontRoutingId?;
11
- private static priceListId?;
12
- private static stockLocationIds?;
13
- private static loginRequiredCallback?;
14
- private static domain?;
15
- private static storefrontThemeId?;
16
- private static salesChannelId?;
17
- private static routings;
18
- private static paymentGateways;
19
- private static gtmId?;
20
- private static fbpId?;
21
- private static analytics4Id?;
22
- private static universalAnalyticsId?;
23
- private static pickUpStockLocationIds?;
24
- private static tiktokPixelId?;
25
- private static favicon?;
26
- private static stockPreference?;
27
- private static translations;
28
- private static storefrontJSScripts;
29
- private static customerReviewSettings?;
30
- private static productBackInStockSettings?;
31
- private static merchantSettings?;
32
- private static currentPageComponents?;
33
- private static isEditor;
34
- private static customerSettings?;
35
- private static metaTemplates;
36
- private static sessionId?;
37
- private static visitorId?;
38
- private static observers;
39
- static addObserver(observer: IkasStorefrontConfigObserver): void;
40
- static init(config: Partial<IkasStorefrontConfigParams>): void;
41
- static initFromAPI(apiKey: string): Promise<void>;
42
- static getCurrentRouting(): IkasStorefrontRouting | undefined;
43
- static getCurrentLocale(): string;
44
- private static notify;
45
- static isCustomerReviewEnabled(): boolean;
46
- static isCustomerReviewLoginRequired(): boolean;
47
- static isBackInStockEnabled(): boolean;
48
- static isCustomerLoginRequiredForBackInStock(): boolean | null | undefined;
49
- static toJSON(): {};
50
- static getThemeId(): string | undefined;
51
- static getApiUrl(): string | undefined;
52
- static getAdminApiUrl(): string | undefined;
53
- static getCdnUrl(): string | undefined;
54
- static getApiKey(): string | undefined;
55
- static getCustomerToken(): string | undefined;
56
- static getStorefrontId(): string | undefined;
57
- static getStorefrontRoutingId(): string | undefined;
58
- static getPriceListId(): string | undefined;
59
- static getStockLocationIds(): string[] | undefined;
60
- static getLoginRequiredCallback(): LoginRequiredCallbackType | undefined;
61
- static getDomain(): string | undefined;
62
- static getStorefrontThemeId(): string | undefined;
63
- static getSalesChannelId(): string | undefined;
64
- static getRoutings(): IkasStorefrontRouting[];
65
- static getPaymentGateways(): IkasSalesChannelPaymentGateway[];
66
- static getGtmId(): string | undefined;
67
- static getFbpId(): string | undefined;
68
- static getAnalytics4Id(): string | undefined;
69
- static getUniversalAnalyticsId(): string | undefined;
70
- static getPickupStockLocationIds(): string[] | null | undefined;
71
- static getTiktokPixelId(): string | undefined;
72
- static getFavicon(): IkasThemeJsonFavicon | undefined;
73
- static getStockPreference(): IkasThemeJsonStockPreference | undefined;
74
- static getTranslations(): Record<string, any>;
75
- static getStorefrontJSScripts(): string[];
76
- static getCustomerReviewSettings(): IkasCustomerReviewSettings | null | undefined;
77
- static getProductBackInStockSettings(): IkasProductBackInStockSettings | null | undefined;
78
- static getMerchantSettings(): IkasMerchantSettings | null | undefined;
79
- static getCurrentPageComponents(): Record<string, any> | undefined;
80
- static getIsEditor(): boolean;
81
- static getSessionId(): string | undefined;
82
- static getVisitorId(): string | undefined;
83
- static getCustomerSettings(): IkasCustomerSettings | undefined;
84
- static getMetaTemplates(): IkasStorefontMetaTemplates[] | null;
85
- }
86
- export declare type IkasStorefrontConfigObserver = {
87
- id: string;
88
- callback: (config: IkasStorefrontConfig) => void;
89
- };
90
- export declare type LoginRequiredCallbackType = () => Promise<void> | void;
91
- export declare type IkasStorefrontConfigParams = {
92
- themeId?: string;
93
- apiUrl?: string;
94
- adminApiUrl?: string;
95
- cdnUrl?: string;
96
- apiKey?: string;
97
- token?: string;
98
- customerToken?: string;
99
- storefrontId?: string;
100
- storefrontRoutingId?: string;
101
- priceListId?: string;
102
- stockLocationIds?: string[];
103
- loginRequiredCallback?: LoginRequiredCallbackType;
104
- domain?: string;
105
- storefrontThemeId?: string;
106
- salesChannelId?: string;
107
- routings: IkasStorefrontRouting[];
108
- paymentGateways: IkasSalesChannelPaymentGateway[];
109
- gtmId?: string;
110
- fbpId?: string;
111
- analytics4Id?: string;
112
- universalAnalyticsId?: string;
113
- pickUpStockLocationIds?: string[] | null;
114
- tiktokPixelId?: string;
115
- favicon?: IkasThemeJsonFavicon;
116
- stockPreference?: IkasThemeJsonStockPreference;
117
- translations: Record<string, any>;
118
- storefrontJSScripts: string[];
119
- customerReviewSettings?: IkasCustomerReviewSettings | null;
120
- productBackInStockSettings?: IkasProductBackInStockSettings | null;
121
- merchantSettings?: IkasMerchantSettings | null;
122
- currentPageComponents?: Record<string, any>;
123
- isEditor: boolean;
124
- customerSettings?: IkasCustomerSettings;
125
- sessionId?: string;
126
- visitorId?: string;
127
- metaTemplates: IkasStorefontMetaTemplates[] | null;
128
- };
package/build/index.js DELETED
@@ -1 +0,0 @@
1
- import{__awaiter as t,__assign as n,__generator as e}from"./_virtual/_tslib.js";var r=function(){function r(){}return r.addObserver=function(t){var n=r.observers.find((function(n){return n.id===t.id}));n?n.callback=t.callback:r.observers.push(t),t.callback(r)},r.init=function(t){try{Object.entries(t).forEach((function(t){var n=t[0],e=t[1];r[n]=e})),t.token&&(r.apiKey=t.token),this.notify()}catch(t){console.error(t)}},r.initFromAPI=function(n){return t(this,void 0,void 0,(function(){return e(this,(function(t){return[2]}))}))},r.getCurrentRouting=function(){return r.routings.find((function(t){return t.id===r.storefrontRoutingId}))},r.getCurrentLocale=function(){var t=r.getCurrentRouting();return(null==t?void 0:t.locale)||"en"},r.notify=function(){var t=this;this.observers.forEach((function(n){return n.callback(t)}))},r.isCustomerReviewEnabled=function(){var t=r.getCustomerReviewSettings();return!!t&&!t.customerPurchaseRequired},r.isCustomerReviewLoginRequired=function(){var t=r.getCustomerReviewSettings();return!t||t.customerLoginRequired},r.isBackInStockEnabled=function(){return!!r.getProductBackInStockSettings()},r.isCustomerLoginRequiredForBackInStock=function(){var t=r.getProductBackInStockSettings();return t&&t.customerLoginRequired},r.toJSON=function(){var t=n({},this);return delete t.observers,t},r.getThemeId=function(){return r.themeId},r.getApiUrl=function(){return r.apiUrl},r.getAdminApiUrl=function(){return r.adminApiUrl},r.getCdnUrl=function(){return r.cdnUrl},r.getApiKey=function(){return r.apiKey},r.getCustomerToken=function(){return r.customerToken},r.getStorefrontId=function(){return r.storefrontId},r.getStorefrontRoutingId=function(){return r.storefrontRoutingId},r.getPriceListId=function(){return r.priceListId},r.getStockLocationIds=function(){return r.stockLocationIds},r.getLoginRequiredCallback=function(){return r.loginRequiredCallback},r.getDomain=function(){return r.domain},r.getStorefrontThemeId=function(){return r.storefrontThemeId},r.getSalesChannelId=function(){return r.salesChannelId},r.getRoutings=function(){return r.routings},r.getPaymentGateways=function(){return r.paymentGateways},r.getGtmId=function(){return r.gtmId},r.getFbpId=function(){return r.fbpId},r.getAnalytics4Id=function(){return r.analytics4Id},r.getUniversalAnalyticsId=function(){return r.universalAnalyticsId},r.getPickupStockLocationIds=function(){return r.pickUpStockLocationIds},r.getTiktokPixelId=function(){return r.tiktokPixelId},r.getFavicon=function(){return r.favicon},r.getStockPreference=function(){return r.stockPreference},r.getTranslations=function(){return r.translations},r.getStorefrontJSScripts=function(){return r.storefrontJSScripts},r.getCustomerReviewSettings=function(){return r.customerReviewSettings},r.getProductBackInStockSettings=function(){return r.productBackInStockSettings},r.getMerchantSettings=function(){return r.merchantSettings},r.getCurrentPageComponents=function(){return r.currentPageComponents},r.getIsEditor=function(){return r.isEditor},r.getSessionId=function(){return r.sessionId},r.getVisitorId=function(){return r.visitorId},r.getCustomerSettings=function(){return r.customerSettings},r.getMetaTemplates=function(){return r.metaTemplates},r.routings=[],r.paymentGateways=[],r.translations={},r.storefrontJSScripts=[],r.isEditor=!1,r.observers=[],r}();export{r as IkasStorefrontConfig};