test-ow-js-sdk
TypeScript icon, indicating that this package has built-in type declarations

1.4.1 • Public • Published

OW-JS-SDK

Installation

OW-JS-SDK requires npm v8+ and Node.js v14 to run.

# Using Yarn:
yarn add ow-js-sdk

# Or, using NPM:
npm install ow-js-sdk

Usage

First of all, it`s necessary to initialize the sdk with OW API base address in order to use its methods.

import * as OW from ow-js-sdk;

OW.initialize('https://ws.dev.overdrive.asia/');

# ...and then you can use the methods you need as it`s shown below

const signOut = async () => {
    return await OW.authn.signOut().run();
}

Methods

Authentication:
Devices:
Messages:

signIn

Performs a sign-in step. It accepts an object as a parameter with a required field "petition". It's an object with a "credentials" field - an array of objects. The response contains the "resolution" object. If credentials fail or are insufficient there is a "challenge" object in the resolution that contains errors and required credential type. If there are sessionId or challengeNo fields in the challenge object, it`s required to use them when trying to sign-in after a failed attempt. Once sign-in succeeded, the client session is established and resolution does not contain a challenge object and may contain verification token required for some sensitive operations.

import * as OW from ow-js-sdk;

const signInPayload = {
    petition: {
        credentials: [
            { credentialType: 'loginName', value: 'your@loign.name' },
            { credentialType: 'password', value: 'your password' }
        ]
    }
}

const signIn = async (signInPayload) => {
    try {
        const { resolution } = await OW.authn.signIn(petition).run();
        
        if (resolution?.challenge) {
            throw new Error(resolution.challenge.error);
        }
        
         # here functionality to handle response goes;
    } catch (error) {
        console.log(error);
    }
}

sessionId and challengeNo should be used in a petition as shown below:

const signInPayload = {
    petition: {
        sessionId: 'some session id',
        credentials: [
            { credentialType: 'loginName', value: 'your@loign.name', challengeNo: 1 },
            { credentialType: 'password', value: 'your password', challengeNo: 1 }
        ]
    }
}

resendSignIn

Requests to re-generate previously dispatched re-sendable sign-in challenge. It`s possible to re-generate only those challenges that have field "resendable" equal to true.

const resendSignIn = async (challengeNo) => {
    try {
        const { challenge } = await OW.authn.resendSignIn(challengeNo).run();
        console.log(challenge);
    } catch (error) {
        console.log(error);
    }
}

verify

The method is similar to sign-in request but it does not affect session authentication status. It should be used to re-generate expired verification token which is required for some sensitive operations.

const payload = {
    petition: {
        credentials: [
            { credentialType: 'loginName', value: 'your@loign.name' },
            { credentialType: 'password', value: 'your password' }
        ]
    }
}

const verify = async (payload) => {
    try {
        const { resolution } = await OW.authn.verify(petition).run();
        console.log(resolution);
    } catch (error) {
        console.log(error);
    }
}

resendVerification

Requests to re-generate previously dispatched re-sendable verification challenge.

const resendVerification = async (challengeNo) => {
    try {
        const { challenge } = await OW.authn.resendVerification(challengeNo).run();
        console.log(challenge);
    } catch (error) {
        console.log(error);
    }
}

generateSignInToken

Generates token that can be used as a credential to sign in.

const generateSignInToken = async () => {
    try {
        const { token } = await OW.authn.generateSignInToken().run();
        console.log(token);
    } catch (error) {
        console.log(error);
    }
}

renewToken

Refreshes the current token by generating a new one.

const renewToken = async (currentToken) => {
    try {
        const { token } = await OW.authn.renewToken(currentToken).run();
        console.log(token);
    } catch (error) {
        console.log(error);
    }
}

removeToken

Removes current token.

const removeToken = async (currentToken) => {
    try {
        await OW.authn.removeToken(currentToken).run();
    } catch (error) {
        console.log(error);
    }
}

inspect

Re-establishes authentication context of the current session on behalf of another user. The current user must have privilege to access context of another user. The request requires a valid verification token.

const payload = {
    inspectionRequest: {
        loginName: 'your@loign.name'
    }
}

const inspect = async (payload) => {
    try {
        const { ack } = await OW.authn.inspect(payload).run();
        console.log(ack);
    } catch (error) {
        console.log(error);
    }
}

signOut

Ends current session.

const signOut = async () => {
    try {
        await OW.authn.signOut().run();
    } catch (error) {
        console.log(error);
    }
}

load

Retrieves user`s devices.

const getUserDevices = async () => {
    try {
        const { devices } = await OW.device.load().run();
    } catch (error) {
        console.log(error);
    }
}

loadFields

Retrieves message fields' meta-data. The data returned describe fields and its values that can be presented in a device`s message.

const getMessageMetadata = async () => {
    try {
        const { messageFields } = await OW.message.loadFields().run();
    } catch (error) {
        console.log(error);
    }
}

latest

Retrieves the latest device's message.

const getDeviceLatestMessage = async (deviceUri) => {
    try {
        const { messageDetails } = await OW.message.latest(deviceUri).run();
    } catch (error) {
        console.log(error);
    }
}

Readme

Keywords

none

Package Sidebar

Install

npm i test-ow-js-sdk

Weekly Downloads

2

Version

1.4.1

License

none

Unpacked Size

185 kB

Total Files

13

Last publish

Collaborators

  • anviltest