@hafdon/sierra-api
Wrapper around Innovative (III) Sierra API
Last updated a year ago by hafdon .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @hafdon/sierra-api 
SYNC missed versions from official npm registry.

sierraApi

Wrapper around Innovative (III) Sierra API

installation

npm i @hafdon/sierra-api

configuration file

/// sierra-api.config.local.js
module.exports = {
    access: 'write' | 'read',
    key: '<key provided by iii>',
    secret: '<your secret>',
    urlBase: '/iii/sierra-api',
    version: 'v5',
    port: 443,
    host: '<your local host>',
};

methods

api._ ({
    path: // uri
    method: // 'GET' | 'POST' | 'PATCH' | 'DELETE'
    body: //
    qs: //
})

use with express.app()

require('dotenv').config()
const express = require('express')
const config =  require('./sierra-api.config.local')

// import (async) sierraApi module
const SierraApi = require('@hafdon/sierra-api')

// create class instance of the sierraApi module
const sierraApi = new SierraApi(config);

const app = express()
const port = process.env.PORT | <default port>

app.all('/*', (async (req, res, next) => {

    try {
        const { body, statusCode } = await sierraApi._({
            "path": req.path,
            "method": req.method,
            "body": req.body,
            "qs": req.query
        })

        // if body.entries doesn't exist, it means the body has our data object (because we're not getting back a list of things)
        const data = (body ? (body.entries ? body.entries : body) : {})
        res.status(statusCode).send(data)
    } catch (e) {
        console.log(e)
        // error-handling logic here
        res.status(404).send({"message": "Error"})
    }
}))

app.listen(port, () => console.log(`Example app listening on port ${port}!`));

debug statements

  • appear on sierra-api

testing

  • no testing yet

Current Tags

  • 1.0.2                                ...           latest (a year ago)

3 Versions

  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 3
This Month 3
Last Day 0
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (4)

Copyright 2014 - 2016 © taobao.org |