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

iate-components

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iate-components

IATE common components

latest
Source
npmnpm
Version
0.5.2
Version published
Maintainers
1
Created
Source

Components

IATE common components

How to use it

errors

Example using express req and res objects:

    const { toHttp, VALIDATION_ERROR } = require('iate-components').errors
    const interactor = require('./interactor')

    const translator = {
        create: async (req, res) => {
            try {
                if (!req.params.id) throw new VALIDATION_ERROR('Missing param', 'ID is required')
                res.json(await interactor.create(req.body))
            } catch (error) {
                // translates application errors to HTTP semantics
                toHttp(error, res)
            }
        }
    }

validator

Example using express req and res objects:

    const { toHttp } = require('iate-components').errors
    const { validator } = require('iate-components')

    const interactor = require('./interactor')

    const translator = {
        create: async (req, res) => {
            // ajv schema
            const schema = {
                additionalProperties: false,
                type: 'object',
                properties: {
                    file_name: { type: 'string' },
                    description: { type: 'string' },
                    content: { type: 'string' },
                    visibility: { enum: [ 'public', 'private' ]},
                },
                required: [ 'file_name', 'description', 'content', 'visibility' ]
            }
            try {
                // validates schema against req.body, throws a VALIDATION_ERROR if fails
                validator(schema, req.body)
                res.json(await interactor.create(req.body))
            } catch (error) {
                // translates application errors to HTTP semantics
                toHttp(error, res)
            }
        }

    }

Keywords

iate

FAQs

Package last updated on 05 Mar 2020

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