Path: blob/master/src/packages/conat/hub/api/system.ts
5808 views
import { noAuth, authFirst, requireAccount } from "./util";1import type { Customize } from "@cocalc/util/db-schema/server-settings";2import type {3ApiKey,4Action as ApiKeyAction,5} from "@cocalc/util/db-schema/api-keys";6import { type UserSearchResult } from "@cocalc/util/db-schema/accounts";78export const system = {9getCustomize: noAuth,10ping: noAuth,11test: authFirst,12terminate: authFirst,13userTracking: authFirst,14logClientError: authFirst,15webappError: authFirst,16manageApiKeys: authFirst,17generateUserAuthToken: authFirst,18revokeUserAuthToken: noAuth,19userSearch: authFirst,20getNames: requireAccount,21adminResetPasswordLink: authFirst,22sendEmailVerification: authFirst,23deletePassport: authFirst,2425adminSalesloftSync: authFirst,26userSalesloftSync: authFirst,27};2829export interface System {30// get all or specific customize data31getCustomize: (fields?: string[]) => Promise<Customize>;32// ping server and get back the current time33ping: () => { now: number };34// test API key and return scope information (account_id) and server time35test: () => Promise<{ account_id: string; server_time: number }>;36// terminate a service:37// - only admin can do this.38// - useful for development39terminate: (service: "database" | "api") => Promise<void>;4041userTracking: (opts: {42event: string;43value: object;44account_id?: string;45}) => Promise<void>;4647logClientError: (opts: {48account_id?: string;49event: string;50error: string;51}) => Promise<void>;5253webappError: (opts: object) => Promise<void>;5455manageApiKeys: (opts: {56account_id?: string;57action: ApiKeyAction;58project_id?: string;59name?: string;60expire?: Date;61id?: number;62}) => Promise<ApiKey[] | undefined>;6364generateUserAuthToken: (opts: {65account_id?: string;66user_account_id: string;67password?: string;68}) => Promise<string>;6970revokeUserAuthToken: (authToken: string) => Promise<void>;7172userSearch: (opts: {73account_id?: string;74query: string;75limit?: number;76admin?: boolean;77only_email?: boolean;78}) => Promise<UserSearchResult[]>;7980getNames: (account_ids: string[]) => Promise<{81[account_id: string]:82| {83first_name: string;84last_name: string;85profile?: { color?: string; image?: string };86}87| undefined;88}>;8990// adminResetPasswordLink: Enables admins (and only admins!) to generate and get a password reset91// for another user. The response message contains a password reset link,92// though without the site part of the url (the client should fill that in).93// This makes it possible for admins to reset passwords of users, even if94// sending email is not setup, e.g., for cocalc-docker, and also deals with the95// possibility that users have no email address, or broken email, or they96// can't receive email due to crazy spam filtering.97// Non-admins always get back an error.98adminResetPasswordLink: (opts: {99account_id?: string;100user_account_id: string;101}) => Promise<string>;102103// user must be an admin or get an error. Sync's the given salesloft accounts.104adminSalesloftSync: (opts: {105account_id?: string;106account_ids: string[];107}) => Promise<void>;108109userSalesloftSync: (opts: { account_id?: string }) => Promise<void>;110111sendEmailVerification: (opts: {112account_id?: string;113only_verify?: boolean;114}) => Promise<void>;115116deletePassport: (opts: {117account_id?: string;118strategy: string;119id: string;120}) => Promise<void>;121}122123124