auth0-deploy-cli 7.5.2 → 7.7.1
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/.eslintrc +7 -41
- package/.husky/pre-commit +4 -0
- package/.husky/pre-push +3 -1
- package/.prettierignore +10 -0
- package/.prettierrc.json +4 -0
- package/CHANGELOG.md +219 -7
- package/CONTRIBUTING.md +2 -2
- package/README.md +3 -0
- package/lib/args.js +16 -17
- package/lib/commands/export.js +3 -3
- package/lib/commands/import.js +7 -6
- package/lib/commands/index.js +1 -1
- package/lib/configFactory.js +5 -1
- package/lib/context/defaults.js +4 -3
- package/lib/context/directory/handlers/actions.js +6 -5
- package/lib/context/directory/handlers/attackProtection.js +10 -9
- package/lib/context/directory/handlers/branding.js +60 -0
- package/lib/context/directory/handlers/clientGrants.js +6 -4
- package/lib/context/directory/handlers/clients.js +4 -3
- package/lib/context/directory/handlers/connections.js +7 -4
- package/lib/context/directory/handlers/databases.js +30 -22
- package/lib/context/directory/handlers/emailProvider.js +6 -4
- package/lib/context/directory/handlers/emailTemplates.js +13 -11
- package/lib/context/directory/handlers/guardianFactorProviders.js +6 -4
- package/lib/context/directory/handlers/guardianFactorTemplates.js +6 -4
- package/lib/context/directory/handlers/guardianFactors.js +6 -4
- package/lib/context/directory/handlers/guardianPhoneFactorMessageTypes.js +4 -3
- package/lib/context/directory/handlers/guardianPhoneFactorSelectedProvider.js +4 -3
- package/lib/context/directory/handlers/guardianPolicies.js +4 -3
- package/lib/context/directory/handlers/hooks.js +5 -4
- package/lib/context/directory/handlers/index.js +5 -2
- package/lib/context/directory/handlers/migrations.js +8 -8
- package/lib/context/directory/handlers/organizations.js +4 -3
- package/lib/context/directory/handlers/pages.js +20 -20
- package/lib/context/directory/handlers/resourceServers.js +6 -4
- package/lib/context/directory/handlers/roles.js +4 -3
- package/lib/context/directory/handlers/rules.js +5 -4
- package/lib/context/directory/handlers/rulesConfigs.js +7 -5
- package/lib/context/directory/handlers/tenant.js +7 -4
- package/lib/context/directory/handlers/triggers.js +3 -2
- package/lib/context/directory/index.js +23 -22
- package/lib/context/index.js +83 -61
- package/lib/context/yaml/handlers/actions.js +12 -8
- package/lib/context/yaml/handlers/attackProtection.js +6 -12
- package/lib/context/yaml/handlers/branding.js +66 -0
- package/lib/context/yaml/handlers/clientGrants.js +5 -4
- package/lib/context/yaml/handlers/clients.js +9 -6
- package/lib/context/yaml/handlers/connections.js +10 -7
- package/lib/context/yaml/handlers/databases.js +15 -10
- package/lib/context/yaml/handlers/emailProvider.js +7 -5
- package/lib/context/yaml/handlers/emailTemplates.js +6 -5
- package/lib/context/yaml/handlers/guardianFactorProviders.js +6 -13
- package/lib/context/yaml/handlers/guardianFactorTemplates.js +6 -13
- package/lib/context/yaml/handlers/guardianFactors.js +6 -13
- package/lib/context/yaml/handlers/guardianPhoneFactorMessageTypes.js +6 -13
- package/lib/context/yaml/handlers/guardianPhoneFactorSelectedProvider.js +6 -13
- package/lib/context/yaml/handlers/guardianPolicies.js +6 -13
- package/lib/context/yaml/handlers/hooks.js +7 -5
- package/lib/context/yaml/handlers/index.js +5 -2
- package/lib/context/yaml/handlers/migrations.js +3 -2
- package/lib/context/yaml/handlers/organizations.js +6 -5
- package/lib/context/yaml/handlers/pages.js +6 -5
- package/lib/context/yaml/handlers/resourceServers.js +5 -4
- package/lib/context/yaml/handlers/roles.js +6 -5
- package/lib/context/yaml/handlers/rules.js +6 -5
- package/lib/context/yaml/handlers/rulesConfigs.js +6 -5
- package/lib/context/yaml/handlers/tenant.js +7 -5
- package/lib/context/yaml/handlers/triggers.js +5 -4
- package/lib/context/yaml/index.js +33 -24
- package/lib/index.js +20 -15
- package/lib/logger.js +4 -3
- package/lib/readonly.js +11 -16
- package/lib/sessionDurationsToMinutes.js +15 -0
- package/lib/tools/auth0/client.js +12 -12
- package/lib/tools/auth0/handlers/actions.js +21 -23
- package/lib/tools/auth0/handlers/attackProtection.js +14 -17
- package/lib/tools/auth0/handlers/branding.js +71 -13
- package/lib/tools/auth0/handlers/clientGrants.js +17 -10
- package/lib/tools/auth0/handlers/clients.js +15 -8
- package/lib/tools/auth0/handlers/connections.js +30 -10
- package/lib/tools/auth0/handlers/databases.js +25 -13
- package/lib/tools/auth0/handlers/default.js +46 -28
- package/lib/tools/auth0/handlers/emailTemplates.js +8 -10
- package/lib/tools/auth0/handlers/guardianFactorProviders.js +3 -3
- package/lib/tools/auth0/handlers/guardianFactorTemplates.js +3 -3
- package/lib/tools/auth0/handlers/guardianFactors.js +3 -3
- package/lib/tools/auth0/handlers/guardianPhoneFactorMessageTypes.js +11 -10
- package/lib/tools/auth0/handlers/guardianPhoneFactorSelectedProvider.js +10 -9
- package/lib/tools/auth0/handlers/guardianPolicies.js +5 -4
- package/lib/tools/auth0/handlers/hooks.js +34 -21
- package/lib/tools/auth0/handlers/index.js +31 -27
- package/lib/tools/auth0/handlers/migrations.js +2 -1
- package/lib/tools/auth0/handlers/organizations.js +67 -32
- package/lib/tools/auth0/handlers/pages.js +20 -14
- package/lib/tools/auth0/handlers/prompts.js +1 -0
- package/lib/tools/auth0/handlers/resourceServers.js +28 -15
- package/lib/tools/auth0/handlers/roles.js +61 -32
- package/lib/tools/auth0/handlers/rules.js +58 -35
- package/lib/tools/auth0/handlers/rulesConfigs.js +12 -6
- package/lib/tools/auth0/handlers/tenant.js +8 -4
- package/lib/tools/auth0/handlers/triggers.js +11 -12
- package/lib/tools/auth0/index.js +15 -31
- package/lib/tools/auth0/schema.js +7 -27
- package/lib/tools/calculateChanges.js +149 -0
- package/lib/tools/constants.js +162 -154
- package/lib/tools/deploy.js +1 -1
- package/lib/tools/index.js +1 -1
- package/lib/tools/logger.js +14 -8
- package/lib/tools/utils.js +34 -150
- package/lib/tools/{ValidationError.js → validationError.js} +3 -1
- package/lib/types.js +2 -0
- package/lib/utils.js +18 -25
- package/package.json +11 -2
- package/tsconfig.json +2 -3
- package/typescript-migration-progress.sh +1 -1
|
@@ -13,9 +13,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.order = void 0;
|
|
16
|
-
const
|
|
16
|
+
const validationError_1 = __importDefault(require("../../validationError"));
|
|
17
17
|
const logger_1 = __importDefault(require("../../logger"));
|
|
18
18
|
const utils_1 = require("../../utils");
|
|
19
|
+
const calculateChanges_1 = require("../../calculateChanges");
|
|
19
20
|
function order(value) {
|
|
20
21
|
return function decorator(t, n, descriptor) {
|
|
21
22
|
descriptor.value.order = value; // eslint-disable-line
|
|
@@ -23,7 +24,7 @@ function order(value) {
|
|
|
23
24
|
};
|
|
24
25
|
}
|
|
25
26
|
exports.order = order;
|
|
26
|
-
class
|
|
27
|
+
class APIHandler {
|
|
27
28
|
constructor(options) {
|
|
28
29
|
this.config = options.config;
|
|
29
30
|
this.type = options.type;
|
|
@@ -32,11 +33,8 @@ class DefaultHandler {
|
|
|
32
33
|
this.existing = null;
|
|
33
34
|
this.identifiers = options.identifiers || ['id', 'name'];
|
|
34
35
|
this.objectFields = options.objectFields || [];
|
|
35
|
-
this.stripUpdateFields = [
|
|
36
|
-
|
|
37
|
-
this.id
|
|
38
|
-
];
|
|
39
|
-
this.functions = Object.assign({ getAll: 'getAll', create: 'create', update: 'update', delete: 'delete' }, options.functions || {});
|
|
36
|
+
this.stripUpdateFields = [...(options.stripUpdateFields || []), this.id];
|
|
37
|
+
this.functions = Object.assign({ getAll: 'getAll', create: 'create', delete: 'delete', update: 'update' }, (options.functions || {}));
|
|
40
38
|
this.updated = 0;
|
|
41
39
|
this.created = 0;
|
|
42
40
|
this.deleted = 0;
|
|
@@ -58,7 +56,7 @@ class DefaultHandler {
|
|
|
58
56
|
logger_1.default.info(`Updated [${this.type}]: ${this.objString(item)}`);
|
|
59
57
|
}
|
|
60
58
|
objString(item) {
|
|
61
|
-
return (0, utils_1.
|
|
59
|
+
return (0, utils_1.convertJsonToString)(item);
|
|
62
60
|
}
|
|
63
61
|
getType() {
|
|
64
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -79,10 +77,21 @@ class DefaultHandler {
|
|
|
79
77
|
const typeAssets = assets[this.type];
|
|
80
78
|
// Do nothing if not set
|
|
81
79
|
if (!typeAssets)
|
|
82
|
-
return {
|
|
80
|
+
return {
|
|
81
|
+
del: [],
|
|
82
|
+
create: [],
|
|
83
|
+
conflicts: [],
|
|
84
|
+
update: [],
|
|
85
|
+
};
|
|
83
86
|
const existing = yield this.getType();
|
|
84
87
|
// Figure out what needs to be updated vs created
|
|
85
|
-
return (0,
|
|
88
|
+
return (0, calculateChanges_1.calculateChanges)({
|
|
89
|
+
handler: this,
|
|
90
|
+
assets: typeAssets,
|
|
91
|
+
//@ts-ignore TODO: investigate what happens when `existing` is null
|
|
92
|
+
existing,
|
|
93
|
+
identifiers: this.identifiers,
|
|
94
|
+
});
|
|
86
95
|
});
|
|
87
96
|
}
|
|
88
97
|
validate(assets) {
|
|
@@ -96,16 +105,16 @@ class DefaultHandler {
|
|
|
96
105
|
const duplicateNames = (0, utils_1.duplicateItems)(typeAssets, 'name');
|
|
97
106
|
if (duplicateNames.length > 0) {
|
|
98
107
|
const formatted = duplicateNames.map((dups) => dups.map((d) => `${d.name}`));
|
|
99
|
-
throw new
|
|
100
|
-
${(0, utils_1.
|
|
108
|
+
throw new validationError_1.default(`There are multiple ${this.type} with the same name combinations
|
|
109
|
+
${(0, utils_1.convertJsonToString)(formatted)}.
|
|
101
110
|
Names must be unique.`);
|
|
102
111
|
}
|
|
103
112
|
// Do not allow items with same id
|
|
104
113
|
const duplicateIDs = (0, utils_1.duplicateItems)(typeAssets, this.id);
|
|
105
114
|
if (duplicateIDs.length > 0) {
|
|
106
115
|
const formatted = duplicateIDs.map((dups) => dups.map((d) => `${d[this.id]}`));
|
|
107
|
-
throw new
|
|
108
|
-
${(0, utils_1.
|
|
116
|
+
throw new validationError_1.default(`There are multiple ${this.type} for the following stage-order combinations
|
|
117
|
+
${(0, utils_1.convertJsonToString)(formatted)}.
|
|
109
118
|
Only one rule must be defined for the same order number in a stage.`);
|
|
110
119
|
}
|
|
111
120
|
});
|
|
@@ -123,7 +132,8 @@ class DefaultHandler {
|
|
|
123
132
|
// Process Deleted
|
|
124
133
|
if (del.length > 0) {
|
|
125
134
|
const allowDelete = this.config('AUTH0_ALLOW_DELETE') === 'true' || this.config('AUTH0_ALLOW_DELETE') === true;
|
|
126
|
-
const byExtension = this.config('EXTENSION_SECRET') &&
|
|
135
|
+
const byExtension = this.config('EXTENSION_SECRET') &&
|
|
136
|
+
(this.type === 'rules' || this.type === 'resourceServers');
|
|
127
137
|
const shouldDelete = allowDelete || byExtension;
|
|
128
138
|
if (!shouldDelete) {
|
|
129
139
|
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
|
|
@@ -131,7 +141,8 @@ class DefaultHandler {
|
|
|
131
141
|
`);
|
|
132
142
|
}
|
|
133
143
|
else {
|
|
134
|
-
yield this.client.pool
|
|
144
|
+
yield this.client.pool
|
|
145
|
+
.addEachTask({
|
|
135
146
|
data: del || [],
|
|
136
147
|
generator: (delItem) => {
|
|
137
148
|
const delFunction = this.getClientFN(this.functions.delete);
|
|
@@ -143,12 +154,14 @@ class DefaultHandler {
|
|
|
143
154
|
.catch((err) => {
|
|
144
155
|
throw new Error(`Problem deleting ${this.type} ${this.objString(delItem)}\n${err}`);
|
|
145
156
|
});
|
|
146
|
-
}
|
|
147
|
-
})
|
|
157
|
+
},
|
|
158
|
+
})
|
|
159
|
+
.promise();
|
|
148
160
|
}
|
|
149
161
|
}
|
|
150
162
|
// Process Renaming Entries Temp due to conflicts in names
|
|
151
|
-
yield this.client.pool
|
|
163
|
+
yield this.client.pool
|
|
164
|
+
.addEachTask({
|
|
152
165
|
data: conflicts || [],
|
|
153
166
|
generator: (updateItem) => {
|
|
154
167
|
const updateFN = this.getClientFN(this.functions.update);
|
|
@@ -159,10 +172,12 @@ class DefaultHandler {
|
|
|
159
172
|
.catch((err) => {
|
|
160
173
|
throw new Error(`Problem updating ${this.type} ${this.objString(updateItem)}\n${err}`);
|
|
161
174
|
});
|
|
162
|
-
}
|
|
163
|
-
})
|
|
175
|
+
},
|
|
176
|
+
})
|
|
177
|
+
.promise();
|
|
164
178
|
// Process Creations
|
|
165
|
-
yield this.client.pool
|
|
179
|
+
yield this.client.pool
|
|
180
|
+
.addEachTask({
|
|
166
181
|
data: create || [],
|
|
167
182
|
generator: (createItem) => {
|
|
168
183
|
const createFunction = this.getClientFN(this.functions.create);
|
|
@@ -174,10 +189,12 @@ class DefaultHandler {
|
|
|
174
189
|
.catch((err) => {
|
|
175
190
|
throw new Error(`Problem creating ${this.type} ${this.objString(createItem)}\n${err}`);
|
|
176
191
|
});
|
|
177
|
-
}
|
|
178
|
-
})
|
|
192
|
+
},
|
|
193
|
+
})
|
|
194
|
+
.promise();
|
|
179
195
|
// Process Updates and strip fields not allowed in updates
|
|
180
|
-
yield this.client.pool
|
|
196
|
+
yield this.client.pool
|
|
197
|
+
.addEachTask({
|
|
181
198
|
data: update || [],
|
|
182
199
|
generator: (updateItem) => {
|
|
183
200
|
const updateFN = this.getClientFN(this.functions.update);
|
|
@@ -191,9 +208,10 @@ class DefaultHandler {
|
|
|
191
208
|
.catch((err) => {
|
|
192
209
|
throw new Error(`Problem updating ${this.type} ${this.objString(updateItem)}\n${err}`);
|
|
193
210
|
});
|
|
194
|
-
}
|
|
195
|
-
})
|
|
211
|
+
},
|
|
212
|
+
})
|
|
213
|
+
.promise();
|
|
196
214
|
});
|
|
197
215
|
}
|
|
198
216
|
}
|
|
199
|
-
exports.default =
|
|
217
|
+
exports.default = APIHandler;
|
|
@@ -44,19 +44,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
44
44
|
exports.schema = exports.supportedTemplates = void 0;
|
|
45
45
|
const default_1 = __importStar(require("./default"));
|
|
46
46
|
const constants_1 = __importDefault(require("../../constants"));
|
|
47
|
-
exports.supportedTemplates = constants_1.default.EMAIL_TEMPLATES_NAMES
|
|
48
|
-
.filter((p) => p.includes('.json'))
|
|
49
|
-
.map((p) => p.replace('.json', ''));
|
|
47
|
+
exports.supportedTemplates = constants_1.default.EMAIL_TEMPLATES_NAMES.filter((p) => p.includes('.json')).map((p) => p.replace('.json', ''));
|
|
50
48
|
exports.schema = {
|
|
51
49
|
type: 'array',
|
|
52
50
|
items: {
|
|
53
51
|
type: 'object',
|
|
54
52
|
properties: {
|
|
55
53
|
template: { type: 'string', enum: exports.supportedTemplates },
|
|
56
|
-
body: { type: 'string', default: '' }
|
|
54
|
+
body: { type: 'string', default: '' },
|
|
57
55
|
},
|
|
58
|
-
required: ['template']
|
|
59
|
-
}
|
|
56
|
+
required: ['template'],
|
|
57
|
+
},
|
|
60
58
|
};
|
|
61
59
|
class EmailTemplateHandler extends default_1.default {
|
|
62
60
|
constructor(options) {
|
|
@@ -64,11 +62,10 @@ class EmailTemplateHandler extends default_1.default {
|
|
|
64
62
|
}
|
|
65
63
|
getType() {
|
|
66
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
const emailTemplates =
|
|
68
|
-
yield Promise.all(constants_1.default.EMAIL_TEMPLATES_TYPES.map((name) => __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
const emailTemplates = yield Promise.all(constants_1.default.EMAIL_TEMPLATES_TYPES.map((name) => __awaiter(this, void 0, void 0, function* () {
|
|
69
66
|
try {
|
|
70
67
|
const template = yield this.client.emailTemplates.get({ name });
|
|
71
|
-
|
|
68
|
+
return template;
|
|
72
69
|
}
|
|
73
70
|
catch (err) {
|
|
74
71
|
// Ignore if not found, else throw error
|
|
@@ -77,7 +74,8 @@ class EmailTemplateHandler extends default_1.default {
|
|
|
77
74
|
}
|
|
78
75
|
}
|
|
79
76
|
})));
|
|
80
|
-
|
|
77
|
+
const nonEmptyTemplates = emailTemplates.filter((template) => !!template);
|
|
78
|
+
return nonEmptyTemplates;
|
|
81
79
|
});
|
|
82
80
|
}
|
|
83
81
|
updateOrCreate(emailTemplate) {
|
|
@@ -27,10 +27,10 @@ exports.schema = {
|
|
|
27
27
|
type: 'object',
|
|
28
28
|
properties: {
|
|
29
29
|
name: { type: 'string', enum: constants_1.default.GUARDIAN_FACTORS },
|
|
30
|
-
provider: { type: 'string', enum: mappings.map((p) => p.provider) }
|
|
30
|
+
provider: { type: 'string', enum: mappings.map((p) => p.provider) },
|
|
31
31
|
},
|
|
32
|
-
required: ['name', 'provider']
|
|
33
|
-
}
|
|
32
|
+
required: ['name', 'provider'],
|
|
33
|
+
},
|
|
34
34
|
};
|
|
35
35
|
class GuardianFactorProvidersHandler extends default_1.default {
|
|
36
36
|
constructor(options) {
|
|
@@ -20,10 +20,10 @@ exports.schema = {
|
|
|
20
20
|
items: {
|
|
21
21
|
type: 'object',
|
|
22
22
|
properties: {
|
|
23
|
-
name: { type: 'string', enum: constants_1.default.GUARDIAN_FACTOR_TEMPLATES }
|
|
23
|
+
name: { type: 'string', enum: constants_1.default.GUARDIAN_FACTOR_TEMPLATES },
|
|
24
24
|
},
|
|
25
|
-
required: ['name']
|
|
26
|
-
}
|
|
25
|
+
required: ['name'],
|
|
26
|
+
},
|
|
27
27
|
};
|
|
28
28
|
class GuardianFactorTemplatesHandler extends default_1.default {
|
|
29
29
|
constructor(options) {
|
|
@@ -20,10 +20,10 @@ exports.schema = {
|
|
|
20
20
|
items: {
|
|
21
21
|
type: 'object',
|
|
22
22
|
properties: {
|
|
23
|
-
name: { type: 'string', enum: constants_1.default.GUARDIAN_FACTORS }
|
|
23
|
+
name: { type: 'string', enum: constants_1.default.GUARDIAN_FACTORS },
|
|
24
24
|
},
|
|
25
|
-
required: ['name']
|
|
26
|
-
}
|
|
25
|
+
required: ['name'],
|
|
26
|
+
},
|
|
27
27
|
};
|
|
28
28
|
class GuardianFactorsHandler extends default_1.default {
|
|
29
29
|
constructor(options) {
|
|
@@ -22,22 +22,22 @@ exports.schema = {
|
|
|
22
22
|
type: 'array',
|
|
23
23
|
items: {
|
|
24
24
|
type: 'string',
|
|
25
|
-
enum: constants_1.default.GUARDIAN_PHONE_MESSAGE_TYPES
|
|
26
|
-
}
|
|
27
|
-
}
|
|
25
|
+
enum: constants_1.default.GUARDIAN_PHONE_MESSAGE_TYPES,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
28
|
},
|
|
29
|
-
additionalProperties: false
|
|
29
|
+
additionalProperties: false,
|
|
30
30
|
};
|
|
31
31
|
const isFeatureUnavailableError = (err) => {
|
|
32
32
|
if (err.statusCode === 404) {
|
|
33
33
|
// Older Management API version where the endpoint is not available.
|
|
34
34
|
return true;
|
|
35
35
|
}
|
|
36
|
-
if (err.statusCode === 403
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
if (err.statusCode === 403 &&
|
|
37
|
+
err.originalError &&
|
|
38
|
+
err.originalError.response &&
|
|
39
|
+
err.originalError.response.body &&
|
|
40
|
+
err.originalError.response.body.errorCode === 'voice_mfa_not_allowed') {
|
|
41
41
|
// Recent Management API version, but with feature explicitly disabled.
|
|
42
42
|
return true;
|
|
43
43
|
}
|
|
@@ -50,7 +50,8 @@ class GuardianPhoneMessageTypesHandler extends default_1.default {
|
|
|
50
50
|
getType() {
|
|
51
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
52
|
// in case client version does not support the operation
|
|
53
|
-
if (!this.client.guardian ||
|
|
53
|
+
if (!this.client.guardian ||
|
|
54
|
+
typeof this.client.guardian.getPhoneFactorMessageTypes !== 'function') {
|
|
54
55
|
return {};
|
|
55
56
|
}
|
|
56
57
|
if (this.existing)
|
|
@@ -20,21 +20,21 @@ exports.schema = {
|
|
|
20
20
|
properties: {
|
|
21
21
|
provider: {
|
|
22
22
|
type: 'string',
|
|
23
|
-
enum: constants_1.default.GUARDIAN_PHONE_PROVIDERS
|
|
24
|
-
}
|
|
23
|
+
enum: constants_1.default.GUARDIAN_PHONE_PROVIDERS,
|
|
24
|
+
},
|
|
25
25
|
},
|
|
26
|
-
additionalProperties: false
|
|
26
|
+
additionalProperties: false,
|
|
27
27
|
};
|
|
28
28
|
const isFeatureUnavailableError = (err) => {
|
|
29
29
|
if (err.statusCode === 404) {
|
|
30
30
|
// Older Management API version where the endpoint is not available.
|
|
31
31
|
return true;
|
|
32
32
|
}
|
|
33
|
-
if (err.statusCode === 403
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
if (err.statusCode === 403 &&
|
|
34
|
+
err.originalError &&
|
|
35
|
+
err.originalError.response &&
|
|
36
|
+
err.originalError.response.body &&
|
|
37
|
+
err.originalError.response.body.errorCode === 'hooks_not_allowed') {
|
|
38
38
|
// Recent Management API version, but with feature explicitly disabled.
|
|
39
39
|
return true;
|
|
40
40
|
}
|
|
@@ -47,7 +47,8 @@ class GuardianPhoneSelectedProviderHandler extends default_1.default {
|
|
|
47
47
|
getType() {
|
|
48
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
49
|
// in case client version does not support the operation
|
|
50
|
-
if (!this.client.guardian ||
|
|
50
|
+
if (!this.client.guardian ||
|
|
51
|
+
typeof this.client.guardian.getPhoneFactorSelectedProvider !== 'function') {
|
|
51
52
|
return {};
|
|
52
53
|
}
|
|
53
54
|
if (this.existing)
|
|
@@ -22,16 +22,17 @@ exports.schema = {
|
|
|
22
22
|
type: 'array',
|
|
23
23
|
items: {
|
|
24
24
|
type: 'string',
|
|
25
|
-
enum: constants_1.default.GUARDIAN_POLICIES
|
|
26
|
-
}
|
|
27
|
-
}
|
|
25
|
+
enum: constants_1.default.GUARDIAN_POLICIES,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
28
|
},
|
|
29
|
-
additionalProperties: false
|
|
29
|
+
additionalProperties: false,
|
|
30
30
|
};
|
|
31
31
|
class GuardianPoliciesHandler extends default_1.default {
|
|
32
32
|
constructor(options) {
|
|
33
33
|
super(Object.assign(Object.assign({}, options), { type: 'guardianPolicies' }));
|
|
34
34
|
}
|
|
35
|
+
//TODO: standardize empty object literal with more intentional empty indicator
|
|
35
36
|
getType() {
|
|
36
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
38
|
// in case client version does not support the operation
|
|
@@ -15,10 +15,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.schema = exports.excludeSchema = void 0;
|
|
16
16
|
const default_1 = __importDefault(require("./default"));
|
|
17
17
|
const constants_1 = __importDefault(require("../../constants"));
|
|
18
|
-
const ALLOWED_TRIGGER_IDS = [
|
|
18
|
+
const ALLOWED_TRIGGER_IDS = [
|
|
19
|
+
'credentials-exchange',
|
|
20
|
+
'pre-user-registration',
|
|
21
|
+
'post-user-registration',
|
|
22
|
+
'post-change-password',
|
|
23
|
+
'send-phone-message',
|
|
24
|
+
];
|
|
19
25
|
exports.excludeSchema = {
|
|
20
26
|
type: 'array',
|
|
21
|
-
items: { type: 'string' }
|
|
27
|
+
items: { type: 'string' },
|
|
22
28
|
};
|
|
23
29
|
exports.schema = {
|
|
24
30
|
type: 'array',
|
|
@@ -28,37 +34,37 @@ exports.schema = {
|
|
|
28
34
|
properties: {
|
|
29
35
|
script: {
|
|
30
36
|
type: 'string',
|
|
31
|
-
description:
|
|
32
|
-
default: ''
|
|
37
|
+
description: "A script that contains the hook's code",
|
|
38
|
+
default: '',
|
|
33
39
|
},
|
|
34
40
|
name: {
|
|
35
41
|
type: 'string',
|
|
36
|
-
description:
|
|
37
|
-
pattern: '^[^-\\s][a-zA-Z0-9-\\s]+[^-\\s]$'
|
|
42
|
+
description: "The name of the hook. Can only contain alphanumeric characters, spaces and '-'. Can neither start nor end with '-' or spaces",
|
|
43
|
+
pattern: '^[^-\\s][a-zA-Z0-9-\\s]+[^-\\s]$',
|
|
38
44
|
},
|
|
39
45
|
enabled: {
|
|
40
46
|
type: 'boolean',
|
|
41
47
|
description: 'true if the hook is active, false otherwise',
|
|
42
|
-
default: false
|
|
48
|
+
default: false,
|
|
43
49
|
},
|
|
44
50
|
triggerId: {
|
|
45
51
|
type: 'string',
|
|
46
|
-
description:
|
|
47
|
-
enum: ALLOWED_TRIGGER_IDS
|
|
52
|
+
description: "The hooks's trigger ID",
|
|
53
|
+
enum: ALLOWED_TRIGGER_IDS,
|
|
48
54
|
},
|
|
49
55
|
secrets: {
|
|
50
56
|
type: 'object',
|
|
51
57
|
description: 'List of key-value pairs containing secrets available to the hook.',
|
|
52
|
-
default: {}
|
|
58
|
+
default: {},
|
|
53
59
|
},
|
|
54
60
|
dependencies: {
|
|
55
61
|
type: 'object',
|
|
56
62
|
default: {},
|
|
57
|
-
description: 'List of key-value pairs of NPM dependencies available to the hook.'
|
|
58
|
-
}
|
|
63
|
+
description: 'List of key-value pairs of NPM dependencies available to the hook.',
|
|
64
|
+
},
|
|
59
65
|
},
|
|
60
|
-
required: ['script', 'name', 'triggerId']
|
|
61
|
-
}
|
|
66
|
+
required: ['script', 'name', 'triggerId'],
|
|
67
|
+
},
|
|
62
68
|
};
|
|
63
69
|
const getCertainHook = (hooks, name, triggerId) => {
|
|
64
70
|
let result = null;
|
|
@@ -89,11 +95,13 @@ class HooksHandler extends default_1.default {
|
|
|
89
95
|
const changes = {
|
|
90
96
|
create: [],
|
|
91
97
|
update: [],
|
|
92
|
-
del: []
|
|
98
|
+
del: [],
|
|
99
|
+
conflicts: [],
|
|
93
100
|
};
|
|
94
101
|
hooks.forEach((hook) => {
|
|
95
102
|
const current = getCertainHook(allHooks, hook.name, hook.triggerId);
|
|
96
|
-
if (current) {
|
|
103
|
+
if (current) {
|
|
104
|
+
// if the hook was deleted we don't care about its secrets
|
|
97
105
|
const oldSecrets = current.secrets || {};
|
|
98
106
|
const newSecrets = hook.secrets || {};
|
|
99
107
|
const create = {};
|
|
@@ -131,6 +139,7 @@ class HooksHandler extends default_1.default {
|
|
|
131
139
|
})));
|
|
132
140
|
});
|
|
133
141
|
}
|
|
142
|
+
//@ts-ignore because hooks use a special reload argument
|
|
134
143
|
getType(reload) {
|
|
135
144
|
return __awaiter(this, void 0, void 0, function* () {
|
|
136
145
|
if (this.existing && !reload) {
|
|
@@ -143,8 +152,10 @@ class HooksHandler extends default_1.default {
|
|
|
143
152
|
try {
|
|
144
153
|
const hooks = yield this.client.hooks.getAll({ paginate: true, include_totals: true });
|
|
145
154
|
// hooks.getAll does not return code and secrets, we have to fetch hooks one-by-one
|
|
146
|
-
this.existing = yield Promise.all(hooks.map((hook) => this.client.hooks
|
|
147
|
-
.
|
|
155
|
+
this.existing = yield Promise.all(hooks.map((hook) => this.client.hooks
|
|
156
|
+
.get({ id: hook.id })
|
|
157
|
+
.then((hookWithCode) => this.client.hooks
|
|
158
|
+
.getSecrets({ id: hook.id })
|
|
148
159
|
.then((secrets) => (Object.assign(Object.assign({}, hookWithCode), { secrets }))))));
|
|
149
160
|
return this.existing;
|
|
150
161
|
}
|
|
@@ -168,7 +179,7 @@ class HooksHandler extends default_1.default {
|
|
|
168
179
|
del,
|
|
169
180
|
update: stripSecrets(update),
|
|
170
181
|
create: stripSecrets(create),
|
|
171
|
-
conflicts: stripSecrets(conflicts)
|
|
182
|
+
conflicts: stripSecrets(conflicts),
|
|
172
183
|
};
|
|
173
184
|
});
|
|
174
185
|
}
|
|
@@ -183,9 +194,11 @@ class HooksHandler extends default_1.default {
|
|
|
183
194
|
return;
|
|
184
195
|
const activeHooks = getActive(hooks);
|
|
185
196
|
ALLOWED_TRIGGER_IDS.forEach((type) => {
|
|
186
|
-
if (activeHooks[type].length > 1) {
|
|
197
|
+
if (activeHooks[type].length > 1) {
|
|
198
|
+
// There can be only one!
|
|
187
199
|
const conflict = activeHooks[type].map((h) => h.name).join(', ');
|
|
188
200
|
const err = new Error(`Only one active hook allowed for "${type}" extensibility point. Conflicting hooks: ${conflict}`);
|
|
201
|
+
//@ts-ignore need to investigate if appending status actually works here
|
|
189
202
|
err.status = 409;
|
|
190
203
|
throw err;
|
|
191
204
|
}
|
|
@@ -208,7 +221,7 @@ class HooksHandler extends default_1.default {
|
|
|
208
221
|
del: changes.del,
|
|
209
222
|
create: changes.create,
|
|
210
223
|
update: changes.update,
|
|
211
|
-
conflicts: changes.conflicts
|
|
224
|
+
conflicts: changes.conflicts,
|
|
212
225
|
});
|
|
213
226
|
yield this.processSecrets(hooks);
|
|
214
227
|
});
|
|
@@ -23,56 +23,60 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
|
|
26
|
+
//TODO:
|
|
27
27
|
const rules = __importStar(require("./rules"));
|
|
28
|
-
exports.rules = rules;
|
|
29
28
|
const rulesConfigs = __importStar(require("./rulesConfigs"));
|
|
30
|
-
exports.rulesConfigs = rulesConfigs;
|
|
31
29
|
const hooks = __importStar(require("./hooks"));
|
|
32
|
-
exports.hooks = hooks;
|
|
33
30
|
const pages = __importStar(require("./pages"));
|
|
34
|
-
exports.pages = pages;
|
|
35
31
|
const resourceServers = __importStar(require("./resourceServers"));
|
|
36
|
-
exports.resourceServers = resourceServers;
|
|
37
32
|
const databases = __importStar(require("./databases"));
|
|
38
|
-
exports.databases = databases;
|
|
39
33
|
const connections = __importStar(require("./connections"));
|
|
40
|
-
exports.connections = connections;
|
|
41
34
|
const clients = __importStar(require("./clients"));
|
|
42
|
-
exports.clients = clients;
|
|
43
35
|
const tenant = __importStar(require("./tenant"));
|
|
44
|
-
exports.tenant = tenant;
|
|
45
36
|
const emailProvider = __importStar(require("./emailProvider"));
|
|
46
|
-
exports.emailProvider = emailProvider;
|
|
47
37
|
const emailTemplates = __importStar(require("./emailTemplates"));
|
|
48
|
-
exports.emailTemplates = emailTemplates;
|
|
49
38
|
const clientGrants = __importStar(require("./clientGrants"));
|
|
50
|
-
exports.clientGrants = clientGrants;
|
|
51
39
|
const guardianFactors = __importStar(require("./guardianFactors"));
|
|
52
|
-
exports.guardianFactors = guardianFactors;
|
|
53
40
|
const guardianFactorProviders = __importStar(require("./guardianFactorProviders"));
|
|
54
|
-
exports.guardianFactorProviders = guardianFactorProviders;
|
|
55
41
|
const guardianFactorTemplates = __importStar(require("./guardianFactorTemplates"));
|
|
56
|
-
exports.guardianFactorTemplates = guardianFactorTemplates;
|
|
57
42
|
const guardianPolicies = __importStar(require("./guardianPolicies"));
|
|
58
|
-
exports.guardianPolicies = guardianPolicies;
|
|
59
43
|
const guardianPhoneFactorSelectedProvider = __importStar(require("./guardianPhoneFactorSelectedProvider"));
|
|
60
|
-
exports.guardianPhoneFactorSelectedProvider = guardianPhoneFactorSelectedProvider;
|
|
61
44
|
const guardianPhoneFactorMessageTypes = __importStar(require("./guardianPhoneFactorMessageTypes"));
|
|
62
|
-
exports.guardianPhoneFactorMessageTypes = guardianPhoneFactorMessageTypes;
|
|
63
45
|
const roles = __importStar(require("./roles"));
|
|
64
|
-
exports.roles = roles;
|
|
65
46
|
const branding = __importStar(require("./branding"));
|
|
66
|
-
exports.branding = branding;
|
|
67
47
|
const prompts = __importStar(require("./prompts"));
|
|
68
|
-
exports.prompts = prompts;
|
|
69
48
|
const migrations = __importStar(require("./migrations"));
|
|
70
|
-
exports.migrations = migrations;
|
|
71
49
|
const actions = __importStar(require("./actions"));
|
|
72
|
-
exports.actions = actions;
|
|
73
50
|
const triggers = __importStar(require("./triggers"));
|
|
74
|
-
exports.triggers = triggers;
|
|
75
51
|
const organizations = __importStar(require("./organizations"));
|
|
76
|
-
exports.organizations = organizations;
|
|
77
52
|
const attackProtection = __importStar(require("./attackProtection"));
|
|
78
|
-
|
|
53
|
+
const auth0ApiHandlers = {
|
|
54
|
+
rules,
|
|
55
|
+
rulesConfigs,
|
|
56
|
+
hooks,
|
|
57
|
+
pages,
|
|
58
|
+
resourceServers,
|
|
59
|
+
clients,
|
|
60
|
+
databases,
|
|
61
|
+
connections,
|
|
62
|
+
tenant,
|
|
63
|
+
emailProvider,
|
|
64
|
+
emailTemplates,
|
|
65
|
+
clientGrants,
|
|
66
|
+
guardianFactors,
|
|
67
|
+
guardianFactorProviders,
|
|
68
|
+
guardianFactorTemplates,
|
|
69
|
+
guardianPolicies,
|
|
70
|
+
guardianPhoneFactorSelectedProvider,
|
|
71
|
+
guardianPhoneFactorMessageTypes,
|
|
72
|
+
roles,
|
|
73
|
+
branding,
|
|
74
|
+
//@ts-ignore because prompts have not been universally implemented yet
|
|
75
|
+
prompts,
|
|
76
|
+
migrations,
|
|
77
|
+
actions,
|
|
78
|
+
triggers,
|
|
79
|
+
organizations,
|
|
80
|
+
attackProtection,
|
|
81
|
+
};
|
|
82
|
+
exports.default = auth0ApiHandlers; // TODO: apply stronger types to schema properties
|
|
@@ -46,12 +46,13 @@ const default_1 = __importStar(require("./default"));
|
|
|
46
46
|
const logger_1 = __importDefault(require("../../logger"));
|
|
47
47
|
exports.schema = {
|
|
48
48
|
type: 'object',
|
|
49
|
-
additionalProperties: { type: 'boolean' }
|
|
49
|
+
additionalProperties: { type: 'boolean' },
|
|
50
50
|
};
|
|
51
51
|
class MigrationsHandler extends default_1.default {
|
|
52
52
|
constructor(options) {
|
|
53
53
|
super(Object.assign(Object.assign({}, options), { type: 'migrations' }));
|
|
54
54
|
}
|
|
55
|
+
//TODO: standardize empty object literal with more intentional empty indicator
|
|
55
56
|
getType() {
|
|
56
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
58
|
try {
|