@hiro-ui/sdk
TypeScript icon, indicating that this package has built-in type declarations

2.0.3 • Public • Published

HIRO SDK for HIRO 7.x

Available Functions

initSdk

Initializes the SDK and provides config details from HIRO Desktop. initSdk also provides a ready callback and a state object.

const config = {}; // Optional default config

initSdk(config).then(
  ({
    config: { } // Config values provided by SDK
    ready, // Callback, once your application is ready
    state, // Stored application state
  }: InitSdkResult) => {
      // SDK is initialized and ready to use
  }
);

close

Closes the application within HIRO Desktop

close();

unauthorized

Callback to SDK for unauthorized Token

unauthorized();

saveState

Sync application state back to HIRO Desktop

const state = {}; // Application state object
saveState(state);

runApp

Open a different application, with parameters, from within your application.

const appParameters = {}; // Parameters for the new application
runApp(appId, appParameters);

Available TypeScript Interfaces

SdkConfig TypeScript Interface

interface SdkConfig {
  authUrl?: string;
  graphUrl?: string;
  redirectUrl?: string;
  clientId?: string;
  roles?: string[];
}

LoadedConfig TypeScript Interface

interface LoadedConfig {
  graphUrl?: string;
  token?: string;
}

DesktopUser TypeScript Interface

interface DesktopUser {
  _id: string;
  accountId: string;
  email: string;
  id: string;
  name: string;
  roles: string[];
}

DesktopConfig TypeScript Interface

interface DesktopConfig {
  user: DesktopUser;
  org: {
    id: string;
    name: string;
  };
  token: string;
  graphUrl: string;
  shared: {
    [key: string]: any;
  };
  options?: {
    [key: string]: any;
  };
}

InitSdkResult TypeScript Interface

InitSdkResult TypeScript Interface

interface InitSdkResult<S = {}> {
  ready: () => void;
  state: S;
  config: DesktopConfig;
}

Example Usage in React

import React from 'react';
import ReactDOM from 'react-dom';

import YourReactApp from './YourReactApp';

import {
  SdkConfig, // SdkConfig TypeScript Interface
  InitSdkResult, // InitSdkResult TypeScript Interface
  initSdk, // Initializes the SDK
  unauthorized, // Callback to SDK for unauthorized Token
} from '@hiro-ui/sdk';

import Client, { Token } from '@hiro-graph/client';

// Default config for Development
const config: SdkConfig = {
  clientId: process.env.HIRO_CLIENT_ID,
  graphUrl: process.env.HIRO_GRAPH_URL,
  authUrl: process.env.HIRO_AUTH_URL,
  redirectUrl: process.env.HIRO_REDIRECT_URL,
  scopeId: process.env.HIRO_SCOPE_ID,
};

// Initializes the SDK with Default config
initSdk(config).then(
  ({
    config: { user, graphUrl, token, shared, scopeId, options },
    ready, // Callback, once your application is ready
    state, // Stored application state
  }: InitSdkResult) => {
    // SDK is initialized and ready to use

    const myToken = new Token({
      onInvalidate: () => {
        // Handle unauthorized Token
        unauthorized();
        return Promise.resolve();
      },
      getToken: () => Promise.resolve(token),
    });

    // Get Graph Client with SKD Configs
    const graphClient = new Client({
      endpoint: graphUrl,
      token: myToken,
    });

    ReactDOM.render(
      <YourReactApp />,
      document.getElementById('app'),
      ready, //ready callback for SDK
    );
  },
);

Readme

Keywords

none

Package Sidebar

Install

npm i @hiro-ui/sdk

Weekly Downloads

13

Version

2.0.3

License

MIT

Unpacked Size

29.4 kB

Total Files

14

Last publish

Collaborators

  • cy303
  • bpneal