@descope/flow-scripts 1.0.0 → 1.0.2

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.
@@ -1 +1,2 @@
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})}));
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}
2
+ /*! Source: (c) FingerprintJS and other contributors | https://dev.fingerprint.com/ */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})}));
@@ -1 +1,2 @@
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})}));
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}
2
+ /*! Source: (c) FingerprintJS and other contributors | https://dev.fingerprint.com/ */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 CHANGED
@@ -1 +1,3 @@
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)}))}))}));
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;
2
+ /*! Source: (c) forter and other contributors | https://www.forter.com */
3
+ 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)}))}))}));
@@ -1 +1,3 @@
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})}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((e="undefined"!=typeof globalThis?globalThis:e||self).descope=e.descope||{},e.descope.grecaptcha=e.descope.grecaptcha||{},e.descope.grecaptcha.ts=t())}(this,(function(){"use strict";function e(e,t,n,o){return new(n||(n=Promise))((function(r,c){function a(e){try{s(o.next(e))}catch(e){c(e)}}function i(e){try{s(o.throw(e))}catch(e){c(e)}}function s(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,i)}s((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;
2
+ /*! Source: (c) google and other contributors | https://developers.google.com/recaptcha/docs/v3 */
3
+ const t=105e3;return(n,o,r)=>{let c=(new Date).getTime();const a=()=>{var e;return n.enterprise?null===(e=window.grecaptcha)||void 0===e?void 0:e.enterprise:window.grecaptcha};let i,s;const d=(e,o)=>{e.ready((()=>{n.siteKey&&(null==e||e.execute(s,{action:"load"}).then(((n,o)=>{o?console.warn("could not execute recaptcha",o):(r(n),c=(new Date).getTime(),i=setTimeout((()=>{d(e)}),t))})))}))},p=()=>{clearTimeout(i)},u=(()=>{const e=document.createElement("div");return e.style.display="none",e.id="recaptcha",document.body.appendChild(e)})(),l=()=>{const e=a();e&&d(e)};return window.onRecaptchaLoadCallback=()=>{const e=u;if(e.hasChildNodes())return;const t=a();t&&setTimeout((()=>{s=t.render(e,{sitekey:n.siteKey,badge:"inline",size:"invisible"}),d(t)}),0)},(()=>{const e=document.createElement("script");e.src=(()=>{const e=new URL("https://www.google.com/recaptcha/");return e.pathname+=(n.enterprise?"enterprise":"api")+".js",e.searchParams.append("onload","onRecaptchaLoadCallback"),e.searchParams.append("render","explicit"),e.toString()})(),e.async=!0,e.id="recaptcha-script",e.defer=!0,document.body.appendChild(e)})(),{stop:p,start:l,refresh:()=>e(void 0,void 0,void 0,(function*(){if(Date.now()-c>t){p();const e=c;return l(),new Promise((t=>{const n=setTimeout((()=>{console.warn("reCAPTCHA token refresh timed out"),t()}),5e3),o=()=>{c!==e?(clearTimeout(n),t()):setTimeout(o,150)};o()}))}return Promise.resolve()}))}}}));
package/jest.config.js ADDED
@@ -0,0 +1,11 @@
1
+ export default {
2
+ preset: 'ts-jest',
3
+ testEnvironment: 'jsdom',
4
+ testMatch: ['<rootDir>/**/*.spec.ts'],
5
+ testPathIgnorePatterns: ['/node_modules/'],
6
+ coverageDirectory: './coverage',
7
+ coveragePathIgnorePatterns: ['node_modules', 'src/database', 'src/test', 'src/types'],
8
+ reporters: ['default'],
9
+ globals: { 'ts-jest': { diagnostics: false } },
10
+ transform: {},
11
+ };
package/package.json CHANGED
@@ -1,24 +1,36 @@
1
1
  {
2
2
  "name": "@descope/flow-scripts",
3
3
  "type": "module",
4
- "version": "1.0.0",
4
+ "version": "1.0.2",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/descope/content"
8
8
  },
9
9
  "scripts": {
10
10
  "build": "rollup -c",
11
- "build:ci": "rollup -c --environment BUILD:ci"
11
+ "build:ci": "rollup -c --environment BUILD:ci",
12
+ "lint": "eslint --fix --max-warnings 0 .",
13
+ "lint:ci": "eslint --max-warnings 0 .",
14
+ "test": "jest"
12
15
  },
13
16
  "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"
17
+ "@rollup/plugin-commonjs": "28.0.2",
18
+ "@rollup/plugin-node-resolve": "16.0.0",
19
+ "@rollup/plugin-terser": "0.4.4",
20
+ "@rollup/plugin-typescript": "12.1.2",
21
+ "@testing-library/dom": "10.4.0",
22
+ "@testing-library/react": "16.2.0",
23
+ "@types/jest": "29.5.14",
24
+ "eslint": "9.23.0",
25
+ "eslint-plugin-import": "2.31.0",
26
+ "jest": "29.7.0",
27
+ "jest-environment-jsdom": "29.7.0",
28
+ "rollup": "4.34.7",
29
+ "ts-jest": "29.3.0",
30
+ "ts-node": "10.9.2",
31
+ "typescript": "5.7.3"
20
32
  },
21
33
  "dependencies": {
22
- "@fingerprintjs/fingerprintjs-pro": "^3.11.8"
34
+ "@fingerprintjs/fingerprintjs-pro": "3.11.8"
23
35
  }
24
36
  }
package/rollup.config.mjs CHANGED
@@ -4,7 +4,7 @@ import { nodeResolve } from '@rollup/plugin-node-resolve';
4
4
  import commonjs from '@rollup/plugin-commonjs';
5
5
  import fs from 'fs';
6
6
 
7
- const scriptFiles = fs.readdirSync("./src");
7
+ const scriptFiles = fs.readdirSync("./src").filter(f => !f.includes('spec'));
8
8
  export default scriptFiles.map(name => ({
9
9
  input: `src/${name}`,
10
10
  output: {
@@ -15,5 +15,5 @@ export default scriptFiles.map(name => ({
15
15
  inlineDynamicImports: true,
16
16
  },
17
17
  external: [],
18
- plugins: [typescript({ sourceMap: true }), nodeResolve(), commonjs({ ignore: ['worker_threads'] }), terser()]
18
+ plugins: [typescript({ sourceMap: true }), nodeResolve(), commonjs({ ignore: ['worker_threads'] }), terser({ format: { comments: 'some' } })]
19
19
  }));
@@ -1,3 +1,5 @@
1
+ /*! Source: (c) FingerprintJS and other contributors | https://dev.fingerprint.com/ */
2
+
1
3
  import {
2
4
  load,
3
5
  defaultEndpoint,
@@ -1,3 +1,5 @@
1
+ /*! Source: (c) FingerprintJS and other contributors | https://dev.fingerprint.com/ */
2
+
1
3
  import {
2
4
  load,
3
5
  defaultEndpoint,
package/src/forter.ts CHANGED
@@ -1,4 +1,5 @@
1
- // Source: Forter team
1
+ /*! Source: (c) forter and other contributors | https://www.forter.com */
2
+
2
3
  const forterScript = `
3
4
  (function () {
4
5
  var merchantConfig = {
@@ -0,0 +1,74 @@
1
+ import { default as loadGRecaptcha } from './grecaptcha';
2
+
3
+ describe('reCAPTCHA script', () => {
4
+ let onTokenReady;
5
+ let element;
6
+
7
+ beforeEach(() => {
8
+ // Mock DOM elements
9
+ element = document.createElement('div');
10
+ document.body.appendChild(element);
11
+
12
+ // Mock the token ready callback
13
+ onTokenReady = jest.fn();
14
+
15
+ // Mock the grecaptcha object
16
+ global.grecaptcha = {
17
+ enterprise: {
18
+ execute: jest.fn(() => Promise.resolve('mock-token')),
19
+ ready: jest.fn((callback) => callback()),
20
+ render: jest.fn(() => 'render-id'),
21
+ },
22
+ ready: jest.fn((callback) => callback()),
23
+ execute: jest.fn(() => Promise.resolve('mock-token')),
24
+ render: jest.fn(() => 'render-id'),
25
+ };
26
+
27
+ // Mock the window.onRecaptchaLoadCallback
28
+ global.onRecaptchaLoadCallback = null;
29
+
30
+ // Mock Date.now
31
+ jest.spyOn(Date, 'now').mockImplementation(() => 1000);
32
+ });
33
+
34
+ afterEach(() => {
35
+ jest.clearAllMocks();
36
+ document.body.removeChild(element);
37
+ });
38
+
39
+ it('should load reCAPTCHA script and return proper module', () => {
40
+ const initArgs = {
41
+ enterprise: false,
42
+ siteKey: 'test-site-key',
43
+ };
44
+
45
+ const module = loadGRecaptcha(initArgs, {}, onTokenReady);
46
+
47
+ // Check that the module has the expected methods
48
+ expect(module).toHaveProperty('stop');
49
+ expect(module).toHaveProperty('start');
50
+ expect(module).toHaveProperty('refresh');
51
+
52
+ // Verify the methods are functions
53
+ expect(typeof module.stop).toBe('function');
54
+ expect(typeof module.start).toBe('function');
55
+ expect(typeof module.refresh).toBe('function');
56
+ });
57
+
58
+ it('should have a refresh method with timeout safety', () => {
59
+ const initArgs = {
60
+ enterprise: false,
61
+ siteKey: 'test-site-key',
62
+ };
63
+
64
+ // Create module
65
+ const module = loadGRecaptcha(initArgs, {}, onTokenReady);
66
+
67
+ // Verify refresh method exists and returns a promise
68
+ expect(typeof module.refresh).toBe('function');
69
+
70
+ // Verify the refresh method returns a Promise
71
+ const refreshPromise = module.refresh();
72
+ expect(refreshPromise).toBeInstanceOf(Promise);
73
+ });
74
+ });
package/src/grecaptcha.ts CHANGED
@@ -1,3 +1,5 @@
1
+ /*! Source: (c) google and other contributors | https://developers.google.com/recaptcha/docs/v3 */
2
+
1
3
  declare global {
2
4
  interface Window {
3
5
  grecaptcha?: {
@@ -10,7 +12,12 @@ declare global {
10
12
  }
11
13
  }
12
14
 
13
- export const loadGRecaptcha = (
15
+ // Token refresh time: 105 seconds (2 minutes minus 15 seconds)
16
+ // Set to refresh the token shortly before expiration to ensure
17
+ // we always have a valid token when submitting the form
18
+ const TOKEN_REFRESH_TIME_MS = 105000;
19
+
20
+ const loadGRecaptcha = (
14
21
  initArgs: {
15
22
  enterprise: boolean;
16
23
  siteKey: string;
@@ -18,6 +25,8 @@ export const loadGRecaptcha = (
18
25
  _inputs: { baseUrl?: string },
19
26
  onTokenReady: (token: string) => void,
20
27
  ) => {
28
+ let lastTokenFetchTime = new Date().getTime();
29
+
21
30
  const getScriptURL = () => {
22
31
  const url = new URL('https://www.google.com/recaptcha/');
23
32
  url.pathname += `${initArgs.enterprise ? 'enterprise' : 'api'}.js`;
@@ -54,10 +63,11 @@ export const loadGRecaptcha = (
54
63
  console.warn('could not execute recaptcha', e);
55
64
  } else {
56
65
  onTokenReady(token);
66
+ lastTokenFetchTime = new Date().getTime();
57
67
  // if the component is still connected, we should try to get a new token before the token expires (2 minutes)
58
68
  timer = setTimeout(() => {
59
69
  getNewToken(grecaptchaInstance, currentNode);
60
- }, 110000);
70
+ }, TOKEN_REFRESH_TIME_MS);
61
71
  }
62
72
  });
63
73
  });
@@ -84,6 +94,46 @@ export const loadGRecaptcha = (
84
94
  getNewToken(grecaptchaInstance, elementRef);
85
95
  };
86
96
 
97
+ /**
98
+ * Checks if the reCAPTCHA token needs refreshing and refreshes it if necessary
99
+ * This is called before form submission to ensure we have a valid token
100
+ * @returns Promise that resolves when token is refreshed or if refresh isn't needed
101
+ */
102
+ const refreshIfTokenExpired = async (): Promise<void> => {
103
+ const currentTime = Date.now();
104
+ const timeDiff = currentTime - lastTokenFetchTime;
105
+
106
+ if (timeDiff > TOKEN_REFRESH_TIME_MS) {
107
+ stopTimer();
108
+ const prev = lastTokenFetchTime;
109
+ resumeScriptExecution();
110
+
111
+ // Return a promise that resolves once the token is refreshed or times out
112
+ return new Promise<void>((resolve) => {
113
+ // Set a timeout to prevent indefinite waiting
114
+ const timeout = setTimeout(() => {
115
+ // eslint-disable-next-line no-console
116
+ console.warn('reCAPTCHA token refresh timed out');
117
+ resolve(); // Resolve anyway to prevent blocking form submission
118
+ }, 5000); // 5 second timeout for token refresh
119
+
120
+ const checkToken = () => {
121
+ if (lastTokenFetchTime !== prev) {
122
+ clearTimeout(timeout);
123
+ resolve();
124
+ } else {
125
+ setTimeout(checkToken, 150);
126
+ }
127
+ };
128
+
129
+ checkToken();
130
+ });
131
+ }
132
+
133
+ // If no refresh is needed, return a resolved promise
134
+ return Promise.resolve();
135
+ };
136
+
87
137
  const createOnLoadScript = () => {
88
138
  window.onRecaptchaLoadCallback = () => {
89
139
  const currentNode = elementRef;
@@ -113,7 +163,11 @@ export const loadGRecaptcha = (
113
163
  createOnLoadScript();
114
164
  loadRecaptchaScript();
115
165
 
116
- return { stop: stopTimer, start: resumeScriptExecution };
166
+ return {
167
+ stop: stopTimer,
168
+ start: resumeScriptExecution,
169
+ refresh: refreshIfTokenExpired,
170
+ };
117
171
  };
118
172
 
119
- export default loadGRecaptcha;
173
+ export default loadGRecaptcha;
@@ -0,0 +1,230 @@
1
+ /* eslint-disable import/no-namespace */
2
+ import { waitFor } from '@testing-library/dom';
3
+ import * as fp from '@fingerprintjs/fingerprintjs-pro';
4
+
5
+ const urlPattern =
6
+ '?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>';
7
+ const mockFetch = jest.fn();
8
+
9
+ async function loadSdkScript(scriptId: string) {
10
+ let res;
11
+ switch (scriptId) {
12
+ case 'forter':
13
+ res = await import('./forter');
14
+ return res.default;
15
+ case 'fingerprint':
16
+ // eslint-disable-next-line no-case-declarations
17
+ res = await import('./fingerprint');
18
+ return res.default;
19
+ case 'fingerprintDescope':
20
+ // eslint-disable-next-line no-case-declarations
21
+ res = await import('./fingerprintDescope');
22
+ return res.default;
23
+ case 'grecaptcha':
24
+ // eslint-disable-next-line no-case-declarations
25
+ res = await import('./grecaptcha');
26
+ return res.default;
27
+ default:
28
+ throw new Error(`Unknown script id: ${scriptId}`);
29
+ }
30
+ }
31
+
32
+ global.fetch = mockFetch;
33
+
34
+ describe('scripts', () => {
35
+ describe('forter', () => {
36
+ it('should run forter', async () => {
37
+ const forterModule = await loadSdkScript('forter');
38
+ const tokenChangedFn = jest.fn();
39
+
40
+ await forterModule({ siteId: 'some-site-id' }, {}, tokenChangedFn);
41
+
42
+ // get script from document and ensure it has id attribute
43
+ const script = document.querySelector('script');
44
+
45
+ // the script changes the id attribute to the siteId
46
+ expect(script?.getAttribute('id')).toBeTruthy();
47
+ // get textContent and ensure it contains the script id
48
+ // eslint-disable-next-line jest-dom/prefer-to-have-text-content
49
+ expect(script?.textContent).toContain('some-site-id');
50
+
51
+ // trigger 'ftr:tokenReady' event and ensure that the tokenChangedFn is called
52
+ const event = new CustomEvent('ftr:tokenReady', {
53
+ detail: 'some-token',
54
+ });
55
+
56
+ document.dispatchEvent(event);
57
+ await waitFor(() =>
58
+ expect(tokenChangedFn).toHaveBeenCalledWith('some-token'),
59
+ );
60
+ });
61
+ });
62
+
63
+ describe('fingerprint', () => {
64
+ it('should run fingerprint', async () => {
65
+ const requestId = '12345';
66
+ const mockOnTokenReady = jest.fn();
67
+ const getFunc = jest.fn().mockResolvedValue({ requestId });
68
+ const agent = jest.spyOn(fp, 'load');
69
+ agent.mockResolvedValue({ get: getFunc });
70
+
71
+ const fingerprintModule = await loadSdkScript('fingerprint');
72
+ await fingerprintModule(
73
+ {
74
+ publicApiKey: 'testApiKey',
75
+ useCloudflareIntegration: false,
76
+ cloudflareEndpointUrl: '',
77
+ cloudflareScriptUrl: '',
78
+ },
79
+ {},
80
+ mockOnTokenReady,
81
+ );
82
+
83
+ expect(agent).toHaveBeenCalledWith({
84
+ apiKey: 'testApiKey',
85
+ endpoint: [fp.defaultEndpoint],
86
+ scriptUrlPattern: [fp.defaultScriptUrlPattern],
87
+ });
88
+ expect(agent).toHaveBeenCalled();
89
+ expect(getFunc).toHaveBeenCalled();
90
+ expect(mockOnTokenReady).toHaveBeenCalledWith(requestId);
91
+ });
92
+
93
+ it('should run fingerprint with cloudflare integration', async () => {
94
+ const requestId = '12345';
95
+ const mockOnTokenReady = jest.fn();
96
+ const getFunc = jest.fn().mockResolvedValue({ requestId });
97
+ const agent = jest.spyOn(fp, 'load');
98
+ agent.mockResolvedValue({ get: getFunc });
99
+
100
+ const fingerprintModule = await loadSdkScript('fingerprint');
101
+ await fingerprintModule(
102
+ {
103
+ publicApiKey: 'testApiKey',
104
+ useCloudflareIntegration: true,
105
+ cloudflareEndpointUrl: 'https://cloudflare.endpoint',
106
+ cloudflareScriptUrl: 'https://cloudflare.script.url',
107
+ },
108
+ {},
109
+ mockOnTokenReady,
110
+ );
111
+
112
+ expect(agent).toHaveBeenCalledWith({
113
+ apiKey: 'testApiKey',
114
+ endpoint: ['https://cloudflare.endpoint', fp.defaultEndpoint],
115
+ scriptUrlPattern: [
116
+ `https://cloudflare.script.url/${urlPattern}`,
117
+ fp.defaultScriptUrlPattern,
118
+ ],
119
+ });
120
+ expect(agent).toHaveBeenCalled();
121
+ expect(getFunc).toHaveBeenCalled();
122
+ expect(mockOnTokenReady).toHaveBeenCalledWith(requestId);
123
+ });
124
+ });
125
+
126
+ describe('fingerprintDescope', () => {
127
+ it('should run fingerprintDescope', async () => {
128
+ const requestId = '12345';
129
+ const mockOnTokenReady = jest.fn();
130
+ const getFunc = jest.fn().mockResolvedValue({ requestId });
131
+ const agent = jest.spyOn(fp, 'load');
132
+ agent.mockResolvedValue({ get: getFunc });
133
+
134
+ const fingerprintModule = await loadSdkScript('fingerprintDescope');
135
+ await fingerprintModule(
136
+ {
137
+ publicApiKey: 'testApiKey',
138
+ cloudflareEndpointPath: 'cloudflare.endpoint',
139
+ cloudflareScriptPath: 'cloudflare.script.url',
140
+ },
141
+ {},
142
+ mockOnTokenReady,
143
+ );
144
+
145
+ expect(agent).toHaveBeenCalledWith({
146
+ apiKey: 'testApiKey',
147
+ endpoint: [
148
+ 'https://api.descope.com/cloudflare.endpoint',
149
+ fp.defaultEndpoint,
150
+ ],
151
+ scriptUrlPattern: [
152
+ `https://api.descope.com/cloudflare.script.url${urlPattern}`,
153
+ fp.defaultScriptUrlPattern,
154
+ ],
155
+ });
156
+ expect(agent).toHaveBeenCalled();
157
+ expect(getFunc).toHaveBeenCalled();
158
+ expect(mockOnTokenReady).toHaveBeenCalledWith(requestId);
159
+ });
160
+
161
+ it('should run fingerprintDescope with base url', async () => {
162
+ const requestId = '12345';
163
+ const baseUrl = 'https://my.base.url.com';
164
+ const mockOnTokenReady = jest.fn();
165
+ const getFunc = jest.fn().mockResolvedValue({ requestId });
166
+ const agent = jest.spyOn(fp, 'load');
167
+ agent.mockResolvedValue({ get: getFunc });
168
+
169
+ const fingerprintModule = await loadSdkScript('fingerprintDescope');
170
+ await fingerprintModule(
171
+ {
172
+ publicApiKey: 'testApiKey',
173
+ cloudflareEndpointPath: 'cloudflare.endpoint',
174
+ cloudflareScriptPath: 'cloudflare.script.url',
175
+ },
176
+ { baseUrl },
177
+ mockOnTokenReady,
178
+ );
179
+
180
+ expect(agent).toHaveBeenCalledWith({
181
+ apiKey: 'testApiKey',
182
+ endpoint: [`${baseUrl}/cloudflare.endpoint`, fp.defaultEndpoint],
183
+ scriptUrlPattern: [
184
+ `${baseUrl}/cloudflare.script.url${urlPattern}`,
185
+ fp.defaultScriptUrlPattern,
186
+ ],
187
+ });
188
+ expect(agent).toHaveBeenCalled();
189
+ expect(getFunc).toHaveBeenCalled();
190
+ expect(mockOnTokenReady).toHaveBeenCalledWith(requestId);
191
+ });
192
+
193
+ it('should run fingerprintDescope with custom domain', async () => {
194
+ const requestId = '12345';
195
+ const baseUrl = 'https://my.base.url.com';
196
+ const customDomain = 'custom.descope.com';
197
+ const mockOnTokenReady = jest.fn();
198
+ const getFunc = jest.fn().mockResolvedValue({ requestId });
199
+ const agent = jest.spyOn(fp, 'load');
200
+ agent.mockResolvedValue({ get: getFunc });
201
+
202
+ const fingerprintModule = await loadSdkScript('fingerprintDescope');
203
+ await fingerprintModule(
204
+ {
205
+ publicApiKey: 'testApiKey',
206
+ customDomain,
207
+ cloudflareEndpointPath: 'cloudflare.endpoint',
208
+ cloudflareScriptPath: 'cloudflare.script.url',
209
+ },
210
+ { baseUrl },
211
+ mockOnTokenReady,
212
+ );
213
+
214
+ expect(agent).toHaveBeenCalledWith({
215
+ apiKey: 'testApiKey',
216
+ endpoint: [
217
+ `https://${customDomain}/cloudflare.endpoint`,
218
+ fp.defaultEndpoint,
219
+ ],
220
+ scriptUrlPattern: [
221
+ `https://${customDomain}/cloudflare.script.url${urlPattern}`,
222
+ fp.defaultScriptUrlPattern,
223
+ ],
224
+ });
225
+ expect(agent).toHaveBeenCalled();
226
+ expect(getFunc).toHaveBeenCalled();
227
+ expect(mockOnTokenReady).toHaveBeenCalledWith(requestId);
228
+ });
229
+ });
230
+ });
package/tsconfig.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "strict": true,
11
11
  "forceConsistentCasingInFileNames": true,
12
12
  "experimentalDecorators": true,
13
- "removeComments": false,
13
+ "removeComments": true,
14
14
  "noImplicitAny": false,
15
15
  "baseUrl": "src",
16
16
  "outDir": "./dist"