npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@orbis-systems/accounts-ts-sdk

v1.1.42

Published

AMT SDK is designed to help clients consume Account Management API with ease. AMT SDK takes care of all the heavy lifting and provides out of the box ready to use object.

Downloads

3

Readme

Account Management Typescript SDK - (AMT)

AMT SDK is designed to help clients consume Account Management API with ease. AMT SDK takes care of all the heavy lifting and provides out of the box ready to use object.

Example of a use case

//APIConfigure.ts
import configureSDK from '@orbis-systems/accounts-ts-sdk';

const SDK = SDKClient({
   environment: 'development'
});

export default SDK;
//App.ts
import SDK from '../api/APIConfigure';

class App extends React.Component<IProps> {
    state: {
        applications: [],
    }
    
    public async componentDidMount(): Promise<void> {
        const user = SDK.rest.client.login('username', 'password', ['user.role']);
        SDK.rest.client.autoRenewToken();`_**~~``~~**_`
        const res = SDK.rest.applications.list();
        if(res.success){
            this.setState({
                applications: res.data.applications,
            });
        }else{
            res.error // handle error
        }           
    }   

    public render(): JSX.Element {
        return (
            <>
                {
                    this.state.applications.map(application => {
                        return (
                            //Render what's needed
                        );
                    })  
                }   
            </>
        )
    };
}

Configuration

interface IConfig {
  tokenExpired?: Function
  onUnauthorized?: Function
  onEndpointError?: Function
  environment: 'production' | 'sandbox'
  storage?: 'local' | 'session'
}

AMT SDK must be configured before use. It provides a configure function that takes a configuration object with options.

  • tokenExpired?: Function optional
    • Called when the token could not be renewed.
  • onUnauthorized?: Function optional
    • Called when an endpoint returned 401 Unauthorized.
  • onEndpointError?: Function optional
    • Called on any endpoint error that has occurred and provides error.
  • environment: 'production' | 'sandbox' required
    • Sets environment to which AMT needs to connect to.
  • storage?: local' | 'session default: session optional
    • Called when the token could not be renewed.

Example

import configureSDK from './index';

const SDK = configureSDK({
    environment: 'production', 
    onEndpointError: (err): void => {
        store.dispatch({
            type: actionTypes.API_ERROR,
            payload: err
        });
    },
    onUnauthorized: (): void => {
        store.dispatch({
            type: actionTypes.AUTH_UNAUTHORIZED,
        })
    },
    tokenExpired: (): void => {
        localStorage.clear();
        store.dispatch({
            type: actionTypes.AUTH_LOGOUT,
        });
    },
    storage: 'local'
});

Authentication

AMT SDK provides a client object that is used to authenticate with Accounts Management API. On a successful authentication AMT SDK stores the token provided into session storage for later use. All endpoints that are protected must be used after the client has authenticated, otherwise the onUnauthorized function with be called. client object has three methods.

  • login(email: string, password: string, includes?: Array<string>)

    //Includes (`['user.role']`) is not required but if needed, please refer to Accounts Management API for available includes
    const user = await SDK.rest.client.login('email', 'password', ['user.role']);
  • logout()

    await SDK.rest.client.logout();
  • autoRenewToken(): boolean

    //Called at root of application in order to start auto token renewal counter, otherwise tokenExpired() will be called when the token has expired
    const success = SDK.rest.client.autoRenewToken();

Endpoints

  • For authentication endpoints please refer to authentication section.
  • For any other endpoints please refer to Accounts Management API https://orbis.dev/api/set/7/account-management-and-onboarding

Endpoint structure

Besides authentication all endpoints have the same structure.

Accesss

To call an endpoint you must use the SDK.rest object and then add the endpoint name.

  • / becomes a .
  • - is removed and word is camel cased
//POST {{domain}}/api/applications/get-application-types
SDK.rest.applications.getApplicationTypes();

//POST {{domain}}/api/applications/submit
SDK.rest.applications.submit();
Parameters endpoint(data?: object, config?: IRequestConfig ) => Promise<any>
  • data optional is anything that is required by Accounts Management API
{
    with: [''], //Anything that your client needs
    user_id: 1 //Or anything else required for given endpoint
}
  • config optional can be used to override defaults
{
    method?: string; //Default: 'POST'
    urlQuery?: string | Array<string>; //Default: ''
    params?: object; //Default {}
    headers?: object; //Default { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' }
}
Return
interface Response {
    data: any,
    status: number | null,
    success: boolean,
    messages: { [key: string]: Array<string> },
    error: {} | null
}