
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
Installation
mkdir mywebproject cd mywebproject npm init npm i typescript ./node_modules/.bin/tsc --init npm i texdec express @types/express @types/nodego to tsconfig.json and set
experimentalDecoratorsandemitDecoratorMetadatatotruetargettoes2019
Set up entry file
on entry file (e.x
server.ts) the usual express stuffexport const app: Express = express() app.use(express.urlencoded()) app.use(express.json())next thing is to get the TExDecSettings class
import {TExDecSettings} from 'texdec' const texDecSettings = TExDecSettings.getInstance()the only option we have to set for TExDec to work is the
controllerDirtexDecSettings.set('controllerDir', path.join(__dirname, 'controllers'))TExDec will search in the given path for files with name matching
*.controllerand load themand then we execute
TExDec.init(app)in order to find all the controller files and load the routes.import {TExDec} from 'texdec' import {Server} from 'http' TExDec.init(app).then(() => { const http = new Server(app) http.listen(3000, () => { console.info(`server started at http://localhost:${3000}`) }) })
TExDec.initreturns a promise which is resolved when all the routes from the controller files have been loaded. When the routes are loaded we can instantiate the http server.
Our first controller
create the directory structure
controllers/catsExample controller:
inside
controllers/catscreate the filescats.controller.tscats.controller.ts
import {Controller, Get, Param, Post, Query, Body} from 'texdec' import {CatsConfig} from './cats.config' @Controller('cats', CatsConfig) class CatsController { public cats: string[] @Get('/') getMany( @Query() search: string, ) { if (search) return this.cats.filter(cat => (cat.indexOf(search) > -1)) else return cats } @Get('/:id') getOne( @Param('id') index: number, ) { return this.cats[index] } @Post('/') insertOne( @Body() name: string, ) { this.cats.push(name) return this.cats } }Class decorator
@Controller(baseRoute: string, controllerConfig?: IControllerConfig)Params
baseRoutethe main route of the controllercontrollerConfigthe configuration class of the controllerMethod Decorators:
@Get(route: string, validationObj?: IValidationObj)@Post(route: string, validationObj?: IValidationObj)@Put(route: string, validationObj?: IValidationObj)@Delete(route: string, validationObj?: IValidationObj)@Patch(route: string, validationObj?: IValidationObj)Params
routethe route of the methodvalidationObjthe validation object of the incoming parametersMethod Parameter Decorators
Match Query parameters
@Query(parameterName?: string | null | undefined, castToType?: boolean)Match url parameters
@Param(parameterName?: string | null | undefined, castToType?: boolean)Match body parameters (only if incomming body is json format)
@Body(parameterName?: string | null | undefined, castToType?: boolean)The Response Object
@Res()The Request Object
@Req()Params
parameterName(Optional) the name of the incoming key - if not set the name of the variable will be used.castToType(Optional) defaults totrue. If set tofalsethe incoming variable will be cast to the type that is declared
Our Controller config
inside
controllers/catscreate the filecats.config.tsimport {ControllerConfig} from 'texdec' export class CatsConfig extends ControllerConfig { constructor() { super(); this.middleware([]).include('getMany') this.middleware([]).exclude('getOne') this.baseRoute() } }class methods
middlewareaccepts and array of function (expressjs middlewares) that will be used in all the controllers methods. you can excude specific methods from using the middleware with the chain methodexcudeor use the middleware in a specific set of methods with the chain methodinclude. Bothincludeandexcludeaccept either a string or an array of strings.
baseRouteif you want to overide the base route that you set ontexdecSettings
TExDec Options
via the
texDecSettingswe can configure some options.available options are:
castHelper webLogger routerLogger routeParamHelper baseRoute controllerDir
castHelper(Default:Class: CastHelper) is the class that contains the methods that casts the variables in the controllers. You can extend the default CastHelper class and write your own cast functions
webLogger(Default:console) the web logger
routerLogger(Default:console) the router logger
routeParamHelperYou can create custom controller method params with this option...
baseRoutebase route is the route all the controllers will be under
FAQs
A typescript web framework that I actually like to use
We found that texdec demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.