-
Notifications
You must be signed in to change notification settings - Fork 36
/
ContentArea.js
105 lines (99 loc) · 3.66 KB
/
ContentArea.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
'use strict';
import TYPE from '../../types/mcdev.d.js';
import MetadataType from './MetadataType.js';
import { Util } from '../util/util.js';
import cache from '../util/cache.js';
/**
* ContentArea MetadataType
*
* @augments MetadataType
*/
class ContentArea extends MetadataType {
/**
* Retrieves SOAP based metadata of metadata type into local filesystem. executes callback with retrieved metadata
*
* @param {string} retrieveDir Directory where retrieved metadata directory will be saved
* @param {void} [_] unused parameter
* @param {void} [__] unused parameter
* @param {string} [key] customer key of single item to retrieve
* @returns {Promise.<TYPE.MetadataTypeMapObj>} Promise of metadata
*/
static retrieve(retrieveDir, _, __, key) {
Util.logger.warn(
' - Classic Content Areas are deprecated and will be discontinued by SFMC in the near future. Ensure that you migrate any existing Content Areas to Content Builder as soon as possible.'
);
/** @type {TYPE.SoapRequestParams} */
let requestParams = null;
if (key) {
requestParams = {
filter: {
leftOperand: 'CustomerKey',
operator: 'equals',
rightOperand: key,
},
};
}
// !dont activate `await File.initPrettier('html');` as we only want to retrieve for migration and formatting might mess with the outcome
return super.retrieveSOAP(retrieveDir, requestParams, key);
}
/**
* manages post retrieve steps
*
* @param {TYPE.MetadataTypeItem} metadata a single item
* @returns {TYPE.MetadataTypeItem} parsed item
*/
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.debug(
` - ${this.definition.type} '${metadata[this.definition.nameField]}' (${
metadata[this.definition.keyField]
}): Could not find folder (${ex.message})`
);
// classic content blocks that reside in the main folder are
// saved with CategoryID=0, instead of to the actual ID of
// their parent root folder.
metadata.r__folder_Path = 'my contents';
}
}
/**
* parses retrieved Metadata before saving
*
* @param {TYPE.MetadataTypeItem} metadata a single item
* @returns {TYPE.MetadataTypeItem} parsed item
*/
static parseMetadata(metadata) {
// folder
this.setFolderPath(metadata);
// extract code
const codeArr = [
{
subFolder: null,
fileName: metadata.CustomerKey,
fileExt: 'html',
content: metadata.Content,
},
];
delete metadata.Content;
return { json: metadata, codeArr: codeArr, subFolder: null };
}
}
// Assign definition to static attributes
import MetadataTypeDefinitions from '../MetadataTypeDefinitions.js';
ContentArea.definition = MetadataTypeDefinitions.contentArea;
export default ContentArea;