@adobe/acc-js-sdk 1.0.7 → 1.0.8
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/CHANGELOG.md +22 -1
- package/README.md +178 -63
- package/compile.js +1 -0
- package/package-lock.json +2 -2
- package/package.json +1 -1
- package/src/application.js +380 -85
- package/src/client.js +18 -10
- package/src/domUtil.js +6 -3
- package/src/entityAccessor.js +5 -5
- package/src/index.js +58 -2
- package/src/testUtil.js +47 -0
- package/src/xtkCaster.js +22 -0
- package/test/application.test.js +684 -655
- package/test/client.test.js +75 -4
- package/test/domUtil.test.js +150 -2
- package/test/escape.test.js +79 -47
- package/test/index.test.js +69 -1
- package/test/mock.js +11 -1
- package/test/testUtil.test.js +64 -0
- package/test/xtkCaster.test.js +122 -1
package/src/client.js
CHANGED
|
@@ -225,16 +225,16 @@ class Credentials {
|
|
|
225
225
|
|
|
226
226
|
/**
|
|
227
227
|
* @typedef {Object} ConnectionOptions
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
228
|
+
* @property {string} representation - the representation to use, i.e. "SimpleJson" (the default), "BadgerFish", or "xml"
|
|
229
|
+
* @property {boolean} rememberMe - The Campaign `rememberMe` attribute which can be used to extend the lifetime of session tokens
|
|
230
|
+
* @property {number} entityCacheTTL - The TTL (in milliseconds) after which cached XTK entities expire. Defaults to 5 minutes
|
|
231
|
+
* @property {number} methodCacheTTL - The TTL (in milliseconds) after which cached XTK methods expire. Defaults to 5 minutes
|
|
232
|
+
* @property {number} optionCacheTTL - The TTL (in milliseconds) after which cached XTK options expire. Defaults to 5 minutes
|
|
233
|
+
* @property {boolean} traceAPICalls - Activates the tracing of all API calls
|
|
234
|
+
* @property {Utils.Transport} transport - Overrides the transport (i.e. HTTP layer)
|
|
235
|
+
* @property {boolean} noStorage - De-activate using of local storage. By default, and in addition to in-memory cache, entities, methods, and options are also persisted in local storage if there is one.
|
|
236
|
+
* @property {Storage} storage - Overrides the storage interface (i.e. LocalStorage)
|
|
237
|
+
* @memberOf Campaign
|
|
238
238
|
*/
|
|
239
239
|
|
|
240
240
|
|
|
@@ -1102,6 +1102,14 @@ class Client {
|
|
|
1102
1102
|
var urn = that._methodCache.getSoapUrn(schemaId, methodName);
|
|
1103
1103
|
var soapCall = that._prepareSoapCall(urn, methodName);
|
|
1104
1104
|
|
|
1105
|
+
// If method is called with one parameter which is a function, then we assume it's a hook: the function will return
|
|
1106
|
+
// the actual list of parameters
|
|
1107
|
+
let isfunc = parameters && typeof parameters === "function";
|
|
1108
|
+
if (!isfunc && parameters && parameters.length >= 1 && typeof parameters[0] === "function")
|
|
1109
|
+
isfunc = true;
|
|
1110
|
+
if (isfunc)
|
|
1111
|
+
parameters = parameters[0](method, callContext);
|
|
1112
|
+
|
|
1105
1113
|
const isStatic = DomUtil.getAttributeAsBoolean(method, "static");
|
|
1106
1114
|
var object = callContext.object;
|
|
1107
1115
|
if (!isStatic) {
|
package/src/domUtil.js
CHANGED
|
@@ -19,7 +19,7 @@ var JSDOM;
|
|
|
19
19
|
|
|
20
20
|
/* istanbul ignore else */
|
|
21
21
|
if (!Util.isBrowser()) {
|
|
22
|
-
|
|
22
|
+
JSDOM = require("jsdom").JSDOM;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/**********************************************************************************
|
|
@@ -40,7 +40,7 @@ else {
|
|
|
40
40
|
return new XMLSerializer().serializeToString(dom);
|
|
41
41
|
};
|
|
42
42
|
};
|
|
43
|
-
|
|
43
|
+
|
|
44
44
|
JSDOM = jsdom;
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -562,7 +562,10 @@ class XPathElement {
|
|
|
562
562
|
class XPath {
|
|
563
563
|
|
|
564
564
|
constructor(path) {
|
|
565
|
-
|
|
565
|
+
path = (path || "").trim();
|
|
566
|
+
if (path && path.startsWith("[") && path.endsWith("]"))
|
|
567
|
+
path = path.substring(1, path.length - 1).trim();
|
|
568
|
+
this._path = path;
|
|
566
569
|
}
|
|
567
570
|
|
|
568
571
|
/**
|
package/src/entityAccessor.js
CHANGED
|
@@ -69,7 +69,7 @@ class EntityAccessor {
|
|
|
69
69
|
*/
|
|
70
70
|
static getAttributeAsString(entity, name) {
|
|
71
71
|
if (entity.documentElement) entity = entity.documentElement;
|
|
72
|
-
if (entity.
|
|
72
|
+
if (entity.nodeType && entity.tagName)
|
|
73
73
|
return DomUtil.getAttributeAsString(entity, name);
|
|
74
74
|
else if (entity instanceof BadgerFishObject)
|
|
75
75
|
return XtkCaster.asString(entity[`@${name}`]);
|
|
@@ -95,7 +95,7 @@ class EntityAccessor {
|
|
|
95
95
|
*/
|
|
96
96
|
static getAttributeAsLong(entity, name) {
|
|
97
97
|
if (entity.documentElement) entity = entity.documentElement;
|
|
98
|
-
if (entity.
|
|
98
|
+
if (entity.nodeType && entity.tagName)
|
|
99
99
|
return DomUtil.getAttributeAsLong(entity, name);
|
|
100
100
|
else if (entity instanceof BadgerFishObject)
|
|
101
101
|
return XtkCaster.asLong(entity[`@${name}`]);
|
|
@@ -121,7 +121,7 @@ class EntityAccessor {
|
|
|
121
121
|
*/
|
|
122
122
|
static getAttributeAsBoolean(entity, name) {
|
|
123
123
|
if (entity.documentElement) entity = entity.documentElement;
|
|
124
|
-
if (entity.
|
|
124
|
+
if (entity.nodeType && entity.tagName)
|
|
125
125
|
return DomUtil.getAttributeAsBoolean(entity, name);
|
|
126
126
|
else if (entity instanceof BadgerFishObject)
|
|
127
127
|
return XtkCaster.asBoolean(entity[`@${name}`]);
|
|
@@ -148,7 +148,7 @@ class EntityAccessor {
|
|
|
148
148
|
*/
|
|
149
149
|
static getChildElements(entity, tagName) {
|
|
150
150
|
if (entity.documentElement) entity = entity.documentElement;
|
|
151
|
-
if (entity.
|
|
151
|
+
if (entity.nodeType && entity.tagName) {
|
|
152
152
|
const elements = [];
|
|
153
153
|
var child = DomUtil.getFirstChildElement(entity);
|
|
154
154
|
while (child) {
|
|
@@ -184,7 +184,7 @@ class EntityAccessor {
|
|
|
184
184
|
*/
|
|
185
185
|
static getElement(entity, tagName) {
|
|
186
186
|
if (entity.documentElement) entity = entity.documentElement;
|
|
187
|
-
if (entity.
|
|
187
|
+
if (entity.nodeType && entity.tagName) {
|
|
188
188
|
var child = DomUtil.getFirstChildElement(entity);
|
|
189
189
|
while (child) {
|
|
190
190
|
if (tagName == child.tagName)
|
package/src/index.js
CHANGED
|
@@ -23,6 +23,7 @@ const DomUtil = require('./domUtil.js').DomUtil;
|
|
|
23
23
|
const XtkCaster = require('./xtkCaster.js').XtkCaster;
|
|
24
24
|
const { Client, Credentials, ConnectionParameters } = require('./client.js');
|
|
25
25
|
const request = require('./transport.js').request;
|
|
26
|
+
const { TestUtil } = require('./testUtil');
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* Get/Set the transport function (defaults to Axios). This function is used for testing / mocking the transport layer.
|
|
@@ -127,8 +128,7 @@ class SDK {
|
|
|
127
128
|
* @example
|
|
128
129
|
* expect(sdk.escapeXtk`@name=${"Rock 'n' Roll"}`).toBe("@name='Rock \\'n\\' Roll'");
|
|
129
130
|
*/
|
|
130
|
-
escapeXtk(p1, ...p2)
|
|
131
|
-
{
|
|
131
|
+
escapeXtk(p1, ...p2) {
|
|
132
132
|
// first syntax: only one parameter which is a string => returns the escaped string.
|
|
133
133
|
// that's how the Campaign function in common.js behaves
|
|
134
134
|
if (p1 === undefined || p1 === null)
|
|
@@ -147,9 +147,65 @@ class SDK {
|
|
|
147
147
|
}
|
|
148
148
|
return str;
|
|
149
149
|
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Escapes a string of characters so that in can be used in a SQL like statement.
|
|
153
|
+
* @param {string | any} text the text to escape. If not a string, it will be casted to a xtk string first
|
|
154
|
+
* @param {boolean?} escapeXtkParams indicates that the escape text contains Xtk parameters (using $ character)
|
|
155
|
+
* @returns the escaped string
|
|
156
|
+
*/
|
|
157
|
+
escapeForLike(text, escapeXtkParams) {
|
|
158
|
+
text = XtkCaster.asString(text);
|
|
159
|
+
if (!text) return "";
|
|
160
|
+
text = text.replace(/\\/g, "\\\\")
|
|
161
|
+
.replace(/'/g, "\\'")
|
|
162
|
+
.replace(/%/g, "\\%")
|
|
163
|
+
.replace(/_/g, "\\_");
|
|
164
|
+
if (escapeXtkParams)
|
|
165
|
+
text = text.replace(/\$/g, "' + Char('36') + '");
|
|
166
|
+
return text;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Expands an xpath, i.e. enclose it with [..] brackets if necessary
|
|
171
|
+
* @param {string} xpath the xpath
|
|
172
|
+
* @returns {string} the expanded xpath
|
|
173
|
+
*/
|
|
174
|
+
expandXPath(xpath) {
|
|
175
|
+
if (!xpath) return xpath;
|
|
176
|
+
if (xpath.startsWith("[") && xpath.endsWith("]"))
|
|
177
|
+
return xpath;
|
|
178
|
+
if (xpath.indexOf('/') === -1 && xpath.indexOf('-') === -1 && xpath.indexOf(':') === -1)
|
|
179
|
+
return xpath;
|
|
180
|
+
return `[${xpath}]`;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
unexpandXPath(xpath) {
|
|
184
|
+
if (!xpath) return xpath;
|
|
185
|
+
if (xpath.startsWith("[") && xpath.endsWith("]"))
|
|
186
|
+
return xpath.substring(1, xpath.length - 1);
|
|
187
|
+
return xpath;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Convert a javascript value into an xtk constant with proper quoting
|
|
192
|
+
* @param {any} value the value to convert
|
|
193
|
+
* @param {string} type the xtk type
|
|
194
|
+
* @returns
|
|
195
|
+
*/
|
|
196
|
+
xtkConstText(value, type) {
|
|
197
|
+
if (!type || type === 'string' || type === 'memo') {
|
|
198
|
+
return sdk.escapeXtk(XtkCaster.asString(value));
|
|
199
|
+
}
|
|
200
|
+
const constText = XtkCaster.asString(XtkCaster.as(value, type));
|
|
201
|
+
if (XtkCaster.isTimeType(type))
|
|
202
|
+
return `#${constText}#`;
|
|
203
|
+
return constText;
|
|
204
|
+
}
|
|
150
205
|
}
|
|
151
206
|
|
|
152
207
|
const sdk = new SDK();
|
|
208
|
+
sdk.TestUtil = TestUtil;
|
|
153
209
|
sdk.XtkCaster = XtkCaster;
|
|
154
210
|
sdk.Credentials = Credentials;
|
|
155
211
|
sdk.DomUtil = DomUtil;
|
package/src/testUtil.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const { DomUtil } = require("./domUtil");
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
Copyright 2022 Adobe. All rights reserved.
|
|
5
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
7
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
+
governing permissions and limitations under the License.
|
|
13
|
+
*/
|
|
14
|
+
(function() {
|
|
15
|
+
"use strict";
|
|
16
|
+
|
|
17
|
+
const { newSchema } = require("./application");
|
|
18
|
+
|
|
19
|
+
/**********************************************************************************
|
|
20
|
+
*
|
|
21
|
+
* Utilities for testing
|
|
22
|
+
*
|
|
23
|
+
*********************************************************************************/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @namespace Utils
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @memberof Utils
|
|
31
|
+
* @class
|
|
32
|
+
* @constructor
|
|
33
|
+
*/
|
|
34
|
+
class TestUtil {
|
|
35
|
+
|
|
36
|
+
static newSchema(xml) {
|
|
37
|
+
if (typeof xml === "string")
|
|
38
|
+
xml = DomUtil.parse(xml);
|
|
39
|
+
return newSchema(xml);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
// Public expots
|
|
45
|
+
exports.TestUtil = TestUtil;
|
|
46
|
+
|
|
47
|
+
})();
|
package/src/xtkCaster.js
CHANGED
|
@@ -341,6 +341,16 @@ class XtkCaster {
|
|
|
341
341
|
return number;
|
|
342
342
|
}
|
|
343
343
|
|
|
344
|
+
/**
|
|
345
|
+
* Convert a raw value into a timestamp (alias to the "asTimestamp" function)
|
|
346
|
+
*
|
|
347
|
+
* @param {*} value is the raw value to convert
|
|
348
|
+
* @return {Date} the timestamp, possibly null
|
|
349
|
+
*/
|
|
350
|
+
static asDatetime(value) {
|
|
351
|
+
return this.asTimestamp(value);
|
|
352
|
+
}
|
|
353
|
+
|
|
344
354
|
/**
|
|
345
355
|
* Convert a raw value into a timestamp
|
|
346
356
|
*
|
|
@@ -421,8 +431,20 @@ class XtkCaster {
|
|
|
421
431
|
return timespan;
|
|
422
432
|
}
|
|
423
433
|
|
|
434
|
+
static isTimeType(type) {
|
|
435
|
+
return type === "datetime" || type === "datetimetz" || type === "datetimenotz" || type === "timestamp" || type === "date" || type === "time" || type === "timespan" || type === 7 || type === 10 || type === 14;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
static isStringType(type) {
|
|
439
|
+
return type === "string" || type === "memo" || type === 6 || type === 12 || type === 13 || type === "blob" || type === "html" || type === "CDATA";
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
static isNumericType(type) {
|
|
443
|
+
return type === "byte" || type === 1 || type === "short" || type === 2 || type === "int" || type === "long" || type === 3 || type === "float" || type === 4 || type === "double" || type === 5 || type === "timespan" || type === 14;
|
|
444
|
+
}
|
|
424
445
|
}
|
|
425
446
|
|
|
447
|
+
|
|
426
448
|
exports.XtkCaster = XtkCaster;
|
|
427
449
|
|
|
428
450
|
})();
|