@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.
- package/CHANGELOG.md +5 -1
- package/bin/yarn-audit-with-suppression.sh +1 -1
- package/dependencies-report.json +2 -2
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +57 -0
- package/docs/assets/icons.css +1043 -0
- package/docs/assets/{images/icons.png → icons.png} +0 -0
- package/docs/assets/{images/icons@2x.png → icons@2x.png} +0 -0
- package/docs/assets/main.js +52 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1384 -0
- package/docs/assets/{images/widgets.png → widgets.png} +0 -0
- package/docs/assets/{images/widgets@2x.png → widgets@2x.png} +0 -0
- package/docs/classes/AccountLockedError.html +7 -332
- package/docs/classes/AuthenticationError.html +8 -339
- package/docs/classes/Base64.html +3 -283
- package/docs/classes/Buffer.html +3 -324
- package/docs/classes/ConfigurationNotSetError.html +8 -333
- package/docs/classes/ConfigurationSetNotFoundError.html +7 -338
- package/docs/classes/DecodeError.html +7 -338
- package/docs/classes/DefaultConfigurationManager.html +18 -333
- package/docs/classes/DefaultLogger.html +19 -417
- package/docs/classes/DefaultSudoKeyArchive.html +61 -598
- package/docs/classes/DefaultSudoKeyManager.html +60 -1110
- package/docs/classes/FatalError.html +8 -339
- package/docs/classes/IllegalArgumentError.html +7 -338
- package/docs/classes/IllegalStateError.html +8 -339
- package/docs/classes/InsufficientEntitlementsError.html +8 -333
- package/docs/classes/InvalidOwnershipProofError.html +7 -332
- package/docs/classes/InvalidTokenError.html +7 -332
- package/docs/classes/KeyArchiveDecodingError.html +7 -338
- package/docs/classes/KeyArchiveIncorrectPasswordError.html +7 -338
- package/docs/classes/KeyArchiveMissingError.html +7 -338
- package/docs/classes/KeyArchiveNoPasswordRequiredError.html +7 -338
- package/docs/classes/KeyArchivePasswordRequiredError.html +7 -338
- package/docs/classes/KeyArchiveTypeError.html +7 -338
- package/docs/classes/KeyArchiveUnknownKeyTypeError.html +7 -338
- package/docs/classes/KeyArchiveVersionError.html +7 -338
- package/docs/classes/KeyNotFoundError.html +7 -338
- package/docs/classes/KeyStoreNotExportableError.html +7 -338
- package/docs/classes/LimitExceededError.html +8 -333
- package/docs/classes/NoEntitlementsError.html +7 -332
- package/docs/classes/NotAuthorizedError.html +8 -339
- package/docs/classes/NotRegisteredError.html +7 -338
- package/docs/classes/NotSignedInError.html +8 -333
- package/docs/classes/OperationNotImplementedError.html +7 -338
- package/docs/classes/RegisterError.html +8 -339
- package/docs/classes/RequestFailedError.html +12 -380
- package/docs/classes/ServiceError.html +9 -340
- package/docs/classes/SignOutError.html +7 -338
- package/docs/classes/SudoCryptoProviderDefaults.html +1 -224
- package/docs/classes/UnknownGraphQLError.html +7 -338
- package/docs/classes/UnrecognizedAlgorithmError.html +7 -0
- package/docs/classes/UserNotConfirmedError.html +8 -333
- package/docs/classes/VersionMismatchError.html +10 -335
- package/docs/enums/CachePolicy.html +4 -170
- package/docs/enums/EncryptionAlgorithm.html +5 -171
- package/docs/enums/KeyArchiveKeyType.html +4 -198
- package/docs/enums/KeyDataKeyFormat.html +18 -202
- package/docs/enums/KeyDataKeyType.html +3 -197
- package/docs/enums/ListOperationResultStatus.html +10 -0
- package/docs/enums/PublicKeyFormat.html +1 -162
- package/docs/index.html +14 -369
- package/docs/interfaces/AsymmetricEncryptionOptions.html +3 -163
- package/docs/interfaces/BooleanFilter.html +3 -177
- package/docs/interfaces/ConfigurationManager.html +37 -349
- package/docs/interfaces/KeyData.html +8 -236
- package/docs/interfaces/ListOperationFailureResult.html +5 -0
- package/docs/interfaces/ListOperationPartialResult.html +10 -0
- package/docs/interfaces/ListOperationSuccessResult.html +7 -0
- package/docs/interfaces/ListOutput.html +3 -185
- package/docs/interfaces/Logger.html +39 -401
- package/docs/interfaces/Owner.html +1 -170
- package/docs/interfaces/PublicKey.html +1 -170
- package/docs/interfaces/StringFilter.html +3 -191
- package/docs/interfaces/SudoCryptoProvider.html +172 -1305
- package/docs/interfaces/SudoKeyArchive.html +54 -490
- package/docs/interfaces/SudoKeyManager.html +167 -1298
- package/docs/interfaces/SymmetricEncryptionOptions.html +3 -177
- package/docs/modules.html +33 -895
- package/github/CHANGELOG.md +5 -1
- package/github/bin/yarn-audit-with-suppression.sh +1 -1
- package/github/docs/.nojekyll +1 -0
- package/github/docs/assets/highlight.css +57 -0
- package/github/docs/assets/icons.css +1043 -0
- package/github/docs/assets/{images/icons.png → icons.png} +0 -0
- package/github/docs/assets/{images/icons@2x.png → icons@2x.png} +0 -0
- package/github/docs/assets/main.js +52 -0
- package/github/docs/assets/search.js +1 -0
- package/github/docs/assets/style.css +1384 -0
- package/github/docs/assets/{images/widgets.png → widgets.png} +0 -0
- package/github/docs/assets/{images/widgets@2x.png → widgets@2x.png} +0 -0
- package/github/docs/classes/AccountLockedError.html +7 -332
- package/github/docs/classes/AuthenticationError.html +8 -339
- package/github/docs/classes/Base64.html +3 -283
- package/github/docs/classes/Buffer.html +3 -324
- package/github/docs/classes/ConfigurationNotSetError.html +8 -333
- package/github/docs/classes/ConfigurationSetNotFoundError.html +7 -338
- package/github/docs/classes/DecodeError.html +7 -338
- package/github/docs/classes/DefaultConfigurationManager.html +18 -333
- package/github/docs/classes/DefaultLogger.html +19 -417
- package/github/docs/classes/DefaultSudoKeyArchive.html +61 -598
- package/github/docs/classes/DefaultSudoKeyManager.html +60 -1110
- package/github/docs/classes/FatalError.html +8 -339
- package/github/docs/classes/IllegalArgumentError.html +7 -338
- package/github/docs/classes/IllegalStateError.html +8 -339
- package/github/docs/classes/InsufficientEntitlementsError.html +8 -333
- package/github/docs/classes/InvalidOwnershipProofError.html +7 -332
- package/github/docs/classes/InvalidTokenError.html +7 -332
- package/github/docs/classes/KeyArchiveDecodingError.html +7 -338
- package/github/docs/classes/KeyArchiveIncorrectPasswordError.html +7 -338
- package/github/docs/classes/KeyArchiveMissingError.html +7 -338
- package/github/docs/classes/KeyArchiveNoPasswordRequiredError.html +7 -338
- package/github/docs/classes/KeyArchivePasswordRequiredError.html +7 -338
- package/github/docs/classes/KeyArchiveTypeError.html +7 -338
- package/github/docs/classes/KeyArchiveUnknownKeyTypeError.html +7 -338
- package/github/docs/classes/KeyArchiveVersionError.html +7 -338
- package/github/docs/classes/KeyNotFoundError.html +7 -338
- package/github/docs/classes/KeyStoreNotExportableError.html +7 -338
- package/github/docs/classes/LimitExceededError.html +8 -333
- package/github/docs/classes/NoEntitlementsError.html +7 -332
- package/github/docs/classes/NotAuthorizedError.html +8 -339
- package/github/docs/classes/NotRegisteredError.html +7 -338
- package/github/docs/classes/NotSignedInError.html +8 -333
- package/github/docs/classes/OperationNotImplementedError.html +7 -338
- package/github/docs/classes/RegisterError.html +8 -339
- package/github/docs/classes/RequestFailedError.html +12 -380
- package/github/docs/classes/ServiceError.html +9 -340
- package/github/docs/classes/SignOutError.html +7 -338
- package/github/docs/classes/SudoCryptoProviderDefaults.html +1 -224
- package/github/docs/classes/UnknownGraphQLError.html +7 -338
- package/github/docs/classes/UnrecognizedAlgorithmError.html +7 -0
- package/github/docs/classes/UserNotConfirmedError.html +8 -333
- package/github/docs/classes/VersionMismatchError.html +10 -335
- package/github/docs/enums/CachePolicy.html +4 -170
- package/github/docs/enums/EncryptionAlgorithm.html +5 -171
- package/github/docs/enums/KeyArchiveKeyType.html +4 -198
- package/github/docs/enums/KeyDataKeyFormat.html +18 -202
- package/github/docs/enums/KeyDataKeyType.html +3 -197
- package/github/docs/enums/ListOperationResultStatus.html +10 -0
- package/github/docs/enums/PublicKeyFormat.html +1 -162
- package/github/docs/index.html +14 -369
- package/github/docs/interfaces/AsymmetricEncryptionOptions.html +3 -163
- package/github/docs/interfaces/BooleanFilter.html +3 -177
- package/github/docs/interfaces/ConfigurationManager.html +37 -349
- package/github/docs/interfaces/KeyData.html +8 -236
- package/github/docs/interfaces/ListOperationFailureResult.html +5 -0
- package/github/docs/interfaces/ListOperationPartialResult.html +10 -0
- package/github/docs/interfaces/ListOperationSuccessResult.html +7 -0
- package/github/docs/interfaces/ListOutput.html +3 -185
- package/github/docs/interfaces/Logger.html +39 -401
- package/github/docs/interfaces/Owner.html +1 -170
- package/github/docs/interfaces/PublicKey.html +1 -170
- package/github/docs/interfaces/StringFilter.html +3 -191
- package/github/docs/interfaces/SudoCryptoProvider.html +172 -1305
- package/github/docs/interfaces/SudoKeyArchive.html +54 -490
- package/github/docs/interfaces/SudoKeyManager.html +167 -1298
- package/github/docs/interfaces/SymmetricEncryptionOptions.html +3 -177
- package/github/docs/modules.html +33 -895
- package/github/package.json +19 -16
- package/github/src/errors/error.ts +10 -0
- package/github/src/sudoKeyArchive/sudoKeyArchive.ts +1 -1
- package/github/src/sudoKeyManager/sudoCryptoProvider.ts +12 -0
- package/github/src/sudoKeyManager/sudoKeyManager.ts +12 -0
- package/github/src/types/types.ts +78 -0
- package/github/test/utils/listOperationResult.spec.ts +84 -0
- package/github/yarn.lock +871 -1264
- package/lib/errors/error.d.ts +6 -0
- package/lib/errors/error.js +16 -2
- package/lib/logging/bunyanLogger.js +1 -1
- package/lib/sudoKeyArchive/keyArchive.js +2 -2
- package/lib/sudoKeyArchive/keyInfo.js +1 -1
- package/lib/sudoKeyArchive/sudoKeyArchive.d.ts +1 -2
- package/lib/sudoKeyArchive/sudoKeyArchive.js +1 -1
- package/lib/sudoKeyManager/keyData.js +1 -1
- package/lib/sudoKeyManager/sudoCryptoProvider.d.ts +12 -0
- package/lib/sudoKeyManager/sudoKeyManager.d.ts +12 -0
- package/lib/types/types.d.ts +71 -0
- package/lib/types/types.js +14 -2
- package/package.json +20 -17
- package/src/errors/error.ts +10 -0
- package/src/sudoKeyArchive/sudoKeyArchive.ts +1 -1
- package/src/sudoKeyManager/sudoCryptoProvider.ts +12 -0
- package/src/sudoKeyManager/sudoKeyManager.ts +12 -0
- package/src/types/types.ts +78 -0
- package/test/utils/listOperationResult.spec.ts +84 -0
- package/yarn.lock +871 -1264
- package/docs/assets/css/main.css +0 -2660
- package/docs/assets/js/main.js +0 -248
- package/docs/assets/js/search.js +0 -1
- package/github/docs/assets/css/main.css +0 -2660
- package/github/docs/assets/js/main.js +0 -248
- package/github/docs/assets/js/search.js +0 -1
- package/github/src/sudoKeyManager/encryptionAlgorithmTransformer.ts +0 -21
- package/lib/sudoKeyManager/encryptionAlgorithmTransformer.d.ts +0 -9
- package/lib/sudoKeyManager/encryptionAlgorithmTransformer.js +0 -28
- package/src/sudoKeyManager/encryptionAlgorithmTransformer.ts +0 -21
package/github/package.json
CHANGED
|
@@ -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-
|
|
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.
|
|
46
|
-
"@babel/core": "^7.15.
|
|
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.
|
|
53
|
+
"@babel/preset-env": "^7.15.8",
|
|
50
54
|
"@babel/preset-typescript": "^7.15.0",
|
|
51
|
-
"@types/jest": "^27.0.
|
|
52
|
-
"@typescript-eslint/eslint-plugin": "^4.
|
|
53
|
-
"@typescript-eslint/parser": "^4.
|
|
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": "^
|
|
58
|
-
"fp-ts": "^2.11.
|
|
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.
|
|
66
|
+
"jest": "^27.2.4",
|
|
64
67
|
"monocle-ts": "^2.3.11",
|
|
65
68
|
"newtype-ts": "^0.3.2",
|
|
66
|
-
"prettier": "^2.
|
|
69
|
+
"prettier": "^2.4.1",
|
|
67
70
|
"rimraf": "^3.0.2",
|
|
68
71
|
"ts-mockito": "^2.6.1",
|
|
69
|
-
"typedoc": "^0.
|
|
70
|
-
"typescript": "^4.3
|
|
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
|
*
|
|
@@ -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
|
+
})
|