Skip to content

Commit

Permalink
graphql logic implemented, need to update pull config to build proper…
Browse files Browse the repository at this point in the history
… yml
  • Loading branch information
blevine-transcend committed Jan 16, 2025
1 parent a4f6771 commit 1fbb140
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/codecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1749,7 +1749,7 @@ export type AssessmentInput = t.TypeOf<typeof AssessmentInput>;
*
* @see https://docs.transcend.io/docs/silo-discovery
*/
export const SiloDiscoveryRecommendation = t.intersection([
export const SiloDiscoveryRecommendationInput = t.intersection([
t.type({
/** The ID of the plugin that found this recommendation */
pluginId: t.string,
Expand Down Expand Up @@ -1789,8 +1789,8 @@ export const SiloDiscoveryRecommendation = t.intersection([
]);

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

export const TranscendInput = t.partial({
Expand Down Expand Up @@ -1913,7 +1913,7 @@ export const TranscendInput = t.partial({
/**
* The full list of silo discovery recommendations
*/
siloDiscoveryRecommendations: t.array(SiloDiscoveryRecommendation),
siloDiscoveryRecommendations: t.array(SiloDiscoveryRecommendationInput),
});

/** Type override */
Expand Down
54 changes: 47 additions & 7 deletions src/graphql/fetchAllSiloDiscoveryRecommendations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface SiloDiscoveryRecommendation {
};
}

const PAGE_SIZE = 20;
const PAGE_SIZE = 30;

/**
* Fetch all silo discovery recommendations in the organization
Expand All @@ -28,28 +28,68 @@ export async function fetchAllSiloDiscoveryRecommendations(
client: GraphQLClient,
): Promise<SiloDiscoveryRecommendation[]> {
const siloDiscoveryRecommendations: SiloDiscoveryRecommendation[] = [];
let lastKey;
let lastKey = null;

// Whether to continue looping
let shouldContinue = false;
do {
/**
* Input for the GraphQL request
*/
const input: {
/** whether to list pending or ignored recommendations */
isPending: boolean;
/** key for previous page */
lastKey?: {
/** ID of plugin that found recommendation */
pluginId: string;
/** unique identifier for the resource */
resourceId: string;
/** ID of organization resource belongs to */
organizationId: string;
/** Status of recommendation, concatenated with latest run time */
statusLatestRunTime: string;
} | null;
} = lastKey
? {
isPending: true,
lastKey,
}
: {
isPending: true,
};

const {
siloDiscoveryRecommendations: { nodes },
siloDiscoveryRecommendations: { nodes, lastKey: newLastKey },
// eslint-disable-next-line no-await-in-loop
} = await makeGraphQLRequest<{
/** Silo Discovery Recommendations */
siloDiscoveryRecommendations: {
/** List */
nodes: SiloDiscoveryRecommendation[];
/**
* Last key for pagination
*/
lastKey: {
/** ID of plugin that found recommendation */
pluginId: string;
/** unique identifier for the resource */
resourceId: string;
/** ID of organization resource belongs to */
organizationId: string;
/** Status of recommendation, concatenated with latest run time */
statusLatestRunTime: string;
} | null;
};
}>(client, SILO_DISCOVERY_RECOMMENDATIONS, {
first: PAGE_SIZE,
input: ,
filterBy:
input,
filterBy: {},
});

siloDiscoveryRecommendations.push(...nodes);
lastKey = PAGE_SIZE;
shouldContinue = nodes.length === PAGE_SIZE;
lastKey = newLastKey;
shouldContinue = nodes.length === PAGE_SIZE && lastKey !== null;
} while (shouldContinue);

return siloDiscoveryRecommendations.sort((a, b) =>
Expand Down
33 changes: 33 additions & 0 deletions src/graphql/pullTranscendConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
AssessmentSectionInput,
AssessmentSectionQuestionInput,
RiskLogicInput,
SiloDiscoveryRecommendationInput,
} from '../codecs';
import {
RequestAction,
Expand Down Expand Up @@ -89,6 +90,7 @@ import {
parseAssessmentDisplayLogic,
} from './parseAssessmentDisplayLogic';
import { parseAssessmentRiskLogic } from './parseAssessmentRiskLogic';
import { fetchAllSiloDiscoveryRecommendations } from './fetchAllSiloDiscoveryRecommendations';

export const DEFAULT_TRANSCEND_PULL_RESOURCES = [
TranscendPullResource.DataSilos,
Expand Down Expand Up @@ -180,6 +182,7 @@ export async function pullTranscendConfiguration(
partitions,
assessments,
assessmentTemplates,
siloDiscoveryRecommendations,
] = await Promise.all([
// Grab all data subjects in the organization
resources.includes(TranscendPullResource.DataSilos) ||
Expand Down Expand Up @@ -328,6 +331,10 @@ export async function pullTranscendConfiguration(
resources.includes(TranscendPullResource.AssessmentTemplates)
? fetchAllAssessmentTemplates(client)
: [],
// Fetch siloDiscoveryRecommendations
resources.includes(TranscendPullResource.SiloDiscoveryRecommendations)
? fetchAllSiloDiscoveryRecommendations(client)
: [],
]);

const consentManagerTheme =
Expand Down Expand Up @@ -762,6 +769,32 @@ export async function pullTranscendConfiguration(
);
}

// Save siloDiscoveryRecommendations
if (
siloDiscoveryRecommendations.length > 0 &&
resources.includes(TranscendPullResource.SiloDiscoveryRecommendations)
) {
result.siloDiscoveryRecommendations = siloDiscoveryRecommendations.map(
({
title,
description,
status,
pluginId,
resourceId,
organizationId,
statusLatestRunTime,
}): SiloDiscoveryRecommendationInput => ({
title,
description,
status,
pluginId,
resourceId,
organizationId,
statusLatestRunTime,
}),
);
}

// Save prompts
if (prompts.length > 0 && resources.includes(TranscendPullResource.Prompts)) {
result.prompts = prompts.map(
Expand Down

0 comments on commit 1fbb140

Please sign in to comment.