Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sentry/core

Package Overview
Dependencies
Maintainers
9
Versions
533
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 0.5.4 to 4.0.0-beta.0

60

dist/base.d.ts

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

import { Breadcrumb, Context, SdkInfo, SentryEvent } from '@sentry/shim';
import { Scope } from '@sentry/hub';
import { Breadcrumb, SdkInfo, SentryEvent, SentryResponse } from '@sentry/types';
import { DSN } from './dsn';
import { Backend, Frontend, Options, Scope } from './interfaces';
import { SendStatus } from './status';
import { Backend, Client, Options } from './interfaces';
/** A class object that can instanciate Backend objects. */
export interface BackendClass<B extends Backend, O extends Options> {
new (frontend: Frontend<O>): B;
new (options: O): B;
}
/**
* Base implementation for all JavaScript SDK frontends.
* Base implementation for all JavaScript SDK clients.
*
* Call the constructor with the corresponding backend constructor and options
* specific to the frontend subclass. To access these options later, use
* {@link Frontend.getOptions}. Also, the Backend instance is available via
* {@link Frontend.getBackend}.
* specific to the client subclass. To access these options later, use
* {@link Client.getOptions}. Also, the Backend instance is available via
* {@link Client.getBackend}.
*

@@ -21,3 +21,3 @@ * Subclasses must implement one abstract method: {@link getSdkInfo}. It must

* If a DSN is specified in the options, it will be parsed and stored. Use
* {@link Frontend.getDSN} to retrieve the DSN at any moment. In case the DSN is
* {@link Client.getDSN} to retrieve the DSN at any moment. In case the DSN is
* invalid, the constructor will throw a {@link SentryException}. Note that

@@ -27,3 +27,3 @@ * without a valid DSN, the SDK will not send any events to Sentry.

* Before sending an event via the backend, it is passed through
* {@link FrontendBase.prepareEvent} to add SDK information and scope data
* {@link BaseClient.prepareEvent} to add SDK information and scope data
* (breadcrumbs and context). To add more custom information, override this

@@ -33,8 +33,8 @@ * method and extend the resulting prepared event.

* To issue automatically created events (e.g. via instrumentation), use
* {@link Frontend.captureEvent}. It will prepare the event and pass it through
* {@link Client.captureEvent}. It will prepare the event and pass it through
* the callback lifecycle. To issue auto-breadcrumbs, use
* {@link Frontend.addBreadcrumb}.
* {@link Client.addBreadcrumb}.
*
* @example
* class NodeFrontend extends FrontendBase<NodeBackend, NodeOptions> {
* class NodeClient extends BaseClient<NodeBackend, NodeOptions> {
* public constructor(options: NodeOptions) {

@@ -47,6 +47,6 @@ * super(NodeBackend, options);

*/
export declare abstract class FrontendBase<B extends Backend, O extends Options> implements Frontend<O> {
export declare abstract class BaseClient<B extends Backend, O extends Options> implements Client<O> {
/**
* The backend used to physically interact in the enviornment. Usually, this
* will correspond to the frontend. When composing SDKs, however, the Backend
* will correspond to the client. When composing SDKs, however, the Backend
* from the root SDK will be used.

@@ -63,8 +63,2 @@ */

/**
* A scope instance containing breadcrumbs and context, used if none is
* specified to the public methods. This is specifically used in standalone
* mode, when the Frontend is directly instanciated by the user.
*/
private readonly internalScope;
/**
* Stores whether installation has been performed and was successful. Before

@@ -75,6 +69,6 @@ * installing, this is undefined. Then it contains the success state.

/**
* Initializes this frontend instance.
* Initializes this client instance.
*
* @param backendClass A constructor function to create the backend.
* @param options Options for the frontend.
* @param options Options for the client.
*/

@@ -97,3 +91,3 @@ protected constructor(backendClass: BackendClass<B, O>, options: O);

*/
captureEvent(event: SentryEvent, scope?: Scope): Promise<void>;
captureEvent(event: SentryEvent, scope?: Scope): Promise<SentryResponse>;
/**

@@ -114,11 +108,3 @@ * @inheritDoc

*/
setContext(nextContext: Context, scope?: Scope): Promise<void>;
/**
* @inheritDoc
*/
getInitialScope(): Scope;
/** Returns the current used SDK version and name. */
protected abstract getSdkInfo(): SdkInfo;
/** Returns the current internal scope of this instance. */
protected getInternalScope(): Scope;
abstract getSdkInfo(): SdkInfo;
/** Returns the current backend. */

@@ -132,3 +118,3 @@ protected getBackend(): B;

* The information includes release and environment from `options`, SDK
* information returned by {@link FrontendBase.getSdkInfo}, as well as
* information returned by {@link BaseClient.getSdkInfo}, as well as
* breadcrumbs and context (extra, tags and user) from the scope.

@@ -143,3 +129,3 @@ *

*/
protected prepareEvent(event: SentryEvent, scope: Scope): Promise<SentryEvent>;
protected prepareEvent(event: SentryEvent, scope?: Scope): Promise<SentryEvent>;
/**

@@ -158,7 +144,7 @@ * Processes an event (either error or message) and sends it to Sentry.

* @param event The event to send to Sentry.
* @param send A function to actually send the event.
* @param scope A scope containing event metadata.
* @param send A function to actually send the event.
* @returns A Promise that resolves with the event status.
*/
protected processEvent(event: SentryEvent, scope: Scope, send: (finalEvent: SentryEvent) => Promise<number>): Promise<SendStatus>;
protected processEvent(event: SentryEvent, send: (finalEvent: SentryEvent) => Promise<SentryResponse>, scope?: Scope): Promise<SentryResponse>;
}

@@ -25,4 +25,4 @@ "use strict";

while (_) try {
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [0, t.value];
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {

@@ -46,25 +46,7 @@ case 0: case 1: t = op; break;

};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
var types_1 = require("@sentry/types");
var misc_1 = require("@sentry/utils/misc");
var string_1 = require("@sentry/utils/string");
var dsn_1 = require("./dsn");
var status_1 = require("./status");
/**

@@ -81,8 +63,12 @@ * Default maximum number of breadcrumbs added to an event. Can be overwritten

/**
* Base implementation for all JavaScript SDK frontends.
* By default, truncates URL values to 250 chars
*/
var MAX_URL_LENGTH = 250;
/**
* Base implementation for all JavaScript SDK clients.
*
* Call the constructor with the corresponding backend constructor and options
* specific to the frontend subclass. To access these options later, use
* {@link Frontend.getOptions}. Also, the Backend instance is available via
* {@link Frontend.getBackend}.
* specific to the client subclass. To access these options later, use
* {@link Client.getOptions}. Also, the Backend instance is available via
* {@link Client.getBackend}.
*

@@ -93,3 +79,3 @@ * Subclasses must implement one abstract method: {@link getSdkInfo}. It must

* If a DSN is specified in the options, it will be parsed and stored. Use
* {@link Frontend.getDSN} to retrieve the DSN at any moment. In case the DSN is
* {@link Client.getDSN} to retrieve the DSN at any moment. In case the DSN is
* invalid, the constructor will throw a {@link SentryException}. Note that

@@ -99,3 +85,3 @@ * without a valid DSN, the SDK will not send any events to Sentry.

* Before sending an event via the backend, it is passed through
* {@link FrontendBase.prepareEvent} to add SDK information and scope data
* {@link BaseClient.prepareEvent} to add SDK information and scope data
* (breadcrumbs and context). To add more custom information, override this

@@ -105,8 +91,8 @@ * method and extend the resulting prepared event.

* To issue automatically created events (e.g. via instrumentation), use
* {@link Frontend.captureEvent}. It will prepare the event and pass it through
* {@link Client.captureEvent}. It will prepare the event and pass it through
* the callback lifecycle. To issue auto-breadcrumbs, use
* {@link Frontend.addBreadcrumb}.
* {@link Client.addBreadcrumb}.
*
* @example
* class NodeFrontend extends FrontendBase<NodeBackend, NodeOptions> {
* class NodeClient extends BaseClient<NodeBackend, NodeOptions> {
* public constructor(options: NodeOptions) {

@@ -119,11 +105,11 @@ * super(NodeBackend, options);

*/
var FrontendBase = /** @class */ (function () {
var BaseClient = /** @class */ (function () {
/**
* Initializes this frontend instance.
* Initializes this client instance.
*
* @param backendClass A constructor function to create the backend.
* @param options Options for the frontend.
* @param options Options for the client.
*/
function FrontendBase(backendClass, options) {
this.backend = new backendClass(this);
function BaseClient(backendClass, options) {
this.backend = new backendClass(options);
this.options = options;

@@ -133,4 +119,2 @@ if (options.dsn) {

}
// The initial scope must have access to backend, options and DSN
this.internalScope = this.getInitialScope();
}

@@ -140,3 +124,3 @@ /**

*/
FrontendBase.prototype.install = function () {
BaseClient.prototype.install = function () {
if (!this.isEnabled()) {

@@ -153,4 +137,3 @@ return false;

*/
FrontendBase.prototype.captureException = function (exception, scope) {
if (scope === void 0) { scope = this.internalScope; }
BaseClient.prototype.captureException = function (exception, scope) {
return __awaiter(this, void 0, void 0, function () {

@@ -174,4 +157,3 @@ var event;

*/
FrontendBase.prototype.captureMessage = function (message, scope) {
if (scope === void 0) { scope = this.internalScope; }
BaseClient.prototype.captureMessage = function (message, scope) {
return __awaiter(this, void 0, void 0, function () {

@@ -195,15 +177,9 @@ var event;

*/
FrontendBase.prototype.captureEvent = function (event, scope) {
if (scope === void 0) { scope = this.internalScope; }
BaseClient.prototype.captureEvent = function (event, scope) {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.processEvent(event, scope, function (finalEvent) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, this.getBackend().sendEvent(finalEvent)];
}); }); })];
case 1:
_a.sent();
return [2 /*return*/];
}
return [2 /*return*/, this.processEvent(event, function (finalEvent) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, this.getBackend().sendEvent(finalEvent)];
}); }); }, scope)];
});

@@ -215,4 +191,3 @@ });

*/
FrontendBase.prototype.addBreadcrumb = function (breadcrumb, scope) {
if (scope === void 0) { scope = this.internalScope; }
BaseClient.prototype.addBreadcrumb = function (breadcrumb, scope) {
return __awaiter(this, void 0, void 0, function () {

@@ -235,6 +210,6 @@ var _a, shouldAddBreadcrumb, beforeBreadcrumb, afterBreadcrumb, _b, maxBreadcrumbs, timestamp, mergedBreadcrumb, finalBreadcrumb;

: mergedBreadcrumb;
return [4 /*yield*/, this.getBackend().storeBreadcrumb(finalBreadcrumb, scope)];
return [4 /*yield*/, this.getBackend().storeBreadcrumb(finalBreadcrumb)];
case 1:
if (_c.sent()) {
scope.breadcrumbs = __spread(scope.breadcrumbs, [finalBreadcrumb]).slice(-Math.max(0, Math.min(maxBreadcrumbs, MAX_BREADCRUMBS)));
if ((_c.sent()) && scope) {
scope.addBreadcrumb(finalBreadcrumb, Math.min(maxBreadcrumbs, MAX_BREADCRUMBS));
}

@@ -252,3 +227,3 @@ if (afterBreadcrumb) {

*/
FrontendBase.prototype.getDSN = function () {
BaseClient.prototype.getDSN = function () {
return this.dsn;

@@ -259,52 +234,11 @@ };

*/
FrontendBase.prototype.getOptions = function () {
BaseClient.prototype.getOptions = function () {
return this.options;
};
/**
* @inheritDoc
*/
FrontendBase.prototype.setContext = function (nextContext, scope) {
if (scope === void 0) { scope = this.internalScope; }
return __awaiter(this, void 0, void 0, function () {
var context;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.getBackend().storeContext(nextContext, scope)];
case 1:
if (_a.sent()) {
context = scope.context;
if (nextContext.extra) {
context.extra = __assign({}, context.extra, nextContext.extra);
}
if (nextContext.tags) {
context.tags = __assign({}, context.tags, nextContext.tags);
}
if (nextContext.user) {
context.user = __assign({}, context.user, nextContext.user);
}
}
return [2 /*return*/];
}
});
});
};
/**
* @inheritDoc
*/
FrontendBase.prototype.getInitialScope = function () {
return {
breadcrumbs: [],
context: {},
};
};
/** Returns the current internal scope of this instance. */
FrontendBase.prototype.getInternalScope = function () {
return this.internalScope;
};
/** Returns the current backend. */
FrontendBase.prototype.getBackend = function () {
BaseClient.prototype.getBackend = function () {
return this.backend;
};
/** Determines whether this SDK is enabled and a valid DSN is present. */
FrontendBase.prototype.isEnabled = function () {
BaseClient.prototype.isEnabled = function () {
return this.getOptions().enabled !== false && this.dsn !== undefined;

@@ -316,3 +250,3 @@ };

* The information includes release and environment from `options`, SDK
* information returned by {@link FrontendBase.getSdkInfo}, as well as
* information returned by {@link BaseClient.getSdkInfo}, as well as
* breadcrumbs and context (extra, tags and user) from the scope.

@@ -327,5 +261,5 @@ *

*/
FrontendBase.prototype.prepareEvent = function (event, scope) {
BaseClient.prototype.prepareEvent = function (event, scope) {
return __awaiter(this, void 0, void 0, function () {
var _a, environment, _b, maxBreadcrumbs, release, prepared, breadcrumbs, context;
var _a, environment, _b, maxBreadcrumbs, release, prepared, exception, request;
return __generator(this, function (_c) {

@@ -340,15 +274,20 @@ _a = this.getOptions(), environment = _a.environment, _b = _a.maxBreadcrumbs, maxBreadcrumbs = _b === void 0 ? DEFAULT_BREADCRUMBS : _b, release = _a.release;

}
breadcrumbs = scope.breadcrumbs;
if (breadcrumbs.length > 0 && maxBreadcrumbs > 0) {
prepared.breadcrumbs = breadcrumbs.slice(-Math.max(0, Math.min(maxBreadcrumbs, MAX_BREADCRUMBS)));
if (prepared.message) {
prepared.message = string_1.truncate(prepared.message, MAX_URL_LENGTH);
}
context = scope.context;
if (context.extra) {
prepared.extra = __assign({}, context.extra, event.extra);
exception = prepared.exception &&
prepared.exception.values &&
prepared.exception.values[0];
if (exception && exception.value) {
exception.value = string_1.truncate(exception.value, MAX_URL_LENGTH);
}
if (context.tags) {
prepared.tags = __assign({}, context.tags, event.tags);
request = prepared.request;
if (request && request.url) {
request.url = string_1.truncate(request.url, MAX_URL_LENGTH);
}
if (context.user) {
prepared.user = __assign({}, context.user, event.user);
prepared.event_id = misc_1.uuid4();
// This should be the last thing called, since we want that
// {@link Hub.addEventProcessor} gets the finished prepared event.
if (scope) {
scope.applyToEvent(prepared, Math.min(maxBreadcrumbs, MAX_BREADCRUMBS));
}

@@ -372,9 +311,9 @@ return [2 /*return*/, prepared];

* @param event The event to send to Sentry.
* @param send A function to actually send the event.
* @param scope A scope containing event metadata.
* @param send A function to actually send the event.
* @returns A Promise that resolves with the event status.
*/
FrontendBase.prototype.processEvent = function (event, scope, send) {
BaseClient.prototype.processEvent = function (event, send, scope) {
return __awaiter(this, void 0, void 0, function () {
var prepared, _a, shouldSend, beforeSend, afterSend, finalEvent, code, status;
var prepared, _a, shouldSend, beforeSend, afterSend, finalEvent, response;
return __generator(this, function (_b) {

@@ -384,3 +323,7 @@ switch (_b.label) {

if (!this.isEnabled()) {
return [2 /*return*/, status_1.SendStatus.Skipped];
return [2 /*return*/, {
code: -1,
event_id: event.event_id,
status: types_1.Status.Skipped,
}];
}

@@ -392,3 +335,7 @@ return [4 /*yield*/, this.prepareEvent(event, scope)];

if (shouldSend && !shouldSend(prepared)) {
return [2 /*return*/, status_1.SendStatus.Skipped];
return [2 /*return*/, {
code: -1,
event_id: event.event_id,
status: types_1.Status.Skipped,
}];
}

@@ -398,12 +345,12 @@ finalEvent = beforeSend ? beforeSend(prepared) : prepared;

case 2:
code = _b.sent();
status = status_1.SendStatus.fromHttpCode(code);
if (status === status_1.SendStatus.RateLimit) {
response = _b.sent();
if (response.status === types_1.Status.RateLimit) {
// TODO: Handle rate limits and maintain a queue. For now, we require SDK
// implementors to override this method and handle it themselves.
}
// TODO: Handle duplicates and backoffs
if (afterSend) {
afterSend(finalEvent, status);
afterSend(finalEvent, response);
}
return [2 /*return*/, status];
return [2 /*return*/, response];
}

@@ -413,5 +360,5 @@ });

};
return FrontendBase;
return BaseClient;
}());
exports.FrontendBase = FrontendBase;
exports.BaseClient = BaseClient;
//# sourceMappingURL=base.js.map

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

/** Supported Sentry transport protocols in a DSN. */
export declare type DSNProtocol = 'http' | 'https';
/** Primitive components of a DSN. */
export interface DSNComponents {
/** Protocol used to connect to Sentry. */
protocol: DSNProtocol;
/** Public authorization key. */
user: string;
/** Private authorization key (deprecated, optional). */
pass?: string;
/** Hostname of the Sentry instance. */
host: string;
/** Port of the Sentry instance. */
port?: string;
/** Project path */
path: string;
}
/** Anything that can be parsed into a DSN. */
export declare type DSNLike = string | DSNComponents;
import { DSNComponents, DSNLike, DSNProtocol } from '@sentry/types';
/** The Sentry DSN, identifying a Sentry instance and project. */

@@ -32,4 +14,6 @@ export declare class DSN implements DSNComponents {

port: string;
/** Project path */
/** Path */
path: string;
/** Project ID */
projectId: string;
/** Creates a new DSN component */

@@ -48,7 +32,7 @@ constructor(from: DSNLike);

/** Parses a string into this DSN. */
private fromString(str);
private fromString;
/** Maps DSN components into this instance. */
private fromComponents(components);
private fromComponents;
/** Validates this DSN and throws on error. */
private validate();
private validate;
}

@@ -56,5 +56,5 @@ "use strict";

// tslint:disable-next-line:no-this-assignment
var _a = this, host = _a.host, path = _a.path, pass = _a.pass, port = _a.port, protocol = _a.protocol, user = _a.user;
var _a = this, host = _a.host, path = _a.path, pass = _a.pass, port = _a.port, projectId = _a.projectId, protocol = _a.protocol, user = _a.user;
return (protocol + "://" + user + (withPassword && pass ? ":" + pass : '') +
("@" + host + (port ? ":" + port : '') + "/" + path));
("@" + host + (port ? ":" + port : '') + "/" + (path ? path + "/" : path) + projectId));
};

@@ -67,4 +67,11 @@ /** Parses a string into this DSN. */

}
var _a = __read(match.slice(1), 6), protocol = _a[0], user = _a[1], _b = _a[2], pass = _b === void 0 ? '' : _b, host = _a[3], _c = _a[4], port = _c === void 0 ? '' : _c, path = _a[5];
Object.assign(this, { host: host, pass: pass, path: path, port: port, protocol: protocol, user: user });
var _a = __read(match.slice(1), 6), protocol = _a[0], user = _a[1], _b = _a[2], pass = _b === void 0 ? '' : _b, host = _a[3], _c = _a[4], port = _c === void 0 ? '' : _c, lastPath = _a[5];
var path = '';
var projectId = lastPath;
var split = projectId.split('/');
if (split.length > 1) {
path = split.slice(0, -1).join('/');
projectId = split.pop();
}
Object.assign(this, { host: host, pass: pass, path: path, projectId: projectId, port: port, protocol: protocol, user: user });
};

@@ -78,9 +85,11 @@ /** Maps DSN components into this instance. */

this.port = components.port || '';
this.path = components.path;
this.path = components.path || '';
this.projectId = components.projectId;
};
/** Validates this DSN and throws on error. */
DSN.prototype.validate = function () {
var e_1, _a;
try {
for (var _a = __values(['protocol', 'user', 'host', 'path']), _b = _a.next(); !_b.done; _b = _a.next()) {
var component = _b.value;
for (var _b = __values(['protocol', 'user', 'host', 'projectId']), _c = _b.next(); !_c.done; _c = _b.next()) {
var component = _c.value;
if (!this[component]) {

@@ -94,3 +103,3 @@ throw new error_1.SentryError("Invalid DSN: Missing " + component);

try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}

@@ -105,3 +114,2 @@ finally { if (e_1) throw e_1.error; }

}
var e_1, _c;
};

@@ -108,0 +116,0 @@ return DSN;

@@ -1,5 +0,7 @@

export { BackendClass, FrontendBase } from './base';
export { DSN, DSNComponents, DSNLike, DSNProtocol } from './dsn';
export { captureException, captureMessage, configureScope, } from '@sentry/minimal';
export { Hub, Scope } from '@sentry/hub';
export { BackendClass, BaseClient } from './base';
export { DSN } from './dsn';
export { SentryError } from './error';
export { Backend, Frontend, LogLevel, Options, Scope } from './interfaces';
export { initAndBind, FrontendClass } from './sdk';
export { Backend, Client, LogLevel, Options } from './interfaces';
export { initAndBind, ClientClass } from './sdk';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var minimal_1 = require("@sentry/minimal");
exports.captureException = minimal_1.captureException;
exports.captureMessage = minimal_1.captureMessage;
exports.configureScope = minimal_1.configureScope;
var hub_1 = require("@sentry/hub");
exports.Hub = hub_1.Hub;
exports.Scope = hub_1.Scope;
var base_1 = require("./base");
exports.FrontendBase = base_1.FrontendBase;
exports.BaseClient = base_1.BaseClient;
var dsn_1 = require("./dsn");

@@ -6,0 +13,0 @@ exports.DSN = dsn_1.DSN;

@@ -1,16 +0,4 @@

import { Breadcrumb, Context, SentryEvent } from '@sentry/shim';
import { Scope } from '@sentry/hub';
import { Breadcrumb, Integration, SdkInfo, SentryEvent, SentryResponse, Transport, TransportClass, TransportOptions } from '@sentry/types';
import { DSN } from './dsn';
import { SendStatus } from './status';
/**
* An exchangable object containing event metadata that will be merged into the
* event payload before sending it to Sentry.
*
* Each Frontend creates an implicit scope when used directly. When using the
* top-level exported functions, however, the shim maintains a stack of scopes
* and injects them into the frontend.
*/
export interface Scope {
breadcrumbs: Breadcrumb[];
context: Context;
}
/** Console logging verbosity for the SDK. */

@@ -25,3 +13,3 @@ export declare enum LogLevel {

/** All SDK actions will be logged. */
Verbose = 3,
Verbose = 3
}

@@ -42,2 +30,16 @@ /** Base configuration options for every SDK. */

/**
* List of integrations that should be installed after SDK was initialized.
* Accepts either a list of integrations or a function that receives
* default integrations and returns a new, updated list.
*/
integrations?: Integration[] | ((integrations: Integration[]) => Integration[]);
/**
* Transport object that should be used to send events to Sentry
*/
transport?: TransportClass<Transport>;
/**
* Options for the default transport that the SDK uses.
*/
transportOptions?: TransportOptions;
/**
* The release identifier used when uploading respective source maps. Specify

@@ -86,3 +88,3 @@ * this value to allow Sentry to resolve the correct source maps when

*/
afterSend?(event: SentryEvent, status: SendStatus): void;
afterSend?(event: SentryEvent, status: SentryResponse): void;
/**

@@ -122,3 +124,3 @@ * A callback allowing to skip breadcrumbs.

/**
* User-Facing Sentry SDK Client Frontend.
* User-Facing Sentry SDK Client Client.
*

@@ -131,14 +133,10 @@ * This interface contains all methods to interface with the SDK once it has

*
* Note that the call to {@link Frontend.install} should occur as early as
* Note that the call to {@link Client.install} should occur as early as
* possible so that even errors during startup can be recorded reliably:
*
* @example
* import { create } from '@sentry/node';
* create({ dsn: '__DSN__' });
*
* @example
* import { captureMessage } from '@sentry/node';
* captureMessage('Custom message');
*/
export interface Frontend<O extends Options = Options> {
export interface Client<O extends Options = Options> {
/**

@@ -177,3 +175,3 @@ * Installs the SDK if it hasn't been installed already.

*/
captureEvent(event: SentryEvent, scope?: Scope): Promise<void>;
captureEvent(event: SentryEvent, scope?: Scope): Promise<SentryResponse>;
/**

@@ -194,11 +192,4 @@ * Records a new breadcrumb which will be attached to future events.

getOptions(): O;
/**
* Updates context information (user, tags, extras) for future events.
*
* @param context A partial context object to merge into current context.
* @param scope An optional scope to store this the context in.
*/
setContext(context: Context, scope: Scope): void;
/** Returns the inital scope for the shim. */
getInitialScope(): Scope;
/** Returns the current used SDK version and name. */
getSdkInfo(): SdkInfo;
}

@@ -208,3 +199,3 @@ /**

*
* While {@link Frontend} contains business logic specific to an SDK, the
* While {@link Client} contains business logic specific to an SDK, the
* Backend offers platform specific implementations for low-level operations.

@@ -214,13 +205,13 @@ * These are persisting and loading information, sending events, and hooking

*
* Backends receive a handle to the Frontend in their constructor. When a
* Backends receive a handle to the Client in their constructor. When a
* Backend automatically generates events or breadcrumbs, it must pass them to
* the Frontend for validation and processing first.
* the Client for validation and processing first.
*
* Usually, the Frontend will be of corresponding type, e.g. NodeBackend
* receives NodeFrontend. However, higher-level SDKs can choose to instanciate
* Usually, the Client will be of corresponding type, e.g. NodeBackend
* receives NodeClient. However, higher-level SDKs can choose to instanciate
* multiple Backends and delegate tasks between them. In this case, an event
* generated by one backend might very well be sent by another one.
*
* The frontend also provides access to options via {@link Frontend.getOptions}
* and context via {@link Frontend.getContext}. Note that the user might update
* The client also provides access to options via {@link Client.getOptions}
* and context via {@link Client.getContext}. Note that the user might update
* these any time and they should not be cached.

@@ -236,7 +227,7 @@ */

/** Submits the event to Sentry */
sendEvent(event: SentryEvent): Promise<number>;
sendEvent(event: SentryEvent): Promise<SentryResponse>;
/**
* Receives a breadcrumb and stores it in a platform-dependent way.
*
* This function is invoked by the frontend before merging the breadcrumb into
* This function is invoked by the client before merging the breadcrumb into
* the scope. Return `false` to prevent this breadcrumb from being merged.

@@ -249,21 +240,14 @@ * This should be done for custom breadcrumb management in the backend.

* @param breadcrumb The breadcrumb to store.
* @param scope The scope instance currently managed by the frontend.
* @returns True if the breadcrumb should be merged by the frontend.
* @returns True if the breadcrumb should be merged by the client.
*/
storeBreadcrumb(breadcrumb: Breadcrumb, scope: Scope): boolean | Promise<boolean>;
storeBreadcrumb(breadcrumb: Breadcrumb): boolean | Promise<boolean>;
/**
* Receives a context and merges it in a platform-dependent way.
* Receives the whole scope and stores it in a platform-dependent way.
*
* This function is invoked by the frontend before merging the context into
* the scope. Return `false` to prevent this context from being merged. This
* should be done for custom context management in the backend.
* This function is invoked by the scope after the scope is configured.
* This should be done for custom context management in the backend.
*
* In most cases, this method does not have to perform any action and can
* simply return `true`. It can either be synchronous or asynchronous.
*
* @param context The context to store.
* @param scope The scope instance currently managed by the frontend.
* @returns True if the breadcrumb should be merged by the frontend.
* @param scope The scope to store.
*/
storeContext(context: Context, scope: Scope): boolean | Promise<boolean>;
storeScope(scope: Scope): void;
}

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

import { Frontend, Options } from './interfaces';
export { captureException, captureMessage, clearScope, popScope, pushScope, setExtraContext, setTagsContext } from '@sentry/shim';
/** A class object that can instanciate Frontend objects. */
export interface FrontendClass<F extends Frontend, O extends Options> {
import { Integration } from '@sentry/types';
import { Client, Options } from './interfaces';
/** A class object that can instanciate Client objects. */
export interface ClientClass<F extends Client, O extends Options> {
new (options: O): F;
}
/**
* Internal function to create a new SDK frontend instance. The frontend is
* Internal function to create a new SDK client instance. The client is
* installed and then bound to the current scope.
*
* @param frontendClass The frontend class to instanciate.
* @param options Options to pass to the frontend.
* @returns The installed and bound frontend instance.
* @param clientClass The client class to instanciate.
* @param options Options to pass to the client.
* @returns The installed and bound client instance.
*/
export declare function initAndBind<F extends Frontend, O extends Options>(frontendClass: FrontendClass<F, O>, options: O): void;
export declare function initAndBind<F extends Client, O extends Options>(clientClass: ClientClass<F, O>, options: O, defaultIntegrations?: Integration[]): void;
"use strict";
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
var Shim = require("@sentry/shim");
var shim_1 = require("@sentry/shim");
exports.captureException = shim_1.captureException;
exports.captureMessage = shim_1.captureMessage;
exports.clearScope = shim_1.clearScope;
exports.popScope = shim_1.popScope;
exports.pushScope = shim_1.pushScope;
exports.setExtraContext = shim_1.setExtraContext;
exports.setTagsContext = shim_1.setTagsContext;
var hub_1 = require("@sentry/hub");
/**
* Internal function to create a new SDK frontend instance. The frontend is
* Internal function to create a new SDK client instance. The client is
* installed and then bound to the current scope.
*
* @param frontendClass The frontend class to instanciate.
* @param options Options to pass to the frontend.
* @returns The installed and bound frontend instance.
* @param clientClass The client class to instanciate.
* @param options Options to pass to the client.
* @returns The installed and bound client instance.
*/
function initAndBind(frontendClass, options) {
if (Shim.getCurrentClient()) {
function initAndBind(clientClass, options, defaultIntegrations) {
if (defaultIntegrations === void 0) { defaultIntegrations = []; }
if (hub_1.getDefaultHub().getClient()) {
return;
}
var frontend = new frontendClass(options);
frontend.install();
Shim.bindClient(frontend);
var client = new clientClass(options);
client.install();
// This should happen here if any integration uses {@link Hub.addEventProcessor}
// there needs to be a client on the hub already.
hub_1.getDefaultHub().bindClient(client);
var integrations = __spread(defaultIntegrations);
if (Array.isArray(options.integrations)) {
integrations = __spread(integrations, options.integrations);
}
else if (typeof options.integrations === 'function') {
integrations = options.integrations(integrations);
}
// Just in case someone will return non-array from a `itegrations` callback
if (Array.isArray(integrations)) {
integrations.forEach(function (integration) {
integration.install();
});
}
}
exports.initAndBind = initAndBind;
//# sourceMappingURL=sdk.js.map
{
"name": "@sentry/core",
"version": "0.5.4",
"version": "4.0.0-beta.0",
"description": "Base implementation for all Sentry JavaScript SDKs",
"repository": "git://github.com/getsentry/raven-js.git",
"homepage": "https://github.com/getsentry/raven-js/tree/next/packages/core",
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/core",
"author": "Sentry",

@@ -18,6 +18,8 @@ "license": "BSD-3-Clause",

"dependencies": {
"@sentry/shim": "0.5.4"
"@sentry/hub": "4.0.0-beta.0",
"@sentry/minimal": "4.0.0-beta.0",
"@sentry/types": "4.0.0-beta.0",
"@sentry/utils": "4.0.0-beta.0"
},
"devDependencies": {
"chai": "^4.1.2",
"jest": "^22.4.3",

@@ -28,3 +30,2 @@ "npm-run-all": "^4.1.2",

"rimraf": "^2.6.2",
"sinon": "^5.0.3",
"tslint": "^5.9.1",

@@ -44,3 +45,23 @@ "typescript": "^2.8.3"

"test:watch": "jest --watch --notify"
}
},
"jest": {
"collectCoverage": true,
"transform": {
"^.+\\.ts$": "ts-jest"
},
"moduleFileExtensions": [
"js",
"ts"
],
"testEnvironment": "node",
"testMatch": [
"**/*.test.ts"
],
"globals": {
"ts-jest": {
"tsConfigFile": "./tsconfig.json"
}
}
},
"gitHead": "a91da22f8bd3bddb38fab7f868326e376da82d4d"
}

@@ -21,3 +21,3 @@ <p align="center">

## Specializing the Frontend
## Specializing the Client

@@ -24,0 +24,0 @@ TODO

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