Skip to content

Commit f3f3e17

Browse files
author
Olha Virolainen
authored
streamPlatformEvents.js use platform secrets (#169)
* streamPlatformEvents.js use platform secrets * Add retry faceless (#171) * add await to emitter according #149
1 parent 24b3d07 commit f3f3e17

File tree

13 files changed

+255
-449
lines changed

13 files changed

+255
-449
lines changed

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,6 @@ This trigger will subscribe for any platform Event using Salesforce streaming AP
120120
![Screenshot from 2019-03-11 11-51-10](https://user-images.githubusercontent.com/13310949/54114889-1088e900-43f4-11e9-8b49-3a8113b6577d.png)
121121

122122
You can find more detail information in the [Platform Events Intro Documentation](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_intro.htm).
123-
#### Environment Variables
124-
125-
1. `SALESFORCE_API_VERSION` - API version for not deprecated actions and triggers e.g(46.0), default value 45.0
126-
127-
2. `LOG_LEVEL` - `trace` | `debug` | `info` | `warning` | `error` controls logger level
128123

129124
#### Limitations:
130125
At the moment this trigger can be used only for **"Realtime"** flows.

lib/actions/deleteObject.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ module.exports.process = async function process(message, configuration) {
9090
} else {
9191
if (results.length === 0) {
9292
this.logger.info('No objects are found');
93-
return this.emit('data', messages.newEmptyMessage());
93+
return messages.newEmptyMessage();
9494
}
9595
const err = new Error('More than one object found, can only delete 1');
9696
this.logger.error(err);
97-
return this.emit('error', err);
97+
throw err;
9898
}
9999
}
100100
this.logger.debug(`Preparing to delete a ${configuration.sobject} object...`);

lib/actions/lookupObject.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,12 @@ module.exports.process = async function processAction(message, configuration) {
6767

6868
if (!lookupValue) {
6969
if (allowCriteriaToBeOmitted) {
70-
this.emit('data', messages.newMessageWithBody({}));
70+
await this.emit('data', messages.newMessageWithBody({}));
7171
return;
7272
}
7373
const err = new Error('No unique criteria provided');
7474
this.logger.error(err);
75-
this.emit('error', err);
76-
return;
75+
throw err;
7776
}
7877

7978
const meta = await callJSForceMethod.call(this, configuration, 'describe');
@@ -88,8 +87,8 @@ module.exports.process = async function processAction(message, configuration) {
8887
if (lookupCache.hasKey(queryKey)) {
8988
this.logger.info('Cached response found!');
9089
const response = lookupCache.getResponse(queryKey);
91-
// eslint-disable-next-line consistent-return
92-
return this.emit('data', messages.newMessageWithBody(response));
90+
await this.emit('data', messages.newMessageWithBody(response));
91+
return;
9392
}
9493

9594
// the query for the object and all its linked parent objects
@@ -107,11 +106,11 @@ module.exports.process = async function processAction(message, configuration) {
107106
if (records.length === 0) {
108107
if (allowZeroResults) {
109108
lookupCache.addRequestResponsePair(queryKey, {});
110-
this.emit('data', messages.newMessageWithBody({}));
109+
await this.emit('data', messages.newMessageWithBody({}));
111110
} else {
112111
const err = new Error('No objects found');
113112
this.logger.error(err);
114-
this.emit('error', err);
113+
throw (err);
115114
}
116115
} else if (records.length === 1) {
117116
try {
@@ -126,13 +125,14 @@ module.exports.process = async function processAction(message, configuration) {
126125

127126
lookupCache.addRequestResponsePair(queryKey, records[0]);
128127
this.logger.debug('Emitting record');
129-
this.emit('data', outputMessage);
128+
await this.emit('data', outputMessage);
130129
} catch (err) {
131-
this.emit('error', err);
130+
this.logger.error('Lookup Object error occurred');
131+
throw (err);
132132
}
133133
} else {
134134
const err = new Error('More than one object found');
135135
this.logger.error(err);
136-
this.emit('error', err);
136+
throw (err);
137137
}
138138
};

lib/helpers/attachment.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const requestPromise = require('request-promise');
66
const client = require('elasticio-rest-node')();
77

88
const { callJSForceMethod } = require('./wrapper');
9-
const { getCredentials } = require('./oauth2Helper');
9+
const { getSecret } = require('../util');
1010

1111
async function downloadFile(url, headers) {
1212
const optsDownload = {
@@ -71,7 +71,7 @@ exports.getAttachment = async function getAttachment(configuration, objectConten
7171
const binDataUrl = objectContent[binField.name];
7272
if (!binDataUrl) return;
7373

74-
const credentials = await getCredentials(emitter, configuration.secretId);
74+
const { credentials } = await getSecret(emitter, configuration.secretId);
7575
const data = await downloadFile(credentials.undefined_params.instance_url + binDataUrl, {
7676
Authorization: `Bearer ${credentials.accessToken}`,
7777
});

lib/helpers/metaLoader.js

Lines changed: 0 additions & 282 deletions
This file was deleted.

0 commit comments

Comments
 (0)