Skip to content

Commit

Permalink
ship more improvements to writeOneTrustAssessment
Browse files Browse the repository at this point in the history
  • Loading branch information
abrantesarthur committed Jan 14, 2025
1 parent 239a72d commit ae5522f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
15 changes: 9 additions & 6 deletions src/cli-sync-ot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ async function main(): Promise<void> {
// 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 ${
Expand Down Expand Up @@ -78,10 +81,11 @@ async function main(): Promise<void> {
);
}

// 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;
Expand Down Expand Up @@ -113,17 +117,16 @@ async function main(): Promise<void> {
});

// 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,
Expand Down
6 changes: 3 additions & 3 deletions src/oneTrust/codecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
>;
8 changes: 4 additions & 4 deletions src/oneTrust/constants.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/oneTrust/flattenOneTrustAssessment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@transcend-io/privacy-types';
import { extractProperties } from '../helpers';
import {
OneTrustCombinedAssessment,
OneTrustEnrichedAssessment,
OneTrustEnrichedAssessmentQuestion,
OneTrustEnrichedAssessmentSection,
OneTrustEnrichedRisk,
Expand Down Expand Up @@ -238,7 +238,7 @@ const flattenOneTrustSections = (

// TODO: update type to be a Record<OneTrustAssessmentCsvHeader, string>
export const flattenOneTrustAssessment = (
combinedAssessment: OneTrustCombinedAssessment,
combinedAssessment: OneTrustEnrichedAssessment,
): Record<string, string> => {
const {
approvers,
Expand Down
11 changes: 3 additions & 8 deletions src/oneTrust/writeOneTrustAssessment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 */
Expand Down

0 comments on commit ae5522f

Please sign in to comment.