🚀 Launch Week Day 5:Introducing Immutable Scans.Learn More →
Socket
Book a DemoInstallSign in
Socket

@hiro-ui/sdk

Package Overview
Dependencies
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hiro-ui/sdk

HIRO Applications SDK.

latest
Source
npmnpm
Version
8.3.12
Version published
Maintainers
1
Created
Source

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
    );
  },
);

FAQs

Package last updated on 30 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts