@behindthescenes/cart 0.0.8 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,6 +12,7 @@ The BTS Cart SDK provides:
12
12
  - **Multiple checkout links** - Configure named checkout links and choose which one to use at checkout.
13
13
  - **Site-key protection** - Cart URL generation is validated by the BTS website cart API using the same public site key and verified-domain model as `@behindthescenes/analytics`.
14
14
  - **Availability validation** - The API validates checkout link status, products/access tiers, requested quantity, and discounts before returning a checkout URL.
15
+ - **Quantity** - The SDK only normalizes quantities to integers **≥ 1**. It does not cap counts to per-line inventory or API max; those rules apply on `checkout-url` only.
15
16
 
16
17
  ## Installation
17
18
 
@@ -70,7 +71,7 @@ const cart = createBTSCart({
70
71
 
71
72
  cart.addItem({
72
73
  id: "garnet",
73
- lineItemId: "2dd3b989-616e-4e2f-9c47-21e1288d3823",
74
+ accessTierId: "2dd3b989-616e-4e2f-9c47-21e1288d3823",
74
75
  checkoutLinkKey: "tickets",
75
76
  name: "Garnet",
76
77
  unitPrice: 395,
@@ -116,7 +117,11 @@ The SDK sends that cart payload to the BTS API for validation and receives a fin
116
117
  https://behindthescenes.com/c/<checkoutLinkId>?cart=<encoded-json>
117
118
  ```
118
119
 
119
- For dynamic checkout links with no saved checkout-link line items, BTS resolves valid line items from the checkout link space’s public products and access tiers. In that case, `lineItemId` is the product ID or access tier ID.
120
+ For dynamic checkout links, set **`accessTierId`** or **`productId`** to the BTS catalog UUID (recommended). The SDK sends that value as `lineItemId` on `checkout-url`, matching how BTS checkout and webhooks resolve lines.
121
+
122
+ When the link has no saved checkout-link line items, BTS synthesizes the catalog from the space’s public products and tiers — use the tier or product UUID, not a site-local slug in `id`.
123
+
124
+ You may still pass `lineItemId` alone (persisted `spaces_checkout_link_items.id`, or tier/product UUID). If both a slug and a catalog UUID are present, the SDK prefers `accessTierId` / `productId` for checkout.
120
125
 
121
126
  `discount` can be either the internal promo-code ID or the customer-facing promo code. The cart API resolves customer-facing codes to the internal IDs required by the BTS checkout page before returning the final URL.
122
127
 
@@ -1 +1 @@
1
- var P="https://api.bts.it.com/v2/website/cart",v="bts-cart",F="default",G=1;class w extends Error{code;status;constructor(C,r,f){super(r);this.name="BTSCartError",this.code=C,this.status=f}}function N(){try{return globalThis.window??null}catch{return null}}function $(){try{return N()?.localStorage}catch{return}}function U(C){return(C??P).replace(/\/$/,"")}function z(C){if(!Number.isFinite(C??1))return 1;return Math.min(99,Math.max(1,Math.floor(C??1)))}function J(C){return{items:C.map((r)=>({...r}))}}function Q(C){if(C.discountEligibleTierOrProductIds?.length)return[...new Set(C.discountEligibleTierOrProductIds.filter(Boolean))];return[...new Set([C.accessTierId,C.productId,C.lineItemId].filter((r)=>Boolean(r)))]}function M(C){let r=new Set;for(let f of C)for(let B of[f.lineItemId,f.accessTierId,f.productId])if(B)r.add(B);return C.map((f)=>{if(!f.discount)return f;let B=Q(f);if(B.length===0||!B.some((A)=>r.has(A))){let A={...f};return delete A.discount,delete A.discountEligibleTierOrProductIds,A}return f})}function q(C,r){let f=new Headers(C);if(!r)return f;return new Headers(r).forEach((B,A)=>f.set(A,B)),f}function H(C){let r=C.checkoutLinkId.trim();try{let f=r.includes("://")?r:r.startsWith("/")?`https://bts-cart.invalid${r}`:r,B=new URL(f),A=B.pathname.split("/").filter(Boolean),T=A.indexOf("c"),R=T>=0?A[T+1]:A.at(-1);if(R)return{checkoutLinkId:R,discountCode:C.discountCode??B.searchParams.get("discountCode")??void 0}}catch{}return{checkoutLinkId:r,discountCode:C.discountCode}}class I{siteKey;endpoint;debug;persist;storageKey;storage;checkoutLinks;defaultCheckoutLinkKey;requestHeaders;items=[];listeners=new Set;constructor(C){this.siteKey=C.siteKey,this.endpoint=U(C.endpoint),this.debug=C.debug??!1,this.persist=C.persist??!0,this.storageKey=C.storageKey??v,this.storage=C.storage??$(),this.checkoutLinks=C.checkoutLinks??{},this.defaultCheckoutLinkKey=C.defaultCheckoutLinkKey??Object.keys(this.checkoutLinks)[0]??F,this.requestHeaders=C.requestHeaders,this.rehydrate()}static init(C){return new I(C)}getItems(){return J(this.items).items}getState(){return J(this.items)}getItemCount(){return this.items.reduce((C,r)=>C+r.quantity,0)}getSubtotal(){return this.items.reduce((C,r)=>C+(r.fullPrice??r.unitPrice)*r.quantity,0)}getTotal(){return this.items.reduce((C,r)=>C+r.unitPrice*r.quantity,0)}subscribe(C){return this.listeners.add(C),C(this.getState()),()=>{this.listeners.delete(C)}}destroy(){this.listeners.clear()}rehydrate(){if(!this.persist||!this.storage)return;try{let C=this.storage.getItem(this.storageKey);if(!C)return;let r=JSON.parse(C),f=Array.isArray(r)?r:r.items;if(!Array.isArray(f))return;this.items=M(f.map((B)=>this.normalizeItem(B)).filter((B)=>Boolean(B))),this.emit()}catch(C){this.log("Failed to hydrate cart",C)}}addItem(C){let r=this.normalizeItem(C);if(!r)return;let f=this.items.find((B)=>B.id===r.id);if(f){this.setQuantity(f.id,f.quantity+r.quantity);return}this.items=[...this.items,r],this.commit()}removeItem(C){this.items=this.items.filter((r)=>r.id!==C),this.commit()}setQuantity(C,r){let f=Math.floor(r);this.items=f<=0?this.items.filter((B)=>B.id!==C):this.items.map((B)=>B.id===C?{...B,quantity:f}:B),this.commit()}increment(C,r=1){let f=this.items.find((B)=>B.id===C);if(f)this.setQuantity(C,f.quantity+Math.max(1,Math.floor(r)))}decrement(C,r=1){let f=this.items.find((B)=>B.id===C);if(f)this.setQuantity(C,f.quantity-Math.max(1,Math.floor(r)))}clear(){if(this.items=[],this.persist&&this.storage)try{this.storage.removeItem(this.storageKey)}catch(C){this.log("Failed to clear cart storage",C)}this.emit()}async resolveCheckoutUrl(C=this.defaultCheckoutLinkKey){let r=this.checkoutLinks[C];if(!r)throw new w("checkout_link_not_found",`Unknown checkout link key: ${C}`);let f=H(r),B=this.itemsForCheckout(C,r),A={siteKey:this.siteKey,checkoutLinkId:f.checkoutLinkId,mode:r.mode,...f.discountCode?{discountCode:f.discountCode}:{},...B.length>0?{items:B}:{}};return(await this.post("/checkout-url",A)).checkoutUrl}async checkout(C=this.defaultCheckoutLinkKey){let r=await this.resolveCheckoutUrl(C),f=N();if(f)f.location.assign(r);return r}itemsForCheckout(C,r){if(r.mode==="static")return[];let f=this.items.filter((B)=>B.checkoutLinkKey===C).map((B)=>({lineItemId:B.lineItemId,quantity:B.quantity,...B.discount?{discount:B.discount}:{}}));if(f.length===0)throw new w("cart_empty","Your cart is empty.");return f}normalizeItem(C){if(!C.id||!C.lineItemId||typeof C.unitPrice!=="number")return null;let r=typeof C.name==="string"&&C.name.trim().length>0?C.name.trim():"Item";return{...C,id:C.id,lineItemId:C.lineItemId,checkoutLinkKey:C.checkoutLinkKey??this.defaultCheckoutLinkKey,name:r,unitPrice:C.unitPrice,quantity:z(C.quantity)}}async post(C,r){let f=`${this.endpoint}${C}`,B=JSON.stringify(r),A={"Content-Type":"application/json"},T={body:r,bodyText:B,endpoint:this.endpoint,headers:A,path:C,siteKey:this.siteKey,url:f},R=typeof this.requestHeaders==="function"?await this.requestHeaders(T):this.requestHeaders,Y=q(A,R),W=await fetch(f,{method:"POST",headers:Y,body:B}),b=await W.json().catch(()=>null);if(!W.ok){let Z=typeof b?.code==="string"&&b.code.length>0?b.code:"request_failed",_=typeof b?.message==="string"&&b.message.length>0?b.message:"Cart request failed";throw new w(Z,_,W.status)}if(!b||typeof b!=="object"||b.ok!==!0||typeof b.checkoutUrl!=="string"||b.checkoutUrl.length===0)throw new w("request_failed","Cart response was invalid.",W.status);return b}commit(){if(this.items=M(this.items),this.persist&&this.storage)try{let C={version:G,items:this.items};this.storage.setItem(this.storageKey,JSON.stringify(C))}catch(C){this.log("Failed to persist cart",C)}this.emit()}emit(){let C=this.getState();for(let r of this.listeners)r(C)}log(...C){if(this.debug)console.log("[@behindthescenes/cart]",...C)}}function D(C){return I.init(C)}function O(C){return typeof C==="object"&&C!==null&&!Array.isArray(C)}function X(){try{return globalThis.window??null}catch{return null}}function V(C){let r=X();if(!r)return;let[f,B,A]=C;if(typeof f!=="string")return;if(f==="config"){if(!O(B))return;r.btsCart?.destroy?.(),r.btsCart=D(B);return}let T=r.btsCart;if(!T)return;if(f==="add"&&O(B)){T.addItem(B);return}if(f==="remove"&&typeof B==="string"){T.removeItem(B);return}if(f==="quantity"&&typeof B==="string"&&typeof A==="number"){T.setQuantity(B,A);return}if(f==="clear"){T.clear();return}if(f==="checkout")T.checkout(typeof B==="string"?B:void 0)}var S=X();if(S){let C=Array.isArray(S.btsCartDataLayer)?[...S.btsCartDataLayer]:[];S.btsCartDataLayer=Array.isArray(S.btsCartDataLayer)?S.btsCartDataLayer:[],S.BTSCart={BTSCart:I,createBTSCart:D},S.createBTSCart=D;for(let r of C)V(Array.from(r));S.btsCartCommand=(...r)=>{S.btsCartDataLayer?.push(r),V(r)}}export{D as createBTSCart,I as BTSCart};
1
+ var H="https://api.bts.it.com/v2/website/cart",Q="bts-cart",R="default",T=2;function z(){try{return globalThis.window??null}catch{return null}}function E(){try{return globalThis.localStorage??z()?.localStorage??null}catch{return null}}var x=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"],W=["fbclid","gclid","gbraid","wbraid","ttclid","li_fat_id","msclkid","_fbp","_fbc"];function v(B){if(!B)return{utm:{},clickIds:{}};try{let F=JSON.parse(B);if(!F||typeof F!=="object"||Array.isArray(F))return{utm:{},clickIds:{}};let G=F,J=G.utm&&typeof G.utm==="object"&&!Array.isArray(G.utm)?Object.fromEntries(Object.entries(G.utm).filter((X)=>typeof X[1]==="string"&&X[1].length>0)):{},Z=G.clickIds&&typeof G.clickIds==="object"&&!Array.isArray(G.clickIds)?Object.fromEntries(Object.entries(G.clickIds).filter((X)=>typeof X[1]==="string"&&X[1].length>0)):{};return{utm:J,clickIds:Z}}catch{return{utm:{},clickIds:{}}}}function C(B,F){let G=new URL(B);G.searchParams.set("bts_site",F);let J=E(),Z=J?.getItem("bts_analytics_jt")?.trim();if(Z)G.searchParams.set("bts_jt",Z);let{utm:X,clickIds:Y}=v(J?.getItem("bts_analytics_attr")??null);for(let V of x){let M=X[V];if(M)G.searchParams.set(V,M)}for(let V of W){let M=Y[V];if(M)G.searchParams.set(V,M)}return G.toString()}class $ extends Error{code;status;details;constructor(B,F,G,J){super(F);this.name="BTSCartError",this.code=B,this.status=G,this.details=J}}function K(){return E()??void 0}function b(B){return(B??H).replace(/\/$/,"")}function I(B){if(!Number.isFinite(B??1))return 1;return Math.max(1,Math.floor(B??1))}function P(B){return{items:B.map((F)=>({...F}))}}function _(B){let F=B?.trim();return F&&F.length>0?F:void 0}function f(B){return B.accessTierId??B.productId??B.lineItemId}function w(B){if(B.discountEligibleTierOrProductIds?.length)return[...new Set(B.discountEligibleTierOrProductIds.filter(Boolean))];return[...new Set([B.accessTierId,B.productId,B.lineItemId].filter((F)=>Boolean(F)))]}function U(B){let F=new Set;for(let G of B)for(let J of[G.lineItemId,G.accessTierId,G.productId])if(J)F.add(J);return B.map((G)=>{if(!G.discount)return G;let J=w(G);if(J.length===0||!J.some((Z)=>F.has(Z))){let Z={...G};return delete Z.discount,delete Z.discountEligibleTierOrProductIds,Z}return G})}function g(B,F){let G=new Headers(B);if(!F)return G;return new Headers(F).forEach((J,Z)=>G.set(Z,J)),G}function p(B){let F=B.checkoutLinkId.trim();try{let G=F.includes("://")?F:F.startsWith("/")?`https://bts-cart.invalid${F}`:F,J=new URL(G),Z=J.pathname.split("/").filter(Boolean),X=Z.indexOf("c"),Y=X>=0?Z[X+1]:Z.at(-1);if(Y)return{checkoutLinkId:Y,discountCode:B.discountCode??J.searchParams.get("discountCode")??void 0}}catch{}return{checkoutLinkId:F,discountCode:B.discountCode}}class D{siteKey;endpoint;debug;persist;storageKey;storage;checkoutLinks;defaultCheckoutLinkKey;requestHeaders;items=[];listeners=new Set;constructor(B){this.siteKey=B.siteKey,this.endpoint=b(B.endpoint),this.debug=B.debug??!1,this.persist=B.persist??!0,this.storageKey=B.storageKey??Q,this.storage=B.storage??K(),this.checkoutLinks=B.checkoutLinks??{},this.defaultCheckoutLinkKey=B.defaultCheckoutLinkKey??Object.keys(this.checkoutLinks)[0]??R,this.requestHeaders=B.requestHeaders,this.rehydrate()}static init(B){return new D(B)}getItems(){return P(this.items).items}getState(){return P(this.items)}getItemCount(){return this.items.reduce((B,F)=>B+F.quantity,0)}getSubtotal(){return this.items.reduce((B,F)=>B+(F.fullPrice??F.unitPrice)*F.quantity,0)}getTotal(){return this.items.reduce((B,F)=>B+F.unitPrice*F.quantity,0)}subscribe(B){return this.listeners.add(B),B(this.getState()),()=>{this.listeners.delete(B)}}destroy(){this.listeners.clear()}rehydrate(){if(!this.persist||!this.storage)return;try{let B=this.storage.getItem(this.storageKey);if(!B)return;let F=JSON.parse(B);if(Array.isArray(F)||F.version!==T){this.storage.removeItem(this.storageKey);return}let G=F.items;if(!Array.isArray(G))return;this.items=U(G.map((J)=>this.normalizeItem(J)).filter((J)=>Boolean(J))),this.emit()}catch(B){this.log("Failed to hydrate cart",B)}}addItem(B){let F=this.normalizeItem(B);if(!F)return;let G=this.items.find((J)=>J.id===F.id);if(G){this.setQuantity(G.id,G.quantity+F.quantity);return}this.items=[...this.items,F],this.commit()}removeItem(B){this.items=this.items.filter((F)=>F.id!==B),this.commit()}setQuantity(B,F){let G=Math.floor(F);this.items=G<=0?this.items.filter((J)=>J.id!==B):this.items.map((J)=>J.id===B?{...J,quantity:G}:J),this.commit()}increment(B,F=1){let G=this.items.find((J)=>J.id===B);if(G)this.setQuantity(B,G.quantity+Math.max(1,Math.floor(F)))}decrement(B,F=1){let G=this.items.find((J)=>J.id===B);if(G)this.setQuantity(B,G.quantity-Math.max(1,Math.floor(F)))}clear(){if(this.items=[],this.persist&&this.storage)try{this.storage.removeItem(this.storageKey)}catch(B){this.log("Failed to clear cart storage",B)}this.emit()}async resolveCheckoutUrl(B=this.defaultCheckoutLinkKey){let F=this.checkoutLinks[B];if(!F)throw new $("checkout_link_not_found",`Unknown checkout link key: ${B}`);let G=p(F),J=this.itemsForCheckout(B,F),Z={siteKey:this.siteKey,checkoutLinkId:G.checkoutLinkId,mode:F.mode,...G.discountCode?{discountCode:G.discountCode}:{},...J.length>0?{items:J}:{}};try{let X=await this.post("/checkout-url",Z);return C(X.checkoutUrl,this.siteKey)}catch(X){if(X instanceof $)if(X.code==="discounts_invalid")throw new $(X.code,X.message,X.status,X.details);else throw new $(X.code,X.message,X.status);throw new $("request_failed","Failed to resolve checkout URL.",void 0,void 0)}}async checkout(B=this.defaultCheckoutLinkKey){try{let F=await this.resolveCheckoutUrl(B),G=z();if(G)G.location.assign(F);return F}catch(F){if(F instanceof $)if(F.code==="discounts_invalid"){for(let G of F.details??[]){if(G.lineItemId)this.items=this.items.map((J)=>J.lineItemId===G.lineItemId?{...J,discount:void 0}:J);if(G.productId)this.items=this.items.map((J)=>J.productId===G.productId?{...J,discount:void 0}:J);if(G.accessTierId)this.items=this.items.map((J)=>J.accessTierId===G.accessTierId?{...J,discount:void 0}:J)}throw this.commit(),new $(F.code,F.message,F.status,F.details)}else throw new $(F.code,F.message,F.status);throw new $("request_failed","Failed to resolve checkout URL.",void 0,void 0)}}itemsForCheckout(B,F){if(F.mode==="static")return[];let G=this.items.filter((J)=>J.checkoutLinkKey===B).map((J)=>({lineItemId:f(J),quantity:J.quantity,...J.discount?{discount:J.discount}:{}}));if(G.length===0)throw new $("cart_empty","Your cart is empty.");return G}normalizeItem(B){let F=_(B.accessTierId),G=_(B.productId),J=_(B.lineItemId)??F??G;if(!B.id||!J||typeof B.unitPrice!=="number")return null;let Z=typeof B.name==="string"&&B.name.trim().length>0?B.name.trim():"Item";return{...B,id:B.id,lineItemId:J,...F?{accessTierId:F}:{},...G?{productId:G}:{},checkoutLinkKey:B.checkoutLinkKey??this.defaultCheckoutLinkKey,name:Z,unitPrice:B.unitPrice,quantity:I(B.quantity)}}async post(B,F){let G=`${this.endpoint}${B}`,J=JSON.stringify(F),Z={"Content-Type":"application/json"},X={body:F,bodyText:J,endpoint:this.endpoint,headers:Z,path:B,siteKey:this.siteKey,url:G},Y=typeof this.requestHeaders==="function"?await this.requestHeaders(X):this.requestHeaders,V=g(Z,Y),M=await fetch(G,{method:"POST",headers:V,body:J}),A=await M.json().catch(()=>null);if(!M.ok){let j=typeof A?.code==="string"&&A.code.length>0?A.code:"request_failed",L=typeof A?.message==="string"&&A.message.length>0?A.message:"Cart request failed";throw new $(j,L,M.status)}if(!A||typeof A!=="object"||A.ok!==!0||typeof A.checkoutUrl!=="string"||A.checkoutUrl.length===0)throw new $("request_failed","Cart response was invalid.",M.status);return A}commit(){if(this.items=U(this.items),this.persist&&this.storage)try{let B={version:T,items:this.items};this.storage.setItem(this.storageKey,JSON.stringify(B))}catch(B){this.log("Failed to persist cart",B)}this.emit()}emit(){let B=this.getState();for(let F of this.listeners)F(B)}log(...B){if(this.debug)console.log("[@behindthescenes/cart]",...B)}}function O(B){return D.init(B)}function q(B){return typeof B==="object"&&B!==null&&!Array.isArray(B)}function S(B){let F=z();if(!F)return;let[G,J,Z]=B;if(typeof G!=="string")return;if(G==="config"){if(!q(J))return;F.btsCart?.destroy?.(),F.btsCart=O(J);return}let X=F.btsCart;if(!X)return;if(G==="add"&&q(J)){X.addItem(J);return}if(G==="remove"&&typeof J==="string"){X.removeItem(J);return}if(G==="quantity"&&typeof J==="string"&&typeof Z==="number"){X.setQuantity(J,Z);return}if(G==="clear"){X.clear();return}if(G==="checkout")X.checkout(typeof J==="string"?J:void 0)}var N=z();if(N){let B=Array.isArray(N.btsCartDataLayer)?[...N.btsCartDataLayer]:[];N.btsCartDataLayer=Array.isArray(N.btsCartDataLayer)?N.btsCartDataLayer:[],N.BTSCart={BTSCart:D,createBTSCart:O},N.createBTSCart=O;for(let F of B)S(Array.from(F));N.btsCartCommand=(...F)=>{N.btsCartDataLayer?.push(F),S(F)}}export{O as createBTSCart,D as BTSCart};
package/dist/cjs/index.js CHANGED
@@ -1 +1 @@
1
- var{defineProperty:Z,getOwnPropertyNames:q,getOwnPropertyDescriptor:B}=Object,I=Object.prototype.hasOwnProperty;function b(A){return this[A]}var T=(A)=>{var F=(_??=new WeakMap).get(A),G;if(F)return F;if(F=Z({},"__esModule",{value:!0}),A&&typeof A==="object"||typeof A==="function"){for(var J of q(A))if(!I.call(F,J))Z(F,J,{get:b.bind(A,J),enumerable:!(G=B(A,J))||G.enumerable})}return _.set(A,F),F},_;var j=(A)=>A;function C(A,F){this[A]=j.bind(null,F)}var K=(A,F)=>{for(var G in F)Z(A,G,{get:F[G],enumerable:!0,configurable:!0,set:C.bind(F,G)})};var k={};K(k,{createBTSCart:()=>h,BTSCartError:()=>O,BTSCart:()=>Y});module.exports=T(k);var $="https://api.bts.it.com/v2/website/cart",R="bts-cart",z="default",W=1;class O extends Error{code;status;constructor(A,F,G){super(F);this.name="BTSCartError",this.code=A,this.status=G}}function U(){try{return globalThis.window??null}catch{return null}}function S(){try{return U()?.localStorage}catch{return}}function w(A){return(A??$).replace(/\/$/,"")}function L(A){if(!Number.isFinite(A??1))return 1;return Math.min(99,Math.max(1,Math.floor(A??1)))}function v(A){return{items:A.map((F)=>({...F}))}}function x(A){if(A.discountEligibleTierOrProductIds?.length)return[...new Set(A.discountEligibleTierOrProductIds.filter(Boolean))];return[...new Set([A.accessTierId,A.productId,A.lineItemId].filter((F)=>Boolean(F)))]}function Q(A){let F=new Set;for(let G of A)for(let J of[G.lineItemId,G.accessTierId,G.productId])if(J)F.add(J);return A.map((G)=>{if(!G.discount)return G;let J=x(G);if(J.length===0||!J.some((M)=>F.has(M))){let M={...G};return delete M.discount,delete M.discountEligibleTierOrProductIds,M}return G})}function f(A,F){let G=new Headers(A);if(!F)return G;return new Headers(F).forEach((J,M)=>G.set(M,J)),G}function g(A){let F=A.checkoutLinkId.trim();try{let G=F.includes("://")?F:F.startsWith("/")?`https://bts-cart.invalid${F}`:F,J=new URL(G),M=J.pathname.split("/").filter(Boolean),P=M.indexOf("c"),V=P>=0?M[P+1]:M.at(-1);if(V)return{checkoutLinkId:V,discountCode:A.discountCode??J.searchParams.get("discountCode")??void 0}}catch{}return{checkoutLinkId:F,discountCode:A.discountCode}}class Y{siteKey;endpoint;debug;persist;storageKey;storage;checkoutLinks;defaultCheckoutLinkKey;requestHeaders;items=[];listeners=new Set;constructor(A){this.siteKey=A.siteKey,this.endpoint=w(A.endpoint),this.debug=A.debug??!1,this.persist=A.persist??!0,this.storageKey=A.storageKey??R,this.storage=A.storage??S(),this.checkoutLinks=A.checkoutLinks??{},this.defaultCheckoutLinkKey=A.defaultCheckoutLinkKey??Object.keys(this.checkoutLinks)[0]??z,this.requestHeaders=A.requestHeaders,this.rehydrate()}static init(A){return new Y(A)}getItems(){return v(this.items).items}getState(){return v(this.items)}getItemCount(){return this.items.reduce((A,F)=>A+F.quantity,0)}getSubtotal(){return this.items.reduce((A,F)=>A+(F.fullPrice??F.unitPrice)*F.quantity,0)}getTotal(){return this.items.reduce((A,F)=>A+F.unitPrice*F.quantity,0)}subscribe(A){return this.listeners.add(A),A(this.getState()),()=>{this.listeners.delete(A)}}destroy(){this.listeners.clear()}rehydrate(){if(!this.persist||!this.storage)return;try{let A=this.storage.getItem(this.storageKey);if(!A)return;let F=JSON.parse(A),G=Array.isArray(F)?F:F.items;if(!Array.isArray(G))return;this.items=Q(G.map((J)=>this.normalizeItem(J)).filter((J)=>Boolean(J))),this.emit()}catch(A){this.log("Failed to hydrate cart",A)}}addItem(A){let F=this.normalizeItem(A);if(!F)return;let G=this.items.find((J)=>J.id===F.id);if(G){this.setQuantity(G.id,G.quantity+F.quantity);return}this.items=[...this.items,F],this.commit()}removeItem(A){this.items=this.items.filter((F)=>F.id!==A),this.commit()}setQuantity(A,F){let G=Math.floor(F);this.items=G<=0?this.items.filter((J)=>J.id!==A):this.items.map((J)=>J.id===A?{...J,quantity:G}:J),this.commit()}increment(A,F=1){let G=this.items.find((J)=>J.id===A);if(G)this.setQuantity(A,G.quantity+Math.max(1,Math.floor(F)))}decrement(A,F=1){let G=this.items.find((J)=>J.id===A);if(G)this.setQuantity(A,G.quantity-Math.max(1,Math.floor(F)))}clear(){if(this.items=[],this.persist&&this.storage)try{this.storage.removeItem(this.storageKey)}catch(A){this.log("Failed to clear cart storage",A)}this.emit()}async resolveCheckoutUrl(A=this.defaultCheckoutLinkKey){let F=this.checkoutLinks[A];if(!F)throw new O("checkout_link_not_found",`Unknown checkout link key: ${A}`);let G=g(F),J=this.itemsForCheckout(A,F),M={siteKey:this.siteKey,checkoutLinkId:G.checkoutLinkId,mode:F.mode,...G.discountCode?{discountCode:G.discountCode}:{},...J.length>0?{items:J}:{}};return(await this.post("/checkout-url",M)).checkoutUrl}async checkout(A=this.defaultCheckoutLinkKey){let F=await this.resolveCheckoutUrl(A),G=U();if(G)G.location.assign(F);return F}itemsForCheckout(A,F){if(F.mode==="static")return[];let G=this.items.filter((J)=>J.checkoutLinkKey===A).map((J)=>({lineItemId:J.lineItemId,quantity:J.quantity,...J.discount?{discount:J.discount}:{}}));if(G.length===0)throw new O("cart_empty","Your cart is empty.");return G}normalizeItem(A){if(!A.id||!A.lineItemId||typeof A.unitPrice!=="number")return null;let F=typeof A.name==="string"&&A.name.trim().length>0?A.name.trim():"Item";return{...A,id:A.id,lineItemId:A.lineItemId,checkoutLinkKey:A.checkoutLinkKey??this.defaultCheckoutLinkKey,name:F,unitPrice:A.unitPrice,quantity:L(A.quantity)}}async post(A,F){let G=`${this.endpoint}${A}`,J=JSON.stringify(F),M={"Content-Type":"application/json"},P={body:F,bodyText:J,endpoint:this.endpoint,headers:M,path:A,siteKey:this.siteKey,url:G},V=typeof this.requestHeaders==="function"?await this.requestHeaders(P):this.requestHeaders,H=f(M,V),X=await fetch(G,{method:"POST",headers:H,body:J}),N=await X.json().catch(()=>null);if(!X.ok){let D=typeof N?.code==="string"&&N.code.length>0?N.code:"request_failed",E=typeof N?.message==="string"&&N.message.length>0?N.message:"Cart request failed";throw new O(D,E,X.status)}if(!N||typeof N!=="object"||N.ok!==!0||typeof N.checkoutUrl!=="string"||N.checkoutUrl.length===0)throw new O("request_failed","Cart response was invalid.",X.status);return N}commit(){if(this.items=Q(this.items),this.persist&&this.storage)try{let A={version:W,items:this.items};this.storage.setItem(this.storageKey,JSON.stringify(A))}catch(A){this.log("Failed to persist cart",A)}this.emit()}emit(){let A=this.getState();for(let F of this.listeners)F(A)}log(...A){if(this.debug)console.log("[@behindthescenes/cart]",...A)}}function h(A){return Y.init(A)}
1
+ var{defineProperty:z,getOwnPropertyNames:S,getOwnPropertyDescriptor:b}=Object,j=Object.prototype.hasOwnProperty;function x(B){return this[B]}var K=(B)=>{var F=(_??=new WeakMap).get(B),G;if(F)return F;if(F=z({},"__esModule",{value:!0}),B&&typeof B==="object"||typeof B==="function"){for(var J of S(B))if(!j.call(F,J))z(F,J,{get:x.bind(B,J),enumerable:!(G=b(B,J))||G.enumerable})}return _.set(B,F),F},_;var L=(B)=>B;function w(B,F){this[B]=L.bind(null,F)}var f=(B,F)=>{for(var G in F)z(B,G,{get:F[G],enumerable:!0,configurable:!0,set:w.bind(F,G)})};var a={};f(a,{resolveLineItemIdForCheckout:()=>C,createBTSCart:()=>u,BTSCartError:()=>$,BTSCart:()=>Y});module.exports=K(a);var D="https://api.bts.it.com/v2/website/cart",H="bts-cart",Q="default",A=2;function O(){try{return globalThis.window??null}catch{return null}}function V(){try{return globalThis.localStorage??O()?.localStorage??null}catch{return null}}var I=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"],g=["fbclid","gclid","gbraid","wbraid","ttclid","li_fat_id","msclkid","_fbp","_fbc"];function h(B){if(!B)return{utm:{},clickIds:{}};try{let F=JSON.parse(B);if(!F||typeof F!=="object"||Array.isArray(F))return{utm:{},clickIds:{}};let G=F,J=G.utm&&typeof G.utm==="object"&&!Array.isArray(G.utm)?Object.fromEntries(Object.entries(G.utm).filter((X)=>typeof X[1]==="string"&&X[1].length>0)):{},Z=G.clickIds&&typeof G.clickIds==="object"&&!Array.isArray(G.clickIds)?Object.fromEntries(Object.entries(G.clickIds).filter((X)=>typeof X[1]==="string"&&X[1].length>0)):{};return{utm:J,clickIds:Z}}catch{return{utm:{},clickIds:{}}}}function U(B,F){let G=new URL(B);G.searchParams.set("bts_site",F);let J=V(),Z=J?.getItem("bts_analytics_jt")?.trim();if(Z)G.searchParams.set("bts_jt",Z);let{utm:X,clickIds:R}=h(J?.getItem("bts_analytics_attr")??null);for(let N of I){let M=X[N];if(M)G.searchParams.set(N,M)}for(let N of g){let M=R[N];if(M)G.searchParams.set(N,M)}return G.toString()}class $ extends Error{code;status;details;constructor(B,F,G,J){super(F);this.name="BTSCartError",this.code=B,this.status=G,this.details=J}}function p(){return V()??void 0}function y(B){return(B??D).replace(/\/$/,"")}function k(B){if(!Number.isFinite(B??1))return 1;return Math.max(1,Math.floor(B??1))}function T(B){return{items:B.map((F)=>({...F}))}}function P(B){let F=B?.trim();return F&&F.length>0?F:void 0}function C(B){return B.accessTierId??B.productId??B.lineItemId}function l(B){if(B.discountEligibleTierOrProductIds?.length)return[...new Set(B.discountEligibleTierOrProductIds.filter(Boolean))];return[...new Set([B.accessTierId,B.productId,B.lineItemId].filter((F)=>Boolean(F)))]}function W(B){let F=new Set;for(let G of B)for(let J of[G.lineItemId,G.accessTierId,G.productId])if(J)F.add(J);return B.map((G)=>{if(!G.discount)return G;let J=l(G);if(J.length===0||!J.some((Z)=>F.has(Z))){let Z={...G};return delete Z.discount,delete Z.discountEligibleTierOrProductIds,Z}return G})}function c(B,F){let G=new Headers(B);if(!F)return G;return new Headers(F).forEach((J,Z)=>G.set(Z,J)),G}function d(B){let F=B.checkoutLinkId.trim();try{let G=F.includes("://")?F:F.startsWith("/")?`https://bts-cart.invalid${F}`:F,J=new URL(G),Z=J.pathname.split("/").filter(Boolean),X=Z.indexOf("c"),R=X>=0?Z[X+1]:Z.at(-1);if(R)return{checkoutLinkId:R,discountCode:B.discountCode??J.searchParams.get("discountCode")??void 0}}catch{}return{checkoutLinkId:F,discountCode:B.discountCode}}class Y{siteKey;endpoint;debug;persist;storageKey;storage;checkoutLinks;defaultCheckoutLinkKey;requestHeaders;items=[];listeners=new Set;constructor(B){this.siteKey=B.siteKey,this.endpoint=y(B.endpoint),this.debug=B.debug??!1,this.persist=B.persist??!0,this.storageKey=B.storageKey??H,this.storage=B.storage??p(),this.checkoutLinks=B.checkoutLinks??{},this.defaultCheckoutLinkKey=B.defaultCheckoutLinkKey??Object.keys(this.checkoutLinks)[0]??Q,this.requestHeaders=B.requestHeaders,this.rehydrate()}static init(B){return new Y(B)}getItems(){return T(this.items).items}getState(){return T(this.items)}getItemCount(){return this.items.reduce((B,F)=>B+F.quantity,0)}getSubtotal(){return this.items.reduce((B,F)=>B+(F.fullPrice??F.unitPrice)*F.quantity,0)}getTotal(){return this.items.reduce((B,F)=>B+F.unitPrice*F.quantity,0)}subscribe(B){return this.listeners.add(B),B(this.getState()),()=>{this.listeners.delete(B)}}destroy(){this.listeners.clear()}rehydrate(){if(!this.persist||!this.storage)return;try{let B=this.storage.getItem(this.storageKey);if(!B)return;let F=JSON.parse(B);if(Array.isArray(F)||F.version!==A){this.storage.removeItem(this.storageKey);return}let G=F.items;if(!Array.isArray(G))return;this.items=W(G.map((J)=>this.normalizeItem(J)).filter((J)=>Boolean(J))),this.emit()}catch(B){this.log("Failed to hydrate cart",B)}}addItem(B){let F=this.normalizeItem(B);if(!F)return;let G=this.items.find((J)=>J.id===F.id);if(G){this.setQuantity(G.id,G.quantity+F.quantity);return}this.items=[...this.items,F],this.commit()}removeItem(B){this.items=this.items.filter((F)=>F.id!==B),this.commit()}setQuantity(B,F){let G=Math.floor(F);this.items=G<=0?this.items.filter((J)=>J.id!==B):this.items.map((J)=>J.id===B?{...J,quantity:G}:J),this.commit()}increment(B,F=1){let G=this.items.find((J)=>J.id===B);if(G)this.setQuantity(B,G.quantity+Math.max(1,Math.floor(F)))}decrement(B,F=1){let G=this.items.find((J)=>J.id===B);if(G)this.setQuantity(B,G.quantity-Math.max(1,Math.floor(F)))}clear(){if(this.items=[],this.persist&&this.storage)try{this.storage.removeItem(this.storageKey)}catch(B){this.log("Failed to clear cart storage",B)}this.emit()}async resolveCheckoutUrl(B=this.defaultCheckoutLinkKey){let F=this.checkoutLinks[B];if(!F)throw new $("checkout_link_not_found",`Unknown checkout link key: ${B}`);let G=d(F),J=this.itemsForCheckout(B,F),Z={siteKey:this.siteKey,checkoutLinkId:G.checkoutLinkId,mode:F.mode,...G.discountCode?{discountCode:G.discountCode}:{},...J.length>0?{items:J}:{}};try{let X=await this.post("/checkout-url",Z);return U(X.checkoutUrl,this.siteKey)}catch(X){if(X instanceof $)if(X.code==="discounts_invalid")throw new $(X.code,X.message,X.status,X.details);else throw new $(X.code,X.message,X.status);throw new $("request_failed","Failed to resolve checkout URL.",void 0,void 0)}}async checkout(B=this.defaultCheckoutLinkKey){try{let F=await this.resolveCheckoutUrl(B),G=O();if(G)G.location.assign(F);return F}catch(F){if(F instanceof $)if(F.code==="discounts_invalid"){for(let G of F.details??[]){if(G.lineItemId)this.items=this.items.map((J)=>J.lineItemId===G.lineItemId?{...J,discount:void 0}:J);if(G.productId)this.items=this.items.map((J)=>J.productId===G.productId?{...J,discount:void 0}:J);if(G.accessTierId)this.items=this.items.map((J)=>J.accessTierId===G.accessTierId?{...J,discount:void 0}:J)}throw this.commit(),new $(F.code,F.message,F.status,F.details)}else throw new $(F.code,F.message,F.status);throw new $("request_failed","Failed to resolve checkout URL.",void 0,void 0)}}itemsForCheckout(B,F){if(F.mode==="static")return[];let G=this.items.filter((J)=>J.checkoutLinkKey===B).map((J)=>({lineItemId:C(J),quantity:J.quantity,...J.discount?{discount:J.discount}:{}}));if(G.length===0)throw new $("cart_empty","Your cart is empty.");return G}normalizeItem(B){let F=P(B.accessTierId),G=P(B.productId),J=P(B.lineItemId)??F??G;if(!B.id||!J||typeof B.unitPrice!=="number")return null;let Z=typeof B.name==="string"&&B.name.trim().length>0?B.name.trim():"Item";return{...B,id:B.id,lineItemId:J,...F?{accessTierId:F}:{},...G?{productId:G}:{},checkoutLinkKey:B.checkoutLinkKey??this.defaultCheckoutLinkKey,name:Z,unitPrice:B.unitPrice,quantity:k(B.quantity)}}async post(B,F){let G=`${this.endpoint}${B}`,J=JSON.stringify(F),Z={"Content-Type":"application/json"},X={body:F,bodyText:J,endpoint:this.endpoint,headers:Z,path:B,siteKey:this.siteKey,url:G},R=typeof this.requestHeaders==="function"?await this.requestHeaders(X):this.requestHeaders,N=c(Z,R),M=await fetch(G,{method:"POST",headers:N,body:J}),E=await M.json().catch(()=>null);if(!M.ok){let q=typeof E?.code==="string"&&E.code.length>0?E.code:"request_failed",v=typeof E?.message==="string"&&E.message.length>0?E.message:"Cart request failed";throw new $(q,v,M.status)}if(!E||typeof E!=="object"||E.ok!==!0||typeof E.checkoutUrl!=="string"||E.checkoutUrl.length===0)throw new $("request_failed","Cart response was invalid.",M.status);return E}commit(){if(this.items=W(this.items),this.persist&&this.storage)try{let B={version:A,items:this.items};this.storage.setItem(this.storageKey,JSON.stringify(B))}catch(B){this.log("Failed to persist cart",B)}this.emit()}emit(){let B=this.getState();for(let F of this.listeners)F(B)}log(...B){if(this.debug)console.log("[@behindthescenes/cart]",...B)}}function u(B){return Y.init(B)}
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- var Z="https://api.bts.it.com/v2/website/cart",_="bts-cart",$="default",R=1;class O extends Error{code;status;constructor(A,F,G){super(F);this.name="BTSCartError",this.code=A,this.status=G}}function v(){try{return globalThis.window??null}catch{return null}}function D(){try{return v()?.localStorage}catch{return}}function E(A){return(A??Z).replace(/\/$/,"")}function q(A){if(!Number.isFinite(A??1))return 1;return Math.min(99,Math.max(1,Math.floor(A??1)))}function z(A){return{items:A.map((F)=>({...F}))}}function B(A){if(A.discountEligibleTierOrProductIds?.length)return[...new Set(A.discountEligibleTierOrProductIds.filter(Boolean))];return[...new Set([A.accessTierId,A.productId,A.lineItemId].filter((F)=>Boolean(F)))]}function W(A){let F=new Set;for(let G of A)for(let J of[G.lineItemId,G.accessTierId,G.productId])if(J)F.add(J);return A.map((G)=>{if(!G.discount)return G;let J=B(G);if(J.length===0||!J.some((M)=>F.has(M))){let M={...G};return delete M.discount,delete M.discountEligibleTierOrProductIds,M}return G})}function I(A,F){let G=new Headers(A);if(!F)return G;return new Headers(F).forEach((J,M)=>G.set(M,J)),G}function b(A){let F=A.checkoutLinkId.trim();try{let G=F.includes("://")?F:F.startsWith("/")?`https://bts-cart.invalid${F}`:F,J=new URL(G),M=J.pathname.split("/").filter(Boolean),P=M.indexOf("c"),V=P>=0?M[P+1]:M.at(-1);if(V)return{checkoutLinkId:V,discountCode:A.discountCode??J.searchParams.get("discountCode")??void 0}}catch{}return{checkoutLinkId:F,discountCode:A.discountCode}}class Y{siteKey;endpoint;debug;persist;storageKey;storage;checkoutLinks;defaultCheckoutLinkKey;requestHeaders;items=[];listeners=new Set;constructor(A){this.siteKey=A.siteKey,this.endpoint=E(A.endpoint),this.debug=A.debug??!1,this.persist=A.persist??!0,this.storageKey=A.storageKey??_,this.storage=A.storage??D(),this.checkoutLinks=A.checkoutLinks??{},this.defaultCheckoutLinkKey=A.defaultCheckoutLinkKey??Object.keys(this.checkoutLinks)[0]??$,this.requestHeaders=A.requestHeaders,this.rehydrate()}static init(A){return new Y(A)}getItems(){return z(this.items).items}getState(){return z(this.items)}getItemCount(){return this.items.reduce((A,F)=>A+F.quantity,0)}getSubtotal(){return this.items.reduce((A,F)=>A+(F.fullPrice??F.unitPrice)*F.quantity,0)}getTotal(){return this.items.reduce((A,F)=>A+F.unitPrice*F.quantity,0)}subscribe(A){return this.listeners.add(A),A(this.getState()),()=>{this.listeners.delete(A)}}destroy(){this.listeners.clear()}rehydrate(){if(!this.persist||!this.storage)return;try{let A=this.storage.getItem(this.storageKey);if(!A)return;let F=JSON.parse(A),G=Array.isArray(F)?F:F.items;if(!Array.isArray(G))return;this.items=W(G.map((J)=>this.normalizeItem(J)).filter((J)=>Boolean(J))),this.emit()}catch(A){this.log("Failed to hydrate cart",A)}}addItem(A){let F=this.normalizeItem(A);if(!F)return;let G=this.items.find((J)=>J.id===F.id);if(G){this.setQuantity(G.id,G.quantity+F.quantity);return}this.items=[...this.items,F],this.commit()}removeItem(A){this.items=this.items.filter((F)=>F.id!==A),this.commit()}setQuantity(A,F){let G=Math.floor(F);this.items=G<=0?this.items.filter((J)=>J.id!==A):this.items.map((J)=>J.id===A?{...J,quantity:G}:J),this.commit()}increment(A,F=1){let G=this.items.find((J)=>J.id===A);if(G)this.setQuantity(A,G.quantity+Math.max(1,Math.floor(F)))}decrement(A,F=1){let G=this.items.find((J)=>J.id===A);if(G)this.setQuantity(A,G.quantity-Math.max(1,Math.floor(F)))}clear(){if(this.items=[],this.persist&&this.storage)try{this.storage.removeItem(this.storageKey)}catch(A){this.log("Failed to clear cart storage",A)}this.emit()}async resolveCheckoutUrl(A=this.defaultCheckoutLinkKey){let F=this.checkoutLinks[A];if(!F)throw new O("checkout_link_not_found",`Unknown checkout link key: ${A}`);let G=b(F),J=this.itemsForCheckout(A,F),M={siteKey:this.siteKey,checkoutLinkId:G.checkoutLinkId,mode:F.mode,...G.discountCode?{discountCode:G.discountCode}:{},...J.length>0?{items:J}:{}};return(await this.post("/checkout-url",M)).checkoutUrl}async checkout(A=this.defaultCheckoutLinkKey){let F=await this.resolveCheckoutUrl(A),G=v();if(G)G.location.assign(F);return F}itemsForCheckout(A,F){if(F.mode==="static")return[];let G=this.items.filter((J)=>J.checkoutLinkKey===A).map((J)=>({lineItemId:J.lineItemId,quantity:J.quantity,...J.discount?{discount:J.discount}:{}}));if(G.length===0)throw new O("cart_empty","Your cart is empty.");return G}normalizeItem(A){if(!A.id||!A.lineItemId||typeof A.unitPrice!=="number")return null;let F=typeof A.name==="string"&&A.name.trim().length>0?A.name.trim():"Item";return{...A,id:A.id,lineItemId:A.lineItemId,checkoutLinkKey:A.checkoutLinkKey??this.defaultCheckoutLinkKey,name:F,unitPrice:A.unitPrice,quantity:q(A.quantity)}}async post(A,F){let G=`${this.endpoint}${A}`,J=JSON.stringify(F),M={"Content-Type":"application/json"},P={body:F,bodyText:J,endpoint:this.endpoint,headers:M,path:A,siteKey:this.siteKey,url:G},V=typeof this.requestHeaders==="function"?await this.requestHeaders(P):this.requestHeaders,Q=I(M,V),X=await fetch(G,{method:"POST",headers:Q,body:J}),N=await X.json().catch(()=>null);if(!X.ok){let U=typeof N?.code==="string"&&N.code.length>0?N.code:"request_failed",H=typeof N?.message==="string"&&N.message.length>0?N.message:"Cart request failed";throw new O(U,H,X.status)}if(!N||typeof N!=="object"||N.ok!==!0||typeof N.checkoutUrl!=="string"||N.checkoutUrl.length===0)throw new O("request_failed","Cart response was invalid.",X.status);return N}commit(){if(this.items=W(this.items),this.persist&&this.storage)try{let A={version:R,items:this.items};this.storage.setItem(this.storageKey,JSON.stringify(A))}catch(A){this.log("Failed to persist cart",A)}this.emit()}emit(){let A=this.getState();for(let F of this.listeners)F(A)}log(...A){if(this.debug)console.log("[@behindthescenes/cart]",...A)}}function S(A){return Y.init(A)}export{S as createBTSCart,O as BTSCartError,Y as BTSCart};
1
+ var P="https://api.bts.it.com/v2/website/cart",_="bts-cart",D="default",Y=2;function z(){try{return globalThis.window??null}catch{return null}}function V(){try{return globalThis.localStorage??z()?.localStorage??null}catch{return null}}var C=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"],q=["fbclid","gclid","gbraid","wbraid","ttclid","li_fat_id","msclkid","_fbp","_fbc"];function v(B){if(!B)return{utm:{},clickIds:{}};try{let F=JSON.parse(B);if(!F||typeof F!=="object"||Array.isArray(F))return{utm:{},clickIds:{}};let G=F,J=G.utm&&typeof G.utm==="object"&&!Array.isArray(G.utm)?Object.fromEntries(Object.entries(G.utm).filter((X)=>typeof X[1]==="string"&&X[1].length>0)):{},Z=G.clickIds&&typeof G.clickIds==="object"&&!Array.isArray(G.clickIds)?Object.fromEntries(Object.entries(G.clickIds).filter((X)=>typeof X[1]==="string"&&X[1].length>0)):{};return{utm:J,clickIds:Z}}catch{return{utm:{},clickIds:{}}}}function H(B,F){let G=new URL(B);G.searchParams.set("bts_site",F);let J=V(),Z=J?.getItem("bts_analytics_jt")?.trim();if(Z)G.searchParams.set("bts_jt",Z);let{utm:X,clickIds:R}=v(J?.getItem("bts_analytics_attr")??null);for(let N of C){let M=X[N];if(M)G.searchParams.set(N,M)}for(let N of q){let M=R[N];if(M)G.searchParams.set(N,M)}return G.toString()}class $ extends Error{code;status;details;constructor(B,F,G,J){super(F);this.name="BTSCartError",this.code=B,this.status=G,this.details=J}}function S(){return V()??void 0}function b(B){return(B??P).replace(/\/$/,"")}function j(B){if(!Number.isFinite(B??1))return 1;return Math.max(1,Math.floor(B??1))}function Q(B){return{items:B.map((F)=>({...F}))}}function A(B){let F=B?.trim();return F&&F.length>0?F:void 0}function x(B){return B.accessTierId??B.productId??B.lineItemId}function K(B){if(B.discountEligibleTierOrProductIds?.length)return[...new Set(B.discountEligibleTierOrProductIds.filter(Boolean))];return[...new Set([B.accessTierId,B.productId,B.lineItemId].filter((F)=>Boolean(F)))]}function U(B){let F=new Set;for(let G of B)for(let J of[G.lineItemId,G.accessTierId,G.productId])if(J)F.add(J);return B.map((G)=>{if(!G.discount)return G;let J=K(G);if(J.length===0||!J.some((Z)=>F.has(Z))){let Z={...G};return delete Z.discount,delete Z.discountEligibleTierOrProductIds,Z}return G})}function L(B,F){let G=new Headers(B);if(!F)return G;return new Headers(F).forEach((J,Z)=>G.set(Z,J)),G}function w(B){let F=B.checkoutLinkId.trim();try{let G=F.includes("://")?F:F.startsWith("/")?`https://bts-cart.invalid${F}`:F,J=new URL(G),Z=J.pathname.split("/").filter(Boolean),X=Z.indexOf("c"),R=X>=0?Z[X+1]:Z.at(-1);if(R)return{checkoutLinkId:R,discountCode:B.discountCode??J.searchParams.get("discountCode")??void 0}}catch{}return{checkoutLinkId:F,discountCode:B.discountCode}}class O{siteKey;endpoint;debug;persist;storageKey;storage;checkoutLinks;defaultCheckoutLinkKey;requestHeaders;items=[];listeners=new Set;constructor(B){this.siteKey=B.siteKey,this.endpoint=b(B.endpoint),this.debug=B.debug??!1,this.persist=B.persist??!0,this.storageKey=B.storageKey??_,this.storage=B.storage??S(),this.checkoutLinks=B.checkoutLinks??{},this.defaultCheckoutLinkKey=B.defaultCheckoutLinkKey??Object.keys(this.checkoutLinks)[0]??D,this.requestHeaders=B.requestHeaders,this.rehydrate()}static init(B){return new O(B)}getItems(){return Q(this.items).items}getState(){return Q(this.items)}getItemCount(){return this.items.reduce((B,F)=>B+F.quantity,0)}getSubtotal(){return this.items.reduce((B,F)=>B+(F.fullPrice??F.unitPrice)*F.quantity,0)}getTotal(){return this.items.reduce((B,F)=>B+F.unitPrice*F.quantity,0)}subscribe(B){return this.listeners.add(B),B(this.getState()),()=>{this.listeners.delete(B)}}destroy(){this.listeners.clear()}rehydrate(){if(!this.persist||!this.storage)return;try{let B=this.storage.getItem(this.storageKey);if(!B)return;let F=JSON.parse(B);if(Array.isArray(F)||F.version!==Y){this.storage.removeItem(this.storageKey);return}let G=F.items;if(!Array.isArray(G))return;this.items=U(G.map((J)=>this.normalizeItem(J)).filter((J)=>Boolean(J))),this.emit()}catch(B){this.log("Failed to hydrate cart",B)}}addItem(B){let F=this.normalizeItem(B);if(!F)return;let G=this.items.find((J)=>J.id===F.id);if(G){this.setQuantity(G.id,G.quantity+F.quantity);return}this.items=[...this.items,F],this.commit()}removeItem(B){this.items=this.items.filter((F)=>F.id!==B),this.commit()}setQuantity(B,F){let G=Math.floor(F);this.items=G<=0?this.items.filter((J)=>J.id!==B):this.items.map((J)=>J.id===B?{...J,quantity:G}:J),this.commit()}increment(B,F=1){let G=this.items.find((J)=>J.id===B);if(G)this.setQuantity(B,G.quantity+Math.max(1,Math.floor(F)))}decrement(B,F=1){let G=this.items.find((J)=>J.id===B);if(G)this.setQuantity(B,G.quantity-Math.max(1,Math.floor(F)))}clear(){if(this.items=[],this.persist&&this.storage)try{this.storage.removeItem(this.storageKey)}catch(B){this.log("Failed to clear cart storage",B)}this.emit()}async resolveCheckoutUrl(B=this.defaultCheckoutLinkKey){let F=this.checkoutLinks[B];if(!F)throw new $("checkout_link_not_found",`Unknown checkout link key: ${B}`);let G=w(F),J=this.itemsForCheckout(B,F),Z={siteKey:this.siteKey,checkoutLinkId:G.checkoutLinkId,mode:F.mode,...G.discountCode?{discountCode:G.discountCode}:{},...J.length>0?{items:J}:{}};try{let X=await this.post("/checkout-url",Z);return H(X.checkoutUrl,this.siteKey)}catch(X){if(X instanceof $)if(X.code==="discounts_invalid")throw new $(X.code,X.message,X.status,X.details);else throw new $(X.code,X.message,X.status);throw new $("request_failed","Failed to resolve checkout URL.",void 0,void 0)}}async checkout(B=this.defaultCheckoutLinkKey){try{let F=await this.resolveCheckoutUrl(B),G=z();if(G)G.location.assign(F);return F}catch(F){if(F instanceof $)if(F.code==="discounts_invalid"){for(let G of F.details??[]){if(G.lineItemId)this.items=this.items.map((J)=>J.lineItemId===G.lineItemId?{...J,discount:void 0}:J);if(G.productId)this.items=this.items.map((J)=>J.productId===G.productId?{...J,discount:void 0}:J);if(G.accessTierId)this.items=this.items.map((J)=>J.accessTierId===G.accessTierId?{...J,discount:void 0}:J)}throw this.commit(),new $(F.code,F.message,F.status,F.details)}else throw new $(F.code,F.message,F.status);throw new $("request_failed","Failed to resolve checkout URL.",void 0,void 0)}}itemsForCheckout(B,F){if(F.mode==="static")return[];let G=this.items.filter((J)=>J.checkoutLinkKey===B).map((J)=>({lineItemId:x(J),quantity:J.quantity,...J.discount?{discount:J.discount}:{}}));if(G.length===0)throw new $("cart_empty","Your cart is empty.");return G}normalizeItem(B){let F=A(B.accessTierId),G=A(B.productId),J=A(B.lineItemId)??F??G;if(!B.id||!J||typeof B.unitPrice!=="number")return null;let Z=typeof B.name==="string"&&B.name.trim().length>0?B.name.trim():"Item";return{...B,id:B.id,lineItemId:J,...F?{accessTierId:F}:{},...G?{productId:G}:{},checkoutLinkKey:B.checkoutLinkKey??this.defaultCheckoutLinkKey,name:Z,unitPrice:B.unitPrice,quantity:j(B.quantity)}}async post(B,F){let G=`${this.endpoint}${B}`,J=JSON.stringify(F),Z={"Content-Type":"application/json"},X={body:F,bodyText:J,endpoint:this.endpoint,headers:Z,path:B,siteKey:this.siteKey,url:G},R=typeof this.requestHeaders==="function"?await this.requestHeaders(X):this.requestHeaders,N=L(Z,R),M=await fetch(G,{method:"POST",headers:N,body:J}),E=await M.json().catch(()=>null);if(!M.ok){let T=typeof E?.code==="string"&&E.code.length>0?E.code:"request_failed",W=typeof E?.message==="string"&&E.message.length>0?E.message:"Cart request failed";throw new $(T,W,M.status)}if(!E||typeof E!=="object"||E.ok!==!0||typeof E.checkoutUrl!=="string"||E.checkoutUrl.length===0)throw new $("request_failed","Cart response was invalid.",M.status);return E}commit(){if(this.items=U(this.items),this.persist&&this.storage)try{let B={version:Y,items:this.items};this.storage.setItem(this.storageKey,JSON.stringify(B))}catch(B){this.log("Failed to persist cart",B)}this.emit()}emit(){let B=this.getState();for(let F of this.listeners)F(B)}log(...B){if(this.debug)console.log("[@behindthescenes/cart]",...B)}}function a(B){return O.init(B)}export{x as resolveLineItemIdForCheckout,a as createBTSCart,$ as BTSCartError,O as BTSCart};
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@behindthescenes/cart",
3
- "version": "0.0.8",
4
- "generatedAt": "2026-05-15T10:30:41.615Z",
3
+ "version": "0.0.12",
4
+ "generatedAt": "2026-05-21T11:01:10.762Z",
5
5
  "artifacts": {
6
6
  "browser": "browser/browser.js",
7
7
  "cjs": "cjs/index.js",
@@ -1,3 +1,4 @@
1
1
  import { BTSCart, createBTSCart } from "./index";
2
+ import "./types/BTSCartBrowser.types";
2
3
  export { BTSCart, createBTSCart };
3
4
  export type { BTSCartCheckoutItemPayload, BTSCartCheckoutLinkConfig, BTSCartCheckoutUrlRequest, BTSCartCheckoutUrlResult, BTSCartInit, BTSCartItem, BTSCartItemInput, BTSCartState, } from "./types/index.types";
@@ -1,4 +1,4 @@
1
1
  export declare const DEFAULT_ENDPOINT = "https://api.bts.it.com/v2/website/cart";
2
2
  export declare const DEFAULT_STORAGE_KEY = "bts-cart";
3
3
  export declare const DEFAULT_CHECKOUT_LINK_KEY = "default";
4
- export declare const STORAGE_VERSION = 1;
4
+ export declare const STORAGE_VERSION = 2;
@@ -1,4 +1,9 @@
1
1
  import type { BTSCartInit, BTSCartItem, BTSCartItemInput, BTSCartListener, BTSCartState } from "./types/index.types";
2
+ /**
3
+ * Prefer catalog UUIDs on checkout-url — matches `resolveDynamicCheckoutCartLineItem` (tier/product
4
+ * id, then persisted line-item pk).
5
+ */
6
+ export declare function resolveLineItemIdForCheckout(item: Pick<BTSCartItem, "lineItemId" | "productId" | "accessTierId">): string;
2
7
  export declare class BTSCart {
3
8
  private siteKey;
4
9
  private endpoint;
@@ -11,31 +16,56 @@ export declare class BTSCart {
11
16
  private requestHeaders?;
12
17
  private items;
13
18
  private listeners;
19
+ /** Hydrate the cart from init options and restore any persisted state. */
14
20
  constructor(init: BTSCartInit);
21
+ /** Convenience constructor matching the analytics package's static `init` API. */
15
22
  static init(opts: BTSCartInit): BTSCart;
23
+ /** Return a defensive copy of cart items for read-only external consumers. */
16
24
  getItems(): BTSCartItem[];
25
+ /** Return the full cart state object expected by subscribers and embedders. */
17
26
  getState(): BTSCartState;
27
+ /** Count total units across all lines, not just distinct items. */
18
28
  getItemCount(): number;
29
+ /** Sum undiscounted line totals using `fullPrice` when it exists. */
19
30
  getSubtotal(): number;
31
+ /** Sum discounted line totals using the actual checkout unit price. */
20
32
  getTotal(): number;
33
+ /** Register a listener and immediately emit the current state for simple UI synchronization. */
21
34
  subscribe(listener: BTSCartListener): () => void;
35
+ /** Tear down subscriptions without mutating the cart contents. */
22
36
  destroy(): void;
37
+ /** Restore a versioned cart snapshot from storage and normalize legacy item shapes on read. */
23
38
  rehydrate(): void;
39
+ /** Add a new line or merge into an existing line with the same SDK item id. */
24
40
  addItem(input: BTSCartItemInput): void;
41
+ /** Remove a line entirely by its SDK item id. */
25
42
  removeItem(id: string): void;
43
+ /** Replace a line quantity, dropping the line when the requested quantity is zero or below. */
26
44
  setQuantity(id: string, quantity: number): void;
45
+ /** Increase a line quantity using a clamped positive integer increment. */
27
46
  increment(id: string, amount?: number): void;
47
+ /** Decrease a line quantity using a clamped positive integer decrement. */
28
48
  decrement(id: string, amount?: number): void;
49
+ /** Empty the in-memory cart and remove the persisted snapshot when persistence is enabled. */
29
50
  clear(): void;
51
+ /** Build a checkout URL via the cart API, then append browser attribution for downstream analytics. */
30
52
  resolveCheckoutUrl(checkoutLinkKey?: string): Promise<string>;
53
+ /** Resolve a checkout URL and navigate the current browser when one is available. */
31
54
  checkout(checkoutLinkKey?: string): Promise<string>;
55
+ /** Convert current cart lines into the API payload expected by dynamic checkout links. */
32
56
  private itemsForCheckout;
57
+ /** Normalize partial external item input into the persisted cart line shape. */
33
58
  private normalizeItem;
59
+ /** POST a cart request with optional caller-supplied headers and normalized API errors. */
34
60
  private post;
61
+ /** Recompute derived cart state, persist it when enabled, and notify subscribers. */
35
62
  private commit;
63
+ /** Fan out the latest immutable state snapshot to all listeners. */
36
64
  private emit;
65
+ /** Emit debug logs only when the SDK was initialized in debug mode. */
37
66
  private log;
38
67
  }
68
+ /** Public package factory mirroring the class-based `BTSCart.init` constructor. */
39
69
  export declare function createBTSCart(init: BTSCartInit): BTSCart;
40
70
  export type { BTSCartCheckoutItemPayload, BTSCartCheckoutLinkConfig, BTSCartCheckoutUrlRequest, BTSCartCheckoutUrlResult, BTSCartErrorCode, BTSCartInit, BTSCartItem, BTSCartItemInput, BTSCartListener, BTSCartMode, BTSCartRequestContext, BTSCartRequestHeaders, BTSCartState, BTSCartStorage, } from "./types/index.types";
41
71
  export { BTSCartError } from "./types/index.types";
@@ -0,0 +1,98 @@
1
+ export type BTSCartMode = "static" | "dynamic";
2
+ export type BTSCartStorage = Pick<Storage, "getItem" | "setItem" | "removeItem">;
3
+ export type BTSCartRequestContext = {
4
+ body: unknown;
5
+ bodyText: string;
6
+ endpoint: string;
7
+ headers: Record<string, string>;
8
+ path: string;
9
+ siteKey: string;
10
+ url: string;
11
+ };
12
+ export type BTSCartRequestHeaders = HeadersInit | ((request: BTSCartRequestContext) => HeadersInit | Promise<HeadersInit>);
13
+ export type BTSCartCheckoutLinkConfig = {
14
+ /** Checkout link UUID, or a full checkout URL (`https://…/c/<uuid>?discountCode=…`). Relative `/c/<uuid>` is supported. */
15
+ checkoutLinkId: string;
16
+ mode: BTSCartMode;
17
+ discountCode?: string;
18
+ };
19
+ export type BTSCartItemInput = {
20
+ id: string;
21
+ /**
22
+ * Sent as `lineItemId` on `POST /v2/website/cart/checkout-url` when no {@link productId} or
23
+ * {@link accessTierId} is set. Must match a resolved line on the link: the row’s `id`, or its
24
+ * `product_id` / `access_tier_id` (see `resolveDynamicCheckoutCartLineItem` in `@bts/common`).
25
+ * For dynamic catalog links, prefer {@link accessTierId} or {@link productId} instead of a
26
+ * site-local slug.
27
+ */
28
+ lineItemId?: string;
29
+ checkoutLinkKey?: string;
30
+ /** BTS product UUID; preferred checkout identifier for product lines on dynamic links. */
31
+ productId?: string;
32
+ /** BTS access tier UUID; preferred checkout identifier for tier lines on dynamic links. */
33
+ accessTierId?: string;
34
+ /** Display only in the SDK; defaults to `"Item"` if empty. Not sent to the cart API. */
35
+ name: string;
36
+ unitPrice: number;
37
+ fullPrice?: number;
38
+ image?: string;
39
+ quantity?: number;
40
+ /** Internal promo-code ID or customer-facing promo code. Customer codes are resolved by the BTS cart API. */
41
+ discount?: string;
42
+ /**
43
+ * Optional catalog identifiers for embedders documenting promo scope. The SDK persists them but
44
+ * does not clear discounts client-side; the cart API validates promos on checkout-url.
45
+ */
46
+ discountEligibleTierOrProductIds?: string[];
47
+ };
48
+ export type BTSCartItem = Required<Pick<BTSCartItemInput, "id" | "lineItemId" | "name" | "unitPrice" | "quantity">> & Omit<BTSCartItemInput, "quantity"> & {
49
+ checkoutLinkKey: string;
50
+ };
51
+ export type BTSCartState = {
52
+ items: BTSCartItem[];
53
+ };
54
+ export type BTSCartListener = (state: BTSCartState) => void;
55
+ export type BTSCartInit = {
56
+ siteKey: string;
57
+ endpoint?: string;
58
+ checkoutLinks?: Record<string, BTSCartCheckoutLinkConfig>;
59
+ defaultCheckoutLinkKey?: string;
60
+ debug?: boolean;
61
+ persist?: boolean;
62
+ storageKey?: string;
63
+ storage?: BTSCartStorage;
64
+ requestHeaders?: BTSCartRequestHeaders;
65
+ };
66
+ export type BTSCartCheckoutItemPayload = {
67
+ lineItemId: string;
68
+ quantity: number;
69
+ discount?: string;
70
+ };
71
+ export type BTSCartCheckoutUrlRequest = {
72
+ siteKey: string;
73
+ checkoutLinkId: string;
74
+ mode: BTSCartMode;
75
+ items?: BTSCartCheckoutItemPayload[];
76
+ discountCode?: string;
77
+ };
78
+ export type BTSCartCheckoutUrlResult = {
79
+ ok: true;
80
+ checkoutUrl: string;
81
+ checkoutLinkId: string;
82
+ mode: BTSCartMode;
83
+ items: BTSCartCheckoutItemPayload[];
84
+ };
85
+ export type BTSCartErrorCode = "unknown_site" | "domain_not_verified" | "analytics_disabled" | "checkout_link_not_found" | "checkout_link_inactive" | "checkout_link_expired" | "checkout_link_sold_out" | "checkout_link_mode_mismatch" | "cart_empty" | "line_item_not_found" | "invalid_quantity" | "line_item_sold_out" | "quantity_exceeded" | "product_unavailable" | "discounts_invalid" | "request_failed" | "discounts_invalid";
86
+ export declare class BTSCartError extends Error {
87
+ code: BTSCartErrorCode;
88
+ status?: number;
89
+ details?: {
90
+ lineItemId: string;
91
+ productId?: string;
92
+ accessTierId?: string;
93
+ discountCode: string;
94
+ discountId?: string;
95
+ reason: string;
96
+ }[];
97
+ constructor(code: BTSCartErrorCode, message: string, status?: number, details?: BTSCartError["details"]);
98
+ }
@@ -1,86 +1,4 @@
1
- export type BTSCartMode = "static" | "dynamic";
2
- export type BTSCartStorage = Pick<Storage, "getItem" | "setItem" | "removeItem">;
3
- export type BTSCartRequestContext = {
4
- body: unknown;
5
- bodyText: string;
6
- endpoint: string;
7
- headers: Record<string, string>;
8
- path: string;
9
- siteKey: string;
10
- url: string;
11
- };
12
- export type BTSCartRequestHeaders = HeadersInit | ((request: BTSCartRequestContext) => HeadersInit | Promise<HeadersInit>);
13
- export type BTSCartCheckoutLinkConfig = {
14
- /** Checkout link UUID, or a full checkout URL (`https://…/c/<uuid>?discountCode=…`). Relative `/c/<uuid>` is supported. */
15
- checkoutLinkId: string;
16
- mode: BTSCartMode;
17
- discountCode?: string;
18
- };
19
- export type BTSCartItemInput = {
20
- id: string;
21
- /**
22
- * Sent as `lineItemId` on `POST /v2/website/cart/checkout-url`. Must match a resolved line on the
23
- * link: the row’s `id`, or its `product_id` / `access_tier_id` (see `resolveDynamicCheckoutCartLineItem` in `@bts/common`).
24
- */
25
- lineItemId: string;
26
- checkoutLinkKey?: string;
27
- productId?: string;
28
- accessTierId?: string;
29
- /** Display only in the SDK; defaults to `"Item"` if empty. Not sent to the cart API. */
30
- name: string;
31
- unitPrice: number;
32
- fullPrice?: number;
33
- image?: string;
34
- quantity?: number;
35
- /** Internal promo-code ID or customer-facing promo code. Customer codes are resolved by the BTS cart API. */
36
- discount?: string;
37
- /**
38
- * Catalog identifiers (access tier id and/or product id) this promo applies to. Used when cart
39
- * lines change so discounts can be cleared if no remaining line is still eligible. Defaults to
40
- * {@link accessTierId}, {@link productId}, and {@link lineItemId} when omitted.
41
- */
42
- discountEligibleTierOrProductIds?: string[];
43
- };
44
- export type BTSCartItem = Required<Pick<BTSCartItemInput, "id" | "lineItemId" | "name" | "unitPrice" | "quantity">> & Omit<BTSCartItemInput, "quantity"> & {
45
- checkoutLinkKey: string;
46
- };
47
- export type BTSCartState = {
48
- items: BTSCartItem[];
49
- };
50
- export type BTSCartListener = (state: BTSCartState) => void;
51
- export type BTSCartInit = {
52
- siteKey: string;
53
- endpoint?: string;
54
- checkoutLinks?: Record<string, BTSCartCheckoutLinkConfig>;
55
- defaultCheckoutLinkKey?: string;
56
- debug?: boolean;
57
- persist?: boolean;
58
- storageKey?: string;
59
- storage?: BTSCartStorage;
60
- requestHeaders?: BTSCartRequestHeaders;
61
- };
62
- export type BTSCartCheckoutItemPayload = {
63
- lineItemId: string;
64
- quantity: number;
65
- discount?: string;
66
- };
67
- export type BTSCartCheckoutUrlRequest = {
68
- siteKey: string;
69
- checkoutLinkId: string;
70
- mode: BTSCartMode;
71
- items?: BTSCartCheckoutItemPayload[];
72
- discountCode?: string;
73
- };
74
- export type BTSCartCheckoutUrlResult = {
75
- ok: true;
76
- checkoutUrl: string;
77
- checkoutLinkId: string;
78
- mode: BTSCartMode;
79
- items: BTSCartCheckoutItemPayload[];
80
- };
81
- export type BTSCartErrorCode = "unknown_site" | "domain_not_verified" | "analytics_disabled" | "checkout_link_not_found" | "checkout_link_inactive" | "checkout_link_expired" | "checkout_link_sold_out" | "checkout_link_mode_mismatch" | "cart_empty" | "line_item_not_found" | "invalid_quantity" | "line_item_sold_out" | "quantity_exceeded" | "product_unavailable" | "discount_invalid" | "request_failed";
82
- export declare class BTSCartError extends Error {
83
- code: BTSCartErrorCode;
84
- status?: number;
85
- constructor(code: BTSCartErrorCode, message: string, status?: number);
86
- }
1
+ export type * from "./BTSCart.types";
2
+ export type * as BTSCartBrowserTypes from "./BTSCartBrowser.types";
3
+ export type * as BTSCartTypes from "./BTSCart.types";
4
+ export { BTSCartError } from "./BTSCart.types";
@@ -0,0 +1,3 @@
1
+ /** Append BTS site, journey, UTMs, and click IDs from analytics localStorage to a checkout URL. */
2
+ declare function decorateCheckoutUrlWithBrowserAttribution(url: string, siteKey: string): string;
3
+ export { decorateCheckoutUrlWithBrowserAttribution };
@@ -0,0 +1,5 @@
1
+ /** Read `window` defensively so Node / SSR bundles never crash on a missing global. */
2
+ declare function safeWindow(): Window | null;
3
+ /** Prefer a directly mocked `globalThis.localStorage`, then fall back to `window.localStorage`. */
4
+ declare function safeStorage(): Storage | null;
5
+ export { safeStorage, safeWindow };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@behindthescenes/cart",
3
- "version": "0.0.8",
3
+ "version": "0.0.12",
4
4
  "description": "Browser cart SDK for BTS external-site checkout links.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",