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