From 803d887ffe1e9cb31cd6c90b9d3c15903e29cac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Berkefeld?= Date: Wed, 26 Jun 2024 20:22:23 +0200 Subject: [PATCH 1/2] #1377: workaround for bad invalid-character-error from rest api --- @types/lib/metadataTypes/Folder.d.ts | 1 + @types/lib/metadataTypes/Folder.d.ts.map | 2 +- .../definitions/Folder.definition.d.ts | 1 + lib/metadataTypes/Folder.js | 53 ++++++++++++------- .../definitions/Folder.definition.js | 1 + 5 files changed, 37 insertions(+), 21 deletions(-) diff --git a/@types/lib/metadataTypes/Folder.d.ts b/@types/lib/metadataTypes/Folder.d.ts index a0ed8cad7..4423614e4 100644 --- a/@types/lib/metadataTypes/Folder.d.ts +++ b/@types/lib/metadataTypes/Folder.d.ts @@ -115,6 +115,7 @@ declare namespace Folder { dependencies: any[]; subTypes: string[]; deployFolderTypes: string[]; + deployFolderTypesRest: string[]; deployFolderBlacklist: string[]; folderTypesFromParent: string[]; hasExtended: boolean; diff --git a/@types/lib/metadataTypes/Folder.d.ts.map b/@types/lib/metadataTypes/Folder.d.ts.map index d64e5f04c..35c94f036 100644 --- a/@types/lib/metadataTypes/Folder.d.ts.map +++ b/@types/lib/metadataTypes/Folder.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Folder.d.ts","sourceRoot":"","sources":["../../../lib/metadataTypes/Folder.js"],"names":[],"mappings":";uBASa,OAAO,wBAAwB,EAAE,QAAQ;0BACzC,OAAO,wBAAwB,EAAE,WAAW;8BAC5C,OAAO,wBAAwB,EAAE,eAAe;+BAChD,OAAO,wBAAwB,EAAE,gBAAgB;mCACjD,OAAO,wBAAwB,EAAE,oBAAoB;kCACrD,OAAO,wBAAwB,EAAE,mBAAmB;8BACpD,OAAO,wBAAwB,EAAE,eAAe;iCAChD,OAAO,wBAAwB,EAAE,kBAAkB;gCACnD,OAAO,wBAAwB,EAAE,iBAAiB;0BAClD,OAAO,wBAAwB,EAAE,WAAW;AAVzD;;;;;;;;;;;GAWG;AAEH;;;;GAIG;AACH;IACI;;;;;;;;OAQG;IACH,6BANW,MAAM,qBACN,MAAM,EAAE,eACR,MAAM,EAAE,QACR,MAAM,gBA8HhB;IAED;;;;;;OAMG;IACH,4BAJW,IAAI,GAAG,MAAM,EAAE,eACf,MAAM,EAAE,gBAKlB;IAED;;;;;;;OAOG;IACH,wBAHW,eAAe,GACb,QAAS,MAAM,CAAC,CA8J5B;IAED;;;;;OAKG;IACH,6BAHW,gBAAgB,gBA+C1B;IAED;;;;;OAKG;IACH,6BAHW,gBAAgB,gBAyB1B;IAED;;;;;OAKG;IACH,gCAHW,gBAAgB,GACd,QAAS,gBAAgB,CAAC,CAgDtC;IAED;;;;;;OAMG;IACH,0BAJW,MAAM,gBACN,OAAO,GACL,QAAS,eAAe,CAAC,CAkErC;IAED;;;;;;;OAOG;IACH,yCALW,MAAM,EAAE,qBACR,OAAO,oBACP,MAAM,EAAE,GACN,QAAS,MAAM,CAAC,CA+B5B;IACD;;;;;OAKG;IACH,mCAHW,gBAAgB,GACd,gBAAgB,CAI5B;IACD;;;;;;;OAOG;IACH,4BALW,eAAe,eACf,MAAM,OACN,MAAM,GAAG,MAAM,GACb,QAAS,MAAM,CAAC,CAuD5B;CACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBA9oBwB,mBAAmB"} \ No newline at end of file +{"version":3,"file":"Folder.d.ts","sourceRoot":"","sources":["../../../lib/metadataTypes/Folder.js"],"names":[],"mappings":";uBASa,OAAO,wBAAwB,EAAE,QAAQ;0BACzC,OAAO,wBAAwB,EAAE,WAAW;8BAC5C,OAAO,wBAAwB,EAAE,eAAe;+BAChD,OAAO,wBAAwB,EAAE,gBAA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\ No newline at end of file diff --git a/@types/lib/metadataTypes/definitions/Folder.definition.d.ts b/@types/lib/metadataTypes/definitions/Folder.definition.d.ts index 8b125445f..f0aa6f7cf 100644 --- a/@types/lib/metadataTypes/definitions/Folder.definition.d.ts +++ b/@types/lib/metadataTypes/definitions/Folder.definition.d.ts @@ -3,6 +3,7 @@ declare namespace _default { let dependencies: any[]; let subTypes: string[]; let deployFolderTypes: string[]; + let deployFolderTypesRest: string[]; let deployFolderBlacklist: string[]; let folderTypesFromParent: string[]; let hasExtended: boolean; diff --git a/lib/metadataTypes/Folder.js b/lib/metadataTypes/Folder.js index 7efc029c4..a18179d43 100644 --- a/lib/metadataTypes/Folder.js +++ b/lib/metadataTypes/Folder.js @@ -351,29 +351,42 @@ class Folder extends MetadataType { } const path = metadataEntry.Path; try { - // * We tried using the SOAP endpoint for creating folders but that did not support folders for automations nor journeys. This rest endpoint seems to cover everything though - const restPayload = { - parentCatId: metadataEntry.ParentFolder.ID, - name: metadataEntry.Name, - catType: metadataEntry.ContentType, - }; - const response = await super.createREST(restPayload, '/email/v1/category', true); - if (response?.objectId) { - // convert the response to the same format as the SOAP response - metadataEntry.ID = response.objectId; - // the following is a bit of a hack to make the response look like the SOAP response; not sure if we actually need that anywhere like this --> future developers feel free to double check - const returnObject = { - Results: [ - { - Object: metadataEntry, - }, - ], + if (this.definition.deployFolderTypesRest.includes(metadataEntry.ContentType)) { + // * The SOAP endpoint for creating folders does not support folders for automations nor journeys. The Rest endpoint on the other hand errors out on certain characters in the folder names that are actually valid. We therefore only use Rest for the folder types that are not supported by SOAP. + const restPayload = { + parentCatId: metadataEntry.ParentFolder.ID, + name: metadataEntry.Name, + catType: metadataEntry.ContentType, }; + const response = await super.createREST(restPayload, '/email/v1/category', true); + if (response?.objectId) { + // convert the response to the same format as the SOAP response + metadataEntry.ID = response.objectId; + // the following is a bit of a hack to make the response look like the SOAP response; not sure if we actually need that anywhere like this --> future developers feel free to double check + const returnObject = { + Results: [ + { + Object: metadataEntry, + }, + ], + }; - Util.logger.info(` - created folder: ${path}`); - return returnObject; + Util.logger.info(` - created folder: ${path}`); + return returnObject; + } else { + throw new Error(response); + } } else { - throw new Error(response); + const response = await super.createSOAP(metadataEntry, true); + if (response) { + response.Results[0].Object = metadataEntry; + response.Results[0].Object.ID = response.Results[0].NewID; + response.Results[0].Object.CustomerKey = metadataEntry.CustomerKey; + delete response.Results[0].Object.$; + + Util.logger.info(` - created folder: ${path}`); + return response; + } } } catch (ex) { if (ex?.results) { diff --git a/lib/metadataTypes/definitions/Folder.definition.js b/lib/metadataTypes/definitions/Folder.definition.js index 6b8e71af0..eafcb3547 100644 --- a/lib/metadataTypes/definitions/Folder.definition.js +++ b/lib/metadataTypes/definitions/Folder.definition.js @@ -52,6 +52,7 @@ export default { 'triggered_send_journeybuilder', 'triggered_send', ], + deployFolderTypesRest: ['automations', 'journey', 'triggered_send_journeybuilder'], deployFolderBlacklist: [ // lower-case values! 'shared data extensions', From 2fd179a13569ff21475fc426654e59c12c4147e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Berkefeld?= Date: Wed, 26 Jun 2024 20:23:58 +0200 Subject: [PATCH 2/2] #0: add missing subType to list --- lib/metadataTypes/definitions/Folder.definition.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/metadataTypes/definitions/Folder.definition.js b/lib/metadataTypes/definitions/Folder.definition.js index eafcb3547..cbef0a8b0 100644 --- a/lib/metadataTypes/definitions/Folder.definition.js +++ b/lib/metadataTypes/definitions/Folder.definition.js @@ -4,6 +4,7 @@ export default { subTypes: [ 'asset-shared', 'asset', + 'automations', 'contextual_suppression_list', 'dataextension', 'filteractivity',