commerce-kit 0.1.0 → 0.2.0
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/README.md +150 -59
- package/dist/index.d.ts +5 -1173
- package/dist/index.js +13 -22
- package/dist/provider-CvZe8Dqo.d.ts +140 -0
- package/dist/stripe.d.ts +77 -0
- package/dist/stripe.js +1 -0
- package/dist/yns-context.d.ts +22 -0
- package/dist/yns-context.js +1 -0
- package/dist/yns.d.ts +95 -18
- package/dist/yns.js +238 -1
- package/package.json +16 -8
package/dist/yns.js
CHANGED
|
@@ -1 +1,238 @@
|
|
|
1
|
-
var
|
|
1
|
+
var h=Object.defineProperty;var c=(i,r)=>()=>(i&&(r=i(i=0)),r);var f=(i,r)=>{for(var t in r)h(i,t,{get:r[t],enumerable:!0})};function l(i){return!i||i.length===0?d:`
|
|
2
|
+
query ProductQuery($slug: String!) {
|
|
3
|
+
product(slug: $slug) {
|
|
4
|
+
${i.join(`
|
|
5
|
+
`)}
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
`}function P(i){return!i||i.length===0?n:`
|
|
9
|
+
query ProductsQuery(
|
|
10
|
+
$offset: Int
|
|
11
|
+
$limit: Int
|
|
12
|
+
$category: String
|
|
13
|
+
$query: String
|
|
14
|
+
$active: Boolean
|
|
15
|
+
$excludeBundles: Boolean
|
|
16
|
+
$orderBy: String
|
|
17
|
+
$orderDirection: String
|
|
18
|
+
) {
|
|
19
|
+
products(
|
|
20
|
+
offset: $offset
|
|
21
|
+
limit: $limit
|
|
22
|
+
category: $category
|
|
23
|
+
query: $query
|
|
24
|
+
active: $active
|
|
25
|
+
excludeBundles: $excludeBundles
|
|
26
|
+
orderBy: $orderBy
|
|
27
|
+
orderDirection: $orderDirection
|
|
28
|
+
) {
|
|
29
|
+
data {
|
|
30
|
+
${i.join(`
|
|
31
|
+
`)}
|
|
32
|
+
}
|
|
33
|
+
meta {
|
|
34
|
+
count
|
|
35
|
+
offset
|
|
36
|
+
limit
|
|
37
|
+
hasMore
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
`}var u,n,d,$,p,g=c(()=>{"use strict";u=`
|
|
42
|
+
fragment ProductFragment on Product {
|
|
43
|
+
id
|
|
44
|
+
name
|
|
45
|
+
slug
|
|
46
|
+
summary
|
|
47
|
+
images
|
|
48
|
+
active
|
|
49
|
+
type
|
|
50
|
+
createdAt
|
|
51
|
+
updatedAt
|
|
52
|
+
category {
|
|
53
|
+
id
|
|
54
|
+
name
|
|
55
|
+
slug
|
|
56
|
+
description
|
|
57
|
+
image
|
|
58
|
+
}
|
|
59
|
+
variants {
|
|
60
|
+
id
|
|
61
|
+
price
|
|
62
|
+
originalPrice
|
|
63
|
+
prePromotionPrice
|
|
64
|
+
stock
|
|
65
|
+
shippable
|
|
66
|
+
attributes
|
|
67
|
+
combinations {
|
|
68
|
+
id
|
|
69
|
+
variantValue {
|
|
70
|
+
id
|
|
71
|
+
value
|
|
72
|
+
colorValue
|
|
73
|
+
variantType {
|
|
74
|
+
id
|
|
75
|
+
label
|
|
76
|
+
type
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
collections {
|
|
82
|
+
id
|
|
83
|
+
name
|
|
84
|
+
slug
|
|
85
|
+
description
|
|
86
|
+
image
|
|
87
|
+
active
|
|
88
|
+
}
|
|
89
|
+
bundleProducts {
|
|
90
|
+
id
|
|
91
|
+
quantity
|
|
92
|
+
position
|
|
93
|
+
variant {
|
|
94
|
+
id
|
|
95
|
+
price
|
|
96
|
+
originalPrice
|
|
97
|
+
stock
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
bundleDiscountPercentage
|
|
101
|
+
}
|
|
102
|
+
`,n=`
|
|
103
|
+
query ProductsQuery(
|
|
104
|
+
$offset: Int
|
|
105
|
+
$limit: Int
|
|
106
|
+
$category: String
|
|
107
|
+
$query: String
|
|
108
|
+
$active: Boolean
|
|
109
|
+
$excludeBundles: Boolean
|
|
110
|
+
$orderBy: String
|
|
111
|
+
$orderDirection: String
|
|
112
|
+
) {
|
|
113
|
+
products(
|
|
114
|
+
offset: $offset
|
|
115
|
+
limit: $limit
|
|
116
|
+
category: $category
|
|
117
|
+
query: $query
|
|
118
|
+
active: $active
|
|
119
|
+
excludeBundles: $excludeBundles
|
|
120
|
+
orderBy: $orderBy
|
|
121
|
+
orderDirection: $orderDirection
|
|
122
|
+
) {
|
|
123
|
+
data {
|
|
124
|
+
...ProductFragment
|
|
125
|
+
}
|
|
126
|
+
meta {
|
|
127
|
+
count
|
|
128
|
+
offset
|
|
129
|
+
limit
|
|
130
|
+
hasMore
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
${u}
|
|
135
|
+
`,d=`
|
|
136
|
+
query ProductQuery($slug: String!) {
|
|
137
|
+
product(slug: $slug) {
|
|
138
|
+
...ProductFragment
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
${u}
|
|
142
|
+
`,$=`
|
|
143
|
+
fragment CartFragment on Cart {
|
|
144
|
+
id
|
|
145
|
+
customerId
|
|
146
|
+
storeId
|
|
147
|
+
shippingId
|
|
148
|
+
couponId
|
|
149
|
+
billingAddressId
|
|
150
|
+
shippingAddressId
|
|
151
|
+
stripePaymentIntentId
|
|
152
|
+
checkoutSessionId
|
|
153
|
+
addonData
|
|
154
|
+
createdAt
|
|
155
|
+
updatedAt
|
|
156
|
+
customer {
|
|
157
|
+
id
|
|
158
|
+
email
|
|
159
|
+
userId
|
|
160
|
+
user {
|
|
161
|
+
id
|
|
162
|
+
email
|
|
163
|
+
name
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
coupon {
|
|
167
|
+
code
|
|
168
|
+
type
|
|
169
|
+
value
|
|
170
|
+
startDate
|
|
171
|
+
endDate
|
|
172
|
+
}
|
|
173
|
+
lineItems {
|
|
174
|
+
id
|
|
175
|
+
cartId
|
|
176
|
+
productVariantId
|
|
177
|
+
subscriptionId
|
|
178
|
+
quantity
|
|
179
|
+
createdAt
|
|
180
|
+
updatedAt
|
|
181
|
+
productVariant {
|
|
182
|
+
id
|
|
183
|
+
price
|
|
184
|
+
originalPrice
|
|
185
|
+
stock
|
|
186
|
+
shippable
|
|
187
|
+
attributes
|
|
188
|
+
}
|
|
189
|
+
subscription {
|
|
190
|
+
id
|
|
191
|
+
name
|
|
192
|
+
price
|
|
193
|
+
interval
|
|
194
|
+
intervalCount
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
billingAddress {
|
|
198
|
+
id
|
|
199
|
+
name
|
|
200
|
+
company
|
|
201
|
+
line1
|
|
202
|
+
line2
|
|
203
|
+
city
|
|
204
|
+
state
|
|
205
|
+
postalCode
|
|
206
|
+
country
|
|
207
|
+
phone
|
|
208
|
+
type
|
|
209
|
+
}
|
|
210
|
+
shippingAddress {
|
|
211
|
+
id
|
|
212
|
+
name
|
|
213
|
+
company
|
|
214
|
+
line1
|
|
215
|
+
line2
|
|
216
|
+
city
|
|
217
|
+
state
|
|
218
|
+
postalCode
|
|
219
|
+
country
|
|
220
|
+
phone
|
|
221
|
+
type
|
|
222
|
+
}
|
|
223
|
+
shipping {
|
|
224
|
+
id
|
|
225
|
+
name
|
|
226
|
+
price
|
|
227
|
+
minValue
|
|
228
|
+
maxValue
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
`,p=`
|
|
232
|
+
query CartQuery($id: String!) {
|
|
233
|
+
cart(id: $id) {
|
|
234
|
+
...CartFragment
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
${$}
|
|
238
|
+
`});var m={};f(m,{YnsProvider:()=>s,createYnsProvider:()=>w});function w(i){return new s(i)}var s,v=c(()=>{"use strict";g();s=class{config;constructor(r){this.config=r}async graphqlRequest(r,t){let o=await fetch(`${this.config.endpoint}/api/graphql`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.config.token}`},body:JSON.stringify({query:r,variables:t})});if(!o.ok)throw new Error(`YNS GraphQL request failed: ${o.status} ${o.statusText}`);let e=await o.json();if(e.errors)throw new Error(`YNS GraphQL errors: ${JSON.stringify(e.errors)}`);return e.data}async restRequest(r,t="GET",o){let e=await fetch(`${this.config.endpoint}/api${r}`,{method:t,headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.config.token}`},body:o?JSON.stringify(o):void 0});if(!e.ok)throw new Error(`YNS REST request failed: ${e.status} ${e.statusText}`);return e.json()}mapYnsProduct(r){return{id:r.id,name:r.name,slug:r.slug,summary:r.summary,images:r.images||[],active:r.active,price:r.variants?.[0]?.price?Number.parseFloat(r.variants[0].price):0,currency:"USD",stock:r.variants?.[0]?.stock,category:r.category,variants:r.variants?.map(t=>({id:t.id,price:Number.parseFloat(t.price),stock:t.stock,attributes:t.attributes}))||[]}}mapYnsCart(r){let t=r.lineItems?.map(e=>({id:e.id,productId:e.productVariant?.id||"",variantId:e.productVariantId,quantity:e.quantity,price:Number.parseFloat(e.productVariant?.price||"0")}))||[],o=t.reduce((e,a)=>e+a.price*a.quantity,0);return{id:r.id,customerId:r.customerId,items:t,total:o,currency:"USD",createdAt:r.createdAt,updatedAt:r.updatedAt}}async productBrowse(r){let t=r.fields?P(r.fields):n,o={offset:r.offset||0,limit:r.first||r.offset||10,category:r.category,query:r.query,active:r.active,excludeBundles:!1,orderBy:r.orderBy,orderDirection:r.orderDirection},e=await this.graphqlRequest(t,o);return{data:e.products.data.map(a=>this.mapYnsProduct(a)),meta:e.products.meta}}async productGet(r){if(!r.slug&&!r.id)throw new Error("Either slug or id is required for productGet");let t=r.fields?l(r.fields):d,o={slug:r.slug},e=await this.graphqlRequest(t,o);return e.product?this.mapYnsProduct(e.product):null}async cartAdd(r){let t={variantId:r.variantId,cartId:r.cartId,subscriptionId:r.subscriptionId};return await this.restRequest("/cart","POST",t)}async cartUpdate(r){let t={variantId:r.variantId,quantity:r.quantity};return await this.restRequest(`/cart/${r.cartId}`,"PUT",t)}async cartClear(r){return await this.restRequest(`/cart/${r.cartId}`,"DELETE")}async cartGet(r){let t=await this.graphqlRequest(p,{id:r.cartId});return t.cart?this.mapYnsCart(t.cart):null}}});var y=class{config;provider;providerPromise;constructor(r){if(this.config=r||this.detectFromEnv(),!this.config.endpoint||!this.config.token)throw new Error("YNS configuration required. Provide endpoint and token in constructor or set YNS_ENDPOINT and YNS_TOKEN environment variables.")}detectFromEnv(){return{endpoint:process.env.YNS_ENDPOINT||"",token:process.env.YNS_TOKEN||""}}async getProvider(){return this.provider?this.provider:(this.providerPromise||(this.providerPromise=this.loadProvider()),this.provider=await this.providerPromise,this.provider)}async loadProvider(){try{let{createYnsProvider:r}=await Promise.resolve().then(()=>(v(),m));return r(this.config)}catch(r){throw new Error(`Failed to initialize YNS provider: ${r instanceof Error?r.message:"Unknown error"}`)}}get product(){return{browse:async(r={})=>(await this.getProvider()).productBrowse(r),get:async r=>(await this.getProvider()).productGet(r),search:async r=>{let t=await this.getProvider();if(!t.productSearch)throw new Error("Product search is not supported by YNS provider");return t.productSearch(r)}}}get cart(){return{add:async r=>(await this.getProvider()).cartAdd(r),update:async r=>(await this.getProvider()).cartUpdate(r),clear:async r=>(await this.getProvider()).cartClear(r),get:async r=>(await this.getProvider()).cartGet(r)}}get order(){return{get:async r=>{let t=await this.getProvider();if(!t.orderGet)throw new Error("Order retrieval is not supported by YNS provider");return t.orderGet(r)},list:async(r={})=>{let t=await this.getProvider();if(!t.orderList)throw new Error("Order listing is not supported by YNS provider");return t.orderList(r)}}}};export{y as Commerce};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "commerce-kit",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
7
7
|
"keywords": [
|
|
@@ -23,6 +23,14 @@
|
|
|
23
23
|
"import": "./dist/index.js",
|
|
24
24
|
"types": "./dist/index.d.ts"
|
|
25
25
|
},
|
|
26
|
+
"./yns": {
|
|
27
|
+
"import": "./dist/yns.js",
|
|
28
|
+
"types": "./dist/yns.d.ts"
|
|
29
|
+
},
|
|
30
|
+
"./stripe": {
|
|
31
|
+
"import": "./dist/stripe.js",
|
|
32
|
+
"types": "./dist/stripe.d.ts"
|
|
33
|
+
},
|
|
26
34
|
"./currencies": {
|
|
27
35
|
"import": "./dist/currencies.js",
|
|
28
36
|
"types": "./dist/currencies.d.ts"
|
|
@@ -31,9 +39,9 @@
|
|
|
31
39
|
"import": "./dist/internal.js",
|
|
32
40
|
"types": "./dist/internal.d.ts"
|
|
33
41
|
},
|
|
34
|
-
"./yns": {
|
|
35
|
-
"import": "./dist/yns.js",
|
|
36
|
-
"types": "./dist/yns.d.ts"
|
|
42
|
+
"./yns-context": {
|
|
43
|
+
"import": "./dist/yns-context.js",
|
|
44
|
+
"types": "./dist/yns-context.d.ts"
|
|
37
45
|
},
|
|
38
46
|
"./db": {
|
|
39
47
|
"import": "./dist/db.js",
|
|
@@ -51,12 +59,13 @@
|
|
|
51
59
|
"build": "biome check && rimraf dist/* && tsup --config tsup.config.ts",
|
|
52
60
|
"prepublishOnly": "bun run build",
|
|
53
61
|
"dev": "tsup --config tsup.config.ts --watch",
|
|
54
|
-
"lint": "biome check --write --unsafe"
|
|
62
|
+
"lint": "biome check --write --unsafe",
|
|
63
|
+
"test": "bun test"
|
|
55
64
|
},
|
|
56
65
|
"devDependencies": {
|
|
57
|
-
"@biomejs/biome": "2.2.
|
|
66
|
+
"@biomejs/biome": "2.2.3",
|
|
58
67
|
"@neondatabase/serverless": "^1.0.1",
|
|
59
|
-
"@types/node": "^24.3.
|
|
68
|
+
"@types/node": "^24.3.1",
|
|
60
69
|
"@types/react": "^19.1.12",
|
|
61
70
|
"@types/react-dom": "^19.1.9",
|
|
62
71
|
"next": "15.5.2",
|
|
@@ -67,7 +76,6 @@
|
|
|
67
76
|
"stripe": "^18.5.0",
|
|
68
77
|
"tsup": "8.5.0",
|
|
69
78
|
"tsx": "^4.20.5",
|
|
70
|
-
"vitest": "^3.2.4",
|
|
71
79
|
"zod": "^4.1.5"
|
|
72
80
|
},
|
|
73
81
|
"peerDependencies": {
|