@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,271 @@
|
|
|
1
|
+
import { get } from 'lodash';
|
|
2
|
+
import { randomUUID } from 'crypto';
|
|
3
|
+
import { createContext } from './__helpers';
|
|
4
|
+
import type { LambdaRequest, HttpRequest } from '../Request';
|
|
5
|
+
|
|
6
|
+
describe('Context', () => {
|
|
7
|
+
describe('Context.constructor(config, request, extraContext)', () => {
|
|
8
|
+
const operationId = 'TestOperationId';
|
|
9
|
+
|
|
10
|
+
it('should create instance for lambda request', () => {
|
|
11
|
+
const context = createContext();
|
|
12
|
+
|
|
13
|
+
expect(context.query).toEqual({});
|
|
14
|
+
expect(context.logger).toBe(console);
|
|
15
|
+
expect(context.headers).toEqual({});
|
|
16
|
+
expect(context.httpPath).toEqual(`/${operationId}`);
|
|
17
|
+
expect(context.bodyJson).toBeNull();
|
|
18
|
+
expect(context.mutation).toBeNull();
|
|
19
|
+
expect(context.identity).toEqual({});
|
|
20
|
+
expect(context.requestId).toBeDefined();
|
|
21
|
+
expect(context.validator).toBeDefined();
|
|
22
|
+
expect(context.httpMethod).toEqual('get');
|
|
23
|
+
expect(context.operationId).toBe(operationId);
|
|
24
|
+
expect(context.requestReceivedAt).toBeDefined();
|
|
25
|
+
|
|
26
|
+
expect(() => get(context, 'undefinedAttribute'))
|
|
27
|
+
.toThrow('"undefinedAttribute" property or method is undefined for Context instance');
|
|
28
|
+
|
|
29
|
+
expect(get(context, 'then')).toBeUndefined();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should create instance for lambda request with body JSON', () => {
|
|
33
|
+
const request = {
|
|
34
|
+
body: JSON.stringify({ status: 'ok' }),
|
|
35
|
+
headers: {},
|
|
36
|
+
operationId,
|
|
37
|
+
} as LambdaRequest;
|
|
38
|
+
|
|
39
|
+
const context = createContext({ request });
|
|
40
|
+
|
|
41
|
+
expect(context.query).toEqual({});
|
|
42
|
+
expect(context.bodyJson).toEqual(JSON.stringify({ status: 'ok' }));
|
|
43
|
+
expect(context.mutation).toEqual({ status: 'ok' });
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should create instance for lambda request with body object and query string parameters', () => {
|
|
47
|
+
const request = {
|
|
48
|
+
body: { status: 'ok' },
|
|
49
|
+
headers: {},
|
|
50
|
+
operationId,
|
|
51
|
+
queryStringParameters: { id: 'ID' },
|
|
52
|
+
} as LambdaRequest;
|
|
53
|
+
|
|
54
|
+
const context = createContext({ request });
|
|
55
|
+
|
|
56
|
+
expect(context.query).toEqual({ id: 'ID' });
|
|
57
|
+
expect(context.bodyJson).toEqual(JSON.stringify({ status: 'ok' }));
|
|
58
|
+
expect(context.mutation).toEqual({ status: 'ok' });
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should create instance for HTTP request', () => {
|
|
62
|
+
const uuid = randomUUID();
|
|
63
|
+
const items = ['a', 'b', 'c'];
|
|
64
|
+
const itemsJson = JSON.stringify(items);
|
|
65
|
+
|
|
66
|
+
const request = {
|
|
67
|
+
url: `http://localhost/api/${operationId}?id=ID&items=${itemsJson}`,
|
|
68
|
+
path: `/api/${operationId}`,
|
|
69
|
+
method: 'get',
|
|
70
|
+
headers: { Accept: 'application/json' },
|
|
71
|
+
requestContext: {
|
|
72
|
+
requestId: uuid,
|
|
73
|
+
},
|
|
74
|
+
} as HttpRequest;
|
|
75
|
+
|
|
76
|
+
const context = createContext({ request });
|
|
77
|
+
|
|
78
|
+
expect(context.query).toEqual({ id: 'ID', items });
|
|
79
|
+
expect(context.logger).toBe(console);
|
|
80
|
+
expect(context.headers).toEqual({ accept: 'application/json' });
|
|
81
|
+
expect(context.httpPath).toEqual(`/${operationId}`);
|
|
82
|
+
expect(context.bodyJson).toBeNull();
|
|
83
|
+
expect(context.mutation).toBeNull();
|
|
84
|
+
expect(context.identity).toEqual({});
|
|
85
|
+
expect(context.requestId).toEqual(uuid);
|
|
86
|
+
expect(context.validator).toBeDefined();
|
|
87
|
+
expect(context.httpMethod).toEqual('get');
|
|
88
|
+
expect(context.operationId).toBe(operationId);
|
|
89
|
+
expect(context.requestReceivedAt).toBeDefined();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should create instance for HTTP request with httpMethod and without path', () => {
|
|
93
|
+
const uuid = randomUUID();
|
|
94
|
+
|
|
95
|
+
const request = {
|
|
96
|
+
url: `http://localhost/api/${operationId}?id=ID`,
|
|
97
|
+
headers: { Accept: 'application/json' },
|
|
98
|
+
httpMethod: 'get',
|
|
99
|
+
requestContext: {
|
|
100
|
+
requestId: uuid,
|
|
101
|
+
},
|
|
102
|
+
} as HttpRequest;
|
|
103
|
+
|
|
104
|
+
const context = createContext({ request });
|
|
105
|
+
|
|
106
|
+
expect(context.httpPath).toEqual(`/${operationId}`);
|
|
107
|
+
expect(context.httpMethod).toEqual('get');
|
|
108
|
+
expect(context.operationId).toBe(operationId);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('should create instance for local HTTP request', () => {
|
|
112
|
+
const uuid = randomUUID();
|
|
113
|
+
|
|
114
|
+
const request = {
|
|
115
|
+
url: `/${operationId}?id=ID`,
|
|
116
|
+
headers: { Accept: 'application/json' },
|
|
117
|
+
httpMethod: 'get',
|
|
118
|
+
requestContext: {
|
|
119
|
+
requestId: uuid,
|
|
120
|
+
},
|
|
121
|
+
} as HttpRequest;
|
|
122
|
+
|
|
123
|
+
const context = createContext({ request });
|
|
124
|
+
|
|
125
|
+
expect(context.httpPath).toEqual(`/${operationId}`);
|
|
126
|
+
expect(context.httpMethod).toEqual('get');
|
|
127
|
+
expect(context.operationId).toBe(operationId);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe('.set(name, value)', () => {
|
|
132
|
+
it('add value to the context runtime', () => {
|
|
133
|
+
const context = createContext();
|
|
134
|
+
context.set('example', 'test');
|
|
135
|
+
|
|
136
|
+
expect(context.get('example')).toEqual('test');
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
describe('.get(name)', () => {
|
|
141
|
+
it('returns value if variable is set', () => {
|
|
142
|
+
const context = createContext();
|
|
143
|
+
context.set('example', 'test');
|
|
144
|
+
|
|
145
|
+
expect(context.get('example')).toEqual('test');
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('returns null value if variable is not set', () => {
|
|
149
|
+
const context = createContext();
|
|
150
|
+
|
|
151
|
+
expect(context.get('example')).toBeNull();
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe('.got(name)', () => {
|
|
156
|
+
it('returns value if variable is set', () => {
|
|
157
|
+
const context = createContext();
|
|
158
|
+
context.set('example', 'test');
|
|
159
|
+
|
|
160
|
+
expect(context.got('example')).toEqual('test');
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('throws exception if variable is not set', () => {
|
|
164
|
+
const context = createContext();
|
|
165
|
+
|
|
166
|
+
expect(() => context.got('example'))
|
|
167
|
+
.toThrow('Context runtime is missing "example" value, runtime: {}');
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
describe('.runtimeReset(name)', () => {
|
|
172
|
+
it('resets context runtime', () => {
|
|
173
|
+
const context = createContext();
|
|
174
|
+
context.set('example', 'test');
|
|
175
|
+
|
|
176
|
+
expect(context.get('example')).toEqual('test');
|
|
177
|
+
|
|
178
|
+
context.runtimeReset();
|
|
179
|
+
|
|
180
|
+
expect(context.get('example')).toBeNull();
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe('.identityId', () => {
|
|
185
|
+
it('returns users ID from context identity', () => {
|
|
186
|
+
const identity = { sub: 'TEST_USER_ID' };
|
|
187
|
+
const context = createContext({ identity });
|
|
188
|
+
|
|
189
|
+
expect(context.identityId).toEqual('TEST_USER_ID');
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('returns SYSTEM if context has no identity', () => {
|
|
193
|
+
const context = createContext();
|
|
194
|
+
|
|
195
|
+
expect(context.identityId).toEqual('SYSTEM');
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('returns SYSTEM if context identity has no subject claim', () => {
|
|
199
|
+
const identity = {};
|
|
200
|
+
const context = createContext({ identity });
|
|
201
|
+
|
|
202
|
+
expect(context.identityId).toEqual('SYSTEM');
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
describe('.identityName', () => {
|
|
207
|
+
it('returns users name from context identity name claim', () => {
|
|
208
|
+
const identity = { name: 'John Doe' };
|
|
209
|
+
const context = createContext({ identity });
|
|
210
|
+
|
|
211
|
+
expect(context.identityName).toEqual('John Doe');
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('returns users name from context identity first and last name claims', () => {
|
|
215
|
+
const identity = { firstName: 'John', lastName: 'Doe' };
|
|
216
|
+
const context = createContext({ identity });
|
|
217
|
+
|
|
218
|
+
expect(context.identityName).toEqual('John Doe');
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('returns null if context has no identity', () => {
|
|
222
|
+
const context = createContext();
|
|
223
|
+
|
|
224
|
+
expect(context.identityName).toBeNull();
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('returns null if context identity has no name related claims', () => {
|
|
228
|
+
const identity = {};
|
|
229
|
+
const context = createContext({ identity });
|
|
230
|
+
|
|
231
|
+
expect(context.identityName).toBeNull();
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
describe('.toJSON()', () => {
|
|
236
|
+
it('returns JSON serializable object', () => {
|
|
237
|
+
const identity = { name: 'John Doe' };
|
|
238
|
+
const context = createContext({ identity });
|
|
239
|
+
|
|
240
|
+
expect(context.toJSON()).toEqual({
|
|
241
|
+
bodyJson: null,
|
|
242
|
+
headers: {},
|
|
243
|
+
httpMethod: 'get',
|
|
244
|
+
httpPath: '/TestOperationId',
|
|
245
|
+
identity: {
|
|
246
|
+
name: 'John Doe',
|
|
247
|
+
},
|
|
248
|
+
mutation: null,
|
|
249
|
+
operationId: 'TestOperationId',
|
|
250
|
+
query: {},
|
|
251
|
+
requestId: context.requestId,
|
|
252
|
+
requestReceivedAt: context.requestReceivedAt,
|
|
253
|
+
runtime: {},
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
describe('.[inspect.custom]()', () => {
|
|
259
|
+
it('returns object serializable for logging', () => {
|
|
260
|
+
const context = createContext();
|
|
261
|
+
console.log(context);
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
describe('.isLive', () => {
|
|
266
|
+
it('flags if running in non test environment', () => {
|
|
267
|
+
const context = createContext();
|
|
268
|
+
expect(context.isLive).toEqual(true);
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { OpenAPIV2 } from 'openapi-types';
|
|
2
|
+
import { Schema, Validator } from '@kravc/schema';
|
|
3
|
+
import { Context, type Identity } from '../../';
|
|
4
|
+
import type { Request, LambdaRequest, ExtraContext } from '../Request';
|
|
5
|
+
|
|
6
|
+
const operationId = 'TestOperationId';
|
|
7
|
+
|
|
8
|
+
const DEFAULT_LAMBDA_REQUEST = {
|
|
9
|
+
headers: {},
|
|
10
|
+
operationId,
|
|
11
|
+
} as LambdaRequest;
|
|
12
|
+
|
|
13
|
+
export const profileSchema = new Schema({
|
|
14
|
+
id: {},
|
|
15
|
+
name: { required: true },
|
|
16
|
+
}, 'Profile');
|
|
17
|
+
|
|
18
|
+
type Props = {
|
|
19
|
+
request?: Request;
|
|
20
|
+
schemas?: Schema[];
|
|
21
|
+
identity?: Identity;
|
|
22
|
+
extraContext?: ExtraContext;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** Creates an instace of an operation context. */
|
|
26
|
+
export const createContext = (props: Props = {}): Context => {
|
|
27
|
+
const {
|
|
28
|
+
request = DEFAULT_LAMBDA_REQUEST,
|
|
29
|
+
schemas = [ profileSchema ],
|
|
30
|
+
identity = {},
|
|
31
|
+
extraContext = {},
|
|
32
|
+
} = props;
|
|
33
|
+
|
|
34
|
+
const validator = new Validator(schemas);
|
|
35
|
+
|
|
36
|
+
const spec = {
|
|
37
|
+
basePath: '/api',
|
|
38
|
+
paths: {
|
|
39
|
+
[`/${operationId}`]: {
|
|
40
|
+
get: {
|
|
41
|
+
operationId,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
['/CreateProfile']: {
|
|
45
|
+
post: {
|
|
46
|
+
operationId: 'CreateProfile',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
['/UpdateProfile']: {
|
|
50
|
+
post: {
|
|
51
|
+
operationId: 'UpdateProfile',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
['/DeleteProfile']: {
|
|
55
|
+
delete: {
|
|
56
|
+
operationId: 'DeleteProfile',
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
['/ReadProfile']: {
|
|
60
|
+
get: {
|
|
61
|
+
operationId: 'ReadProfile',
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
['/IndexProfiles']: {
|
|
65
|
+
get: {
|
|
66
|
+
operationId: 'IndexProfiles',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
['/ListProfiles']: {
|
|
70
|
+
get: {
|
|
71
|
+
operationId: 'ListProfiles',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
['/Health']: {
|
|
75
|
+
get: {
|
|
76
|
+
operationId: 'Health',
|
|
77
|
+
},
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
} as unknown as OpenAPIV2.Document;
|
|
81
|
+
|
|
82
|
+
const context = new Context({ spec, validator }, request, extraContext);
|
|
83
|
+
context.identity = identity;
|
|
84
|
+
|
|
85
|
+
return context;
|
|
86
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { got } from '@kravc/schema';
|
|
2
|
+
import { OpenAPIV2 } from 'openapi-types';
|
|
3
|
+
import type { Request, LambdaRequest, HttpRequest } from './Request';
|
|
4
|
+
|
|
5
|
+
/** Returns HTTP method of a request. */
|
|
6
|
+
const getHttpMethod = (spec: OpenAPIV2.Document, request: Request): string => {
|
|
7
|
+
const { operationId } = request as LambdaRequest;
|
|
8
|
+
|
|
9
|
+
if (operationId) {
|
|
10
|
+
const methods = Object.keys(got(spec.paths, `/${operationId}`) as OpenAPIV2.PathsObject);
|
|
11
|
+
const method = methods[0] as string;
|
|
12
|
+
|
|
13
|
+
return method;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const { method, httpMethod } = request as HttpRequest;
|
|
17
|
+
|
|
18
|
+
return (method || httpMethod!).toLowerCase();
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default getHttpMethod;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { get } from 'lodash';
|
|
2
|
+
import { OpenAPIV2 } from 'openapi-types';
|
|
3
|
+
import type { Request, LambdaRequest, HttpRequest } from './Request';
|
|
4
|
+
|
|
5
|
+
const BASE_URL = 'http://localhost:3000';
|
|
6
|
+
|
|
7
|
+
/** Returns HTTP path of a request. */
|
|
8
|
+
const getHttpPath = (spec: OpenAPIV2.Document, request: Request): string => {
|
|
9
|
+
const { basePath } = spec;
|
|
10
|
+
const { operationId } = request as LambdaRequest;
|
|
11
|
+
|
|
12
|
+
if (operationId) {
|
|
13
|
+
return `/${operationId}`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const httpRequest = request as HttpRequest;
|
|
17
|
+
|
|
18
|
+
let { path } = httpRequest;
|
|
19
|
+
|
|
20
|
+
if (!path) {
|
|
21
|
+
const { url } = httpRequest;
|
|
22
|
+
const _url = new URL(url, BASE_URL);
|
|
23
|
+
|
|
24
|
+
path = get(_url, 'pathname', '/');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const httpPath = path
|
|
28
|
+
.replace(basePath!, '/')
|
|
29
|
+
.replace('//', '/');
|
|
30
|
+
|
|
31
|
+
return httpPath;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default getHttpPath;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isString } from 'lodash';
|
|
2
|
+
import type { MutationMap, Request } from './Request';
|
|
3
|
+
|
|
4
|
+
/** Returns mutation parameters of a request. */
|
|
5
|
+
const getMutationParameters = (request: Request) => {
|
|
6
|
+
const result = {
|
|
7
|
+
bodyJson: null,
|
|
8
|
+
mutation: null,
|
|
9
|
+
} as {
|
|
10
|
+
bodyJson: string | null;
|
|
11
|
+
mutation: MutationMap | null;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const { body } = request;
|
|
15
|
+
|
|
16
|
+
if (!body) {
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const isJSON = isString(body);
|
|
21
|
+
|
|
22
|
+
if (isJSON) {
|
|
23
|
+
result.bodyJson = body;
|
|
24
|
+
result.mutation = JSON.parse(body);
|
|
25
|
+
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
result.bodyJson = JSON.stringify(body);
|
|
30
|
+
result.mutation = body;
|
|
31
|
+
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default getMutationParameters;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { get } from 'lodash';
|
|
2
|
+
import getHttpPath from './getHttpPath';
|
|
3
|
+
import getHttpMethod from './getHttpMethod';
|
|
4
|
+
import { OpenAPIV2 } from 'openapi-types';
|
|
5
|
+
import type { Request, LambdaRequest } from './Request';
|
|
6
|
+
|
|
7
|
+
const UNDEFINED_VALUE = 'undefined';
|
|
8
|
+
|
|
9
|
+
/** Returns operation ID for a request. */
|
|
10
|
+
const getOperationId = (spec: OpenAPIV2.Document, request: Request): string => {
|
|
11
|
+
const { operationId } = request as LambdaRequest;
|
|
12
|
+
|
|
13
|
+
if (operationId) {
|
|
14
|
+
return operationId;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const httpPath = getHttpPath(spec, request);
|
|
18
|
+
const httpMethod = getHttpMethod(spec, request);
|
|
19
|
+
|
|
20
|
+
return get(spec.paths, `${httpPath}.${httpMethod}.operationId`, UNDEFINED_VALUE) as string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default getOperationId;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { get } from 'lodash';
|
|
2
|
+
import type { QueryMap, Request } from './Request';
|
|
3
|
+
|
|
4
|
+
const BASE_URL = 'http://localhost:3000';
|
|
5
|
+
|
|
6
|
+
/** Returns query parameters of a request. */
|
|
7
|
+
const getQueryParameters = (request: Request): QueryMap => {
|
|
8
|
+
let parameters = {} as QueryMap;
|
|
9
|
+
|
|
10
|
+
const url = get(request, 'url');
|
|
11
|
+
|
|
12
|
+
if (url) {
|
|
13
|
+
const { searchParams } = new URL(url, BASE_URL);
|
|
14
|
+
parameters = Object.fromEntries(searchParams);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const queryStringParameters = get(request, 'queryStringParameters');
|
|
18
|
+
|
|
19
|
+
if (queryStringParameters) {
|
|
20
|
+
const keys = Object.keys(queryStringParameters);
|
|
21
|
+
|
|
22
|
+
for (const key of keys) {
|
|
23
|
+
const value = queryStringParameters[key] as string;
|
|
24
|
+
queryStringParameters[key] = decodeURIComponent(value);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
parameters = queryStringParameters;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const queryKeys = Object.keys(parameters);
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
for (const queryKey of queryKeys) {
|
|
34
|
+
const value = parameters[queryKey] as string;
|
|
35
|
+
const isArrayOfStrings = `${value}`.startsWith('["');
|
|
36
|
+
|
|
37
|
+
if (isArrayOfStrings) {
|
|
38
|
+
parameters[queryKey] = JSON.parse(`${value}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return parameters;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default getQueryParameters;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { got } from '@kravc/schema';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns instance of an object with safe attributes.
|
|
5
|
+
*
|
|
6
|
+
* ## Intent
|
|
7
|
+
*
|
|
8
|
+
* Wraps an object instance in a Proxy that enforces safe attribute access. This function ensures that:
|
|
9
|
+
* - Properties and methods must exist on the instance before they can be accessed
|
|
10
|
+
* - Clear, descriptive errors are thrown when accessing undefined properties/methods
|
|
11
|
+
* - The object cannot be accidentally treated as a Promise (by returning `undefined` for `then`)
|
|
12
|
+
*
|
|
13
|
+
* This is particularly useful for component classes where you want to catch typos and undefined
|
|
14
|
+
* property access early with helpful error messages that include the class name.
|
|
15
|
+
*
|
|
16
|
+
* ## Use Cases
|
|
17
|
+
*
|
|
18
|
+
* 1. **Component Safety**: Wrap component instances to ensure all property/method accesses are valid
|
|
19
|
+
* 2. **Early Error Detection**: Catch typos and undefined accesses at runtime with clear error messages
|
|
20
|
+
* 3. **Promise Prevention**: Prevent objects from being accidentally treated as Promises in async contexts
|
|
21
|
+
* 4. **Type Safety**: Provide runtime validation complementing TypeScript's compile-time checks
|
|
22
|
+
*/
|
|
23
|
+
function withSafeAttributes<T>(targetInstance: T, className: string): T {
|
|
24
|
+
return new Proxy(targetInstance as object, {
|
|
25
|
+
/** Ensures attribute is defined as property or method of the instance. */
|
|
26
|
+
get(target: Record<string, unknown>, prop: string) {
|
|
27
|
+
const shouldSkip = ['then'].includes(prop);
|
|
28
|
+
|
|
29
|
+
if (shouldSkip) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const errorTemplate = `"$PATH" property or method is undefined for ${className} instance`;
|
|
34
|
+
return got(target, prop, errorTemplate);
|
|
35
|
+
}
|
|
36
|
+
}) as T;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default withSafeAttributes;
|