@syncrelay/node
TypeScript icon, indicating that this package has built-in type declarations

2021.6.1-alpha.4 • Public • Published

SyncRelay SDK for Node.js

Disclaimer: This package is still in preview and may change substantially until a stable version is released.

The SyncRelay SDK for Node.js is a wrapper around the API that allows you to easily build applications using SyncRelay.

Getting started

You can create a client by initiating a new instance of Client, exported from @syncrelay/node. To create a client, you need to provide a valid access token, created in the SyncRelay dashboard.

import { Client } from '@syncrelay/node';

const client = new Client({ accessToken: 'sra_...' });

Authorizing Consumers

You can authorize consumers to access the live endpoint of a project by using the authorizeConsumer method on the Client instance. It will return a Promise that resolves to the returned object including the consumer token.

const { consumerToken } = await client.authorizeConsumer({
  data: {
    projectId: '<your project id',
    allowedTopics: ['/topic1' /* ... */]
  }
});

Sending messages

Send a message to a topic using the sendMessage method on the Client instance. It will return a Promise that resolves to the returned object including the message id, topic, kind, and payload. The payload you pass must be a stringified JSON object.

const { sentMessage } = await client.sendMessage({
  data: {
    projectId: '<your project id',
    kind: '<message kind>',
    topic: '<message topic>',
    payload: JSON.stringify({
      /* ... */
    })
  }
});

Readme

Keywords

none

Package Sidebar

Install

npm i @syncrelay/node

Weekly Downloads

0

Version

2021.6.1-alpha.4

License

MIT

Unpacked Size

61 kB

Total Files

18

Last publish

Collaborators

  • brunoscheufler-bot