Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/conat/hub/api/system.ts
1452 views
1
import { noAuth, authFirst, requireAccount } from "./util";
2
import type { Customize } from "@cocalc/util/db-schema/server-settings";
3
import type {
4
ApiKey,
5
Action as ApiKeyAction,
6
} from "@cocalc/util/db-schema/api-keys";
7
import { type UserSearchResult } from "@cocalc/util/db-schema/accounts";
8
9
export const system = {
10
getCustomize: noAuth,
11
ping: noAuth,
12
terminate: authFirst,
13
userTracking: authFirst,
14
logClientError: authFirst,
15
webappError: authFirst,
16
manageApiKeys: authFirst,
17
generateUserAuthToken: authFirst,
18
revokeUserAuthToken: noAuth,
19
userSearch: authFirst,
20
getNames: requireAccount,
21
adminResetPasswordLink: authFirst,
22
sendEmailVerification: authFirst,
23
deletePassport: authFirst,
24
25
adminSalesloftSync: authFirst,
26
};
27
28
export interface System {
29
// get all or specific customize data
30
getCustomize: (fields?: string[]) => Promise<Customize>;
31
// ping server and get back the current time
32
ping: () => { now: number };
33
// terminate a service:
34
// - only admin can do this.
35
// - useful for development
36
terminate: (service: "database" | "api") => Promise<void>;
37
38
userTracking: (opts: {
39
event: string;
40
value: object;
41
account_id?: string;
42
}) => Promise<void>;
43
44
logClientError: (opts: {
45
account_id?: string;
46
event: string;
47
error: string;
48
}) => Promise<void>;
49
50
webappError: (opts: object) => Promise<void>;
51
52
manageApiKeys: (opts: {
53
account_id?: string;
54
action: ApiKeyAction;
55
project_id?: string;
56
name?: string;
57
expire?: Date;
58
id?: number;
59
}) => Promise<ApiKey[] | undefined>;
60
61
generateUserAuthToken: (opts: {
62
account_id?: string;
63
user_account_id: string;
64
password?: string;
65
}) => Promise<string>;
66
67
revokeUserAuthToken: (authToken: string) => Promise<void>;
68
69
userSearch: (opts: {
70
account_id?: string;
71
query: string;
72
limit?: number;
73
admin?: boolean;
74
only_email?: boolean;
75
}) => Promise<UserSearchResult[]>;
76
77
getNames: (account_ids: string[]) => Promise<{
78
[account_id: string]:
79
| {
80
first_name: string;
81
last_name: string;
82
profile?: { color?: string; image?: string };
83
}
84
| undefined;
85
}>;
86
87
// adminResetPasswordLink: Enables admins (and only admins!) to generate and get a password reset
88
// for another user. The response message contains a password reset link,
89
// though without the site part of the url (the client should fill that in).
90
// This makes it possible for admins to reset passwords of users, even if
91
// sending email is not setup, e.g., for cocalc-docker, and also deals with the
92
// possibility that users have no email address, or broken email, or they
93
// can't receive email due to crazy spam filtering.
94
// Non-admins always get back an error.
95
adminResetPasswordLink: (opts: {
96
account_id?: string;
97
user_account_id: string;
98
}) => Promise<string>;
99
100
// user must be an admin or get an error. Sync's the given salesloft accounts.
101
adminSalesloftSync: (opts: {
102
account_id?: string;
103
account_ids: string[];
104
}) => Promise<void>;
105
106
sendEmailVerification: (opts: {
107
account_id?: string;
108
only_verify?: boolean;
109
}) => Promise<void>;
110
111
deletePassport: (opts: {
112
account_id?: string;
113
strategy: string;
114
id: string;
115
}) => Promise<void>;
116
}
117
118