/
accounts-base.d.ts
392 lines (334 loc) · 11.1 KB
/
accounts-base.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
import { Mongo } from 'meteor/mongo';
import { Meteor } from 'meteor/meteor';
import { Configuration } from 'meteor/service-configuration';
import { DDP } from 'meteor/ddp';
export interface URLS {
resetPassword: (token: string) => string;
verifyEmail: (token: string) => string;
enrollAccount: (token: string) => string;
}
export interface EmailFields {
from?: ((user: Meteor.User) => string) | undefined;
subject?: ((user: Meteor.User) => string) | undefined;
text?: ((user: Meteor.User, url: string) => string) | undefined;
html?: ((user: Meteor.User, url: string) => string) | undefined;
}
export interface AccountsClientOptions {
connection?: DDP.DDPStatic;
ddpUrl?: string;
}
export class AccountsClient {
constructor(options?: AccountsClientOptions);
connection: DDP.DDPStatic;
}
export namespace Accounts {
var urls: URLS;
function user(options?: {
fields?: Mongo.FieldSpecifier | undefined;
}): Meteor.User | null;
function userAsync(options?: {
fields?: Mongo.FieldSpecifier | undefined;
}): Promise<Meteor.User | null>;
function userId(): string | null;
function createUser(
options: {
username?: string | undefined;
email?: string | undefined;
password?: string | undefined;
profile?: Meteor.UserProfile | undefined;
},
callback?: (error?: Error | Meteor.Error | Meteor.TypedError) => void
): string;
function createUserAsync(
options: {
username?: string | undefined;
email?: string | undefined;
password?: string | undefined;
profile?: Meteor.UserProfile | undefined;
},
callback?: (error?: Error | Meteor.Error | Meteor.TypedError) => void
): Promise<string>;
function createUserVerifyingEmail(
options: {
username?: string | undefined;
email?: string | undefined;
password?: string | undefined;
profile?: Meteor.UserProfile | undefined;
},
callback?: (error?: Error | Meteor.Error | Meteor.TypedError) => void
): Promise<string>;
function config(options: {
sendVerificationEmail?: boolean | undefined;
forbidClientAccountCreation?: boolean | undefined;
restrictCreationByEmailDomain?: string | Function | undefined;
loginExpiration?: number | undefined;
loginExpirationInDays?: number | undefined;
oauthSecretKey?: string | undefined;
passwordResetTokenExpiration?: number | undefined;
passwordResetTokenExpirationInDays?: number | undefined;
passwordEnrollTokenExpiration?: number | undefined;
passwordEnrollTokenExpirationInDays?: number | undefined;
ambiguousErrorMessages?: boolean | undefined;
bcryptRounds?: number | undefined;
defaultFieldSelector?: { [key: string]: 0 | 1 } | undefined;
collection?: string | undefined;
loginTokenExpirationHours?: number | undefined;
tokenSequenceLength?: number | undefined;
clientStorage?: 'session' | 'local';
}): void;
function onLogin(
func: Function
): {
stop: () => void;
};
function onLoginFailure(
func: Function
): {
stop: () => void;
};
var loginServiceConfiguration: Mongo.Collection<Configuration>
function loginServicesConfigured(): boolean;
function onPageLoadLogin(func: Function): void;
}
export namespace Accounts {
function changePassword(
oldPassword: string,
newPassword: string,
callback?: (error?: Error | Meteor.Error | Meteor.TypedError) => void
): void;
function forgotPassword(
options: { email?: string | undefined },
callback?: (error?: Error | Meteor.Error | Meteor.TypedError) => void
): void;
function resetPassword(
token: string,
newPassword: string,
callback?: (error?: Error | Meteor.Error | Meteor.TypedError) => void
): void;
function verifyEmail(
token: string,
callback?: (error?: Error | Meteor.Error | Meteor.TypedError) => void
): void;
function onEmailVerificationLink(callback: Function): void;
function onEnrollmentLink(callback: Function): void;
function onResetPasswordLink(callback: Function): void;
function loggingIn(): boolean;
function loggingOut(): boolean;
function logout(
callback?: (error?: Error | Meteor.Error | Meteor.TypedError) => void
): void;
function logoutOtherClients(
callback?: (error?: Error | Meteor.Error | Meteor.TypedError) => void
): void;
type PasswordSignupField = 'USERNAME_AND_EMAIL' | 'USERNAME_AND_OPTIONAL_EMAIL' | 'USERNAME_ONLY' | 'EMAIL_ONLY';
type PasswordlessSignupField = 'USERNAME_AND_EMAIL' | 'EMAIL_ONLY';
var ui: {
config(options: {
requestPermissions?: Record<string, string[]> | undefined;
requestOfflineToken?: Record<'google', boolean> | undefined;
forceApprovalPrompt?: Record<'google', boolean> | undefined;
passwordSignupFields?: PasswordSignupField | PasswordSignupField[] | undefined;
passwordlessSignupFields?: PasswordlessSignupField | PasswordlessSignupField[] | undefined;
}): void;
};
}
export interface Header {
[id: string]: string;
}
export interface EmailTemplates {
from: string;
siteName: string;
headers?: Header | undefined;
resetPassword: EmailFields;
enrollAccount: EmailFields;
verifyEmail: EmailFields;
}
export namespace Accounts {
var emailTemplates: EmailTemplates;
function addEmail(userId: string, newEmail: string, verified?: boolean): void;
function removeEmail(userId: string, email: string): void;
function onCreateUser(
func: (options: { profile?: {} | undefined }, user: Meteor.User) => void
): void;
function findUserByEmail(
email: string,
options?: { fields?: Mongo.FieldSpecifier | undefined }
): Meteor.User | null | undefined;
function findUserByUsername(
username: string,
options?: { fields?: Mongo.FieldSpecifier | undefined }
): Meteor.User | null | undefined;
function sendEnrollmentEmail(
userId: string,
email?: string,
extraTokenData?: Record<string, unknown>,
extraParams?: Record<string, unknown>
): void;
function sendResetPasswordEmail(
userId: string,
email?: string,
extraTokenData?: Record<string, unknown>,
extraParams?: Record<string, unknown>
): void;
function sendVerificationEmail(
userId: string,
email?: string,
extraTokenData?: Record<string, unknown>,
extraParams?: Record<string, unknown>
): void;
function setUsername(userId: string, newUsername: string): void;
function setPassword(
userId: string,
newPassword: string,
options?: { logout?: boolean | undefined }
): void;
function setPasswordAsync(
userId: string,
newPassword: string,
options?: { logout?: boolean | undefined }
): Promise<void>;
function validateNewUser(func: Function): boolean;
function validateLoginAttempt(
func: Function
): {
stop: () => void;
};
function _hashPassword(
password: string
): { digest: string; algorithm: string };
interface IValidateLoginAttemptCbOpts {
type: string;
allowed: boolean;
error: Meteor.Error;
user: Meteor.User;
connection: Meteor.Connection;
methodName: string;
methodArguments: any[];
}
}
export namespace Accounts {
function onLogout(func: Function): void;
}
export namespace Accounts {
function onLogout(
func: (options: {
user: Meteor.User;
connection: Meteor.Connection;
}) => void
): void;
}
export namespace Accounts {
interface LoginMethodOptions {
/**
* The method to call (default 'login')
*/
methodName?: string | undefined;
/**
* The arguments for the method
*/
methodArguments?: any[] | undefined;
/**
* If provided, will be called with the result of the
* method. If it throws, the client will not be logged in (and
* its error will be passed to the callback).
*/
validateResult?: Function | undefined;
/**
* Will be called with no arguments once the user is fully
* logged in, or with the error on error.
*/
userCallback?: ((err?: any) => void) | undefined;
}
/**
*
* Call a login method on the server.
*
* A login method is a method which on success calls `this.setUserId(id)` and
* `Accounts._setLoginToken` on the server and returns an object with fields
* 'id' (containing the user id), 'token' (containing a resume token), and
* optionally `tokenExpires`.
*
* This function takes care of:
* - Updating the Meteor.loggingIn() reactive data source
* - Calling the method in 'wait' mode
* - On success, saving the resume token to localStorage
* - On success, calling Accounts.connection.setUserId()
* - Setting up an onReconnect handler which logs in with
* the resume token
*
* Options:
* - methodName: The method to call (default 'login')
* - methodArguments: The arguments for the method
* - validateResult: If provided, will be called with the result of the
* method. If it throws, the client will not be logged in (and
* its error will be passed to the callback).
* - userCallback: Will be called with no arguments once the user is fully
* logged in, or with the error on error.
*
* */
function callLoginMethod(options: LoginMethodOptions): void;
type LoginMethodResult = { error: Error } | {
userId: string;
error?: Error;
stampedLoginToken?: StampedLoginToken;
options?: Record<string, any>;
};
/**
*
* The main entry point for auth packages to hook in to login.
*
* A login handler is a login method which can return `undefined` to
* indicate that the login request is not handled by this handler.
*
* @param name {String} Optional. The service name, used by default
* if a specific service name isn't returned in the result.
*
* @param handler {Function} A function that receives an options object
* (as passed as an argument to the `login` method) and returns one of:
* - `undefined`, meaning don't handle;
* - a login method result object
**/
function registerLoginHandler(
handler: (options: any) => undefined | LoginMethodResult
): void;
function registerLoginHandler(
name: string,
handler: (options: any) => undefined | LoginMethodResult
): void;
type Password =
| string
| {
digest: string;
algorithm: 'sha-256';
};
/**
*
* Check whether the provided password matches the bcrypt'ed password in
* the database user record. `password` can be a string (in which case
* it will be run through SHA256 before bcrypt) or an object with
* properties `digest` and `algorithm` (in which case we bcrypt
* `password.digest`).
*/
function _checkPassword(
user: Meteor.User,
password: Password
): { userId: string; error?: any };
}
export namespace Accounts {
type StampedLoginToken = {
token: string;
when: Date;
};
type HashedStampedLoginToken = {
hashedToken: string;
when: Date;
};
function _generateStampedLoginToken(): StampedLoginToken;
function _hashStampedToken(token: StampedLoginToken): HashedStampedLoginToken;
function _insertHashedLoginToken<T>(
userId: string,
token: HashedStampedLoginToken,
query?: Mongo.Selector<T> | Mongo.ObjectID | string
): void;
function _hashLoginToken(token: string): string;
}