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

@colearn/microservices-kit

Package Overview
Dependencies
Maintainers
3
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@colearn/microservices-kit - npm Package Compare versions

Comparing version 0.0.29 to 0.0.30

2

lib/auth.d.ts
import type { Request, Response, NextFunction } from 'express';
import { SystemRole } from './types';
import { AuthToken } from './token';

@@ -7,2 +8,3 @@ export interface AuthorizedRequest extends Request {

export declare function authorize(req: AuthorizedRequest, _: Response, next: NextFunction): void;
export declare function authorizeRoles(...roles: SystemRole[]): (req: Request, _: Response, next: NextFunction) => void;
export declare function authorizeAdmin(req: Request, _: Response, next: NextFunction): void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.authorizeAdmin = exports.authorize = void 0;
exports.authorizeAdmin = exports.authorizeRoles = exports.authorize = void 0;
const types_1 = require("./types");

@@ -16,2 +16,15 @@ const token_1 = require("./token");

exports.authorize = authorize;
function authorizeRoles(...roles) {
return (req, _, next) => {
const user = req.user;
const role = (0, token_1.parseSystemRole)(user === null || user === void 0 ? void 0 : user.scopes);
if (!role || !roles.includes(role)) {
next(new errors_1.ForbiddenError('Access Forbidden'));
}
else {
next();
}
};
}
exports.authorizeRoles = authorizeRoles;
function authorizeAdmin(req, _, next) {

@@ -18,0 +31,0 @@ const user = req.user;

2

lib/token.d.ts

@@ -10,3 +10,3 @@ import { SystemRole, User, Person, Maybe, PersonMembership } from './types';

export declare function createMembershipScopes(memberships?: Maybe<Maybe<PersonMembership>[]>): string[];
export default function createAuthToken(user: User, person?: Person): AuthToken;
export declare function createAuthToken(user: User, person?: Person): AuthToken;
export declare function parseSystemRole(scopes?: string[]): SystemRole | undefined;

@@ -13,0 +13,0 @@ export declare type RoleRecord = {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseEntityRoleRecord = exports.parseSystemRole = exports.createMembershipScopes = void 0;
exports.parseEntityRoleRecord = exports.parseSystemRole = exports.createAuthToken = exports.createMembershipScopes = void 0;
const types_1 = require("./types");

@@ -39,3 +39,3 @@ function createMembershipScopes(memberships) {

}
exports.default = createAuthToken;
exports.createAuthToken = createAuthToken;
function parseSystemRole(scopes) {

@@ -42,0 +42,0 @@ const system = scopes === null || scopes === void 0 ? void 0 : scopes.find((s) => s.startsWith('role:'));

{
"name": "@colearn/microservices-kit",
"version": "0.0.29",
"version": "0.0.30",
"description": "colearn microservice kit",

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

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