@digitap.ai/sync-sdk 0.0.9 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 v(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 m="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(g)}function g(){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 O={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:m,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 v(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:m,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 h(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 _=!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"},S={code:1003,message:"Server Error, Try after some time"},P={code:1004,message:"Internet not connected"},A={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){let o=null;try{if(!function(e){return!(!e||""===String(e).trim()||isNaN(Number(e))||""===String(e).replace(/^0+/,"").trim())}(r))return n({status:"error",code:T.code,message:"Invalid userId",data:{userId:r||null,deviceId:null}});if(_)return n({status:"failure",code:A.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:P.code,message:P.message,data:{userId:r,deviceId:o}});_=!0,async function(e){localStorage.setItem("userId",e)}(r),o=await async function(){let e=localStorage.getItem("sync_device_id");if(!e){const t=await O.load({apiKey:"w5EseVLxhpfRzzsVj0fl"});e=(await t.get()).visitorId,localStorage.setItem("sync_device_id",e)}return e}();const a=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:s,longitude:c}=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})}))}(),u={customAuthenticationToken:e,sdkVersion:"1.0.0",userId:r,ipAddress:a,location:{latitude:s,longitude:c},deviceId:o,deviceType:"WEB"},d=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()}(u,t);if(200==d.code)if(d.model?.isSyncEnabled){var i="";try{console.log("data:"+d.model?.data),i=await h(d.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:",i),null!=i&&""!=i){const e=JSON.parse(i);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:d.syncId||null,userId:r,deviceId:o}});else n({status:"failure",code:S.code,message:"Server error, "+d.msg,data:{syncId:d.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{_=!1}}};export{L as default};
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 v(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 m="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(g)}function g(){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 O={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:m,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 v(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:m,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 h(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 _=!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"},S={code:1003,message:"Server Error, Try after some time"},P={code:1004,message:"Internet not connected"},A={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){let o=null;try{if(!function(e){return!(!e||""===String(e).trim()||isNaN(Number(e))||""===String(e).replace(/^0+/,"").trim())}(r))return n({status:"error",code:T.code,message:"Invalid userId",data:{userId:r||null,deviceId:null}});if(_)return n({status:"failure",code:A.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:P.code,message:P.message,data:{userId:r,deviceId:o}});_=!0,async function(e){localStorage.setItem("userId",e)}(r),o=await async function(){let e=localStorage.getItem("sync_device_id");if(!e){const t=await O.load({apiKey:"w5EseVLxhpfRzzsVj0fl",region:"ap"});e=(await t.get()).visitorId,localStorage.setItem("sync_device_id",e)}return e}();const a=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:s,longitude:c}=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})}))}(),u={customAuthenticationToken:e,sdkVersion:"1.0.0",userId:r,ipAddress:a,location:{latitude:s,longitude:c},deviceId:o,deviceType:"WEB"},d=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()}(u,t);if(200==d.code)if(d.model?.isSyncEnabled){var i="";try{console.log("data:"+d.model?.data),i=await h(d.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:",i),null!=i&&""!=i){const e=JSON.parse(i);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:d.syncId||null,userId:r,deviceId:o}});else n({status:"failure",code:S.code,message:"Server error, "+d.msg,data:{syncId:d.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{_=!1}}};export{L as default};
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",R="API key not found",p="API key expired",E="Failed to load the JS script of the agent",I="9319";function y(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===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,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 R(o)}))}))};return R(l).then((function(e){return[e,u]}))}var h="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";function m(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(E))},o.async=!0,o.src=e,a.appendChild(o)}))}(e)}),(function(){throw new Error(t)})).then(v)}function v(){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(I);return n}var _={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:h,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 y(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),m)})).catch((function(e){throw d(),function(e){return e instanceof Error&&e.message===I?new Error(E):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:h,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: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:p,ERROR_TOKEN_INVALID:R,ERROR_TOKEN_MISSING:f,ERROR_UNSUPPORTED_VERSION:a,ERROR_WRONG_REGION:o,defaultEndpoint:{default:"endpoint"},defaultTlsEndpoint:{default:"tlsEndpoint"}};function O(){const e=["charCodeAt","getRandomValues","30GnTJrx","277869kalgll","2569072RBKyOW","repeat","encrypt","set","Encryption error:","slice","join","166180KdoJRe","raw","decrypt","2815560vdMmFt","subtle","607218IwWEjm","encode","5unMsHw","fromCharCode","replace","decode","275pciGGN","2GrVDOs","622484TiDRWM","error","length","3070UfbtDy","AES-GCM","importKey","from"];return(O=function(){return e})()}function g(e,t){const n=O();return(g=function(e,t){return n[e-=296]})(e,t)}async function N(e,t){const n=g;try{const r=e[n(315)](/-/g,"+")[n(315)](/_/g,"/"),o=function(e){const t=g,n=atob(e);return Uint8Array.from(n,(e=>e[t(326)](0)))}(r+"="[n(300)]((4-r[n(321)]%4)%4)),i=o.slice(0,12),a=o[n(304)](12),s=(new TextEncoder).encode(t),c=await crypto[n(310)].importKey(n(307),s,{name:"AES-GCM"},!1,["decrypt"]),u=await crypto[n(310)][n(308)]({name:n(323),iv:i,tagLength:128},c,a);return(new TextDecoder)[n(316)](u)}catch(e){return console[n(320)]("Decryption error:",e),null}}!function(e){const t=g,n=e();for(;;)try{if(182889===-parseInt(t(298))/1*(parseInt(t(318))/2)+parseInt(t(311))/3+parseInt(t(319))/4*(parseInt(t(313))/5)+-parseInt(t(297))/6*(-parseInt(t(306))/7)+-parseInt(t(299))/8+parseInt(t(309))/9+-parseInt(t(322))/10*(parseInt(t(317))/11))break;n.push(n.shift())}catch(e){n.push(n.shift())}}(O);const T=b;!function(e){const t=b,n=e();for(;;)try{if(226623===-parseInt(t(201))/1*(parseInt(t(202))/2)+parseInt(t(221))/3*(parseInt(t(229))/4)+parseInt(t(254))/5*(parseInt(t(196))/6)+-parseInt(t(239))/7+-parseInt(t(242))/8*(parseInt(t(200))/9)+parseInt(t(213))/10+-parseInt(t(215))/11*(-parseInt(t(219))/12))break;n.push(n.shift())}catch(e){n.push(n.shift())}}(C);const w=T(214),S=T(198);let A=!1;const P={dev:"https://api.digitap.work/sync/",stage:"https://apistage.digitap.work/sync/",uat:T(204),prod:T(248)},D={INVALID_INPUT:{code:1001,message:T(260)},INTERNAL_ERROR:{code:1002,message:"Internal Error, Try after some time"},SERVER_ERROR:{code:1003,message:T(247)},INTERNET_NOT_CONNECTED:{code:1004,message:"Internet not connected"},SYNC_IN_PROGRESS:{code:1005,message:T(212)},SYNC_DISABLED:{code:1006,message:"Sync disabled"},SYNC_CANCELLED:{code:1007,message:"Sync cancelled due to it took more time and another sync initiated"}};function b(e,t){const n=C();return(b=function(e,t){return n[e-=194]})(e,t)}async function L(){const e=T;return localStorage[e(224)](e(258))}function C(){const e=["Sync Completed","POST","INTERNET_NOT_CONNECTED","message","Previous sms sync is in progress, please try after some time","1816630QkSHjU","1.0.0","11DbTmRV","coords","log",", please try after some time","1288572NEMYth","data:","3eSQwnl","data","Previous sms sync is initiated for the user_id ","getItem","latitude","WEB","failure","setItem","1581012kbHQMJ","Server error, ","msg","replace","Internal error, ","parse","https://api.ipify.org?format=json","Failed to fetch IP address","error","SYNC_IN_PROGRESS","1042608hlaLho","longitude","INTERNAL_ERROR","1049568bLyWWP","syncId","sdk/auth","onLine","stringify","Server Error, Try after some time","https://api.digitap.ai/sync/","getCurrentPosition","code","w5EseVLxhpfRzzsVj0fl","SERVER_ERROR","model","3720ndghhY","isSyncEnabled","application/json","Unexpected error","userId","get","Invalid Input","geolocation","json","load","516JxJpia","trim","PpwCKmkiEE8Q0O0FmbpZ90ZbdNypVhkp","syncConfig","18KItlsf","6129hVeEkL","36cYNFXB","visitorId","https://apidemo.digitap.work/sync/","Failed to send data to API","SYNC_DISABLED","sync_device_id"];return(C=function(){return e})()}return{start:async function(e,t,n,r){const o=T;let i=null;try{if(!function(e){const t=T;return!(!e||""===String(e).trim()||isNaN(Number(e))||""===String(e)[t(232)](/^0+/,"")[t(197)]())}(n))return r({status:o(237),code:D.INVALID_INPUT[o(250)],message:"Invalid userId",data:{userId:n||null,deviceId:null}});if(A)return r({status:o(227),code:D[o(238)][o(250)],message:o(223)+L()+o(218),data:{userId:n,deviceId:i}});if(!navigator[o(245)])return r({status:o(237),code:D[o(210)][o(250)],message:D[o(210)][o(211)],data:{userId:n,deviceId:i}});A=!0,async function(e){const t=T;localStorage[t(228)](t(258),e)}(n),i=await async function(){const e=T;let t=localStorage[e(224)]("sync_device_id");if(!t){const n=await _[e(195)]({apiKey:e(251)});t=(await n[e(259)]())[e(203)],localStorage.setItem(e(207),t)}return t}();const s=await async function(){const e=T,t=await fetch(e(235));if(!t.ok)throw new Error(e(236));return(await t[e(194)]()).ip}(),{latitude:c,longitude:u}=await async function(){return new Promise((e=>{const t=b;if(!navigator[t(261)])return e({latitude:0,longitude:0});navigator.geolocation[t(249)]((n=>{const r=t;e({latitude:n.coords[r(225)],longitude:n[r(216)][r(240)]})}),(()=>{e({latitude:0,longitude:0})}),{timeout:1e4})}))}(),d={customAuthenticationToken:e,sdkVersion:w,userId:n,ipAddress:s,location:{latitude:c,longitude:u},deviceId:i,deviceType:o(226)},l=await async function(e,t){const n=T,r=await fetch(P[t]+n(244),{method:n(209),headers:{"Content-Type":n(256)},body:JSON[n(246)](e)});if(!r.ok)throw new Error(n(205));return await r[n(194)]()}(d,t);if(200==l.code)if(l[o(253)]?.[o(255)]){var a="";try{console[o(217)](o(220)+l[o(253)]?.[o(222)]),a=await N(l[o(253)]?.[o(222)],S)}catch(e){return void r({status:o(227),code:D.INTERNAL_ERROR[o(250)],message:o(233)+(e[o(211)]||o(257)),data:{userId:n,deviceId:i}})}if(console[o(217)]("Decrypted:",a),null!=a&&""!=a){const e=JSON[o(234)](a);r({status:"success",code:200,message:o(208),data:{syncId:e?.[o(199)]?.syncId||null,userId:n,deviceId:i}})}else r({status:o(227),code:D.INTERNAL_ERROR[o(250)],message:D[o(241)].message,data:{userId:n,deviceId:i}})}else r({status:o(227),code:D[o(206)].code,message:D[o(206)][o(211)],data:{syncId:l[o(243)]||null,userId:n,deviceId:i}});else r({status:o(227),code:D[o(252)][o(250)],message:o(230)+l[o(231)],data:{syncId:l[o(243)]||null,userId:n,deviceId:i}})}catch(e){r({status:"failure",code:D[o(241)][o(250)],message:o(233)+(e.message||o(257)),data:{userId:n,deviceId:i}})}finally{A=!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",R="API key not found",p="API key expired",E="Failed to load the JS script of the agent",I="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===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,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 R(o)}))}))};return R(l).then((function(e){return[e,u]}))}var y="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";function h(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(E))},o.async=!0,o.src=e,a.appendChild(o)}))}(e)}),(function(){throw new Error(t)})).then(g)}function g(){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(I);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),h)})).catch((function(e){throw d(),function(e){return e instanceof Error&&e.message===I?new Error(E):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: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: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:p,ERROR_TOKEN_INVALID:R,ERROR_TOKEN_MISSING:f,ERROR_UNSUPPORTED_VERSION:a,ERROR_WRONG_REGION:o,defaultEndpoint:{default:"endpoint"},defaultTlsEndpoint:{default:"tlsEndpoint"}};function O(e,t){const n=_();return(O=function(e,t){return n[e-=321]})(e,t)}function _(){const e=["88OGKZgW","8srUCLs","37690iERMAo","charCodeAt","3FcxJvx","decrypt","from","length","encode","set","subtle","7115112RDhbOo","slice","replace","importKey","1727SnZeAE","290543FTRtRX","121465tIfVNE","821176EBHiLx","167251ltVPvH","AES-GCM","getRandomValues","byteLength","decode","Decryption error:","4959492XRLyVa","error","raw","join","encrypt","12DtNMJv","fromCharCode"];return(_=function(){return e})()}async function N(e,t){const n=O;try{const r=e[n(350)](/-/g,"+")[n(350)](/_/g,"/"),o=function(e){const t=O,n=atob(e);return Uint8Array[t(343)](n,(e=>e[t(340)](0)))}(r+"=".repeat((4-r.length%4)%4)),i=o[n(349)](0,12),a=o[n(349)](12),s=(new TextEncoder)[n(345)](t),c=await crypto.subtle[n(351)](n(332),s,{name:n(325)},!1,[n(342)]),u=await crypto.subtle[n(342)]({name:n(325),iv:i,tagLength:128},c,a);return(new TextDecoder)[n(328)](u)}catch(e){return console[n(331)](n(329),e),null}}!function(e){const t=O,n=e();for(;;)try{if(493227===-parseInt(t(321))/1+parseInt(t(323))/2*(-parseInt(t(341))/3)+parseInt(t(337))/4*(parseInt(t(322))/5)+parseInt(t(335))/6*(parseInt(t(324))/7)+parseInt(t(338))/8*(parseInt(t(348))/9)+parseInt(t(339))/10*(-parseInt(t(352))/11)+parseInt(t(330))/12)break;n.push(n.shift())}catch(e){n.push(n.shift())}}(_);const T=b;function w(){const e=["Failed to fetch IP address","msg","geolocation","Server Error, Try after some time","SYNC_DISABLED","Internet not connected","isSyncEnabled","setItem","7ieHvCx","visitorId","INTERNET_NOT_CONNECTED","log","3922870GCaCMQ","4rNPUst","Sync cancelled due to it took more time and another sync initiated","data","syncId","syncConfig","40400QvDQpi","getCurrentPosition","code","Previous sms sync is in progress, please try after some time","userId","https://apistage.digitap.work/sync/","error","data:","INTERNAL_ERROR","3735306FLnqrp","5046392ggiGQZ","get","failure","sync_device_id","Sync disabled","Sync Completed","https://api.digitap.work/sync/","WEB","json","coords","SERVER_ERROR","555894pkryCi","getItem","Failed to send data to API","4072128mrOYVB","Unexpected error","onLine","Previous sms sync is initiated for the user_id ","success","Internal Error, Try after some time","model","Invalid Input","https://apidemo.digitap.work/sync/","Invalid userId","9DXvELY","w5EseVLxhpfRzzsVj0fl","trim","Server error, ","stringify","Decrypted:","INVALID_INPUT","33736720WZpzoG","message","PpwCKmkiEE8Q0O0FmbpZ90ZbdNypVhkp","Internal error, ","sdk/auth"];return(w=function(){return e})()}!function(e){const t=b,n=e();for(;;)try{if(583814===parseInt(t(476))/1*(parseInt(t(471))/2)+parseInt(t(497))/3+-parseInt(t(436))/4+-parseInt(t(470))/5+-parseInt(t(485))/6*(parseInt(t(466))/7)+parseInt(t(486))/8*(-parseInt(t(446))/9)+parseInt(t(453))/10)break;n.push(n.shift())}catch(e){n.push(n.shift())}}(w);const S=T(455);let A=!1;const P={dev:T(492),stage:T(481),uat:T(444),prod:"https://api.digitap.ai/sync/"},D={INVALID_INPUT:{code:1001,message:T(443)},INTERNAL_ERROR:{code:1002,message:T(441)},SERVER_ERROR:{code:1003,message:T(461)},INTERNET_NOT_CONNECTED:{code:1004,message:T(463)},SYNC_IN_PROGRESS:{code:1005,message:T(479)},SYNC_DISABLED:{code:1006,message:T(490)},SYNC_CANCELLED:{code:1007,message:T(472)}};async function C(){const e=T;return localStorage[e(498)](e(480))}function b(e,t){const n=w();return(b=function(e,t){return n[e-=436]})(e,t)}return{start:async function(e,t,n,r){const o=T;let i=null;try{if(!function(e){const t=T;return!(!e||""===String(e)[t(448)]()||isNaN(Number(e))||""===String(e).replace(/^0+/,"")[t(448)]())}(n))return r({status:o(482),code:D[o(452)].code,message:o(445),data:{userId:n||null,deviceId:null}});if(A)return r({status:o(488),code:D.SYNC_IN_PROGRESS[o(478)],message:o(439)+C()+", please try after some time",data:{userId:n,deviceId:i}});if(!navigator[o(438)])return r({status:o(482),code:D[o(468)][o(478)],message:D[o(468)][o(454)],data:{userId:n,deviceId:i}});A=!0,async function(e){const t=T;localStorage.setItem(t(480),e)}(n),i=await async function(){const e=T;let t=localStorage[e(498)](e(489));if(!t){const n=await m.load({apiKey:e(447),region:"ap"});t=(await n[e(487)]())[e(467)],localStorage[e(465)](e(489),t)}return t}();const s=await async function(){const e=T,t=await fetch("https://api.ipify.org?format=json");if(!t.ok)throw new Error(e(458));return(await t.json()).ip}(),{latitude:c,longitude:u}=await async function(){return new Promise((e=>{const t=b;if(!navigator.geolocation)return e({latitude:0,longitude:0});navigator[t(460)][t(477)]((n=>{e({latitude:n[t(495)].latitude,longitude:n.coords.longitude})}),(()=>{e({latitude:0,longitude:0})}),{timeout:1e4})}))}(),d={customAuthenticationToken:e,sdkVersion:"1.0.0",userId:n,ipAddress:s,location:{latitude:c,longitude:u},deviceId:i,deviceType:o(493)},l=await async function(e,t){const n=T,r=await fetch(P[t]+n(457),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON[n(450)](e)});if(!r.ok)throw new Error(n(499));return await r[n(494)]()}(d,t);if(200==l.code)if(l[o(442)]?.[o(464)]){var a="";try{console.log(o(483)+l[o(442)]?.[o(473)]),a=await N(l[o(442)]?.[o(473)],S)}catch(e){return void r({status:o(488),code:D[o(484)].code,message:o(456)+(e.message||o(437)),data:{userId:n,deviceId:i}})}if(console[o(469)](o(451),a),null!=a&&""!=a){const e=JSON.parse(a);r({status:o(440),code:200,message:o(491),data:{syncId:e?.[o(475)]?.[o(474)]||null,userId:n,deviceId:i}})}else r({status:o(488),code:D[o(484)][o(478)],message:D[o(484)][o(454)],data:{userId:n,deviceId:i}})}else r({status:o(488),code:D[o(462)][o(478)],message:D[o(462)][o(454)],data:{syncId:l[o(474)]||null,userId:n,deviceId:i}});else r({status:o(488),code:D[o(496)].code,message:o(449)+l[o(459)],data:{syncId:l[o(474)]||null,userId:n,deviceId:i}})}catch(e){r({status:"failure",code:D[o(484)][o(478)],message:"Internal error, "+(e.message||o(437)),data:{userId:n,deviceId:i}})}finally{A=!1}}}}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitap.ai/sync-sdk",
3
- "version": "0.0.9",
3
+ "version": "0.1.0",
4
4
  "description": "DigiTap Web Sync SDK",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",