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

kwyjibo

Package Overview
Dependencies
Maintainers
2
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kwyjibo - npm Package Compare versions

Comparing version 1.0.24 to 1.0.27

20

js/controller.d.ts

@@ -0,1 +1,2 @@

/// <reference types="node" />
/*********************************************************************************

@@ -27,2 +28,3 @@

import * as Express from "express";
import * as Stream from "stream";
export interface IDisposable {

@@ -48,16 +50,24 @@ dispose(): void;

message: string;
constructor(code: number, message: string);
constructor(code: number, messageOrError: string | Error);
}
export declare class BadRequest extends HttpError {
constructor(message: string);
constructor(messageOrError: string | Error);
}
export declare class Unauthorized extends HttpError {
constructor(message: string);
constructor(messageOrError: string | Error);
}
export declare class NotFound extends HttpError {
constructor(message: string);
constructor(messageOrError: string | Error);
}
export declare class InternalServerError extends HttpError {
constructor(message: string);
constructor(messageOrError: string | Error);
}
export declare class FileServe {
file: string | Stream.Readable;
filename: string;
contentType: string;
forceAttachment: boolean;
constructor(file: string | Stream.Readable, filename?: string, extension?: string, forceAttachment?: boolean);
sendHeaders(res: Express.Response): void;
}
export declare let globalKCState: KwyjiboControllersState;

@@ -64,0 +74,0 @@ /*********************************************************

@@ -39,2 +39,4 @@ /*********************************************************************************

const FS = require("fs");
const Path = require("path");
const Stream = require("stream");
/**

@@ -60,5 +62,15 @@ * Contains context for the current call .

class HttpError {
constructor(code, message) {
constructor(code, messageOrError) {
this.code = code;
this.message = message;
if (messageOrError != undefined) {
if (messageOrError instanceof Error) {
this.message = messageOrError.message;
}
else {
this.message = messageOrError.toString();
}
}
else {
this.message = "";
}
}

@@ -68,4 +80,4 @@ }

class BadRequest extends HttpError {
constructor(message) {
super(400, message);
constructor(messageOrError) {
super(400, messageOrError);
}

@@ -75,4 +87,4 @@ }

class Unauthorized extends HttpError {
constructor(message) {
super(401, message);
constructor(messageOrError) {
super(401, messageOrError);
}

@@ -82,4 +94,4 @@ }

class NotFound extends HttpError {
constructor(message) {
super(404, message);
constructor(messageOrError) {
super(404, messageOrError);
}

@@ -89,7 +101,22 @@ }

class InternalServerError extends HttpError {
constructor(message) {
super(500, message);
constructor(messageOrError) {
super(500, messageOrError);
}
}
exports.InternalServerError = InternalServerError;
class FileServe {
constructor(file, filename, extension, forceAttachment) {
this.file = file;
this.filename = filename != undefined ? filename : (typeof (file) === "string" ? (Path.basename(file)) : "file");
extension = extension != undefined ? extension : this.filename;
this.contentType = require("mime-types").contentType(extension);
this.forceAttachment = !!forceAttachment;
}
sendHeaders(res) {
res.setHeader("Accept-Ranges", "bytes");
res.setHeader("Content-Type", this.contentType);
res.setHeader("Content-Disposition", `${this.forceAttachment ? "attachment" : "inline"}; filename=${this.filename}`);
}
}
exports.FileServe = FileServe;
/*********************************************************

@@ -408,2 +435,25 @@ * Class Decorators

}
function serveFile(res, file) {
return __awaiter(this, void 0, void 0, function* () {
if (typeof (file.file) === "string") {
yield new Promise((resolve, reject) => {
FS.access(file.file, FS["R_OK"], (err) => {
if (err != undefined) {
throw new NotFound(err);
}
let filestream = FS.createReadStream(file.file);
file.sendHeaders(res);
filestream.pipe(res);
});
});
}
else if (file.file instanceof Stream.Readable) {
file.sendHeaders(res);
file.file.pipe(res);
}
else {
throw new Error("Invalid file type on FileServe");
}
});
}
function mountMethod(controller, instance, methodKey) {

@@ -466,3 +516,6 @@ let method = controller.methods[methodKey];

}
if (ret instanceof Object) {
if (ret instanceof FileServe) {
serveFile(res, ret);
}
else if (ret instanceof Object) {
if (ret["$render_view"] != undefined) {

@@ -593,7 +646,7 @@ res.render(ret["$render_view"], ret);

let path = "";
if (requiredDirectory.charAt(0) == "/") {
if (Path.isAbsolute(requiredDirectory)) {
path = requiredDirectory;
}
else {
path = U.UrlJoin(process.cwd(), "/", requiredDirectory);
path = Path.join(process.cwd(), requiredDirectory);
}

@@ -600,0 +653,0 @@ try {

{
"name": "kwyjibo",
"version": "1.0.24",
"version": "1.0.27",
"description": "A set of Typescript Decorators and helpers to write better node.js+Express applications.",

@@ -39,4 +39,5 @@ "main": "js/index.js",

"express": "^4.14.0",
"mime-types": "^2.1.12",
"require-all": "^2.0.0"
}
}

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