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

efesto

Package Overview
Dependencies
Maintainers
0
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

efesto - npm Package Compare versions

Comparing version 0.16.0 to 0.16.1

1

dist/efesto.d.ts

@@ -10,4 +10,5 @@ declare global {

var verbose: boolean;
var mongoIdParser: boolean;
}
}
export {};

3

dist/engine/wrapperResolver.d.ts
import type { NextFunction, Request, Response } from "express";
declare const wrapperResolver: (functionToCall: (req: Request, res: Response, next: NextFunction) => Promise<any>) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
declare const wrapperResolver: (functionToCall: (req: Request, res: Response, next: NextFunction) => Promise<any>) => (req: Request, res: Response, next: NextFunction) => Promise<any>;
export default wrapperResolver;
export declare function idFieldAdder(ret: any, _depth?: number): any;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.idFieldAdder = void 0;
const tslib_1 = require("tslib");
const wrapperResolver = (functionToCall) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const result = yield functionToCall(req, res, next);
let result = yield functionToCall(req, res, next);
//@ts-ignore
// console.log(res.originalBody);
if (Efesto.mongoIdParser) {
//@ts-ignore
result = idFieldAdder(res.originalBody);
//@ts-ignore
return res.originalJson(result);
}
//TODO: keep an eye on this

@@ -12,2 +21,22 @@ if (result && !res.headersSent) {

exports.default = wrapperResolver;
function idFieldAdder(ret, _depth = 0) {
// recursive function to add id field to the object
let newRet = JSON.parse(JSON.stringify(ret));
if (ret === null || ret === undefined) {
return newRet;
}
if (Array.isArray(ret)) {
return newRet.map((item) => idFieldAdder(item, _depth + 1));
}
if (typeof ret === "object") {
if (ret._id) {
newRet.id = ret._id;
}
Object.keys(newRet).forEach((key) => {
newRet[key] = idFieldAdder(newRet[key], _depth + 1);
});
}
return newRet;
}
exports.idFieldAdder = idFieldAdder;
//# sourceMappingURL=wrapperResolver.js.map

@@ -12,2 +12,3 @@ export * from "./serviceUtils/types";

verbose?: boolean;
mongoIdParser?: boolean;
abacPermissions?: {

@@ -14,0 +15,0 @@ actions?: string[];

@@ -23,3 +23,3 @@ "use strict";

function efesto(params) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
global.Efesto = {

@@ -33,2 +33,3 @@ generatedTypesFolder: (_a = params.options) === null || _a === void 0 ? void 0 : _a.generatedTypesFolder,

verbose: (_r = (_q = (_p = params.options) === null || _p === void 0 ? void 0 : _p.config) === null || _q === void 0 ? void 0 : _q.verbose) !== null && _r !== void 0 ? _r : false,
mongoIdParser: (_u = (_t = (_s = params.options) === null || _s === void 0 ? void 0 : _s.config) === null || _t === void 0 ? void 0 : _t.mongoIdParser) !== null && _u !== void 0 ? _u : false,
};

@@ -44,3 +45,3 @@ if (global.Efesto.verbose)

}
const config = (_s = params === null || params === void 0 ? void 0 : params.options) === null || _s === void 0 ? void 0 : _s.config;
const config = (_v = params === null || params === void 0 ? void 0 : params.options) === null || _v === void 0 ? void 0 : _v.config;
const upload = (0, multer_1.default)();

@@ -62,3 +63,3 @@ const router = (0, express_promise_router_1.default)();

}
const baseSwagger = ((_t = params === null || params === void 0 ? void 0 : params.options) === null || _t === void 0 ? void 0 : _t.relativeDirSwaggerDeclarationsPath) || "swagger-declarations";
const baseSwagger = ((_w = params === null || params === void 0 ? void 0 : params.options) === null || _w === void 0 ? void 0 : _w.relativeDirSwaggerDeclarationsPath) || "swagger-declarations";
const baseApiURI = `${baseSwagger}/baseIndex.yaml`;

@@ -79,3 +80,3 @@ const destinationURI = `${baseSwagger}/index.yaml`;

catch (err) { }
const paramsAbsoluteDirRouter = ((_u = params === null || params === void 0 ? void 0 : params.options) === null || _u === void 0 ? void 0 : _u.absoluteDirRoutes) || [];
const paramsAbsoluteDirRouter = ((_x = params === null || params === void 0 ? void 0 : params.options) === null || _x === void 0 ? void 0 : _x.absoluteDirRoutes) || [];
const baseDir = (0, isArray_1.default)(paramsAbsoluteDirRouter)

@@ -85,7 +86,7 @@ ? paramsAbsoluteDirRouter

const redisAndPermissionMiddleware = (options) => (req, res, next) => tslib_1.__awaiter(this, void 0, void 0, function* () {
var _x, _y, _z, _0, _1, _2;
const abilityField = ((_x = config === null || config === void 0 ? void 0 : config.abacPermissions) === null || _x === void 0 ? void 0 : _x.reqAbilityField) || "ability";
const hasToCheckPermissions = (_z = (_y = config === null || config === void 0 ? void 0 : config.abacPermissions) === null || _y === void 0 ? void 0 : _y.checkPermissionBeforeResolver) !== null && _z !== void 0 ? _z : true;
var _0, _1, _2, _3, _4, _5;
const abilityField = ((_0 = config === null || config === void 0 ? void 0 : config.abacPermissions) === null || _0 === void 0 ? void 0 : _0.reqAbilityField) || "ability";
const hasToCheckPermissions = (_2 = (_1 = config === null || config === void 0 ? void 0 : config.abacPermissions) === null || _1 === void 0 ? void 0 : _1.checkPermissionBeforeResolver) !== null && _2 !== void 0 ? _2 : true;
if (hasToCheckPermissions && (options === null || options === void 0 ? void 0 : options.permission) && req[abilityField]) {
ability_1.ForbiddenError.from(req[abilityField]).throwUnlessCan((_0 = options === null || options === void 0 ? void 0 : options.permission) === null || _0 === void 0 ? void 0 : _0.action, (_1 = options === null || options === void 0 ? void 0 : options.permission) === null || _1 === void 0 ? void 0 : _1.model);
ability_1.ForbiddenError.from(req[abilityField]).throwUnlessCan((_3 = options === null || options === void 0 ? void 0 : options.permission) === null || _3 === void 0 ? void 0 : _3.action, (_4 = options === null || options === void 0 ? void 0 : options.permission) === null || _4 === void 0 ? void 0 : _4.model);
}

@@ -123,3 +124,3 @@ try {

if (options === null || options === void 0 ? void 0 : options.cache) {
const key = eval((_2 = options === null || options === void 0 ? void 0 : options.cache) === null || _2 === void 0 ? void 0 : _2.key);
const key = eval((_5 = options === null || options === void 0 ? void 0 : options.cache) === null || _5 === void 0 ? void 0 : _5.key);
const value = yield redisClient.get(key);

@@ -146,2 +147,20 @@ if (value)

});
const jsonParserMiddleware = (req, res, next) => {
if (Efesto.mongoIdParser) {
const originalJson = res.json;
// Override res.json to capture the response body
// @ts-ignore
res.json = function (body) {
// Here you can log or modify the response body
// console.log("Intercepted JSON Response Body:", body);
// Call the original res.json with the original body
// @ts-ignore
res.originalBody = body;
// @ts-ignore
res.originalJson = originalJson;
// originalJson.call(this, body);
};
}
next();
};
baseDir.forEach((dir) => {

@@ -179,4 +198,4 @@ recursiveReadDir(dir, dir, 0, config);

export type ParamNames = string;`, () => { });
const actions = (_v = config === null || config === void 0 ? void 0 : config.abacPermissions) === null || _v === void 0 ? void 0 : _v.actions;
const models = (_w = config === null || config === void 0 ? void 0 : config.abacPermissions) === null || _w === void 0 ? void 0 : _w.models;
const actions = (_y = config === null || config === void 0 ? void 0 : config.abacPermissions) === null || _y === void 0 ? void 0 : _y.actions;
const models = (_z = config === null || config === void 0 ? void 0 : config.abacPermissions) === null || _z === void 0 ? void 0 : _z.models;
fs_1.default.writeFile(`${__dirname}/serviceUtils/permission.d.ts`, `export type ABACActions = ${(actions !== null && actions !== void 0 ? actions : ["readOne", "readAll", "read", "update", "create", "delete", "manage"])

@@ -343,7 +362,7 @@ .map((x) => `"${x}"`)

//@ts-ignore
route[parsedMethod](multipleMulter ? upload.array("files") : upload.single("file"), validations, overrideErrorMiddleWare, overrideAuth, redisAndPermissionMiddleware({ cache, purgeKey, permission }), (0, wrapperResolver_1.default)(service[method].bind(service)));
route[parsedMethod](multipleMulter ? upload.array("files") : upload.single("file"), validations, overrideErrorMiddleWare, overrideAuth, redisAndPermissionMiddleware({ cache, purgeKey, permission }), jsonParserMiddleware, (0, wrapperResolver_1.default)(service[method].bind(service)));
}
else {
//@ts-ignore
route[parsedMethod](validations, overrideErrorMiddleWare, overrideAuth, redisAndPermissionMiddleware({ cache, purgeKey, permission }), (0, wrapperResolver_1.default)(service[method].bind(service)));
route[parsedMethod](validations, overrideErrorMiddleWare, overrideAuth, redisAndPermissionMiddleware({ cache, purgeKey, permission }), jsonParserMiddleware, (0, wrapperResolver_1.default)(service[method].bind(service)));
}

@@ -354,7 +373,7 @@ }

//@ts-ignore
route[parsedMethod](multipleMulter ? upload.array("files") : upload.single("file"), overrideAuth, redisAndPermissionMiddleware({ cache, purgeKey, permission }), (0, wrapperResolver_1.default)(service[method].bind(service)));
route[parsedMethod](multipleMulter ? upload.array("files") : upload.single("file"), overrideAuth, redisAndPermissionMiddleware({ cache, purgeKey, permission }), jsonParserMiddleware, (0, wrapperResolver_1.default)(service[method].bind(service)));
}
else {
//@ts-ignore
route[parsedMethod](overrideAuth, redisAndPermissionMiddleware({ cache, purgeKey, permission }), (0, wrapperResolver_1.default)(service[method].bind(service)));
route[parsedMethod](overrideAuth, redisAndPermissionMiddleware({ cache, purgeKey, permission }), jsonParserMiddleware, (0, wrapperResolver_1.default)(service[method].bind(service)));
}

@@ -629,3 +648,2 @@ }

if (k == "type") {
// console.log("~ ~ value[k]", value[k]);
if (value[k].substr(-1) === "!") {

@@ -683,3 +701,2 @@ requiredItems.push(pName);

if (k == "type") {
// console.log("~ ~ value[k]", value[k]);
if (value[k].substr(-1) === "!") {

@@ -686,0 +703,0 @@ requiredItems.push(pName);

{
"name": "efesto",
"version": "0.16.0",
"version": "0.16.1",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

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