@clinq/bridge
TypeScript icon, indicating that this package has built-in type declarations

11.9.1 • Public • Published

CLINQ Bridge Framework

This is the CLINQ Bridge framework for developing integration services. It provides a unified way to connect the CLINQ web application to any contact provider.

Bootstrapping a new bridge

If you want to bootstrap a new CLINQ Bridge you can use this repository: clinq-bridge-boilerplate

Installation

npm install --save @clinq/bridge
# or
yarn add @clinq/bridge

Quick Start

CLINQ accepts contacts in this format:

{
  id: "abc123",
  // Provide either the full name or first and last name, not both
  name: null, // or null
  firstName: "Walter", // or null
  lastName: "Geoffrey", // or null
  organization: "Rocket Science Inc.", // or null
  contactUrl: "http://myapp.com/contacts/abc123", // or null
  avatarUrl: "http://myapp.com/avatar/abc123.png", // or null
  email: "walter@example.com", // or null
  phoneNumbers: [
    {
      label: "MOBILE", // or "WORK" or "HOME"
      phoneNumber: "+4915799912345"
    }
  ]
}

The minimum adapter implements the getContacts method:

const bridge = require("@clinq/bridge");
const fetch = require("node-fetch");

const { ServerError } = bridge;

const adapter = {
  getContacts: async ({ apiKey, apiUrl }) => {
    // Fetch contacts using apiKey and apiUrl or throw on error
    const response = await fetch(`${apiUrl}/api/contacts`, {
      headers: { Authorization: `Bearer ${apiKey}` },
    });

    if (response.status === 401) {
      throw new ServerError(401, "Unauthorized");
    }

    if (response.ok) {
      const contacts = await response.json();
      // TODO: Convert contact to the structure above
      return contacts;
    } else {
      throw new ServerError(500, "Could not fetch contacts");
    }
  },
};

bridge.start(adapter);

Configuration

The CLINQ Bridge support configuration through the following environment variables

  • REDIS_URL: URL of a Redis instance to cache responses, otherwise memory cache will be used
  • CACHE_DISABLED: Disable caching
  • CACHE_REFRESH_INTERVAL: Time a contact in cache is not refreshed (in seconds), only used if redis or memory cache is active

Package Sidebar

Install

npm i @clinq/bridge

Weekly Downloads

1

Version

11.9.1

License

Apache-2.0

Unpacked Size

110 kB

Total Files

102

Last publish

Collaborators

  • lauravikanis
  • fgladisch
  • fuglu
  • alphabetapeter
  • leonerath
  • tamerxkilinc
  • nightillusions
  • wo-ist-henry
  • chingucoding