Installation

Install the Node.js Product SDK using the Node Package Manager (NPM)

The Cofor.io Product SDK for Node.JS backend APIs is available for installation using npm. See more details of the package on NPM.

Installation using NPM or YARN

Install using the command line:

npm install @inventives/coforio-sdk

If you prefer to use yarn instead of npm, run the following:

yarn add @inventives/coforio-sdk

Import into your project

Import into your project with either of the following depending on your node/javascript engine version:

import Coforio from '@inventives/coforio-sdk';
const Coforio = require('@inventives/coforio.sdk');

You must first instantiate a Coforio object with the Cofor.io product ID and key you get from the product setup/management page.

const cio = new Coforio(
    process.env.CIO_PRODUCT_ID,
    process.env.CIO_PRODUCT_KEY
);

Optionally if you wish to use a local Redis cache to improve the performance of your API authorization middleware, the Redis hostname/IP address and password can be passed in.

const cio = new Coforio(
    process.env.CIO_PRODUCT_ID,
    process.env.CIO_PRODUCT_KEY,
    process.env.CIO_REDIS_CACHE_HOST,
    process.env.CIO_REDIS_CACHE_PASSWORD
);

👍

Optimized API Performance

Deploy a Redis instance in your environment and connect your product SDK to it by passing the redis host and password when instantiating your Coforio object. This lets your product cache authenticated user, team, and membership information locally so you don't have to authenticate against the Cofor.io API each time.

Usage with TypeScript

If you are using Cofor.io with TypeScript, you can provide more detailed types as parameters to the Coforio constructor. This will allow proper type-checking and auto-complete options for Team Scopes, Membership Scopes, Team Data objects, and Membership Data objects depending on your IDE.

type TeamScopes = 'admin' | 'crew';
type MembershipScopes = 'moderator' | 'user';
interface TeamData {
    // ...
}
interface MembershipData {
    // ...
}

const cio = new Coforio<MembershipScopes, MembershipData, TeamScopes, TeamData>(
    process.env.CIO_PRODUCT_ID,
    process.env.CIO_PRODUCT_KEY,
);

Error Handling

Any method may throw an Error object if the operation fails. The Error object shall include a message parameter with a helper error message, and a response object that contains the API response from the Cofor.io API.