Skip to content

Commit

Permalink
update flattenOneTrustAssessment type
Browse files Browse the repository at this point in the history
  • Loading branch information
abrantesarthur committed Jan 12, 2025
1 parent e104337 commit ee8b072
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
12 changes: 12 additions & 0 deletions src/oneTrust/codecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1075,4 +1075,16 @@ export type OneTrustEnrichedAssessmentResponseCodec = t.TypeOf<
typeof OneTrustEnrichedAssessmentResponseCodec
>;

// TODO: do not add to privacy-types
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { status, ...OneTrustAssessmentCodecWithoutStatus } =
OneTrustAssessmentCodec.props;
export const CombinedAssessmentCodec = t.intersection([
t.type(OneTrustAssessmentCodecWithoutStatus),
OneTrustEnrichedAssessmentResponseCodec,
]);

/** Type override */
export type CombinedAssessmentCodec = t.TypeOf<typeof CombinedAssessmentCodec>;

/* eslint-enable max-lines */
24 changes: 7 additions & 17 deletions src/oneTrust/flattenOneTrustAssessment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import {
extractProperties,
} from '../helpers';
import {
OneTrustAssessmentCodec,
CombinedAssessmentCodec,
OneTrustAssessmentNestedQuestionCodec,
OneTrustAssessmentQuestionOptionCodec,
OneTrustAssessmentQuestionResponseCodec,
OneTrustAssessmentSectionHeaderCodec,
OneTrustEnrichedAssessmentQuestionCodec,
OneTrustEnrichedAssessmentResponseCodec,
OneTrustEnrichedAssessmentSectionCodec,
OneTrustEnrichedRiskCodec,
OneTrustRiskCategories,
Expand Down Expand Up @@ -237,15 +236,9 @@ const flattenOneTrustSections = (
return { ...sectionsFlat, ...headersFlat, ...questionsFlat };
};

export const flattenOneTrustAssessment = ({
assessment,
assessmentDetails,
}: {
/** the assessment */
assessment: OneTrustAssessmentCodec;
/** the assessment with details and enriched with risk */
assessmentDetails: OneTrustEnrichedAssessmentResponseCodec;
}): any => {
export const flattenOneTrustAssessment = (
combinedAssessment: CombinedAssessmentCodec,
): any => {
/**
* TODO: experiment creating a default assessment with
* const result = createDefaultCodec(OneTrustGetAssessmentResponseCodec);
Expand All @@ -255,15 +248,14 @@ export const flattenOneTrustAssessment = ({

// add default values to assessments
const transformedAssessmentDetails = {
...assessmentDetails,
...combinedAssessment,
primaryEntityDetails: enrichPrimaryEntityDetailsWithDefault(
assessmentDetails.primaryEntityDetails,
combinedAssessment.primaryEntityDetails,
),
sections: enrichSectionsWithDefault(assessmentDetails.sections),
sections: enrichSectionsWithDefault(combinedAssessment.sections),
};

const {
// TODO: handle these
approvers,
primaryEntityDetails,
respondents,
Expand All @@ -273,7 +265,6 @@ export const flattenOneTrustAssessment = ({
...rest
} = transformedAssessmentDetails;

// console.log({ approvers: flattenApprovers(approvers) });
const flatApprovers = approvers.map((approver) =>
flattenObject(approver, 'approvers'),
);
Expand All @@ -286,7 +277,6 @@ export const flattenOneTrustAssessment = ({
);

return {
...flattenObject(assessment),
...flattenObject(rest),
...aggregateObjects({ objs: flatApprovers }),
...aggregateObjects({ objs: flatRespondents }),
Expand Down
4 changes: 2 additions & 2 deletions src/oneTrust/writeOneTrustAssessment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ export const writeOneTrustAssessment = ({
}

const flattened = flattenOneTrustAssessment({
assessment,
assessmentDetails: enrichedAssessment,
...assessment,
...enrichedAssessment,
});
const stringifiedFlattened = JSON.stringify(flattened, null, 2);
// TODO: do not forget to ensure we have the same set of keys!!!
Expand Down

0 comments on commit ee8b072

Please sign in to comment.