@digitap.ai/sync-sdk 0.1.2 → 0.1.3

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"),a=n("SubscriptionNotActive"),i=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,a,i,s,c,u=[],d=(o=function(e){var t=function(e,t,r){if(r||2===arguments.length)for(var n,o=0,a=t.length;o<a;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,a=function(){return Math.random()*Math.min(3e3,100*Math.pow(2,s++))},i=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&&!i.has(d)&&(i.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()+a()-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],a=r[1];return(n=a,new Promise((function(e){return setTimeout(e,n)}))).then((function(){return R(o)}))}))};return R(l).then((function(e){return[e,u]}))}var g="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";function m(e){return function(e,t,r,n){var o,a=document,i="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())};a.addEventListener(i,s);var c=function(){return a.removeEventListener(i,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"),a=function(){var e;return null===(e=o.parentNode)||void 0===e?void 0:e.removeChild(o)},i=document.head||document.getElementsByTagName("head")[0];o.onload=function(){a(),t()},o.onerror=function(){a(),n(new Error(E))},o.async=!0,o.src=e,i.appendChild(o)}))}(e)}),(function(){throw new Error(t)})).then(y)}function y(){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 _={load:function(t){var r;t.scriptUrlPattern;var n=t.token,o=t.apiKey,a=void 0===o?n:o,i=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:g,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(!a||"string"!=typeof a)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,a),m)})).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({},i),{ldi:{attempts:n,visibilityStates:u}}))}))},defaultScriptUrlPattern:g,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:a,ERROR_TOKEN_EXPIRED:p,ERROR_TOKEN_INVALID:R,ERROR_TOKEN_MISSING:f,ERROR_UNSUPPORTED_VERSION:i,ERROR_WRONG_REGION:o,defaultEndpoint:{default:"endpoint"},defaultTlsEndpoint:{default:"tlsEndpoint"}};async function O(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),a=n.slice(12),i=(new TextEncoder).encode(t),s=await crypto.subtle.importKey("raw",i,{name:"AES-GCM"},!1,["decrypt"]),c=await crypto.subtle.decrypt({name:"AES-GCM",iv:o,tagLength:128},s,a);return(new TextDecoder).decode(c)}catch(e){return console.error("Decryption error:",e),null}}let h=!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="",a="";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(({deviceId:o,userAgent:a}=await async function(){let e=localStorage.getItem("sync_device_id"),t=localStorage.getItem("sync_user_agent");if(!e){const r=await _.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}}()),h)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}});h=!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:a},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 i="";try{console.log("data:"+l.model?.data),i=await O(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:",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: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{h=!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 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};
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 v="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(E))},o.async=!0,o.src=e,a.appendChild(o)}))}(e)}),(function(){throw new Error(t)})).then(_)}function _(){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:v,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),g)})).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: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: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 h(){const e=["246522qKYLFd","decrypt","Decryption error:","encode","slice","6222804RyKBLA","repeat","6007095GocEHO","length","64698eelxTD","charCodeAt","importKey","raw","error","set","byteLength","from","5246850sNwZNJ","130qLbCwC","replace","AES-GCM","subtle","fromCharCode","4115560gCEZso","6XUIAVT","join","getRandomValues","147732WvlCRs","encrypt"];return(h=function(){return e})()}function O(e,t){const n=h();return(O=function(e,t){return n[e-=242]})(e,t)}async function N(e,t){const n=O;try{const r=e[n(261)](/-/g,"+")[n(261)](/_/g,"/"),o=function(e){const t=O,n=atob(e);return Uint8Array[t(258)](n,(e=>e[t(252)](0)))}(r+"="[n(248)]((4-r.length%4)%4)),i=o[n(246)](0,12),a=o[n(246)](12),s=(new TextEncoder)[n(245)](t),c=await crypto[n(263)][n(253)](n(254),s,{name:n(262)},!1,["decrypt"]),u=await crypto[n(263)][n(243)]({name:n(262),iv:i,tagLength:128},c,a);return(new TextDecoder).decode(u)}catch(e){return console[n(255)](n(244),e),null}}function T(e,t){const n=b();return(T=function(e,t){return n[e-=330]})(e,t)}!function(e){const t=O,n=e();for(;;)try{if(524993===-parseInt(t(242))/1*(-parseInt(t(266))/2)+parseInt(t(251))/3+parseInt(t(269))/4*(parseInt(t(260))/5)+parseInt(t(259))/6+-parseInt(t(247))/7+-parseInt(t(265))/8+-parseInt(t(249))/9)break;n.push(n.shift())}catch(e){n.push(n.shift())}}(h);const w=T;!function(e){const t=T,n=e();for(;;)try{if(473124===-parseInt(t(330))/1+-parseInt(t(390))/2*(-parseInt(t(355))/3)+parseInt(t(387))/4+-parseInt(t(363))/5*(parseInt(t(368))/6)+-parseInt(t(381))/7+parseInt(t(372))/8*(parseInt(t(374))/9)+-parseInt(t(345))/10)break;n.push(n.shift())}catch(e){n.push(n.shift())}}(b);const S=w(362);let A=!1;const P={dev:w(367),stage:"https://apistage.digitap.work/sync/",uat:w(385),prod:"https://api.digitap.ai/sync/"},D={INVALID_INPUT:{code:1001,message:w(332)},INTERNAL_ERROR:{code:1002,message:w(339)},SERVER_ERROR:{code:1003,message:w(331)},INTERNET_NOT_CONNECTED:{code:1004,message:w(340)},SYNC_IN_PROGRESS:{code:1005,message:w(358)},SYNC_DISABLED:{code:1006,message:w(334)},SYNC_CANCELLED:{code:1007,message:w(356)}};async function C(){const e=w;return localStorage.getItem(e(347))}function b(){const e=["Sync cancelled due to it took more time and another sync initiated","visitorId","Previous sms sync is in progress, please try after some time","Internal error, ","trim","SYNC_IN_PROGRESS","1.0.0","355YqDZoY","value","setItem","log","https://api.digitap.work/sync/","17070yDFuop","Unexpected error","SYNC_DISABLED","Previous sms sync is initiated for the user_id ","16voxxfy","Failed to fetch IP address","4182471ubpnwy","error","sync_user_agent","data","longitude","Decrypted:","parse","575918UzdNYk","Invalid userId","msg","load","https://apidemo.digitap.work/sync/","failure","2292216AauzLy","json","INTERNAL_ERROR","10EbIFtt","userAgent","stringify","146908TPFcse","Server Error, Try after some time","Invalid Input","INVALID_INPUT","Sync disabled","SERVER_ERROR","data:","success","coords","Internal Error, Try after some time","Internet not connected","replace","get","code","getItem","10125560mfPPov","syncConfig","userId","message","syncId","POST","Sync Completed","onLine","model","sdk/auth","248619SUpBXb"];return(b=function(){return e})()}return{start:async function(e,t,n,r){const o=w;var i="",a="";try{if(!function(e){const t=w;return!(!e||""===String(e)[t(360)]()||isNaN(Number(e))||""===String(e)[t(341)](/^0+/,"")[t(360)]())}(n))return r({status:o(375),code:D[o(333)].code,message:o(382),data:{userId:n||null,deviceId:null}});if(({deviceId:i,userAgent:a}=await async function(){const e=w;let t=localStorage[e(344)]("sync_device_id"),n=localStorage.getItem(e(376));if(!t){const r=await m[e(384)]({apiKey:"w5EseVLxhpfRzzsVj0fl",region:"ap"}),o=await r[e(342)]();t=o?.[e(357)],n=o?.components?.[e(391)]?.[e(364)]||navigator?.userAgent,localStorage.setItem("sync_device_id",t),localStorage[e(365)](e(376),n)}return{deviceId:t,userAgent:n}}()),A)return r({status:o(386),code:D[o(361)][o(343)],message:o(371)+C()+", please try after some time",data:{userId:n,deviceId:i}});if(!navigator[o(352)])return r({status:"error",code:D.INTERNET_NOT_CONNECTED[o(343)],message:D.INTERNET_NOT_CONNECTED[o(348)],data:{userId:n,deviceId:i}});A=!0,async function(e){const t=w;localStorage[t(365)](t(347),e)}(n);const c=await async function(){const e=w,t=await fetch("https://api.ipify.org?format=json");if(!t.ok)throw new Error(e(373));return(await t[e(388)]()).ip}(),{latitude:u,longitude:d}=await async function(){return new Promise((e=>{if(!navigator.geolocation)return e({latitude:0,longitude:0});navigator.geolocation.getCurrentPosition((t=>{const n=T;e({latitude:t.coords.latitude,longitude:t[n(338)][n(378)]})}),(()=>{e({latitude:0,longitude:0})}),{timeout:1e4})}))}(),l={customAuthenticationToken:e,sdkVersion:S,userId:n,ipAddress:c,location:{latitude:u,longitude:d},deviceId:i,deviceType:"WEB",userAgent:a},f=await async function(e,t){const n=w,r=await fetch(P[t]+n(354),{method:n(350),headers:{"Content-Type":"application/json"},body:JSON[n(392)](e)});if(!r.ok)throw new Error("Failed to send data to API");return await r[n(388)]()}(l,t);if(200==f[o(343)])if(f.model?.isSyncEnabled){var s="";try{console[o(366)](o(336)+f[o(353)]?.[o(377)]),s=await N(f.model?.[o(377)],"PpwCKmkiEE8Q0O0FmbpZ90ZbdNypVhkp")}catch(e){return void r({status:o(386),code:D[o(389)].code,message:o(359)+(e[o(348)]||"Unexpected error"),data:{userId:n,deviceId:i}})}if(console.log(o(379),s),null!=s&&""!=s){const e=JSON[o(380)](s);r({status:o(337),code:200,message:o(351),data:{syncId:e?.[o(346)]?.[o(349)]||null,userId:n,deviceId:i}})}else r({status:"failure",code:D[o(389)][o(343)],message:D[o(389)].message,data:{userId:n,deviceId:i}})}else r({status:o(386),code:D.SYNC_DISABLED[o(343)],message:D[o(370)][o(348)],data:{syncId:f[o(349)]||null,userId:n,deviceId:i}});else r({status:o(386),code:D[o(335)][o(343)],message:"Server error, "+f[o(383)],data:{syncId:f[o(349)]||null,userId:n,deviceId:i}})}catch(e){r({status:o(386),code:D[o(389)][o(343)],message:"Internal error, "+(e[o(348)]||o(369)),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",p="API key not found",R="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 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 v="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(E))},o.async=!0,o.src=e,a.appendChild(o)}))}(e)}),(function(){throw new Error(t)})).then(_)}function _(){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 h={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:v,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),g)})).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:v,ERROR_SCRIPT_LOAD_FAIL:E,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 O(e,t){const n=m();return(O=function(e,t){return n[e-=422]})(e,t)}function m(){const e=["Decryption error:","join","3811026wiKeGX","encode","byteLength","decode","Encryption error:","8ltXuoN","1775110bGCYrp","error","set","encrypt","raw","length","8994337JXUZii","3230101AGpnsF","AES-GCM","replace","6341607Uwjifv","4anbSvG","importKey","decrypt","fromCharCode","72XbWYlw","10IlsjJZ","slice","subtle","from","400248YGeOcs","8639xWTbUE"];return(m=function(){return e})()}async function N(e,t){const n=O;try{const r=e.replace(/-/g,"+")[n(442)](/_/g,"/"),o=function(e){const t=O,n=atob(e);return Uint8Array[t(422)](n,(e=>e.charCodeAt(0)))}(r+"=".repeat((4-r[n(438)]%4)%4)),i=o.slice(0,12),a=o[n(450)](12),s=(new TextEncoder).encode(t),c=await crypto.subtle[n(445)](n(437),s,{name:"AES-GCM"},!1,[n(446)]),u=await crypto.subtle.decrypt({name:n(441),iv:i,tagLength:128},c,a);return(new TextDecoder)[n(430)](u)}catch(e){return console[n(434)](n(425),e),null}}!function(e){const t=O,n=e();for(;;)try{if(471926===parseInt(t(424))/1*(parseInt(t(448))/2)+-parseInt(t(423))/3+parseInt(t(444))/4*(parseInt(t(433))/5)+-parseInt(t(427))/6+parseInt(t(440))/7*(parseInt(t(432))/8)+parseInt(t(443))/9*(-parseInt(t(449))/10)+parseInt(t(439))/11)break;n.push(n.shift())}catch(e){n.push(n.shift())}}(m);const T=D;!function(e){const t=D,n=e();for(;;)try{if(566571===parseInt(t(399))/1*(parseInt(t(375))/2)+parseInt(t(425))/3+parseInt(t(386))/4+parseInt(t(384))/5*(-parseInt(t(369))/6)+-parseInt(t(385))/7+parseInt(t(363))/8+-parseInt(t(381))/9)break;n.push(n.shift())}catch(e){n.push(n.shift())}}(L);const w=T(382),S=T(393);let A=!1;const P={dev:T(371),stage:T(377),uat:"https://apidemo.digitap.work/sync/",prod:T(407)},b={INVALID_INPUT:{code:1001,message:T(412)},INTERNAL_ERROR:{code:1002,message:"Internal Error, Try after some time"},SERVER_ERROR:{code:1003,message:"Server Error, Try after some time"},INTERNET_NOT_CONNECTED:{code:1004,message:T(387)},SYNC_IN_PROGRESS:{code:1005,message:T(392)},SYNC_DISABLED:{code:1006,message:T(417)},SYNC_CANCELLED:{code:1007,message:T(361)}};function D(e,t){const n=L();return(D=function(e,t){return n[e-=358]})(e,t)}async function C(){const e=T;return localStorage[e(389)](e(404))}function L(){const e=["Invalid userId","-9223372036854775808","3900843Ldwpqm","1.0.0","Server error, ","3340ElyFYn","843437xZMzlW","198948NZMuKo","Internet not connected","json","getItem","SERVER_ERROR","msg","Previous sms sync is in progress, please try after some time","w5EseVLxhpfRzzsVj0fl","INTERNAL_ERROR","application/json","load","model","data","11yYMPmv","parse","length","Sync Completed","error","userId","stringify","Internal error, ","https://api.digitap.ai/sync/","syncId","Unexpected error","sync_device_id","isSyncEnabled","Invalid Input","trim","test","9223372036854775807","data:","Sync disabled","SYNC_IN_PROGRESS","Previous sms sync is initiated for the user_id ","components","syncConfig","coords","geolocation","getCurrentPosition","82152XIDQrO","code","Failed to fetch IP address","sync_user_agent","Sync cancelled due to it took more time and another sync initiated","message","3404616HokQor","failure","SYNC_DISABLED","sdk/auth","WEB","setItem","3582sqILjk","log","https://api.digitap.work/sync/","get",", please try after some time","latitude","184834LyOyOV","success","https://apistage.digitap.work/sync/","visitorId"];return(L=function(){return e})()}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(413)]();if(!n)return!1;if(!/^\d+$/[t(414)](n))return!1;try{if(e[t(401)]<18)return!0;{const e=BigInt(n),r=BigInt(t(380)),o=BigInt(t(415));return e>=r&&e<=o}}catch{return!1}}(n))return r({status:o(403),code:b.INVALID_INPUT[o(358)],message:o(379),data:{userId:n||null,deviceId:null}});if(({deviceId:i,userAgent:a}=await async function(){const e=T;let t=localStorage[e(389)](e(410)),n=localStorage[e(389)]("sync_user_agent");if(!t){const r=await h[e(396)]({apiKey:S,region:"ap"}),o=await r[e(372)]();t=o?.[e(378)],n=o?.[e(420)]?.userAgent?.value||navigator?.userAgent,localStorage.setItem(e(410),t),localStorage[e(368)](e(360),n)}return{deviceId:t,userAgent:n}}()),A)return r({status:"failure",code:b[o(418)][o(358)],message:o(419)+C()+o(373),data:{userId:n,deviceId:i}});if(!navigator.onLine)return r({status:"error",code:b.INTERNET_NOT_CONNECTED[o(358)],message:b.INTERNET_NOT_CONNECTED[o(362)],data:{userId:n,deviceId:i}});A=!0,async function(e){const t=T;localStorage[t(368)](t(404),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(e(359));return(await t[e(388)]()).ip}(),{latitude:u,longitude:d}=await async function(){return new Promise((e=>{const t=D;if(!navigator[t(423)])return e({latitude:0,longitude:0});navigator[t(423)][t(424)]((n=>{const r=t;e({latitude:n[r(422)][r(374)],longitude:n[r(422)].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(367),userAgent:a},f=await async function(e,t){const n=T,r=await fetch(P[t]+n(366),{method:"POST",headers:{"Content-Type":n(395)},body:JSON[n(405)](e)});if(!r.ok)throw new Error("Failed to send data to API");return await r.json()}(l,t);if(200==f[o(358)])if(f[o(397)]?.[o(411)]){var s="";try{console[o(370)](o(416)+f[o(397)]?.data),s=await N(f[o(397)]?.[o(398)],"PpwCKmkiEE8Q0O0FmbpZ90ZbdNypVhkp")}catch(e){return void r({status:o(364),code:b.INTERNAL_ERROR[o(358)],message:o(406)+(e[o(362)]||o(409)),data:{userId:n,deviceId:i}})}if(console[o(370)]("Decrypted:",s),null!=s&&""!=s){const e=JSON[o(400)](s);r({status:o(376),code:200,message:o(402),data:{syncId:e?.[o(421)]?.[o(408)]||null,userId:n,deviceId:i}})}else r({status:o(364),code:b[o(394)][o(358)],message:b[o(394)][o(362)],data:{userId:n,deviceId:i}})}else r({status:o(364),code:b[o(365)][o(358)],message:b[o(365)][o(362)],data:{syncId:f[o(408)]||null,userId:n,deviceId:i}});else r({status:o(364),code:b[o(390)][o(358)],message:o(383)+f[o(391)],data:{syncId:f[o(408)]||null,userId:n,deviceId:i}})}catch(e){r({status:o(364),code:b[o(394)][o(358)],message:o(406)+(e.message||"Unexpected error"),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.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "DigiTap Web Sync SDK",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",