Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
6af899c
Added new functionality to put snapshot in message data into url tran…
Jun 25, 2021
72fd506
Added unit tests for new paging functionality, added check for missin…
Jun 29, 2021
d838ed3
In progress work on the component. Attachment tests still failing
Jul 15, 2021
fe8db9e
Changing testing back to fatal logging and commented out tests that a…
Jul 16, 2021
4d8a713
Added GitHub Actions to build/test image
Jul 16, 2021
75b4e34
Added Docker Hub repo path as a separate repo secret
Jul 16, 2021
de1a40d
Use newer version on node.js for github workflow
Jul 16, 2021
9a076d0
Fixed local path in test
Jul 16, 2021
1030493
Merge pull request #1 from blendededge/feature/paging
winklerj Jul 16, 2021
71fb0f4
Bump yarn from 1.7.0 to 1.22.0
dependabot[bot] Jul 16, 2021
45ec411
Merge pull request #2 from blendededge/dependabot/npm_and_yarn/yarn-1…
winklerj Jul 16, 2021
dc5b602
Update to REST component for saving received data
Jul 26, 2021
98135bc
Added received data to error message for cfg.dontThrowErrorFlg
Jul 30, 2021
bbacb80
Added savedReceivedData to README
Jul 30, 2021
654661a
Merge pull request #4 from blendededge/feature/error-update
kerriannercrawford Jul 30, 2021
7dc818d
Uncommented requestOptions
Jul 30, 2021
05aec17
Merge branch 'master' of https://github.com/blendededge/REST-API-comp…
Jul 30, 2021
f582fd4
Fixed linting issues and issue with the savedReceived data being adde…
Aug 2, 2021
b336114
Uncommented authorization header to fix broken unit test
Aug 2, 2021
f31e645
Merge pull request #5 from blendededge/feature/fix-linting
winklerj Aug 2, 2021
c8aa276
Added jsonataResponseValidator configuration to rebound/delay a reque…
Aug 3, 2021
2cbefc4
Merge pull request #6 from blendededge/feature/rebound-config
winklerj Aug 3, 2021
cddebc1
Added ability to configure which error status codes cause a rebound. …
Aug 3, 2021
fdfad15
Merge pull request #7 from blendededge/feature/rebound-config
winklerj Aug 3, 2021
c2f111d
Fixed the output for the error message
Aug 4, 2021
dddbf78
Merge pull request #8 from blendededge/feature/fix-error-message
kerriannercrawford Aug 4, 2021
8ea3a54
Simplified code and added await to rebound end emit in line with othe…
Aug 5, 2021
a79094b
Refactored to use async await instead of promise. It will be easier t…
Aug 5, 2021
b4374f7
Refactored to prepare for looping through pages on GET request. Check…
Aug 5, 2021
2d1ff62
Added the ability to loop through pages within the component
Aug 6, 2021
6507df0
Updated readme for paging functionality
Aug 6, 2021
020c34d
Merge pull request #9 from blendededge/feature/paging-loop
winklerj Aug 6, 2021
a62be23
Add helper to extract secret credentials from the config object and p…
Aug 11, 2021
473cbab
Added unit test and fixed one issue
Aug 11, 2021
5e409e5
Merge pull request #10 from blendededge/feature/secret-access
winklerj Aug 11, 2021
6eb4c0e
Bump url-parse from 1.5.1 to 1.5.3
dependabot[bot] Aug 11, 2021
19cb8cb
Merge pull request #11 from blendededge/dependabot/npm_and_yarn/url-p…
winklerj Aug 11, 2021
502f517
Changed the assumption that the first page starts at 0 instead of 1. …
Aug 12, 2021
977f356
Merge pull request #12 from blendededge/feature/nextPage-init
winklerj Aug 12, 2021
1680941
Update to paging to allow post requests
Aug 24, 2021
02b87e8
Update to POST url
Aug 24, 2021
4d0aec2
Added request body to test
Aug 24, 2021
f59c614
Merge pull request #13 from blendededge/feature/paging-update-request…
kerriannercrawford Aug 24, 2021
2387a70
Bump axios from 0.21.1 to 0.21.2
dependabot[bot] Sep 17, 2021
ec1a4dc
Merge pull request #14 from blendededge/dependabot/npm_and_yarn/axios…
winklerj Sep 17, 2021
3423165
Merge branch 'openintegrationhub:master' into master
winklerj Sep 17, 2021
7edbda7
Fixed bug where end event emitted after each page instead of when don…
Sep 22, 2021
0268a64
Merge pull request #15 from blendededge/bugfix/snapshot-end-emit
winklerj Sep 22, 2021
d90123a
Updated dependencies
Sep 22, 2021
9aa06ee
Merge pull request #16 from blendededge/bugfix/snapshot-end-emit
winklerj Sep 22, 2021
7710191
Update master.yml
winklerj Oct 4, 2021
e29cb28
Merge pull request #17 from blendededge/workflow-patch-1
winklerj Oct 4, 2021
29bac3d
Update utils.js
winklerj Oct 7, 2021
e693b6f
Merge pull request #18 from blendededge/winklerj-patch-1
winklerj Oct 7, 2021
d6d9a4c
Switch docker build from npm to yarn to reflect lock file, fixed issu…
Oct 7, 2021
e9ccfdd
Merge pull request #19 from blendededge/bugfix/ferryman-version
winklerj Oct 7, 2021
486827d
Reverted changes to master.yml to see if that caused the docker image…
Oct 7, 2021
ff4ee77
Merge pull request #20 from blendededge/bugfix/ferryman-version
winklerj Oct 7, 2021
cc659f9
Removed build cache to fix wrong ferryman library somehow being included
Oct 8, 2021
308f4d5
Merge pull request #21 from blendededge/bugfix/ferryman-version
winklerj Oct 8, 2021
118a331
Update master.yml
winklerj Oct 8, 2021
a5c33e9
Switched ferryman version definition from caret to tilde since versio…
Oct 8, 2021
6e79c24
Merge pull request #22 from blendededge/bugfix/ferryman-version
winklerj Oct 8, 2021
f0efa72
Update master.yml
winklerj Oct 12, 2021
5283f97
Merge pull request #23 from blendededge/build-patch-1
winklerj Oct 12, 2021
dceeada
Update package.json
winklerj Oct 12, 2021
c2d28d2
Update package.json
winklerj Oct 12, 2021
01c9b6e
Merge pull request #24 from blendededge/ferryman-latest-patch-1
winklerj Oct 12, 2021
4c13628
Created separate GitHub Action workflow for tags. It will now ignore …
Oct 12, 2021
351cf59
Merge pull request #25 from blendededge/auto-version
winklerj Oct 13, 2021
110aad8
added snapshot to process method
kerriannercrawford Oct 16, 2021
031954d
Merge pull request #26 from blendededge/add-snapshot
kerriannercrawford Oct 18, 2021
e764ed8
update axios and specify multiple ferryman versions
BirdHighway Nov 8, 2021
50f4f6f
conditional logic for ferryman version
BirdHighway Nov 8, 2021
65999f5
set entrypoint to shell start script
BirdHighway Nov 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added jsonataResponseValidator configuration to rebound/delay a reque…
…st and requeue it to the component after that delay period has passed.
  • Loading branch information
Robb Winkle committed Aug 3, 2021
commit c8aa2764f23b8e7f07aa2509667fca159bf7fd00
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ _Numbers show: (1) The URL and method of the REST API resource, (2) the HTTP cal
The `Call Count` value by default is 1. If you want to use another value, please set the `Call Count` field.
Notice: See [Known Limitations](#known-limitations) about `Delay` value.
- `Call Count` - the field should be used only in pair with `Delay`, default to 1.
- `jsonataResponseValidator` - This works in coordination with the `enableRebound` configuration to throw a status code 429. When this JSONata configuration is present and `enableRebound` set to `true`, it is assumed the JSONata will resolve to a boolean. If the boolean is false the incoming component message will be requeued and tried again. Otherwise the response will be processed as it normally would.
- `Request timeout` - Timeout period in milliseconds (1-1140000) while component waiting for server response, also can be configured with REQUEST_TIMEOUT environment variable if configuration field is not provided. Defaults to 100000 (100 sec).

Notice: Specified for component REQUEST_TIMEOUT enviroment variable would be overwritten by specified value of Request timeout, default value would be also overwritten
Expand Down
83 changes: 46 additions & 37 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ module.exports.processMethod = async function (msg, cfg, snapshot) {
msg.data.oihsnapshot = snapshot;
}

const { jsonataResponseValidator } = cfg;
const config = cfg.reader;

if (!config.url) {
Expand Down Expand Up @@ -128,13 +129,13 @@ module.exports.processMethod = async function (msg, cfg, snapshot) {
headers: {
Authorization: `Bearer ${token}`,
},
data: {
name: msg.data.name,
first_name: msg.data.first_name,
last_name: msg.data.name,
phone: msg.data.phone,
email: msg.data.email,
},
// data: {
// name: msg.data.name,
// first_name: msg.data.first_name,
// last_name: msg.data.name,
// phone: msg.data.phone,
// email: msg.data.email,
// },
};

const returnObject = {
Expand Down Expand Up @@ -429,40 +430,48 @@ module.exports.processMethod = async function (msg, cfg, snapshot) {
const contType = response.headers['content-type'];

emitter.logger.debug('Response content type: %o', contType);
if (contType) {
if (contType.includes('json') && !contType.includes('jsonl')) {
const data = await Promise.resolve(response.data);
emitter.logger.info('HTTP Response body1: %o', data);
return data;
if (!contType || (contType && contType.includes('json') && !contType.includes('jsonl'))) {
const data = await Promise.resolve(response.data);
emitter.logger.info('HTTP Response body1: %o', data);
if (jsonataResponseValidator) {
const valid = transform(data, { customMapping: jsonataResponseValidator });
emitter.logger.debug(`jsonataResponseValidator config is ${jsonataResponseValidator} and evaluates to ${valid}`);
if (!valid) {
// Throw error to, if enabled, force a rebound of this component
const err = new Error('JSONata validation against response failed and request should be retried in rebound queue');
err.response = { status: 429 };
return Promise.reject(err);
}
}
// TODO: implement later and add unit tests for XML file
// if (contType.includes('xml')) {
// emitter.logger.info('Trying to parse response as XML');
// const parseOptions = {
// trim: false,
// normalize: false,
// explicitArray: false,
// normalizeTags: false,
// attrkey: '_attr',
// tagNameProcessors: [
// (name) => name.replace(':', '-'),
// ],
// };
// return xml2js(response.body, parseOptions)
// .then((result) => {
// emitter.logger.info('Response successfully parsed');
// return result;
// });
// }
if (contType.includes('image') || contType.includes('msword')
return data;
}
// TODO: implement later and add unit tests for XML file
// if (contType.includes('xml')) {
// emitter.logger.info('Trying to parse response as XML');
// const parseOptions = {
// trim: false,
// normalize: false,
// explicitArray: false,
// normalizeTags: false,
// attrkey: '_attr',
// tagNameProcessors: [
// (name) => name.replace(':', '-'),
// ],
// };
// return xml2js(response.body, parseOptions)
// .then((result) => {
// emitter.logger.info('Response successfully parsed');
// return result;
// });
// }
if (contType.includes('image') || contType.includes('msword')
|| contType.includes('msexcel') || contType.includes('pdf')
|| contType.includes('csv') || contType.includes('octet-stream')
|| contType.includes('binary') || contType.includes('jsonl')) {
const attachmentProcessor = new AttachmentProcessor(emitter, null, cfg.attachmentServiceUrl);
const attachment = await attachmentProcessor.uploadAttachment(response.data, contType);
emitter.logger.info('Binary data successfully saved to attachments');
return attachment;
}
const attachmentProcessor = new AttachmentProcessor(emitter, null, cfg.attachmentServiceUrl);
const attachment = await attachmentProcessor.uploadAttachment(response.data, contType);
emitter.logger.info('Binary data successfully saved to attachments');
return attachment;
}
emitter.logger.info('Unknown content-type. Trying to parse as JSON');
return Promise.resolve(response.data);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "This is the rest api component for the OIH",
"main": "node_modules/@openintegrationhub/ferryman/runGlobal.js",
"scripts": {
"test": "LOG_LEVEL=fatal mocha test --recursive --timeout 50000"
"test": "LOG_LEVEL=fatal mocha test --recursive --timeout 50000",
"test:debug": "LOG_LEVEL=trace DEBUG=nock.* mocha test --recursive --timeout 50000"
},
"repository": {
"type": "git",
Expand Down
35 changes: 35 additions & 0 deletions test/httpRequestAction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,41 @@ describe('httpRequest action', () => {
'Request failed with status code 408',
);
});

it('jsonata response validator false && enableRebound true', async () => {
const method = 'POST';
const msg = {
data: {
url: 'http://example.com',
},
};

const cfg = {
enableRebound: true,
jsonataResponseValidator: 'data.result',
reader: {
url: '$$.data.url',
method,
},
auth: {},
};

const responseMessage = {
data: { result: false },
};

nock(transform(msg, { customMapping: cfg.reader.url }))
.intercept('/', method)
.delay(20 + Math.random() * 200)
.reply((uri, requestBody) => [200, responseMessage]);


await processAction.call(emitter, msg, cfg);
expect(emitter.emit.withArgs('rebound').callCount).to.be.equal(1);
expect(emitter.emit.withArgs('rebound').args[0][1]).to.be.equal(
'JSONata validation against response failed and request should be retried in rebound queue',
);
});
});

describe('when some args are wrong', () => {
Expand Down