
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
@axmit/scythe-core
Advanced tools
This micro-framework created to help implement NodeJS backend applications with TypeScript without pain. The main idea is to provide several abstractions and tools to increase development speed and use popular used technologies as built-in features powered by TypeScript and also add ability for extension without losing flexibility. We use ExpressJS as core technology.
npm i @scythe/core
or yarn add @scythe/core
To create application you can use ScytheApplicationBuilder
(see below for more information).
import { ScytheApplicationBuilder } from '@scythe/core';
export const testApp = new ScytheApplicationBuilder().build();
This module will export instance of ScytheApplication
(see below for more information) all you need to do is to call start
method.
Let's make it more complex and create endpoint to get sample string. Logic part that contain routing, docs and middleware definitions called controller. Controller is abstract class with TypeScript decorators for storing metadata upon which routing, OpenAPI documentation, middlewares logic etc are generated.
import { controller, get, summary, description, response } from '@scythe/core';
@controller('/test', 'Test')
export abstract class TestController {
@get()
@summary('Test')
@description('Test description')
@response(200, 'string')
public testGet() {
return 'sample string';
}
}
And update main application file to
import { ScytheApplicationBuilder } from '@scythe/core';
import { TestController } from './TestController';
export const testApp = new ScytheApplicationBuilder().addController(TestController).build();
This will create express server on 3030 port with 2 endpoints:
To add more endpoints just define more methods with decorators (to see all available decorators keep reading).
All .env variables will be available throught proces.env[VARIABLE_NAME]
.
This particular module use only one variable is:
PORT = 3030 //defines your server port
This tool helps you to build Scythe Application (you can also use ScytheApplication
class itself). Base example was provided in usage section.
ScytheApplicationBuilder
methods:Sets config for the application. Available fields:
withoutServer?: boolean
- if sets to true, application will be started without express servervalidateRequests?: boolean
- sets validation for requests according to open API schema (see more in OpenAPI validation section)validateResponse?: boolean
- sets validation for responses according to open API schema (see more in OpenAPI validation section)hydrateOpenAPIModels?: boolean
- enables hydration by OpenAPI docksopenAPIInfo?: InfoObject
- info object for OpenAPI docsopenAPIDocksEndpoint?: string
- endpoint to open api docs UI generated from metadataDefault config is:
validateResponse: true
validateRequests: true
Sets path to application log file. Default path is ./logs/application.log
Adds router created by ScytheRouterBuilder
, which will be mounted on url
passed in params
Adds custom module to your application (more about modules see in https://www.npmjs.com/package/@scythe/types
Adds additional middleware into middlewares poll. Accept ordinary express middleware as param
Schedule a job to be executed by timetable. Params:
Adds controller to current application to be mounted on basePath.
Controller is abstract class decorated with @controller decorator (see more in decorators section)
Builds ScytheApplication
based on provided info
Base application class which contains almost all necessary logic.
ScytheApplication
methodsInits application with provided params:
withoutServer?: boolean
- if sets to true, application will be started without express servervalidateRequests?: boolean
- sets validation for requests according to open API schema (see more in OpenAPI validation section)validateResponse?: boolean
- sets validation for responses according to open API schema (see more in OpenAPI validation section)hydrateOpenAPIModels?: boolean
- enables hydration by OpenAPI docksopenAPIInfo?: InfoObject
- info object for OpenAPI docsopenAPIDocksEndpoint?: string
- endpoint to open api docs UI generated from metadataPath to application log file
Array of express middlewares to be applied
Adds router created by ScytheRouterBuilder
, which will be mounted on url
passed in params
Adds custom module to your application (more about modules see in https://www.npmjs.com/package/@scythe/types
Starts an application running all modules and creating express servers if needs to
Schedule a job to be executed by timetable. Params:
Adds controller to current application to be mounted on basePath.
Controller is abstract class decorated with @controller
or @webSocketController
decorator (see more in decorators section)
Stops application destroying connections and stopping jobs and modules
Return generated open API docs
This framework provides amount of decorators to create controller to simplify working with routing/docs/validation ets.
@controller(path: string, tag?: string): ClassDecorator
Sets decorated class as controller. All methods inside will be mounted on path from params. If tag param is passed, all endpoints will have this open API tag by default
@baseSecurity(securitySchema: string): ClassDecorator
Sets base security schema for controller. Accept name of open API defined security schema
@commonMiddlewares(...middlewares: RequestHandler[]): ClassDecorator
Sets common middlewares to be executed before each method logic in controller
@method(method: string, path: string = '/'): MethodDecorator
Binds http method to class method. If class method decorated with it, it will be treated as endpoint by passed path
@get(path: string = '/'): MethodDecorator
Alias for get method
@put(path: string = '/'): MethodDecorator
Alias for put method
@del(path: string = '/'): MethodDecorator
Alias for delete method
@post(path: string = '/'): MethodDecorator
Alias for post method
@patch(path: string = '/'): MethodDecorator
Alias for patch method
@middlewares(...middlewares: RequestHandler[]): MethodDecorator
Sets middlewares to be executed before method logic in controller
@tag(tag: string): MethodDecorator
Sets open API tag
@summary(summary: string): MethodDecorator
Sets Open API summary
@description(description: string): MethodDecorator
Sets Open API description
@response(responseCode: number, type: string | INewable, isArray: boolean = false): MethodDecorator
Sets Open API response by path as Open API schema reference with selected response status code
@defaultResponses(...responses: EDefaultResponse[]): MethodDecorator
Sets predefined responses. Can be:
@parameters(...parameters: ParameterObject[]): MethodDecorator
Sets Open API parameters
@headerParameter(name: string, schema: string, required: boolean = true): MethodDecorator
Sets Open API header parameter by its schema reference name
@security(name: string): MethodDecorator
Sets Open API security schema by its name
@deprecated(): MethodDecorator
Mark endpoint as deprecated
Builder for express routing implementation, it provides extended version of express router by adding methods to write open API docs.
Should be used only if controllers do not cover your case.
Usage:
import { ScytheRouterBuilder } from '@scythe/core';
const builder = new ScytheRouterBuilder();
builder
.useNamespace('/yourPath')
.useOpenAPIDocs({
get: {
tags: ['Your Tags'],
summary: 'Summary',
description: 'Descrition',
consumes: ['application/json'],
produces: ['application/json'],
parameters: [{ name: 'filter', description: 'filter', required: false, type: 'string', in: 'query' }],
responses: {
'200': {
description: 'description',
type: 'array',
items: {
$ref: '#/definitions/swagerSchemaName'
}
}
}
}
})
.buildNamespace()
.get(yourMiddlewaresGoesHere);
export const awesomeRouter = builder.buildRouter();
Define route namespace (ex. /users
, /users/:id
)
Sets OpenAPI docs for your namespace
Sets OpenAPI definitions for your router
Builds namespace and return express router route instance, where you can add any request methods
Builds router to be passed into ScytheApplication
or ScytheApplicationBuilder
This framework provides full set of types of Open API v3, so it'll be easy for you to implement all definitions.
This builder helps you create Open API definition to pass into controller or router builder
Sets Open API schemas according to Open API v3
Sets Open API responses according to Open API v3
Sets Open API parameters according to Open API v3
Sets Open API examples according to Open API v3
Sets Open API request bodies according to Open API v3
Sets Open API headers according to Open API v3
Sets Open API security schemas according to Open API v3
Sets Open API links according to Open API v3
Sets Open API callbacks according to Open API v3
Builds all components to be passed into @registerComponents decorator or into router builder
This part provides amount of function helpers to ease Open API components writing
Generates Open API query param component
{
name: 'test', in: 'query', schema: { $ref: '#/components/schemas/test' }, required: true}
Creates Open API json content based on schema.
{
content: { 'application/json': { schema: { $ref: '#/components/schemas/test' } } }}
Same as createRefContent
only take Open API schema object
Generates Open API ref object by passed type. Available types:
{
$ref: '#/componens/headers/TestHeader'}
Return object representation of Open API validation error object (same object returns by Open API Validator)
{
error: { message: 'Validation error', details: [{ dataPath: '.body.test', message: 'should be string' }] }}
If pass
validateResponse: true
validateRequests: true
into your application, all your responses/requests will be validated according to your Open API definitions.
FAQs
Core module for scythe framework
We found that @axmit/scythe-core demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.