A unified JavaScript SDK for the Cogs (cogswell.io) APIs
IMPORTANT: The module on npmjs.com has been renamed from cogs-javascript-sdk to cogs-sdk. Please update your project dependencies accordingly.
This module contains the JavaScript SDKs for the various Cogs APIs.
- Info - Informational APIs requiring no authentication.
- Tools - Customer APIs which are meant for Cogs' users' internal use only (not client apps, websites, or devices). These require authentication using customer API key credentials.
- Client - Client APIs which are meant for client software (apps, devices, etc.). These require authentication using derived client (salt/secret pair generated by the tools API) credentials.
Configuration
There are different configurations for the client and tools SDKs. While it is possible to include all key components (both the api key and client key) required in order to use both at the same time (and this is fine for testing on your own equipment), the secret component of your Cogs API key should never be placed into an app, a consumer device, or field unit.
An example of each type of config are included in this repository in the cogs-tools.json
and cogs-client.json
for the tools and client APIs respectively.
The tools SDK requires that the api_key.access
and api_key.secret
fields be populated.
The client SDK requires that the api_key.access
, client_key.salt
, and client_key.secret
fields be populated.
Info API Routes
GET /api-docs
Provides the Swagger documentation for the Cogs APIs formatted as JSON.
var cogs = ; cogsinfo;
GET /build_info
Provides details regarding the currently deployed version Cogs. This information is useful when reporting issues with the service APIs.
var cogs = ; cogsinfo;
Tools API Routes
All of these routes are authenticated using the access_key and secret_key.
GET /namespace/:NAMESPACE_NAME/schema
Use this endpoint to fetch the schema for one of your namespaces. This includes the attributes for that namespace as well as all core attributes for your account. It will indicate the type of each attribute and indicate whether it is part of the primary key for that namespace.
var cogs = ;var namespace = 'my-namespace'; cogstools;
POST /random_uuid
Use this endpoint to generate random (version 4) UUID for use by client devices from a solid entropy source.
var cogs = ; cogstools;
POST /client_secret
Use this endpoint to generate new client keys for your client devices/apps. The new salt/secret pair will be associated with the api key you use to authenticate this API operation. When you disable (revoke) an api key, all client keys generated using that api key are also disabled.
var cogs = ; cogstools;
Client API Routes
All of these routes are authenticated using the access_key, client_salt and client_secert.
POST /event
All events are sent to Cogs through this route. The event data must only contain attributes valid for the namespace specified in the request. It must also include all attributes defined as primary key attributes for the namespace. These uniquely identify the topic of the event.
var cogs = ; var namespace = 'my-namespace';var eventName = 'my-event'var attributes = 'my-id-attribute': 12 'my-name': 'Bob' 'my-boolean': true;var tags = 'foo' 'bar'; cogsclient;
GET /message/:MESSAGE_ID
Messages generated by Cogs may be fetched by their ID. This is important for mobile devices which receive only the message ID in notifications and need to fetch the full message payload in response to the notification. This is also useful when for space constraints you wish to store only historical message IDs on a device, and fetch messages from Cogs only when you need to reference them. Keep in mind that the identified message is also paired with the namespace and topic attributes identified in the authentication payload.
var cogs = ; var namespace = 'my-namespace';var topicAttributes = 'my-id-attribute': 12;var messageId = 'deadbeef-dead-beef-dead-beefdeadbeef'; cogsclient;
GET /push
This endpoint is use to establish WebSockets in order to receive push notifications for individual topics. New messages generated for a particular topic are delivered to all WebSockets registered with that topic's identifying attributes. Unlike mobile notifications, which only contain the message ID, the payload sent over these WebSockets is the entire message payload. It does include the message ID, so you can still fetch the message again later by its ID.
var cogs = ; var namespace = 'my-namespace';var topicAttributes = 'my-id-attribute': 12; cogsclient;