@adobe/acc-js-sdk 1.1.19 → 1.1.21

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.
@@ -75,8 +75,8 @@ class MethodCache extends Cache {
75
75
  * @deprecated
76
76
  * @param {Element} schema DOM document node represening the schema
77
77
  */
78
- cache(schema) {
79
- return this.put(schema);
78
+ async cache(schema) {
79
+ return await this.put(schema);
80
80
  }
81
81
 
82
82
  /**
@@ -84,7 +84,7 @@ class MethodCache extends Cache {
84
84
  *
85
85
  * @param {Element} schema DOM document node represening the schema
86
86
  */
87
- put(schema) {
87
+ async put(schema) {
88
88
  var namespace = DomUtil.getAttributeAsString(schema, "namespace");
89
89
  var name = DomUtil.getAttributeAsString(schema, "name");
90
90
  var impls = DomUtil.getAttributeAsString(schema, "implements");
@@ -103,7 +103,7 @@ class MethodCache extends Cache {
103
103
  while (child) {
104
104
  const methodName = DomUtil.getAttributeAsString(child, "name");
105
105
  const cached = { method: child, urn: schemaId };
106
- super.put(schemaId, methodName, cached);
106
+ await super.put(schemaId, methodName, cached);
107
107
  child = DomUtil.getNextSiblingElement(child, "method");
108
108
  }
109
109
  }
@@ -124,7 +124,7 @@ class MethodCache extends Cache {
124
124
  let cached = this._cache[key].value;
125
125
  cached = { method: cached.method, urn: urn };
126
126
  const methodName = DomUtil.getAttributeAsString(cached.method, "name");
127
- super.put(schemaId, methodName, cached);
127
+ await super.put(schemaId, methodName, cached);
128
128
  }
129
129
  }
130
130
  }
@@ -137,8 +137,8 @@ class MethodCache extends Cache {
137
137
  * @param {string} methodName the method name
138
138
  * @returns {Campaign.SoapMethodDefinition} the method definition, or undefined if the schema or the method is not found
139
139
  */
140
- get(schemaId, methodName) {
141
- const cached = super.get(schemaId, methodName);
140
+ async get(schemaId, methodName) {
141
+ const cached = await super.get(schemaId, methodName);
142
142
  return cached ? cached.method : undefined;
143
143
  }
144
144
 
@@ -149,8 +149,8 @@ class MethodCache extends Cache {
149
149
  * @param {string} methodName the method name
150
150
  * @returns {string} the URN (or Soap action header), or undefined if the schema or the method is not found
151
151
  */
152
- getSoapUrn(schemaId, methodName) {
153
- const cached = super.get(schemaId, methodName);
152
+ async getSoapUrn(schemaId, methodName) {
153
+ const cached = await super.get(schemaId, methodName);
154
154
  return cached ? cached.urn : undefined;
155
155
  }
156
156
  }
@@ -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
- cache(schemaId, methodName) {
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
  /**
@@ -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
  }
@@ -141,6 +141,25 @@ describe('Application', () => {
141
141
  });
142
142
  });
143
143
 
144
+ describe('dbEnum', () => {
145
+ it("Should find dbEnum attribute", () => {
146
+ var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
147
+ <element name='recipient' label='Recipients'>
148
+ <attribute dbEnum="operationNature" desc="Nature of the campaign" label="Nature"
149
+ length="64" name="nature" type="string"/>
150
+ </element>
151
+ </schema>`);
152
+ var schema = newSchema(xml);
153
+ var root = schema.root;
154
+ expect(!!root.children.get("@nature")).toBe(true);
155
+ var attribute = root.children["@nature"];
156
+ expect(attribute).not.toBeNull();
157
+ expect(attribute.dbEnum).toBe("operationNature");
158
+ expect(attribute.type).toBe("string");
159
+ expect(attribute.length).toBe(64);
160
+ });
161
+ });
162
+
144
163
  describe("Children", () => {
145
164
  it("Should browse root children", () => {
146
165
  var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
@@ -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);