dreams-web-sdk
TypeScript icon, indicating that this package has built-in type declarations

1.4.1 • Public • Published

Dreams Web SDK

Dependencies

To install dependencies run

yarn install

We use lefthook. Refer to their github page for installation instructions.

Testing

yarn test

We use jest for testing.

Building

To build distros run

yarn run build

New distros are going to be created in the dist folder.

For more info about building packages refer to rollup webpage.

Usage

<div id="dreams-web-sdk-container"></div>

<script src="path/to/dreams/sdk/js/file">
  var callbacks = {
    onIdTokenDidExpire: async () => {
      const resp = await fetch("/token-expired-endpoint");
      const data = await resp.json();

      return data.token;
    },
    onAccountProvisionRequested: async () => {
      await fetch("/provision-account-endpoint")
    },
    onExitRequested: () => {
      window.location.href = "http://example.com/some/path"
    }, 
    onTransferConsentRequested: (event) => promise.resolve({consentId: event.message.consentId, requestId: event.message.requestId, consentRef: 'foo'}),
    onAccountRequested: (event) => promise.resolve({requestId: event.message.requestId})
  }

  var sdk = new DreamsWebSDK("https://dreams.api.endpoint");

  // Optional param to redirect user inside dreams app
  var location = "marketplace";

  sdk.setup(callbacks);
  sdk.start(user_jwk_token_value, "en", location);
</script>

Manually sending a message

<div id="dreams-web-sdk-container"></div>

<script src="path/to/dreams/sdk/js/file">
  var callbacks = {}
  var sdk = new DreamsWebSDK("https://dreams.api.endpoint");
  var messageHandler = sdk.setup(callbacks);

  sdk.start(user_jwk_token_value, "en");

  const new_token = await fetch("/token-endpoint");

  messageHandler.postUpdateToken('request-id-string', new_token)
</script>

message types

currently we can:

  • postUpdateToken a response to onIdTokenDidExpire message
  • postAccountProvisionInitiated a response to onAccountProvisionRequested message
  • postInvestmentAccountProvisionInitiated a response to onInvestmentAccountProvisionRequested message
  • navigateTo that has no corresponding dreams side message

see the docs about their usage.

Contributing

Commit naming

We use commitlint to make sure commit messages adhere to certain rules. These are:

Semantic release takes care of automatically bumping release versions provided that we name commits correctly. Here you can find what constitutes a patch/feature/breaking release.

License

Mozilla Public License Version 2.0

Readme

Keywords

Package Sidebar

Install

npm i dreams-web-sdk

Weekly Downloads

4

Version

1.4.1

License

MPL-2.0

Unpacked Size

126 kB

Total Files

31

Last publish

Collaborators

  • beniamin.bartkowiak
  • thelitek
  • loffek