auth0-deploy-cli 7.4.0 → 7.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/.circleci/config.yml +15 -0
  2. package/.eslintrc +66 -17
  3. package/.github/CODEOWNERS +1 -0
  4. package/.husky/pre-commit +2 -0
  5. package/CHANGELOG.md +27 -2
  6. package/lib/args.js +94 -81
  7. package/lib/commands/export.js +54 -78
  8. package/lib/commands/import.js +46 -70
  9. package/lib/commands/index.js +11 -20
  10. package/lib/configFactory.js +19 -27
  11. package/lib/context/defaults.js +18 -41
  12. package/lib/context/directory/handlers/actions.js +77 -107
  13. package/lib/context/directory/handlers/attackProtection.js +59 -0
  14. package/lib/context/directory/handlers/clientGrants.js +45 -54
  15. package/lib/context/directory/handlers/clients.js +60 -79
  16. package/lib/context/directory/handlers/connections.js +65 -89
  17. package/lib/context/directory/handlers/databases.js +91 -123
  18. package/lib/context/directory/handlers/emailProvider.js +46 -57
  19. package/lib/context/directory/handlers/emailTemplates.js +67 -80
  20. package/lib/context/directory/handlers/guardianFactorProviders.js +41 -49
  21. package/lib/context/directory/handlers/guardianFactorTemplates.js +41 -49
  22. package/lib/context/directory/handlers/guardianFactors.js +41 -49
  23. package/lib/context/directory/handlers/guardianPhoneFactorMessageTypes.js +40 -50
  24. package/lib/context/directory/handlers/guardianPhoneFactorSelectedProvider.js +40 -50
  25. package/lib/context/directory/handlers/guardianPolicies.js +40 -50
  26. package/lib/context/directory/handlers/hooks.js +55 -70
  27. package/lib/context/directory/handlers/index.js +53 -123
  28. package/lib/context/directory/handlers/migrations.js +36 -41
  29. package/lib/context/directory/handlers/organizations.js +54 -69
  30. package/lib/context/directory/handlers/pages.js +72 -86
  31. package/lib/context/directory/handlers/resourceServers.js +41 -49
  32. package/lib/context/directory/handlers/roles.js +49 -62
  33. package/lib/context/directory/handlers/rules.js +52 -68
  34. package/lib/context/directory/handlers/rulesConfigs.js +33 -32
  35. package/lib/context/directory/handlers/tenant.js +52 -47
  36. package/lib/context/directory/handlers/triggers.js +39 -54
  37. package/lib/context/directory/index.js +113 -101
  38. package/lib/context/index.js +96 -105
  39. package/lib/context/yaml/handlers/actions.js +71 -88
  40. package/lib/context/yaml/handlers/attackProtection.js +29 -0
  41. package/lib/context/yaml/handlers/clientGrants.js +36 -29
  42. package/lib/context/yaml/handlers/clients.js +61 -76
  43. package/lib/context/yaml/handlers/connections.js +76 -103
  44. package/lib/context/yaml/handlers/databases.js +64 -79
  45. package/lib/context/yaml/handlers/emailProvider.js +33 -30
  46. package/lib/context/yaml/handlers/emailTemplates.js +45 -54
  47. package/lib/context/yaml/handlers/guardianFactorProviders.js +27 -18
  48. package/lib/context/yaml/handlers/guardianFactorTemplates.js +27 -18
  49. package/lib/context/yaml/handlers/guardianFactors.js +27 -18
  50. package/lib/context/yaml/handlers/guardianPhoneFactorMessageTypes.js +27 -20
  51. package/lib/context/yaml/handlers/guardianPhoneFactorSelectedProvider.js +27 -20
  52. package/lib/context/yaml/handlers/guardianPolicies.js +27 -20
  53. package/lib/context/yaml/handlers/hooks.js +57 -67
  54. package/lib/context/yaml/handlers/index.js +53 -123
  55. package/lib/context/yaml/handlers/migrations.js +23 -24
  56. package/lib/context/yaml/handlers/organizations.js +40 -38
  57. package/lib/context/yaml/handlers/pages.js +49 -58
  58. package/lib/context/yaml/handlers/resourceServers.js +27 -18
  59. package/lib/context/yaml/handlers/roles.js +34 -24
  60. package/lib/context/yaml/handlers/rules.js +48 -58
  61. package/lib/context/yaml/handlers/rulesConfigs.js +27 -18
  62. package/lib/context/yaml/handlers/tenant.js +44 -30
  63. package/lib/context/yaml/handlers/triggers.js +32 -23
  64. package/lib/context/yaml/index.js +127 -142
  65. package/lib/index.js +73 -79
  66. package/lib/logger.js +18 -22
  67. package/lib/readonly.js +74 -66
  68. package/lib/tools/ValidationError.js +8 -13
  69. package/lib/tools/auth0/client.js +143 -133
  70. package/lib/tools/auth0/handlers/actions.js +231 -243
  71. package/lib/tools/auth0/handlers/attackProtection.js +86 -0
  72. package/lib/tools/auth0/handlers/branding.js +47 -46
  73. package/lib/tools/auth0/handlers/clientGrants.js +118 -116
  74. package/lib/tools/auth0/handlers/clients.js +72 -90
  75. package/lib/tools/auth0/handlers/connections.js +150 -118
  76. package/lib/tools/auth0/handlers/databases.js +127 -124
  77. package/lib/tools/auth0/handlers/default.js +186 -189
  78. package/lib/tools/auth0/handlers/emailProvider.js +67 -78
  79. package/lib/tools/auth0/handlers/emailTemplates.js +116 -92
  80. package/lib/tools/auth0/handlers/guardianFactorProviders.js +66 -81
  81. package/lib/tools/auth0/handlers/guardianFactorTemplates.js +60 -71
  82. package/lib/tools/auth0/handlers/guardianFactors.js +56 -63
  83. package/lib/tools/auth0/handlers/guardianPhoneFactorMessageTypes.js +80 -79
  84. package/lib/tools/auth0/handlers/guardianPhoneFactorSelectedProvider.js +77 -76
  85. package/lib/tools/auth0/handlers/guardianPolicies.js +59 -62
  86. package/lib/tools/auth0/handlers/hooks.js +201 -227
  87. package/lib/tools/auth0/handlers/index.js +53 -111
  88. package/lib/tools/auth0/handlers/migrations.js +99 -79
  89. package/lib/tools/auth0/handlers/organizations.js +225 -247
  90. package/lib/tools/auth0/handlers/pages.js +116 -154
  91. package/lib/tools/auth0/handlers/prompts.js +47 -46
  92. package/lib/tools/auth0/handlers/resourceServers.js +88 -112
  93. package/lib/tools/auth0/handlers/roles.js +203 -220
  94. package/lib/tools/auth0/handlers/rules.js +168 -189
  95. package/lib/tools/auth0/handlers/rulesConfigs.js +54 -63
  96. package/lib/tools/auth0/handlers/tenant.js +88 -64
  97. package/lib/tools/auth0/handlers/triggers.js +126 -126
  98. package/lib/tools/auth0/index.js +92 -85
  99. package/lib/tools/auth0/schema.js +39 -31
  100. package/lib/tools/constants.js +111 -21
  101. package/lib/tools/deploy.js +35 -32
  102. package/lib/tools/index.js +19 -32
  103. package/lib/tools/logger.js +11 -12
  104. package/lib/tools/utils.js +255 -282
  105. package/lib/utils.js +167 -190
  106. package/package.json +10 -16
  107. package/tsconfig.json +17 -0
  108. package/typescript-migration-progress.sh +22 -0
  109. package/.babelrc +0 -17
  110. package/.nyc_output/597f412e-a239-4319-ad5b-ddb87fc39e67.json +0 -1
  111. package/.nyc_output/processinfo/597f412e-a239-4319-ad5b-ddb87fc39e67.json +0 -1
  112. package/.nyc_output/processinfo/index.json +0 -1
@@ -1,147 +1,157 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = pagedClient;
7
-
8
- var _promisePoolExecutor = require("promise-pool-executor");
9
-
10
- var _lodash = require("lodash");
11
-
12
- var _lodash2 = _interopRequireDefault(_lodash);
13
-
14
- var _utils = require("../utils");
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const promise_pool_executor_1 = require("promise-pool-executor");
27
+ const lodash_1 = __importDefault(require("lodash"));
28
+ const utils_1 = require("../utils");
18
29
  const API_CONCURRENCY = 3;
30
+ // To ensure a complete deployment, limit the API requests generated to be 80% of the capacity
31
+ // https://auth0.com/docs/policies/rate-limits#management-api-v2
19
32
  const API_FREQUENCY_PER_SECOND = 8;
20
33
  const MAX_PAGE_SIZE = 100;
21
-
22
34
  function getEntity(rsp) {
23
- const found = Object.values(rsp).filter(a => Array.isArray(a));
24
-
25
- if (found.length === 1) {
26
- return found[0];
27
- }
28
-
29
- throw new Error('There was an error trying to find the entity within paginate');
35
+ const found = Object.values(rsp).filter((a) => Array.isArray(a));
36
+ if (found.length === 1) {
37
+ return found[0];
38
+ }
39
+ throw new Error('There was an error trying to find the entity within paginate');
30
40
  }
31
-
32
41
  function checkpointPaginator(client, target, name) {
33
- return async function (...args) {
34
- const data = [];
35
-
36
- const {
37
- checkpoint,
38
- ...newArgs
39
- } = _lodash2.default.cloneDeep(args[0]);
40
-
41
- const {
42
- total
43
- } = await client.pool.addSingleTask({
44
- data: newArgs,
45
- generator: requestArgs => target[name](requestArgs)
46
- }).promise();
47
- let done = false;
48
- newArgs.take = 50;
49
-
50
- while (!done) {
51
- const rsp = await client.pool.addSingleTask({
52
- data: newArgs,
53
- generator: requestArgs => target[name](requestArgs)
54
- }).promise();
55
- data.push(...getEntity(rsp));
56
-
57
- if (!rsp.next) {
58
- done = true;
59
- } else {
60
- newArgs.from = rsp.next;
61
- }
62
- }
63
-
64
- if (data.length !== total) {
65
- throw new Error('Fail to load data from tenant');
66
- }
67
-
68
- return data;
69
- };
42
+ return function (...args) {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ const data = [];
45
+ // remove the _checkpoint_ flag
46
+ const _a = lodash_1.default.cloneDeep(args[0]), { checkpoint } = _a, newArgs = __rest(_a, ["checkpoint"]);
47
+ // fetch the total to validate records match
48
+ const { total } = yield client.pool
49
+ .addSingleTask({
50
+ data: newArgs,
51
+ generator: (requestArgs) => target[name](requestArgs)
52
+ })
53
+ .promise();
54
+ let done = false;
55
+ // use checkpoint pagination to allow fetching 1000+ results
56
+ newArgs.take = 50;
57
+ while (!done) {
58
+ const rsp = yield client.pool
59
+ .addSingleTask({
60
+ data: newArgs,
61
+ generator: (requestArgs) => target[name](requestArgs)
62
+ })
63
+ .promise();
64
+ data.push(...getEntity(rsp));
65
+ if (!rsp.next) {
66
+ done = true;
67
+ }
68
+ else {
69
+ newArgs.from = rsp.next;
70
+ }
71
+ }
72
+ if (data.length !== total) {
73
+ throw new Error('Fail to load data from tenant');
74
+ }
75
+ return data;
76
+ });
77
+ };
70
78
  }
71
-
72
79
  function pagePaginator(client, target, name) {
73
- return async function (...args) {
74
- const data = [];
75
- const newArgs = [...args];
76
- newArgs[0] = { ...newArgs[0],
77
- page: 0
80
+ return function (...args) {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ // Where the entity data will be collected
83
+ const data = [];
84
+ // Create new args and inject the properties we require for pagination automation
85
+ const newArgs = [...args];
86
+ newArgs[0] = Object.assign(Object.assign({}, newArgs[0]), { page: 0 });
87
+ // Grab data we need from the request then delete the keys as they are only needed for this automation function to work
88
+ const perPage = newArgs[0].per_page || MAX_PAGE_SIZE;
89
+ newArgs[0].per_page = perPage;
90
+ delete newArgs[0].paginate;
91
+ // Run the first request to get the total number of entity items
92
+ const rsp = yield client.pool
93
+ .addSingleTask({
94
+ data: lodash_1.default.cloneDeep(newArgs),
95
+ generator: (pageArgs) => target[name](...pageArgs)
96
+ })
97
+ .promise();
98
+ data.push(...getEntity(rsp));
99
+ const total = rsp.total || 0;
100
+ const pagesLeft = Math.ceil(total / perPage) - 1;
101
+ // Setup pool to get the rest of the pages
102
+ if (pagesLeft > 0) {
103
+ const pages = yield client.pool
104
+ .addEachTask({
105
+ data: Array.from(Array(pagesLeft).keys()),
106
+ generator: (page) => {
107
+ const pageArgs = lodash_1.default.cloneDeep(newArgs);
108
+ pageArgs[0].page = page + 1;
109
+ return target[name](...pageArgs).then((r) => getEntity(r));
110
+ }
111
+ })
112
+ .promise();
113
+ data.push(...(0, utils_1.flatten)(pages));
114
+ if (data.length !== total) {
115
+ throw new Error('Fail to load data from tenant');
116
+ }
117
+ }
118
+ return data;
119
+ });
78
120
  };
79
- const perPage = newArgs[0].per_page || MAX_PAGE_SIZE;
80
- newArgs[0].per_page = perPage;
81
- delete newArgs[0].paginate;
82
- const rsp = await client.pool.addSingleTask({
83
- data: _lodash2.default.cloneDeep(newArgs),
84
- generator: pageArgs => target[name](...pageArgs)
85
- }).promise();
86
- data.push(...getEntity(rsp));
87
- const total = rsp.total || 0;
88
- const pagesLeft = Math.ceil(total / perPage) - 1;
89
-
90
- if (pagesLeft > 0) {
91
- const pages = await client.pool.addEachTask({
92
- data: Array.from(Array(pagesLeft).keys()),
93
- generator: page => {
94
- const pageArgs = _lodash2.default.cloneDeep(newArgs);
95
-
96
- pageArgs[0].page = page + 1;
97
- return target[name](...pageArgs).then(r => getEntity(r));
98
- }
99
- }).promise();
100
- data.push(...(0, _utils.flatten)(pages));
101
-
102
- if (data.length !== total) {
103
- throw new Error('Fail to load data from tenant');
104
- }
105
- }
106
-
107
- return data;
108
- };
109
121
  }
110
-
122
+ // Warp around a <resource>Manager and detect when requesting specific pages to return all
111
123
  function pagedManager(client, manager) {
112
- return new Proxy(manager, {
113
- get: function (target, name, receiver) {
114
- if (name === 'getAll') {
115
- return async function (...args) {
116
- switch (true) {
117
- case args[0] && typeof args[0] === 'object' && args[0].checkpoint:
118
- return checkpointPaginator(client, target, name)(...args);
119
-
120
- case args[0] && typeof args[0] === 'object' && args[0].paginate:
121
- return pagePaginator(client, target, name)(...args);
122
-
123
- default:
124
- return target[name](...args);
125
- }
126
- };
127
- }
128
-
129
- const nestedManager = Reflect.get(target, name, receiver);
130
-
131
- if (typeof nestedManager === 'object' && nestedManager !== null) {
132
- return pagedManager(client, nestedManager);
133
- }
134
-
135
- return nestedManager;
136
- }
137
- });
124
+ return new Proxy(manager, {
125
+ get: function (target, name, receiver) {
126
+ if (name === 'getAll') {
127
+ return function (...args) {
128
+ return __awaiter(this, void 0, void 0, function* () {
129
+ switch (true) {
130
+ case args[0] && typeof args[0] === 'object' && args[0].checkpoint:
131
+ return checkpointPaginator(client, target, name)(...args);
132
+ case args[0] && typeof args[0] === 'object' && args[0].paginate:
133
+ return pagePaginator(client, target, name)(...args);
134
+ default:
135
+ return target[name](...args);
136
+ }
137
+ });
138
+ };
139
+ }
140
+ const nestedManager = Reflect.get(target, name, receiver);
141
+ if (typeof nestedManager === 'object' && nestedManager !== null) {
142
+ return pagedManager(client, nestedManager);
143
+ }
144
+ return nestedManager;
145
+ }
146
+ });
138
147
  }
139
-
148
+ // Warp around the ManagementClient and detect when requesting specific pages to return all
140
149
  function pagedClient(client) {
141
- client.pool = new _promisePoolExecutor.PromisePoolExecutor({
142
- concurrencyLimit: API_CONCURRENCY,
143
- frequencyLimit: API_FREQUENCY_PER_SECOND,
144
- frequencyWindow: 1000
145
- });
146
- return pagedManager(client, client);
147
- }
150
+ client.pool = new promise_pool_executor_1.PromisePoolExecutor({
151
+ concurrencyLimit: API_CONCURRENCY,
152
+ frequencyLimit: API_FREQUENCY_PER_SECOND,
153
+ frequencyWindow: 1000 // 1 sec
154
+ });
155
+ return pagedManager(client, client);
156
+ }
157
+ exports.default = pagedClient;