bitsnap-react 1.11.1 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +10 -4
  2. package/dist/CartProvider-XNFSUOCB.js +2 -0
  3. package/dist/CartProvider-XNFSUOCB.js.map +1 -0
  4. package/dist/CartProvider-YMJ7RFO4.mjs +2 -0
  5. package/dist/analytics.js +1 -1
  6. package/dist/analytics.mjs +1 -1
  7. package/dist/catalog.js +1 -1
  8. package/dist/catalog.mjs +1 -1
  9. package/dist/{chunk-ETGHIHWR.mjs → chunk-3QG7H2AI.mjs} +2 -2
  10. package/dist/chunk-4BW6J7FP.js +4 -0
  11. package/dist/{chunk-FBTYZHXM.js.map → chunk-4BW6J7FP.js.map} +1 -1
  12. package/dist/{chunk-HWQNT6XU.mjs → chunk-5R3WR22A.mjs} +2 -2
  13. package/dist/{chunk-UFIOJGJZ.js → chunk-6IACFTJR.js} +2 -2
  14. package/dist/{chunk-UFIOJGJZ.js.map → chunk-6IACFTJR.js.map} +1 -1
  15. package/dist/{chunk-WGJTXDIS.js → chunk-DF2IK2GN.js} +2 -2
  16. package/dist/{chunk-WGJTXDIS.js.map → chunk-DF2IK2GN.js.map} +1 -1
  17. package/dist/{chunk-3IVLQILF.js → chunk-DGUIG334.js} +2 -2
  18. package/dist/{chunk-3IVLQILF.js.map → chunk-DGUIG334.js.map} +1 -1
  19. package/dist/{chunk-JUDR4EZA.mjs → chunk-E5DCEFI2.mjs} +2 -2
  20. package/dist/chunk-ERL4Z7M7.js +2 -0
  21. package/dist/{chunk-Q25D7OAO.js.map → chunk-ERL4Z7M7.js.map} +1 -1
  22. package/dist/{chunk-IJLHU2MA.mjs → chunk-FF2ICGFQ.mjs} +2 -2
  23. package/dist/{chunk-IJLHU2MA.mjs.map → chunk-FF2ICGFQ.mjs.map} +1 -1
  24. package/dist/{chunk-VPBFEAFQ.js → chunk-ICFYSZTV.js} +2 -2
  25. package/dist/{chunk-VPBFEAFQ.js.map → chunk-ICFYSZTV.js.map} +1 -1
  26. package/dist/{chunk-UCL4Y7L3.js → chunk-MLSKHOA3.js} +2 -2
  27. package/dist/{chunk-UCL4Y7L3.js.map → chunk-MLSKHOA3.js.map} +1 -1
  28. package/dist/chunk-P4Q5KXKS.mjs +2 -0
  29. package/dist/{chunk-G2UOTVS5.mjs.map → chunk-P4Q5KXKS.mjs.map} +1 -1
  30. package/dist/chunk-PNTO3L2C.mjs +4 -0
  31. package/dist/chunk-PNTO3L2C.mjs.map +1 -0
  32. package/dist/chunk-QSIKRVZL.mjs +2 -0
  33. package/dist/chunk-QSIKRVZL.mjs.map +1 -0
  34. package/dist/{chunk-DWRBPP32.mjs → chunk-UCESDAEC.mjs} +2 -2
  35. package/dist/chunk-XTIY6PXH.js +2 -0
  36. package/dist/{chunk-YBGAYEJQ.js.map → chunk-XTIY6PXH.js.map} +1 -1
  37. package/dist/course.js +1 -1
  38. package/dist/course.mjs +1 -1
  39. package/dist/embed/analytics.js +1 -1
  40. package/dist/index.css +1 -1
  41. package/dist/index.css.map +1 -1
  42. package/dist/index.d.mts +49 -1
  43. package/dist/index.d.ts +49 -1
  44. package/dist/index.js +1 -1
  45. package/dist/index.js.map +1 -1
  46. package/dist/index.mjs +1 -1
  47. package/dist/index.mjs.map +1 -1
  48. package/dist/methods-DDGOXLP6.mjs +2 -0
  49. package/dist/methods-RQPDIUUN.js +2 -0
  50. package/dist/{methods-ZBX4BTDE.js.map → methods-RQPDIUUN.js.map} +1 -1
  51. package/dist/returns.js +1 -1
  52. package/dist/returns.mjs +1 -1
  53. package/package.json +51 -26
  54. package/dist/CartProvider-QY2DMNCC.js +0 -2
  55. package/dist/CartProvider-QY2DMNCC.js.map +0 -1
  56. package/dist/CartProvider-XMHPQRWC.mjs +0 -2
  57. package/dist/chunk-2PK36NGB.mjs +0 -4
  58. package/dist/chunk-2PK36NGB.mjs.map +0 -1
  59. package/dist/chunk-2X32DDUM.mjs +0 -2
  60. package/dist/chunk-2X32DDUM.mjs.map +0 -1
  61. package/dist/chunk-FBTYZHXM.js +0 -4
  62. package/dist/chunk-G2UOTVS5.mjs +0 -2
  63. package/dist/chunk-Q25D7OAO.js +0 -2
  64. package/dist/chunk-YBGAYEJQ.js +0 -2
  65. package/dist/methods-ALO22YWQ.mjs +0 -2
  66. package/dist/methods-ZBX4BTDE.js +0 -2
  67. /package/dist/{CartProvider-XMHPQRWC.mjs.map → CartProvider-YMJ7RFO4.mjs.map} +0 -0
  68. /package/dist/{chunk-ETGHIHWR.mjs.map → chunk-3QG7H2AI.mjs.map} +0 -0
  69. /package/dist/{chunk-HWQNT6XU.mjs.map → chunk-5R3WR22A.mjs.map} +0 -0
  70. /package/dist/{chunk-JUDR4EZA.mjs.map → chunk-E5DCEFI2.mjs.map} +0 -0
  71. /package/dist/{chunk-DWRBPP32.mjs.map → chunk-UCESDAEC.mjs.map} +0 -0
  72. /package/dist/{methods-ALO22YWQ.mjs.map → methods-DDGOXLP6.mjs.map} +0 -0
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkXIHGWNTSjs = require('./chunk-XIHGWNTS.js');var Oe=Symbol.for("bitsnap.pageViews");function ye(e){let t=e;return t[Oe]??={path:null,starters:new Set,watching:!1}}function De(e,t){let n=()=>{try{t()}catch (e2){}};for(let o of["pushState","replaceState"]){let a=e.history[o];e.history[o]=function(...i){let c=a.apply(this,i);return n(),c}}e.addEventListener("popstate",n)}function A(e,t=window){try{let n=ye(t),o=()=>e();n.watching||(n.watching=!0,De(t,()=>{let i=t.location.pathname;i===n.path||n.starters.size===0||(n.path=i,_optionalChain([n, 'access', _2 => _2.starters, 'access', _3 => _3.values, 'call', _4 => _4(), 'access', _5 => _5.next, 'call', _6 => _6(), 'access', _7 => _7.value, 'optionalCall', _8 => _8()]))})),n.starters.add(o);let a=t.location.pathname;return a!==n.path&&(n.path=a,o()),()=>void n.starters.delete(o)}catch (e3){return()=>{}}}function ge(e=window){let t=ye(e);t.path=null,t.starters.clear()}var ve="1.11.1";function I(e){let t=new Uint8Array(e),n=typeof crypto<"u"?crypto:void 0;if(n&&typeof n.getRandomValues=="function")n.getRandomValues(t);else for(let o=0;o<e;o++)t[o]=Math.floor(Math.random()*256);return t}var me="X-Bitsnap-Visitor",$e=390*24*60*60,Me=/^[A-Za-z0-9_-]{22}$/;function R(e){return e.BitsnapConsent}function je(e,t){for(let n of e.cookie.split(";")){let o=n.indexOf("=");if(o!==-1&&n.slice(0,o).trim()===t)return n.slice(o+1).trim()}return null}function He(e){let t=e.toLowerCase();return t==="bitsnap.pl"||t.endsWith(".bitsnap.pl")}function F(e,t){try{let n=R(e);if(!n)return!1;if(n.scope==="project")return n.projectKey===t;let o=He(e.location.hostname);return n.scope==="global"?!o:!1}catch (e4){return!1}}function J(e,t){try{return _optionalChain([R, 'call', _9 => _9(e), 'optionalAccess', _10 => _10.get, 'call', _11 => _11(), 'optionalAccess', _12 => _12.c, 'access', _13 => _13.analytics])===!0&&F(e,t)}catch (e5){return!1}}function he(){let e="";return I(16).forEach(t=>e+=String.fromCharCode(t)),btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function Ee(e,t){try{return je(e,_chunkXIHGWNTSjs.f.call(void 0, t))}catch (e6){return null}}function B(e,t){let n=Ee(e,t);return n!==null&&Me.test(n)?n:null}function ke(e,t,n){try{let o=e.document,a=`${_chunkXIHGWNTSjs.f.call(void 0, t)}=${n}; Max-Age=${$e}; Path=/; SameSite=Lax`+(e.location.protocol==="https:"?"; Secure":"");for(let i of _chunkXIHGWNTSjs.n.call(void 0, e.location.hostname).reverse())if(o.cookie=`${a}; Domain=${i}`,B(o,t)===n)return;o.cookie=a}catch (e7){}}function be(e,t){try{let n=e.document;if(Ee(n,t)===null)return;let o=`${_chunkXIHGWNTSjs.f.call(void 0, t)}=; Max-Age=0; Path=/; SameSite=Lax`+(e.location.protocol==="https:"?"; Secure":"");n.cookie=o;for(let a of _chunkXIHGWNTSjs.n.call(void 0, e.location.hostname))n.cookie=`${o}; Domain=${a}`}catch (e8){}}function N(e,t){try{let n=e.navigator;return _optionalChain([n, 'optionalAccess', _14 => _14.globalPrivacyControl])===!0||_optionalChain([n, 'optionalAccess', _15 => _15.webdriver])===!0?null:J(e,t)?B(e.document,t):null}catch (e9){return null}}var Ue="https://collect.bitsnap.pl",Ke=5e3,Ge=20,Te=32*1024,ze=60*1024,xe=/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function _e(e){return typeof TextEncoder=="function"?new TextEncoder().encode(e).length:unescape(encodeURIComponent(e)).length}var y={track(){},page(){},clientId:()=>null,flush(){},setEnabled(){},onEvent:()=>()=>{},configure(){},destroy(){}};function Ye(e=Date.now()){let t=I(16),n=e;for(let a=5;a>=0;a--)t[a]=n%256,n=Math.floor(n/256);t[6]=t[6]&15|112,t[8]=t[8]&63|128;let o=Array.from(t,a=>a.toString(16).padStart(2,"0")).join("");return`${o.slice(0,8)}-${o.slice(8,12)}-${o.slice(12,16)}-${o.slice(16,20)}-${o.slice(20)}`}var Ce="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";function Fe(){return Array.from(I(16),e=>Ce[e%Ce.length]).join("")}function Je(e,t,n=!1){let o=_e(JSON.stringify({k:e,events:[]})),a=[],i=[],c=o,s=()=>{i.length>0&&a.push({body:JSON.stringify({k:e,events:i}),bytes:c,count:i.length}),i=[],c=o};for(let u of t){let l=_e(JSON.stringify(u));o+l>Te||((i.length>=_chunkXIHGWNTSjs.a.maxBatchEvents||c+l+(i.length>0?1:0)>Te)&&s(),c+=l+(i.length>0?1:0),i.push(u))}if(s(),n){let u=0,l=a.length;for(;l>0&&u+a[l-1].bytes<=ze;)u+=a[l-1].bytes,l--;a=a.slice(l)}return a}function Xe(e){try{return typeof window>"u"||typeof document>"u"?y:qe(e,window)}catch (e10){return y}}function qe(e,t){let n=_chunkXIHGWNTSjs.b.call(void 0, _nullishCoalesce(e.projectKey, () => (""))),o=!!e.debug,a=(...r)=>{o&&console.warn("[bitsnap analytics]",...r)};if(!n)return a("invalid projectKey, tracking is off"),y;let i=n,c=r=>`${(r||Ue).replace(/\/+$/,"")}/e`,s=c(e.endpoint),u=_nullishCoalesce(e.source, () => ("sdk_react")),l=_nullishCoalesce(e.channel, () => ("embed")),b=`bitsnap-react@${ve}`,M=Fe(),T=_chunkXIHGWNTSjs.d.call(void 0, t.location.href),j=_nullishCoalesce(e.env, () => ("live"));if(!e.env)try{new URLSearchParams(t.location.search).has("test")&&(j="test")}catch (e11){}let Le=_chunkXIHGWNTSjs.e.call(void 0, document.referrer),H=e.enabled!==!1,ee=null,Re=0,p=[],h=null,C=new Set;e.onEvent&&C.add(e.onEvent);let E=[],g,m=!0;function W(){let r=R(t);!r||r===g||(g=r,m=!r.ready,_optionalChain([r, 'access', _16 => _16.ready, 'optionalAccess', _17 => _17.then, 'call', _18 => _18(()=>{g===r&&(m=!0,re())},()=>{g===r&&(m=!0)})]))}function te(){W();try{if(!g)return!1;let r=g.get();return!!g.denied&&g.denied("analytics")||!!r&&r.c.analytics===!1}catch (e12){return!1}}function ne(r){C.forEach(f=>{try{f(r)}catch (e13){}})}function U(r){try{if(W(),!g||!F(t,i))return;J(t,i)?P()&&B(t.document,i)===null&&ke(t,i,he()):r&&be(t,i)}catch (e14){}}function re(){if(U(!0),te())p=[],E=[],w();else{if(m&&E.length>0){let r=E;E=[],r.forEach(ne)}p.length>0&&x()}}function P(){if(!H)return!1;let r=t.navigator;return r&&(r.globalPrivacyControl===!0||r.webdriver===!0)?!1:!te()}function w(){h!==null&&clearTimeout(h),h=null}function Be(){h===null&&(h=setTimeout(()=>{h=null,x()},Ke),_optionalChain([h, 'access', _19 => _19.unref, 'optionalCall', _20 => _20()]))}function Ne(r){try{if(typeof fetch=="function"){fetch(s,{method:"POST",body:r,keepalive:!0,credentials:"omit",headers:{"Content-Type":"text/plain"}}).catch(()=>{});return}}catch (e15){}try{let f=t.navigator;f&&typeof f.sendBeacon=="function"&&f.sendBeacon(s,new Blob([r],{type:"text/plain"}))}catch (e16){}}function x(r=!1){try{if(w(),p.length===0)return;if(!P()){p=[];return}if(!m)return;U(m);let f=N(t,i),d=f?p.map(k=>({...k,client_id:f})):p;p=[],Je(i,d,r).forEach(k=>Ne(k.body))}catch (e17){}}function oe(r,f,d){if(!P())return;let k=_chunkXIHGWNTSjs.g.call(void 0, r,f);if(!k.ok){a("dropped",r,k.reason);return}let se=_chunkXIHGWNTSjs.d.call(void 0, t.location.href),K={event_id:_optionalChain([d, 'optionalAccess', _21 => _21.event_id])&&xe.test(d.event_id)?d.event_id:Ye(),event:r,ts:Date.now(),schema_version:1,env:j,source:u,channel:l,sdk:b,page_id:M,page_type:_optionalChain([d, 'optionalAccess', _22 => _22.page_type])!==void 0?d.page_type:ee,host:_nullishCoalesce(_optionalChain([se, 'optionalAccess', _23 => _23.host]), () => (null)),path:_optionalChain([d, 'optionalAccess', _24 => _24.path])?_chunkXIHGWNTSjs.c.call(void 0, d.path.split(/[?#]/)[0]):_nullishCoalesce(_optionalChain([se, 'optionalAccess', _25 => _25.path]), () => (null)),referrer_host:Le,utm_source:_nullishCoalesce(_optionalChain([T, 'optionalAccess', _26 => _26.utm_source]), () => (null)),utm_medium:_nullishCoalesce(_optionalChain([T, 'optionalAccess', _27 => _27.utm_medium]), () => (null)),utm_campaign:_nullishCoalesce(_optionalChain([T, 'optionalAccess', _28 => _28.utm_campaign]), () => (null)),utm_content:_nullishCoalesce(_optionalChain([T, 'optionalAccess', _29 => _29.utm_content]), () => (null)),utm_term:_nullishCoalesce(_optionalChain([T, 'optionalAccess', _30 => _30.utm_term]), () => (null)),ref_code:_nullishCoalesce(_optionalChain([T, 'optionalAccess', _31 => _31.ref_code]), () => (null)),product_id:_nullishCoalesce(_optionalChain([d, 'optionalAccess', _32 => _32.product_id]), () => (null)),variant_id:_nullishCoalesce(_optionalChain([d, 'optionalAccess', _33 => _33.variant_id]), () => (null)),order_ref:_nullishCoalesce(_optionalChain([d, 'optionalAccess', _34 => _34.order_ref]), () => (null)),props:k.props};_optionalChain([d, 'optionalAccess', _35 => _35.event_id])&&!xe.test(d.event_id)&&a("ignored invalid event_id",r),u==="dashboard"&&e.visitorId&&(K.visitor_id=e.visitorId);let ce=_chunkXIHGWNTSjs.h.call(void 0, K);if(!ce.ok){a("dropped",r,ce.reason);return}let G=K;m?ne(G):E.push(G),p.push(G),p.length>=Ge?x():Be()}let ie=()=>x(!0),ae=()=>{document.visibilityState==="hidden"&&x(!0)},S=()=>re();return t.addEventListener("pagehide",ie),document.addEventListener("visibilitychange",ae),t.addEventListener("bitsnap:consent",S),t.addEventListener("bitsnap:consent:ready",S),W(),U(m),{track(r,f,d){try{oe(r,f,d)}catch (e18){}},page(r,f){try{r!==void 0&&(ee=r),oe("page_view",{landing:Re++===0},f)}catch (e19){}},clientId(r){try{return r!==void 0&&_chunkXIHGWNTSjs.b.call(void 0, r)!==i?null:P()?N(t,i):null}catch (e20){return null}},flush:()=>x(),setEnabled(r){H=!!r,H||(p=[],E=[],w())},configure(r){try{(r.env==="live"||r.env==="test")&&(j=r.env),typeof r.endpoint=="string"&&r.endpoint&&(s=c(r.endpoint))}catch (e21){}},onEvent(r){return C.add(r),()=>void C.delete(r)},destroy(){p=[],E=[],w(),C.clear(),t.removeEventListener("pagehide",ie),document.removeEventListener("visibilitychange",ae),t.removeEventListener("bitsnap:consent",S),t.removeEventListener("bitsnap:consent:ready",S)}}}var v,O=null;function D(e){if(!v){let t=Xe(e);return t===y||(v=t,O=_chunkXIHGWNTSjs.b.call(void 0, _nullishCoalesce(e.projectKey, () => ("")))),t}try{let t=_chunkXIHGWNTSjs.b.call(void 0, _nullishCoalesce(e.projectKey, () => ("")));t!==O&&e.debug&&console.warn("[bitsnap analytics]","tracker already started for another projectKey, ignoring",e.projectKey),t===O&&((e.env||e.endpoint)&&v.configure({env:e.env,endpoint:e.endpoint}),e.enabled!=null&&v.setEnabled(e.enabled))}catch (e22){}return v}function Ae(){return v}function xt(){typeof window<"u"&&ge(window),_optionalChain([v, 'optionalAccess', _36 => _36.destroy, 'call', _37 => _37()]),v=void 0,O=null}function _t(e){try{if(typeof window>"u")return{};let t=v,n=null;if(t)n=t.clientId(e);else{let o=e?_chunkXIHGWNTSjs.b.call(void 0, e):null;n=o?N(window,o):null}return n?{[me]:n}:{}}catch (e23){return{}}}var _react = require('react');var nt={track:y.track,page:y.page},Pe=_react.createContext.call(void 0, nt);function St({projectKey:e,env:t,enabled:n,endpoint:o,onEvent:a,autoPageViews:i,children:c}){let s=_react.useMemo.call(void 0, ()=>D({projectKey:e,env:t,endpoint:o,enabled:n}),[e,t,o]),u=_react.useRef.call(void 0, a);u.current=a,_chunkXIHGWNTSjs.p.call(void 0, ()=>{s.setEnabled(n!==!1)},[s,n]),_chunkXIHGWNTSjs.p.call(void 0, ()=>{if(!(i===!1||n===!1||s===y))return A(()=>s.page(null))},[s,i,n]),_chunkXIHGWNTSjs.p.call(void 0, ()=>s.onEvent(b=>_optionalChain([u, 'access', _38 => _38.current, 'optionalCall', _39 => _39(b)])),[s]);let l=_react.useMemo.call(void 0, ()=>({track:s.track.bind(s),page:s.page.bind(s)}),[s]);return _react.createElement.call(void 0, Pe.Provider,{value:l},c)}function we(){return _react.useContext.call(void 0, Pe)}var $={track(){}},X=null;function lt(e){let t=Symbol("bitsnap-instrument");function n(){if(typeof window>"u")return null;let{projectKey:i,analytics:c,provided:s}=e();return c===!1?null:s||(i?D({projectKey:i,source:"sdk_react",channel:"embed",env:typeof c=="object"?c.env:void 0}):null)}let o={track(i,c,s){try{let u=n();if(!u)return;let{analytics:l,pageType:b}=e(),M=b&&_optionalChain([s, 'optionalAccess', _40 => _40.page_type])===void 0?{...s,page_type:b}:s;X=typeof l=="object"&&l.onEvent?t:null,u.track(i,c,M)}catch (e24){}finally{X=null}}};function a(){try{if(!n())return()=>{};let i=Ae();if(!i)return()=>{};let c=e().provided?()=>{}:A(()=>i.page(_nullishCoalesce(e().pageType, () => (null)))),s=i.onEvent(u=>{if(X===t)try{let{analytics:l}=e();typeof l=="object"&&_optionalChain([l, 'access', _41 => _41.onEvent, 'optionalCall', _42 => _42(u)])}catch (e25){}});return()=>{c(),s()}}catch (e26){return()=>{}}}return{instrument:o,attach:a}}var Z=_react.createContext.call(void 0, null);function Nt({value:e,children:t}){return _react.createElement.call(void 0, Z.Provider,{value:e},t)}function Ot(){return _nullishCoalesce(_react.useContext.call(void 0, Z), () => ($))}function Dt(e,t,n){let o=_react.useContext.call(void 0, Z),a=we(),i=a.track===y.track?null:a,c=_react.useRef.call(void 0, {projectKey:e,analytics:t,pageType:n,provided:i});c.current={projectKey:e,analytics:t,pageType:n,provided:i};let s=_react.useMemo.call(void 0, ()=>lt(()=>c.current),[]),u=t===void 0&&o!==null,l=typeof t=="object"&&!!t.onEvent;return _react.useLayoutEffect.call(void 0, ()=>{if(!u)return s.attach()},[s,u,l,e]),u?o:s.instrument}var Q=$;function Se(e){Q=_nullishCoalesce(e, () => ($))}var q=0;function $t(){return q>0?$:Q}async function Mt(e){q++;try{return await e()}finally{q--}}function jt(e){_react.useEffect.call(void 0, ()=>(Se(e),()=>{Q===e&&Se(null)}),[e])}function Ht(e){let t=Number.isFinite(e)?Math.max(0,Math.min(100,e)):0;return t>=100?"100":t>=75?"75-99":t>=50?"50-74":t>=25?"25-49":"0-24"}function Wt(e,t){let n=[];for(let o of[25,50,75,100])e>=o&&!t.has(o)&&(t.add(o),n.push(o));return n}exports.a = ve; exports.b = A; exports.c = Ue; exports.d = Xe; exports.e = D; exports.f = Ae; exports.g = xt; exports.h = _t; exports.i = St; exports.j = we; exports.k = $; exports.l = Nt; exports.m = Ot; exports.n = Dt; exports.o = $t; exports.p = Mt; exports.q = jt; exports.r = Ht; exports.s = Wt;
2
- //# sourceMappingURL=chunk-WGJTXDIS.js.map
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkXIHGWNTSjs = require('./chunk-XIHGWNTS.js');var Oe=Symbol.for("bitsnap.pageViews");function ye(e){let t=e;return t[Oe]??={path:null,starters:new Set,watching:!1}}function De(e,t){let n=()=>{try{t()}catch (e2){}};for(let o of["pushState","replaceState"]){let a=e.history[o];e.history[o]=function(...i){let c=a.apply(this,i);return n(),c}}e.addEventListener("popstate",n)}function A(e,t=window){try{let n=ye(t),o=()=>e();n.watching||(n.watching=!0,De(t,()=>{let i=t.location.pathname;i===n.path||n.starters.size===0||(n.path=i,_optionalChain([n, 'access', _2 => _2.starters, 'access', _3 => _3.values, 'call', _4 => _4(), 'access', _5 => _5.next, 'call', _6 => _6(), 'access', _7 => _7.value, 'optionalCall', _8 => _8()]))})),n.starters.add(o);let a=t.location.pathname;return a!==n.path&&(n.path=a,o()),()=>void n.starters.delete(o)}catch (e3){return()=>{}}}function ge(e=window){let t=ye(e);t.path=null,t.starters.clear()}var ve="1.12.0";function I(e){let t=new Uint8Array(e),n=typeof crypto<"u"?crypto:void 0;if(n&&typeof n.getRandomValues=="function")n.getRandomValues(t);else for(let o=0;o<e;o++)t[o]=Math.floor(Math.random()*256);return t}var me="X-Bitsnap-Visitor",$e=390*24*60*60,Me=/^[A-Za-z0-9_-]{22}$/;function R(e){return e.BitsnapConsent}function je(e,t){for(let n of e.cookie.split(";")){let o=n.indexOf("=");if(o!==-1&&n.slice(0,o).trim()===t)return n.slice(o+1).trim()}return null}function He(e){let t=e.toLowerCase();return t==="bitsnap.pl"||t.endsWith(".bitsnap.pl")}function F(e,t){try{let n=R(e);if(!n)return!1;if(n.scope==="project")return n.projectKey===t;let o=He(e.location.hostname);return n.scope==="global"?!o:!1}catch (e4){return!1}}function J(e,t){try{return _optionalChain([R, 'call', _9 => _9(e), 'optionalAccess', _10 => _10.get, 'call', _11 => _11(), 'optionalAccess', _12 => _12.c, 'access', _13 => _13.analytics])===!0&&F(e,t)}catch (e5){return!1}}function he(){let e="";return I(16).forEach(t=>e+=String.fromCharCode(t)),btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function Ee(e,t){try{return je(e,_chunkXIHGWNTSjs.f.call(void 0, t))}catch (e6){return null}}function B(e,t){let n=Ee(e,t);return n!==null&&Me.test(n)?n:null}function ke(e,t,n){try{let o=e.document,a=`${_chunkXIHGWNTSjs.f.call(void 0, t)}=${n}; Max-Age=${$e}; Path=/; SameSite=Lax`+(e.location.protocol==="https:"?"; Secure":"");for(let i of _chunkXIHGWNTSjs.n.call(void 0, e.location.hostname).reverse())if(o.cookie=`${a}; Domain=${i}`,B(o,t)===n)return;o.cookie=a}catch (e7){}}function be(e,t){try{let n=e.document;if(Ee(n,t)===null)return;let o=`${_chunkXIHGWNTSjs.f.call(void 0, t)}=; Max-Age=0; Path=/; SameSite=Lax`+(e.location.protocol==="https:"?"; Secure":"");n.cookie=o;for(let a of _chunkXIHGWNTSjs.n.call(void 0, e.location.hostname))n.cookie=`${o}; Domain=${a}`}catch (e8){}}function N(e,t){try{let n=e.navigator;return _optionalChain([n, 'optionalAccess', _14 => _14.globalPrivacyControl])===!0||_optionalChain([n, 'optionalAccess', _15 => _15.webdriver])===!0?null:J(e,t)?B(e.document,t):null}catch (e9){return null}}var Ue="https://collect.bitsnap.pl",Ke=5e3,Ge=20,Te=32*1024,ze=60*1024,xe=/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function _e(e){return typeof TextEncoder=="function"?new TextEncoder().encode(e).length:unescape(encodeURIComponent(e)).length}var y={track(){},page(){},clientId:()=>null,flush(){},setEnabled(){},onEvent:()=>()=>{},configure(){},destroy(){}};function Ye(e=Date.now()){let t=I(16),n=e;for(let a=5;a>=0;a--)t[a]=n%256,n=Math.floor(n/256);t[6]=t[6]&15|112,t[8]=t[8]&63|128;let o=Array.from(t,a=>a.toString(16).padStart(2,"0")).join("");return`${o.slice(0,8)}-${o.slice(8,12)}-${o.slice(12,16)}-${o.slice(16,20)}-${o.slice(20)}`}var Ce="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";function Fe(){return Array.from(I(16),e=>Ce[e%Ce.length]).join("")}function Je(e,t,n=!1){let o=_e(JSON.stringify({k:e,events:[]})),a=[],i=[],c=o,s=()=>{i.length>0&&a.push({body:JSON.stringify({k:e,events:i}),bytes:c,count:i.length}),i=[],c=o};for(let u of t){let l=_e(JSON.stringify(u));o+l>Te||((i.length>=_chunkXIHGWNTSjs.a.maxBatchEvents||c+l+(i.length>0?1:0)>Te)&&s(),c+=l+(i.length>0?1:0),i.push(u))}if(s(),n){let u=0,l=a.length;for(;l>0&&u+a[l-1].bytes<=ze;)u+=a[l-1].bytes,l--;a=a.slice(l)}return a}function Xe(e){try{return typeof window>"u"||typeof document>"u"?y:qe(e,window)}catch (e10){return y}}function qe(e,t){let n=_chunkXIHGWNTSjs.b.call(void 0, _nullishCoalesce(e.projectKey, () => (""))),o=!!e.debug,a=(...r)=>{o&&console.warn("[bitsnap analytics]",...r)};if(!n)return a("invalid projectKey, tracking is off"),y;let i=n,c=r=>`${(r||Ue).replace(/\/+$/,"")}/e`,s=c(e.endpoint),u=_nullishCoalesce(e.source, () => ("sdk_react")),l=_nullishCoalesce(e.channel, () => ("embed")),b=`bitsnap-react@${ve}`,M=Fe(),T=_chunkXIHGWNTSjs.d.call(void 0, t.location.href),j=_nullishCoalesce(e.env, () => ("live"));if(!e.env)try{new URLSearchParams(t.location.search).has("test")&&(j="test")}catch (e11){}let Le=_chunkXIHGWNTSjs.e.call(void 0, document.referrer),H=e.enabled!==!1,ee=null,Re=0,p=[],h=null,C=new Set;e.onEvent&&C.add(e.onEvent);let E=[],g,m=!0;function W(){let r=R(t);!r||r===g||(g=r,m=!r.ready,_optionalChain([r, 'access', _16 => _16.ready, 'optionalAccess', _17 => _17.then, 'call', _18 => _18(()=>{g===r&&(m=!0,re())},()=>{g===r&&(m=!0)})]))}function te(){W();try{if(!g)return!1;let r=g.get();return!!g.denied&&g.denied("analytics")||!!r&&r.c.analytics===!1}catch (e12){return!1}}function ne(r){C.forEach(f=>{try{f(r)}catch (e13){}})}function U(r){try{if(W(),!g||!F(t,i))return;J(t,i)?P()&&B(t.document,i)===null&&ke(t,i,he()):r&&be(t,i)}catch (e14){}}function re(){if(U(!0),te())p=[],E=[],w();else{if(m&&E.length>0){let r=E;E=[],r.forEach(ne)}p.length>0&&x()}}function P(){if(!H)return!1;let r=t.navigator;return r&&(r.globalPrivacyControl===!0||r.webdriver===!0)?!1:!te()}function w(){h!==null&&clearTimeout(h),h=null}function Be(){h===null&&(h=setTimeout(()=>{h=null,x()},Ke),_optionalChain([h, 'access', _19 => _19.unref, 'optionalCall', _20 => _20()]))}function Ne(r){try{if(typeof fetch=="function"){fetch(s,{method:"POST",body:r,keepalive:!0,credentials:"omit",headers:{"Content-Type":"text/plain"}}).catch(()=>{});return}}catch (e15){}try{let f=t.navigator;f&&typeof f.sendBeacon=="function"&&f.sendBeacon(s,new Blob([r],{type:"text/plain"}))}catch (e16){}}function x(r=!1){try{if(w(),p.length===0)return;if(!P()){p=[];return}if(!m)return;U(m);let f=N(t,i),d=f?p.map(k=>({...k,client_id:f})):p;p=[],Je(i,d,r).forEach(k=>Ne(k.body))}catch (e17){}}function oe(r,f,d){if(!P())return;let k=_chunkXIHGWNTSjs.g.call(void 0, r,f);if(!k.ok){a("dropped",r,k.reason);return}let se=_chunkXIHGWNTSjs.d.call(void 0, t.location.href),K={event_id:_optionalChain([d, 'optionalAccess', _21 => _21.event_id])&&xe.test(d.event_id)?d.event_id:Ye(),event:r,ts:Date.now(),schema_version:1,env:j,source:u,channel:l,sdk:b,page_id:M,page_type:_optionalChain([d, 'optionalAccess', _22 => _22.page_type])!==void 0?d.page_type:ee,host:_nullishCoalesce(_optionalChain([se, 'optionalAccess', _23 => _23.host]), () => (null)),path:_optionalChain([d, 'optionalAccess', _24 => _24.path])?_chunkXIHGWNTSjs.c.call(void 0, d.path.split(/[?#]/)[0]):_nullishCoalesce(_optionalChain([se, 'optionalAccess', _25 => _25.path]), () => (null)),referrer_host:Le,utm_source:_nullishCoalesce(_optionalChain([T, 'optionalAccess', _26 => _26.utm_source]), () => (null)),utm_medium:_nullishCoalesce(_optionalChain([T, 'optionalAccess', _27 => _27.utm_medium]), () => (null)),utm_campaign:_nullishCoalesce(_optionalChain([T, 'optionalAccess', _28 => _28.utm_campaign]), () => (null)),utm_content:_nullishCoalesce(_optionalChain([T, 'optionalAccess', _29 => _29.utm_content]), () => (null)),utm_term:_nullishCoalesce(_optionalChain([T, 'optionalAccess', _30 => _30.utm_term]), () => (null)),ref_code:_nullishCoalesce(_optionalChain([T, 'optionalAccess', _31 => _31.ref_code]), () => (null)),product_id:_nullishCoalesce(_optionalChain([d, 'optionalAccess', _32 => _32.product_id]), () => (null)),variant_id:_nullishCoalesce(_optionalChain([d, 'optionalAccess', _33 => _33.variant_id]), () => (null)),order_ref:_nullishCoalesce(_optionalChain([d, 'optionalAccess', _34 => _34.order_ref]), () => (null)),props:k.props};_optionalChain([d, 'optionalAccess', _35 => _35.event_id])&&!xe.test(d.event_id)&&a("ignored invalid event_id",r),u==="dashboard"&&e.visitorId&&(K.visitor_id=e.visitorId);let ce=_chunkXIHGWNTSjs.h.call(void 0, K);if(!ce.ok){a("dropped",r,ce.reason);return}let G=K;m?ne(G):E.push(G),p.push(G),p.length>=Ge?x():Be()}let ie=()=>x(!0),ae=()=>{document.visibilityState==="hidden"&&x(!0)},S=()=>re();return t.addEventListener("pagehide",ie),document.addEventListener("visibilitychange",ae),t.addEventListener("bitsnap:consent",S),t.addEventListener("bitsnap:consent:ready",S),W(),U(m),{track(r,f,d){try{oe(r,f,d)}catch (e18){}},page(r,f){try{r!==void 0&&(ee=r),oe("page_view",{landing:Re++===0},f)}catch (e19){}},clientId(r){try{return r!==void 0&&_chunkXIHGWNTSjs.b.call(void 0, r)!==i?null:P()?N(t,i):null}catch (e20){return null}},flush:()=>x(),setEnabled(r){H=!!r,H||(p=[],E=[],w())},configure(r){try{(r.env==="live"||r.env==="test")&&(j=r.env),typeof r.endpoint=="string"&&r.endpoint&&(s=c(r.endpoint))}catch (e21){}},onEvent(r){return C.add(r),()=>void C.delete(r)},destroy(){p=[],E=[],w(),C.clear(),t.removeEventListener("pagehide",ie),document.removeEventListener("visibilitychange",ae),t.removeEventListener("bitsnap:consent",S),t.removeEventListener("bitsnap:consent:ready",S)}}}var v,O=null;function D(e){if(!v){let t=Xe(e);return t===y||(v=t,O=_chunkXIHGWNTSjs.b.call(void 0, _nullishCoalesce(e.projectKey, () => ("")))),t}try{let t=_chunkXIHGWNTSjs.b.call(void 0, _nullishCoalesce(e.projectKey, () => ("")));t!==O&&e.debug&&console.warn("[bitsnap analytics]","tracker already started for another projectKey, ignoring",e.projectKey),t===O&&((e.env||e.endpoint)&&v.configure({env:e.env,endpoint:e.endpoint}),e.enabled!=null&&v.setEnabled(e.enabled))}catch (e22){}return v}function Ae(){return v}function xt(){typeof window<"u"&&ge(window),_optionalChain([v, 'optionalAccess', _36 => _36.destroy, 'call', _37 => _37()]),v=void 0,O=null}function _t(e){try{if(typeof window>"u")return{};let t=v,n=null;if(t)n=t.clientId(e);else{let o=e?_chunkXIHGWNTSjs.b.call(void 0, e):null;n=o?N(window,o):null}return n?{[me]:n}:{}}catch (e23){return{}}}var _react = require('react');var nt={track:y.track,page:y.page},Pe=_react.createContext.call(void 0, nt);function St({projectKey:e,env:t,enabled:n,endpoint:o,onEvent:a,autoPageViews:i,children:c}){let s=_react.useMemo.call(void 0, ()=>D({projectKey:e,env:t,endpoint:o,enabled:n}),[e,t,o]),u=_react.useRef.call(void 0, a);u.current=a,_chunkXIHGWNTSjs.p.call(void 0, ()=>{s.setEnabled(n!==!1)},[s,n]),_chunkXIHGWNTSjs.p.call(void 0, ()=>{if(!(i===!1||n===!1||s===y))return A(()=>s.page(null))},[s,i,n]),_chunkXIHGWNTSjs.p.call(void 0, ()=>s.onEvent(b=>_optionalChain([u, 'access', _38 => _38.current, 'optionalCall', _39 => _39(b)])),[s]);let l=_react.useMemo.call(void 0, ()=>({track:s.track.bind(s),page:s.page.bind(s)}),[s]);return _react.createElement.call(void 0, Pe.Provider,{value:l},c)}function we(){return _react.useContext.call(void 0, Pe)}var $={track(){}},X=null;function lt(e){let t=Symbol("bitsnap-instrument");function n(){if(typeof window>"u")return null;let{projectKey:i,analytics:c,provided:s}=e();return c===!1?null:s||(i?D({projectKey:i,source:"sdk_react",channel:"embed",env:typeof c=="object"?c.env:void 0}):null)}let o={track(i,c,s){try{let u=n();if(!u)return;let{analytics:l,pageType:b}=e(),M=b&&_optionalChain([s, 'optionalAccess', _40 => _40.page_type])===void 0?{...s,page_type:b}:s;X=typeof l=="object"&&l.onEvent?t:null,u.track(i,c,M)}catch (e24){}finally{X=null}}};function a(){try{if(!n())return()=>{};let i=Ae();if(!i)return()=>{};let c=e().provided?()=>{}:A(()=>i.page(_nullishCoalesce(e().pageType, () => (null)))),s=i.onEvent(u=>{if(X===t)try{let{analytics:l}=e();typeof l=="object"&&_optionalChain([l, 'access', _41 => _41.onEvent, 'optionalCall', _42 => _42(u)])}catch (e25){}});return()=>{c(),s()}}catch (e26){return()=>{}}}return{instrument:o,attach:a}}var Z=_react.createContext.call(void 0, null);function Nt({value:e,children:t}){return _react.createElement.call(void 0, Z.Provider,{value:e},t)}function Ot(){return _nullishCoalesce(_react.useContext.call(void 0, Z), () => ($))}function Dt(e,t,n){let o=_react.useContext.call(void 0, Z),a=we(),i=a.track===y.track?null:a,c=_react.useRef.call(void 0, {projectKey:e,analytics:t,pageType:n,provided:i});c.current={projectKey:e,analytics:t,pageType:n,provided:i};let s=_react.useMemo.call(void 0, ()=>lt(()=>c.current),[]),u=t===void 0&&o!==null,l=typeof t=="object"&&!!t.onEvent;return _react.useLayoutEffect.call(void 0, ()=>{if(!u)return s.attach()},[s,u,l,e]),u?o:s.instrument}var Q=$;function Se(e){Q=_nullishCoalesce(e, () => ($))}var q=0;function $t(){return q>0?$:Q}async function Mt(e){q++;try{return await e()}finally{q--}}function jt(e){_react.useEffect.call(void 0, ()=>(Se(e),()=>{Q===e&&Se(null)}),[e])}function Ht(e){let t=Number.isFinite(e)?Math.max(0,Math.min(100,e)):0;return t>=100?"100":t>=75?"75-99":t>=50?"50-74":t>=25?"25-49":"0-24"}function Wt(e,t){let n=[];for(let o of[25,50,75,100])e>=o&&!t.has(o)&&(t.add(o),n.push(o));return n}exports.a = ve; exports.b = A; exports.c = Ue; exports.d = Xe; exports.e = D; exports.f = Ae; exports.g = xt; exports.h = _t; exports.i = St; exports.j = we; exports.k = $; exports.l = Nt; exports.m = Ot; exports.n = Dt; exports.o = $t; exports.p = Mt; exports.q = jt; exports.r = Ht; exports.s = Wt;
2
+ //# sourceMappingURL=chunk-DF2IK2GN.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/emems/web/bitsnap/bitsnap/bitsnap-react/dist/chunk-WGJTXDIS.js","../src/analytics/pageviews.ts","../src/version.ts","../src/analytics/random.ts","../src/analytics/visitor.ts"],"names":["REGISTRY","registry","win","holder","watchNavigation","onChange","check","name","original","args","result","startAutoPageViews","send","reg","starter","path","resetAutoPageViews","SDK_VERSION","randomBytes","n","bytes","c","i","VISITOR_HEADER","MAX_AGE_SECONDS","VISITOR_ID_RE","consentApi","readCookie","doc","part","index","isBitsnapHost","hostname","host","consentBelongsTo","projectKey","api","onBitsnap","analyticsGranted","newVisitorId","binary","byte","rawVisitorCookie","clientIdCookieName","readVisitorCookie","value","writeVisitorCookie","id","base"],"mappings":"AAAA,uuBAA2G,ICYrGA,EAAAA,CAAW,MAAA,CAAO,GAAA,CAAI,mBAAmB,CAAA,CAE/C,SAASC,EAAAA,CAASC,CAAAA,CAAuB,CACvC,IAAMC,CAAAA,CAASD,CAAAA,CACf,OAAQC,CAAAA,CAAOH,EAAQ,CAAA,GAAM,CAAE,IAAA,CAAM,IAAA,CAAM,QAAA,CAAU,IAAI,GAAA,CAAO,QAAA,CAAU,CAAA,CAAM,CAClF,CAGA,SAASI,EAAAA,CAAgBF,CAAAA,CAAaG,CAAAA,CAAsB,CAC1D,IAAMC,CAAAA,CAAQ,CAAA,CAAA,EAAM,CAClB,GAAI,CACFD,CAAAA,CAAS,CACX,CAAA,UAAQ,CAAC,CACX,CAAA,CACA,GAAA,CAAA,IAAWE,EAAAA,EAAQ,CAAC,WAAA,CAAa,cAAc,CAAA,CAAY,CACzD,IAAMC,CAAAA,CAAWN,CAAAA,CAAI,OAAA,CAAQK,CAAI,CAAA,CACjCL,CAAAA,CAAI,OAAA,CAAQK,CAAI,CAAA,CAAI,QAAA,CAAA,GAA4BE,CAAAA,CAAwC,CACtF,IAAMC,CAAAA,CAASF,CAAAA,CAAS,KAAA,CAAM,IAAA,CAAMC,CAAI,CAAA,CACxC,OAAAH,CAAAA,CAAM,CAAA,CACCI,CACT,CACF,CACAR,CAAAA,CAAI,gBAAA,CAAiB,UAAA,CAAYI,CAAK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,OAAA,CAAQ,KAAA,CAAO,GAAG,CAAA,CAAE,OAAA,CAAQ,KAAA,CAAO,EAAE,CAC/E,CAGA,SAASE,EAAAA,CAAiBd,CAAAA,CAAeO,CAAAA,CAAmC,CAC1E,GAAI,CACF,OAAOR,EAAAA,CAAWC,CAAAA,CAAKe,gCAAAA,CAA6B,CAAC,CACvD,CAAA,UAAQ,CACN,OAAO,IACT,CACF,CAGO,SAASC,CAAAA,CAAkBhB,CAAAA,CAAeO,CAAAA,CAAmC,CAClF,IAAMU,CAAAA,CAAQH,EAAAA,CAAiBd,CAAAA,CAAKO,CAAU,CAAA,CAC9C,OAAOU,CAAAA,GAAU,IAAA,EAAQpB,EAAAA,CAAc,IAAA,CAAKoB,CAAK,CAAA,CAAIA,CAAAA,CAAQ,IAC/D,CAOO,SAASC,EAAAA,CAAmB5C,CAAAA,CAAaiC,CAAAA,CAAoBY,CAAAA,CAAkB,CACpF,GAAI,CACF,IAAMnB,CAAAA,CAAM1B,CAAAA,CAAI,QAAA,CACV8C,CAAAA,CACJ,CAAA,EAAA","file":"/home/emems/web/bitsnap/bitsnap/bitsnap-react/dist/chunk-WGJTXDIS.js","sourcesContent":[null,"/**\n * Page-wide state of the automatic page views. It lives on `window`, so the\n * npm package, a second copy of it and the `analytics.js` script agree on who\n * reports a path and the history is patched once.\n */\ntype Registry = {\n /** Last path some starter reported. */\n path: string | null;\n starters: Set<() => void>;\n watching: boolean;\n};\n\nconst REGISTRY = Symbol.for(\"bitsnap.pageViews\");\n\nfunction registry(win: Window): Registry {\n const holder = win as unknown as Record<symbol, Registry | undefined>;\n return (holder[REGISTRY] ??= { path: null, starters: new Set(), watching: false });\n}\n\n/** Calls `onChange` when the path changes through `history.pushState`/`replaceState` or Back/Forward. */\nfunction watchNavigation(win: Window, onChange: () => void) {\n const check = () => {\n try {\n onChange();\n } catch {}\n };\n for (const name of [\"pushState\", \"replaceState\"] as const) {\n const original = win.history[name];\n win.history[name] = function (this: History, ...args: Parameters<History[typeof name]>) {\n const result = original.apply(this, args);\n check();\n return result;\n };\n }\n win.addEventListener(\"popstate\", check);\n}\n\n/**\n * Calls `send` for the current path and again on every path change, unless\n * another starter on the page already reported that path: the page gets one\n * `page_view` per path change however many providers, components and embeds\n * start it. Returns the function that stops this starter.\n */\nexport function startAutoPageViews(send: () => void, win: Window = window): () => void {\n try {\n const reg = registry(win);\n const starter = () => send();\n if (!reg.watching) {\n reg.watching = true;\n watchNavigation(win, () => {\n const path = win.location.pathname;\n // Nobody listening: leave the path unreported so the next starter sends it.\n if (path === reg.path || reg.starters.size === 0) return;\n reg.path = path;\n reg.starters.values().next().value?.();\n });\n }\n reg.starters.add(starter);\n const path = win.location.pathname;\n if (path !== reg.path) {\n reg.path = path;\n starter();\n }\n return () => void reg.starters.delete(starter);\n } catch {\n return () => {};\n }\n}\n\n/** Forgets the reported path and the starters (tests, hot reload). The history patch stays. */\nexport function resetAutoPageViews(win: Window = window) {\n const reg = registry(win);\n reg.path = null;\n reg.starters.clear();\n}\n","// Generated by scripts/write-version.mjs from package.json. Do not edit.\nexport const SDK_VERSION = \"1.11.1\";\n","export function randomBytes(n: number): Uint8Array {\n const bytes = new Uint8Array(n);\n const c = typeof crypto !== \"undefined\" ? crypto : undefined;\n if (c && typeof c.getRandomValues === \"function\") c.getRandomValues(bytes);\n else for (let i = 0; i < n; i++) bytes[i] = Math.floor(Math.random() * 256);\n return bytes;\n}\n","import { domainCandidates } from \"../consent/core/cookie\";\nimport { clientIdCookieName } from \"./contract\";\nimport { randomBytes } from \"./random\";\n\n/** The part of `window.BitsnapConsent` (`bitsnap-react/consent`) the tracker reads. */\nexport type ConsentLike = {\n /** Absent on a consent script older than 1.9.0, which never counts as the project's banner. */\n scope?: \"global\" | \"project\";\n projectKey?: string | null;\n get(): { c: { analytics?: boolean } } | null;\n /** Also true for a refusal made on an older banner version, which `get()` no longer returns. */\n denied?(category: \"analytics\"): boolean;\n ready?: Promise<unknown>;\n};\n\n/** Sent to the Bitsnap server on the requests that create a checkout or payment link. */\nexport const VISITOR_HEADER = \"X-Bitsnap-Visitor\";\n// 390 days, under the 13 months CNIL allows. Set once, never extended.\nconst MAX_AGE_SECONDS = 390 * 24 * 60 * 60;\nconst VISITOR_ID_RE = /^[A-Za-z0-9_-]{22}$/;\n\nexport function consentApi(win: Window): ConsentLike | undefined {\n return (win as unknown as { BitsnapConsent?: ConsentLike }).BitsnapConsent;\n}\n\nfunction readCookie(doc: Document, name: string): string | null {\n for (const part of doc.cookie.split(\";\")) {\n const index = part.indexOf(\"=\");\n if (index !== -1 && part.slice(0, index).trim() === name) return part.slice(index + 1).trim();\n }\n return null;\n}\n\n/** bitsnap.pl and its subdomains: many merchants share them, and the site-wide choice is bitsnap's own. */\nfunction isBitsnapHost(hostname: string): boolean {\n const host = hostname.toLowerCase();\n return host === \"bitsnap.pl\" || host.endsWith(\".bitsnap.pl\");\n}\n\n/**\n * Whether the page's consent banner speaks for `projectKey`: a project-scope banner of that\n * key, or a site-scope banner on a merchant's own site. On bitsnap.pl a site-scope choice is\n * bitsnap's own, so only a project-scope one counts.\n */\nexport function consentBelongsTo(win: Window, projectKey: string): boolean {\n try {\n const api = consentApi(win);\n if (!api) return false;\n if (api.scope === \"project\") return api.projectKey === projectKey;\n const onBitsnap = isBitsnapHost(win.location.hostname);\n if (api.scope === \"global\") return !onBitsnap;\n // A consent script from before the scope info: it cannot be told apart from another project's banner.\n return false;\n } catch {\n return false;\n }\n}\n\n/** `true` only while a banner that speaks for `projectKey` holds a valid choice that grants `analytics`. */\nexport function analyticsGranted(win: Window, projectKey: string): boolean {\n try {\n return consentApi(win)?.get()?.c.analytics === true && consentBelongsTo(win, projectKey);\n } catch {\n return false;\n }\n}\n\n/** 16 random bytes as 22 base64url characters. */\nexport function newVisitorId(): string {\n let binary = \"\";\n randomBytes(16).forEach((byte) => (binary += String.fromCharCode(byte)));\n return btoa(binary).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n}\n\n/** Value of the `bs_vid_<projectKey>` cookie, whatever it holds; `null` when it is absent. */\nfunction rawVisitorCookie(doc: Document, projectKey: string): string | null {\n try {\n return readCookie(doc, clientIdCookieName(projectKey));\n } catch {\n return null;\n }\n}\n\n/** The project's client id from its first-party cookie (`bs_vid_<projectKey>`), or `null` if absent or malformed. */\nexport function readVisitorCookie(doc: Document, projectKey: string): string | null {\n const value = rawVisitorCookie(doc, projectKey);\n return value !== null && VISITOR_ID_RE.test(value) ? value : null;\n}\n\n/**\n * Sets the cookie on the widest registrable domain the browser accepts\n * (shortest suffix with two labels first, so `shop.example.co.uk` skips the\n * refused `co.uk`), host-only where no domain sticks (localhost, IP hosts).\n */\nexport function writeVisitorCookie(win: Window, projectKey: string, id: string): void {\n try {\n const doc = win.document;\n const base =\n `${clientIdCookieName(projectKey)}=${id}; Max-Age=${MAX_AGE_SECONDS}; Path=/; SameSite=Lax` +\n (win.location.protocol === \"https:\" ? \"; Secure\" : \"\");\n for (const domain of domainCandidates(win.location.hostname).reverse()) {\n doc.cookie = `${base}; Domain=${domain}`;\n if (readVisitorCookie(doc, projectKey) === id) return;\n }\n doc.cookie = base;\n } catch {\n // cookies blocked (sandboxed frame)\n }\n}\n\n/** Expires the cookie on the host and on every parent domain it may have been set on. */\nexport function deleteVisitorCookie(win: Window, projectKey: string): void {\n try {\n const doc = win.document;\n // Present under any value: a malformed one must go too.\n if (rawVisitorCookie(doc, projectKey) === null) return;\n const base =\n `${clientIdCookieName(projectKey)}=; Max-Age=0; Path=/; SameSite=Lax` +\n (win.location.protocol === \"https:\" ? \"; Secure\" : \"\");\n doc.cookie = base;\n for (const domain of domainCandidates(win.location.hostname)) doc.cookie = `${base}; Domain=${domain}`;\n } catch {\n // best effort\n }\n}\n\n/**\n * The project's client id to send, or `null`: analytics consent is granted,\n * Global Privacy Control is off, the browser is not automated and the cookie exists.\n */\nexport function readVisitorId(win: Window, projectKey: string): string | null {\n try {\n const nav = win.navigator as { globalPrivacyControl?: boolean; webdriver?: boolean } | undefined;\n if (nav?.globalPrivacyControl === true || nav?.webdriver === true) return null;\n return analyticsGranted(win, projectKey) ? readVisitorCookie(win.document, projectKey) : null;\n } catch {\n return null;\n }\n}\n"]}
1
+ {"version":3,"sources":["/home/emems/web/bitsnap/bitsnap/bitsnap-react/dist/chunk-DF2IK2GN.js","../src/analytics/pageviews.ts","../src/version.ts","../src/analytics/random.ts","../src/analytics/visitor.ts"],"names":["REGISTRY","registry","win","holder","watchNavigation","onChange","check","name","original","args","result","startAutoPageViews","send","reg","starter","path","resetAutoPageViews","SDK_VERSION","randomBytes","n","bytes","c","i","VISITOR_HEADER","MAX_AGE_SECONDS","VISITOR_ID_RE","consentApi","readCookie","doc","part","index","isBitsnapHost","hostname","host","consentBelongsTo","projectKey","api","onBitsnap","analyticsGranted","newVisitorId","binary","byte","rawVisitorCookie","clientIdCookieName","readVisitorCookie","value","writeVisitorCookie","id","base"],"mappings":"AAAA,uuBAA2G,ICYrGA,EAAAA,CAAW,MAAA,CAAO,GAAA,CAAI,mBAAmB,CAAA,CAE/C,SAASC,EAAAA,CAASC,CAAAA,CAAuB,CACvC,IAAMC,CAAAA,CAASD,CAAAA,CACf,OAAQC,CAAAA,CAAOH,EAAQ,CAAA,GAAM,CAAE,IAAA,CAAM,IAAA,CAAM,QAAA,CAAU,IAAI,GAAA,CAAO,QAAA,CAAU,CAAA,CAAM,CAClF,CAGA,SAASI,EAAAA,CAAgBF,CAAAA,CAAaG,CAAAA,CAAsB,CAC1D,IAAMC,CAAAA,CAAQ,CAAA,CAAA,EAAM,CAClB,GAAI,CACFD,CAAAA,CAAS,CACX,CAAA,UAAQ,CAAC,CACX,CAAA,CACA,GAAA,CAAA,IAAWE,EAAAA,EAAQ,CAAC,WAAA,CAAa,cAAc,CAAA,CAAY,CACzD,IAAMC,CAAAA,CAAWN,CAAAA,CAAI,OAAA,CAAQK,CAAI,CAAA,CACjCL,CAAAA,CAAI,OAAA,CAAQK,CAAI,CAAA,CAAI,QAAA,CAAA,GAA4BE,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AA,CAAY,EAAE,CAAA,CAAE,OAAA,CAASuB,CAAAA,EAAUD,CAAAA,EAAU,MAAA,CAAO,YAAA,CAAaC,CAAI,CAAE,CAAA,CAChE,IAAA,CAAKD,CAAM,CAAA,CAAE,OAAA,CAAQ,KAAA,CAAO,GAAG,CAAA,CAAE,OAAA,CAAQ,KAAA,CAAO,GAAG,CAAA,CAAE,OAAA,CAAQ,KAAA,CAAO,EAAE,CAC/E,CAGA,SAASE,EAAAA,CAAiBd,CAAAA,CAAeO,CAAAA,CAAmC,CAC1E,GAAI,CACF,OAAOR,EAAAA,CAAWC,CAAAA,CAAKe,gCAAAA,CAA6B,CAAC,CACvD,CAAA,UAAQ,CACN,OAAO,IACT,CACF,CAGO,SAASC,CAAAA,CAAkBhB,CAAAA,CAAeO,CAAAA,CAAmC,CAClF,IAAMU,CAAAA,CAAQH,EAAAA,CAAiBd,CAAAA,CAAKO,CAAU,CAAA,CAC9C,OAAOU,CAAAA,GAAU,IAAA,EAAQpB,EAAAA,CAAc,IAAA,CAAKoB,CAAK,CAAA,CAAIA,CAAAA,CAAQ,IAC/D,CAOO,SAASC,EAAAA,CAAmB5C,CAAAA,CAAaiC,CAAAA,CAAoBY,CAAAA,CAAkB,CACpF,GAAI,CACF,IAAMnB,CAAAA,CAAM1B,CAAAA,CAAI,QAAA,CACV8C,CAAAA,CACJ,CAAA,EAAA","file":"/home/emems/web/bitsnap/bitsnap/bitsnap-react/dist/chunk-DF2IK2GN.js","sourcesContent":[null,"/**\n * Page-wide state of the automatic page views. It lives on `window`, so the\n * npm package, a second copy of it and the `analytics.js` script agree on who\n * reports a path and the history is patched once.\n */\ntype Registry = {\n /** Last path some starter reported. */\n path: string | null;\n starters: Set<() => void>;\n watching: boolean;\n};\n\nconst REGISTRY = Symbol.for(\"bitsnap.pageViews\");\n\nfunction registry(win: Window): Registry {\n const holder = win as unknown as Record<symbol, Registry | undefined>;\n return (holder[REGISTRY] ??= { path: null, starters: new Set(), watching: false });\n}\n\n/** Calls `onChange` when the path changes through `history.pushState`/`replaceState` or Back/Forward. */\nfunction watchNavigation(win: Window, onChange: () => void) {\n const check = () => {\n try {\n onChange();\n } catch {}\n };\n for (const name of [\"pushState\", \"replaceState\"] as const) {\n const original = win.history[name];\n win.history[name] = function (this: History, ...args: Parameters<History[typeof name]>) {\n const result = original.apply(this, args);\n check();\n return result;\n };\n }\n win.addEventListener(\"popstate\", check);\n}\n\n/**\n * Calls `send` for the current path and again on every path change, unless\n * another starter on the page already reported that path: the page gets one\n * `page_view` per path change however many providers, components and embeds\n * start it. Returns the function that stops this starter.\n */\nexport function startAutoPageViews(send: () => void, win: Window = window): () => void {\n try {\n const reg = registry(win);\n const starter = () => send();\n if (!reg.watching) {\n reg.watching = true;\n watchNavigation(win, () => {\n const path = win.location.pathname;\n // Nobody listening: leave the path unreported so the next starter sends it.\n if (path === reg.path || reg.starters.size === 0) return;\n reg.path = path;\n reg.starters.values().next().value?.();\n });\n }\n reg.starters.add(starter);\n const path = win.location.pathname;\n if (path !== reg.path) {\n reg.path = path;\n starter();\n }\n return () => void reg.starters.delete(starter);\n } catch {\n return () => {};\n }\n}\n\n/** Forgets the reported path and the starters (tests, hot reload). The history patch stays. */\nexport function resetAutoPageViews(win: Window = window) {\n const reg = registry(win);\n reg.path = null;\n reg.starters.clear();\n}\n","// Generated by scripts/write-version.mjs from package.json. Do not edit.\nexport const SDK_VERSION = \"1.12.0\";\n","export function randomBytes(n: number): Uint8Array {\n const bytes = new Uint8Array(n);\n const c = typeof crypto !== \"undefined\" ? crypto : undefined;\n if (c && typeof c.getRandomValues === \"function\") c.getRandomValues(bytes);\n else for (let i = 0; i < n; i++) bytes[i] = Math.floor(Math.random() * 256);\n return bytes;\n}\n","import { domainCandidates } from \"../consent/core/cookie\";\nimport { clientIdCookieName } from \"./contract\";\nimport { randomBytes } from \"./random\";\n\n/** The part of `window.BitsnapConsent` (`bitsnap-react/consent`) the tracker reads. */\nexport type ConsentLike = {\n /** Absent on a consent script older than 1.9.0, which never counts as the project's banner. */\n scope?: \"global\" | \"project\";\n projectKey?: string | null;\n get(): { c: { analytics?: boolean } } | null;\n /** Also true for a refusal made on an older banner version, which `get()` no longer returns. */\n denied?(category: \"analytics\"): boolean;\n ready?: Promise<unknown>;\n};\n\n/** Sent to the Bitsnap server on the requests that create a checkout or payment link. */\nexport const VISITOR_HEADER = \"X-Bitsnap-Visitor\";\n// 390 days, under the 13 months CNIL allows. Set once, never extended.\nconst MAX_AGE_SECONDS = 390 * 24 * 60 * 60;\nconst VISITOR_ID_RE = /^[A-Za-z0-9_-]{22}$/;\n\nexport function consentApi(win: Window): ConsentLike | undefined {\n return (win as unknown as { BitsnapConsent?: ConsentLike }).BitsnapConsent;\n}\n\nfunction readCookie(doc: Document, name: string): string | null {\n for (const part of doc.cookie.split(\";\")) {\n const index = part.indexOf(\"=\");\n if (index !== -1 && part.slice(0, index).trim() === name) return part.slice(index + 1).trim();\n }\n return null;\n}\n\n/** bitsnap.pl and its subdomains: many merchants share them, and the site-wide choice is bitsnap's own. */\nfunction isBitsnapHost(hostname: string): boolean {\n const host = hostname.toLowerCase();\n return host === \"bitsnap.pl\" || host.endsWith(\".bitsnap.pl\");\n}\n\n/**\n * Whether the page's consent banner speaks for `projectKey`: a project-scope banner of that\n * key, or a site-scope banner on a merchant's own site. On bitsnap.pl a site-scope choice is\n * bitsnap's own, so only a project-scope one counts.\n */\nexport function consentBelongsTo(win: Window, projectKey: string): boolean {\n try {\n const api = consentApi(win);\n if (!api) return false;\n if (api.scope === \"project\") return api.projectKey === projectKey;\n const onBitsnap = isBitsnapHost(win.location.hostname);\n if (api.scope === \"global\") return !onBitsnap;\n // A consent script from before the scope info: it cannot be told apart from another project's banner.\n return false;\n } catch {\n return false;\n }\n}\n\n/** `true` only while a banner that speaks for `projectKey` holds a valid choice that grants `analytics`. */\nexport function analyticsGranted(win: Window, projectKey: string): boolean {\n try {\n return consentApi(win)?.get()?.c.analytics === true && consentBelongsTo(win, projectKey);\n } catch {\n return false;\n }\n}\n\n/** 16 random bytes as 22 base64url characters. */\nexport function newVisitorId(): string {\n let binary = \"\";\n randomBytes(16).forEach((byte) => (binary += String.fromCharCode(byte)));\n return btoa(binary).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n}\n\n/** Value of the `bs_vid_<projectKey>` cookie, whatever it holds; `null` when it is absent. */\nfunction rawVisitorCookie(doc: Document, projectKey: string): string | null {\n try {\n return readCookie(doc, clientIdCookieName(projectKey));\n } catch {\n return null;\n }\n}\n\n/** The project's client id from its first-party cookie (`bs_vid_<projectKey>`), or `null` if absent or malformed. */\nexport function readVisitorCookie(doc: Document, projectKey: string): string | null {\n const value = rawVisitorCookie(doc, projectKey);\n return value !== null && VISITOR_ID_RE.test(value) ? value : null;\n}\n\n/**\n * Sets the cookie on the widest registrable domain the browser accepts\n * (shortest suffix with two labels first, so `shop.example.co.uk` skips the\n * refused `co.uk`), host-only where no domain sticks (localhost, IP hosts).\n */\nexport function writeVisitorCookie(win: Window, projectKey: string, id: string): void {\n try {\n const doc = win.document;\n const base =\n `${clientIdCookieName(projectKey)}=${id}; Max-Age=${MAX_AGE_SECONDS}; Path=/; SameSite=Lax` +\n (win.location.protocol === \"https:\" ? \"; Secure\" : \"\");\n for (const domain of domainCandidates(win.location.hostname).reverse()) {\n doc.cookie = `${base}; Domain=${domain}`;\n if (readVisitorCookie(doc, projectKey) === id) return;\n }\n doc.cookie = base;\n } catch {\n // cookies blocked (sandboxed frame)\n }\n}\n\n/** Expires the cookie on the host and on every parent domain it may have been set on. */\nexport function deleteVisitorCookie(win: Window, projectKey: string): void {\n try {\n const doc = win.document;\n // Present under any value: a malformed one must go too.\n if (rawVisitorCookie(doc, projectKey) === null) return;\n const base =\n `${clientIdCookieName(projectKey)}=; Max-Age=0; Path=/; SameSite=Lax` +\n (win.location.protocol === \"https:\" ? \"; Secure\" : \"\");\n doc.cookie = base;\n for (const domain of domainCandidates(win.location.hostname)) doc.cookie = `${base}; Domain=${domain}`;\n } catch {\n // best effort\n }\n}\n\n/**\n * The project's client id to send, or `null`: analytics consent is granted,\n * Global Privacy Control is off, the browser is not automated and the cookie exists.\n */\nexport function readVisitorId(win: Window, projectKey: string): string | null {\n try {\n const nav = win.navigator as { globalPrivacyControl?: boolean; webdriver?: boolean } | undefined;\n if (nav?.globalPrivacyControl === true || nav?.webdriver === true) return null;\n return analyticsGranted(win, projectKey) ? readVisitorCookie(win.document, projectKey) : null;\n } catch {\n return null;\n }\n}\n"]}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _chunkUFIOJGJZjs = require('./chunk-UFIOJGJZ.js');var _chunkWGJTXDISjs = require('./chunk-WGJTXDIS.js');var t={projectID:void 0,loginURL:"/panel/login",theme:void 0,host:void 0,allowedReturnOrigins:[]},u=[];function w(e){t={...t,...e}}function s(){return t}function P(e){t.projectID=e}function v(e){t.theme=e}function C(e){t.loginURL=e}function R(e){t.host=e}function x(e){u=e,t={...t,allowedReturnOrigins:e}}function y(){return u}var _react = require('react');var _jsxruntime = require('react/jsx-runtime');var f=_react.createContext.call(void 0, s()),b= exports.i =({children:e,analytics:n})=>{let o=s(),i=_chunkWGJTXDISjs.n.call(void 0, o.projectID,n,"panel");return _jsxruntime.jsx.call(void 0, _chunkUFIOJGJZjs.o,{children:_jsxruntime.jsx.call(void 0, f.Provider,{value:{...o},children:_jsxruntime.jsx.call(void 0, _chunkWGJTXDISjs.l,{value:i,children:_jsxruntime.jsx.call(void 0, "div",{className:"bitsnap-react",children:e})})})})},L= exports.j =()=>_react.useContext.call(void 0, f);var l=(e,n)=>`bitsnap-panel-session:${encodeURIComponent(_nullishCoalesce(n, () => ("https://bitsnap.pl")))}:${encodeURIComponent(e)}`,a=(e,n)=>`bitsnap-panel-email:${encodeURIComponent(_nullishCoalesce(n, () => ("https://bitsnap.pl")))}:${encodeURIComponent(e)}`;function $(e,n){return typeof window>"u"||!e?void 0:_nullishCoalesce(window.localStorage.getItem(l(e,n)), () => (void 0))}function G(e,n,o,i){typeof window>"u"||!e||(window.localStorage.setItem(l(e,i),n),window.localStorage.setItem(a(e,i),o))}function k(e,n){return typeof window>"u"||!e?null:window.localStorage.getItem(a(e,n))}function E(e,n){typeof window>"u"||!e||(window.localStorage.removeItem(l(e,n)),window.localStorage.removeItem(a(e,n)))}exports.a = w; exports.b = s; exports.c = P; exports.d = v; exports.e = C; exports.f = R; exports.g = x; exports.h = y; exports.i = b; exports.j = L; exports.k = $; exports.l = G; exports.m = k; exports.n = E;
2
- //# sourceMappingURL=chunk-3IVLQILF.js.map
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _chunk6IACFTJRjs = require('./chunk-6IACFTJR.js');var _chunkDF2IK2GNjs = require('./chunk-DF2IK2GN.js');var t={projectID:void 0,loginURL:"/panel/login",theme:void 0,host:void 0,allowedReturnOrigins:[]},u=[];function w(e){t={...t,...e}}function s(){return t}function P(e){t.projectID=e}function v(e){t.theme=e}function C(e){t.loginURL=e}function R(e){t.host=e}function x(e){u=e,t={...t,allowedReturnOrigins:e}}function y(){return u}var _react = require('react');var _jsxruntime = require('react/jsx-runtime');var f=_react.createContext.call(void 0, s()),b= exports.i =({children:e,analytics:n})=>{let o=s(),i=_chunkDF2IK2GNjs.n.call(void 0, o.projectID,n,"panel");return _jsxruntime.jsx.call(void 0, _chunk6IACFTJRjs.o,{children:_jsxruntime.jsx.call(void 0, f.Provider,{value:{...o},children:_jsxruntime.jsx.call(void 0, _chunkDF2IK2GNjs.l,{value:i,children:_jsxruntime.jsx.call(void 0, "div",{className:"bitsnap-react",children:e})})})})},L= exports.j =()=>_react.useContext.call(void 0, f);var l=(e,n)=>`bitsnap-panel-session:${encodeURIComponent(_nullishCoalesce(n, () => ("https://bitsnap.pl")))}:${encodeURIComponent(e)}`,a=(e,n)=>`bitsnap-panel-email:${encodeURIComponent(_nullishCoalesce(n, () => ("https://bitsnap.pl")))}:${encodeURIComponent(e)}`;function $(e,n){return typeof window>"u"||!e?void 0:_nullishCoalesce(window.localStorage.getItem(l(e,n)), () => (void 0))}function G(e,n,o,i){typeof window>"u"||!e||(window.localStorage.setItem(l(e,i),n),window.localStorage.setItem(a(e,i),o))}function k(e,n){return typeof window>"u"||!e?null:window.localStorage.getItem(a(e,n))}function E(e,n){typeof window>"u"||!e||(window.localStorage.removeItem(l(e,n)),window.localStorage.removeItem(a(e,n)))}exports.a = w; exports.b = s; exports.c = P; exports.d = v; exports.e = C; exports.f = R; exports.g = x; exports.h = y; exports.i = b; exports.j = L; exports.k = $; exports.l = G; exports.m = k; exports.n = E;
2
+ //# sourceMappingURL=chunk-DGUIG334.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/emems/web/bitsnap/bitsnap/bitsnap-react/dist/chunk-3IVLQILF.js","../src/panel/config.ts","../src/panel/PanelProvider.tsx","../src/panel/session-storage.ts"],"names":["config","allowedReturnOrigins","setPanelConfig","newConfig","getPanelConfig","setProjectID","projectID","setTheme","theme","setLoginURL","loginURL","setHost","host","setAllowedReturnOrigins","origins","getAllowedReturnOrigins","PanelContext","createContext","PanelProvider","children","analytics","instrument","useInstrument","jsx","RpcProvider","InstrumentProvider","usePanelConfig","useContext","panelSessionKey"],"mappings":"AAAA,mOAAuC,sDAA+C,ICElFA,CAAAA,CAAsB,CACxB,SAAA,CAAW,KAAA,CAAA,CACX,QAAA,CAAU,cAAA,CACV,KAAA,CAAO,KAAA,CAAA,CACP,IAAA,CAAM,KAAA,CAAA,CACN,oBAAA,CAAsB,CAAC,CACzB,CAAA,CAEIC,CAAAA,CAAiC,CAAC,CAAA,CAU/B,SAASC,CAAAA,CAAeC,CAAAA,CAAuC,CACpEH,CAAAA,CAAS,CAAE,GAAGA,CAAAA,CAAQ,GAAGG,CAAU,CACrC,CAEO,SAASC,CAAAA,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A,aAAiB,CAAA,CAAA,EAAMC,+BAAAA,CAAuB,CAAA,CClC3D,IAAMC,CAAAA,CAAkB,CAACtB,CAAAA,CAAmBM,CAAAA,CAAAA,EAC1C,CAAA,sBAAA,EAAyB,kBAAA,kBAAmBA,CAAAA,SAAQ,sBAAoB,CAAC,CAAA,CAAA,EAAI,kBAAA,CAAmBN,CAAS,CAAC,CAAA,CAAA","file":"/home/emems/web/bitsnap/bitsnap/bitsnap-react/dist/chunk-3IVLQILF.js","sourcesContent":[null,"import type { GetThemeOutput } from \"./types\";\n\nlet config: PanelConfig = {\n projectID: undefined,\n loginURL: \"/panel/login\",\n theme: undefined,\n host: undefined,\n allowedReturnOrigins: [],\n};\n\nlet allowedReturnOrigins: string[] = [];\n\nexport interface PanelConfig {\n projectID?: string;\n loginURL?: string;\n theme?: GetThemeOutput;\n host?: string;\n allowedReturnOrigins: string[];\n}\n\nexport function setPanelConfig(newConfig: Partial<PanelConfig>): void {\n config = { ...config, ...newConfig };\n}\n\nexport function getPanelConfig(): PanelConfig {\n return config;\n}\n\nexport function setProjectID(projectID: string): void {\n config.projectID = projectID;\n}\n\nexport function setTheme(theme: GetThemeOutput): void {\n config.theme = theme;\n}\n\nexport function setLoginURL(loginURL: string): void {\n config.loginURL = loginURL;\n}\n\nexport function setHost(host: string): void {\n config.host = host;\n}\n\nexport function setAllowedReturnOrigins(origins: string[]): void {\n allowedReturnOrigins = origins;\n config = { ...config, allowedReturnOrigins: origins };\n}\n\nexport function getAllowedReturnOrigins(): string[] {\n return allowedReturnOrigins;\n}\n","import { createContext, useContext } from \"react\";\nimport {\n InstrumentProvider,\n useInstrument,\n type AnalyticsOption,\n} from \"../analytics/instrument\";\nimport { RpcProvider } from \"../rpc-provider\";\nimport { getPanelConfig, type PanelConfig } from \"./config\";\n\nconst PanelContext = createContext<PanelConfig>(getPanelConfig());\n\nexport const PanelProvider: React.FC<{\n children: React.ReactNode;\n /**\n * Usage statistics for your Bitsnap dashboard (panel logins, orders viewed,\n * downloads, course progress). On by default; `false` turns it off. An\n * object lets you forward every event: `{ onEvent }`. Nothing is stored on\n * the visitor's device.\n */\n analytics?: AnalyticsOption;\n}> = ({ children, analytics }) => {\n const config = getPanelConfig();\n const instrument = useInstrument(config.projectID, analytics, \"panel\");\n return (\n <RpcProvider>\n <PanelContext.Provider value={{ ...config }}>\n <InstrumentProvider value={instrument}>\n <div className=\"bitsnap-react\">{children}</div>\n </InstrumentProvider>\n </PanelContext.Provider>\n </RpcProvider>\n );\n};\n\nexport const usePanelConfig = () => useContext(PanelContext);\n","const panelSessionKey = (projectID: string, host?: string) =>\n `bitsnap-panel-session:${encodeURIComponent(host ?? \"https://bitsnap.pl\")}:${encodeURIComponent(projectID)}`;\n\nconst panelEmailKey = (projectID: string, host?: string) =>\n `bitsnap-panel-email:${encodeURIComponent(host ?? \"https://bitsnap.pl\")}:${encodeURIComponent(projectID)}`;\n\nexport function getPanelSession(projectID?: string, host?: string) {\n if (typeof window === \"undefined\" || !projectID) return undefined;\n const token = window.localStorage.getItem(panelSessionKey(projectID, host));\n return token ?? undefined;\n}\n\nexport function savePanelSession(projectID: string | undefined, token: string, email: string, host?: string) {\n if (typeof window === \"undefined\" || !projectID) return;\n window.localStorage.setItem(panelSessionKey(projectID, host), token);\n window.localStorage.setItem(panelEmailKey(projectID, host), email);\n}\n\nexport function getPanelEmail(projectID?: string, host?: string) {\n if (typeof window === \"undefined\" || !projectID) return null;\n return window.localStorage.getItem(panelEmailKey(projectID, host));\n}\n\nexport function clearPanelSession(projectID?: string, host?: string) {\n if (typeof window === \"undefined\" || !projectID) return;\n window.localStorage.removeItem(panelSessionKey(projectID, host));\n window.localStorage.removeItem(panelEmailKey(projectID, host));\n}\n"]}
1
+ {"version":3,"sources":["/home/emems/web/bitsnap/bitsnap/bitsnap-react/dist/chunk-DGUIG334.js","../src/panel/config.ts","../src/panel/PanelProvider.tsx","../src/panel/session-storage.ts"],"names":["config","allowedReturnOrigins","setPanelConfig","newConfig","getPanelConfig","setProjectID","projectID","setTheme","theme","setLoginURL","loginURL","setHost","host","setAllowedReturnOrigins","origins","getAllowedReturnOrigins","PanelContext","createContext","PanelProvider","children","analytics","instrument","useInstrument","jsx","RpcProvider","InstrumentProvider","usePanelConfig","useContext","panelSessionKey"],"mappings":"AAAA,mOAAuC,sDAA+C,ICElFA,CAAAA,CAAsB,CACxB,SAAA,CAAW,KAAA,CAAA,CACX,QAAA,CAAU,cAAA,CACV,KAAA,CAAO,KAAA,CAAA,CACP,IAAA,CAAM,KAAA,CAAA,CACN,oBAAA,CAAsB,CAAC,CACzB,CAAA,CAEIC,CAAAA,CAAiC,CAAC,CAAA,CAU/B,SAASC,CAAAA,CAAeC,CAAAA,CAAuC,CACpEH,CAAAA,CAAS,CAAE,GAAGA,CAAAA,CAAQ,GAAGG,CAAU,CACrC,CAEO,SAASC,CAAAA,CAAAA,CAA8B,CAC5C,OAAOJ,CACT,CAEO,SAASK,CAAAA,CAAaC,CAAAA,CAAyB,CACpDN,CAAAA,CAAO,SAAA,CAAYM,CACrB,CAEO,SAASC,CAAAA,CAASC,CAAAA,CAA6B,CACpDR,CAAAA,CAAO,KAAA,CAAQQ,CACjB,CAEO,SAASC,CAAAA,CAAYC,CAAAA,CAAwB,CAClDV,CAAAA,CAAO,QAAA,CAAWU,CACpB,CAEO,SAASC,CAAAA,CAAQC,CAAAA,CAAoB,CAC1CZ,CAAAA,CAAO,IAAA,CAAOY,CAChB,CAEO,SAASC,CAAAA,CAAwBC,CAAAA,CAAyB,CAC/Db,CAAAA,CAAuBa,CAAAA,CACvBd,CAAAA,CAAS,CAAE,GAAGA,CAAAA,CAAQ,oBAAA,CAAsBc,CAAQ,CACtD,CAEO,SAASC,CAAAA,CAAAA,CAAoC,CAClD,OAAOd,CACT,CCnDA,8BAA0C,+CA2BhC,IAlBJe,CAAAA,CAAeC,kCAAAA,CAA2Bb,CAAe,CAAC,CAAA,CAEnDc,CAAAA,aASR,CAAC,CAAE,QAAA,CAAAC,CAAAA,CAAU,SAAA,CAAAC,CAAU,CAAA,CAAA,EAAM,CAChC,IAAMpB,CAAAA,CAASI,CAAAA,CAAe,CAAA,CACxBiB,CAAAA,CAAaC,gCAAAA,CAActB,CAAO,SAAA,CAAWoB,CAAAA,CAAW,OAAO,CAAA,CACrE,OACEG,6BAAAA,kBAACC,CAAA,CACC,QAAA,CAAAD,6BAAAA,CAACP,CAAa,QAAA,CAAb,CAAsB,KAAA,CAAO,CAAE,GAAGhB,CAAO,CAAA,CACxC,QAAA,CAAAuB,6BAAAA,kBAACE,CAAA,CAAmB,KAAA,CAAOJ,CAAAA,CACzB,QAAA,CAAAE,6BAAAA,KAAC,CAAA,CAAI,SAAA,CAAU,eAAA,CAAiB,QAAA,CAAAJ,CAAAA,CAAS,CAAA,CAC3C,CAAA,CACF,CAAA,CACF,CAEJ,CAAA,CAEaO,CAAAA,aAAiB,CAAA,CAAA,EAAMC,+BAAAA,CAAuB,CAAA,CClC3D,IAAMC,CAAAA,CAAkB,CAACtB,CAAAA,CAAmBM,CAAAA,CAAAA,EAC1C,CAAA,sBAAA,EAAyB,kBAAA,kBAAmBA,CAAAA,SAAQ,sBAAoB,CAAC,CAAA,CAAA,EAAI,kBAAA,CAAmBN,CAAS,CAAC,CAAA,CAAA","file":"/home/emems/web/bitsnap/bitsnap/bitsnap-react/dist/chunk-DGUIG334.js","sourcesContent":[null,"import type { GetThemeOutput } from \"./types\";\n\nlet config: PanelConfig = {\n projectID: undefined,\n loginURL: \"/panel/login\",\n theme: undefined,\n host: undefined,\n allowedReturnOrigins: [],\n};\n\nlet allowedReturnOrigins: string[] = [];\n\nexport interface PanelConfig {\n projectID?: string;\n loginURL?: string;\n theme?: GetThemeOutput;\n host?: string;\n allowedReturnOrigins: string[];\n}\n\nexport function setPanelConfig(newConfig: Partial<PanelConfig>): void {\n config = { ...config, ...newConfig };\n}\n\nexport function getPanelConfig(): PanelConfig {\n return config;\n}\n\nexport function setProjectID(projectID: string): void {\n config.projectID = projectID;\n}\n\nexport function setTheme(theme: GetThemeOutput): void {\n config.theme = theme;\n}\n\nexport function setLoginURL(loginURL: string): void {\n config.loginURL = loginURL;\n}\n\nexport function setHost(host: string): void {\n config.host = host;\n}\n\nexport function setAllowedReturnOrigins(origins: string[]): void {\n allowedReturnOrigins = origins;\n config = { ...config, allowedReturnOrigins: origins };\n}\n\nexport function getAllowedReturnOrigins(): string[] {\n return allowedReturnOrigins;\n}\n","import { createContext, useContext } from \"react\";\nimport {\n InstrumentProvider,\n useInstrument,\n type AnalyticsOption,\n} from \"../analytics/instrument\";\nimport { RpcProvider } from \"../rpc-provider\";\nimport { getPanelConfig, type PanelConfig } from \"./config\";\n\nconst PanelContext = createContext<PanelConfig>(getPanelConfig());\n\nexport const PanelProvider: React.FC<{\n children: React.ReactNode;\n /**\n * Usage statistics for your Bitsnap dashboard (panel logins, orders viewed,\n * downloads, course progress). On by default; `false` turns it off. An\n * object lets you forward every event: `{ onEvent }`. Nothing is stored on\n * the visitor's device.\n */\n analytics?: AnalyticsOption;\n}> = ({ children, analytics }) => {\n const config = getPanelConfig();\n const instrument = useInstrument(config.projectID, analytics, \"panel\");\n return (\n <RpcProvider>\n <PanelContext.Provider value={{ ...config }}>\n <InstrumentProvider value={instrument}>\n <div className=\"bitsnap-react\">{children}</div>\n </InstrumentProvider>\n </PanelContext.Provider>\n </RpcProvider>\n );\n};\n\nexport const usePanelConfig = () => useContext(PanelContext);\n","const panelSessionKey = (projectID: string, host?: string) =>\n `bitsnap-panel-session:${encodeURIComponent(host ?? \"https://bitsnap.pl\")}:${encodeURIComponent(projectID)}`;\n\nconst panelEmailKey = (projectID: string, host?: string) =>\n `bitsnap-panel-email:${encodeURIComponent(host ?? \"https://bitsnap.pl\")}:${encodeURIComponent(projectID)}`;\n\nexport function getPanelSession(projectID?: string, host?: string) {\n if (typeof window === \"undefined\" || !projectID) return undefined;\n const token = window.localStorage.getItem(panelSessionKey(projectID, host));\n return token ?? undefined;\n}\n\nexport function savePanelSession(projectID: string | undefined, token: string, email: string, host?: string) {\n if (typeof window === \"undefined\" || !projectID) return;\n window.localStorage.setItem(panelSessionKey(projectID, host), token);\n window.localStorage.setItem(panelEmailKey(projectID, host), email);\n}\n\nexport function getPanelEmail(projectID?: string, host?: string) {\n if (typeof window === \"undefined\" || !projectID) return null;\n return window.localStorage.getItem(panelEmailKey(projectID, host));\n}\n\nexport function clearPanelSession(projectID?: string, host?: string) {\n if (typeof window === \"undefined\" || !projectID) return;\n window.localStorage.removeItem(panelSessionKey(projectID, host));\n window.localStorage.removeItem(panelEmailKey(projectID, host));\n}\n"]}
@@ -1,2 +1,2 @@
1
- import{A as N,f as m,i,j as d,k as R,s as c,t as E,u as p,v as S,w as l,x as y,y as I,z as T}from"./chunk-HWQNT6XU.mjs";import{d as a}from"./chunk-G2UOTVS5.mjs";var B=["orders","order","confirmation","result","myReturns","myReturn"];function P(e){return B.includes(e)}function f(e){return e?{name:"orders"}:{name:"email"}}function C(e,n){switch(n.type){case"SESSION_EXPIRED":return P(e.name)?{name:"email"}:e;case"CODE_SENT":return e.name==="email"?{name:"code"}:e;case"AUTHENTICATED":return e.name==="email"||e.name==="code"?{name:"orders"}:e;case"SELECT_ORDER":return e.name==="orders"?{name:"order",orderId:n.orderId}:e;case"REVIEW":return e.name==="order"?{name:"confirmation",orderId:e.orderId,items:n.items,note:n.note}:e;case"SUBMITTED":return e.name==="confirmation"?{name:"result",returnId:n.returnId}:e;case"OPEN_MY_RETURNS":return e.name==="orders"||e.name==="result"?{name:"myReturns"}:e;case"SELECT_RETURN":return e.name==="myReturns"?{name:"myReturn",returnId:n.returnId}:e;case"CONTINUE":return e.name==="result"?{name:"orders"}:e;case"BACK":switch(e.name){case"code":return{name:"email"};case"order":case"myReturns":return{name:"orders"};case"confirmation":return{name:"order",orderId:e.orderId,items:e.items,note:e.note};case"myReturn":return{name:"myReturns"};default:return e}}}var x={email:1,code:2,orders:3,order:4,confirmation:5,result:6},_=6;function O(e){return x[e]}import{useEffect as D,useReducer as A}from"react";import{jsx as o,jsxs as L}from"react/jsx-runtime";function g({current:e}){let n=i(),r=m("stepIndicator");return o("p",{"data-bitsnap-returns-slot":"stepIndicator",className:a("text-xs",r.className),style:r.style,children:n("stepIndicator",{current:e,total:_})})}function b({panelToken:e}){let{status:n}=d("BitsnapReturns"),[r,t]=A(C,f(!1));if(D(()=>{n==="authenticated"?t({type:"AUTHENTICATED"}):n==="anonymous"&&t({type:"SESSION_EXPIRED"})},[n]),n==="exchanging"||n==="hydrating"&&e)return o(c,{});let s=O(r.name);return L("div",{className:"flex flex-col gap-4",children:[s!=null&&o(g,{current:s}),r.name==="email"&&o(E,{onSubmitted:()=>t({type:"CODE_SENT"})}),r.name==="code"&&o(p,{onVerified:()=>t({type:"AUTHENTICATED"}),onBack:()=>t({type:"BACK"})}),r.name==="orders"&&o(S,{showLogout:!e,onSelectOrder:u=>t({type:"SELECT_ORDER",orderId:u}),onOpenMyReturns:()=>t({type:"OPEN_MY_RETURNS"})}),r.name==="order"&&o(l,{orderId:r.orderId,initialItems:r.items,initialNote:r.note,onBack:()=>t({type:"BACK"}),onContinue:({items:u,note:U})=>t({type:"REVIEW",items:u,note:U})}),r.name==="confirmation"&&o(y,{orderId:r.orderId,items:r.items,note:r.note,onBack:()=>t({type:"BACK"}),onSubmitted:u=>t({type:"SUBMITTED",returnId:u})}),r.name==="result"&&o(I,{returnId:r.returnId,onContinue:()=>t({type:"CONTINUE"}),onOpenMyReturns:()=>t({type:"OPEN_MY_RETURNS"})}),r.name==="myReturns"&&o(T,{onSelectReturn:u=>t({type:"SELECT_RETURN",returnId:u}),onBack:()=>t({type:"BACK"})}),r.name==="myReturn"&&o(N,{returnId:r.returnId,onBack:()=>t({type:"BACK"})})]})}function q(e){return o(R,{...e,children:o(b,{panelToken:e.panelAccessToken!=null&&e.panelAccessToken!==""})})}export{q as a};
2
- //# sourceMappingURL=chunk-JUDR4EZA.mjs.map
1
+ import{A as N,f as m,i,j as d,k as R,s as c,t as E,u as p,v as S,w as l,x as y,y as I,z as T}from"./chunk-5R3WR22A.mjs";import{d as a}from"./chunk-P4Q5KXKS.mjs";var B=["orders","order","confirmation","result","myReturns","myReturn"];function P(e){return B.includes(e)}function f(e){return e?{name:"orders"}:{name:"email"}}function C(e,n){switch(n.type){case"SESSION_EXPIRED":return P(e.name)?{name:"email"}:e;case"CODE_SENT":return e.name==="email"?{name:"code"}:e;case"AUTHENTICATED":return e.name==="email"||e.name==="code"?{name:"orders"}:e;case"SELECT_ORDER":return e.name==="orders"?{name:"order",orderId:n.orderId}:e;case"REVIEW":return e.name==="order"?{name:"confirmation",orderId:e.orderId,items:n.items,note:n.note}:e;case"SUBMITTED":return e.name==="confirmation"?{name:"result",returnId:n.returnId}:e;case"OPEN_MY_RETURNS":return e.name==="orders"||e.name==="result"?{name:"myReturns"}:e;case"SELECT_RETURN":return e.name==="myReturns"?{name:"myReturn",returnId:n.returnId}:e;case"CONTINUE":return e.name==="result"?{name:"orders"}:e;case"BACK":switch(e.name){case"code":return{name:"email"};case"order":case"myReturns":return{name:"orders"};case"confirmation":return{name:"order",orderId:e.orderId,items:e.items,note:e.note};case"myReturn":return{name:"myReturns"};default:return e}}}var x={email:1,code:2,orders:3,order:4,confirmation:5,result:6},_=6;function O(e){return x[e]}import{useEffect as D,useReducer as A}from"react";import{jsx as o,jsxs as L}from"react/jsx-runtime";function g({current:e}){let n=i(),r=m("stepIndicator");return o("p",{"data-bitsnap-returns-slot":"stepIndicator",className:a("text-xs",r.className),style:r.style,children:n("stepIndicator",{current:e,total:_})})}function b({panelToken:e}){let{status:n}=d("BitsnapReturns"),[r,t]=A(C,f(!1));if(D(()=>{n==="authenticated"?t({type:"AUTHENTICATED"}):n==="anonymous"&&t({type:"SESSION_EXPIRED"})},[n]),n==="exchanging"||n==="hydrating"&&e)return o(c,{});let s=O(r.name);return L("div",{className:"flex flex-col gap-4",children:[s!=null&&o(g,{current:s}),r.name==="email"&&o(E,{onSubmitted:()=>t({type:"CODE_SENT"})}),r.name==="code"&&o(p,{onVerified:()=>t({type:"AUTHENTICATED"}),onBack:()=>t({type:"BACK"})}),r.name==="orders"&&o(S,{showLogout:!e,onSelectOrder:u=>t({type:"SELECT_ORDER",orderId:u}),onOpenMyReturns:()=>t({type:"OPEN_MY_RETURNS"})}),r.name==="order"&&o(l,{orderId:r.orderId,initialItems:r.items,initialNote:r.note,onBack:()=>t({type:"BACK"}),onContinue:({items:u,note:U})=>t({type:"REVIEW",items:u,note:U})}),r.name==="confirmation"&&o(y,{orderId:r.orderId,items:r.items,note:r.note,onBack:()=>t({type:"BACK"}),onSubmitted:u=>t({type:"SUBMITTED",returnId:u})}),r.name==="result"&&o(I,{returnId:r.returnId,onContinue:()=>t({type:"CONTINUE"}),onOpenMyReturns:()=>t({type:"OPEN_MY_RETURNS"})}),r.name==="myReturns"&&o(T,{onSelectReturn:u=>t({type:"SELECT_RETURN",returnId:u}),onBack:()=>t({type:"BACK"})}),r.name==="myReturn"&&o(N,{returnId:r.returnId,onBack:()=>t({type:"BACK"})})]})}function q(e){return o(R,{...e,children:o(b,{panelToken:e.panelAccessToken!=null&&e.panelAccessToken!==""})})}export{q as a};
2
+ //# sourceMappingURL=chunk-E5DCEFI2.mjs.map
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkDF2IK2GNjs = require('./chunk-DF2IK2GN.js');var u="X-Bitsnap-Client",i=`bitsnap-react@${_chunkDF2IK2GNjs.a}`,d="bs_client",b= exports.a ={[u]:i},z= exports.b =e=>t=>(t.header.set(u,i),e(t));function j(e){let t=e.indexOf("#"),n=t===-1?e:e.slice(0,t),a=t===-1?"":e.slice(t),o=n.includes("?")?/[?&]$/.test(n)?"":"&":"?";return`${n}${o}${d}=${encodeURIComponent(i)}${a}`}var g="https://bitsnap.pl",x= exports.f =g;function K(e){console.log("setCustomHost",e),x= exports.f =e}function T(e,t){return t.toLowerCase().startsWith("en")?e.en:e.pl}function k(e,t){let n={...e};if(t!=null)for(let[a,o]of Object.entries(t))o!=null&&(n[a]=o);return n}function l(e,t,n){return k(T(e,t),n)}function y(e,t){return _nullishCoalesce(e[t], () => (t))}var C={en:{cart:"Cart",emptyCart:"Your cart is empty.",total:"Total:",delivery:"+ delivery",chooseCountry:"Choose a country",nextStep:"Next step",unavailableProducts:"Not all products are available.",checkoutFailed:"Something went wrong. Please try again later.",noPaymentGateway:"This shop doesn't accept online payments yet. Try again later or contact the seller.",gatewayNotConfigured:"Payments in this shop are not set up correctly. Try again later or contact the seller.",shippingNotConfigured:"Delivery in this shop is not configured yet. Try again later or contact the seller.",mixedRecurring:"Subscriptions and one-time products cannot be paid for together. Pay for them in separate orders.",currencyUnsupported:"The shop doesn't accept payments in this currency. Contact the seller.",priceChanged:"The product price has changed. Refresh the page to see the current price.",close:"Close cart",remove:"Remove",quantity:"Quantity",increaseQuantity:"Increase quantity",decreaseQuantity:"Decrease quantity",openCart:"Open cart",cartItemsCount:"Items in cart",lowestPrice30Days:"Lowest price in the last 30 days:",noPriceHistory:"No price data for the last 30 days",redirectFailed:"Could not redirect to the payment. Please try again later.",subscriptionUnsupported:"Subscriptions cannot be added to the cart yet.",searchCountry:"Find a country",noCountriesFound:"No countries found",countryRequired:"Choose a country to continue.",paymentForCart:"Cart payment",coupon:"Coupon",extrasCalculatedNext:"Discounts, shipping and taxes are calculated at the next step",loadFailed:"Could not load your cart.",retry:"Try again"},pl:{cart:"Koszyk",emptyCart:"Brak produkt\xF3w w koszyku.",total:"Suma:",delivery:"+ dostawa",chooseCountry:"Wybierz kraj",nextStep:"Nast\u0119pny krok",unavailableProducts:"Nie wszystkie produkty s\u0105 dost\u0119pne w magazynie.",checkoutFailed:"Co\u015B posz\u0142o nie tak. Spr\xF3buj ponownie p\xF3\u017Aniej.",noPaymentGateway:"Ten sklep nie przyjmuje jeszcze p\u0142atno\u015Bci online. Spr\xF3buj ponownie p\xF3\u017Aniej lub skontaktuj si\u0119 ze sprzedawc\u0105.",gatewayNotConfigured:"P\u0142atno\u015Bci w tym sklepie nie s\u0105 poprawnie skonfigurowane. Spr\xF3buj ponownie p\xF3\u017Aniej lub skontaktuj si\u0119 ze sprzedawc\u0105.",shippingNotConfigured:"Dostawa w tym sklepie nie jest jeszcze skonfigurowana. Spr\xF3buj ponownie p\xF3\u017Aniej lub skontaktuj si\u0119 ze sprzedawc\u0105.",mixedRecurring:"Subskrypcji i produkt\xF3w jednorazowych nie mo\u017Cna op\u0142aci\u0107 razem. Op\u0142a\u0107 je w osobnych zam\xF3wieniach.",currencyUnsupported:"Sklep nie przyjmuje p\u0142atno\u015Bci w tej walucie. Skontaktuj si\u0119 ze sprzedawc\u0105.",priceChanged:"Cena produktu si\u0119 zmieni\u0142a. Od\u015Bwie\u017C stron\u0119, aby zobaczy\u0107 aktualn\u0105 cen\u0119.",close:"Zamknij koszyk",remove:"Usu\u0144",quantity:"Ilo\u015B\u0107",increaseQuantity:"Zwi\u0119ksz ilo\u015B\u0107",decreaseQuantity:"Zmniejsz ilo\u015B\u0107",openCart:"Otw\xF3rz koszyk",cartItemsCount:"Produkt\xF3w w koszyku",lowestPrice30Days:"Najni\u017Csza cena z 30 dni:",noPriceHistory:"Brak danych o cenie z ostatnich 30 dni",redirectFailed:"Nie uda\u0142o si\u0119 przekierowa\u0107 do p\u0142atno\u015Bci. Spr\xF3buj ponownie p\xF3\u017Aniej.",subscriptionUnsupported:"Subskrypcji nie mo\u017Cna jeszcze doda\u0107 do koszyka.",searchCountry:"Znajd\u017A kraj",noCountriesFound:"Nie znaleziono kraj\xF3w",countryRequired:"Wybierz kraj, aby przej\u015B\u0107 dalej.",paymentForCart:"P\u0142atno\u015B\u0107 za koszyk",coupon:"Kupon",extrasCalculatedNext:"Rabaty, dostawa i podatki w nast\u0119pnym kroku",loadFailed:"Nie uda\u0142o si\u0119 wczyta\u0107 koszyka.",retry:"Spr\xF3buj ponownie"}};function m(e,t){return l(C,e,t)}function R(e,t,n){return y(m(t,n),e)}var s="pl-PL",c="bitsnap-locale",r;function E(e){let t=_optionalChain([e, 'optionalAccess', _ => _.trim, 'call', _2 => _2()]);r=t?t.toLowerCase()==="en"?"en-US":t.toLowerCase()==="pl"?s:t:void 0,typeof localStorage<"u"&&(r==null?localStorage.removeItem(c):localStorage.setItem(c,r))}function F(){return _nullishCoalesce(r, () => ((typeof localStorage<"u"?_nullishCoalesce(localStorage.getItem(c), () => (s)):s)))}var _clsx = require('clsx');var _tailwindmerge = require('tailwind-merge');function H(...e){return _tailwindmerge.twMerge.call(void 0, _clsx.clsx.call(void 0, e))}exports.a = b; exports.b = z; exports.c = j; exports.d = H; exports.e = g; exports.f = x; exports.g = K; exports.h = T; exports.i = l; exports.j = R; exports.k = s; exports.l = E; exports.m = F;
2
+ //# sourceMappingURL=chunk-ERL4Z7M7.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/emems/web/bitsnap/bitsnap/bitsnap-react/dist/chunk-Q25D7OAO.js","../src/lib/client-header.ts"],"names":["CLIENT_HEADER_NAME","CLIENT_HEADER_VALUE","SDK_VERSION"],"mappings":"AAAA,uuBAAuC,ICG1BA,CAAAA,CAAqB,kBAAA,CACrBC,CAAAA,CAAsB,CAAA,cAAA,EAAiBC,kBAAW,CAAA,CAAA","file":"/home/emems/web/bitsnap/bitsnap/bitsnap-react/dist/chunk-Q25D7OAO.js","sourcesContent":[null,"import type { Interceptor } from \"@connectrpc/connect\";\nimport { SDK_VERSION } from \"../version\";\n\nexport const CLIENT_HEADER_NAME = \"X-Bitsnap-Client\";\nexport const CLIENT_HEADER_VALUE = `bitsnap-react@${SDK_VERSION}`;\n\nexport const CLIENT_QUERY_PARAM = \"bs_client\";\n\n/**\n * Spread into the `headers` of a fetch that already triggers a CORS preflight\n * (JSON POST, Connect RPC). Never use it on a simple cross-origin GET: the\n * custom header would force a preflight that older servers and merchant\n * proxies do not allow. Use `withClientParam` there.\n */\nexport const clientHeaders: Record<string, string> = {\n [CLIENT_HEADER_NAME]: CLIENT_HEADER_VALUE,\n};\n\n/** Connect interceptor adding the client header to every RPC. */\nexport const clientHeaderInterceptor: Interceptor = (next) => (req) => {\n req.header.set(CLIENT_HEADER_NAME, CLIENT_HEADER_VALUE);\n return next(req);\n};\n\n/** Adds `bs_client=<pkg>@<ver>` to a URL, for simple GETs that must stay preflight-free. */\nexport function withClientParam(url: string): string {\n const hash = url.indexOf(\"#\");\n const base = hash === -1 ? url : url.slice(0, hash);\n const fragment = hash === -1 ? \"\" : url.slice(hash);\n const separator = base.includes(\"?\") ? (/[?&]$/.test(base) ? \"\" : \"&\") : \"?\";\n return `${base}${separator}${CLIENT_QUERY_PARAM}=${encodeURIComponent(CLIENT_HEADER_VALUE)}${fragment}`;\n}\n"]}
1
+ {"version":3,"sources":["/home/emems/web/bitsnap/bitsnap/bitsnap-react/dist/chunk-ERL4Z7M7.js","../src/lib/client-header.ts"],"names":["CLIENT_HEADER_NAME","CLIENT_HEADER_VALUE","SDK_VERSION"],"mappings":"AAAA,uuBAAuC,ICG1BA,CAAAA,CAAqB,kBAAA,CACrBC,CAAAA,CAAsB,CAAA,cAAA,EAAiBC,kBAAW,CAAA,CAAA","file":"/home/emems/web/bitsnap/bitsnap/bitsnap-react/dist/chunk-ERL4Z7M7.js","sourcesContent":[null,"import type { Interceptor } from \"@connectrpc/connect\";\nimport { SDK_VERSION } from \"../version\";\n\nexport const CLIENT_HEADER_NAME = \"X-Bitsnap-Client\";\nexport const CLIENT_HEADER_VALUE = `bitsnap-react@${SDK_VERSION}`;\n\nexport const CLIENT_QUERY_PARAM = \"bs_client\";\n\n/**\n * Spread into the `headers` of a fetch that already triggers a CORS preflight\n * (JSON POST, Connect RPC). Never use it on a simple cross-origin GET: the\n * custom header would force a preflight that older servers and merchant\n * proxies do not allow. Use `withClientParam` there.\n */\nexport const clientHeaders: Record<string, string> = {\n [CLIENT_HEADER_NAME]: CLIENT_HEADER_VALUE,\n};\n\n/** Connect interceptor adding the client header to every RPC. */\nexport const clientHeaderInterceptor: Interceptor = (next) => (req) => {\n req.header.set(CLIENT_HEADER_NAME, CLIENT_HEADER_VALUE);\n return next(req);\n};\n\n/** Adds `bs_client=<pkg>@<ver>` to a URL, for simple GETs that must stay preflight-free. */\nexport function withClientParam(url: string): string {\n const hash = url.indexOf(\"#\");\n const base = hash === -1 ? url : url.slice(0, hash);\n const fragment = hash === -1 ? \"\" : url.slice(hash);\n const separator = base.includes(\"?\") ? (/[?&]$/.test(base) ? \"\" : \"&\") : \"?\";\n return `${base}${separator}${CLIENT_QUERY_PARAM}=${encodeURIComponent(CLIENT_HEADER_VALUE)}${fragment}`;\n}\n"]}
@@ -1,2 +1,2 @@
1
- import{a as le,b as _,c as ue,d as z,e as de,f as V,g as fe,h as pe,n as Y,p as L}from"./chunk-ADYVTMGH.mjs";var Oe=Symbol.for("bitsnap.pageViews");function ye(e){let t=e;return t[Oe]??={path:null,starters:new Set,watching:!1}}function De(e,t){let n=()=>{try{t()}catch{}};for(let o of["pushState","replaceState"]){let a=e.history[o];e.history[o]=function(...i){let c=a.apply(this,i);return n(),c}}e.addEventListener("popstate",n)}function A(e,t=window){try{let n=ye(t),o=()=>e();n.watching||(n.watching=!0,De(t,()=>{let i=t.location.pathname;i===n.path||n.starters.size===0||(n.path=i,n.starters.values().next().value?.())})),n.starters.add(o);let a=t.location.pathname;return a!==n.path&&(n.path=a,o()),()=>void n.starters.delete(o)}catch{return()=>{}}}function ge(e=window){let t=ye(e);t.path=null,t.starters.clear()}var ve="1.11.1";function I(e){let t=new Uint8Array(e),n=typeof crypto<"u"?crypto:void 0;if(n&&typeof n.getRandomValues=="function")n.getRandomValues(t);else for(let o=0;o<e;o++)t[o]=Math.floor(Math.random()*256);return t}var me="X-Bitsnap-Visitor",$e=390*24*60*60,Me=/^[A-Za-z0-9_-]{22}$/;function R(e){return e.BitsnapConsent}function je(e,t){for(let n of e.cookie.split(";")){let o=n.indexOf("=");if(o!==-1&&n.slice(0,o).trim()===t)return n.slice(o+1).trim()}return null}function He(e){let t=e.toLowerCase();return t==="bitsnap.pl"||t.endsWith(".bitsnap.pl")}function F(e,t){try{let n=R(e);if(!n)return!1;if(n.scope==="project")return n.projectKey===t;let o=He(e.location.hostname);return n.scope==="global"?!o:!1}catch{return!1}}function J(e,t){try{return R(e)?.get()?.c.analytics===!0&&F(e,t)}catch{return!1}}function he(){let e="";return I(16).forEach(t=>e+=String.fromCharCode(t)),btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function Ee(e,t){try{return je(e,V(t))}catch{return null}}function B(e,t){let n=Ee(e,t);return n!==null&&Me.test(n)?n:null}function ke(e,t,n){try{let o=e.document,a=`${V(t)}=${n}; Max-Age=${$e}; Path=/; SameSite=Lax`+(e.location.protocol==="https:"?"; Secure":"");for(let i of Y(e.location.hostname).reverse())if(o.cookie=`${a}; Domain=${i}`,B(o,t)===n)return;o.cookie=a}catch{}}function be(e,t){try{let n=e.document;if(Ee(n,t)===null)return;let o=`${V(t)}=; Max-Age=0; Path=/; SameSite=Lax`+(e.location.protocol==="https:"?"; Secure":"");n.cookie=o;for(let a of Y(e.location.hostname))n.cookie=`${o}; Domain=${a}`}catch{}}function N(e,t){try{let n=e.navigator;return n?.globalPrivacyControl===!0||n?.webdriver===!0?null:J(e,t)?B(e.document,t):null}catch{return null}}var Ue="https://collect.bitsnap.pl",Ke=5e3,Ge=20,Te=32*1024,ze=60*1024,xe=/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function _e(e){return typeof TextEncoder=="function"?new TextEncoder().encode(e).length:unescape(encodeURIComponent(e)).length}var y={track(){},page(){},clientId:()=>null,flush(){},setEnabled(){},onEvent:()=>()=>{},configure(){},destroy(){}};function Ye(e=Date.now()){let t=I(16),n=e;for(let a=5;a>=0;a--)t[a]=n%256,n=Math.floor(n/256);t[6]=t[6]&15|112,t[8]=t[8]&63|128;let o=Array.from(t,a=>a.toString(16).padStart(2,"0")).join("");return`${o.slice(0,8)}-${o.slice(8,12)}-${o.slice(12,16)}-${o.slice(16,20)}-${o.slice(20)}`}var Ce="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";function Fe(){return Array.from(I(16),e=>Ce[e%Ce.length]).join("")}function Je(e,t,n=!1){let o=_e(JSON.stringify({k:e,events:[]})),a=[],i=[],c=o,s=()=>{i.length>0&&a.push({body:JSON.stringify({k:e,events:i}),bytes:c,count:i.length}),i=[],c=o};for(let u of t){let l=_e(JSON.stringify(u));o+l>Te||((i.length>=le.maxBatchEvents||c+l+(i.length>0?1:0)>Te)&&s(),c+=l+(i.length>0?1:0),i.push(u))}if(s(),n){let u=0,l=a.length;for(;l>0&&u+a[l-1].bytes<=ze;)u+=a[l-1].bytes,l--;a=a.slice(l)}return a}function Xe(e){try{return typeof window>"u"||typeof document>"u"?y:qe(e,window)}catch{return y}}function qe(e,t){let n=_(e.projectKey??""),o=!!e.debug,a=(...r)=>{o&&console.warn("[bitsnap analytics]",...r)};if(!n)return a("invalid projectKey, tracking is off"),y;let i=n,c=r=>`${(r||Ue).replace(/\/+$/,"")}/e`,s=c(e.endpoint),u=e.source??"sdk_react",l=e.channel??"embed",b=`bitsnap-react@${ve}`,M=Fe(),T=z(t.location.href),j=e.env??"live";if(!e.env)try{new URLSearchParams(t.location.search).has("test")&&(j="test")}catch{}let Le=de(document.referrer),H=e.enabled!==!1,ee=null,Re=0,p=[],h=null,C=new Set;e.onEvent&&C.add(e.onEvent);let E=[],g,m=!0;function W(){let r=R(t);!r||r===g||(g=r,m=!r.ready,r.ready?.then(()=>{g===r&&(m=!0,re())},()=>{g===r&&(m=!0)}))}function te(){W();try{if(!g)return!1;let r=g.get();return!!g.denied&&g.denied("analytics")||!!r&&r.c.analytics===!1}catch{return!1}}function ne(r){C.forEach(f=>{try{f(r)}catch{}})}function U(r){try{if(W(),!g||!F(t,i))return;J(t,i)?P()&&B(t.document,i)===null&&ke(t,i,he()):r&&be(t,i)}catch{}}function re(){if(U(!0),te())p=[],E=[],w();else{if(m&&E.length>0){let r=E;E=[],r.forEach(ne)}p.length>0&&x()}}function P(){if(!H)return!1;let r=t.navigator;return r&&(r.globalPrivacyControl===!0||r.webdriver===!0)?!1:!te()}function w(){h!==null&&clearTimeout(h),h=null}function Be(){h===null&&(h=setTimeout(()=>{h=null,x()},Ke),h.unref?.())}function Ne(r){try{if(typeof fetch=="function"){fetch(s,{method:"POST",body:r,keepalive:!0,credentials:"omit",headers:{"Content-Type":"text/plain"}}).catch(()=>{});return}}catch{}try{let f=t.navigator;f&&typeof f.sendBeacon=="function"&&f.sendBeacon(s,new Blob([r],{type:"text/plain"}))}catch{}}function x(r=!1){try{if(w(),p.length===0)return;if(!P()){p=[];return}if(!m)return;U(m);let f=N(t,i),d=f?p.map(k=>({...k,client_id:f})):p;p=[],Je(i,d,r).forEach(k=>Ne(k.body))}catch{}}function oe(r,f,d){if(!P())return;let k=fe(r,f);if(!k.ok){a("dropped",r,k.reason);return}let se=z(t.location.href),K={event_id:d?.event_id&&xe.test(d.event_id)?d.event_id:Ye(),event:r,ts:Date.now(),schema_version:1,env:j,source:u,channel:l,sdk:b,page_id:M,page_type:d?.page_type!==void 0?d.page_type:ee,host:se?.host??null,path:d?.path?ue(d.path.split(/[?#]/)[0]):se?.path??null,referrer_host:Le,utm_source:T?.utm_source??null,utm_medium:T?.utm_medium??null,utm_campaign:T?.utm_campaign??null,utm_content:T?.utm_content??null,utm_term:T?.utm_term??null,ref_code:T?.ref_code??null,product_id:d?.product_id??null,variant_id:d?.variant_id??null,order_ref:d?.order_ref??null,props:k.props};d?.event_id&&!xe.test(d.event_id)&&a("ignored invalid event_id",r),u==="dashboard"&&e.visitorId&&(K.visitor_id=e.visitorId);let ce=pe(K);if(!ce.ok){a("dropped",r,ce.reason);return}let G=K;m?ne(G):E.push(G),p.push(G),p.length>=Ge?x():Be()}let ie=()=>x(!0),ae=()=>{document.visibilityState==="hidden"&&x(!0)},S=()=>re();return t.addEventListener("pagehide",ie),document.addEventListener("visibilitychange",ae),t.addEventListener("bitsnap:consent",S),t.addEventListener("bitsnap:consent:ready",S),W(),U(m),{track(r,f,d){try{oe(r,f,d)}catch{}},page(r,f){try{r!==void 0&&(ee=r),oe("page_view",{landing:Re++===0},f)}catch{}},clientId(r){try{return r!==void 0&&_(r)!==i?null:P()?N(t,i):null}catch{return null}},flush:()=>x(),setEnabled(r){H=!!r,H||(p=[],E=[],w())},configure(r){try{(r.env==="live"||r.env==="test")&&(j=r.env),typeof r.endpoint=="string"&&r.endpoint&&(s=c(r.endpoint))}catch{}},onEvent(r){return C.add(r),()=>void C.delete(r)},destroy(){p=[],E=[],w(),C.clear(),t.removeEventListener("pagehide",ie),document.removeEventListener("visibilitychange",ae),t.removeEventListener("bitsnap:consent",S),t.removeEventListener("bitsnap:consent:ready",S)}}}var v,O=null;function D(e){if(!v){let t=Xe(e);return t===y||(v=t,O=_(e.projectKey??"")),t}try{let t=_(e.projectKey??"");t!==O&&e.debug&&console.warn("[bitsnap analytics]","tracker already started for another projectKey, ignoring",e.projectKey),t===O&&((e.env||e.endpoint)&&v.configure({env:e.env,endpoint:e.endpoint}),e.enabled!=null&&v.setEnabled(e.enabled))}catch{}return v}function Ae(){return v}function xt(){typeof window<"u"&&ge(window),v?.destroy(),v=void 0,O=null}function _t(e){try{if(typeof window>"u")return{};let t=v,n=null;if(t)n=t.clientId(e);else{let o=e?_(e):null;n=o?N(window,o):null}return n?{[me]:n}:{}}catch{return{}}}import{createContext as Ze,createElement as Qe,useContext as et,useMemo as Ie,useRef as tt}from"react";var nt={track:y.track,page:y.page},Pe=Ze(nt);function St({projectKey:e,env:t,enabled:n,endpoint:o,onEvent:a,autoPageViews:i,children:c}){let s=Ie(()=>D({projectKey:e,env:t,endpoint:o,enabled:n}),[e,t,o]),u=tt(a);u.current=a,L(()=>{s.setEnabled(n!==!1)},[s,n]),L(()=>{if(!(i===!1||n===!1||s===y))return A(()=>s.page(null))},[s,i,n]),L(()=>s.onEvent(b=>u.current?.(b)),[s]);let l=Ie(()=>({track:s.track.bind(s),page:s.page.bind(s)}),[s]);return Qe(Pe.Provider,{value:l},c)}function we(){return et(Pe)}import{createContext as rt,createElement as ot,useContext as Ve,useEffect as it,useLayoutEffect as at,useMemo as st,useRef as ct}from"react";var $={track(){}},X=null;function lt(e){let t=Symbol("bitsnap-instrument");function n(){if(typeof window>"u")return null;let{projectKey:i,analytics:c,provided:s}=e();return c===!1?null:s||(i?D({projectKey:i,source:"sdk_react",channel:"embed",env:typeof c=="object"?c.env:void 0}):null)}let o={track(i,c,s){try{let u=n();if(!u)return;let{analytics:l,pageType:b}=e(),M=b&&s?.page_type===void 0?{...s,page_type:b}:s;X=typeof l=="object"&&l.onEvent?t:null,u.track(i,c,M)}catch{}finally{X=null}}};function a(){try{if(!n())return()=>{};let i=Ae();if(!i)return()=>{};let c=e().provided?()=>{}:A(()=>i.page(e().pageType??null)),s=i.onEvent(u=>{if(X===t)try{let{analytics:l}=e();typeof l=="object"&&l.onEvent?.(u)}catch{}});return()=>{c(),s()}}catch{return()=>{}}}return{instrument:o,attach:a}}var Z=rt(null);function Nt({value:e,children:t}){return ot(Z.Provider,{value:e},t)}function Ot(){return Ve(Z)??$}function Dt(e,t,n){let o=Ve(Z),a=we(),i=a.track===y.track?null:a,c=ct({projectKey:e,analytics:t,pageType:n,provided:i});c.current={projectKey:e,analytics:t,pageType:n,provided:i};let s=st(()=>lt(()=>c.current),[]),u=t===void 0&&o!==null,l=typeof t=="object"&&!!t.onEvent;return at(()=>{if(!u)return s.attach()},[s,u,l,e]),u?o:s.instrument}var Q=$;function Se(e){Q=e??$}var q=0;function $t(){return q>0?$:Q}async function Mt(e){q++;try{return await e()}finally{q--}}function jt(e){it(()=>(Se(e),()=>{Q===e&&Se(null)}),[e])}function Ht(e){let t=Number.isFinite(e)?Math.max(0,Math.min(100,e)):0;return t>=100?"100":t>=75?"75-99":t>=50?"50-74":t>=25?"25-49":"0-24"}function Wt(e,t){let n=[];for(let o of[25,50,75,100])e>=o&&!t.has(o)&&(t.add(o),n.push(o));return n}export{ve as a,A as b,Ue as c,Xe as d,D as e,Ae as f,xt as g,_t as h,St as i,we as j,$ as k,Nt as l,Ot as m,Dt as n,$t as o,Mt as p,jt as q,Ht as r,Wt as s};
2
- //# sourceMappingURL=chunk-IJLHU2MA.mjs.map
1
+ import{a as le,b as _,c as ue,d as z,e as de,f as V,g as fe,h as pe,n as Y,p as L}from"./chunk-ADYVTMGH.mjs";var Oe=Symbol.for("bitsnap.pageViews");function ye(e){let t=e;return t[Oe]??={path:null,starters:new Set,watching:!1}}function De(e,t){let n=()=>{try{t()}catch{}};for(let o of["pushState","replaceState"]){let a=e.history[o];e.history[o]=function(...i){let c=a.apply(this,i);return n(),c}}e.addEventListener("popstate",n)}function A(e,t=window){try{let n=ye(t),o=()=>e();n.watching||(n.watching=!0,De(t,()=>{let i=t.location.pathname;i===n.path||n.starters.size===0||(n.path=i,n.starters.values().next().value?.())})),n.starters.add(o);let a=t.location.pathname;return a!==n.path&&(n.path=a,o()),()=>void n.starters.delete(o)}catch{return()=>{}}}function ge(e=window){let t=ye(e);t.path=null,t.starters.clear()}var ve="1.12.0";function I(e){let t=new Uint8Array(e),n=typeof crypto<"u"?crypto:void 0;if(n&&typeof n.getRandomValues=="function")n.getRandomValues(t);else for(let o=0;o<e;o++)t[o]=Math.floor(Math.random()*256);return t}var me="X-Bitsnap-Visitor",$e=390*24*60*60,Me=/^[A-Za-z0-9_-]{22}$/;function R(e){return e.BitsnapConsent}function je(e,t){for(let n of e.cookie.split(";")){let o=n.indexOf("=");if(o!==-1&&n.slice(0,o).trim()===t)return n.slice(o+1).trim()}return null}function He(e){let t=e.toLowerCase();return t==="bitsnap.pl"||t.endsWith(".bitsnap.pl")}function F(e,t){try{let n=R(e);if(!n)return!1;if(n.scope==="project")return n.projectKey===t;let o=He(e.location.hostname);return n.scope==="global"?!o:!1}catch{return!1}}function J(e,t){try{return R(e)?.get()?.c.analytics===!0&&F(e,t)}catch{return!1}}function he(){let e="";return I(16).forEach(t=>e+=String.fromCharCode(t)),btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function Ee(e,t){try{return je(e,V(t))}catch{return null}}function B(e,t){let n=Ee(e,t);return n!==null&&Me.test(n)?n:null}function ke(e,t,n){try{let o=e.document,a=`${V(t)}=${n}; Max-Age=${$e}; Path=/; SameSite=Lax`+(e.location.protocol==="https:"?"; Secure":"");for(let i of Y(e.location.hostname).reverse())if(o.cookie=`${a}; Domain=${i}`,B(o,t)===n)return;o.cookie=a}catch{}}function be(e,t){try{let n=e.document;if(Ee(n,t)===null)return;let o=`${V(t)}=; Max-Age=0; Path=/; SameSite=Lax`+(e.location.protocol==="https:"?"; Secure":"");n.cookie=o;for(let a of Y(e.location.hostname))n.cookie=`${o}; Domain=${a}`}catch{}}function N(e,t){try{let n=e.navigator;return n?.globalPrivacyControl===!0||n?.webdriver===!0?null:J(e,t)?B(e.document,t):null}catch{return null}}var Ue="https://collect.bitsnap.pl",Ke=5e3,Ge=20,Te=32*1024,ze=60*1024,xe=/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function _e(e){return typeof TextEncoder=="function"?new TextEncoder().encode(e).length:unescape(encodeURIComponent(e)).length}var y={track(){},page(){},clientId:()=>null,flush(){},setEnabled(){},onEvent:()=>()=>{},configure(){},destroy(){}};function Ye(e=Date.now()){let t=I(16),n=e;for(let a=5;a>=0;a--)t[a]=n%256,n=Math.floor(n/256);t[6]=t[6]&15|112,t[8]=t[8]&63|128;let o=Array.from(t,a=>a.toString(16).padStart(2,"0")).join("");return`${o.slice(0,8)}-${o.slice(8,12)}-${o.slice(12,16)}-${o.slice(16,20)}-${o.slice(20)}`}var Ce="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";function Fe(){return Array.from(I(16),e=>Ce[e%Ce.length]).join("")}function Je(e,t,n=!1){let o=_e(JSON.stringify({k:e,events:[]})),a=[],i=[],c=o,s=()=>{i.length>0&&a.push({body:JSON.stringify({k:e,events:i}),bytes:c,count:i.length}),i=[],c=o};for(let u of t){let l=_e(JSON.stringify(u));o+l>Te||((i.length>=le.maxBatchEvents||c+l+(i.length>0?1:0)>Te)&&s(),c+=l+(i.length>0?1:0),i.push(u))}if(s(),n){let u=0,l=a.length;for(;l>0&&u+a[l-1].bytes<=ze;)u+=a[l-1].bytes,l--;a=a.slice(l)}return a}function Xe(e){try{return typeof window>"u"||typeof document>"u"?y:qe(e,window)}catch{return y}}function qe(e,t){let n=_(e.projectKey??""),o=!!e.debug,a=(...r)=>{o&&console.warn("[bitsnap analytics]",...r)};if(!n)return a("invalid projectKey, tracking is off"),y;let i=n,c=r=>`${(r||Ue).replace(/\/+$/,"")}/e`,s=c(e.endpoint),u=e.source??"sdk_react",l=e.channel??"embed",b=`bitsnap-react@${ve}`,M=Fe(),T=z(t.location.href),j=e.env??"live";if(!e.env)try{new URLSearchParams(t.location.search).has("test")&&(j="test")}catch{}let Le=de(document.referrer),H=e.enabled!==!1,ee=null,Re=0,p=[],h=null,C=new Set;e.onEvent&&C.add(e.onEvent);let E=[],g,m=!0;function W(){let r=R(t);!r||r===g||(g=r,m=!r.ready,r.ready?.then(()=>{g===r&&(m=!0,re())},()=>{g===r&&(m=!0)}))}function te(){W();try{if(!g)return!1;let r=g.get();return!!g.denied&&g.denied("analytics")||!!r&&r.c.analytics===!1}catch{return!1}}function ne(r){C.forEach(f=>{try{f(r)}catch{}})}function U(r){try{if(W(),!g||!F(t,i))return;J(t,i)?P()&&B(t.document,i)===null&&ke(t,i,he()):r&&be(t,i)}catch{}}function re(){if(U(!0),te())p=[],E=[],w();else{if(m&&E.length>0){let r=E;E=[],r.forEach(ne)}p.length>0&&x()}}function P(){if(!H)return!1;let r=t.navigator;return r&&(r.globalPrivacyControl===!0||r.webdriver===!0)?!1:!te()}function w(){h!==null&&clearTimeout(h),h=null}function Be(){h===null&&(h=setTimeout(()=>{h=null,x()},Ke),h.unref?.())}function Ne(r){try{if(typeof fetch=="function"){fetch(s,{method:"POST",body:r,keepalive:!0,credentials:"omit",headers:{"Content-Type":"text/plain"}}).catch(()=>{});return}}catch{}try{let f=t.navigator;f&&typeof f.sendBeacon=="function"&&f.sendBeacon(s,new Blob([r],{type:"text/plain"}))}catch{}}function x(r=!1){try{if(w(),p.length===0)return;if(!P()){p=[];return}if(!m)return;U(m);let f=N(t,i),d=f?p.map(k=>({...k,client_id:f})):p;p=[],Je(i,d,r).forEach(k=>Ne(k.body))}catch{}}function oe(r,f,d){if(!P())return;let k=fe(r,f);if(!k.ok){a("dropped",r,k.reason);return}let se=z(t.location.href),K={event_id:d?.event_id&&xe.test(d.event_id)?d.event_id:Ye(),event:r,ts:Date.now(),schema_version:1,env:j,source:u,channel:l,sdk:b,page_id:M,page_type:d?.page_type!==void 0?d.page_type:ee,host:se?.host??null,path:d?.path?ue(d.path.split(/[?#]/)[0]):se?.path??null,referrer_host:Le,utm_source:T?.utm_source??null,utm_medium:T?.utm_medium??null,utm_campaign:T?.utm_campaign??null,utm_content:T?.utm_content??null,utm_term:T?.utm_term??null,ref_code:T?.ref_code??null,product_id:d?.product_id??null,variant_id:d?.variant_id??null,order_ref:d?.order_ref??null,props:k.props};d?.event_id&&!xe.test(d.event_id)&&a("ignored invalid event_id",r),u==="dashboard"&&e.visitorId&&(K.visitor_id=e.visitorId);let ce=pe(K);if(!ce.ok){a("dropped",r,ce.reason);return}let G=K;m?ne(G):E.push(G),p.push(G),p.length>=Ge?x():Be()}let ie=()=>x(!0),ae=()=>{document.visibilityState==="hidden"&&x(!0)},S=()=>re();return t.addEventListener("pagehide",ie),document.addEventListener("visibilitychange",ae),t.addEventListener("bitsnap:consent",S),t.addEventListener("bitsnap:consent:ready",S),W(),U(m),{track(r,f,d){try{oe(r,f,d)}catch{}},page(r,f){try{r!==void 0&&(ee=r),oe("page_view",{landing:Re++===0},f)}catch{}},clientId(r){try{return r!==void 0&&_(r)!==i?null:P()?N(t,i):null}catch{return null}},flush:()=>x(),setEnabled(r){H=!!r,H||(p=[],E=[],w())},configure(r){try{(r.env==="live"||r.env==="test")&&(j=r.env),typeof r.endpoint=="string"&&r.endpoint&&(s=c(r.endpoint))}catch{}},onEvent(r){return C.add(r),()=>void C.delete(r)},destroy(){p=[],E=[],w(),C.clear(),t.removeEventListener("pagehide",ie),document.removeEventListener("visibilitychange",ae),t.removeEventListener("bitsnap:consent",S),t.removeEventListener("bitsnap:consent:ready",S)}}}var v,O=null;function D(e){if(!v){let t=Xe(e);return t===y||(v=t,O=_(e.projectKey??"")),t}try{let t=_(e.projectKey??"");t!==O&&e.debug&&console.warn("[bitsnap analytics]","tracker already started for another projectKey, ignoring",e.projectKey),t===O&&((e.env||e.endpoint)&&v.configure({env:e.env,endpoint:e.endpoint}),e.enabled!=null&&v.setEnabled(e.enabled))}catch{}return v}function Ae(){return v}function xt(){typeof window<"u"&&ge(window),v?.destroy(),v=void 0,O=null}function _t(e){try{if(typeof window>"u")return{};let t=v,n=null;if(t)n=t.clientId(e);else{let o=e?_(e):null;n=o?N(window,o):null}return n?{[me]:n}:{}}catch{return{}}}import{createContext as Ze,createElement as Qe,useContext as et,useMemo as Ie,useRef as tt}from"react";var nt={track:y.track,page:y.page},Pe=Ze(nt);function St({projectKey:e,env:t,enabled:n,endpoint:o,onEvent:a,autoPageViews:i,children:c}){let s=Ie(()=>D({projectKey:e,env:t,endpoint:o,enabled:n}),[e,t,o]),u=tt(a);u.current=a,L(()=>{s.setEnabled(n!==!1)},[s,n]),L(()=>{if(!(i===!1||n===!1||s===y))return A(()=>s.page(null))},[s,i,n]),L(()=>s.onEvent(b=>u.current?.(b)),[s]);let l=Ie(()=>({track:s.track.bind(s),page:s.page.bind(s)}),[s]);return Qe(Pe.Provider,{value:l},c)}function we(){return et(Pe)}import{createContext as rt,createElement as ot,useContext as Ve,useEffect as it,useLayoutEffect as at,useMemo as st,useRef as ct}from"react";var $={track(){}},X=null;function lt(e){let t=Symbol("bitsnap-instrument");function n(){if(typeof window>"u")return null;let{projectKey:i,analytics:c,provided:s}=e();return c===!1?null:s||(i?D({projectKey:i,source:"sdk_react",channel:"embed",env:typeof c=="object"?c.env:void 0}):null)}let o={track(i,c,s){try{let u=n();if(!u)return;let{analytics:l,pageType:b}=e(),M=b&&s?.page_type===void 0?{...s,page_type:b}:s;X=typeof l=="object"&&l.onEvent?t:null,u.track(i,c,M)}catch{}finally{X=null}}};function a(){try{if(!n())return()=>{};let i=Ae();if(!i)return()=>{};let c=e().provided?()=>{}:A(()=>i.page(e().pageType??null)),s=i.onEvent(u=>{if(X===t)try{let{analytics:l}=e();typeof l=="object"&&l.onEvent?.(u)}catch{}});return()=>{c(),s()}}catch{return()=>{}}}return{instrument:o,attach:a}}var Z=rt(null);function Nt({value:e,children:t}){return ot(Z.Provider,{value:e},t)}function Ot(){return Ve(Z)??$}function Dt(e,t,n){let o=Ve(Z),a=we(),i=a.track===y.track?null:a,c=ct({projectKey:e,analytics:t,pageType:n,provided:i});c.current={projectKey:e,analytics:t,pageType:n,provided:i};let s=st(()=>lt(()=>c.current),[]),u=t===void 0&&o!==null,l=typeof t=="object"&&!!t.onEvent;return at(()=>{if(!u)return s.attach()},[s,u,l,e]),u?o:s.instrument}var Q=$;function Se(e){Q=e??$}var q=0;function $t(){return q>0?$:Q}async function Mt(e){q++;try{return await e()}finally{q--}}function jt(e){it(()=>(Se(e),()=>{Q===e&&Se(null)}),[e])}function Ht(e){let t=Number.isFinite(e)?Math.max(0,Math.min(100,e)):0;return t>=100?"100":t>=75?"75-99":t>=50?"50-74":t>=25?"25-49":"0-24"}function Wt(e,t){let n=[];for(let o of[25,50,75,100])e>=o&&!t.has(o)&&(t.add(o),n.push(o));return n}export{ve as a,A as b,Ue as c,Xe as d,D as e,Ae as f,xt as g,_t as h,St as i,we as j,$ as k,Nt as l,Ot as m,Dt as n,$t as o,Mt as p,jt as q,Ht as r,Wt as s};
2
+ //# sourceMappingURL=chunk-FF2ICGFQ.mjs.map