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

bugfix/988 read refresh from options #992

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
80 changes: 26 additions & 54 deletions docs/dist/documentation.md

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions lib/Deployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,9 @@ class Deployer {
* @param {TYPE.SupportedMetadataTypes[]} [typeArr] limit deployment to given metadata type (can include subtype)
* @param {string[]} [keyArr] limit deployment to given metadata keys
* @param {boolean} [fromRetrieve] if true, no folders will be updated/created
* @param {boolean} [isRefresh] optional flag to indicate that triggeredSend should be refreshed after deployment of assets
* @returns {Promise.<TYPE.MultiMetadataTypeMap>} Promise of all deployed metadata
*/
async _deploy(typeArr, keyArr, fromRetrieve, isRefresh) {
async _deploy(typeArr, keyArr, fromRetrieve) {
if (await File.pathExists(this.deployDir)) {
/** @type {TYPE.MultiMetadataTypeMap} */
this.metadata = Deployer.readBUMetadata(this.deployDir, typeArr);
Expand Down Expand Up @@ -297,8 +296,7 @@ class Deployer {
const result = await MetadataTypeInfo[type].deploy(
this.metadata[type],
this.deployDir,
this.retrieveDir,
isRefresh
this.retrieveDir
);
multiMetadataTypeMap[type] = result;
cache.mergeMetadata(type, result);
Expand Down
11 changes: 5 additions & 6 deletions lib/metadataTypes/Asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ class Asset extends MetadataType {
* @param {TYPE.AssetItem} metadata a single asset
* @param {TYPE.AssetSubType} subType group of similar assets to put in a folder (ie. images)
* @param {string} deployDir directory of deploy files
* @param {boolean} [pathOnly=false] used by getFilesToCommit which does not need the binary file to be actually read
* @param {boolean} [pathOnly] used by getFilesToCommit which does not need the binary file to be actually read
* @returns {Promise.<string>} if found will return the path of the binary file
*/
static async _readExtendedFileFromFS(metadata, subType, deployDir, pathOnly = false) {
Expand Down Expand Up @@ -504,11 +504,10 @@ 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, _, createdUpdated, isRefresh) {
if (isRefresh) {
static async postDeployTasks(metadata, _, createdUpdated) {
if (Util.OPTIONS.refresh) {
if (createdUpdated.updated) {
// only run this if assets were updated. for created assets we do not expect
this._refreshTriggeredSend(metadata);
Expand All @@ -521,7 +520,7 @@ class Asset extends MetadataType {
}

/**
* helper for {@link postDeployTasks}. triggers a refresh of active triggerredSendDefinitions associated with the updated asset-message items. Gets executed if isRefresh is true.
* helper for {@link postDeployTasks}. triggers a refresh of active triggerredSendDefinitions associated with the updated asset-message items. Gets executed if refresh option has been set.
*
* @private
* @param {TYPE.MetadataTypeMap} metadata metadata mapped by their keyField
Expand All @@ -546,7 +545,7 @@ class Asset extends MetadataType {
TriggeredSend.client = this.client;
try {
// find refreshable TSDs
const tsdObj = (await TriggeredSend.findRefreshableItems()).metadata;
const tsdObj = (await TriggeredSend.findRefreshableItems(true)).metadata;

const tsdCountInitial = Object.keys(tsdObj).length;
const emailCount = legacyIdArr.length;
Expand Down
5 changes: 2 additions & 3 deletions lib/metadataTypes/Automation.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,11 +452,10 @@ 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, isRefresh) {
const upsertResults = await this.upsert(metadata, targetBU, isRefresh);
static async deploy(metadata, targetBU, retrieveDir) {
const upsertResults = await this.upsert(metadata, targetBU);
const savedMetadata = await this.saveResults(upsertResults, retrieveDir, null);
if (
this.properties.metaDataTypes.documentOnRetrieve.includes(this.definition.type) &&
Expand Down
5 changes: 2 additions & 3 deletions lib/metadataTypes/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,11 @@ class Event 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, isRefresh) {
static async deploy(metadata, deployDir, retrieveDir) {
Util.logBeta(this.definition.type);
return super.deploy(metadata, deployDir, retrieveDir, isRefresh);
return super.deploy(metadata, deployDir, retrieveDir);
}

/**
Expand Down
5 changes: 2 additions & 3 deletions lib/metadataTypes/Journey.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,11 @@ class Journey 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 interaction
* @returns {Promise.<TYPE.MetadataTypeMap>} Promise of keyField => metadata map
*/
static async deploy(metadata, deployDir, retrieveDir, isRefresh) {
static async deploy(metadata, deployDir, retrieveDir) {
Util.logBeta(this.definition.type);
return super.deploy(metadata, deployDir, retrieveDir, isRefresh);
return super.deploy(metadata, deployDir, retrieveDir);
}

/**
Expand Down
21 changes: 8 additions & 13 deletions lib/metadataTypes/MetadataType.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,10 @@ class 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 to indicate that triggeredSend should be refreshed after deployment of assets
* @returns {Promise.<TYPE.MetadataTypeMap>} Promise of keyField => metadata map
*/
static async deploy(metadata, deployDir, retrieveDir, isRefresh) {
const upsertResults = await this.upsert(metadata, deployDir, isRefresh);
static async deploy(metadata, deployDir, retrieveDir) {
const upsertResults = await this.upsert(metadata, deployDir);
const savedMetadata = await this.saveResults(upsertResults, retrieveDir, null);
if (
this.properties.metaDataTypes.documentOnRetrieve.includes(this.definition.type) &&
Expand All @@ -131,10 +130,9 @@ class MetadataType {
* @param {TYPE.MetadataTypeMap} upsertResults metadata mapped by their keyField as returned by update/create
* @param {TYPE.MetadataTypeMap} originalMetadata metadata 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 {void}
*/
static postDeployTasks(upsertResults, originalMetadata, createdUpdated, isRefresh) {}
static postDeployTasks(upsertResults, originalMetadata, createdUpdated) {}

/**
* helper for {@link createREST}
Expand Down Expand Up @@ -537,10 +535,9 @@ class MetadataType {
*
* @param {TYPE.MetadataTypeMap} metadataMap metadata mapped by their keyField
* @param {string} deployDir directory where deploy metadata are saved
* @param {boolean} [isRefresh] optional flag to indicate that triggeredSend should be refreshed after deployment of assets
* @returns {Promise.<TYPE.MetadataTypeMap>} keyField => metadata map
*/
static async upsert(metadataMap, deployDir, isRefresh) {
static async upsert(metadataMap, deployDir) {
const orignalMetadataMap = JSON.parse(JSON.stringify(metadataMap));
const metadataToUpdate = [];
const metadataToCreate = [];
Expand Down Expand Up @@ -632,12 +629,10 @@ class MetadataType {
const metadataResults = createResults.concat(updateResults).filter(Boolean);
upsertResults = this.parseResponseBody(metadataResults);
}
await this.postDeployTasks(
upsertResults,
orignalMetadataMap,
{ created: createResults.length, updated: updateResults.length },
isRefresh
);
await this.postDeployTasks(upsertResults, orignalMetadataMap, {
created: createResults.length,
updated: updateResults.length,
});
return upsertResults;
}

Expand Down
67 changes: 21 additions & 46 deletions lib/metadataTypes/TriggeredSend.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,51 +85,19 @@ class TriggeredSend extends MetadataType {
return super.deleteByKeySOAP(customerKey);
}

/**
* manages post retrieve steps
*
* @param {TYPE.MetadataTypeItem} metadata a single query
* @returns {TYPE.MetadataTypeItem} Array with one metadata object and one query string
*/
static postRetrieveTasks(metadata) {
return this.parseMetadata(metadata);
}
/**
* generic script that retrieves the folder path from cache and updates the given metadata with it after retrieve
*
* @param {TYPE.MetadataTypeItem} metadata a single script activity definition
*/
static setFolderPath(metadata) {
try {
metadata.r__folder_Path = cache.searchForField(
'folder',
metadata[this.definition.folderIdField],
'ID',
'Path'
);
delete metadata[this.definition.folderIdField];
} catch (ex) {
Util.logger.verbose(
` - skipping ${this.definition.type} '${metadata[this.definition.nameField]}' (${
metadata[this.definition.keyField]
}): Could not find folder (${ex.message})`
);
throw ex;
}
}
/**
* parses retrieved Metadata before saving
*
* @param {TYPE.MetadataTypeItem} metadata a single query activity definition
* @param {TYPE.MetadataTypeItem} metadata a single item
* @returns {TYPE.MetadataTypeItem | void} Array with one metadata object and one sql string
*/
static parseMetadata(metadata) {
static postRetrieveTasks(metadata) {
// remove IsPlatformObject, always has to be 'false'
delete metadata.IsPlatformObject;

// folder
try {
this.setFolderPath(metadata);
} catch {
this.setFolderPath(metadata);
if (!metadata.r__folder_Path) {
Util.logger.verbose(
` ☇ skipping ${this.definition.typeName} '${metadata.Name}'/'${metadata.CustomerKey}': Could not find folder.`
);
Expand Down Expand Up @@ -246,7 +214,7 @@ class TriggeredSend extends MetadataType {
* TSD-specific refresh method that finds active TSDs and refreshes them
*
* @param {string[]} [keyArr] metadata keys
* @param {boolean} [checkKey=true] whether to check if the key is valid
* @param {boolean} [checkKey] whether to check if the key is valid
* @returns {Promise.<void>} -
*/
static async refresh(keyArr, checkKey = true) {
Expand Down Expand Up @@ -284,9 +252,10 @@ class TriggeredSend extends MetadataType {
/**
* helper for {@link refresh} that finds active TSDs on the server and filters it by the same rules that {@link retrieve} is using to avoid refreshing TSDs with broken dependencies
*
* @param {boolean} [assetLoaded] if run after Asset.deploy via --refresh option this will skip caching assets
* @returns {Promise.<TYPE.MetadataTypeMapObj>} Promise of TSD item map
*/
static async findRefreshableItems() {
static async findRefreshableItems(assetLoaded = false) {
Util.logger.info('Finding refreshable items...');
// cache dependencies to test for broken links
// skip deprecated classic emails here, assuming they cannot be updated and hence are not relevant for {@link refresh}
Expand All @@ -305,14 +274,20 @@ class TriggeredSend extends MetadataType {
list: null,
};
for (const [type, subTypeArr] of Object.entries(requiredCache)) {
if (!cache.getCache()?.[type]) {
Util.logger.info(` - Caching dependent Metadata: ${type}`);
Util.logSubtypes(subTypeArr);
cacheTypes[type].client = this.client;
cacheTypes[type].buObject = this.buObject;
cacheTypes[type].properties = this.properties;
if (type === 'asset' && assetLoaded) {
continue;
}
Util.logger.info(` - Caching dependent Metadata: ${type}`);
Util.logSubtypes(subTypeArr);
cacheTypes[type].client = this.client;
cacheTypes[type].buObject = this.buObject;
cacheTypes[type].properties = this.properties;

const result = await cacheTypes[type].retrieveForCache(null, subTypeArr);
const result = await cacheTypes[type].retrieveForCache(null, subTypeArr);
if (cache.getCache()?.[type]) {
// re-run caching to merge with existing cache, assuming we might have missed subtypes
cache.mergeMetadata(type, result.metadata);
} else {
cache.setMetadata(type, result.metadata);
}
}
Expand Down