@adobe/acc-js-sdk 1.1.19 → 1.1.20
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 +26 -1
- package/docs/changeLog.html +20 -0
- package/package-lock.json +4 -4
- package/package.json +1 -1
- package/src/cache.js +41 -30
- package/src/cacheRefresher.js +31 -31
- package/src/client.js +42 -33
- package/src/methodCache.js +9 -9
- package/src/optionCache.js +7 -7
- package/src/util.js +17 -0
- package/src/xtkEntityCache.js +5 -5
- package/test/cacheRefresher.test.js +29 -29
- package/test/caches.test.js +151 -123
- package/test/client.test.js +55 -8
- package/test/observability.test.js +2 -2
- package/test/util.test.js +58 -37
package/src/optionCache.js
CHANGED
|
@@ -65,7 +65,7 @@ class OptionCache extends Cache {
|
|
|
65
65
|
* @param {Array} rawValueAndtype a 2 elements array, whose first element is the raw option value (text serialized) and the second element
|
|
66
66
|
* is the data type of the option. Such an array is returned by the xtk:session#GetOption method
|
|
67
67
|
*/
|
|
68
|
-
|
|
68
|
+
async cache(schemaId, methodName) {
|
|
69
69
|
return this.put(schemaId, methodName);
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -76,7 +76,7 @@ class OptionCache extends Cache {
|
|
|
76
76
|
* @param {Array} rawValueAndtype a 2 elements array, whose first element is the raw option value (text serialized) and the second element
|
|
77
77
|
* is the data type of the option. Such an array is returned by the xtk:session#GetOption method
|
|
78
78
|
*/
|
|
79
|
-
put(name, rawValueAndtype) {
|
|
79
|
+
async put(name, rawValueAndtype) {
|
|
80
80
|
var value = null;
|
|
81
81
|
var type = 0;
|
|
82
82
|
var rawValue;
|
|
@@ -85,7 +85,7 @@ class OptionCache extends Cache {
|
|
|
85
85
|
type = rawValueAndtype[1];
|
|
86
86
|
value = XtkCaster.as(rawValue, type);
|
|
87
87
|
}
|
|
88
|
-
super.put(name, { value:value, type:type, rawValue:rawValue });
|
|
88
|
+
await super.put(name, { value:value, type:type, rawValue:rawValue });
|
|
89
89
|
return value;
|
|
90
90
|
}
|
|
91
91
|
|
|
@@ -95,8 +95,8 @@ class OptionCache extends Cache {
|
|
|
95
95
|
* @param {string} name the option name
|
|
96
96
|
* @returns {*} the option value
|
|
97
97
|
*/
|
|
98
|
-
get(name) {
|
|
99
|
-
const option = super.get(name);
|
|
98
|
+
async get(name) {
|
|
99
|
+
const option = await super.get(name);
|
|
100
100
|
return option ? option.value : undefined;
|
|
101
101
|
}
|
|
102
102
|
|
|
@@ -106,8 +106,8 @@ class OptionCache extends Cache {
|
|
|
106
106
|
* @param {string} name the option name
|
|
107
107
|
* @returns {Campaign.XtkOption} the option
|
|
108
108
|
*/
|
|
109
|
-
getOption(name) {
|
|
110
|
-
return super.get(name);
|
|
109
|
+
async getOption(name) {
|
|
110
|
+
return await super.get(name);
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
|
package/src/util.js
CHANGED
|
@@ -153,6 +153,23 @@ class Util {
|
|
|
153
153
|
}
|
|
154
154
|
return schemaId;
|
|
155
155
|
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Test if an object is a promise
|
|
159
|
+
* @param {*} object the object to test
|
|
160
|
+
* @returns {boolean} if the object is a promise
|
|
161
|
+
*/
|
|
162
|
+
static isPromise(object) {
|
|
163
|
+
if (object === null || object === undefined) return false;
|
|
164
|
+
if (object.then && (typeof object.then === "function")) return true;
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
static asPromise(object) {
|
|
169
|
+
if (this.isPromise(object))
|
|
170
|
+
return object;
|
|
171
|
+
return Promise.resolve(object);
|
|
172
|
+
}
|
|
156
173
|
}
|
|
157
174
|
|
|
158
175
|
/**
|
package/src/xtkEntityCache.js
CHANGED
|
@@ -64,8 +64,8 @@ class XtkEntityCache extends Cache {
|
|
|
64
64
|
* @param {string} entityFullName is the entity name, such as "nms:recipient"
|
|
65
65
|
* @returns {*} the cached entity, or undefined if not found
|
|
66
66
|
*/
|
|
67
|
-
get(entityType, entityFullName) {
|
|
68
|
-
return super.get(entityType, entityFullName);
|
|
67
|
+
async get(entityType, entityFullName) {
|
|
68
|
+
return await super.get(entityType, entityFullName);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
/**
|
|
@@ -74,15 +74,15 @@ class XtkEntityCache extends Cache {
|
|
|
74
74
|
* @param {string} entityFullName is the entity name, such as "nms:recipient"
|
|
75
75
|
* @param {*} entity is the entity
|
|
76
76
|
*/
|
|
77
|
-
put(entityType, entityFullName, entity) {
|
|
78
|
-
super.put(entityType, entityFullName, entity);
|
|
77
|
+
async put(entityType, entityFullName, entity) {
|
|
78
|
+
await super.put(entityType, entityFullName, entity);
|
|
79
79
|
// For schemas, cache interfaces
|
|
80
80
|
if (entityType == "xtk:schema") {
|
|
81
81
|
const namespace = entity.getAttribute("namespace");
|
|
82
82
|
var interfaceElement = DomUtil.getFirstChildElement(entity, "interface");
|
|
83
83
|
while (interfaceElement) {
|
|
84
84
|
const name = `${namespace}:${interfaceElement.getAttribute("name")}`;
|
|
85
|
-
super.put(entityType, name, interfaceElement);
|
|
85
|
+
await super.put(entityType, name, interfaceElement);
|
|
86
86
|
interfaceElement = DomUtil.getNextSiblingElement(interfaceElement, "interface");
|
|
87
87
|
}
|
|
88
88
|
}
|
|
@@ -36,13 +36,13 @@ describe("CacheRefresher cache", function () {
|
|
|
36
36
|
|
|
37
37
|
client._transport.mockReturnValueOnce(Mock.GETMODIFIEDENTITIES_CLEAR_RESPONSE);
|
|
38
38
|
await cacheRefresher._callAndRefresh();
|
|
39
|
-
expect(cacheRefresher._refresherStateCache.get("buildNumber")).toBe("9469");
|
|
40
|
-
expect(cacheRefresher._refresherStateCache.get("time")).toBe("2022-07-28T14:38:55.766Z");
|
|
39
|
+
await expect(cacheRefresher._refresherStateCache.get("buildNumber")).resolves.toBe("9469");
|
|
40
|
+
await expect(cacheRefresher._refresherStateCache.get("time")).resolves.toBe("2022-07-28T14:38:55.766Z");
|
|
41
41
|
|
|
42
42
|
client._transport.mockReturnValueOnce(Mock.GETMODIFIEDENTITIES_CLEAR_RESPONSE);
|
|
43
43
|
await cacheRefresher._callAndRefresh();
|
|
44
|
-
expect(cacheRefresher._refresherStateCache.get("buildNumber")).toBe("9469");
|
|
45
|
-
expect(cacheRefresher._refresherStateCache.get("time")).toBe("2022-07-28T14:38:55.766Z");
|
|
44
|
+
await expect(cacheRefresher._refresherStateCache.get("buildNumber")).resolves.toBe("9469");
|
|
45
|
+
await expect(cacheRefresher._refresherStateCache.get("time")).resolves.toBe("2022-07-28T14:38:55.766Z");
|
|
46
46
|
|
|
47
47
|
client._transport.mockReturnValueOnce(Mock.LOGOFF_RESPONSE);
|
|
48
48
|
await client.NLWS.xtkSession.logoff();
|
|
@@ -61,8 +61,8 @@ describe("CacheRefresher cache", function () {
|
|
|
61
61
|
|
|
62
62
|
const cacheRefresher = new CacheRefresher(cache, client, "xtk:schema", "rootkey");
|
|
63
63
|
|
|
64
|
-
expect(cacheRefresher._refresherStateCache.get("buildNumber")).toBeUndefined();
|
|
65
|
-
expect(cacheRefresher._refresherStateCache.get("time")).toBeUndefined();
|
|
64
|
+
await expect(cacheRefresher._refresherStateCache.get("buildNumber")).resolves.toBeUndefined();
|
|
65
|
+
await expect(cacheRefresher._refresherStateCache.get("time")).resolves.toBeUndefined();
|
|
66
66
|
client._transport.mockReturnValue(Promise.resolve(Mock.GETMODIFIEDENTITIES_CLEAR_RESPONSE));
|
|
67
67
|
jest.useFakeTimers();
|
|
68
68
|
cacheRefresher.startAutoRefresh(5000);
|
|
@@ -72,8 +72,8 @@ describe("CacheRefresher cache", function () {
|
|
|
72
72
|
// to allow soap call to finish
|
|
73
73
|
await new Promise(process.nextTick);
|
|
74
74
|
|
|
75
|
-
expect(cacheRefresher._refresherStateCache.get("buildNumber")).toBe("9469");
|
|
76
|
-
expect(cacheRefresher._refresherStateCache.get("time")).toBe("2022-07-28T14:38:55.766Z");
|
|
75
|
+
await expect(cacheRefresher._refresherStateCache.get("buildNumber")).resolves.toBe("9469");
|
|
76
|
+
await expect(cacheRefresher._refresherStateCache.get("time")).resolves.toBe("2022-07-28T14:38:55.766Z");
|
|
77
77
|
|
|
78
78
|
cacheRefresher.stopAutoRefresh();
|
|
79
79
|
client._transport.mockReturnValueOnce(Mock.LOGOFF_RESPONSE);
|
|
@@ -91,13 +91,13 @@ describe("CacheRefresher cache", function () {
|
|
|
91
91
|
const cache = new Cache();
|
|
92
92
|
|
|
93
93
|
const cacheRefresher = new CacheRefresher(cache, client, "xtk:schema", "rootkey");
|
|
94
|
-
cacheRefresher._refresherStateCache.put("buildNumber", "9469");
|
|
95
|
-
cacheRefresher._refresherStateCache.put("time", "2022-07-28T14:38:55.766Z");
|
|
94
|
+
await cacheRefresher._refresherStateCache.put("buildNumber", "9469");
|
|
95
|
+
await cacheRefresher._refresherStateCache.put("time", "2022-07-28T14:38:55.766Z");
|
|
96
96
|
|
|
97
97
|
client._transport.mockReturnValueOnce(Mock.GETMODIFIEDENTITIES_CLEAR_RESPONSE);
|
|
98
98
|
await cacheRefresher._callAndRefresh();
|
|
99
|
-
expect(cacheRefresher._refresherStateCache.get("buildNumber")).toBe("9469");
|
|
100
|
-
expect(cacheRefresher._refresherStateCache.get("time")).toBe("2022-07-28T14:38:55.766Z");
|
|
99
|
+
await expect(cacheRefresher._refresherStateCache.get("buildNumber")).resolves.toBe("9469");
|
|
100
|
+
await expect(cacheRefresher._refresherStateCache.get("time")).resolves.toBe("2022-07-28T14:38:55.766Z");
|
|
101
101
|
|
|
102
102
|
client._transport.mockReturnValueOnce(Mock.LOGOFF_RESPONSE);
|
|
103
103
|
|
|
@@ -122,20 +122,20 @@ describe("CacheRefresher cache", function () {
|
|
|
122
122
|
const cache = new Cache();
|
|
123
123
|
const cacheRefresher = new CacheRefresher(cache, client, "xtk:schema", "rootkey");
|
|
124
124
|
|
|
125
|
-
cache.put("xtk:schema|nms:recipient", "<content recipient>");
|
|
126
|
-
cache.put("xtk:schema|nms:replicationStrategy", "<content xtk:schema|nms:replicationStrategy>");
|
|
127
|
-
cache.put("xtk:schema|nms:operation", "<content xtk:schema|nms:operation>");
|
|
128
|
-
expect(cache.get("xtk:schema|nms:recipient")).toBe("<content recipient>");
|
|
129
|
-
expect(cache.get("xtk:schema|nms:replicationStrategy")).toBe("<content xtk:schema|nms:replicationStrategy>");
|
|
130
|
-
expect(cache.get("xtk:schema|nms:operation")).toBe("<content xtk:schema|nms:operation>");
|
|
125
|
+
await cache.put("xtk:schema|nms:recipient", "<content recipient>");
|
|
126
|
+
await cache.put("xtk:schema|nms:replicationStrategy", "<content xtk:schema|nms:replicationStrategy>");
|
|
127
|
+
await cache.put("xtk:schema|nms:operation", "<content xtk:schema|nms:operation>");
|
|
128
|
+
await expect(cache.get("xtk:schema|nms:recipient")).resolves.toBe("<content recipient>");
|
|
129
|
+
await expect(cache.get("xtk:schema|nms:replicationStrategy")).resolves.toBe("<content xtk:schema|nms:replicationStrategy>");
|
|
130
|
+
await expect(cache.get("xtk:schema|nms:operation")).resolves.toBe("<content xtk:schema|nms:operation>");
|
|
131
131
|
|
|
132
132
|
client._transport.mockReturnValueOnce(Mock.GETMODIFIEDENTITIES_SCHEMA_RESPONSE);
|
|
133
133
|
await cacheRefresher._callAndRefresh();
|
|
134
|
-
expect(cacheRefresher._refresherStateCache.get("buildNumber")).toBe("9469");
|
|
135
|
-
expect(cacheRefresher._refresherStateCache.get("time")).toBe("2022-07-28T15:32:00.785Z");
|
|
136
|
-
expect(cache.get("xtk:schema|nms:recipient")).toBeUndefined();
|
|
137
|
-
expect(cache.get("xtk:schema|nms:replicationStrategy")).toBeUndefined();
|
|
138
|
-
expect(cache.get("xtk:schema|nms:operation")).toBe("<content xtk:schema|nms:operation>");
|
|
134
|
+
await expect(cacheRefresher._refresherStateCache.get("buildNumber")).resolves.toBe("9469");
|
|
135
|
+
await expect(cacheRefresher._refresherStateCache.get("time")).resolves.toBe("2022-07-28T15:32:00.785Z");
|
|
136
|
+
await expect(cache.get("xtk:schema|nms:recipient")).resolves.toBeUndefined();
|
|
137
|
+
await expect(cache.get("xtk:schema|nms:replicationStrategy")).resolves.toBeUndefined();
|
|
138
|
+
await expect(cache.get("xtk:schema|nms:operation")).resolves.toBe("<content xtk:schema|nms:operation>");
|
|
139
139
|
|
|
140
140
|
client._transport.mockReturnValueOnce(Mock.LOGOFF_RESPONSE);
|
|
141
141
|
await client.NLWS.xtkSession.logoff();
|
|
@@ -153,8 +153,8 @@ describe("CacheRefresher cache", function () {
|
|
|
153
153
|
|
|
154
154
|
client._transport.mockReturnValueOnce(Mock.GETMODIFIEDENTITIES_UNDEFINED_RESPONSE);
|
|
155
155
|
await cacheRefresher._callAndRefresh();
|
|
156
|
-
expect(cacheRefresher._refresherStateCache.get("buildNumber")).toBeUndefined();
|
|
157
|
-
expect(cacheRefresher._refresherStateCache.get("time")).toBeUndefined();
|
|
156
|
+
await expect(cacheRefresher._refresherStateCache.get("buildNumber")).resolves.toBeUndefined();
|
|
157
|
+
await expect(cacheRefresher._refresherStateCache.get("time")).resolves.toBeUndefined();
|
|
158
158
|
expect(cacheRefresher._intervalId).toBeNull();
|
|
159
159
|
|
|
160
160
|
client._transport.mockReturnValueOnce(Mock.LOGOFF_RESPONSE);
|
|
@@ -178,8 +178,8 @@ describe("CacheRefresher cache", function () {
|
|
|
178
178
|
} catch (e) {
|
|
179
179
|
expect(e).not.toBeNull();
|
|
180
180
|
}
|
|
181
|
-
expect(cacheRefresher._refresherStateCache.get("buildNumber")).toBeUndefined();
|
|
182
|
-
expect(cacheRefresher._refresherStateCache.get("time")).toBeUndefined();
|
|
181
|
+
await expect(cacheRefresher._refresherStateCache.get("buildNumber")).resolves.toBeUndefined();
|
|
182
|
+
await expect(cacheRefresher._refresherStateCache.get("time")).resolves.toBeUndefined();
|
|
183
183
|
expect(cacheRefresher._intervalId).not.toBeNull();
|
|
184
184
|
|
|
185
185
|
cacheRefresher.stopAutoRefresh();
|
|
@@ -211,8 +211,8 @@ describe("CacheRefresher cache", function () {
|
|
|
211
211
|
// to allow soap call to finish
|
|
212
212
|
await new Promise(process.nextTick);
|
|
213
213
|
|
|
214
|
-
expect(cacheRefresher._refresherStateCache.get("buildNumber")).toBe("9469");
|
|
215
|
-
expect(cacheRefresher._refresherStateCache.get("time")).toBe("2022-07-28T14:38:55.766Z");
|
|
214
|
+
await expect(cacheRefresher._refresherStateCache.get("buildNumber")).resolves.toBe("9469");
|
|
215
|
+
await expect(cacheRefresher._refresherStateCache.get("time")).resolves.toBe("2022-07-28T14:38:55.766Z");
|
|
216
216
|
|
|
217
217
|
cacheRefresher.stopAutoRefresh();
|
|
218
218
|
client._transport.mockReturnValueOnce(Mock.LOGOFF_RESPONSE);
|