commerce-kit 0.0.18 → 0.0.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.
@@ -0,0 +1,263 @@
1
+ import { z } from 'zod';
2
+
3
+ declare const configSchema: z.ZodObject<{
4
+ hero: z.ZodObject<{
5
+ show: z.ZodBoolean;
6
+ title: z.ZodString;
7
+ description: z.ZodString;
8
+ button: z.ZodObject<{
9
+ label: z.ZodString;
10
+ path: z.ZodString;
11
+ }, "strip", z.ZodTypeAny, {
12
+ path: string;
13
+ label: string;
14
+ }, {
15
+ path: string;
16
+ label: string;
17
+ }>;
18
+ image: z.ZodObject<{
19
+ src: z.ZodString;
20
+ alt: z.ZodString;
21
+ }, "strip", z.ZodTypeAny, {
22
+ src: string;
23
+ alt: string;
24
+ }, {
25
+ src: string;
26
+ alt: string;
27
+ }>;
28
+ }, "strip", z.ZodTypeAny, {
29
+ show: boolean;
30
+ title: string;
31
+ description: string;
32
+ button: {
33
+ path: string;
34
+ label: string;
35
+ };
36
+ image: {
37
+ src: string;
38
+ alt: string;
39
+ };
40
+ }, {
41
+ show: boolean;
42
+ title: string;
43
+ description: string;
44
+ button: {
45
+ path: string;
46
+ label: string;
47
+ };
48
+ image: {
49
+ src: string;
50
+ alt: string;
51
+ };
52
+ }>;
53
+ categorySection: z.ZodObject<{
54
+ show: z.ZodBoolean;
55
+ }, "strip", z.ZodTypeAny, {
56
+ show: boolean;
57
+ }, {
58
+ show: boolean;
59
+ }>;
60
+ nav: z.ZodObject<{
61
+ title: z.ZodString;
62
+ searchBar: z.ZodObject<{
63
+ show: z.ZodBoolean;
64
+ }, "strip", z.ZodTypeAny, {
65
+ show: boolean;
66
+ }, {
67
+ show: boolean;
68
+ }>;
69
+ links: z.ZodArray<z.ZodObject<{
70
+ label: z.ZodString;
71
+ href: z.ZodString;
72
+ }, "strip", z.ZodTypeAny, {
73
+ label: string;
74
+ href: string;
75
+ }, {
76
+ label: string;
77
+ href: string;
78
+ }>, "many">;
79
+ }, "strip", z.ZodTypeAny, {
80
+ title: string;
81
+ searchBar: {
82
+ show: boolean;
83
+ };
84
+ links: {
85
+ label: string;
86
+ href: string;
87
+ }[];
88
+ }, {
89
+ title: string;
90
+ searchBar: {
91
+ show: boolean;
92
+ };
93
+ links: {
94
+ label: string;
95
+ href: string;
96
+ }[];
97
+ }>;
98
+ footer: z.ZodObject<{
99
+ name: z.ZodString;
100
+ tagline: z.ZodString;
101
+ newsletter: z.ZodObject<{
102
+ show: z.ZodBoolean;
103
+ }, "strip", z.ZodTypeAny, {
104
+ show: boolean;
105
+ }, {
106
+ show: boolean;
107
+ }>;
108
+ credits: z.ZodBoolean;
109
+ sections: z.ZodArray<z.ZodObject<{
110
+ header: z.ZodString;
111
+ links: z.ZodArray<z.ZodObject<{
112
+ label: z.ZodString;
113
+ href: z.ZodString;
114
+ }, "strip", z.ZodTypeAny, {
115
+ label: string;
116
+ href: string;
117
+ }, {
118
+ label: string;
119
+ href: string;
120
+ }>, "many">;
121
+ }, "strip", z.ZodTypeAny, {
122
+ links: {
123
+ label: string;
124
+ href: string;
125
+ }[];
126
+ header: string;
127
+ }, {
128
+ links: {
129
+ label: string;
130
+ href: string;
131
+ }[];
132
+ header: string;
133
+ }>, "many">;
134
+ }, "strip", z.ZodTypeAny, {
135
+ name: string;
136
+ tagline: string;
137
+ newsletter: {
138
+ show: boolean;
139
+ };
140
+ credits: boolean;
141
+ sections: {
142
+ links: {
143
+ label: string;
144
+ href: string;
145
+ }[];
146
+ header: string;
147
+ }[];
148
+ }, {
149
+ name: string;
150
+ tagline: string;
151
+ newsletter: {
152
+ show: boolean;
153
+ };
154
+ credits: boolean;
155
+ sections: {
156
+ links: {
157
+ label: string;
158
+ href: string;
159
+ }[];
160
+ header: string;
161
+ }[];
162
+ }>;
163
+ pages: z.ZodRecord<z.ZodString, z.ZodObject<{
164
+ content: z.ZodString;
165
+ }, "strip", z.ZodTypeAny, {
166
+ content: string;
167
+ }, {
168
+ content: string;
169
+ }>>;
170
+ }, "strip", z.ZodTypeAny, {
171
+ hero: {
172
+ show: boolean;
173
+ title: string;
174
+ description: string;
175
+ button: {
176
+ path: string;
177
+ label: string;
178
+ };
179
+ image: {
180
+ src: string;
181
+ alt: string;
182
+ };
183
+ };
184
+ categorySection: {
185
+ show: boolean;
186
+ };
187
+ nav: {
188
+ title: string;
189
+ searchBar: {
190
+ show: boolean;
191
+ };
192
+ links: {
193
+ label: string;
194
+ href: string;
195
+ }[];
196
+ };
197
+ footer: {
198
+ name: string;
199
+ tagline: string;
200
+ newsletter: {
201
+ show: boolean;
202
+ };
203
+ credits: boolean;
204
+ sections: {
205
+ links: {
206
+ label: string;
207
+ href: string;
208
+ }[];
209
+ header: string;
210
+ }[];
211
+ };
212
+ pages: Record<string, {
213
+ content: string;
214
+ }>;
215
+ }, {
216
+ hero: {
217
+ show: boolean;
218
+ title: string;
219
+ description: string;
220
+ button: {
221
+ path: string;
222
+ label: string;
223
+ };
224
+ image: {
225
+ src: string;
226
+ alt: string;
227
+ };
228
+ };
229
+ categorySection: {
230
+ show: boolean;
231
+ };
232
+ nav: {
233
+ title: string;
234
+ searchBar: {
235
+ show: boolean;
236
+ };
237
+ links: {
238
+ label: string;
239
+ href: string;
240
+ }[];
241
+ };
242
+ footer: {
243
+ name: string;
244
+ tagline: string;
245
+ newsletter: {
246
+ show: boolean;
247
+ };
248
+ credits: boolean;
249
+ sections: {
250
+ links: {
251
+ label: string;
252
+ href: string;
253
+ }[];
254
+ header: string;
255
+ }[];
256
+ };
257
+ pages: Record<string, {
258
+ content: string;
259
+ }>;
260
+ }>;
261
+ type Config = z.infer<typeof configSchema>;
262
+
263
+ export { type Config, configSchema };
@@ -0,0 +1 @@
1
+ import{z as t}from"zod";var o=t.object({hero:t.object({show:t.boolean(),title:t.string(),description:t.string(),button:t.object({label:t.string(),path:t.string()}),image:t.object({src:t.string(),alt:t.string()})}),categorySection:t.object({show:t.boolean()}),nav:t.object({title:t.string(),searchBar:t.object({show:t.boolean()}),links:t.array(t.object({label:t.string(),href:t.string()}))}),footer:t.object({name:t.string(),tagline:t.string(),newsletter:t.object({show:t.boolean()}),credits:t.boolean(),sections:t.array(t.object({header:t.string(),links:t.array(t.object({label:t.string(),href:t.string()}))}))}),pages:t.record(t.string(),t.object({content:t.string()}))});export{o as configSchema};
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { CartMetadata, MappedCart } from './internal.js';
2
2
  export { MappedProduct, MappedShippingRate } from './internal.js';
3
- import { Config } from './yns.js';
3
+ import { Config } from './browser.js';
4
4
  import Stripe from 'stripe';
5
5
  import { z, TypeOf } from 'zod';
6
6
 
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import"server-only";import"server-only";import{z as u}from"zod";function S(t,e){if(!t)throw new Error(e)}var H=async t=>{try{return[null,await t]}catch(e){return[e instanceof Error?e:new Error(String(e)),null]}},$=t=>{if(t==null)return 0;if(typeof t=="number")return t;let e=Number.parseInt(t,10);return Number.isNaN(e)?0:e},U=t=>{if(t==null)return null;try{return JSON.parse(t)}catch{return null}};var dt=t=>t.toString().replace(/\\/g,"\\\\").replace(/"/g,'\\"'),D=t=>Object.entries(t).map(([e,n])=>`${e}:"${dt(n)}"`).join(" AND ").trim();function G(t){return t.toSorted((e,n)=>{let a=Number(e.metadata.order),i=Number(n.metadata.order);return Number.isNaN(a)&&Number.isNaN(i)||a===i?n.updated-e.updated:Number.isNaN(a)?1:Number.isNaN(i)?-1:a-i})}var pt=u.object({category:u.string().optional(),order:u.coerce.number().optional(),slug:u.string(),variant:u.string().optional()});function M({default_price:t,marketing_features:e,...n}){return S(t,"Product must have a default price"),S(typeof t=="object","Product default price must be an object"),{...n,default_price:t,marketing_features:e.map(a=>a.name).filter(Boolean),metadata:pt.parse(n.metadata)}}function j(t){return t.data.map(M)}function z(t){return t}function J(t){return t.data.map(z)}function Y(t){return t.filter((e,n,a)=>n===a.findIndex(i=>i.metadata.slug===e.metadata.slug))}var W=t=>!t.deleted&&t.active,O=u.object({shippingRateId:u.string().optional(),taxCalculationId:u.string().optional(),taxCalculationExp:u.string().optional(),taxId:u.string().optional(),"billingAddress.city":u.string().optional(),"billingAddress.country":u.string().optional(),"billingAddress.line1":u.string().optional(),"billingAddress.line2":u.string().optional(),"billingAddress.name":u.string().optional(),"billingAddress.postalCode":u.string().optional(),"billingAddress.state":u.string().optional(),netAmount:u.string().optional(),taxBreakdown0:u.string().optional(),taxBreakdown1:u.string().optional(),taxBreakdown2:u.string().optional(),taxBreakdown3:u.string().optional(),taxBreakdown4:u.string().optional(),taxBreakdown5:u.string().optional()}).and(u.record(u.string())),X=u.object({taxType:u.string(),taxPercentage:u.string(),taxAmount:u.number()});function Q(t){let e=t.payment_method;S(typeof e!="string","Payment method is missing from cart");let n=O.parse(t.metadata),a=Object.entries(n).filter(([i])=>i.startsWith("taxBreakdown")).map(([i,r])=>{let o=X.safeParse(U(String(r)));return o.success?o.data:null}).filter(Boolean);return{...t,metadata:n,payment_method:e,taxBreakdown:a}}function Z({payment_method:t,latest_charge:e,...n}){S(typeof t=="object","Payment method is missing from order"),S(typeof e=="object","Latest charge is missing from order");let a=O.parse(n.metadata),i=Object.entries(a).filter(([r])=>r.startsWith("taxBreakdown")).map(([r,o])=>{let c=X.safeParse(U(String(o)));return c.success?c.data:null}).filter(Boolean);return{...n,payment_method:t,latest_charge:e,taxBreakdown:i,metadata:a}}import"server-only";import{revalidatePath as rt,revalidateTag as T}from"next/cache";import R from"stripe";import{z as b}from"zod";import"server-only";import{z as s}from"zod";var Gt=s.object({hero:s.object({show:s.boolean(),title:s.string(),description:s.string(),button:s.object({label:s.string(),path:s.string()}),image:s.object({src:s.string(),alt:s.string()})}),categorySection:s.object({show:s.boolean()}),nav:s.object({title:s.string(),searchBar:s.object({show:s.boolean()}),links:s.array(s.object({label:s.string(),href:s.string()}))}),footer:s.object({name:s.string(),tagline:s.string(),newsletter:s.object({show:s.boolean()}),credits:s.boolean(),sections:s.array(s.object({header:s.string(),links:s.array(s.object({label:s.string(),href:s.string()}))}))}),pages:s.record(s.string(),s.object({content:s.string()}))}),l=async()=>{let t={hero:{show:!0,title:"Discover our Curated Collection",description:"Explore our carefully selected products for your home and lifestyle.",button:{label:"Shop Now",path:"/"},image:{src:"https://files.stripe.com/links/MDB8YWNjdF8xT3BaeG5GSmNWbVh6bURsfGZsX3Rlc3RfaDVvWXowdU9ZbWlobUIyaHpNc1hCeDM200NBzvUjqP",alt:"Cup of coffee"}},categorySection:{show:!0},nav:{title:"Your Next Store",searchBar:{show:!0},links:[{label:"Home",href:"/"},{label:"Apparel",href:"/category/apparel"},{label:"Accessories",href:"/category/accessories"}]},footer:{name:"Your Next Store",tagline:"Handcrafted with passion in California",newsletter:{show:!0},credits:!0,sections:[{header:"Products",links:[{label:"Apparel",href:"/category/apparel"},{label:"Accessories",href:"/category/accessories"}]},{header:"Support",links:[{label:"Features",href:"https://yournextstore.com/#features"},{label:"Pricing",href:"https://yournextstore.com/#pricing"},{label:"Contact Us",href:"mailto:hi@yournextstore.com"}]}]},pages:{"/about":{content:`# Header 1
1
+ import"server-only";import"server-only";import{z as c}from"zod";function S(t,e){if(!t)throw new Error(e)}var V=async t=>{try{return[null,await t]}catch(e){return[e instanceof Error?e:new Error(String(e)),null]}},N=t=>{if(t==null)return 0;if(typeof t=="number")return t;let e=Number.parseInt(t,10);return Number.isNaN(e)?0:e},U=t=>{if(t==null)return null;try{return JSON.parse(t)}catch{return null}};var ut=t=>t.toString().replace(/\\/g,"\\\\").replace(/"/g,'\\"'),j=t=>Object.entries(t).map(([e,n])=>`${e}:"${ut(n)}"`).join(" AND ").trim();function q(t){return t.toSorted((e,n)=>{let a=Number(e.metadata.order),i=Number(n.metadata.order);return Number.isNaN(a)&&Number.isNaN(i)||a===i?n.updated-e.updated:Number.isNaN(a)?1:Number.isNaN(i)?-1:a-i})}var dt=c.object({category:c.string().optional(),order:c.coerce.number().optional(),slug:c.string(),variant:c.string().optional()});function G({default_price:t,marketing_features:e,...n}){return S(t,"Product must have a default price"),S(typeof t=="object","Product default price must be an object"),{...n,default_price:t,marketing_features:e.map(a=>a.name).filter(Boolean),metadata:dt.parse(n.metadata)}}function M(t){return t.data.map(G)}function H(t){return t}function z(t){return t.data.map(H)}function D(t){return t.filter((e,n,a)=>n===a.findIndex(i=>i.metadata.slug===e.metadata.slug))}var W=t=>!t.deleted&&t.active,O=c.object({shippingRateId:c.string().optional(),taxCalculationId:c.string().optional(),taxCalculationExp:c.string().optional(),taxId:c.string().optional(),"billingAddress.city":c.string().optional(),"billingAddress.country":c.string().optional(),"billingAddress.line1":c.string().optional(),"billingAddress.line2":c.string().optional(),"billingAddress.name":c.string().optional(),"billingAddress.postalCode":c.string().optional(),"billingAddress.state":c.string().optional(),netAmount:c.string().optional(),taxBreakdown0:c.string().optional(),taxBreakdown1:c.string().optional(),taxBreakdown2:c.string().optional(),taxBreakdown3:c.string().optional(),taxBreakdown4:c.string().optional(),taxBreakdown5:c.string().optional()}).and(c.record(c.string())),J=c.object({taxType:c.string(),taxPercentage:c.string(),taxAmount:c.number()});function Y(t){let e=t.payment_method;S(typeof e!="string","Payment method is missing from cart");let n=O.parse(t.metadata),a=Object.entries(n).filter(([i])=>i.startsWith("taxBreakdown")).map(([i,r])=>{let o=J.safeParse(U(String(r)));return o.success?o.data:null}).filter(Boolean);return{...t,metadata:n,payment_method:e,taxBreakdown:a}}function X({payment_method:t,latest_charge:e,...n}){S(typeof t=="object","Payment method is missing from order"),S(typeof e=="object","Latest charge is missing from order");let a=O.parse(n.metadata),i=Object.entries(a).filter(([r])=>r.startsWith("taxBreakdown")).map(([r,o])=>{let s=J.safeParse(U(String(o)));return s.success?s.data:null}).filter(Boolean);return{...n,payment_method:t,latest_charge:e,taxBreakdown:i,metadata:a}}import"server-only";import{revalidatePath as et,revalidateTag as I}from"next/cache";import v from"stripe";import{z as _}from"zod";import"server-only";var p=async()=>{let t={hero:{show:!0,title:"Discover our Curated Collection",description:"Explore our carefully selected products for your home and lifestyle.",button:{label:"Shop Now",path:"/"},image:{src:"https://files.stripe.com/links/MDB8YWNjdF8xT3BaeG5GSmNWbVh6bURsfGZsX3Rlc3RfaDVvWXowdU9ZbWlobUIyaHpNc1hCeDM200NBzvUjqP",alt:"Cup of coffee"}},categorySection:{show:!0},nav:{title:"Your Next Store",searchBar:{show:!0},links:[{label:"Home",href:"/"},{label:"Apparel",href:"/category/apparel"},{label:"Accessories",href:"/category/accessories"}]},footer:{name:"Your Next Store",tagline:"Handcrafted with passion in California",newsletter:{show:!0},credits:!0,sections:[{header:"Products",links:[{label:"Apparel",href:"/category/apparel"},{label:"Accessories",href:"/category/accessories"}]},{header:"Support",links:[{label:"Features",href:"https://yournextstore.com/#features"},{label:"Pricing",href:"https://yournextstore.com/#pricing"},{label:"Contact Us",href:"mailto:hi@yournextstore.com"}]}]},pages:{"/about":{content:`# Header 1
2
2
 
3
3
  ## Header 2
4
4
 
@@ -23,13 +23,13 @@ function hello() {
23
23
  console.log('Hello world!');
24
24
  }
25
25
  \`\`\`
26
- `}}},e={stripeAccount:void 0,storeId:void 0,secretKey:void 0,config:t},n=await global?.__ynsFindStripeAccount?.();return n?{...n,config:n.config??t}:e};import"server-only";import et from"stripe";import"server-only";var lt=process.env.STRIPE_SECRET_KEY,tt=process.env.STRIPE_CURRENCY;if(!tt)throw new Error("Missing STRIPE_CURRENCY");var w={StripeSecretKey:lt,StripeCurrency:tt};var v={DEBUG:0,LOG:1,WARN:2,ERROR:3},mt="LOG",ft=process.env.LOG_LEVEL&&process.env.LOG_LEVEL in v?process.env.LOG_LEVEL:mt,E=v[ft],d={time(t){E>v.DEBUG||console.time(t)},timeEnd(t){E>v.DEBUG||console.timeEnd(t)},log(...t){E>v.LOG||console.log(...t)},dir(t,e){E>v.LOG||console.dir(t,e)},warn(...t){E>v.WARN||console.warn(...t)},error(...t){E>v.ERROR||console.error(...t)}};var gt=(t,e)=>!t||!e?t:[...t,`prefix-${e}`,...t.map(n=>`${e}-${n}`)],f=({tags:t,revalidate:e,cache:n,tagPrefix:a,secretKey:i})=>{let r=i??w.StripeSecretKey;if(!r)throw new Error("Missing `secretKey` parameter and `STRIPE_SECRET_KEY` env variable.");d.log(`Using Stripe secret key from ${i?"parameter":"env"}.`);let o=gt(t,a);return new et(r,{typescript:!0,apiVersion:"2024-06-20",httpClient:et.createFetchHttpClient((y,p)=>fetch(y,{...p,cache:n??p?.cache,next:{tags:o??p?.next?.tags,revalidate:e??p?.next?.revalidate}})),appInfo:{name:"Commerce SDK",version:"beta",url:"https://yournextstore.com",partner_id:"CONS-003378"}})};var _=t=>t.filter(Boolean),C={accountGetById:{tags:({accountId:t})=>_(["account",t&&`account-${t}`]),revalidate:()=>{}},cartGetById:{tags:({cartId:t})=>_(["cart",`cart-${t}`]),revalidate:()=>{}},createTaxCalculation:{tags:({cartId:t})=>_(["tax-calculations",`tax-calculations-${t}`]),revalidate:()=>{}},fileGetById:{tags:({fileId:t})=>_(["files",`file-${t}`]),revalidate:()=>{}},orderGetById:{tags:({orderId:t})=>_(["order",`order-${t}`]),revalidate:()=>{}},productBrowse:{tags:({category:t})=>_(["product",t&&`category-${t}`]),revalidate:()=>{}},productGetById:{tags:({productId:t})=>_(["product",`product-${t}`]),revalidate:()=>{}},productGetBySlug:{tags:({productSlug:t})=>_(["product",`product-${t}`]),revalidate:()=>{}},shippingBrowse:{tags:()=>_(["shipping"]),revalidate:()=>{}},shippingGetById:{tags:({shippingId:t})=>_(["shipping",`shipping-${t}`]),revalidate:()=>{}},taxDefaultGet:{tags:()=>_(["tax-settings"]),revalidate:()=>{}}};import{neon as ht}from"@neondatabase/serverless";var I;process.env.DATABASE_URL&&(I=ht(process.env.DATABASE_URL));var F=1e3;function de({productId:t,cartId:e}){return e?yt({cartId:e,productId:t,operation:"INCREASE",clearTaxCalculation:!0}):xt({productId:t})}async function yt({productId:t,cartId:e,operation:n,clearTaxCalculation:a}){let[i,r]=await Promise.all([q(t),st(e)]);if(!i)throw new Error(`Product not found: ${t}`);if(!r)throw new Error(`Cart not found: ${e}`);if(w.StripeCurrency.toLowerCase()!==i.default_price.currency.toLowerCase())throw new Error(`Product currency ${i.default_price.currency} does not match cart currency ${w.StripeCurrency}`);let o=r.cart.metadata??{},p=$(o[t])+(n==="INCREASE"?1:-1);p<=0?o[t]="":o[t]=p.toString();let h=bt(r)+(i.default_price.unit_amount??0);try{return await B({paymentIntentId:e,data:{metadata:o,amount:h||F},clearTaxCalculation:a})}catch(m){d.error(m)}finally{T(`cart-${e}`)}}async function L(t){let{stripeAccount:e,storeId:n,secretKey:a}=await l(),i=f({secretKey:a,tagPrefix:n,tags:C.cartGetById.tags({cartId:t}),cache:"force-cache"});try{let r=await i.paymentIntents.retrieve(t,{expand:["payment_method"]},{stripeAccount:e});if(it.includes(r.status)){let o=Q(r);if(!o)return null;let c=await V(o.metadata),{metadata:{shippingRateId:y}}=o,p=y&&await k(y);return{cart:o,lines:c.map(({product:h,quantity:m})=>h?{product:h,quantity:m}:null).filter(Boolean),shippingRate:p||null}}}catch(r){if(d.error(r),r instanceof R.errors.StripeError&&r.code==="resource_missing")return null;throw r}}async function xt({productId:t}={}){let{stripeAccount:e,storeId:n,secretKey:a}=await l(),i=f({secretKey:a,tagPrefix:n,cache:"no-cache"});try{let r=t?await q(t):null;return await i.paymentIntents.create({currency:w.StripeCurrency,amount:r?.default_price.unit_amount||F,automatic_payment_methods:{enabled:!0},metadata:{...r&&{[r.id]:"1"}}},{stripeAccount:e})}catch(r){throw d.error(r),r}}async function pe({cart:t,add:e}){if(!e)return t;let n=await q(e);if(!n)return d.warn(`Product not found: ${e}`),t;let i=(t?.lines.find(o=>o.product.id===e)?t.lines:[...t?.lines??[],{product:n,quantity:0}]).map(o=>o.product.id===e?{...o,quantity:o.quantity+1}:o),r=t?K(t)+(n.default_price.unit_amount??0):n.default_price.unit_amount??0;return{...t,cart:{...t?.cart,amount:r},lines:i}}async function le({cartId:t,productId:e,quantity:n}){let[a,i]=await Promise.all([at(e),L(t)]);if(!a)throw new Error(`Product not found: ${e}`);if(!i)throw new Error(`Cart not found: ${t}`);if(w.StripeCurrency?.toLowerCase()!==a.default_price.currency.toLowerCase())throw new Error(`Product currency ${a.default_price.currency} does not match cart currency ${w.StripeCurrency}`);let r=i.cart.metadata??{};n<=0?r[e]="":r[e]=n.toString();let o=K(i)+(a.default_price.unit_amount??0);try{return await B({paymentIntentId:t,data:{metadata:r,amount:o||F}})}catch(c){d.error(c)}finally{T(`cart-${t}`),rt("/cart"),rt("/cart-overlay")}}async function at(t){let{stripeAccount:e,storeId:n,secretKey:a}=await l(),i=f({secretKey:a,tagPrefix:n,tags:C.productGetById.tags({productId:t}),cache:"force-cache"});try{let r=await i.products.retrieve(t,{expand:["default_price"]},{stripeAccount:e});return M(r)}catch(r){if(r instanceof R.errors.StripeError&&r.code==="resource_missing")return null;throw r}}async function me({slug:t}){let{stripeAccount:e,storeId:n,secretKey:a}=await l(),r=await f({secretKey:a,tagPrefix:n,tags:C.productGetBySlug.tags({productSlug:t}),cache:"force-cache"}).products.search({query:D({active:!0,'metadata["slug"]':t}),expand:["data.default_price"]},{stripeAccount:e});if(r.data.length>1&&r.data.some(o=>!o.metadata.variant))throw new Error(`Multiple products found with the same slug (${t}) but no variant set.`);return G(j(r).filter(W))}async function wt(t){let{stripeAccount:e,storeId:n,secretKey:a}=await l();if(t.filter?.category){let i=t.filter?.category,o=await f({secretKey:a,tagPrefix:n,tags:C.productBrowse.tags({category:i}),cache:"force-cache"}).products.search({limit:100,query:D({active:!0,'metadata["category"]':i}),expand:["data.default_price"]},{stripeAccount:e});return G(Y(j(o)).filter(W).slice(t.offset,t.first))}else{let r=await f({secretKey:a,tagPrefix:n,tags:C.productBrowse.tags({}),cache:"force-cache"}).products.list({limit:100,active:!0,expand:["data.default_price"]},{stripeAccount:e});return G(Y(j(r)).filter(W).slice(t.offset,t.first))}}async function fe(){let{stripeAccount:t,storeId:e,secretKey:n}=await l(),i=await f({secretKey:n,tagPrefix:e,tags:C.shippingBrowse.tags(),cache:"force-cache"}).shippingRates.list({active:!0},{stripeAccount:t});return J(i)}async function k(t){let{stripeAccount:e,storeId:n,secretKey:a}=await l(),i=f({secretKey:a,tagPrefix:n,tags:C.shippingGetById.tags({shippingId:t}),cache:"force-cache"});try{let r=await i.shippingRates.retrieve(t,{},{stripeAccount:e});return r}catch(r){if(d.error(r),r instanceof R.errors.StripeError&&r.code==="resource_missing")return null;throw r}}async function ge(){let e=(await wt({first:100})).map(a=>a.metadata.category).filter(Boolean),n=new Set(e);return Array.from(n)}async function he(t){let{stripeAccount:e,storeId:n,secretKey:a}=await l(),i=f({secretKey:a,tagPrefix:n,tags:C.fileGetById.tags({fileId:t}),cache:"force-cache"});try{return await i.fileLinks.create({file:t},{stripeAccount:e})}catch(r){if(d.error(r),r instanceof R.errors.StripeError&&r.code==="resource_missing")return null;throw r}}async function ye(){let{stripeAccount:t,storeId:e,secretKey:n}=await l(),a=f({secretKey:n,tagPrefix:e,tags:C.accountGetById.tags({}),cache:"force-cache"});try{let[i,r]=await H(a.accounts.retrieve({expand:["settings.branding.logo"]},{stripeAccount:t})),o=r?.settings?.branding.logo??null;return!o||typeof o=="string"?{account:r,logo:null}:{account:r,logo:o}}catch(i){if(d.error(i),i instanceof R.errors.StripeError&&i.code==="resource_missing")return null;throw i}}async function Ct(t){let{stripeAccount:e,storeId:n,secretKey:a}=await l(),i=f({secretKey:a,tagPrefix:n,tags:C.orderGetById.tags({orderId:t}),cache:"force-cache"});try{let r=await i.paymentIntents.retrieve(t,{expand:["payment_method","latest_charge"]},{stripeAccount:e});return Z(r)}catch(r){if(r instanceof R.errors.StripeError&&r.code==="resource_missing")return null;throw r}}async function xe(t){let e=await Ct(t);if(!e)return null;let n=ot(e.metadata),a=await Promise.all(n.map(async([o,c])=>({product:await q(o),quantity:c}))),{metadata:{shippingRateId:i}}=e,r=i&&await k(i);return{order:e,lines:a.map(({product:o,quantity:c})=>o?{product:o,quantity:c}:null).filter(Boolean),shippingRate:r||null}}var q=async t=>{let{stripeAccount:e,storeId:n,secretKey:a}=await l(),i=f({secretKey:a,tagPrefix:n,tags:C.productGetById.tags({productId:t}),cache:"force-cache"});try{let r=await i.products.retrieve(t,{expand:["default_price"]},{stripeAccount:e});return M(r)}catch(r){if(r instanceof R.errors.StripeError&&r.code==="resource_missing")return null;throw r}},it=["requires_action","requires_confirmation","requires_capture","requires_payment_method"],ot=t=>Object.entries(t??{}).filter(([e])=>e.startsWith("prod_")).map(([e,n])=>[e,$(n)]).filter(([,e])=>e&&Number.isFinite(e)&&e>0),_t=async t=>{let{stripeAccount:e,storeId:n,secretKey:a}=await l(),i=f({secretKey:a,tagPrefix:n,tags:C.cartGetById.tags({cartId:t}),cache:"force-cache"});try{let r=await i.paymentIntents.retrieve(t,{expand:["payment_method"]},{stripeAccount:e});if(it.includes(r.status))return Q(r)}catch(r){if(d.error(r),r instanceof R.errors.StripeError&&r.code==="resource_missing")return null;throw r}};async function V(t){let e=ot(t);return await Promise.all(e.map(async([a,i])=>({product:await q(a),quantity:i})))}var st=async t=>{let e=await _t(t);if(!e)return null;let n=await V(e.metadata),{metadata:{shippingRateId:a}}=e,i=a&&await k(a);return{cart:e,lines:n.map(({product:r,quantity:o})=>r?{product:r,quantity:o}:null).filter(Boolean),shippingRate:i||null}},bt=t=>t?t.cart.metadata?.taxCalculationId?t.cart.amount:(t.shippingRate?.fixed_amount?.amount??0)+t.lines.reduce((e,{product:n,quantity:a})=>e+(n.default_price?.unit_amount??0)*a,0):0,St=["billingAddress.country","billingAddress.postalCode","billingAddress.state","taxId","shippingRateId"];function vt({oldCart:t,data:e,mergedMetadata:n,lines:a}){if(!process.env.ENABLE_STRIPE_TAX)return!1;let i=Date.now(),r=n.taxCalculationExp?Number.parseInt(n.taxCalculationExp)*1e3:null;if(!r||i>=r)return!0;let o=t.cart.metadata.netAmount||t.cart.amount,c=e.amount,y=St.some(x=>!n[x]&&!t.cart.metadata[x]?!1:n[x]!==t.cart.metadata[x]),p=a.length!==t.lines.length||a.some(x=>{let P=t.lines.find(g=>g.product.id===x.product?.id);return x.product?.default_price.unit_amount!==P?.product.default_price.unit_amount||x.quantity!==P?.quantity});return c&&o!==c||y||p}var we=t=>b.object({name:b.string({required_error:t.nameRequired}).min(1,t.nameRequired),city:b.string({required_error:t.cityRequired}).min(1,t.cityRequired),country:b.string({required_error:t.countryRequired}).min(1,t.countryRequired),line1:b.string({required_error:t.line1Required}).min(1,t.line1Required),line2:b.string().optional().nullable().default(""),postalCode:b.string({required_error:t.postalCodeRequired}).min(1,t.postalCodeRequired),state:b.string().optional().nullable().default(""),phone:b.string().optional().nullable().default(""),taxId:b.string().optional().nullable().default("")}),Rt=async({lineItems:t,billingAddress:e,cartId:n,shippingRateId:a,taxId:i})=>{if(!process.env.ENABLE_STRIPE_TAX)return null;let{stripeAccount:r,storeId:o,secretKey:c}=await l(),y=f({secretKey:c,tagPrefix:o,tags:C.createTaxCalculation.tags({cartId:n}),cache:"force-cache"});if(!e?.country)return null;let p=a?await k(a):null,h=typeof p?.tax_code=="string"?p.tax_code:p?.tax_code?.id,m=await At(),x=w.StripeCurrency==="usd"||w.StripeCurrency==="cad"?"exclusive":"inclusive",P=m.defaults.tax_behavior==="inferred_by_currency"?x:m.defaults.tax_behavior??x;m.defaults.tax_behavior||d.warn(`Tax behavior not set in Stripe settings. Inferring from currency ${w.StripeCurrency}: ${x}.`),d.time("createTaxCalculation ${cartId}");let g=await y.tax.calculations.create({expand:["line_items"],line_items:t.map(A=>({...A,tax_behavior:A.tax_behavior??P})),currency:w.StripeCurrency,shipping_cost:p?.active&&p?.fixed_amount?{amount:p.fixed_amount.amount,tax_behavior:p.tax_behavior==="inclusive"?"inclusive":p.tax_behavior==="exclusive"?"exclusive":P,tax_code:h??m.defaults.tax_code??void 0}:void 0,customer_details:{tax_ids:i?[{type:"eu_vat",value:i}]:void 0,address_source:"billing",address:{country:e.country,city:e?.city,line1:e?.line1,line2:e?.line2,postal_code:e?.postalCode,state:e?.state}}},{stripeAccount:r});return d.timeEnd("createTaxCalculation ${cartId}"),g},nt={taxBreakdown0:"",taxBreakdown1:"",taxBreakdown2:"",taxBreakdown3:"",taxBreakdown4:"",taxBreakdown5:""},B=async({paymentIntentId:t,data:e,clearTaxCalculation:n})=>{let{stripeAccount:a,storeId:i,secretKey:r}=await l(),o=await st(t);S(o,`Cart not found: ${t}`);let c=O.parse({...o.cart.metadata,...e.metadata});d.time("getProductsFromMetadata");let y=await V(c);d.timeEnd("getProductsFromMetadata");let h=!n&&vt({oldCart:o,data:e,mergedMetadata:c,lines:y})?await Rt({cartId:t,taxId:c.taxId??null,shippingRateId:c.shippingRateId??null,billingAddress:{country:c["billingAddress.country"]??"",city:c["billingAddress.city"]??"",line1:c["billingAddress.line1"]??"",line2:c["billingAddress.line2"]??"",name:c["billingAddress.name"]??"",postalCode:c["billingAddress.postalCode"]??"",state:c["billingAddress.state"]??""},lineItems:y.map(({product:g,quantity:A})=>{if(g?.default_price.unit_amount)return{product:g.id,reference:[g.metadata.slug,g.metadata.variant].filter(Boolean).join("-"),quantity:A,amount:g.default_price.unit_amount*A,tax_behavior:g.default_price.tax_behavior==="exclusive"?"exclusive":g.default_price.tax_behavior==="inclusive"?"inclusive":void 0,tax_code:g.tax_code?typeof g.tax_code=="string"?g.tax_code:g.tax_code.id:void 0}}).filter(Boolean)}):null,m=e.amount?e.amount.toString():null;if(h){let g=Object.fromEntries(h.tax_breakdown.map(N=>({taxType:N.tax_rate_details.tax_type,taxPercentage:N.tax_rate_details.percentage_decimal,taxAmount:N.amount})).map((N,ut)=>[`taxBreakdown${ut}`,JSON.stringify(N)])),A=f({secretKey:r,tagPrefix:i,cache:"no-cache"});d.time(`paymentIntents.update ${t}`);let ct=await A.paymentIntents.update(t,{...e,amount:h.amount_total,metadata:{...c,...m&&{netAmount:m},...nt,...g,taxCalculationId:h.id,taxCalculationExp:h?.expires_at}},{stripeAccount:a});return d.timeEnd(`paymentIntents.update ${t}`),ct}let x=f({secretKey:r,tagPrefix:i,cache:"no-cache"});d.time(`paymentIntents.update ${t}`);let P=await x.paymentIntents.update(t,{...e,metadata:{...c,...m&&{netAmount:m},...n&&{...nt,taxCalculationId:"",taxCalculationExp:""}}},{stripeAccount:a});return d.timeEnd(`paymentIntents.update ${t}`),P},K=t=>t?t.cart.metadata?.taxCalculationId?t.cart.amount:(t.shippingRate?.fixed_amount?.amount??0)+Pt(t):0,Pt=t=>t?t.lines.reduce((e,{product:n,quantity:a})=>e+(n.default_price?.unit_amount??0)*a,0):0;async function Ce({productId:t,cartId:e,operation:n,clearTaxCalculation:a}){let[i,r]=await Promise.all([at(t),L(e)]);if(!i)throw new Error(`Product not found: ${t}`);if(!r)throw new Error(`Cart not found: ${e}`);if(w.StripeCurrency?.toLowerCase()!==i.default_price.currency.toLowerCase())throw new Error(`Product currency ${i.default_price.currency} does not match cart currency ${w.StripeCurrency}`);let o=r.cart.metadata??{},p=$(o[t])+(n==="INCREASE"?1:-1);p<=0?o[t]="":o[t]=p.toString();let h=K(r)+(i.default_price.unit_amount??0);try{return await B({paymentIntentId:e,data:{metadata:o,amount:h||F},clearTaxCalculation:a})}catch(m){d.error(m)}finally{T(`cart-${e}`)}}var _e=async({cartId:t,taxId:e})=>{let n=await L(t);if(!n)throw new Error(`Cart not found: ${t}`);try{return await B({paymentIntentId:t,data:{metadata:{...n.cart.metadata,taxId:e}}})}catch(a){d.error(a)}finally{T(`cart-${t}`)}};async function be({cartId:t,shippingRateId:e}){let n=await L(t);if(!n)throw new Error(`Cart not found: ${t}`);d.time(`cartSaveShipping ${t}`);let a=await k(e);if(d.timeEnd(`cartSaveShipping ${t}`),!a)throw new Error(`Shipping rate not found: ${e}`);try{d.time(`updatePaymentIntent ${t}`);let i=await B({paymentIntentId:t,data:{metadata:{...n.cart.metadata,shippingRateId:e},amount:K({...n,shippingRate:a})}});return d.timeEnd(`updatePaymentIntent ${t}`),i}catch(i){d.error(i)}finally{T(`cart-${t}`)}}async function Se({cartId:t,billingAddress:e}){if(!await L(t))throw new Error(`Cart not found: ${t}`);try{return await B({paymentIntentId:t,data:{metadata:{"billingAddress.name":e.name,"billingAddress.phone":e.phone,"billingAddress.city":e.city,"billingAddress.country":e.country,"billingAddress.line1":e.line1,"billingAddress.line2":e.line2??"","billingAddress.postalCode":e.postalCode,"billingAddress.state":e.state??""}}})}catch(a){d.error(a)}finally{T(`cart-${t}`)}}async function At(){let{stripeAccount:t,storeId:e,secretKey:n}=await l();return await f({secretKey:n,tagPrefix:e,tags:["tax-settings"],cache:"force-cache"}).tax.settings.retrieve({},{stripeAccount:t})}function ve(t){return Object.entries(t??{}).filter(([e])=>e.startsWith("prod_")).map(([e,n])=>[e,$(n)]).filter(([,e])=>e&&Number.isFinite(e)&&e>0).length}async function Re(t){if(!I)return null;let{storeId:e}=await l();return await I`
26
+ `}}},e={stripeAccount:void 0,storeId:void 0,secretKey:void 0,config:t},n=await global?.__ynsFindStripeAccount?.();return n?{...n,config:n.config??t}:e};import"server-only";import tt from"stripe";import"server-only";var pt=process.env.STRIPE_SECRET_KEY,Z=process.env.STRIPE_CURRENCY;if(!Z)throw new Error("Missing STRIPE_CURRENCY");var x={StripeSecretKey:pt,StripeCurrency:Z};var b={DEBUG:0,LOG:1,WARN:2,ERROR:3},lt="LOG",mt=process.env.LOG_LEVEL&&process.env.LOG_LEVEL in b?process.env.LOG_LEVEL:lt,A=b[mt],u={time(t){A>b.DEBUG||console.time(t)},timeEnd(t){A>b.DEBUG||console.timeEnd(t)},log(...t){A>b.LOG||console.log(...t)},dir(t,e){A>b.LOG||console.dir(t,e)},warn(...t){A>b.WARN||console.warn(...t)},error(...t){A>b.ERROR||console.error(...t)}};var ft=(t,e)=>!t||!e?t:[...t,`prefix-${e}`,...t.map(n=>`${e}-${n}`)],m=({tags:t,revalidate:e,cache:n,tagPrefix:a,secretKey:i})=>{let r=i??x.StripeSecretKey;if(!r)throw new Error("Missing `secretKey` parameter and `STRIPE_SECRET_KEY` env variable.");u.log(`Using Stripe secret key from ${i?"parameter":"env"}.`);let o=ft(t,a);return new tt(r,{typescript:!0,apiVersion:"2024-06-20",httpClient:tt.createFetchHttpClient((h,d)=>fetch(h,{...d,cache:n??d?.cache,next:{tags:o??d?.next?.tags,revalidate:e??d?.next?.revalidate}})),appInfo:{name:"Commerce SDK",version:"beta",url:"https://yournextstore.com",partner_id:"CONS-003378"}})};var C=t=>t.filter(Boolean),w={accountGetById:{tags:({accountId:t})=>C(["account",t&&`account-${t}`]),revalidate:()=>{}},cartGetById:{tags:({cartId:t})=>C(["cart",`cart-${t}`]),revalidate:()=>{}},createTaxCalculation:{tags:({cartId:t})=>C(["tax-calculations",`tax-calculations-${t}`]),revalidate:()=>{}},fileGetById:{tags:({fileId:t})=>C(["files",`file-${t}`]),revalidate:()=>{}},orderGetById:{tags:({orderId:t})=>C(["order",`order-${t}`]),revalidate:()=>{}},productBrowse:{tags:({category:t})=>C(["product",t&&`category-${t}`]),revalidate:()=>{}},productGetById:{tags:({productId:t})=>C(["product",`product-${t}`]),revalidate:()=>{}},productGetBySlug:{tags:({productSlug:t})=>C(["product",`product-${t}`]),revalidate:()=>{}},shippingBrowse:{tags:()=>C(["shipping"]),revalidate:()=>{}},shippingGetById:{tags:({shippingId:t})=>C(["shipping",`shipping-${t}`]),revalidate:()=>{}},taxDefaultGet:{tags:()=>C(["tax-settings"]),revalidate:()=>{}}};import{neon as gt}from"@neondatabase/serverless";var E;process.env.DATABASE_URL&&(E=gt(process.env.DATABASE_URL));var F=1e3;function se({productId:t,cartId:e}){return e?ht({cartId:e,productId:t,operation:"INCREASE",clearTaxCalculation:!0}):yt({productId:t})}async function ht({productId:t,cartId:e,operation:n,clearTaxCalculation:a}){let[i,r]=await Promise.all([k(t),ot(e)]);if(!i)throw new Error(`Product not found: ${t}`);if(!r)throw new Error(`Cart not found: ${e}`);if(x.StripeCurrency.toLowerCase()!==i.default_price.currency.toLowerCase())throw new Error(`Product currency ${i.default_price.currency} does not match cart currency ${x.StripeCurrency}`);let o=r.cart.metadata??{},d=N(o[t])+(n==="INCREASE"?1:-1);d<=0?o[t]="":o[t]=d.toString();let g=_t(r)+(i.default_price.unit_amount??0);try{return await T({paymentIntentId:e,data:{metadata:o,amount:g||F},clearTaxCalculation:a})}catch(l){u.error(l)}finally{I(`cart-${e}`)}}async function $(t){let{stripeAccount:e,storeId:n,secretKey:a}=await p(),i=m({secretKey:a,tagPrefix:n,tags:w.cartGetById.tags({cartId:t}),cache:"force-cache"});try{let r=await i.paymentIntents.retrieve(t,{expand:["payment_method"]},{stripeAccount:e});if(at.includes(r.status)){let o=Y(r);if(!o)return null;let s=await Q(o.metadata),{metadata:{shippingRateId:h}}=o,d=h&&await L(h);return{cart:o,lines:s.map(({product:g,quantity:l})=>g?{product:g,quantity:l}:null).filter(Boolean),shippingRate:d||null}}}catch(r){if(u.error(r),r instanceof v.errors.StripeError&&r.code==="resource_missing")return null;throw r}}async function yt({productId:t}={}){let{stripeAccount:e,storeId:n,secretKey:a}=await p(),i=m({secretKey:a,tagPrefix:n,cache:"no-cache"});try{let r=t?await k(t):null;return await i.paymentIntents.create({currency:x.StripeCurrency,amount:r?.default_price.unit_amount||F,automatic_payment_methods:{enabled:!0},metadata:{...r&&{[r.id]:"1"}}},{stripeAccount:e})}catch(r){throw u.error(r),r}}async function ce({cart:t,add:e}){if(!e)return t;let n=await k(e);if(!n)return u.warn(`Product not found: ${e}`),t;let i=(t?.lines.find(o=>o.product.id===e)?t.lines:[...t?.lines??[],{product:n,quantity:0}]).map(o=>o.product.id===e?{...o,quantity:o.quantity+1}:o),r=t?K(t)+(n.default_price.unit_amount??0):n.default_price.unit_amount??0;return{...t,cart:{...t?.cart,amount:r},lines:i}}async function ue({cartId:t,productId:e,quantity:n}){let[a,i]=await Promise.all([nt(e),$(t)]);if(!a)throw new Error(`Product not found: ${e}`);if(!i)throw new Error(`Cart not found: ${t}`);if(x.StripeCurrency?.toLowerCase()!==a.default_price.currency.toLowerCase())throw new Error(`Product currency ${a.default_price.currency} does not match cart currency ${x.StripeCurrency}`);let r=i.cart.metadata??{};n<=0?r[e]="":r[e]=n.toString();let o=K(i)+(a.default_price.unit_amount??0);try{return await T({paymentIntentId:t,data:{metadata:r,amount:o||F}})}catch(s){u.error(s)}finally{I(`cart-${t}`),et("/cart"),et("/cart-overlay")}}async function nt(t){let{stripeAccount:e,storeId:n,secretKey:a}=await p(),i=m({secretKey:a,tagPrefix:n,tags:w.productGetById.tags({productId:t}),cache:"force-cache"});try{let r=await i.products.retrieve(t,{expand:["default_price"]},{stripeAccount:e});return G(r)}catch(r){if(r instanceof v.errors.StripeError&&r.code==="resource_missing")return null;throw r}}async function de({slug:t}){let{stripeAccount:e,storeId:n,secretKey:a}=await p(),r=await m({secretKey:a,tagPrefix:n,tags:w.productGetBySlug.tags({productSlug:t}),cache:"force-cache"}).products.search({query:j({active:!0,'metadata["slug"]':t}),expand:["data.default_price"]},{stripeAccount:e});if(r.data.length>1&&r.data.some(o=>!o.metadata.variant))throw new Error(`Multiple products found with the same slug (${t}) but no variant set.`);return q(M(r).filter(W))}async function xt(t){let{stripeAccount:e,storeId:n,secretKey:a}=await p();if(t.filter?.category){let i=t.filter?.category,o=await m({secretKey:a,tagPrefix:n,tags:w.productBrowse.tags({category:i}),cache:"force-cache"}).products.search({limit:100,query:j({active:!0,'metadata["category"]':i}),expand:["data.default_price"]},{stripeAccount:e});return q(D(M(o)).filter(W).slice(t.offset,t.first))}else{let r=await m({secretKey:a,tagPrefix:n,tags:w.productBrowse.tags({}),cache:"force-cache"}).products.list({limit:100,active:!0,expand:["data.default_price"]},{stripeAccount:e});return q(D(M(r)).filter(W).slice(t.offset,t.first))}}async function pe(){let{stripeAccount:t,storeId:e,secretKey:n}=await p(),i=await m({secretKey:n,tagPrefix:e,tags:w.shippingBrowse.tags(),cache:"force-cache"}).shippingRates.list({active:!0},{stripeAccount:t});return z(i)}async function L(t){let{stripeAccount:e,storeId:n,secretKey:a}=await p(),i=m({secretKey:a,tagPrefix:n,tags:w.shippingGetById.tags({shippingId:t}),cache:"force-cache"});try{let r=await i.shippingRates.retrieve(t,{},{stripeAccount:e});return r}catch(r){if(u.error(r),r instanceof v.errors.StripeError&&r.code==="resource_missing")return null;throw r}}async function le(){let e=(await xt({first:100})).map(a=>a.metadata.category).filter(Boolean),n=new Set(e);return Array.from(n)}async function me(t){let{stripeAccount:e,storeId:n,secretKey:a}=await p(),i=m({secretKey:a,tagPrefix:n,tags:w.fileGetById.tags({fileId:t}),cache:"force-cache"});try{return await i.fileLinks.create({file:t},{stripeAccount:e})}catch(r){if(u.error(r),r instanceof v.errors.StripeError&&r.code==="resource_missing")return null;throw r}}async function fe(){let{stripeAccount:t,storeId:e,secretKey:n}=await p(),a=m({secretKey:n,tagPrefix:e,tags:w.accountGetById.tags({}),cache:"force-cache"});try{let[i,r]=await V(a.accounts.retrieve({expand:["settings.branding.logo"]},{stripeAccount:t})),o=r?.settings?.branding.logo??null;return!o||typeof o=="string"?{account:r,logo:null}:{account:r,logo:o}}catch(i){if(u.error(i),i instanceof v.errors.StripeError&&i.code==="resource_missing")return null;throw i}}async function wt(t){let{stripeAccount:e,storeId:n,secretKey:a}=await p(),i=m({secretKey:a,tagPrefix:n,tags:w.orderGetById.tags({orderId:t}),cache:"force-cache"});try{let r=await i.paymentIntents.retrieve(t,{expand:["payment_method","latest_charge"]},{stripeAccount:e});return X(r)}catch(r){if(r instanceof v.errors.StripeError&&r.code==="resource_missing")return null;throw r}}async function ge(t){let e=await wt(t);if(!e)return null;let n=it(e.metadata),a=await Promise.all(n.map(async([o,s])=>({product:await k(o),quantity:s}))),{metadata:{shippingRateId:i}}=e,r=i&&await L(i);return{order:e,lines:a.map(({product:o,quantity:s})=>o?{product:o,quantity:s}:null).filter(Boolean),shippingRate:r||null}}var k=async t=>{let{stripeAccount:e,storeId:n,secretKey:a}=await p(),i=m({secretKey:a,tagPrefix:n,tags:w.productGetById.tags({productId:t}),cache:"force-cache"});try{let r=await i.products.retrieve(t,{expand:["default_price"]},{stripeAccount:e});return G(r)}catch(r){if(r instanceof v.errors.StripeError&&r.code==="resource_missing")return null;throw r}},at=["requires_action","requires_confirmation","requires_capture","requires_payment_method"],it=t=>Object.entries(t??{}).filter(([e])=>e.startsWith("prod_")).map(([e,n])=>[e,N(n)]).filter(([,e])=>e&&Number.isFinite(e)&&e>0),Ct=async t=>{let{stripeAccount:e,storeId:n,secretKey:a}=await p(),i=m({secretKey:a,tagPrefix:n,tags:w.cartGetById.tags({cartId:t}),cache:"force-cache"});try{let r=await i.paymentIntents.retrieve(t,{expand:["payment_method"]},{stripeAccount:e});if(at.includes(r.status))return Y(r)}catch(r){if(u.error(r),r instanceof v.errors.StripeError&&r.code==="resource_missing")return null;throw r}};async function Q(t){let e=it(t);return await Promise.all(e.map(async([a,i])=>({product:await k(a),quantity:i})))}var ot=async t=>{let e=await Ct(t);if(!e)return null;let n=await Q(e.metadata),{metadata:{shippingRateId:a}}=e,i=a&&await L(a);return{cart:e,lines:n.map(({product:r,quantity:o})=>r?{product:r,quantity:o}:null).filter(Boolean),shippingRate:i||null}},_t=t=>t?t.cart.metadata?.taxCalculationId?t.cart.amount:(t.shippingRate?.fixed_amount?.amount??0)+t.lines.reduce((e,{product:n,quantity:a})=>e+(n.default_price?.unit_amount??0)*a,0):0,St=["billingAddress.country","billingAddress.postalCode","billingAddress.state","taxId","shippingRateId"];function bt({oldCart:t,data:e,mergedMetadata:n,lines:a}){if(!process.env.ENABLE_STRIPE_TAX)return!1;let i=Date.now(),r=n.taxCalculationExp?Number.parseInt(n.taxCalculationExp)*1e3:null;if(!r||i>=r)return!0;let o=t.cart.metadata.netAmount||t.cart.amount,s=e.amount,h=St.some(y=>!n[y]&&!t.cart.metadata[y]?!1:n[y]!==t.cart.metadata[y]),d=a.length!==t.lines.length||a.some(y=>{let R=t.lines.find(f=>f.product.id===y.product?.id);return y.product?.default_price.unit_amount!==R?.product.default_price.unit_amount||y.quantity!==R?.quantity});return s&&o!==s||h||d}var he=t=>_.object({name:_.string({required_error:t.nameRequired}).min(1,t.nameRequired),city:_.string({required_error:t.cityRequired}).min(1,t.cityRequired),country:_.string({required_error:t.countryRequired}).min(1,t.countryRequired),line1:_.string({required_error:t.line1Required}).min(1,t.line1Required),line2:_.string().optional().nullable().default(""),postalCode:_.string({required_error:t.postalCodeRequired}).min(1,t.postalCodeRequired),state:_.string().optional().nullable().default(""),phone:_.string().optional().nullable().default(""),taxId:_.string().optional().nullable().default("")}),vt=async({lineItems:t,billingAddress:e,cartId:n,shippingRateId:a,taxId:i})=>{if(!process.env.ENABLE_STRIPE_TAX)return null;let{stripeAccount:r,storeId:o,secretKey:s}=await p(),h=m({secretKey:s,tagPrefix:o,tags:w.createTaxCalculation.tags({cartId:n}),cache:"force-cache"});if(!e?.country)return null;let d=a?await L(a):null,g=typeof d?.tax_code=="string"?d.tax_code:d?.tax_code?.id,l=await Pt(),y=x.StripeCurrency==="usd"||x.StripeCurrency==="cad"?"exclusive":"inclusive",R=l.defaults.tax_behavior==="inferred_by_currency"?y:l.defaults.tax_behavior??y;l.defaults.tax_behavior||u.warn(`Tax behavior not set in Stripe settings. Inferring from currency ${x.StripeCurrency}: ${y}.`),u.time("createTaxCalculation ${cartId}");let f=await h.tax.calculations.create({expand:["line_items"],line_items:t.map(P=>({...P,tax_behavior:P.tax_behavior??R})),currency:x.StripeCurrency,shipping_cost:d?.active&&d?.fixed_amount?{amount:d.fixed_amount.amount,tax_behavior:d.tax_behavior==="inclusive"?"inclusive":d.tax_behavior==="exclusive"?"exclusive":R,tax_code:g??l.defaults.tax_code??void 0}:void 0,customer_details:{tax_ids:i?[{type:"eu_vat",value:i}]:void 0,address_source:"billing",address:{country:e.country,city:e?.city,line1:e?.line1,line2:e?.line2,postal_code:e?.postalCode,state:e?.state}}},{stripeAccount:r});return u.timeEnd("createTaxCalculation ${cartId}"),f},rt={taxBreakdown0:"",taxBreakdown1:"",taxBreakdown2:"",taxBreakdown3:"",taxBreakdown4:"",taxBreakdown5:""},T=async({paymentIntentId:t,data:e,clearTaxCalculation:n})=>{let{stripeAccount:a,storeId:i,secretKey:r}=await p(),o=await ot(t);S(o,`Cart not found: ${t}`);let s=O.parse({...o.cart.metadata,...e.metadata});u.time("getProductsFromMetadata");let h=await Q(s);u.timeEnd("getProductsFromMetadata");let g=!n&&bt({oldCart:o,data:e,mergedMetadata:s,lines:h})?await vt({cartId:t,taxId:s.taxId??null,shippingRateId:s.shippingRateId??null,billingAddress:{country:s["billingAddress.country"]??"",city:s["billingAddress.city"]??"",line1:s["billingAddress.line1"]??"",line2:s["billingAddress.line2"]??"",name:s["billingAddress.name"]??"",postalCode:s["billingAddress.postalCode"]??"",state:s["billingAddress.state"]??""},lineItems:h.map(({product:f,quantity:P})=>{if(f?.default_price.unit_amount)return{product:f.id,reference:[f.metadata.slug,f.metadata.variant].filter(Boolean).join("-"),quantity:P,amount:f.default_price.unit_amount*P,tax_behavior:f.default_price.tax_behavior==="exclusive"?"exclusive":f.default_price.tax_behavior==="inclusive"?"inclusive":void 0,tax_code:f.tax_code?typeof f.tax_code=="string"?f.tax_code:f.tax_code.id:void 0}}).filter(Boolean)}):null,l=e.amount?e.amount.toString():null;if(g){let f=Object.fromEntries(g.tax_breakdown.map(B=>({taxType:B.tax_rate_details.tax_type,taxPercentage:B.tax_rate_details.percentage_decimal,taxAmount:B.amount})).map((B,ct)=>[`taxBreakdown${ct}`,JSON.stringify(B)])),P=m({secretKey:r,tagPrefix:i,cache:"no-cache"});u.time(`paymentIntents.update ${t}`);let st=await P.paymentIntents.update(t,{...e,amount:g.amount_total,metadata:{...s,...l&&{netAmount:l},...rt,...f,taxCalculationId:g.id,taxCalculationExp:g?.expires_at}},{stripeAccount:a});return u.timeEnd(`paymentIntents.update ${t}`),st}let y=m({secretKey:r,tagPrefix:i,cache:"no-cache"});u.time(`paymentIntents.update ${t}`);let R=await y.paymentIntents.update(t,{...e,metadata:{...s,...l&&{netAmount:l},...n&&{...rt,taxCalculationId:"",taxCalculationExp:""}}},{stripeAccount:a});return u.timeEnd(`paymentIntents.update ${t}`),R},K=t=>t?t.cart.metadata?.taxCalculationId?t.cart.amount:(t.shippingRate?.fixed_amount?.amount??0)+Rt(t):0,Rt=t=>t?t.lines.reduce((e,{product:n,quantity:a})=>e+(n.default_price?.unit_amount??0)*a,0):0;async function ye({productId:t,cartId:e,operation:n,clearTaxCalculation:a}){let[i,r]=await Promise.all([nt(t),$(e)]);if(!i)throw new Error(`Product not found: ${t}`);if(!r)throw new Error(`Cart not found: ${e}`);if(x.StripeCurrency?.toLowerCase()!==i.default_price.currency.toLowerCase())throw new Error(`Product currency ${i.default_price.currency} does not match cart currency ${x.StripeCurrency}`);let o=r.cart.metadata??{},d=N(o[t])+(n==="INCREASE"?1:-1);d<=0?o[t]="":o[t]=d.toString();let g=K(r)+(i.default_price.unit_amount??0);try{return await T({paymentIntentId:e,data:{metadata:o,amount:g||F},clearTaxCalculation:a})}catch(l){u.error(l)}finally{I(`cart-${e}`)}}var xe=async({cartId:t,taxId:e})=>{let n=await $(t);if(!n)throw new Error(`Cart not found: ${t}`);try{return await T({paymentIntentId:t,data:{metadata:{...n.cart.metadata,taxId:e}}})}catch(a){u.error(a)}finally{I(`cart-${t}`)}};async function we({cartId:t,shippingRateId:e}){let n=await $(t);if(!n)throw new Error(`Cart not found: ${t}`);u.time(`cartSaveShipping ${t}`);let a=await L(e);if(u.timeEnd(`cartSaveShipping ${t}`),!a)throw new Error(`Shipping rate not found: ${e}`);try{u.time(`updatePaymentIntent ${t}`);let i=await T({paymentIntentId:t,data:{metadata:{...n.cart.metadata,shippingRateId:e},amount:K({...n,shippingRate:a})}});return u.timeEnd(`updatePaymentIntent ${t}`),i}catch(i){u.error(i)}finally{I(`cart-${t}`)}}async function Ce({cartId:t,billingAddress:e}){if(!await $(t))throw new Error(`Cart not found: ${t}`);try{return await T({paymentIntentId:t,data:{metadata:{"billingAddress.name":e.name,"billingAddress.phone":e.phone,"billingAddress.city":e.city,"billingAddress.country":e.country,"billingAddress.line1":e.line1,"billingAddress.line2":e.line2??"","billingAddress.postalCode":e.postalCode,"billingAddress.state":e.state??""}}})}catch(a){u.error(a)}finally{I(`cart-${t}`)}}async function Pt(){let{stripeAccount:t,storeId:e,secretKey:n}=await p();return await m({secretKey:n,tagPrefix:e,tags:["tax-settings"],cache:"force-cache"}).tax.settings.retrieve({},{stripeAccount:t})}function _e(t){return Object.entries(t??{}).filter(([e])=>e.startsWith("prod_")).map(([e,n])=>[e,N(n)]).filter(([,e])=>e&&Number.isFinite(e)&&e>0).length}async function Se(t){if(!E)return null;let{storeId:e}=await p();return await E`
27
27
  select * from reviews
28
28
  where product_id = ${t.productId} and store_id = ${e}
29
29
  order by created_at desc
30
30
  limit ${t.first??100}
31
31
  offset ${t.offset??0}
32
- `}async function Pe(t){if(!I)return null;let{storeId:e}=await l();return await I`
32
+ `}async function be(t){if(!E)return null;let{storeId:e}=await p();return await E`
33
33
  insert into reviews (store_id, product_id, author, email, content, rating, created_at, updated_at)
34
34
  values (${e}, ${t.productId}, ${t.author}, ${t.email}, ${t.content}, ${t.rating}, now(), now())
35
- `}var Ae=l;export{ye as accountGet,bt as calculateCartTotalNet,Pt as calculateCartTotalNetWithoutShipping,K as calculateCartTotalPossiblyWithTax,de as cartAdd,pe as cartAddOptimistic,Ce as cartChangeQuantity,ve as cartCount,xt as cartCreate,L as cartGet,Se as cartSaveBillingAddress,be as cartSaveShipping,_e as cartSaveTax,le as cartSetQuantity,yt as cartUpdateQuantity,ge as categoryBrowse,Ae as contextGet,he as fileGet,we as getAddressSchema,st as getCartWithProductsById,ot as getProductsFromCart,xe as orderGet,wt as productBrowse,me as productGet,at as productGetById,Pe as productReviewAdd,Re as productReviewBrowse,f as provider,fe as shippingBrowse,k as shippingGet,At as taxDefaultGet};
35
+ `}var ve=p;export{fe as accountGet,_t as calculateCartTotalNet,Rt as calculateCartTotalNetWithoutShipping,K as calculateCartTotalPossiblyWithTax,se as cartAdd,ce as cartAddOptimistic,ye as cartChangeQuantity,_e as cartCount,yt as cartCreate,$ as cartGet,Ce as cartSaveBillingAddress,we as cartSaveShipping,xe as cartSaveTax,ue as cartSetQuantity,ht as cartUpdateQuantity,le as categoryBrowse,ve as contextGet,me as fileGet,he as getAddressSchema,ot as getCartWithProductsById,it as getProductsFromCart,ge as orderGet,xt as productBrowse,de as productGet,nt as productGetById,be as productReviewAdd,Se as productReviewBrowse,m as provider,pe as shippingBrowse,L as shippingGet,Pt as taxDefaultGet};
package/dist/yns.d.ts CHANGED
@@ -1,264 +1,6 @@
1
- import { z } from 'zod';
1
+ import { Config } from './browser.js';
2
+ import 'zod';
2
3
 
3
- declare const configSchema: z.ZodObject<{
4
- hero: z.ZodObject<{
5
- show: z.ZodBoolean;
6
- title: z.ZodString;
7
- description: z.ZodString;
8
- button: z.ZodObject<{
9
- label: z.ZodString;
10
- path: z.ZodString;
11
- }, "strip", z.ZodTypeAny, {
12
- path: string;
13
- label: string;
14
- }, {
15
- path: string;
16
- label: string;
17
- }>;
18
- image: z.ZodObject<{
19
- src: z.ZodString;
20
- alt: z.ZodString;
21
- }, "strip", z.ZodTypeAny, {
22
- src: string;
23
- alt: string;
24
- }, {
25
- src: string;
26
- alt: string;
27
- }>;
28
- }, "strip", z.ZodTypeAny, {
29
- description: string;
30
- show: boolean;
31
- title: string;
32
- button: {
33
- path: string;
34
- label: string;
35
- };
36
- image: {
37
- src: string;
38
- alt: string;
39
- };
40
- }, {
41
- description: string;
42
- show: boolean;
43
- title: string;
44
- button: {
45
- path: string;
46
- label: string;
47
- };
48
- image: {
49
- src: string;
50
- alt: string;
51
- };
52
- }>;
53
- categorySection: z.ZodObject<{
54
- show: z.ZodBoolean;
55
- }, "strip", z.ZodTypeAny, {
56
- show: boolean;
57
- }, {
58
- show: boolean;
59
- }>;
60
- nav: z.ZodObject<{
61
- title: z.ZodString;
62
- searchBar: z.ZodObject<{
63
- show: z.ZodBoolean;
64
- }, "strip", z.ZodTypeAny, {
65
- show: boolean;
66
- }, {
67
- show: boolean;
68
- }>;
69
- links: z.ZodArray<z.ZodObject<{
70
- label: z.ZodString;
71
- href: z.ZodString;
72
- }, "strip", z.ZodTypeAny, {
73
- label: string;
74
- href: string;
75
- }, {
76
- label: string;
77
- href: string;
78
- }>, "many">;
79
- }, "strip", z.ZodTypeAny, {
80
- title: string;
81
- searchBar: {
82
- show: boolean;
83
- };
84
- links: {
85
- label: string;
86
- href: string;
87
- }[];
88
- }, {
89
- title: string;
90
- searchBar: {
91
- show: boolean;
92
- };
93
- links: {
94
- label: string;
95
- href: string;
96
- }[];
97
- }>;
98
- footer: z.ZodObject<{
99
- name: z.ZodString;
100
- tagline: z.ZodString;
101
- newsletter: z.ZodObject<{
102
- show: z.ZodBoolean;
103
- }, "strip", z.ZodTypeAny, {
104
- show: boolean;
105
- }, {
106
- show: boolean;
107
- }>;
108
- credits: z.ZodBoolean;
109
- sections: z.ZodArray<z.ZodObject<{
110
- header: z.ZodString;
111
- links: z.ZodArray<z.ZodObject<{
112
- label: z.ZodString;
113
- href: z.ZodString;
114
- }, "strip", z.ZodTypeAny, {
115
- label: string;
116
- href: string;
117
- }, {
118
- label: string;
119
- href: string;
120
- }>, "many">;
121
- }, "strip", z.ZodTypeAny, {
122
- links: {
123
- label: string;
124
- href: string;
125
- }[];
126
- header: string;
127
- }, {
128
- links: {
129
- label: string;
130
- href: string;
131
- }[];
132
- header: string;
133
- }>, "many">;
134
- }, "strip", z.ZodTypeAny, {
135
- name: string;
136
- tagline: string;
137
- newsletter: {
138
- show: boolean;
139
- };
140
- credits: boolean;
141
- sections: {
142
- links: {
143
- label: string;
144
- href: string;
145
- }[];
146
- header: string;
147
- }[];
148
- }, {
149
- name: string;
150
- tagline: string;
151
- newsletter: {
152
- show: boolean;
153
- };
154
- credits: boolean;
155
- sections: {
156
- links: {
157
- label: string;
158
- href: string;
159
- }[];
160
- header: string;
161
- }[];
162
- }>;
163
- pages: z.ZodRecord<z.ZodString, z.ZodObject<{
164
- content: z.ZodString;
165
- }, "strip", z.ZodTypeAny, {
166
- content: string;
167
- }, {
168
- content: string;
169
- }>>;
170
- }, "strip", z.ZodTypeAny, {
171
- hero: {
172
- description: string;
173
- show: boolean;
174
- title: string;
175
- button: {
176
- path: string;
177
- label: string;
178
- };
179
- image: {
180
- src: string;
181
- alt: string;
182
- };
183
- };
184
- categorySection: {
185
- show: boolean;
186
- };
187
- nav: {
188
- title: string;
189
- searchBar: {
190
- show: boolean;
191
- };
192
- links: {
193
- label: string;
194
- href: string;
195
- }[];
196
- };
197
- footer: {
198
- name: string;
199
- tagline: string;
200
- newsletter: {
201
- show: boolean;
202
- };
203
- credits: boolean;
204
- sections: {
205
- links: {
206
- label: string;
207
- href: string;
208
- }[];
209
- header: string;
210
- }[];
211
- };
212
- pages: Record<string, {
213
- content: string;
214
- }>;
215
- }, {
216
- hero: {
217
- description: string;
218
- show: boolean;
219
- title: string;
220
- button: {
221
- path: string;
222
- label: string;
223
- };
224
- image: {
225
- src: string;
226
- alt: string;
227
- };
228
- };
229
- categorySection: {
230
- show: boolean;
231
- };
232
- nav: {
233
- title: string;
234
- searchBar: {
235
- show: boolean;
236
- };
237
- links: {
238
- label: string;
239
- href: string;
240
- }[];
241
- };
242
- footer: {
243
- name: string;
244
- tagline: string;
245
- newsletter: {
246
- show: boolean;
247
- };
248
- credits: boolean;
249
- sections: {
250
- links: {
251
- label: string;
252
- href: string;
253
- }[];
254
- header: string;
255
- }[];
256
- };
257
- pages: Record<string, {
258
- content: string;
259
- }>;
260
- }>;
261
- type Config = z.infer<typeof configSchema>;
262
4
  type YnsFindStripeAccountResult = {
263
5
  stripeAccount: string | undefined;
264
6
  storeId: string | undefined;
@@ -280,4 +22,4 @@ declare global {
280
22
  }
281
23
  declare const getYnsContext: () => Promise<YnsContextResult>;
282
24
 
283
- export { type Config, configSchema, getYnsContext };
25
+ export { getYnsContext };
package/dist/yns.js CHANGED
@@ -1,4 +1,4 @@
1
- import"server-only";import{z as e}from"zod";var s=e.object({hero:e.object({show:e.boolean(),title:e.string(),description:e.string(),button:e.object({label:e.string(),path:e.string()}),image:e.object({src:e.string(),alt:e.string()})}),categorySection:e.object({show:e.boolean()}),nav:e.object({title:e.string(),searchBar:e.object({show:e.boolean()}),links:e.array(e.object({label:e.string(),href:e.string()}))}),footer:e.object({name:e.string(),tagline:e.string(),newsletter:e.object({show:e.boolean()}),credits:e.boolean(),sections:e.array(e.object({header:e.string(),links:e.array(e.object({label:e.string(),href:e.string()}))}))}),pages:e.record(e.string(),e.object({content:e.string()}))}),a=async()=>{let n={hero:{show:!0,title:"Discover our Curated Collection",description:"Explore our carefully selected products for your home and lifestyle.",button:{label:"Shop Now",path:"/"},image:{src:"https://files.stripe.com/links/MDB8YWNjdF8xT3BaeG5GSmNWbVh6bURsfGZsX3Rlc3RfaDVvWXowdU9ZbWlobUIyaHpNc1hCeDM200NBzvUjqP",alt:"Cup of coffee"}},categorySection:{show:!0},nav:{title:"Your Next Store",searchBar:{show:!0},links:[{label:"Home",href:"/"},{label:"Apparel",href:"/category/apparel"},{label:"Accessories",href:"/category/accessories"}]},footer:{name:"Your Next Store",tagline:"Handcrafted with passion in California",newsletter:{show:!0},credits:!0,sections:[{header:"Products",links:[{label:"Apparel",href:"/category/apparel"},{label:"Accessories",href:"/category/accessories"}]},{header:"Support",links:[{label:"Features",href:"https://yournextstore.com/#features"},{label:"Pricing",href:"https://yournextstore.com/#pricing"},{label:"Contact Us",href:"mailto:hi@yournextstore.com"}]}]},pages:{"/about":{content:`# Header 1
1
+ import"server-only";var o=async()=>{let t={hero:{show:!0,title:"Discover our Curated Collection",description:"Explore our carefully selected products for your home and lifestyle.",button:{label:"Shop Now",path:"/"},image:{src:"https://files.stripe.com/links/MDB8YWNjdF8xT3BaeG5GSmNWbVh6bURsfGZsX3Rlc3RfaDVvWXowdU9ZbWlobUIyaHpNc1hCeDM200NBzvUjqP",alt:"Cup of coffee"}},categorySection:{show:!0},nav:{title:"Your Next Store",searchBar:{show:!0},links:[{label:"Home",href:"/"},{label:"Apparel",href:"/category/apparel"},{label:"Accessories",href:"/category/accessories"}]},footer:{name:"Your Next Store",tagline:"Handcrafted with passion in California",newsletter:{show:!0},credits:!0,sections:[{header:"Products",links:[{label:"Apparel",href:"/category/apparel"},{label:"Accessories",href:"/category/accessories"}]},{header:"Support",links:[{label:"Features",href:"https://yournextstore.com/#features"},{label:"Pricing",href:"https://yournextstore.com/#pricing"},{label:"Contact Us",href:"mailto:hi@yournextstore.com"}]}]},pages:{"/about":{content:`# Header 1
2
2
 
3
3
  ## Header 2
4
4
 
@@ -23,4 +23,4 @@ function hello() {
23
23
  console.log('Hello world!');
24
24
  }
25
25
  \`\`\`
26
- `}}},o={stripeAccount:void 0,storeId:void 0,secretKey:void 0,config:n},t=await global?.__ynsFindStripeAccount?.();return t?{...t,config:t.config??n}:o};export{s as configSchema,a as getYnsContext};
26
+ `}}},n={stripeAccount:void 0,storeId:void 0,secretKey:void 0,config:t},e=await global?.__ynsFindStripeAccount?.();return e?{...e,config:e.config??t}:n};export{o as getYnsContext};
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.0.18",
4
+ "version": "0.0.19",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-only",
7
7
  "keywords": [
@@ -35,6 +35,10 @@
35
35
  "import": "./dist/yns.js",
36
36
  "types": "./dist/yns.d.ts"
37
37
  },
38
+ "./browser": {
39
+ "import": "./dist/browser.js",
40
+ "types": "./dist/browser.d.ts"
41
+ },
38
42
  "./db": {
39
43
  "import": "./dist/db.js",
40
44
  "types": "./dist/db.d.ts"