@adobe/acc-js-sdk 1.1.26 → 1.1.28

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.26",
3
+ "version": "1.1.28",
4
4
  "description": "ACC Javascript SDK",
5
5
  "main": "src/index.js",
6
6
  "homepage": "https://github.com/adobe/acc-js-sdk#readme",
@@ -95,7 +95,8 @@ class SchemaCache {
95
95
  if (schema === undefined) {
96
96
  schema = await this._client.application._getSchema(schemaId);
97
97
  if (!schema) schema = null; // null = not found
98
- this._schemas[schemaId] = schema;
98
+ if (!schemaId.startsWith("temp:group:"))
99
+ this._schemas[schemaId] = schema;
99
100
  }
100
101
  return schema;
101
102
  }
package/src/client.js CHANGED
@@ -1740,16 +1740,55 @@ class Client {
1740
1740
  async getSchema(schemaId, representation, internal) {
1741
1741
  var entity = await this._entityCache.get("xtk:schema", schemaId);
1742
1742
  if (!entity) {
1743
- entity = await this.getEntityIfMoreRecent("xtk:schema", schemaId, "xml", internal);
1744
- if (entity) {
1745
- const impls = DomUtil.getAttributeAsString(entity, "implements");
1746
- if (impls === "xtk:persist" && schemaId !== "xtk:session" && schemaId !== "xtk:persist") {
1747
- // Ensure xtk:persist is present by loading the xtk:session schema
1748
- await this.getSchema("xtk:session", "xml", true);
1743
+ // special case of "temp:group:*" schemas for nms:group
1744
+ // Schema "temp:group:*" is not cached because life cycle of this kind of schema is not the same as the others schemas
1745
+ if (schemaId.startsWith("temp:group:")) {
1746
+ const parts = schemaId.split(":");
1747
+ let queryDef = {
1748
+ "schema": "nms:group",
1749
+ "operation": "get",
1750
+ "select": {
1751
+ "node": [
1752
+ { "expr": "@id" },
1753
+ { "expr": "extension" }
1754
+ ]
1755
+ },
1756
+ "where": {
1757
+ "condition": [
1758
+ { "expr": "@id=" + XtkCaster.asLong(parts[2]) }
1759
+ ]
1760
+ }
1761
+ };
1762
+ // Convert to current representation
1763
+ queryDef = this._convertToRepresentation(queryDef, "SimpleJson", "xml");
1764
+ const query = this.NLWS.xml.xtkQueryDef.create(queryDef);
1765
+ try {
1766
+ const groupSchema = await query.executeQuery();
1767
+ const extension = DomUtil.findElement(groupSchema, "extension");
1768
+ if (extension) {
1769
+ entity = extension;
1770
+ } else {
1771
+ entity = null;
1772
+ }
1773
+ } catch (ex) {
1774
+ if (ex.name == 'CampaignException' && ex.errorCode == 'SOP-330011') {
1775
+ entity = null;
1776
+ } else {
1777
+ throw ex;
1778
+ }
1779
+ }
1780
+ } else {
1781
+ entity = await this.getEntityIfMoreRecent("xtk:schema", schemaId, "xml", internal);
1782
+ if (entity) {
1783
+ const impls = DomUtil.getAttributeAsString(entity, "implements");
1784
+ if (impls === "xtk:persist" && schemaId !== "xtk:session" && schemaId !== "xtk:persist") {
1785
+ // Ensure xtk:persist is present by loading the xtk:session schema
1786
+ await this.getSchema("xtk:session", "xml", true);
1787
+ }
1788
+ await this._entityCache.put("xtk:schema", schemaId, entity);
1789
+ await this._methodCache.put(entity);
1790
+ }
1749
1791
  }
1750
- await this._entityCache.put("xtk:schema", schemaId, entity);
1751
- await this._methodCache.put(entity);
1752
- }
1753
1792
  }
1754
1793
  entity = this._toRepresentation(entity, representation);
1755
1794
  return entity;
package/src/domUtil.js CHANGED
@@ -380,13 +380,22 @@ class DomUtil {
380
380
  return doc;
381
381
  }
382
382
 
383
+ // Get the text of a node. Will return the text if the xml node contains
384
+ // only text and cdata nodes. Otherwise will return null
383
385
  static _getTextIfTextNode(xml) {
384
- const child = xml.firstChild;
386
+ let child = xml.firstChild;
385
387
  if (!child) return null; // no children
386
388
  if (xml.hasAttributes()) return null; // no attributes
387
- if (child.nextSibling) return null; // more than 1 child
388
- if (child.nodeType !== 3 && child.nodeType !== 4) return null;
389
- const text = child.nodeValue;
389
+ let text = "";
390
+ while (child) {
391
+ // if child node is not text or cdata, it means we have a mix
392
+ // of text children and non-text children => we do not consider
393
+ // the xml node to be a text-only node
394
+ if (child.nodeType !== 3 && child.nodeType !== 4)
395
+ return null;
396
+ text = text + child.nodeValue;
397
+ child = child.nextSibling;
398
+ }
390
399
  return text;
391
400
  }
392
401
 
@@ -1499,6 +1499,66 @@ describe('Application', () => {
1499
1499
  const isoA3 = await recipient.root.findNode("country/@isoA3");
1500
1500
  expect(isoA3).toBeFalsy();
1501
1501
  });
1502
+
1503
+ it("Should not cache temp:group: schemas", async () => {
1504
+ const client = await Mock.makeClient();
1505
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
1506
+ await client.NLWS.xtkSession.logon();
1507
+
1508
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
1509
+ client._transport.mockReturnValueOnce(Promise.resolve(`<?xml version='1.0'?>
1510
+ <SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns='urn:xtk:queryDef' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
1511
+ <SOAP-ENV:Body>
1512
+ <ExecuteQueryResponse xmlns='urn:xtk:queryDef' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
1513
+ <pdomOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
1514
+ <group expirationDate="" folder-id="1199" id="2200" label="testlist" name="LST260" schema="nms:recipient" type="1">
1515
+ <extension label="email is not empty" mappingType="sql" name="query" namespace="temp">
1516
+ <element advanced="false" dataSource="nms:extAccount:ffda" label="email is not empty" name="query" pkSequence="" sqltable="grp2200" unbound="false">
1517
+ <compute-string expr=""/>
1518
+ <key internal="true" name="internal">
1519
+ <keyfield xpath="@id"/>
1520
+ </key>
1521
+ <attribute advanced="false" belongsTo="@id" label="Primary key" length="0" name="id" notNull="false" sql="true" sqlname="uId" type="uuid" xml="false"/>
1522
+ <element advanced="false" externalJoin="true" label="Targeting dimension" name="target" revLink="" target="nms:recipient" type="link" unbound="false">
1523
+ <join xpath-dst="@id" xpath-src="@id"/>
1524
+ </element>
1525
+ </element>
1526
+ </extension>
1527
+ </group>
1528
+ </pdomOutput>
1529
+ </ExecuteQueryResponse>
1530
+ </SOAP-ENV:Body>
1531
+ </SOAP-ENV:Envelope>`));
1532
+ const group = await client.application.getSchema('temp:group:2200');
1533
+ expect(group.label).toBe("email is not empty");
1534
+
1535
+ // return updated schema with label changed
1536
+ client._transport.mockReturnValueOnce(Promise.resolve(`<?xml version='1.0'?>
1537
+ <SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns='urn:xtk:queryDef' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
1538
+ <SOAP-ENV:Body>
1539
+ <ExecuteQueryResponse xmlns='urn:xtk:queryDef' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
1540
+ <pdomOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
1541
+ <group expirationDate="" folder-id="1199" id="2200" label="testlist" name="LST260" schema="nms:recipient" type="1">
1542
+ <extension label="email is empty" mappingType="sql" name="query" namespace="temp">
1543
+ <element advanced="false" dataSource="nms:extAccount:ffda" label="email is empty" name="query" pkSequence="" sqltable="grp2200" unbound="false">
1544
+ <compute-string expr=""/>
1545
+ <key internal="true" name="internal">
1546
+ <keyfield xpath="@id"/>
1547
+ </key>
1548
+ <attribute advanced="false" belongsTo="@id" label="Primary key" length="0" name="id" notNull="false" sql="true" sqlname="uId" type="uuid" xml="false"/>
1549
+ <element advanced="false" externalJoin="true" label="Targeting dimension" name="target" revLink="" target="nms:recipient" type="link" unbound="false">
1550
+ <join xpath-dst="@id" xpath-src="@id"/>
1551
+ </element>
1552
+ </element>
1553
+ </extension>
1554
+ </group>
1555
+ </pdomOutput>
1556
+ </ExecuteQueryResponse>
1557
+ </SOAP-ENV:Body>
1558
+ </SOAP-ENV:Envelope>`));
1559
+ const group2 = await client.application.getSchema('temp:group:2200');
1560
+ expect(group2.label).toBe("email is empty");
1561
+ });
1502
1562
  });
1503
1563
 
1504
1564
  describe("Ref nodes", () => {
@@ -434,6 +434,129 @@ describe('ACC Client', function () {
434
434
  await client.NLWS.xtkSession.logoff();
435
435
  });
436
436
 
437
+ it("Should return temp group schema definition", async () => {
438
+ const client = await Mock.makeClient();
439
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
440
+ await client.NLWS.xtkSession.logon();
441
+
442
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
443
+ client._transport.mockReturnValueOnce(Promise.resolve(`<?xml version='1.0'?>
444
+ <SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns='urn:xtk:queryDef' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
445
+ <SOAP-ENV:Body>
446
+ <ExecuteQueryResponse xmlns='urn:xtk:queryDef' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
447
+ <pdomOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
448
+ <group expirationDate="" folder-id="1199" id="2200" label="testlist" name="LST260" schema="nms:recipient" type="1">
449
+ <extension label="email is not empty" mappingType="sql" name="query" namespace="temp">
450
+ <element advanced="false" dataSource="nms:extAccount:ffda" label="email is not empty" name="query" pkSequence="" sqltable="grp2200" unbound="false">
451
+ <compute-string expr=""/>
452
+ <key internal="true" name="internal">
453
+ <keyfield xpath="@id"/>
454
+ </key>
455
+ <attribute advanced="false" belongsTo="@id" label="Primary key" length="0" name="id" notNull="false" sql="true" sqlname="uId" type="uuid" xml="false"/>
456
+ <element advanced="false" externalJoin="true" label="Targeting dimension" name="target" revLink="" target="nms:recipient" type="link" unbound="false">
457
+ <join xpath-dst="@id" xpath-src="@id"/>
458
+ </element>
459
+ </element>
460
+ </extension>
461
+ <desc><![CDATA[]]></desc>
462
+ <folder _cs="Lists" fullName="/Profiles and Targets/Lists/" id="1199"/>
463
+ </group>
464
+ </pdomOutput></ExecuteQueryResponse>
465
+ </SOAP-ENV:Body>
466
+ </SOAP-ENV:Envelope>`));
467
+
468
+ var schema = await client.getSchema("temp:group:2200");
469
+ expect(schema["namespace"]).toBe("temp");
470
+ expect(schema["name"]).toBe("query");
471
+ expect(schema["element"].label).toBe("email is not empty");
472
+
473
+ // Update label of first element
474
+ client._transport.mockReturnValueOnce(Promise.resolve(`<?xml version='1.0'?>
475
+ <SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns='urn:xtk:queryDef' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
476
+ <SOAP-ENV:Body>
477
+ <ExecuteQueryResponse xmlns='urn:xtk:queryDef' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
478
+ <pdomOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
479
+ <group expirationDate="" folder-id="1199" id="2200" label="testlist" name="LST260" schema="nms:recipient" type="1">
480
+ <extension label="email is not empty" mappingType="sql" name="query" namespace="temp">
481
+ <element advanced="false" dataSource="nms:extAccount:ffda" label="email is empty" name="query" pkSequence="" sqltable="grp2200" unbound="false">
482
+ <compute-string expr=""/>
483
+ <key internal="true" name="internal">
484
+ <keyfield xpath="@id"/>
485
+ </key>
486
+ <attribute advanced="false" belongsTo="@id" label="Primary key" length="0" name="id" notNull="false" sql="true" sqlname="uId" type="uuid" xml="false"/>
487
+ <element advanced="false" externalJoin="true" label="Targeting dimension" name="target" revLink="" target="nms:recipient" type="link" unbound="false">
488
+ <join xpath-dst="@id" xpath-src="@id"/>
489
+ </element>
490
+ </element>
491
+ </extension>
492
+ <desc><![CDATA[]]></desc>
493
+ <folder _cs="Lists" fullName="/Profiles and Targets/Lists/" id="1199"/>
494
+ </group>
495
+ </pdomOutput></ExecuteQueryResponse>
496
+ </SOAP-ENV:Body>
497
+ </SOAP-ENV:Envelope>`));
498
+ var schema = await client.getSchema("temp:group:2200");
499
+ expect(schema["namespace"]).toBe("temp");
500
+ expect(schema["name"]).toBe("query");
501
+ //check that we have the updated label
502
+ expect(schema["element"].label).toBe("email is empty");
503
+ });
504
+
505
+ it("Should return null when temp group schema definition is empty", async () => {
506
+ const client = await Mock.makeClient();
507
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
508
+ await client.NLWS.xtkSession.logon();
509
+
510
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
511
+ client._transport.mockReturnValueOnce(Promise.resolve(`<?xml version='1.0'?>
512
+ <SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns='urn:xtk:queryDef' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
513
+ <SOAP-ENV:Body>
514
+ <ExecuteQueryResponse xmlns='urn:xtk:queryDef' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
515
+ <pdomOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
516
+ <group />
517
+ </pdomOutput></ExecuteQueryResponse>
518
+ </SOAP-ENV:Body>
519
+ </SOAP-ENV:Envelope>`));
520
+
521
+ var schema = await client.getSchema("temp:group:2200");
522
+ expect(schema).toBeNull();
523
+ });
524
+
525
+ it("Should return null when temp group schema definition does not exist", async () => {
526
+ const client = await Mock.makeClient();
527
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
528
+ await client.NLWS.xtkSession.logon();
529
+
530
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
531
+ client._transport.mockReturnValueOnce(Promise.resolve(`<?xml version='1.0' encoding='UTF-8'?>
532
+ <SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ns='http://xml.apache.org/xml-soap'>
533
+ <SOAP-ENV:Body>
534
+ <SOAP-ENV:Fault>
535
+ <faultcode>faultcode</faultcode>
536
+ <faultstring>SOP-330011</faultstring>
537
+ <detail>"Error while executing the method 'ExecuteQuery' of service 'xtk:queryDef'."</detail>
538
+ </SOAP-ENV:Fault>
539
+ </SOAP-ENV:Body>
540
+ </SOAP-ENV:Envelope>`));
541
+
542
+ var schema = await client.getSchema("temp:group:2200");
543
+ expect(schema).toBeNull();
544
+ });
545
+
546
+ it("Should rethrow exception when exception is not related to not existing group", async () => {
547
+ const client = await Mock.makeClient();
548
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
549
+ await client.NLWS.xtkSession.logon();
550
+
551
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
552
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
553
+
554
+ try {
555
+ var schema = await client.getSchema("temp:group:2200");
556
+ expect(schema).toBe('not be called')
557
+ } catch (ex) {}
558
+ });
559
+
437
560
  it("Should return sys enum definition", async () => {
438
561
  const client = await Mock.makeClient({ representation: "BadgerFish" });
439
562
  client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
@@ -3874,7 +3997,9 @@ describe('ACC Client', function () {
3874
3997
  const schema = client.newSchema(xml);
3875
3998
  const jobs = schema.root.children["jobs"];
3876
3999
  expect(jobs.target).toBe("xtk:job");
3877
- await expect(jobs.linkTarget()).rejects.toThrow("Cannot read property 'getSchema' of null");
4000
+ // node 14 throws "Cannot read property 'getSchema' of null"
4001
+ // node 16+ throws "Cannot read properties of null (reading 'getSchema')"
4002
+ await expect(jobs.linkTarget()).rejects.toThrow(/Cannot read (.*getSchema.*of null)|(.*of null.*getSchema)/);
3878
4003
  });
3879
4004
  });
3880
4005
  });
@@ -958,4 +958,21 @@ describe('DomUtil', function() {
958
958
  expect(new XPathElement(".").isParent()).toBe(false);
959
959
  })
960
960
  });
961
+
962
+ it("Should handle content made of CDATA text", () => {
963
+ const xml = DomUtil.parse(`<delivery>
964
+ <source><![CDATA[<head></head>]]></source>
965
+ </delivery>`);
966
+ const json = DomUtil.toJSON(xml, "SimpleJson");
967
+ expect(json.$source).toBe("<head></head>")
968
+ });
969
+ it("Should handle content made of multiple CDATA text", () => {
970
+ const xml = DomUtil.parse(`<delivery>
971
+ <source><![CDATA[<head>]]><![CDATA[</head>]]></source>
972
+ </delivery>`);
973
+ const json = DomUtil.toJSON(xml, "SimpleJson");
974
+ expect(json.$source).toBe("<head></head>")
975
+ });
961
976
  });
977
+
978
+