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