How to Install the JS SDK
This guide explains how to install and initialize the TigerConnect JS SDK.
Installation
Web
Using npm
npm install --save tigerconnect
Using a require
statement:
const TigerConnect = require('tigerconnect');const client = new TigerConnect.Client(config);
Alternatively, using an import
statement:
import { Client as TigerConnectClient } from 'tigerconnect';const client = new TigerConnectClient(config);
Webpack and most other bundlers support automatically finding the web-specific version of the package at tigerconnect-sdk-web.min.js
. If your bundler does not support this, or you are not using a bundler, then you may need to use an explicit path like this instead:
const TigerConnect = require('tigerconnect/tigerconnect-sdk-web.min.js');const client = new TigerConnect.Client(config);
Using Bower
bower install --save tigerconnect
<script src="bower_components/tigerconnect/tigerconnect-sdk-web.min.js" charset="utf-8"></script>
Manual Include
Download tigerconnect-sdk-web.min.js and include it in a script
tag:
<script src="path/to/tigerconnect-sdk-web.min.js" charset="utf-8"></script>
Node.js
We recommend using Node.js 12.
To install the SDK using npm
:
npm install --save tigerconnect
const TigerConnect = require('tigerconnect');const client = new TigerConnect.Client(config);
Polyfills
In order to make integration easier, the TigerConnect JS SDK will install its own polyfills when the SDK is loaded. If you want to disable this behavior, add one of the following statements before loading the SDK:
// if in a browser contextwindow._tcShouldPolyfill = false;
// if in a Node.js or Webpack contextglobal._tcShouldPolyfill = false;
Make sure that you do not use static import
statements if you are doing this in the same file as the load of the SDK itself, otherwise the import
statement for the SDK may be hoisted above the _tcShouldPolyfill
statement, causing the disablement to have no effect.
If you do opt to manage your own polyfills, you may want to install the core-js
and promise
npm modules and then include at least these polyfills (which are for features known to be used in the JS SDK) as early in your code execution as possible, as documented in the next section.
Make sure that these statements are at the top-level of the file, and are not inside of a function call, otherwise they will not install correctly into the global context.
Browser Polyfills
These polyfills are for code that will run in a browser, in case you want to manage your own browser polyfills.
require('core-js/features/array/find');require('core-js/features/array/from');require('core-js/features/array/includes');require('core-js/features/object/assign');require('core-js/features/object/entries');require('core-js/features/object/values');require('core-js/features/string/ends-with');require('core-js/features/string/includes');require('core-js/features/string/starts-with');require('core-js/features/symbol');const isIE11 = window && window.navigator.userAgent.includes('Trident/');if (isIE11 || typeof Promise === 'undefined' || !('finally' in Promise.prototype)) {require('promise/lib/rejection-tracking').enable();self.Promise = require('promise/lib/es6-extensions.js');}require('abortcontroller-polyfill/dist/abortcontroller-polyfill-only');require('cross-fetch/polyfill');
Node.js Polyfills
These polyfills are for code that will run in Node.js, in case you want to manage your own Node.js polyfills. Please note that you will need to install the separate @tigerconnect/node-fetch
npm module.
require('core-js/features/array/find');require('core-js/features/array/from');require('core-js/features/array/includes');require('core-js/features/object/assign');require('core-js/features/object/entries');require('core-js/features/object/values');require('core-js/features/string/ends-with');require('core-js/features/string/includes');require('core-js/features/string/starts-with');require('core-js/features/symbol');if (typeof fetch === 'undefined') {const nodeFetch = require('@tigerconnect/node-fetch');global.fetch = nodeFetch.default;global.Response = nodeFetch.Response;global.Headers = nodeFetch.Headers;global.Request = nodeFetch.Request;require('abortcontroller-polyfill/dist/polyfill-patch-fetch');}
Initializing the SDK
All communication with TigerConnect is performed with a single TigerConnect.Client
instance. The client can hold a single authenticated user, and will execute all commands on this user's behalf.
You can create a client by using our provided constructor.
Definition
new TigerConnect.Client({apiEnv: ?string = 'production',baseUrl: ?string,defaultOrganizationId: ?string = null,logLevel: ?string = 'error',partnerName: string,version: ?string}):<Client>
Parameters
Parameter | Type | Description |
---|---|---|
apiEnv | ?string | Environment to use (default: production ). For testing purposes, it is recommended to set this to uat . Will be ignored if baseUrl is provided. Please coordinate this value with your TigerConnect support representative. |
baseUrl | ?string | Exact URL to use when contacting the TigerConnect API servers (default: not provided, in which case the apiEnv parameter will be used to formulate the URL). Please coordinate this value with your TigerConnect support representative. |
defaultOrganizationId | ?string | The default organization used to send all messages; if not provided, no default organization will be used |
logLevel | ?string | How verbose logging should be, can be one of debug /info /warn /error /fatal |
partnerName | string | A name used to identify a specific partner of TigerConnect. Please coordinate this value with your TigerConnect support representative. |
version | ?string | A version number which identifies the partner's own code deployment |
Returns
A client object that can be used to sign in with a user and execute commands.
Example
const client = new TigerConnect.Client({apiEnv: 'uat',defaultOrganizationId: 'some-org-id',partnerName: 'a-partner-name'});const session = await client.signIn('user@mail.com', 's3cr3t');console.log('Signed in as', session.user.displayName);const message = await client.messages.sendToUser('someone@mail.com', 'hello!');console.log('sent', message.body, 'to', message.recipient.displayName);client.events.connect();client.models.Message.on('afterInject', function(resource, message) {console.log('message received from',message.sender.displayName,'to',message.recipient.displayName,':',message.body);});