@ikas/storefront 0.1.22-alpha.1 → 0.1.22-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.es.js +63 -24
- package/build/index.js +62 -23
- package/build/store/cart.d.ts +1 -0
- package/build/store/customer.d.ts +1 -0
- package/package.json +1 -1
package/build/index.es.js
CHANGED
|
@@ -2,9 +2,9 @@ import { makeAutoObservable, configure, makeObservable, observable, runInAction,
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path$1 from 'path';
|
|
4
4
|
import getConfig from 'next/config';
|
|
5
|
-
import React, { createElement, Fragment as Fragment$1, useEffect, useMemo,
|
|
6
|
-
import { observer } from 'mobx-react-lite';
|
|
5
|
+
import React, { createElement, Fragment as Fragment$1, useState, useEffect, useMemo, useRef, useCallback } from 'react';
|
|
7
6
|
import { useRouter } from 'next/router';
|
|
7
|
+
import { observer } from 'mobx-react-lite';
|
|
8
8
|
import Head from 'next/head';
|
|
9
9
|
import crypto$1 from 'crypto';
|
|
10
10
|
import NextImage from 'next/image';
|
|
@@ -23142,23 +23142,46 @@ var IkasCartStore = /** @class */ (function () {
|
|
|
23142
23142
|
}
|
|
23143
23143
|
});
|
|
23144
23144
|
}); };
|
|
23145
|
+
this.beforeCartOperationCheck = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
23146
|
+
var cartId;
|
|
23147
|
+
return __generator(this, function (_a) {
|
|
23148
|
+
switch (_a.label) {
|
|
23149
|
+
case 0:
|
|
23150
|
+
cartId = localStorage.getItem(CART_LS_KEY);
|
|
23151
|
+
if (!(this.cart && !cartId)) return [3 /*break*/, 1];
|
|
23152
|
+
this.removeCart();
|
|
23153
|
+
return [3 /*break*/, 3];
|
|
23154
|
+
case 1:
|
|
23155
|
+
if (!(!this.cart && !!cartId)) return [3 /*break*/, 3];
|
|
23156
|
+
return [4 /*yield*/, this.getCart()];
|
|
23157
|
+
case 2:
|
|
23158
|
+
_a.sent();
|
|
23159
|
+
_a.label = 3;
|
|
23160
|
+
case 3: return [2 /*return*/];
|
|
23161
|
+
}
|
|
23162
|
+
});
|
|
23163
|
+
}); };
|
|
23145
23164
|
this.addItem = function (variant, product, initialQuantity) {
|
|
23146
23165
|
if (initialQuantity === void 0) { initialQuantity = 1; }
|
|
23147
23166
|
return __awaiter(_this, void 0, void 0, function () {
|
|
23148
|
-
var existingItem, input, cart, eventId, item, err_2;
|
|
23167
|
+
var existingItem, cartId, input, cart, eventId, item, err_2;
|
|
23149
23168
|
var _a, _b, _c;
|
|
23150
23169
|
return __generator(this, function (_d) {
|
|
23151
23170
|
switch (_d.label) {
|
|
23152
23171
|
case 0:
|
|
23153
|
-
_d.trys.push([0,
|
|
23172
|
+
_d.trys.push([0, 5, , 6]);
|
|
23173
|
+
return [4 /*yield*/, this.beforeCartOperationCheck()];
|
|
23174
|
+
case 1:
|
|
23175
|
+
_d.sent();
|
|
23154
23176
|
if (this.cart) {
|
|
23155
23177
|
existingItem = this.cart.items.find(function (item) { return item.variant.id === variant.id; });
|
|
23156
23178
|
if (existingItem) {
|
|
23157
23179
|
return [2 /*return*/, this.changeItemQuantity(existingItem, existingItem.quantity + 1)];
|
|
23158
23180
|
}
|
|
23159
23181
|
}
|
|
23182
|
+
cartId = ((_a = this.cart) === null || _a === void 0 ? void 0 : _a.id) || localStorage.getItem(CART_LS_KEY);
|
|
23160
23183
|
input = {
|
|
23161
|
-
cartId:
|
|
23184
|
+
cartId: cartId,
|
|
23162
23185
|
customerId: ((_b = this.cart) === null || _b === void 0 ? void 0 : _b.customerId) || ((_c = this.baseStore.customerStore.customer) === null || _c === void 0 ? void 0 : _c.id) ||
|
|
23163
23186
|
null,
|
|
23164
23187
|
item: {
|
|
@@ -23176,14 +23199,14 @@ var IkasCartStore = /** @class */ (function () {
|
|
|
23176
23199
|
storefrontThemeId: IkasStorefrontConfig.storefrontThemeId,
|
|
23177
23200
|
};
|
|
23178
23201
|
return [4 /*yield*/, IkasCartAPI.saveItemToCart(input)];
|
|
23179
|
-
case
|
|
23202
|
+
case 2:
|
|
23180
23203
|
cart = _d.sent();
|
|
23181
|
-
if (!cart) return [3 /*break*/,
|
|
23204
|
+
if (!cart) return [3 /*break*/, 4];
|
|
23182
23205
|
return [4 /*yield*/, this.setCart(cart)];
|
|
23183
|
-
case 2:
|
|
23184
|
-
_d.sent();
|
|
23185
|
-
_d.label = 3;
|
|
23186
23206
|
case 3:
|
|
23207
|
+
_d.sent();
|
|
23208
|
+
_d.label = 4;
|
|
23209
|
+
case 4:
|
|
23187
23210
|
if (this.cart) {
|
|
23188
23211
|
eventId = this.cart.id + "-" + this.cart.updatedAt;
|
|
23189
23212
|
item = this.cart.items.find(function (i) { return i.variant.id; });
|
|
@@ -23191,12 +23214,12 @@ var IkasCartStore = /** @class */ (function () {
|
|
|
23191
23214
|
Analytics.addToCart(item, initialQuantity, eventId, this.cart);
|
|
23192
23215
|
}
|
|
23193
23216
|
}
|
|
23194
|
-
return [3 /*break*/,
|
|
23195
|
-
case
|
|
23217
|
+
return [3 /*break*/, 6];
|
|
23218
|
+
case 5:
|
|
23196
23219
|
err_2 = _d.sent();
|
|
23197
23220
|
console.log(err_2);
|
|
23198
|
-
return [3 /*break*/,
|
|
23199
|
-
case
|
|
23221
|
+
return [3 /*break*/, 6];
|
|
23222
|
+
case 6: return [2 /*return*/];
|
|
23200
23223
|
}
|
|
23201
23224
|
});
|
|
23202
23225
|
});
|
|
@@ -23207,7 +23230,10 @@ var IkasCartStore = /** @class */ (function () {
|
|
|
23207
23230
|
return __generator(this, function (_d) {
|
|
23208
23231
|
switch (_d.label) {
|
|
23209
23232
|
case 0:
|
|
23210
|
-
_d.trys.push([0,
|
|
23233
|
+
_d.trys.push([0, 5, , 6]);
|
|
23234
|
+
return [4 /*yield*/, this.beforeCartOperationCheck()];
|
|
23235
|
+
case 1:
|
|
23236
|
+
_d.sent();
|
|
23211
23237
|
input = {
|
|
23212
23238
|
cartId: ((_a = this.cart) === null || _a === void 0 ? void 0 : _a.id) || null,
|
|
23213
23239
|
customerId: ((_b = this.cart) === null || _b === void 0 ? void 0 : _b.customerId) || ((_c = this.baseStore.customerStore.customer) === null || _c === void 0 ? void 0 : _c.id) ||
|
|
@@ -23227,14 +23253,14 @@ var IkasCartStore = /** @class */ (function () {
|
|
|
23227
23253
|
storefrontThemeId: IkasStorefrontConfig.storefrontThemeId,
|
|
23228
23254
|
};
|
|
23229
23255
|
return [4 /*yield*/, IkasCartAPI.saveItemToCart(input)];
|
|
23230
|
-
case
|
|
23256
|
+
case 2:
|
|
23231
23257
|
cart = _d.sent();
|
|
23232
|
-
if (!cart) return [3 /*break*/,
|
|
23258
|
+
if (!cart) return [3 /*break*/, 4];
|
|
23233
23259
|
return [4 /*yield*/, this.setCart(cart)];
|
|
23234
|
-
case 2:
|
|
23235
|
-
_d.sent();
|
|
23236
|
-
_d.label = 3;
|
|
23237
23260
|
case 3:
|
|
23261
|
+
_d.sent();
|
|
23262
|
+
_d.label = 4;
|
|
23263
|
+
case 4:
|
|
23238
23264
|
this.removeCardIfEmpty();
|
|
23239
23265
|
if (this.cart) {
|
|
23240
23266
|
eventId = this.cart.id + "-" + this.cart.updatedAt;
|
|
@@ -23246,12 +23272,12 @@ var IkasCartStore = /** @class */ (function () {
|
|
|
23246
23272
|
Analytics.addToCart(item, quantity - oldQuantity, eventId, this.cart);
|
|
23247
23273
|
}
|
|
23248
23274
|
}
|
|
23249
|
-
return [3 /*break*/,
|
|
23250
|
-
case
|
|
23275
|
+
return [3 /*break*/, 6];
|
|
23276
|
+
case 5:
|
|
23251
23277
|
err_3 = _d.sent();
|
|
23252
23278
|
console.log(err_3);
|
|
23253
|
-
return [3 /*break*/,
|
|
23254
|
-
case
|
|
23279
|
+
return [3 /*break*/, 6];
|
|
23280
|
+
case 6: return [2 /*return*/];
|
|
23255
23281
|
}
|
|
23256
23282
|
});
|
|
23257
23283
|
}); };
|
|
@@ -33330,6 +33356,15 @@ var AnalyticsHead = function (_a) {
|
|
|
33330
33356
|
var AnalyticsBody = function () {
|
|
33331
33357
|
var gtmId = IkasStorefrontConfig.gtmId;
|
|
33332
33358
|
var fbpId = IkasStorefrontConfig.fbpId;
|
|
33359
|
+
var router = useRouter();
|
|
33360
|
+
var routeChangeListener = useState(function () { return function () {
|
|
33361
|
+
//@ts-ignore
|
|
33362
|
+
IkasStorefrontConfig.store.customerStore.routeChangeInit();
|
|
33363
|
+
}; })[0];
|
|
33364
|
+
useEffect(function () {
|
|
33365
|
+
router.events.on("routeChangeStart", routeChangeListener);
|
|
33366
|
+
return function () { return router.events.off("routeChangeStart", routeChangeListener); };
|
|
33367
|
+
}, []);
|
|
33333
33368
|
return (createElement(Fragment$1, null,
|
|
33334
33369
|
gtmId && (createElement("noscript", { dangerouslySetInnerHTML: {
|
|
33335
33370
|
__html: "<iframe src=\"https://www.googletagmanager.com/ns.html?id=" + gtmId + "\" height=\"0\" width=\"0\" style=\"display:none;visibility:hidden\"></iframe>",
|
|
@@ -33942,6 +33977,10 @@ var IkasCustomerStore = /** @class */ (function () {
|
|
|
33942
33977
|
});
|
|
33943
33978
|
});
|
|
33944
33979
|
};
|
|
33980
|
+
IkasCustomerStore.prototype.routeChangeInit = function () {
|
|
33981
|
+
if (!this.customer)
|
|
33982
|
+
this.init();
|
|
33983
|
+
};
|
|
33945
33984
|
IkasCustomerStore.prototype.getCustomer = function () {
|
|
33946
33985
|
return __awaiter(this, void 0, void 0, function () {
|
|
33947
33986
|
var customer;
|
package/build/index.js
CHANGED
|
@@ -7,8 +7,8 @@ var fs = require('fs');
|
|
|
7
7
|
var path$1 = require('path');
|
|
8
8
|
var getConfig = require('next/config');
|
|
9
9
|
var React = require('react');
|
|
10
|
-
var mobxReactLite = require('mobx-react-lite');
|
|
11
10
|
var router = require('next/router');
|
|
11
|
+
var mobxReactLite = require('mobx-react-lite');
|
|
12
12
|
var Head = require('next/head');
|
|
13
13
|
var crypto$1 = require('crypto');
|
|
14
14
|
var NextImage = require('next/image');
|
|
@@ -23149,23 +23149,46 @@ var IkasCartStore = /** @class */ (function () {
|
|
|
23149
23149
|
}
|
|
23150
23150
|
});
|
|
23151
23151
|
}); };
|
|
23152
|
+
this.beforeCartOperationCheck = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
23153
|
+
var cartId;
|
|
23154
|
+
return __generator(this, function (_a) {
|
|
23155
|
+
switch (_a.label) {
|
|
23156
|
+
case 0:
|
|
23157
|
+
cartId = localStorage.getItem(CART_LS_KEY);
|
|
23158
|
+
if (!(this.cart && !cartId)) return [3 /*break*/, 1];
|
|
23159
|
+
this.removeCart();
|
|
23160
|
+
return [3 /*break*/, 3];
|
|
23161
|
+
case 1:
|
|
23162
|
+
if (!(!this.cart && !!cartId)) return [3 /*break*/, 3];
|
|
23163
|
+
return [4 /*yield*/, this.getCart()];
|
|
23164
|
+
case 2:
|
|
23165
|
+
_a.sent();
|
|
23166
|
+
_a.label = 3;
|
|
23167
|
+
case 3: return [2 /*return*/];
|
|
23168
|
+
}
|
|
23169
|
+
});
|
|
23170
|
+
}); };
|
|
23152
23171
|
this.addItem = function (variant, product, initialQuantity) {
|
|
23153
23172
|
if (initialQuantity === void 0) { initialQuantity = 1; }
|
|
23154
23173
|
return __awaiter(_this, void 0, void 0, function () {
|
|
23155
|
-
var existingItem, input, cart, eventId, item, err_2;
|
|
23174
|
+
var existingItem, cartId, input, cart, eventId, item, err_2;
|
|
23156
23175
|
var _a, _b, _c;
|
|
23157
23176
|
return __generator(this, function (_d) {
|
|
23158
23177
|
switch (_d.label) {
|
|
23159
23178
|
case 0:
|
|
23160
|
-
_d.trys.push([0,
|
|
23179
|
+
_d.trys.push([0, 5, , 6]);
|
|
23180
|
+
return [4 /*yield*/, this.beforeCartOperationCheck()];
|
|
23181
|
+
case 1:
|
|
23182
|
+
_d.sent();
|
|
23161
23183
|
if (this.cart) {
|
|
23162
23184
|
existingItem = this.cart.items.find(function (item) { return item.variant.id === variant.id; });
|
|
23163
23185
|
if (existingItem) {
|
|
23164
23186
|
return [2 /*return*/, this.changeItemQuantity(existingItem, existingItem.quantity + 1)];
|
|
23165
23187
|
}
|
|
23166
23188
|
}
|
|
23189
|
+
cartId = ((_a = this.cart) === null || _a === void 0 ? void 0 : _a.id) || localStorage.getItem(CART_LS_KEY);
|
|
23167
23190
|
input = {
|
|
23168
|
-
cartId:
|
|
23191
|
+
cartId: cartId,
|
|
23169
23192
|
customerId: ((_b = this.cart) === null || _b === void 0 ? void 0 : _b.customerId) || ((_c = this.baseStore.customerStore.customer) === null || _c === void 0 ? void 0 : _c.id) ||
|
|
23170
23193
|
null,
|
|
23171
23194
|
item: {
|
|
@@ -23183,14 +23206,14 @@ var IkasCartStore = /** @class */ (function () {
|
|
|
23183
23206
|
storefrontThemeId: IkasStorefrontConfig.storefrontThemeId,
|
|
23184
23207
|
};
|
|
23185
23208
|
return [4 /*yield*/, IkasCartAPI.saveItemToCart(input)];
|
|
23186
|
-
case
|
|
23209
|
+
case 2:
|
|
23187
23210
|
cart = _d.sent();
|
|
23188
|
-
if (!cart) return [3 /*break*/,
|
|
23211
|
+
if (!cart) return [3 /*break*/, 4];
|
|
23189
23212
|
return [4 /*yield*/, this.setCart(cart)];
|
|
23190
|
-
case 2:
|
|
23191
|
-
_d.sent();
|
|
23192
|
-
_d.label = 3;
|
|
23193
23213
|
case 3:
|
|
23214
|
+
_d.sent();
|
|
23215
|
+
_d.label = 4;
|
|
23216
|
+
case 4:
|
|
23194
23217
|
if (this.cart) {
|
|
23195
23218
|
eventId = this.cart.id + "-" + this.cart.updatedAt;
|
|
23196
23219
|
item = this.cart.items.find(function (i) { return i.variant.id; });
|
|
@@ -23198,12 +23221,12 @@ var IkasCartStore = /** @class */ (function () {
|
|
|
23198
23221
|
Analytics.addToCart(item, initialQuantity, eventId, this.cart);
|
|
23199
23222
|
}
|
|
23200
23223
|
}
|
|
23201
|
-
return [3 /*break*/,
|
|
23202
|
-
case
|
|
23224
|
+
return [3 /*break*/, 6];
|
|
23225
|
+
case 5:
|
|
23203
23226
|
err_2 = _d.sent();
|
|
23204
23227
|
console.log(err_2);
|
|
23205
|
-
return [3 /*break*/,
|
|
23206
|
-
case
|
|
23228
|
+
return [3 /*break*/, 6];
|
|
23229
|
+
case 6: return [2 /*return*/];
|
|
23207
23230
|
}
|
|
23208
23231
|
});
|
|
23209
23232
|
});
|
|
@@ -23214,7 +23237,10 @@ var IkasCartStore = /** @class */ (function () {
|
|
|
23214
23237
|
return __generator(this, function (_d) {
|
|
23215
23238
|
switch (_d.label) {
|
|
23216
23239
|
case 0:
|
|
23217
|
-
_d.trys.push([0,
|
|
23240
|
+
_d.trys.push([0, 5, , 6]);
|
|
23241
|
+
return [4 /*yield*/, this.beforeCartOperationCheck()];
|
|
23242
|
+
case 1:
|
|
23243
|
+
_d.sent();
|
|
23218
23244
|
input = {
|
|
23219
23245
|
cartId: ((_a = this.cart) === null || _a === void 0 ? void 0 : _a.id) || null,
|
|
23220
23246
|
customerId: ((_b = this.cart) === null || _b === void 0 ? void 0 : _b.customerId) || ((_c = this.baseStore.customerStore.customer) === null || _c === void 0 ? void 0 : _c.id) ||
|
|
@@ -23234,14 +23260,14 @@ var IkasCartStore = /** @class */ (function () {
|
|
|
23234
23260
|
storefrontThemeId: IkasStorefrontConfig.storefrontThemeId,
|
|
23235
23261
|
};
|
|
23236
23262
|
return [4 /*yield*/, IkasCartAPI.saveItemToCart(input)];
|
|
23237
|
-
case
|
|
23263
|
+
case 2:
|
|
23238
23264
|
cart = _d.sent();
|
|
23239
|
-
if (!cart) return [3 /*break*/,
|
|
23265
|
+
if (!cart) return [3 /*break*/, 4];
|
|
23240
23266
|
return [4 /*yield*/, this.setCart(cart)];
|
|
23241
|
-
case 2:
|
|
23242
|
-
_d.sent();
|
|
23243
|
-
_d.label = 3;
|
|
23244
23267
|
case 3:
|
|
23268
|
+
_d.sent();
|
|
23269
|
+
_d.label = 4;
|
|
23270
|
+
case 4:
|
|
23245
23271
|
this.removeCardIfEmpty();
|
|
23246
23272
|
if (this.cart) {
|
|
23247
23273
|
eventId = this.cart.id + "-" + this.cart.updatedAt;
|
|
@@ -23253,12 +23279,12 @@ var IkasCartStore = /** @class */ (function () {
|
|
|
23253
23279
|
Analytics.addToCart(item, quantity - oldQuantity, eventId, this.cart);
|
|
23254
23280
|
}
|
|
23255
23281
|
}
|
|
23256
|
-
return [3 /*break*/,
|
|
23257
|
-
case
|
|
23282
|
+
return [3 /*break*/, 6];
|
|
23283
|
+
case 5:
|
|
23258
23284
|
err_3 = _d.sent();
|
|
23259
23285
|
console.log(err_3);
|
|
23260
|
-
return [3 /*break*/,
|
|
23261
|
-
case
|
|
23286
|
+
return [3 /*break*/, 6];
|
|
23287
|
+
case 6: return [2 /*return*/];
|
|
23262
23288
|
}
|
|
23263
23289
|
});
|
|
23264
23290
|
}); };
|
|
@@ -33337,6 +33363,15 @@ var AnalyticsHead = function (_a) {
|
|
|
33337
33363
|
var AnalyticsBody = function () {
|
|
33338
33364
|
var gtmId = IkasStorefrontConfig.gtmId;
|
|
33339
33365
|
var fbpId = IkasStorefrontConfig.fbpId;
|
|
33366
|
+
var router$1 = router.useRouter();
|
|
33367
|
+
var routeChangeListener = React.useState(function () { return function () {
|
|
33368
|
+
//@ts-ignore
|
|
33369
|
+
IkasStorefrontConfig.store.customerStore.routeChangeInit();
|
|
33370
|
+
}; })[0];
|
|
33371
|
+
React.useEffect(function () {
|
|
33372
|
+
router$1.events.on("routeChangeStart", routeChangeListener);
|
|
33373
|
+
return function () { return router$1.events.off("routeChangeStart", routeChangeListener); };
|
|
33374
|
+
}, []);
|
|
33340
33375
|
return (React.createElement(React.Fragment, null,
|
|
33341
33376
|
gtmId && (React.createElement("noscript", { dangerouslySetInnerHTML: {
|
|
33342
33377
|
__html: "<iframe src=\"https://www.googletagmanager.com/ns.html?id=" + gtmId + "\" height=\"0\" width=\"0\" style=\"display:none;visibility:hidden\"></iframe>",
|
|
@@ -33949,6 +33984,10 @@ var IkasCustomerStore = /** @class */ (function () {
|
|
|
33949
33984
|
});
|
|
33950
33985
|
});
|
|
33951
33986
|
};
|
|
33987
|
+
IkasCustomerStore.prototype.routeChangeInit = function () {
|
|
33988
|
+
if (!this.customer)
|
|
33989
|
+
this.init();
|
|
33990
|
+
};
|
|
33952
33991
|
IkasCustomerStore.prototype.getCustomer = function () {
|
|
33953
33992
|
return __awaiter(this, void 0, void 0, function () {
|
|
33954
33993
|
var customer;
|
package/build/store/cart.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare class IkasCartStore {
|
|
|
17
17
|
get checkoutUrl(): string | undefined;
|
|
18
18
|
private getCart;
|
|
19
19
|
private setCart;
|
|
20
|
+
private beforeCartOperationCheck;
|
|
20
21
|
addItem: (variant: IkasProductVariant, product: IkasProduct, initialQuantity?: number) => Promise<void>;
|
|
21
22
|
changeItemQuantity: (item: IkasOrderLineItem, quantity: number) => Promise<void>;
|
|
22
23
|
removeItem: (item: IkasOrderLineItem) => Promise<void>;
|