@personizely/shopify-hydrogen 1.0.1 → 1.0.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.cjs +26 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +342 -0
- package/dist/index.mjs +22 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
package/dist/index.cjs
CHANGED
|
@@ -133,7 +133,20 @@ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
${f}
|
|
136
|
-
|
|
136
|
+
`,v=`
|
|
137
|
+
mutation cartAttributesUpdate($cartId: ID!, $attributes: [AttributeInput!]!) {
|
|
138
|
+
cartAttributesUpdate(cartId: $cartId, attributes: $attributes) {
|
|
139
|
+
cart {
|
|
140
|
+
...CartFragment
|
|
141
|
+
}
|
|
142
|
+
userErrors {
|
|
143
|
+
field
|
|
144
|
+
message
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
${f}
|
|
149
|
+
`;function y(e,t){return`gid://shopify/${t}/${e}`}function b(e){return Number(e.split(`/`).pop())}const x=`_ply_coupon`;var S=class{constructor(e,t,n){this.listeners=[],this.cart=null,this.storefrontClient=t,this.cartPromise=e,this.revalidate=n}updateCartData(e){this.cart=e,this.cartPromise=null}notifyListeners(){this.cart&&this.listeners.forEach(e=>{try{this.cart&&e(this.toCartData(this.cart))}catch(e){console.error(`Cart listener error:`,e)}})}isSynced(){return!!this.cart}onChange(e){return this.listeners.push(e),()=>{let t=this.listeners.indexOf(e);t>-1&&this.listeners.splice(t,1)}}async fetch(e=!0){return this.cart&&!e?this.toCartData(this.cart):this.cartPromise?(this.cart=await this.cartPromise,this.toCartData(this.cart)):this.cart?this.toCartData(this.cart):null}async update(e,t){if(!this.cart)throw Error(`Cart not initialized`);let n=this.cart.lines.nodes.map(e=>e.id);try{let r;switch(e){case`add`:r=await this.storefrontClient.mutate(m,{cartId:this.cart.id,lines:[{merchandiseId:y(t.id,`ProductVariant`),quantity:t.quantity||1,attributes:t.properties?Object.entries(t.properties).map(([e,t])=>({key:e,value:String(t)})):void 0}]}),r?.cartLinesAdd?.cart&&(this.cart=r.cartLinesAdd.cart,this.notifyListeners());break;case`update`:case`change`:if(t.updates){let e=[],n=[];Object.entries(t.updates).forEach(([t,r])=>{let i=this.cart.lines.nodes.find(e=>b(e.merchandise.id)===Number(t));i?e.push({id:i.id,quantity:Number(r)}):Number(r)>0&&n.push({merchandiseId:y(Number(t),`ProductVariant`),quantity:Number(r)})});let r=[];if(e.length>0&&r.push(this.storefrontClient.mutate(h,{cartId:this.cart.id,lines:e})),n.length>0&&r.push(this.storefrontClient.mutate(m,{cartId:this.cart.id,lines:n})),r.length>0){let e=await Promise.all(r),t=e[e.length-1];(t?.cartLinesUpdate?.cart||t?.cartLinesAdd?.cart)&&(this.cart=t.cartLinesUpdate?.cart||t.cartLinesAdd?.cart,this.notifyListeners())}}else t.id&&(r=await this.storefrontClient.mutate(h,{cartId:this.cart.id,lines:[{id:`gid://shopify/CartLine/${t.id}`,quantity:t.quantity}]}),r?.cartLinesUpdate?.cart&&(this.cart=r.cartLinesUpdate.cart,this.notifyListeners()));t.attributes&&this.cart&&(r=await this.storefrontClient.mutate(v,{cartId:this.cart.id,attributes:Object.entries(t.attributes).map(([e,t])=>({key:e,value:String(t)}))}),r?.cartAttributesUpdate?.cart&&(this.cart=r.cartAttributesUpdate.cart,this.notifyListeners())),t.discount&&this.cart&&(r=await this.storefrontClient.mutate(_,{cartId:this.cart.id,discountCodes:[t.discount]}),r?.cartDiscountCodesUpdate?.cart&&(this.cart=r.cartDiscountCodesUpdate.cart,this.notifyListeners()));break;case`clear`:r=await this.storefrontClient.mutate(g,{cartId:this.cart.id,lineIds:n}),r?.cartLinesRemove?.cart&&(this.cart=r.cartLinesRemove.cart,this.notifyListeners());break;default:console.warn(`Unknown cart action: ${e}`)}this.revalidate&&this.revalidate()}catch(e){throw console.error(`Cart update error:`,e),e}}async buy(e,t=1){if(!this.cart)return;let n=this.getCoupon(),r=this.cart.checkoutUrl||`/checkout`,i=n?`${r}?discount=${n}`:r;typeof window<`u`&&(window.location.href=i)}get(e){return this.cart?e?this.toCartData(this.cart)[e]:this.toCartData(this.cart):e?void 0:null}getToken(){return this.cart&&this.cart.id||null}getItemsIds(){return this.cart?this.cart.lines.nodes.map(e=>e.merchandise.product.id):[]}getCurrency(){return this.cart?this.cart.cost.totalAmount.currencyCode:`USD`}getValue(e){return this.cart?parseFloat(this.cart.cost.totalAmount.amount)*100:0}getSize(e=!1){return this.cart?e?new Set(this.cart.lines.nodes.map(e=>e.merchandise.product.id)).size:this.cart.totalQuantity:0}async fetchCollections(e=!1){return console.warn(`fetchCollections: Not implemented for Hydrogen. Use custom metafield query.`),{}}async applyCoupon(e,t){if(!this.cart)throw Error(`Cart not initialized`);d(x,e,t);try{let t=await this.storefrontClient.mutate(_,{cartId:this.cart.id,discountCodes:[e]});t?.cartDiscountCodesUpdate?.cart&&(this.cart=t.cartDiscountCodesUpdate.cart,this.notifyListeners()),this.revalidate&&this.revalidate()}catch(e){throw console.error(`Error applying coupon:`,e),e}}getCoupon(){return this.cart?this.cart.discountCodes&&this.cart.discountCodes.length>0?this.cart.discountCodes[0].code:u(x):null}toCartData(e){return{token:e.id,item_count:e.totalQuantity||0,items:(e.lines?.nodes||[]).map(e=>({id:b(e.id),product_id:b(e.merchandise.product.id),variant_id:b(e.merchandise.id),price:Number(e.merchandise.price.amount)*100,quantity:e.quantity})),total_price:Number(e.cost.totalAmount.amount)*100,discount_codes:e.discountCodes,attributes:e.attributes,note:e.note}}};const C=`
|
|
137
150
|
fragment ProductFragment on Product {
|
|
138
151
|
id
|
|
139
152
|
handle
|
|
@@ -221,28 +234,28 @@ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=
|
|
|
221
234
|
}
|
|
222
235
|
}
|
|
223
236
|
}
|
|
224
|
-
`,
|
|
237
|
+
`,w=`
|
|
225
238
|
query getProductByHandle($handle: String!) {
|
|
226
239
|
product(handle: $handle) {
|
|
227
240
|
...ProductFragment
|
|
228
241
|
}
|
|
229
242
|
}
|
|
230
|
-
${
|
|
231
|
-
`,
|
|
243
|
+
${C}
|
|
244
|
+
`,T=`
|
|
232
245
|
query getProductById($id: ID!) {
|
|
233
246
|
product(id: $id) {
|
|
234
247
|
...ProductFragment
|
|
235
248
|
}
|
|
236
249
|
}
|
|
237
|
-
${
|
|
238
|
-
`,
|
|
250
|
+
${C}
|
|
251
|
+
`,E=`
|
|
239
252
|
query getProductRecommendations($productId: ID!) {
|
|
240
253
|
productRecommendations(productId: $productId) {
|
|
241
254
|
...ProductFragment
|
|
242
255
|
}
|
|
243
256
|
}
|
|
244
|
-
${
|
|
245
|
-
`,
|
|
257
|
+
${C}
|
|
258
|
+
`,D=`
|
|
246
259
|
fragment CustomerFragment on Customer {
|
|
247
260
|
id
|
|
248
261
|
email
|
|
@@ -260,7 +273,7 @@ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=
|
|
|
260
273
|
zip
|
|
261
274
|
}
|
|
262
275
|
}
|
|
263
|
-
`,
|
|
276
|
+
`,O=`
|
|
264
277
|
fragment OrderFragment on Order {
|
|
265
278
|
id
|
|
266
279
|
orderNumber
|
|
@@ -290,7 +303,7 @@ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=
|
|
|
290
303
|
}
|
|
291
304
|
}
|
|
292
305
|
}
|
|
293
|
-
`,
|
|
306
|
+
`,k=`
|
|
294
307
|
query getCustomer($customerAccessToken: String!) {
|
|
295
308
|
customer(customerAccessToken: $customerAccessToken) {
|
|
296
309
|
...CustomerFragment
|
|
@@ -315,7 +328,7 @@ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=
|
|
|
315
328
|
}
|
|
316
329
|
}
|
|
317
330
|
|
|
318
|
-
`,
|
|
331
|
+
`,A=`
|
|
319
332
|
query getCustomerOrders($customerAccessToken: String!, $first: Int = 20) {
|
|
320
333
|
customer(customerAccessToken: $customerAccessToken) {
|
|
321
334
|
id
|
|
@@ -357,7 +370,7 @@ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=
|
|
|
357
370
|
}
|
|
358
371
|
}
|
|
359
372
|
|
|
360
|
-
`;var
|
|
373
|
+
`;var j=class{constructor(e,t){this.customerAccessToken=null,this.client=t,this.methods=e.methods,this.currency={active:`USD`,base:`USD`,rate:1,...e.currency},this.locale=e.locale||`en-US`,this.market=e.market||null,this.pageContext={pageType:void 0,product:null,collection:null}}setCustomerAccessToken(e){this.customerAccessToken=e}async fetchProduct(e){let t=await this.client.query(w,{handle:e});if(!t.product)throw Error(`Product not found: ${e}`);return this.toProductData(t.product)}async fetchProductCollections(e,t){let n;if(t?n=await this.client.query(T,{id:`gid://shopify/Product/${t}`}):e&&(n=await this.client.query(w,{handle:e})),!n||!n.product)throw Error(`Product not found: ${t}`);return n.product.collections.nodes.map(e=>b(e.id))}async fetchRecommendations(e,t){return{intent:t,products:(await this.client.query(E,{productId:`gid://shopify/Product/${e}`,intent:t})).productRecommendations.map(e=>this.toProductData(e))||[]}}buildProductPath(e){return typeof this.methods?.builtProductPath==`function`?this.methods.builtProductPath(e):`/products/${e.handle}`}convertToBaseCurrency(e){return this.currency.rate/e}convertFromBaseCurrency(e){return this.currency.rate*e}formatMoney(e,t=!0){return typeof this.methods?.formatMoney==`function`?this.methods.formatMoney(e,t):new Intl.NumberFormat(this.locale,{style:`currency`,currency:this.currency.active,maximumFractionDigits:t?void 0:0}).format(e/100)}async getCustomer(){if(!this.customerAccessToken)return null;try{return(await this.client.query(`
|
|
361
374
|
query getCustomer($customerAccessToken: String!) {
|
|
362
375
|
customer(customerAccessToken: $customerAccessToken) {
|
|
363
376
|
...CustomerFragment
|
|
@@ -382,5 +395,5 @@ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=
|
|
|
382
395
|
}
|
|
383
396
|
}
|
|
384
397
|
|
|
385
|
-
`,{customerAccessToken:this.customerAccessToken})).customer||null}catch(e){return console.error(`Error fetching customer:`,e),null}}getPageContext(){return this.pageContext}setPageContext(e){e.product&&(e.product.id=
|
|
398
|
+
`,{customerAccessToken:this.customerAccessToken})).customer||null}catch(e){return console.error(`Error fetching customer:`,e),null}}getPageContext(){return this.pageContext}setPageContext(e){e.product&&(e.product.id=b(String(e.product.id))),e.collection&&(e.collection.id=b(String(e.collection.id))),this.pageContext=e}getVisitorId(){return null}getMarket(){return this.market}getCurrencyRate(){return this.currency.rate}toProductData(e){return{id:b(e.id),handle:e.handle,title:e.title,available:e.availableForSale,requires_selling_plan:e.requiresSellingPlan,images:e.images.nodes.map(e=>e.url),variants:e.variants.nodes.map(e=>({id:b(e.id),title:e.title,available:e.availableForSale,price:Math.round(parseFloat(e.price.amount)*100),compare_at_price:e.compareAtPrice?Math.round(parseFloat(e.compareAtPrice.amount)*100):null,featured_image:e.image?{src:e.image.url}:null,selling_plan_allocations:e.sellingPlanAllocations?.edges?.map(e=>({selling_plan_id:e.node.sellingPlan.id}))||[]}))}}},M=class{constructor(e){this.storefrontAccessToken=e.storefrontAccessToken,this.shopDomain=e.shopDomain,this.apiVersion=e.apiVersion||`2024-01`,this.endpoint=`https://${this.shopDomain}/api/${this.apiVersion}/graphql.json`}async query(e,t){try{let n=await fetch(this.endpoint,{method:`POST`,headers:{"Content-Type":`application/json`,"X-Shopify-Storefront-Access-Token":this.storefrontAccessToken},body:JSON.stringify({query:e,variables:t})});if(!n.ok)throw Error(`Storefront API request failed: ${n.statusText}`);let r=await n.json();if(r.errors)throw Error(`GraphQL errors: ${JSON.stringify(r.errors)}`);return r.data}catch(e){throw console.error(`Storefront API error:`,e),e}}async mutate(e,t){return this.query(e,t)}};const N=(0,c.createContext)(null);function P({websiteApiKey:e,storefrontAccessToken:t,shopDomain:n,locale:r,currency:i,market:a,apiVersion:o,scriptBaseUrl:s,methods:u,children:d,customerAccessToken:f}){let p=(0,l.useMatches)().find(e=>e.id===`root`)?.loaderData?.cart,m=(0,l.useRevalidator)(),h=(0,c.useMemo)(()=>new M({storefrontAccessToken:t,shopDomain:n,apiVersion:o}),[t,n,o]),g=(0,c.useMemo)(()=>{let e=new j({locale:r,currency:i,market:a,methods:u},h);return f&&e.setCustomerAccessToken(f),e},[]),_=(0,c.useMemo)(()=>new S(p,h,m.revalidate),[]),v=(0,c.useRef)(null);(0,c.useEffect)(()=>{p.then(e=>{e&&e!==v.current&&(_.updateCartData(e),_.notifyListeners(),v.current=e)})},[p,_]);let y=(0,c.useRef)([]),b=(0,c.useRef)([]);(0,c.useEffect)(()=>{if(typeof window>`u`)return;window.__PLY_HYDROGEN_CONFIG__={cart:_,adapter:g,onCartAdd:e=>(y.current.push(e),()=>{let t=y.current.indexOf(e);t>-1&&y.current.splice(t,1)}),onCheckout:e=>(b.current.push(e),()=>{let t=b.current.indexOf(e);t>-1&&b.current.splice(t,1)})};let t=document.createElement(`script`);return t.src=`${s||`https://static.personizely.net`}/${e}.js`,document.head.appendChild(t),()=>{delete window.__PLY_HYDROGEN_CONFIG__,t&&t.remove()}},[]);let x=(0,c.useMemo)(()=>({cart:_,adapter:g,websiteApiKey:e,triggerCartAdd:async e=>{let t=!1;for(let n of y.current)try{await n(e)&&(t=!0)}catch(e){console.error(`Cart add callback error:`,e)}return t},triggerCheckout:async()=>{let e=!1;for(let t of b.current)try{await t()&&(e=!0)}catch(e){console.error(`Checkout callback error:`,e)}return e}}),[_,g,e]);return c.default.createElement(N.Provider,{value:x},d)}function F(){let e=(0,c.useContext)(N);if(!e)throw Error(`usePersonizely must be used within a PersonizelyProvider. Make sure your component is wrapped with <PersonizelyProvider>.`);return e}function I(){let e=F();return(0,c.useCallback)(async t=>typeof window>`u`?!1:await e.triggerCartAdd({...t,id:b(String(t.id)),variantId:b(String(t.variantId)),price:Number(t.price)*100}),[e])}function L(){let e=F();return(0,c.useCallback)(async()=>typeof window>`u`?!1:await e.triggerCheckout(),[e])}function R(e){F().adapter.setPageContext(e)}exports.Adapter=j,exports.Cart=S,exports.PersonizelyProvider=P,exports.useCartAdd=I,exports.useCheckout=L,exports.usePageContext=R,exports.usePersonizely=F;
|
|
386
399
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["result: any","linesToUpdate: any[]","linesToAdd: any[]","line","mutations: Promise<any>[]"],"sources":["../src/utils/cookies.ts","../src/graphql/queries/cart.ts","../src/utils/id.ts","../src/classes/Cart.ts","../src/graphql/queries/product.ts","../src/graphql/queries/customer.ts","../src/classes/Adapter.ts","../src/utils/storefront-client.ts","../src/components/PersonizelyProvider.tsx","../src/hooks/usePersonizely.ts","../src/hooks/useCartAdd.ts","../src/hooks/useCheckout.ts","../src/hooks/usePageContext.ts"],"sourcesContent":["/**\n * Cookie utilities for browser storage\n * Mirrors cookie helpers from snippet-manager\n */\n\n/**\n * Read a cookie value by name\n * @param name - Cookie name\n * @returns Cookie value or null if not found\n */\nexport function readCookie (name: string): string | null {\n if (typeof document === 'undefined') {\n return null\n }\n\n const nameEQ = name + '='\n const cookies = document.cookie.split(';')\n\n for (let i = 0; i < cookies.length; i++) {\n let cookie = cookies[i]\n while (cookie.charAt(0) === ' ') {\n cookie = cookie.substring(1, cookie.length)\n }\n if (cookie.indexOf(nameEQ) === 0) {\n return cookie.substring(nameEQ.length, cookie.length)\n }\n }\n\n return null\n}\n\n/**\n * Create/update a cookie\n * @param name - Cookie name\n * @param value - Cookie value\n * @param days - Expiration in days (optional, default: session cookie)\n * @param path - Cookie path (default: '/')\n */\nexport function createCookie (name: string,\n value: string,\n days?: number,\n path: string = '/'): void {\n if (typeof document === 'undefined') {\n return\n }\n\n let expires = ''\n if (days) {\n const date = new Date()\n date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000))\n expires = '; expires=' + date.toUTCString()\n }\n\n document.cookie = name + '=' + value + expires + '; path=' + path\n}\n\n/**\n * Delete a cookie by name\n * @param name - Cookie name\n * @param path - Cookie path (default: '/')\n */\nexport function deleteCookie (name: string, path: string = '/'): void {\n createCookie(name, '', -1, path)\n}\n","/**\n * GraphQL queries and mutations for cart operations\n */\n\nexport const CART_FRAGMENT = `\n fragment CartFragment on Cart {\n id\n checkoutUrl\n totalQuantity\n cost {\n subtotalAmount {\n amount\n currencyCode\n }\n totalAmount {\n amount\n currencyCode\n }\n totalTaxAmount {\n amount\n currencyCode\n }\n }\n lines(first: 100) {\n nodes {\n id\n quantity\n cost {\n totalAmount {\n amount\n currencyCode\n }\n amountPerQuantity {\n amount\n currencyCode\n }\n }\n merchandise {\n ... on ProductVariant {\n id\n title\n price {\n amount\n currencyCode\n }\n image {\n url\n altText\n }\n selectedOptions {\n name\n value\n }\n product {\n id\n handle\n title\n featuredImage {\n url\n altText\n }\n tags\n }\n }\n }\n attributes {\n key\n value\n }\n }\n }\n discountCodes {\n code\n applicable\n }\n attributes {\n key\n value\n }\n }\n`\n\nexport const GET_CART = `\n query getCart($cartId: ID!) {\n cart(id: $cartId) {\n ...CartFragment\n }\n }\n ${CART_FRAGMENT}\n`\n\n/**\n * Cart mutations\n */\n\nexport const CART_LINES_ADD = `\n mutation cartLinesAdd($cartId: ID!, $lines: [CartLineInput!]!) {\n cartLinesAdd(cartId: $cartId, lines: $lines) {\n cart {\n ...CartFragment\n }\n userErrors {\n field\n message\n }\n }\n }\n ${CART_FRAGMENT}\n`\n\nexport const CART_LINES_UPDATE = `\n mutation cartLinesUpdate($cartId: ID!, $lines: [CartLineUpdateInput!]!) {\n cartLinesUpdate(cartId: $cartId, lines: $lines) {\n cart {\n ...CartFragment\n }\n userErrors {\n field\n message\n }\n }\n }\n ${CART_FRAGMENT}\n`\n\nexport const CART_LINES_REMOVE = `\n mutation cartLinesRemove($cartId: ID!, $lineIds: [ID!]!) {\n cartLinesRemove(cartId: $cartId, lineIds: $lineIds) {\n cart {\n ...CartFragment\n }\n userErrors {\n field\n message\n }\n }\n }\n ${CART_FRAGMENT}\n`\n\nexport const CART_DISCOUNT_CODES_UPDATE = `\n mutation cartDiscountCodesUpdate($cartId: ID!, $discountCodes: [String!]!) {\n cartDiscountCodesUpdate(cartId: $cartId, discountCodes: $discountCodes) {\n cart {\n ...CartFragment\n }\n userErrors {\n field\n message\n }\n }\n }\n ${CART_FRAGMENT}\n`\n","export function toGId (id: number, type: string): string {\n return `gid://shopify/${type}/${id}`\n}\n\nexport function toId (id: string): number {\n return Number(id.split('/').pop())\n}","import type { CartData, ICart } from '../types'\nimport { createCookie, readCookie } from '../utils/cookies'\nimport type { CartReturn } from '@shopify/hydrogen'\nimport { StorefrontClient } from '../utils/storefront-client'\nimport {\n CART_LINES_ADD,\n CART_LINES_UPDATE,\n CART_LINES_REMOVE,\n CART_DISCOUNT_CODES_UPDATE\n} from '../graphql/queries/cart'\nimport { toGId, toId } from '../utils/id'\n\nconst COUPON_COOKIE_NAME = '_ply_coupon'\n\nexport class Cart implements ICart {\n private storefrontClient: StorefrontClient\n\n private listeners: Array<(cart: CartData) => void> = []\n\n private cart: CartReturn | null = null\n\n private cartPromise: Promise<CartReturn> | null\n\n private revalidate?: () => void\n\n constructor (cartPromise: Promise<CartReturn>, storefrontClient: StorefrontClient, revalidate?: () => void) {\n this.storefrontClient = storefrontClient\n this.cartPromise = cartPromise\n this.revalidate = revalidate\n }\n\n /**\n * Update internal cart data\n * Called by Provider when cart data changes from loader\n */\n updateCartData (cart: CartReturn): void {\n this.cart = cart\n this.cartPromise = null\n }\n\n /**\n * Notify all listeners of cart change\n * Called by Provider when cart updates\n */\n notifyListeners (): void {\n if (!this.cart) return\n\n this.listeners.forEach((listener) => {\n try {\n if (this.cart) {\n listener(this.toCartData(this.cart))\n }\n } catch (error) {\n console.error('Cart listener error:', error)\n }\n })\n }\n\n /**\n * Check if cart data is loaded and synced\n */\n isSynced (): boolean {\n return !!this.cart\n }\n\n /**\n * Register a callback to be called when cart changes\n * Returns a function to unregister the callback\n */\n onChange (callback: (cart: CartData) => void): () => void {\n this.listeners.push(callback)\n\n // Return unsubscribe function\n return () => {\n const index = this.listeners.indexOf(callback)\n if (index > -1) {\n this.listeners.splice(index, 1)\n }\n }\n }\n\n /**\n * Fetch current cart data\n * Returns cached cart data from loader (always fresh from React Router)\n */\n async fetch (force: boolean = true): Promise<CartData | null> {\n if (this.cart && !force) {\n return this.toCartData(this.cart)\n }\n\n if (this.cartPromise) {\n this.cart = await this.cartPromise\n return this.toCartData(this.cart)\n }\n\n if (!this.cart) return null\n\n return this.toCartData(this.cart)\n }\n\n /**\n * Update cart via Storefront API mutations\n * Actions: 'add', 'update', 'change', 'clear'\n */\n async update (action: string, data: any): Promise<void> {\n if (!this.cart) {\n throw new Error('Cart not initialized')\n }\n\n const lineIds = this.cart.lines.nodes.map((line: any) => line.id)\n\n try {\n let result: any\n\n switch (action) {\n case 'add':\n result = await this.storefrontClient.mutate(CART_LINES_ADD, {\n cartId: this.cart.id,\n lines: [{\n merchandiseId: toGId(data.id, 'ProductVariant'),\n quantity: data.quantity || 1,\n attributes: data.properties\n ? Object.entries(data.properties).map(([key, value]) => ({\n key,\n value: String(value)\n }))\n : undefined\n }]\n })\n\n // Update local cart immediately with mutation response\n if (result?.cartLinesAdd?.cart) {\n this.cart = result.cartLinesAdd.cart\n this.notifyListeners()\n }\n break\n\n case 'update':\n case 'change':\n // Handle Cart AJAX API format: { updates: { [variantId]: quantity } }\n if (data.updates) {\n // Separate into lines to update vs lines to add\n const linesToUpdate: any[] = []\n const linesToAdd: any[] = []\n\n Object.entries(data.updates).forEach(([variantId, quantity]) => {\n const line = this.cart!.lines.nodes.find((line: any) =>\n toId(line.merchandise.id) === Number(variantId))\n\n if (line) {\n linesToUpdate.push({\n id: line.id,\n quantity: Number(quantity)\n })\n } else if (Number(quantity) > 0) {\n // Line doesn't exist and quantity > 0 - add it\n linesToAdd.push({\n merchandiseId: toGId(Number(variantId), 'ProductVariant'),\n quantity: Number(quantity)\n })\n }\n })\n\n // Execute mutations in parallel\n const mutations: Promise<any>[] = []\n\n if (linesToUpdate.length > 0) {\n mutations.push(this.storefrontClient.mutate(CART_LINES_UPDATE, {\n cartId: this.cart.id,\n lines: linesToUpdate\n }))\n }\n\n if (linesToAdd.length > 0) {\n mutations.push(this.storefrontClient.mutate(CART_LINES_ADD, {\n cartId: this.cart.id,\n lines: linesToAdd\n }))\n }\n\n if (mutations.length > 0) {\n const results = await Promise.all(mutations)\n // Use the last result's cart (both mutations return the updated cart)\n const lastResult = results[results.length - 1]\n if (lastResult?.cartLinesUpdate?.cart || lastResult?.cartLinesAdd?.cart) {\n this.cart = lastResult.cartLinesUpdate?.cart || lastResult.cartLinesAdd?.cart\n this.notifyListeners()\n }\n }\n } else {\n // Handle single item update (old format)\n result = await this.storefrontClient.mutate(CART_LINES_UPDATE, {\n cartId: this.cart.id,\n lines: [{\n id: `gid://shopify/CartLine/${data.id}`,\n quantity: data.quantity\n }]\n })\n\n // Update local cart immediately with mutation response\n if (result?.cartLinesUpdate?.cart) {\n this.cart = result.cartLinesUpdate.cart\n this.notifyListeners()\n }\n }\n\n // Handle discount update\n if (data.discount && this.cart) {\n result = await this.storefrontClient.mutate(CART_DISCOUNT_CODES_UPDATE, {\n cartId: this.cart.id,\n discountCodes: [data.discount]\n })\n\n // Update local cart immediately\n if (result?.cartDiscountCodesUpdate?.cart) {\n this.cart = result.cartDiscountCodesUpdate.cart\n this.notifyListeners()\n }\n }\n break\n\n case 'clear':\n result = await this.storefrontClient.mutate(CART_LINES_REMOVE, {\n cartId: this.cart.id,\n lineIds\n })\n\n // Update local cart immediately with mutation response\n if (result?.cartLinesRemove?.cart) {\n this.cart = result.cartLinesRemove.cart\n this.notifyListeners()\n }\n break\n\n default:\n console.warn(`Unknown cart action: ${action}`)\n }\n\n // Trigger revalidation to fetch fresh cart data from loader\n if (this.revalidate) {\n this.revalidate()\n }\n } catch (error) {\n console.error('Cart update error:', error)\n throw error\n }\n }\n\n /**\n * Quick buy - redirect to checkout with variant\n */\n async buy (_variantId: string, _quantity: number = 1): Promise<void> {\n if (!this.cart) return\n\n const coupon = this.getCoupon()\n const baseUrl = this.cart.checkoutUrl || '/checkout'\n const url = coupon ? `${baseUrl}?discount=${coupon}` : baseUrl\n\n if (typeof window !== 'undefined') {\n window.location.href = url\n }\n }\n\n /**\n * Get cart data or specific property\n */\n get (property?: string): any {\n if (!this.cart) {\n return property ? undefined : null\n }\n\n if (!property) {\n return this.toCartData(this.cart)\n }\n\n return (this.toCartData(this.cart) as any)[property]\n }\n\n /**\n * Get cart token/ID\n */\n getToken (): string | null {\n if (!this.cart) return null\n\n return this.cart.id || null\n }\n\n /**\n * Get array of product IDs in cart\n */\n getItemsIds (): string[] {\n if (!this.cart) {\n return []\n }\n\n return this.cart.lines.nodes.map(line => line.merchandise.product.id)\n }\n\n /**\n * Get cart currency code\n */\n getCurrency (): string {\n if (!this.cart) return 'USD'\n\n return this.cart.cost.totalAmount.currencyCode\n }\n\n /**\n * Get cart total value\n * For Hydrogen, currency conversion would need to be handled separately\n */\n getValue (_currency?: string): number {\n if (!this.cart) return 0\n\n return parseFloat(this.cart.cost.totalAmount.amount) * 100\n }\n\n /**\n * Get cart item count\n * @param distinct - Count distinct products instead of total quantity\n */\n getSize (distinct: boolean = false): number {\n if (!this.cart) return 0\n\n if (distinct) {\n const uniqueProductIds = new Set(this.cart.lines.nodes.map(line => line.merchandise.product.id))\n return uniqueProductIds.size\n }\n\n return this.cart.totalQuantity\n }\n\n /**\n * Fetch cart collections data\n * Requires custom implementation or metafield query\n */\n async fetchCollections (_force: boolean = false): Promise<any> {\n console.warn('fetchCollections: Not implemented for Hydrogen. Use custom metafield query.')\n return {}\n }\n\n /**\n * Apply discount code to cart\n */\n async applyCoupon (code: string, expiresIn?: number): Promise<void> {\n if (!this.cart) {\n throw new Error('Cart not initialized')\n }\n\n // Store in cookie\n createCookie(COUPON_COOKIE_NAME, code, expiresIn)\n\n try {\n const result = await this.storefrontClient.mutate(CART_DISCOUNT_CODES_UPDATE, {\n cartId: this.cart.id,\n discountCodes: [code]\n })\n\n // Update local cart immediately with mutation response\n if (result?.cartDiscountCodesUpdate?.cart) {\n this.cart = result.cartDiscountCodesUpdate.cart\n this.notifyListeners()\n }\n\n // Trigger revalidation to fetch fresh cart data from loader (backup)\n if (this.revalidate) {\n this.revalidate()\n }\n } catch (error) {\n console.error('Error applying coupon:', error)\n throw error\n }\n }\n\n /**\n * Get currently applied coupon code\n */\n getCoupon (): string | null {\n if (!this.cart) return null\n\n // First check cart discount codes\n if (this.cart.discountCodes && this.cart.discountCodes.length > 0) {\n return this.cart.discountCodes[0].code\n }\n\n // Fall back to cookie\n return readCookie(COUPON_COOKIE_NAME)\n }\n\n /**\n * Convert Hydrogen cart to CartData format\n * For compatibility with snippet-manager\n */\n private toCartData (cart: CartReturn): CartData {\n return {\n token: cart.id,\n item_count: cart.totalQuantity || 0,\n items: (cart.lines?.nodes || []).map(line => ({\n id: toId(line.id),\n product_id: toId(line.merchandise.product.id),\n variant_id: toId(line.merchandise.id),\n price: Number(line.merchandise.price.amount) * 100,\n quantity: line.quantity\n })),\n total_price: Number(cart.cost.totalAmount.amount) * 100,\n discount_codes: cart.discountCodes,\n attributes: cart.attributes,\n note: cart.note\n }\n }\n}\n","/**\n * GraphQL queries for product operations\n */\n\nexport const PRODUCT_FRAGMENT = `\n fragment ProductFragment on Product {\n id\n handle\n title\n description\n descriptionHtml\n productType\n vendor\n tags\n availableForSale\n requiresSellingPlan\n priceRange {\n minVariantPrice {\n amount\n currencyCode\n }\n maxVariantPrice {\n amount\n currencyCode\n }\n }\n featuredImage {\n id\n url\n altText\n width\n height\n }\n images(first: 10) {\n nodes {\n id\n url\n altText\n width\n height\n }\n }\n variants(first: 100) {\n nodes {\n id\n title\n availableForSale\n quantityAvailable\n sellingPlanAllocations(first: 10) {\n edges {\n node {\n sellingPlan {\n id\n }\n }\n }\n }\n sku\n price {\n amount\n currencyCode\n }\n compareAtPrice {\n amount\n currencyCode\n }\n selectedOptions {\n name\n value\n }\n image {\n id\n url\n altText\n width\n height\n }\n }\n }\n options {\n id\n name\n values\n }\n collections(first: 10) {\n nodes {\n id\n handle\n title\n }\n }\n }\n`\n\nexport const GET_PRODUCT_BY_HANDLE = `\n query getProductByHandle($handle: String!) {\n product(handle: $handle) {\n ...ProductFragment\n }\n }\n ${PRODUCT_FRAGMENT}\n`\n\nexport const GET_PRODUCT_BY_ID = `\n query getProductById($id: ID!) {\n product(id: $id) {\n ...ProductFragment\n }\n }\n ${PRODUCT_FRAGMENT}\n`\n\nexport const GET_PRODUCT_RECOMMENDATIONS = `\n query getProductRecommendations($productId: ID!) {\n productRecommendations(productId: $productId) {\n ...ProductFragment\n }\n }\n ${PRODUCT_FRAGMENT}\n`\n","/**\n * GraphQL queries for customer operations\n */\n\nexport const CUSTOMER_FRAGMENT = `\n fragment CustomerFragment on Customer {\n id\n email\n phone\n firstName\n lastName\n displayName\n defaultAddress {\n id\n address1\n address2\n city\n province\n country\n zip\n }\n }\n`\n\nexport const ORDER_FRAGMENT = `\n fragment OrderFragment on Order {\n id\n orderNumber\n processedAt\n financialStatus\n fulfillmentStatus\n totalPrice {\n amount\n currencyCode\n }\n lineItems(first: 100) {\n nodes {\n title\n quantity\n variant {\n id\n title\n price {\n amount\n currencyCode\n }\n image {\n url\n altText\n }\n }\n }\n }\n }\n`\n\nexport const GET_CUSTOMER = `\n query getCustomer($customerAccessToken: String!) {\n customer(customerAccessToken: $customerAccessToken) {\n ...CustomerFragment\n }\n }\n ${CUSTOMER_FRAGMENT}\n`\n\nexport const GET_CUSTOMER_ORDERS = `\n query getCustomerOrders($customerAccessToken: String!, $first: Int = 20) {\n customer(customerAccessToken: $customerAccessToken) {\n id\n orders(first: $first, sortKey: PROCESSED_AT, reverse: true) {\n nodes {\n ...OrderFragment\n }\n }\n }\n }\n ${ORDER_FRAGMENT}\n`\n","import type {\n IShopifyAdapter,\n Product,\n Customer,\n PageContext,\n PersonizelyConfig,\n PersonizelyConfigMethods,\n ProductData\n} from '../types'\nimport { StorefrontClient } from '../utils/storefront-client'\nimport {\n GET_PRODUCT_BY_HANDLE, GET_PRODUCT_BY_ID,\n GET_PRODUCT_RECOMMENDATIONS\n} from '../graphql/queries/product'\nimport { GET_CUSTOMER } from '../graphql/queries/customer'\nimport { toId } from '../utils/id'\n\nexport class Adapter implements IShopifyAdapter {\n private client: StorefrontClient\n\n private currency: {\n active: string\n base: string\n rate: number\n }\n\n private market: string | null\n\n private locale: string\n\n private pageContext: PageContext\n\n private methods?: PersonizelyConfigMethods\n\n private customerAccessToken: string | null = null\n\n constructor (config: PersonizelyConfig, storefrontClient: StorefrontClient) {\n this.client = storefrontClient\n\n this.methods = config.methods\n this.currency = { active: 'USD', base: 'USD', rate: 1, ...config.currency }\n this.locale = config.locale || 'en-US'\n this.market = config.market || null\n\n this.pageContext = {\n pageType: undefined,\n product: null,\n collection: null\n }\n }\n\n /**\n * Set customer access token for authenticated requests\n */\n setCustomerAccessToken (token: string | null): void {\n this.customerAccessToken = token\n }\n\n /**\n * Fetch product by handle from Storefront API\n */\n async fetchProduct (handle: string): Promise<ProductData> {\n const data = await this.client.query<{ product: Product }>(GET_PRODUCT_BY_HANDLE, { handle })\n\n if (!data.product) {\n throw new Error(`Product not found: ${handle}`)\n }\n\n return this.toProductData(data.product)\n }\n\n /**\n * Fetch product collections metadata\n */\n async fetchProductCollections (handle: string, productId: number): Promise<number[]> {\n let data\n if (productId) {\n data = await this.client.query<{ product: Product }>(GET_PRODUCT_BY_ID, { id: `gid://shopify/Product/${productId}` })\n } else if (handle) {\n data = await this.client.query<{ product: Product }>(GET_PRODUCT_BY_HANDLE, { handle })\n }\n\n if (!data || !data.product) {\n throw new Error(`Product not found: ${productId}`)\n }\n\n return data.product.collections.nodes.map(c => toId(c.id))\n }\n\n /**\n * Fetch product recommendations\n */\n async fetchRecommendations (productId: number, intent: string): Promise<{ products: ProductData[], intent: string }> {\n const data = await this.client.query<{ productRecommendations: Product[] }>(GET_PRODUCT_RECOMMENDATIONS, { productId: `gid://shopify/Product/${productId}`, intent })\n\n return {\n intent,\n products: data.productRecommendations.map(p => this.toProductData(p)) || []\n }\n }\n\n /**\n * Build product URL path\n */\n buildProductPath (product: { handle: string }): string {\n if (typeof this.methods?.builtProductPath !== 'function') return `/products/${product.handle}`\n\n return this.methods.builtProductPath(product)\n }\n\n /**\n * Convert currency amount\n */\n convertToBaseCurrency (amount: number): number {\n return this.currency.rate / amount\n }\n\n /**\n * Convert currency amount\n */\n convertFromBaseCurrency (amount: number): number {\n return this.currency.rate * amount\n }\n\n /**\n * Format money according to shop's format\n */\n formatMoney (amount: number, includeDecimals: boolean = true): string {\n if (typeof this.methods?.formatMoney !== 'function') return new Intl.NumberFormat(this.locale, {\n style: 'currency',\n currency: this.currency.active,\n maximumFractionDigits: includeDecimals ? undefined : 0\n }).format(amount / 100)\n\n return this.methods.formatMoney(amount, includeDecimals)\n }\n\n /**\n * Fetch customer data from Storefront API\n * Requires customer access token to be set\n */\n async getCustomer (): Promise<Customer | null> {\n if (!this.customerAccessToken) {\n return null\n }\n\n try {\n const data = await this.client.query<{ customer: Customer }>(GET_CUSTOMER, { customerAccessToken: this.customerAccessToken })\n\n return data.customer || null\n } catch (error) {\n console.error('Error fetching customer:', error)\n return null\n }\n }\n\n /**\n * Get current page context\n * Auto-detected from Remix router in Provider\n */\n getPageContext (): PageContext {\n return this.pageContext\n }\n\n setPageContext (context: Partial<PageContext>) {\n if (context.product) {\n context.product.id = toId(String(context.product.id))\n }\n if (context.collection) {\n context.collection.id = toId(String(context.collection.id))\n }\n this.pageContext = context\n }\n\n getVisitorId (): string | null {\n return null\n }\n\n /**\n * Get current market information\n */\n getMarket (): string | null {\n return this.market\n }\n\n /**\n * Get currency conversion rate\n * Note: Stub implementation\n */\n getCurrencyRate (): number {\n return this.currency.rate\n }\n\n /**\n * Transform Hydrogen Product to snippet-manager ProductData format\n */\n toProductData (product: Product): ProductData {\n return {\n id: toId(product.id),\n handle: product.handle,\n title: product.title,\n available: product.availableForSale,\n requires_selling_plan: product.requiresSellingPlan,\n images: product.images.nodes.map(img => img.url),\n variants: product.variants.nodes.map(variant => ({\n id: toId(variant.id),\n title: variant.title,\n available: variant.availableForSale,\n price: Math.round(parseFloat(variant.price.amount) * 100), // Convert to cents\n compare_at_price: variant.compareAtPrice\n ? Math.round(parseFloat(variant.compareAtPrice.amount) * 100)\n : null,\n featured_image: variant.image ? { src: variant.image.url } : null,\n selling_plan_allocations: variant.sellingPlanAllocations?.edges?.map(edge => ({\n selling_plan_id: edge.node.sellingPlan.id\n })) || []\n }))\n }\n }\n}\n","/**\n * Shopify Storefront API GraphQL client\n */\n\nexport type StorefrontClientConfig = {\n storefrontAccessToken: string\n shopDomain: string\n apiVersion?: string\n}\n\nexport class StorefrontClient {\n private storefrontAccessToken: string\n\n private shopDomain: string\n\n private apiVersion: string\n\n private endpoint: string\n\n constructor (config: StorefrontClientConfig) {\n this.storefrontAccessToken = config.storefrontAccessToken\n this.shopDomain = config.shopDomain\n this.apiVersion = config.apiVersion || '2024-01'\n this.endpoint = `https://${this.shopDomain}/api/${this.apiVersion}/graphql.json`\n }\n\n /**\n * Execute a GraphQL query against the Storefront API\n */\n async query<T = any>(query: string, variables?: Record<string, any>): Promise<T> {\n try {\n const response = await fetch(this.endpoint, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Shopify-Storefront-Access-Token': this.storefrontAccessToken\n },\n body: JSON.stringify({\n query,\n variables\n })\n })\n\n if (!response.ok) {\n throw new Error(`Storefront API request failed: ${response.statusText}`)\n }\n\n const result = await response.json()\n\n if (result.errors) {\n throw new Error(`GraphQL errors: ${JSON.stringify(result.errors)}`)\n }\n\n return result.data as T\n } catch (error) {\n console.error('Storefront API error:', error)\n throw error\n }\n }\n\n /**\n * Execute a GraphQL mutation against the Storefront API\n */\n async mutate<T = any>(mutation: string, variables?: Record<string, any>): Promise<T> {\n return this.query<T>(mutation, variables)\n }\n}\n","import React, { createContext, useEffect, useMemo, useRef, ReactNode } from 'react'\nimport { useMatches, useRevalidator } from 'react-router'\nimport {\n PersonizelyConfigMethods,\n HydrogenConfig,\n CartAddProduct\n} from '../types'\nimport type { CartReturn } from '@shopify/hydrogen'\nimport { Cart } from '../classes/Cart'\nimport { Adapter } from '../classes/Adapter'\nimport { StorefrontClient } from '../utils/storefront-client'\n\ndeclare global {\n interface Window {\n __PLY_HYDROGEN_CONFIG__?: HydrogenConfig\n }\n}\n\nexport type PersonizelyContextType = {\n cart: Cart\n adapter: Adapter\n websiteApiKey: string\n triggerCartAdd: (product: CartAddProduct) => Promise<boolean>\n triggerCheckout: () => Promise<boolean>\n}\n\nexport const PersonizelyContext = createContext<PersonizelyContextType | null>(null)\n\nexport type PersonizelyProviderProps = {\n websiteApiKey: string\n storefrontAccessToken: string\n shopDomain: string\n apiVersion?: string\n scriptBaseUrl?: string\n locale?: string\n currency?: {\n rate: number\n active: string\n base: string\n }\n market?: string\n methods?: PersonizelyConfigMethods\n children: ReactNode\n /**\n * Optional: Customer access token for authenticated requests\n */\n customerAccessToken?: string | null\n}\n\nexport function PersonizelyProvider ({\n websiteApiKey,\n storefrontAccessToken,\n shopDomain,\n locale,\n currency,\n market,\n apiVersion,\n scriptBaseUrl,\n methods,\n children,\n customerAccessToken\n}: PersonizelyProviderProps) {\n const matches = useMatches()\n const rootMatch = matches.find(m => m.id === 'root')\n const localCart = (rootMatch?.loaderData as any)?.cart as Promise<CartReturn>\n const revalidator = useRevalidator()\n\n const storefrontClient = useMemo(() => {\n return new StorefrontClient({\n storefrontAccessToken,\n shopDomain,\n apiVersion\n })\n }, [storefrontAccessToken, shopDomain, apiVersion])\n\n const adapter = useMemo(() => {\n const adapterInstance = new Adapter({\n locale,\n currency,\n market,\n methods\n }, storefrontClient)\n\n if (customerAccessToken) {\n adapterInstance.setCustomerAccessToken(customerAccessToken)\n }\n\n return adapterInstance\n }, [])\n\n const cart = useMemo(() => new Cart(localCart, storefrontClient, revalidator.revalidate), [])\n\n // Update cart data when it changes from the loader\n const prevCartDataRef = useRef<CartReturn | null>(null)\n useEffect(() => {\n localCart.then((data) => {\n if (data && data !== prevCartDataRef.current) {\n cart.updateCartData(data)\n cart.notifyListeners()\n prevCartDataRef.current = data\n }\n })\n }, [localCart, cart])\n\n const cartAddCallbacksRef = useRef<Array<(product: CartAddProduct) => Promise<boolean>>>([])\n const checkoutCallbacksRef = useRef<Array<() => Promise<boolean>>>([])\n\n // Set up window.__PLY_HYDROGEN_CONFIG__ and load Personizely script\n useEffect(() => {\n if (typeof window === 'undefined') {\n return\n }\n\n window.__PLY_HYDROGEN_CONFIG__ = {\n cart,\n adapter,\n onCartAdd: (callback) => {\n cartAddCallbacksRef.current.push(callback)\n\n return () => {\n const index = cartAddCallbacksRef.current.indexOf(callback)\n if (index > -1) {\n cartAddCallbacksRef.current.splice(index, 1)\n }\n }\n },\n onCheckout: (callback) => {\n checkoutCallbacksRef.current.push(callback)\n\n return () => {\n const index = checkoutCallbacksRef.current.indexOf(callback)\n if (index > -1) {\n checkoutCallbacksRef.current.splice(index, 1)\n }\n }\n }\n }\n\n const script = document.createElement('script')\n const baseUrl = scriptBaseUrl || 'https://static.personizely.net'\n script.src = `${baseUrl}/${websiteApiKey}.js`\n document.head.appendChild(script)\n\n return () => {\n delete window.__PLY_HYDROGEN_CONFIG__\n if (script) {\n script.remove()\n }\n }\n }, [])\n\n const contextValue = useMemo(() => ({\n cart,\n adapter,\n websiteApiKey,\n triggerCartAdd: async (product: CartAddProduct): Promise<boolean> => {\n let shown = false\n for (const callback of cartAddCallbacksRef.current) {\n try {\n const result = await callback(product)\n if (result) {\n shown = true\n }\n } catch (error) {\n console.error('Cart add callback error:', error)\n }\n }\n return shown\n },\n triggerCheckout: async (): Promise<boolean> => {\n let shown = false\n for (const callback of checkoutCallbacksRef.current) {\n try {\n const result = await callback()\n if (result) {\n shown = true\n }\n } catch (error) {\n console.error('Checkout callback error:', error)\n }\n }\n return shown\n }\n }), [cart, adapter, websiteApiKey])\n\n return (\n <PersonizelyContext.Provider value={contextValue}>\n {children}\n </PersonizelyContext.Provider>\n )\n}\n","/**\n * usePersonizely - Access Personizely context\n */\n\nimport { useContext } from 'react'\nimport { PersonizelyContext, PersonizelyContextType } from '../components/PersonizelyProvider'\n\n/**\n * Hook to access Personizely context\n * Provides access to cart, adapter, and configuration\n *\n * @returns PersonizelyContextType\n * @throws Error if used outside PersonizelyProvider\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const { cart, adapter } = usePersonizely()\n * // Use cart and adapter...\n * }\n * ```\n */\nexport function usePersonizely (): PersonizelyContextType {\n const context = useContext(PersonizelyContext)\n\n if (!context) {\n throw new Error('usePersonizely must be used within a PersonizelyProvider. ' +\n 'Make sure your component is wrapped with <PersonizelyProvider>.')\n }\n\n return context\n}\n","/**\n * useCartAdd - Hook to trigger Personizely cart add widgets\n */\n\nimport { useCallback } from 'react'\nimport type { CartAddProduct } from '../types'\nimport { usePersonizely } from './usePersonizely'\nimport { toId } from '../utils/id'\n\n/**\n * Hook to trigger Personizely cart add event\n * Call this when a product is being added to cart to show relevant widgets\n *\n * @returns Function to trigger cart add event\n *\n * @example\n * ```tsx\n * function ProductForm({ product, selectedVariant }) {\n * const triggerCartAdd = useCartAdd()\n *\n * const handleAddToCart = async () => {\n * const widgetShown = await triggerCartAdd({\n * id: product.id,\n * variantId: selectedVariant.id,\n * price: parseFloat(selectedVariant.price.amount),\n * quantity: 1,\n * handle: product.handle\n * })\n *\n * if (!widgetShown) {\n * await cart.linesAdd([{\n * merchandiseId: selectedVariant.id,\n * quantity: 1\n * }])\n * }\n * }\n *\n * return <button onClick={handleAddToCart}>Add to Cart</button>\n * }\n * ```\n */\nexport function useCartAdd () {\n const personizely = usePersonizely()\n\n return useCallback(async (product: CartAddProduct): Promise<boolean> => {\n if (typeof window === 'undefined') {\n return false\n }\n\n return await personizely.triggerCartAdd({\n ...product,\n id: toId(String(product.id)),\n variantId: toId(String(product.variantId)),\n price: Number(product.price) * 100\n })\n }, [personizely])\n}\n","/**\n * useCheckout - Hook to trigger Personizely checkout widgets\n */\n\nimport { useCallback } from 'react'\nimport { usePersonizely } from './usePersonizely'\n\n/**\n * Hook to trigger Personizely checkout event\n * Call this when proceeding to checkout to show relevant widgets\n *\n * @returns Function to trigger checkout event\n *\n * @example\n * ```tsx\n * function CheckoutButton() {\n * const triggerCheckout = useCheckout()\n *\n * const handleCheckout = async () => {\n * const widgetShown = await triggerCheckout()\n *\n * if (!widgetShown) {\n * window.location.href = cart.checkoutUrl\n * }\n * }\n *\n * return <button onClick={handleCheckout}>Checkout</button>\n * }\n * ```\n */\nexport function useCheckout () {\n const personizely = usePersonizely()\n\n return useCallback(async (): Promise<boolean> => {\n if (typeof window === 'undefined') {\n return false\n }\n\n return await personizely.triggerCheckout()\n }, [personizely])\n}\n","import { usePersonizely } from './usePersonizely'\nimport { PageContext } from '../types'\n\nexport function usePageContext (context: Partial<PageContext>) {\n const personizely = usePersonizely()\n\n personizely.adapter.setPageContext(context)\n}\n"],"mappings":"0hBAUA,SAAgB,EAAY,EAA6B,CACvD,GAAI,OAAO,SAAa,IACtB,OAAO,KAGT,IAAM,EAAS,EAAO,IAChB,EAAU,SAAS,OAAO,MAAM,IAAI,CAE1C,IAAK,IAAI,EAAI,EAAG,EAAI,EAAQ,OAAQ,IAAK,CACvC,IAAI,EAAS,EAAQ,GACrB,KAAO,EAAO,OAAO,EAAE,GAAK,KAC1B,EAAS,EAAO,UAAU,EAAG,EAAO,OAAO,CAE7C,GAAI,EAAO,QAAQ,EAAO,GAAK,EAC7B,OAAO,EAAO,UAAU,EAAO,OAAQ,EAAO,OAAO,CAIzD,OAAO,KAUT,SAAgB,EAAc,EAC5B,EACA,EACA,EAAe,IAAW,CAC1B,GAAI,OAAO,SAAa,IACtB,OAGF,IAAI,EAAU,GACd,GAAI,EAAM,CACR,IAAM,EAAO,IAAI,KACjB,EA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","line","mutations: Promise<any>[]"],"sources":["../src/utils/cookies.ts","../src/graphql/queries/cart.ts","../src/utils/id.ts","../src/classes/Cart.ts","../src/graphql/queries/product.ts","../src/graphql/queries/customer.ts","../src/classes/Adapter.ts","../src/utils/storefront-client.ts","../src/components/PersonizelyProvider.tsx","../src/hooks/usePersonizely.ts","../src/hooks/useCartAdd.ts","../src/hooks/useCheckout.ts","../src/hooks/usePageContext.ts"],"sourcesContent":["/**\n * Cookie utilities for browser storage\n * Mirrors cookie helpers from snippet-manager\n */\n\n/**\n * Read a cookie value by name\n * @param name - Cookie name\n * @returns Cookie value or null if not found\n */\nexport function readCookie (name: string): string | null {\n if (typeof document === 'undefined') {\n return null\n }\n\n const nameEQ = name + '='\n const cookies = document.cookie.split(';')\n\n for (let i = 0; i < cookies.length; i++) {\n let cookie = cookies[i]\n while (cookie.charAt(0) === ' ') {\n cookie = cookie.substring(1, cookie.length)\n }\n if (cookie.indexOf(nameEQ) === 0) {\n return cookie.substring(nameEQ.length, cookie.length)\n }\n }\n\n return null\n}\n\n/**\n * Create/update a cookie\n * @param name - Cookie name\n * @param value - Cookie value\n * @param days - Expiration in days (optional, default: session cookie)\n * @param path - Cookie path (default: '/')\n */\nexport function createCookie (name: string,\n value: string,\n days?: number,\n path: string = '/'): void {\n if (typeof document === 'undefined') {\n return\n }\n\n let expires = ''\n if (days) {\n const date = new Date()\n date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000))\n expires = '; expires=' + date.toUTCString()\n }\n\n document.cookie = name + '=' + value + expires + '; path=' + path\n}\n\n/**\n * Delete a cookie by name\n * @param name - Cookie name\n * @param path - Cookie path (default: '/')\n */\nexport function deleteCookie (name: string, path: string = '/'): void {\n createCookie(name, '', -1, path)\n}\n","/**\n * GraphQL queries and mutations for cart operations\n */\n\nexport const CART_FRAGMENT = `\n fragment CartFragment on Cart {\n id\n checkoutUrl\n totalQuantity\n cost {\n subtotalAmount {\n amount\n currencyCode\n }\n totalAmount {\n amount\n currencyCode\n }\n totalTaxAmount {\n amount\n currencyCode\n }\n }\n lines(first: 100) {\n nodes {\n id\n quantity\n cost {\n totalAmount {\n amount\n currencyCode\n }\n amountPerQuantity {\n amount\n currencyCode\n }\n }\n merchandise {\n ... on ProductVariant {\n id\n title\n price {\n amount\n currencyCode\n }\n image {\n url\n altText\n }\n selectedOptions {\n name\n value\n }\n product {\n id\n handle\n title\n featuredImage {\n url\n altText\n }\n tags\n }\n }\n }\n attributes {\n key\n value\n }\n }\n }\n discountCodes {\n code\n applicable\n }\n attributes {\n key\n value\n }\n }\n`\n\nexport const GET_CART = `\n query getCart($cartId: ID!) {\n cart(id: $cartId) {\n ...CartFragment\n }\n }\n ${CART_FRAGMENT}\n`\n\n/**\n * Cart mutations\n */\n\nexport const CART_LINES_ADD = `\n mutation cartLinesAdd($cartId: ID!, $lines: [CartLineInput!]!) {\n cartLinesAdd(cartId: $cartId, lines: $lines) {\n cart {\n ...CartFragment\n }\n userErrors {\n field\n message\n }\n }\n }\n ${CART_FRAGMENT}\n`\n\nexport const CART_LINES_UPDATE = `\n mutation cartLinesUpdate($cartId: ID!, $lines: [CartLineUpdateInput!]!) {\n cartLinesUpdate(cartId: $cartId, lines: $lines) {\n cart {\n ...CartFragment\n }\n userErrors {\n field\n message\n }\n }\n }\n ${CART_FRAGMENT}\n`\n\nexport const CART_LINES_REMOVE = `\n mutation cartLinesRemove($cartId: ID!, $lineIds: [ID!]!) {\n cartLinesRemove(cartId: $cartId, lineIds: $lineIds) {\n cart {\n ...CartFragment\n }\n userErrors {\n field\n message\n }\n }\n }\n ${CART_FRAGMENT}\n`\n\nexport const CART_DISCOUNT_CODES_UPDATE = `\n mutation cartDiscountCodesUpdate($cartId: ID!, $discountCodes: [String!]!) {\n cartDiscountCodesUpdate(cartId: $cartId, discountCodes: $discountCodes) {\n cart {\n ...CartFragment\n }\n userErrors {\n field\n message\n }\n }\n }\n ${CART_FRAGMENT}\n`\n\nexport const CART_ATTRIBUTES_UPDATE = `\n mutation cartAttributesUpdate($cartId: ID!, $attributes: [AttributeInput!]!) {\n cartAttributesUpdate(cartId: $cartId, attributes: $attributes) {\n cart {\n ...CartFragment\n }\n userErrors {\n field\n message\n }\n }\n }\n ${CART_FRAGMENT}\n`\n","export function toGId (id: number, type: string): string {\n return `gid://shopify/${type}/${id}`\n}\n\nexport function toId (id: string): number {\n return Number(id.split('/').pop())\n}","import type { CartData, ICart } from '../types'\nimport { createCookie, readCookie } from '../utils/cookies'\nimport type { CartReturn } from '@shopify/hydrogen'\nimport { StorefrontClient } from '../utils/storefront-client'\nimport {\n CART_LINES_ADD,\n CART_LINES_UPDATE,\n CART_LINES_REMOVE,\n CART_DISCOUNT_CODES_UPDATE,\n CART_ATTRIBUTES_UPDATE\n} from '../graphql/queries/cart'\nimport { toGId, toId } from '../utils/id'\n\nconst COUPON_COOKIE_NAME = '_ply_coupon'\n\nexport class Cart implements ICart {\n private storefrontClient: StorefrontClient\n\n private listeners: Array<(cart: CartData) => void> = []\n\n private cart: CartReturn | null = null\n\n private cartPromise: Promise<CartReturn> | null\n\n private revalidate?: () => void\n\n constructor (cartPromise: Promise<CartReturn>, storefrontClient: StorefrontClient, revalidate?: () => void) {\n this.storefrontClient = storefrontClient\n this.cartPromise = cartPromise\n this.revalidate = revalidate\n }\n\n /**\n * Update internal cart data\n * Called by Provider when cart data changes from loader\n */\n updateCartData (cart: CartReturn): void {\n this.cart = cart\n this.cartPromise = null\n }\n\n /**\n * Notify all listeners of cart change\n * Called by Provider when cart updates\n */\n notifyListeners (): void {\n if (!this.cart) return\n\n this.listeners.forEach((listener) => {\n try {\n if (this.cart) {\n listener(this.toCartData(this.cart))\n }\n } catch (error) {\n console.error('Cart listener error:', error)\n }\n })\n }\n\n /**\n * Check if cart data is loaded and synced\n */\n isSynced (): boolean {\n return !!this.cart\n }\n\n /**\n * Register a callback to be called when cart changes\n * Returns a function to unregister the callback\n */\n onChange (callback: (cart: CartData) => void): () => void {\n this.listeners.push(callback)\n\n // Return unsubscribe function\n return () => {\n const index = this.listeners.indexOf(callback)\n if (index > -1) {\n this.listeners.splice(index, 1)\n }\n }\n }\n\n /**\n * Fetch current cart data\n * Returns cached cart data from loader (always fresh from React Router)\n */\n async fetch (force: boolean = true): Promise<CartData | null> {\n if (this.cart && !force) {\n return this.toCartData(this.cart)\n }\n\n if (this.cartPromise) {\n this.cart = await this.cartPromise\n return this.toCartData(this.cart)\n }\n\n if (!this.cart) return null\n\n return this.toCartData(this.cart)\n }\n\n /**\n * Update cart via Storefront API mutations\n * Actions: 'add', 'update', 'change', 'clear'\n */\n async update (action: string, data: any): Promise<void> {\n if (!this.cart) {\n throw new Error('Cart not initialized')\n }\n\n const lineIds = this.cart.lines.nodes.map((line: any) => line.id)\n\n try {\n let result: any\n\n switch (action) {\n case 'add':\n result = await this.storefrontClient.mutate(CART_LINES_ADD, {\n cartId: this.cart.id,\n lines: [{\n merchandiseId: toGId(data.id, 'ProductVariant'),\n quantity: data.quantity || 1,\n attributes: data.properties\n ? Object.entries(data.properties).map(([key, value]) => ({\n key,\n value: String(value)\n }))\n : undefined\n }]\n })\n\n // Update local cart immediately with mutation response\n if (result?.cartLinesAdd?.cart) {\n this.cart = result.cartLinesAdd.cart\n this.notifyListeners()\n }\n break\n\n case 'update':\n case 'change':\n // Handle Cart AJAX API format: { updates: { [variantId]: quantity }, attributes: {...} }\n if (data.updates) {\n // Separate into lines to update vs lines to add\n const linesToUpdate: any[] = []\n const linesToAdd: any[] = []\n\n Object.entries(data.updates).forEach(([variantId, quantity]) => {\n const line = this.cart!.lines.nodes.find((line: any) =>\n toId(line.merchandise.id) === Number(variantId))\n\n if (line) {\n linesToUpdate.push({\n id: line.id,\n quantity: Number(quantity)\n })\n } else if (Number(quantity) > 0) {\n // Line doesn't exist and quantity > 0 - add it\n linesToAdd.push({\n merchandiseId: toGId(Number(variantId), 'ProductVariant'),\n quantity: Number(quantity)\n })\n }\n })\n\n // Execute mutations in parallel\n const mutations: Promise<any>[] = []\n\n if (linesToUpdate.length > 0) {\n mutations.push(this.storefrontClient.mutate(CART_LINES_UPDATE, {\n cartId: this.cart.id,\n lines: linesToUpdate\n }))\n }\n\n if (linesToAdd.length > 0) {\n mutations.push(this.storefrontClient.mutate(CART_LINES_ADD, {\n cartId: this.cart.id,\n lines: linesToAdd\n }))\n }\n\n if (mutations.length > 0) {\n const results = await Promise.all(mutations)\n // Use the last result's cart (both mutations return the updated cart)\n const lastResult = results[results.length - 1]\n if (lastResult?.cartLinesUpdate?.cart || lastResult?.cartLinesAdd?.cart) {\n this.cart = lastResult.cartLinesUpdate?.cart || lastResult.cartLinesAdd?.cart\n this.notifyListeners()\n }\n }\n } else if (data.id) {\n // Handle single line item update\n result = await this.storefrontClient.mutate(CART_LINES_UPDATE, {\n cartId: this.cart.id,\n lines: [{\n id: `gid://shopify/CartLine/${data.id}`,\n quantity: data.quantity\n }]\n })\n\n // Update local cart immediately with mutation response\n if (result?.cartLinesUpdate?.cart) {\n this.cart = result.cartLinesUpdate.cart\n this.notifyListeners()\n }\n }\n\n // Handle cart-level attributes update\n if (data.attributes && this.cart) {\n result = await this.storefrontClient.mutate(CART_ATTRIBUTES_UPDATE, {\n cartId: this.cart.id,\n attributes: Object.entries(data.attributes).map(([key, value]) => ({\n key,\n value: String(value)\n }))\n })\n\n // Update local cart immediately\n if (result?.cartAttributesUpdate?.cart) {\n this.cart = result.cartAttributesUpdate.cart\n this.notifyListeners()\n }\n }\n\n // Handle discount update\n if (data.discount && this.cart) {\n result = await this.storefrontClient.mutate(CART_DISCOUNT_CODES_UPDATE, {\n cartId: this.cart.id,\n discountCodes: [data.discount]\n })\n\n // Update local cart immediately\n if (result?.cartDiscountCodesUpdate?.cart) {\n this.cart = result.cartDiscountCodesUpdate.cart\n this.notifyListeners()\n }\n }\n break\n\n case 'clear':\n result = await this.storefrontClient.mutate(CART_LINES_REMOVE, {\n cartId: this.cart.id,\n lineIds\n })\n\n // Update local cart immediately with mutation response\n if (result?.cartLinesRemove?.cart) {\n this.cart = result.cartLinesRemove.cart\n this.notifyListeners()\n }\n break\n\n default:\n console.warn(`Unknown cart action: ${action}`)\n }\n\n // Trigger revalidation to fetch fresh cart data from loader\n if (this.revalidate) {\n this.revalidate()\n }\n } catch (error) {\n console.error('Cart update error:', error)\n throw error\n }\n }\n\n /**\n * Quick buy - redirect to checkout with variant\n */\n async buy (_variantId: string, _quantity: number = 1): Promise<void> {\n if (!this.cart) return\n\n const coupon = this.getCoupon()\n const baseUrl = this.cart.checkoutUrl || '/checkout'\n const url = coupon ? `${baseUrl}?discount=${coupon}` : baseUrl\n\n if (typeof window !== 'undefined') {\n window.location.href = url\n }\n }\n\n /**\n * Get cart data or specific property\n */\n get (property?: string): any {\n if (!this.cart) {\n return property ? undefined : null\n }\n\n if (!property) {\n return this.toCartData(this.cart)\n }\n\n return (this.toCartData(this.cart) as any)[property]\n }\n\n /**\n * Get cart token/ID\n */\n getToken (): string | null {\n if (!this.cart) return null\n\n return this.cart.id || null\n }\n\n /**\n * Get array of product IDs in cart\n */\n getItemsIds (): string[] {\n if (!this.cart) {\n return []\n }\n\n return this.cart.lines.nodes.map(line => line.merchandise.product.id)\n }\n\n /**\n * Get cart currency code\n */\n getCurrency (): string {\n if (!this.cart) return 'USD'\n\n return this.cart.cost.totalAmount.currencyCode\n }\n\n /**\n * Get cart total value\n * For Hydrogen, currency conversion would need to be handled separately\n */\n getValue (_currency?: string): number {\n if (!this.cart) return 0\n\n return parseFloat(this.cart.cost.totalAmount.amount) * 100\n }\n\n /**\n * Get cart item count\n * @param distinct - Count distinct products instead of total quantity\n */\n getSize (distinct: boolean = false): number {\n if (!this.cart) return 0\n\n if (distinct) {\n const uniqueProductIds = new Set(this.cart.lines.nodes.map(line => line.merchandise.product.id))\n return uniqueProductIds.size\n }\n\n return this.cart.totalQuantity\n }\n\n /**\n * Fetch cart collections data\n * Requires custom implementation or metafield query\n */\n async fetchCollections (_force: boolean = false): Promise<any> {\n console.warn('fetchCollections: Not implemented for Hydrogen. Use custom metafield query.')\n return {}\n }\n\n /**\n * Apply discount code to cart\n */\n async applyCoupon (code: string, expiresIn?: number): Promise<void> {\n if (!this.cart) {\n throw new Error('Cart not initialized')\n }\n\n // Store in cookie\n createCookie(COUPON_COOKIE_NAME, code, expiresIn)\n\n try {\n const result = await this.storefrontClient.mutate(CART_DISCOUNT_CODES_UPDATE, {\n cartId: this.cart.id,\n discountCodes: [code]\n })\n\n // Update local cart immediately with mutation response\n if (result?.cartDiscountCodesUpdate?.cart) {\n this.cart = result.cartDiscountCodesUpdate.cart\n this.notifyListeners()\n }\n\n // Trigger revalidation to fetch fresh cart data from loader (backup)\n if (this.revalidate) {\n this.revalidate()\n }\n } catch (error) {\n console.error('Error applying coupon:', error)\n throw error\n }\n }\n\n /**\n * Get currently applied coupon code\n */\n getCoupon (): string | null {\n if (!this.cart) return null\n\n // First check cart discount codes\n if (this.cart.discountCodes && this.cart.discountCodes.length > 0) {\n return this.cart.discountCodes[0].code\n }\n\n // Fall back to cookie\n return readCookie(COUPON_COOKIE_NAME)\n }\n\n /**\n * Convert Hydrogen cart to CartData format\n * For compatibility with snippet-manager\n */\n private toCartData (cart: CartReturn): CartData {\n return {\n token: cart.id,\n item_count: cart.totalQuantity || 0,\n items: (cart.lines?.nodes || []).map(line => ({\n id: toId(line.id),\n product_id: toId(line.merchandise.product.id),\n variant_id: toId(line.merchandise.id),\n price: Number(line.merchandise.price.amount) * 100,\n quantity: line.quantity\n })),\n total_price: Number(cart.cost.totalAmount.amount) * 100,\n discount_codes: cart.discountCodes,\n attributes: cart.attributes,\n note: cart.note\n }\n }\n}\n","/**\n * GraphQL queries for product operations\n */\n\nexport const PRODUCT_FRAGMENT = `\n fragment ProductFragment on Product {\n id\n handle\n title\n description\n descriptionHtml\n productType\n vendor\n tags\n availableForSale\n requiresSellingPlan\n priceRange {\n minVariantPrice {\n amount\n currencyCode\n }\n maxVariantPrice {\n amount\n currencyCode\n }\n }\n featuredImage {\n id\n url\n altText\n width\n height\n }\n images(first: 10) {\n nodes {\n id\n url\n altText\n width\n height\n }\n }\n variants(first: 100) {\n nodes {\n id\n title\n availableForSale\n quantityAvailable\n sellingPlanAllocations(first: 10) {\n edges {\n node {\n sellingPlan {\n id\n }\n }\n }\n }\n sku\n price {\n amount\n currencyCode\n }\n compareAtPrice {\n amount\n currencyCode\n }\n selectedOptions {\n name\n value\n }\n image {\n id\n url\n altText\n width\n height\n }\n }\n }\n options {\n id\n name\n values\n }\n collections(first: 10) {\n nodes {\n id\n handle\n title\n }\n }\n }\n`\n\nexport const GET_PRODUCT_BY_HANDLE = `\n query getProductByHandle($handle: String!) {\n product(handle: $handle) {\n ...ProductFragment\n }\n }\n ${PRODUCT_FRAGMENT}\n`\n\nexport const GET_PRODUCT_BY_ID = `\n query getProductById($id: ID!) {\n product(id: $id) {\n ...ProductFragment\n }\n }\n ${PRODUCT_FRAGMENT}\n`\n\nexport const GET_PRODUCT_RECOMMENDATIONS = `\n query getProductRecommendations($productId: ID!) {\n productRecommendations(productId: $productId) {\n ...ProductFragment\n }\n }\n ${PRODUCT_FRAGMENT}\n`\n","/**\n * GraphQL queries for customer operations\n */\n\nexport const CUSTOMER_FRAGMENT = `\n fragment CustomerFragment on Customer {\n id\n email\n phone\n firstName\n lastName\n displayName\n defaultAddress {\n id\n address1\n address2\n city\n province\n country\n zip\n }\n }\n`\n\nexport const ORDER_FRAGMENT = `\n fragment OrderFragment on Order {\n id\n orderNumber\n processedAt\n financialStatus\n fulfillmentStatus\n totalPrice {\n amount\n currencyCode\n }\n lineItems(first: 100) {\n nodes {\n title\n quantity\n variant {\n id\n title\n price {\n amount\n currencyCode\n }\n image {\n url\n altText\n }\n }\n }\n }\n }\n`\n\nexport const GET_CUSTOMER = `\n query getCustomer($customerAccessToken: String!) {\n customer(customerAccessToken: $customerAccessToken) {\n ...CustomerFragment\n }\n }\n ${CUSTOMER_FRAGMENT}\n`\n\nexport const GET_CUSTOMER_ORDERS = `\n query getCustomerOrders($customerAccessToken: String!, $first: Int = 20) {\n customer(customerAccessToken: $customerAccessToken) {\n id\n orders(first: $first, sortKey: PROCESSED_AT, reverse: true) {\n nodes {\n ...OrderFragment\n }\n }\n }\n }\n ${ORDER_FRAGMENT}\n`\n","import type {\n IShopifyAdapter,\n Product,\n Customer,\n PageContext,\n PersonizelyConfig,\n PersonizelyConfigMethods,\n ProductData\n} from '../types'\nimport { StorefrontClient } from '../utils/storefront-client'\nimport {\n GET_PRODUCT_BY_HANDLE, GET_PRODUCT_BY_ID,\n GET_PRODUCT_RECOMMENDATIONS\n} from '../graphql/queries/product'\nimport { GET_CUSTOMER } from '../graphql/queries/customer'\nimport { toId } from '../utils/id'\n\nexport class Adapter implements IShopifyAdapter {\n private client: StorefrontClient\n\n private currency: {\n active: string\n base: string\n rate: number\n }\n\n private market: string | null\n\n private locale: string\n\n private pageContext: PageContext\n\n private methods?: PersonizelyConfigMethods\n\n private customerAccessToken: string | null = null\n\n constructor (config: PersonizelyConfig, storefrontClient: StorefrontClient) {\n this.client = storefrontClient\n\n this.methods = config.methods\n this.currency = { active: 'USD', base: 'USD', rate: 1, ...config.currency }\n this.locale = config.locale || 'en-US'\n this.market = config.market || null\n\n this.pageContext = {\n pageType: undefined,\n product: null,\n collection: null\n }\n }\n\n /**\n * Set customer access token for authenticated requests\n */\n setCustomerAccessToken (token: string | null): void {\n this.customerAccessToken = token\n }\n\n /**\n * Fetch product by handle from Storefront API\n */\n async fetchProduct (handle: string): Promise<ProductData> {\n const data = await this.client.query<{ product: Product }>(GET_PRODUCT_BY_HANDLE, { handle })\n\n if (!data.product) {\n throw new Error(`Product not found: ${handle}`)\n }\n\n return this.toProductData(data.product)\n }\n\n /**\n * Fetch product collections metadata\n */\n async fetchProductCollections (handle: string, productId: number): Promise<number[]> {\n let data\n if (productId) {\n data = await this.client.query<{ product: Product }>(GET_PRODUCT_BY_ID, { id: `gid://shopify/Product/${productId}` })\n } else if (handle) {\n data = await this.client.query<{ product: Product }>(GET_PRODUCT_BY_HANDLE, { handle })\n }\n\n if (!data || !data.product) {\n throw new Error(`Product not found: ${productId}`)\n }\n\n return data.product.collections.nodes.map(c => toId(c.id))\n }\n\n /**\n * Fetch product recommendations\n */\n async fetchRecommendations (productId: number, intent: string): Promise<{ products: ProductData[], intent: string }> {\n const data = await this.client.query<{ productRecommendations: Product[] }>(GET_PRODUCT_RECOMMENDATIONS, { productId: `gid://shopify/Product/${productId}`, intent })\n\n return {\n intent,\n products: data.productRecommendations.map(p => this.toProductData(p)) || []\n }\n }\n\n /**\n * Build product URL path\n */\n buildProductPath (product: { handle: string }): string {\n if (typeof this.methods?.builtProductPath !== 'function') return `/products/${product.handle}`\n\n return this.methods.builtProductPath(product)\n }\n\n /**\n * Convert currency amount\n */\n convertToBaseCurrency (amount: number): number {\n return this.currency.rate / amount\n }\n\n /**\n * Convert currency amount\n */\n convertFromBaseCurrency (amount: number): number {\n return this.currency.rate * amount\n }\n\n /**\n * Format money according to shop's format\n */\n formatMoney (amount: number, includeDecimals: boolean = true): string {\n if (typeof this.methods?.formatMoney !== 'function') return new Intl.NumberFormat(this.locale, {\n style: 'currency',\n currency: this.currency.active,\n maximumFractionDigits: includeDecimals ? undefined : 0\n }).format(amount / 100)\n\n return this.methods.formatMoney(amount, includeDecimals)\n }\n\n /**\n * Fetch customer data from Storefront API\n * Requires customer access token to be set\n */\n async getCustomer (): Promise<Customer | null> {\n if (!this.customerAccessToken) {\n return null\n }\n\n try {\n const data = await this.client.query<{ customer: Customer }>(GET_CUSTOMER, { customerAccessToken: this.customerAccessToken })\n\n return data.customer || null\n } catch (error) {\n console.error('Error fetching customer:', error)\n return null\n }\n }\n\n /**\n * Get current page context\n * Auto-detected from Remix router in Provider\n */\n getPageContext (): PageContext {\n return this.pageContext\n }\n\n setPageContext (context: Partial<PageContext>) {\n if (context.product) {\n context.product.id = toId(String(context.product.id))\n }\n if (context.collection) {\n context.collection.id = toId(String(context.collection.id))\n }\n this.pageContext = context\n }\n\n getVisitorId (): string | null {\n return null\n }\n\n /**\n * Get current market information\n */\n getMarket (): string | null {\n return this.market\n }\n\n /**\n * Get currency conversion rate\n * Note: Stub implementation\n */\n getCurrencyRate (): number {\n return this.currency.rate\n }\n\n /**\n * Transform Hydrogen Product to snippet-manager ProductData format\n */\n toProductData (product: Product): ProductData {\n return {\n id: toId(product.id),\n handle: product.handle,\n title: product.title,\n available: product.availableForSale,\n requires_selling_plan: product.requiresSellingPlan,\n images: product.images.nodes.map(img => img.url),\n variants: product.variants.nodes.map(variant => ({\n id: toId(variant.id),\n title: variant.title,\n available: variant.availableForSale,\n price: Math.round(parseFloat(variant.price.amount) * 100), // Convert to cents\n compare_at_price: variant.compareAtPrice\n ? Math.round(parseFloat(variant.compareAtPrice.amount) * 100)\n : null,\n featured_image: variant.image ? { src: variant.image.url } : null,\n selling_plan_allocations: variant.sellingPlanAllocations?.edges?.map(edge => ({\n selling_plan_id: edge.node.sellingPlan.id\n })) || []\n }))\n }\n }\n}\n","/**\n * Shopify Storefront API GraphQL client\n */\n\nexport type StorefrontClientConfig = {\n storefrontAccessToken: string\n shopDomain: string\n apiVersion?: string\n}\n\nexport class StorefrontClient {\n private storefrontAccessToken: string\n\n private shopDomain: string\n\n private apiVersion: string\n\n private endpoint: string\n\n constructor (config: StorefrontClientConfig) {\n this.storefrontAccessToken = config.storefrontAccessToken\n this.shopDomain = config.shopDomain\n this.apiVersion = config.apiVersion || '2024-01'\n this.endpoint = `https://${this.shopDomain}/api/${this.apiVersion}/graphql.json`\n }\n\n /**\n * Execute a GraphQL query against the Storefront API\n */\n async query<T = any>(query: string, variables?: Record<string, any>): Promise<T> {\n try {\n const response = await fetch(this.endpoint, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Shopify-Storefront-Access-Token': this.storefrontAccessToken\n },\n body: JSON.stringify({\n query,\n variables\n })\n })\n\n if (!response.ok) {\n throw new Error(`Storefront API request failed: ${response.statusText}`)\n }\n\n const result = await response.json()\n\n if (result.errors) {\n throw new Error(`GraphQL errors: ${JSON.stringify(result.errors)}`)\n }\n\n return result.data as T\n } catch (error) {\n console.error('Storefront API error:', error)\n throw error\n }\n }\n\n /**\n * Execute a GraphQL mutation against the Storefront API\n */\n async mutate<T = any>(mutation: string, variables?: Record<string, any>): Promise<T> {\n return this.query<T>(mutation, variables)\n }\n}\n","import React, { createContext, useEffect, useMemo, useRef, ReactNode } from 'react'\nimport { useMatches, useRevalidator } from 'react-router'\nimport {\n PersonizelyConfigMethods,\n HydrogenConfig,\n CartAddProduct\n} from '../types'\nimport type { CartReturn } from '@shopify/hydrogen'\nimport { Cart } from '../classes/Cart'\nimport { Adapter } from '../classes/Adapter'\nimport { StorefrontClient } from '../utils/storefront-client'\n\ndeclare global {\n interface Window {\n __PLY_HYDROGEN_CONFIG__?: HydrogenConfig\n }\n}\n\nexport type PersonizelyContextType = {\n cart: Cart\n adapter: Adapter\n websiteApiKey: string\n triggerCartAdd: (product: CartAddProduct) => Promise<boolean>\n triggerCheckout: () => Promise<boolean>\n}\n\nexport const PersonizelyContext = createContext<PersonizelyContextType | null>(null)\n\nexport type PersonizelyProviderProps = {\n websiteApiKey: string\n storefrontAccessToken: string\n shopDomain: string\n apiVersion?: string\n scriptBaseUrl?: string\n locale?: string\n currency?: {\n rate: number\n active: string\n base: string\n }\n market?: string\n methods?: PersonizelyConfigMethods\n children: ReactNode\n /**\n * Optional: Customer access token for authenticated requests\n */\n customerAccessToken?: string | null\n}\n\nexport function PersonizelyProvider ({\n websiteApiKey,\n storefrontAccessToken,\n shopDomain,\n locale,\n currency,\n market,\n apiVersion,\n scriptBaseUrl,\n methods,\n children,\n customerAccessToken\n}: PersonizelyProviderProps) {\n const matches = useMatches()\n const rootMatch = matches.find(m => m.id === 'root')\n const localCart = (rootMatch?.loaderData as any)?.cart as Promise<CartReturn>\n const revalidator = useRevalidator()\n\n const storefrontClient = useMemo(() => {\n return new StorefrontClient({\n storefrontAccessToken,\n shopDomain,\n apiVersion\n })\n }, [storefrontAccessToken, shopDomain, apiVersion])\n\n const adapter = useMemo(() => {\n const adapterInstance = new Adapter({\n locale,\n currency,\n market,\n methods\n }, storefrontClient)\n\n if (customerAccessToken) {\n adapterInstance.setCustomerAccessToken(customerAccessToken)\n }\n\n return adapterInstance\n }, [])\n\n const cart = useMemo(() => new Cart(localCart, storefrontClient, revalidator.revalidate), [])\n\n // Update cart data when it changes from the loader\n const prevCartDataRef = useRef<CartReturn | null>(null)\n useEffect(() => {\n localCart.then((data) => {\n if (data && data !== prevCartDataRef.current) {\n cart.updateCartData(data)\n cart.notifyListeners()\n prevCartDataRef.current = data\n }\n })\n }, [localCart, cart])\n\n const cartAddCallbacksRef = useRef<Array<(product: CartAddProduct) => Promise<boolean>>>([])\n const checkoutCallbacksRef = useRef<Array<() => Promise<boolean>>>([])\n\n // Set up window.__PLY_HYDROGEN_CONFIG__ and load Personizely script\n useEffect(() => {\n if (typeof window === 'undefined') {\n return\n }\n\n window.__PLY_HYDROGEN_CONFIG__ = {\n cart,\n adapter,\n onCartAdd: (callback) => {\n cartAddCallbacksRef.current.push(callback)\n\n return () => {\n const index = cartAddCallbacksRef.current.indexOf(callback)\n if (index > -1) {\n cartAddCallbacksRef.current.splice(index, 1)\n }\n }\n },\n onCheckout: (callback) => {\n checkoutCallbacksRef.current.push(callback)\n\n return () => {\n const index = checkoutCallbacksRef.current.indexOf(callback)\n if (index > -1) {\n checkoutCallbacksRef.current.splice(index, 1)\n }\n }\n }\n }\n\n const script = document.createElement('script')\n const baseUrl = scriptBaseUrl || 'https://static.personizely.net'\n script.src = `${baseUrl}/${websiteApiKey}.js`\n document.head.appendChild(script)\n\n return () => {\n delete window.__PLY_HYDROGEN_CONFIG__\n if (script) {\n script.remove()\n }\n }\n }, [])\n\n const contextValue = useMemo(() => ({\n cart,\n adapter,\n websiteApiKey,\n triggerCartAdd: async (product: CartAddProduct): Promise<boolean> => {\n let shown = false\n for (const callback of cartAddCallbacksRef.current) {\n try {\n const result = await callback(product)\n if (result) {\n shown = true\n }\n } catch (error) {\n console.error('Cart add callback error:', error)\n }\n }\n return shown\n },\n triggerCheckout: async (): Promise<boolean> => {\n let shown = false\n for (const callback of checkoutCallbacksRef.current) {\n try {\n const result = await callback()\n if (result) {\n shown = true\n }\n } catch (error) {\n console.error('Checkout callback error:', error)\n }\n }\n return shown\n }\n }), [cart, adapter, websiteApiKey])\n\n return (\n <PersonizelyContext.Provider value={contextValue}>\n {children}\n </PersonizelyContext.Provider>\n )\n}\n","/**\n * usePersonizely - Access Personizely context\n */\n\nimport { useContext } from 'react'\nimport { PersonizelyContext, PersonizelyContextType } from '../components/PersonizelyProvider'\n\n/**\n * Hook to access Personizely context\n * Provides access to cart, adapter, and configuration\n *\n * @returns PersonizelyContextType\n * @throws Error if used outside PersonizelyProvider\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const { cart, adapter } = usePersonizely()\n * // Use cart and adapter...\n * }\n * ```\n */\nexport function usePersonizely (): PersonizelyContextType {\n const context = useContext(PersonizelyContext)\n\n if (!context) {\n throw new Error('usePersonizely must be used within a PersonizelyProvider. ' +\n 'Make sure your component is wrapped with <PersonizelyProvider>.')\n }\n\n return context\n}\n","/**\n * useCartAdd - Hook to trigger Personizely cart add widgets\n */\n\nimport { useCallback } from 'react'\nimport type { CartAddProduct } from '../types'\nimport { usePersonizely } from './usePersonizely'\nimport { toId } from '../utils/id'\n\n/**\n * Hook to trigger Personizely cart add event\n * Call this when a product is being added to cart to show relevant widgets\n *\n * @returns Function to trigger cart add event\n *\n * @example\n * ```tsx\n * function ProductForm({ product, selectedVariant }) {\n * const triggerCartAdd = useCartAdd()\n *\n * const handleAddToCart = async () => {\n * const widgetShown = await triggerCartAdd({\n * id: product.id,\n * variantId: selectedVariant.id,\n * price: parseFloat(selectedVariant.price.amount),\n * quantity: 1,\n * handle: product.handle\n * })\n *\n * if (!widgetShown) {\n * await cart.linesAdd([{\n * merchandiseId: selectedVariant.id,\n * quantity: 1\n * }])\n * }\n * }\n *\n * return <button onClick={handleAddToCart}>Add to Cart</button>\n * }\n * ```\n */\nexport function useCartAdd () {\n const personizely = usePersonizely()\n\n return useCallback(async (product: CartAddProduct): Promise<boolean> => {\n if (typeof window === 'undefined') {\n return false\n }\n\n return await personizely.triggerCartAdd({\n ...product,\n id: toId(String(product.id)),\n variantId: toId(String(product.variantId)),\n price: Number(product.price) * 100\n })\n }, [personizely])\n}\n","/**\n * useCheckout - Hook to trigger Personizely checkout widgets\n */\n\nimport { useCallback } from 'react'\nimport { usePersonizely } from './usePersonizely'\n\n/**\n * Hook to trigger Personizely checkout event\n * Call this when proceeding to checkout to show relevant widgets\n *\n * @returns Function to trigger checkout event\n *\n * @example\n * ```tsx\n * function CheckoutButton() {\n * const triggerCheckout = useCheckout()\n *\n * const handleCheckout = async () => {\n * const widgetShown = await triggerCheckout()\n *\n * if (!widgetShown) {\n * window.location.href = cart.checkoutUrl\n * }\n * }\n *\n * return <button onClick={handleCheckout}>Checkout</button>\n * }\n * ```\n */\nexport function useCheckout () {\n const personizely = usePersonizely()\n\n return useCallback(async (): Promise<boolean> => {\n if (typeof window === 'undefined') {\n return false\n }\n\n return await personizely.triggerCheckout()\n }, [personizely])\n}\n","import { usePersonizely } from './usePersonizely'\nimport { PageContext } from '../types'\n\nexport function usePageContext (context: Partial<PageContext>) {\n const personizely = usePersonizely()\n\n personizely.adapter.setPageContext(context)\n}\n"],"mappings":"0hBAUA,SAAgB,EAAY,EAA6B,CACvD,GAAI,OAAO,SAAa,IACtB,OAAO,KAGT,IAAM,EAAS,EAAO,IAChB,EAAU,SAAS,OAAO,MAAM,IAAI,CAE1C,IAAK,IAAI,EAAI,EAAG,EAAI,EAAQ,OAAQ,IAAK,CACvC,IAAI,EAAS,EAAQ,GACrB,KAAO,EAAO,OAAO,EAAE,GAAK,KAC1B,EAAS,EAAO,UAAU,EAAG,EAAO,OAAO,CAE7C,GAAI,EAAO,QAAQ,EAAO,GAAK,EAC7B,OAAO,EAAO,UAAU,EAAO,OAAQ,EAAO,OAAO,CAIzD,OAAO,KAUT,SAAgB,EAAc,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,eAAe,CACtC,GAAG,EACH,GAAI,EAAK,OAAO,EAAQ,GAAG,CAAC,CAC5B,UAAW,EAAK,OAAO,EAAQ,UAAU,CAAC,CAC1C,MAAO,OAAO,EAAQ,MAAM,CAAG,IAChC,CAAC,CACD,CAAC,EAAY,CAAC,CCzBnB,SAAgB,GAAe,CAC7B,IAAM,EAAc,GAAgB,CAEpC,OAAA,EAAA,EAAA,aAAmB,SACb,OAAO,OAAW,IACb,GAGF,MAAM,EAAY,iBAAiB,CACzC,CAAC,EAAY,CAAC,CCpCnB,SAAgB,EAAgB,EAA+B,CACzC,GAAgB,CAExB,QAAQ,eAAe,EAAQ"}
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types/interfaces.ts","../src/types/index.ts","../src/utils/storefront-client.ts","../src/classes/Cart.ts","../src/classes/Adapter.ts","../src/components/PersonizelyProvider.tsx","../src/hooks/usePersonizely.ts","../src/hooks/useCartAdd.ts","../src/hooks/useCheckout.ts","../src/hooks/usePageContext.ts"],"sourcesContent":[],"mappings":";;;;UAWiB,KAAA;;4BAUW;EAVX,KAAA,CAAA,KAAK,CAAA,EAAA,OAAA,CAAA,EAgBI,OAhBJ,CAgBY,QAhBZ,GAAA,IAAA,CAAA;EAUM,MAAA,CAAA,MAAA,EAAA,MAAA,EAAA,IAAA,EAAA,GAAA,CAAA,EAYS,OAZT,CAAA,IAAA,CAAA;EAMM,GAAA,CAAA,SAAA,EAAA,MAAA,EAAA,QAAA,CAAA,EAAA,MAAA,CAAA,EAAA,IAAA;EAAR,GAAA,CAAA,QAAA,CAAA,EAAA,MAAA,CAAA,EAAA,GAAA;EAMW,QAAA,EAAA,EAAA,MAAA,GAAA,IAAA;EAoCA,WAAA,EAAA,EAAA,MAAA,EAAA;EAKY,QAAA,CAAA,QAAA,CAAA,EAAA,MAAA,CAAA,EAAA,MAAA;EAAO,OAAA,CAAA,QAAA,CAAA,EAAA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AAmB,GAAA,CAAA,EAAA,MAAA,GAAA,IAAA;EACtB,iBAAA,CAAA,EAAA,MAAA;CAAO;KAzK1B,KAAA;;;EC/EA,OAAA,CAAA,EAAA,MAAA,GAAA,IAAA;EAMC,KAAA,CAAA,EAAA,MAAA;EASU,MAAA,CAAA,EAAA,MAAA;CAU2B;AAA8B,KDiEpE,KAAA,GCjEoE;EAAR,MAAA,EAAA,MAAA;EAkClB,YAAA,EAAA,MAAA;CAA8B;AAAR,KDuChE,UAAA,GCvCgE;EAAO,eAAA,EDwChE,KCxCgE;mBDyChE;;KAMP,aAAA;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types/interfaces.ts","../src/types/index.ts","../src/utils/storefront-client.ts","../src/classes/Cart.ts","../src/classes/Adapter.ts","../src/components/PersonizelyProvider.tsx","../src/hooks/usePersonizely.ts","../src/hooks/useCartAdd.ts","../src/hooks/useCheckout.ts","../src/hooks/usePageContext.ts"],"sourcesContent":[],"mappings":";;;;UAWiB,KAAA;;4BAUW;EAVX,KAAA,CAAA,KAAK,CAAA,EAAA,OAAA,CAAA,EAgBI,OAhBJ,CAgBY,QAhBZ,GAAA,IAAA,CAAA;EAUM,MAAA,CAAA,MAAA,EAAA,MAAA,EAAA,IAAA,EAAA,GAAA,CAAA,EAYS,OAZT,CAAA,IAAA,CAAA;EAMM,GAAA,CAAA,SAAA,EAAA,MAAA,EAAA,QAAA,CAAA,EAAA,MAAA,CAAA,EAAA,IAAA;EAAR,GAAA,CAAA,QAAA,CAAA,EAAA,MAAA,CAAA,EAAA,GAAA;EAMW,QAAA,EAAA,EAAA,MAAA,GAAA,IAAA;EAoCA,WAAA,EAAA,EAAA,MAAA,EAAA;EAKY,QAAA,CAAA,QAAA,CAAA,EAAA,MAAA,CAAA,EAAA,MAAA;EAAO,OAAA,CAAA,QAAA,CAAA,EAAA,OAAA,CAAA,EAAA,MAAA;EAWvC,gBAAA,CAAA,KAAe,CAAA,EAAA,OAAA,CAAA,EAh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A;EAUM,UAAA,MAAA,CAAA;IAMM,uBAAA,CAAA,EKbJ,cLaI;EAAR;;AA0CW,KKnDzB,sBAAA,GLmDyB;EAKY,IAAA,EKvDzC,ILuDyC;EAAO,OAAA,EKtD7C,OLsD6C;EAWvC,aAAA,EAAA,MAAe;EAIQ,cAAA,EAAA,CAAA,OAAA,EKnEZ,cLmEY,EAAA,GKnEO,OLmEP,CAAA,OAAA,CAAA;EAAR,eAAA,EAAA,GAAA,GKlEP,OLkEO,CAAA,OAAA,CAAA;CAK8B;AAOH,KKzE/C,wBAAA,GLyE+C;EAyBlC,aAAA,EAAA,MAAA;EAAR,qBAAA,EAAA,MAAA;EAKG,UAAA,EAAA,MAAA;EAAW,UAAA,CAAA,EAAA,MAAA;;;;IC9HnB,IAAA,EAAA,MAAW;IAaX,MAAA,EAAA,MAAA;IAaA,IAAA,EAAO,MAAA;EAOR,CAAA;EAGA,MAAA,CAAA,EAAA,MAAA;EAEO,OAAA,CAAA,EIFN,wBJEM;EACJ,QAAA,EIFF,SJEE;EAKH,mBAAA,CAAA,EAAA,MAAA,GAAA,IAAA;CAIA;AAAa,iBIJR,mBAAA,CJIQ;EAAA,aAAA;EAAA,qBAAA;EAAA,UAAA;EAAA,MAAA;EAAA,QAAA;EAAA,MAAA;EAAA,UAAA;EAAA,aAAA;EAAA,OAAA;EAAA,QAAA;EAAA;AAAA,CAAA,EIQrB,wBJRqB,CAAA,EIQG,KAAA,CAAA,GAAA,CAAA,OJRH;;;iBK/BR,cAAA,CAAA,GAAmB;;;iBCmBnB,UAAA,CAAA,aAGqB,mBAAiB;;;iBCdtC,WAAA,CAAA,SAGe;;;iBC9Bf,cAAA,UAAyB,QAAQ"}
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/interfaces.ts","../src/types/index.ts","../src/utils/storefront-client.ts","../src/classes/Cart.ts","../src/classes/Adapter.ts","../src/components/PersonizelyProv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,EAAA,MAAA,EAAA;EAGR,WAAA,EAAA,MAAA;EAQQ,MAAA,EAAA,MAAA;EACT,WAAA,EAAA;IAAK,KAAA,EA1BJ,UA0BI,EAAA;EAQH,CAAA;EAWA,mBAAK,EAAA,OAAA;EAQL,gBAAU,EAAA,OACH;EAOP,OAAA,EAzDD,aAyDc,EAAA;AASzB,CAAA;AAQY,KApEA,OAAA,GAoEU;EAUV,EAAA,EAAA,MAAA;EAGH,KAAA,EAAA,MAAA;EAEU,KAAA,EAhFV,KAgFU;EACJ,cAAA,CAAA,EAhFI,KAgFJ,GAAA,IAAA;EAAM,gBAAA,EAAA,OAAA;EAOT,sBAAY,EAAA;IAYZ,KAAA,EAhGD,KAgGa,CAAA;MAQZ,IAAQ,EAAA;QAcR,WAAW,EAAA;UASX,EAAc,EAAA,MAAA;QASd,CAAA;MAQA,CAAA;IAsCA,CAAA,CAAA;EACJ,CAAA;EACG,eAAA,EAhLQ,cAgLR,EAAA;EACuB,KAAA,CAAA,EAhLxB,KAgLwB,GAAA,IAAA;EAAmB,GAAA,CAAA,EAAA,MAAA,GAAA,IAAA;EACtB,iBAAA,CAAA,EAAA,MAAA;CAAO;KAzK1B,KAAA;;;EC/EA,OAAA,CAAA,EAAA,MAAA,GAAA,IAAA;EAMC,KAAA,CAAA,EAAA,MAAA;EASU,MAAA,CAAA,EAAA,MAAA;CAU2B;AAA8B,KDiEpE,KAAA,GCjEoE;EAAR,MAAA,EAAA,MAAA;EAkClB,YAAA,EAAA,MAAA;CAA8B;AAAR,KDuChE,UAAA,GCvCgE;EAAO,eAAA,EDwChE,KCxCgE;mBDyChE;;KAMP,aAAA;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/interfaces.ts","../src/types/index.ts","../src/utils/storefront-client.ts","../src/classes/Cart.ts","../src/classes/Adapter.ts","../src/components/PersonizelyProvider.tsx","../src/hooks/usePersonizely.ts","../src/hooks/useCartAdd.ts","../src/hooks/useCheckout.ts","../src/hooks/usePage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AEO,OAAA,CAAA,EIFN,wBJEM;EACJ,QAAA,EIFF,SJEE;EAKH,mBAAA,CAAA,EAAA,MAAA,GAAA,IAAA;CAIA;AAAa,iBIJR,mBAAA,CJIQ;EAAA,aAAA;EAAA,qBAAA;EAAA,UAAA;EAAA,MAAA;EAAA,QAAA;EAAA,MAAA;EAAA,UAAA;EAAA,aAAA;EAAA,OAAA;EAAA,QAAA;EAAA;AAAA,CAAA,EIQrB,wBJRqB,CAAA,EIQG,KAAA,CAAA,GAAA,CAAA,OJRH;;;iBK/BR,cAAA,CAAA,GAAmB;;;iBCmBnB,UAAA,CAAA,aAGqB,mBAAiB;;;iBCdtC,WAAA,CAAA,SAGe;;;iBC9Bf,cAAA,UAAyB,QAAQ"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
|
+
import { CartReturn } from "@shopify/hydrogen";
|
|
3
|
+
|
|
4
|
+
//#region src/types/interfaces.d.ts
|
|
5
|
+
interface ICart {
|
|
6
|
+
isSynced(): boolean;
|
|
7
|
+
onChange(callback: (cart: CartData) => void): () => void;
|
|
8
|
+
fetch(force?: boolean): Promise<CartData | null>;
|
|
9
|
+
update(action: string, data: any): Promise<void>;
|
|
10
|
+
buy(variantId: string, quantity?: number): void;
|
|
11
|
+
get(property?: string): any;
|
|
12
|
+
getToken(): string | null;
|
|
13
|
+
getItemsIds(): string[];
|
|
14
|
+
getValue(currency?: string): number;
|
|
15
|
+
getSize(distinct?: boolean): number;
|
|
16
|
+
fetchCollections(force?: boolean): Promise<any>;
|
|
17
|
+
applyCoupon(code: string, expiresIn?: number): Promise<void>;
|
|
18
|
+
getCoupon(): string | null;
|
|
19
|
+
}
|
|
20
|
+
interface IShopifyAdapter {
|
|
21
|
+
fetchProduct(handle: string): Promise<ProductData>;
|
|
22
|
+
fetchProductCollections(handle: string, productId: number): Promise<any>;
|
|
23
|
+
fetchRecommendations(productId: number, intent: string): Promise<{
|
|
24
|
+
products: ProductData[];
|
|
25
|
+
intent: string;
|
|
26
|
+
}>;
|
|
27
|
+
buildProductPath(params: {
|
|
28
|
+
handle: string;
|
|
29
|
+
}): string;
|
|
30
|
+
convertToBaseCurrency(amount: number): number;
|
|
31
|
+
convertFromBaseCurrency(amount: number): number;
|
|
32
|
+
formatMoney(amount: number, includeDecimals: boolean): string;
|
|
33
|
+
getCustomer(): Promise<Customer | null>;
|
|
34
|
+
getPageContext(): PageContext;
|
|
35
|
+
getVisitorId(): string | null;
|
|
36
|
+
getMarket(): string | null;
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/types/index.d.ts
|
|
40
|
+
type ProductData = {
|
|
41
|
+
id: number;
|
|
42
|
+
handle: string;
|
|
43
|
+
title: string;
|
|
44
|
+
available: boolean;
|
|
45
|
+
requires_selling_plan: boolean;
|
|
46
|
+
images: string[];
|
|
47
|
+
variants: ProductDataVariant[];
|
|
48
|
+
};
|
|
49
|
+
type ProductDataVariant = {
|
|
50
|
+
id: number;
|
|
51
|
+
title: string;
|
|
52
|
+
available: boolean;
|
|
53
|
+
price: number;
|
|
54
|
+
compare_at_price: number | null;
|
|
55
|
+
featured_image: {
|
|
56
|
+
src: string;
|
|
57
|
+
} | null;
|
|
58
|
+
selling_plan_allocations: Array<{
|
|
59
|
+
selling_plan_id: string;
|
|
60
|
+
}>;
|
|
61
|
+
};
|
|
62
|
+
type Product = {
|
|
63
|
+
id: string;
|
|
64
|
+
handle: string;
|
|
65
|
+
title: string;
|
|
66
|
+
description: string;
|
|
67
|
+
descriptionHtml: string;
|
|
68
|
+
variants: {
|
|
69
|
+
nodes: Variant[];
|
|
70
|
+
};
|
|
71
|
+
images: {
|
|
72
|
+
nodes: Image[];
|
|
73
|
+
};
|
|
74
|
+
featuredImage?: Image | null;
|
|
75
|
+
priceRange: PriceRange;
|
|
76
|
+
tags: string[];
|
|
77
|
+
productType: string;
|
|
78
|
+
vendor: string;
|
|
79
|
+
collections: {
|
|
80
|
+
nodes: Collection[];
|
|
81
|
+
};
|
|
82
|
+
requiresSellingPlan: boolean;
|
|
83
|
+
availableForSale: boolean;
|
|
84
|
+
options: ProductOption[];
|
|
85
|
+
};
|
|
86
|
+
type Variant = {
|
|
87
|
+
id: string;
|
|
88
|
+
title: string;
|
|
89
|
+
price: Money;
|
|
90
|
+
compareAtPrice?: Money | null;
|
|
91
|
+
availableForSale: boolean;
|
|
92
|
+
sellingPlanAllocations: {
|
|
93
|
+
edges: Array<{
|
|
94
|
+
node: {
|
|
95
|
+
sellingPlan: {
|
|
96
|
+
id: string;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
}>;
|
|
100
|
+
};
|
|
101
|
+
selectedOptions: SelectedOption[];
|
|
102
|
+
image?: Image | null;
|
|
103
|
+
sku?: string | null;
|
|
104
|
+
quantityAvailable?: number;
|
|
105
|
+
};
|
|
106
|
+
type Image = {
|
|
107
|
+
id?: string;
|
|
108
|
+
url: string;
|
|
109
|
+
altText?: string | null;
|
|
110
|
+
width?: number;
|
|
111
|
+
height?: number;
|
|
112
|
+
};
|
|
113
|
+
type Money = {
|
|
114
|
+
amount: string;
|
|
115
|
+
currencyCode: string;
|
|
116
|
+
};
|
|
117
|
+
type PriceRange = {
|
|
118
|
+
minVariantPrice: Money;
|
|
119
|
+
maxVariantPrice: Money;
|
|
120
|
+
};
|
|
121
|
+
type ProductOption = {
|
|
122
|
+
id?: string;
|
|
123
|
+
name: string;
|
|
124
|
+
values: string[];
|
|
125
|
+
};
|
|
126
|
+
type SelectedOption = {
|
|
127
|
+
name: string;
|
|
128
|
+
value: string;
|
|
129
|
+
};
|
|
130
|
+
type Collection = {
|
|
131
|
+
id: string;
|
|
132
|
+
handle: string;
|
|
133
|
+
title: string;
|
|
134
|
+
description?: string;
|
|
135
|
+
};
|
|
136
|
+
type CartData = {
|
|
137
|
+
token: string;
|
|
138
|
+
item_count: number;
|
|
139
|
+
items: CartDataItem[];
|
|
140
|
+
total_price: number;
|
|
141
|
+
discount_codes?: DiscountCode[];
|
|
142
|
+
attributes?: Record<string, any>;
|
|
143
|
+
note?: string | null;
|
|
144
|
+
};
|
|
145
|
+
type CartDataItem = {
|
|
146
|
+
id: number;
|
|
147
|
+
quantity: number;
|
|
148
|
+
product_id: number;
|
|
149
|
+
variant_id: number;
|
|
150
|
+
price: number;
|
|
151
|
+
};
|
|
152
|
+
type DiscountCode = {
|
|
153
|
+
code: string;
|
|
154
|
+
applicable: boolean;
|
|
155
|
+
};
|
|
156
|
+
type Customer = {
|
|
157
|
+
id: string;
|
|
158
|
+
email?: string | null;
|
|
159
|
+
phone?: string | null;
|
|
160
|
+
firstName?: string | null;
|
|
161
|
+
lastName?: string | null;
|
|
162
|
+
displayName: string;
|
|
163
|
+
hasAccount: boolean;
|
|
164
|
+
tags: string[];
|
|
165
|
+
};
|
|
166
|
+
type PageContext = {
|
|
167
|
+
pageType?: string | number;
|
|
168
|
+
product?: {
|
|
169
|
+
handle: string;
|
|
170
|
+
id: number;
|
|
171
|
+
tags?: string[];
|
|
172
|
+
} | null;
|
|
173
|
+
collection?: {
|
|
174
|
+
id: number;
|
|
175
|
+
} | null;
|
|
176
|
+
};
|
|
177
|
+
type CartAddProduct = {
|
|
178
|
+
id: string | number;
|
|
179
|
+
variantId: string | number;
|
|
180
|
+
price?: string | number;
|
|
181
|
+
quantity?: number;
|
|
182
|
+
handle?: string;
|
|
183
|
+
properties?: Record<string, string>;
|
|
184
|
+
};
|
|
185
|
+
type PersonizelyConfigMethods = {
|
|
186
|
+
formatMoney: (amount: number, includeDecimals: boolean) => string;
|
|
187
|
+
builtProductPath?: ({
|
|
188
|
+
handle
|
|
189
|
+
}: {
|
|
190
|
+
handle: string;
|
|
191
|
+
}) => string;
|
|
192
|
+
};
|
|
193
|
+
type PersonizelyConfig = {
|
|
194
|
+
locale?: string;
|
|
195
|
+
currency?: {
|
|
196
|
+
rate?: number;
|
|
197
|
+
active?: string;
|
|
198
|
+
base?: string;
|
|
199
|
+
};
|
|
200
|
+
market?: string;
|
|
201
|
+
methods?: PersonizelyConfigMethods;
|
|
202
|
+
};
|
|
203
|
+
type HydrogenConfig = {
|
|
204
|
+
cart: ICart;
|
|
205
|
+
adapter: IShopifyAdapter;
|
|
206
|
+
onCartAdd: (callback: (product: CartAddProduct) => Promise<boolean>) => () => void;
|
|
207
|
+
onCheckout: (callback: () => Promise<boolean>) => () => void;
|
|
208
|
+
};
|
|
209
|
+
//#endregion
|
|
210
|
+
//#region src/utils/storefront-client.d.ts
|
|
211
|
+
type StorefrontClientConfig = {
|
|
212
|
+
storefrontAccessToken: string;
|
|
213
|
+
shopDomain: string;
|
|
214
|
+
apiVersion?: string;
|
|
215
|
+
};
|
|
216
|
+
declare class StorefrontClient {
|
|
217
|
+
private storefrontAccessToken;
|
|
218
|
+
private shopDomain;
|
|
219
|
+
private apiVersion;
|
|
220
|
+
private endpoint;
|
|
221
|
+
constructor(config: StorefrontClientConfig);
|
|
222
|
+
query<T = any>(query: string, variables?: Record<string, any>): Promise<T>;
|
|
223
|
+
mutate<T = any>(mutation: string, variables?: Record<string, any>): Promise<T>;
|
|
224
|
+
}
|
|
225
|
+
//#endregion
|
|
226
|
+
//#region src/classes/Cart.d.ts
|
|
227
|
+
declare class Cart implements ICart {
|
|
228
|
+
private storefrontClient;
|
|
229
|
+
private listeners;
|
|
230
|
+
private cart;
|
|
231
|
+
private cartPromise;
|
|
232
|
+
private revalidate?;
|
|
233
|
+
constructor(cartPromise: Promise<CartReturn>, storefrontClient: StorefrontClient, revalidate?: () => void);
|
|
234
|
+
updateCartData(cart: CartReturn): void;
|
|
235
|
+
notifyListeners(): void;
|
|
236
|
+
isSynced(): boolean;
|
|
237
|
+
onChange(callback: (cart: CartData) => void): () => void;
|
|
238
|
+
fetch(force?: boolean): Promise<CartData | null>;
|
|
239
|
+
update(action: string, data: any): Promise<void>;
|
|
240
|
+
buy(_variantId: string, _quantity?: number): Promise<void>;
|
|
241
|
+
get(property?: string): any;
|
|
242
|
+
getToken(): string | null;
|
|
243
|
+
getItemsIds(): string[];
|
|
244
|
+
getCurrency(): string;
|
|
245
|
+
getValue(_currency?: string): number;
|
|
246
|
+
getSize(distinct?: boolean): number;
|
|
247
|
+
fetchCollections(_force?: boolean): Promise<any>;
|
|
248
|
+
applyCoupon(code: string, expiresIn?: number): Promise<void>;
|
|
249
|
+
getCoupon(): string | null;
|
|
250
|
+
private toCartData;
|
|
251
|
+
}
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region src/classes/Adapter.d.ts
|
|
254
|
+
declare class Adapter implements IShopifyAdapter {
|
|
255
|
+
private client;
|
|
256
|
+
private currency;
|
|
257
|
+
private market;
|
|
258
|
+
private locale;
|
|
259
|
+
private pageContext;
|
|
260
|
+
private methods?;
|
|
261
|
+
private customerAccessToken;
|
|
262
|
+
constructor(config: PersonizelyConfig, storefrontClient: StorefrontClient);
|
|
263
|
+
setCustomerAccessToken(token: string | null): void;
|
|
264
|
+
fetchProduct(handle: string): Promise<ProductData>;
|
|
265
|
+
fetchProductCollections(handle: string, productId: number): Promise<number[]>;
|
|
266
|
+
fetchRecommendations(productId: number, intent: string): Promise<{
|
|
267
|
+
products: ProductData[];
|
|
268
|
+
intent: string;
|
|
269
|
+
}>;
|
|
270
|
+
buildProductPath(product: {
|
|
271
|
+
handle: string;
|
|
272
|
+
}): string;
|
|
273
|
+
convertToBaseCurrency(amount: number): number;
|
|
274
|
+
convertFromBaseCurrency(amount: number): number;
|
|
275
|
+
formatMoney(amount: number, includeDecimals?: boolean): string;
|
|
276
|
+
getCustomer(): Promise<Customer | null>;
|
|
277
|
+
getPageContext(): PageContext;
|
|
278
|
+
setPageContext(context: Partial<PageContext>): void;
|
|
279
|
+
getVisitorId(): string | null;
|
|
280
|
+
getMarket(): string | null;
|
|
281
|
+
getCurrencyRate(): number;
|
|
282
|
+
toProductData(product: Product): ProductData;
|
|
283
|
+
}
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region src/components/PersonizelyProvider.d.ts
|
|
286
|
+
declare global {
|
|
287
|
+
interface Window {
|
|
288
|
+
__PLY_HYDROGEN_CONFIG__?: HydrogenConfig;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
type PersonizelyContextType = {
|
|
292
|
+
cart: Cart;
|
|
293
|
+
adapter: Adapter;
|
|
294
|
+
websiteApiKey: string;
|
|
295
|
+
triggerCartAdd: (product: CartAddProduct) => Promise<boolean>;
|
|
296
|
+
triggerCheckout: () => Promise<boolean>;
|
|
297
|
+
};
|
|
298
|
+
type PersonizelyProviderProps = {
|
|
299
|
+
websiteApiKey: string;
|
|
300
|
+
storefrontAccessToken: string;
|
|
301
|
+
shopDomain: string;
|
|
302
|
+
apiVersion?: string;
|
|
303
|
+
scriptBaseUrl?: string;
|
|
304
|
+
locale?: string;
|
|
305
|
+
currency?: {
|
|
306
|
+
rate: number;
|
|
307
|
+
active: string;
|
|
308
|
+
base: string;
|
|
309
|
+
};
|
|
310
|
+
market?: string;
|
|
311
|
+
methods?: PersonizelyConfigMethods;
|
|
312
|
+
children: ReactNode;
|
|
313
|
+
customerAccessToken?: string | null;
|
|
314
|
+
};
|
|
315
|
+
declare function PersonizelyProvider({
|
|
316
|
+
websiteApiKey,
|
|
317
|
+
storefrontAccessToken,
|
|
318
|
+
shopDomain,
|
|
319
|
+
locale,
|
|
320
|
+
currency,
|
|
321
|
+
market,
|
|
322
|
+
apiVersion,
|
|
323
|
+
scriptBaseUrl,
|
|
324
|
+
methods,
|
|
325
|
+
children,
|
|
326
|
+
customerAccessToken
|
|
327
|
+
}: PersonizelyProviderProps): React.JSX.Element;
|
|
328
|
+
//#endregion
|
|
329
|
+
//#region src/hooks/usePersonizely.d.ts
|
|
330
|
+
declare function usePersonizely(): PersonizelyContextType;
|
|
331
|
+
//#endregion
|
|
332
|
+
//#region src/hooks/useCartAdd.d.ts
|
|
333
|
+
declare function useCartAdd(): (product: CartAddProduct) => Promise<boolean>;
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region src/hooks/useCheckout.d.ts
|
|
336
|
+
declare function useCheckout(): () => Promise<boolean>;
|
|
337
|
+
//#endregion
|
|
338
|
+
//#region src/hooks/usePageContext.d.ts
|
|
339
|
+
declare function usePageContext(context: Partial<PageContext>): void;
|
|
340
|
+
//#endregion
|
|
341
|
+
export { Adapter, Cart, type CartAddProduct, type HydrogenConfig, type ICart, type IShopifyAdapter, type PageContext, type PersonizelyConfig, type PersonizelyContextType, PersonizelyProvider, type PersonizelyProviderProps, useCartAdd, useCheckout, usePageContext, usePersonizely };
|
|
342
|
+
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -126,7 +126,20 @@ import e,{createContext as t,useCallback as n,useContext as r,useEffect as i,use
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
${d}
|
|
129
|
-
|
|
129
|
+
`,g=`
|
|
130
|
+
mutation cartAttributesUpdate($cartId: ID!, $attributes: [AttributeInput!]!) {
|
|
131
|
+
cartAttributesUpdate(cartId: $cartId, attributes: $attributes) {
|
|
132
|
+
cart {
|
|
133
|
+
...CartFragment
|
|
134
|
+
}
|
|
135
|
+
userErrors {
|
|
136
|
+
field
|
|
137
|
+
message
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
${d}
|
|
142
|
+
`;function _(e,t){return`gid://shopify/${t}/${e}`}function v(e){return Number(e.split(`/`).pop())}const y=`_ply_coupon`;var b=class{constructor(e,t,n){this.listeners=[],this.cart=null,this.storefrontClient=t,this.cartPromise=e,this.revalidate=n}updateCartData(e){this.cart=e,this.cartPromise=null}notifyListeners(){this.cart&&this.listeners.forEach(e=>{try{this.cart&&e(this.toCartData(this.cart))}catch(e){console.error(`Cart listener error:`,e)}})}isSynced(){return!!this.cart}onChange(e){return this.listeners.push(e),()=>{let t=this.listeners.indexOf(e);t>-1&&this.listeners.splice(t,1)}}async fetch(e=!0){return this.cart&&!e?this.toCartData(this.cart):this.cartPromise?(this.cart=await this.cartPromise,this.toCartData(this.cart)):this.cart?this.toCartData(this.cart):null}async update(e,t){if(!this.cart)throw Error(`Cart not initialized`);let n=this.cart.lines.nodes.map(e=>e.id);try{let r;switch(e){case`add`:r=await this.storefrontClient.mutate(f,{cartId:this.cart.id,lines:[{merchandiseId:_(t.id,`ProductVariant`),quantity:t.quantity||1,attributes:t.properties?Object.entries(t.properties).map(([e,t])=>({key:e,value:String(t)})):void 0}]}),r?.cartLinesAdd?.cart&&(this.cart=r.cartLinesAdd.cart,this.notifyListeners());break;case`update`:case`change`:if(t.updates){let e=[],n=[];Object.entries(t.updates).forEach(([t,r])=>{let i=this.cart.lines.nodes.find(e=>v(e.merchandise.id)===Number(t));i?e.push({id:i.id,quantity:Number(r)}):Number(r)>0&&n.push({merchandiseId:_(Number(t),`ProductVariant`),quantity:Number(r)})});let r=[];if(e.length>0&&r.push(this.storefrontClient.mutate(p,{cartId:this.cart.id,lines:e})),n.length>0&&r.push(this.storefrontClient.mutate(f,{cartId:this.cart.id,lines:n})),r.length>0){let e=await Promise.all(r),t=e[e.length-1];(t?.cartLinesUpdate?.cart||t?.cartLinesAdd?.cart)&&(this.cart=t.cartLinesUpdate?.cart||t.cartLinesAdd?.cart,this.notifyListeners())}}else t.id&&(r=await this.storefrontClient.mutate(p,{cartId:this.cart.id,lines:[{id:`gid://shopify/CartLine/${t.id}`,quantity:t.quantity}]}),r?.cartLinesUpdate?.cart&&(this.cart=r.cartLinesUpdate.cart,this.notifyListeners()));t.attributes&&this.cart&&(r=await this.storefrontClient.mutate(g,{cartId:this.cart.id,attributes:Object.entries(t.attributes).map(([e,t])=>({key:e,value:String(t)}))}),r?.cartAttributesUpdate?.cart&&(this.cart=r.cartAttributesUpdate.cart,this.notifyListeners())),t.discount&&this.cart&&(r=await this.storefrontClient.mutate(h,{cartId:this.cart.id,discountCodes:[t.discount]}),r?.cartDiscountCodesUpdate?.cart&&(this.cart=r.cartDiscountCodesUpdate.cart,this.notifyListeners()));break;case`clear`:r=await this.storefrontClient.mutate(m,{cartId:this.cart.id,lineIds:n}),r?.cartLinesRemove?.cart&&(this.cart=r.cartLinesRemove.cart,this.notifyListeners());break;default:console.warn(`Unknown cart action: ${e}`)}this.revalidate&&this.revalidate()}catch(e){throw console.error(`Cart update error:`,e),e}}async buy(e,t=1){if(!this.cart)return;let n=this.getCoupon(),r=this.cart.checkoutUrl||`/checkout`,i=n?`${r}?discount=${n}`:r;typeof window<`u`&&(window.location.href=i)}get(e){return this.cart?e?this.toCartData(this.cart)[e]:this.toCartData(this.cart):e?void 0:null}getToken(){return this.cart&&this.cart.id||null}getItemsIds(){return this.cart?this.cart.lines.nodes.map(e=>e.merchandise.product.id):[]}getCurrency(){return this.cart?this.cart.cost.totalAmount.currencyCode:`USD`}getValue(e){return this.cart?parseFloat(this.cart.cost.totalAmount.amount)*100:0}getSize(e=!1){return this.cart?e?new Set(this.cart.lines.nodes.map(e=>e.merchandise.product.id)).size:this.cart.totalQuantity:0}async fetchCollections(e=!1){return console.warn(`fetchCollections: Not implemented for Hydrogen. Use custom metafield query.`),{}}async applyCoupon(e,t){if(!this.cart)throw Error(`Cart not initialized`);u(y,e,t);try{let t=await this.storefrontClient.mutate(h,{cartId:this.cart.id,discountCodes:[e]});t?.cartDiscountCodesUpdate?.cart&&(this.cart=t.cartDiscountCodesUpdate.cart,this.notifyListeners()),this.revalidate&&this.revalidate()}catch(e){throw console.error(`Error applying coupon:`,e),e}}getCoupon(){return this.cart?this.cart.discountCodes&&this.cart.discountCodes.length>0?this.cart.discountCodes[0].code:l(y):null}toCartData(e){return{token:e.id,item_count:e.totalQuantity||0,items:(e.lines?.nodes||[]).map(e=>({id:v(e.id),product_id:v(e.merchandise.product.id),variant_id:v(e.merchandise.id),price:Number(e.merchandise.price.amount)*100,quantity:e.quantity})),total_price:Number(e.cost.totalAmount.amount)*100,discount_codes:e.discountCodes,attributes:e.attributes,note:e.note}}};const x=`
|
|
130
143
|
fragment ProductFragment on Product {
|
|
131
144
|
id
|
|
132
145
|
handle
|
|
@@ -214,28 +227,28 @@ import e,{createContext as t,useCallback as n,useContext as r,useEffect as i,use
|
|
|
214
227
|
}
|
|
215
228
|
}
|
|
216
229
|
}
|
|
217
|
-
`,
|
|
230
|
+
`,S=`
|
|
218
231
|
query getProductByHandle($handle: String!) {
|
|
219
232
|
product(handle: $handle) {
|
|
220
233
|
...ProductFragment
|
|
221
234
|
}
|
|
222
235
|
}
|
|
223
|
-
${
|
|
224
|
-
`,
|
|
236
|
+
${x}
|
|
237
|
+
`,C=`
|
|
225
238
|
query getProductById($id: ID!) {
|
|
226
239
|
product(id: $id) {
|
|
227
240
|
...ProductFragment
|
|
228
241
|
}
|
|
229
242
|
}
|
|
230
|
-
${
|
|
231
|
-
`,
|
|
243
|
+
${x}
|
|
244
|
+
`,w=`
|
|
232
245
|
query getProductRecommendations($productId: ID!) {
|
|
233
246
|
productRecommendations(productId: $productId) {
|
|
234
247
|
...ProductFragment
|
|
235
248
|
}
|
|
236
249
|
}
|
|
237
|
-
${
|
|
238
|
-
`;var
|
|
250
|
+
${x}
|
|
251
|
+
`;var T=class{constructor(e,t){this.customerAccessToken=null,this.client=t,this.methods=e.methods,this.currency={active:`USD`,base:`USD`,rate:1,...e.currency},this.locale=e.locale||`en-US`,this.market=e.market||null,this.pageContext={pageType:void 0,product:null,collection:null}}setCustomerAccessToken(e){this.customerAccessToken=e}async fetchProduct(e){let t=await this.client.query(S,{handle:e});if(!t.product)throw Error(`Product not found: ${e}`);return this.toProductData(t.product)}async fetchProductCollections(e,t){let n;if(t?n=await this.client.query(C,{id:`gid://shopify/Product/${t}`}):e&&(n=await this.client.query(S,{handle:e})),!n||!n.product)throw Error(`Product not found: ${t}`);return n.product.collections.nodes.map(e=>v(e.id))}async fetchRecommendations(e,t){return{intent:t,products:(await this.client.query(w,{productId:`gid://shopify/Product/${e}`,intent:t})).productRecommendations.map(e=>this.toProductData(e))||[]}}buildProductPath(e){return typeof this.methods?.builtProductPath==`function`?this.methods.builtProductPath(e):`/products/${e.handle}`}convertToBaseCurrency(e){return this.currency.rate/e}convertFromBaseCurrency(e){return this.currency.rate*e}formatMoney(e,t=!0){return typeof this.methods?.formatMoney==`function`?this.methods.formatMoney(e,t):new Intl.NumberFormat(this.locale,{style:`currency`,currency:this.currency.active,maximumFractionDigits:t?void 0:0}).format(e/100)}async getCustomer(){if(!this.customerAccessToken)return null;try{return(await this.client.query(`
|
|
239
252
|
query getCustomer($customerAccessToken: String!) {
|
|
240
253
|
customer(customerAccessToken: $customerAccessToken) {
|
|
241
254
|
...CustomerFragment
|
|
@@ -260,5 +273,5 @@ import e,{createContext as t,useCallback as n,useContext as r,useEffect as i,use
|
|
|
260
273
|
}
|
|
261
274
|
}
|
|
262
275
|
|
|
263
|
-
`,{customerAccessToken:this.customerAccessToken})).customer||null}catch(e){return console.error(`Error fetching customer:`,e),null}}getPageContext(){return this.pageContext}setPageContext(e){e.product&&(e.product.id=
|
|
276
|
+
`,{customerAccessToken:this.customerAccessToken})).customer||null}catch(e){return console.error(`Error fetching customer:`,e),null}}getPageContext(){return this.pageContext}setPageContext(e){e.product&&(e.product.id=v(String(e.product.id))),e.collection&&(e.collection.id=v(String(e.collection.id))),this.pageContext=e}getVisitorId(){return null}getMarket(){return this.market}getCurrencyRate(){return this.currency.rate}toProductData(e){return{id:v(e.id),handle:e.handle,title:e.title,available:e.availableForSale,requires_selling_plan:e.requiresSellingPlan,images:e.images.nodes.map(e=>e.url),variants:e.variants.nodes.map(e=>({id:v(e.id),title:e.title,available:e.availableForSale,price:Math.round(parseFloat(e.price.amount)*100),compare_at_price:e.compareAtPrice?Math.round(parseFloat(e.compareAtPrice.amount)*100):null,featured_image:e.image?{src:e.image.url}:null,selling_plan_allocations:e.sellingPlanAllocations?.edges?.map(e=>({selling_plan_id:e.node.sellingPlan.id}))||[]}))}}},E=class{constructor(e){this.storefrontAccessToken=e.storefrontAccessToken,this.shopDomain=e.shopDomain,this.apiVersion=e.apiVersion||`2024-01`,this.endpoint=`https://${this.shopDomain}/api/${this.apiVersion}/graphql.json`}async query(e,t){try{let n=await fetch(this.endpoint,{method:`POST`,headers:{"Content-Type":`application/json`,"X-Shopify-Storefront-Access-Token":this.storefrontAccessToken},body:JSON.stringify({query:e,variables:t})});if(!n.ok)throw Error(`Storefront API request failed: ${n.statusText}`);let r=await n.json();if(r.errors)throw Error(`GraphQL errors: ${JSON.stringify(r.errors)}`);return r.data}catch(e){throw console.error(`Storefront API error:`,e),e}}async mutate(e,t){return this.query(e,t)}};const D=t(null);function O({websiteApiKey:t,storefrontAccessToken:n,shopDomain:r,locale:l,currency:u,market:d,apiVersion:f,scriptBaseUrl:p,methods:m,children:h,customerAccessToken:g}){let _=s().find(e=>e.id===`root`)?.loaderData?.cart,v=c(),y=a(()=>new E({storefrontAccessToken:n,shopDomain:r,apiVersion:f}),[n,r,f]),x=a(()=>{let e=new T({locale:l,currency:u,market:d,methods:m},y);return g&&e.setCustomerAccessToken(g),e},[]),S=a(()=>new b(_,y,v.revalidate),[]),C=o(null);i(()=>{_.then(e=>{e&&e!==C.current&&(S.updateCartData(e),S.notifyListeners(),C.current=e)})},[_,S]);let w=o([]),O=o([]);i(()=>{if(typeof window>`u`)return;window.__PLY_HYDROGEN_CONFIG__={cart:S,adapter:x,onCartAdd:e=>(w.current.push(e),()=>{let t=w.current.indexOf(e);t>-1&&w.current.splice(t,1)}),onCheckout:e=>(O.current.push(e),()=>{let t=O.current.indexOf(e);t>-1&&O.current.splice(t,1)})};let e=document.createElement(`script`);return e.src=`${p||`https://static.personizely.net`}/${t}.js`,document.head.appendChild(e),()=>{delete window.__PLY_HYDROGEN_CONFIG__,e&&e.remove()}},[]);let k=a(()=>({cart:S,adapter:x,websiteApiKey:t,triggerCartAdd:async e=>{let t=!1;for(let n of w.current)try{await n(e)&&(t=!0)}catch(e){console.error(`Cart add callback error:`,e)}return t},triggerCheckout:async()=>{let e=!1;for(let t of O.current)try{await t()&&(e=!0)}catch(e){console.error(`Checkout callback error:`,e)}return e}}),[S,x,t]);return e.createElement(D.Provider,{value:k},h)}function k(){let e=r(D);if(!e)throw Error(`usePersonizely must be used within a PersonizelyProvider. Make sure your component is wrapped with <PersonizelyProvider>.`);return e}function A(){let e=k();return n(async t=>typeof window>`u`?!1:await e.triggerCartAdd({...t,id:v(String(t.id)),variantId:v(String(t.variantId)),price:Number(t.price)*100}),[e])}function j(){let e=k();return n(async()=>typeof window>`u`?!1:await e.triggerCheckout(),[e])}function M(e){k().adapter.setPageContext(e)}export{T as Adapter,b as Cart,O as PersonizelyProvider,A as useCartAdd,j as useCheckout,M as usePageContext,k as usePersonizely};
|
|
264
277
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["result: any","linesToUpdate: any[]","linesToAdd: any[]","line","mutations: Promise<any>[]"],"sources":["../src/utils/cookies.ts","../src/graphql/queries/cart.ts","../src/utils/id.ts","../src/classes/Cart.ts","../src/graphql/queries/product.ts","../src/graphql/queries/customer.ts","../src/classes/Adapter.ts","../src/utils/storefront-client.ts","../src/components/PersonizelyProvider.tsx","../src/hooks/usePersonizely.ts","../src/hooks/useCartAdd.ts","../src/hooks/useCheckout.ts","../src/hooks/usePageContext.ts"],"sourcesContent":["/**\n * Cookie utilities for browser storage\n * Mirrors cookie helpers from snippet-manager\n */\n\n/**\n * Read a cookie value by name\n * @param name - Cookie name\n * @returns Cookie value or null if not found\n */\nexport function readCookie (name: string): string | null {\n if (typeof document === 'undefined') {\n return null\n }\n\n const nameEQ = name + '='\n const cookies = document.cookie.split(';')\n\n for (let i = 0; i < cookies.length; i++) {\n let cookie = cookies[i]\n while (cookie.charAt(0) === ' ') {\n cookie = cookie.substring(1, cookie.length)\n }\n if (cookie.indexOf(nameEQ) === 0) {\n return cookie.substring(nameEQ.length, cookie.length)\n }\n }\n\n return null\n}\n\n/**\n * Create/update a cookie\n * @param name - Cookie name\n * @param value - Cookie value\n * @param days - Expiration in days (optional, default: session cookie)\n * @param path - Cookie path (default: '/')\n */\nexport function createCookie (name: string,\n value: string,\n days?: number,\n path: string = '/'): void {\n if (typeof document === 'undefined') {\n return\n }\n\n let expires = ''\n if (days) {\n const date = new Date()\n date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000))\n expires = '; expires=' + date.toUTCString()\n }\n\n document.cookie = name + '=' + value + expires + '; path=' + path\n}\n\n/**\n * Delete a cookie by name\n * @param name - Cookie name\n * @param path - Cookie path (default: '/')\n */\nexport function deleteCookie (name: string, path: string = '/'): void {\n createCookie(name, '', -1, path)\n}\n","/**\n * GraphQL queries and mutations for cart operations\n */\n\nexport const CART_FRAGMENT = `\n fragment CartFragment on Cart {\n id\n checkoutUrl\n totalQuantity\n cost {\n subtotalAmount {\n amount\n currencyCode\n }\n totalAmount {\n amount\n currencyCode\n }\n totalTaxAmount {\n amount\n currencyCode\n }\n }\n lines(first: 100) {\n nodes {\n id\n quantity\n cost {\n totalAmount {\n amount\n currencyCode\n }\n amountPerQuantity {\n amount\n currencyCode\n }\n }\n merchandise {\n ... on ProductVariant {\n id\n title\n price {\n amount\n currencyCode\n }\n image {\n url\n altText\n }\n selectedOptions {\n name\n value\n }\n product {\n id\n handle\n title\n featuredImage {\n url\n altText\n }\n tags\n }\n }\n }\n attributes {\n key\n value\n }\n }\n }\n discountCodes {\n code\n applicable\n }\n attributes {\n key\n value\n }\n }\n`\n\nexport const GET_CART = `\n query getCart($cartId: ID!) {\n cart(id: $cartId) {\n ...CartFragment\n }\n }\n ${CART_FRAGMENT}\n`\n\n/**\n * Cart mutations\n */\n\nexport const CART_LINES_ADD = `\n mutation cartLinesAdd($cartId: ID!, $lines: [CartLineInput!]!) {\n cartLinesAdd(cartId: $cartId, lines: $lines) {\n cart {\n ...CartFragment\n }\n userErrors {\n field\n message\n }\n }\n }\n ${CART_FRAGMENT}\n`\n\nexport const CART_LINES_UPDATE = `\n mutation cartLinesUpdate($cartId: ID!, $lines: [CartLineUpdateInput!]!) {\n cartLinesUpdate(cartId: $cartId, lines: $lines) {\n cart {\n ...CartFragment\n }\n userErrors {\n field\n message\n }\n }\n }\n ${CART_FRAGMENT}\n`\n\nexport const CART_LINES_REMOVE = `\n mutation cartLinesRemove($cartId: ID!, $lineIds: [ID!]!) {\n cartLinesRemove(cartId: $cartId, lineIds: $lineIds) {\n cart {\n ...CartFragment\n }\n userErrors {\n field\n message\n }\n }\n }\n ${CART_FRAGMENT}\n`\n\nexport const CART_DISCOUNT_CODES_UPDATE = `\n mutation cartDiscountCodesUpdate($cartId: ID!, $discountCodes: [String!]!) {\n cartDiscountCodesUpdate(cartId: $cartId, discountCodes: $discountCodes) {\n cart {\n ...CartFragment\n }\n userErrors {\n field\n message\n }\n }\n }\n ${CART_FRAGMENT}\n`\n","export function toGId (id: number, type: string): string {\n return `gid://shopify/${type}/${id}`\n}\n\nexport function toId (id: string): number {\n return Number(id.split('/').pop())\n}","import type { CartData, ICart } from '../types'\nimport { createCookie, readCookie } from '../utils/cookies'\nimport type { CartReturn } from '@shopify/hydrogen'\nimport { StorefrontClient } from '../utils/storefront-client'\nimport {\n CART_LINES_ADD,\n CART_LINES_UPDATE,\n CART_LINES_REMOVE,\n CART_DISCOUNT_CODES_UPDATE\n} from '../graphql/queries/cart'\nimport { toGId, toId } from '../utils/id'\n\nconst COUPON_COOKIE_NAME = '_ply_coupon'\n\nexport class Cart implements ICart {\n private storefrontClient: StorefrontClient\n\n private listeners: Array<(cart: CartData) => void> = []\n\n private cart: CartReturn | null = null\n\n private cartPromise: Promise<CartReturn> | null\n\n private revalidate?: () => void\n\n constructor (cartPromise: Promise<CartReturn>, storefrontClient: StorefrontClient, revalidate?: () => void) {\n this.storefrontClient = storefrontClient\n this.cartPromise = cartPromise\n this.revalidate = revalidate\n }\n\n /**\n * Update internal cart data\n * Called by Provider when cart data changes from loader\n */\n updateCartData (cart: CartReturn): void {\n this.cart = cart\n this.cartPromise = null\n }\n\n /**\n * Notify all listeners of cart change\n * Called by Provider when cart updates\n */\n notifyListeners (): void {\n if (!this.cart) return\n\n this.listeners.forEach((listener) => {\n try {\n if (this.cart) {\n listener(this.toCartData(this.cart))\n }\n } catch (error) {\n console.error('Cart listener error:', error)\n }\n })\n }\n\n /**\n * Check if cart data is loaded and synced\n */\n isSynced (): boolean {\n return !!this.cart\n }\n\n /**\n * Register a callback to be called when cart changes\n * Returns a function to unregister the callback\n */\n onChange (callback: (cart: CartData) => void): () => void {\n this.listeners.push(callback)\n\n // Return unsubscribe function\n return () => {\n const index = this.listeners.indexOf(callback)\n if (index > -1) {\n this.listeners.splice(index, 1)\n }\n }\n }\n\n /**\n * Fetch current cart data\n * Returns cached cart data from loader (always fresh from React Router)\n */\n async fetch (force: boolean = true): Promise<CartData | null> {\n if (this.cart && !force) {\n return this.toCartData(this.cart)\n }\n\n if (this.cartPromise) {\n this.cart = await this.cartPromise\n return this.toCartData(this.cart)\n }\n\n if (!this.cart) return null\n\n return this.toCartData(this.cart)\n }\n\n /**\n * Update cart via Storefront API mutations\n * Actions: 'add', 'update', 'change', 'clear'\n */\n async update (action: string, data: any): Promise<void> {\n if (!this.cart) {\n throw new Error('Cart not initialized')\n }\n\n const lineIds = this.cart.lines.nodes.map((line: any) => line.id)\n\n try {\n let result: any\n\n switch (action) {\n case 'add':\n result = await this.storefrontClient.mutate(CART_LINES_ADD, {\n cartId: this.cart.id,\n lines: [{\n merchandiseId: toGId(data.id, 'ProductVariant'),\n quantity: data.quantity || 1,\n attributes: data.properties\n ? Object.entries(data.properties).map(([key, value]) => ({\n key,\n value: String(value)\n }))\n : undefined\n }]\n })\n\n // Update local cart immediately with mutation response\n if (result?.cartLinesAdd?.cart) {\n this.cart = result.cartLinesAdd.cart\n this.notifyListeners()\n }\n break\n\n case 'update':\n case 'change':\n // Handle Cart AJAX API format: { updates: { [variantId]: quantity } }\n if (data.updates) {\n // Separate into lines to update vs lines to add\n const linesToUpdate: any[] = []\n const linesToAdd: any[] = []\n\n Object.entries(data.updates).forEach(([variantId, quantity]) => {\n const line = this.cart!.lines.nodes.find((line: any) =>\n toId(line.merchandise.id) === Number(variantId))\n\n if (line) {\n linesToUpdate.push({\n id: line.id,\n quantity: Number(quantity)\n })\n } else if (Number(quantity) > 0) {\n // Line doesn't exist and quantity > 0 - add it\n linesToAdd.push({\n merchandiseId: toGId(Number(variantId), 'ProductVariant'),\n quantity: Number(quantity)\n })\n }\n })\n\n // Execute mutations in parallel\n const mutations: Promise<any>[] = []\n\n if (linesToUpdate.length > 0) {\n mutations.push(this.storefrontClient.mutate(CART_LINES_UPDATE, {\n cartId: this.cart.id,\n lines: linesToUpdate\n }))\n }\n\n if (linesToAdd.length > 0) {\n mutations.push(this.storefrontClient.mutate(CART_LINES_ADD, {\n cartId: this.cart.id,\n lines: linesToAdd\n }))\n }\n\n if (mutations.length > 0) {\n const results = await Promise.all(mutations)\n // Use the last result's cart (both mutations return the updated cart)\n const lastResult = results[results.length - 1]\n if (lastResult?.cartLinesUpdate?.cart || lastResult?.cartLinesAdd?.cart) {\n this.cart = lastResult.cartLinesUpdate?.cart || lastResult.cartLinesAdd?.cart\n this.notifyListeners()\n }\n }\n } else {\n // Handle single item update (old format)\n result = await this.storefrontClient.mutate(CART_LINES_UPDATE, {\n cartId: this.cart.id,\n lines: [{\n id: `gid://shopify/CartLine/${data.id}`,\n quantity: data.quantity\n }]\n })\n\n // Update local cart immediately with mutation response\n if (result?.cartLinesUpdate?.cart) {\n this.cart = result.cartLinesUpdate.cart\n this.notifyListeners()\n }\n }\n\n // Handle discount update\n if (data.discount && this.cart) {\n result = await this.storefrontClient.mutate(CART_DISCOUNT_CODES_UPDATE, {\n cartId: this.cart.id,\n discountCodes: [data.discount]\n })\n\n // Update local cart immediately\n if (result?.cartDiscountCodesUpdate?.cart) {\n this.cart = result.cartDiscountCodesUpdate.cart\n this.notifyListeners()\n }\n }\n break\n\n case 'clear':\n result = await this.storefrontClient.mutate(CART_LINES_REMOVE, {\n cartId: this.cart.id,\n lineIds\n })\n\n // Update local cart immediately with mutation response\n if (result?.cartLinesRemove?.cart) {\n this.cart = result.cartLinesRemove.cart\n this.notifyListeners()\n }\n break\n\n default:\n console.warn(`Unknown cart action: ${action}`)\n }\n\n // Trigger revalidation to fetch fresh cart data from loader\n if (this.revalidate) {\n this.revalidate()\n }\n } catch (error) {\n console.error('Cart update error:', error)\n throw error\n }\n }\n\n /**\n * Quick buy - redirect to checkout with variant\n */\n async buy (_variantId: string, _quantity: number = 1): Promise<void> {\n if (!this.cart) return\n\n const coupon = this.getCoupon()\n const baseUrl = this.cart.checkoutUrl || '/checkout'\n const url = coupon ? `${baseUrl}?discount=${coupon}` : baseUrl\n\n if (typeof window !== 'undefined') {\n window.location.href = url\n }\n }\n\n /**\n * Get cart data or specific property\n */\n get (property?: string): any {\n if (!this.cart) {\n return property ? undefined : null\n }\n\n if (!property) {\n return this.toCartData(this.cart)\n }\n\n return (this.toCartData(this.cart) as any)[property]\n }\n\n /**\n * Get cart token/ID\n */\n getToken (): string | null {\n if (!this.cart) return null\n\n return this.cart.id || null\n }\n\n /**\n * Get array of product IDs in cart\n */\n getItemsIds (): string[] {\n if (!this.cart) {\n return []\n }\n\n return this.cart.lines.nodes.map(line => line.merchandise.product.id)\n }\n\n /**\n * Get cart currency code\n */\n getCurrency (): string {\n if (!this.cart) return 'USD'\n\n return this.cart.cost.totalAmount.currencyCode\n }\n\n /**\n * Get cart total value\n * For Hydrogen, currency conversion would need to be handled separately\n */\n getValue (_currency?: string): number {\n if (!this.cart) return 0\n\n return parseFloat(this.cart.cost.totalAmount.amount) * 100\n }\n\n /**\n * Get cart item count\n * @param distinct - Count distinct products instead of total quantity\n */\n getSize (distinct: boolean = false): number {\n if (!this.cart) return 0\n\n if (distinct) {\n const uniqueProductIds = new Set(this.cart.lines.nodes.map(line => line.merchandise.product.id))\n return uniqueProductIds.size\n }\n\n return this.cart.totalQuantity\n }\n\n /**\n * Fetch cart collections data\n * Requires custom implementation or metafield query\n */\n async fetchCollections (_force: boolean = false): Promise<any> {\n console.warn('fetchCollections: Not implemented for Hydrogen. Use custom metafield query.')\n return {}\n }\n\n /**\n * Apply discount code to cart\n */\n async applyCoupon (code: string, expiresIn?: number): Promise<void> {\n if (!this.cart) {\n throw new Error('Cart not initialized')\n }\n\n // Store in cookie\n createCookie(COUPON_COOKIE_NAME, code, expiresIn)\n\n try {\n const result = await this.storefrontClient.mutate(CART_DISCOUNT_CODES_UPDATE, {\n cartId: this.cart.id,\n discountCodes: [code]\n })\n\n // Update local cart immediately with mutation response\n if (result?.cartDiscountCodesUpdate?.cart) {\n this.cart = result.cartDiscountCodesUpdate.cart\n this.notifyListeners()\n }\n\n // Trigger revalidation to fetch fresh cart data from loader (backup)\n if (this.revalidate) {\n this.revalidate()\n }\n } catch (error) {\n console.error('Error applying coupon:', error)\n throw error\n }\n }\n\n /**\n * Get currently applied coupon code\n */\n getCoupon (): string | null {\n if (!this.cart) return null\n\n // First check cart discount codes\n if (this.cart.discountCodes && this.cart.discountCodes.length > 0) {\n return this.cart.discountCodes[0].code\n }\n\n // Fall back to cookie\n return readCookie(COUPON_COOKIE_NAME)\n }\n\n /**\n * Convert Hydrogen cart to CartData format\n * For compatibility with snippet-manager\n */\n private toCartData (cart: CartReturn): CartData {\n return {\n token: cart.id,\n item_count: cart.totalQuantity || 0,\n items: (cart.lines?.nodes || []).map(line => ({\n id: toId(line.id),\n product_id: toId(line.merchandise.product.id),\n variant_id: toId(line.merchandise.id),\n price: Number(line.merchandise.price.amount) * 100,\n quantity: line.quantity\n })),\n total_price: Number(cart.cost.totalAmount.amount) * 100,\n discount_codes: cart.discountCodes,\n attributes: cart.attributes,\n note: cart.note\n }\n }\n}\n","/**\n * GraphQL queries for product operations\n */\n\nexport const PRODUCT_FRAGMENT = `\n fragment ProductFragment on Product {\n id\n handle\n title\n description\n descriptionHtml\n productType\n vendor\n tags\n availableForSale\n requiresSellingPlan\n priceRange {\n minVariantPrice {\n amount\n currencyCode\n }\n maxVariantPrice {\n amount\n currencyCode\n }\n }\n featuredImage {\n id\n url\n altText\n width\n height\n }\n images(first: 10) {\n nodes {\n id\n url\n altText\n width\n height\n }\n }\n variants(first: 100) {\n nodes {\n id\n title\n availableForSale\n quantityAvailable\n sellingPlanAllocations(first: 10) {\n edges {\n node {\n sellingPlan {\n id\n }\n }\n }\n }\n sku\n price {\n amount\n currencyCode\n }\n compareAtPrice {\n amount\n currencyCode\n }\n selectedOptions {\n name\n value\n }\n image {\n id\n url\n altText\n width\n height\n }\n }\n }\n options {\n id\n name\n values\n }\n collections(first: 10) {\n nodes {\n id\n handle\n title\n }\n }\n }\n`\n\nexport const GET_PRODUCT_BY_HANDLE = `\n query getProductByHandle($handle: String!) {\n product(handle: $handle) {\n ...ProductFragment\n }\n }\n ${PRODUCT_FRAGMENT}\n`\n\nexport const GET_PRODUCT_BY_ID = `\n query getProductById($id: ID!) {\n product(id: $id) {\n ...ProductFragment\n }\n }\n ${PRODUCT_FRAGMENT}\n`\n\nexport const GET_PRODUCT_RECOMMENDATIONS = `\n query getProductRecommendations($productId: ID!) {\n productRecommendations(productId: $productId) {\n ...ProductFragment\n }\n }\n ${PRODUCT_FRAGMENT}\n`\n","/**\n * GraphQL queries for customer operations\n */\n\nexport const CUSTOMER_FRAGMENT = `\n fragment CustomerFragment on Customer {\n id\n email\n phone\n firstName\n lastName\n displayName\n defaultAddress {\n id\n address1\n address2\n city\n province\n country\n zip\n }\n }\n`\n\nexport const ORDER_FRAGMENT = `\n fragment OrderFragment on Order {\n id\n orderNumber\n processedAt\n financialStatus\n fulfillmentStatus\n totalPrice {\n amount\n currencyCode\n }\n lineItems(first: 100) {\n nodes {\n title\n quantity\n variant {\n id\n title\n price {\n amount\n currencyCode\n }\n image {\n url\n altText\n }\n }\n }\n }\n }\n`\n\nexport const GET_CUSTOMER = `\n query getCustomer($customerAccessToken: String!) {\n customer(customerAccessToken: $customerAccessToken) {\n ...CustomerFragment\n }\n }\n ${CUSTOMER_FRAGMENT}\n`\n\nexport const GET_CUSTOMER_ORDERS = `\n query getCustomerOrders($customerAccessToken: String!, $first: Int = 20) {\n customer(customerAccessToken: $customerAccessToken) {\n id\n orders(first: $first, sortKey: PROCESSED_AT, reverse: true) {\n nodes {\n ...OrderFragment\n }\n }\n }\n }\n ${ORDER_FRAGMENT}\n`\n","import type {\n IShopifyAdapter,\n Product,\n Customer,\n PageContext,\n PersonizelyConfig,\n PersonizelyConfigMethods,\n ProductData\n} from '../types'\nimport { StorefrontClient } from '../utils/storefront-client'\nimport {\n GET_PRODUCT_BY_HANDLE, GET_PRODUCT_BY_ID,\n GET_PRODUCT_RECOMMENDATIONS\n} from '../graphql/queries/product'\nimport { GET_CUSTOMER } from '../graphql/queries/customer'\nimport { toId } from '../utils/id'\n\nexport class Adapter implements IShopifyAdapter {\n private client: StorefrontClient\n\n private currency: {\n active: string\n base: string\n rate: number\n }\n\n private market: string | null\n\n private locale: string\n\n private pageContext: PageContext\n\n private methods?: PersonizelyConfigMethods\n\n private customerAccessToken: string | null = null\n\n constructor (config: PersonizelyConfig, storefrontClient: StorefrontClient) {\n this.client = storefrontClient\n\n this.methods = config.methods\n this.currency = { active: 'USD', base: 'USD', rate: 1, ...config.currency }\n this.locale = config.locale || 'en-US'\n this.market = config.market || null\n\n this.pageContext = {\n pageType: undefined,\n product: null,\n collection: null\n }\n }\n\n /**\n * Set customer access token for authenticated requests\n */\n setCustomerAccessToken (token: string | null): void {\n this.customerAccessToken = token\n }\n\n /**\n * Fetch product by handle from Storefront API\n */\n async fetchProduct (handle: string): Promise<ProductData> {\n const data = await this.client.query<{ product: Product }>(GET_PRODUCT_BY_HANDLE, { handle })\n\n if (!data.product) {\n throw new Error(`Product not found: ${handle}`)\n }\n\n return this.toProductData(data.product)\n }\n\n /**\n * Fetch product collections metadata\n */\n async fetchProductCollections (handle: string, productId: number): Promise<number[]> {\n let data\n if (productId) {\n data = await this.client.query<{ product: Product }>(GET_PRODUCT_BY_ID, { id: `gid://shopify/Product/${productId}` })\n } else if (handle) {\n data = await this.client.query<{ product: Product }>(GET_PRODUCT_BY_HANDLE, { handle })\n }\n\n if (!data || !data.product) {\n throw new Error(`Product not found: ${productId}`)\n }\n\n return data.product.collections.nodes.map(c => toId(c.id))\n }\n\n /**\n * Fetch product recommendations\n */\n async fetchRecommendations (productId: number, intent: string): Promise<{ products: ProductData[], intent: string }> {\n const data = await this.client.query<{ productRecommendations: Product[] }>(GET_PRODUCT_RECOMMENDATIONS, { productId: `gid://shopify/Product/${productId}`, intent })\n\n return {\n intent,\n products: data.productRecommendations.map(p => this.toProductData(p)) || []\n }\n }\n\n /**\n * Build product URL path\n */\n buildProductPath (product: { handle: string }): string {\n if (typeof this.methods?.builtProductPath !== 'function') return `/products/${product.handle}`\n\n return this.methods.builtProductPath(product)\n }\n\n /**\n * Convert currency amount\n */\n convertToBaseCurrency (amount: number): number {\n return this.currency.rate / amount\n }\n\n /**\n * Convert currency amount\n */\n convertFromBaseCurrency (amount: number): number {\n return this.currency.rate * amount\n }\n\n /**\n * Format money according to shop's format\n */\n formatMoney (amount: number, includeDecimals: boolean = true): string {\n if (typeof this.methods?.formatMoney !== 'function') return new Intl.NumberFormat(this.locale, {\n style: 'currency',\n currency: this.currency.active,\n maximumFractionDigits: includeDecimals ? undefined : 0\n }).format(amount / 100)\n\n return this.methods.formatMoney(amount, includeDecimals)\n }\n\n /**\n * Fetch customer data from Storefront API\n * Requires customer access token to be set\n */\n async getCustomer (): Promise<Customer | null> {\n if (!this.customerAccessToken) {\n return null\n }\n\n try {\n const data = await this.client.query<{ customer: Customer }>(GET_CUSTOMER, { customerAccessToken: this.customerAccessToken })\n\n return data.customer || null\n } catch (error) {\n console.error('Error fetching customer:', error)\n return null\n }\n }\n\n /**\n * Get current page context\n * Auto-detected from Remix router in Provider\n */\n getPageContext (): PageContext {\n return this.pageContext\n }\n\n setPageContext (context: Partial<PageContext>) {\n if (context.product) {\n context.product.id = toId(String(context.product.id))\n }\n if (context.collection) {\n context.collection.id = toId(String(context.collection.id))\n }\n this.pageContext = context\n }\n\n getVisitorId (): string | null {\n return null\n }\n\n /**\n * Get current market information\n */\n getMarket (): string | null {\n return this.market\n }\n\n /**\n * Get currency conversion rate\n * Note: Stub implementation\n */\n getCurrencyRate (): number {\n return this.currency.rate\n }\n\n /**\n * Transform Hydrogen Product to snippet-manager ProductData format\n */\n toProductData (product: Product): ProductData {\n return {\n id: toId(product.id),\n handle: product.handle,\n title: product.title,\n available: product.availableForSale,\n requires_selling_plan: product.requiresSellingPlan,\n images: product.images.nodes.map(img => img.url),\n variants: product.variants.nodes.map(variant => ({\n id: toId(variant.id),\n title: variant.title,\n available: variant.availableForSale,\n price: Math.round(parseFloat(variant.price.amount) * 100), // Convert to cents\n compare_at_price: variant.compareAtPrice\n ? Math.round(parseFloat(variant.compareAtPrice.amount) * 100)\n : null,\n featured_image: variant.image ? { src: variant.image.url } : null,\n selling_plan_allocations: variant.sellingPlanAllocations?.edges?.map(edge => ({\n selling_plan_id: edge.node.sellingPlan.id\n })) || []\n }))\n }\n }\n}\n","/**\n * Shopify Storefront API GraphQL client\n */\n\nexport type StorefrontClientConfig = {\n storefrontAccessToken: string\n shopDomain: string\n apiVersion?: string\n}\n\nexport class StorefrontClient {\n private storefrontAccessToken: string\n\n private shopDomain: string\n\n private apiVersion: string\n\n private endpoint: string\n\n constructor (config: StorefrontClientConfig) {\n this.storefrontAccessToken = config.storefrontAccessToken\n this.shopDomain = config.shopDomain\n this.apiVersion = config.apiVersion || '2024-01'\n this.endpoint = `https://${this.shopDomain}/api/${this.apiVersion}/graphql.json`\n }\n\n /**\n * Execute a GraphQL query against the Storefront API\n */\n async query<T = any>(query: string, variables?: Record<string, any>): Promise<T> {\n try {\n const response = await fetch(this.endpoint, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Shopify-Storefront-Access-Token': this.storefrontAccessToken\n },\n body: JSON.stringify({\n query,\n variables\n })\n })\n\n if (!response.ok) {\n throw new Error(`Storefront API request failed: ${response.statusText}`)\n }\n\n const result = await response.json()\n\n if (result.errors) {\n throw new Error(`GraphQL errors: ${JSON.stringify(result.errors)}`)\n }\n\n return result.data as T\n } catch (error) {\n console.error('Storefront API error:', error)\n throw error\n }\n }\n\n /**\n * Execute a GraphQL mutation against the Storefront API\n */\n async mutate<T = any>(mutation: string, variables?: Record<string, any>): Promise<T> {\n return this.query<T>(mutation, variables)\n }\n}\n","import React, { createContext, useEffect, useMemo, useRef, ReactNode } from 'react'\nimport { useMatches, useRevalidator } from 'react-router'\nimport {\n PersonizelyConfigMethods,\n HydrogenConfig,\n CartAddProduct\n} from '../types'\nimport type { CartReturn } from '@shopify/hydrogen'\nimport { Cart } from '../classes/Cart'\nimport { Adapter } from '../classes/Adapter'\nimport { StorefrontClient } from '../utils/storefront-client'\n\ndeclare global {\n interface Window {\n __PLY_HYDROGEN_CONFIG__?: HydrogenConfig\n }\n}\n\nexport type PersonizelyContextType = {\n cart: Cart\n adapter: Adapter\n websiteApiKey: string\n triggerCartAdd: (product: CartAddProduct) => Promise<boolean>\n triggerCheckout: () => Promise<boolean>\n}\n\nexport const PersonizelyContext = createContext<PersonizelyContextType | null>(null)\n\nexport type PersonizelyProviderProps = {\n websiteApiKey: string\n storefrontAccessToken: string\n shopDomain: string\n apiVersion?: string\n scriptBaseUrl?: string\n locale?: string\n currency?: {\n rate: number\n active: string\n base: string\n }\n market?: string\n methods?: PersonizelyConfigMethods\n children: ReactNode\n /**\n * Optional: Customer access token for authenticated requests\n */\n customerAccessToken?: string | null\n}\n\nexport function PersonizelyProvider ({\n websiteApiKey,\n storefrontAccessToken,\n shopDomain,\n locale,\n currency,\n market,\n apiVersion,\n scriptBaseUrl,\n methods,\n children,\n customerAccessToken\n}: PersonizelyProviderProps) {\n const matches = useMatches()\n const rootMatch = matches.find(m => m.id === 'root')\n const localCart = (rootMatch?.loaderData as any)?.cart as Promise<CartReturn>\n const revalidator = useRevalidator()\n\n const storefrontClient = useMemo(() => {\n return new StorefrontClient({\n storefrontAccessToken,\n shopDomain,\n apiVersion\n })\n }, [storefrontAccessToken, shopDomain, apiVersion])\n\n const adapter = useMemo(() => {\n const adapterInstance = new Adapter({\n locale,\n currency,\n market,\n methods\n }, storefrontClient)\n\n if (customerAccessToken) {\n adapterInstance.setCustomerAccessToken(customerAccessToken)\n }\n\n return adapterInstance\n }, [])\n\n const cart = useMemo(() => new Cart(localCart, storefrontClient, revalidator.revalidate), [])\n\n // Update cart data when it changes from the loader\n const prevCartDataRef = useRef<CartReturn | null>(null)\n useEffect(() => {\n localCart.then((data) => {\n if (data && data !== prevCartDataRef.current) {\n cart.updateCartData(data)\n cart.notifyListeners()\n prevCartDataRef.current = data\n }\n })\n }, [localCart, cart])\n\n const cartAddCallbacksRef = useRef<Array<(product: CartAddProduct) => Promise<boolean>>>([])\n const checkoutCallbacksRef = useRef<Array<() => Promise<boolean>>>([])\n\n // Set up window.__PLY_HYDROGEN_CONFIG__ and load Personizely script\n useEffect(() => {\n if (typeof window === 'undefined') {\n return\n }\n\n window.__PLY_HYDROGEN_CONFIG__ = {\n cart,\n adapter,\n onCartAdd: (callback) => {\n cartAddCallbacksRef.current.push(callback)\n\n return () => {\n const index = cartAddCallbacksRef.current.indexOf(callback)\n if (index > -1) {\n cartAddCallbacksRef.current.splice(index, 1)\n }\n }\n },\n onCheckout: (callback) => {\n checkoutCallbacksRef.current.push(callback)\n\n return () => {\n const index = checkoutCallbacksRef.current.indexOf(callback)\n if (index > -1) {\n checkoutCallbacksRef.current.splice(index, 1)\n }\n }\n }\n }\n\n const script = document.createElement('script')\n const baseUrl = scriptBaseUrl || 'https://static.personizely.net'\n script.src = `${baseUrl}/${websiteApiKey}.js`\n document.head.appendChild(script)\n\n return () => {\n delete window.__PLY_HYDROGEN_CONFIG__\n if (script) {\n script.remove()\n }\n }\n }, [])\n\n const contextValue = useMemo(() => ({\n cart,\n adapter,\n websiteApiKey,\n triggerCartAdd: async (product: CartAddProduct): Promise<boolean> => {\n let shown = false\n for (const callback of cartAddCallbacksRef.current) {\n try {\n const result = await callback(product)\n if (result) {\n shown = true\n }\n } catch (error) {\n console.error('Cart add callback error:', error)\n }\n }\n return shown\n },\n triggerCheckout: async (): Promise<boolean> => {\n let shown = false\n for (const callback of checkoutCallbacksRef.current) {\n try {\n const result = await callback()\n if (result) {\n shown = true\n }\n } catch (error) {\n console.error('Checkout callback error:', error)\n }\n }\n return shown\n }\n }), [cart, adapter, websiteApiKey])\n\n return (\n <PersonizelyContext.Provider value={contextValue}>\n {children}\n </PersonizelyContext.Provider>\n )\n}\n","/**\n * usePersonizely - Access Personizely context\n */\n\nimport { useContext } from 'react'\nimport { PersonizelyContext, PersonizelyContextType } from '../components/PersonizelyProvider'\n\n/**\n * Hook to access Personizely context\n * Provides access to cart, adapter, and configuration\n *\n * @returns PersonizelyContextType\n * @throws Error if used outside PersonizelyProvider\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const { cart, adapter } = usePersonizely()\n * // Use cart and adapter...\n * }\n * ```\n */\nexport function usePersonizely (): PersonizelyContextType {\n const context = useContext(PersonizelyContext)\n\n if (!context) {\n throw new Error('usePersonizely must be used within a PersonizelyProvider. ' +\n 'Make sure your component is wrapped with <PersonizelyProvider>.')\n }\n\n return context\n}\n","/**\n * useCartAdd - Hook to trigger Personizely cart add widgets\n */\n\nimport { useCallback } from 'react'\nimport type { CartAddProduct } from '../types'\nimport { usePersonizely } from './usePersonizely'\nimport { toId } from '../utils/id'\n\n/**\n * Hook to trigger Personizely cart add event\n * Call this when a product is being added to cart to show relevant widgets\n *\n * @returns Function to trigger cart add event\n *\n * @example\n * ```tsx\n * function ProductForm({ product, selectedVariant }) {\n * const triggerCartAdd = useCartAdd()\n *\n * const handleAddToCart = async () => {\n * const widgetShown = await triggerCartAdd({\n * id: product.id,\n * variantId: selectedVariant.id,\n * price: parseFloat(selectedVariant.price.amount),\n * quantity: 1,\n * handle: product.handle\n * })\n *\n * if (!widgetShown) {\n * await cart.linesAdd([{\n * merchandiseId: selectedVariant.id,\n * quantity: 1\n * }])\n * }\n * }\n *\n * return <button onClick={handleAddToCart}>Add to Cart</button>\n * }\n * ```\n */\nexport function useCartAdd () {\n const personizely = usePersonizely()\n\n return useCallback(async (product: CartAddProduct): Promise<boolean> => {\n if (typeof window === 'undefined') {\n return false\n }\n\n return await personizely.triggerCartAdd({\n ...product,\n id: toId(String(product.id)),\n variantId: toId(String(product.variantId)),\n price: Number(product.price) * 100\n })\n }, [personizely])\n}\n","/**\n * useCheckout - Hook to trigger Personizely checkout widgets\n */\n\nimport { useCallback } from 'react'\nimport { usePersonizely } from './usePersonizely'\n\n/**\n * Hook to trigger Personizely checkout event\n * Call this when proceeding to checkout to show relevant widgets\n *\n * @returns Function to trigger checkout event\n *\n * @example\n * ```tsx\n * function CheckoutButton() {\n * const triggerCheckout = useCheckout()\n *\n * const handleCheckout = async () => {\n * const widgetShown = await triggerCheckout()\n *\n * if (!widgetShown) {\n * window.location.href = cart.checkoutUrl\n * }\n * }\n *\n * return <button onClick={handleCheckout}>Checkout</button>\n * }\n * ```\n */\nexport function useCheckout () {\n const personizely = usePersonizely()\n\n return useCallback(async (): Promise<boolean> => {\n if (typeof window === 'undefined') {\n return false\n }\n\n return await personizely.triggerCheckout()\n }, [personizely])\n}\n","import { usePersonizely } from './usePersonizely'\nimport { PageContext } from '../types'\n\nexport function usePageContext (context: Partial<PageContext>) {\n const personizely = usePersonizely()\n\n personizely.adapter.setPageContext(context)\n}\n"],"mappings":"gLAUA,SAAgB,EAAY,EAA6B,CACvD,GAAI,OAAO,SAAa,IACtB,OAAO,KAGT,IAAM,EAAS,EAAO,IAChB,EAAU,SAAS,OAAO,MAAM,IAAI,CAE1C,IAAK,IAAI,EAAI,EAAG,EAAI,EAAQ,OAAQ,IAAK,CACvC,IAAI,EAAS,EAAQ,GACrB,KAAO,EAAO,OAAO,EAAE,GAAK,KAC1B,EAAS,EAAO,UAAU,EAAG,EAAO,OAAO,CAE7C,GAAI,EAAO,QAAQ,EAAO,GAAK,EAC7B,OAAO,EAAO,UAAU,EAAO,OAAQ,EAAO,OAAO,CAIz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AQ,MAAM,2BAA4B,EAAM,CAGpD,OAAO,GAET,gBAAiB,SAA8B,CAC7C,IAAI,EAAQ,GACZ,IAAK,IAAM,KAAY,EAAqB,QAC1C,GAAI,CACa,MAAM,GAAU,GAE7B,EAAQ,UAEH,EAAO,CACd,QAAQ,MAAM,2BAA4B,EAAM,CAGpD,OAAO,GAEV,EAAG,CAAC,EAAM,EAAS,EAAc,CAAC,CAEnC,OACE,EAAA,cAAC,EAAmB,SAAA,CAAS,MAAO,EAAA,CACjC,EAC2B,CCtKlC,SAAgB,GAA0C,CACxD,IAAM,EAAU,EAAW,EAAmB,CAE9C,GAAI,CAAC,EACH,MAAU,MAAM,4HACoD,CAGtE,OAAO,ECWT,SAAgB,GAAc,CAC5B,IAAM,EAAc,GAAgB,CAEpC,OAAO,EAAY,KAAO,IACpB,OAAO,OAAW,IACb,GAGF,MAAM,EAAY,eAAe,CACtC,GAAG,EACH,GAAI,EAAK,OAAO,EAAQ,GAAG,CAAC,CAC5B,UAAW,EAAK,OAAO,EAAQ,UAAU,CAAC,CAC1C,MAAO,OAAO,EAAQ,MAAM,CAAG,IAChC,CAAC,CACD,CAAC,EAAY,CAAC,CCzBnB,SAAgB,GAAe,CAC7B,IAAM,EAAc,GAAgB,CAEpC,OAAO,EAAY,SACb,OAAO,OAAW,IACb,GAGF,MAAM,EAAY,iBAAiB,CACzC,CAAC,EAAY,CAAC,CCpCnB,SAAgB,EAAgB,EAA+B,CACzC,GAAgB,CAExB,QAAQ,eAAe,EAAQ"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["result: any","linesToUpdate: any[]","linesToAdd: any[]","line","mutations: Promise<any>[]"],"sources":["../src/utils/cookies.ts","../src/graphql/queries/cart.ts","../src/utils/id.ts","../src/classes/Cart.ts","../src/graphql/queries/product.ts","../src/graphql/queries/customer.ts","../src/classes/Adapter.ts","../src/utils/storefront-client.ts","../src/components/PersonizelyProvider.tsx","../src/hooks/usePersonizely.ts","../src/hooks/useCartAdd.ts","../src/hooks/useCheckout.ts","../src/hooks/usePageContext.ts"],"sourcesContent":["/**\n * Cookie utilities for browser storage\n * Mirrors cookie helpers from snippet-manager\n */\n\n/**\n * Read a cookie value by name\n * @param name - Cookie name\n * @returns Cookie value or null if not found\n */\nexport function readCookie (name: string): string | null {\n if (typeof document === 'undefined') {\n return null\n }\n\n const nameEQ = name + '='\n const cookies = document.cookie.split(';')\n\n for (let i = 0; i < cookies.length; i++) {\n let cookie = cookies[i]\n while (cookie.charAt(0) === ' ') {\n cookie = cookie.substring(1, cookie.length)\n }\n if (cookie.indexOf(nameEQ) === 0) {\n return cookie.substring(nameEQ.length, cookie.length)\n }\n }\n\n return null\n}\n\n/**\n * Create/update a cookie\n * @param name - Cookie name\n * @param value - Cookie value\n * @param days - Expiration in days (optional, default: session cookie)\n * @param path - Cookie path (default: '/')\n */\nexport function createCookie (name: string,\n value: string,\n days?: number,\n path: string = '/'): void {\n if (typeof document === 'undefined') {\n return\n }\n\n let expires = ''\n if (days) {\n const date = new Date()\n date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000))\n expires = '; expires=' + date.toUTCString()\n }\n\n document.cookie = name + '=' + value + expires + '; path=' + path\n}\n\n/**\n * Delete a cookie by name\n * @param name - Cookie name\n * @param path - Cookie path (default: '/')\n */\nexport function deleteCookie (name: string, path: string = '/'): void {\n createCookie(name, '', -1, path)\n}\n","/**\n * GraphQL queries and mutations for cart operations\n */\n\nexport const CART_FRAGMENT = `\n fragment CartFragment on Cart {\n id\n checkoutUrl\n totalQuantity\n cost {\n subtotalAmount {\n amount\n currencyCode\n }\n totalAmount {\n amount\n currencyCode\n }\n totalTaxAmount {\n amount\n currencyCode\n }\n }\n lines(first: 100) {\n nodes {\n id\n quantity\n cost {\n totalAmount {\n amount\n currencyCode\n }\n amountPerQuantity {\n amount\n currencyCode\n }\n }\n merchandise {\n ... on ProductVariant {\n id\n title\n price {\n amount\n currencyCode\n }\n image {\n url\n altText\n }\n selectedOptions {\n name\n value\n }\n product {\n id\n handle\n title\n featuredImage {\n url\n altText\n }\n tags\n }\n }\n }\n attributes {\n key\n value\n }\n }\n }\n discountCodes {\n code\n applicable\n }\n attributes {\n key\n value\n }\n }\n`\n\nexport const GET_CART = `\n query getCart($cartId: ID!) {\n cart(id: $cartId) {\n ...CartFragment\n }\n }\n ${CART_FRAGMENT}\n`\n\n/**\n * Cart mutations\n */\n\nexport const CART_LINES_ADD = `\n mutation cartLinesAdd($cartId: ID!, $lines: [CartLineInput!]!) {\n cartLinesAdd(cartId: $cartId, lines: $lines) {\n cart {\n ...CartFragment\n }\n userErrors {\n field\n message\n }\n }\n }\n ${CART_FRAGMENT}\n`\n\nexport const CART_LINES_UPDATE = `\n mutation cartLinesUpdate($cartId: ID!, $lines: [CartLineUpdateInput!]!) {\n cartLinesUpdate(cartId: $cartId, lines: $lines) {\n cart {\n ...CartFragment\n }\n userErrors {\n field\n message\n }\n }\n }\n ${CART_FRAGMENT}\n`\n\nexport const CART_LINES_REMOVE = `\n mutation cartLinesRemove($cartId: ID!, $lineIds: [ID!]!) {\n cartLinesRemove(cartId: $cartId, lineIds: $lineIds) {\n cart {\n ...CartFragment\n }\n userErrors {\n field\n message\n }\n }\n }\n ${CART_FRAGMENT}\n`\n\nexport const CART_DISCOUNT_CODES_UPDATE = `\n mutation cartDiscountCodesUpdate($cartId: ID!, $discountCodes: [String!]!) {\n cartDiscountCodesUpdate(cartId: $cartId, discountCodes: $discountCodes) {\n cart {\n ...CartFragment\n }\n userErrors {\n field\n message\n }\n }\n }\n ${CART_FRAGMENT}\n`\n\nexport const CART_ATTRIBUTES_UPDATE = `\n mutation cartAttributesUpdate($cartId: ID!, $attributes: [AttributeInput!]!) {\n cartAttributesUpdate(cartId: $cartId, attributes: $attributes) {\n cart {\n ...CartFragment\n }\n userErrors {\n field\n message\n }\n }\n }\n ${CART_FRAGMENT}\n`\n","export function toGId (id: number, type: string): string {\n return `gid://shopify/${type}/${id}`\n}\n\nexport function toId (id: string): number {\n return Number(id.split('/').pop())\n}","import type { CartData, ICart } from '../types'\nimport { createCookie, readCookie } from '../utils/cookies'\nimport type { CartReturn } from '@shopify/hydrogen'\nimport { StorefrontClient } from '../utils/storefront-client'\nimport {\n CART_LINES_ADD,\n CART_LINES_UPDATE,\n CART_LINES_REMOVE,\n CART_DISCOUNT_CODES_UPDATE,\n CART_ATTRIBUTES_UPDATE\n} from '../graphql/queries/cart'\nimport { toGId, toId } from '../utils/id'\n\nconst COUPON_COOKIE_NAME = '_ply_coupon'\n\nexport class Cart implements ICart {\n private storefrontClient: StorefrontClient\n\n private listeners: Array<(cart: CartData) => void> = []\n\n private cart: CartReturn | null = null\n\n private cartPromise: Promise<CartReturn> | null\n\n private revalidate?: () => void\n\n constructor (cartPromise: Promise<CartReturn>, storefrontClient: StorefrontClient, revalidate?: () => void) {\n this.storefrontClient = storefrontClient\n this.cartPromise = cartPromise\n this.revalidate = revalidate\n }\n\n /**\n * Update internal cart data\n * Called by Provider when cart data changes from loader\n */\n updateCartData (cart: CartReturn): void {\n this.cart = cart\n this.cartPromise = null\n }\n\n /**\n * Notify all listeners of cart change\n * Called by Provider when cart updates\n */\n notifyListeners (): void {\n if (!this.cart) return\n\n this.listeners.forEach((listener) => {\n try {\n if (this.cart) {\n listener(this.toCartData(this.cart))\n }\n } catch (error) {\n console.error('Cart listener error:', error)\n }\n })\n }\n\n /**\n * Check if cart data is loaded and synced\n */\n isSynced (): boolean {\n return !!this.cart\n }\n\n /**\n * Register a callback to be called when cart changes\n * Returns a function to unregister the callback\n */\n onChange (callback: (cart: CartData) => void): () => void {\n this.listeners.push(callback)\n\n // Return unsubscribe function\n return () => {\n const index = this.listeners.indexOf(callback)\n if (index > -1) {\n this.listeners.splice(index, 1)\n }\n }\n }\n\n /**\n * Fetch current cart data\n * Returns cached cart data from loader (always fresh from React Router)\n */\n async fetch (force: boolean = true): Promise<CartData | null> {\n if (this.cart && !force) {\n return this.toCartData(this.cart)\n }\n\n if (this.cartPromise) {\n this.cart = await this.cartPromise\n return this.toCartData(this.cart)\n }\n\n if (!this.cart) return null\n\n return this.toCartData(this.cart)\n }\n\n /**\n * Update cart via Storefront API mutations\n * Actions: 'add', 'update', 'change', 'clear'\n */\n async update (action: string, data: any): Promise<void> {\n if (!this.cart) {\n throw new Error('Cart not initialized')\n }\n\n const lineIds = this.cart.lines.nodes.map((line: any) => line.id)\n\n try {\n let result: any\n\n switch (action) {\n case 'add':\n result = await this.storefrontClient.mutate(CART_LINES_ADD, {\n cartId: this.cart.id,\n lines: [{\n merchandiseId: toGId(data.id, 'ProductVariant'),\n quantity: data.quantity || 1,\n attributes: data.properties\n ? Object.entries(data.properties).map(([key, value]) => ({\n key,\n value: String(value)\n }))\n : undefined\n }]\n })\n\n // Update local cart immediately with mutation response\n if (result?.cartLinesAdd?.cart) {\n this.cart = result.cartLinesAdd.cart\n this.notifyListeners()\n }\n break\n\n case 'update':\n case 'change':\n // Handle Cart AJAX API format: { updates: { [variantId]: quantity }, attributes: {...} }\n if (data.updates) {\n // Separate into lines to update vs lines to add\n const linesToUpdate: any[] = []\n const linesToAdd: any[] = []\n\n Object.entries(data.updates).forEach(([variantId, quantity]) => {\n const line = this.cart!.lines.nodes.find((line: any) =>\n toId(line.merchandise.id) === Number(variantId))\n\n if (line) {\n linesToUpdate.push({\n id: line.id,\n quantity: Number(quantity)\n })\n } else if (Number(quantity) > 0) {\n // Line doesn't exist and quantity > 0 - add it\n linesToAdd.push({\n merchandiseId: toGId(Number(variantId), 'ProductVariant'),\n quantity: Number(quantity)\n })\n }\n })\n\n // Execute mutations in parallel\n const mutations: Promise<any>[] = []\n\n if (linesToUpdate.length > 0) {\n mutations.push(this.storefrontClient.mutate(CART_LINES_UPDATE, {\n cartId: this.cart.id,\n lines: linesToUpdate\n }))\n }\n\n if (linesToAdd.length > 0) {\n mutations.push(this.storefrontClient.mutate(CART_LINES_ADD, {\n cartId: this.cart.id,\n lines: linesToAdd\n }))\n }\n\n if (mutations.length > 0) {\n const results = await Promise.all(mutations)\n // Use the last result's cart (both mutations return the updated cart)\n const lastResult = results[results.length - 1]\n if (lastResult?.cartLinesUpdate?.cart || lastResult?.cartLinesAdd?.cart) {\n this.cart = lastResult.cartLinesUpdate?.cart || lastResult.cartLinesAdd?.cart\n this.notifyListeners()\n }\n }\n } else if (data.id) {\n // Handle single line item update\n result = await this.storefrontClient.mutate(CART_LINES_UPDATE, {\n cartId: this.cart.id,\n lines: [{\n id: `gid://shopify/CartLine/${data.id}`,\n quantity: data.quantity\n }]\n })\n\n // Update local cart immediately with mutation response\n if (result?.cartLinesUpdate?.cart) {\n this.cart = result.cartLinesUpdate.cart\n this.notifyListeners()\n }\n }\n\n // Handle cart-level attributes update\n if (data.attributes && this.cart) {\n result = await this.storefrontClient.mutate(CART_ATTRIBUTES_UPDATE, {\n cartId: this.cart.id,\n attributes: Object.entries(data.attributes).map(([key, value]) => ({\n key,\n value: String(value)\n }))\n })\n\n // Update local cart immediately\n if (result?.cartAttributesUpdate?.cart) {\n this.cart = result.cartAttributesUpdate.cart\n this.notifyListeners()\n }\n }\n\n // Handle discount update\n if (data.discount && this.cart) {\n result = await this.storefrontClient.mutate(CART_DISCOUNT_CODES_UPDATE, {\n cartId: this.cart.id,\n discountCodes: [data.discount]\n })\n\n // Update local cart immediately\n if (result?.cartDiscountCodesUpdate?.cart) {\n this.cart = result.cartDiscountCodesUpdate.cart\n this.notifyListeners()\n }\n }\n break\n\n case 'clear':\n result = await this.storefrontClient.mutate(CART_LINES_REMOVE, {\n cartId: this.cart.id,\n lineIds\n })\n\n // Update local cart immediately with mutation response\n if (result?.cartLinesRemove?.cart) {\n this.cart = result.cartLinesRemove.cart\n this.notifyListeners()\n }\n break\n\n default:\n console.warn(`Unknown cart action: ${action}`)\n }\n\n // Trigger revalidation to fetch fresh cart data from loader\n if (this.revalidate) {\n this.revalidate()\n }\n } catch (error) {\n console.error('Cart update error:', error)\n throw error\n }\n }\n\n /**\n * Quick buy - redirect to checkout with variant\n */\n async buy (_variantId: string, _quantity: number = 1): Promise<void> {\n if (!this.cart) return\n\n const coupon = this.getCoupon()\n const baseUrl = this.cart.checkoutUrl || '/checkout'\n const url = coupon ? `${baseUrl}?discount=${coupon}` : baseUrl\n\n if (typeof window !== 'undefined') {\n window.location.href = url\n }\n }\n\n /**\n * Get cart data or specific property\n */\n get (property?: string): any {\n if (!this.cart) {\n return property ? undefined : null\n }\n\n if (!property) {\n return this.toCartData(this.cart)\n }\n\n return (this.toCartData(this.cart) as any)[property]\n }\n\n /**\n * Get cart token/ID\n */\n getToken (): string | null {\n if (!this.cart) return null\n\n return this.cart.id || null\n }\n\n /**\n * Get array of product IDs in cart\n */\n getItemsIds (): string[] {\n if (!this.cart) {\n return []\n }\n\n return this.cart.lines.nodes.map(line => line.merchandise.product.id)\n }\n\n /**\n * Get cart currency code\n */\n getCurrency (): string {\n if (!this.cart) return 'USD'\n\n return this.cart.cost.totalAmount.currencyCode\n }\n\n /**\n * Get cart total value\n * For Hydrogen, currency conversion would need to be handled separately\n */\n getValue (_currency?: string): number {\n if (!this.cart) return 0\n\n return parseFloat(this.cart.cost.totalAmount.amount) * 100\n }\n\n /**\n * Get cart item count\n * @param distinct - Count distinct products instead of total quantity\n */\n getSize (distinct: boolean = false): number {\n if (!this.cart) return 0\n\n if (distinct) {\n const uniqueProductIds = new Set(this.cart.lines.nodes.map(line => line.merchandise.product.id))\n return uniqueProductIds.size\n }\n\n return this.cart.totalQuantity\n }\n\n /**\n * Fetch cart collections data\n * Requires custom implementation or metafield query\n */\n async fetchCollections (_force: boolean = false): Promise<any> {\n console.warn('fetchCollections: Not implemented for Hydrogen. Use custom metafield query.')\n return {}\n }\n\n /**\n * Apply discount code to cart\n */\n async applyCoupon (code: string, expiresIn?: number): Promise<void> {\n if (!this.cart) {\n throw new Error('Cart not initialized')\n }\n\n // Store in cookie\n createCookie(COUPON_COOKIE_NAME, code, expiresIn)\n\n try {\n const result = await this.storefrontClient.mutate(CART_DISCOUNT_CODES_UPDATE, {\n cartId: this.cart.id,\n discountCodes: [code]\n })\n\n // Update local cart immediately with mutation response\n if (result?.cartDiscountCodesUpdate?.cart) {\n this.cart = result.cartDiscountCodesUpdate.cart\n this.notifyListeners()\n }\n\n // Trigger revalidation to fetch fresh cart data from loader (backup)\n if (this.revalidate) {\n this.revalidate()\n }\n } catch (error) {\n console.error('Error applying coupon:', error)\n throw error\n }\n }\n\n /**\n * Get currently applied coupon code\n */\n getCoupon (): string | null {\n if (!this.cart) return null\n\n // First check cart discount codes\n if (this.cart.discountCodes && this.cart.discountCodes.length > 0) {\n return this.cart.discountCodes[0].code\n }\n\n // Fall back to cookie\n return readCookie(COUPON_COOKIE_NAME)\n }\n\n /**\n * Convert Hydrogen cart to CartData format\n * For compatibility with snippet-manager\n */\n private toCartData (cart: CartReturn): CartData {\n return {\n token: cart.id,\n item_count: cart.totalQuantity || 0,\n items: (cart.lines?.nodes || []).map(line => ({\n id: toId(line.id),\n product_id: toId(line.merchandise.product.id),\n variant_id: toId(line.merchandise.id),\n price: Number(line.merchandise.price.amount) * 100,\n quantity: line.quantity\n })),\n total_price: Number(cart.cost.totalAmount.amount) * 100,\n discount_codes: cart.discountCodes,\n attributes: cart.attributes,\n note: cart.note\n }\n }\n}\n","/**\n * GraphQL queries for product operations\n */\n\nexport const PRODUCT_FRAGMENT = `\n fragment ProductFragment on Product {\n id\n handle\n title\n description\n descriptionHtml\n productType\n vendor\n tags\n availableForSale\n requiresSellingPlan\n priceRange {\n minVariantPrice {\n amount\n currencyCode\n }\n maxVariantPrice {\n amount\n currencyCode\n }\n }\n featuredImage {\n id\n url\n altText\n width\n height\n }\n images(first: 10) {\n nodes {\n id\n url\n altText\n width\n height\n }\n }\n variants(first: 100) {\n nodes {\n id\n title\n availableForSale\n quantityAvailable\n sellingPlanAllocations(first: 10) {\n edges {\n node {\n sellingPlan {\n id\n }\n }\n }\n }\n sku\n price {\n amount\n currencyCode\n }\n compareAtPrice {\n amount\n currencyCode\n }\n selectedOptions {\n name\n value\n }\n image {\n id\n url\n altText\n width\n height\n }\n }\n }\n options {\n id\n name\n values\n }\n collections(first: 10) {\n nodes {\n id\n handle\n title\n }\n }\n }\n`\n\nexport const GET_PRODUCT_BY_HANDLE = `\n query getProductByHandle($handle: String!) {\n product(handle: $handle) {\n ...ProductFragment\n }\n }\n ${PRODUCT_FRAGMENT}\n`\n\nexport const GET_PRODUCT_BY_ID = `\n query getProductById($id: ID!) {\n product(id: $id) {\n ...ProductFragment\n }\n }\n ${PRODUCT_FRAGMENT}\n`\n\nexport const GET_PRODUCT_RECOMMENDATIONS = `\n query getProductRecommendations($productId: ID!) {\n productRecommendations(productId: $productId) {\n ...ProductFragment\n }\n }\n ${PRODUCT_FRAGMENT}\n`\n","/**\n * GraphQL queries for customer operations\n */\n\nexport const CUSTOMER_FRAGMENT = `\n fragment CustomerFragment on Customer {\n id\n email\n phone\n firstName\n lastName\n displayName\n defaultAddress {\n id\n address1\n address2\n city\n province\n country\n zip\n }\n }\n`\n\nexport const ORDER_FRAGMENT = `\n fragment OrderFragment on Order {\n id\n orderNumber\n processedAt\n financialStatus\n fulfillmentStatus\n totalPrice {\n amount\n currencyCode\n }\n lineItems(first: 100) {\n nodes {\n title\n quantity\n variant {\n id\n title\n price {\n amount\n currencyCode\n }\n image {\n url\n altText\n }\n }\n }\n }\n }\n`\n\nexport const GET_CUSTOMER = `\n query getCustomer($customerAccessToken: String!) {\n customer(customerAccessToken: $customerAccessToken) {\n ...CustomerFragment\n }\n }\n ${CUSTOMER_FRAGMENT}\n`\n\nexport const GET_CUSTOMER_ORDERS = `\n query getCustomerOrders($customerAccessToken: String!, $first: Int = 20) {\n customer(customerAccessToken: $customerAccessToken) {\n id\n orders(first: $first, sortKey: PROCESSED_AT, reverse: true) {\n nodes {\n ...OrderFragment\n }\n }\n }\n }\n ${ORDER_FRAGMENT}\n`\n","import type {\n IShopifyAdapter,\n Product,\n Customer,\n PageContext,\n PersonizelyConfig,\n PersonizelyConfigMethods,\n ProductData\n} from '../types'\nimport { StorefrontClient } from '../utils/storefront-client'\nimport {\n GET_PRODUCT_BY_HANDLE, GET_PRODUCT_BY_ID,\n GET_PRODUCT_RECOMMENDATIONS\n} from '../graphql/queries/product'\nimport { GET_CUSTOMER } from '../graphql/queries/customer'\nimport { toId } from '../utils/id'\n\nexport class Adapter implements IShopifyAdapter {\n private client: StorefrontClient\n\n private currency: {\n active: string\n base: string\n rate: number\n }\n\n private market: string | null\n\n private locale: string\n\n private pageContext: PageContext\n\n private methods?: PersonizelyConfigMethods\n\n private customerAccessToken: string | null = null\n\n constructor (config: PersonizelyConfig, storefrontClient: StorefrontClient) {\n this.client = storefrontClient\n\n this.methods = config.methods\n this.currency = { active: 'USD', base: 'USD', rate: 1, ...config.currency }\n this.locale = config.locale || 'en-US'\n this.market = config.market || null\n\n this.pageContext = {\n pageType: undefined,\n product: null,\n collection: null\n }\n }\n\n /**\n * Set customer access token for authenticated requests\n */\n setCustomerAccessToken (token: string | null): void {\n this.customerAccessToken = token\n }\n\n /**\n * Fetch product by handle from Storefront API\n */\n async fetchProduct (handle: string): Promise<ProductData> {\n const data = await this.client.query<{ product: Product }>(GET_PRODUCT_BY_HANDLE, { handle })\n\n if (!data.product) {\n throw new Error(`Product not found: ${handle}`)\n }\n\n return this.toProductData(data.product)\n }\n\n /**\n * Fetch product collections metadata\n */\n async fetchProductCollections (handle: string, productId: number): Promise<number[]> {\n let data\n if (productId) {\n data = await this.client.query<{ product: Product }>(GET_PRODUCT_BY_ID, { id: `gid://shopify/Product/${productId}` })\n } else if (handle) {\n data = await this.client.query<{ product: Product }>(GET_PRODUCT_BY_HANDLE, { handle })\n }\n\n if (!data || !data.product) {\n throw new Error(`Product not found: ${productId}`)\n }\n\n return data.product.collections.nodes.map(c => toId(c.id))\n }\n\n /**\n * Fetch product recommendations\n */\n async fetchRecommendations (productId: number, intent: string): Promise<{ products: ProductData[], intent: string }> {\n const data = await this.client.query<{ productRecommendations: Product[] }>(GET_PRODUCT_RECOMMENDATIONS, { productId: `gid://shopify/Product/${productId}`, intent })\n\n return {\n intent,\n products: data.productRecommendations.map(p => this.toProductData(p)) || []\n }\n }\n\n /**\n * Build product URL path\n */\n buildProductPath (product: { handle: string }): string {\n if (typeof this.methods?.builtProductPath !== 'function') return `/products/${product.handle}`\n\n return this.methods.builtProductPath(product)\n }\n\n /**\n * Convert currency amount\n */\n convertToBaseCurrency (amount: number): number {\n return this.currency.rate / amount\n }\n\n /**\n * Convert currency amount\n */\n convertFromBaseCurrency (amount: number): number {\n return this.currency.rate * amount\n }\n\n /**\n * Format money according to shop's format\n */\n formatMoney (amount: number, includeDecimals: boolean = true): string {\n if (typeof this.methods?.formatMoney !== 'function') return new Intl.NumberFormat(this.locale, {\n style: 'currency',\n currency: this.currency.active,\n maximumFractionDigits: includeDecimals ? undefined : 0\n }).format(amount / 100)\n\n return this.methods.formatMoney(amount, includeDecimals)\n }\n\n /**\n * Fetch customer data from Storefront API\n * Requires customer access token to be set\n */\n async getCustomer (): Promise<Customer | null> {\n if (!this.customerAccessToken) {\n return null\n }\n\n try {\n const data = await this.client.query<{ customer: Customer }>(GET_CUSTOMER, { customerAccessToken: this.customerAccessToken })\n\n return data.customer || null\n } catch (error) {\n console.error('Error fetching customer:', error)\n return null\n }\n }\n\n /**\n * Get current page context\n * Auto-detected from Remix router in Provider\n */\n getPageContext (): PageContext {\n return this.pageContext\n }\n\n setPageContext (context: Partial<PageContext>) {\n if (context.product) {\n context.product.id = toId(String(context.product.id))\n }\n if (context.collection) {\n context.collection.id = toId(String(context.collection.id))\n }\n this.pageContext = context\n }\n\n getVisitorId (): string | null {\n return null\n }\n\n /**\n * Get current market information\n */\n getMarket (): string | null {\n return this.market\n }\n\n /**\n * Get currency conversion rate\n * Note: Stub implementation\n */\n getCurrencyRate (): number {\n return this.currency.rate\n }\n\n /**\n * Transform Hydrogen Product to snippet-manager ProductData format\n */\n toProductData (product: Product): ProductData {\n return {\n id: toId(product.id),\n handle: product.handle,\n title: product.title,\n available: product.availableForSale,\n requires_selling_plan: product.requiresSellingPlan,\n images: product.images.nodes.map(img => img.url),\n variants: product.variants.nodes.map(variant => ({\n id: toId(variant.id),\n title: variant.title,\n available: variant.availableForSale,\n price: Math.round(parseFloat(variant.price.amount) * 100), // Convert to cents\n compare_at_price: variant.compareAtPrice\n ? Math.round(parseFloat(variant.compareAtPrice.amount) * 100)\n : null,\n featured_image: variant.image ? { src: variant.image.url } : null,\n selling_plan_allocations: variant.sellingPlanAllocations?.edges?.map(edge => ({\n selling_plan_id: edge.node.sellingPlan.id\n })) || []\n }))\n }\n }\n}\n","/**\n * Shopify Storefront API GraphQL client\n */\n\nexport type StorefrontClientConfig = {\n storefrontAccessToken: string\n shopDomain: string\n apiVersion?: string\n}\n\nexport class StorefrontClient {\n private storefrontAccessToken: string\n\n private shopDomain: string\n\n private apiVersion: string\n\n private endpoint: string\n\n constructor (config: StorefrontClientConfig) {\n this.storefrontAccessToken = config.storefrontAccessToken\n this.shopDomain = config.shopDomain\n this.apiVersion = config.apiVersion || '2024-01'\n this.endpoint = `https://${this.shopDomain}/api/${this.apiVersion}/graphql.json`\n }\n\n /**\n * Execute a GraphQL query against the Storefront API\n */\n async query<T = any>(query: string, variables?: Record<string, any>): Promise<T> {\n try {\n const response = await fetch(this.endpoint, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Shopify-Storefront-Access-Token': this.storefrontAccessToken\n },\n body: JSON.stringify({\n query,\n variables\n })\n })\n\n if (!response.ok) {\n throw new Error(`Storefront API request failed: ${response.statusText}`)\n }\n\n const result = await response.json()\n\n if (result.errors) {\n throw new Error(`GraphQL errors: ${JSON.stringify(result.errors)}`)\n }\n\n return result.data as T\n } catch (error) {\n console.error('Storefront API error:', error)\n throw error\n }\n }\n\n /**\n * Execute a GraphQL mutation against the Storefront API\n */\n async mutate<T = any>(mutation: string, variables?: Record<string, any>): Promise<T> {\n return this.query<T>(mutation, variables)\n }\n}\n","import React, { createContext, useEffect, useMemo, useRef, ReactNode } from 'react'\nimport { useMatches, useRevalidator } from 'react-router'\nimport {\n PersonizelyConfigMethods,\n HydrogenConfig,\n CartAddProduct\n} from '../types'\nimport type { CartReturn } from '@shopify/hydrogen'\nimport { Cart } from '../classes/Cart'\nimport { Adapter } from '../classes/Adapter'\nimport { StorefrontClient } from '../utils/storefront-client'\n\ndeclare global {\n interface Window {\n __PLY_HYDROGEN_CONFIG__?: HydrogenConfig\n }\n}\n\nexport type PersonizelyContextType = {\n cart: Cart\n adapter: Adapter\n websiteApiKey: string\n triggerCartAdd: (product: CartAddProduct) => Promise<boolean>\n triggerCheckout: () => Promise<boolean>\n}\n\nexport const PersonizelyContext = createContext<PersonizelyContextType | null>(null)\n\nexport type PersonizelyProviderProps = {\n websiteApiKey: string\n storefrontAccessToken: string\n shopDomain: string\n apiVersion?: string\n scriptBaseUrl?: string\n locale?: string\n currency?: {\n rate: number\n active: string\n base: string\n }\n market?: string\n methods?: PersonizelyConfigMethods\n children: ReactNode\n /**\n * Optional: Customer access token for authenticated requests\n */\n customerAccessToken?: string | null\n}\n\nexport function PersonizelyProvider ({\n websiteApiKey,\n storefrontAccessToken,\n shopDomain,\n locale,\n currency,\n market,\n apiVersion,\n scriptBaseUrl,\n methods,\n children,\n customerAccessToken\n}: PersonizelyProviderProps) {\n const matches = useMatches()\n const rootMatch = matches.find(m => m.id === 'root')\n const localCart = (rootMatch?.loaderData as any)?.cart as Promise<CartReturn>\n const revalidator = useRevalidator()\n\n const storefrontClient = useMemo(() => {\n return new StorefrontClient({\n storefrontAccessToken,\n shopDomain,\n apiVersion\n })\n }, [storefrontAccessToken, shopDomain, apiVersion])\n\n const adapter = useMemo(() => {\n const adapterInstance = new Adapter({\n locale,\n currency,\n market,\n methods\n }, storefrontClient)\n\n if (customerAccessToken) {\n adapterInstance.setCustomerAccessToken(customerAccessToken)\n }\n\n return adapterInstance\n }, [])\n\n const cart = useMemo(() => new Cart(localCart, storefrontClient, revalidator.revalidate), [])\n\n // Update cart data when it changes from the loader\n const prevCartDataRef = useRef<CartReturn | null>(null)\n useEffect(() => {\n localCart.then((data) => {\n if (data && data !== prevCartDataRef.current) {\n cart.updateCartData(data)\n cart.notifyListeners()\n prevCartDataRef.current = data\n }\n })\n }, [localCart, cart])\n\n const cartAddCallbacksRef = useRef<Array<(product: CartAddProduct) => Promise<boolean>>>([])\n const checkoutCallbacksRef = useRef<Array<() => Promise<boolean>>>([])\n\n // Set up window.__PLY_HYDROGEN_CONFIG__ and load Personizely script\n useEffect(() => {\n if (typeof window === 'undefined') {\n return\n }\n\n window.__PLY_HYDROGEN_CONFIG__ = {\n cart,\n adapter,\n onCartAdd: (callback) => {\n cartAddCallbacksRef.current.push(callback)\n\n return () => {\n const index = cartAddCallbacksRef.current.indexOf(callback)\n if (index > -1) {\n cartAddCallbacksRef.current.splice(index, 1)\n }\n }\n },\n onCheckout: (callback) => {\n checkoutCallbacksRef.current.push(callback)\n\n return () => {\n const index = checkoutCallbacksRef.current.indexOf(callback)\n if (index > -1) {\n checkoutCallbacksRef.current.splice(index, 1)\n }\n }\n }\n }\n\n const script = document.createElement('script')\n const baseUrl = scriptBaseUrl || 'https://static.personizely.net'\n script.src = `${baseUrl}/${websiteApiKey}.js`\n document.head.appendChild(script)\n\n return () => {\n delete window.__PLY_HYDROGEN_CONFIG__\n if (script) {\n script.remove()\n }\n }\n }, [])\n\n const contextValue = useMemo(() => ({\n cart,\n adapter,\n websiteApiKey,\n triggerCartAdd: async (product: CartAddProduct): Promise<boolean> => {\n let shown = false\n for (const callback of cartAddCallbacksRef.current) {\n try {\n const result = await callback(product)\n if (result) {\n shown = true\n }\n } catch (error) {\n console.error('Cart add callback error:', error)\n }\n }\n return shown\n },\n triggerCheckout: async (): Promise<boolean> => {\n let shown = false\n for (const callback of checkoutCallbacksRef.current) {\n try {\n const result = await callback()\n if (result) {\n shown = true\n }\n } catch (error) {\n console.error('Checkout callback error:', error)\n }\n }\n return shown\n }\n }), [cart, adapter, websiteApiKey])\n\n return (\n <PersonizelyContext.Provider value={contextValue}>\n {children}\n </PersonizelyContext.Provider>\n )\n}\n","/**\n * usePersonizely - Access Personizely context\n */\n\nimport { useContext } from 'react'\nimport { PersonizelyContext, PersonizelyContextType } from '../components/PersonizelyProvider'\n\n/**\n * Hook to access Personizely context\n * Provides access to cart, adapter, and configuration\n *\n * @returns PersonizelyContextType\n * @throws Error if used outside PersonizelyProvider\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const { cart, adapter } = usePersonizely()\n * // Use cart and adapter...\n * }\n * ```\n */\nexport function usePersonizely (): PersonizelyContextType {\n const context = useContext(PersonizelyContext)\n\n if (!context) {\n throw new Error('usePersonizely must be used within a PersonizelyProvider. ' +\n 'Make sure your component is wrapped with <PersonizelyProvider>.')\n }\n\n return context\n}\n","/**\n * useCartAdd - Hook to trigger Personizely cart add widgets\n */\n\nimport { useCallback } from 'react'\nimport type { CartAddProduct } from '../types'\nimport { usePersonizely } from './usePersonizely'\nimport { toId } from '../utils/id'\n\n/**\n * Hook to trigger Personizely cart add event\n * Call this when a product is being added to cart to show relevant widgets\n *\n * @returns Function to trigger cart add event\n *\n * @example\n * ```tsx\n * function ProductForm({ product, selectedVariant }) {\n * const triggerCartAdd = useCartAdd()\n *\n * const handleAddToCart = async () => {\n * const widgetShown = await triggerCartAdd({\n * id: product.id,\n * variantId: selectedVariant.id,\n * price: parseFloat(selectedVariant.price.amount),\n * quantity: 1,\n * handle: product.handle\n * })\n *\n * if (!widgetShown) {\n * await cart.linesAdd([{\n * merchandiseId: selectedVariant.id,\n * quantity: 1\n * }])\n * }\n * }\n *\n * return <button onClick={handleAddToCart}>Add to Cart</button>\n * }\n * ```\n */\nexport function useCartAdd () {\n const personizely = usePersonizely()\n\n return useCallback(async (product: CartAddProduct): Promise<boolean> => {\n if (typeof window === 'undefined') {\n return false\n }\n\n return await personizely.triggerCartAdd({\n ...product,\n id: toId(String(product.id)),\n variantId: toId(String(product.variantId)),\n price: Number(product.price) * 100\n })\n }, [personizely])\n}\n","/**\n * useCheckout - Hook to trigger Personizely checkout widgets\n */\n\nimport { useCallback } from 'react'\nimport { usePersonizely } from './usePersonizely'\n\n/**\n * Hook to trigger Personizely checkout event\n * Call this when proceeding to checkout to show relevant widgets\n *\n * @returns Function to trigger checkout event\n *\n * @example\n * ```tsx\n * function CheckoutButton() {\n * const triggerCheckout = useCheckout()\n *\n * const handleCheckout = async () => {\n * const widgetShown = await triggerCheckout()\n *\n * if (!widgetShown) {\n * window.location.href = cart.checkoutUrl\n * }\n * }\n *\n * return <button onClick={handleCheckout}>Checkout</button>\n * }\n * ```\n */\nexport function useCheckout () {\n const personizely = usePersonizely()\n\n return useCallback(async (): Promise<boolean> => {\n if (typeof window === 'undefined') {\n return false\n }\n\n return await personizely.triggerCheckout()\n }, [personizely])\n}\n","import { usePersonizely } from './usePersonizely'\nimport { PageContext } from '../types'\n\nexport function usePageContext (context: Partial<PageContext>) {\n const personizely = usePersonizely()\n\n personizely.adapter.setPageContext(context)\n}\n"],"mappings":"gLAUA,SAAgB,EAAY,EAA6B,CACvD,GAAI,OAAO,SAAa,IACtB,OAAO,KAGT,IAAM,EAAS,EAAO,IAChB,EAAU,SAAS,OAAO,MAAM,IAAI,CAE1C,IAAK,IAAI,EAAI,EAAG,EAAI,EAAQ,OAAQ,IAAK,CACvC,IAAI,EAAS,EAAQ,GACrB,KAAO,EAAO,OAAO,EAAE,GAAK,KAC1B,EAAS,EAAO,UAAU,EAAG,EAAO,OAAO,CAE7C,GAAI,EAAO,QAAQ,EAAO,GAAK,EAC7B,OAAO,EAAO,UAAU,EAAO,OAAQ,EAAO,OAAO,CAIzD,OAAO,KAUT,SAAgB,EAAc,EAC5B,EACA,EACA,EAAe,IAAW,CAC1B,GAAI,OAAO,SAAa,IACtB,OAGF,IAAI,EAAU,GACd,GAAI,EAAM,CACR,IAAM,EAAO,IAAI,KACjB,EAAK,QAAQ,EAAK,SAAS,CAAI,EAAO,GAAK,GAAK,GAAK,IAAM,CAC3D,EAAU,aAAe,EAAK,aAAa,CAG7C,SAAS,O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M,KAAY,EAAoB,QACzC,GAAI,CACa,MAAM,EAAS,EAAQ,GAEpC,EAAQ,UAEH,EAAO,CACd,QAAQ,MAAM,2BAA4B,EAAM,CAGpD,OAAO,GAET,gBAAiB,SAA8B,CAC7C,IAAI,EAAQ,GACZ,IAAK,IAAM,KAAY,EAAqB,QAC1C,GAAI,CACa,MAAM,GAAU,GAE7B,EAAQ,UAEH,EAAO,CACd,QAAQ,MAAM,2BAA4B,EAAM,CAGpD,OAAO,GAEV,EAAG,CAAC,EAAM,EAAS,EAAc,CAAC,CAEnC,OACE,EAAA,cAAC,EAAmB,SAAA,CAAS,MAAO,EAAA,CACjC,EAC2B,CCtKlC,SAAgB,GAA0C,CACxD,IAAM,EAAU,EAAW,EAAmB,CAE9C,GAAI,CAAC,EACH,MAAU,MAAM,4HACoD,CAGtE,OAAO,ECWT,SAAgB,GAAc,CAC5B,IAAM,EAAc,GAAgB,CAEpC,OAAO,EAAY,KAAO,IACpB,OAAO,OAAW,IACb,GAGF,MAAM,EAAY,eAAe,CACtC,GAAG,EACH,GAAI,EAAK,OAAO,EAAQ,GAAG,CAAC,CAC5B,UAAW,EAAK,OAAO,EAAQ,UAAU,CAAC,CAC1C,MAAO,OAAO,EAAQ,MAAM,CAAG,IAChC,CAAC,CACD,CAAC,EAAY,CAAC,CCzBnB,SAAgB,GAAe,CAC7B,IAAM,EAAc,GAAgB,CAEpC,OAAO,EAAY,SACb,OAAO,OAAW,IACb,GAGF,MAAM,EAAY,iBAAiB,CACzC,CAAC,EAAY,CAAC,CCpCnB,SAAgB,EAAgB,EAA+B,CACzC,GAAgB,CAExB,QAAQ,eAAe,EAAQ"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@personizely/shopify-hydrogen",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Personizely adapter for Shopify Hydrogen headless storefronts - Simple React Provider integration",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
|
-
"module": "dist/index.
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
12
|
"require": "./dist/index.cjs"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
"url": "https://github.com/personizely/shopify-hydrogen.git"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
|
-
"build": "tsdown",
|
|
38
|
+
"build": "tsdown && npm run postbuild",
|
|
39
|
+
"postbuild": "cp dist/index.d.mts dist/index.d.ts",
|
|
39
40
|
"clean": "rm -rf dist",
|
|
40
41
|
"lint": "eslint src --ext .ts,.tsx",
|
|
41
42
|
"lint:fix": "eslint src --ext .ts,.tsx --fix",
|