From 76dda3e59d1e17a59237670548a784b47288aa20 Mon Sep 17 00:00:00 2001 From: Yuliia Likhytska Date: Mon, 7 Aug 2023 17:37:13 +0200 Subject: [PATCH] #984: move updateNotifications under runMethod --- docs/dist/documentation.md | 31 +++++-------- lib/cli.js | 15 +++--- lib/index.js | 94 +++++++++----------------------------- 3 files changed, 40 insertions(+), 100 deletions(-) diff --git a/docs/dist/documentation.md b/docs/dist/documentation.md index 0c9648bd7..528b4f951 100644 --- a/docs/dist/documentation.md +++ b/docs/dist/documentation.md @@ -195,8 +195,6 @@ Provides default functionality that can be overwritten by child metadata type cl
Mcdev.(selectedType, buObject)Array.<string>

helper for Mcdev.#runOnBU

-
Mcdev.(cred, bu, type, [keys])Promise.<Array.<string>>
-
Automation.(metadata)boolean

helper for postRetrieveTasks and execute

@@ -215,6 +213,8 @@ Provides default functionality that can be overwritten by child metadata type cl
Automation.(metadataMap, key)Promise.<void>

helper for postDeployTasks

+
Automation.()string
+
Automation.(metadataMap, originalMetadataMap, key)Promise.<{key:string, response:object}>

helper for postDeployTasks

@@ -525,7 +525,7 @@ main class * [.execute(businessUnit, [selectedType], [keys])](#Mcdev.execute) ⇒ Promise.<Object.<string, Array.<string>>> * [.pause(businessUnit, [selectedType], [keys])](#Mcdev.pause) ⇒ Promise.<Object.<string, Array.<string>>> * [.fixKeys(businessUnit, type, [keys])](#Mcdev.fixKeys) ⇒ Promise.<Object.<string, Array.<string>>> - * [.updateNotifications(businessUnit, type, [keys])](#Mcdev.updateNotifications) ⇒ Promise.<Object.<string, Array.<string>>> + * [.updateNotifications(businessUnit, selectedType, [keys])](#Mcdev.updateNotifications) ⇒ Promise.<Object.<string, Array.<string>>> @@ -835,7 +835,7 @@ Updates the key to match the name field -### Mcdev.updateNotifications(businessUnit, type, [keys]) ⇒ Promise.<Object.<string, Array.<string>>> +### Mcdev.updateNotifications(businessUnit, selectedType, [keys]) ⇒ Promise.<Object.<string, Array.<string>>> Updates notification email address field **Kind**: static method of [Mcdev](#Mcdev) @@ -844,7 +844,7 @@ Updates notification email address field | Param | Type | Description | | --- | --- | --- | | businessUnit | string | name of BU | -| type | TYPE.SupportedMetadataTypes | limit execution to given metadata type | +| selectedType | TYPE.SupportedMetadataTypes | limit execution to given metadata type | | [keys] | Array.<string> | customerkey of the metadata | @@ -8476,7 +8476,7 @@ run a method across BUs | Param | Type | Description | | --- | --- | --- | -| methodName | 'execute' \| 'pause' | what to run | +| methodName | 'execute' \| 'pause' \| 'updateNotifications' | what to run | | businessUnit | string | name of BU | | [selectedType] | TYPE.SupportedMetadataTypes | limit to given metadata types | | [keys] | Array.<string> | customerkey of the metadata | @@ -8491,7 +8491,7 @@ helper for [Mcdev.#runMethod](Mcdev.#runMethod) | Param | Type | Description | | --- | --- | --- | -| methodName | 'execute' \| 'pause' | what to run | +| methodName | 'execute' \| 'pause' \| 'updateNotifications' | what to run | | cred | string | name of Credential | | bu | string | name of BU | | [type] | TYPE.SupportedMetadataTypes | limit execution to given metadata type | @@ -8510,19 +8510,6 @@ helper for [Mcdev.#runOnBU](Mcdev.#runOnBU) | selectedType | TYPE.SupportedMetadataTypes | limit execution to given metadata type | | buObject | TYPE.BuObject | properties for auth | - - -## Mcdev.(cred, bu, type, [keys]) ⇒ Promise.<Array.<string>> -**Kind**: global function -**Returns**: Promise.<Array.<string>> - keys of the automations where notifications were updated - -| Param | Type | Description | -| --- | --- | --- | -| cred | string | name of Credential | -| bu | string | name of BU | -| type | string | metadata type | -| [keys] | Array.<string> | limit retrieval to given metadata keys | - ## Automation.(metadata) ⇒ boolean @@ -8598,6 +8585,10 @@ helper for [postDeployTasks](#Automation.postDeployTasks) +## Automation.() ⇒ string +**Kind**: global function + + ## Automation.(metadataMap, originalMetadataMap, key) ⇒ Promise.<{key:string, response:object}> helper for [postDeployTasks](#Automation.postDeployTasks) diff --git a/lib/cli.js b/lib/cli.js index eca03ad9d..8870c97d6 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -544,8 +544,9 @@ yargs }, }) .command({ - command: 'updateNotifications [KEY]', - aliases: ['updNotif'], + command: + 'updateNotifications [KEY] [emailError] [emailComplete] [errorNote] [completionNote]', + aliases: ['un'], desc: 'bulk updates notification email addresses', builder: (yargs) => { yargs @@ -561,25 +562,25 @@ yargs type: 'string', describe: 'key(s) of the metadata component(s)', }) - .positional('emailError', { + .option('errorEmail', { type: 'string', describe: 'email to notify that an error occured during execution', }) - .positional('emailComplete', { + .option('completionEmail', { type: 'string', describe: 'email to notify about successfull completion', }) - .positional('errorNote', { + .option('errorNote', { type: 'string', describe: 'run error note', }) - .positional('completionNote', { + .option('completionNote', { type: 'string', describe: 'run completion note', }) .option('like', { type: 'string', - group: 'Options for update notification email address:', + group: 'Options for updateNotifications:', describe: 'filter metadata components (can include % as wildcard or _ for a single character)', }); diff --git a/lib/index.js b/lib/index.js index 0e94d205f..f8f82a0eb 100644 --- a/lib/index.js +++ b/lib/index.js @@ -64,8 +64,8 @@ class Mcdev { 'refresh', 'schedule', 'skipInteraction', - 'emailError', - 'emailComplete', + 'errorEmail', + 'completionEmail', 'errorNote', 'completionNote', ]; @@ -781,7 +781,7 @@ class Mcdev { /** * run a method across BUs * - * @param {'execute'|'pause'} methodName what to run + * @param {'execute'|'pause'|'updateNotifications'} methodName what to run * @param {string} businessUnit name of BU * @param {TYPE.SupportedMetadataTypes} [selectedType] limit to given metadata types * @param {string[]} [keys] customerkey of the metadata @@ -807,6 +807,12 @@ class Mcdev { requireKeyOrLike = true; break; } + case 'updateNotifications': { + lang_past = 'updated'; + lang_present = 'updating notifications for'; + requireKeyOrLike = true; + break; + } } Util.logger.info(`mcdev:: ${methodName} ${selectedType}`); @@ -925,7 +931,7 @@ class Mcdev { /** * helper for {@link Mcdev.#runMethod} * - * @param {'execute'|'pause'} methodName what to run + * @param {'execute'|'pause'|'updateNotifications'} methodName what to run * @param {string} cred name of Credential * @param {string} bu name of BU * @param {TYPE.SupportedMetadataTypes} [type] limit execution to given metadata type @@ -1134,80 +1140,22 @@ class Mcdev { * Updates notification email address field * * @param {string} businessUnit name of BU - * @param {TYPE.SupportedMetadataTypes} type limit execution to given metadata type + * @param {TYPE.SupportedMetadataTypes} selectedType limit execution to given metadata type * @param {string[]} [keys] customerkey of the metadata * @returns {Promise.>} key: business unit name, value: list of affected item keys */ - 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.} 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 - ); - if (buObject !== null) { - cache.initCache(buObject); - cred = buObject.credential; - bu = buObject.businessUnit; - } - try { - MetadataTypeInfo[type].client = auth.getSDK(buObject); - } catch (ex) { - Util.logger.error(ex.message); + static async updateNotifications(businessUnit, selectedType, keys) { + if ( + Util.OPTIONS.completionEmail === undefined && + Util.OPTIONS.errorEmail === undefined && + Util.OPTIONS.completionNote === undefined && + Util.OPTIONS.errorNote === undefined + ) { + // if no options were provided there is nothing to update + Util.logger.error(`No email addresses or run notes were provided`); return null; } - Util.logger.info( - `Setting notification email address of type ${type} on ${cred}/${bu}` + - (keys ? Util.getKeysString(keys) : '') + - `\n` - ); - return await MetadataTypeInfo[type].updateNotifications(keys); + return this.#runMethod('updateNotifications', businessUnit, selectedType, keys); } }