@adobe/acc-js-sdk 1.1.17 → 1.1.19

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.17",
3
+ "version": "1.1.19",
4
4
  "description": "ACC Javascript SDK",
5
5
  "main": "src/index.js",
6
6
  "homepage": "https://github.com/adobe/acc-js-sdk#readme",
@@ -10,17 +10,17 @@
10
10
  "test": "test"
11
11
  },
12
12
  "dependencies": {
13
- "axios": "^0.25.0",
14
- "jsdom": "^19.0.0",
13
+ "axios": "^1.2.1",
14
+ "jsdom": "^20.0.3",
15
15
  "qs-stringify": "^1.2.1"
16
16
  },
17
17
  "devDependencies": {
18
- "docdash": "^1.2.0",
18
+ "docdash": "^2.0.0",
19
19
  "eslint": "^8.7.0",
20
- "jest": "^27.4.7",
21
- "jest-junit": "^13.0.0",
22
- "jsdoc": "^3.6.7",
23
- "jshint": "^2.13.3"
20
+ "jest": "^29.3.1",
21
+ "jest-junit": "^15.0.0",
22
+ "jsdoc": "^4.0.0",
23
+ "jshint": "^2.13.6"
24
24
  },
25
25
  "author": "",
26
26
  "scripts": {
package/src/client.js CHANGED
@@ -647,6 +647,15 @@ class Client {
647
647
  if (instanceKey.startsWith("https://")) instanceKey = instanceKey.substr(8);
648
648
  const rootKey = `acc.js.sdk.${sdk.getSDKVersion().version}.${instanceKey}.cache`;
649
649
 
650
+ // Clear storage cache if the sdk versions or the instances are different
651
+ if (this._storage && typeof this._storage.removeItem === 'function') {
652
+ for (let key in this._storage) {
653
+ if (key.startsWith("acc.js.sdk.") && !key.startsWith(rootKey)) {
654
+ this._storage.removeItem(key);
655
+ }
656
+ }
657
+ }
658
+
650
659
  this._entityCache = new XtkEntityCache(this._storage, `${rootKey}.XtkEntityCache`, connectionParameters._options.entityCacheTTL);
651
660
  this._entityCacheRefresher = new CacheRefresher(this._entityCache, this, "xtk:schema", `${rootKey}.XtkEntityCache`);
652
661
  this._methodCache = new MethodCache(this._storage, `${rootKey}.MethodCache`, connectionParameters._options.methodCacheTTL);
@@ -1872,6 +1881,7 @@ class Client {
1872
1881
  url: `${this._connectionParameters._endpoint}/nl/jsp/ping.jsp`,
1873
1882
  headers: {
1874
1883
  'X-Security-Token': this._securityToken,
1884
+ 'X-Session-Token': this._sessionToken,
1875
1885
  'Cookie': '__sessiontoken=' + this._sessionToken
1876
1886
  }
1877
1887
  };
@@ -1942,6 +1952,7 @@ class Client {
1942
1952
  url: `${this._connectionParameters._endpoint}/nl/jsp/mcPing.jsp`,
1943
1953
  headers: {
1944
1954
  'X-Security-Token': this._securityToken,
1955
+ 'X-Session-Token': this._sessionToken,
1945
1956
  'Cookie': '__sessiontoken=' + this._sessionToken
1946
1957
  }
1947
1958
  };
package/src/soap.js CHANGED
@@ -538,7 +538,8 @@ class SoapMethodCall {
538
538
  const headers = {
539
539
  'Content-type': `application/soap+xml${this._charset ? ";charset=" + this._charset : ""}`,
540
540
  'SoapAction': `${this.urn}#${this.methodName}`,
541
- 'X-Security-Token': this._securityToken
541
+ 'X-Security-Token': this._securityToken,
542
+ 'X-Session-Token': this._sessionToken,
542
543
  };
543
544
 
544
545
  // Add HTTP headers specific to the SOAP call for better tracing/troubleshooting
package/src/util.js CHANGED
@@ -98,7 +98,8 @@ class Util {
98
98
  }
99
99
  if (typeof obj == "object") {
100
100
  for (const p in obj) {
101
- if (p.toLowerCase() === "x-security-token")
101
+ const lowerP = p.toLowerCase();
102
+ if (lowerP === "x-security-token" || lowerP === "x-session-token")
102
103
  obj[p] = "***";
103
104
  else if (p === "Cookie") {
104
105
  var index = obj[p].toLowerCase().indexOf("__sessiontoken");
@@ -126,6 +127,7 @@ class Util {
126
127
  // Hide session tokens
127
128
  obj = this._removeBetween(obj, "<Cookie>__sessiontoken=", "</Cookie>");
128
129
  obj = this._removeBetween(obj, "<X-Security-Token>", "</X-Security-Token>");
130
+ obj = this._removeBetween(obj, "<X-Session-Token>", "</X-Session-Token>");
129
131
  obj = this._removeBetween(obj, '<sessiontoken xsi:type="xsd:string">', '</sessiontoken>');
130
132
  obj = this._removeBetween(obj, "<pstrSessionToken xsi:type='xsd:string'>", "</pstrSessionToken>");
131
133
  obj = this._removeBetween(obj, "<pstrSecurityToken xsi:type='xsd:string'>", "</pstrSecurityToken>");
@@ -2316,7 +2316,7 @@ describe('ACC Client', function () {
2316
2316
  expect(JSON.parse(call[1])).toMatchObject({
2317
2317
  value: { value: "World", type: 6 }
2318
2318
  })
2319
- });
2319
+ })
2320
2320
 
2321
2321
  it("Should ignore protocol for local storage root key", async () => {
2322
2322
  const version = sdk.getSDKVersion().version; // "${version}" or similar
@@ -2359,7 +2359,7 @@ describe('ACC Client', function () {
2359
2359
  client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
2360
2360
  await client.NLWS.xtkSession.logon();
2361
2361
  client._transport.mockReturnValueOnce(Mock.GET_NMS_EXTACCOUNT_SCHEMA_RESPONSE);
2362
- await client.getSchema("nms:extAccount");
2362
+ await client.getSchema("nms:extAccount");
2363
2363
  // Schema should have been cached to local storage
2364
2364
  expect(storage.setItem.mock.calls.length).toBe(1);
2365
2365
  expect(storage.setItem.mock.calls[0][0]).toMatch("cache.XtkEntityCache$xtk:schema|nms:extAccount");
@@ -2375,6 +2375,73 @@ describe('ACC Client', function () {
2375
2375
  await client.NLWS.xtkSession.logon();
2376
2376
  client._transport.mockReturnValueOnce(Mock.GET_NMS_EXTACCOUNT_SCHEMA_RESPONSE);
2377
2377
  await client.getSchema("nms:extAccount");
2378
+ // Here we can't simply check the length of mock calls since there're for "lastCleared"
2379
+ // We check inside the new calls, since the creation of the second client, if there's
2380
+ // one for the schema "nms:extAccount"
2381
+ let callLength = storage.getItem.mock.calls.length;
2382
+ expect(storage.getItem.mock.calls[callLength-1][0]).toMatch("cache.XtkEntityCache$xtk:schema|nms:extAccount");
2383
+ })
2384
+
2385
+ it("Should clear storage if necessary", async () => {
2386
+ const sdkVersion = sdk.getSDKVersion().version;
2387
+ const mockSdkVersionItemKey = "acc.js.sdk.0.0.0.acc-sdk:8080.cache.Hello";
2388
+ const otherItemKey = "other.Hello";
2389
+ const map = {};
2390
+ const storage = {
2391
+ "acc.js.sdk.0.0.0.acc-sdk:8080.cache.Hello": "0.0.0.World",
2392
+ "other.Hello": "other.World",
2393
+ getItem: jest.fn((key) => map[key]),
2394
+ setItem: jest.fn((key, value) => map[key] = value),
2395
+ removeItem: jest.fn((key) => { delete map[key] })
2396
+ }
2397
+
2398
+ let client = await Mock.makeClient({ storage: storage });
2399
+
2400
+ // Remove item not matches to the current sdk version and begins with "acc.js.sdk"
2401
+ expect(storage.removeItem.mock.calls.length).toBe(1);
2402
+ expect(storage.removeItem.mock.calls[0][0]).toMatch(mockSdkVersionItemKey);
2403
+
2404
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
2405
+ await client.NLWS.xtkSession.logon();
2406
+ client._transport.mockReturnValueOnce(Mock.GET_NMS_EXTACCOUNT_SCHEMA_RESPONSE);
2407
+ await client.getSchema("nms:extAccount");
2408
+ const currentSdkVersionItemKey = "acc.js.sdk."+sdkVersion+".acc-sdk:8080.cache.XtkEntityCache$xtk:schema|nms:extAccount";
2409
+ expect(storage.setItem.mock.calls[0][0]).toMatch(currentSdkVersionItemKey);
2410
+
2411
+ // Remove ONLY the item not matches to the current sdk version but not the one matches
2412
+ // Now simulate reusing the local storage to make sure that we remove ONLY the item
2413
+ // not matches to the current sdk version.
2414
+ // We need a new client to make sure we do not reuse the in-memory cache of the client.
2415
+ // We use the same test method as the one we use in the previous test "Should cache XML in storage"
2416
+ client = await Mock.makeClient({ storage: storage });
2417
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
2418
+ await client.NLWS.xtkSession.logon();
2419
+ client._transport.mockReturnValueOnce(Mock.GET_NMS_EXTACCOUNT_SCHEMA_RESPONSE);
2420
+ await client.getSchema("nms:extAccount");
2421
+ let callLength = storage.getItem.mock.calls.length;
2422
+ expect(storage.getItem.mock.calls[callLength-1][0]).toMatch("cache.XtkEntityCache$xtk:schema|nms:extAccount");
2423
+ })
2424
+
2425
+ it("Should support 'storage.removeItem' not defined", async () => {
2426
+ const mockSdkVersionItemKey = "acc.js.sdk.0.0.0.acc-sdk:8080.cache.Hello";
2427
+ const map = {};
2428
+ const storage = {
2429
+ "acc.js.sdk.0.0.0.acc-sdk:8080.cache.Hello": "0.0.0.World",
2430
+ getItem: jest.fn((key) => map[key]),
2431
+ setItem: jest.fn((key, value) => map[key] = value)
2432
+ }
2433
+ let client = await Mock.makeClient({ storage: storage });
2434
+ // storage.removeItem not defined. Cache should not be removed.
2435
+ expect(storage[mockSdkVersionItemKey]).toStrictEqual("0.0.0.World");
2436
+ })
2437
+
2438
+ it("Should support 'storage' not defined", async () => {
2439
+ const storage = undefined
2440
+ let client = await Mock.makeClient({ storage: storage });
2441
+ // Create a client with "storage" undefined
2442
+ const NLWS = client.NLWS;
2443
+ expect(NLWS).toBeTruthy();
2444
+ expect(client.isLogged()).toBe(false);
2378
2445
  })
2379
2446
  })
2380
2447
 
package/test/soap.test.js CHANGED
@@ -163,6 +163,7 @@ describe('SOAP', function() {
163
163
  const call = makeSoapMethodCall(undefined, "xtk:session", "Empty", "$session$", "$security$");
164
164
  const [ request ] = call._createHTTPRequest(URL);
165
165
  assert.equal(request.headers["X-Security-Token"], "$security$", "Security token matches");
166
+ assert.equal(request.headers["X-Session-Token"], "$session$", "Session token matches");
166
167
  assert.equal(request.headers["Cookie"], "__sessiontoken=$session$", "Session token matches");
167
168
  const env = DomUtil.parse(request.data).documentElement;
168
169
  const header = hasChildElement(env, "SOAP-ENV:Header");
package/test/util.test.js CHANGED
@@ -86,6 +86,10 @@ describe('Util', function() {
86
86
  expect(Util.trim({hello:"Lead<X-Security-Token>Stuff</X-Security-Token>Trail"})).toStrictEqual({hello:"Lead<X-Security-Token>***</X-Security-Token>Trail"});
87
87
  })
88
88
 
89
+ it("Should remove session token headers", () => {
90
+ expect(Util.trim({hello:"Lead<X-Session-Token>Stuff</X-Session-Token>Trail"})).toStrictEqual({hello:"Lead<X-Session-Token>***</X-Session-Token>Trail"});
91
+ })
92
+
89
93
  it("Should remove session tokens", () => {
90
94
  expect(Util.trim({hello:'Lead<sessiontoken xsi:type="xsd:string">Stuff</sessiontoken>Trail'})).toStrictEqual({hello:'Lead<sessiontoken xsi:type="xsd:string">***</sessiontoken>Trail'});
91
95
  })