@sudoplatform/sudo-common 5.9.0 → 6.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.
Files changed (166) hide show
  1. package/.eslintrc.js +2 -4
  2. package/bin/outdated-with-suppression.sh +20 -0
  3. package/bin/suppress-outdated.sh +15 -0
  4. package/dependencies-report.json +1 -1
  5. package/docs/assets/search.js +1 -1
  6. package/docs/classes/AccountLockedError.html +4 -3
  7. package/docs/classes/AuthenticationError.html +4 -3
  8. package/docs/classes/Base64.html +2 -2
  9. package/docs/classes/Buffer.html +2 -2
  10. package/docs/classes/ConfigurationNotSetError.html +4 -3
  11. package/docs/classes/ConfigurationSetNotFoundError.html +4 -3
  12. package/docs/classes/DecodeError.html +4 -3
  13. package/docs/classes/DefaultConfigurationManager.html +6 -6
  14. package/docs/classes/DefaultLogger.html +13 -7
  15. package/docs/classes/DefaultSudoKeyArchive.html +13 -13
  16. package/docs/classes/DefaultSudoKeyManager.html +31 -27
  17. package/docs/classes/FatalError.html +4 -3
  18. package/docs/classes/IllegalArgumentError.html +4 -3
  19. package/docs/classes/IllegalStateError.html +4 -3
  20. package/docs/classes/InsufficientEntitlementsError.html +4 -3
  21. package/docs/classes/InvalidOwnershipProofError.html +4 -3
  22. package/docs/classes/InvalidTokenError.html +4 -3
  23. package/docs/classes/KeyArchiveDecodingError.html +4 -3
  24. package/docs/classes/KeyArchiveIncorrectPasswordError.html +4 -3
  25. package/docs/classes/KeyArchiveMissingError.html +4 -3
  26. package/docs/classes/KeyArchiveNoPasswordRequiredError.html +4 -3
  27. package/docs/classes/KeyArchivePasswordRequiredError.html +4 -3
  28. package/docs/classes/KeyArchiveTypeError.html +4 -3
  29. package/docs/classes/KeyArchiveUnknownKeyTypeError.html +4 -3
  30. package/docs/classes/KeyArchiveVersionError.html +4 -3
  31. package/docs/classes/KeyNotFoundError.html +4 -3
  32. package/docs/classes/KeyStoreNotExportableError.html +4 -3
  33. package/docs/classes/LimitExceededError.html +4 -3
  34. package/docs/classes/NoEntitlementsError.html +4 -3
  35. package/docs/classes/NotAuthorizedError.html +4 -3
  36. package/docs/classes/NotRegisteredError.html +4 -3
  37. package/docs/classes/NotSignedInError.html +4 -3
  38. package/docs/classes/OperationNotImplementedError.html +4 -3
  39. package/docs/classes/RegisterError.html +4 -3
  40. package/docs/classes/RequestFailedError.html +6 -5
  41. package/docs/classes/ServiceError.html +4 -3
  42. package/docs/classes/SignOutError.html +4 -3
  43. package/docs/classes/SudoCryptoProviderDefaults.html +1 -1
  44. package/docs/classes/UnknownGraphQLError.html +6 -4
  45. package/docs/classes/UnrecognizedAlgorithmError.html +4 -3
  46. package/docs/classes/UserNotConfirmedError.html +4 -3
  47. package/docs/classes/VersionMismatchError.html +4 -3
  48. package/docs/enums/CachePolicy.html +2 -2
  49. package/docs/enums/EncryptionAlgorithm.html +2 -2
  50. package/docs/enums/KeyArchiveKeyType.html +2 -2
  51. package/docs/enums/KeyDataKeyFormat.html +3 -3
  52. package/docs/enums/KeyDataKeyType.html +2 -2
  53. package/docs/enums/ListOperationResultStatus.html +4 -4
  54. package/docs/enums/PublicKeyFormat.html +1 -1
  55. package/docs/index.html +1 -1
  56. package/docs/interfaces/AsymmetricEncryptionOptions.html +2 -2
  57. package/docs/interfaces/BooleanFilter.html +2 -2
  58. package/docs/interfaces/ConfigurationManager.html +5 -5
  59. package/docs/interfaces/KeyData.html +2 -2
  60. package/docs/interfaces/ListOperationFailureResult.html +2 -2
  61. package/docs/interfaces/ListOperationPartialResult.html +4 -4
  62. package/docs/interfaces/ListOperationSuccessResult.html +3 -3
  63. package/docs/interfaces/ListOutput.html +2 -2
  64. package/docs/interfaces/Logger.html +13 -7
  65. package/docs/interfaces/Owner.html +1 -1
  66. package/docs/interfaces/PublicKey.html +1 -1
  67. package/docs/interfaces/StringFilter.html +2 -2
  68. package/docs/interfaces/SudoCryptoProvider.html +39 -31
  69. package/docs/interfaces/SudoKeyArchive.html +10 -10
  70. package/docs/interfaces/SudoKeyManager.html +39 -31
  71. package/docs/interfaces/SymmetricEncryptionOptions.html +2 -2
  72. package/docs/modules.html +4 -4
  73. package/github/.eslintrc.js +2 -4
  74. package/github/bin/outdated-with-suppression.sh +20 -0
  75. package/github/bin/suppress-outdated.sh +15 -0
  76. package/github/docs/assets/search.js +1 -1
  77. package/github/docs/classes/AccountLockedError.html +4 -3
  78. package/github/docs/classes/AuthenticationError.html +4 -3
  79. package/github/docs/classes/Base64.html +2 -2
  80. package/github/docs/classes/Buffer.html +2 -2
  81. package/github/docs/classes/ConfigurationNotSetError.html +4 -3
  82. package/github/docs/classes/ConfigurationSetNotFoundError.html +4 -3
  83. package/github/docs/classes/DecodeError.html +4 -3
  84. package/github/docs/classes/DefaultConfigurationManager.html +6 -6
  85. package/github/docs/classes/DefaultLogger.html +13 -7
  86. package/github/docs/classes/DefaultSudoKeyArchive.html +13 -13
  87. package/github/docs/classes/DefaultSudoKeyManager.html +31 -27
  88. package/github/docs/classes/FatalError.html +4 -3
  89. package/github/docs/classes/IllegalArgumentError.html +4 -3
  90. package/github/docs/classes/IllegalStateError.html +4 -3
  91. package/github/docs/classes/InsufficientEntitlementsError.html +4 -3
  92. package/github/docs/classes/InvalidOwnershipProofError.html +4 -3
  93. package/github/docs/classes/InvalidTokenError.html +4 -3
  94. package/github/docs/classes/KeyArchiveDecodingError.html +4 -3
  95. package/github/docs/classes/KeyArchiveIncorrectPasswordError.html +4 -3
  96. package/github/docs/classes/KeyArchiveMissingError.html +4 -3
  97. package/github/docs/classes/KeyArchiveNoPasswordRequiredError.html +4 -3
  98. package/github/docs/classes/KeyArchivePasswordRequiredError.html +4 -3
  99. package/github/docs/classes/KeyArchiveTypeError.html +4 -3
  100. package/github/docs/classes/KeyArchiveUnknownKeyTypeError.html +4 -3
  101. package/github/docs/classes/KeyArchiveVersionError.html +4 -3
  102. package/github/docs/classes/KeyNotFoundError.html +4 -3
  103. package/github/docs/classes/KeyStoreNotExportableError.html +4 -3
  104. package/github/docs/classes/LimitExceededError.html +4 -3
  105. package/github/docs/classes/NoEntitlementsError.html +4 -3
  106. package/github/docs/classes/NotAuthorizedError.html +4 -3
  107. package/github/docs/classes/NotRegisteredError.html +4 -3
  108. package/github/docs/classes/NotSignedInError.html +4 -3
  109. package/github/docs/classes/OperationNotImplementedError.html +4 -3
  110. package/github/docs/classes/RegisterError.html +4 -3
  111. package/github/docs/classes/RequestFailedError.html +6 -5
  112. package/github/docs/classes/ServiceError.html +4 -3
  113. package/github/docs/classes/SignOutError.html +4 -3
  114. package/github/docs/classes/SudoCryptoProviderDefaults.html +1 -1
  115. package/github/docs/classes/UnknownGraphQLError.html +6 -4
  116. package/github/docs/classes/UnrecognizedAlgorithmError.html +4 -3
  117. package/github/docs/classes/UserNotConfirmedError.html +4 -3
  118. package/github/docs/classes/VersionMismatchError.html +4 -3
  119. package/github/docs/enums/CachePolicy.html +2 -2
  120. package/github/docs/enums/EncryptionAlgorithm.html +2 -2
  121. package/github/docs/enums/KeyArchiveKeyType.html +2 -2
  122. package/github/docs/enums/KeyDataKeyFormat.html +3 -3
  123. package/github/docs/enums/KeyDataKeyType.html +2 -2
  124. package/github/docs/enums/ListOperationResultStatus.html +4 -4
  125. package/github/docs/enums/PublicKeyFormat.html +1 -1
  126. package/github/docs/index.html +1 -1
  127. package/github/docs/interfaces/AsymmetricEncryptionOptions.html +2 -2
  128. package/github/docs/interfaces/BooleanFilter.html +2 -2
  129. package/github/docs/interfaces/ConfigurationManager.html +5 -5
  130. package/github/docs/interfaces/KeyData.html +2 -2
  131. package/github/docs/interfaces/ListOperationFailureResult.html +2 -2
  132. package/github/docs/interfaces/ListOperationPartialResult.html +4 -4
  133. package/github/docs/interfaces/ListOperationSuccessResult.html +3 -3
  134. package/github/docs/interfaces/ListOutput.html +2 -2
  135. package/github/docs/interfaces/Logger.html +13 -7
  136. package/github/docs/interfaces/Owner.html +1 -1
  137. package/github/docs/interfaces/PublicKey.html +1 -1
  138. package/github/docs/interfaces/StringFilter.html +2 -2
  139. package/github/docs/interfaces/SudoCryptoProvider.html +39 -31
  140. package/github/docs/interfaces/SudoKeyArchive.html +10 -10
  141. package/github/docs/interfaces/SudoKeyManager.html +39 -31
  142. package/github/docs/interfaces/SymmetricEncryptionOptions.html +2 -2
  143. package/github/docs/modules.html +4 -4
  144. package/github/package.json +13 -10
  145. package/github/src/errors/error.ts +17 -8
  146. package/github/src/logging/logger.ts +65 -6
  147. package/github/src/sudoKeyManager/sudoCryptoProvider.ts +14 -0
  148. package/github/src/sudoKeyManager/sudoKeyManager.ts +22 -0
  149. package/github/test/logging/logger.spec.ts +122 -0
  150. package/github/test/sudoKeyManager/sudoKeyManager.spec.ts +37 -0
  151. package/github/yarn.lock +566 -687
  152. package/lib/errors/error.d.ts +3 -2
  153. package/lib/errors/error.js +30 -20
  154. package/lib/logging/logger.d.ts +30 -0
  155. package/lib/logging/logger.js +12 -0
  156. package/lib/sudoKeyManager/sudoCryptoProvider.d.ts +12 -0
  157. package/lib/sudoKeyManager/sudoKeyManager.d.ts +14 -0
  158. package/lib/sudoKeyManager/sudoKeyManager.js +8 -0
  159. package/package.json +13 -10
  160. package/src/errors/error.ts +17 -8
  161. package/src/logging/logger.ts +65 -6
  162. package/src/sudoKeyManager/sudoCryptoProvider.ts +14 -0
  163. package/src/sudoKeyManager/sudoKeyManager.ts +22 -0
  164. package/test/logging/logger.spec.ts +122 -0
  165. package/test/sudoKeyManager/sudoKeyManager.spec.ts +37 -0
  166. package/yarn.lock +566 -687
@@ -9,10 +9,11 @@ export declare type AppSyncNetworkError = Error & {
9
9
  };
10
10
  export declare function isAppSyncNetworkError(u: Error): u is AppSyncNetworkError;
11
11
  /**
12
- * Indicates the GraphQL API returned an error that's not recognized by the client.
12
+ * Indicates the GraphQL API returned an error that's not recognized by
13
+ * the client.
13
14
  */
14
15
  export declare class UnknownGraphQLError extends Error {
15
- constructor(cause: AppSyncError);
16
+ constructor(cause: unknown);
16
17
  }
17
18
  /**
18
19
  * The configuration set was not found by the given key
@@ -15,16 +15,28 @@ function isAppSyncNetworkError(u) {
15
15
  return !!u.networkError;
16
16
  }
17
17
  /**
18
- * Indicates the GraphQL API returned an error that's not recognized by the client.
18
+ * Indicates the GraphQL API returned an error that's not recognized by
19
+ * the client.
19
20
  */
20
21
 
21
22
 
22
23
  class UnknownGraphQLError extends Error {
23
24
  constructor(cause) {
24
- var _cause$errorType;
25
+ const maybeAppSyncError = cause;
26
+ let message;
27
+
28
+ if (maybeAppSyncError !== null && maybeAppSyncError !== void 0 && maybeAppSyncError.errorType) {
29
+ message = `type: ${maybeAppSyncError.errorType}, message: ${maybeAppSyncError.message}`;
30
+ } else if (maybeAppSyncError !== null && maybeAppSyncError !== void 0 && maybeAppSyncError.message) {
31
+ message = maybeAppSyncError === null || maybeAppSyncError === void 0 ? void 0 : maybeAppSyncError.message;
32
+ } else if (maybeAppSyncError !== null && maybeAppSyncError !== void 0 && maybeAppSyncError.name) {
33
+ message = maybeAppSyncError.name;
34
+ } else {
35
+ message = 'unknown cause';
36
+ }
25
37
 
26
- super(`type: ${(_cause$errorType = cause.errorType) !== null && _cause$errorType !== void 0 ? _cause$errorType : '<cause type not specified>'}, message: ${cause.message}`);
27
- this.name = 'GraphQLError';
38
+ super(message);
39
+ this.name = 'UnknownGraphQLError';
28
40
  }
29
41
 
30
42
  }
@@ -129,7 +141,7 @@ exports.RegisterError = RegisterError;
129
141
 
130
142
  class NotRegisteredError extends Error {
131
143
  constructor(message) {
132
- super(message !== null && message !== void 0 ? message : 'User is not registered.');
144
+ super(message ?? 'User is not registered.');
133
145
  this.name = 'NotRegisteredError';
134
146
  }
135
147
 
@@ -144,7 +156,7 @@ exports.NotRegisteredError = NotRegisteredError;
144
156
 
145
157
  class NotAuthorizedError extends Error {
146
158
  constructor(message) {
147
- super(message !== null && message !== void 0 ? message : 'User is not authorized perform the requested operation.');
159
+ super(message ?? 'User is not authorized perform the requested operation.');
148
160
  this.name = 'NotAuthorizedError';
149
161
  }
150
162
 
@@ -264,7 +276,7 @@ exports.ServiceError = ServiceError;
264
276
 
265
277
  class IllegalArgumentError extends Error {
266
278
  constructor(message) {
267
- super(message !== null && message !== void 0 ? message : 'Invalid arguments were specified');
279
+ super(message ?? 'Invalid arguments were specified');
268
280
  this.name = 'IllegalArgumentError';
269
281
  }
270
282
 
@@ -316,9 +328,7 @@ class RequestFailedError extends Error {
316
328
  * status code.
317
329
  */
318
330
  constructor(cause, statusCode) {
319
- var _cause$message;
320
-
321
- super(`API request failed. cause: ${(_cause$message = cause === null || cause === void 0 ? void 0 : cause.message) !== null && _cause$message !== void 0 ? _cause$message : '<none>'}, statusCode: ${statusCode !== null && statusCode !== void 0 ? statusCode : '<none>'}`);
331
+ super(`API request failed. cause: ${(cause === null || cause === void 0 ? void 0 : cause.message) ?? '<none>'}, statusCode: ${statusCode ?? '<none>'}`);
322
332
 
323
333
  _defineProperty(this, "cause", void 0);
324
334
 
@@ -382,7 +392,7 @@ exports.InvalidTokenError = InvalidTokenError;
382
392
 
383
393
  class KeyNotFoundError extends Error {
384
394
  constructor(message) {
385
- super(message !== null && message !== void 0 ? message : 'Key not found.');
395
+ super(message ?? 'Key not found.');
386
396
  this.name = 'KeyNotFoundError';
387
397
  }
388
398
 
@@ -396,7 +406,7 @@ exports.KeyNotFoundError = KeyNotFoundError;
396
406
 
397
407
  class KeyStoreNotExportableError extends Error {
398
408
  constructor(message) {
399
- super(message !== null && message !== void 0 ? message : 'Key store not exportable.');
409
+ super(message ?? 'Key store not exportable.');
400
410
  this.name = 'KeyStoreNotExportableError';
401
411
  }
402
412
 
@@ -410,7 +420,7 @@ exports.KeyStoreNotExportableError = KeyStoreNotExportableError;
410
420
 
411
421
  class KeyArchiveMissingError extends Error {
412
422
  constructor(message) {
413
- super(message !== null && message !== void 0 ? message : 'No key archive provided prior to unarchiving');
423
+ super(message ?? 'No key archive provided prior to unarchiving');
414
424
  this.name = 'KeyArchiveMissingError';
415
425
  }
416
426
 
@@ -424,7 +434,7 @@ exports.KeyArchiveMissingError = KeyArchiveMissingError;
424
434
 
425
435
  class KeyArchivePasswordRequiredError extends Error {
426
436
  constructor(message) {
427
- super(message !== null && message !== void 0 ? message : 'No password provided to unarchive secure archive');
437
+ super(message ?? 'No password provided to unarchive secure archive');
428
438
  this.name = 'KeyArchivePasswordRequiredError';
429
439
  }
430
440
 
@@ -438,7 +448,7 @@ exports.KeyArchivePasswordRequiredError = KeyArchivePasswordRequiredError;
438
448
 
439
449
  class KeyArchiveNoPasswordRequiredError extends Error {
440
450
  constructor(message) {
441
- super(message !== null && message !== void 0 ? message : 'No password required to unarchive insecure archive');
451
+ super(message ?? 'No password required to unarchive insecure archive');
442
452
  this.name = 'KeyArchiveNoPasswordRequiredError';
443
453
  }
444
454
 
@@ -452,7 +462,7 @@ exports.KeyArchiveNoPasswordRequiredError = KeyArchiveNoPasswordRequiredError;
452
462
 
453
463
  class KeyArchiveDecodingError extends Error {
454
464
  constructor(message) {
455
- super(message !== null && message !== void 0 ? message : 'Key archive data could not be decoded as expected');
465
+ super(message ?? 'Key archive data could not be decoded as expected');
456
466
  this.name = 'KeyArchiveDecodingError';
457
467
  }
458
468
 
@@ -466,7 +476,7 @@ exports.KeyArchiveDecodingError = KeyArchiveDecodingError;
466
476
 
467
477
  class KeyArchiveIncorrectPasswordError extends Error {
468
478
  constructor(message) {
469
- super(message !== null && message !== void 0 ? message : 'Key archive was unable to be decrypted using the provided password');
479
+ super(message ?? 'Key archive was unable to be decrypted using the provided password');
470
480
  this.name = 'KeyArchiveIncorrectPasswordError';
471
481
  }
472
482
 
@@ -508,7 +518,7 @@ exports.KeyArchiveVersionError = KeyArchiveVersionError;
508
518
 
509
519
  class KeyArchiveUnknownKeyTypeError extends Error {
510
520
  constructor(message) {
511
- super(message !== null && message !== void 0 ? message : 'Key type is not recognized');
521
+ super(message ?? 'Key type is not recognized');
512
522
  this.name = 'KeyArchiveUnknownKeyTypeError';
513
523
  }
514
524
 
@@ -522,7 +532,7 @@ exports.KeyArchiveUnknownKeyTypeError = KeyArchiveUnknownKeyTypeError;
522
532
 
523
533
  class OperationNotImplementedError extends Error {
524
534
  constructor(message) {
525
- super(message !== null && message !== void 0 ? message : 'Operation is not implemented');
535
+ super(message ?? 'Operation is not implemented');
526
536
  this.name = 'OperationNotImplementedError';
527
537
  }
528
538
 
@@ -536,7 +546,7 @@ exports.OperationNotImplementedError = OperationNotImplementedError;
536
546
 
537
547
  class UnrecognizedAlgorithmError extends Error {
538
548
  constructor(message) {
539
- super(message !== null && message !== void 0 ? message : 'Unrecognized encryption algorithm name.');
549
+ super(message ?? 'Unrecognized encryption algorithm name.');
540
550
  this.name = 'UnrecognizedAlgorithmError';
541
551
  }
542
552
 
@@ -2,36 +2,60 @@
2
2
  * Interface encapsulating logger functions.
3
3
  */
4
4
  export interface Logger {
5
+ /**
6
+ * @returns Whether or not trace level logging is enabled
7
+ */
8
+ trace(): boolean;
5
9
  /**
6
10
  * Will log the given message with the logger implementation using the TRACE level
7
11
  * @param message the message to be logged
8
12
  * @param fields optional fields that represent an object
9
13
  */
10
14
  trace(message: string, fields?: Record<string, unknown>): void;
15
+ /**
16
+ * @returns Whether or not debug level logging is enabled
17
+ */
18
+ debug(): boolean;
11
19
  /**
12
20
  * Will log the given message with the logger implementation using the DEBUG level
13
21
  * @param message the message to be logged
14
22
  * @param fields optional fields that represent an object
15
23
  */
16
24
  debug(message: string, fields?: Record<string, unknown>): void;
25
+ /**
26
+ * @returns Whether or not info level logging is enabled
27
+ */
28
+ info(): boolean;
17
29
  /**
18
30
  * Will log the given message with the logger implementation using the INFO level
19
31
  * @param message the message to be logged
20
32
  * @param fields optional fields that represent an object
21
33
  */
22
34
  info(message: string, fields?: Record<string, unknown>): void;
35
+ /**
36
+ * @returns Whether or not warn level logging is enabled
37
+ */
38
+ warn(): boolean;
23
39
  /**
24
40
  * Will log the given message with the logger implementation using the WARN level
25
41
  * @param message the message to be logged
26
42
  * @param fields optional fields that represent an object
27
43
  */
28
44
  warn(message: string, fields?: Record<string, unknown>): void;
45
+ /**
46
+ * @returns Whether or not error level logging is enabled
47
+ */
48
+ error(): boolean;
29
49
  /**
30
50
  * Will log the given message with the logger implementation using the ERROR level
31
51
  * @param message the message to be logged
32
52
  * @param fields optional fields that represent an object
33
53
  */
34
54
  error(message: string, fields?: Record<string, unknown>): void;
55
+ /**
56
+ * @returns Whether or not fatal level logging is enabled
57
+ */
58
+ fatal(): boolean;
35
59
  /**
36
60
  * Will log the given message with the logger implementation using the FATAL level
37
61
  * @param message the message to be logged
@@ -48,10 +72,16 @@ export declare class DefaultLogger implements Logger {
48
72
  * @param logLevel the log level for the module
49
73
  */
50
74
  constructor(identifier?: string, logLevel?: string);
75
+ trace(): boolean;
51
76
  trace(message: string, fields?: Record<string, unknown>): void;
77
+ debug(): boolean;
52
78
  debug(message: string, fields?: Record<string, unknown>): void;
79
+ info(): boolean;
53
80
  info(message: string, fields?: Record<string, unknown>): void;
81
+ warn(): boolean;
54
82
  warn(message: string, fields?: Record<string, unknown>): void;
83
+ error(): boolean;
55
84
  error(message: string, fields?: Record<string, unknown>): void;
85
+ fatal(): boolean;
56
86
  fatal(message: string, fields?: Record<string, unknown>): void;
57
87
  }
@@ -23,6 +23,8 @@ class DefaultLogger {
23
23
  }
24
24
 
25
25
  trace(message, fields) {
26
+ if (message === undefined) return this.logger.trace();
27
+
26
28
  if (fields) {
27
29
  this.logger.trace({
28
30
  obj: fields
@@ -33,6 +35,8 @@ class DefaultLogger {
33
35
  }
34
36
 
35
37
  debug(message, fields) {
38
+ if (message === undefined) return this.logger.debug();
39
+
36
40
  if (fields) {
37
41
  this.logger.debug({
38
42
  obj: fields
@@ -43,6 +47,8 @@ class DefaultLogger {
43
47
  }
44
48
 
45
49
  info(message, fields) {
50
+ if (message === undefined) return this.logger.info();
51
+
46
52
  if (fields) {
47
53
  this.logger.info({
48
54
  obj: fields
@@ -53,6 +59,8 @@ class DefaultLogger {
53
59
  }
54
60
 
55
61
  warn(message, fields) {
62
+ if (message === undefined) return this.logger.warn();
63
+
56
64
  if (fields) {
57
65
  this.logger.warn({
58
66
  obj: fields
@@ -63,6 +71,8 @@ class DefaultLogger {
63
71
  }
64
72
 
65
73
  error(message, fields) {
74
+ if (message === undefined) return this.logger.error();
75
+
66
76
  if (fields) {
67
77
  this.logger.error({
68
78
  obj: fields
@@ -73,6 +83,8 @@ class DefaultLogger {
73
83
  }
74
84
 
75
85
  fatal(message, fields) {
86
+ if (message === undefined) return this.logger.fatal();
87
+
76
88
  if (fields) {
77
89
  this.logger.fatal({
78
90
  obj: fields
@@ -69,6 +69,12 @@ export interface SudoCryptoProvider {
69
69
  * @returns The symmetric key or undefined if not found.
70
70
  */
71
71
  getSymmetricKey(name: string): Promise<ArrayBuffer | undefined>;
72
+ /**
73
+ * Checks to see if the specified symmetric key exists.
74
+ *
75
+ * @param name The name of the symmetric key.
76
+ */
77
+ doesSymmetricKeyExists(name: string): Promise<boolean>;
72
78
  /**
73
79
  * Deletes a symmetric key from the secure store.
74
80
  *
@@ -122,6 +128,12 @@ export interface SudoCryptoProvider {
122
128
  * @returns Requested private key or undefined if the key was not found.
123
129
  */
124
130
  getPrivateKey(name: string): Promise<ArrayBuffer | undefined>;
131
+ /**
132
+ * Checks to see if the specified private key exists.
133
+ *
134
+ * @param name The name of the private key.
135
+ */
136
+ doesPrivateKeyExists(name: string): Promise<boolean>;
125
137
  /**
126
138
  * Adds a public key to the secure store.
127
139
  *
@@ -51,6 +51,12 @@ export interface SudoKeyManager {
51
51
  * @returns The symmetric key or undefined if not found.
52
52
  */
53
53
  getSymmetricKey(name: string): Promise<ArrayBuffer | undefined>;
54
+ /**
55
+ * Checks to see if the specified symmetric key exists.
56
+ *
57
+ * @param name The name of the symmetric key.
58
+ */
59
+ doesSymmetricKeyExists(name: string): Promise<boolean>;
54
60
  /**
55
61
  * Deletes a symmetric key from the secure store.
56
62
  *
@@ -72,6 +78,12 @@ export interface SudoKeyManager {
72
78
  * @returns Requested private key or undefined if the key was not found.
73
79
  */
74
80
  getPrivateKey(name: string): Promise<ArrayBuffer | undefined>;
81
+ /**
82
+ * Checks to see if the specified private key exists.
83
+ *
84
+ * @param name The name of the private key.
85
+ */
86
+ doesPrivateKeyExists(name: string): Promise<boolean>;
75
87
  /**
76
88
  * Adds a public key to the secure store.
77
89
  *
@@ -278,10 +290,12 @@ export declare class DefaultSudoKeyManager implements SudoKeyManager {
278
290
  updatePassword(password: ArrayBuffer, name: string): Promise<void>;
279
291
  addSymmetricKey(key: ArrayBuffer, name: string): Promise<void>;
280
292
  getSymmetricKey(name: string): Promise<ArrayBuffer | undefined>;
293
+ doesSymmetricKeyExists(name: string): Promise<boolean>;
281
294
  deleteSymmetricKey(name: string): Promise<void>;
282
295
  generateKeyPair(name: string): Promise<void>;
283
296
  addPrivateKey(key: ArrayBuffer, name: string): Promise<void>;
284
297
  getPrivateKey(name: string): Promise<ArrayBuffer | undefined>;
298
+ doesPrivateKeyExists(name: string): Promise<boolean>;
285
299
  addPublicKey(key: ArrayBuffer, name: string): Promise<void>;
286
300
  getPublicKey(name: string): Promise<PublicKey | undefined>;
287
301
  deleteKeyPair(name: string): Promise<void>;
@@ -49,6 +49,10 @@ class DefaultSudoKeyManager {
49
49
  return this.sudoCryptoProvider.getSymmetricKey(name);
50
50
  }
51
51
 
52
+ doesSymmetricKeyExists(name) {
53
+ return this.sudoCryptoProvider.doesSymmetricKeyExists(name);
54
+ }
55
+
52
56
  deleteSymmetricKey(name) {
53
57
  return this.sudoCryptoProvider.deleteSymmetricKey(name);
54
58
  }
@@ -65,6 +69,10 @@ class DefaultSudoKeyManager {
65
69
  return this.sudoCryptoProvider.getPrivateKey(name);
66
70
  }
67
71
 
72
+ doesPrivateKeyExists(name) {
73
+ return this.sudoCryptoProvider.doesPrivateKeyExists(name);
74
+ }
75
+
68
76
  addPublicKey(key, name) {
69
77
  return this.sudoCryptoProvider.addPublicKey(key, name);
70
78
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sudoplatform/sudo-common",
3
- "version": "5.9.0",
3
+ "version": "6.0.1",
4
4
  "author": "Anonyome Labs, Inc.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,6 +9,7 @@
9
9
  "license": "Apache-2.0",
10
10
  "scripts": {
11
11
  "audit-with-suppressions": "bin/yarn-audit-with-suppression.sh",
12
+ "outdated-with-suppressions": "bin/yarn-outdated-with-suppression.sh",
12
13
  "clean": "rimraf ./lib ./test-lib",
13
14
  "lint": "yarn lint:eslint && yarn lint:prettier",
14
15
  "lint:eslint": "eslint \"{bin,integration-tests,src,test}/**/*.{ts,tsx}\"",
@@ -24,7 +25,9 @@
24
25
  "types": "./lib/index.d.ts",
25
26
  "bin": {
26
27
  "audit-with-suppressions": "bin/yarn-audit-with-suppression.sh",
27
- "suppress-audit": "bin/suppress-audit.sh"
28
+ "suppress-audit": "bin/suppress-audit.sh",
29
+ "outdated-with-suppressions": "bin/yarn-outdated-with-suppression.sh",
30
+ "suppress-outdated": "bin/suppress-outdated.sh"
28
31
  },
29
32
  "files": [
30
33
  "lib",
@@ -53,23 +56,23 @@
53
56
  "@babel/preset-env": "^7.15.8",
54
57
  "@babel/preset-typescript": "^7.15.0",
55
58
  "@types/jest": "^27.0.2",
56
- "@typescript-eslint/eslint-plugin": "^4.33.0",
57
- "@typescript-eslint/parser": "^4.33.0",
58
- "eslint": "^7.32.0",
59
+ "@typescript-eslint/eslint-plugin": "^5.1.0",
60
+ "@typescript-eslint/parser": "^5.1.0",
61
+ "eslint": "^8.0.1",
59
62
  "eslint-config-prettier": "^8.3.0",
60
- "eslint-plugin-import": "^2.24.2",
63
+ "eslint-plugin-import": "^2.25.2",
61
64
  "eslint-plugin-prettier": "^4.0.0",
62
- "fp-ts": "^2.11.4",
65
+ "fp-ts": "^2.11.5",
63
66
  "io-ts": "^2.2.16",
64
67
  "io-ts-types": "^0.5.16",
65
68
  "isomorphic-webcrypto": "^2.3.8",
66
- "jest": "^27.2.4",
69
+ "jest": "^27.3.1",
67
70
  "monocle-ts": "^2.3.11",
68
71
  "newtype-ts": "^0.3.2",
69
72
  "prettier": "^2.4.1",
70
73
  "rimraf": "^3.0.2",
71
74
  "ts-mockito": "^2.6.1",
72
- "typedoc": "^0.22.5",
73
- "typescript": "^4.4.3"
75
+ "typedoc": "^0.22.6",
76
+ "typescript": "^4.4.4"
74
77
  }
75
78
  }
@@ -16,16 +16,25 @@ export function isAppSyncNetworkError(u: Error): u is AppSyncNetworkError {
16
16
  }
17
17
 
18
18
  /**
19
- * Indicates the GraphQL API returned an error that's not recognized by the client.
19
+ * Indicates the GraphQL API returned an error that's not recognized by
20
+ * the client.
20
21
  */
21
22
  export class UnknownGraphQLError extends Error {
22
- constructor(cause: AppSyncError) {
23
- super(
24
- `type: ${cause.errorType ?? '<cause type not specified>'}, message: ${
25
- cause.message
26
- }`,
27
- )
28
- this.name = 'GraphQLError'
23
+ constructor(cause: unknown) {
24
+ const maybeAppSyncError = cause as AppSyncError
25
+ let message: string
26
+ if (maybeAppSyncError?.errorType) {
27
+ message = `type: ${maybeAppSyncError.errorType}, message: ${maybeAppSyncError.message}`
28
+ } else if (maybeAppSyncError?.message) {
29
+ message = maybeAppSyncError?.message
30
+ } else if (maybeAppSyncError?.name) {
31
+ message = maybeAppSyncError.name
32
+ } else {
33
+ message = 'unknown cause'
34
+ }
35
+ super(message)
36
+
37
+ this.name = 'UnknownGraphQLError'
29
38
  }
30
39
  }
31
40
 
@@ -4,36 +4,71 @@ import { BunyanLogger, createBunyanLogger } from './bunyanLogger'
4
4
  * Interface encapsulating logger functions.
5
5
  */
6
6
  export interface Logger {
7
+ /**
8
+ * @returns Whether or not trace level logging is enabled
9
+ */
10
+ trace(): boolean
11
+
7
12
  /**
8
13
  * Will log the given message with the logger implementation using the TRACE level
9
14
  * @param message the message to be logged
10
15
  * @param fields optional fields that represent an object
11
16
  */
12
17
  trace(message: string, fields?: Record<string, unknown>): void
18
+
19
+ /**
20
+ * @returns Whether or not debug level logging is enabled
21
+ */
22
+ debug(): boolean
23
+
13
24
  /**
14
25
  * Will log the given message with the logger implementation using the DEBUG level
15
26
  * @param message the message to be logged
16
27
  * @param fields optional fields that represent an object
17
28
  */
18
29
  debug(message: string, fields?: Record<string, unknown>): void
30
+
31
+ /**
32
+ * @returns Whether or not info level logging is enabled
33
+ */
34
+ info(): boolean
35
+
19
36
  /**
20
37
  * Will log the given message with the logger implementation using the INFO level
21
38
  * @param message the message to be logged
22
39
  * @param fields optional fields that represent an object
23
40
  */
24
41
  info(message: string, fields?: Record<string, unknown>): void
42
+
43
+ /**
44
+ * @returns Whether or not warn level logging is enabled
45
+ */
46
+ warn(): boolean
47
+
25
48
  /**
26
49
  * Will log the given message with the logger implementation using the WARN level
27
50
  * @param message the message to be logged
28
51
  * @param fields optional fields that represent an object
29
52
  */
30
53
  warn(message: string, fields?: Record<string, unknown>): void
54
+
55
+ /**
56
+ * @returns Whether or not error level logging is enabled
57
+ */
58
+ error(): boolean
59
+
31
60
  /**
32
61
  * Will log the given message with the logger implementation using the ERROR level
33
62
  * @param message the message to be logged
34
63
  * @param fields optional fields that represent an object
35
64
  */
36
65
  error(message: string, fields?: Record<string, unknown>): void
66
+
67
+ /**
68
+ * @returns Whether or not fatal level logging is enabled
69
+ */
70
+ fatal(): boolean
71
+
37
72
  /**
38
73
  * Will log the given message with the logger implementation using the FATAL level
39
74
  * @param message the message to be logged
@@ -55,7 +90,11 @@ export class DefaultLogger implements Logger {
55
90
  this.logger = createBunyanLogger(identifier, logLevel)
56
91
  }
57
92
 
58
- trace(message: string, fields?: Record<string, unknown>): void {
93
+ trace(): boolean
94
+ trace(message: string, fields?: Record<string, unknown>): void
95
+ trace(message?: string, fields?: Record<string, unknown>): boolean | void {
96
+ if (message === undefined) return this.logger.trace()
97
+
59
98
  if (fields) {
60
99
  this.logger.trace({ obj: fields }, message)
61
100
  } else {
@@ -63,7 +102,11 @@ export class DefaultLogger implements Logger {
63
102
  }
64
103
  }
65
104
 
66
- debug(message: string, fields?: Record<string, unknown>): void {
105
+ debug(): boolean
106
+ debug(message: string, fields?: Record<string, unknown>): void
107
+ debug(message?: string, fields?: Record<string, unknown>): boolean | void {
108
+ if (message === undefined) return this.logger.debug()
109
+
67
110
  if (fields) {
68
111
  this.logger.debug({ obj: fields }, message)
69
112
  } else {
@@ -71,7 +114,11 @@ export class DefaultLogger implements Logger {
71
114
  }
72
115
  }
73
116
 
74
- info(message: string, fields?: Record<string, unknown>): void {
117
+ info(): boolean
118
+ info(message: string, fields?: Record<string, unknown>): void
119
+ info(message?: string, fields?: Record<string, unknown>): boolean | void {
120
+ if (message === undefined) return this.logger.info()
121
+
75
122
  if (fields) {
76
123
  this.logger.info({ obj: fields }, message)
77
124
  } else {
@@ -79,7 +126,11 @@ export class DefaultLogger implements Logger {
79
126
  }
80
127
  }
81
128
 
82
- warn(message: string, fields?: Record<string, unknown>): void {
129
+ warn(): boolean
130
+ warn(message: string, fields?: Record<string, unknown>): void
131
+ warn(message?: string, fields?: Record<string, unknown>): boolean | void {
132
+ if (message === undefined) return this.logger.warn()
133
+
83
134
  if (fields) {
84
135
  this.logger.warn({ obj: fields }, message)
85
136
  } else {
@@ -87,7 +138,11 @@ export class DefaultLogger implements Logger {
87
138
  }
88
139
  }
89
140
 
90
- error(message: string, fields?: Record<string, unknown>): void {
141
+ error(): boolean
142
+ error(message: string, fields?: Record<string, unknown>): void
143
+ error(message?: string, fields?: Record<string, unknown>): boolean | void {
144
+ if (message === undefined) return this.logger.error()
145
+
91
146
  if (fields) {
92
147
  this.logger.error({ obj: fields }, message)
93
148
  } else {
@@ -95,7 +150,11 @@ export class DefaultLogger implements Logger {
95
150
  }
96
151
  }
97
152
 
98
- fatal(message: string, fields?: Record<string, unknown>): void {
153
+ fatal(): boolean
154
+ fatal(message: string, fields?: Record<string, unknown>): void
155
+ fatal(message?: string, fields?: Record<string, unknown>): boolean | void {
156
+ if (message === undefined) return this.logger.fatal()
157
+
99
158
  if (fields) {
100
159
  this.logger.fatal({ obj: fields }, message)
101
160
  } else {
@@ -85,6 +85,13 @@ export interface SudoCryptoProvider {
85
85
  */
86
86
  getSymmetricKey(name: string): Promise<ArrayBuffer | undefined>
87
87
 
88
+ /**
89
+ * Checks to see if the specified symmetric key exists.
90
+ *
91
+ * @param name The name of the symmetric key.
92
+ */
93
+ doesSymmetricKeyExists(name: string): Promise<boolean>
94
+
88
95
  /**
89
96
  * Deletes a symmetric key from the secure store.
90
97
  *
@@ -147,6 +154,13 @@ export interface SudoCryptoProvider {
147
154
  */
148
155
  getPrivateKey(name: string): Promise<ArrayBuffer | undefined>
149
156
 
157
+ /**
158
+ * Checks to see if the specified private key exists.
159
+ *
160
+ * @param name The name of the private key.
161
+ */
162
+ doesPrivateKeyExists(name: string): Promise<boolean>
163
+
150
164
  /**
151
165
  * Adds a public key to the secure store.
152
166
  *