Skip to content

Commit

Permalink
tsc
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfarrell76 committed Nov 29, 2024
1 parent 9bed09f commit f5e8462
Show file tree
Hide file tree
Showing 21 changed files with 691 additions and 269 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2326,7 +2326,7 @@ The API key needs the following scopes:

- Modify User Stored Preferences
- View Managed Consent Database Admin API
- View Global Attributes
- View Preference Store Settings

#### Authentication

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,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.96.0",
"@transcend-io/privacy-types": "^4.98.0",
"@transcend-io/secret-value": "^1.2.0",
"@transcend-io/type-utils": "^1.5.0",
"bluebird": "^3.7.2",
Expand Down
65 changes: 65 additions & 0 deletions src/graphql/fetchAllPreferenceTopics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { GraphQLClient } from 'graphql-request';
import { PREFERENCE_TOPICS } from './gqls';
import { makeGraphQLRequest } from './makeGraphQLRequest';
import { PreferenceTopicType } from '@transcend-io/privacy-types';

export interface PreferenceTopic {
/** ID of preference topic */
id: string;
/** Slug of preference topic */
slug: string;
/** Type of preference topic */
type: PreferenceTopicType;
/** Option values */
preferenceOptionValues: {
/** Slug of value */
slug: string;
}[];
/** Related purpose */
purpose: {
/** Slug */
trackingType: string;
};
}

const PAGE_SIZE = 20;

/**
* Fetch all preference topics in the organization
*
* @param client - GraphQL client
* @returns All preference topics in the organization
*/
export async function fetchAllPreferenceTopics(
client: GraphQLClient,
): Promise<PreferenceTopic[]> {
const preferenceTopics: PreferenceTopic[] = [];
let offset = 0;

// Whether to continue looping
let shouldContinue = false;
do {
const {
preferenceTopics: { nodes },
// eslint-disable-next-line no-await-in-loop
} = await makeGraphQLRequest<{
/** Preference topics */
preferenceTopics: {
/** List */
nodes: PreferenceTopic[];
};
}>(client, PREFERENCE_TOPICS, {
first: PAGE_SIZE,
offset,
});
preferenceTopics.push(...nodes);
offset += PAGE_SIZE;
shouldContinue = nodes.length === PAGE_SIZE;
} while (shouldContinue);

return preferenceTopics.sort((a, b) =>
`${a.slug}:${a.purpose.trackingType}`.localeCompare(
`${b.slug}:${b.purpose.trackingType}`,
),
);
}
64 changes: 64 additions & 0 deletions src/graphql/fetchAllPurposes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { GraphQLClient } from 'graphql-request';
import { PURPOSES } from './gqls';
import { makeGraphQLRequest } from './makeGraphQLRequest';

export interface Purpose {
/** ID of purpose */
id: string;
/** Name of purpose */
name: string;
/** Slug of purpose */
trackingType: string;
/** Whether the purpose is active */
isActive: boolean;
/** Whether the purpose is deleted */
deletedAt?: string;
}

const PAGE_SIZE = 20;

/**
* Fetch all purposes in the organization
*
* @param client - GraphQL client
* @param input - Input
* @returns All purposes in the organization
*/
export async function fetchAllPurposes(
client: GraphQLClient,
{
includeDeleted = false,
}: {
/** Whether to include deleted purposes */
includeDeleted?: boolean;
} = {},
): Promise<Purpose[]> {
const purposes: Purpose[] = [];
let offset = 0;

// Whether to continue looping
let shouldContinue = false;
do {
const {
purposes: { nodes },
// eslint-disable-next-line no-await-in-loop
} = await makeGraphQLRequest<{
/** Purposes */
purposes: {
/** List */
nodes: Purpose[];
};
}>(client, PURPOSES, {
first: PAGE_SIZE,
offset,
input: {
includeDeleted,
},
});
purposes.push(...nodes);
offset += PAGE_SIZE;
shouldContinue = nodes.length === PAGE_SIZE;
} while (shouldContinue);

return purposes.sort((a, b) => a.trackingType.localeCompare(b.trackingType));
}
22 changes: 0 additions & 22 deletions src/graphql/fetchConsentManagerId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
FETCH_CONSENT_MANAGER_ID,
FETCH_CONSENT_MANAGER,
EXPERIENCES,
PURPOSES,
CONSENT_MANAGER_ANALYTICS_DATA,
FETCH_CONSENT_MANAGER_THEME,
} from './gqls';
Expand Down Expand Up @@ -118,27 +117,6 @@ export interface ConsentPurpose {
trackingType: string;
}

/**
* Fetch consent manager purposes
*
* @param client - GraphQL client
* @returns Consent manager purposes in the organization
*/
export async function fetchPurposes(
client: GraphQLClient,
): Promise<ConsentPurpose[]> {
const {
purposes: { purposes },
} = await makeGraphQLRequest<{
/** Consent manager query */
purposes: {
/** Consent manager object */
purposes: ConsentPurpose[];
};
}>(client, PURPOSES);
return purposes;
}

const PAGE_SIZE = 50;

export interface ConsentExperience {
Expand Down
12 changes: 0 additions & 12 deletions src/graphql/gqls/consentManager.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
/* eslint-disable max-lines */
import { gql } from 'graphql-request';

export const PURPOSES = gql`
query TranscendCliPurposes {
purposes {
purposes {
id
name
trackingType
}
}
}
`;

// TODO: https://transcend.height.app/T-27909 - order by createdAt
// TODO: https://transcend.height.app/T-27909 - enable optimizations
// isExportCsv: true
Expand Down
2 changes: 2 additions & 0 deletions src/graphql/gqls/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export * from './request';
export * from './message';
export * from './RequestEnricher';
export * from './assessment';
export * from './purpose';
export * from './preferenceTopic';
export * from './assessmentTemplate';
export * from './prompt';
export * from './RequestEnricher';
Expand Down
30 changes: 30 additions & 0 deletions src/graphql/gqls/preferenceTopic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { gql } from 'graphql-request';

// TODO: https://transcend.height.app/T-27909 - enable optimizations
// isExportCsv: true
// useMaster: false
// orderBy: [
// { field: createdAt, direction: ASC }
// { field: name, direction: ASC }
// ]
export const PREFERENCE_TOPICS = gql`
query TranscendCliPreferenceTopics(
$first: Int!
$offset: Int!
$filterBy: PreferenceTopicFilterInput
) {
preferenceTopics(first: $first, offset: $offset, filterBy: $filterBy) {
nodes {
id
slug
type
preferenceOptionValues {
slug
}
purpose {
trackingType
}
}
}
}
`;
32 changes: 32 additions & 0 deletions src/graphql/gqls/purpose.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { gql } from 'graphql-request';

// TODO: https://transcend.height.app/T-27909 - enable optimizations
// isExportCsv: true
// useMaster: false
// orderBy: [
// { field: createdAt, direction: ASC }
// { field: name, direction: ASC }
// ]
export const PURPOSES = gql`
query TranscendCliPurposes(
$first: Int!
$offset: Int!
$filterBy: TrackingPurposeFiltersInput
$input: TrackingPurposeInput!
) {
purposes(
first: $first
offset: $offset
filterBy: $filterBy
input: $input
) {
nodes {
id
name
trackingType
isActive
deletedAt
}
}
}
`;
2 changes: 2 additions & 0 deletions src/graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ export * from './fetchAllRequests';
export * from './fetchAllRequestIdentifiers';
export * from './fetchAllRequestEnrichers';
export * from './fetchRequestDataSilo';
export * from './fetchAllPreferenceTopics';
export * from './fetchAllAttributes';
export * from './syncAttribute';
export * from './fetchAllDataFlows';
export * from './syncActionItems';
export * from './fetchAllPurposes';
export * from './syncActionItemCollections';
export * from './fetchAllCookies';
export * from './fetchAllActionItems';
Expand Down
4 changes: 2 additions & 2 deletions src/graphql/syncConsentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { makeGraphQLRequest } from './makeGraphQLRequest';
import {
fetchConsentManagerId,
fetchConsentManagerExperiences,
fetchPurposes,
} from './fetchConsentManagerId';
import keyBy from 'lodash/keyBy';
import { map } from 'bluebird';
Expand All @@ -30,6 +29,7 @@ import {
import { logger } from '../logger';
import { fetchPrivacyCenterId } from './fetchPrivacyCenterId';
import { fetchPartitions } from './syncPartitions';
import { fetchAllPurposes } from './fetchAllPurposes';

const PURPOSES_LINK =
'https://app.transcend.io/consent-manager/regional-experiences/purposes';
Expand All @@ -49,7 +49,7 @@ export async function syncConsentManagerExperiences(
const experienceLookup = keyBy(existingExperiences, 'name');

// Fetch existing purposes
const purposes = await fetchPurposes(client);
const purposes = await fetchAllPurposes(client);
const purposeLookup = keyBy(purposes, 'trackingType');

// Bulk update or create experiences
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/syncCookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function updateOrCreateCookies(
const airgapBundleId = await fetchConsentManagerId(client);

// TODO: https://transcend.height.app/T-19841 - add with custom purposes
// const purposes = await fetchPurposes(client);
// const purposes = await fetchAllPurposes(client);
// const purposeNameToId = keyBy(purposes, 'name');

await mapSeries(chunk(cookieInputs, MAX_PAGE_SIZE), async (page) => {
Expand Down
4 changes: 2 additions & 2 deletions src/graphql/syncDataFlows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function updateDataFlows(
const airgapBundleId = await fetchConsentManagerId(client);

// TODO: https://transcend.height.app/T-19841 - add with custom purposes
// const purposes = await fetchPurposes(client);
// const purposes = await fetchAllPurposes(client);
// const purposeNameToId = keyBy(purposes, 'name');

await mapSeries(chunk(dataFlowInputs, MAX_PAGE_SIZE), async (page) => {
Expand Down Expand Up @@ -74,7 +74,7 @@ export async function createDataFlows(
): Promise<void> {
const airgapBundleId = await fetchConsentManagerId(client);
// TODO: https://transcend.height.app/T-19841 - add with custom purposes
// const purposes = await fetchPurposes(client);
// const purposes = await fetchAllPurposes(client);
// const purposeNameToId = keyBy(purposes, 'name');
await mapSeries(chunk(dataFlowInputs, MAX_PAGE_SIZE), async (page) => {
await makeGraphQLRequest(client, CREATE_DATA_FLOWS, {
Expand Down
Loading

0 comments on commit f5e8462

Please sign in to comment.