@novashield/client
Version:
Device fingerprinting
3 lines (2 loc) • 14.7 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).NovaShield=e()}(this,(function(){"use strict";function t(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function e(t,e){for(var r=0;r<e.length;r++){var o=e[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,n(o.key),o)}}function r(){r=function(){return e};var t,e={},n=Object.prototype,o=n.hasOwnProperty,i=Object.defineProperty||function(t,e,r){t[e]=r.value},a="function"==typeof Symbol?Symbol:{},u=a.iterator||"@@iterator",c=a.asyncIterator||"@@asyncIterator",f=a.toStringTag||"@@toStringTag";function l(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{l({},"")}catch(t){l=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=e&&e.prototype instanceof E?e:E,a=Object.create(o.prototype),u=new x(n||[]);return i(a,"_invoke",{value:L(t,r,u)}),a}function p(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=s;var h="suspendedStart",v="suspendedYield",d="executing",y="completed",R={};function E(){}function g(){}function m(){}var w={};l(w,u,(function(){return this}));var O=Object.getPrototypeOf,_=O&&O(O(A([])));_&&_!==n&&o.call(_,u)&&(w=_);var b=m.prototype=E.prototype=Object.create(w);function I(t){["next","throw","return"].forEach((function(e){l(t,e,(function(t){return this._invoke(e,t)}))}))}function N(t,e){function r(n,i,a,u){var c=p(t[n],t,i);if("throw"!==c.type){var f=c.arg,l=f.value;return l&&"object"==typeof l&&o.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,a,u)}),(function(t){r("throw",t,a,u)})):e.resolve(l).then((function(t){f.value=t,a(f)}),(function(t){return r("throw",t,a,u)}))}u(c.arg)}var n;i(this,"_invoke",{value:function(t,o){function i(){return new e((function(e,n){r(t,o,e,n)}))}return n=n?n.then(i,i):i()}})}function L(e,r,n){var o=h;return function(i,a){if(o===d)throw Error("Generator is already running");if(o===y){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var u=n.delegate;if(u){var c=T(u,n);if(c){if(c===R)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===h)throw o=y,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=d;var f=p(e,r,n);if("normal"===f.type){if(o=n.done?y:v,f.arg===R)continue;return{value:f.arg,done:n.done}}"throw"===f.type&&(o=y,n.method="throw",n.arg=f.arg)}}}function T(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,T(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),R;var i=p(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,R;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,R):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,R)}function P(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function S(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function x(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function A(e){if(e||""===e){var r=e[u];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function r(){for(;++n<e.length;)if(o.call(e,n))return r.value=e[n],r.done=!1,r;return r.value=t,r.done=!0,r};return i.next=i}}throw new TypeError(typeof e+" is not iterable")}return g.prototype=m,i(b,"constructor",{value:m,configurable:!0}),i(m,"constructor",{value:g,configurable:!0}),g.displayName=l(m,f,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===g||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,m):(t.__proto__=m,l(t,f,"GeneratorFunction")),t.prototype=Object.create(b),t},e.awrap=function(t){return{__await:t}},I(N.prototype),l(N.prototype,c,(function(){return this})),e.AsyncIterator=N,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new N(s(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},I(b),l(b,f,"Generator"),l(b,u,(function(){return this})),l(b,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=A,x.prototype={constructor:x,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(S),!e)for(var r in this)"t"===r.charAt(0)&&o.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(n,o){return u.type="throw",u.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var c=o.call(a,"catchLoc"),f=o.call(a,"finallyLoc");if(c&&f){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!f)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,R):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),R},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),S(r),R}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;S(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:A(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),R}},e}function n(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t,"string");return"symbol"==typeof e?e:e+""}var o=function(){return o=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},o.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var i="Blocked by CSP",a="The endpoint parameter is not a valid URL";function u(t){for(var e="",r=0;r<t.length;++r)if(r>0){var n=t[r].toLowerCase();n!==t[r]?e+=" ".concat(n):e+=t[r]}else e+=t[r].toUpperCase();return e}var c=u("WrongRegion"),f=u("SubscriptionNotActive"),l=u("UnsupportedVersion"),s=u("InstallationMethodRestricted"),p="API key required",h="API key not found",v="API key expired",d="Failed to load the JS script of the agent",y="9319";function R(t,e){var r,n,o,u,c,f=[],l=(r=function(t){var e=function(t,e,r){if(r||2===arguments.length)for(var n,o=0,i=e.length;o<i;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}([],t,!0);return{current:function(){return e[0]},postpone:function(){var t=e.shift();void 0!==t&&e.push(t)},exclude:function(){e.shift()}}}(t),u=0,n=function(){return Math.random()*Math.min(3e3,100*Math.pow(2,u++))},o=new Set,[r.current(),function(t,e){var u,c=e instanceof Error?e.message:"";if(c===i||c===a)r.exclude(),u=0;else if(c===y)r.exclude();else if(c===d){var f=Date.now()-t.getTime()<50,l=r.current();l&&f&&!o.has(l)&&(o.add(l),u=0),r.postpone()}else r.postpone();var s=r.current();return void 0===s?void 0:[s,null!=u?u:t.getTime()+n()-Date.now()]}]),s=l[0],p=l[1];if(void 0===s)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var h=function(t){var r=new Date,n=function(e){return f.push({url:t,startedAt:r,finishedAt:new Date,error:e})},o=e(t);return o.then((function(){return n()}),n),o.catch((function(t){if(null!=c||(c=t),f.length>=5)throw c;var e=p(r,t);if(!e)throw c;var n,o=e[0],i=e[1];return(n=i,new Promise((function(t){return setTimeout(t,n)}))).then((function(){return h(o)}))}))};return h(s).then((function(t){return[t,f]}))}var E="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";function g(t){return function(t,e,r){var n,o=document,i="securitypolicyviolation",a=function(e){var r=new URL(t,location.href),o=e.blockedURI;o!==r.href&&o!==r.protocol.slice(0,-1)&&o!==r.origin||(n=e,u())};o.addEventListener(i,a);var u=function(){return o.removeEventListener(i,a)};return Promise.resolve().then(e).then((function(t){return u(),t}),(function(t){return new Promise((function(t){var e=new MessageChannel;e.port1.onmessage=function(){return t()},e.port2.postMessage(null)})).then((function(){if(u(),n)return r(n);throw t}))}))}(t,(function(){return function(t){return new Promise((function(e,r){if(function(t){if(URL.prototype)try{return new URL(t,location.href),!1}catch(t){if(t instanceof Error&&"TypeError"===t.name)return!0;throw t}}(t))throw new Error(a);var n=document.createElement("script"),o=function(){var t;return null===(t=n.parentNode)||void 0===t?void 0:t.removeChild(n)},i=document.head||document.getElementsByTagName("head")[0];n.onload=function(){o(),e()},n.onerror=function(){o(),r(new Error(d))},n.async=!0,n.src=t,i.appendChild(n)}))}(t)}),(function(){throw new Error(i)})).then(m)}function m(){var t=window,e="__fpjs_p_l_b",r=t[e];if(function(t,e){var r,n=null===(r=Object.getOwnPropertyDescriptor)||void 0===r?void 0:r.call(Object,t,e);(null==n?void 0:n.configurable)?delete t[e]:n&&!n.writable||(t[e]=void 0)}(t,e),"function"!=typeof(null==r?void 0:r.load))throw new Error(y);return r}var w={load:function(t){var e;t.scriptUrlPattern;var r=t.token,n=t.apiKey,i=void 0===n?r:n,a=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(r[n[o]]=t[n[o]])}return r}(t,["scriptUrlPattern","token","apiKey"]),u=null!==(e=function(t,e){return function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(t,e)?t[e]:void 0}(t,"scriptUrlPattern"))&&void 0!==e?e:E,c=function(){var t=[],e=function(){t.push({time:new Date,state:document.visibilityState})},r=function(t,e,r,n){return t.addEventListener(e,r,n),function(){return t.removeEventListener(e,r,n)}}(document,"visibilitychange",e);return e(),[t,r]}(),f=c[0],l=c[1];return Promise.resolve().then((function(){if(!i||"string"!=typeof i)throw new Error(p);return R(function(t,e){return(Array.isArray(t)?t:[t]).map((function(t){return function(t,e){var r=encodeURIComponent;return t.replace(/<[^<>]+>/g,(function(t){return"<version>"===t?"3":"<apiKey>"===t?r(e):"<loaderVersion>"===t?r("3.11.5"):t}))}(String(t),e)}))}(u,i),g)})).catch((function(t){throw l(),function(t){return t instanceof Error&&t.message===y?new Error(d):t}(t)})).then((function(t){var e=t[0],r=t[1];return l(),e.load(o(o({},a),{ldi:{attempts:r,visibilityStates:f}}))}))},defaultScriptUrlPattern:E,ERROR_SCRIPT_LOAD_FAIL:d,ERROR_API_KEY_EXPIRED:v,ERROR_API_KEY_INVALID:h,ERROR_API_KEY_MISSING:p,ERROR_BAD_REQUEST_FORMAT:"Request cannot be parsed",ERROR_BAD_RESPONSE_FORMAT:"Response cannot be parsed",ERROR_CLIENT_TIMEOUT:"Client timeout",ERROR_CSP_BLOCK:i,ERROR_FORBIDDEN_ENDPOINT:u("HostnameRestricted"),ERROR_FORBIDDEN_HEADER:"Not available with restricted header",ERROR_FORBIDDEN_ORIGIN:"Not available for this origin",ERROR_GENERAL_SERVER_FAILURE:"Request failed",ERROR_INSTALLATION_METHOD_RESTRICTED:s,ERROR_INTEGRATION_FAILURE:u("IntegrationFailed"),ERROR_INVALID_ENDPOINT:a,ERROR_NETWORK_ABORT:"Network request aborted",ERROR_NETWORK_CONNECTION:"Network connection error",ERROR_RATE_LIMIT:"Too many requests, rate limit exceeded",ERROR_SERVER_TIMEOUT:"Request failed to process",ERROR_SUBSCRIPTION_NOT_ACTIVE:f,ERROR_TOKEN_EXPIRED:v,ERROR_TOKEN_INVALID:h,ERROR_TOKEN_MISSING:p,ERROR_UNSUPPORTED_VERSION:l,ERROR_WRONG_REGION:c,defaultEndpoint:{default:"endpoint"},defaultTlsEndpoint:{default:"tlsEndpoint"}},O=function(){function n(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,n),this.fingerprintJsOptions={apiKey:null,region:null,endpoint:["https://metrics.novashield.io"]}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}(n,[{key:"lookupDevice",value:(o=r().mark((function t(){var e,n;return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.fingerprintJsOptions.apiKey){t.next=2;break}throw new Error("NovaShield is not initialized. Call init() first.");case 2:return t.next=4,w.load(this.fingerprintJsOptions);case 4:return e=t.sent,t.next=7,e.get();case 7:return n=t.sent,t.abrupt("return",(null==n?void 0:n.requestId)||null);case 9:case"end":return t.stop()}}),t,this)})),i=function(){var e=this,r=arguments;return new Promise((function(n,i){var a=o.apply(e,r);function u(e){t(a,n,i,u,c,"next",e)}function c(e){t(a,n,i,u,c,"throw",e)}u(void 0)}))},function(){return i.apply(this,arguments)})}],[{key:"init",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"us";if(!t)throw new Error("API key is required to initialize NovaShield.");var r=new n;return r.fingerprintJsOptions.apiKey=t,r.fingerprintJsOptions.region=e,r}}]);var o,i}();return O}));
//# sourceMappingURL=novashield.min.js.map