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

kinvey-flex-sdk

v4.1.4

Published

SDK for creating Kinvey Flex Services

Downloads

5,957

Readme

Build Status

Kinvey Flex SDK

This is the SDK for code execution of Flex Microservices. The module provides a framework for building Kinvey-backend services using FlexData, FlexFunctions, and FlexAuth.

Upgrading from 2.x to 3.x

Flex-sdk 3.x contains several breaking changes as well as new features. To upgrade your service from Flex-sdk 2.x to 3.x:

  • All email and push methods now return a promise. It is now required that you either handle the promise, or pass a callback.
  • For all stores (e.g. dataStore, userStore, etc), the deprecated options skipBl and useMasterSecret have been removed and no longer function. Use useBl and useUserContext instead.
  • All asynchonous modules (dataStore, groupStore, roleStore, endpointRunner, userStore, email, and push) now return a promise or accept a callback.
  • For more information on what's new, see the Changelog.

Official documentation

Installation and usage

To install this project, add kinvey-flex-sdk to your package.json file and install it via npm

npm install kinvey-flex-sdk

To use this module, require it in your project as such:

const sdk = require('kinvey-flex-sdk');

Working Flex SDK service examples

This section contains standalone sample microservices for FlexData, FlexFunctions, and FlexAuth frameworks. Note that all three can be combined into one service and are separated for example purposes.

Flex Service initialization Options

When developing and testing FlexServices locally, you can specify a host and port to listen on by passing an options object with an optional host and port. If no host/port is specified, localhost:10001 will be used:

sdk.service({ host: 'somehost', port: 7777 }, (err, flex) => {
  // code goes here
});

You can also specify a shared secret (i.e. a secret key) to be used by this service. Any client that accesses this service must contain this shared secret, or requests will be rejected with a 401 Unauthorized error.

sdk.service({ sharedSecret: '<some shared secret>'} }, (err, flex) => {
  // code goes here
});

Once set here, you must set this shared secret in the Kinvey console when configuring your service for Kinvey requests to execute properly. For testing locally, this shared secret can be passed in the X-Auth-Key http header.

FlexData

const sdk = require('kinvey-flex-sdk');
sdk.service(function(err, flex) {
  const data = flex.data;   // gets the FlexData object from the service

  function getRecordById(request, complete, modules) {
    let entityId = request.entityId;
    let entity = null;

    // Do some logic to get the entity id from the remote data store
    // Assume that data is retrieved and stored in "entity" variable

    // After entity is retrieved, check to see if it exists
    if (typeof entity === 'undefined' || entity === null) {
      return complete("The entity could not be found").notFound().next();
    } else  {
      // return the entity
      return complete().setBody(entity).ok().next();
    }
  }

  // set the serviceObject
  const widgets = data.serviceObject('widgets');

  // wire up the event that we want to process
  widgets.onGetById(getRecordById);
};

FlexFunctions

const sdk = require('kinvey-flex-sdk');
const request = require('request'); // assumes that the request module was added to package.json
sdk.service(function(err, flex) {

  const flexFunctions = flex.functions;   // gets the FlexFunctions object from the service

  function getRedLineSchedule(context, complete, modules) {
    request.get('http://developer.mbta.com/Data/Red.json', (err, response, body) => {
      // if error, return an error
      if (err) {
        return complete().setBody("Could not complete request").runtimeError().done();
      }

      // otherwise, return the results
      return complete().setBody(body).ok().done();
    });

   }

  // set the handler
  flexFunctions.register('getRedLineData', getRedLineSchedule);
};

FlexAuth

const sdk = require('kinvey-flex-sdk');
const request = require('request'); // assumes that the request module was added to package.json
sdk.service(function(err, flex) {

  const flexAuth = flex.auth;   // gets the FlexAuth object from the service

  function authenticate(context, complete, modules) {
    // authenticate the user here
    if (err) {
      return complete().accessDenied(err).next();
    }
    return complete().setToken(token).ok().next();
  }

  // set the handler
  flexFunctions.register('myAuth', authenticate);
};

Support

Please contact Kinvey for further information or questions