0.1.1 • Published 1 year ago

hurdle-interceptor v0.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Hurdle Interceptor

Hurdle -

It is any form of login mechanism(for eg.Google Oauth, MPIN, OTP,etc) , this will usually be invoked when any API throws the hurdle error code(428). The Client will receive the response from its backend with status code 428 along with the details of the list of hurdles that need to be manifested.

The Interceptor -

This will be an NPM module The interceptor will cache the initial original request from which the hurdle flow was initially started. It will require the client to send the axios instance and callback Method for UI rendering and instantiate CreateHurdleInterceptor like below in its request.js or similar file. The interceptor will then pause the execution of the request until the callBack Promise is resolved and if the validation is successful, the interceptor will replay the original request stored in its Cache and send its success response and finally then will clean the cache.

Installation

npm install @phonepe/hurdle-interceptor

Note: Please make sure your .npmrc is pointing to the internal npm repository. For more details please reach out to @web-dev

Usage For Client :-

import axios from 'axios';
import { createHurdleInterceptor } from 'hurdle-interceptor';
import renderHurdle from '../renderHurdle';

const request = axios.create();

// the client will need to instantiate this function in its request.js file
createHurdleInterceptor(request, renderHurdle);

export default request;

The client’s callback function(renderHurdle in this case) will be invoked inside the interceptor that needs to render the UI by understanding the response and call the sentinel server for its validation.

The Flow diagram is as follows:

flow_diag

0.1.1

1 year ago

0.1.0

1 year ago