npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

katana.sdk

v2.1.0

Published

KATANA SDK for Node.js v6

Downloads

18

Readme

KATANA SDK for Node.js

version Build Status Coveralls Coverage Status license

Node.js v6 SDK to interface with the KATANA™ framework (https://kusanagi.io).

Requirements

  • KATANA Framework 1.2
  • Node.js 6.0+
  • python (a node-gyp requirement) (v2.7 recommended, v3.x.x is not supported)
  • libzmq 4.1.5+ (including headers, you probably need a libzmq-dev package)

Installation

Make sure the system dependencies are met.

Use the following command to install the SDK from the NPM repository and add it to your dependencies:

$ npm install katana.sdk --save

Alternatively, you might want to install through the yarn package manager:

$ yarn add katana.sdk

To run the tests, determine the code coverage, and pass the linter, run the following:

$ npm run test

Or, you can simply run the tests:

$ npm run test:unit

You can also run the tests and watch for changes, which can be useful when developing:

$ npm run test:dev

If you'd like to generate a code coverage report, run the following:

$ npm run coverage
$ open coverage/lcov-report/index.html

Also, to run the linter on the code base, run the following:

$ npm run lint

Finally, if you'd like to build the technical documentation for the code base, you can generate it with the following:

$ npm run docs

Troubleshooting

Make sure these are met before installing the katana.sdk npm package. Some of its dependencies need to be compiled through node-gyp, and these depend on the libzmq headers being present. That means you probably need to install zqm-devel or a similar package (read more). If the katana.sdk npm package was installed before the libzmq header files were present, you'll need to nuke your project's node_modules folder and reinstall katana.sdk.

rm -Rf node_modules
npm install

Getting Started

Include the KATANA™ SDK library and set up Service or Middleware instances, for example:

const Service = require('katana.sdk').Service;

const service = new Service();

Examples

The following is a simple Middleware implementation to handle CORS.

KATANA configurations can be defined as XML, YAML or JSON. For this example we're using JSON.

First, we'll create a new config file for the Middleware as the following:

{
  "@context": "urn:katana:middleware",
  "name": "cors",
  "version": "1.0.0",
  "request": true,
  "engine": {
    "runner": "urn:katana:runner:node",
    "path": "cors.js"
  }
}

Note that you can also use a remote debugger by adding the --debug-brk flag as the value of the interpreter-options property of the engine element of the configuration, for example:

{
  "@context": "urn:katana:middleware",
  "name": "cors",
  "version": "1.0.0",
  "request": true,
  "engine": {
    "runner": "urn:katana:runner:node",
    "path": "cors.js",
    "interpreter-options": "--debug-brk=8888"
  }
}

Now we'll need to create the logic for the Middleware in the cors.js file, as defined in the config file:

const Middleware = require('katana.sdk').Middleware;

const middleware = new Middleware();

middleware.request((request) => {
  const httpRequest = request.getHttpRequest();
  const httpMethod  = httpRequest.getMethod();
  const urlPath     = httpRequest.getUrlPath();
  if (httpMethod === 'OPTIONS') {
    const response     = request.newResponse(200, 'OK');
    const httpResponse = response.getHttpResponse();
    httpResponse.setHeader('Access-Control-Allow-Origin', '*');
    httpResponse.setHeader('Access-Control-Allow-Headers', 'cache-control');
    httpResponse.setHeader('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, DELETE, PUT');
    return response; // exit early
  }
  return request;
});

middleware.run();

This Middleware can now be included in any Gateway to enable CORS processing.

In the following example we'll create a Service which provides a simple CRUD interface for users:

{
  "@context": "urn:katana:service",
  "name": "users",
  "version": "1.0.0",
  "http-base-path": "/1.0.0/users",
  "info": {
    "title": "Users Service"
  },
  "engine": {
    "runner": "urn:katana:runner:node",
    "path": "users.js"
  },
  "action": [
    {
      "name": "list",
      "collection": true,
      "http-method": "get"
    },
    {
      "name": "create",
      "http-method": "post",
      "http-input": "form-data",
      "param": [
        {"name": "name", "required": true}
      ]
    },
    {
      "name": "read",
      "http-method": "get",
      "http-path": "/{id}",
      "param": [
        {"name": "id", "type": "integer", "required": true, "http-input": "path"}
      ]
    },
    {
      "name": "update",
      "http-method": "put",
      "http-path": "/{id}",
      "param": [
        {"name": "id", "type": "integer", "required": true, "http-input": "path"},
        {"name": "name", "required": true, "http-input": "form-data"}
      ]
    },
    {
      "name": "delete",
      "http-method": "delete",
      "http-path": "/{id}",
      "param": [
        {"name": "id", "type": "integer", "required": true, "http-input": "path"}
      ]
    }
  ]
}

And as before, we'll create the Service logic in a file named users.js, as we had defined in the config file:

const Service = require('katana.sdk').Service;

const service = new Service();

service.action('list', (action) => {
  // get all entities from the data store
  action.setCollection(collection);
  return action;
});

service.action('create', (action) => {
  const name = action.getParam('name').getValue();
  // create entity in data store with "name"
  action.setEntity(entity);
  return action;
});

service.action('read', (action) => {
  const id = action.getParam('id').getValue();
  // get entity from data store with "id"
  action.setEntity(entity);
  return action;
});

service.action('update', (action) => {
  const id = action.getParam('id').getValue();
  const name = action.getParam('name').getValue();
  // update "name" in data store for "id"
  return action;
});

service.action('delete', (action) => {
  const id = action.getParam('id').getValue();
  // delete from data store with "id"
  return action;
});

service.run();

Documentation

See the API for a technical reference of the SDK.

For help using the framework see the documentation.

Support

Please first read our contribution guidelines.

We use milestones to track upcoming releases inline with our versioning strategy, and as defined in our roadmap.

For commercial support see the solutions available or contact us for more information.

Contributing

If you'd like to know how you can help and support our Open Source efforts see the many ways to get involved.

Please also be sure to review our community guidelines.

License

Copyright 2016-2018 KUSANAGI S.L. (https://kusanagi.io). All rights reserved.

KUSANAGI, the sword logo, KATANA and the "K" logo are trademarks and/or registered trademarks of KUSANAGI S.L. All other trademarks are property of their respective owners.

Licensed under the MIT License. Redistributions of the source code included in this repository must retain the copyright notice found in each file.