Skip to content

Commit

Permalink
import assessment types from privacy types
Browse files Browse the repository at this point in the history
  • Loading branch information
abrantesarthur committed Jan 13, 2025
1 parent 3ac69be commit f9be7b6
Show file tree
Hide file tree
Showing 14 changed files with 234 additions and 1,298 deletions.
10 changes: 5 additions & 5 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"@transcend-io/handlebars-utils": "^1.1.0",
"@transcend-io/internationalization": "^1.6.0",
"@transcend-io/persisted-state": "^1.0.4",
"@transcend-io/privacy-types": "^4.103.0",
"@transcend-io/privacy-types": "^4.105.0",
"@transcend-io/secret-value": "^1.2.0",
"@transcend-io/type-utils": "^1.5.0",
"bluebird": "^3.7.2",
Expand Down
15 changes: 10 additions & 5 deletions src/cli-pull-ot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import {
import { OneTrustPullResource } from './enums';
import { mapSeries, map } from 'bluebird';
import uniq from 'lodash/uniq';
import { OneTrustGetRiskResponseCodec } from './oneTrust/codecs';
import {
OneTrustAssessmentQuestion,
OneTrustAssessmentSection,
OneTrustGetRiskResponse,
} from '@transcend-io/privacy-types';

/**
* Pull configuration from OneTrust down locally to disk
Expand All @@ -28,6 +32,7 @@ async function main(): Promise<void> {
parseCliPullOtArguments();

try {
// TODO: move to helper function
if (resource === OneTrustPullResource.Assessments) {
// use the hostname and auth token to instantiate a client to talk to OneTrust
const oneTrust = createOneTrustGotInstance({ hostname, auth });
Expand All @@ -48,10 +53,10 @@ async function main(): Promise<void> {
});

// enrich assessments with risk information
let riskDetails: OneTrustGetRiskResponseCodec[] = [];
let riskDetails: OneTrustGetRiskResponse[] = [];
const riskIds = uniq(
assessmentDetails.sections.flatMap((s) =>
s.questions.flatMap((q) =>
assessmentDetails.sections.flatMap((s: OneTrustAssessmentSection) =>
s.questions.flatMap((q: OneTrustAssessmentQuestion) =>
(q.risks ?? []).flatMap((r) => r.riskId),
),
),
Expand All @@ -64,7 +69,7 @@ async function main(): Promise<void> {
);
riskDetails = await map(
riskIds,
(riskId) => getOneTrustRisk({ oneTrust, riskId }),
(riskId) => getOneTrustRisk({ oneTrust, riskId: riskId as string }),
{
concurrency: 5,
},
Expand Down
66 changes: 34 additions & 32 deletions src/helpers/enrichWithDefault.ts
Original file line number Diff line number Diff line change
@@ -1,66 +1,68 @@
import * as t from 'io-ts';
import {
OneTrustAssessmentNestedQuestionCodec,
OneTrustAssessmentQuestionOptionCodec,
OneTrustAssessmentQuestionResponseCodec,
OneTrustAssessmentQuestionResponsesCodec,
OneTrustAssessmentResponsesCodec,
OneTrustAssessmentSectionHeaderRiskStatisticsCodec,
OneTrustAssessmentSectionSubmittedByCodec,
OneTrustCombinedAssessmentCodec,
OneTrustEnrichedAssessmentSectionCodec,
OneTrustEnrichedRiskCodec,
OneTrustEnrichedRisksCodec,
OneTrustPrimaryEntityDetailsCodec,
OneTrustAssessmentNestedQuestion,
OneTrustAssessmentQuestionOption,
OneTrustAssessmentQuestionResponses,
OneTrustAssessmentResponses,
OneTrustAssessmentSectionHeaderRiskStatistics,
OneTrustAssessmentSectionSubmittedBy,
OneTrustPrimaryEntityDetails,
} from '@transcend-io/privacy-types';

import {
OneTrustCombinedAssessment,
OneTrustEnrichedAssessmentSection,
OneTrustEnrichedRisk,
OneTrustEnrichedRisks,
} from '../oneTrust/codecs';
import { createDefaultCodec } from './createDefaultCodec';

// TODO: test the shit out of this
const enrichQuestionWithDefault = ({
options,
...rest
}: OneTrustAssessmentNestedQuestionCodec): OneTrustAssessmentNestedQuestionCodec => ({
}: OneTrustAssessmentNestedQuestion): OneTrustAssessmentNestedQuestion => ({
options:
options === null || options.length === 0
? createDefaultCodec(t.array(OneTrustAssessmentQuestionOptionCodec))
? createDefaultCodec(t.array(OneTrustAssessmentQuestionOption))
: options,
...rest,
});

// TODO: test the shit out of this
const enrichQuestionResponsesWithDefault = (
questionResponses: OneTrustAssessmentQuestionResponsesCodec,
): OneTrustAssessmentQuestionResponsesCodec =>
questionResponses: OneTrustAssessmentQuestionResponses,
): OneTrustAssessmentQuestionResponses =>
questionResponses.length === 0
? createDefaultCodec(t.array(OneTrustAssessmentQuestionResponseCodec))
? createDefaultCodec(OneTrustAssessmentQuestionResponses)
: questionResponses.map((questionResponse) => ({
...questionResponse,
responses:
questionResponse.responses.length === 0
? createDefaultCodec(OneTrustAssessmentResponsesCodec)
? createDefaultCodec(OneTrustAssessmentResponses)
: questionResponse.responses,
}));

// TODO: test the shit out of this
const enrichRisksWithDefault = (
risks: OneTrustEnrichedRisksCodec,
): OneTrustEnrichedRisksCodec =>
risks: OneTrustEnrichedRisks,
): OneTrustEnrichedRisks =>
risks === null || risks.length === 0
? createDefaultCodec(t.array(OneTrustEnrichedRiskCodec))
? createDefaultCodec(t.array(OneTrustEnrichedRisk))
: risks;

// TODO: test the shit out of this
const enrichRiskStatisticsWithDefault = (
riskStatistics: OneTrustAssessmentSectionHeaderRiskStatisticsCodec,
): OneTrustAssessmentSectionHeaderRiskStatisticsCodec =>
riskStatistics: OneTrustAssessmentSectionHeaderRiskStatistics,
): OneTrustAssessmentSectionHeaderRiskStatistics =>
riskStatistics === null
? createDefaultCodec(OneTrustAssessmentSectionHeaderRiskStatisticsCodec)
? createDefaultCodec(OneTrustAssessmentSectionHeaderRiskStatistics)
: riskStatistics;

// TODO: test the shit out of this
const enrichSectionsWithDefault = (
sections: OneTrustEnrichedAssessmentSectionCodec[],
): OneTrustEnrichedAssessmentSectionCodec[] =>
sections: OneTrustEnrichedAssessmentSection[],
): OneTrustEnrichedAssessmentSection[] =>
sections.map((s) => ({
...s,
header: {
Expand All @@ -77,20 +79,20 @@ const enrichSectionsWithDefault = (
})),
submittedBy:
s.submittedBy === null
? createDefaultCodec(OneTrustAssessmentSectionSubmittedByCodec)
? createDefaultCodec(OneTrustAssessmentSectionSubmittedBy)
: s.submittedBy,
}));

const enrichPrimaryEntityDetailsWithDefault = (
primaryEntityDetails: OneTrustPrimaryEntityDetailsCodec,
): OneTrustPrimaryEntityDetailsCodec =>
primaryEntityDetails: OneTrustPrimaryEntityDetails,
): OneTrustPrimaryEntityDetails =>
primaryEntityDetails.length === 0
? createDefaultCodec(OneTrustPrimaryEntityDetailsCodec)
? createDefaultCodec(OneTrustPrimaryEntityDetails)
: primaryEntityDetails;

export const enrichCombinedAssessmentWithDefaults = (
combinedAssessment: OneTrustCombinedAssessmentCodec,
): OneTrustCombinedAssessmentCodec => ({
combinedAssessment: OneTrustCombinedAssessment,
): OneTrustCombinedAssessment => ({
...combinedAssessment,
primaryEntityDetails: enrichPrimaryEntityDetailsWithDefault(
combinedAssessment.primaryEntityDetails,
Expand Down
5 changes: 5 additions & 0 deletions src/helpers/tests/createDefaultCodec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import chai, { expect } from 'chai';
import deepEqualInAnyOrder from 'deep-equal-in-any-order';

import { createDefaultCodec } from '../createDefaultCodec';
import {
OneTrustCombinedAssessment,
OneTrustCombinedAssessmentCodec,
} from '../../oneTrust/codecs';
import { flattenOneTrustAssessment } from '../../oneTrust/flattenOneTrustAssessment';

chai.use(deepEqualInAnyOrder);

Expand Down
Loading

0 comments on commit f9be7b6

Please sign in to comment.