Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/database/postgres/pii.ts
1503 views
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { expire_time } from "@cocalc/util/misc";
7
import { get_server_settings } from "./server-settings";
8
9
// this converts what's in the pii_expired setting to a new Date in the future
10
export function pii_retention_to_future<T extends object>(
11
pii_retention: number | false,
12
data?: T & { expire?: Date },
13
): Date | undefined {
14
if (!pii_retention) return;
15
const future: Date = expire_time(pii_retention);
16
if (data != null) {
17
data.expire = future;
18
}
19
return future;
20
}
21
22
// use this to get the "expire" value for storing certain entries in the DB,
23
// which contain personally identifiable information.
24
// if data is set, it's expire field will be set. in any case, it returns the "Date"
25
// in the future.
26
export async function pii_expire<T extends object>(
27
data?: T & { expire?: Date },
28
): Promise<Date | undefined> {
29
const settings = await get_server_settings();
30
return pii_retention_to_future<T>(settings.pii_retention, data);
31
}
32
33