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

restapify

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

restapify - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

dist/CONST.d.ts

2

dist/internalApi/index.d.ts
/// <reference types="express-serve-static-core" />
import * as express from 'express';
import { Routes, PrivateRouteState, RouteState } from '../server';
import { Routes, PrivateRouteState, RouteState } from '../Restapify';
export interface InternalApiParams {

@@ -5,0 +5,0 @@ setState: (newState: RouteState) => void;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getInitialisedInternalApi = void 0;
const CONST_1 = require("../server/CONST");
const CONST_2 = require("../server/CONST");
const CONST_1 = require("../CONST");
const CONST_2 = require("../CONST");
const utils_1 = require("../utils");
const getRoute = (route) => {

@@ -11,2 +12,15 @@ return CONST_1.INTERNAL_API_BASEURL + route;

const { states, routes, setState, onClose } = params;
const getSortedRoutes = () => {
const finalRoutes = {};
const sortedRoutes = utils_1.getRoutesByFileOrder(routes);
sortedRoutes.forEach(sortedRoute => {
const { route, method } = sortedRoute;
if (finalRoutes[route] === undefined) {
finalRoutes[route] = {};
}
finalRoutes[route][method] = routes[method][route];
});
return finalRoutes;
};
const sortedRoutes = getSortedRoutes();
app.get(getRoute('/close'), (req, res) => {

@@ -18,3 +32,3 @@ res.status(204);

app.get(getRoute('/routes'), (req, res) => {
res.json(routes);
res.json(sortedRoutes);
});

@@ -21,0 +35,0 @@ app.get(getRoute('/states'), (req, res) => {

export * from './internalApi';
export * from './server';
export * from './restapify';

@@ -14,2 +14,2 @@ "use strict";

__exportStar(require("./internalApi"), exports);
__exportStar(require("./server"), exports);
__exportStar(require("./restapify"), exports);

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

import { Route as RouteData } from '../server/getRoute';
import { Route as RouteData } from '../getRoute';
import { HttpVerb } from '.';

@@ -3,0 +3,0 @@ export declare type Route = Pick<RouteData, 'fileContent' | 'body' | 'route' | 'method' | 'filename' | 'header' | 'routeVars' | 'stateVars' | 'statusCode'>;

@@ -0,1 +1,23 @@

import { HttpVerb } from './types';
import { Routes } from './Restapify';
export declare const getDirs: (p: string) => string[];
export declare const getFiles: (p: string) => string[];
export declare const replaceAll: (str: string, find: string, replace: string) => string;
export declare const getVarsInPath: (pathParam: string) => string[];
export declare const isHttpVerb: (str: string) => boolean;
export declare const isStateVariable: (str: string) => boolean;
export declare const isNumeric: (str: string) => boolean;
export declare const routeResolve: (...routes: string[]) => string;
export declare const withoutUndefinedFromObject: (obj: Object) => Object;
interface OrderedRoutes {
route: string;
method: HttpVerb;
}
export declare const getRoutesByFileOrder: (routes: Routes) => OrderedRoutes[];
export declare const getRouteFiles: (rootDir: string, files?: {
[filename: string]: string;
}) => {
[filename: string]: string;
};
export declare const isJsonString: (str: string) => boolean;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.replaceAll = void 0;
exports.isJsonString = exports.getRouteFiles = exports.getRoutesByFileOrder = exports.withoutUndefinedFromObject = exports.routeResolve = exports.isNumeric = exports.isStateVariable = exports.isHttpVerb = exports.getVarsInPath = exports.replaceAll = exports.getFiles = exports.getDirs = void 0;
const fs = require("fs");
const path = require("path");
const CONST_1 = require("./CONST");
const getDirs = (p) => {
return fs.readdirSync(p).filter(f => fs.statSync(path.join(p, f)).isDirectory());
};
exports.getDirs = getDirs;
const getFiles = (p) => {
return fs.readdirSync(p).filter(f => fs.statSync(path.join(p, f)).isFile());
};
exports.getFiles = getFiles;
const replaceAll = (str, find, replace) => {

@@ -8,1 +19,95 @@ return str.split(find).join(replace);

exports.replaceAll = replaceAll;
const getVarsInPath = (pathParam) => {
const vars = [];
if (pathParam.endsWith('.json')) {
pathParam = pathParam.slice(0, -'.json'.length);
}
const explodedPath = pathParam.split('/');
explodedPath.forEach(pathElement => {
const isVar = pathElement.startsWith('[') && pathElement.endsWith(']');
if (isVar) {
vars.push(pathElement.slice(1, -1));
}
});
return vars;
};
exports.getVarsInPath = getVarsInPath;
const isHttpVerb = (str) => {
// @ts-ignore
return CONST_1.HTTP_VERBS.includes(str);
};
exports.isHttpVerb = isHttpVerb;
const isStateVariable = (str) => {
return str.startsWith('{') && str.endsWith('}');
};
exports.isStateVariable = isStateVariable;
const isNumeric = (str) => {
return !Number.isNaN(str) // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)...
&& !Number.isNaN(parseFloat(str)); // ...and ensure strings of whitespace fail
};
exports.isNumeric = isNumeric;
const routeResolve = (...routes) => {
let finalRoute = '';
routes.forEach((route, routeId) => {
const hasPreviousRouteFinalSlash = !!routes[routeId - 1]?.endsWith('/');
const hasRouteFirstSlash = route.startsWith('/');
if (hasPreviousRouteFinalSlash && hasRouteFirstSlash) {
finalRoute += route.slice(1);
}
else if (!hasPreviousRouteFinalSlash && !hasRouteFirstSlash) {
finalRoute += '/' + route;
}
else {
finalRoute += route;
}
});
return finalRoute;
};
exports.routeResolve = routeResolve;
const withoutUndefinedFromObject = (obj) => {
// @ts-ignore
Object.keys(obj).forEach(key => obj[key] === undefined && delete obj[key]);
return obj;
};
exports.withoutUndefinedFromObject = withoutUndefinedFromObject;
const getRoutesByFileOrder = (routes) => {
const orderedRoutes = [];
let routesLink = [];
CONST_1.HTTP_VERBS.forEach(method => {
routesLink = [...routesLink, ...Object.keys(routes[method])];
});
// remove duplicates and sort
routesLink = [...new Set(routesLink)].sort();
routesLink.forEach(routeLink => {
CONST_1.HTTP_VERBS.forEach(method => {
if (routes[method][routeLink]) {
orderedRoutes.push({ method, route: routeLink });
}
});
});
return orderedRoutes;
};
exports.getRoutesByFileOrder = getRoutesByFileOrder;
const getRouteFiles = (rootDir, files = {}) => {
const dirNames = exports.getDirs(rootDir);
const fileNames = exports.getFiles(rootDir);
fileNames.forEach(filename => {
const filePath = path.resolve(rootDir, filename);
files[filePath] = fs.readFileSync(filePath, 'utf8');
});
dirNames.forEach(dir => {
return exports.getRouteFiles(path.resolve(rootDir, dir), files);
});
return files;
};
exports.getRouteFiles = getRouteFiles;
const isJsonString = (str) => {
try {
JSON.parse(str);
}
catch (e) {
return false;
}
return true;
};
exports.isJsonString = isJsonString;
{
"name": "restapify",
"version": "0.0.7",
"main": "dist/server/index.js",
"version": "0.0.8",
"main": "dist/src/Restapify.js",
"files": [
"dist",
"node_modules/restapify-dashboard"
"dist"
],

@@ -12,12 +11,9 @@ "license": "MIT",

"scripts": {
"test": "jest --silent",
"test": "jest --silent --no-cache",
"test:manual": "yarn ts-node-dev --files test/run.ts",
"start": "yarn nodemon --watch test src/index.js",
"build": "yarn tsc",
"postbuild": "yarn cpy ./node_modules/restapify-dashboard/public ./dist --parents",
"lint": "yarn eslint . --ext .js,.ts"
},
"bin": {
"@johannchopin/restapify": "bin/restapify",
"restapify": "bin/restapify"
},
"publishConfig": {

@@ -27,3 +23,3 @@ "access": "public"

"dependencies": {
"arg": "^5.0.0",
"chokidar": "^3.4.3",
"eslint-config-airbnb-base": "^14.2.1",

@@ -34,3 +30,4 @@ "esm": "^3.2.25",

"nodemon": "^2.0.5",
"restapify-dashboard": "^1.0.4"
"open": "^7.3.0",
"restapify-dashboard": "^1.0.9"
},

@@ -45,2 +42,3 @@ "devDependencies": {

"@typescript-eslint/parser": "^4.7.0",
"cpy-cli": "^3.1.1",
"eslint": "^7.13.0",

@@ -47,0 +45,0 @@ "isomorphic-fetch": "^3.0.0",

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