@kravc/dos 1.12.5 → 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 -350
- 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
package/src/Service.spec.js
DELETED
|
@@ -1,388 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { Schema } = require('@kravc/schema')
|
|
4
|
-
|
|
5
|
-
const Health = require('examples/Health')
|
|
6
|
-
const { expect } = require('chai')
|
|
7
|
-
const ReadProfile = require('examples/ReadProfile')
|
|
8
|
-
const CreateProfile = require('examples/CreateProfile')
|
|
9
|
-
const UpdateProfile = require('examples/UpdateProfile')
|
|
10
|
-
const DeleteProfile = require('examples/DeleteProfile')
|
|
11
|
-
const IndexProfiles = require('examples/IndexProfiles')
|
|
12
|
-
|
|
13
|
-
const test = require('src/test')
|
|
14
|
-
const {
|
|
15
|
-
Create,
|
|
16
|
-
Service,
|
|
17
|
-
Component,
|
|
18
|
-
InvalidParametersError,
|
|
19
|
-
UnprocessibleConditionError,
|
|
20
|
-
} = require('src')
|
|
21
|
-
|
|
22
|
-
const testSchema = new Schema({
|
|
23
|
-
test: {
|
|
24
|
-
type: 'string'
|
|
25
|
-
}
|
|
26
|
-
}, 'Test')
|
|
27
|
-
|
|
28
|
-
const modules = [
|
|
29
|
-
testSchema,
|
|
30
|
-
Health,
|
|
31
|
-
ReadProfile,
|
|
32
|
-
CreateProfile,
|
|
33
|
-
UpdateProfile,
|
|
34
|
-
DeleteProfile,
|
|
35
|
-
IndexProfiles
|
|
36
|
-
]
|
|
37
|
-
|
|
38
|
-
const ROOT_PATH = process.cwd()
|
|
39
|
-
|
|
40
|
-
describe('Service', () => {
|
|
41
|
-
before(() => {
|
|
42
|
-
const { Component: Profile } = CreateProfile
|
|
43
|
-
Profile.reset()
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
describe('Service.constructor(modules, url, path = \'/src\')', () => {
|
|
47
|
-
it('initializes service', () => {
|
|
48
|
-
const service = new Service(modules, {
|
|
49
|
-
url: 'https://example.com/api',
|
|
50
|
-
path: `${ROOT_PATH}/examples`
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
expect(service).to.exist
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
it('throw error if spec validation failed', () => {
|
|
57
|
-
class InvalidOperation extends CreateProfile {
|
|
58
|
-
static get query() {
|
|
59
|
-
return {
|
|
60
|
-
id: { type: 'INVALID_TYPE' }
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
static get errors() {
|
|
65
|
-
return {
|
|
66
|
-
InvalidParametersError: { statusCode: 422 }
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const modules = [ InvalidOperation, Health ]
|
|
72
|
-
expect(() => new Service(modules))
|
|
73
|
-
.to.throw('Service spec validation failed')
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
it('throw error if schema for component not found', () => {
|
|
77
|
-
class NoSchema extends Component {}
|
|
78
|
-
class NoComponentSchemaOperation extends Create(NoSchema) {}
|
|
79
|
-
|
|
80
|
-
const modules = [ NoComponentSchemaOperation ]
|
|
81
|
-
|
|
82
|
-
expect(() => new Service(modules))
|
|
83
|
-
.to.throw('Schema for component "NoSchema" not found')
|
|
84
|
-
})
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
describe('.handler(request)', () => {
|
|
88
|
-
const service = new Service(modules, {
|
|
89
|
-
url: 'https://example.com/api/',
|
|
90
|
-
path: `${ROOT_PATH}/examples`
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
const { exec, request: executeRequest, expectError } = test.execute(service)
|
|
94
|
-
|
|
95
|
-
const authorization = test.createAccessToken({}, { group: 'Administrators' })
|
|
96
|
-
|
|
97
|
-
it('returns "UnauthorizedError / 401" if missing authorization header', async () => {
|
|
98
|
-
const error = await expectError('CreateProfile', {}, {}, 'UnauthorizedError')
|
|
99
|
-
expect(error.statusCode).to.eql(401)
|
|
100
|
-
|
|
101
|
-
// NOTE: Additional tests for execute helpers to get code coverage.
|
|
102
|
-
try {
|
|
103
|
-
await executeRequest('CreateProfile', {}, {})
|
|
104
|
-
throw new Error('Expected error was not thrown')
|
|
105
|
-
} catch (error) {
|
|
106
|
-
expect(error.message).to.include('RequestError for "CreateProfile"')
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
try {
|
|
110
|
-
await expectError('CreateProfile', {}, {}, 'AccessDeniedError')
|
|
111
|
-
throw new Error('Expected error was not thrown')
|
|
112
|
-
} catch (error) {
|
|
113
|
-
expect(error.message).to.include('Unexpected error code received')
|
|
114
|
-
}
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
it('returns "UnauthorizedError / 401" if invalid authorization header', async () => {
|
|
118
|
-
const cookie = 'authorization=INVALID_TOKEN; path=/; HttpOnly'
|
|
119
|
-
const error = await expectError('CreateProfile', {}, { cookie }, 'UnauthorizedError')
|
|
120
|
-
|
|
121
|
-
expect(error.statusCode).to.eql(401)
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
it('returns "UnauthorizedError / 401" if token expired', async () => {
|
|
125
|
-
const authorization = test.createAccessToken({ expiresIn: '1 second' })
|
|
126
|
-
await test.wait(1200)
|
|
127
|
-
|
|
128
|
-
const error = await expectError('CreateProfile', {}, { authorization }, 'UnauthorizedError')
|
|
129
|
-
|
|
130
|
-
expect(error.statusCode).to.eql(401)
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
it('returns "AccessDeniedError / 403" if operation access denied', async () => {
|
|
134
|
-
const authorization = test.createAccessToken({}, { group: 'Clients' })
|
|
135
|
-
const error = await expectError('CreateProfile', {}, { authorization }, 'AccessDeniedError')
|
|
136
|
-
|
|
137
|
-
expect(error.statusCode).to.eql(403)
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
it('returns "InvalidInputError / 400" if invalid input', async () => {
|
|
141
|
-
const error = await expectError('CreateProfile', {}, { authorization }, 'InvalidInputError')
|
|
142
|
-
|
|
143
|
-
expect(error.statusCode).to.eql(400)
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
it('returns "InvalidParametersError / 400" if invalid parameters', async () => {
|
|
147
|
-
class InvalidIndexProfiles extends IndexProfiles {
|
|
148
|
-
action() {
|
|
149
|
-
throw new InvalidParametersError()
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const modules = [ InvalidIndexProfiles ]
|
|
154
|
-
const service = new Service(modules)
|
|
155
|
-
const { expectError: customExpectError } = test.execute(service)
|
|
156
|
-
const error = await customExpectError('InvalidIndexProfiles', {}, {}, 'InvalidParametersError')
|
|
157
|
-
|
|
158
|
-
expect(error.statusCode).to.eql(400)
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
it('returns "OperationNotFoundError / 404" if operation not found', async () => {
|
|
162
|
-
const error = await expectError('DestroyProfile', {}, { authorization }, 'OperationNotFoundError')
|
|
163
|
-
|
|
164
|
-
expect(error.statusCode).to.eql(404)
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
it('returns "UnprocessibleConditionError / 422" if unprocessible condition', async () => {
|
|
168
|
-
class InvalidIndexProfiles extends IndexProfiles {
|
|
169
|
-
action() {
|
|
170
|
-
throw new UnprocessibleConditionError()
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const modules = [ InvalidIndexProfiles ]
|
|
175
|
-
const service = new Service(modules)
|
|
176
|
-
const { expectError: customExpectError } = test.execute(service)
|
|
177
|
-
const error = await customExpectError('InvalidIndexProfiles', {}, {}, 'UnprocessibleConditionError')
|
|
178
|
-
|
|
179
|
-
expect(error.statusCode).to.eql(422)
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
it('returns "InvalidOutputError / 500" if invalid output, logs an error', async () => {
|
|
183
|
-
class InvalidIndexProfiles extends IndexProfiles {
|
|
184
|
-
action() {
|
|
185
|
-
return { invalid: 'RESPONSE' }
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
const modules = [ InvalidIndexProfiles ]
|
|
189
|
-
const service = new Service(modules)
|
|
190
|
-
const { expectError: customExpectError } = test.execute(service)
|
|
191
|
-
const error = await customExpectError('InvalidIndexProfiles', {}, {}, 'InvalidOutputError')
|
|
192
|
-
|
|
193
|
-
expect(error.statusCode).to.eql(500)
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
it('returns "OperationError / 500" if unexpected operation error, logs an error', async () => {
|
|
197
|
-
class InvalidIndexProfiles extends IndexProfiles {
|
|
198
|
-
action() {
|
|
199
|
-
this.context.authorization = 'SECRET'
|
|
200
|
-
this.context.query = {
|
|
201
|
-
id: 'ID',
|
|
202
|
-
password: 'SECRET',
|
|
203
|
-
nested: {
|
|
204
|
-
token: 'SECRET',
|
|
205
|
-
items: [ 'a1', 'b2', { code: 'SECRET' } ],
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
throw new Error('Boom!')
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
const modules = [ InvalidIndexProfiles ]
|
|
213
|
-
const service = new Service(modules)
|
|
214
|
-
const { expectError: customExpectError } = test.execute(service)
|
|
215
|
-
const error = await customExpectError('InvalidIndexProfiles', {}, {}, 'OperationError')
|
|
216
|
-
|
|
217
|
-
expect(error.statusCode).to.eql(500)
|
|
218
|
-
})
|
|
219
|
-
|
|
220
|
-
it('executes operations', async () => {
|
|
221
|
-
const id = 'HELLO_WORLD'
|
|
222
|
-
let response
|
|
223
|
-
|
|
224
|
-
response = await exec('CreateProfile', {
|
|
225
|
-
mutation: { id, name: 'Hello, world!' }
|
|
226
|
-
}, { authorization })
|
|
227
|
-
|
|
228
|
-
expect(response.statusCode).to.eql(201)
|
|
229
|
-
expect(response.result.data).to.include({ id, name: 'Hello, world!' })
|
|
230
|
-
|
|
231
|
-
response = await exec('UpdateProfile', {
|
|
232
|
-
id, mutation: { name: 'Test update!' }
|
|
233
|
-
}, { authorization })
|
|
234
|
-
|
|
235
|
-
expect(response.statusCode).to.eql(200)
|
|
236
|
-
expect(response.result.data).to.include({ name: 'Test update!' })
|
|
237
|
-
|
|
238
|
-
const data = await executeRequest('UpdateProfile', {
|
|
239
|
-
id, mutation: { name: 'System operation request!' }
|
|
240
|
-
}, {})
|
|
241
|
-
|
|
242
|
-
expect(data).to.include({ name: 'System operation request!' })
|
|
243
|
-
|
|
244
|
-
// NOTE: Additional tests for execute helpers to get code coverage.
|
|
245
|
-
try {
|
|
246
|
-
await expectError('UpdateProfile', {
|
|
247
|
-
id, mutation: { name: 'System operation request!' }
|
|
248
|
-
}, {}, 'AccessDeniedError')
|
|
249
|
-
throw new Error('Expected error was not thrown')
|
|
250
|
-
} catch (error) {
|
|
251
|
-
expect(error.message).to.include('Success NOT expected for')
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
response = await exec('IndexProfiles')
|
|
255
|
-
expect(response.statusCode).to.eql(200)
|
|
256
|
-
expect(response.result.data).to.be.not.empty
|
|
257
|
-
|
|
258
|
-
response = await exec('DeleteProfile', { id })
|
|
259
|
-
expect(response.statusCode).to.eql(204)
|
|
260
|
-
expect(response.result).to.not.exist
|
|
261
|
-
|
|
262
|
-
await executeRequest('CreateProfile', {
|
|
263
|
-
mutation: { id, name: 'Hello, world!' }
|
|
264
|
-
}, { authorization })
|
|
265
|
-
|
|
266
|
-
await executeRequest('DeleteProfile', { id })
|
|
267
|
-
})
|
|
268
|
-
|
|
269
|
-
it('executes operation via HTTP request', async () => {
|
|
270
|
-
const lambdaFunction = request => service.handler(request)
|
|
271
|
-
|
|
272
|
-
let request
|
|
273
|
-
let response
|
|
274
|
-
|
|
275
|
-
request = {
|
|
276
|
-
url: 'http://localhost:3000/api/Health',
|
|
277
|
-
httpMethod: 'GET'
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
response = await lambdaFunction(request)
|
|
281
|
-
expect(response.statusCode).to.eql(204)
|
|
282
|
-
|
|
283
|
-
request = {
|
|
284
|
-
url: 'http://localhost:3000/api/CreateProfile',
|
|
285
|
-
body: JSON.stringify({ id: 'HELLO_WORLD', name: 'Hello, world!' }),
|
|
286
|
-
headers: { authorization },
|
|
287
|
-
httpMethod: 'POST'
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
response = await lambdaFunction(request)
|
|
291
|
-
expect(response.statusCode).to.eql(201)
|
|
292
|
-
|
|
293
|
-
request = {
|
|
294
|
-
url: 'http://localhost:3000/api/UpdateProfile?id=HELLO_WORLD&tags=["tag1","tag2"]',
|
|
295
|
-
body: JSON.stringify({ name: 'HTTP test!' }),
|
|
296
|
-
method: 'PATCH',
|
|
297
|
-
headers: { authorization }
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
response = await lambdaFunction(request)
|
|
301
|
-
expect(response.statusCode).to.eql(200)
|
|
302
|
-
})
|
|
303
|
-
|
|
304
|
-
it('supports spec middleware in dev environment', async () => {
|
|
305
|
-
process.env.NODE_APP_INSTANCE = 'dev'
|
|
306
|
-
|
|
307
|
-
const lambdaFunction = request => service.handler(request)
|
|
308
|
-
|
|
309
|
-
let request
|
|
310
|
-
let response
|
|
311
|
-
|
|
312
|
-
request = {
|
|
313
|
-
url: 'http://localhost:3000/',
|
|
314
|
-
httpMethod: 'GET'
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
response = await lambdaFunction(request)
|
|
318
|
-
expect(response.statusCode).to.eql(200)
|
|
319
|
-
expect(response.body.startsWith('<!DOCTYPE')).to.be.true
|
|
320
|
-
|
|
321
|
-
request = {
|
|
322
|
-
path: '/Spec',
|
|
323
|
-
httpMethod: 'GET'
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
response = await lambdaFunction(request)
|
|
327
|
-
expect(response.statusCode).to.eql(200)
|
|
328
|
-
|
|
329
|
-
const body = JSON.parse(response.body)
|
|
330
|
-
expect(body.swagger).to.exist
|
|
331
|
-
|
|
332
|
-
response = await lambdaFunction({ path: '/Documents.yaml', httpMethod: 'GET' })
|
|
333
|
-
response = await lambdaFunction({ path: '/Enums.yaml', httpMethod: 'GET' })
|
|
334
|
-
response = await lambdaFunction({ path: '/Operations.yaml', httpMethod: 'GET' })
|
|
335
|
-
response = await lambdaFunction({ path: '/Parameters.yaml', httpMethod: 'GET' })
|
|
336
|
-
response = await lambdaFunction({ path: '/Schenarios.yaml', httpMethod: 'GET' })
|
|
337
|
-
response = await lambdaFunction({ path: '/Schemas.yaml', httpMethod: 'GET' })
|
|
338
|
-
expect(response.statusCode).to.eql(200)
|
|
339
|
-
|
|
340
|
-
process.env.NODE_APP_INSTANCE = undefined
|
|
341
|
-
})
|
|
342
|
-
|
|
343
|
-
it('does not expose spec middleware in non-dev environment', async () => {
|
|
344
|
-
const lambdaFunction = request => service.handler(request)
|
|
345
|
-
|
|
346
|
-
let request
|
|
347
|
-
let response
|
|
348
|
-
|
|
349
|
-
request = {
|
|
350
|
-
url: 'http://localhost:3000/',
|
|
351
|
-
httpMethod: 'GET'
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
response = await lambdaFunction(request)
|
|
355
|
-
expect(response.statusCode).to.eql(200)
|
|
356
|
-
expect(response.body).to.eql('healthy')
|
|
357
|
-
|
|
358
|
-
request = {
|
|
359
|
-
path: '/Spec',
|
|
360
|
-
httpMethod: 'GET'
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
response = await lambdaFunction(request)
|
|
364
|
-
expect(response.statusCode).to.eql(200)
|
|
365
|
-
|
|
366
|
-
const body = JSON.parse(response.body)
|
|
367
|
-
expect(body.swagger).to.not.exist
|
|
368
|
-
})
|
|
369
|
-
|
|
370
|
-
it('logs operation input in non-test environment', async () => {
|
|
371
|
-
process.env.NODE_APP_INSTANCE = 'dev'
|
|
372
|
-
|
|
373
|
-
const lambdaFunction = request => service.handler(request)
|
|
374
|
-
|
|
375
|
-
await lambdaFunction({
|
|
376
|
-
url: 'http://localhost:3000/api/Health',
|
|
377
|
-
httpMethod: 'GET'
|
|
378
|
-
})
|
|
379
|
-
|
|
380
|
-
const id = 'HELLO_WORLD'
|
|
381
|
-
await exec('CreateProfile', {
|
|
382
|
-
mutation: { id, name: 'Hello, world!' }
|
|
383
|
-
}, { authorization })
|
|
384
|
-
|
|
385
|
-
process.env.NODE_APP_INSTANCE = undefined
|
|
386
|
-
})
|
|
387
|
-
})
|
|
388
|
-
})
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
class CommonError extends Error {
|
|
4
|
-
constructor(code, message) {
|
|
5
|
-
super(message)
|
|
6
|
-
|
|
7
|
-
this._code = code
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
get code() {
|
|
11
|
-
return this._code
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
get isCommonError() {
|
|
15
|
-
return true
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
module.exports = CommonError
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const CommonError = require('./CommonError')
|
|
4
|
-
const getComponentTitle = require('../helpers/getComponentTitle')
|
|
5
|
-
|
|
6
|
-
class DocumentExistsError extends CommonError {
|
|
7
|
-
constructor(Document, parameters) {
|
|
8
|
-
const documentTitle = getComponentTitle(Document)
|
|
9
|
-
const jsonParameters = JSON.stringify(parameters, null, 2)
|
|
10
|
-
|
|
11
|
-
super('DocumentExistsError', `${documentTitle} already exists ${jsonParameters}`)
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
module.exports = DocumentExistsError
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const CommonError = require('./CommonError')
|
|
4
|
-
const getComponentTitle = require('../helpers/getComponentTitle')
|
|
5
|
-
|
|
6
|
-
class DocumentNotFoundError extends CommonError {
|
|
7
|
-
constructor(Document, parameters) {
|
|
8
|
-
const documentTitle = getComponentTitle(Document)
|
|
9
|
-
const jsonParameters = JSON.stringify(parameters, null, 2)
|
|
10
|
-
|
|
11
|
-
super('DocumentNotFoundError', `${documentTitle} not found ${jsonParameters}`)
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
module.exports = DocumentNotFoundError
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const CommonError = require('./CommonError')
|
|
4
|
-
|
|
5
|
-
class InvalidInputError extends CommonError {
|
|
6
|
-
constructor(validationError) {
|
|
7
|
-
super('InvalidInputError', 'Invalid operation input')
|
|
8
|
-
|
|
9
|
-
const { validationErrors } = validationError.toJSON()
|
|
10
|
-
|
|
11
|
-
this._validationErrors = validationErrors
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
get validationErrors() {
|
|
15
|
-
return this._validationErrors
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
module.exports = InvalidInputError
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const CommonError = require('./CommonError')
|
|
4
|
-
|
|
5
|
-
class InvalidOutputError extends CommonError {
|
|
6
|
-
constructor(invalidObject, validationError) {
|
|
7
|
-
super('InvalidOutputError', 'Invalid operation output')
|
|
8
|
-
|
|
9
|
-
this._validationError = validationError
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
toJSON() {
|
|
13
|
-
return {
|
|
14
|
-
...this._validationError.toJSON(),
|
|
15
|
-
object: '[MASKED]'
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
module.exports = InvalidOutputError
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const CommonError = require('./CommonError')
|
|
4
|
-
|
|
5
|
-
class InvalidParametersError extends CommonError {
|
|
6
|
-
constructor(message = 'Invalid parameters') {
|
|
7
|
-
super('InvalidParametersError', message)
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
module.exports = InvalidParametersError
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const path = require('path')
|
|
4
|
-
const loadSync = require('../helpers/loadSync')
|
|
5
|
-
const logError = require('../helpers/logError')
|
|
6
|
-
const Component = require('../Component')
|
|
7
|
-
|
|
8
|
-
const SCHEMA_PATH = path.resolve(__dirname) + '/OperationError.yaml'
|
|
9
|
-
const OPERATION_ERROR_SCHEMA = loadSync(SCHEMA_PATH)
|
|
10
|
-
|
|
11
|
-
class OperationError extends Component {
|
|
12
|
-
static get schema() {
|
|
13
|
-
return OPERATION_ERROR_SCHEMA
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
constructor(context, statusCode, originalError) {
|
|
17
|
-
let { code, message, validationErrors, isCommonError } = originalError
|
|
18
|
-
|
|
19
|
-
const shouldLogError = statusCode === 500
|
|
20
|
-
|
|
21
|
-
const error = {
|
|
22
|
-
code,
|
|
23
|
-
message,
|
|
24
|
-
statusCode
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (validationErrors) {
|
|
28
|
-
error.validationErrors = validationErrors
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (!isCommonError) {
|
|
32
|
-
error.code = 'OperationError'
|
|
33
|
-
error.message = 'Unexpected operation error'
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
super(context, { error })
|
|
37
|
-
|
|
38
|
-
if (shouldLogError) {
|
|
39
|
-
logError(context, error, originalError)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
module.exports = OperationError
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const CommonError = require('./CommonError')
|
|
4
|
-
|
|
5
|
-
class OperationNotFoundError extends CommonError {
|
|
6
|
-
constructor(parameters) {
|
|
7
|
-
const parametersJson = JSON.stringify(parameters, null, 2)
|
|
8
|
-
super('OperationNotFoundError', `Operation not found, ${parametersJson}`)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
get statusCode() {
|
|
12
|
-
return 404
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
module.exports = OperationNotFoundError
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const CommonError = require('./CommonError')
|
|
4
|
-
|
|
5
|
-
class UnprocessibleConditionError extends CommonError {
|
|
6
|
-
constructor(message = 'Invalid parameters') {
|
|
7
|
-
super('UnprocessibleConditionError', message)
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
module.exports = UnprocessibleConditionError
|
package/src/errors/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
CommonError: require('./CommonError'),
|
|
5
|
-
UnauthorizedError: require('./UnauthorizedError'),
|
|
6
|
-
AccessDeniedError: require('./AccessDeniedError'),
|
|
7
|
-
DocumentExistsError: require('./DocumentExistsError'),
|
|
8
|
-
DocumentNotFoundError: require('./DocumentNotFoundError'),
|
|
9
|
-
InvalidParametersError: require('./InvalidParametersError'),
|
|
10
|
-
UnprocessibleConditionError: require('./UnprocessibleConditionError')
|
|
11
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const asSafeClass = classTarget => {
|
|
4
|
-
return new Proxy(classTarget, {
|
|
5
|
-
get(target, prop) {
|
|
6
|
-
const isPropertyDefined = (prop in target)
|
|
7
|
-
const isThen = prop === 'then'
|
|
8
|
-
|
|
9
|
-
if (isThen) {
|
|
10
|
-
return undefined
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (!isPropertyDefined) {
|
|
14
|
-
throw new Error(`Undefined property or method: ${prop}`)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return target[prop]
|
|
18
|
-
}
|
|
19
|
-
})
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
module.exports = asSafeClass
|
package/src/helpers/authorize.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const authorize = async (Operation, context) => {
|
|
4
|
-
const { security: requirements } = Operation
|
|
5
|
-
|
|
6
|
-
const isPublic = requirements.length === 0
|
|
7
|
-
|
|
8
|
-
if (isPublic) { return {} }
|
|
9
|
-
|
|
10
|
-
let authorizationContext = {}
|
|
11
|
-
let authorizationErrorsCount
|
|
12
|
-
let authorizationError
|
|
13
|
-
|
|
14
|
-
for (const orRequirement of requirements) {
|
|
15
|
-
authorizationErrorsCount = 0
|
|
16
|
-
|
|
17
|
-
for (const andRequirementKey in orRequirement) {
|
|
18
|
-
const andRequirement = orRequirement[andRequirementKey]
|
|
19
|
-
const SecurityClass = andRequirement.klass
|
|
20
|
-
|
|
21
|
-
const security = new SecurityClass(andRequirement)
|
|
22
|
-
const { isAuthorized, error, ...rest } = await security.verify(context)
|
|
23
|
-
|
|
24
|
-
if (isAuthorized) {
|
|
25
|
-
authorizationContext = { ...authorizationContext, ...rest }
|
|
26
|
-
|
|
27
|
-
} else {
|
|
28
|
-
authorizationError = error
|
|
29
|
-
authorizationErrorsCount += 1
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const isRequestAuthorized = authorizationErrorsCount === 0
|
|
35
|
-
|
|
36
|
-
if (isRequestAuthorized) {
|
|
37
|
-
return authorizationContext
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
throw authorizationError
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
module.exports = authorize
|