@betterstore/react 0.3.24 → 0.3.26
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 +12 -0
- package/dist/components/cart/useCart.d.ts +7 -4
- package/dist/components/index.d.ts +1 -1
- package/dist/index.cjs.js +8 -3
- package/dist/index.mjs +8 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Product, LineItemCreate as
|
|
1
|
+
import { Product, LineItemCreate as SDKLineItemCreate } from "@betterstore/sdk";
|
|
2
2
|
type RecursiveRecord = {
|
|
3
3
|
[key: string]: any;
|
|
4
4
|
};
|
|
@@ -10,12 +10,15 @@ type LineItemOptionalParams = {
|
|
|
10
10
|
}[];
|
|
11
11
|
metadata?: RecursiveRecord;
|
|
12
12
|
};
|
|
13
|
-
interface LineItem extends Pick<
|
|
13
|
+
interface LineItem extends Pick<SDKLineItemCreate, "metadata" | "quantity" | "variantOptions" | "productId" | "product"> {
|
|
14
14
|
id: string;
|
|
15
|
+
selectedVariant: Product["productVariants"][number] | null;
|
|
15
16
|
}
|
|
16
|
-
interface Cart {
|
|
17
|
+
export interface Cart {
|
|
17
18
|
lineItems: LineItem[];
|
|
18
|
-
addItem: (product: Omit<Product, "productVariants"
|
|
19
|
+
addItem: (product: Omit<Product, "productVariants"> & {
|
|
20
|
+
productVariants?: Product["productVariants"];
|
|
21
|
+
}, additionalParams?: LineItemOptionalParams) => void;
|
|
19
22
|
removeItem: (id: string) => void;
|
|
20
23
|
updateQuantity: (id: string, quantity: number) => void;
|
|
21
24
|
getProductQuantity: (productId: string) => number;
|
package/dist/index.cjs.js
CHANGED
|
@@ -269,13 +269,18 @@ const generateLineItemId = (item) => {
|
|
|
269
269
|
const useCart = create()(persist((set, get) => ({
|
|
270
270
|
lineItems: [],
|
|
271
271
|
addItem: (product, additionalParams) => set((state) => {
|
|
272
|
-
var _a, _b;
|
|
272
|
+
var _a, _b, _c;
|
|
273
273
|
const productId = product.id;
|
|
274
|
+
const selectedVariant = ((_a = product.productVariants) !== null && _a !== void 0 ? _a : []).find((v) => v.variantOptions.every((vOpt) => {
|
|
275
|
+
var _a;
|
|
276
|
+
return (_a = additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.variantOptions) === null || _a === void 0 ? void 0 : _a.some((iOpt) => vOpt.name === iOpt.name && vOpt.value === iOpt.value);
|
|
277
|
+
})) || null;
|
|
274
278
|
const formattedNewItem = {
|
|
275
279
|
productId: productId,
|
|
276
280
|
product: product,
|
|
277
|
-
quantity: (
|
|
278
|
-
|
|
281
|
+
quantity: (_b = additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.quantity) !== null && _b !== void 0 ? _b : 1,
|
|
282
|
+
selectedVariant,
|
|
283
|
+
variantOptions: (_c = additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.variantOptions) !== null && _c !== void 0 ? _c : [],
|
|
279
284
|
metadata: additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.metadata,
|
|
280
285
|
};
|
|
281
286
|
const id = generateLineItemId(formattedNewItem);
|
package/dist/index.mjs
CHANGED
|
@@ -246,13 +246,18 @@ const generateLineItemId = (item) => {
|
|
|
246
246
|
const useCart = create()(persist((set, get) => ({
|
|
247
247
|
lineItems: [],
|
|
248
248
|
addItem: (product, additionalParams) => set((state) => {
|
|
249
|
-
var _a, _b;
|
|
249
|
+
var _a, _b, _c;
|
|
250
250
|
const productId = product.id;
|
|
251
|
+
const selectedVariant = ((_a = product.productVariants) !== null && _a !== void 0 ? _a : []).find((v) => v.variantOptions.every((vOpt) => {
|
|
252
|
+
var _a;
|
|
253
|
+
return (_a = additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.variantOptions) === null || _a === void 0 ? void 0 : _a.some((iOpt) => vOpt.name === iOpt.name && vOpt.value === iOpt.value);
|
|
254
|
+
})) || null;
|
|
251
255
|
const formattedNewItem = {
|
|
252
256
|
productId: productId,
|
|
253
257
|
product: product,
|
|
254
|
-
quantity: (
|
|
255
|
-
|
|
258
|
+
quantity: (_b = additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.quantity) !== null && _b !== void 0 ? _b : 1,
|
|
259
|
+
selectedVariant,
|
|
260
|
+
variantOptions: (_c = additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.variantOptions) !== null && _c !== void 0 ? _c : [],
|
|
256
261
|
metadata: additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.metadata,
|
|
257
262
|
};
|
|
258
263
|
const id = generateLineItemId(formattedNewItem);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@betterstore/react",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.26",
|
|
4
4
|
"description": "E-commerce for Developers",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"author": "Better Store",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@betterstore/sdk": "^0.3.
|
|
22
|
+
"@betterstore/sdk": "^0.3.76",
|
|
23
23
|
"@changesets/cli": "^2.28.1",
|
|
24
24
|
"@rollup/plugin-commonjs": "^28.0.3",
|
|
25
25
|
"@rollup/plugin-json": "^6.1.0",
|