diff --git a/src/helpers/enrichWithDefault.ts b/src/helpers/enrichWithDefault.ts index 578b5602..2d1596c8 100644 --- a/src/helpers/enrichWithDefault.ts +++ b/src/helpers/enrichWithDefault.ts @@ -4,12 +4,13 @@ import { OneTrustAssessmentQuestionOptionCodec, OneTrustAssessmentQuestionResponseCodec, OneTrustAssessmentQuestionResponsesCodec, - OneTrustAssessmentQuestionRiskCodec, - OneTrustAssessmentQuestionRisksCodec, OneTrustAssessmentResponsesCodec, OneTrustAssessmentSectionCodec, OneTrustAssessmentSectionHeaderRiskStatisticsCodec, OneTrustAssessmentSectionSubmittedByCodec, + OneTrustEnrichedAssessmentSectionCodec, + OneTrustEnrichedRiskCodec, + OneTrustEnrichedRisksCodec, OneTrustPrimaryEntityDetailsCodec, } from '../oneTrust/codecs'; import { createDefaultCodec } from './createDefaultCodec'; @@ -42,10 +43,10 @@ const enrichQuestionResponsesWithDefault = ( // TODO: test the shit out of this const enrichRisksWithDefault = ( - risks: OneTrustAssessmentQuestionRisksCodec, -): OneTrustAssessmentQuestionRisksCodec => + risks: OneTrustEnrichedRisksCodec, +): OneTrustEnrichedRisksCodec => risks === null || risks.length === 0 - ? createDefaultCodec(t.array(OneTrustAssessmentQuestionRiskCodec)) + ? createDefaultCodec(t.array(OneTrustEnrichedRiskCodec)) : risks; // TODO: test the shit out of this @@ -58,7 +59,7 @@ const enrichRiskStatisticsWithDefault = ( // TODO: test the shit out of this export const enrichSectionsWithDefault = ( - sections: OneTrustAssessmentSectionCodec[], + sections: OneTrustEnrichedAssessmentSectionCodec[], ): OneTrustAssessmentSectionCodec[] => sections.map((s) => ({ ...s, diff --git a/src/oneTrust/codecs.ts b/src/oneTrust/codecs.ts index f331a3f4..a7dc1661 100644 --- a/src/oneTrust/codecs.ts +++ b/src/oneTrust/codecs.ts @@ -1031,4 +1031,44 @@ export type OneTrustEnrichedRiskCodec = t.TypeOf< typeof OneTrustEnrichedRiskCodec >; +// TODO: do not move to privacy-types +export const OneTrustEnrichedRisksCodec = t.union([ + t.array(OneTrustEnrichedRiskCodec), + t.null, +]); +/** Type override */ +export type OneTrustEnrichedRisksCodec = t.TypeOf< + typeof OneTrustEnrichedRisksCodec +>; + +// TODO: do not add to privacy-types +export const OneTrustEnrichedAssessmentQuestionCodec = t.type({ + ...OneTrustAssessmentQuestionCodec.props, + risks: t.union([t.array(OneTrustEnrichedRiskCodec), t.null]), +}); +/** Type override */ +export type OneTrustEnrichedAssessmentQuestionCodec = t.TypeOf< + typeof OneTrustEnrichedAssessmentQuestionCodec +>; + +// TODO: do not add to privacy-types +export const OneTrustEnrichedAssessmentSectionCodec = t.type({ + ...OneTrustAssessmentSectionCodec.props, + questions: t.array(OneTrustEnrichedAssessmentQuestionCodec), +}); +/** Type override */ +export type OneTrustEnrichedAssessmentSectionCodec = t.TypeOf< + typeof OneTrustEnrichedAssessmentSectionCodec +>; + +// TODO: do not add to privacy-types +export const OneTrustEnrichedAssessmentResponseCodec = t.type({ + ...OneTrustGetAssessmentResponseCodec.props, + sections: t.array(OneTrustEnrichedAssessmentSectionCodec), +}); +/** Type override */ +export type OneTrustEnrichedAssessmentResponseCodec = t.TypeOf< + typeof OneTrustEnrichedAssessmentResponseCodec +>; + /* eslint-enable max-lines */ diff --git a/src/oneTrust/flattenOneTrustAssessment.ts b/src/oneTrust/flattenOneTrustAssessment.ts index d0050ec5..c128a9f8 100644 --- a/src/oneTrust/flattenOneTrustAssessment.ts +++ b/src/oneTrust/flattenOneTrustAssessment.ts @@ -13,8 +13,7 @@ import { OneTrustAssessmentQuestionResponseCodec, OneTrustAssessmentSectionCodec, OneTrustAssessmentSectionHeaderCodec, - OneTrustEnrichedRiskCodec, - OneTrustGetAssessmentResponseCodec, + OneTrustEnrichedAssessmentResponseCodec, } from './codecs'; // TODO: will have to use something like csv-stringify @@ -111,7 +110,6 @@ const flattenOneTrustQuestionResponses = ( ['responses'], ); - // TODO: do we handle it right when empty? const responsesFlat = (responses ?? []).map((r) => flattenObject(r, prefix), ); @@ -138,6 +136,7 @@ const flattenOneTrustQuestions = ( rest: restSectionQuestions, question: questions, questionResponses: allQuestionResponses, + // TODO; continue from here // risks: allRisks, } = extractProperties(sectionQuestions, [ 'question', @@ -211,18 +210,16 @@ export const flattenOneTrustAssessment = ({ }: { /** the assessment */ assessment: OneTrustAssessmentCodec; - /** the assessment with details */ - assessmentDetails: OneTrustGetAssessmentResponseCodec & { - /** the sections enriched with risk details */ - sections: (OneTrustAssessmentSectionCodec & { - /** the questions enriched with risk details */ - questions: (OneTrustAssessmentQuestionCodec & { - /** the enriched risk details */ - risks: OneTrustEnrichedRiskCodec[] | null; - })[]; - })[]; - }; + /** the assessment with details and enriched with risk */ + assessmentDetails: OneTrustEnrichedAssessmentResponseCodec; }): any => { + /** + * TODO: experiment creating a default assessment with + * const result = createDefaultCodec(OneTrustGetAssessmentResponseCodec); + * Then, flatten it and aggregate it with the actual assessment. This way, every + * assessment will always have the same fields! + */ + // add default values to assessments const transformedAssessmentDetails = { ...assessmentDetails,