@digitap.ai/sync-sdk 0.0.2 → 0.0.4
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"),R="API key required",f="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],R=d[1];if(void 0===l)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var f=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=R(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 f(o)}))}))};return f(l).then((function(e){return[e,u]}))}var m="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";function O(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(
|
|
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"),R="API key required",f="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],R=d[1];if(void 0===l)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var f=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=R(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 f(o)}))}))};return f(l).then((function(e){return[e,u]}))}var m="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";function O(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(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,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(R);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),O)})).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:f,ERROR_API_KEY_MISSING:R,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:f,ERROR_TOKEN_MISSING:R,ERROR_UNSUPPORTED_VERSION:a,ERROR_WRONG_REGION:o,defaultEndpoint:{default:"endpoint"},defaultTlsEndpoint:{default:"tlsEndpoint"}};let g=!1;const h={dev:"https://apidev.digitap.work/sync/",stage:"https://apistage.digitap.work/sync/",uat:"https://apidemo.digitap.work/sync/",prod:"https://api.digitap.ai/sync/"},w={code:1001,message:"Invalid Input"},T={code:1002,message:"Internal Error, Try after some time"},N={code:1003,message:"Server Error, Try after some time"},P={code:1004,message:"Internet not connected"},S={code:1005,message:"Previous sms sync is in progress, please try after some time"},A={code:1006,message:"Sync disabled"};async function b(){return localStorage.getItem("userId")}var D={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:w.code,message:"Invalid userId",data:{userId:r||null,deviceId:null}});if(g)return n({status:"failure",code:S.code,message:"Previous sms sync is initiated for the user_id "+b()+", 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}});g=!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 _.load({apiKey:"w5EseVLxhpfRzzsVj0fl"});e=(await t.get()).visitorId,localStorage.setItem("sync_device_id",e)}return e}();const i=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:a,longitude:s}=await async function(){return new Promise((e=>{if(!navigator.geolocation)return e({latitude:-1,longitude:-1});navigator.geolocation.getCurrentPosition((t=>{e({latitude:t.coords.latitude,longitude:t.coords.longitude})}),(()=>{e({latitude:-1,longitude:-1})}),{timeout:1e4})}))}(),c={customAuthenticationToken:e,sdkVersion:"WEB_1.0.0",userId:r,ipAddress:i,latitude:a,longitude:s,deviceId:o},u=await async function(e,t){const r=await fetch(h[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()}(c,t);200==u.code?u.model?.isSyncEnabled?n({status:"success",code:200,message:"Sync Completed",data:{syncId:u.syncId||null,userId:r,deviceId:o}}):n({status:"failure",code:A.code,message:A.message,data:{syncId:u.syncId||null,userId:r,deviceId:o}}):n({status:"failure",code:N.code,message:"Server error, "+u.msg,data:{syncId:u.syncId||null,userId:r,deviceId:o}})}catch(e){n({status:"failure",code:T.code,message:"Internal error, "+(e.message||"Unexpected error"),data:{userId:r,deviceId:o}})}finally{g=!1}}};export{D 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"),R="API key required",f="API key not found",E="API key expired",p="Failed to load the JS script of the agent",I="9319";function _(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===p){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],R=d[1];if(void 0===l)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var f=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=R(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 f(o)}))}))};return f(l).then((function(e){return[e,u]}))}var O="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";function v(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(p))},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",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:O,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(R);return _(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),v)})).catch((function(e){throw d(),function(e){return e instanceof Error&&e.message===I?new Error(p):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:O,ERROR_SCRIPT_LOAD_FAIL:p,ERROR_API_KEY_EXPIRED:E,ERROR_API_KEY_INVALID:f,ERROR_API_KEY_MISSING:R,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:E,ERROR_TOKEN_INVALID:f,ERROR_TOKEN_MISSING:R,ERROR_UNSUPPORTED_VERSION:a,ERROR_WRONG_REGION:o,defaultEndpoint:{default:"endpoint"},defaultTlsEndpoint:{default:"tlsEndpoint"}};function y(e,t){const n=A();return(y=function(e,t){return n[e-=474]})(e,t)}const N=y;!function(e){const t=y,n=e();for(;;)try{if(705281===-parseInt(t(505))/1+parseInt(t(490))/2+-parseInt(t(495))/3*(parseInt(t(494))/4)+-parseInt(t(483))/5+-parseInt(t(516))/6+parseInt(t(525))/7+-parseInt(t(474))/8*(-parseInt(t(488))/9))break;n.push(n.shift())}catch(e){n.push(n.shift())}}(A);const g=N(520);let T=!1;const S={uat:N(509),prod:"https://api.digitap.ai/sync/"},w={INVALID_INPUT:{code:1001,message:N(524)},INTERNAL_ERROR:{code:1002,message:N(493)},SERVER_ERROR:{code:1003,message:N(479)},INTERNET_NOT_CONNECTED:{code:1004,message:"Internet not connected"},SYNC_IN_PROGRESS:{code:1005,message:N(491)},SYNC_DISABLED:{code:1006,message:N(510)},SYNC_CANCELLED:{code:1007,message:"Sync cancelled due to it took more time and another sync initiated"}};async function P(){const e=N;return localStorage.getItem(e(507))}function A(){const e=["4656294dHbmte","SYNC_IN_PROGRESS","1291292qJyoCl","Previous sms sync is in progress, please try after some time","trim","Internal Error, Try after some time","4yGfhiV","1467195DIzioz","stringify","INTERNAL_ERROR","longitude","syncId","failure","latitude","Failed to send data to API","getItem","geolocation","1261128KRbjBP","Server error, ","userId","msg","https://apidemo.digitap.work/sync/","Sync disabled","w5EseVLxhpfRzzsVj0fl","sdk/auth","code","message","getCurrentPosition","6825168zzZibd","replace","application/json","SERVER_ERROR","WEB_1.0.0","json","onLine","Sync Completed","Invalid Input","4155788JOXvIh","40OexPqR","get","SYNC_DISABLED","Internal error, ","load","Server Error, Try after some time","POST","setItem","INTERNET_NOT_CONNECTED","1165790qzANSX","visitorId","sync_device_id","coords","Invalid userId"];return(A=function(){return e})()}return{start:async function(e,t,n,r){const o=N;let i=null;try{if(!function(e){const t=N;return!(!e||""===String(e)[t(492)]()||isNaN(Number(e))||""===String(e)[t(517)](/^0+/,"").trim())}(n))return r({status:"error",code:w.INVALID_INPUT[o(513)],message:o(487),data:{userId:n||null,deviceId:null}});if(T)return r({status:o(500),code:w[o(489)][o(513)],message:"Previous sms sync is initiated for the user_id "+P()+", please try after some time",data:{userId:n,deviceId:i}});if(!navigator[o(522)])return r({status:"error",code:w[o(482)][o(513)],message:w.INTERNET_NOT_CONNECTED[o(514)],data:{userId:n,deviceId:i}});T=!0,async function(e){localStorage[N(481)]("userId",e)}(n),i=await async function(){const e=N;let t=localStorage[e(503)](e(485));if(!t){const n=await h[e(478)]({apiKey:e(511)});t=(await n[e(475)]())[e(484)],localStorage.setItem(e(485),t)}return t}();const a=await async function(){const e=N,t=await fetch("https://api.ipify.org?format=json");if(!t.ok)throw new Error("Failed to fetch IP address");return(await t[e(521)]()).ip}(),{latitude:s,longitude:c}=await async function(){return new Promise((e=>{const t=y;if(!navigator[t(504)])return e({latitude:-1,longitude:-1});navigator[t(504)][t(515)]((n=>{const r=t;e({latitude:n[r(486)][r(501)],longitude:n.coords[r(498)]})}),(()=>{e({latitude:-1,longitude:-1})}),{timeout:1e4})}))}(),u={customAuthenticationToken:e,sdkVersion:g,userId:n,ipAddress:a,latitude:s,longitude:c,deviceId:i},d=await async function(e,t){const n=N,r=await fetch(S[t]+n(512),{method:n(480),headers:{"Content-Type":n(518)},body:JSON[n(496)](e)});if(!r.ok)throw new Error(n(502));return await r[n(521)]()}(u,t);200==d[o(513)]?d.model?.isSyncEnabled?r({status:"success",code:200,message:o(523),data:{syncId:d[o(499)]||null,userId:n,deviceId:i}}):r({status:"failure",code:w.SYNC_DISABLED[o(513)],message:w[o(476)][o(514)],data:{syncId:d[o(499)]||null,userId:n,deviceId:i}}):r({status:o(500),code:w[o(519)].code,message:o(506)+d[o(508)],data:{syncId:d[o(499)]||null,userId:n,deviceId:i}})}catch(e){r({status:o(500),code:w[o(497)][o(513)],message:o(477)+(e[o(514)]||"Unexpected error"),data:{userId:n,deviceId:i}})}finally{T=!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"),R="API key required",f="API key not found",E="API key expired",p="Failed to load the JS script of the agent",I="9319";function _(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===p){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],R=d[1];if(void 0===l)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var f=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=R(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 f(o)}))}))};return f(l).then((function(e){return[e,u]}))}var v="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";function O(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(p))},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",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 y={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(R);return _(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),O)})).catch((function(e){throw d(),function(e){return e instanceof Error&&e.message===I?new Error(p):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:p,ERROR_API_KEY_EXPIRED:E,ERROR_API_KEY_INVALID:f,ERROR_API_KEY_MISSING:R,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:E,ERROR_TOKEN_INVALID:f,ERROR_TOKEN_MISSING:R,ERROR_UNSUPPORTED_VERSION:a,ERROR_WRONG_REGION:o,defaultEndpoint:{default:"endpoint"},defaultTlsEndpoint:{default:"tlsEndpoint"}};const h=N;function N(e,t){const n=g();return(N=function(e,t){return n[e-=454]})(e,t)}!function(e){const t=N,n=e();for(;;)try{if(640578===-parseInt(t(496))/1+-parseInt(t(469))/2+parseInt(t(466))/3+-parseInt(t(454))/4+parseInt(t(482))/5*(parseInt(t(457))/6)+-parseInt(t(473))/7+parseInt(t(471))/8)break;n.push(n.shift())}catch(e){n.push(n.shift())}}(g);function g(){const e=["https://apistage.digitap.work/sync/","Previous sms sync is in progress, please try after some time","https://apidev.digitap.work/sync/","model","3981772BkRyZQ","Sync Completed","SYNC_IN_PROGRESS","6702Tmrdai","Server Error, Try after some time","w5EseVLxhpfRzzsVj0fl","Failed to fetch IP address","geolocation","syncId","failure","replace","longitude","1866156EcQqLH","Server error, ","visitorId","2134328CNsNHm","json","13432616PeXXMI","Internal error, ","3959221FkvJlL","success","Failed to send data to API","Previous sms sync is initiated for the user_id ","https://apidemo.digitap.work/sync/","Sync cancelled due to it took more time and another sync initiated","code","INTERNET_NOT_CONNECTED","message","4425sEkOtk","INTERNAL_ERROR","SERVER_ERROR","stringify","Unexpected error",", please try after some time","getItem","trim","https://api.ipify.org?format=json","get","isSyncEnabled","latitude","Sync disabled","msg","20886DmfucY","error","INVALID_INPUT","sdk/auth","coords","getCurrentPosition","userId","sync_device_id","application/json"];return(g=function(){return e})()}let T=!1;const w={dev:h(507),stage:h(505),uat:h(477),prod:"https://api.digitap.ai/sync/"},S={INVALID_INPUT:{code:1001,message:"Invalid Input"},INTERNAL_ERROR:{code:1002,message:"Internal Error, Try after some time"},SERVER_ERROR:{code:1003,message:h(458)},INTERNET_NOT_CONNECTED:{code:1004,message:"Internet not connected"},SYNC_IN_PROGRESS:{code:1005,message:h(506)},SYNC_DISABLED:{code:1006,message:h(494)},SYNC_CANCELLED:{code:1007,message:h(478)}};async function P(){const e=h;return localStorage[e(488)](e(502))}return{start:async function(e,t,n,r){const o=h;let i=null;try{if(!function(e){const t=h;return!(!e||""===String(e)[t(489)]()||isNaN(Number(e))||""===String(e)[t(464)](/^0+/,"")[t(489)]())}(n))return r({status:"error",code:S[o(498)][o(479)],message:"Invalid userId",data:{userId:n||null,deviceId:null}});if(T)return r({status:"failure",code:S[o(456)][o(479)],message:o(476)+P()+o(487),data:{userId:n,deviceId:i}});if(!navigator.onLine)return r({status:o(497),code:S[o(480)].code,message:S[o(480)].message,data:{userId:n,deviceId:i}});T=!0,async function(e){const t=h;localStorage.setItem(t(502),e)}(n),i=await async function(){const e=h;let t=localStorage.getItem("sync_device_id");if(!t){const n=await y.load({apiKey:e(459)});t=(await n[e(491)]())[e(468)],localStorage.setItem(e(503),t)}return t}();const a=await async function(){const e=h,t=await fetch(e(490));if(!t.ok)throw new Error(e(460));return(await t[e(470)]()).ip}(),{latitude:s,longitude:c}=await async function(){return new Promise((e=>{const t=N;if(!navigator[t(461)])return e({latitude:-1,longitude:-1});navigator[t(461)][t(501)]((n=>{const r=t;e({latitude:n[r(500)][r(493)],longitude:n[r(500)][r(465)]})}),(()=>{e({latitude:-1,longitude:-1})}),{timeout:1e4})}))}(),u={customAuthenticationToken:e,sdkVersion:"WEB_1.0.0",userId:n,ipAddress:a,latitude:s,longitude:c,deviceId:i},d=await async function(e,t){const n=h,r=await fetch(w[t]+n(499),{method:"POST",headers:{"Content-Type":n(504)},body:JSON[n(485)](e)});if(!r.ok)throw new Error(n(475));return await r.json()}(u,t);200==d[o(479)]?d[o(508)]?.[o(492)]?r({status:o(474),code:200,message:o(455),data:{syncId:d[o(462)]||null,userId:n,deviceId:i}}):r({status:o(463),code:S.SYNC_DISABLED[o(479)],message:S.SYNC_DISABLED[o(481)],data:{syncId:d.syncId||null,userId:n,deviceId:i}}):r({status:o(463),code:S[o(484)][o(479)],message:o(467)+d[o(495)],data:{syncId:d[o(462)]||null,userId:n,deviceId:i}})}catch(e){r({status:o(463),code:S[o(483)].code,message:o(472)+(e[o(481)]||o(486)),data:{userId:n,deviceId:i}})}finally{T=!1}}}}));
|