@rockcarver/frodo-cli 2.0.0-32 → 2.0.0-33
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/CHANGELOG.md +5 -1
- package/esm/cli/FrodoCommand.js +8 -1
- package/esm/cli/FrodoCommand.js.map +1 -1
- package/esm/cli/admin/admin-export-full-cloud-config.js +44 -0
- package/esm/cli/admin/admin-export-full-cloud-config.js.map +1 -0
- package/esm/cli/admin/admin.js +1 -0
- package/esm/cli/admin/admin.js.map +1 -1
- package/esm/cli/authz/authz-policy-export.js +1 -1
- package/esm/cli/authz/authz-policy-export.js.map +1 -1
- package/esm/cli/authz/authz-policy-import.js +1 -1
- package/esm/cli/authz/authz-policy-import.js.map +1 -1
- package/esm/cli/authz/authz-policy-list.js +2 -2
- package/esm/cli/authz/authz-policy-list.js.map +1 -1
- package/esm/cli/authz/authz-set-delete.js +2 -2
- package/esm/cli/authz/authz-set-delete.js.map +1 -1
- package/esm/cli/authz/authz-set-export.js +1 -1
- package/esm/cli/authz/authz-set-export.js.map +1 -1
- package/esm/cli/authz/authz-set-import.js +1 -1
- package/esm/cli/authz/authz-set-import.js.map +1 -1
- package/esm/cli/authz/authz-set-list.js +1 -1
- package/esm/cli/authz/authz-set-list.js.map +1 -1
- package/esm/cli/authz/authz-type-delete.js +3 -3
- package/esm/cli/authz/authz-type-delete.js.map +1 -1
- package/esm/cli/authz/authz-type-export.js +2 -2
- package/esm/cli/authz/authz-type-export.js.map +1 -1
- package/esm/cli/authz/authz-type-import.js +2 -2
- package/esm/cli/authz/authz-type-import.js.map +1 -1
- package/esm/cli/authz/authz-type-list.js +1 -1
- package/esm/cli/authz/authz-type-list.js.map +1 -1
- package/esm/cli/email/email-template-export.js +3 -3
- package/esm/cli/email/email-template-export.js.map +1 -1
- package/esm/cli/email/email-template-import.js +4 -4
- package/esm/cli/email/email-template-import.js.map +1 -1
- package/esm/cli/email/email-template-list.js +1 -1
- package/esm/cli/email/email-template-list.js.map +1 -1
- package/esm/cli/idm/idm-count.js +1 -1
- package/esm/cli/idm/idm-count.js.map +1 -1
- package/esm/cli/idm/idm-export.js +3 -3
- package/esm/cli/idm/idm-export.js.map +1 -1
- package/esm/cli/idm/idm-list.js +2 -2
- package/esm/cli/idm/idm-list.js.map +1 -1
- package/esm/cli/idp/idp-export.js +3 -3
- package/esm/cli/idp/idp-export.js.map +1 -1
- package/esm/cli/idp/idp-import.js +4 -4
- package/esm/cli/idp/idp-import.js.map +1 -1
- package/esm/cli/idp/idp-list.js +1 -1
- package/esm/cli/idp/idp-list.js.map +1 -1
- package/esm/cli/journey/journey-delete.js +6 -2
- package/esm/cli/journey/journey-delete.js.map +1 -1
- package/esm/cli/journey/journey-disable.js +4 -10
- package/esm/cli/journey/journey-disable.js.map +1 -1
- package/esm/cli/journey/journey-enable.js +4 -10
- package/esm/cli/journey/journey-enable.js.map +1 -1
- package/esm/cli/journey/journey-import.js +4 -4
- package/esm/cli/journey/journey-import.js.map +1 -1
- package/esm/cli/journey/journey-list.js +1 -1
- package/esm/cli/journey/journey-list.js.map +1 -1
- package/esm/cli/saml/saml-cot-export.js +3 -3
- package/esm/cli/saml/saml-cot-export.js.map +1 -1
- package/esm/cli/saml/saml-cot-list.js +1 -1
- package/esm/cli/saml/saml-cot-list.js.map +1 -1
- package/esm/cli/saml/saml-describe.js +1 -1
- package/esm/cli/saml/saml-describe.js.map +1 -1
- package/esm/cli/saml/saml-import.js +4 -4
- package/esm/cli/saml/saml-import.js.map +1 -1
- package/esm/cli/saml/saml-list.js +1 -1
- package/esm/cli/saml/saml-list.js.map +1 -1
- package/esm/cli/saml/saml-metadata-export.js +1 -1
- package/esm/cli/saml/saml-metadata-export.js.map +1 -1
- package/esm/cli/script/script-export.js +2 -6
- package/esm/cli/script/script-export.js.map +1 -1
- package/esm/cli/theme/theme-delete.js +3 -3
- package/esm/cli/theme/theme-delete.js.map +1 -1
- package/esm/cli/theme/theme-export.js +4 -4
- package/esm/cli/theme/theme-export.js.map +1 -1
- package/esm/cli/theme/theme-import.js +4 -4
- package/esm/cli/theme/theme-import.js.map +1 -1
- package/esm/cli/theme/theme-list.js +1 -1
- package/esm/cli/theme/theme-list.js.map +1 -1
- package/esm/ops/AdminFederationOps.js +28 -26
- package/esm/ops/AdminFederationOps.js.map +1 -1
- package/esm/ops/AdminOps.js +112 -0
- package/esm/ops/AdminOps.js.map +1 -0
- package/esm/ops/AgentOps.js +59 -51
- package/esm/ops/AgentOps.js.map +1 -1
- package/esm/ops/ApplicationOps.js +19 -13
- package/esm/ops/ApplicationOps.js.map +1 -1
- package/esm/ops/CirclesOfTrustOps.js +28 -26
- package/esm/ops/CirclesOfTrustOps.js.map +1 -1
- package/esm/ops/EmailTemplateOps.js +78 -94
- package/esm/ops/EmailTemplateOps.js.map +1 -1
- package/esm/ops/IdmOps.js +8 -31
- package/esm/ops/IdmOps.js.map +1 -1
- package/esm/ops/IdpOps.js +49 -54
- package/esm/ops/IdpOps.js.map +1 -1
- package/esm/ops/JourneyOps.js +91 -70
- package/esm/ops/JourneyOps.js.map +1 -1
- package/esm/ops/OAuth2ClientOps.js +13 -11
- package/esm/ops/OAuth2ClientOps.js.map +1 -1
- package/esm/ops/PolicyOps.js +31 -26
- package/esm/ops/PolicyOps.js.map +1 -1
- package/esm/ops/PolicySetOps.js +42 -39
- package/esm/ops/PolicySetOps.js.map +1 -1
- package/esm/ops/ResourceTypeOps.js +19 -16
- package/esm/ops/ResourceTypeOps.js.map +1 -1
- package/esm/ops/Saml2Ops.js +49 -45
- package/esm/ops/Saml2Ops.js.map +1 -1
- package/esm/ops/ScriptOps.js +36 -55
- package/esm/ops/ScriptOps.js.map +1 -1
- package/esm/ops/SecretsOps.js +13 -11
- package/esm/ops/SecretsOps.js.map +1 -1
- package/esm/ops/ThemeOps.js +111 -130
- package/esm/ops/ThemeOps.js.map +1 -1
- package/esm/ops/VariablesOps.js +14 -12
- package/esm/ops/VariablesOps.js.map +1 -1
- package/esm/utils/Console.js +68 -30
- package/esm/utils/Console.js.map +1 -1
- package/esm/utils/ExportImportUtils.js +4 -12
- package/esm/utils/ExportImportUtils.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { frodo } from '@rockcarver/frodo-lib';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import { createProgressIndicator, createTable, debugMessage,
|
|
4
|
+
import { createProgressIndicator, createTable, debugMessage, printMessage, stopProgressIndicator, updateProgressIndicator } from '../utils/Console';
|
|
5
5
|
import { getTypedFilename, saveJsonToFile } from '../utils/ExportImportUtils';
|
|
6
6
|
import { cloneDeep } from './utils/OpsUtils';
|
|
7
7
|
import wordwrap from './utils/Wordwrap';
|
|
@@ -14,6 +14,7 @@ const {
|
|
|
14
14
|
EMAIL_TEMPLATE_TYPE,
|
|
15
15
|
readEmailTemplates,
|
|
16
16
|
readEmailTemplate,
|
|
17
|
+
exportEmailTemplates,
|
|
17
18
|
updateEmailTemplate
|
|
18
19
|
} = frodo.email.template;
|
|
19
20
|
const EMAIL_TEMPLATE_FILE_TYPE = 'template.email';
|
|
@@ -110,16 +111,16 @@ export async function exportEmailTemplateToFile(templateId, file) {
|
|
|
110
111
|
fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);
|
|
111
112
|
}
|
|
112
113
|
const filePath = getFilePath(fileName, true);
|
|
113
|
-
createProgressIndicator('determinate', 1, `Exporting ${templateId}`);
|
|
114
|
+
const indicatorId = createProgressIndicator('determinate', 1, `Exporting ${templateId}`);
|
|
114
115
|
try {
|
|
115
116
|
const templateData = await readEmailTemplate(templateId);
|
|
116
|
-
updateProgressIndicator(`Writing file ${filePath}`);
|
|
117
|
+
updateProgressIndicator(indicatorId, `Writing file ${filePath}`);
|
|
117
118
|
const fileData = getFileDataTemplate();
|
|
118
119
|
fileData.emailTemplate[templateId] = templateData;
|
|
119
120
|
saveJsonToFile(fileData, filePath);
|
|
120
|
-
stopProgressIndicator(`Exported ${templateId['brightCyan']} to ${filePath['brightCyan']}.`);
|
|
121
|
+
stopProgressIndicator(indicatorId, `Exported ${templateId['brightCyan']} to ${filePath['brightCyan']}.`);
|
|
121
122
|
} catch (err) {
|
|
122
|
-
stopProgressIndicator(`${err}`);
|
|
123
|
+
stopProgressIndicator(indicatorId, `${err}`);
|
|
123
124
|
printMessage(err, 'error');
|
|
124
125
|
}
|
|
125
126
|
}
|
|
@@ -135,18 +136,9 @@ export async function exportEmailTemplatesToFile(file) {
|
|
|
135
136
|
}
|
|
136
137
|
const filePath = getFilePath(fileName, true);
|
|
137
138
|
try {
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
createProgressIndicator('determinate', templates.length, 'Exporting email templates');
|
|
141
|
-
for (const template of templates) {
|
|
142
|
-
const templateId = template._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');
|
|
143
|
-
updateProgressIndicator(`Exporting ${templateId}`);
|
|
144
|
-
fileData.emailTemplate[templateId] = template;
|
|
145
|
-
}
|
|
146
|
-
saveJsonToFile(fileData, filePath);
|
|
147
|
-
stopProgressIndicator(`${templates.length} templates exported to ${filePath}.`);
|
|
139
|
+
const exportData = await exportEmailTemplates();
|
|
140
|
+
saveJsonToFile(exportData, filePath);
|
|
148
141
|
} catch (err) {
|
|
149
|
-
stopProgressIndicator(`${err}`);
|
|
150
142
|
printMessage(err, 'error');
|
|
151
143
|
}
|
|
152
144
|
}
|
|
@@ -155,20 +147,20 @@ export async function exportEmailTemplatesToFile(file) {
|
|
|
155
147
|
* Export all email templates to separate files
|
|
156
148
|
*/
|
|
157
149
|
export async function exportEmailTemplatesToFiles() {
|
|
150
|
+
let indicatorId;
|
|
158
151
|
try {
|
|
159
|
-
const
|
|
160
|
-
createProgressIndicator('determinate',
|
|
161
|
-
for (const template of
|
|
162
|
-
const templateId = template._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');
|
|
152
|
+
const exportData = Object.entries((await exportEmailTemplates()).emailTemplate);
|
|
153
|
+
indicatorId = createProgressIndicator('determinate', exportData.length, 'Writing email templates');
|
|
154
|
+
for (const [templateId, template] of exportData) {
|
|
163
155
|
const fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);
|
|
164
156
|
const fileData = getFileDataTemplate();
|
|
165
|
-
updateProgressIndicator(`Exporting ${templateId}`);
|
|
157
|
+
updateProgressIndicator(indicatorId, `Exporting ${templateId}`);
|
|
166
158
|
fileData.emailTemplate[templateId] = template;
|
|
167
159
|
saveJsonToFile(fileData, getFilePath(fileName, true));
|
|
168
160
|
}
|
|
169
|
-
stopProgressIndicator(`${
|
|
161
|
+
stopProgressIndicator(indicatorId, `${exportData.length} templates written.`);
|
|
170
162
|
} catch (err) {
|
|
171
|
-
stopProgressIndicator(`${err}`);
|
|
163
|
+
stopProgressIndicator(indicatorId, `${err}`);
|
|
172
164
|
printMessage(err, 'error');
|
|
173
165
|
}
|
|
174
166
|
}
|
|
@@ -182,29 +174,27 @@ export async function exportEmailTemplatesToFiles() {
|
|
|
182
174
|
export async function importEmailTemplateFromFile(templateId, file, raw = false) {
|
|
183
175
|
templateId = templateId.replaceAll(`${EMAIL_TEMPLATE_TYPE}/`, '');
|
|
184
176
|
const filePath = getFilePath(file);
|
|
185
|
-
|
|
186
|
-
|
|
177
|
+
try {
|
|
178
|
+
const data = fs.readFileSync(filePath, 'utf8');
|
|
187
179
|
const fileData = JSON.parse(data);
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
printMessage(updateEmailTemplateError, 'error');
|
|
199
|
-
}
|
|
200
|
-
} else {
|
|
201
|
-
stopProgressIndicator(`Email template ${templateId} not found in ${filePath}!`);
|
|
202
|
-
printMessage(`Email template ${templateId} not found in ${filePath}!`, 'error');
|
|
180
|
+
const indicatorId = createProgressIndicator('determinate', 1, `Importing ${templateId}`);
|
|
181
|
+
if (fileData.emailTemplate && fileData.emailTemplate[templateId] || raw && getTemplateIdFromFileName(file) === templateId) {
|
|
182
|
+
try {
|
|
183
|
+
const emailTemplateData = raw ? s2sConvert(fileData) : fileData.emailTemplate[templateId];
|
|
184
|
+
await updateEmailTemplate(templateId, emailTemplateData);
|
|
185
|
+
updateProgressIndicator(indicatorId, `Importing ${templateId}`);
|
|
186
|
+
stopProgressIndicator(indicatorId, `Imported ${templateId}`);
|
|
187
|
+
} catch (updateEmailTemplateError) {
|
|
188
|
+
stopProgressIndicator(indicatorId, `${updateEmailTemplateError}`);
|
|
189
|
+
printMessage(updateEmailTemplateError, 'error');
|
|
203
190
|
}
|
|
204
191
|
} else {
|
|
205
|
-
|
|
192
|
+
stopProgressIndicator(indicatorId, `Email template ${templateId} not found in ${filePath}!`);
|
|
193
|
+
printMessage(`Email template ${templateId} not found in ${filePath}!`, 'error');
|
|
206
194
|
}
|
|
207
|
-
})
|
|
195
|
+
} catch (error) {
|
|
196
|
+
printMessage(`Error importing email template ${templateId}: ${error}`, 'error');
|
|
197
|
+
}
|
|
208
198
|
}
|
|
209
199
|
|
|
210
200
|
/**
|
|
@@ -212,28 +202,24 @@ export async function importEmailTemplateFromFile(templateId, file, raw = false)
|
|
|
212
202
|
* @param {string} file optional filename
|
|
213
203
|
*/
|
|
214
204
|
export async function importEmailTemplatesFromFile(file) {
|
|
215
|
-
|
|
216
|
-
|
|
205
|
+
try {
|
|
206
|
+
const data = fs.readFileSync(getFilePath(file), 'utf8');
|
|
217
207
|
const fileData = JSON.parse(data);
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
printMessage(`\nError importing ${templateId}`, 'error');
|
|
228
|
-
printMessage(updateEmailTemplateError.response.data, 'error');
|
|
229
|
-
}
|
|
230
|
-
}
|
|
208
|
+
const indicatorId = createProgressIndicator('determinate', Object.keys(fileData.emailTemplate).length, `Importing email templates`);
|
|
209
|
+
for (const id of Object.keys(fileData.emailTemplate)) {
|
|
210
|
+
const templateId = id.replace(regexEmailTemplateType, '');
|
|
211
|
+
try {
|
|
212
|
+
await updateEmailTemplate(templateId, fileData.emailTemplate[templateId]);
|
|
213
|
+
updateProgressIndicator(indicatorId, `Imported ${templateId}`);
|
|
214
|
+
} catch (updateEmailTemplateError) {
|
|
215
|
+
printMessage(`\nError importing ${templateId}`, 'error');
|
|
216
|
+
printMessage(updateEmailTemplateError.response.data, 'error');
|
|
231
217
|
}
|
|
232
|
-
stopProgressIndicator(`Done.`);
|
|
233
|
-
} else {
|
|
234
|
-
printMessage('Import validation failed...', 'error');
|
|
235
218
|
}
|
|
236
|
-
|
|
219
|
+
stopProgressIndicator(indicatorId, `Done.`);
|
|
220
|
+
} catch (error) {
|
|
221
|
+
printMessage(`Error importing email templates: ${error}`, 'error');
|
|
222
|
+
}
|
|
237
223
|
}
|
|
238
224
|
|
|
239
225
|
/**
|
|
@@ -276,7 +262,7 @@ function s2sConvert(templateData) {
|
|
|
276
262
|
export async function importEmailTemplatesFromFiles(raw = false) {
|
|
277
263
|
const names = fs.readdirSync(getWorkingDirectory());
|
|
278
264
|
const jsonFiles = names.filter(name => raw ? name.startsWith(`${EMAIL_TEMPLATE_TYPE}-`) && name.endsWith(`.json`) : name.toLowerCase().endsWith(`${EMAIL_TEMPLATE_FILE_TYPE}.json`)).map(name => getFilePath(name));
|
|
279
|
-
createProgressIndicator('determinate', jsonFiles.length, 'Importing email templates...');
|
|
265
|
+
const indicatorId = createProgressIndicator('determinate', jsonFiles.length, 'Importing email templates...');
|
|
280
266
|
let total = 0;
|
|
281
267
|
let totalErrors = 0;
|
|
282
268
|
for (const file of jsonFiles) {
|
|
@@ -313,12 +299,12 @@ export async function importEmailTemplatesFromFiles(raw = false) {
|
|
|
313
299
|
}
|
|
314
300
|
}
|
|
315
301
|
totalErrors += errors;
|
|
316
|
-
updateProgressIndicator(`Imported ${file}`);
|
|
302
|
+
updateProgressIndicator(indicatorId, `Imported ${file}`);
|
|
317
303
|
} else {
|
|
318
304
|
printMessage(`Validation of ${file} failed!`, 'error');
|
|
319
305
|
}
|
|
320
306
|
}
|
|
321
|
-
stopProgressIndicator(`Imported ${total - totalErrors} of ${total} email template(s) from ${jsonFiles.length} file(s).`);
|
|
307
|
+
stopProgressIndicator(indicatorId, `Imported ${total - totalErrors} of ${total} email template(s) from ${jsonFiles.length} file(s).`);
|
|
322
308
|
}
|
|
323
309
|
|
|
324
310
|
/**
|
|
@@ -326,40 +312,38 @@ export async function importEmailTemplatesFromFiles(raw = false) {
|
|
|
326
312
|
* @param {String} file optional filename
|
|
327
313
|
*/
|
|
328
314
|
export async function importFirstEmailTemplateFromFile(file, raw = false) {
|
|
329
|
-
|
|
330
|
-
|
|
315
|
+
let indicatorId;
|
|
316
|
+
try {
|
|
317
|
+
const data = fs.readFileSync(getFilePath(file), 'utf8');
|
|
331
318
|
const fileData = JSON.parse(data);
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
319
|
+
indicatorId = createProgressIndicator('indeterminate', 0, `Importing first email template`);
|
|
320
|
+
if (raw) {
|
|
321
|
+
try {
|
|
322
|
+
const templateId = getTemplateIdFromFileName(file);
|
|
323
|
+
const templateData = s2sConvert(fileData);
|
|
324
|
+
await updateEmailTemplate(templateId, templateData);
|
|
325
|
+
stopProgressIndicator(indicatorId, `Imported ${templateId}`, 'success');
|
|
326
|
+
} catch (error) {
|
|
327
|
+
var _error$response;
|
|
328
|
+
stopProgressIndicator(indicatorId, `Error importing email template: ${error}`, 'fail');
|
|
329
|
+
printMessage((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data, 'error');
|
|
330
|
+
}
|
|
331
|
+
} else {
|
|
332
|
+
for (const id of Object.keys(fileData.emailTemplate)) {
|
|
335
333
|
try {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
failSpinner(`Error importing email template: ${error}`);
|
|
343
|
-
printMessage((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data, 'error');
|
|
344
|
-
}
|
|
345
|
-
} else {
|
|
346
|
-
for (const id in fileData.emailTemplate) {
|
|
347
|
-
if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {
|
|
348
|
-
try {
|
|
349
|
-
await updateEmailTemplate(id.replace(regexEmailTemplateType, ''), fileData.emailTemplate[id]);
|
|
350
|
-
succeedSpinner(`Imported ${id}`);
|
|
351
|
-
} catch (updateEmailTemplateError) {
|
|
352
|
-
var _updateEmailTemplateE2;
|
|
353
|
-
failSpinner(`Error importing ${id}`);
|
|
354
|
-
printMessage((_updateEmailTemplateE2 = updateEmailTemplateError.response) === null || _updateEmailTemplateE2 === void 0 ? void 0 : _updateEmailTemplateE2.data, 'error');
|
|
355
|
-
}
|
|
356
|
-
break;
|
|
357
|
-
}
|
|
334
|
+
await updateEmailTemplate(id.replace(regexEmailTemplateType, ''), fileData.emailTemplate[id]);
|
|
335
|
+
stopProgressIndicator(indicatorId, `Imported ${id}`, 'success');
|
|
336
|
+
} catch (updateEmailTemplateError) {
|
|
337
|
+
var _updateEmailTemplateE2;
|
|
338
|
+
stopProgressIndicator(indicatorId, `Error importing ${id}`, 'fail');
|
|
339
|
+
printMessage((_updateEmailTemplateE2 = updateEmailTemplateError.response) === null || _updateEmailTemplateE2 === void 0 ? void 0 : _updateEmailTemplateE2.data, 'error');
|
|
358
340
|
}
|
|
341
|
+
break;
|
|
359
342
|
}
|
|
360
|
-
} else {
|
|
361
|
-
printMessage('Import validation failed...', 'error');
|
|
362
343
|
}
|
|
363
|
-
})
|
|
344
|
+
} catch (error) {
|
|
345
|
+
stopProgressIndicator(indicatorId, `Error importing first email template`, 'fail');
|
|
346
|
+
printMessage(`Error importing first email template: ${error}`, 'error');
|
|
347
|
+
}
|
|
364
348
|
}
|
|
365
349
|
//# sourceMappingURL=EmailTemplateOps.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmailTemplateOps.js","names":["frodo","fs","path","createProgressIndicator","createTable","debugMessage","failSpinner","printMessage","showSpinner","stopProgressIndicator","succeedSpinner","updateProgressIndicator","getTypedFilename","saveJsonToFile","cloneDeep","wordwrap","validateImport","getFilePath","getWorkingDirectory","utils","EMAIL_TEMPLATE_TYPE","readEmailTemplates","readEmailTemplate","updateEmailTemplate","email","template","EMAIL_TEMPLATE_FILE_TYPE","regexEmailTemplateType","RegExp","getFileDataTemplate","meta","emailTemplate","getOneLineDescription","templateObj","description","_id","split","displayName","defaultLocale","subject","Object","values","getTableHeaderMd","markdown","getTableRowMd","templateId","replace","locales","keys","length","filter","locale","join","row","name","listEmailTemplates","long","emailTemplates","error","message","sort","a","b","localeCompare","entries","table","push","enabled","from","toString","exportEmailTemplateToFile","file","fileName","filePath","templateData","fileData","err","exportEmailTemplatesToFile","templates","exportEmailTemplatesToFiles","importEmailTemplateFromFile","raw","replaceAll","readFile","data","JSON","parse","getTemplateIdFromFileName","emailTemplateData","s2sConvert","updateEmailTemplateError","importEmailTemplatesFromFile","id","hasOwnProperty","call","response","basename","Error","html","convertedData","importEmailTemplatesFromFiles","names","readdirSync","jsonFiles","startsWith","endsWith","toLowerCase","map","total","totalErrors","readFileSync","errors","_updateEmailTemplateE","importFirstEmailTemplateFromFile","_error$response","_updateEmailTemplateE2"],"sources":["../../src/ops/EmailTemplateOps.ts"],"sourcesContent":["import { frodo } from '@rockcarver/frodo-lib';\nimport { EmailTemplateSkeleton } from '@rockcarver/frodo-lib/types/ops/EmailTemplateOps';\nimport fs from 'fs';\nimport path from 'path';\n\nimport {\n createProgressIndicator,\n createTable,\n debugMessage,\n failSpinner,\n printMessage,\n showSpinner,\n stopProgressIndicator,\n succeedSpinner,\n updateProgressIndicator,\n} from '../utils/Console';\nimport { getTypedFilename, saveJsonToFile } from '../utils/ExportImportUtils';\nimport { cloneDeep } from './utils/OpsUtils';\nimport wordwrap from './utils/Wordwrap';\n\nconst { validateImport, getFilePath, getWorkingDirectory } = frodo.utils;\nconst {\n EMAIL_TEMPLATE_TYPE,\n readEmailTemplates,\n readEmailTemplate,\n updateEmailTemplate,\n} = frodo.email.template;\n\nconst EMAIL_TEMPLATE_FILE_TYPE = 'template.email';\n\nconst regexEmailTemplateType = new RegExp(`${EMAIL_TEMPLATE_TYPE}/`, 'g');\n\n// use a function vs a template variable to avoid problems in loops\nfunction getFileDataTemplate() {\n return {\n meta: {},\n emailTemplate: {},\n };\n}\n\n/**\n * Get a one-line description of the email template\n * @param {EmailTemplateSkeleton} templateObj email template object to describe\n * @returns {string} a one-line description\n */\nexport function getOneLineDescription(\n templateObj: EmailTemplateSkeleton\n): string {\n const description = `[${templateObj._id.split('/')[1]['brightCyan']}] ${\n templateObj.displayName ? templateObj.displayName : ''\n } - ${\n templateObj.defaultLocale\n ? templateObj.subject[templateObj.defaultLocale]\n : Object.values(templateObj.subject)[0]\n }`;\n return description;\n}\n\n/**\n * Get markdown table header\n * @returns {string} markdown table header\n */\nexport function getTableHeaderMd(): string {\n let markdown = '';\n markdown += '| Display Name | Locale(s) | Subject | Id |\\n';\n markdown += '| ------------ | --------- | ------- | ---|';\n return markdown;\n}\n\n/**\n * Get a table-row of the email template in markdown\n * @param {EmailTemplateSkeleton} templateObj email template object to describe\n * @returns {string} a table-row of the email template in markdown\n */\nexport function getTableRowMd(templateObj: EmailTemplateSkeleton): string {\n const templateId = templateObj._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');\n const locales = `${templateObj.defaultLocale}${\n Object.keys(templateObj.subject).length > 1\n ? ` (${Object.keys(templateObj.subject)\n .filter((locale) => locale !== templateObj.defaultLocale)\n .join(',')})`\n : ''\n }`;\n const row = `| ${\n templateObj.name ? templateObj.name : templateId\n } | ${locales} | ${\n templateObj.subject[templateObj.defaultLocale]\n } | \\`${templateId}\\` |`;\n return row;\n}\n\n/**\n * List email templates\n * @param {boolean} long Long list format with details\n * @return {Promise<unknown[]>} a promise that resolves to an array of email template objects\n */\nexport async function listEmailTemplates(long = false): Promise<unknown[]> {\n let emailTemplates = [];\n try {\n emailTemplates = await readEmailTemplates();\n } catch (error) {\n printMessage(`Error retrieving email templates: ${error.message}`, 'error');\n }\n emailTemplates.sort((a, b) => a._id.localeCompare(b._id));\n if (!long) {\n for (const [, emailTemplate] of emailTemplates.entries()) {\n printMessage(\n `${emailTemplate._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '')}`,\n 'data'\n );\n }\n } else {\n const table = createTable([\n 'Id'['brightCyan'],\n 'Name'['brightCyan'],\n 'Status'['brightCyan'],\n 'Locale(s)'['brightCyan'],\n 'From'['brightCyan'],\n 'Subject'['brightCyan'],\n ]);\n for (const emailTemplate of emailTemplates) {\n table.push([\n // Id\n `${emailTemplate._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '')}`,\n // Name\n `${emailTemplate.displayName ? emailTemplate.displayName : ''}`,\n // Status\n emailTemplate.enabled === false\n ? 'disabled'['brightRed']\n : 'enabled'['brightGreen'],\n // Locale(s)\n `${emailTemplate.defaultLocale}${\n Object.keys(emailTemplate.subject).length > 1\n ? ` (${Object.keys(emailTemplate.subject)\n .filter((locale) => locale !== emailTemplate.defaultLocale)\n .join(',')})`\n : ''\n }`,\n // From\n `${emailTemplate.from ? emailTemplate.from : ''}`,\n // Subject\n wordwrap(emailTemplate.subject[emailTemplate.defaultLocale], 40),\n ]);\n }\n printMessage(table.toString(), 'data');\n }\n return emailTemplates;\n}\n\n/**\n * Export single email template to a file\n * @param {string} templateId email template id to export\n * @param {string} file filename where to export the template data\n */\nexport async function exportEmailTemplateToFile(\n templateId: string,\n file: string\n) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);\n }\n const filePath = getFilePath(fileName, true);\n createProgressIndicator('determinate', 1, `Exporting ${templateId}`);\n try {\n const templateData = await readEmailTemplate(templateId);\n updateProgressIndicator(`Writing file ${filePath}`);\n const fileData = getFileDataTemplate();\n fileData.emailTemplate[templateId] = templateData;\n saveJsonToFile(fileData, filePath);\n stopProgressIndicator(\n `Exported ${templateId['brightCyan']} to ${filePath['brightCyan']}.`\n );\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export all email templates to file\n * @param {String} file optional filename\n */\nexport async function exportEmailTemplatesToFile(file) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(`allEmailTemplates`, EMAIL_TEMPLATE_FILE_TYPE);\n }\n const filePath = getFilePath(fileName, true);\n try {\n const fileData = getFileDataTemplate();\n const templates = await readEmailTemplates();\n createProgressIndicator(\n 'determinate',\n templates.length,\n 'Exporting email templates'\n );\n for (const template of templates) {\n const templateId = template._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');\n updateProgressIndicator(`Exporting ${templateId}`);\n fileData.emailTemplate[templateId] = template;\n }\n saveJsonToFile(fileData, filePath);\n stopProgressIndicator(\n `${templates.length} templates exported to ${filePath}.`\n );\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export all email templates to separate files\n */\nexport async function exportEmailTemplatesToFiles() {\n try {\n const templates = await readEmailTemplates();\n createProgressIndicator(\n 'determinate',\n templates.length,\n 'Exporting email templates'\n );\n for (const template of templates) {\n const templateId = template._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');\n const fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);\n const fileData = getFileDataTemplate();\n updateProgressIndicator(`Exporting ${templateId}`);\n fileData.emailTemplate[templateId] = template;\n saveJsonToFile(fileData, getFilePath(fileName, true));\n }\n stopProgressIndicator(`${templates.length} templates exported.`);\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Import email template by id from file\n * @param {string} templateId email template id\n * @param {string} file optional filename\n * @param {boolean} raw import raw data file lacking frodo export envelop\n */\nexport async function importEmailTemplateFromFile(\n templateId: string,\n file: string,\n raw = false\n) {\n templateId = templateId.replaceAll(`${EMAIL_TEMPLATE_TYPE}/`, '');\n const filePath = getFilePath(file);\n fs.readFile(filePath, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (raw || validateImport(fileData.meta)) {\n createProgressIndicator('determinate', 1, `Importing ${templateId}`);\n if (\n (fileData.emailTemplate && fileData.emailTemplate[templateId]) ||\n (raw && getTemplateIdFromFileName(file) === templateId)\n ) {\n try {\n const emailTemplateData = raw\n ? s2sConvert(fileData)\n : fileData.emailTemplate[templateId];\n await updateEmailTemplate(templateId, emailTemplateData);\n updateProgressIndicator(`Importing ${templateId}`);\n stopProgressIndicator(`Imported ${templateId}`);\n } catch (updateEmailTemplateError) {\n stopProgressIndicator(`${updateEmailTemplateError}`);\n printMessage(updateEmailTemplateError, 'error');\n }\n } else {\n stopProgressIndicator(\n `Email template ${templateId} not found in ${filePath}!`\n );\n printMessage(\n `Email template ${templateId} not found in ${filePath}!`,\n 'error'\n );\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import all email templates from file\n * @param {string} file optional filename\n */\nexport async function importEmailTemplatesFromFile(file: string) {\n fs.readFile(getFilePath(file), 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(\n 'determinate',\n Object.keys(fileData.emailTemplate).length,\n `Importing email templates`\n );\n for (const id in fileData.emailTemplate) {\n if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {\n const templateId = id.replace(regexEmailTemplateType, '');\n try {\n await updateEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n updateProgressIndicator(`Imported ${templateId}`);\n } catch (updateEmailTemplateError) {\n printMessage(`\\nError importing ${templateId}`, 'error');\n printMessage(updateEmailTemplateError.response.data, 'error');\n }\n }\n }\n stopProgressIndicator(`Done.`);\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Helper function to get email template id from file name\n * @param {string} file file name\n * @returns {string} email template id/name\n */\nfunction getTemplateIdFromFileName(file: string) {\n debugMessage(`cli.EmailTemplateOps.getTemplateIdFromFileName: file=${file}`);\n const basename = path.basename(file);\n const keys = basename.split('-');\n if (keys[0] !== EMAIL_TEMPLATE_TYPE || keys.length <= 1)\n throw new Error(`Filename does not indicate a raw email template: ${file}`);\n const templateId = keys[1].split('.')[0];\n debugMessage(\n `cli.EmailTemplateOps.getTemplateIdFromFileName: templateId=${templateId}`\n );\n return templateId;\n}\n\n/**\n * Convert template for s2s purposes (software-to-saas migration)\n * @param {EmailTemplateSkeleton} templateData template object\n * @returns {EmailTemplateSkeleton} converted template object\n */\nfunction s2sConvert(\n templateData: EmailTemplateSkeleton\n): EmailTemplateSkeleton {\n if (templateData.message && !templateData.html) {\n const convertedData = cloneDeep(templateData);\n convertedData.html = cloneDeep(templateData.message);\n debugMessage(`cli.EmailTemplateOps.s2sConvert: templateData:`);\n debugMessage(templateData);\n debugMessage(`cli.EmailTemplateOps.s2sConvert: convertedData:`);\n debugMessage(convertedData);\n return convertedData;\n }\n return templateData;\n}\n\n/**\n * Import all email templates from separate files\n * @param {boolean} raw import raw data file lacking frodo export envelop\n */\nexport async function importEmailTemplatesFromFiles(raw = false) {\n const names = fs.readdirSync(getWorkingDirectory());\n const jsonFiles = names\n .filter((name) =>\n raw\n ? name.startsWith(`${EMAIL_TEMPLATE_TYPE}-`) && name.endsWith(`.json`)\n : name.toLowerCase().endsWith(`${EMAIL_TEMPLATE_FILE_TYPE}.json`)\n )\n .map((name) => getFilePath(name));\n createProgressIndicator(\n 'determinate',\n jsonFiles.length,\n 'Importing email templates...'\n );\n let total = 0;\n let totalErrors = 0;\n for (const file of jsonFiles) {\n const data = fs.readFileSync(file, 'utf8');\n const fileData = JSON.parse(data);\n if (\n (raw && file.startsWith('emailTemplate-')) ||\n validateImport(fileData.meta)\n ) {\n let errors = 0;\n if (raw) {\n total++;\n const templateId = getTemplateIdFromFileName(file);\n try {\n const templateData = s2sConvert(fileData);\n await updateEmailTemplate(templateId, templateData);\n } catch (updateEmailTemplateError) {\n errors += 1;\n printMessage(`\\nError importing ${templateId}`, 'error');\n printMessage(updateEmailTemplateError, 'error');\n printMessage(updateEmailTemplateError.response?.data, 'error');\n }\n } else {\n total += Object.keys(fileData.emailTemplate).length;\n for (const id in fileData.emailTemplate) {\n if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {\n const templateId = id.replace(regexEmailTemplateType, '');\n try {\n await updateEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n } catch (updateEmailTemplateError) {\n errors += 1;\n printMessage(`\\nError importing ${templateId}`, 'error');\n printMessage(updateEmailTemplateError.response.data, 'error');\n }\n }\n }\n }\n totalErrors += errors;\n updateProgressIndicator(`Imported ${file}`);\n } else {\n printMessage(`Validation of ${file} failed!`, 'error');\n }\n }\n stopProgressIndicator(\n `Imported ${total - totalErrors} of ${total} email template(s) from ${\n jsonFiles.length\n } file(s).`\n );\n}\n\n/**\n * Import first email template from file\n * @param {String} file optional filename\n */\nexport async function importFirstEmailTemplateFromFile(\n file: string,\n raw = false\n) {\n fs.readFile(getFilePath(file), 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (raw || validateImport(fileData.meta)) {\n showSpinner(`Importing first email template`);\n if (raw) {\n try {\n const templateId = getTemplateIdFromFileName(file);\n const templateData = s2sConvert(fileData);\n await updateEmailTemplate(templateId, templateData);\n succeedSpinner(`Imported ${templateId}`);\n } catch (error) {\n failSpinner(`Error importing email template: ${error}`);\n printMessage(error.response?.data, 'error');\n }\n } else {\n for (const id in fileData.emailTemplate) {\n if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {\n try {\n await updateEmailTemplate(\n id.replace(regexEmailTemplateType, ''),\n fileData.emailTemplate[id]\n );\n succeedSpinner(`Imported ${id}`);\n } catch (updateEmailTemplateError) {\n failSpinner(`Error importing ${id}`);\n printMessage(updateEmailTemplateError.response?.data, 'error');\n }\n break;\n }\n }\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,uBAAuB;AAE7C,OAAOC,EAAE,MAAM,IAAI;AACnB,OAAOC,IAAI,MAAM,MAAM;AAEvB,SACEC,uBAAuB,EACvBC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,qBAAqB,EACrBC,cAAc,EACdC,uBAAuB,QAClB,kBAAkB;AACzB,SAASC,gBAAgB,EAAEC,cAAc,QAAQ,4BAA4B;AAC7E,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,OAAOC,QAAQ,MAAM,kBAAkB;AAEvC,MAAM;EAAEC,cAAc;EAAEC,WAAW;EAAEC;AAAoB,CAAC,GAAGlB,KAAK,CAACmB,KAAK;AACxE,MAAM;EACJC,mBAAmB;EACnBC,kBAAkB;EAClBC,iBAAiB;EACjBC;AACF,CAAC,GAAGvB,KAAK,CAACwB,KAAK,CAACC,QAAQ;AAExB,MAAMC,wBAAwB,GAAG,gBAAgB;AAEjD,MAAMC,sBAAsB,GAAG,IAAIC,MAAM,CAAE,GAAER,mBAAoB,GAAE,EAAE,GAAG,CAAC;;AAEzE;AACA,SAASS,mBAAmBA,CAAA,EAAG;EAC7B,OAAO;IACLC,IAAI,EAAE,CAAC,CAAC;IACRC,aAAa,EAAE,CAAC;EAClB,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CACnCC,WAAkC,EAC1B;EACR,MAAMC,WAAW,GAAI,IAAGD,WAAW,CAACE,GAAG,CAACC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAE,KAClEH,WAAW,CAACI,WAAW,GAAGJ,WAAW,CAACI,WAAW,GAAG,EACrD,MACCJ,WAAW,CAACK,aAAa,GACrBL,WAAW,CAACM,OAAO,CAACN,WAAW,CAACK,aAA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","fs","path","createProgressIndicator","createTable","debugMessage","printMessage","stopProgressIndicator","updateProgressIndicator","getTypedFilename","saveJsonToFile","cloneDeep","wordwrap","validateImport","getFilePath","getWorkingDirectory","utils","EMAIL_TEMPLATE_TYPE","readEmailTemplates","readEmailTemplate","exportEmailTemplates","updateEmailTemplate","email","template","EMAIL_TEMPLATE_FILE_TYPE","regexEmailTemplateType","RegExp","getFileDataTemplate","meta","emailTemplate","getOneLineDescription","templateObj","description","_id","split","displayName","defaultLocale","subject","Object","values","getTableHeaderMd","markdown","getTableRowMd","templateId","replace","locales","keys","length","filter","locale","join","row","name","listEmailTemplates","long","emailTemplates","error","message","sort","a","b","localeCompare","entries","table","push","enabled","from","toString","exportEmailTemplateToFile","file","fileName","filePath","indicatorId","templateData","fileData","err","exportEmailTemplatesToFile","exportData","exportEmailTemplatesToFiles","importEmailTemplateFromFile","raw","replaceAll","data","readFileSync","JSON","parse","getTemplateIdFromFileName","emailTemplateData","s2sConvert","updateEmailTemplateError","importEmailTemplatesFromFile","id","response","basename","Error","html","convertedData","importEmailTemplatesFromFiles","names","readdirSync","jsonFiles","startsWith","endsWith","toLowerCase","map","total","totalErrors","errors","_updateEmailTemplateE","hasOwnProperty","call","importFirstEmailTemplateFromFile","_error$response","_updateEmailTemplateE2"],"sources":["../../src/ops/EmailTemplateOps.ts"],"sourcesContent":["import { frodo } from '@rockcarver/frodo-lib';\nimport { EmailTemplateSkeleton } from '@rockcarver/frodo-lib/types/ops/EmailTemplateOps';\nimport fs from 'fs';\nimport path from 'path';\n\nimport {\n createProgressIndicator,\n createTable,\n debugMessage,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n} from '../utils/Console';\nimport { getTypedFilename, saveJsonToFile } from '../utils/ExportImportUtils';\nimport { cloneDeep } from './utils/OpsUtils';\nimport wordwrap from './utils/Wordwrap';\n\nconst { validateImport, getFilePath, getWorkingDirectory } = frodo.utils;\nconst {\n EMAIL_TEMPLATE_TYPE,\n readEmailTemplates,\n readEmailTemplate,\n exportEmailTemplates,\n updateEmailTemplate,\n} = frodo.email.template;\n\nconst EMAIL_TEMPLATE_FILE_TYPE = 'template.email';\n\nconst regexEmailTemplateType = new RegExp(`${EMAIL_TEMPLATE_TYPE}/`, 'g');\n\n// use a function vs a template variable to avoid problems in loops\nfunction getFileDataTemplate() {\n return {\n meta: {},\n emailTemplate: {},\n };\n}\n\n/**\n * Get a one-line description of the email template\n * @param {EmailTemplateSkeleton} templateObj email template object to describe\n * @returns {string} a one-line description\n */\nexport function getOneLineDescription(\n templateObj: EmailTemplateSkeleton\n): string {\n const description = `[${templateObj._id.split('/')[1]['brightCyan']}] ${\n templateObj.displayName ? templateObj.displayName : ''\n } - ${\n templateObj.defaultLocale\n ? templateObj.subject[templateObj.defaultLocale]\n : Object.values(templateObj.subject)[0]\n }`;\n return description;\n}\n\n/**\n * Get markdown table header\n * @returns {string} markdown table header\n */\nexport function getTableHeaderMd(): string {\n let markdown = '';\n markdown += '| Display Name | Locale(s) | Subject | Id |\\n';\n markdown += '| ------------ | --------- | ------- | ---|';\n return markdown;\n}\n\n/**\n * Get a table-row of the email template in markdown\n * @param {EmailTemplateSkeleton} templateObj email template object to describe\n * @returns {string} a table-row of the email template in markdown\n */\nexport function getTableRowMd(templateObj: EmailTemplateSkeleton): string {\n const templateId = templateObj._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');\n const locales = `${templateObj.defaultLocale}${\n Object.keys(templateObj.subject).length > 1\n ? ` (${Object.keys(templateObj.subject)\n .filter((locale) => locale !== templateObj.defaultLocale)\n .join(',')})`\n : ''\n }`;\n const row = `| ${\n templateObj.name ? templateObj.name : templateId\n } | ${locales} | ${\n templateObj.subject[templateObj.defaultLocale]\n } | \\`${templateId}\\` |`;\n return row;\n}\n\n/**\n * List email templates\n * @param {boolean} long Long list format with details\n * @return {Promise<unknown[]>} a promise that resolves to an array of email template objects\n */\nexport async function listEmailTemplates(long = false): Promise<unknown[]> {\n let emailTemplates = [];\n try {\n emailTemplates = await readEmailTemplates();\n } catch (error) {\n printMessage(`Error retrieving email templates: ${error.message}`, 'error');\n }\n emailTemplates.sort((a, b) => a._id.localeCompare(b._id));\n if (!long) {\n for (const [, emailTemplate] of emailTemplates.entries()) {\n printMessage(\n `${emailTemplate._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '')}`,\n 'data'\n );\n }\n } else {\n const table = createTable([\n 'Id'['brightCyan'],\n 'Name'['brightCyan'],\n 'Status'['brightCyan'],\n 'Locale(s)'['brightCyan'],\n 'From'['brightCyan'],\n 'Subject'['brightCyan'],\n ]);\n for (const emailTemplate of emailTemplates) {\n table.push([\n // Id\n `${emailTemplate._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '')}`,\n // Name\n `${emailTemplate.displayName ? emailTemplate.displayName : ''}`,\n // Status\n emailTemplate.enabled === false\n ? 'disabled'['brightRed']\n : 'enabled'['brightGreen'],\n // Locale(s)\n `${emailTemplate.defaultLocale}${\n Object.keys(emailTemplate.subject).length > 1\n ? ` (${Object.keys(emailTemplate.subject)\n .filter((locale) => locale !== emailTemplate.defaultLocale)\n .join(',')})`\n : ''\n }`,\n // From\n `${emailTemplate.from ? emailTemplate.from : ''}`,\n // Subject\n wordwrap(emailTemplate.subject[emailTemplate.defaultLocale], 40),\n ]);\n }\n printMessage(table.toString(), 'data');\n }\n return emailTemplates;\n}\n\n/**\n * Export single email template to a file\n * @param {string} templateId email template id to export\n * @param {string} file filename where to export the template data\n */\nexport async function exportEmailTemplateToFile(\n templateId: string,\n file: string\n) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);\n }\n const filePath = getFilePath(fileName, true);\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n `Exporting ${templateId}`\n );\n try {\n const templateData = await readEmailTemplate(templateId);\n updateProgressIndicator(indicatorId, `Writing file ${filePath}`);\n const fileData = getFileDataTemplate();\n fileData.emailTemplate[templateId] = templateData;\n saveJsonToFile(fileData, filePath);\n stopProgressIndicator(\n indicatorId,\n `Exported ${templateId['brightCyan']} to ${filePath['brightCyan']}.`\n );\n } catch (err) {\n stopProgressIndicator(indicatorId, `${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export all email templates to file\n * @param {String} file optional filename\n */\nexport async function exportEmailTemplatesToFile(file) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(`allEmailTemplates`, EMAIL_TEMPLATE_FILE_TYPE);\n }\n const filePath = getFilePath(fileName, true);\n try {\n const exportData = await exportEmailTemplates();\n saveJsonToFile(exportData, filePath);\n } catch (err) {\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export all email templates to separate files\n */\nexport async function exportEmailTemplatesToFiles() {\n let indicatorId: string;\n try {\n const exportData = Object.entries(\n (await exportEmailTemplates()).emailTemplate\n );\n indicatorId = createProgressIndicator(\n 'determinate',\n exportData.length,\n 'Writing email templates'\n );\n for (const [templateId, template] of exportData) {\n const fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);\n const fileData = getFileDataTemplate();\n updateProgressIndicator(indicatorId, `Exporting ${templateId}`);\n fileData.emailTemplate[templateId] = template;\n saveJsonToFile(fileData, getFilePath(fileName, true));\n }\n stopProgressIndicator(\n indicatorId,\n `${exportData.length} templates written.`\n );\n } catch (err) {\n stopProgressIndicator(indicatorId, `${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Import email template by id from file\n * @param {string} templateId email template id\n * @param {string} file optional filename\n * @param {boolean} raw import raw data file lacking frodo export envelop\n */\nexport async function importEmailTemplateFromFile(\n templateId: string,\n file: string,\n raw = false\n) {\n templateId = templateId.replaceAll(`${EMAIL_TEMPLATE_TYPE}/`, '');\n const filePath = getFilePath(file);\n try {\n const data = fs.readFileSync(filePath, 'utf8');\n const fileData = JSON.parse(data);\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n `Importing ${templateId}`\n );\n if (\n (fileData.emailTemplate && fileData.emailTemplate[templateId]) ||\n (raw && getTemplateIdFromFileName(file) === templateId)\n ) {\n try {\n const emailTemplateData = raw\n ? s2sConvert(fileData)\n : fileData.emailTemplate[templateId];\n await updateEmailTemplate(templateId, emailTemplateData);\n updateProgressIndicator(indicatorId, `Importing ${templateId}`);\n stopProgressIndicator(indicatorId, `Imported ${templateId}`);\n } catch (updateEmailTemplateError) {\n stopProgressIndicator(indicatorId, `${updateEmailTemplateError}`);\n printMessage(updateEmailTemplateError, 'error');\n }\n } else {\n stopProgressIndicator(\n indicatorId,\n `Email template ${templateId} not found in ${filePath}!`\n );\n printMessage(\n `Email template ${templateId} not found in ${filePath}!`,\n 'error'\n );\n }\n } catch (error) {\n printMessage(\n `Error importing email template ${templateId}: ${error}`,\n 'error'\n );\n }\n}\n\n/**\n * Import all email templates from file\n * @param {string} file optional filename\n */\nexport async function importEmailTemplatesFromFile(file: string) {\n try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const fileData = JSON.parse(data);\n const indicatorId = createProgressIndicator(\n 'determinate',\n Object.keys(fileData.emailTemplate).length,\n `Importing email templates`\n );\n for (const id of Object.keys(fileData.emailTemplate)) {\n const templateId = id.replace(regexEmailTemplateType, '');\n try {\n await updateEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n updateProgressIndicator(indicatorId, `Imported ${templateId}`);\n } catch (updateEmailTemplateError) {\n printMessage(`\\nError importing ${templateId}`, 'error');\n printMessage(updateEmailTemplateError.response.data, 'error');\n }\n }\n stopProgressIndicator(indicatorId, `Done.`);\n } catch (error) {\n printMessage(`Error importing email templates: ${error}`, 'error');\n }\n}\n\n/**\n * Helper function to get email template id from file name\n * @param {string} file file name\n * @returns {string} email template id/name\n */\nfunction getTemplateIdFromFileName(file: string) {\n debugMessage(`cli.EmailTemplateOps.getTemplateIdFromFileName: file=${file}`);\n const basename = path.basename(file);\n const keys = basename.split('-');\n if (keys[0] !== EMAIL_TEMPLATE_TYPE || keys.length <= 1)\n throw new Error(`Filename does not indicate a raw email template: ${file}`);\n const templateId = keys[1].split('.')[0];\n debugMessage(\n `cli.EmailTemplateOps.getTemplateIdFromFileName: templateId=${templateId}`\n );\n return templateId;\n}\n\n/**\n * Convert template for s2s purposes (software-to-saas migration)\n * @param {EmailTemplateSkeleton} templateData template object\n * @returns {EmailTemplateSkeleton} converted template object\n */\nfunction s2sConvert(\n templateData: EmailTemplateSkeleton\n): EmailTemplateSkeleton {\n if (templateData.message && !templateData.html) {\n const convertedData = cloneDeep(templateData);\n convertedData.html = cloneDeep(templateData.message);\n debugMessage(`cli.EmailTemplateOps.s2sConvert: templateData:`);\n debugMessage(templateData);\n debugMessage(`cli.EmailTemplateOps.s2sConvert: convertedData:`);\n debugMessage(convertedData);\n return convertedData;\n }\n return templateData;\n}\n\n/**\n * Import all email templates from separate files\n * @param {boolean} raw import raw data file lacking frodo export envelop\n */\nexport async function importEmailTemplatesFromFiles(raw = false) {\n const names = fs.readdirSync(getWorkingDirectory());\n const jsonFiles = names\n .filter((name) =>\n raw\n ? name.startsWith(`${EMAIL_TEMPLATE_TYPE}-`) && name.endsWith(`.json`)\n : name.toLowerCase().endsWith(`${EMAIL_TEMPLATE_FILE_TYPE}.json`)\n )\n .map((name) => getFilePath(name));\n const indicatorId = createProgressIndicator(\n 'determinate',\n jsonFiles.length,\n 'Importing email templates...'\n );\n let total = 0;\n let totalErrors = 0;\n for (const file of jsonFiles) {\n const data = fs.readFileSync(file, 'utf8');\n const fileData = JSON.parse(data);\n if (\n (raw && file.startsWith('emailTemplate-')) ||\n validateImport(fileData.meta)\n ) {\n let errors = 0;\n if (raw) {\n total++;\n const templateId = getTemplateIdFromFileName(file);\n try {\n const templateData = s2sConvert(fileData);\n await updateEmailTemplate(templateId, templateData);\n } catch (updateEmailTemplateError) {\n errors += 1;\n printMessage(`\\nError importing ${templateId}`, 'error');\n printMessage(updateEmailTemplateError, 'error');\n printMessage(updateEmailTemplateError.response?.data, 'error');\n }\n } else {\n total += Object.keys(fileData.emailTemplate).length;\n for (const id in fileData.emailTemplate) {\n if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {\n const templateId = id.replace(regexEmailTemplateType, '');\n try {\n await updateEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n } catch (updateEmailTemplateError) {\n errors += 1;\n printMessage(`\\nError importing ${templateId}`, 'error');\n printMessage(updateEmailTemplateError.response.data, 'error');\n }\n }\n }\n }\n totalErrors += errors;\n updateProgressIndicator(indicatorId, `Imported ${file}`);\n } else {\n printMessage(`Validation of ${file} failed!`, 'error');\n }\n }\n stopProgressIndicator(\n indicatorId,\n `Imported ${total - totalErrors} of ${total} email template(s) from ${\n jsonFiles.length\n } file(s).`\n );\n}\n\n/**\n * Import first email template from file\n * @param {String} file optional filename\n */\nexport async function importFirstEmailTemplateFromFile(\n file: string,\n raw = false\n) {\n let indicatorId: string;\n try {\n const data = fs.readFileSync(getFilePath(file), 'utf8');\n const fileData = JSON.parse(data);\n indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Importing first email template`\n );\n if (raw) {\n try {\n const templateId = getTemplateIdFromFileName(file);\n const templateData = s2sConvert(fileData);\n await updateEmailTemplate(templateId, templateData);\n stopProgressIndicator(indicatorId, `Imported ${templateId}`, 'success');\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error importing email template: ${error}`,\n 'fail'\n );\n printMessage(error.response?.data, 'error');\n }\n } else {\n for (const id of Object.keys(fileData.emailTemplate)) {\n try {\n await updateEmailTemplate(\n id.replace(regexEmailTemplateType, ''),\n fileData.emailTemplate[id]\n );\n stopProgressIndicator(indicatorId, `Imported ${id}`, 'success');\n } catch (updateEmailTemplateError) {\n stopProgressIndicator(indicatorId, `Error importing ${id}`, 'fail');\n printMessage(updateEmailTemplateError.response?.data, 'error');\n }\n break;\n }\n }\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error importing first email template`,\n 'fail'\n );\n printMessage(`Error importing first email template: ${error}`, 'error');\n }\n}\n"],"mappings":"AAAA,SAASA,KAAK,QA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C8D,EAAE,CAC3B,CAAC;UACDpF,qBAAqB,CAACiE,WAAW,EAAG,YAAWmB,EAAG,EAAC,EAAE,SAAS,CAAC;QACjE,CAAC,CAAC,OAAOF,wBAAwB,EAAE;UAAA,IAAAwB,sBAAA;UACjC1G,qBAAqB,CAACiE,WAAW,EAAG,mBAAkBmB,EAAG,EAAC,EAAE,MAAM,CAAC;UACnErF,YAAY,EAAA2G,sBAAA,GAACxB,wBAAwB,CAACG,QAAQ,cAAAqB,sBAAA,uBAAjCA,sBAAA,CAAmC/B,IAAI,EAAE,OAAO,CAAC;QAChE;QACA;MACF;IACF;EACF,CAAC,CAAC,OAAO1B,KAAK,EAAE;IACdjD,qBAAqB,CACnBiE,WAAW,EACV,sCAAqC,EACtC,MACF,CAAC;IACDlE,YAAY,CAAE,yCAAwCkD,KAAM,EAAC,EAAE,OAAO,CAAC;EACzE;AACF"}
|
package/esm/ops/IdmOps.js
CHANGED
|
@@ -15,6 +15,7 @@ const {
|
|
|
15
15
|
testConnectorServers,
|
|
16
16
|
readConfigEntities,
|
|
17
17
|
readConfigEntity,
|
|
18
|
+
exportConfigEntities,
|
|
18
19
|
updateConfigEntity
|
|
19
20
|
} = frodo.idm.config;
|
|
20
21
|
const {
|
|
@@ -75,39 +76,15 @@ export async function exportConfigEntity(id, file) {
|
|
|
75
76
|
* Export all IDM configuration objects into separate JSON files in a directory specified by <directory>
|
|
76
77
|
*/
|
|
77
78
|
export async function exportAllRawConfigEntities() {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
var _readConfigEntityErro, _readConfigEntityErro2, _readConfigEntityErro3, _readConfigEntityErro4, _readConfigEntityErro5, _readConfigEntityErro6;
|
|
85
|
-
if (!(((_readConfigEntityErro = readConfigEntityError.response) === null || _readConfigEntityErro === void 0 ? void 0 : _readConfigEntityErro.status) === 403 && ((_readConfigEntityErro2 = readConfigEntityError.response) === null || _readConfigEntityErro2 === void 0 || (_readConfigEntityErro2 = _readConfigEntityErro2.data) === null || _readConfigEntityErro2 === void 0 ? void 0 : _readConfigEntityErro2.message) === 'This operation is not available in ForgeRock Identity Cloud.') && !(
|
|
86
|
-
// list of config entities, which do not exist by default or ever.
|
|
87
|
-
|
|
88
|
-
['script', 'notificationFactory', 'apiVersion', 'metrics', 'repo.init', 'endpoint/validateQueryFilter', 'endpoint/oauthproxy', 'external.rest', 'scheduler', 'org.apache.felix.fileinstall/openidm', 'cluster', 'endpoint/mappingDetails', 'fieldPolicy/teammember'].includes(configEntity._id) && ((_readConfigEntityErro3 = readConfigEntityError.response) === null || _readConfigEntityErro3 === void 0 ? void 0 : _readConfigEntityErro3.status) === 404 && ((_readConfigEntityErro4 = readConfigEntityError.response) === null || _readConfigEntityErro4 === void 0 || (_readConfigEntityErro4 = _readConfigEntityErro4.data) === null || _readConfigEntityErro4 === void 0 ? void 0 : _readConfigEntityErro4.reason) === 'Not Found') &&
|
|
89
|
-
// https://bugster.forgerock.org/jira/browse/OPENIDM-18270
|
|
90
|
-
!(((_readConfigEntityErro5 = readConfigEntityError.response) === null || _readConfigEntityErro5 === void 0 ? void 0 : _readConfigEntityErro5.status) === 404 && ((_readConfigEntityErro6 = readConfigEntityError.response) === null || _readConfigEntityErro6 === void 0 || (_readConfigEntityErro6 = _readConfigEntityErro6.data) === null || _readConfigEntityErro6 === void 0 ? void 0 : _readConfigEntityErro6.message) === 'No configuration exists for id org.apache.felix.fileinstall/openidm')) {
|
|
91
|
-
var _readConfigEntityErro7;
|
|
92
|
-
printMessage((_readConfigEntityErro7 = readConfigEntityError.response) === null || _readConfigEntityErro7 === void 0 ? void 0 : _readConfigEntityErro7.data, 'error');
|
|
93
|
-
printMessage(`Error getting config entity ${configEntity._id}: ${readConfigEntityError}`, 'error');
|
|
79
|
+
const exportedConfigurations = await exportConfigEntities();
|
|
80
|
+
for (const [id, value] of Object.entries(exportedConfigurations.config)) {
|
|
81
|
+
if (value != null) {
|
|
82
|
+
fse.outputFile(getFilePath(`${id}.json`, true), JSON.stringify(value, null, 2), err => {
|
|
83
|
+
if (err) {
|
|
84
|
+
return printMessage(`ERROR - can't save config ${id} to file - ${err}`, 'error');
|
|
94
85
|
}
|
|
95
|
-
})
|
|
86
|
+
});
|
|
96
87
|
}
|
|
97
|
-
const results = await Promise.all(entityPromises);
|
|
98
|
-
for (const item of results) {
|
|
99
|
-
if (item != null) {
|
|
100
|
-
fse.outputFile(getFilePath(`${item._id}.json`, true), JSON.stringify(item, null, 2), err => {
|
|
101
|
-
if (err) {
|
|
102
|
-
return printMessage(`ERROR - can't save config ${item._id} to file - ${err}`, 'error');
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
stopProgressIndicator('Exported config objects.', 'success');
|
|
108
|
-
} catch (readConfigEntitiesError) {
|
|
109
|
-
printMessage(readConfigEntitiesError, 'error');
|
|
110
|
-
printMessage(`Error getting config entities: ${readConfigEntitiesError}`, 'error');
|
|
111
88
|
}
|
|
112
89
|
}
|
|
113
90
|
|
package/esm/ops/IdmOps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdmOps.js","names":["frodo","state","fs","fse","path","propertiesReader","replaceall","createProgressIndicator","printMessage","stopProgressIndicator","getTypedFilename","readFiles","unSubstituteEnvParams","areScriptHooksValid","getFilePath","utils","testConnectorServers","readConfigEntities","readConfigEntity","updateConfigEntity","idm","config","queryManagedObjects","managed","warnAboutOfflineConnectorServers","all","offline","filter","status","ok","map","name","length","join","error","message","listAllConfigEntities","configurations","configEntity","_id","readConfigEntitiesError","exportConfigEntity","id","file","fileName","writeFile","JSON","stringify","err","exportAllRawConfigEntities","undefined","entityPromises","push","catch","readConfigEntityError","_readConfigEntityErro","_readConfigEntityErro2","_readConfigEntityErro3","_readConfigEntityErro4","_readConfigEntityErro5","_readConfigEntityErro6","response","data","includes","reason","_readConfigEntityErro7","results","Promise","item","outputFile","exportAllConfigEntities","entitiesFile","envFile","entriesToExport","readFile","entriesData","parse","envParams","configEntityString","each","key","value","importConfigEntityByIdFromFile","entityId","validate","fileData","readFileSync","resolve","process","cwd","entityData","isValid","updateConfigEntityError","importConfigEntityFromFile","importAllRawConfigEntities","baseDirectory","getDirectory","existsSync","files","jsonFiles","toLowerCase","endsWith","content","substring","everyScriptValid","jsObject","isScriptValid","allSettled","errors","result","importAllConfigEntities","entriesToImport","envReader","unsubstituted","countManagedObjects","type"],"sources":["../../src/ops/IdmOps.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\nimport fs from 'fs';\nimport fse from 'fs-extra';\nimport path from 'path';\nimport propertiesReader from 'properties-reader';\nimport replaceall from 'replaceall';\n\nimport {\n createProgressIndicator,\n printMessage,\n stopProgressIndicator,\n} from '../utils/Console';\nimport { getTypedFilename, readFiles } from '../utils/ExportImportUtils';\n\nconst { unSubstituteEnvParams, areScriptHooksValid, getFilePath } = frodo.utils;\nconst {\n testConnectorServers,\n readConfigEntities,\n readConfigEntity,\n updateConfigEntity,\n} = frodo.idm.config;\nconst { queryManagedObjects } = frodo.idm.managed;\n\n/**\n * Warn about and list offline remote connector servers\n */\nexport async function warnAboutOfflineConnectorServers() {\n try {\n const all = await testConnectorServers();\n const offline = all\n .filter((status) => !status.ok)\n .map((status) => status.name);\n if (offline.length) {\n printMessage(\n `\\nThe following connector server(s) are offline and their connectors and configuration unavailable:\\n${offline.join(\n '\\n'\n )}`,\n 'warn'\n );\n }\n } catch (error) {\n printMessage(error, 'error');\n printMessage(\n `Error getting offline connector servers: ${error.message}`,\n 'error'\n );\n }\n}\n\n/**\n * List all IDM configuration objects\n */\nexport async function listAllConfigEntities() {\n try {\n const configurations = await readConfigEntities();\n for (const configEntity of configurations) {\n printMessage(`${configEntity._id}`, 'data');\n }\n } catch (readConfigEntitiesError) {\n printMessage(readConfigEntitiesError, 'error');\n printMessage(\n `Error getting config entities: ${readConfigEntitiesError}`,\n 'error'\n );\n }\n}\n\n/**\n * Export an IDM configuration object.\n * @param {String} id the desired configuration object\n * @param {String} file optional export file\n */\nexport async function exportConfigEntity(id, file) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(`${id}`, 'idm');\n }\n const configEntity = await readConfigEntity(id);\n fs.writeFile(\n getFilePath(fileName, true),\n JSON.stringify(configEntity, null, 2),\n (err) => {\n if (err) {\n return printMessage(`ERROR - can't save ${id} export to file`, 'error');\n }\n return '';\n }\n );\n}\n\n/**\n * Export all IDM configuration objects into separate JSON files in a directory specified by <directory>\n */\nexport async function exportAllRawConfigEntities() {\n try {\n const configurations = await readConfigEntities();\n createProgressIndicator(\n 'indeterminate',\n undefined,\n 'Exporting config objects...'\n );\n const entityPromises = [];\n for (const configEntity of configurations) {\n entityPromises.push(\n readConfigEntity(configEntity._id).catch((readConfigEntityError) => {\n if (\n !(\n readConfigEntityError.response?.status === 403 &&\n readConfigEntityError.response?.data?.message ===\n 'This operation is not available in ForgeRock Identity Cloud.'\n ) &&\n !(\n // list of config entities, which do not exist by default or ever.\n (\n [\n 'script',\n 'notificationFactory',\n 'apiVersion',\n 'metrics',\n 'repo.init',\n 'endpoint/validateQueryFilter',\n 'endpoint/oauthproxy',\n 'external.rest',\n 'scheduler',\n 'org.apache.felix.fileinstall/openidm',\n 'cluster',\n 'endpoint/mappingDetails',\n 'fieldPolicy/teammember',\n ].includes(configEntity._id) &&\n readConfigEntityError.response?.status === 404 &&\n readConfigEntityError.response?.data?.reason === 'Not Found'\n )\n ) &&\n // https://bugster.forgerock.org/jira/browse/OPENIDM-18270\n !(\n readConfigEntityError.response?.status === 404 &&\n readConfigEntityError.response?.data?.message ===\n 'No configuration exists for id org.apache.felix.fileinstall/openidm'\n )\n ) {\n printMessage(readConfigEntityError.response?.data, 'error');\n printMessage(\n `Error getting config entity ${configEntity._id}: ${readConfigEntityError}`,\n 'error'\n );\n }\n })\n );\n }\n const results = await Promise.all(entityPromises);\n for (const item of results) {\n if (item != null) {\n fse.outputFile(\n getFilePath(`${item._id}.json`, true),\n JSON.stringify(item, null, 2),\n (err) => {\n if (err) {\n return printMessage(\n `ERROR - can't save config ${item._id} to file - ${err}`,\n 'error'\n );\n }\n }\n );\n }\n }\n stopProgressIndicator('Exported config objects.', 'success');\n } catch (readConfigEntitiesError) {\n printMessage(readConfigEntitiesError, 'error');\n printMessage(\n `Error getting config entities: ${readConfigEntitiesError}`,\n 'error'\n );\n }\n}\n\n/**\n * Export all IDM configuration objects\n * @param {String} entitiesFile JSON file that specifies the config entities to export/import\n * @param {String} envFile File that defines environment specific variables for replacement during configuration export/import\n */\nexport async function exportAllConfigEntities(entitiesFile, envFile) {\n let entriesToExport = [];\n // read list of entities to export\n fs.readFile(entitiesFile, 'utf8', async (err, data) => {\n if (err) throw err;\n const entriesData = JSON.parse(data);\n entriesToExport = entriesData.idm;\n // console.log(`entriesToExport ${entriesToExport}`);\n\n // read list of configs to parameterize for environment specific values\n const envParams = propertiesReader(envFile);\n\n try {\n const configurations = await readConfigEntities();\n createProgressIndicator(\n 'indeterminate',\n undefined,\n 'Exporting config objects...'\n );\n const entityPromises = [];\n for (const configEntity of configurations) {\n if (entriesToExport.includes(configEntity._id)) {\n entityPromises.push(readConfigEntity(configEntity._id));\n }\n }\n const results = await Promise.all(entityPromises);\n for (const item of results) {\n if (item != null) {\n let configEntityString = JSON.stringify(item, null, 2);\n envParams.each((key, value) => {\n configEntityString = replaceall(\n value,\n `\\${${key}}`,\n configEntityString\n );\n });\n fse.outputFile(\n getFilePath(`${item._id}.json`, true),\n configEntityString,\n (error) => {\n if (err) {\n return printMessage(\n `ERROR - can't save config ${item._id} to file - ${error}`,\n 'error'\n );\n }\n }\n );\n }\n }\n stopProgressIndicator(null, 'success');\n } catch (readConfigEntitiesError) {\n printMessage(readConfigEntitiesError, 'error');\n printMessage(\n `Error getting config entities: ${readConfigEntitiesError}`,\n 'error'\n );\n }\n });\n}\n\n/**\n * Import an IDM configuration object by id from file.\n * @param entityId the configuration object to import\n * @param file optional file to import\n * @param validate validate script hooks\n */\nexport async function importConfigEntityByIdFromFile(\n entityId: string,\n file?: string,\n validate?: boolean\n) {\n if (!file) {\n file = getTypedFilename(entityId, 'idm');\n }\n\n const fileData = fs.readFileSync(\n path.resolve(process.cwd(), getFilePath(file)),\n 'utf8'\n );\n\n const entityData = JSON.parse(fileData);\n const isValid = areScriptHooksValid(entityData);\n if (validate && !isValid) {\n printMessage('Invalid IDM configuration object', 'error');\n return;\n }\n\n try {\n await updateConfigEntity(entityId, entityData);\n } catch (updateConfigEntityError) {\n printMessage(updateConfigEntityError, 'error');\n printMessage(`Error: ${updateConfigEntityError}`, 'error');\n }\n}\n\n/**\n * Import IDM configuration object from file.\n * @param file optional file to import\n * @param validate validate script hooks\n */\nexport async function importConfigEntityFromFile(\n file: string,\n validate?: boolean\n) {\n const fileData = fs.readFileSync(\n path.resolve(process.cwd(), getFilePath(file)),\n 'utf8'\n );\n const entityData = JSON.parse(fileData);\n const entityId = entityData._id;\n const isValid = areScriptHooksValid(entityData);\n if (validate && !isValid) {\n printMessage('Invalid IDM configuration object', 'error');\n return;\n }\n\n try {\n await updateConfigEntity(entityId, entityData);\n } catch (updateConfigEntityError) {\n printMessage(updateConfigEntityError, 'error');\n printMessage(`Error: ${updateConfigEntityError}`, 'error');\n }\n}\n\n/**\n * Import all IDM configuration objects from separate JSON files in a directory specified by <directory>\n * @param validate validate script hooks\n */\nexport async function importAllRawConfigEntities(validate?: boolean) {\n const baseDirectory = state.getDirectory();\n if (!fs.existsSync(baseDirectory)) {\n return;\n }\n const files = await readFiles(baseDirectory);\n const jsonFiles = files\n .filter(({ path }) => path.toLowerCase().endsWith('.json'))\n .map(({ path, content }) => ({\n // Remove .json extension\n entityId: path.substring(0, path.length - 5),\n content,\n path,\n }));\n\n let everyScriptValid = true;\n for (const file of jsonFiles) {\n const jsObject = JSON.parse(file.content);\n const isScriptValid = areScriptHooksValid(jsObject);\n if (!isScriptValid) {\n printMessage(`Invalid script hook in ${file.path}`, 'error');\n everyScriptValid = false;\n }\n }\n\n if (validate && !everyScriptValid) {\n return;\n }\n\n createProgressIndicator(\n 'indeterminate',\n undefined,\n 'Importing config objects...'\n );\n\n const entityPromises = jsonFiles.map((file) => {\n return updateConfigEntity(file.entityId, JSON.parse(file.content));\n });\n\n const results = await Promise.allSettled(entityPromises);\n const errors = results.filter(\n (result): result is PromiseRejectedResult => result.status === 'rejected'\n );\n\n if (errors.length > 0) {\n printMessage(`Failed to import ${errors.length} config objects:`, 'error');\n for (const error of errors) {\n printMessage(`- ${error.reason}`, 'error');\n }\n stopProgressIndicator(\n `Failed to import ${errors.length} config objects`,\n 'error'\n );\n return;\n }\n\n stopProgressIndicator(`Imported ${results.length} config objects`, 'success');\n}\n\n/**\n * Import all IDM configuration objects\n * @param entitiesFile JSON file that specifies the config entities to export/import\n * @param envFile File that defines environment specific variables for replacement during configuration export/import\n * @param validate validate script hooks\n */\nexport async function importAllConfigEntities(\n entitiesFile: string,\n envFile: string,\n validate?: boolean\n) {\n const baseDirectory = state.getDirectory();\n if (!fs.existsSync(baseDirectory)) {\n return;\n }\n const entriesToImport = JSON.parse(fs.readFileSync(entitiesFile, 'utf8')).idm;\n\n const envReader = propertiesReader(envFile);\n\n const files = await readFiles(baseDirectory);\n const jsonFiles = files\n .filter(({ path }) => path.toLowerCase().endsWith('.json'))\n .map(({ content, path }) => ({\n // Remove .json extension\n entityId: path.substring(0, path.length - 5),\n content,\n path,\n }));\n\n let everyScriptValid = true;\n for (const file of jsonFiles) {\n const jsObject = JSON.parse(file.content);\n const isScriptValid = areScriptHooksValid(jsObject);\n if (!isScriptValid) {\n printMessage(`Invalid script hook in ${file.path}`, 'error');\n everyScriptValid = false;\n }\n }\n\n if (validate && !everyScriptValid) {\n return;\n }\n\n createProgressIndicator(\n 'indeterminate',\n undefined,\n 'Importing config objects...'\n );\n\n const entityPromises = jsonFiles\n .filter(({ entityId }) => {\n return entriesToImport.includes(entityId);\n })\n .map(({ entityId, content }) => {\n const unsubstituted = unSubstituteEnvParams(content, envReader);\n return updateConfigEntity(entityId, JSON.parse(unsubstituted));\n });\n\n const results = await Promise.allSettled(entityPromises);\n const errors = results.filter(\n (result): result is PromiseRejectedResult => result.status === 'rejected'\n );\n\n if (errors.length > 0) {\n printMessage(`Failed to import ${errors.length} config objects:`, 'error');\n for (const error of errors) {\n printMessage(`- ${error.reason}`, 'error');\n }\n stopProgressIndicator(\n `Failed to import ${errors.length} config objects`,\n 'error'\n );\n return;\n }\n\n stopProgressIndicator(`Imported ${results.length} config objects`, 'success');\n}\n\n/**\n * Count number of managed objects of a given type\n * @param {String} type managed object type, e.g. alpha_user\n */\nexport async function countManagedObjects(type: string) {\n try {\n const result = await queryManagedObjects(type);\n printMessage(`${type}: ${result.length}`, 'data');\n } catch (error) {\n printMessage(error.response.data, 'error');\n printMessage(`Error querying managed objects by type: ${error}`, 'error');\n }\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AACpD,OAAOC,EAAE,MAAM,IAAI;AACnB,OAAOC,GAAG,MAAM,UAAU;AAC1B,OAAOC,IAAI,MAAM,MAAM;AACvB,OAAOC,gBAAgB,MAAM,mBAAmB;AAChD,OAAOC,UAAU,MAAM,YAAY;AAEnC,SACEC,uBAAuB,EACvBC,YAAY,EACZC,qBAAqB,QAChB,kBAAkB;AACzB,SAASC,gBAAgB,EAAEC,SAAS,QAAQ,4BAA4B;AAExE,MAAM;EAAEC,qBAAqB;EAAEC,mBAAmB;EAAEC;AAAY,CAAC,GAAGd,KAAK,CAACe,KAAK;AAC/E,MAAM;EACJC,oBAAoB;EACpBC,kBAAkB;EAClBC,gBAAgB;EAChBC;AACF,CAAC,GAAGnB,KAAK,CAACoB,GAAG,CAACC,MAAM;AACpB,MAAM;EAAEC;AAAoB,CAAC,GAAGtB,KAAK,CAACoB,GAAG,CAACG,OAAO;;AAEjD;AACA;AACA;AACA,OAAO,eAAeC,gCAAgCA,CAAA,EAAG;EACvD,IAAI;IACF,MAAMC,G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MAAMC,OAAO,CAACwC,UAAU,CAACxD,cAAc,CAAC;EACxD,MAAMyD,MAAM,GAAG1C,OAAO,CAACvC,MAAM,CAC1BkF,MAAM,IAAsCA,MAAM,CAACjF,MAAM,KAAK,UACjE,CAAC;EAED,IAAIgF,MAAM,CAAC5E,MAAM,GAAG,CAAC,EAAE;IACrBxB,YAAY,CAAE,oBAAmBoG,MAAM,CAAC5E,MAAO,kBAAiB,EAAE,OAAO,CAAC;IAC1E,KAAK,MAAME,KAAK,IAAI0E,MAAM,EAAE;MAC1BpG,YAAY,CAAE,KAAI0B,KAAK,CAAC8B,MAAO,EAAC,EAAE,OAAO,CAAC;IAC5C;IACAvD,qBAAqB,CAClB,oBAAmBmG,MAAM,CAAC5E,MAAO,iBAAgB,EAClD,OACF,CAAC;IACD;EACF;EAEAvB,qBAAqB,CAAE,YAAWyD,OAAO,CAAClC,MAAO,iBAAgB,EAAE,SAAS,CAAC;AAC/E;;AAEA;AACA;AACA;AACA;AACA,OAAO,eAAekF,mBAAmBA,CAACC,IAAY,EAAE;EACtD,IAAI;IACF,MAAMN,MAAM,GAAG,MAAMvF,mBAAmB,CAAC6F,IAAI,CAAC;IAC9C3G,YAAY,CAAE,GAAE2G,IAAK,KAAIN,MAAM,CAAC7E,MAAO,EAAC,EAAE,MAAM,CAAC;EACnD,CAAC,CAAC,OAAOE,KAAK,EAAE;IACd1B,YAAY,CAAC0B,KAAK,CAAC2B,QAAQ,CAACC,IAAI,EAAE,OAAO,CAAC;IAC1CtD,YAAY,CAAE,2CAA0C0B,KAAM,EAAC,EAAE,OAAO,CAAC;EAC3E;AACF"}
|
|
1
|
+
{"version":3,"file":"IdmOps.js","names":["frodo","state","fs","fse","path","propertiesReader","replaceall","createProgressIndicator","printMessage","stopProgressIndicator","getTypedFilename","readFiles","unSubstituteEnvParams","areScriptHooksValid","getFilePath","utils","testConnectorServers","readConfigEntities","readConfigEntity","exportConfigEntities","updateConfigEntity","idm","config","queryManagedObjects","managed","warnAboutOfflineConnectorServers","all","offline","filter","status","ok","map","name","length","join","error","message","listAllConfigEntities","configurations","configEntity","_id","readConfigEntitiesError","exportConfigEntity","id","file","fileName","writeFile","JSON","stringify","err","exportAllRawConfigEntities","exportedConfigurations","value","Object","entries","outputFile","exportAllConfigEntities","entitiesFile","envFile","entriesToExport","readFile","data","entriesData","parse","envParams","undefined","entityPromises","includes","push","results","Promise","item","configEntityString","each","key","importConfigEntityByIdFromFile","entityId","validate","fileData","readFileSync","resolve","process","cwd","entityData","isValid","updateConfigEntityError","importConfigEntityFromFile","importAllRawConfigEntities","baseDirectory","getDirectory","existsSync","files","jsonFiles","toLowerCase","endsWith","content","substring","everyScriptValid","jsObject","isScriptValid","allSettled","errors","result","reason","importAllConfigEntities","entriesToImport","envReader","unsubstituted","countManagedObjects","type","response"],"sources":["../../src/ops/IdmOps.ts"],"sourcesContent":["import { frodo, state } from '@rockcarver/frodo-lib';\nimport fs from 'fs';\nimport fse from 'fs-extra';\nimport path from 'path';\nimport propertiesReader from 'properties-reader';\nimport replaceall from 'replaceall';\n\nimport {\n createProgressIndicator,\n printMessage,\n stopProgressIndicator,\n} from '../utils/Console';\nimport { getTypedFilename, readFiles } from '../utils/ExportImportUtils';\n\nconst { unSubstituteEnvParams, areScriptHooksValid, getFilePath } = frodo.utils;\nconst {\n testConnectorServers,\n readConfigEntities,\n readConfigEntity,\n exportConfigEntities,\n updateConfigEntity,\n} = frodo.idm.config;\nconst { queryManagedObjects } = frodo.idm.managed;\n\n/**\n * Warn about and list offline remote connector servers\n */\nexport async function warnAboutOfflineConnectorServers() {\n try {\n const all = await testConnectorServers();\n const offline = all\n .filter((status) => !status.ok)\n .map((status) => status.name);\n if (offline.length) {\n printMessage(\n `\\nThe following connector server(s) are offline and their connectors and configuration unavailable:\\n${offline.join(\n '\\n'\n )}`,\n 'warn'\n );\n }\n } catch (error) {\n printMessage(error, 'error');\n printMessage(\n `Error getting offline connector servers: ${error.message}`,\n 'error'\n );\n }\n}\n\n/**\n * List all IDM configuration objects\n */\nexport async function listAllConfigEntities() {\n try {\n const configurations = await readConfigEntities();\n for (const configEntity of configurations) {\n printMessage(`${configEntity._id}`, 'data');\n }\n } catch (readConfigEntitiesError) {\n printMessage(readConfigEntitiesError, 'error');\n printMessage(\n `Error getting config entities: ${readConfigEntitiesError}`,\n 'error'\n );\n }\n}\n\n/**\n * Export an IDM configuration object.\n * @param {String} id the desired configuration object\n * @param {String} file optional export file\n */\nexport async function exportConfigEntity(id, file) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(`${id}`, 'idm');\n }\n const configEntity = await readConfigEntity(id);\n fs.writeFile(\n getFilePath(fileName, true),\n JSON.stringify(configEntity, null, 2),\n (err) => {\n if (err) {\n return printMessage(`ERROR - can't save ${id} export to file`, 'error');\n }\n return '';\n }\n );\n}\n\n/**\n * Export all IDM configuration objects into separate JSON files in a directory specified by <directory>\n */\nexport async function exportAllRawConfigEntities() {\n const exportedConfigurations = await exportConfigEntities();\n for (const [id, value] of Object.entries(exportedConfigurations.config)) {\n if (value != null) {\n fse.outputFile(\n getFilePath(`${id}.json`, true),\n JSON.stringify(value, null, 2),\n (err) => {\n if (err) {\n return printMessage(\n `ERROR - can't save config ${id} to file - ${err}`,\n 'error'\n );\n }\n }\n );\n }\n }\n}\n\n/**\n * Export all IDM configuration objects\n * @param {String} entitiesFile JSON file that specifies the config entities to export/import\n * @param {String} envFile File that defines environment specific variables for replacement during configuration export/import\n */\nexport async function exportAllConfigEntities(entitiesFile, envFile) {\n let entriesToExport = [];\n // read list of entities to export\n fs.readFile(entitiesFile, 'utf8', async (err, data) => {\n if (err) throw err;\n const entriesData = JSON.parse(data);\n entriesToExport = entriesData.idm;\n // console.log(`entriesToExport ${entriesToExport}`);\n\n // read list of configs to parameterize for environment specific values\n const envParams = propertiesReader(envFile);\n\n try {\n const configurations = await readConfigEntities();\n createProgressIndicator(\n 'indeterminate',\n undefined,\n 'Exporting config objects...'\n );\n const entityPromises = [];\n for (const configEntity of configurations) {\n if (entriesToExport.includes(configEntity._id)) {\n entityPromises.push(readConfigEntity(configEntity._id));\n }\n }\n const results = await Promise.all(entityPromises);\n for (const item of results) {\n if (item != null) {\n let configEntityString = JSON.stringify(item, null, 2);\n envParams.each((key, value) => {\n configEntityString = replaceall(\n value,\n `\\${${key}}`,\n configEntityString\n );\n });\n fse.outputFile(\n getFilePath(`${item._id}.json`, true),\n configEntityString,\n (error) => {\n if (err) {\n return printMessage(\n `ERROR - can't save config ${item._id} to file - ${error}`,\n 'error'\n );\n }\n }\n );\n }\n }\n stopProgressIndicator(null, 'success');\n } catch (readConfigEntitiesError) {\n printMessage(readConfigEntitiesError, 'error');\n printMessage(\n `Error getting config entities: ${readConfigEntitiesError}`,\n 'error'\n );\n }\n });\n}\n\n/**\n * Import an IDM configuration object by id from file.\n * @param entityId the configuration object to import\n * @param file optional file to import\n * @param validate validate script hooks\n */\nexport async function importConfigEntityByIdFromFile(\n entityId: string,\n file?: string,\n validate?: boolean\n) {\n if (!file) {\n file = getTypedFilename(entityId, 'idm');\n }\n\n const fileData = fs.readFileSync(\n path.resolve(process.cwd(), getFilePath(file)),\n 'utf8'\n );\n\n const entityData = JSON.parse(fileData);\n const isValid = areScriptHooksValid(entityData);\n if (validate && !isValid) {\n printMessage('Invalid IDM configuration object', 'error');\n return;\n }\n\n try {\n await updateConfigEntity(entityId, entityData);\n } catch (updateConfigEntityError) {\n printMessage(updateConfigEntityError, 'error');\n printMessage(`Error: ${updateConfigEntityError}`, 'error');\n }\n}\n\n/**\n * Import IDM configuration object from file.\n * @param file optional file to import\n * @param validate validate script hooks\n */\nexport async function importConfigEntityFromFile(\n file: string,\n validate?: boolean\n) {\n const fileData = fs.readFileSync(\n path.resolve(process.cwd(), getFilePath(file)),\n 'utf8'\n );\n const entityData = JSON.parse(fileData);\n const entityId = entityData._id;\n const isValid = areScriptHooksValid(entityData);\n if (validate && !isValid) {\n printMessage('Invalid IDM configuration object', 'error');\n return;\n }\n\n try {\n await updateConfigEntity(entityId, entityData);\n } catch (updateConfigEntityError) {\n printMessage(updateConfigEntityError, 'error');\n printMessage(`Error: ${updateConfigEntityError}`, 'error');\n }\n}\n\n/**\n * Import all IDM configuration objects from separate JSON files in a directory specified by <directory>\n * @param validate validate script hooks\n */\nexport async function importAllRawConfigEntities(validate?: boolean) {\n const baseDirectory = state.getDirectory();\n if (!fs.existsSync(baseDirectory)) {\n return;\n }\n const files = await readFiles(baseDirectory);\n const jsonFiles = files\n .filter(({ path }) => path.toLowerCase().endsWith('.json'))\n .map(({ path, content }) => ({\n // Remove .json extension\n entityId: path.substring(0, path.length - 5),\n content,\n path,\n }));\n\n let everyScriptValid = true;\n for (const file of jsonFiles) {\n const jsObject = JSON.parse(file.content);\n const isScriptValid = areScriptHooksValid(jsObject);\n if (!isScriptValid) {\n printMessage(`Invalid script hook in ${file.path}`, 'error');\n everyScriptValid = false;\n }\n }\n\n if (validate && !everyScriptValid) {\n return;\n }\n\n createProgressIndicator(\n 'indeterminate',\n undefined,\n 'Importing config objects...'\n );\n\n const entityPromises = jsonFiles.map((file) => {\n return updateConfigEntity(file.entityId, JSON.parse(file.content));\n });\n\n const results = await Promise.allSettled(entityPromises);\n const errors = results.filter(\n (result): result is PromiseRejectedResult => result.status === 'rejected'\n );\n\n if (errors.length > 0) {\n printMessage(`Failed to import ${errors.length} config objects:`, 'error');\n for (const error of errors) {\n printMessage(`- ${error.reason}`, 'error');\n }\n stopProgressIndicator(\n `Failed to import ${errors.length} config objects`,\n 'error'\n );\n return;\n }\n\n stopProgressIndicator(`Imported ${results.length} config objects`, 'success');\n}\n\n/**\n * Import all IDM configuration objects\n * @param entitiesFile JSON file that specifies the config entities to export/import\n * @param envFile File that defines environment specific variables for replacement during configuration export/import\n * @param validate validate script hooks\n */\nexport async function importAllConfigEntities(\n entitiesFile: string,\n envFile: string,\n validate?: boolean\n) {\n const baseDirectory = state.getDirectory();\n if (!fs.existsSync(baseDirectory)) {\n return;\n }\n const entriesToImport = JSON.parse(fs.readFileSync(entitiesFile, 'utf8')).idm;\n\n const envReader = propertiesReader(envFile);\n\n const files = await readFiles(baseDirectory);\n const jsonFiles = files\n .filter(({ path }) => path.toLowerCase().endsWith('.json'))\n .map(({ content, path }) => ({\n // Remove .json extension\n entityId: path.substring(0, path.length - 5),\n content,\n path,\n }));\n\n let everyScriptValid = true;\n for (const file of jsonFiles) {\n const jsObject = JSON.parse(file.content);\n const isScriptValid = areScriptHooksValid(jsObject);\n if (!isScriptValid) {\n printMessage(`Invalid script hook in ${file.path}`, 'error');\n everyScriptValid = false;\n }\n }\n\n if (validate && !everyScriptValid) {\n return;\n }\n\n createProgressIndicator(\n 'indeterminate',\n undefined,\n 'Importing config objects...'\n );\n\n const entityPromises = jsonFiles\n .filter(({ entityId }) => {\n return entriesToImport.includes(entityId);\n })\n .map(({ entityId, content }) => {\n const unsubstituted = unSubstituteEnvParams(content, envReader);\n return updateConfigEntity(entityId, JSON.parse(unsubstituted));\n });\n\n const results = await Promise.allSettled(entityPromises);\n const errors = results.filter(\n (result): result is PromiseRejectedResult => result.status === 'rejected'\n );\n\n if (errors.length > 0) {\n printMessage(`Failed to import ${errors.length} config objects:`, 'error');\n for (const error of errors) {\n printMessage(`- ${error.reason}`, 'error');\n }\n stopProgressIndicator(\n `Failed to import ${errors.length} config objects`,\n 'error'\n );\n return;\n }\n\n stopProgressIndicator(`Imported ${results.length} config objects`, 'success');\n}\n\n/**\n * Count number of managed objects of a given type\n * @param {String} type managed object type, e.g. alpha_user\n */\nexport async function countManagedObjects(type: string) {\n try {\n const result = await queryManagedObjects(type);\n printMessage(`${type}: ${result.length}`, 'data');\n } catch (error) {\n printMessage(error.response.data, 'error');\n printMessage(`Error querying managed objects by type: ${error}`, 'error');\n }\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,QAAQ,uBAAuB;AACpD,OAAOC,EAAE,MAAM,IAAI;AACnB,OAAOC,GAAG,MAAM,UAAU;AAC1B,OAAOC,IAAI,MAAM,MAAM;AACvB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