Skip to content

Commit

Permalink
Merge pull request #416 from vscheuber/main
Browse files Browse the repository at this point in the history
resolves #402 - Exporting Journeys or Scripts doesn't include any req…
  • Loading branch information
vscheuber authored Jun 19, 2024
2 parents 53480c1 + 1b363e4 commit d3de97a
Show file tree
Hide file tree
Showing 20 changed files with 21,898 additions and 12,118 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- \#402: Library scripts are now treated as dependencies during script and journey exports and imports.

## [2.0.0-85] - 2024-06-11

### Changed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"build": "npx tsup && npm run clean-types && npm run generate-types",
"doc": "npx typedoc",
"prettier:fix": "npm run prettier write",
"dev": "npx tsup --watch src"
"dev": "npx tsup --watch src --onSuccess 'npx tsup --dts-only'"
},
"description": "A library to manage ForgeRock Identity Cloud tenants, ForgeOps deployments, and classic deployments.",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion src/ops/ConfigOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export async function exportFullConfiguration({
await exportOrImportWithErrorHandling(
exportScripts,
{
includeDefault,
options: { includeLibraries: false, includeDefault, useStringArrays },
state,
},
errors
Expand Down
32 changes: 27 additions & 5 deletions src/ops/JourneyOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
type Saml2ProviderSkeleton,
updateProvider,
} from '../api/Saml2Api';
import { getScript, type ScriptSkeleton } from '../api/ScriptApi';
import { type ScriptSkeleton } from '../api/ScriptApi';
import {
getSocialIdentityProviders,
putProviderByTypeAndId,
Expand Down Expand Up @@ -81,7 +81,12 @@ import {
} from './NodeOps';
import { type ExportMetaData } from './OpsTypes';
import { readSaml2ProviderStubs } from './Saml2Ops';
import { updateScript } from './ScriptOps';
import {
getLibraryScriptNames,
readScript,
readScriptByName,
updateScript,
} from './ScriptOps';
import { readThemes, type ThemeSkeleton, updateThemes } from './ThemeOps';

export type Journey = {
Expand Down Expand Up @@ -920,7 +925,7 @@ export async function exportJourney({
hasScriptDependency(nodeObject) &&
nodeObject.script !== emptyScriptPlaceholder
) {
scriptPromises.push(getScript({ scriptId: nodeObject.script, state }));
scriptPromises.push(readScript({ scriptId: nodeObject.script, state }));
}

// frodo supports email templates in platform deployments
Expand Down Expand Up @@ -1055,7 +1060,7 @@ export async function exportJourney({
// handle script node types
if (deps && hasScriptDependency(innerNodeObject)) {
scriptPromises.push(
getScript({ scriptId: innerNodeObject.script, state })
readScript({ scriptId: innerNodeObject.script, state })
);
}

Expand Down Expand Up @@ -1244,7 +1249,7 @@ export async function exportJourney({
state,
});
scriptPromises.push(
getScript({ scriptId: socialProvider.transform, state })
readScript({ scriptId: socialProvider.transform, state })
);
exportData.socialIdentityProviders[socialProvider._id] =
socialProvider;
Expand All @@ -1262,6 +1267,7 @@ export async function exportJourney({
printMessage({ message: '\n - Scripts:', newline: false, state });
try {
const scriptObjects = await Promise.all(scriptPromises);
const name2uuid: { [key: string]: string } = {};
for (const scriptObject of scriptObjects) {
if (scriptObject) {
if (verbose)
Expand All @@ -1275,6 +1281,22 @@ export async function exportJourney({
? convertBase64TextToArray(scriptObject.script)
: JSON.stringify(decode(scriptObject.script));
exportData.scripts[scriptObject._id] = scriptObject;

// handle library scripts
const scriptNames = getLibraryScriptNames(scriptObject);
for (const scriptName of scriptNames) {
if (name2uuid[scriptName] === undefined) {
const libScriptObject = await readScriptByName({
scriptName,
state,
});
name2uuid[scriptName] = libScriptObject._id;
libScriptObject.script = useStringArrays
? convertBase64TextToArray(libScriptObject.script as string)
: JSON.stringify(decode(scriptObject.script));
exportData.scripts[libScriptObject._id] = libScriptObject;
}
}
}
}
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions src/ops/OAuth2ClientOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,8 @@ async function exportOAuth2ClientDependencies(
} catch (error) {
if (
!(
error.response?.status === 403 &&
error.response?.data?.message ===
(error as FrodoError).httpStatus === 403 &&
(error as FrodoError).httpMessage ===
'This operation is not available in ForgeRock Identity Cloud.'
)
) {
Expand Down
32 changes: 20 additions & 12 deletions src/ops/ScriptOps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,11 @@ describe('ScriptOps', () => {

test('1: Export all scripts', async () => {
const response = await ScriptOps.exportScripts({
includeDefault: false,
options: {
includeLibraries: false,
includeDefault: false,
useStringArrays: true,
},
state,
});
expect(response).toMatchSnapshot({
Expand All @@ -485,7 +489,11 @@ describe('ScriptOps', () => {

test('2: Export all scripts, including default scripts', async () => {
const response = await ScriptOps.exportScripts({
includeDefault: true,
options: {
includeLibraries: false,
includeDefault: true,
useStringArrays: true,
},
state,
});
expect(response).toMatchSnapshot({
Expand Down Expand Up @@ -525,16 +533,16 @@ describe('ScriptOps', () => {

test(`3: Import no scripts when excluding default scripts and only default scripts given`, async () => {
expect.assertions(1);
const result = await ScriptOps.importScripts({
scriptName: '',
importData: import2.data,
options: {
reUuid: false,
includeDefault: false,
},
state,
});
expect(result).toMatchSnapshot();
const result = await ScriptOps.importScripts({
scriptName: '',
importData: import2.data,
options: {
reUuid: false,
includeDefault: false,
},
state,
});
expect(result).toMatchSnapshot();
});
});

Expand Down
Loading

0 comments on commit d3de97a

Please sign in to comment.