@digitap.ai/sync-sdk 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.
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=function(){return e=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)};var t="Blocked by CSP",r="The endpoint parameter is not a valid URL";function n(e){for(var t="",r=0;r<e.length;++r)if(r>0){var n=e[r].toLowerCase();n!==e[r]?t+=" ".concat(n):t+=e[r]}else t+=e[r].toUpperCase();return t}var o=n("WrongRegion"),i=n("SubscriptionNotActive"),a=n("UnsupportedVersion"),s=n("InstallationMethodRestricted"),c=n("HostnameRestricted"),u=n("IntegrationFailed"),d=n("NetworkRestricted"),l=n("InvalidProxyIntegrationSecret"),f="API key required",R="API key not found",p="API key expired",E="Failed to load the JS script of the agent",I="9319";function g(e,n){var o,i,a,s,c,u=[],d=(o=function(e){var t=function(e,t,r){if(r||2===arguments.length)for(var n,o=0,i=t.length;o<i;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}([],e,!0);return{current:function(){return t[0]},postpone:function(){var e=t.shift();void 0!==e&&t.push(e)},exclude:function(){t.shift()}}}(e),s=0,i=function(){return Math.random()*Math.min(3e3,100*Math.pow(2,s++))},a=new Set,[o.current(),function(e,n){var s,c=n instanceof Error?n.message:"";if(c===t||c===r)o.exclude(),s=0;else if(c===I)o.exclude();else if(c===E){var u=Date.now()-e.getTime()<50,d=o.current();d&&u&&!a.has(d)&&(a.add(d),s=0),o.postpone()}else o.postpone();var l=o.current();return void 0===l?void 0:[l,null!=s?s:e.getTime()+i()-Date.now()]}]),l=d[0],f=d[1];if(void 0===l)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var R=function(e){var t=new Date,r=function(r){return u.push({url:e,startedAt:t,finishedAt:new Date,error:r})},o=n(e);return o.then((function(){return r()}),r),o.catch((function(e){if(null!=c||(c=e),u.length>=5)throw c;var r=f(t,e);if(!r)throw c;var n,o=r[0],i=r[1];return(n=i,new Promise((function(e){return setTimeout(e,n)}))).then((function(){return R(o)}))}))};return R(l).then((function(e){return[e,u]}))}var v="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";function y(e){return function(e,t,r,n){var o,i=document,a="securitypolicyviolation",s=function(t){var r=new URL(e,location.href),n=t.blockedURI;n!==r.href&&n!==r.protocol.slice(0,-1)&&n!==r.origin||(o=t,c())};i.addEventListener(a,s);var c=function(){return i.removeEventListener(a,s)};return null==n||n.then(c,c),Promise.resolve().then(t).then((function(e){return c(),e}),(function(e){return new Promise((function(e){var t=new MessageChannel;t.port1.onmessage=function(){return e()},t.port2.postMessage(null)})).then((function(){if(c(),o)return r(o);throw e}))}))}(e,(function(){return function(e){return new Promise((function(t,n){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(r);var o=document.createElement("script"),i=function(){var e;return null===(e=o.parentNode)||void 0===e?void 0:e.removeChild(o)},a=document.head||document.getElementsByTagName("head")[0];o.onload=function(){i(),t()},o.onerror=function(){i(),n(new Error(E))},o.async=!0,o.src=e,a.appendChild(o)}))}(e)}),(function(){throw new Error(t)})).then(m)}function m(){var e=window,t="__fpjs_p_l_b",r=e[t];if(function(e,t){var r,n=null===(r=Object.getOwnPropertyDescriptor)||void 0===r?void 0:r.call(Object,e,t);(null==n?void 0:n.configurable)?delete e[t]:n&&!n.writable||(e[t]=void 0)}(e,t),"function"!=typeof(null==r?void 0:r.load))throw new Error(I);return r}var h={load:function(t){var r;t.scriptUrlPattern;var n=t.token,o=t.apiKey,i=void 0===o?n:o,a=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r}(t,["scriptUrlPattern","token","apiKey"]),s=null!==(r=function(e,t){return function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t)?e[t]:void 0}(t,"scriptUrlPattern"))&&void 0!==r?r:v,c=function(){var e=[],t=function(){e.push({time:new Date,state:document.visibilityState})},r=function(e,t,r,n){return e.addEventListener(t,r,n),function(){return e.removeEventListener(t,r,n)}}(document,"visibilitychange",t);return t(),[e,r]}(),u=c[0],d=c[1];return Promise.resolve().then((function(){if(!i||"string"!=typeof i)throw new Error(f);return g(function(e,t){return(Array.isArray(e)?e:[e]).map((function(e){return function(e,t){var r=encodeURIComponent;return e.replace(/<[^<>]+>/g,(function(e){return"<version>"===e?"3":"<apiKey>"===e?r(t):"<loaderVersion>"===e?r("3.11.8"):e}))}(String(e),t)}))}(s,i),y)})).catch((function(e){throw d(),function(e){return e instanceof Error&&e.message===I?new Error(E):e}(e)})).then((function(t){var r=t[0],n=t[1];return d(),r.load(e(e({},a),{ldi:{attempts:n,visibilityStates:u}}))}))},defaultScriptUrlPattern:v,ERROR_SCRIPT_LOAD_FAIL:E,ERROR_API_KEY_EXPIRED:p,ERROR_API_KEY_INVALID:R,ERROR_API_KEY_MISSING:f,ERROR_BAD_REQUEST_FORMAT:"Request cannot be parsed",ERROR_BAD_RESPONSE_FORMAT:"Response cannot be parsed",ERROR_CLIENT_TIMEOUT:"Client timeout",ERROR_CSP_BLOCK:t,ERROR_FORBIDDEN_ENDPOINT:c,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,ERROR_INVALID_ENDPOINT:r,ERROR_INVALID_PROXY_INTEGRATION_HEADERS:n("InvalidProxyIntegrationHeaders"),ERROR_INVALID_PROXY_INTEGRATION_SECRET:l,ERROR_NETWORK_ABORT:"Network request aborted",ERROR_NETWORK_CONNECTION:"Network connection error",ERROR_NETWORK_RESTRICTED:d,ERROR_RATE_LIMIT:"Too many requests, rate limit exceeded",ERROR_SERVER_TIMEOUT:"Request failed to process",ERROR_SUBSCRIPTION_NOT_ACTIVE:i,ERROR_TOKEN_EXPIRED:p,ERROR_TOKEN_INVALID:R,ERROR_TOKEN_MISSING:f,ERROR_UNSUPPORTED_VERSION:a,ERROR_WRONG_REGION:o,defaultEndpoint:{default:"endpoint"},defaultTlsEndpoint:{default:"tlsEndpoint"}};async function _(e,t){try{const r=e.replace(/-/g,"+").replace(/_/g,"/"),n=function(e){const t=atob(e);return Uint8Array.from(t,(e=>e.charCodeAt(0)))}(r+"=".repeat((4-r.length%4)%4)),o=n.slice(0,12),i=n.slice(12),a=(new TextEncoder).encode(t),s=await crypto.subtle.importKey("raw",a,{name:"AES-GCM"},!1,["decrypt"]),c=await crypto.subtle.decrypt({name:"AES-GCM",iv:o,tagLength:128},s,i);return(new TextDecoder).decode(c)}catch(e){return console.error("Decryption error:",e),null}}let O=!1;const w={dev:"https://api.digitap.work/sync/",stage:"https://apistage.digitap.work/sync/",uat:"https://apidemo.digitap.work/sync/",prod:"https://api.digitap.ai/sync/"},T={code:1001,message:"Invalid Input"},N={code:1002,message:"Internal Error, Try after some time"},A={code:1003,message:"Server Error, Try after some time"},S={code:1004,message:"Internet not connected"},P={code:1005,message:"Previous sms sync is in progress, please try after some time"},b={code:1006,message:"Sync disabled"};async function D(){return localStorage.getItem("userId")}var L={start:async function(e,t,r,n){var o="",i="";try{if(!function(e){const t=String(e).trim();if(!t)return!1;if(!/^\d+$/.test(t))return!1;try{if(e.length<18)return!0;{const e=BigInt(t),r=BigInt("-9223372036854775808"),n=BigInt("9223372036854775807");return e>=r&&e<=n}}catch{return!1}}(r))return n({status:"error",code:T.code,message:"Invalid userId",data:{userId:r||null,deviceId:null}});if(({deviceId:o,userAgent:i}=await async function(){let e=localStorage.getItem("sync_device_id"),t=localStorage.getItem("sync_user_agent");if(!e){const r=await h.load({apiKey:"w5EseVLxhpfRzzsVj0fl",region:"ap"}),n=await r.get();e=n?.visitorId,t=n?.components?.userAgent?.value||navigator?.userAgent,localStorage.setItem("sync_device_id",e),localStorage.setItem("sync_user_agent",t)}return{deviceId:e,userAgent:t}}()),O)return n({status:"failure",code:P.code,message:"Previous sms sync is initiated for the user_id "+D()+", please try after some time",data:{userId:r,deviceId:o}});if(!navigator.onLine)return n({status:"error",code:S.code,message:S.message,data:{userId:r,deviceId:o}});O=!0,async function(e){localStorage.setItem("userId",e)}(r);const s=await async function(){const e=await fetch("https://api.ipify.org?format=json");if(!e.ok)throw new Error("Failed to fetch IP address");return(await e.json()).ip}(),{latitude:c,longitude:u}=await async function(){return new Promise((e=>{if(!navigator.geolocation)return e({latitude:0,longitude:0});navigator.geolocation.getCurrentPosition((t=>{e({latitude:t.coords.latitude,longitude:t.coords.longitude})}),(()=>{e({latitude:0,longitude:0})}),{timeout:1e4})}))}(),d={customAuthenticationToken:e,sdkVersion:"1.0.0",userId:r,ipAddress:s,location:{latitude:c,longitude:u},deviceId:o,deviceType:"WEB",userAgent:i},l=await async function(e,t){const r=await fetch(w[t]+"sdk/auth",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!r.ok)throw new Error("Failed to send data to API");return await r.json()}(d,t);if(200==l.code)if(l.model?.isSyncEnabled){var a="";try{console.log("data:"+l.model?.data),a=await _(l.model?.data,"PpwCKmkiEE8Q0O0FmbpZ90ZbdNypVhkp")}catch(e){return void n({status:"failure",code:N.code,message:"Internal error, "+(e.message||"Unexpected error"),data:{userId:r,deviceId:o}})}if(console.log("Decrypted:",a),null!=a&&""!=a){const e=JSON.parse(a);n({status:"success",code:200,message:"Sync Completed",data:{syncId:e?.syncConfig?.syncId||null,userId:r,deviceId:o}})}else n({status:"failure",code:N.code,message:N.message,data:{userId:r,deviceId:o}})}else n({status:"failure",code:b.code,message:b.message,data:{syncId:l.syncId||null,userId:r,deviceId:o}});else n({status:"failure",code:A.code,message:"Server error, "+l.msg,data:{syncId:l.syncId||null,userId:r,deviceId:o}})}catch(e){n({status:"failure",code:N.code,message:"Internal error, "+(e.message||"Unexpected error"),data:{userId:r,deviceId:o}})}finally{O=!1}}};export{L as default};
|
|
1
|
+
function e(e){return e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}function t(){const e=window,t="__fpjs_p_l_b",n=e[t];if(function(e,t){var n;const r=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,e,t);(null==r?void 0:r.configurable)?delete e[t]:r&&!r.writable||(e[t]=void 0)}(e,t),"function"!=typeof(null==n?void 0:n.load))throw new Error(c);return n}function n(e,t){return(e-t+256)%256}const r="Blocked by CSP",o="The endpoint parameter is not a valid URL",i="Handle on demand agent data error";var a="3.12.16";const s="Failed to load the JS script of the agent",c="9319";function u(e,t){oe(e,e.len+t.length),e.arr.set(t,e.len),e.len+=t.length}const d="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",l=d;function f(e,t){try{document.cookie}catch(e){if(function(e){if(!(e instanceof DOMException))return!1;const t=e.message;return Z.test(t)||ee.test(t)||te.test(t)}(e))return t;throw e}return e()}function R(e){const t=new Uint8Array(e.length);for(let n=0;n<e.length;n++){const r=e.charCodeAt(n);if(r>127)return(new TextEncoder).encode(e);t[n]=r}return t}function g(e,t,...n){e&&async function(e){try{return await e()}catch(e){return void console.error(e)}}(()=>{const r=t(...n);void 0!==r&&e(r)})}function E({level:e,message:t}){"error"===e?console.error(t):"warning"===e?console.warn(t):console.log(t)}const h="_vid";function p(e){const t=location.hostname,n=function(){var e,t;const n=window;return["buildID"in navigator,"MozAppearance"in(null!==(t=null===(e=document.documentElement)||void 0===e?void 0:e.style)&&void 0!==t?t:{}),"onmozfullscreenchange"in n,"mozInnerScreenX"in n,"CSSMozDocumentRule"in n,"CanvasCaptureMediaStream"in n].reduce((e,t)=>e+(t?1:0),0)>=4}();(function(e,t){let n=e.length-("."===e.slice(-1)?1:0);do{if(n=n>0?e.lastIndexOf(".",n-1):-1,!0===t(e.slice(n+1)))return!0}while(n>=0);return!1})(t,r=>{if(!n||!/^([^.]{1,3}\.)*[^.]+\.?$/.test(r)||r===t)return e(r)})||e()}function I(e,t){const n=[],[i,a]=function(e){const t=function(e){const t=[...e];return{current:()=>t[0],postpone(){const e=t.shift();void 0!==e&&t.push(e)},exclude(){t.shift()}}}(e),n=function(){let e=0;return()=>Math.random()*Math.min(3e3,100*Math.pow(2,e++))}(),i=new Set;return[t.current(),(e,a)=>{let u;const d=a instanceof Error?a.message:"";if(d===r||d===o)t.exclude(),u=0;else if(d===c)t.exclude();else if(d===s){const n=Date.now()-e.getTime()<50,r=t.current();r&&n&&!i.has(r)&&(i.add(r),u=0),t.postpone()}else t.postpone();const l=t.current();return void 0===l?void 0:[l,null!=u?u:e.getTime()+n()-Date.now()]}]}(e);let u;if(void 0===i)return Promise.reject(new TypeError("The list of script URL patterns is empty"));const d=e=>{const r=new Date,o=t=>n.push({url:e,startedAt:r,finishedAt:new Date,error:t}),i=t(e);return i.then(()=>o(),o),i.catch(e=>{if(null!=u||(u=e),n.length>=5)throw u;const t=a(r,e);if(!t)throw u;const[o,i]=t;return(s=i,new Promise(e=>setTimeout(e,s))).then(()=>d(o));var s})};return d(i).then(e=>[e,n])}function m(e){return e>=S&&e<S+10||e===U}const y=34,v=44,w=58,_=32,O=9,A=13,T=10,N=92,S=48,b=101,P=117,D=69,C=43,U=45,L=46,k=91,x=93,M=123,K=125,V=new Uint8Array([110,P,108,108]),B=new Uint8Array([116,114,P,b]),j=new Uint8Array([102,97,108,115,b]),F={'"':'"',"\\":"\\","\b":"b","\f":"f","\n":"n","\r":"r","\t":"t"},G=(()=>{const e=new Uint8Array(128);for(const[t,n]of Object.entries(F))e[n.charCodeAt(0)]=t.charCodeAt(0);return e})(),$=re("WrongRegion"),H=re("SubscriptionNotActive"),q=re("UnsupportedVersion"),z=re("InstallationMethodRestricted"),W=re("HostnameRestricted"),X=re("IntegrationFailed"),Y=re("NetworkRestricted"),J=re("InvalidProxyIntegrationSecret");function Q(e,t,n,r){f(()=>{const o=`${e}=${t}`,i=`expires=${new Date(Date.now()+24*n*60*60*1e3).toUTCString()}`,a=r?`domain=${r}`:"";document.cookie=[o,"path=/",i,a,"SameSite=Lax"].join("; ")},void 0)}const Z=/The document is sandboxed and lacks the 'allow-same-origin' flag/,ee=/The operation is insecure/,te=/Forbidden in a sandboxed document without the 'allow-same-origin' flag/;function ne(e,t){oe(e,e.len+1),e.arr[e.len++]=t}function re(e){let t="";for(let n=0;n<e.length;++n)if(n>0){const r=e[n].toLowerCase();r!==e[n]?t+=` ${r}`:t+=e[n]}else t+=e[n].toUpperCase();return t}function oe(e,t){if(e.arr.length<t){const n=new Uint8Array(Math.max(2*e.arr.length,t));n.set(e.arr),e.arr=n}}const ie=[3,13];function ae(t){if("function"==typeof TextDecoder){const e=(new TextDecoder).decode(t);if(e)return e}const n=e(t);return decodeURIComponent(escape(String.fromCharCode.apply(null,n)))}function se(e){return function(e,t,n,r){const o=document,i="securitypolicyviolation";let a;const s=t=>{const n=new URL(e,location.href),{blockedURI:r}=t;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(a=t,c())};o.addEventListener(i,s);const c=()=>o.removeEventListener(i,s);return null==r||r.then(c,c),Promise.resolve().then(t).then(e=>(c(),e),e=>new Promise(e=>{const t=new MessageChannel;t.port1.onmessage=()=>e(),t.port2.postMessage(null)}).then(()=>{if(c(),a)return n(a);throw e}))}(e,()=>function(e){return new Promise((t,n)=>{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(o);const r=document.createElement("script"),i=()=>{var e;return null===(e=r.parentNode)||void 0===e?void 0:e.removeChild(r)},a=document.head||document.getElementsByTagName("head")[0];r.onload=()=>{i(),t()},r.onerror=()=>{i(),n(new Error(s))},r.async=!0,r.src=e,a.appendChild(r)})}(e),()=>{throw new Error(r)}).then(t)}const ce="API key required",ue="API key not found",de="API key expired";var le={load:function(e){var t,n;const{picked:r,rest:o}=function(e,t){const n={},r={};for(const[o,i]of Object.entries(e))t.includes(o)?n[o]=i:r[o]=i;return{picked:n,rest:r}}(e,["scriptUrlPattern","token","apiKey"]),i=r.token,u=null!==(t=r.apiKey)&&void 0!==t?t:i,l=null!==(n=function(e,t){return function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t)?e[t]:void 0}(e,"scriptUrlPattern"))&&void 0!==n?n:d,[f,R]=function(){const e=[],t=()=>{e.push({time:new Date,state:document.visibilityState})},n=(r=document,o="visibilitychange",i=t,r.addEventListener(o,i,a),()=>r.removeEventListener(o,i,a));var r,o,i,a;return t(),[e,n]}();return Promise.resolve().then(()=>{if(!u||"string"!=typeof u)throw new Error("API key required");return I(function(e,t){return(Array.isArray(e)?e:[e]).map(e=>function(e,t){const n=encodeURIComponent;return e.replace(/<[^<>]+>/g,e=>"<version>"===e?"3":"<apiKey>"===e?n(t):"<loaderVersion>"===e?n(a):e)}(String(e),t))}(l,u),se)}).catch(e=>{throw R(),function(e){return e instanceof Error&&e.message===c?new Error(s):e}(e)}).then(([e,t])=>(R(),e.load({...o,ldi:{attempts:t,visibilityStates:f}})))},defaultScriptUrlPattern:l,ERROR_SCRIPT_LOAD_FAIL:s,ERROR_API_KEY_EXPIRED:de,ERROR_API_KEY_INVALID:ue,ERROR_API_KEY_MISSING:ce,ERROR_BAD_REQUEST_FORMAT:"Request cannot be parsed",ERROR_BAD_RESPONSE_FORMAT:"Response cannot be parsed",ERROR_CLIENT_TIMEOUT:"Client timeout",ERROR_CSP_BLOCK:r,ERROR_FORBIDDEN_ENDPOINT:W,ERROR_FORBIDDEN_HEADER:"Not available with restricted header",ERROR_FORBIDDEN_ORIGIN:"Not available for this origin",ERROR_GENERAL_SERVER_FAILURE:"Request failed",ERROR_HANDLE_AGENT_DATA:i,ERROR_INSTALLATION_METHOD_RESTRICTED:z,ERROR_INTEGRATION_FAILURE:X,ERROR_INVALID_ENDPOINT:o,ERROR_INVALID_PROXY_INTEGRATION_HEADERS:re("InvalidProxyIntegrationHeaders"),ERROR_INVALID_PROXY_INTEGRATION_SECRET:J,ERROR_NETWORK_ABORT:"Network request aborted",ERROR_NETWORK_CONNECTION:"Network connection error",ERROR_NETWORK_RESTRICTED:Y,ERROR_PROXY_INTEGRATION_SECRET_ENVIRONMENT_MISMATCH:re("ProxyIntegrationSecretEnvironmentMismatch"),ERROR_RATE_LIMIT:"Too many requests, rate limit exceeded",ERROR_SERVER_TIMEOUT:"Request failed to process",ERROR_SUBSCRIPTION_NOT_ACTIVE:H,ERROR_TOKEN_EXPIRED:de,ERROR_TOKEN_INVALID:ue,ERROR_TOKEN_MISSING:ce,ERROR_UNSUPPORTED_VERSION:q,ERROR_WRONG_REGION:$,defaultEndpoint:{default:"endpoint"},defaultTlsEndpoint:{default:"tlsEndpoint"},handleAgentData:function(t,r={}){const{storageKey:o=h,do:a}=r;try{const r=function(t){const r=function(e){const t=atob(e),n=t.length,r=new Uint8Array(n);for(let e=0;e<n;e++)r[e]=t.charCodeAt(e);return r}(t);let o=r;try{o=function(t,r){const o=()=>{throw new Error("Invalid data")},i=e(t);i.length<r.length+2&&o();for(let e=0;e<r.length;++e)n(i[1+e],i[0])!==r[e]&&o();const a=1+r.length,s=n(i[a],i[0]);i.length<a+1+s+9&&o();const c=a+1+s,u=c+9,d=new ArrayBuffer(i.length-u),l=new Uint8Array(d);for(let e=0;e<l.length;++e)l[e]=i[u+e]^i[c+e%9];return d}(r,ie)}catch(e){}try{return function(t){const n={len:0,arr:new Uint8Array(128)},r=e(t);let o=0;const i=()=>(l(),r[o]===y?a():m(r[o])?s():f(V)?(o+=V.length,null):f(B)?(o+=B.length,!0):f(j)?(o+=j.length,!1):r[o]===k?c():r[o]===M?d():g()),a=()=>{for(n.len=0;o++,r[o]!==y;){if(r[o]===N){if(o++,r[o]===P){const e=parseInt(ae(r.subarray(o+1,o+5)),16);u(n,R(String.fromCharCode(e))),o+=4;continue}const e=G[r[o]];if(e){ne(n,e);continue}return g()}if(void 0===r[o])return g();ne(n,r[o])}return o++,ae(function(e){return e.arr.subarray(0,e.len)}(n))},s=()=>{const e=o;for(;r[o]===L||r[o]===b||r[o]===D||r[o]===C||m(r[o]);)o++;return Number(ae(r.subarray(e,o)))},c=()=>{const e=[];for(o++;;){if(l(),r[o]===x){o++;break}if(e.length){if(r[o]!==v)return g();o++}e.push(i())}return e},d=()=>{const e={};let t=!0;for(o++;;){if(l(),r[o]===K){o++;break}if(!t){if(r[o]!==v)return g();o++,l()}if(r[o]!==y)return g();const n=a();if(l(),r[o]!==w)return g();o++,Object.defineProperty(e,n,{value:i(),configurable:!0,enumerable:!0,writable:!0}),t=!1}return e},l=()=>{for(;r[o]===_||r[o]===T||r[o]===A||r[o]===O;)o++},f=e=>{for(let t=0;t<e.length;t++)if(r[o+t]!==e[t])return!1;return!0},g=()=>{throw new SyntaxError("Unexpected "+(o<r.length?`byte ${o}`:"end"))},E=i();return l(),void 0!==r[o]&&g(),E}(o)}catch(e){}return null}(t);null!==r?(r.visitorToken&&function(e,t){(function(e,t){p(t=>{!function(e,t){Q(e,"",-1,t)}(e,t)}),p(n=>(Q(e,t,365,n),function(e){return f(()=>{const t=`${e}=`;for(const e of document.cookie.split(";")){let n=0;for(;" "===e[n]&&n<e.length;)++n;if(e.indexOf(t)===n)return e.slice(n+t.length)}},void 0)}(e)===t))})(t,e),function(e,t){var n;try{null===(n=null===localStorage||void 0===localStorage?void 0:localStorage.setItem)||void 0===n||n.call(localStorage,e,t)}catch(e){}}(t,e)}(r.visitorToken,`${o}_t`),null==(s=r.notifications)||s.forEach(E),g(a,()=>({e:25,result:{response:r}}))):g(a,()=>({e:25,result:{error:new Error("Failed to decode response")}}))}catch(e){throw g(a,()=>({e:25,result:{error:e instanceof Error?e:new Error(String(e))}})),function(e,t,n){const r=new Error(i);return void 0!==n&&(r.raw=n),r}(0,0,e)}var s}};async function fe(e,t){try{const n=e.replace(/-/g,"+").replace(/_/g,"/"),r=function(e){const t=atob(e);return Uint8Array.from(t,e=>e.charCodeAt(0))}(n+"=".repeat((4-n.length%4)%4)),o=r.slice(0,12),i=r.slice(12),a=(new TextEncoder).encode(t),s=await crypto.subtle.importKey("raw",a,{name:"AES-GCM"},!1,["decrypt"]),c=await crypto.subtle.decrypt({name:"AES-GCM",iv:o,tagLength:128},s,i);return(new TextDecoder).decode(c)}catch(e){return console.error("Decryption error:",e),null}}let Re=!1;const ge={code:1001,message:"Invalid Input"},Ee={code:1002,message:"Internal Error, Try after some time"},he={code:1003,message:"Server Error, Try after some time"},pe={code:1004,message:"Internet not connected"},Ie={code:1005,message:"Previous sms sync is in progress, please try after some time"},me={code:1006,message:"Sync disabled"},ye=e=>""===e||null===e||"null"===e||void 0===e||"undefined"===e;function ve(e,t){let n=t;ye(t)||(n=btoa(t)),sessionStorage.setItem(e,n)}function we(e){let t=sessionStorage.getItem(e);if(!ye(t))try{return atob(t)}catch(e){console.error(e)}return t}async function _e(){return we("userId")}var Oe={start:async function(e,t,n,r,o){var i="",a="";try{if(!function(e){const t=String(e).trim();if(!t)return!1;if(!/^\d+$/.test(t))return!1;try{if(e.length<18)return!0;{const e=BigInt(t),n=BigInt("-9223372036854775808"),r=BigInt("9223372036854775807");return e>=n&&e<=r}}catch{return!1}}(r))return o({status:"error",code:ge.code,message:"Invalid userId",data:{userId:r||null,deviceId:null}});if(({deviceId:i,userAgent:a}=await async function(){let e=we("sync_device_id"),t=we("sync_user_agent");if(!e){const n=await le.load({apiKey:"w5EseVLxhpfRzzsVj0fl",region:"ap"}),r=await n.get();e=r?.visitorId,t=r?.components?.userAgent?.value||navigator?.userAgent,ve("sync_device_id",e),ve("sync_user_agent",t)}return{deviceId:e,userAgent:t}}()),Re)return o({status:"failure",code:Ie.code,message:"Previous sms sync is initiated for the user_id "+_e()+", please try after some time",data:{userId:r,deviceId:i}});if(!navigator.onLine)return o({status:"error",code:pe.code,message:pe.message,data:{userId:r,deviceId:i}});Re=!0,async function(e){ve("userId",e)}(r);const t=await async function(){const e=await fetch("https://api.ipify.org?format=json");if(!e.ok)throw new Error("Failed to fetch IP address");return(await e.json()).ip}(),{latitude:c,longitude:u}=await async function(){return new Promise(e=>{if(!navigator.geolocation)return e({latitude:0,longitude:0});navigator.geolocation.getCurrentPosition(t=>{e({latitude:t.coords.latitude,longitude:t.coords.longitude})},()=>{e({latitude:0,longitude:0})},{timeout:1e4})})}(),d={customAuthenticationToken:e,sdkVersion:"1.0.1",userId:r,ipAddress:t,location:{latitude:c,longitude:u},deviceId:i,deviceType:"WEB",userAgent:a},l=await async function(e,t,n){const r=await fetch(n+"/sync/sdk/auth",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!r.ok)throw new Error("Failed to send data to API");return await r.json()}(d,0,n);if(200==l.code)if(l.model?.isSyncEnabled){var s="";try{console.log("data:"+l.model?.data),s=await fe(l.model?.data,"PpwCKmkiEE8Q0O0FmbpZ90ZbdNypVhkp")}catch(e){return void o({status:"failure",code:Ee.code,message:"Internal error, "+(e.message||"Unexpected error"),data:{userId:r,deviceId:i}})}if(console.log("Decrypted:",s),null!=s&&""!=s){const e=JSON.parse(s);o({status:"success",code:200,message:"Sync Completed",data:{syncId:e?.syncConfig?.syncId||null,userId:r,deviceId:i}})}else o({status:"failure",code:Ee.code,message:Ee.message,data:{userId:r,deviceId:i}})}else o({status:"failure",code:me.code,message:me.message,data:{syncId:l.syncId||null,userId:r,deviceId:i}});else o({status:"failure",code:he.code,message:"Server error, "+l.msg,data:{syncId:l.syncId||null,userId:r,deviceId:i}})}catch(e){o({status:"failure",code:Ee.code,message:"Internal error, "+(e.message||"Unexpected error"),data:{userId:r,deviceId:i}})}finally{Re=!1}}};export{Oe as default,ye as isNullOrEmpty};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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).Sync=t()}(this,(function(){"use strict";var e=function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)};var t="Blocked by CSP",n="The endpoint parameter is not a valid URL";function r(e){for(var t="",n=0;n<e.length;++n)if(n>0){var r=e[n].toLowerCase();r!==e[n]?t+=" ".concat(r):t+=e[n]}else t+=e[n].toUpperCase();return t}var o=r("WrongRegion"),i=r("SubscriptionNotActive"),a=r("UnsupportedVersion"),s=r("InstallationMethodRestricted"),c=r("HostnameRestricted"),u=r("IntegrationFailed"),d=r("NetworkRestricted"),l=r("InvalidProxyIntegrationSecret"),f="API key required",p="API key not found",R="API key expired",I="Failed to load the JS script of the agent",E="9319";function v(e,r){var o,i,a,s,c,u=[],d=(o=function(e){var t=function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([],e,!0);return{current:function(){return t[0]},postpone:function(){var e=t.shift();void 0!==e&&t.push(e)},exclude:function(){t.shift()}}}(e),s=0,i=function(){return Math.random()*Math.min(3e3,100*Math.pow(2,s++))},a=new Set,[o.current(),function(e,r){var s,c=r instanceof Error?r.message:"";if(c===t||c===n)o.exclude(),s=0;else if(c===E)o.exclude();else if(c===I){var u=Date.now()-e.getTime()<50,d=o.current();d&&u&&!a.has(d)&&(a.add(d),s=0),o.postpone()}else o.postpone();var l=o.current();return void 0===l?void 0:[l,null!=s?s:e.getTime()+i()-Date.now()]}]),l=d[0],f=d[1];if(void 0===l)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var p=function(e){var t=new Date,n=function(n){return u.push({url:e,startedAt:t,finishedAt:new Date,error:n})},o=r(e);return o.then((function(){return n()}),n),o.catch((function(e){if(null!=c||(c=e),u.length>=5)throw c;var n=f(t,e);if(!n)throw c;var r,o=n[0],i=n[1];return(r=i,new Promise((function(e){return setTimeout(e,r)}))).then((function(){return p(o)}))}))};return p(l).then((function(e){return[e,u]}))}var y="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";function g(e){return function(e,t,n,r){var o,i=document,a="securitypolicyviolation",s=function(t){var n=new URL(e,location.href),r=t.blockedURI;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(o=t,c())};i.addEventListener(a,s);var c=function(){return i.removeEventListener(a,s)};return null==r||r.then(c,c),Promise.resolve().then(t).then((function(e){return c(),e}),(function(e){return new Promise((function(e){var t=new MessageChannel;t.port1.onmessage=function(){return e()},t.port2.postMessage(null)})).then((function(){if(c(),o)return n(o);throw e}))}))}(e,(function(){return function(e){return new Promise((function(t,r){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(n);var o=document.createElement("script"),i=function(){var e;return null===(e=o.parentNode)||void 0===e?void 0:e.removeChild(o)},a=document.head||document.getElementsByTagName("head")[0];o.onload=function(){i(),t()},o.onerror=function(){i(),r(new Error(I))},o.async=!0,o.src=e,a.appendChild(o)}))}(e)}),(function(){throw new Error(t)})).then(h)}function h(){var e=window,t="__fpjs_p_l_b",n=e[t];if(function(e,t){var n,r=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,e,t);(null==r?void 0:r.configurable)?delete e[t]:r&&!r.writable||(e[t]=void 0)}(e,t),"function"!=typeof(null==n?void 0:n.load))throw new Error(E);return n}var m={load:function(t){var n;t.scriptUrlPattern;var r=t.token,o=t.apiKey,i=void 0===o?r:o,a=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}(t,["scriptUrlPattern","token","apiKey"]),s=null!==(n=function(e,t){return function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t)?e[t]:void 0}(t,"scriptUrlPattern"))&&void 0!==n?n:y,c=function(){var e=[],t=function(){e.push({time:new Date,state:document.visibilityState})},n=function(e,t,n,r){return e.addEventListener(t,n,r),function(){return e.removeEventListener(t,n,r)}}(document,"visibilitychange",t);return t(),[e,n]}(),u=c[0],d=c[1];return Promise.resolve().then((function(){if(!i||"string"!=typeof i)throw new Error(f);return v(function(e,t){return(Array.isArray(e)?e:[e]).map((function(e){return function(e,t){var n=encodeURIComponent;return e.replace(/<[^<>]+>/g,(function(e){return"<version>"===e?"3":"<apiKey>"===e?n(t):"<loaderVersion>"===e?n("3.11.8"):e}))}(String(e),t)}))}(s,i),g)})).catch((function(e){throw d(),function(e){return e instanceof Error&&e.message===E?new Error(I):e}(e)})).then((function(t){var n=t[0],r=t[1];return d(),n.load(e(e({},a),{ldi:{attempts:r,visibilityStates:u}}))}))},defaultScriptUrlPattern:y,ERROR_SCRIPT_LOAD_FAIL:I,ERROR_API_KEY_EXPIRED:R,ERROR_API_KEY_INVALID:p,ERROR_API_KEY_MISSING:f,ERROR_BAD_REQUEST_FORMAT:"Request cannot be parsed",ERROR_BAD_RESPONSE_FORMAT:"Response cannot be parsed",ERROR_CLIENT_TIMEOUT:"Client timeout",ERROR_CSP_BLOCK:t,ERROR_FORBIDDEN_ENDPOINT:c,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,ERROR_INVALID_ENDPOINT:n,ERROR_INVALID_PROXY_INTEGRATION_HEADERS:r("InvalidProxyIntegrationHeaders"),ERROR_INVALID_PROXY_INTEGRATION_SECRET:l,ERROR_NETWORK_ABORT:"Network request aborted",ERROR_NETWORK_CONNECTION:"Network connection error",ERROR_NETWORK_RESTRICTED:d,ERROR_RATE_LIMIT:"Too many requests, rate limit exceeded",ERROR_SERVER_TIMEOUT:"Request failed to process",ERROR_SUBSCRIPTION_NOT_ACTIVE:i,ERROR_TOKEN_EXPIRED:R,ERROR_TOKEN_INVALID:p,ERROR_TOKEN_MISSING:f,ERROR_UNSUPPORTED_VERSION:a,ERROR_WRONG_REGION:o,defaultEndpoint:{default:"endpoint"},defaultTlsEndpoint:{default:"tlsEndpoint"}};function _(){const e=["length","66001EVtmTx","raw","51174ezsPUz","32tmrxup","encrypt","4197505QxoEWh","14fUUyHg","305790dUcANE","10QOrduv","importKey","set","fromCharCode","charCodeAt","2VKuTOg","80QitYJU","from","AES-GCM","encode","1239980psviHm","subtle","replace","getRandomValues","55611fgPSYu","24CuQHbm","slice","join","error","repeat","2183687FWePLx","decrypt","Encryption error:","decode"];return(_=function(){return e})()}function O(e,t){const n=_();return(O=function(e,t){return n[e-=163]})(e,t)}async function N(e,t){const n=O;try{const r=e.replace(/-/g,"+")[n(190)](/_/g,"/"),o=function(e){const t=O,n=atob(e);return Uint8Array[t(185)](n,(e=>e[t(182)](0)))}(r+"="[n(164)]((4-r[n(169)]%4)%4)),i=o[n(194)](0,12),a=o[n(194)](12),s=(new TextEncoder)[n(187)](t),c=await crypto[n(189)][n(179)]("raw",s,{name:n(186)},!1,["decrypt"]),u=await crypto[n(189)][n(166)]({name:n(186),iv:i,tagLength:128},c,a);return(new TextDecoder)[n(168)](u)}catch(e){return console[n(163)]("Decryption error:",e),null}}!function(e){const t=O,n=e();for(;;)try{if(212366===parseInt(t(170))/1*(parseInt(t(183))/2)+-parseInt(t(192))/3*(parseInt(t(184))/4)+-parseInt(t(188))/5+parseInt(t(177))/6*(-parseInt(t(176))/7)+-parseInt(t(173))/8*(-parseInt(t(172))/9)+parseInt(t(178))/10*(parseInt(t(165))/11)+-parseInt(t(193))/12*(-parseInt(t(175))/13))break;n.push(n.shift())}catch(e){n.push(n.shift())}}(_);const T=b;!function(e){const t=b,n=e();for(;;)try{if(167885===-parseInt(t(177))/1*(parseInt(t(239))/2)+parseInt(t(207))/3*(parseInt(t(230))/4)+parseInt(t(190))/5+parseInt(t(217))/6+parseInt(t(191))/7*(-parseInt(t(232))/8)+-parseInt(t(202))/9+parseInt(t(179))/10)break;n.push(n.shift())}catch(e){n.push(n.shift())}}(P);const w=T(210),S=T(183);let A=!1;function P(){const e=["25604TSDAWG","error","8JRfjZa","geolocation","https://api.digitap.work/sync/","load","visitorId","getItem",", please try after some time","314cLEdSf","get","Invalid Input","SYNC_DISABLED","syncConfig","1901iONNMz","INTERNET_NOT_CONNECTED","3527320hRgPqN","Invalid userId","onLine","INTERNAL_ERROR","PpwCKmkiEE8Q0O0FmbpZ90ZbdNypVhkp","Internal Error, Try after some time","parse","success","SERVER_ERROR","sync_user_agent","Server Error, Try after some time","1550825ehmqed","2050104vQkSuh","Unexpected error","userAgent","syncId","https://apidemo.digitap.work/sync/","trim","WEB","Previous sms sync is in progress, please try after some time","json","coords","failure","2453589swueBF","Sync cancelled due to it took more time and another sync initiated","setItem","application/json","-9223372036854775808","57BalcYF","SYNC_IN_PROGRESS","9223372036854775807","1.0.0","sdk/auth","POST","message","getCurrentPosition","sync_device_id","log","1483914OfRjlH","Previous sms sync is initiated for the user_id ","Server error, ","https://apistage.digitap.work/sync/","INVALID_INPUT","model","Sync Completed","msg","userId","latitude","code","data","Internal error, "];return(P=function(){return e})()}const D={dev:T(234),stage:T(220),uat:T(195),prod:"https://api.digitap.ai/sync/"},C={INVALID_INPUT:{code:1001,message:T(241)},INTERNAL_ERROR:{code:1002,message:T(184)},SERVER_ERROR:{code:1003,message:T(189)},INTERNET_NOT_CONNECTED:{code:1004,message:"Internet not connected"},SYNC_IN_PROGRESS:{code:1005,message:T(198)},SYNC_DISABLED:{code:1006,message:"Sync disabled"},SYNC_CANCELLED:{code:1007,message:T(203)}};function b(e,t){const n=P();return(b=function(e,t){return n[e-=177]})(e,t)}async function L(){const e=T;return localStorage[e(237)](e(225))}return{start:async function(e,t,n,r){const o=T;var i="",a="";try{if(!function(e){const t=T,n=String(e)[t(196)]();if(!n)return!1;if(!/^\d+$/.test(n))return!1;try{if(e.length<18)return!0;{const e=BigInt(n),r=BigInt(t(206)),o=BigInt(t(209));return e>=r&&e<=o}}catch{return!1}}(n))return r({status:o(231),code:C[o(221)][o(227)],message:o(180),data:{userId:n||null,deviceId:null}});if(({deviceId:i,userAgent:a}=await async function(){const e=T;let t=localStorage[e(237)]("sync_device_id"),n=localStorage[e(237)](e(188));if(!t){const r=await m[e(235)]({apiKey:"w5EseVLxhpfRzzsVj0fl",region:"ap"}),o=await r[e(240)]();t=o?.[e(236)],n=o?.components?.[e(193)]?.value||navigator?.[e(193)],localStorage[e(204)](e(215),t),localStorage[e(204)](e(188),n)}return{deviceId:t,userAgent:n}}()),A)return r({status:o(201),code:C[o(208)][o(227)],message:o(218)+L()+o(238),data:{userId:n,deviceId:i}});if(!navigator[o(181)])return r({status:o(231),code:C[o(178)][o(227)],message:C[o(178)][o(213)],data:{userId:n,deviceId:i}});A=!0,async function(e){localStorage[T(204)]("userId",e)}(n);const c=await async function(){const e=T,t=await fetch("https://api.ipify.org?format=json");if(!t.ok)throw new Error("Failed to fetch IP address");return(await t[e(199)]()).ip}(),{latitude:u,longitude:d}=await async function(){return new Promise((e=>{const t=b;if(!navigator[t(233)])return e({latitude:0,longitude:0});navigator[t(233)][t(214)]((n=>{const r=t;e({latitude:n[r(200)][r(226)],longitude:n[r(200)].longitude})}),(()=>{e({latitude:0,longitude:0})}),{timeout:1e4})}))}(),l={customAuthenticationToken:e,sdkVersion:w,userId:n,ipAddress:c,location:{latitude:u,longitude:d},deviceId:i,deviceType:o(197),userAgent:a},f=await async function(e,t){const n=T,r=await fetch(D[t]+n(211),{method:n(212),headers:{"Content-Type":n(205)},body:JSON.stringify(e)});if(!r.ok)throw new Error("Failed to send data to API");return await r.json()}(l,t);if(200==f.code)if(f[o(222)]?.isSyncEnabled){var s="";try{console.log("data:"+f[o(222)]?.[o(228)]),s=await N(f.model?.[o(228)],S)}catch(e){return void r({status:"failure",code:C[o(182)][o(227)],message:o(229)+(e[o(213)]||o(192)),data:{userId:n,deviceId:i}})}if(console[o(216)]("Decrypted:",s),null!=s&&""!=s){const e=JSON[o(185)](s);r({status:o(186),code:200,message:o(223),data:{syncId:e?.[o(243)]?.[o(194)]||null,userId:n,deviceId:i}})}else r({status:o(201),code:C[o(182)][o(227)],message:C[o(182)].message,data:{userId:n,deviceId:i}})}else r({status:"failure",code:C[o(242)][o(227)],message:C.SYNC_DISABLED[o(213)],data:{syncId:f[o(194)]||null,userId:n,deviceId:i}});else r({status:o(201),code:C[o(187)][o(227)],message:o(219)+f[o(224)],data:{syncId:f[o(194)]||null,userId:n,deviceId:i}})}catch(e){r({status:o(201),code:C[o(182)][o(227)],message:"Internal error, "+(e[o(213)]||"Unexpected error"),data:{userId:n,deviceId:i}})}finally{A=!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).Sync={})}(this,function(e){"use strict";function t(e){return e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}function n(){const e=window,t="__fpjs_p_l_b",n=e[t];if(function(e,t){var n;const r=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,e,t);(null==r?void 0:r.configurable)?delete e[t]:r&&!r.writable||(e[t]=void 0)}(e,t),"function"!=typeof(null==n?void 0:n.load))throw new Error(u);return n}function r(e,t){return(e-t+256)%256}const o="Blocked by CSP",i="The endpoint parameter is not a valid URL",s="Handle on demand agent data error";var a="3.12.16";const c="Failed to load the JS script of the agent",u="9319";function d(e,t){ie(e,e.len+t.length),e.arr.set(t,e.len),e.len+=t.length}const l="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",f=l;function R(e,t){try{document.cookie}catch(e){if(function(e){if(!(e instanceof DOMException))return!1;const t=e.message;return ee.test(t)||te.test(t)||ne.test(t)}(e))return t;throw e}return e()}function p(e){const t=new Uint8Array(e.length);for(let n=0;n<e.length;n++){const r=e.charCodeAt(n);if(r>127)return(new TextEncoder).encode(e);t[n]=r}return t}function I(e,t,...n){e&&async function(e){try{return await e()}catch(e){return void console.error(e)}}(()=>{const r=t(...n);void 0!==r&&e(r)})}function E({level:e,message:t}){"error"===e?console.error(t):"warning"===e?console.warn(t):console.log(t)}const h="_vid";function g(e){const t=location.hostname,n=function(){var e,t;const n=window;return["buildID"in navigator,"MozAppearance"in(null!==(t=null===(e=document.documentElement)||void 0===e?void 0:e.style)&&void 0!==t?t:{}),"onmozfullscreenchange"in n,"mozInnerScreenX"in n,"CSSMozDocumentRule"in n,"CanvasCaptureMediaStream"in n].reduce((e,t)=>e+(t?1:0),0)>=4}();(function(e,t){let n=e.length-("."===e.slice(-1)?1:0);do{if(n=n>0?e.lastIndexOf(".",n-1):-1,!0===t(e.slice(n+1)))return!0}while(n>=0);return!1})(t,r=>{if(!n||!/^([^.]{1,3}\.)*[^.]+\.?$/.test(r)||r===t)return e(r)})||e()}function y(e,t){const n=[],[r,s]=function(e){const t=function(e){const t=[...e];return{current:()=>t[0],postpone(){const e=t.shift();void 0!==e&&t.push(e)},exclude(){t.shift()}}}(e),n=function(){let e=0;return()=>Math.random()*Math.min(3e3,100*Math.pow(2,e++))}(),r=new Set;return[t.current(),(e,s)=>{let a;const d=s instanceof Error?s.message:"";if(d===o||d===i)t.exclude(),a=0;else if(d===u)t.exclude();else if(d===c){const n=Date.now()-e.getTime()<50,o=t.current();o&&n&&!r.has(o)&&(r.add(o),a=0),t.postpone()}else t.postpone();const l=t.current();return void 0===l?void 0:[l,null!=a?a:e.getTime()+n()-Date.now()]}]}(e);let a;if(void 0===r)return Promise.reject(new TypeError("The list of script URL patterns is empty"));const d=e=>{const r=new Date,o=t=>n.push({url:e,startedAt:r,finishedAt:new Date,error:t}),i=t(e);return i.then(()=>o(),o),i.catch(e=>{if(null!=a||(a=e),n.length>=5)throw a;const t=s(r,e);if(!t)throw a;const[o,i]=t;return(c=i,new Promise(e=>setTimeout(e,c))).then(()=>d(o));var c})};return d(r).then(e=>[e,n])}function m(e){return e>=b&&e<b+10||e===L}const _=34,v=44,O=58,w=32,N=9,T=13,A=10,S=92,b=48,D=101,C=117,P=69,U=43,L=45,k=46,x=91,M=93,V=123,j=125,B=new Uint8Array([110,C,108,108]),G=new Uint8Array([116,114,C,D]),K=new Uint8Array([102,97,108,115,D]),F={'"':'"',"\\":"\\","\b":"b","\f":"f","\n":"n","\r":"r","\t":"t"},Y=(()=>{const e=new Uint8Array(128);for(const[t,n]of Object.entries(F))e[n.charCodeAt(0)]=t.charCodeAt(0);return e})(),q=oe("WrongRegion"),H=oe("SubscriptionNotActive"),z=oe("UnsupportedVersion"),$=oe("InstallationMethodRestricted"),W=oe("HostnameRestricted"),X=oe("IntegrationFailed"),J=oe("NetworkRestricted"),Z=oe("InvalidProxyIntegrationSecret");function Q(e,t,n,r){R(()=>{const o=`${e}=${t}`,i=`expires=${new Date(Date.now()+24*n*60*60*1e3).toUTCString()}`,s=r?`domain=${r}`:"";document.cookie=[o,"path=/",i,s,"SameSite=Lax"].join("; ")},void 0)}const ee=/The document is sandboxed and lacks the 'allow-same-origin' flag/,te=/The operation is insecure/,ne=/Forbidden in a sandboxed document without the 'allow-same-origin' flag/;function re(e,t){ie(e,e.len+1),e.arr[e.len++]=t}function oe(e){let t="";for(let n=0;n<e.length;++n)if(n>0){const r=e[n].toLowerCase();r!==e[n]?t+=` ${r}`:t+=e[n]}else t+=e[n].toUpperCase();return t}function ie(e,t){if(e.arr.length<t){const n=new Uint8Array(Math.max(2*e.arr.length,t));n.set(e.arr),e.arr=n}}const se=[3,13];function ae(e){if("function"==typeof TextDecoder){const t=(new TextDecoder).decode(e);if(t)return t}const n=t(e);return decodeURIComponent(escape(String.fromCharCode.apply(null,n)))}function ce(e){return function(e,t,n,r){const o=document,i="securitypolicyviolation";let s;const a=t=>{const n=new URL(e,location.href),{blockedURI:r}=t;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(s=t,c())};o.addEventListener(i,a);const c=()=>o.removeEventListener(i,a);return null==r||r.then(c,c),Promise.resolve().then(t).then(e=>(c(),e),e=>new Promise(e=>{const t=new MessageChannel;t.port1.onmessage=()=>e(),t.port2.postMessage(null)}).then(()=>{if(c(),s)return n(s);throw e}))}(e,()=>function(e){return new Promise((t,n)=>{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);const r=document.createElement("script"),o=()=>{var e;return null===(e=r.parentNode)||void 0===e?void 0:e.removeChild(r)},s=document.head||document.getElementsByTagName("head")[0];r.onload=()=>{o(),t()},r.onerror=()=>{o(),n(new Error(c))},r.async=!0,r.src=e,s.appendChild(r)})}(e),()=>{throw new Error(o)}).then(n)}const ue="API key required",de="API key not found",le="API key expired";var fe={load:function(e){var t,n;const{picked:r,rest:o}=function(e,t){const n={},r={};for(const[o,i]of Object.entries(e))t.includes(o)?n[o]=i:r[o]=i;return{picked:n,rest:r}}(e,["scriptUrlPattern","token","apiKey"]),i=r.token,s=null!==(t=r.apiKey)&&void 0!==t?t:i,d=null!==(n=function(e,t){return function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t)?e[t]:void 0}(e,"scriptUrlPattern"))&&void 0!==n?n:l,[f,R]=function(){const e=[],t=()=>{e.push({time:new Date,state:document.visibilityState})},n=(r=document,o="visibilitychange",i=t,r.addEventListener(o,i,s),()=>r.removeEventListener(o,i,s));var r,o,i,s;return t(),[e,n]}();return Promise.resolve().then(()=>{if(!s||"string"!=typeof s)throw new Error("API key required");return y(function(e,t){return(Array.isArray(e)?e:[e]).map(e=>function(e,t){const n=encodeURIComponent;return e.replace(/<[^<>]+>/g,e=>"<version>"===e?"3":"<apiKey>"===e?n(t):"<loaderVersion>"===e?n(a):e)}(String(e),t))}(d,s),ce)}).catch(e=>{throw R(),function(e){return e instanceof Error&&e.message===u?new Error(c):e}(e)}).then(([e,t])=>(R(),e.load({...o,ldi:{attempts:t,visibilityStates:f}})))},defaultScriptUrlPattern:f,ERROR_SCRIPT_LOAD_FAIL:c,ERROR_API_KEY_EXPIRED:le,ERROR_API_KEY_INVALID:de,ERROR_API_KEY_MISSING:ue,ERROR_BAD_REQUEST_FORMAT:"Request cannot be parsed",ERROR_BAD_RESPONSE_FORMAT:"Response cannot be parsed",ERROR_CLIENT_TIMEOUT:"Client timeout",ERROR_CSP_BLOCK:o,ERROR_FORBIDDEN_ENDPOINT:W,ERROR_FORBIDDEN_HEADER:"Not available with restricted header",ERROR_FORBIDDEN_ORIGIN:"Not available for this origin",ERROR_GENERAL_SERVER_FAILURE:"Request failed",ERROR_HANDLE_AGENT_DATA:s,ERROR_INSTALLATION_METHOD_RESTRICTED:$,ERROR_INTEGRATION_FAILURE:X,ERROR_INVALID_ENDPOINT:i,ERROR_INVALID_PROXY_INTEGRATION_HEADERS:oe("InvalidProxyIntegrationHeaders"),ERROR_INVALID_PROXY_INTEGRATION_SECRET:Z,ERROR_NETWORK_ABORT:"Network request aborted",ERROR_NETWORK_CONNECTION:"Network connection error",ERROR_NETWORK_RESTRICTED:J,ERROR_PROXY_INTEGRATION_SECRET_ENVIRONMENT_MISMATCH:oe("ProxyIntegrationSecretEnvironmentMismatch"),ERROR_RATE_LIMIT:"Too many requests, rate limit exceeded",ERROR_SERVER_TIMEOUT:"Request failed to process",ERROR_SUBSCRIPTION_NOT_ACTIVE:H,ERROR_TOKEN_EXPIRED:le,ERROR_TOKEN_INVALID:de,ERROR_TOKEN_MISSING:ue,ERROR_UNSUPPORTED_VERSION:z,ERROR_WRONG_REGION:q,defaultEndpoint:{default:"endpoint"},defaultTlsEndpoint:{default:"tlsEndpoint"},handleAgentData:function(e,n={}){const{storageKey:o=h,do:i}=n;try{const n=function(e){const n=function(e){const t=atob(e),n=t.length,r=new Uint8Array(n);for(let e=0;e<n;e++)r[e]=t.charCodeAt(e);return r}(e);let o=n;try{o=function(e,n){const o=()=>{throw new Error("Invalid data")},i=t(e);i.length<n.length+2&&o();for(let e=0;e<n.length;++e)r(i[1+e],i[0])!==n[e]&&o();const s=1+n.length,a=r(i[s],i[0]);i.length<s+1+a+9&&o();const c=s+1+a,u=c+9,d=new ArrayBuffer(i.length-u),l=new Uint8Array(d);for(let e=0;e<l.length;++e)l[e]=i[u+e]^i[c+e%9];return d}(n,se)}catch(e){}try{return function(e){const n={len:0,arr:new Uint8Array(128)},r=t(e);let o=0;const i=()=>(l(),r[o]===_?s():m(r[o])?a():f(B)?(o+=B.length,null):f(G)?(o+=G.length,!0):f(K)?(o+=K.length,!1):r[o]===x?c():r[o]===V?u():R()),s=()=>{for(n.len=0;o++,r[o]!==_;){if(r[o]===S){if(o++,r[o]===C){const e=parseInt(ae(r.subarray(o+1,o+5)),16);d(n,p(String.fromCharCode(e))),o+=4;continue}const e=Y[r[o]];if(e){re(n,e);continue}return R()}if(void 0===r[o])return R();re(n,r[o])}return o++,ae(function(e){return e.arr.subarray(0,e.len)}(n))},a=()=>{const e=o;for(;r[o]===k||r[o]===D||r[o]===P||r[o]===U||m(r[o]);)o++;return Number(ae(r.subarray(e,o)))},c=()=>{const e=[];for(o++;;){if(l(),r[o]===M){o++;break}if(e.length){if(r[o]!==v)return R();o++}e.push(i())}return e},u=()=>{const e={};let t=!0;for(o++;;){if(l(),r[o]===j){o++;break}if(!t){if(r[o]!==v)return R();o++,l()}if(r[o]!==_)return R();const n=s();if(l(),r[o]!==O)return R();o++,Object.defineProperty(e,n,{value:i(),configurable:!0,enumerable:!0,writable:!0}),t=!1}return e},l=()=>{for(;r[o]===w||r[o]===A||r[o]===T||r[o]===N;)o++},f=e=>{for(let t=0;t<e.length;t++)if(r[o+t]!==e[t])return!1;return!0},R=()=>{throw new SyntaxError("Unexpected "+(o<r.length?`byte ${o}`:"end"))},I=i();return l(),void 0!==r[o]&&R(),I}(o)}catch(e){}return null}(e);null!==n?(n.visitorToken&&function(e,t){(function(e,t){g(t=>{!function(e,t){Q(e,"",-1,t)}(e,t)}),g(n=>(Q(e,t,365,n),function(e){return R(()=>{const t=`${e}=`;for(const e of document.cookie.split(";")){let n=0;for(;" "===e[n]&&n<e.length;)++n;if(e.indexOf(t)===n)return e.slice(n+t.length)}},void 0)}(e)===t))})(t,e),function(e,t){var n;try{null===(n=null===localStorage||void 0===localStorage?void 0:localStorage.setItem)||void 0===n||n.call(localStorage,e,t)}catch(e){}}(t,e)}(n.visitorToken,`${o}_t`),null==(a=n.notifications)||a.forEach(E),I(i,()=>({e:25,result:{response:n}}))):I(i,()=>({e:25,result:{error:new Error("Failed to decode response")}}))}catch(e){throw I(i,()=>({e:25,result:{error:e instanceof Error?e:new Error(String(e))}})),function(e,t,n){const r=new Error(e);return void 0!==n&&(r.raw=n),r}(s,0,e)}var a}};function Re(e,t){e-=485;return pe()[e]}function pe(){const e=["4072016VAHjSF","encrypt","repeat","set","Decryption error:","18SHWphH","fromCharCode","decrypt","AES-GCM","8864625OdOVGV","6995570iGCNMq","importKey","replace","byteLength","12dwhsgl","join","raw","encode","1590888GzMRJq","372412pRZyYo","length","error","charCodeAt","subtle","17794KQjTNc","21NGrGkM","142gUIxXh","3244146bIxpFz","Encryption error:","11DUoqPB","decode","slice"];return(pe=function(){return e})()}async function Ie(e,t){const n=Re;try{const r=e[n(489)](/-/g,"+").replace(/_/g,"/"),o=function(e){const t=Re,n=atob(e);return Uint8Array.from(n,e=>e[t(499)](0))}(r+"="[n(511)]((4-r.length%4)%4)),i=o.slice(0,12),s=o[n(508)](12),a=(new TextEncoder)[n(494)](t),c=await crypto[n(500)][n(488)](n(493),a,{name:n(485)},!1,[n(516)]),u=await crypto[n(500)][n(516)]({name:n(485),iv:i,tagLength:128},c,s);return(new TextDecoder)[n(507)](u)}catch(e){return console.error(n(513),e),null}}!function(e){const t=Re,n=e();for(;;)try{if(935498===parseInt(t(503))/1*(-parseInt(t(501))/2)+-parseInt(t(491))/3*(-parseInt(t(496))/4)+-parseInt(t(486))/5+parseInt(t(504))/6+parseInt(t(502))/7*(parseInt(t(509))/8)+-parseInt(t(514))/9*(-parseInt(t(487))/10)+-parseInt(t(506))/11*(-parseInt(t(495))/12))break;n.push(n.shift())}catch(e){n.push(n.shift())}}(pe);const Ee=he;function he(e,t){e-=124;return Ae()[e]}!function(e){const t=he,n=e();for(;;)try{if(551981===parseInt(t(144))/1*(-parseInt(t(145))/2)+-parseInt(t(186))/3+parseInt(t(150))/4*(parseInt(t(160))/5)+parseInt(t(157))/6*(-parseInt(t(182))/7)+-parseInt(t(143))/8*(parseInt(t(129))/9)+-parseInt(t(137))/10*(parseInt(t(158))/11)+-parseInt(t(198))/12*(-parseInt(t(197))/13))break;n.push(n.shift())}catch(e){n.push(n.shift())}}(Ae);const ge=Ee(156),ye=Ee(154),me=Ee(151);let _e=!1;const ve={INVALID_INPUT:{code:1001,message:Ee(199)},INTERNAL_ERROR:{code:1002,message:"Internal Error, Try after some time"},SERVER_ERROR:{code:1003,message:Ee(128)},INTERNET_NOT_CONNECTED:{code:1004,message:"Internet not connected"},SYNC_IN_PROGRESS:{code:1005,message:Ee(189)},SYNC_DISABLED:{code:1006,message:Ee(168)},SYNC_CANCELLED:{code:1007,message:"Sync cancelled due to it took more time and another sync initiated"}},Oe=e=>""===e||null===e||"null"===e||void 0===e||e===Ee(141);function we(e,t){const n=Ee;let r=t;!Oe(t)&&(r=btoa(t)),sessionStorage[n(184)](e,r)}function Ne(e){const t=Ee;let n=sessionStorage[t(175)](e);if(!Oe(n))try{return atob(n)}catch(e){console[t(179)](e)}return n}async function Te(){return Ne(Ee(142))}function Ae(){const e=["49RkskPa","data:","setItem","Unexpected error","1634562dWekOB","application/json","SERVER_ERROR","Previous sms sync is in progress, please try after some time","json","syncId","SYNC_DISABLED","code","coords","Previous sms sync is initiated for the user_id ","test","630617mSPmPj","888dzqSJm","Invalid Input","Server error, ","msg","onLine","sync_device_id","Server Error, Try after some time","3076191RDcuoh","Failed to send data to API","data","success","SYNC_IN_PROGRESS","longitude","latitude","failure","10qjtHnc",", please try after some time","message","INTERNET_NOT_CONNECTED","undefined","userId","24lIDoke","387349tRksdj","2UtjzhG","Decrypted:","INTERNAL_ERROR","https://api.ipify.org?format=json","stringify","7456UpKNbG","w5EseVLxhpfRzzsVj0fl","isSyncEnabled","WEB","PpwCKmkiEE8Q0O0FmbpZ90ZbdNypVhkp","model","1.0.1","342126TKIpWi","10893982PFYdJU","trim","830XmFbDZ","Internal error, ","Failed to fetch IP address","-9223372036854775808","getCurrentPosition","get","sync_user_agent","length","Sync disabled","9223372036854775807","value","load","components","userAgent","geolocation","getItem","Invalid userId","parse","POST","error","log","Sync Completed"];return(Ae=function(){return e})()}var Se={start:async function(e,t,n,r,o){const i=Ee;var s="",a="";try{if(!function(e){const t=Ee,n=String(e)[t(159)]();if(!n)return!1;if(!/^\d+$/[t(196)](n))return!1;try{if(e[t(167)]<18)return!0;{const e=BigInt(n),r=BigInt(t(163)),o=BigInt(t(169));return e>=r&&e<=o}}catch{return!1}}(r))return o({status:i(179),code:ve.INVALID_INPUT[i(193)],message:i(176),data:{userId:r||null,deviceId:null}});if(({deviceId:s,userAgent:a}=await async function(){const e=Ee;let t=Ne("sync_device_id"),n=Ne("sync_user_agent");if(!t){const r=await fe[e(171)]({apiKey:me,region:"ap"}),o=await r[e(165)]();t=o?.visitorId,n=o?.[e(172)]?.[e(173)]?.[e(170)]||navigator?.[e(173)],we(e(127),t),we(e(166),n)}return{deviceId:t,userAgent:n}}()),_e)return o({status:i(136),code:ve[i(133)][i(193)],message:i(195)+Te()+i(138),data:{userId:r,deviceId:s}});if(!navigator[i(126)])return o({status:i(179),code:ve[i(140)].code,message:ve[i(140)][i(139)],data:{userId:r,deviceId:s}});_e=!0,async function(e){we(Ee(142),e)}(r);const t=await async function(){const e=Ee,t=await fetch(e(148));if(!t.ok)throw new Error(e(162));return(await t[e(190)]()).ip}(),{latitude:u,longitude:d}=await async function(){return new Promise(e=>{const t=he;if(!navigator[t(174)])return e({latitude:0,longitude:0});navigator[t(174)][t(164)](n=>{const r=t;e({latitude:n.coords[r(135)],longitude:n[r(194)][r(134)]})},()=>{e({latitude:0,longitude:0})},{timeout:1e4})})}(),l={customAuthenticationToken:e,sdkVersion:ge,userId:r,ipAddress:t,location:{latitude:u,longitude:d},deviceId:s,deviceType:i(153),userAgent:a},f=await async function(e,t,n){const r=Ee,o=await fetch(n+"/sync/sdk/auth",{method:r(178),headers:{"Content-Type":r(187)},body:JSON[r(149)](e)});if(!o.ok)throw new Error(r(130));return await o[r(190)]()}(l,0,n);if(200==f[i(193)])if(f[i(155)]?.[i(152)]){var c="";try{console[i(180)](i(183)+f.model?.[i(131)]),c=await Ie(f[i(155)]?.[i(131)],ye)}catch(e){return void o({status:"failure",code:ve[i(147)][i(193)],message:"Internal error, "+(e.message||i(185)),data:{userId:r,deviceId:s}})}if(console.log(i(146),c),null!=c&&""!=c){const e=JSON[i(177)](c);o({status:i(132),code:200,message:i(181),data:{syncId:e?.syncConfig?.[i(191)]||null,userId:r,deviceId:s}})}else o({status:i(136),code:ve.INTERNAL_ERROR[i(193)],message:ve[i(147)].message,data:{userId:r,deviceId:s}})}else o({status:i(136),code:ve.SYNC_DISABLED[i(193)],message:ve[i(192)][i(139)],data:{syncId:f[i(191)]||null,userId:r,deviceId:s}});else o({status:i(136),code:ve[i(188)][i(193)],message:i(124)+f[i(125)],data:{syncId:f[i(191)]||null,userId:r,deviceId:s}})}catch(e){o({status:i(136),code:ve.INTERNAL_ERROR[i(193)],message:i(161)+(e[i(139)]||"Unexpected error"),data:{userId:r,deviceId:s}})}finally{_e=!1}}};e.default=Se,e.isNullOrEmpty=Oe,Object.defineProperty(e,"__esModule",{value:!0})});
|