mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
1 line
15 KiB
JSON
1 line
15 KiB
JSON
|
|
{"ast":null,"code":"import _asyncToGenerator from \"C:/Users/eudes.inacio/GabineteDigital/gabinete-digital-fo/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js\";\nimport { getGlobalObject, logger, uuid4, normalize } from '@sentry/utils';\nimport localForage from 'localforage';\n\n/**\n * cache offline errors and send when connected\n */\nclass Offline {\n /**\n * @inheritDoc\n */\n static __initStatic() {\n this.id = 'Offline';\n }\n\n /**\n * @inheritDoc\n */\n __init() {\n this.name = Offline.id;\n }\n\n /**\n * the global instance\n */\n\n /**\n * the current hub instance\n */\n\n /**\n * maximum number of events to store while offline\n */\n\n /**\n * event cache\n */\n\n /**\n * @inheritDoc\n */\n constructor(options = {}) {\n ;\n Offline.prototype.__init.call(this);\n this.global = getGlobalObject();\n this.maxStoredEvents = options.maxStoredEvents || 30; // set a reasonable default\n this.offlineEventStore = localForage.createInstance({\n name: 'sentry/offlineEventStore'\n });\n }\n\n /**\n * @inheritDoc\n */\n setupOnce(addGlobalEventProcessor, getCurrentHub) {\n this.hub = getCurrentHub();\n if ('addEventListener' in this.global) {\n this.global.addEventListener('online', () => {\n void this._sendEvents().catch(() => {\n (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.warn('could not send cached events');\n });\n });\n }\n var eventProcessor = event => {\n if (this.hub && this.hub.getIntegration(Offline)) {\n // cache if we are positively offline\n if ('navigator' in this.global && 'onLine' in this.global.navigator && !this.global.navigator.onLine) {\n (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.log('Event dropped due to being a offline - caching instead');\n void this._cacheEvent(event).then(_event => this._enforceMaxEvents()).catch(_error => {\n (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.warn('could not cache event while offline');\n });\n\n // return null on success or failure, because being offline will still result in an error\n return null;\n }\n }\n return event;\n };\n eventProcessor.id = this.name;\n addGlobalEventProcessor(eventProcessor);\n\n // if online now, send any events stored in a previous offline session\n if ('navigator' in this.global && 'onLine' in this.global.navigator && this.global.navigator.onLine) {\n void this._sendEvents().catch(() => {\n (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.warn('could not send cached events');\n });\n }\n }\n\n /**\n * cache an event to send later\n * @param event an event\n */\n _cacheEvent(event) {\n var _this = this;\n return _asyncToGenerator(function* () {\n return _this.offlineEventStore.setItem(uuid4(), normalize(event));\n })();\n }\n\n /**\n * purge excess events if necessary\n */\n _enforceMaxEvents() {\n var _this2 = this;\n return _asyncToGenerator(function* () {\n var events = [];\n return _this2.offlineEventStore.iterate((event, cacheKey, _index) => {\n // aggregate events\n events.push({\n cacheKey,\n event\n });\n }).then(() =>\n // this promise resolves when the iteration is finished\n _this2._purgeEvents(\n // purge all events past maxStoredEvents in reverse chronological order\n events.sort((a, b) => (b.event.timestamp || 0) - (a.event.timestamp || 0)).slice(_this2.maxStoredEvents < events.length ? _this2.maxStoredEvents : events.length).map(event => event.cacheKey))).catch(_error => {\n (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.warn('could not enforce max events');\n });\n })();\n }\n\n /**\n * purge event from cache\n */\n _purgeEvent(cacheKey) {\n var _this3 = this;\n return _asyncToGenerator(function* () {\n
|