@adobe/acc-js-sdk 1.0.6 → 1.0.7
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/.github/workflows/codeql-analysis.yml +70 -0
- package/CHANGELOG.md +11 -0
- package/README.md +14 -0
- package/package-lock.json +2156 -3344
- package/package.json +6 -7
- package/samples/002 - basics - schemas.js +3 -3
- package/samples/020 - encryption.js +5 -5
- package/src/application.js +55 -0
- package/src/campaign.js +4 -0
- package/src/client.js +43 -4
- package/src/soap.js +44 -18
- package/src/xtkCaster.js +58 -6
- package/test/application.test.js +40 -1
- package/test/client.test.js +167 -15
- package/test/crypto.test.js +16 -12
- package/test/mock.js +24 -6
- package/test/soap.test.js +0 -6
- package/test/xtkCaster.test.js +97 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/acc-js-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
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,16 @@
|
|
|
10
10
|
"test": "test"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"axios": "^0.
|
|
14
|
-
"jsdom": "^
|
|
13
|
+
"axios": "^0.25.0",
|
|
14
|
+
"jsdom": "^19.0.0"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"docdash": "^1.2.0",
|
|
18
|
-
"eslint": "^7.
|
|
19
|
-
"jest": "^27.
|
|
18
|
+
"eslint": "^8.7.0",
|
|
19
|
+
"jest": "^27.4.7",
|
|
20
20
|
"jest-junit": "^13.0.0",
|
|
21
21
|
"jsdoc": "^3.6.7",
|
|
22
|
-
"
|
|
23
|
-
"jshint": "^2.13.1"
|
|
22
|
+
"jshint": "^2.13.3"
|
|
24
23
|
},
|
|
25
24
|
"author": "",
|
|
26
25
|
"scripts": {
|
|
@@ -25,7 +25,7 @@ const utils = require("./utils.js");
|
|
|
25
25
|
code: async() => {
|
|
26
26
|
return await utils.logon(async (client, NLWS) => {
|
|
27
27
|
const schema = await client.getSchema("xtk:option");
|
|
28
|
-
console.log(`>> client.getSchema (current representation)
|
|
28
|
+
console.log(`>> client.getSchema (current representation) : ${JSON.stringify(schema)}`);
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
});
|
|
@@ -38,7 +38,7 @@ const utils = require("./utils.js");
|
|
|
38
38
|
code: async() => {
|
|
39
39
|
return await utils.logon(async (client, NLWS) => {
|
|
40
40
|
const schema = await client.getSchema("xtk:option", "xml");
|
|
41
|
-
console.log(`>> client.getSchema (xml)
|
|
41
|
+
console.log(`>> client.getSchema (xml) : ${client.DomUtil.toXMLString(schema)}`);
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
});
|
|
@@ -52,7 +52,7 @@ const utils = require("./utils.js");
|
|
|
52
52
|
code: async() => {
|
|
53
53
|
return await utils.logon(async (client, NLWS) => {
|
|
54
54
|
const schema = await client.getEntityIfMoreRecent("xtk:srcSchema", "nms:rtEvent");
|
|
55
|
-
console.log(`>> client.getEntityIfMoreRecent
|
|
55
|
+
console.log(`>> client.getEntityIfMoreRecent : ${JSON.stringify(schema)}`);
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
});
|
|
@@ -31,11 +31,11 @@ const utils = require("./utils.js");
|
|
|
31
31
|
code: async() => {
|
|
32
32
|
return await utils.logon(async (client, NLWS) => {
|
|
33
33
|
const password = "Hello, World";
|
|
34
|
-
console.log(`xtk:session#Encrypt
|
|
35
|
-
console.log(`xtk:session#EncryptPassword
|
|
36
|
-
console.log(`xtk:session#EncryptServerPassword
|
|
37
|
-
console.log(`xtk:session#HashPassword
|
|
38
|
-
console.log(`xtk:session#ReEncryptPassword
|
|
34
|
+
console.log(`xtk:session#Encrypt : ${await NLWS.xtkSession.encrypt(password)}`);
|
|
35
|
+
console.log(`xtk:session#EncryptPassword : ${await NLWS.xtkSession.encryptPassword(password)}`);
|
|
36
|
+
console.log(`xtk:session#EncryptServerPassword : ${await NLWS.xtkSession.encryptServerPassword(password)}`);
|
|
37
|
+
console.log(`xtk:session#HashPassword : ${await NLWS.xtkSession.hashPassword(password)}`);
|
|
38
|
+
console.log(`xtk:session#ReEncryptPassword : ${await NLWS.xtkSession.reEncryptPassword(await NLWS.xtkSession.encryptPassword(password))}`);
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
});
|
package/src/application.js
CHANGED
|
@@ -88,6 +88,22 @@ class XtkSchemaKey {
|
|
|
88
88
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
/**
|
|
92
|
+
* A join in a XtkSchemaNode link type
|
|
93
|
+
*
|
|
94
|
+
* @private
|
|
95
|
+
* @class
|
|
96
|
+
* @constructor
|
|
97
|
+
* @param {} xml
|
|
98
|
+
* @memberof Campaign
|
|
99
|
+
*/
|
|
100
|
+
class XtkJoin {
|
|
101
|
+
|
|
102
|
+
constructor(xml) {
|
|
103
|
+
this.src = EntityAccessor.getAttributeAsString(xml, "xpath-src");
|
|
104
|
+
this.dst = EntityAccessor.getAttributeAsString(xml, "xpath-dst");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
91
107
|
// ========================================================================================
|
|
92
108
|
// Schema nodes
|
|
93
109
|
// ========================================================================================
|
|
@@ -157,16 +173,37 @@ class XtkSchemaNode {
|
|
|
157
173
|
* @type {string}
|
|
158
174
|
*/
|
|
159
175
|
this.type = EntityAccessor.getAttributeAsString(xml, "type");
|
|
176
|
+
/**
|
|
177
|
+
* The node target
|
|
178
|
+
* @type {string}
|
|
179
|
+
*/
|
|
180
|
+
this.target = EntityAccessor.getAttributeAsString(xml, "target");
|
|
181
|
+
/**
|
|
182
|
+
* The node integrity
|
|
183
|
+
* @type {string}
|
|
184
|
+
*/
|
|
185
|
+
this.integrity = EntityAccessor.getAttributeAsString(xml, "integrity");
|
|
160
186
|
/**
|
|
161
187
|
* The node data length (applicable for string-types only)
|
|
162
188
|
* @type {number}
|
|
163
189
|
*/
|
|
164
190
|
this.length = EntityAccessor.getAttributeAsLong(xml, "length");
|
|
191
|
+
/**
|
|
192
|
+
* The enum of the node
|
|
193
|
+
* @type {string}
|
|
194
|
+
*/
|
|
195
|
+
this.enum = EntityAccessor.getAttributeAsString(xml, "enum");
|
|
165
196
|
/**
|
|
166
197
|
* "ref" attribute of the node, which references another node
|
|
167
198
|
* @type {string}
|
|
168
199
|
*/
|
|
169
200
|
this.ref = EntityAccessor.getAttributeAsString(xml, "ref");
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Has an unlimited number of children of the same type
|
|
204
|
+
* @type {boolean}
|
|
205
|
+
*/
|
|
206
|
+
this.unbound = EntityAccessor.getAttributeAsBoolean(xml, "unbound");
|
|
170
207
|
/**
|
|
171
208
|
* Children of the node. This is a object whose key are the names of the children nodes (without the "@"
|
|
172
209
|
* character for attributes)
|
|
@@ -198,6 +235,15 @@ class XtkSchemaNode {
|
|
|
198
235
|
* @type {string}
|
|
199
236
|
*/
|
|
200
237
|
this.nodePath = this._getNodePath(true)._path;
|
|
238
|
+
/**
|
|
239
|
+
* Element of type "link" has an array of XtkJoin
|
|
240
|
+
* @type {@type {XtkJoin[]}}
|
|
241
|
+
*/
|
|
242
|
+
this.joins = [];
|
|
243
|
+
|
|
244
|
+
for (var child of EntityAccessor.getChildElements(xml, "join")) {
|
|
245
|
+
this.joins.push(new XtkJoin(child));
|
|
246
|
+
}
|
|
201
247
|
|
|
202
248
|
// Children (elements and attributes)
|
|
203
249
|
const childNodes = [];
|
|
@@ -242,6 +288,15 @@ class XtkSchemaNode {
|
|
|
242
288
|
return false;
|
|
243
289
|
}
|
|
244
290
|
|
|
291
|
+
/**
|
|
292
|
+
* Indicates whether the current node has an unlimited number of children of the same type.
|
|
293
|
+
*
|
|
294
|
+
* @returns {boolean} a boolean indicating whether the node contains a child with the given name
|
|
295
|
+
*/
|
|
296
|
+
isUnbound() {
|
|
297
|
+
return this.unbound;
|
|
298
|
+
}
|
|
299
|
+
|
|
245
300
|
/**
|
|
246
301
|
* Computes the path of a node
|
|
247
302
|
*
|
package/src/campaign.js
CHANGED
|
@@ -37,6 +37,7 @@ const { Util } = require("./util.js");
|
|
|
37
37
|
static SOAP_UNKNOWN_METHOD(schema, method, details) { return new CampaignException(undefined, 400, 16384, `SDK-000009 Unknown method '${method}' of schema '${schema}'`, details); }
|
|
38
38
|
static NOT_LOGGED_IN(call, details) { return new CampaignException( call, 400, 16384, `SDK-000010 Cannot call API because client is not logged in`, details); }
|
|
39
39
|
static DECRYPT_ERROR(details) { return new CampaignException(undefined, 400, 16384, `SDK-000011 "Cannot decrypt password: password marker is missing`, details); }
|
|
40
|
+
static SESSION_EXPIRED() { return new CampaignException(undefined, 401, 16384, `SDK-000012 "Session has expired or is invalid. Please reconnect.`); }
|
|
40
41
|
|
|
41
42
|
|
|
42
43
|
/**
|
|
@@ -223,6 +224,9 @@ function makeCampaignException(call, err) {
|
|
|
223
224
|
faultString = err.data;
|
|
224
225
|
details = undefined;
|
|
225
226
|
}
|
|
227
|
+
// Session expiration case must return a 401
|
|
228
|
+
if (err.data && err.data.indexOf(`XSV-350008`) != -1)
|
|
229
|
+
return CampaignException.SESSION_EXPIRED();
|
|
226
230
|
return new CampaignException(call, err.statusCode, "", faultString, details, err);
|
|
227
231
|
}
|
|
228
232
|
|
package/src/client.js
CHANGED
|
@@ -296,6 +296,7 @@ class ConnectionParameters {
|
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
298
|
this._options._storage = storage;
|
|
299
|
+
this._options.refreshClient = options.refreshClient;
|
|
299
300
|
}
|
|
300
301
|
|
|
301
302
|
/**
|
|
@@ -478,6 +479,7 @@ class Client {
|
|
|
478
479
|
this._transport = connectionParameters._options.transport;
|
|
479
480
|
this._traceAPICalls = connectionParameters._options.traceAPICalls;
|
|
480
481
|
this._observers = [];
|
|
482
|
+
this._refreshClient = connectionParameters._options.refreshClient;
|
|
481
483
|
|
|
482
484
|
// expose utilities
|
|
483
485
|
|
|
@@ -676,6 +678,38 @@ class Client {
|
|
|
676
678
|
return soapCall;
|
|
677
679
|
}
|
|
678
680
|
|
|
681
|
+
/**
|
|
682
|
+
* Retry a a SOAP call
|
|
683
|
+
*
|
|
684
|
+
* @private
|
|
685
|
+
* @return {SOAP.SoapMethodCall} a SoapMethodCall to retry
|
|
686
|
+
* parameters should be set
|
|
687
|
+
*/
|
|
688
|
+
async _retrySoapCall(soapCall) {
|
|
689
|
+
soapCall.retry = false;
|
|
690
|
+
var newClient = await this._refreshClient(this);
|
|
691
|
+
soapCall.finalize(newClient._soapEndPoint(), newClient);
|
|
692
|
+
if (this._traceAPICalls) {
|
|
693
|
+
const safeCallData = Util.trim(soapCall.request.data);
|
|
694
|
+
console.log(`RETRY SOAP//request ${safeCallData}`);
|
|
695
|
+
}
|
|
696
|
+
await soapCall.execute();
|
|
697
|
+
if (this._traceAPICalls) {
|
|
698
|
+
const safeCallResponse = Util.trim(soapCall.response);
|
|
699
|
+
console.log(`SOAP//response ${safeCallResponse}`);
|
|
700
|
+
}
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* SOAP Endpoint
|
|
706
|
+
*
|
|
707
|
+
* @private
|
|
708
|
+
* @return {string} soap call End point
|
|
709
|
+
*/
|
|
710
|
+
_soapEndPoint() {
|
|
711
|
+
return this._connectionParameters._endpoint + "/nl/jsp/soaprouter.jsp";
|
|
712
|
+
}
|
|
679
713
|
/**
|
|
680
714
|
* After a SOAP method call has been prepared with '_prepareSoapCall', and parameters have been added,
|
|
681
715
|
* this function actually executes the SOAP call
|
|
@@ -687,8 +721,7 @@ class Client {
|
|
|
687
721
|
const that = this;
|
|
688
722
|
if (soapCall.requiresLogon() && !that.isLogged())
|
|
689
723
|
throw CampaignException.NOT_LOGGED_IN(soapCall, `Cannot execute SOAP call ${soapCall.urn}#${soapCall.methodName}: you are not logged in. Use the Logon function first`);
|
|
690
|
-
|
|
691
|
-
soapCall.finalize(soapEndpoint);
|
|
724
|
+
soapCall.finalize(this._soapEndPoint());
|
|
692
725
|
|
|
693
726
|
const safeCallData = Util.trim(soapCall.request.data);
|
|
694
727
|
if (that._traceAPICalls)
|
|
@@ -707,7 +740,12 @@ class Client {
|
|
|
707
740
|
if (that._traceAPICalls)
|
|
708
741
|
console.log(`SOAP//failure ${ex.toString()}`);
|
|
709
742
|
that._notifyObservers((observer) => observer.onSOAPCallFailure && observer.onSOAPCallFailure(soapCall, ex) );
|
|
710
|
-
|
|
743
|
+
// Call session expiration callback in case of 401
|
|
744
|
+
if (ex.statusCode == 401 && that._refreshClient && soapCall.retry) {
|
|
745
|
+
return this._retrySoapCall(soapCall);
|
|
746
|
+
}
|
|
747
|
+
else
|
|
748
|
+
return Promise.reject(ex);
|
|
711
749
|
});
|
|
712
750
|
}
|
|
713
751
|
|
|
@@ -745,6 +783,8 @@ class Client {
|
|
|
745
783
|
}
|
|
746
784
|
else if (credentials._type == "UserPassword" || credentials._type == "BearerToken") {
|
|
747
785
|
const soapCall = that._prepareSoapCall("xtk:session", credentials._type === "UserPassword" ? "Logon" : "BearerTokenLogon");
|
|
786
|
+
// No retry for logon SOAP methods
|
|
787
|
+
soapCall.retry = false;
|
|
748
788
|
if (credentials._type == "UserPassword") {
|
|
749
789
|
const user = credentials._getUser();
|
|
750
790
|
const password = credentials._getPassword();
|
|
@@ -813,7 +853,6 @@ class Client {
|
|
|
813
853
|
logoff() {
|
|
814
854
|
var that = this;
|
|
815
855
|
if (!that.isLogged()) return;
|
|
816
|
-
|
|
817
856
|
const credentials = this._connectionParameters._credentials;
|
|
818
857
|
if (credentials._type != "SessionToken" && credentials._type != "AnonymousUser") {
|
|
819
858
|
var soapCall = that._prepareSoapCall("xtk:session", "Logoff");
|
package/src/soap.js
CHANGED
|
@@ -93,6 +93,8 @@ class SoapMethodCall {
|
|
|
93
93
|
// Soap calls marked as internal are calls performed by the framework internally
|
|
94
94
|
// (such as GetEntityIfMoreRecent calls needed to lookup schemas)
|
|
95
95
|
this.internal = false;
|
|
96
|
+
// Enable soap retry
|
|
97
|
+
this.retry = true;
|
|
96
98
|
|
|
97
99
|
this._sessionToken = sessionToken || "";
|
|
98
100
|
this._securityToken = securityToken || "";
|
|
@@ -151,22 +153,6 @@ class SoapMethodCall {
|
|
|
151
153
|
this._method.setAttribute(`xmlns:m`, urnPath);
|
|
152
154
|
this._method.setAttribute(`SOAP-ENV:encodingStyle`, encoding);
|
|
153
155
|
this._data.appendChild(this._method);
|
|
154
|
-
|
|
155
|
-
if (this._sessionToken) {
|
|
156
|
-
const cookieHeader = this._doc.createElement("Cookie");
|
|
157
|
-
cookieHeader.textContent = `__sessiontoken=${this._sessionToken}`;
|
|
158
|
-
this._header.appendChild(cookieHeader);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const securityTokenHeader = this._doc.createElement("X-Security-Token");
|
|
162
|
-
securityTokenHeader.textContent = this._securityToken;
|
|
163
|
-
this._header.appendChild(securityTokenHeader);
|
|
164
|
-
|
|
165
|
-
// Always write a sessiontoken element as the first parameter. Even when using SecurityToken authentication
|
|
166
|
-
// and when the session token is actually passed implicitely as a cookie, one must write a sessiontoken
|
|
167
|
-
// element. If not, authentication will fail because the first parameter is interpreted as the "authentication mode"
|
|
168
|
-
// and eventually passed as the first parameter of CXtkLocalSessionPart::GetXtkSecurity
|
|
169
|
-
this.writeString("sessiontoken", this._sessionToken);
|
|
170
156
|
}
|
|
171
157
|
|
|
172
158
|
/**
|
|
@@ -542,12 +528,50 @@ class SoapMethodCall {
|
|
|
542
528
|
options.headers['User-Agent'] = this._userAgentString;
|
|
543
529
|
return options;
|
|
544
530
|
}
|
|
545
|
-
|
|
531
|
+
|
|
546
532
|
/**
|
|
547
533
|
* Finalize a SOAP call just before sending
|
|
548
534
|
* @param {string} url the endpoint (/nl/jsp/soaprouter.jsp)
|
|
535
|
+
* @param {client.Client} sdk client (optional)
|
|
549
536
|
*/
|
|
550
|
-
finalize(url) {
|
|
537
|
+
finalize(url, client) {
|
|
538
|
+
if (client) {
|
|
539
|
+
this._sessionToken = client._sessionToken;
|
|
540
|
+
this._securityToken = client._securityToken;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
var cookieHeader = DomUtil.findElement(this._header, "Cookie");
|
|
544
|
+
if (this._sessionToken) {
|
|
545
|
+
if (!cookieHeader) {
|
|
546
|
+
cookieHeader = this._doc.createElement("Cookie");
|
|
547
|
+
this._header.appendChild(cookieHeader);
|
|
548
|
+
}
|
|
549
|
+
cookieHeader.textContent = `__sessiontoken=${this._sessionToken}`;
|
|
550
|
+
} else if (cookieHeader) {
|
|
551
|
+
cookieHeader.remove();
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
var securityTokenHeader = DomUtil.findElement(this._header, "X-Security-Token");
|
|
555
|
+
if (!securityTokenHeader) {
|
|
556
|
+
securityTokenHeader = this._doc.createElement("X-Security-Token");
|
|
557
|
+
this._header.appendChild(securityTokenHeader);
|
|
558
|
+
}
|
|
559
|
+
securityTokenHeader.textContent = this._securityToken;
|
|
560
|
+
|
|
561
|
+
// Always write a sessiontoken element as the first parameter. Even when using SecurityToken authentication
|
|
562
|
+
// and when the session token is actually passed implicitely as a cookie, one must write a sessiontoken
|
|
563
|
+
// element. If not, authentication will fail because the first parameter is interpreted as the "authentication mode"
|
|
564
|
+
// and eventually passed as the first parameter of CXtkLocalSessionPart::GetXtkSecurity
|
|
565
|
+
var sessionTokenElem = DomUtil.findElement(this._method, "sessiontoken");
|
|
566
|
+
if (sessionTokenElem) {
|
|
567
|
+
sessionTokenElem.textContent = this._sessionToken;
|
|
568
|
+
} else {
|
|
569
|
+
sessionTokenElem = this._doc.createElement("sessiontoken");
|
|
570
|
+
sessionTokenElem.setAttribute("xsi:type", "xsd:string");
|
|
571
|
+
// sessionTokenElem.setAttribute("SOAP-ENV:encodingStyle", SOAP_ENCODING_NATIVE);
|
|
572
|
+
sessionTokenElem.textContent = this._sessionToken;
|
|
573
|
+
this._method.prepend(sessionTokenElem);
|
|
574
|
+
}
|
|
551
575
|
const options = this._createHTTPRequest(url);
|
|
552
576
|
// Prepare request and empty response objects
|
|
553
577
|
this.request = options;
|
|
@@ -565,6 +589,8 @@ class SoapMethodCall {
|
|
|
565
589
|
const that = this;
|
|
566
590
|
const promise = this._transport(this.request);
|
|
567
591
|
return promise.then(function(body) {
|
|
592
|
+
if (body.indexOf(`XSV-350008`) != -1)
|
|
593
|
+
throw CampaignException.SESSION_EXPIRED();
|
|
568
594
|
that.response = body;
|
|
569
595
|
// Response is a serialized XML document with the following structure
|
|
570
596
|
//
|
package/src/xtkCaster.js
CHANGED
|
@@ -12,6 +12,8 @@ governing permissions and limitations under the License.
|
|
|
12
12
|
(function() {
|
|
13
13
|
"use strict";
|
|
14
14
|
|
|
15
|
+
const { Util } = require('./util.js');
|
|
16
|
+
|
|
15
17
|
/**********************************************************************************
|
|
16
18
|
*
|
|
17
19
|
* Helper class to cast values to and from their Xtk versions
|
|
@@ -37,11 +39,15 @@ governing permissions and limitations under the License.
|
|
|
37
39
|
| Xtk type | | JS type | Comment |
|
|
38
40
|
| ------------ |----|-------- | --- |
|
|
39
41
|
| string | 6 | string | never null, defaults to "" |
|
|
40
|
-
| memo | 12 | string |
|
|
41
|
-
| CDATA | 13 | string |
|
|
42
|
+
| memo | 12 | string | large strings. Never null, defaults to ""
|
|
43
|
+
| CDATA | 13 | string | string in the CDATA section of an XML document. Never null, defaults to ""
|
|
44
|
+
| uuid | | string |
|
|
45
|
+
| blob | | string |
|
|
46
|
+
| html | | string |
|
|
42
47
|
| byte | 1 | number | signed integer in the [-128, 128[ range. Never null, defaults to 0 |
|
|
43
48
|
| short | 2 | number | signed 16 bits integer in the [-32768, 32768[ range. Never null, defaults to 0 |
|
|
44
49
|
| long | 3 | number | signed 32 bits integer. Never null, defaults to 0 |
|
|
50
|
+
| int | | number | signed 32 bits integer. Never null, defaults to 0 |
|
|
45
51
|
| int64 | | string | signed 64 bits integer. As JavaScript handles all numbers as doubles, it's not possible to properly represent an int64 as a number, and it's therefore represented as a string.
|
|
46
52
|
| float | 4 | number | single-percision numeric value. Never null, defaults to 0 |
|
|
47
53
|
| double | 5 | number | single-percision numeric value. Never null, defaults to 0 |
|
|
@@ -49,10 +55,11 @@ governing permissions and limitations under the License.
|
|
|
49
55
|
| datetimetz | | | |
|
|
50
56
|
| datetimenotz | | | |
|
|
51
57
|
| date | 10 | Date | UTC timestamp with day precision. Can be null |
|
|
58
|
+
| timespan | 14 | number | A timespan, in seconds
|
|
52
59
|
| boolean | 15 | boolean | boolean value, defaultint to false. Cannot be null |
|
|
53
|
-
|
|
|
60
|
+
| array | | Array | a array or a collection
|
|
54
61
|
|
|
55
|
-
* @typedef {(0|''|6|'string'|'int64'|12|13|'memo'|'CDATA'|1|'byte'|2|'short'|3|'long'|15|'boolean'|4|5|'float'|'double'|7|'datetime'|'datetimetz'|'datetimenotz'|10|'date')} XtkType
|
|
62
|
+
* @typedef {(0|''|6|'string'|'int64'|12|13|'memo'|'CDATA'|1|'byte'|2|'short'|3|'long'|15|'boolean'|4|5|'float'|'double'|7|'datetime'|'datetimetz'|'datetimenotz'|10|'date'|14|'timespan'|'array')} XtkType
|
|
56
63
|
* @memberof Campaign
|
|
57
64
|
*/
|
|
58
65
|
|
|
@@ -85,10 +92,13 @@ class XtkCaster {
|
|
|
85
92
|
return null;
|
|
86
93
|
case 6: // FIELD_SZ
|
|
87
94
|
case "string":
|
|
95
|
+
case "uuid":
|
|
88
96
|
case "int64":
|
|
89
97
|
return "stringValue";
|
|
90
98
|
case 12: // FIELD_MEMO
|
|
91
99
|
case 13: // FIELD_MEMOSHORT
|
|
100
|
+
case "blob":
|
|
101
|
+
case "html":
|
|
92
102
|
case "memo":
|
|
93
103
|
case "CDATA":
|
|
94
104
|
return "memoValue";
|
|
@@ -97,8 +107,10 @@ class XtkCaster {
|
|
|
97
107
|
case 2: // FIELD_SHORT
|
|
98
108
|
case "short":
|
|
99
109
|
case 3: // FIELD_LONG
|
|
110
|
+
case "int":
|
|
100
111
|
case "long":
|
|
101
|
-
case
|
|
112
|
+
case "timespan":
|
|
113
|
+
case 15: // FIELD_BOOLEAN
|
|
102
114
|
case "boolean":
|
|
103
115
|
return "longValue";
|
|
104
116
|
case 4: // FIELD_FLOAT
|
|
@@ -137,6 +149,9 @@ class XtkCaster {
|
|
|
137
149
|
case 13: // FIELD_MEMOSHORT
|
|
138
150
|
case "string":
|
|
139
151
|
case "memo":
|
|
152
|
+
case "uuid":
|
|
153
|
+
case "blob":
|
|
154
|
+
case "html":
|
|
140
155
|
case "CDATA": {
|
|
141
156
|
return this.asString(value);
|
|
142
157
|
}
|
|
@@ -149,6 +164,7 @@ class XtkCaster {
|
|
|
149
164
|
return this.asShort(value);
|
|
150
165
|
}
|
|
151
166
|
case 3: // FIELD_LONG
|
|
167
|
+
case "int":
|
|
152
168
|
case "long": {
|
|
153
169
|
return this.asLong(value);
|
|
154
170
|
}
|
|
@@ -175,6 +191,13 @@ class XtkCaster {
|
|
|
175
191
|
case "date": {
|
|
176
192
|
return this.asDate(value);
|
|
177
193
|
}
|
|
194
|
+
case "array": {
|
|
195
|
+
return this.asArray(value);
|
|
196
|
+
}
|
|
197
|
+
case 14: // FIELD_TIMESPAN
|
|
198
|
+
case "timespan": {
|
|
199
|
+
return this.asTimespan(value);
|
|
200
|
+
}
|
|
178
201
|
default: {
|
|
179
202
|
throw CampaignException.BAD_PARAMETER("type", type, `Cannot convert value type='${type}', value='${value}'`);
|
|
180
203
|
}
|
|
@@ -354,7 +377,7 @@ class XtkCaster {
|
|
|
354
377
|
}
|
|
355
378
|
|
|
356
379
|
/**
|
|
357
|
-
* Convert a raw value into a
|
|
380
|
+
* Convert a raw value into a date. This is a UTC timestamp where time fields are 0
|
|
358
381
|
*
|
|
359
382
|
* @param {*} value is the raw value to convert
|
|
360
383
|
* @return {Date} a date
|
|
@@ -369,6 +392,35 @@ class XtkCaster {
|
|
|
369
392
|
}
|
|
370
393
|
return timestamp;
|
|
371
394
|
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Convert a raw value into an array (if it is not an array yet). Null and undefined will be
|
|
398
|
+
* converted into an empty array
|
|
399
|
+
*
|
|
400
|
+
* @param {*} value is the raw value to convert
|
|
401
|
+
* @return {Array} a array
|
|
402
|
+
*/
|
|
403
|
+
static asArray(value) {
|
|
404
|
+
if (value === null || value === undefined) return [];
|
|
405
|
+
if (Util.isArray(value)) return value;
|
|
406
|
+
return [value];
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Convert a raw value into a timespan, in seconds
|
|
411
|
+
* @param {*} value is the raw value to convert
|
|
412
|
+
* @returns is the time span, in seconds
|
|
413
|
+
*/
|
|
414
|
+
static asTimespan(value) {
|
|
415
|
+
if (value === null || value === undefined) return 0;
|
|
416
|
+
if ((typeof value) == "string") value = value.trim();
|
|
417
|
+
if (value === "" || value === true || value === false) return 0;
|
|
418
|
+
if (value !== value || value === Number.POSITIVE_INFINITY || value === Number.NEGATIVE_INFINITY) return 0;
|
|
419
|
+
// Number to timespan -> Consider as number of seconds
|
|
420
|
+
var timespan = XtkCaster.asLong(value);
|
|
421
|
+
return timespan;
|
|
422
|
+
}
|
|
423
|
+
|
|
372
424
|
}
|
|
373
425
|
|
|
374
426
|
exports.XtkCaster = XtkCaster;
|
package/test/application.test.js
CHANGED
|
@@ -290,7 +290,10 @@ describe('Schemas', function() {
|
|
|
290
290
|
<value name="prospect" label="Prospect" value="0" img=""/>
|
|
291
291
|
<value name="customer" label="Client" value="1" img=""/>
|
|
292
292
|
</enumeration>
|
|
293
|
-
<element name='recipient' label='Recipients'
|
|
293
|
+
<element name='recipient' label='Recipients'>
|
|
294
|
+
<attribute advanced="true" desc="Recipient sex" enum="nms:recipient:gender"
|
|
295
|
+
label="Gender" name="gender" sqlname="iGender" type="byte"/>
|
|
296
|
+
</element>
|
|
294
297
|
</schema>`);
|
|
295
298
|
var schema = newSchema(xml);
|
|
296
299
|
var enumerations = schema.enumerations;
|
|
@@ -303,6 +306,7 @@ describe('Schemas', function() {
|
|
|
303
306
|
// at least one img attribute
|
|
304
307
|
expect(enumerations.status2.name).toBe("status2");
|
|
305
308
|
expect(enumerations.status2.hasImage).toBe(false);
|
|
309
|
+
expect(schema.root.children["@gender"].enum).toBe("nms:recipient:gender");
|
|
306
310
|
})
|
|
307
311
|
|
|
308
312
|
it("Should list enumeration values", () => {
|
|
@@ -383,6 +387,41 @@ describe('Schemas', function() {
|
|
|
383
387
|
})
|
|
384
388
|
});
|
|
385
389
|
|
|
390
|
+
describe("Link", () => {
|
|
391
|
+
it("Should have a link element", () => {
|
|
392
|
+
var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
393
|
+
<element name='recipient' label='Recipients'>
|
|
394
|
+
<element integrity="neutral" label="Info on the email" name="emailInfo"
|
|
395
|
+
target="nms:address" type="link" unbound="true">
|
|
396
|
+
<join xpath-dst="@address" xpath-src="@email"/>
|
|
397
|
+
<join xpath-dst="@dst" xpath-src="@source"/>
|
|
398
|
+
</element>
|
|
399
|
+
</element>
|
|
400
|
+
</schema>`);
|
|
401
|
+
var schema = newSchema(xml);
|
|
402
|
+
var link = schema.root.children["emailInfo"];
|
|
403
|
+
expect(link.target).toBe("nms:address");
|
|
404
|
+
expect(link.integrity).toBe("neutral");
|
|
405
|
+
expect(link.isUnbound()).toBe(true);
|
|
406
|
+
expect(link.joins.length).toBe(2);
|
|
407
|
+
expect(link.joins[0].dst).toBe("@address");
|
|
408
|
+
expect(link.joins[0].src).toBe("@email");
|
|
409
|
+
|
|
410
|
+
xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
411
|
+
<element name='recipient' label='Recipients'>
|
|
412
|
+
<element integrity="neutral" label="Info on the email" name="emailInfo"
|
|
413
|
+
target="nms:address" type="link">
|
|
414
|
+
<join xpath-dst="@address" xpath-src="@email"/>
|
|
415
|
+
<join xpath-dst="@dst" xpath-src="@source"/>
|
|
416
|
+
</element>
|
|
417
|
+
</element>
|
|
418
|
+
</schema>`);
|
|
419
|
+
schema = newSchema(xml);
|
|
420
|
+
link = schema.root.children["emailInfo"];
|
|
421
|
+
expect(link.isUnbound()).toBe(false);
|
|
422
|
+
})
|
|
423
|
+
})
|
|
424
|
+
|
|
386
425
|
describe("getnodepath", () => {
|
|
387
426
|
var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
388
427
|
<element name='recipient' label='Recipients'>
|