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

backtrace-service

Package Overview
Dependencies
Maintainers
7
Versions
153
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

backtrace-service - npm Package Compare versions

Comparing version 3.1.1 to 3.1.2

lib/model/errorScope.d.ts

32

lib/index.d.ts
/**
* Identity
*/
export { IUser, IServerConfiguration, IUniverse, IUniverseProject, IProjectsExt, } from './identity/model/serverConfiguration';
export { getDescriptor, listenDescriptor } from './config/config';
export { ICoronerDescriptor } from './config/model/coronerDescriptor';
export { IDescriptorOpts } from './config/model/descriptorOptions';
export { IdentityManager } from './identity/identity';
export { IAuthRequest } from './identity/model/authRequest';
export { ICoronerRequestOption } from './identity/model/authRequestOptions';
export { IAuthRequest } from './identity/model/authRequest';
export { IProjectsExt, IServerConfiguration, IUniverse, IUniverseProject, IUser, } from './identity/model/serverConfiguration';
/**
* Logging
*/
export { Logger } from './log/logger';
/**
* Metrics
*/
export { MetricsStorage } from './metrics/metricsStorage';
export { ApiError } from './model/apiError';
export { IAppOptions } from './model/appOptions';
export { IConfiguration, ILoggerOptions, IMetricsOptions, } from './model/configuration';
/**
* Logging
* Error scope
*/
export { Logger } from './log/logger';
export { ErrorScope, IErrorScopeOptions, IErrorScopeRequest, } from './model/errorScope';
/**
* Helpers
*/
export { UniverseHelper } from './universe/backtraceUniverseHelper';
/**
* Service configuration helpers
*/
export { IServiceDescriptor } from './model/serviceDescriptor';
export { getDescriptor, listenDescriptor } from './config/config';
export { ICoronerDescriptor } from './config/model/coronerDescriptor';
export { IDescriptorOpts } from './config/model/descriptorOptions';
/**

@@ -31,5 +34,6 @@ * Backtrace service initialization methods

export { BacktraceService } from './service/backtraceService';
export { IAppOptions } from './model/appOptions';
export { IConfiguration, ILoggerOptions, IMetricsOptions, } from './model/configuration';
export { ServiceConfiguration } from './service/serviceConfiguration';
export { ApiError } from './model/apiError';
/**
* Helpers
*/
export { UniverseHelper } from './universe/backtraceUniverseHelper';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApiError = exports.ServiceConfiguration = exports.BacktraceService = exports.listenDescriptor = exports.getDescriptor = exports.UniverseHelper = exports.Logger = exports.MetricsStorage = exports.IdentityManager = void 0;
exports.UniverseHelper = exports.ServiceConfiguration = exports.BacktraceService = exports.ErrorScope = exports.ApiError = exports.MetricsStorage = exports.Logger = exports.IdentityManager = exports.listenDescriptor = exports.getDescriptor = void 0;
/**
* Identity
*/
var config_1 = require("./config/config");
Object.defineProperty(exports, "getDescriptor", { enumerable: true, get: function () { return config_1.getDescriptor; } });
Object.defineProperty(exports, "listenDescriptor", { enumerable: true, get: function () { return config_1.listenDescriptor; } });
var identity_1 = require("./identity/identity");
Object.defineProperty(exports, "IdentityManager", { enumerable: true, get: function () { return identity_1.IdentityManager; } });
/**
* Logging
*/
var logger_1 = require("./log/logger");
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
/**
* Metrics

@@ -11,16 +22,10 @@ */

Object.defineProperty(exports, "MetricsStorage", { enumerable: true, get: function () { return metricsStorage_1.MetricsStorage; } });
var apiError_1 = require("./model/apiError");
Object.defineProperty(exports, "ApiError", { enumerable: true, get: function () { return apiError_1.ApiError; } });
/**
* Logging
* Error scope
*/
var logger_1 = require("./log/logger");
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
var errorScope_1 = require("./model/errorScope");
Object.defineProperty(exports, "ErrorScope", { enumerable: true, get: function () { return errorScope_1.ErrorScope; } });
/**
* Helpers
*/
var backtraceUniverseHelper_1 = require("./universe/backtraceUniverseHelper");
Object.defineProperty(exports, "UniverseHelper", { enumerable: true, get: function () { return backtraceUniverseHelper_1.UniverseHelper; } });
var config_1 = require("./config/config");
Object.defineProperty(exports, "getDescriptor", { enumerable: true, get: function () { return config_1.getDescriptor; } });
Object.defineProperty(exports, "listenDescriptor", { enumerable: true, get: function () { return config_1.listenDescriptor; } });
/**
* Backtrace service initialization methods

@@ -32,4 +37,7 @@ */

Object.defineProperty(exports, "ServiceConfiguration", { enumerable: true, get: function () { return serviceConfiguration_1.ServiceConfiguration; } });
var apiError_1 = require("./model/apiError");
Object.defineProperty(exports, "ApiError", { enumerable: true, get: function () { return apiError_1.ApiError; } });
/**
* Helpers
*/
var backtraceUniverseHelper_1 = require("./universe/backtraceUniverseHelper");
Object.defineProperty(exports, "UniverseHelper", { enumerable: true, get: function () { return backtraceUniverseHelper_1.UniverseHelper; } });
//# sourceMappingURL=index.js.map
import express from 'express';
import { BacktraceService } from '../service/backtraceService';
import { Logger } from './../log/logger';
import { BacktraceService } from '../service/backtraceService';
import { IErrorScopeOptions } from './errorScope';
export interface IAppOptions<T extends {}> {

@@ -20,2 +21,6 @@ confPath?: string;

coronerdCallback?: (ip: string) => void;
/**
* Options for the error scope middleware.
*/
errorScopeOptions?: IErrorScopeOptions;
}
import express from 'express';
import { IdentityManager } from '..';
import { Logger } from '../log/logger';
import { MetricsStorage } from '../metrics/metricsStorage';
import { IAppOptions } from '../model/appOptions';
import { IConfiguration } from '../model/configuration';
import { IErrorScopeOptions } from '../model/errorScope';
export declare class BacktraceService<T extends {}> {

@@ -46,2 +48,3 @@ private readonly name;

static setupMiddlewares(app: express.Express, prefix?: string, identityManager?: IdentityManager): void;
static setupErrorScopeMiddleware(app: express.Express, opts?: IErrorScopeOptions): void;
/**

@@ -51,3 +54,3 @@ * Setup express error middleware

*/
static setupErrorMiddleware(app: express.Express, identityManager?: IdentityManager): void;
static setupErrorMiddleware(app: express.Express, identityManager?: IdentityManager, overrideLogger?: Logger): void;
/**

@@ -54,0 +57,0 @@ * Setup security middlewares

@@ -17,2 +17,3 @@ "use strict";

const metricsStorage_1 = require("../metrics/metricsStorage");
const errorScope_1 = require("../model/errorScope");
const projectValidation_1 = require("./projectValidation");

@@ -93,2 +94,3 @@ const serviceConfiguration_1 = require("./serviceConfiguration");

const expressApp = service.app;
this.setupErrorScopeMiddleware(expressApp, opts?.errorScopeOptions);
this.setupAuth(expressApp);

@@ -150,2 +152,18 @@ this.setupMiddlewares(expressApp, service.apiPrefix, service.identityManager);

}
static setupErrorScopeMiddleware(app, opts) {
app.use((req, res, next) => {
const errorScope = new errorScope_1.ErrorScope();
if (opts?.addExpressAttributes) {
errorScope.addAttributes(() => ({
originalUrl: req.originalUrl,
protocol: req.protocol,
query: req.query,
headers: req.headers,
body: { value: req.body }, // Avoid putting string bodies in attributes
}));
}
req.errorScope = errorScope;
next();
});
}
/**

@@ -155,3 +173,3 @@ * Setup express error middleware

*/
static setupErrorMiddleware(app, identityManager) {
static setupErrorMiddleware(app, identityManager, overrideLogger) {
app.use((err, req, res, next) => {

@@ -165,3 +183,3 @@ // handle a situation when we already sent a response from onError method

}
const logger = logger_1.Logger.getLogger();
const logger = overrideLogger ?? logger_1.Logger.getLogger();
// if we reach this part of code, the error middlewa needs to assume

@@ -178,2 +196,3 @@ // the teams validation weren't handled on the route side - for example:

// to learn more how errors throwed by axios are beings handled by them.
const { errorScope } = req;
if (err.statusCode || (err.response && err.response.status)) {

@@ -183,3 +202,9 @@ const status = err.statusCode || err.response.status;

if (status === 500) {
logger.error(err);
const attributes = errorScope?.getAttributes();
if (attributes) {
logger.error(err, attributes);
}
else {
logger.error(err);
}
}

@@ -190,8 +215,15 @@ else {

res.status(status).send(message);
return;
}
logger.error(err);
res.status(500).send({
error: 'Internal server error',
});
else {
const attributes = errorScope?.getAttributes();
if (attributes) {
logger.error(err, attributes);
}
else {
logger.error(err);
}
res.status(500).send({
error: 'Internal server error',
});
}
});

@@ -267,3 +299,3 @@ app.use((req, res, next) => {

}
BacktraceService.setupErrorMiddleware(this.app, this.identityManager);
BacktraceService.setupErrorMiddleware(this.app, this.identityManager, this._opts?.logger);
(0, __1.listenDescriptor)(this._descriptor, this.app, this.configuration.ssl, () => {

@@ -270,0 +302,0 @@ this._logger.info(`Application is Running. ${this._descriptor

{
"name": "backtrace-service",
"version": "3.1.1",
"version": "3.1.2",
"description": "Common tools for Backtrace Node services",

@@ -5,0 +5,0 @@ "author": "Backtrace",

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