@adobe/acc-js-sdk 1.1.23 → 1.1.25

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.
@@ -289,6 +289,8 @@ const root = await node.linkTarget();
289
289
  <tr><td><b>isMappedAsXml</b></td><td>Is the field mapped as XML?</td></tr>
290
290
  <tr><td><b>visibleIf</b></td><td>The visibility expression of the node (if any) since version 1.1.9 of the SDK</td></tr>
291
291
  <tr><td><b>belongsTo</b></td><td>For attribute and elements, indicates the schema id in which they were defined. Since version 1.1.10 of the SDK</td></tr>
292
+ <tr><td><b>default</b></td><td>Default value if any. Can be an array for collections. Since version 1.1.24 of the SDK</td></tr>
293
+ <tr><td><b>translatedDefault</b></td><td>Default value if any. Since version 1.1.24 of the SDK</td></tr>
292
294
  </tbody>
293
295
  </table>
294
296
 
@@ -2,6 +2,29 @@
2
2
  layout: page
3
3
  title: Change Log
4
4
  ---
5
+ <section class="changelog"><h1>Version 1.1.25</h1>
6
+ <h2>2023/03/07</h2>
7
+
8
+ <li>
9
+ Added an (optional) parameter "options" to the file upload function. This parameter contains an "action" property whose value
10
+ can be "publishIfNeeded" or "none" and indicates which action the upload function should perform after it uploaded the file.
11
+ The default is "publishIfNeeded" which consists of creating a public resources with the file content and publishing it (making
12
+ it available publicly). The other action "none" means that no action is taken and that it is the responsibility of the caller
13
+ to post-process the uploaded file by calling the relevant APIs.
14
+ </li>
15
+ </section>
16
+
17
+ <section class="changelog"><h1>Version 1.1.24</h1>
18
+ <h2>2023/03/07</h2>
19
+
20
+ <li>
21
+ Added support for abortable requests. See <a href="https://opensource.adobe.com/acc-js-sdk/abortRequest.html"> for more details.</a>
22
+ </li>
23
+ <li>
24
+ Fixed compilation of vanilla JS bundle
25
+ </li>
26
+ </section>
27
+
5
28
  <section class="changelog"><h1>Version 1.1.23</h1>
6
29
  <h2>2023/03/02</h2>
7
30
 
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@adobe/acc-js-sdk",
3
- "version": "1.1.23",
3
+ "version": "1.1.25",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@adobe/acc-js-sdk",
9
- "version": "1.1.23",
9
+ "version": "1.1.25",
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
12
  "axios": "^1.2.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/acc-js-sdk",
3
- "version": "1.1.23",
3
+ "version": "1.1.25",
4
4
  "description": "ACC Javascript SDK",
5
5
  "main": "src/index.js",
6
6
  "homepage": "https://github.com/adobe/acc-js-sdk#readme",
@@ -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');
@@ -419,6 +419,18 @@ class XtkSchemaNode {
419
419
  */
420
420
  this.childrenCount = 0;
421
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
+
422
434
  /**
423
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
424
436
  * @type {boolean}
@@ -639,6 +651,16 @@ class XtkSchemaNode {
639
651
  this.expr = EntityAccessor.getAttributeAsString(child, "expr");
640
652
  this.isCalculated = false;
641
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
+ }
642
664
  }
643
665
  for (const childNode of childNodes) {
644
666
  this.children._push(childNode.name, childNode);
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/client.js CHANGED
@@ -520,6 +520,13 @@ class ConnectionParameters {
520
520
  // File Uploader
521
521
  // ========================================================================================
522
522
 
523
+ /**
524
+ * @typedef {Object} FileUploadOptions
525
+ * @property {"publishIfNeeded"|"none"|undefined} the post-processing action to execute. Defaults to "publishIfNeeded"
526
+ * @memberOf Campaign
527
+ */
528
+
529
+
523
530
  /**
524
531
  * File Uploader API for JS SDK(Currently available only in browsers)
525
532
  * @private
@@ -535,11 +542,15 @@ const fileUploader = (client) => {
535
542
  * This is the exposed/public method for fileUploader instance which will do all the processing related to the upload process internally and returns the promise containing all the required data.
536
543
  * @ignore
537
544
  * @param file, where file is an instance of [File](https://developer.mozilla.org/en-US/docs/Web/API/File)
545
+ * @param {FileUploadOptions|undefined} options
538
546
  * @returns {Promise<{name: string, md5: string, type: string, size: string, url: string}>}
539
547
  */
540
- upload: (file) => {
548
+ upload: (file, options) => {
541
549
  console.log(`fileuploader.upload is an experimental feature and is not currently fully functional. It is work in progress and will change in the future.`);
542
550
  return new Promise((resolve, reject) => {
551
+ const action = (options && options.action) ? options.action : "publishIfNeeded";
552
+ if (action !== "publishIfNeeded" && action !== "none")
553
+ reject(CampaignException.BAD_PARAMETER("action", action, "The 'action' parameter of the upload API should be 'publishIfNeeded' or 'none'"));
543
554
  try {
544
555
  if (!Util.isBrowser()) {
545
556
  throw 'File uploading is only supported in browser based calls.';
@@ -569,28 +580,31 @@ const fileUploader = (client) => {
569
580
  // https://git.corp.adobe.com/Campaign/ac/blob/v6-master/wpp/xtk/web/dce/uploader.js
570
581
  return reject(CampaignException.FILE_UPLOAD_FAILED(file.name, 'Malformed data:' + data.toString()));
571
582
  }
572
- const counter = await client.NLWS.xtkCounter.increaseValue({name: 'xtkResource'});
573
- const fileRes= {
574
- internalName: 'RES' + counter,
575
- md5: data[0].md5,
576
- label: data[0].fileName,
577
- fileName: data[0].fileName,
578
- originalName: data[0].fileName,
579
- useMd5AsFilename: '1',
580
- storageType: 5,
581
- xtkschema: 'xtk:fileRes'
582
-
583
- };
584
- await client.NLWS.xtkSession.write(fileRes);
585
- await client.NLWS.xtkFileRes.create(fileRes).publishIfNeeded();
586
- const url = await client.NLWS.xtkFileRes.create(fileRes).getURL();
587
- resolve({
583
+ const result = {
588
584
  name: data[0].fileName,
589
585
  md5: data[0].md5,
590
586
  type: file.type,
591
587
  size: file.size,
592
- url: url
593
- });
588
+ };
589
+ if (action === "publishIfNeeded") {
590
+ const counter = await client.NLWS.xtkCounter.increaseValue({name: 'xtkResource'});
591
+ const fileRes= {
592
+ internalName: 'RES' + counter,
593
+ md5: data[0].md5,
594
+ label: data[0].fileName,
595
+ fileName: data[0].fileName,
596
+ originalName: data[0].fileName,
597
+ useMd5AsFilename: '1',
598
+ storageType: 5,
599
+ xtkschema: 'xtk:fileRes'
600
+
601
+ };
602
+ await client.NLWS.xtkSession.write(fileRes);
603
+ await client.NLWS.xtkFileRes.create(fileRes).publishIfNeeded();
604
+ const url = await client.NLWS.xtkFileRes.create(fileRes).getURL();
605
+ result.url = url;
606
+ }
607
+ resolve(result);
594
608
  }
595
609
  };
596
610
  const html = `<body>${okay}</body>`;
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
  /**
@@ -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'>
@@ -3511,8 +3511,115 @@ describe('ACC Client', function () {
3511
3511
  }).catch((ex) => {
3512
3512
  expect(ex.message).toMatch('500 - Error 16384: SDK-000013 "Failed to upload file abcd.txt. Malformed data:');
3513
3513
  })
3514
+ });
3514
3515
 
3515
- })
3516
+ it("Should support 'publishIfNeeded' action", async () => {
3517
+ // Create a mock client and logon
3518
+ const client = await Mock.makeClient();
3519
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
3520
+ await client.NLWS.xtkSession.logon();
3521
+
3522
+ // Mock the upload protocol
3523
+ // - the upload.jsp (which returns the content of an iframe and JS to eval)
3524
+ // - call to xtk:counter#IncreaseValue (first, retrieve the schema xtk:counter then call the function)
3525
+ // - call to xtk:session#Write
3526
+ // - call to xtk:fileRes#PublishIfNeeded
3527
+ // - call to xtk:fileRes#GetURL
3528
+
3529
+ client._transport.mockReturnValueOnce(Promise.resolve(`Ok
3530
+ <html xmlns="http://www.w3.org/1999/xhtml">
3531
+ <head>
3532
+ <script type="text/javascript">if(window.parent&&window.parent.document.controller&&"function"==typeof window.parent.document.controller.uploadFileCallBack){var aFilesInfo=new Array;aFilesInfo.push({paramName:"file",fileName:"test.txt",newFileName:"d8e8fca2dc0f896fd7cb4cb0031ba249.txt",md5:"d8e8fca2dc0f896fd7cb4cb0031ba249"}),window.parent.document.controller.uploadFileCallBack(aFilesInfo)}</script>
3533
+ </head>
3534
+ <body></body>
3535
+ </html>`)); // upload.jsp
3536
+
3537
+ client._transport.mockReturnValueOnce(Promise.resolve(Mock.GET_XTK_COUNTER_RESPONSE)); // GetEntityIfMoreRecentResponse - counter
3538
+ client._transport.mockReturnValueOnce(Mock.INCREASE_VALUE_RESPONSE); // xtk:counter#IncreaseValue
3539
+
3540
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE); // GetEntityIfMoreRecentResponse - session
3541
+ client._transport.mockReturnValueOnce(Mock.FILE_RES_WRITE_RESPONSE); // xtk:session#Write
3542
+
3543
+ client._transport.mockReturnValueOnce(Promise.resolve(Mock.GET_FILERES_QUERY_SCHEMA_RESPONSE)); // GetEntityIfMoreRecentResponse - fileRes
3544
+ client._transport.mockReturnValueOnce(Promise.resolve(Mock.PUBLISH_IF_NEEDED_RESPONSE)); // xtk:fileRes#PublishIfNeeded
3545
+
3546
+ client._transport.mockReturnValueOnce(Promise.resolve(Mock.GET_URL_RESPONSE)); // xtk:fileRes#GetURL
3547
+
3548
+ // Call upload
3549
+ const result = await client.fileUploader.upload({
3550
+ type: 'text/html',
3551
+ size: 12345
3552
+ }, { action: "publishIfNeeded" });
3553
+
3554
+ expect(result).toMatchObject({
3555
+ md5: "d8e8fca2dc0f896fd7cb4cb0031ba249",
3556
+ name: "test.txt",
3557
+ size: 12345,
3558
+ type: "text/html",
3559
+ url: "http://hello.com"
3560
+ });
3561
+ });
3562
+
3563
+ it("Should support 'none' action", async () => {
3564
+ // Create a mock client and logon
3565
+ const client = await Mock.makeClient();
3566
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
3567
+ await client.NLWS.xtkSession.logon();
3568
+
3569
+ // Mock the upload protocol
3570
+ // With the "none" action, we skip the counter & publication
3571
+ // - the upload.jsp (which returns the content of an iframe and JS to eval)
3572
+ client._transport.mockReturnValueOnce(Promise.resolve(`Ok
3573
+ <html xmlns="http://www.w3.org/1999/xhtml">
3574
+ <head>
3575
+ <script type="text/javascript">if(window.parent&&window.parent.document.controller&&"function"==typeof window.parent.document.controller.uploadFileCallBack){var aFilesInfo=new Array;aFilesInfo.push({paramName:"file",fileName:"test.txt",newFileName:"d8e8fca2dc0f896fd7cb4cb0031ba249.txt",md5:"d8e8fca2dc0f896fd7cb4cb0031ba249"}),window.parent.document.controller.uploadFileCallBack(aFilesInfo)}</script>
3576
+ </head>
3577
+ <body></body>
3578
+ </html>`)); // upload.jsp
3579
+
3580
+ // Call upload
3581
+ const result = await client.fileUploader.upload({
3582
+ type: 'text/html',
3583
+ size: 12345
3584
+ }, { action: "none" });
3585
+
3586
+ expect(result).toMatchObject({
3587
+ md5: "d8e8fca2dc0f896fd7cb4cb0031ba249",
3588
+ name: "test.txt",
3589
+ size: 12345,
3590
+ type: "text/html",
3591
+ });
3592
+ expect(result.url).toBeUndefined();
3593
+ });
3594
+
3595
+ it("Should failed with invalid action", async () => {
3596
+ // Create a mock client and logon
3597
+ const client = await Mock.makeClient();
3598
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
3599
+ await client.NLWS.xtkSession.logon();
3600
+
3601
+ // Mock the upload protocol
3602
+ // With the "none" action, we skip the counter & publication
3603
+ // - the upload.jsp (which returns the content of an iframe and JS to eval)
3604
+ client._transport.mockReturnValueOnce(Promise.resolve(`Ok
3605
+ <html xmlns="http://www.w3.org/1999/xhtml">
3606
+ <head>
3607
+ <script type="text/javascript">if(window.parent&&window.parent.document.controller&&"function"==typeof window.parent.document.controller.uploadFileCallBack){var aFilesInfo=new Array;aFilesInfo.push({paramName:"file",fileName:"test.txt",newFileName:"d8e8fca2dc0f896fd7cb4cb0031ba249.txt",md5:"d8e8fca2dc0f896fd7cb4cb0031ba249"}),window.parent.document.controller.uploadFileCallBack(aFilesInfo)}</script>
3608
+ </head>
3609
+ <body></body>
3610
+ </html>`)); // upload.jsp
3611
+
3612
+ // Call upload
3613
+ await expect(client.fileUploader.upload({
3614
+ type: 'text/html',
3615
+ size: 12345
3616
+ }, { action: "invalid" })).rejects.toMatchObject({
3617
+ errorCode: "SDK-000006",
3618
+ "faultCode": 16384,
3619
+ "faultString": "Bad parameter 'action' with value 'invalid'",
3620
+ "statusCode": 400
3621
+ });
3622
+ });
3516
3623
  });
3517
3624
 
3518
3625
  describe("Setting the xtkschema attribute", () => {
@@ -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
  });