This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

textsync-server-node
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

TextSync Node Library

Server side library for TextSync. It's useful for generating tokens in the format expected by the TextSync client library when an authorization endpoint is configured.

Usage

Importing

It's possible to import textsync-server-node using ES6 modules.

import TextSync from 'textsync-server-node';

Commonjs is supported too.

const TextSync = require('textsync-server-node');

Instantiation

The constructor takes a single options object with the following required keys:

  • instanceLocator
  • key

Both of which should be available from the keys page of your TextSync dashboard.

let instance = new TextSync({
  instanceLocator: INSTANCE_LOCATOR,
  key: KEY,
});

Authorization

instance.authorizeDocument(requestData, permissionsFn, options);
  • requestData (required) - body of the request from the client library
  • permissionsFn (required) - a function returning a promise resolving to the permissions the user making the request has to docId. The library exposes the available permissions (at present there is only TextSync.Permissions.READ and TextSync.Permissions.WRITE)
  • options (optional) - an object containing authorization options. At present the only option available tokenExpiry

Example

const TextSync = require('textsync-server-node');
const express = require('express');
const bodyParser = require('body-parser');
 
const app = express();
app.use(bodyParser.json());
 
 
let textSync = new TextSync({
  locator: INSTANCE_LOCATOR,
  key: KEY,
});
 
app.post('/textsync/tokens', (req, res) => {
  const getPermissions = docId => {
    return new Promise((resolve, reject) => {
      // Some async logic to determine what permissions the user has
      //
      // Permissions are modelled as an array of TextSync.Permissions exports
      resolve([TextSync.Permissions.READ, TextSync.Permissions.WRITE]);
    });
  };
  const options = { tokenExpiry: (60 * 15) }; // 15 minutes;
  textSync.authorizeDocument(req.body, getPermissions, options).then(token => {
    res.send(token);
  });
});

Readme

Keywords

none

Package Sidebar

Install

npm i textsync-server-node

Weekly Downloads

3

Version

0.4.0

License

MIT

Unpacked Size

117 kB

Total Files

19

Last publish

Collaborators

  • jeremy.goldstein
  • fbenevides
  • marcelcorso
  • pushercom