@sentry/core
Advanced tools
Comparing version 0.4.2 to 0.5.0-beta.0
@@ -5,3 +5,3 @@ export { BackendClass, FrontendBase } from './lib/base'; | ||
export { SentryError } from './lib/error'; | ||
export { Backend, Frontend, LogLevel, Options } from './lib/interfaces'; | ||
export { FrontendClass, Sdk } from './lib/sdk'; | ||
export { Backend, Frontend, LogLevel, Options, Scope } from './lib/interfaces'; | ||
export { addBreadcrumb, captureEvent, createAndBind, FrontendClass, setUserContext } from './lib/sdk'; |
@@ -14,3 +14,6 @@ "use strict"; | ||
var sdk_1 = require("./lib/sdk"); | ||
exports.Sdk = sdk_1.Sdk; | ||
exports.addBreadcrumb = sdk_1.addBreadcrumb; | ||
exports.captureEvent = sdk_1.captureEvent; | ||
exports.createAndBind = sdk_1.createAndBind; | ||
exports.setUserContext = sdk_1.setUserContext; | ||
//# sourceMappingURL=index.js.map |
import { Breadcrumb, Context, SdkInfo, SentryEvent } from './domain'; | ||
import { DSN } from './dsn'; | ||
import { Backend, Frontend, Options } from './interfaces'; | ||
import { Backend, Frontend, Options, Scope } from './interfaces'; | ||
/** A class object that can instanciate Backend objects. */ | ||
@@ -56,9 +56,5 @@ export interface BackendClass<B extends Backend, O extends Options> { | ||
*/ | ||
private dsn?; | ||
/** A promise that resolves during installation. */ | ||
private readonly dsn?; | ||
/** A promise that resolves during installation. TODO */ | ||
private installation?; | ||
/** Lazy cache of breadcrumbs, initialized when first accessed. */ | ||
private breadcrumbs?; | ||
/** Lazy cache of context data, initialized when first accessed. */ | ||
private context?; | ||
/** | ||
@@ -74,19 +70,19 @@ * Initializes this frontend instance. | ||
*/ | ||
install(): Promise<boolean>; | ||
install(): boolean; | ||
/** | ||
* @inheritDoc | ||
*/ | ||
captureException(exception: any): Promise<void>; | ||
captureException(exception: any, scope?: Scope): Promise<void>; | ||
/** | ||
* @inheritDoc | ||
*/ | ||
captureMessage(message: string): Promise<void>; | ||
captureMessage(message: string, scope?: Scope): Promise<void>; | ||
/** | ||
* @inheritDoc | ||
*/ | ||
captureEvent(event: SentryEvent): Promise<void>; | ||
captureEvent(event: SentryEvent, scope?: Scope): Promise<void>; | ||
/** | ||
* @inheritDoc | ||
*/ | ||
addBreadcrumb(breadcrumb: Breadcrumb): Promise<void>; | ||
addBreadcrumb(breadcrumb: Breadcrumb, scope: Scope): Promise<void>; | ||
/** | ||
@@ -103,12 +99,8 @@ * @inheritDoc | ||
*/ | ||
setOptions(nextOptions: O): Promise<void>; | ||
setContext(nextContext: Context, scope?: Scope): Promise<void>; | ||
/** | ||
* @inheritDoc | ||
*/ | ||
getContext(): Promise<Context>; | ||
getInitialScope(): Scope; | ||
/** | ||
* @inheritDoc | ||
*/ | ||
setContext(nextContext: Context): Promise<void>; | ||
/** | ||
* Returns the current used SDK version and name. {@link SdkInfo} | ||
@@ -120,4 +112,2 @@ * @returns SdkInfo | ||
protected getBackend(): B; | ||
/** Resolves all currently known breadcrumbs. */ | ||
protected getBreadcrumbs(): Promise<Breadcrumb[]>; | ||
/** Determines whether this SDK is enabled and a valid DSN is present. */ | ||
@@ -132,5 +122,6 @@ protected isEnabled(): boolean; | ||
* @param event The original event. | ||
* TODO | ||
* @returns A new event with more information. | ||
*/ | ||
protected prepareEvent(event: SentryEvent): Promise<SentryEvent>; | ||
protected prepareEvent(event: SentryEvent, scope: Scope): Promise<SentryEvent>; | ||
/** | ||
@@ -149,5 +140,6 @@ * Sends an event (either error or message) to Sentry. | ||
* @param event The event to send to Sentry. | ||
* TODO | ||
* @returns A Promise that resolves with the event status. | ||
*/ | ||
private sendEvent(event); | ||
private sendEvent(event, scope); | ||
} |
@@ -126,14 +126,10 @@ "use strict"; | ||
FrontendBase.prototype.install = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
if (!this.isEnabled()) { | ||
return [2 /*return*/, false]; | ||
} | ||
if (this.installation) { | ||
return [2 /*return*/, this.installation]; | ||
} | ||
this.installation = this.getBackend().install(); | ||
return [2 /*return*/, this.installation]; | ||
}); | ||
}); | ||
if (!this.isEnabled()) { | ||
return false; | ||
} | ||
if (this.installation) { | ||
return this.installation; | ||
} | ||
this.installation = this.getBackend().install(); | ||
return this.installation; | ||
}; | ||
@@ -143,3 +139,4 @@ /** | ||
*/ | ||
FrontendBase.prototype.captureException = function (exception) { | ||
FrontendBase.prototype.captureException = function (exception, scope) { | ||
if (scope === void 0) { scope = this.getInitialScope(); } | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -152,3 +149,3 @@ var event; | ||
event = _a.sent(); | ||
return [4 /*yield*/, this.captureEvent(event)]; | ||
return [4 /*yield*/, this.captureEvent(event, scope)]; | ||
case 2: | ||
@@ -164,3 +161,4 @@ _a.sent(); | ||
*/ | ||
FrontendBase.prototype.captureMessage = function (message) { | ||
FrontendBase.prototype.captureMessage = function (message, scope) { | ||
if (scope === void 0) { scope = this.getInitialScope(); } | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -173,3 +171,3 @@ var event; | ||
event = _a.sent(); | ||
return [4 /*yield*/, this.captureEvent(event)]; | ||
return [4 /*yield*/, this.captureEvent(event, scope)]; | ||
case 2: | ||
@@ -185,7 +183,8 @@ _a.sent(); | ||
*/ | ||
FrontendBase.prototype.captureEvent = function (event) { | ||
FrontendBase.prototype.captureEvent = function (event, scope) { | ||
if (scope === void 0) { scope = this.getInitialScope(); } | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.sendEvent(event)]; | ||
case 0: return [4 /*yield*/, this.sendEvent(event, scope)]; | ||
case 1: | ||
@@ -201,40 +200,23 @@ _a.sent(); | ||
*/ | ||
FrontendBase.prototype.addBreadcrumb = function (breadcrumb) { | ||
FrontendBase.prototype.addBreadcrumb = function (breadcrumb, scope) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _a, shouldAddBreadcrumb, beforeBreadcrumb, afterBreadcrumb, _b, maxBreadcrumbs, timestamp, mergedBreadcrumb, finalBreadcrumb; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
_a = this.getOptions(), shouldAddBreadcrumb = _a.shouldAddBreadcrumb, beforeBreadcrumb = _a.beforeBreadcrumb, afterBreadcrumb = _a.afterBreadcrumb, _b = _a.maxBreadcrumbs, maxBreadcrumbs = _b === void 0 ? MAX_BREADCRUMBS : _b; | ||
if (maxBreadcrumbs === 0) { | ||
return [2 /*return*/]; | ||
} | ||
timestamp = new Date().getTime() / 1000; | ||
mergedBreadcrumb = __assign({ timestamp: timestamp }, breadcrumb); | ||
if (shouldAddBreadcrumb && !shouldAddBreadcrumb(mergedBreadcrumb)) { | ||
return [2 /*return*/]; | ||
} | ||
finalBreadcrumb = beforeBreadcrumb | ||
? beforeBreadcrumb(mergedBreadcrumb) | ||
: mergedBreadcrumb; | ||
// We need to call this.getBreadcrumbs here, since if we assign the value to | ||
// a local variable we could get an inconsistent state if mulitple calls to | ||
// addBreadcrumb happen at the same time. DO NOT assign this.breadcrumbs to | ||
// a local variable as this would lead to a "lost update" race condition. | ||
return [4 /*yield*/, this.getBreadcrumbs()]; | ||
case 1: | ||
// We need to call this.getBreadcrumbs here, since if we assign the value to | ||
// a local variable we could get an inconsistent state if mulitple calls to | ||
// addBreadcrumb happen at the same time. DO NOT assign this.breadcrumbs to | ||
// a local variable as this would lead to a "lost update" race condition. | ||
_c.sent(); | ||
this.breadcrumbs = __spread(this.breadcrumbs, [finalBreadcrumb]).slice(-maxBreadcrumbs); | ||
return [4 /*yield*/, this.getBackend().storeBreadcrumbs(this.breadcrumbs)]; | ||
case 2: | ||
_c.sent(); | ||
if (afterBreadcrumb) { | ||
afterBreadcrumb(finalBreadcrumb); | ||
} | ||
return [2 /*return*/]; | ||
_a = this.getOptions(), shouldAddBreadcrumb = _a.shouldAddBreadcrumb, beforeBreadcrumb = _a.beforeBreadcrumb, afterBreadcrumb = _a.afterBreadcrumb, _b = _a.maxBreadcrumbs, maxBreadcrumbs = _b === void 0 ? MAX_BREADCRUMBS : _b; | ||
if (maxBreadcrumbs === 0) { | ||
return [2 /*return*/]; | ||
} | ||
timestamp = new Date().getTime() / 1000; | ||
mergedBreadcrumb = __assign({ timestamp: timestamp }, breadcrumb); | ||
if (shouldAddBreadcrumb && !shouldAddBreadcrumb(mergedBreadcrumb)) { | ||
return [2 /*return*/]; | ||
} | ||
finalBreadcrumb = beforeBreadcrumb | ||
? beforeBreadcrumb(mergedBreadcrumb) | ||
: mergedBreadcrumb; | ||
scope.breadcrumbs = __spread(scope.breadcrumbs, [finalBreadcrumb]).slice(-maxBreadcrumbs); | ||
if (afterBreadcrumb) { | ||
afterBreadcrumb(finalBreadcrumb); | ||
} | ||
return [2 /*return*/]; | ||
}); | ||
@@ -258,10 +240,17 @@ }); | ||
*/ | ||
FrontendBase.prototype.setOptions = function (nextOptions) { | ||
FrontendBase.prototype.setContext = function (nextContext, scope) { | ||
if (scope === void 0) { scope = this.getInitialScope(); } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var context; | ||
return __generator(this, function (_a) { | ||
if (nextOptions.dsn && | ||
String(this.options.dsn) !== String(nextOptions.dsn)) { | ||
this.dsn = new dsn_1.DSN(nextOptions.dsn); | ||
context = scope.context; | ||
if (nextContext.extra) { | ||
context.extra = __assign({}, context.extra, nextContext.extra); | ||
} | ||
Object.assign(this.options, nextOptions); | ||
if (nextContext.tags) { | ||
context.tags = __assign({}, context.tags, nextContext.tags); | ||
} | ||
if (nextContext.user) { | ||
context.user = __assign({}, context.user, nextContext.user); | ||
} | ||
return [2 /*return*/]; | ||
@@ -274,58 +263,8 @@ }); | ||
*/ | ||
FrontendBase.prototype.getContext = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _a, _b; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
if (!!this.context) return [3 /*break*/, 2]; | ||
_a = this; | ||
_b = [{}]; | ||
return [4 /*yield*/, this.getBackend().loadContext()]; | ||
case 1: | ||
_a.context = __assign.apply(void 0, _b.concat([(_c.sent())])); | ||
_c.label = 2; | ||
case 2: return [2 /*return*/, this.context]; | ||
} | ||
}); | ||
}); | ||
FrontendBase.prototype.getInitialScope = function () { | ||
return { | ||
breadcrumbs: [], | ||
context: {}, | ||
}; | ||
}; | ||
/** | ||
* @inheritDoc | ||
*/ | ||
FrontendBase.prototype.setContext = function (nextContext) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var context; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
// We need call this.getContext here, since if we assign the value to a | ||
// local variable we could get an inconsistent state if mulitple calls to | ||
// setContext happen at the same time. DO NOT assign this.context to a local | ||
// variable as this would lead to a "lost update" race condition. | ||
return [4 /*yield*/, this.getContext()]; | ||
case 1: | ||
// We need call this.getContext here, since if we assign the value to a | ||
// local variable we could get an inconsistent state if mulitple calls to | ||
// setContext happen at the same time. DO NOT assign this.context to a local | ||
// variable as this would lead to a "lost update" race condition. | ||
_a.sent(); | ||
context = this.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 [4 /*yield*/, this.getBackend().storeContext(context)]; | ||
case 2: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** Returns the current backend. */ | ||
@@ -335,20 +274,2 @@ FrontendBase.prototype.getBackend = function () { | ||
}; | ||
/** Resolves all currently known breadcrumbs. */ | ||
FrontendBase.prototype.getBreadcrumbs = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (!!this.breadcrumbs) return [3 /*break*/, 2]; | ||
_a = this; | ||
return [4 /*yield*/, this.getBackend().loadBreadcrumbs()]; | ||
case 1: | ||
_a.breadcrumbs = __spread.apply(void 0, [(_b.sent())]); | ||
_b.label = 2; | ||
case 2: return [2 /*return*/, this.breadcrumbs]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** Determines whether this SDK is enabled and a valid DSN is present. */ | ||
@@ -365,38 +286,32 @@ FrontendBase.prototype.isEnabled = function () { | ||
* @param event The original event. | ||
* TODO | ||
* @returns A new event with more information. | ||
*/ | ||
FrontendBase.prototype.prepareEvent = function (event) { | ||
FrontendBase.prototype.prepareEvent = function (event, scope) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _a, environment, _b, maxBreadcrumbs, release, prepared, breadcrumbs, context; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
_a = this.getOptions(), environment = _a.environment, _b = _a.maxBreadcrumbs, maxBreadcrumbs = _b === void 0 ? MAX_BREADCRUMBS : _b, release = _a.release; | ||
prepared = __assign({}, event, { sdk: this.getSdkInfo() }); | ||
if (environment !== undefined) { | ||
prepared.environment = environment; | ||
} | ||
if (release !== undefined) { | ||
prepared.release = release; | ||
} | ||
return [4 /*yield*/, this.getBreadcrumbs()]; | ||
case 1: | ||
breadcrumbs = _c.sent(); | ||
if (breadcrumbs.length > 0 && maxBreadcrumbs > 0) { | ||
prepared.breadcrumbs = breadcrumbs.slice(-maxBreadcrumbs); | ||
} | ||
return [4 /*yield*/, this.getContext()]; | ||
case 2: | ||
context = _c.sent(); | ||
if (context.extra) { | ||
prepared.extra = __assign({}, context.extra, event.extra); | ||
} | ||
if (context.tags) { | ||
prepared.tags = __assign({}, context.tags, event.tags); | ||
} | ||
if (context.user) { | ||
prepared.user = __assign({}, context.user, event.user); | ||
} | ||
return [2 /*return*/, prepared]; | ||
_a = this.getOptions(), environment = _a.environment, _b = _a.maxBreadcrumbs, maxBreadcrumbs = _b === void 0 ? MAX_BREADCRUMBS : _b, release = _a.release; | ||
prepared = __assign({}, event, { sdk: this.getSdkInfo() }); | ||
if (environment !== undefined) { | ||
prepared.environment = environment; | ||
} | ||
if (release !== undefined) { | ||
prepared.release = release; | ||
} | ||
breadcrumbs = scope.breadcrumbs; | ||
if (breadcrumbs.length > 0 && maxBreadcrumbs > 0) { | ||
prepared.breadcrumbs = breadcrumbs.slice(-maxBreadcrumbs); | ||
} | ||
context = scope.context; | ||
if (context.extra) { | ||
prepared.extra = __assign({}, context.extra, event.extra); | ||
} | ||
if (context.tags) { | ||
prepared.tags = __assign({}, context.tags, event.tags); | ||
} | ||
if (context.user) { | ||
prepared.user = __assign({}, context.user, event.user); | ||
} | ||
return [2 /*return*/, prepared]; | ||
}); | ||
@@ -418,5 +333,6 @@ }); | ||
* @param event The event to send to Sentry. | ||
* TODO | ||
* @returns A Promise that resolves with the event status. | ||
*/ | ||
FrontendBase.prototype.sendEvent = function (event) { | ||
FrontendBase.prototype.sendEvent = function (event, scope) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -430,3 +346,3 @@ var prepared, _a, shouldSend, beforeSend, afterSend, finalEvent, code, status; | ||
} | ||
return [4 /*yield*/, this.prepareEvent(event)]; | ||
return [4 /*yield*/, this.prepareEvent(event, scope)]; | ||
case 1: | ||
@@ -433,0 +349,0 @@ prepared = _b.sent(); |
import { Breadcrumb, Context, SentryEvent } from './domain'; | ||
import { DSN } from './dsn'; | ||
import { SendStatus } from './status'; | ||
/** | ||
* TODO | ||
*/ | ||
export interface Scope { | ||
breadcrumbs: Breadcrumb[]; | ||
context: Context; | ||
} | ||
/** Console logging verbosity for the SDK. */ | ||
@@ -143,5 +150,5 @@ export declare enum LogLevel { | ||
* | ||
* @returns A Promise that resolves when installation has finished. | ||
* @returns If the installation was the successful or not. | ||
*/ | ||
install(): Promise<boolean>; | ||
install(): boolean; | ||
/** | ||
@@ -151,5 +158,6 @@ * Captures an exception event and sends it to Sentry. | ||
* @param exception An exception-like object. | ||
* @returns A Promise that resolves when the exception has been sent. | ||
* TODO | ||
* @returns The created event id. | ||
*/ | ||
captureException(exception: any): Promise<void>; | ||
captureException(exception: any, scope?: Scope): Promise<void>; | ||
/** | ||
@@ -159,5 +167,6 @@ * Captures a message event and sends it to Sentry. | ||
* @param message The message to send to Sentry. | ||
* @returns A Promise that resolves when the message has been sent. | ||
* TODO | ||
* @returns The created event id. | ||
*/ | ||
captureMessage(message: string): Promise<void>; | ||
captureMessage(message: string, scope?: Scope): Promise<void>; | ||
/** | ||
@@ -167,5 +176,6 @@ * Captures a manually created event and sends it to Sentry. | ||
* @param event The event to send to Sentry. | ||
* @returns A Promise that resolves when the event has been sent. | ||
* TODO | ||
* @returns The created event id. | ||
*/ | ||
captureEvent(event: SentryEvent): Promise<void>; | ||
captureEvent(event: SentryEvent, scope?: Scope): Promise<void>; | ||
/** | ||
@@ -179,5 +189,5 @@ * Records a new breadcrumb which will be attached to future events. | ||
* @param breadcrumb The breadcrumb to record. | ||
* @returns A Promise that resolves when the breadcrumb has been persisted. | ||
* TODO | ||
*/ | ||
addBreadcrumb(breadcrumb: Breadcrumb): Promise<void>; | ||
addBreadcrumb(breadcrumb: Breadcrumb, scope?: Scope): void; | ||
/** Returns the current DSN. */ | ||
@@ -188,17 +198,10 @@ getDSN(): DSN | undefined; | ||
/** | ||
* Updates SDK options with the provided values. | ||
* | ||
* @param options A partial options object to merge into current options. | ||
* @returns A Promise that resolves when the new options have been applied. | ||
*/ | ||
setOptions(options: O): Promise<void>; | ||
/** Resolves the current context. */ | ||
getContext(): Promise<Context>; | ||
/** | ||
* Updates context information (user, tags, extras) for future events. | ||
* | ||
* @param context A partial context object to merge into current context. | ||
* @returns A Promise that resolves when the new context has been merged. | ||
* TODO | ||
*/ | ||
setContext(context: Context): Promise<void>; | ||
setContext(context: Context, scope: Scope): void; | ||
/** Returns the inital scope for the shim. */ | ||
getInitialScope(): Scope; | ||
} | ||
@@ -228,3 +231,3 @@ /** | ||
/** Installs the SDK into the environment. */ | ||
install(): Promise<boolean>; | ||
install(): boolean; | ||
/** Creates a {@link SentryEvent} from an exception. */ | ||
@@ -236,13 +239,2 @@ eventFromException(exception: any): Promise<SentryEvent>; | ||
sendEvent(event: SentryEvent): Promise<number>; | ||
/** Receives the full merged context and stores it persistently. */ | ||
storeContext(context: Context): Promise<void>; | ||
/** Returns the latest context including SDK defaults. */ | ||
loadContext(): Promise<Context>; | ||
/** | ||
* Receives a list of breadcrumbs and stores them persistently. If previously | ||
* stored breadcrumbs are missing, they should be deleted. | ||
*/ | ||
storeBreadcrumbs(breadcrumbs: Breadcrumb[]): Promise<void>; | ||
/** Returns the full list of stored breadcrumbs (or empty) */ | ||
loadBreadcrumbs(): Promise<Breadcrumb[]>; | ||
} |
@@ -1,3 +0,15 @@ | ||
import { Breadcrumb, Context, SentryEvent } from './domain'; | ||
import { Breadcrumb, SentryEvent, User } from './domain'; | ||
import { Frontend, Options } from './interfaces'; | ||
/** | ||
* TODO | ||
*/ | ||
export declare function captureEvent(event: SentryEvent): void; | ||
/** | ||
* TODO | ||
*/ | ||
export declare function addBreadcrumb(breadcrumb: Breadcrumb): void; | ||
/** | ||
* TODO | ||
*/ | ||
export declare function setUserContext(user: User): void; | ||
/** A class object that can instanciate Backend objects. */ | ||
@@ -7,70 +19,6 @@ export interface FrontendClass<F extends Frontend, O extends Options> { | ||
} | ||
/** A Sentry SDK class. */ | ||
export declare class Sdk<F extends Frontend<O>, O extends Options> { | ||
/** The SDK specific frontend class. */ | ||
private readonly frontendClass; | ||
/** The frontend instance generated in create(). */ | ||
private frontend?; | ||
/** Creates a new SDK. */ | ||
constructor(frontendClass: FrontendClass<F, O>); | ||
/** | ||
* Creates and initializes the SDK. | ||
* @param options Options to customize SDK behavior. | ||
*/ | ||
create(options: O): Promise<void>; | ||
/** | ||
* Captures an exception evebt and sends it to Sentry. | ||
* | ||
* @param exception An exception-like object. | ||
* @returns A Promise that resolves when the exception has been sent. | ||
*/ | ||
captureException(exception: any): Promise<void>; | ||
/** | ||
* Captures a message event and sends it to Sentry. | ||
* | ||
* @param message The message to send to Sentry. | ||
* @returns A Promise that resolves when the message has been sent. | ||
*/ | ||
captureMessage(message: string): Promise<void>; | ||
/** | ||
* Captures a manually created event and sends it to Sentry. | ||
* | ||
* @param event The event to send to Sentry. | ||
* @returns A Promise that resolves when the event has been sent. | ||
*/ | ||
captureEvent(event: SentryEvent): Promise<void>; | ||
/** | ||
* 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. To configure the maximum number | ||
* of breadcrumbs, use {@link Options.maxBreadcrumbs}. | ||
* | ||
* @param breadcrumb The breadcrumb to record. | ||
* @returns A Promise that resolves when the breadcrumb has been persisted. | ||
*/ | ||
addBreadcrumb(breadcrumb: Breadcrumb): Promise<void>; | ||
/** | ||
* Updates SDK options with the provided values. | ||
* | ||
* @param options A partial options object to merge into current options. | ||
* @returns A Promise that resolves when the new options have been applied. | ||
*/ | ||
setOptions(options: O): Promise<void>; | ||
/** Resolves the current context. */ | ||
getContext(): Promise<Context>; | ||
/** | ||
* Updates context information (user, tags, extras) for future events. | ||
* | ||
* @param context A partial context object to merge into current context. | ||
* @returns A Promise that resolves when the new context has been merged. | ||
*/ | ||
setContext(context: Context): Promise<void>; | ||
/** | ||
* Calls the given callback only if a frontend has been created. | ||
* | ||
* @param fn A function that will be executed if a frontend is ready. | ||
* @returns A Promise that resolves the response or undefined. | ||
*/ | ||
private withInstance<R>(fn); | ||
} | ||
/** | ||
* TODO | ||
* @param options | ||
*/ | ||
export declare function createAndBind<F extends Frontend, O extends Options>(frontendClass: FrontendClass<F, O>, options: O): void; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
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]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** A Sentry SDK class. */ | ||
var Sdk = /** @class */ (function () { | ||
/** Creates a new SDK. */ | ||
function Sdk(frontendClass) { | ||
this.frontendClass = frontendClass; | ||
var shim_1 = require("@sentry/shim"); | ||
/** | ||
* TODO | ||
*/ | ||
function captureEvent(event) { | ||
shim_1.captureEvent(event); | ||
} | ||
exports.captureEvent = captureEvent; | ||
/** | ||
* TODO | ||
*/ | ||
function addBreadcrumb(breadcrumb) { | ||
shim_1.addBreadcrumb(breadcrumb); | ||
} | ||
exports.addBreadcrumb = addBreadcrumb; | ||
/** | ||
* TODO | ||
*/ | ||
function setUserContext(user) { | ||
shim_1.setUserContext(user); | ||
} | ||
exports.setUserContext = setUserContext; | ||
/** | ||
* TODO | ||
* @param options | ||
*/ | ||
function createAndBind(frontendClass, options) { | ||
if (!shim_1.getCurrentClient()) { | ||
var client = new frontendClass(options); | ||
client.install(); | ||
shim_1.bindClient(client); | ||
} | ||
/** | ||
* Creates and initializes the SDK. | ||
* @param options Options to customize SDK behavior. | ||
*/ | ||
Sdk.prototype.create = function (options) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
this.frontend = new this.frontendClass(options); | ||
return [4 /*yield*/, this.frontend.install()]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Captures an exception evebt and sends it to Sentry. | ||
* | ||
* @param exception An exception-like object. | ||
* @returns A Promise that resolves when the exception has been sent. | ||
*/ | ||
Sdk.prototype.captureException = function (exception) { | ||
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.withInstance(function (f) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { | ||
return [2 /*return*/, f.captureException(exception)]; | ||
}); }); })]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Captures a message event and sends it to Sentry. | ||
* | ||
* @param message The message to send to Sentry. | ||
* @returns A Promise that resolves when the message has been sent. | ||
*/ | ||
Sdk.prototype.captureMessage = function (message) { | ||
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.withInstance(function (f) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { | ||
return [2 /*return*/, f.captureMessage(message)]; | ||
}); }); })]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Captures a manually created event and sends it to Sentry. | ||
* | ||
* @param event The event to send to Sentry. | ||
* @returns A Promise that resolves when the event has been sent. | ||
*/ | ||
Sdk.prototype.captureEvent = function (event) { | ||
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.withInstance(function (f) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { | ||
return [2 /*return*/, f.captureEvent(event)]; | ||
}); }); })]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* 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. To configure the maximum number | ||
* of breadcrumbs, use {@link Options.maxBreadcrumbs}. | ||
* | ||
* @param breadcrumb The breadcrumb to record. | ||
* @returns A Promise that resolves when the breadcrumb has been persisted. | ||
*/ | ||
Sdk.prototype.addBreadcrumb = function (breadcrumb) { | ||
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.withInstance(function (f) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { | ||
return [2 /*return*/, f.addBreadcrumb(breadcrumb)]; | ||
}); }); })]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Updates SDK options with the provided values. | ||
* | ||
* @param options A partial options object to merge into current options. | ||
* @returns A Promise that resolves when the new options have been applied. | ||
*/ | ||
Sdk.prototype.setOptions = function (options) { | ||
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.withInstance(function (f) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { | ||
return [2 /*return*/, f.setOptions(options)]; | ||
}); }); })]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** Resolves the current context. */ | ||
Sdk.prototype.getContext = function () { | ||
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.withInstance(function (f) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { | ||
return [2 /*return*/, f.getContext()]; | ||
}); }); })]; | ||
case 1: return [2 /*return*/, (_a.sent()) || {}]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Updates context information (user, tags, extras) for future events. | ||
* | ||
* @param context A partial context object to merge into current context. | ||
* @returns A Promise that resolves when the new context has been merged. | ||
*/ | ||
Sdk.prototype.setContext = function (context) { | ||
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.withInstance(function (f) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { | ||
return [2 /*return*/, f.setContext(context)]; | ||
}); }); })]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Calls the given callback only if a frontend has been created. | ||
* | ||
* @param fn A function that will be executed if a frontend is ready. | ||
* @returns A Promise that resolves the response or undefined. | ||
*/ | ||
Sdk.prototype.withInstance = function (fn) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, this.frontend && fn(this.frontend)]; | ||
}); | ||
}); | ||
}; | ||
return Sdk; | ||
}()); | ||
exports.Sdk = Sdk; | ||
} | ||
exports.createAndBind = createAndBind; | ||
//# sourceMappingURL=sdk.js.map |
{ | ||
"name": "@sentry/core", | ||
"version": "0.4.2", | ||
"version": "0.5.0-beta.0", | ||
"description": "Base implementation for all Sentry JavaScript SDKs", | ||
@@ -16,2 +16,6 @@ "repository": "https://github.com/getsentry/raven-js", | ||
}, | ||
"dependencies": { | ||
"@sentry/shim": "0.5.0-beta.0", | ||
"@sentry/utils": "0.5.0-beta.0" | ||
}, | ||
"devDependencies": { | ||
@@ -18,0 +22,0 @@ "chai": "^4.1.2", |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
87715
2
1223
+ Added@sentry/shim@0.5.0-beta.0
+ Added@sentry/utils@0.5.0-beta.0
+ Added@sentry/shim@0.5.0-beta.0(transitive)
+ Added@sentry/utils@0.5.0-beta.0(transitive)