auth0-deploy-cli 7.5.2 → 7.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +219 -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 +10 -9
  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 +83 -61
  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 +12 -12
  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 +25 -13
  82. package/lib/tools/auth0/handlers/default.js +46 -28
  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 +58 -35
  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 +34 -150
  110. package/lib/tools/{ValidationError.js → validationError.js} +3 -1
  111. package/lib/types.js +2 -0
  112. package/lib/utils.js +18 -25
  113. package/package.json +11 -2
  114. package/tsconfig.json +2 -3
  115. package/typescript-migration-progress.sh +1 -1
@@ -9,23 +9,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- function parse(context) {
12
+ function parseAndDump(context) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
14
  // nothing to do, set default if empty
15
15
  return {
16
- guardianPhoneFactorMessageTypes: Object.assign({}, context.assets.guardianPhoneFactorMessageTypes || {})
16
+ guardianPhoneFactorMessageTypes: Object.assign({}, (context.assets.guardianPhoneFactorMessageTypes || {})),
17
17
  };
18
18
  });
19
19
  }
20
- function dump(context) {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- // nothing to do, set default empty
23
- return {
24
- guardianPhoneFactorMessageTypes: Object.assign({}, context.assets.guardianPhoneFactorMessageTypes || {})
25
- };
26
- });
27
- }
28
- exports.default = {
29
- parse,
30
- dump
20
+ const guardianPhoneFactorMessageTypesHandler = {
21
+ parse: parseAndDump,
22
+ dump: parseAndDump,
31
23
  };
24
+ exports.default = guardianPhoneFactorMessageTypesHandler;
@@ -9,23 +9,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- function parse(context) {
13
- return __awaiter(this, void 0, void 0, function* () {
14
- // nothing to do, set default if empty
15
- return {
16
- guardianPhoneFactorSelectedProvider: Object.assign({}, context.assets.guardianPhoneFactorSelectedProvider || {})
17
- };
18
- });
19
- }
20
- function dump(context) {
12
+ function parseAndDump(context) {
21
13
  return __awaiter(this, void 0, void 0, function* () {
22
14
  // nothing to do, set default empty
23
15
  return {
24
- guardianPhoneFactorSelectedProvider: Object.assign({}, context.assets.guardianPhoneFactorSelectedProvider || {})
16
+ guardianPhoneFactorSelectedProvider: Object.assign({}, (context.assets.guardianPhoneFactorSelectedProvider || {})),
25
17
  };
26
18
  });
27
19
  }
28
- exports.default = {
29
- parse,
30
- dump
20
+ const guardianPhoneFactorSelectedProviderHandler = {
21
+ parse: parseAndDump,
22
+ dump: parseAndDump,
31
23
  };
24
+ exports.default = guardianPhoneFactorSelectedProviderHandler;
@@ -9,23 +9,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- function parse(context) {
12
+ function parseAndDump(context) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
14
  // nothing to do, set default if empty
15
15
  return {
16
- guardianPolicies: Object.assign({}, context.assets.guardianPolicies || {})
16
+ guardianPolicies: Object.assign({}, (context.assets.guardianPolicies || {})),
17
17
  };
18
18
  });
19
19
  }
20
- function dump(context) {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- // nothing to do, set default empty
23
- return {
24
- guardianPolicies: Object.assign({}, context.assets.guardianPolicies || {})
25
- };
26
- });
27
- }
28
- exports.default = {
29
- parse,
30
- dump
20
+ const guardianPoliciesHandler = {
21
+ parse: parseAndDump,
22
+ dump: parseAndDump,
31
23
  };
24
+ exports.default = guardianPoliciesHandler;
@@ -26,18 +26,19 @@ function parse(context) {
26
26
  hooks: [
27
27
  ...context.assets.hooks.map((hook) => {
28
28
  if (hook.script) {
29
+ //@ts-ignore TODO: understand why two arguments are passed when context.loadFile only accepts one
29
30
  hook.script = context.loadFile(hook.script, tools_1.constants.HOOKS_DIRECTORY);
30
31
  }
31
32
  hook.name = hook.name.toLowerCase().replace(/\s/g, '-');
32
33
  return Object.assign({}, hook);
33
- })
34
- ]
34
+ }),
35
+ ],
35
36
  };
36
37
  });
37
38
  }
38
39
  function dump(context) {
39
40
  return __awaiter(this, void 0, void 0, function* () {
40
- let hooks = [...context.assets.hooks || []];
41
+ let hooks = [...(context.assets.hooks || [])];
41
42
  if (hooks.length > 0) {
42
43
  // Create hooks folder
43
44
  const hooksFolder = path_1.default.join(context.basePath, 'hooks');
@@ -56,7 +57,8 @@ function dump(context) {
56
57
  return { hooks };
57
58
  });
58
59
  }
59
- exports.default = {
60
+ const hooksHandler = {
60
61
  parse,
61
- dump
62
+ dump,
62
63
  };
64
+ exports.default = hooksHandler;
@@ -27,7 +27,8 @@ const migrations_1 = __importDefault(require("./migrations"));
27
27
  const actions_1 = __importDefault(require("./actions"));
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 yamlHandlers = {
31
32
  rules: rules_1.default,
32
33
  hooks: hooks_1.default,
33
34
  rulesConfigs: rulesConfigs_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 = yamlHandlers;
@@ -21,7 +21,8 @@ function dump(context) {
21
21
  return { migrations: migrations || {} };
22
22
  });
23
23
  }
24
- exports.default = {
24
+ const migrationsHandler = {
25
25
  parse,
26
- dump
26
+ dump,
27
27
  };
28
+ exports.default = migrationsHandler;
@@ -13,7 +13,7 @@ function parse(context) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
14
  const { organizations } = context.assets;
15
15
  return {
16
- organizations: organizations
16
+ organizations: organizations,
17
17
  };
18
18
  });
19
19
  }
@@ -33,12 +33,13 @@ function dump(context) {
33
33
  });
34
34
  }
35
35
  return org;
36
- })
37
- ]
36
+ }),
37
+ ],
38
38
  };
39
39
  });
40
40
  }
41
- exports.default = {
41
+ const organizationsHandler = {
42
42
  parse,
43
- dump
43
+ dump,
44
44
  };
45
+ exports.default = organizationsHandler;
@@ -22,14 +22,14 @@ function parse(context) {
22
22
  return {};
23
23
  return {
24
24
  pages: [
25
- ...context.assets.pages.map((page) => (Object.assign(Object.assign({}, page), { html: page.html ? context.loadFile(page.html) : '' })))
26
- ]
25
+ ...context.assets.pages.map((page) => (Object.assign(Object.assign({}, page), { html: page.html ? context.loadFile(page.html) : '' }))),
26
+ ],
27
27
  };
28
28
  });
29
29
  }
30
30
  function dump(context) {
31
31
  return __awaiter(this, void 0, void 0, function* () {
32
- let pages = [...context.assets.pages || []];
32
+ let pages = [...(context.assets.pages || [])];
33
33
  if (pages.length > 0) {
34
34
  // Create Pages folder
35
35
  const pagesFolder = path_1.default.join(context.basePath, 'pages');
@@ -48,7 +48,8 @@ function dump(context) {
48
48
  return { pages };
49
49
  });
50
50
  }
51
- exports.default = {
51
+ const pagesHandler = {
52
52
  parse,
53
- dump
53
+ dump,
54
54
  };
55
+ exports.default = pagesHandler;
@@ -13,7 +13,7 @@ function parse(context) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
14
  // nothing to do, set default if empty
15
15
  return {
16
- resourceServers: context.assets.resourceServers
16
+ resourceServers: context.assets.resourceServers,
17
17
  };
18
18
  });
19
19
  }
@@ -21,11 +21,12 @@ function dump(context) {
21
21
  return __awaiter(this, void 0, void 0, function* () {
22
22
  // nothing to do, set default if empty
23
23
  return {
24
- resourceServers: [...context.assets.resourceServers || []]
24
+ resourceServers: [...(context.assets.resourceServers || [])],
25
25
  };
26
26
  });
27
27
  }
28
- exports.default = {
28
+ const resourceServersHandler = {
29
29
  parse,
30
- dump
30
+ dump,
31
31
  };
32
+ exports.default = resourceServersHandler;
@@ -13,7 +13,7 @@ function parse(context) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
14
  // nothing to do, set default empty
15
15
  return {
16
- roles: context.assets.roles
16
+ roles: context.assets.roles,
17
17
  };
18
18
  });
19
19
  }
@@ -27,12 +27,13 @@ function dump(context) {
27
27
  delete role.description;
28
28
  }
29
29
  return role;
30
- })
31
- ]
30
+ }),
31
+ ],
32
32
  };
33
33
  });
34
34
  }
35
- exports.default = {
35
+ const rolesHandler = {
36
36
  parse,
37
- dump
37
+ dump,
38
38
  };
39
+ exports.default = rolesHandler;
@@ -23,14 +23,14 @@ function parse(context) {
23
23
  return {};
24
24
  return {
25
25
  rules: [
26
- ...context.assets.rules.map((rule) => (Object.assign(Object.assign({}, rule), { script: context.loadFile(rule.script) })))
27
- ]
26
+ ...context.assets.rules.map((rule) => (Object.assign(Object.assign({}, rule), { script: context.loadFile(rule.script) }))),
27
+ ],
28
28
  };
29
29
  });
30
30
  }
31
31
  function dump(context) {
32
32
  return __awaiter(this, void 0, void 0, function* () {
33
- let rules = [...context.assets.rules || []];
33
+ let rules = [...(context.assets.rules || [])];
34
34
  if (rules.length > 0) {
35
35
  // Create Rules folder
36
36
  const rulesFolder = path_1.default.join(context.basePath, 'rules');
@@ -47,7 +47,8 @@ function dump(context) {
47
47
  return { rules };
48
48
  });
49
49
  }
50
- exports.default = {
50
+ const rulesHandler = {
51
51
  parse,
52
- dump
52
+ dump,
53
53
  };
54
+ exports.default = rulesHandler;
@@ -13,19 +13,20 @@ function parse(context) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
14
  // nothing to do, set default if empty
15
15
  return {
16
- rulesConfigs: context.assets.rulesConfigs
16
+ rulesConfigs: context.assets.rulesConfigs,
17
17
  };
18
18
  });
19
19
  }
20
- function dump() {
20
+ function dump(_context) {
21
21
  return __awaiter(this, void 0, void 0, function* () {
22
22
  // do not export rulesConfigs as its values cannot be extracted
23
23
  return {
24
- rulesConfigs: []
24
+ rulesConfigs: [],
25
25
  };
26
26
  });
27
27
  }
28
- exports.default = {
28
+ const rulesConfigsHandler = {
29
29
  parse,
30
- dump
30
+ dump,
31
31
  };
32
+ exports.default = rulesConfigsHandler;
@@ -21,6 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  const utils_1 = require("../../../utils");
24
+ const sessionDurationsToMinutes_1 = require("../../../sessionDurationsToMinutes");
24
25
  function parse(context) {
25
26
  return __awaiter(this, void 0, void 0, function* () {
26
27
  // Nothing to do
@@ -29,20 +30,21 @@ function parse(context) {
29
30
  /* eslint-disable camelcase */
30
31
  const _a = context.assets.tenant, { session_lifetime, idle_session_lifetime } = _a, tenant = __rest(_a, ["session_lifetime", "idle_session_lifetime"]);
31
32
  (0, utils_1.clearTenantFlags)(tenant);
33
+ const sessionDurations = (0, sessionDurationsToMinutes_1.sessionDurationsToMinutes)({ session_lifetime, idle_session_lifetime });
32
34
  return {
33
- 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))
35
+ tenant: Object.assign(Object.assign({}, tenant), sessionDurations),
34
36
  };
35
- /* eslint-enable camelcase */
36
37
  });
37
38
  }
38
39
  function dump(context) {
39
40
  return __awaiter(this, void 0, void 0, function* () {
40
- const tenant = Object.assign({}, context.assets.tenant || {});
41
+ const tenant = Object.assign({}, (context.assets.tenant || {}));
41
42
  (0, utils_1.clearTenantFlags)(tenant);
42
43
  return { tenant };
43
44
  });
44
45
  }
45
- exports.default = {
46
+ const tenantHandler = {
46
47
  parse,
47
- dump
48
+ dump,
48
49
  };
50
+ exports.default = tenantHandler;
@@ -15,7 +15,7 @@ function parse(context) {
15
15
  if (!context.assets.triggers)
16
16
  return {};
17
17
  return {
18
- triggers: context.assets.triggers
18
+ triggers: context.assets.triggers,
19
19
  };
20
20
  });
21
21
  }
@@ -26,11 +26,12 @@ function dump(context) {
26
26
  if (!triggers)
27
27
  return {};
28
28
  return {
29
- triggers: triggers
29
+ triggers: triggers,
30
30
  };
31
31
  });
32
32
  }
33
- exports.default = {
33
+ const triggersHandler = {
34
34
  parse,
35
- dump
35
+ dump,
36
36
  };
37
+ exports.default = triggersHandler;
@@ -20,27 +20,29 @@ const logger_1 = __importDefault(require("../../logger"));
20
20
  const utils_1 = require("../../utils");
21
21
  const handlers_1 = __importDefault(require("./handlers"));
22
22
  const readonly_1 = __importDefault(require("../../readonly"));
23
- class default_1 {
23
+ class YAMLContext {
24
24
  constructor(config, mgmtClient) {
25
25
  this.configFile = config.AUTH0_INPUT_FILE;
26
26
  this.config = config;
27
- this.mappings = config.AUTH0_KEYWORD_REPLACE_MAPPINGS;
27
+ this.mappings = config.AUTH0_KEYWORD_REPLACE_MAPPINGS || {};
28
28
  this.mgmtClient = mgmtClient;
29
+ //@ts-ignore because the assets property gets filled out throughout
30
+ this.assets = {};
29
31
  // Get excluded rules
30
- this.assets = {
31
- exclude: {
32
- rules: config.AUTH0_EXCLUDED_RULES || [],
33
- clients: config.AUTH0_EXCLUDED_CLIENTS || [],
34
- databases: config.AUTH0_EXCLUDED_DATABASES || [],
35
- connections: config.AUTH0_EXCLUDED_CONNECTIONS || [],
36
- resourceServers: config.AUTH0_EXCLUDED_RESOURCE_SERVERS || [],
37
- defaults: config.AUTH0_EXCLUDED_DEFAULTS || []
38
- }
32
+ this.assets.exclude = {
33
+ rules: config.AUTH0_EXCLUDED_RULES || [],
34
+ clients: config.AUTH0_EXCLUDED_CLIENTS || [],
35
+ databases: config.AUTH0_EXCLUDED_DATABASES || [],
36
+ connections: config.AUTH0_EXCLUDED_CONNECTIONS || [],
37
+ resourceServers: config.AUTH0_EXCLUDED_RESOURCE_SERVERS || [],
38
+ defaults: config.AUTH0_EXCLUDED_DEFAULTS || [],
39
39
  };
40
- this.basePath = config.AUTH0_BASE_PATH;
41
- if (!this.basePath) {
42
- this.basePath = (typeof configFile === 'object') ? process.cwd() : path_1.default.dirname(this.configFile);
43
- }
40
+ this.basePath = (() => {
41
+ if (!!config.AUTH0_BASE_PATH)
42
+ return config.AUTH0_BASE_PATH;
43
+ //@ts-ignore because this looks to be a bug, but do not want to introduce regression; more investigation needed
44
+ return typeof configFile === 'object' ? process.cwd() : path_1.default.dirname(this.configFile);
45
+ })();
44
46
  }
45
47
  loadFile(f) {
46
48
  let toLoad = path_1.default.join(this.basePath, f);
@@ -69,13 +71,12 @@ class default_1 {
69
71
  }
70
72
  // Run initial schema check to ensure valid YAML
71
73
  const auth0 = new tools_1.Auth0(this.mgmtClient, this.assets, (0, utils_1.toConfigFn)(this.config));
72
- yield auth0.validate('validate');
74
+ yield auth0.validate();
73
75
  // Allow handlers to process the assets such as loading files etc
74
76
  yield Promise.all(Object.entries(handlers_1.default).map(([name, handler]) => __awaiter(this, void 0, void 0, function* () {
75
77
  try {
76
78
  const parsed = yield handler.parse(this);
77
- Object.entries(parsed)
78
- .forEach(([k, v]) => {
79
+ Object.entries(parsed).forEach(([k, v]) => {
79
80
  this.assets[k] = v;
80
81
  });
81
82
  }
@@ -96,17 +97,25 @@ class default_1 {
96
97
  }
97
98
  catch (err) {
98
99
  const docUrl = 'https://auth0.com/docs/deploy/deploy-cli-tool/create-and-configure-the-deploy-cli-application#modify-deploy-cli-application-scopes';
99
- const extraMessage = err.message.startsWith('Insufficient scope') ? `\nSee ${docUrl} for more information` : '';
100
+ const extraMessage = err.message.startsWith('Insufficient scope')
101
+ ? `\nSee ${docUrl} for more information`
102
+ : '';
100
103
  throw new Error(`Problem loading tenant data from Auth0 ${err}${extraMessage}`);
101
104
  }
102
- yield Promise.all(Object.entries(handlers_1.default).map(([name, handler]) => __awaiter(this, void 0, void 0, function* () {
105
+ yield Promise.all(Object.entries(handlers_1.default)
106
+ .filter(([handlerName]) => {
107
+ const excludedAssetTypes = this.config.AUTH0_EXCLUDED || [];
108
+ return !excludedAssetTypes.includes(handlerName);
109
+ })
110
+ .map(([name, handler]) => __awaiter(this, void 0, void 0, function* () {
103
111
  try {
104
112
  const data = yield handler.dump(this);
105
113
  if (data) {
106
114
  logger_1.default.info(`Exporting ${name}`);
107
- Object.entries(data)
108
- .forEach(([k, v]) => {
109
- this.assets[k] = Array.isArray(v) ? v.map(utils_1.formatResults).sort(utils_1.recordsSorter) : (0, utils_1.formatResults)(v);
115
+ Object.entries(data).forEach(([k, v]) => {
116
+ this.assets[k] = Array.isArray(v)
117
+ ? v.map(utils_1.formatResults).sort(utils_1.recordsSorter)
118
+ : (0, utils_1.formatResults)(v);
110
119
  });
111
120
  }
112
121
  }
@@ -130,4 +139,4 @@ class default_1 {
130
139
  });
131
140
  }
132
141
  }
133
- exports.default = default_1;
142
+ exports.default = YAMLContext;
package/lib/index.js CHANGED
@@ -15,13 +15,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  const global_agent_1 = require("global-agent");
17
17
  const args_1 = require("./args");
18
- const commands_1 = __importDefault(require("./commands"));
19
18
  const logger_1 = __importDefault(require("./logger"));
20
19
  const tools_1 = __importDefault(require("./tools"));
20
+ const import_1 = __importDefault(require("./commands/import"));
21
+ const export_1 = __importDefault(require("./commands/export"));
21
22
  function run(params) {
22
23
  return __awaiter(this, void 0, void 0, function* () {
23
24
  // Run command
24
- const cmd = commands_1.default[params._[0]];
25
+ const command = params._[0];
25
26
  const proxy = params.proxy_url;
26
27
  if (proxy) {
27
28
  const MAJOR_NODEJS_VERSION = parseInt(process.version.slice(1).split('.')[0], 10);
@@ -32,9 +33,14 @@ function run(params) {
32
33
  process.env.GLOBAL_AGENT_HTTP_PROXY = proxy;
33
34
  (0, global_agent_1.bootstrap)();
34
35
  }
35
- logger_1.default.debug(`Start command ${params._[0]}`);
36
- yield cmd(params);
37
- logger_1.default.debug(`Finished command ${params._[0]}`);
36
+ logger_1.default.debug(`Start command ${command}`);
37
+ if (['deploy', 'import'].includes(command) && 'input_file' in params) {
38
+ yield (0, import_1.default)(params);
39
+ }
40
+ if (['dump', 'export'].includes(command) && 'output_folder' in params) {
41
+ yield (0, export_1.default)(params);
42
+ }
43
+ logger_1.default.debug(`Finished command ${command}`);
38
44
  });
39
45
  }
40
46
  // Only run if from command line
@@ -42,8 +48,6 @@ if (require.main === module) {
42
48
  // Load cli params
43
49
  const params = (0, args_1.getParams)();
44
50
  logger_1.default.debug('Starting Auth0 Deploy CLI Tool');
45
- // Set log level
46
- logger_1.default.transports.console.level = params.level;
47
51
  if (params.debug) {
48
52
  logger_1.default.transports.console.level = 'debug';
49
53
  // Set for tools
@@ -53,15 +57,16 @@ if (require.main === module) {
53
57
  run(params)
54
58
  .then(() => process.exit(0))
55
59
  .catch((error) => {
60
+ const command = params._[0];
56
61
  if (error.type || error.stage) {
57
- logger_1.default.error(`Problem running command ${params._[0]} during stage ${error.stage} when processing type ${error.type}`);
62
+ logger_1.default.error(`Problem running command ${command} during stage ${error.stage} when processing type ${error.type}`);
58
63
  }
59
64
  else {
60
- logger_1.default.error(`Problem running command ${params._[0]}`);
65
+ logger_1.default.error(`Problem running command ${command}`);
61
66
  }
62
67
  const msg = error.message || error.toString();
63
68
  logger_1.default.error(msg);
64
- if (process.env.AUTH0_DEBUG === 'true') {
69
+ if (process.env.AUTH0_DEBUG === 'true' && error.stack) {
65
70
  logger_1.default.debug(error.stack);
66
71
  }
67
72
  if (typeof msg === 'string' && msg.includes('Payload validation error')) {
@@ -72,9 +77,9 @@ if (require.main === module) {
72
77
  }
73
78
  // Export commands to be used programmatically
74
79
  module.exports = {
75
- deploy: commands_1.default.import,
76
- dump: commands_1.default.export,
77
- import: commands_1.default.import,
78
- export: commands_1.default.export,
79
- tools: tools_1.default
80
+ deploy: import_1.default,
81
+ dump: export_1.default,
82
+ import: import_1.default,
83
+ export: export_1.default,
84
+ tools: tools_1.default,
80
85
  };
package/lib/logger.js CHANGED
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const winston_1 = __importDefault(require("winston"));
7
+ //@ts-ignore because used version of Winston still supports emitErrs property
7
8
  winston_1.default.emitErrs = true;
8
9
  const log = new winston_1.default.Logger({
9
10
  transports: [
@@ -12,9 +13,9 @@ const log = new winston_1.default.Logger({
12
13
  level: process.env.AUTH0_LOG || 'info',
13
14
  handleExceptions: true,
14
15
  json: false,
15
- colorize: true
16
- })
16
+ colorize: true,
17
+ }),
17
18
  ],
18
- exitOnError: false
19
+ exitOnError: false,
19
20
  });
20
21
  exports.default = log;
package/lib/readonly.js CHANGED
@@ -6,24 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const dot_prop_1 = __importDefault(require("dot-prop"));
7
7
  const lodash_1 = __importDefault(require("lodash"));
8
8
  // Filter out known read only fields during dump
9
- const readOnly = {
10
- guardianFactors: [
11
- 'trial_expired'
12
- ],
13
- connections: [
14
- 'provisioning_ticket_url',
15
- 'realms'
16
- ],
17
- databases: [
18
- 'options.configuration'
19
- ],
9
+ const readOnlyFields = {
10
+ guardianFactors: ['trial_expired'],
11
+ connections: ['provisioning_ticket_url', 'realms'],
12
+ databases: ['options.configuration'],
20
13
  tenant: [
21
14
  'sandbox_version',
22
15
  'sandbox_versions_available',
23
16
  'flags.allow_changing_enable_sso',
24
17
  'flags.enable_sso',
25
18
  'flags.disable_impersonation',
26
- 'flags.remove_stale_idp_attributes'
19
+ 'flags.remove_stale_idp_attributes',
27
20
  ],
28
21
  clients: [
29
22
  'client_secret',
@@ -33,11 +26,11 @@ const readOnly = {
33
26
  'tenant',
34
27
  'custom_login_page_preview',
35
28
  'config_route',
36
- 'owners'
37
- ]
29
+ 'owners',
30
+ ],
38
31
  };
39
32
  function getExcludedFields(config) {
40
- const strippedFields = Object.assign({}, readOnly);
33
+ const strippedFields = Object.assign({}, readOnlyFields);
41
34
  let { EXCLUDED_PROPS: excluded, INCLUDED_PROPS: included } = config;
42
35
  if (typeof excluded !== 'object')
43
36
  excluded = {};
@@ -45,7 +38,7 @@ function getExcludedFields(config) {
45
38
  included = {};
46
39
  Object.entries(excluded).forEach(([name, fields]) => {
47
40
  // Do not allow same field to be included and excluded at the same time
48
- const intersections = fields.filter((field) => included[name] && included[name].includes(field));
41
+ const intersections = fields.filter((field) => included && included[name] && included[name].includes(field));
49
42
  if (intersections.length > 0) {
50
43
  throw new Error(`EXCLUDED_PROPS should NOT have any intersections with INCLUDED_PROPS. Intersections found: ${name}: ${intersections.join(', ')}`);
51
44
  }
@@ -71,9 +64,11 @@ function cleanAssets(assets, config) {
71
64
  if (!obj)
72
65
  return;
73
66
  if (Array.isArray(obj)) {
67
+ //@ts-ignore because `message_types` and `policies` on guardianPhoneFactorMessageTypes and guardianPolicies don't adhere to the expect types
74
68
  cleaned[name] = obj.map((o) => deleteKeys(o, fields));
75
69
  }
76
70
  else {
71
+ //@ts-ignore because `message_types` and `policies` on guardianPhoneFactorMessageTypes and guardianPolicies don't adhere to the expect types
77
72
  cleaned[name] = deleteKeys(cleaned[name], fields);
78
73
  }
79
74
  });