Socket
Socket
Sign inDemoInstall

@sentry/hub

Package Overview
Dependencies
Maintainers
9
Versions
430
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sentry/hub - npm Package Compare versions

Comparing version 4.6.4 to 5.0.0-rc.0

132

dist/hub.d.ts

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

import { Breadcrumb, Integration, IntegrationClass, SentryBreadcrumbHint, SentryEvent, SentryEventHint, Severity } from '@sentry/types';
import { Breadcrumb, BreadcrumbHint, Client, Event, EventHint, Hub as HubInterface, Integration, IntegrationClass, Severity } from '@sentry/types';
import { Carrier, Layer } from './interfaces';

@@ -18,12 +18,13 @@ import { Scope } from './scope';

* changes a and new methods are introduced.
*
* @hidden
*/
export declare const API_VERSION = 3;
/**
* Internal class used to make sure we always have the latest internal functions
* working in case we have a version conflict.
* @inheritDoc
*/
export declare class Hub {
private readonly version;
export declare class Hub implements HubInterface {
private readonly _version;
/** Is a {@link Layer}[] containing the client and scope */
private readonly stack;
private readonly _stack;
/** Contains the last event id of a captured event. */

@@ -39,65 +40,34 @@ private _lastEventId?;

*/
constructor(client?: any, scope?: Scope, version?: number);
constructor(client?: Client, scope?: Scope, _version?: number);
/**
* Internal helper function to call a method on the top client if it exists.
*
* @param method The method to call on the client/client.
* @param args Arguments to pass to the client/frontend.
* @param method The method to call on the client.
* @param args Arguments to pass to the client function.
*/
private invokeClient;
private _invokeClient;
/**
* Internal helper function to call an async method on the top client if it
* exists.
*
* @param method The method to call on the client/client.
* @param args Arguments to pass to the client/frontend.
* @inheritDoc
*/
private invokeClientAsync;
/**
* Checks if this hub's version is older than the given version.
*
* @param version A version number to compare to.
* @return True if the given version is newer; otherwise false.
*/
isOlderThan(version: number): boolean;
/**
* This binds the given client to the current scope.
* @param client An SDK client (client) instance.
* @inheritDoc
*/
bindClient(client?: any): void;
bindClient(client?: Client): void;
/**
* Create a new scope to store context information.
*
* The scope will be layered on top of the current one. It is isolated, i.e. all
* breadcrumbs and context information added to this scope will be removed once
* the scope ends. Be sure to always remove this scope with {@link this.popScope}
* when the operation finishes or throws.
*
* @returns Scope, the new cloned scope
* @inheritDoc
*/
pushScope(): Scope;
/**
* Removes a previously pushed scope from the stack.
*
* This restores the state before the scope was pushed. All breadcrumbs and
* context information added since the last call to {@link this.pushScope} are
* discarded.
* @inheritDoc
*/
popScope(): boolean;
/**
* Creates a new scope with and executes the given operation within.
* The scope is automatically removed once the operation
* finishes or throws.
*
* This is essentially a convenience function for:
*
* pushScope();
* callback();
* popScope();
*
* @param callback that will be enclosed into push/popScope.
* @inheritDoc
*/
withScope(callback: ((scope: Scope) => void)): void;
/** Returns the client of the top stack. */
getClient(): any | undefined;
withScope(callback: (scope: Scope) => void): void;
/**
* @inheritDoc
*/
getClient<C extends Client>(): C | undefined;
/** Returns the scope of the top stack. */

@@ -110,54 +80,32 @@ getScope(): Scope | undefined;

/**
* Captures an exception event and sends it to Sentry.
*
* @param exception An exception-like object.
* @param hint May contain additional information about the original exception.
* @returns The generated eventId.
* @inheritDoc
*/
captureException(exception: any, hint?: SentryEventHint): string;
captureException(exception: any, hint?: EventHint): string;
/**
* Captures a message event and sends it to Sentry.
*
* @param message The message to send to Sentry.
* @param level Define the level of the message.
* @param hint May contain additional information about the original exception.
* @returns The generated eventId.
* @inheritDoc
*/
captureMessage(message: string, level?: Severity, hint?: SentryEventHint): string;
captureMessage(message: string, level?: Severity, hint?: EventHint): string;
/**
* Captures a manually created event and sends it to Sentry.
*
* @param event The event to send to Sentry.
* @param hint May contain additional information about the original exception.
* @inheritDoc
*/
captureEvent(event: SentryEvent, hint?: SentryEventHint): string;
captureEvent(event: Event, hint?: EventHint): string;
/**
* This is the getter for lastEventId.
*
* @returns The last event id of a captured event.
* @inheritDoc
*/
lastEventId(): string | undefined;
/**
* Records a new breadcrumb which will be attached to future events.
*
* Breadcrumbs will be added to subsequent events to provide more context on
* user's actions prior to an error or crash.
*
* @param breadcrumb The breadcrumb to record.
* @param hint May contain additional information about the original breadcrumb.
* @inheritDoc
*/
addBreadcrumb(breadcrumb: Breadcrumb, hint?: SentryBreadcrumbHint): void;
addBreadcrumb(breadcrumb: Breadcrumb, hint?: BreadcrumbHint): void;
/**
* Callback to set context information onto the scope.
*
* @param callback Callback function that receives Scope.
* @inheritDoc
*/
configureScope(callback: (scope: Scope) => void): void;
/**
* For the duraction of the callback, this hub will be set as the global current Hub.
* This function is useful if you want to run your own client and hook into an already initialized one
* e.g.: Reporting issues to your own sentry when running in your component while still using the users configuration.
* @inheritDoc
*/
run(callback: ((hub: Hub) => void)): void;
/** Returns the integration if installed on the current client. */
run(callback: (hub: Hub) => void): void;
/**
* @inheritDoc
*/
getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null;

@@ -182,10 +130,6 @@ }

/**
* This will tell whether a carrier has a hub on it or not
* @param carrier object
*/
export declare function hasHubOnCarrier(carrier: any): boolean;
/**
* This will create a new {@link Hub} and add to the passed object on
* __SENTRY__.hub.
* @param carrier object
* @hidden
*/

@@ -192,0 +136,0 @@ export declare function getHubFromCarrier(carrier: any): Hub;

@@ -12,8 +12,19 @@ "use strict";

* changes a and new methods are introduced.
*
* @hidden
*/
exports.API_VERSION = 3;
/**
* Internal class used to make sure we always have the latest internal functions
* working in case we have a version conflict.
* Default maximum number of breadcrumbs added to an event. Can be overwritten
* with {@link Options.maxBreadcrumbs}.
*/
var DEFAULT_BREADCRUMBS = 30;
/**
* Absolute maximum number of breadcrumbs added to an event. The
* `maxBreadcrumbs` option cannot be higher than this value.
*/
var MAX_BREADCRUMBS = 100;
/**
* @inheritDoc
*/
var Hub = /** @class */ (function () {

@@ -28,9 +39,9 @@ /**

*/
function Hub(client, scope, version) {
function Hub(client, scope, _version) {
if (scope === void 0) { scope = new scope_1.Scope(); }
if (version === void 0) { version = exports.API_VERSION; }
this.version = version;
if (_version === void 0) { _version = exports.API_VERSION; }
this._version = _version;
/** Is a {@link Layer}[] containing the client and scope */
this.stack = [];
this.stack.push({ client: client, scope: scope });
this._stack = [];
this._stack.push({ client: client, scope: scope });
}

@@ -40,6 +51,6 @@ /**

*
* @param method The method to call on the client/client.
* @param args Arguments to pass to the client/frontend.
* @param method The method to call on the client.
* @param args Arguments to pass to the client function.
*/
Hub.prototype.invokeClient = function (method) {
Hub.prototype._invokeClient = function (method) {
var args = [];

@@ -56,33 +67,9 @@ for (var _i = 1; _i < arguments.length; _i++) {

/**
* Internal helper function to call an async method on the top client if it
* exists.
*
* @param method The method to call on the client/client.
* @param args Arguments to pass to the client/frontend.
* @inheritDoc
*/
Hub.prototype.invokeClientAsync = function (method) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
var _a;
var top = this.getStackTop();
if (top && top.client && top.client[method]) {
(_a = top.client)[method].apply(_a, tslib_1.__spread(args, [top.scope])).catch(function (err) {
logger_1.logger.error(err);
});
}
};
/**
* Checks if this hub's version is older than the given version.
*
* @param version A version number to compare to.
* @return True if the given version is newer; otherwise false.
*/
Hub.prototype.isOlderThan = function (version) {
return this.version < version;
return this._version < version;
};
/**
* This binds the given client to the current scope.
* @param client An SDK client (client) instance.
* @inheritDoc
*/

@@ -92,24 +79,5 @@ Hub.prototype.bindClient = function (client) {

top.client = client;
if (top && top.scope && client) {
top.scope.addScopeListener(function (s) {
if (client.getBackend) {
try {
client.getBackend().storeScope(s);
}
catch (_a) {
// Do nothing
}
}
});
}
};
/**
* Create a new scope to store context information.
*
* The scope will be layered on top of the current one. It is isolated, i.e. all
* breadcrumbs and context information added to this scope will be removed once
* the scope ends. Be sure to always remove this scope with {@link this.popScope}
* when the operation finishes or throws.
*
* @returns Scope, the new cloned scope
* @inheritDoc
*/

@@ -128,7 +96,3 @@ Hub.prototype.pushScope = function () {

/**
* Removes a previously pushed scope from the stack.
*
* This restores the state before the scope was pushed. All breadcrumbs and
* context information added since the last call to {@link this.pushScope} are
* discarded.
* @inheritDoc
*/

@@ -139,13 +103,3 @@ Hub.prototype.popScope = function () {

/**
* Creates a new scope with and executes the given operation within.
* The scope is automatically removed once the operation
* finishes or throws.
*
* This is essentially a convenience function for:
*
* pushScope();
* callback();
* popScope();
*
* @param callback that will be enclosed into push/popScope.
* @inheritDoc
*/

@@ -161,3 +115,5 @@ Hub.prototype.withScope = function (callback) {

};
/** Returns the client of the top stack. */
/**
* @inheritDoc
*/
Hub.prototype.getClient = function () {

@@ -172,48 +128,34 @@ return this.getStackTop().client;

Hub.prototype.getStack = function () {
return this.stack;
return this._stack;
};
/** Returns the topmost scope layer in the order domain > local > process. */
Hub.prototype.getStackTop = function () {
return this.stack[this.stack.length - 1];
return this._stack[this._stack.length - 1];
};
/**
* Captures an exception event and sends it to Sentry.
*
* @param exception An exception-like object.
* @param hint May contain additional information about the original exception.
* @returns The generated eventId.
* @inheritDoc
*/
Hub.prototype.captureException = function (exception, hint) {
var eventId = (this._lastEventId = misc_1.uuid4());
this.invokeClientAsync('captureException', exception, tslib_1.__assign({}, hint, { event_id: eventId }));
this._invokeClient('captureException', exception, tslib_1.__assign({}, hint, { event_id: eventId }));
return eventId;
};
/**
* Captures a message event and sends it to Sentry.
*
* @param message The message to send to Sentry.
* @param level Define the level of the message.
* @param hint May contain additional information about the original exception.
* @returns The generated eventId.
* @inheritDoc
*/
Hub.prototype.captureMessage = function (message, level, hint) {
var eventId = (this._lastEventId = misc_1.uuid4());
this.invokeClientAsync('captureMessage', message, level, tslib_1.__assign({}, hint, { event_id: eventId }));
this._invokeClient('captureMessage', message, level, tslib_1.__assign({}, hint, { event_id: eventId }));
return eventId;
};
/**
* Captures a manually created event and sends it to Sentry.
*
* @param event The event to send to Sentry.
* @param hint May contain additional information about the original exception.
* @inheritDoc
*/
Hub.prototype.captureEvent = function (event, hint) {
var eventId = (this._lastEventId = misc_1.uuid4());
this.invokeClientAsync('captureEvent', event, tslib_1.__assign({}, hint, { event_id: eventId }));
this._invokeClient('captureEvent', event, tslib_1.__assign({}, hint, { event_id: eventId }));
return eventId;
};
/**
* This is the getter for lastEventId.
*
* @returns The last event id of a captured event.
* @inheritDoc
*/

@@ -224,17 +166,25 @@ Hub.prototype.lastEventId = function () {

/**
* Records a new breadcrumb which will be attached to future events.
*
* Breadcrumbs will be added to subsequent events to provide more context on
* user's actions prior to an error or crash.
*
* @param breadcrumb The breadcrumb to record.
* @param hint May contain additional information about the original breadcrumb.
* @inheritDoc
*/
Hub.prototype.addBreadcrumb = function (breadcrumb, hint) {
this.invokeClient('addBreadcrumb', breadcrumb, tslib_1.__assign({}, hint));
var top = this.getStackTop();
if (!top.scope || !top.client) {
return;
}
var _a = top.client.getOptions(), beforeBreadcrumb = _a.beforeBreadcrumb, _b = _a.maxBreadcrumbs, maxBreadcrumbs = _b === void 0 ? DEFAULT_BREADCRUMBS : _b;
if (maxBreadcrumbs <= 0) {
return;
}
var timestamp = new Date().getTime() / 1000;
var mergedBreadcrumb = tslib_1.__assign({ timestamp: timestamp }, breadcrumb);
var finalBreadcrumb = beforeBreadcrumb
? misc_1.consoleSandbox(function () { return beforeBreadcrumb(mergedBreadcrumb, hint); })
: mergedBreadcrumb;
if (finalBreadcrumb === null) {
return;
}
top.scope.addBreadcrumb(finalBreadcrumb, Math.min(maxBreadcrumbs, MAX_BREADCRUMBS));
};
/**
* Callback to set context information onto the scope.
*
* @param callback Callback function that receives Scope.
* @inheritDoc
*/

@@ -249,5 +199,3 @@ Hub.prototype.configureScope = function (callback) {

/**
* For the duraction of the callback, this hub will be set as the global current Hub.
* This function is useful if you want to run your own client and hook into an already initialized one
* e.g.: Reporting issues to your own sentry when running in your component while still using the users configuration.
* @inheritDoc
*/

@@ -263,6 +211,12 @@ Hub.prototype.run = function (callback) {

};
/** Returns the integration if installed on the current client. */
/**
* @inheritDoc
*/
Hub.prototype.getIntegration = function (integration) {
var client = this.getClient();
if (!client) {
return null;
}
try {
return this.getClient().getIntegration(integration);
return client.getIntegration(integration);
}

@@ -345,7 +299,4 @@ catch (_oO) {

}
else {
return false;
}
return false;
}
exports.hasHubOnCarrier = hasHubOnCarrier;
/**

@@ -355,2 +306,3 @@ * This will create a new {@link Hub} and add to the passed object on

* @param carrier object
* @hidden
*/

@@ -361,7 +313,5 @@ function getHubFromCarrier(carrier) {

}
else {
carrier.__SENTRY__ = {};
carrier.__SENTRY__.hub = new Hub();
return carrier.__SENTRY__.hub;
}
carrier.__SENTRY__ = {};
carrier.__SENTRY__.hub = new Hub();
return carrier.__SENTRY__.hub;
}

@@ -368,0 +318,0 @@ exports.getHubFromCarrier = getHubFromCarrier;

export { Carrier, Layer } from './interfaces';
export { addGlobalEventProcessor, Scope } from './scope';
export { getCurrentHub, getHubFromCarrier, getMainCarrier, Hub, setHubOnCarrier } from './hub';
export { getCurrentHub, getHubFromCarrier, getMainCarrier, Hub, makeMain, setHubOnCarrier } from './hub';

@@ -11,3 +11,4 @@ "use strict";

exports.Hub = hub_1.Hub;
exports.makeMain = hub_1.makeMain;
exports.setHubOnCarrier = hub_1.setHubOnCarrier;
//# sourceMappingURL=index.js.map

@@ -0,9 +1,16 @@

import { Client } from '@sentry/types';
import { Hub } from './hub';
import { Scope } from './scope';
/** A layer in the process stack. */
/**
* A layer in the process stack.
* @hidden
*/
export interface Layer {
client?: any;
client?: Client;
scope?: Scope;
}
/** An object that contains a hub and maintains a scope stack. */
/**
* An object that contains a hub and maintains a scope stack.
* @hidden
*/
export interface Carrier {

@@ -10,0 +17,0 @@ __SENTRY__?: {

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

import { Breadcrumb, SentryEvent, SentryEventHint, Severity, User } from '@sentry/types';
export declare type EventProcessor = (event: SentryEvent, hint?: SentryEventHint) => Promise<SentryEvent | null> | SentryEvent | null;
import { Breadcrumb, Event, EventHint, EventProcessor, Scope as ScopeInterface, Severity, User } from '@sentry/types';
import { SyncPromise } from '@sentry/utils/syncpromise';
/**

@@ -7,63 +7,75 @@ * Holds additional event information. {@link Scope.applyToEvent} will be

*/
export declare class Scope {
export declare class Scope implements ScopeInterface {
/** Flag if notifiying is happening. */
protected notifyingListeners: boolean;
protected _notifyingListeners: boolean;
/** Callback for client to receive scope changes. */
protected scopeListeners: Array<(scope: Scope) => void>;
protected _scopeListeners: Array<(scope: Scope) => void>;
/** Callback list that will be called after {@link applyToEvent}. */
protected eventProcessors: EventProcessor[];
protected _eventProcessors: EventProcessor[];
/** Array of breadcrumbs. */
protected breadcrumbs: Breadcrumb[];
protected _breadcrumbs: Breadcrumb[];
/** User */
protected user: User;
protected _user: User;
/** Tags */
protected tags: {
protected _tags: {
[key: string]: string;
};
/** Extra */
protected extra: {
protected _extra: {
[key: string]: any;
};
/** Fingerprint */
protected fingerprint?: string[];
protected _fingerprint?: string[];
/** Severity */
protected level?: Severity;
/** Add internal on change listener. */
protected _level?: Severity;
/**
* Add internal on change listener. Used for sub SDKs that need to store the scope.
* @hidden
*/
addScopeListener(callback: (scope: Scope) => void): void;
/** Add new event processor that will be called after {@link applyToEvent}. */
addEventProcessor(callback: EventProcessor): Scope;
/**
* @inheritDoc
*/
addEventProcessor(callback: EventProcessor): this;
/**
* This will be called on every set call.
*/
protected notifyScopeListeners(): void;
protected _notifyScopeListeners(): void;
/**
* This will be called after {@link applyToEvent} is finished.
*/
protected notifyEventProcessors(event: SentryEvent, hint?: SentryEventHint): Promise<SentryEvent | null>;
protected _notifyEventProcessors(processors: EventProcessor[], event: Event | null, hint?: EventHint, index?: number): SyncPromise<Event | null>;
/**
* Updates user context information for future events.
* @param user User context object to be set in the current context.
* @inheritDoc
*/
setUser(user: User): Scope;
setUser(user: User): this;
/**
* Updates tags context information for future events.
* @param tags Tags context object to merge into current context.
* @inheritDoc
*/
setTag(key: string, value: string): Scope;
setTags(tags: {
[key: string]: string;
}): this;
/**
* Updates extra context information for future events.
* @param extra context object to merge into current context.
* @inheritDoc
*/
setExtra(key: string, extra: any): Scope;
setTag(key: string, value: string): this;
/**
* Sets the fingerprint on the scope to send with the events.
* @param fingerprint string[] to group events in Sentry.
* @inheritDoc
*/
setFingerprint(fingerprint: string[]): Scope;
setExtras(extra: {
[key: string]: any;
}): this;
/**
* Sets the level on the scope for future events.
* @param level string {@link Severity}
* @inheritDoc
*/
setLevel(level: Severity): Scope;
setExtra(key: string, extra: any): this;
/**
* @inheritDoc
*/
setFingerprint(fingerprint: string[]): this;
/**
* @inheritDoc
*/
setLevel(level: Severity): this;
/**
* Inherit values from the parent scope.

@@ -73,15 +85,19 @@ * @param scope to clone.

static clone(scope?: Scope): Scope;
/** Clears the current scope and resets its properties. */
clear(): void;
/**
* Sets the breadcrumbs in the scope
* @param breadcrumbs Breadcrumb
* @param maxBreadcrumbs number of max breadcrumbs to merged into event.
* @inheritDoc
*/
addBreadcrumb(breadcrumb: Breadcrumb, maxBreadcrumbs?: number): void;
clear(): this;
/**
* @inheritDoc
*/
addBreadcrumb(breadcrumb: Breadcrumb, maxBreadcrumbs?: number): this;
/**
* @inheritDoc
*/
clearBreadcrumbs(): this;
/**
* Applies fingerprint from the scope to the event if there's one,
* uses message if there's one instead or get rid of empty fingerprint
*/
private applyFingerprint;
private _applyFingerprint;
/**

@@ -91,7 +107,8 @@ * Applies the current context and fingerprint to the event.

* Also if the event has already breadcrumbs on it, we do not merge them.
* @param event SentryEvent
* @param event Event
* @param hint May contain additional informartion about the original exception.
* @param maxBreadcrumbs number of max breadcrumbs to merged into event.
* @hidden
*/
applyToEvent(event: SentryEvent, hint?: SentryEventHint, maxBreadcrumbs?: number): Promise<SentryEvent | null>;
applyToEvent(event: Event, hint?: EventHint): SyncPromise<Event | null>;
}

@@ -98,0 +115,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var is_1 = require("@sentry/utils/is");
var misc_1 = require("@sentry/utils/misc");
var object_1 = require("@sentry/utils/object");
var syncpromise_1 = require("@sentry/utils/syncpromise");
/**

@@ -13,23 +15,28 @@ * Holds additional event information. {@link Scope.applyToEvent} will be

/** Flag if notifiying is happening. */
this.notifyingListeners = false;
this._notifyingListeners = false;
/** Callback for client to receive scope changes. */
this.scopeListeners = [];
this._scopeListeners = [];
/** Callback list that will be called after {@link applyToEvent}. */
this.eventProcessors = [];
this._eventProcessors = [];
/** Array of breadcrumbs. */
this.breadcrumbs = [];
this._breadcrumbs = [];
/** User */
this.user = {};
this._user = {};
/** Tags */
this.tags = {};
this._tags = {};
/** Extra */
this.extra = {};
this._extra = {};
}
/** Add internal on change listener. */
/**
* Add internal on change listener. Used for sub SDKs that need to store the scope.
* @hidden
*/
Scope.prototype.addScopeListener = function (callback) {
this.scopeListeners.push(callback);
this._scopeListeners.push(callback);
};
/** Add new event processor that will be called after {@link applyToEvent}. */
/**
* @inheritDoc
*/
Scope.prototype.addEventProcessor = function (callback) {
this.eventProcessors.push(callback);
this._eventProcessors.push(callback);
return this;

@@ -40,11 +47,11 @@ };

*/
Scope.prototype.notifyScopeListeners = function () {
Scope.prototype._notifyScopeListeners = function () {
var _this = this;
if (!this.notifyingListeners) {
this.notifyingListeners = true;
if (!this._notifyingListeners) {
this._notifyingListeners = true;
setTimeout(function () {
_this.scopeListeners.forEach(function (callback) {
_this._scopeListeners.forEach(function (callback) {
callback(_this);
});
_this.notifyingListeners = false;
_this._notifyingListeners = false;
});

@@ -56,94 +63,82 @@ }

*/
Scope.prototype.notifyEventProcessors = function (event, hint) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var e_1, _a, processedEvent, _b, _c, processor, e_2, e_1_1;
return tslib_1.__generator(this, function (_d) {
switch (_d.label) {
case 0:
processedEvent = event;
_d.label = 1;
case 1:
_d.trys.push([1, 8, 9, 10]);
_b = tslib_1.__values(tslib_1.__spread(getGlobalEventProcessors(), this.eventProcessors)), _c = _b.next();
_d.label = 2;
case 2:
if (!!_c.done) return [3 /*break*/, 7];
processor = _c.value;
_d.label = 3;
case 3:
_d.trys.push([3, 5, , 6]);
return [4 /*yield*/, processor(tslib_1.__assign({}, processedEvent), hint)];
case 4:
processedEvent = _d.sent();
if (processedEvent === null) {
return [2 /*return*/, null];
}
return [3 /*break*/, 6];
case 5:
e_2 = _d.sent();
return [3 /*break*/, 6];
case 6:
_c = _b.next();
return [3 /*break*/, 2];
case 7: return [3 /*break*/, 10];
case 8:
e_1_1 = _d.sent();
e_1 = { error: e_1_1 };
return [3 /*break*/, 10];
case 9:
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
return [7 /*endfinally*/];
case 10: return [2 /*return*/, processedEvent];
Scope.prototype._notifyEventProcessors = function (processors, event, hint, index) {
var _this = this;
if (index === void 0) { index = 0; }
return new syncpromise_1.SyncPromise(function (resolve, reject) {
var processor = processors[index];
// tslint:disable-next-line:strict-type-predicates
if (event === null || typeof processor !== 'function') {
resolve(event);
}
else {
var result = processor(tslib_1.__assign({}, event), hint);
if (is_1.isThenable(result)) {
result
.then(function (final) { return _this._notifyEventProcessors(processors, final, hint, index + 1).then(resolve); })
.catch(reject);
}
});
else {
_this._notifyEventProcessors(processors, result, hint, index + 1)
.then(resolve)
.catch(reject);
}
}
});
};
/**
* Updates user context information for future events.
* @param user User context object to be set in the current context.
* @inheritDoc
*/
Scope.prototype.setUser = function (user) {
this.user = object_1.safeNormalize(user);
this.notifyScopeListeners();
this._user = object_1.normalize(user);
this._notifyScopeListeners();
return this;
};
/**
* Updates tags context information for future events.
* @param tags Tags context object to merge into current context.
* @inheritDoc
*/
Scope.prototype.setTags = function (tags) {
this._tags = tslib_1.__assign({}, this._tags, object_1.normalize(tags));
this._notifyScopeListeners();
return this;
};
/**
* @inheritDoc
*/
Scope.prototype.setTag = function (key, value) {
var _a;
this.tags = tslib_1.__assign({}, this.tags, (_a = {}, _a[key] = object_1.safeNormalize(value), _a));
this.notifyScopeListeners();
this._tags = tslib_1.__assign({}, this._tags, (_a = {}, _a[key] = object_1.normalize(value), _a));
this._notifyScopeListeners();
return this;
};
/**
* Updates extra context information for future events.
* @param extra context object to merge into current context.
* @inheritDoc
*/
Scope.prototype.setExtras = function (extra) {
this._extra = tslib_1.__assign({}, this._extra, object_1.normalize(extra));
this._notifyScopeListeners();
return this;
};
/**
* @inheritDoc
*/
Scope.prototype.setExtra = function (key, extra) {
var _a;
this.extra = tslib_1.__assign({}, this.extra, (_a = {}, _a[key] = object_1.safeNormalize(extra), _a));
this.notifyScopeListeners();
this._extra = tslib_1.__assign({}, this._extra, (_a = {}, _a[key] = object_1.normalize(extra), _a));
this._notifyScopeListeners();
return this;
};
/**
* Sets the fingerprint on the scope to send with the events.
* @param fingerprint string[] to group events in Sentry.
* @inheritDoc
*/
Scope.prototype.setFingerprint = function (fingerprint) {
this.fingerprint = object_1.safeNormalize(fingerprint);
this.notifyScopeListeners();
this._fingerprint = object_1.normalize(fingerprint);
this._notifyScopeListeners();
return this;
};
/**
* Sets the level on the scope for future events.
* @param level string {@link Severity}
* @inheritDoc
*/
Scope.prototype.setLevel = function (level) {
this.level = object_1.safeNormalize(level);
this.notifyScopeListeners();
this._level = object_1.normalize(level);
this._notifyScopeListeners();
return this;

@@ -157,40 +152,53 @@ };

var newScope = new Scope();
object_1.assign(newScope, scope, {
scopeListeners: [],
Object.assign(newScope, scope, {
_scopeListeners: [],
});
if (scope) {
newScope.extra = object_1.assign(scope.extra);
newScope.tags = object_1.assign(scope.tags);
newScope.breadcrumbs = tslib_1.__spread(scope.breadcrumbs);
newScope.eventProcessors = tslib_1.__spread(scope.eventProcessors);
newScope._breadcrumbs = tslib_1.__spread(scope._breadcrumbs);
newScope._tags = tslib_1.__assign({}, scope._tags);
newScope._extra = tslib_1.__assign({}, scope._extra);
newScope._user = scope._user;
newScope._level = scope._level;
newScope._fingerprint = scope._fingerprint;
newScope._eventProcessors = tslib_1.__spread(scope._eventProcessors);
}
return newScope;
};
/** Clears the current scope and resets its properties. */
/**
* @inheritDoc
*/
Scope.prototype.clear = function () {
this.breadcrumbs = [];
this.tags = {};
this.extra = {};
this.user = {};
this.level = undefined;
this.fingerprint = undefined;
this.notifyScopeListeners();
this._breadcrumbs = [];
this._tags = {};
this._extra = {};
this._user = {};
this._level = undefined;
this._fingerprint = undefined;
this._notifyScopeListeners();
return this;
};
/**
* Sets the breadcrumbs in the scope
* @param breadcrumbs Breadcrumb
* @param maxBreadcrumbs number of max breadcrumbs to merged into event.
* @inheritDoc
*/
Scope.prototype.addBreadcrumb = function (breadcrumb, maxBreadcrumbs) {
this.breadcrumbs =
this._breadcrumbs =
maxBreadcrumbs !== undefined && maxBreadcrumbs >= 0
? tslib_1.__spread(this.breadcrumbs, [object_1.safeNormalize(breadcrumb)]).slice(-maxBreadcrumbs)
: tslib_1.__spread(this.breadcrumbs, [object_1.safeNormalize(breadcrumb)]);
this.notifyScopeListeners();
? tslib_1.__spread(this._breadcrumbs, [object_1.normalize(breadcrumb)]).slice(-maxBreadcrumbs)
: tslib_1.__spread(this._breadcrumbs, [object_1.normalize(breadcrumb)]);
this._notifyScopeListeners();
return this;
};
/**
* @inheritDoc
*/
Scope.prototype.clearBreadcrumbs = function () {
this._breadcrumbs = [];
this._notifyScopeListeners();
return this;
};
/**
* Applies fingerprint from the scope to the event if there's one,
* uses message if there's one instead or get rid of empty fingerprint
*/
Scope.prototype.applyFingerprint = function (event) {
Scope.prototype._applyFingerprint = function (event) {
// Make sure it's an array first and we actually have something in place

@@ -203,9 +211,5 @@ event.fingerprint = event.fingerprint

// If we have something on the scope, then merge it with event
if (this.fingerprint) {
event.fingerprint = event.fingerprint.concat(this.fingerprint);
if (this._fingerprint) {
event.fingerprint = event.fingerprint.concat(this._fingerprint);
}
else if (event.message) {
// If not, but we have message, use it instead
event.fingerprint = event.fingerprint.concat(event.message);
}
// If we have no data at all, remove empty array default

@@ -220,33 +224,26 @@ if (event.fingerprint && !event.fingerprint.length) {

* Also if the event has already breadcrumbs on it, we do not merge them.
* @param event SentryEvent
* @param event Event
* @param hint May contain additional informartion about the original exception.
* @param maxBreadcrumbs number of max breadcrumbs to merged into event.
* @hidden
*/
Scope.prototype.applyToEvent = function (event, hint, maxBreadcrumbs) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var hasNoBreadcrumbs;
return tslib_1.__generator(this, function (_a) {
if (this.extra && Object.keys(this.extra).length) {
event.extra = tslib_1.__assign({}, this.extra, event.extra);
}
if (this.tags && Object.keys(this.tags).length) {
event.tags = tslib_1.__assign({}, this.tags, event.tags);
}
if (this.user && Object.keys(this.user).length) {
event.user = tslib_1.__assign({}, this.user, event.user);
}
if (this.level) {
event.level = this.level;
}
this.applyFingerprint(event);
hasNoBreadcrumbs = !event.breadcrumbs || event.breadcrumbs.length === 0;
if (hasNoBreadcrumbs && this.breadcrumbs.length > 0) {
event.breadcrumbs =
maxBreadcrumbs !== undefined && maxBreadcrumbs >= 0
? this.breadcrumbs.slice(-maxBreadcrumbs)
: this.breadcrumbs;
}
return [2 /*return*/, this.notifyEventProcessors(event, hint)];
});
});
Scope.prototype.applyToEvent = function (event, hint) {
if (this._extra && Object.keys(this._extra).length) {
event.extra = tslib_1.__assign({}, this._extra, event.extra);
}
if (this._tags && Object.keys(this._tags).length) {
event.tags = tslib_1.__assign({}, this._tags, event.tags);
}
if (this._user && Object.keys(this._user).length) {
event.user = tslib_1.__assign({}, this._user, event.user);
}
if (this._level) {
event.level = this._level;
}
this._applyFingerprint(event);
var hasNoBreadcrumbs = !event.breadcrumbs || event.breadcrumbs.length === 0;
if (hasNoBreadcrumbs && this._breadcrumbs.length > 0) {
event.breadcrumbs = this._breadcrumbs;
}
return this._notifyEventProcessors(tslib_1.__spread(getGlobalEventProcessors(), this._eventProcessors), event, hint);
};

@@ -253,0 +250,0 @@ return Scope;

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

import { Breadcrumb, Integration, IntegrationClass, SentryBreadcrumbHint, SentryEvent, SentryEventHint, Severity } from '@sentry/types/esm';
import { Breadcrumb, BreadcrumbHint, Client, Event, EventHint, Hub as HubInterface, Integration, IntegrationClass, Severity } from '@sentry/types';
import { Carrier, Layer } from './interfaces';

@@ -18,12 +18,13 @@ import { Scope } from './scope';

* changes a and new methods are introduced.
*
* @hidden
*/
export declare const API_VERSION = 3;
/**
* Internal class used to make sure we always have the latest internal functions
* working in case we have a version conflict.
* @inheritDoc
*/
export declare class Hub {
private readonly version;
export declare class Hub implements HubInterface {
private readonly _version;
/** Is a {@link Layer}[] containing the client and scope */
private readonly stack;
private readonly _stack;
/** Contains the last event id of a captured event. */

@@ -39,65 +40,34 @@ private _lastEventId?;

*/
constructor(client?: any, scope?: Scope, version?: number);
constructor(client?: Client, scope?: Scope, _version?: number);
/**
* Internal helper function to call a method on the top client if it exists.
*
* @param method The method to call on the client/client.
* @param args Arguments to pass to the client/frontend.
* @param method The method to call on the client.
* @param args Arguments to pass to the client function.
*/
private invokeClient;
private _invokeClient;
/**
* Internal helper function to call an async method on the top client if it
* exists.
*
* @param method The method to call on the client/client.
* @param args Arguments to pass to the client/frontend.
* @inheritDoc
*/
private invokeClientAsync;
/**
* Checks if this hub's version is older than the given version.
*
* @param version A version number to compare to.
* @return True if the given version is newer; otherwise false.
*/
isOlderThan(version: number): boolean;
/**
* This binds the given client to the current scope.
* @param client An SDK client (client) instance.
* @inheritDoc
*/
bindClient(client?: any): void;
bindClient(client?: Client): void;
/**
* Create a new scope to store context information.
*
* The scope will be layered on top of the current one. It is isolated, i.e. all
* breadcrumbs and context information added to this scope will be removed once
* the scope ends. Be sure to always remove this scope with {@link this.popScope}
* when the operation finishes or throws.
*
* @returns Scope, the new cloned scope
* @inheritDoc
*/
pushScope(): Scope;
/**
* Removes a previously pushed scope from the stack.
*
* This restores the state before the scope was pushed. All breadcrumbs and
* context information added since the last call to {@link this.pushScope} are
* discarded.
* @inheritDoc
*/
popScope(): boolean;
/**
* Creates a new scope with and executes the given operation within.
* The scope is automatically removed once the operation
* finishes or throws.
*
* This is essentially a convenience function for:
*
* pushScope();
* callback();
* popScope();
*
* @param callback that will be enclosed into push/popScope.
* @inheritDoc
*/
withScope(callback: ((scope: Scope) => void)): void;
/** Returns the client of the top stack. */
getClient(): any | undefined;
withScope(callback: (scope: Scope) => void): void;
/**
* @inheritDoc
*/
getClient<C extends Client>(): C | undefined;
/** Returns the scope of the top stack. */

@@ -110,54 +80,32 @@ getScope(): Scope | undefined;

/**
* Captures an exception event and sends it to Sentry.
*
* @param exception An exception-like object.
* @param hint May contain additional information about the original exception.
* @returns The generated eventId.
* @inheritDoc
*/
captureException(exception: any, hint?: SentryEventHint): string;
captureException(exception: any, hint?: EventHint): string;
/**
* Captures a message event and sends it to Sentry.
*
* @param message The message to send to Sentry.
* @param level Define the level of the message.
* @param hint May contain additional information about the original exception.
* @returns The generated eventId.
* @inheritDoc
*/
captureMessage(message: string, level?: Severity, hint?: SentryEventHint): string;
captureMessage(message: string, level?: Severity, hint?: EventHint): string;
/**
* Captures a manually created event and sends it to Sentry.
*
* @param event The event to send to Sentry.
* @param hint May contain additional information about the original exception.
* @inheritDoc
*/
captureEvent(event: SentryEvent, hint?: SentryEventHint): string;
captureEvent(event: Event, hint?: EventHint): string;
/**
* This is the getter for lastEventId.
*
* @returns The last event id of a captured event.
* @inheritDoc
*/
lastEventId(): string | undefined;
/**
* Records a new breadcrumb which will be attached to future events.
*
* Breadcrumbs will be added to subsequent events to provide more context on
* user's actions prior to an error or crash.
*
* @param breadcrumb The breadcrumb to record.
* @param hint May contain additional information about the original breadcrumb.
* @inheritDoc
*/
addBreadcrumb(breadcrumb: Breadcrumb, hint?: SentryBreadcrumbHint): void;
addBreadcrumb(breadcrumb: Breadcrumb, hint?: BreadcrumbHint): void;
/**
* Callback to set context information onto the scope.
*
* @param callback Callback function that receives Scope.
* @inheritDoc
*/
configureScope(callback: (scope: Scope) => void): void;
/**
* For the duraction of the callback, this hub will be set as the global current Hub.
* This function is useful if you want to run your own client and hook into an already initialized one
* e.g.: Reporting issues to your own sentry when running in your component while still using the users configuration.
* @inheritDoc
*/
run(callback: ((hub: Hub) => void)): void;
/** Returns the integration if installed on the current client. */
run(callback: (hub: Hub) => void): void;
/**
* @inheritDoc
*/
getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null;

@@ -182,10 +130,6 @@ }

/**
* This will tell whether a carrier has a hub on it or not
* @param carrier object
*/
export declare function hasHubOnCarrier(carrier: any): boolean;
/**
* This will create a new {@link Hub} and add to the passed object on
* __SENTRY__.hub.
* @param carrier object
* @hidden
*/

@@ -192,0 +136,0 @@ export declare function getHubFromCarrier(carrier: any): Hub;

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

import { logger } from '@sentry/utils/esm/logger';
import { dynamicRequire, getGlobalObject, uuid4 } from '@sentry/utils/esm/misc';
import { logger } from '@sentry/utils/logger';
import { consoleSandbox, dynamicRequire, getGlobalObject, uuid4 } from '@sentry/utils/misc';
import { Scope } from './scope';

@@ -9,8 +9,19 @@ /**

* changes a and new methods are introduced.
*
* @hidden
*/
export const API_VERSION = 3;
/**
* Internal class used to make sure we always have the latest internal functions
* working in case we have a version conflict.
* Default maximum number of breadcrumbs added to an event. Can be overwritten
* with {@link Options.maxBreadcrumbs}.
*/
const DEFAULT_BREADCRUMBS = 30;
/**
* Absolute maximum number of breadcrumbs added to an event. The
* `maxBreadcrumbs` option cannot be higher than this value.
*/
const MAX_BREADCRUMBS = 100;
/**
* @inheritDoc
*/
export class Hub {

@@ -25,7 +36,7 @@ /**

*/
constructor(client, scope = new Scope(), version = API_VERSION) {
this.version = version;
constructor(client, scope = new Scope(), _version = API_VERSION) {
this._version = _version;
/** Is a {@link Layer}[] containing the client and scope */
this.stack = [];
this.stack.push({ client, scope });
this._stack = [];
this._stack.push({ client, scope });
}

@@ -35,6 +46,6 @@ /**

*
* @param method The method to call on the client/client.
* @param args Arguments to pass to the client/frontend.
* @param method The method to call on the client.
* @param args Arguments to pass to the client function.
*/
invokeClient(method, ...args) {
_invokeClient(method, ...args) {
const top = this.getStackTop();

@@ -46,28 +57,9 @@ if (top && top.client && top.client[method]) {

/**
* Internal helper function to call an async method on the top client if it
* exists.
*
* @param method The method to call on the client/client.
* @param args Arguments to pass to the client/frontend.
* @inheritDoc
*/
invokeClientAsync(method, ...args) {
const top = this.getStackTop();
if (top && top.client && top.client[method]) {
top.client[method](...args, top.scope).catch((err) => {
logger.error(err);
});
}
}
/**
* Checks if this hub's version is older than the given version.
*
* @param version A version number to compare to.
* @return True if the given version is newer; otherwise false.
*/
isOlderThan(version) {
return this.version < version;
return this._version < version;
}
/**
* This binds the given client to the current scope.
* @param client An SDK client (client) instance.
* @inheritDoc
*/

@@ -77,24 +69,5 @@ bindClient(client) {

top.client = client;
if (top && top.scope && client) {
top.scope.addScopeListener((s) => {
if (client.getBackend) {
try {
client.getBackend().storeScope(s);
}
catch {
// Do nothing
}
}
});
}
}
/**
* Create a new scope to store context information.
*
* The scope will be layered on top of the current one. It is isolated, i.e. all
* breadcrumbs and context information added to this scope will be removed once
* the scope ends. Be sure to always remove this scope with {@link this.popScope}
* when the operation finishes or throws.
*
* @returns Scope, the new cloned scope
* @inheritDoc
*/

@@ -113,7 +86,3 @@ pushScope() {

/**
* Removes a previously pushed scope from the stack.
*
* This restores the state before the scope was pushed. All breadcrumbs and
* context information added since the last call to {@link this.pushScope} are
* discarded.
* @inheritDoc
*/

@@ -124,13 +93,3 @@ popScope() {

/**
* Creates a new scope with and executes the given operation within.
* The scope is automatically removed once the operation
* finishes or throws.
*
* This is essentially a convenience function for:
*
* pushScope();
* callback();
* popScope();
*
* @param callback that will be enclosed into push/popScope.
* @inheritDoc
*/

@@ -146,3 +105,5 @@ withScope(callback) {

}
/** Returns the client of the top stack. */
/**
* @inheritDoc
*/
getClient() {

@@ -157,57 +118,34 @@ return this.getStackTop().client;

getStack() {
return this.stack;
return this._stack;
}
/** Returns the topmost scope layer in the order domain > local > process. */
getStackTop() {
return this.stack[this.stack.length - 1];
return this._stack[this._stack.length - 1];
}
/**
* Captures an exception event and sends it to Sentry.
*
* @param exception An exception-like object.
* @param hint May contain additional information about the original exception.
* @returns The generated eventId.
* @inheritDoc
*/
captureException(exception, hint) {
const eventId = (this._lastEventId = uuid4());
this.invokeClientAsync('captureException', exception, {
...hint,
event_id: eventId,
});
this._invokeClient('captureException', exception, Object.assign({}, hint, { event_id: eventId }));
return eventId;
}
/**
* Captures a message event and sends it to Sentry.
*
* @param message The message to send to Sentry.
* @param level Define the level of the message.
* @param hint May contain additional information about the original exception.
* @returns The generated eventId.
* @inheritDoc
*/
captureMessage(message, level, hint) {
const eventId = (this._lastEventId = uuid4());
this.invokeClientAsync('captureMessage', message, level, {
...hint,
event_id: eventId,
});
this._invokeClient('captureMessage', message, level, Object.assign({}, hint, { event_id: eventId }));
return eventId;
}
/**
* Captures a manually created event and sends it to Sentry.
*
* @param event The event to send to Sentry.
* @param hint May contain additional information about the original exception.
* @inheritDoc
*/
captureEvent(event, hint) {
const eventId = (this._lastEventId = uuid4());
this.invokeClientAsync('captureEvent', event, {
...hint,
event_id: eventId,
});
this._invokeClient('captureEvent', event, Object.assign({}, hint, { event_id: eventId }));
return eventId;
}
/**
* This is the getter for lastEventId.
*
* @returns The last event id of a captured event.
* @inheritDoc
*/

@@ -218,17 +156,25 @@ lastEventId() {

/**
* Records a new breadcrumb which will be attached to future events.
*
* Breadcrumbs will be added to subsequent events to provide more context on
* user's actions prior to an error or crash.
*
* @param breadcrumb The breadcrumb to record.
* @param hint May contain additional information about the original breadcrumb.
* @inheritDoc
*/
addBreadcrumb(breadcrumb, hint) {
this.invokeClient('addBreadcrumb', breadcrumb, { ...hint });
const top = this.getStackTop();
if (!top.scope || !top.client) {
return;
}
const { beforeBreadcrumb, maxBreadcrumbs = DEFAULT_BREADCRUMBS } = top.client.getOptions();
if (maxBreadcrumbs <= 0) {
return;
}
const timestamp = new Date().getTime() / 1000;
const mergedBreadcrumb = Object.assign({ timestamp }, breadcrumb);
const finalBreadcrumb = beforeBreadcrumb
? consoleSandbox(() => beforeBreadcrumb(mergedBreadcrumb, hint))
: mergedBreadcrumb;
if (finalBreadcrumb === null) {
return;
}
top.scope.addBreadcrumb(finalBreadcrumb, Math.min(maxBreadcrumbs, MAX_BREADCRUMBS));
}
/**
* Callback to set context information onto the scope.
*
* @param callback Callback function that receives Scope.
* @inheritDoc
*/

@@ -243,5 +189,3 @@ configureScope(callback) {

/**
* For the duraction of the callback, this hub will be set as the global current Hub.
* This function is useful if you want to run your own client and hook into an already initialized one
* e.g.: Reporting issues to your own sentry when running in your component while still using the users configuration.
* @inheritDoc
*/

@@ -257,6 +201,12 @@ run(callback) {

}
/** Returns the integration if installed on the current client. */
/**
* @inheritDoc
*/
getIntegration(integration) {
const client = this.getClient();
if (!client) {
return null;
}
try {
return this.getClient().getIntegration(integration);
return client.getIntegration(integration);
}

@@ -330,9 +280,7 @@ catch (_oO) {

*/
export function hasHubOnCarrier(carrier) {
function hasHubOnCarrier(carrier) {
if (carrier && carrier.__SENTRY__ && carrier.__SENTRY__.hub) {
return true;
}
else {
return false;
}
return false;
}

@@ -343,2 +291,3 @@ /**

* @param carrier object
* @hidden
*/

@@ -349,7 +298,5 @@ export function getHubFromCarrier(carrier) {

}
else {
carrier.__SENTRY__ = {};
carrier.__SENTRY__.hub = new Hub();
return carrier.__SENTRY__.hub;
}
carrier.__SENTRY__ = {};
carrier.__SENTRY__.hub = new Hub();
return carrier.__SENTRY__.hub;
}

@@ -356,0 +303,0 @@ /**

export { Carrier, Layer } from './interfaces';
export { addGlobalEventProcessor, Scope } from './scope';
export { getCurrentHub, getHubFromCarrier, getMainCarrier, Hub, setHubOnCarrier } from './hub';
export { getCurrentHub, getHubFromCarrier, getMainCarrier, Hub, makeMain, setHubOnCarrier } from './hub';
export { addGlobalEventProcessor, Scope } from './scope';
export { getCurrentHub, getHubFromCarrier, getMainCarrier, Hub, setHubOnCarrier } from './hub';
export { getCurrentHub, getHubFromCarrier, getMainCarrier, Hub, makeMain, setHubOnCarrier } from './hub';
//# sourceMappingURL=index.js.map

@@ -0,9 +1,16 @@

import { Client } from '@sentry/types';
import { Hub } from './hub';
import { Scope } from './scope';
/** A layer in the process stack. */
/**
* A layer in the process stack.
* @hidden
*/
export interface Layer {
client?: any;
client?: Client;
scope?: Scope;
}
/** An object that contains a hub and maintains a scope stack. */
/**
* An object that contains a hub and maintains a scope stack.
* @hidden
*/
export interface Carrier {

@@ -10,0 +17,0 @@ __SENTRY__?: {

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

import { Breadcrumb, SentryEvent, SentryEventHint, Severity, User } from '@sentry/types/esm';
export declare type EventProcessor = (event: SentryEvent, hint?: SentryEventHint) => Promise<SentryEvent | null> | SentryEvent | null;
import { Breadcrumb, Event, EventHint, EventProcessor, Scope as ScopeInterface, Severity, User } from '@sentry/types';
import { SyncPromise } from '@sentry/utils/syncpromise';
/**

@@ -7,63 +7,75 @@ * Holds additional event information. {@link Scope.applyToEvent} will be

*/
export declare class Scope {
export declare class Scope implements ScopeInterface {
/** Flag if notifiying is happening. */
protected notifyingListeners: boolean;
protected _notifyingListeners: boolean;
/** Callback for client to receive scope changes. */
protected scopeListeners: Array<(scope: Scope) => void>;
protected _scopeListeners: Array<(scope: Scope) => void>;
/** Callback list that will be called after {@link applyToEvent}. */
protected eventProcessors: EventProcessor[];
protected _eventProcessors: EventProcessor[];
/** Array of breadcrumbs. */
protected breadcrumbs: Breadcrumb[];
protected _breadcrumbs: Breadcrumb[];
/** User */
protected user: User;
protected _user: User;
/** Tags */
protected tags: {
protected _tags: {
[key: string]: string;
};
/** Extra */
protected extra: {
protected _extra: {
[key: string]: any;
};
/** Fingerprint */
protected fingerprint?: string[];
protected _fingerprint?: string[];
/** Severity */
protected level?: Severity;
/** Add internal on change listener. */
protected _level?: Severity;
/**
* Add internal on change listener. Used for sub SDKs that need to store the scope.
* @hidden
*/
addScopeListener(callback: (scope: Scope) => void): void;
/** Add new event processor that will be called after {@link applyToEvent}. */
addEventProcessor(callback: EventProcessor): Scope;
/**
* @inheritDoc
*/
addEventProcessor(callback: EventProcessor): this;
/**
* This will be called on every set call.
*/
protected notifyScopeListeners(): void;
protected _notifyScopeListeners(): void;
/**
* This will be called after {@link applyToEvent} is finished.
*/
protected notifyEventProcessors(event: SentryEvent, hint?: SentryEventHint): Promise<SentryEvent | null>;
protected _notifyEventProcessors(processors: EventProcessor[], event: Event | null, hint?: EventHint, index?: number): SyncPromise<Event | null>;
/**
* Updates user context information for future events.
* @param user User context object to be set in the current context.
* @inheritDoc
*/
setUser(user: User): Scope;
setUser(user: User): this;
/**
* Updates tags context information for future events.
* @param tags Tags context object to merge into current context.
* @inheritDoc
*/
setTag(key: string, value: string): Scope;
setTags(tags: {
[key: string]: string;
}): this;
/**
* Updates extra context information for future events.
* @param extra context object to merge into current context.
* @inheritDoc
*/
setExtra(key: string, extra: any): Scope;
setTag(key: string, value: string): this;
/**
* Sets the fingerprint on the scope to send with the events.
* @param fingerprint string[] to group events in Sentry.
* @inheritDoc
*/
setFingerprint(fingerprint: string[]): Scope;
setExtras(extra: {
[key: string]: any;
}): this;
/**
* Sets the level on the scope for future events.
* @param level string {@link Severity}
* @inheritDoc
*/
setLevel(level: Severity): Scope;
setExtra(key: string, extra: any): this;
/**
* @inheritDoc
*/
setFingerprint(fingerprint: string[]): this;
/**
* @inheritDoc
*/
setLevel(level: Severity): this;
/**
* Inherit values from the parent scope.

@@ -73,15 +85,19 @@ * @param scope to clone.

static clone(scope?: Scope): Scope;
/** Clears the current scope and resets its properties. */
clear(): void;
/**
* Sets the breadcrumbs in the scope
* @param breadcrumbs Breadcrumb
* @param maxBreadcrumbs number of max breadcrumbs to merged into event.
* @inheritDoc
*/
addBreadcrumb(breadcrumb: Breadcrumb, maxBreadcrumbs?: number): void;
clear(): this;
/**
* @inheritDoc
*/
addBreadcrumb(breadcrumb: Breadcrumb, maxBreadcrumbs?: number): this;
/**
* @inheritDoc
*/
clearBreadcrumbs(): this;
/**
* Applies fingerprint from the scope to the event if there's one,
* uses message if there's one instead or get rid of empty fingerprint
*/
private applyFingerprint;
private _applyFingerprint;
/**

@@ -91,7 +107,8 @@ * Applies the current context and fingerprint to the event.

* Also if the event has already breadcrumbs on it, we do not merge them.
* @param event SentryEvent
* @param event Event
* @param hint May contain additional informartion about the original exception.
* @param maxBreadcrumbs number of max breadcrumbs to merged into event.
* @hidden
*/
applyToEvent(event: SentryEvent, hint?: SentryEventHint, maxBreadcrumbs?: number): Promise<SentryEvent | null>;
applyToEvent(event: Event, hint?: EventHint): SyncPromise<Event | null>;
}

@@ -98,0 +115,0 @@ /**

@@ -1,3 +0,5 @@

import { getGlobalObject } from '@sentry/utils/esm/misc';
import { assign, safeNormalize } from '@sentry/utils/esm/object';
import { isThenable } from '@sentry/utils/is';
import { getGlobalObject } from '@sentry/utils/misc';
import { normalize } from '@sentry/utils/object';
import { SyncPromise } from '@sentry/utils/syncpromise';
/**

@@ -10,23 +12,28 @@ * Holds additional event information. {@link Scope.applyToEvent} will be

/** Flag if notifiying is happening. */
this.notifyingListeners = false;
this._notifyingListeners = false;
/** Callback for client to receive scope changes. */
this.scopeListeners = [];
this._scopeListeners = [];
/** Callback list that will be called after {@link applyToEvent}. */
this.eventProcessors = [];
this._eventProcessors = [];
/** Array of breadcrumbs. */
this.breadcrumbs = [];
this._breadcrumbs = [];
/** User */
this.user = {};
this._user = {};
/** Tags */
this.tags = {};
this._tags = {};
/** Extra */
this.extra = {};
this._extra = {};
}
/** Add internal on change listener. */
/**
* Add internal on change listener. Used for sub SDKs that need to store the scope.
* @hidden
*/
addScopeListener(callback) {
this.scopeListeners.push(callback);
this._scopeListeners.push(callback);
}
/** Add new event processor that will be called after {@link applyToEvent}. */
/**
* @inheritDoc
*/
addEventProcessor(callback) {
this.eventProcessors.push(callback);
this._eventProcessors.push(callback);
return this;

@@ -37,10 +44,10 @@ }

*/
notifyScopeListeners() {
if (!this.notifyingListeners) {
this.notifyingListeners = true;
_notifyScopeListeners() {
if (!this._notifyingListeners) {
this._notifyingListeners = true;
setTimeout(() => {
this.scopeListeners.forEach(callback => {
this._scopeListeners.forEach(callback => {
callback(this);
});
this.notifyingListeners = false;
this._notifyingListeners = false;
});

@@ -52,60 +59,78 @@ }

*/
async notifyEventProcessors(event, hint) {
let processedEvent = event;
for (const processor of [...getGlobalEventProcessors(), ...this.eventProcessors]) {
try {
processedEvent = await processor({ ...processedEvent }, hint);
if (processedEvent === null) {
return null;
_notifyEventProcessors(processors, event, hint, index = 0) {
return new SyncPromise((resolve, reject) => {
const processor = processors[index];
// tslint:disable-next-line:strict-type-predicates
if (event === null || typeof processor !== 'function') {
resolve(event);
}
else {
const result = processor(Object.assign({}, event), hint);
if (isThenable(result)) {
result
.then(final => this._notifyEventProcessors(processors, final, hint, index + 1).then(resolve))
.catch(reject);
}
else {
this._notifyEventProcessors(processors, result, hint, index + 1)
.then(resolve)
.catch(reject);
}
}
catch (e) {
continue;
}
}
return processedEvent;
});
}
/**
* Updates user context information for future events.
* @param user User context object to be set in the current context.
* @inheritDoc
*/
setUser(user) {
this.user = safeNormalize(user);
this.notifyScopeListeners();
this._user = normalize(user);
this._notifyScopeListeners();
return this;
}
/**
* Updates tags context information for future events.
* @param tags Tags context object to merge into current context.
* @inheritDoc
*/
setTags(tags) {
this._tags = Object.assign({}, this._tags, normalize(tags));
this._notifyScopeListeners();
return this;
}
/**
* @inheritDoc
*/
setTag(key, value) {
this.tags = { ...this.tags, [key]: safeNormalize(value) };
this.notifyScopeListeners();
this._tags = Object.assign({}, this._tags, { [key]: normalize(value) });
this._notifyScopeListeners();
return this;
}
/**
* Updates extra context information for future events.
* @param extra context object to merge into current context.
* @inheritDoc
*/
setExtras(extra) {
this._extra = Object.assign({}, this._extra, normalize(extra));
this._notifyScopeListeners();
return this;
}
/**
* @inheritDoc
*/
setExtra(key, extra) {
this.extra = { ...this.extra, [key]: safeNormalize(extra) };
this.notifyScopeListeners();
this._extra = Object.assign({}, this._extra, { [key]: normalize(extra) });
this._notifyScopeListeners();
return this;
}
/**
* Sets the fingerprint on the scope to send with the events.
* @param fingerprint string[] to group events in Sentry.
* @inheritDoc
*/
setFingerprint(fingerprint) {
this.fingerprint = safeNormalize(fingerprint);
this.notifyScopeListeners();
this._fingerprint = normalize(fingerprint);
this._notifyScopeListeners();
return this;
}
/**
* Sets the level on the scope for future events.
* @param level string {@link Severity}
* @inheritDoc
*/
setLevel(level) {
this.level = safeNormalize(level);
this.notifyScopeListeners();
this._level = normalize(level);
this._notifyScopeListeners();
return this;

@@ -119,40 +144,53 @@ }

const newScope = new Scope();
assign(newScope, scope, {
scopeListeners: [],
Object.assign(newScope, scope, {
_scopeListeners: [],
});
if (scope) {
newScope.extra = assign(scope.extra);
newScope.tags = assign(scope.tags);
newScope.breadcrumbs = [...scope.breadcrumbs];
newScope.eventProcessors = [...scope.eventProcessors];
newScope._breadcrumbs = [...scope._breadcrumbs];
newScope._tags = Object.assign({}, scope._tags);
newScope._extra = Object.assign({}, scope._extra);
newScope._user = scope._user;
newScope._level = scope._level;
newScope._fingerprint = scope._fingerprint;
newScope._eventProcessors = [...scope._eventProcessors];
}
return newScope;
}
/** Clears the current scope and resets its properties. */
/**
* @inheritDoc
*/
clear() {
this.breadcrumbs = [];
this.tags = {};
this.extra = {};
this.user = {};
this.level = undefined;
this.fingerprint = undefined;
this.notifyScopeListeners();
this._breadcrumbs = [];
this._tags = {};
this._extra = {};
this._user = {};
this._level = undefined;
this._fingerprint = undefined;
this._notifyScopeListeners();
return this;
}
/**
* Sets the breadcrumbs in the scope
* @param breadcrumbs Breadcrumb
* @param maxBreadcrumbs number of max breadcrumbs to merged into event.
* @inheritDoc
*/
addBreadcrumb(breadcrumb, maxBreadcrumbs) {
this.breadcrumbs =
this._breadcrumbs =
maxBreadcrumbs !== undefined && maxBreadcrumbs >= 0
? [...this.breadcrumbs, safeNormalize(breadcrumb)].slice(-maxBreadcrumbs)
: [...this.breadcrumbs, safeNormalize(breadcrumb)];
this.notifyScopeListeners();
? [...this._breadcrumbs, normalize(breadcrumb)].slice(-maxBreadcrumbs)
: [...this._breadcrumbs, normalize(breadcrumb)];
this._notifyScopeListeners();
return this;
}
/**
* @inheritDoc
*/
clearBreadcrumbs() {
this._breadcrumbs = [];
this._notifyScopeListeners();
return this;
}
/**
* Applies fingerprint from the scope to the event if there's one,
* uses message if there's one instead or get rid of empty fingerprint
*/
applyFingerprint(event) {
_applyFingerprint(event) {
// Make sure it's an array first and we actually have something in place

@@ -165,9 +203,5 @@ event.fingerprint = event.fingerprint

// If we have something on the scope, then merge it with event
if (this.fingerprint) {
event.fingerprint = event.fingerprint.concat(this.fingerprint);
if (this._fingerprint) {
event.fingerprint = event.fingerprint.concat(this._fingerprint);
}
else if (event.message) {
// If not, but we have message, use it instead
event.fingerprint = event.fingerprint.concat(event.message);
}
// If we have no data at all, remove empty array default

@@ -182,28 +216,26 @@ if (event.fingerprint && !event.fingerprint.length) {

* Also if the event has already breadcrumbs on it, we do not merge them.
* @param event SentryEvent
* @param event Event
* @param hint May contain additional informartion about the original exception.
* @param maxBreadcrumbs number of max breadcrumbs to merged into event.
* @hidden
*/
async applyToEvent(event, hint, maxBreadcrumbs) {
if (this.extra && Object.keys(this.extra).length) {
event.extra = { ...this.extra, ...event.extra };
applyToEvent(event, hint) {
if (this._extra && Object.keys(this._extra).length) {
event.extra = Object.assign({}, this._extra, event.extra);
}
if (this.tags && Object.keys(this.tags).length) {
event.tags = { ...this.tags, ...event.tags };
if (this._tags && Object.keys(this._tags).length) {
event.tags = Object.assign({}, this._tags, event.tags);
}
if (this.user && Object.keys(this.user).length) {
event.user = { ...this.user, ...event.user };
if (this._user && Object.keys(this._user).length) {
event.user = Object.assign({}, this._user, event.user);
}
if (this.level) {
event.level = this.level;
if (this._level) {
event.level = this._level;
}
this.applyFingerprint(event);
this._applyFingerprint(event);
const hasNoBreadcrumbs = !event.breadcrumbs || event.breadcrumbs.length === 0;
if (hasNoBreadcrumbs && this.breadcrumbs.length > 0) {
event.breadcrumbs =
maxBreadcrumbs !== undefined && maxBreadcrumbs >= 0
? this.breadcrumbs.slice(-maxBreadcrumbs)
: this.breadcrumbs;
if (hasNoBreadcrumbs && this._breadcrumbs.length > 0) {
event.breadcrumbs = this._breadcrumbs;
}
return this.notifyEventProcessors(event, hint);
return this._notifyEventProcessors([...getGlobalEventProcessors(), ...this._eventProcessors], event, hint);
}

@@ -210,0 +242,0 @@ }

{
"name": "@sentry/hub",
"version": "4.6.4",
"version": "5.0.0-rc.0",
"description": "Sentry hub which handles global state managment.",

@@ -13,2 +13,3 @@ "repository": "git://github.com/getsentry/sentry-javascript.git",

"main": "dist/index.js",
"module": "esm/index.js",
"types": "dist/index.d.ts",

@@ -19,14 +20,14 @@ "publishConfig": {

"dependencies": {
"@sentry/types": "4.5.3",
"@sentry/utils": "4.6.4",
"@sentry/types": "5.0.0-rc.0",
"@sentry/utils": "5.0.0-rc.0",
"tslib": "^1.9.3"
},
"devDependencies": {
"jest": "^22.4.3",
"jest": "^24.5.0",
"npm-run-all": "^4.1.2",
"prettier": "^1.14.0",
"prettier": "^1.16.4",
"prettier-check": "^2.0.0",
"rimraf": "^2.6.2",
"tslint": "^5.11.0",
"typescript": "^3.2.0"
"rimraf": "^2.6.3",
"tslint": "^5.14.0",
"typescript": "^3.3.3333"
},

@@ -36,7 +37,8 @@ "scripts": {

"build:es5": "tsc -p tsconfig.build.json",
"build:esm": "run-s build:esm:transpile build:esm:rewrite",
"build:esm:transpile": "tsc -p tsconfig.esm.json",
"build:esm:rewrite": "node ../../scripts/esm-rewrite.js",
"build:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
"build:esm": "tsc -p tsconfig.esm.json",
"build:watch": "run-p build:watch:es5 build:watch:esm",
"build:watch:es5": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
"build:watch:esm": "tsc -p tsconfig.esm.json -w --preserveWatchOutput",
"clean": "rimraf dist coverage",
"link:yarn": "yarn link",
"lint": "run-s lint:prettier lint:tslint",

@@ -50,3 +52,3 @@ "lint:prettier": "prettier-check \"{src,test}/**/*.ts\"",

"test": "jest",
"test:watch": "jest --watch --notify"
"test:watch": "jest --watch"
},

@@ -53,0 +55,0 @@ "jest": {

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

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

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