@sudoplatform/sudo-common 5.6.0 → 5.9.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.
Files changed (197) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/bin/yarn-audit-with-suppression.sh +1 -1
  3. package/dependencies-report.json +2 -2
  4. package/docs/.nojekyll +1 -0
  5. package/docs/assets/highlight.css +57 -0
  6. package/docs/assets/icons.css +1043 -0
  7. package/docs/assets/{images/icons.png → icons.png} +0 -0
  8. package/docs/assets/{images/icons@2x.png → icons@2x.png} +0 -0
  9. package/docs/assets/main.js +52 -0
  10. package/docs/assets/search.js +1 -0
  11. package/docs/assets/style.css +1384 -0
  12. package/docs/assets/{images/widgets.png → widgets.png} +0 -0
  13. package/docs/assets/{images/widgets@2x.png → widgets@2x.png} +0 -0
  14. package/docs/classes/AccountLockedError.html +7 -332
  15. package/docs/classes/AuthenticationError.html +8 -339
  16. package/docs/classes/Base64.html +3 -283
  17. package/docs/classes/Buffer.html +3 -324
  18. package/docs/classes/ConfigurationNotSetError.html +8 -333
  19. package/docs/classes/ConfigurationSetNotFoundError.html +7 -338
  20. package/docs/classes/DecodeError.html +7 -338
  21. package/docs/classes/DefaultConfigurationManager.html +18 -333
  22. package/docs/classes/DefaultLogger.html +19 -417
  23. package/docs/classes/DefaultSudoKeyArchive.html +61 -598
  24. package/docs/classes/DefaultSudoKeyManager.html +60 -1110
  25. package/docs/classes/FatalError.html +8 -339
  26. package/docs/classes/IllegalArgumentError.html +7 -338
  27. package/docs/classes/IllegalStateError.html +8 -339
  28. package/docs/classes/InsufficientEntitlementsError.html +8 -333
  29. package/docs/classes/InvalidOwnershipProofError.html +7 -332
  30. package/docs/classes/InvalidTokenError.html +7 -332
  31. package/docs/classes/KeyArchiveDecodingError.html +7 -338
  32. package/docs/classes/KeyArchiveIncorrectPasswordError.html +7 -338
  33. package/docs/classes/KeyArchiveMissingError.html +7 -338
  34. package/docs/classes/KeyArchiveNoPasswordRequiredError.html +7 -338
  35. package/docs/classes/KeyArchivePasswordRequiredError.html +7 -338
  36. package/docs/classes/KeyArchiveTypeError.html +7 -338
  37. package/docs/classes/KeyArchiveUnknownKeyTypeError.html +7 -338
  38. package/docs/classes/KeyArchiveVersionError.html +7 -338
  39. package/docs/classes/KeyNotFoundError.html +7 -338
  40. package/docs/classes/KeyStoreNotExportableError.html +7 -338
  41. package/docs/classes/LimitExceededError.html +8 -333
  42. package/docs/classes/NoEntitlementsError.html +7 -332
  43. package/docs/classes/NotAuthorizedError.html +8 -339
  44. package/docs/classes/NotRegisteredError.html +7 -338
  45. package/docs/classes/NotSignedInError.html +8 -333
  46. package/docs/classes/OperationNotImplementedError.html +7 -338
  47. package/docs/classes/RegisterError.html +8 -339
  48. package/docs/classes/RequestFailedError.html +12 -380
  49. package/docs/classes/ServiceError.html +9 -340
  50. package/docs/classes/SignOutError.html +7 -338
  51. package/docs/classes/SudoCryptoProviderDefaults.html +1 -224
  52. package/docs/classes/UnknownGraphQLError.html +7 -338
  53. package/docs/classes/UnrecognizedAlgorithmError.html +7 -0
  54. package/docs/classes/UserNotConfirmedError.html +8 -333
  55. package/docs/classes/VersionMismatchError.html +10 -335
  56. package/docs/enums/CachePolicy.html +4 -170
  57. package/docs/enums/EncryptionAlgorithm.html +5 -171
  58. package/docs/enums/KeyArchiveKeyType.html +4 -198
  59. package/docs/enums/KeyDataKeyFormat.html +18 -202
  60. package/docs/enums/KeyDataKeyType.html +3 -197
  61. package/docs/enums/ListOperationResultStatus.html +10 -0
  62. package/docs/enums/PublicKeyFormat.html +1 -162
  63. package/docs/index.html +14 -369
  64. package/docs/interfaces/AsymmetricEncryptionOptions.html +3 -163
  65. package/docs/interfaces/BooleanFilter.html +3 -177
  66. package/docs/interfaces/ConfigurationManager.html +37 -349
  67. package/docs/interfaces/KeyData.html +8 -236
  68. package/docs/interfaces/ListOperationFailureResult.html +5 -0
  69. package/docs/interfaces/ListOperationPartialResult.html +10 -0
  70. package/docs/interfaces/ListOperationSuccessResult.html +7 -0
  71. package/docs/interfaces/ListOutput.html +3 -185
  72. package/docs/interfaces/Logger.html +39 -401
  73. package/docs/interfaces/Owner.html +1 -170
  74. package/docs/interfaces/PublicKey.html +1 -170
  75. package/docs/interfaces/StringFilter.html +3 -191
  76. package/docs/interfaces/SudoCryptoProvider.html +172 -1305
  77. package/docs/interfaces/SudoKeyArchive.html +54 -490
  78. package/docs/interfaces/SudoKeyManager.html +167 -1298
  79. package/docs/interfaces/SymmetricEncryptionOptions.html +3 -177
  80. package/docs/modules.html +33 -895
  81. package/github/CHANGELOG.md +5 -1
  82. package/github/bin/yarn-audit-with-suppression.sh +1 -1
  83. package/github/docs/.nojekyll +1 -0
  84. package/github/docs/assets/highlight.css +57 -0
  85. package/github/docs/assets/icons.css +1043 -0
  86. package/github/docs/assets/{images/icons.png → icons.png} +0 -0
  87. package/github/docs/assets/{images/icons@2x.png → icons@2x.png} +0 -0
  88. package/github/docs/assets/main.js +52 -0
  89. package/github/docs/assets/search.js +1 -0
  90. package/github/docs/assets/style.css +1384 -0
  91. package/github/docs/assets/{images/widgets.png → widgets.png} +0 -0
  92. package/github/docs/assets/{images/widgets@2x.png → widgets@2x.png} +0 -0
  93. package/github/docs/classes/AccountLockedError.html +7 -332
  94. package/github/docs/classes/AuthenticationError.html +8 -339
  95. package/github/docs/classes/Base64.html +3 -283
  96. package/github/docs/classes/Buffer.html +3 -324
  97. package/github/docs/classes/ConfigurationNotSetError.html +8 -333
  98. package/github/docs/classes/ConfigurationSetNotFoundError.html +7 -338
  99. package/github/docs/classes/DecodeError.html +7 -338
  100. package/github/docs/classes/DefaultConfigurationManager.html +18 -333
  101. package/github/docs/classes/DefaultLogger.html +19 -417
  102. package/github/docs/classes/DefaultSudoKeyArchive.html +61 -598
  103. package/github/docs/classes/DefaultSudoKeyManager.html +60 -1110
  104. package/github/docs/classes/FatalError.html +8 -339
  105. package/github/docs/classes/IllegalArgumentError.html +7 -338
  106. package/github/docs/classes/IllegalStateError.html +8 -339
  107. package/github/docs/classes/InsufficientEntitlementsError.html +8 -333
  108. package/github/docs/classes/InvalidOwnershipProofError.html +7 -332
  109. package/github/docs/classes/InvalidTokenError.html +7 -332
  110. package/github/docs/classes/KeyArchiveDecodingError.html +7 -338
  111. package/github/docs/classes/KeyArchiveIncorrectPasswordError.html +7 -338
  112. package/github/docs/classes/KeyArchiveMissingError.html +7 -338
  113. package/github/docs/classes/KeyArchiveNoPasswordRequiredError.html +7 -338
  114. package/github/docs/classes/KeyArchivePasswordRequiredError.html +7 -338
  115. package/github/docs/classes/KeyArchiveTypeError.html +7 -338
  116. package/github/docs/classes/KeyArchiveUnknownKeyTypeError.html +7 -338
  117. package/github/docs/classes/KeyArchiveVersionError.html +7 -338
  118. package/github/docs/classes/KeyNotFoundError.html +7 -338
  119. package/github/docs/classes/KeyStoreNotExportableError.html +7 -338
  120. package/github/docs/classes/LimitExceededError.html +8 -333
  121. package/github/docs/classes/NoEntitlementsError.html +7 -332
  122. package/github/docs/classes/NotAuthorizedError.html +8 -339
  123. package/github/docs/classes/NotRegisteredError.html +7 -338
  124. package/github/docs/classes/NotSignedInError.html +8 -333
  125. package/github/docs/classes/OperationNotImplementedError.html +7 -338
  126. package/github/docs/classes/RegisterError.html +8 -339
  127. package/github/docs/classes/RequestFailedError.html +12 -380
  128. package/github/docs/classes/ServiceError.html +9 -340
  129. package/github/docs/classes/SignOutError.html +7 -338
  130. package/github/docs/classes/SudoCryptoProviderDefaults.html +1 -224
  131. package/github/docs/classes/UnknownGraphQLError.html +7 -338
  132. package/github/docs/classes/UnrecognizedAlgorithmError.html +7 -0
  133. package/github/docs/classes/UserNotConfirmedError.html +8 -333
  134. package/github/docs/classes/VersionMismatchError.html +10 -335
  135. package/github/docs/enums/CachePolicy.html +4 -170
  136. package/github/docs/enums/EncryptionAlgorithm.html +5 -171
  137. package/github/docs/enums/KeyArchiveKeyType.html +4 -198
  138. package/github/docs/enums/KeyDataKeyFormat.html +18 -202
  139. package/github/docs/enums/KeyDataKeyType.html +3 -197
  140. package/github/docs/enums/ListOperationResultStatus.html +10 -0
  141. package/github/docs/enums/PublicKeyFormat.html +1 -162
  142. package/github/docs/index.html +14 -369
  143. package/github/docs/interfaces/AsymmetricEncryptionOptions.html +3 -163
  144. package/github/docs/interfaces/BooleanFilter.html +3 -177
  145. package/github/docs/interfaces/ConfigurationManager.html +37 -349
  146. package/github/docs/interfaces/KeyData.html +8 -236
  147. package/github/docs/interfaces/ListOperationFailureResult.html +5 -0
  148. package/github/docs/interfaces/ListOperationPartialResult.html +10 -0
  149. package/github/docs/interfaces/ListOperationSuccessResult.html +7 -0
  150. package/github/docs/interfaces/ListOutput.html +3 -185
  151. package/github/docs/interfaces/Logger.html +39 -401
  152. package/github/docs/interfaces/Owner.html +1 -170
  153. package/github/docs/interfaces/PublicKey.html +1 -170
  154. package/github/docs/interfaces/StringFilter.html +3 -191
  155. package/github/docs/interfaces/SudoCryptoProvider.html +172 -1305
  156. package/github/docs/interfaces/SudoKeyArchive.html +54 -490
  157. package/github/docs/interfaces/SudoKeyManager.html +167 -1298
  158. package/github/docs/interfaces/SymmetricEncryptionOptions.html +3 -177
  159. package/github/docs/modules.html +33 -895
  160. package/github/package.json +19 -16
  161. package/github/src/errors/error.ts +10 -0
  162. package/github/src/sudoKeyArchive/sudoKeyArchive.ts +1 -1
  163. package/github/src/sudoKeyManager/sudoCryptoProvider.ts +12 -0
  164. package/github/src/sudoKeyManager/sudoKeyManager.ts +12 -0
  165. package/github/src/types/types.ts +78 -0
  166. package/github/test/utils/listOperationResult.spec.ts +84 -0
  167. package/github/yarn.lock +871 -1264
  168. package/lib/errors/error.d.ts +6 -0
  169. package/lib/errors/error.js +16 -2
  170. package/lib/logging/bunyanLogger.js +1 -1
  171. package/lib/sudoKeyArchive/keyArchive.js +2 -2
  172. package/lib/sudoKeyArchive/keyInfo.js +1 -1
  173. package/lib/sudoKeyArchive/sudoKeyArchive.d.ts +1 -2
  174. package/lib/sudoKeyArchive/sudoKeyArchive.js +1 -1
  175. package/lib/sudoKeyManager/keyData.js +1 -1
  176. package/lib/sudoKeyManager/sudoCryptoProvider.d.ts +12 -0
  177. package/lib/sudoKeyManager/sudoKeyManager.d.ts +12 -0
  178. package/lib/types/types.d.ts +71 -0
  179. package/lib/types/types.js +14 -2
  180. package/package.json +20 -17
  181. package/src/errors/error.ts +10 -0
  182. package/src/sudoKeyArchive/sudoKeyArchive.ts +1 -1
  183. package/src/sudoKeyManager/sudoCryptoProvider.ts +12 -0
  184. package/src/sudoKeyManager/sudoKeyManager.ts +12 -0
  185. package/src/types/types.ts +78 -0
  186. package/test/utils/listOperationResult.spec.ts +84 -0
  187. package/yarn.lock +871 -1264
  188. package/docs/assets/css/main.css +0 -2660
  189. package/docs/assets/js/main.js +0 -248
  190. package/docs/assets/js/search.js +0 -1
  191. package/github/docs/assets/css/main.css +0 -2660
  192. package/github/docs/assets/js/main.js +0 -248
  193. package/github/docs/assets/js/search.js +0 -1
  194. package/github/src/sudoKeyManager/encryptionAlgorithmTransformer.ts +0 -21
  195. package/lib/sudoKeyManager/encryptionAlgorithmTransformer.d.ts +0 -9
  196. package/lib/sudoKeyManager/encryptionAlgorithmTransformer.js +0 -28
  197. package/src/sudoKeyManager/encryptionAlgorithmTransformer.ts +0 -21
@@ -18,7 +18,7 @@
18
18
  "build:verify": "yarn audit-with-suppressions && yarn lint && yarn test --coverage",
19
19
  "build:transpile": "babel src --out-dir lib --extensions '.ts'",
20
20
  "build:declarations": "yarn tsc --emitDeclarationOnly",
21
- "build:doc": "typedoc --excludePrivate --out docs src/index.ts"
21
+ "build:doc": "typedoc --treatWarningsAsErrors --excludePrivate --out docs src/index.ts"
22
22
  },
23
23
  "main": "./lib/index.js",
24
24
  "types": "./lib/index.d.ts",
@@ -31,42 +31,45 @@
31
31
  "!*.spec.*"
32
32
  ],
33
33
  "resolutions": {
34
- "**/apollo-client": "^2.6.10"
34
+ "**/apollo-cache-inmemory": "^1.6.6",
35
+ "**/apollo-client": "^2.6.10",
36
+ "ansi-regex": "^5.0.1",
37
+ "tmpl": "^1.0.5"
35
38
  },
36
39
  "dependencies": {
37
40
  "apollo-client": "^2.6.10",
38
41
  "browser-bunyan": "^1.6.3",
39
- "fflate": "^0.7.1"
42
+ "fflate": "^0.7.1",
43
+ "graphql": "^15.6.1"
40
44
  },
41
45
  "peerDependencies": {
42
46
  "io-ts": "^2.2.10"
43
47
  },
44
48
  "devDependencies": {
45
- "@babel/cli": "^7.14.8",
46
- "@babel/core": "^7.15.0",
49
+ "@babel/cli": "^7.15.7",
50
+ "@babel/core": "^7.15.8",
47
51
  "@babel/plugin-proposal-class-properties": "^7.14.5",
48
52
  "@babel/plugin-proposal-private-methods": "^7.14.5",
49
- "@babel/preset-env": "^7.15.0",
53
+ "@babel/preset-env": "^7.15.8",
50
54
  "@babel/preset-typescript": "^7.15.0",
51
- "@types/jest": "^27.0.1",
52
- "@typescript-eslint/eslint-plugin": "^4.29.3",
53
- "@typescript-eslint/parser": "^4.29.3",
55
+ "@types/jest": "^27.0.2",
56
+ "@typescript-eslint/eslint-plugin": "^4.33.0",
57
+ "@typescript-eslint/parser": "^4.33.0",
54
58
  "eslint": "^7.32.0",
55
59
  "eslint-config-prettier": "^8.3.0",
56
60
  "eslint-plugin-import": "^2.24.2",
57
- "eslint-plugin-prettier": "^3.4.1",
58
- "fp-ts": "^2.11.1",
59
- "graphql": "^15.5.1",
61
+ "eslint-plugin-prettier": "^4.0.0",
62
+ "fp-ts": "^2.11.4",
60
63
  "io-ts": "^2.2.16",
61
64
  "io-ts-types": "^0.5.16",
62
65
  "isomorphic-webcrypto": "^2.3.8",
63
- "jest": "^27.0.6",
66
+ "jest": "^27.2.4",
64
67
  "monocle-ts": "^2.3.11",
65
68
  "newtype-ts": "^0.3.2",
66
- "prettier": "^2.3.2",
69
+ "prettier": "^2.4.1",
67
70
  "rimraf": "^3.0.2",
68
71
  "ts-mockito": "^2.6.1",
69
- "typedoc": "^0.21.6",
70
- "typescript": "^4.3.5"
72
+ "typedoc": "^0.22.5",
73
+ "typescript": "^4.4.3"
71
74
  }
72
75
  }
@@ -398,6 +398,16 @@ export class OperationNotImplementedError extends Error {
398
398
  }
399
399
  }
400
400
 
401
+ /**
402
+ * Encryption algorithm is not recognized
403
+ */
404
+ export class UnrecognizedAlgorithmError extends Error {
405
+ constructor(message?: string) {
406
+ super(message ?? 'Unrecognized encryption algorithm name.')
407
+ this.name = 'UnrecognizedAlgorithmError'
408
+ }
409
+ }
410
+
401
411
  /**
402
412
  * Helper method for mapping an App Sync error to common errors.
403
413
  *
@@ -124,7 +124,7 @@ export interface SudoKeyArchive {
124
124
  getMetaInfo(): ReadonlyMap<string, string>
125
125
  }
126
126
 
127
- type KeyArchiveKeyInfoDecoded = KeyArchiveKeyInfo & {
127
+ export type KeyArchiveKeyInfoDecoded = KeyArchiveKeyInfo & {
128
128
  Decoded: ArrayBuffer
129
129
  }
130
130
 
@@ -194,6 +194,8 @@ export interface SudoCryptoProvider {
194
194
  *
195
195
  *
196
196
  * @returns Encrypted data and IV
197
+ *
198
+ * @throws {@link UnrecognizedAlgorithmError}
197
199
  */
198
200
  encryptWithSymmetricKeyName(
199
201
  name: string,
@@ -225,6 +227,8 @@ export interface SudoCryptoProvider {
225
227
  * @param data The data to decrypt.
226
228
  *
227
229
  * @returns Decrypted data
230
+ *
231
+ * @throws {@link UnrecognizedAlgorithmError}
228
232
  */
229
233
  decryptWithSymmetricKeyName(
230
234
  name: string,
@@ -256,6 +260,8 @@ export interface SudoCryptoProvider {
256
260
  * @param data Data to encrypt.
257
261
  *
258
262
  * @returns Encrypted data and IV
263
+ *
264
+ * @throws {@link UnrecognizedAlgorithmError}
259
265
  */
260
266
  encryptWithSymmetricKey(
261
267
  key: ArrayBuffer,
@@ -287,6 +293,8 @@ export interface SudoCryptoProvider {
287
293
  * @param data The data to decrypt.
288
294
  *
289
295
  * @returns Decrypted data
296
+ *
297
+ * @throws {@link UnrecognizedAlgorithmError}
290
298
  */
291
299
  decryptWithSymmetricKey(
292
300
  key: ArrayBuffer,
@@ -301,6 +309,8 @@ export interface SudoCryptoProvider {
301
309
  * @param data The data to encrypt.
302
310
  *
303
311
  * @returns Encrypted data
312
+ *
313
+ * @throws {@link UnrecognizedAlgorithmError}
304
314
  */
305
315
  encryptWithPublicKey(
306
316
  name: string,
@@ -315,6 +325,8 @@ export interface SudoCryptoProvider {
315
325
  * @param data The data to decrypt.
316
326
  *
317
327
  * @returns Decrypted data or undefined if the private key is not found.
328
+ *
329
+ * @throws {@link UnrecognizedAlgorithmError}
318
330
  */
319
331
  decryptWithPrivateKey(
320
332
  name: string,
@@ -139,6 +139,8 @@ export interface SudoKeyManager {
139
139
  * @param data Data to encrypt.
140
140
  *
141
141
  * @returns Encrypted data and IV
142
+ *
143
+ * @throws {@link UnrecognizedAlgorithmError}
142
144
  */
143
145
  encryptWithSymmetricKey(
144
146
  key: ArrayBuffer,
@@ -170,6 +172,8 @@ export interface SudoKeyManager {
170
172
  * @param encryptedData The encrypted data.
171
173
  *
172
174
  * @returns Decrypted data
175
+ *
176
+ * @throws {@link UnrecognizedAlgorithmError}
173
177
  */
174
178
  decryptWithSymmetricKey(
175
179
  key: ArrayBuffer,
@@ -201,6 +205,8 @@ export interface SudoKeyManager {
201
205
  * @param data The data to decrypt.
202
206
  *
203
207
  * @returns Decrypted data
208
+ *
209
+ * @throws {@link UnrecognizedAlgorithmError}
204
210
  */
205
211
  encryptWithSymmetricKeyName(
206
212
  name: string,
@@ -231,6 +237,8 @@ export interface SudoKeyManager {
231
237
  * @param data The data to decrypt.
232
238
  *
233
239
  * @returns Decrypted data
240
+ *
241
+ * @throws {@link UnrecognizedAlgorithmError}
234
242
  */
235
243
  decryptWithSymmetricKeyName(
236
244
  name: string,
@@ -245,6 +253,8 @@ export interface SudoKeyManager {
245
253
  * @param data The data to encrypt.
246
254
  *
247
255
  * @returns Encrypted data
256
+ *
257
+ * @throws {@link UnrecognizedAlgorithmError}
248
258
  */
249
259
  encryptWithPublicKey(
250
260
  name: string,
@@ -259,6 +269,8 @@ export interface SudoKeyManager {
259
269
  * @param data The data to decrypt.
260
270
  *
261
271
  * @returns Decrypted data or undefined if the private key is not found.
272
+ *
273
+ * @throws {@link UnrecognizedAlgorithmError}
262
274
  */
263
275
  decryptWithPrivateKey(
264
276
  name: string,
@@ -48,3 +48,81 @@ export enum EncryptionAlgorithm {
48
48
  AesCbcPkcs7Padding = 'AES/CBC/PKCS7Padding',
49
49
  RsaOaepSha1 = 'RSA/OAEPWithSHA-1',
50
50
  }
51
+
52
+ export type Subset<T, S> = Pick<S, Extract<keyof T, keyof S>> &
53
+ Partial<Record<Exclude<keyof T, keyof S>, never>>
54
+
55
+ /**
56
+ * Status of the list operation result.
57
+ */
58
+ export enum ListOperationResultStatus {
59
+ /**
60
+ * The operation completed successfully.
61
+ */
62
+ Success = 'Success',
63
+ /**
64
+ * The operation completed but some items had errors during
65
+ * processing.
66
+ */
67
+ Partial = 'Partial',
68
+ /**
69
+ * The operation failed and no list item could be returned.
70
+ */
71
+ Failure = 'Failure',
72
+ }
73
+
74
+ export interface ListOperationSuccessResult<T> {
75
+ /**
76
+ * Operation status.
77
+ */
78
+ status: ListOperationResultStatus.Success
79
+ /**
80
+ * List of items that were successfully processed.
81
+ */
82
+ items: T[]
83
+ /**
84
+ * Pagination token.
85
+ */
86
+ nextToken?: string
87
+ }
88
+
89
+ export interface ListOperationFailureResult {
90
+ /**
91
+ * Operation status.
92
+ */
93
+ status: ListOperationResultStatus.Failure
94
+ /**
95
+ * The error that caused the failure.
96
+ */
97
+ cause: Error
98
+ }
99
+
100
+ export interface ListOperationPartialResult<T, S extends Subset<S, T>> {
101
+ /**
102
+ * Operation status.
103
+ */
104
+ status: ListOperationResultStatus.Partial
105
+ /**
106
+ * List of items that were successfully processed.
107
+ */
108
+ items: T[]
109
+ /**
110
+ * List of items that failed to be processed and the error
111
+ * that caused the failure.
112
+ */
113
+ failed: { item: Omit<T, keyof S>; cause: Error }[]
114
+ /**
115
+ * Pagination token.
116
+ */
117
+ nextToken?: string
118
+ }
119
+
120
+ /**
121
+ * Result of a list operation. T is the expected item type and
122
+ * S is a subset of T's properties that won't be present if the
123
+ * additional processing after the item has been fetched fails.
124
+ */
125
+ export type ListOperationResult<T, S extends Subset<S, T> = T> =
126
+ | ListOperationSuccessResult<T>
127
+ | ListOperationFailureResult
128
+ | ListOperationPartialResult<T, S>
@@ -0,0 +1,84 @@
1
+ import {
2
+ ListOperationResult,
3
+ ListOperationResultStatus,
4
+ } from '../../src/types/types'
5
+
6
+ type Item = {
7
+ id: string
8
+ createdAt: Date
9
+ updatedAt: Date
10
+ } & SealedAttributes
11
+ type SealedAttributes = {
12
+ secret: string
13
+ }
14
+ type ListItemResult = ListOperationResult<Item, SealedAttributes>
15
+
16
+ describe('ListOperationResult', () => {
17
+ it('should successfully assign success result', () => {
18
+ const obj: ListItemResult = {
19
+ status: ListOperationResultStatus.Success,
20
+ items: [
21
+ {
22
+ id: 'dummy_id',
23
+ createdAt: new Date(1),
24
+ updatedAt: new Date(2),
25
+ secret: 'dummy_secret',
26
+ },
27
+ ],
28
+ nextToken: 'dummy_token',
29
+ }
30
+ expect(obj.status).toBe('Success')
31
+ expect(obj.nextToken).toBe('dummy_token')
32
+ expect(obj.items.length).toBe(1)
33
+ expect(obj.items[0].id).toBe('dummy_id')
34
+ expect(obj.items[0].createdAt).toEqual(new Date(1))
35
+ expect(obj.items[0].updatedAt).toEqual(new Date(2))
36
+ expect(obj.items[0].secret).toBe('dummy_secret')
37
+ })
38
+
39
+ it('should successfully assign failure result', () => {
40
+ const obj: ListItemResult = {
41
+ status: ListOperationResultStatus.Failure,
42
+ cause: new Error('dummy_error'),
43
+ }
44
+ expect(obj.status).toBe('Failure')
45
+ expect(obj.cause.message).toBe('dummy_error')
46
+ })
47
+
48
+ it('should successfully assign partial result', () => {
49
+ const obj: ListItemResult = {
50
+ status: ListOperationResultStatus.Partial,
51
+ items: [
52
+ {
53
+ id: 'dummy_id',
54
+ createdAt: new Date(1),
55
+ updatedAt: new Date(2),
56
+ secret: 'dummy_secret',
57
+ },
58
+ ],
59
+ failed: [
60
+ {
61
+ item: {
62
+ id: 'dummy_id',
63
+ createdAt: new Date(1),
64
+ updatedAt: new Date(2),
65
+ },
66
+ cause: new Error('dummy_error'),
67
+ },
68
+ ],
69
+ nextToken: 'dummy_token',
70
+ }
71
+ expect(obj.status).toBe('Partial')
72
+ expect(obj.nextToken).toBe('dummy_token')
73
+ expect(obj.items.length).toBe(1)
74
+ expect(obj.items[0].id).toBe('dummy_id')
75
+ expect(obj.items[0].createdAt).toEqual(new Date(1))
76
+ expect(obj.items[0].updatedAt).toEqual(new Date(2))
77
+ expect(obj.items[0].secret).toBe('dummy_secret')
78
+ expect(obj.items.length).toBe(1)
79
+ expect(obj.failed[0].item.id).toBe('dummy_id')
80
+ expect(obj.failed[0].item.createdAt).toEqual(new Date(1))
81
+ expect(obj.failed[0].item.updatedAt).toEqual(new Date(2))
82
+ expect(obj.failed[0].cause.message).toBe('dummy_error')
83
+ })
84
+ })