auth0-deploy-cli 7.3.6 → 7.5.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 (113) hide show
  1. package/.circleci/config.yml +15 -0
  2. package/.github/CODEOWNERS +1 -0
  3. package/.husky/pre-commit +6 -0
  4. package/.husky/pre-push +4 -0
  5. package/.nyc_output/60b76a45-577b-4171-9982-a8e836ab7fd6.json +1 -0
  6. package/.nyc_output/processinfo/60b76a45-577b-4171-9982-a8e836ab7fd6.json +1 -0
  7. package/.nyc_output/processinfo/index.json +1 -1
  8. package/CHANGELOG.md +35 -2
  9. package/lib/args.js +89 -81
  10. package/lib/commands/export.js +51 -77
  11. package/lib/commands/import.js +45 -69
  12. package/lib/commands/index.js +11 -20
  13. package/lib/configFactory.js +19 -27
  14. package/lib/context/defaults.js +18 -41
  15. package/lib/context/directory/handlers/actions.js +77 -107
  16. package/lib/context/directory/handlers/attackProtection.js +59 -0
  17. package/lib/context/directory/handlers/clientGrants.js +45 -54
  18. package/lib/context/directory/handlers/clients.js +60 -79
  19. package/lib/context/directory/handlers/connections.js +65 -89
  20. package/lib/context/directory/handlers/databases.js +91 -123
  21. package/lib/context/directory/handlers/emailProvider.js +46 -57
  22. package/lib/context/directory/handlers/emailTemplates.js +67 -80
  23. package/lib/context/directory/handlers/guardianFactorProviders.js +41 -49
  24. package/lib/context/directory/handlers/guardianFactorTemplates.js +41 -49
  25. package/lib/context/directory/handlers/guardianFactors.js +41 -49
  26. package/lib/context/directory/handlers/guardianPhoneFactorMessageTypes.js +40 -50
  27. package/lib/context/directory/handlers/guardianPhoneFactorSelectedProvider.js +40 -50
  28. package/lib/context/directory/handlers/guardianPolicies.js +40 -50
  29. package/lib/context/directory/handlers/hooks.js +55 -70
  30. package/lib/context/directory/handlers/index.js +53 -123
  31. package/lib/context/directory/handlers/migrations.js +36 -41
  32. package/lib/context/directory/handlers/organizations.js +54 -69
  33. package/lib/context/directory/handlers/pages.js +72 -86
  34. package/lib/context/directory/handlers/resourceServers.js +41 -49
  35. package/lib/context/directory/handlers/roles.js +49 -62
  36. package/lib/context/directory/handlers/rules.js +52 -68
  37. package/lib/context/directory/handlers/rulesConfigs.js +33 -32
  38. package/lib/context/directory/handlers/tenant.js +52 -47
  39. package/lib/context/directory/handlers/triggers.js +39 -54
  40. package/lib/context/directory/index.js +113 -101
  41. package/lib/context/index.js +96 -105
  42. package/lib/context/yaml/handlers/actions.js +71 -88
  43. package/lib/context/yaml/handlers/attackProtection.js +29 -0
  44. package/lib/context/yaml/handlers/clientGrants.js +36 -29
  45. package/lib/context/yaml/handlers/clients.js +61 -76
  46. package/lib/context/yaml/handlers/connections.js +76 -103
  47. package/lib/context/yaml/handlers/databases.js +64 -79
  48. package/lib/context/yaml/handlers/emailProvider.js +33 -30
  49. package/lib/context/yaml/handlers/emailTemplates.js +45 -54
  50. package/lib/context/yaml/handlers/guardianFactorProviders.js +27 -18
  51. package/lib/context/yaml/handlers/guardianFactorTemplates.js +27 -18
  52. package/lib/context/yaml/handlers/guardianFactors.js +27 -18
  53. package/lib/context/yaml/handlers/guardianPhoneFactorMessageTypes.js +27 -20
  54. package/lib/context/yaml/handlers/guardianPhoneFactorSelectedProvider.js +27 -20
  55. package/lib/context/yaml/handlers/guardianPolicies.js +27 -20
  56. package/lib/context/yaml/handlers/hooks.js +57 -67
  57. package/lib/context/yaml/handlers/index.js +53 -123
  58. package/lib/context/yaml/handlers/migrations.js +23 -24
  59. package/lib/context/yaml/handlers/organizations.js +40 -38
  60. package/lib/context/yaml/handlers/pages.js +49 -58
  61. package/lib/context/yaml/handlers/resourceServers.js +27 -18
  62. package/lib/context/yaml/handlers/roles.js +34 -24
  63. package/lib/context/yaml/handlers/rules.js +48 -58
  64. package/lib/context/yaml/handlers/rulesConfigs.js +27 -18
  65. package/lib/context/yaml/handlers/tenant.js +44 -30
  66. package/lib/context/yaml/handlers/triggers.js +32 -23
  67. package/lib/context/yaml/index.js +127 -142
  68. package/lib/index.js +73 -79
  69. package/lib/logger.js +18 -22
  70. package/lib/readonly.js +74 -66
  71. package/lib/tools/ValidationError.js +8 -13
  72. package/lib/tools/auth0/client.js +143 -133
  73. package/lib/tools/auth0/handlers/actions.js +231 -241
  74. package/lib/tools/auth0/handlers/attackProtection.js +86 -0
  75. package/lib/tools/auth0/handlers/branding.js +47 -46
  76. package/lib/tools/auth0/handlers/clientGrants.js +118 -116
  77. package/lib/tools/auth0/handlers/clients.js +72 -90
  78. package/lib/tools/auth0/handlers/connections.js +150 -118
  79. package/lib/tools/auth0/handlers/databases.js +127 -124
  80. package/lib/tools/auth0/handlers/default.js +186 -189
  81. package/lib/tools/auth0/handlers/emailProvider.js +67 -78
  82. package/lib/tools/auth0/handlers/emailTemplates.js +116 -92
  83. package/lib/tools/auth0/handlers/guardianFactorProviders.js +66 -81
  84. package/lib/tools/auth0/handlers/guardianFactorTemplates.js +60 -71
  85. package/lib/tools/auth0/handlers/guardianFactors.js +56 -63
  86. package/lib/tools/auth0/handlers/guardianPhoneFactorMessageTypes.js +80 -79
  87. package/lib/tools/auth0/handlers/guardianPhoneFactorSelectedProvider.js +77 -76
  88. package/lib/tools/auth0/handlers/guardianPolicies.js +59 -62
  89. package/lib/tools/auth0/handlers/hooks.js +201 -227
  90. package/lib/tools/auth0/handlers/index.js +53 -111
  91. package/lib/tools/auth0/handlers/migrations.js +99 -79
  92. package/lib/tools/auth0/handlers/organizations.js +225 -247
  93. package/lib/tools/auth0/handlers/pages.js +116 -154
  94. package/lib/tools/auth0/handlers/prompts.js +47 -46
  95. package/lib/tools/auth0/handlers/resourceServers.js +88 -112
  96. package/lib/tools/auth0/handlers/roles.js +203 -220
  97. package/lib/tools/auth0/handlers/rules.js +168 -189
  98. package/lib/tools/auth0/handlers/rulesConfigs.js +54 -63
  99. package/lib/tools/auth0/handlers/tenant.js +88 -64
  100. package/lib/tools/auth0/handlers/triggers.js +126 -126
  101. package/lib/tools/auth0/index.js +92 -85
  102. package/lib/tools/auth0/schema.js +39 -31
  103. package/lib/tools/constants.js +111 -21
  104. package/lib/tools/deploy.js +35 -32
  105. package/lib/tools/index.js +19 -32
  106. package/lib/tools/logger.js +11 -12
  107. package/lib/tools/utils.js +258 -254
  108. package/lib/utils.js +167 -190
  109. package/package.json +6 -3
  110. package/tsconfig.json +96 -0
  111. package/typescript-migration-progress.sh +22 -0
  112. package/.nyc_output/8cf4dd0c-1f3a-4ac1-899c-8e453a64221e.json +0 -1
  113. package/.nyc_output/processinfo/8cf4dd0c-1f3a-4ac1-899c-8e453a64221e.json +0 -1
@@ -1,202 +1,199 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.order = order;
7
-
8
- var _ValidationError = require("../../ValidationError");
9
-
10
- var _ValidationError2 = _interopRequireDefault(_ValidationError);
11
-
12
- var _logger = require("../../logger");
13
-
14
- var _logger2 = _interopRequireDefault(_logger);
15
-
16
- var _utils = require("../../utils");
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.order = void 0;
16
+ const ValidationError_1 = __importDefault(require("../../ValidationError"));
17
+ const logger_1 = __importDefault(require("../../logger"));
18
+ const utils_1 = require("../../utils");
20
19
  function order(value) {
21
- return function decorator(t, n, descriptor) {
22
- descriptor.value.order = value;
23
- return descriptor;
24
- };
20
+ return function decorator(t, n, descriptor) {
21
+ descriptor.value.order = value; // eslint-disable-line
22
+ return descriptor;
23
+ };
25
24
  }
26
-
25
+ exports.order = order;
27
26
  class DefaultHandler {
28
- constructor(options) {
29
- this.config = options.config;
30
- this.type = options.type;
31
- this.id = options.id || 'id';
32
- this.client = options.client;
33
- this.existing = null;
34
- this.identifiers = options.identifiers || ['id', 'name'];
35
- this.objectFields = options.objectFields || [];
36
- this.stripUpdateFields = [...(options.stripUpdateFields || []), this.id];
37
- this.functions = {
38
- getAll: 'getAll',
39
- create: 'create',
40
- update: 'update',
41
- delete: 'delete',
42
- ...(options.functions || {})
43
- };
44
- this.updated = 0;
45
- this.created = 0;
46
- this.deleted = 0;
47
- }
48
-
49
- getClientFN(fn) {
50
- if (typeof fn === 'string') {
51
- const client = Reflect.get(this.client, this.type);
52
- return Reflect.get(client, fn).bind(client);
27
+ constructor(options) {
28
+ this.config = options.config;
29
+ this.type = options.type;
30
+ this.id = options.id || 'id';
31
+ this.client = options.client;
32
+ this.existing = null;
33
+ this.identifiers = options.identifiers || ['id', 'name'];
34
+ this.objectFields = options.objectFields || [];
35
+ this.stripUpdateFields = [
36
+ ...options.stripUpdateFields || [],
37
+ this.id
38
+ ];
39
+ this.functions = Object.assign({ getAll: 'getAll', create: 'create', update: 'update', delete: 'delete' }, options.functions || {});
40
+ this.updated = 0;
41
+ this.created = 0;
42
+ this.deleted = 0;
53
43
  }
54
-
55
- return fn;
56
- }
57
-
58
- didDelete(item) {
59
- _logger2.default.info(`Deleted [${this.type}]: ${this.objString(item)}`);
60
- }
61
-
62
- didCreate(item) {
63
- _logger2.default.info(`Created [${this.type}]: ${this.objString(item)}`);
64
- }
65
-
66
- didUpdate(item) {
67
- _logger2.default.info(`Updated [${this.type}]: ${this.objString(item)}`);
68
- }
69
-
70
- objString(item) {
71
- return (0, _utils.dumpJSON)(item);
72
- }
73
-
74
- async getType() {
75
- throw new Error(`Must implement getType for type ${this.type}`);
76
- }
77
-
78
- async load() {
79
- _logger2.default.info(`Retrieving ${this.type} data from Auth0`);
80
-
81
- this.existing = await this.getType();
82
- return {
83
- [this.type]: this.existing
84
- };
85
- }
86
-
87
- async calcChanges(assets) {
88
- const typeAssets = assets[this.type];
89
- if (!typeAssets) return {};
90
- const existing = await this.getType();
91
- return (0, _utils.calcChanges)(this, typeAssets, existing, this.identifiers, this.objectFields);
92
- }
93
-
94
- async validate(assets) {
95
- const typeAssets = assets[this.type];
96
- if (!Array.isArray(typeAssets)) return;
97
- const duplicateNames = (0, _utils.duplicateItems)(typeAssets, 'name');
98
-
99
- if (duplicateNames.length > 0) {
100
- const formatted = duplicateNames.map(dups => dups.map(d => `${d.name}`));
101
- throw new _ValidationError2.default(`There are multiple ${this.type} with the same name combinations
102
- ${(0, _utils.dumpJSON)(formatted)}.
103
- Names must be unique.`);
44
+ getClientFN(fn) {
45
+ if (typeof fn === 'string') {
46
+ const client = this.client[this.type];
47
+ return client[fn].bind(client);
48
+ }
49
+ return fn;
104
50
  }
105
-
106
- const duplicateIDs = (0, _utils.duplicateItems)(typeAssets, this.id);
107
-
108
- if (duplicateIDs.length > 0) {
109
- const formatted = duplicateIDs.map(dups => dups.map(d => `${d[this.id]}`));
110
- throw new _ValidationError2.default(`There are multiple ${this.type} for the following stage-order combinations
111
- ${(0, _utils.dumpJSON)(formatted)}.
112
- Only one rule must be defined for the same order number in a stage.`);
51
+ didDelete(item) {
52
+ logger_1.default.info(`Deleted [${this.type}]: ${this.objString(item)}`);
113
53
  }
114
- }
115
-
116
- async processChanges(assets, changes) {
117
- if (!changes) {
118
- changes = await this.calcChanges(assets);
54
+ didCreate(item) {
55
+ logger_1.default.info(`Created [${this.type}]: ${this.objString(item)}`);
119
56
  }
120
-
121
- const del = changes.del || [];
122
- const update = changes.update || [];
123
- const create = changes.create || [];
124
- const conflicts = changes.conflicts || [];
125
-
126
- _logger2.default.debug(`Start processChanges for ${this.type} [delete:${del.length}] [update:${update.length}], [create:${create.length}], [conflicts:${conflicts.length}]`);
127
-
128
- if (del.length > 0) {
129
- const allowDelete = this.config('AUTH0_ALLOW_DELETE') === 'true' || this.config('AUTH0_ALLOW_DELETE') === true;
130
- const byExtension = this.config('EXTENSION_SECRET') && (this.type === 'rules' || this.type === 'resourceServers');
131
- const shouldDelete = allowDelete || byExtension;
132
-
133
- if (!shouldDelete) {
134
- _logger2.default.warn(`Detected the following ${this.type} should be deleted. Doing so may be destructive.\nYou can enable deletes by setting 'AUTH0_ALLOW_DELETE' to true in the config
135
- \n${changes.del.map(i => this.objString(i)).join('\n')}
136
- `);
137
- } else {
138
- await this.client.pool.addEachTask({
139
- data: del || [],
140
- generator: delItem => {
141
- const delFunction = this.getClientFN(this.functions.delete);
142
- return delFunction({
143
- [this.id]: delItem[this.id]
144
- }).then(() => {
145
- this.didDelete(delItem);
146
- this.deleted += 1;
147
- }).catch(err => {
148
- throw new Error(`Problem deleting ${this.type} ${this.objString(delItem)}\n${err}`);
149
- });
150
- }
151
- }).promise();
152
- }
57
+ didUpdate(item) {
58
+ logger_1.default.info(`Updated [${this.type}]: ${this.objString(item)}`);
153
59
  }
154
-
155
- await this.client.pool.addEachTask({
156
- data: conflicts || [],
157
- generator: updateItem => {
158
- const updateFN = this.getClientFN(this.functions.update);
159
- const params = {
160
- [this.id]: updateItem[this.id]
161
- };
162
- const payload = (0, _utils.stripFields)({ ...updateItem
163
- }, this.stripUpdateFields);
164
- return updateFN(params, payload).then(data => this.didUpdate(data)).catch(err => {
165
- throw new Error(`Problem updating ${this.type} ${this.objString(updateItem)}\n${err}`);
60
+ objString(item) {
61
+ return (0, utils_1.dumpJSON)(item);
62
+ }
63
+ getType() {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ // Each type to impl how to get the existing as its not consistent across the mgnt api.
66
+ throw new Error(`Must implement getType for type ${this.type}`);
166
67
  });
167
- }
168
- }).promise();
169
- await this.client.pool.addEachTask({
170
- data: create || [],
171
- generator: createItem => {
172
- const createFunction = this.getClientFN(this.functions.create);
173
- return createFunction(createItem).then(data => {
174
- this.didCreate(data);
175
- this.created += 1;
176
- }).catch(err => {
177
- throw new Error(`Problem creating ${this.type} ${this.objString(createItem)}\n${err}`);
68
+ }
69
+ load() {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ // Load Asset from Tenant
72
+ logger_1.default.info(`Retrieving ${this.type} data from Auth0`);
73
+ this.existing = yield this.getType();
74
+ return { [this.type]: this.existing };
178
75
  });
179
- }
180
- }).promise();
181
- await this.client.pool.addEachTask({
182
- data: update || [],
183
- generator: updateItem => {
184
- const updateFN = this.getClientFN(this.functions.update);
185
- const params = {
186
- [this.id]: updateItem[this.id]
187
- };
188
- const payload = (0, _utils.stripFields)({ ...updateItem
189
- }, this.stripUpdateFields);
190
- return updateFN(params, payload).then(data => {
191
- this.didUpdate(data);
192
- this.updated += 1;
193
- }).catch(err => {
194
- throw new Error(`Problem updating ${this.type} ${this.objString(updateItem)}\n${err}`);
76
+ }
77
+ calcChanges(assets) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ const typeAssets = assets[this.type];
80
+ // Do nothing if not set
81
+ if (!typeAssets)
82
+ return {};
83
+ const existing = yield this.getType();
84
+ // Figure out what needs to be updated vs created
85
+ return (0, utils_1.calcChanges)(this, typeAssets, existing, this.identifiers);
86
+ });
87
+ }
88
+ validate(assets) {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ // Ensure no duplication in id and name
91
+ const typeAssets = assets[this.type];
92
+ // Do nothing if not set
93
+ if (!Array.isArray(typeAssets))
94
+ return;
95
+ // Do not allow items with same name
96
+ const duplicateNames = (0, utils_1.duplicateItems)(typeAssets, 'name');
97
+ if (duplicateNames.length > 0) {
98
+ const formatted = duplicateNames.map((dups) => dups.map((d) => `${d.name}`));
99
+ throw new ValidationError_1.default(`There are multiple ${this.type} with the same name combinations
100
+ ${(0, utils_1.dumpJSON)(formatted)}.
101
+ Names must be unique.`);
102
+ }
103
+ // Do not allow items with same id
104
+ const duplicateIDs = (0, utils_1.duplicateItems)(typeAssets, this.id);
105
+ if (duplicateIDs.length > 0) {
106
+ const formatted = duplicateIDs.map((dups) => dups.map((d) => `${d[this.id]}`));
107
+ throw new ValidationError_1.default(`There are multiple ${this.type} for the following stage-order combinations
108
+ ${(0, utils_1.dumpJSON)(formatted)}.
109
+ Only one rule must be defined for the same order number in a stage.`);
110
+ }
195
111
  });
196
- }
197
- }).promise();
198
- }
199
-
112
+ }
113
+ processChanges(assets, changes) {
114
+ return __awaiter(this, void 0, void 0, function* () {
115
+ if (!changes) {
116
+ changes = yield this.calcChanges(assets);
117
+ }
118
+ const del = changes.del || [];
119
+ const update = changes.update || [];
120
+ const create = changes.create || [];
121
+ const conflicts = changes.conflicts || [];
122
+ logger_1.default.debug(`Start processChanges for ${this.type} [delete:${del.length}] [update:${update.length}], [create:${create.length}], [conflicts:${conflicts.length}]`);
123
+ // Process Deleted
124
+ if (del.length > 0) {
125
+ const allowDelete = this.config('AUTH0_ALLOW_DELETE') === 'true' || this.config('AUTH0_ALLOW_DELETE') === true;
126
+ const byExtension = this.config('EXTENSION_SECRET') && (this.type === 'rules' || this.type === 'resourceServers');
127
+ const shouldDelete = allowDelete || byExtension;
128
+ if (!shouldDelete) {
129
+ logger_1.default.warn(`Detected the following ${this.type} should be deleted. Doing so may be destructive.\nYou can enable deletes by setting 'AUTH0_ALLOW_DELETE' to true in the config
130
+ \n${changes.del.map((i) => this.objString(i)).join('\n')}
131
+ `);
132
+ }
133
+ else {
134
+ yield this.client.pool.addEachTask({
135
+ data: del || [],
136
+ generator: (delItem) => {
137
+ const delFunction = this.getClientFN(this.functions.delete);
138
+ return delFunction({ [this.id]: delItem[this.id] })
139
+ .then(() => {
140
+ this.didDelete(delItem);
141
+ this.deleted += 1;
142
+ })
143
+ .catch((err) => {
144
+ throw new Error(`Problem deleting ${this.type} ${this.objString(delItem)}\n${err}`);
145
+ });
146
+ }
147
+ }).promise();
148
+ }
149
+ }
150
+ // Process Renaming Entries Temp due to conflicts in names
151
+ yield this.client.pool.addEachTask({
152
+ data: conflicts || [],
153
+ generator: (updateItem) => {
154
+ const updateFN = this.getClientFN(this.functions.update);
155
+ const params = { [this.id]: updateItem[this.id] };
156
+ const payload = (0, utils_1.stripFields)(Object.assign({}, updateItem), this.stripUpdateFields);
157
+ return updateFN(params, payload)
158
+ .then((data) => this.didUpdate(data))
159
+ .catch((err) => {
160
+ throw new Error(`Problem updating ${this.type} ${this.objString(updateItem)}\n${err}`);
161
+ });
162
+ }
163
+ }).promise();
164
+ // Process Creations
165
+ yield this.client.pool.addEachTask({
166
+ data: create || [],
167
+ generator: (createItem) => {
168
+ const createFunction = this.getClientFN(this.functions.create);
169
+ return createFunction(createItem)
170
+ .then((data) => {
171
+ this.didCreate(data);
172
+ this.created += 1;
173
+ })
174
+ .catch((err) => {
175
+ throw new Error(`Problem creating ${this.type} ${this.objString(createItem)}\n${err}`);
176
+ });
177
+ }
178
+ }).promise();
179
+ // Process Updates and strip fields not allowed in updates
180
+ yield this.client.pool.addEachTask({
181
+ data: update || [],
182
+ generator: (updateItem) => {
183
+ const updateFN = this.getClientFN(this.functions.update);
184
+ const params = { [this.id]: updateItem[this.id] };
185
+ const payload = (0, utils_1.stripFields)(Object.assign({}, updateItem), this.stripUpdateFields);
186
+ return updateFN(params, payload)
187
+ .then((data) => {
188
+ this.didUpdate(data);
189
+ this.updated += 1;
190
+ })
191
+ .catch((err) => {
192
+ throw new Error(`Problem updating ${this.type} ${this.objString(updateItem)}\n${err}`);
193
+ });
194
+ }
195
+ }).promise();
196
+ });
197
+ }
200
198
  }
201
-
202
- exports.default = DefaultHandler;
199
+ exports.default = DefaultHandler;
@@ -1,84 +1,73 @@
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
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- const schema = exports.schema = {
15
- type: 'object'
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
13
  };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.schema = void 0;
16
+ const default_1 = __importDefault(require("./default"));
17
+ exports.schema = { type: 'object' };
18
+ // The Management API requires the fields to be specified
17
19
  const defaultFields = ['name', 'enabled', 'credentials', 'settings', 'default_from_address'];
18
-
19
- class EmailProviderHandler extends _default2.default {
20
- constructor(options) {
21
- super({ ...options,
22
- type: 'emailProvider'
23
- });
24
- }
25
-
26
- async getType() {
27
- try {
28
- return await this.client.emailProvider.get({
29
- include_fields: true,
30
- fields: defaultFields
31
- });
32
- } catch (err) {
33
- if (err.statusCode === 404) return {};
34
- throw err;
20
+ class EmailProviderHandler extends default_1.default {
21
+ constructor(options) {
22
+ super(Object.assign(Object.assign({}, options), { type: 'emailProvider' }));
35
23
  }
36
- }
37
-
38
- objString(provider) {
39
- return super.objString({
40
- name: provider.name,
41
- enabled: provider.enabled
42
- });
43
- }
44
-
45
- async processChanges(assets) {
46
- const {
47
- emailProvider
48
- } = assets;
49
- if (!emailProvider) return;
50
-
51
- if (Object.keys(emailProvider).length > 0) {
52
- let existing = await this.getType();
53
-
54
- if (existing.name) {
55
- if (existing.name !== emailProvider.name) {
56
- await this.client.emailProvider.delete();
57
- this.didDelete(existing);
58
- existing = {};
59
- }
60
- }
61
-
62
- if (existing.name) {
63
- const provider = {
64
- name: emailProvider.name,
65
- enabled: emailProvider.enabled
66
- };
67
- const updated = await this.client.emailProvider.update(provider, emailProvider);
68
- this.updated += 1;
69
- this.didUpdate(updated);
70
- } else {
71
- const provider = {
72
- name: emailProvider.name,
73
- enabled: emailProvider.enabled
74
- };
75
- const created = await this.client.emailProvider.configure(provider, emailProvider);
76
- this.created += 1;
77
- this.didCreate(created);
78
- }
24
+ getType() {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ try {
27
+ return yield this.client.emailProvider.get({ include_fields: true, fields: defaultFields });
28
+ }
29
+ catch (err) {
30
+ if (err.statusCode === 404)
31
+ return {};
32
+ throw err;
33
+ }
34
+ });
35
+ }
36
+ objString(provider) {
37
+ return super.objString({ name: provider.name, enabled: provider.enabled });
38
+ }
39
+ processChanges(assets) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const { emailProvider } = assets;
42
+ // Do nothing if not set
43
+ if (!emailProvider)
44
+ return;
45
+ if (Object.keys(emailProvider).length > 0) {
46
+ let existing = yield this.getType();
47
+ // Check for existing Email Provider
48
+ if (existing.name) {
49
+ if (existing.name !== emailProvider.name) {
50
+ // Delete the current provider as it's different
51
+ yield this.client.emailProvider.delete();
52
+ this.didDelete(existing);
53
+ existing = {};
54
+ }
55
+ }
56
+ // Now configure or update depending if it is configured already
57
+ if (existing.name) {
58
+ const provider = { name: emailProvider.name, enabled: emailProvider.enabled };
59
+ const updated = yield this.client.emailProvider.update(provider, emailProvider);
60
+ this.updated += 1;
61
+ this.didUpdate(updated);
62
+ }
63
+ else {
64
+ const provider = { name: emailProvider.name, enabled: emailProvider.enabled };
65
+ const created = yield this.client.emailProvider.configure(provider, emailProvider);
66
+ this.created += 1;
67
+ this.didCreate(created);
68
+ }
69
+ }
70
+ });
79
71
  }
80
- }
81
-
82
72
  }
83
-
84
- exports.default = EmailProviderHandler;
73
+ exports.default = EmailProviderHandler;