JSPM

@dustid/dust-go-connect

0.1.7
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q43752F
  • License MIT

A library for connecting a frontend application to the DUST GO react native application

Package Exports

  • @dustid/dust-go-connect
  • @dustid/dust-go-connect/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@dustid/dust-go-connect) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@dustid/dust-go-connect

DUST Go is a prototyping platform that allows developers to create mobile webapps that leverage DUST Identity's platform-dependent functionality without requiring an upfront investment into mobile toolchains.

Install

npm install @dustid/dust-go-connect

Usage

// NOTE: connector will be undefined if running outside DUST Go
import { connector } from @dustid/dust-go';

const scans: {data: string, metadata: Record<string, unknownn>}[] = [];

connector?.add("unique-id-for-this-listener", (event: ScanEvent) => {
  if (event.type === 'scan') scans.push(event.payload)
  if (event.type === 'hide') // do something
  if (event.type === 'show') // do something
});
connector?.showScanner();

API

High Level API

scanAsync() Presents the scanner, and awaits a scan. Rejects if scanner is hidden.

// scanAsync(): Promise<ScanPayload>
const scan = await scanAsync();

DUST Go Connector

This is more low level, but more flexible.

connector.showScanner(): void

Shows the scanner modal over the main webview.

connector.hideScanner(): void

Hides the scanner modal, returning to the main webview. Note, this can be called even while the webview is in the "background", the webview isn't paused while the scanner is presented.

Events

type ScanPayload =
  | {
      type: 'DUST'
      data: string
      metadata?: ScanSettings
    }
  | {
      type: 'QR'
      data: string
      metadata?: Record<string, any>
    }
  | { type: 'BARCODE'; data: string; metadata?: Record<string, any> }
  | { type: 'DATA_MATRIX'; data: string; metadata?: Record<string, any> }
  | { type: 'NFC'; Data: string; metadata?: Record<string, any> }
Scan Events
{ type: 'scan', payload: ScanPayload}
{ type: 'show' }
{ type: 'hide' }
connector.dispatch(event: ScanEvent): void

Add a listener with a unique identifier.

connector.add(id: string, cb: (event: ScanEvent) => void): void

Remove the listener with the provided identifier.

connector.remove(id: string): void

Check if a listener has been added for the given id

connector.has(id: string): boolean

Remove all event listeners

connector.clear();

Auth

On some platforms, it's necessary to rewrite the redirects from the app to the OAuth2 server to work around platform limitations. It's recommended to always wrap those redirects with this call, and let the connector no-op when no workaround is required.

connector.rewriteRedirect(url: URL): URL