@adobe/acc-js-sdk 1.1.17 → 1.1.18
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/docs/caches.html +25 -10
- package/docs/changeLog.html +15 -0
- package/package-lock.json +785 -922
- package/package.json +8 -8
- package/src/client.js +9 -0
- package/test/client.test.js +69 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/acc-js-sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.18",
|
|
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": "^
|
|
14
|
-
"jsdom": "^
|
|
13
|
+
"axios": "^1.2.1",
|
|
14
|
+
"jsdom": "^20.0.3",
|
|
15
15
|
"qs-stringify": "^1.2.1"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"docdash": "^
|
|
18
|
+
"docdash": "^2.0.0",
|
|
19
19
|
"eslint": "^8.7.0",
|
|
20
|
-
"jest": "^
|
|
21
|
-
"jest-junit": "^
|
|
22
|
-
"jsdoc": "^
|
|
23
|
-
"jshint": "^2.13.
|
|
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);
|
package/test/client.test.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|