
Research
NPM targeted by malware campaign mimicking familiar library names
Socket uncovered npm malware campaign mimicking popular Node.js libraries and packages from other ecosystems; packages steal data and execute remote code.
@kodasoftware/api
Advanced tools
A library for create Node, Koa-based applications. It facilitates both HTTP server and serverless exports of your APIs.
In order to use this library you should first create your application using the factory function. (This example uses the config library):
index.ts
import { application } from './app';
import configuration from 'config';
// Start the server
const config = configuration.util.toObject();
try {
application.start({ port: config.app.port });
} catch (err) {
application.end();
}
// Or you can export as a serverless handler instead with one of the below examples - simple!
// AWS - Lambda
// export const handler = application.serverless({ provider: 'aws' });
// Azure - Function
// export const nameOfFunction = application.serverless({ provider: 'azure' });
// Google Cloud - Cloud Function
// application.serverless({ provider: 'gcloud' });
app.ts
import { createApplication, generateSwaggerSpec } from '@nokkel/api';
import configuration from 'config';
import { AccountService, CoffeeService } from './lib/services';
import { accountRouteFactory, coffeeRouteFactory } from './routes';
const config = configuration.util.toObject();
export const application = createApplication({
config: {
name: config.app.name,
logLevel: config.log.level,
// This attaches services to the request context, accessible in a middleware via `ctx.services`
services: {
account: new AccountService(),
coffee: new CoffeeService(),
},
},
cors: { origin: config.cors.origin },
// Specify koa options constructor
koa: {},
// Specify options for koa-body
body: {},
swagger: {
spec: generateSwaggerSpec({
definition: {
info: {
title: config.app.name,
version: config.app.version,
},
},
}),
},
});
application.use(accountRouteFactory().attach());
application.use(coffeeRouteFactory().attach());
lib/services.ts
export class AccountService {
public async retrieveAccounts() {
return fetch('https://api.sampleapis.com/fakebank/accounts').then(res =>
res.json()
);
}
}
export class CoffeeService {
public async retrieveCoffee(type: 'hot' | 'iced') {
return await fetch(
new URL(`https://api.sampleapis.com/coffee/${type}`)
).then(res => res.json());
}
}
middlewares.ts
import type { AccountService, CoffeeService } from '../lib';
interface Account {
transactionDate: string;
description: string;
category: string;
debit: number | null;
credit: number | null;
id: number;
}
export function accountMiddlewareFactory(): Middleware<
Account[],
{ account: AccountService }
> {
return async function accountMiddleware(ctx) {
ctx.body = await ctx.services.account.retrieveAccounts();
ctx.status = 200;
};
}
interface Coffee {
title: string;
description: string;
ingredients: string[];
image: string;
id: number;
}
export function coffeeMiddlewareFactory(): Middleware<
Coffee,
{ coffee: CoffeeService }
> {
return async function exampleMiddleware(ctx) {
const type = ctx.params.type as 'hot' | 'iced';
ctx.body = await ctx.services.coffee.retrieveCoffee(type);
ctx.status = 200;
};
}
routes.ts
import { Router, schemaMiddlewareFactory } from '@nokkel/api';
import {
accountMiddlewareFactory,
coffeeMiddlewareFactory,
} from '../middlewares';
/**
* @openapi
* /accounts:
* get:
* tags:
* - Account
* description: Retrieve bank accounts
* responses:
* 200:
* description: Return 200 response
* content:
* application/json:
* schema:
* type: array
*/
export function accountRouteFactory() {
const router = new Router();
router.get('accounts', '/accounts', accountMiddlewareFactory());
return router;
}
/**
* @openapi
* /coffee/{type}:
* post:
* tags:
* - Coffee
* description: Retrieve types of coffee
* parameters:
* - name: type
* in: path
* description: The type of coffee you want to retrieve
* required: true
* schema:
* type: string
* enum:
* - hot
* - iced
* responses:
* 200:
* description: Return 200 response
* content:
* application/json:
* schema:
* type: array
*/
export function coffeeRouteFactory() {
const router = new Router();
router.post(
'coffee',
'/coffee/:type',
schemaMiddlewareFactory({
schema: {
path: {
type: 'object',
properties: {
type: {
type: 'string',
enum: ['hot', 'iced'],
},
},
required: ['type'],
},
},
expose: true,
}),
coffeeMiddlewareFactory()
);
return router;
}
Enjoy!
FAQs
A library for create Node, Koa-based applications.
The npm package @kodasoftware/api receives a total of 3 weekly downloads. As such, @kodasoftware/api popularity was classified as not popular.
We found that @kodasoftware/api demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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
Socket uncovered npm malware campaign mimicking popular Node.js libraries and packages from other ecosystems; packages steal data and execute remote code.
Research
Socket's research uncovers three dangerous Go modules that contain obfuscated disk-wiping malware, threatening complete data loss.
Research
Socket uncovers malicious packages on PyPI using Gmail's SMTP protocol for command and control (C2) to exfiltrate data and execute commands.