JSPM

  • Created
  • Published
  • Downloads 69
  • Score
    100M100P100Q110721F
  • License Apache-2.0

CLINQ Bridge Framework

Package Exports

  • @clinq/bridge

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@clinq/bridge) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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