@vardario/cognito-client 4.0.1 → 4.0.3

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/error.d.ts CHANGED
@@ -362,8 +362,10 @@ export declare enum RevokeTokenException {
362
362
  UnsupportedOperationException = "UnsupportedOperationException",
363
363
  UnsupportedTokenTypeException = "UnsupportedTokenTypeException"
364
364
  }
365
+ export type CognitoErrorType = 'CommonError' | 'InitAuthError' | 'RespondToAuthChallengeError' | 'SignUpError' | 'ConfirmSignUpError' | 'ChangePasswordError' | 'RevokeTokenError' | 'ForgotPasswordError' | 'ConfirmForgotPasswordError' | 'ResendConfirmationCodeError' | 'UpdateUserAttributesError' | 'VerifyUserAttributeError' | 'GlobalSignOutError';
365
366
  export declare class CognitoError extends Error {
366
- constructor(message: string);
367
+ readonly errorType: CognitoErrorType;
368
+ constructor(message: string, errorType: CognitoErrorType);
367
369
  }
368
370
  export declare class CommonError extends CognitoError {
369
371
  readonly cognitoException: CommonException;
package/lib/error.js CHANGED
@@ -401,85 +401,86 @@ export var RevokeTokenException;
401
401
  RevokeTokenException["UnsupportedTokenTypeException"] = "UnsupportedTokenTypeException";
402
402
  })(RevokeTokenException || (RevokeTokenException = {}));
403
403
  export class CognitoError extends Error {
404
- constructor(message) {
404
+ constructor(message, errorType) {
405
405
  super(message);
406
+ this.errorType = errorType;
406
407
  }
407
408
  }
408
409
  export class CommonError extends CognitoError {
409
410
  constructor(message, cognitoException) {
410
- super(message);
411
+ super(message, 'CommonError');
411
412
  this.cognitoException = cognitoException;
412
413
  }
413
414
  }
414
415
  export class InitAuthError extends CognitoError {
415
416
  constructor(message, cognitoException) {
416
- super(message);
417
+ super(message, 'InitAuthError');
417
418
  this.cognitoException = cognitoException;
418
419
  }
419
420
  }
420
421
  export class RespondToAuthChallengeError extends CognitoError {
421
422
  constructor(message, cognitoException) {
422
- super(message);
423
+ super(message, 'RespondToAuthChallengeError');
423
424
  this.cognitoException = cognitoException;
424
425
  }
425
426
  }
426
427
  export class SignUpError extends CognitoError {
427
428
  constructor(message, cognitoException) {
428
- super(message);
429
+ super(message, 'SignUpError');
429
430
  this.cognitoException = cognitoException;
430
431
  }
431
432
  }
432
433
  export class ConfirmSignUpError extends CognitoError {
433
434
  constructor(message, cognitoException) {
434
- super(message);
435
+ super(message, 'ConfirmSignUpError');
435
436
  this.cognitoException = cognitoException;
436
437
  }
437
438
  }
438
439
  export class ChangePasswordError extends CognitoError {
439
440
  constructor(message, cognitoException) {
440
- super(message);
441
+ super(message, 'ChangePasswordError');
441
442
  this.cognitoException = cognitoException;
442
443
  }
443
444
  }
444
445
  export class RevokeTokenError extends CognitoError {
445
446
  constructor(message, cognitoException) {
446
- super(message);
447
+ super(message, 'RevokeTokenError');
447
448
  this.cognitoException = cognitoException;
448
449
  }
449
450
  }
450
451
  export class ForgotPasswordError extends CognitoError {
451
452
  constructor(message, cognitoException) {
452
- super(message);
453
+ super(message, 'ForgotPasswordError');
453
454
  this.cognitoException = cognitoException;
454
455
  }
455
456
  }
456
457
  export class ConfirmForgotPasswordError extends CognitoError {
457
458
  constructor(message, cognitoException) {
458
- super(message);
459
+ super(message, 'ConfirmForgotPasswordError');
459
460
  this.cognitoException = cognitoException;
460
461
  }
461
462
  }
462
463
  export class ResendConfirmationCodeError extends CognitoError {
463
464
  constructor(message, cognitoException) {
464
- super(message);
465
+ super(message, 'ResendConfirmationCodeError');
465
466
  this.cognitoException = cognitoException;
466
467
  }
467
468
  }
468
469
  export class UpdateUserAttributesError extends CognitoError {
469
470
  constructor(message, cognitoException) {
470
- super(message);
471
+ super(message, 'UpdateUserAttributesError');
471
472
  this.cognitoException = cognitoException;
472
473
  }
473
474
  }
474
475
  export class VerifyUserAttributeError extends CognitoError {
475
476
  constructor(message, cognitoException) {
476
- super(message);
477
+ super(message, 'VerifyUserAttributeError');
477
478
  this.cognitoException = cognitoException;
478
479
  }
479
480
  }
480
481
  export class GlobalSignOutError extends CognitoError {
481
482
  constructor(message, cognitoException) {
482
- super(message);
483
+ super(message, 'GlobalSignOutError');
483
484
  this.cognitoException = cognitoException;
484
485
  }
485
486
  }
package/lib/utils.js CHANGED
@@ -2,11 +2,7 @@ import hashJs from 'hash.js';
2
2
  import { BigInteger } from 'jsbn';
3
3
  import { Buffer } from 'buffer';
4
4
  import formatInTimeZone from 'date-fns-tz/formatInTimeZone';
5
- let crypto = globalThis.crypto;
6
- if (!crypto) {
7
- const nodeCrypto = await import('node:crypto');
8
- crypto = nodeCrypto.webcrypto;
9
- }
5
+ import { random } from '@lukeed/csprng';
10
6
  const initN = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1' +
11
7
  '29024E088A67CC74020BBEA63B139B22514A08798E3404DD' +
12
8
  'EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245' +
@@ -118,7 +114,7 @@ export function decodeJwt(jwt) {
118
114
  };
119
115
  }
120
116
  export async function randomBytes(num) {
121
- return Buffer.from(crypto.getRandomValues(new Uint8Array(num)));
117
+ return random(num);
122
118
  }
123
119
  export function formatTimestamp(date) {
124
120
  return formatInTimeZone(date, 'UTC', "EEE MMM d HH:mm:ss 'UTC' yyyy");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vardario/cognito-client",
3
- "version": "4.0.1",
3
+ "version": "4.0.3",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "author": "Sahin Vardar",
@@ -22,6 +22,7 @@
22
22
  "watch": "tsc --build --watch"
23
23
  },
24
24
  "dependencies": {
25
+ "@lukeed/csprng": "^1.1.0",
25
26
  "buffer": "^6.0.3",
26
27
  "date-fns-tz": "^2.0.0",
27
28
  "hash.js": "^1.1.7",