Big News: Socket Selected for OpenAI's Cybersecurity Grant Program.Details
Socket
Book a DemoSign in
Socket

@sentry/core

Package Overview
Dependencies
Maintainers
9
Versions
697
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sentry/core - npm Package Compare versions

Comparing version
5.0.6
to
5.0.7
+3
-1
dist/baseclient.d.ts

@@ -54,2 +54,4 @@ import { Scope } from '@sentry/hub';

protected _processing: boolean;
/** Processing interval */
protected _processingInterval?: number;
/**

@@ -99,3 +101,3 @@ * Initializes this client instance.

/** Waits for the client to be done with processing. */
protected _isClientProcessing(counter?: number): Promise<boolean>;
protected _isClientProcessing(timeout?: number): Promise<boolean>;
/** Returns the current backend. */

@@ -102,0 +104,0 @@ protected _getBackend(): B;

@@ -136,11 +136,17 @@ "use strict";

return tslib_1.__awaiter(this, void 0, void 0, function () {
var clientReady, transportFlushed;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Promise.all([
this._getBackend()
case 0: return [4 /*yield*/, this._isClientProcessing(timeout)];
case 1:
clientReady = _a.sent();
if (this._processingInterval) {
clearInterval(this._processingInterval);
}
return [4 /*yield*/, this._getBackend()
.getTransport()
.close(timeout),
this._isClientProcessing(),
])];
case 1: return [2 /*return*/, (_a.sent()).reduce(function (prev, current) { return prev && current; })];
.close(timeout)];
case 2:
transportFlushed = _a.sent();
return [2 /*return*/, clientReady && transportFlushed];
}

@@ -155,7 +161,5 @@ });

return tslib_1.__awaiter(this, void 0, void 0, function () {
var _this = this;
return tslib_1.__generator(this, function (_a) {
return [2 /*return*/, this.flush(timeout).finally(function () {
_this.getOptions().enabled = false;
})];
this.getOptions().enabled = false;
return [2 /*return*/, this.flush(timeout)];
});

@@ -183,4 +187,3 @@ });

/** Waits for the client to be done with processing. */
BaseClient.prototype._isClientProcessing = function (counter) {
if (counter === void 0) { counter = 0; }
BaseClient.prototype._isClientProcessing = function (timeout) {
return tslib_1.__awaiter(this, void 0, void 0, function () {

@@ -190,26 +193,18 @@ var _this = this;

return [2 /*return*/, new Promise(function (resolve) {
if (_this._processing) {
// Safeguard in case of endless recursion
if (counter >= 10) {
resolve(false);
var ticked = 0;
var tick = 1;
if (_this._processingInterval) {
clearInterval(_this._processingInterval);
}
_this._processingInterval = setInterval(function () {
if (!_this._processing) {
resolve(true);
}
else {
setTimeout(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var _a;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = resolve;
return [4 /*yield*/, this._isClientProcessing(counter + 1)];
case 1:
_a.apply(void 0, [_b.sent()]);
return [2 /*return*/];
}
});
}); }, 10);
ticked += tick;
if (timeout && ticked >= timeout) {
resolve(false);
}
}
}
else {
resolve(true);
}
}, tick);
})];

@@ -216,0 +211,0 @@ });

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

{"version":3,"file":"baseclient.js","sourceRoot":"","sources":["../src/baseclient.ts"],"names":[],"mappings":";;;AAEA,uCAA8F;AAG9F,6BAA4B;AAC5B,6CAAoE;AAEpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH;IAoBE;;;;;OAKG;IACH,oBAAsB,YAAgC,EAAE,OAAU;QATlE,6CAA6C;QACnC,gBAAW,GAAY,KAAK,CAAC;QASrC,IAAI,CAAC,QAAQ,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QAExB,IAAI,OAAO,CAAC,GAAG,EAAE;YACf,IAAI,CAAC,IAAI,GAAG,IAAI,SAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;SAClC;QAED,IAAI,CAAC,aAAa,GAAG,+BAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACxD,CAAC;IAED;;OAEG;IACI,qCAAgB,GAAvB,UAAwB,SAAc,EAAE,IAAgB,EAAE,KAAa;QAAvE,iBAkBC;QAjBC,IAAI,OAAO,GAAuB,IAAI,IAAI,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,CAAC;4BACd,OAAO;yBACR;wBAED,mCAAmC;wBACnC,KAAI,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;wBACzC,OAAO,CAAC,UAAU,CAAC,CAAC;qBACrB;iBACF;gBAAC,OAAO,SAAS,EAAE;oBAClB,KAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE;wBAC/B,IAAI,EAAE;4BACJ,UAAU,EAAE,IAAI;yBACjB;wBACD,iBAAiB,EAAE,SAAkB;qBACtC,CAAC,CAAC;oBACH,MAAM,CAAC,mDAAmD,CAAC,CAAC;iBAC7D;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACK,2CAAsB,GAA9B,UACE,UAAiC,EACjC,OAA+B,EAC/B,MAAgC;QAHlC,iBAkBC;QAbC,UAAU;aACP,IAAI,CAAC,UAAA,cAAc;YAClB,IAAI,cAAc,KAAK,IAAI,EAAE;gBAC3B,MAAM,CAAC,oDAAoD,CAAC,CAAC;gBAC7D,OAAO;aACR;YACD,mCAAmC;YACnC,KAAI,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;YAC7C,OAAO,CAAC,cAAc,CAAC,CAAC;QAC1B,CAAC,CAAC;aACD,KAAK,CAAC,UAAA,CAAC;YACN,MAAM,CAAC,8BAA4B,CAAG,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACP,CAAC;IACH,iBAAC;AAAD,CAAC,AAtWD,IAsWC;AAtWqB,gCAAU","sourcesContent":["import { Scope } from '@sentry/hub';\nimport { Client, Event, EventHint, Integration, IntegrationClass, Options, SdkInfo, Severity } from '@sentry/types';\nimport { isPrimitive, isThenable, logger, SyncPromise, truncate, uuid4 } from '@sentry/utils';\n\nimport { Backend, BackendClass } from './basebackend';\nimport { Dsn } from './dsn';\nimport { IntegrationIndex, setupIntegrations } from './integration';\n\n/**\n * Base implementation for all JavaScript SDK clients.\n *\n * Call the constructor with the corresponding backend constructor and options\n * specific to the client subclass. To access these options later, use\n * {@link Client.getOptions}. Also, the Backend instance is available via\n * {@link Client.getBackend}.\n *\n * If a Dsn is specified in the options, it will be parsed and stored. Use\n * {@link Client.getDsn} to retrieve the Dsn at any moment. In case the Dsn is\n * invalid, the constructor will throw a {@link SentryException}. Note that\n * without a valid Dsn, the SDK will not send any events to Sentry.\n *\n * Before sending an event via the backend, it is passed through\n * {@link BaseClient.prepareEvent} to add SDK information and scope data\n * (breadcrumbs and context). To add more custom information, override this\n * method and extend the resulting prepared event.\n *\n * To issue automatically created events (e.g. via instrumentation), use\n * {@link Client.captureEvent}. It will prepare the event and pass it through\n * the callback lifecycle. To issue auto-breadcrumbs, use\n * {@link Client.addBreadcrumb}.\n *\n * @example\n * class NodeClient extends BaseClient<NodeBackend, NodeOptions> {\n * public constructor(options: NodeOptions) {\n * super(NodeBackend, options);\n * }\n *\n * // ...\n * }\n */\nexport abstract class BaseClient<B extends Backend, O extends Options> implements Client<O> {\n /**\n * The backend used to physically interact in the enviornment. Usually, this\n * will correspond to the client. When composing SDKs, however, the Backend\n * from the root SDK will be used.\n */\n protected readonly _backend: B;\n\n /** Options passed to the SDK. */\n protected readonly _options: O;\n\n /** The client Dsn, if specified in options. Without this Dsn, the SDK will be disabled. */\n protected readonly _dsn?: Dsn;\n\n /** Array of used integrations. */\n protected readonly _integrations: IntegrationIndex;\n\n /** Is the client still processing a call? */\n protected _processing: boolean = false;\n\n /**\n * Initializes this client instance.\n *\n * @param backendClass A constructor function to create the backend.\n * @param options Options for the client.\n */\n protected constructor(backendClass: BackendClass<B, O>, options: O) {\n this._backend = new backendClass(options);\n this._options = options;\n\n if (options.dsn) {\n this._dsn = new Dsn(options.dsn);\n }\n\n this._integrations = setupIntegrations(this._options);\n }\n\n /**\n * @inheritDoc\n */\n public captureException(exception: any, hint?: EventHint, scope?: Scope): string | undefined {\n let eventId: string | undefined = hint && hint.event_id;\n this._processing = true;\n\n this._getBackend()\n .eventFromException(exception, hint)\n .then(event => this._processEvent(event, hint, scope))\n .then(finalEvent => {\n // We need to check for finalEvent in case beforeSend returned null\n eventId = finalEvent && finalEvent.event_id;\n this._processing = false;\n })\n .catch(reason => {\n logger.log(reason);\n this._processing = false;\n });\n\n return eventId;\n }\n\n /**\n * @inheritDoc\n */\n public captureMessage(message: string, level?: Severity, hint?: EventHint, scope?: Scope): string | undefined {\n let eventId: string | undefined = hint && hint.event_id;\n\n this._processing = true;\n\n const promisedEvent = isPrimitive(message)\n ? this._getBackend().eventFromMessage(`${message}`, level, hint)\n : this._getBackend().eventFromException(message, hint);\n\n promisedEvent\n .then(event => this._processEvent(event, hint, scope))\n .then(finalEvent => {\n // We need to check for finalEvent in case beforeSend returned null\n eventId = finalEvent && finalEvent.event_id;\n this._processing = false;\n })\n .catch(reason => {\n logger.log(reason);\n this._processing = false;\n });\n\n return eventId;\n }\n\n /**\n * @inheritDoc\n */\n public captureEvent(event: Event, hint?: EventHint, scope?: Scope): string | undefined {\n let eventId: string | undefined = hint && hint.event_id;\n this._processing = true;\n\n this._processEvent(event, hint, scope)\n .then(finalEvent => {\n // We need to check for finalEvent in case beforeSend returned null\n eventId = finalEvent && finalEvent.event_id;\n this._processing = false;\n })\n .catch(reason => {\n logger.log(reason);\n this._processing = false;\n });\n return eventId;\n }\n\n /**\n * @inheritDoc\n */\n public getDsn(): Dsn | undefined {\n return this._dsn;\n }\n\n /**\n * @inheritDoc\n */\n public getOptions(): O {\n return this._options;\n }\n\n /**\n * @inheritDoc\n */\n public async flush(timeout?: number): Promise<boolean> {\n return (await Promise.all([\n this._getBackend()\n .getTransport()\n .close(timeout),\n this._isClientProcessing(),\n ])).reduce((prev, current) => prev && current);\n }\n\n /**\n * @inheritDoc\n */\n public async close(timeout?: number): Promise<boolean> {\n return this.flush(timeout).finally(() => {\n this.getOptions().enabled = false;\n });\n }\n\n /**\n * @inheritDoc\n */\n public getIntegrations(): IntegrationIndex {\n return this._integrations || {};\n }\n\n /**\n * @inheritDoc\n */\n public getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null {\n try {\n return (this._integrations[integration.id] as T) || null;\n } catch (_oO) {\n logger.warn(`Cannot retrieve integration ${integration.id} from the current Client`);\n return null;\n }\n }\n\n /** Waits for the client to be done with processing. */\n protected async _isClientProcessing(counter: number = 0): Promise<boolean> {\n return new Promise<boolean>(resolve => {\n if (this._processing) {\n // Safeguard in case of endless recursion\n if (counter >= 10) {\n resolve(false);\n } else {\n setTimeout(async () => {\n resolve(await this._isClientProcessing(counter + 1));\n }, 10);\n }\n } else {\n resolve(true);\n }\n });\n }\n\n /** Returns the current backend. */\n protected _getBackend(): B {\n return this._backend;\n }\n\n /** Determines whether this SDK is enabled and a valid Dsn is present. */\n protected _isEnabled(): boolean {\n return this.getOptions().enabled !== false && this._dsn !== undefined;\n }\n\n /**\n * Adds common information to events.\n *\n * The information includes release and environment from `options`,\n * breadcrumbs and context (extra, tags and user) from the scope.\n *\n * Information that is already present in the event is never overwritten. For\n * nested objects, such as the context, keys are merged.\n *\n * @param event The original event.\n * @param hint May contain additional informartion about the original exception.\n * @param scope A scope containing event metadata.\n * @returns A new event with more information.\n */\n protected _prepareEvent(event: Event, scope?: Scope, hint?: EventHint): SyncPromise<Event | null> {\n const { environment, release, dist, maxValueLength = 250 } = this.getOptions();\n\n const prepared: Event = { ...event };\n if (prepared.environment === undefined && environment !== undefined) {\n prepared.environment = environment;\n }\n if (prepared.release === undefined && release !== undefined) {\n prepared.release = release;\n }\n\n if (prepared.dist === undefined && dist !== undefined) {\n prepared.dist = dist;\n }\n\n if (prepared.message) {\n prepared.message = truncate(prepared.message, maxValueLength);\n }\n\n const exception = prepared.exception && prepared.exception.values && prepared.exception.values[0];\n if (exception && exception.value) {\n exception.value = truncate(exception.value, maxValueLength);\n }\n\n const request = prepared.request;\n if (request && request.url) {\n request.url = truncate(request.url, maxValueLength);\n }\n\n if (prepared.event_id === undefined) {\n prepared.event_id = uuid4();\n }\n\n this._addIntegrations(prepared.sdk);\n\n // We prepare the result here with a resolved Event.\n let result = SyncPromise.resolve<Event | null>(prepared);\n\n // This should be the last thing called, since we want that\n // {@link Hub.addEventProcessor} gets the finished prepared event.\n if (scope) {\n // In case we have a hub we reassign it.\n result = scope.applyToEvent(prepared, hint);\n }\n\n return result;\n }\n\n /**\n * This function adds all used integrations to the SDK info in the event.\n * @param sdkInfo The sdkInfo of the event that will be filled with all integrations.\n */\n protected _addIntegrations(sdkInfo?: SdkInfo): void {\n const integrationsArray = Object.keys(this._integrations);\n if (sdkInfo && integrationsArray.length > 0) {\n sdkInfo.integrations = integrationsArray;\n }\n }\n\n /**\n * Processes an event (either error or message) and sends it to Sentry.\n *\n * This also adds breadcrumbs and context information to the event. However,\n * platform specific meta data (such as the User's IP address) must be added\n * by the SDK implementor.\n *\n *\n * @param event The event to send to Sentry.\n * @param hint May contain additional informartion about the original exception.\n * @param scope A scope containing event metadata.\n * @returns A SyncPromise that resolves with the event or rejects in case event was/will not be send.\n */\n protected _processEvent(event: Event, hint?: EventHint, scope?: Scope): SyncPromise<Event> {\n const { beforeSend, sampleRate } = this.getOptions();\n\n if (!this._isEnabled()) {\n return SyncPromise.reject('SDK not enabled, will not send event.');\n }\n\n // 1.0 === 100% events are sent\n // 0.0 === 0% events are sent\n if (typeof sampleRate === 'number' && Math.random() > sampleRate) {\n return SyncPromise.reject('This event has been sampled, will not send event.');\n }\n\n return new SyncPromise((resolve, reject) => {\n this._prepareEvent(event, scope, hint).then(prepared => {\n if (prepared === null) {\n reject('An event processor returned null, will not send event.');\n return;\n }\n\n let finalEvent: Event | null = prepared;\n\n try {\n const isInternalException = hint && hint.data && (hint.data as { [key: string]: any }).__sentry__ === true;\n if (isInternalException || !beforeSend) {\n this._getBackend().sendEvent(finalEvent);\n resolve(finalEvent);\n return;\n }\n\n const beforeSendResult = beforeSend(prepared, hint);\n if ((typeof beforeSendResult as any) === 'undefined') {\n logger.error('`beforeSend` method has to return `null` or a valid event.');\n } else if (isThenable(beforeSendResult)) {\n this._handleAsyncBeforeSend(beforeSendResult as Promise<Event | null>, resolve, reject);\n } else {\n finalEvent = beforeSendResult as Event | null;\n\n if (finalEvent === null) {\n logger.log('`beforeSend` returned `null`, will not send event.');\n resolve(null);\n return;\n }\n\n // From here on we are really async\n this._getBackend().sendEvent(finalEvent);\n resolve(finalEvent);\n }\n } catch (exception) {\n this.captureException(exception, {\n data: {\n __sentry__: true,\n },\n originalException: exception as Error,\n });\n reject('`beforeSend` throw an error, will not send event.');\n }\n });\n });\n }\n\n /**\n * Resolves before send Promise and calls resolve/reject on parent SyncPromise.\n */\n private _handleAsyncBeforeSend(\n beforeSend: Promise<Event | null>,\n resolve: (event: Event) => void,\n reject: (reason: string) => void,\n ): void {\n beforeSend\n .then(processedEvent => {\n if (processedEvent === null) {\n reject('`beforeSend` returned `null`, will not send event.');\n return;\n }\n // From here on we are really async\n this._getBackend().sendEvent(processedEvent);\n resolve(processedEvent);\n })\n .catch(e => {\n reject(`beforeSend rejected with ${e}`);\n });\n }\n}\n"]}
{"version":3,"file":"baseclient.js","sourceRoot":"","sources":["../src/baseclient.ts"],"names":[],"mappings":";;;AAEA,uCAA8F;AAG9F,6BAA4B;AAC5B,6CAAoE;AAEpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH;IAuBE;;;;;OAKG;IACH,oBAAsB,YAAgC,EAAE,OAAU;QAZlE,6CAA6C;QACnC,gBAAW,GAAY,KAAK,CAAC;QAYrC,IAAI,CAAC,QAAQ,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QAExB,IAAI,OAAO,CAAC,GAAG,EAAE;YACf,IAAI,CAAC,IAAI,GAAG,IAAI,SAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;SAClC;QAED,IAAI,CAAC,aAAa,GAAG,+BAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACxD,CAAC;IAED;;OAEG;IACI,qC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CAAC,CAAC;qBACzF;yBAAM;wBACL,UAAU,GAAG,gBAAgC,CAAC;wBAE9C,IAAI,UAAU,KAAK,IAAI,EAAE;4BACvB,cAAM,CAAC,GAAG,CAAC,oDAAoD,CAAC,CAAC;4BACjE,OAAO,CAAC,IAAI,CAAC,CAAC;4BACd,OAAO;yBACR;wBAED,mCAAmC;wBACnC,KAAI,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;wBACzC,OAAO,CAAC,UAAU,CAAC,CAAC;qBACrB;iBACF;gBAAC,OAAO,SAAS,EAAE;oBAClB,KAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE;wBAC/B,IAAI,EAAE;4BACJ,UAAU,EAAE,IAAI;yBACjB;wBACD,iBAAiB,EAAE,SAAkB;qBACtC,CAAC,CAAC;oBACH,MAAM,CAAC,mDAAmD,CAAC,CAAC;iBAC7D;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACK,2CAAsB,GAA9B,UACE,UAAiC,EACjC,OAA+B,EAC/B,MAAgC;QAHlC,iBAkBC;QAbC,UAAU;aACP,IAAI,CAAC,UAAA,cAAc;YAClB,IAAI,cAAc,KAAK,IAAI,EAAE;gBAC3B,MAAM,CAAC,oDAAoD,CAAC,CAAC;gBAC7D,OAAO;aACR;YACD,mCAAmC;YACnC,KAAI,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;YAC7C,OAAO,CAAC,cAAc,CAAC,CAAC;QAC1B,CAAC,CAAC;aACD,KAAK,CAAC,UAAA,CAAC;YACN,MAAM,CAAC,8BAA4B,CAAG,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACP,CAAC;IACH,iBAAC;AAAD,CAAC,AA7WD,IA6WC;AA7WqB,gCAAU","sourcesContent":["import { Scope } from '@sentry/hub';\nimport { Client, Event, EventHint, Integration, IntegrationClass, Options, SdkInfo, Severity } from '@sentry/types';\nimport { isPrimitive, isThenable, logger, SyncPromise, truncate, uuid4 } from '@sentry/utils';\n\nimport { Backend, BackendClass } from './basebackend';\nimport { Dsn } from './dsn';\nimport { IntegrationIndex, setupIntegrations } from './integration';\n\n/**\n * Base implementation for all JavaScript SDK clients.\n *\n * Call the constructor with the corresponding backend constructor and options\n * specific to the client subclass. To access these options later, use\n * {@link Client.getOptions}. Also, the Backend instance is available via\n * {@link Client.getBackend}.\n *\n * If a Dsn is specified in the options, it will be parsed and stored. Use\n * {@link Client.getDsn} to retrieve the Dsn at any moment. In case the Dsn is\n * invalid, the constructor will throw a {@link SentryException}. Note that\n * without a valid Dsn, the SDK will not send any events to Sentry.\n *\n * Before sending an event via the backend, it is passed through\n * {@link BaseClient.prepareEvent} to add SDK information and scope data\n * (breadcrumbs and context). To add more custom information, override this\n * method and extend the resulting prepared event.\n *\n * To issue automatically created events (e.g. via instrumentation), use\n * {@link Client.captureEvent}. It will prepare the event and pass it through\n * the callback lifecycle. To issue auto-breadcrumbs, use\n * {@link Client.addBreadcrumb}.\n *\n * @example\n * class NodeClient extends BaseClient<NodeBackend, NodeOptions> {\n * public constructor(options: NodeOptions) {\n * super(NodeBackend, options);\n * }\n *\n * // ...\n * }\n */\nexport abstract class BaseClient<B extends Backend, O extends Options> implements Client<O> {\n /**\n * The backend used to physically interact in the enviornment. Usually, this\n * will correspond to the client. When composing SDKs, however, the Backend\n * from the root SDK will be used.\n */\n protected readonly _backend: B;\n\n /** Options passed to the SDK. */\n protected readonly _options: O;\n\n /** The client Dsn, if specified in options. Without this Dsn, the SDK will be disabled. */\n protected readonly _dsn?: Dsn;\n\n /** Array of used integrations. */\n protected readonly _integrations: IntegrationIndex;\n\n /** Is the client still processing a call? */\n protected _processing: boolean = false;\n\n /** Processing interval */\n protected _processingInterval?: number;\n\n /**\n * Initializes this client instance.\n *\n * @param backendClass A constructor function to create the backend.\n * @param options Options for the client.\n */\n protected constructor(backendClass: BackendClass<B, O>, options: O) {\n this._backend = new backendClass(options);\n this._options = options;\n\n if (options.dsn) {\n this._dsn = new Dsn(options.dsn);\n }\n\n this._integrations = setupIntegrations(this._options);\n }\n\n /**\n * @inheritDoc\n */\n public captureException(exception: any, hint?: EventHint, scope?: Scope): string | undefined {\n let eventId: string | undefined = hint && hint.event_id;\n this._processing = true;\n\n this._getBackend()\n .eventFromException(exception, hint)\n .then(event => this._processEvent(event, hint, scope))\n .then(finalEvent => {\n // We need to check for finalEvent in case beforeSend returned null\n eventId = finalEvent && finalEvent.event_id;\n this._processing = false;\n })\n .catch(reason => {\n logger.log(reason);\n this._processing = false;\n });\n\n return eventId;\n }\n\n /**\n * @inheritDoc\n */\n public captureMessage(message: string, level?: Severity, hint?: EventHint, scope?: Scope): string | undefined {\n let eventId: string | undefined = hint && hint.event_id;\n\n this._processing = true;\n\n const promisedEvent = isPrimitive(message)\n ? this._getBackend().eventFromMessage(`${message}`, level, hint)\n : this._getBackend().eventFromException(message, hint);\n\n promisedEvent\n .then(event => this._processEvent(event, hint, scope))\n .then(finalEvent => {\n // We need to check for finalEvent in case beforeSend returned null\n eventId = finalEvent && finalEvent.event_id;\n this._processing = false;\n })\n .catch(reason => {\n logger.log(reason);\n this._processing = false;\n });\n\n return eventId;\n }\n\n /**\n * @inheritDoc\n */\n public captureEvent(event: Event, hint?: EventHint, scope?: Scope): string | undefined {\n let eventId: string | undefined = hint && hint.event_id;\n this._processing = true;\n\n this._processEvent(event, hint, scope)\n .then(finalEvent => {\n // We need to check for finalEvent in case beforeSend returned null\n eventId = finalEvent && finalEvent.event_id;\n this._processing = false;\n })\n .catch(reason => {\n logger.log(reason);\n this._processing = false;\n });\n return eventId;\n }\n\n /**\n * @inheritDoc\n */\n public getDsn(): Dsn | undefined {\n return this._dsn;\n }\n\n /**\n * @inheritDoc\n */\n public getOptions(): O {\n return this._options;\n }\n\n /**\n * @inheritDoc\n */\n public async flush(timeout?: number): Promise<boolean> {\n const clientReady = await this._isClientProcessing(timeout);\n if (this._processingInterval) {\n clearInterval(this._processingInterval);\n }\n const transportFlushed = await this._getBackend()\n .getTransport()\n .close(timeout);\n return clientReady && transportFlushed;\n }\n\n /**\n * @inheritDoc\n */\n public async close(timeout?: number): Promise<boolean> {\n this.getOptions().enabled = false;\n return this.flush(timeout);\n }\n\n /**\n * @inheritDoc\n */\n public getIntegrations(): IntegrationIndex {\n return this._integrations || {};\n }\n\n /**\n * @inheritDoc\n */\n public getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null {\n try {\n return (this._integrations[integration.id] as T) || null;\n } catch (_oO) {\n logger.warn(`Cannot retrieve integration ${integration.id} from the current Client`);\n return null;\n }\n }\n\n /** Waits for the client to be done with processing. */\n protected async _isClientProcessing(timeout?: number): Promise<boolean> {\n return new Promise<boolean>(resolve => {\n let ticked: number = 0;\n const tick: number = 1;\n if (this._processingInterval) {\n clearInterval(this._processingInterval);\n }\n this._processingInterval = (setInterval(() => {\n if (!this._processing) {\n resolve(true);\n } else {\n ticked += tick;\n if (timeout && ticked >= timeout) {\n resolve(false);\n }\n }\n }, tick) as unknown) as number;\n });\n }\n\n /** Returns the current backend. */\n protected _getBackend(): B {\n return this._backend;\n }\n\n /** Determines whether this SDK is enabled and a valid Dsn is present. */\n protected _isEnabled(): boolean {\n return this.getOptions().enabled !== false && this._dsn !== undefined;\n }\n\n /**\n * Adds common information to events.\n *\n * The information includes release and environment from `options`,\n * breadcrumbs and context (extra, tags and user) from the scope.\n *\n * Information that is already present in the event is never overwritten. For\n * nested objects, such as the context, keys are merged.\n *\n * @param event The original event.\n * @param hint May contain additional informartion about the original exception.\n * @param scope A scope containing event metadata.\n * @returns A new event with more information.\n */\n protected _prepareEvent(event: Event, scope?: Scope, hint?: EventHint): SyncPromise<Event | null> {\n const { environment, release, dist, maxValueLength = 250 } = this.getOptions();\n\n const prepared: Event = { ...event };\n if (prepared.environment === undefined && environment !== undefined) {\n prepared.environment = environment;\n }\n if (prepared.release === undefined && release !== undefined) {\n prepared.release = release;\n }\n\n if (prepared.dist === undefined && dist !== undefined) {\n prepared.dist = dist;\n }\n\n if (prepared.message) {\n prepared.message = truncate(prepared.message, maxValueLength);\n }\n\n const exception = prepared.exception && prepared.exception.values && prepared.exception.values[0];\n if (exception && exception.value) {\n exception.value = truncate(exception.value, maxValueLength);\n }\n\n const request = prepared.request;\n if (request && request.url) {\n request.url = truncate(request.url, maxValueLength);\n }\n\n if (prepared.event_id === undefined) {\n prepared.event_id = uuid4();\n }\n\n this._addIntegrations(prepared.sdk);\n\n // We prepare the result here with a resolved Event.\n let result = SyncPromise.resolve<Event | null>(prepared);\n\n // This should be the last thing called, since we want that\n // {@link Hub.addEventProcessor} gets the finished prepared event.\n if (scope) {\n // In case we have a hub we reassign it.\n result = scope.applyToEvent(prepared, hint);\n }\n\n return result;\n }\n\n /**\n * This function adds all used integrations to the SDK info in the event.\n * @param sdkInfo The sdkInfo of the event that will be filled with all integrations.\n */\n protected _addIntegrations(sdkInfo?: SdkInfo): void {\n const integrationsArray = Object.keys(this._integrations);\n if (sdkInfo && integrationsArray.length > 0) {\n sdkInfo.integrations = integrationsArray;\n }\n }\n\n /**\n * Processes an event (either error or message) and sends it to Sentry.\n *\n * This also adds breadcrumbs and context information to the event. However,\n * platform specific meta data (such as the User's IP address) must be added\n * by the SDK implementor.\n *\n *\n * @param event The event to send to Sentry.\n * @param hint May contain additional informartion about the original exception.\n * @param scope A scope containing event metadata.\n * @returns A SyncPromise that resolves with the event or rejects in case event was/will not be send.\n */\n protected _processEvent(event: Event, hint?: EventHint, scope?: Scope): SyncPromise<Event> {\n const { beforeSend, sampleRate } = this.getOptions();\n\n if (!this._isEnabled()) {\n return SyncPromise.reject('SDK not enabled, will not send event.');\n }\n\n // 1.0 === 100% events are sent\n // 0.0 === 0% events are sent\n if (typeof sampleRate === 'number' && Math.random() > sampleRate) {\n return SyncPromise.reject('This event has been sampled, will not send event.');\n }\n\n return new SyncPromise((resolve, reject) => {\n this._prepareEvent(event, scope, hint).then(prepared => {\n if (prepared === null) {\n reject('An event processor returned null, will not send event.');\n return;\n }\n\n let finalEvent: Event | null = prepared;\n\n try {\n const isInternalException = hint && hint.data && (hint.data as { [key: string]: any }).__sentry__ === true;\n if (isInternalException || !beforeSend) {\n this._getBackend().sendEvent(finalEvent);\n resolve(finalEvent);\n return;\n }\n\n const beforeSendResult = beforeSend(prepared, hint);\n if ((typeof beforeSendResult as any) === 'undefined') {\n logger.error('`beforeSend` method has to return `null` or a valid event.');\n } else if (isThenable(beforeSendResult)) {\n this._handleAsyncBeforeSend(beforeSendResult as Promise<Event | null>, resolve, reject);\n } else {\n finalEvent = beforeSendResult as Event | null;\n\n if (finalEvent === null) {\n logger.log('`beforeSend` returned `null`, will not send event.');\n resolve(null);\n return;\n }\n\n // From here on we are really async\n this._getBackend().sendEvent(finalEvent);\n resolve(finalEvent);\n }\n } catch (exception) {\n this.captureException(exception, {\n data: {\n __sentry__: true,\n },\n originalException: exception as Error,\n });\n reject('`beforeSend` throw an error, will not send event.');\n }\n });\n });\n }\n\n /**\n * Resolves before send Promise and calls resolve/reject on parent SyncPromise.\n */\n private _handleAsyncBeforeSend(\n beforeSend: Promise<Event | null>,\n resolve: (event: Event) => void,\n reject: (reason: string) => void,\n ): void {\n beforeSend\n .then(processedEvent => {\n if (processedEvent === null) {\n reject('`beforeSend` returned `null`, will not send event.');\n return;\n }\n // From here on we are really async\n this._getBackend().sendEvent(processedEvent);\n resolve(processedEvent);\n })\n .catch(e => {\n reject(`beforeSend rejected with ${e}`);\n });\n }\n}\n"]}

@@ -54,2 +54,4 @@ import { Scope } from '@sentry/hub';

protected _processing: boolean;
/** Processing interval */
protected _processingInterval?: number;
/**

@@ -99,3 +101,3 @@ * Initializes this client instance.

/** Waits for the client to be done with processing. */
protected _isClientProcessing(counter?: number): Promise<boolean>;
protected _isClientProcessing(timeout?: number): Promise<boolean>;
/** Returns the current backend. */

@@ -102,0 +104,0 @@ protected _getBackend(): B;

@@ -134,11 +134,17 @@ import * as tslib_1 from "tslib";

return tslib_1.__awaiter(this, void 0, void 0, function () {
var clientReady, transportFlushed;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Promise.all([
this._getBackend()
case 0: return [4 /*yield*/, this._isClientProcessing(timeout)];
case 1:
clientReady = _a.sent();
if (this._processingInterval) {
clearInterval(this._processingInterval);
}
return [4 /*yield*/, this._getBackend()
.getTransport()
.close(timeout),
this._isClientProcessing(),
])];
case 1: return [2 /*return*/, (_a.sent()).reduce(function (prev, current) { return prev && current; })];
.close(timeout)];
case 2:
transportFlushed = _a.sent();
return [2 /*return*/, clientReady && transportFlushed];
}

@@ -153,7 +159,5 @@ });

return tslib_1.__awaiter(this, void 0, void 0, function () {
var _this = this;
return tslib_1.__generator(this, function (_a) {
return [2 /*return*/, this.flush(timeout).finally(function () {
_this.getOptions().enabled = false;
})];
this.getOptions().enabled = false;
return [2 /*return*/, this.flush(timeout)];
});

@@ -181,4 +185,3 @@ });

/** Waits for the client to be done with processing. */
BaseClient.prototype._isClientProcessing = function (counter) {
if (counter === void 0) { counter = 0; }
BaseClient.prototype._isClientProcessing = function (timeout) {
return tslib_1.__awaiter(this, void 0, void 0, function () {

@@ -188,26 +191,18 @@ var _this = this;

return [2 /*return*/, new Promise(function (resolve) {
if (_this._processing) {
// Safeguard in case of endless recursion
if (counter >= 10) {
resolve(false);
var ticked = 0;
var tick = 1;
if (_this._processingInterval) {
clearInterval(_this._processingInterval);
}
_this._processingInterval = setInterval(function () {
if (!_this._processing) {
resolve(true);
}
else {
setTimeout(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var _a;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = resolve;
return [4 /*yield*/, this._isClientProcessing(counter + 1)];
case 1:
_a.apply(void 0, [_b.sent()]);
return [2 /*return*/];
}
});
}); }, 10);
ticked += tick;
if (timeout && ticked >= timeout) {
resolve(false);
}
}
}
else {
resolve(true);
}
}, tick);
})];

@@ -214,0 +209,0 @@ });

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

{"version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ACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACK,2CAAsB,GAA9B,UACE,UAAiC,EACjC,OAA+B,EAC/B,MAAgC;QAHlC,iBAkBC;QAbC,UAAU;aACP,IAAI,CAAC,UAAA,cAAc;YAClB,IAAI,cAAc,KAAK,IAAI,EAAE;gBAC3B,MAAM,CAAC,oDAAoD,CAAC,CAAC;gBAC7D,OAAO;aACR;YACD,mCAAmC;YACnC,KAAI,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;YAC7C,OAAO,CAAC,cAAc,CAAC,CAAC;QAC1B,CAAC,CAAC;aACD,KAAK,CAAC,UAAA,CAAC;YACN,MAAM,CAAC,8BAA4B,CAAG,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACP,CAAC;IACH,iBAAC;AAAD,CAAC,AAtWD,IAsWC","sourcesContent":["import { Scope } from '@sentry/hub';\nimport { Client, Event, EventHint, Integration, IntegrationClass, Options, SdkInfo, Severity } from '@sentry/types';\nimport { isPrimitive, isThenable, logger, SyncPromise, truncate, uuid4 } from '@sentry/utils';\n\nimport { Backend, BackendClass } from './basebackend';\nimport { Dsn } from './dsn';\nimport { IntegrationIndex, setupIntegrations } from './integration';\n\n/**\n * Base implementation for all JavaScript SDK clients.\n *\n * Call the constructor with the corresponding backend constructor and options\n * specific to the client subclass. To access these options later, use\n * {@link Client.getOptions}. Also, the Backend instance is available via\n * {@link Client.getBackend}.\n *\n * If a Dsn is specified in the options, it will be parsed and stored. Use\n * {@link Client.getDsn} to retrieve the Dsn at any moment. In case the Dsn is\n * invalid, the constructor will throw a {@link SentryException}. Note that\n * without a valid Dsn, the SDK will not send any events to Sentry.\n *\n * Before sending an event via the backend, it is passed through\n * {@link BaseClient.prepareEvent} to add SDK information and scope data\n * (breadcrumbs and context). To add more custom information, override this\n * method and extend the resulting prepared event.\n *\n * To issue automatically created events (e.g. via instrumentation), use\n * {@link Client.captureEvent}. It will prepare the event and pass it through\n * the callback lifecycle. To issue auto-breadcrumbs, use\n * {@link Client.addBreadcrumb}.\n *\n * @example\n * class NodeClient extends BaseClient<NodeBackend, NodeOptions> {\n * public constructor(options: NodeOptions) {\n * super(NodeBackend, options);\n * }\n *\n * // ...\n * }\n */\nexport abstract class BaseClient<B extends Backend, O extends Options> implements Client<O> {\n /**\n * The backend used to physically interact in the enviornment. Usually, this\n * will correspond to the client. When composing SDKs, however, the Backend\n * from the root SDK will be used.\n */\n protected readonly _backend: B;\n\n /** Options passed to the SDK. */\n protected readonly _options: O;\n\n /** The client Dsn, if specified in options. Without this Dsn, the SDK will be disabled. */\n protected readonly _dsn?: Dsn;\n\n /** Array of used integrations. */\n protected readonly _integrations: IntegrationIndex;\n\n /** Is the client still processing a call? */\n protected _processing: boolean = false;\n\n /**\n * Initializes this client instance.\n *\n * @param backendClass A constructor function to create the backend.\n * @param options Options for the client.\n */\n protected constructor(backendClass: BackendClass<B, O>, options: O) {\n this._backend = new backendClass(options);\n this._options = options;\n\n if (options.dsn) {\n this._dsn = new Dsn(options.dsn);\n }\n\n this._integrations = setupIntegrations(this._options);\n }\n\n /**\n * @inheritDoc\n */\n public captureException(exception: any, hint?: EventHint, scope?: Scope): string | undefined {\n let eventId: string | undefined = hint && hint.event_id;\n this._processing = true;\n\n this._getBackend()\n .eventFromException(exception, hint)\n .then(event => this._processEvent(event, hint, scope))\n .then(finalEvent => {\n // We need to check for finalEvent in case beforeSend returned null\n eventId = finalEvent && finalEvent.event_id;\n this._processing = false;\n })\n .catch(reason => {\n logger.log(reason);\n this._processing = false;\n });\n\n return eventId;\n }\n\n /**\n * @inheritDoc\n */\n public captureMessage(message: string, level?: Severity, hint?: EventHint, scope?: Scope): string | undefined {\n let eventId: string | undefined = hint && hint.event_id;\n\n this._processing = true;\n\n const promisedEvent = isPrimitive(message)\n ? this._getBackend().eventFromMessage(`${message}`, level, hint)\n : this._getBackend().eventFromException(message, hint);\n\n promisedEvent\n .then(event => this._processEvent(event, hint, scope))\n .then(finalEvent => {\n // We need to check for finalEvent in case beforeSend returned null\n eventId = finalEvent && finalEvent.event_id;\n this._processing = false;\n })\n .catch(reason => {\n logger.log(reason);\n this._processing = false;\n });\n\n return eventId;\n }\n\n /**\n * @inheritDoc\n */\n public captureEvent(event: Event, hint?: EventHint, scope?: Scope): string | undefined {\n let eventId: string | undefined = hint && hint.event_id;\n this._processing = true;\n\n this._processEvent(event, hint, scope)\n .then(finalEvent => {\n // We need to check for finalEvent in case beforeSend returned null\n eventId = finalEvent && finalEvent.event_id;\n this._processing = false;\n })\n .catch(reason => {\n logger.log(reason);\n this._processing = false;\n });\n return eventId;\n }\n\n /**\n * @inheritDoc\n */\n public getDsn(): Dsn | undefined {\n return this._dsn;\n }\n\n /**\n * @inheritDoc\n */\n public getOptions(): O {\n return this._options;\n }\n\n /**\n * @inheritDoc\n */\n public async flush(timeout?: number): Promise<boolean> {\n return (await Promise.all([\n this._getBackend()\n .getTransport()\n .close(timeout),\n this._isClientProcessing(),\n ])).reduce((prev, current) => prev && current);\n }\n\n /**\n * @inheritDoc\n */\n public async close(timeout?: number): Promise<boolean> {\n return this.flush(timeout).finally(() => {\n this.getOptions().enabled = false;\n });\n }\n\n /**\n * @inheritDoc\n */\n public getIntegrations(): IntegrationIndex {\n return this._integrations || {};\n }\n\n /**\n * @inheritDoc\n */\n public getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null {\n try {\n return (this._integrations[integration.id] as T) || null;\n } catch (_oO) {\n logger.warn(`Cannot retrieve integration ${integration.id} from the current Client`);\n return null;\n }\n }\n\n /** Waits for the client to be done with processing. */\n protected async _isClientProcessing(counter: number = 0): Promise<boolean> {\n return new Promise<boolean>(resolve => {\n if (this._processing) {\n // Safeguard in case of endless recursion\n if (counter >= 10) {\n resolve(false);\n } else {\n setTimeout(async () => {\n resolve(await this._isClientProcessing(counter + 1));\n }, 10);\n }\n } else {\n resolve(true);\n }\n });\n }\n\n /** Returns the current backend. */\n protected _getBackend(): B {\n return this._backend;\n }\n\n /** Determines whether this SDK is enabled and a valid Dsn is present. */\n protected _isEnabled(): boolean {\n return this.getOptions().enabled !== false && this._dsn !== undefined;\n }\n\n /**\n * Adds common information to events.\n *\n * The information includes release and environment from `options`,\n * breadcrumbs and context (extra, tags and user) from the scope.\n *\n * Information that is already present in the event is never overwritten. For\n * nested objects, such as the context, keys are merged.\n *\n * @param event The original event.\n * @param hint May contain additional informartion about the original exception.\n * @param scope A scope containing event metadata.\n * @returns A new event with more information.\n */\n protected _prepareEvent(event: Event, scope?: Scope, hint?: EventHint): SyncPromise<Event | null> {\n const { environment, release, dist, maxValueLength = 250 } = this.getOptions();\n\n const prepared: Event = { ...event };\n if (prepared.environment === undefined && environment !== undefined) {\n prepared.environment = environment;\n }\n if (prepared.release === undefined && release !== undefined) {\n prepared.release = release;\n }\n\n if (prepared.dist === undefined && dist !== undefined) {\n prepared.dist = dist;\n }\n\n if (prepared.message) {\n prepared.message = truncate(prepared.message, maxValueLength);\n }\n\n const exception = prepared.exception && prepared.exception.values && prepared.exception.values[0];\n if (exception && exception.value) {\n exception.value = truncate(exception.value, maxValueLength);\n }\n\n const request = prepared.request;\n if (request && request.url) {\n request.url = truncate(request.url, maxValueLength);\n }\n\n if (prepared.event_id === undefined) {\n prepared.event_id = uuid4();\n }\n\n this._addIntegrations(prepared.sdk);\n\n // We prepare the result here with a resolved Event.\n let result = SyncPromise.resolve<Event | null>(prepared);\n\n // This should be the last thing called, since we want that\n // {@link Hub.addEventProcessor} gets the finished prepared event.\n if (scope) {\n // In case we have a hub we reassign it.\n result = scope.applyToEvent(prepared, hint);\n }\n\n return result;\n }\n\n /**\n * This function adds all used integrations to the SDK info in the event.\n * @param sdkInfo The sdkInfo of the event that will be filled with all integrations.\n */\n protected _addIntegrations(sdkInfo?: SdkInfo): void {\n const integrationsArray = Object.keys(this._integrations);\n if (sdkInfo && integrationsArray.length > 0) {\n sdkInfo.integrations = integrationsArray;\n }\n }\n\n /**\n * Processes an event (either error or message) and sends it to Sentry.\n *\n * This also adds breadcrumbs and context information to the event. However,\n * platform specific meta data (such as the User's IP address) must be added\n * by the SDK implementor.\n *\n *\n * @param event The event to send to Sentry.\n * @param hint May contain additional informartion about the original exception.\n * @param scope A scope containing event metadata.\n * @returns A SyncPromise that resolves with the event or rejects in case event was/will not be send.\n */\n protected _processEvent(event: Event, hint?: EventHint, scope?: Scope): SyncPromise<Event> {\n const { beforeSend, sampleRate } = this.getOptions();\n\n if (!this._isEnabled()) {\n return SyncPromise.reject('SDK not enabled, will not send event.');\n }\n\n // 1.0 === 100% events are sent\n // 0.0 === 0% events are sent\n if (typeof sampleRate === 'number' && Math.random() > sampleRate) {\n return SyncPromise.reject('This event has been sampled, will not send event.');\n }\n\n return new SyncPromise((resolve, reject) => {\n this._prepareEvent(event, scope, hint).then(prepared => {\n if (prepared === null) {\n reject('An event processor returned null, will not send event.');\n return;\n }\n\n let finalEvent: Event | null = prepared;\n\n try {\n const isInternalException = hint && hint.data && (hint.data as { [key: string]: any }).__sentry__ === true;\n if (isInternalException || !beforeSend) {\n this._getBackend().sendEvent(finalEvent);\n resolve(finalEvent);\n return;\n }\n\n const beforeSendResult = beforeSend(prepared, hint);\n if ((typeof beforeSendResult as any) === 'undefined') {\n logger.error('`beforeSend` method has to return `null` or a valid event.');\n } else if (isThenable(beforeSendResult)) {\n this._handleAsyncBeforeSend(beforeSendResult as Promise<Event | null>, resolve, reject);\n } else {\n finalEvent = beforeSendResult as Event | null;\n\n if (finalEvent === null) {\n logger.log('`beforeSend` returned `null`, will not send event.');\n resolve(null);\n return;\n }\n\n // From here on we are really async\n this._getBackend().sendEvent(finalEvent);\n resolve(finalEvent);\n }\n } catch (exception) {\n this.captureException(exception, {\n data: {\n __sentry__: true,\n },\n originalException: exception as Error,\n });\n reject('`beforeSend` throw an error, will not send event.');\n }\n });\n });\n }\n\n /**\n * Resolves before send Promise and calls resolve/reject on parent SyncPromise.\n */\n private _handleAsyncBeforeSend(\n beforeSend: Promise<Event | null>,\n resolve: (event: Event) => void,\n reject: (reason: string) => void,\n ): void {\n beforeSend\n .then(processedEvent => {\n if (processedEvent === null) {\n reject('`beforeSend` returned `null`, will not send event.');\n return;\n }\n // From here on we are really async\n this._getBackend().sendEvent(processedEvent);\n resolve(processedEvent);\n })\n .catch(e => {\n reject(`beforeSend rejected with ${e}`);\n });\n }\n}\n"]}
{"version":3,"file":"baseclient.js","sourceRoot":"","sources":["../src/baseclient.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAG9F,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAoB,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH;IAuBE;;;;;OAKG;IACH,oBAAsB,YAAgC,EAAE,OAAU;QAZlE,6CAA6C;QACnC,gBAAW,GAAY,KAAK,CAAC;QAYrC,IAAI,CAAC,QAAQ,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QAExB,IAAI,OAAO,CAAC,GAAG,EAAE;YACf,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;SAClC;QAED,IAAI,CAAC,aAAa,GAAG,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACxD,CAAC;IAED;;OAEG;IACI,qCAAgB,GAAvB,UAAwB,SAAc,EAAE,IAAgB,EAAE,KAAa;QAAvE,iBAkBC;QAjBC,IAAI,OAAO,GAAuB,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC;QACxD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAExB,IAAI,CAAC,WAAW,EAAE;aACf,kBAAkB,CAAC,SAAS,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AAW,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;wBACzC,OAAO,CAAC,UAAU,CAAC,CAAC;qBACrB;iBACF;gBAAC,OAAO,SAAS,EAAE;oBAClB,KAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE;wBAC/B,IAAI,EAAE;4BACJ,UAAU,EAAE,IAAI;yBACjB;wBACD,iBAAiB,EAAE,SAAkB;qBACtC,CAAC,CAAC;oBACH,MAAM,CAAC,mDAAmD,CAAC,CAAC;iBAC7D;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACK,2CAAsB,GAA9B,UACE,UAAiC,EACjC,OAA+B,EAC/B,MAAgC;QAHlC,iBAkBC;QAbC,UAAU;aACP,IAAI,CAAC,UAAA,cAAc;YAClB,IAAI,cAAc,KAAK,IAAI,EAAE;gBAC3B,MAAM,CAAC,oDAAoD,CAAC,CAAC;gBAC7D,OAAO;aACR;YACD,mCAAmC;YACnC,KAAI,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;YAC7C,OAAO,CAAC,cAAc,CAAC,CAAC;QAC1B,CAAC,CAAC;aACD,KAAK,CAAC,UAAA,CAAC;YACN,MAAM,CAAC,8BAA4B,CAAG,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACP,CAAC;IACH,iBAAC;AAAD,CAAC,AA7WD,IA6WC","sourcesContent":["import { Scope } from '@sentry/hub';\nimport { Client, Event, EventHint, Integration, IntegrationClass, Options, SdkInfo, Severity } from '@sentry/types';\nimport { isPrimitive, isThenable, logger, SyncPromise, truncate, uuid4 } from '@sentry/utils';\n\nimport { Backend, BackendClass } from './basebackend';\nimport { Dsn } from './dsn';\nimport { IntegrationIndex, setupIntegrations } from './integration';\n\n/**\n * Base implementation for all JavaScript SDK clients.\n *\n * Call the constructor with the corresponding backend constructor and options\n * specific to the client subclass. To access these options later, use\n * {@link Client.getOptions}. Also, the Backend instance is available via\n * {@link Client.getBackend}.\n *\n * If a Dsn is specified in the options, it will be parsed and stored. Use\n * {@link Client.getDsn} to retrieve the Dsn at any moment. In case the Dsn is\n * invalid, the constructor will throw a {@link SentryException}. Note that\n * without a valid Dsn, the SDK will not send any events to Sentry.\n *\n * Before sending an event via the backend, it is passed through\n * {@link BaseClient.prepareEvent} to add SDK information and scope data\n * (breadcrumbs and context). To add more custom information, override this\n * method and extend the resulting prepared event.\n *\n * To issue automatically created events (e.g. via instrumentation), use\n * {@link Client.captureEvent}. It will prepare the event and pass it through\n * the callback lifecycle. To issue auto-breadcrumbs, use\n * {@link Client.addBreadcrumb}.\n *\n * @example\n * class NodeClient extends BaseClient<NodeBackend, NodeOptions> {\n * public constructor(options: NodeOptions) {\n * super(NodeBackend, options);\n * }\n *\n * // ...\n * }\n */\nexport abstract class BaseClient<B extends Backend, O extends Options> implements Client<O> {\n /**\n * The backend used to physically interact in the enviornment. Usually, this\n * will correspond to the client. When composing SDKs, however, the Backend\n * from the root SDK will be used.\n */\n protected readonly _backend: B;\n\n /** Options passed to the SDK. */\n protected readonly _options: O;\n\n /** The client Dsn, if specified in options. Without this Dsn, the SDK will be disabled. */\n protected readonly _dsn?: Dsn;\n\n /** Array of used integrations. */\n protected readonly _integrations: IntegrationIndex;\n\n /** Is the client still processing a call? */\n protected _processing: boolean = false;\n\n /** Processing interval */\n protected _processingInterval?: number;\n\n /**\n * Initializes this client instance.\n *\n * @param backendClass A constructor function to create the backend.\n * @param options Options for the client.\n */\n protected constructor(backendClass: BackendClass<B, O>, options: O) {\n this._backend = new backendClass(options);\n this._options = options;\n\n if (options.dsn) {\n this._dsn = new Dsn(options.dsn);\n }\n\n this._integrations = setupIntegrations(this._options);\n }\n\n /**\n * @inheritDoc\n */\n public captureException(exception: any, hint?: EventHint, scope?: Scope): string | undefined {\n let eventId: string | undefined = hint && hint.event_id;\n this._processing = true;\n\n this._getBackend()\n .eventFromException(exception, hint)\n .then(event => this._processEvent(event, hint, scope))\n .then(finalEvent => {\n // We need to check for finalEvent in case beforeSend returned null\n eventId = finalEvent && finalEvent.event_id;\n this._processing = false;\n })\n .catch(reason => {\n logger.log(reason);\n this._processing = false;\n });\n\n return eventId;\n }\n\n /**\n * @inheritDoc\n */\n public captureMessage(message: string, level?: Severity, hint?: EventHint, scope?: Scope): string | undefined {\n let eventId: string | undefined = hint && hint.event_id;\n\n this._processing = true;\n\n const promisedEvent = isPrimitive(message)\n ? this._getBackend().eventFromMessage(`${message}`, level, hint)\n : this._getBackend().eventFromException(message, hint);\n\n promisedEvent\n .then(event => this._processEvent(event, hint, scope))\n .then(finalEvent => {\n // We need to check for finalEvent in case beforeSend returned null\n eventId = finalEvent && finalEvent.event_id;\n this._processing = false;\n })\n .catch(reason => {\n logger.log(reason);\n this._processing = false;\n });\n\n return eventId;\n }\n\n /**\n * @inheritDoc\n */\n public captureEvent(event: Event, hint?: EventHint, scope?: Scope): string | undefined {\n let eventId: string | undefined = hint && hint.event_id;\n this._processing = true;\n\n this._processEvent(event, hint, scope)\n .then(finalEvent => {\n // We need to check for finalEvent in case beforeSend returned null\n eventId = finalEvent && finalEvent.event_id;\n this._processing = false;\n })\n .catch(reason => {\n logger.log(reason);\n this._processing = false;\n });\n return eventId;\n }\n\n /**\n * @inheritDoc\n */\n public getDsn(): Dsn | undefined {\n return this._dsn;\n }\n\n /**\n * @inheritDoc\n */\n public getOptions(): O {\n return this._options;\n }\n\n /**\n * @inheritDoc\n */\n public async flush(timeout?: number): Promise<boolean> {\n const clientReady = await this._isClientProcessing(timeout);\n if (this._processingInterval) {\n clearInterval(this._processingInterval);\n }\n const transportFlushed = await this._getBackend()\n .getTransport()\n .close(timeout);\n return clientReady && transportFlushed;\n }\n\n /**\n * @inheritDoc\n */\n public async close(timeout?: number): Promise<boolean> {\n this.getOptions().enabled = false;\n return this.flush(timeout);\n }\n\n /**\n * @inheritDoc\n */\n public getIntegrations(): IntegrationIndex {\n return this._integrations || {};\n }\n\n /**\n * @inheritDoc\n */\n public getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null {\n try {\n return (this._integrations[integration.id] as T) || null;\n } catch (_oO) {\n logger.warn(`Cannot retrieve integration ${integration.id} from the current Client`);\n return null;\n }\n }\n\n /** Waits for the client to be done with processing. */\n protected async _isClientProcessing(timeout?: number): Promise<boolean> {\n return new Promise<boolean>(resolve => {\n let ticked: number = 0;\n const tick: number = 1;\n if (this._processingInterval) {\n clearInterval(this._processingInterval);\n }\n this._processingInterval = (setInterval(() => {\n if (!this._processing) {\n resolve(true);\n } else {\n ticked += tick;\n if (timeout && ticked >= timeout) {\n resolve(false);\n }\n }\n }, tick) as unknown) as number;\n });\n }\n\n /** Returns the current backend. */\n protected _getBackend(): B {\n return this._backend;\n }\n\n /** Determines whether this SDK is enabled and a valid Dsn is present. */\n protected _isEnabled(): boolean {\n return this.getOptions().enabled !== false && this._dsn !== undefined;\n }\n\n /**\n * Adds common information to events.\n *\n * The information includes release and environment from `options`,\n * breadcrumbs and context (extra, tags and user) from the scope.\n *\n * Information that is already present in the event is never overwritten. For\n * nested objects, such as the context, keys are merged.\n *\n * @param event The original event.\n * @param hint May contain additional informartion about the original exception.\n * @param scope A scope containing event metadata.\n * @returns A new event with more information.\n */\n protected _prepareEvent(event: Event, scope?: Scope, hint?: EventHint): SyncPromise<Event | null> {\n const { environment, release, dist, maxValueLength = 250 } = this.getOptions();\n\n const prepared: Event = { ...event };\n if (prepared.environment === undefined && environment !== undefined) {\n prepared.environment = environment;\n }\n if (prepared.release === undefined && release !== undefined) {\n prepared.release = release;\n }\n\n if (prepared.dist === undefined && dist !== undefined) {\n prepared.dist = dist;\n }\n\n if (prepared.message) {\n prepared.message = truncate(prepared.message, maxValueLength);\n }\n\n const exception = prepared.exception && prepared.exception.values && prepared.exception.values[0];\n if (exception && exception.value) {\n exception.value = truncate(exception.value, maxValueLength);\n }\n\n const request = prepared.request;\n if (request && request.url) {\n request.url = truncate(request.url, maxValueLength);\n }\n\n if (prepared.event_id === undefined) {\n prepared.event_id = uuid4();\n }\n\n this._addIntegrations(prepared.sdk);\n\n // We prepare the result here with a resolved Event.\n let result = SyncPromise.resolve<Event | null>(prepared);\n\n // This should be the last thing called, since we want that\n // {@link Hub.addEventProcessor} gets the finished prepared event.\n if (scope) {\n // In case we have a hub we reassign it.\n result = scope.applyToEvent(prepared, hint);\n }\n\n return result;\n }\n\n /**\n * This function adds all used integrations to the SDK info in the event.\n * @param sdkInfo The sdkInfo of the event that will be filled with all integrations.\n */\n protected _addIntegrations(sdkInfo?: SdkInfo): void {\n const integrationsArray = Object.keys(this._integrations);\n if (sdkInfo && integrationsArray.length > 0) {\n sdkInfo.integrations = integrationsArray;\n }\n }\n\n /**\n * Processes an event (either error or message) and sends it to Sentry.\n *\n * This also adds breadcrumbs and context information to the event. However,\n * platform specific meta data (such as the User's IP address) must be added\n * by the SDK implementor.\n *\n *\n * @param event The event to send to Sentry.\n * @param hint May contain additional informartion about the original exception.\n * @param scope A scope containing event metadata.\n * @returns A SyncPromise that resolves with the event or rejects in case event was/will not be send.\n */\n protected _processEvent(event: Event, hint?: EventHint, scope?: Scope): SyncPromise<Event> {\n const { beforeSend, sampleRate } = this.getOptions();\n\n if (!this._isEnabled()) {\n return SyncPromise.reject('SDK not enabled, will not send event.');\n }\n\n // 1.0 === 100% events are sent\n // 0.0 === 0% events are sent\n if (typeof sampleRate === 'number' && Math.random() > sampleRate) {\n return SyncPromise.reject('This event has been sampled, will not send event.');\n }\n\n return new SyncPromise((resolve, reject) => {\n this._prepareEvent(event, scope, hint).then(prepared => {\n if (prepared === null) {\n reject('An event processor returned null, will not send event.');\n return;\n }\n\n let finalEvent: Event | null = prepared;\n\n try {\n const isInternalException = hint && hint.data && (hint.data as { [key: string]: any }).__sentry__ === true;\n if (isInternalException || !beforeSend) {\n this._getBackend().sendEvent(finalEvent);\n resolve(finalEvent);\n return;\n }\n\n const beforeSendResult = beforeSend(prepared, hint);\n if ((typeof beforeSendResult as any) === 'undefined') {\n logger.error('`beforeSend` method has to return `null` or a valid event.');\n } else if (isThenable(beforeSendResult)) {\n this._handleAsyncBeforeSend(beforeSendResult as Promise<Event | null>, resolve, reject);\n } else {\n finalEvent = beforeSendResult as Event | null;\n\n if (finalEvent === null) {\n logger.log('`beforeSend` returned `null`, will not send event.');\n resolve(null);\n return;\n }\n\n // From here on we are really async\n this._getBackend().sendEvent(finalEvent);\n resolve(finalEvent);\n }\n } catch (exception) {\n this.captureException(exception, {\n data: {\n __sentry__: true,\n },\n originalException: exception as Error,\n });\n reject('`beforeSend` throw an error, will not send event.');\n }\n });\n });\n }\n\n /**\n * Resolves before send Promise and calls resolve/reject on parent SyncPromise.\n */\n private _handleAsyncBeforeSend(\n beforeSend: Promise<Event | null>,\n resolve: (event: Event) => void,\n reject: (reason: string) => void,\n ): void {\n beforeSend\n .then(processedEvent => {\n if (processedEvent === null) {\n reject('`beforeSend` returned `null`, will not send event.');\n return;\n }\n // From here on we are really async\n this._getBackend().sendEvent(processedEvent);\n resolve(processedEvent);\n })\n .catch(e => {\n reject(`beforeSend rejected with ${e}`);\n });\n }\n}\n"]}
{
"name": "@sentry/core",
"version": "5.0.6",
"version": "5.0.7",
"description": "Base implementation for all Sentry JavaScript SDKs",

@@ -19,6 +19,6 @@ "repository": "git://github.com/getsentry/sentry-javascript.git",

"dependencies": {
"@sentry/hub": "5.0.6",
"@sentry/minimal": "5.0.6",
"@sentry/hub": "5.0.7",
"@sentry/minimal": "5.0.7",
"@sentry/types": "5.0.6",
"@sentry/utils": "5.0.6",
"@sentry/utils": "5.0.7",
"tslib": "^1.9.3"

@@ -25,0 +25,0 @@ },