@kravc/dos 1.12.6 → 2.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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/{src → dist/Service}/errors/OperationError.yaml +7 -10
- 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 +35 -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 +9 -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/Service/errors/OperationError.yaml +29 -0
- package/src/Service/errors/OperationErrorAttributes.d.ts +12 -0
- package/src/Service/errors/OperationNotFoundError.ts +45 -0
- package/src/Service/errors/__tests__/OperationError.test.ts +17 -0
- package/src/Service/errors/__tests__/maskSecrets.test.ts +92 -0
- package/src/Service/errors/index.ts +18 -0
- package/src/Service/errors/logOperationError.ts +72 -0
- package/src/Service/errors/maskSecrets.ts +65 -0
- package/src/Service/index.ts +9 -0
- package/src/Service/logRequest.ts +50 -0
- package/src/Service/spec/__tests__/validateSpec.test.ts +10 -0
- package/src/Service/spec/createSpec.ts +68 -0
- package/src/Service/spec/getErrorResponseDescription.ts +20 -0
- package/src/Service/spec/getHttpMethod.ts +20 -0
- package/src/Service/spec/getOperation.ts +99 -0
- package/src/Service/spec/getOperationParameters.ts +43 -0
- package/src/Service/spec/getServiceDefinitions.ts +23 -0
- package/src/Service/spec/getServiceInfo.ts +18 -0
- package/src/Service/spec/getServiceSecurityDefinitions.ts +26 -0
- package/src/Service/spec/getServiceTags.ts +23 -0
- package/src/Service/spec/getSuccessStatusCode.ts +15 -0
- package/src/Service/spec/index.ts +5 -0
- package/src/Service/spec/validateSpec.ts +22 -0
- package/src/Service/test/__tests__/createAccessToken.test.ts +104 -0
- package/src/Service/test/__tests__/ensureItem.test.ts +41 -0
- package/src/Service/test/__tests__/ensureNoItem.test.ts +49 -0
- package/src/Service/test/__tests__/execute.test.ts +125 -0
- package/src/Service/test/__tests__/findItem.test.ts +45 -0
- package/src/Service/test/__tests__/firstItemGet.test.ts +50 -0
- package/src/Service/test/__tests__/wait.test.ts +66 -0
- package/src/Service/test/createAccessToken.ts +28 -0
- package/src/Service/test/ensureItem.ts +9 -0
- package/src/Service/test/ensureNoItem.ts +9 -0
- package/src/Service/test/execute.ts +112 -0
- package/src/Service/test/findItem.ts +22 -0
- package/src/Service/test/firstItemGet.ts +18 -0
- package/src/Service/test/index.ts +19 -0
- package/src/Service/test/keys.ts +75 -0
- package/src/Service/test/wait.ts +5 -0
- package/src/Service/useComposerMiddleware.ts +56 -0
- package/src/Service/useOasMiddleware.ts +69 -0
- package/src/index.ts +12 -0
- package/tsconfig.json +26 -0
- package/examples/CreateProfile.js +0 -40
- package/examples/DeleteProfile.js +0 -6
- package/examples/Health.js +0 -8
- package/examples/IndexProfiles.js +0 -6
- package/examples/Profile.js +0 -8
- package/examples/Profile.yaml +0 -4
- package/examples/ReadProfile.js +0 -18
- package/examples/UpdateProfile.js +0 -25
- package/examples/index.js +0 -29
- package/src/Component.js +0 -59
- package/src/Component.spec.js +0 -65
- package/src/Document.js +0 -310
- package/src/Document.spec.js +0 -331
- package/src/Operation.js +0 -258
- package/src/Operation.spec.js +0 -474
- package/src/Service.js +0 -207
- package/src/Service.spec.js +0 -388
- package/src/errors/AccessDeniedError.js +0 -11
- package/src/errors/CommonError.js +0 -19
- package/src/errors/DocumentExistsError.js +0 -15
- package/src/errors/DocumentNotFoundError.js +0 -15
- package/src/errors/InvalidInputError.js +0 -19
- package/src/errors/InvalidOutputError.js +0 -20
- package/src/errors/InvalidParametersError.js +0 -11
- package/src/errors/OperationError.js +0 -44
- package/src/errors/OperationNotFoundError.js +0 -16
- package/src/errors/UnauthorizedError.js +0 -11
- package/src/errors/UnprocessibleConditionError.js +0 -11
- package/src/errors/index.js +0 -11
- package/src/helpers/asSafeClass.js +0 -22
- package/src/helpers/authorize.js +0 -44
- package/src/helpers/createContext.js +0 -96
- package/src/helpers/createSchemasMap.js +0 -37
- package/src/helpers/createSpec.js +0 -196
- package/src/helpers/defaultId.js +0 -30
- package/src/helpers/defaultSummary.js +0 -15
- package/src/helpers/defaultTags.js +0 -16
- package/src/helpers/getComponentTitle.js +0 -22
- package/src/helpers/getDefaultSchemaAttributes.js +0 -32
- package/src/helpers/getHttpMethod.js +0 -19
- package/src/helpers/getIdPrefix.js +0 -7
- package/src/helpers/getOrFail.js +0 -24
- package/src/helpers/getOrFail.spec.js +0 -17
- package/src/helpers/getSuccessStatusCode.js +0 -15
- package/src/helpers/handler.js +0 -21
- package/src/helpers/loadSync.js +0 -14
- package/src/helpers/logError.js +0 -33
- package/src/helpers/logRequest.js +0 -36
- package/src/helpers/maskSecrets.js +0 -42
- package/src/helpers/specMiddleware.js +0 -81
- package/src/index.d.ts +0 -352
- package/src/index.js +0 -35
- package/src/operations/Create.js +0 -39
- package/src/operations/Delete.js +0 -54
- package/src/operations/Index.js +0 -107
- package/src/operations/Read.js +0 -46
- package/src/operations/Update.js +0 -50
- package/src/security/JwtAuthorization.js +0 -125
- package/src/security/SystemAuthorization.js +0 -73
- package/src/security/index.js +0 -9
- package/src/security/verifyToken.js +0 -17
- package/src/test/createAccessToken.js +0 -23
- package/src/test/execute.js +0 -84
- package/src/test/index.js +0 -11
- package/src/test/keys.js +0 -39
- package/src/test/wait.js +0 -5
- /package/{specs → .composer}/Documents.yaml +0 -0
- /package/{specs → .composer}/Enums.yaml +0 -0
- /package/{specs → .composer}/Operations.yaml +0 -0
- /package/{specs → .composer}/Parameters.yaml +0 -0
- /package/{specs → .composer}/Scenarios.yaml +0 -0
- /package/{specs → .composer}/Schemas.yaml +0 -0
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { parse } = require('url')
|
|
4
|
-
const { v4: uuid } = require('uuid')
|
|
5
|
-
const { get, isString } = require('lodash')
|
|
6
|
-
|
|
7
|
-
const createContext = (service, request, extraContext = {}) => {
|
|
8
|
-
const { logger = console } = extraContext
|
|
9
|
-
|
|
10
|
-
let httpPath
|
|
11
|
-
let httpMethod
|
|
12
|
-
|
|
13
|
-
let { operationId } = request
|
|
14
|
-
|
|
15
|
-
if (!operationId) {
|
|
16
|
-
let { path } = request
|
|
17
|
-
|
|
18
|
-
if (!path) {
|
|
19
|
-
const { url } = request
|
|
20
|
-
path = parse(url, true).pathname
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const { basePath } = service
|
|
24
|
-
|
|
25
|
-
httpPath = path.replace(basePath, '/')
|
|
26
|
-
httpMethod = (request.method || request.httpMethod).toLowerCase()
|
|
27
|
-
|
|
28
|
-
operationId = service.getOperationId(httpMethod, httpPath)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const requestId = get(request, 'requestContext.requestId', uuid())
|
|
32
|
-
|
|
33
|
-
const context = {
|
|
34
|
-
headers: {},
|
|
35
|
-
baseUrl: service.baseUrl,
|
|
36
|
-
validator: service.validator,
|
|
37
|
-
requestReceivedAt: new Date().toISOString(),
|
|
38
|
-
logger,
|
|
39
|
-
httpPath,
|
|
40
|
-
requestId,
|
|
41
|
-
httpMethod,
|
|
42
|
-
operationId,
|
|
43
|
-
...extraContext,
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
for (const name in request.headers) {
|
|
47
|
-
context.headers[name.toLowerCase()] = request.headers[name]
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const { url, queryStringParameters, body } = request
|
|
51
|
-
|
|
52
|
-
context.query = {}
|
|
53
|
-
|
|
54
|
-
if (url) {
|
|
55
|
-
context.query = parse(url, true).query
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (queryStringParameters) {
|
|
59
|
-
const keys = Object.keys(queryStringParameters)
|
|
60
|
-
|
|
61
|
-
for (const key in keys) {
|
|
62
|
-
queryStringParameters[key] = decodeURIComponent(queryStringParameters[key])
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
context.query = queryStringParameters
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const queryKeys = Object.keys(context.query)
|
|
69
|
-
|
|
70
|
-
for (const queryKey of queryKeys) {
|
|
71
|
-
const value = context.query[queryKey]
|
|
72
|
-
|
|
73
|
-
const isJsonArray = `${value}`.startsWith('["')
|
|
74
|
-
|
|
75
|
-
if (isJsonArray) {
|
|
76
|
-
context.query[queryKey] = JSON.parse(value)
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (body) {
|
|
81
|
-
const isJSON = isString(body)
|
|
82
|
-
|
|
83
|
-
if (isJSON) {
|
|
84
|
-
context.bodyJson = body
|
|
85
|
-
context.mutation = JSON.parse(body)
|
|
86
|
-
|
|
87
|
-
} else {
|
|
88
|
-
context.mutation = body
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return context
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
module.exports = createContext
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const path = require('path')
|
|
4
|
-
const { keyBy } = require('lodash')
|
|
5
|
-
const loadSync = require('./loadSync')
|
|
6
|
-
const { readdirSync, statSync } = require('fs')
|
|
7
|
-
|
|
8
|
-
const SCHEMA_CLASS_NAME = 'Schema'
|
|
9
|
-
|
|
10
|
-
const listFilesSync = dir =>
|
|
11
|
-
readdirSync(dir)
|
|
12
|
-
.reduce((files, file) =>
|
|
13
|
-
statSync(path.join(dir, file)).isDirectory() ?
|
|
14
|
-
files.concat(listFilesSync(path.join(dir, file))) :
|
|
15
|
-
files.concat(path.join(dir, file))
|
|
16
|
-
, [])
|
|
17
|
-
|
|
18
|
-
const readSchemasSync = path =>
|
|
19
|
-
listFilesSync(path)
|
|
20
|
-
.filter(fileName => fileName.endsWith('.yaml'))
|
|
21
|
-
.map(schemaPath => loadSync(schemaPath))
|
|
22
|
-
|
|
23
|
-
const createSchemasMap = (path, modules) => {
|
|
24
|
-
const yamlSchemas = readSchemasSync(path)
|
|
25
|
-
const schemasMap = keyBy(yamlSchemas, 'id')
|
|
26
|
-
|
|
27
|
-
const schemas = modules
|
|
28
|
-
.filter(item => item.constructor.name === SCHEMA_CLASS_NAME)
|
|
29
|
-
|
|
30
|
-
for (const schema of schemas) {
|
|
31
|
-
schemasMap[schema.id] = schema
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return schemasMap
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
module.exports = createSchemasMap
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { omit, uniq } = require('lodash')
|
|
4
|
-
const ZSchema = require('z-schema')
|
|
5
|
-
const { parse } = require('url')
|
|
6
|
-
const jsonSchema = require('../../assets/schemas/oas2.json')
|
|
7
|
-
const getHttpMethod = require('./getHttpMethod')
|
|
8
|
-
const getSuccessStatusCode = require('./getSuccessStatusCode')
|
|
9
|
-
|
|
10
|
-
const ROOT_PATH = process.cwd()
|
|
11
|
-
const { name: title, version } = require(`${ROOT_PATH}/package.json`)
|
|
12
|
-
|
|
13
|
-
const formatErrorResponseDescription = errors => {
|
|
14
|
-
return errors
|
|
15
|
-
.map(({ code, description }) => {
|
|
16
|
-
if (!description) { return `\`${code}\`` }
|
|
17
|
-
|
|
18
|
-
return `\`${code}\` — ${description}`
|
|
19
|
-
})
|
|
20
|
-
.join('\n')
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const createSpec = (operations, schemasMap, url) => {
|
|
24
|
-
const { protocol: _protocol, host, path: basePath } = parse(url)
|
|
25
|
-
const protocol = _protocol.replace(':', '')
|
|
26
|
-
|
|
27
|
-
const spec = {
|
|
28
|
-
swagger: '2.0',
|
|
29
|
-
host,
|
|
30
|
-
basePath,
|
|
31
|
-
schemes: [ protocol ],
|
|
32
|
-
info: {
|
|
33
|
-
title,
|
|
34
|
-
version
|
|
35
|
-
},
|
|
36
|
-
consumes: [ 'application/json' ],
|
|
37
|
-
produces: [ 'application/json' ],
|
|
38
|
-
tags: [],
|
|
39
|
-
securityDefinitions: {},
|
|
40
|
-
paths: {},
|
|
41
|
-
definitions: {}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
for (const schemaId in schemasMap) {
|
|
45
|
-
const isNotInputSchema = !schemaId.endsWith('Input')
|
|
46
|
-
|
|
47
|
-
if (isNotInputSchema) {
|
|
48
|
-
const schema = schemasMap[schemaId]
|
|
49
|
-
spec.definitions[schemaId] = omit(schema.jsonSchema, [ 'id' ])
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
let serviceTags = []
|
|
54
|
-
for (const Operation of operations) {
|
|
55
|
-
const httpPath = `/${Operation.id}`
|
|
56
|
-
const httpMethod = getHttpMethod(Operation)
|
|
57
|
-
const operationId = Operation.id
|
|
58
|
-
|
|
59
|
-
const {
|
|
60
|
-
tags,
|
|
61
|
-
query,
|
|
62
|
-
errors,
|
|
63
|
-
summary,
|
|
64
|
-
security,
|
|
65
|
-
description,
|
|
66
|
-
outputSchema,
|
|
67
|
-
mutationSchema
|
|
68
|
-
} = Operation
|
|
69
|
-
|
|
70
|
-
serviceTags = serviceTags.concat(tags)
|
|
71
|
-
|
|
72
|
-
const operationSpec = {
|
|
73
|
-
tags,
|
|
74
|
-
summary,
|
|
75
|
-
description,
|
|
76
|
-
operationId
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const parameters = []
|
|
80
|
-
|
|
81
|
-
for (const name in query) {
|
|
82
|
-
const queryParameter = { in: 'query', name, type: 'string', ...query[name] }
|
|
83
|
-
|
|
84
|
-
if (queryParameter.example) {
|
|
85
|
-
queryParameter['x-example'] = queryParameter.example
|
|
86
|
-
delete queryParameter.example
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
parameters.push(queryParameter)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (mutationSchema) {
|
|
93
|
-
parameters.push({
|
|
94
|
-
in: 'body',
|
|
95
|
-
name: 'mutation',
|
|
96
|
-
schema: { $ref: mutationSchema.id },
|
|
97
|
-
required: true
|
|
98
|
-
})
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const hasParameters = parameters.length > 0
|
|
102
|
-
|
|
103
|
-
if (hasParameters) {
|
|
104
|
-
operationSpec.parameters = parameters
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const successStatusCode = getSuccessStatusCode(Operation)
|
|
108
|
-
const success = { description: 'Successful operation execution response' }
|
|
109
|
-
|
|
110
|
-
if (outputSchema) {
|
|
111
|
-
success.schema = { $ref: outputSchema.id }
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const responses = {
|
|
115
|
-
[successStatusCode]: success,
|
|
116
|
-
default: {
|
|
117
|
-
description: '`OperationError` — Default operation error',
|
|
118
|
-
schema: { $ref: 'OperationError' }
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const errorsMap = {}
|
|
123
|
-
|
|
124
|
-
for (const code in errors) {
|
|
125
|
-
const { statusCode, description } = errors[code]
|
|
126
|
-
|
|
127
|
-
errorsMap[`${statusCode}`] = errorsMap[`${statusCode}`] || []
|
|
128
|
-
errorsMap[`${statusCode}`].push({ code, description })
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
for (const statusCode in errorsMap) {
|
|
132
|
-
const description = formatErrorResponseDescription(errorsMap[statusCode])
|
|
133
|
-
|
|
134
|
-
responses[`${statusCode}`] = {
|
|
135
|
-
schema: { $ref: 'OperationError' },
|
|
136
|
-
description
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
operationSpec.responses = responses
|
|
141
|
-
|
|
142
|
-
const hasSecurityRequirements = security.length > 0
|
|
143
|
-
|
|
144
|
-
if (hasSecurityRequirements) {
|
|
145
|
-
operationSpec.security = []
|
|
146
|
-
|
|
147
|
-
for (const requirements of security) {
|
|
148
|
-
|
|
149
|
-
const config = {}
|
|
150
|
-
for (const name in requirements) {
|
|
151
|
-
const { definition } = requirements[name]
|
|
152
|
-
spec.securityDefinitions[name] = definition
|
|
153
|
-
|
|
154
|
-
config[name] = []
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
operationSpec.security.push(config)
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
spec.paths[httpPath] = { [httpMethod]: operationSpec }
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
serviceTags = uniq(serviceTags)
|
|
165
|
-
serviceTags.sort((a, b) => {
|
|
166
|
-
const aStartsWithUpper = /^[A-Z]/.test(a)
|
|
167
|
-
const bStartsWithUpper = /^[A-Z]/.test(b)
|
|
168
|
-
|
|
169
|
-
if (aStartsWithUpper && !bStartsWithUpper) { return -1 }
|
|
170
|
-
|
|
171
|
-
if (!aStartsWithUpper && bStartsWithUpper) { return 1 }
|
|
172
|
-
|
|
173
|
-
return a.localeCompare(b)
|
|
174
|
-
})
|
|
175
|
-
spec.tags = serviceTags.map(name => ({ name }))
|
|
176
|
-
|
|
177
|
-
const json = JSON
|
|
178
|
-
.stringify(spec, null, 2)
|
|
179
|
-
.replace(/"\$ref": "/g, '"$ref": "#/definitions/')
|
|
180
|
-
|
|
181
|
-
const result = JSON.parse(json)
|
|
182
|
-
|
|
183
|
-
const validator = new ZSchema({ ignoreUnknownFormats: true })
|
|
184
|
-
const isValid = validator.validate(result, { id: 'Spec', ...jsonSchema })
|
|
185
|
-
|
|
186
|
-
if (!isValid) {
|
|
187
|
-
const validationErrors = validator.getLastErrors()
|
|
188
|
-
|
|
189
|
-
const json = JSON.stringify(validationErrors, null, 2)
|
|
190
|
-
throw new Error(`Service spec validation failed: ${json}`)
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return result
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
module.exports = createSpec
|
package/src/helpers/defaultId.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { startCase } = require('lodash')
|
|
4
|
-
const pluralize = require('pluralize')
|
|
5
|
-
|
|
6
|
-
const defaultId = Operation => {
|
|
7
|
-
const { name, Component, componentAction } = Operation
|
|
8
|
-
|
|
9
|
-
const isCustom = name !== 'Operation' && name !== ''
|
|
10
|
-
|
|
11
|
-
if (isCustom) {
|
|
12
|
-
return name
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (Component && componentAction) {
|
|
16
|
-
const isIndex = componentAction === 'index'
|
|
17
|
-
const actionName = startCase(componentAction)
|
|
18
|
-
|
|
19
|
-
if (isIndex) {
|
|
20
|
-
const componentTitlePlural = pluralize(startCase(Component.name))
|
|
21
|
-
return `${actionName}${componentTitlePlural}`
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return `${actionName}${Component.name}`
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
throw new Error('Operation ID is undefined')
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
module.exports = defaultId
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { startCase, capitalize } = require('lodash')
|
|
4
|
-
|
|
5
|
-
const defaultSummary = (Component, componentAction) => {
|
|
6
|
-
if (!Component) { return '' }
|
|
7
|
-
|
|
8
|
-
const { name } = Component
|
|
9
|
-
|
|
10
|
-
const componentTitle = startCase(name).toLowerCase()
|
|
11
|
-
|
|
12
|
-
return capitalize(`${componentAction} ${componentTitle}`)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
module.exports = defaultSummary
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { startCase } = require('lodash')
|
|
4
|
-
const pluralize = require('pluralize')
|
|
5
|
-
|
|
6
|
-
const defaultTags = Component => {
|
|
7
|
-
if (!Component) { return [] }
|
|
8
|
-
|
|
9
|
-
const { name } = Component
|
|
10
|
-
|
|
11
|
-
const componentTitlePlural = pluralize(startCase(name))
|
|
12
|
-
|
|
13
|
-
return [ componentTitlePlural ]
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
module.exports = defaultTags
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { startCase, capitalize } = require('lodash')
|
|
4
|
-
const pluralize = require('pluralize')
|
|
5
|
-
|
|
6
|
-
const getComponentTitle = (Component, isCapitalized = true, isPlural = false) => {
|
|
7
|
-
const { name } = Component
|
|
8
|
-
|
|
9
|
-
let componentTitle = startCase(name).toLowerCase()
|
|
10
|
-
|
|
11
|
-
if (isPlural) {
|
|
12
|
-
componentTitle = pluralize(componentTitle)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (isCapitalized) {
|
|
16
|
-
componentTitle = capitalize(componentTitle)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return componentTitle
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
module.exports = getComponentTitle
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { capitalize } = require('lodash')
|
|
4
|
-
const getComponentTitle = require('./getComponentTitle')
|
|
5
|
-
|
|
6
|
-
const getDefaultSchemaAttributes = (Component) => {
|
|
7
|
-
const documentTitle = getComponentTitle(Component, false)
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
id: {
|
|
11
|
-
description: capitalize(documentTitle) + ' ID',
|
|
12
|
-
required: true
|
|
13
|
-
},
|
|
14
|
-
createdAt: {
|
|
15
|
-
description: `Date and time when ${documentTitle} was created`,
|
|
16
|
-
format: 'date-time',
|
|
17
|
-
required: true
|
|
18
|
-
},
|
|
19
|
-
updatedAt: {
|
|
20
|
-
description: `Date and time when ${documentTitle} was updated`,
|
|
21
|
-
format: 'date-time'
|
|
22
|
-
},
|
|
23
|
-
createdBy: {
|
|
24
|
-
description: `ID of a user who created ${documentTitle}`
|
|
25
|
-
},
|
|
26
|
-
updatedBy: {
|
|
27
|
-
description: `ID of a user who updated ${documentTitle}`
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
module.exports = getDefaultSchemaAttributes
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const getHttpMethod = ({ types: TYPES, type }) => {
|
|
4
|
-
switch (type) {
|
|
5
|
-
case TYPES.CREATE:
|
|
6
|
-
return 'post'
|
|
7
|
-
|
|
8
|
-
case TYPES.DELETE:
|
|
9
|
-
return 'delete'
|
|
10
|
-
|
|
11
|
-
case TYPES.UPDATE:
|
|
12
|
-
return 'patch'
|
|
13
|
-
|
|
14
|
-
default:
|
|
15
|
-
return 'get'
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
module.exports = getHttpMethod
|
package/src/helpers/getOrFail.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const lodash = require('lodash')
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Returns value by path from the object, throws exception if value not defined.
|
|
7
|
-
* @param {object} object - The object to pull value by path
|
|
8
|
-
* @param {string} path - The path of the value within object
|
|
9
|
-
* @returns {any} A value
|
|
10
|
-
*/
|
|
11
|
-
const getOrFail = (object, path) => {
|
|
12
|
-
const value = lodash.get(object, path)
|
|
13
|
-
const isUndefined = value === undefined
|
|
14
|
-
|
|
15
|
-
/* istanbul ignore else: we should not get here in tests */
|
|
16
|
-
if (!isUndefined) {
|
|
17
|
-
return value
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/* istanbul ignore next: should never be reached at runtime */
|
|
21
|
-
throw Error(`Value is undefined for "${path}"`)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
module.exports = getOrFail
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const getOrFail = require('./getOrFail')
|
|
4
|
-
const { expect } = require('chai')
|
|
5
|
-
|
|
6
|
-
describe('getOrFail(object, path)', () => {
|
|
7
|
-
it('returns requested value', () => {
|
|
8
|
-
const value = getOrFail({ target: 1 }, 'target')
|
|
9
|
-
expect(value).to.exist
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
it('throw error if value is undefined', () => {
|
|
13
|
-
expect(
|
|
14
|
-
() => getOrFail({}, 'target')
|
|
15
|
-
).to.throw('Value is undefined for "target"')
|
|
16
|
-
})
|
|
17
|
-
})
|
package/src/helpers/handler.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const logRequest = require('./logRequest')
|
|
4
|
-
const createContext = require('./createContext')
|
|
5
|
-
const specMiddleware = require('./specMiddleware')
|
|
6
|
-
|
|
7
|
-
const handler = (service, _createContext = createContext, _middleware = specMiddleware) => {
|
|
8
|
-
return (request, extraContext) => {
|
|
9
|
-
const context = _createContext(service, request, extraContext)
|
|
10
|
-
|
|
11
|
-
const result = _middleware(service, context)
|
|
12
|
-
|
|
13
|
-
if (result) { return result }
|
|
14
|
-
|
|
15
|
-
logRequest(context)
|
|
16
|
-
|
|
17
|
-
return service.process(context)
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
module.exports = handler
|
package/src/helpers/loadSync.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { load } = require('js-yaml')
|
|
4
|
-
const { Schema } = require('@kravc/schema')
|
|
5
|
-
const { readFileSync } = require('fs')
|
|
6
|
-
|
|
7
|
-
const loadSync = (yamlPath) => {
|
|
8
|
-
const id = yamlPath.split('/').reverse()[0].split('.yaml')[0]
|
|
9
|
-
const source = load(readFileSync(yamlPath))
|
|
10
|
-
|
|
11
|
-
return new Schema(source, id)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
module.exports = loadSync
|
package/src/helpers/logError.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { pick } = require('lodash')
|
|
4
|
-
const maskSecrets = require('./maskSecrets')
|
|
5
|
-
|
|
6
|
-
const OPERATION_CONTEXT_FIELDS = [
|
|
7
|
-
'query',
|
|
8
|
-
'mutation',
|
|
9
|
-
'identity',
|
|
10
|
-
'requestId',
|
|
11
|
-
'operationId',
|
|
12
|
-
'requestReceivedAt'
|
|
13
|
-
]
|
|
14
|
-
|
|
15
|
-
const logError = (context, errorResponse, originalError) => {
|
|
16
|
-
const { logger } = context
|
|
17
|
-
|
|
18
|
-
errorResponse.context = maskSecrets(pick(context, OPERATION_CONTEXT_FIELDS))
|
|
19
|
-
|
|
20
|
-
let unexpectedErrorMessage = ''
|
|
21
|
-
|
|
22
|
-
if (originalError.toJSON) {
|
|
23
|
-
errorResponse.originalError = originalError
|
|
24
|
-
|
|
25
|
-
} else {
|
|
26
|
-
unexpectedErrorMessage = `, Unexpected ${originalError.stack}`
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const errorResponseJson = JSON.stringify(errorResponse, null, 2)
|
|
30
|
-
logger.error(`OperationError ${errorResponseJson}${unexpectedErrorMessage}`)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
module.exports = logError
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const isTestEnvironment = () => process.env.NODE_APP_INSTANCE === 'test'
|
|
4
|
-
|
|
5
|
-
const logRequest = context => {
|
|
6
|
-
if (isTestEnvironment()) {
|
|
7
|
-
return
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const {
|
|
11
|
-
operationId,
|
|
12
|
-
query,
|
|
13
|
-
logger,
|
|
14
|
-
mutation,
|
|
15
|
-
requestId,
|
|
16
|
-
headers,
|
|
17
|
-
requestReceivedAt
|
|
18
|
-
} = context
|
|
19
|
-
|
|
20
|
-
const { host } = headers
|
|
21
|
-
|
|
22
|
-
const metadata = {
|
|
23
|
-
host,
|
|
24
|
-
requestId,
|
|
25
|
-
requestReceivedAt,
|
|
26
|
-
query,
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (mutation) {
|
|
30
|
-
metadata.mutation = mutation
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
logger.info(`${operationId}: ${JSON.stringify(metadata, null, 2)}`)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
module.exports = logRequest
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { isObject, cloneDeep } = require('lodash')
|
|
4
|
-
const { isArray } = Array
|
|
5
|
-
|
|
6
|
-
const SECRET_REGEXP = /(password|code|token|authorization|cookie)/i
|
|
7
|
-
|
|
8
|
-
// NOTE: Theoretically this method can be applied to every log entry. This
|
|
9
|
-
// would require refactor of logger interface.
|
|
10
|
-
const maskSecrets = object => {
|
|
11
|
-
for (const key in object) {
|
|
12
|
-
const value = object[key]
|
|
13
|
-
|
|
14
|
-
if (isArray(value)) {
|
|
15
|
-
for (const item of value) {
|
|
16
|
-
maskSecrets(item)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
continue
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (isObject(value)) {
|
|
23
|
-
maskSecrets(value)
|
|
24
|
-
|
|
25
|
-
continue
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const isSecret = SECRET_REGEXP.test(key)
|
|
29
|
-
|
|
30
|
-
if (isSecret) {
|
|
31
|
-
object[key] = '[MASKED]'
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
module.exports = input => {
|
|
37
|
-
const object = cloneDeep(input)
|
|
38
|
-
|
|
39
|
-
maskSecrets(object)
|
|
40
|
-
|
|
41
|
-
return object
|
|
42
|
-
}
|