-
Notifications
You must be signed in to change notification settings - Fork 36
/
TransactionalPush.js
93 lines (85 loc) · 3.42 KB
/
TransactionalPush.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
'use strict';
import TransactionalMessage from './TransactionalMessage.js';
import { Util } from '../util/util.js';
import cache from '../util/cache.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
*/
/**
* TransactionalPush TransactionalMessage
*
* @augments TransactionalMessage
*/
class TransactionalPush extends TransactionalMessage {
static subType = 'push';
/**
* prepares for deployment
*
* @param {MetadataTypeItem} metadata a single item
* @returns {Promise.<MetadataTypeItem>} -
*/
static async preDeployTasks(metadata) {
// asset
if (metadata.r__asset_key) {
// we merely want to be able to show an error if it does not exist
metadata.content ||= {};
metadata.content.customerKey = cache.searchForField(
'asset',
metadata.r__asset_key,
'customerKey',
'customerKey'
);
delete metadata.r__asset_key;
}
if (metadata.options?.badge && typeof metadata.options?.badge !== 'string') {
// ensure it's a string, or else the API will return an error. Our SDK turns numbers in strings into actual numbers
metadata.options.badge += '';
}
return metadata;
}
/**
* manages post retrieve steps
*
* @param {MetadataTypeItem} metadata a single item
* @returns {MetadataTypeItem} a single item
*/
static postRetrieveTasks(metadata) {
// asset
if (metadata.content?.customerKey) {
try {
// we merely want to be able to show an error if it does not exist
metadata.r__asset_key = cache.searchForField(
'asset',
metadata.content.customerKey,
'customerKey',
'customerKey'
);
delete metadata.content;
} catch (ex) {
Util.logger.warn(
` - ${this.definition.type} ${metadata[this.definition.nameField]} (${
metadata[this.definition.keyField]
}): ${ex.message}.`
);
}
}
if (metadata.options?.badge && typeof metadata.options?.badge !== 'string') {
// ensure it's a string, or else the API will return an error. Our SDK turns numbers in strings into actual numbers
metadata.options.badge += '';
}
return metadata;
}
}
// Assign definition to static attributes
import MetadataTypeDefinitions from '../MetadataTypeDefinitions.js';
TransactionalPush.definition = MetadataTypeDefinitions.transactionalPush;
export default TransactionalPush;