@betterstore/react 0.1.5 → 0.1.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/CHANGELOG.md +18 -0
- package/dist/components/cart/useCart.d.ts +10 -2
- package/dist/index.cjs.js +3 -7
- package/dist/index.esm.js +3 -7
- package/package.json +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @betterstore/sdk
|
|
2
2
|
|
|
3
|
+
## 0.1.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- product data added to cart
|
|
8
|
+
|
|
9
|
+
## 0.1.7
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- deps fix
|
|
14
|
+
|
|
15
|
+
## 0.1.6
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- deps fix
|
|
20
|
+
|
|
3
21
|
## 0.1.5
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
type Product = {
|
|
2
|
+
id: string;
|
|
3
|
+
title: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
images: string[];
|
|
6
|
+
priceInCents: number;
|
|
7
|
+
} | string;
|
|
1
8
|
interface LineItem {
|
|
2
9
|
id: string;
|
|
3
|
-
quantity: number;
|
|
4
10
|
productId: string;
|
|
11
|
+
product?: Product;
|
|
12
|
+
quantity: number;
|
|
5
13
|
variantOptions: {
|
|
6
14
|
name: string;
|
|
7
15
|
value: string;
|
|
@@ -19,7 +27,7 @@ type LineItemOptionalParams = {
|
|
|
19
27
|
};
|
|
20
28
|
interface Cart {
|
|
21
29
|
lineItems: LineItem[];
|
|
22
|
-
addItem: (
|
|
30
|
+
addItem: (product: Product, additionalParams?: LineItemOptionalParams) => void;
|
|
23
31
|
removeItem: (id: string) => void;
|
|
24
32
|
updateQuantity: (id: string, quantity: number) => void;
|
|
25
33
|
getProductQuantity: (productId: string) => number;
|
package/dist/index.cjs.js
CHANGED
|
@@ -242,14 +242,10 @@ const generateLineItemId = (item) => {
|
|
|
242
242
|
};
|
|
243
243
|
const useCart = create()(persist((set, get) => ({
|
|
244
244
|
lineItems: [],
|
|
245
|
-
addItem: (
|
|
245
|
+
addItem: (product, additionalParams) => set((state) => {
|
|
246
246
|
var _a, _b;
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
quantity: (_a = additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.quantity) !== null && _a !== void 0 ? _a : 1,
|
|
250
|
-
variantOptions: (_b = additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.variantOptions) !== null && _b !== void 0 ? _b : [],
|
|
251
|
-
metadata: additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.metadata,
|
|
252
|
-
};
|
|
247
|
+
const productId = typeof product === "string" ? product : product === null || product === void 0 ? void 0 : product.id;
|
|
248
|
+
const formattedNewItem = Object.assign(Object.assign({ productId: productId }, (typeof product !== "string" && Object.assign({}, product))), { quantity: (_a = additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.quantity) !== null && _a !== void 0 ? _a : 1, variantOptions: (_b = additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.variantOptions) !== null && _b !== void 0 ? _b : [], metadata: additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.metadata });
|
|
253
249
|
const id = generateLineItemId(formattedNewItem);
|
|
254
250
|
const existingItemIndex = state.lineItems.findIndex((item) => item.id === id);
|
|
255
251
|
if (existingItemIndex !== -1) {
|
package/dist/index.esm.js
CHANGED
|
@@ -240,14 +240,10 @@ const generateLineItemId = (item) => {
|
|
|
240
240
|
};
|
|
241
241
|
const useCart = create()(persist((set, get) => ({
|
|
242
242
|
lineItems: [],
|
|
243
|
-
addItem: (
|
|
243
|
+
addItem: (product, additionalParams) => set((state) => {
|
|
244
244
|
var _a, _b;
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
quantity: (_a = additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.quantity) !== null && _a !== void 0 ? _a : 1,
|
|
248
|
-
variantOptions: (_b = additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.variantOptions) !== null && _b !== void 0 ? _b : [],
|
|
249
|
-
metadata: additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.metadata,
|
|
250
|
-
};
|
|
245
|
+
const productId = typeof product === "string" ? product : product === null || product === void 0 ? void 0 : product.id;
|
|
246
|
+
const formattedNewItem = Object.assign(Object.assign({ productId: productId }, (typeof product !== "string" && Object.assign({}, product))), { quantity: (_a = additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.quantity) !== null && _a !== void 0 ? _a : 1, variantOptions: (_b = additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.variantOptions) !== null && _b !== void 0 ? _b : [], metadata: additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.metadata });
|
|
251
247
|
const id = generateLineItemId(formattedNewItem);
|
|
252
248
|
const existingItemIndex = state.lineItems.findIndex((item) => item.id === id);
|
|
253
249
|
if (existingItemIndex !== -1) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@betterstore/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "E-commerce for Developers",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -25,20 +25,21 @@
|
|
|
25
25
|
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
26
26
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
27
27
|
"@tailwindcss/postcss": "^4.0.12",
|
|
28
|
-
"@types/react": "^
|
|
28
|
+
"@types/react": "^18.0.0",
|
|
29
|
+
"@types/react-dom": "^18.2.0",
|
|
29
30
|
"autoprefixer": "^10.4.20",
|
|
30
|
-
"babel-preset-react": "^6.
|
|
31
|
-
"postcss": "^8.
|
|
31
|
+
"babel-preset-react": "^6.23.3",
|
|
32
|
+
"postcss": "^8.4.31",
|
|
32
33
|
"prettier": "^3.5.3",
|
|
33
34
|
"rollup": "^4.34.9",
|
|
34
|
-
"tailwindcss": "^
|
|
35
|
+
"tailwindcss": "^3.0.12",
|
|
35
36
|
"tslib": "^2.8.1",
|
|
36
37
|
"tsup": "^8.4.0",
|
|
37
38
|
"typescript": "^5.8.2"
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
|
40
|
-
"react": "^
|
|
41
|
-
"react-dom": "^
|
|
41
|
+
"react": "^18.0.0",
|
|
42
|
+
"react-dom": "^18.0.0"
|
|
42
43
|
},
|
|
43
44
|
"dependencies": {
|
|
44
45
|
"@betterstore/sdk": "^0.2.0",
|