@springmicro/cart 0.5.1 → 0.5.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/.eslintrc.cjs CHANGED
@@ -1,21 +1,21 @@
1
- module.exports = {
2
- root: true,
3
- env: { browser: true, es2020: true },
4
- extends: [
5
- "eslint:recommended",
6
- "plugin:@typescript-eslint/recommended",
7
- "plugin:react-hooks/recommended",
8
- ],
9
- ignorePatterns: ["dist", ".eslintrc.cjs"],
10
- parser: "@typescript-eslint/parser",
11
- plugins: ["react-refresh"],
12
- rules: {
13
- "react-refresh/only-export-components": [
14
- "warn",
15
- { allowConstantExport: true },
16
- ],
17
- "@typescript-eslint/no-explicit-any": "off",
18
- "@typescript-eslint/no-unused-vars": "off",
19
- "react-hooks/exhaustive-deps": "off",
20
- },
21
- };
1
+ module.exports = {
2
+ root: true,
3
+ env: { browser: true, es2020: true },
4
+ extends: [
5
+ "eslint:recommended",
6
+ "plugin:@typescript-eslint/recommended",
7
+ "plugin:react-hooks/recommended",
8
+ ],
9
+ ignorePatterns: ["dist", ".eslintrc.cjs"],
10
+ parser: "@typescript-eslint/parser",
11
+ plugins: ["react-refresh"],
12
+ rules: {
13
+ "react-refresh/only-export-components": [
14
+ "warn",
15
+ { allowConstantExport: true },
16
+ ],
17
+ "@typescript-eslint/no-explicit-any": "off",
18
+ "@typescript-eslint/no-unused-vars": "off",
19
+ "react-hooks/exhaustive-deps": "off",
20
+ },
21
+ };
package/README.md CHANGED
@@ -1,64 +1,64 @@
1
- # @springmicro/cart
2
-
3
- A package for eCommerce sites that provides shopping cart functionality.
4
-
5
- # Exports
6
-
7
- ## Components
8
-
9
- ### CartProvider
10
-
11
- Provides and handles all the data for the cart.
12
- Requires a ReactNode child. `apiUrl` will be modified to end with `/api/ecommerce/cart`. If the user object changes, the provider automatically logs in and out of the cart.
13
-
14
- #### Required props:
15
-
16
- ```ts
17
- user={({ id: number | string } & any) | undefined}
18
- apiUrl={string}
19
- ```
20
-
21
- ### CartContext
22
-
23
- Allows all scopes under the `CartProvider` to read from the cart data and the functions to modify the cart.
24
-
25
- #### Provisions:
26
-
27
- - `cart`: `Cart`
28
- - - Provides cart and authentication data.
29
- - `addToCart`: `(product: CartProduct) => void`
30
- - - Adds a product to the cart.
31
- - `removeFromCart`: `(i: number) => void`
32
- - - Removes an item from the cart at the given index.
33
- - `clearCart`: `() => void`
34
- - - Clears the cart.
35
-
36
- ### CartButton
37
-
38
- A frontend-facing component to display the cart contents in a Modal. This component is designed to go in a top navbar, ideally on the right-hand side.
39
- This component is required to be in a `CartProvider` scope.
40
-
41
- ## Types
42
-
43
- ### Cart
44
-
45
- The type of the `cart` in `CartContext.cart`.
46
-
47
- ```ts
48
- {
49
- cart: CartProducts[],
50
- authentication: {loggedIn: boolean, user_id: string | number}
51
- }
52
- ```
53
-
54
- ### CartProduct
55
-
56
- The type of the products listed in `Cart.cart`.
57
-
58
- ```ts
59
- {
60
- id: number | string,
61
- name: string,
62
- quantity: number | undefined
63
- }
64
- ```
1
+ # @springmicro/cart
2
+
3
+ A package for eCommerce sites that provides shopping cart functionality.
4
+
5
+ # Exports
6
+
7
+ ## Components
8
+
9
+ ### CartProvider
10
+
11
+ Provides and handles all the data for the cart.
12
+ Requires a ReactNode child. `apiUrl` will be modified to end with `/api/ecommerce/cart`. If the user object changes, the provider automatically logs in and out of the cart.
13
+
14
+ #### Required props:
15
+
16
+ ```ts
17
+ user={({ id: number | string } & any) | undefined}
18
+ apiUrl={string}
19
+ ```
20
+
21
+ ### CartContext
22
+
23
+ Allows all scopes under the `CartProvider` to read from the cart data and the functions to modify the cart.
24
+
25
+ #### Provisions:
26
+
27
+ - `cart`: `Cart`
28
+ - - Provides cart and authentication data.
29
+ - `addToCart`: `(product: CartProduct) => void`
30
+ - - Adds a product to the cart.
31
+ - `removeFromCart`: `(i: number) => void`
32
+ - - Removes an item from the cart at the given index.
33
+ - `clearCart`: `() => void`
34
+ - - Clears the cart.
35
+
36
+ ### CartButton
37
+
38
+ A frontend-facing component to display the cart contents in a Modal. This component is designed to go in a top navbar, ideally on the right-hand side.
39
+ This component is required to be in a `CartProvider` scope.
40
+
41
+ ## Types
42
+
43
+ ### Cart
44
+
45
+ The type of the `cart` in `CartContext.cart`.
46
+
47
+ ```ts
48
+ {
49
+ cart: CartProducts[],
50
+ authentication: {loggedIn: boolean, user_id: string | number}
51
+ }
52
+ ```
53
+
54
+ ### CartProduct
55
+
56
+ The type of the products listed in `Cart.cart`.
57
+
58
+ ```ts
59
+ {
60
+ id: number | string,
61
+ name: string,
62
+ quantity: number | undefined
63
+ }
64
+ ```
package/dist/index.js CHANGED
@@ -29386,32 +29386,32 @@ function UI({
29386
29386
  priceTierName: n
29387
29387
  }) {
29388
29388
  const r = JSON.parse(kl(xt)), a = r.items.findIndex(
29389
- (f) => f.product_id === e.id
29390
- ), i = !!~a, s = JSON.parse(e.pricing), l = s.findIndex((f) => f.tier_label === n), c = r.items.findIndex(
29391
- (f) => f.price_id === s[l].id
29392
- ), u = !!~c;
29393
- function d(f = l) {
29389
+ (p) => p.product_id === e.id
29390
+ ), i = !!~a, s = JSON.parse(e.pricing), l = s.findIndex((p) => p.tier_label === n), c = l != -1 ? r.items.findIndex((p) => p.price_id === s[l].id) : -1;
29391
+ function u(p = l) {
29392
+ if (p === -1)
29393
+ throw "Price index not found. Provide price index to addToCart OR provide priceTierName to ProductCard.";
29394
29394
  Df({
29395
29395
  product_id: e.id,
29396
29396
  name: e.name,
29397
- price_id: s[f].id,
29397
+ price_id: s[p].id,
29398
29398
  image: void 0,
29399
29399
  quantity: void 0
29400
29400
  });
29401
29401
  }
29402
- const p = {
29402
+ const d = {
29403
29403
  product: e,
29404
29404
  foundInCart: {
29405
29405
  product: i,
29406
- price: u
29406
+ price: l != -1 ? !!~c : null
29407
29407
  },
29408
29408
  pricing: s,
29409
- addToCart: d,
29410
- removeFromCart: (f) => {
29411
- Fl(f ? c : a);
29409
+ addToCart: u,
29410
+ removeFromCart: (p) => {
29411
+ Fl(p ? c : a);
29412
29412
  }
29413
29413
  };
29414
- return t !== void 0 ? t(p) : /* @__PURE__ */ h.jsx(iC, { ...p });
29414
+ return t !== void 0 ? t(d) : /* @__PURE__ */ h.jsx(iC, { ...d });
29415
29415
  }
29416
29416
  function iC({
29417
29417
  product: e,