Skip to content

Commit

Permalink
fix bugs and import codecs from privacy-types
Browse files Browse the repository at this point in the history
  • Loading branch information
abrantesarthur committed Jan 22, 2025
1 parent 0c7030f commit b60400d
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/oneTrust/helpers/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createDefaultCodec } from '@transcend-io/type-utils';
import { OneTrustEnrichedAssessment } from '../codecs';
import { flattenOneTrustAssessment } from './flattenOneTrustAssessment';
import { OneTrustEnrichedAssessment } from '@transcend-io/privacy-types';

/**
* An object with default values of type OneTrustEnrichedAssessment. It's very
Expand Down
18 changes: 5 additions & 13 deletions src/oneTrust/helpers/enrichOneTrustAssessment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,7 @@ export const enrichOneTrustAssessment = ({
const details = riskDetailsById[risk.riskId];
return {
...risk,
description: details.description,
name: details.name,
treatment: details.treatment,
treatmentStatus: details.treatmentStatus,
type: details.type,
state: details.state,
stage: details.stage,
result: details.result,
categories: details.categories,
...details,
};
});
return {
Expand Down Expand Up @@ -98,17 +90,17 @@ export const enrichOneTrustAssessment = ({

// grab respondents details
const respondentsDetailsById = keyBy(respondentsDetails, 'id');
const enrichedRespondents = assessmentDetails.respondents.map(
(respondent) => ({
const enrichedRespondents = assessmentDetails.respondents
.filter((r) => !r.name.includes('@')) // search only internal respondents
.map((respondent) => ({
...respondent,
active: respondentsDetailsById[respondent.id].active,
userType: respondentsDetailsById[respondent.id].userType,
emails: respondentsDetailsById[respondent.id].emails,
title: respondentsDetailsById[respondent.id].title,
givenName: respondentsDetailsById[respondent.id].name.givenName ?? null,
familyName: respondentsDetailsById[respondent.id].name.familyName ?? null,
}),
);
}));

// combine everything into a single enriched assessment
return {
Expand Down
7 changes: 3 additions & 4 deletions src/oneTrust/helpers/flattenOneTrustAssessment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import {
OneTrustAssessmentResponses,
OneTrustAssessmentSectionHeader,
OneTrustAssessmentSectionHeaderRiskStatistics,
OneTrustRiskCategories,
} from '@transcend-io/privacy-types';
import {
OneTrustEnrichedAssessment,
OneTrustEnrichedAssessmentQuestion,
OneTrustEnrichedAssessmentSection,
OneTrustEnrichedRisk,
} from '../codecs';
OneTrustRiskCategories,
} from '@transcend-io/privacy-types';

import {
flattenObject,
aggregateObjects,
Expand Down
2 changes: 1 addition & 1 deletion src/oneTrust/helpers/oneTrustAssessmentToCsv.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OneTrustEnrichedAssessment } from '../codecs';
import { OneTrustEnrichedAssessment } from '@transcend-io/privacy-types';
import { oneTrustAssessmentToCsvRecord } from './oneTrustAssessmentToCsvRecord';

/**
Expand Down
6 changes: 4 additions & 2 deletions src/oneTrust/helpers/oneTrustAssessmentToCsvRecord.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { decodeCodec } from '@transcend-io/type-utils';
import { OneTrustEnrichedAssessment } from '../codecs';
import { DEFAULT_ONE_TRUST_ASSESSMENT_CSV_HEADER } from './constants';
import { flattenOneTrustAssessment } from './flattenOneTrustAssessment';
import { OneTrustAssessmentCsvRecord } from '@transcend-io/privacy-types';
import {
OneTrustAssessmentCsvRecord,
OneTrustEnrichedAssessment,
} from '@transcend-io/privacy-types';

/**
* Converts the assessment into a csv record (i.e. a map from the csv header
Expand Down
2 changes: 1 addition & 1 deletion src/oneTrust/helpers/oneTrustAssessmentToJson.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OneTrustEnrichedAssessment } from '../codecs';
import { OneTrustEnrichedAssessment } from '@transcend-io/privacy-types';

/**
* Converts the assessment into a json entry.
Expand Down
2 changes: 1 addition & 1 deletion src/oneTrust/helpers/syncOneTrustAssessmentToDisk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { logger } from '../../logger';
import colors from 'colors';
import { OneTrustFileFormat } from '../../enums';
import fs from 'fs';
import { OneTrustEnrichedAssessment } from '../codecs';
import { oneTrustAssessmentToJson } from './oneTrustAssessmentToJson';
import { oneTrustAssessmentToCsv } from './oneTrustAssessmentToCsv';
import { OneTrustEnrichedAssessment } from '@transcend-io/privacy-types';

/**
* Write the assessment to disk at the specified file path.
Expand Down
2 changes: 1 addition & 1 deletion src/oneTrust/helpers/syncOneTrustAssessmentToTranscend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
makeGraphQLRequest,
} from '../../graphql';
import { ImportOnetrustAssessmentsInput } from '../../codecs';
import { OneTrustEnrichedAssessment } from '../codecs';
import { OneTrustEnrichedAssessment } from '@transcend-io/privacy-types';

export interface AssessmentForm {
/** ID of Assessment Form */
Expand Down
24 changes: 9 additions & 15 deletions src/oneTrust/helpers/syncOneTrustAssessments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ export const syncOneTrustAssessments = async ({
*/
await mapSeries(assessments, async (assessment, index) => {
logger.info(
`Fetching details about assessment ${index + 1} of ${
assessments.length
}...`,
`[assessment ${index + 1} of ${assessments.length}]: fetching details...`,
);
const assessmentDetails = await getOneTrustAssessment({
oneTrust,
Expand All @@ -72,9 +70,9 @@ export const syncOneTrustAssessments = async ({
let creator = oneTrustCachedUsers[creatorId];
if (!creator) {
logger.info(
`Fetching details about assessment ${index + 1} of ${
`[assessment ${index + 1} of ${
assessments.length
} creator...`,
}]: fetching creator...`,
);
creator = await getOneTrustUser({
oneTrust,
Expand All @@ -88,9 +86,9 @@ export const syncOneTrustAssessments = async ({
let approversDetails: OneTrustGetUserResponse[] = [];
if (approvers.length > 0) {
logger.info(
`Fetching details about ${approvers.length} approvers for assessment ${
index + 1
} of ${assessments.length}...`,
`[assessment ${index + 1} of ${
assessments.length
}]: fetching approvers...`,
);
approversDetails = await map(
approvers.map(({ id }) => id),
Expand All @@ -115,11 +113,9 @@ export const syncOneTrustAssessments = async ({
let respondentsDetails: OneTrustGetUserResponse[] = [];
if (internalRespondents.length > 0) {
logger.info(
`Fetching details about ${
internalRespondents.length
} internal responds for assessment ${index + 1} of ${
`[assessment ${index + 1} of ${
assessments.length
}...`,
}]: fetching respondents...`,
);
respondentsDetails = await map(
internalRespondents.map(({ id }) => id),
Expand All @@ -146,9 +142,7 @@ export const syncOneTrustAssessments = async ({
);
if (riskIds.length > 0) {
logger.info(
`Fetching details about ${riskIds.length} risks for assessment ${
index + 1
} of ${assessments.length}...`,
`[assessment ${index + 1} of ${assessments.length}]: fetching risks...`,
);
riskDetails = await map(
riskIds,
Expand Down

0 comments on commit b60400d

Please sign in to comment.