@adobe/acc-js-sdk 1.1.60 → 1.1.62

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/acc-js-sdk",
3
- "version": "1.1.60",
3
+ "version": "1.1.62",
4
4
  "description": "ACC Javascript SDK",
5
5
  "main": "src/index.js",
6
6
  "homepage": "https://github.com/adobe/acc-js-sdk#readme",
package/src/client.js CHANGED
@@ -309,6 +309,7 @@ class Credentials {
309
309
  * @property {number} timeout - Can be set to change the HTTP call timeout. Value is passed in ms.
310
310
  * @property {string} cacheRootKey - "default" or "none" - determine the prefix to use for the keys in the caches of schemas, options, etc.
311
311
  * @property {string} instanceKey - an optional value to override the instance key which is used for the caches of schemas, options, etc.
312
+ * @property {boolean} enableRequestIdHeader - an optional value to enable the request ID header for SOAP API calls
312
313
  * @memberOf Campaign
313
314
  */
314
315
 
@@ -1178,11 +1179,26 @@ class Client {
1178
1179
  * parameters should be set
1179
1180
  */
1180
1181
  _prepareSoapCall(urn, method, isStatic, internal, extraHttpHeaders, pushDownOptions) {
1182
+
1183
+ // Send request ID header if enableRequestIdHeader flag is set to true
1184
+ const enableRequestIdHeader = this._connectionParameters._options &&
1185
+ this._connectionParameters._options.enableRequestIdHeader;
1186
+ let updatedExtraHttpHeaders = extraHttpHeaders;
1187
+ if (enableRequestIdHeader) {
1188
+ try {
1189
+ const requestId = Util.getUUID();
1190
+ updatedExtraHttpHeaders = Object.assign({}, extraHttpHeaders, {
1191
+ "x-request-id": requestId,
1192
+ });
1193
+ } catch (error) {
1194
+ console.error("Failed to generate request ID", error);
1195
+ }
1196
+ }
1181
1197
  const soapCall = new SoapMethodCall(this._transport, urn, method,
1182
1198
  this._sessionToken, this._securityToken,
1183
1199
  this._getUserAgentString(),
1184
1200
  Object.assign({}, this._connectionParameters._options, pushDownOptions),
1185
- extraHttpHeaders,
1201
+ updatedExtraHttpHeaders,
1186
1202
  this._bearerToken);
1187
1203
  soapCall.internal = !!internal;
1188
1204
  soapCall.isStatic = isStatic;
@@ -3446,6 +3446,97 @@ describe('ACC Client', function () {
3446
3446
  "X-Query-Source": `${sdk.getSDKVersion().name} ${sdk.getSDKVersion().version},Test client app`,
3447
3447
  });
3448
3448
  });
3449
+
3450
+ it("Should add x-request-id header to SOAP call when enableRequestIdHeader is true", async () => {
3451
+ const client = await Mock.makeClient({ enableRequestIdHeader: true });
3452
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
3453
+ await client.NLWS.xtkSession.logon();
3454
+
3455
+ const mockGetUUID = jest.spyOn(Util, 'getUUID').mockImplementation(() => { return 'test-uuid'; });
3456
+
3457
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
3458
+ client._transport.mockReturnValueOnce(Mock.GET_QUERY_EXECUTE_RESPONSE);
3459
+
3460
+ const queryDef = {
3461
+ "schema": "nms:extAccount",
3462
+ "operation": "select",
3463
+ "select": {
3464
+ "node": [
3465
+ { "expr": "@id" },
3466
+ { "expr": "@name" }
3467
+ ]
3468
+ }
3469
+ };
3470
+ const query = client.NLWS.xtkQueryDef.create(queryDef);
3471
+
3472
+ const headers = await collectHeaders(client, async() => {
3473
+ await query.executeQuery();
3474
+ });
3475
+
3476
+ expect(headers["x-request-id"]).toBe('test-uuid');
3477
+
3478
+ // Restore the mock
3479
+ mockGetUUID.mockRestore();
3480
+ });
3481
+
3482
+ it("Should call SOAP call on request ID generation failure", async () => {
3483
+ const client = await Mock.makeClient({enableRequestIdHeader: true});
3484
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
3485
+ await client.NLWS.xtkSession.logon();
3486
+
3487
+ const mockGetUUID = jest.spyOn(Util, 'getUUID').mockImplementation(() => { throw new Error('UUID error'); });
3488
+
3489
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
3490
+ client._transport.mockReturnValueOnce(Mock.GET_QUERY_EXECUTE_RESPONSE);
3491
+ const queryDef = {
3492
+ "schema": "nms:extAccount",
3493
+ "operation": "select",
3494
+ "select": {
3495
+ "node": [{ "expr": "@id" }]
3496
+ }
3497
+ };
3498
+
3499
+ const query = client.NLWS.xtkQueryDef.create(queryDef);
3500
+
3501
+ const headers = await collectHeaders(client, async() => {
3502
+ await query.executeQuery();
3503
+ });
3504
+
3505
+ expect(headers["x-request-id"]).toBeUndefined();
3506
+
3507
+ // Restore the mock
3508
+ mockGetUUID.mockRestore();
3509
+ });
3510
+
3511
+
3512
+ it("Should not add x-request-id header to SOAP call when enableRequestIdHeader is false", async () => {
3513
+ const client = await Mock.makeClient({ enableRequestIdHeader: false });
3514
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
3515
+ await client.NLWS.xtkSession.logon();
3516
+
3517
+ const mockGetUUID = jest.spyOn(Util, 'getUUID').mockImplementation(() => { throw new Error('UUID error'); });
3518
+
3519
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
3520
+ client._transport.mockReturnValueOnce(Mock.GET_QUERY_EXECUTE_RESPONSE);
3521
+ const queryDef = {
3522
+ "schema": "nms:extAccount",
3523
+ "operation": "select",
3524
+ "select": {
3525
+ "node": [{ "expr": "@id" }]
3526
+ }
3527
+ };
3528
+
3529
+ const query = client.NLWS.xtkQueryDef.create(queryDef);
3530
+
3531
+ const headers = await collectHeaders(client, async() => {
3532
+ await query.executeQuery();
3533
+ });
3534
+
3535
+ expect(headers["x-request-id"]).toBeUndefined();
3536
+
3537
+ // Restore the mock
3538
+ mockGetUUID.mockRestore();
3539
+ });
3449
3540
  });
3450
3541
 
3451
3542
  describe("Pushdown parameters", () => {