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,98 +1,122 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
5
17
  });
6
- exports.default = exports.schema = exports.supportedTemplates = undefined;
7
-
8
- var _dec, _class;
9
-
10
- var _default = require("./default");
11
-
12
- var _default2 = _interopRequireDefault(_default);
13
-
14
- var _constants = require("../../constants");
15
-
16
- var _constants2 = _interopRequireDefault(_constants);
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
- function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
21
-
22
- const supportedTemplates = exports.supportedTemplates = _constants2.default.EMAIL_TEMPLATES_NAMES.filter(p => p.includes('.json')).map(p => p.replace('.json', ''));
23
-
24
- const schema = exports.schema = {
25
- type: 'array',
26
- items: {
27
- type: 'object',
28
- properties: {
29
- template: {
30
- type: 'string',
31
- enum: supportedTemplates
32
- },
33
- body: {
34
- type: 'string',
35
- default: ''
36
- }
37
- },
38
- required: ['template']
39
- }
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
40
30
  };
41
- let EmailTemplateHandler = (_dec = (0, _default.order)('60'), (_class = class EmailTemplateHandler extends _default2.default {
42
- constructor(options) {
43
- super({ ...options,
44
- type: 'emailTemplates',
45
- id: 'template'
31
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
32
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
33
+ return new (P || (P = Promise))(function (resolve, reject) {
34
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
35
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
36
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
37
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
46
38
  });
47
- }
48
-
49
- async getType() {
50
- const emailTemplates = [];
51
- await Promise.all(_constants2.default.EMAIL_TEMPLATES_TYPES.map(async name => {
52
- try {
53
- const template = await this.client.emailTemplates.get({
54
- name
39
+ };
40
+ var __importDefault = (this && this.__importDefault) || function (mod) {
41
+ return (mod && mod.__esModule) ? mod : { "default": mod };
42
+ };
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.schema = exports.supportedTemplates = void 0;
45
+ const default_1 = __importStar(require("./default"));
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', ''));
50
+ exports.schema = {
51
+ type: 'array',
52
+ items: {
53
+ type: 'object',
54
+ properties: {
55
+ template: { type: 'string', enum: exports.supportedTemplates },
56
+ body: { type: 'string', default: '' }
57
+ },
58
+ required: ['template']
59
+ }
60
+ };
61
+ class EmailTemplateHandler extends default_1.default {
62
+ constructor(options) {
63
+ super(Object.assign(Object.assign({}, options), { type: 'emailTemplates', id: 'template' }));
64
+ }
65
+ getType() {
66
+ 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* () {
69
+ try {
70
+ const template = yield this.client.emailTemplates.get({ name });
71
+ emailTemplates.push(template);
72
+ }
73
+ catch (err) {
74
+ // Ignore if not found, else throw error
75
+ if (err.statusCode !== 404) {
76
+ throw err;
77
+ }
78
+ }
79
+ })));
80
+ return emailTemplates;
81
+ });
82
+ }
83
+ updateOrCreate(emailTemplate) {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ try {
86
+ const params = { name: emailTemplate[this.id] };
87
+ const updated = yield this.client.emailTemplates.update(params, emailTemplate);
88
+ delete updated.body;
89
+ this.didUpdate(updated);
90
+ this.updated += 1;
91
+ }
92
+ catch (err) {
93
+ if (err.statusCode === 404) {
94
+ // Create if it does not exist
95
+ const created = yield this.client.emailTemplates.create(emailTemplate);
96
+ delete created.body;
97
+ this.didCreate(created);
98
+ this.created += 1;
99
+ }
100
+ else {
101
+ throw err;
102
+ }
103
+ }
104
+ });
105
+ }
106
+ // Run after email provider changes
107
+ processChanges(assets) {
108
+ return __awaiter(this, void 0, void 0, function* () {
109
+ const { emailTemplates } = assets;
110
+ // Do nothing if not set
111
+ if (!emailTemplates || !emailTemplates.length)
112
+ return;
113
+ yield Promise.all(emailTemplates.map((emailTemplate) => __awaiter(this, void 0, void 0, function* () {
114
+ yield this.updateOrCreate(emailTemplate);
115
+ })));
55
116
  });
56
- emailTemplates.push(template);
57
- } catch (err) {
58
- if (err.statusCode !== 404) {
59
- throw err;
60
- }
61
- }
62
- }));
63
- return emailTemplates;
64
- }
65
-
66
- async updateOrCreate(emailTemplate) {
67
- try {
68
- const params = {
69
- name: emailTemplate[this.id]
70
- };
71
- const updated = await this.client.emailTemplates.update(params, emailTemplate);
72
- delete updated.body;
73
- this.didUpdate(updated);
74
- this.updated += 1;
75
- } catch (err) {
76
- if (err.statusCode === 404) {
77
- const created = await this.client.emailTemplates.create(emailTemplate);
78
- delete created.body;
79
- this.didCreate(created);
80
- this.created += 1;
81
- } else {
82
- throw err;
83
- }
84
117
  }
85
- }
86
-
87
- async processChanges(assets) {
88
- const {
89
- emailTemplates
90
- } = assets;
91
- if (!emailTemplates || !emailTemplates.length) return;
92
- await Promise.all(emailTemplates.map(async emailTemplate => {
93
- await this.updateOrCreate(emailTemplate);
94
- }));
95
- }
96
-
97
- }, (_applyDecoratedDescriptor(_class.prototype, "processChanges", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "processChanges"), _class.prototype)), _class));
98
- exports.default = EmailTemplateHandler;
118
+ }
119
+ __decorate([
120
+ (0, default_1.order)('60')
121
+ ], EmailTemplateHandler.prototype, "processChanges", null);
122
+ exports.default = EmailTemplateHandler;
@@ -1,86 +1,71 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.schema = undefined;
7
-
8
- var _default = require("./default");
9
-
10
- var _default2 = _interopRequireDefault(_default);
11
-
12
- var _constants = require("../../constants");
13
-
14
- var _constants2 = _interopRequireDefault(_constants);
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- const mappings = Object.entries(_constants2.default.GUARDIAN_FACTOR_PROVIDERS).reduce((accum, [name, providers]) => {
19
- providers.forEach(p => {
20
- accum.push({
21
- name,
22
- provider: p
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());
23
9
  });
24
- });
25
- return accum;
26
- }, []);
27
- const schema = exports.schema = {
28
- type: 'array',
29
- items: {
30
- type: 'object',
31
- properties: {
32
- name: {
33
- type: 'string',
34
- enum: _constants2.default.GUARDIAN_FACTORS
35
- },
36
- provider: {
37
- type: 'string',
38
- enum: mappings.map(p => p.provider)
39
- }
40
- },
41
- required: ['name', 'provider']
42
- }
43
10
  };
44
-
45
- class GuardianFactorProvidersHandler extends _default2.default {
46
- constructor(options) {
47
- super({ ...options,
48
- type: 'guardianFactorProviders',
49
- id: 'name'
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.schema = void 0;
16
+ const default_1 = __importDefault(require("./default"));
17
+ const constants_1 = __importDefault(require("../../constants"));
18
+ const mappings = Object.entries(constants_1.default.GUARDIAN_FACTOR_PROVIDERS).reduce((accum, [name, providers]) => {
19
+ providers.forEach((p) => {
20
+ accum.push({ name, provider: p });
50
21
  });
51
- }
52
-
53
- async getType() {
54
- if (this.existing) return this.existing;
55
- const data = await Promise.all(mappings.map(async m => {
56
- const provider = await this.client.guardian.getFactorProvider(m);
57
- return { ...m,
58
- ...provider
59
- };
60
- }));
61
- return data.filter(d => Object.keys(d).length > 2);
62
- }
63
-
64
- async processChanges(assets) {
65
- const {
66
- guardianFactorProviders
67
- } = assets;
68
- if (!guardianFactorProviders || !guardianFactorProviders.length) return;
69
- await Promise.all(guardianFactorProviders.map(async factorProvider => {
70
- const data = { ...factorProvider
71
- };
72
- const params = {
73
- name: factorProvider.name,
74
- provider: factorProvider.provider
75
- };
76
- delete data.name;
77
- delete data.provider;
78
- await this.client.guardian.updateFactorProvider(params, data);
79
- this.didUpdate(params);
80
- this.updated += 1;
81
- }));
82
- }
83
-
22
+ return accum;
23
+ }, []);
24
+ exports.schema = {
25
+ type: 'array',
26
+ items: {
27
+ type: 'object',
28
+ properties: {
29
+ name: { type: 'string', enum: constants_1.default.GUARDIAN_FACTORS },
30
+ provider: { type: 'string', enum: mappings.map((p) => p.provider) }
31
+ },
32
+ required: ['name', 'provider']
33
+ }
34
+ };
35
+ class GuardianFactorProvidersHandler extends default_1.default {
36
+ constructor(options) {
37
+ super(Object.assign(Object.assign({}, options), { type: 'guardianFactorProviders', id: 'name' }));
38
+ }
39
+ getType() {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ if (this.existing)
42
+ return this.existing;
43
+ const data = yield Promise.all(mappings.map((m) => __awaiter(this, void 0, void 0, function* () {
44
+ const provider = yield this.client.guardian.getFactorProvider(m);
45
+ return Object.assign(Object.assign({}, m), provider);
46
+ })));
47
+ // Filter out empty, should have more then 2 keys (name, provider)
48
+ return data.filter((d) => Object.keys(d).length > 2);
49
+ });
50
+ }
51
+ processChanges(assets) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ // No API to delete or create guardianFactorProviders, we can only update.
54
+ const { guardianFactorProviders } = assets;
55
+ // Do nothing if not set
56
+ if (!guardianFactorProviders || !guardianFactorProviders.length)
57
+ return;
58
+ // Process each factor
59
+ yield Promise.all(guardianFactorProviders.map((factorProvider) => __awaiter(this, void 0, void 0, function* () {
60
+ const data = Object.assign({}, factorProvider);
61
+ const params = { name: factorProvider.name, provider: factorProvider.provider };
62
+ delete data.name;
63
+ delete data.provider;
64
+ yield this.client.guardian.updateFactorProvider(params, data);
65
+ this.didUpdate(params);
66
+ this.updated += 1;
67
+ })));
68
+ });
69
+ }
84
70
  }
85
-
86
- exports.default = GuardianFactorProvidersHandler;
71
+ exports.default = GuardianFactorProvidersHandler;
@@ -1,74 +1,63 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.schema = undefined;
7
-
8
- var _default = require("./default");
9
-
10
- var _default2 = _interopRequireDefault(_default);
11
-
12
- var _constants = require("../../constants");
13
-
14
- var _constants2 = _interopRequireDefault(_constants);
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- const schema = exports.schema = {
19
- type: 'array',
20
- items: {
21
- type: 'object',
22
- properties: {
23
- name: {
24
- type: 'string',
25
- enum: _constants2.default.GUARDIAN_FACTOR_TEMPLATES
26
- }
27
- },
28
- required: ['name']
29
- }
30
- };
31
-
32
- class GuardianFactorTemplatesHandler extends _default2.default {
33
- constructor(options) {
34
- super({ ...options,
35
- type: 'guardianFactorTemplates',
36
- id: 'name'
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());
37
9
  });
38
- }
39
-
40
- async getType() {
41
- if (this.existing) return this.existing;
42
- const data = await Promise.all(_constants2.default.GUARDIAN_FACTOR_TEMPLATES.map(async name => {
43
- const templates = await this.client.guardian.getFactorTemplates({
44
- name
45
- });
46
- return {
47
- name,
48
- ...templates
49
- };
50
- }));
51
- return data.filter(d => Object.keys(d).length > 1);
52
- }
53
-
54
- async processChanges(assets) {
55
- const {
56
- guardianFactorTemplates
57
- } = assets;
58
- if (!guardianFactorTemplates || !guardianFactorTemplates.length) return;
59
- await Promise.all(guardianFactorTemplates.map(async fatorTemplates => {
60
- const data = { ...fatorTemplates
61
- };
62
- const params = {
63
- name: fatorTemplates.name
64
- };
65
- delete data.name;
66
- await this.client.guardian.updateFactorTemplates(params, data);
67
- this.didUpdate(params);
68
- this.updated += 1;
69
- }));
70
- }
71
-
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.schema = void 0;
16
+ const default_1 = __importDefault(require("./default"));
17
+ const constants_1 = __importDefault(require("../../constants"));
18
+ exports.schema = {
19
+ type: 'array',
20
+ items: {
21
+ type: 'object',
22
+ properties: {
23
+ name: { type: 'string', enum: constants_1.default.GUARDIAN_FACTOR_TEMPLATES }
24
+ },
25
+ required: ['name']
26
+ }
27
+ };
28
+ class GuardianFactorTemplatesHandler extends default_1.default {
29
+ constructor(options) {
30
+ super(Object.assign(Object.assign({}, options), { type: 'guardianFactorTemplates', id: 'name' }));
31
+ }
32
+ getType() {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ if (this.existing)
35
+ return this.existing;
36
+ const data = yield Promise.all(constants_1.default.GUARDIAN_FACTOR_TEMPLATES.map((name) => __awaiter(this, void 0, void 0, function* () {
37
+ const templates = yield this.client.guardian.getFactorTemplates({ name });
38
+ return Object.assign({ name }, templates);
39
+ })));
40
+ // Filter out empty, should have more then 1 keys (name)
41
+ return data.filter((d) => Object.keys(d).length > 1);
42
+ });
43
+ }
44
+ processChanges(assets) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ // No API to delete or create guardianFactorTemplates, we can only update.
47
+ const { guardianFactorTemplates } = assets;
48
+ // Do nothing if not set
49
+ if (!guardianFactorTemplates || !guardianFactorTemplates.length)
50
+ return;
51
+ // Process each factor templates
52
+ yield Promise.all(guardianFactorTemplates.map((fatorTemplates) => __awaiter(this, void 0, void 0, function* () {
53
+ const data = Object.assign({}, fatorTemplates);
54
+ const params = { name: fatorTemplates.name };
55
+ delete data.name;
56
+ yield this.client.guardian.updateFactorTemplates(params, data);
57
+ this.didUpdate(params);
58
+ this.updated += 1;
59
+ })));
60
+ });
61
+ }
72
62
  }
73
-
74
- exports.default = GuardianFactorTemplatesHandler;
63
+ exports.default = GuardianFactorTemplatesHandler;
@@ -1,66 +1,59 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.schema = undefined;
7
-
8
- var _default = require("./default");
9
-
10
- var _default2 = _interopRequireDefault(_default);
11
-
12
- var _constants = require("../../constants");
13
-
14
- var _constants2 = _interopRequireDefault(_constants);
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- const schema = exports.schema = {
19
- type: 'array',
20
- items: {
21
- type: 'object',
22
- properties: {
23
- name: {
24
- type: 'string',
25
- enum: _constants2.default.GUARDIAN_FACTORS
26
- }
27
- },
28
- required: ['name']
29
- }
30
- };
31
-
32
- class GuardianFactorsHandler extends _default2.default {
33
- constructor(options) {
34
- super({ ...options,
35
- type: 'guardianFactors',
36
- id: 'name'
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());
37
9
  });
38
- }
39
-
40
- async getType() {
41
- if (this.existing) return this.existing;
42
- this.existing = await this.client.guardian.getFactors();
43
- return this.existing;
44
- }
45
-
46
- async processChanges(assets) {
47
- const {
48
- guardianFactors
49
- } = assets;
50
- if (!guardianFactors || !guardianFactors.length) return;
51
- await Promise.all(guardianFactors.map(async factor => {
52
- const data = { ...factor
53
- };
54
- const params = {
55
- name: factor.name
56
- };
57
- delete data.name;
58
- await this.client.guardian.updateFactor(params, data);
59
- this.didUpdate(params);
60
- this.updated += 1;
61
- }));
62
- }
63
-
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.schema = void 0;
16
+ const default_1 = __importDefault(require("./default"));
17
+ const constants_1 = __importDefault(require("../../constants"));
18
+ exports.schema = {
19
+ type: 'array',
20
+ items: {
21
+ type: 'object',
22
+ properties: {
23
+ name: { type: 'string', enum: constants_1.default.GUARDIAN_FACTORS }
24
+ },
25
+ required: ['name']
26
+ }
27
+ };
28
+ class GuardianFactorsHandler extends default_1.default {
29
+ constructor(options) {
30
+ super(Object.assign(Object.assign({}, options), { type: 'guardianFactors', id: 'name' }));
31
+ }
32
+ getType() {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ if (this.existing)
35
+ return this.existing;
36
+ this.existing = yield this.client.guardian.getFactors();
37
+ return this.existing;
38
+ });
39
+ }
40
+ processChanges(assets) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ // No API to delete or create guardianFactors, we can only update.
43
+ const { guardianFactors } = assets;
44
+ // Do nothing if not set
45
+ if (!guardianFactors || !guardianFactors.length)
46
+ return;
47
+ // Process each factor
48
+ yield Promise.all(guardianFactors.map((factor) => __awaiter(this, void 0, void 0, function* () {
49
+ const data = Object.assign({}, factor);
50
+ const params = { name: factor.name };
51
+ delete data.name;
52
+ yield this.client.guardian.updateFactor(params, data);
53
+ this.didUpdate(params);
54
+ this.updated += 1;
55
+ })));
56
+ });
57
+ }
64
58
  }
65
-
66
- exports.default = GuardianFactorsHandler;
59
+ exports.default = GuardianFactorsHandler;