UNPKG

@micro-sentry/angular

Version:

[![npm version](https://img.shields.io/npm/v/@micro-sentry/angular.svg)](https://npmjs.com/package/@micro-sentry/angular)

139 lines (128 loc) 6.38 kB
import { DOCUMENT, CommonModule } from '@angular/common'; import * as i0 from '@angular/core'; import { InjectionToken, Inject, Injectable, ErrorHandler, inject, Injector, runInInjectionContext, NgModule } from '@angular/core'; import { Subject } from 'rxjs'; import { throttleTime, groupBy, mergeMap } from 'rxjs/operators'; import { BrowserMicroSentryClient } from '@micro-sentry/browser'; const MICRO_SENTRY_ERRORS_THROTTLE_TIME = 1000; const MICRO_SENTRY_ERRORS_THROTTLE = new InjectionToken('Micro sentry error throttle', { providedIn: 'root', factory() { return (source) => source.pipe(throttleTime(MICRO_SENTRY_ERRORS_THROTTLE_TIME)); }, }); class MicroSentryErrorBusService { constructor(throttle) { this.throttle = throttle; this._errors$ = new Subject(); this.errors$ = this._errors$.pipe(groupBy((error) => error?.toString()), mergeMap((group) => group.pipe(this.throttle))); } ngOnDestroy() { this._errors$.complete(); } next(error) { this._errors$.next(error); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: MicroSentryErrorBusService, deps: [{ token: MICRO_SENTRY_ERRORS_THROTTLE }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: MicroSentryErrorBusService, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: MicroSentryErrorBusService, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: () => [{ type: undefined, decorators: [{ type: Inject, args: [MICRO_SENTRY_ERRORS_THROTTLE] }] }] }); const MICRO_SENTRY_CONFIG = new InjectionToken('Micro Sentry Options'); class MicroSentryService extends BrowserMicroSentryClient { constructor(config, document) { super(config, document?.defaultView ?? undefined); } getRequestBlank() { return { ...super.getRequestBlank(), sdk: { name: 'micro-sentry.javascript.angular', version: '0.0.0', }, }; } ngOnDestroy() { this.destroy(); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: MicroSentryService, deps: [{ token: MICRO_SENTRY_CONFIG }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: MicroSentryService, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: MicroSentryService, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: () => [{ type: undefined, decorators: [{ type: Inject, args: [MICRO_SENTRY_CONFIG] }] }, { type: Document, decorators: [{ type: Inject, args: [DOCUMENT] }] }] }); class MicroSentryErrorHandler { constructor(errorBus, microSentry) { this.errorBus = errorBus; errorBus.errors$.subscribe((error) => { microSentry.report(error); }); } handleError(error) { this.errorBus.next(error); console.error(error); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: MicroSentryErrorHandler, deps: [{ token: MicroSentryErrorBusService }, { token: MicroSentryService }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: MicroSentryErrorHandler, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: MicroSentryErrorHandler, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: () => [{ type: MicroSentryErrorBusService }, { type: MicroSentryService }] }); function provideMicroSentry({ beforeSend, beforeBreadcrumb, ...config }) { return [ { provide: ErrorHandler, useExisting: MicroSentryErrorHandler, }, { provide: MICRO_SENTRY_CONFIG, useFactory: () => { const injector = inject(Injector); return { ...config, beforeSend: beforeSend && ((...args) => runInInjectionContext(injector, () => beforeSend(...args))), beforeBreadcrumb: beforeBreadcrumb && ((...args) => runInInjectionContext(injector, () => beforeBreadcrumb(...args))), }; }, }, ]; } class MicroSentryModule { static forRoot(config) { return { ngModule: MicroSentryModule, providers: provideMicroSentry(config), }; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: MicroSentryModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.12", ngImport: i0, type: MicroSentryModule, imports: [CommonModule] }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: MicroSentryModule, imports: [CommonModule] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: MicroSentryModule, decorators: [{ type: NgModule, args: [{ declarations: [], imports: [CommonModule], }] }] }); // modules /** * Generated bundle index. Do not edit. */ export { MICRO_SENTRY_CONFIG, MICRO_SENTRY_ERRORS_THROTTLE, MICRO_SENTRY_ERRORS_THROTTLE_TIME, MicroSentryErrorBusService, MicroSentryModule, MicroSentryService, provideMicroSentry }; //# sourceMappingURL=micro-sentry-angular.mjs.map