@sudoplatform/sudo-common 6.0.2 → 6.2.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.
- package/.gitignore +1 -0
- package/.yarn/releases/yarn-1.22.18.cjs +147520 -0
- package/.yarnrc +5 -0
- package/bin/outdated-with-suppression.sh +86 -9
- package/bin/suppress-outdated.sh +21 -3
- package/dependencies-report.json +118 -8
- package/docs/assets/highlight.css +1 -1
- package/docs/assets/main.js +2 -2
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +32 -2
- package/docs/classes/AccountLockedError.html +3 -3
- package/docs/classes/AuthenticationError.html +3 -3
- package/docs/classes/Base64.html +2 -2
- package/docs/classes/Buffer.html +2 -2
- package/docs/classes/ConfigurationNotSetError.html +3 -3
- package/docs/classes/ConfigurationSetNotFoundError.html +3 -3
- package/docs/classes/DecodeError.html +3 -3
- package/docs/classes/DefaultConfigurationManager.html +13 -6
- package/docs/classes/DefaultLogger.html +7 -7
- package/docs/classes/DefaultSudoKeyArchive.html +13 -13
- package/docs/classes/DefaultSudoKeyManager.html +28 -28
- package/docs/classes/FatalError.html +3 -3
- package/docs/classes/IllegalArgumentError.html +3 -3
- package/docs/classes/IllegalStateError.html +3 -3
- package/docs/classes/InsufficientEntitlementsError.html +3 -3
- package/docs/classes/InvalidOwnershipProofError.html +3 -3
- package/docs/classes/InvalidTokenError.html +3 -3
- package/docs/classes/KeyArchiveDecodingError.html +3 -3
- package/docs/classes/KeyArchiveIncorrectPasswordError.html +3 -3
- package/docs/classes/KeyArchiveMissingError.html +3 -3
- package/docs/classes/KeyArchiveNoPasswordRequiredError.html +3 -3
- package/docs/classes/KeyArchivePasswordRequiredError.html +3 -3
- package/docs/classes/KeyArchiveTypeError.html +3 -3
- package/docs/classes/KeyArchiveUnknownKeyTypeError.html +3 -3
- package/docs/classes/KeyArchiveVersionError.html +3 -3
- package/docs/classes/KeyNotFoundError.html +3 -3
- package/docs/classes/KeyStoreNotExportableError.html +3 -3
- package/docs/classes/LimitExceededError.html +3 -3
- package/docs/classes/NoEntitlementsError.html +3 -3
- package/docs/classes/NotAuthorizedError.html +3 -3
- package/docs/classes/NotRegisteredError.html +3 -3
- package/docs/classes/NotSignedInError.html +3 -3
- package/docs/classes/OperationNotImplementedError.html +3 -3
- package/docs/classes/RegisterError.html +3 -3
- package/docs/classes/RequestFailedError.html +5 -5
- package/docs/classes/ServiceError.html +3 -3
- package/docs/classes/SignOutError.html +3 -3
- package/docs/classes/SudoCryptoProviderDefaults.html +1 -1
- package/docs/classes/UnknownGraphQLError.html +3 -3
- package/docs/classes/UnrecognizedAlgorithmError.html +3 -3
- package/docs/classes/UserNotConfirmedError.html +3 -3
- package/docs/classes/VersionMismatchError.html +3 -3
- package/docs/enums/CachePolicy.html +2 -2
- package/docs/enums/EncryptionAlgorithm.html +2 -2
- package/docs/enums/KeyArchiveKeyType.html +2 -2
- package/docs/enums/KeyDataKeyFormat.html +3 -3
- package/docs/enums/KeyDataKeyType.html +2 -2
- package/docs/enums/ListOperationResultStatus.html +4 -4
- package/docs/enums/PublicKeyFormat.html +1 -1
- package/docs/index.html +2 -2
- package/docs/interfaces/AsymmetricEncryptionOptions.html +2 -2
- package/docs/interfaces/BooleanFilter.html +2 -2
- package/docs/interfaces/ConfigurationManager.html +13 -6
- package/docs/interfaces/KeyData.html +2 -2
- package/docs/interfaces/ListOperationFailureResult.html +2 -2
- package/docs/interfaces/ListOperationPartialResult.html +4 -4
- package/docs/interfaces/ListOperationSuccessResult.html +3 -3
- package/docs/interfaces/ListOutput.html +2 -2
- package/docs/interfaces/Logger.html +7 -7
- package/docs/interfaces/Owner.html +1 -1
- package/docs/interfaces/PublicKey.html +1 -1
- package/docs/interfaces/ServiceCompatibilityInfo.html +17 -0
- package/docs/interfaces/StringFilter.html +2 -2
- package/docs/interfaces/SudoCryptoProvider.html +28 -28
- package/docs/interfaces/SudoKeyArchive.html +10 -10
- package/docs/interfaces/SudoKeyManager.html +28 -28
- package/docs/interfaces/SymmetricEncryptionOptions.html +2 -2
- package/docs/interfaces/ValidationResult.html +11 -0
- package/docs/modules.html +6 -6
- package/github/.gitignore +1 -0
- package/github/.yarn/releases/yarn-1.22.18.cjs +147520 -0
- package/github/.yarnrc +5 -0
- package/github/bin/outdated-with-suppression.sh +86 -9
- package/github/bin/suppress-outdated.sh +21 -3
- package/github/docs/assets/highlight.css +1 -1
- package/github/docs/assets/main.js +2 -2
- package/github/docs/assets/search.js +1 -1
- package/github/docs/assets/style.css +32 -2
- package/github/docs/classes/AccountLockedError.html +3 -3
- package/github/docs/classes/AuthenticationError.html +3 -3
- package/github/docs/classes/Base64.html +2 -2
- package/github/docs/classes/Buffer.html +2 -2
- package/github/docs/classes/ConfigurationNotSetError.html +3 -3
- package/github/docs/classes/ConfigurationSetNotFoundError.html +3 -3
- package/github/docs/classes/DecodeError.html +3 -3
- package/github/docs/classes/DefaultConfigurationManager.html +13 -6
- package/github/docs/classes/DefaultLogger.html +7 -7
- package/github/docs/classes/DefaultSudoKeyArchive.html +13 -13
- package/github/docs/classes/DefaultSudoKeyManager.html +28 -28
- package/github/docs/classes/FatalError.html +3 -3
- package/github/docs/classes/IllegalArgumentError.html +3 -3
- package/github/docs/classes/IllegalStateError.html +3 -3
- package/github/docs/classes/InsufficientEntitlementsError.html +3 -3
- package/github/docs/classes/InvalidOwnershipProofError.html +3 -3
- package/github/docs/classes/InvalidTokenError.html +3 -3
- package/github/docs/classes/KeyArchiveDecodingError.html +3 -3
- package/github/docs/classes/KeyArchiveIncorrectPasswordError.html +3 -3
- package/github/docs/classes/KeyArchiveMissingError.html +3 -3
- package/github/docs/classes/KeyArchiveNoPasswordRequiredError.html +3 -3
- package/github/docs/classes/KeyArchivePasswordRequiredError.html +3 -3
- package/github/docs/classes/KeyArchiveTypeError.html +3 -3
- package/github/docs/classes/KeyArchiveUnknownKeyTypeError.html +3 -3
- package/github/docs/classes/KeyArchiveVersionError.html +3 -3
- package/github/docs/classes/KeyNotFoundError.html +3 -3
- package/github/docs/classes/KeyStoreNotExportableError.html +3 -3
- package/github/docs/classes/LimitExceededError.html +3 -3
- package/github/docs/classes/NoEntitlementsError.html +3 -3
- package/github/docs/classes/NotAuthorizedError.html +3 -3
- package/github/docs/classes/NotRegisteredError.html +3 -3
- package/github/docs/classes/NotSignedInError.html +3 -3
- package/github/docs/classes/OperationNotImplementedError.html +3 -3
- package/github/docs/classes/RegisterError.html +3 -3
- package/github/docs/classes/RequestFailedError.html +5 -5
- package/github/docs/classes/ServiceError.html +3 -3
- package/github/docs/classes/SignOutError.html +3 -3
- package/github/docs/classes/SudoCryptoProviderDefaults.html +1 -1
- package/github/docs/classes/UnknownGraphQLError.html +3 -3
- package/github/docs/classes/UnrecognizedAlgorithmError.html +3 -3
- package/github/docs/classes/UserNotConfirmedError.html +3 -3
- package/github/docs/classes/VersionMismatchError.html +3 -3
- package/github/docs/enums/CachePolicy.html +2 -2
- package/github/docs/enums/EncryptionAlgorithm.html +2 -2
- package/github/docs/enums/KeyArchiveKeyType.html +2 -2
- package/github/docs/enums/KeyDataKeyFormat.html +3 -3
- package/github/docs/enums/KeyDataKeyType.html +2 -2
- package/github/docs/enums/ListOperationResultStatus.html +4 -4
- package/github/docs/enums/PublicKeyFormat.html +1 -1
- package/github/docs/index.html +2 -2
- package/github/docs/interfaces/AsymmetricEncryptionOptions.html +2 -2
- package/github/docs/interfaces/BooleanFilter.html +2 -2
- package/github/docs/interfaces/ConfigurationManager.html +13 -6
- package/github/docs/interfaces/KeyData.html +2 -2
- package/github/docs/interfaces/ListOperationFailureResult.html +2 -2
- package/github/docs/interfaces/ListOperationPartialResult.html +4 -4
- package/github/docs/interfaces/ListOperationSuccessResult.html +3 -3
- package/github/docs/interfaces/ListOutput.html +2 -2
- package/github/docs/interfaces/Logger.html +7 -7
- package/github/docs/interfaces/Owner.html +1 -1
- package/github/docs/interfaces/PublicKey.html +1 -1
- package/github/docs/interfaces/ServiceCompatibilityInfo.html +17 -0
- package/github/docs/interfaces/StringFilter.html +2 -2
- package/github/docs/interfaces/SudoCryptoProvider.html +28 -28
- package/github/docs/interfaces/SudoKeyArchive.html +10 -10
- package/github/docs/interfaces/SudoKeyManager.html +28 -28
- package/github/docs/interfaces/SymmetricEncryptionOptions.html +2 -2
- package/github/docs/interfaces/ValidationResult.html +11 -0
- package/github/docs/modules.html +6 -6
- package/github/package.json +30 -25
- package/github/src/configurationManager/defaultConfigurationManager.ts +156 -7
- package/github/src/errors/error.ts +5 -1
- package/github/test/integration/defaultConfigurationManager.spec.ts +85 -0
- package/github/test/unit/configurationManager/defaultConfigurationManager.spec.ts +506 -0
- package/{test → github/test/unit}/errors/error.spec.ts +4 -19
- package/github/test/{sudoKeyArchive → unit}/keyType.spec.ts +0 -0
- package/{test → github/test/unit}/logging/logger.spec.ts +1 -1
- package/github/test/{sudoKeyArchive → unit}/sudoKeyArchive.spec.ts +0 -0
- package/github/test/{sudoKeyManager → unit}/sudoKeyManager.spec.ts +0 -0
- package/github/test/{utils → unit/utils}/base64.spec.ts +1 -1
- package/github/test/{utils → unit/utils}/buffer.spec.ts +1 -1
- package/{test → github/test/unit}/utils/listOperationResult.spec.ts +1 -1
- package/github/tsconfig.test.json +3 -1
- package/github/yarn.lock +1852 -1342
- package/lib/configurationManager/defaultConfigurationManager.d.ts +57 -0
- package/lib/configurationManager/defaultConfigurationManager.js +102 -7
- package/lib/errors/error.d.ts +1 -1
- package/lib/errors/error.js +3 -0
- package/package.json +30 -25
- package/src/configurationManager/defaultConfigurationManager.ts +156 -7
- package/src/errors/error.ts +5 -1
- package/test/integration/defaultConfigurationManager.spec.ts +85 -0
- package/test/unit/configurationManager/defaultConfigurationManager.spec.ts +506 -0
- package/{github/test → test/unit}/errors/error.spec.ts +4 -19
- package/test/{sudoKeyArchive → unit}/keyType.spec.ts +0 -0
- package/{github/test → test/unit}/logging/logger.spec.ts +1 -1
- package/test/{sudoKeyArchive → unit}/sudoKeyArchive.spec.ts +0 -0
- package/test/{sudoKeyManager → unit}/sudoKeyManager.spec.ts +0 -0
- package/test/{utils → unit/utils}/base64.spec.ts +1 -1
- package/test/{utils → unit/utils}/buffer.spec.ts +1 -1
- package/{github/test → test/unit}/utils/listOperationResult.spec.ts +1 -1
- package/tsconfig.test.json +3 -1
- package/yarn.lock +1852 -1342
- package/github/test/configurationManager/defaultConfigurationManager.spec.ts +0 -185
- package/test/configurationManager/defaultConfigurationManager.spec.ts +0 -185
package/github/package.json
CHANGED
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
"lint": "yarn lint:eslint && yarn lint:prettier",
|
|
15
15
|
"lint:eslint": "eslint \"{bin,integration-tests,src,test}/**/*.{ts,tsx}\"",
|
|
16
16
|
"lint:prettier": "prettier -l \"{bin,integration-tests,src,test}/**/*.{js,json,jsx,ts,tsx}\"",
|
|
17
|
-
"test": "jest",
|
|
17
|
+
"unit-test": "jest test/unit",
|
|
18
|
+
"integration-test": "jest test/integration",
|
|
19
|
+
"test": "yarn unit-test && yarn integration-test",
|
|
18
20
|
"build": "yarn clean && yarn build:transpile && yarn build:verify && yarn build:declarations && yarn build:doc",
|
|
19
21
|
"build:verify": "yarn audit-with-suppressions && yarn lint && yarn test --coverage",
|
|
20
22
|
"build:transpile": "babel src --out-dir lib --extensions '.ts'",
|
|
@@ -37,42 +39,45 @@
|
|
|
37
39
|
"**/apollo-cache-inmemory": "^1.6.6",
|
|
38
40
|
"**/apollo-client": "^2.6.10",
|
|
39
41
|
"ansi-regex": "^5.0.1",
|
|
40
|
-
"tmpl": "^1.0.5"
|
|
42
|
+
"tmpl": "^1.0.5",
|
|
43
|
+
"minimist": "^1.2.6"
|
|
41
44
|
},
|
|
42
45
|
"dependencies": {
|
|
43
46
|
"apollo-client": "^2.6.10",
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
+
"aws-sdk": "^2.973.0",
|
|
48
|
+
"browser-bunyan": "^1.8.0",
|
|
49
|
+
"fflate": "^0.7.3",
|
|
50
|
+
"graphql": "^15.8.0"
|
|
47
51
|
},
|
|
48
52
|
"peerDependencies": {
|
|
49
53
|
"io-ts": "^2.2.10"
|
|
50
54
|
},
|
|
51
55
|
"devDependencies": {
|
|
52
|
-
"@babel/cli": "^7.
|
|
53
|
-
"@babel/core": "^7.
|
|
54
|
-
"@babel/plugin-proposal-class-properties": "^7.
|
|
55
|
-
"@babel/plugin-proposal-private-methods": "^7.
|
|
56
|
-
"@babel/preset-env": "^7.
|
|
57
|
-
"@babel/preset-typescript": "^7.
|
|
58
|
-
"@types/jest": "^27.0
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
60
|
-
"@typescript-eslint/parser": "^5.
|
|
61
|
-
"
|
|
62
|
-
"eslint
|
|
63
|
-
"eslint-
|
|
56
|
+
"@babel/cli": "^7.17.10",
|
|
57
|
+
"@babel/core": "^7.17.10",
|
|
58
|
+
"@babel/plugin-proposal-class-properties": "^7.16.7",
|
|
59
|
+
"@babel/plugin-proposal-private-methods": "^7.16.11",
|
|
60
|
+
"@babel/preset-env": "^7.17.10",
|
|
61
|
+
"@babel/preset-typescript": "^7.16.7",
|
|
62
|
+
"@types/jest": "^27.5.0",
|
|
63
|
+
"@typescript-eslint/eslint-plugin": "^5.22.0",
|
|
64
|
+
"@typescript-eslint/parser": "^5.22.0",
|
|
65
|
+
"aws-sdk-mock": "^5.7.0",
|
|
66
|
+
"eslint": "^8.14.0",
|
|
67
|
+
"eslint-config-prettier": "^8.5.0",
|
|
68
|
+
"eslint-plugin-import": "^2.26.0",
|
|
64
69
|
"eslint-plugin-prettier": "^4.0.0",
|
|
65
|
-
"fp-ts": "^2.11.
|
|
70
|
+
"fp-ts": "^2.11.8",
|
|
66
71
|
"io-ts": "^2.2.16",
|
|
67
72
|
"io-ts-types": "^0.5.16",
|
|
68
73
|
"isomorphic-webcrypto": "^2.3.8",
|
|
69
|
-
"jest": "^27.
|
|
70
|
-
"monocle-ts": "^2.3.
|
|
71
|
-
"newtype-ts": "^0.3.
|
|
72
|
-
"prettier": "^2.
|
|
74
|
+
"jest": "^27.5.1",
|
|
75
|
+
"monocle-ts": "^2.3.13",
|
|
76
|
+
"newtype-ts": "^0.3.5",
|
|
77
|
+
"prettier": "^2.6.2",
|
|
73
78
|
"rimraf": "^3.0.2",
|
|
74
79
|
"ts-mockito": "^2.6.1",
|
|
75
|
-
"typedoc": "^0.22.
|
|
76
|
-
"typescript": "^4.
|
|
80
|
+
"typedoc": "^0.22.15",
|
|
81
|
+
"typescript": "^4.6.4"
|
|
77
82
|
}
|
|
78
|
-
}
|
|
83
|
+
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
1
6
|
import { fold, left } from 'fp-ts/lib/Either'
|
|
2
7
|
import { pipe } from 'fp-ts/lib/pipeable'
|
|
3
8
|
import * as t from 'io-ts'
|
|
9
|
+
import * as AWS from 'aws-sdk'
|
|
4
10
|
import { PathReporter } from 'io-ts/lib/PathReporter'
|
|
5
11
|
import {
|
|
6
12
|
ConfigurationNotSetError,
|
|
@@ -8,6 +14,54 @@ import {
|
|
|
8
14
|
ConfigurationSetNotFoundError,
|
|
9
15
|
} from '../errors/error'
|
|
10
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Service compatibility information.
|
|
19
|
+
*/
|
|
20
|
+
export interface ServiceCompatibilityInfo {
|
|
21
|
+
/**
|
|
22
|
+
* The name of the service associated with the compatibility info. This matches one of the
|
|
23
|
+
* service name present in sudoplatformconfig.json.
|
|
24
|
+
*/
|
|
25
|
+
name: string
|
|
26
|
+
/**
|
|
27
|
+
* The version of the service config present in sudoplatformconfig.json. It defaults
|
|
28
|
+
* to 1 if not present.
|
|
29
|
+
*/
|
|
30
|
+
configVersion: number
|
|
31
|
+
/**
|
|
32
|
+
* The minimum supported service config version currently supported by the backend.
|
|
33
|
+
*/
|
|
34
|
+
minSupportedVersion?: number
|
|
35
|
+
/**
|
|
36
|
+
* Any service config version less than or equal to this version is considered deprecated
|
|
37
|
+
* and the backend may remove the support for those versions after a grace period.
|
|
38
|
+
*/
|
|
39
|
+
deprecatedVersion?: number
|
|
40
|
+
/**
|
|
41
|
+
* After this time any deprecated service config versions will no longer be compatible
|
|
42
|
+
* with the backend. It is recommended to warn the user prior to the deprecation grace.
|
|
43
|
+
*/
|
|
44
|
+
deprecationGrace?: Date
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Result returned by `validateConfig` API if an incompatible client config is found when compared
|
|
49
|
+
* to the deployed backend services.
|
|
50
|
+
*/
|
|
51
|
+
export interface ValidationResult {
|
|
52
|
+
/**
|
|
53
|
+
* The list of incompatible services. The client must be upgraded to the latest
|
|
54
|
+
* version in order to use these services.
|
|
55
|
+
*/
|
|
56
|
+
incompatible: ServiceCompatibilityInfo[]
|
|
57
|
+
/**
|
|
58
|
+
* The list of services that will be made incompatible with the current version of the
|
|
59
|
+
* client. The users should be warned that after the specified grace period these services will be
|
|
60
|
+
* made incompatible.
|
|
61
|
+
*/
|
|
62
|
+
deprecated: ServiceCompatibilityInfo[]
|
|
63
|
+
}
|
|
64
|
+
|
|
11
65
|
/**
|
|
12
66
|
* Interface that encapsulates the APIs common to all configuration manager implementations.
|
|
13
67
|
* A configuration manager should be a singleton that holds reference to a parsed config
|
|
@@ -62,6 +116,17 @@ export interface ConfigurationManager {
|
|
|
62
116
|
* @throws {@link DecodeError}
|
|
63
117
|
*/
|
|
64
118
|
bindConfigSet<T>(codec: t.Mixed, namespace?: string): T
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Validates the client configuration (sudoplatformconfig.json) against the currently deployed set of
|
|
122
|
+
* backend services. If the client configuration is valid, i.e. the client is compatible will all deployed
|
|
123
|
+
* backend services, then the call will complete with `success` result. If any part of the client
|
|
124
|
+
* configuration is incompatible then a detailed information on the incompatible service will be
|
|
125
|
+
* returned in `failure` result. See `SudoConfigManagerError.compatibilityIssueFound` for more details.
|
|
126
|
+
*
|
|
127
|
+
* @return validation result with the details of incompatible or deprecated service configurations.
|
|
128
|
+
*/
|
|
129
|
+
validateConfig(): Promise<ValidationResult>
|
|
65
130
|
}
|
|
66
131
|
|
|
67
132
|
/**
|
|
@@ -95,15 +160,9 @@ export class DefaultConfigurationManager implements ConfigurationManager {
|
|
|
95
160
|
throw new ConfigurationNotSetError()
|
|
96
161
|
}
|
|
97
162
|
|
|
98
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
99
163
|
const parsed = JSON.parse(this._config)
|
|
100
|
-
|
|
101
|
-
const configSet = namespace
|
|
102
|
-
? // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
103
|
-
parsed[namespace]
|
|
104
|
-
: parsed
|
|
164
|
+
const configSet = namespace ? parsed[namespace] : parsed
|
|
105
165
|
|
|
106
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
107
166
|
return configSet
|
|
108
167
|
}
|
|
109
168
|
|
|
@@ -129,4 +188,94 @@ export class DefaultConfigurationManager implements ConfigurationManager {
|
|
|
129
188
|
|
|
130
189
|
return this.bind<T>(configSet, codec)
|
|
131
190
|
}
|
|
191
|
+
|
|
192
|
+
public async validateConfig(): Promise<ValidationResult> {
|
|
193
|
+
if (!this._config) {
|
|
194
|
+
return { incompatible: [], deprecated: [] }
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const config = JSON.parse(this._config)
|
|
198
|
+
|
|
199
|
+
const region = config.identityService?.region
|
|
200
|
+
const bucket = config.identityService?.serviceInfoBucket
|
|
201
|
+
|
|
202
|
+
if (!(region && bucket)) {
|
|
203
|
+
return { incompatible: [], deprecated: [] }
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const s3Client = new AWS.S3({ region: region })
|
|
207
|
+
|
|
208
|
+
const incompatible: ServiceCompatibilityInfo[] = []
|
|
209
|
+
const deprecated: ServiceCompatibilityInfo[] = []
|
|
210
|
+
|
|
211
|
+
const objects = await s3Client
|
|
212
|
+
.makeUnauthenticatedRequest('listObjects', {
|
|
213
|
+
Bucket: bucket,
|
|
214
|
+
})
|
|
215
|
+
.promise()
|
|
216
|
+
|
|
217
|
+
if (!objects.Contents?.length) {
|
|
218
|
+
return { incompatible: [], deprecated: [] }
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const keys = objects.Contents.map((object: any) => object.Key)
|
|
222
|
+
|
|
223
|
+
// Only fetch the service info docs for the services that are present in client config
|
|
224
|
+
// to minimize the network calls.
|
|
225
|
+
const keysToFetch = keys.filter(
|
|
226
|
+
(key: string) =>
|
|
227
|
+
key.endsWith('.json') && config[key.replace('.json', '')],
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
for (const key of keysToFetch) {
|
|
231
|
+
const object = await s3Client
|
|
232
|
+
.makeUnauthenticatedRequest('getObject', {
|
|
233
|
+
Key: key,
|
|
234
|
+
Bucket: bucket,
|
|
235
|
+
})
|
|
236
|
+
.promise()
|
|
237
|
+
|
|
238
|
+
let body: string
|
|
239
|
+
|
|
240
|
+
if (typeof object.Body === 'string') {
|
|
241
|
+
body = object.Body
|
|
242
|
+
} else if (ArrayBuffer.isView(object.Body)) {
|
|
243
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
244
|
+
body = new TextDecoder().decode(object.Body)
|
|
245
|
+
} else {
|
|
246
|
+
continue
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const json = JSON.parse(body)
|
|
250
|
+
const serviceName = key.replace('.json', '')
|
|
251
|
+
const serviceInfo: any = json[serviceName]
|
|
252
|
+
const serviceConfig: any = config[serviceName]
|
|
253
|
+
if (serviceInfo && serviceConfig) {
|
|
254
|
+
const currentVersion: number = serviceConfig.version ?? 1
|
|
255
|
+
const deprecationGrace: number = serviceInfo.deprecationGrace ?? -1
|
|
256
|
+
const compatibilityInfo: ServiceCompatibilityInfo = {
|
|
257
|
+
name: serviceName,
|
|
258
|
+
configVersion: currentVersion,
|
|
259
|
+
minSupportedVersion: serviceInfo.minVersion,
|
|
260
|
+
deprecatedVersion: serviceInfo.deprecated,
|
|
261
|
+
deprecationGrace:
|
|
262
|
+
deprecationGrace != -1 ? new Date(deprecationGrace) : undefined,
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// If the service config in `sudoplatformconfig.json` is less than the
|
|
266
|
+
// minimum supported version then the client is incompatible.
|
|
267
|
+
if (currentVersion < (compatibilityInfo.minSupportedVersion ?? 0)) {
|
|
268
|
+
incompatible.push(compatibilityInfo)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// If the service config is less than or equal to the deprecated version
|
|
272
|
+
// then it will be made incompatible after the deprecation grace.
|
|
273
|
+
if (currentVersion <= (compatibilityInfo.deprecatedVersion ?? 0)) {
|
|
274
|
+
deprecated.push(compatibilityInfo)
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return { incompatible, deprecated }
|
|
280
|
+
}
|
|
132
281
|
}
|
|
@@ -425,7 +425,9 @@ export class UnrecognizedAlgorithmError extends Error {
|
|
|
425
425
|
* @param error The App Sync error to map
|
|
426
426
|
* @returns The mapped error
|
|
427
427
|
*/
|
|
428
|
-
export function mapGraphQLToClientError(
|
|
428
|
+
export function mapGraphQLToClientError(
|
|
429
|
+
error: Pick<AppSyncError, 'errorType' | 'message'>,
|
|
430
|
+
): Error {
|
|
429
431
|
switch (error.errorType) {
|
|
430
432
|
case 'sudoplatform.AccountLockedError':
|
|
431
433
|
return new AccountLockedError()
|
|
@@ -435,6 +437,8 @@ export function mapGraphQLToClientError(error: AppSyncError): Error {
|
|
|
435
437
|
return new InvalidTokenError()
|
|
436
438
|
case 'sudoplatform.InvalidArgumentError':
|
|
437
439
|
return new IllegalArgumentError()
|
|
440
|
+
case 'sudoplatform.LimitExceededError':
|
|
441
|
+
return new LimitExceededError()
|
|
438
442
|
case 'sudoplatform.NoEntitlementsError':
|
|
439
443
|
return new NoEntitlementsError()
|
|
440
444
|
case 'sudoplatform.ServiceError':
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { DefaultConfigurationManager } from '../../src/configurationManager/defaultConfigurationManager'
|
|
2
|
+
import { readFileSync, existsSync } from 'fs'
|
|
3
|
+
import { TextEncoder, TextDecoder } from 'util'
|
|
4
|
+
|
|
5
|
+
global.TextEncoder = TextEncoder
|
|
6
|
+
global.TextDecoder = TextDecoder
|
|
7
|
+
|
|
8
|
+
describe('configuration manager', () => {
|
|
9
|
+
const configFilePath = 'config/sudoplatformconfig.json'
|
|
10
|
+
if (existsSync(configFilePath)) {
|
|
11
|
+
const config = readFileSync(configFilePath, 'utf-8')
|
|
12
|
+
const json = JSON.parse(config)
|
|
13
|
+
|
|
14
|
+
describe('validateConfig', () => {
|
|
15
|
+
it('should return deprecated service info if equal to deprecated version', async () => {
|
|
16
|
+
const config = {
|
|
17
|
+
identityService: {
|
|
18
|
+
region: json.identityService.region,
|
|
19
|
+
serviceInfoBucket: json.identityService.serviceInfoBucket,
|
|
20
|
+
},
|
|
21
|
+
vcService: {
|
|
22
|
+
version: 3,
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const manager = DefaultConfigurationManager.getInstance().setConfig(
|
|
27
|
+
JSON.stringify(config),
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
await expect(manager.validateConfig()).resolves.toEqual({
|
|
31
|
+
deprecated: [
|
|
32
|
+
{
|
|
33
|
+
configVersion: 3,
|
|
34
|
+
minSupportedVersion: 2,
|
|
35
|
+
deprecatedVersion: 3,
|
|
36
|
+
name: 'vcService',
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
incompatible: [],
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('should return incompatible service info if less than min version', async () => {
|
|
44
|
+
const config = {
|
|
45
|
+
identityService: {
|
|
46
|
+
region: json.identityService.region,
|
|
47
|
+
serviceInfoBucket: json.identityService.serviceInfoBucket,
|
|
48
|
+
},
|
|
49
|
+
vcService: {
|
|
50
|
+
version: 1,
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const manager = DefaultConfigurationManager.getInstance().setConfig(
|
|
55
|
+
JSON.stringify(config),
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
await expect(manager.validateConfig()).resolves.toEqual({
|
|
59
|
+
deprecated: [
|
|
60
|
+
{
|
|
61
|
+
configVersion: 1,
|
|
62
|
+
minSupportedVersion: 2,
|
|
63
|
+
deprecatedVersion: 3,
|
|
64
|
+
name: 'vcService',
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
incompatible: [
|
|
68
|
+
{
|
|
69
|
+
configVersion: 1,
|
|
70
|
+
minSupportedVersion: 2,
|
|
71
|
+
deprecatedVersion: 3,
|
|
72
|
+
name: 'vcService',
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
} else {
|
|
79
|
+
it('Skip all tests.', () => {
|
|
80
|
+
console.log(
|
|
81
|
+
'No sudoplatformconfig.json, test key and test key ID file found. Skipping all integration tests.',
|
|
82
|
+
)
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
})
|