@saasquatch/squatch-js 2.8.3-9 → 2.8.4

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 (42) hide show
  1. package/CHANGELOG.md +9 -2
  2. package/babelregister.js +0 -1
  3. package/coverage/base.css +224 -0
  4. package/coverage/block-navigation.js +87 -0
  5. package/coverage/clover.xml +996 -0
  6. package/coverage/coverage-final.json +26 -0
  7. package/coverage/favicon.png +0 -0
  8. package/coverage/prettify.css +1 -0
  9. package/coverage/prettify.js +2 -0
  10. package/coverage/sort-arrow-sprite.png +0 -0
  11. package/coverage/sorter.js +210 -0
  12. package/demo/perf-benchmark.ts +363 -0
  13. package/demo/perf-compare.html +870 -0
  14. package/demo/perf-deploy/vercel.json +17 -0
  15. package/demo/perf-frame.html +417 -0
  16. package/demo/perf-server.ts +131 -0
  17. package/dist/ErrorTemplate-DUNm11h9.js +124 -0
  18. package/dist/ErrorTemplate-DUNm11h9.js.map +1 -0
  19. package/dist/ErrorTemplate-DumOlC5f.cjs +109 -0
  20. package/dist/ErrorTemplate-DumOlC5f.cjs.map +1 -0
  21. package/dist/SkeletonTemplate-B3Bk4NFu.cjs +243 -0
  22. package/dist/SkeletonTemplate-B3Bk4NFu.cjs.map +1 -0
  23. package/dist/SkeletonTemplate-Day_0iMM.js +246 -0
  24. package/dist/SkeletonTemplate-Day_0iMM.js.map +1 -0
  25. package/dist/squatch.cjs.js +20 -329
  26. package/dist/squatch.cjs.js.map +1 -1
  27. package/dist/squatch.esm.js +417 -764
  28. package/dist/squatch.esm.js.map +1 -1
  29. package/dist/squatch.js +149 -110
  30. package/dist/squatch.js.map +1 -1
  31. package/dist/squatch.min.js +2 -2
  32. package/dist/utils/cookieUtils.d.ts +1 -0
  33. package/dist/widgets/EmbedWidget.d.ts +1 -1
  34. package/dist/widgets/ErrorTemplate.d.ts +9 -0
  35. package/dist/widgets/PopupWidget.d.ts +1 -4
  36. package/dist/widgets/SkeletonTemplate.d.ts +1 -2
  37. package/dist/widgets/Widget.d.ts +19 -11
  38. package/package.json +11 -15
  39. package/vite-env.d.ts +2 -1
  40. package/vite.config.ts +17 -0
  41. package/babel.config.js +0 -8
  42. package/jest.config.ts +0 -200
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SkeletonTemplate-Day_0iMM.js","sources":["../src/widgets/SkeletonTemplate.ts"],"sourcesContent":["export type WidgetType = \"instant-access\" | \"verified-access\";\n\ninterface SkeletonProps {\n type?: WidgetType;\n}\n\n/**\n * Returns the complete HTML string (including <style>) for the skeleton.\n * Values are injected directly into the CSS string.\n */\nexport const getSkeleton = ({ type = \"verified-access\" }: SkeletonProps) => {\n const skeletonBackgroundColor = \"#e0e0e0\";\n const skeletonShimmerColor = \"#f5f5f5\";\n const referrerHTML = `\n <div class=\"hero-section\">\n <div class=\"hero-content\">\n <div class=\"skeleton sk-title-lg\"></div>\n <div class=\"skeleton sk-text\"></div>\n <div class=\"skeleton sk-text sk-text-short\"></div>\n </div>\n <div class=\"skeleton hero-image\"></div>\n </div>\n\n <div class=\"share-section\">\n <div class=\"skeleton sk-label\"></div>\n <div class=\"skeleton sk-input\"></div>\n <div class=\"social-buttons\">\n <div class=\"skeleton sk-btn-social\"></div>\n <div class=\"skeleton sk-btn-social\"></div>\n <div class=\"skeleton sk-btn-social\"></div>\n <div class=\"skeleton sk-btn-social\"></div>\n </div>\n </div>\n\n <div class=\"skeleton sk-title-md\" style=\"margin-top: 0; width: 30%; margin-left: auto; margin-right: auto\"></div>\n <div class=\"skeleton sk-text\" style=\"width: 60%; margin-left: auto; margin-right: auto\"></div>\n\n <div class=\"stats-section\">\n <div class=\"stat-card\">\n <div class=\"skeleton sk-stat-num\"></div>\n <div class=\"skeleton sk-stat-label\"></div>\n </div>\n <div class=\"stat-card stat-divider\">\n <div class=\"skeleton sk-stat-num\"></div>\n <div class=\"skeleton sk-stat-label\"></div>\n </div>\n </div>\n\n <div class=\"skeleton sk-title-md\"></div>\n\n <div class=\"table-header\">\n <div class=\"skeleton sk-th col-user\"></div>\n <div class=\"skeleton sk-th col-status\"></div>\n <div class=\"skeleton sk-th col-reward\"></div>\n <div class=\"skeleton sk-th col-date\"></div>\n </div>\n\n <div class=\"table-row\">\n <div class=\"col-user\"><div class=\"skeleton sk-text\" style=\"width: 70%; margin: 0\"></div></div>\n <div class=\"col-status\"><div class=\"skeleton sk-badge\" style=\"margin: 0\"></div></div>\n <div class=\"col-reward\"><div class=\"skeleton sk-reward-block\" style=\"margin: 0\"></div></div>\n <div class=\"col-date\"><div class=\"skeleton sk-text\" style=\"width: 80%; margin: 0\"></div></div>\n </div>\n \n <div class=\"table-row\">\n <div class=\"col-user\"><div class=\"skeleton sk-text\" style=\"width: 60%; margin: 0\"></div></div>\n <div class=\"col-status\"><div class=\"skeleton sk-badge\" style=\"margin: 0\"></div></div>\n <div class=\"col-reward\"><div class=\"skeleton sk-reward-block\" style=\"margin: 0\"></div></div>\n <div class=\"col-date\"><div class=\"skeleton sk-text\" style=\"width: 80%; margin: 0\"></div></div>\n </div>\n\n <div class=\"table-row\">\n <div class=\"col-user\"><div class=\"skeleton sk-text\" style=\"width: 75%; margin: 0\"></div></div>\n <div class=\"col-status\"><div class=\"skeleton sk-badge\" style=\"margin: 0\"></div></div>\n <div class=\"col-reward\"><div class=\"skeleton sk-reward-block\" style=\"margin: 0\"></div></div>\n <div class=\"col-date\"><div class=\"skeleton sk-text\" style=\"width: 80%; margin: 0\"></div></div>\n </div>\n\n <div class=\"pagination\">\n <div class=\"skeleton sk-btn-page\"></div>\n <div class=\"skeleton sk-btn-page\"></div>\n </div>\n `;\n\n const instantAccessHTML = `\n <div class=\"hero-section instant-access-layout\">\n <div class=\"skeleton hero-image ia-image\"></div>\n \n <div class=\"hero-content ia-content\">\n <div class=\"skeleton sk-title-lg ia-center\"></div>\n <div class=\"skeleton sk-text ia-center\"></div>\n \n <div class=\"skeleton sk-btn-action\"></div>\n\n <div class=\"skeleton sk-label\"></div>\n <div class=\"input-group\">\n <div class=\"skeleton sk-input\"></div>\n <div class=\"skeleton sk-btn-copy\"></div>\n </div>\n\n <div class=\"skeleton sk-text-short ia-center\" style=\"margin-top: 20px; width: 30%\"></div>\n <div class=\"skeleton sk-text-short ia-center\" style=\"width: 20%\"></div>\n </div>\n </div>\n `;\n\n return `\n <style>\n * {\n box-sizing: border-box;\n padding: 0;\n margin: 0;\n }\n\n .widget-container {\n background: white;\n width: 100%;\n padding: 40px;\n box-sizing: border-box;\n overflow: hidden; \n }\n\n @keyframes pulse {\n 0%, 100% { opacity: 1; }\n 50% { opacity: 0.6; }\n }\n\n .skeleton {\n background: ${skeletonBackgroundColor};\n animation: pulse 1.8s ease-in-out infinite;\n border-radius: 6px;\n margin-bottom: 12px;\n }\n\n /* Typography Skeletons */\n .sk-title-lg { height: 36px; width: 80%; margin-bottom: 16px; }\n .sk-title-md { height: 28px; width: 30%; margin-bottom: 20px; margin-top: 40px; }\n .sk-text { height: 16px; width: 90%; margin-bottom: 8px; }\n .sk-text-short { width: 40%; }\n .sk-label { height: 14px; width: 25%; margin-bottom: 10px; }\n\n /* Layouts */\n .hero-section {\n display: flex;\n gap: 40px;\n margin-bottom: 40px;\n padding-bottom: 40px;\n flex-direction: row;\n height: 100%;\n /* Removed border-bottom */\n }\n \n .hero-content {\n flex: 1;\n display: flex;\n flex-direction: column;\n justify-content: center;\n }\n \n .hero-image {\n flex: 1;\n height: 300px;\n border-radius: 12px;\n }\n\n /* -- Specific Instant Access Overrides -- */\n .instant-access-layout {\n margin-bottom: 0;\n padding-bottom: 0;\n align-items: center; \n }\n .ia-image {\n height: 400px; \n }\n .ia-center {\n margin-left: auto;\n margin-right: auto;\n }\n .ia-content {\n align-items: center; \n text-align: center;\n }\n .sk-btn-action {\n height: 45px;\n width: 140px;\n border-radius: 6px;\n margin: 24px auto;\n }\n .input-group {\n display: flex;\n gap: 10px;\n width: 100%;\n max-width: 400px;\n }\n .sk-btn-copy {\n height: 50px;\n width: 120px;\n border-radius: 8px;\n }\n /* ------------------------------------- */\n\n .share-section { margin-bottom: 40px; }\n .sk-input { height: 50px; width: 100%; border-radius: 8px; margin-bottom: 16px; }\n \n .social-buttons { display: flex; gap: 12px; }\n .sk-btn-social { flex: 1; height: 50px; border-radius: 8px; }\n\n .stats-section {\n display: flex;\n gap: 24px;\n margin-bottom: 40px;\n padding: 30px 0;\n /* Removed border-top and border-bottom */\n }\n .stat-card { flex: 1; display: flex; flex-direction: column; align-items: center; }\n .stat-divider { padding-left: 24px; }\n .sk-stat-num { height: 48px; width: 120px; margin-bottom: 8px; }\n .sk-stat-label { height: 18px; width: 80px; }\n\n /* Table Styles */\n .table-header { display: flex; gap: 16px; margin-bottom: 16px; }\n .sk-th { height: 16px; }\n .table-row { \n display: flex; \n align-items: center; \n gap: 16px; \n padding: 16px 0; \n /* Removed border-bottom */\n }\n \n .col-user { flex: 2; }\n .col-status { flex: 1; }\n .col-reward { flex: 2; }\n .col-date { flex: 1; }\n\n .sk-badge { height: 28px; width: 90px; border-radius: 14px; }\n .sk-reward-block { height: 36px; width: 100%; border-radius: 6px; }\n\n .pagination { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }\n .sk-btn-page { height: 36px; width: 64px; border-radius: 6px; margin-bottom: 0; }\n\n @media (max-width: 768px) {\n body { padding: 20px; }\n .widget-container { padding: 24px; }\n\n .hero-section { flex-direction: column-reverse; gap: 24px; }\n .instant-access-layout { flex-direction: column; }\n \n .hero-image { height: 220px; width: 100%; }\n .sk-title-lg { width: 100%; }\n\n .col-date { display: none; }\n }\n </style>\n\n <div class=\"widget-container\">\n ${type === \"verified-access\" ? referrerHTML : instantAccessHTML}\n </div>\n `;\n};\n"],"names":["getSkeleton","type"],"mappings":"AAUO,MAAMA,IAAc,CAAC,EAAE,MAAAC,IAAO,wBAgG5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAsJDA,MAAS,oBAnPM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAuEK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GA4KyC;AAAA;AAAA;"}
@@ -1,4 +1,4 @@
1
- "use strict";var Ae=Object.defineProperty;var Ie=(o,t,e)=>t in o?Ae(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var l=(o,t,e)=>Ie(o,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let C=null;function _e(o){const e=o.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*");C=new RegExp(`^${e}$`)}function We(){C=null}function k(o){const t=(...e)=>{C&&C.test(o)&&console.log(`[${o}]`,...e)};return Object.defineProperty(t,"enabled",{get(){return!!(C&&C.test(o))}}),t}/*! js-cookie v3.0.5 | MIT */function M(o){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var n in e)o[n]=e[n]}return o}var Te={read:function(o){return o[0]==='"'&&(o=o.slice(1,-1)),o.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(o){return encodeURIComponent(o).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}};function Q(o,t){function e(i,s,r){if(!(typeof document>"u")){r=M({},t,r),typeof r.expires=="number"&&(r.expires=new Date(Date.now()+r.expires*864e5)),r.expires&&(r.expires=r.expires.toUTCString()),i=encodeURIComponent(i).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var a="";for(var d in r)r[d]&&(a+="; "+d,r[d]!==!0&&(a+="="+r[d].split(";")[0]));return document.cookie=i+"="+o.write(s,i)+a}}function n(i){if(!(typeof document>"u"||arguments.length&&!i)){for(var s=document.cookie?document.cookie.split("; "):[],r={},a=0;a<s.length;a++){var d=s[a].split("="),c=d.slice(1).join("=");try{var h=decodeURIComponent(d[0]);if(r[h]=o.read(c,h),i===h)break}catch{}}return i?r[i]:r}}return Object.create({set:e,get:n,remove:function(i,s){e(i,"",M({},s,{expires:-1}))},withAttributes:function(i){return Q(this.converter,M({},this.attributes,i))},withConverter:function(i){return Q(M({},this.converter,i),this.attributes)}},{attributes:{value:Object.freeze(t)},converter:{value:Object.freeze(o)}})}var j=Q(Te,{path:"/"});const A="https://app.referralsaasquatch.com",Y="https://fast.ssqt.io/npm",L="squatch",X="impact";function q(o){if(typeof o!="object")throw new Error("config must be an object");const t=window.squatchTenant,e=ee(),n={tenantAlias:(o==null?void 0:o.tenantAlias)||t,domain:(o==null?void 0:o.domain)||(e==null?void 0:e.domain),npmCdn:(o==null?void 0:o.npmCdn)||(e==null?void 0:e.npmCdn),debug:(o==null?void 0:o.debug)||(e==null?void 0:e.debug)};if(typeof n.tenantAlias!="string")throw new Error("tenantAlias not provided");const i=n.tenantAlias,s=typeof n.domain=="string"&&n.domain||A,r=typeof n.debug=="boolean"&&n.debug||!1,a=typeof n.npmCdn=="string"&&n.npmCdn||Y;return{tenantAlias:i,domain:s,debug:r,npmCdn:a}}function I(o){return typeof o=="object"&&!Array.isArray(o)&&o!==null}function $e(o){if(o&&/^[a-z]{2}_(?:[A-Z]{2}|[0-9]{3})$/.test(o))return o}function ue(o){if(!I(o))throw new Error("Widget properties must be an object");if(!(o!=null&&o.user))throw new Error("Required properties missing.");return o}function pe(o){if(!I(o))throw new Error("Widget properties must be an object");return o}function R(){return window.impactToken||window.squatchToken}function ee(){return window.impactConfig||window.squatchConfig}function J(o){console.log("[DEBUG] parseErrorResponse - raw responseText:",o);try{const t=JSON.parse(o);if(console.log("[DEBUG] parseErrorResponse - parsed JSON:",t),t&&typeof t=="object")return console.log("[DEBUG] parseErrorResponse - returning parsed object with apiErrorCode:",t.apiErrorCode),t}catch(t){console.log("[DEBUG] parseErrorResponse - JSON parse failed:",t)}return{message:o}}async function Ue(o,t,e,n){const i=n||R(),s={Accept:"application/json","Content-Type":"application/json",...i?{Authorization:`Bearer ${i}`}:{},"X-SaaSquatch-Referrer":window?window.location.href:""};try{const r=await fetch(o,{method:"POST",body:JSON.stringify({query:t,variables:e}),headers:s});if(!r.ok)throw J(await r.text());return await r.json()}catch(r){throw r}}async function Se(o,t=""){const e={Accept:"application/json","Content-Type":"application/json"},n=t||R();n?(e["X-SaaSquatch-User-Token"]=n,console.log("[DEBUG] doGet - Adding token to headers:",n)):console.log("[DEBUG] doGet - No token found, proceeding without authentication header.");try{const i=await fetch(o,{method:"GET",credentials:"include",headers:e}),s=await i.text();if(!i.ok)throw J(s);return s&&JSON.parse(s)}catch(i){throw i}}async function K(o,t,e){const n={Accept:"application/json","Content-Type":"application/json"},i=e||R();i?(console.log("[DEBUG] doPost - Adding token to headers:",i),n["X-SaaSquatch-User-Token"]=i):console.log("[DEBUG] doPost - No token found, proceeding without authentication header.");try{const s=await fetch(o,{method:"POST",body:t,headers:n}),r=await s.text();if(!s.ok)throw J(r);return r&&JSON.parse(r)}catch(s){throw s}}async function qe(o,t,e){const n={Accept:"application/json","Content-Type":"application/json","X-SaaSquatch-Referrer":window?window.location.href:""},i=e||R();i&&(n["X-SaaSquatch-User-Token"]=i);try{const s=await fetch(o,{headers:n,method:"PUT",credentials:"include",body:t}),r=await s.text();if(!s.ok)throw J(r);return r&&JSON.parse(r)}catch(s){throw s}}const Re=`
1
+ "use strict";var Ae=Object.defineProperty;var Ie=(o,t,e)=>t in o?Ae(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var l=(o,t,e)=>Ie(o,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let _=null;function _e(o){const e=o.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*");_=new RegExp(`^${e}$`)}function ke(){_=null}function C(o){const t=(...e)=>{_&&_.test(o)&&console.log(`[${o}]`,...e)};return Object.defineProperty(t,"enabled",{get(){return!!(_&&_.test(o))}}),t}const v=C("squatch-js");function Q(o){const t=document.cookie.match(new RegExp("(?:^|; )"+o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"=([^;]*)"));return t?decodeURIComponent(t[1]):void 0}function Se(o,t,e){let n=`${encodeURIComponent(o)}=${encodeURIComponent(t)}`;{const i=new Date;i.setTime(i.getTime()+e.expires*864e5),n+=`; expires=${i.toUTCString()}`}e.path&&(n+=`; path=${e.path}`),e.domain&&(n+=`; domain=${e.domain}`),e.sameSite&&(n+=`; SameSite=${e.sameSite}`),document.cookie=n}const ae=o=>typeof o=="object"&&!Array.isArray(o),le=(o,t)=>{const e=i=>ae(t[i])&&o.hasOwnProperty(i)&&ae(o[i]),n=Object.getOwnPropertyNames(t).map(i=>({[i]:e(i)?le(o[i],t[i]):t[i]})).reduce((i,s)=>({...i,...s}),{});return{...o,...n}};function N(o){const t=atob(o.replace(/_/g,"/").replace(/-/g,"+")),e=new Uint8Array(t.length);for(let n=0;n<t.length;n++)e[n]=t.charCodeAt(n);return new TextDecoder("utf8").decode(e)}function ce(o){const t=new TextEncoder().encode(o),e=Array.from(t,n=>String.fromCodePoint(n)).join("");return btoa(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function We(){var o,t,e="weird_get_top_level_domain=cookie",n=document.location.hostname.split(".");for(o=n.length-1;o>=0;o--)if(t=n.slice(o).join("."),document.cookie=e+";domain=."+t+";",document.cookie.indexOf(e)>-1)return document.cookie=e.split("=")[0]+"=;domain=."+t+";expires=Thu, 01 Jan 1970 00:00:01 GMT;",t}function Te(){const o=window.location.search,e=new URLSearchParams(o).get("_saasquatch")||"";if(e){let n="",i="",s="";try{n=JSON.parse(N(e))}catch(r){v("Unable to decode params",r);return}try{i=JSON.parse(N(Q("_saasquatch"))),v("existing cookie",i)}catch(r){v("Unable to retrieve cookie",r)}try{const r=We();if(v("domain retrieved:",r),i){const a=le(i,n);s=ce(JSON.stringify(a)),v("cookie to store:",a)}else s=ce(JSON.stringify(n)),v("cookie to store:",n);Se("_saasquatch",s,{expires:365,secure:!1,sameSite:"Lax",domain:r,path:"/"})}catch(r){v("Unable to set cookie",r)}}}const k="https://app.referralsaasquatch.com",Y="https://fast.ssqt.io/npm",L="squatch",X="impact";function P(o){if(typeof o!="object")throw new Error("config must be an object");const t=window.squatchTenant,e=K(),n={tenantAlias:(o==null?void 0:o.tenantAlias)||t,domain:(o==null?void 0:o.domain)||(e==null?void 0:e.domain),npmCdn:(o==null?void 0:o.npmCdn)||(e==null?void 0:e.npmCdn),debug:(o==null?void 0:o.debug)||(e==null?void 0:e.debug)};if(typeof n.tenantAlias!="string")throw new Error("tenantAlias not provided");const i=n.tenantAlias,s=typeof n.domain=="string"&&n.domain||k,r=typeof n.debug=="boolean"&&n.debug||!1,a=typeof n.npmCdn=="string"&&n.npmCdn||Y;return{tenantAlias:i,domain:s,debug:r,npmCdn:a}}function S(o){return typeof o=="object"&&!Array.isArray(o)&&o!==null}function $e(o){if(o&&/^[a-z]{2}_(?:[A-Z]{2}|[0-9]{3})$/.test(o))return o}function he(o){if(!S(o))throw new Error("Widget properties must be an object");if(!(o!=null&&o.user))throw new Error("Required properties missing.");return o}function ue(o){if(!S(o))throw new Error("Widget properties must be an object");return o}function U(){return window.impactToken||window.squatchToken}function K(){return window.impactConfig||window.squatchConfig}const me=C("squatch-js:io");function G(o){let t,e,n,i=o;try{const r=JSON.parse(o);r&&typeof r=="object"&&(t=r.apiErrorCode,e=r.rsCode,n=r.statusCode,i=r.message||o)}catch{}const s=new Error(i);return t&&(s.apiErrorCode=t),e&&(s.rsCode=e),n!==void 0&&(s.statusCode=n),s}async function qe(o,t,e,n){const i=n||U(),s={Accept:"application/json","Content-Type":"application/json",...i?{Authorization:`Bearer ${i}`}:{},"X-SaaSquatch-Referrer":window?window.location.href:""};try{const r=await fetch(o,{method:"POST",body:JSON.stringify({query:t,variables:e}),headers:s});if(!r.ok)throw G(await r.text());return await r.json()}catch(r){throw r}}async function xe(o,t=""){const e={Accept:"application/json","Content-Type":"application/json"},n=t||U();n?e["X-SaaSquatch-User-Token"]=n:me("[DEBUG] doGet - No token found, proceeding without authentication header.");try{const i=await fetch(o,{method:"GET",credentials:"include",headers:e}),s=await i.text();if(!i.ok)throw G(s);return s&&JSON.parse(s)}catch(i){throw i}}async function Z(o,t,e){const n={Accept:"application/json","Content-Type":"application/json"},i=e||U();i?n["X-SaaSquatch-User-Token"]=i:me("[DEBUG] doPost - No token found, proceeding without authentication header.");try{const s=await fetch(o,{method:"POST",body:t,headers:n}),r=await s.text();if(!s.ok)throw G(r);return r&&JSON.parse(r)}catch(s){throw s}}async function Me(o,t,e){const n={Accept:"application/json","Content-Type":"application/json","X-SaaSquatch-Referrer":window?window.location.href:""},i=e||U();i&&(n["X-SaaSquatch-User-Token"]=i);try{const s=await fetch(o,{headers:n,method:"PUT",credentials:"include",body:t}),r=await s.text();if(!s.ok)throw G(r);return r&&JSON.parse(r)}catch(s){throw s}}const Pe=`
2
2
  query renderWidget ($user: UserIdInput, $engagementMedium: UserEngagementMedium, $widgetType: WidgetType, $locale: RSLocale) {
3
3
  renderWidget(user: $user, engagementMedium: $engagementMedium, widgetType: $widgetType, locale: $locale) {
4
4
  template
@@ -12,350 +12,41 @@
12
12
  }
13
13
  }
14
14
  }
15
- `;class z{constructor(t){l(this,"tenantAlias");l(this,"domain");l(this,"npmCdn");l(this,"referralCookie",this.squatchReferralCookie);const n=q(t);this.tenantAlias=n.tenantAlias,this.domain=n.domain,this.npmCdn=n.npmCdn}upsertUser(t){const n=ue(t),{widgetType:i,engagementMedium:s="POPUP",jwt:r,locale:a,user:d}=n,c=encodeURIComponent(this.tenantAlias),h=d.accountId?encodeURIComponent(d.accountId):null,u=d.id?encodeURIComponent(d.id):null,p=Pe({widgetType:i,engagementMedium:s,locale:a}),m=`/api/v1/${c}/widget/account/${h}/user/${u}/upsert${p}`,g=this.domain+m,w=(j||window.Cookies).get("_saasquatch");return w&&(d.cookies=w),qe(g,JSON.stringify(d),r)}render(t){const n=pe(t),{widgetType:i,engagementMedium:s="POPUP",jwt:r,user:a}=n,d=encodeURIComponent(this.tenantAlias),c=a!=null&&a.accountId?encodeURIComponent(a.accountId):null,h=a!=null&&a.id?encodeURIComponent(a.id):null,u=n.locale??$e(navigator.language.replace(/\-/g,"_")),p=`/api/v1/${d}/graphql`,m=this.domain+p;return new Promise(async(g,w)=>{var b;try{const f=await Ue(m,Re,{user:h&&c?{id:h,accountId:c}:null,engagementMedium:s,widgetType:i,locale:u},r);g((b=f==null?void 0:f.data)==null?void 0:b.renderWidget)}catch(f){w(f)}})}async squatchReferralCookie(){const t=encodeURIComponent(this.tenantAlias),e=(j||window.Cookies).get("_saasquatch")||"",n=e?`?cookies=${encodeURIComponent(e)}`:"",i=`${this.domain}/a/${t}/widgets/squatchcookiejson${n}`,s=await Se(i);return Promise.resolve({...s,encodedCookie:e})}}function Pe({widgetType:o,engagementMedium:t,locale:e}){const n=new URLSearchParams;return n.append("engagementMedium",t),o&&n.append("widgetType",o),e&&n.append("locale",e),`?${n.toString()}`}/*!
15
+ `;class z{constructor(t){l(this,"tenantAlias");l(this,"domain");l(this,"npmCdn");l(this,"referralCookie",this.squatchReferralCookie);const n=P(t);this.tenantAlias=n.tenantAlias,this.domain=n.domain,this.npmCdn=n.npmCdn}upsertUser(t){const n=he(t),{widgetType:i,engagementMedium:s="POPUP",jwt:r,locale:a,user:c}=n,d=encodeURIComponent(this.tenantAlias),h=c.accountId?encodeURIComponent(c.accountId):null,u=c.id?encodeURIComponent(c.id):null,m=Ue({widgetType:i,engagementMedium:s,locale:a}),p=`/api/v1/${d}/widget/account/${h}/user/${u}/upsert${m}`,g=this.domain+p,f=Q("_saasquatch");return f&&(c.cookies=f),Me(g,JSON.stringify(c),r)}render(t){const n=ue(t),{widgetType:i,engagementMedium:s="POPUP",jwt:r,user:a}=n,c=encodeURIComponent(this.tenantAlias),d=a!=null&&a.accountId?encodeURIComponent(a.accountId):null,h=a!=null&&a.id?encodeURIComponent(a.id):null,u=n.locale??$e(navigator.language.replace(/\-/g,"_")),m=`/api/v1/${c}/graphql`,p=this.domain+m;return new Promise(async(g,f)=>{var b;try{const w=await qe(p,Pe,{user:h&&d?{id:h,accountId:d}:null,engagementMedium:s,widgetType:i,locale:u},r);g((b=w==null?void 0:w.data)==null?void 0:b.renderWidget)}catch(w){f(w)}})}async squatchReferralCookie(){const t=encodeURIComponent(this.tenantAlias),e=Q("_saasquatch")||"",n=e?`?cookies=${encodeURIComponent(e)}`:"",i=`${this.domain}/a/${t}/widgets/squatchcookiejson${n}`,s=await xe(i);return Promise.resolve({...s,encodedCookie:e})}}function Ue({widgetType:o,engagementMedium:t,locale:e}){const n=new URLSearchParams;return n.append("engagementMedium",t),o&&n.append("widgetType",o),e&&n.append("locale",e),`?${n.toString()}`}/*!
16
16
  * domready (c) Dustin Diaz 2014 - License MIT
17
17
  *
18
- */function Z(o,t){let e=[],n,i=o,s=i.documentElement.doScroll,r="DOMContentLoaded",a=(s?/^loaded|^c/:/^loaded|^i|^c/).test(i.readyState);return a||i.addEventListener(r,n=()=>{for(i.removeEventListener(r,n),a=!0;n=e.shift();)n()}),a?setTimeout(t,0):e.push(t)}function N({value:o,unit:t}){switch(t){case"px":return`${o}px`;case"%":return`${o}%`;default:return`${o}px`}}class ge{constructor(t){l(this,"domain");var i;const n=Me(t);this.domain=(n==null?void 0:n.domain)||((i=ee())==null?void 0:i.domain)||A}pushAnalyticsLoadEvent(t){if(!t.externalUserId||!t.externalAccountId)return;const e=encodeURIComponent(t.tenantAlias),n=encodeURIComponent(t.externalAccountId),i=encodeURIComponent(t.externalUserId),s=encodeURIComponent(t.engagementMedium),r=t.programId?`&programId=${encodeURIComponent(t.programId)}`:"",a=`/a/${e}/widgets/analytics/loaded?externalAccountId=${n}&externalUserId=${i}&engagementMedium=${s}${r}`,d=this.domain+a;return K(d,JSON.stringify({}))}pushAnalyticsShareClickedEvent(t){const e=encodeURIComponent(t.tenantAlias),n=encodeURIComponent(t.externalAccountId),i=encodeURIComponent(t.externalUserId),s=encodeURIComponent(t.engagementMedium),r=encodeURIComponent(t.shareMedium),a=`/a/${e}/widgets/analytics/shared?externalAccountId=${n}&externalUserId=${i}&engagementMedium=${s}&shareMedium=${r}`,d=this.domain+a;return K(d,JSON.stringify({}))}}function Me(o){if(!I(o))throw new Error("'options' should be an object");return o}const me=({type:o="verified-access",height:t="500px"})=>{const e="#e0e0e0";return`
19
- <style>
20
- * {
21
- box-sizing: border-box;
22
- padding: 0;
23
- margin: 0;
24
- }
25
-
26
- .widget-container {
27
- background: white;
28
- width: 100%;
29
- padding: 40px;
30
- box-sizing: border-box;
31
- overflow: hidden;
32
- }
33
-
34
- @keyframes shimmer {
35
- 0% { background-position: -100% 0; }
36
- 100% { background-position: 100% 0; }
37
- }
38
-
39
- .skeleton {
40
- background: ${e};
41
- background: linear-gradient(
42
- 90deg,
43
- ${e} 25%,
44
- #f5f5f5 50%,
45
- ${e} 75%
46
- );
47
- background-size: 200% 100%;
48
- animation: shimmer 1.5s infinite linear;
49
- border-radius: 6px;
50
- margin-bottom: 12px;
51
- }
52
-
53
- /* Typography Skeletons */
54
- .sk-title-lg { height: 36px; width: 80%; margin-bottom: 16px; }
55
- .sk-title-md { height: 28px; width: 30%; margin-bottom: 20px; margin-top: 40px; }
56
- .sk-text { height: 16px; width: 90%; margin-bottom: 8px; }
57
- .sk-text-short { width: 40%; }
58
- .sk-label { height: 14px; width: 25%; margin-bottom: 10px; }
59
-
60
- /* Layouts */
61
- .hero-section {
62
- display: flex;
63
- gap: 40px;
64
- margin-bottom: 40px;
65
- padding-bottom: 40px;
66
- flex-direction: row;
67
- height: 100%;
68
- /* Removed border-bottom */
69
- }
70
-
71
- .hero-content {
72
- flex: 1;
73
- display: flex;
74
- flex-direction: column;
75
- justify-content: center;
76
- }
77
-
78
- .hero-image {
79
- flex: 1;
80
- height: 300px;
81
- border-radius: 12px;
82
- }
83
-
84
- /* -- Specific Instant Access Overrides -- */
85
- .instant-access-layout {
86
- margin-bottom: 0;
87
- padding-bottom: 0;
88
- align-items: center;
89
- }
90
- .ia-image {
91
- height: 400px;
92
- }
93
- .ia-center {
94
- margin-left: auto;
95
- margin-right: auto;
96
- }
97
- .ia-content {
98
- align-items: center;
99
- text-align: center;
100
- }
101
- .sk-btn-action {
102
- height: 45px;
103
- width: 140px;
104
- border-radius: 6px;
105
- margin: 24px auto;
106
- }
107
- .input-group {
108
- display: flex;
109
- gap: 10px;
110
- width: 100%;
111
- max-width: 400px;
112
- }
113
- .sk-btn-copy {
114
- height: 50px;
115
- width: 120px;
116
- border-radius: 8px;
117
- }
118
- /* ------------------------------------- */
119
-
120
- .share-section { margin-bottom: 40px; }
121
- .sk-input { height: 50px; width: 100%; border-radius: 8px; margin-bottom: 16px; }
122
-
123
- .social-buttons { display: flex; gap: 12px; }
124
- .sk-btn-social { flex: 1; height: 50px; border-radius: 8px; }
125
-
126
- .stats-section {
127
- display: flex;
128
- gap: 24px;
129
- margin-bottom: 40px;
130
- padding: 30px 0;
131
- /* Removed border-top and border-bottom */
132
- }
133
- .stat-card { flex: 1; display: flex; flex-direction: column; align-items: center; }
134
- .stat-divider { padding-left: 24px; }
135
- .sk-stat-num { height: 48px; width: 120px; margin-bottom: 8px; }
136
- .sk-stat-label { height: 18px; width: 80px; }
137
-
138
- /* Table Styles */
139
- .table-header { display: flex; gap: 16px; margin-bottom: 16px; }
140
- .sk-th { height: 16px; }
141
- .table-row {
142
- display: flex;
143
- align-items: center;
144
- gap: 16px;
145
- padding: 16px 0;
146
- /* Removed border-bottom */
147
- }
148
-
149
- .col-user { flex: 2; }
150
- .col-status { flex: 1; }
151
- .col-reward { flex: 2; }
152
- .col-date { flex: 1; }
153
-
154
- .sk-badge { height: 28px; width: 90px; border-radius: 14px; }
155
- .sk-reward-block { height: 36px; width: 100%; border-radius: 6px; }
156
-
157
- .pagination { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }
158
- .sk-btn-page { height: 36px; width: 64px; border-radius: 6px; margin-bottom: 0; }
159
-
160
- @media (max-width: 768px) {
161
- body { padding: 20px; }
162
- .widget-container { padding: 24px; }
163
-
164
- .hero-section { flex-direction: column-reverse; gap: 24px; }
165
- .instant-access-layout { flex-direction: column; }
166
-
167
- .hero-image { height: 220px; width: 100%; }
168
- .sk-title-lg { width: 100%; }
169
-
170
- .col-date { display: none; }
171
- }
172
- </style>
173
-
174
- <div class="widget-container">
175
- ${o==="verified-access"?`
176
- <div class="hero-section">
177
- <div class="hero-content">
178
- <div class="skeleton sk-title-lg"></div>
179
- <div class="skeleton sk-text"></div>
180
- <div class="skeleton sk-text sk-text-short"></div>
181
- </div>
182
- <div class="skeleton hero-image"></div>
183
- </div>
184
-
185
- <div class="share-section">
186
- <div class="skeleton sk-label"></div>
187
- <div class="skeleton sk-input"></div>
188
- <div class="social-buttons">
189
- <div class="skeleton sk-btn-social"></div>
190
- <div class="skeleton sk-btn-social"></div>
191
- <div class="skeleton sk-btn-social"></div>
192
- <div class="skeleton sk-btn-social"></div>
18
+ */function $(o,t){let e=[],n,i=o,s=i.documentElement.doScroll,r="DOMContentLoaded",a=(s?/^loaded|^c/:/^loaded|^i|^c/).test(i.readyState);return a||i.addEventListener(r,n=()=>{for(i.removeEventListener(r,n),a=!0;n=e.shift();)n()}),a?setTimeout(t,0):e.push(t)}function F({value:o,unit:t}){switch(t){case"px":return`${o}px`;case"%":return`${o}%`;default:return`${o}px`}}class ge{constructor(t){l(this,"domain");var i;const n=Re(t);this.domain=(n==null?void 0:n.domain)||((i=K())==null?void 0:i.domain)||k}pushAnalyticsLoadEvent(t){if(!t.externalUserId||!t.externalAccountId)return;const e=window.location.search,n=new URLSearchParams(e),i=n==null?void 0:n.get("rsShareMedium"),s=encodeURIComponent(t.tenantAlias),r=encodeURIComponent(t.externalAccountId),a=encodeURIComponent(t.externalUserId),c=encodeURIComponent(t.engagementMedium),d=t.programId?`&programId=${encodeURIComponent(t.programId)}`:"",h=i?`&shareMedium=${encodeURIComponent(i)}`:"",u=`/a/${s}/widgets/analytics/loaded?externalAccountId=${r}&externalUserId=${a}&engagementMedium=${c}${h}${d}`,m=this.domain+u;return Z(m,JSON.stringify({}))}pushAnalyticsShareClickedEvent(t){const e=encodeURIComponent(t.tenantAlias),n=encodeURIComponent(t.externalAccountId),i=encodeURIComponent(t.externalUserId),s=encodeURIComponent(t.engagementMedium),r=encodeURIComponent(t.shareMedium),a=`/a/${e}/widgets/analytics/shared?externalAccountId=${n}&externalUserId=${i}&engagementMedium=${s}&shareMedium=${r}`,c=this.domain+a;return Z(c,JSON.stringify({}))}}function Re(o){if(!S(o))throw new Error("'options' should be an object");return o}const y=C("squatch-js:widget");class pe{constructor(t){l(this,"type");l(this,"content");l(this,"analyticsApi");l(this,"widgetApi");l(this,"context");l(this,"npmCdn");l(this,"container");l(this,"loadEventListener",null);l(this,"errorInfo");var e;y("widget initializing ..."),t.content==="error"?(this.content="error",this.errorInfo={rsCode:t.rsCode,apiErrorCode:t.apiErrorCode,statusCode:t.statusCode,message:t.errorMessage}):this.content=t.content,this.type=t.type,this.widgetApi=t.api,this.npmCdn=t.npmCdn,this.analyticsApi=new ge({domain:t.domain}),this.context=t.context,this.container=((e=t.context)==null?void 0:e.container)||t.container}async _getContent(){if(this.content==="error"&&this.errorInfo){const{getErrorTemplate:t}=await Promise.resolve().then(()=>require("./ErrorTemplate-DumOlC5f.cjs"));return t({rsCode:this.errorInfo.rsCode,apiErrorCode:this.errorInfo.apiErrorCode,statusCode:this.errorInfo.statusCode,mode:this._getErrorMode(),style:this._getErrorStyle(),message:this.errorInfo.message})}return this.content}_getErrorMode(){return"modal"}_getErrorStyle(){return""}_findElement(){let t;if(typeof this.container=="string"?(t=document.querySelector(this.container),y("loading widget with selector",t)):this.container instanceof HTMLElement?(t=this.container,y("loading widget with container",t)):this.container?(t=null,y("container must be an HTMLElement or string",this.container)):(t=document.querySelector("#squatchembed")||document.querySelector(".squatchembed")||document.querySelector("#impactembed")||document.querySelector(".impactembed"),y("loading widget with default selector",t)),!(t instanceof HTMLElement))throw new Error(`element with selector '${this.container||"#squatchembed, .squatchembed, #impactembed, or .impactembed"}' not found.'`);return t}_createFrame(t){const e=document.createElement("iframe");return e.squatchJsApi=this,e.id="squatchFrame",e.width="100%",e.src="about:blank",e.scrolling="no",e.setAttribute("style","border: 0; background-color: none; width: 1px; min-width: 100%; display: block;"),t!=null&&t.minWidth&&(e.style.minWidth=t.minWidth),t!=null&&t.maxWidth&&(e.style.maxWidth=t.maxWidth),(t!=null&&t.maxWidth||t!=null&&t.minWidth)&&(e.style.width="100%"),t!=null&&t.initialHeight&&(e.height=String(t.initialHeight)),e}_findFrame(){const t=this.container?this._findElement():document.body;return(t.shadowRoot||t).querySelector("iframe#squatchFrame")}_detachLoadEventListener(t){this.loadEventListener&&(t.removeEventListener("sq:user-registration",this.loadEventListener),this.loadEventListener=null)}_attachLoadEventListener(t,e){this.loadEventListener===null&&(this.loadEventListener=n=>{this._loadEvent({...e,userId:n.detail.userId,accountId:n.detail.accountId})},t.addEventListener("sq:user-registration",this.loadEventListener))}_loadEvent(t){var n;if(!t)return;if(!S(t))throw new Error("Widget Load event identity property is not an object");let e;if("programId"in t){if(!t.tenantAlias||!t.accountId||!t.userId||!t.engagementMedium)throw new Error("Widget Load event missing required properties");e={tenantAlias:t.tenantAlias,externalAccountId:t.accountId,externalUserId:t.userId,engagementMedium:t.engagementMedium,programId:t.programId}}else{const{analytics:i,mode:s}=t;e={tenantAlias:i.attributes.tenant,externalAccountId:i.attributes.accountId,externalUserId:i.attributes.userId,engagementMedium:s.widgetMode}}(n=this.analyticsApi.pushAnalyticsLoadEvent(e))==null||n.then(i=>{y(`${e.engagementMedium} loaded event recorded.`)}).catch(i=>{y(`ERROR: pushAnalyticsLoadEvent() ${i}`)})}_shareEvent(t,e){t&&this.analyticsApi.pushAnalyticsShareClickedEvent({tenantAlias:t.analytics.attributes.tenant,externalAccountId:t.analytics.attributes.accountId,externalUserId:t.analytics.attributes.userId,engagementMedium:t.mode.widgetMode,shareMedium:e}).then(n=>{y(`${t.mode.widgetMode} share ${e} event recorded. ${n}`)}).catch(n=>{y(`ERROR: pushAnalyticsShareClickedEvent() ${n}`)})}async _findInnerContainer(t){const{contentWindow:e}=t;if(!e)throw new Error("Squatch.js frame inner frame is empty");const n=e.document;function i(){const r=n.getElementsByTagName("sqh-global-container"),a=n.getElementsByClassName("squatch-container");return r.length>0?r[0]:a.length>0?a[0]:null}let s=null;for(let r=0;r<5&&(s=i(),!s);r++)await Le(100);return s||n.body}async _getSkeletonPreloadHTML(t,e){if(!t)return"";const{getSkeleton:n}=await Promise.resolve().then(()=>require("./SkeletonTemplate-B3Bk4NFu.cjs")),i=this.context.type==="passwordless"?"instant-access":"verified-access",s=n({type:i}),r=new Set,a=/<([a-z][\w]*-[\w-]*)/gi;let c;for(;c=a.exec(this.content);)r.add(c[1].toLowerCase());const d=JSON.stringify([...r]);return`
19
+ <div id="sq-preload" style="visibility: visible; position: absolute; top: 0; left: 0; width: 100%; z-index: 9999; background: ${(e||"white").replace(/[^a-zA-Z0-9#(),.\s%-]/g,"")};">
20
+ ${s}
193
21
  </div>
194
- </div>
195
-
196
- <div class="skeleton sk-title-md" style="margin-top: 0; width: 30%; margin-left: auto; margin-right: auto"></div>
197
- <div class="skeleton sk-text" style="width: 60%; margin-left: auto; margin-right: auto"></div>
198
-
199
- <div class="stats-section">
200
- <div class="stat-card">
201
- <div class="skeleton sk-stat-num"></div>
202
- <div class="skeleton sk-stat-label"></div>
203
- </div>
204
- <div class="stat-card stat-divider">
205
- <div class="skeleton sk-stat-num"></div>
206
- <div class="skeleton sk-stat-label"></div>
207
- </div>
208
- </div>
209
-
210
- <div class="skeleton sk-title-md"></div>
211
-
212
- <div class="table-header">
213
- <div class="skeleton sk-th col-user"></div>
214
- <div class="skeleton sk-th col-status"></div>
215
- <div class="skeleton sk-th col-reward"></div>
216
- <div class="skeleton sk-th col-date"></div>
217
- </div>
218
-
219
- <div class="table-row">
220
- <div class="col-user"><div class="skeleton sk-text" style="width: 70%; margin: 0"></div></div>
221
- <div class="col-status"><div class="skeleton sk-badge" style="margin: 0"></div></div>
222
- <div class="col-reward"><div class="skeleton sk-reward-block" style="margin: 0"></div></div>
223
- <div class="col-date"><div class="skeleton sk-text" style="width: 80%; margin: 0"></div></div>
224
- </div>
225
-
226
- <div class="table-row">
227
- <div class="col-user"><div class="skeleton sk-text" style="width: 60%; margin: 0"></div></div>
228
- <div class="col-status"><div class="skeleton sk-badge" style="margin: 0"></div></div>
229
- <div class="col-reward"><div class="skeleton sk-reward-block" style="margin: 0"></div></div>
230
- <div class="col-date"><div class="skeleton sk-text" style="width: 80%; margin: 0"></div></div>
231
- </div>
232
-
233
- <div class="table-row">
234
- <div class="col-user"><div class="skeleton sk-text" style="width: 75%; margin: 0"></div></div>
235
- <div class="col-status"><div class="skeleton sk-badge" style="margin: 0"></div></div>
236
- <div class="col-reward"><div class="skeleton sk-reward-block" style="margin: 0"></div></div>
237
- <div class="col-date"><div class="skeleton sk-text" style="width: 80%; margin: 0"></div></div>
238
- </div>
239
-
240
- <div class="pagination">
241
- <div class="skeleton sk-btn-page"></div>
242
- <div class="skeleton sk-btn-page"></div>
243
- </div>
244
- `:`
245
- <div class="hero-section instant-access-layout">
246
- <div class="skeleton hero-image ia-image"></div>
247
-
248
- <div class="hero-content ia-content">
249
- <div class="skeleton sk-title-lg ia-center"></div>
250
- <div class="skeleton sk-text ia-center"></div>
251
-
252
- <div class="skeleton sk-btn-action"></div>
253
-
254
- <div class="skeleton sk-label"></div>
255
- <div class="input-group">
256
- <div class="skeleton sk-input"></div>
257
- <div class="skeleton sk-btn-copy"></div>
258
- </div>
259
-
260
- <div class="skeleton sk-text-short ia-center" style="margin-top: 20px; width: 30%"></div>
261
- <div class="skeleton sk-text-short ia-center" style="width: 20%"></div>
262
- </div>
263
- </div>
264
- `}
265
- </div>
266
- `},Le=Object.freeze(Object.defineProperty({__proto__:null,getSkeleton:me},Symbol.toStringTag,{value:"Module"})),y=k("squatch-js:widget");class fe{constructor(t){l(this,"type");l(this,"content");l(this,"analyticsApi");l(this,"widgetApi");l(this,"context");l(this,"npmCdn");l(this,"container");l(this,"loadEventListener",null);var e;y("widget initializing ..."),this.content=t.content==="error"?this._error({rsCode:t.rsCode,apiErrorCode:t.apiErrorCode,statusCode:t.statusCode,message:t.errorMessage}):t.content,this.type=t.type,this.widgetApi=t.api,this.npmCdn=t.npmCdn,this.analyticsApi=new ge({domain:t.domain}),this.context=t.context,this.container=((e=t.context)==null?void 0:e.container)||t.container}_findElement(){let t;if(typeof this.container=="string"?(t=document.querySelector(this.container),y("loading widget with selector",t)):this.container instanceof HTMLElement?(t=this.container,y("loading widget with container",t)):this.container?(t=null,y("container must be an HTMLElement or string",this.container)):(t=document.querySelector("#squatchembed")||document.querySelector(".squatchembed")||document.querySelector("#impactembed")||document.querySelector(".impactembed"),y("loading widget with default selector",t)),!(t instanceof HTMLElement))throw new Error(`element with selector '${this.container||"#squatchembed, .squatchembed, #impactembed, or .impactembed"}' not found.'`);return t}_createFrame(t){const e=document.createElement("iframe");return e.squatchJsApi=this,e.id="squatchFrame",e.width="100%",e.src="about:blank",e.scrolling="no",e.setAttribute("style","border: 0; background-color: none; width: 1px; min-width: 100%; display: block;"),t!=null&&t.minWidth&&(e.style.minWidth=t.minWidth),t!=null&&t.maxWidth&&(e.style.maxWidth=t.maxWidth),(t!=null&&t.maxWidth||t!=null&&t.minWidth)&&(e.style.width="100%"),t!=null&&t.initialHeight&&(e.height=String(t.initialHeight)),e}_findFrame(){const t=this.container?this._findElement():document.body;return(t.shadowRoot||t).querySelector("iframe#squatchFrame")}_detachLoadEventListener(t){this.loadEventListener&&(t.removeEventListener("sq:user-registration",this.loadEventListener),this.loadEventListener=null)}_attachLoadEventListener(t,e){this.loadEventListener===null&&(this.loadEventListener=n=>{this._loadEvent({...e,userId:n.detail.userId,accountId:n.detail.accountId})},t.addEventListener("sq:user-registration",this.loadEventListener))}_loadEvent(t){var n;if(!t)return;if(!I(t))throw new Error("Widget Load event identity property is not an object");let e;if("programId"in t){if(!t.tenantAlias||!t.accountId||!t.userId||!t.engagementMedium)throw new Error("Widget Load event missing required properties");e={tenantAlias:t.tenantAlias,externalAccountId:t.accountId,externalUserId:t.userId,engagementMedium:t.engagementMedium,programId:t.programId}}else{const{analytics:i,mode:s}=t;e={tenantAlias:i.attributes.tenant,externalAccountId:i.attributes.accountId,externalUserId:i.attributes.userId,engagementMedium:s.widgetMode}}(n=this.analyticsApi.pushAnalyticsLoadEvent(e))==null||n.then(i=>{y(`${e.engagementMedium} loaded event recorded.`)}).catch(i=>{y(`ERROR: pushAnalyticsLoadEvent() ${i}`)})}_shareEvent(t,e){t&&this.analyticsApi.pushAnalyticsShareClickedEvent({tenantAlias:t.analytics.attributes.tenant,externalAccountId:t.analytics.attributes.accountId,externalUserId:t.analytics.attributes.userId,engagementMedium:t.mode.widgetMode,shareMedium:e}).then(n=>{y(`${t.mode.widgetMode} share ${e} event recorded. ${n}`)}).catch(n=>{y(`ERROR: pushAnalyticsShareClickedEvent() ${n}`)})}_error(t,e="modal",n=""){const{rsCode:i,apiErrorCode:s,statusCode:r,message:a}=t||{};return`<!DOCTYPE html>
267
- <!--[if IE 7]><html class="ie7 oldie" lang="en"><![endif]-->
268
- <!--[if IE 8]><html class="ie8 oldie" lang="en"><![endif]-->
269
- <!--[if gt IE 8]><!--><html lang="en"><!--<![endif]-->
270
- <head>
271
- <link rel="stylesheet" media="all" href="https://fast.ssqt.io/assets/css/widget/errorpage.css">
272
- <style>
273
- ${n}
274
- .error-details {
275
- margin-top: 16px;
276
- padding: 12px;
277
- background: #f8f8f8;
278
- border-radius: 4px;
279
- text-align: left;
280
- font-size: 13px;
281
- color: #666;
282
- }
283
- .error-details dt {
284
- font-weight: 600;
285
- color: #333;
286
- margin-top: 8px;
287
- }
288
- .error-details dt:first-child {
289
- margin-top: 0;
290
- }
291
- .error-details dd {
292
- margin: 4px 0 0 0;
293
- word-break: break-word;
294
- font-family: monospace;
295
- }
296
- .error-details dd.message {
297
- font-family: inherit;
298
- }
299
- </style>
300
- </head>
301
- <body>
302
-
303
- <div class="squatch-container ${e}" style="width:100%">
304
- <div class="errorheader">
305
- <button type="button" class="close" onclick="window.frameElement.squatchJsApi.close();">&times;</button>
306
- <p class="errortitle">Error</p>
307
- </div>
308
- <div class="errorbody">
309
- <div class="sadface"><img src="https://res.cloudinary.com/saasquatch-staging/image/upload/v1774538373/whoops-error-image_km94z1.svg"></div>
310
- <h4>Our referral program is temporarily unavailable.</h4>
311
- <p>Please reload the page or check back later.</p>
312
- <p>If the problem persists please contact our support team.</p>
313
-
314
- ${r||s||i||a?`
315
- <dl class="error-details">
316
- ${r?`<dt>Status Code</dt><dd>${r}</dd>`:""}
317
- ${s?`<dt>API Error Code</dt><dd>${s}</dd>`:""}
318
- ${i?`<dt>RS Code</dt><dd>${i}</dd>`:""}
319
- ${a?`<dt>Message</dt><dd class="message">${a}</dd>`:""}
320
- </dl>
321
- `:""}
322
- </div>
323
- </div>
324
- </body>
325
- </html>`}async _findInnerContainer(t){const{contentWindow:e}=t;if(!e)throw new Error("Squatch.js frame inner frame is empty");const n=e.document;function i(){const r=n.getElementsByTagName("sqh-global-container"),a=n.getElementsByClassName("squatch-container");return r.length>0?r[0]:a.length>0?a[0]:null}let s=null;for(let r=0;r<5&&(s=i(),!s);r++)await Oe(100);return s||n.body}_getSkeletonPreloadHTML(t,e){if(!t)return"";const n=this.context.type==="passwordless"?"instant-access":"verified-access",i=me({type:n,height:"100%"});return`
326
- <div id="sq-preload" style="visibility: visible; position: absolute; top: 0; left: 0; width: 100%; z-index: 9999; background: ${e||"white"};">
327
- ${i}
328
- </div>
329
- <script>(${De.toString()})()<\/script>
330
- `}reload({email:t,firstName:e,lastName:n},i){const s=this._findFrame();if(!s)throw new Error("Could not find widget iframe");const r=s.contentWindow,a=this.context.engagementMedium||"POPUP";if(!r)throw new Error("Frame needs a content window");let d;if(this.context.type==="upsert"){if(!this.context.user)throw new Error("Can't reload without user ids");let c={email:t||null,firstName:e||null,lastName:n||null,id:this.context.user.id,accountId:this.context.user.accountId};d=this.widgetApi.upsertUser({user:c,engagementMedium:a,widgetType:this.type,jwt:i})}else if(this.context.type==="passwordless")d=this.widgetApi.render({user:void 0,engagementMedium:a,widgetType:this.type,jwt:void 0});else throw new Error("can't reload an error widget");d.then(({template:c})=>{c&&(this.content=c,this.__deprecated__register(s,{email:t,engagementMedium:a},()=>{this.load(),a==="POPUP"&&this.open()}))}).catch(({message:c})=>{y(`${c}`)})}__deprecated__register(t,e,n){const s=t.contentWindow.document,r=s.createElement("button"),a=s.getElementsByClassName("squatch-register")[0];if(a){r.className="btn btn-primary",r.id="show-stats-btn",r.textContent=this.type==="REFERRER_WIDGET"?"Show Stats":"Show Reward";const d=e.engagementMedium==="POPUP"?"margin-top: 10px; max-width: 130px; width: 100%;":"margin-top: 10px;";r.setAttribute("style",d),r.onclick=n,a.style.paddingTop="30px",a.innerHTML=`<p><strong>${e.email}</strong><br>Has been successfully registered</p>`,a.appendChild(r)}}}function Oe(o){return new Promise(t=>{setTimeout(t,o)})}function De(){var o=setTimeout(t,1e4);function t(){var n=document.getElementById("sq-preload");n&&n.remove(),clearTimeout(o)}function e(){var n=new Set;if(document.querySelectorAll("*").forEach(function(i){i.tagName.includes("-")&&n.add(i.tagName.toLowerCase())}),!n.size)return t();Promise.all(Array.from(n).map(function(i){return customElements.whenDefined(i)})).then(function(){requestAnimationFrame(function(){requestAnimationFrame(t)})})}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e):setTimeout(e,0)}const x=k("squatch-js:EMBEDwidget");class $ extends fe{constructor(e,n){super(e);l(this,"show",this.open);l(this,"hide",this.close);n&&(this.container=n)}async load(){var g,w,b,f,_,ie,oe,se,re;const e=(w=(g=this.context.widgetConfig)==null?void 0:g.values)==null?void 0:w.brandingConfig,n=(b=this.content)==null?void 0:b.includes("mint-components"),i=(e==null?void 0:e.loadingHeight)||500,s=(f=e==null?void 0:e.widgetSize)==null?void 0:f.embeddedWidgets,r=s!=null&&s.maxWidth?N(s.maxWidth):"",a=s!=null&&s.minWidth?N(s.minWidth):"",d=this._createFrame({minWidth:a,maxWidth:r,initialHeight:i}),c=this._findElement();(_=this.context)!=null&&_.container&&(c.style.visibility="hidden",c.style.height="0",c.style["overflow-y"]="hidden"),this.container?c.shadowRoot?((ie=c.shadowRoot.lastChild)==null?void 0:ie.nodeName)==="IFRAME"?c.shadowRoot.replaceChild(d,c.shadowRoot.lastChild):c.shadowRoot.appendChild(d):c.firstChild?c.replaceChild(d,c.firstChild):c.appendChild(d):(!c.firstChild||c.firstChild.nodeName==="#text")&&c.appendChild(d);const{contentWindow:h}=d;if(!h)throw new Error("Frame needs a content window");const u=h.document;u.open();const m=this.widgetApi.domain==="https://staging.referralsaasquatch.com"?"-staging":"";u.write(`
331
- ${(oe=e==null?void 0:e.main)!=null&&oe.brandFont?`
332
- <link rel="preconnect" href="https://fast${m}.ssqt.io">
333
- <link rel="preconnect" href="https://fonts.gstatic.com">
334
- <link rel="preconnect" href="https://fonts.googleapis.com">
335
- <link rel="preload" href="https://fonts.googleapis.com/css2?family=${encodeURIComponent((se=e==null?void 0:e.main)==null?void 0:se.brandFont)}" as="style">`:""}
22
+ <script>(${Oe.toString()})(${d})<\/script>
23
+ `}reload({email:t,firstName:e,lastName:n},i){const s=this._findFrame();if(!s)throw new Error("Could not find widget iframe");const r=s.contentWindow,a=this.context.engagementMedium||"POPUP";if(!r)throw new Error("Frame needs a content window");let c;if(this.context.type==="upsert"){if(!this.context.user)throw new Error("Can't reload without user ids");let d={email:t||null,firstName:e||null,lastName:n||null,id:this.context.user.id,accountId:this.context.user.accountId};c=this.widgetApi.upsertUser({user:d,engagementMedium:a,widgetType:this.type,jwt:i})}else if(this.context.type==="passwordless")c=this.widgetApi.render({user:void 0,engagementMedium:a,widgetType:this.type,jwt:void 0});else throw new Error("can't reload an error widget");c.then(({template:d})=>{d&&(this.content=d,this.__deprecated__register(s,{email:t,engagementMedium:a},()=>{this.load(),a==="POPUP"&&this.open()}))}).catch(({message:d})=>{y(`${d}`)})}__deprecated__register(t,e,n){const s=t.contentWindow.document,r=s.createElement("button"),a=s.getElementsByClassName("squatch-register")[0];if(a){r.className="btn btn-primary",r.id="show-stats-btn",r.textContent=this.type==="REFERRER_WIDGET"?"Show Stats":"Show Reward";const c=e.engagementMedium==="POPUP"?"margin-top: 10px; max-width: 130px; width: 100%;":"margin-top: 10px;";r.setAttribute("style",c),r.onclick=n,a.style.paddingTop="30px",a.innerHTML=`<p><strong>${e.email}</strong><br>Has been successfully registered</p>`,a.appendChild(r)}}}function Le(o){return new Promise(t=>{setTimeout(t,o)})}function Oe(o){var t=setTimeout(e,1e4);function e(){var i=document.getElementById("sq-preload");i&&i.remove(),clearTimeout(t)}function n(){if(!o||!o.length)return e();Promise.all(o.map(function(i){return customElements.whenDefined(i)})).then(function(){requestAnimationFrame(function(){requestAnimationFrame(e)})})}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",n):setTimeout(n,0)}const A=C("squatch-js:EMBEDwidget");class q extends pe{constructor(e,n){super(e);l(this,"show",this.open);l(this,"hide",this.close);n&&(this.container=n)}async load(){var g,f,b,w,W,ne,ie,oe,se;const e=(f=(g=this.context.widgetConfig)==null?void 0:g.values)==null?void 0:f.brandingConfig,n=(b=this.content)==null?void 0:b.includes("mint-components"),i=(e==null?void 0:e.loadingHeight)||500,s=(w=e==null?void 0:e.widgetSize)==null?void 0:w.embeddedWidgets,r=s!=null&&s.maxWidth?F(s.maxWidth):"",a=s!=null&&s.minWidth?F(s.minWidth):"",c=this._createFrame({minWidth:a,maxWidth:r,initialHeight:i}),d=this._findElement();(W=this.context)!=null&&W.container&&(d.style.visibility="hidden",d.style.height="0",d.style["overflow-y"]="hidden"),this.container?d.shadowRoot?((ne=d.shadowRoot.lastChild)==null?void 0:ne.nodeName)==="IFRAME"?d.shadowRoot.replaceChild(c,d.shadowRoot.lastChild):d.shadowRoot.appendChild(c):d.firstChild?d.replaceChild(c,d.firstChild):d.appendChild(c):(!d.firstChild||d.firstChild.nodeName==="#text")&&d.appendChild(c);const{contentWindow:h}=c;if(!h)throw new Error("Frame needs a content window");const u=h.document;if(u.open(),this.content==="error"){u.write(await this._getContent()),u.close(),$(u,()=>{c.height=u.body.scrollHeight});return}const p=this.widgetApi.domain==="https://staging.referralsaasquatch.com"?"-staging":"";u.write(`
24
+ ${(ie=e==null?void 0:e.main)!=null&&ie.brandFont?`
25
+ <link rel="preconnect" href="https://fast${p}.ssqt.io">
26
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
27
+ <link rel="preconnect" href="https://fonts.googleapis.com" crossorigin>
28
+ <link rel="preload" href="https://fonts.googleapis.com/css2?family=${encodeURIComponent((oe=e==null?void 0:e.main)==null?void 0:oe.brandFont)}" as="style">`:""}
336
29
  <link rel="dns-prefetch" href="https://res.cloudinary.com">
337
30
  <link rel="preconnect" href="https://res.cloudinary.com" crossorigin>
338
31
  ${n?`
339
32
  <style data-styles>
340
33
  html { visibility: hidden; }
341
34
  </style>`:""}
342
- ${this._getSkeletonPreloadHTML(n,(re=e==null?void 0:e.color)==null?void 0:re.backgroundColor)}
343
- ${this.content}
344
- <script src="${this.npmCdn}/resize-observer-polyfill@1.5.x"><\/script>
345
- `),u.close(),Z(u,async()=>{const ae=h.squatch||h.widgetIdent;d.height=i;const ke=new h.ResizeObserver(Ee=>{for(const xe of Ee){const{height:Ce}=xe.contentRect;d.height=Ce}}),be=await this._findInnerContainer(d);ke.observe(be),this._shouldFireLoadEvent()?(this._loadEvent(ae),x("loaded")):u&&this._attachLoadEventListener(u,ae)})}open(){const e=this._findFrame();if(!e)return x("no target element to open");if(!e.contentWindow)return x("Frame needs a content window");const n=this._findElement();n.style.visibility="unset",n.style.height="auto",n.style["overflow-y"]="auto",e.contentWindow.document.dispatchEvent(new CustomEvent("sq:refresh"));const i=e.contentWindow.squatch||e.contentWindow.widgetIdent;if(this.context.user)this._loadEvent(i),x("loaded");else{if(!e.contentDocument)return;this._attachLoadEventListener(e.contentDocument,i)}}close(){const e=this._findFrame();if(!e)return x("no target element to close");e.contentDocument&&this._detachLoadEventListener(e.contentDocument);const n=this._findElement();n.style.visibility="hidden",n.style.height="0",n.style["overflow-y"]="hidden",x("Embed widget closed")}_error(e,n="embed",i=""){return super._error(e,n,i)}_shouldFireLoadEvent(){const e=!this.container,n=this.container instanceof HTMLElement&&(this.container.tagName.startsWith("SQUATCH-")||this.container.tagName.startsWith("IMPACT-"));return!!this.context.user&&(e||n)}}const W=k("squatch-js:POPUPwidget");let O=0;class U extends fe{constructor(e,n=".squatchpop"){super(e);l(this,"trigger");l(this,"id");l(this,"show",this.open);l(this,"hide",this.close);this.trigger=n,this.container?this.id="squatchModal":(this.id=O===0?"squatchModal":`squatchModal__${O}`,O=O+1),document.head.insertAdjacentHTML("beforeend",`<style>#${this.id}::-webkit-scrollbar { display: none; }</style>`)}_initialiseCTA(){if(!this.trigger)return;let e;try{e=document.querySelector(this.trigger)||document.querySelector(".impactpop"),this.trigger&&!e&&W("No element found with trigger selector",this.trigger)}catch{W("Not a valid selector",this.trigger)}e&&(e.onclick=()=>{this.open()})}_createPopupDialog(e){var d;const n=document.createElement("dialog"),i=(d=e==null?void 0:e.widgetSize)==null?void 0:d.popupWidgets,s=i!=null&&i.minWidth?N(i.minWidth):"auto",r=i!=null&&i.maxWidth?N(i.maxWidth):"500px";n.id=this.id,n.setAttribute("style",`width: 100%; min-width: ${s}; max-width: ${r}; border: none; padding: 0;`);const a=c=>{c.stopPropagation(),c.target===n&&n.close()};return n.addEventListener("click",a),n}async load(){var p,m,g,w,b,f,_;const e=(m=(p=this.context.widgetConfig)==null?void 0:p.values)==null?void 0:m.brandingConfig,n=(e==null?void 0:e.loadingHeight)||500,i=(g=this.content)==null?void 0:g.includes("mint-components"),s=this._createFrame();s.style.height=n+"px",this._initialiseCTA();const r=this.container?this._findElement():document.body,a=(r==null?void 0:r.shadowRoot)||r,d=this._createPopupDialog(e);d.appendChild(s),((w=a.lastChild)==null?void 0:w.nodeName)==="DIALOG"?a.replaceChild(d,a.lastChild):a.appendChild(d);const{contentWindow:c}=s;if(!c)throw new Error("Frame needs a content window");const h=c.document;h.open();const u=this.widgetApi.domain;h.write(`
35
+ ${await this._getSkeletonPreloadHTML(n,(se=e==null?void 0:e.color)==null?void 0:se.backgroundColor)}
36
+ ${await this._getContent()}
37
+ `),u.close(),$(u,async()=>{const re=h.squatch||h.widgetIdent;c.height=i;const ye=new h.ResizeObserver(Ce=>{for(const be of Ce){const{height:ve}=be.contentRect;c.height=ve}}),Ee=await this._findInnerContainer(c);ye.observe(Ee),this._shouldFireLoadEvent()?(this._loadEvent(re),A("loaded")):u&&this._attachLoadEventListener(u,re)})}open(){const e=this._findFrame();if(!e)return A("no target element to open");if(!e.contentWindow)return A("Frame needs a content window");const n=this._findElement();n.style.visibility="unset",n.style.height="auto",n.style["overflow-y"]="auto",e.contentWindow.document.dispatchEvent(new CustomEvent("sq:refresh"));const i=e.contentWindow.squatch||e.contentWindow.widgetIdent;if(this.context.user)this._loadEvent(i),A("loaded");else{if(!e.contentDocument)return;this._attachLoadEventListener(e.contentDocument,i)}}close(){const e=this._findFrame();if(!e)return A("no target element to close");e.contentDocument&&this._detachLoadEventListener(e.contentDocument);const n=this._findElement();n.style.visibility="hidden",n.style.height="0",n.style["overflow-y"]="hidden",A("Embed widget closed")}_getErrorMode(){return"embed"}_shouldFireLoadEvent(){const e=!this.container,n=this.container instanceof HTMLElement&&(this.container.tagName.startsWith("SQUATCH-")||this.container.tagName.startsWith("IMPACT-"));return!!this.context.user&&(e||n)}}const I=C("squatch-js:POPUPwidget");let O=0;class x extends pe{constructor(e,n=".squatchpop"){super(e);l(this,"trigger");l(this,"id");l(this,"show",this.open);l(this,"hide",this.close);this.trigger=n,this.container?this.id="squatchModal":(this.id=O===0?"squatchModal":`squatchModal__${O}`,O=O+1),document.head.insertAdjacentHTML("beforeend",`<style>#${this.id}::-webkit-scrollbar { display: none; }</style>`)}_initialiseCTA(){if(!this.trigger)return;let e;try{e=document.querySelector(this.trigger)||document.querySelector(".impactpop"),this.trigger&&!e&&I("No element found with trigger selector",this.trigger)}catch{I("Not a valid selector",this.trigger)}e&&(e.onclick=()=>{this.open()})}_createPopupDialog(e){var c;const n=document.createElement("dialog"),i=(c=e==null?void 0:e.widgetSize)==null?void 0:c.popupWidgets,s=i!=null&&i.minWidth?F(i.minWidth):"auto",r=i!=null&&i.maxWidth?F(i.maxWidth):"500px";n.id=this.id,n.setAttribute("style",`width: 100%; min-width: ${s}; max-width: ${r}; border: none; padding: 0;`);const a=d=>{d.stopPropagation(),d.target===n&&n.close()};return n.addEventListener("click",a),n}async load(){var m,p,g,f,b,w,W;const e=(p=(m=this.context.widgetConfig)==null?void 0:m.values)==null?void 0:p.brandingConfig,n=(e==null?void 0:e.loadingHeight)||500,i=(g=this.content)==null?void 0:g.includes("mint-components"),s=this._createFrame();s.style.height=n+"px",this._initialiseCTA();const r=this.container?this._findElement():document.body,a=(r==null?void 0:r.shadowRoot)||r,c=this._createPopupDialog(e);c.appendChild(s),((f=a.lastChild)==null?void 0:f.nodeName)==="DIALOG"?a.replaceChild(c,a.lastChild):a.appendChild(c);const{contentWindow:d}=s;if(!d)throw new Error("Frame needs a content window");const h=d.document;if(h.open(),this.content==="error"){h.write(await this._getContent()),h.close(),$(h,()=>{s.height=h.body.scrollHeight}),I("Popup error template loaded into iframe");return}const u=this.widgetApi.domain;h.write(`
346
38
  ${(b=e==null?void 0:e.main)!=null&&b.brandFont?`
347
39
  <link rel="preconnect" href="https://fast${u==="https://staging.referralsaasquatch.com"?"-staging":""}.ssqt.io">
348
- <link rel="preconnect" href="https://fonts.gstatic.com">
40
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
349
41
  <link rel="preconnect" href="https://fonts.googleapis.com">
350
- <link rel="preload" href="https://fonts.googleapis.com/css2?family=${encodeURIComponent((f=e==null?void 0:e.main)==null?void 0:f.brandFont)}" as="style">`:""}
42
+ <link rel="preload" href="https://fonts.googleapis.com/css2?family=${encodeURIComponent((w=e==null?void 0:e.main)==null?void 0:w.brandFont)}" as="style">`:""}
351
43
  <link rel="dns-prefetch" href="https://res.cloudinary.com">
352
44
  <link rel="preconnect" href="https://res.cloudinary.com" crossorigin>
353
45
  ${i?`
354
46
  <style data-styles>
355
47
  html { visibility: hidden; }
356
48
  </style>`:""}
357
- ${this._getSkeletonPreloadHTML(i,(_=e==null?void 0:e.color)==null?void 0:_.backgroundColor)}
358
- ${this.content}
359
- <script src="${this.npmCdn}/resize-observer-polyfill@1.5.x"><\/script>
360
- `),h.close(),W("Popup template loaded into iframe"),await this._setupResizeHandler(s)}async _setupResizeHandler(e){const{contentWindow:n}=e;if(!n)throw new Error("Frame needs a content window");const i=n.document;Z(i,async()=>{i.body.style.overflowY="hidden";let s=!0;new n.ResizeObserver(a=>{for(const d of a){const{top:c,bottom:h}=d.contentRect,u=h+c;u<=0||(s?(s=!1,e.style.height="0",e.height=i.body.scrollHeight+"",e.style.height=""):e.height=u+"",d.target.style="")}}).observe(await this._findInnerContainer(e))})}open(){const e=this.container?this._findElement():document.body,i=(e.shadowRoot||e).querySelector(`#${this.id}`);if(!i)throw new Error("Could not determine container div");i.showModal();const s=this._findFrame();if(!s)throw new Error("Could not find iframe");const{contentWindow:r}=s;if(!r)throw new Error("Squatch.js has an empty iframe");const a=r.document;Z(a,()=>{var c;const d=r.squatch||r.widgetIdent;(c=s.contentDocument)==null||c.dispatchEvent(new CustomEvent("sq:refresh")),this.context.user?(this._loadEvent(d),W("Popup opened")):this._attachLoadEventListener(a,d)})}close(){const e=this._findFrame();e!=null&&e.contentDocument&&this._detachLoadEventListener(e.contentDocument);const n=this.container?this._findElement():document.body,s=(n.shadowRoot||n).querySelector(`#${this.id}`);if(!s)throw new Error("Could not determine container div");s.close(),W("Popup closed")}_clickedOutside({target:e}){}_error(e,n="modal",i=""){return super._error(e,n,i||"body { margin: 0; } .modal { box-shadow: none; border: 0; }")}}const v=k("squatch-js:widgets");class S{constructor(t){l(this,"api");l(this,"tenantAlias");l(this,"domain");l(this,"npmCdn");const e=q(t);this.tenantAlias=e.tenantAlias,this.domain=e.domain,this.npmCdn=e.npmCdn,this.api=new z(e)}async upsertUser(t){const n=ue(t);try{const i=await this.api.upsertUser(n);return{widget:this._renderWidget(i,n,{type:"upsert",user:n.user,engagementMedium:t.engagementMedium,container:t.container,trigger:t.trigger,widgetConfig:{values:{brandingConfig:i==null?void 0:i.brandingConfig}}}),user:i.user}}catch(i){throw console.log("[DEBUG] Widgets.upsertUser catch - err:",i),console.log("[DEBUG] Widgets.upsertUser catch - typeof err:",typeof i),console.log("[DEBUG] Widgets.upsertUser catch - err.apiErrorCode:",i.apiErrorCode),console.log("[DEBUG] Widgets.upsertUser catch - err keys:",Object.keys(i||{})),v(i),i.apiErrorCode&&(console.log("[DEBUG] Widgets.upsertUser - calling _renderErrorWidget"),this._renderErrorWidget(i,t.engagementMedium)),new Error(i)}}async render(t){const n=pe(t);try{const i=await this.api.render(n);return{widget:this._renderWidget(i,n,{type:"passwordless",engagementMedium:n.engagementMedium,container:n.container,trigger:n.trigger,widgetConfig:i==null?void 0:i.widgetConfig}),user:i.user}}catch(i){throw i.apiErrorCode&&this._renderErrorWidget(i,n.engagementMedium),new Error(i)}}async autofill(t){const e=t;if(typeof e=="function"){try{const s=await this.api.squatchReferralCookie();e(s)}catch(s){throw v("Autofill error",s),new Error(s)}return}if(typeof e!="string")throw new Error("Autofill accepts a string or function");let n=document.querySelectorAll(e),i;if(n.length>0)i=n[0];else throw v("Element id/class or function missing"),new Error("Element id/class or function missing");try{const s=await this.api.squatchReferralCookie();i.value=s.codes[0]}catch(s){throw new Error(s)}}_renderWidget(t,e,n){var d;if(v("Rendering Widget..."),!t)throw new Error("Unable to get a response");let i,s=!!e.displayOnLoad;const r=t.jsOptions||{},a={content:t.template,type:e.widgetType||((d=r.widget)==null?void 0:d.defaultWidgetType),api:this.api,domain:this.domain,npmCdn:this.npmCdn,context:n};return r.widgetUrlMappings&&r.widgetUrlMappings.forEach(c=>{var h,u;S._matchesUrl(c.url)&&(c.widgetType!=="CONVERSION_WIDGET"||(u=(h=t.user)==null?void 0:h.referredBy)!=null&&u.code?(s=c.displayOnLoad,v(`Display ${c.widgetType} on ${c.url}`)):v(`Don't display ${c.widgetType} when no referral on widget rule match ${c.url}`))}),r.fuelTankAutofillUrls&&(v("We found a fuel tank autofill!"),r.fuelTankAutofillUrls.forEach(({url:c,formSelector:h})=>{var u,p,m;if(S._matchesUrl(c)&&(v("Fuel Tank URL matches"),(p=(u=t.user)==null?void 0:u.referredBy)!=null&&p.code)){const g=document.querySelector(h);g?g.value=((m=t.user.referredBy.referredReward)==null?void 0:m.fuelTankCode)||"":v(new Error(`Element with id/class ${h} was not found.`))}})),e.engagementMedium==="EMBED"?i=this._renderEmbedWidget(a):(i=this._renderPopupWidget(a),s&&i.open()),i}_renderPopupWidget(t){const e=new U(t,t.context.trigger);return e.load(),e}_renderEmbedWidget(t){const e=new $(t,t.context.container);return e.load(),e}_renderErrorWidget(t,e="POPUP"){const{apiErrorCode:n,rsCode:i,statusCode:s,message:r}=t;v(new Error(`${n} (${i}) ${r}`));const a={content:"error",rsCode:i,apiErrorCode:n,statusCode:s,errorMessage:r,api:this.api,domain:this.domain,npmCdn:this.npmCdn,type:"ERROR_WIDGET",context:{type:"error"}};let d;e==="EMBED"?(d=new $(a),d.load()):e==="POPUP"&&(d=new U(a),d.load())}static _matchesUrl(t){return!!window.location.href.match(new RegExp(t))}}class je{constructor(t){l(this,"tenantAlias");l(this,"domain");const n=q(t);this.tenantAlias=n.tenantAlias,this.domain=n.domain}track(t,e){const n=t,i=e,s=Ne(n),{jwt:r}=Fe(i),a=encodeURIComponent(this.tenantAlias),d=encodeURIComponent(s.userId),c=encodeURIComponent(s.accountId),h=`/api/v1/${a}/open/account/${c}/user/${d}/events`,u=this.domain+h;return K(u,JSON.stringify(s),r)}}function Ne(o){if(!I(o))throw new Error("tracking parameter must be an object");if(!(o!=null&&o.accountId))throw new Error("accountId field is required");if(!(o!=null&&o.events))throw new Error("events field is required");if(!(o!=null&&o.userId))throw new Error("userId field is required");const t=o;if(!Array.isArray(t.events))throw new Error("'events' should be an array");return t}function Fe(o){if(!I(o))throw new Error("'options' should be an object");return o}function Be(){var i;const o=window[X]?X:L,t=((i=window["_"+o])==null?void 0:i.ready)||[],e=window.impactOnReady||window.squatchOnReady,n=[...t,e].filter(s=>!!s);setTimeout(()=>{window[L]&&(window[X]=window[L],n.forEach(s=>s()),window[L]._auto(),window["_"+o]=void 0,delete window["_"+o])},0)}const E=k("squatch-js"),de=o=>typeof o=="object"&&!Array.isArray(o),we=(o,t)=>{const e=i=>de(t[i])&&o.hasOwnProperty(i)&&de(o[i]),n=Object.getOwnPropertyNames(t).map(i=>({[i]:e(i)?we(o[i],t[i]):t[i]})).reduce((i,s)=>({...i,...s}),{});return{...o,...n}};function F(o){const t=atob(o.replace(/_/g,"/").replace(/-/g,"+")),e=new Uint8Array(t.length);for(let n=0;n<t.length;n++)e[n]=t.charCodeAt(n);return new TextDecoder("utf8").decode(e)}function ce(o){const t=new TextEncoder().encode(o),e=Array.from(t,n=>String.fromCodePoint(n)).join("");return btoa(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function He(){var o,t,e="weird_get_top_level_domain=cookie",n=document.location.hostname.split(".");for(o=n.length-1;o>=0;o--)if(t=n.slice(o).join("."),document.cookie=e+";domain=."+t+";",document.cookie.indexOf(e)>-1)return document.cookie=e.split("=")[0]+"=;domain=."+t+";expires=Thu, 01 Jan 1970 00:00:01 GMT;",t}function Ge(){const o=window.location.search,e=new URLSearchParams(o).get("_saasquatch")||"";if(e){let n="",i="",s="";try{n=JSON.parse(F(e))}catch(r){E("Unable to decode params",r);return}try{i=JSON.parse(F(j.get("_saasquatch"))),E("existing cookie",i)}catch(r){E("Unable to retrieve cookie",r)}try{const r=He();if(E("domain retrieved:",r),i){const a=we(i,n);s=ce(JSON.stringify(a)),E("cookie to store:",a)}else s=ce(JSON.stringify(n)),E("cookie to store:",n);j.set("_saasquatch",s,{expires:365,secure:!1,sameSite:"Lax",domain:r,path:"/"})}catch(r){E("Unable to set cookie",r)}}}const D=k("squatch-js");function Je(){var u;const o=window.location.search,e=new URLSearchParams(o).get("_saasquatchExtra")||"";if(!e){D("No _saasquatchExtra param");return}const n=q({tenantAlias:"UNKNOWN"});if(!n.domain){D("domain must be provided in config to use _saasquatchExtra");return}let i;try{i=JSON.parse(F(e))}catch{D("Unable to decode _saasquatchExtra config");return}function s(p){return p.replace(/^https?:\/\//,"")}const r=s(n.domain),a=Object.keys((i==null?void 0:i[r])||{})[0],d=(u=i==null?void 0:i[r])==null?void 0:u[a];if(!d){D("_saasquatchExtra did not have an expected structure");return}const{autoPopupWidgetType:c,...h}=d;return{widgetConfig:{widgetType:c,displayOnLoad:!0,...h},squatchConfig:{...n,tenantAlias:a}}}const ze=k("squatch-js:decodeUserJwt");function Ve(o){var t;try{const e=o.split(".")[1];if(e===void 0)return null;const n=F(e);return(t=JSON.parse(n))==null?void 0:t.user}catch(e){return ze(e),null}}const le=k("squatch-js:DeclarativeWidget");class ye extends HTMLElement{constructor(){super();l(this,"config");l(this,"token");l(this,"tenant");l(this,"widgetType");l(this,"locale");l(this,"widgetApi");l(this,"analyticsApi");l(this,"widgetInstance");l(this,"type");l(this,"container");l(this,"element");l(this,"loaded");l(this,"_setWidget",(e,n)=>{var s;const i={api:this.widgetApi,content:e.template,context:{type:n.type,user:n.user,container:this.container||void 0,engagementMedium:this.type,widgetConfig:e.widgetConfig},type:this.widgetType,domain:((s=this.config)==null?void 0:s.domain)||A,npmCdn:Y,container:this};if(this.type==="EMBED")return new $(i);{const r=this.firstChild?null:void 0;return new U(i,r)}});l(this,"setErrorWidget",e=>{var d;const n=e instanceof Error?e.message:e==null?void 0:e.message,i=e instanceof Error||e==null?void 0:e.apiErrorCode,s=e instanceof Error||e==null?void 0:e.rsCode,r=e instanceof Error||e==null?void 0:e.statusCode,a={api:this.widgetApi,content:"error",context:{type:"error",container:this.container||void 0},type:"ERROR_WIDGET",domain:((d=this.config)==null?void 0:d.domain)||A,npmCdn:Y,container:this,apiErrorCode:i,rsCode:s,statusCode:r,errorMessage:n};if(this.type==="EMBED")return new $(a);{const c=this.firstChild?null:void 0;return new U(a,c)}});l(this,"reload",this.renderWidget);l(this,"show",this.open);l(this,"hide",this.close);this.attachShadow({mode:"open"}).innerHTML="<style>:host { display: block; }</style><slot></slot>",this.config=ee(),this.token=R(),this.tenant=window.squatchTenant,this.container=this}_setupApis(e){var n,i;if(!this.tenant)throw new Error("tenantAlias not provided");this.widgetApi=new z({tenantAlias:(e==null?void 0:e.tenantAlias)||this.tenant,domain:(e==null?void 0:e.domain)||((n=this.config)==null?void 0:n.domain)||A}),this.analyticsApi=new ge({domain:(e==null?void 0:e.domain)||((i=this.config)==null?void 0:i.domain)||A})}getWidgetType(e){return e&&(e.includes("websiteReferralWidget")||e.includes("friendWidget"))?"instant-access":"verified-access"}async renderPasswordlessVariant(){return this._setupApis(),le("Rendering as an Instant Access widget"),await this.widgetApi.render({engagementMedium:this.type,widgetType:this.widgetType,locale:this.locale}).then(e=>this._setWidget(e,{type:"passwordless"})).catch(this.setErrorWidget)}async renderUserUpsertVariant(){this._setupApis();const e=Ve(this.token);if(!e)return this.setErrorWidget(Error("No user object in token."));le("Rendering as a Verified widget");try{await this.widgetApi.upsertUser({user:e,locale:this.locale,engagementMedium:this.type,widgetType:this.widgetType,jwt:this.token})}catch(i){return this.setErrorWidget(i)}return await this.widgetApi.render({locale:this.locale,engagementMedium:this.type,widgetType:this.widgetType}).then(i=>this._setWidget(i,{type:"upsert",user:e})).catch(this.setErrorWidget)}async getWidgetInstance(){let e;this.widgetType=this.getAttribute("widget")||void 0,this.locale=this.getAttribute("locale")||this.locale;const n=this.getWidgetType(this.widgetType);if(!this.widgetType)throw new Error("No widget has been specified");return!this.token&&n==="verified-access"?this.setErrorWidget(Error("A valid token is required to render this widget.")):(n==="instant-access"?e=await this.renderPasswordlessVariant():e=await this.renderUserUpsertVariant(),this.widgetInstance=e,this.widgetInstance&&this.dispatchEvent(new CustomEvent("sq:widget-loaded")),e)}async renderWidget(){await this.getWidgetInstance(),await this.widgetInstance.load()}open(){if(!this.widgetInstance)throw new Error("Widget has not loaded yet");this.widgetInstance.open()}close(){if(!this.widgetInstance)throw new Error("Widget has not loaded yet");this.widgetInstance.close()}static get observedAttributes(){return["widget","locale"]}attributeChangedCallback(e,n,i){if(!(n===i||!this.loaded))switch(e){case"locale":case"widget":this.connectedCallback();break}}async connectedCallback(){this.loaded=!0,this.container=this.getAttribute("container"),this.widgetType=this.getAttribute("widget")||void 0;const e=this.getWidgetType(this.widgetType),{getSkeleton:n}=await Promise.resolve().then(()=>Le),i=n({height:"100%",type:e}),s=document.createElement("div");s.id="loading-skeleton",s.innerHTML=i;const r=this.shadowRoot||this.attachShadow({mode:"open"});if(this.type==="POPUP"){const d=r.getElementById("#squatchModal");d&&(d.innerHTML="",d.appendChild(s))}else r.innerHTML="",r.appendChild(s);await this.renderWidget();const a=r.getElementById("loading-skeleton");a&&a.remove(),this.getAttribute("open")!==null&&this.open()}}class te extends ye{constructor(){super(),this.type="EMBED",this.loaded=!1}}class ne extends ye{constructor(){super(),this.type="POPUP",this.loaded=!1,this.addEventListener("click",t=>{t.stopPropagation(),this.open()})}}class Xe extends te{}class Qe extends ne{}class Ye extends te{}class Ke extends ne{}window.customElements.get("squatch-embed")||window.customElements.define("squatch-embed",Xe);window.customElements.get("impact-embed")||window.customElements.define("impact-embed",Ye);window.customElements.get("squatch-popup")||window.customElements.define("squatch-popup",Qe);window.customElements.get("impact-popup")||window.customElements.define("impact-popup",Ke);function Ze(){console.log("Having trouble using Squatch.js? Go to https://docs.referralsaasquatch.com/developer/ for tutorials, references and error codes.")}const T=k("squatch-js");let B=null,H=null,G=null;function et(){return B||P({}),B}function V(){return H||P({}),H}function tt(){return G||P({}),G}function nt(o){var t;return(t=V())==null?void 0:t.render(o)}function it(){var t;const o=Je();if(o){const{squatchConfig:e,widgetConfig:n}=o;return P(e),(t=V())==null?void 0:t.render(n)}}function P(o){const e=q(o);e.tenantAlias.match("^test")||e.debug?_e("squatch-js*"):We(),T("initializing ..."),B=new z(e),H=new S(e),G=new je(e),T("Widget API instance",B),T("Widgets instance",H),T("Events API instance",G)}function ot(o){o()}function st(o){V().autofill(o)}function ve(){Ge()}typeof document<"u"&&!window.SaaSquatchDoNotAutoDrop&&ve();var he;(he=window.squatch)!=null&&he.init&&T("Squatchjs is being loaded more than once. This may lead to multiple load events being sent, duplicated widgets, and inaccurate analytics.");typeof document<"u"&&Be();exports.DeclarativeEmbedWidget=te;exports.DeclarativePopupWidget=ne;exports.EmbedWidget=$;exports.PopupWidget=U;exports.WidgetApi=z;exports.Widgets=S;exports._auto=it;exports.api=et;exports.autofill=st;exports.events=tt;exports.help=Ze;exports.init=P;exports.pushCookie=ve;exports.ready=ot;exports.widget=nt;exports.widgets=V;
49
+ ${await this._getSkeletonPreloadHTML(i,(W=e==null?void 0:e.color)==null?void 0:W.backgroundColor)}
50
+ ${await this._getContent()}
51
+ `),h.close(),I("Popup template loaded into iframe"),await this._setupResizeHandler(s)}async _setupResizeHandler(e){const{contentWindow:n}=e;if(!n)throw new Error("Frame needs a content window");const i=n.document;$(i,async()=>{i.body.style.overflowY="hidden";let s=!0;new n.ResizeObserver(a=>{for(const c of a){const{top:d,bottom:h}=c.contentRect,u=h+d;u<=0||(s?(s=!1,e.style.height="0",e.height=i.body.scrollHeight+"",e.style.height=""):e.height=u+"",c.target.style="")}}).observe(await this._findInnerContainer(e))})}open(){const e=this.container?this._findElement():document.body,i=(e.shadowRoot||e).querySelector(`#${this.id}`);if(!i)throw new Error("Could not determine container div");i.showModal();const s=this._findFrame();if(!s)throw new Error("Could not find iframe");const{contentWindow:r}=s;if(!r)throw new Error("Squatch.js has an empty iframe");const a=r.document;$(a,()=>{var d;const c=r.squatch||r.widgetIdent;(d=s.contentDocument)==null||d.dispatchEvent(new CustomEvent("sq:refresh")),this.context.user?(this._loadEvent(c),I("Popup opened")):this._attachLoadEventListener(a,c)})}close(){const e=this._findFrame();e!=null&&e.contentDocument&&this._detachLoadEventListener(e.contentDocument);const n=this.container?this._findElement():document.body,s=(n.shadowRoot||n).querySelector(`#${this.id}`);if(!s)throw new Error("Could not determine container div");s.close(),I("Popup closed")}_getErrorStyle(){return"body { margin: 0; } .modal { box-shadow: none; border: 0; }"}}const E=C("squatch-js:widgets");class M{constructor(t){l(this,"api");l(this,"tenantAlias");l(this,"domain");l(this,"npmCdn");const e=P(t);this.tenantAlias=e.tenantAlias,this.domain=e.domain,this.npmCdn=e.npmCdn,this.api=new z(e)}async upsertUser(t){const n=he(t);try{const i=await this.api.upsertUser(n);return{widget:this._renderWidget(i,n,{type:"upsert",user:n.user,engagementMedium:t.engagementMedium,container:t.container,trigger:t.trigger,widgetConfig:{values:{brandingConfig:i==null?void 0:i.brandingConfig}}}),user:i.user}}catch(i){throw E(i),i.apiErrorCode&&this._renderErrorWidget(i,t.engagementMedium),new Error(i)}}async render(t){const n=ue(t);try{const i=await this.api.render(n);return{widget:this._renderWidget(i,n,{type:"passwordless",engagementMedium:n.engagementMedium,container:n.container,trigger:n.trigger,widgetConfig:i==null?void 0:i.widgetConfig}),user:i.user}}catch(i){throw i.apiErrorCode&&this._renderErrorWidget(i,n.engagementMedium),new Error(i)}}async autofill(t){const e=t;if(typeof e=="function"){try{const s=await this.api.squatchReferralCookie();e(s)}catch(s){throw E("Autofill error",s),new Error(s)}return}if(typeof e!="string")throw new Error("Autofill accepts a string or function");let n=document.querySelectorAll(e),i;if(n.length>0)i=n[0];else throw E("Element id/class or function missing"),new Error("Element id/class or function missing");try{const s=await this.api.squatchReferralCookie();i.value=s.codes[0]}catch(s){throw new Error(s)}}_renderWidget(t,e,n){var c;if(E("Rendering Widget..."),!t)throw new Error("Unable to get a response");let i,s=!!e.displayOnLoad;const r=t.jsOptions||{},a={content:t.template,type:e.widgetType||((c=r.widget)==null?void 0:c.defaultWidgetType),api:this.api,domain:this.domain,npmCdn:this.npmCdn,context:n};return r.widgetUrlMappings&&r.widgetUrlMappings.forEach(d=>{var h,u;M._matchesUrl(d.url)&&(d.widgetType!=="CONVERSION_WIDGET"||(u=(h=t.user)==null?void 0:h.referredBy)!=null&&u.code?(s=d.displayOnLoad,E(`Display ${d.widgetType} on ${d.url}`)):E(`Don't display ${d.widgetType} when no referral on widget rule match ${d.url}`))}),r.fuelTankAutofillUrls&&(E("We found a fuel tank autofill!"),r.fuelTankAutofillUrls.forEach(({url:d,formSelector:h})=>{var u,m,p;if(M._matchesUrl(d)&&(E("Fuel Tank URL matches"),(m=(u=t.user)==null?void 0:u.referredBy)!=null&&m.code)){const g=document.querySelector(h);g?g.value=((p=t.user.referredBy.referredReward)==null?void 0:p.fuelTankCode)||"":E(new Error(`Element with id/class ${h} was not found.`))}})),e.engagementMedium==="EMBED"?i=this._renderEmbedWidget(a):(i=this._renderPopupWidget(a),s&&i.open()),i}_renderPopupWidget(t){const e=new x(t,t.context.trigger);return e.load(),e}_renderEmbedWidget(t){const e=new q(t,t.context.container);return e.load(),e}_renderErrorWidget(t,e="POPUP"){const{apiErrorCode:n,rsCode:i,statusCode:s,message:r}=t;E(new Error(`${n} (${i}) ${r}`));const a={content:"error",rsCode:i,apiErrorCode:n,statusCode:s,errorMessage:r,api:this.api,domain:this.domain,npmCdn:this.npmCdn,type:"ERROR_WIDGET",context:{type:"error"}};let c;e==="EMBED"?(c=new q(a),c.load()):e==="POPUP"&&(c=new x(a),c.load())}static _matchesUrl(t){return!!window.location.href.match(new RegExp(t))}}class De{constructor(t){l(this,"tenantAlias");l(this,"domain");const n=P(t);this.tenantAlias=n.tenantAlias,this.domain=n.domain}track(t,e){const n=t,i=e,s=je(n),{jwt:r}=Ne(i),a=encodeURIComponent(this.tenantAlias),c=encodeURIComponent(s.userId),d=encodeURIComponent(s.accountId),h=`/api/v1/${a}/open/account/${d}/user/${c}/events`,u=this.domain+h;return Z(u,JSON.stringify(s),r)}}function je(o){if(!S(o))throw new Error("tracking parameter must be an object");if(!(o!=null&&o.accountId))throw new Error("accountId field is required");if(!(o!=null&&o.events))throw new Error("events field is required");if(!(o!=null&&o.userId))throw new Error("userId field is required");const t=o;if(!Array.isArray(t.events))throw new Error("'events' should be an array");return t}function Ne(o){if(!S(o))throw new Error("'options' should be an object");return o}function Fe(){var i;const o=window[X]?X:L,t=((i=window["_"+o])==null?void 0:i.ready)||[],e=window.impactOnReady||window.squatchOnReady,n=[...t,e].filter(s=>!!s);setTimeout(()=>{window[L]&&(window[X]=window[L],n.forEach(s=>s()),window[L]._auto(),window["_"+o]=void 0,delete window["_"+o])},0)}const D=C("squatch-js");function He(){var u;const o=window.location.search,e=new URLSearchParams(o).get("_saasquatchExtra")||"";if(!e){D("No _saasquatchExtra param");return}const n=P({tenantAlias:"UNKNOWN"});if(!n.domain){D("domain must be provided in config to use _saasquatchExtra");return}let i;try{i=JSON.parse(N(e))}catch{D("Unable to decode _saasquatchExtra config");return}function s(m){return m.replace(/^https?:\/\//,"")}const r=s(n.domain),a=Object.keys((i==null?void 0:i[r])||{})[0],c=(u=i==null?void 0:i[r])==null?void 0:u[a];if(!c){D("_saasquatchExtra did not have an expected structure");return}const{autoPopupWidgetType:d,...h}=c;return{widgetConfig:{widgetType:d,displayOnLoad:!0,...h},squatchConfig:{...n,tenantAlias:a}}}const Je=C("squatch-js:decodeUserJwt");function Be(o){var t;try{const e=o.split(".")[1];if(e===void 0)return null;const n=N(e);return(t=JSON.parse(n))==null?void 0:t.user}catch(e){return Je(e),null}}const j=C("squatch-js:DeclarativeWidget");class we extends HTMLElement{constructor(){super();l(this,"config");l(this,"token");l(this,"tenant");l(this,"widgetType");l(this,"locale");l(this,"widgetApi");l(this,"analyticsApi");l(this,"widgetInstance");l(this,"type");l(this,"container");l(this,"element");l(this,"loaded");l(this,"_setWidget",(e,n)=>{var s;const i={api:this.widgetApi,content:e.template,context:{type:n.type,user:n.user,container:this.container||void 0,engagementMedium:this.type,widgetConfig:e.widgetConfig},type:this.widgetType,domain:((s=this.config)==null?void 0:s.domain)||k,npmCdn:Y,container:this};if(this.type==="EMBED")return new q(i);{const r=this.firstChild?null:void 0;return new x(i,r)}});l(this,"setErrorWidget",e=>{var c;const n=e instanceof Error?e.message:e==null?void 0:e.message,i=e==null?void 0:e.apiErrorCode,s=e==null?void 0:e.rsCode,r=e==null?void 0:e.statusCode,a={api:this.widgetApi,content:"error",context:{type:"error",container:this.container||void 0},type:"ERROR_WIDGET",domain:((c=this.config)==null?void 0:c.domain)||k,npmCdn:Y,container:this,apiErrorCode:i,rsCode:s,statusCode:r,errorMessage:n};if(this.type==="EMBED")return new q(a);{const d=this.firstChild?null:void 0;return new x(a,d)}});l(this,"reload",this.renderWidget);l(this,"show",this.open);l(this,"hide",this.close);this.attachShadow({mode:"open"}).innerHTML="<style>:host { display: block; }</style><slot></slot>",this.config=K(),this.token=U(),this.tenant=window.squatchTenant,this.container=this}_setupApis(e){var n,i;if(!this.tenant)throw new Error("tenantAlias not provided");this.widgetApi=new z({tenantAlias:(e==null?void 0:e.tenantAlias)||this.tenant,domain:(e==null?void 0:e.domain)||((n=this.config)==null?void 0:n.domain)||k}),this.analyticsApi=new ge({domain:(e==null?void 0:e.domain)||((i=this.config)==null?void 0:i.domain)||k})}getWidgetType(e){return e&&e.includes("friendWidget")?"instant-access":"verified-access"}async renderPasswordlessVariant(){return this._setupApis(),j("Rendering as an Instant Access widget"),await this.widgetApi.render({engagementMedium:this.type,widgetType:this.widgetType,locale:this.locale}).then(e=>this._setWidget(e,{type:"passwordless"})).catch(this.setErrorWidget)}async renderUserUpsertVariant(){this._setupApis();const e=Be(this.token);if(!e)return this.setErrorWidget(Error("No user object in token."));!this.locale&&e.locale&&(this.locale=e.locale),j("Rendering as a Verified widget");try{await this.widgetApi.upsertUser({user:e,locale:this.locale,engagementMedium:this.type,widgetType:this.widgetType,jwt:this.token})}catch(i){return this.setErrorWidget(i)}return await this.widgetApi.render({locale:this.locale,engagementMedium:this.type,widgetType:this.widgetType}).then(i=>this._setWidget(i,{type:"upsert",user:e})).catch(this.setErrorWidget)}async getWidgetInstance(){let e;this.widgetType=this.getAttribute("widget")||void 0,this.locale=this.getAttribute("locale")||this.locale;const n=this.getWidgetType(this.widgetType);if(!this.widgetType)throw new Error("No widget has been specified");return!this.token&&n==="verified-access"&&j("[SquatchJS] Authentication token is required for this widget type."),this.token?e=await this.renderUserUpsertVariant():e=await this.renderPasswordlessVariant(),this.widgetInstance=e,this.widgetInstance&&this.dispatchEvent(new CustomEvent("sq:widget-loaded")),e}async renderWidget(){await this.getWidgetInstance(),await this.widgetInstance.load()}open(){if(!this.widgetInstance)throw new Error("Widget has not loaded yet");this.widgetInstance.open()}close(){if(!this.widgetInstance)throw new Error("Widget has not loaded yet");this.widgetInstance.close()}static get observedAttributes(){return["widget","locale"]}attributeChangedCallback(e,n,i){if(!(n===i||!this.loaded))switch(e){case"locale":case"widget":this.connectedCallback();break}}async connectedCallback(){this.loaded=!0,this.container=this.getAttribute("container"),this.widgetType=this.getAttribute("widget")||void 0;const e=this.getWidgetType(this.widgetType),{getSkeleton:n}=await Promise.resolve().then(()=>require("./SkeletonTemplate-B3Bk4NFu.cjs")),i=n({type:e}),s=document.createElement("div");s.id="loading-skeleton",s.innerHTML=i;const r=this.shadowRoot||this.attachShadow({mode:"open"});if(this.type==="POPUP"){const a=r.getElementById("squatchModal");a&&(a.innerHTML="",a.appendChild(s))}else r.innerHTML="",r.appendChild(s);try{await this.renderWidget()}catch(a){j("Failed to render widget",a)}finally{const a=r.getElementById("loading-skeleton");a&&a.remove()}this.getAttribute("open")!==null&&this.open()}}class ee extends we{constructor(){super(),this.type="EMBED",this.loaded=!1}}class te extends we{constructor(){super(),this.type="POPUP",this.loaded=!1,this.addEventListener("click",t=>{t.stopPropagation(),this.open()})}}class Ge extends ee{}class ze extends te{}class Ve extends ee{}class Xe extends te{}window.customElements.get("squatch-embed")||window.customElements.define("squatch-embed",Ge);window.customElements.get("impact-embed")||window.customElements.define("impact-embed",Ve);window.customElements.get("squatch-popup")||window.customElements.define("squatch-popup",ze);window.customElements.get("impact-popup")||window.customElements.define("impact-popup",Xe);function Qe(){console.log("Having trouble using Squatch.js? Go to https://docs.referralsaasquatch.com/developer/ for tutorials, references and error codes.")}const T=C("squatch-js");let H=null,J=null,B=null;function Ye(){return H||R({}),H}function V(){return J||R({}),J}function Ze(){return B||R({}),B}function Ke(o){var t;return(t=V())==null?void 0:t.render(o)}function et(){var t;const o=He();if(o){const{squatchConfig:e,widgetConfig:n}=o;return R(e),(t=V())==null?void 0:t.render(n)}}function R(o){const e=P(o);e.tenantAlias.match("^test")||e.debug?_e("squatch-js*"):ke(),T("initializing ..."),H=new z(e),J=new M(e),B=new De(e),T("Widget API instance",H),T("Widgets instance",J),T("Events API instance",B)}function tt(o){o()}function nt(o){V().autofill(o)}function fe(){Te()}typeof document<"u"&&!window.SaaSquatchDoNotAutoDrop&&fe();var de;(de=window.squatch)!=null&&de.init&&T("Squatchjs is being loaded more than once. This may lead to multiple load events being sent, duplicated widgets, and inaccurate analytics.");typeof document<"u"&&Fe();exports.DeclarativeEmbedWidget=ee;exports.DeclarativePopupWidget=te;exports.EmbedWidget=q;exports.PopupWidget=x;exports.WidgetApi=z;exports.Widgets=M;exports._auto=et;exports.api=Ye;exports.autofill=nt;exports.events=Ze;exports.help=Qe;exports.init=R;exports.pushCookie=fe;exports.ready=tt;exports.widget=Ke;exports.widgets=V;
361
52
  //# sourceMappingURL=squatch.cjs.js.map