Git Product home page Git Product logo

blocks-js-sdk's Introduction

js-sdk

Client libraries includes methods to use SHIELD, libraries to ease the use of Webpack Module Federation - Promise based loading. It provides the essential packages to facilitate appblocks features across appblocks applications.

As of now, js-sdk contains the following

shield helps to setup authentication for your application. It contains many methods to setup user authentication with shield and obtain tokens across appblocks applications.

ab-federation-helpers contains hooks and methods to facilitate federated Components and Modules

Installation

    npm i @appblocks/js-sdk

Usage

    import { shield } from '@appblocks/js-sdk/shield'

    import { useFederatedComponent } from '@appblocks/js-sdk/ab-federation-helpers'

shield

js-sdk/shield includes the following elements

  1. tokenStore
  2. init
  3. verifyLogin
  4. getAuthUrl
  5. logout

tokenStore

Description

Its an object which stores the token, refresh Token, expiry time as private variables along with related functions. It contains the timer id for the token

Usage

shield.tokenStore.getToken()

init

Description

Its used to initialise the tokenstore with values from the shield backend. It takes a parameter clientID which is unique for each application.

Usage

await shield.init('#client-id')

verifyLogin

Description

It retrieves for the token from the localStorage and validates the token. If the token is not present in the localStorage it redirects to the shield login.

Usage

const isLoggedinn = await shield.verifyLogin()

getAuthUrl

Description

It generates authorization URL with query parameters

Usage

const authUrl = shield.getAuthUrl()

logout

Description

It logs out the user by removing the token from localStorage and redirects to shield login.

Usage

await shield.logout()

ab-federation-helpers

ab-federation-helpers includes the following elements

  1. useFederatedComponent
  2. useFederatedModule
  3. useDynamicScript

useFederatedComponent

Description

used to obtain federated Component .

Usage

const system = {
    module: './login',
    scope: 'login',
    url: 'http://localhost:3013/remoteEntry.js',
}
const { Component: FederatedComponent, errorLoading } = useFederatedComponent(
  system?.url,
  system?.scope,
  system?.module,
  React
)
return (
  <React.Suspense fallback={''}>
    {errorLoading
      ? `Error loading module "${module}"`
      : FederatedComponent && <FederatedComponent />}
  </React.Suspense>
)

useFederatedModule

Description

used to obtain federated Module .

Usage

const system = {
    module: './login',
    scope: 'login',
    url: 'http://localhost:3013/remoteEntry.js',
}
const { Component: FederatedModule, errorLoading } = useFederatedModule(
  system?.url,
  system?.scope,
  system?.module,
  React
)

useDynamicScript

Description

loads script from remote URL.

Usage

  const { ready, errorLoading } = useDynamicScript(remoteUrl, React);

blocks-js-sdk's People

Contributors

frederic-neo avatar that-coder avatar uttahb avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.