console messaging for config-manager#100
Conversation
15ca7cf to
436a8eb
Compare
436a8eb to
85f4b54
Compare
There was a problem hiding this comment.
Missing some indicators, and a few wording things that I mentioned, but mostly looks good. Keep in mind that since this PR was created there might've been some new commands added, so you will want to make sure to rebase and get indicators added to those as well. For future PRs though I'll make sure we include indicators for each command that we add.
| export async function configManagerImportCookieDomains(): Promise<boolean> { | ||
| try { | ||
| const getFile = getFilePath('cookie-domains/cookie-domains.json'); | ||
| const readFile = fs.readFileSync(getFile, 'utf-8'); | ||
| const importData = JSON.parse(readFile); | ||
| await updateCookieDomains(importData); | ||
| return true; | ||
| } catch (error) { | ||
| printError(error, `Error importing custom domains`); | ||
| printError(error, `Error importing cookie domains`); | ||
| } |
There was a problem hiding this comment.
We should add indicator here as well
| export async function configManagerImportEmailProvider(): Promise<boolean> { | ||
| try { | ||
| const filePath = getFilePath('email-provider'); | ||
| const fileData = fs.readFileSync( | ||
| `${filePath}/external.email.json`, | ||
| 'utf-8' | ||
| ); | ||
| let importData = JSON.parse(fileData); | ||
| importData = { idm: { [importData._id]: importData } }; | ||
| await config.importConfigEntities(importData); | ||
| return true; | ||
| } catch (error) { | ||
| printError(error); | ||
| } | ||
| return false; | ||
| } |
There was a problem hiding this comment.
We should add indicator here as well
| export async function configManagerImportEmailTemplates( | ||
| templateName?: string | ||
| ): Promise<boolean> { | ||
| try { | ||
| const templateDir = getFilePath('email-templates'); | ||
| const templateFiles = fs.readdirSync(templateDir); | ||
| const importTemplateData = { emailTemplate: {} }; | ||
|
|
||
| for (const templateFile of templateFiles) { | ||
| const templateJsonPath = getFilePath( | ||
| `email-templates/${templateFile}/${templateFile}.json` | ||
| ); | ||
| const readTemplate = fs.readFileSync(templateJsonPath, 'utf8'); | ||
| const importData = JSON.parse(readTemplate); | ||
| const id = importData._id; | ||
|
|
||
| if (templateName && id !== `emailTemplate/${templateName}`) { | ||
| continue; | ||
| } | ||
|
|
||
| if (importData.html && typeof importData.html === 'object') { | ||
| for (const locale in importData.html) { | ||
| const htmlFilePath = getFilePath( | ||
| `email-templates/${templateFile}/${importData.html[locale].file}` | ||
| ); | ||
| importData.html[locale] = fs.readFileSync(htmlFilePath, 'utf8'); | ||
| } | ||
| } | ||
| if (importData.message && typeof importData.message === 'object') { | ||
| for (const locale in importData.message) { | ||
| const messageFilePath = getFilePath( | ||
| `email-templates/${templateFile}/${importData.message[locale].file}` | ||
| ); | ||
| importData.message[locale] = fs.readFileSync(messageFilePath, 'utf8'); | ||
| } | ||
| } | ||
| if (importData.styles && typeof importData.styles === 'object') { | ||
| const stylesFilePath = getFilePath( | ||
| `email-templates/${templateFile}/${importData.styles.file}` | ||
| ); | ||
| importData.styles = fs.readFileSync(stylesFilePath, 'utf8'); | ||
| } | ||
| importTemplateData.emailTemplate[id.replace('emailTemplate/', '')] = | ||
| importData; | ||
| } | ||
| await importEmailTemplates(importTemplateData); | ||
| return true; | ||
| } catch (error) { | ||
| printError(error, `Error importing email templates to files`); | ||
| } | ||
| return false; | ||
| } |
There was a problem hiding this comment.
We should have progress indicator here as well
| export async function configManagerImportEndpoints( | ||
| endpointName?: string | ||
| ): Promise<boolean> { | ||
| try { | ||
| const endpointsDir = getFilePath(`endpoints`); | ||
| const endpointsFiles = fs.readdirSync(endpointsDir); | ||
| const importEndpointData = { idm: {} }; | ||
| for (const endpointsFile of endpointsFiles) { | ||
| const jsonFilePath = getFilePath( | ||
| `endpoints/${endpointsFile}/${endpointsFile}.json` | ||
| ); | ||
| const readJsonEndpoint = fs.readFileSync(jsonFilePath, 'utf8') as any; | ||
| const importData = JSON.parse(readJsonEndpoint) as any; | ||
| const id = importData._id; | ||
|
|
||
| if (endpointName && id !== `endpoint/${endpointName}`) { | ||
| continue; | ||
| } | ||
| if (importData.file) { | ||
| const scriptPath = getFilePath( | ||
| `endpoints/${endpointsFile}/${importData.file}` | ||
| ); | ||
| importData.source = fs.readFileSync(scriptPath, 'utf8'); | ||
| delete importData.file; | ||
| } | ||
|
|
||
| importEndpointData.idm[id] = importData; | ||
| } | ||
| await importConfigEntities(importEndpointData); | ||
| return true; | ||
| } catch (error) { | ||
| printError(error, `Error importing config entity endpoints`); | ||
| printError(error, `Error importing endpoints`); | ||
| } | ||
| return false; | ||
| } |
There was a problem hiding this comment.
We should add indicator here as well
| export async function configManagerImportInternalRoles( | ||
| internalRoleName?: string | ||
| ): Promise<boolean> { | ||
| try { | ||
| const internalRolesDir = getFilePath('internal-roles'); | ||
| const internalRolesFiles = fs.readdirSync(internalRolesDir); | ||
| const importData = { internalRole: {} }; | ||
| for (const internalRolesFile of internalRolesFiles) { | ||
| const filePath = getFilePath(`internal-roles/${internalRolesFile}`); | ||
| const readFile = fs.readFileSync(filePath, 'utf-8'); | ||
| const roleData = JSON.parse(readFile); | ||
| if (internalRoleName && roleData.name !== internalRoleName) { | ||
| continue; | ||
| } | ||
| importData.internalRole[roleData._id] = roleData; | ||
| } | ||
| await importInternalRoles(importData); | ||
| return true; | ||
| } catch (error) { | ||
| printError(error, `Error importing internal roles to files`); | ||
| printError(error, `Error importing internal roles`); | ||
| } | ||
| return false; | ||
| } |
There was a problem hiding this comment.
We should have an indicator here as well
| export async function configManagerImportServiceObjects(): Promise<boolean> { | ||
| try { | ||
| const objectsDir = getFilePath('service-objects/'); | ||
| const objectTypes = fs.readdirSync(objectsDir); | ||
|
|
||
| for (const objectType of objectTypes) { | ||
| const objectPath = `${objectsDir}/${objectType}`; | ||
| const objectFiles = fs.readdirSync(objectPath); | ||
|
|
||
| for (const objectFile of objectFiles) { | ||
| const fullPath = `${objectPath}/${objectFile}`; | ||
| const readFiles = fs.readFileSync(fullPath, 'utf8'); | ||
| const importData = JSON.parse(readFiles); | ||
| delete importData._rev; | ||
| delete importData._refProperties; | ||
|
|
||
| await updateManagedObject(objectType, importData._id, importData); | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } catch (err) { | ||
| printError(err, `Error importing service-objects`); | ||
| } | ||
| return false; | ||
| } |
There was a problem hiding this comment.
We should have an indicator here as well
| export async function configManagerImportTermsAndConditions(): Promise<boolean> { | ||
| try { | ||
| const mainFile = getFilePath('terms-conditions/terms-conditions.json'); | ||
| const readMain = fs.readFileSync(mainFile, 'utf8') as any; | ||
| let importData = JSON.parse(readMain) as any; | ||
| const id = importData._id; | ||
| importData = { idm: { [id]: importData } }; | ||
| for (const version of importData.idm[id].versions) { | ||
| for (const [language] of Object.entries(version.termsTranslations)) { | ||
| const languageFileName = `${version.version}/${language}.html`; | ||
| const directoryName = `terms-conditions`; | ||
| const fileDir = getFilePath(`${directoryName}/${languageFileName}`); | ||
| version.termsTranslations[language] = fs.readFileSync(fileDir, 'utf8'); | ||
| } | ||
| } | ||
| await importConfigEntities(importData); | ||
| return true; | ||
| } catch (error) { | ||
| printError(error); | ||
| return false; | ||
| } | ||
| } |
There was a problem hiding this comment.
We should have an indicator here as well
| export async function configManagerImportThemes(): Promise<boolean> { | ||
| try { | ||
| const realms = await readRealms(); | ||
| for (const realm of realms) { | ||
| // fr-config-manager doesn't support root themes | ||
| if (realm.name === '/') continue; | ||
| state.setRealm(realm.name); | ||
| const importDir = getFilePath( | ||
| `realms${realm.parentPath + realm.name}/themes` | ||
| ); | ||
| const themesDir = fs | ||
| .readdirSync(importDir, { withFileTypes: true }) | ||
| .filter((dirent) => dirent.isDirectory()) | ||
| .map((dirent) => dirent.name); | ||
| const themeMap: Record<string, ThemeSkeleton> = {}; | ||
| for (const themeName of themesDir) { | ||
| const themeDir = `${importDir}/${themeName}`; | ||
| const themeJsonPath = `${themeDir}/${themeName}.json`; | ||
| const theme: ThemeSkeleton = JSON.parse( | ||
| fs.readFileSync(themeJsonPath, 'utf8') | ||
| ); | ||
| for (const field of THEME_HTML_FIELDS) { | ||
| if ( | ||
| !theme[field.name] || | ||
| typeof theme[field.name] !== 'object' || | ||
| typeof (theme[field.name] as any).file !== 'string' | ||
| ) | ||
| continue; | ||
| const fileName = (theme[field.name] as any).file; | ||
| const filePath = `${themeDir}/${fileName}`; | ||
| const fileContent = fs.readFileSync(filePath, 'utf8'); | ||
| theme[field.name] = fileContent; | ||
| } | ||
| themeMap[theme._id] = theme; | ||
| } | ||
| await importThemes({ theme: themeMap }); | ||
| } | ||
| return true; | ||
| } catch (error) { | ||
| printError(error); | ||
| return false; | ||
| } | ||
| } |
There was a problem hiding this comment.
We should have an indicator here as well
| export async function configManagerImportUiConfig(): Promise<boolean> { | ||
| try { | ||
| const fileData = getFilePath(`ui/ui-configuration.json`); | ||
| const readFile = fs.readFileSync(fileData, 'utf8'); | ||
| let importData = JSON.parse(readFile); | ||
| importData = { idm: { [importData._id]: importData } }; | ||
| await importConfigEntities(importData); | ||
| return true; | ||
| } catch (error) { | ||
| printError(error); | ||
| } | ||
| return false; | ||
| } |
There was a problem hiding this comment.
We should have an indicator here as well
There was a problem hiding this comment.
Fun fact, this file is completely useless, the function is not being used anywhere, so no need for changes here, although you can keep them in if you want. We'll have a separate PR that removes it, but just thought I'd let you know.
No description provided.