auth0-deploy-cli 7.6.0 → 7.8.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 (216) 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 +222 -7
  7. package/CONTRIBUTING.md +2 -2
  8. package/README.md +3 -0
  9. package/lib/args.d.ts +29 -0
  10. package/lib/args.js +16 -15
  11. package/lib/commands/export.d.ts +2 -0
  12. package/lib/commands/export.js +3 -3
  13. package/lib/commands/import.d.ts +2 -0
  14. package/lib/commands/import.js +6 -6
  15. package/lib/commands/index.d.ts +9 -0
  16. package/lib/commands/index.js +1 -1
  17. package/lib/configFactory.d.ts +7 -0
  18. package/lib/configFactory.js +5 -1
  19. package/lib/context/defaults.d.ts +1 -0
  20. package/lib/context/defaults.js +4 -3
  21. package/lib/context/directory/handlers/actions.d.ts +6 -0
  22. package/lib/context/directory/handlers/actions.js +3 -3
  23. package/lib/context/directory/handlers/attackProtection.d.ts +10 -0
  24. package/lib/context/directory/handlers/attackProtection.js +7 -7
  25. package/lib/context/directory/handlers/branding.d.ts +6 -0
  26. package/lib/context/directory/handlers/branding.js +6 -5
  27. package/lib/context/directory/handlers/clientGrants.d.ts +6 -0
  28. package/lib/context/directory/handlers/clientGrants.js +3 -2
  29. package/lib/context/directory/handlers/clients.d.ts +6 -0
  30. package/lib/context/directory/handlers/clients.js +1 -1
  31. package/lib/context/directory/handlers/connections.d.ts +6 -0
  32. package/lib/context/directory/handlers/connections.js +4 -2
  33. package/lib/context/directory/handlers/databases.d.ts +6 -0
  34. package/lib/context/directory/handlers/databases.js +13 -7
  35. package/lib/context/directory/handlers/emailProvider.d.ts +6 -0
  36. package/lib/context/directory/handlers/emailProvider.js +3 -2
  37. package/lib/context/directory/handlers/emailTemplates.d.ts +6 -0
  38. package/lib/context/directory/handlers/emailTemplates.js +2 -2
  39. package/lib/context/directory/handlers/guardianFactorProviders.d.ts +6 -0
  40. package/lib/context/directory/handlers/guardianFactorProviders.js +3 -2
  41. package/lib/context/directory/handlers/guardianFactorTemplates.d.ts +6 -0
  42. package/lib/context/directory/handlers/guardianFactorTemplates.js +3 -2
  43. package/lib/context/directory/handlers/guardianFactors.d.ts +6 -0
  44. package/lib/context/directory/handlers/guardianFactors.js +3 -2
  45. package/lib/context/directory/handlers/guardianPhoneFactorMessageTypes.d.ts +6 -0
  46. package/lib/context/directory/handlers/guardianPhoneFactorMessageTypes.js +1 -1
  47. package/lib/context/directory/handlers/guardianPhoneFactorSelectedProvider.d.ts +6 -0
  48. package/lib/context/directory/handlers/guardianPhoneFactorSelectedProvider.js +1 -1
  49. package/lib/context/directory/handlers/guardianPolicies.d.ts +6 -0
  50. package/lib/context/directory/handlers/guardianPolicies.js +1 -1
  51. package/lib/context/directory/handlers/hooks.d.ts +6 -0
  52. package/lib/context/directory/handlers/hooks.js +2 -2
  53. package/lib/context/directory/handlers/index.d.ts +12 -0
  54. package/lib/context/directory/handlers/index.js +3 -2
  55. package/lib/context/directory/handlers/migrations.d.ts +6 -0
  56. package/lib/context/directory/handlers/organizations.d.ts +6 -0
  57. package/lib/context/directory/handlers/organizations.js +1 -1
  58. package/lib/context/directory/handlers/pages.d.ts +6 -0
  59. package/lib/context/directory/handlers/pages.js +2 -2
  60. package/lib/context/directory/handlers/resourceServers.d.ts +6 -0
  61. package/lib/context/directory/handlers/resourceServers.js +3 -2
  62. package/lib/context/directory/handlers/roles.d.ts +6 -0
  63. package/lib/context/directory/handlers/roles.js +1 -1
  64. package/lib/context/directory/handlers/rules.d.ts +6 -0
  65. package/lib/context/directory/handlers/rules.js +2 -2
  66. package/lib/context/directory/handlers/rulesConfigs.d.ts +6 -0
  67. package/lib/context/directory/handlers/rulesConfigs.js +3 -2
  68. package/lib/context/directory/handlers/tenant.d.ts +10 -0
  69. package/lib/context/directory/handlers/tenant.js +3 -2
  70. package/lib/context/directory/handlers/triggers.d.ts +6 -0
  71. package/lib/context/directory/index.d.ts +17 -0
  72. package/lib/context/directory/index.js +21 -18
  73. package/lib/context/index.d.ts +4 -0
  74. package/lib/context/index.js +83 -61
  75. package/lib/context/yaml/handlers/actions.d.ts +6 -0
  76. package/lib/context/yaml/handlers/actions.js +9 -6
  77. package/lib/context/yaml/handlers/attackProtection.d.ts +6 -0
  78. package/lib/context/yaml/handlers/attackProtection.js +1 -1
  79. package/lib/context/yaml/handlers/branding.d.ts +6 -0
  80. package/lib/context/yaml/handlers/branding.js +5 -4
  81. package/lib/context/yaml/handlers/clientGrants.d.ts +6 -0
  82. package/lib/context/yaml/handlers/clientGrants.js +2 -2
  83. package/lib/context/yaml/handlers/clients.d.ts +6 -0
  84. package/lib/context/yaml/handlers/clients.js +6 -4
  85. package/lib/context/yaml/handlers/connections.d.ts +6 -0
  86. package/lib/context/yaml/handlers/connections.js +7 -5
  87. package/lib/context/yaml/handlers/databases.d.ts +6 -0
  88. package/lib/context/yaml/handlers/databases.js +12 -8
  89. package/lib/context/yaml/handlers/emailProvider.d.ts +6 -0
  90. package/lib/context/yaml/handlers/emailProvider.js +4 -3
  91. package/lib/context/yaml/handlers/emailTemplates.d.ts +6 -0
  92. package/lib/context/yaml/handlers/emailTemplates.js +3 -3
  93. package/lib/context/yaml/handlers/guardianFactorProviders.d.ts +6 -0
  94. package/lib/context/yaml/handlers/guardianFactorProviders.js +1 -1
  95. package/lib/context/yaml/handlers/guardianFactorTemplates.d.ts +6 -0
  96. package/lib/context/yaml/handlers/guardianFactorTemplates.js +1 -1
  97. package/lib/context/yaml/handlers/guardianFactors.d.ts +6 -0
  98. package/lib/context/yaml/handlers/guardianFactors.js +1 -1
  99. package/lib/context/yaml/handlers/guardianPhoneFactorMessageTypes.d.ts +6 -0
  100. package/lib/context/yaml/handlers/guardianPhoneFactorMessageTypes.js +1 -1
  101. package/lib/context/yaml/handlers/guardianPhoneFactorSelectedProvider.d.ts +6 -0
  102. package/lib/context/yaml/handlers/guardianPhoneFactorSelectedProvider.js +1 -1
  103. package/lib/context/yaml/handlers/guardianPolicies.d.ts +6 -0
  104. package/lib/context/yaml/handlers/guardianPolicies.js +1 -1
  105. package/lib/context/yaml/handlers/hooks.d.ts +6 -0
  106. package/lib/context/yaml/handlers/hooks.js +4 -3
  107. package/lib/context/yaml/handlers/index.d.ts +12 -0
  108. package/lib/context/yaml/handlers/index.js +3 -2
  109. package/lib/context/yaml/handlers/migrations.d.ts +6 -0
  110. package/lib/context/yaml/handlers/organizations.d.ts +6 -0
  111. package/lib/context/yaml/handlers/organizations.js +3 -3
  112. package/lib/context/yaml/handlers/pages.d.ts +6 -0
  113. package/lib/context/yaml/handlers/pages.js +3 -3
  114. package/lib/context/yaml/handlers/resourceServers.d.ts +6 -0
  115. package/lib/context/yaml/handlers/resourceServers.js +2 -2
  116. package/lib/context/yaml/handlers/roles.d.ts +6 -0
  117. package/lib/context/yaml/handlers/roles.js +3 -3
  118. package/lib/context/yaml/handlers/rules.d.ts +6 -0
  119. package/lib/context/yaml/handlers/rules.js +3 -3
  120. package/lib/context/yaml/handlers/rulesConfigs.d.ts +6 -0
  121. package/lib/context/yaml/handlers/rulesConfigs.js +2 -2
  122. package/lib/context/yaml/handlers/tenant.d.ts +6 -0
  123. package/lib/context/yaml/handlers/tenant.js +4 -3
  124. package/lib/context/yaml/handlers/triggers.d.ts +6 -0
  125. package/lib/context/yaml/handlers/triggers.js +2 -2
  126. package/lib/context/yaml/index.d.ts +13 -0
  127. package/lib/context/yaml/index.js +31 -23
  128. package/lib/index.d.ts +88 -0
  129. package/lib/index.js +25 -17
  130. package/lib/logger.d.ts +2 -0
  131. package/lib/logger.js +8 -17
  132. package/lib/readonly.d.ts +2 -0
  133. package/lib/readonly.js +11 -16
  134. package/lib/sessionDurationsToMinutes.d.ts +7 -0
  135. package/lib/sessionDurationsToMinutes.js +15 -0
  136. package/lib/tools/auth0/client.d.ts +2 -0
  137. package/lib/tools/auth0/client.js +12 -12
  138. package/lib/tools/auth0/handlers/actions.d.ts +95 -0
  139. package/lib/tools/auth0/handlers/actions.js +22 -24
  140. package/lib/tools/auth0/handlers/attackProtection.d.ts +28 -0
  141. package/lib/tools/auth0/handlers/attackProtection.js +14 -17
  142. package/lib/tools/auth0/handlers/branding.d.ts +27 -0
  143. package/lib/tools/auth0/handlers/branding.js +13 -9
  144. package/lib/tools/auth0/handlers/clientGrants.d.ts +32 -0
  145. package/lib/tools/auth0/handlers/clientGrants.js +17 -10
  146. package/lib/tools/auth0/handlers/clients.d.ts +23 -0
  147. package/lib/tools/auth0/handlers/clients.js +15 -8
  148. package/lib/tools/auth0/handlers/connections.d.ts +54 -0
  149. package/lib/tools/auth0/handlers/connections.js +30 -10
  150. package/lib/tools/auth0/handlers/databases.d.ts +36 -0
  151. package/lib/tools/auth0/handlers/databases.js +25 -13
  152. package/lib/tools/auth0/handlers/default.d.ts +54 -0
  153. package/lib/tools/auth0/handlers/default.js +62 -36
  154. package/lib/tools/auth0/handlers/emailProvider.d.ts +11 -0
  155. package/lib/tools/auth0/handlers/emailTemplates.d.ts +26 -0
  156. package/lib/tools/auth0/handlers/emailTemplates.js +8 -10
  157. package/lib/tools/auth0/handlers/guardianFactorProviders.d.ts +25 -0
  158. package/lib/tools/auth0/handlers/guardianFactorProviders.js +3 -3
  159. package/lib/tools/auth0/handlers/guardianFactorTemplates.d.ts +21 -0
  160. package/lib/tools/auth0/handlers/guardianFactorTemplates.js +3 -3
  161. package/lib/tools/auth0/handlers/guardianFactors.d.ts +21 -0
  162. package/lib/tools/auth0/handlers/guardianFactors.js +3 -3
  163. package/lib/tools/auth0/handlers/guardianPhoneFactorMessageTypes.d.ts +21 -0
  164. package/lib/tools/auth0/handlers/guardianPhoneFactorMessageTypes.js +11 -10
  165. package/lib/tools/auth0/handlers/guardianPhoneFactorSelectedProvider.d.ts +18 -0
  166. package/lib/tools/auth0/handlers/guardianPhoneFactorSelectedProvider.js +10 -9
  167. package/lib/tools/auth0/handlers/guardianPolicies.d.ts +23 -0
  168. package/lib/tools/auth0/handlers/guardianPolicies.js +5 -4
  169. package/lib/tools/auth0/handlers/hooks.d.ts +58 -0
  170. package/lib/tools/auth0/handlers/hooks.js +34 -21
  171. package/lib/tools/auth0/handlers/index.d.ts +129 -0
  172. package/lib/tools/auth0/handlers/index.js +31 -27
  173. package/lib/tools/auth0/handlers/migrations.d.ts +15 -0
  174. package/lib/tools/auth0/handlers/migrations.js +3 -2
  175. package/lib/tools/auth0/handlers/organizations.d.ts +51 -0
  176. package/lib/tools/auth0/handlers/organizations.js +62 -32
  177. package/lib/tools/auth0/handlers/pages.d.ts +42 -0
  178. package/lib/tools/auth0/handlers/pages.js +20 -14
  179. package/lib/tools/auth0/handlers/prompts.d.ts +11 -0
  180. package/lib/tools/auth0/handlers/prompts.js +1 -0
  181. package/lib/tools/auth0/handlers/resourceServers.d.ts +51 -0
  182. package/lib/tools/auth0/handlers/resourceServers.js +22 -14
  183. package/lib/tools/auth0/handlers/roles.d.ts +48 -0
  184. package/lib/tools/auth0/handlers/roles.js +56 -32
  185. package/lib/tools/auth0/handlers/rules.d.ts +55 -0
  186. package/lib/tools/auth0/handlers/rules.js +53 -36
  187. package/lib/tools/auth0/handlers/rulesConfigs.d.ts +25 -0
  188. package/lib/tools/auth0/handlers/rulesConfigs.js +12 -6
  189. package/lib/tools/auth0/handlers/tenant.d.ts +11 -0
  190. package/lib/tools/auth0/handlers/tenant.js +8 -4
  191. package/lib/tools/auth0/handlers/triggers.d.ts +35 -0
  192. package/lib/tools/auth0/handlers/triggers.js +12 -13
  193. package/lib/tools/auth0/index.d.ts +15 -0
  194. package/lib/tools/auth0/index.js +15 -31
  195. package/lib/tools/auth0/schema.d.ts +15 -0
  196. package/lib/tools/auth0/schema.js +7 -27
  197. package/lib/tools/calculateChanges.d.ts +26 -0
  198. package/lib/tools/calculateChanges.js +12 -7
  199. package/lib/tools/constants.d.ts +71 -0
  200. package/lib/tools/constants.js +164 -161
  201. package/lib/tools/deploy.d.ts +3 -0
  202. package/lib/tools/deploy.js +3 -3
  203. package/lib/tools/index.d.ts +82 -0
  204. package/lib/tools/index.js +1 -1
  205. package/lib/tools/utils.d.ts +18 -0
  206. package/lib/tools/utils.js +68 -10
  207. package/lib/tools/validationError.d.ts +5 -0
  208. package/lib/tools/{ValidationError.js → validationError.js} +3 -1
  209. package/lib/types.d.ts +255 -0
  210. package/lib/types.js +2 -0
  211. package/lib/utils.d.ts +66 -0
  212. package/lib/utils.js +18 -25
  213. package/package.json +16 -7
  214. package/tsconfig.json +3 -4
  215. package/typescript-migration-progress.sh +1 -1
  216. package/lib/tools/logger.js +0 -15
@@ -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,13 +103,22 @@ 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 existingDatabasesConnections = 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
- return Object.assign(Object.assign({}, db), { enabled_clients: (0, utils_1.getEnabledClients)(assets, db, existingDatabasesConecctions, clients) });
121
+ return Object.assign(Object.assign({}, db), { enabled_clients: (0, utils_1.getEnabledClients)(assets, db, existingDatabasesConnections, clients) });
110
122
  }
111
123
  return db;
112
124
  });
@@ -0,0 +1,54 @@
1
+ import { Asset, Assets, Auth0APIClient, CalculatedChanges } from '../../../types';
2
+ import { ConfigFunction } from '../../../configFactory';
3
+ export declare function order(value: any): (t: any, n: any, descriptor: any) => any;
4
+ export default class APIHandler {
5
+ config: ConfigFunction;
6
+ id: string;
7
+ type: string;
8
+ updated: number;
9
+ created: number;
10
+ deleted: number;
11
+ existing: null | Asset | Asset[];
12
+ client: Auth0APIClient;
13
+ identifiers: string[];
14
+ objectFields: string[];
15
+ sensitiveFieldsToObfuscate: string[];
16
+ stripUpdateFields: string[];
17
+ stripCreateFields: string[];
18
+ name?: string;
19
+ functions: {
20
+ getAll: string;
21
+ update: string;
22
+ create: string;
23
+ delete: string;
24
+ };
25
+ constructor(options: {
26
+ id?: APIHandler['id'];
27
+ config: ConfigFunction;
28
+ type: APIHandler['type'];
29
+ client: Auth0APIClient;
30
+ objectFields?: APIHandler['objectFields'];
31
+ identifiers?: APIHandler['identifiers'];
32
+ stripUpdateFields?: APIHandler['stripUpdateFields'];
33
+ sensitiveFieldsToObfuscate?: APIHandler['sensitiveFieldsToObfuscate'];
34
+ stripCreateFields?: APIHandler['stripCreateFields'];
35
+ functions: {
36
+ getAll?: string;
37
+ update?: string;
38
+ create?: string;
39
+ delete?: string;
40
+ };
41
+ });
42
+ getClientFN(fn: string | Function): Function;
43
+ didDelete(item: Asset): void;
44
+ didCreate(item: Asset): void;
45
+ didUpdate(item: Asset): void;
46
+ objString(item: Asset): string;
47
+ getType(): Promise<Asset | Asset[] | null>;
48
+ load(): Promise<{
49
+ [key: string]: Asset | Asset[] | null;
50
+ }>;
51
+ calcChanges(assets: Assets): Promise<CalculatedChanges>;
52
+ validate(assets: Assets): Promise<void>;
53
+ processChanges(assets: Assets, changes: CalculatedChanges): Promise<void>;
54
+ }
@@ -13,9 +13,9 @@ 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"));
17
- const logger_1 = __importDefault(require("../../logger"));
16
+ const validationError_1 = __importDefault(require("../../validationError"));
18
17
  const utils_1 = require("../../utils");
18
+ const logger_1 = __importDefault(require("../../../logger"));
19
19
  const calculateChanges_1 = require("../../calculateChanges");
20
20
  function order(value) {
21
21
  return function decorator(t, n, descriptor) {
@@ -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,10 @@ 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.sensitiveFieldsToObfuscate = options.sensitiveFieldsToObfuscate || [];
38
+ this.stripCreateFields = options.stripCreateFields || [];
39
+ this.functions = Object.assign({ getAll: 'getAll', create: 'create', delete: 'delete', update: 'update' }, (options.functions || {}));
41
40
  this.updated = 0;
42
41
  this.created = 0;
43
42
  this.deleted = 0;
@@ -59,7 +58,7 @@ class DefaultHandler {
59
58
  logger_1.default.info(`Updated [${this.type}]: ${this.objString(item)}`);
60
59
  }
61
60
  objString(item) {
62
- return (0, utils_1.dumpJSON)(item);
61
+ return (0, utils_1.convertJsonToString)(item);
63
62
  }
64
63
  getType() {
65
64
  return __awaiter(this, void 0, void 0, function* () {
@@ -71,7 +70,8 @@ class DefaultHandler {
71
70
  return __awaiter(this, void 0, void 0, function* () {
72
71
  // Load Asset from Tenant
73
72
  logger_1.default.info(`Retrieving ${this.type} data from Auth0`);
74
- this.existing = yield this.getType();
73
+ const data = yield this.getType();
74
+ this.existing = (0, utils_1.obfuscateSensitiveValues)(data, this.sensitiveFieldsToObfuscate);
75
75
  return { [this.type]: this.existing };
76
76
  });
77
77
  }
@@ -79,15 +79,22 @@ class DefaultHandler {
79
79
  return __awaiter(this, void 0, void 0, function* () {
80
80
  const typeAssets = assets[this.type];
81
81
  // Do nothing if not set
82
- if (!typeAssets)
83
- return {};
82
+ if (!typeAssets) {
83
+ return {
84
+ del: [],
85
+ create: [],
86
+ conflicts: [],
87
+ update: [],
88
+ };
89
+ }
84
90
  const existing = yield this.getType();
85
91
  // Figure out what needs to be updated vs created
86
92
  return (0, calculateChanges_1.calculateChanges)({
87
93
  handler: this,
88
94
  assets: typeAssets,
95
+ //@ts-ignore TODO: investigate what happens when `existing` is null
89
96
  existing,
90
- identifiers: this.identifiers
97
+ identifiers: this.identifiers,
91
98
  });
92
99
  });
93
100
  }
@@ -102,16 +109,16 @@ class DefaultHandler {
102
109
  const duplicateNames = (0, utils_1.duplicateItems)(typeAssets, 'name');
103
110
  if (duplicateNames.length > 0) {
104
111
  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
106
- ${(0, utils_1.dumpJSON)(formatted)}.
112
+ throw new validationError_1.default(`There are multiple ${this.type} with the same name combinations
113
+ ${(0, utils_1.convertJsonToString)(formatted)}.
107
114
  Names must be unique.`);
108
115
  }
109
116
  // Do not allow items with same id
110
117
  const duplicateIDs = (0, utils_1.duplicateItems)(typeAssets, this.id);
111
118
  if (duplicateIDs.length > 0) {
112
119
  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
114
- ${(0, utils_1.dumpJSON)(formatted)}.
120
+ throw new validationError_1.default(`There are multiple ${this.type} for the following stage-order combinations
121
+ ${(0, utils_1.convertJsonToString)(formatted)}.
115
122
  Only one rule must be defined for the same order number in a stage.`);
116
123
  }
117
124
  });
@@ -129,7 +136,8 @@ class DefaultHandler {
129
136
  // Process Deleted
130
137
  if (del.length > 0) {
131
138
  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');
139
+ const byExtension = this.config('EXTENSION_SECRET') &&
140
+ (this.type === 'rules' || this.type === 'resourceServers');
133
141
  const shouldDelete = allowDelete || byExtension;
134
142
  if (!shouldDelete) {
135
143
  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,7 +145,8 @@ class DefaultHandler {
137
145
  `);
138
146
  }
139
147
  else {
140
- yield this.client.pool.addEachTask({
148
+ yield this.client.pool
149
+ .addEachTask({
141
150
  data: del || [],
142
151
  generator: (delItem) => {
143
152
  const delFunction = this.getClientFN(this.functions.delete);
@@ -149,30 +158,41 @@ class DefaultHandler {
149
158
  .catch((err) => {
150
159
  throw new Error(`Problem deleting ${this.type} ${this.objString(delItem)}\n${err}`);
151
160
  });
152
- }
153
- }).promise();
161
+ },
162
+ })
163
+ .promise();
154
164
  }
155
165
  }
156
166
  // Process Renaming Entries Temp due to conflicts in names
157
- yield this.client.pool.addEachTask({
167
+ yield this.client.pool
168
+ .addEachTask({
158
169
  data: conflicts || [],
159
170
  generator: (updateItem) => {
160
171
  const updateFN = this.getClientFN(this.functions.update);
161
172
  const params = { [this.id]: updateItem[this.id] };
162
- const payload = (0, utils_1.stripFields)(Object.assign({}, updateItem), this.stripUpdateFields);
163
- return updateFN(params, payload)
173
+ const updatePayload = (() => {
174
+ let data = (0, utils_1.stripFields)(Object.assign({}, updateItem), this.stripUpdateFields);
175
+ return (0, utils_1.stripObfuscatedFieldsFromPayload)(data, this.sensitiveFieldsToObfuscate);
176
+ })();
177
+ return updateFN(params, updatePayload)
164
178
  .then((data) => this.didUpdate(data))
165
179
  .catch((err) => {
166
180
  throw new Error(`Problem updating ${this.type} ${this.objString(updateItem)}\n${err}`);
167
181
  });
168
- }
169
- }).promise();
182
+ },
183
+ })
184
+ .promise();
170
185
  // Process Creations
171
- yield this.client.pool.addEachTask({
186
+ yield this.client.pool
187
+ .addEachTask({
172
188
  data: create || [],
173
189
  generator: (createItem) => {
174
190
  const createFunction = this.getClientFN(this.functions.create);
175
- return createFunction(createItem)
191
+ const createPayload = (() => {
192
+ const strippedPayload = (0, utils_1.stripFields)(createItem, this.stripCreateFields);
193
+ return (0, utils_1.stripObfuscatedFieldsFromPayload)(strippedPayload, this.sensitiveFieldsToObfuscate);
194
+ })();
195
+ return createFunction(createPayload)
176
196
  .then((data) => {
177
197
  this.didCreate(data);
178
198
  this.created += 1;
@@ -180,16 +200,21 @@ class DefaultHandler {
180
200
  .catch((err) => {
181
201
  throw new Error(`Problem creating ${this.type} ${this.objString(createItem)}\n${err}`);
182
202
  });
183
- }
184
- }).promise();
203
+ },
204
+ })
205
+ .promise();
185
206
  // Process Updates and strip fields not allowed in updates
186
- yield this.client.pool.addEachTask({
207
+ yield this.client.pool
208
+ .addEachTask({
187
209
  data: update || [],
188
210
  generator: (updateItem) => {
189
211
  const updateFN = this.getClientFN(this.functions.update);
190
212
  const params = { [this.id]: updateItem[this.id] };
191
- const payload = (0, utils_1.stripFields)(Object.assign({}, updateItem), this.stripUpdateFields);
192
- return updateFN(params, payload)
213
+ const updatePayload = (() => {
214
+ let data = (0, utils_1.stripFields)(Object.assign({}, updateItem), this.stripUpdateFields);
215
+ return (0, utils_1.stripObfuscatedFieldsFromPayload)(data, this.sensitiveFieldsToObfuscate);
216
+ })();
217
+ return updateFN(params, updatePayload)
193
218
  .then((data) => {
194
219
  this.didUpdate(data);
195
220
  this.updated += 1;
@@ -197,9 +222,10 @@ class DefaultHandler {
197
222
  .catch((err) => {
198
223
  throw new Error(`Problem updating ${this.type} ${this.objString(updateItem)}\n${err}`);
199
224
  });
200
- }
201
- }).promise();
225
+ },
226
+ })
227
+ .promise();
202
228
  });
203
229
  }
204
230
  }
205
- exports.default = DefaultHandler;
231
+ exports.default = APIHandler;
@@ -0,0 +1,11 @@
1
+ import DefaultHandler from './default';
2
+ import { Asset, Assets } from '../../../types';
3
+ export declare const schema: {
4
+ type: string;
5
+ };
6
+ export default class EmailProviderHandler extends DefaultHandler {
7
+ constructor(options: DefaultHandler);
8
+ getType(): Promise<Asset>;
9
+ objString(provider: any): string;
10
+ processChanges(assets: Assets): Promise<void>;
11
+ }
@@ -0,0 +1,26 @@
1
+ import DefaultHandler from './default';
2
+ import { Assets, Asset } from '../../../types';
3
+ export declare const supportedTemplates: string[];
4
+ export declare const schema: {
5
+ type: string;
6
+ items: {
7
+ type: string;
8
+ properties: {
9
+ template: {
10
+ type: string;
11
+ enum: string[];
12
+ };
13
+ body: {
14
+ type: string;
15
+ default: string;
16
+ };
17
+ };
18
+ required: string[];
19
+ };
20
+ };
21
+ export default class EmailTemplateHandler extends DefaultHandler {
22
+ constructor(options: DefaultHandler);
23
+ getType(): Promise<Asset>;
24
+ updateOrCreate(emailTemplate: any): Promise<void>;
25
+ processChanges(assets: Assets): Promise<void>;
26
+ }
@@ -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) {
@@ -0,0 +1,25 @@
1
+ import DefaultHandler from './default';
2
+ import { Asset, Assets } from '../../../types';
3
+ export declare const schema: {
4
+ type: string;
5
+ items: {
6
+ type: string;
7
+ properties: {
8
+ name: {
9
+ type: string;
10
+ enum: string[];
11
+ };
12
+ provider: {
13
+ type: string;
14
+ enum: string[];
15
+ };
16
+ };
17
+ required: string[];
18
+ };
19
+ };
20
+ export default class GuardianFactorProvidersHandler extends DefaultHandler {
21
+ existing: Asset[];
22
+ constructor(options: DefaultHandler);
23
+ getType(): Promise<Asset[]>;
24
+ processChanges(assets: Assets): Promise<void>;
25
+ }
@@ -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) {
@@ -0,0 +1,21 @@
1
+ import DefaultHandler from './default';
2
+ import { Assets, Asset } from '../../../types';
3
+ export declare const schema: {
4
+ type: string;
5
+ items: {
6
+ type: string;
7
+ properties: {
8
+ name: {
9
+ type: string;
10
+ enum: string[];
11
+ };
12
+ };
13
+ required: string[];
14
+ };
15
+ };
16
+ export default class GuardianFactorTemplatesHandler extends DefaultHandler {
17
+ existing: Asset[];
18
+ constructor(options: any);
19
+ getType(): Promise<Asset[]>;
20
+ processChanges(assets: Assets): Promise<void>;
21
+ }
@@ -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) {
@@ -0,0 +1,21 @@
1
+ import DefaultHandler from './default';
2
+ import { Asset, Assets } from '../../../types';
3
+ export declare const schema: {
4
+ type: string;
5
+ items: {
6
+ type: string;
7
+ properties: {
8
+ name: {
9
+ type: string;
10
+ enum: string[];
11
+ };
12
+ };
13
+ required: string[];
14
+ };
15
+ };
16
+ export default class GuardianFactorsHandler extends DefaultHandler {
17
+ existing: Asset[];
18
+ constructor(options: DefaultHandler);
19
+ getType(): Promise<Asset[]>;
20
+ processChanges(assets: Assets): Promise<void>;
21
+ }
@@ -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) {
@@ -0,0 +1,21 @@
1
+ import DefaultHandler from './default';
2
+ import { Asset, Assets } from '../../../types';
3
+ export declare const schema: {
4
+ type: string;
5
+ properties: {
6
+ message_types: {
7
+ type: string;
8
+ items: {
9
+ type: string;
10
+ enum: string[];
11
+ };
12
+ };
13
+ };
14
+ additionalProperties: boolean;
15
+ };
16
+ export default class GuardianPhoneMessageTypesHandler extends DefaultHandler {
17
+ existing: Asset[];
18
+ constructor(options: DefaultHandler);
19
+ getType(): Promise<Asset[] | {}>;
20
+ processChanges(assets: Assets): Promise<void>;
21
+ }
@@ -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)
@@ -0,0 +1,18 @@
1
+ import DefaultHandler from './default';
2
+ import { Asset, Assets } from '../../../types';
3
+ export declare const schema: {
4
+ type: string;
5
+ properties: {
6
+ provider: {
7
+ type: string;
8
+ enum: string[];
9
+ };
10
+ };
11
+ additionalProperties: boolean;
12
+ };
13
+ export default class GuardianPhoneSelectedProviderHandler extends DefaultHandler {
14
+ existing: Asset[];
15
+ constructor(options: any);
16
+ getType(): Promise<{}>;
17
+ processChanges(assets: Assets): Promise<void>;
18
+ }