Options
All
  • Public
  • Public/Protected
  • All
Menu

Subaio Fintech Bridge for Web

This document provides informations of how to use the Subaio Fintech Bridge in your projects. There exists 3 Fintech Bridge libraries:

  • Fintech Bridge for iOS
  • Fintech Bridge for Android
  • Fintech Bridge for Web.

The libraries provides user interfaces, API integrations and other functionality related to Subaio. The purpose of the libraries is to reduce the implementation and maintenance cost the host applications, while enabling the Subaio application to evolve parallel with the host application. While there are slight differences between them because of differences in syntax and convention, the general structure is the same.

Architecture

The fintech bridge is intended for embedding small, widget-like applications inside a larger app. The application is structured in the following parts:

  • Host application: The iOS-, Android-, or web-application that hosts the web-components. This might be a mobile bank application or web home banking solution.
  • Bridge: The bridge library is used by the host application to grant easy control over the embedded app as well as a standardized event system. It consists primarily of two components:
    • BridgeManager: A singleton-class for global configuration of all subaio-views, authentication mangagement, as well as communication between views.
    • BridgeView: A wrapper around a single embedded application.
  • Embedded application: The web-application running inside of a webview/iframe.

Including embedded applications thus requires including the bridge library, configuring the BridgeManager and instantiating a BridgeView.

Each bridge project includes an example project demonstrating how to use the manager and the views.

Importing

The library supports ES6 Modules (ESM), CommonJS imports and inclusion as a library script.

ESM

import { BridgeManager, BridgeView } from '@subaio/fintech-bridge-web'

CommonJS

const { BridgeManager, BridgeView } = require('@subaio/fintech-bridge-web')

Library

<script src='/path/to/fintech-bridge-web/dist/subaio.min.js'></script>
var BridgeManager = window.FintechBridge.BridgeManager
var BridgeView = window.FintechBridge.BridgeView

Navigation

To better facilitate native transitions between pages, the subaio app is separated in pages that can be placed in separate view-controllers and pushed separately to the nagivation stack.

Each instance of an embedded view can be set to show a specific Page, defined by a name and optionally a set of parameters, e.g. { name: "OVERVIEW", params: null } or { name: "SUBSCRIPTION", params: { subscriptionId: "..." } }. The exact pages will depend on the application. For simple integrations where the views are simply pushed to the navigation stack, the host application only need knowledge of the initial overview page.

Views will push new pages using the onNavigatedTo event.

Authentication

The subaio views use JSON web tokens for authentication. All views use a shared token, administred by the global configuration. The tokens generally expire after one hour, so there is internal logic to automatically refresh the token when necessary.

The preferred method of obtaining a subaio token is to let the host application make an authenticated request to its own backend, which will then request a token from the subaio backend.

The host application is responsible for providing an onTokenRequired callback for obtaining a token. This callback must handle three cases:

  • Successfully obtained a token. This is distributed to the views and used for future requests.
  • Temporarily unavailable, from a network outage or similar. The BridgeManager will ignore this attempt and try to request a new token later (likely after 1 minute).
  • User unauthenticated. The user is no longer logged in and any active views should be cleared of all data. The BridgeManager will stop requesting new tokens. This is signalled by throwing any error, to ease usage with fetch.

The onTokenRequired callback provided to the configure function has two modes of operation: a promise-based version and a node-style callback version.

// Async/await
BridgeManager.shared.configure({
    onTokenRequired: async (language) => {
        // success
        return token
        // unauthenticated
        return null
        // unavailable
        throw new Error('...')
    },
})
// Manual promise
BridgeManager.shared.configure({
    onTokenRequired: (language) => new Promise((resolve, reject) => {
        // success
        resolve(token)
        // unauthenticated
        resolve(null)
        // unavailable
        reject(new Error('...'))
    }),
})
// Callback
BridgeManager.shared.configure({
    onTokenRequired: (language, callback) => {
        // success
        callback(null, token)
        // unauthenticated
        callback(null, null)
        // unavailable
        callback(new Error('...'))
    },
})

Besides providing the callback, the host application should invoke BridgeManager.shared.refreshToken when the current user is unauthenticated or a new user is authenticated.

See OnTokenRequired.

Configuring the BridgeManager

The following options needs to be provided to the BridgeManager.shared.configure function before any views can be instantiated:

  • baseUrl: The URL where the embedded app is hosted.
  • language: (default null) A BCP-47 language tag. The language can be changed on the fly. If a language is not provided, views will stay in loading-state until one is provided.
  • onTokenRequired: Callback to request a new token. The callback will be called whenever the BridgeManager needs new token information (including if the user is logged out). See OnTokenRequired and the Authentication section.

Instantiating a BridgeView

The BridgeView is a wrapper around an iframe DOM element. It has to be created in a container-element.

Example instantiation:

var view = new BridgeView({
    element: element,
    page: { name: 'OVERVIEW', params: null },
    eventHandlers: {
        onNavigateTo: function (page) { },
        onBack: function (view) { },
        onStatusChange: function (status) { },
        onTitleChange: function (title) { },
        onError: function (type) { },
    },
})

The events provided are:

  • onNavigateTo: Handles navigation to a new Page.
  • onBack: Handles navigation away from the current view.
  • onStatusChange: Called whenever the view changes status. It can be safely ignored. Can be used to implement a custom loading-screen by hiding the loading-screen and showing the view on a change to running or errored, or to implement a custom error-screen by hiding the view and showing an error page on a change to errored.
  • onTitleChange: Called whenever the view changes title. This is useful if a host application controlled navigation bar is used. Otherwise it can be safely ignored.
  • onError: Called whenever the view receives an error.
    • load: The iframe failed to load the page, or the page failed to communicate in a timely manner.
    • internal: Does not need to be handled as the View will show its own error page.

Before the container-element is removed from the DOM, the view.cleanup method should always be called.

Customization

If it is necessary to customize parts of the embedded app, such as colors, this can be passed as customConfig when configuring the manager.

The specific custom value names should be agreed between host and embedded app. Note that while an arbitrary JSON-serializable POJO can be passed, it is recommended to use a flat object with string keys as JS-style dot-paths to ensure compatibility with iOS/Android versions, where creating arbitrary object structures is less straight forward.

Example:

BridgeManager.shared.configure({
    customConfig: {
        'color': '#123456',
        'fonts.regular.url': 'https://path.to/font/file',
    },
})

Build package

The package can be built by running yarn build or npm run build. Output will be placed in dist, documentation will be placed in docs.

Examples

Development can be started by running yarn start or npm run start. Server port is specified by PORT env variable (default 8080).

  • /exampleSimple.html: A minimalist example of usage. The bridge is included as a script tag and everything is written to be runnable on older browsers.

Index

Type aliases

Action

Action: { payload: string; type: SetToken } | { payload?: undefined | null; type: Logout } | { payload?: undefined | null; type: Clear } | { payload?: undefined | null; type: Refresh } | { payload: Page; type: SetView } | { payload: string; type: SetLanguage } | { payload: Array<Page>; type: SetActivePages } | { payload: Array<string>; type: InvalidateData } | { payload: string; type: Unsupported } | { payload: Array<string>; type: SupportedEvents } | { payload?: undefined | null; type: ReportSize } | { payload: Record<string, string>; type: SetCustomConfig } | { payload: { matches: boolean; name: string }; type: MediaQueryChange } | { payload: { data?: any; name: string }; type: CustomAction }

Messages sent from host-application to embedded-application.

Config

Config: { PromiseLib?: PromiseLibType | null; baseUrl: string; customConfig?: Record<string, string>; language?: string | null; onTokenRequired: OnTokenRequired }

Type declaration

  • Optional PromiseLib?: PromiseLibType | null

    Promise implementation to be used. Defaults to native promises, which requires a polyfill to work in any Internet Explorer.

    Can be replaced with another implementation, such as Q or Bluebird.

    null disables promises returned from functions.

  • baseUrl: string

    URL pointing to root of embedded application, e.g. if template is at https://www.bar.foo/template, then baseUrl should be https://www.bar.foo.

  • Optional customConfig?: Record<string, string>

    Custom named values (such as customizable colors) sent to the views.

  • Optional language?: string | null

    Language to be used by all bridge views as a BCP-47 string.

  • onTokenRequired: OnTokenRequired

    Callback invoked whenever BridgeViews need an authentication token.

    Takes the current language-tag as first parameter. Can either return a promise or invoke a node-style callback provided as second parameter to signal completion.

    Three cases are supported:

    • Success: Should resolve to the new token string.
    • Unauthenticated: User is not logged in. Should resolve to null.
    • Unavailable: User is still logged in, but a new token can't be retrived for some reason, e.g. lost connection. Should reject with any error
    param

    The current language tag, provided for convenience.

    param

    node-style callback – (error, result) => void

EventHandlers

EventHandlers: { onBack?: undefined | ((view: BridgeView) => void); onError?: undefined | ((type: "load" | "internal", view: BridgeView) => void); onNavigateTo?: undefined | ((page: Page, view: BridgeView) => void); onResize?: undefined | ((height: number, view: BridgeView) => void); onStatusChange?: undefined | ((status: Status, view: BridgeView) => void); onTitleChange?: undefined | ((title: string, view: BridgeView) => void) }

Type declaration

  • [key: string]: ((payload: any, view: BridgeView) => void) | undefined

    Custom events can be added. The signature of a custom event should be agreed upon between the host and embedded app.

  • Optional onBack?: undefined | ((view: BridgeView) => void)

    Called whenever a view attempts to close itself.

  • Optional onError?: undefined | ((type: "load" | "internal", view: BridgeView) => void)

    Called whenever an error occurs. Should handle 2 cases:

    • load: The iframe failed to load the page, or the page failed to communicate in a timely manner.
    • internal: An error occured inside the embedded application. A built-in error screen is shown, it is not necessary for the host application to show an error.
  • Optional onNavigateTo?: undefined | ((page: Page, view: BridgeView) => void)

    Called whenever the view attempts to navigate to another page.

  • Optional onResize?: undefined | ((height: number, view: BridgeView) => void)

    Called whenever the content of the iframe resizes. Is only enabled when enableResize is set to true.

  • Optional onStatusChange?: undefined | ((status: Status, view: BridgeView) => void)

    Called whenever the status of the view changes.

    Can be used to implement a custom loading-screen by hiding the loading-screen and showing the view on a change to running or errored.

    Can be used to implement a custom error-screen by hiding the view and showing an error page on a change to errored.

  • Optional onTitleChange?: undefined | ((title: string, view: BridgeView) => void)

    Called whenever the view changes title.

    If a host-application controlled title-bar is used, this text should be shown there.

Event_2

Event_2: { payload: { status: Status }; type: StatusChanged } | { payload: number; type: Resize } | { payload: Page; type: Navigate } | { payload?: undefined | null; type: Back } | { payload?: undefined | null; type: Error } | { payload: string; type: TitleUpdated } | { payload: Array<string>; type: InvalidateData } | { payload: string; type: OpenUrl } | { payload: { message: string }; type: Share } | { payload?: undefined | null; type: RequestToken } | { payload: { name: string; query: string }; type: SubscribeMediaQuery } | { payload: { data?: any; name: string }; type: CustomEvent }

Messages sent from embedded-application to host-application.

OnTokenRequired

OnTokenRequired: ((language: string) => Promise<string>) | ((language: string, callback: (error: Error, result: string) => void) => void)

Callback invoked whenever BridgeViews need an authentication token.

Takes the current language-tag as first parameter. Can either return a promise or invoke a node-style callback provided as second parameter to signal completion.

Three cases are supported:

  • Success: Should resolve to the new token string.
  • Unauthenticated: User is not logged in. Should resolve to null.
  • Unavailable: User is still logged in, but a new token can't be retrived for some reason, e.g. lost connection. Should reject with any error
param

The current language tag, provided for convenience.

param

node-style callback – (error, result) => void

Page

Page: { name: string; params?: null | Record<string, string | number> }
license

Copyright © 2018 Subaio ApS. All rights reserved.

Type declaration

  • name: string
  • Optional params?: null | Record<string, string | number>

PromiseLibType

PromiseLibType: { constructor: any; reject: (error: any) => Promise<any>; resolve: <T>(value?: T) => Promise<T> }

Type declaration

  • constructor: function
    • new __type<T>(executor: (resolve: (value: T) => void, reject: (reason: any) => void) => void): Promise<T>
    • Type parameters

      • T

      Parameters

      • executor: (resolve: (value: T) => void, reject: (reason: any) => void) => void
          • (resolve: (value: T) => void, reject: (reason: any) => void): void
          • Parameters

            • resolve: (value: T) => void
                • (value: T): void
                • Parameters

                  • value: T

                  Returns void

            • reject: (reason: any) => void
                • (reason: any): void
                • Parameters

                  • reason: any

                  Returns void

            Returns void

      Returns Promise<T>

  • reject: (error: any) => Promise<any>
      • (error: any): Promise<any>
      • Parameters

        • error: any

        Returns Promise<any>

  • resolve: <T>(value?: T) => Promise<T>
      • <T>(value?: T): Promise<T>
      • Type parameters

        • T

        Parameters

        • Optional value: T

        Returns Promise<T>

ViewOptions

ViewOptions: { element: HTMLElement; enableResize?: undefined | false | true; eventHandlers?: EventHandlers; managerInstance?: BridgeManager; page?: Page; settings?: undefined | { height: string; width: string } }

Type declaration

  • element: HTMLElement

    The target element. The iframe will attempt to fill the entire container.

  • Optional enableResize?: undefined | false | true

    Enable the onResize event. Defaults to off to avoid unnecessary tracking of size.

  • Optional eventHandlers?: EventHandlers
  • Optional managerInstance?: BridgeManager

    Instance of BridgeManager to be used. Defaults to the shared instance, BridgeManager.shared. Useful in paradigms where singletons are discuraged over distributed instances.

  • Optional page?: Page
  • Optional settings?: undefined | { height: string; width: string }

    Override iframe settings. Both width and height defaults to '100%'.

Legend

  • Constructor
  • Property
  • Method
  • Accessor

Generated using TypeDoc