@adobe/acc-js-sdk 1.1.24 → 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.
@@ -2,6 +2,18 @@
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
+
5
17
  <section class="changelog"><h1>Version 1.1.24</h1>
6
18
  <h2>2023/03/07</h2>
7
19
 
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@adobe/acc-js-sdk",
3
- "version": "1.1.24",
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.24",
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.24",
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",
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>`;
@@ -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", () => {