2.0.3 • Published 1 month ago

@meshconnect/web-link-sdk v2.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

@meshconnect/web-link-sdk

A client-side JS library for integrating with Mesh Connect

Install

With npm:

npm install --save @meshconnect/web-link-sdk

With yarn

yarn add @meshconnect/web-link-sdk

Getting Link token

Link token should be obtained from the GET /api/v1/linktoken endpoint. Api reference for this request is available here. Request must be preformed from the server side because it requires the client secret. You will get the response in the following format:

{
  "content": {
    "linkToken": "{linktoken}"
  },
  "status": "ok",
  "message": ""
}

You can use linkToken value from this response to open the popup window with openLink method.

Generating connection method

import { createLink } from '@meshconnect/web-link-sdk';

// ...

const linkConnection = createLink({
  clientId: '<Your Mesh Connect Client Id>',
  onIntegrationConnected: (data: LinkPayload) => {
    // use broker account data
  },
  onExit: (error?: string) => {
    if (error) {
      // handle error
    } else {
      // ...
    }
  }

Using connection to open auth link

To open authentication link provided by Front Finance Integration API you need to call openLink method:

linkConnection.openLink(linkToken)

ℹ️ See full source code example at react-example/src/ui/Link.tsx

import { createLink, Link, LinkPayload } from '@meshconnect/web-link-sdk'

// ...

const [linkConnection, setLinkConnection] = useState<Link | null>(null)

useEffect(() => {
  setLinkConnection(createLink(options))
}, [])

useEffect(() => {
  if (authLink) {
    linkConnection?.openLink(linkToken)
  }
}, [linkConnection, authLink])

return <></>

Getting tokens

After successfull authentication on the Link session, the popup will be closed and the broker tokens will be passed to the onIntegrationConnected function. Link instance will check if URL contains query parameters, load broker tokens and fire the events.

Available Connection configuration options

ℹ️ See src/types/index.ts for exported types.

createLink arguments

keytypedescription
clientIdstringKeys from https://dashboard.getfront.com/company/keys page
onIntegrationConnected(payload: LinkPayload) => voidCallback called when users connects their accounts
onExit((error?: string \| undefined) => void) \| undefinedCalled if connection not happened
onTransferFinished(payload: TransferFinishedPayload) => voidCallback called when a crypto transfer is executed
onEvent(payload: LinkEventType) => voidA callback function that is called when various events occur within the Front iframe
accessTokensIntegrationAccessToken[]An array of integration access tokens

createLink return value

keytypedescription
openLink(linkToken: string) => Promise<void>Opens the Link UI popup
closeLink() => Promise<void>Closes the Link UI popup

Using tokens

You can use broker tokens to perform requests to get current balance, assets and execute transactions. Full API reference can be found here.

Typescript support

TypeScript definitions for @meshconnect/web-link-sdk are built into the npm package.

2.0.3

1 month ago

2.0.1

5 months ago

2.0.0

7 months ago