rittenhop-dev/versions/5.94.2/node_modules/@sentry/integrations/esm/offline.js.map

1 line
9.4 KiB
Plaintext
Raw Normal View History

2024-09-23 19:40:12 -04:00
{"version":3,"file":"offline.js","sources":["../../../src/offline.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable deprecation/deprecation */\nimport type { Event, EventProcessor, Hub, Integration } from '@sentry/types';\nimport { GLOBAL_OBJ, logger, normalize, uuid4 } from '@sentry/utils';\nimport * as localForage from 'localforage';\n\nimport { DEBUG_BUILD } from './debug-build';\n\nconst WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window;\n\ntype LocalForage = {\n setItem<T>(key: string, value: T, callback?: (err: any, value: T) => void): Promise<T>;\n iterate<T, U>(\n iteratee: (value: T, key: string, iterationNumber: number) => U,\n callback?: (err: any, result: U) => void,\n ): Promise<U>;\n removeItem(key: string, callback?: (err: any) => void): Promise<void>;\n length(): Promise<number>;\n};\n\nexport type Item = { key: string; value: Event };\n\n/**\n * cache offline errors and send when connected\n * @deprecated The offline integration has been deprecated in favor of the offline transport wrapper.\n *\n * http://docs.sentry.io/platforms/javascript/configuration/transports/#offline-caching\n */\nexport class Offline implements Integration {\n /**\n * @inheritDoc\n */\n public static id: string = 'Offline';\n\n /**\n * @inheritDoc\n */\n public readonly name: string;\n\n /**\n * the current hub instance\n */\n public hub?: Hub;\n\n /**\n * maximum number of events to store while offline\n */\n public maxStoredEvents: number;\n\n /**\n * event cache\n */\n public offlineEventStore: LocalForage;\n\n /**\n * @inheritDoc\n */\n public constructor(options: { maxStoredEvents?: number } = {}) {\n this.name = Offline.id;\n\n this.maxStoredEvents = options.maxStoredEvents || 30; // set a reasonable default\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n this.offlineEventStore = localForage.createInstance({\n name: 'sentry/offlineEventStore',\n });\n }\n\n /**\n * @inheritDoc\n */\n public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {\n this.hub = getCurrentHub();\n\n if ('addEventListener' in WINDOW) {\n WINDOW.addEventListener('online', () => {\n void this._sendEvents().catch(() => {\n DEBUG_BUILD && logger.warn('could not send cached events');\n });\n });\n }\n\n const eventProcessor: EventProcessor = event => {\n // eslint-disable-next-line deprecation/deprecation\n if (this.hub && this.hub.getIntegration(Offline)) {\n // cache if we are positively offline\n if ('navigator' in WINDOW && 'onLine' in WINDOW.navigator && !WINDOW.navigator.onLine) {\n DEBUG_BUILD && logger.log('Event dropped due to being a offline - caching instead');\n\n void this._cacheEvent(event)\n .then((_event: Event): Promise<void> => this._enforceMaxEvents())\n .catch((_error): void => {\n DEBUG_BUILD && 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\n return event;\n };\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 WINDOW && 'onLine' in WINDOW.navigator && WINDOW.navigator.onLine) {\n void this._sendEvents().catch(() => {\n DEBUG_BUILD && 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 private async _cacheEvent(event: Event): Promise<Event> {\n return this.offlineEventStore.setItem<Event>(uuid4(), normalize(event));\n }\n\n /**\n * purge excess events if necessary\n */\n private async _enforceMaxEvents(): Promise<void> {\n