Skip to content

Commit

Permalink
#706: moving postDeployTasks() from deploy() into upsert()
Browse files Browse the repository at this point in the history
allows adding a created/updated counter into postDeployTasks()
  • Loading branch information
JoernBerkefeld committed Feb 9, 2023
1 parent 224461d commit 9040270
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 35 deletions.
35 changes: 21 additions & 14 deletions docs/dist/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ FileTransfer MetadataType
* [._retrieveExtendedFile(metadata, subType, retrieveDir)](#Asset._retrieveExtendedFile) ⇒ <code>Promise.&lt;void&gt;</code>
* [._readExtendedFileFromFS(metadata, subType, deployDir, [pathOnly])](#Asset._readExtendedFileFromFS) ⇒ <code>Promise.&lt;string&gt;</code>
* [.postRetrieveTasks(metadata)](#Asset.postRetrieveTasks) ⇒ <code>TYPE.CodeExtractItem</code>
* [.postDeployTasks(metadata, _, [isRefresh])](#Asset.postDeployTasks) ⇒ <code>Promise.&lt;void&gt;</code>
* [.postDeployTasks(metadata, _, createdUpdated, [isRefresh])](#Asset.postDeployTasks) ⇒ <code>Promise.&lt;void&gt;</code>
* [.preDeployTasks(metadata, deployDir)](#Asset.preDeployTasks) ⇒ <code>Promise.&lt;TYPE.AssetItem&gt;</code>
* [._getMainSubtype(extendedSubType)](#Asset._getMainSubtype) ⇒ <code>string</code>
* [.buildDefinitionForNested(templateDir, targetDir, metadata, templateVariables, templateName)](#Asset.buildDefinitionForNested) ⇒ <code>Promise.&lt;void&gt;</code>
Expand Down Expand Up @@ -982,7 +982,7 @@ manages post retrieve steps

<a name="Asset.postDeployTasks"></a>

### Asset.postDeployTasks(metadata, _, [isRefresh]) ⇒ <code>Promise.&lt;void&gt;</code>
### Asset.postDeployTasks(metadata, _, createdUpdated, [isRefresh]) ⇒ <code>Promise.&lt;void&gt;</code>
Gets executed after deployment of metadata type

**Kind**: static method of [<code>Asset</code>](#Asset)
Expand All @@ -992,6 +992,7 @@ Gets executed after deployment of metadata type
| --- | --- | --- |
| metadata | <code>TYPE.MetadataTypeMap</code> | metadata mapped by their keyField |
| _ | <code>TYPE.MetadataTypeMap</code> | originalMetadata to be updated (contains additioanl fields) |
| createdUpdated | <code>Object</code> | counter representing successful creates/updates |
| [isRefresh] | <code>boolean</code> | optional flag to indicate that triggeredSend should be refreshed after deployment of assets |

<a name="Asset.preDeployTasks"></a>
Expand Down Expand Up @@ -1260,7 +1261,7 @@ Automation MetadataType
* [.retrieveForCache()](#Automation.retrieveForCache) ⇒ <code>Promise.&lt;TYPE.AutomationMapObj&gt;</code>
* [.retrieveAsTemplate(templateDir, name, templateVariables)](#Automation.retrieveAsTemplate) ⇒ <code>Promise.&lt;TYPE.AutomationItemObj&gt;</code>
* [.postRetrieveTasks(metadata)](#Automation.postRetrieveTasks) ⇒ <code>TYPE.AutomationItem</code>
* [.deploy(metadata, targetBU, retrieveDir)](#Automation.deploy) ⇒ <code>Promise.&lt;TYPE.AutomationMap&gt;</code>
* [.deploy(metadata, targetBU, retrieveDir, [isRefresh])](#Automation.deploy) ⇒ <code>Promise.&lt;TYPE.AutomationMap&gt;</code>
* [.create(metadata)](#Automation.create) ⇒ <code>Promise</code>
* [.update(metadata, metadataBefore)](#Automation.update) ⇒ <code>Promise</code>
* [.preDeployTasks(metadata)](#Automation.preDeployTasks) ⇒ <code>Promise.&lt;TYPE.AutomationItem&gt;</code>
Expand Down Expand Up @@ -1331,7 +1332,7 @@ manages post retrieve steps

<a name="Automation.deploy"></a>

### Automation.deploy(metadata, targetBU, retrieveDir) ⇒ <code>Promise.&lt;TYPE.AutomationMap&gt;</code>
### Automation.deploy(metadata, targetBU, retrieveDir, [isRefresh]) ⇒ <code>Promise.&lt;TYPE.AutomationMap&gt;</code>
Deploys automation - the saved file is the original one due to large differences required for deployment

**Kind**: static method of [<code>Automation</code>](#Automation)
Expand All @@ -1342,6 +1343,7 @@ Deploys automation - the saved file is the original one due to large differences
| metadata | <code>TYPE.AutomationMap</code> | metadata mapped by their keyField |
| targetBU | <code>string</code> | name/shorthand of target businessUnit for mapping |
| retrieveDir | <code>string</code> | directory where metadata after deploy should be saved |
| [isRefresh] | <code>boolean</code> | optional flag - so far not used by automation |

<a name="Automation.create"></a>

Expand Down Expand Up @@ -1610,7 +1612,7 @@ DataExtension MetadataType
* [._filterUpsertResults(res)](#DataExtension._filterUpsertResults) ⇒ <code>boolean</code>
* [.create(metadata)](#DataExtension.create) ⇒ <code>Promise</code>
* [.update(metadata)](#DataExtension.update) ⇒ <code>Promise</code>
* [.postDeployTasks(upsertedMetadata, originalMetadata)](#DataExtension.postDeployTasks) ⇒ <code>void</code>
* [.postDeployTasks(upsertedMetadata, originalMetadata, createdUpdated)](#DataExtension.postDeployTasks) ⇒ <code>void</code>
* [.retrieve(retrieveDir, [additionalFields], [_], [key])](#DataExtension.retrieve) ⇒ <code>Promise.&lt;{metadata: TYPE.DataExtensionMap, type: string}&gt;</code>
* [.retrieveChangelog([additionalFields])](#DataExtension.retrieveChangelog) ⇒ <code>Promise.&lt;{metadata: TYPE.DataExtensionMap, type: string}&gt;</code>
* [.postRetrieveTasks(metadata)](#DataExtension.postRetrieveTasks) ⇒ <code>TYPE.DataExtensionItem</code>
Expand Down Expand Up @@ -1674,7 +1676,7 @@ Updates a single dataExtension. Also updates their columns in 'dataExtension.col

<a name="DataExtension.postDeployTasks"></a>

### DataExtension.postDeployTasks(upsertedMetadata, originalMetadata) ⇒ <code>void</code>
### DataExtension.postDeployTasks(upsertedMetadata, originalMetadata, createdUpdated) ⇒ <code>void</code>
Gets executed after deployment of metadata type

**Kind**: static method of [<code>DataExtension</code>](#DataExtension)
Expand All @@ -1683,6 +1685,7 @@ Gets executed after deployment of metadata type
| --- | --- | --- |
| upsertedMetadata | <code>TYPE.DataExtensionMap</code> | metadata mapped by their keyField |
| originalMetadata | <code>TYPE.DataExtensionMap</code> | metadata to be updated (contains additioanl fields) |
| createdUpdated | <code>Object</code> | counter representing successful creates/updates |

<a name="DataExtension.retrieve"></a>

Expand Down Expand Up @@ -2331,7 +2334,7 @@ EventDefinition MetadataType
* [.retrieveAsTemplate(templateDir, name, templateVariables)](#EventDefinition.retrieveAsTemplate) ⇒ <code>Promise.&lt;TYPE.MetadataTypeItemObj&gt;</code>
* [.postRetrieveTasks(eventDef)](#EventDefinition.postRetrieveTasks) ⇒ <code>TYPE.MetadataTypeItem</code>
* [.deleteByKey(key)](#EventDefinition.deleteByKey) ⇒ <code>Promise.&lt;boolean&gt;</code>
* [.deploy(metadata, deployDir, retrieveDir)](#EventDefinition.deploy) ⇒ <code>Promise.&lt;TYPE.MetadataTypeMap&gt;</code>
* [.deploy(metadata, deployDir, retrieveDir, [isRefresh])](#EventDefinition.deploy) ⇒ <code>Promise.&lt;TYPE.MetadataTypeMap&gt;</code>
* [.create(EventDefinition)](#EventDefinition.create) ⇒ <code>Promise</code>
* [.update(metadataEntry)](#EventDefinition.update) ⇒ <code>Promise</code>
* [.preDeployTasks(metadata)](#EventDefinition.preDeployTasks) ⇒ <code>TYPE.MetadataTypeItem</code>
Expand Down Expand Up @@ -2401,7 +2404,7 @@ Delete a metadata item from the specified business unit

<a name="EventDefinition.deploy"></a>

### EventDefinition.deploy(metadata, deployDir, retrieveDir) ⇒ <code>Promise.&lt;TYPE.MetadataTypeMap&gt;</code>
### EventDefinition.deploy(metadata, deployDir, retrieveDir, [isRefresh]) ⇒ <code>Promise.&lt;TYPE.MetadataTypeMap&gt;</code>
Deploys metadata - merely kept here to be able to print [logBeta](#Util.logBeta) once per deploy

**Kind**: static method of [<code>EventDefinition</code>](#EventDefinition)
Expand All @@ -2412,6 +2415,7 @@ Deploys metadata - merely kept here to be able to print [logBeta](#Util.logBeta)
| metadata | <code>TYPE.MetadataTypeMap</code> | metadata mapped by their keyField |
| deployDir | <code>string</code> | directory where deploy metadata are saved |
| retrieveDir | <code>string</code> | directory where metadata after deploy should be saved |
| [isRefresh] | <code>boolean</code> | optional flag - so far not used by eventDefinition |

<a name="EventDefinition.create"></a>

Expand Down Expand Up @@ -2918,7 +2922,7 @@ definitionId: A unique UUID provided by Salesforce Marketing Cloud. Each version
* [Interaction](#Interaction)[<code>MetadataType</code>](#MetadataType)
* [.retrieve(retrieveDir, [_], [__], [key])](#Interaction.retrieve) ⇒ <code>Promise.&lt;TYPE.MetadataTypeMapObj&gt;</code>
* [.deleteByKey(key)](#Interaction.deleteByKey) ⇒ <code>Promise.&lt;boolean&gt;</code>
* [.deploy(metadata, deployDir, retrieveDir)](#Interaction.deploy) ⇒ <code>Promise.&lt;TYPE.MetadataTypeMap&gt;</code>
* [.deploy(metadata, deployDir, retrieveDir, [isRefresh])](#Interaction.deploy) ⇒ <code>Promise.&lt;TYPE.MetadataTypeMap&gt;</code>
* [.update(metadata)](#Interaction.update) ⇒ <code>Promise</code>
* [.create(metadata)](#Interaction.create) ⇒ <code>Promise</code>
* [.saveResults(results, retrieveDir, [overrideType], [templateVariables])](#Interaction.saveResults) ⇒ <code>Promise.&lt;TYPE.MetadataTypeMap&gt;</code>
Expand Down Expand Up @@ -2956,7 +2960,7 @@ Delete a metadata item from the specified business unit

<a name="Interaction.deploy"></a>

### Interaction.deploy(metadata, deployDir, retrieveDir) ⇒ <code>Promise.&lt;TYPE.MetadataTypeMap&gt;</code>
### Interaction.deploy(metadata, deployDir, retrieveDir, [isRefresh]) ⇒ <code>Promise.&lt;TYPE.MetadataTypeMap&gt;</code>
Deploys metadata - merely kept here to be able to print [logBeta](#Util.logBeta) once per deploy

**Kind**: static method of [<code>Interaction</code>](#Interaction)
Expand All @@ -2967,6 +2971,7 @@ Deploys metadata - merely kept here to be able to print [logBeta](#Util.logBeta)
| metadata | <code>TYPE.MetadataTypeMap</code> | metadata mapped by their keyField |
| deployDir | <code>string</code> | directory where deploy metadata are saved |
| retrieveDir | <code>string</code> | directory where metadata after deploy should be saved |
| [isRefresh] | <code>boolean</code> | optional flag - so far not used by interaction |

<a name="Interaction.update"></a>

Expand Down Expand Up @@ -3147,7 +3152,7 @@ Provides default functionality that can be overwritten by child metadata type cl
* [.getJsonFromFS(dir, [listBadKeys])](#MetadataType.getJsonFromFS) ⇒ <code>TYPE.MetadataTypeMap</code>
* [.getFieldNamesToRetrieve([additionalFields])](#MetadataType.getFieldNamesToRetrieve) ⇒ <code>Array.&lt;string&gt;</code>
* [.deploy(metadata, deployDir, retrieveDir, [isRefresh])](#MetadataType.deploy) ⇒ <code>Promise.&lt;TYPE.MetadataTypeMap&gt;</code>
* [.postDeployTasks(metadata, originalMetadata, [isRefresh])](#MetadataType.postDeployTasks) ⇒ <code>void</code>
* [.postDeployTasks(metadata, originalMetadata, createdUpdated, [isRefresh])](#MetadataType.postDeployTasks) ⇒ <code>void</code>
* [.postRetrieveTasks(metadata, targetDir, [isTemplating])](#MetadataType.postRetrieveTasks) ⇒ <code>TYPE.MetadataTypeItem</code>
* [.setFolderPath(metadata)](#MetadataType.setFolderPath)
* [.setFolderId(metadata)](#MetadataType.setFolderId)
Expand All @@ -3162,7 +3167,7 @@ Provides default functionality that can be overwritten by child metadata type cl
* [.refresh()](#MetadataType.refresh) ⇒ <code>void</code>
* [.hasChanged(cachedVersion, metadata, [fieldName])](#MetadataType.hasChanged) ⇒ <code>boolean</code>
* [.hasChangedGeneric(cachedVersion, metadata, [fieldName], [silent])](#MetadataType.hasChangedGeneric) ⇒ <code>boolean</code>
* [.upsert(metadata, deployDir)](#MetadataType.upsert) ⇒ <code>Promise.&lt;TYPE.MetadataTypeMap&gt;</code>
* [.upsert(metadata, deployDir, [isRefresh])](#MetadataType.upsert) ⇒ <code>Promise.&lt;TYPE.MetadataTypeMap&gt;</code>
* [.createOrUpdate(metadata, metadataKey, hasError, metadataToUpdate, metadataToCreate)](#MetadataType.createOrUpdate) ⇒ <code>void</code>
* [.createREST(metadataEntry, uri)](#MetadataType.createREST) ⇒ <code>Promise.&lt;object&gt;</code> \| <code>null</code>
* [.createSOAP(metadataEntry, [overrideType], [handleOutside])](#MetadataType.createSOAP) ⇒ <code>Promise.&lt;object&gt;</code> \| <code>null</code>
Expand Down Expand Up @@ -3255,7 +3260,7 @@ Deploys metadata

<a name="MetadataType.postDeployTasks"></a>

### MetadataType.postDeployTasks(metadata, originalMetadata, [isRefresh]) ⇒ <code>void</code>
### MetadataType.postDeployTasks(metadata, originalMetadata, createdUpdated, [isRefresh]) ⇒ <code>void</code>
Gets executed after deployment of metadata type

**Kind**: static method of [<code>MetadataType</code>](#MetadataType)
Expand All @@ -3264,6 +3269,7 @@ Gets executed after deployment of metadata type
| --- | --- | --- |
| metadata | <code>TYPE.MetadataTypeMap</code> | metadata mapped by their keyField |
| originalMetadata | <code>TYPE.MetadataTypeMap</code> | metadata to be updated (contains additioanl fields) |
| createdUpdated | <code>Object</code> | counter representing successful creates/updates |
| [isRefresh] | <code>boolean</code> | optional flag to indicate that triggeredSend should be refreshed after deployment of assets |

<a name="MetadataType.postRetrieveTasks"></a>
Expand Down Expand Up @@ -3447,7 +3453,7 @@ test if metadata was actually changed or not to potentially skip it during deplo

<a name="MetadataType.upsert"></a>

### MetadataType.upsert(metadata, deployDir) ⇒ <code>Promise.&lt;TYPE.MetadataTypeMap&gt;</code>
### MetadataType.upsert(metadata, deployDir, [isRefresh]) ⇒ <code>Promise.&lt;TYPE.MetadataTypeMap&gt;</code>
MetadataType upsert, after retrieving from target and comparing to check if create or update operation is needed.

**Kind**: static method of [<code>MetadataType</code>](#MetadataType)
Expand All @@ -3457,6 +3463,7 @@ MetadataType upsert, after retrieving from target and comparing to check if crea
| --- | --- | --- |
| metadata | <code>TYPE.MetadataTypeMap</code> | metadata mapped by their keyField |
| deployDir | <code>string</code> | directory where deploy metadata are saved |
| [isRefresh] | <code>boolean</code> | optional flag to indicate that triggeredSend should be refreshed after deployment of assets |

<a name="MetadataType.createOrUpdate"></a>

Expand Down
12 changes: 10 additions & 2 deletions lib/metadataTypes/Asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,12 +500,20 @@ class Asset extends MetadataType {
*
* @param {TYPE.MetadataTypeMap} metadata metadata mapped by their keyField
* @param {TYPE.MetadataTypeMap} _ originalMetadata to be updated (contains additioanl fields)
* @param {{created: number, updated: number}} createdUpdated counter representing successful creates/updates
* @param {boolean} [isRefresh] optional flag to indicate that triggeredSend should be refreshed after deployment of assets
* @returns {Promise.<void>} -
*/
static async postDeployTasks(metadata, _, isRefresh) {
static async postDeployTasks(metadata, _, createdUpdated, isRefresh) {
if (isRefresh) {
this._refreshTriggeredSendDefinition(metadata);
if (createdUpdated.updated) {
// only run this if assets were updated. for created assets we do not expect
this._refreshTriggeredSendDefinition(metadata);
} else {
Util.logger.warn(
'You set the --refresh flag but no updated assets found. Skipping refresh of triggeredSendDefinitions.'
);
}
}
}

Expand Down
7 changes: 3 additions & 4 deletions lib/metadataTypes/Automation.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,11 @@ class Automation extends MetadataType {
* @param {TYPE.AutomationMap} metadata metadata mapped by their keyField
* @param {string} targetBU name/shorthand of target businessUnit for mapping
* @param {string} retrieveDir directory where metadata after deploy should be saved
* @param {boolean} [isRefresh] optional flag - so far not used by automation
* @returns {Promise.<TYPE.AutomationMap>} Promise
*/
static async deploy(metadata, targetBU, retrieveDir) {
const orignalMetadata = JSON.parse(JSON.stringify(metadata));
const upsertResults = await this.upsert(metadata, targetBU);
await this.postDeployTasks(upsertResults, orignalMetadata);
static async deploy(metadata, targetBU, retrieveDir, isRefresh) {
const upsertResults = await this.upsert(metadata, targetBU, isRefresh);
await this.saveResults(upsertResults, retrieveDir, null);
return upsertResults;
}
Expand Down
17 changes: 13 additions & 4 deletions lib/metadataTypes/DataExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class DataExtension extends MetadataType {
`${this.definition.type} upsert: ${createResults.length} of ${deCreatePromises.length} created / ${updateResults.length} of ${deUpdatePromises.length} updated` +
(filteredByPreDeploy > 0 ? ` / ${filteredByPreDeploy} filtered` : '')
);
let upsertResults;
if (successfulResults.length > 0) {
const metadataResults = successfulResults
.map((r) => r.value.Results[0].Object)
Expand All @@ -133,10 +134,15 @@ class DataExtension extends MetadataType {
}
return r;
});
return super.parseResponseBody({ Results: metadataResults });
upsertResults = super.parseResponseBody({ Results: metadataResults });
} else {
return {};
upsertResults = {};
}
await this.postDeployTasks(upsertResults, desToDeploy, {
created: createResults.length,
updated: updateResults.length,
});
return upsertResults;
}

/**
Expand Down Expand Up @@ -247,12 +253,15 @@ class DataExtension extends MetadataType {
*
* @param {TYPE.DataExtensionMap} upsertedMetadata metadata mapped by their keyField
* @param {TYPE.DataExtensionMap} originalMetadata metadata to be updated (contains additioanl fields)
* @param {{created: number, updated: number}} createdUpdated counter representing successful creates/updates
* @returns {void}
*/
static postDeployTasks(upsertedMetadata, originalMetadata) {
static postDeployTasks(upsertedMetadata, originalMetadata, createdUpdated) {
for (const key in upsertedMetadata) {
const item = upsertedMetadata[key];
const cachedVersion = cache.getByKey('dataExtension', item.CustomerKey);
const cachedVersion = createdUpdated.updated
? cache.getByKey('dataExtension', item.CustomerKey)
: null;
if (cachedVersion) {
// UPDATE
// restore retention values that are typically not returned by the update call
Expand Down
5 changes: 3 additions & 2 deletions lib/metadataTypes/EventDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,12 @@ class EventDefinition extends MetadataType {
* @param {TYPE.MetadataTypeMap} metadata metadata mapped by their keyField
* @param {string} deployDir directory where deploy metadata are saved
* @param {string} retrieveDir directory where metadata after deploy should be saved
* @param {boolean} [isRefresh] optional flag - so far not used by eventDefinition
* @returns {Promise.<TYPE.MetadataTypeMap>} Promise of keyField => metadata map
*/
static async deploy(metadata, deployDir, retrieveDir) {
static async deploy(metadata, deployDir, retrieveDir, isRefresh) {
Util.logBeta(this.definition.type);
return super.deploy(metadata, deployDir, retrieveDir);
return super.deploy(metadata, deployDir, retrieveDir, isRefresh);
}

/**
Expand Down
5 changes: 5 additions & 0 deletions lib/metadataTypes/Folder.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class Folder extends MetadataType {
* @returns {Promise.<object>} Promise of saved metadata
*/
static async upsert(metadata) {
const orignalMetadata = JSON.parse(JSON.stringify(metadata));
let updateCount = 0;
let updateFailedCount = 0;
let createCount = 0;
Expand Down Expand Up @@ -318,6 +319,10 @@ class Folder extends MetadataType {
` - Folders are recognized for updates based on their CustomerKey or, if that is not given, their folder-path.`
);
}
await this.postDeployTasks(upsertResults, orignalMetadata, {
created: createCount,
updated: updateCount,
});
return upsertResults;
}

Expand Down
Loading

0 comments on commit 9040270

Please sign in to comment.