|
1 | 1 | /* eslint-disable no-await-in-loop */ |
2 | 2 | const { SalesForceClient } = require('../salesForceClient'); |
3 | 3 | const { getCredentials, refreshToken } = require('../helpers/oauth2Helper'); |
| 4 | +const { REFRESH_TOKEN_RETRIES } = require('../common.js').globalConsts; |
4 | 5 |
|
5 | 6 | let client; |
6 | 7 |
|
7 | 8 | exports.callJSForceMethod = async function callJSForceMethod(configuration, method, options) { |
8 | | - this.logger.trace('Incoming configuration: %j', configuration); |
| 9 | + this.logger.info('Preparing SalesForce Client...'); |
9 | 10 | let accessToken; |
10 | 11 | let instanceUrl; |
11 | 12 | const { secretId } = configuration; |
12 | 13 | if (secretId) { |
| 14 | + this.logger.info('Fetching credentials by secretId'); |
13 | 15 | const credentials = await getCredentials(this, secretId); |
14 | | - this.logger.trace('Fetched credentials: %j', credentials); |
15 | 16 | accessToken = credentials.access_token; |
16 | 17 | instanceUrl = credentials.instance_url; |
17 | 18 | } else { |
| 19 | + this.logger.info('Fetching credentials from configuration'); |
18 | 20 | accessToken = configuration.oauth.access_token; |
19 | 21 | instanceUrl = configuration.oauth.instance_url; |
20 | 22 | } |
21 | 23 | let result; |
22 | 24 | let isSuccess = false; |
23 | | - let iteration = 3; |
| 25 | + let iteration = REFRESH_TOKEN_RETRIES; |
24 | 26 | do { |
25 | 27 | iteration -= 1; |
26 | 28 | try { |
27 | | - this.logger.info('Iteration: %s', iteration); |
| 29 | + this.logger.info('Iteration: %s', REFRESH_TOKEN_RETRIES - iteration); |
28 | 30 | const cfg = { |
29 | 31 | ...configuration, |
30 | 32 | access_token: accessToken, |
31 | 33 | instance_url: instanceUrl, |
32 | 34 | }; |
33 | 35 | if (!client || Object.entries(client.configuration).toString() !== Object.entries(cfg).toString()) { |
34 | | - this.logger.info('Try to create connection', iteration); |
| 36 | + this.logger.info('Try to create SalesForce Client', REFRESH_TOKEN_RETRIES - iteration); |
| 37 | + this.logger.trace('Creating SalesForce Client with configuration: %j', cfg); |
35 | 38 | client = new SalesForceClient(this, cfg); |
36 | | - this.logger.info('Connection is created'); |
| 39 | + this.logger.info('SalesForce Client is created'); |
37 | 40 | } |
38 | | - this.logger.info('Trying to call method %s with options: %j', method, options); |
| 41 | + this.logger.info('Trying to call method %s', method); |
| 42 | + this.logger.debug('Trying to call method %s with options: %j', method, options); |
39 | 43 | result = await client[method](options); |
40 | | - this.logger.trace('Execution result: %j', result); |
| 44 | + this.logger.debug('Execution result: %j', result); |
41 | 45 | isSuccess = true; |
42 | 46 | this.logger.info('Method is executed successfully'); |
43 | 47 | break; |
|
0 commit comments