JSPM

  • Created
  • Published
  • Downloads 69
  • Score
    100M100P100Q110671F
  • 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 one of these repositories:

Installation

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

Quick Start

CLINQ accepts contacts in this format:

{
  id: "abc123",
  name: "Walter Geoffrey",
  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 null
      phoneNumber: "+4915799912345"
    }
  ]
}

The minimum adapter implements the getContacts method:

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

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) {
      bridge.unauthorized();
    }
    if (response.ok) {
      const contacts = await response.json();
      // TODO: Convert contact to the structure above
      return contacts;
    } else {
      throw new Error("Could not fetch contacts :(");
    }
  }
};

bridge.start(adapter);