To install the @commarket/loyaltyplus
package, you can use npm or yarn:
npm install @commarket/loyaltyplus
yarn add @commarket/loyaltyplus
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.
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).