New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

offline-sync-handler-test

Package Overview
Dependencies
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

offline-sync-handler-test - npm Package Compare versions

Comparing version 0.1.67 to 0.1.68

21

dist/offline-sync-handler-test.cjs.development.js

@@ -586,2 +586,6 @@ 'use strict';

storedRequests = _context.t0;
console.log("perform stored", {
req: storedRequests,
length: storedRequests.length
});
if (apiConfig != null && apiConfig.isFormdata && (apiConfig == null ? void 0 : apiConfig.data) instanceof FormData) {

@@ -596,16 +600,19 @@ // console.log({ apiConfig })

}
_context.next = 11;
console.log("perform stored after:", {
storedRequests: storedRequests
});
_context.next = 13;
return localForage.setItem(API_REQUESTS_STORAGE_KEY$1, storedRequests);
case 11:
_context.next = 16;
case 13:
_context.next = 18;
break;
case 13:
_context.prev = 13;
case 15:
_context.prev = 15;
_context.t1 = _context["catch"](0);
console.error('Error saving API request for offline:', _context.t1);
case 16:
case 18:
case "end":
return _context.stop();
}
}, _callee, null, [[0, 13]]);
}, _callee, null, [[0, 15]]);
}));

@@ -612,0 +619,0 @@ return function saveRequestToOfflineStorage(_x) {

@@ -1,2 +0,2 @@

"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=t(e),n=t(require("axios")),o=t(require("localforage")),a=require("underscore");function i(){i=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,n=Object.defineProperty||function(t,e,r){t[e]=r.value},o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",u=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function l(t,e,r,o){var a=Object.create((e&&e.prototype instanceof h?e:h).prototype),i=new S(o||[]);return n(a,"_invoke",{value:E(t,r,i)}),a}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=l;var p={};function h(){}function v(){}function d(){}var y={};s(y,a,(function(){return this}));var g=Object.getPrototypeOf,m=g&&g(g(j([])));m&&m!==e&&r.call(m,a)&&(y=m);var w=d.prototype=h.prototype=Object.create(y);function x(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){var o;n(this,"_invoke",{value:function(n,a){function i(){return new e((function(o,i){!function n(o,a,i,u){var c=f(t[o],t,a);if("throw"!==c.type){var s=c.arg,l=s.value;return l&&"object"==typeof l&&r.call(l,"__await")?e.resolve(l.__await).then((function(t){n("next",t,i,u)}),(function(t){n("throw",t,i,u)})):e.resolve(l).then((function(t){s.value=t,i(s)}),(function(t){return n("throw",t,i,u)}))}u(c.arg)}(n,a,o,i)}))}return o=o?o.then(i,i):i()}})}function E(t,e,r){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return{value:void 0,done:!0}}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var u=L(i,r);if(u){if(u===p)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=f(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===p)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function L(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,L(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),p;var o=f(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,p;var a=o.arg;return a?a.done?(e[t.resultName]=a.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function k(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function O(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function j(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:q}}function q(){return{value:void 0,done:!0}}return v.prototype=d,n(w,"constructor",{value:d,configurable:!0}),n(d,"constructor",{value:v,configurable:!0}),v.displayName=s(d,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===v||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,s(t,c,"GeneratorFunction")),t.prototype=Object.create(w),t},t.awrap=function(t){return{__await:t}},x(b.prototype),s(b.prototype,u,(function(){return this})),t.AsyncIterator=b,t.async=function(e,r,n,o,a){void 0===a&&(a=Promise);var i=new b(l(e,r,n,o),a);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},x(w),s(w,c,"Generator"),s(w,a,(function(){return this})),s(w,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=j,S.prototype={constructor:S,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(O),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return i.type="throw",i.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=r.call(a,"catchLoc"),c=r.call(a,"finallyLoc");if(u&&c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,p):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),p},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),O(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;O(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:j(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}function u(t,e,r,n,o,a,i){try{var u=t[a](i),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function c(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var a=t.apply(e,r);function i(t){u(a,n,o,i,c,"next",t)}function c(t){u(a,n,o,i,c,"throw",t)}i(void 0)}))}}function s(){return(s=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function l(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function f(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return l(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?l(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var p=e.createContext(null),h=function(){var t=c(i().mark((function t(){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,o.getItem("apiRequests");case 3:return t.abrupt("return",t.sent);case 6:return t.prev=6,t.t0=t.catch(0),console.error("Error getting stored API requests:",t.t0),t.abrupt("return",[]);case 10:case"end":return t.stop()}}),t,null,[[0,6]])})));return function(){return t.apply(this,arguments)}}(),v=function(){var t=c(i().mark((function t(e){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,o.setItem("apiRequests",e);case 3:t.next=8;break;case 5:t.prev=5,t.t0=t.catch(0),console.error("Error setting store :",t.t0);case 8:case"end":return t.stop()}}),t,null,[[0,5]])})));return function(e){return t.apply(this,arguments)}}(),d=function(){var t=c(i().mark((function t(){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,o.removeItem("apiRequests");case 3:t.next=8;break;case 5:t.prev=5,t.t0=t.catch(0),console.error("Error clearing stored API requests:",t.t0);case 8:case"end":return t.stop()}}),t,null,[[0,5]])})));return function(){return t.apply(this,arguments)}}();function y(t){var e={};return t.forEach((function(t,r){e.hasOwnProperty(r)?(Array.isArray(e[r])||(e[r]=[e[r]]),e[r].push(t)):e[r]=t})),e}function g(t){var e=new FormData,r=function(r){if(Object.hasOwnProperty.call(t,r)){var n=t[r];Array.isArray(n)?n.forEach((function(t){return e.append(r,t)})):e.append(r,n)}};for(var n in t)r(n);return e.forEach((function(t,e){console.log("formdata",e+" "+t)})),e}var m=n.create();exports.OfflineSyncProvider=function(t){var n,u,l=t.children,w=t.render,x=t.onStatusChange,b=t.onCallback,E=e.useState({}),L=E[0],k=E[1],O=e.useState(null==(n=null==(u=window)||null==(u=u.navigator)?void 0:u.onLine)||n),S=O[0],j=O[1];e.useEffect((function(){if(window&&"undefined"!=typeof window)return window.addEventListener("online",q),window.addEventListener("offline",P),function(){window.removeEventListener("offline",P),window.removeEventListener("online",q)}}),[]);var q=e.useCallback((function(){I(!1),F()}),[]),P=function(){I(!0)},I=function(t){void 0===t&&(t=!0);var e=!t;null==x||x({isOnline:e}),j(e)};e.useEffect((function(){F()}),[]);var _=function(){var t=c(i().mark((function t(e){var r;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,console.log("perform save",{request:e.meta.citizenId}),t.next=4,o.getItem("apiRequests");case 4:if(t.t0=t.sent,t.t0){t.next=7;break}t.t0=[];case 7:return r=t.t0,null!=e&&e.isFormdata&&(null==e?void 0:e.data)instanceof FormData?r.push(a.omit(s({},e,{data:y(e.data)}),"onSuccess")):(console.log("Saving request normally"),r.push(a.omit(s({},e),"onSuccess"))),t.next=11,o.setItem("apiRequests",r);case 11:t.next=16;break;case 13:t.prev=13,t.t1=t.catch(0),console.error("Error saving API request for offline:",t.t1);case 16:case"end":return t.stop()}}),t,null,[[0,13]])})));return function(e){return t.apply(this,arguments)}}(),A=function(){var t=c(i().mark((function t(e){var r,n;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(t.prev=0,console.log("perform",{request:e.meta.citizenId}),null==e||!e.isFormdata||(null==e?void 0:e.data)instanceof FormData){t.next=9;break}return n=s({},e,{data:g(e.data)}),t.next=6,m.request(n);case 6:r=t.sent,t.next=12;break;case 9:return t.next=11,m.request(e);case 11:r=t.sent;case 12:return b&&b({config:e,data:r,sendRequest:C}),t.abrupt("return",r.data);case 16:if(t.prev=16,t.t0=t.catch(0),console.log("packageError",{error:t.t0}),!(e.retryCount<1)){t.next=26;break}return t.next=22,new Promise((function(t){return setTimeout(t,1e3)}));case 22:return e.retryCount++,t.abrupt("return",A(e));case 26:return t.next=28,_(e);case 28:case"end":return t.stop()}}),t,null,[[0,16]])})));return function(e){return t.apply(this,arguments)}}(),C=function(){var t=c(i().mark((function t(e){var r;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,e.retryCount=null!=(r=e.retryCount)?r:0,e.id=String(Date.now().toString(32)+Math.random().toString(16)).replace(/\./g,""),t.next=5,A(e);case 5:return t.abrupt("return",t.sent);case 8:throw t.prev=8,t.t0=t.catch(0),t.t0;case 11:case"end":return t.stop()}}),t,null,[[0,8]])})));return function(e){return t.apply(this,arguments)}}(),F=function(){var t=c(i().mark((function t(){var e,r,n,a,u;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,h();case 2:if((e=t.sent)&&0!==e.length){t.next=5;break}return t.abrupt("return");case 5:r=[].concat(e),n=i().mark((function t(){var e,n;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!(e=u.value)){t.next=16;break}return t.prev=2,t.next=5,A(e);case 5:n=r.filter((function(t){return t.id!==e.id})),r.splice.apply(r,[0,r.length].concat(n)),t.next=12;break;case 9:t.prev=9,t.t0=t.catch(2),console.log({error:t.t0});case 12:return t.prev=12,t.next=15,o.setItem("apiRequests",r);case 15:return t.finish(12);case 16:case"end":return t.stop()}}),t,null,[[2,9,12,16]])})),a=f(e);case 8:if((u=a()).done){t.next=12;break}return t.delegateYield(n(),"t0",10);case 10:t.next=8;break;case 12:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}();return r.createElement(r.Fragment,null,r.createElement(p.Provider,{value:{data:L,setData:k,sendRequest:C,clearStoredRequests:d,getStoredRequests:h,setStorage:v}},null==w?void 0:w({isOnline:S}),l))},exports.useOfflineSyncContext=function(){return e.useContext(p)};
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=t(e),n=t(require("axios")),o=t(require("localforage")),a=require("underscore");function i(){i=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,n=Object.defineProperty||function(t,e,r){t[e]=r.value},o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",u=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function l(t,e,r,o){var a=Object.create((e&&e.prototype instanceof h?e:h).prototype),i=new S(o||[]);return n(a,"_invoke",{value:E(t,r,i)}),a}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=l;var p={};function h(){}function v(){}function d(){}var y={};s(y,a,(function(){return this}));var g=Object.getPrototypeOf,m=g&&g(g(q([])));m&&m!==e&&r.call(m,a)&&(y=m);var w=d.prototype=h.prototype=Object.create(y);function x(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){var o;n(this,"_invoke",{value:function(n,a){function i(){return new e((function(o,i){!function n(o,a,i,u){var c=f(t[o],t,a);if("throw"!==c.type){var s=c.arg,l=s.value;return l&&"object"==typeof l&&r.call(l,"__await")?e.resolve(l.__await).then((function(t){n("next",t,i,u)}),(function(t){n("throw",t,i,u)})):e.resolve(l).then((function(t){s.value=t,i(s)}),(function(t){return n("throw",t,i,u)}))}u(c.arg)}(n,a,o,i)}))}return o=o?o.then(i,i):i()}})}function E(t,e,r){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return{value:void 0,done:!0}}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var u=L(i,r);if(u){if(u===p)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=f(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===p)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function L(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,L(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),p;var o=f(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,p;var a=o.arg;return a?a.done?(e[t.resultName]=a.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function k(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function O(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function q(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:j}}function j(){return{value:void 0,done:!0}}return v.prototype=d,n(w,"constructor",{value:d,configurable:!0}),n(d,"constructor",{value:v,configurable:!0}),v.displayName=s(d,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===v||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,s(t,c,"GeneratorFunction")),t.prototype=Object.create(w),t},t.awrap=function(t){return{__await:t}},x(b.prototype),s(b.prototype,u,(function(){return this})),t.AsyncIterator=b,t.async=function(e,r,n,o,a){void 0===a&&(a=Promise);var i=new b(l(e,r,n,o),a);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},x(w),s(w,c,"Generator"),s(w,a,(function(){return this})),s(w,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=q,S.prototype={constructor:S,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(O),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return i.type="throw",i.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=r.call(a,"catchLoc"),c=r.call(a,"finallyLoc");if(u&&c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,p):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),p},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),O(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;O(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:q(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}function u(t,e,r,n,o,a,i){try{var u=t[a](i),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function c(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var a=t.apply(e,r);function i(t){u(a,n,o,i,c,"next",t)}function c(t){u(a,n,o,i,c,"throw",t)}i(void 0)}))}}function s(){return(s=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function l(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function f(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return l(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?l(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var p=e.createContext(null),h=function(){var t=c(i().mark((function t(){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,o.getItem("apiRequests");case 3:return t.abrupt("return",t.sent);case 6:return t.prev=6,t.t0=t.catch(0),console.error("Error getting stored API requests:",t.t0),t.abrupt("return",[]);case 10:case"end":return t.stop()}}),t,null,[[0,6]])})));return function(){return t.apply(this,arguments)}}(),v=function(){var t=c(i().mark((function t(e){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,o.setItem("apiRequests",e);case 3:t.next=8;break;case 5:t.prev=5,t.t0=t.catch(0),console.error("Error setting store :",t.t0);case 8:case"end":return t.stop()}}),t,null,[[0,5]])})));return function(e){return t.apply(this,arguments)}}(),d=function(){var t=c(i().mark((function t(){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,o.removeItem("apiRequests");case 3:t.next=8;break;case 5:t.prev=5,t.t0=t.catch(0),console.error("Error clearing stored API requests:",t.t0);case 8:case"end":return t.stop()}}),t,null,[[0,5]])})));return function(){return t.apply(this,arguments)}}();function y(t){var e={};return t.forEach((function(t,r){e.hasOwnProperty(r)?(Array.isArray(e[r])||(e[r]=[e[r]]),e[r].push(t)):e[r]=t})),e}function g(t){var e=new FormData,r=function(r){if(Object.hasOwnProperty.call(t,r)){var n=t[r];Array.isArray(n)?n.forEach((function(t){return e.append(r,t)})):e.append(r,n)}};for(var n in t)r(n);return e.forEach((function(t,e){console.log("formdata",e+" "+t)})),e}var m=n.create();exports.OfflineSyncProvider=function(t){var n,u,l=t.children,w=t.render,x=t.onStatusChange,b=t.onCallback,E=e.useState({}),L=E[0],k=E[1],O=e.useState(null==(n=null==(u=window)||null==(u=u.navigator)?void 0:u.onLine)||n),S=O[0],q=O[1];e.useEffect((function(){if(window&&"undefined"!=typeof window)return window.addEventListener("online",j),window.addEventListener("offline",P),function(){window.removeEventListener("offline",P),window.removeEventListener("online",j)}}),[]);var j=e.useCallback((function(){I(!1),F()}),[]),P=function(){I(!0)},I=function(t){void 0===t&&(t=!0);var e=!t;null==x||x({isOnline:e}),q(e)};e.useEffect((function(){F()}),[]);var _=function(){var t=c(i().mark((function t(e){var r;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,console.log("perform save",{request:e.meta.citizenId}),t.next=4,o.getItem("apiRequests");case 4:if(t.t0=t.sent,t.t0){t.next=7;break}t.t0=[];case 7:return r=t.t0,console.log("perform stored",{req:r,length:r.length}),null!=e&&e.isFormdata&&(null==e?void 0:e.data)instanceof FormData?r.push(a.omit(s({},e,{data:y(e.data)}),"onSuccess")):(console.log("Saving request normally"),r.push(a.omit(s({},e),"onSuccess"))),console.log("perform stored after:",{storedRequests:r}),t.next=13,o.setItem("apiRequests",r);case 13:t.next=18;break;case 15:t.prev=15,t.t1=t.catch(0),console.error("Error saving API request for offline:",t.t1);case 18:case"end":return t.stop()}}),t,null,[[0,15]])})));return function(e){return t.apply(this,arguments)}}(),A=function(){var t=c(i().mark((function t(e){var r,n;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(t.prev=0,console.log("perform",{request:e.meta.citizenId}),null==e||!e.isFormdata||(null==e?void 0:e.data)instanceof FormData){t.next=9;break}return n=s({},e,{data:g(e.data)}),t.next=6,m.request(n);case 6:r=t.sent,t.next=12;break;case 9:return t.next=11,m.request(e);case 11:r=t.sent;case 12:return b&&b({config:e,data:r,sendRequest:C}),t.abrupt("return",r.data);case 16:if(t.prev=16,t.t0=t.catch(0),console.log("packageError",{error:t.t0}),!(e.retryCount<1)){t.next=26;break}return t.next=22,new Promise((function(t){return setTimeout(t,1e3)}));case 22:return e.retryCount++,t.abrupt("return",A(e));case 26:return t.next=28,_(e);case 28:case"end":return t.stop()}}),t,null,[[0,16]])})));return function(e){return t.apply(this,arguments)}}(),C=function(){var t=c(i().mark((function t(e){var r;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,e.retryCount=null!=(r=e.retryCount)?r:0,e.id=String(Date.now().toString(32)+Math.random().toString(16)).replace(/\./g,""),t.next=5,A(e);case 5:return t.abrupt("return",t.sent);case 8:throw t.prev=8,t.t0=t.catch(0),t.t0;case 11:case"end":return t.stop()}}),t,null,[[0,8]])})));return function(e){return t.apply(this,arguments)}}(),F=function(){var t=c(i().mark((function t(){var e,r,n,a,u;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,h();case 2:if((e=t.sent)&&0!==e.length){t.next=5;break}return t.abrupt("return");case 5:r=[].concat(e),n=i().mark((function t(){var e,n;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!(e=u.value)){t.next=16;break}return t.prev=2,t.next=5,A(e);case 5:n=r.filter((function(t){return t.id!==e.id})),r.splice.apply(r,[0,r.length].concat(n)),t.next=12;break;case 9:t.prev=9,t.t0=t.catch(2),console.log({error:t.t0});case 12:return t.prev=12,t.next=15,o.setItem("apiRequests",r);case 15:return t.finish(12);case 16:case"end":return t.stop()}}),t,null,[[2,9,12,16]])})),a=f(e);case 8:if((u=a()).done){t.next=12;break}return t.delegateYield(n(),"t0",10);case 10:t.next=8;break;case 12:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}();return r.createElement(r.Fragment,null,r.createElement(p.Provider,{value:{data:L,setData:k,sendRequest:C,clearStoredRequests:d,getStoredRequests:h,setStorage:v}},null==w?void 0:w({isOnline:S}),l))},exports.useOfflineSyncContext=function(){return e.useContext(p)};
//# sourceMappingURL=offline-sync-handler-test.cjs.production.min.js.map

@@ -579,2 +579,6 @@ import React, { createContext, useState, useEffect, useCallback, useContext } from 'react';

storedRequests = _context.t0;
console.log("perform stored", {
req: storedRequests,
length: storedRequests.length
});
if (apiConfig != null && apiConfig.isFormdata && (apiConfig == null ? void 0 : apiConfig.data) instanceof FormData) {

@@ -589,16 +593,19 @@ // console.log({ apiConfig })

}
_context.next = 11;
console.log("perform stored after:", {
storedRequests: storedRequests
});
_context.next = 13;
return localForage.setItem(API_REQUESTS_STORAGE_KEY$1, storedRequests);
case 11:
_context.next = 16;
case 13:
_context.next = 18;
break;
case 13:
_context.prev = 13;
case 15:
_context.prev = 15;
_context.t1 = _context["catch"](0);
console.error('Error saving API request for offline:', _context.t1);
case 16:
case 18:
case "end":
return _context.stop();
}
}, _callee, null, [[0, 13]]);
}, _callee, null, [[0, 15]]);
}));

@@ -605,0 +612,0 @@ return function saveRequestToOfflineStorage(_x) {

{
"version": "0.1.67",
"version": "0.1.68",
"license": "MIT",

@@ -4,0 +4,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc