@vardario/cognito-client 4.0.0 → 4.0.1

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.
@@ -1,7 +1,7 @@
1
1
  import hashJs from 'hash.js';
2
2
  import { BigInteger } from 'jsbn';
3
3
  import { Buffer } from 'buffer';
4
- import { ChangePasswordError, ConfirmForgotPasswordError, ConfirmSignUpError, ForgotPasswordError, GlobalSignOutError, InitAuthError, ResendConfirmationCodeError, RespondToAuthChallengeError, RevokeTokenError, SignUpError, UpdateUserAttributesError, VerifyUserAttributeError } from './error.js';
4
+ import { ChangePasswordError, ConfirmForgotPasswordError, ConfirmSignUpError, ForgotPasswordError, GlobalSignOutError, InitAuthError, ResendConfirmationCodeError, RespondToAuthChallengeError, RevokeTokenError, SignUpError, UpdateUserAttributesError, VerifyUserAttributeError, COMMON_EXCEPTIONS, CommonError } from './error.js';
5
5
  import { calculateSecretHash, calculateSignature, calculateU, decodeJwt, generateA, generateSmallA, getPasswordAuthenticationKey, randomBytes } from './utils.js';
6
6
  /**
7
7
  * List of used and supported Cognito API calls.
@@ -74,6 +74,9 @@ export async function cognitoRequest(body, serviceTarget, cognitoEndpoint) {
74
74
  cognitoResponseBody.code ??
75
75
  cognitoResponseBody.__type ??
76
76
  'Unknown');
77
+ if (COMMON_EXCEPTIONS.includes(cognitoException)) {
78
+ throw new CommonError(errorMessage, cognitoException);
79
+ }
77
80
  switch (serviceTarget) {
78
81
  case ServiceTarget.InitiateAuth:
79
82
  throw new InitAuthError(errorMessage, cognitoException);
package/lib/error.d.ts CHANGED
@@ -1,3 +1,17 @@
1
+ export declare enum CommonException {
2
+ AccessDeniedException = "AccessDeniedException",
3
+ IncompleteSignature = "IncompleteSignature",
4
+ InternalFailure = "InternalFailure",
5
+ InvalidAction = "InvalidAction",
6
+ InvalidClientTokenId = "InvalidClientTokenId",
7
+ NotAuthorized = "NotAuthorized",
8
+ OptInRequired = "OptInRequired",
9
+ RequestExpired = "RequestExpired",
10
+ ServiceUnavailable = "ServiceUnavailable",
11
+ ThrottlingException = "ThrottlingException",
12
+ ValidationError = "ValidationError"
13
+ }
14
+ export declare const COMMON_EXCEPTIONS: CommonException[];
1
15
  export declare enum AssociateSoftwareTokenException {
2
16
  ConcurrentModificationException = "ConcurrentModificationException",
3
17
  ForbiddenException = "ForbiddenException",
@@ -348,51 +362,58 @@ export declare enum RevokeTokenException {
348
362
  UnsupportedOperationException = "UnsupportedOperationException",
349
363
  UnsupportedTokenTypeException = "UnsupportedTokenTypeException"
350
364
  }
351
- export declare class InitAuthError extends Error {
365
+ export declare class CognitoError extends Error {
366
+ constructor(message: string);
367
+ }
368
+ export declare class CommonError extends CognitoError {
369
+ readonly cognitoException: CommonException;
370
+ constructor(message: string, cognitoException: CommonException);
371
+ }
372
+ export declare class InitAuthError extends CognitoError {
352
373
  readonly cognitoException: InitiateAuthException;
353
374
  constructor(message: string, cognitoException: InitiateAuthException);
354
375
  }
355
- export declare class RespondToAuthChallengeError extends Error {
376
+ export declare class RespondToAuthChallengeError extends CognitoError {
356
377
  readonly cognitoException: RespondToAuthChallengeException;
357
378
  constructor(message: string, cognitoException: RespondToAuthChallengeException);
358
379
  }
359
- export declare class SignUpError extends Error {
380
+ export declare class SignUpError extends CognitoError {
360
381
  readonly cognitoException: SignUpException;
361
382
  constructor(message: string, cognitoException: SignUpException);
362
383
  }
363
- export declare class ConfirmSignUpError extends Error {
384
+ export declare class ConfirmSignUpError extends CognitoError {
364
385
  readonly cognitoException: ConfirmSignUpException;
365
386
  constructor(message: string, cognitoException: ConfirmSignUpException);
366
387
  }
367
- export declare class ChangePasswordError extends Error {
388
+ export declare class ChangePasswordError extends CognitoError {
368
389
  readonly cognitoException: ChangePasswordException;
369
390
  constructor(message: string, cognitoException: ChangePasswordException);
370
391
  }
371
- export declare class RevokeTokenError extends Error {
392
+ export declare class RevokeTokenError extends CognitoError {
372
393
  readonly cognitoException: RevokeTokenException;
373
394
  constructor(message: string, cognitoException: RevokeTokenException);
374
395
  }
375
- export declare class ForgotPasswordError extends Error {
396
+ export declare class ForgotPasswordError extends CognitoError {
376
397
  readonly cognitoException: ForgotPasswordException;
377
398
  constructor(message: string, cognitoException: ForgotPasswordException);
378
399
  }
379
- export declare class ConfirmForgotPasswordError extends Error {
400
+ export declare class ConfirmForgotPasswordError extends CognitoError {
380
401
  readonly cognitoException: ConfirmForgotPasswordException;
381
402
  constructor(message: string, cognitoException: ConfirmForgotPasswordException);
382
403
  }
383
- export declare class ResendConfirmationCodeError extends Error {
404
+ export declare class ResendConfirmationCodeError extends CognitoError {
384
405
  readonly cognitoException: ResendConfirmationException;
385
406
  constructor(message: string, cognitoException: ResendConfirmationException);
386
407
  }
387
- export declare class UpdateUserAttributesError extends Error {
408
+ export declare class UpdateUserAttributesError extends CognitoError {
388
409
  readonly cognitoException: UpdateUserAttributesException;
389
410
  constructor(message: string, cognitoException: UpdateUserAttributesException);
390
411
  }
391
- export declare class VerifyUserAttributeError extends Error {
412
+ export declare class VerifyUserAttributeError extends CognitoError {
392
413
  readonly cognitoException: VerifyUserAttributeException;
393
414
  constructor(message: string, cognitoException: VerifyUserAttributeException);
394
415
  }
395
- export declare class GlobalSignOutError extends Error {
416
+ export declare class GlobalSignOutError extends CognitoError {
396
417
  readonly cognitoException: GlobalSignOutException;
397
418
  constructor(message: string, cognitoException: GlobalSignOutException);
398
419
  }
package/lib/error.js CHANGED
@@ -1,3 +1,30 @@
1
+ export var CommonException;
2
+ (function (CommonException) {
3
+ CommonException["AccessDeniedException"] = "AccessDeniedException";
4
+ CommonException["IncompleteSignature"] = "IncompleteSignature";
5
+ CommonException["InternalFailure"] = "InternalFailure";
6
+ CommonException["InvalidAction"] = "InvalidAction";
7
+ CommonException["InvalidClientTokenId"] = "InvalidClientTokenId";
8
+ CommonException["NotAuthorized"] = "NotAuthorized";
9
+ CommonException["OptInRequired"] = "OptInRequired";
10
+ CommonException["RequestExpired"] = "RequestExpired";
11
+ CommonException["ServiceUnavailable"] = "ServiceUnavailable";
12
+ CommonException["ThrottlingException"] = "ThrottlingException";
13
+ CommonException["ValidationError"] = "ValidationError";
14
+ })(CommonException || (CommonException = {}));
15
+ export const COMMON_EXCEPTIONS = [
16
+ CommonException.AccessDeniedException,
17
+ CommonException.IncompleteSignature,
18
+ CommonException.InternalFailure,
19
+ CommonException.InvalidAction,
20
+ CommonException.InvalidClientTokenId,
21
+ CommonException.NotAuthorized,
22
+ CommonException.OptInRequired,
23
+ CommonException.RequestExpired,
24
+ CommonException.ServiceUnavailable,
25
+ CommonException.ThrottlingException,
26
+ CommonException.ValidationError
27
+ ];
1
28
  export var AssociateSoftwareTokenException;
2
29
  (function (AssociateSoftwareTokenException) {
3
30
  AssociateSoftwareTokenException["ConcurrentModificationException"] = "ConcurrentModificationException";
@@ -373,73 +400,84 @@ export var RevokeTokenException;
373
400
  RevokeTokenException["UnsupportedOperationException"] = "UnsupportedOperationException";
374
401
  RevokeTokenException["UnsupportedTokenTypeException"] = "UnsupportedTokenTypeException";
375
402
  })(RevokeTokenException || (RevokeTokenException = {}));
376
- export class InitAuthError extends Error {
403
+ export class CognitoError extends Error {
404
+ constructor(message) {
405
+ super(message);
406
+ }
407
+ }
408
+ export class CommonError extends CognitoError {
409
+ constructor(message, cognitoException) {
410
+ super(message);
411
+ this.cognitoException = cognitoException;
412
+ }
413
+ }
414
+ export class InitAuthError extends CognitoError {
377
415
  constructor(message, cognitoException) {
378
416
  super(message);
379
417
  this.cognitoException = cognitoException;
380
418
  }
381
419
  }
382
- export class RespondToAuthChallengeError extends Error {
420
+ export class RespondToAuthChallengeError extends CognitoError {
383
421
  constructor(message, cognitoException) {
384
422
  super(message);
385
423
  this.cognitoException = cognitoException;
386
424
  }
387
425
  }
388
- export class SignUpError extends Error {
426
+ export class SignUpError extends CognitoError {
389
427
  constructor(message, cognitoException) {
390
428
  super(message);
391
429
  this.cognitoException = cognitoException;
392
430
  }
393
431
  }
394
- export class ConfirmSignUpError extends Error {
432
+ export class ConfirmSignUpError extends CognitoError {
395
433
  constructor(message, cognitoException) {
396
434
  super(message);
397
435
  this.cognitoException = cognitoException;
398
436
  }
399
437
  }
400
- export class ChangePasswordError extends Error {
438
+ export class ChangePasswordError extends CognitoError {
401
439
  constructor(message, cognitoException) {
402
440
  super(message);
403
441
  this.cognitoException = cognitoException;
404
442
  }
405
443
  }
406
- export class RevokeTokenError extends Error {
444
+ export class RevokeTokenError extends CognitoError {
407
445
  constructor(message, cognitoException) {
408
446
  super(message);
409
447
  this.cognitoException = cognitoException;
410
448
  }
411
449
  }
412
- export class ForgotPasswordError extends Error {
450
+ export class ForgotPasswordError extends CognitoError {
413
451
  constructor(message, cognitoException) {
414
452
  super(message);
415
453
  this.cognitoException = cognitoException;
416
454
  }
417
455
  }
418
- export class ConfirmForgotPasswordError extends Error {
456
+ export class ConfirmForgotPasswordError extends CognitoError {
419
457
  constructor(message, cognitoException) {
420
458
  super(message);
421
459
  this.cognitoException = cognitoException;
422
460
  }
423
461
  }
424
- export class ResendConfirmationCodeError extends Error {
462
+ export class ResendConfirmationCodeError extends CognitoError {
425
463
  constructor(message, cognitoException) {
426
464
  super(message);
427
465
  this.cognitoException = cognitoException;
428
466
  }
429
467
  }
430
- export class UpdateUserAttributesError extends Error {
468
+ export class UpdateUserAttributesError extends CognitoError {
431
469
  constructor(message, cognitoException) {
432
470
  super(message);
433
471
  this.cognitoException = cognitoException;
434
472
  }
435
473
  }
436
- export class VerifyUserAttributeError extends Error {
474
+ export class VerifyUserAttributeError extends CognitoError {
437
475
  constructor(message, cognitoException) {
438
476
  super(message);
439
477
  this.cognitoException = cognitoException;
440
478
  }
441
479
  }
442
- export class GlobalSignOutError extends Error {
480
+ export class GlobalSignOutError extends CognitoError {
443
481
  constructor(message, cognitoException) {
444
482
  super(message);
445
483
  this.cognitoException = cognitoException;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vardario/cognito-client",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "author": "Sahin Vardar",