From a7e7c1cc6b319b6bd01aca99fdbe8ce9aedec25f Mon Sep 17 00:00:00 2001 From: Karan Kanwar Date: Wed, 19 Jul 2023 04:10:45 -0400 Subject: [PATCH] Add informational logging --- package-lock.json | 4 ++-- package.json | 2 +- src/index.ts | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3f379b1..fd1c617 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@spresso-sdk/price_optimization", - "version": "2.1.0", + "version": "2.1.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@spresso-sdk/price_optimization", - "version": "2.1.0", + "version": "2.1.1", "license": "MIT", "dependencies": { "axios": "^1.4.0" diff --git a/package.json b/package.json index 219a2a3..3d06c8a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.ts b/src/index.ts index 61eaea8..7449bf6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,7 @@ const DEFAULT_SOCKET_COUNT = 128; export interface ILogger { error(message: string): void; + info?(message: string): void; } export type PricingRequest = { @@ -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', @@ -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); @@ -151,6 +154,7 @@ 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() @@ -158,6 +162,7 @@ class SpressoSDK { 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, @@ -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; \ No newline at end of file