@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
package/esm/ops/IdpOps.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { frodo } from '@rockcarver/frodo-lib';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
-
import {
|
|
3
|
+
import { createProgressIndicator, debugMessage, printMessage, stopProgressIndicator, updateProgressIndicator } from '../utils/Console';
|
|
4
4
|
import { getRealmString, getTypedFilename, saveJsonToFile } from '../utils/ExportImportUtils';
|
|
5
5
|
const {
|
|
6
6
|
readSocialIdentityProviders,
|
|
@@ -74,14 +74,14 @@ export async function exportSocialIdentityProviderToFile(providerId, file = '')
|
|
|
74
74
|
fileName = getTypedFilename(providerId, 'idp');
|
|
75
75
|
}
|
|
76
76
|
const filePath = getFilePath(fileName, true);
|
|
77
|
-
|
|
77
|
+
const indicatorId = createProgressIndicator('determinate', 1, `Exporting ${providerId}`);
|
|
78
78
|
try {
|
|
79
|
-
|
|
79
|
+
updateProgressIndicator(indicatorId, `Writing file ${filePath}`);
|
|
80
80
|
const fileData = await exportSocialIdentityProvider(providerId);
|
|
81
81
|
saveJsonToFile(fileData, filePath);
|
|
82
|
-
|
|
82
|
+
stopProgressIndicator(indicatorId, `Exported ${providerId['brightCyan']} to ${filePath['brightCyan']}.`);
|
|
83
83
|
} catch (err) {
|
|
84
|
-
|
|
84
|
+
stopProgressIndicator(indicatorId, `${err}`);
|
|
85
85
|
printMessage(`${err}`, 'error');
|
|
86
86
|
}
|
|
87
87
|
debugMessage(`cli.IdpOps.exportSocialIdentityProviderToFile: end`);
|
|
@@ -105,22 +105,23 @@ export async function exportSocialIdentityProvidersToFile(file = '') {
|
|
|
105
105
|
*/
|
|
106
106
|
export async function exportSocialIdentityProvidersToFiles() {
|
|
107
107
|
debugMessage(`cli.IdpOps.exportSocialIdentityProvidersToFiles: start`);
|
|
108
|
+
let indicatorId;
|
|
108
109
|
try {
|
|
109
110
|
const allIdpsData = await readSocialIdentityProviders();
|
|
110
|
-
|
|
111
|
+
indicatorId = createProgressIndicator('determinate', allIdpsData.length, 'Exporting providers');
|
|
111
112
|
for (const idpData of allIdpsData) {
|
|
112
113
|
try {
|
|
113
114
|
const fileName = getTypedFilename(idpData._id, 'idp');
|
|
114
115
|
const fileData = await exportSocialIdentityProvider(idpData._id);
|
|
115
116
|
saveJsonToFile(fileData, getFilePath(fileName, true));
|
|
116
|
-
|
|
117
|
+
updateProgressIndicator(indicatorId, `Exported provider ${idpData._id}`);
|
|
117
118
|
} catch (error) {
|
|
118
119
|
printMessage(`Error exporting ${idpData._id}: ${error}`, 'error');
|
|
119
120
|
}
|
|
120
121
|
}
|
|
121
|
-
|
|
122
|
+
stopProgressIndicator(indicatorId, `${allIdpsData.length} providers exported.`);
|
|
122
123
|
} catch (error) {
|
|
123
|
-
|
|
124
|
+
stopProgressIndicator(indicatorId, `${error}`);
|
|
124
125
|
printMessage(`${error}`, 'error');
|
|
125
126
|
}
|
|
126
127
|
debugMessage(`cli.IdpOps.exportSocialIdentityProvidersToFiles: end`);
|
|
@@ -135,20 +136,18 @@ export async function exportSocialIdentityProvidersToFiles() {
|
|
|
135
136
|
export async function importSocialIdentityProviderFromFile(providerId, file) {
|
|
136
137
|
let outcome = false;
|
|
137
138
|
const filePath = getFilePath(file);
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
});
|
|
139
|
+
const indicatorId = createProgressIndicator('indeterminate', 0, `Importing provider ${providerId} from ${filePath}...`);
|
|
140
|
+
try {
|
|
141
|
+
const data = fs.readFileSync(filePath, 'utf8');
|
|
142
|
+
const fileData = JSON.parse(data);
|
|
143
|
+
await importSocialIdentityProvider(providerId, fileData);
|
|
144
|
+
outcome = true;
|
|
145
|
+
stopProgressIndicator(indicatorId, `Successfully imported provider ${providerId} from ${filePath}.`, 'success');
|
|
146
|
+
} catch (error) {
|
|
147
|
+
var _error$response;
|
|
148
|
+
stopProgressIndicator(indicatorId, `Error importing provider ${providerId} from ${filePath}.`, 'fail');
|
|
149
|
+
printMessage(((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data) || error, 'error');
|
|
150
|
+
}
|
|
152
151
|
return outcome;
|
|
153
152
|
}
|
|
154
153
|
|
|
@@ -160,20 +159,18 @@ export async function importSocialIdentityProviderFromFile(providerId, file) {
|
|
|
160
159
|
export async function importFirstSocialIdentityProviderFromFile(file) {
|
|
161
160
|
let outcome = false;
|
|
162
161
|
const filePath = getFilePath(file);
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
});
|
|
162
|
+
const indicatorId = createProgressIndicator('indeterminate', 0, `Importing first provider from ${filePath}...`);
|
|
163
|
+
try {
|
|
164
|
+
const data = fs.readFileSync(filePath, 'utf8');
|
|
165
|
+
const fileData = JSON.parse(data);
|
|
166
|
+
await importFirstSocialIdentityProvider(fileData);
|
|
167
|
+
outcome = true;
|
|
168
|
+
stopProgressIndicator(indicatorId, `Successfully imported first provider from ${filePath}.`, 'success');
|
|
169
|
+
} catch (error) {
|
|
170
|
+
var _error$response2;
|
|
171
|
+
stopProgressIndicator(indicatorId, `Error importing first provider from ${filePath}.`, 'fail');
|
|
172
|
+
printMessage(((_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.data) || error, 'error');
|
|
173
|
+
}
|
|
177
174
|
return outcome;
|
|
178
175
|
}
|
|
179
176
|
|
|
@@ -185,20 +182,18 @@ export async function importFirstSocialIdentityProviderFromFile(file) {
|
|
|
185
182
|
export async function importSocialIdentityProvidersFromFile(file) {
|
|
186
183
|
let outcome = false;
|
|
187
184
|
const filePath = getFilePath(file);
|
|
188
|
-
|
|
189
|
-
fs.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
});
|
|
185
|
+
const indicatorId = createProgressIndicator('indeterminate', 0, `Importing providers from ${filePath}...`);
|
|
186
|
+
const data = fs.readFileSync(filePath, 'utf8');
|
|
187
|
+
try {
|
|
188
|
+
const fileData = JSON.parse(data);
|
|
189
|
+
await importSocialIdentityProviders(fileData);
|
|
190
|
+
outcome = true;
|
|
191
|
+
stopProgressIndicator(indicatorId, `Successfully imported providers from ${filePath}.`, 'success');
|
|
192
|
+
} catch (error) {
|
|
193
|
+
var _error$response3;
|
|
194
|
+
stopProgressIndicator(indicatorId, `Error importing providers from ${filePath}.`, 'fail');
|
|
195
|
+
printMessage(((_error$response3 = error.response) === null || _error$response3 === void 0 ? void 0 : _error$response3.data) || error, 'error');
|
|
196
|
+
}
|
|
202
197
|
return outcome;
|
|
203
198
|
}
|
|
204
199
|
|
|
@@ -208,7 +203,7 @@ export async function importSocialIdentityProvidersFromFile(file) {
|
|
|
208
203
|
export async function importSocialIdentityProvidersFromFiles() {
|
|
209
204
|
const names = fs.readdirSync(getWorkingDirectory());
|
|
210
205
|
const jsonFiles = names.filter(name => name.toLowerCase().endsWith('.idp.json')).map(name => getFilePath(name));
|
|
211
|
-
|
|
206
|
+
const indicatorId = createProgressIndicator('determinate', jsonFiles.length, 'Importing providers...');
|
|
212
207
|
let total = 0;
|
|
213
208
|
for (const file of jsonFiles) {
|
|
214
209
|
const data = fs.readFileSync(file, 'utf8');
|
|
@@ -216,8 +211,8 @@ export async function importSocialIdentityProvidersFromFiles() {
|
|
|
216
211
|
const count = Object.keys(fileData.idp).length;
|
|
217
212
|
total += count;
|
|
218
213
|
await importSocialIdentityProviders(fileData);
|
|
219
|
-
|
|
214
|
+
updateProgressIndicator(indicatorId, `Imported ${count} provider(s) from ${file}`);
|
|
220
215
|
}
|
|
221
|
-
|
|
216
|
+
stopProgressIndicator(indicatorId, `Finished importing ${total} provider(s) from ${jsonFiles.length} file(s).`);
|
|
222
217
|
}
|
|
223
218
|
//# sourceMappingURL=IdpOps.js.map
|
package/esm/ops/IdpOps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdpOps.js","names":["frodo","fs","createProgressBar","debugMessage","failSpinner","printMessage","showSpinner","stopProgressBar","succeedSpinner","updateProgressBar","getRealmString","getTypedFilename","saveJsonToFile","readSocialIdentityProviders","exportSocialIdentityProvider","exportSocialIdentityProviders","importFirstSocialIdentityProvider","importSocialIdentityProvider","importSocialIdentityProviders","oauth2oidc","external","getFilePath","getWorkingDirectory","utils","getOneLineDescription","socialIdpObj","description","_id","_type","getTableHeaderMd","markdown","getTableRowMd","row","enabled","name","listSocialProviders","providers","sort","a","b","localeCompare","forEach","socialIdentityProvider","err","message","exportSocialIdentityProviderToFile","providerId","file","fileName","filePath","fileData","exportSocialIdentityProvidersToFile","exportSocialIdentityProvidersToFiles","allIdpsData","length","idpData","error","importSocialIdentityProviderFromFile","outcome","readFile","data","JSON","parse","_error$response","response","importFirstSocialIdentityProviderFromFile","_error$response2","importSocialIdentityProvidersFromFile","_error$response3","importSocialIdentityProvidersFromFiles","names","readdirSync","jsonFiles","filter","toLowerCase","endsWith","map","total","readFileSync","count","Object","keys","idp"],"sources":["../../src/ops/IdpOps.ts"],"sourcesContent":["import { frodo } from '@rockcarver/frodo-lib';\nimport { SocialIdpSkeleton } from '@rockcarver/frodo-lib/types/api/SocialIdentityProvidersApi';\nimport fs from 'fs';\n\nimport {\n createProgressBar,\n debugMessage,\n failSpinner,\n printMessage,\n showSpinner,\n stopProgressBar,\n succeedSpinner,\n updateProgressBar,\n} from '../utils/Console';\nimport {\n getRealmString,\n getTypedFilename,\n saveJsonToFile,\n} from '../utils/ExportImportUtils';\n\nconst {\n readSocialIdentityProviders,\n exportSocialIdentityProvider,\n exportSocialIdentityProviders,\n importFirstSocialIdentityProvider,\n importSocialIdentityProvider,\n importSocialIdentityProviders,\n} = frodo.oauth2oidc.external;\n\nconst { getFilePath, getWorkingDirectory } = frodo.utils;\n\n/**\n * Get a one-line description of the social idp object\n * @param {SocialIdpSkeleton} socialIdpObj social idp object to describe\n * @returns {string} a one-line description\n */\nexport function getOneLineDescription(socialIdpObj: SocialIdpSkeleton): string {\n const description = `[${socialIdpObj._id['brightCyan']}] ${socialIdpObj._type._id}`;\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 += '| Name/Id | Status | Type |\\n';\n markdown += '| ------- | ------ | ---- |';\n return markdown;\n}\n\n/**\n * Get a table-row of the social idp in markdown\n * @param {SocialIdpSkeleton} socialIdpObj social idp object to describe\n * @returns {string} a table-row of the social idp in markdown\n */\nexport function getTableRowMd(socialIdpObj: SocialIdpSkeleton): string {\n const row = `| ${socialIdpObj._id} | ${\n socialIdpObj.enabled === false\n ? ':o: `disabled`'\n : ':white_check_mark: `enabled`'\n } | ${socialIdpObj._type.name} |`;\n return row;\n}\n\n/**\n * List providers\n */\nexport async function listSocialProviders() {\n try {\n const providers = await readSocialIdentityProviders();\n providers.sort((a, b) => a._id.localeCompare(b._id));\n providers.forEach((socialIdentityProvider) => {\n printMessage(`${socialIdentityProvider._id}`, 'data');\n });\n } catch (err) {\n printMessage(`listSocialProviders ERROR: ${err.message}`, 'error');\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export provider by id\n * @param {string} providerId provider id/name\n * @param {string} file optional export file name\n */\nexport async function exportSocialIdentityProviderToFile(\n providerId: string,\n file = ''\n) {\n debugMessage(`cli.IdpOps.exportSocialIdentityProviderToFile: start`);\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(providerId, 'idp');\n }\n const filePath = getFilePath(fileName, true);\n createProgressBar(1, `Exporting ${providerId}`);\n try {\n updateProgressBar(`Writing file ${filePath}`);\n const fileData = await exportSocialIdentityProvider(providerId);\n saveJsonToFile(fileData, filePath);\n stopProgressBar(\n `Exported ${providerId['brightCyan']} to ${filePath['brightCyan']}.`\n );\n } catch (err) {\n stopProgressBar(`${err}`);\n printMessage(`${err}`, 'error');\n }\n debugMessage(`cli.IdpOps.exportSocialIdentityProviderToFile: end`);\n}\n\n/**\n * Export all providers\n * @param {string} file optional export file name\n */\nexport async function exportSocialIdentityProvidersToFile(file = '') {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(`all${getRealmString()}Providers`, 'idp');\n }\n const fileData = await exportSocialIdentityProviders();\n saveJsonToFile(fileData, getFilePath(fileName, true));\n}\n\n/**\n * Export all providers to individual files\n */\nexport async function exportSocialIdentityProvidersToFiles() {\n debugMessage(`cli.IdpOps.exportSocialIdentityProvidersToFiles: start`);\n try {\n const allIdpsData = await readSocialIdentityProviders();\n createProgressBar(allIdpsData.length, 'Exporting providers');\n for (const idpData of allIdpsData) {\n try {\n const fileName = getTypedFilename(idpData._id, 'idp');\n const fileData = await exportSocialIdentityProvider(idpData._id);\n saveJsonToFile(fileData, getFilePath(fileName, true));\n updateProgressBar(`Exported provider ${idpData._id}`);\n } catch (error) {\n printMessage(`Error exporting ${idpData._id}: ${error}`, 'error');\n }\n }\n stopProgressBar(`${allIdpsData.length} providers exported.`);\n } catch (error) {\n stopProgressBar(`${error}`);\n printMessage(`${error}`, 'error');\n }\n debugMessage(`cli.IdpOps.exportSocialIdentityProvidersToFiles: end`);\n}\n\n/**\n * Import provider by id/name\n * @param {string} providerId provider id/name\n * @param {string} file import file name\n * @returns {Promise<boolean>} true if provider was imported successfully, false otherwise\n */\nexport async function importSocialIdentityProviderFromFile(\n providerId: string,\n file: string\n): Promise<boolean> {\n let outcome = false;\n const filePath = getFilePath(file);\n showSpinner(`Importing provider ${providerId} from ${filePath}...`);\n fs.readFile(filePath, 'utf8', async (err, data) => {\n if (err) throw err;\n try {\n const fileData = JSON.parse(data);\n await importSocialIdentityProvider(providerId, fileData);\n outcome = true;\n succeedSpinner(\n `Successfully imported provider ${providerId} from ${filePath}.`\n );\n } catch (error) {\n failSpinner(`Error importing provider ${providerId} from ${filePath}.`);\n printMessage(error.response?.data || error, 'error');\n }\n });\n return outcome;\n}\n\n/**\n * Import first provider from file\n * @param {String} file import file name\n * @returns {Promise<boolean>} true if first provider was imported successfully, false otherwise\n */\nexport async function importFirstSocialIdentityProviderFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n const filePath = getFilePath(file);\n showSpinner(`Importing first provider from ${filePath}...`);\n fs.readFile(filePath, 'utf8', async (err, data) => {\n if (err) throw err;\n try {\n const fileData = JSON.parse(data);\n await importFirstSocialIdentityProvider(fileData);\n outcome = true;\n succeedSpinner(`Successfully imported first provider from ${filePath}.`);\n } catch (error) {\n failSpinner(`Error importing first provider from ${filePath}.`);\n printMessage(error.response?.data || error, 'error');\n }\n });\n return outcome;\n}\n\n/**\n * Import all providers from file\n * @param {string} file import file name\n * @returns {Promise<boolean>} true if all providers were imported successfully, false otherwise\n */\nexport async function importSocialIdentityProvidersFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n const filePath = getFilePath(file);\n showSpinner(`Importing providers from ${filePath}...`);\n fs.readFile(filePath, 'utf8', async (err, data) => {\n if (err) throw err;\n try {\n const fileData = JSON.parse(data);\n await importSocialIdentityProviders(fileData);\n outcome = true;\n succeedSpinner(`Successfully imported providers from ${filePath}.`);\n } catch (error) {\n failSpinner(`Error importing providers from ${filePath}.`);\n printMessage(error.response?.data || error, 'error');\n }\n });\n return outcome;\n}\n\n/**\n * Import providers from *.idp.json files in current working directory\n */\nexport async function importSocialIdentityProvidersFromFiles() {\n const names = fs.readdirSync(getWorkingDirectory());\n const jsonFiles = names\n .filter((name) => name.toLowerCase().endsWith('.idp.json'))\n .map((name) => getFilePath(name));\n\n createProgressBar(jsonFiles.length, 'Importing providers...');\n let total = 0;\n for (const file of jsonFiles) {\n const data = fs.readFileSync(file, 'utf8');\n const fileData = JSON.parse(data);\n const count = Object.keys(fileData.idp).length;\n total += count;\n await importSocialIdentityProviders(fileData);\n updateProgressBar(`Imported ${count} provider(s) from ${file}`);\n }\n stopProgressBar(\n `Finished importing ${total} provider(s) from ${jsonFiles.length} file(s).`\n );\n}\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,uBAAuB;AAE7C,OAAOC,EAAE,MAAM,IAAI;AAEnB,SACEC,iBAAiB,EACjBC,YAAY,EACZC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,eAAe,EACfC,cAAc,EACdC,iBAAiB,QACZ,kBAAkB;AACzB,SACEC,cAAc,EACdC,gBAAgB,EAChBC,cAAc,QACT,4BAA4B;AAEnC,MAAM;EACJC,2BAA2B;EAC3BC,4BAA4B;EAC5BC,6BAA6B;EAC7BC,iCAAiC;EACjCC,4BAA4B;EAC5BC;AACF,CAAC,GAAGlB,KAAK,CAACmB,UAAU,CAACC,QAAQ;AAE7B,MAAM;EAAEC,WAAW;EAAEC;AAAoB,CAAC,GAAGtB,KAAK,CAACuB,KAAK;;AAExD;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CAACC,YAA+B,EAAU;EAC7E,MAAMC,WAAW,GAAI,IAAGD,YAAY,CAACE,GAAG,CAAC,YAAY,CAAE,KAAIF,YAAY,CAACG,KAAK,CAACD,GAAI,EAAC;EACnF,OAAOD,WAAW;AACpB;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASG,gBAAgBA,CAAA,EAAW;EACzC,IAAIC,QAAQ,GAAG,EAAE;EACjBA,QAAQ,IAAI,+BAA+B;EAC3CA,QAAQ,IAAI,6BAA6B;EACzC,OAAOA,QAAQ;AACjB;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAACN,YAA+B,EAAU;EACrE,MAAMO,GAAG,GAAI,KA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,IAAI,CAAC/B,QAAQ,CAACgC,GAAG,CAAC,CAAC5B,MAAM;IAC9CuB,KAAK,IAAIE,KAAK;IACd,MAAM7D,6BAA6B,CAACgC,QAAQ,CAAC;IAC7CzC,iBAAiB,CAAE,YAAWsE,KAAM,qBAAoBhC,IAAK,EAAC,CAAC;EACjE;EACAxC,eAAe,CACZ,sBAAqBsE,KAAM,qBAAoBL,SAAS,CAAClB,MAAO,WACnE,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"IdpOps.js","names":["frodo","fs","createProgressIndicator","debugMessage","printMessage","stopProgressIndicator","updateProgressIndicator","getRealmString","getTypedFilename","saveJsonToFile","readSocialIdentityProviders","exportSocialIdentityProvider","exportSocialIdentityProviders","importFirstSocialIdentityProvider","importSocialIdentityProvider","importSocialIdentityProviders","oauth2oidc","external","getFilePath","getWorkingDirectory","utils","getOneLineDescription","socialIdpObj","description","_id","_type","getTableHeaderMd","markdown","getTableRowMd","row","enabled","name","listSocialProviders","providers","sort","a","b","localeCompare","forEach","socialIdentityProvider","err","message","exportSocialIdentityProviderToFile","providerId","file","fileName","filePath","indicatorId","fileData","exportSocialIdentityProvidersToFile","exportSocialIdentityProvidersToFiles","allIdpsData","length","idpData","error","importSocialIdentityProviderFromFile","outcome","data","readFileSync","JSON","parse","_error$response","response","importFirstSocialIdentityProviderFromFile","_error$response2","importSocialIdentityProvidersFromFile","_error$response3","importSocialIdentityProvidersFromFiles","names","readdirSync","jsonFiles","filter","toLowerCase","endsWith","map","total","count","Object","keys","idp"],"sources":["../../src/ops/IdpOps.ts"],"sourcesContent":["import { frodo } from '@rockcarver/frodo-lib';\nimport { SocialIdpSkeleton } from '@rockcarver/frodo-lib/types/api/SocialIdentityProvidersApi';\nimport fs from 'fs';\n\nimport {\n createProgressIndicator,\n debugMessage,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n} from '../utils/Console';\nimport {\n getRealmString,\n getTypedFilename,\n saveJsonToFile,\n} from '../utils/ExportImportUtils';\n\nconst {\n readSocialIdentityProviders,\n exportSocialIdentityProvider,\n exportSocialIdentityProviders,\n importFirstSocialIdentityProvider,\n importSocialIdentityProvider,\n importSocialIdentityProviders,\n} = frodo.oauth2oidc.external;\n\nconst { getFilePath, getWorkingDirectory } = frodo.utils;\n\n/**\n * Get a one-line description of the social idp object\n * @param {SocialIdpSkeleton} socialIdpObj social idp object to describe\n * @returns {string} a one-line description\n */\nexport function getOneLineDescription(socialIdpObj: SocialIdpSkeleton): string {\n const description = `[${socialIdpObj._id['brightCyan']}] ${socialIdpObj._type._id}`;\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 += '| Name/Id | Status | Type |\\n';\n markdown += '| ------- | ------ | ---- |';\n return markdown;\n}\n\n/**\n * Get a table-row of the social idp in markdown\n * @param {SocialIdpSkeleton} socialIdpObj social idp object to describe\n * @returns {string} a table-row of the social idp in markdown\n */\nexport function getTableRowMd(socialIdpObj: SocialIdpSkeleton): string {\n const row = `| ${socialIdpObj._id} | ${\n socialIdpObj.enabled === false\n ? ':o: `disabled`'\n : ':white_check_mark: `enabled`'\n } | ${socialIdpObj._type.name} |`;\n return row;\n}\n\n/**\n * List providers\n */\nexport async function listSocialProviders() {\n try {\n const providers = await readSocialIdentityProviders();\n providers.sort((a, b) => a._id.localeCompare(b._id));\n providers.forEach((socialIdentityProvider) => {\n printMessage(`${socialIdentityProvider._id}`, 'data');\n });\n } catch (err) {\n printMessage(`listSocialProviders ERROR: ${err.message}`, 'error');\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export provider by id\n * @param {string} providerId provider id/name\n * @param {string} file optional export file name\n */\nexport async function exportSocialIdentityProviderToFile(\n providerId: string,\n file = ''\n) {\n debugMessage(`cli.IdpOps.exportSocialIdentityProviderToFile: start`);\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(providerId, 'idp');\n }\n const filePath = getFilePath(fileName, true);\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n `Exporting ${providerId}`\n );\n try {\n updateProgressIndicator(indicatorId, `Writing file ${filePath}`);\n const fileData = await exportSocialIdentityProvider(providerId);\n saveJsonToFile(fileData, filePath);\n stopProgressIndicator(\n indicatorId,\n `Exported ${providerId['brightCyan']} to ${filePath['brightCyan']}.`\n );\n } catch (err) {\n stopProgressIndicator(indicatorId, `${err}`);\n printMessage(`${err}`, 'error');\n }\n debugMessage(`cli.IdpOps.exportSocialIdentityProviderToFile: end`);\n}\n\n/**\n * Export all providers\n * @param {string} file optional export file name\n */\nexport async function exportSocialIdentityProvidersToFile(file = '') {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(`all${getRealmString()}Providers`, 'idp');\n }\n const fileData = await exportSocialIdentityProviders();\n saveJsonToFile(fileData, getFilePath(fileName, true));\n}\n\n/**\n * Export all providers to individual files\n */\nexport async function exportSocialIdentityProvidersToFiles() {\n debugMessage(`cli.IdpOps.exportSocialIdentityProvidersToFiles: start`);\n let indicatorId: string;\n try {\n const allIdpsData = await readSocialIdentityProviders();\n indicatorId = createProgressIndicator(\n 'determinate',\n allIdpsData.length,\n 'Exporting providers'\n );\n for (const idpData of allIdpsData) {\n try {\n const fileName = getTypedFilename(idpData._id, 'idp');\n const fileData = await exportSocialIdentityProvider(idpData._id);\n saveJsonToFile(fileData, getFilePath(fileName, true));\n updateProgressIndicator(\n indicatorId,\n `Exported provider ${idpData._id}`\n );\n } catch (error) {\n printMessage(`Error exporting ${idpData._id}: ${error}`, 'error');\n }\n }\n stopProgressIndicator(\n indicatorId,\n `${allIdpsData.length} providers exported.`\n );\n } catch (error) {\n stopProgressIndicator(indicatorId, `${error}`);\n printMessage(`${error}`, 'error');\n }\n debugMessage(`cli.IdpOps.exportSocialIdentityProvidersToFiles: end`);\n}\n\n/**\n * Import provider by id/name\n * @param {string} providerId provider id/name\n * @param {string} file import file name\n * @returns {Promise<boolean>} true if provider was imported successfully, false otherwise\n */\nexport async function importSocialIdentityProviderFromFile(\n providerId: string,\n file: string\n): Promise<boolean> {\n let outcome = false;\n const filePath = getFilePath(file);\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Importing provider ${providerId} from ${filePath}...`\n );\n try {\n const data = fs.readFileSync(filePath, 'utf8');\n const fileData = JSON.parse(data);\n await importSocialIdentityProvider(providerId, fileData);\n outcome = true;\n stopProgressIndicator(\n indicatorId,\n `Successfully imported provider ${providerId} from ${filePath}.`,\n 'success'\n );\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error importing provider ${providerId} from ${filePath}.`,\n 'fail'\n );\n printMessage(error.response?.data || error, 'error');\n }\n return outcome;\n}\n\n/**\n * Import first provider from file\n * @param {String} file import file name\n * @returns {Promise<boolean>} true if first provider was imported successfully, false otherwise\n */\nexport async function importFirstSocialIdentityProviderFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n const filePath = getFilePath(file);\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Importing first provider from ${filePath}...`\n );\n try {\n const data = fs.readFileSync(filePath, 'utf8');\n const fileData = JSON.parse(data);\n await importFirstSocialIdentityProvider(fileData);\n outcome = true;\n stopProgressIndicator(\n indicatorId,\n `Successfully imported first provider from ${filePath}.`,\n 'success'\n );\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error importing first provider from ${filePath}.`,\n 'fail'\n );\n printMessage(error.response?.data || error, 'error');\n }\n return outcome;\n}\n\n/**\n * Import all providers from file\n * @param {string} file import file name\n * @returns {Promise<boolean>} true if all providers were imported successfully, false otherwise\n */\nexport async function importSocialIdentityProvidersFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n const filePath = getFilePath(file);\n const indicatorId = createProgressIndicator(\n 'indeterminate',\n 0,\n `Importing providers from ${filePath}...`\n );\n const data = fs.readFileSync(filePath, 'utf8');\n try {\n const fileData = JSON.parse(data);\n await importSocialIdentityProviders(fileData);\n outcome = true;\n stopProgressIndicator(\n indicatorId,\n `Successfully imported providers from ${filePath}.`,\n 'success'\n );\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error importing providers from ${filePath}.`,\n 'fail'\n );\n printMessage(error.response?.data || error, 'error');\n }\n return outcome;\n}\n\n/**\n * Import providers from *.idp.json files in current working directory\n */\nexport async function importSocialIdentityProvidersFromFiles() {\n const names = fs.readdirSync(getWorkingDirectory());\n const jsonFiles = names\n .filter((name) => name.toLowerCase().endsWith('.idp.json'))\n .map((name) => getFilePath(name));\n\n const indicatorId = createProgressIndicator(\n 'determinate',\n jsonFiles.length,\n 'Importing providers...'\n );\n let total = 0;\n for (const file of jsonFiles) {\n const data = fs.readFileSync(file, 'utf8');\n const fileData = JSON.parse(data);\n const count = Object.keys(fileData.idp).length;\n total += count;\n await importSocialIdentityProviders(fileData);\n updateProgressIndicator(\n indicatorId,\n `Imported ${count} provider(s) from ${file}`\n );\n }\n stopProgressIndicator(\n indicatorId,\n `Finished importing ${total} provider(s) from ${jsonFiles.length} file(s).`\n );\n}\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,uBAAuB;AAE7C,OAAOC,EAAE,MAAM,IAAI;AAEnB,SACEC,uBAAuB,EACvBC,YAAY,EACZC,YAAY,EACZC,qBAAqB,EACrBC,uBAAuB,QAClB,kBAAkB;AACzB,SACEC,cAAc,EACdC,gBAAgB,EAChBC,cAAc,QACT,4BAA4B;AAEnC,MAAM;EACJC,2BAA2B;EAC3BC,4BAA4B;EAC5BC,6BAA6B;EAC7BC,iCAAiC;EACjCC,4BAA4B;EAC5BC;AACF,CAAC,GAAGf,KAAK,CAACgB,UAAU,CAACC,QAAQ;AAE7B,MAAM;EAAEC,WAAW;EAAEC;AAAoB,CAAC,GAAGnB,KAAK,CAACoB,KAAK;;AAExD;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CAACC,YAA+B,EAAU;EAC7E,MAAMC,WAAW,GAAI,IAAGD,YAAY,CAACE,GAAG,CAAC,YAAY,CAAE,KAAIF,YAAY,CAACG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C,CAAC;EACnD,MAAMmD,SAAS,GAAGF,KAAK,CACpBG,MAAM,CAAExC,IAAI,IAAKA,IAAI,CAACyC,WAAW,CAAC,CAAC,CAACC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAC1DC,GAAG,CAAE3C,IAAI,IAAKb,WAAW,CAACa,IAAI,CAAC,CAAC;EAEnC,MAAMgB,WAAW,GAAG7C,uBAAuB,CACzC,aAAa,EACboE,SAAS,CAAClB,MAAM,EAChB,wBACF,CAAC;EACD,IAAIuB,KAAK,GAAG,CAAC;EACb,KAAK,MAAM/B,IAAI,IAAI0B,SAAS,EAAE;IAC5B,MAAMb,IAAI,GAAGxD,EAAE,CAACyD,YAAY,CAACd,IAAI,EAAE,MAAM,CAAC;IAC1C,MAAMI,QAAQ,GAAGW,IAAI,CAACC,KAAK,CAACH,IAAI,CAAC;IACjC,MAAMmB,KAAK,GAAGC,MAAM,CAACC,IAAI,CAAC9B,QAAQ,CAAC+B,GAAG,CAAC,CAAC3B,MAAM;IAC9CuB,KAAK,IAAIC,KAAK;IACd,MAAM7D,6BAA6B,CAACiC,QAAQ,CAAC;IAC7C1C,uBAAuB,CACrByC,WAAW,EACV,YAAW6B,KAAM,qBAAoBhC,IAAK,EAC7C,CAAC;EACH;EACAvC,qBAAqB,CACnB0C,WAAW,EACV,sBAAqB4B,KAAM,qBAAoBL,SAAS,CAAClB,MAAO,WACnE,CAAC;AACH"}
|
package/esm/ops/JourneyOps.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { frodo, state } from '@rockcarver/frodo-lib';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
-
import {
|
|
3
|
+
import { createProgressIndicator, createTable, debugMessage, printMessage, stopProgressIndicator, updateProgressIndicator } from '../utils/Console';
|
|
4
4
|
import * as CirclesOfTrust from './CirclesOfTrustOps';
|
|
5
5
|
import * as EmailTemplate from './EmailTemplateOps';
|
|
6
6
|
import * as Idp from './IdpOps';
|
|
@@ -20,14 +20,16 @@ const {
|
|
|
20
20
|
const {
|
|
21
21
|
readJourneys,
|
|
22
22
|
exportJourney,
|
|
23
|
-
|
|
23
|
+
exportJourneys,
|
|
24
24
|
resolveDependencies,
|
|
25
25
|
importJourneys,
|
|
26
26
|
importJourney,
|
|
27
27
|
getTreeDescendents,
|
|
28
28
|
getNodeRef,
|
|
29
29
|
onlineTreeExportResolver,
|
|
30
|
-
getJourneyClassification: _getJourneyClassification
|
|
30
|
+
getJourneyClassification: _getJourneyClassification,
|
|
31
|
+
disableJourney: _disableJourney,
|
|
32
|
+
enableJourney: _enableJourney
|
|
31
33
|
} = frodo.authn.journey;
|
|
32
34
|
|
|
33
35
|
/**
|
|
@@ -53,7 +55,7 @@ export async function listJourneys(long = false, analyze = false) {
|
|
|
53
55
|
}
|
|
54
56
|
printMessage(table.toString(), 'data');
|
|
55
57
|
} else {
|
|
56
|
-
|
|
58
|
+
const spinnerId = createProgressIndicator('indeterminate', 0, `Retrieving details of all journeys...`);
|
|
57
59
|
const exportPromises = [];
|
|
58
60
|
try {
|
|
59
61
|
for (const journeyStub of journeys) {
|
|
@@ -63,7 +65,7 @@ export async function listJourneys(long = false, analyze = false) {
|
|
|
63
65
|
}));
|
|
64
66
|
}
|
|
65
67
|
const journeyExports = await Promise.all(exportPromises);
|
|
66
|
-
|
|
68
|
+
stopProgressIndicator(spinnerId, 'Retrieved details of all journeys.', 'success');
|
|
67
69
|
const table = createTable(['Name', 'Status', 'Classification', 'Tags']);
|
|
68
70
|
for (const journeyExport of journeyExports) {
|
|
69
71
|
var _journeyExport$tree$u;
|
|
@@ -71,7 +73,7 @@ export async function listJourneys(long = false, analyze = false) {
|
|
|
71
73
|
}
|
|
72
74
|
printMessage(table.toString(), 'data');
|
|
73
75
|
} catch (error) {
|
|
74
|
-
|
|
76
|
+
stopProgressIndicator(spinnerId, 'Error retrieving details of all journeys.', 'fail');
|
|
75
77
|
printMessage(error.response.data, 'error');
|
|
76
78
|
}
|
|
77
79
|
}
|
|
@@ -96,15 +98,16 @@ export async function exportJourneyToFile(journeyId, file, options) {
|
|
|
96
98
|
file = getTypedFilename(journeyId, 'journey');
|
|
97
99
|
}
|
|
98
100
|
const filePath = getFilePath(file, true);
|
|
99
|
-
|
|
101
|
+
let spinnerId;
|
|
102
|
+
if (!verbose) spinnerId = createProgressIndicator('indeterminate', 0, `${journeyId}`);
|
|
100
103
|
try {
|
|
101
104
|
const fileData = await exportJourney(journeyId, options);
|
|
102
|
-
if (verbose)
|
|
105
|
+
if (verbose) spinnerId = createProgressIndicator('indeterminate', 0, `${journeyId}`);
|
|
103
106
|
saveJsonToFile(fileData, filePath);
|
|
104
|
-
|
|
107
|
+
stopProgressIndicator(spinnerId, `Exported ${journeyId['brightCyan']} to ${filePath['brightCyan']}.`, 'success');
|
|
105
108
|
} catch (error) {
|
|
106
|
-
if (verbose)
|
|
107
|
-
|
|
109
|
+
if (verbose) spinnerId = createProgressIndicator('indeterminate', 0, `${journeyId}`);
|
|
110
|
+
stopProgressIndicator(spinnerId, `Error exporting journey ${journeyId}: ${error}`, 'fail');
|
|
108
111
|
}
|
|
109
112
|
}
|
|
110
113
|
|
|
@@ -121,21 +124,8 @@ export async function exportJourneysToFile(file, options = {
|
|
|
121
124
|
file = getTypedFilename(`all${getRealmString()}Journeys`, 'journey');
|
|
122
125
|
}
|
|
123
126
|
const filePath = getFilePath(file, true);
|
|
124
|
-
const
|
|
125
|
-
const fileData = createMultiTreeExportTemplate();
|
|
126
|
-
createProgressBar(trees.length, 'Exporting journeys...');
|
|
127
|
-
for (const tree of trees) {
|
|
128
|
-
updateProgressBar(`${tree._id}`);
|
|
129
|
-
try {
|
|
130
|
-
const exportData = await exportJourney(tree._id, options);
|
|
131
|
-
delete exportData.meta;
|
|
132
|
-
fileData.trees[tree._id] = exportData;
|
|
133
|
-
} catch (error) {
|
|
134
|
-
printMessage(`Error exporting journey ${tree._id}: ${error}`, 'error');
|
|
135
|
-
}
|
|
136
|
-
}
|
|
127
|
+
const fileData = await exportJourneys(options);
|
|
137
128
|
saveJsonToFile(fileData, filePath);
|
|
138
|
-
stopProgressBar(`Exported to ${filePath}`);
|
|
139
129
|
}
|
|
140
130
|
|
|
141
131
|
/**
|
|
@@ -143,19 +133,20 @@ export async function exportJourneysToFile(file, options = {
|
|
|
143
133
|
* @param {TreeExportOptions} options export options
|
|
144
134
|
*/
|
|
145
135
|
export async function exportJourneysToFiles(options) {
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
for (const
|
|
149
|
-
|
|
150
|
-
const
|
|
136
|
+
const journeysExport = await exportJourneys(options);
|
|
137
|
+
const trees = Object.entries(journeysExport.trees);
|
|
138
|
+
for (const [treeId, treeValue] of trees) {
|
|
139
|
+
const indicatorId = createProgressIndicator('determinate', 1, `Saving ${treeId}...`);
|
|
140
|
+
const file = getFilePath(getTypedFilename(`${treeId}`, 'journey'), true);
|
|
141
|
+
treeValue['meta'] = journeysExport.meta;
|
|
151
142
|
try {
|
|
152
|
-
|
|
153
|
-
saveJsonToFile(
|
|
143
|
+
updateProgressIndicator(indicatorId, `Saving ${treeId} to ${file}`);
|
|
144
|
+
saveJsonToFile(treeValue, file);
|
|
145
|
+
stopProgressIndicator(indicatorId, `${treeId} saved to ${file}`);
|
|
154
146
|
} catch (error) {
|
|
155
|
-
|
|
147
|
+
stopProgressIndicator(indicatorId, `Error saving ${treeId} to ${file}`);
|
|
156
148
|
}
|
|
157
149
|
}
|
|
158
|
-
stopProgressBar('Done');
|
|
159
150
|
}
|
|
160
151
|
|
|
161
152
|
/**
|
|
@@ -166,8 +157,8 @@ export async function exportJourneysToFiles(options) {
|
|
|
166
157
|
*/
|
|
167
158
|
export async function importJourneyFromFile(journeyId, file, options) {
|
|
168
159
|
const verbose = state.getVerbose();
|
|
169
|
-
|
|
170
|
-
|
|
160
|
+
try {
|
|
161
|
+
const data = fs.readFileSync(getFilePath(file), 'utf8');
|
|
171
162
|
let journeyData = JSON.parse(data);
|
|
172
163
|
// check if this is a file with multiple trees and get journey by id
|
|
173
164
|
if (journeyData.trees && journeyData.trees[journeyId]) {
|
|
@@ -182,32 +173,36 @@ export async function importJourneyFromFile(journeyId, file, options) {
|
|
|
182
173
|
const installedJourneys = (await readJourneys()).map(x => x._id);
|
|
183
174
|
const unresolvedJourneys = {};
|
|
184
175
|
const resolvedJourneys = [];
|
|
185
|
-
|
|
176
|
+
const indicatorId1 = createProgressIndicator('indeterminate', 0, 'Resolving dependencies');
|
|
186
177
|
await resolveDependencies(installedJourneys, {
|
|
187
178
|
[journeyId]: journeyData
|
|
188
179
|
}, unresolvedJourneys, resolvedJourneys);
|
|
189
180
|
if (Object.keys(unresolvedJourneys).length === 0) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
181
|
+
stopProgressIndicator(indicatorId1, `Resolved all dependencies.`, 'success');
|
|
182
|
+
let indicatorId2;
|
|
183
|
+
if (!verbose) indicatorId2 = createProgressIndicator('indeterminate', 0, `Importing ${journeyId}...`);
|
|
184
|
+
try {
|
|
185
|
+
await importJourney(journeyData, options);
|
|
186
|
+
if (verbose) indicatorId2 = createProgressIndicator('indeterminate', 0, `Importing ${journeyId}...`);
|
|
187
|
+
stopProgressIndicator(indicatorId2, `Imported ${journeyId}.`, 'success');
|
|
188
|
+
} catch (importError) {
|
|
189
|
+
if (verbose) indicatorId2 = createProgressIndicator('indeterminate', 0, `Importing ${journeyId}...`);
|
|
190
|
+
stopProgressIndicator(indicatorId2, `${importError}`, 'fail');
|
|
191
|
+
}
|
|
199
192
|
} else {
|
|
200
|
-
|
|
193
|
+
stopProgressIndicator(indicatorId1, `Unresolved dependencies:`, 'fail');
|
|
201
194
|
for (const journey of Object.keys(unresolvedJourneys)) {
|
|
202
195
|
printMessage(` ${journey} requires ${unresolvedJourneys[journey]}`, 'error');
|
|
203
196
|
}
|
|
204
197
|
}
|
|
205
198
|
// end dependency resolution for single tree import
|
|
206
199
|
} else {
|
|
207
|
-
|
|
208
|
-
|
|
200
|
+
const indicatorId3 = createProgressIndicator('indeterminate', 0, `Importing ${journeyId}...`);
|
|
201
|
+
stopProgressIndicator(indicatorId3, `${journeyId} not found!`, 'fail');
|
|
209
202
|
}
|
|
210
|
-
})
|
|
203
|
+
} catch (error) {
|
|
204
|
+
printMessage(`Error importing journey ${journeyId}: ${error}`, 'error');
|
|
205
|
+
}
|
|
211
206
|
}
|
|
212
207
|
|
|
213
208
|
/**
|
|
@@ -217,8 +212,8 @@ export async function importJourneyFromFile(journeyId, file, options) {
|
|
|
217
212
|
*/
|
|
218
213
|
export async function importFirstJourneyFromFile(file, options) {
|
|
219
214
|
const verbose = state.getVerbose();
|
|
220
|
-
|
|
221
|
-
|
|
215
|
+
try {
|
|
216
|
+
const data = fs.readFileSync(getFilePath(file), 'utf8');
|
|
222
217
|
let journeyData = cloneDeep(JSON.parse(data));
|
|
223
218
|
let journeyId = null;
|
|
224
219
|
// single tree
|
|
@@ -242,32 +237,36 @@ export async function importFirstJourneyFromFile(file, options) {
|
|
|
242
237
|
const installedJourneys = (await readJourneys()).map(x => x._id);
|
|
243
238
|
const unresolvedJourneys = {};
|
|
244
239
|
const resolvedJourneys = [];
|
|
245
|
-
|
|
240
|
+
const depSpinnerId = createProgressIndicator('indeterminate', 0, 'Resolving dependencies');
|
|
246
241
|
await resolveDependencies(installedJourneys, {
|
|
247
242
|
[journeyId]: journeyData
|
|
248
243
|
}, unresolvedJourneys, resolvedJourneys);
|
|
249
244
|
if (Object.keys(unresolvedJourneys).length === 0) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
245
|
+
stopProgressIndicator(depSpinnerId, `Resolved all dependencies.`, 'success');
|
|
246
|
+
let importSpinnerId;
|
|
247
|
+
if (!verbose) importSpinnerId = createProgressIndicator('indeterminate', 0, `Importing ${journeyId}...`);
|
|
248
|
+
try {
|
|
249
|
+
await importJourney(journeyData, options);
|
|
250
|
+
if (verbose) importSpinnerId = createProgressIndicator('indeterminate', 0, `Importing ${journeyId}...`);
|
|
251
|
+
stopProgressIndicator(importSpinnerId, `Imported ${journeyId}.`, 'success');
|
|
252
|
+
} catch (importError) {
|
|
253
|
+
if (verbose) importSpinnerId = createProgressIndicator('indeterminate', 0, `Importing ${journeyId}...`);
|
|
254
|
+
stopProgressIndicator(importSpinnerId, `${importError}`, 'fail');
|
|
255
|
+
}
|
|
259
256
|
} else {
|
|
260
|
-
|
|
257
|
+
stopProgressIndicator(depSpinnerId, `Unresolved dependencies:`, 'fail');
|
|
261
258
|
for (const journey of Object.keys(unresolvedJourneys)) {
|
|
262
259
|
printMessage(` ${journey} requires ${unresolvedJourneys[journey]}`, 'error');
|
|
263
260
|
}
|
|
264
261
|
}
|
|
265
262
|
} else {
|
|
266
|
-
|
|
267
|
-
|
|
263
|
+
const importSpinnerId = createProgressIndicator('indeterminate', 0, `Importing...`);
|
|
264
|
+
stopProgressIndicator(importSpinnerId, `No journeys found!`, 'fail');
|
|
268
265
|
}
|
|
269
266
|
// end dependency resolution for single tree import
|
|
270
|
-
})
|
|
267
|
+
} catch (error) {
|
|
268
|
+
printMessage(`Error importing first journey: ${error}`, 'error');
|
|
269
|
+
}
|
|
271
270
|
}
|
|
272
271
|
|
|
273
272
|
/**
|
|
@@ -276,11 +275,11 @@ export async function importFirstJourneyFromFile(file, options) {
|
|
|
276
275
|
* @param {TreeImportOptions} options import options
|
|
277
276
|
*/
|
|
278
277
|
export async function importJourneysFromFile(file, options) {
|
|
279
|
-
|
|
280
|
-
|
|
278
|
+
try {
|
|
279
|
+
const data = fs.readFileSync(getFilePath(file), 'utf8');
|
|
281
280
|
try {
|
|
282
281
|
const fileData = JSON.parse(data);
|
|
283
|
-
importJourneys(fileData.trees, options);
|
|
282
|
+
await importJourneys(fileData.trees, options);
|
|
284
283
|
} catch (error) {
|
|
285
284
|
if (error.name === 'UnresolvedDependenciesError') {
|
|
286
285
|
for (const journey of Object.keys(error.unresolvedJourneys)) {
|
|
@@ -294,7 +293,9 @@ export async function importJourneysFromFile(file, options) {
|
|
|
294
293
|
printMessage(`${error.message}`, 'error');
|
|
295
294
|
}
|
|
296
295
|
}
|
|
297
|
-
})
|
|
296
|
+
} catch (error) {
|
|
297
|
+
printMessage(`Error importing journeys: ${error}`, 'error');
|
|
298
|
+
}
|
|
298
299
|
}
|
|
299
300
|
|
|
300
301
|
/**
|
|
@@ -682,4 +683,24 @@ export async function describeJourneyMd(journeyData, resolveTreeExport = onlineT
|
|
|
682
683
|
}
|
|
683
684
|
}
|
|
684
685
|
}
|
|
686
|
+
export async function enableJourney(journeyId) {
|
|
687
|
+
const indicatorId = createProgressIndicator('indeterminate', 0, `Enabling journey ${journeyId}...`);
|
|
688
|
+
if (_enableJourney(journeyId)) {
|
|
689
|
+
stopProgressIndicator(indicatorId, `Enabled journey ${journeyId}.`, 'success');
|
|
690
|
+
return true;
|
|
691
|
+
} else {
|
|
692
|
+
stopProgressIndicator(indicatorId, `Error enabling journey ${journeyId}`, 'fail');
|
|
693
|
+
return false;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
export async function disableJourney(journeyId) {
|
|
697
|
+
const indicatorId = createProgressIndicator('indeterminate', 0, `Disabling journey ${journeyId}...`);
|
|
698
|
+
if (_disableJourney(journeyId)) {
|
|
699
|
+
stopProgressIndicator(indicatorId, `Disabled journey ${journeyId}.`, 'success');
|
|
700
|
+
return true;
|
|
701
|
+
} else {
|
|
702
|
+
stopProgressIndicator(indicatorId, `Error disabling journey ${journeyId}`, 'fail');
|
|
703
|
+
return false;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
685
706
|
//# sourceMappingURL=JourneyOps.js.map
|