Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/630 refresh emails in active triggeredsends journeys #643

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 116 additions & 58 deletions docs/dist/documentation.md

Large diffs are not rendered by default.

33 changes: 27 additions & 6 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,7 @@ yargs
handler: (argv) => {
Mcdev.setSkipInteraction(argv.skipInteraction);
Mcdev.setLoggingLevel(argv);
const keyArr = csvToArray(argv.KEY);

Mcdev.buildTemplate(argv.BU, argv.TYPE, keyArr, argv.MARKET);
Mcdev.buildTemplate(argv.BU, argv.TYPE, csvToArray(argv.KEY), argv.MARKET);
},
})
.command({
Expand Down Expand Up @@ -345,9 +343,32 @@ yargs
handler: (argv) => {
Mcdev.setSkipInteraction(argv.skipInteraction);
Mcdev.setLoggingLevel(argv);
const keyArr = csvToArray(argv.KEY);

Mcdev.getFilesToCommit(argv.BU, argv.TYPE, keyArr);
Mcdev.getFilesToCommit(argv.BU, argv.TYPE, csvToArray(argv.KEY));
},
})
.command({
command: 'refresh <BU> [TYPE] [KEY]',
aliases: ['re'],
desc: 'ensures that updates are properly published',
builder: (yargs) => {
yargs
.positional('BU', {
type: 'string',
describe: 'the business unit to execute the refresh on',
})
.positional('TYPE', {
type: 'string',
describe: 'metadata type',
})
.positional('KEY', {
type: 'string',
describe: 'key(s) of the metadata component(s)',
});
},
handler: (argv) => {
Mcdev.setSkipInteraction(argv.skipInteraction);
Mcdev.setLoggingLevel(argv);
Mcdev.refresh(argv.BU, argv.TYPE, csvToArray(argv.KEY));
},
})
.command({
Expand Down
46 changes: 41 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ class Mcdev {
}

/**
* Creates docs for supported metadata types in Markdown and/or HTML format
* deletes metadata from MC instance by key
*
* @param {string} businessUnit references credentials from properties.json
* @param {string} type supported metadata type
Expand All @@ -359,27 +359,63 @@ class Mcdev {
*/
static async deleteByKey(businessUnit, type, customerKey) {
Util.logger.info('mcdev:: delete');
if (!Util._isValidType(type)) {
return;
}
const properties = await config.getProperties();
if (!(await config.checkProperties(properties))) {
return null;
}
const buObject = await Cli.getCredentialObject(properties, businessUnit);
if (buObject !== null) {
if ('string' !== typeof type) {
Util.logger.error('mcdev.delete failed: Bad metadata type passed in');
try {
MetadataTypeInfo[type].client = auth.getSDK(buObject);
} catch (ex) {
Util.logger.error(ex.message);
return;
}
try {
MetadataTypeInfo[type].properties = properties;
MetadataTypeInfo[type].buObject = buObject;
await MetadataTypeInfo[type].deleteByKey(customerKey);
} catch (ex) {
Util.logger.errorStack(ex, ` - Deleting ${type} failed`);
}
}
}
/**
* ensures triggered sends are restarted to ensure they pick up on changes of the underlying emails
*
* @param {string} businessUnit references credentials from properties.json
* @param {string} type references credentials from properties.json
* @param {string[]} [keyArr] metadata keys
* @returns {Promise.<void>} -
*/
static async refresh(businessUnit, type, keyArr) {
Util.logger.info('mcdev:: refresh');
if (!type || !Util._isValidType(type, true)) {
type = 'triggeredSendDefinition';
Util.logger.info(' - setting type to ' + type);
}
const properties = await config.getProperties();
if (!(await config.checkProperties(properties))) {
return null;
}
const buObject = await Cli.getCredentialObject(properties, businessUnit);
if (buObject !== null) {
try {
MetadataTypeInfo[type].client = auth.getSDK(buObject);
} catch (ex) {
Util.logger.error(ex.message);
return;
}
try {
cache.initCache(buObject);
MetadataTypeInfo[type].properties = properties;
await MetadataTypeInfo[type].deleteByKey(buObject, customerKey);
MetadataTypeInfo[type].buObject = buObject;
await MetadataTypeInfo[type].refresh(keyArr);
} catch (ex) {
Util.logger.errorStack(ex, ` - Deleting ${type} failed`);
Util.logger.errorStack(ex, 'mcdev.refresh ' + ex.message);
}
}
}
Expand Down
16 changes: 7 additions & 9 deletions lib/metadataTypes/DataExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -839,27 +839,25 @@ class DataExtension extends MetadataType {
/**
* Delete a metadata item from the specified business unit
*
* @param {TYPE.BuObject} buObject references credentials
* @param {string} customerKey Identifier of data extension
* @returns {Promise.<boolean>} deletion success status
*/
static deleteByKey(buObject, customerKey) {
return super.deleteByKeySOAP(buObject, customerKey, false);
static deleteByKey(customerKey) {
return super.deleteByKeySOAP(customerKey, false);
}

/**
* clean up after deleting a metadata item
*
* @param {TYPE.BuObject} buObject references credentials
* @param {string} customerKey Identifier of metadata item
* @returns {void}
*/
static async postDeleteTasks(buObject, customerKey) {
static async postDeleteTasks(customerKey) {
// delete local copy: retrieve/cred/bu/dataExtension/...json
const jsonFile = File.normalizePath([
this.properties.directories.retrieve,
buObject.credential,
buObject.businessUnit,
this.buObject.credential,
this.buObject.businessUnit,
this.definition.type,
`${customerKey}.${this.definition.type}-meta.json`,
]);
Expand All @@ -868,8 +866,8 @@ class DataExtension extends MetadataType {
const mdFile = File.normalizePath([
this.properties.directories.docs,
'dataExtension',
buObject.credential,
buObject.businessUnit,
this.buObject.credential,
this.buObject.businessUnit,
`${customerKey}.${this.definition.type}.md`,
]);
await File.remove(mdFile);
Expand Down
10 changes: 4 additions & 6 deletions lib/metadataTypes/DataExtensionField.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,23 +253,21 @@ class DataExtensionField extends MetadataType {
/**
* Delete a metadata item from the specified business unit
*
* @param {TYPE.BuObject} buObject references credentials
* @param {string} customerKey Identifier of data extension
* @returns {Promise.<boolean>} deletion success status
*/
static deleteByKey(buObject, customerKey) {
return this.deleteByKeySOAP(buObject, customerKey, false);
static deleteByKey(customerKey) {
return this.deleteByKeySOAP(customerKey, false);
}

/**
* Delete a data extension from the specified business unit
*
* @param {TYPE.BuObject} buObject references credentials
* @param {string} customerKey Identifier of metadata
* @param {boolean} [handleOutside] if the API reponse is irregular this allows you to handle it outside of this generic method
* @returns {boolean} deletion success flag
*/
static async deleteByKeySOAP(buObject, customerKey, handleOutside) {
static async deleteByKeySOAP(customerKey, handleOutside) {
const [deKey, fieldKey] = customerKey.split('.');
customerKey = `[${deKey}].[${fieldKey}]`;

Expand Down Expand Up @@ -309,7 +307,7 @@ class DataExtensionField extends MetadataType {
if (!handleOutside) {
Util.logger.info(`- deleted ${this.definition.type}: ${customerKey}`);
}
this.postDeleteTasks(buObject, customerKey);
this.postDeleteTasks(customerKey);
return true;
} catch (ex) {
if (handleOutside) {
Expand Down
5 changes: 2 additions & 3 deletions lib/metadataTypes/EmailSendDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,11 @@ class EmailSendDefinition extends MetadataType {
/**
* Delete a metadata item from the specified business unit
*
* @param {TYPE.BuObject} buObject references credentials
* @param {string} customerKey Identifier of data extension
* @returns {Promise.<boolean>} deletion success status
*/
static deleteByKey(buObject, customerKey) {
return super.deleteByKeySOAP(buObject, customerKey, false);
static deleteByKey(customerKey) {
return super.deleteByKeySOAP(customerKey, false);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions lib/metadataTypes/EventDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,11 @@ class EventDefinition extends MetadataType {
/**
* Delete a metadata item from the specified business unit
*
* @param {TYPE.BuObject} buObject references credentials
* @param {string} key Identifier of item
* @returns {Promise.<boolean>} deletion success status
*/
static deleteByKey(buObject, key) {
static deleteByKey(key) {
return super.deleteByKeyREST(
buObject,
'/interaction/v1/eventDefinitions/key:' + encodeURIComponent(key),
key,
false
Expand Down
4 changes: 1 addition & 3 deletions lib/metadataTypes/Interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ class Interaction extends MetadataType {
/**
* Delete a metadata item from the specified business unit
*
* @param {TYPE.BuObject} buObject references credentials
* @param {string} key Identifier of item
* @returns {Promise.<boolean>} deletion success status
*/
static async deleteByKey(buObject, key) {
static async deleteByKey(key) {
let version;
let singleKey = '';
/* eslint-disable unicorn/prefer-ternary */
Expand Down Expand Up @@ -134,7 +133,6 @@ class Interaction extends MetadataType {
);
/* eslint-enable unicorn/prefer-ternary */
return super.deleteByKeyREST(
buObject,
'/interaction/v1/interactions/' + singleKey + `?versionNumber=${version}`,
key,
false
Expand Down
5 changes: 2 additions & 3 deletions lib/metadataTypes/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,11 @@ class List extends MetadataType {
/**
* Delete a metadata item from the specified business unit
*
* @param {TYPE.BuObject} buObject references credentials
* @param {string} customerKey Identifier of data extension
* @returns {Promise.<boolean>} deletion success status
*/
static deleteByKey(buObject, customerKey) {
return super.deleteByKeySOAP(buObject, customerKey, false);
static deleteByKey(customerKey) {
return super.deleteByKeySOAP(customerKey, false);
}

/**
Expand Down
Loading