commerce-kit 0.6.0 → 0.6.1-experimental.2
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/dist/index.d.ts +37 -6
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -0
- package/package.json +23 -44
- package/LICENSE.md +0 -650
- package/README.md +0 -234
- package/dist/currencies.d.ts +0 -11
- package/dist/currencies.js +0 -1
- package/dist/internal.d.ts +0 -383
- package/dist/internal.js +0 -1
- package/dist/provider-CeP9uHnB.d.ts +0 -166
- package/dist/stripe.d.ts +0 -75
- package/dist/stripe.js +0 -1
- package/dist/yns-context.d.ts +0 -22
- package/dist/yns-context.js +0 -1
- package/dist/yns.d.ts +0 -101
- package/dist/yns.js +0 -1
package/README.md
DELETED
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
# commerce-kit
|
|
2
|
-
|
|
3
|
-
TypeScript SDK for building e-commerce apps. Works with Stripe and YNS APIs through a clean, unified interface. Built for Next.js, but plays nice with whatever you're using.
|
|
4
|
-
|
|
5
|
-
Built by [Your Next Store](https://yournextstore.com).
|
|
6
|
-
|
|
7
|
-
## Features
|
|
8
|
-
|
|
9
|
-
- **Multi-provider**: Switch between Stripe and YNS without changing code
|
|
10
|
-
- **Class-based**: Industry standard pattern like Stripe, OpenAI, AWS SDK
|
|
11
|
-
- **Zero config**: Works out of the box with environment variables
|
|
12
|
-
- **Type-safe**: Full TypeScript with provider-specific types
|
|
13
|
-
- **GraphQL support**: Field selection for YNS, REST for Stripe
|
|
14
|
-
- **Multi-instance**: Perfect for testing and multi-tenant apps
|
|
15
|
-
|
|
16
|
-
## Install
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
npm install commerce-kit
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
## Quick start
|
|
23
|
-
|
|
24
|
-
**Zero config** - works automatically with environment variables:
|
|
25
|
-
|
|
26
|
-
```tsx
|
|
27
|
-
// Set environment variables:
|
|
28
|
-
// STRIPE_SECRET_KEY=sk_test_...
|
|
29
|
-
// or YNS_ENDPOINT=https://api.yournextstore.com and YNS_TOKEN=token_...
|
|
30
|
-
|
|
31
|
-
import commerce from "commerce-kit";
|
|
32
|
-
import { formatMoney } from "commerce-kit/currencies";
|
|
33
|
-
|
|
34
|
-
export async function ProductList() {
|
|
35
|
-
const products = await commerce.product.browse({ first: 6 });
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<div>
|
|
39
|
-
{products.data.map((product) => (
|
|
40
|
-
<div key={product.id}>
|
|
41
|
-
<h2>{product.name}</h2>
|
|
42
|
-
<p>{formatMoney({ amount: product.price, currency: product.currency })}</p>
|
|
43
|
-
</div>
|
|
44
|
-
))}
|
|
45
|
-
</div>
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
**Explicit configuration**:
|
|
51
|
-
|
|
52
|
-
```tsx
|
|
53
|
-
import { Commerce } from "commerce-kit";
|
|
54
|
-
|
|
55
|
-
// Create your own instance with explicit config
|
|
56
|
-
const commerce = new Commerce({
|
|
57
|
-
provider: "stripe",
|
|
58
|
-
stripe: { secretKey: "sk_test_..." }
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const products = await commerce.product.browse({ first: 6 });
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
## Usage Patterns
|
|
65
|
-
|
|
66
|
-
### 1. Default Instance (Recommended)
|
|
67
|
-
|
|
68
|
-
```tsx
|
|
69
|
-
import commerce from "commerce-kit";
|
|
70
|
-
|
|
71
|
-
// Auto-detects from STRIPE_SECRET_KEY or YNS_ENDPOINT/YNS_TOKEN
|
|
72
|
-
const products = await commerce.product.browse({ first: 10 });
|
|
73
|
-
const cart = await commerce.cart.add({ variantId: "var_123", quantity: 1 });
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
### 2. Commerce Class
|
|
77
|
-
|
|
78
|
-
```tsx
|
|
79
|
-
import { Commerce } from "commerce-kit";
|
|
80
|
-
|
|
81
|
-
// Zero-config constructor
|
|
82
|
-
const commerce = new Commerce();
|
|
83
|
-
|
|
84
|
-
// Or explicit configuration
|
|
85
|
-
const commerce = new Commerce({
|
|
86
|
-
provider: "stripe",
|
|
87
|
-
stripe: { secretKey: "sk_test_..." }
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
const products = await commerce.product.browse({ first: 10 });
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
### 3. Provider-Specific Classes
|
|
94
|
-
|
|
95
|
-
```tsx
|
|
96
|
-
import { StripeCommerce, YNSCommerce } from "commerce-kit";
|
|
97
|
-
|
|
98
|
-
// Stripe-specific client
|
|
99
|
-
const stripe = new StripeCommerce({
|
|
100
|
-
secretKey: "sk_test_..."
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
// YNS-specific client with GraphQL support
|
|
104
|
-
const yns = new YNSCommerce({
|
|
105
|
-
endpoint: "https://api.yournextstore.com",
|
|
106
|
-
token: "token_..."
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
const stripeProducts = await stripe.product.browse({ first: 10 });
|
|
110
|
-
const ynsProducts = await yns.product.browse({
|
|
111
|
-
first: 10,
|
|
112
|
-
fields: ["id", "name", "price"] // GraphQL field selection
|
|
113
|
-
});
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
## API Reference
|
|
117
|
-
|
|
118
|
-
### Products
|
|
119
|
-
|
|
120
|
-
```tsx
|
|
121
|
-
import { Commerce } from "commerce-kit";
|
|
122
|
-
const commerce = new Commerce();
|
|
123
|
-
|
|
124
|
-
// Browse with filters
|
|
125
|
-
const products = await commerce.product.browse({
|
|
126
|
-
first: 10,
|
|
127
|
-
category: "electronics",
|
|
128
|
-
fields: ["id", "name", "price"] // GraphQL field selection (YNS only)
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
// Get single product
|
|
132
|
-
const product = await commerce.product.get({ slug: "awesome-laptop" });
|
|
133
|
-
|
|
134
|
-
// Search (YNS only)
|
|
135
|
-
const results = await commerce.product.search({ query: "macbook" });
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
### Cart
|
|
139
|
-
|
|
140
|
-
```tsx
|
|
141
|
-
import { Commerce } from "commerce-kit";
|
|
142
|
-
const commerce = new Commerce();
|
|
143
|
-
|
|
144
|
-
// Add to cart
|
|
145
|
-
const result = await commerce.cart.add({
|
|
146
|
-
variantId: "variant_123",
|
|
147
|
-
quantity: 2
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
// Update quantity
|
|
151
|
-
await commerce.cart.update({
|
|
152
|
-
cartId: result.cartId,
|
|
153
|
-
variantId: "variant_123",
|
|
154
|
-
quantity: 3
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
// Get cart
|
|
158
|
-
const cartData = await commerce.cart.get({ cartId: result.cartId });
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### Orders (YNS only)
|
|
162
|
-
|
|
163
|
-
```tsx
|
|
164
|
-
import { YNSCommerce } from "commerce-kit";
|
|
165
|
-
|
|
166
|
-
const yns = new YNSCommerce({
|
|
167
|
-
endpoint: process.env.YNS_ENDPOINT,
|
|
168
|
-
token: process.env.YNS_TOKEN
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
// List orders
|
|
172
|
-
const orders = await yns.order.list({ first: 10 });
|
|
173
|
-
|
|
174
|
-
// Get single order
|
|
175
|
-
const order = await yns.order.get({ id: "order_123" });
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
## Environment Variables
|
|
179
|
-
|
|
180
|
-
Set these environment variables for automatic configuration:
|
|
181
|
-
|
|
182
|
-
```bash
|
|
183
|
-
# For Stripe
|
|
184
|
-
STRIPE_SECRET_KEY=sk_test_...
|
|
185
|
-
STRIPE_TAG_PREFIX=my-store # optional
|
|
186
|
-
|
|
187
|
-
# For YNS
|
|
188
|
-
YNS_ENDPOINT=https://api.yournextstore.com
|
|
189
|
-
YNS_TOKEN=token_...
|
|
190
|
-
|
|
191
|
-
# Optional: explicitly choose provider
|
|
192
|
-
COMMERCE_PROVIDER=stripe # or "yns"
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
## Multi-Tenant & Testing
|
|
196
|
-
|
|
197
|
-
Perfect for multi-tenant applications and testing:
|
|
198
|
-
|
|
199
|
-
```tsx
|
|
200
|
-
// Multi-tenant
|
|
201
|
-
class TenantService {
|
|
202
|
-
getCommerce(tenantId: string) {
|
|
203
|
-
const config = this.getTenantConfig(tenantId);
|
|
204
|
-
return new Commerce(config);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// Testing
|
|
209
|
-
describe("Product Service", () => {
|
|
210
|
-
it("should fetch products", async () => {
|
|
211
|
-
const commerce = new Commerce({
|
|
212
|
-
provider: "stripe",
|
|
213
|
-
stripe: { secretKey: "sk_test_mock" }
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
const products = await commerce.product.browse();
|
|
217
|
-
expect(products).toBeDefined();
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
## Why Class-Based?
|
|
223
|
-
|
|
224
|
-
Following industry standards from Stripe, OpenAI, and AWS SDK:
|
|
225
|
-
|
|
226
|
-
- ✅ **Explicit initialization** - Clear where configuration happens
|
|
227
|
-
- ✅ **Multiple instances** - Multi-tenant and testing support
|
|
228
|
-
- ✅ **Type safety** - Better TypeScript integration
|
|
229
|
-
- ✅ **No global state** - Each instance is isolated
|
|
230
|
-
- ✅ **Familiar pattern** - Same as `new Stripe()`, `new OpenAI()`
|
|
231
|
-
|
|
232
|
-
## License
|
|
233
|
-
|
|
234
|
-
AGPL-3.0 – see LICENSE.md
|
package/dist/currencies.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
type Money = {
|
|
2
|
-
amount: number;
|
|
3
|
-
currency: string;
|
|
4
|
-
};
|
|
5
|
-
declare const getStripeAmountFromDecimal: ({ amount: major, currency }: Money) => number;
|
|
6
|
-
declare const getDecimalFromStripeAmount: ({ amount: minor, currency }: Money) => number;
|
|
7
|
-
declare const formatMoney: ({ amount: minor, currency, locale }: Money & {
|
|
8
|
-
locale?: string;
|
|
9
|
-
}) => string;
|
|
10
|
-
|
|
11
|
-
export { formatMoney, getDecimalFromStripeAmount, getStripeAmountFromDecimal };
|
package/dist/currencies.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function o(e,n){if(!e)throw new Error(n)}var s=e=>{o(Number.isInteger(e),"Value must be an integer")};var u=e=>(o(e.length===3,"currency needs to be a 3-letter code"),a[e.toUpperCase()]??2),m=({amount:e,currency:n})=>{let t=10**u(n);return Number.parseInt((e*t).toFixed(0),10)},i=({amount:e,currency:n})=>{s(e);let r=u(n),t=10**r;return Number.parseFloat((e/t).toFixed(r))},p=({amount:e,currency:n,locale:r="en-US"})=>{let t=i({amount:e,currency:n});return new Intl.NumberFormat(r,{style:"currency",currency:n}).format(t)},a={BIF:0,CLP:0,DJF:0,GNF:0,JPY:0,KMF:0,KRW:0,MGA:0,PYG:0,RWF:0,UGX:0,VND:0,VUV:0,XAF:0,XOF:0,XPF:0,BHD:3,JOD:3,KWD:3,OMR:3,TND:3};export{p as formatMoney,i as getDecimalFromStripeAmount,m as getStripeAmountFromDecimal};
|
package/dist/internal.d.ts
DELETED
|
@@ -1,383 +0,0 @@
|
|
|
1
|
-
import Stripe from 'stripe';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
|
|
4
|
-
declare const sanitizeQueryValue: (slug: string | number | boolean) => string;
|
|
5
|
-
declare const objectToStripeQuery: (obj: Record<string, string | number | boolean>) => string;
|
|
6
|
-
|
|
7
|
-
type MappedProduct = ReturnType<typeof mapProduct>;
|
|
8
|
-
/**
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
declare function sortProducts(products: MappedProduct[]): {
|
|
12
|
-
default_price: Stripe.Price;
|
|
13
|
-
marketing_features: (string | undefined)[];
|
|
14
|
-
metadata: {
|
|
15
|
-
slug: string;
|
|
16
|
-
stock: number;
|
|
17
|
-
category?: string | undefined;
|
|
18
|
-
order?: number | undefined;
|
|
19
|
-
variant?: string | undefined;
|
|
20
|
-
digitalAsset?: string | undefined;
|
|
21
|
-
preview?: string | undefined;
|
|
22
|
-
};
|
|
23
|
-
id: string;
|
|
24
|
-
object: "product";
|
|
25
|
-
active: boolean;
|
|
26
|
-
created: number;
|
|
27
|
-
deleted?: void | undefined;
|
|
28
|
-
description: string | null;
|
|
29
|
-
images: Array<string>;
|
|
30
|
-
livemode: boolean;
|
|
31
|
-
name: string;
|
|
32
|
-
package_dimensions: Stripe.Product.PackageDimensions | null;
|
|
33
|
-
shippable: boolean | null;
|
|
34
|
-
statement_descriptor?: string | null;
|
|
35
|
-
tax_code: string | Stripe.TaxCode | null;
|
|
36
|
-
type: Stripe.Product.Type;
|
|
37
|
-
unit_label?: string | null;
|
|
38
|
-
updated: number;
|
|
39
|
-
url: string | null;
|
|
40
|
-
}[];
|
|
41
|
-
declare const ProductMetadataSchema: z.ZodObject<{
|
|
42
|
-
category: z.ZodOptional<z.ZodString>;
|
|
43
|
-
order: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
44
|
-
slug: z.ZodString;
|
|
45
|
-
variant: z.ZodOptional<z.ZodString>;
|
|
46
|
-
stock: z.ZodPipe<z.ZodOptional<z.ZodCoercedNumber<unknown>>, z.ZodTransform<number, number | undefined>>;
|
|
47
|
-
digitalAsset: z.ZodOptional<z.ZodString>;
|
|
48
|
-
preview: z.ZodOptional<z.ZodString>;
|
|
49
|
-
}, z.core.$strip>;
|
|
50
|
-
type ProductMetadata = z.infer<typeof ProductMetadataSchema>;
|
|
51
|
-
/**
|
|
52
|
-
* @internal
|
|
53
|
-
*/
|
|
54
|
-
declare function mapProduct({ default_price, marketing_features, ...product }: Stripe.Product): {
|
|
55
|
-
default_price: Stripe.Price;
|
|
56
|
-
marketing_features: (string | undefined)[];
|
|
57
|
-
metadata: {
|
|
58
|
-
slug: string;
|
|
59
|
-
stock: number;
|
|
60
|
-
category?: string | undefined;
|
|
61
|
-
order?: number | undefined;
|
|
62
|
-
variant?: string | undefined;
|
|
63
|
-
digitalAsset?: string | undefined;
|
|
64
|
-
preview?: string | undefined;
|
|
65
|
-
};
|
|
66
|
-
id: string;
|
|
67
|
-
object: "product";
|
|
68
|
-
active: boolean;
|
|
69
|
-
created: number;
|
|
70
|
-
deleted?: void | undefined;
|
|
71
|
-
description: string | null;
|
|
72
|
-
images: Array<string>;
|
|
73
|
-
livemode: boolean;
|
|
74
|
-
name: string;
|
|
75
|
-
package_dimensions: Stripe.Product.PackageDimensions | null;
|
|
76
|
-
shippable: boolean | null;
|
|
77
|
-
statement_descriptor?: string | null;
|
|
78
|
-
tax_code: string | Stripe.TaxCode | null;
|
|
79
|
-
type: Stripe.Product.Type;
|
|
80
|
-
unit_label?: string | null;
|
|
81
|
-
updated: number;
|
|
82
|
-
url: string | null;
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* @internal
|
|
86
|
-
*/
|
|
87
|
-
declare function filterValidProduct(product: Stripe.Product): boolean;
|
|
88
|
-
/**
|
|
89
|
-
* @internal
|
|
90
|
-
*/
|
|
91
|
-
declare function filterValidProducts(products: Stripe.Response<Stripe.ApiSearchResult<Stripe.Product> | Stripe.ApiList<Stripe.Product>>): {
|
|
92
|
-
data: Stripe.Product[];
|
|
93
|
-
object: "search_result";
|
|
94
|
-
has_more: boolean;
|
|
95
|
-
url: string;
|
|
96
|
-
next_page: string | null;
|
|
97
|
-
total_count?: number;
|
|
98
|
-
lastResponse: {
|
|
99
|
-
headers: {
|
|
100
|
-
[key: string]: string;
|
|
101
|
-
};
|
|
102
|
-
requestId: string;
|
|
103
|
-
statusCode: number;
|
|
104
|
-
apiVersion?: string;
|
|
105
|
-
idempotencyKey?: string;
|
|
106
|
-
stripeAccount?: string;
|
|
107
|
-
};
|
|
108
|
-
} | {
|
|
109
|
-
data: Stripe.Product[];
|
|
110
|
-
object: "list";
|
|
111
|
-
has_more: boolean;
|
|
112
|
-
url: string;
|
|
113
|
-
lastResponse: {
|
|
114
|
-
headers: {
|
|
115
|
-
[key: string]: string;
|
|
116
|
-
};
|
|
117
|
-
requestId: string;
|
|
118
|
-
statusCode: number;
|
|
119
|
-
apiVersion?: string;
|
|
120
|
-
idempotencyKey?: string;
|
|
121
|
-
stripeAccount?: string;
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
/**
|
|
125
|
-
* @internal
|
|
126
|
-
*/
|
|
127
|
-
declare function mapProducts(products: Stripe.Response<Stripe.ApiSearchResult<Stripe.Product> | Stripe.ApiList<Stripe.Product>>): {
|
|
128
|
-
default_price: Stripe.Price;
|
|
129
|
-
marketing_features: (string | undefined)[];
|
|
130
|
-
metadata: {
|
|
131
|
-
slug: string;
|
|
132
|
-
stock: number;
|
|
133
|
-
category?: string | undefined;
|
|
134
|
-
order?: number | undefined;
|
|
135
|
-
variant?: string | undefined;
|
|
136
|
-
digitalAsset?: string | undefined;
|
|
137
|
-
preview?: string | undefined;
|
|
138
|
-
};
|
|
139
|
-
id: string;
|
|
140
|
-
object: "product";
|
|
141
|
-
active: boolean;
|
|
142
|
-
created: number;
|
|
143
|
-
deleted?: void | undefined;
|
|
144
|
-
description: string | null;
|
|
145
|
-
images: Array<string>;
|
|
146
|
-
livemode: boolean;
|
|
147
|
-
name: string;
|
|
148
|
-
package_dimensions: Stripe.Product.PackageDimensions | null;
|
|
149
|
-
shippable: boolean | null;
|
|
150
|
-
statement_descriptor?: string | null;
|
|
151
|
-
tax_code: string | Stripe.TaxCode | null;
|
|
152
|
-
type: Stripe.Product.Type;
|
|
153
|
-
unit_label?: string | null;
|
|
154
|
-
updated: number;
|
|
155
|
-
url: string | null;
|
|
156
|
-
}[];
|
|
157
|
-
/**
|
|
158
|
-
* @internal
|
|
159
|
-
*/
|
|
160
|
-
declare function mapShippingRate(shippingRate: Stripe.ShippingRate): Stripe.ShippingRate;
|
|
161
|
-
type MappedShippingRate = ReturnType<typeof mapShippingRate>;
|
|
162
|
-
/**
|
|
163
|
-
* @internal
|
|
164
|
-
*/
|
|
165
|
-
declare function mapShippingRates(shippingRates: Stripe.ApiList<Stripe.ShippingRate>): Stripe.ShippingRate[];
|
|
166
|
-
/**
|
|
167
|
-
* @internal
|
|
168
|
-
*/
|
|
169
|
-
declare function getUniqueVariants(products: MappedProduct[]): {
|
|
170
|
-
default_price: Stripe.Price;
|
|
171
|
-
marketing_features: (string | undefined)[];
|
|
172
|
-
metadata: {
|
|
173
|
-
slug: string;
|
|
174
|
-
stock: number;
|
|
175
|
-
category?: string | undefined;
|
|
176
|
-
order?: number | undefined;
|
|
177
|
-
variant?: string | undefined;
|
|
178
|
-
digitalAsset?: string | undefined;
|
|
179
|
-
preview?: string | undefined;
|
|
180
|
-
};
|
|
181
|
-
id: string;
|
|
182
|
-
object: "product";
|
|
183
|
-
active: boolean;
|
|
184
|
-
created: number;
|
|
185
|
-
deleted?: void | undefined;
|
|
186
|
-
description: string | null;
|
|
187
|
-
images: Array<string>;
|
|
188
|
-
livemode: boolean;
|
|
189
|
-
name: string;
|
|
190
|
-
package_dimensions: Stripe.Product.PackageDimensions | null;
|
|
191
|
-
shippable: boolean | null;
|
|
192
|
-
statement_descriptor?: string | null;
|
|
193
|
-
tax_code: string | Stripe.TaxCode | null;
|
|
194
|
-
type: Stripe.Product.Type;
|
|
195
|
-
unit_label?: string | null;
|
|
196
|
-
updated: number;
|
|
197
|
-
url: string | null;
|
|
198
|
-
}[];
|
|
199
|
-
/**
|
|
200
|
-
* @internal
|
|
201
|
-
*/
|
|
202
|
-
declare const isProductAvailable: (product: MappedProduct) => boolean;
|
|
203
|
-
/**
|
|
204
|
-
* @internal
|
|
205
|
-
*/
|
|
206
|
-
declare const cartMetadataSchema: z.ZodIntersection<z.ZodObject<{
|
|
207
|
-
shippingRateId: z.ZodOptional<z.ZodString>;
|
|
208
|
-
taxCalculationId: z.ZodOptional<z.ZodString>;
|
|
209
|
-
taxCalculationExp: z.ZodOptional<z.ZodString>;
|
|
210
|
-
taxId: z.ZodOptional<z.ZodString>;
|
|
211
|
-
couponCode: z.ZodOptional<z.ZodString>;
|
|
212
|
-
taxedAmount: z.ZodOptional<z.ZodString>;
|
|
213
|
-
"billingAddress.city": z.ZodOptional<z.ZodString>;
|
|
214
|
-
"billingAddress.country": z.ZodOptional<z.ZodString>;
|
|
215
|
-
"billingAddress.line1": z.ZodOptional<z.ZodString>;
|
|
216
|
-
"billingAddress.line2": z.ZodOptional<z.ZodString>;
|
|
217
|
-
"billingAddress.name": z.ZodOptional<z.ZodString>;
|
|
218
|
-
"billingAddress.postalCode": z.ZodOptional<z.ZodString>;
|
|
219
|
-
"billingAddress.state": z.ZodOptional<z.ZodString>;
|
|
220
|
-
netAmount: z.ZodOptional<z.ZodString>;
|
|
221
|
-
taxBreakdown0: z.ZodOptional<z.ZodString>;
|
|
222
|
-
taxBreakdown1: z.ZodOptional<z.ZodString>;
|
|
223
|
-
taxBreakdown2: z.ZodOptional<z.ZodString>;
|
|
224
|
-
taxBreakdown3: z.ZodOptional<z.ZodString>;
|
|
225
|
-
taxBreakdown4: z.ZodOptional<z.ZodString>;
|
|
226
|
-
taxBreakdown5: z.ZodOptional<z.ZodString>;
|
|
227
|
-
}, z.core.$strip>, z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
228
|
-
type CartMetadata = z.infer<typeof cartMetadataSchema>;
|
|
229
|
-
/**
|
|
230
|
-
* @internal
|
|
231
|
-
*/
|
|
232
|
-
declare const cartMetadataTaxBreakdownSchema: z.ZodObject<{
|
|
233
|
-
taxType: z.ZodLiteral<Stripe.Tax.Calculation.TaxBreakdown.TaxRateDetails.TaxType | (string & {})>;
|
|
234
|
-
taxPercentage: z.ZodString;
|
|
235
|
-
taxAmount: z.ZodNumber;
|
|
236
|
-
}, z.core.$strip>;
|
|
237
|
-
/**
|
|
238
|
-
* @internal
|
|
239
|
-
*/
|
|
240
|
-
declare function mapCart(cart: Stripe.PaymentIntent): {
|
|
241
|
-
metadata: {
|
|
242
|
-
shippingRateId?: string | undefined;
|
|
243
|
-
taxCalculationId?: string | undefined;
|
|
244
|
-
taxCalculationExp?: string | undefined;
|
|
245
|
-
taxId?: string | undefined;
|
|
246
|
-
couponCode?: string | undefined;
|
|
247
|
-
taxedAmount?: string | undefined;
|
|
248
|
-
"billingAddress.city"?: string | undefined;
|
|
249
|
-
"billingAddress.country"?: string | undefined;
|
|
250
|
-
"billingAddress.line1"?: string | undefined;
|
|
251
|
-
"billingAddress.line2"?: string | undefined;
|
|
252
|
-
"billingAddress.name"?: string | undefined;
|
|
253
|
-
"billingAddress.postalCode"?: string | undefined;
|
|
254
|
-
"billingAddress.state"?: string | undefined;
|
|
255
|
-
netAmount?: string | undefined;
|
|
256
|
-
taxBreakdown0?: string | undefined;
|
|
257
|
-
taxBreakdown1?: string | undefined;
|
|
258
|
-
taxBreakdown2?: string | undefined;
|
|
259
|
-
taxBreakdown3?: string | undefined;
|
|
260
|
-
taxBreakdown4?: string | undefined;
|
|
261
|
-
taxBreakdown5?: string | undefined;
|
|
262
|
-
} & Record<string, string>;
|
|
263
|
-
customer: Stripe.Customer | null;
|
|
264
|
-
payment_method: Stripe.PaymentMethod | null;
|
|
265
|
-
taxBreakdown: ({
|
|
266
|
-
taxType: Stripe.Tax.Calculation.TaxBreakdown.TaxRateDetails.TaxType | (string & {});
|
|
267
|
-
taxPercentage: string;
|
|
268
|
-
taxAmount: number;
|
|
269
|
-
} | null)[];
|
|
270
|
-
id: string;
|
|
271
|
-
object: "payment_intent";
|
|
272
|
-
amount: number;
|
|
273
|
-
amount_capturable: number;
|
|
274
|
-
amount_details?: Stripe.PaymentIntent.AmountDetails;
|
|
275
|
-
amount_received: number;
|
|
276
|
-
application: string | Stripe.Application | null;
|
|
277
|
-
application_fee_amount: number | null;
|
|
278
|
-
automatic_payment_methods: Stripe.PaymentIntent.AutomaticPaymentMethods | null;
|
|
279
|
-
canceled_at: number | null;
|
|
280
|
-
cancellation_reason: Stripe.PaymentIntent.CancellationReason | null;
|
|
281
|
-
capture_method: Stripe.PaymentIntent.CaptureMethod;
|
|
282
|
-
client_secret: string | null;
|
|
283
|
-
confirmation_method: Stripe.PaymentIntent.ConfirmationMethod;
|
|
284
|
-
created: number;
|
|
285
|
-
currency: string;
|
|
286
|
-
description: string | null;
|
|
287
|
-
excluded_payment_method_types: Array<Stripe.PaymentIntent.ExcludedPaymentMethodType> | null;
|
|
288
|
-
last_payment_error: Stripe.PaymentIntent.LastPaymentError | null;
|
|
289
|
-
latest_charge: string | Stripe.Charge | null;
|
|
290
|
-
livemode: boolean;
|
|
291
|
-
next_action: Stripe.PaymentIntent.NextAction | null;
|
|
292
|
-
on_behalf_of: string | Stripe.Account | null;
|
|
293
|
-
payment_method_configuration_details: Stripe.PaymentIntent.PaymentMethodConfigurationDetails | null;
|
|
294
|
-
payment_method_options: Stripe.PaymentIntent.PaymentMethodOptions | null;
|
|
295
|
-
payment_method_types: Array<string>;
|
|
296
|
-
presentment_details?: Stripe.PaymentIntent.PresentmentDetails;
|
|
297
|
-
processing: Stripe.PaymentIntent.Processing | null;
|
|
298
|
-
receipt_email: string | null;
|
|
299
|
-
review: string | Stripe.Review | null;
|
|
300
|
-
setup_future_usage: Stripe.PaymentIntent.SetupFutureUsage | null;
|
|
301
|
-
shipping: Stripe.PaymentIntent.Shipping | null;
|
|
302
|
-
source: string | Stripe.CustomerSource | Stripe.DeletedCustomerSource | null;
|
|
303
|
-
statement_descriptor: string | null;
|
|
304
|
-
statement_descriptor_suffix: string | null;
|
|
305
|
-
status: Stripe.PaymentIntent.Status;
|
|
306
|
-
transfer_data: Stripe.PaymentIntent.TransferData | null;
|
|
307
|
-
transfer_group: string | null;
|
|
308
|
-
};
|
|
309
|
-
type MappedCart = ReturnType<typeof mapCart>;
|
|
310
|
-
/**
|
|
311
|
-
* @internal
|
|
312
|
-
*/
|
|
313
|
-
declare function mapOrder({ payment_method, latest_charge, ...order }: Stripe.PaymentIntent): {
|
|
314
|
-
payment_method: Stripe.PaymentMethod | null;
|
|
315
|
-
latest_charge: Stripe.Charge | null;
|
|
316
|
-
taxBreakdown: ({
|
|
317
|
-
taxType: Stripe.Tax.Calculation.TaxBreakdown.TaxRateDetails.TaxType | (string & {});
|
|
318
|
-
taxPercentage: string;
|
|
319
|
-
taxAmount: number;
|
|
320
|
-
} | null)[];
|
|
321
|
-
metadata: {
|
|
322
|
-
shippingRateId?: string | undefined;
|
|
323
|
-
taxCalculationId?: string | undefined;
|
|
324
|
-
taxCalculationExp?: string | undefined;
|
|
325
|
-
taxId?: string | undefined;
|
|
326
|
-
couponCode?: string | undefined;
|
|
327
|
-
taxedAmount?: string | undefined;
|
|
328
|
-
"billingAddress.city"?: string | undefined;
|
|
329
|
-
"billingAddress.country"?: string | undefined;
|
|
330
|
-
"billingAddress.line1"?: string | undefined;
|
|
331
|
-
"billingAddress.line2"?: string | undefined;
|
|
332
|
-
"billingAddress.name"?: string | undefined;
|
|
333
|
-
"billingAddress.postalCode"?: string | undefined;
|
|
334
|
-
"billingAddress.state"?: string | undefined;
|
|
335
|
-
netAmount?: string | undefined;
|
|
336
|
-
taxBreakdown0?: string | undefined;
|
|
337
|
-
taxBreakdown1?: string | undefined;
|
|
338
|
-
taxBreakdown2?: string | undefined;
|
|
339
|
-
taxBreakdown3?: string | undefined;
|
|
340
|
-
taxBreakdown4?: string | undefined;
|
|
341
|
-
taxBreakdown5?: string | undefined;
|
|
342
|
-
} & Record<string, string>;
|
|
343
|
-
id: string;
|
|
344
|
-
object: "payment_intent";
|
|
345
|
-
amount: number;
|
|
346
|
-
amount_capturable: number;
|
|
347
|
-
amount_details?: Stripe.PaymentIntent.AmountDetails;
|
|
348
|
-
amount_received: number;
|
|
349
|
-
application: string | Stripe.Application | null;
|
|
350
|
-
application_fee_amount: number | null;
|
|
351
|
-
automatic_payment_methods: Stripe.PaymentIntent.AutomaticPaymentMethods | null;
|
|
352
|
-
canceled_at: number | null;
|
|
353
|
-
cancellation_reason: Stripe.PaymentIntent.CancellationReason | null;
|
|
354
|
-
capture_method: Stripe.PaymentIntent.CaptureMethod;
|
|
355
|
-
client_secret: string | null;
|
|
356
|
-
confirmation_method: Stripe.PaymentIntent.ConfirmationMethod;
|
|
357
|
-
created: number;
|
|
358
|
-
currency: string;
|
|
359
|
-
customer: string | Stripe.Customer | Stripe.DeletedCustomer | null;
|
|
360
|
-
description: string | null;
|
|
361
|
-
excluded_payment_method_types: Array<Stripe.PaymentIntent.ExcludedPaymentMethodType> | null;
|
|
362
|
-
last_payment_error: Stripe.PaymentIntent.LastPaymentError | null;
|
|
363
|
-
livemode: boolean;
|
|
364
|
-
next_action: Stripe.PaymentIntent.NextAction | null;
|
|
365
|
-
on_behalf_of: string | Stripe.Account | null;
|
|
366
|
-
payment_method_configuration_details: Stripe.PaymentIntent.PaymentMethodConfigurationDetails | null;
|
|
367
|
-
payment_method_options: Stripe.PaymentIntent.PaymentMethodOptions | null;
|
|
368
|
-
payment_method_types: Array<string>;
|
|
369
|
-
presentment_details?: Stripe.PaymentIntent.PresentmentDetails;
|
|
370
|
-
processing: Stripe.PaymentIntent.Processing | null;
|
|
371
|
-
receipt_email: string | null;
|
|
372
|
-
review: string | Stripe.Review | null;
|
|
373
|
-
setup_future_usage: Stripe.PaymentIntent.SetupFutureUsage | null;
|
|
374
|
-
shipping: Stripe.PaymentIntent.Shipping | null;
|
|
375
|
-
source: string | Stripe.CustomerSource | Stripe.DeletedCustomerSource | null;
|
|
376
|
-
statement_descriptor: string | null;
|
|
377
|
-
statement_descriptor_suffix: string | null;
|
|
378
|
-
status: Stripe.PaymentIntent.Status;
|
|
379
|
-
transfer_data: Stripe.PaymentIntent.TransferData | null;
|
|
380
|
-
transfer_group: string | null;
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
export { type CartMetadata, type MappedCart, type MappedProduct, type MappedShippingRate, type ProductMetadata, cartMetadataSchema, cartMetadataTaxBreakdownSchema, filterValidProduct, filterValidProducts, getUniqueVariants, isProductAvailable, mapCart, mapOrder, mapProduct, mapProducts, mapShippingRate, mapShippingRates, objectToStripeQuery, sanitizeQueryValue, sortProducts };
|
package/dist/internal.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{z as e}from"zod";function i(t,r){if(!t)throw new Error(r)}var d=t=>{if(t==null)return null;try{return JSON.parse(t)}catch{return null}};var m=t=>t.toString().replace(/\\/g,"\\\\").replace(/"/g,'\\"'),S=t=>Object.entries(t).map(([r,n])=>`${r}:"${m(n)}"`).join(" AND ").trim();function N(t){return t.toSorted((r,n)=>{let a=Number(r.metadata.order),o=Number(n.metadata.order);return Number.isNaN(a)&&Number.isNaN(o)||a===o?n.updated-r.updated:Number.isNaN(a)?1:Number.isNaN(o)?-1:a-o})}var g=e.object({category:e.string().optional(),order:e.coerce.number().optional(),slug:e.string(),variant:e.string().optional(),stock:e.coerce.number().optional().transform(t=>t===void 0?Number.POSITIVE_INFINITY:t),digitalAsset:e.string().optional(),preview:e.string().optional()});function f({default_price:t,marketing_features:r,...n}){return i(t,"Product must have a default price"),i(typeof t=="object","Product default price must be an object"),{...n,default_price:t,marketing_features:r.map(a=>a.name).filter(Boolean),metadata:g.parse(n.metadata)}}function x(t){return!!(t.active&&!t.deleted&&t.default_price)}function T(t){return{...t,data:t.data.filter(x)}}function k(t){return t.data.map(f)}function b(t){return t}function A(t){return t.data.map(b)}function B(t){return t.filter((r,n,a)=>n===a.findIndex(o=>o.metadata.slug===r.metadata.slug))}var R=t=>!t.deleted&&t.active,l=e.object({shippingRateId:e.string().optional(),taxCalculationId:e.string().optional(),taxCalculationExp:e.string().optional(),taxId:e.string().optional(),couponCode:e.string().optional(),taxedAmount:e.string().optional(),"billingAddress.city":e.string().optional(),"billingAddress.country":e.string().optional(),"billingAddress.line1":e.string().optional(),"billingAddress.line2":e.string().optional(),"billingAddress.name":e.string().optional(),"billingAddress.postalCode":e.string().optional(),"billingAddress.state":e.string().optional(),netAmount:e.string().optional(),taxBreakdown0:e.string().optional(),taxBreakdown1:e.string().optional(),taxBreakdown2:e.string().optional(),taxBreakdown3:e.string().optional(),taxBreakdown4:e.string().optional(),taxBreakdown5:e.string().optional()}).and(e.record(e.string(),e.string())),c=e.object({taxType:e.string(),taxPercentage:e.string(),taxAmount:e.number()});function I(t){let r=t.payment_method;i(typeof r!="string","Payment method should not be a string");let n=t.customer;i(typeof n!="string"&&!n?.deleted,"Customer should not be a string");let a=l.parse(t.metadata),o=Object.entries(a).filter(([s])=>s.startsWith("taxBreakdown")).map(([s,u])=>{let p=c.safeParse(d(String(u)));return p.success?p.data:null}).filter(Boolean);return{...t,metadata:a,customer:n,payment_method:r,taxBreakdown:o}}function M({payment_method:t,latest_charge:r,...n}){i(typeof t=="object","Payment method is missing from order"),i(typeof r=="object","Latest charge is missing from order");let a=l.parse(n.metadata),o=Object.entries(a).filter(([s])=>s.startsWith("taxBreakdown")).map(([s,u])=>{let p=c.safeParse(d(String(u)));return p.success?p.data:null}).filter(Boolean);return{...n,payment_method:t,latest_charge:r,taxBreakdown:o,metadata:a}}export{l as cartMetadataSchema,c as cartMetadataTaxBreakdownSchema,x as filterValidProduct,T as filterValidProducts,B as getUniqueVariants,R as isProductAvailable,I as mapCart,M as mapOrder,f as mapProduct,k as mapProducts,b as mapShippingRate,A as mapShippingRates,S as objectToStripeQuery,m as sanitizeQueryValue,N as sortProducts};
|