Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions docs/connectionParameters.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@
<td>string</td>
<td>An optional value to override the instance key which is used for the caches of schemas, options, etc.</td>
</tr>
<tr>
<td>enableRequestIdHeader</td>
<td>boolean</td>
<td>Enable the request ID header for SOAP API calls</td>
</tr>
</tbody>
</table>

11 changes: 7 additions & 4 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ class Credentials {
* @property {number} timeout - Can be set to change the HTTP call timeout. Value is passed in ms.
* @property {string} cacheRootKey - "default" or "none" - determine the prefix to use for the keys in the caches of schemas, options, etc.
* @property {string} instanceKey - an optional value to override the instance key which is used for the caches of schemas, options, etc.
* @property {boolean} enableRequestIdHeader - an optional value to enable the request ID header for SOAP API calls
* @memberOf Campaign
*/

Expand Down Expand Up @@ -1185,10 +1186,12 @@ class Client {
} catch (error) {
console.error("Failed to generate request ID", error);
}
const updatedExtraHttpHeaders = requestId ? Object.assign({}, extraHttpHeaders, {
"x-request-id": requestId,
})
: extraHttpHeaders;
const enableRequestIdHeader = this._connectionParameters._options?.enableRequestIdHeader;
const updatedExtraHttpHeaders = (enableRequestIdHeader && requestId)
? Object.assign({}, extraHttpHeaders, {
"x-request-id": requestId,
})
: extraHttpHeaders;
const soapCall = new SoapMethodCall(this._transport, urn, method,
this._sessionToken, this._securityToken,
this._getUserAgentString(),
Expand Down
36 changes: 33 additions & 3 deletions test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3447,8 +3447,8 @@ describe('ACC Client', function () {
});
});

it("Should add x-request-id header to every SOAP call", async () => {
const client = await Mock.makeClient();
it("Should add x-request-id header to SOAP call when enableRequestIdHeader is true", async () => {
const client = await Mock.makeClient({ enableRequestIdHeader: true });
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
await client.NLWS.xtkSession.logon();

Expand Down Expand Up @@ -3480,7 +3480,37 @@ describe('ACC Client', function () {
});

it("Should call SOAP call on request ID generation failure", async () => {
const client = await Mock.makeClient();
const client = await Mock.makeClient({enableRequestIdHeader: true});
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
await client.NLWS.xtkSession.logon();

const mockGetUUID = jest.spyOn(Util, 'getUUID').mockImplementation(() => { throw new Error('UUID error'); });

client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
client._transport.mockReturnValueOnce(Mock.GET_QUERY_EXECUTE_RESPONSE);
const queryDef = {
"schema": "nms:extAccount",
"operation": "select",
"select": {
"node": [{ "expr": "@id" }]
}
};

const query = client.NLWS.xtkQueryDef.create(queryDef);

const headers = await collectHeaders(client, async() => {
await query.executeQuery();
});

expect(headers["x-request-id"]).toBeUndefined();

// Restore the mock
mockGetUUID.mockRestore();
});


it("Should not add x-request-id header to SOAP call when enableRequestIdHeader is false", async () => {
const client = await Mock.makeClient({ enableRequestIdHeader: false });
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
await client.NLWS.xtkSession.logon();

Expand Down