Skip to content

Commit

Permalink
Add informational logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Karan Kanwar authored and Karan Kanwar committed Jul 19, 2023
1 parent 3cf4ccc commit a7e7c1c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@spresso-sdk/price_optimization",
"version": "2.1.0",
"version": "2.1.1",
"description": "Spresso Price Optimization SDK for Node",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
Expand Down
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const DEFAULT_SOCKET_COUNT = 128;

export interface ILogger {
error(message: string): void;
info?(message: string): void;
}

export type PricingRequest = {
Expand Down Expand Up @@ -130,6 +131,7 @@ class SpressoSDK {
return Promise.resolve(); // Current token is valid and non-expired, no need to refetch
}

this.logInfo('Authenticating Spresso API...');
return this.axiosInstance.request({
method: 'post',
url: '/identity/v1/public/token',
Expand All @@ -140,6 +142,7 @@ class SpressoSDK {
grant_type: 'client_credentials',
},
}).then(response => {
this.logInfo('Spresso Authentication Successful!');
const authResponse = (response.data as AuthResponse);
this.authToken = authResponse.access_token;
this.tokenExpiration = now + (authResponse.expires_in * 1000);
Expand All @@ -151,13 +154,15 @@ class SpressoSDK {
return Promise.resolve(); // Bot user agent list has already been fetched
}

this.logInfo('Fetch Bot user-agent list...');
return this.axiosInstance.request({
headers: {
'Authorization': this.authHeader()
},
method: 'get',
url: '/pim/v1/priceOptimizationOrgConfig',
}).then(response => {
this.logInfo('Bot user-agent list fetched!');
const userAgents = response.data.data.userAgentBlacklist.map((userAgent: UserAgentResponse) => {
return {
name: userAgent.name,
Expand Down Expand Up @@ -241,6 +246,12 @@ class SpressoSDK {
console.log(errMsg);
}
}

private logInfo(msg: string): void {
if (this.logger != undefined && this.logger.info != undefined) {
this.logger.info(msg);
}
}
}

export default SpressoSDK;

0 comments on commit a7e7c1c

Please sign in to comment.