New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

wrong-type-report-generator

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wrong-type-report-generator

Automatically generate runtime wrong type report from typescript type definition

latest
npmnpm
Version
0.0.15
Version published
Weekly downloads
5
400%
Maintainers
1
Weekly downloads
 
Created
Source

Motivation

When your DTO is different from your backend's specification and have no way to detect it, it is hard to debug the error!
Below is an example of WTF moment.

// Your DTO
interface meDto {
    ...
    user: {
        id: number;
    }
    ...
}

// From your backend
{
    ...
    user: "{id: 123}" // WTF?! it is too hard to find!
    ...
}

So, when Backend's API response is different from our DTO, report it!

Installation

npm i wrong-type-report-generator

Usage

1. Generate wrong-type-report

import { generateWrongTypeReport } from 'wrong-type-report-generator';

const files = getFiles();

await generateWrongTypeReport({
    filePaths: files,
    outDirPath: './generated',
});

2. Use generated reporter with Axios then send wrong type report

import { generateReporter } from 'wrong-type-report-generator';
import { validateDto } from './generated';

const report = generateReporter((errorReport) => {
    sendForDebug(errorReport);
});

export const xxxApi = async () => {
    return axios.get('www.xxx.xxx').then(report(validateDto)); // use generated reporter here!
};

TODO

  • transform a.b.c -> a['b']['c'] (to support things like this -> asdf['asdf.asdf'])
  • Refactor spaghetti code
  • code generator tests
  • duplicated property error optimization
  • performance optimization

Keywords

runtime

FAQs

Package last updated on 12 Jun 2023

Did you know?

Socket

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.

Install

Related posts