@betterstore/react 0.3.24 → 0.3.25

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @betterstore/sdk
2
2
 
3
+ ## 0.3.25
4
+
5
+ ### Patch Changes
6
+
7
+ - bug fixes
8
+
3
9
  ## 0.3.24
4
10
 
5
11
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import { Product, LineItemCreate as SDKLineItem } from "@betterstore/sdk";
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<SDKLineItem, "metadata" | "quantity" | "variantOptions" | "product" | "productId"> {
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">, additionalParams?: LineItemOptionalParams) => void;
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;
@@ -1,4 +1,4 @@
1
- export { useCart } from "./cart/useCart";
1
+ export * from "./cart/useCart";
2
2
  export { default as CheckoutEmbed } from "./checkout-embed";
3
3
  export { default as PaymentElement } from "./payment-element";
4
4
  export { useCheckout } from "./payment-element/useCheckout";
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: (_a = additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.quantity) !== null && _a !== void 0 ? _a : 1,
278
- variantOptions: (_b = additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.variantOptions) !== null && _b !== void 0 ? _b : [],
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: (_a = additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.quantity) !== null && _a !== void 0 ? _a : 1,
255
- variantOptions: (_b = additionalParams === null || additionalParams === void 0 ? void 0 : additionalParams.variantOptions) !== null && _b !== void 0 ? _b : [],
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.24",
3
+ "version": "0.3.25",
4
4
  "description": "E-commerce for Developers",
5
5
  "private": false,
6
6
  "publishConfig": {