@colearn/microservices-kit
Advanced tools
Comparing version 0.0.19 to 0.0.20
@@ -13,10 +13,3 @@ import type { Request, Response, NextFunction } from 'express'; | ||
export declare function isAdmin(user?: AuthData): boolean; | ||
export declare type AuthUser = AuthData & { | ||
system: string[]; | ||
roles: { | ||
[entityType: string]: Record<string, string>; | ||
}; | ||
}; | ||
export declare function authUser(auth?: AuthData): AuthUser | undefined; | ||
export declare function authorize(req: AuthorizedRequest, _: 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 = exports.authUser = exports.isAdmin = void 0; | ||
exports.authorizeAdmin = exports.authorize = exports.isAdmin = void 0; | ||
const errors_1 = require("./errors"); | ||
@@ -10,22 +10,2 @@ function isAdmin(user) { | ||
exports.isAdmin = isAdmin; | ||
function authUser(auth) { | ||
var _a, _b, _c; | ||
var _d; | ||
if (!auth) { | ||
return undefined; | ||
} | ||
const system = ((_a = auth === null || auth === void 0 ? void 0 : auth.scopes) !== null && _a !== void 0 ? _a : []) | ||
.filter((s) => s.startsWith('role:')) | ||
.map((r) => r.split(':')[1]); | ||
const user = { ...auth, system, roles: {} }; | ||
const entityRoles = ((_b = auth.scopes) !== null && _b !== void 0 ? _b : []) | ||
.map((s) => s.split(':')) | ||
.filter((e) => e.length === 3); | ||
for (const [entity, id, role] of entityRoles) { | ||
(_c = (_d = user.roles)[entity]) !== null && _c !== void 0 ? _c : (_d[entity] = {}); | ||
user.roles[entity][id] = role; | ||
} | ||
return user; | ||
} | ||
exports.authUser = authUser; | ||
function authorize(req, _, next) { | ||
@@ -32,0 +12,0 @@ var _a; |
export { default as HttpService } from './http-service'; | ||
export * from './auth'; | ||
export * from './auth-user'; | ||
export * from './errors'; | ||
@@ -4,0 +5,0 @@ export * from './client'; |
@@ -36,2 +36,3 @@ "use strict"; | ||
__exportStar(require("./auth"), exports); | ||
__exportStar(require("./auth-user"), exports); | ||
__exportStar(require("./errors"), exports); | ||
@@ -38,0 +39,0 @@ __exportStar(require("./client"), exports); |
{ | ||
"name": "@colearn/microservices-kit", | ||
"version": "0.0.19", | ||
"version": "0.0.20", | ||
"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
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
38984
37
624