@adobe/acc-js-sdk 1.1.22 → 1.1.24

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/acc-js-sdk",
3
- "version": "1.1.22",
3
+ "version": "1.1.24",
4
4
  "description": "ACC Javascript SDK",
5
5
  "main": "src/index.js",
6
6
  "homepage": "https://github.com/adobe/acc-js-sdk#readme",
@@ -21,7 +21,7 @@ const utils = require("./utils.js");
21
21
  ( async () => {
22
22
 
23
23
  await utils.sample({
24
- title: "Testing generating and importing packages",
24
+ title: "Testing generating and importing packages (in XML)",
25
25
  labels: [ "Basics", "Packages", "xtk:builder", "InstallPackage" ],
26
26
  description: `The xtkBuilder.installPackage() can be used to import packages`,
27
27
  code: async() => {
@@ -51,6 +51,40 @@ const utils = require("./utils.js");
51
51
  // Install package. The package is in XML format and we set the timeout to 5 mins to prevent any issues
52
52
  console.log(`Installing package`, DomUtil.toXMLString(doc));
53
53
  await NLWS.xml.pushDown({ timeout: 5*60*1000 }).xtkBuilder.installPackage(doc);
54
+ });
55
+ }
56
+ });
57
+
58
+ await utils.sample({
59
+ title: "Testing generating and importing packages (in JSON)",
60
+ labels: [ "Basics", "Packages", "xtk:builder", "InstallPackage" ],
61
+ description: `The xtkBuilder.installPackage() can be used to import packages`,
62
+ code: async() => {
63
+ return await utils.logon(async (client, NLWS) => {
64
+ console.log(`Generating package with a service named 'newsletterTest'`);
65
+
66
+ const jsonPackage = {
67
+ package: {
68
+ buildNumber: "*",
69
+ buildVersion: "*",
70
+ entities: {
71
+ schema:"nms:service",
72
+ service: {
73
+ label: "NewsletterTest",
74
+ name: "newsletterTest",
75
+ folder: {
76
+ _operation: "none",
77
+ name: "nmsSetOfServices"
78
+ },
79
+ visitorFolder: {
80
+ _operation: "none",
81
+ name: "nmsVisitor"
82
+ }
83
+ }
84
+ }
85
+ }
86
+ };
87
+ await NLWS.pushDown({ timeout: 5*60*1000 }).xtkBuilder.installPackage(jsonPackage);
54
88
  console.log(`Package installed`);
55
89
  });
56
90
  }
@@ -19,7 +19,7 @@ governing permissions and limitations under the License.
19
19
  * https://docs.adobe.com/content/help/en/campaign-classic/technicalresources/api/c-Application.html
20
20
  *
21
21
  *********************************************************************************/
22
- const { DomException, XPath } = require('./domUtil.js');
22
+ const { DomException, DomUtil, XPath } = require('./domUtil.js');
23
23
  const XtkCaster = require('./xtkCaster.js').XtkCaster;
24
24
  const EntityAccessor = require('./entityAccessor.js').EntityAccessor;
25
25
  const { ArrayMap } = require('./util.js');
@@ -35,11 +35,14 @@ const PACKAGE_STATUS = { "never": 0, "always": 1, "default": 2, "preCreate": 3 }
35
35
  // ========================================================================================
36
36
 
37
37
  /**
38
- * Creates a schema object from an XML representation
39
- * This function is not intended to be used publicly.
38
+ * Creates a schema object from an XML representation.
39
+ * The returned XtkSchema object will not be added to the application schema cache.
40
+ * If you do not pass an application object, it will not be possible to follow
41
+ * references or get enumeration values from the returned XtkSchema
40
42
  *
41
43
  * @private
42
44
  * @param {DOMElement|DOMDocument} xml the XML document or element representing the schema
45
+ * @param {Campaign.Application|undefined} the application object which will be used to follow links and references
43
46
  * @returns {XtkSchema} a schema object
44
47
  * @see {@link XtkSchema}
45
48
  * @memberof Campaign
@@ -416,6 +419,18 @@ class XtkSchemaNode {
416
419
  */
417
420
  this.childrenCount = 0;
418
421
 
422
+ /**
423
+ * Get the default value of a node
424
+ * @type {string}
425
+ */
426
+ this.default = EntityAccessor.getAttributeAsString(xml, "default");
427
+
428
+ /**
429
+ * Get the default translation for the default value of a node
430
+ * @type {string}
431
+ */
432
+ this.translatedDefault = EntityAccessor.getAttributeAsString(xml, "translatedDefault");
433
+
419
434
  /**
420
435
  * Indicates if the node is the root node, i.e. the first child node of the schema, whose name is the same as the schema name
421
436
  * @type {boolean}
@@ -636,6 +651,16 @@ class XtkSchemaNode {
636
651
  this.expr = EntityAccessor.getAttributeAsString(child, "expr");
637
652
  this.isCalculated = false;
638
653
  }
654
+ if (child.tagName === "default") {
655
+ if(this.unbound) {
656
+ // Default value for a collection of elements
657
+ const xml = DomUtil.parse(`<xml>${child.textContent}</xml>`);
658
+ const json = DomUtil.toJSON(xml);
659
+ this.default = XtkCaster.asArray(json[this.name]);
660
+ } else {
661
+ this.default = child.textContent;
662
+ }
663
+ }
639
664
  }
640
665
  for (const childNode of childNodes) {
641
666
  this.children._push(childNode.name, childNode);
@@ -1094,6 +1119,7 @@ class XtkEnumeration {
1094
1119
  * @private
1095
1120
  * @class
1096
1121
  * @constructor
1122
+ * @param {Campaign.Application|undefined} the application object which will be used to follow links and references
1097
1123
  * @augments Campaign.XtkSchemaNode
1098
1124
  * @param {XML.XtkObject} xml the schema definition
1099
1125
  * @memberof Campaign
package/src/cache.js CHANGED
@@ -12,7 +12,7 @@ governing permissions and limitations under the License.
12
12
  (function() {
13
13
  "use strict";
14
14
 
15
- const { Util } = require("./util");
15
+ const { Util } = require("./util.js");
16
16
 
17
17
 
18
18
  /**********************************************************************************
package/src/campaign.js CHANGED
@@ -41,6 +41,7 @@ const { Util } = require("./util.js");
41
41
  static FILE_UPLOAD_FAILED(name, details) { return new CampaignException(undefined, 500, 16384, `SDK-000013 "Failed to upload file ${name}`, details); }
42
42
  static REPORT_FETCH_FAILED(name, details) { return new CampaignException(undefined, 500, 16384, `SDK-000014 Failed to fetch report ${name}`, details); }
43
43
  static FEATURE_NOT_SUPPORTED(name) { return new CampaignException(undefined, 500, 16384, `SDK-000015 ${name} feature is not supported by the ACC instance`); }
44
+ static REQUEST_ABORTED( ) { return new CampaignException(undefined, 500, -53, `SDK-000016 Request was aborted by the client`); }
44
45
 
45
46
 
46
47
  /**
@@ -214,6 +215,9 @@ function makeCampaignException(call, err) {
214
215
  if (err instanceof CampaignException)
215
216
  return err;
216
217
 
218
+ if (err && err.name == "AbortError")
219
+ throw CampaignException.REQUEST_ABORTED();
220
+
217
221
  // Wraps DOM exceptions which can occur when dealing with malformed XML
218
222
  const ctor = Object.getPrototypeOf(err).constructor;
219
223
  if (ctor && ctor.name == "DOMException") {
package/src/client.js CHANGED
@@ -33,7 +33,7 @@ const MethodCache = require('./methodCache.js').MethodCache;
33
33
  const OptionCache = require('./optionCache.js').OptionCache;
34
34
  const CacheRefresher = require('./cacheRefresher.js').CacheRefresher;
35
35
  const request = require('./transport.js').request;
36
- const Application = require('./application.js').Application;
36
+ const { Application, newSchema } = require('./application.js');
37
37
  const EntityAccessor = require('./entityAccessor.js').EntityAccessor;
38
38
  const { Util } = require('./util.js');
39
39
  const { XtkJobInterface } = require('./xtkJob.js');
@@ -1629,6 +1629,20 @@ class Client {
1629
1629
  return outputParams[0].value;
1630
1630
  }
1631
1631
 
1632
+ /**
1633
+ * Creates a schema object from an XML representation.
1634
+ * The returned XtkSchema object will not be added to the application schema cache.
1635
+ * If you do not pass an application object, it will not be possible to follow
1636
+ * references or get enumeration values from the returned XtkSchema
1637
+ *
1638
+ * @param {DOMElement|DOMDocument} xml the XML document or element representing the schema
1639
+ * @returns {Campaign.XtkSchema} a schema object
1640
+ * @see {@link Campaign.XtkSchema}
1641
+ */
1642
+ newSchema(xml) {
1643
+ return newSchema(xml, this.application);
1644
+ }
1645
+
1632
1646
  /**
1633
1647
  * Get a compiled schema (not a source schema) definition as a DOM or JSON object depending on hte current representation
1634
1648
  *
package/src/domUtil.js CHANGED
@@ -114,7 +114,6 @@ class DomUtil {
114
114
  const doc = dom.window.document;
115
115
  doc.__jsdom__ = dom;
116
116
  return doc;
117
- //return parseXML(xmlString);
118
117
  }
119
118
 
120
119
  /**
package/src/transport.js CHANGED
@@ -74,6 +74,7 @@ if (!Util.isBrowser()) {
74
74
  headers: options.headers,
75
75
  data: options.data,
76
76
  timeout: requestOptions.timeout || 5000,
77
+ signal: requestOptions.signal,
77
78
  };
78
79
  return axios(request)
79
80
  .then((response) => {
@@ -104,8 +105,8 @@ if (!Util.isBrowser()) {
104
105
  *********************************************************************************/
105
106
  else {
106
107
 
107
- const request = function(options) {
108
-
108
+ const request = function(options, requestOptions) {
109
+ requestOptions = requestOptions || {};
109
110
  const headers = new Headers();
110
111
  for (var k in options.headers) {
111
112
  headers.append(k, options.headers[k]);
@@ -114,6 +115,7 @@ if (!Util.isBrowser()) {
114
115
  method: options.method,
115
116
  headers: headers,
116
117
  body: options.data,
118
+ signal : requestOptions.signal,
117
119
  });
118
120
 
119
121
  const p = fetch(r).then(async (response) => {
@@ -123,6 +125,9 @@ if (!Util.isBrowser()) {
123
125
  return blob.text();
124
126
  });
125
127
  }).catch((ex) => {
128
+ if(ex.name === 'AbortError'){
129
+ throw ex;
130
+ }
126
131
  const proto = Object.getPrototypeOf(ex);
127
132
  if (proto.constructor.name == "HttpError")
128
133
  throw ex;
@@ -1939,6 +1939,86 @@ describe('Application', () => {
1939
1939
  });
1940
1940
  });
1941
1941
 
1942
+ describe("default values", () => {
1943
+
1944
+ it("Should extract default", async () => {
1945
+ var xml = DomUtil.parse(`<schema namespace='xtk' name='workflow'>
1946
+ <element name='workflow' label='Workflow'>
1947
+ <attribute default="true" label="In simulation mode: execute" name="runOnsimulation" type="boolean" xml="true"/>
1948
+ </element>
1949
+ </schema>`);
1950
+ var schema = newSchema(xml);
1951
+
1952
+ var node = await schema.root.findNode("@runOnsimulation");
1953
+ expect(node).toMatchObject({ name:"@runOnsimulation", childrenCount:0, default: 'true' });
1954
+ });
1955
+
1956
+ it("Should extract default values of a collection of elements", async () => {
1957
+ var xml = DomUtil.parse(`<schema namespace='xtk' name='workflow'>
1958
+ <element name='workflow' label='Workflow'>
1959
+ <element name="fork" label="Fork">
1960
+ <element label="Transitions" name="transitions" xml="true">
1961
+ <element label="transition" name="transition" ref="transition" unbound="true" xml="true">
1962
+ <default>
1963
+ &lt;transition name="transition1" enabled="true"/&gt;
1964
+ &lt;transition name="transition2" enabled="true"/&gt;
1965
+ </default>
1966
+ </element>
1967
+ </element>
1968
+ </element>
1969
+ </element>
1970
+ </schema>`);
1971
+ var schema = newSchema(xml);
1972
+
1973
+ var node = await schema.root.findNode("fork/transitions/transition");
1974
+ expect(node).toMatchObject({ name:"transition", childrenCount:0, default: [
1975
+ {
1976
+ "enabled": "true",
1977
+ "name": "transition1"
1978
+ },
1979
+ {
1980
+ "enabled": "true",
1981
+ "name": "transition2"
1982
+ }
1983
+ ] });
1984
+ });
1985
+
1986
+ it("Should extract default values of a memo", async () => {
1987
+ var xml = DomUtil.parse(`<schema namespace='xtk' name='workflow'>
1988
+ <element name='workflow' label='Workflow'>
1989
+ <element name="directorywatcher" label="File collector">
1990
+ <element name="period" type="memo" label="Schedule">
1991
+ <default>"m_abDay='7' m_abDay[0]='0' m_abDay[1]='0'"</default>
1992
+ </element>
1993
+ </element>
1994
+ </element>
1995
+ </schema>`);
1996
+ var schema = newSchema(xml);
1997
+
1998
+ var node = await schema.root.findNode("directorywatcher/period");
1999
+ expect(node).toMatchObject({ name:"period", childrenCount:0, default: "\"m_abDay='7' m_abDay[0]='0' m_abDay[1]='0'\"" });
2000
+ });
2001
+
2002
+ it("Should extract translatedDefault", async () => {
2003
+ var xml = DomUtil.parse(`<schema namespace='xtk' name='workflow'>
2004
+ <element name='workflow' label='Workflow'>
2005
+ <element name="delivery" label="Delivery">
2006
+ <element label="Transitions" name="transitions" xml="true">
2007
+ <element label="transition" name="done" xml="true">
2008
+ <attribute label="Label" name="label" type="string" translatedDefault="'Ok'" xml="true"/>
2009
+ </element>
2010
+ </element>
2011
+ </element>
2012
+ </element>
2013
+ </schema>`);
2014
+ var schema = newSchema(xml);
2015
+
2016
+ var node = await schema.root.findNode("delivery/transitions/done/@label");
2017
+ expect(node).toMatchObject({ name:"@label", childrenCount:0, translatedDefault: "'Ok'" });
2018
+ });
2019
+
2020
+ });
2021
+
1942
2022
  describe("toString", () => {
1943
2023
  var xml = DomUtil.parse(`<schema namespace='nms' name='recipient' label="Recipients" labelSingular="Recipient">
1944
2024
  <element name='recipient'>
@@ -3702,4 +3702,72 @@ describe('ACC Client', function () {
3702
3702
  });
3703
3703
  });
3704
3704
 
3705
+ describe("New schema", () => {
3706
+ it("Should create XtkSchema from XML Document", async () => {
3707
+ const client = await Mock.makeClient();
3708
+ const xml = DomUtil.parse("<schema namespace='nms' name='recipient'></schema>");
3709
+ const schema = client.newSchema(xml);
3710
+ expect(client.application).toBeNull(); // client not logged. newSchema should support undefined application object
3711
+ expect(schema.name).toBe('recipient');
3712
+ });
3713
+
3714
+ it("Should create XtkSchema from XML Element", async () => {
3715
+ const client = await Mock.makeClient();
3716
+ const xml = DomUtil.parse("<schema namespace='nms' name='recipient'></schema>");
3717
+ const schema = client.newSchema(xml.documentElement);
3718
+ expect(client.application).toBeNull(); // client not logged. newSchema should support undefined application object
3719
+ expect(schema.name).toBe('recipient');
3720
+ });
3721
+
3722
+ it("Should create XtkSchema from XML Document on a logged client", async () => {
3723
+ const client = await Mock.makeClient();
3724
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
3725
+ await client.NLWS.xtkSession.logon();
3726
+ expect(client.application).not.toBeNull();
3727
+ const xml = DomUtil.parse("<schema namespace='nms' name='recipient'></schema>");
3728
+ const schema = client.newSchema(xml);
3729
+ expect(schema.name).toBe('recipient');
3730
+ });
3731
+
3732
+ it("Should not add created XtkSchema to the application cache", async () => {
3733
+ const client = await Mock.makeClient();
3734
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
3735
+ await client.NLWS.xtkSession.logon();
3736
+ const xml = DomUtil.parse("<schema namespace='nms' name='recipient'></schema>");
3737
+ /*const schema = */client.newSchema(xml);
3738
+ expect(client.application._schemaCache._schemas['nms:recipient']).toBeUndefined()
3739
+ });
3740
+
3741
+ it("Should follow references", async () => {
3742
+ const client = await Mock.makeClient();
3743
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
3744
+ await client.NLWS.xtkSession.logon();
3745
+ const xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
3746
+ <element name='recipient' label='Recipients'>
3747
+ <element name="jobs" target="xtk:job" type="link" unbound="true">
3748
+ </element>
3749
+ </element>
3750
+ </schema>`);
3751
+ const schema = client.newSchema(xml);
3752
+ const jobs = schema.root.children["jobs"];
3753
+ expect(jobs.target).toBe("xtk:job");
3754
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_JOB_SCHEMA_RESPONSE);
3755
+ const target = await jobs.linkTarget();
3756
+ expect(target.name).toBe("job");
3757
+ });
3758
+
3759
+ it("Should not follow references if no application object", async () => {
3760
+ const client = await Mock.makeClient();
3761
+ const xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
3762
+ <element name='recipient' label='Recipients'>
3763
+ <element name="jobs" target="xtk:job" type="link" unbound="true">
3764
+ </element>
3765
+ </element>
3766
+ </schema>`);
3767
+ const schema = client.newSchema(xml);
3768
+ const jobs = schema.root.children["jobs"];
3769
+ expect(jobs.target).toBe("xtk:job");
3770
+ await expect(jobs.linkTarget()).rejects.toThrow("Cannot read property 'getSchema' of null");
3771
+ });
3772
+ });
3705
3773
  });
@@ -943,5 +943,5 @@ describe('DomUtil', function() {
943
943
  expect(new XPathElement("..").isParent()).toBe(true);
944
944
  expect(new XPathElement(".").isParent()).toBe(false);
945
945
  })
946
- })
946
+ });
947
947
  });
package/test/soap.test.js CHANGED
@@ -551,7 +551,7 @@ describe('SOAP', function() {
551
551
  return call.execute().then(() => {
552
552
  expect(call.getNextString()).toBe("XSV-350008 Session has expired or is invalid. Please reconnect.");
553
553
  });
554
- });
554
+ });
555
555
 
556
556
  it("Should should read Element response", function() {
557
557
  const xml = '<root att="Hello"><child/></root>';
@@ -853,6 +853,18 @@ describe("Campaign exception", () => {
853
853
 
854
854
  })
855
855
 
856
+ it("aborting pending HTTP calls to avoid unnecessary attempts to re-render.", function() {
857
+ const transport = function() {
858
+ return Promise.reject({name: 'AbortError'});
859
+ };
860
+ const call = makeSoapMethodCall(transport, "xtk:session", "Date", "$session$", "$security$");
861
+ return call.execute().catch((ex) => {
862
+ expect(ex.statusCode).toBe(500);
863
+ expect(ex.faultCode).toBe(-53);
864
+ expect(ex.message).toBe(`500 - Error -53: SDK-000016 Request was aborted by the client`);
865
+ });
866
+ });
867
+
856
868
  describe("User agent", () => {
857
869
  it("Should set user agent", () => {
858
870
  const call = makeSoapMethodCall(undefined, "xtk:session", "Date", "$session$", "$security$", "My User Agent");