Comparing version 4.0.3 to 4.0.4
@@ -227,3 +227,3 @@ import assert from 'assert'; | ||
].reduce( | ||
(respBody, fn) => fn(requestBodyString, respBody, scope), | ||
(respBody, fn) => fn(requestBodyString, respBody, scope, req), | ||
interceptor.body | ||
@@ -230,0 +230,0 @@ )); |
import crypto from 'crypto'; | ||
import qs from 'querystring'; | ||
import get from 'lodash.get'; | ||
import { tryParseJson } from './util.js'; | ||
import xml2js from 'xml2js'; | ||
const parseRequestBody = (body) => Object.values(Object | ||
.entries(qs.parse(body)) | ||
.filter(([k, v]) => k.startsWith('SendMessageBatchRequestEntry.')) | ||
.sort((a, b) => a[0].localeCompare(b[0])) | ||
.map(([k, v]) => [k.split('.'), v]) | ||
.reduce((p, [k, v]) => { | ||
if (p[k[1]] === undefined) { | ||
Object.assign(p, { [k[1]]: {} }); | ||
} | ||
Object.assign(p[k[1]], { [k[2]]: v }); | ||
return p; | ||
}, {})); | ||
const parseResponseBody = (body) => { | ||
let parsed = null; | ||
xml2js.parseString(body, (err, result) => { | ||
parsed = result; | ||
}); | ||
return parsed; | ||
}; | ||
export default (requestBody, responseBody, scope) => { | ||
export default (requestBody, responseBody, scope, req) => { | ||
if ( | ||
!/^https:\/\/sqs\.[a-z0-9-]+\.amazonaws\.com:443$/.test(scope.basePath) | ||
|| !responseBody.startsWith('<?xml version="1.0"?><SendMessageBatchResponse')) { | ||
scope?.basePath !== 'https://sqs.us-west-2.amazonaws.com:443' | ||
|| req?.options?.headers?.['x-amz-target'] !== 'AmazonSQS.SendMessageBatch' | ||
) { | ||
return responseBody; | ||
} | ||
const responseBodyParsed = parseResponseBody(responseBody); | ||
const resultEntries = parseRequestBody(requestBody) | ||
.map(({ Id, MessageBody }, idx) => [ | ||
'<SendMessageBatchResultEntry>', | ||
`<Id>${Id}</Id>`, | ||
`<MessageId>${ | ||
get(responseBodyParsed, [ | ||
'SendMessageBatchResponse', | ||
'SendMessageBatchResult', | ||
0, | ||
'SendMessageBatchResultEntry', | ||
idx, | ||
'MessageId' | ||
], crypto.randomUUID()) | ||
}</MessageId>`, | ||
`<MD5OfMessageBody>${ | ||
crypto.createHash('md5').update(MessageBody).digest('hex') | ||
}</MD5OfMessageBody>`, | ||
'</SendMessageBatchResultEntry>' | ||
].join('')); | ||
return [ | ||
'<?xml version="1.0"?>', | ||
'<SendMessageBatchResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/">', | ||
'<SendMessageBatchResult>', | ||
...resultEntries, | ||
'</SendMessageBatchResult>', | ||
'<ResponseMetadata>', | ||
`<RequestId>${ | ||
get(responseBodyParsed, [ | ||
'SendMessageBatchResponse', | ||
'ResponseMetadata', | ||
0, | ||
'RequestId', | ||
0 | ||
], crypto.randomUUID()) | ||
}</RequestId>`, | ||
'</ResponseMetadata>', | ||
'</SendMessageBatchResponse>' | ||
].join(''); | ||
const requestJson = tryParseJson(requestBody); | ||
const responseJson = tryParseJson(responseBody); | ||
return { | ||
Successful: requestJson.Entries.map(({ Id, MessageBody }, idx) => ({ | ||
Id, | ||
MessageId: responseJson?.Successful?.[idx]?.MessageId || crypto.randomUUID(), | ||
MD5OfMessageBody: crypto.createHash('md5').update(MessageBody).digest('hex') | ||
})) | ||
}; | ||
}; |
{ | ||
"name": "node-tdd", | ||
"type": "module", | ||
"version": "4.0.3", | ||
"version": "4.0.4", | ||
"description": "Drop in extension for mocha to abstract commonly used test setups", | ||
@@ -44,3 +44,3 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@aws-sdk/client-sqs": "3.385.0", | ||
"@aws-sdk/client-sqs": "3.458.0", | ||
"@babel/core": "7.23.3", | ||
@@ -55,3 +55,3 @@ "@babel/eslint-parser": "7.23.3", | ||
"chai": "4.3.10", | ||
"eslint": "8.53.0", | ||
"eslint": "8.54.0", | ||
"eslint-config-airbnb-base": "15.0.0", | ||
@@ -85,3 +85,3 @@ "eslint-plugin-import": "2.29.0", | ||
"minimist": "1.2.8", | ||
"nock": "13.3.8", | ||
"nock": "13.4.0", | ||
"normalize-url": "2.0.1", | ||
@@ -91,5 +91,4 @@ "object-scan": "19.0.5", | ||
"timekeeper": "2.3.1", | ||
"tmp": "0.2.1", | ||
"xml2js": "0.6.2" | ||
"tmp": "0.2.1" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12
45532
1043
+ Addednock@13.4.0(transitive)
- Removedxml2js@0.6.2
- Removednock@13.3.8(transitive)
- Removedxml2js@0.6.2(transitive)
- Removedxmlbuilder@11.0.1(transitive)
Updatednock@13.4.0