@sentry/shim
Advanced tools
Comparing version 0.5.0-beta.0 to 0.5.0-beta.1
@@ -1,1 +0,1 @@ | ||
export { addBreadcrumb, bindClient, captureMessage, captureException, captureEvent, clearScope, getCurrentClient, popScope, pushScope, setUserContext, setTagsContext, setExtraContext, withScope } from './lib/shim'; | ||
export { addBreadcrumb, bindClient, _callOnClient, captureMessage, captureException, captureEvent, clearScope, getCurrentClient, popScope, pushScope, setUserContext, setTagsContext, setExtraContext, withScope } from './lib/shim'; |
@@ -6,2 +6,3 @@ "use strict"; | ||
exports.bindClient = shim_1.bindClient; | ||
exports._callOnClient = shim_1._callOnClient; | ||
exports.captureMessage = shim_1.captureMessage; | ||
@@ -8,0 +9,0 @@ exports.captureException = shim_1.captureException; |
/** | ||
* TODO | ||
* Create a new scope to store context information. | ||
*/ | ||
export declare function pushScope(client?: any): void; | ||
/** | ||
* TODO | ||
* Resets the current scope and removes it from the stack. | ||
*/ | ||
export declare function popScope(): void; | ||
/** | ||
* TODO | ||
* Create a new scope to store context information. Convenience function instead | ||
* of: pushScope(); callback(); popScope(); | ||
* @param client | ||
* @param callback | ||
*/ | ||
export declare function withScope(client: any, callback: () => void): void; | ||
/** | ||
* Create a new scope to store context information. Convenience function instead | ||
* of: pushScope(); callback(); popScope(); | ||
* @param callback | ||
* @param client | ||
*/ | ||
export declare function withScope(callback: () => void, client?: any): void; | ||
/** | ||
* TODO | ||
* This clears the current scope and resets it to the initalScope. | ||
*/ | ||
export declare function clearScope(): void; | ||
/** | ||
* TODO | ||
* Returns the current used client. | ||
* @returns client | undefined | ||
*/ | ||
export declare function getCurrentClient(): any | undefined; | ||
/** | ||
* TODO | ||
* This binds a client to the stack top. | ||
* @param client | ||
*/ | ||
@@ -28,6 +39,3 @@ export declare function bindClient(client: any): void; | ||
* Captures an exception event and sends it to Sentry. | ||
* | ||
* @param exception An exception-like object. | ||
* TODO | ||
* @returns A Promise that resolves when the exception has been sent. | ||
*/ | ||
@@ -37,11 +45,8 @@ export declare function captureException(exception: any): void; | ||
* Captures a message event and sends it to Sentry. | ||
* | ||
* @param message The message to send to Sentry. | ||
* TODO | ||
* @returns A Promise that resolves when the message has been sent. | ||
*/ | ||
export declare function captureMessage(message: string): void; | ||
/** | ||
* TODO | ||
* @param event T | ||
* Captures a manually created event and sends it to Sentry. | ||
* @param event The event to send to Sentry. | ||
*/ | ||
@@ -53,20 +58,14 @@ export declare function captureEvent(event: any): void; | ||
* 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}. | ||
* | ||
* user's actions prior to an error or crash. | ||
* @param breadcrumb The breadcrumb to record. | ||
* TODO | ||
* @returns A Promise that resolves when the breadcrumb has been persisted. | ||
*/ | ||
export declare function addBreadcrumb(breadcrumb: object): void; | ||
/** | ||
* 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. | ||
* Updates user context information for future events. | ||
* @param extra User context object to merge into current context. | ||
*/ | ||
export declare function setUserContext(user: object): void; | ||
/** | ||
* TODO | ||
* @param tags T | ||
* Updates tags context information for future events. | ||
* @param extra Tags context object to merge into current context. | ||
*/ | ||
@@ -77,5 +76,13 @@ export declare function setTagsContext(tags: { | ||
/** | ||
* TODO | ||
* @param tags T | ||
* Updates extra context information for future events. | ||
* @param extra Extra context object to merge into current context. | ||
*/ | ||
export declare function setExtraContext(extra: object): void; | ||
/** | ||
* This calls a function on the latest client. Use this with caution, it's | ||
* meant as in "internal" helper so we don't need to expose every possible | ||
* function in the shim. | ||
* @param method The method to call on the client/frontend. | ||
* @param args Arguments to pass to the client/fontend. | ||
*/ | ||
export declare function _callOnClient(method: string, ...args: any[]): void; |
@@ -24,2 +24,5 @@ "use strict"; | ||
var domain_1 = require("./domain"); | ||
/** | ||
* This number should only be increased if we ever change the Global interface. | ||
*/ | ||
var API_VERSION = 1; | ||
@@ -31,3 +34,4 @@ global.__SENTRY__ = global.__SENTRY__ || { | ||
/** | ||
* TODO | ||
* Internal class used to make sure we always have the latest internal functions | ||
* working in case we have a version conflict. | ||
*/ | ||
@@ -40,3 +44,4 @@ var Shim = /** @class */ (function () { | ||
/** | ||
* TODO | ||
* Checks the domain > local > process, stack an returns the top most item. | ||
* @returns The top most ScopeLayer. | ||
*/ | ||
@@ -47,3 +52,5 @@ Shim.prototype.getStackTop = function () { | ||
/** | ||
* TODO | ||
* Returns true if the passed version in bigger than the one set in the class. | ||
* User to check in case of multiple modules in global space. | ||
* @param version number | ||
*/ | ||
@@ -54,9 +61,12 @@ Shim.prototype.isOlderThan = function (version) { | ||
/** | ||
* TODO | ||
* Creates a new 'local' ScopeLayer with the client passed of the current | ||
* Client set. | ||
* @param client | ||
*/ | ||
Shim.prototype.pushScope = function (client) { | ||
var usedClient = client || getCurrentClient(); | ||
var currentClient = getCurrentClient(); | ||
var usedClient = client || currentClient; | ||
var layer = { | ||
client: usedClient, | ||
scope: usedClient.getInitialScope(), | ||
scope: this.getInitialScope(usedClient), | ||
type: 'local', | ||
@@ -73,3 +83,3 @@ }; | ||
/** | ||
* TODO | ||
* Removes the top most ScopeLayer of the current stack. | ||
*/ | ||
@@ -84,3 +94,5 @@ Shim.prototype.popScope = function () { | ||
/** | ||
* TODO | ||
* Same as pushScope/popScope. Convience method. | ||
* @param arg1 client | callback | ||
* @param arg2 client | callback | ||
*/ | ||
@@ -107,10 +119,10 @@ Shim.prototype.withScope = function (arg1, arg2) { | ||
/** | ||
* TODO | ||
* Resets the current scope to the initialScope. | ||
*/ | ||
Shim.prototype.clearScope = function () { | ||
var top = this.getStackTop(); | ||
top.scope = top.client.getInitialScope(); | ||
top.scope = this.getInitialScope(top.client); | ||
}; | ||
/** | ||
* TODO | ||
* Always returns the base processStack from global. | ||
*/ | ||
@@ -121,3 +133,3 @@ Shim.prototype.getProcessStack = function () { | ||
/** | ||
* TODO | ||
* Returns the top most ScopeLayer from the processStack. | ||
*/ | ||
@@ -135,3 +147,4 @@ Shim.prototype.getProcessStackTop = function () { | ||
/** | ||
* TODO | ||
* Checks if there is an active domain, if so a new domainStack will be | ||
* returned. Otherwise we return undefined. | ||
*/ | ||
@@ -149,3 +162,3 @@ Shim.prototype.getDomainStack = function () { | ||
/** | ||
* TODO | ||
* Tries to return the top most ScopeLayer from the domainStack. | ||
*/ | ||
@@ -158,5 +171,6 @@ Shim.prototype.getDomainStackTop = function () { | ||
if (stack.length === 0) { | ||
var client = getCurrentClient(); | ||
stack.push({ | ||
client: getCurrentClient(), | ||
scope: this.getInitialScope(), | ||
client: client, | ||
scope: this.getInitialScope(client), | ||
type: 'domain', | ||
@@ -168,8 +182,10 @@ }); | ||
/** | ||
* TODO | ||
* Tries to call the function getInitialScope on the client. | ||
* Fallback to empty {} in case function doesn't exist. | ||
* @param client | ||
*/ | ||
Shim.prototype.getInitialScope = function () { | ||
Shim.prototype.getInitialScope = function (client) { | ||
var initalScope = {}; | ||
try { | ||
initalScope = getCurrentClient() && getCurrentClient().getInitialScope(); | ||
initalScope = client && client.getInitialScope(); | ||
} | ||
@@ -184,3 +200,3 @@ catch (_a) { | ||
/** | ||
* TODO | ||
* Returns and sets the current most uptodate shim into the gobal context. | ||
*/ | ||
@@ -195,3 +211,3 @@ function _getLatestShim() { | ||
/** | ||
* TODO | ||
* Internal helper function to silently catch rejected promises. | ||
* @param promise | ||
@@ -207,3 +223,3 @@ */ | ||
/** | ||
* TODO | ||
* Create a new scope to store context information. | ||
*/ | ||
@@ -215,3 +231,3 @@ function pushScope(client) { | ||
/** | ||
* TODO | ||
* Resets the current scope and removes it from the stack. | ||
*/ | ||
@@ -227,3 +243,3 @@ function popScope() { | ||
/** | ||
* TODO | ||
* This clears the current scope and resets it to the initalScope. | ||
*/ | ||
@@ -235,3 +251,4 @@ function clearScope() { | ||
/** | ||
* TODO | ||
* Returns the current used client. | ||
* @returns client | undefined | ||
*/ | ||
@@ -243,12 +260,16 @@ function getCurrentClient() { | ||
/** | ||
* TODO | ||
* This binds a client to the stack top. | ||
* @param client | ||
*/ | ||
function bindClient(client) { | ||
var top = _getLatestShim().getStackTop(); | ||
var shim = _getLatestShim(); | ||
var top = shim.getStackTop(); | ||
top.client = client; | ||
top.scope = client.getInitialScope(); | ||
top.scope = shim.getInitialScope(client); | ||
} | ||
exports.bindClient = bindClient; | ||
/** | ||
* TODO | ||
* Internal helper function to call a method on the top client if it exists. | ||
* @param method The method to call on the client/frontend. | ||
* @param args Arguments to pass to the client/fontend. | ||
*/ | ||
@@ -268,6 +289,3 @@ function _callOnLatestShim(method) { | ||
* Captures an exception event and sends it to Sentry. | ||
* | ||
* @param exception An exception-like object. | ||
* TODO | ||
* @returns A Promise that resolves when the exception has been sent. | ||
*/ | ||
@@ -280,6 +298,3 @@ function captureException(exception) { | ||
* Captures a message event and sends it to Sentry. | ||
* | ||
* @param message The message to send to Sentry. | ||
* TODO | ||
* @returns A Promise that resolves when the message has been sent. | ||
*/ | ||
@@ -291,4 +306,4 @@ function captureMessage(message) { | ||
/** | ||
* TODO | ||
* @param event T | ||
* Captures a manually created event and sends it to Sentry. | ||
* @param event The event to send to Sentry. | ||
*/ | ||
@@ -303,8 +318,4 @@ function captureEvent(event) { | ||
* 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}. | ||
* | ||
* user's actions prior to an error or crash. | ||
* @param breadcrumb The breadcrumb to record. | ||
* TODO | ||
* @returns A Promise that resolves when the breadcrumb has been persisted. | ||
*/ | ||
@@ -316,6 +327,4 @@ function addBreadcrumb(breadcrumb) { | ||
/** | ||
* 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. | ||
* Updates user context information for future events. | ||
* @param extra User context object to merge into current context. | ||
*/ | ||
@@ -327,4 +336,4 @@ function setUserContext(user) { | ||
/** | ||
* TODO | ||
* @param tags T | ||
* Updates tags context information for future events. | ||
* @param extra Tags context object to merge into current context. | ||
*/ | ||
@@ -336,4 +345,4 @@ function setTagsContext(tags) { | ||
/** | ||
* TODO | ||
* @param tags T | ||
* Updates extra context information for future events. | ||
* @param extra Extra context object to merge into current context. | ||
*/ | ||
@@ -344,2 +353,17 @@ function setExtraContext(extra) { | ||
exports.setExtraContext = setExtraContext; | ||
/** | ||
* This calls a function on the latest client. Use this with caution, it's | ||
* meant as in "internal" helper so we don't need to expose every possible | ||
* function in the shim. | ||
* @param method The method to call on the client/frontend. | ||
* @param args Arguments to pass to the client/fontend. | ||
*/ | ||
function _callOnClient(method) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
_callOnLatestShim.apply(void 0, __spread([method], args)); | ||
} | ||
exports._callOnClient = _callOnClient; | ||
//# sourceMappingURL=shim.js.map |
{ | ||
"name": "@sentry/shim", | ||
"version": "0.5.0-beta.0", | ||
"version": "0.5.0-beta.1", | ||
"description": "Sentry shim which can be used in libraries", | ||
@@ -23,2 +23,3 @@ "repository": "https://github.com/getsentry/raven-js", | ||
"rimraf": "^2.6.2", | ||
"sinon": "^4.4.9", | ||
"tslint": "^5.9.1", | ||
@@ -25,0 +26,0 @@ "typescript": "^2.7.2" |
export { | ||
addBreadcrumb, | ||
bindClient, | ||
_callOnClient, | ||
captureMessage, | ||
@@ -5,0 +6,0 @@ captureException, |
import { shimDomain } from './domain'; | ||
/** | ||
* This number should only be increased if we ever change the Global interface. | ||
*/ | ||
const API_VERSION = 1; | ||
/** | ||
* TODO | ||
* Global interface helper for type safety. | ||
*/ | ||
@@ -25,3 +28,3 @@ interface Global { | ||
/** | ||
* TODO | ||
* This is our internal interface for each layer in the current stack. | ||
*/ | ||
@@ -35,3 +38,4 @@ interface ScopeLayer { | ||
/** | ||
* TODO | ||
* Internal class used to make sure we always have the latest internal functions | ||
* working in case we have a version conflict. | ||
*/ | ||
@@ -42,3 +46,4 @@ class Shim { | ||
/** | ||
* TODO | ||
* Checks the domain > local > process, stack an returns the top most item. | ||
* @returns The top most ScopeLayer. | ||
*/ | ||
@@ -50,3 +55,5 @@ public getStackTop(): ScopeLayer { | ||
/** | ||
* TODO | ||
* Returns true if the passed version in bigger than the one set in the class. | ||
* User to check in case of multiple modules in global space. | ||
* @param version number | ||
*/ | ||
@@ -58,9 +65,12 @@ public isOlderThan(version: number): boolean { | ||
/** | ||
* TODO | ||
* Creates a new 'local' ScopeLayer with the client passed of the current | ||
* Client set. | ||
* @param client | ||
*/ | ||
public pushScope(client?: any): void { | ||
const usedClient = client || getCurrentClient(); | ||
const currentClient = getCurrentClient(); | ||
const usedClient = client || currentClient; | ||
const layer: ScopeLayer = { | ||
client: usedClient, | ||
scope: usedClient.getInitialScope(), | ||
scope: this.getInitialScope(usedClient), | ||
type: 'local', | ||
@@ -77,3 +87,3 @@ }; | ||
/** | ||
* TODO | ||
* Removes the top most ScopeLayer of the current stack. | ||
*/ | ||
@@ -89,3 +99,5 @@ public popScope(): boolean { | ||
/** | ||
* TODO | ||
* Same as pushScope/popScope. Convience method. | ||
* @param arg1 client | callback | ||
* @param arg2 client | callback | ||
*/ | ||
@@ -112,11 +124,11 @@ public withScope(arg1: (() => void) | any, arg2?: (() => void) | any): void { | ||
/** | ||
* TODO | ||
* Resets the current scope to the initialScope. | ||
*/ | ||
public clearScope(): void { | ||
const top = this.getStackTop(); | ||
top.scope = top.client.getInitialScope(); | ||
top.scope = this.getInitialScope(top.client); | ||
} | ||
/** | ||
* TODO | ||
* Always returns the base processStack from global. | ||
*/ | ||
@@ -128,3 +140,3 @@ private getProcessStack(): ScopeLayer[] { | ||
/** | ||
* TODO | ||
* Returns the top most ScopeLayer from the processStack. | ||
*/ | ||
@@ -143,3 +155,4 @@ private getProcessStackTop(): ScopeLayer { | ||
/** | ||
* TODO | ||
* Checks if there is an active domain, if so a new domainStack will be | ||
* returned. Otherwise we return undefined. | ||
*/ | ||
@@ -158,3 +171,3 @@ private getDomainStack(): ScopeLayer[] | undefined { | ||
/** | ||
* TODO | ||
* Tries to return the top most ScopeLayer from the domainStack. | ||
*/ | ||
@@ -167,5 +180,6 @@ private getDomainStackTop(): ScopeLayer | undefined { | ||
if (stack.length === 0) { | ||
const client = getCurrentClient(); | ||
stack.push({ | ||
client: getCurrentClient(), | ||
scope: this.getInitialScope(), | ||
client, | ||
scope: this.getInitialScope(client), | ||
type: 'domain', | ||
@@ -178,8 +192,10 @@ }); | ||
/** | ||
* TODO | ||
* Tries to call the function getInitialScope on the client. | ||
* Fallback to empty {} in case function doesn't exist. | ||
* @param client | ||
*/ | ||
private getInitialScope(): any { | ||
public getInitialScope(client: any): any { | ||
let initalScope = {}; | ||
try { | ||
initalScope = getCurrentClient() && getCurrentClient().getInitialScope(); | ||
initalScope = client && client.getInitialScope(); | ||
} catch { | ||
@@ -193,3 +209,3 @@ // we do nothing | ||
/** | ||
* TODO | ||
* Returns and sets the current most uptodate shim into the gobal context. | ||
*/ | ||
@@ -207,3 +223,3 @@ function _getLatestShim(): Shim { | ||
/** | ||
* TODO | ||
* Internal helper function to silently catch rejected promises. | ||
* @param promise | ||
@@ -220,3 +236,3 @@ */ | ||
/** | ||
* TODO | ||
* Create a new scope to store context information. | ||
*/ | ||
@@ -228,3 +244,3 @@ export function pushScope(client?: any): void { | ||
/** | ||
* TODO | ||
* Resets the current scope and removes it from the stack. | ||
*/ | ||
@@ -236,5 +252,14 @@ export function popScope(): void { | ||
/** | ||
* TODO | ||
* Create a new scope to store context information. Convenience function instead | ||
* of: pushScope(); callback(); popScope(); | ||
* @param client | ||
* @param callback | ||
*/ | ||
export function withScope(client: any, callback: () => void): void; | ||
/** | ||
* Create a new scope to store context information. Convenience function instead | ||
* of: pushScope(); callback(); popScope(); | ||
* @param callback | ||
* @param client | ||
*/ | ||
export function withScope(callback: () => void, client?: any): void; | ||
@@ -246,3 +271,3 @@ export function withScope(arg1: any, arg2: any): void { | ||
/** | ||
* TODO | ||
* This clears the current scope and resets it to the initalScope. | ||
*/ | ||
@@ -254,3 +279,4 @@ export function clearScope(): void { | ||
/** | ||
* TODO | ||
* Returns the current used client. | ||
* @returns client | undefined | ||
*/ | ||
@@ -262,12 +288,16 @@ export function getCurrentClient(): any | undefined { | ||
/** | ||
* TODO | ||
* This binds a client to the stack top. | ||
* @param client | ||
*/ | ||
export function bindClient(client: any): void { | ||
const top = _getLatestShim().getStackTop(); | ||
const shim = _getLatestShim(); | ||
const top = shim.getStackTop(); | ||
top.client = client; | ||
top.scope = client.getInitialScope(); | ||
top.scope = shim.getInitialScope(client); | ||
} | ||
/** | ||
* TODO | ||
* Internal helper function to call a method on the top client if it exists. | ||
* @param method The method to call on the client/frontend. | ||
* @param args Arguments to pass to the client/fontend. | ||
*/ | ||
@@ -283,6 +313,3 @@ function _callOnLatestShim(method: string, ...args: any[]): void { | ||
* Captures an exception event and sends it to Sentry. | ||
* | ||
* @param exception An exception-like object. | ||
* TODO | ||
* @returns A Promise that resolves when the exception has been sent. | ||
*/ | ||
@@ -292,8 +319,6 @@ export function captureException(exception: any): void { | ||
} | ||
/** | ||
* Captures a message event and sends it to Sentry. | ||
* | ||
* @param message The message to send to Sentry. | ||
* TODO | ||
* @returns A Promise that resolves when the message has been sent. | ||
*/ | ||
@@ -305,4 +330,4 @@ export function captureMessage(message: string): void { | ||
/** | ||
* TODO | ||
* @param event T | ||
* Captures a manually created event and sends it to Sentry. | ||
* @param event The event to send to Sentry. | ||
*/ | ||
@@ -317,8 +342,4 @@ export function captureEvent(event: any): void { | ||
* 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}. | ||
* | ||
* user's actions prior to an error or crash. | ||
* @param breadcrumb The breadcrumb to record. | ||
* TODO | ||
* @returns A Promise that resolves when the breadcrumb has been persisted. | ||
*/ | ||
@@ -330,6 +351,4 @@ export function addBreadcrumb(breadcrumb: object): void { | ||
/** | ||
* 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. | ||
* Updates user context information for future events. | ||
* @param extra User context object to merge into current context. | ||
*/ | ||
@@ -341,4 +360,4 @@ export function setUserContext(user: object): void { | ||
/** | ||
* TODO | ||
* @param tags T | ||
* Updates tags context information for future events. | ||
* @param extra Tags context object to merge into current context. | ||
*/ | ||
@@ -350,4 +369,4 @@ export function setTagsContext(tags: { [key: string]: string }): void { | ||
/** | ||
* TODO | ||
* @param tags T | ||
* Updates extra context information for future events. | ||
* @param extra Extra context object to merge into current context. | ||
*/ | ||
@@ -357,1 +376,12 @@ export function setExtraContext(extra: object): void { | ||
} | ||
/** | ||
* This calls a function on the latest client. Use this with caution, it's | ||
* meant as in "internal" helper so we don't need to expose every possible | ||
* function in the shim. | ||
* @param method The method to call on the client/frontend. | ||
* @param args Arguments to pass to the client/fontend. | ||
*/ | ||
export function _callOnClient(method: string, ...args: any[]): void { | ||
_callOnLatestShim(method, ...args); | ||
} |
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
231825
45
1512
9