@saasquatch/squatch-js 2.7.0-3 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/dist/squatch.cjs.js +2119 -7
  3. package/dist/squatch.cjs.js.map +1 -1
  4. package/dist/squatch.esm.js +2161 -0
  5. package/dist/squatch.esm.js.map +1 -0
  6. package/dist/squatch.js +2125 -9
  7. package/dist/squatch.js.map +1 -1
  8. package/dist/squatch.min.js +6 -0
  9. package/package.json +10 -9
  10. package/vite.config.ts +10 -3
  11. package/coverage/clover.xml +0 -917
  12. package/coverage/coverage-final.json +0 -21
  13. package/coverage/lcov-report/base.css +0 -224
  14. package/coverage/lcov-report/block-navigation.js +0 -87
  15. package/coverage/lcov-report/favicon.png +0 -0
  16. package/coverage/lcov-report/prettify.css +0 -1
  17. package/coverage/lcov-report/prettify.js +0 -2
  18. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  19. package/coverage/lcov-report/sorter.js +0 -196
  20. package/coverage/lcov.info +0 -1669
  21. package/dist/squatch.es.js +0 -1623
  22. package/dist/squatch.es.js.map +0 -1
  23. package/dist copy/api/AnalyticsApi.d.ts +0 -32
  24. package/dist copy/api/EventsApi.d.ts +0 -52
  25. package/dist copy/api/WidgetApi.d.ts +0 -64
  26. package/dist copy/api/graphql.d.ts +0 -1
  27. package/dist copy/async.d.ts +0 -20
  28. package/dist copy/docs.d.ts +0 -1
  29. package/dist copy/globals.d.ts +0 -4
  30. package/dist copy/squatch.cjs.js +0 -48
  31. package/dist copy/squatch.d.ts +0 -122
  32. package/dist copy/squatch.es.js +0 -1622
  33. package/dist copy/squatch.esm.js +0 -2317
  34. package/dist copy/squatch.esm.js.map +0 -1
  35. package/dist copy/squatch.js +0 -2337
  36. package/dist copy/squatch.js.map +0 -1
  37. package/dist copy/types.d.ts +0 -109
  38. package/dist copy/utils/cookieUtils.d.ts +0 -3
  39. package/dist copy/utils/decodeUserJwt.d.ts +0 -2
  40. package/dist copy/utils/domready.d.ts +0 -6
  41. package/dist copy/utils/io.d.ts +0 -5
  42. package/dist copy/utils/utmUtils.d.ts +0 -14
  43. package/dist copy/utils/validate.d.ts +0 -12
  44. package/dist copy/widgets/EmbedWidget.d.ts +0 -25
  45. package/dist copy/widgets/PopupWidget.d.ts +0 -30
  46. package/dist copy/widgets/Widget.d.ts +0 -57
  47. package/dist copy/widgets/Widgets.d.ts +0 -112
  48. package/dist copy/widgets/declarative/DeclarativeWidget.d.ts +0 -100
  49. package/dist copy/widgets/declarative/DeclarativeWidgets.d.ts +0 -35
@@ -1,48 +0,0 @@
1
- "use strict";var Ae=Object.defineProperty;var Ie=(i,n,t)=>n in i?Ae(i,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[n]=t;var p=(i,n,t)=>Ie(i,typeof n!="symbol"?n+"":n,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function _e(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var M={exports:{}},G,re;function Fe(){if(re)return G;re=1;var i=1e3,n=i*60,t=n*60,e=t*24,o=e*7,r=e*365.25;G=function(s,c){c=c||{};var l=typeof s;if(l==="string"&&s.length>0)return a(s);if(l==="number"&&isFinite(s))return c.long?u(s):d(s);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(s))};function a(s){if(s=String(s),!(s.length>100)){var c=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(s);if(c){var l=parseFloat(c[1]),m=(c[2]||"ms").toLowerCase();switch(m){case"years":case"year":case"yrs":case"yr":case"y":return l*r;case"weeks":case"week":case"w":return l*o;case"days":case"day":case"d":return l*e;case"hours":case"hour":case"hrs":case"hr":case"h":return l*t;case"minutes":case"minute":case"mins":case"min":case"m":return l*n;case"seconds":case"second":case"secs":case"sec":case"s":return l*i;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return l;default:return}}}}function d(s){var c=Math.abs(s);return c>=e?Math.round(s/e)+"d":c>=t?Math.round(s/t)+"h":c>=n?Math.round(s/n)+"m":c>=i?Math.round(s/i)+"s":s+"ms"}function u(s){var c=Math.abs(s);return c>=e?h(s,c,e,"day"):c>=t?h(s,c,t,"hour"):c>=n?h(s,c,n,"minute"):c>=i?h(s,c,i,"second"):s+" ms"}function h(s,c,l,m){var f=c>=l*1.5;return Math.round(s/l)+" "+m+(f?"s":"")}return G}var V,se;function ke(){if(se)return V;se=1;function i(n){e.debug=e,e.default=e,e.coerce=h,e.disable=d,e.enable=a,e.enabled=u,e.humanize=Fe(),Object.keys(n).forEach(function(s){e[s]=n[s]}),e.instances=[],e.names=[],e.skips=[],e.formatters={};function t(s){for(var c=0,l=0;l<s.length;l++)c=(c<<5)-c+s.charCodeAt(l),c|=0;return e.colors[Math.abs(c)%e.colors.length]}e.selectColor=t;function e(s){var c;function l(){if(l.enabled){for(var m=arguments.length,f=new Array(m),b=0;b<m;b++)f[b]=arguments[b];var w=l,y=Number(new Date),Ce=y-(c||y);w.diff=Ce,w.prev=c,w.curr=y,c=y,f[0]=e.coerce(f[0]),typeof f[0]!="string"&&f.unshift("%O");var T=0;f[0]=f[0].replace(/%([a-zA-Z%])/g,function(P,be){if(P==="%%")return P;T++;var ie=e.formatters[be];if(typeof ie=="function"){var ve=f[T];P=ie.call(w,ve),f.splice(T,1),T--}return P}),e.formatArgs.call(w,f);var Ee=w.log||e.log;Ee.apply(w,f)}}return l.namespace=s,l.enabled=e.enabled(s),l.useColors=e.useColors(),l.color=t(s),l.destroy=o,l.extend=r,typeof e.init=="function"&&e.init(l),e.instances.push(l),l}function o(){var s=e.instances.indexOf(this);return s!==-1?(e.instances.splice(s,1),!0):!1}function r(s,c){return e(this.namespace+(typeof c>"u"?":":c)+s)}function a(s){e.save(s),e.names=[],e.skips=[];var c,l=(typeof s=="string"?s:"").split(/[\s,]+/),m=l.length;for(c=0;c<m;c++)l[c]&&(s=l[c].replace(/\*/g,".*?"),s[0]==="-"?e.skips.push(new RegExp("^"+s.substr(1)+"$")):e.names.push(new RegExp("^"+s+"$")));for(c=0;c<e.instances.length;c++){var f=e.instances[c];f.enabled=e.enabled(f.namespace)}}function d(){e.enable("")}function u(s){if(s[s.length-1]==="*")return!0;var c,l;for(c=0,l=e.skips.length;c<l;c++)if(e.skips[c].test(s))return!1;for(c=0,l=e.names.length;c<l;c++)if(e.names[c].test(s))return!0;return!1}function h(s){return s instanceof Error?s.stack||s.message:s}return e.enable(e.load()),e}return V=i,V}var ae;function qe(){return ae||(ae=1,function(i,n){function t(s){return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?t=function(l){return typeof l}:t=function(l){return l&&typeof Symbol=="function"&&l.constructor===Symbol&&l!==Symbol.prototype?"symbol":typeof l},t(s)}n.log=r,n.formatArgs=o,n.save=a,n.load=d,n.useColors=e,n.storage=u(),n.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function e(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function o(s){if(s[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+s[0]+(this.useColors?"%c ":" ")+"+"+i.exports.humanize(this.diff),!!this.useColors){var c="color: "+this.color;s.splice(1,0,c,"color: inherit");var l=0,m=0;s[0].replace(/%[a-zA-Z%]/g,function(f){f!=="%%"&&(l++,f==="%c"&&(m=l))}),s.splice(m,0,c)}}function r(){var s;return(typeof console>"u"?"undefined":t(console))==="object"&&console.log&&(s=console).log.apply(s,arguments)}function a(s){try{s?n.storage.setItem("debug",s):n.storage.removeItem("debug")}catch{}}function d(){var s;try{s=n.storage.getItem("debug")}catch{}return!s&&typeof process<"u"&&"env"in process&&(s=process.env.DEBUG),s}function u(){try{return localStorage}catch{}}i.exports=ke()(n);var h=i.exports.formatters;h.j=function(s){try{return JSON.stringify(s)}catch(c){return"[UnexpectedJSONParseError]: "+c.message}}}(M,M.exports)),M.exports}var g=qe();const xe=_e(g);/*! js-cookie v3.0.5 | MIT */function $(i){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var e in t)i[e]=t[e]}return i}var Re={read:function(i){return i[0]==='"'&&(i=i.slice(1,-1)),i.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(i){return encodeURIComponent(i).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}};function Y(i,n){function t(o,r,a){if(!(typeof document>"u")){a=$({},n,a),typeof a.expires=="number"&&(a.expires=new Date(Date.now()+a.expires*864e5)),a.expires&&(a.expires=a.expires.toUTCString()),o=encodeURIComponent(o).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var d="";for(var u in a)a[u]&&(d+="; "+u,a[u]!==!0&&(d+="="+a[u].split(";")[0]));return document.cookie=o+"="+i.write(r,o)+d}}function e(o){if(!(typeof document>"u"||arguments.length&&!o)){for(var r=document.cookie?document.cookie.split("; "):[],a={},d=0;d<r.length;d++){var u=r[d].split("="),h=u.slice(1).join("=");try{var s=decodeURIComponent(u[0]);if(a[s]=i.read(h,s),o===s)break}catch{}}return o?a[o]:a}}return Object.create({set:t,get:e,remove:function(o,r){t(o,"",$({},r,{expires:-1}))},withAttributes:function(o){return Y(this.converter,$({},this.attributes,o))},withConverter:function(o){return Y($({},this.converter,o),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(i)}})}var L=Y(Re,{path:"/"});const I="https://app.referralsaasquatch.com",Z="https://fast.ssqt.io/npm",W="squatch",X="impact";function B(i){if(typeof i!="object")throw new Error("config must be an object");const n=window.squatchTenant,t=te(),e={tenantAlias:(i==null?void 0:i.tenantAlias)||n,domain:(i==null?void 0:i.domain)||(t==null?void 0:t.domain),npmCdn:(i==null?void 0:i.npmCdn)||(t==null?void 0:t.npmCdn),debug:(i==null?void 0:i.debug)||(t==null?void 0:t.debug)};if(typeof e.tenantAlias!="string")throw new Error("tenantAlias not provided");const o=e.tenantAlias,r=typeof e.domain=="string"&&e.domain||I,a=typeof e.debug=="boolean"&&e.debug||!1,d=typeof e.npmCdn=="string"&&e.npmCdn||Z;return{tenantAlias:o,domain:r,debug:a,npmCdn:d}}function _(i){return typeof i=="object"&&!Array.isArray(i)&&i!==null}function Ue(i){if(i&&/^[a-z]{2}_(?:[A-Z]{2}|[0-9]{3})$/.test(i))return i}function he(i){if(!_(i))throw new Error("Widget properties must be an object");if(!(i!=null&&i.user))throw new Error("Required properties missing.");return i}function pe(i){if(!_(i))throw new Error("Widget properties must be an object");return i}function U(){return window.impactToken||window.squatchToken}function te(){return window.impactConfig||window.squatchConfig}g.debug("squatch-js:io");async function Se(i,n,t,e){const o=e||U(),r={Accept:"application/json","Content-Type":"application/json",...o?{Authorization:`Bearer ${o}`}:{},"X-SaaSquatch-Referrer":window?window.location.href:""};try{const a=await fetch(i,{method:"POST",body:JSON.stringify({query:n,variables:t}),headers:r});if(!a.ok)throw new Error(await a.text());return await a.json()}catch(a){throw a}}async function Te(i,n=""){const t={Accept:"application/json","Content-Type":"application/json"},e=n||U();e&&(t["X-SaaSquatch-User-Token"]=e);try{const o=await fetch(i,{method:"GET",credentials:"include",headers:t}),r=await o.text();if(!o.ok)throw new Error(r);return r&&JSON.parse(r)}catch(o){throw o}}async function K(i,n,t){const e={Accept:"application/json","Content-Type":"application/json"},o=t||U();o&&(e["X-SaaSquatch-User-Token"]=o);try{const r=await fetch(i,{method:"POST",body:n,headers:e}),a=await r.text();if(!r.ok)throw new Error(a);return a&&JSON.parse(a)}catch(r){throw r}}async function Pe(i,n,t){const e={Accept:"application/json","Content-Type":"application/json","X-SaaSquatch-Referrer":window?window.location.href:""},o=t||U();o&&(e["X-SaaSquatch-User-Token"]=o);try{const r=await fetch(i,{headers:e,method:"PUT",credentials:"include",body:n}),a=await r.text();if(!r.ok)throw new Error(a);return a&&JSON.parse(a)}catch(r){throw r}}const Me=`
2
- query renderWidget ($user: UserIdInput, $engagementMedium: UserEngagementMedium, $widgetType: WidgetType, $locale: RSLocale) {
3
- renderWidget(user: $user, engagementMedium: $engagementMedium, widgetType: $widgetType, locale: $locale) {
4
- template
5
- user {
6
- id
7
- accountId
8
- }
9
- jsOptions
10
- widgetConfig {
11
- values
12
- }
13
- }
14
- }
15
- `;class z{constructor(n){p(this,"tenantAlias");p(this,"domain");p(this,"npmCdn");p(this,"referralCookie",this.squatchReferralCookie);const e=B(n);this.tenantAlias=e.tenantAlias,this.domain=e.domain,this.npmCdn=e.npmCdn}upsertUser(n){const e=he(n),{widgetType:o,engagementMedium:r="POPUP",jwt:a,locale:d,user:u}=e,h=encodeURIComponent(this.tenantAlias),s=u.accountId?encodeURIComponent(u.accountId):null,c=u.id?encodeURIComponent(u.id):null,l=$e({widgetType:o,engagementMedium:r,locale:d}),m=`/api/v1/${h}/widget/account/${s}/user/${c}/upsert${l}`,f=this.domain+m,b=(L||window.Cookies).get("_saasquatch");return b&&(u.cookies=b),Pe(f,JSON.stringify(u),a)}render(n){const e=pe(n),{widgetType:o,engagementMedium:r="POPUP",jwt:a,user:d}=e,u=encodeURIComponent(this.tenantAlias),h=d!=null&&d.accountId?encodeURIComponent(d.accountId):null,s=d!=null&&d.id?encodeURIComponent(d.id):null,c=e.locale??Ue(navigator.language.replace(/\-/g,"_")),l=`/api/v1/${u}/graphql`,m=this.domain+l;return new Promise(async(f,b)=>{var w;try{const y=await Se(m,Me,{user:s&&h?{id:s,accountId:h}:null,engagementMedium:r,widgetType:o,locale:c},a);f((w=y==null?void 0:y.data)==null?void 0:w.renderWidget)}catch(y){b(y)}})}async squatchReferralCookie(){const n=encodeURIComponent(this.tenantAlias),t=(L||window.Cookies).get("_saasquatch")||"",e=t?`?cookies=${encodeURIComponent(t)}`:"",o=`${this.domain}/a/${n}/widgets/squatchcookiejson${e}`,r=await Te(o);return Promise.resolve({...r,encodedCookie:t})}}function $e({widgetType:i,engagementMedium:n,locale:t}){const e=new URLSearchParams;return e.append("engagementMedium",n),i&&e.append("widgetType",i),t&&e.append("locale",t),`?${e.toString()}`}class fe{constructor(n){p(this,"domain");var o;const e=We(n);this.domain=(e==null?void 0:e.domain)||((o=te())==null?void 0:o.domain)||I}pushAnalyticsLoadEvent(n){if(!n.externalUserId||!n.externalAccountId)return;const t=encodeURIComponent(n.tenantAlias),e=encodeURIComponent(n.externalAccountId),o=encodeURIComponent(n.externalUserId),r=encodeURIComponent(n.engagementMedium),a=n.programId?`&programId=${encodeURIComponent(n.programId)}`:"",d=`/a/${t}/widgets/analytics/loaded?externalAccountId=${e}&externalUserId=${o}&engagementMedium=${r}${a}`,u=this.domain+d;return K(u,JSON.stringify({}))}pushAnalyticsShareClickedEvent(n){const t=encodeURIComponent(n.tenantAlias),e=encodeURIComponent(n.externalAccountId),o=encodeURIComponent(n.externalUserId),r=encodeURIComponent(n.engagementMedium),a=encodeURIComponent(n.shareMedium),d=`/a/${t}/widgets/analytics/shared?externalAccountId=${e}&externalUserId=${o}&engagementMedium=${r}&shareMedium=${a}`,u=this.domain+d;return K(u,JSON.stringify({}))}}function We(i){if(!_(i))throw new Error("'options' should be an object");return i}const C=g.debug("squatch-js:widget");class me{constructor(n){p(this,"type");p(this,"content");p(this,"analyticsApi");p(this,"widgetApi");p(this,"context");p(this,"npmCdn");p(this,"container");p(this,"loadEventListener",null);var t;C("widget initializing ..."),this.content=n.content==="error"?this._error(n.rsCode):n.content,this.type=n.type,this.widgetApi=n.api,this.npmCdn=n.npmCdn,this.analyticsApi=new fe({domain:n.domain}),this.context=n.context,this.container=((t=n.context)==null?void 0:t.container)||n.container}_findElement(){let n;if(typeof this.container=="string"?(n=document.querySelector(this.container),C("loading widget with selector",n)):this.container instanceof HTMLElement?(n=this.container,C("loading widget with container",n)):this.container?(n=null,C("container must be an HTMLElement or string",this.container)):(n=document.querySelector("#squatchembed")||document.querySelector(".squatchembed")||document.querySelector("#impactembed")||document.querySelector(".impactembed"),C("loading widget with default selector",n)),!(n instanceof HTMLElement))throw new Error(`element with selector '${this.container||"#squatchembed, .squatchembed, #impactembed, or .impactembed"}' not found.'`);return n}_createFrame(){const n=document.createElement("iframe");return n.squatchJsApi=this,n.id="squatchFrame",n.width="100%",n.src="about:blank",n.scrolling="no",n.setAttribute("style","border: 0; background-color: none; width: 1px; min-width: 100%;"),n}_findFrame(){const n=this.container?this._findElement():document.body;return(n.shadowRoot||n).querySelector("iframe#squatchFrame")}_detachLoadEventListener(n){this.loadEventListener&&(n.removeEventListener("sq:user-registration",this.loadEventListener),this.loadEventListener=null)}_attachLoadEventListener(n,t){this.loadEventListener===null&&(this.loadEventListener=e=>{this._loadEvent({...t,userId:e.detail.userId,accountId:e.detail.accountId})},n.addEventListener("sq:user-registration",this.loadEventListener))}_loadEvent(n){var e;if(!n)return;if(!_(n))throw new Error("Widget Load event identity property is not an object");let t;if("programId"in n){if(!n.tenantAlias||!n.accountId||!n.userId||!n.engagementMedium)throw new Error("Widget Load event missing required properties");t={tenantAlias:n.tenantAlias,externalAccountId:n.accountId,externalUserId:n.userId,engagementMedium:n.engagementMedium,programId:n.programId}}else{const{analytics:o,mode:r}=n;t={tenantAlias:o.attributes.tenant,externalAccountId:o.attributes.accountId,externalUserId:o.attributes.userId,engagementMedium:r.widgetMode}}(e=this.analyticsApi.pushAnalyticsLoadEvent(t))==null||e.then(o=>{C(`${t.engagementMedium} loaded event recorded.`)}).catch(o=>{C(`ERROR: pushAnalyticsLoadEvent() ${o}`)})}_shareEvent(n,t){n&&this.analyticsApi.pushAnalyticsShareClickedEvent({tenantAlias:n.analytics.attributes.tenant,externalAccountId:n.analytics.attributes.accountId,externalUserId:n.analytics.attributes.userId,engagementMedium:n.mode.widgetMode,shareMedium:t}).then(e=>{C(`${n.mode.widgetMode} share ${t} event recorded. ${e}`)}).catch(e=>{C(`ERROR: pushAnalyticsShareClickedEvent() ${e}`)})}_error(n,t="modal",e=""){return`<!DOCTYPE html>
16
- <!--[if IE 7]><html class="ie7 oldie" lang="en"><![endif]-->
17
- <!--[if IE 8]><html class="ie8 oldie" lang="en"><![endif]-->
18
- <!--[if gt IE 8]><!--><html lang="en"><!--<![endif]-->
19
- <head>
20
- <link rel="stylesheet" media="all" href="https://fast.ssqt.io/assets/css/widget/errorpage.css">
21
- <style>
22
- ${e}
23
- </style>
24
- </head>
25
- <body>
26
-
27
- <div class="squatch-container ${t}" style="width:100%">
28
- <div class="errorheader">
29
- <button type="button" class="close" onclick="window.frameElement.squatchJsApi.close();">&times;</button>
30
- <p class="errortitle">Error</p>
31
- </div>
32
- <div class="errorbody">
33
- <div class="sadface"><img src="https://fast.ssqt.io/assets/images/face.png"></div>
34
- <h4>Our referral program is temporarily unavailable.</h4><br>
35
- <p>Please reload the page or check back later.</p>
36
- <p>If the persists please contact our support team.</p>
37
- <br>
38
- <br>
39
- <div class="right-align errtxt">
40
- Error Code: ${n}
41
- </div>
42
- </div>
43
- </div>
44
- </body>
45
- </html>`}async _findInnerContainer(n){const{contentWindow:t}=n;if(!t)throw new Error("Squatch.js frame inner frame is empty");const e=t.document;function o(){const a=e.getElementsByTagName("sqh-global-container"),d=e.getElementsByClassName("squatch-container");return a.length>0?a[0]:d.length>0?d[0]:null}let r=null;for(let a=0;a<5&&(r=o(),!r);a++)await Oe(100);return r||e.body}reload({email:n,firstName:t,lastName:e},o){const r=this._findFrame();if(!r)throw new Error("Could not find widget iframe");const a=r.contentWindow,d=this.context.engagementMedium||"POPUP";if(!a)throw new Error("Frame needs a content window");let u;if(this.context.type==="upsert"){if(!this.context.user)throw new Error("Can't reload without user ids");let h={email:n||null,firstName:t||null,lastName:e||null,id:this.context.user.id,accountId:this.context.user.accountId};u=this.widgetApi.upsertUser({user:h,engagementMedium:d,widgetType:this.type,jwt:o})}else if(this.context.type==="passwordless")u=this.widgetApi.render({user:void 0,engagementMedium:d,widgetType:this.type,jwt:void 0});else throw new Error("can't reload an error widget");u.then(({template:h})=>{h&&(this.content=h,this.__deprecated__register(r,{email:n,engagementMedium:d},()=>{this.load(),d==="POPUP"&&this.open()}))}).catch(({message:h})=>{C(`${h}`)})}__deprecated__register(n,t,e){const r=n.contentWindow.document,a=r.createElement("button"),d=r.getElementsByClassName("squatch-register")[0];if(d){a.className="btn btn-primary",a.id="show-stats-btn",a.textContent=this.type==="REFERRER_WIDGET"?"Show Stats":"Show Reward";const u=t.engagementMedium==="POPUP"?"margin-top: 10px; max-width: 130px; width: 100%;":"margin-top: 10px;";a.setAttribute("style",u),a.onclick=e,d.style.paddingTop="30px",d.innerHTML=`<p><strong>${t.email}</strong><br>Has been successfully registered</p>`,d.appendChild(a)}}}function Oe(i){return new Promise(n=>{setTimeout(n,i)})}/*!
46
- * domready (c) Dustin Diaz 2014 - License MIT
47
- *
48
- */function ee(i,n){let t=[],e,o=i,r=o.documentElement.doScroll,a="DOMContentLoaded",d=(r?/^loaded|^c/:/^loaded|^i|^c/).test(o.readyState);return d||o.addEventListener(a,e=()=>{for(o.removeEventListener(a,e),d=!0;e=t.shift();)e()}),d?setTimeout(n,0):t.push(n)}const A=g.debug("squatch-js:EMBEDwidget");class q extends me{constructor(t,e){super(t);p(this,"show",this.open);p(this,"hide",this.close);e&&(this.container=e)}async load(){var a,d;const t=this._createFrame(),e=this._findElement();(a=this.context)!=null&&a.container&&(e.style.visibility="hidden",e.style.height="0",e.style["overflow-y"]="hidden"),this.container?e.shadowRoot?((d=e.shadowRoot.lastChild)==null?void 0:d.nodeName)==="IFRAME"?e.shadowRoot.replaceChild(t,e.shadowRoot.lastChild):e.shadowRoot.appendChild(t):e.firstChild?e.replaceChild(t,e.firstChild):e.appendChild(t):(!e.firstChild||e.firstChild.nodeName==="#text")&&e.appendChild(t);const{contentWindow:o}=t;if(!o)throw new Error("Frame needs a content window");const r=o.document;r.open(),r.write(this.content),r.write(`<script src="${this.npmCdn}/resize-observer-polyfill@1.5.x"><\/script>`),r.close(),ee(r,async()=>{const u=o.squatch||o.widgetIdent;t.height=r.body.scrollHeight;const h=new o.ResizeObserver(c=>{for(const l of c){const{height:m}=l.contentRect;t.height=m}}),s=await this._findInnerContainer(t);h.observe(s),this._shouldFireLoadEvent()?(this._loadEvent(u),A("loaded")):r&&this._attachLoadEventListener(r,u)})}open(){const t=this._findFrame();if(!t)return A("no target element to open");if(!t.contentWindow)return A("Frame needs a content window");const e=this._findElement();e.style.visibility="unset",e.style.height="auto",e.style["overflow-y"]="auto",t.contentWindow.document.dispatchEvent(new CustomEvent("sq:refresh"));const o=t.contentWindow.squatch||t.contentWindow.widgetIdent;if(this.context.user)this._loadEvent(o),A("loaded");else{if(!t.contentDocument)return;this._attachLoadEventListener(t.contentDocument,o)}}close(){const t=this._findFrame();if(!t)return A("no target element to close");t.contentDocument&&this._detachLoadEventListener(t.contentDocument);const e=this._findElement();e.style.visibility="hidden",e.style.height="0",e.style["overflow-y"]="hidden",A("Embed widget closed")}_error(t,e="embed",o=""){return super._error(t,e,o)}_shouldFireLoadEvent(){const t=!this.container,e=this.container instanceof HTMLElement&&(this.container.tagName.startsWith("SQUATCH-")||this.container.tagName.startsWith("IMPACT-"));return!!this.context.user&&(t||e)}}const F=g.debug("squatch-js:POPUPwidget");let O=0;class x extends me{constructor(t,e=".squatchpop"){super(t);p(this,"trigger");p(this,"id");p(this,"show",this.open);p(this,"hide",this.close);this.trigger=e,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 t;try{t=document.querySelector(this.trigger)||document.querySelector(".impactpop"),this.trigger&&!t&&F("No element found with trigger selector",this.trigger)}catch{F("Not a valid selector",this.trigger)}t&&(t.onclick=()=>{this.open()})}_createPopupDialog(){const t=document.createElement("dialog");t.id=this.id,t.setAttribute("style","width: 100%; max-width: 500px; border: none; padding: 0;");const e=o=>{o.stopPropagation(),o.target===t&&t.close()};return t.addEventListener("click",e),t}async load(){var u;const t=this._createFrame();this._initialiseCTA();const e=this.container?this._findElement():document.body,o=e.shadowRoot||e,r=this._createPopupDialog();r.appendChild(t),((u=o.lastChild)==null?void 0:u.nodeName)==="DIALOG"?o.replaceChild(r,o.lastChild):o.appendChild(r);const{contentWindow:a}=t;if(!a)throw new Error("Frame needs a content window");const d=a.document;d.open(),d.write(this.content),d.write(`<script src="${this.npmCdn}/resize-observer-polyfill@1.5.x"><\/script>`),d.close(),F("Popup template loaded into iframe"),await this._setupResizeHandler(t)}async _setupResizeHandler(t){const{contentWindow:e}=t;if(!e)throw new Error("Frame needs a content window");const o=e.document;ee(o,async()=>{o.body.style.overflowY="hidden",t.height=`${o.body.offsetHeight}px`,new e.ResizeObserver(a=>{for(const d of a){const{top:u,bottom:h}=d.contentRect,s=h+u;t.height=s+"",d.target.style=""}}).observe(await this._findInnerContainer(t))})}open(){const t=this.container?this._findElement():document.body,o=(t.shadowRoot||t).querySelector(`#${this.id}`);if(!o)throw new Error("Could not determine container div");o.showModal();const r=this._findFrame();if(!r)throw new Error("Could not find iframe");const{contentWindow:a}=r;if(!a)throw new Error("Squatch.js has an empty iframe");const d=a.document;ee(d,()=>{var h;const u=a.squatch||a.widgetIdent;(h=r.contentDocument)==null||h.dispatchEvent(new CustomEvent("sq:refresh")),this.context.user?(this._loadEvent(u),F("Popup opened")):this._attachLoadEventListener(d,u)})}close(){const t=this._findFrame();t!=null&&t.contentDocument&&this._detachLoadEventListener(t.contentDocument);const e=this.container?this._findElement():document.body,r=(e.shadowRoot||e).querySelector(`#${this.id}`);if(!r)throw new Error("Could not determine container div");r.close(),F("Popup closed")}_clickedOutside({target:t}){}_error(t,e="modal",o=""){return super._error(t,e,o||"body { margin: 0; } .modal { box-shadow: none; border: 0; }")}}const E=g.debug("squatch-js:widgets");class R{constructor(n){p(this,"api");p(this,"tenantAlias");p(this,"domain");p(this,"npmCdn");const t=B(n);this.tenantAlias=t.tenantAlias,this.domain=t.domain,this.npmCdn=t.npmCdn,this.api=new z(t)}async upsertUser(n){const e=he(n);try{const o=await this.api.upsertUser(e);return{widget:this._renderWidget(o,e,{type:"upsert",user:e.user,engagementMedium:n.engagementMedium,container:n.container,trigger:n.trigger}),user:o.user}}catch(o){throw E(o),o.apiErrorCode&&this._renderErrorWidget(o,n.engagementMedium),new Error(o)}}async render(n){const e=pe(n);try{const o=await this.api.render(e);return{widget:this._renderWidget(o,e,{type:"passwordless",engagementMedium:e.engagementMedium,container:e.container,trigger:e.trigger}),user:o.user}}catch(o){throw o.apiErrorCode&&this._renderErrorWidget(o,e.engagementMedium),new Error(o)}}async autofill(n){const t=n;if(typeof t=="function"){try{const r=await this.api.squatchReferralCookie();t(r)}catch(r){throw E("Autofill error",r),new Error(r)}return}if(typeof t!="string")throw new Error("Autofill accepts a string or function");let e=document.querySelectorAll(t),o;if(e.length>0)o=e[0];else throw E("Element id/class or function missing"),new Error("Element id/class or function missing");try{const r=await this.api.squatchReferralCookie();o.value=r.codes[0]}catch(r){throw new Error(r)}}_renderWidget(n,t,e){var u;if(E("Rendering Widget..."),!n)throw new Error("Unable to get a response");let o,r=!!t.displayOnLoad;const a=n.jsOptions||{},d={content:n.template,type:t.widgetType||((u=a.widget)==null?void 0:u.defaultWidgetType),api:this.api,domain:this.domain,npmCdn:this.npmCdn,context:e};return a.widgetUrlMappings&&a.widgetUrlMappings.forEach(h=>{var s,c;R._matchesUrl(h.url)&&(h.widgetType!=="CONVERSION_WIDGET"||(c=(s=n.user)==null?void 0:s.referredBy)!=null&&c.code?(r=h.displayOnLoad,E(`Display ${h.widgetType} on ${h.url}`)):E(`Don't display ${h.widgetType} when no referral on widget rule match ${h.url}`))}),a.fuelTankAutofillUrls&&(E("We found a fuel tank autofill!"),a.fuelTankAutofillUrls.forEach(({url:h,formSelector:s})=>{var c,l,m;if(R._matchesUrl(h)&&(E("Fuel Tank URL matches"),(l=(c=n.user)==null?void 0:c.referredBy)!=null&&l.code)){const f=document.querySelector(s);f?f.value=((m=n.user.referredBy.referredReward)==null?void 0:m.fuelTankCode)||"":E(new Error(`Element with id/class ${s} was not found.`))}})),t.engagementMedium==="EMBED"?o=this._renderEmbedWidget(d):(o=this._renderPopupWidget(d),r&&o.open()),o}_renderPopupWidget(n){const t=new x(n,n.context.trigger);return t.load(),t}_renderEmbedWidget(n){const t=new q(n,n.context.container);return t.load(),t}_renderErrorWidget(n,t="POPUP"){const{apiErrorCode:e,rsCode:o,message:r}=n;E(new Error(`${e} (${o}) ${r}`));const a={content:"error",rsCode:o,api:this.api,domain:this.domain,npmCdn:this.npmCdn,type:"ERROR_WIDGET",context:{type:"error"}};let d;t==="EMBED"?(d=new q(a),d.load()):t==="POPUP"&&(d=new x(a),d.load())}static _matchesUrl(n){return!!window.location.href.match(new RegExp(n))}}class Le{constructor(n){p(this,"tenantAlias");p(this,"domain");const e=B(n);this.tenantAlias=e.tenantAlias,this.domain=e.domain}track(n,t){const e=n,o=t,r=De(e),{jwt:a}=je(o),d=encodeURIComponent(this.tenantAlias),u=encodeURIComponent(r.userId),h=encodeURIComponent(r.accountId),s=`/api/v1/${d}/open/account/${h}/user/${u}/events`,c=this.domain+s;return K(c,JSON.stringify(r),a)}}function De(i){if(!_(i))throw new Error("tracking parameter must be an object");if(!(i!=null&&i.accountId))throw new Error("accountId field is required");if(!(i!=null&&i.events))throw new Error("events field is required");if(!(i!=null&&i.userId))throw new Error("userId field is required");const n=i;if(!Array.isArray(n.events))throw new Error("'events' should be an array");return n}function je(i){if(!_(i))throw new Error("'options' should be an object");return i}function Ne(){var o;const i=window[X]?X:W,n=((o=window["_"+i])==null?void 0:o.ready)||[],t=window.impactOnReady||window.squatchOnReady,e=[...n,t].filter(r=>!!r);setTimeout(()=>{window[W]&&(window[X]=window[W],e.forEach(r=>r()),window[W]._auto(),window["_"+i]=void 0,delete window["_"+i])},0)}const v=g.debug("squatch-js"),ce=i=>typeof i=="object"&&!Array.isArray(i),ge=(i,n)=>{const t=o=>ce(n[o])&&i.hasOwnProperty(o)&&ce(i[o]),e=Object.getOwnPropertyNames(n).map(o=>({[o]:t(o)?ge(i[o],n[o]):n[o]})).reduce((o,r)=>({...o,...r}),{});return{...i,...e}};function D(i){const n=atob(i.replace(/_/g,"/").replace(/-/g,"+")),t=new Uint8Array(n.length);for(let e=0;e<n.length;e++)t[e]=n.charCodeAt(e);return new TextDecoder("utf8").decode(t)}function de(i){const n=new TextEncoder().encode(i),t=Array.from(n,e=>String.fromCodePoint(e)).join("");return btoa(t).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function Je(){var i,n,t="weird_get_top_level_domain=cookie",e=document.location.hostname.split(".");for(i=e.length-1;i>=0;i--)if(n=e.slice(i).join("."),document.cookie=t+";domain=."+n+";",document.cookie.indexOf(t)>-1)return document.cookie=t.split("=")[0]+"=;domain=."+n+";expires=Thu, 01 Jan 1970 00:00:01 GMT;",n}function Be(){const i=window.location.search,t=new URLSearchParams(i).get("_saasquatch")||"";if(t){let e="",o="",r="";try{e=JSON.parse(D(t))}catch(a){v("Unable to decode params",a);return}try{o=JSON.parse(D(L.get("_saasquatch"))),v("existing cookie",o)}catch(a){v("Unable to retrieve cookie",a)}try{const a=Je();if(v("domain retrieved:",a),o){const d=ge(o,e);r=de(JSON.stringify(d)),v("cookie to store:",d)}else r=de(JSON.stringify(e)),v("cookie to store:",e);L.set("_saasquatch",r,{expires:365,secure:!1,sameSite:"Lax",domain:a,path:"/"})}catch(a){v("Unable to set cookie",a)}}}const Q=g.debug("squatch-js");function ze(i){const n=window.location.search,e=new URLSearchParams(n).get("_saasquatchExtra")||"";if(!e){Q("No _saasquatchExtra param");return}let o;try{o=JSON.parse(D(e))}catch{Q("Unable to decode _saasquatchExtra config");return}const{domain:r,tenantAlias:a,widgetConfig:d}=He(o);if(!r||!a||!d){Q("_saasquatchExtra did not have an expected structure");return}const{autoPopupWidgetType:u,...h}=d;return{widgetConfig:{widgetType:u,displayOnLoad:!0,...h},squatchConfig:{...i?{configIn:i}:{},domain:r,tenantAlias:a}}}function He(i){var r;const n=Object.keys(i||{})[0],t=Object.keys((i==null?void 0:i[n])||{})[0],e=(r=i==null?void 0:i[n])==null?void 0:r[t];return{domain:n?`https://${n}`:void 0,tenantAlias:t,widgetConfig:e}}const Ge=g.debug("squatch-js:decodeUserJwt");function Ve(i){var n;try{const t=i.split(".")[1];if(t===void 0)return null;const e=D(t);return(n=JSON.parse(e))==null?void 0:n.user}catch(t){return Ge(t),null}}const le=xe("squatch-js:DeclarativeWidget");class we extends HTMLElement{constructor(){super();p(this,"config");p(this,"token");p(this,"tenant");p(this,"widgetType");p(this,"locale");p(this,"widgetApi");p(this,"analyticsApi");p(this,"widgetInstance");p(this,"type");p(this,"container");p(this,"element");p(this,"loaded");p(this,"_setWidget",(t,e)=>{var r;const o={api:this.widgetApi,content:t,context:{type:e.type,user:e.user,container:this.container||void 0,engagementMedium:this.type},type:this.widgetType,domain:((r=this.config)==null?void 0:r.domain)||I,npmCdn:Z,container:this};if(this.type==="EMBED")return new q(o);{const a=this.firstChild?null:void 0;return new x(o,a)}});p(this,"setErrorWidget",t=>{var o;const e={api:this.widgetApi,content:"error",context:{type:"error",container:this.container||void 0},type:"ERROR_WIDGET",domain:((o=this.config)==null?void 0:o.domain)||I,npmCdn:Z,container:this};if(this.type==="EMBED")return new q(e);{const r=this.firstChild?null:void 0;return new x(e,r)}});p(this,"reload",this.renderWidget);p(this,"show",this.open);p(this,"hide",this.close);this.attachShadow({mode:"open"}).innerHTML="<style>:host { display: block; }</style><slot></slot>",this.config=te(),this.token=U(),this.tenant=window.squatchTenant,this.container=this}_setupApis(t){var e,o;if(!this.tenant)throw new Error("tenantAlias not provided");this.widgetApi=new z({tenantAlias:(t==null?void 0:t.tenantAlias)||this.tenant,domain:(t==null?void 0:t.domain)||((e=this.config)==null?void 0:e.domain)||I}),this.analyticsApi=new fe({domain:(t==null?void 0:t.domain)||((o=this.config)==null?void 0:o.domain)||I})}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(t=>this._setWidget(t.template,{type:"passwordless"})).catch(this.setErrorWidget)}async renderUserUpsertVariant(){this._setupApis();const t=Ve(this.token);return t?(le("Rendering as a Verified widget"),await this.widgetApi.upsertUser({user:t,locale:this.locale,engagementMedium:this.type,widgetType:this.widgetType,jwt:this.token}).then(o=>this._setWidget(o.template,{type:"upsert",user:t})).catch(this.setErrorWidget)):this.setErrorWidget(Error("No user object in token."))}async getWidgetInstance(){let t;if(this.widgetType=this.getAttribute("widget")||void 0,this.locale=this.getAttribute("locale")||this.locale,!this.widgetType)throw new Error("No widget has been specified");return this.token?t=await this.renderUserUpsertVariant():t=await this.renderPasswordlessVariant(),this.widgetInstance=t,this.widgetInstance&&this.dispatchEvent(new CustomEvent("sq:widget-loaded")),t}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()}}class ne extends we{constructor(){super(),this.type="EMBED",this.loaded=!1}static get observedAttributes(){return["widget","locale"]}attributeChangedCallback(n,t,e){if(!(t===e||!this.loaded))switch(n){case"locale":case"widget":this.connectedCallback();break}}async connectedCallback(){var t,e;this.loaded=!0,this.container=this.getAttribute("container"),await this.renderWidget();const n=(t=this.shadowRoot&&Array.from(this.shadowRoot.children))==null?void 0:t.find(o=>o.tagName==="SLOT");n&&((e=this.shadowRoot)==null||e.removeChild(n)),this.getAttribute("open")!==null&&this.open()}}class oe extends we{constructor(){super(),this.type="POPUP",this.loaded=!1,this.addEventListener("click",n=>{n.stopPropagation(),this.open()})}static get observedAttributes(){return["widget","locale"]}attributeChangedCallback(n,t,e){if(!(t===e||!this.loaded))switch(n){case"locale":case"widget":this.connectedCallback();break}}async connectedCallback(){this.loaded=!0,this.container=this.getAttribute("container"),await this.renderWidget(),this.getAttribute("open")!==null&&this.open()}}class Xe extends ne{}class Qe extends oe{}class Ye extends ne{}class Ze extends oe{}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",Ze);function Ke(){console.log("Having trouble using Squatch.js? Go to https://docs.referralsaasquatch.com/developer/ for tutorials, references and error codes.")}const k=g.debug("squatch-js");let j=null,N=null,J=null;function et(){return j||S({}),j}function H(){return N||S({}),N}function tt(){return J||S({}),J}function nt(i){var n;return(n=H())==null?void 0:n.render(i)}function ot(i){var t;const n=ze(i);if(n){const{squatchConfig:e,widgetConfig:o}=n;return S(e),(t=H())==null?void 0:t.render(o)}}function S(i){const t=B(i);t.tenantAlias.match("^test")||t.debug?g.debug.enable("squatch-js*"):g.debug.disable(),k("initializing ..."),j=new z(t),N=new R(t),J=new Le(t),k("Widget API instance",j),k("Widgets instance",N),k("Events API instance",J)}function it(i){i()}function rt(i){H().autofill(i)}function ye(){Be()}typeof document<"u"&&!window.SaaSquatchDoNotAutoDrop&&ye();var ue;(ue=window.squatch)!=null&&ue.init&&k("Squatchjs is being loaded more than once. This may lead to multiple load events being sent, duplicated widgets, and inaccurate analytics.");typeof document<"u"&&Ne();exports.DeclarativeEmbedWidget=ne;exports.DeclarativePopupWidget=oe;exports.EmbedWidget=q;exports.PopupWidget=x;exports.WidgetApi=z;exports.Widgets=R;exports._auto=ot;exports.api=et;exports.autofill=rt;exports.events=tt;exports.help=Ke;exports.init=S;exports.pushCookie=ye;exports.ready=it;exports.widget=nt;exports.widgets=H;
@@ -1,122 +0,0 @@
1
- import Widgets from "./widgets/Widgets";
2
- import EmbedWidget from "./widgets/EmbedWidget";
3
- import PopupWidget from "./widgets/PopupWidget";
4
- import WidgetApi from "./api/WidgetApi";
5
- import EventsApi from "./api/EventsApi";
6
- import { ConfigOptions, WidgetConfig, WidgetResult } from "./types";
7
- import { DeclarativeEmbedWidget, DeclarativePopupWidget } from "./widgets/declarative/DeclarativeWidgets";
8
- export * from "./types";
9
- export * from "./docs";
10
- export { Widgets, EmbedWidget, PopupWidget, DeclarativeEmbedWidget, DeclarativePopupWidget, WidgetApi, };
11
- /**
12
- * A static instance of the {@link WidgetApi} created when you call {@link #init init}.
13
- *
14
- * Read the {@link WidgetApi} docs.
15
- *
16
- * @returns WidgetApi static instance
17
- * @example
18
- * squatch.api().render({ ... })
19
- * squatch.api().upsertUser({ ... })
20
- * squatch.api().squatchReferralCookie()
21
- */
22
- export declare function api(): WidgetApi | null;
23
- /**
24
- * A static instance of the {@link Widgets} created when you call {@link #init init}.
25
- *
26
- * Read the {@link Widgets} docs.
27
- *
28
- * @returns static instance
29
- * @example
30
- * squatch.widgets().render({ widgetType: "w/widget-type" })
31
- * squatch.widgets().upsertUser({ user: { ... }, widgetType: "w/widget-type" })
32
- * squatch.widgets().autofill(".referral-code")
33
- */
34
- export declare function widgets(): Widgets | null;
35
- /**
36
- * A static instance of the {@link EventsApi} created when you call {@link #init init}.
37
- *
38
- * Read the {@link EventsApi} docs.
39
- *
40
- * @returns EventsApi static instance
41
- *
42
- * @example
43
- * squatch.events().track({ ... })
44
- */
45
- export declare function events(): EventsApi | null;
46
- /**
47
- * Entry-point for high level API to render a widget using the instance of {@link Widgets} created when you call {@link #init init}.
48
- *
49
- * Read the {@link Widgets.render} docs.
50
- *
51
- * @example
52
- * squatch.widget().then(res => {
53
- * const widget = res.widget
54
- * }).catch(e => console.error("Did not render widget:", e))
55
- */
56
- export declare function widget(widgetConfig: WidgetConfig): Promise<WidgetResult | undefined> | undefined;
57
- /**
58
- * Extracts widget configuration from `_saasquatchExtra` UTM parameter. Initialises `squatch` and renders the widget as a {@link PopupWidget} via static instanct of {@link Widgets}.
59
- *
60
- * Called by default on startup via the loader script.
61
- * @private
62
- */
63
- export declare function _auto(configIn: ConfigOptions): Promise<WidgetResult | undefined> | undefined;
64
- /**
65
- * Initializes the static `squatch` global. This sets up:
66
- *
67
- * - `squatch.api()` a static instance of the {@link WidgetApi}
68
- * - `squatch.widgets()` a static instance of {@link Widgets}
69
- * - `squatch.events()` a static instance of {@link EventsApi}
70
- *
71
- * @param config Configuration details
72
- *
73
- * @example
74
- * squatch.init({
75
- * tenantAlias:'test_basbtabstq51v',
76
- * });
77
- */
78
- export declare function init(configIn: ConfigOptions): void;
79
- /**
80
- * Squatch.js can't start safely making operations until it's "ready". This
81
- * function detects that state.
82
- *
83
- * @param fn A callback once Squatch.js is ready.
84
- *
85
- * @example
86
- * squatch.ready(function() {
87
- * console.log("ready!");
88
- * squatch.api().upsertUser({ ... });
89
- * });
90
- */
91
- export declare function ready(fn: () => any): void;
92
- /**
93
- * Autofills a referral code into an element when someone has been referred.
94
- * Uses {@link WidgetApi.squatchReferralCookie} behind the scenes.
95
- *
96
- * @param {string} selector Element class/id
97
- * @returns {void}
98
- *
99
- * @example
100
- * squatch.autofill("input.referral-code")
101
- * squatch.autofill("input#referral-code")
102
- */
103
- export declare function autofill(selector: string): void;
104
- /**
105
- * Manually set the _saasquatch cookie as a 1st party cookie if available as a URL parameter on the current page.
106
- * This runs automatically immediately when squatch-js is loaded, except when window.SaaSquatchDoNotAutoDrop is true.
107
- * Use this function manually if you have a single page application or custom routing that causes the `_saasquatch` URL parameter to not be set when Squatch.js loads.
108
-
109
- * It is safe to run this function multiple times. If the `_saasquatch` URL parameter is invalid or missing it will not clear the 1st party cookie.
110
-
111
- *
112
- * @returns {void}
113
- *
114
- * @example
115
- * squatch.pushCookie();
116
- */
117
- export declare function pushCookie(): void;
118
- declare global {
119
- interface Window {
120
- SaaSquatchDoNotAutoDrop?: boolean;
121
- }
122
- }