auth0-deploy-cli 7.5.1 → 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 (115) 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 +209 -7
  7. package/CONTRIBUTING.md +2 -2
  8. package/README.md +3 -0
  9. package/lib/args.js +16 -17
  10. package/lib/commands/export.js +3 -3
  11. package/lib/commands/import.js +7 -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 +6 -5
  16. package/lib/context/directory/handlers/attackProtection.js +7 -6
  17. package/lib/context/directory/handlers/branding.js +60 -0
  18. package/lib/context/directory/handlers/clientGrants.js +6 -4
  19. package/lib/context/directory/handlers/clients.js +4 -3
  20. package/lib/context/directory/handlers/connections.js +7 -4
  21. package/lib/context/directory/handlers/databases.js +30 -22
  22. package/lib/context/directory/handlers/emailProvider.js +6 -4
  23. package/lib/context/directory/handlers/emailTemplates.js +13 -11
  24. package/lib/context/directory/handlers/guardianFactorProviders.js +6 -4
  25. package/lib/context/directory/handlers/guardianFactorTemplates.js +6 -4
  26. package/lib/context/directory/handlers/guardianFactors.js +6 -4
  27. package/lib/context/directory/handlers/guardianPhoneFactorMessageTypes.js +4 -3
  28. package/lib/context/directory/handlers/guardianPhoneFactorSelectedProvider.js +4 -3
  29. package/lib/context/directory/handlers/guardianPolicies.js +4 -3
  30. package/lib/context/directory/handlers/hooks.js +5 -4
  31. package/lib/context/directory/handlers/index.js +5 -2
  32. package/lib/context/directory/handlers/migrations.js +8 -8
  33. package/lib/context/directory/handlers/organizations.js +4 -3
  34. package/lib/context/directory/handlers/pages.js +20 -20
  35. package/lib/context/directory/handlers/resourceServers.js +6 -4
  36. package/lib/context/directory/handlers/roles.js +4 -3
  37. package/lib/context/directory/handlers/rules.js +5 -4
  38. package/lib/context/directory/handlers/rulesConfigs.js +7 -5
  39. package/lib/context/directory/handlers/tenant.js +7 -4
  40. package/lib/context/directory/handlers/triggers.js +3 -2
  41. package/lib/context/directory/index.js +23 -22
  42. package/lib/context/index.js +66 -62
  43. package/lib/context/yaml/handlers/actions.js +12 -8
  44. package/lib/context/yaml/handlers/attackProtection.js +6 -12
  45. package/lib/context/yaml/handlers/branding.js +66 -0
  46. package/lib/context/yaml/handlers/clientGrants.js +5 -4
  47. package/lib/context/yaml/handlers/clients.js +9 -6
  48. package/lib/context/yaml/handlers/connections.js +10 -7
  49. package/lib/context/yaml/handlers/databases.js +15 -10
  50. package/lib/context/yaml/handlers/emailProvider.js +7 -5
  51. package/lib/context/yaml/handlers/emailTemplates.js +6 -5
  52. package/lib/context/yaml/handlers/guardianFactorProviders.js +6 -13
  53. package/lib/context/yaml/handlers/guardianFactorTemplates.js +6 -13
  54. package/lib/context/yaml/handlers/guardianFactors.js +6 -13
  55. package/lib/context/yaml/handlers/guardianPhoneFactorMessageTypes.js +6 -13
  56. package/lib/context/yaml/handlers/guardianPhoneFactorSelectedProvider.js +6 -13
  57. package/lib/context/yaml/handlers/guardianPolicies.js +6 -13
  58. package/lib/context/yaml/handlers/hooks.js +7 -5
  59. package/lib/context/yaml/handlers/index.js +5 -2
  60. package/lib/context/yaml/handlers/migrations.js +3 -2
  61. package/lib/context/yaml/handlers/organizations.js +6 -5
  62. package/lib/context/yaml/handlers/pages.js +6 -5
  63. package/lib/context/yaml/handlers/resourceServers.js +5 -4
  64. package/lib/context/yaml/handlers/roles.js +6 -5
  65. package/lib/context/yaml/handlers/rules.js +6 -5
  66. package/lib/context/yaml/handlers/rulesConfigs.js +6 -5
  67. package/lib/context/yaml/handlers/tenant.js +7 -5
  68. package/lib/context/yaml/handlers/triggers.js +5 -4
  69. package/lib/context/yaml/index.js +33 -24
  70. package/lib/index.js +20 -15
  71. package/lib/logger.js +4 -3
  72. package/lib/readonly.js +11 -16
  73. package/lib/sessionDurationsToMinutes.js +15 -0
  74. package/lib/tools/auth0/client.js +6 -6
  75. package/lib/tools/auth0/handlers/actions.js +21 -23
  76. package/lib/tools/auth0/handlers/attackProtection.js +14 -17
  77. package/lib/tools/auth0/handlers/branding.js +71 -13
  78. package/lib/tools/auth0/handlers/clientGrants.js +17 -10
  79. package/lib/tools/auth0/handlers/clients.js +15 -8
  80. package/lib/tools/auth0/handlers/connections.js +30 -10
  81. package/lib/tools/auth0/handlers/databases.js +24 -12
  82. package/lib/tools/auth0/handlers/default.js +47 -29
  83. package/lib/tools/auth0/handlers/emailTemplates.js +8 -10
  84. package/lib/tools/auth0/handlers/guardianFactorProviders.js +3 -3
  85. package/lib/tools/auth0/handlers/guardianFactorTemplates.js +3 -3
  86. package/lib/tools/auth0/handlers/guardianFactors.js +3 -3
  87. package/lib/tools/auth0/handlers/guardianPhoneFactorMessageTypes.js +11 -10
  88. package/lib/tools/auth0/handlers/guardianPhoneFactorSelectedProvider.js +10 -9
  89. package/lib/tools/auth0/handlers/guardianPolicies.js +5 -4
  90. package/lib/tools/auth0/handlers/hooks.js +34 -21
  91. package/lib/tools/auth0/handlers/index.js +31 -27
  92. package/lib/tools/auth0/handlers/migrations.js +2 -1
  93. package/lib/tools/auth0/handlers/organizations.js +67 -32
  94. package/lib/tools/auth0/handlers/pages.js +20 -14
  95. package/lib/tools/auth0/handlers/prompts.js +1 -0
  96. package/lib/tools/auth0/handlers/resourceServers.js +28 -15
  97. package/lib/tools/auth0/handlers/roles.js +61 -32
  98. package/lib/tools/auth0/handlers/rules.js +55 -32
  99. package/lib/tools/auth0/handlers/rulesConfigs.js +12 -6
  100. package/lib/tools/auth0/handlers/tenant.js +8 -4
  101. package/lib/tools/auth0/handlers/triggers.js +11 -12
  102. package/lib/tools/auth0/index.js +15 -31
  103. package/lib/tools/auth0/schema.js +7 -27
  104. package/lib/tools/calculateChanges.js +149 -0
  105. package/lib/tools/constants.js +162 -154
  106. package/lib/tools/deploy.js +1 -1
  107. package/lib/tools/index.js +1 -1
  108. package/lib/tools/logger.js +14 -8
  109. package/lib/tools/utils.js +3 -144
  110. package/lib/tools/{ValidationError.js → validationError.js} +3 -1
  111. package/lib/types.js +2 -0
  112. package/lib/utils.js +12 -22
  113. package/package.json +9 -2
  114. package/tsconfig.json +2 -3
  115. package/typescript-migration-progress.sh +1 -1
@@ -21,10 +21,11 @@ function parse(context) {
21
21
  if (!(0, utils_1.existsMustBeDir)(factorTemplatesFolder))
22
22
  return { guardianFactorTemplates: undefined }; // Skip
23
23
  const foundFiles = (0, utils_1.getFiles)(factorTemplatesFolder, ['.json']);
24
- const guardianFactorTemplates = foundFiles.map((f) => (0, utils_1.loadJSON)(f, context.mappings))
24
+ const guardianFactorTemplates = foundFiles
25
+ .map((f) => (0, utils_1.loadJSON)(f, context.mappings))
25
26
  .filter((p) => Object.keys(p).length > 0); // Filter out empty guardianFactorTemplates
26
27
  return {
27
- guardianFactorTemplates
28
+ guardianFactorTemplates,
28
29
  };
29
30
  }
30
31
  function dump(context) {
@@ -40,7 +41,8 @@ function dump(context) {
40
41
  });
41
42
  });
42
43
  }
43
- exports.default = {
44
+ const guardianFactorTemplatesHandler = {
44
45
  parse,
45
- dump
46
+ dump,
46
47
  };
48
+ exports.default = guardianFactorTemplatesHandler;
@@ -21,10 +21,11 @@ function parse(context) {
21
21
  if (!(0, utils_1.existsMustBeDir)(factorsFolder))
22
22
  return { guardianFactors: undefined }; // Skip
23
23
  const foundFiles = (0, utils_1.getFiles)(factorsFolder, ['.json']);
24
- const guardianFactors = foundFiles.map((f) => (0, utils_1.loadJSON)(f, context.mappings))
24
+ const guardianFactors = foundFiles
25
+ .map((f) => (0, utils_1.loadJSON)(f, context.mappings))
25
26
  .filter((p) => Object.keys(p).length > 0); // Filter out empty guardianFactors
26
27
  return {
27
- guardianFactors
28
+ guardianFactors,
28
29
  };
29
30
  }
30
31
  function dump(context) {
@@ -40,7 +41,8 @@ function dump(context) {
40
41
  });
41
42
  });
42
43
  }
43
- exports.default = {
44
+ const guardianFactorsHandler = {
44
45
  parse,
45
- dump
46
+ dump,
46
47
  };
48
+ exports.default = guardianFactorsHandler;
@@ -23,7 +23,7 @@ function parse(context) {
23
23
  const file = path_1.default.join(guardianFolder, 'phoneFactorMessageTypes.json');
24
24
  if ((0, utils_1.isFile)(file)) {
25
25
  return {
26
- guardianPhoneFactorMessageTypes: (0, utils_1.loadJSON)(file, context.mappings)
26
+ guardianPhoneFactorMessageTypes: (0, utils_1.loadJSON)(file, context.mappings),
27
27
  };
28
28
  }
29
29
  return {};
@@ -39,7 +39,8 @@ function dump(context) {
39
39
  (0, utils_1.dumpJSON)(file, guardianPhoneFactorMessageTypes);
40
40
  });
41
41
  }
42
- exports.default = {
42
+ const guardianFactorMessageTypesHandler = {
43
43
  parse,
44
- dump
44
+ dump,
45
45
  };
46
+ exports.default = guardianFactorMessageTypesHandler;
@@ -23,7 +23,7 @@ function parse(context) {
23
23
  const file = path_1.default.join(guardianFolder, 'phoneFactorSelectedProvider.json');
24
24
  if ((0, utils_1.isFile)(file)) {
25
25
  return {
26
- guardianPhoneFactorSelectedProvider: (0, utils_1.loadJSON)(file, context.mappings)
26
+ guardianPhoneFactorSelectedProvider: (0, utils_1.loadJSON)(file, context.mappings),
27
27
  };
28
28
  }
29
29
  return {};
@@ -39,7 +39,8 @@ function dump(context) {
39
39
  (0, utils_1.dumpJSON)(file, guardianPhoneFactorSelectedProvider);
40
40
  });
41
41
  }
42
- exports.default = {
42
+ const guardianFactorSelectedProviderHandler = {
43
43
  parse,
44
- dump
44
+ dump,
45
45
  };
46
+ exports.default = guardianFactorSelectedProviderHandler;
@@ -23,7 +23,7 @@ function parse(context) {
23
23
  const file = path_1.default.join(guardianFolder, 'policies.json');
24
24
  if ((0, utils_1.isFile)(file)) {
25
25
  return {
26
- guardianPolicies: (0, utils_1.loadJSON)(file, context.mappings)
26
+ guardianPolicies: (0, utils_1.loadJSON)(file, context.mappings),
27
27
  };
28
28
  }
29
29
  return {};
@@ -39,7 +39,8 @@ function dump(context) {
39
39
  (0, utils_1.dumpJSON)(file, guardianPolicies);
40
40
  });
41
41
  }
42
- exports.default = {
42
+ const guardianPoliciesHandler = {
43
43
  parse,
44
- dump
44
+ dump,
45
45
  };
46
+ exports.default = guardianPoliciesHandler;
@@ -31,12 +31,12 @@ function parse(context) {
31
31
  return hook;
32
32
  });
33
33
  return {
34
- hooks
34
+ hooks,
35
35
  };
36
36
  }
37
37
  function dump(context) {
38
38
  return __awaiter(this, void 0, void 0, function* () {
39
- const hooks = [...context.assets.hooks || []];
39
+ const hooks = [...(context.assets.hooks || [])];
40
40
  if (hooks.length < 1)
41
41
  return;
42
42
  // Create Hooks folder
@@ -56,7 +56,8 @@ function dump(context) {
56
56
  });
57
57
  });
58
58
  }
59
- exports.default = {
59
+ const hooksHandler = {
60
60
  parse,
61
- dump
61
+ dump,
62
62
  };
63
+ exports.default = hooksHandler;
@@ -27,7 +27,8 @@ const actions_1 = __importDefault(require("./actions"));
27
27
  const organizations_1 = __importDefault(require("./organizations"));
28
28
  const triggers_1 = __importDefault(require("./triggers"));
29
29
  const attackProtection_1 = __importDefault(require("./attackProtection"));
30
- exports.default = {
30
+ const branding_1 = __importDefault(require("./branding"));
31
+ const directoryHandlers = {
31
32
  rules: rules_1.default,
32
33
  rulesConfigs: rulesConfigs_1.default,
33
34
  hooks: hooks_1.default,
@@ -51,5 +52,7 @@ exports.default = {
51
52
  actions: actions_1.default,
52
53
  organizations: organizations_1.default,
53
54
  triggers: triggers_1.default,
54
- attackProtection: attackProtection_1.default
55
+ attackProtection: attackProtection_1.default,
56
+ branding: branding_1.default,
55
57
  };
58
+ exports.default = directoryHandlers;
@@ -19,12 +19,11 @@ function parse(context) {
19
19
  if (!(0, utils_1.existsMustBeDir)(baseFolder))
20
20
  return {}; // Skip
21
21
  const migrationsFile = path_1.default.join(baseFolder, 'migrations.json');
22
- if ((0, utils_1.isFile)(migrationsFile)) {
23
- /* eslint-disable camelcase */
24
- const migrations = (0, utils_1.loadJSON)(migrationsFile, context.mappings);
25
- return { migrations };
26
- }
27
- return {};
22
+ if (!(0, utils_1.isFile)(migrationsFile))
23
+ return {};
24
+ /* eslint-disable camelcase */
25
+ const migrations = (0, utils_1.loadJSON)(migrationsFile, context.mappings);
26
+ return { migrations };
28
27
  }
29
28
  function dump(context) {
30
29
  return __awaiter(this, void 0, void 0, function* () {
@@ -35,7 +34,8 @@ function dump(context) {
35
34
  (0, utils_1.dumpJSON)(migrationsFile, migrations);
36
35
  });
37
36
  }
38
- exports.default = {
37
+ const migrationsHandler = {
39
38
  parse,
40
- dump
39
+ dump,
41
40
  };
41
+ exports.default = migrationsHandler;
@@ -26,7 +26,7 @@ function parse(context) {
26
26
  return org;
27
27
  });
28
28
  return {
29
- organizations
29
+ organizations,
30
30
  };
31
31
  }
32
32
  function dump(context) {
@@ -54,7 +54,8 @@ function dump(context) {
54
54
  });
55
55
  });
56
56
  }
57
- exports.default = {
57
+ const organizationsHandler = {
58
58
  parse,
59
- dump
59
+ dump,
60
60
  };
61
+ exports.default = organizationsHandler;
@@ -22,35 +22,34 @@ function parse(context) {
22
22
  if (!(0, utils_1.existsMustBeDir)(pagesFolder))
23
23
  return { pages: undefined }; // Skip
24
24
  const files = (0, utils_1.getFiles)(pagesFolder, ['.json', '.html']);
25
- const sorted = {};
26
- files.forEach((file) => {
25
+ const sorted = files.reduce((acc, file) => {
27
26
  const { ext, name } = path_1.default.parse(file);
28
- if (!sorted[name])
29
- sorted[name] = {};
27
+ if (!acc[name])
28
+ acc[name] = {};
30
29
  if (ext === '.json')
31
- sorted[name].meta = file;
30
+ acc[name].meta = file;
32
31
  if (ext === '.html')
33
- sorted[name].html = file;
34
- });
35
- const pages = [];
36
- Object.values(sorted).forEach((data) => {
37
- if (!data.meta) {
38
- logger_1.default.warn(`Skipping pages file ${data.html} as missing the corresponding '.json' file`);
39
- }
40
- else if (!data.html) {
41
- logger_1.default.warn(`Skipping pages file ${data.meta} as missing corresponding '.html' file`);
32
+ acc[name].html = file;
33
+ return acc;
34
+ }, {});
35
+ const pages = Object.values(sorted).flatMap(({ meta, html }) => {
36
+ if (!meta) {
37
+ logger_1.default.warn(`Skipping pages file ${html} as missing the corresponding '.json' file`);
38
+ return [];
42
39
  }
43
- else {
44
- pages.push(Object.assign(Object.assign({}, (0, utils_1.loadJSON)(data.meta, context.mappings)), { html: (0, tools_1.loadFileAndReplaceKeywords)(data.html, context.mappings) }));
40
+ if (!html) {
41
+ logger_1.default.warn(`Skipping pages file ${meta} as missing corresponding '.html' file`);
42
+ return [];
45
43
  }
44
+ return Object.assign(Object.assign({}, (0, utils_1.loadJSON)(meta, context.mappings)), { html: (0, tools_1.loadFileAndReplaceKeywords)(html, context.mappings) });
46
45
  });
47
46
  return {
48
- pages
47
+ pages,
49
48
  };
50
49
  }
51
50
  function dump(context) {
52
51
  return __awaiter(this, void 0, void 0, function* () {
53
- const pages = [...context.assets.pages || []];
52
+ const pages = [...(context.assets.pages || [])];
54
53
  if (!pages)
55
54
  return; // Skip, nothing to dump
56
55
  // Create Pages folder
@@ -71,7 +70,8 @@ function dump(context) {
71
70
  });
72
71
  });
73
72
  }
74
- exports.default = {
73
+ const pagesHandler = {
75
74
  parse,
76
- dump
75
+ dump,
77
76
  };
77
+ exports.default = pagesHandler;
@@ -21,10 +21,11 @@ function parse(context) {
21
21
  if (!(0, utils_1.existsMustBeDir)(resourceServersFolder))
22
22
  return { resourceServers: undefined }; // Skip
23
23
  const foundFiles = (0, utils_1.getFiles)(resourceServersFolder, ['.json']);
24
- const resourceServers = foundFiles.map((f) => (0, utils_1.loadJSON)(f, context.mappings))
24
+ const resourceServers = foundFiles
25
+ .map((f) => (0, utils_1.loadJSON)(f, context.mappings))
25
26
  .filter((p) => Object.keys(p).length > 0); // Filter out empty resourceServers
26
27
  return {
27
- resourceServers
28
+ resourceServers,
28
29
  };
29
30
  }
30
31
  function dump(context) {
@@ -40,7 +41,8 @@ function dump(context) {
40
41
  });
41
42
  });
42
43
  }
43
- exports.default = {
44
+ const resourceServersHandler = {
44
45
  parse,
45
- dump
46
+ dump,
46
47
  };
48
+ exports.default = resourceServersHandler;
@@ -27,7 +27,7 @@ function parse(context) {
27
27
  return role;
28
28
  });
29
29
  return {
30
- roles
30
+ roles,
31
31
  };
32
32
  }
33
33
  function dump(context) {
@@ -49,7 +49,8 @@ function dump(context) {
49
49
  });
50
50
  });
51
51
  }
52
- exports.default = {
52
+ const rolesHandler = {
53
53
  parse,
54
- dump
54
+ dump,
55
55
  };
56
+ exports.default = rolesHandler;
@@ -30,12 +30,12 @@ function parse(context) {
30
30
  return rule;
31
31
  });
32
32
  return {
33
- rules
33
+ rules,
34
34
  };
35
35
  }
36
36
  function dump(context) {
37
37
  return __awaiter(this, void 0, void 0, function* () {
38
- const rules = [...context.assets.rules || []];
38
+ const rules = [...(context.assets.rules || [])];
39
39
  if (!rules)
40
40
  return; // Skip, nothing to dump
41
41
  // Create Rules folder
@@ -53,7 +53,8 @@ function dump(context) {
53
53
  });
54
54
  });
55
55
  }
56
- exports.default = {
56
+ const rulesHandler = {
57
57
  parse,
58
- dump
58
+ dump,
59
59
  };
60
+ exports.default = rulesHandler;
@@ -20,19 +20,21 @@ function parse(context) {
20
20
  if (!(0, utils_1.existsMustBeDir)(rulesConfigsFolder))
21
21
  return { rulesConfigs: undefined }; // Skip
22
22
  const foundFiles = (0, utils_1.getFiles)(rulesConfigsFolder, ['.json']);
23
- const rulesConfigs = foundFiles.map((f) => (0, utils_1.loadJSON)(f, context.mappings))
23
+ const rulesConfigs = foundFiles
24
+ .map((f) => (0, utils_1.loadJSON)(f, context.mappings))
24
25
  .filter((p) => Object.keys(p).length > 0); // Filter out empty rulesConfigs
25
26
  return {
26
- rulesConfigs
27
+ rulesConfigs,
27
28
  };
28
29
  }
29
30
  function dump() {
30
31
  return __awaiter(this, void 0, void 0, function* () {
31
32
  // do not export rulesConfigs as its values cannot be extracted
32
- return null;
33
+ return;
33
34
  });
34
35
  }
35
- exports.default = {
36
+ const rulesConfigsHandler = {
36
37
  parse,
37
- dump
38
+ dump,
38
39
  };
40
+ exports.default = rulesConfigsHandler;
@@ -25,6 +25,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  const path_1 = __importDefault(require("path"));
27
27
  const utils_1 = require("../../../utils");
28
+ const sessionDurationsToMinutes_1 = require("../../../sessionDurationsToMinutes");
28
29
  function parse(context) {
29
30
  const baseFolder = path_1.default.join(context.filePath);
30
31
  if (!(0, utils_1.existsMustBeDir)(baseFolder))
@@ -34,10 +35,10 @@ function parse(context) {
34
35
  /* eslint-disable camelcase */
35
36
  const _a = (0, utils_1.loadJSON)(tenantFile, context.mappings), { session_lifetime, idle_session_lifetime } = _a, tenant = __rest(_a, ["session_lifetime", "idle_session_lifetime"]);
36
37
  (0, utils_1.clearTenantFlags)(tenant);
38
+ const sessionDurations = (0, sessionDurationsToMinutes_1.sessionDurationsToMinutes)({ session_lifetime, idle_session_lifetime });
37
39
  return {
38
- tenant: Object.assign(tenant, session_lifetime && (0, utils_1.hoursAsInteger)('session_lifetime', session_lifetime), idle_session_lifetime && (0, utils_1.hoursAsInteger)('idle_session_lifetime', idle_session_lifetime))
40
+ tenant: Object.assign(Object.assign({}, tenant), sessionDurations),
39
41
  };
40
- /* eslint-enable camelcase */
41
42
  }
42
43
  return {};
43
44
  }
@@ -49,9 +50,11 @@ function dump(context) {
49
50
  (0, utils_1.clearTenantFlags)(tenant);
50
51
  const tenantFile = path_1.default.join(context.filePath, 'tenant.json');
51
52
  (0, utils_1.dumpJSON)(tenantFile, tenant);
53
+ return;
52
54
  });
53
55
  }
54
- exports.default = {
56
+ const tenantHandler = {
55
57
  parse,
56
- dump
58
+ dump,
57
59
  };
60
+ exports.default = tenantHandler;
@@ -38,7 +38,8 @@ function dump(context) {
38
38
  fs_extra_1.default.writeFileSync(triggerFile, JSON.stringify(triggers, null, 2));
39
39
  });
40
40
  }
41
- exports.default = {
41
+ const triggersHandler = {
42
42
  parse,
43
- dump
43
+ dump,
44
44
  };
45
+ exports.default = triggersHandler;
@@ -41,22 +41,22 @@ const readonly_1 = __importDefault(require("../../readonly"));
41
41
  const logger_1 = __importDefault(require("../../logger"));
42
42
  const handlers_1 = __importDefault(require("./handlers"));
43
43
  const utils_1 = require("../../utils");
44
- class default_1 {
44
+ class DirectoryContext {
45
45
  constructor(config, mgmtClient) {
46
46
  this.filePath = config.AUTH0_INPUT_FILE;
47
47
  this.config = config;
48
- this.mappings = config.AUTH0_KEYWORD_REPLACE_MAPPINGS;
48
+ this.mappings = config.AUTH0_KEYWORD_REPLACE_MAPPINGS || {};
49
49
  this.mgmtClient = mgmtClient;
50
+ //@ts-ignore for now
51
+ this.assets = {};
50
52
  // Get excluded rules
51
- this.assets = {
52
- exclude: {
53
- rules: config.AUTH0_EXCLUDED_RULES || [],
54
- clients: config.AUTH0_EXCLUDED_CLIENTS || [],
55
- databases: config.AUTH0_EXCLUDED_DATABASES || [],
56
- connections: config.AUTH0_EXCLUDED_CONNECTIONS || [],
57
- resourceServers: config.AUTH0_EXCLUDED_RESOURCE_SERVERS || [],
58
- defaults: config.AUTH0_EXCLUDED_DEFAULTS || []
59
- }
53
+ this.assets.exclude = {
54
+ rules: config.AUTH0_EXCLUDED_RULES || [],
55
+ clients: config.AUTH0_EXCLUDED_CLIENTS || [],
56
+ databases: config.AUTH0_EXCLUDED_DATABASES || [],
57
+ connections: config.AUTH0_EXCLUDED_CONNECTIONS || [],
58
+ resourceServers: config.AUTH0_EXCLUDED_RESOURCE_SERVERS || [],
59
+ defaults: config.AUTH0_EXCLUDED_DEFAULTS || [],
60
60
  };
61
61
  }
62
62
  loadFile(f, folder) {
@@ -73,11 +73,9 @@ class default_1 {
73
73
  if ((0, utils_1.isDirectory)(this.filePath)) {
74
74
  /* If this is a directory, look for each file in the directory */
75
75
  logger_1.default.info(`Processing directory ${this.filePath}`);
76
- Object.values(handlers_1.default)
77
- .forEach((handler) => {
76
+ Object.values(handlers_1.default).forEach((handler) => {
78
77
  const parsed = handler.parse(this);
79
- Object.entries(parsed)
80
- .forEach(([k, v]) => {
78
+ Object.entries(parsed).forEach(([k, v]) => {
81
79
  this.assets[k] = v;
82
80
  });
83
81
  });
@@ -96,17 +94,20 @@ class default_1 {
96
94
  this.assets = (0, readonly_1.default)(this.assets, this.config);
97
95
  // Copy clients to be used by handlers which require converting client_id to the name
98
96
  // Must copy as the client_id will be stripped if AUTH0_EXPORT_IDENTIFIERS is false
99
- this.assets.clientsOrig = [...this.assets.clients];
97
+ //@ts-ignore because assets haven't been typed yet TODO: type assets
98
+ this.assets.clientsOrig = [...(this.assets.clients || [])];
100
99
  // Optionally Strip identifiers
101
100
  if (!this.config.AUTH0_EXPORT_IDENTIFIERS) {
102
101
  this.assets = (0, utils_1.stripIdentifiers)(auth0, this.assets);
103
102
  }
104
- yield Promise.all(Object.entries(handlers_1.default).map(([name, handler]) => __awaiter(this, void 0, void 0, function* () {
103
+ yield Promise.all(Object.entries(handlers_1.default)
104
+ .filter(([handlerName]) => {
105
+ const excludedAssetTypes = this.config.AUTH0_EXCLUDED || [];
106
+ return !excludedAssetTypes.includes(handlerName);
107
+ })
108
+ .map(([name, handler]) => __awaiter(this, void 0, void 0, function* () {
105
109
  try {
106
- const data = yield handler.dump(this);
107
- if (data) {
108
- logger_1.default.info(`Exporting ${name}`);
109
- }
110
+ yield handler.dump(this);
110
111
  }
111
112
  catch (err) {
112
113
  logger_1.default.debug(err.stack);
@@ -116,4 +117,4 @@ class default_1 {
116
117
  });
117
118
  }
118
119
  }
119
- exports.default = default_1;
120
+ exports.default = DirectoryContext;
@@ -12,13 +12,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.setupContext = void 0;
15
16
  const path_1 = __importDefault(require("path"));
16
17
  const auth0_1 = require("auth0");
17
18
  const yaml_1 = __importDefault(require("./yaml"));
18
19
  const directory_1 = __importDefault(require("./directory"));
19
20
  const utils_1 = require("../utils");
20
- const package_json_1 = require("../../package.json");
21
21
  const logger_1 = __importDefault(require("../logger"));
22
+ const { version: packageVersion } = require('../../package.json');
22
23
  const nonPrimitiveProps = [
23
24
  'AUTH0_KEYWORD_REPLACE_MAPPINGS',
24
25
  'AUTH0_EXCLUDED_RULES',
@@ -27,73 +28,76 @@ const nonPrimitiveProps = [
27
28
  'AUTH0_EXCLUDED_CONNECTIONS',
28
29
  'AUTH0_EXCLUDED_RESOURCE_SERVERS',
29
30
  'AUTH0_EXCLUDED_DEFAULTS',
31
+ 'AUTH0_EXCLUDED',
30
32
  'EXCLUDED_PROPS',
31
- 'INCLUDED_PROPS'
33
+ 'INCLUDED_PROPS',
32
34
  ];
33
- function default_1(config) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- // Validate config
36
- const errors = [];
37
- if (!config.AUTH0_DOMAIN)
38
- errors.push('AUTH0_DOMAIN');
39
- if (!config.AUTH0_ACCESS_TOKEN) {
40
- if (!config.AUTH0_CLIENT_ID)
41
- errors.push('AUTH0_CLIENT_ID');
42
- if (!config.AUTH0_CLIENT_SECRET)
43
- errors.push('AUTH0_CLIENT_SECRET');
44
- }
45
- if (errors.length > 0) {
46
- throw new Error(`The following parameters were missing. Please add them to your config.json or as an environment variable. ${JSON.stringify(errors)}`);
47
- }
48
- let accessToken = config.AUTH0_ACCESS_TOKEN;
49
- if (!accessToken) {
50
- const authClient = new auth0_1.AuthenticationClient({
51
- domain: config.AUTH0_DOMAIN,
52
- clientId: config.AUTH0_CLIENT_ID,
53
- clientSecret: config.AUTH0_CLIENT_SECRET
54
- });
55
- const clientCredentials = yield authClient.clientCredentialsGrant({
56
- audience: config.AUTH0_AUDIENCE ? config.AUTH0_AUDIENCE : `https://${config.AUTH0_DOMAIN}/api/v2/`
57
- });
58
- accessToken = clientCredentials.access_token;
59
- }
60
- const mgmtClient = new auth0_1.ManagementClient({
35
+ const setupContext = (config) => __awaiter(void 0, void 0, void 0, function* () {
36
+ // Validate config
37
+ const missingParams = [];
38
+ if (!config.AUTH0_DOMAIN)
39
+ missingParams.push('AUTH0_DOMAIN');
40
+ if (!config.AUTH0_ACCESS_TOKEN) {
41
+ if (!config.AUTH0_CLIENT_ID)
42
+ missingParams.push('AUTH0_CLIENT_ID');
43
+ if (!config.AUTH0_CLIENT_SECRET)
44
+ missingParams.push('AUTH0_CLIENT_SECRET');
45
+ }
46
+ if (missingParams.length > 0) {
47
+ throw new Error(`The following parameters were missing. Please add them to your config.json or as an environment variable. ${JSON.stringify(missingParams)}`);
48
+ }
49
+ const accessToken = yield (() => __awaiter(void 0, void 0, void 0, function* () {
50
+ if (!!config.AUTH0_ACCESS_TOKEN)
51
+ return config.AUTH0_ACCESS_TOKEN;
52
+ const authClient = new auth0_1.AuthenticationClient({
61
53
  domain: config.AUTH0_DOMAIN,
62
- token: accessToken,
63
- retry: { maxRetries: config.AUTH0_API_MAX_RETRIES || 10, enabled: true },
64
- headers: {
65
- 'User-agent': `deploy-cli/${package_json_1.version} (node.js/${process.version.replace('v', '')})`
66
- }
54
+ clientId: config.AUTH0_CLIENT_ID,
55
+ clientSecret: config.AUTH0_CLIENT_SECRET,
67
56
  });
68
- const inputFile = config.AUTH0_INPUT_FILE;
69
- const ensureObject = (key, value) => {
70
- if (typeof value === 'string') {
71
- try {
72
- return JSON.parse(value);
73
- }
74
- catch (e) {
75
- logger_1.default.debug(`Cannot convert config.${key} to an object. Error: ${e.message}`);
76
- return value;
77
- }
57
+ const clientCredentials = yield authClient.clientCredentialsGrant({
58
+ audience: config.AUTH0_AUDIENCE
59
+ ? config.AUTH0_AUDIENCE
60
+ : `https://${config.AUTH0_DOMAIN}/api/v2/`,
61
+ });
62
+ return clientCredentials.access_token;
63
+ }))();
64
+ const mgmtClient = new auth0_1.ManagementClient({
65
+ domain: config.AUTH0_DOMAIN,
66
+ token: accessToken,
67
+ retry: { maxRetries: config.AUTH0_API_MAX_RETRIES || 10, enabled: true },
68
+ headers: {
69
+ 'User-agent': `deploy-cli/${packageVersion} (node.js/${process.version.replace('v', '')})`,
70
+ },
71
+ });
72
+ const inputFile = config.AUTH0_INPUT_FILE;
73
+ const ensureObject = (key, value) => {
74
+ if (typeof value === 'string') {
75
+ try {
76
+ return JSON.parse(value);
78
77
  }
79
- return value;
80
- };
81
- nonPrimitiveProps.forEach((key) => {
82
- if (config[key]) {
83
- config[key] = ensureObject(key, config[key]);
78
+ catch (e) {
79
+ logger_1.default.debug(`Cannot convert config.${key} to an object. Error: ${e.message}`);
80
+ return value;
84
81
  }
85
- });
86
- if (typeof inputFile === 'object') {
87
- return new yaml_1.default(config, mgmtClient);
88
- }
89
- if ((0, utils_1.isDirectory)(inputFile)) {
90
- return new directory_1.default(config, mgmtClient);
91
82
  }
92
- const ext = path_1.default.extname(inputFile);
93
- if (ext === '.yaml' || ext === '.yml') {
94
- return new yaml_1.default(config, mgmtClient);
83
+ return value;
84
+ };
85
+ nonPrimitiveProps.forEach((key) => {
86
+ if (config[key]) {
87
+ //@ts-ignore because this method of config overwriting technically functions
88
+ config[key] = ensureObject(key, config[key]);
95
89
  }
96
- throw new Error(`Unable to determine context processor to load for file ${inputFile}, does it exist? `);
97
90
  });
98
- }
99
- exports.default = default_1;
91
+ if (typeof inputFile === 'object') {
92
+ return new yaml_1.default(config, mgmtClient);
93
+ }
94
+ if ((0, utils_1.isDirectory)(inputFile)) {
95
+ return new directory_1.default(config, mgmtClient);
96
+ }
97
+ const ext = path_1.default.extname(inputFile);
98
+ if (ext === '.yaml' || ext === '.yml') {
99
+ return new yaml_1.default(config, mgmtClient);
100
+ }
101
+ throw new Error(`Unable to determine context processor to load for file ${inputFile}, does it exist? `);
102
+ });
103
+ exports.setupContext = setupContext;