@itentialopensource/adapter-utils 5.3.9 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,22 @@
1
1
 
2
+ ## 5.4.0 [04-26-2024]
3
+
4
+ * changes to support changing scope and resource
5
+
6
+ Closes ADAPT-3342
7
+
8
+ See merge request itentialopensource/adapter-utils!292
9
+
10
+ ---
11
+
12
+ ## 5.3.10 [03-06-2024]
13
+
14
+ * Fix some security vulnerabilities
15
+
16
+ See merge request itentialopensource/adapter-utils!289
17
+
18
+ ---
19
+
2
20
  ## 5.3.9 [03-04-2024]
3
21
 
4
22
  * Resolve ADAPT-3296
@@ -58,6 +58,8 @@ let username = null;
58
58
  let password = null;
59
59
  let clientId = null;
60
60
  let clientSecret = null;
61
+ let scope = null;
62
+ let resource = null;
61
63
  let grantType = null;
62
64
  let staticToken = null;
63
65
  let tokenUserField = 'username';
@@ -416,10 +418,12 @@ function returnStub(request, entitySchema, callProperties) {
416
418
  if (reqBody && (!entitySchema || !entitySchema.requestDatatype
417
419
  || entitySchema.requestDatatype.toUpperCase() === 'JSON' || entitySchema.requestDatatype.toUpperCase() === 'URLENCODE')) {
418
420
  let reqBdObj = null;
419
- if (entitySchema && entitySchema.requestDatatype && entitySchema.requestDatatype.toUpperCase() === 'URLENCODE') {
420
- reqBdObj = querystring.parse(reqBody.trim());
421
- } else {
422
- reqBdObj = JSON.parse(reqBody.trim());
421
+ if (typeof reqBody === 'string') {
422
+ if (entitySchema && entitySchema.requestDatatype && entitySchema.requestDatatype.toUpperCase() === 'URLENCODE') {
423
+ reqBdObj = querystring.parse(reqBody.trim());
424
+ } else {
425
+ reqBdObj = JSON.parse(reqBody.trim());
426
+ }
423
427
  }
424
428
 
425
429
  specificResp = checkBodyData(uriPath, method, reqBdObj, mockresponses, entitySchema.responseDatatype);
@@ -687,7 +691,10 @@ function makeRequest(request, entitySchema, callProperties, startTrip, attempt,
687
691
  // add the data for each field into the form
688
692
  const mykeys = Object.keys(mybody);
689
693
  if (mykeys.length === 2 && mykeys[0] === 'file' && mykeys[1] === 'convertBase64ToBuffer') {
690
- const filePart = mybody[mykeys[0]].split(';');
694
+ let filePart = mybody[mykeys[0]];
695
+ if (typeof filePart === 'string') {
696
+ filePart = filePart.split(';');
697
+ }
691
698
  let fileName = null;
692
699
  // see if we have a filename that we should add to the formdata
693
700
  for (let p = 1; p < filePart.length; p += 1) {
@@ -710,11 +717,20 @@ function makeRequest(request, entitySchema, callProperties, startTrip, attempt,
710
717
  for (let k = 0; k < mykeys.length; k += 1) {
711
718
  if (mykeys[k] === 'file') {
712
719
  let fileVal = mybody[mykeys[k]];
713
- if (fileVal.indexOf('@') === 0) {
720
+ if ((typeof fileVal === 'string') && (fileVal.indexOf('@') === 0)) {
714
721
  // if there are multiple parts - first part is full path to file, other part can be name (starts with name=)
715
722
  const filePart = fileVal.split(';');
716
723
  let fileName = null;
717
- fileVal = fs.readFileSync(filePart[0].substring(1));
724
+
725
+ // get the path for the specific file
726
+ // const dataFile = path.join(__dirname, `/uploads/${filePart[0].substring(1)}`);
727
+ // const dataFile = path.join(__dirname, '/../uploads/filetoupload');
728
+ // Read the action from the file system
729
+ if (request.filePath) {
730
+ fileVal = fs.readFileSync(request.filePath);
731
+ } else {
732
+ fileVal = '';
733
+ }
718
734
 
719
735
  // see if we have a filename that we should add to the formdata
720
736
  for (let p = 1; p < filePart.length; p += 1) {
@@ -2069,6 +2085,12 @@ async function buildTokenRequest(reqPath, reqBody, callProperties, callback) {
2069
2085
  if (clientSecret) {
2070
2086
  creds.client_secret = clientSecret;
2071
2087
  }
2088
+ if (scope) {
2089
+ creds.scope = scope;
2090
+ }
2091
+ if (resource) {
2092
+ creds.resource = resource;
2093
+ }
2072
2094
  if (grantType) {
2073
2095
  creds.grant_type = grantType;
2074
2096
  }
@@ -2078,6 +2100,12 @@ async function buildTokenRequest(reqPath, reqBody, callProperties, callback) {
2078
2100
  if (callProperties && callProperties.authentication && callProperties.authentication.client_secret) {
2079
2101
  creds.client_secret = callProperties.authentication.client_secret;
2080
2102
  }
2103
+ if (callProperties && callProperties.authentication && callProperties.authentication.scope) {
2104
+ creds.scope = callProperties.authentication.scope;
2105
+ }
2106
+ if (callProperties && callProperties.authentication && callProperties.authentication.resource) {
2107
+ creds.resource = callProperties.authentication.resource;
2108
+ }
2081
2109
  if (callProperties && callProperties.authentication && callProperties.authentication.grant_type) {
2082
2110
  creds.grant_type = callProperties.authentication.grant_type;
2083
2111
  }
@@ -3972,6 +4000,16 @@ class ConnectorRest {
3972
4000
  clientSecret = props.authentication.client_secret;
3973
4001
  }
3974
4002
 
4003
+ // set the client secret (optional - default is null)
4004
+ if (typeof props.authentication.scope === 'string') {
4005
+ scope = props.authentication.scope;
4006
+ }
4007
+
4008
+ // set the client secret (optional - default is null)
4009
+ if (typeof props.authentication.resource === 'string') {
4010
+ resource = props.authentication.resource;
4011
+ }
4012
+
3975
4013
  // set the grant type (optional - default is null)
3976
4014
  if (typeof props.authentication.grant_type === 'string') {
3977
4015
  grantType = props.authentication.grant_type;
@@ -142,9 +142,40 @@ function handleRestRequest(request, entityId, entitySchema, callProperties, filt
142
142
  const origin = `${id}-restHandler-handleRestRequest`;
143
143
  log.trace(origin);
144
144
 
145
+ // copy the request so lint does not complain about update
146
+ const newReqObj = request;
147
+
148
+ // this is only something in Form data with files
149
+ if (entitySchema && entitySchema.requestDatatype && entitySchema.requestDatatype.toUpperCase() === 'FORM') {
150
+ // need to convert request.body back to JSON
151
+ let mybody = newReqObj.body;
152
+ if (typeof mybody === 'string') {
153
+ try {
154
+ mybody = JSON.parse(newReqObj.body);
155
+ } catch (ex) {
156
+ log.debug('Rest Handler can not parse Form Body');
157
+ }
158
+ }
159
+ // set the filePath into the request object
160
+ const mykeys = Object.keys(mybody);
161
+ for (let k = 0; k < mykeys.length; k += 1) {
162
+ if (mykeys[k] === 'file') {
163
+ const itemVal = mybody[mykeys[k]];
164
+ if ((typeof itemVal === 'string') && (itemVal.indexOf('@') === 0)) {
165
+ const fileVal = itemVal;
166
+ if (fileVal.indexOf('@') === 0) {
167
+ const filePart = fileVal.split(';');
168
+ newReqObj.filePath = filePart[0].substring(1);
169
+ }
170
+ }
171
+ break;
172
+ }
173
+ }
174
+ }
175
+
145
176
  try {
146
177
  // perform the request to get entity(ies)
147
- return connectorInst.performRequest(request, entitySchema, callProperties, (resObj, perror) => {
178
+ return connectorInst.performRequest(newReqObj, entitySchema, callProperties, (resObj, perror) => {
148
179
  if (perror) {
149
180
  let retError = null;
150
181
  const retErrorObj = perror;
@@ -219,13 +250,13 @@ function handleRestRequest(request, entityId, entitySchema, callProperties, filt
219
250
 
220
251
  if (entitySchema.responseObjects) {
221
252
  const responseKeys = entitySchema.responseObjects;
222
- const uriPath = request.origPath;
223
- const method = request.method.toUpperCase();
224
- const reqBody = request.body;
225
- const reqPath = request.path;
253
+ const uriPath = newReqObj.origPath;
254
+ const method = newReqObj.method.toUpperCase();
255
+ const reqBody = newReqObj.body;
256
+ const reqPath = newReqObj.path;
226
257
 
227
258
  // if there is a request body, see if there is something that matches a specific input
228
- if (reqBody && (!entitySchema || !entitySchema.requestDatatype
259
+ if (reqBody && (typeof reqBody === 'string') && (!entitySchema || !entitySchema.requestDatatype
229
260
  || entitySchema.requestDatatype.toUpperCase() === 'JSON' || entitySchema.requestDatatype.toUpperCase() === 'URLENCODE')) {
230
261
  let reqBdObj = null;
231
262
  if (entitySchema && entitySchema.requestDatatype && entitySchema.requestDatatype.toUpperCase() === 'URLENCODE') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itentialopensource/adapter-utils",
3
- "version": "5.3.9",
3
+ "version": "5.4.0",
4
4
  "description": "Itential Adapter Utility Libraries",
5
5
  "scripts": {
6
6
  "postinstall": "node utils/setup.js",
Binary file