auth0-deploy-cli 7.3.7 → 7.5.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 (113) 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 +6 -0
  5. package/.husky/pre-push +4 -0
  6. package/CHANGELOG.md +37 -2
  7. package/lib/args.js +94 -81
  8. package/lib/commands/export.js +54 -78
  9. package/lib/commands/import.js +46 -70
  10. package/lib/commands/index.js +11 -20
  11. package/lib/configFactory.js +19 -27
  12. package/lib/context/defaults.js +18 -41
  13. package/lib/context/directory/handlers/actions.js +77 -107
  14. package/lib/context/directory/handlers/attackProtection.js +59 -0
  15. package/lib/context/directory/handlers/clientGrants.js +45 -54
  16. package/lib/context/directory/handlers/clients.js +60 -79
  17. package/lib/context/directory/handlers/connections.js +65 -89
  18. package/lib/context/directory/handlers/databases.js +91 -123
  19. package/lib/context/directory/handlers/emailProvider.js +46 -57
  20. package/lib/context/directory/handlers/emailTemplates.js +67 -80
  21. package/lib/context/directory/handlers/guardianFactorProviders.js +41 -49
  22. package/lib/context/directory/handlers/guardianFactorTemplates.js +41 -49
  23. package/lib/context/directory/handlers/guardianFactors.js +41 -49
  24. package/lib/context/directory/handlers/guardianPhoneFactorMessageTypes.js +40 -50
  25. package/lib/context/directory/handlers/guardianPhoneFactorSelectedProvider.js +40 -50
  26. package/lib/context/directory/handlers/guardianPolicies.js +40 -50
  27. package/lib/context/directory/handlers/hooks.js +55 -70
  28. package/lib/context/directory/handlers/index.js +53 -123
  29. package/lib/context/directory/handlers/migrations.js +36 -41
  30. package/lib/context/directory/handlers/organizations.js +54 -69
  31. package/lib/context/directory/handlers/pages.js +72 -86
  32. package/lib/context/directory/handlers/resourceServers.js +41 -49
  33. package/lib/context/directory/handlers/roles.js +49 -62
  34. package/lib/context/directory/handlers/rules.js +52 -68
  35. package/lib/context/directory/handlers/rulesConfigs.js +33 -32
  36. package/lib/context/directory/handlers/tenant.js +52 -47
  37. package/lib/context/directory/handlers/triggers.js +39 -54
  38. package/lib/context/directory/index.js +113 -101
  39. package/lib/context/index.js +96 -105
  40. package/lib/context/yaml/handlers/actions.js +71 -88
  41. package/lib/context/yaml/handlers/attackProtection.js +29 -0
  42. package/lib/context/yaml/handlers/clientGrants.js +36 -29
  43. package/lib/context/yaml/handlers/clients.js +61 -76
  44. package/lib/context/yaml/handlers/connections.js +76 -103
  45. package/lib/context/yaml/handlers/databases.js +64 -79
  46. package/lib/context/yaml/handlers/emailProvider.js +33 -30
  47. package/lib/context/yaml/handlers/emailTemplates.js +45 -54
  48. package/lib/context/yaml/handlers/guardianFactorProviders.js +27 -18
  49. package/lib/context/yaml/handlers/guardianFactorTemplates.js +27 -18
  50. package/lib/context/yaml/handlers/guardianFactors.js +27 -18
  51. package/lib/context/yaml/handlers/guardianPhoneFactorMessageTypes.js +27 -20
  52. package/lib/context/yaml/handlers/guardianPhoneFactorSelectedProvider.js +27 -20
  53. package/lib/context/yaml/handlers/guardianPolicies.js +27 -20
  54. package/lib/context/yaml/handlers/hooks.js +57 -67
  55. package/lib/context/yaml/handlers/index.js +53 -123
  56. package/lib/context/yaml/handlers/migrations.js +23 -24
  57. package/lib/context/yaml/handlers/organizations.js +40 -38
  58. package/lib/context/yaml/handlers/pages.js +49 -58
  59. package/lib/context/yaml/handlers/resourceServers.js +27 -18
  60. package/lib/context/yaml/handlers/roles.js +34 -24
  61. package/lib/context/yaml/handlers/rules.js +48 -58
  62. package/lib/context/yaml/handlers/rulesConfigs.js +27 -18
  63. package/lib/context/yaml/handlers/tenant.js +44 -30
  64. package/lib/context/yaml/handlers/triggers.js +32 -23
  65. package/lib/context/yaml/index.js +127 -142
  66. package/lib/index.js +73 -79
  67. package/lib/logger.js +18 -22
  68. package/lib/readonly.js +74 -66
  69. package/lib/tools/ValidationError.js +8 -13
  70. package/lib/tools/auth0/client.js +143 -133
  71. package/lib/tools/auth0/handlers/actions.js +231 -243
  72. package/lib/tools/auth0/handlers/attackProtection.js +86 -0
  73. package/lib/tools/auth0/handlers/branding.js +47 -46
  74. package/lib/tools/auth0/handlers/clientGrants.js +118 -116
  75. package/lib/tools/auth0/handlers/clients.js +72 -90
  76. package/lib/tools/auth0/handlers/connections.js +150 -118
  77. package/lib/tools/auth0/handlers/databases.js +127 -124
  78. package/lib/tools/auth0/handlers/default.js +186 -189
  79. package/lib/tools/auth0/handlers/emailProvider.js +67 -78
  80. package/lib/tools/auth0/handlers/emailTemplates.js +116 -92
  81. package/lib/tools/auth0/handlers/guardianFactorProviders.js +66 -81
  82. package/lib/tools/auth0/handlers/guardianFactorTemplates.js +60 -71
  83. package/lib/tools/auth0/handlers/guardianFactors.js +56 -63
  84. package/lib/tools/auth0/handlers/guardianPhoneFactorMessageTypes.js +80 -79
  85. package/lib/tools/auth0/handlers/guardianPhoneFactorSelectedProvider.js +77 -76
  86. package/lib/tools/auth0/handlers/guardianPolicies.js +59 -62
  87. package/lib/tools/auth0/handlers/hooks.js +201 -227
  88. package/lib/tools/auth0/handlers/index.js +53 -111
  89. package/lib/tools/auth0/handlers/migrations.js +99 -79
  90. package/lib/tools/auth0/handlers/organizations.js +225 -247
  91. package/lib/tools/auth0/handlers/pages.js +116 -154
  92. package/lib/tools/auth0/handlers/prompts.js +47 -46
  93. package/lib/tools/auth0/handlers/resourceServers.js +88 -112
  94. package/lib/tools/auth0/handlers/roles.js +203 -220
  95. package/lib/tools/auth0/handlers/rules.js +168 -189
  96. package/lib/tools/auth0/handlers/rulesConfigs.js +54 -63
  97. package/lib/tools/auth0/handlers/tenant.js +88 -64
  98. package/lib/tools/auth0/handlers/triggers.js +126 -126
  99. package/lib/tools/auth0/index.js +92 -85
  100. package/lib/tools/auth0/schema.js +39 -31
  101. package/lib/tools/constants.js +111 -21
  102. package/lib/tools/deploy.js +35 -32
  103. package/lib/tools/index.js +19 -32
  104. package/lib/tools/logger.js +11 -12
  105. package/lib/tools/utils.js +258 -254
  106. package/lib/utils.js +167 -190
  107. package/package.json +13 -17
  108. package/tsconfig.json +17 -0
  109. package/typescript-migration-progress.sh +22 -0
  110. package/.babelrc +0 -17
  111. package/.nyc_output/32e2bffd-d561-4814-9aa3-fe929a1e178a.json +0 -1
  112. package/.nyc_output/processinfo/32e2bffd-d561-4814-9aa3-fe929a1e178a.json +0 -1
  113. package/.nyc_output/processinfo/index.json +0 -1
@@ -1,125 +1,157 @@
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 = undefined;
7
-
8
- var _dec, _class;
9
-
10
- var _default = require("./default");
11
-
12
- var _default2 = _interopRequireDefault(_default);
13
-
14
- var _utils = require("../../utils");
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- 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; }
19
-
20
- const schema = exports.schema = {
21
- type: 'array',
22
- items: {
23
- type: 'object',
24
- properties: {
25
- name: {
26
- type: 'string'
27
- },
28
- strategy: {
29
- type: 'string'
30
- },
31
- options: {
32
- type: 'object'
33
- },
34
- enabled_clients: {
35
- type: 'array',
36
- items: {
37
- type: 'string'
38
- }
39
- },
40
- realms: {
41
- type: 'array',
42
- items: {
43
- type: 'string'
44
- }
45
- },
46
- metadata: {
47
- type: 'object'
48
- }
49
- },
50
- required: ['name', 'strategy']
51
- }
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;
52
23
  };
53
- let ConnectionsHandler = (_dec = (0, _default.order)('60'), (_class = class ConnectionsHandler extends _default2.default {
54
- constructor(config) {
55
- super({ ...config,
56
- type: 'connections',
57
- stripUpdateFields: ['strategy', 'name']
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;
30
+ };
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());
58
38
  });
59
- }
60
-
61
- objString(connection) {
62
- return super.objString({
63
- name: connection.name,
64
- id: connection.id
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.addExcludedConnectionPropertiesToChanges = exports.schema = void 0;
45
+ const dot_prop_1 = __importDefault(require("dot-prop"));
46
+ const lodash_1 = __importDefault(require("lodash"));
47
+ const default_1 = __importStar(require("./default"));
48
+ const utils_1 = require("../../utils");
49
+ exports.schema = {
50
+ type: 'array',
51
+ items: {
52
+ type: 'object',
53
+ properties: {
54
+ name: { type: 'string' },
55
+ strategy: { type: 'string' },
56
+ options: { type: 'object' },
57
+ enabled_clients: { type: 'array', items: { type: 'string' } },
58
+ realms: { type: 'array', items: { type: 'string' } },
59
+ metadata: { type: 'object' }
60
+ },
61
+ required: ['name', 'strategy']
62
+ }
63
+ };
64
+ // addExcludedConnectionPropertiesToChanges superimposes excluded properties on the `options` object. The Auth0 API
65
+ // will overwrite the options property when updating connections, so it is necessary to add excluded properties back in to prevent those excluded properties from being deleted.
66
+ // This use case is common because organizations may not want to expose sensitive connection details, but want to preserve them in the tenant.
67
+ // exported only for unit testing purposes
68
+ const addExcludedConnectionPropertiesToChanges = ({ proposedChanges, existingConnections, config }) => {
69
+ var _a, _b;
70
+ if (proposedChanges.update.length === 0)
71
+ return proposedChanges;
72
+ const excludedFields = ((_b = (_a = config()) === null || _a === void 0 ? void 0 : _a.EXCLUDED_PROPS) === null || _b === void 0 ? void 0 : _b.connections) || [];
73
+ if (excludedFields.length === 0)
74
+ return proposedChanges;
75
+ const existingConnectionsMap = lodash_1.default.keyBy(existingConnections, 'id');
76
+ const excludedOptions = excludedFields.filter(
77
+ // Only include fields that pertain to options
78
+ (excludedField) => excludedField.startsWith('options'));
79
+ const newProposedUpdates = proposedChanges.update.map((proposedConnection) => {
80
+ const currConnection = existingConnectionsMap[proposedConnection.id];
81
+ const currentExcludedPropertyValues = excludedOptions.reduce((agg, excludedField) => {
82
+ if (!dot_prop_1.default.has(currConnection, excludedField))
83
+ return agg;
84
+ const currentExcludedFieldValue = dot_prop_1.default.get(currConnection, excludedField);
85
+ dot_prop_1.default.set(agg, excludedField, currentExcludedFieldValue);
86
+ return agg;
87
+ }, {});
88
+ return Object.assign(Object.assign({}, proposedConnection), { options: Object.assign(Object.assign({}, proposedConnection.options), currentExcludedPropertyValues.options) });
65
89
  });
66
- }
67
-
68
- getFormattedOptions(connection, clients) {
69
- try {
70
- return {
71
- options: { ...connection.options,
72
- idpinitiated: { ...connection.options.idpinitiated,
73
- client_id: (0, _utils.convertClientNameToId)(connection.options.idpinitiated.client_id, clients)
74
- }
90
+ return Object.assign(Object.assign({}, proposedChanges), { update: newProposedUpdates });
91
+ };
92
+ exports.addExcludedConnectionPropertiesToChanges = addExcludedConnectionPropertiesToChanges;
93
+ class ConnectionsHandler extends default_1.default {
94
+ constructor(config) {
95
+ super(Object.assign(Object.assign({}, config), { type: 'connections', stripUpdateFields: ['strategy', 'name'] }));
96
+ }
97
+ objString(connection) {
98
+ return super.objString({ name: connection.name, id: connection.id });
99
+ }
100
+ getFormattedOptions(connection, clients) {
101
+ try {
102
+ return {
103
+ options: Object.assign(Object.assign({}, connection.options), { idpinitiated: Object.assign(Object.assign({}, connection.options.idpinitiated), { client_id: (0, utils_1.convertClientNameToId)(connection.options.idpinitiated.client_id, clients) }) })
104
+ };
105
+ }
106
+ catch (e) {
107
+ return {};
75
108
  }
76
- };
77
- } catch (e) {
78
- return {};
79
109
  }
80
- }
81
-
82
- async getType() {
83
- if (this.existing) return this.existing;
84
- const connections = await this.client.connections.getAll({
85
- paginate: true,
86
- include_totals: true
87
- });
88
- this.existing = connections.filter(c => c.strategy !== 'auth0');
89
- return this.existing;
90
- }
91
-
92
- async calcChanges(assets) {
93
- const {
94
- connections
95
- } = assets;
96
- if (!connections) return {};
97
- const clients = await this.client.clients.getAll({
98
- paginate: true,
99
- include_totals: true
100
- });
101
- const existingConnections = await this.client.connections.getAll({
102
- paginate: true,
103
- include_totals: true
104
- });
105
- const formatted = assets.connections.map(connection => ({ ...connection,
106
- ...this.getFormattedOptions(connection, clients),
107
- enabled_clients: (0, _utils.getEnabledClients)(assets, connection, existingConnections, clients)
108
- }));
109
- return super.calcChanges({ ...assets,
110
- connections: formatted
111
- });
112
- }
113
-
114
- async processChanges(assets) {
115
- const {
116
- connections
117
- } = assets;
118
- if (!connections) return;
119
- const excludedConnections = assets.exclude && assets.exclude.connections || [];
120
- const changes = await this.calcChanges(assets);
121
- await super.processChanges(assets, (0, _utils.filterExcluded)(changes, excludedConnections));
122
- }
123
-
124
- }, (_applyDecoratedDescriptor(_class.prototype, "processChanges", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "processChanges"), _class.prototype)), _class));
125
- exports.default = ConnectionsHandler;
110
+ getType() {
111
+ return __awaiter(this, void 0, void 0, function* () {
112
+ if (this.existing)
113
+ return this.existing;
114
+ const connections = yield this.client.connections.getAll({ paginate: true, include_totals: true });
115
+ // Filter out database connections
116
+ this.existing = connections.filter((c) => c.strategy !== 'auth0');
117
+ return this.existing;
118
+ });
119
+ }
120
+ calcChanges(assets) {
121
+ const _super = Object.create(null, {
122
+ calcChanges: { get: () => super.calcChanges }
123
+ });
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ const { connections } = assets;
126
+ // Do nothing if not set
127
+ if (!connections)
128
+ return {};
129
+ // Convert enabled_clients by name to the id
130
+ const clients = yield this.client.clients.getAll({ paginate: true, include_totals: true });
131
+ const existingConnections = yield this.client.connections.getAll({ paginate: true, include_totals: true });
132
+ const formatted = assets.connections.map((connection) => (Object.assign(Object.assign(Object.assign({}, connection), this.getFormattedOptions(connection, clients)), { enabled_clients: (0, utils_1.getEnabledClients)(assets, connection, existingConnections, clients) })));
133
+ const proposedChanges = yield _super.calcChanges.call(this, Object.assign(Object.assign({}, assets), { connections: formatted }));
134
+ const proposedChangesWithExcludedProperties = (0, exports.addExcludedConnectionPropertiesToChanges)({ proposedChanges, existingConnections, config: this.config });
135
+ return proposedChangesWithExcludedProperties;
136
+ });
137
+ }
138
+ // Run after clients are updated so we can convert all the enabled_clients names to id's
139
+ processChanges(assets) {
140
+ const _super = Object.create(null, {
141
+ processChanges: { get: () => super.processChanges }
142
+ });
143
+ return __awaiter(this, void 0, void 0, function* () {
144
+ const { connections } = assets;
145
+ // Do nothing if not set
146
+ if (!connections)
147
+ return;
148
+ const excludedConnections = (assets.exclude && assets.exclude.connections) || [];
149
+ const changes = yield this.calcChanges(assets);
150
+ yield _super.processChanges.call(this, assets, (0, utils_1.filterExcluded)(changes, excludedConnections));
151
+ });
152
+ }
153
+ }
154
+ __decorate([
155
+ (0, default_1.order)('60')
156
+ ], ConnectionsHandler.prototype, "processChanges", null);
157
+ exports.default = ConnectionsHandler;
@@ -1,132 +1,135 @@
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 = 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
- var _utils = require("../../utils");
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
- 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; }
23
-
24
- const schema = exports.schema = {
25
- type: 'array',
26
- items: {
27
- type: 'object',
28
- properties: {
29
- strategy: {
30
- type: 'string',
31
- enum: ['auth0'],
32
- default: 'auth0'
33
- },
34
- name: {
35
- type: 'string'
36
- },
37
- options: {
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;
30
+ };
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());
38
+ });
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 = void 0;
45
+ const default_1 = __importStar(require("./default"));
46
+ const constants_1 = __importDefault(require("../../constants"));
47
+ const utils_1 = require("../../utils");
48
+ exports.schema = {
49
+ type: 'array',
50
+ items: {
38
51
  type: 'object',
39
52
  properties: {
40
- customScripts: {
41
- type: 'object',
42
- properties: { ..._constants2.default.DATABASE_SCRIPTS.reduce((o, script) => ({ ...o,
43
- [script]: {
44
- type: 'string'
53
+ strategy: { type: 'string', enum: ['auth0'], default: 'auth0' },
54
+ name: { type: 'string' },
55
+ options: {
56
+ type: 'object',
57
+ properties: {
58
+ customScripts: {
59
+ type: 'object',
60
+ properties: Object.assign({}, constants_1.default.DATABASE_SCRIPTS.reduce((o, script) => (Object.assign(Object.assign({}, o), { [script]: { type: 'string' } })), {}))
61
+ }
45
62
  }
46
- }), {})
47
63
  }
48
- }
49
- }
50
- }
51
- },
52
- required: ['name']
53
- }
64
+ },
65
+ required: ['name']
66
+ }
54
67
  };
55
- let DatabaseHandler = (_dec = (0, _default.order)('60'), (_class = class DatabaseHandler extends _default2.default {
56
- constructor(config) {
57
- super({ ...config,
58
- type: 'databases',
59
- stripUpdateFields: ['strategy', 'name']
60
- });
61
- }
62
-
63
- objString(db) {
64
- return super.objString({
65
- name: db.name,
66
- id: db.id
67
- });
68
- }
69
-
70
- getClientFN(fn) {
71
- if (fn === this.functions.update) {
72
- return (params, payload) => this.client.connections.get(params).then(connection => {
73
- payload.options = { ...connection.options,
74
- ...payload.options
75
- };
76
- return this.client.connections.update(params, payload);
77
- });
68
+ class DatabaseHandler extends default_1.default {
69
+ constructor(config) {
70
+ super(Object.assign(Object.assign({}, config), { type: 'databases', stripUpdateFields: ['strategy', 'name'] }));
78
71
  }
79
-
80
- return Reflect.get(this.client.connections, fn, this.client.connections);
81
- }
82
-
83
- async getType() {
84
- if (this.existing) return this.existing;
85
- this.existing = this.client.connections.getAll({
86
- strategy: 'auth0',
87
- paginate: true,
88
- include_totals: true
89
- });
90
- return this.existing;
91
- }
92
-
93
- async calcChanges(assets) {
94
- const {
95
- databases
96
- } = assets;
97
- if (!databases) return {};
98
- const clients = await this.client.clients.getAll({
99
- paginate: true,
100
- include_totals: true
101
- });
102
- const existingDatabasesConecctions = await this.client.connections.getAll({
103
- strategy: 'auth0',
104
- paginate: true,
105
- include_totals: true
106
- });
107
- const formatted = databases.map(db => {
108
- if (db.enabled_clients) {
109
- return { ...db,
110
- enabled_clients: (0, _utils.getEnabledClients)(assets, db, existingDatabasesConecctions, clients)
111
- };
112
- }
113
-
114
- return db;
115
- });
116
- return super.calcChanges({ ...assets,
117
- databases: formatted
118
- });
119
- }
120
-
121
- async processChanges(assets) {
122
- const {
123
- databases
124
- } = assets;
125
- if (!databases) return;
126
- const excludedConnections = assets.exclude && assets.exclude.databases || [];
127
- const changes = await this.calcChanges(assets);
128
- await super.processChanges(assets, (0, _utils.filterExcluded)(changes, excludedConnections));
129
- }
130
-
131
- }, (_applyDecoratedDescriptor(_class.prototype, "processChanges", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "processChanges"), _class.prototype)), _class));
132
- exports.default = DatabaseHandler;
72
+ objString(db) {
73
+ return super.objString({ name: db.name, id: db.id });
74
+ }
75
+ getClientFN(fn) {
76
+ // Override this as a database is actually a connection but we are treating them as a different object
77
+ // If we going to update database, we need to get current options first
78
+ if (fn === this.functions.update) {
79
+ return (params, payload) => this.client.connections.get(params)
80
+ .then((connection) => {
81
+ payload.options = Object.assign(Object.assign({}, connection.options), payload.options);
82
+ return this.client.connections.update(params, payload);
83
+ });
84
+ }
85
+ return this.client.connections[fn].bind(this.client.connections);
86
+ }
87
+ getType() {
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ if (this.existing)
90
+ return this.existing;
91
+ this.existing = this.client.connections.getAll({ strategy: 'auth0', paginate: true, include_totals: true });
92
+ return this.existing;
93
+ });
94
+ }
95
+ calcChanges(assets) {
96
+ const _super = Object.create(null, {
97
+ calcChanges: { get: () => super.calcChanges }
98
+ });
99
+ return __awaiter(this, void 0, void 0, function* () {
100
+ const { databases } = assets;
101
+ // Do nothing if not set
102
+ if (!databases)
103
+ return {};
104
+ // Convert enabled_clients by name to the id
105
+ const clients = yield this.client.clients.getAll({ paginate: true, include_totals: true });
106
+ const existingDatabasesConecctions = yield this.client.connections.getAll({ strategy: 'auth0', paginate: true, include_totals: true });
107
+ const formatted = databases.map((db) => {
108
+ if (db.enabled_clients) {
109
+ return Object.assign(Object.assign({}, db), { enabled_clients: (0, utils_1.getEnabledClients)(assets, db, existingDatabasesConecctions, clients) });
110
+ }
111
+ return db;
112
+ });
113
+ return _super.calcChanges.call(this, Object.assign(Object.assign({}, assets), { databases: formatted }));
114
+ });
115
+ }
116
+ // Run after clients are updated so we can convert all the enabled_clients names to id's
117
+ processChanges(assets) {
118
+ const _super = Object.create(null, {
119
+ processChanges: { get: () => super.processChanges }
120
+ });
121
+ return __awaiter(this, void 0, void 0, function* () {
122
+ const { databases } = assets;
123
+ // Do nothing if not set
124
+ if (!databases)
125
+ return;
126
+ const excludedConnections = (assets.exclude && assets.exclude.databases) || [];
127
+ const changes = yield this.calcChanges(assets);
128
+ yield _super.processChanges.call(this, assets, (0, utils_1.filterExcluded)(changes, excludedConnections));
129
+ });
130
+ }
131
+ }
132
+ __decorate([
133
+ (0, default_1.order)('60')
134
+ ], DatabaseHandler.prototype, "processChanges", null);
135
+ exports.default = DatabaseHandler;