-
Notifications
You must be signed in to change notification settings - Fork 36
/
retrieveChangelog.js
103 lines (95 loc) · 3.22 KB
/
retrieveChangelog.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
#!/usr/bin/env node
'use strict';
/* eslint-disable unicorn/prefer-top-level-await */
/**
* sample file on how to retrieve a simple changelog to use in GUIs or automated processing of any kind
*
* @example
[{
name: 'deName',
key: 'deKey',
t: 'dataExtension',
cd: '2020-05-06T00:16:00.737',
cb: 'name of creator',
ld: '2020-05-06T00:16:00.737',
lb: 'name of lastmodified'
}]
*/
import mcdev from './index.js';
import Definition from './MetadataTypeDefinitions.js';
import MetadataType from './MetadataTypeInfo.js';
// disable cli logs
// mcdev._setLoggingLevel({ silent: true });
const customDefinition = {
automation: {
keyField: 'CustomerKey',
nameField: 'Name',
createdDateField: 'CreatedDate',
createdNameField: 'CreatedBy',
lastmodDateField: 'LastSaveDate',
lastmodNameField: 'LastSavedBy',
},
dataExtension: {
keyField: 'CustomerKey',
nameField: 'Name',
createdDateField: 'CreatedDate',
createdNameField: null,
lastmodDateField: 'ModifiedDate',
lastmodNameField: null,
},
};
(async function () {
// get userid>name mapping
const userList = (await mcdev.retrieve('ACN-Learning/_ParentBU_', ['user'], null, true)).user;
// reduce userList to simple id-name map
for (const key of Object.keys(userList)) {
userList[userList[key].ID] = userList[key].Name;
delete userList[key];
}
// get changed metadata
const changelogList = await mcdev.retrieve(
'ACN-Learning/MCDEV_Training_Source',
null,
null,
true
);
const allMetadata = [];
Object.keys(changelogList).map((type) => {
if (changelogList[type]) {
const def = customDefinition[type] || Definition[type];
allMetadata.push(
...Object.keys(changelogList[type]).map((key) => {
const item = changelogList[type][key];
if (
MetadataType[type].isFiltered(item, true) ||
MetadataType[type].isFiltered(item, false)
) {
return;
}
const listEntry = {
name: item[def.nameField],
key: item[def.keyField],
t: type,
cd: item[def.createdDateField],
cb: getUserName(userList, item, def.createdNameField),
ld: item[def.lastmodDateField],
lb: getUserName(userList, item, def.lastmodNameField),
};
return listEntry;
})
);
}
});
const finalResult = allMetadata.filter((item) => undefined !== item);
console.log('finalResult', finalResult); // eslint-disable-line no-console
})();
/**
*
* @param {Object.<string, string>} userList user-id > user-name map
* @param {Object.<string, string>} item single metadata item
* @param {string} fieldname name of field containing the info
* @returns {string} username or user id or 'n/a'
*/
function getUserName(userList, item, fieldname) {
return userList[item[fieldname]] || item[fieldname] || 'n/a';
}