@descope/flow-scripts 1.0.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.
@@ -0,0 +1 @@
1
+ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(((e="undefined"!=typeof globalThis?globalThis:e||self).descope=e.descope||{},e.descope.fingerprint=e.descope.fingerprint||{},e.descope.fingerprint.ts={}))}(this,(function(e){"use strict";var n=function(){return n=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},n.apply(this,arguments)};function t(e,n,t,r){return new(t||(t=Promise))((function(o,i){function u(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(u,c)}a((r=r.apply(e,n||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;var r={default:"endpoint"},o="Blocked by CSP",i="The endpoint parameter is not a valid URL",u="Failed to load the JS script of the agent",c="9319";function a(e,n){var t,r,a,f,l,s=[],p=(t=function(e){var n=function(e,n,t){if(t||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return e.concat(r||Array.prototype.slice.call(n))}([],e,!0);return{current:function(){return n[0]},postpone:function(){var e=n.shift();void 0!==e&&n.push(e)},exclude:function(){n.shift()}}}(e),f=0,r=function(){return Math.random()*Math.min(3e3,100*Math.pow(2,f++))},a=new Set,[t.current(),function(e,n){var f,l=n instanceof Error?n.message:"";if(l===o||l===i)t.exclude(),f=0;else if(l===c)t.exclude();else if(l===u){var s=Date.now()-e.getTime()<50,p=t.current();p&&s&&!a.has(p)&&(a.add(p),f=0),t.postpone()}else t.postpone();var d=t.current();return void 0===d?void 0:[d,null!=f?f:e.getTime()+r()-Date.now()]}]),d=p[0],v=p[1];if(void 0===d)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var h=function(e){var t=new Date,r=function(n){return s.push({url:e,startedAt:t,finishedAt:new Date,error:n})},o=n(e);return o.then((function(){return r()}),r),o.catch((function(e){if(null!=l||(l=e),s.length>=5)throw l;var n=v(t,e);if(!n)throw l;var r,o=n[0],i=n[1];return(r=i,new Promise((function(e){return setTimeout(e,r)}))).then((function(){return h(o)}))}))};return h(d).then((function(e){return[e,s]}))}var f="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",l=f;function s(e){var t;e.scriptUrlPattern;var r=e.token,o=e.apiKey,i=void 0===o?r:o,l=function(e,n){var t={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)n.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(t[r[o]]=e[r[o]])}return t}(e,["scriptUrlPattern","token","apiKey"]),s=null!==(t=function(e,n){return function(e,n){return Object.prototype.hasOwnProperty.call(e,n)}(e,n)?e[n]:void 0}(e,"scriptUrlPattern"))&&void 0!==t?t:f,d=function(){var e=[],n=function(){e.push({time:new Date,state:document.visibilityState})},t=function(e,n,t,r){return e.addEventListener(n,t,r),function(){return e.removeEventListener(n,t,r)}}(document,"visibilitychange",n);return n(),[e,t]}(),v=d[0],h=d[1];return Promise.resolve().then((function(){if(!i||"string"!=typeof i)throw new Error("API key required");return a(function(e,n){return(Array.isArray(e)?e:[e]).map((function(e){return function(e,n){var t=encodeURIComponent;return e.replace(/<[^<>]+>/g,(function(e){return"<version>"===e?"3":"<apiKey>"===e?t(n):"<loaderVersion>"===e?t("3.11.8"):e}))}(String(e),n)}))}(s,i),p)})).catch((function(e){throw h(),function(e){return e instanceof Error&&e.message===c?new Error(u):e}(e)})).then((function(e){var t=e[0],r=e[1];return h(),t.load(n(n({},l),{ldi:{attempts:r,visibilityStates:v}}))}))}function p(e){return function(e,n,t){var r,o=document,i="securitypolicyviolation",u=function(n){var t=new URL(e,location.href),o=n.blockedURI;o!==t.href&&o!==t.protocol.slice(0,-1)&&o!==t.origin||(r=n,c())};o.addEventListener(i,u);var c=function(){return o.removeEventListener(i,u)};return Promise.resolve().then(n).then((function(e){return c(),e}),(function(e){return new Promise((function(e){var n=new MessageChannel;n.port1.onmessage=function(){return e()},n.port2.postMessage(null)})).then((function(){if(c(),r)return t(r);throw e}))}))}(e,(function(){return function(e){return new Promise((function(n,t){if(function(e){if(URL.prototype)try{return new URL(e,location.href),!1}catch(e){if(e instanceof Error&&"TypeError"===e.name)return!0;throw e}}(e))throw new Error(i);var r=document.createElement("script"),o=function(){var e;return null===(e=r.parentNode)||void 0===e?void 0:e.removeChild(r)},c=document.head||document.getElementsByTagName("head")[0];r.onload=function(){o(),n()},r.onerror=function(){o(),t(new Error(u))},r.async=!0,r.src=e,c.appendChild(r)}))}(e)}),(function(){throw new Error(o)})).then(d)}function d(){var e=window,n="__fpjs_p_l_b",t=e[n];if(function(e,n){var t,r=null===(t=Object.getOwnPropertyDescriptor)||void 0===t?void 0:t.call(Object,e,n);(null==r?void 0:r.configurable)?delete e[n]:r&&!r.writable||(e[n]=void 0)}(e,n),"function"!=typeof(null==t?void 0:t.load))throw new Error(c);return t}const v=(e,n,o)=>t(void 0,void 0,void 0,(function*(){try{const{publicApiKey:n,useCloudflareIntegration:t,cloudflareScriptUrl:i,cloudflareEndpointUrl:u}=e;let c=[];c=t&&u?[u,r]:[r];let a=[];if(t&&i){const e=new URL(i);a=[`${e.toString()}?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>`,l]}else a=[l];const f=s({apiKey:n,endpoint:c,scriptUrlPattern:a}),p=yield f,{requestId:d}=yield p.get();o(d)}catch(e){console.warn("Could not load fingerprint",e)}}));e.default=v,e.loadFingerprint=v,Object.defineProperty(e,"__esModule",{value:!0})}));
@@ -0,0 +1 @@
1
+ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(((e="undefined"!=typeof globalThis?globalThis:e||self).descope=e.descope||{},e.descope.fingerprintDescope=e.descope.fingerprintDescope||{},e.descope.fingerprintDescope.ts={}))}(this,(function(e){"use strict";var n=function(){return n=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},n.apply(this,arguments)};function t(e,n,t,r){return new(t||(t=Promise))((function(o,i){function c(e){try{a(r.next(e))}catch(e){i(e)}}function u(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(c,u)}a((r=r.apply(e,n||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;var r={default:"endpoint"},o="Blocked by CSP",i="The endpoint parameter is not a valid URL",c="Failed to load the JS script of the agent",u="9319";function a(e,n){var t,r,a,s,f,l=[],p=(t=function(e){var n=function(e,n,t){if(t||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return e.concat(r||Array.prototype.slice.call(n))}([],e,!0);return{current:function(){return n[0]},postpone:function(){var e=n.shift();void 0!==e&&n.push(e)},exclude:function(){n.shift()}}}(e),s=0,r=function(){return Math.random()*Math.min(3e3,100*Math.pow(2,s++))},a=new Set,[t.current(),function(e,n){var s,f=n instanceof Error?n.message:"";if(f===o||f===i)t.exclude(),s=0;else if(f===u)t.exclude();else if(f===c){var l=Date.now()-e.getTime()<50,p=t.current();p&&l&&!a.has(p)&&(a.add(p),s=0),t.postpone()}else t.postpone();var d=t.current();return void 0===d?void 0:[d,null!=s?s:e.getTime()+r()-Date.now()]}]),d=p[0],v=p[1];if(void 0===d)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var h=function(e){var t=new Date,r=function(n){return l.push({url:e,startedAt:t,finishedAt:new Date,error:n})},o=n(e);return o.then((function(){return r()}),r),o.catch((function(e){if(null!=f||(f=e),l.length>=5)throw f;var n=v(t,e);if(!n)throw f;var r,o=n[0],i=n[1];return(r=i,new Promise((function(e){return setTimeout(e,r)}))).then((function(){return h(o)}))}))};return h(d).then((function(e){return[e,l]}))}var s="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",f=s;function l(e){var t;e.scriptUrlPattern;var r=e.token,o=e.apiKey,i=void 0===o?r:o,f=function(e,n){var t={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)n.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(t[r[o]]=e[r[o]])}return t}(e,["scriptUrlPattern","token","apiKey"]),l=null!==(t=function(e,n){return function(e,n){return Object.prototype.hasOwnProperty.call(e,n)}(e,n)?e[n]:void 0}(e,"scriptUrlPattern"))&&void 0!==t?t:s,d=function(){var e=[],n=function(){e.push({time:new Date,state:document.visibilityState})},t=function(e,n,t,r){return e.addEventListener(n,t,r),function(){return e.removeEventListener(n,t,r)}}(document,"visibilitychange",n);return n(),[e,t]}(),v=d[0],h=d[1];return Promise.resolve().then((function(){if(!i||"string"!=typeof i)throw new Error("API key required");return a(function(e,n){return(Array.isArray(e)?e:[e]).map((function(e){return function(e,n){var t=encodeURIComponent;return e.replace(/<[^<>]+>/g,(function(e){return"<version>"===e?"3":"<apiKey>"===e?t(n):"<loaderVersion>"===e?t("3.11.8"):e}))}(String(e),n)}))}(l,i),p)})).catch((function(e){throw h(),function(e){return e instanceof Error&&e.message===u?new Error(c):e}(e)})).then((function(e){var t=e[0],r=e[1];return h(),t.load(n(n({},f),{ldi:{attempts:r,visibilityStates:v}}))}))}function p(e){return function(e,n,t){var r,o=document,i="securitypolicyviolation",c=function(n){var t=new URL(e,location.href),o=n.blockedURI;o!==t.href&&o!==t.protocol.slice(0,-1)&&o!==t.origin||(r=n,u())};o.addEventListener(i,c);var u=function(){return o.removeEventListener(i,c)};return Promise.resolve().then(n).then((function(e){return u(),e}),(function(e){return new Promise((function(e){var n=new MessageChannel;n.port1.onmessage=function(){return e()},n.port2.postMessage(null)})).then((function(){if(u(),r)return t(r);throw e}))}))}(e,(function(){return function(e){return new Promise((function(n,t){if(function(e){if(URL.prototype)try{return new URL(e,location.href),!1}catch(e){if(e instanceof Error&&"TypeError"===e.name)return!0;throw e}}(e))throw new Error(i);var r=document.createElement("script"),o=function(){var e;return null===(e=r.parentNode)||void 0===e?void 0:e.removeChild(r)},u=document.head||document.getElementsByTagName("head")[0];r.onload=function(){o(),n()},r.onerror=function(){o(),t(new Error(c))},r.async=!0,r.src=e,u.appendChild(r)}))}(e)}),(function(){throw new Error(o)})).then(d)}function d(){var e=window,n="__fpjs_p_l_b",t=e[n];if(function(e,n){var t,r=null===(t=Object.getOwnPropertyDescriptor)||void 0===t?void 0:t.call(Object,e,n);(null==r?void 0:r.configurable)?delete e[n]:r&&!r.writable||(e[n]=void 0)}(e,n),"function"!=typeof(null==t?void 0:t.load))throw new Error(u);return t}const v=(e,n,o)=>t(void 0,void 0,void 0,(function*(){try{const{customDomain:t,publicApiKey:i,cloudflareEndpointPath:c,cloudflareScriptPath:u}=e,{baseUrl:a}=n;let s;s=t?`https://${t}`:a||"https://api.descope.com";const p=new URL(s);p.pathname=c;const d=new URL(s);d.pathname=u;const v=`${d.toString()}?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>`,h=l({apiKey:i,endpoint:[p.toString(),r],scriptUrlPattern:[v,f]}),y=yield h,{requestId:m}=yield y.get();o(m)}catch(e){console.warn("Could not load descope fingerprint",e)}}));e.default=v,e.loadFingerprint=v,Object.defineProperty(e,"__esModule",{value:!0})}));
package/dist/forter.js ADDED
@@ -0,0 +1 @@
1
+ !function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):((t="undefined"!=typeof globalThis?globalThis:t||self).descope=t.descope||{},t.descope.forter=t.descope.forter||{},t.descope.forter.ts=n())}(this,(function(){"use strict";function t(t,n,e,r){return new(e||(e=Promise))((function(o,i){function c(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(c,a)}u((r=r.apply(t,n||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const n='\n(function () {\nvar merchantConfig = {\n csp: false\n};\n\nvar siteId = "{{SITE_ID}}";\nfunction t(t,n){for(var e=t.split(""),r=0;r<e.length;++r)e[r]=String.fromCharCode(e[r].charCodeAt(0)+n);return e.join("")}function n(n){return t(n,-L).replace(/%SN%/g,siteId)}function e(){var t="no"+"op"+"fn",n="g"+"a",e="n"+"ame";return window[n]&&window[n][e]===t}function r(){return!(!navigator.brave||"function"!=typeof navigator.brave.isBrave)}function o(){return document.currentScript&&document.currentScript.src}function i(t){try{if("number"==typeof t&&window.location&&window.location.pathname){for(var n=window.location.pathname.split("/"),e=[],r=0;r<=Math.min(n.length-1,Math.abs(t));r++)e.push(n[r]);return e.join("/")||"/"}}catch(t){}return"/"}function c(t){try{G.ex=t,e()&&-1===G.ex.indexOf(B.uB)&&(G.ex+=B.uB),r()&&-1===G.ex.indexOf(B.uBr)&&(G.ex+=B.uBr),o()&&-1===G.ex.indexOf(B.nIL)&&(G.ex+=B.nIL),window.ftr__snp_cwc||(G.ex+=B.s),M(G)}catch(t){}}function a(t,n){function e(o){try{o.blockedURI===t&&(n(),document.removeEventListener(r,e))}catch(t){document.removeEventListener(r,e)}}var r="securitypolicyviolation";document.addEventListener(r,e),setTimeout(function(){document.removeEventListener(r,e)},2*60*1e3)}function u(t,n,e,r){var o=!1;t="https://"+t,a(t,function(){r(!0),o=!0});var i=document.createElement("script");i.onerror=function(){if(!o)try{r(!1),o=!0}catch(t){}},i.onload=e,i.type="text/javascript",i.id="ftr__script",i.async=!0,i.src=t;var c=document.getElementsByTagName("script")[0];c.parentNode.insertBefore(i,c)}function f(){J(B.uDF),setTimeout(h,I,B.uDF)}function d(t,n,e,r){var o=!1,i=new XMLHttpRequest;if(a("https:"+t,function(){e(new Error("CSP Violation"),!0),o=!0}),"//"===t.slice(0,2)&&(t="https:"+t),"withCredentials"in i)i.open("GET",t,!0);else{if("undefined"==typeof XDomainRequest)return;i=new XDomainRequest,i.open("GET",t)}Object.keys(r).forEach(function(t){i.setRequestHeader(t,r[t])}),i.onload=function(){"function"==typeof n&&n(i)},i.onerror=function(t){if("function"==typeof e&&!o)try{e(t,!1),o=!0}catch(t){}},i.onprogress=function(){},i.ontimeout=function(){"function"==typeof e&&e("tim"+"eo"+"ut",!1)},setTimeout(function(){i.send()},0)}function s(t,siteId,n){function e(t){var n=t.toString(16);return n.length%2?"0"+n:n}function r(t){if(t<=0)return"";for(var n="0123456789abcdef",e="",r=0;r<t;r++)e+=n[Math.floor(Math.random()*n.length)];return e}function o(t){for(var n="",r=0;r<t.length;r++)n+=e(t.charCodeAt(r));return n}function i(t){for(var n=t.split(""),e=0;e<n.length;++e)n[e]=String.fromCharCode(255^n[e].charCodeAt(0));return n.join("")}n=n?"1":"0";var c=[];return c.push(t),c.push(siteId),c.push(n),function(t){var n=40,e="";return t.length<n/2&&(e=","+r(n/2-t.length-1)),o(i(t+e))}(c.join(","))}function w(){function t(){D&&(J(B.dUAL),setTimeout(h,I,B.dUAL))}function n(t,n){c(n?B.uAS+B.uF+B.cP:B.uAS+B.uF)}window.ftr__fdad(t,n)}function h(t){try{var n;switch(t){case B.uFP:n=q;break;case B.uDF:n=E;break;default:n=D}if(!n)return;u(n,void 0,function(){try{K(),c(t+B.uS)}catch(t){}},function(n){try{K(),G.td=1*new Date-G.ts,c(n?t+B.uF+B.cP:t+B.uF),t===B.uFP&&f(),t===B.uDF&&w()}catch(t){c(B.eUoe)}})}catch(n){c(t+B.eTlu)}}var m="22ge:t7mj8unkn;1forxgiurqw1qhw2vwdwxv",v="fort",l="erTo",p="ken";window.ftr__config={m:merchantConfig,s:"23",si:siteId};var g=!1,_=v+l+p,y=400*24*60,T=10,k={write:function(t,n,e,r){void 0===r&&(r=!0);var o=0;window.ftr__config&&window.ftr__config.m&&window.ftr__config.m.ckDepth&&(o=window.ftr__config.m.ckDepth);var c,a,u=i(o);if(e?(c=new Date,c.setTime(c.getTime()+60*e*1e3),a="; expires="+c.toGMTString()):a="",!r)return void(document.cookie=escape(t)+"="+escape(n)+a+"; path="+u);for(var f=1,d=document.domain.split("."),s=T,w=!0;w&&d.length>=f&&s>0;){var h=d.slice(-f).join(".");document.cookie=escape(t)+"="+escape(n)+a+"; path="+u+"; domain="+h;var m=k.read(t);null!=m&&m==n||(h="."+h,document.cookie=escape(t)+"="+escape(n)+a+"; path="+u+"; domain="+h),w=-1===document.cookie.indexOf(t+"="+n),f++,s--}},read:function(t){var n=null;try{for(var e=escape(t)+"=",r=document.cookie.split(";"),o=32,i=0;i<r.length;i++){for(var c=r[i];c.charCodeAt(0)===o;)c=c.substring(1,c.length);0===c.indexOf(e)&&(n=unescape(c.substring(e.length,c.length)))}}finally{return n}}},S=window.ftr__config.s;S+="ck";var x=function(t){var n=!1,e=null,r=function(){try{if(!e||!n)return;e.remove&&"function"==typeof e.remove?e.remove():document.head.removeChild(e),n=!1}catch(t){}};document.head&&(!function(){e=document.createElement("link"),e.setAttribute("rel","pre"+"con"+"nect"),e.setAttribute("cros"+"sori"+"gin","anonymous"),e.onload=r,e.onerror=r,e.setAttribute("href",t),document.head.appendChild(e),n=!0}(),setTimeout(r,3e3))},L=3,A=n(m||"22ge:t7mj8unkn;1forxgiurqw1qhw2vwdwxv"),F=t("[0Uhtxhvw0LG",-L),U=t("[0Fruuhodwlrq0LG",-L),b=t("Li0Qrqh0Pdwfk",-L),D,C="fgq71iruwhu1frp",E=n("(VQ(1"+C+"2vq2(VQ(2vfulsw1mv"),V=n("(VQ(1"+C+"2vqV2(VQ(2vfulsw1mv"),q;window.ftr__config&&window.ftr__config.m&&window.ftr__config.m.fpi&&(q=window.ftr__config.m.fpi+n("2vq2(VQ(2vfulsw1mv"));var I=10;window.ftr__startScriptLoad=1*new Date;var R=function(t){var n="ft"+"r:tok"+"enR"+"eady";window.ftr__tt&&clearTimeout(window.ftr__tt),window.ftr__tt=setTimeout(function(){try{delete window.ftr__tt,t+="_tt";var e=document.createEvent("Event");e.initEvent(n,!1,!1),e.detail=t,document.dispatchEvent(e)}catch(t){}},1e3)},M=function(t){var n=function(t){return t||""},e=n(t.id)+"_"+n(t.ts)+"_"+n(t.td)+"_"+n(t.ex)+"_"+n(S),r=y;!isNaN(window.ftr__config.m.ckTTL)&&window.ftr__config.m.ckTTL&&(r=window.ftr__config.m.ckTTL),k.write(_,e,r,!0),R(e),window.ftr__gt=e},P=function(){var t=k.read(_)||"",n=t.split("_"),e=function(t){return n[t]||void 0};return{id:e(0),ts:e(1),td:e(2),ex:e(3),vr:e(4)}},j=function(){for(var t={},n="fgu",e=[],r=0;r<256;r++)e[r]=(r<16?"0":"")+r.toString(16);var o=function(t,n,r,o,i){var c=i?"-":"";return e[255&t]+e[t>>8&255]+e[t>>16&255]+e[t>>24&255]+c+e[255&n]+e[n>>8&255]+c+e[n>>16&15|64]+e[n>>24&255]+c+e[63&r|128]+e[r>>8&255]+c+e[r>>16&255]+e[r>>24&255]+e[255&o]+e[o>>8&255]+e[o>>16&255]+e[o>>24&255]},i=function(){if(window.Uint32Array&&window.crypto&&window.crypto.getRandomValues){var t=new window.Uint32Array(4);return window.crypto.getRandomValues(t),{d0:t[0],d1:t[1],d2:t[2],d3:t[3]}}return{d0:4294967296*Math.random()>>>0,d1:4294967296*Math.random()>>>0,d2:4294967296*Math.random()>>>0,d3:4294967296*Math.random()>>>0}},c=function(){var t="",n=function(t,n){for(var e="",r=t;r>0;--r)e+=n.charAt(1e3*Math.random()%n.length);return e};return t+=n(2,"0123456789"),t+=n(1,"123456789"),t+=n(8,"0123456789")};return t.safeGenerateNoDash=function(){try{var t=i();return o(t.d0,t.d1,t.d2,t.d3,!1)}catch(t){try{return n+c()}catch(t){}}},t.isValidNumericalToken=function(t){return t&&t.toString().length<=11&&t.length>=9&&parseInt(t,10).toString().length<=11&&parseInt(t,10).toString().length>=9},t.isValidUUIDToken=function(t){return t&&32===t.toString().length&&/^[a-z0-9]+$/.test(t)},t.isValidFGUToken=function(t){return 0==t.indexOf(n)&&t.length>=12},t}(),B={uDF:"UDF",dUAL:"dUAL",uAS:"UAS",uFP:"UFP",mLd:"1",eTlu:"2",eUoe:"3",uS:"4",uF:"9",tmos:["T5","T10","T15","T30","T60"],tmosSecs:[5,10,15,30,60],bIR:"43",uB:"u",uBr:"b",cP:"c",nIL:"i",s:"s"};try{var G=P();try{G.id&&(j.isValidNumericalToken(G.id)||j.isValidUUIDToken(G.id)||j.isValidFGUToken(G.id))?window.ftr__ncd=!1:(G.id=j.safeGenerateNoDash(),window.ftr__ncd=!0),G.ts=window.ftr__startScriptLoad,M(G),window.ftr__snp_cwc=!!k.read(_),window.ftr__snp_cwc||(E=V);for(var N="for"+"ter"+".co"+"m",O="ht"+"tps://c"+"dn9."+N,Q="ht"+"tps://"+G.id+"-"+siteId+".cd"+"n."+N,H="http"+"s://cd"+"n3."+N,X=[O,Q,H],z=0;z<X.length;z++)x(X[z]);var $=new Array(B.tmosSecs.length),J=function(t){for(var n=0;n<B.tmosSecs.length;n++)$[n]=setTimeout(c,1e3*B.tmosSecs[n],t+B.tmos[n])},K=function(){for(var t=0;t<B.tmosSecs.length;t++)clearTimeout($[t])};window.ftr__fdad=function(n,e){if(!g){g=!0;var r={};r[b]=s(window.ftr__config.s,siteId,window.ftr__config.m.csp),d(A,function(e){try{var r=e.getAllResponseHeaders().toLowerCase();if(r.indexOf(U.toLowerCase())>=0){var o=e.getResponseHeader(U);window.ftr__altd2=t(atob(o),-L-1)}if(r.indexOf(F.toLowerCase())<0)return;var i=e.getResponseHeader(F),c=t(atob(i),-L-1);if(c){var a=c.split(":");if(a&&2===a.length){for(var u=a[0],f=a[1],d="",s=0,w=0;s<20;++s)d+=s%3>0&&w<12?siteId.charAt(w++):G.id.charAt(s);var h=f.split(",");if(h.length>1){var m=h[0],v=h[1];D=u+"/"+m+"."+d+"."+v}}}n()}catch(t){}},function(t,n){e&&e(t,n)},r)}};var W=q?B.uFP:B.uDF;J(W),setTimeout(h,I,W)}catch(t){c(B.mLd)}}catch(t){}})();\n';return(e,r,o)=>t(void 0,void 0,void 0,(function*(){const{siteId:t}=e,r=n.replace(/{{SITE_ID}}/g,t),i=document.createElement("script");i.setAttribute("type","text/javascript"),i.setAttribute("id",t),i.text=r,document.body.appendChild(i),document.addEventListener("ftr:tokenReady",(t=>{o(t.detail)}))}))}));
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).descope=e.descope||{},e.descope.grecaptcha=e.descope.grecaptcha||{},e.descope.grecaptcha.ts={}))}(this,(function(e){"use strict";const t=(e,t,c)=>{const n=()=>{var t;return e.enterprise?null===(t=window.grecaptcha)||void 0===t?void 0:t.enterprise:window.grecaptcha};let o,a;const r=(t,n)=>{t.ready((()=>{e.siteKey&&(null==t||t.execute(a,{action:"load"}).then(((e,n)=>{n?console.warn("could not execute recaptcha",n):(c(e),o=setTimeout((()=>{r(t)}),11e4))})))}))},s=(()=>{const e=document.createElement("div");return e.style.display="none",e.id="recaptcha",document.body.appendChild(e)})();return window.onRecaptchaLoadCallback=()=>{const t=s;if(t.hasChildNodes())return;const c=n();c&&setTimeout((()=>{a=c.render(t,{sitekey:e.siteKey,badge:"inline",size:"invisible"}),r(c)}),0)},(()=>{const t=document.createElement("script");t.src=(()=>{const t=new URL("https://www.google.com/recaptcha/");return t.pathname+=(e.enterprise?"enterprise":"api")+".js",t.searchParams.append("onload","onRecaptchaLoadCallback"),t.searchParams.append("render","explicit"),t.toString()})(),t.async=!0,t.id="recaptcha-script",t.defer=!0,document.body.appendChild(t)})(),{stop:()=>{clearTimeout(o)},start:()=>{const e=n();e&&r(e)}}};e.default=t,e.loadGRecaptcha=t,Object.defineProperty(e,"__esModule",{value:!0})}));
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@descope/flow-scripts",
3
+ "type": "module",
4
+ "version": "1.0.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/descope/content"
8
+ },
9
+ "scripts": {
10
+ "build": "rollup -c",
11
+ "build:ci": "rollup -c --environment BUILD:ci"
12
+ },
13
+ "devDependencies": {
14
+ "@rollup/plugin-commonjs": "^28.0.2",
15
+ "@rollup/plugin-node-resolve": "^16.0.0",
16
+ "@rollup/plugin-terser": "^0.4.4",
17
+ "@rollup/plugin-typescript": "^12.1.2",
18
+ "rollup": "^4.34.7",
19
+ "typescript": "^5.7.3"
20
+ },
21
+ "dependencies": {
22
+ "@fingerprintjs/fingerprintjs-pro": "^3.11.8"
23
+ }
24
+ }
@@ -0,0 +1,19 @@
1
+ import typescript from '@rollup/plugin-typescript';
2
+ import terser from '@rollup/plugin-terser';
3
+ import { nodeResolve } from '@rollup/plugin-node-resolve';
4
+ import commonjs from '@rollup/plugin-commonjs';
5
+ import fs from 'fs';
6
+
7
+ const scriptFiles = fs.readdirSync("./src");
8
+ export default scriptFiles.map(name => ({
9
+ input: `src/${name}`,
10
+ output: {
11
+ preserveModules: false,
12
+ dir: 'dist',
13
+ format: 'umd',
14
+ name: `descope.${name}`,
15
+ inlineDynamicImports: true,
16
+ },
17
+ external: [],
18
+ plugins: [typescript({ sourceMap: true }), nodeResolve(), commonjs({ ignore: ['worker_threads'] }), terser()]
19
+ }));
@@ -0,0 +1,57 @@
1
+ import {
2
+ load,
3
+ defaultEndpoint,
4
+ defaultScriptUrlPattern,
5
+ } from '@fingerprintjs/fingerprintjs-pro';
6
+
7
+ export const loadFingerprint = async (
8
+ initArgs: {
9
+ publicApiKey: string;
10
+ useCloudflareIntegration: boolean;
11
+ cloudflareEndpointUrl: string;
12
+ cloudflareScriptUrl: string;
13
+ },
14
+ _: { baseUrl?: string },
15
+ onTokenReady: (token: string) => void,
16
+ ) => {
17
+ try {
18
+ const {
19
+ publicApiKey,
20
+ useCloudflareIntegration,
21
+ cloudflareScriptUrl,
22
+ cloudflareEndpointUrl,
23
+ } = initArgs;
24
+
25
+ let endpoints: any[] = [];
26
+ if (useCloudflareIntegration && cloudflareEndpointUrl) {
27
+ endpoints = [cloudflareEndpointUrl, defaultEndpoint];
28
+ } else {
29
+ endpoints = [defaultEndpoint];
30
+ }
31
+
32
+ let scriptUrlPatterns: any[] = [];
33
+ if (useCloudflareIntegration && cloudflareScriptUrl) {
34
+ const patterUrl = new URL(cloudflareScriptUrl);
35
+ const scriptUrlPattern = `${patterUrl.toString()}?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>`;
36
+ scriptUrlPatterns = [scriptUrlPattern, defaultScriptUrlPattern];
37
+ } else {
38
+ scriptUrlPatterns = [defaultScriptUrlPattern];
39
+ }
40
+
41
+ // load from FingerprintJS
42
+ const agentP = load({
43
+ apiKey: publicApiKey,
44
+ endpoint: endpoints,
45
+ scriptUrlPattern: scriptUrlPatterns,
46
+ });
47
+
48
+ const agent = await agentP;
49
+ const { requestId } = await agent.get();
50
+ onTokenReady(requestId);
51
+ } catch (ex) {
52
+ // eslint-disable-next-line no-console
53
+ console.warn('Could not load fingerprint', ex);
54
+ }
55
+ };
56
+
57
+ export default loadFingerprint;
@@ -0,0 +1,63 @@
1
+ import {
2
+ load,
3
+ defaultEndpoint,
4
+ defaultScriptUrlPattern,
5
+ } from '@fingerprintjs/fingerprintjs-pro';
6
+
7
+ export const loadFingerprint = async (
8
+ initArgs: {
9
+ customDomain?: string;
10
+ publicApiKey: string;
11
+ cloudflareEndpointPath: string;
12
+ cloudflareScriptPath: string;
13
+ },
14
+ inputs: { baseUrl?: string },
15
+ onTokenReady: (token: string) => void,
16
+ ) => {
17
+ try {
18
+ const {
19
+ customDomain,
20
+ publicApiKey,
21
+ cloudflareEndpointPath,
22
+ cloudflareScriptPath,
23
+ } = initArgs;
24
+ const { baseUrl } = inputs;
25
+ let fpUrl: string;
26
+ if (customDomain) {
27
+ fpUrl = `https://${customDomain}`;
28
+ } else if (baseUrl) {
29
+ fpUrl = baseUrl;
30
+ } else {
31
+ fpUrl = 'https://api.descope.com';
32
+ }
33
+
34
+ const endpointUrl = new URL(fpUrl);
35
+ endpointUrl.pathname = cloudflareEndpointPath;
36
+
37
+ const patterUrl = new URL(fpUrl);
38
+ patterUrl.pathname = cloudflareScriptPath;
39
+ const scriptUrlPattern = `${patterUrl.toString()}?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>`;
40
+
41
+ // load from FingerprintJS
42
+ const agentP = load({
43
+ apiKey: publicApiKey,
44
+ endpoint: [
45
+ endpointUrl.toString(),
46
+ defaultEndpoint, // Fallback to default endpoint in case of error
47
+ ],
48
+ scriptUrlPattern: [
49
+ scriptUrlPattern,
50
+ defaultScriptUrlPattern, // Fallback to default CDN in case of error
51
+ ],
52
+ });
53
+
54
+ const agent = await agentP;
55
+ const { requestId } = await agent.get();
56
+ onTokenReady(requestId);
57
+ } catch (ex) {
58
+ // eslint-disable-next-line no-console
59
+ console.warn('Could not load descope fingerprint', ex);
60
+ }
61
+ };
62
+
63
+ export default loadFingerprint;
package/src/forter.ts ADDED
@@ -0,0 +1,30 @@
1
+ // Source: Forter team
2
+ const forterScript = `
3
+ (function () {
4
+ var merchantConfig = {
5
+ csp: false
6
+ };
7
+
8
+ var siteId = "{{SITE_ID}}";
9
+ function t(t,n){for(var e=t.split(""),r=0;r<e.length;++r)e[r]=String.fromCharCode(e[r].charCodeAt(0)+n);return e.join("")}function n(n){return t(n,-L).replace(/%SN%/g,siteId)}function e(){var t="no"+"op"+"fn",n="g"+"a",e="n"+"ame";return window[n]&&window[n][e]===t}function r(){return!(!navigator.brave||"function"!=typeof navigator.brave.isBrave)}function o(){return document.currentScript&&document.currentScript.src}function i(t){try{if("number"==typeof t&&window.location&&window.location.pathname){for(var n=window.location.pathname.split("/"),e=[],r=0;r<=Math.min(n.length-1,Math.abs(t));r++)e.push(n[r]);return e.join("/")||"/"}}catch(t){}return"/"}function c(t){try{G.ex=t,e()&&-1===G.ex.indexOf(B.uB)&&(G.ex+=B.uB),r()&&-1===G.ex.indexOf(B.uBr)&&(G.ex+=B.uBr),o()&&-1===G.ex.indexOf(B.nIL)&&(G.ex+=B.nIL),window.ftr__snp_cwc||(G.ex+=B.s),M(G)}catch(t){}}function a(t,n){function e(o){try{o.blockedURI===t&&(n(),document.removeEventListener(r,e))}catch(t){document.removeEventListener(r,e)}}var r="securitypolicyviolation";document.addEventListener(r,e),setTimeout(function(){document.removeEventListener(r,e)},2*60*1e3)}function u(t,n,e,r){var o=!1;t="https://"+t,a(t,function(){r(!0),o=!0});var i=document.createElement("script");i.onerror=function(){if(!o)try{r(!1),o=!0}catch(t){}},i.onload=e,i.type="text/javascript",i.id="ftr__script",i.async=!0,i.src=t;var c=document.getElementsByTagName("script")[0];c.parentNode.insertBefore(i,c)}function f(){J(B.uDF),setTimeout(h,I,B.uDF)}function d(t,n,e,r){var o=!1,i=new XMLHttpRequest;if(a("https:"+t,function(){e(new Error("CSP Violation"),!0),o=!0}),"//"===t.slice(0,2)&&(t="https:"+t),"withCredentials"in i)i.open("GET",t,!0);else{if("undefined"==typeof XDomainRequest)return;i=new XDomainRequest,i.open("GET",t)}Object.keys(r).forEach(function(t){i.setRequestHeader(t,r[t])}),i.onload=function(){"function"==typeof n&&n(i)},i.onerror=function(t){if("function"==typeof e&&!o)try{e(t,!1),o=!0}catch(t){}},i.onprogress=function(){},i.ontimeout=function(){"function"==typeof e&&e("tim"+"eo"+"ut",!1)},setTimeout(function(){i.send()},0)}function s(t,siteId,n){function e(t){var n=t.toString(16);return n.length%2?"0"+n:n}function r(t){if(t<=0)return"";for(var n="0123456789abcdef",e="",r=0;r<t;r++)e+=n[Math.floor(Math.random()*n.length)];return e}function o(t){for(var n="",r=0;r<t.length;r++)n+=e(t.charCodeAt(r));return n}function i(t){for(var n=t.split(""),e=0;e<n.length;++e)n[e]=String.fromCharCode(255^n[e].charCodeAt(0));return n.join("")}n=n?"1":"0";var c=[];return c.push(t),c.push(siteId),c.push(n),function(t){var n=40,e="";return t.length<n/2&&(e=","+r(n/2-t.length-1)),o(i(t+e))}(c.join(","))}function w(){function t(){D&&(J(B.dUAL),setTimeout(h,I,B.dUAL))}function n(t,n){c(n?B.uAS+B.uF+B.cP:B.uAS+B.uF)}window.ftr__fdad(t,n)}function h(t){try{var n;switch(t){case B.uFP:n=q;break;case B.uDF:n=E;break;default:n=D}if(!n)return;u(n,void 0,function(){try{K(),c(t+B.uS)}catch(t){}},function(n){try{K(),G.td=1*new Date-G.ts,c(n?t+B.uF+B.cP:t+B.uF),t===B.uFP&&f(),t===B.uDF&&w()}catch(t){c(B.eUoe)}})}catch(n){c(t+B.eTlu)}}var m="22ge:t7mj8unkn;1forxgiurqw1qhw2vwdwxv",v="fort",l="erTo",p="ken";window.ftr__config={m:merchantConfig,s:"23",si:siteId};var g=!1,_=v+l+p,y=400*24*60,T=10,k={write:function(t,n,e,r){void 0===r&&(r=!0);var o=0;window.ftr__config&&window.ftr__config.m&&window.ftr__config.m.ckDepth&&(o=window.ftr__config.m.ckDepth);var c,a,u=i(o);if(e?(c=new Date,c.setTime(c.getTime()+60*e*1e3),a="; expires="+c.toGMTString()):a="",!r)return void(document.cookie=escape(t)+"="+escape(n)+a+"; path="+u);for(var f=1,d=document.domain.split("."),s=T,w=!0;w&&d.length>=f&&s>0;){var h=d.slice(-f).join(".");document.cookie=escape(t)+"="+escape(n)+a+"; path="+u+"; domain="+h;var m=k.read(t);null!=m&&m==n||(h="."+h,document.cookie=escape(t)+"="+escape(n)+a+"; path="+u+"; domain="+h),w=-1===document.cookie.indexOf(t+"="+n),f++,s--}},read:function(t){var n=null;try{for(var e=escape(t)+"=",r=document.cookie.split(";"),o=32,i=0;i<r.length;i++){for(var c=r[i];c.charCodeAt(0)===o;)c=c.substring(1,c.length);0===c.indexOf(e)&&(n=unescape(c.substring(e.length,c.length)))}}finally{return n}}},S=window.ftr__config.s;S+="ck";var x=function(t){var n=!1,e=null,r=function(){try{if(!e||!n)return;e.remove&&"function"==typeof e.remove?e.remove():document.head.removeChild(e),n=!1}catch(t){}};document.head&&(!function(){e=document.createElement("link"),e.setAttribute("rel","pre"+"con"+"nect"),e.setAttribute("cros"+"sori"+"gin","anonymous"),e.onload=r,e.onerror=r,e.setAttribute("href",t),document.head.appendChild(e),n=!0}(),setTimeout(r,3e3))},L=3,A=n(m||"22ge:t7mj8unkn;1forxgiurqw1qhw2vwdwxv"),F=t("[0Uhtxhvw0LG",-L),U=t("[0Fruuhodwlrq0LG",-L),b=t("Li0Qrqh0Pdwfk",-L),D,C="fgq71iruwhu1frp",E=n("(VQ(1"+C+"2vq2(VQ(2vfulsw1mv"),V=n("(VQ(1"+C+"2vqV2(VQ(2vfulsw1mv"),q;window.ftr__config&&window.ftr__config.m&&window.ftr__config.m.fpi&&(q=window.ftr__config.m.fpi+n("2vq2(VQ(2vfulsw1mv"));var I=10;window.ftr__startScriptLoad=1*new Date;var R=function(t){var n="ft"+"r:tok"+"enR"+"eady";window.ftr__tt&&clearTimeout(window.ftr__tt),window.ftr__tt=setTimeout(function(){try{delete window.ftr__tt,t+="_tt";var e=document.createEvent("Event");e.initEvent(n,!1,!1),e.detail=t,document.dispatchEvent(e)}catch(t){}},1e3)},M=function(t){var n=function(t){return t||""},e=n(t.id)+"_"+n(t.ts)+"_"+n(t.td)+"_"+n(t.ex)+"_"+n(S),r=y;!isNaN(window.ftr__config.m.ckTTL)&&window.ftr__config.m.ckTTL&&(r=window.ftr__config.m.ckTTL),k.write(_,e,r,!0),R(e),window.ftr__gt=e},P=function(){var t=k.read(_)||"",n=t.split("_"),e=function(t){return n[t]||void 0};return{id:e(0),ts:e(1),td:e(2),ex:e(3),vr:e(4)}},j=function(){for(var t={},n="fgu",e=[],r=0;r<256;r++)e[r]=(r<16?"0":"")+r.toString(16);var o=function(t,n,r,o,i){var c=i?"-":"";return e[255&t]+e[t>>8&255]+e[t>>16&255]+e[t>>24&255]+c+e[255&n]+e[n>>8&255]+c+e[n>>16&15|64]+e[n>>24&255]+c+e[63&r|128]+e[r>>8&255]+c+e[r>>16&255]+e[r>>24&255]+e[255&o]+e[o>>8&255]+e[o>>16&255]+e[o>>24&255]},i=function(){if(window.Uint32Array&&window.crypto&&window.crypto.getRandomValues){var t=new window.Uint32Array(4);return window.crypto.getRandomValues(t),{d0:t[0],d1:t[1],d2:t[2],d3:t[3]}}return{d0:4294967296*Math.random()>>>0,d1:4294967296*Math.random()>>>0,d2:4294967296*Math.random()>>>0,d3:4294967296*Math.random()>>>0}},c=function(){var t="",n=function(t,n){for(var e="",r=t;r>0;--r)e+=n.charAt(1e3*Math.random()%n.length);return e};return t+=n(2,"0123456789"),t+=n(1,"123456789"),t+=n(8,"0123456789")};return t.safeGenerateNoDash=function(){try{var t=i();return o(t.d0,t.d1,t.d2,t.d3,!1)}catch(t){try{return n+c()}catch(t){}}},t.isValidNumericalToken=function(t){return t&&t.toString().length<=11&&t.length>=9&&parseInt(t,10).toString().length<=11&&parseInt(t,10).toString().length>=9},t.isValidUUIDToken=function(t){return t&&32===t.toString().length&&/^[a-z0-9]+$/.test(t)},t.isValidFGUToken=function(t){return 0==t.indexOf(n)&&t.length>=12},t}(),B={uDF:"UDF",dUAL:"dUAL",uAS:"UAS",uFP:"UFP",mLd:"1",eTlu:"2",eUoe:"3",uS:"4",uF:"9",tmos:["T5","T10","T15","T30","T60"],tmosSecs:[5,10,15,30,60],bIR:"43",uB:"u",uBr:"b",cP:"c",nIL:"i",s:"s"};try{var G=P();try{G.id&&(j.isValidNumericalToken(G.id)||j.isValidUUIDToken(G.id)||j.isValidFGUToken(G.id))?window.ftr__ncd=!1:(G.id=j.safeGenerateNoDash(),window.ftr__ncd=!0),G.ts=window.ftr__startScriptLoad,M(G),window.ftr__snp_cwc=!!k.read(_),window.ftr__snp_cwc||(E=V);for(var N="for"+"ter"+".co"+"m",O="ht"+"tps://c"+"dn9."+N,Q="ht"+"tps://"+G.id+"-"+siteId+".cd"+"n."+N,H="http"+"s://cd"+"n3."+N,X=[O,Q,H],z=0;z<X.length;z++)x(X[z]);var $=new Array(B.tmosSecs.length),J=function(t){for(var n=0;n<B.tmosSecs.length;n++)$[n]=setTimeout(c,1e3*B.tmosSecs[n],t+B.tmos[n])},K=function(){for(var t=0;t<B.tmosSecs.length;t++)clearTimeout($[t])};window.ftr__fdad=function(n,e){if(!g){g=!0;var r={};r[b]=s(window.ftr__config.s,siteId,window.ftr__config.m.csp),d(A,function(e){try{var r=e.getAllResponseHeaders().toLowerCase();if(r.indexOf(U.toLowerCase())>=0){var o=e.getResponseHeader(U);window.ftr__altd2=t(atob(o),-L-1)}if(r.indexOf(F.toLowerCase())<0)return;var i=e.getResponseHeader(F),c=t(atob(i),-L-1);if(c){var a=c.split(":");if(a&&2===a.length){for(var u=a[0],f=a[1],d="",s=0,w=0;s<20;++s)d+=s%3>0&&w<12?siteId.charAt(w++):G.id.charAt(s);var h=f.split(",");if(h.length>1){var m=h[0],v=h[1];D=u+"/"+m+"."+d+"."+v}}}n()}catch(t){}},function(t,n){e&&e(t,n)},r)}};var W=q?B.uFP:B.uDF;J(W),setTimeout(h,I,W)}catch(t){c(B.mLd)}}catch(t){}})();
10
+ `;
11
+
12
+ const loadForter = async (
13
+ initArgs: { siteId: string },
14
+ _: { baseUrl?: string },
15
+ onTokenReady: (token: string) => void,
16
+ ) => {
17
+ const { siteId } = initArgs;
18
+ const script = forterScript.replace(/{{SITE_ID}}/g, siteId);
19
+ const scriptTag = document.createElement('script');
20
+ scriptTag.setAttribute('type', 'text/javascript');
21
+ scriptTag.setAttribute('id', siteId);
22
+ scriptTag.text = script;
23
+ document.body.appendChild(scriptTag);
24
+
25
+ document.addEventListener('ftr:tokenReady', (evt) => {
26
+ onTokenReady((evt as CustomEvent).detail);
27
+ });
28
+ };
29
+
30
+ export default loadForter;
@@ -0,0 +1,119 @@
1
+ declare global {
2
+ interface Window {
3
+ grecaptcha?: {
4
+ enterprise?: any;
5
+ ready: (callback: () => void) => void;
6
+ execute: (widgetId: any, options: { action: string }) => Promise<string>;
7
+ render: (container: HTMLElement, parameters: any) => any;
8
+ };
9
+ onRecaptchaLoadCallback: () => void;
10
+ }
11
+ }
12
+
13
+ export const loadGRecaptcha = (
14
+ initArgs: {
15
+ enterprise: boolean;
16
+ siteKey: string;
17
+ },
18
+ _inputs: { baseUrl?: string },
19
+ onTokenReady: (token: string) => void,
20
+ ) => {
21
+ const getScriptURL = () => {
22
+ const url = new URL('https://www.google.com/recaptcha/');
23
+ url.pathname += `${initArgs.enterprise ? 'enterprise' : 'api'}.js`;
24
+ url.searchParams.append('onload', 'onRecaptchaLoadCallback');
25
+ url.searchParams.append('render', 'explicit');
26
+ return url.toString();
27
+ };
28
+
29
+ const loadRecaptchaScript = () => {
30
+ const script = document.createElement('script');
31
+ script.src = getScriptURL();
32
+ script.async = true;
33
+ script.id = 'recaptcha-script';
34
+ script.defer = true;
35
+ document.body.appendChild(script);
36
+ };
37
+
38
+ const getGrecaptchaInstance = () =>
39
+ initArgs.enterprise ? window.grecaptcha?.enterprise : window.grecaptcha;
40
+
41
+ let timer;
42
+ let recaptchaWidgetId;
43
+
44
+ const getNewToken = (grecaptchaInstance, currentNode) => {
45
+ grecaptchaInstance.ready(() => {
46
+ if (!initArgs.siteKey) {
47
+ return;
48
+ }
49
+ grecaptchaInstance
50
+ ?.execute(recaptchaWidgetId, { action: 'load' })
51
+ .then((token: string, e: any) => {
52
+ if (e) {
53
+ // eslint-disable-next-line no-console
54
+ console.warn('could not execute recaptcha', e);
55
+ } else {
56
+ onTokenReady(token);
57
+ // if the component is still connected, we should try to get a new token before the token expires (2 minutes)
58
+ timer = setTimeout(() => {
59
+ getNewToken(grecaptchaInstance, currentNode);
60
+ }, 110000);
61
+ }
62
+ });
63
+ });
64
+ };
65
+
66
+ const stopTimer = () => {
67
+ clearTimeout(timer);
68
+ };
69
+
70
+ const createRecaptchaEle = () => {
71
+ const recaptchaEle = document.createElement('div');
72
+ recaptchaEle.style.display = 'none';
73
+ recaptchaEle.id = 'recaptcha';
74
+ return document.body.appendChild(recaptchaEle);
75
+ };
76
+
77
+ const elementRef = createRecaptchaEle();
78
+
79
+ const resumeScriptExecution = () => {
80
+ const grecaptchaInstance = getGrecaptchaInstance();
81
+ if (!grecaptchaInstance) {
82
+ return;
83
+ }
84
+ getNewToken(grecaptchaInstance, elementRef);
85
+ };
86
+
87
+ const createOnLoadScript = () => {
88
+ window.onRecaptchaLoadCallback = () => {
89
+ const currentNode = elementRef;
90
+
91
+ // if there are child nodes, it means that the recaptcha was already rendered
92
+ if (currentNode.hasChildNodes()) {
93
+ return;
94
+ }
95
+
96
+ const grecaptchaInstance = getGrecaptchaInstance();
97
+
98
+ if (!grecaptchaInstance) {
99
+ return;
100
+ }
101
+
102
+ setTimeout(() => {
103
+ recaptchaWidgetId = grecaptchaInstance.render(currentNode, {
104
+ sitekey: initArgs.siteKey,
105
+ badge: 'inline',
106
+ size: 'invisible',
107
+ });
108
+ getNewToken(grecaptchaInstance, currentNode);
109
+ }, 0);
110
+ };
111
+ };
112
+
113
+ createOnLoadScript();
114
+ loadRecaptchaScript();
115
+
116
+ return { stop: stopTimer, start: resumeScriptExecution };
117
+ };
118
+
119
+ export default loadGRecaptcha;
package/tsconfig.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es6",
4
+ "module": "ESNext",
5
+ "moduleResolution": "node",
6
+ "sourceMap": true,
7
+ "emitDecoratorMetadata": true,
8
+ "esModuleInterop": true,
9
+ "allowSyntheticDefaultImports": true,
10
+ "strict": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "experimentalDecorators": true,
13
+ "removeComments": false,
14
+ "noImplicitAny": false,
15
+ "baseUrl": "src",
16
+ "outDir": "./dist"
17
+ },
18
+ "include": [
19
+ "src/**/*.ts"
20
+ ],
21
+ "exclude": [
22
+ "node_modules",
23
+ ".npm"
24
+ ]
25
+ }