1 | declare module 'amazon-cognito-identity-js' {
|
2 |
|
3 |
|
4 | export type NodeCallback<E, T> = (err?: E, result?: T) => void;
|
5 | export type UpdateAttributesNodeCallback<E, T, K> = (
|
6 | err?: E,
|
7 | result?: T,
|
8 | details?: K
|
9 | ) => void;
|
10 | export namespace NodeCallback {
|
11 | export type Any = NodeCallback<Error | undefined, any>;
|
12 | }
|
13 |
|
14 | export interface CodeDeliveryDetails {
|
15 | AttributeName: string;
|
16 | DeliveryMedium: string;
|
17 | Destination: string;
|
18 | }
|
19 |
|
20 | export type ClientMetadata = { [key: string]: string } | undefined;
|
21 |
|
22 | export interface IAuthenticationCallback {
|
23 | onSuccess: (
|
24 | session: CognitoUserSession,
|
25 | userConfirmationNecessary?: boolean
|
26 | ) => void;
|
27 | onFailure: (err: any) => void;
|
28 | newPasswordRequired?: (
|
29 | userAttributes: any,
|
30 | requiredAttributes: any
|
31 | ) => void;
|
32 | mfaRequired?: (
|
33 | challengeName: ChallengeName,
|
34 | challengeParameters: any
|
35 | ) => void;
|
36 | totpRequired?: (
|
37 | challengeName: ChallengeName,
|
38 | challengeParameters: any
|
39 | ) => void;
|
40 | customChallenge?: (challengeParameters: any) => void;
|
41 | mfaSetup?: (challengeName: ChallengeName, challengeParameters: any) => void;
|
42 | selectMFAType?: (
|
43 | challengeName: ChallengeName,
|
44 | challengeParameters: any
|
45 | ) => void;
|
46 | }
|
47 |
|
48 | export interface IMfaSettings {
|
49 | PreferredMfa: boolean;
|
50 | Enabled: boolean;
|
51 | }
|
52 | export interface IAuthenticationDetailsData {
|
53 | Username: string;
|
54 | Password?: string;
|
55 | ValidationData?: { [key: string]: any };
|
56 | ClientMetadata?: ClientMetadata;
|
57 | }
|
58 |
|
59 | export class AuthenticationDetails {
|
60 | constructor(data: IAuthenticationDetailsData);
|
61 |
|
62 | public getUsername(): string;
|
63 | public getPassword(): string;
|
64 | public getValidationData(): any[];
|
65 | }
|
66 |
|
67 | export interface ICognitoStorage {
|
68 | setItem(key: string, value: string): void;
|
69 | getItem(key: string): string | null;
|
70 | removeItem(key: string): void;
|
71 | clear(): void;
|
72 | }
|
73 |
|
74 | export interface ICognitoUserData {
|
75 | Username: string;
|
76 | Pool: CognitoUserPool;
|
77 | Storage?: ICognitoStorage;
|
78 | }
|
79 |
|
80 | export interface GetSessionOptions {
|
81 | clientMetadata: Record<string, string>;
|
82 | }
|
83 |
|
84 | export type ChallengeName =
|
85 | | 'CUSTOM_CHALLENGE'
|
86 | | 'MFA_SETUP'
|
87 | | 'NEW_PASSWORD_REQUIRED'
|
88 | | 'SELECT_MFA_TYPE'
|
89 | | 'SMS_MFA'
|
90 | | 'SOFTWARE_TOKEN_MFA';
|
91 |
|
92 | export class CognitoUser {
|
93 | constructor(data: ICognitoUserData);
|
94 |
|
95 | challengeName?: ChallengeName;
|
96 |
|
97 | public setSignInUserSession(signInUserSession: CognitoUserSession): void;
|
98 | public getSignInUserSession(): CognitoUserSession | null;
|
99 | public getUsername(): string;
|
100 |
|
101 | public getAuthenticationFlowType(): string;
|
102 | public setAuthenticationFlowType(authenticationFlowType: string): string;
|
103 | public getCachedDeviceKeyAndPassword(): void;
|
104 |
|
105 | public getSession(
|
106 | callback:
|
107 | | ((error: Error, session: null) => void)
|
108 | | ((error: null, session: CognitoUserSession) => void),
|
109 | options?: GetSessionOptions
|
110 | ): void;
|
111 | public refreshSession(
|
112 | refreshToken: CognitoRefreshToken,
|
113 | callback: NodeCallback<any, any>,
|
114 | clientMetadata?: ClientMetadata
|
115 | ): void;
|
116 | public authenticateUser(
|
117 | authenticationDetails: AuthenticationDetails,
|
118 | callbacks: IAuthenticationCallback
|
119 | ): void;
|
120 | public initiateAuth(
|
121 | authenticationDetails: AuthenticationDetails,
|
122 | callbacks: IAuthenticationCallback
|
123 | ): void;
|
124 | public confirmRegistration(
|
125 | code: string,
|
126 | forceAliasCreation: boolean,
|
127 | callback: NodeCallback<any, any>,
|
128 | clientMetadata?: ClientMetadata
|
129 | ): void;
|
130 | public sendCustomChallengeAnswer(
|
131 | answerChallenge: any,
|
132 | callback: IAuthenticationCallback,
|
133 | clientMetaData?: ClientMetadata
|
134 | ): void;
|
135 | public resendConfirmationCode(
|
136 | callback: NodeCallback<Error, any>,
|
137 | clientMetaData?: ClientMetadata
|
138 | ): void;
|
139 | public changePassword(
|
140 | oldPassword: string,
|
141 | newPassword: string,
|
142 | callback: NodeCallback<Error, 'SUCCESS'>,
|
143 | clientMetadata?: ClientMetadata
|
144 | ): void;
|
145 | public forgotPassword(
|
146 | callbacks: {
|
147 | onSuccess: (data: any) => void;
|
148 | onFailure: (err: Error) => void;
|
149 | inputVerificationCode?: (data: any) => void;
|
150 | },
|
151 | clientMetaData?: ClientMetadata
|
152 | ): void;
|
153 | public confirmPassword(
|
154 | verificationCode: string,
|
155 | newPassword: string,
|
156 | callbacks: {
|
157 | onSuccess: (success: string) => void;
|
158 | onFailure: (err: Error) => void;
|
159 | },
|
160 | clientMetaData?: ClientMetadata
|
161 | ): void;
|
162 | public setDeviceStatusRemembered(callbacks: {
|
163 | onSuccess: (success: string) => void;
|
164 | onFailure: (err: any) => void;
|
165 | }): void;
|
166 | public setDeviceStatusNotRemembered(callbacks: {
|
167 | onSuccess: (success: string) => void;
|
168 | onFailure: (err: any) => void;
|
169 | }): void;
|
170 | public getDevice(callbacks: {
|
171 | onSuccess: (success: string) => void;
|
172 | onFailure: (err: Error) => void;
|
173 | }): any;
|
174 | public forgetDevice(callbacks: {
|
175 | onSuccess: (success: string) => void;
|
176 | onFailure: (err: Error) => void;
|
177 | }): void;
|
178 | public forgetSpecificDevice(
|
179 | deviceKey: string,
|
180 | callbacks: {
|
181 | onSuccess: (success: string) => void;
|
182 | onFailure: (err: Error) => void;
|
183 | }
|
184 | ): void;
|
185 | public sendMFACode(
|
186 | confirmationCode: string,
|
187 | callbacks: {
|
188 | onSuccess: (
|
189 | session: CognitoUserSession,
|
190 | userConfirmationNecessary?: boolean
|
191 | ) => void;
|
192 | onFailure: (err: any) => void;
|
193 | },
|
194 | mfaType?: string,
|
195 | clientMetadata?: ClientMetadata
|
196 | ): void;
|
197 | public listDevices(
|
198 | limit: number,
|
199 | paginationToken: string | null,
|
200 | callbacks: {
|
201 | onSuccess: (data: any) => void;
|
202 | onFailure: (err: Error) => void;
|
203 | }
|
204 | ): void;
|
205 | public completeNewPasswordChallenge(
|
206 | newPassword: string,
|
207 | requiredAttributeData: any,
|
208 | callbacks: IAuthenticationCallback,
|
209 | clientMetadata?: ClientMetadata
|
210 | ): void;
|
211 | public signOut(callback?: () => void): void;
|
212 | public globalSignOut(callbacks: {
|
213 | onSuccess: (msg: string) => void;
|
214 | onFailure: (err: Error) => void;
|
215 | }): void;
|
216 | public verifyAttribute(
|
217 | attributeName: string,
|
218 | confirmationCode: string,
|
219 | callbacks: {
|
220 | onSuccess: (success: string) => void;
|
221 | onFailure: (err: Error) => void;
|
222 | }
|
223 | ): void;
|
224 | public getUserAttributes(
|
225 | callback: NodeCallback<Error, CognitoUserAttribute[]>
|
226 | ): void;
|
227 | public updateAttributes(
|
228 | attributes: (CognitoUserAttribute | ICognitoUserAttributeData)[],
|
229 | callback: UpdateAttributesNodeCallback<Error, string, any>,
|
230 | clientMetadata?: ClientMetadata
|
231 | ): void;
|
232 | public deleteAttributes(
|
233 | attributeList: string[],
|
234 | callback: NodeCallback<Error, string>
|
235 | ): void;
|
236 | public getAttributeVerificationCode(
|
237 | name: string,
|
238 | callback: {
|
239 | onSuccess: (success: string) => void;
|
240 | onFailure: (err: Error) => void;
|
241 | inputVerificationCode?: (data: string) => void | null;
|
242 | },
|
243 | clientMetadata?: ClientMetadata
|
244 | ): void;
|
245 | public deleteUser(callback: NodeCallback<Error, string>): void;
|
246 | public enableMFA(callback: NodeCallback<Error, string>): void;
|
247 | public disableMFA(callback: NodeCallback<Error, string>): void;
|
248 | public getMFAOptions(callback: NodeCallback<Error, MFAOption[]>): void;
|
249 | public getUserData(
|
250 | callback: NodeCallback<Error, UserData>,
|
251 | params?: any
|
252 | ): void;
|
253 | public associateSoftwareToken(callbacks: {
|
254 | associateSecretCode: (secretCode: string) => void;
|
255 | onFailure: (err: any) => void;
|
256 | }): void;
|
257 | public verifySoftwareToken(
|
258 | totpCode: string,
|
259 | friendlyDeviceName: string,
|
260 | callbacks: {
|
261 | onSuccess: (session: CognitoUserSession) => void;
|
262 | onFailure: (err: Error) => void;
|
263 | }
|
264 | ): void;
|
265 | public setUserMfaPreference(
|
266 | smsMfaSettings: IMfaSettings | null,
|
267 | softwareTokenMfaSettings: IMfaSettings | null,
|
268 | callback: NodeCallback<Error, string>
|
269 | ): void;
|
270 | public sendMFASelectionAnswer(
|
271 | answerChallenge: string,
|
272 | callbacks: {
|
273 | onSuccess: (session: CognitoUserSession) => void;
|
274 | onFailure: (err: any) => void;
|
275 | mfaRequired?: (
|
276 | challengeName: ChallengeName,
|
277 | challengeParameters: any
|
278 | ) => void;
|
279 | totpRequired?: (
|
280 | challengeName: ChallengeName,
|
281 | challengeParameters: any
|
282 | ) => void;
|
283 | }
|
284 | ): void;
|
285 | }
|
286 |
|
287 | export interface MFAOption {
|
288 | DeliveryMedium: 'SMS' | 'EMAIL';
|
289 | AttributeName: string;
|
290 | }
|
291 |
|
292 | export interface UserData {
|
293 | MFAOptions: MFAOption[];
|
294 | PreferredMfaSetting: string;
|
295 | UserAttributes: ICognitoUserAttributeData[];
|
296 | UserMFASettingList: string[];
|
297 | Username: string;
|
298 | }
|
299 |
|
300 | export interface ICognitoUserAttributeData {
|
301 | Name: string;
|
302 | Value: string;
|
303 | }
|
304 |
|
305 | export class CognitoUserAttribute implements ICognitoUserAttributeData {
|
306 | constructor(data: ICognitoUserAttributeData);
|
307 |
|
308 | Name: string;
|
309 | Value: string;
|
310 |
|
311 | public getValue(): string;
|
312 | public setValue(value: string): CognitoUserAttribute;
|
313 | public getName(): string;
|
314 | public setName(name: string): CognitoUserAttribute;
|
315 | public toString(): string;
|
316 | public toJSON(): Object;
|
317 | }
|
318 |
|
319 | export interface ISignUpResult {
|
320 | user: CognitoUser;
|
321 | userConfirmed: boolean;
|
322 | userSub: string;
|
323 | codeDeliveryDetails: CodeDeliveryDetails;
|
324 | }
|
325 |
|
326 | export interface ICognitoUserPoolData {
|
327 | UserPoolId: string;
|
328 | ClientId: string;
|
329 | endpoint?: string;
|
330 | Storage?: ICognitoStorage;
|
331 | AdvancedSecurityDataCollectionFlag?: boolean;
|
332 | }
|
333 |
|
334 | export class CognitoUserPool {
|
335 | constructor(
|
336 | data: ICognitoUserPoolData,
|
337 | wrapRefreshSessionCallback?: (
|
338 | target: NodeCallback.Any
|
339 | ) => NodeCallback.Any
|
340 | );
|
341 |
|
342 | public getUserPoolId(): string;
|
343 | public getUserPoolName(): string;
|
344 | public getClientId(): string;
|
345 |
|
346 | public signUp(
|
347 | username: string,
|
348 | password: string,
|
349 | userAttributes: CognitoUserAttribute[],
|
350 | validationData: CognitoUserAttribute[],
|
351 | callback: NodeCallback<Error, ISignUpResult>,
|
352 | clientMetadata?: ClientMetadata
|
353 | ): void;
|
354 |
|
355 | public getCurrentUser(): CognitoUser | null;
|
356 | }
|
357 |
|
358 | export interface ICognitoUserSessionData {
|
359 | IdToken: CognitoIdToken;
|
360 | AccessToken: CognitoAccessToken;
|
361 | RefreshToken?: CognitoRefreshToken;
|
362 | }
|
363 |
|
364 | export class CognitoUserSession {
|
365 | constructor(data: ICognitoUserSessionData);
|
366 |
|
367 | public getIdToken(): CognitoIdToken;
|
368 | public getRefreshToken(): CognitoRefreshToken;
|
369 | public getAccessToken(): CognitoAccessToken;
|
370 | public isValid(): boolean;
|
371 | }
|
372 | /*
|
373 | export class CognitoIdentityServiceProvider {
|
374 | public config: AWS.CognitoIdentityServiceProvider.Types.ClientConfiguration;
|
375 | }
|
376 | */
|
377 | export class CognitoAccessToken {
|
378 | payload: { [key: string]: any };
|
379 |
|
380 | constructor({ AccessToken }: { AccessToken: string });
|
381 |
|
382 | public getJwtToken(): string;
|
383 | public getExpiration(): number;
|
384 | public getIssuedAt(): number;
|
385 | public decodePayload(): { [id: string]: any };
|
386 | }
|
387 |
|
388 | export class CognitoIdToken {
|
389 | payload: { [key: string]: any };
|
390 |
|
391 | constructor({ IdToken }: { IdToken: string });
|
392 |
|
393 | public getJwtToken(): string;
|
394 | public getExpiration(): number;
|
395 | public getIssuedAt(): number;
|
396 | public decodePayload(): { [id: string]: any };
|
397 | }
|
398 |
|
399 | export class CognitoRefreshToken {
|
400 | constructor({ RefreshToken }: { RefreshToken: string });
|
401 |
|
402 | public getToken(): string;
|
403 | }
|
404 |
|
405 | export interface ICookieStorageData {
|
406 | domain?: string;
|
407 | path?: string;
|
408 | expires?: number;
|
409 | secure?: boolean;
|
410 | sameSite?: 'strict' | 'lax' | 'none';
|
411 | }
|
412 | export class CookieStorage implements ICognitoStorage {
|
413 | constructor(data?: ICookieStorageData);
|
414 | setItem(key: string, value: string): void;
|
415 | getItem(key: string): string;
|
416 | removeItem(key: string): void;
|
417 | clear(): void;
|
418 | }
|
419 |
|
420 | export class UserAgent {
|
421 | constructor();
|
422 | }
|
423 |
|
424 | export const appendToCognitoUserAgent: (content: string) => void;
|
425 |
|
426 | export class WordArray {
|
427 | constructor(words?: string[], sigBytes?: number);
|
428 | random(nBytes: number): WordArray;
|
429 | toString(): string;
|
430 | }
|
431 | }
|