@adobe/acc-js-sdk 1.1.21 → 1.1.23

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.21",
3
+ "version": "1.1.23",
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
  }
@@ -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
@@ -1065,7 +1068,7 @@ class XtkEnumeration {
1065
1068
  const e = new XtkEnumerationValue(child, this.baseType, this._localizationId);
1066
1069
  this.values._push(e.name, e);
1067
1070
  if (e.image != "") this.hasImage = true;
1068
- const stringValue = EntityAccessor.getAttributeAsString(child, "value");
1071
+ const stringValue = EntityAccessor.getAttributeAsString(child, "name");
1069
1072
  if (defaultValue == stringValue)
1070
1073
  this.default = e;
1071
1074
  }
@@ -1094,6 +1097,7 @@ class XtkEnumeration {
1094
1097
  * @private
1095
1098
  * @class
1096
1099
  * @constructor
1100
+ * @param {Campaign.Application|undefined} the application object which will be used to follow links and references
1097
1101
  * @augments Campaign.XtkSchemaNode
1098
1102
  * @param {XML.XtkObject} xml the schema definition
1099
1103
  * @memberof Campaign
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/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;
@@ -467,7 +467,7 @@ describe('Application', () => {
467
467
 
468
468
  it("Should support default values", () => {
469
469
  var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
470
- <enumeration basetype="byte" name="instanceType" default="1">
470
+ <enumeration basetype="byte" name="instanceType" default="master">
471
471
  <value label="One-off event" name="single" value="0"/>
472
472
  <value label="Reference recurrence" name="master" value="1"/>
473
473
  <value label="Instance of a recurrence" name="instance" value="2"/>
@@ -492,7 +492,7 @@ describe('Application', () => {
492
492
  <GetEntityIfMoreRecentResponse xmlns='urn:wpp:default' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
493
493
  <pdomDoc xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
494
494
  <schema name="profile" namespace="nms" xtkschema="xtk:schema">
495
- <enumeration basetype="byte" name="instanceType" default="1" label="Instance type">
495
+ <enumeration basetype="byte" name="instanceType" default="master" label="Instance type">
496
496
  <value label="One-off event" name="single" value="0"/>
497
497
  <value label="Reference recurrence" name="master" value="1"/>
498
498
  <value label="Instance of a recurrence" name="instance" value="2"/>
@@ -517,7 +517,7 @@ describe('Application', () => {
517
517
  <GetEntityIfMoreRecentResponse xmlns='urn:wpp:default' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
518
518
  <pdomDoc xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
519
519
  <schema name="profile" namespace="nms" xtkschema="xtk:schema">
520
- <enumeration basetype="byte" name="instanceType" default="1" label="Instance type">
520
+ <enumeration basetype="byte" name="instanceType" default="master" label="Instance type">
521
521
  <value label="One-off event" name="single" value="0"/>
522
522
  <value label="Reference recurrence" name="master" value="1"/>
523
523
  <value label="Instance of a recurrence" name="instance" value="2"/>
@@ -558,7 +558,7 @@ describe('Application', () => {
558
558
  <GetEntityIfMoreRecentResponse xmlns='urn:wpp:default' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
559
559
  <pdomDoc xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
560
560
  <schema name="profile" namespace="nms" xtkschema="xtk:schema">
561
- <enumeration basetype="byte" name="instanceType" default="1" label="Instance type">
561
+ <enumeration basetype="byte" name="instanceType" default="master" label="Instance type">
562
562
  <value label="One-off event" name="single" value="0"/>
563
563
  <value label="Reference recurrence" name="master" value="1"/>
564
564
  <value label="Instance of a recurrence" name="instance" value="2"/>
@@ -584,7 +584,7 @@ describe('Application', () => {
584
584
  <GetEntityIfMoreRecentResponse xmlns='urn:wpp:default' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
585
585
  <pdomDoc xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
586
586
  <schema name="profile" namespace="nms" xtkschema="xtk:schema">
587
- <enumeration basetype="byte" name="instanceType" default="1" label="Instance type">
587
+ <enumeration basetype="byte" name="instanceType" default="master" label="Instance type">
588
588
  <value label="One-off event" name="single" value="0"/>
589
589
  <value label="Reference recurrence" name="master" value="1"/>
590
590
  <value label="Instance of a recurrence" name="instance" value="2"/>
@@ -625,7 +625,7 @@ describe('Application', () => {
625
625
  <GetEntityIfMoreRecentResponse xmlns='urn:wpp:default' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
626
626
  <pdomDoc xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
627
627
  <schema name="profile" namespace="nms" xtkschema="xtk:schema">
628
- <enumeration basetype="byte" name="instanceType" default="1" label="Instance type">
628
+ <enumeration basetype="byte" name="instanceType" default="master" label="Instance type">
629
629
  <value label="One-off event" name="single" value="0"/>
630
630
  <value label="Reference recurrence" name="master" value="1"/>
631
631
  <value label="Instance of a recurrence" name="instance" value="2"/>
@@ -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
  });
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");