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.
- package/.circleci/config.yml +15 -0
- package/.eslintrc +66 -17
- package/.github/CODEOWNERS +1 -0
- package/.husky/pre-commit +6 -0
- package/.husky/pre-push +4 -0
- package/CHANGELOG.md +37 -2
- package/lib/args.js +94 -81
- package/lib/commands/export.js +54 -78
- package/lib/commands/import.js +46 -70
- package/lib/commands/index.js +11 -20
- package/lib/configFactory.js +19 -27
- package/lib/context/defaults.js +18 -41
- package/lib/context/directory/handlers/actions.js +77 -107
- package/lib/context/directory/handlers/attackProtection.js +59 -0
- package/lib/context/directory/handlers/clientGrants.js +45 -54
- package/lib/context/directory/handlers/clients.js +60 -79
- package/lib/context/directory/handlers/connections.js +65 -89
- package/lib/context/directory/handlers/databases.js +91 -123
- package/lib/context/directory/handlers/emailProvider.js +46 -57
- package/lib/context/directory/handlers/emailTemplates.js +67 -80
- package/lib/context/directory/handlers/guardianFactorProviders.js +41 -49
- package/lib/context/directory/handlers/guardianFactorTemplates.js +41 -49
- package/lib/context/directory/handlers/guardianFactors.js +41 -49
- package/lib/context/directory/handlers/guardianPhoneFactorMessageTypes.js +40 -50
- package/lib/context/directory/handlers/guardianPhoneFactorSelectedProvider.js +40 -50
- package/lib/context/directory/handlers/guardianPolicies.js +40 -50
- package/lib/context/directory/handlers/hooks.js +55 -70
- package/lib/context/directory/handlers/index.js +53 -123
- package/lib/context/directory/handlers/migrations.js +36 -41
- package/lib/context/directory/handlers/organizations.js +54 -69
- package/lib/context/directory/handlers/pages.js +72 -86
- package/lib/context/directory/handlers/resourceServers.js +41 -49
- package/lib/context/directory/handlers/roles.js +49 -62
- package/lib/context/directory/handlers/rules.js +52 -68
- package/lib/context/directory/handlers/rulesConfigs.js +33 -32
- package/lib/context/directory/handlers/tenant.js +52 -47
- package/lib/context/directory/handlers/triggers.js +39 -54
- package/lib/context/directory/index.js +113 -101
- package/lib/context/index.js +96 -105
- package/lib/context/yaml/handlers/actions.js +71 -88
- package/lib/context/yaml/handlers/attackProtection.js +29 -0
- package/lib/context/yaml/handlers/clientGrants.js +36 -29
- package/lib/context/yaml/handlers/clients.js +61 -76
- package/lib/context/yaml/handlers/connections.js +76 -103
- package/lib/context/yaml/handlers/databases.js +64 -79
- package/lib/context/yaml/handlers/emailProvider.js +33 -30
- package/lib/context/yaml/handlers/emailTemplates.js +45 -54
- package/lib/context/yaml/handlers/guardianFactorProviders.js +27 -18
- package/lib/context/yaml/handlers/guardianFactorTemplates.js +27 -18
- package/lib/context/yaml/handlers/guardianFactors.js +27 -18
- package/lib/context/yaml/handlers/guardianPhoneFactorMessageTypes.js +27 -20
- package/lib/context/yaml/handlers/guardianPhoneFactorSelectedProvider.js +27 -20
- package/lib/context/yaml/handlers/guardianPolicies.js +27 -20
- package/lib/context/yaml/handlers/hooks.js +57 -67
- package/lib/context/yaml/handlers/index.js +53 -123
- package/lib/context/yaml/handlers/migrations.js +23 -24
- package/lib/context/yaml/handlers/organizations.js +40 -38
- package/lib/context/yaml/handlers/pages.js +49 -58
- package/lib/context/yaml/handlers/resourceServers.js +27 -18
- package/lib/context/yaml/handlers/roles.js +34 -24
- package/lib/context/yaml/handlers/rules.js +48 -58
- package/lib/context/yaml/handlers/rulesConfigs.js +27 -18
- package/lib/context/yaml/handlers/tenant.js +44 -30
- package/lib/context/yaml/handlers/triggers.js +32 -23
- package/lib/context/yaml/index.js +127 -142
- package/lib/index.js +73 -79
- package/lib/logger.js +18 -22
- package/lib/readonly.js +74 -66
- package/lib/tools/ValidationError.js +8 -13
- package/lib/tools/auth0/client.js +143 -133
- package/lib/tools/auth0/handlers/actions.js +231 -243
- package/lib/tools/auth0/handlers/attackProtection.js +86 -0
- package/lib/tools/auth0/handlers/branding.js +47 -46
- package/lib/tools/auth0/handlers/clientGrants.js +118 -116
- package/lib/tools/auth0/handlers/clients.js +72 -90
- package/lib/tools/auth0/handlers/connections.js +150 -118
- package/lib/tools/auth0/handlers/databases.js +127 -124
- package/lib/tools/auth0/handlers/default.js +186 -189
- package/lib/tools/auth0/handlers/emailProvider.js +67 -78
- package/lib/tools/auth0/handlers/emailTemplates.js +116 -92
- package/lib/tools/auth0/handlers/guardianFactorProviders.js +66 -81
- package/lib/tools/auth0/handlers/guardianFactorTemplates.js +60 -71
- package/lib/tools/auth0/handlers/guardianFactors.js +56 -63
- package/lib/tools/auth0/handlers/guardianPhoneFactorMessageTypes.js +80 -79
- package/lib/tools/auth0/handlers/guardianPhoneFactorSelectedProvider.js +77 -76
- package/lib/tools/auth0/handlers/guardianPolicies.js +59 -62
- package/lib/tools/auth0/handlers/hooks.js +201 -227
- package/lib/tools/auth0/handlers/index.js +53 -111
- package/lib/tools/auth0/handlers/migrations.js +99 -79
- package/lib/tools/auth0/handlers/organizations.js +225 -247
- package/lib/tools/auth0/handlers/pages.js +116 -154
- package/lib/tools/auth0/handlers/prompts.js +47 -46
- package/lib/tools/auth0/handlers/resourceServers.js +88 -112
- package/lib/tools/auth0/handlers/roles.js +203 -220
- package/lib/tools/auth0/handlers/rules.js +168 -189
- package/lib/tools/auth0/handlers/rulesConfigs.js +54 -63
- package/lib/tools/auth0/handlers/tenant.js +88 -64
- package/lib/tools/auth0/handlers/triggers.js +126 -126
- package/lib/tools/auth0/index.js +92 -85
- package/lib/tools/auth0/schema.js +39 -31
- package/lib/tools/constants.js +111 -21
- package/lib/tools/deploy.js +35 -32
- package/lib/tools/index.js +19 -32
- package/lib/tools/logger.js +11 -12
- package/lib/tools/utils.js +258 -254
- package/lib/utils.js +167 -190
- package/package.json +13 -17
- package/tsconfig.json +17 -0
- package/typescript-migration-progress.sh +22 -0
- package/.babelrc +0 -17
- package/.nyc_output/32e2bffd-d561-4814-9aa3-fe929a1e178a.json +0 -1
- package/.nyc_output/processinfo/32e2bffd-d561-4814-9aa3-fe929a1e178a.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
|
@@ -1,257 +1,235 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var _lodash2 = _interopRequireDefault(_lodash);
|
|
13
|
-
|
|
14
|
-
var _default = require("./default");
|
|
15
|
-
|
|
16
|
-
var _default2 = _interopRequireDefault(_default);
|
|
17
|
-
|
|
18
|
-
var _utils = require("../../utils");
|
|
19
|
-
|
|
20
|
-
var _logger = require("../../logger");
|
|
21
|
-
|
|
22
|
-
var _logger2 = _interopRequireDefault(_logger);
|
|
23
|
-
|
|
24
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
-
|
|
26
|
-
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; }
|
|
27
|
-
|
|
28
|
-
const schema = exports.schema = {
|
|
29
|
-
type: 'array',
|
|
30
|
-
items: {
|
|
31
|
-
type: 'object',
|
|
32
|
-
properties: {
|
|
33
|
-
name: {
|
|
34
|
-
type: 'string'
|
|
35
|
-
},
|
|
36
|
-
display_name: {
|
|
37
|
-
type: 'string'
|
|
38
|
-
},
|
|
39
|
-
branding: {
|
|
40
|
-
type: 'object'
|
|
41
|
-
},
|
|
42
|
-
metadata: {
|
|
43
|
-
type: 'object'
|
|
44
|
-
},
|
|
45
|
-
connections: {
|
|
46
|
-
type: 'array',
|
|
47
|
-
items: {
|
|
48
|
-
type: 'object',
|
|
49
|
-
properties: {
|
|
50
|
-
connection_id: {
|
|
51
|
-
type: 'string'
|
|
52
|
-
},
|
|
53
|
-
assign_membership_on_login: {
|
|
54
|
-
type: 'boolean'
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
required: ['name']
|
|
61
|
-
}
|
|
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;
|
|
62
23
|
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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());
|
|
75
38
|
});
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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 lodash_1 = __importDefault(require("lodash"));
|
|
46
|
+
const default_1 = __importStar(require("./default"));
|
|
47
|
+
const utils_1 = require("../../utils");
|
|
48
|
+
const logger_1 = __importDefault(require("../../logger"));
|
|
49
|
+
exports.schema = {
|
|
50
|
+
type: 'array',
|
|
51
|
+
items: {
|
|
52
|
+
type: 'object',
|
|
53
|
+
properties: {
|
|
54
|
+
name: { type: 'string' },
|
|
55
|
+
display_name: { type: 'string' },
|
|
56
|
+
branding: { type: 'object' },
|
|
57
|
+
metadata: { type: 'object' },
|
|
58
|
+
connections: {
|
|
59
|
+
type: 'array',
|
|
60
|
+
items: {
|
|
61
|
+
type: 'object',
|
|
62
|
+
properties: {
|
|
63
|
+
connection_id: { type: 'string' },
|
|
64
|
+
assign_membership_on_login: { type: 'boolean' }
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
required: ['name']
|
|
92
70
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
};
|
|
98
|
-
delete organization.connections;
|
|
99
|
-
const created = await this.client.organizations.create(organization);
|
|
100
|
-
|
|
101
|
-
if (typeof org.connections !== 'undefined' && org.connections.length > 0) {
|
|
102
|
-
await Promise.all(org.connections.map(conn => this.client.organizations.addEnabledConnection({
|
|
103
|
-
id: created.id
|
|
104
|
-
}, conn)));
|
|
71
|
+
};
|
|
72
|
+
class OrganizationsHandler extends default_1.default {
|
|
73
|
+
constructor(config) {
|
|
74
|
+
super(Object.assign(Object.assign({}, config), { type: 'organizations', id: 'id', identifiers: ['name'] }));
|
|
105
75
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
async createOrganizations(creates) {
|
|
111
|
-
await this.client.pool.addEachTask({
|
|
112
|
-
data: creates || [],
|
|
113
|
-
generator: item => this.createOrganization(item).then(data => {
|
|
114
|
-
this.didCreate(data);
|
|
115
|
-
this.created += 1;
|
|
116
|
-
}).catch(err => {
|
|
117
|
-
throw new Error(`Problem creating ${this.type} ${this.objString(item)}\n${err}`);
|
|
118
|
-
})
|
|
119
|
-
}).promise();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
async updateOrganization(org, organizations) {
|
|
123
|
-
const {
|
|
124
|
-
connections: existingConnections
|
|
125
|
-
} = await organizations.find(orgToUpdate => orgToUpdate.name === org.name);
|
|
126
|
-
const params = {
|
|
127
|
-
id: org.id
|
|
128
|
-
};
|
|
129
|
-
const {
|
|
130
|
-
connections
|
|
131
|
-
} = org;
|
|
132
|
-
delete org.connections;
|
|
133
|
-
delete org.name;
|
|
134
|
-
delete org.id;
|
|
135
|
-
await this.client.organizations.update(params, org);
|
|
136
|
-
const connectionsToRemove = existingConnections.filter(c => !connections.find(x => x.connection_id === c.connection_id));
|
|
137
|
-
const connectionsToAdd = connections.filter(c => !existingConnections.find(x => x.connection_id === c.connection_id));
|
|
138
|
-
const connectionsToUpdate = connections.filter(c => existingConnections.find(x => x.connection_id === c.connection_id && x.assign_membership_on_login !== c.assign_membership_on_login));
|
|
139
|
-
await Promise.all(connectionsToUpdate.map(conn => this.client.organizations.updateEnabledConnection({
|
|
140
|
-
connection_id: conn.connection_id,
|
|
141
|
-
...params
|
|
142
|
-
}, {
|
|
143
|
-
assign_membership_on_login: conn.assign_membership_on_login
|
|
144
|
-
}).catch(() => {
|
|
145
|
-
throw new Error(`Problem updating Enabled Connection ${conn.connection_id} for organizations ${params.id}`);
|
|
146
|
-
})));
|
|
147
|
-
await Promise.all(connectionsToAdd.map(conn => this.client.organizations.addEnabledConnection(params, _lodash2.default.omit(conn, 'connection')).catch(() => {
|
|
148
|
-
throw new Error(`Problem adding Enabled Connection ${conn.connection_id} for organizations ${params.id}`);
|
|
149
|
-
})));
|
|
150
|
-
await Promise.all(connectionsToRemove.map(conn => this.client.organizations.removeEnabledConnection({
|
|
151
|
-
connection_id: conn.connection_id,
|
|
152
|
-
...params
|
|
153
|
-
}).catch(() => {
|
|
154
|
-
throw new Error(`Problem removing Enabled Connection ${conn.connection_id} for organizations ${params.id}`);
|
|
155
|
-
})));
|
|
156
|
-
return params;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
async updateOrganizations(updates, orgs) {
|
|
160
|
-
await this.client.pool.addEachTask({
|
|
161
|
-
data: updates || [],
|
|
162
|
-
generator: item => this.updateOrganization(item, orgs).then(data => {
|
|
163
|
-
this.didUpdate(data);
|
|
164
|
-
this.updated += 1;
|
|
165
|
-
}).catch(err => {
|
|
166
|
-
throw new Error(`Problem updating ${this.type} ${this.objString(item)}\n${err}`);
|
|
167
|
-
})
|
|
168
|
-
}).promise();
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
async getType() {
|
|
172
|
-
if (this.existing) {
|
|
173
|
-
return this.existing;
|
|
76
|
+
deleteOrganization(org) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
yield this.client.organizations.delete({ id: org.id });
|
|
79
|
+
});
|
|
174
80
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
81
|
+
deleteOrganizations(data) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
if (this.config('AUTH0_ALLOW_DELETE') === 'true' || this.config('AUTH0_ALLOW_DELETE') === true) {
|
|
84
|
+
yield this.client.pool.addEachTask({
|
|
85
|
+
data: data || [],
|
|
86
|
+
generator: (item) => this.deleteOrganization(item).then(() => {
|
|
87
|
+
this.didDelete(item);
|
|
88
|
+
this.deleted += 1;
|
|
89
|
+
}).catch((err) => {
|
|
90
|
+
throw new Error(`Problem deleting ${this.type} ${this.objString(item)}\n${err}`);
|
|
91
|
+
})
|
|
92
|
+
}).promise();
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
logger_1.default.warn(`Detected the following organizations should be deleted. Doing so may be destructive.\nYou can enable deletes by setting 'AUTH0_ALLOW_DELETE' to true in the config
|
|
96
|
+
\n${data.map((i) => this.objString(i)).join('\n')}`);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
178
99
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
id: organizations[index].id
|
|
100
|
+
createOrganization(org) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
const organization = Object.assign({}, org);
|
|
103
|
+
delete organization.connections;
|
|
104
|
+
const created = yield this.client.organizations.create(organization);
|
|
105
|
+
if (typeof org.connections !== 'undefined' && org.connections.length > 0) {
|
|
106
|
+
yield Promise.all(org.connections.map((conn) => this.client.organizations.addEnabledConnection({ id: created.id }, conn)));
|
|
107
|
+
}
|
|
108
|
+
return created;
|
|
189
109
|
});
|
|
190
|
-
organizations[index].connections = connections;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
this.existing = organizations;
|
|
194
|
-
return this.existing;
|
|
195
|
-
} catch (err) {
|
|
196
|
-
if (err.statusCode === 404 || err.statusCode === 501) {
|
|
197
|
-
return [];
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
throw err;
|
|
201
110
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
|
|
111
|
+
createOrganizations(creates) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
yield this.client.pool.addEachTask({
|
|
114
|
+
data: creates || [],
|
|
115
|
+
generator: (item) => this.createOrganization(item).then((data) => {
|
|
116
|
+
this.didCreate(data);
|
|
117
|
+
this.created += 1;
|
|
118
|
+
}).catch((err) => {
|
|
119
|
+
throw new Error(`Problem creating ${this.type} ${this.objString(item)}\n${err}`);
|
|
120
|
+
})
|
|
121
|
+
}).promise();
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
updateOrganization(org, organizations) {
|
|
125
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
+
const { connections: existingConnections } = yield organizations.find((orgToUpdate) => orgToUpdate.name === org.name);
|
|
127
|
+
const params = { id: org.id };
|
|
128
|
+
const { connections } = org;
|
|
129
|
+
delete org.connections;
|
|
130
|
+
delete org.name;
|
|
131
|
+
delete org.id;
|
|
132
|
+
yield this.client.organizations.update(params, org);
|
|
133
|
+
const connectionsToRemove = existingConnections.filter((c) => !connections.find((x) => x.connection_id === c.connection_id));
|
|
134
|
+
const connectionsToAdd = connections.filter((c) => !existingConnections.find((x) => x.connection_id === c.connection_id));
|
|
135
|
+
const connectionsToUpdate = connections.filter((c) => existingConnections.find((x) => x.connection_id === c.connection_id && x.assign_membership_on_login !== c.assign_membership_on_login));
|
|
136
|
+
// Handle updates first
|
|
137
|
+
yield Promise.all(connectionsToUpdate.map((conn) => this.client.organizations
|
|
138
|
+
.updateEnabledConnection(Object.assign({ connection_id: conn.connection_id }, params), { assign_membership_on_login: conn.assign_membership_on_login })
|
|
139
|
+
.catch(() => {
|
|
140
|
+
throw new Error(`Problem updating Enabled Connection ${conn.connection_id} for organizations ${params.id}`);
|
|
141
|
+
})));
|
|
142
|
+
yield Promise.all(connectionsToAdd.map((conn) => this.client.organizations
|
|
143
|
+
.addEnabledConnection(params, lodash_1.default.omit(conn, 'connection'))
|
|
144
|
+
.catch(() => {
|
|
145
|
+
throw new Error(`Problem adding Enabled Connection ${conn.connection_id} for organizations ${params.id}`);
|
|
146
|
+
})));
|
|
147
|
+
yield Promise.all(connectionsToRemove.map((conn) => this.client.organizations
|
|
148
|
+
.removeEnabledConnection(Object.assign({ connection_id: conn.connection_id }, params))
|
|
149
|
+
.catch(() => {
|
|
150
|
+
throw new Error(`Problem removing Enabled Connection ${conn.connection_id} for organizations ${params.id}`);
|
|
151
|
+
})));
|
|
152
|
+
return params;
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
updateOrganizations(updates, orgs) {
|
|
156
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
157
|
+
yield this.client.pool.addEachTask({
|
|
158
|
+
data: updates || [],
|
|
159
|
+
generator: (item) => this.updateOrganization(item, orgs).then((data) => {
|
|
160
|
+
this.didUpdate(data);
|
|
161
|
+
this.updated += 1;
|
|
162
|
+
}).catch((err) => {
|
|
163
|
+
throw new Error(`Problem updating ${this.type} ${this.objString(item)}\n${err}`);
|
|
164
|
+
})
|
|
165
|
+
}).promise();
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
getType() {
|
|
169
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
170
|
+
if (this.existing) {
|
|
171
|
+
return this.existing;
|
|
172
|
+
}
|
|
173
|
+
if (!this.client.organizations || typeof this.client.organizations.getAll !== 'function') {
|
|
174
|
+
return [];
|
|
175
|
+
}
|
|
176
|
+
try {
|
|
177
|
+
const organizations = yield this.client.organizations.getAll({ checkpoint: true, include_totals: true });
|
|
178
|
+
for (let index = 0; index < organizations.length; index++) {
|
|
179
|
+
const connections = yield this.client.organizations.connections.get({ id: organizations[index].id });
|
|
180
|
+
organizations[index].connections = connections;
|
|
181
|
+
}
|
|
182
|
+
this.existing = organizations;
|
|
183
|
+
return this.existing;
|
|
184
|
+
}
|
|
185
|
+
catch (err) {
|
|
186
|
+
if (err.statusCode === 404 || err.statusCode === 501) {
|
|
187
|
+
return [];
|
|
188
|
+
}
|
|
189
|
+
throw err;
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
// Run after connections
|
|
194
|
+
processChanges(assets) {
|
|
195
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
196
|
+
const { organizations } = assets;
|
|
197
|
+
// Do nothing if not set
|
|
198
|
+
if (!organizations)
|
|
199
|
+
return;
|
|
200
|
+
// Gets organizations from destination tenant
|
|
201
|
+
const existing = yield this.getType();
|
|
202
|
+
const existingConnections = yield this.client.connections.getAll({ paginate: true, include_totals: true });
|
|
203
|
+
// We need to get the connection ids for the names configured so we can link them together
|
|
204
|
+
organizations.forEach((org) => {
|
|
205
|
+
org.connections = (org.connections || []).map((connection) => {
|
|
206
|
+
const { name } = connection;
|
|
207
|
+
delete connection.name;
|
|
208
|
+
return Object.assign(Object.assign({}, connection), { connection_id: (existingConnections.find((c) => c.name === name) || {}).id });
|
|
209
|
+
}).filter((connection) => !!connection.connection_id);
|
|
210
|
+
});
|
|
211
|
+
const changes = (0, utils_1.calcChanges)(this, organizations, existing, ['id', 'name']);
|
|
212
|
+
logger_1.default.debug(`Start processChanges for organizations [delete:${changes.del.length}] [update:${changes.update.length}], [create:${changes.create.length}]`);
|
|
213
|
+
const myChanges = [{ del: changes.del }, { create: changes.create }, { update: changes.update }];
|
|
214
|
+
yield Promise.all(myChanges.map((change) => __awaiter(this, void 0, void 0, function* () {
|
|
215
|
+
switch (true) {
|
|
216
|
+
case change.del && change.del.length > 0:
|
|
217
|
+
yield this.deleteOrganizations(change.del);
|
|
218
|
+
break;
|
|
219
|
+
case change.create && change.create.length > 0:
|
|
220
|
+
yield this.createOrganizations(changes.create);
|
|
221
|
+
break;
|
|
222
|
+
case change.update && change.update.length > 0:
|
|
223
|
+
yield this.updateOrganizations(change.update, existing);
|
|
224
|
+
break;
|
|
225
|
+
default:
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
})));
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
__decorate([
|
|
233
|
+
(0, default_1.order)('70')
|
|
234
|
+
], OrganizationsHandler.prototype, "processChanges", null);
|
|
235
|
+
exports.default = OrganizationsHandler;
|