Skip to content

Commit

Permalink
Merge pull request #699 from Accenture/develop
Browse files Browse the repository at this point in the history
4.3.1
  • Loading branch information
JoernBerkefeld authored Feb 2, 2023
2 parents b88f926 + 7250e43 commit a81bf06
Show file tree
Hide file tree
Showing 21 changed files with 802 additions and 123 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ body:
label: Version
description: What version of our software are you running? (mcdev --version)
options:
- 4.3.1
- 4.3.0
- 4.2.1
- 4.2.0
Expand Down
5 changes: 2 additions & 3 deletions docs/dist/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ FileTransfer MetadataType
* [.retrieveAsTemplate(templateDir, name, templateVariables, [selectedSubType])](#Asset.retrieveAsTemplate) ⇒ <code>Promise.&lt;{metadata: TYPE.AssetItem, type: string}&gt;</code>
* [.create(metadata)](#Asset.create) ⇒ <code>Promise</code>
* [.update(metadata)](#Asset.update) ⇒ <code>Promise</code>
* [.requestSubType(subType, subTypeArray, [retrieveDir], [templateName], [templateVariables], key)](#Asset.requestSubType) ⇒ <code>Promise</code>
* [.requestSubType(subType, [retrieveDir], [templateName], [templateVariables], key)](#Asset.requestSubType) ⇒ <code>Promise</code>
* [.requestAndSaveExtended(items, subType, retrieveDir, [templateVariables])](#Asset.requestAndSaveExtended) ⇒ <code>Promise</code>
* [._retrieveExtendedFile(metadata, subType, retrieveDir)](#Asset._retrieveExtendedFile) ⇒ <code>Promise.&lt;void&gt;</code>
* [._readExtendedFileFromFS(metadata, subType, deployDir, [pathOnly])](#Asset._readExtendedFileFromFS) ⇒ <code>Promise.&lt;string&gt;</code>
Expand Down Expand Up @@ -939,7 +939,7 @@ Updates a single asset

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

### Asset.requestSubType(subType, subTypeArray, [retrieveDir], [templateName], [templateVariables], key) ⇒ <code>Promise</code>
### Asset.requestSubType(subType, [retrieveDir], [templateName], [templateVariables], key) ⇒ <code>Promise</code>
Retrieves Metadata of a specific asset type

**Kind**: static method of [<code>Asset</code>](#Asset)
Expand All @@ -948,7 +948,6 @@ Retrieves Metadata of a specific asset type
| Param | Type | Description |
| --- | --- | --- |
| subType | <code>TYPE.AssetSubType</code> | group of similar assets to put in a folder (ie. images) |
| subTypeArray | <code>Array.&lt;TYPE.AssetSubType&gt;</code> | list of all asset types within this subtype |
| [retrieveDir] | <code>string</code> | target directory for saving assets |
| [templateName] | <code>string</code> | name of the metadata file |
| [templateVariables] | <code>TYPE.TemplateMap</code> | variables to be replaced in the metadata |
Expand Down
41 changes: 22 additions & 19 deletions lib/Retriever.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,33 @@ class Retriever {
// ensure we know which real dependencies we have to ensure we cache those completely
const dependencies = this._getTypeDependencies(metadataTypes);
const deployOrder = Util.getMetadataHierachy(metadataTypes);
for (const metadataType in deployOrder) {
const type = metadataType;
const subTypeArr = deployOrder[metadataType];
for (const type in deployOrder) {
const subTypeArr = deployOrder[type];
// if types were added by getMetadataHierachy() for caching, make sure the key-list is set to [null] for them which will retrieve all
typeKeyMap[metadataType] = typeKeyMap[metadataType] || [null];
typeKeyMap[type] = typeKeyMap[type] || [null];
// add client to metadata process class instead of passing every time
MetadataTypeInfo[type].client = auth.getSDK(this.buObject);
MetadataTypeInfo[type].properties = this.properties;
MetadataTypeInfo[type].buObject = this.buObject;
try {
let result;
if (!metadataTypes.includes(type) && !metadataTypes.includes(metadataType)) {
if (
!metadataTypes.includes(type) &&
(!Array.isArray(subTypeArr) ||
(Array.isArray(subTypeArr) &&
!metadataTypes.includes(`${type}-${subTypeArr?.[0]}`)))
) {
// type not in list of types to retrieve, but is a dependency of one of them
if (changelogOnly && type !== 'folder') {
// no extra caching needed for list view except for folders
continue;
}
Util.logger.info(`Caching dependent Metadata: ${metadataType}`);
Util.logger.info(`Caching dependent Metadata: ${type}`);
Util.logSubtypes(subTypeArr);
result = await MetadataTypeInfo[type].retrieveForCache(null, subTypeArr);
} else if (templateVariables) {
// type is in list of types to retrieve and we have template variables
Util.logger.info(`Retrieving as Template: ${metadataType}`);
Util.logger.info(`Retrieving as Template: ${type}`);
if (subTypeArr?.length > 1) {
Util.logger.warn(
`retrieveAsTemplate only works with one subtype, ignoring all but first subtype from your list: ${subTypeArr.join(
Expand All @@ -93,7 +97,7 @@ class Retriever {
);
}
result = await Promise.all(
typeKeyMap[metadataType].map((name) =>
typeKeyMap[type].map((name) =>
MetadataTypeInfo[type].retrieveAsTemplate(
this.templateDir,
name,
Expand All @@ -106,28 +110,27 @@ class Retriever {
// type is in list of types to retrieve and we don't have template variables
let cacheResult = null;
if (
(typeKeyMap[metadataType].length > 1 ||
typeKeyMap[metadataType][0] !== null) &&
(dependencies.includes(type) || dependencies.includes(metadataType))
(typeKeyMap[type].length > 1 || typeKeyMap[type][0] !== null) &&
(dependencies.includes(type) || dependencies.includes(type))
) {
// if we have a key-list and the type is a dependency, we need to cache the whole type
Util.logger.info(`Caching dependent Metadata: ${metadataType}`);
Util.logger.info(`Caching dependent Metadata: ${type}`);
Util.logSubtypes(subTypeArr);
cacheResult = await MetadataTypeInfo[type].retrieveForCache(
null,
subTypeArr
);
}
Util.logger.info(
`Retrieving: ${metadataType}` +
(typeKeyMap[metadataType][0] === null
`Retrieving: ${type}` +
(typeKeyMap[type][0] === null
? ''
: Util.getKeysString(typeKeyMap[metadataType]))
: Util.getKeysString(typeKeyMap[type]))
);
result = await (changelogOnly
? MetadataTypeInfo[type].retrieveChangelog(null, subTypeArr)
: Promise.all(
typeKeyMap[metadataType].map((key) =>
typeKeyMap[type].map((key) =>
MetadataTypeInfo[type].retrieve(
this.savePath,
null,
Expand All @@ -154,14 +157,14 @@ class Retriever {
cache.mergeMetadata(type, result_i.metadata);
}
}
if (metadataTypes.includes(type) || metadataTypes.includes(metadataType)) {
if (metadataTypes.includes(type) || metadataTypes.includes(type)) {
retrieveChangelog[type] = result
.filter((el) => !!el)
.map((element) => element.metadata);
}
} else {
cache.setMetadata(type, result.metadata);
if (metadataTypes.includes(type) || metadataTypes.includes(metadataType)) {
if (metadataTypes.includes(type) || metadataTypes.includes(type)) {
retrieveChangelog[type] = result.metadata;
}
}
Expand All @@ -175,7 +178,7 @@ class Retriever {
Util.logger.error(ex.message);
break;
} else {
Util.logger.errorStack(ex, ` - Retrieving ${metadataType} failed`);
Util.logger.errorStack(ex, ` - Retrieving ${type} failed`);
}
}
}
Expand Down
35 changes: 8 additions & 27 deletions lib/metadataTypes/Asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,7 @@ class Asset extends MetadataType {
for (const subType of subTypeArr) {
// each subtype contains multiple different specific types (images contains jpg and png for example)
// we use await here to limit the risk of too many concurrent api requests at time
items.push(
...(await this.requestSubType(
subType,
this.definition.extendedSubTypes[subType],
retrieveDir,
null,
null,
key
))
);
items.push(...(await this.requestSubType(subType, retrieveDir, null, null, key)));
}
const metadata = this.parseResponseBody({ items: items });
if (retrieveDir) {
Expand Down Expand Up @@ -81,13 +72,7 @@ class Asset extends MetadataType {
// each subtype contains multiple different specific types (images contains jpg and png for example)
// we use await here to limit the risk of too many concurrent api requests at time
items.push(
...(await this.requestSubType(
subType,
this.definition.extendedSubTypes[subType],
templateDir,
name,
templateVariables
))
...(await this.requestSubType(subType, templateDir, name, templateVariables))
);
}
const metadata = this.parseResponseBody({ items: items });
Expand Down Expand Up @@ -146,27 +131,21 @@ class Asset extends MetadataType {
* Retrieves Metadata of a specific asset type
*
* @param {TYPE.AssetSubType} subType group of similar assets to put in a folder (ie. images)
* @param {TYPE.AssetSubType[]} subTypeArray list of all asset types within this subtype
* @param {string} [retrieveDir] target directory for saving assets
* @param {string} [templateName] name of the metadata file
* @param {TYPE.TemplateMap} [templateVariables] variables to be replaced in the metadata
* @param {string} key customer key to filter by
* @returns {Promise} Promise
*/
static async requestSubType(
subType,
subTypeArray,
retrieveDir,
templateName,
templateVariables,
key
) {
static async requestSubType(subType, retrieveDir, templateName, templateVariables, key) {
if (retrieveDir) {
Util.logger.info(`- Retrieving Subtype: ${subType}`);
} else {
Util.logger.info(` - Caching Subtype: ${subType}`);
}
const subtypeIds = subTypeArray?.map(
/** @type {TYPE.AssetSubType[]} */
const extendedSubTypeArr = this.definition.extendedSubTypes[subType];
const subtypeIds = extendedSubTypeArr?.map(
(subTypeItemName) => Asset.definition.typeMapping[subTypeItemName]
);
const uri = '/asset/v1/content/assets/query';
Expand Down Expand Up @@ -977,6 +956,7 @@ class Asset extends MetadataType {

break;
}
case 'template': // template-template
case 'buttonblock': // block - Button Block
case 'freeformblock': // block
case 'htmlblock': // block
Expand Down Expand Up @@ -1198,6 +1178,7 @@ class Asset extends MetadataType {
subFolder: [customerKey],
};
}
case 'template': // template-template
case 'buttonblock': // block - Button Block
case 'freeformblock': // block
case 'htmlblock': // block
Expand Down
2 changes: 1 addition & 1 deletion lib/metadataTypes/Automation.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Automation extends MetadataType {
}
// if we do get here, we should log the error and continue instead of failing to download all automations
Util.logger.error(
` - skipping retrieving Automation ${a.ObjectID}: ${ex.message} ${ex.code}`
` skipping Automation ${a.ObjectID}: ${ex.message} ${ex.code}`
);
return null;
}
Expand Down
66 changes: 35 additions & 31 deletions lib/metadataTypes/EmailSendDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,33 +182,35 @@ class EmailSendDefinition extends MetadataType {
super.setFolderPath(metadata);

// email
try {
// classic
const classicEmail = cache.searchForField('email', metadata.Email.ID, 'ID', 'Name');
metadata.r__email_Name = classicEmail;
delete metadata.Email;
} catch {
if (metadata.Email?.ID) {
try {
// content builder
const contentBuilderEmailName = cache.searchForField(
'asset',
metadata.Email.ID,
'legacyData.legacyId',
'name'
);
metadata.r__assetMessage_Name = contentBuilderEmailName;
const contentBuilderEmailKey = cache.searchForField(
'asset',
metadata.Email.ID,
'legacyData.legacyId',
'customerKey'
);
metadata.r__assetMessage_Key = contentBuilderEmailKey;
// classic
const classicEmail = cache.searchForField('email', metadata.Email.ID, 'ID', 'Name');
metadata.r__email_Name = classicEmail;
delete metadata.Email;
} catch {
Util.logger.warn(
` - ${this.definition.typeName} '${metadata.Name}'/'${metadata.CustomerKey}': Could not find email with ID ${metadata.Email.ID} in Classic nor in Content Builder.`
);
try {
// content builder
const contentBuilderEmailName = cache.searchForField(
'asset',
metadata.Email.ID,
'legacyData.legacyId',
'name'
);
metadata.r__assetMessage_Name = contentBuilderEmailName;
const contentBuilderEmailKey = cache.searchForField(
'asset',
metadata.Email.ID,
'legacyData.legacyId',
'customerKey'
);
metadata.r__assetMessage_Key = contentBuilderEmailKey;
delete metadata.Email;
} catch {
Util.logger.warn(
` - ${this.definition.typeName} '${metadata.Name}'/'${metadata.CustomerKey}': Could not find email with ID ${metadata.Email.ID} in Classic nor in Content Builder.`
);
}
}
}
// Target Audience DataExtension
Expand Down Expand Up @@ -237,13 +239,15 @@ class EmailSendDefinition extends MetadataType {
}
}
// List
try {
sdl.r__list_PathName = cache.getListPathName(sdl.List.ID, 'ID');
delete sdl.List;
} catch (ex) {
Util.logger.warn(
` - ${this.definition.typeName} '${metadata.Name}'/'${metadata.CustomerKey}': ${ex.message}`
);
if (sdl.List?.ID) {
try {
sdl.r__list_PathName = cache.getListPathName(sdl.List.ID, 'ID');
delete sdl.List;
} catch (ex) {
Util.logger.warn(
` - ${this.definition.typeName} '${metadata.Name}'/'${metadata.CustomerKey}': ${ex.message}`
);
}
}
}

Expand Down
Loading

0 comments on commit a81bf06

Please sign in to comment.