7.0.7 • Published 7 months ago

@frollo/frollo-web-sdk v7.0.7

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
7 months ago

Frollo Web SDK

CircleCI npm bundle size npm

A JavaScript and TypeScript SDK for Frollo API

Note

For compatability with the different Frollo Server versions please use the web-sdk versions below:

v7.x.x -> Frollo Server v2.23
v4.x.x -> Frollo Server v2.21
v3.x.x -> Frollo Server v2.20
v2.x.x -> Frollo Server v2.20
v1.x.x -> Frollo Server v2.19
v0.2.x -> Frollo Server v2.18
v0.1.5 -> Frollo Server v2.17

Management API is supported from v3.x.x onwards.

Installation

npm i @frollo/frollo-web-sdk

or

yarn add @frollo/frollo-web-sdk

Note: For local development please refer to the general development readme.

Usage

Initialise the client by providing the api base url as a parameter.

import { FrolloSDK } from '@frollo/frollo-web-sdk'

FrolloSDK().init('api-base.url')

Once initialised and authorised (Cookie/Header), services will be available. Types can also be imported. E.g.

import { userService, UserDetailsResponse, UserAccountPayload } from '@frollo/frollo-web-sdk'

const { getUserDetails, updateUserAccount } = userService();

const userDetails: UserDetailsResponse = (await getUserDetails()).data;

const userAccountPayload: UserAccountPayload = {...}
await updateUserAccount(userAccountPayload);

Interceptors

Axios interceptors can be added by hooking onto the global FrolloClient after initialisation.

// Add a request interceptor
globalThis.FrolloClient.interceptors.request.use(
  (config: AxiosRequestConfig) => {
    // Do something before request is sent
    return config;
  },
  (error) => {
    // Do something with request error
    return Promise.reject(error);
  }
);

// Add a response interceptor
globalThis.FrolloClient.interceptors.response.use(
  (response: AxiosResponse) => {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    return response;
  },
  (error: AxiosError) => {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    return Promise.reject(error);
  }
);

If you need to remove an interceptor later you can.

const myInterceptor = globalThis.FrolloClient.interceptors.request.use(function () {/*...*/});
axios.interceptors.request.eject(myInterceptor);
7.0.7

7 months ago

7.0.6

7 months ago

7.0.5

7 months ago

7.0.0

10 months ago

7.0.4

9 months ago

7.0.3

10 months ago

7.0.2

10 months ago

7.0.1

10 months ago

6.0.1

11 months ago

6.0.2

11 months ago

5.0.3

1 year ago

5.0.2

1 year ago

6.0.0

12 months ago

5.0.1

1 year ago

5.0.0

1 year ago

4.0.1

1 year ago

3.0.2

1 year ago

4.0.0

1 year ago

2.0.7

1 year ago

2.0.6

1 year ago

3.0.1

1 year ago

3.0.0

1 year ago

2.0.5

1 year ago

2.0.4

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.0

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.1

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.0

2 years ago

0.1.4

2 years ago

0.1.5

2 years ago

0.1.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.3

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago