@kravc/dos 1.12.6 → 2.0.0-alpha.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/README.md +31 -994
- package/dist/Component/Component.d.ts +43 -0
- package/dist/Component/Component.d.ts.map +1 -0
- package/dist/Component/Component.js +99 -0
- package/dist/Component/Component.js.map +1 -0
- package/dist/Component/index.d.ts +4 -0
- package/dist/Component/index.d.ts.map +1 -0
- package/dist/Component/index.js +10 -0
- package/dist/Component/index.js.map +1 -0
- package/dist/Context/Context.d.ts +86 -0
- package/dist/Context/Context.d.ts.map +1 -0
- package/dist/Context/Context.js +148 -0
- package/dist/Context/Context.js.map +1 -0
- package/dist/Context/Request.d.ts +35 -0
- package/dist/Context/Request.d.ts.map +1 -0
- package/dist/Context/Request.js +3 -0
- package/dist/Context/Request.js.map +1 -0
- package/dist/Context/__tests__/__helpers.d.ts +14 -0
- package/dist/Context/__tests__/__helpers.d.ts.map +1 -0
- package/dist/Context/__tests__/__helpers.js +69 -0
- package/dist/Context/__tests__/__helpers.js.map +1 -0
- package/dist/Context/getHttpMethod.d.ts +6 -0
- package/dist/Context/getHttpMethod.d.ts.map +1 -0
- package/dist/Context/getHttpMethod.js +16 -0
- package/dist/Context/getHttpMethod.js.map +1 -0
- package/dist/Context/getHttpPath.d.ts +6 -0
- package/dist/Context/getHttpPath.d.ts.map +1 -0
- package/dist/Context/getHttpPath.js +25 -0
- package/dist/Context/getHttpPath.js.map +1 -0
- package/dist/Context/getMutationParameters.d.ts +8 -0
- package/dist/Context/getMutationParameters.d.ts.map +1 -0
- package/dist/Context/getMutationParameters.js +25 -0
- package/dist/Context/getMutationParameters.js.map +1 -0
- package/dist/Context/getOperationId.d.ts +6 -0
- package/dist/Context/getOperationId.d.ts.map +1 -0
- package/dist/Context/getOperationId.js +21 -0
- package/dist/Context/getOperationId.js.map +1 -0
- package/dist/Context/getQueryParameters.d.ts +5 -0
- package/dist/Context/getQueryParameters.d.ts.map +1 -0
- package/dist/Context/getQueryParameters.js +33 -0
- package/dist/Context/getQueryParameters.js.map +1 -0
- package/dist/Context/index.d.ts +7 -0
- package/dist/Context/index.d.ts.map +1 -0
- package/dist/Context/index.js +12 -0
- package/dist/Context/index.js.map +1 -0
- package/dist/Context/withSafeAttributes.d.ts +23 -0
- package/dist/Context/withSafeAttributes.d.ts.map +1 -0
- package/dist/Context/withSafeAttributes.js +39 -0
- package/dist/Context/withSafeAttributes.js.map +1 -0
- package/dist/Document/Document.d.ts +114 -0
- package/dist/Document/Document.d.ts.map +1 -0
- package/dist/Document/Document.js +285 -0
- package/dist/Document/Document.js.map +1 -0
- package/dist/Document/MemoryDocument.d.ts +34 -0
- package/dist/Document/MemoryDocument.d.ts.map +1 -0
- package/dist/Document/MemoryDocument.js +103 -0
- package/dist/Document/MemoryDocument.js.map +1 -0
- package/dist/Document/__tests__/__helpers.d.ts +18 -0
- package/dist/Document/__tests__/__helpers.d.ts.map +1 -0
- package/dist/Document/__tests__/__helpers.js +28 -0
- package/dist/Document/__tests__/__helpers.js.map +1 -0
- package/dist/Document/index.d.ts +5 -0
- package/dist/Document/index.d.ts.map +1 -0
- package/dist/Document/index.js +11 -0
- package/dist/Document/index.js.map +1 -0
- package/dist/Operation/Operation.d.ts +95 -0
- package/dist/Operation/Operation.d.ts.map +1 -0
- package/dist/Operation/Operation.js +301 -0
- package/dist/Operation/Operation.js.map +1 -0
- package/dist/Operation/errors/AccessDeniedError.d.ts +22 -0
- package/dist/Operation/errors/AccessDeniedError.d.ts.map +1 -0
- package/dist/Operation/errors/AccessDeniedError.js +29 -0
- package/dist/Operation/errors/AccessDeniedError.js.map +1 -0
- package/dist/Operation/errors/CommonError.d.ts +30 -0
- package/dist/Operation/errors/CommonError.d.ts.map +1 -0
- package/dist/Operation/errors/CommonError.js +39 -0
- package/dist/Operation/errors/CommonError.js.map +1 -0
- package/dist/Operation/errors/DocumentExistsError.d.ts +27 -0
- package/dist/Operation/errors/DocumentExistsError.d.ts.map +1 -0
- package/dist/Operation/errors/DocumentExistsError.js +35 -0
- package/dist/Operation/errors/DocumentExistsError.js.map +1 -0
- package/dist/Operation/errors/DocumentNotFoundError.d.ts +28 -0
- package/dist/Operation/errors/DocumentNotFoundError.d.ts.map +1 -0
- package/dist/Operation/errors/DocumentNotFoundError.js +36 -0
- package/dist/Operation/errors/DocumentNotFoundError.js.map +1 -0
- package/dist/Operation/errors/InvalidParametersError.d.ts +27 -0
- package/dist/Operation/errors/InvalidParametersError.d.ts.map +1 -0
- package/dist/Operation/errors/InvalidParametersError.js +34 -0
- package/dist/Operation/errors/InvalidParametersError.js.map +1 -0
- package/dist/Operation/errors/UnauthorizedError.d.ts +25 -0
- package/dist/Operation/errors/UnauthorizedError.d.ts.map +1 -0
- package/dist/Operation/errors/UnauthorizedError.js +32 -0
- package/dist/Operation/errors/UnauthorizedError.js.map +1 -0
- package/dist/Operation/errors/UnprocessibleConditionError.d.ts +29 -0
- package/dist/Operation/errors/UnprocessibleConditionError.d.ts.map +1 -0
- package/dist/Operation/errors/UnprocessibleConditionError.js +36 -0
- package/dist/Operation/errors/UnprocessibleConditionError.js.map +1 -0
- package/dist/Operation/errors/index.d.ts +9 -0
- package/dist/Operation/errors/index.d.ts.map +1 -0
- package/dist/Operation/errors/index.js +21 -0
- package/dist/Operation/errors/index.js.map +1 -0
- package/dist/Operation/helpers/index.d.ts +4 -0
- package/dist/Operation/helpers/index.d.ts.map +1 -0
- package/dist/Operation/helpers/index.js +9 -0
- package/dist/Operation/helpers/index.js.map +1 -0
- package/dist/Operation/helpers/withActivity.d.ts +16 -0
- package/dist/Operation/helpers/withActivity.d.ts.map +1 -0
- package/dist/Operation/helpers/withActivity.js +23 -0
- package/dist/Operation/helpers/withActivity.js.map +1 -0
- package/dist/Operation/index.d.ts +14 -0
- package/dist/Operation/index.d.ts.map +1 -0
- package/dist/Operation/index.js +40 -0
- package/dist/Operation/index.js.map +1 -0
- package/dist/Operation/operations/Create.d.ts +5 -0
- package/dist/Operation/operations/Create.d.ts.map +1 -0
- package/dist/Operation/operations/Create.js +44 -0
- package/dist/Operation/operations/Create.js.map +1 -0
- package/dist/Operation/operations/Delete.d.ts +5 -0
- package/dist/Operation/operations/Delete.d.ts.map +1 -0
- package/dist/Operation/operations/Delete.js +58 -0
- package/dist/Operation/operations/Delete.js.map +1 -0
- package/dist/Operation/operations/Index.d.ts +11 -0
- package/dist/Operation/operations/Index.d.ts.map +1 -0
- package/dist/Operation/operations/Index.js +128 -0
- package/dist/Operation/operations/Index.js.map +1 -0
- package/dist/Operation/operations/List.d.ts +5 -0
- package/dist/Operation/operations/List.d.ts.map +1 -0
- package/dist/Operation/operations/List.js +48 -0
- package/dist/Operation/operations/List.js.map +1 -0
- package/dist/Operation/operations/Read.d.ts +5 -0
- package/dist/Operation/operations/Read.d.ts.map +1 -0
- package/dist/Operation/operations/Read.js +50 -0
- package/dist/Operation/operations/Read.js.map +1 -0
- package/dist/Operation/operations/Update.d.ts +5 -0
- package/dist/Operation/operations/Update.d.ts.map +1 -0
- package/dist/Operation/operations/Update.js +54 -0
- package/dist/Operation/operations/Update.js.map +1 -0
- package/dist/Operation/security/JwtAuthorization.d.ts +67 -0
- package/dist/Operation/security/JwtAuthorization.d.ts.map +1 -0
- package/dist/Operation/security/JwtAuthorization.js +148 -0
- package/dist/Operation/security/JwtAuthorization.js.map +1 -0
- package/dist/Operation/security/LambdaAuthorization.d.ts +30 -0
- package/dist/Operation/security/LambdaAuthorization.d.ts.map +1 -0
- package/dist/Operation/security/LambdaAuthorization.js +77 -0
- package/dist/Operation/security/LambdaAuthorization.js.map +1 -0
- package/dist/Operation/security/index.d.ts +8 -0
- package/dist/Operation/security/index.d.ts.map +1 -0
- package/dist/Operation/security/index.js +17 -0
- package/dist/Operation/security/index.js.map +1 -0
- package/dist/Operation/security/systemAuthorization.d.ts +5 -0
- package/dist/Operation/security/systemAuthorization.d.ts.map +1 -0
- package/dist/Operation/security/systemAuthorization.js +24 -0
- package/dist/Operation/security/systemAuthorization.js.map +1 -0
- package/dist/Operation/security/userAuthorization.d.ts +11 -0
- package/dist/Operation/security/userAuthorization.d.ts.map +1 -0
- package/dist/Operation/security/userAuthorization.js +36 -0
- package/dist/Operation/security/userAuthorization.js.map +1 -0
- package/dist/Operation/security/verifyToken.d.ts +6 -0
- package/dist/Operation/security/verifyToken.d.ts.map +1 -0
- package/dist/Operation/security/verifyToken.js +15 -0
- package/dist/Operation/security/verifyToken.js.map +1 -0
- package/dist/Service/Service.d.ts +62 -0
- package/dist/Service/Service.d.ts.map +1 -0
- package/dist/Service/Service.js +213 -0
- package/dist/Service/Service.js.map +1 -0
- package/dist/Service/authorize.d.ts +26 -0
- package/dist/Service/authorize.d.ts.map +1 -0
- package/dist/Service/authorize.js +40 -0
- package/dist/Service/authorize.js.map +1 -0
- package/dist/Service/errors/InvalidInputError.d.ts +29 -0
- package/dist/Service/errors/InvalidInputError.d.ts.map +1 -0
- package/dist/Service/errors/InvalidInputError.js +36 -0
- package/dist/Service/errors/InvalidInputError.js.map +1 -0
- package/dist/Service/errors/InvalidOutputError.d.ts +29 -0
- package/dist/Service/errors/InvalidOutputError.d.ts.map +1 -0
- package/dist/Service/errors/InvalidOutputError.js +36 -0
- package/dist/Service/errors/InvalidOutputError.js.map +1 -0
- package/dist/Service/errors/OperationError.d.ts +30 -0
- package/dist/Service/errors/OperationError.d.ts.map +1 -0
- package/dist/Service/errors/OperationError.js +61 -0
- package/dist/Service/errors/OperationError.js.map +1 -0
- package/dist/Service/errors/OperationNotFoundError.d.ts +38 -0
- package/dist/Service/errors/OperationNotFoundError.d.ts.map +1 -0
- package/dist/Service/errors/OperationNotFoundError.js +45 -0
- package/dist/Service/errors/OperationNotFoundError.js.map +1 -0
- package/dist/Service/errors/index.d.ts +8 -0
- package/dist/Service/errors/index.d.ts.map +1 -0
- package/dist/Service/errors/index.js +15 -0
- package/dist/Service/errors/index.js.map +1 -0
- package/dist/Service/errors/logOperationError.d.ts +35 -0
- package/dist/Service/errors/logOperationError.d.ts.map +1 -0
- package/dist/Service/errors/logOperationError.js +47 -0
- package/dist/Service/errors/logOperationError.js.map +1 -0
- package/dist/Service/errors/maskSecrets.d.ts +13 -0
- package/dist/Service/errors/maskSecrets.d.ts.map +1 -0
- package/dist/Service/errors/maskSecrets.js +57 -0
- package/dist/Service/errors/maskSecrets.js.map +1 -0
- package/dist/Service/index.d.ts +5 -0
- package/dist/Service/index.d.ts.map +1 -0
- package/dist/Service/index.js +25 -0
- package/dist/Service/index.js.map +1 -0
- package/dist/Service/logRequest.d.ts +5 -0
- package/dist/Service/logRequest.d.ts.map +1 -0
- package/dist/Service/logRequest.js +26 -0
- package/dist/Service/logRequest.js.map +1 -0
- package/dist/Service/spec/createSpec.d.ts +7 -0
- package/dist/Service/spec/createSpec.d.ts.map +1 -0
- package/dist/Service/spec/createSpec.js +56 -0
- package/dist/Service/spec/createSpec.js.map +1 -0
- package/dist/Service/spec/getErrorResponseDescription.d.ts +8 -0
- package/dist/Service/spec/getErrorResponseDescription.d.ts.map +1 -0
- package/dist/Service/spec/getErrorResponseDescription.js +15 -0
- package/dist/Service/spec/getErrorResponseDescription.js.map +1 -0
- package/dist/Service/spec/getHttpMethod.d.ts +4 -0
- package/dist/Service/spec/getHttpMethod.d.ts.map +1 -0
- package/dist/Service/spec/getHttpMethod.js +21 -0
- package/dist/Service/spec/getHttpMethod.js.map +1 -0
- package/dist/Service/spec/getOperation.d.ts +6 -0
- package/dist/Service/spec/getOperation.d.ts.map +1 -0
- package/dist/Service/spec/getOperation.js +71 -0
- package/dist/Service/spec/getOperation.js.map +1 -0
- package/dist/Service/spec/getOperationParameters.d.ts +6 -0
- package/dist/Service/spec/getOperationParameters.d.ts.map +1 -0
- package/dist/Service/spec/getOperationParameters.js +32 -0
- package/dist/Service/spec/getOperationParameters.js.map +1 -0
- package/dist/Service/spec/getServiceDefinitions.d.ts +6 -0
- package/dist/Service/spec/getServiceDefinitions.d.ts.map +1 -0
- package/dist/Service/spec/getServiceDefinitions.js +18 -0
- package/dist/Service/spec/getServiceDefinitions.js.map +1 -0
- package/dist/Service/spec/getServiceInfo.d.ts +7 -0
- package/dist/Service/spec/getServiceInfo.d.ts.map +1 -0
- package/dist/Service/spec/getServiceInfo.js +15 -0
- package/dist/Service/spec/getServiceInfo.js.map +1 -0
- package/dist/Service/spec/getServiceSecurityDefinitions.d.ts +6 -0
- package/dist/Service/spec/getServiceSecurityDefinitions.d.ts.map +1 -0
- package/dist/Service/spec/getServiceSecurityDefinitions.js +21 -0
- package/dist/Service/spec/getServiceSecurityDefinitions.js.map +1 -0
- package/dist/Service/spec/getServiceTags.d.ts +7 -0
- package/dist/Service/spec/getServiceTags.d.ts.map +1 -0
- package/dist/Service/spec/getServiceTags.js +19 -0
- package/dist/Service/spec/getServiceTags.js.map +1 -0
- package/dist/Service/spec/getSuccessStatusCode.d.ts +4 -0
- package/dist/Service/spec/getSuccessStatusCode.d.ts.map +1 -0
- package/dist/Service/spec/getSuccessStatusCode.js +14 -0
- package/dist/Service/spec/getSuccessStatusCode.js.map +1 -0
- package/dist/Service/spec/index.d.ts +3 -0
- package/dist/Service/spec/index.d.ts.map +1 -0
- package/dist/Service/spec/index.js +9 -0
- package/dist/Service/spec/index.js.map +1 -0
- package/dist/Service/spec/validateSpec.d.ts +5 -0
- package/dist/Service/spec/validateSpec.d.ts.map +1 -0
- package/dist/Service/spec/validateSpec.js +21 -0
- package/dist/Service/spec/validateSpec.js.map +1 -0
- package/dist/Service/test/createAccessToken.d.ts +9 -0
- package/dist/Service/test/createAccessToken.d.ts.map +1 -0
- package/dist/Service/test/createAccessToken.js +16 -0
- package/dist/Service/test/createAccessToken.js.map +1 -0
- package/dist/Service/test/ensureItem.d.ts +5 -0
- package/dist/Service/test/ensureItem.d.ts.map +1 -0
- package/dist/Service/test/ensureItem.js +13 -0
- package/dist/Service/test/ensureItem.js.map +1 -0
- package/dist/Service/test/ensureNoItem.d.ts +5 -0
- package/dist/Service/test/ensureNoItem.d.ts.map +1 -0
- package/dist/Service/test/ensureNoItem.js +13 -0
- package/dist/Service/test/ensureNoItem.js.map +1 -0
- package/dist/Service/test/execute.d.ts +44 -0
- package/dist/Service/test/execute.d.ts.map +1 -0
- package/dist/Service/test/execute.js +65 -0
- package/dist/Service/test/execute.js.map +1 -0
- package/dist/Service/test/findItem.d.ts +7 -0
- package/dist/Service/test/findItem.d.ts.map +1 -0
- package/dist/Service/test/findItem.js +16 -0
- package/dist/Service/test/findItem.js.map +1 -0
- package/dist/Service/test/firstItemGet.d.ts +5 -0
- package/dist/Service/test/firstItemGet.d.ts.map +1 -0
- package/dist/Service/test/firstItemGet.js +15 -0
- package/dist/Service/test/firstItemGet.js.map +1 -0
- package/dist/Service/test/index.d.ts +10 -0
- package/dist/Service/test/index.d.ts.map +1 -0
- package/dist/Service/test/index.js +36 -0
- package/dist/Service/test/index.js.map +1 -0
- package/dist/Service/test/keys.d.ts +5 -0
- package/dist/Service/test/keys.d.ts.map +1 -0
- package/dist/Service/test/keys.js +74 -0
- package/dist/Service/test/keys.js.map +1 -0
- package/dist/Service/test/wait.d.ts +4 -0
- package/dist/Service/test/wait.d.ts.map +1 -0
- package/dist/Service/test/wait.js +6 -0
- package/dist/Service/test/wait.js.map +1 -0
- package/dist/Service/useComposerMiddleware.d.ts +11 -0
- package/dist/Service/useComposerMiddleware.d.ts.map +1 -0
- package/dist/Service/useComposerMiddleware.js +41 -0
- package/dist/Service/useComposerMiddleware.js.map +1 -0
- package/dist/Service/useOasMiddleware.d.ts +16 -0
- package/dist/Service/useOasMiddleware.d.ts.map +1 -0
- package/dist/Service/useOasMiddleware.js +53 -0
- package/dist/Service/useOasMiddleware.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/eslint.config.mjs +32 -52
- package/example/documents/Profile/Profile.ts +8 -0
- package/example/documents/Profile/Profile.yaml +6 -0
- package/example/documents/Profile/ProfileAttributes.d.ts +5 -0
- package/example/documents/Profile/index.ts +3 -0
- package/example/documents/index.ts +5 -0
- package/example/index.ts +38 -0
- package/example/lib/createActivity.ts +28 -0
- package/example/lib/index.ts +24 -0
- package/example/operations/Profile/CreateProfile.ts +9 -0
- package/example/operations/Profile/DeleteProfile.ts +9 -0
- package/example/operations/Profile/IndexProfiles.ts +9 -0
- package/example/operations/Profile/ReadProfile.ts +9 -0
- package/example/operations/Profile/ReadProfileSystem.ts +9 -0
- package/example/operations/Profile/UpdateProfile.ts +9 -0
- package/example/operations/Service/Health.ts +11 -0
- package/example/operations/index.ts +22 -0
- package/example/security/index.ts +25 -0
- package/jest.config.mjs +7 -0
- package/package.json +34 -24
- package/src/Component/Component.ts +120 -0
- package/src/Component/__tests__/Component.test.ts +161 -0
- package/src/Component/index.ts +7 -0
- package/src/Context/Context.ts +217 -0
- package/src/Context/Request.ts +41 -0
- package/src/Context/__tests__/Context.test.ts +271 -0
- package/src/Context/__tests__/__helpers.ts +86 -0
- package/src/Context/getHttpMethod.ts +21 -0
- package/src/Context/getHttpPath.ts +34 -0
- package/src/Context/getMutationParameters.ts +35 -0
- package/src/Context/getOperationId.ts +23 -0
- package/src/Context/getQueryParameters.ts +45 -0
- package/src/Context/index.ts +12 -0
- package/src/Context/withSafeAttributes.ts +39 -0
- package/src/Document/Document.ts +448 -0
- package/src/Document/MemoryDocument.ts +152 -0
- package/src/Document/__tests__/MemoryDocument.test.ts +406 -0
- package/src/Document/__tests__/__helpers.ts +40 -0
- package/src/Document/index.ts +11 -0
- package/src/Operation/Operation.ts +401 -0
- package/src/Operation/__tests__/Operation.test.ts +142 -0
- package/src/Operation/errors/AccessDeniedError.ts +25 -0
- package/src/Operation/errors/CommonError.ts +41 -0
- package/src/Operation/errors/DocumentExistsError.ts +33 -0
- package/src/Operation/errors/DocumentNotFoundError.ts +34 -0
- package/src/Operation/errors/InvalidParametersError.ts +30 -0
- package/src/Operation/errors/UnauthorizedError.ts +28 -0
- package/src/Operation/errors/UnprocessibleConditionError.ts +32 -0
- package/src/Operation/errors/__tests__/InvalidParametersError.test.ts +20 -0
- package/src/Operation/errors/__tests__/UnprocessibleConditionError.test.ts +20 -0
- package/src/Operation/errors/index.ts +17 -0
- package/src/Operation/helpers/index.ts +9 -0
- package/src/Operation/helpers/withActivity.ts +43 -0
- package/src/Operation/index.ts +29 -0
- package/src/Operation/operations/Create.ts +49 -0
- package/src/Operation/operations/Delete.ts +65 -0
- package/src/Operation/operations/Index.ts +164 -0
- package/src/Operation/operations/List.ts +62 -0
- package/src/Operation/operations/Read.ts +55 -0
- package/src/Operation/operations/Update.ts +60 -0
- package/src/Operation/operations/__tests__/Create.test.ts +153 -0
- package/src/Operation/operations/__tests__/Delete.test.ts +163 -0
- package/src/Operation/operations/__tests__/Index.test.ts +209 -0
- package/src/Operation/operations/__tests__/List.test.ts +146 -0
- package/src/Operation/operations/__tests__/Read.test.ts +152 -0
- package/src/Operation/operations/__tests__/Update.test.ts +158 -0
- package/src/Operation/security/JwtAuthorization.ts +247 -0
- package/src/Operation/security/LambdaAuthorization.ts +103 -0
- package/src/Operation/security/__tests__/JwtAuthorization.test.ts +230 -0
- package/src/Operation/security/__tests__/LambdaAuthorization.test.ts +63 -0
- package/src/Operation/security/__tests__/userAuthorization.test.ts +42 -0
- package/src/Operation/security/index.ts +15 -0
- package/src/Operation/security/systemAuthorization.ts +23 -0
- package/src/Operation/security/userAuthorization.ts +47 -0
- package/src/Operation/security/verifyToken.ts +22 -0
- package/src/Service/Service.ts +317 -0
- package/src/Service/__tests__/Service.test.ts +229 -0
- package/src/Service/authorize.ts +80 -0
- package/src/Service/errors/InvalidInputError.ts +40 -0
- package/src/Service/errors/InvalidOutputError.ts +40 -0
- package/src/Service/errors/OperationError.ts +74 -0
- package/src/{errors → Service/errors}/OperationError.yaml +7 -10
- package/src/Service/errors/OperationErrorAttributes.d.ts +12 -0
- package/src/Service/errors/OperationNotFoundError.ts +45 -0
- package/src/Service/errors/__tests__/OperationError.test.ts +17 -0
- package/src/Service/errors/__tests__/maskSecrets.test.ts +92 -0
- package/src/Service/errors/index.ts +18 -0
- package/src/Service/errors/logOperationError.ts +72 -0
- package/src/Service/errors/maskSecrets.ts +65 -0
- package/src/Service/index.ts +9 -0
- package/src/Service/logRequest.ts +50 -0
- package/src/Service/spec/__tests__/validateSpec.test.ts +10 -0
- package/src/Service/spec/createSpec.ts +68 -0
- package/src/Service/spec/getErrorResponseDescription.ts +20 -0
- package/src/Service/spec/getHttpMethod.ts +20 -0
- package/src/Service/spec/getOperation.ts +99 -0
- package/src/Service/spec/getOperationParameters.ts +43 -0
- package/src/Service/spec/getServiceDefinitions.ts +23 -0
- package/src/Service/spec/getServiceInfo.ts +18 -0
- package/src/Service/spec/getServiceSecurityDefinitions.ts +26 -0
- package/src/Service/spec/getServiceTags.ts +23 -0
- package/src/Service/spec/getSuccessStatusCode.ts +15 -0
- package/src/Service/spec/index.ts +5 -0
- package/src/Service/spec/validateSpec.ts +22 -0
- package/src/Service/test/__tests__/createAccessToken.test.ts +104 -0
- package/src/Service/test/__tests__/ensureItem.test.ts +41 -0
- package/src/Service/test/__tests__/ensureNoItem.test.ts +49 -0
- package/src/Service/test/__tests__/execute.test.ts +125 -0
- package/src/Service/test/__tests__/findItem.test.ts +45 -0
- package/src/Service/test/__tests__/firstItemGet.test.ts +50 -0
- package/src/Service/test/__tests__/wait.test.ts +66 -0
- package/src/Service/test/createAccessToken.ts +28 -0
- package/src/Service/test/ensureItem.ts +9 -0
- package/src/Service/test/ensureNoItem.ts +9 -0
- package/src/Service/test/execute.ts +112 -0
- package/src/Service/test/findItem.ts +22 -0
- package/src/Service/test/firstItemGet.ts +18 -0
- package/src/Service/test/index.ts +19 -0
- package/src/Service/test/keys.ts +75 -0
- package/src/Service/test/wait.ts +5 -0
- package/src/Service/useComposerMiddleware.ts +56 -0
- package/src/Service/useOasMiddleware.ts +69 -0
- package/src/index.ts +12 -0
- package/tsconfig.json +26 -0
- package/examples/CreateProfile.js +0 -40
- package/examples/DeleteProfile.js +0 -6
- package/examples/Health.js +0 -8
- package/examples/IndexProfiles.js +0 -6
- package/examples/Profile.js +0 -8
- package/examples/Profile.yaml +0 -4
- package/examples/ReadProfile.js +0 -18
- package/examples/UpdateProfile.js +0 -25
- package/examples/index.js +0 -29
- package/src/Component.js +0 -59
- package/src/Component.spec.js +0 -65
- package/src/Document.js +0 -310
- package/src/Document.spec.js +0 -331
- package/src/Operation.js +0 -258
- package/src/Operation.spec.js +0 -474
- package/src/Service.js +0 -207
- package/src/Service.spec.js +0 -388
- package/src/errors/AccessDeniedError.js +0 -11
- package/src/errors/CommonError.js +0 -19
- package/src/errors/DocumentExistsError.js +0 -15
- package/src/errors/DocumentNotFoundError.js +0 -15
- package/src/errors/InvalidInputError.js +0 -19
- package/src/errors/InvalidOutputError.js +0 -20
- package/src/errors/InvalidParametersError.js +0 -11
- package/src/errors/OperationError.js +0 -44
- package/src/errors/OperationNotFoundError.js +0 -16
- package/src/errors/UnauthorizedError.js +0 -11
- package/src/errors/UnprocessibleConditionError.js +0 -11
- package/src/errors/index.js +0 -11
- package/src/helpers/asSafeClass.js +0 -22
- package/src/helpers/authorize.js +0 -44
- package/src/helpers/createContext.js +0 -96
- package/src/helpers/createSchemasMap.js +0 -37
- package/src/helpers/createSpec.js +0 -196
- package/src/helpers/defaultId.js +0 -30
- package/src/helpers/defaultSummary.js +0 -15
- package/src/helpers/defaultTags.js +0 -16
- package/src/helpers/getComponentTitle.js +0 -22
- package/src/helpers/getDefaultSchemaAttributes.js +0 -32
- package/src/helpers/getHttpMethod.js +0 -19
- package/src/helpers/getIdPrefix.js +0 -7
- package/src/helpers/getOrFail.js +0 -24
- package/src/helpers/getOrFail.spec.js +0 -17
- package/src/helpers/getSuccessStatusCode.js +0 -15
- package/src/helpers/handler.js +0 -21
- package/src/helpers/loadSync.js +0 -14
- package/src/helpers/logError.js +0 -33
- package/src/helpers/logRequest.js +0 -36
- package/src/helpers/maskSecrets.js +0 -42
- package/src/helpers/specMiddleware.js +0 -81
- package/src/index.d.ts +0 -352
- package/src/index.js +0 -35
- package/src/operations/Create.js +0 -39
- package/src/operations/Delete.js +0 -54
- package/src/operations/Index.js +0 -107
- package/src/operations/Read.js +0 -46
- package/src/operations/Update.js +0 -50
- package/src/security/JwtAuthorization.js +0 -125
- package/src/security/SystemAuthorization.js +0 -73
- package/src/security/index.js +0 -9
- package/src/security/verifyToken.js +0 -17
- package/src/test/createAccessToken.js +0 -23
- package/src/test/execute.js +0 -84
- package/src/test/index.js +0 -11
- package/src/test/keys.js +0 -39
- package/src/test/wait.js +0 -5
- /package/{specs → .composer}/Documents.yaml +0 -0
- /package/{specs → .composer}/Enums.yaml +0 -0
- /package/{specs → .composer}/Operations.yaml +0 -0
- /package/{specs → .composer}/Parameters.yaml +0 -0
- /package/{specs → .composer}/Scenarios.yaml +0 -0
- /package/{specs → .composer}/Schemas.yaml +0 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { Profile } from '../../../Document/__tests__/__helpers';
|
|
2
|
+
import { createContext } from '../../../Context/__tests__/__helpers';
|
|
3
|
+
import { List, Operation } from '../../../';
|
|
4
|
+
|
|
5
|
+
describe('List(Document, actionMethod)', () => {
|
|
6
|
+
it('throws exception if component class is of invalid type', () => {
|
|
7
|
+
expect(() => List({}))
|
|
8
|
+
.toThrow('Argument "ComponentClass" is undefined for "List" operation function');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('returns a list operation class for a document', () => {
|
|
12
|
+
const ListOperation = List(Profile);
|
|
13
|
+
|
|
14
|
+
expect(ListOperation).toBeDefined();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('ListOperation', () => {
|
|
18
|
+
const ListProfiles = List(Profile);
|
|
19
|
+
|
|
20
|
+
describe('ListOperation.isComponent', () => {
|
|
21
|
+
it('returns false', () => {
|
|
22
|
+
expect(ListProfiles.isComponent).toBeFalsy();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('ListOperation.type', () => {
|
|
27
|
+
it('returns READ type', () => {
|
|
28
|
+
expect(ListProfiles.type).toEqual(Operation.types.READ);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('ListOperation.isCreate', () => {
|
|
33
|
+
it('returns false', () => {
|
|
34
|
+
expect(ListProfiles.isCreate).toBeFalsy();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('ListOperation.isUpdate', () => {
|
|
39
|
+
it('returns false', () => {
|
|
40
|
+
expect(ListProfiles.isUpdate).toBeFalsy();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('ListOperation.Component', () => {
|
|
45
|
+
it('returns referenced component', () => {
|
|
46
|
+
expect(ListProfiles.Component).toEqual(Profile);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('ListOperation.componentName', () => {
|
|
51
|
+
it('returns referenced component name', () => {
|
|
52
|
+
expect(ListProfiles.componentName).toEqual('Profile');
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('ListOperation.componentAction', () => {
|
|
57
|
+
it('returns indexAll action name', () => {
|
|
58
|
+
expect(ListProfiles.componentAction).toEqual('indexAll');
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('ListOperation.id', () => {
|
|
63
|
+
it('returns operation ID', () => {
|
|
64
|
+
expect(ListProfiles.id).toEqual('ListProfiles');
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe('ListOperation.tags', () => {
|
|
69
|
+
it('returns operation tags', () => {
|
|
70
|
+
expect(ListProfiles.tags).toEqual([ 'Profile' ]);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe('ListOperation.summary', () => {
|
|
75
|
+
it('returns operation summary', () => {
|
|
76
|
+
expect(ListProfiles.summary).toEqual('List profiles');
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('ListOperation.description', () => {
|
|
81
|
+
it('returns operation description', () => {
|
|
82
|
+
expect(ListProfiles.description).toEqual('');
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('ListOperation.security', () => {
|
|
87
|
+
it('returns operation security requirements', () => {
|
|
88
|
+
expect(ListProfiles.security).toEqual([]);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('ListOperation.errors', () => {
|
|
93
|
+
it('includes related errors', () => {
|
|
94
|
+
const errorCodes = Object.keys(ListProfiles.errors);
|
|
95
|
+
expect(errorCodes).toContain('InvalidOutputError');
|
|
96
|
+
expect(errorCodes).toContain('UnprocessibleConditionError');
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe('ListOperation.query', () => {
|
|
101
|
+
it('returns null', () => {
|
|
102
|
+
expect(ListProfiles.query).toBeNull();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe('ListOperation.inputSchema', () => {
|
|
107
|
+
it('returns null', () => {
|
|
108
|
+
expect(ListProfiles.inputSchema).toBeNull();
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe('ListOperation.outputSchema', () => {
|
|
113
|
+
it('returns operation output schema', () => {
|
|
114
|
+
expect(ListProfiles.outputSchema).toBeDefined();
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe('ListOperation.hasOutput', () => {
|
|
119
|
+
it('returns true', () => {
|
|
120
|
+
expect(ListProfiles.hasOutput).toBeTruthy();
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('ListOperation.componentActionMethod', () => {
|
|
125
|
+
it('returns binded component action method', () => {
|
|
126
|
+
expect(ListProfiles.componentActionMethod).toBeDefined();
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe('.exec(input)', () => {
|
|
131
|
+
it('lists documents', async () => {
|
|
132
|
+
const context = createContext({ request: { operationId: 'ListProfiles' } });
|
|
133
|
+
const { id } = await Profile.create(context, { name: 'John Doe' });
|
|
134
|
+
|
|
135
|
+
const operation = new ListProfiles(context);
|
|
136
|
+
|
|
137
|
+
const { result, headers, multiValueHeaders } = await operation.exec({});
|
|
138
|
+
|
|
139
|
+
expect(headers).toEqual({});
|
|
140
|
+
expect(multiValueHeaders).toEqual({});
|
|
141
|
+
|
|
142
|
+
expect((result.data as Profile[])[0].id).toEqual(id);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { Profile } from '../../../Document/__tests__/__helpers';
|
|
2
|
+
import { createContext } from '../../../Context/__tests__/__helpers';
|
|
3
|
+
import { Read, Operation } from '../../../';
|
|
4
|
+
|
|
5
|
+
describe('Read(Document, actionMethod)', () => {
|
|
6
|
+
it('throws exception if component class is of invalid type', () => {
|
|
7
|
+
expect(() => Read({}))
|
|
8
|
+
.toThrow('Argument "ComponentClass" is undefined for "Read" operation function');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('returns a read operation class for a document', () => {
|
|
12
|
+
const ReadOperation = Read(Profile);
|
|
13
|
+
|
|
14
|
+
expect(ReadOperation).toBeDefined();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('ReadOperation', () => {
|
|
18
|
+
const ReadProfile = Read(Profile);
|
|
19
|
+
|
|
20
|
+
describe('ReadOperation.isComponent', () => {
|
|
21
|
+
it('returns false', () => {
|
|
22
|
+
expect(ReadProfile.isComponent).toBeFalsy();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('ReadOperation.type', () => {
|
|
27
|
+
it('returns READ type', () => {
|
|
28
|
+
expect(ReadProfile.type).toEqual(Operation.types.READ);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('ReadOperation.isCreate', () => {
|
|
33
|
+
it('returns false', () => {
|
|
34
|
+
expect(ReadProfile.isCreate).toBeFalsy();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('ReadOperation.isUpdate', () => {
|
|
39
|
+
it('returns false', () => {
|
|
40
|
+
expect(ReadProfile.isUpdate).toBeFalsy();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('ReadOperation.Component', () => {
|
|
45
|
+
it('returns referenced component', () => {
|
|
46
|
+
expect(ReadProfile.Component).toEqual(Profile);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('ReadOperation.componentName', () => {
|
|
51
|
+
it('returns referenced component name', () => {
|
|
52
|
+
expect(ReadProfile.componentName).toEqual('Profile');
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('ReadOperation.componentAction', () => {
|
|
57
|
+
it('returns read action name', () => {
|
|
58
|
+
expect(ReadProfile.componentAction).toEqual('read');
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('ReadOperation.id', () => {
|
|
63
|
+
it('returns operation ID', () => {
|
|
64
|
+
expect(ReadProfile.id).toEqual('ReadProfile');
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe('ReadOperation.tags', () => {
|
|
69
|
+
it('returns operation tags', () => {
|
|
70
|
+
expect(ReadProfile.tags).toEqual([ 'Profile' ]);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe('ReadOperation.summary', () => {
|
|
75
|
+
it('returns operation summary', () => {
|
|
76
|
+
expect(ReadProfile.summary).toEqual('Read profile');
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('ReadOperation.description', () => {
|
|
81
|
+
it('returns operation description', () => {
|
|
82
|
+
expect(ReadProfile.description).toEqual('');
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('ReadOperation.security', () => {
|
|
87
|
+
it('returns operation security requirements', () => {
|
|
88
|
+
expect(ReadProfile.security).toEqual([]);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('ReadOperation.errors', () => {
|
|
93
|
+
it('includes related errors', () => {
|
|
94
|
+
const errorCodes = Object.keys(ReadProfile.errors);
|
|
95
|
+
expect(errorCodes).toContain('InvalidInputError');
|
|
96
|
+
expect(errorCodes).toContain('InvalidOutputError');
|
|
97
|
+
expect(errorCodes).toContain('UnprocessibleConditionError');
|
|
98
|
+
expect(errorCodes).toContain('DocumentNotFoundError');
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('ReadOperation.query', () => {
|
|
103
|
+
it('includes ID parameters', () => {
|
|
104
|
+
expect(ReadProfile.query!.id).toEqual({
|
|
105
|
+
description: 'ID of profile to be returned',
|
|
106
|
+
required: true
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe('ReadOperation.inputSchema', () => {
|
|
112
|
+
it('returns operation input schema', () => {
|
|
113
|
+
expect(ReadProfile.inputSchema).toBeDefined();
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe('ReadOperation.outputSchema', () => {
|
|
118
|
+
it('returns operation output schema', () => {
|
|
119
|
+
expect(ReadProfile.outputSchema).toBeDefined();
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe('ReadOperation.hasOutput', () => {
|
|
124
|
+
it('returns true', () => {
|
|
125
|
+
expect(ReadProfile.hasOutput).toBeTruthy();
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('ReadOperation.componentActionMethod', () => {
|
|
130
|
+
it('returns binded component action method', () => {
|
|
131
|
+
expect(ReadProfile.componentActionMethod).toBeDefined();
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
describe('.exec(input)', () => {
|
|
136
|
+
it('reads document', async () => {
|
|
137
|
+
const context = createContext({ request: { operationId: 'ReadProfile' } });
|
|
138
|
+
const { id } = await Profile.create(context, { name: 'John Doe' });
|
|
139
|
+
|
|
140
|
+
const operation = new ReadProfile(context);
|
|
141
|
+
const input = { id };
|
|
142
|
+
|
|
143
|
+
const { result, headers, multiValueHeaders } = await operation.exec(input);
|
|
144
|
+
|
|
145
|
+
expect(headers).toEqual({});
|
|
146
|
+
expect(multiValueHeaders).toEqual({});
|
|
147
|
+
|
|
148
|
+
expect((result.data as Profile).attributes.name).toEqual('John Doe');
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
});
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { Profile } from '../../../Document/__tests__/__helpers';
|
|
2
|
+
import { createContext } from '../../../Context/__tests__/__helpers';
|
|
3
|
+
import { Update, Operation } from '../../../';
|
|
4
|
+
|
|
5
|
+
describe('Update(Document, actionMethod)', () => {
|
|
6
|
+
it('throws exception if component class is of invalid type', () => {
|
|
7
|
+
expect(() => Update({}))
|
|
8
|
+
.toThrow('Argument "ComponentClass" is undefined for "Update" operation function');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('returns a create operation class for a document', () => {
|
|
12
|
+
const UpdateOperation = Update(Profile);
|
|
13
|
+
|
|
14
|
+
expect(UpdateOperation).toBeDefined();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('UpdateOperation', () => {
|
|
18
|
+
const UpdateProfile = Update(Profile);
|
|
19
|
+
|
|
20
|
+
describe('UpdateOperation.isComponent', () => {
|
|
21
|
+
it('returns false', () => {
|
|
22
|
+
expect(UpdateProfile.isComponent).toBeFalsy();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('UpdateOperation.type', () => {
|
|
27
|
+
it('returns UPDATE type', () => {
|
|
28
|
+
expect(UpdateProfile.type).toEqual(Operation.types.UPDATE);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('UpdateOperation.isCreate', () => {
|
|
33
|
+
it('returns false', () => {
|
|
34
|
+
expect(UpdateProfile.isCreate).toBeFalsy();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('UpdateOperation.isUpdate', () => {
|
|
39
|
+
it('returns true', () => {
|
|
40
|
+
expect(UpdateProfile.isUpdate).toBeTruthy();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('UpdateOperation.Component', () => {
|
|
45
|
+
it('returns referenced component', () => {
|
|
46
|
+
expect(UpdateProfile.Component).toEqual(Profile);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('UpdateOperation.componentName', () => {
|
|
51
|
+
it('returns referenced component name', () => {
|
|
52
|
+
expect(UpdateProfile.componentName).toEqual('Profile');
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('UpdateOperation.componentAction', () => {
|
|
57
|
+
it('returns update action name', () => {
|
|
58
|
+
expect(UpdateProfile.componentAction).toEqual('update');
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('UpdateOperation.componentMutationSchema', () => {
|
|
63
|
+
it('returns component mutation schema', () => {
|
|
64
|
+
expect(UpdateProfile.componentMutationSchema).toEqual(Profile.mutationSchema);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe('UpdateOperation.id', () => {
|
|
69
|
+
it('returns operation ID', () => {
|
|
70
|
+
expect(UpdateProfile.id).toEqual('UpdateProfile');
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe('UpdateOperation.tags', () => {
|
|
75
|
+
it('returns operation tags', () => {
|
|
76
|
+
expect(UpdateProfile.tags).toEqual([ 'Profile' ]);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('UpdateOperation.summary', () => {
|
|
81
|
+
it('returns operation summary', () => {
|
|
82
|
+
expect(UpdateProfile.summary).toEqual('Update profile');
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('UpdateOperation.description', () => {
|
|
87
|
+
it('returns operation description', () => {
|
|
88
|
+
expect(UpdateProfile.description).toEqual('');
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('UpdateOperation.security', () => {
|
|
93
|
+
it('returns operation security requirements', () => {
|
|
94
|
+
expect(UpdateProfile.security).toEqual([]);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('UpdateOperation.errors', () => {
|
|
99
|
+
it('includes related errors', () => {
|
|
100
|
+
const errorCodes = Object.keys(UpdateProfile.errors);
|
|
101
|
+
expect(errorCodes).toContain('InvalidInputError');
|
|
102
|
+
expect(errorCodes).toContain('InvalidOutputError');
|
|
103
|
+
expect(errorCodes).toContain('UnprocessibleConditionError');
|
|
104
|
+
expect(errorCodes).toContain('DocumentNotFoundError');
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe('UpdateOperation.query', () => {
|
|
109
|
+
it('includes ID parameters', () => {
|
|
110
|
+
expect(UpdateProfile.query!.id).toEqual({
|
|
111
|
+
description: 'ID of profile to be updated',
|
|
112
|
+
required: true
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe('UpdateOperation.inputSchema', () => {
|
|
118
|
+
it('returns operation input schema', () => {
|
|
119
|
+
expect(UpdateProfile.inputSchema).toBeDefined();
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe('UpdateOperation.outputSchema', () => {
|
|
124
|
+
it('returns operation output schema', () => {
|
|
125
|
+
expect(UpdateProfile.outputSchema).toBeDefined();
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('UpdateOperation.hasOutput', () => {
|
|
130
|
+
it('returns true', () => {
|
|
131
|
+
expect(UpdateProfile.hasOutput).toBeTruthy();
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
describe('UpdateOperation.componentActionMethod', () => {
|
|
136
|
+
it('returns binded component action method', () => {
|
|
137
|
+
expect(UpdateProfile.componentActionMethod).toBeDefined();
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe('.exec(input)', () => {
|
|
142
|
+
it('updates document', async () => {
|
|
143
|
+
const context = createContext({ request: { operationId: 'UpdateProfile' } });
|
|
144
|
+
const { id } = await Profile.create(context, { name: 'John Doe' });
|
|
145
|
+
|
|
146
|
+
const operation = new UpdateProfile(context);
|
|
147
|
+
const input = { id, mutation: { name: 'Jenn Doe' } };
|
|
148
|
+
|
|
149
|
+
const { result, headers, multiValueHeaders } = await operation.exec(input);
|
|
150
|
+
|
|
151
|
+
expect(headers).toEqual({});
|
|
152
|
+
expect(multiValueHeaders).toEqual({});
|
|
153
|
+
|
|
154
|
+
expect((result.data as Profile).attributes.name).toEqual('Jenn Doe');
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
});
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import Context from '../../Context';
|
|
2
|
+
import verifyToken from './verifyToken';
|
|
3
|
+
import AccessDeniedError from '../errors/AccessDeniedError';
|
|
4
|
+
import UnauthorizedError from '../errors/UnauthorizedError';
|
|
5
|
+
import { get, capitalize } from 'lodash';
|
|
6
|
+
import { decode, type Algorithm } from 'jsonwebtoken';
|
|
7
|
+
import type { VerificationResult, Requirement } from '../../Service/authorize';
|
|
8
|
+
|
|
9
|
+
type Claims = {
|
|
10
|
+
sub?: string;
|
|
11
|
+
iss?: string;
|
|
12
|
+
permissions?: string[];
|
|
13
|
+
[x: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type TokenVerificationMethod = (
|
|
17
|
+
context: Context,
|
|
18
|
+
token: string,
|
|
19
|
+
publicKey: string,
|
|
20
|
+
algorithm: Algorithm
|
|
21
|
+
) => Promise<[ true ] | [ false, string ]>;
|
|
22
|
+
|
|
23
|
+
type AccessVerificationMethod = (
|
|
24
|
+
context: Context,
|
|
25
|
+
claims: Claims,
|
|
26
|
+
permissions?: Permissions,
|
|
27
|
+
) => Promise<[ true ] | [ false, string ]>;
|
|
28
|
+
|
|
29
|
+
type NormalizeClaimsMethod = (claims: Claims) => Claims;
|
|
30
|
+
|
|
31
|
+
type RequirementOptions = {
|
|
32
|
+
name?: string;
|
|
33
|
+
issuer?: string;
|
|
34
|
+
publicKey: string;
|
|
35
|
+
cookieName?: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
permissions?: Permissions;
|
|
38
|
+
requirementName?: string;
|
|
39
|
+
algorithm?: Algorithm;
|
|
40
|
+
normalizeClaimsMethod?: NormalizeClaimsMethod;
|
|
41
|
+
tokenVerificationMethod?: TokenVerificationMethod;
|
|
42
|
+
accessVerificationMethod?: AccessVerificationMethod;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type Permissions = Record<string, string[]>;
|
|
46
|
+
|
|
47
|
+
const DEFAULT_HEADER_NAME = 'authorization';
|
|
48
|
+
|
|
49
|
+
const MESSAGE_ACCESS_DENIED = 'Access denied';
|
|
50
|
+
|
|
51
|
+
/** Default method to normalize claims. */
|
|
52
|
+
const DEFAULT_NORMALIZED_CLAIMS_METHOD = (claims: Claims) => claims;
|
|
53
|
+
|
|
54
|
+
/** Ensures permissions claim includes permissions required by an operation. */
|
|
55
|
+
const DEFAULT_ACCESS_VERIFICATION_METHOD = async (
|
|
56
|
+
context: Context,
|
|
57
|
+
claims: Claims,
|
|
58
|
+
permissionsMap?: Permissions
|
|
59
|
+
): Promise<[ true ] | [ false, string ]> => {
|
|
60
|
+
if (!permissionsMap) {
|
|
61
|
+
return [ true ];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const { operationId } = context;
|
|
65
|
+
|
|
66
|
+
const permissionsClaim = get(claims, 'permissions', []);
|
|
67
|
+
|
|
68
|
+
for (const permission of permissionsClaim) {
|
|
69
|
+
const operationIds = get(permissionsMap, permission, []) as string[];
|
|
70
|
+
|
|
71
|
+
const hasAccess = operationIds.includes(operationId);
|
|
72
|
+
|
|
73
|
+
if (hasAccess) {
|
|
74
|
+
return [ true ];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return [ false, MESSAGE_ACCESS_DENIED ];
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/** JWT Authorization */
|
|
82
|
+
class JwtAuthorization {
|
|
83
|
+
private _name: string;
|
|
84
|
+
private _issuer?: string;
|
|
85
|
+
private _publicKey: string;
|
|
86
|
+
private _algorithm: Algorithm;
|
|
87
|
+
private _cookieName: string;
|
|
88
|
+
private _permissions?: Permissions;
|
|
89
|
+
|
|
90
|
+
private _verifyToken: TokenVerificationMethod;
|
|
91
|
+
private _verifyAccess: AccessVerificationMethod;
|
|
92
|
+
private _normalizeClaims: NormalizeClaimsMethod;
|
|
93
|
+
|
|
94
|
+
/** Creates an instance of JWT authorization security. */
|
|
95
|
+
constructor({
|
|
96
|
+
name,
|
|
97
|
+
issuer,
|
|
98
|
+
publicKey,
|
|
99
|
+
cookieName,
|
|
100
|
+
permissions,
|
|
101
|
+
algorithm = 'RS256',
|
|
102
|
+
normalizeClaimsMethod = DEFAULT_NORMALIZED_CLAIMS_METHOD,
|
|
103
|
+
tokenVerificationMethod = verifyToken,
|
|
104
|
+
accessVerificationMethod = DEFAULT_ACCESS_VERIFICATION_METHOD,
|
|
105
|
+
}: {
|
|
106
|
+
name: string;
|
|
107
|
+
issuer?: string;
|
|
108
|
+
publicKey: string;
|
|
109
|
+
algorithm?: Algorithm;
|
|
110
|
+
cookieName?: string;
|
|
111
|
+
permissions?: Permissions;
|
|
112
|
+
normalizeClaimsMethod?: NormalizeClaimsMethod;
|
|
113
|
+
tokenVerificationMethod?: TokenVerificationMethod;
|
|
114
|
+
accessVerificationMethod?: AccessVerificationMethod;
|
|
115
|
+
}) {
|
|
116
|
+
this._name = name;
|
|
117
|
+
this._issuer = issuer;
|
|
118
|
+
this._publicKey = publicKey;
|
|
119
|
+
this._algorithm = algorithm;
|
|
120
|
+
this._cookieName = cookieName || name;
|
|
121
|
+
this._permissions = permissions;
|
|
122
|
+
|
|
123
|
+
this._verifyToken = tokenVerificationMethod;
|
|
124
|
+
this._verifyAccess = accessVerificationMethod;
|
|
125
|
+
this._normalizeClaims = normalizeClaimsMethod;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Returns specification for JWT authorization security requirement. */
|
|
129
|
+
static createRequirement(options: RequirementOptions): Record<string, Requirement> {
|
|
130
|
+
const name = get(options, 'name', DEFAULT_HEADER_NAME);
|
|
131
|
+
const description = get(options, 'description');
|
|
132
|
+
const requirementName = get(options, 'requirementName', capitalize(name));
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
[requirementName]: {
|
|
136
|
+
definition: {
|
|
137
|
+
in: 'header',
|
|
138
|
+
type: 'apiKey',
|
|
139
|
+
name,
|
|
140
|
+
description,
|
|
141
|
+
},
|
|
142
|
+
errors: JwtAuthorization.errors,
|
|
143
|
+
/** Verifies context via JWT authorization requirement. */
|
|
144
|
+
verify: (context: Context) => {
|
|
145
|
+
const security = new JwtAuthorization({ name, ...options });
|
|
146
|
+
return security.verify(context);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Returns security related errors. */
|
|
153
|
+
static get errors() {
|
|
154
|
+
return {
|
|
155
|
+
UnauthorizedError: {
|
|
156
|
+
statusCode: 401,
|
|
157
|
+
description: 'Unauthorized request'
|
|
158
|
+
},
|
|
159
|
+
AccessDeniedError: {
|
|
160
|
+
statusCode: 403,
|
|
161
|
+
description: 'Operation access denied'
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Verifies JWT authorization. */
|
|
167
|
+
async verify(context: Context): Promise<VerificationResult> {
|
|
168
|
+
const { headers, cookies } = context;
|
|
169
|
+
|
|
170
|
+
let token = get(cookies, this._cookieName);
|
|
171
|
+
|
|
172
|
+
if (!token) {
|
|
173
|
+
token = headers[this._name] as string;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (!token) {
|
|
177
|
+
const error = new UnauthorizedError(`Header "${this._name}" is missing`);
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
isAuthorized: false,
|
|
181
|
+
error
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
token = token.replace(/^bearer\s+/i, '');
|
|
186
|
+
|
|
187
|
+
const object = decode(token, { complete: true });
|
|
188
|
+
|
|
189
|
+
if (!object) {
|
|
190
|
+
const error = new UnauthorizedError(`Invalid "${this._name}" token`);
|
|
191
|
+
|
|
192
|
+
return {
|
|
193
|
+
isAuthorized: false,
|
|
194
|
+
error
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const [ isTokenOk, tokenErrorMessage ] =
|
|
199
|
+
await this._verifyToken(context, token, this._publicKey, this._algorithm);
|
|
200
|
+
|
|
201
|
+
if (!isTokenOk) {
|
|
202
|
+
const error = new UnauthorizedError(`"${this._name}" token verification failed: ${tokenErrorMessage}`);
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
isAuthorized: false,
|
|
206
|
+
error
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const claims = object.payload as Claims;
|
|
211
|
+
|
|
212
|
+
if (this._issuer) {
|
|
213
|
+
const { iss } = claims;
|
|
214
|
+
|
|
215
|
+
const isValidIssuer = iss === this._issuer;
|
|
216
|
+
|
|
217
|
+
if (!isValidIssuer) {
|
|
218
|
+
const error = new UnauthorizedError(`Invalid issuer of "${this._name}" token`);
|
|
219
|
+
|
|
220
|
+
return {
|
|
221
|
+
isAuthorized: false,
|
|
222
|
+
error
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const [ isAccessOk, accessErrorMessage ] = await this._verifyAccess(context, claims, this._permissions);
|
|
228
|
+
|
|
229
|
+
if (!isAccessOk) {
|
|
230
|
+
const error = new AccessDeniedError(accessErrorMessage);
|
|
231
|
+
|
|
232
|
+
return {
|
|
233
|
+
isAuthorized: false,
|
|
234
|
+
error
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const normalizedClaims = this._normalizeClaims(claims);
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
isAuthorized: true,
|
|
242
|
+
claims: normalizedClaims
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export default JwtAuthorization;
|