Skip to content

Commit

Permalink
#984: added a function to update notifications for Automations
Browse files Browse the repository at this point in the history
  • Loading branch information
phjulia committed Aug 3, 2023
1 parent b09acd1 commit 000778e
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 51 deletions.
63 changes: 45 additions & 18 deletions docs/dist/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ Provides default functionality that can be overwritten by child metadata type cl
<dt><a href="#Mcdev.">Mcdev.(selectedType, buObject)</a> ⇒ <code>Array.&lt;string&gt;</code></dt>
<dd><p>helper for <a href="Mcdev.#runOnBU">Mcdev.#runOnBU</a></p>
</dd>
<dt><a href="#Mcdev.">Mcdev.(cred, bu, type, [keys])</a> ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code></dt>
<dd></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 All @@ -216,6 +218,9 @@ Provides default functionality that can be overwritten by child metadata type cl
<dt><a href="#Automation.">Automation.(metadataMap, originalMetadataMap, key)</a> ⇒ <code>Promise.&lt;{key:string, response:object}&gt;</code></dt>
<dd><p>helper for <a href="#Automation.postDeployTasks">postDeployTasks</a></p>
</dd>
<dt><a href="#Automation.">Automation.()</a> ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code></dt>
<dd><p>helper function to retrieve data about all automations in the BU</p>
</dd>
<dt><a href="#getUserName">getUserName(userList, item, fieldname)</a> ⇒ <code>string</code></dt>
<dd></dd>
<dt><a href="#setupSDK">setupSDK(sessionKey, authObject)</a> ⇒ <code><a href="#SDK">SDK</a></code></dt>
Expand Down Expand Up @@ -520,7 +525,7 @@ main class
* [.execute(businessUnit, [selectedType], [keys])](#Mcdev.execute) ⇒ <code>Promise.&lt;Object.&lt;string, Array.&lt;string&gt;&gt;&gt;</code>
* [.pause(businessUnit, [selectedType], [keys])](#Mcdev.pause) ⇒ <code>Promise.&lt;Object.&lt;string, Array.&lt;string&gt;&gt;&gt;</code>
* [.fixKeys(businessUnit, type, [keys])](#Mcdev.fixKeys) ⇒ <code>Promise.&lt;Object.&lt;string, Array.&lt;string&gt;&gt;&gt;</code>
* [.setNotifEmailAddr(businessUnit, type, keys, emailFailed, emailComplete)](#Mcdev.setNotifEmailAddr) ⇒ <code>Promise.&lt;string&gt;</code>
* [.updateNotifications(businessUnit, type, [keys])](#Mcdev.updateNotifications) ⇒ <code>Promise.&lt;Object.&lt;string, Array.&lt;string&gt;&gt;&gt;</code>

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

Expand Down Expand Up @@ -828,18 +833,19 @@ Updates the key to match the name field
| type | <code>TYPE.SupportedMetadataTypes</code> | limit execution to given metadata type |
| [keys] | <code>Array.&lt;string&gt;</code> | customerkey of the metadata |

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

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

### Mcdev.setNotifEmailAddr(businessUnit, type, keys, emailFailed, emailComplete) ⇒ <code>Promise.&lt;string&gt;</code>
**Kind**: static method of [<code>Mcdev</code>](#Mcdev)
**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 |
| --- | --- |
| businessUnit | <code>\*</code> |
| type | <code>\*</code> |
| keys | <code>\*</code> |
| emailFailed | <code>\*</code> |
| emailComplete | <code>\*</code> |
| Param | Type | Description |
| --- | --- | --- |
| businessUnit | <code>string</code> | name of BU |
| type | <code>TYPE.SupportedMetadataTypes</code> | limit execution to given metadata type |
| [keys] | <code>Array.&lt;string&gt;</code> | customerkey of the metadata |

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

Expand Down Expand Up @@ -1398,7 +1404,7 @@ Automation MetadataType
* [.getFilesToCommit(keyArr)](#Automation.getFilesToCommit) ⇒ <code>Array.&lt;string&gt;</code>
* [.deleteByKey(customerKey)](#Automation.deleteByKey) ⇒ <code>boolean</code>
* [.postDeleteTasks(customerKey)](#Automation.postDeleteTasks) ⇒ <code>void</code>
* [.setNotifEmailAddr(keys, emailFailed, emailComplete)](#Automation.setNotifEmailAddr) ⇒ <code>string</code>
* [.updateNotifications(keys)](#Automation.updateNotifications) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>

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

Expand Down Expand Up @@ -1665,16 +1671,17 @@ clean up after deleting a metadata item
| --- | --- | --- |
| customerKey | <code>string</code> | Identifier of metadata item |

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

### Automation.updateNotifications(keys) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>
A function to update automation email notifications

### Automation.setNotifEmailAddr(keys, emailFailed, emailComplete) ⇒ <code>string</code>
**Kind**: static method of [<code>Automation</code>](#Automation)
**Returns**: <code>Promise.&lt;Array.&lt;string&gt;&gt;</code> - keys of the automations where notifications were updated

| Param | Type |
| --- | --- |
| keys | <code>\*</code> |
| emailFailed | <code>\*</code> |
| emailComplete | <code>\*</code> |
| Param | Type | Description |
| --- | --- | --- |
| keys | <code>string</code> | metadata keys |

<a name="Campaign"></a>

Expand Down Expand Up @@ -8503,6 +8510,19 @@ helper for [Mcdev.#runOnBU](Mcdev.#runOnBU)
| selectedType | <code>TYPE.SupportedMetadataTypes</code> | limit execution to given metadata type |
| buObject | <code>TYPE.BuObject</code> | properties for auth |

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

## Mcdev.(cred, bu, type, [keys]) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>
**Kind**: global function
**Returns**: <code>Promise.&lt;Array.&lt;string&gt;&gt;</code> - keys of the automations where notifications were updated

| Param | Type | Description |
| --- | --- | --- |
| cred | <code>string</code> | name of Credential |
| bu | <code>string</code> | name of BU |
| type | <code>string</code> | metadata type |
| [keys] | <code>Array.&lt;string&gt;</code> | limit retrieval to given metadata keys |

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

## Automation.(metadata) ⇒ <code>boolean</code>
Expand Down Expand Up @@ -8590,6 +8610,13 @@ helper for [postDeployTasks](#Automation.postDeployTasks)
| originalMetadataMap | <code>TYPE.AutomationMap</code> | metadata to be updated (contains additioanl fields) |
| key | <code>string</code> | current customer key |

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

## Automation.() ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>
helper function to retrieve data about all automations in the BU

**Kind**: global function
**Returns**: <code>Promise.&lt;Array.&lt;string&gt;&gt;</code> - returns data about automations with the legacy key
<a name="getUserName"></a>

## getUserName(userList, item, fieldname) ⇒ <code>string</code>
Expand Down
18 changes: 13 additions & 5 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,9 @@ yargs
},
})
.command({
command: 'setNotifEmailAddr <BU> <TYPE> [KEY]',
aliases: ['setNotif'],
desc: 'bulk updates notificaiton email addresses',
command: 'updateNotifications <BU> <TYPE> [KEY]',
aliases: ['updNotif'],
desc: 'bulk updates notification email addresses',
builder: (yargs) => {
yargs
.positional('BU', {
Expand All @@ -561,14 +561,22 @@ yargs
type: 'string',
describe: 'key(s) of the metadata component(s)',
})
.positional('emailFailed', {
.positional('emailError', {
type: 'string',
describe: 'email to notify that an error occured during execution',
})
.positional('emailComplete', {
type: 'string',
describe: 'email to notify about successfull completion',
})
.positional('errorNote', {
type: 'string',
describe: 'run error note',
})
.positional('completionNote', {
type: 'string',
describe: 'run completion note',
})
.option('like', {
type: 'string',
group: 'Options for update notification email address:',
Expand All @@ -579,7 +587,7 @@ yargs
handler: (argv) => {
Mcdev.setOptions(argv);
// ! do not allow multiple types to be passed in here via csvToArray
Mcdev.setNotifEmailAddr(argv.BU, argv.TYPE, csvToArray(argv.KEY));
Mcdev.updateNotifications(argv.BU, argv.TYPE, csvToArray(argv.KEY));
},
})
.command({
Expand Down
76 changes: 60 additions & 16 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ class Mcdev {
'refresh',
'schedule',
'skipInteraction',
'emailFailed',
'emailError',
'emailComplete',
'errorNote',
'completionNote',
];
for (const option of knownOptions) {
if (argv[option] !== undefined) {
Expand Down Expand Up @@ -1129,41 +1131,83 @@ class Mcdev {
return result;
}
/**
* Updates notification email address field
*
* @param {*} businessUnit
* @param {*} type
* @param {*} keys
* @param {*} emailFailed
* @param {*} emailComplete
* @returns {Promise.<string>}
* @param {string} businessUnit name of BU
* @param {TYPE.SupportedMetadataTypes} type limit execution to given metadata type
* @param {string[]} [keys] customerkey of the metadata
* @returns {Promise.<Object.<string, string[]>>} key: business unit name, value: list of affected item keys
*/
static async setNotifEmailAddr(businessUnit, type, keys, emailFailed, emailComplete) {
let [cred, bu] = businessUnit ? businessUnit.split('/') : [null, null];
static async updateNotifications(businessUnit, type, keys) {
const [cred, bu] = businessUnit ? businessUnit.split('/') : [null, null];
if (Util.OPTIONS.emailComplete == null && Util.OPTIONS.emailError == null) {
Util.logger.error(`No email addresses were provided`);
return null;
}
const properties = await config.getProperties();
const resultsObj = {};
if (bu === '*') {
Util.logger.info(':: Updating notifications on all BUs for all credentials');
let counter_credTotal = 0;
for (const cred in properties.credentials) {
Util.logger.info(`:: Updating notifications on BUs for ${cred}`);
let counter_credBu = 0;
for (const bu in properties.credentials[cred].businessUnits) {
resultsObj[`${cred}/${bu}`] = await this.#updateNotificationsBU(
cred,
bu,
type,
keys
);
counter_credBu++;
Util.startLogger(true);
}
counter_credTotal += counter_credBu;
Util.logger.info(`:: ${counter_credBu} BUs of ${cred}\n`);
}
Util.logger.info(`:: Updated notifications on ${counter_credTotal} BUs of ${cred}\n`);
} else {
resultsObj[`${cred}/${bu}`] = await this.#updateNotificationsBU(cred, bu, type, keys);
}

return resultsObj;
}
/**
*
* @param {string} cred name of Credential
* @param {string} bu name of BU
* @param {string} type metadata type
* @param {string[]} [keys] limit retrieval to given metadata keys
* @returns {Promise.<string[]>} keys of the automations where notifications were updated
*/
static async #updateNotificationsBU(cred, bu, type, keys) {
const properties = await config.getProperties();
if (!(await config.checkProperties(properties))) {
return null;
}
const buObject = await Cli.getCredentialObject(
properties,
cred === null ? null : cred + '/' + bu,
null,
true
);
Util.logger.info(`${emailFailed} ${emailComplete}`);
if (buObject !== null) {
cache.initCache(buObject);
cred = buObject.credential;
bu = buObject.businessUnit;
}
Util.logger.info(
`Setting notification email address for ${type} on ${cred}/${bu}` +
(keys ? Util.getKeysString(keys) : '') +
`\n`
);
try {
MetadataTypeInfo[type].client = auth.getSDK(buObject);
} catch (ex) {
Util.logger.error(ex.message);
return null;
}
return await MetadataTypeInfo[type].setNotifEmailAddr(keys, emailFailed, emailComplete);
Util.logger.info(
`Setting notification email address of type ${type} on ${cred}/${bu}` +
(keys ? Util.getKeysString(keys) : '') +
`\n`
);
return await MetadataTypeInfo[type].updateNotifications(keys);
}
}

Expand Down
Loading

0 comments on commit 000778e

Please sign in to comment.