@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
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Schema } from '@kravc/schema';
|
|
2
|
+
import Context from '../Context';
|
|
3
|
+
/** Component */
|
|
4
|
+
declare class Component<Attributes> {
|
|
5
|
+
protected static _schema?: Schema;
|
|
6
|
+
private _id;
|
|
7
|
+
private _context;
|
|
8
|
+
private _attributes;
|
|
9
|
+
/** Creates an instance of the component with execution context and attributes. */
|
|
10
|
+
constructor(context: Context, attributes: Attributes);
|
|
11
|
+
/** Returns ID key of a component. */
|
|
12
|
+
static get idKey(): string;
|
|
13
|
+
/** Flags if a component class. */
|
|
14
|
+
static get isComponent(): boolean;
|
|
15
|
+
/** Returns component ID. */
|
|
16
|
+
static get id(): string;
|
|
17
|
+
/** Attaches schema to validate component attributes. */
|
|
18
|
+
static set schema(schema: Schema);
|
|
19
|
+
/** Returns schema to validate component attributes. */
|
|
20
|
+
static get schema(): Schema | undefined;
|
|
21
|
+
/** Flag if schema is defined for a component. */
|
|
22
|
+
static get hasSchema(): boolean;
|
|
23
|
+
/** Returns schema for component mutation attributes. */
|
|
24
|
+
static get mutationSchema(): Schema | undefined;
|
|
25
|
+
/** Converts a component name into a human-readable title. */
|
|
26
|
+
static getTitle(isCapitalized?: boolean, isPlural?: boolean): string;
|
|
27
|
+
/** Returns component instance ID. */
|
|
28
|
+
get id(): string | null;
|
|
29
|
+
/** Returns context of the component instance. */
|
|
30
|
+
get context(): Context;
|
|
31
|
+
/** Returns component attributes. */
|
|
32
|
+
get attributes(): Attributes;
|
|
33
|
+
/** Returns name of a component class. */
|
|
34
|
+
get componentId(): string;
|
|
35
|
+
/** Returns normalized component attributes. */
|
|
36
|
+
get json(): any;
|
|
37
|
+
/** Returns component attributes, ready for JSON stringify. */
|
|
38
|
+
toJSON(): Attributes;
|
|
39
|
+
/** Validates component JSON stringified attributes. */
|
|
40
|
+
validate(): any;
|
|
41
|
+
}
|
|
42
|
+
export default Component;
|
|
43
|
+
//# sourceMappingURL=Component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Component.d.ts","sourceRoot":"","sources":["../../src/Component/Component.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,OAA+B,MAAM,YAAY,CAAC;AAIzD,gBAAgB;AAChB,cAAM,SAAS,CAAC,UAAU;IACxB,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAElC,OAAO,CAAC,GAAG,CAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,WAAW,CAAa;IAEhC,kFAAkF;gBACtE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU;IAWpD,qCAAqC;IACrC,MAAM,KAAK,KAAK,IAAI,MAAM,CAEzB;IAED,kCAAkC;IAClC,MAAM,KAAK,WAAW,IAAI,OAAO,CAEhC;IAED,4BAA4B;IAC5B,MAAM,KAAK,EAAE,IAAI,MAAM,CAEtB;IAED,wDAAwD;IACxD,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,EAE/B;IAED,uDAAuD;IACvD,MAAM,KAAK,MAAM,IAAI,MAAM,GAAG,SAAS,CAEtC;IAED,iDAAiD;IACjD,MAAM,KAAK,SAAS,IAAI,OAAO,CAE9B;IAED,wDAAwD;IACxD,MAAM,KAAK,cAAc,IAAI,MAAM,GAAG,SAAS,CAE9C;IAED,6DAA6D;IAC7D,MAAM,CAAC,QAAQ,CAAC,aAAa,GAAE,OAAc,EAAE,QAAQ,GAAE,OAAe,GAAG,MAAM;IAgBjF,qCAAqC;IACrC,IAAI,EAAE,kBAEL;IAED,iDAAiD;IACjD,IAAI,OAAO,YAEV;IAED,oCAAoC;IACpC,IAAI,UAAU,eAEb;IAED,yCAAyC;IACzC,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,+CAA+C;IAC/C,IAAI,IAAI,QAEP;IAED,8DAA8D;IAC9D,MAAM;IAIN,uDAAuD;IACvD,QAAQ;CAMT;AAED,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
7
|
+
const pluralize_1 = __importDefault(require("pluralize"));
|
|
8
|
+
const lodash_2 = require("lodash");
|
|
9
|
+
const Context_1 = require("../Context");
|
|
10
|
+
const DEFAULT_ID_KEY = 'id';
|
|
11
|
+
/** Component */
|
|
12
|
+
class Component {
|
|
13
|
+
static _schema;
|
|
14
|
+
_id;
|
|
15
|
+
_context;
|
|
16
|
+
_attributes;
|
|
17
|
+
/** Creates an instance of the component with execution context and attributes. */
|
|
18
|
+
constructor(context, attributes) {
|
|
19
|
+
const idKey = (0, lodash_1.get)(this.constructor, 'idKey');
|
|
20
|
+
const className = (0, lodash_1.get)(this.constructor, 'name');
|
|
21
|
+
this._id = (0, lodash_1.get)(attributes, idKey, null);
|
|
22
|
+
this._context = context;
|
|
23
|
+
this._attributes = attributes;
|
|
24
|
+
return (0, Context_1.withSafeAttributes)(this, className);
|
|
25
|
+
}
|
|
26
|
+
/** Returns ID key of a component. */
|
|
27
|
+
static get idKey() {
|
|
28
|
+
return DEFAULT_ID_KEY;
|
|
29
|
+
}
|
|
30
|
+
/** Flags if a component class. */
|
|
31
|
+
static get isComponent() {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
/** Returns component ID. */
|
|
35
|
+
static get id() {
|
|
36
|
+
return this.name;
|
|
37
|
+
}
|
|
38
|
+
/** Attaches schema to validate component attributes. */
|
|
39
|
+
static set schema(schema) {
|
|
40
|
+
this._schema = schema.clone(this.id);
|
|
41
|
+
}
|
|
42
|
+
/** Returns schema to validate component attributes. */
|
|
43
|
+
static get schema() {
|
|
44
|
+
return this._schema;
|
|
45
|
+
}
|
|
46
|
+
/** Flag if schema is defined for a component. */
|
|
47
|
+
static get hasSchema() {
|
|
48
|
+
return !!this._schema;
|
|
49
|
+
}
|
|
50
|
+
/** Returns schema for component mutation attributes. */
|
|
51
|
+
static get mutationSchema() {
|
|
52
|
+
return this.schema;
|
|
53
|
+
}
|
|
54
|
+
/** Converts a component name into a human-readable title. */
|
|
55
|
+
static getTitle(isCapitalized = true, isPlural = false) {
|
|
56
|
+
const { name } = this;
|
|
57
|
+
let componentTitle = (0, lodash_2.startCase)(name).toLowerCase();
|
|
58
|
+
if (isPlural) {
|
|
59
|
+
componentTitle = (0, pluralize_1.default)(componentTitle);
|
|
60
|
+
}
|
|
61
|
+
if (isCapitalized) {
|
|
62
|
+
componentTitle = (0, lodash_2.capitalize)(componentTitle);
|
|
63
|
+
}
|
|
64
|
+
return componentTitle;
|
|
65
|
+
}
|
|
66
|
+
;
|
|
67
|
+
/** Returns component instance ID. */
|
|
68
|
+
get id() {
|
|
69
|
+
return this._id;
|
|
70
|
+
}
|
|
71
|
+
/** Returns context of the component instance. */
|
|
72
|
+
get context() {
|
|
73
|
+
return this._context;
|
|
74
|
+
}
|
|
75
|
+
/** Returns component attributes. */
|
|
76
|
+
get attributes() {
|
|
77
|
+
return this._attributes;
|
|
78
|
+
}
|
|
79
|
+
/** Returns name of a component class. */
|
|
80
|
+
get componentId() {
|
|
81
|
+
return (0, lodash_1.get)(this.constructor, 'id');
|
|
82
|
+
}
|
|
83
|
+
/** Returns normalized component attributes. */
|
|
84
|
+
get json() {
|
|
85
|
+
return JSON.parse(JSON.stringify(this));
|
|
86
|
+
}
|
|
87
|
+
/** Returns component attributes, ready for JSON stringify. */
|
|
88
|
+
toJSON() {
|
|
89
|
+
return this.attributes;
|
|
90
|
+
}
|
|
91
|
+
/** Validates component JSON stringified attributes. */
|
|
92
|
+
validate() {
|
|
93
|
+
const shouldNullifyEmptyValues = false;
|
|
94
|
+
const shouldCleanupNulls = true;
|
|
95
|
+
return this._context.validator.validate(this.json, this.componentId, shouldNullifyEmptyValues, shouldCleanupNulls);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.default = Component;
|
|
99
|
+
//# sourceMappingURL=Component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Component.js","sourceRoot":"","sources":["../../src/Component/Component.ts"],"names":[],"mappings":";;;;;AAAA,mCAA6B;AAC7B,0DAAkC;AAElC,mCAA+C;AAC/C,wCAAyD;AAEzD,MAAM,cAAc,GAAG,IAAI,CAAC;AAE5B,gBAAgB;AAChB,MAAM,SAAS;IACH,MAAM,CAAC,OAAO,CAAU;IAE1B,GAAG,CAAgB;IACnB,QAAQ,CAAU;IAClB,WAAW,CAAa;IAEhC,kFAAkF;IAClF,YAAY,OAAgB,EAAE,UAAsB;QAClD,MAAM,KAAK,GAAG,IAAA,YAAG,EAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAE,CAAC;QAC9C,MAAM,SAAS,GAAG,IAAA,YAAG,EAAC,IAAI,CAAC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
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Component = void 0;
|
|
7
|
+
const Component_1 = __importDefault(require("./Component"));
|
|
8
|
+
exports.Component = Component_1.default;
|
|
9
|
+
exports.default = Component_1.default;
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Component/index.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAoC;AAKlC,oBALK,mBAAS,CAKL;AAHX,kBAAe,mBAAS,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { type Cookies } from 'cookie';
|
|
2
|
+
import { inspect } from 'util';
|
|
3
|
+
import { Validator } from '@kravc/schema';
|
|
4
|
+
import { OpenAPIV2 } from 'openapi-types';
|
|
5
|
+
import type { Logger, Headers, Request, QueryMap, MutationMap, ExtraContext } from './Request';
|
|
6
|
+
type Runtime = Record<string, unknown>;
|
|
7
|
+
export type Identity = {
|
|
8
|
+
sub?: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
email?: string;
|
|
11
|
+
lastName?: string;
|
|
12
|
+
firstName?: string;
|
|
13
|
+
[x: string]: unknown;
|
|
14
|
+
};
|
|
15
|
+
export type ContextConfig = {
|
|
16
|
+
spec: OpenAPIV2.Document;
|
|
17
|
+
validator: Validator;
|
|
18
|
+
};
|
|
19
|
+
/** Service request context. */
|
|
20
|
+
declare class Context {
|
|
21
|
+
query: QueryMap;
|
|
22
|
+
logger: Logger;
|
|
23
|
+
headers: Headers;
|
|
24
|
+
cookies?: Cookies;
|
|
25
|
+
httpPath: string;
|
|
26
|
+
bodyJson: string | null;
|
|
27
|
+
mutation: MutationMap | null;
|
|
28
|
+
identity: Identity;
|
|
29
|
+
requestId: string;
|
|
30
|
+
validator: Validator;
|
|
31
|
+
httpMethod: string;
|
|
32
|
+
operationId: string;
|
|
33
|
+
requestReceivedAt: string;
|
|
34
|
+
private _env?;
|
|
35
|
+
private _runtime;
|
|
36
|
+
/** Creates an instance of the context. */
|
|
37
|
+
constructor(config: ContextConfig, request: Request, extraContext: ExtraContext);
|
|
38
|
+
/** Returns true if running in the development environment. */
|
|
39
|
+
get isDevelopment(): boolean;
|
|
40
|
+
/** Returns true if running in the test environment. */
|
|
41
|
+
get isTest(): boolean;
|
|
42
|
+
/** Returns true if running in the live, non test environment. */
|
|
43
|
+
get isLive(): boolean;
|
|
44
|
+
/** Adds variable to the context runtime. */
|
|
45
|
+
set(path: string, value: unknown): void;
|
|
46
|
+
/** Returns variable from the context runtime. */
|
|
47
|
+
get(path: string): unknown | null;
|
|
48
|
+
/** Returns variable from the context runtime if exists, otherwise throws exception. */
|
|
49
|
+
got<T>(path: string): T;
|
|
50
|
+
/** Resets context runtime. */
|
|
51
|
+
runtimeReset(): void;
|
|
52
|
+
/** Returns authenticated identity ID, or SYSTEM if missing. */
|
|
53
|
+
get identityId(): string;
|
|
54
|
+
/** Returns authenticated identity full name if present in claims. */
|
|
55
|
+
get identityName(): string | null;
|
|
56
|
+
/** Serializes context to JSON object. */
|
|
57
|
+
toJSON(): {
|
|
58
|
+
operationId: string;
|
|
59
|
+
httpPath: string;
|
|
60
|
+
httpMethod: string;
|
|
61
|
+
requestId: string;
|
|
62
|
+
requestReceivedAt: string;
|
|
63
|
+
headers: Headers;
|
|
64
|
+
query: QueryMap;
|
|
65
|
+
mutation: MutationMap | null;
|
|
66
|
+
bodyJson: string | null;
|
|
67
|
+
identity: Identity;
|
|
68
|
+
runtime: Runtime;
|
|
69
|
+
};
|
|
70
|
+
/** Serializes context for console.log and util.inspect. */
|
|
71
|
+
[inspect.custom](): {
|
|
72
|
+
operationId: string;
|
|
73
|
+
httpPath: string;
|
|
74
|
+
httpMethod: string;
|
|
75
|
+
requestId: string;
|
|
76
|
+
requestReceivedAt: string;
|
|
77
|
+
headers: Headers;
|
|
78
|
+
query: QueryMap;
|
|
79
|
+
mutation: MutationMap | null;
|
|
80
|
+
bodyJson: string | null;
|
|
81
|
+
identity: Identity;
|
|
82
|
+
runtime: Runtime;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export default Context;
|
|
86
|
+
//# sourceMappingURL=Context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../src/Context/Context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,OAAO,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAG/B,OAAO,EAAO,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAO1C,OAAO,KAAK,EACV,MAAM,EACN,OAAO,EACP,OAAO,EACP,QAAQ,EACR,WAAW,EACX,YAAY,EACb,MAAM,WAAW,CAAC;AAEnB,KAAK,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEvC,MAAM,MAAM,QAAQ,GAAG;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,SAAS,CAAC,QAAQ,CAAC;IACzB,SAAS,EAAE,SAAS,CAAC;CACtB,CAAA;AAQD,+BAA+B;AAC/B,cAAM,OAAO;IACJ,KAAK,EAAE,QAAQ,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAA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
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const cookie_1 = require("cookie");
|
|
7
|
+
const util_1 = require("util");
|
|
8
|
+
const getHttpPath_1 = __importDefault(require("./getHttpPath"));
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
10
|
+
const schema_1 = require("@kravc/schema");
|
|
11
|
+
const getHttpMethod_1 = __importDefault(require("./getHttpMethod"));
|
|
12
|
+
const crypto_1 = require("crypto");
|
|
13
|
+
const getOperationId_1 = __importDefault(require("./getOperationId"));
|
|
14
|
+
const withSafeAttributes_1 = __importDefault(require("./withSafeAttributes"));
|
|
15
|
+
const getQueryParameters_1 = __importDefault(require("./getQueryParameters"));
|
|
16
|
+
const getMutationParameters_1 = __importDefault(require("./getMutationParameters"));
|
|
17
|
+
const SYSTEM = 'SYSTEM';
|
|
18
|
+
const IDENTITY_NAME_CLAIM = 'name';
|
|
19
|
+
const IDENTITY_SUBJECT_CLAIM = 'sub';
|
|
20
|
+
const IDENTITY_LAST_NAME_CLAIM = 'lastName';
|
|
21
|
+
const IDENTITY_FIRST_NAME_CLAIM = 'firstName';
|
|
22
|
+
/** Service request context. */
|
|
23
|
+
class Context {
|
|
24
|
+
query;
|
|
25
|
+
logger;
|
|
26
|
+
headers;
|
|
27
|
+
cookies;
|
|
28
|
+
httpPath;
|
|
29
|
+
bodyJson;
|
|
30
|
+
mutation;
|
|
31
|
+
identity;
|
|
32
|
+
requestId;
|
|
33
|
+
validator;
|
|
34
|
+
httpMethod;
|
|
35
|
+
operationId;
|
|
36
|
+
requestReceivedAt;
|
|
37
|
+
_env;
|
|
38
|
+
_runtime;
|
|
39
|
+
/** Creates an instance of the context. */
|
|
40
|
+
constructor(config, request, extraContext) {
|
|
41
|
+
const { spec, validator } = config;
|
|
42
|
+
const { env = process.env.NODE_APP_INSTANCE, logger = console, ...runtime } = extraContext;
|
|
43
|
+
const headers = {};
|
|
44
|
+
const cookies = {};
|
|
45
|
+
for (const headerName in request.headers) {
|
|
46
|
+
headers[headerName.toLowerCase()] = request.headers[headerName];
|
|
47
|
+
const isCookieHeader = headerName.toLowerCase() === 'cookie';
|
|
48
|
+
if (isCookieHeader) {
|
|
49
|
+
const parsedCookies = (0, cookie_1.parse)(headers.cookie);
|
|
50
|
+
for (const cookieName in parsedCookies) {
|
|
51
|
+
cookies[cookieName.toLowerCase()] = parsedCookies[cookieName];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
this.query = (0, getQueryParameters_1.default)(request);
|
|
56
|
+
this.logger = logger;
|
|
57
|
+
this.headers = headers;
|
|
58
|
+
this.cookies = cookies;
|
|
59
|
+
this.identity = {};
|
|
60
|
+
this.httpPath = (0, getHttpPath_1.default)(spec, request);
|
|
61
|
+
this.validator = validator;
|
|
62
|
+
this.requestId = (0, lodash_1.get)(request, 'requestContext.requestId', (0, crypto_1.randomUUID)());
|
|
63
|
+
this.httpMethod = (0, getHttpMethod_1.default)(spec, request);
|
|
64
|
+
this.operationId = (0, getOperationId_1.default)(spec, request);
|
|
65
|
+
this.requestReceivedAt = new Date().toISOString();
|
|
66
|
+
const { bodyJson, mutation } = (0, getMutationParameters_1.default)(request);
|
|
67
|
+
this.bodyJson = bodyJson;
|
|
68
|
+
this.mutation = mutation;
|
|
69
|
+
this._env = env;
|
|
70
|
+
this._runtime = runtime;
|
|
71
|
+
return (0, withSafeAttributes_1.default)(this, 'Context');
|
|
72
|
+
}
|
|
73
|
+
/** Returns true if running in the development environment. */
|
|
74
|
+
get isDevelopment() {
|
|
75
|
+
return this._env === 'dev' || !this._env;
|
|
76
|
+
}
|
|
77
|
+
/** Returns true if running in the test environment. */
|
|
78
|
+
get isTest() {
|
|
79
|
+
return this._env === 'test';
|
|
80
|
+
}
|
|
81
|
+
/** Returns true if running in the live, non test environment. */
|
|
82
|
+
get isLive() {
|
|
83
|
+
return !this.isTest;
|
|
84
|
+
}
|
|
85
|
+
/** Adds variable to the context runtime. */
|
|
86
|
+
set(path, value) {
|
|
87
|
+
(0, lodash_1.set)(this._runtime, path, value);
|
|
88
|
+
}
|
|
89
|
+
/** Returns variable from the context runtime. */
|
|
90
|
+
get(path) {
|
|
91
|
+
return (0, lodash_1.get)(this._runtime, path, null);
|
|
92
|
+
}
|
|
93
|
+
/** Returns variable from the context runtime if exists, otherwise throws exception. */
|
|
94
|
+
got(path) {
|
|
95
|
+
const runtimeJson = JSON.stringify(this._runtime, null, 2);
|
|
96
|
+
const errorTemplate = `Context runtime is missing "$PATH" value, runtime: ${runtimeJson}`;
|
|
97
|
+
return (0, schema_1.got)(this._runtime, path, errorTemplate);
|
|
98
|
+
}
|
|
99
|
+
/** Resets context runtime. */
|
|
100
|
+
runtimeReset() {
|
|
101
|
+
this._runtime = {};
|
|
102
|
+
}
|
|
103
|
+
/** Returns authenticated identity ID, or SYSTEM if missing. */
|
|
104
|
+
get identityId() {
|
|
105
|
+
return (0, lodash_1.get)(this.identity, IDENTITY_SUBJECT_CLAIM, SYSTEM);
|
|
106
|
+
}
|
|
107
|
+
/** Returns authenticated identity full name if present in claims. */
|
|
108
|
+
get identityName() {
|
|
109
|
+
let name = (0, lodash_1.get)(this.identity, IDENTITY_NAME_CLAIM);
|
|
110
|
+
if (name) {
|
|
111
|
+
return name;
|
|
112
|
+
}
|
|
113
|
+
const lastName = (0, lodash_1.get)(this.identity, IDENTITY_LAST_NAME_CLAIM, '');
|
|
114
|
+
const firstName = (0, lodash_1.get)(this.identity, IDENTITY_FIRST_NAME_CLAIM, '');
|
|
115
|
+
name = [firstName, lastName]
|
|
116
|
+
.map(item => item.trim())
|
|
117
|
+
.join(' ');
|
|
118
|
+
const isEmpty = name === ' ';
|
|
119
|
+
if (!isEmpty) {
|
|
120
|
+
return name;
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
/** Serializes context to JSON object. */
|
|
125
|
+
toJSON() {
|
|
126
|
+
const { _runtime: runtime, query, headers, identity, httpPath, requestId, httpMethod, operationId, requestReceivedAt, bodyJson, mutation, } = this;
|
|
127
|
+
return {
|
|
128
|
+
operationId,
|
|
129
|
+
httpPath,
|
|
130
|
+
httpMethod,
|
|
131
|
+
requestId,
|
|
132
|
+
requestReceivedAt,
|
|
133
|
+
headers,
|
|
134
|
+
query,
|
|
135
|
+
mutation,
|
|
136
|
+
bodyJson,
|
|
137
|
+
identity,
|
|
138
|
+
runtime,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/** Serializes context for console.log and util.inspect. */
|
|
142
|
+
[util_1.inspect.custom]() {
|
|
143
|
+
return this.toJSON();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
;
|
|
147
|
+
exports.default = Context;
|
|
148
|
+
//# sourceMappingURL=Context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Context.js","sourceRoot":"","sources":["../../src/Context/Context.ts"],"names":[],"mappings":";;;;;AAAA,mCAA6C;AAC7C,+BAA+B;AAC/B,gEAAwC;AACxC,mCAAkC;AAClC,0CAA+C;AAE/C,oEAA4C;AAC5C,mCAAoC;AACpC,sEAA8C;AAC9C,8EAAsD;AACtD,8EAAsD;AACtD,oFAA4D;AA0B5D,MAAM,MAAM,GAAG,QAAQ,CAAC;AACxB,MAAM,mBAAmB,GAAG,MAAM,CAAC;AACnC,MAAM,sBAAsB,GAAG,KAAK,CAAC;AACrC,MAAM,wBAAwB,GAAG,UAAU,CAAC;AAC5C,MAAM,yBAAyB,GAAG,WAAW,CAAC;AAE9C,+BAA+B;AAC/B,MAAM,OAAO;IACJ,KAAK,CAAW;IAChB,MAAM,CAAS;IACf,OAAO,CAAU;IACjB,OAAO,CAAW;IAClB,QAAQ,CAAS;IACjB,QAAQ,CAAgB;IACxB,QAAQ,CAAqB;IAC7B,QAAQ,CAAW;IACnB,SAAS,CAAS;IAClB,S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IAAI,CAAC;QACd,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,yCAAyC;IACzC,MAAM;QACJ,MAAM,EACJ,QAAQ,EAAE,OAAO,EACjB,KAAK,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,QAAQ,EACR,QAAQ,GACT,GAAG,IAAI,CAAC;QAET,OAAO;YACL,WAAW;YACX,QAAQ;YACR,UAAU;YACV,SAAS;YACT,iBAAiB;YACjB,OAAO;YACP,KAAK;YACL,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,OAAO;SACR,CAAC;IACJ,CAAC;IAED,2DAA2D;IAC3D,CAAC,cAAO,CAAC,MAAM,CAAC;QACd,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;CACF;AAAA,CAAC;AAEF,kBAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type Logger = {
|
|
2
|
+
dir: (object: Record<string, unknown>, options: Record<string, unknown>) => void;
|
|
3
|
+
info: (message: string, object?: unknown) => void;
|
|
4
|
+
error: (message: string) => void;
|
|
5
|
+
};
|
|
6
|
+
export type ExtraContext = {
|
|
7
|
+
env?: string;
|
|
8
|
+
logger?: Logger;
|
|
9
|
+
[index: string]: unknown;
|
|
10
|
+
};
|
|
11
|
+
export type Headers = {
|
|
12
|
+
cookie?: string;
|
|
13
|
+
[x: string]: unknown;
|
|
14
|
+
};
|
|
15
|
+
export type QueryMap = Record<string, unknown>;
|
|
16
|
+
export type MutationMap = Record<string, unknown>;
|
|
17
|
+
export type LambdaRequest = {
|
|
18
|
+
body?: string | MutationMap;
|
|
19
|
+
headers?: Headers;
|
|
20
|
+
operationId: string;
|
|
21
|
+
queryStringParameters?: QueryMap;
|
|
22
|
+
};
|
|
23
|
+
export type HttpRequest = {
|
|
24
|
+
url: string;
|
|
25
|
+
path?: string;
|
|
26
|
+
body?: string;
|
|
27
|
+
method?: string;
|
|
28
|
+
headers: Headers;
|
|
29
|
+
httpMethod?: string;
|
|
30
|
+
requestContext?: {
|
|
31
|
+
requestId?: string;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export type Request = HttpRequest | LambdaRequest;
|
|
35
|
+
//# sourceMappingURL=Request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Request.d.ts","sourceRoot":"","sources":["../../src/Context/Request.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,MAAM,GAAG;IACnB,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IACjF,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAClD,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B,CAAA;AAED,MAAM,MAAM,OAAO,GAAG;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC/C,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAElD,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,qBAAqB,CAAC,EAAE,QAAQ,CAAC;CAClC,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE;QACf,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG,WAAW,GAAG,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Request.js","sourceRoot":"","sources":["../../src/Context/Request.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Schema } from '@kravc/schema';
|
|
2
|
+
import { Context, type Identity } from '../../';
|
|
3
|
+
import type { Request, ExtraContext } from '../Request';
|
|
4
|
+
export declare const profileSchema: Schema;
|
|
5
|
+
type Props = {
|
|
6
|
+
request?: Request;
|
|
7
|
+
schemas?: Schema[];
|
|
8
|
+
identity?: Identity;
|
|
9
|
+
extraContext?: ExtraContext;
|
|
10
|
+
};
|
|
11
|
+
/** Creates an instace of an operation context. */
|
|
12
|
+
export declare const createContext: (props?: Props) => Context;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=__helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"__helpers.d.ts","sourceRoot":"","sources":["../../../src/Context/__tests__/__helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAa,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAiB,YAAY,EAAE,MAAM,YAAY,CAAC;AASvE,eAAO,MAAM,aAAa,QAGb,CAAC;AAEd,KAAK,KAAK,GAAG;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,CAAC;AAEF,kDAAkD;AAClD,eAAO,MAAM,aAAa,GAAI,QAAO,KAAU,KAAG,OA4DjD,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createContext = exports.profileSchema = void 0;
|
|
4
|
+
const schema_1 = require("@kravc/schema");
|
|
5
|
+
const __1 = require("../../");
|
|
6
|
+
const operationId = 'TestOperationId';
|
|
7
|
+
const DEFAULT_LAMBDA_REQUEST = {
|
|
8
|
+
headers: {},
|
|
9
|
+
operationId,
|
|
10
|
+
};
|
|
11
|
+
exports.profileSchema = new schema_1.Schema({
|
|
12
|
+
id: {},
|
|
13
|
+
name: { required: true },
|
|
14
|
+
}, 'Profile');
|
|
15
|
+
/** Creates an instace of an operation context. */
|
|
16
|
+
const createContext = (props = {}) => {
|
|
17
|
+
const { request = DEFAULT_LAMBDA_REQUEST, schemas = [exports.profileSchema], identity = {}, extraContext = {}, } = props;
|
|
18
|
+
const validator = new schema_1.Validator(schemas);
|
|
19
|
+
const spec = {
|
|
20
|
+
basePath: '/api',
|
|
21
|
+
paths: {
|
|
22
|
+
[`/${operationId}`]: {
|
|
23
|
+
get: {
|
|
24
|
+
operationId,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
['/CreateProfile']: {
|
|
28
|
+
post: {
|
|
29
|
+
operationId: 'CreateProfile',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
['/UpdateProfile']: {
|
|
33
|
+
post: {
|
|
34
|
+
operationId: 'UpdateProfile',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
['/DeleteProfile']: {
|
|
38
|
+
delete: {
|
|
39
|
+
operationId: 'DeleteProfile',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
['/ReadProfile']: {
|
|
43
|
+
get: {
|
|
44
|
+
operationId: 'ReadProfile',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
['/IndexProfiles']: {
|
|
48
|
+
get: {
|
|
49
|
+
operationId: 'IndexProfiles',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
['/ListProfiles']: {
|
|
53
|
+
get: {
|
|
54
|
+
operationId: 'ListProfiles',
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
['/Health']: {
|
|
58
|
+
get: {
|
|
59
|
+
operationId: 'Health',
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const context = new __1.Context({ spec, validator }, request, extraContext);
|
|
65
|
+
context.identity = identity;
|
|
66
|
+
return context;
|
|
67
|
+
};
|
|
68
|
+
exports.createContext = createContext;
|
|
69
|
+
//# sourceMappingURL=__helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"__helpers.js","sourceRoot":"","sources":["../../../src/Context/__tests__/__helpers.ts"],"names":[],"mappings":";;;AACA,0CAAkD;AAClD,8BAAgD;AAGhD,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAEtC,MAAM,sBAAsB,GAAG;IAC7B,OAAO,EAAE,EAAE;IACX,WAAW;CACK,CAAC;AAEN,QAAA,aAAa,GAAG,IAAI,eAAM,CAAC;IACtC,EAAE,EAAE,EAAE;IACN,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;CACzB,EAAE,SAAS,CAAC,CAAC;AASd,kDAAkD;AAC3C,MAAM,aAAa,GAAG,CAAC,QAAe,EAAE,EAAW,EAAE;IAC1D,MAAM,EACJ,OAAO,GAAG,sBAAsB,EAChC,OAAO,GAAG,CAAE,qBAAa,CA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Request';
|
|
3
|
+
/** Returns HTTP method of a request. */
|
|
4
|
+
declare const getHttpMethod: (spec: OpenAPIV2.Document, request: Request) => string;
|
|
5
|
+
export default getHttpMethod;
|
|
6
|
+
//# sourceMappingURL=getHttpMethod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getHttpMethod.d.ts","sourceRoot":"","sources":["../../src/Context/getHttpMethod.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAE,OAAO,EAA8B,MAAM,WAAW,CAAC;AAErE,wCAAwC;AACxC,QAAA,MAAM,aAAa,GAAI,MAAM,SAAS,CAAC,QAAQ,EAAE,SAAS,OAAO,KAAG,MAanE,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const schema_1 = require("@kravc/schema");
|
|
4
|
+
/** Returns HTTP method of a request. */
|
|
5
|
+
const getHttpMethod = (spec, request) => {
|
|
6
|
+
const { operationId } = request;
|
|
7
|
+
if (operationId) {
|
|
8
|
+
const methods = Object.keys((0, schema_1.got)(spec.paths, `/${operationId}`));
|
|
9
|
+
const method = methods[0];
|
|
10
|
+
return method;
|
|
11
|
+
}
|
|
12
|
+
const { method, httpMethod } = request;
|
|
13
|
+
return (method || httpMethod).toLowerCase();
|
|
14
|
+
};
|
|
15
|
+
exports.default = getHttpMethod;
|
|
16
|
+
//# sourceMappingURL=getHttpMethod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getHttpMethod.js","sourceRoot":"","sources":["../../src/Context/getHttpMethod.ts"],"names":[],"mappings":";;AAAA,0CAAoC;AAIpC,wCAAwC;AACxC,MAAM,aAAa,GAAG,CAAC,IAAwB,EAAE,OAAgB,EAAU,EAAE;IAC3E,MAAM,EAAE,WAAW,EAAE,GAAG,OAAwB,CAAC;IAEjD,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAA,YAAG,EAAC,IAAI,CAAC,KAAK,EAAE,IAAI,WAAW,EAAE,CAA0B,CAAC,CAAC;QACzF,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAW,CAAC;QAEpC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,OAAsB,CAAC;IAEtD,OAAO,CAAC,MAAM,IAAI,UAAW,CAAC,CAAC,WAAW,EAAE,CAAC;AAC/C,CAAC,CAAC;AAEF,kBAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { OpenAPIV2 } from 'openapi-types';
|
|
2
|
+
import type { Request } from './Request';
|
|
3
|
+
/** Returns HTTP path of a request. */
|
|
4
|
+
declare const getHttpPath: (spec: OpenAPIV2.Document, request: Request) => string;
|
|
5
|
+
export default getHttpPath;
|
|
6
|
+
//# sourceMappingURL=getHttpPath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getHttpPath.d.ts","sourceRoot":"","sources":["../../src/Context/getHttpPath.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAE,OAAO,EAA8B,MAAM,WAAW,CAAC;AAIrE,sCAAsC;AACtC,QAAA,MAAM,WAAW,GAAI,MAAM,SAAS,CAAC,QAAQ,EAAE,SAAS,OAAO,KAAG,MAwBjE,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const lodash_1 = require("lodash");
|
|
4
|
+
const BASE_URL = 'http://localhost:3000';
|
|
5
|
+
/** Returns HTTP path of a request. */
|
|
6
|
+
const getHttpPath = (spec, request) => {
|
|
7
|
+
const { basePath } = spec;
|
|
8
|
+
const { operationId } = request;
|
|
9
|
+
if (operationId) {
|
|
10
|
+
return `/${operationId}`;
|
|
11
|
+
}
|
|
12
|
+
const httpRequest = request;
|
|
13
|
+
let { path } = httpRequest;
|
|
14
|
+
if (!path) {
|
|
15
|
+
const { url } = httpRequest;
|
|
16
|
+
const _url = new URL(url, BASE_URL);
|
|
17
|
+
path = (0, lodash_1.get)(_url, 'pathname', '/');
|
|
18
|
+
}
|
|
19
|
+
const httpPath = path
|
|
20
|
+
.replace(basePath, '/')
|
|
21
|
+
.replace('//', '/');
|
|
22
|
+
return httpPath;
|
|
23
|
+
};
|
|
24
|
+
exports.default = getHttpPath;
|
|
25
|
+
//# sourceMappingURL=getHttpPath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getHttpPath.js","sourceRoot":"","sources":["../../src/Context/getHttpPath.ts"],"names":[],"mappings":";;AAAA,mCAA6B;AAI7B,MAAM,QAAQ,GAAG,uBAAuB,CAAC;AAEzC,sCAAsC;AACtC,MAAM,WAAW,GAAG,CAAC,IAAwB,EAAE,OAAgB,EAAU,EAAE;IACzE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IAC1B,MAAM,EAAE,WAAW,EAAE,GAAG,OAAwB,CAAC;IAEjD,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,IAAI,WAAW,EAAE,CAAC;IAC3B,CAAC;IAED,MAAM,WAAW,GAAG,OAAsB,CAAC;IAE3C,IAAI,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC;IAE3B,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,EAAE,GAAG,EAAE,GAAG,WAAW,CAAC;QAC5B,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QAEpC,IAAI,GAAG,IAAA,YAAG,EAAC,IAAI,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,QAAQ,GAAG,IAAI;SAClB,OAAO,CAAC,QAAS,EAAE,GAAG,CAAC;SACvB,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAEtB,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAEF,kBAAe,WAAW,CAAC"}
|