Socket
Book a DemoInstallSign in
Socket

vtex-io

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vtex-io

VTEX IO platform client

npmnpm
Version
0.0.1-beta.15
Version published
Weekly downloads
5
Maintainers
1
Weekly downloads
 
Created
Source

Colossus SDK for Node JS

Usage

const {Service} = require('vtex-io')

// Create a service instance
service = new Service()

// Do your page, API and event bindings

// And start the service
service.start()

Registering an API

service.api({
  '/products': {
    get: (req, res, ctx) => {
      // get a list of products
      return Promise.resolve()
    },
    post: (req, res, ctx) => {
      // create a new product
      return Promise.resolve()
    },
    '/:id': {
      get: (req, res, ctx) => {
        // get a specific product
        return Promise.resolve()
      },
      put: (req, res, ctx) => {
        // update a product
        return Promise.resolve()
      }
    }
  },
  '/categories': (req, res, ctx) => {
    // a handler without a method defaults to GET
    // get all categories
    return Promise.resolve()
  }
})

Callback parameters

  • request (Object) - a Koa Request
  • response (Object) - a Koa Response
  • context (Object) - the context object, with the folowing fields:
    • account (String) - current account name
    • workspace (String) - current workspace
    • params (Object) - URL parameter values obtained from the route

Using Events

service.events({
  'apps:installed,uninstalled:render': (body, ctx) => {},
  'vbase:file-changed:render:*': (body, ctx) => {},
  'vtex.render:hotreload:product-page': (body, ctx) => {}
})

Each event subscription has a key and a callback.

Subscription key

Each key has at least two segments, separated by a colon (:). The two first are always:

  • Sender, which is the app or platform service name (apps, vbase, vtex.render, vtex.payments etc.)
  • Event name, as defined by the sender

The remaining segments are arbitrary and defined by the sender.

Each segment of a subscription key may use one of two special characters:

  • * is a wildcard, which represents "anything". It will match any value for that segment. Example: apps:installed:* will match any value for the last segment.
  • , is a shorthand to describe many key variations in one. Example: apps:installed,uninstalled:render will match both apps:installed:render and apps:uninstalled:render.

Event callback

Parameters:

  • body (String) - the event body.
  • context (Object) - the context, with the following fields:
    • account (String) - current account name
    • workspace (String) - current workspace
    • sender (String) - platform service name (apps, vbase etc.) or app ID (vtex.render@1.2.3) of the sender
    • key (String) - the actual event key (for instance, foo:bar:lala is a valid key for subscriptions foo:bar:lala, foo:*:lala or foo:bar,zaz:lala)

FAQs

Package last updated on 08 Dec 2016

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