Skip to content

Commit

Permalink
#984: fixed tests, adjusted logic to set some notifications, check if…
Browse files Browse the repository at this point in the history
… notifs exist etc
  • Loading branch information
phjulia committed Aug 13, 2023
1 parent 581a3a1 commit 0f1c3fe
Show file tree
Hide file tree
Showing 7 changed files with 290 additions and 107 deletions.
29 changes: 29 additions & 0 deletions docs/dist/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ Provides default functionality that can be overwritten by child metadata type cl
<dt><a href="#Mcdev.">Mcdev.(cred, bu, type, [keyArr])</a> ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code></dt>
<dd><p>Updates the key to match the name field</p>
</dd>
<dt><a href="#Mcdev.">Mcdev.(type, [keyArr])</a> ⇒ <code>Promise.&lt;Object.&lt;string, Array.&lt;string&gt;&gt;&gt;</code></dt>
<dd><p>Updates notification email address field</p>
</dd>
<dt><a href="#Automation.">Automation.(metadata)</a> ⇒ <code>boolean</code></dt>
<dd><p>helper for <a href="#Automation.postRetrieveTasks">postRetrieveTasks</a> and <a href="#Automation.execute">execute</a></p>
</dd>
Expand Down Expand Up @@ -3417,6 +3420,7 @@ Provides default functionality that can be overwritten by child metadata type cl
* [.readBUMetadataForType(readDir, [listBadKeys], [buMetadata])](#MetadataType.readBUMetadataForType) ⇒ <code>object</code>
* [.getFilesToCommit(keyArr)](#MetadataType.getFilesToCommit) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>
* [.getKeysForFixing(metadataMap)](#MetadataType.getKeysForFixing) ⇒ <code>Array.&lt;string&gt;</code>
* [.getKeysToSetNotifications(metadataMap)](#MetadataType.getKeysToSetNotifications) ⇒ <code>Array.&lt;string&gt;</code>
* [.updateNotifications()](#MetadataType.updateNotifications) ⇒ <code>Array.&lt;string&gt;</code>

<a name="MetadataType.client"></a>
Expand Down Expand Up @@ -4245,6 +4249,18 @@ additionally, the documentation for dataExtension and automation should be retur
| --- | --- | --- |
| metadataMap | <code>TYPE.MetadataTypeMap</code> | metadata mapped by their keyField |

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

### MetadataType.getKeysToSetNotifications(metadataMap) ⇒ <code>Array.&lt;string&gt;</code>
helper function to get a list of keys where notification email address should be updated

**Kind**: static method of [<code>MetadataType</code>](#MetadataType)
**Returns**: <code>Array.&lt;string&gt;</code> - list of keys

| Param | Type | Description |
| --- | --- | --- |
| metadataMap | <code>TYPE.MetadataTypeMap</code> | metadata mapped by their keyField |

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

### MetadataType.updateNotifications() ⇒ <code>Array.&lt;string&gt;</code>
Expand Down Expand Up @@ -8493,6 +8509,19 @@ Updates the key to match the name field
| type | <code>TYPE.SupportedMetadataTypes</code> | limit execution to given metadata type |
| [keyArr] | <code>Array.&lt;string&gt;</code> | customerkey of the metadata |

<a name="Mcdev."></a>

## Mcdev.(type, [keyArr]) ⇒ <code>Promise.&lt;Object.&lt;string, Array.&lt;string&gt;&gt;&gt;</code>
Updates notification email address field

**Kind**: global function
**Returns**: <code>Promise.&lt;Object.&lt;string, Array.&lt;string&gt;&gt;&gt;</code> - key: business unit name, value: list of affected item keys

| Param | Type | Description |
| --- | --- | --- |
| type | <code>TYPE.SupportedMetadataTypes</code> | limit execution to given metadata type |
| [keyArr] | <code>Array.&lt;string&gt;</code> | customerkey of the metadata |

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

## Automation.(metadata) ⇒ <code>boolean</code>
Expand Down
94 changes: 92 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const cache = require('./util/cache');
* main class
*/
class Mcdev {
static buObject = {};
static properties;
static cred;
static bu;
/**
* helper method to use unattended mode when including mcdev as a package
*
Expand Down Expand Up @@ -832,6 +836,7 @@ class Mcdev {
lang_past = 'updated';
lang_present = 'updating notifications for';
requireKeyOrLike = true;
checkMetadataSupport = false;
break;
}
}
Expand Down Expand Up @@ -970,6 +975,7 @@ class Mcdev {
*/
static async #runOnBU(methodName, cred, bu, type, keyArr) {
const properties = await config.getProperties();
this.properties = properties;
const resultArr = [];
const buObject = await Cli.getCredentialObject(
properties,
Expand All @@ -986,6 +992,9 @@ class Mcdev {
cred = buObject.credential;
bu = buObject.businessUnit;
}
this.buObject = buObject;
this.cred = cred;
this.bu = bu;
Util.logger.info(`:: ${methodName} ${type} on ${cred}/${bu}`);
MetadataTypeInfo[type].client = auth.getSDK(buObject);

Expand All @@ -999,6 +1008,20 @@ class Mcdev {
break;
}
}
case 'updateNotifications': {
{
if (
Object.prototype.hasOwnProperty.call(MetadataTypeInfo[type], methodName)
) {
resultArr.push(...(await MetadataTypeInfo[type][methodName](keyArr)));
} else {
resultArr.push(
...(await this.#updateNotificationsGeneric(type, keyArr))
);
}
break;
}
}
default: {
if (Util.OPTIONS.like && Object.keys(Util.OPTIONS.like).length) {
keyArr = await this.#retrieveKeysWithLike(type, buObject);
Expand All @@ -1012,7 +1035,6 @@ class Mcdev {
} catch (ex) {
Util.logger.errorStack(ex, 'mcdev.' + methodName + ' failed');
}

return resultArr;
}

Expand Down Expand Up @@ -1182,9 +1204,77 @@ class Mcdev {
Util.logger.error(`No email addresses or run notes were provided`);
return null;
}
const result = this.#runMethod('updateNotifications', businessUnit, selectedType, keys);
const result = await this.#runMethod(
'updateNotifications',
businessUnit,
selectedType,
keys
);
if (Object.values(result)[0].length > 0) {
Util.logger.info(`Retrieving automations to have most recent changes`);
const retriever = new Retriever(this.properties, this.buObject);
await retriever.retrieve([selectedType], Object.values(result), null, false);
}
return result;
}
/**
* Updates notification email address field
*
* @param {TYPE.SupportedMetadataTypes} type limit execution to given metadata type
* @param {string[]} [keyArr] customerkey of the metadata
* @returns {Promise.<Object.<string, string[]>>} key: business unit name, value: list of affected item keys
*/
static async #updateNotificationsGeneric(type, keyArr) {
let keysUpdatedNotifications = [];
const resultArr = [];
if (
!Object.prototype.hasOwnProperty.call(
(MetadataTypeDefinitions[type].sendEmailNotification, 'updateNotifications')
)
) {
Util.logger.error(`Update notifications is not supported for this type`);
return resultArr;
}
try {
Util.logger.info(`Retrieving latest versions of ${type} from server`);
const retriever = new Retriever(this.properties, this.buObject);
const retrieved = await retriever.retrieve([type], keyArr, null, false);

const metadataMap = Object.values(retrieved)[0][0];
const keysForDeploy = await MetadataTypeInfo[type].getKeysToSetNotifications(
metadataMap
);
if (keysForDeploy.length < 1) {
Util.logger.warn(
`No items found with a key-name mismatch that match your criteria.\n`
);
return resultArr;
}
this.setOptions({
fromRetrieve: true,
});
const deployed = await Deployer.deploy(
this.cred + '/' + this.bu,
[type],
keysForDeploy
);
keysUpdatedNotifications = Object.keys(Object.values(Object.values(deployed)[0])[0]);
resultArr.push(...keysUpdatedNotifications);
if (keysUpdatedNotifications && keysUpdatedNotifications.length) {
Util.logger.info(
`Successfully updated ${keysUpdatedNotifications.length} key${
keysUpdatedNotifications.length === 1 ? '' : 's'
} of type ${type}`
);
} else {
Util.logger.warn(`No keys of type ${type} updated.`);
}
} catch (ex) {
Util.logger.errorStack(ex, 'mcdev.updateNotificationsGeneric failed');
}
Util.logger.info(`:: Done\n`);
return resultArr;
}
}

module.exports = Mcdev;
Loading

0 comments on commit 0f1c3fe

Please sign in to comment.