-
Notifications
You must be signed in to change notification settings - Fork 36
/
SenderProfile.js
179 lines (168 loc) · 6.22 KB
/
SenderProfile.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
'use strict';
import MetadataType from './MetadataType.js';
import { Util } from '../util/util.js';
import ReplaceCbReference from '../util/replaceContentBlockReference.js';
/**
* @typedef {import('../../types/mcdev.d.js').BuObject} BuObject
* @typedef {import('../../types/mcdev.d.js').CodeExtract} CodeExtract
* @typedef {import('../../types/mcdev.d.js').CodeExtractItem} CodeExtractItem
* @typedef {import('../../types/mcdev.d.js').MetadataTypeItem} MetadataTypeItem
* @typedef {import('../../types/mcdev.d.js').MetadataTypeItemDiff} MetadataTypeItemDiff
* @typedef {import('../../types/mcdev.d.js').MetadataTypeItemObj} MetadataTypeItemObj
* @typedef {import('../../types/mcdev.d.js').MetadataTypeMap} MetadataTypeMap
* @typedef {import('../../types/mcdev.d.js').MetadataTypeMapObj} MetadataTypeMapObj
* @typedef {import('../../types/mcdev.d.js').SoapRequestParams} SoapRequestParams
* @typedef {import('../../types/mcdev.d.js').TemplateMap} TemplateMap
*/
/**
* SenderProfile MetadataType
*
* @augments MetadataType
*/
class SenderProfile 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 | string[]} [_] unused parameter
* @param {void | string[]} [__] unused parameter
* @param {string} [key] customer key of single item to retrieve
* @returns {Promise.<MetadataTypeMapObj>} Promise of metadata
*/
static async retrieve(retrieveDir, _, __, key) {
/** @type {SoapRequestParams} */
let requestParams;
if (key) {
requestParams = {
filter: {
leftOperand: 'CustomerKey',
operator: 'equals',
rightOperand: key,
},
};
}
return super.retrieveSOAP(retrieveDir, requestParams, key);
}
/**
* Updates a single item
*
* @param {MetadataTypeItem} metadataItem a single item
* @returns {Promise} Promise
*/
static update(metadataItem) {
return super.updateSOAP(metadataItem);
}
/**
* Creates a single item
*
* @param {MetadataTypeItem} metadataItem a single item
* @returns {Promise} Promise
*/
static create(metadataItem) {
return super.createSOAP(metadataItem);
}
/**
* Delete a metadata item from the specified business unit
*
* @param {string} customerKey Identifier of data extension
* @returns {Promise.<boolean>} deletion success status
*/
static deleteByKey(customerKey) {
return super.deleteByKeySOAP(customerKey);
}
/**
* prepares a single item for deployment
*
* @param {MetadataTypeItem} metadata a single query activity
* @returns {Promise.<MetadataTypeItem>} Promise
*/
static async preDeployTasks(metadata) {
if (
metadata.UseDefaultRMMRules &&
(metadata.AutoForwardToEmailAddress !== '' || metadata.AutoForwardToName !== '')
) {
Util.logger.warn(
` - ${this.definition.type} ${metadata[this.definition.nameField]} (${
metadata[this.definition.keyField]
}): AutoForwardToEmailAddress and AutoForwardToName will be ignored because UseDefaultRMMRules is set to true; setting UseDefaultRMMRules to false`
);
metadata.UseDefaultRMMRules = false;
} else if (
!metadata.UseDefaultRMMRules &&
(metadata.AutoForwardToEmailAddress === '' || metadata.AutoForwardToName === '')
) {
Util.logger.warn(
` - ${this.definition.type} ${metadata[this.definition.nameField]} (${
metadata[this.definition.keyField]
}): AutoForwardToEmailAddress and AutoForwardToName are required when UseDefaultRMMRules is set to false; setting UseDefaultRMMRules to true`
);
metadata.UseDefaultRMMRules = true;
}
return metadata;
}
/**
*
* @param {MetadataTypeItem} item single metadata item
* @returns {Promise.<MetadataTypeItem>} key of the item that was updated
*/
static async replaceCbReference(item) {
const parentName = `${this.definition.type} ${item[this.definition.keyField]}`;
let changes = false;
let error;
// *** type specific logic ***
try {
item.FromName = ReplaceCbReference.replaceReference(item.FromName, parentName);
changes = true;
} catch (ex) {
if (ex.code !== 200) {
error = ex;
}
}
try {
item.FromAddress = ReplaceCbReference.replaceReference(item.FromAddress, parentName);
changes = true;
} catch (ex) {
if (ex.code !== 200) {
error = ex;
}
}
try {
item.AutoForwardToEmailAddress = ReplaceCbReference.replaceReference(
item.AutoForwardToEmailAddress,
parentName
);
changes = true;
} catch (ex) {
if (ex.code !== 200) {
error = ex;
}
}
try {
item.AutoForwardToName = ReplaceCbReference.replaceReference(
item.AutoForwardToName,
parentName
);
changes = true;
} catch (ex) {
if (ex.code !== 200) {
error = ex;
}
}
if (error) {
throw error;
}
if (!changes) {
const ex = new Error('No changes made to the code.');
ex.code = 200;
throw ex;
}
// *** finish ***
// replaceReference will throw an error if nothing was updated which will end execution here
// no error means we have a new item to deploy and need to update the item in our retrieve folder
return item;
}
}
// Assign definition & cache to static attributes
import MetadataTypeDefinitions from '../MetadataTypeDefinitions.js';
SenderProfile.definition = MetadataTypeDefinitions.senderProfile;
export default SenderProfile;