@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 +21 -21
- package/README.md +64 -64
- package/dist/index.js +12 -12
- package/dist/index.umd.cjs +1 -1
- package/package.json +3 -3
- package/springmicro-cart-0.3.4.tgz +0 -0
- package/src/AddToCartForm.tsx +16 -16
- package/src/CartButton.tsx +249 -249
- package/src/ProductCard.css +106 -106
- package/src/ProductCard.tsx +167 -165
- package/src/checkout/ReviewCartAndCalculateTaxes.css +93 -93
- package/src/checkout/ReviewCartAndCalculateTaxes.tsx +370 -370
- package/src/checkout/components/AddCard.tsx +267 -267
- package/src/checkout/components/Address.tsx +261 -261
- package/src/checkout/components/CartList.tsx +151 -151
- package/src/checkout/components/CartProductCard.css +67 -67
- package/src/checkout/components/CartProductCard.tsx +90 -90
- package/src/checkout/components/Invoice.tsx +145 -145
- package/src/checkout/components/ProviderLogos.tsx +93 -93
- package/src/checkout/components/StatusBar.tsx +32 -32
- package/src/checkout/index.tsx +165 -165
- package/src/index.css +5 -5
- package/src/index.ts +36 -36
- package/src/types.d.ts +56 -56
- package/src/utils/api.ts +67 -67
- package/src/utils/cartAuthHandler.ts +50 -50
- package/src/utils/index.ts +28 -28
- package/src/utils/storage.ts +133 -133
- package/tsconfig.json +24 -24
- package/tsconfig.node.json +11 -11
- package/vite.config.ts +25 -25
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
|
-
(
|
|
29390
|
-
), i = !!~a, s = JSON.parse(e.pricing), l = s.findIndex((
|
|
29391
|
-
|
|
29392
|
-
|
|
29393
|
-
|
|
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[
|
|
29397
|
+
price_id: s[p].id,
|
|
29398
29398
|
image: void 0,
|
|
29399
29399
|
quantity: void 0
|
|
29400
29400
|
});
|
|
29401
29401
|
}
|
|
29402
|
-
const
|
|
29402
|
+
const d = {
|
|
29403
29403
|
product: e,
|
|
29404
29404
|
foundInCart: {
|
|
29405
29405
|
product: i,
|
|
29406
|
-
price:
|
|
29406
|
+
price: l != -1 ? !!~c : null
|
|
29407
29407
|
},
|
|
29408
29408
|
pricing: s,
|
|
29409
|
-
addToCart:
|
|
29410
|
-
removeFromCart: (
|
|
29411
|
-
Fl(
|
|
29409
|
+
addToCart: u,
|
|
29410
|
+
removeFromCart: (p) => {
|
|
29411
|
+
Fl(p ? c : a);
|
|
29412
29412
|
}
|
|
29413
29413
|
};
|
|
29414
|
-
return t !== void 0 ? t(
|
|
29414
|
+
return t !== void 0 ? t(d) : /* @__PURE__ */ h.jsx(iC, { ...d });
|
|
29415
29415
|
}
|
|
29416
29416
|
function iC({
|
|
29417
29417
|
product: e,
|