From ad4a4c1e594bc5f7bda240ad301bd62efeacc5eb Mon Sep 17 00:00:00 2001 From: ricardo Date: Mon, 20 Apr 2020 12:14:13 -0500 Subject: [PATCH] :zap: Use xml2js to create xml --- .../nodes-base/nodes/Aws/S3/AwsS3.node.ts | 33 ++++++++++++------- packages/nodes-base/package.json | 1 - 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/packages/nodes-base/nodes/Aws/S3/AwsS3.node.ts b/packages/nodes-base/nodes/Aws/S3/AwsS3.node.ts index 1cd56dfe22..8a4d5fd0a0 100644 --- a/packages/nodes-base/nodes/Aws/S3/AwsS3.node.ts +++ b/packages/nodes-base/nodes/Aws/S3/AwsS3.node.ts @@ -41,7 +41,9 @@ import { createHash, } from 'crypto'; -import * as js2xmlparser from 'js2xmlparser'; +import { + Builder, + } from 'xml2js'; export class AwsS3 implements INodeType { description: INodeTypeDescription = { @@ -136,13 +138,16 @@ export class AwsS3 implements INodeType { } const body: IDataObject = { - '@': { - xmlns: 'http://s3.amazonaws.com/doc/2006-03-01/', - }, - LocationConstraint: [credentials!.region], + CreateBucketConfiguration: { + '$': { + xmlns: 'http://s3.amazonaws.com/doc/2006-03-01/', + }, + LocationConstraint: [credentials!.region], + } }; - const data = js2xmlparser.parse('CreateBucketConfiguration', body); + const builder = new Builder(); + const data = builder.buildObject(body); responseData = await awsApiRequestSOAP.call(this, `${name}.s3`, 'PUT', '', data, qs, headers); @@ -243,17 +248,23 @@ export class AwsS3 implements INodeType { } else { // delete everything inside the folder const body: IDataObject = { - '@': { - xmlns: 'http://s3.amazonaws.com/doc/2006-03-01/', + Delete: { + '$': { + xmlns: 'http://s3.amazonaws.com/doc/2006-03-01/', + }, + Object: [], }, - Object: [], }; + for (const childObject of responseData) { - (body.Object as IDataObject[]).push({ + //@ts-ignore + (body.Delete.Object as IDataObject[]).push({ Key: childObject.Key as string }); } - const data = js2xmlparser.parse('Delete', body); + + const builder = new Builder(); + const data = builder.buildObject(body); headers['Content-MD5'] = createHash('md5').update(data).digest('base64'); diff --git a/packages/nodes-base/package.json b/packages/nodes-base/package.json index 3727fbf0fc..a63a9e4192 100644 --- a/packages/nodes-base/package.json +++ b/packages/nodes-base/package.json @@ -284,7 +284,6 @@ "gm": "^1.23.1", "googleapis": "~46.0.0", "imap-simple": "^4.3.0", - "js2xmlparser": "^4.0.1", "lodash.get": "^4.4.2", "lodash.set": "^4.3.2", "lodash.unset": "^4.5.2",