Skip to content

Commit

Permalink
Adds assessment export to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfarrell76 committed Nov 26, 2024
1 parent 4eafcf0 commit 1bdd2e3
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 5 deletions.
104 changes: 104 additions & 0 deletions src/codecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import {
PrivacyCenterComponentStyles,
PrivacyCenterTextStyles,
ConfigurableColorPaletteColor,
AssessmentFormTemplateStatus,
AssessmentFormStatus,
} from '@transcend-io/privacy-types';
import {
InitialViewState,
Expand Down Expand Up @@ -1442,6 +1444,100 @@ export const ActionItemInput = t.intersection([
/** Type override */
export type ActionItemInput = t.TypeOf<typeof ActionItemInput>;

export const AssessmentTemplateInput = t.intersection([
t.type({
/** The title of the assessment template */
title: t.string,
}),
t.partial({
/** The Assessment sections under this assessment template */
sections: t.array(AssessmentSectionInput),
/** Description of assessment template */
description: t.string,
/** The status of the assessment */
status: valuesOf(AssessmentFormTemplateStatus),
/** The source of the assessment */
source: valuesOf(AssessmentFormTemplateSource),
/** The email of the user that created the assessment */
creator: t.string,
/** Whether the template is in a locked status */
locked: t.boolean,
/** Whether the template is archived */
archived: t.boolean,
/** The date that the assessment was created */
'created-at': t.string,
/** The names of the custom fields associated to this assessment template */
'attribute-keys': t.array(t.string),
/** The retention schedule configuration */
'retention-schedule': AssessmentRetentionScheduleInput,
/** The titles of the email templates used in the assessment template */
templates: t.array(t.string),
}),
]);

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

export const AssessmentInput = t.intersection([
t.type({
/** The title of the assessment */
title: t.string,
/** The title of the assessment group */
group: t.string, // FIXME unique?
}),
t.partial({
/** The assessment sections */
sections: t.array(AssessmentSectionInput),
/** The email of the user that created the assessment */
creator: t.string,
/** The title of the assessment template used for this assessment */
'assessment-template': t.string,
/** The description of the assessment */
description: t.string,
/** The status of the assessment */
status: valuesOf(AssessmentFormStatus),
/** The emails of the transcend users assigned to the assessment */
assignees: t.array(t.string),
/** The emails of the external emails assigned to the assessment */
'external-assignees': t.array(t.string),
/** The emails of the assessment reviewers */
reviewers: t.array(t.string),
/** Whether the assessment is in a locked status */
locked: t.boolean,
/** Whether the assessment is archived */
archived: t.boolean,
/** Whether the form is created by an external user */
external: t.boolean,
/**
* Whether the form title is an internal label only, and the group title should be used in communications with assignees
*/
'title-is-internal': t.boolean,
/** The date that the assessment is due */
'due-date': t.string,
/** The date that the assessment was created */
'created-at': t.string,
/** The date that the assessment was assigned at */
'assigned-at': t.string,
/** The date that the assessment was submitted at */
'submitted-at': t.string,
/** The date that the assessment was approved at */
'approved-at': t.string,
/** The date that the assessment was rejected at */
'rejected-at': t.string,
/** The linked data inventory resources */
resources: t.array(AssessmentResourceInput),
/** The linked data inventory synced rows */
rows: t.array(AssessmentRowInput),
/** The assessment retention schedule */
'retention-schedule': AssessmentRetentionScheduleInput,
/** The assessment custom fields */
attributes: t.array(AttributePreview),
}),
]);

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

export const TranscendInput = t.partial({
/**
* Action items
Expand Down Expand Up @@ -1551,6 +1647,14 @@ export const TranscendInput = t.partial({
messages: t.array(IntlMessageInput),
/** The full list of consent manager partitions (e.g. dev vs staging vs prod) */
partitions: t.array(PartitionInput),
/**
* The full list of assessment templates
*/
'assessment-templates': t.array(AssessmentTemplateInput),
/**
* The full list of assessment results
*/
assessments: t.array(AssessmentInput),
});

/** Type override */
Expand Down
6 changes: 6 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export const TR_PUSH_RESOURCE_SCOPE_MAP: {
[TranscendPullResource.Messages]: [ScopeName.ManageIntlMessages],
[TranscendPullResource.PrivacyCenters]: [ScopeName.ManagePrivacyCenter],
[TranscendPullResource.Policies]: [ScopeName.ManagePolicies],
[TranscendPullResource.Assessments]: [ScopeName.ManageAssessments],
[TranscendPullResource.AssessmentTemplates]: [ScopeName.ManageAssessments],
};

/**
Expand Down Expand Up @@ -110,6 +112,8 @@ export const TR_PULL_RESOURCE_SCOPE_MAP: {
[TranscendPullResource.Messages]: [ScopeName.ViewIntlMessages],
[TranscendPullResource.PrivacyCenters]: [ScopeName.ViewPrivacyCenter],
[TranscendPullResource.Policies]: [ScopeName.ViewPolicies],
[TranscendPullResource.Assessments]: [ScopeName.ViewAssessments],
[TranscendPullResource.AssessmentTemplates]: [ScopeName.ViewAssessments],
};

export const TR_YML_RESOURCE_TO_FIELD_NAME: Record<
Expand Down Expand Up @@ -144,4 +148,6 @@ export const TR_YML_RESOURCE_TO_FIELD_NAME: Record<
[TranscendPullResource.Messages]: 'messages',
[TranscendPullResource.PrivacyCenters]: 'privacy-center',
[TranscendPullResource.Policies]: 'policies',
[TranscendPullResource.Assessments]: 'assessments',
[TranscendPullResource.AssessmentTemplates]: 'assessment-templates',
};
2 changes: 2 additions & 0 deletions src/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export enum TranscendPullResource {
PrivacyCenters = 'privacyCenters',
Policies = 'policies',
Messages = 'messages',
Assessments = 'assessments',
AssessmentTemplates = 'assessmentTemplates',
}

/**
Expand Down
19 changes: 14 additions & 5 deletions src/requests/approvePrivacyRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export async function approvePrivacyRequests({
logger.info(colors.magenta(`Approving "${allRequests.length}" requests.`));

let total = 0;
let skipped = 0;
progressBar.start(allRequests.length, 0);
await map(
allRequests,
Expand All @@ -91,10 +92,16 @@ export async function approvePrivacyRequests({
});
}

// approve the request
await makeGraphQLRequest(client, APPROVE_PRIVACY_REQUEST, {
input: { requestId: requestToApprove.id },
});
try {
// approve the request
await makeGraphQLRequest(client, APPROVE_PRIVACY_REQUEST, {
input: { requestId: requestToApprove.id },
});
} catch (err) {
if (err.message.includes('Request must be in an approving state,')) {
skipped += 1;
}
}

total += 1;
progressBar.update(total);
Expand All @@ -105,7 +112,9 @@ export async function approvePrivacyRequests({
progressBar.stop();
const t1 = new Date().getTime();
const totalTime = t1 - t0;

if (skipped > 0) {
logger.info(colors.yellow(`${skipped} requests were skipped.`));
}
logger.info(
colors.green(
`Successfully approved ${total} requests in "${
Expand Down

0 comments on commit 1bdd2e3

Please sign in to comment.