Skip to content

Commit 37e6a2d

Browse files
author
Olha Virolainen
authored
Update sailor version to 2.6.17 (#3)
Update sailor version to 2.6.17
1 parent bfaf482 commit 37e6a2d

17 files changed

+160
-37
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.1 (October 23, 2020)
2+
3+
* Update sailor version to 2.6.17
4+
15
## 2.0.0 (October 2, 2020)
26

37
* First commit of v2 branch. See https://github.com/elasticio/salesforce-component for the v1 component version details

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![CircleCI](https://circleci.com/gh/elasticio/salesforce-component.svg)](https://circleci.com/gh/elasticio/salesforce-component)
1+
[![CircleCI](https://circleci.com/gh/elasticio/salesforce-component-v2.svg?style=svg&circle-token=4407ac16eb7e472a4533a176ca180c2c89d41777)](https://circleci.com/gh/elasticio/salesforce-component-v2)
22
# Salesforce Component
33
## Table of Contents
44

lib/actions/lookupObject.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ module.exports.process = async function processAction(message, configuration) {
8383

8484
lookupCache.useCache(configuration.enableCacheUsage);
8585
const queryKey = lookupCache.generateKeyFromDataArray(configuration.sobject, whereCondition);
86-
this.logger.trace(`Current request key hash: "${queryKey}"`);
8786
if (lookupCache.hasKey(queryKey)) {
8887
this.logger.info('Cached response found!');
8988
const response = lookupCache.getResponse(queryKey);

lib/actions/lookupObjects.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ module.exports.process = async function processAction(message, configuration) {
188188
this.logger.debug(`Preparing to query ${configuration.sobject} objects...`);
189189
this.logger.debug('Building a wherePart...');
190190
const wherePart = await getWherePart.call(this, message, configuration);
191-
this.logger.trace('Where part: ', wherePart);
192191

193192
let limit;
194193
let offset;
@@ -217,7 +216,6 @@ module.exports.process = async function processAction(message, configuration) {
217216
lookupCache.useCache(configuration.enableCacheUsage);
218217
const queryKey = lookupCache.generateKeyFromDataArray(configuration.sobject, wherePart,
219218
offset, limit, configuration.includeDeleted);
220-
this.logger.trace(`Current request key hash: "${queryKey}"`);
221219
if (lookupCache.hasKey(queryKey)) {
222220
this.logger.info('Cached response found!');
223221
records = lookupCache.getResponse(queryKey);

lib/actions/query.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ exports.process = async function processAction(message, configuration) {
99
throw new Error('batchSize must be a number');
1010
}
1111
const { query } = message.body;
12-
this.logger.trace('Starting SOQL Select batchSize=%s query=%s', batchSize, query);
12+
this.logger.debug('Starting SOQL Select: batchSize=%s', batchSize);
1313
if (configuration.allowResultAsSet) {
1414
this.logger.info('Selected EmitAllHandler');
1515
const result = await callJSForceMethod.call(this, configuration, 'queryEmitAll', query);

lib/actions/upsert.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,22 @@ module.exports.process = async function upsertObject(message, configuration) {
3737
const { sobject } = configuration;
3838
if (message.body.Id) {
3939
configuration.lookupField = 'Id';
40-
this.logger.info('Upserting sobject=%s by internalId', sobject);
41-
this.logger.trace('Upserting sobject=%s by internalId=%s, data: %j', sobject, message.body.Id, message);
40+
this.logger.debug('Upserting sobject=%s by internalId', sobject);
41+
this.logger.trace('Upserting sobject=%s by internalId=%s', sobject, message.body.Id);
4242
await callJSForceMethod.call(this, configuration, 'sobjectUpdate', message);
4343
} else {
4444
if (!configuration.extIdField) {
4545
throw Error('Can not find internalId/externalId ids');
4646
}
4747
configuration.lookupField = configuration.extIdField;
48-
this.logger.info('Upserting sobject=%s by externalId', sobject);
49-
this.logger.trace('Upserting sobject=%s by externalId=%s, data: %j', sobject, configuration.extIdField, message);
48+
this.logger.debug('Upserting sobject=%s by externalId', sobject);
49+
this.logger.trace('Upserting sobject=%s by externalId=%s', sobject, configuration.extIdField);
5050
await callJSForceMethod.call(this, configuration, 'sobjectUpsert', message);
5151
}
5252

5353
const lookupResults = await callJSForceMethod.call(this, configuration, 'sobjectLookup', message);
5454
if (lookupResults.length === 1) {
55-
this.logger.info('sobject=%s was successfully upserted by %s', sobject, configuration.lookupField);
56-
this.logger.trace('sobject=%s was successfully upserted by %s=%s', sobject, configuration.lookupField, message.body[configuration.lookupField]);
55+
this.logger.debug('sobject=%s was successfully upserted by %s', sobject, configuration.lookupField);
5756
await this.emit('data', messages.newMessageWithBody(lookupResults[0]));
5857
return;
5958
}

lib/entry.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,19 @@ module.exports.process = async function process(message, configuration, snapshot
2525
snapshot = {
2626
previousLastModified: configuration.startTime || '1970-01-01T00:00:00.000Z',
2727
};
28-
this.logger.trace('Created snapshot: %j', snapshot);
2928
} else if (typeof snapshot === 'string') {
3029
// for backward compatibility
3130
snapshot = { previousLastModified: snapshot };
32-
this.logger.trace('Snapshot has been converted to: %j', snapshot);
31+
this.logger.debug('Snapshot has been converted');
3332
} else {
34-
this.logger.trace('Got snapshot: %j', snapshot);
33+
this.logger.debug('Snapshot received');
3534
}
3635
const { linkedObjects = [] } = configuration;
3736
const singlePagePerInterval = (configuration.singlePagePerInterval !== 'no');
3837
const maxTime = configuration.endTime ? ` AND LastModifiedDate <= ${configuration.endTime}` : '';
3938
let hasMorePages = true;
4039
let lastSeenTime = snapshot.previousLastModified;
41-
let maxFetch = configuration.maxFetch ? configuration.parseInt(configuration.maxFetch, 10) : 1000;
40+
let maxFetch = configuration.maxFetch ? parseInt(configuration.maxFetch, 10) : 1000;
4241

4342
if (configuration.sizeOfPollingPage) {
4443
this.logger.debug('Current sizeOfPollingPage=%s, maxFetch=%s', configuration.sizeOfPollingPage, maxFetch);
@@ -98,7 +97,7 @@ module.exports.process = async function process(message, configuration, snapshot
9897

9998
if (snapshot.previousLastModified !== lastSeenTime) {
10099
snapshot.previousLastModified = lastSeenTime;
101-
this.logger.trace('emitting new snapshot: %j', snapshot);
100+
this.logger.debug('emitting new snapshot...');
102101
await this.emit('snapshot', snapshot);
103102
}
104103
await this.emit('end');

lib/helpers/wrapper.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ exports.callJSForceMethod = async function callJSForceMethod(configuration, meth
2727
iteration -= 1;
2828
try {
2929
this.logger.debug('Iteration: %s', REFRESH_TOKEN_RETRIES - iteration);
30-
this.logger.trace('AccessToken = %s, Iteration: %s', accessToken, REFRESH_TOKEN_RETRIES - iteration);
3130
const cfg = {
3231
...configuration,
3332
access_token: accessToken,
@@ -44,15 +43,15 @@ exports.callJSForceMethod = async function callJSForceMethod(configuration, meth
4443
this.logger.debug('Method %s was successfully executed', method);
4544
break;
4645
} catch (e) {
47-
this.logger.error('Got error: ', e);
46+
this.logger.error('Got error %s', e.name || '');
4847
if (e.name === 'INVALID_SESSION_ID') {
4948
try {
5049
this.logger.debug('Session is expired, trying to refresh token...');
5150
accessToken = await refreshToken(this, secretId);
5251
this.logger.debug('Token is successfully refreshed');
5352
client = undefined;
5453
} catch (err) {
55-
this.logger.error(err, 'Failed to refresh token');
54+
this.logger.error('Failed to refresh token');
5655
}
5756
} else {
5857
throw e;

lib/salesForceClient.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ class SalesForceClient {
241241
})
242242
.execute({ autoFetch: true, maxFetch: limit });
243243
} catch (e) {
244-
this.logger.trace('Lookup query failed', e);
245244
this.logger.error('Lookup query failed');
246245
throw e;
247246
}

lib/triggers/query.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@ const { callJSForceMethod } = require('../helpers/wrapper');
44
exports.process = async function processTrigger(msg, configuration) {
55
this.logger.info('Starting Query trigger');
66
const { query, outputMethod = 'emitIndividually' } = configuration;
7-
const records = await callJSForceMethod.call(this, configuration, 'queryEmitAll', query);
7+
let records;
8+
try {
9+
records = await callJSForceMethod.call(this, configuration, 'queryEmitAll', query);
10+
} catch (e) {
11+
const errorMsg = e.message ? e.message.replace(query, '').replace(/\s+/g, ' ').trim() : 'Error occurred during query execution';
12+
const error = new Error(errorMsg);
13+
error.name = e.name || 'unknown error';
14+
this.logger.error(errorMsg);
15+
throw errorMsg;
16+
}
817
if (records.length === 0) {
918
await this.emit('data', messages.newEmptyMessage());
1019
} else if (outputMethod === 'emitAll') {

lib/triggers/streamPlatformEvents.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ async function processTrigger(msg, configuration) {
2222
const { credentials } = await getSecret(this, secretId);
2323
const accessToken = credentials.access_token;
2424
const instanceUrl = credentials.undefined_params.instance_url;
25-
this.logger.trace('AccessToken = %s', accessToken);
2625
this.logger.debug('Preparing SalesForce connection...');
2726
const connection = new jsforce.Connection({
2827
instanceUrl,
@@ -36,16 +35,15 @@ async function processTrigger(msg, configuration) {
3635
fayeClient = connection.streaming.createClient([
3736
new jsforce.StreamingExtension.Replay(topic, replayId),
3837
new jsforce.StreamingExtension.AuthFailure(async (err) => {
39-
this.logger.trace('AuthFailure: %j', err);
38+
this.logger.trace('AuthFailure error occurred');
4039
if (err.ext && err.ext.sfdc && err.ext.sfdc.failureReason && (err.ext.sfdc.failureReason === '401::Authentication invalid')) {
4140
try {
4241
this.logger.debug('Session is expired, trying to refresh token');
4342
await refreshToken(this, secretId);
4443
this.logger.debug('Token is successfully refreshed');
4544
} catch (error) {
46-
this.logger.trace('Refresh token error: %j', error);
47-
this.logger.error('Failed to fetch and/or refresh token');
48-
throw new Error('Failed to fetch and/or refresh token');
45+
this.logger.error('Failed to fetch refresh token');
46+
throw new Error('Failed to fetch refresh token');
4947
}
5048
fayeClient = undefined;
5149
this.logger.info('Lets call processTrigger one more time');
@@ -59,7 +57,6 @@ async function processTrigger(msg, configuration) {
5957

6058
fayeClient.subscribe(topic, async (message) => {
6159
this.logger.info('Incoming message found, going to emit...');
62-
this.logger.trace('Incoming Message: %j', message);
6360
await this.emit('data', messages.newMessageWithBody(message));
6461
})
6562
.then(() => {

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "salesforce-component-v2",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "elastic.io component that connects to Salesforce API (node.js) v2",
55
"main": "index.js",
66
"scripts": {
@@ -30,7 +30,7 @@
3030
"axios": "0.20.0",
3131
"elasticio-node": "0.0.9",
3232
"elasticio-rest-node": "1.2.6",
33-
"elasticio-sailor-nodejs": "2.6.14",
33+
"elasticio-sailor-nodejs": "2.6.17",
3434
"jsforce": "1.10.0",
3535
"mime-types": "2.1.27",
3636
"request": "2.88.2",

spec-integration/actions/lookupObject.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ describe('lookupObject', () => {
2929
configuration = {
3030
apiVersion: '45.0',
3131
oauth: {
32-
instance_url: 'https://na38.salesforce.com',
32+
undefined_params: {
33+
instance_url: process.env.INSTANCE_URL,
34+
},
3335
refresh_token: process.env.REFRESH_TOKEN,
3436
access_token: process.env.ACCESS_TOKEN,
3537
},
36-
prodEnv: 'login',
3738
sobject: 'Contact',
38-
_account: '5be195b7c99b61001068e1d0',
3939
lookupField: 'Id',
4040
typeOfSearch: 'uniqueFields',
4141
};
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* eslint-disable no-return-assign */
2+
const fs = require('fs');
3+
const sinon = require('sinon');
4+
const chai = require('chai');
5+
const logger = require('@elastic.io/component-logger')();
6+
const lookupObjects = require('../../lib/actions/lookupObjects');
7+
8+
const { expect } = chai;
9+
let configuration;
10+
let emitter;
11+
12+
describe('lookupObjects', () => {
13+
before(async () => {
14+
if (fs.existsSync('.env')) {
15+
// eslint-disable-next-line global-require
16+
require('dotenv').config();
17+
}
18+
configuration = {
19+
apiVersion: '45.0',
20+
oauth: {
21+
undefined_params: {
22+
instance_url: process.env.INSTANCE_URL,
23+
},
24+
refresh_token: process.env.REFRESH_TOKEN,
25+
access_token: process.env.ACCESS_TOKEN,
26+
},
27+
};
28+
29+
emitter = {
30+
emit: sinon.spy(),
31+
logger,
32+
};
33+
});
34+
35+
it('looks up Contact Objects', async () => {
36+
const cfg = {
37+
...configuration,
38+
sobject: 'Contact',
39+
termNumber: 1,
40+
outputMethod: 'emitIndividually',
41+
};
42+
const message = {
43+
body: {
44+
sTerm_1: {
45+
fieldName: 'extID',
46+
condition: '=',
47+
fieldValue: '22016aa0-2222-4048-4048-4e191e1a1638',
48+
},
49+
},
50+
};
51+
await lookupObjects.process.call(emitter, message, cfg);
52+
expect(emitter.emit.callCount).to.eql(1);
53+
expect(emitter.emit.args[0][0]).to.eql('data');
54+
expect(emitter.emit.args[0][1].body.results[0].attributes.type).to.eql(cfg.sobject);
55+
});
56+
});
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* eslint-disable no-return-assign */
2+
const fs = require('fs');
3+
const sinon = require('sinon');
4+
const logger = require('@elastic.io/component-logger')();
5+
const chaiAsPromised = require('chai-as-promised');
6+
const chai = require('chai');
7+
const queryTrigger = require('../../lib/triggers/query');
8+
9+
chai.use(chaiAsPromised);
10+
const { expect } = chai;
11+
12+
describe('queryTrigger', () => {
13+
let configuration;
14+
const snapshot = {};
15+
const message = {};
16+
17+
before(async () => {
18+
if (fs.existsSync('.env')) {
19+
// eslint-disable-next-line global-require
20+
require('dotenv').config();
21+
}
22+
23+
configuration = {
24+
apiVersion: '39.0',
25+
oauth: {
26+
undefined_params: {
27+
instance_url: process.env.INSTANCE_URL,
28+
},
29+
refresh_token: process.env.REFRESH_TOKEN,
30+
access_token: process.env.ACCESS_TOKEN,
31+
},
32+
};
33+
});
34+
35+
const emitter = {
36+
emit: sinon.spy(),
37+
logger,
38+
};
39+
40+
it('queryTrigger should succeed with valid query', async () => {
41+
const query = 'SELECT Id, Name FROM Contact LIMIT 2';
42+
const outputMethod = 'emitAll';
43+
const cfg = {
44+
...configuration,
45+
query,
46+
outputMethod,
47+
};
48+
await queryTrigger.process.call(emitter, message, cfg, snapshot);
49+
expect(emitter.emit.callCount).to.eql(1);
50+
expect(emitter.emit.args[0][0]).to.eql('data');
51+
expect(emitter.emit.args[0][1].body.records.length).to.eql(2);
52+
});
53+
54+
it('queryTrigger should fail with invalid query', async () => {
55+
const query = 'SELECT Id FROM Contact123';
56+
const cfg = {
57+
...configuration,
58+
query,
59+
};
60+
await expect(queryTrigger.process.call(emitter, message, cfg, snapshot)).be.rejectedWith('^ ERROR at Row:1:Column:16 '
61+
+ 'sObject type \'Contact123\' is not supported. '
62+
+ 'If you are attempting to use a custom object, be sure to append the \'__c\' after the entity name. '
63+
+ 'Please reference your WSDL or the describe call for the appropriate names.');
64+
});
65+
});

verifyCredentials.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const { callJSForceMethod } = require('./lib/helpers/wrapper');
22

33
module.exports = async function verify(credentials) {
44
try {
5-
this.logger.trace('Incoming credentials: %j', credentials);
65
this.logger.info('Going to make request describeGlobal() for verifying credentials...');
76
const result = await callJSForceMethod.call(this, credentials, 'describeGlobal');
87
this.logger.info('Credentials are valid, it was found sobjects count: %s', result.sobjects.length);

0 commit comments

Comments
 (0)