Path: blob/master/src/packages/conat/hub/api/system.ts
1452 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,11terminate: authFirst,12userTracking: authFirst,13logClientError: authFirst,14webappError: authFirst,15manageApiKeys: authFirst,16generateUserAuthToken: authFirst,17revokeUserAuthToken: noAuth,18userSearch: authFirst,19getNames: requireAccount,20adminResetPasswordLink: authFirst,21sendEmailVerification: authFirst,22deletePassport: authFirst,2324adminSalesloftSync: authFirst,25};2627export interface System {28// get all or specific customize data29getCustomize: (fields?: string[]) => Promise<Customize>;30// ping server and get back the current time31ping: () => { now: number };32// terminate a service:33// - only admin can do this.34// - useful for development35terminate: (service: "database" | "api") => Promise<void>;3637userTracking: (opts: {38event: string;39value: object;40account_id?: string;41}) => Promise<void>;4243logClientError: (opts: {44account_id?: string;45event: string;46error: string;47}) => Promise<void>;4849webappError: (opts: object) => Promise<void>;5051manageApiKeys: (opts: {52account_id?: string;53action: ApiKeyAction;54project_id?: string;55name?: string;56expire?: Date;57id?: number;58}) => Promise<ApiKey[] | undefined>;5960generateUserAuthToken: (opts: {61account_id?: string;62user_account_id: string;63password?: string;64}) => Promise<string>;6566revokeUserAuthToken: (authToken: string) => Promise<void>;6768userSearch: (opts: {69account_id?: string;70query: string;71limit?: number;72admin?: boolean;73only_email?: boolean;74}) => Promise<UserSearchResult[]>;7576getNames: (account_ids: string[]) => Promise<{77[account_id: string]:78| {79first_name: string;80last_name: string;81profile?: { color?: string; image?: string };82}83| undefined;84}>;8586// adminResetPasswordLink: Enables admins (and only admins!) to generate and get a password reset87// for another user. The response message contains a password reset link,88// though without the site part of the url (the client should fill that in).89// This makes it possible for admins to reset passwords of users, even if90// sending email is not setup, e.g., for cocalc-docker, and also deals with the91// possibility that users have no email address, or broken email, or they92// can't receive email due to crazy spam filtering.93// Non-admins always get back an error.94adminResetPasswordLink: (opts: {95account_id?: string;96user_account_id: string;97}) => Promise<string>;9899// user must be an admin or get an error. Sync's the given salesloft accounts.100adminSalesloftSync: (opts: {101account_id?: string;102account_ids: string[];103}) => Promise<void>;104105sendEmailVerification: (opts: {106account_id?: string;107only_verify?: boolean;108}) => Promise<void>;109110deletePassport: (opts: {111account_id?: string;112strategy: string;113id: string;114}) => Promise<void>;115}116117118