diff --git a/src/cli-sync-ot.ts b/src/cli-sync-ot.ts index da163e82..dd9b6ca1 100644 --- a/src/cli-sync-ot.ts +++ b/src/cli-sync-ot.ts @@ -42,7 +42,10 @@ async function main(): Promise { // fetch the list of all assessments in the OneTrust organization const assessments = await getListOfOneTrustAssessments({ oneTrust }); - // fetch details about one assessment at a time and sync to disk right away to avoid running out of memory + /** + * fetch details about one assessment in series and push to transcend or write to disk + * (depending on the dryRun argument) right away to avoid running out of memory + */ await mapSeries(assessments, async (assessment, index) => { logger.info( `Fetching details about assessment ${index + 1} of ${ @@ -78,10 +81,11 @@ async function main(): Promise { ); } + // TODO: create a helper for this // enrich the sections with risk details const riskDetailsById = keyBy(riskDetails, 'id'); const { sections, ...restAssessmentDetails } = assessmentDetails; - const enrichedSections = sections.map((section) => { + const sectionsWithEnrichedRisk = sections.map((section) => { const { questions, ...restSection } = section; const enrichedQuestions = questions.map((question) => { const { risks, ...restQuestion } = question; @@ -113,17 +117,16 @@ async function main(): Promise { }); // combine the two assessments into a single enriched result - const enrichedAssessment = { + const assessmentWithEnrichedRisk = { ...restAssessmentDetails, - sections: enrichedSections, + sections: sectionsWithEnrichedRisk, }; writeOneTrustAssessment({ assessment: { ...assessment, - ...enrichedAssessment, + ...assessmentWithEnrichedRisk, }, - riskDetails, index, total: assessments.length, file, diff --git a/src/oneTrust/codecs.ts b/src/oneTrust/codecs.ts index 7be22bd4..3677d153 100644 --- a/src/oneTrust/codecs.ts +++ b/src/oneTrust/codecs.ts @@ -159,12 +159,12 @@ export type OneTrustEnrichedAssessmentResponse = t.TypeOf< // eslint-disable-next-line @typescript-eslint/no-unused-vars const { status, ...OneTrustAssessmentWithoutStatus } = OneTrustAssessment.props; -export const OneTrustCombinedAssessment = t.intersection([ +export const OneTrustEnrichedAssessment = t.intersection([ t.type(OneTrustAssessmentWithoutStatus), OneTrustEnrichedAssessmentResponse, ]); /** Type override */ -export type OneTrustCombinedAssessment = t.TypeOf< - typeof OneTrustCombinedAssessment +export type OneTrustEnrichedAssessment = t.TypeOf< + typeof OneTrustEnrichedAssessment >; diff --git a/src/oneTrust/constants.ts b/src/oneTrust/constants.ts index 1f7e65cf..de4cf982 100644 --- a/src/oneTrust/constants.ts +++ b/src/oneTrust/constants.ts @@ -1,14 +1,14 @@ import { createDefaultCodec } from '@transcend-io/type-utils'; -import { OneTrustCombinedAssessment } from './codecs'; +import { OneTrustEnrichedAssessment } from './codecs'; import { flattenOneTrustAssessment } from './flattenOneTrustAssessment'; /** - * An object with default values of type OneTrustCombinedAssessment. It's very + * An object with default values of type OneTrustEnrichedAssessment. It's very * valuable when converting assessments to CSV, as it contains all keys that * make up the CSV header in the expected order */ -const DEFAULT_ONE_TRUST_COMBINED_ASSESSMENT: OneTrustCombinedAssessment = - createDefaultCodec(OneTrustCombinedAssessment); +const DEFAULT_ONE_TRUST_COMBINED_ASSESSMENT: OneTrustEnrichedAssessment = + createDefaultCodec(OneTrustEnrichedAssessment); /** The header of the OneTrust ASsessment CSV file */ export const DEFAULT_ONE_TRUST_ASSESSMENT_CSV_HEADER = Object.keys( diff --git a/src/oneTrust/flattenOneTrustAssessment.ts b/src/oneTrust/flattenOneTrustAssessment.ts index ce31f9f5..9702b0fb 100644 --- a/src/oneTrust/flattenOneTrustAssessment.ts +++ b/src/oneTrust/flattenOneTrustAssessment.ts @@ -9,7 +9,7 @@ import { } from '@transcend-io/privacy-types'; import { extractProperties } from '../helpers'; import { - OneTrustCombinedAssessment, + OneTrustEnrichedAssessment, OneTrustEnrichedAssessmentQuestion, OneTrustEnrichedAssessmentSection, OneTrustEnrichedRisk, @@ -238,7 +238,7 @@ const flattenOneTrustSections = ( // TODO: update type to be a Record export const flattenOneTrustAssessment = ( - combinedAssessment: OneTrustCombinedAssessment, + combinedAssessment: OneTrustEnrichedAssessment, ): Record => { const { approvers, diff --git a/src/oneTrust/writeOneTrustAssessment.ts b/src/oneTrust/writeOneTrustAssessment.ts index eb7a08fc..56e29fa9 100644 --- a/src/oneTrust/writeOneTrustAssessment.ts +++ b/src/oneTrust/writeOneTrustAssessment.ts @@ -5,11 +5,8 @@ import fs from 'fs'; import { flattenOneTrustAssessment } from './flattenOneTrustAssessment'; import { DEFAULT_ONE_TRUST_ASSESSMENT_CSV_HEADER } from './constants'; import { decodeCodec } from '@transcend-io/type-utils'; -import { - OneTrustAssessmentCsvRecord, - OneTrustGetRiskResponse, -} from '@transcend-io/privacy-types'; -import { OneTrustCombinedAssessment } from './codecs'; +import { OneTrustAssessmentCsvRecord } from '@transcend-io/privacy-types'; +import { OneTrustEnrichedAssessment } from './codecs'; /** * Write the assessment to disk at the specified file path. @@ -29,9 +26,7 @@ export const writeOneTrustAssessment = ({ /** The format of the output file */ fileFormat: OneTrustFileFormat; /** The basic assessment */ - assessment: OneTrustCombinedAssessment; - /** The details of risks found within the assessment */ - riskDetails: OneTrustGetRiskResponse[]; + assessment: OneTrustEnrichedAssessment; /** The index of the assessment being written to the file */ index: number; /** The total amount of assessments that we will write */