Path: blob/master/src/packages/util/db-schema/api-keys.ts
1447 views
import { Table } from "./types";1import { CREATED_BY, ID } from "./crm";23export type Action = "get" | "delete" | "create" | "edit";45export interface ApiKey {6id: number;7account_id: string;8created: Date;9hash?: string; // usually NOT available10trunc: string;11project_id?: string; // only for project api keys12expire?: Date;13name: string;14last_active?: Date;15secret?: string; // only when initially creating the key (and never in database)16}1718Table({19name: "api_keys",20fields: {21id: ID,22account_id: CREATED_BY, // who made this api key23expire: {24type: "timestamp",25desc: "When this api key expires and is automatically deleted.",26},27created: {28type: "timestamp",29desc: "When this api key was created.",30},31hash: {32type: "string",33pg_type: "VARCHAR(173)",34desc: "Hash of the api key. This is the same hash as for user passwords, which is 1000 iterations of sha512 with salt of length 32.",35},36name: {37type: "string",38pg_type: "VARCHAR(128)",39desc: "user defined name of this key",40},41trunc: {42type: "string",43pg_type: "VARCHAR(16)",44desc: "Truncated version of the actual api key, suitable for display to remind user which key it is.",45},46project_id: {47type: "uuid",48desc: "Optional uuid of the project that this api key applies to. If not set, api key is global.",49},50last_active: {51type: "timestamp",52desc: "When this api key was last used.",53},54},55rules: {56primary_key: "id",57pg_indexes: [58"((created IS NOT NULL))",59"((account_id IS NOT NULL))",60"project_id",61],62},63});646566