0.1.0 • Published 4 years ago

@wykerd/osd-sdk v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

One Stop Domestic SDK

The Javascript SDK for OSD backend services

Installation

Install the module using your prevered node package manager. I'll use yarn in the examples below

yarn add https://github.com/Wykerd/osd-sdk.git

Usage

The SDK provides classes to interface with diffent OSD services. It is wrapped up into two classes, for clients and workers respectively

For clients use

import OSDClient from 'osd-sdk/client'

For workers use

import OSDWorker from 'osd-sdk/worker'

Authentication

The base class for all account type classes provide an OSDAuth object at the property authenticator

Use this object to authenticate with the auth service.

Authenticating

Signing in is done with the OSD.authenticator.signIn (id, password). Signing up is done simularly with the OSD.authenticator.signUp (id, password).

The id parameter is the username or email of the user and the password parameter is the plaintext passcode of the user.

Both methods return Promise<Promise<string>> which resolves to the JWT authorization token. You should however not store or use the token directly from here. Instead it is recommended to use an event listener to listen for changes in the auth state.

To listen for changes in auth state, there is two options:

  1. Using the authenticator object directly
    OSD.authenticator.onAuthStateChanged(user => /* do something */)
    which returns a unsubscribe function and calles the callback asynchrously with the user object.
  1. Using an event handler on the base class (like node events module)

    function handler (user) {
        /* Do something */
    }
    
    // Attach a listener
    OSD.addEventListener('auth', handler)
    
    // Remove / unsubscribe from listener
    OSD.removeEventListener('auth', handler);

You can check the authetication status with the OSD.authenticator.isAuthenticated method which returns a boolean true if authenticated. This method is usually not used directly.

When using the SDK all requests are automatically authorized after the user has logged in. Authentication is not required after session as a reset token is set to a http-only cookie which is used interally to get the JWT token again.

Client

The client has access to several OSD API endpoints. The SDK wraps them up nicely for use.

Creating a job request

One of the main functions of OSD's platform is the ability to filter for job candidates. The SDK makes the flow from filtering to finalizing a request easy.

Simply call OSDClient.jobRequest()

Support

The current npm build targets "> 0.2%, not dead" but you can clone the repo and change the .babelrc.json targets to earlier versions if you wish. See Contributing for build steps.

Contributing

Install the dev dependecies using

yarn install --dev

Build the modules using

yarn build

There is currently no test suite for the SDK, so test it yourself.

0.1.0

4 years ago