npm package: @frollo/frollo-connect-sdk
Description: Frollo's Connect SDK for Frollo Link Web as a Popup
Latest version: 1.0.0

## Frollo Connect SDK

[![build](https://circleci.com/gh/frollous/frollo-connect-sdk/tree/develop.svg?style=shield&circle-token=08be4e5de32493d7fd73d5699cd27749d496bac9)](https://circleci.com/gh/frollous/frollo-connect-sdk/tree/develop) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@frollo/frollo-connect-sdk) [![npm](https://img.shields.io/npm/v/@frollo/frollo-connect-sdk)](https://www.npmjs.com/package/@frollo/frollo-connect-sdk/v/latest)

A JavaScript SDK for linking Frollo Link Web as a popup app.

#### Installation
```bash
npm i @frollo/frollo-connect-sdk
```
or
```bash
yarn add @frollo/frollo-connect-sdk
```

#### Import as a module
```ts
import { openFrolloLink } from '@frollo/frollo-connect-sdk';

openFrolloLink(options)
```

#### Direct Browser usage
##### Reference any one of the CDN scripts in your html
```html
<!-- JSDelivr CDN -->
<script src="https://cdn.jsdelivr.net/npm/@frollo/frollo-connect-sdk"></script>

<!-- UnPkg CDN -->
<script src="https://unpkg.com/@frollo/frollo-connect-sdk"></script>
```
##### Then call the function on a user interaction event
```js
FrolloConnectSdk.openFrolloLink(options);
```

#### Configuration options
```ts
{
  url: string;
  type: 'collection' | 'disclosure' | 'collection,disclosure' | 'dashboard';
  authorisation_code?: string;
  callback?: (arg0: { status: string; description: string } | string) => void | FunctionStringCallback;
  context?: string;
  external_party_id?: number | string;
}
```
##### url
Base url of client's Frollo Link Web environment.
##### type
Type of Consent to be provided.
##### authorisation_code
Authorisation code used for passwordless authentication. See [Get User Passwordless Authentication Token](https://developer.frollo.com.au/docs/frollo-api/662e8b3d3ce1b-get-user-passwordless-authentication-token).
##### callback
The callback is fired when a flow has completed, failed or ended. More info about the callback below.
##### context
Provide a context string identifier that all Collection Consents linked during a flow will be attributed with. Only applies to the Collection Consent flow and one will be generated automatically if not provided.
##### external_party_id
Unique ID of the External Party to disclose to. Only applies to the Disclosure Consent flow.

More info - [Frollo Link Web developer portal](https://developer.frollo.com.au/docs/developer-portal-guides/ab611358492e8-frollo-link#frollo-link-web)

#### Callback
```js
function linkCallback(data) {
  if (data === 'collection-consent-started') { // Consent created
    console.info('Consent partially linked');
  }
  if (data === 'linking-completed') { // Consent created and context updated
    console.info('Consent successfully linked');
  }
  if (data === 'disclose-consent-completed') { // Disclosure consent created
    console.info('Disclosure consent successfully linked');
  }
  if (data === 'failed') { // Consent failed (user can retry)
    console.info('Failed to link');
  }
  if (data.status === 'cancelled') { // Popup closed and description provided
    // description = 'Window closed' | 'Invalid origin' | 'manual-application'
    console.info(data.status, data.description);
  }
}
```


Note: For local development please refer to the [general development readme](https://github.com/frollous/frollo-connect-sdk/blob/develop/development.md).