@casual-simulation/aux-records 3.0.16 → 3.0.18-alpha.2720826118

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,306 @@
1
+ import { AddressType, AuthStore } from './AuthStore';
2
+ import { ServerError } from './Errors';
3
+ import { AuthMessenger } from './AuthMessenger';
4
+ /**
5
+ * The number of miliseconds that a login request should be valid for before expiration.
6
+ */
7
+ export declare const LOGIN_REQUEST_LIFETIME_MS: number;
8
+ /**
9
+ * The number of bytes that should be used for login request IDs.
10
+ */
11
+ export declare const LOGIN_REQUEST_ID_BYTE_LENGTH = 16;
12
+ /**
13
+ * The number of bytes that should be used for session IDs.
14
+ */
15
+ export declare const SESSION_ID_BYTE_LENGTH = 16;
16
+ /**
17
+ * The number of bytes that should be used for session secrets.
18
+ */
19
+ export declare const SESSION_SECRET_BYTE_LENGTH = 16;
20
+ /**
21
+ * The number of miliseconds that a login session should be valid for before expiration.
22
+ */
23
+ export declare const SESSION_LIFETIME_MS: number;
24
+ /**
25
+ * The error message that should be used for invalid_request error messages.
26
+ */
27
+ export declare const INVALID_REQUEST_ERROR_MESSAGE = "The login request is invalid.";
28
+ /**
29
+ * The maximum allowed number of attempts for completing a login request.
30
+ */
31
+ export declare const MAX_LOGIN_REQUEST_ATTEMPTS = 5;
32
+ /**
33
+ * The error message that should be used for invalid_key error messages.
34
+ */
35
+ export declare const INVALID_KEY_ERROR_MESSAGE = "The session key is invalid.";
36
+ /**
37
+ * Defines a class that is able to authenticate users.
38
+ */
39
+ export declare class AuthController {
40
+ private _store;
41
+ private _messenger;
42
+ constructor(authStore: AuthStore, messenger: AuthMessenger);
43
+ requestLogin(request: LoginRequest): Promise<LoginRequestResult>;
44
+ completeLogin(request: CompleteLoginRequest): Promise<CompleteLoginResult>;
45
+ validateSessionKey(key: string): Promise<ValidateSessionKeyResult>;
46
+ revokeSession(request: RevokeSessionRequest): Promise<RevokeSessionResult>;
47
+ /**
48
+ * Attempts to revoke all the sessions for the specified user.
49
+ * @param request The request.
50
+ */
51
+ revokeAllSessions(request: RevokeAllSessionsRequest): Promise<RevokeAllSessionsResult>;
52
+ /**
53
+ * Attempts to replace the given session key with a new key.
54
+ * @param request The request.
55
+ */
56
+ replaceSession(request: ReplaceSessionRequest): Promise<ReplaceSessionResult>;
57
+ /**
58
+ * Lists all the sessions for a given user.
59
+ * @param request The request.
60
+ */
61
+ listSessions(request: ListSessionsRequest): Promise<ListSessionsResult>;
62
+ }
63
+ export interface LoginRequest {
64
+ /**
65
+ * The address that the login is for.
66
+ */
67
+ address: string;
68
+ /**
69
+ * The type of the address.
70
+ */
71
+ addressType: AddressType;
72
+ /**
73
+ * The IP address that the login is from.
74
+ */
75
+ ipAddress: string;
76
+ }
77
+ export declare type LoginRequestResult = LoginRequestSuccess | LoginRequestFailure;
78
+ export interface LoginRequestSuccess {
79
+ success: true;
80
+ /**
81
+ * The ID of the user that the request is for.
82
+ */
83
+ userId: string;
84
+ /**
85
+ * The ID of the generated login request.
86
+ */
87
+ requestId: string;
88
+ /**
89
+ * The address that the login request is for.
90
+ */
91
+ address: string;
92
+ /**
93
+ * The type of the address.
94
+ */
95
+ addressType: AddressType;
96
+ /**
97
+ * The unix timestamp in miliseconds that the login request will expire at.
98
+ */
99
+ expireTimeMs: number;
100
+ }
101
+ export interface LoginRequestFailure {
102
+ success: false;
103
+ /**
104
+ * The error code for the failure.
105
+ */
106
+ errorCode: 'unacceptable_address' | 'unacceptable_address_type' | 'unacceptable_ip_address' | 'address_type_not_supported' | ServerError;
107
+ /**
108
+ * The error message for the failure.
109
+ */
110
+ errorMessage: string;
111
+ }
112
+ export interface CompleteLoginRequest {
113
+ /**
114
+ * The ID of the user that the login request is for.
115
+ */
116
+ userId: string;
117
+ /**
118
+ * The ID of the login request.
119
+ */
120
+ requestId: string;
121
+ /**
122
+ * The code that was sent to the address.
123
+ */
124
+ code: string;
125
+ /**
126
+ * The IP address that the request is coming from.
127
+ */
128
+ ipAddress: string;
129
+ }
130
+ export declare type CompleteLoginResult = CompleteLoginSuccess | CompleteLoginFailure;
131
+ export interface CompleteLoginSuccess {
132
+ success: true;
133
+ /**
134
+ * The ID of the user that the session is for.
135
+ */
136
+ userId: string;
137
+ /**
138
+ * The secret key that provides access for the session.
139
+ */
140
+ sessionKey: string;
141
+ /**
142
+ * The unix timestamp in miliseconds that the session will expire at.
143
+ */
144
+ expireTimeMs: number;
145
+ }
146
+ export interface CompleteLoginFailure {
147
+ success: false;
148
+ /**
149
+ * The error code for the failure.
150
+ */
151
+ errorCode: 'unacceptable_user_id' | 'unacceptable_request_id' | 'unacceptable_code' | 'invalid_code' | 'unacceptable_ip_address' | 'invalid_request' | ServerError;
152
+ /**
153
+ * The error message for the failure.
154
+ */
155
+ errorMessage: string;
156
+ }
157
+ export declare type ValidateSessionKeyResult = ValidateSessionKeySuccess | ValidateSessionKeyFailure;
158
+ export interface ValidateSessionKeySuccess {
159
+ success: true;
160
+ userId: string;
161
+ sessionId: string;
162
+ allSessionsRevokedTimeMs?: number;
163
+ }
164
+ export interface ValidateSessionKeyFailure {
165
+ success: false;
166
+ errorCode: 'unacceptable_session_key' | 'invalid_key' | 'session_expired' | ServerError;
167
+ errorMessage: string;
168
+ }
169
+ export interface RevokeSessionRequest {
170
+ /**
171
+ * The ID of the user whose session should be revoked.
172
+ */
173
+ userId: string;
174
+ /**
175
+ * The ID of the session that should be revoked.
176
+ */
177
+ sessionId: string;
178
+ /**
179
+ * The session key that should authenticate the request.
180
+ */
181
+ sessionKey: string;
182
+ }
183
+ export declare type RevokeSessionResult = RevokeSessionSuccess | RevokeSessionFailure;
184
+ export interface RevokeSessionSuccess {
185
+ success: true;
186
+ }
187
+ export interface RevokeSessionFailure {
188
+ success: false;
189
+ errorCode: 'unacceptable_user_id' | 'unacceptable_session_id' | 'unacceptable_session_key' | 'invalid_key' | 'session_expired' | 'session_not_found' | 'session_already_revoked' | ServerError;
190
+ errorMessage: string;
191
+ }
192
+ export interface RevokeAllSessionsRequest {
193
+ /**
194
+ * The ID of the user whose sessions should be revoked.
195
+ */
196
+ userId: string;
197
+ /**
198
+ * The session key that should authenticate the request.
199
+ */
200
+ sessionKey: string;
201
+ }
202
+ export declare type RevokeAllSessionsResult = RevokeAllSessionsSuccess | RevokeAllSessionsFailure;
203
+ export interface RevokeAllSessionsSuccess {
204
+ success: true;
205
+ }
206
+ export interface RevokeAllSessionsFailure {
207
+ success: false;
208
+ errorCode: 'unacceptable_user_id' | 'unacceptable_session_key' | 'invalid_key' | 'session_expired' | ServerError;
209
+ errorMessage: string;
210
+ }
211
+ export interface ListSessionsRequest {
212
+ /**
213
+ * The ID of the user whose sessions should be listed.
214
+ */
215
+ userId: string;
216
+ /**
217
+ * The expiration time that the listing should start after.
218
+ */
219
+ expireTimeMs?: number | null;
220
+ /**
221
+ * The key that should be used to authorize the request.
222
+ */
223
+ sessionKey: string;
224
+ }
225
+ export declare type ListSessionsResult = ListSessionsSuccess | ListSessionsFailure;
226
+ export interface ListSessionsSuccess {
227
+ success: true;
228
+ /**
229
+ *
230
+ */
231
+ sessions: ListedSession[];
232
+ }
233
+ export interface ListSessionsFailure {
234
+ success: false;
235
+ errorCode: 'unacceptable_user_id' | 'unacceptable_expire_time' | 'unacceptable_session_key' | 'invalid_key' | 'session_expired' | ServerError;
236
+ errorMessage: string;
237
+ }
238
+ /**
239
+ * Defines an interface for a session that has been listed.
240
+ */
241
+ export interface ListedSession {
242
+ /**
243
+ * The ID of the user that this session belongs to.
244
+ */
245
+ userId: string;
246
+ /**
247
+ * The ID of the session.
248
+ */
249
+ sessionId: string;
250
+ /**
251
+ * The unix time that the session was granted at.
252
+ */
253
+ grantedTimeMs: number;
254
+ /**
255
+ * The unix time that the session will expire at.
256
+ */
257
+ expireTimeMs: number;
258
+ /**
259
+ * The unix time that the session was revoked at.
260
+ */
261
+ revokeTimeMs: number;
262
+ /**
263
+ * The IP address that the session was granted to.
264
+ */
265
+ ipAddress: string;
266
+ /**
267
+ * Whether this session represents the session key that was used to access the session list.
268
+ */
269
+ currentSession: boolean;
270
+ /**
271
+ * The ID of the session that replaced this session.
272
+ */
273
+ nextSessionId: string;
274
+ }
275
+ export interface ReplaceSessionRequest {
276
+ /**
277
+ * The session key that should be replaced.
278
+ */
279
+ sessionKey: string;
280
+ /**
281
+ * The IP Address that is making this request.
282
+ */
283
+ ipAddress: string;
284
+ }
285
+ export declare type ReplaceSessionResult = ReplaceSessionSuccess | ReplaceSessionFailure;
286
+ export interface ReplaceSessionSuccess {
287
+ success: true;
288
+ /**
289
+ * The ID of the user that the session is for.
290
+ */
291
+ userId: string;
292
+ /**
293
+ * The secret key that provides access for the session.
294
+ */
295
+ sessionKey: string;
296
+ /**
297
+ * The unix timestamp in miliseconds that the session will expire at.
298
+ */
299
+ expireTimeMs: number;
300
+ }
301
+ export interface ReplaceSessionFailure {
302
+ success: false;
303
+ errorCode: 'unacceptable_session_key' | 'unacceptable_ip_address' | ValidateSessionKeyFailure['errorCode'] | ServerError;
304
+ errorMessage: string;
305
+ }
306
+ //# sourceMappingURL=AuthController.d.ts.map