@bitblit/ratchet-epsilon-common 4.0.85-alpha
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/CHANGELOG.md +177 -0
- package/License.txt +13 -0
- package/README.md +242 -0
- package/dist/cjs/background/background-dynamo-log-table-handler.js +38 -0
- package/dist/cjs/background/background-entry.js +2 -0
- package/dist/cjs/background/background-execution-event-type.js +11 -0
- package/dist/cjs/background/background-execution-event.js +2 -0
- package/dist/cjs/background/background-execution-listener.js +2 -0
- package/dist/cjs/background/background-handler.js +269 -0
- package/dist/cjs/background/background-http-adapter-handler.js +127 -0
- package/dist/cjs/background/background-meta-response-internal.js +2 -0
- package/dist/cjs/background/background-process-handling.js +8 -0
- package/dist/cjs/background/background-process-log-table-entry.js +2 -0
- package/dist/cjs/background/background-queue-response-internal.js +2 -0
- package/dist/cjs/background/background-validator.js +88 -0
- package/dist/cjs/background/epsilon-background-process-error.js +93 -0
- package/dist/cjs/background/internal-background-entry.js +2 -0
- package/dist/cjs/background/manager/abstract-background-manager.js +92 -0
- package/dist/cjs/background/manager/aws-sqs-sns-background-manager.js +153 -0
- package/dist/cjs/background/manager/background-manager-like.js +2 -0
- package/dist/cjs/background/manager/single-thread-local-background-manager.js +49 -0
- package/dist/cjs/background/s3-background-transaction-logger.js +54 -0
- package/dist/cjs/build/ratchet-epsilon-common-info.js +18 -0
- package/dist/cjs/built-in/background/echo-processor.js +18 -0
- package/dist/cjs/built-in/background/log-and-enqueue-echo-processor.js +16 -0
- package/dist/cjs/built-in/background/log-message-background-error-processor.js +10 -0
- package/dist/cjs/built-in/background/no-op-processor.js +13 -0
- package/dist/cjs/built-in/background/retry-processor.js +41 -0
- package/dist/cjs/built-in/background/sample-delay-processor.js +16 -0
- package/dist/cjs/built-in/background/sample-input-validated-processor-data.js +2 -0
- package/dist/cjs/built-in/background/sample-input-validated-processor.js +16 -0
- package/dist/cjs/built-in/built-in-trace-id-generators.js +25 -0
- package/dist/cjs/built-in/daemon/daemon-authorizer-function.js +2 -0
- package/dist/cjs/built-in/daemon/daemon-config.js +2 -0
- package/dist/cjs/built-in/daemon/daemon-group-selection-function.js +2 -0
- package/dist/cjs/built-in/daemon/daemon-handler.js +62 -0
- package/dist/cjs/built-in/daemon/daemon-process-state-list.js +2 -0
- package/dist/cjs/built-in/http/apollo-filter.js +63 -0
- package/dist/cjs/built-in/http/built-in-auth-filters.js +115 -0
- package/dist/cjs/built-in/http/built-in-authorizers.js +43 -0
- package/dist/cjs/built-in/http/built-in-filters.js +222 -0
- package/dist/cjs/built-in/http/built-in-handlers.js +73 -0
- package/dist/cjs/built-in/http/log-level-manipulation-filter.js +20 -0
- package/dist/cjs/built-in/http/run-handler-as-filter.js +64 -0
- package/dist/cjs/cli-bootstrap/epsilon-run-background-process-from-command-line-dry-run.js +20 -0
- package/dist/cjs/config/background/background-aws-config.js +2 -0
- package/dist/cjs/config/background/background-config.js +2 -0
- package/dist/cjs/config/background/background-error-processor.js +2 -0
- package/dist/cjs/config/background/background-processor.js +2 -0
- package/dist/cjs/config/background/background-transaction-log.js +2 -0
- package/dist/cjs/config/background/background-transaction-logger.js +2 -0
- package/dist/cjs/config/cron/abstract-cron-entry.js +2 -0
- package/dist/cjs/config/cron/cron-background-entry.js +2 -0
- package/dist/cjs/config/cron/cron-config.js +2 -0
- package/dist/cjs/config/dynamo-db-config.js +2 -0
- package/dist/cjs/config/epsilon-config.js +2 -0
- package/dist/cjs/config/epsilon-lambda-event-handler.js +2 -0
- package/dist/cjs/config/epsilon-logger-config.js +2 -0
- package/dist/cjs/config/generic-aws-event-handler-function.js +2 -0
- package/dist/cjs/config/http/authorizer-function.js +2 -0
- package/dist/cjs/config/http/epsilon-authorization-context.js +2 -0
- package/dist/cjs/config/http/extended-api-gateway-event.js +2 -0
- package/dist/cjs/config/http/filter-chain-context.js +2 -0
- package/dist/cjs/config/http/filter-function.js +2 -0
- package/dist/cjs/config/http/handler-function.js +2 -0
- package/dist/cjs/config/http/http-config.js +2 -0
- package/dist/cjs/config/http/http-processing-config.js +2 -0
- package/dist/cjs/config/http/mapped-http-processing-config.js +2 -0
- package/dist/cjs/config/http/null-returned-object-handling.js +9 -0
- package/dist/cjs/config/inter-api/inter-api-aws-config.js +2 -0
- package/dist/cjs/config/inter-api/inter-api-config.js +2 -0
- package/dist/cjs/config/inter-api/inter-api-process-mapping.js +2 -0
- package/dist/cjs/config/logging-trace-id-generator.js +2 -0
- package/dist/cjs/config/open-api/open-api-document-components.js +2 -0
- package/dist/cjs/config/open-api/open-api-document-path.js +2 -0
- package/dist/cjs/config/open-api/open-api-document.js +2 -0
- package/dist/cjs/config/s3-config.js +2 -0
- package/dist/cjs/config/sns-config.js +2 -0
- package/dist/cjs/epsilon-build-properties.js +28 -0
- package/dist/cjs/epsilon-constants.js +49 -0
- package/dist/cjs/epsilon-global-handler.js +155 -0
- package/dist/cjs/epsilon-instance.js +2 -0
- package/dist/cjs/epsilon-logging-extension-processor.js +19 -0
- package/dist/cjs/http/auth/api-gateway-adapter-authentication-handler.js +75 -0
- package/dist/cjs/http/auth/auth0-web-token-manipulator.js +62 -0
- package/dist/cjs/http/auth/basic-auth-token.js +2 -0
- package/dist/cjs/http/auth/google-web-token-manipulator.js +72 -0
- package/dist/cjs/http/auth/jwt-ratchet-local-web-token-manipulator.js +29 -0
- package/dist/cjs/http/auth/local-web-token-manipulator.js +74 -0
- package/dist/cjs/http/auth/web-token-manipulator.js +2 -0
- package/dist/cjs/http/error/bad-gateway.js +12 -0
- package/dist/cjs/http/error/bad-request-error.js +12 -0
- package/dist/cjs/http/error/conflict-error.js +12 -0
- package/dist/cjs/http/error/epsilon-http-error.js +132 -0
- package/dist/cjs/http/error/forbidden-error.js +12 -0
- package/dist/cjs/http/error/gateway-timeout.js +12 -0
- package/dist/cjs/http/error/method-not-allowed-error.js +12 -0
- package/dist/cjs/http/error/misconfigured-error.js +12 -0
- package/dist/cjs/http/error/not-found-error.js +12 -0
- package/dist/cjs/http/error/not-implemented.js +12 -0
- package/dist/cjs/http/error/request-timeout-error.js +12 -0
- package/dist/cjs/http/error/service-unavailable.js +12 -0
- package/dist/cjs/http/error/too-many-requests-error.js +12 -0
- package/dist/cjs/http/error/unauthorized-error.js +12 -0
- package/dist/cjs/http/event-util.js +180 -0
- package/dist/cjs/http/response-util.js +146 -0
- package/dist/cjs/http/route/epsilon-router.js +2 -0
- package/dist/cjs/http/route/extended-auth-response-context.js +2 -0
- package/dist/cjs/http/route/route-mapping.js +2 -0
- package/dist/cjs/http/route/route-validator-config.js +2 -0
- package/dist/cjs/http/route/router-util.js +238 -0
- package/dist/cjs/http/web-handler.js +122 -0
- package/dist/cjs/http/web-v2-handler.js +25 -0
- package/dist/cjs/index.js +136 -0
- package/dist/cjs/inter-api/inter-api-entry.js +2 -0
- package/dist/cjs/inter-api/inter-api-util.js +62 -0
- package/dist/cjs/inter-api-manager.js +67 -0
- package/dist/cjs/lambda-event-handler/cron-epsilon-lambda-event-handler.js +76 -0
- package/dist/cjs/lambda-event-handler/dynamo-epsilon-lambda-event-handler.js +36 -0
- package/dist/cjs/lambda-event-handler/generic-sns-epsilon-lambda-event-handler.js +32 -0
- package/dist/cjs/lambda-event-handler/inter-api-epsilon-lambda-event-handler.js +26 -0
- package/dist/cjs/lambda-event-handler/s3-epsilon-lambda-event-handler.js +44 -0
- package/dist/cjs/local-container-server.js +79 -0
- package/dist/cjs/local-server-cert.js +71 -0
- package/dist/cjs/local-server.js +145 -0
- package/dist/cjs/open-api-util/open-api-doc-modifications.js +2 -0
- package/dist/cjs/open-api-util/open-api-doc-modifier.js +83 -0
- package/dist/cjs/open-api-util/yaml-combiner.js +32 -0
- package/dist/cjs/run-background-process-from-command-line.js +37 -0
- package/dist/cjs/sample/sample-batch-only-local-server.js +19 -0
- package/dist/cjs/sample/sample-local-server.js +30 -0
- package/dist/cjs/sample/sample-server-components.js +197 -0
- package/dist/cjs/test-error-server.js +48 -0
- package/dist/cjs/util/aws-util.js +69 -0
- package/dist/cjs/util/context-util.js +104 -0
- package/dist/cjs/util/cron-util.js +72 -0
- package/dist/cjs/util/epsilon-config-parser.js +70 -0
- package/dist/es/background/background-dynamo-log-table-handler.js +33 -0
- package/dist/es/background/background-entry.js +1 -0
- package/dist/es/background/background-execution-event-type.js +8 -0
- package/dist/es/background/background-execution-event.js +1 -0
- package/dist/es/background/background-execution-listener.js +1 -0
- package/dist/es/background/background-handler.js +265 -0
- package/dist/es/background/background-http-adapter-handler.js +123 -0
- package/dist/es/background/background-meta-response-internal.js +1 -0
- package/dist/es/background/background-process-handling.js +5 -0
- package/dist/es/background/background-process-log-table-entry.js +1 -0
- package/dist/es/background/background-queue-response-internal.js +1 -0
- package/dist/es/background/background-validator.js +84 -0
- package/dist/es/background/epsilon-background-process-error.js +88 -0
- package/dist/es/background/internal-background-entry.js +1 -0
- package/dist/es/background/manager/abstract-background-manager.js +88 -0
- package/dist/es/background/manager/aws-sqs-sns-background-manager.js +149 -0
- package/dist/es/background/manager/background-manager-like.js +1 -0
- package/dist/es/background/manager/single-thread-local-background-manager.js +45 -0
- package/dist/es/background/s3-background-transaction-logger.js +49 -0
- package/dist/es/build/ratchet-epsilon-common-info.js +14 -0
- package/dist/es/built-in/background/echo-processor.js +14 -0
- package/dist/es/built-in/background/log-and-enqueue-echo-processor.js +12 -0
- package/dist/es/built-in/background/log-message-background-error-processor.js +6 -0
- package/dist/es/built-in/background/no-op-processor.js +9 -0
- package/dist/es/built-in/background/retry-processor.js +36 -0
- package/dist/es/built-in/background/sample-delay-processor.js +12 -0
- package/dist/es/built-in/background/sample-input-validated-processor-data.js +1 -0
- package/dist/es/built-in/background/sample-input-validated-processor.js +12 -0
- package/dist/es/built-in/built-in-trace-id-generators.js +21 -0
- package/dist/es/built-in/daemon/daemon-authorizer-function.js +1 -0
- package/dist/es/built-in/daemon/daemon-config.js +1 -0
- package/dist/es/built-in/daemon/daemon-group-selection-function.js +1 -0
- package/dist/es/built-in/daemon/daemon-handler.js +58 -0
- package/dist/es/built-in/daemon/daemon-process-state-list.js +1 -0
- package/dist/es/built-in/http/apollo-filter.js +58 -0
- package/dist/es/built-in/http/built-in-auth-filters.js +107 -0
- package/dist/es/built-in/http/built-in-authorizers.js +39 -0
- package/dist/es/built-in/http/built-in-filters.js +208 -0
- package/dist/es/built-in/http/built-in-handlers.js +69 -0
- package/dist/es/built-in/http/log-level-manipulation-filter.js +16 -0
- package/dist/es/built-in/http/run-handler-as-filter.js +60 -0
- package/dist/es/cli-bootstrap/epsilon-run-background-process-from-command-line-dry-run.js +17 -0
- package/dist/es/config/background/background-aws-config.js +1 -0
- package/dist/es/config/background/background-config.js +1 -0
- package/dist/es/config/background/background-error-processor.js +1 -0
- package/dist/es/config/background/background-processor.js +1 -0
- package/dist/es/config/background/background-transaction-log.js +1 -0
- package/dist/es/config/background/background-transaction-logger.js +1 -0
- package/dist/es/config/cron/abstract-cron-entry.js +1 -0
- package/dist/es/config/cron/cron-background-entry.js +1 -0
- package/dist/es/config/cron/cron-config.js +1 -0
- package/dist/es/config/dynamo-db-config.js +1 -0
- package/dist/es/config/epsilon-config.js +1 -0
- package/dist/es/config/epsilon-lambda-event-handler.js +1 -0
- package/dist/es/config/epsilon-logger-config.js +1 -0
- package/dist/es/config/generic-aws-event-handler-function.js +1 -0
- package/dist/es/config/http/authorizer-function.js +1 -0
- package/dist/es/config/http/epsilon-authorization-context.js +1 -0
- package/dist/es/config/http/extended-api-gateway-event.js +1 -0
- package/dist/es/config/http/filter-chain-context.js +1 -0
- package/dist/es/config/http/filter-function.js +1 -0
- package/dist/es/config/http/handler-function.js +1 -0
- package/dist/es/config/http/http-config.js +1 -0
- package/dist/es/config/http/http-processing-config.js +1 -0
- package/dist/es/config/http/mapped-http-processing-config.js +1 -0
- package/dist/es/config/http/null-returned-object-handling.js +6 -0
- package/dist/es/config/inter-api/inter-api-aws-config.js +1 -0
- package/dist/es/config/inter-api/inter-api-config.js +1 -0
- package/dist/es/config/inter-api/inter-api-process-mapping.js +1 -0
- package/dist/es/config/logging-trace-id-generator.js +1 -0
- package/dist/es/config/open-api/open-api-document-components.js +1 -0
- package/dist/es/config/open-api/open-api-document-path.js +1 -0
- package/dist/es/config/open-api/open-api-document.js +1 -0
- package/dist/es/config/s3-config.js +1 -0
- package/dist/es/config/sns-config.js +1 -0
- package/dist/es/epsilon-build-properties.js +24 -0
- package/dist/es/epsilon-constants.js +45 -0
- package/dist/es/epsilon-global-handler.js +149 -0
- package/dist/es/epsilon-instance.js +1 -0
- package/dist/es/epsilon-logging-extension-processor.js +15 -0
- package/dist/es/http/auth/api-gateway-adapter-authentication-handler.js +71 -0
- package/dist/es/http/auth/auth0-web-token-manipulator.js +56 -0
- package/dist/es/http/auth/basic-auth-token.js +1 -0
- package/dist/es/http/auth/google-web-token-manipulator.js +67 -0
- package/dist/es/http/auth/jwt-ratchet-local-web-token-manipulator.js +25 -0
- package/dist/es/http/auth/local-web-token-manipulator.js +70 -0
- package/dist/es/http/auth/web-token-manipulator.js +1 -0
- package/dist/es/http/error/bad-gateway.js +8 -0
- package/dist/es/http/error/bad-request-error.js +8 -0
- package/dist/es/http/error/conflict-error.js +8 -0
- package/dist/es/http/error/epsilon-http-error.js +127 -0
- package/dist/es/http/error/forbidden-error.js +8 -0
- package/dist/es/http/error/gateway-timeout.js +8 -0
- package/dist/es/http/error/method-not-allowed-error.js +8 -0
- package/dist/es/http/error/misconfigured-error.js +8 -0
- package/dist/es/http/error/not-found-error.js +8 -0
- package/dist/es/http/error/not-implemented.js +8 -0
- package/dist/es/http/error/request-timeout-error.js +8 -0
- package/dist/es/http/error/service-unavailable.js +8 -0
- package/dist/es/http/error/too-many-requests-error.js +8 -0
- package/dist/es/http/error/unauthorized-error.js +8 -0
- package/dist/es/http/event-util.js +175 -0
- package/dist/es/http/response-util.js +141 -0
- package/dist/es/http/route/epsilon-router.js +1 -0
- package/dist/es/http/route/extended-auth-response-context.js +1 -0
- package/dist/es/http/route/route-mapping.js +1 -0
- package/dist/es/http/route/route-validator-config.js +1 -0
- package/dist/es/http/route/router-util.js +233 -0
- package/dist/es/http/web-handler.js +116 -0
- package/dist/es/http/web-v2-handler.js +21 -0
- package/dist/es/index.js +133 -0
- package/dist/es/inter-api/inter-api-entry.js +1 -0
- package/dist/es/inter-api/inter-api-util.js +58 -0
- package/dist/es/inter-api-manager.js +63 -0
- package/dist/es/lambda-event-handler/cron-epsilon-lambda-event-handler.js +72 -0
- package/dist/es/lambda-event-handler/dynamo-epsilon-lambda-event-handler.js +32 -0
- package/dist/es/lambda-event-handler/generic-sns-epsilon-lambda-event-handler.js +28 -0
- package/dist/es/lambda-event-handler/inter-api-epsilon-lambda-event-handler.js +22 -0
- package/dist/es/lambda-event-handler/s3-epsilon-lambda-event-handler.js +40 -0
- package/dist/es/local-container-server.js +74 -0
- package/dist/es/local-server-cert.js +67 -0
- package/dist/es/local-server.js +140 -0
- package/dist/es/open-api-util/open-api-doc-modifications.js +1 -0
- package/dist/es/open-api-util/open-api-doc-modifier.js +78 -0
- package/dist/es/open-api-util/yaml-combiner.js +27 -0
- package/dist/es/run-background-process-from-command-line.js +32 -0
- package/dist/es/sample/sample-batch-only-local-server.js +17 -0
- package/dist/es/sample/sample-local-server.js +28 -0
- package/dist/es/sample/sample-server-components.js +192 -0
- package/dist/es/test-error-server.js +43 -0
- package/dist/es/util/aws-util.js +65 -0
- package/dist/es/util/context-util.js +95 -0
- package/dist/es/util/cron-util.js +68 -0
- package/dist/es/util/epsilon-config-parser.js +64 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.es.tsbuildinfo +1 -0
- package/dist/tsconfig.types.tsbuildinfo +1 -0
- package/dist/types/background/background-dynamo-log-table-handler.d.ts +11 -0
- package/dist/types/background/background-entry.d.ts +4 -0
- package/dist/types/background/background-execution-event-type.d.ts +7 -0
- package/dist/types/background/background-execution-event.d.ts +8 -0
- package/dist/types/background/background-execution-listener.d.ts +5 -0
- package/dist/types/background/background-handler.d.ts +33 -0
- package/dist/types/background/background-http-adapter-handler.d.ts +26 -0
- package/dist/types/background/background-meta-response-internal.d.ts +5 -0
- package/dist/types/background/background-process-handling.d.ts +4 -0
- package/dist/types/background/background-process-log-table-entry.d.ts +11 -0
- package/dist/types/background/background-queue-response-internal.d.ts +8 -0
- package/dist/types/background/background-validator.d.ts +20 -0
- package/dist/types/background/epsilon-background-process-error.d.ts +30 -0
- package/dist/types/background/internal-background-entry.d.ts +7 -0
- package/dist/types/background/manager/abstract-background-manager.d.ts +26 -0
- package/dist/types/background/manager/aws-sqs-sns-background-manager.d.ts +30 -0
- package/dist/types/background/manager/background-manager-like.d.ts +24 -0
- package/dist/types/background/manager/single-thread-local-background-manager.d.ts +22 -0
- package/dist/types/background/s3-background-transaction-logger.d.ts +17 -0
- package/dist/types/build/ratchet-epsilon-common-info.d.ts +5 -0
- package/dist/types/built-in/background/echo-processor.d.ts +7 -0
- package/dist/types/built-in/background/log-and-enqueue-echo-processor.d.ts +6 -0
- package/dist/types/built-in/background/log-message-background-error-processor.d.ts +5 -0
- package/dist/types/built-in/background/no-op-processor.d.ts +6 -0
- package/dist/types/built-in/background/retry-processor.d.ts +16 -0
- package/dist/types/built-in/background/sample-delay-processor.d.ts +6 -0
- package/dist/types/built-in/background/sample-input-validated-processor-data.d.ts +4 -0
- package/dist/types/built-in/background/sample-input-validated-processor.d.ts +8 -0
- package/dist/types/built-in/built-in-trace-id-generators.d.ts +5 -0
- package/dist/types/built-in/daemon/daemon-authorizer-function.d.ts +5 -0
- package/dist/types/built-in/daemon/daemon-config.d.ts +8 -0
- package/dist/types/built-in/daemon/daemon-group-selection-function.d.ts +4 -0
- package/dist/types/built-in/daemon/daemon-handler.d.ts +22 -0
- package/dist/types/built-in/daemon/daemon-process-state-list.d.ts +8 -0
- package/dist/types/built-in/http/apollo-filter.d.ts +10 -0
- package/dist/types/built-in/http/built-in-auth-filters.d.ts +9 -0
- package/dist/types/built-in/http/built-in-authorizers.d.ts +8 -0
- package/dist/types/built-in/http/built-in-filters.d.ts +25 -0
- package/dist/types/built-in/http/built-in-handlers.d.ts +9 -0
- package/dist/types/built-in/http/log-level-manipulation-filter.d.ts +9 -0
- package/dist/types/built-in/http/run-handler-as-filter.d.ts +12 -0
- package/dist/types/cli-bootstrap/epsilon-run-background-process-from-command-line-dry-run.d.ts +2 -0
- package/dist/types/config/background/background-aws-config.d.ts +7 -0
- package/dist/types/config/background/background-config.d.ts +14 -0
- package/dist/types/config/background/background-error-processor.d.ts +4 -0
- package/dist/types/config/background/background-processor.d.ts +6 -0
- package/dist/types/config/background/background-transaction-log.d.ts +8 -0
- package/dist/types/config/background/background-transaction-logger.d.ts +5 -0
- package/dist/types/config/cron/abstract-cron-entry.d.ts +12 -0
- package/dist/types/config/cron/cron-background-entry.d.ts +15 -0
- package/dist/types/config/cron/cron-config.d.ts +6 -0
- package/dist/types/config/dynamo-db-config.d.ts +5 -0
- package/dist/types/config/epsilon-config.d.ts +20 -0
- package/dist/types/config/epsilon-lambda-event-handler.d.ts +7 -0
- package/dist/types/config/epsilon-logger-config.d.ts +12 -0
- package/dist/types/config/generic-aws-event-handler-function.d.ts +3 -0
- package/dist/types/config/http/authorizer-function.d.ts +6 -0
- package/dist/types/config/http/epsilon-authorization-context.d.ts +5 -0
- package/dist/types/config/http/extended-api-gateway-event.d.ts +7 -0
- package/dist/types/config/http/filter-chain-context.d.ts +14 -0
- package/dist/types/config/http/filter-function.d.ts +4 -0
- package/dist/types/config/http/handler-function.d.ts +5 -0
- package/dist/types/config/http/http-config.d.ts +15 -0
- package/dist/types/config/http/http-processing-config.d.ts +11 -0
- package/dist/types/config/http/mapped-http-processing-config.d.ts +7 -0
- package/dist/types/config/http/null-returned-object-handling.d.ts +5 -0
- package/dist/types/config/inter-api/inter-api-aws-config.d.ts +5 -0
- package/dist/types/config/inter-api/inter-api-config.d.ts +6 -0
- package/dist/types/config/inter-api/inter-api-process-mapping.d.ts +11 -0
- package/dist/types/config/logging-trace-id-generator.d.ts +4 -0
- package/dist/types/config/open-api/open-api-document-components.d.ts +4 -0
- package/dist/types/config/open-api/open-api-document-path.d.ts +2 -0
- package/dist/types/config/open-api/open-api-document.d.ts +6 -0
- package/dist/types/config/s3-config.d.ts +6 -0
- package/dist/types/config/sns-config.d.ts +5 -0
- package/dist/types/epsilon-build-properties.d.ts +9 -0
- package/dist/types/epsilon-constants.d.ts +16 -0
- package/dist/types/epsilon-global-handler.d.ts +23 -0
- package/dist/types/epsilon-instance.d.ts +19 -0
- package/dist/types/epsilon-logging-extension-processor.d.ts +5 -0
- package/dist/types/http/auth/api-gateway-adapter-authentication-handler.d.ts +18 -0
- package/dist/types/http/auth/auth0-web-token-manipulator.d.ts +13 -0
- package/dist/types/http/auth/basic-auth-token.d.ts +7 -0
- package/dist/types/http/auth/google-web-token-manipulator.d.ts +14 -0
- package/dist/types/http/auth/jwt-ratchet-local-web-token-manipulator.d.ts +13 -0
- package/dist/types/http/auth/local-web-token-manipulator.d.ts +20 -0
- package/dist/types/http/auth/web-token-manipulator.d.ts +7 -0
- package/dist/types/http/error/bad-gateway.d.ts +5 -0
- package/dist/types/http/error/bad-request-error.d.ts +5 -0
- package/dist/types/http/error/conflict-error.d.ts +5 -0
- package/dist/types/http/error/epsilon-http-error.d.ts +41 -0
- package/dist/types/http/error/forbidden-error.d.ts +5 -0
- package/dist/types/http/error/gateway-timeout.d.ts +5 -0
- package/dist/types/http/error/method-not-allowed-error.d.ts +5 -0
- package/dist/types/http/error/misconfigured-error.d.ts +5 -0
- package/dist/types/http/error/not-found-error.d.ts +5 -0
- package/dist/types/http/error/not-implemented.d.ts +5 -0
- package/dist/types/http/error/request-timeout-error.d.ts +5 -0
- package/dist/types/http/error/service-unavailable.d.ts +5 -0
- package/dist/types/http/error/too-many-requests-error.d.ts +5 -0
- package/dist/types/http/error/unauthorized-error.d.ts +5 -0
- package/dist/types/http/event-util.d.ts +47 -0
- package/dist/types/http/response-util.d.ts +11 -0
- package/dist/types/http/route/epsilon-router.d.ts +8 -0
- package/dist/types/http/route/extended-auth-response-context.d.ts +6 -0
- package/dist/types/http/route/route-mapping.d.ts +12 -0
- package/dist/types/http/route/route-validator-config.d.ts +5 -0
- package/dist/types/http/route/router-util.d.ts +26 -0
- package/dist/types/http/web-handler.d.ts +26 -0
- package/dist/types/http/web-v2-handler.d.ts +13 -0
- package/dist/types/index.d.ts +136 -0
- package/dist/types/inter-api/inter-api-entry.d.ts +7 -0
- package/dist/types/inter-api/inter-api-util.d.ts +10 -0
- package/dist/types/inter-api-manager.d.ts +17 -0
- package/dist/types/lambda-event-handler/cron-epsilon-lambda-event-handler.d.ts +14 -0
- package/dist/types/lambda-event-handler/dynamo-epsilon-lambda-event-handler.d.ts +11 -0
- package/dist/types/lambda-event-handler/generic-sns-epsilon-lambda-event-handler.d.ts +10 -0
- package/dist/types/lambda-event-handler/inter-api-epsilon-lambda-event-handler.d.ts +10 -0
- package/dist/types/lambda-event-handler/s3-epsilon-lambda-event-handler.d.ts +10 -0
- package/dist/types/local-container-server.d.ts +13 -0
- package/dist/types/local-server-cert.d.ts +5 -0
- package/dist/types/local-server.d.ts +19 -0
- package/dist/types/open-api-util/open-api-doc-modifications.d.ts +8 -0
- package/dist/types/open-api-util/open-api-doc-modifier.d.ts +10 -0
- package/dist/types/open-api-util/yaml-combiner.d.ts +3 -0
- package/dist/types/run-background-process-from-command-line.d.ts +13 -0
- package/dist/types/sample/sample-batch-only-local-server.d.ts +1 -0
- package/dist/types/sample/sample-local-server.d.ts +1 -0
- package/dist/types/sample/sample-server-components.d.ts +12 -0
- package/dist/types/test-error-server.d.ts +13 -0
- package/dist/types/util/aws-util.d.ts +8 -0
- package/dist/types/util/context-util.d.ts +33 -0
- package/dist/types/util/cron-util.d.ts +11 -0
- package/dist/types/util/epsilon-config-parser.d.ts +14 -0
- package/package.json +132 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContextUtil = void 0;
|
|
4
|
+
const ratchet_common_1 = require("@bitblit/ratchet-common");
|
|
5
|
+
const ratchet_common_2 = require("@bitblit/ratchet-common");
|
|
6
|
+
const built_in_trace_id_generators_1 = require("../built-in/built-in-trace-id-generators");
|
|
7
|
+
const ratchet_common_3 = require("@bitblit/ratchet-common");
|
|
8
|
+
class ContextUtil {
|
|
9
|
+
constructor() { }
|
|
10
|
+
static initContext(epsilon, evt, ctx, processLabel) {
|
|
11
|
+
ContextUtil.CURRENT_EPSILON_REFERENCE = epsilon;
|
|
12
|
+
ContextUtil.CURRENT_CONTEXT = ctx;
|
|
13
|
+
ContextUtil.CURRENT_EVENT = evt;
|
|
14
|
+
ContextUtil.CURRENT_LOG_VARS = {};
|
|
15
|
+
ContextUtil.CURRENT_PROCESS_LABEL = processLabel;
|
|
16
|
+
}
|
|
17
|
+
static clearContext() {
|
|
18
|
+
ContextUtil.CURRENT_EPSILON_REFERENCE = null;
|
|
19
|
+
ContextUtil.CURRENT_CONTEXT = null;
|
|
20
|
+
ContextUtil.CURRENT_EVENT = null;
|
|
21
|
+
ContextUtil.CURRENT_LOG_VARS = {};
|
|
22
|
+
ContextUtil.CURRENT_PROCESS_LABEL = null;
|
|
23
|
+
ContextUtil.CURRENT_OVERRIDE_TRACE_ID = null;
|
|
24
|
+
ContextUtil.CURRENT_OVERRIDE_TRACE_DEPTH = null;
|
|
25
|
+
}
|
|
26
|
+
static setOverrideTrace(traceId, traceDepth) {
|
|
27
|
+
ContextUtil.CURRENT_OVERRIDE_TRACE_ID = traceId || ContextUtil.CURRENT_OVERRIDE_TRACE_ID;
|
|
28
|
+
ContextUtil.CURRENT_OVERRIDE_TRACE_DEPTH = traceDepth || ContextUtil.CURRENT_OVERRIDE_TRACE_DEPTH;
|
|
29
|
+
}
|
|
30
|
+
static setOverrideTraceFromInternalBackgroundEntry(entry) {
|
|
31
|
+
ContextUtil.setOverrideTrace(entry.traceId, entry.traceDepth);
|
|
32
|
+
}
|
|
33
|
+
static setOverrideTraceFromInterApiEntry(interApiEntry) {
|
|
34
|
+
ContextUtil.setOverrideTrace(interApiEntry.traceId, interApiEntry.traceDepth);
|
|
35
|
+
}
|
|
36
|
+
static addHeadersToRecord(input, depthOffset = 0) {
|
|
37
|
+
if (input) {
|
|
38
|
+
input[ContextUtil.traceHeaderName()] = ContextUtil.currentTraceId();
|
|
39
|
+
input[ContextUtil.traceDepthHeaderName()] = ratchet_common_3.StringRatchet.safeString(ContextUtil.currentTraceDepth() + depthOffset);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
ratchet_common_2.ErrorRatchet.throwFormattedErr('Cannot add headers to null/undefined input');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
static addTraceToProxyResult(pr) {
|
|
46
|
+
pr.headers = pr.headers || {};
|
|
47
|
+
ContextUtil.addHeadersToRecord(pr.headers);
|
|
48
|
+
}
|
|
49
|
+
static addTraceToHttpRequestInit(ri) {
|
|
50
|
+
ri.headers = ri.headers || {};
|
|
51
|
+
ContextUtil.addHeadersToRecord(ri.headers, 1);
|
|
52
|
+
}
|
|
53
|
+
static setProcessLabel(processLabel) {
|
|
54
|
+
ContextUtil.CURRENT_PROCESS_LABEL = processLabel;
|
|
55
|
+
}
|
|
56
|
+
static currentRequestId() {
|
|
57
|
+
const ctx = ContextUtil.CURRENT_CONTEXT;
|
|
58
|
+
return ctx ? ctx.awsRequestId : null;
|
|
59
|
+
}
|
|
60
|
+
static remainingTimeMS() {
|
|
61
|
+
const ctx = ContextUtil.CURRENT_CONTEXT;
|
|
62
|
+
return ctx ? ctx.getRemainingTimeInMillis() : null;
|
|
63
|
+
}
|
|
64
|
+
static currentProcessLabel() {
|
|
65
|
+
return ContextUtil.CURRENT_PROCESS_LABEL || 'unset';
|
|
66
|
+
}
|
|
67
|
+
static traceHeaderName() {
|
|
68
|
+
var _a, _b, _c;
|
|
69
|
+
const headerName = ((_c = (_b = (_a = ContextUtil === null || ContextUtil === void 0 ? void 0 : ContextUtil.CURRENT_EPSILON_REFERENCE) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.loggerConfig) === null || _c === void 0 ? void 0 : _c.traceHeaderName) || 'X-TRACE-ID';
|
|
70
|
+
return headerName;
|
|
71
|
+
}
|
|
72
|
+
static traceDepthHeaderName() {
|
|
73
|
+
var _a, _b, _c;
|
|
74
|
+
const headerName = ((_c = (_b = (_a = ContextUtil === null || ContextUtil === void 0 ? void 0 : ContextUtil.CURRENT_EPSILON_REFERENCE) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.loggerConfig) === null || _c === void 0 ? void 0 : _c.traceDepthHeaderName) || 'X-TRACE-DEPTH';
|
|
75
|
+
return headerName;
|
|
76
|
+
}
|
|
77
|
+
static currentTraceId() {
|
|
78
|
+
var _a, _b, _c, _d, _e;
|
|
79
|
+
const traceFn = ((_c = (_b = (_a = ContextUtil === null || ContextUtil === void 0 ? void 0 : ContextUtil.CURRENT_EPSILON_REFERENCE) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.loggerConfig) === null || _c === void 0 ? void 0 : _c.traceIdGenerator) || built_in_trace_id_generators_1.BuiltInTraceIdGenerators.fullAwsRequestId;
|
|
80
|
+
const traceId = ContextUtil.CURRENT_OVERRIDE_TRACE_ID ||
|
|
81
|
+
((_e = (_d = ContextUtil.CURRENT_EVENT) === null || _d === void 0 ? void 0 : _d.headers) === null || _e === void 0 ? void 0 : _e[ContextUtil.traceHeaderName()]) ||
|
|
82
|
+
traceFn(ContextUtil.CURRENT_EVENT, ContextUtil.CURRENT_CONTEXT);
|
|
83
|
+
return traceId;
|
|
84
|
+
}
|
|
85
|
+
static currentTraceDepth() {
|
|
86
|
+
var _a, _b;
|
|
87
|
+
const caller = ContextUtil.CURRENT_OVERRIDE_TRACE_DEPTH ||
|
|
88
|
+
ratchet_common_1.NumberRatchet.safeNumber((_b = (_a = ContextUtil.CURRENT_EVENT) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b[ContextUtil.traceDepthHeaderName()]) ||
|
|
89
|
+
1;
|
|
90
|
+
return caller;
|
|
91
|
+
}
|
|
92
|
+
static addLogVariable(name, val) {
|
|
93
|
+
ContextUtil.CURRENT_LOG_VARS[name] = val;
|
|
94
|
+
}
|
|
95
|
+
static fetchLogVariable(name) {
|
|
96
|
+
var _a;
|
|
97
|
+
return (_a = ContextUtil.CURRENT_LOG_VARS) === null || _a === void 0 ? void 0 : _a[name];
|
|
98
|
+
}
|
|
99
|
+
static fetchLogVariables() {
|
|
100
|
+
return Object.assign({}, ContextUtil.CURRENT_LOG_VARS || {});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.ContextUtil = ContextUtil;
|
|
104
|
+
ContextUtil.CURRENT_LOG_VARS = {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CronUtil = void 0;
|
|
4
|
+
const ratchet_common_1 = require("@bitblit/ratchet-common");
|
|
5
|
+
const ratchet_common_2 = require("@bitblit/ratchet-common");
|
|
6
|
+
const luxon_1 = require("luxon");
|
|
7
|
+
const ratchet_common_3 = require("@bitblit/ratchet-common");
|
|
8
|
+
class CronUtil {
|
|
9
|
+
static everyNMinuteFilter(n) {
|
|
10
|
+
return CronUtil.everyNElementFilter(n, 60);
|
|
11
|
+
}
|
|
12
|
+
static everyNDaysOfYearFilter(n) {
|
|
13
|
+
return CronUtil.everyNElementFilter(n, 365);
|
|
14
|
+
}
|
|
15
|
+
static everyNElementFilter(n, m) {
|
|
16
|
+
ratchet_common_1.RequireRatchet.notNullOrUndefined(n);
|
|
17
|
+
ratchet_common_1.RequireRatchet.notNullOrUndefined(m);
|
|
18
|
+
const half = Math.floor(m / 2);
|
|
19
|
+
if (!n || n < 2 || n > half || m % n !== 0) {
|
|
20
|
+
ratchet_common_2.ErrorRatchet.throwFormattedErr('Invalid config - this function only makes sense for 2 < N < %d and %d evenly divisible by N', half, m);
|
|
21
|
+
throw new Error('Invalid config - this function only makes sense for 2 < N < 31 and 60 evenly divisible by N');
|
|
22
|
+
}
|
|
23
|
+
const rval = [];
|
|
24
|
+
for (let i = 0; i < 60; i += n) {
|
|
25
|
+
rval.push(i);
|
|
26
|
+
}
|
|
27
|
+
return rval;
|
|
28
|
+
}
|
|
29
|
+
static numberMatchesFilter(num, filter) {
|
|
30
|
+
return !filter || filter.length === 0 || filter.includes(num);
|
|
31
|
+
}
|
|
32
|
+
static eventMatchesEntry(event, entry, cfg, testTimeEpochMS = new Date().getTime()) {
|
|
33
|
+
let rval = false;
|
|
34
|
+
if (!!event && !!entry && !!cfg.timezone) {
|
|
35
|
+
if (!!event.resources && event.resources.length > 0) {
|
|
36
|
+
const eventSourceName = event.resources[0];
|
|
37
|
+
const targetTZ = ratchet_common_3.StringRatchet.trimToNull(entry.overrideTimezone) || cfg.timezone;
|
|
38
|
+
const nowInTZ = luxon_1.DateTime.fromMillis(testTimeEpochMS).setZone(targetTZ);
|
|
39
|
+
rval = !entry.eventFilter || entry.eventFilter.test(eventSourceName);
|
|
40
|
+
rval = rval && CronUtil.numberMatchesFilter(nowInTZ.minute, entry.minuteFilter);
|
|
41
|
+
rval = rval && CronUtil.numberMatchesFilter(nowInTZ.hour, entry.hourFilter);
|
|
42
|
+
rval = rval && CronUtil.numberMatchesFilter(nowInTZ.weekday, entry.dayOfWeekFilter);
|
|
43
|
+
rval = rval && CronUtil.numberMatchesFilter(nowInTZ.day, entry.dayOfMonthFilter);
|
|
44
|
+
rval = rval && CronUtil.numberMatchesFilter(nowInTZ.month, entry.monthOfYearFilter);
|
|
45
|
+
rval = rval && (!entry.contextMatchFilter || entry.contextMatchFilter.test(ratchet_common_3.StringRatchet.trimToEmpty(cfg.context)));
|
|
46
|
+
rval = rval && (!entry.contextNoMatchFilter || !entry.contextNoMatchFilter.test(ratchet_common_3.StringRatchet.trimToEmpty(cfg.context)));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return rval;
|
|
50
|
+
}
|
|
51
|
+
static cronEntryName(entry, idx = null) {
|
|
52
|
+
ratchet_common_1.RequireRatchet.notNullOrUndefined(entry);
|
|
53
|
+
let rval = null;
|
|
54
|
+
if (!!entry) {
|
|
55
|
+
rval = entry.name;
|
|
56
|
+
rval = rval || entry['backgroundTaskType'];
|
|
57
|
+
if (!rval && !!entry['directHandler']) {
|
|
58
|
+
if (!!idx) {
|
|
59
|
+
rval = 'Direct Entry ' + idx;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
rval = 'Direct Entry (No idx specified)';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
rval = 'ERROR: no entry passed';
|
|
68
|
+
}
|
|
69
|
+
return rval;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.CronUtil = CronUtil;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EpsilonConfigParser = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const ratchet_common_1 = require("@bitblit/ratchet-common");
|
|
6
|
+
const ratchet_common_2 = require("@bitblit/ratchet-common");
|
|
7
|
+
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
8
|
+
const ratchet_misc_1 = require("@bitblit/ratchet-misc");
|
|
9
|
+
const background_http_adapter_handler_1 = require("../background/background-http-adapter-handler");
|
|
10
|
+
const background_handler_1 = require("../background/background-handler");
|
|
11
|
+
const router_util_1 = require("../http/route/router-util");
|
|
12
|
+
const web_handler_1 = require("../http/web-handler");
|
|
13
|
+
const misconfigured_error_1 = require("../http/error/misconfigured-error");
|
|
14
|
+
const epsilon_global_handler_1 = require("../epsilon-global-handler");
|
|
15
|
+
class EpsilonConfigParser {
|
|
16
|
+
constructor() { }
|
|
17
|
+
static epsilonConfigToEpsilonGlobalHandler(config, backgroundManager) {
|
|
18
|
+
return new epsilon_global_handler_1.EpsilonGlobalHandler(EpsilonConfigParser.epsilonConfigToEpsilonInstance(config, backgroundManager));
|
|
19
|
+
}
|
|
20
|
+
static epsilonConfigToEpsilonInstance(config, backgroundManager) {
|
|
21
|
+
this.validateGlobalConfig(config);
|
|
22
|
+
ratchet_common_1.Logger.info('Creating epsilon : BM : %j', backgroundManager);
|
|
23
|
+
const parsed = EpsilonConfigParser.parseOpenApiDocument(config.openApiYamlString);
|
|
24
|
+
const modelValidator = EpsilonConfigParser.openApiDocToValidator(parsed);
|
|
25
|
+
const backgroundHttpAdapter = new background_http_adapter_handler_1.BackgroundHttpAdapterHandler(config.backgroundConfig, modelValidator, backgroundManager);
|
|
26
|
+
const backgroundHandler = config.backgroundConfig
|
|
27
|
+
? new background_handler_1.BackgroundHandler(config.backgroundConfig, backgroundManager, modelValidator)
|
|
28
|
+
: null;
|
|
29
|
+
const epsilonRouter = config.httpConfig
|
|
30
|
+
? router_util_1.RouterUtil.openApiYamlToRouterConfig(config.httpConfig, parsed, modelValidator, backgroundHttpAdapter)
|
|
31
|
+
: null;
|
|
32
|
+
const webHandler = epsilonRouter ? new web_handler_1.WebHandler(epsilonRouter) : null;
|
|
33
|
+
const inst = {
|
|
34
|
+
config: config,
|
|
35
|
+
parsedOpenApiDoc: parsed,
|
|
36
|
+
modelValidator: modelValidator,
|
|
37
|
+
webHandler: webHandler,
|
|
38
|
+
backgroundHandler: backgroundHandler,
|
|
39
|
+
backgroundManager: backgroundManager,
|
|
40
|
+
};
|
|
41
|
+
return inst;
|
|
42
|
+
}
|
|
43
|
+
static parseOpenApiDocument(yamlString) {
|
|
44
|
+
if (!yamlString) {
|
|
45
|
+
throw new misconfigured_error_1.MisconfiguredError('Cannot configure, missing either yaml or cfg');
|
|
46
|
+
}
|
|
47
|
+
const doc = js_yaml_1.default.load(yamlString);
|
|
48
|
+
return doc;
|
|
49
|
+
}
|
|
50
|
+
static openApiDocToValidator(doc) {
|
|
51
|
+
var _a;
|
|
52
|
+
let rval = null;
|
|
53
|
+
if ((_a = doc === null || doc === void 0 ? void 0 : doc.components) === null || _a === void 0 ? void 0 : _a.schemas) {
|
|
54
|
+
rval = ratchet_misc_1.ModelValidator.createFromParsedObject(doc.components.schemas);
|
|
55
|
+
}
|
|
56
|
+
return rval;
|
|
57
|
+
}
|
|
58
|
+
static validateGlobalConfig(config) {
|
|
59
|
+
if (!config) {
|
|
60
|
+
ratchet_common_2.ErrorRatchet.throwFormattedErr('Config may not be null');
|
|
61
|
+
}
|
|
62
|
+
if (!config.openApiYamlString) {
|
|
63
|
+
ratchet_common_2.ErrorRatchet.throwFormattedErr('Config must define an open api document');
|
|
64
|
+
}
|
|
65
|
+
if (!!config.cron && !config.cron.timezone) {
|
|
66
|
+
ratchet_common_2.ErrorRatchet.throwFormattedErr('Cron is defined, but timezone is not set');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.EpsilonConfigParser = EpsilonConfigParser;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BackgroundExecutionEventType } from './background-execution-event-type';
|
|
2
|
+
import { ContextUtil } from '../util/context-util';
|
|
3
|
+
export class BackgroundDynamoLogTableHandler {
|
|
4
|
+
constructor(dynamo, tableName, env, backgroundQueueName) {
|
|
5
|
+
this.dynamo = dynamo;
|
|
6
|
+
this.tableName = tableName;
|
|
7
|
+
this.env = env;
|
|
8
|
+
this.backgroundQueueName = backgroundQueueName;
|
|
9
|
+
}
|
|
10
|
+
async onEvent(event) {
|
|
11
|
+
const entry = {
|
|
12
|
+
env: this.env,
|
|
13
|
+
backgroundQueueName: this.backgroundQueueName,
|
|
14
|
+
requestId: ContextUtil.currentRequestId(),
|
|
15
|
+
guid: event.guid,
|
|
16
|
+
processTypeName: event.processorType,
|
|
17
|
+
state: event.type.toString(),
|
|
18
|
+
timestampEpochMs: new Date().getTime(),
|
|
19
|
+
};
|
|
20
|
+
if (event.type == BackgroundExecutionEventType.DataValidationError) {
|
|
21
|
+
const errors = event?.errors?.length ? event.errors : ['No-Error'];
|
|
22
|
+
entry.errors = errors;
|
|
23
|
+
}
|
|
24
|
+
else if (event.type == BackgroundExecutionEventType.ProcessStarting) {
|
|
25
|
+
entry.params = event.data;
|
|
26
|
+
}
|
|
27
|
+
else if (event.type == BackgroundExecutionEventType.ExecutionFailedError) {
|
|
28
|
+
const errors = event?.errors?.length ? event.errors : ['No-Error'];
|
|
29
|
+
entry.errors = errors;
|
|
30
|
+
}
|
|
31
|
+
await this.dynamo.simplePut(this.tableName, entry);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export var BackgroundExecutionEventType;
|
|
2
|
+
(function (BackgroundExecutionEventType) {
|
|
3
|
+
BackgroundExecutionEventType["ProcessStarting"] = "ProcessStarting";
|
|
4
|
+
BackgroundExecutionEventType["DataValidationError"] = "DataValidationError";
|
|
5
|
+
BackgroundExecutionEventType["ExecutionSuccessfullyComplete"] = "ExecutionSuccessfullyComplete";
|
|
6
|
+
BackgroundExecutionEventType["ExecutionFailedError"] = "ExecutionRuntimeError";
|
|
7
|
+
BackgroundExecutionEventType["NoMatchProcessorName"] = "NoMatchProcessorName";
|
|
8
|
+
})(BackgroundExecutionEventType || (BackgroundExecutionEventType = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { ErrorRatchet, Logger, StopWatch, StringRatchet } from '@bitblit/ratchet-common';
|
|
2
|
+
import { LambdaEventDetector } from '@bitblit/ratchet-aws';
|
|
3
|
+
import { EpsilonConstants } from '../epsilon-constants';
|
|
4
|
+
import { BackgroundValidator } from './background-validator';
|
|
5
|
+
import { BackgroundExecutionEventType } from './background-execution-event-type';
|
|
6
|
+
import { ContextUtil } from '../util/context-util';
|
|
7
|
+
import { AbstractBackgroundManager } from './manager/abstract-background-manager';
|
|
8
|
+
export class BackgroundHandler {
|
|
9
|
+
constructor(cfg, mgr, modelValidator) {
|
|
10
|
+
this.cfg = cfg;
|
|
11
|
+
this.mgr = mgr;
|
|
12
|
+
this.modelValidator = modelValidator;
|
|
13
|
+
const cfgErrors = BackgroundValidator.validateConfig(cfg);
|
|
14
|
+
if (cfgErrors.length > 0) {
|
|
15
|
+
ErrorRatchet.throwFormattedErr('Invalid background config : %j', cfgErrors);
|
|
16
|
+
}
|
|
17
|
+
Logger.silly('Starting Background processor, %d processors', cfg.processors.length);
|
|
18
|
+
this.validator = new BackgroundValidator(cfg, modelValidator);
|
|
19
|
+
this.processors = BackgroundValidator.validateAndMapProcessors(cfg.processors, modelValidator);
|
|
20
|
+
if (mgr?.immediateProcessQueue && mgr.immediateProcessQueue()) {
|
|
21
|
+
Logger.info('Attaching to immediate processing queue');
|
|
22
|
+
mgr.immediateProcessQueue().subscribe(async (evt) => {
|
|
23
|
+
Logger.debug('Processing local background entry : %j', evt);
|
|
24
|
+
const rval = await this.processSingleBackgroundEntry(evt);
|
|
25
|
+
Logger.info('Processor returned %s', rval);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
extractLabel(evt, context) {
|
|
30
|
+
let rval = null;
|
|
31
|
+
if (this.isBackgroundStartSnsEvent(evt)) {
|
|
32
|
+
rval = 'BG:START-EVT';
|
|
33
|
+
}
|
|
34
|
+
else if (this.isBackgroundImmediateFireEvent(evt)) {
|
|
35
|
+
const pEvt = this.parseImmediateFireBackgroundEntry(evt);
|
|
36
|
+
rval = 'BG:' + pEvt.type + ':' + pEvt.guid;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
rval = 'BG:UNKNOWN';
|
|
40
|
+
}
|
|
41
|
+
return rval;
|
|
42
|
+
}
|
|
43
|
+
handlesEvent(evt) {
|
|
44
|
+
return LambdaEventDetector.isValidSnsEvent(evt) && this.isBackgroundSNSEvent(evt);
|
|
45
|
+
}
|
|
46
|
+
isBackgroundSNSEvent(event) {
|
|
47
|
+
return this.isBackgroundStartSnsEvent(event) || this.isBackgroundImmediateFireEvent(event);
|
|
48
|
+
}
|
|
49
|
+
isBackgroundStartSnsEvent(event) {
|
|
50
|
+
let rval = false;
|
|
51
|
+
if (event) {
|
|
52
|
+
if (LambdaEventDetector.isSingleSnsEvent(event)) {
|
|
53
|
+
const cast = event;
|
|
54
|
+
rval = cast.Records[0].Sns.Message === EpsilonConstants.BACKGROUND_SNS_START_MARKER;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return rval;
|
|
58
|
+
}
|
|
59
|
+
isBackgroundImmediateFireEvent(event) {
|
|
60
|
+
let rval = false;
|
|
61
|
+
if (!!event) {
|
|
62
|
+
if (LambdaEventDetector.isSingleSnsEvent(event)) {
|
|
63
|
+
const cast = event;
|
|
64
|
+
const msg = cast.Records[0].Sns.Message;
|
|
65
|
+
if (!!StringRatchet.trimToNull(msg)) {
|
|
66
|
+
const parsed = JSON.parse(msg);
|
|
67
|
+
rval = !!parsed && parsed['type'] === EpsilonConstants.BACKGROUND_SNS_IMMEDIATE_RUN_FLAG;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return rval;
|
|
72
|
+
}
|
|
73
|
+
parseImmediateFireBackgroundEntry(event) {
|
|
74
|
+
let rval = null;
|
|
75
|
+
try {
|
|
76
|
+
if (!!event) {
|
|
77
|
+
if (LambdaEventDetector.isSingleSnsEvent(event)) {
|
|
78
|
+
const cast = event;
|
|
79
|
+
const msg = cast.Records[0].Sns.Message;
|
|
80
|
+
if (!!StringRatchet.trimToNull(msg)) {
|
|
81
|
+
const parsed = JSON.parse(msg);
|
|
82
|
+
if (!!parsed && parsed['type'] === EpsilonConstants.BACKGROUND_SNS_IMMEDIATE_RUN_FLAG) {
|
|
83
|
+
rval = parsed['backgroundEntry'];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
Logger.error('Could not parse %j as an immediate run event : %s', event, err, err);
|
|
91
|
+
}
|
|
92
|
+
return rval;
|
|
93
|
+
}
|
|
94
|
+
async processEvent(event, context) {
|
|
95
|
+
let procd = null;
|
|
96
|
+
if (!this.isBackgroundStartSnsEvent(event)) {
|
|
97
|
+
const backgroundEntry = this.parseImmediateFireBackgroundEntry(event);
|
|
98
|
+
if (!!backgroundEntry) {
|
|
99
|
+
Logger.silly('Processing immediate fire event : %j', backgroundEntry);
|
|
100
|
+
const result = await this.processSingleBackgroundEntry(backgroundEntry);
|
|
101
|
+
procd = 1;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
Logger.warn('Tried to process non-background start / immediate event : %j returning false', event);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
Logger.info('Reading task from background queue');
|
|
109
|
+
procd = await this.takeAndProcessSingleBackgroundQueueEntry();
|
|
110
|
+
if (procd > 0) {
|
|
111
|
+
Logger.info('Processed %d elements from background queue, refiring', procd);
|
|
112
|
+
const refire = await this.mgr.fireStartProcessingRequest();
|
|
113
|
+
Logger.info('Refire returned %s', refire);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
Logger.info('No items processed - stopping');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const rval = {
|
|
120
|
+
statusCode: 200,
|
|
121
|
+
body: StringRatchet.safeString(procd),
|
|
122
|
+
isBase64Encoded: false,
|
|
123
|
+
};
|
|
124
|
+
return rval;
|
|
125
|
+
}
|
|
126
|
+
async takeAndProcessSingleBackgroundQueueEntry() {
|
|
127
|
+
let rval = null;
|
|
128
|
+
const entries = await this.mgr.takeEntryFromBackgroundQueue();
|
|
129
|
+
Logger.info('Found %d entries - processing', entries.length);
|
|
130
|
+
for (let i = 0; i < entries.length; i++) {
|
|
131
|
+
const e = entries[i];
|
|
132
|
+
const result = await this.processSingleBackgroundEntry(e);
|
|
133
|
+
rval += result ? 1 : 0;
|
|
134
|
+
}
|
|
135
|
+
Logger.debug('Returning %d', rval);
|
|
136
|
+
return rval;
|
|
137
|
+
}
|
|
138
|
+
async safeWriteToLogger(entry) {
|
|
139
|
+
if (this.cfg.transactionLogger) {
|
|
140
|
+
try {
|
|
141
|
+
await this.cfg.transactionLogger.logTransaction(entry);
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
Logger.error('Failed to write to transaction logger : %j : %s', entry, err, err);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
Logger.silly('Skipping - no logger defined');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async conditionallyStartTransactionLog(e) {
|
|
152
|
+
if (!StringRatchet.trimToNull(e.guid)) {
|
|
153
|
+
Logger.warn('No guid found - creating');
|
|
154
|
+
e.guid = AbstractBackgroundManager.generateBackgroundGuid();
|
|
155
|
+
const log = {
|
|
156
|
+
request: e,
|
|
157
|
+
running: true,
|
|
158
|
+
};
|
|
159
|
+
await this.safeWriteToLogger(log);
|
|
160
|
+
}
|
|
161
|
+
Logger.debug('Starting transaction log');
|
|
162
|
+
}
|
|
163
|
+
async conditionallyCompleteTransactionLog(e, result, error, runtimeMS) {
|
|
164
|
+
Logger.debug('Completing transaction log');
|
|
165
|
+
const log = {
|
|
166
|
+
request: e,
|
|
167
|
+
result: result,
|
|
168
|
+
error: error ? ErrorRatchet.safeStringifyErr(error) : null,
|
|
169
|
+
running: false,
|
|
170
|
+
runtimeMS: runtimeMS,
|
|
171
|
+
};
|
|
172
|
+
await this.safeWriteToLogger(log);
|
|
173
|
+
}
|
|
174
|
+
async conditionallyRunErrorProcessor(e, error) {
|
|
175
|
+
try {
|
|
176
|
+
if (this.cfg.errorProcessor) {
|
|
177
|
+
Logger.info('Running error processor');
|
|
178
|
+
await this.cfg.errorProcessor.handleError(e, error);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
catch (err) {
|
|
182
|
+
Logger.error('Background : BAD - Failed to run error processor : %s', err, err);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
async fireListenerEvent(event) {
|
|
186
|
+
const listeners = this.cfg.executionListeners || [];
|
|
187
|
+
for (const listener of listeners) {
|
|
188
|
+
try {
|
|
189
|
+
await listener.onEvent(event);
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
Logger.error('Failure triggering handler %s : %s', StringRatchet.trimToNull(listener?.label) || 'No-name', err);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
async processSingleBackgroundEntry(e) {
|
|
197
|
+
ContextUtil.setOverrideTraceFromInternalBackgroundEntry(e);
|
|
198
|
+
Logger.info('Background Process Start: %j', e);
|
|
199
|
+
const sw = new StopWatch();
|
|
200
|
+
await this.conditionallyStartTransactionLog(e);
|
|
201
|
+
let rval = false;
|
|
202
|
+
try {
|
|
203
|
+
await this.fireListenerEvent({
|
|
204
|
+
type: BackgroundExecutionEventType.ProcessStarting,
|
|
205
|
+
processorType: e.type,
|
|
206
|
+
data: e.data,
|
|
207
|
+
guid: e.guid,
|
|
208
|
+
});
|
|
209
|
+
const processorInput = this.processors.get(e.type);
|
|
210
|
+
if (!processorInput) {
|
|
211
|
+
ErrorRatchet.throwFormattedErr('Found no processor for background entry : %j (returning false)', e);
|
|
212
|
+
await this.fireListenerEvent({
|
|
213
|
+
type: BackgroundExecutionEventType.NoMatchProcessorName,
|
|
214
|
+
processorType: e.type,
|
|
215
|
+
data: e.data,
|
|
216
|
+
guid: e.guid,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
let dataValidationErrors = [];
|
|
220
|
+
if (StringRatchet.trimToNull(processorInput.dataSchemaName)) {
|
|
221
|
+
dataValidationErrors = this.modelValidator.validate(processorInput.dataSchemaName, e.data, false, false);
|
|
222
|
+
}
|
|
223
|
+
if (dataValidationErrors.length > 0) {
|
|
224
|
+
await this.fireListenerEvent({
|
|
225
|
+
type: BackgroundExecutionEventType.DataValidationError,
|
|
226
|
+
processorType: e.type,
|
|
227
|
+
data: e.data,
|
|
228
|
+
errors: dataValidationErrors,
|
|
229
|
+
guid: e.guid,
|
|
230
|
+
});
|
|
231
|
+
ErrorRatchet.throwFormattedErr('Not processing, data failed validation; entry was %j : errors : %j', e, dataValidationErrors);
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
let result = await processorInput.handleEvent(e.data, this.mgr);
|
|
235
|
+
result = result || 'SUCCESSFUL COMPLETION : NO RESULT RETURNED';
|
|
236
|
+
await this.conditionallyCompleteTransactionLog(e, result, null, sw.elapsedMS());
|
|
237
|
+
await this.fireListenerEvent({
|
|
238
|
+
type: BackgroundExecutionEventType.ExecutionSuccessfullyComplete,
|
|
239
|
+
processorType: e.type,
|
|
240
|
+
data: result,
|
|
241
|
+
guid: e.guid,
|
|
242
|
+
});
|
|
243
|
+
rval = true;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
catch (err) {
|
|
247
|
+
Logger.error('Background Process Error: %j : %s', e, err, err);
|
|
248
|
+
await this.conditionallyRunErrorProcessor(e, err);
|
|
249
|
+
await this.conditionallyCompleteTransactionLog(e, null, err, sw.elapsedMS());
|
|
250
|
+
await this.fireListenerEvent({
|
|
251
|
+
type: BackgroundExecutionEventType.ExecutionFailedError,
|
|
252
|
+
processorType: e.type,
|
|
253
|
+
data: e.data,
|
|
254
|
+
errors: [ErrorRatchet.safeStringifyErr(err)],
|
|
255
|
+
guid: e.guid,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
Logger.info('Background Process Stop: %j : %s', e, sw.dump());
|
|
259
|
+
return rval;
|
|
260
|
+
}
|
|
261
|
+
getConfig() {
|
|
262
|
+
const rval = Object.assign({}, this.cfg);
|
|
263
|
+
return rval;
|
|
264
|
+
}
|
|
265
|
+
}
|