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
@@ -25,11 +25,11 @@ exports.schema = {
25
25
  type: 'object',
26
26
  properties: {
27
27
  template: { type: 'string' },
28
- body: { type: 'string' }
29
- }
30
- }
31
- }
32
- }
28
+ body: { type: 'string' },
29
+ },
30
+ },
31
+ },
32
+ },
33
33
  };
34
34
  class BrandingHandler extends default_1.default {
35
35
  constructor(options) {
@@ -52,8 +52,8 @@ class BrandingHandler extends default_1.default {
52
52
  branding.templates = [
53
53
  {
54
54
  template: constants_1.default.UNIVERSAL_LOGIN_TEMPLATE,
55
- body: payload.body
56
- }
55
+ body: payload.body,
56
+ },
57
57
  ];
58
58
  }
59
59
  }
@@ -88,10 +88,14 @@ class BrandingHandler extends default_1.default {
88
88
  }
89
89
  // handle templates
90
90
  if (branding.templates && branding.templates.length) {
91
- const unknownTemplates = branding.templates.filter((t) => !constants_1.default.SUPPORTED_BRANDING_TEMPLATES.includes(t.template)).map((t) => t.template);
91
+ const unknownTemplates = branding.templates
92
+ .filter((t) => !constants_1.default.SUPPORTED_BRANDING_TEMPLATES.includes(t.template))
93
+ .map((t) => t.template);
92
94
  if (unknownTemplates.length) {
93
95
  // throw a helpful warning for unknown templates, the context handlers are unaware of which are supported, that's all handled here.
94
- logger_1.default.warn(`Found unknown branding template(s): ${unknownTemplates.join().toString()}. Supported branding templates are: ${constants_1.default.SUPPORTED_BRANDING_TEMPLATES.join()}.`);
96
+ logger_1.default.warn(`Found unknown branding template(s): ${unknownTemplates
97
+ .join()
98
+ .toString()}. Supported branding templates are: ${constants_1.default.SUPPORTED_BRANDING_TEMPLATES.join()}.`);
95
99
  }
96
100
  const templateDefinition = branding.templates.find((t) => t.template === constants_1.default.UNIVERSAL_LOGIN_TEMPLATE);
97
101
  if (templateDefinition && templateDefinition.body) {
@@ -51,15 +51,17 @@ exports.schema = {
51
51
  scope: {
52
52
  type: 'array',
53
53
  items: { type: 'string' },
54
- uniqueItems: true
55
- }
54
+ uniqueItems: true,
55
+ },
56
56
  },
57
- required: ['client_id', 'scope', 'audience']
58
- }
57
+ required: ['client_id', 'scope', 'audience'],
58
+ },
59
59
  };
60
- class ClientHandler extends default_1.default {
60
+ class ClientGrantsHandler extends default_1.default {
61
61
  constructor(config) {
62
- super(Object.assign(Object.assign({}, config), { type: 'clientGrants', id: 'id', identifiers: ['id', ['client_id', 'audience']], stripUpdateFields: ['audience', 'client_id'] }));
62
+ super(Object.assign(Object.assign({}, config), { type: 'clientGrants', id: 'id',
63
+ //@ts-ignore because not sure why two-dimensional array passed in
64
+ identifiers: ['id', ['client_id', 'audience']], stripUpdateFields: ['audience', 'client_id'] }));
63
65
  }
64
66
  objString(item) {
65
67
  return super.objString({ id: item.id, client_id: item.client_id, audience: item.audience });
@@ -103,15 +105,20 @@ class ClientHandler extends default_1.default {
103
105
  const { del, update, create, conflicts } = yield this.calcChanges(Object.assign(Object.assign({}, assets), { clientGrants: formatted }));
104
106
  const filterGrants = (list) => {
105
107
  if (excludedClients.length) {
106
- return list.filter((item) => item.client_id !== currentClient && ![...excludedClientsByNames, ...excludedClients].includes(item.client_id));
108
+ return list.filter((item) => item.client_id !== currentClient &&
109
+ ![...excludedClientsByNames, ...excludedClients].includes(item.client_id));
107
110
  }
108
111
  return list.filter((item) => item.client_id !== currentClient);
109
112
  };
110
113
  const changes = {
114
+ //@ts-ignore because this expects `client_id` and that's not yet typed on Asset
111
115
  del: filterGrants(del),
116
+ //@ts-ignore because this expects `client_id` and that's not yet typed on Asset
112
117
  update: filterGrants(update),
118
+ //@ts-ignore because this expects `client_id` and that's not yet typed on Asset
113
119
  create: filterGrants(create),
114
- conflicts: filterGrants(conflicts)
120
+ //@ts-ignore because this expects `client_id` and that's not yet typed on Asset
121
+ conflicts: filterGrants(conflicts),
115
122
  };
116
123
  yield _super.processChanges.call(this, assets, Object.assign({}, changes));
117
124
  });
@@ -119,5 +126,5 @@ class ClientHandler extends default_1.default {
119
126
  }
120
127
  __decorate([
121
128
  (0, default_1.order)('60')
122
- ], ClientHandler.prototype, "processChanges", null);
123
- exports.default = ClientHandler;
129
+ ], ClientGrantsHandler.prototype, "processChanges", null);
130
+ exports.default = ClientGrantsHandler;
@@ -19,16 +19,20 @@ exports.schema = {
19
19
  items: {
20
20
  type: 'object',
21
21
  properties: {
22
- name: { type: 'string', minLength: 1, pattern: '[^<>]+' }
22
+ name: { type: 'string', minLength: 1, pattern: '[^<>]+' },
23
23
  },
24
- required: ['name']
25
- }
24
+ required: ['name'],
25
+ },
26
26
  };
27
27
  class ClientHandler extends default_1.default {
28
28
  constructor(config) {
29
29
  super(Object.assign(Object.assign({}, config), { type: 'clients', id: 'client_id', identifiers: ['client_id', 'name'], objectFields: ['client_metadata'], stripUpdateFields: [
30
30
  // Fields not allowed during updates
31
- 'callback_url_template', 'signing_keys', 'global', 'tenant', 'jwt_configuration.secret_encoded'
31
+ 'callback_url_template',
32
+ 'signing_keys',
33
+ 'global',
34
+ 'tenant',
35
+ 'jwt_configuration.secret_encoded',
32
36
  ] }));
33
37
  }
34
38
  objString(item) {
@@ -58,17 +62,20 @@ class ClientHandler extends default_1.default {
58
62
  del: filterClients(del),
59
63
  update: filterClients(update),
60
64
  create: filterClients(create),
61
- conflicts: filterClients(conflicts)
65
+ conflicts: filterClients(conflicts),
62
66
  };
63
67
  yield _super.processChanges.call(this, assets, Object.assign({}, changes));
64
68
  });
65
69
  }
66
70
  getType() {
67
71
  return __awaiter(this, void 0, void 0, function* () {
68
- if (this.existing) {
72
+ if (this.existing)
69
73
  return this.existing;
70
- }
71
- this.existing = yield this.client.clients.getAll({ paginate: true, include_totals: true, is_global: false });
74
+ this.existing = yield this.client.clients.getAll({
75
+ paginate: true,
76
+ include_totals: true,
77
+ is_global: false,
78
+ });
72
79
  return this.existing;
73
80
  });
74
81
  }
@@ -56,19 +56,20 @@ exports.schema = {
56
56
  options: { type: 'object' },
57
57
  enabled_clients: { type: 'array', items: { type: 'string' } },
58
58
  realms: { type: 'array', items: { type: 'string' } },
59
- metadata: { type: 'object' }
59
+ metadata: { type: 'object' },
60
60
  },
61
- required: ['name', 'strategy']
62
- }
61
+ required: ['name', 'strategy'],
62
+ },
63
63
  };
64
64
  // addExcludedConnectionPropertiesToChanges superimposes excluded properties on the `options` object. The Auth0 API
65
65
  // will overwrite the options property when updating connections, so it is necessary to add excluded properties back in to prevent those excluded properties from being deleted.
66
66
  // This use case is common because organizations may not want to expose sensitive connection details, but want to preserve them in the tenant.
67
67
  // exported only for unit testing purposes
68
- const addExcludedConnectionPropertiesToChanges = ({ proposedChanges, existingConnections, config }) => {
68
+ const addExcludedConnectionPropertiesToChanges = ({ proposedChanges, existingConnections, config, }) => {
69
69
  var _a, _b;
70
70
  if (proposedChanges.update.length === 0)
71
71
  return proposedChanges;
72
+ //@ts-ignore because this expects a parameter to be passed
72
73
  const excludedFields = ((_b = (_a = config()) === null || _a === void 0 ? void 0 : _a.EXCLUDED_PROPS) === null || _b === void 0 ? void 0 : _b.connections) || [];
73
74
  if (excludedFields.length === 0)
74
75
  return proposedChanges;
@@ -84,7 +85,9 @@ const addExcludedConnectionPropertiesToChanges = ({ proposedChanges, existingCon
84
85
  const currentExcludedFieldValue = dot_prop_1.default.get(currConnection, excludedField);
85
86
  dot_prop_1.default.set(agg, excludedField, currentExcludedFieldValue);
86
87
  return agg;
87
- }, {});
88
+ }, {
89
+ options: {},
90
+ });
88
91
  return Object.assign(Object.assign({}, proposedConnection), { options: Object.assign(Object.assign({}, proposedConnection.options), currentExcludedPropertyValues.options) });
89
92
  });
90
93
  return Object.assign(Object.assign({}, proposedChanges), { update: newProposedUpdates });
@@ -100,7 +103,7 @@ class ConnectionsHandler extends default_1.default {
100
103
  getFormattedOptions(connection, clients) {
101
104
  try {
102
105
  return {
103
- options: Object.assign(Object.assign({}, connection.options), { idpinitiated: Object.assign(Object.assign({}, connection.options.idpinitiated), { client_id: (0, utils_1.convertClientNameToId)(connection.options.idpinitiated.client_id, clients) }) })
106
+ options: Object.assign(Object.assign({}, connection.options), { idpinitiated: Object.assign(Object.assign({}, connection.options.idpinitiated), { client_id: (0, utils_1.convertClientNameToId)(connection.options.idpinitiated.client_id, clients) }) }),
104
107
  };
105
108
  }
106
109
  catch (e) {
@@ -111,9 +114,14 @@ class ConnectionsHandler extends default_1.default {
111
114
  return __awaiter(this, void 0, void 0, function* () {
112
115
  if (this.existing)
113
116
  return this.existing;
114
- const connections = yield this.client.connections.getAll({ paginate: true, include_totals: true });
117
+ const connections = yield this.client.connections.getAll({
118
+ paginate: true,
119
+ include_totals: true,
120
+ });
115
121
  // Filter out database connections
116
122
  this.existing = connections.filter((c) => c.strategy !== 'auth0');
123
+ if (this.existing === null)
124
+ return [];
117
125
  return this.existing;
118
126
  });
119
127
  }
@@ -125,13 +133,25 @@ class ConnectionsHandler extends default_1.default {
125
133
  const { connections } = assets;
126
134
  // Do nothing if not set
127
135
  if (!connections)
128
- return {};
136
+ return {
137
+ del: [],
138
+ create: [],
139
+ update: [],
140
+ conflicts: [],
141
+ };
129
142
  // Convert enabled_clients by name to the id
130
143
  const clients = yield this.client.clients.getAll({ paginate: true, include_totals: true });
131
- const existingConnections = yield this.client.connections.getAll({ paginate: true, include_totals: true });
144
+ const existingConnections = yield this.client.connections.getAll({
145
+ paginate: true,
146
+ include_totals: true,
147
+ });
132
148
  const formatted = assets.connections.map((connection) => (Object.assign(Object.assign(Object.assign({}, connection), this.getFormattedOptions(connection, clients)), { enabled_clients: (0, utils_1.getEnabledClients)(assets, connection, existingConnections, clients) })));
133
149
  const proposedChanges = yield _super.calcChanges.call(this, Object.assign(Object.assign({}, assets), { connections: formatted }));
134
- const proposedChangesWithExcludedProperties = (0, exports.addExcludedConnectionPropertiesToChanges)({ proposedChanges, existingConnections, config: this.config });
150
+ const proposedChangesWithExcludedProperties = (0, exports.addExcludedConnectionPropertiesToChanges)({
151
+ proposedChanges,
152
+ existingConnections,
153
+ config: this.config,
154
+ });
135
155
  return proposedChangesWithExcludedProperties;
136
156
  });
137
157
  }
@@ -57,13 +57,13 @@ exports.schema = {
57
57
  properties: {
58
58
  customScripts: {
59
59
  type: 'object',
60
- properties: Object.assign({}, constants_1.default.DATABASE_SCRIPTS.reduce((o, script) => (Object.assign(Object.assign({}, o), { [script]: { type: 'string' } })), {}))
61
- }
62
- }
63
- }
60
+ properties: Object.assign({}, constants_1.default.DATABASE_SCRIPTS.reduce((o, script) => (Object.assign(Object.assign({}, o), { [script]: { type: 'string' } })), {})),
61
+ },
62
+ },
63
+ },
64
64
  },
65
- required: ['name']
66
- }
65
+ required: ['name'],
66
+ },
67
67
  };
68
68
  class DatabaseHandler extends default_1.default {
69
69
  constructor(config) {
@@ -75,9 +75,8 @@ class DatabaseHandler extends default_1.default {
75
75
  getClientFN(fn) {
76
76
  // Override this as a database is actually a connection but we are treating them as a different object
77
77
  // If we going to update database, we need to get current options first
78
- if (fn === this.functions.update) {
79
- return (params, payload) => this.client.connections.get(params)
80
- .then((connection) => {
78
+ if (fn === 'update') {
79
+ return (params, payload) => this.client.connections.get(params).then((connection) => {
81
80
  payload.options = Object.assign(Object.assign({}, connection.options), payload.options);
82
81
  return this.client.connections.update(params, payload);
83
82
  });
@@ -88,7 +87,11 @@ class DatabaseHandler extends default_1.default {
88
87
  return __awaiter(this, void 0, void 0, function* () {
89
88
  if (this.existing)
90
89
  return this.existing;
91
- this.existing = this.client.connections.getAll({ strategy: 'auth0', paginate: true, include_totals: true });
90
+ this.existing = this.client.connections.getAll({
91
+ strategy: 'auth0',
92
+ paginate: true,
93
+ include_totals: true,
94
+ });
92
95
  return this.existing;
93
96
  });
94
97
  }
@@ -100,10 +103,19 @@ class DatabaseHandler extends default_1.default {
100
103
  const { databases } = assets;
101
104
  // Do nothing if not set
102
105
  if (!databases)
103
- return {};
106
+ return {
107
+ del: [],
108
+ create: [],
109
+ update: [],
110
+ conflicts: [],
111
+ };
104
112
  // Convert enabled_clients by name to the id
105
113
  const clients = yield this.client.clients.getAll({ paginate: true, include_totals: true });
106
- const existingDatabasesConecctions = yield this.client.connections.getAll({ strategy: 'auth0', paginate: true, include_totals: true });
114
+ const existingDatabasesConecctions = yield this.client.connections.getAll({
115
+ strategy: 'auth0',
116
+ paginate: true,
117
+ include_totals: true,
118
+ });
107
119
  const formatted = databases.map((db) => {
108
120
  if (db.enabled_clients) {
109
121
  return Object.assign(Object.assign({}, db), { enabled_clients: (0, utils_1.getEnabledClients)(assets, db, existingDatabasesConecctions, clients) });
@@ -13,7 +13,7 @@ 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 ValidationError_1 = __importDefault(require("../../ValidationError"));
16
+ const validationError_1 = __importDefault(require("../../validationError"));
17
17
  const logger_1 = __importDefault(require("../../logger"));
18
18
  const utils_1 = require("../../utils");
19
19
  const calculateChanges_1 = require("../../calculateChanges");
@@ -24,7 +24,7 @@ function order(value) {
24
24
  };
25
25
  }
26
26
  exports.order = order;
27
- class DefaultHandler {
27
+ class APIHandler {
28
28
  constructor(options) {
29
29
  this.config = options.config;
30
30
  this.type = options.type;
@@ -33,11 +33,8 @@ class DefaultHandler {
33
33
  this.existing = null;
34
34
  this.identifiers = options.identifiers || ['id', 'name'];
35
35
  this.objectFields = options.objectFields || [];
36
- this.stripUpdateFields = [
37
- ...options.stripUpdateFields || [],
38
- this.id
39
- ];
40
- 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 || {}));
41
38
  this.updated = 0;
42
39
  this.created = 0;
43
40
  this.deleted = 0;
@@ -80,14 +77,20 @@ class DefaultHandler {
80
77
  const typeAssets = assets[this.type];
81
78
  // Do nothing if not set
82
79
  if (!typeAssets)
83
- return {};
80
+ return {
81
+ del: [],
82
+ create: [],
83
+ conflicts: [],
84
+ update: [],
85
+ };
84
86
  const existing = yield this.getType();
85
87
  // Figure out what needs to be updated vs created
86
88
  return (0, calculateChanges_1.calculateChanges)({
87
89
  handler: this,
88
90
  assets: typeAssets,
91
+ //@ts-ignore TODO: investigate what happens when `existing` is null
89
92
  existing,
90
- identifiers: this.identifiers
93
+ identifiers: this.identifiers,
91
94
  });
92
95
  });
93
96
  }
@@ -102,7 +105,7 @@ class DefaultHandler {
102
105
  const duplicateNames = (0, utils_1.duplicateItems)(typeAssets, 'name');
103
106
  if (duplicateNames.length > 0) {
104
107
  const formatted = duplicateNames.map((dups) => dups.map((d) => `${d.name}`));
105
- throw new ValidationError_1.default(`There are multiple ${this.type} with the same name combinations
108
+ throw new validationError_1.default(`There are multiple ${this.type} with the same name combinations
106
109
  ${(0, utils_1.dumpJSON)(formatted)}.
107
110
  Names must be unique.`);
108
111
  }
@@ -110,7 +113,7 @@ class DefaultHandler {
110
113
  const duplicateIDs = (0, utils_1.duplicateItems)(typeAssets, this.id);
111
114
  if (duplicateIDs.length > 0) {
112
115
  const formatted = duplicateIDs.map((dups) => dups.map((d) => `${d[this.id]}`));
113
- throw new ValidationError_1.default(`There are multiple ${this.type} for the following stage-order combinations
116
+ throw new validationError_1.default(`There are multiple ${this.type} for the following stage-order combinations
114
117
  ${(0, utils_1.dumpJSON)(formatted)}.
115
118
  Only one rule must be defined for the same order number in a stage.`);
116
119
  }
@@ -129,7 +132,8 @@ class DefaultHandler {
129
132
  // Process Deleted
130
133
  if (del.length > 0) {
131
134
  const allowDelete = this.config('AUTH0_ALLOW_DELETE') === 'true' || this.config('AUTH0_ALLOW_DELETE') === true;
132
- const byExtension = this.config('EXTENSION_SECRET') && (this.type === 'rules' || this.type === 'resourceServers');
135
+ const byExtension = this.config('EXTENSION_SECRET') &&
136
+ (this.type === 'rules' || this.type === 'resourceServers');
133
137
  const shouldDelete = allowDelete || byExtension;
134
138
  if (!shouldDelete) {
135
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
@@ -137,10 +141,11 @@ class DefaultHandler {
137
141
  `);
138
142
  }
139
143
  else {
140
- yield this.client.pool.addEachTask({
144
+ yield this.client.pool
145
+ .addEachTask({
141
146
  data: del || [],
142
147
  generator: (delItem) => {
143
- const delFunction = this.getClientFN(this.functions.delete);
148
+ const delFunction = this.getClientFN('delete');
144
149
  return delFunction({ [this.id]: delItem[this.id] })
145
150
  .then(() => {
146
151
  this.didDelete(delItem);
@@ -149,15 +154,17 @@ class DefaultHandler {
149
154
  .catch((err) => {
150
155
  throw new Error(`Problem deleting ${this.type} ${this.objString(delItem)}\n${err}`);
151
156
  });
152
- }
153
- }).promise();
157
+ },
158
+ })
159
+ .promise();
154
160
  }
155
161
  }
156
162
  // Process Renaming Entries Temp due to conflicts in names
157
- yield this.client.pool.addEachTask({
163
+ yield this.client.pool
164
+ .addEachTask({
158
165
  data: conflicts || [],
159
166
  generator: (updateItem) => {
160
- const updateFN = this.getClientFN(this.functions.update);
167
+ const updateFN = this.getClientFN('update');
161
168
  const params = { [this.id]: updateItem[this.id] };
162
169
  const payload = (0, utils_1.stripFields)(Object.assign({}, updateItem), this.stripUpdateFields);
163
170
  return updateFN(params, payload)
@@ -165,13 +172,15 @@ class DefaultHandler {
165
172
  .catch((err) => {
166
173
  throw new Error(`Problem updating ${this.type} ${this.objString(updateItem)}\n${err}`);
167
174
  });
168
- }
169
- }).promise();
175
+ },
176
+ })
177
+ .promise();
170
178
  // Process Creations
171
- yield this.client.pool.addEachTask({
179
+ yield this.client.pool
180
+ .addEachTask({
172
181
  data: create || [],
173
182
  generator: (createItem) => {
174
- const createFunction = this.getClientFN(this.functions.create);
183
+ const createFunction = this.getClientFN('create');
175
184
  return createFunction(createItem)
176
185
  .then((data) => {
177
186
  this.didCreate(data);
@@ -180,13 +189,15 @@ class DefaultHandler {
180
189
  .catch((err) => {
181
190
  throw new Error(`Problem creating ${this.type} ${this.objString(createItem)}\n${err}`);
182
191
  });
183
- }
184
- }).promise();
192
+ },
193
+ })
194
+ .promise();
185
195
  // Process Updates and strip fields not allowed in updates
186
- yield this.client.pool.addEachTask({
196
+ yield this.client.pool
197
+ .addEachTask({
187
198
  data: update || [],
188
199
  generator: (updateItem) => {
189
- const updateFN = this.getClientFN(this.functions.update);
200
+ const updateFN = this.getClientFN('update');
190
201
  const params = { [this.id]: updateItem[this.id] };
191
202
  const payload = (0, utils_1.stripFields)(Object.assign({}, updateItem), this.stripUpdateFields);
192
203
  return updateFN(params, payload)
@@ -197,9 +208,10 @@ class DefaultHandler {
197
208
  .catch((err) => {
198
209
  throw new Error(`Problem updating ${this.type} ${this.objString(updateItem)}\n${err}`);
199
210
  });
200
- }
201
- }).promise();
211
+ },
212
+ })
213
+ .promise();
202
214
  });
203
215
  }
204
216
  }
205
- exports.default = DefaultHandler;
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
- emailTemplates.push(template);
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
- return emailTemplates;
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
- && err.originalError
38
- && err.originalError.response
39
- && err.originalError.response.body
40
- && err.originalError.response.body.errorCode === 'voice_mfa_not_allowed') {
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 || typeof this.client.guardian.getPhoneFactorMessageTypes !== 'function') {
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
- && err.originalError
35
- && err.originalError.response
36
- && err.originalError.response.body
37
- && err.originalError.response.body.errorCode === 'hooks_not_allowed') {
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 || typeof this.client.guardian.getPhoneFactorSelectedProvider !== 'function') {
50
+ if (!this.client.guardian ||
51
+ typeof this.client.guardian.getPhoneFactorSelectedProvider !== 'function') {
51
52
  return {};
52
53
  }
53
54
  if (this.existing)