@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
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { get } from 'lodash';
|
|
2
|
+
import Context from '../../Context';
|
|
3
|
+
import AccessDeniedError from '../errors/AccessDeniedError';
|
|
4
|
+
import type { Requirement, VerificationResult } from '../../Service/authorize';
|
|
5
|
+
|
|
6
|
+
const NAME = 'System';
|
|
7
|
+
const DESCRIPTION = 'This security definition and a header for system' +
|
|
8
|
+
' operations should be ignored. The verification method of system' +
|
|
9
|
+
' operations relies on a gateway that adds headers for all' +
|
|
10
|
+
' external requests. Request without headers considered to be' +
|
|
11
|
+
' internal.';
|
|
12
|
+
|
|
13
|
+
const MESSAGE_ACCESS_DENIED = 'Access denied, operation is available only for internal requests';
|
|
14
|
+
|
|
15
|
+
const DEFAULT_HEADER_NAME = 'authorization';
|
|
16
|
+
|
|
17
|
+
type AccessVerificationMethod = (context: Context) => Promise<[ true ] | [ false, string ]>;
|
|
18
|
+
|
|
19
|
+
type RequirementOptions = {
|
|
20
|
+
name?: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
requirementName?: string;
|
|
23
|
+
accessVerificationMethod?: AccessVerificationMethod;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Ensures no headers are set by the gateway. */
|
|
27
|
+
const verifyAccess = async (context: Context): Promise<[ true ] | [ false, string ]> => {
|
|
28
|
+
const { headers } = context;
|
|
29
|
+
|
|
30
|
+
const isExternalRequest = Object.keys(headers).length > 0;
|
|
31
|
+
|
|
32
|
+
if (isExternalRequest) {
|
|
33
|
+
return [ false, MESSAGE_ACCESS_DENIED ];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return [ true ];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** Lambda Authorization */
|
|
40
|
+
class LambdaAuthorization {
|
|
41
|
+
private _verifyAccess: AccessVerificationMethod;
|
|
42
|
+
|
|
43
|
+
/** Creates an instance of System authorization security. */
|
|
44
|
+
constructor({
|
|
45
|
+
accessVerificationMethod = verifyAccess,
|
|
46
|
+
}: {
|
|
47
|
+
accessVerificationMethod?: AccessVerificationMethod;
|
|
48
|
+
}) {
|
|
49
|
+
this._verifyAccess = accessVerificationMethod;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Creates an instance of system authorization security. */
|
|
53
|
+
static createRequirement(options: RequirementOptions = {}): Record<string, Requirement> {
|
|
54
|
+
const name = get(options, 'name', DEFAULT_HEADER_NAME);
|
|
55
|
+
const description = get(options, 'description', DESCRIPTION);
|
|
56
|
+
const requirementName = get(options, 'requirementName', NAME);
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
[requirementName]: {
|
|
60
|
+
definition: {
|
|
61
|
+
in: 'header',
|
|
62
|
+
type: 'apiKey',
|
|
63
|
+
name,
|
|
64
|
+
description,
|
|
65
|
+
},
|
|
66
|
+
errors: LambdaAuthorization.errors,
|
|
67
|
+
/** Verifies context via JWT authorization requirement. */
|
|
68
|
+
verify: (context: Context) => {
|
|
69
|
+
const security = new LambdaAuthorization({ ...options });
|
|
70
|
+
return security.verify(context);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Returns security related errors. */
|
|
77
|
+
static get errors() {
|
|
78
|
+
return {
|
|
79
|
+
AccessDeniedError: {
|
|
80
|
+
statusCode: 403,
|
|
81
|
+
description: MESSAGE_ACCESS_DENIED
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Verifies System authorization. */
|
|
87
|
+
async verify(context: Context): Promise<VerificationResult> {
|
|
88
|
+
const [ isAccessOk, accessErrorMessage ] = await this._verifyAccess(context);
|
|
89
|
+
|
|
90
|
+
if (!isAccessOk) {
|
|
91
|
+
const error = new AccessDeniedError(accessErrorMessage);
|
|
92
|
+
return { isAuthorized: false, error };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const claims = {
|
|
96
|
+
isSystem: true,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
return { isAuthorized: true, claims };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export default LambdaAuthorization;
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { LambdaRequest } from '../../../Context';
|
|
2
|
+
import { createContext } from '../../../Context/__tests__/__helpers';
|
|
3
|
+
import { stringifyCookie } from 'cookie';
|
|
4
|
+
import { service, handler } from '../../../../example';
|
|
5
|
+
import { JwtAuthorization, createAccessToken, TEST_PUBLIC_KEY as publicKey } from '../../../';
|
|
6
|
+
|
|
7
|
+
describe('JwtAuthorization', () => {
|
|
8
|
+
const CreateProfile = service.get('CreateProfile');
|
|
9
|
+
|
|
10
|
+
describe('JwtAuthorization.createRequirement(options)', () => {
|
|
11
|
+
it('extends operation with Authorization security requirements', () => {
|
|
12
|
+
expect(CreateProfile.security[0].Authorization).toBeDefined();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('supports default access verification method without permissions map', async () => {
|
|
16
|
+
const Authorization = createAccessToken({}, { permissions: [] });
|
|
17
|
+
|
|
18
|
+
const request = {
|
|
19
|
+
headers: { authorization: Authorization },
|
|
20
|
+
operationId: 'CreateProfile'
|
|
21
|
+
} as LambdaRequest;
|
|
22
|
+
|
|
23
|
+
const context = createContext({ request });
|
|
24
|
+
|
|
25
|
+
const requirement = JwtAuthorization.createRequirement({ publicKey });
|
|
26
|
+
const verify = requirement.Authorization.verify;
|
|
27
|
+
|
|
28
|
+
const result = await verify(context);
|
|
29
|
+
|
|
30
|
+
expect(result.isAuthorized).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('supports default access verification method with permissions map', async () => {
|
|
34
|
+
const Authorization = createAccessToken({}, { permissions: [ 'profiles-read' ] });
|
|
35
|
+
|
|
36
|
+
const request = {
|
|
37
|
+
headers: { authorization: Authorization },
|
|
38
|
+
operationId: 'CreateProfile'
|
|
39
|
+
} as LambdaRequest;
|
|
40
|
+
|
|
41
|
+
const context = createContext({ request });
|
|
42
|
+
|
|
43
|
+
const requirement = JwtAuthorization.createRequirement({
|
|
44
|
+
publicKey,
|
|
45
|
+
permissions: { 'profiles-write': [ 'CreateProfile' ] }
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const verify = requirement.Authorization.verify;
|
|
49
|
+
|
|
50
|
+
const result = await verify(context);
|
|
51
|
+
|
|
52
|
+
expect(result.isAuthorized).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('JwtAuthorization.errors', () => {
|
|
57
|
+
it('includes authorization related errors', () => {
|
|
58
|
+
const errorCodes = Object.keys(CreateProfile.errors);
|
|
59
|
+
expect(errorCodes).toContain('UnauthorizedError');
|
|
60
|
+
expect(errorCodes).toContain('AccessDeniedError');
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('.verify(context)', () => {
|
|
65
|
+
it('returns UnauthorizedError if no authorization header provided', async () => {
|
|
66
|
+
const request = {
|
|
67
|
+
operationId: 'CreateProfile',
|
|
68
|
+
} as LambdaRequest;
|
|
69
|
+
|
|
70
|
+
const { statusCode, body: json } = await handler(request);
|
|
71
|
+
|
|
72
|
+
expect(statusCode).toEqual(401);
|
|
73
|
+
|
|
74
|
+
const body = JSON.parse(json!);
|
|
75
|
+
|
|
76
|
+
expect(body).toEqual({
|
|
77
|
+
error: {
|
|
78
|
+
code: 'UnauthorizedError',
|
|
79
|
+
message: 'Header "authorization" is missing',
|
|
80
|
+
statusCode: 401,
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('returns UnauthorizedError if invalid authorization header provided', async () => {
|
|
86
|
+
const request = {
|
|
87
|
+
operationId: 'CreateProfile',
|
|
88
|
+
headers: {
|
|
89
|
+
Authorization: 'INVALID_AUTHORIZATION_TOKEN',
|
|
90
|
+
}
|
|
91
|
+
} as LambdaRequest;
|
|
92
|
+
|
|
93
|
+
const { statusCode, body: json } = await handler(request);
|
|
94
|
+
|
|
95
|
+
expect(statusCode).toEqual(401);
|
|
96
|
+
|
|
97
|
+
const body = JSON.parse(json!);
|
|
98
|
+
|
|
99
|
+
expect(body).toEqual({
|
|
100
|
+
error: {
|
|
101
|
+
code: 'UnauthorizedError',
|
|
102
|
+
message: 'Invalid "authorization" token',
|
|
103
|
+
statusCode: 401,
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('returns UnauthorizedError if token is not verified as expired', async () => {
|
|
109
|
+
const exp = Math.floor((new Date('2026-01-01T00:00:00Z').getTime()) / 1000);
|
|
110
|
+
const Authorization = createAccessToken({}, { exp });
|
|
111
|
+
|
|
112
|
+
const request = {
|
|
113
|
+
operationId: 'CreateProfile',
|
|
114
|
+
headers: {
|
|
115
|
+
Authorization,
|
|
116
|
+
}
|
|
117
|
+
} as LambdaRequest;
|
|
118
|
+
|
|
119
|
+
const { statusCode, body: json } = await handler(request);
|
|
120
|
+
|
|
121
|
+
expect(statusCode).toEqual(401);
|
|
122
|
+
|
|
123
|
+
const body = JSON.parse(json!);
|
|
124
|
+
|
|
125
|
+
expect(body).toEqual({
|
|
126
|
+
error: {
|
|
127
|
+
code: 'UnauthorizedError',
|
|
128
|
+
message: '"authorization" token verification failed: jwt expired',
|
|
129
|
+
statusCode: 401,
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('returns UnauthorizedError if invalid token issuer', async () => {
|
|
135
|
+
const issuer = 'http://example.com';
|
|
136
|
+
const Authorization = createAccessToken({ issuer }, {});
|
|
137
|
+
|
|
138
|
+
const request = {
|
|
139
|
+
operationId: 'CreateProfile',
|
|
140
|
+
headers: {
|
|
141
|
+
Authorization,
|
|
142
|
+
}
|
|
143
|
+
} as LambdaRequest;
|
|
144
|
+
|
|
145
|
+
const { statusCode, body: json } = await handler(request);
|
|
146
|
+
|
|
147
|
+
expect(statusCode).toEqual(401);
|
|
148
|
+
|
|
149
|
+
const body = JSON.parse(json!);
|
|
150
|
+
|
|
151
|
+
expect(body).toEqual({
|
|
152
|
+
error: {
|
|
153
|
+
code: 'UnauthorizedError',
|
|
154
|
+
message: 'Invalid issuer of "authorization" token',
|
|
155
|
+
statusCode: 401,
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('returns AccessDeniedError if access verification failed', async () => {
|
|
161
|
+
const Authorization = createAccessToken({}, { permissions: [] });
|
|
162
|
+
|
|
163
|
+
const request = {
|
|
164
|
+
operationId: 'CreateProfile',
|
|
165
|
+
headers: {
|
|
166
|
+
Authorization,
|
|
167
|
+
}
|
|
168
|
+
} as LambdaRequest;
|
|
169
|
+
|
|
170
|
+
const { statusCode, body: json } = await handler(request);
|
|
171
|
+
|
|
172
|
+
expect(statusCode).toEqual(403);
|
|
173
|
+
|
|
174
|
+
const body = JSON.parse(json!);
|
|
175
|
+
|
|
176
|
+
expect(body).toEqual({
|
|
177
|
+
error: {
|
|
178
|
+
code: 'AccessDeniedError',
|
|
179
|
+
message: 'Access denied',
|
|
180
|
+
statusCode: 403,
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('returns success for a valid authorization header', async () => {
|
|
186
|
+
const Authorization = createAccessToken({}, { permissions: [ 'profiles-write' ] });
|
|
187
|
+
|
|
188
|
+
const request = {
|
|
189
|
+
operationId: 'CreateProfile',
|
|
190
|
+
headers: {
|
|
191
|
+
Authorization,
|
|
192
|
+
},
|
|
193
|
+
body: {
|
|
194
|
+
name: 'John Doe',
|
|
195
|
+
},
|
|
196
|
+
} as LambdaRequest;
|
|
197
|
+
|
|
198
|
+
const { statusCode, body: json } = await handler(request);
|
|
199
|
+
|
|
200
|
+
expect(statusCode).toEqual(201);
|
|
201
|
+
|
|
202
|
+
const body = JSON.parse(json!);
|
|
203
|
+
|
|
204
|
+
expect(body.data.name).toEqual('John Doe');
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('returns success for a valid authorization cookie', async () => {
|
|
208
|
+
const Authorization = createAccessToken({}, { permissions: [ 'profiles-write' ] });
|
|
209
|
+
const cookie = stringifyCookie({ Authorization });
|
|
210
|
+
|
|
211
|
+
const request = {
|
|
212
|
+
operationId: 'CreateProfile',
|
|
213
|
+
headers: {
|
|
214
|
+
cookie,
|
|
215
|
+
},
|
|
216
|
+
body: {
|
|
217
|
+
name: 'John Doe',
|
|
218
|
+
},
|
|
219
|
+
} as LambdaRequest;
|
|
220
|
+
|
|
221
|
+
const { statusCode, body: json } = await handler(request);
|
|
222
|
+
|
|
223
|
+
expect(statusCode).toEqual(201);
|
|
224
|
+
|
|
225
|
+
const body = JSON.parse(json!);
|
|
226
|
+
|
|
227
|
+
expect(body.data.name).toEqual('John Doe');
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Profile } from '../../../../example/documents';
|
|
2
|
+
import { LambdaRequest } from '../../../Context';
|
|
3
|
+
import { createContext } from '../../../Context/__tests__/__helpers';
|
|
4
|
+
import { service, handler } from '../../../../example';
|
|
5
|
+
|
|
6
|
+
describe('LambdaAuthorization', () => {
|
|
7
|
+
const operationId = 'ReadProfileSystem';
|
|
8
|
+
const ReadProfileSystem = service.get(operationId);
|
|
9
|
+
|
|
10
|
+
describe('LambdaAuthorization.createRequirement(options)', () => {
|
|
11
|
+
it('extends operation with System security requirements', () => {
|
|
12
|
+
expect(ReadProfileSystem.security[0].System).toBeDefined();
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe('LambdaAuthorization.errors', () => {
|
|
17
|
+
it('includes authorization related errors', () => {
|
|
18
|
+
const errorCodes = Object.keys(ReadProfileSystem.errors);
|
|
19
|
+
expect(errorCodes).toContain('AccessDeniedError');
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('.verify(context)', () => {
|
|
24
|
+
it('returns AccessDeniedError if headers are set by the gateway for external request', async () => {
|
|
25
|
+
const request = {
|
|
26
|
+
operationId,
|
|
27
|
+
headers: { Host: 'http://localhost:3000/' },
|
|
28
|
+
} as LambdaRequest;
|
|
29
|
+
|
|
30
|
+
const { statusCode, body: json } = await handler(request);
|
|
31
|
+
|
|
32
|
+
expect(statusCode).toEqual(403);
|
|
33
|
+
|
|
34
|
+
const body = JSON.parse(json!);
|
|
35
|
+
|
|
36
|
+
expect(body).toEqual({
|
|
37
|
+
error: {
|
|
38
|
+
code: 'AccessDeniedError',
|
|
39
|
+
message: 'Access denied, operation is available only for internal requests',
|
|
40
|
+
statusCode: 403,
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('returns success if no headers are set by the gateway for internal request', async () => {
|
|
46
|
+
const context = createContext();
|
|
47
|
+
const { id } = await Profile.create(context, { name: 'John Doe' });
|
|
48
|
+
|
|
49
|
+
const request = {
|
|
50
|
+
operationId,
|
|
51
|
+
queryStringParameters: { id },
|
|
52
|
+
} as LambdaRequest;
|
|
53
|
+
|
|
54
|
+
const { statusCode, body: json } = await handler(request);
|
|
55
|
+
|
|
56
|
+
expect(statusCode).toEqual(200);
|
|
57
|
+
|
|
58
|
+
const body = JSON.parse(json!);
|
|
59
|
+
|
|
60
|
+
expect(body.data.name).toEqual('John Doe');
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Profile } from '../../../Document/__tests__/__helpers';
|
|
2
|
+
import userAuthorization from '../userAuthorization';
|
|
3
|
+
import { Create, Update } from '../../';
|
|
4
|
+
import { TEST_ISSUER as issuer, TEST_PRIVATE_KEY as publicKey } from '../../../Service';
|
|
5
|
+
|
|
6
|
+
describe('userAuthorization(props)', () => {
|
|
7
|
+
describe('OperationClass.permissions', () => {
|
|
8
|
+
const permissions = {
|
|
9
|
+
'profile-write': [
|
|
10
|
+
'CreateProfile',
|
|
11
|
+
],
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
it('returns null if permissions are not defined', () => {
|
|
15
|
+
const asUser = userAuthorization({ issuer, publicKey });
|
|
16
|
+
|
|
17
|
+
/** Operation class to test no permissions case. */
|
|
18
|
+
class CreateProfile extends asUser(Create(Profile)) {}
|
|
19
|
+
|
|
20
|
+
expect(CreateProfile.permissions).toBeNull();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('returns permissions from the permissions map', () => {
|
|
24
|
+
const asUser = userAuthorization({ issuer, publicKey, permissions });
|
|
25
|
+
|
|
26
|
+
/** Operation class to test no permissions case. */
|
|
27
|
+
class CreateProfile extends asUser(Create(Profile)) {}
|
|
28
|
+
|
|
29
|
+
expect(CreateProfile.permissions).toEqual([ 'profile-write' ]);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('throws exception if operation permissions is not defined', () => {
|
|
33
|
+
const asUser = userAuthorization({ issuer, publicKey, permissions });
|
|
34
|
+
|
|
35
|
+
/** Operation class to test no permissions case. */
|
|
36
|
+
class UpdateProfile extends asUser(Update(Profile)) {}
|
|
37
|
+
|
|
38
|
+
expect(() => UpdateProfile.permissions)
|
|
39
|
+
.toThrow('Permissions not defined for operation "UpdateProfile"');
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import verifyToken from './verifyToken';
|
|
2
|
+
import JwtAuthorization from './JwtAuthorization';
|
|
3
|
+
import userAuthorization from './userAuthorization';
|
|
4
|
+
import systemAuthorization from './systemAuthorization';
|
|
5
|
+
import LambdaAuthorization from './LambdaAuthorization';
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
verifyToken,
|
|
9
|
+
JwtAuthorization,
|
|
10
|
+
userAuthorization,
|
|
11
|
+
systemAuthorization,
|
|
12
|
+
LambdaAuthorization,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type * from './JwtAuthorization';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Operation from '../Operation';
|
|
2
|
+
import LambdaAuthorization from './LambdaAuthorization';
|
|
3
|
+
|
|
4
|
+
const authorizationRequirement = LambdaAuthorization.createRequirement();
|
|
5
|
+
|
|
6
|
+
/** Returns helper to extend operation class with system authorization requirements. */
|
|
7
|
+
const systemAuthorization = () => {
|
|
8
|
+
return (OperationClass: typeof Operation): typeof Operation =>
|
|
9
|
+
/** Extended operation class. */
|
|
10
|
+
class extends OperationClass {
|
|
11
|
+
/** Returns operation security requirements. */
|
|
12
|
+
static get security() {
|
|
13
|
+
return [ authorizationRequirement ];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Returns a list of permissions to access operation. */
|
|
17
|
+
static get permissions() {
|
|
18
|
+
return [ 'System' ];
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default systemAuthorization;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import Operation from '../Operation';
|
|
2
|
+
import JwtAuthorization, { type Permissions } from './JwtAuthorization';
|
|
3
|
+
|
|
4
|
+
type Props = {
|
|
5
|
+
issuer: string;
|
|
6
|
+
publicKey: string;
|
|
7
|
+
permissions?: Permissions;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Returns helper to extend operation class with user authorization requirement. */
|
|
11
|
+
const userAuthorization = (props: Props) => {
|
|
12
|
+
const authorizationRequirement = JwtAuthorization.createRequirement(props);
|
|
13
|
+
|
|
14
|
+
return (OperationClass: typeof Operation): typeof Operation =>
|
|
15
|
+
/** Extended operation class. */
|
|
16
|
+
class extends OperationClass {
|
|
17
|
+
/** Returns operation security requirements. */
|
|
18
|
+
static get security() {
|
|
19
|
+
return [ authorizationRequirement ];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Returns a list of permissions to access operation. */
|
|
23
|
+
static get permissions() {
|
|
24
|
+
const permissionsMap = props.permissions;
|
|
25
|
+
|
|
26
|
+
if (!permissionsMap) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const { id: operationId } = this;
|
|
31
|
+
|
|
32
|
+
const operationPermissions = Object.entries(permissionsMap)
|
|
33
|
+
.filter(([, operationIds]) => operationIds.includes(operationId))
|
|
34
|
+
.map(([permission]) => permission);
|
|
35
|
+
|
|
36
|
+
const hasPermissionsDefined = operationPermissions.length > 0;
|
|
37
|
+
|
|
38
|
+
if (!hasPermissionsDefined) {
|
|
39
|
+
throw new Error(`Permissions not defined for operation "${operationId}"`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return operationPermissions;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default userAuthorization;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import Context from '../../Context';
|
|
2
|
+
import { verify, type Algorithm } from 'jsonwebtoken';
|
|
3
|
+
|
|
4
|
+
/** Verifies JWT via public key and an algorithm. */
|
|
5
|
+
const verifyToken = async (
|
|
6
|
+
_context: Context,
|
|
7
|
+
token: string,
|
|
8
|
+
publicKey: string,
|
|
9
|
+
algorithm: Algorithm
|
|
10
|
+
): Promise<[ true ] | [ false, string ]> => {
|
|
11
|
+
try {
|
|
12
|
+
verify(token, publicKey, { algorithms: [ algorithm ] });
|
|
13
|
+
|
|
14
|
+
} catch (verificationError) {
|
|
15
|
+
return [ false, (verificationError as Error).message ];
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return [ true ];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default verifyToken;
|