auth0-deploy-cli 7.6.0 → 7.7.0

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.
Files changed (112) hide show
  1. package/.eslintrc +7 -41
  2. package/.husky/pre-commit +4 -0
  3. package/.husky/pre-push +3 -1
  4. package/.prettierignore +10 -0
  5. package/.prettierrc.json +4 -0
  6. package/CHANGELOG.md +194 -7
  7. package/CONTRIBUTING.md +2 -2
  8. package/README.md +3 -0
  9. package/lib/args.js +16 -15
  10. package/lib/commands/export.js +3 -3
  11. package/lib/commands/import.js +6 -6
  12. package/lib/commands/index.js +1 -1
  13. package/lib/configFactory.js +5 -1
  14. package/lib/context/defaults.js +4 -3
  15. package/lib/context/directory/handlers/actions.js +3 -3
  16. package/lib/context/directory/handlers/attackProtection.js +4 -4
  17. package/lib/context/directory/handlers/branding.js +6 -5
  18. package/lib/context/directory/handlers/clientGrants.js +3 -2
  19. package/lib/context/directory/handlers/clients.js +1 -1
  20. package/lib/context/directory/handlers/connections.js +4 -2
  21. package/lib/context/directory/handlers/databases.js +13 -7
  22. package/lib/context/directory/handlers/emailProvider.js +3 -2
  23. package/lib/context/directory/handlers/emailTemplates.js +2 -2
  24. package/lib/context/directory/handlers/guardianFactorProviders.js +3 -2
  25. package/lib/context/directory/handlers/guardianFactorTemplates.js +3 -2
  26. package/lib/context/directory/handlers/guardianFactors.js +3 -2
  27. package/lib/context/directory/handlers/guardianPhoneFactorMessageTypes.js +1 -1
  28. package/lib/context/directory/handlers/guardianPhoneFactorSelectedProvider.js +1 -1
  29. package/lib/context/directory/handlers/guardianPolicies.js +1 -1
  30. package/lib/context/directory/handlers/hooks.js +2 -2
  31. package/lib/context/directory/handlers/index.js +3 -2
  32. package/lib/context/directory/handlers/organizations.js +1 -1
  33. package/lib/context/directory/handlers/pages.js +2 -2
  34. package/lib/context/directory/handlers/resourceServers.js +3 -2
  35. package/lib/context/directory/handlers/roles.js +1 -1
  36. package/lib/context/directory/handlers/rules.js +2 -2
  37. package/lib/context/directory/handlers/rulesConfigs.js +3 -2
  38. package/lib/context/directory/handlers/tenant.js +3 -2
  39. package/lib/context/directory/index.js +21 -18
  40. package/lib/context/index.js +66 -62
  41. package/lib/context/yaml/handlers/actions.js +9 -6
  42. package/lib/context/yaml/handlers/attackProtection.js +1 -1
  43. package/lib/context/yaml/handlers/branding.js +5 -4
  44. package/lib/context/yaml/handlers/clientGrants.js +2 -2
  45. package/lib/context/yaml/handlers/clients.js +6 -4
  46. package/lib/context/yaml/handlers/connections.js +7 -5
  47. package/lib/context/yaml/handlers/databases.js +12 -8
  48. package/lib/context/yaml/handlers/emailProvider.js +4 -3
  49. package/lib/context/yaml/handlers/emailTemplates.js +3 -3
  50. package/lib/context/yaml/handlers/guardianFactorProviders.js +1 -1
  51. package/lib/context/yaml/handlers/guardianFactorTemplates.js +1 -1
  52. package/lib/context/yaml/handlers/guardianFactors.js +1 -1
  53. package/lib/context/yaml/handlers/guardianPhoneFactorMessageTypes.js +1 -1
  54. package/lib/context/yaml/handlers/guardianPhoneFactorSelectedProvider.js +1 -1
  55. package/lib/context/yaml/handlers/guardianPolicies.js +1 -1
  56. package/lib/context/yaml/handlers/hooks.js +4 -3
  57. package/lib/context/yaml/handlers/index.js +3 -2
  58. package/lib/context/yaml/handlers/organizations.js +3 -3
  59. package/lib/context/yaml/handlers/pages.js +3 -3
  60. package/lib/context/yaml/handlers/resourceServers.js +2 -2
  61. package/lib/context/yaml/handlers/roles.js +3 -3
  62. package/lib/context/yaml/handlers/rules.js +3 -3
  63. package/lib/context/yaml/handlers/rulesConfigs.js +2 -2
  64. package/lib/context/yaml/handlers/tenant.js +4 -3
  65. package/lib/context/yaml/handlers/triggers.js +2 -2
  66. package/lib/context/yaml/index.js +31 -23
  67. package/lib/index.js +20 -15
  68. package/lib/logger.js +4 -3
  69. package/lib/readonly.js +11 -16
  70. package/lib/sessionDurationsToMinutes.js +15 -0
  71. package/lib/tools/auth0/client.js +6 -6
  72. package/lib/tools/auth0/handlers/actions.js +21 -23
  73. package/lib/tools/auth0/handlers/attackProtection.js +14 -17
  74. package/lib/tools/auth0/handlers/branding.js +13 -9
  75. package/lib/tools/auth0/handlers/clientGrants.js +17 -10
  76. package/lib/tools/auth0/handlers/clients.js +15 -8
  77. package/lib/tools/auth0/handlers/connections.js +30 -10
  78. package/lib/tools/auth0/handlers/databases.js +24 -12
  79. package/lib/tools/auth0/handlers/default.js +41 -29
  80. package/lib/tools/auth0/handlers/emailTemplates.js +8 -10
  81. package/lib/tools/auth0/handlers/guardianFactorProviders.js +3 -3
  82. package/lib/tools/auth0/handlers/guardianFactorTemplates.js +3 -3
  83. package/lib/tools/auth0/handlers/guardianFactors.js +3 -3
  84. package/lib/tools/auth0/handlers/guardianPhoneFactorMessageTypes.js +11 -10
  85. package/lib/tools/auth0/handlers/guardianPhoneFactorSelectedProvider.js +10 -9
  86. package/lib/tools/auth0/handlers/guardianPolicies.js +5 -4
  87. package/lib/tools/auth0/handlers/hooks.js +34 -21
  88. package/lib/tools/auth0/handlers/index.js +31 -27
  89. package/lib/tools/auth0/handlers/migrations.js +2 -1
  90. package/lib/tools/auth0/handlers/organizations.js +61 -31
  91. package/lib/tools/auth0/handlers/pages.js +20 -14
  92. package/lib/tools/auth0/handlers/prompts.js +1 -0
  93. package/lib/tools/auth0/handlers/resourceServers.js +22 -14
  94. package/lib/tools/auth0/handlers/roles.js +55 -31
  95. package/lib/tools/auth0/handlers/rules.js +49 -32
  96. package/lib/tools/auth0/handlers/rulesConfigs.js +12 -6
  97. package/lib/tools/auth0/handlers/tenant.js +8 -4
  98. package/lib/tools/auth0/handlers/triggers.js +11 -12
  99. package/lib/tools/auth0/index.js +15 -31
  100. package/lib/tools/auth0/schema.js +7 -27
  101. package/lib/tools/calculateChanges.js +11 -6
  102. package/lib/tools/constants.js +162 -161
  103. package/lib/tools/deploy.js +1 -1
  104. package/lib/tools/index.js +1 -1
  105. package/lib/tools/logger.js +14 -8
  106. package/lib/tools/utils.js +2 -2
  107. package/lib/tools/{ValidationError.js → validationError.js} +3 -1
  108. package/lib/types.js +2 -0
  109. package/lib/utils.js +12 -22
  110. package/package.json +8 -1
  111. package/tsconfig.json +1 -3
  112. package/typescript-migration-progress.sh +1 -1
@@ -59,15 +59,15 @@ exports.schema = {
59
59
  type: 'object',
60
60
  properties: {
61
61
  permission_name: { type: 'string' },
62
- resource_server_identifier: { type: 'string' }
63
- }
64
- }
65
- }
62
+ resource_server_identifier: { type: 'string' },
63
+ },
64
+ },
65
+ },
66
66
  },
67
- required: ['name']
68
- }
67
+ required: ['name'],
68
+ },
69
69
  };
70
- class RoleHandler extends default_1.default {
70
+ class RolesHandler extends default_1.default {
71
71
  constructor(config) {
72
72
  super(Object.assign(Object.assign({}, config), { type: 'roles', id: 'id', identifiers: ['name'] }));
73
73
  }
@@ -84,15 +84,19 @@ class RoleHandler extends default_1.default {
84
84
  }
85
85
  createRoles(creates) {
86
86
  return __awaiter(this, void 0, void 0, function* () {
87
- yield this.client.pool.addEachTask({
87
+ yield this.client.pool
88
+ .addEachTask({
88
89
  data: creates || [],
89
- generator: (item) => this.createRole(item).then((data) => {
90
+ generator: (item) => this.createRole(item)
91
+ .then((data) => {
90
92
  this.didCreate(data);
91
93
  this.created += 1;
92
- }).catch((err) => {
93
- throw new Error(`Problem creating ${this.type} ${this.objString(item)}\n${err}`);
94
94
  })
95
- }).promise();
95
+ .catch((err) => {
96
+ throw new Error(`Problem creating ${this.type} ${this.objString(item)}\n${err}`);
97
+ }),
98
+ })
99
+ .promise();
96
100
  });
97
101
  }
98
102
  deleteRole(data) {
@@ -102,16 +106,21 @@ class RoleHandler extends default_1.default {
102
106
  }
103
107
  deleteRoles(dels) {
104
108
  return __awaiter(this, void 0, void 0, function* () {
105
- if (this.config('AUTH0_ALLOW_DELETE') === 'true' || this.config('AUTH0_ALLOW_DELETE') === true) {
106
- yield this.client.pool.addEachTask({
109
+ if (this.config('AUTH0_ALLOW_DELETE') === 'true' ||
110
+ this.config('AUTH0_ALLOW_DELETE') === true) {
111
+ yield this.client.pool
112
+ .addEachTask({
107
113
  data: dels || [],
108
- generator: (item) => this.deleteRole(item).then(() => {
114
+ generator: (item) => this.deleteRole(item)
115
+ .then(() => {
109
116
  this.didDelete(item);
110
117
  this.deleted += 1;
111
- }).catch((err) => {
112
- throw new Error(`Problem deleting ${this.type} ${this.objString(item)}\n${err}`);
113
118
  })
114
- }).promise();
119
+ .catch((err) => {
120
+ throw new Error(`Problem deleting ${this.type} ${this.objString(item)}\n${err}`);
121
+ }),
122
+ })
123
+ .promise();
115
124
  }
116
125
  else {
117
126
  logger_1.default.warn(`Detected the following roles should be deleted. Doing so may be destructive.\nYou can enable deletes by setting 'AUTH0_ALLOW_DELETE' to true in the config
@@ -138,15 +147,19 @@ class RoleHandler extends default_1.default {
138
147
  }
139
148
  updateRoles(updates, roles) {
140
149
  return __awaiter(this, void 0, void 0, function* () {
141
- yield this.client.pool.addEachTask({
150
+ yield this.client.pool
151
+ .addEachTask({
142
152
  data: updates || [],
143
- generator: (item) => this.updateRole(item, roles).then((data) => {
153
+ generator: (item) => this.updateRole(item, roles)
154
+ .then((data) => {
144
155
  this.didUpdate(data);
145
156
  this.updated += 1;
146
- }).catch((err) => {
147
- throw new Error(`Problem updating ${this.type} ${this.objString(item)}\n${err}`);
148
157
  })
149
- }).promise();
158
+ .catch((err) => {
159
+ throw new Error(`Problem updating ${this.type} ${this.objString(item)}\n${err}`);
160
+ }),
161
+ })
162
+ .promise();
150
163
  });
151
164
  }
152
165
  getType() {
@@ -161,7 +174,11 @@ class RoleHandler extends default_1.default {
161
174
  try {
162
175
  const roles = yield this.client.roles.getAll({ paginate: true, include_totals: true });
163
176
  for (let index = 0; index < roles.length; index++) {
164
- const permissions = yield this.client.roles.permissions.getAll({ paginate: true, include_totals: true, id: roles[index].id });
177
+ const permissions = yield this.client.roles.permissions.getAll({
178
+ paginate: true,
179
+ include_totals: true,
180
+ id: roles[index].id,
181
+ });
165
182
  const strippedPerms = yield Promise.all(permissions.map((permission) => __awaiter(this, void 0, void 0, function* () {
166
183
  delete permission.resource_server_name;
167
184
  delete permission.description;
@@ -192,20 +209,27 @@ class RoleHandler extends default_1.default {
192
209
  handler: this,
193
210
  assets: roles,
194
211
  existing,
195
- identifiers: ['id', 'name']
212
+ identifiers: ['id', 'name'],
213
+ allowDelete: false, //TODO: actually pass in correct allowDelete value
196
214
  });
197
215
  logger_1.default.debug(`Start processChanges for roles [delete:${changes.del.length}] [update:${changes.update.length}], [create:${changes.create.length}]`);
198
- const myChanges = [{ del: changes.del }, { create: changes.create }, { update: changes.update }];
216
+ const myChanges = [
217
+ { del: changes.del },
218
+ { create: changes.create },
219
+ { update: changes.update },
220
+ ];
199
221
  yield Promise.all(myChanges.map((change) => __awaiter(this, void 0, void 0, function* () {
200
222
  switch (true) {
201
223
  case change.del && change.del.length > 0:
202
- yield this.deleteRoles(change.del);
224
+ if (change.del)
225
+ yield this.deleteRoles(change.del);
203
226
  break;
204
227
  case change.create && change.create.length > 0:
205
- yield this.createRoles(changes.create);
228
+ yield this.createRoles(changes.create); //TODO: fix this tho change.create
206
229
  break;
207
230
  case change.update && change.update.length > 0:
208
- yield this.updateRoles(change.update, existing);
231
+ if (change.update)
232
+ yield this.updateRoles(change.update, existing);
209
233
  break;
210
234
  default:
211
235
  break;
@@ -216,5 +240,5 @@ class RoleHandler extends default_1.default {
216
240
  }
217
241
  __decorate([
218
242
  (0, default_1.order)('60')
219
- ], RoleHandler.prototype, "processChanges", null);
220
- exports.default = RoleHandler;
243
+ ], RolesHandler.prototype, "processChanges", null);
244
+ exports.default = RolesHandler;
@@ -13,14 +13,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.schema = exports.excludeSchema = void 0;
16
- const ValidationError_1 = __importDefault(require("../../ValidationError"));
16
+ const validationError_1 = __importDefault(require("../../validationError"));
17
17
  const utils_1 = require("../../utils");
18
18
  const default_1 = __importDefault(require("./default"));
19
19
  const logger_1 = __importDefault(require("../../logger"));
20
20
  const calculateChanges_1 = require("../../calculateChanges");
21
21
  exports.excludeSchema = {
22
22
  type: 'array',
23
- items: { type: 'string' }
23
+ items: { type: 'string' },
24
24
  };
25
25
  exports.schema = {
26
26
  type: 'array',
@@ -30,38 +30,37 @@ exports.schema = {
30
30
  properties: {
31
31
  script: {
32
32
  type: 'string',
33
- description: 'A script that contains the rule\'s code',
34
- default: ''
33
+ description: "A script that contains the rule's code",
34
+ default: '',
35
35
  },
36
36
  name: {
37
37
  type: 'string',
38
- description: 'The name of the rule. Can only contain alphanumeric characters, spaces and \'-\'. Can neither start nor end with \'-\' or spaces',
39
- pattern: '^[^-\\s][a-zA-Z0-9-\\s]+[^-\\s]$'
38
+ description: "The name of the rule. Can only contain alphanumeric characters, spaces and '-'. Can neither start nor end with '-' or spaces",
39
+ pattern: '^[^-\\s][a-zA-Z0-9-\\s]+[^-\\s]$',
40
40
  },
41
41
  order: {
42
42
  type: ['number', 'null'],
43
- description: 'The rule\'s order in relation to other rules. A rule with a lower order than another rule executes first.',
44
- default: null
43
+ description: "The rule's order in relation to other rules. A rule with a lower order than another rule executes first.",
44
+ default: null,
45
45
  },
46
46
  enabled: {
47
47
  type: 'boolean',
48
48
  description: 'true if the rule is enabled, false otherwise',
49
- default: true
49
+ default: true,
50
50
  },
51
51
  stage: {
52
52
  type: 'string',
53
- description: 'The rule\'s execution stage',
53
+ description: "The rule's execution stage",
54
54
  default: 'login_success',
55
- enum: ['login_success', 'login_failure', 'pre_authorize']
56
- }
55
+ enum: ['login_success', 'login_failure', 'pre_authorize'],
56
+ },
57
57
  },
58
- required: ['name']
59
- }
58
+ required: ['name'],
59
+ },
60
60
  };
61
61
  class RulesHandler extends default_1.default {
62
62
  constructor(options) {
63
- super(Object.assign(Object.assign({}, options), { type: 'rules', stripUpdateFields: ['stage'] // Fields not allowed in updates
64
- }));
63
+ super(Object.assign(Object.assign({}, options), { type: 'rules', stripUpdateFields: ['stage'] }));
65
64
  }
66
65
  getType() {
67
66
  return __awaiter(this, void 0, void 0, function* () {
@@ -89,18 +88,23 @@ class RulesHandler extends default_1.default {
89
88
  handler: this,
90
89
  assets: rules,
91
90
  existing,
92
- identifiers: ['id', 'name']
91
+ identifiers: ['id', 'name'],
92
+ allowDelete: false, //TODO: actually pass in correct allowDelete value
93
93
  });
94
94
  // Figure out the rules that need to be re-ordered
95
95
  const futureRules = [...create, ...update];
96
96
  const futureMaxOrder = Math.max(...futureRules.map((r) => r.order));
97
97
  const existingMaxOrder = Math.max(...existing.map((r) => r.order));
98
98
  let nextOrderNo = Math.max(futureMaxOrder, existingMaxOrder);
99
+ //@ts-ignore because we know reOrder is Asset[]
99
100
  const reOrder = futureRules.reduce((accum, r) => {
100
101
  const conflict = existing.find((f) => r.order === f.order && r.name !== f.name);
101
- if (conflict) {
102
+ if (conflict !== undefined) {
102
103
  nextOrderNo += 1;
103
- accum.push(Object.assign(Object.assign({}, conflict), { order: nextOrderNo }));
104
+ return [
105
+ ...accum,
106
+ Object.assign(Object.assign({}, conflict), { order: nextOrderNo }),
107
+ ];
104
108
  }
105
109
  return accum;
106
110
  }, []);
@@ -109,7 +113,7 @@ class RulesHandler extends default_1.default {
109
113
  update,
110
114
  create,
111
115
  reOrder,
112
- conflicts
116
+ conflicts,
113
117
  };
114
118
  });
115
119
  }
@@ -127,23 +131,29 @@ class RulesHandler extends default_1.default {
127
131
  const { update, create, del } = yield this.calcChanges(assets, true);
128
132
  // Include del rules which are actually not going to be deleted but are excluded
129
133
  // they can still muck up the ordering so we must take it into consideration.
130
- const futureRules = [...create, ...update, ...del.filter((r) => excludedRules.includes(r.name))];
134
+ const futureRules = [
135
+ ...create,
136
+ ...update,
137
+ ...del.filter((r) => excludedRules.includes(r.name)),
138
+ ];
131
139
  // Detect rules with the same order
132
140
  const rulesSameOrder = (0, utils_1.duplicateItems)(futureRules, 'order');
133
141
  if (rulesSameOrder.length > 0) {
134
142
  const formatted = rulesSameOrder.map((dups) => dups.map((d) => `${d.name}`));
135
- throw new ValidationError_1.default(`There are multiple rules for the following stage-order combinations
143
+ throw new validationError_1.default(`There are multiple rules for the following stage-order combinations
136
144
  ${(0, utils_1.dumpJSON)(formatted)}.
137
145
  Only one rule must be defined for the same order number in a stage.`);
138
146
  }
139
147
  // Detect Rules that are changing stage as it's not allowed.
140
148
  const existing = yield this.getType();
141
- const stateChanged = futureRules.reduce((changed, rule) => ([
149
+ const stateChanged = futureRules
150
+ .reduce((changed, rule) => [
142
151
  ...changed,
143
- ...existing.filter((r) => rule.name.toLowerCase() === r.name.toLowerCase() && r.stage !== rule.stage)
144
- ]), []).map((r) => r.name);
152
+ ...existing.filter((r) => rule.name.toLowerCase() === r.name.toLowerCase() && r.stage !== rule.stage),
153
+ ], [])
154
+ .map((r) => r.name);
145
155
  if (stateChanged.length > 0) {
146
- throw new ValidationError_1.default(`The following rules changed stage which is not allowed:
156
+ throw new validationError_1.default(`The following rules changed stage which is not allowed:
147
157
  ${(0, utils_1.dumpJSON)(stateChanged)}.
148
158
  Rename the rules to recreate them and avoid this error.`);
149
159
  }
@@ -162,20 +172,27 @@ class RulesHandler extends default_1.default {
162
172
  // Figure out what needs to be updated vs created
163
173
  const changes = yield this.calcChanges(assets);
164
174
  // Temporally re-order rules with conflicting ordering
165
- yield this.client.pool.addEachTask({
175
+ yield this.client.pool
176
+ .addEachTask({
166
177
  data: changes.reOrder,
167
- generator: (rule) => this.client.updateRule({ id: rule.id }, (0, utils_1.stripFields)(rule, this.stripUpdateFields)).then(() => {
178
+ generator: (rule) => this.client
179
+ .updateRule({ id: rule.id }, (0, utils_1.stripFields)(rule, this.stripUpdateFields))
180
+ .then(() => {
168
181
  const updated = {
169
- name: rule.name, stage: rule.stage, order: rule.order, id: rule.id
182
+ name: rule.name,
183
+ stage: rule.stage,
184
+ order: rule.order,
185
+ id: rule.id,
170
186
  };
171
187
  logger_1.default.info(`Temporally re-order Rule ${(0, utils_1.dumpJSON)(updated)}`);
172
- })
173
- }).promise();
188
+ }),
189
+ })
190
+ .promise();
174
191
  yield _super.processChanges.call(this, assets, {
175
192
  del: changes.del,
176
193
  create: changes.create,
177
194
  update: changes.update,
178
- conflicts: changes.conflicts
195
+ conflicts: changes.conflicts,
179
196
  });
180
197
  });
181
198
  }
@@ -20,16 +20,16 @@ exports.schema = {
20
20
  type: 'object',
21
21
  properties: {
22
22
  key: { type: 'string', pattern: '^[A-Za-z0-9_-]*$' },
23
- value: { type: 'string' }
23
+ value: { type: 'string' },
24
24
  },
25
- required: ['key', 'value']
25
+ required: ['key', 'value'],
26
26
  },
27
- additionalProperties: false
27
+ additionalProperties: false,
28
28
  };
29
29
  class RulesConfigsHandler extends default_1.default {
30
30
  constructor(options) {
31
31
  super(Object.assign(Object.assign({}, options), { type: 'rulesConfigs', id: 'key', functions: {
32
- update: 'set' // Update or Creation of a ruleConfig is via set not update
32
+ update: 'set', // Update or Creation of a ruleConfig is via set not update
33
33
  } }));
34
34
  }
35
35
  getType() {
@@ -45,12 +45,18 @@ class RulesConfigsHandler extends default_1.default {
45
45
  const { rulesConfigs } = assets;
46
46
  // Do nothing if not set
47
47
  if (!rulesConfigs || !rulesConfigs.length)
48
- return {};
48
+ return {
49
+ del: [],
50
+ update: [],
51
+ create: [],
52
+ conflicts: [],
53
+ };
49
54
  // Intention is to not delete/cleanup old configRules, that needs to be handled manually.
50
55
  return {
51
56
  del: [],
52
57
  update: rulesConfigs,
53
- create: []
58
+ create: [],
59
+ conflicts: [],
54
60
  };
55
61
  });
56
62
  }
@@ -42,14 +42,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
42
42
  };
43
43
  Object.defineProperty(exports, "__esModule", { value: true });
44
44
  exports.schema = void 0;
45
- const ValidationError_1 = __importDefault(require("../../ValidationError"));
45
+ const validationError_1 = __importDefault(require("../../validationError"));
46
46
  const default_1 = __importStar(require("./default"));
47
47
  const pages_1 = require("./pages");
48
48
  const utils_1 = require("../../utils");
49
49
  exports.schema = {
50
- type: 'object'
50
+ type: 'object',
51
51
  };
52
- const blockPageKeys = [...Object.keys(pages_1.pageNameMap), ...Object.values(pages_1.pageNameMap), ...pages_1.supportedPages];
52
+ const blockPageKeys = [
53
+ ...Object.keys(pages_1.pageNameMap),
54
+ ...Object.values(pages_1.pageNameMap),
55
+ ...pages_1.supportedPages,
56
+ ];
53
57
  class TenantHandler extends default_1.default {
54
58
  constructor(options) {
55
59
  super(Object.assign(Object.assign({}, options), { type: 'tenant' }));
@@ -72,7 +76,7 @@ class TenantHandler extends default_1.default {
72
76
  return;
73
77
  const pageKeys = Object.keys(tenant).filter((k) => blockPageKeys.includes(k));
74
78
  if (pageKeys.length > 0) {
75
- throw new ValidationError_1.default(`The following pages ${(0, utils_1.dumpJSON)(pageKeys)} were found in tenant settings. Pages should be set separately. Please refer to the documentation.`);
79
+ throw new validationError_1.default(`The following pages ${(0, utils_1.dumpJSON)(pageKeys)} were found in tenant settings. Pages should be set separately. Please refer to the documentation.`);
76
80
  }
77
81
  });
78
82
  }
@@ -56,15 +56,15 @@ exports.schema = {
56
56
  type: 'object',
57
57
  properties: {
58
58
  action_name: { type: 'string', enum: constants_1.default.ACTIONS_TRIGGERS },
59
- display_name: { type: 'string', default: '' }
60
- }
61
- }
62
- }
63
- }
59
+ display_name: { type: 'string', default: '' },
60
+ },
61
+ },
62
+ },
63
+ },
64
64
  };
65
65
  function isActionsDisabled(err) {
66
66
  const errorBody = lodash_1.default.get(err, 'originalError.response.body') || {};
67
- return (err.statusCode === 403 && errorBody.errorCode === 'feature_not_enabled');
67
+ return err.statusCode === 403 && errorBody.errorCode === 'feature_not_enabled';
68
68
  }
69
69
  class TriggersHandler extends default_1.default {
70
70
  constructor(options) {
@@ -76,8 +76,7 @@ class TriggersHandler extends default_1.default {
76
76
  return this.existing;
77
77
  }
78
78
  // in case client version does not support actions
79
- if (!this.client.actions
80
- || typeof this.client.actions.getAllTriggers !== 'function') {
79
+ if (!this.client.actions || typeof this.client.actions.getAllTriggers !== 'function') {
81
80
  return [];
82
81
  }
83
82
  const triggerBindings = {};
@@ -87,12 +86,12 @@ class TriggersHandler extends default_1.default {
87
86
  for (let i = 0; i < triggers.length; i++) {
88
87
  const triggerId = triggers[i];
89
88
  const { bindings } = yield this.client.actions.getTriggerBindings({
90
- trigger_id: triggerId
89
+ trigger_id: triggerId,
91
90
  });
92
91
  if (bindings.length > 0) {
93
92
  triggerBindings[triggerId] = bindings.map((binding) => ({
94
93
  action_name: binding.action.name,
95
- display_name: binding.display_name
94
+ display_name: binding.display_name,
96
95
  }));
97
96
  }
98
97
  }
@@ -123,9 +122,9 @@ class TriggersHandler extends default_1.default {
123
122
  const bindings = data.map((binding) => ({
124
123
  ref: {
125
124
  type: 'action_name',
126
- value: binding.action_name
125
+ value: binding.action_name,
127
126
  },
128
- display_name: binding.display_name
127
+ display_name: binding.display_name,
129
128
  }));
130
129
  yield this.client.actions.updateTriggerBindings({ trigger_id: name }, { bindings });
131
130
  this.didUpdate({ trigger_id: name });
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -38,12 +15,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
38
15
  const ajv_1 = __importDefault(require("ajv/lib/ajv"));
39
16
  const client_1 = __importDefault(require("./client"));
40
17
  const schema_1 = __importDefault(require("./schema"));
41
- const handlers = __importStar(require("./handlers"));
42
- const defaultOrder = 50;
18
+ const handlers_1 = __importDefault(require("./handlers"));
43
19
  function sortByOrder(toSort, stage) {
20
+ const defaultOrder = 50;
44
21
  const sorted = [...toSort];
45
22
  sorted.sort((a, b) => {
23
+ //@ts-ignore because this doesn't actually work. TODO: apply stage order
46
24
  const aOrder = a[stage].order || defaultOrder;
25
+ //@ts-ignore because this doesn't actually work. TODO: apply stage order
47
26
  const bOrder = b[stage].order || defaultOrder;
48
27
  return aOrder - bOrder;
49
28
  });
@@ -54,19 +33,24 @@ class Auth0 {
54
33
  this.client = (0, client_1.default)(client);
55
34
  this.config = config;
56
35
  this.assets = assets;
57
- this.handlers = [];
58
- Object.values(handlers).forEach((h) => {
59
- const handler = new h.default({ client: this.client, config });
60
- this.handlers.push(handler);
36
+ this.handlers = Object.values(handlers_1.default)
37
+ .map((handler) => {
38
+ //@ts-ignore because class expects `type` property but gets directly injected into class constructors
39
+ return new handler.default({ client: this.client, config: this.config });
40
+ })
41
+ .filter((handler) => {
42
+ const excludedAssetTypes = config('AUTH0_EXCLUDED') || [];
43
+ return !excludedAssetTypes.includes(handler.type);
61
44
  });
62
45
  }
63
46
  runStage(stage) {
64
47
  return __awaiter(this, void 0, void 0, function* () {
65
48
  // Sort by priority
66
- for (const handler of sortByOrder(this.handlers, stage)) { // eslint-disable-line
49
+ for (const handler of sortByOrder(this.handlers, stage)) {
50
+ // eslint-disable-line
67
51
  try {
68
52
  const stageFn = Object.getPrototypeOf(handler)[stage];
69
- this.assets = Object.assign(Object.assign({}, this.assets), (yield stageFn.apply(handler, [this.assets])) || {});
53
+ this.assets = Object.assign(Object.assign({}, this.assets), ((yield stageFn.apply(handler, [this.assets])) || {}));
70
54
  }
71
55
  catch (err) {
72
56
  err.type = handler.type;
@@ -1,34 +1,14 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
4
  };
25
5
  Object.defineProperty(exports, "__esModule", { value: true });
26
- const handlers = __importStar(require("./handlers"));
27
- const typesSchema = Object.entries(handlers).reduce((map, [name, obj]) => {
6
+ const handlers_1 = __importDefault(require("./handlers"));
7
+ const typesSchema = Object.entries(handlers_1.default).reduce((map, [name, obj]) => {
28
8
  map[name] = obj.schema; //eslint-disable-line
29
9
  return map;
30
10
  }, {});
31
- const excludeSchema = Object.entries(handlers).reduce((map, [name, obj]) => {
11
+ const excludeSchema = Object.entries(handlers_1.default).reduce((map, [name, obj]) => {
32
12
  if (obj.excludeSchema) {
33
13
  map[name] = obj.excludeSchema;
34
14
  }
@@ -40,7 +20,7 @@ exports.default = {
40
20
  properties: Object.assign(Object.assign({}, typesSchema), { exclude: {
41
21
  type: 'object',
42
22
  properties: Object.assign({}, excludeSchema),
43
- default: {}
23
+ default: {},
44
24
  } }),
45
- additionalProperties: false
25
+ additionalProperties: false,
46
26
  };
@@ -14,11 +14,12 @@ const logger_1 = __importDefault(require("./logger"));
14
14
  * @param {boolean} [allowDelete=false]
15
15
  * @returns T
16
16
  */
17
- function processChangedObjectFields({ handler, desiredAssetState, currentAssetState, allowDelete = false }) {
17
+ function processChangedObjectFields({ handler, desiredAssetState, currentAssetState, allowDelete = false, }) {
18
18
  const desiredAssetStateWithChanges = Object.assign({}, desiredAssetState);
19
19
  // eslint-disable-next-line no-restricted-syntax
20
20
  for (const fieldName of handler.objectFields) {
21
- const areDesiredStateAndCurrentStateEmpty = Object.keys(desiredAssetState[fieldName] || {}).length === 0 && Object.keys(currentAssetState[fieldName] || {}).length === 0;
21
+ const areDesiredStateAndCurrentStateEmpty = Object.keys(desiredAssetState[fieldName] || {}).length === 0 &&
22
+ Object.keys(currentAssetState[fieldName] || {}).length === 0;
22
23
  if (areDesiredStateAndCurrentStateEmpty) {
23
24
  // If both the desired state and current state for a given object is empty, it is a no-op and can skip
24
25
  // eslint-disable-next-line no-continue
@@ -63,7 +64,7 @@ function processChangedObjectFields({ handler, desiredAssetState, currentAssetSt
63
64
  return desiredAssetStateWithChanges;
64
65
  }
65
66
  exports.processChangedObjectFields = processChangedObjectFields;
66
- function calculateChanges({ handler, assets, existing, identifiers = ['id', 'name'], allowDelete }) {
67
+ function calculateChanges({ handler, assets, existing, identifiers = ['id', 'name'], allowDelete, }) {
67
68
  // Calculate the changes required between two sets of assets.
68
69
  const update = [];
69
70
  let del = [...existing];
@@ -103,7 +104,10 @@ function calculateChanges({ handler, assets, existing, identifiers = ['id', 'nam
103
104
  return obj;
104
105
  }, {})), (handler.objectFields.length
105
106
  ? processChangedObjectFields({
106
- handler, desiredAssetState: asset, currentAssetState: found, allowDelete
107
+ handler,
108
+ desiredAssetState: asset,
109
+ currentAssetState: found,
110
+ allowDelete,
107
111
  })
108
112
  : asset)));
109
113
  }
@@ -113,7 +117,8 @@ function calculateChanges({ handler, assets, existing, identifiers = ['id', 'nam
113
117
  // Loop through identifiers (in order) to try match assets to existing
114
118
  // If existing then update if not create
115
119
  // The remainder will be deleted
116
- for (const id of identifiers) { // eslint-disable-line
120
+ for (const id of identifiers) {
121
+ // eslint-disable-line
117
122
  processAssets(id, [...create]);
118
123
  }
119
124
  // Check if there are assets with names that will conflict with existing names during the update process
@@ -138,7 +143,7 @@ function calculateChanges({ handler, assets, existing, identifiers = ['id', 'nam
138
143
  del,
139
144
  update,
140
145
  conflicts,
141
- create
146
+ create,
142
147
  };
143
148
  }
144
149
  exports.calculateChanges = calculateChanges;