@fintechprimitives/fpapi
TypeScript icon, indicating that this package has built-in type declarations

0.1.18 • Public • Published

Fp API Sdk

  • SDK will have interfaces defined for all request object and api calls
    • ex. investor request, mf_purchase request etc
      • ex. for api call. Fp.Investor.create(), Fp.Investor.fetch(:id)
  • We cann't put type definition in the response as typescript currently doesn't supports it.
  • Developers who uses our interface can detect error if any during compilation itself.
  • SDK will return the following,
    • JSON data for 2xx responses
    • Throw error for non 2xx responses (WIP)

Some References:

  • https://github.com/microsoft/TypeScript/issues/3628

  • https://stackoverflow.com/questions/47218390/angular-4-httpclient-type-of-http-response-object-not-enforced-by-interface

    Library contents

    • Supports Authentication via PKCE flow using oidc-client-ts package.
    • Has wrapper built over FP apis

    Install instructions

    • install the package using any of the ways below
      1. using cli,
        • From terminal run
          npm i @fintechprimitives/fpapi
          

    Update Sdk

    • To pull the latest changes after pushing this branch to master,
      run `npm upgrade @fintechprimitives/fpapi`
    

    Usage

    1) Auth Service

    // create in the root component so that only one instance exists and pass it around using props.
    import { AuthService } from '@fintechprimitives/fpapi';
    const fpAuthService = new AuthService({
                                          authority: <URL>,      // identity provider url
                                          clientId: <client_id>, // client id associated
                                          redirectUri: <uri>,    // redirect uri for KC to call after authentication,
                                                                  // a route needs to be present to handle.
                                          postLogoutRedirectUri: <uri>, // redirect uri for KC to call after logout
                                        });
    

    2) FP-API's

    Basic Usage

    Need to intialise the config object with the base-url, then make calls to respective api's. Make sure you have a valid token before and recreate the client if the token is expired.

    The resources can be accessed via this instance.

    Every resource method returns a promise.

    const investorResp = await fpClient.investor().fetch(1);
    

    Error Handling

      import { fp } from '@fintechprimitives/fpapi';
    
      let options = {
        hostUrl: 'https://s.finprim.com/',
        token: '{{generated_token}}',
      };
    
      const fpClient = new fp(options);
    
      // using as  async / await
      try {
        const data = await fpClient.investor().fetch(663);
        console.log('data', data);
      } catch(e: any) {
        console.log('error', e);
      }
    
      // using as promises
      fpClient.investor().fetch(663)
      .then(data => {
        console.log(data);
      })
      .catch(e => console.log(e));
    
    • To test local use while developing, use src/testing.ts file
    • run $ npx ts-node testing.ts

Readme

Keywords

none

Package Sidebar

Install

npm i @fintechprimitives/fpapi

Weekly Downloads

4

Version

0.1.18

License

ISC

Unpacked Size

202 kB

Total Files

7

Last publish

Collaborators

  • fpsdkadmin