@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,50 @@
|
|
|
1
|
+
import { firstItemGet } from '../';
|
|
2
|
+
|
|
3
|
+
describe('firstItemGet(items, attributeName, isUndefinedExpected)', () => {
|
|
4
|
+
const items = [
|
|
5
|
+
{ id: '1', name: 'Alice', role: 'admin', nested: { value: 'test' } },
|
|
6
|
+
{ id: '2', name: 'Bob', role: 'user' },
|
|
7
|
+
];
|
|
8
|
+
|
|
9
|
+
describe('when isUndefinedExpected is false (default)', () => {
|
|
10
|
+
it('returns attribute value when first item exists and has the attribute', () => {
|
|
11
|
+
expect(firstItemGet(items, 'id')).toEqual('1');
|
|
12
|
+
expect(firstItemGet(items, 'name')).toEqual('Alice');
|
|
13
|
+
expect(firstItemGet(items, 'role')).toEqual('admin');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('returns nested attribute value when first item has nested attribute', () => {
|
|
17
|
+
expect(firstItemGet(items, 'nested.value')).toEqual('test');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('throws when first item is undefined (empty array)', () => {
|
|
21
|
+
expect(() => firstItemGet([], 'id')).toThrow();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('throws when first item exists but attribute does not exist', () => {
|
|
25
|
+
expect(() => firstItemGet(items, 'missing')).toThrow();
|
|
26
|
+
expect(() => firstItemGet(items, 'nested.missing')).toThrow();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('when isUndefinedExpected is true', () => {
|
|
31
|
+
it('returns attribute value when first item exists and has the attribute', () => {
|
|
32
|
+
expect(firstItemGet(items, 'id', true)).toEqual('1');
|
|
33
|
+
expect(firstItemGet(items, 'name', true)).toEqual('Alice');
|
|
34
|
+
expect(firstItemGet(items, 'role', true)).toEqual('admin');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('returns nested attribute value when first item has nested attribute', () => {
|
|
38
|
+
expect(firstItemGet(items, 'nested.value', true)).toEqual('test');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('returns undefined when first item is undefined (empty array)', () => {
|
|
42
|
+
expect(firstItemGet([], 'id', true)).toBeUndefined();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('returns undefined when first item exists but attribute does not exist', () => {
|
|
46
|
+
expect(firstItemGet(items, 'missing', true)).toBeUndefined();
|
|
47
|
+
expect(firstItemGet(items, 'nested.missing', true)).toBeUndefined();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { wait } from '../';
|
|
2
|
+
|
|
3
|
+
describe('wait(ms)', () => {
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
jest.useFakeTimers();
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
jest.runOnlyPendingTimers();
|
|
10
|
+
jest.useRealTimers();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('returns a Promise', () => {
|
|
14
|
+
expect(wait(100)).toBeInstanceOf(Promise);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('resolves after specified milliseconds', async () => {
|
|
18
|
+
const promise = wait(100);
|
|
19
|
+
let resolved = false;
|
|
20
|
+
|
|
21
|
+
promise.then(() => {
|
|
22
|
+
resolved = true;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
expect(resolved).toBe(false);
|
|
26
|
+
jest.advanceTimersByTime(99);
|
|
27
|
+
await Promise.resolve();
|
|
28
|
+
expect(resolved).toBe(false);
|
|
29
|
+
jest.advanceTimersByTime(1);
|
|
30
|
+
await Promise.resolve();
|
|
31
|
+
expect(resolved).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('resolves when ms is 0', async () => {
|
|
35
|
+
const promise = wait(0);
|
|
36
|
+
let resolved = false;
|
|
37
|
+
|
|
38
|
+
promise.then(() => {
|
|
39
|
+
resolved = true;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
expect(resolved).toBe(false);
|
|
43
|
+
jest.advanceTimersByTime(0);
|
|
44
|
+
await Promise.resolve();
|
|
45
|
+
expect(resolved).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('handles different time durations correctly', async () => {
|
|
49
|
+
const promise1 = wait(50);
|
|
50
|
+
const promise2 = wait(200);
|
|
51
|
+
let resolved1 = false;
|
|
52
|
+
let resolved2 = false;
|
|
53
|
+
|
|
54
|
+
promise1.then(() => { resolved1 = true; });
|
|
55
|
+
promise2.then(() => { resolved2 = true; });
|
|
56
|
+
|
|
57
|
+
jest.advanceTimersByTime(50);
|
|
58
|
+
await Promise.resolve();
|
|
59
|
+
expect(resolved1).toBe(true);
|
|
60
|
+
expect(resolved2).toBe(false);
|
|
61
|
+
|
|
62
|
+
jest.advanceTimersByTime(150);
|
|
63
|
+
await Promise.resolve();
|
|
64
|
+
expect(resolved2).toBe(true);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { sign, type SignOptions } from 'jsonwebtoken';
|
|
2
|
+
import { TEST_ISSUER, TEST_PRIVATE_KEY } from './keys';
|
|
3
|
+
|
|
4
|
+
interface Options extends SignOptions {
|
|
5
|
+
exp?: string;
|
|
6
|
+
privateKey?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Creates access token. */
|
|
10
|
+
const createAccessToken = (options: Options, claims: Record<string, unknown>) => {
|
|
11
|
+
const {
|
|
12
|
+
issuer = TEST_ISSUER,
|
|
13
|
+
algorithm = 'RS256',
|
|
14
|
+
privateKey = TEST_PRIVATE_KEY,
|
|
15
|
+
...signOptions
|
|
16
|
+
} = options;
|
|
17
|
+
|
|
18
|
+
const payload = {
|
|
19
|
+
sub: 'TEST_USER_ID',
|
|
20
|
+
...claims
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const token = sign(payload, privateKey, { algorithm, issuer, ...signOptions });
|
|
24
|
+
|
|
25
|
+
return `Bearer ${token}`;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default createAccessToken;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import findItem, { type Items, type Query } from './findItem';
|
|
2
|
+
|
|
3
|
+
/** Ensures item to exists in a list for specified query. */
|
|
4
|
+
const ensureItem = (items: Items, query: Query) => {
|
|
5
|
+
const item = findItem(items, query);
|
|
6
|
+
expect(item).toBeDefined();
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default ensureItem;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import findItem, { type Items, type Query } from './findItem';
|
|
2
|
+
|
|
3
|
+
/** Ensures item does not exist in a list for specified query. */
|
|
4
|
+
const ensureNoItem = (data: Items, query: Query) => {
|
|
5
|
+
const item = findItem(data, query);
|
|
6
|
+
expect(item).toBeUndefined();
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default ensureNoItem;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import Service from '../Service';
|
|
2
|
+
import { type ErrorAttributes } from '../errors';
|
|
3
|
+
import type { Headers, MutationMap, LambdaRequest, Logger } from '../../Context';
|
|
4
|
+
|
|
5
|
+
const SUCCESS_HTTP_CODES = [ 200, 201, 204 ];
|
|
6
|
+
const NO_RESPONSE_HTTP_CODE = 204;
|
|
7
|
+
|
|
8
|
+
type Parameters = {
|
|
9
|
+
mutation?: MutationMap;
|
|
10
|
+
[index: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type SuccessResult = { data: Record<string, unknown>; };
|
|
14
|
+
type ErrorResult = { error: ErrorAttributes; };
|
|
15
|
+
type Result = SuccessResult | ErrorResult;
|
|
16
|
+
|
|
17
|
+
type Options = {
|
|
18
|
+
logger?: Logger
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** Returns helpers to process requests successfully or expect an error. */
|
|
22
|
+
const execute = (service: Service, options: Options = {}) => {
|
|
23
|
+
const { logger = console } = options;
|
|
24
|
+
|
|
25
|
+
/** Processes an operation parameters via service. */
|
|
26
|
+
const exec = async (operationId: string, parameters: Parameters = {}, headers: Headers = {}) => {
|
|
27
|
+
const { mutation: body, ...queryStringParameters } = parameters;
|
|
28
|
+
|
|
29
|
+
const request = {
|
|
30
|
+
body,
|
|
31
|
+
headers,
|
|
32
|
+
operationId,
|
|
33
|
+
queryStringParameters
|
|
34
|
+
} as LambdaRequest;
|
|
35
|
+
|
|
36
|
+
const response = await service.process(request);
|
|
37
|
+
|
|
38
|
+
let result;
|
|
39
|
+
|
|
40
|
+
if (response.body) {
|
|
41
|
+
result = JSON.parse(response.body) as Result;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return { ...response, result };
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** Processes an operation parameters via service, expects successfull response. */
|
|
48
|
+
const request = async (operationId: string, parameters: Parameters = {}, headers: Headers = {}) => {
|
|
49
|
+
const {
|
|
50
|
+
result,
|
|
51
|
+
statusCode,
|
|
52
|
+
} = await exec(operationId, parameters, headers);
|
|
53
|
+
|
|
54
|
+
let data;
|
|
55
|
+
|
|
56
|
+
const isResultExpected = statusCode !== NO_RESPONSE_HTTP_CODE;
|
|
57
|
+
|
|
58
|
+
if (isResultExpected) {
|
|
59
|
+
data = (result as SuccessResult).data;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const isSuccess = SUCCESS_HTTP_CODES.includes(statusCode);
|
|
63
|
+
|
|
64
|
+
if (!isSuccess) {
|
|
65
|
+
const { error } = (result as ErrorResult);
|
|
66
|
+
|
|
67
|
+
logger.error(`\x1b[31mRequestError for "${operationId}"\x1b[37m`);
|
|
68
|
+
logger.dir({ operationId, parameters, error }, { depth: null });
|
|
69
|
+
|
|
70
|
+
throw Error(`RequestError for "${operationId}"`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return data;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/** Processes an operation parameters via service, expects an error with a specific code. */
|
|
77
|
+
const expectError = async (errorCode: string, operationId: string, parameters: Parameters = {}, headers: Headers = {}) => {
|
|
78
|
+
const {
|
|
79
|
+
result,
|
|
80
|
+
statusCode,
|
|
81
|
+
} = await exec(operationId, parameters, headers);
|
|
82
|
+
|
|
83
|
+
const isSuccess = SUCCESS_HTTP_CODES.includes(statusCode);
|
|
84
|
+
|
|
85
|
+
if (isSuccess) {
|
|
86
|
+
const { data } = (result as SuccessResult);
|
|
87
|
+
|
|
88
|
+
logger.error(`\x1b[31mSuccess NOT expected for "${operationId}"\x1b[37m`);
|
|
89
|
+
logger.dir({ operationId, statusCode, parameters, data }, { depth: null });
|
|
90
|
+
|
|
91
|
+
throw Error(`Success NOT expected for "${operationId}"`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const { error } = (result as ErrorResult);
|
|
95
|
+
|
|
96
|
+
const isExpectedCode = error.code === errorCode;
|
|
97
|
+
|
|
98
|
+
if (!isExpectedCode) {
|
|
99
|
+
throw Error(`Unexpected error code received "${error.code}", expected "${errorCode}"`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return error;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
exec,
|
|
107
|
+
request,
|
|
108
|
+
expectError,
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export default execute;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type Item = Record<string, unknown>;
|
|
2
|
+
export type Items = Item[];
|
|
3
|
+
export type Query = Record<string, unknown>;
|
|
4
|
+
|
|
5
|
+
/** Finds item in a list using query. */
|
|
6
|
+
const findItem = (items: Items, query: Query): Item | undefined =>
|
|
7
|
+
items.find(item => {
|
|
8
|
+
for (const key in query) {
|
|
9
|
+
const queryValue = query[key];
|
|
10
|
+
const itemValue = item[key];
|
|
11
|
+
|
|
12
|
+
const isMatch = itemValue === queryValue;
|
|
13
|
+
|
|
14
|
+
if (!isMatch) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return true;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export default findItem;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { get } from 'lodash';
|
|
2
|
+
import { got } from '@kravc/schema';
|
|
3
|
+
import { type Items } from './findItem';
|
|
4
|
+
|
|
5
|
+
/** Returns value or ensures specified attribute exists for the first item from the list. */
|
|
6
|
+
const firstItemGet = (items: Items, attributeName: string, isUndefinedExpected: boolean = false) => {
|
|
7
|
+
const [ firstItem ] = items;
|
|
8
|
+
|
|
9
|
+
if (isUndefinedExpected) {
|
|
10
|
+
return get(firstItem || {}, attributeName);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
expect(firstItem).toBeDefined();
|
|
14
|
+
|
|
15
|
+
return got(firstItem, attributeName);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default firstItemGet;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import wait from './wait';
|
|
2
|
+
import execute from './execute';
|
|
3
|
+
import findItem from './findItem';
|
|
4
|
+
import ensureItem from './ensureItem';
|
|
5
|
+
import ensureNoItem from './ensureNoItem';
|
|
6
|
+
import firstItemGet from './firstItemGet';
|
|
7
|
+
import createAccessToken from './createAccessToken';
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
wait,
|
|
11
|
+
execute,
|
|
12
|
+
findItem,
|
|
13
|
+
ensureItem,
|
|
14
|
+
ensureNoItem,
|
|
15
|
+
firstItemGet,
|
|
16
|
+
createAccessToken
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export * from './keys';
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const TEST_ISSUER = 'http://localhost:3000';
|
|
2
|
+
|
|
3
|
+
const TEST_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
4
|
+
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA8+PZ2JWhsb9kwI4gdEhr
|
|
5
|
+
xaRimI6p/zYgYY9pb16wmiR5T2JaStWJU0Whbd8SImqgNPpNUkBhjMU1gY2rdYDr
|
|
6
|
+
K1vLyYcOrF6dZs50LzTZkxr6siWARYIOfgKKm+zfESNR2LhT+846pAwgjyzTfIri
|
|
7
|
+
E5astLrUtrHoDCH0kvUEBgWREDwNpOsDcuWdt/9J50rVKlIar5XhfPxN0ZPqkb4F
|
|
8
|
+
UnZXOwbE4yHEUcafXwnEAJ+e7nRMSAkTUQahN722xdZKYSeATSvANIAr64CH3Cxv
|
|
9
|
+
vHWDt7ZJUJ1wgRWmkyqOkJu+NwnNhVBLt/6KacMkdXLDJhq7KnOFOmGLqUIPEY2F
|
|
10
|
+
yFGahicWYoZiYCLli/XknzZRtmKjXrwvbIE6tx5lF/+RwD75Y4j057SHwDkvA/G7
|
|
11
|
+
aBMvcCBYMnRRuJnsnGf8hXwjbdjvbjx3S3NQU/nOumEuPEjSmm92WrnLXLfmVVrv
|
|
12
|
+
AImtxiAZWQi/EKVion96g3rTpirbbpp11+8JIlcy0cKZFNN3Vwfw2JmsG5srBEqz
|
|
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q758VerwUBL6T
|
|
58
|
+
qWrLMFMrK1SVTesHwxkP+dMYFRr8Na/5f1VmSeWwpFBpQskUNXE+7QXxeRLpWID0
|
|
59
|
+
T/EgTGlf6eUKwpKsgnRLzwsU1NZyPgIljgKBZk46yatZT7vplQ78iO6QwZzoDdFA
|
|
60
|
+
3wYA4Lnl7Nw+FAQzKtuBONpDJgTkCfFuIyriHlZj8qwaZk+Tk2ubArY2Dl3r93/g
|
|
61
|
+
bqZY28NAd802wMXeSq3zXb8svP6G2KEJmvp2nM3axXtPTDkybdLj8NaDlb1Ev3B6
|
|
62
|
+
IEvwdBbZOMGxFyplxHjTvPkbzQBmFnA9JIDHRvR2uUTRK28QvB3aCRPTD3vFaNem
|
|
63
|
+
9KJBAoIBAH7OBL3maedlRcFZSqFNvGhh+J6RO5+6oFN8+8BAvfp6/eziircZSsr+
|
|
64
|
+
NOWNkVamC4Ye0mBQIToGb+65LzIhUbPOq9e7DbZt6mQTD9RJ+qYHcrY4xkCUOljo
|
|
65
|
+
ovI6AzKS+ENQ34OHbQXdkPSF+XoRrz2yFmp9YbB18+QnHSdJpQhE1yHEdnWWqxGp
|
|
66
|
+
xcIsxWce/OpIR5XWqMYuRxfFZ6/ftNV263gtKuZKpdcYthsDtrINbIh+hCz4ppjM
|
|
67
|
+
SOnb9KGxz2qg82zm6YtSRrrh6WwlrapSP5IaX6gTgE6gXa57hDsq/faTqzo8nO5C
|
|
68
|
+
/SGCq5WpDkykHMReK+D02pckJVfJcY8=
|
|
69
|
+
-----END PRIVATE KEY-----`;
|
|
70
|
+
|
|
71
|
+
export {
|
|
72
|
+
TEST_ISSUER,
|
|
73
|
+
TEST_PUBLIC_KEY,
|
|
74
|
+
TEST_PRIVATE_KEY,
|
|
75
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { sync } from 'read-yaml-file';
|
|
2
|
+
import type { Context } from '../Context';
|
|
3
|
+
import { OK_STATUS, JSON_TYPE } from './useOasMiddleware';
|
|
4
|
+
|
|
5
|
+
const ROOT_PATH = process.cwd();
|
|
6
|
+
|
|
7
|
+
const COMPOSER_FILES = [
|
|
8
|
+
'/Enums.yaml',
|
|
9
|
+
'/Schemas.yaml',
|
|
10
|
+
'/Documents.yaml',
|
|
11
|
+
'/Scenarios.yaml',
|
|
12
|
+
'/Operations.yaml',
|
|
13
|
+
'/Parameters.yaml'
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
/** Returns result if request is for service composer file. */
|
|
17
|
+
const useComposerMiddleware = (_service: unknown, context: Context) => {
|
|
18
|
+
const {
|
|
19
|
+
httpPath,
|
|
20
|
+
httpMethod,
|
|
21
|
+
isDevelopment
|
|
22
|
+
} = context;
|
|
23
|
+
|
|
24
|
+
const isGetRequest = httpMethod === 'get';
|
|
25
|
+
|
|
26
|
+
/** Returns specified composer source file. */
|
|
27
|
+
const readFileJson = (httpPath: string) => {
|
|
28
|
+
const fileName = httpPath.replace('/', '');
|
|
29
|
+
const composerSource = sync(`${ROOT_PATH}/.composer/${fileName}`);
|
|
30
|
+
|
|
31
|
+
return JSON.stringify(composerSource, null, 2);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const isComposerPath = COMPOSER_FILES.includes(httpPath);
|
|
35
|
+
|
|
36
|
+
const shouldReturnComposerSource =
|
|
37
|
+
isDevelopment &&
|
|
38
|
+
isGetRequest &&
|
|
39
|
+
isComposerPath;
|
|
40
|
+
|
|
41
|
+
if (!shouldReturnComposerSource) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const bodyJson = readFileJson(httpPath);
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
headers: {
|
|
49
|
+
'Content-Type': JSON_TYPE
|
|
50
|
+
},
|
|
51
|
+
statusCode: OK_STATUS,
|
|
52
|
+
body: bodyJson,
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export default useComposerMiddleware;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import { Context } from '../Context';
|
|
3
|
+
import { OpenAPIV2 } from 'openapi-types';
|
|
4
|
+
import getServiceInfo from './spec/getServiceInfo';
|
|
5
|
+
import { readFileSync } from 'fs';
|
|
6
|
+
|
|
7
|
+
const SWAGGER_UI_TEMPLATE_PATH = resolve(__dirname, '../../assets/index.html');
|
|
8
|
+
const SWAGGER_UI_TEMPLATE = readFileSync(SWAGGER_UI_TEMPLATE_PATH, { encoding: 'utf8' });
|
|
9
|
+
|
|
10
|
+
const TEXT_TYPE = 'text/html; charset=UTF-8';
|
|
11
|
+
export const JSON_TYPE = 'application/json; charset=utf-8';
|
|
12
|
+
export const OK_STATUS = 200;
|
|
13
|
+
|
|
14
|
+
/** Returns result if request is for service specification file. */
|
|
15
|
+
const useOasMiddleware = ({ spec }: { spec: OpenAPIV2.Document; }, context: Context) => {
|
|
16
|
+
const {
|
|
17
|
+
httpPath,
|
|
18
|
+
httpMethod,
|
|
19
|
+
isDevelopment
|
|
20
|
+
} = context;
|
|
21
|
+
|
|
22
|
+
const isGetRequest = httpMethod === 'get';
|
|
23
|
+
|
|
24
|
+
const isRootPath = httpPath === '/';
|
|
25
|
+
|
|
26
|
+
const shouldReturnBody =
|
|
27
|
+
isRootPath &&
|
|
28
|
+
isGetRequest;
|
|
29
|
+
|
|
30
|
+
if (shouldReturnBody) {
|
|
31
|
+
const bodyText = isDevelopment
|
|
32
|
+
? SWAGGER_UI_TEMPLATE.replace('$TITLE', getServiceInfo().title)
|
|
33
|
+
: 'healthy';
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
headers: {
|
|
37
|
+
'Content-Type': TEXT_TYPE
|
|
38
|
+
},
|
|
39
|
+
statusCode: OK_STATUS,
|
|
40
|
+
body: bodyText,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const isSpecPath = httpPath.toLowerCase() === '/spec';
|
|
45
|
+
|
|
46
|
+
const shouldReturnSpec =
|
|
47
|
+
isSpecPath &&
|
|
48
|
+
isGetRequest;
|
|
49
|
+
|
|
50
|
+
if (shouldReturnSpec) {
|
|
51
|
+
const body = isDevelopment
|
|
52
|
+
? spec
|
|
53
|
+
: { info: getServiceInfo() };
|
|
54
|
+
|
|
55
|
+
const bodyJson = JSON.stringify(body, null, 2);
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
headers: {
|
|
59
|
+
'Content-Type': JSON_TYPE
|
|
60
|
+
},
|
|
61
|
+
statusCode: OK_STATUS,
|
|
62
|
+
body: bodyJson,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return null;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export default useOasMiddleware;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { got } from '@kravc/schema';
|
|
2
|
+
export { got };
|
|
3
|
+
|
|
4
|
+
export * from './Component';
|
|
5
|
+
export * from './Document';
|
|
6
|
+
export * from './Operation';
|
|
7
|
+
export * from './Service';
|
|
8
|
+
export * from './Context';
|
|
9
|
+
|
|
10
|
+
export type * from './Context';
|
|
11
|
+
export type * from './Document';
|
|
12
|
+
export type * from './Operation';
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"rootDir": "./src",
|
|
4
|
+
"outDir": "./dist",
|
|
5
|
+
"target": "esnext",
|
|
6
|
+
"module": "nodenext",
|
|
7
|
+
"isolatedModules": true,
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"strictNullChecks": true,
|
|
11
|
+
"noUnusedLocals": true,
|
|
12
|
+
"noUnusedParameters": true,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"declaration": true,
|
|
15
|
+
"declarationMap": true,
|
|
16
|
+
"sourceMap": true
|
|
17
|
+
},
|
|
18
|
+
"include": [
|
|
19
|
+
"src"
|
|
20
|
+
],
|
|
21
|
+
"exclude": [
|
|
22
|
+
"node_modules",
|
|
23
|
+
"dist",
|
|
24
|
+
"**/*.test.ts"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const Create = require('../src/operations/Create')
|
|
4
|
-
const Profile = require('./Profile')
|
|
5
|
-
const verifyToken = require('../src/security/verifyToken')
|
|
6
|
-
const { publicKey } = require('../src/test/keys')
|
|
7
|
-
const JwtAuthorization = require('../src/security/JwtAuthorization')
|
|
8
|
-
|
|
9
|
-
class CreateProfile extends Create(Profile) {
|
|
10
|
-
static get tags() {
|
|
11
|
-
return [
|
|
12
|
-
'Profiles',
|
|
13
|
-
'profiles-write',
|
|
14
|
-
'System'
|
|
15
|
-
]
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
static get security() {
|
|
19
|
-
const algorithm = 'RS256'
|
|
20
|
-
|
|
21
|
-
const accessVerificationMethod = (context, { group }) => {
|
|
22
|
-
const isAccessGranted = [ 'Administrators' ].includes(group)
|
|
23
|
-
|
|
24
|
-
return [ isAccessGranted, 'Access denied' ]
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const tokenVerificationMethod = (...args) => verifyToken(...args)
|
|
28
|
-
|
|
29
|
-
return [
|
|
30
|
-
JwtAuthorization.createRequirement({
|
|
31
|
-
publicKey,
|
|
32
|
-
algorithm,
|
|
33
|
-
tokenVerificationMethod,
|
|
34
|
-
accessVerificationMethod
|
|
35
|
-
})
|
|
36
|
-
]
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
module.exports = CreateProfile
|
package/examples/Health.js
DELETED
package/examples/Profile.js
DELETED
package/examples/Profile.yaml
DELETED