Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/cli/journey/journey-describe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
"Override version. Notation: '<major>.<minor>.<patch>' e.g. '7.2.0'. Override detected version with any version. This is helpful in order to check if journeys in one environment would be compatible running in another environment (e.g. in preparation of migrating from on-prem to ForgeRock Identity Cloud."
)
)
.addOption(

Check warning on line 46 in src/cli/journey/journey-describe.ts

View workflow job for this annotation

GitHub Actions / Build

Replace `⏎······new·Option(⏎········'-u,·--usage',⏎·····` with `new·Option('-u,·--usage',`
new Option(
'-u, --usage',
'List all uses of the journey.'))
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
Expand Down Expand Up @@ -119,7 +123,8 @@
if (!options.markdown) {
const outcome = await describeJourney(
journeyData,
createFileParamTreeExportResolver(options.file)
createFileParamTreeExportResolver(options.file),
options.usage
);
if (!outcome) process.exitCode = 1;
}
Expand Down Expand Up @@ -154,7 +159,7 @@
const treeData = await exportJourney(journey['_id']);
// ANSI text output
if (!options.markdown) {
const outcome = await describeJourney(treeData);
const outcome = await describeJourney(treeData, undefined, options.usage);

Check warning on line 162 in src/cli/journey/journey-describe.ts

View workflow job for this annotation

GitHub Actions / Build

Replace `treeData,·undefined,·options.usage` with `⏎····················treeData,⏎····················undefined,⏎····················options.usage⏎··················`
if (!outcome) process.exitCode = 1;
}
// Markdown output
Expand All @@ -175,7 +180,7 @@
const treeData = await exportJourney(options.journeyId);
// ANSI text output
if (!options.markdown) {
const outcome = await describeJourney(treeData);
const outcome = await describeJourney(treeData, undefined, options.usage);

Check warning on line 183 in src/cli/journey/journey-describe.ts

View workflow job for this annotation

GitHub Actions / Build

Replace `treeData,·undefined,·options.usage` with `⏎··················treeData,⏎··················undefined,⏎··················options.usage⏎················`
if (!outcome) process.exitCode = 1;
}
// Markdown output
Expand Down
71 changes: 70 additions & 1 deletion src/ops/JourneyOps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { frodo, FrodoError, state } from '@rockcarver/frodo-lib';

Check failure on line 1 in src/ops/JourneyOps.ts

View workflow job for this annotation

GitHub Actions / Build

Run autofix to sort these imports!
import { type NodeSkeleton } from '@rockcarver/frodo-lib/types/api/NodeApi';
import { type TreeSkeleton } from '@rockcarver/frodo-lib/types/api/TreeApi';
import {
Expand All @@ -14,13 +14,15 @@
import fs from 'fs';

import {
createKeyValueTable,
createProgressIndicator,
createTable,
debugMessage,
printError,
printMessage,
stopProgressIndicator,
updateProgressIndicator,
stopAllProgressBars,
} from '../utils/Console';
import * as CirclesOfTrust from './CirclesOfTrustOps';
import * as EmailTemplate from './EmailTemplateOps';
Expand All @@ -31,6 +33,7 @@
import * as Theme from './ThemeOps';
import { cloneDeep, errorHandler } from './utils/OpsUtils';
import wordwrap from './utils/Wordwrap';
import { getFullExportConfig } from '../utils/Config';

Check failure on line 36 in src/ops/JourneyOps.ts

View workflow job for this annotation

GitHub Actions / Build

'getFullExportConfig' is defined but never used

const {
getTypedFilename,
Expand Down Expand Up @@ -704,7 +707,8 @@
*/
export async function describeJourney(
journeyData: SingleTreeExportInterface,
resolveTreeExport: TreeExportResolverInterface = onlineTreeExportResolver
resolveTreeExport: TreeExportResolverInterface = onlineTreeExportResolver,
usage = false
): Promise<boolean> {
const errors: Error[] = [];
try {
Expand Down Expand Up @@ -766,6 +770,35 @@
'data'
);
}
// Usage
if (usage) {
try {
const journeysExport = await exportJourneys({
useStringArrays: true,
deps: false,
coords: false,
});
let journey = journeyData as SingleTreeExportInterface & {

Check failure on line 781 in src/ops/JourneyOps.ts

View workflow job for this annotation

GitHub Actions / Build

'journey' is never reassigned. Use 'const' instead
locations: string[];
};
const journeyName =
typeof journey.tree === 'string' ? journey.tree : journey.tree?._id;
journey.locations = getJourneyLocations(journeysExport, journeyName);
const table = createKeyValueTable();
table.push([
`Usage Locations (${journey.locations.length} total)`['brightCyan'],
journey.locations.length > 0 ? journey.locations[0] : '',
]);
for (let i = 1; i < journey.locations.length; i++) {
table.push(['', journey.locations[i]]);
}
stopAllProgressBars();
printMessage(table.toString(), 'data');
return true;
} catch (error) {
return false;
}
}

// Dependency Tree
try {
Expand Down Expand Up @@ -1212,3 +1245,39 @@
}
return false;
}

/**
* Helper that finds all locations where a journey is being used as an inner journey in another journey
* @param journeysExport export data containing journeys
* @param journeyName ID of the journey to search for as an inner journey
*/
function getJourneyLocations(
journeysExport: MultiTreeExportInterface,
journeyName: string
): string[] {
const locations: string[] = [];
for (const journeyData of Object.values(journeysExport.trees)) {
interface InnerTreeNode {
_id: string;
_type?: { _id?: string };
tree?: string | { _id: string };
}

for (const node of Object.values(
journeyData.nodes ?? {}
) as InnerTreeNode[]) {
const innerTreeName =
typeof node.tree === 'string' ? node.tree : node.tree?._id;

if (
node._type?._id === 'InnerTreeEvaluatorNode' &&
innerTreeName === journeyName
) {
locations.push(
`journey.${journeyData.tree?._id ?? journeyData.tree._id}`
);
}
}
}
return locations;
}
2 changes: 2 additions & 0 deletions src/ops/ScriptOps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { frodo, FrodoError, state } from '@rockcarver/frodo-lib';

Check failure on line 1 in src/ops/ScriptOps.ts

View workflow job for this annotation

GitHub Actions / Build

Run autofix to sort these imports!
import { type ScriptSkeleton } from '@rockcarver/frodo-lib/types/api/ScriptApi';
import { FullExportInterface } from '@rockcarver/frodo-lib/types/ops/ConfigOps';
import {
Expand Down Expand Up @@ -28,6 +28,7 @@
stopProgressIndicator,
succeedSpinner,
updateProgressIndicator,
stopAllProgressBars,
} from '../utils/Console';
import { errorHandler } from './utils/OpsUtils';
import wordwrap from './utils/Wordwrap';
Expand Down Expand Up @@ -252,6 +253,7 @@
table.push(['', script.locations[i]]);
}
}
stopAllProgressBars();
printMessage(table.toString(), 'data');
}
return true;
Expand Down
7 changes: 7 additions & 0 deletions src/utils/Console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,13 @@ function stopProgressBar(id: string, message: string = null) {
);
}

export function stopAllProgressBars() {
if (multiBarContainer) {
multiBarContainer.stop();
multiBarContainer = null;
}
}

/**
* Clean-up progress bars
*/
Expand Down
Loading