auth0-deploy-cli 7.4.0 → 7.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.circleci/config.yml +15 -0
- package/.eslintrc +66 -17
- package/.github/CODEOWNERS +1 -0
- package/.husky/pre-commit +2 -0
- package/CHANGELOG.md +27 -2
- package/lib/args.js +94 -81
- package/lib/commands/export.js +54 -78
- package/lib/commands/import.js +46 -70
- package/lib/commands/index.js +11 -20
- package/lib/configFactory.js +19 -27
- package/lib/context/defaults.js +18 -41
- package/lib/context/directory/handlers/actions.js +77 -107
- package/lib/context/directory/handlers/attackProtection.js +59 -0
- package/lib/context/directory/handlers/clientGrants.js +45 -54
- package/lib/context/directory/handlers/clients.js +60 -79
- package/lib/context/directory/handlers/connections.js +65 -89
- package/lib/context/directory/handlers/databases.js +91 -123
- package/lib/context/directory/handlers/emailProvider.js +46 -57
- package/lib/context/directory/handlers/emailTemplates.js +67 -80
- package/lib/context/directory/handlers/guardianFactorProviders.js +41 -49
- package/lib/context/directory/handlers/guardianFactorTemplates.js +41 -49
- package/lib/context/directory/handlers/guardianFactors.js +41 -49
- package/lib/context/directory/handlers/guardianPhoneFactorMessageTypes.js +40 -50
- package/lib/context/directory/handlers/guardianPhoneFactorSelectedProvider.js +40 -50
- package/lib/context/directory/handlers/guardianPolicies.js +40 -50
- package/lib/context/directory/handlers/hooks.js +55 -70
- package/lib/context/directory/handlers/index.js +53 -123
- package/lib/context/directory/handlers/migrations.js +36 -41
- package/lib/context/directory/handlers/organizations.js +54 -69
- package/lib/context/directory/handlers/pages.js +72 -86
- package/lib/context/directory/handlers/resourceServers.js +41 -49
- package/lib/context/directory/handlers/roles.js +49 -62
- package/lib/context/directory/handlers/rules.js +52 -68
- package/lib/context/directory/handlers/rulesConfigs.js +33 -32
- package/lib/context/directory/handlers/tenant.js +52 -47
- package/lib/context/directory/handlers/triggers.js +39 -54
- package/lib/context/directory/index.js +113 -101
- package/lib/context/index.js +96 -105
- package/lib/context/yaml/handlers/actions.js +71 -88
- package/lib/context/yaml/handlers/attackProtection.js +29 -0
- package/lib/context/yaml/handlers/clientGrants.js +36 -29
- package/lib/context/yaml/handlers/clients.js +61 -76
- package/lib/context/yaml/handlers/connections.js +76 -103
- package/lib/context/yaml/handlers/databases.js +64 -79
- package/lib/context/yaml/handlers/emailProvider.js +33 -30
- package/lib/context/yaml/handlers/emailTemplates.js +45 -54
- package/lib/context/yaml/handlers/guardianFactorProviders.js +27 -18
- package/lib/context/yaml/handlers/guardianFactorTemplates.js +27 -18
- package/lib/context/yaml/handlers/guardianFactors.js +27 -18
- package/lib/context/yaml/handlers/guardianPhoneFactorMessageTypes.js +27 -20
- package/lib/context/yaml/handlers/guardianPhoneFactorSelectedProvider.js +27 -20
- package/lib/context/yaml/handlers/guardianPolicies.js +27 -20
- package/lib/context/yaml/handlers/hooks.js +57 -67
- package/lib/context/yaml/handlers/index.js +53 -123
- package/lib/context/yaml/handlers/migrations.js +23 -24
- package/lib/context/yaml/handlers/organizations.js +40 -38
- package/lib/context/yaml/handlers/pages.js +49 -58
- package/lib/context/yaml/handlers/resourceServers.js +27 -18
- package/lib/context/yaml/handlers/roles.js +34 -24
- package/lib/context/yaml/handlers/rules.js +48 -58
- package/lib/context/yaml/handlers/rulesConfigs.js +27 -18
- package/lib/context/yaml/handlers/tenant.js +44 -30
- package/lib/context/yaml/handlers/triggers.js +32 -23
- package/lib/context/yaml/index.js +127 -142
- package/lib/index.js +73 -79
- package/lib/logger.js +18 -22
- package/lib/readonly.js +74 -66
- package/lib/tools/ValidationError.js +8 -13
- package/lib/tools/auth0/client.js +143 -133
- package/lib/tools/auth0/handlers/actions.js +231 -243
- package/lib/tools/auth0/handlers/attackProtection.js +86 -0
- package/lib/tools/auth0/handlers/branding.js +47 -46
- package/lib/tools/auth0/handlers/clientGrants.js +118 -116
- package/lib/tools/auth0/handlers/clients.js +72 -90
- package/lib/tools/auth0/handlers/connections.js +150 -118
- package/lib/tools/auth0/handlers/databases.js +127 -124
- package/lib/tools/auth0/handlers/default.js +186 -189
- package/lib/tools/auth0/handlers/emailProvider.js +67 -78
- package/lib/tools/auth0/handlers/emailTemplates.js +116 -92
- package/lib/tools/auth0/handlers/guardianFactorProviders.js +66 -81
- package/lib/tools/auth0/handlers/guardianFactorTemplates.js +60 -71
- package/lib/tools/auth0/handlers/guardianFactors.js +56 -63
- package/lib/tools/auth0/handlers/guardianPhoneFactorMessageTypes.js +80 -79
- package/lib/tools/auth0/handlers/guardianPhoneFactorSelectedProvider.js +77 -76
- package/lib/tools/auth0/handlers/guardianPolicies.js +59 -62
- package/lib/tools/auth0/handlers/hooks.js +201 -227
- package/lib/tools/auth0/handlers/index.js +53 -111
- package/lib/tools/auth0/handlers/migrations.js +99 -79
- package/lib/tools/auth0/handlers/organizations.js +225 -247
- package/lib/tools/auth0/handlers/pages.js +116 -154
- package/lib/tools/auth0/handlers/prompts.js +47 -46
- package/lib/tools/auth0/handlers/resourceServers.js +88 -112
- package/lib/tools/auth0/handlers/roles.js +203 -220
- package/lib/tools/auth0/handlers/rules.js +168 -189
- package/lib/tools/auth0/handlers/rulesConfigs.js +54 -63
- package/lib/tools/auth0/handlers/tenant.js +88 -64
- package/lib/tools/auth0/handlers/triggers.js +126 -126
- package/lib/tools/auth0/index.js +92 -85
- package/lib/tools/auth0/schema.js +39 -31
- package/lib/tools/constants.js +111 -21
- package/lib/tools/deploy.js +35 -32
- package/lib/tools/index.js +19 -32
- package/lib/tools/logger.js +11 -12
- package/lib/tools/utils.js +255 -282
- package/lib/utils.js +167 -190
- package/package.json +10 -16
- package/tsconfig.json +17 -0
- package/typescript-migration-progress.sh +22 -0
- package/.babelrc +0 -17
- package/.nyc_output/597f412e-a239-4319-ad5b-ddb87fc39e67.json +0 -1
- package/.nyc_output/processinfo/597f412e-a239-4319-ad5b-ddb87fc39e67.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
|
@@ -1,202 +1,199 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.order = void 0;
|
|
16
|
+
const ValidationError_1 = __importDefault(require("../../ValidationError"));
|
|
17
|
+
const logger_1 = __importDefault(require("../../logger"));
|
|
18
|
+
const utils_1 = require("../../utils");
|
|
20
19
|
function order(value) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
return function decorator(t, n, descriptor) {
|
|
21
|
+
descriptor.value.order = value; // eslint-disable-line
|
|
22
|
+
return descriptor;
|
|
23
|
+
};
|
|
25
24
|
}
|
|
26
|
-
|
|
25
|
+
exports.order = order;
|
|
27
26
|
class DefaultHandler {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
this.updated = 0;
|
|
45
|
-
this.created = 0;
|
|
46
|
-
this.deleted = 0;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
getClientFN(fn) {
|
|
50
|
-
if (typeof fn === 'string') {
|
|
51
|
-
const client = this.client[this.type];
|
|
52
|
-
return client[fn].bind(client);
|
|
27
|
+
constructor(options) {
|
|
28
|
+
this.config = options.config;
|
|
29
|
+
this.type = options.type;
|
|
30
|
+
this.id = options.id || 'id';
|
|
31
|
+
this.client = options.client;
|
|
32
|
+
this.existing = null;
|
|
33
|
+
this.identifiers = options.identifiers || ['id', 'name'];
|
|
34
|
+
this.objectFields = options.objectFields || [];
|
|
35
|
+
this.stripUpdateFields = [
|
|
36
|
+
...options.stripUpdateFields || [],
|
|
37
|
+
this.id
|
|
38
|
+
];
|
|
39
|
+
this.functions = Object.assign({ getAll: 'getAll', create: 'create', update: 'update', delete: 'delete' }, options.functions || {});
|
|
40
|
+
this.updated = 0;
|
|
41
|
+
this.created = 0;
|
|
42
|
+
this.deleted = 0;
|
|
53
43
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
didCreate(item) {
|
|
63
|
-
_logger2.default.info(`Created [${this.type}]: ${this.objString(item)}`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
didUpdate(item) {
|
|
67
|
-
_logger2.default.info(`Updated [${this.type}]: ${this.objString(item)}`);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
objString(item) {
|
|
71
|
-
return (0, _utils.dumpJSON)(item);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
async getType() {
|
|
75
|
-
throw new Error(`Must implement getType for type ${this.type}`);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async load() {
|
|
79
|
-
_logger2.default.info(`Retrieving ${this.type} data from Auth0`);
|
|
80
|
-
|
|
81
|
-
this.existing = await this.getType();
|
|
82
|
-
return {
|
|
83
|
-
[this.type]: this.existing
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async calcChanges(assets) {
|
|
88
|
-
const typeAssets = assets[this.type];
|
|
89
|
-
if (!typeAssets) return {};
|
|
90
|
-
const existing = await this.getType();
|
|
91
|
-
return (0, _utils.calcChanges)(this, typeAssets, existing, this.identifiers);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
async validate(assets) {
|
|
95
|
-
const typeAssets = assets[this.type];
|
|
96
|
-
if (!Array.isArray(typeAssets)) return;
|
|
97
|
-
const duplicateNames = (0, _utils.duplicateItems)(typeAssets, 'name');
|
|
98
|
-
|
|
99
|
-
if (duplicateNames.length > 0) {
|
|
100
|
-
const formatted = duplicateNames.map(dups => dups.map(d => `${d.name}`));
|
|
101
|
-
throw new _ValidationError2.default(`There are multiple ${this.type} with the same name combinations
|
|
102
|
-
${(0, _utils.dumpJSON)(formatted)}.
|
|
103
|
-
Names must be unique.`);
|
|
44
|
+
getClientFN(fn) {
|
|
45
|
+
if (typeof fn === 'string') {
|
|
46
|
+
const client = this.client[this.type];
|
|
47
|
+
return client[fn].bind(client);
|
|
48
|
+
}
|
|
49
|
+
return fn;
|
|
104
50
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (duplicateIDs.length > 0) {
|
|
109
|
-
const formatted = duplicateIDs.map(dups => dups.map(d => `${d[this.id]}`));
|
|
110
|
-
throw new _ValidationError2.default(`There are multiple ${this.type} for the following stage-order combinations
|
|
111
|
-
${(0, _utils.dumpJSON)(formatted)}.
|
|
112
|
-
Only one rule must be defined for the same order number in a stage.`);
|
|
51
|
+
didDelete(item) {
|
|
52
|
+
logger_1.default.info(`Deleted [${this.type}]: ${this.objString(item)}`);
|
|
113
53
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
async processChanges(assets, changes) {
|
|
117
|
-
if (!changes) {
|
|
118
|
-
changes = await this.calcChanges(assets);
|
|
54
|
+
didCreate(item) {
|
|
55
|
+
logger_1.default.info(`Created [${this.type}]: ${this.objString(item)}`);
|
|
119
56
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const update = changes.update || [];
|
|
123
|
-
const create = changes.create || [];
|
|
124
|
-
const conflicts = changes.conflicts || [];
|
|
125
|
-
|
|
126
|
-
_logger2.default.debug(`Start processChanges for ${this.type} [delete:${del.length}] [update:${update.length}], [create:${create.length}], [conflicts:${conflicts.length}]`);
|
|
127
|
-
|
|
128
|
-
if (del.length > 0) {
|
|
129
|
-
const allowDelete = this.config('AUTH0_ALLOW_DELETE') === 'true' || this.config('AUTH0_ALLOW_DELETE') === true;
|
|
130
|
-
const byExtension = this.config('EXTENSION_SECRET') && (this.type === 'rules' || this.type === 'resourceServers');
|
|
131
|
-
const shouldDelete = allowDelete || byExtension;
|
|
132
|
-
|
|
133
|
-
if (!shouldDelete) {
|
|
134
|
-
_logger2.default.warn(`Detected the following ${this.type} should be deleted. Doing so may be destructive.\nYou can enable deletes by setting 'AUTH0_ALLOW_DELETE' to true in the config
|
|
135
|
-
\n${changes.del.map(i => this.objString(i)).join('\n')}
|
|
136
|
-
`);
|
|
137
|
-
} else {
|
|
138
|
-
await this.client.pool.addEachTask({
|
|
139
|
-
data: del || [],
|
|
140
|
-
generator: delItem => {
|
|
141
|
-
const delFunction = this.getClientFN(this.functions.delete);
|
|
142
|
-
return delFunction({
|
|
143
|
-
[this.id]: delItem[this.id]
|
|
144
|
-
}).then(() => {
|
|
145
|
-
this.didDelete(delItem);
|
|
146
|
-
this.deleted += 1;
|
|
147
|
-
}).catch(err => {
|
|
148
|
-
throw new Error(`Problem deleting ${this.type} ${this.objString(delItem)}\n${err}`);
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}).promise();
|
|
152
|
-
}
|
|
57
|
+
didUpdate(item) {
|
|
58
|
+
logger_1.default.info(`Updated [${this.type}]: ${this.objString(item)}`);
|
|
153
59
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
};
|
|
162
|
-
const payload = (0, _utils.stripFields)({ ...updateItem
|
|
163
|
-
}, this.stripUpdateFields);
|
|
164
|
-
return updateFN(params, payload).then(data => this.didUpdate(data)).catch(err => {
|
|
165
|
-
throw new Error(`Problem updating ${this.type} ${this.objString(updateItem)}\n${err}`);
|
|
60
|
+
objString(item) {
|
|
61
|
+
return (0, utils_1.dumpJSON)(item);
|
|
62
|
+
}
|
|
63
|
+
getType() {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
// Each type to impl how to get the existing as its not consistent across the mgnt api.
|
|
66
|
+
throw new Error(`Must implement getType for type ${this.type}`);
|
|
166
67
|
});
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
this.didCreate(data);
|
|
175
|
-
this.created += 1;
|
|
176
|
-
}).catch(err => {
|
|
177
|
-
throw new Error(`Problem creating ${this.type} ${this.objString(createItem)}\n${err}`);
|
|
68
|
+
}
|
|
69
|
+
load() {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
// Load Asset from Tenant
|
|
72
|
+
logger_1.default.info(`Retrieving ${this.type} data from Auth0`);
|
|
73
|
+
this.existing = yield this.getType();
|
|
74
|
+
return { [this.type]: this.existing };
|
|
178
75
|
});
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
76
|
+
}
|
|
77
|
+
calcChanges(assets) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
const typeAssets = assets[this.type];
|
|
80
|
+
// Do nothing if not set
|
|
81
|
+
if (!typeAssets)
|
|
82
|
+
return {};
|
|
83
|
+
const existing = yield this.getType();
|
|
84
|
+
// Figure out what needs to be updated vs created
|
|
85
|
+
return (0, utils_1.calcChanges)(this, typeAssets, existing, this.identifiers);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
validate(assets) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
// Ensure no duplication in id and name
|
|
91
|
+
const typeAssets = assets[this.type];
|
|
92
|
+
// Do nothing if not set
|
|
93
|
+
if (!Array.isArray(typeAssets))
|
|
94
|
+
return;
|
|
95
|
+
// Do not allow items with same name
|
|
96
|
+
const duplicateNames = (0, utils_1.duplicateItems)(typeAssets, 'name');
|
|
97
|
+
if (duplicateNames.length > 0) {
|
|
98
|
+
const formatted = duplicateNames.map((dups) => dups.map((d) => `${d.name}`));
|
|
99
|
+
throw new ValidationError_1.default(`There are multiple ${this.type} with the same name combinations
|
|
100
|
+
${(0, utils_1.dumpJSON)(formatted)}.
|
|
101
|
+
Names must be unique.`);
|
|
102
|
+
}
|
|
103
|
+
// Do not allow items with same id
|
|
104
|
+
const duplicateIDs = (0, utils_1.duplicateItems)(typeAssets, this.id);
|
|
105
|
+
if (duplicateIDs.length > 0) {
|
|
106
|
+
const formatted = duplicateIDs.map((dups) => dups.map((d) => `${d[this.id]}`));
|
|
107
|
+
throw new ValidationError_1.default(`There are multiple ${this.type} for the following stage-order combinations
|
|
108
|
+
${(0, utils_1.dumpJSON)(formatted)}.
|
|
109
|
+
Only one rule must be defined for the same order number in a stage.`);
|
|
110
|
+
}
|
|
195
111
|
});
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
112
|
+
}
|
|
113
|
+
processChanges(assets, changes) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
if (!changes) {
|
|
116
|
+
changes = yield this.calcChanges(assets);
|
|
117
|
+
}
|
|
118
|
+
const del = changes.del || [];
|
|
119
|
+
const update = changes.update || [];
|
|
120
|
+
const create = changes.create || [];
|
|
121
|
+
const conflicts = changes.conflicts || [];
|
|
122
|
+
logger_1.default.debug(`Start processChanges for ${this.type} [delete:${del.length}] [update:${update.length}], [create:${create.length}], [conflicts:${conflicts.length}]`);
|
|
123
|
+
// Process Deleted
|
|
124
|
+
if (del.length > 0) {
|
|
125
|
+
const allowDelete = this.config('AUTH0_ALLOW_DELETE') === 'true' || this.config('AUTH0_ALLOW_DELETE') === true;
|
|
126
|
+
const byExtension = this.config('EXTENSION_SECRET') && (this.type === 'rules' || this.type === 'resourceServers');
|
|
127
|
+
const shouldDelete = allowDelete || byExtension;
|
|
128
|
+
if (!shouldDelete) {
|
|
129
|
+
logger_1.default.warn(`Detected the following ${this.type} should be deleted. Doing so may be destructive.\nYou can enable deletes by setting 'AUTH0_ALLOW_DELETE' to true in the config
|
|
130
|
+
\n${changes.del.map((i) => this.objString(i)).join('\n')}
|
|
131
|
+
`);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
yield this.client.pool.addEachTask({
|
|
135
|
+
data: del || [],
|
|
136
|
+
generator: (delItem) => {
|
|
137
|
+
const delFunction = this.getClientFN(this.functions.delete);
|
|
138
|
+
return delFunction({ [this.id]: delItem[this.id] })
|
|
139
|
+
.then(() => {
|
|
140
|
+
this.didDelete(delItem);
|
|
141
|
+
this.deleted += 1;
|
|
142
|
+
})
|
|
143
|
+
.catch((err) => {
|
|
144
|
+
throw new Error(`Problem deleting ${this.type} ${this.objString(delItem)}\n${err}`);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}).promise();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// Process Renaming Entries Temp due to conflicts in names
|
|
151
|
+
yield this.client.pool.addEachTask({
|
|
152
|
+
data: conflicts || [],
|
|
153
|
+
generator: (updateItem) => {
|
|
154
|
+
const updateFN = this.getClientFN(this.functions.update);
|
|
155
|
+
const params = { [this.id]: updateItem[this.id] };
|
|
156
|
+
const payload = (0, utils_1.stripFields)(Object.assign({}, updateItem), this.stripUpdateFields);
|
|
157
|
+
return updateFN(params, payload)
|
|
158
|
+
.then((data) => this.didUpdate(data))
|
|
159
|
+
.catch((err) => {
|
|
160
|
+
throw new Error(`Problem updating ${this.type} ${this.objString(updateItem)}\n${err}`);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}).promise();
|
|
164
|
+
// Process Creations
|
|
165
|
+
yield this.client.pool.addEachTask({
|
|
166
|
+
data: create || [],
|
|
167
|
+
generator: (createItem) => {
|
|
168
|
+
const createFunction = this.getClientFN(this.functions.create);
|
|
169
|
+
return createFunction(createItem)
|
|
170
|
+
.then((data) => {
|
|
171
|
+
this.didCreate(data);
|
|
172
|
+
this.created += 1;
|
|
173
|
+
})
|
|
174
|
+
.catch((err) => {
|
|
175
|
+
throw new Error(`Problem creating ${this.type} ${this.objString(createItem)}\n${err}`);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}).promise();
|
|
179
|
+
// Process Updates and strip fields not allowed in updates
|
|
180
|
+
yield this.client.pool.addEachTask({
|
|
181
|
+
data: update || [],
|
|
182
|
+
generator: (updateItem) => {
|
|
183
|
+
const updateFN = this.getClientFN(this.functions.update);
|
|
184
|
+
const params = { [this.id]: updateItem[this.id] };
|
|
185
|
+
const payload = (0, utils_1.stripFields)(Object.assign({}, updateItem), this.stripUpdateFields);
|
|
186
|
+
return updateFN(params, payload)
|
|
187
|
+
.then((data) => {
|
|
188
|
+
this.didUpdate(data);
|
|
189
|
+
this.updated += 1;
|
|
190
|
+
})
|
|
191
|
+
.catch((err) => {
|
|
192
|
+
throw new Error(`Problem updating ${this.type} ${this.objString(updateItem)}\n${err}`);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}).promise();
|
|
196
|
+
});
|
|
197
|
+
}
|
|
200
198
|
}
|
|
201
|
-
|
|
202
|
-
exports.default = DefaultHandler;
|
|
199
|
+
exports.default = DefaultHandler;
|
|
@@ -1,84 +1,73 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const schema = exports.schema = {
|
|
15
|
-
type: 'object'
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
13
|
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.schema = void 0;
|
|
16
|
+
const default_1 = __importDefault(require("./default"));
|
|
17
|
+
exports.schema = { type: 'object' };
|
|
18
|
+
// The Management API requires the fields to be specified
|
|
17
19
|
const defaultFields = ['name', 'enabled', 'credentials', 'settings', 'default_from_address'];
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
super({ ...options,
|
|
22
|
-
type: 'emailProvider'
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async getType() {
|
|
27
|
-
try {
|
|
28
|
-
return await this.client.emailProvider.get({
|
|
29
|
-
include_fields: true,
|
|
30
|
-
fields: defaultFields
|
|
31
|
-
});
|
|
32
|
-
} catch (err) {
|
|
33
|
-
if (err.statusCode === 404) return {};
|
|
34
|
-
throw err;
|
|
20
|
+
class EmailProviderHandler extends default_1.default {
|
|
21
|
+
constructor(options) {
|
|
22
|
+
super(Object.assign(Object.assign({}, options), { type: 'emailProvider' }));
|
|
35
23
|
}
|
|
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
|
-
|
|
24
|
+
getType() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
try {
|
|
27
|
+
return yield this.client.emailProvider.get({ include_fields: true, fields: defaultFields });
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
if (err.statusCode === 404)
|
|
31
|
+
return {};
|
|
32
|
+
throw err;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
objString(provider) {
|
|
37
|
+
return super.objString({ name: provider.name, enabled: provider.enabled });
|
|
38
|
+
}
|
|
39
|
+
processChanges(assets) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const { emailProvider } = assets;
|
|
42
|
+
// Do nothing if not set
|
|
43
|
+
if (!emailProvider)
|
|
44
|
+
return;
|
|
45
|
+
if (Object.keys(emailProvider).length > 0) {
|
|
46
|
+
let existing = yield this.getType();
|
|
47
|
+
// Check for existing Email Provider
|
|
48
|
+
if (existing.name) {
|
|
49
|
+
if (existing.name !== emailProvider.name) {
|
|
50
|
+
// Delete the current provider as it's different
|
|
51
|
+
yield this.client.emailProvider.delete();
|
|
52
|
+
this.didDelete(existing);
|
|
53
|
+
existing = {};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Now configure or update depending if it is configured already
|
|
57
|
+
if (existing.name) {
|
|
58
|
+
const provider = { name: emailProvider.name, enabled: emailProvider.enabled };
|
|
59
|
+
const updated = yield this.client.emailProvider.update(provider, emailProvider);
|
|
60
|
+
this.updated += 1;
|
|
61
|
+
this.didUpdate(updated);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const provider = { name: emailProvider.name, enabled: emailProvider.enabled };
|
|
65
|
+
const created = yield this.client.emailProvider.configure(provider, emailProvider);
|
|
66
|
+
this.created += 1;
|
|
67
|
+
this.didCreate(created);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
79
71
|
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
72
|
}
|
|
83
|
-
|
|
84
|
-
exports.default = EmailProviderHandler;
|
|
73
|
+
exports.default = EmailProviderHandler;
|