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.2 to 3.2.0

16

lib/identity/identity.d.ts

@@ -15,8 +15,20 @@ import { NextFunction, Request, Response } from 'express';

};
/**
* Sets the coroned callback function - the funciton that will be
* executed by the identity manager, when a new coronerd instance
* registers. Setting a new coronerd callback will also invoke the
* callback funciton with all saved unique ip addresses.
* @param callback: callback function that retrieves a registered coronerd ip address
*/
coronerdCallback(callback: (ip: string, alreadyRegistered: boolean) => Promise<void> | void): void;
private registeredUniverses;
/**
* Coronerd callback function
*/
private onCoronerCallback?;
private logger?;
private httpsAgent;
constructor(descr: IServiceDescriptor);
constructor(descr: IServiceDescriptor, logger?: Logger);
setLogger(logger: Logger): void;
serviceRequest(opts?: ICoronerRequestOption): ((request: Request, response: Response, next: NextFunction) => void)[];
serviceRequest(opts?: ICoronerRequestOption): ((request: Request, response: Response, next: NextFunction) => Promise<void>)[];
/**

@@ -23,0 +35,0 @@ * Generate a middleware for Express.js which validates a request

52

lib/identity/identity.js

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

const axios_1 = __importDefault(require("axios"));
const body_parser_1 = __importDefault(require("body-parser"));
const crypto_1 = require("crypto");

@@ -38,3 +37,3 @@ const https_1 = __importDefault(require("https"));

class IdentityManager {
constructor(descr) {
constructor(descr, logger) {
this.descr = descr;

@@ -55,3 +54,25 @@ /*

: https_1.default.globalAgent;
if (logger) {
this.setLogger(logger);
}
}
/**
* Sets the coroned callback function - the funciton that will be
* executed by the identity manager, when a new coronerd instance
* registers. Setting a new coronerd callback will also invoke the
* callback funciton with all saved unique ip addresses.
* @param callback: callback function that retrieves a registered coronerd ip address
*/
coronerdCallback(callback) {
this.onCoronerCallback = callback;
const authenticatedIpAddresses = Object.keys(this.authenticated);
authenticatedIpAddresses.forEach(async (ip) => {
/**
* Pass false as a alreadyRegisteredFlag to tell
* the callback function, this is a new coroned address for
* the callback consumer.
*/
await callback(ip, false);
});
}
setLogger(logger) {

@@ -70,2 +91,5 @@ if (!logger || !logger.log) {

serviceRequest(opts) {
if (opts?.coronerdCallback) {
this.onCoronerCallback = opts.coronerdCallback;
}
/*

@@ -76,10 +100,9 @@ * Handle <prefix>/service requests. These require action QS. Other QS

return [
body_parser_1.default.json(),
(request, response, next) => {
async (request, response, next) => {
if (!request.body) {
throw new apiError_1.ApiError('Missing body', 400);
return next(new apiError_1.ApiError('Missing body', 400));
}
const action = request.body.action;
if (!action) {
throw new apiError_1.ApiError('Missing action parameter', 400);
return next(new apiError_1.ApiError('Missing action parameter', 400));
}

@@ -90,12 +113,13 @@ switch (action) {

if (!url || !nonce || !hmac) {
throw new apiError_1.ApiError(`missing parameters
${!url ? 'url' : ''}
${!nonce ? 'nonce' : ''}
${!hmac ? 'hmac' : ''}`, 400);
return next(new apiError_1.ApiError(`missing parameters
${!url ? 'url' : ''}
${!nonce ? 'nonce' : ''}
${!hmac ? 'hmac' : ''}`, 400));
}
if (!this.checkHmac(this.descr.secret, nonce, hmac)) {
throw new apiError_1.ApiError('Unauthorized', 403);
return next(new apiError_1.ApiError('Unauthorized', 403));
}
/* Track authenticated URLs. */
if (!this.authenticated[url]) {
const alreadyRegistered = !!this.authenticated[url];
if (!alreadyRegistered) {
this.authenticated[url] = {};

@@ -116,4 +140,4 @@ }

});
if (opts && opts.coronerdCallback) {
opts.coronerdCallback(url);
if (this.onCoronerCallback) {
await this.onCoronerCallback(url, alreadyRegistered);
}

@@ -120,0 +144,0 @@ // Ignore project validation in service layer handshake.

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

hostUrl: this.configuration?.metrics?.hostUrl,
disableExpressMetrics: this.configuration?.metrics?.disableExpressMetrics,
disableExpressMetrics: this.configuration?.metrics
?.disableExpressMetrics,
}, this.app, this._logger);

@@ -338,3 +339,3 @@ this.prepareServiceLayer();

}
this.identityManager = new __1.IdentityManager(this._descriptor);
this.identityManager = new __1.IdentityManager(this._descriptor, this._logger);
}

@@ -341,0 +342,0 @@ }

{
"name": "backtrace-service",
"version": "3.1.2",
"version": "3.2.0",
"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