@vardario/cognito-client 5.0.0 → 5.2.0
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.
- package/lib/browser.js +332 -72
- package/lib/cognito-client.d.ts +176 -17
- package/lib/cognito-client.js +165 -11
- package/lib/error.d.ts +15 -3
- package/lib/error.js +38 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/utils.d.ts +6 -1
- package/lib/utils.js +56 -0
- package/package.json +7 -7
package/lib/error.js
CHANGED
|
@@ -401,6 +401,8 @@ export var RevokeTokenException;
|
|
|
401
401
|
RevokeTokenException["UnsupportedTokenTypeException"] = "UnsupportedTokenTypeException";
|
|
402
402
|
})(RevokeTokenException || (RevokeTokenException = {}));
|
|
403
403
|
export class CognitoError extends Error {
|
|
404
|
+
errorType;
|
|
405
|
+
cognitoException;
|
|
404
406
|
constructor(message, errorType, cognitoException) {
|
|
405
407
|
super(message);
|
|
406
408
|
this.errorType = errorType;
|
|
@@ -408,92 +410,128 @@ export class CognitoError extends Error {
|
|
|
408
410
|
}
|
|
409
411
|
}
|
|
410
412
|
export class CommonError extends CognitoError {
|
|
413
|
+
cognitoException;
|
|
411
414
|
constructor(message, cognitoException) {
|
|
412
415
|
super(message, 'CommonError', cognitoException);
|
|
413
416
|
this.cognitoException = cognitoException;
|
|
414
417
|
}
|
|
415
418
|
}
|
|
416
419
|
export class InitAuthError extends CognitoError {
|
|
420
|
+
cognitoException;
|
|
417
421
|
constructor(message, cognitoException) {
|
|
418
422
|
super(message, 'InitAuthError', cognitoException);
|
|
419
423
|
this.cognitoException = cognitoException;
|
|
420
424
|
}
|
|
421
425
|
}
|
|
422
426
|
export class RespondToAuthChallengeError extends CognitoError {
|
|
427
|
+
cognitoException;
|
|
423
428
|
constructor(message, cognitoException) {
|
|
424
429
|
super(message, 'RespondToAuthChallengeError', cognitoException);
|
|
425
430
|
this.cognitoException = cognitoException;
|
|
426
431
|
}
|
|
427
432
|
}
|
|
428
433
|
export class SignUpError extends CognitoError {
|
|
434
|
+
cognitoException;
|
|
429
435
|
constructor(message, cognitoException) {
|
|
430
436
|
super(message, 'SignUpError', cognitoException);
|
|
431
437
|
this.cognitoException = cognitoException;
|
|
432
438
|
}
|
|
433
439
|
}
|
|
434
440
|
export class ConfirmSignUpError extends CognitoError {
|
|
441
|
+
cognitoException;
|
|
435
442
|
constructor(message, cognitoException) {
|
|
436
443
|
super(message, 'ConfirmSignUpError', cognitoException);
|
|
437
444
|
this.cognitoException = cognitoException;
|
|
438
445
|
}
|
|
439
446
|
}
|
|
440
447
|
export class ChangePasswordError extends CognitoError {
|
|
448
|
+
cognitoException;
|
|
441
449
|
constructor(message, cognitoException) {
|
|
442
450
|
super(message, 'ChangePasswordError', cognitoException);
|
|
443
451
|
this.cognitoException = cognitoException;
|
|
444
452
|
}
|
|
445
453
|
}
|
|
446
454
|
export class RevokeTokenError extends CognitoError {
|
|
455
|
+
cognitoException;
|
|
447
456
|
constructor(message, cognitoException) {
|
|
448
457
|
super(message, 'RevokeTokenError', cognitoException);
|
|
449
458
|
this.cognitoException = cognitoException;
|
|
450
459
|
}
|
|
451
460
|
}
|
|
452
461
|
export class ForgotPasswordError extends CognitoError {
|
|
462
|
+
cognitoException;
|
|
453
463
|
constructor(message, cognitoException) {
|
|
454
464
|
super(message, 'ForgotPasswordError', cognitoException);
|
|
455
465
|
this.cognitoException = cognitoException;
|
|
456
466
|
}
|
|
457
467
|
}
|
|
458
468
|
export class ConfirmForgotPasswordError extends CognitoError {
|
|
469
|
+
cognitoException;
|
|
459
470
|
constructor(message, cognitoException) {
|
|
460
471
|
super(message, 'ConfirmForgotPasswordError', cognitoException);
|
|
461
472
|
this.cognitoException = cognitoException;
|
|
462
473
|
}
|
|
463
474
|
}
|
|
464
475
|
export class ResendConfirmationCodeError extends CognitoError {
|
|
476
|
+
cognitoException;
|
|
465
477
|
constructor(message, cognitoException) {
|
|
466
478
|
super(message, 'ResendConfirmationCodeError', cognitoException);
|
|
467
479
|
this.cognitoException = cognitoException;
|
|
468
480
|
}
|
|
469
481
|
}
|
|
470
482
|
export class UpdateUserAttributesError extends CognitoError {
|
|
483
|
+
cognitoException;
|
|
471
484
|
constructor(message, cognitoException) {
|
|
472
485
|
super(message, 'UpdateUserAttributesError', cognitoException);
|
|
473
486
|
this.cognitoException = cognitoException;
|
|
474
487
|
}
|
|
475
488
|
}
|
|
476
489
|
export class VerifyUserAttributeError extends CognitoError {
|
|
490
|
+
cognitoException;
|
|
477
491
|
constructor(message, cognitoException) {
|
|
478
492
|
super(message, 'VerifyUserAttributeError', cognitoException);
|
|
479
493
|
this.cognitoException = cognitoException;
|
|
480
494
|
}
|
|
481
495
|
}
|
|
482
496
|
export class GlobalSignOutError extends CognitoError {
|
|
497
|
+
cognitoException;
|
|
483
498
|
constructor(message, cognitoException) {
|
|
484
499
|
super(message, 'GlobalSignOutError', cognitoException);
|
|
485
500
|
this.cognitoException = cognitoException;
|
|
486
501
|
}
|
|
487
502
|
}
|
|
488
503
|
export class VerifySoftwareTokenError extends CognitoError {
|
|
504
|
+
cognitoException;
|
|
489
505
|
constructor(message, cognitoException) {
|
|
490
506
|
super(message, 'VerifySoftwareTokenError', cognitoException);
|
|
491
507
|
this.cognitoException = cognitoException;
|
|
492
508
|
}
|
|
493
509
|
}
|
|
494
510
|
export class AssociateSoftwareTokenError extends CognitoError {
|
|
511
|
+
cognitoException;
|
|
495
512
|
constructor(message, cognitoException) {
|
|
496
513
|
super(message, 'AssociateSoftwareTokenError', cognitoException);
|
|
497
514
|
this.cognitoException = cognitoException;
|
|
498
515
|
}
|
|
499
516
|
}
|
|
517
|
+
export class SetUserMFAPreferenceError extends CognitoError {
|
|
518
|
+
cognitoException;
|
|
519
|
+
constructor(message, cognitoException) {
|
|
520
|
+
super(message, 'SetUserMFAPreferenceError', cognitoException);
|
|
521
|
+
this.cognitoException = cognitoException;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
export class ListDevicesError extends CognitoError {
|
|
525
|
+
cognitoException;
|
|
526
|
+
constructor(message, cognitoException) {
|
|
527
|
+
super(message, 'ListDevicesError', cognitoException);
|
|
528
|
+
this.cognitoException = cognitoException;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
export class GetUserError extends CognitoError {
|
|
532
|
+
cognitoException;
|
|
533
|
+
constructor(message, cognitoException) {
|
|
534
|
+
super(message, 'GetUserError', cognitoException);
|
|
535
|
+
this.cognitoException = cognitoException;
|
|
536
|
+
}
|
|
537
|
+
}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
package/lib/utils.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
3
|
export declare function uint8ArrayFromHexString(hexString: string): Uint8Array;
|
|
3
4
|
export declare function uint8ArrayFromString(str: string): Uint8Array;
|
|
4
5
|
export declare function uint8ArrayFromBase64String(str: string): Uint8Array;
|
|
5
6
|
export declare function uint8ArrayToHexString(bytes: Uint8Array): string;
|
|
6
|
-
export declare function uint8ArrayToBase64String(bytes: Uint8Array): string;
|
|
7
|
+
export declare function uint8ArrayToBase64String(bytes: Uint8Array | ArrayBuffer): string;
|
|
8
|
+
export declare function uint8ArrayToBase64UrlString(bytes: Uint8Array | ArrayBuffer | undefined): string | undefined;
|
|
9
|
+
export declare function base64UrlToUint8Array(base64: string): Uint8Array;
|
|
10
|
+
export declare function publicKeyCredentialToJSON(cred: any): any;
|
|
7
11
|
export declare function padHex(bigInt: bigint): string;
|
|
8
12
|
export declare function hashHexString(str: string): Promise<string>;
|
|
9
13
|
export declare function hashBuffer(buffer: Uint8Array): Promise<string>;
|
|
@@ -27,3 +31,4 @@ export declare function formatTimestamp(date: Date): string;
|
|
|
27
31
|
export declare function calculateSecretHash(clientSecret: string, userPoolClientId: string, username: string): Promise<string>;
|
|
28
32
|
export declare function digest(algorithm: AlgorithmIdentifier, data: Uint8Array): Promise<Uint8Array>;
|
|
29
33
|
export declare function hmac(algorithm: AlgorithmIdentifier, key: Uint8Array, data: Uint8Array): Promise<Uint8Array>;
|
|
34
|
+
export declare function removeUndefined(obj: any): any;
|
package/lib/utils.js
CHANGED
|
@@ -20,8 +20,49 @@ export function uint8ArrayToHexString(bytes) {
|
|
|
20
20
|
return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');
|
|
21
21
|
}
|
|
22
22
|
export function uint8ArrayToBase64String(bytes) {
|
|
23
|
+
if (bytes instanceof ArrayBuffer) {
|
|
24
|
+
const byteArray = new Uint8Array(bytes);
|
|
25
|
+
return btoa(String.fromCharCode(...byteArray));
|
|
26
|
+
}
|
|
23
27
|
return btoa(String.fromCharCode(...bytes));
|
|
24
28
|
}
|
|
29
|
+
export function uint8ArrayToBase64UrlString(bytes) {
|
|
30
|
+
if (bytes === undefined) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
const base64String = uint8ArrayToBase64String(bytes);
|
|
34
|
+
return base64String.replaceAll('+', '-').replaceAll('/', '_').replace(/=+$/, '');
|
|
35
|
+
}
|
|
36
|
+
export function base64UrlToUint8Array(base64) {
|
|
37
|
+
const binary = atob(base64.replace(/-/g, '+').replace(/_/g, '/'));
|
|
38
|
+
const len = binary.length;
|
|
39
|
+
const bytes = new Uint8Array(len);
|
|
40
|
+
for (let i = 0; i < len; i++) {
|
|
41
|
+
bytes[i] = binary.charCodeAt(i);
|
|
42
|
+
}
|
|
43
|
+
return bytes;
|
|
44
|
+
}
|
|
45
|
+
export function publicKeyCredentialToJSON(cred) {
|
|
46
|
+
return removeUndefined({
|
|
47
|
+
authenticatorAttachment: cred.authenticatorAttachment,
|
|
48
|
+
clientExtensionResults: cred.getClientExtensionResults(),
|
|
49
|
+
id: cred.id,
|
|
50
|
+
rawId: uint8ArrayToBase64UrlString(cred.rawId),
|
|
51
|
+
response: {
|
|
52
|
+
attestationObject: uint8ArrayToBase64UrlString(cred.response.attestationObject),
|
|
53
|
+
authenticatorData: cred.response.authenticatorData
|
|
54
|
+
? uint8ArrayToBase64UrlString(cred.response.authenticatorData)
|
|
55
|
+
: undefined,
|
|
56
|
+
clientDataJSON: uint8ArrayToBase64UrlString(cred.response.clientDataJSON),
|
|
57
|
+
publicKey: cred.response.getPublicKey ? uint8ArrayToBase64UrlString(cred.response.getPublicKey()) : undefined,
|
|
58
|
+
publicKeyAlgorithm: cred.response.getPublicKeyAlgorithm ? cred.response.getPublicKeyAlgorithm() : undefined,
|
|
59
|
+
transports: cred.response.getTransports ? cred.response.getTransports() : undefined,
|
|
60
|
+
signature: cred.response.signature ? uint8ArrayToBase64UrlString(cred.response.signature) : undefined,
|
|
61
|
+
userHandle: cred.response.userHandle ? uint8ArrayToBase64UrlString(cred.response.userHandle) : undefined
|
|
62
|
+
},
|
|
63
|
+
type: cred.type
|
|
64
|
+
});
|
|
65
|
+
}
|
|
25
66
|
const N = BigInt('0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1' +
|
|
26
67
|
'29024E088A67CC74020BBEA63B139B22514A08798E3404DD' +
|
|
27
68
|
'EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245' +
|
|
@@ -151,3 +192,18 @@ export async function hmac(algorithm, key, data) {
|
|
|
151
192
|
const signature = await crypto.subtle.sign('HMAC', cryptoKey, data);
|
|
152
193
|
return new Uint8Array(signature);
|
|
153
194
|
}
|
|
195
|
+
export function removeUndefined(obj) {
|
|
196
|
+
if (Array.isArray(obj)) {
|
|
197
|
+
return obj.map(item => removeUndefined(item)).filter(item => item !== undefined);
|
|
198
|
+
}
|
|
199
|
+
if (obj !== null && typeof obj === 'object') {
|
|
200
|
+
return Object.entries(obj).reduce((acc, [key, value]) => {
|
|
201
|
+
const cleaned = removeUndefined(value);
|
|
202
|
+
if (cleaned !== undefined) {
|
|
203
|
+
acc[key] = cleaned;
|
|
204
|
+
}
|
|
205
|
+
return acc;
|
|
206
|
+
}, {});
|
|
207
|
+
}
|
|
208
|
+
return obj !== undefined ? obj : undefined;
|
|
209
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vardario/cognito-client",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Sahin Vardar",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@aws-sdk/client-cognito-identity-provider": "^3.465.0",
|
|
29
29
|
"@types/jsdom": "^21.1.5",
|
|
30
|
-
"@types/node": "^
|
|
30
|
+
"@types/node": "^24",
|
|
31
31
|
"@typescript-eslint/eslint-plugin": "^6.11.0",
|
|
32
32
|
"@typescript-eslint/parser": "^6.11.0",
|
|
33
33
|
"esbuild": "^0.25.8",
|
|
@@ -36,15 +36,15 @@
|
|
|
36
36
|
"eslint-plugin-unused-imports": "^4.1.4",
|
|
37
37
|
"husky": "^8.0.3",
|
|
38
38
|
"isomorphic-fetch": "^3.0.0",
|
|
39
|
-
"jsdom": "^
|
|
40
|
-
"lint-staged": "^
|
|
39
|
+
"jsdom": "^26.1.0",
|
|
40
|
+
"lint-staged": "^16.1.4",
|
|
41
41
|
"prettier": "^3.1.0",
|
|
42
42
|
"prettier-package-json": "^2.8.0",
|
|
43
|
-
"semantic-release": "^
|
|
44
|
-
"testcontainers": "^
|
|
43
|
+
"semantic-release": "^24.2.7",
|
|
44
|
+
"testcontainers": "^11.5.1",
|
|
45
45
|
"tsx": "^4.7.1",
|
|
46
46
|
"typescript": "^5.2.2",
|
|
47
|
-
"vitest": "^
|
|
47
|
+
"vitest": "^3.2.4",
|
|
48
48
|
"vitest-fetch-mock": "^0.2.2"
|
|
49
49
|
},
|
|
50
50
|
"lint-staged": {
|