@springmicro/cart 0.7.15 → 0.7.19

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@springmicro/cart",
3
3
  "private": false,
4
- "version": "0.7.15",
4
+ "version": "0.7.19",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -24,12 +24,12 @@
24
24
  "@nanostores/persistent": "^0.10.1",
25
25
  "@nanostores/query": "^0.3.3",
26
26
  "@nanostores/react": "^0.7.2",
27
- "@springmicro/utils": "^0.7.15",
27
+ "@springmicro/utils": "^0.7.19",
28
28
  "dotenv": "^16.4.5",
29
29
  "nanostores": "^0.10.3",
30
- "react": "^18.2.0",
30
+ "react": "^19.2.4",
31
31
  "react-credit-cards-2": "^1.0.2",
32
- "react-dom": "^18.2.0",
32
+ "react-dom": "^19.2.4",
33
33
  "unstorage": "^1.10.2",
34
34
  "vite-plugin-dts": "^3.9.0"
35
35
  },
@@ -49,5 +49,5 @@
49
49
  "vite-plugin-css-injected-by-js": "^3.5.1",
50
50
  "yup": "^1.4.0"
51
51
  },
52
- "gitHead": "999f4d500555ee2474404a1baa353945a82781db"
52
+ "gitHead": "5242f8a3ea5bde25f4b6681f9a30baae76713016"
53
53
  }
@@ -25,7 +25,7 @@ export type ProductCardComponentProps = {
25
25
  disabled?: boolean;
26
26
  findInCart?: (
27
27
  product_id: number,
28
- price_id?: number
28
+ price_id?: number,
29
29
  ) => {
30
30
  product: boolean;
31
31
  price: number | null; // If null, price id was not provided or the price wasn't found.
@@ -55,13 +55,13 @@ export default function ProductCard({
55
55
 
56
56
  function findInCart(
57
57
  product_id: number,
58
- price_id?: number
58
+ price_id?: number,
59
59
  ): {
60
60
  product: boolean;
61
61
  price: number | null; // If null, price id was not provided.
62
62
  } {
63
63
  const productInCartIndex: number = (cart.items as any[]).findIndex(
64
- (p) => p.product_id === product_id
64
+ (p) => p.product_id === product_id,
65
65
  );
66
66
 
67
67
  if (price_id == null) {
@@ -72,7 +72,7 @@ export default function ProductCard({
72
72
  }
73
73
 
74
74
  const priceInCartIndex: number = (cart.items as any[]).findIndex(
75
- (p) => p.price_id === price_id
75
+ (p) => p.price_id === price_id,
76
76
  );
77
77
 
78
78
  return {
@@ -82,13 +82,16 @@ export default function ProductCard({
82
82
  }
83
83
 
84
84
  const productInCartIndex: number = (cart.items as any[]).findIndex(
85
- (p) => p.product_id === product.id
85
+ (p) => p.product_id === product.id,
86
86
  );
87
87
  const productFoundInCart = !!~productInCartIndex;
88
88
 
89
89
  const pricing: ProductPricing[] = JSON.parse(product.pricing);
90
90
 
91
- const pi = pricing.findIndex((price) => price.tier_label === priceTierName); // TODO add fail-case for missing price
91
+ const pi =
92
+ pricing.length === 1
93
+ ? 0
94
+ : pricing.findIndex((price) => price.tier_label === priceTierName); // TODO add fail-case for missing price
92
95
 
93
96
  const priceInCartIndex: number =
94
97
  pi != -1
package/src/index.ts CHANGED
@@ -15,7 +15,7 @@ import { AddCard, AddCardProps } from "./checkout/components/AddCard";
15
15
  import Invoice from "./checkout/components/Invoice";
16
16
  import "react-credit-cards-2/dist/es/styles-compiled.css";
17
17
  import "./index.css";
18
- import ProductCard from "./ProductCard";
18
+ import ProductCard, { ProductCardComponentProps } from "./ProductCard";
19
19
  import ReviewCartAndCalculateTaxes from "./checkout/ReviewCartAndCalculateTaxes";
20
20
  import Checkout from "./checkout";
21
21
 
@@ -34,6 +34,7 @@ export {
34
34
  AddToCartForm,
35
35
  setOrder,
36
36
  ProductCard,
37
+ type ProductCardComponentProps,
37
38
  ReviewCartAndCalculateTaxes,
38
39
  login,
39
40
  logout,
@@ -9,7 +9,7 @@ import { Cart, CartProduct, PathDetailsType } from "../types";
9
9
 
10
10
  export const cartStore = persistentAtom(
11
11
  "cart",
12
- JSON.stringify(defaultCartValue)
12
+ JSON.stringify(defaultCartValue),
13
13
  );
14
14
 
15
15
  export const apiPathDetails = atom<PathDetailsType>({});
@@ -66,24 +66,24 @@ apiPathDetails.listen((pathDetails, oldPathDetails) => {
66
66
  fetchFromCartApi(
67
67
  "PUT",
68
68
  pathDetails,
69
- cartToApiCart(pathDetails, localCartData)
69
+ cartToApiCart(pathDetails, localCartData),
70
70
  ).then(async ({ ok, json }) => {
71
71
  if (!ok) return;
72
72
  const cart = await json();
73
- console.log(
74
- "Update local cart",
75
- JSON.stringify({
76
- authentication: { loggedIn: true, user_id: cart.user_id },
77
- items: jsonOrObj(cart.items),
78
- order: cart.order ? jsonOrObj(cart.order) : undefined,
79
- })
80
- );
73
+ // console.log(
74
+ // "Update local cart",
75
+ // JSON.stringify({
76
+ // authentication: { loggedIn: true, user_id: cart.user_id },
77
+ // items: jsonOrObj(cart.items),
78
+ // order: cart.order ? jsonOrObj(cart.order) : undefined,
79
+ // })
80
+ // );
81
81
  cartStore.set(
82
82
  JSON.stringify({
83
83
  authentication: { loggedIn: true, user_id: cart.user_id },
84
84
  items: jsonOrObj(cart.items),
85
85
  order: cart.order ? jsonOrObj(cart.order) : undefined,
86
- })
86
+ }),
87
87
  );
88
88
  });
89
89
  } else {
@@ -91,7 +91,7 @@ apiPathDetails.listen((pathDetails, oldPathDetails) => {
91
91
  JSON.stringify({
92
92
  ...defaultCartValue,
93
93
  authentication: { loggedIn: true, user_id: pathDetails.userId },
94
- })
94
+ }),
95
95
  );
96
96
  }
97
97
  });
@@ -135,7 +135,7 @@ export function addToCart(p: CartProduct) {
135
135
  JSON.stringify({
136
136
  user_id: pathDetails.userId,
137
137
  items: newCart.items.map((p) => cartProductToCartDataItemIds(p)),
138
- })
138
+ }),
139
139
  ).then(async (res) => {
140
140
  if (!res.ok) return;
141
141
 
@@ -171,7 +171,7 @@ export function removeFromCart(i: number) {
171
171
  fetchFromCartApi(
172
172
  cartIsEmpty ? "PUT" : "DELETE",
173
173
  pathDetails,
174
- cartIsEmpty ? JSON.stringify(body) : undefined
174
+ cartIsEmpty ? JSON.stringify(body) : undefined,
175
175
  ).then(async (res) => {
176
176
  if (!res.ok) return;
177
177
 
@@ -211,7 +211,7 @@ export function setOrder(order: { id: number; reference: string }) {
211
211
  user_id: pathDetails.userId,
212
212
  items: newCart.items.map((p) => cartProductToCartDataItemIds(p)),
213
213
  order: JSON.stringify(order),
214
- })
214
+ }),
215
215
  ).then(async () => {
216
216
  cartStore.set(JSON.stringify(newCart));
217
217
  });