@commarket/loyaltyplus
v1.0.56
Published
To install the `@commarket/loyaltyplus` package, you can use npm or yarn:
Downloads
1,821
Readme
LoyaltyPlus Library
Installation
To install the @commarket/loyaltyplus
package, you can use npm or yarn:
Using npm
npm install @commarket/loyaltyplus
Using yarn
yarn add @commarket/loyaltyplus
Methods
configureAPI Method
The configureAPI
method is responsible for setting up and configuring an Axios instance to interact with a loyalty API. This method handles the following tasks:
- Resolves the base URL for the API based on the provided environment.
- Sets a timeout for API requests.
- Configures request and response interceptors to log requests and responses.
- Handles token creation and renewal for authorization.
Usage
Importing the Method
First, import the configureAPI
method and the loyaltyApi
instance from the module:
const apiOptions: ApiOptions = {
environment: EnvironmentEnum.PRD,
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
timeout: 60000, //DEFAULT 6000
verbose: false //DEFAULT false
};
configureAPI(apiOptions).then(() => { // Now you can use the configured loyaltyApi instance to make requests loyaltyApi.get('/endpoint') .then(response => { console.log(response.data); }) .catch(error => { console.error('API call error:', error); }); });
For more detailed documentation, please refer to the official [LoyaltyPlus Documentation](https://example.com/docs).