Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfarrell76 committed Dec 1, 2024
1 parent f5e8462 commit 6b61ec6
Show file tree
Hide file tree
Showing 11 changed files with 371 additions and 712 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ transcend.yml
transcend-privacy-requests-cache.json
cron-identifiers.csv
manual-enrichment-identifiers.csv
preference-management-upload-receipts.json
build/
privacy-request-upload-receipts/

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Transcend Inc.",
"name": "@transcend-io/cli",
"description": "Small package containing useful typescript utilities.",
"version": "6.9.0",
"version": "6.10.0",
"homepage": "https://github.com/transcend-io/cli",
"repository": {
"type": "git",
Expand Down
11 changes: 7 additions & 4 deletions src/cli-upload-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ async function main(): Promise<void> {
partition,
/** Whether to do a dry run */
dryRun = 'false',
/** Whether to refresh cache */
refreshCache = 'false',
/** Whether to skip workflow triggers */
skipWorkflowTriggers = 'false',
/** Whether to skip sending emails */
isSilent = 'true',
/** Attributes to add to any DSR request if created */
attributes = 'Tags:transcend-cli',
attributes = 'Tags:transcend-cli,Source:transcend-cli',
/** Store resulting, continuing where left off */
receiptFilepath = './preference-management-upload-receipts.json',
} = yargs(process.argv.slice(2)) as { [k in string]: string };
Expand Down Expand Up @@ -73,8 +75,9 @@ async function main(): Promise<void> {
sombraAuth,
files: splitCsvToList(files),
partition,
refreshPreferenceStoreCache: refreshCache === 'true',
transcendUrl,
skipWorkflowTriggers: skipWorkflowTriggers !== 'false',
isSilent: isSilent !== 'false',
dryRun: dryRun !== 'false',
attributes: splitCsvToList(attributes),
});
Expand Down
30 changes: 7 additions & 23 deletions src/preference-management/codecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ export const FileMetadataState = t.intersection([
* Mapping of userId to the rows in the file that need to be uploaded
* these records have conflicts with existing consent preferences
*/
pendingConflictUpdates: t.record(t.string, t.record(t.string, t.string)),
pendingConflictUpdates: t.record(
t.string,
t.type({
record: PreferenceQueryResponseItem,
row: t.record(t.string, t.string),
}),
),
/**
* Mapping of userId to the rows in the file that can be skipped because
* their preferences are already in the store
Expand All @@ -49,32 +55,10 @@ export type FileMetadataState = t.TypeOf<typeof FileMetadataState>;

/** Persist this data between runs of the script */
export const PreferenceState = t.type({
/**
* Mapping from core userId to preference store record
*/
preferenceStoreRecords: t.record(
t.string,
t.union([PreferenceQueryResponseItem, t.null]),
),
/**
* Store a cache of previous files read in
*/
fileMetadata: t.record(t.string, FileMetadataState),
/**
* The set of successful uploads to Transcend
* Mapping from userId to the upload metadata
*/
successfulUpdates: t.record(
t.string,
t.array(
t.type({
/** Time upload ran at */
uploadedAt: t.string,
/** The update body */
update: PreferenceUpdateItem,
}),
),
),
/**
* The set of successful uploads to Transcend
* Mapping from userId to the upload metadata
Expand Down
22 changes: 16 additions & 6 deletions src/preference-management/getPreferencesForIdentifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export async function getPreferencesForIdentifiers(
{
identifiers,
partitionKey,
skipLogging = false,
}: {
/** The list of identifiers to look up */
identifiers: {
Expand All @@ -38,6 +39,8 @@ export async function getPreferencesForIdentifiers(
}[];
/** The partition key to look up */
partitionKey: string;
/** Whether to skip logging */
skipLogging?: boolean;
},
): Promise<PreferenceQueryResponseItem[]> {
const results: PreferenceQueryResponseItem[] = [];
Expand All @@ -49,7 +52,9 @@ export async function getPreferencesForIdentifiers(
{},
cliProgress.Presets.shades_classic,
);
progressBar.start(identifiers.length, 0);
if (!skipLogging) {
progressBar.start(identifiers.length, 0);
}

let total = 0;
await map(
Expand All @@ -63,6 +68,7 @@ export async function getPreferencesForIdentifiers(
filter: {
identifiers: group,
},
limit: group.length,
},
})
.json();
Expand Down Expand Up @@ -101,7 +107,9 @@ export async function getPreferencesForIdentifiers(
const result = decodeCodec(PreferenceRecordsQueryResponse, rawResult);
results.push(...result.nodes);
total += group.length;
progressBar.update(total);
if (!skipLogging) {
progressBar.update(total);
}
}
},
{
Expand All @@ -113,10 +121,12 @@ export async function getPreferencesForIdentifiers(
const t1 = new Date().getTime();
const totalTime = t1 - t0;

// Log completion time
logger.info(
colors.green(`Completed upload in "${totalTime / 1000}" seconds.`),
);
if (!skipLogging) {
// Log completion time
logger.info(
colors.green(`Completed download in "${totalTime / 1000}" seconds.`),
);
}

return results;
}
100 changes: 0 additions & 100 deletions src/preference-management/getPreferencesFromIdentifiersWithCache.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/preference-management/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './uploadPreferenceManagementPreferencesInteractive';
export * from './codecs';
export * from './getPreferencesForIdentifiers';
export * from './getPreferencesFromIdentifiersWithCache';
export * from './parsePreferenceManagementCsvWithCache';
Loading

0 comments on commit 6b61ec6

Please sign in to comment.