Skip to content

Commit

Permalink
create more codecs
Browse files Browse the repository at this point in the history
  • Loading branch information
abrantesarthur committed Jan 12, 2025
1 parent 930a1ba commit 6538e41
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 20 deletions.
13 changes: 7 additions & 6 deletions src/helpers/enrichWithDefault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
40 changes: 40 additions & 0 deletions src/oneTrust/codecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
25 changes: 11 additions & 14 deletions src/oneTrust/flattenOneTrustAssessment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import {
OneTrustAssessmentQuestionResponseCodec,
OneTrustAssessmentSectionCodec,
OneTrustAssessmentSectionHeaderCodec,
OneTrustEnrichedRiskCodec,
OneTrustGetAssessmentResponseCodec,
OneTrustEnrichedAssessmentResponseCodec,
} from './codecs';

// TODO: will have to use something like csv-stringify
Expand Down Expand Up @@ -111,7 +110,6 @@ const flattenOneTrustQuestionResponses = (
['responses'],
);

// TODO: do we handle it right when empty?
const responsesFlat = (responses ?? []).map((r) =>
flattenObject(r, prefix),
);
Expand All @@ -138,6 +136,7 @@ const flattenOneTrustQuestions = (
rest: restSectionQuestions,
question: questions,
questionResponses: allQuestionResponses,
// TODO; continue from here
// risks: allRisks,
} = extractProperties(sectionQuestions, [
'question',
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 6538e41

Please sign in to comment.