@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.
Files changed (409) hide show
  1. package/CHANGELOG.md +177 -0
  2. package/License.txt +13 -0
  3. package/README.md +242 -0
  4. package/dist/cjs/background/background-dynamo-log-table-handler.js +38 -0
  5. package/dist/cjs/background/background-entry.js +2 -0
  6. package/dist/cjs/background/background-execution-event-type.js +11 -0
  7. package/dist/cjs/background/background-execution-event.js +2 -0
  8. package/dist/cjs/background/background-execution-listener.js +2 -0
  9. package/dist/cjs/background/background-handler.js +269 -0
  10. package/dist/cjs/background/background-http-adapter-handler.js +127 -0
  11. package/dist/cjs/background/background-meta-response-internal.js +2 -0
  12. package/dist/cjs/background/background-process-handling.js +8 -0
  13. package/dist/cjs/background/background-process-log-table-entry.js +2 -0
  14. package/dist/cjs/background/background-queue-response-internal.js +2 -0
  15. package/dist/cjs/background/background-validator.js +88 -0
  16. package/dist/cjs/background/epsilon-background-process-error.js +93 -0
  17. package/dist/cjs/background/internal-background-entry.js +2 -0
  18. package/dist/cjs/background/manager/abstract-background-manager.js +92 -0
  19. package/dist/cjs/background/manager/aws-sqs-sns-background-manager.js +153 -0
  20. package/dist/cjs/background/manager/background-manager-like.js +2 -0
  21. package/dist/cjs/background/manager/single-thread-local-background-manager.js +49 -0
  22. package/dist/cjs/background/s3-background-transaction-logger.js +54 -0
  23. package/dist/cjs/build/ratchet-epsilon-common-info.js +18 -0
  24. package/dist/cjs/built-in/background/echo-processor.js +18 -0
  25. package/dist/cjs/built-in/background/log-and-enqueue-echo-processor.js +16 -0
  26. package/dist/cjs/built-in/background/log-message-background-error-processor.js +10 -0
  27. package/dist/cjs/built-in/background/no-op-processor.js +13 -0
  28. package/dist/cjs/built-in/background/retry-processor.js +41 -0
  29. package/dist/cjs/built-in/background/sample-delay-processor.js +16 -0
  30. package/dist/cjs/built-in/background/sample-input-validated-processor-data.js +2 -0
  31. package/dist/cjs/built-in/background/sample-input-validated-processor.js +16 -0
  32. package/dist/cjs/built-in/built-in-trace-id-generators.js +25 -0
  33. package/dist/cjs/built-in/daemon/daemon-authorizer-function.js +2 -0
  34. package/dist/cjs/built-in/daemon/daemon-config.js +2 -0
  35. package/dist/cjs/built-in/daemon/daemon-group-selection-function.js +2 -0
  36. package/dist/cjs/built-in/daemon/daemon-handler.js +62 -0
  37. package/dist/cjs/built-in/daemon/daemon-process-state-list.js +2 -0
  38. package/dist/cjs/built-in/http/apollo-filter.js +63 -0
  39. package/dist/cjs/built-in/http/built-in-auth-filters.js +115 -0
  40. package/dist/cjs/built-in/http/built-in-authorizers.js +43 -0
  41. package/dist/cjs/built-in/http/built-in-filters.js +222 -0
  42. package/dist/cjs/built-in/http/built-in-handlers.js +73 -0
  43. package/dist/cjs/built-in/http/log-level-manipulation-filter.js +20 -0
  44. package/dist/cjs/built-in/http/run-handler-as-filter.js +64 -0
  45. package/dist/cjs/cli-bootstrap/epsilon-run-background-process-from-command-line-dry-run.js +20 -0
  46. package/dist/cjs/config/background/background-aws-config.js +2 -0
  47. package/dist/cjs/config/background/background-config.js +2 -0
  48. package/dist/cjs/config/background/background-error-processor.js +2 -0
  49. package/dist/cjs/config/background/background-processor.js +2 -0
  50. package/dist/cjs/config/background/background-transaction-log.js +2 -0
  51. package/dist/cjs/config/background/background-transaction-logger.js +2 -0
  52. package/dist/cjs/config/cron/abstract-cron-entry.js +2 -0
  53. package/dist/cjs/config/cron/cron-background-entry.js +2 -0
  54. package/dist/cjs/config/cron/cron-config.js +2 -0
  55. package/dist/cjs/config/dynamo-db-config.js +2 -0
  56. package/dist/cjs/config/epsilon-config.js +2 -0
  57. package/dist/cjs/config/epsilon-lambda-event-handler.js +2 -0
  58. package/dist/cjs/config/epsilon-logger-config.js +2 -0
  59. package/dist/cjs/config/generic-aws-event-handler-function.js +2 -0
  60. package/dist/cjs/config/http/authorizer-function.js +2 -0
  61. package/dist/cjs/config/http/epsilon-authorization-context.js +2 -0
  62. package/dist/cjs/config/http/extended-api-gateway-event.js +2 -0
  63. package/dist/cjs/config/http/filter-chain-context.js +2 -0
  64. package/dist/cjs/config/http/filter-function.js +2 -0
  65. package/dist/cjs/config/http/handler-function.js +2 -0
  66. package/dist/cjs/config/http/http-config.js +2 -0
  67. package/dist/cjs/config/http/http-processing-config.js +2 -0
  68. package/dist/cjs/config/http/mapped-http-processing-config.js +2 -0
  69. package/dist/cjs/config/http/null-returned-object-handling.js +9 -0
  70. package/dist/cjs/config/inter-api/inter-api-aws-config.js +2 -0
  71. package/dist/cjs/config/inter-api/inter-api-config.js +2 -0
  72. package/dist/cjs/config/inter-api/inter-api-process-mapping.js +2 -0
  73. package/dist/cjs/config/logging-trace-id-generator.js +2 -0
  74. package/dist/cjs/config/open-api/open-api-document-components.js +2 -0
  75. package/dist/cjs/config/open-api/open-api-document-path.js +2 -0
  76. package/dist/cjs/config/open-api/open-api-document.js +2 -0
  77. package/dist/cjs/config/s3-config.js +2 -0
  78. package/dist/cjs/config/sns-config.js +2 -0
  79. package/dist/cjs/epsilon-build-properties.js +28 -0
  80. package/dist/cjs/epsilon-constants.js +49 -0
  81. package/dist/cjs/epsilon-global-handler.js +155 -0
  82. package/dist/cjs/epsilon-instance.js +2 -0
  83. package/dist/cjs/epsilon-logging-extension-processor.js +19 -0
  84. package/dist/cjs/http/auth/api-gateway-adapter-authentication-handler.js +75 -0
  85. package/dist/cjs/http/auth/auth0-web-token-manipulator.js +62 -0
  86. package/dist/cjs/http/auth/basic-auth-token.js +2 -0
  87. package/dist/cjs/http/auth/google-web-token-manipulator.js +72 -0
  88. package/dist/cjs/http/auth/jwt-ratchet-local-web-token-manipulator.js +29 -0
  89. package/dist/cjs/http/auth/local-web-token-manipulator.js +74 -0
  90. package/dist/cjs/http/auth/web-token-manipulator.js +2 -0
  91. package/dist/cjs/http/error/bad-gateway.js +12 -0
  92. package/dist/cjs/http/error/bad-request-error.js +12 -0
  93. package/dist/cjs/http/error/conflict-error.js +12 -0
  94. package/dist/cjs/http/error/epsilon-http-error.js +132 -0
  95. package/dist/cjs/http/error/forbidden-error.js +12 -0
  96. package/dist/cjs/http/error/gateway-timeout.js +12 -0
  97. package/dist/cjs/http/error/method-not-allowed-error.js +12 -0
  98. package/dist/cjs/http/error/misconfigured-error.js +12 -0
  99. package/dist/cjs/http/error/not-found-error.js +12 -0
  100. package/dist/cjs/http/error/not-implemented.js +12 -0
  101. package/dist/cjs/http/error/request-timeout-error.js +12 -0
  102. package/dist/cjs/http/error/service-unavailable.js +12 -0
  103. package/dist/cjs/http/error/too-many-requests-error.js +12 -0
  104. package/dist/cjs/http/error/unauthorized-error.js +12 -0
  105. package/dist/cjs/http/event-util.js +180 -0
  106. package/dist/cjs/http/response-util.js +146 -0
  107. package/dist/cjs/http/route/epsilon-router.js +2 -0
  108. package/dist/cjs/http/route/extended-auth-response-context.js +2 -0
  109. package/dist/cjs/http/route/route-mapping.js +2 -0
  110. package/dist/cjs/http/route/route-validator-config.js +2 -0
  111. package/dist/cjs/http/route/router-util.js +238 -0
  112. package/dist/cjs/http/web-handler.js +122 -0
  113. package/dist/cjs/http/web-v2-handler.js +25 -0
  114. package/dist/cjs/index.js +136 -0
  115. package/dist/cjs/inter-api/inter-api-entry.js +2 -0
  116. package/dist/cjs/inter-api/inter-api-util.js +62 -0
  117. package/dist/cjs/inter-api-manager.js +67 -0
  118. package/dist/cjs/lambda-event-handler/cron-epsilon-lambda-event-handler.js +76 -0
  119. package/dist/cjs/lambda-event-handler/dynamo-epsilon-lambda-event-handler.js +36 -0
  120. package/dist/cjs/lambda-event-handler/generic-sns-epsilon-lambda-event-handler.js +32 -0
  121. package/dist/cjs/lambda-event-handler/inter-api-epsilon-lambda-event-handler.js +26 -0
  122. package/dist/cjs/lambda-event-handler/s3-epsilon-lambda-event-handler.js +44 -0
  123. package/dist/cjs/local-container-server.js +79 -0
  124. package/dist/cjs/local-server-cert.js +71 -0
  125. package/dist/cjs/local-server.js +145 -0
  126. package/dist/cjs/open-api-util/open-api-doc-modifications.js +2 -0
  127. package/dist/cjs/open-api-util/open-api-doc-modifier.js +83 -0
  128. package/dist/cjs/open-api-util/yaml-combiner.js +32 -0
  129. package/dist/cjs/run-background-process-from-command-line.js +37 -0
  130. package/dist/cjs/sample/sample-batch-only-local-server.js +19 -0
  131. package/dist/cjs/sample/sample-local-server.js +30 -0
  132. package/dist/cjs/sample/sample-server-components.js +197 -0
  133. package/dist/cjs/test-error-server.js +48 -0
  134. package/dist/cjs/util/aws-util.js +69 -0
  135. package/dist/cjs/util/context-util.js +104 -0
  136. package/dist/cjs/util/cron-util.js +72 -0
  137. package/dist/cjs/util/epsilon-config-parser.js +70 -0
  138. package/dist/es/background/background-dynamo-log-table-handler.js +33 -0
  139. package/dist/es/background/background-entry.js +1 -0
  140. package/dist/es/background/background-execution-event-type.js +8 -0
  141. package/dist/es/background/background-execution-event.js +1 -0
  142. package/dist/es/background/background-execution-listener.js +1 -0
  143. package/dist/es/background/background-handler.js +265 -0
  144. package/dist/es/background/background-http-adapter-handler.js +123 -0
  145. package/dist/es/background/background-meta-response-internal.js +1 -0
  146. package/dist/es/background/background-process-handling.js +5 -0
  147. package/dist/es/background/background-process-log-table-entry.js +1 -0
  148. package/dist/es/background/background-queue-response-internal.js +1 -0
  149. package/dist/es/background/background-validator.js +84 -0
  150. package/dist/es/background/epsilon-background-process-error.js +88 -0
  151. package/dist/es/background/internal-background-entry.js +1 -0
  152. package/dist/es/background/manager/abstract-background-manager.js +88 -0
  153. package/dist/es/background/manager/aws-sqs-sns-background-manager.js +149 -0
  154. package/dist/es/background/manager/background-manager-like.js +1 -0
  155. package/dist/es/background/manager/single-thread-local-background-manager.js +45 -0
  156. package/dist/es/background/s3-background-transaction-logger.js +49 -0
  157. package/dist/es/build/ratchet-epsilon-common-info.js +14 -0
  158. package/dist/es/built-in/background/echo-processor.js +14 -0
  159. package/dist/es/built-in/background/log-and-enqueue-echo-processor.js +12 -0
  160. package/dist/es/built-in/background/log-message-background-error-processor.js +6 -0
  161. package/dist/es/built-in/background/no-op-processor.js +9 -0
  162. package/dist/es/built-in/background/retry-processor.js +36 -0
  163. package/dist/es/built-in/background/sample-delay-processor.js +12 -0
  164. package/dist/es/built-in/background/sample-input-validated-processor-data.js +1 -0
  165. package/dist/es/built-in/background/sample-input-validated-processor.js +12 -0
  166. package/dist/es/built-in/built-in-trace-id-generators.js +21 -0
  167. package/dist/es/built-in/daemon/daemon-authorizer-function.js +1 -0
  168. package/dist/es/built-in/daemon/daemon-config.js +1 -0
  169. package/dist/es/built-in/daemon/daemon-group-selection-function.js +1 -0
  170. package/dist/es/built-in/daemon/daemon-handler.js +58 -0
  171. package/dist/es/built-in/daemon/daemon-process-state-list.js +1 -0
  172. package/dist/es/built-in/http/apollo-filter.js +58 -0
  173. package/dist/es/built-in/http/built-in-auth-filters.js +107 -0
  174. package/dist/es/built-in/http/built-in-authorizers.js +39 -0
  175. package/dist/es/built-in/http/built-in-filters.js +208 -0
  176. package/dist/es/built-in/http/built-in-handlers.js +69 -0
  177. package/dist/es/built-in/http/log-level-manipulation-filter.js +16 -0
  178. package/dist/es/built-in/http/run-handler-as-filter.js +60 -0
  179. package/dist/es/cli-bootstrap/epsilon-run-background-process-from-command-line-dry-run.js +17 -0
  180. package/dist/es/config/background/background-aws-config.js +1 -0
  181. package/dist/es/config/background/background-config.js +1 -0
  182. package/dist/es/config/background/background-error-processor.js +1 -0
  183. package/dist/es/config/background/background-processor.js +1 -0
  184. package/dist/es/config/background/background-transaction-log.js +1 -0
  185. package/dist/es/config/background/background-transaction-logger.js +1 -0
  186. package/dist/es/config/cron/abstract-cron-entry.js +1 -0
  187. package/dist/es/config/cron/cron-background-entry.js +1 -0
  188. package/dist/es/config/cron/cron-config.js +1 -0
  189. package/dist/es/config/dynamo-db-config.js +1 -0
  190. package/dist/es/config/epsilon-config.js +1 -0
  191. package/dist/es/config/epsilon-lambda-event-handler.js +1 -0
  192. package/dist/es/config/epsilon-logger-config.js +1 -0
  193. package/dist/es/config/generic-aws-event-handler-function.js +1 -0
  194. package/dist/es/config/http/authorizer-function.js +1 -0
  195. package/dist/es/config/http/epsilon-authorization-context.js +1 -0
  196. package/dist/es/config/http/extended-api-gateway-event.js +1 -0
  197. package/dist/es/config/http/filter-chain-context.js +1 -0
  198. package/dist/es/config/http/filter-function.js +1 -0
  199. package/dist/es/config/http/handler-function.js +1 -0
  200. package/dist/es/config/http/http-config.js +1 -0
  201. package/dist/es/config/http/http-processing-config.js +1 -0
  202. package/dist/es/config/http/mapped-http-processing-config.js +1 -0
  203. package/dist/es/config/http/null-returned-object-handling.js +6 -0
  204. package/dist/es/config/inter-api/inter-api-aws-config.js +1 -0
  205. package/dist/es/config/inter-api/inter-api-config.js +1 -0
  206. package/dist/es/config/inter-api/inter-api-process-mapping.js +1 -0
  207. package/dist/es/config/logging-trace-id-generator.js +1 -0
  208. package/dist/es/config/open-api/open-api-document-components.js +1 -0
  209. package/dist/es/config/open-api/open-api-document-path.js +1 -0
  210. package/dist/es/config/open-api/open-api-document.js +1 -0
  211. package/dist/es/config/s3-config.js +1 -0
  212. package/dist/es/config/sns-config.js +1 -0
  213. package/dist/es/epsilon-build-properties.js +24 -0
  214. package/dist/es/epsilon-constants.js +45 -0
  215. package/dist/es/epsilon-global-handler.js +149 -0
  216. package/dist/es/epsilon-instance.js +1 -0
  217. package/dist/es/epsilon-logging-extension-processor.js +15 -0
  218. package/dist/es/http/auth/api-gateway-adapter-authentication-handler.js +71 -0
  219. package/dist/es/http/auth/auth0-web-token-manipulator.js +56 -0
  220. package/dist/es/http/auth/basic-auth-token.js +1 -0
  221. package/dist/es/http/auth/google-web-token-manipulator.js +67 -0
  222. package/dist/es/http/auth/jwt-ratchet-local-web-token-manipulator.js +25 -0
  223. package/dist/es/http/auth/local-web-token-manipulator.js +70 -0
  224. package/dist/es/http/auth/web-token-manipulator.js +1 -0
  225. package/dist/es/http/error/bad-gateway.js +8 -0
  226. package/dist/es/http/error/bad-request-error.js +8 -0
  227. package/dist/es/http/error/conflict-error.js +8 -0
  228. package/dist/es/http/error/epsilon-http-error.js +127 -0
  229. package/dist/es/http/error/forbidden-error.js +8 -0
  230. package/dist/es/http/error/gateway-timeout.js +8 -0
  231. package/dist/es/http/error/method-not-allowed-error.js +8 -0
  232. package/dist/es/http/error/misconfigured-error.js +8 -0
  233. package/dist/es/http/error/not-found-error.js +8 -0
  234. package/dist/es/http/error/not-implemented.js +8 -0
  235. package/dist/es/http/error/request-timeout-error.js +8 -0
  236. package/dist/es/http/error/service-unavailable.js +8 -0
  237. package/dist/es/http/error/too-many-requests-error.js +8 -0
  238. package/dist/es/http/error/unauthorized-error.js +8 -0
  239. package/dist/es/http/event-util.js +175 -0
  240. package/dist/es/http/response-util.js +141 -0
  241. package/dist/es/http/route/epsilon-router.js +1 -0
  242. package/dist/es/http/route/extended-auth-response-context.js +1 -0
  243. package/dist/es/http/route/route-mapping.js +1 -0
  244. package/dist/es/http/route/route-validator-config.js +1 -0
  245. package/dist/es/http/route/router-util.js +233 -0
  246. package/dist/es/http/web-handler.js +116 -0
  247. package/dist/es/http/web-v2-handler.js +21 -0
  248. package/dist/es/index.js +133 -0
  249. package/dist/es/inter-api/inter-api-entry.js +1 -0
  250. package/dist/es/inter-api/inter-api-util.js +58 -0
  251. package/dist/es/inter-api-manager.js +63 -0
  252. package/dist/es/lambda-event-handler/cron-epsilon-lambda-event-handler.js +72 -0
  253. package/dist/es/lambda-event-handler/dynamo-epsilon-lambda-event-handler.js +32 -0
  254. package/dist/es/lambda-event-handler/generic-sns-epsilon-lambda-event-handler.js +28 -0
  255. package/dist/es/lambda-event-handler/inter-api-epsilon-lambda-event-handler.js +22 -0
  256. package/dist/es/lambda-event-handler/s3-epsilon-lambda-event-handler.js +40 -0
  257. package/dist/es/local-container-server.js +74 -0
  258. package/dist/es/local-server-cert.js +67 -0
  259. package/dist/es/local-server.js +140 -0
  260. package/dist/es/open-api-util/open-api-doc-modifications.js +1 -0
  261. package/dist/es/open-api-util/open-api-doc-modifier.js +78 -0
  262. package/dist/es/open-api-util/yaml-combiner.js +27 -0
  263. package/dist/es/run-background-process-from-command-line.js +32 -0
  264. package/dist/es/sample/sample-batch-only-local-server.js +17 -0
  265. package/dist/es/sample/sample-local-server.js +28 -0
  266. package/dist/es/sample/sample-server-components.js +192 -0
  267. package/dist/es/test-error-server.js +43 -0
  268. package/dist/es/util/aws-util.js +65 -0
  269. package/dist/es/util/context-util.js +95 -0
  270. package/dist/es/util/cron-util.js +68 -0
  271. package/dist/es/util/epsilon-config-parser.js +64 -0
  272. package/dist/tsconfig.cjs.tsbuildinfo +1 -0
  273. package/dist/tsconfig.es.tsbuildinfo +1 -0
  274. package/dist/tsconfig.types.tsbuildinfo +1 -0
  275. package/dist/types/background/background-dynamo-log-table-handler.d.ts +11 -0
  276. package/dist/types/background/background-entry.d.ts +4 -0
  277. package/dist/types/background/background-execution-event-type.d.ts +7 -0
  278. package/dist/types/background/background-execution-event.d.ts +8 -0
  279. package/dist/types/background/background-execution-listener.d.ts +5 -0
  280. package/dist/types/background/background-handler.d.ts +33 -0
  281. package/dist/types/background/background-http-adapter-handler.d.ts +26 -0
  282. package/dist/types/background/background-meta-response-internal.d.ts +5 -0
  283. package/dist/types/background/background-process-handling.d.ts +4 -0
  284. package/dist/types/background/background-process-log-table-entry.d.ts +11 -0
  285. package/dist/types/background/background-queue-response-internal.d.ts +8 -0
  286. package/dist/types/background/background-validator.d.ts +20 -0
  287. package/dist/types/background/epsilon-background-process-error.d.ts +30 -0
  288. package/dist/types/background/internal-background-entry.d.ts +7 -0
  289. package/dist/types/background/manager/abstract-background-manager.d.ts +26 -0
  290. package/dist/types/background/manager/aws-sqs-sns-background-manager.d.ts +30 -0
  291. package/dist/types/background/manager/background-manager-like.d.ts +24 -0
  292. package/dist/types/background/manager/single-thread-local-background-manager.d.ts +22 -0
  293. package/dist/types/background/s3-background-transaction-logger.d.ts +17 -0
  294. package/dist/types/build/ratchet-epsilon-common-info.d.ts +5 -0
  295. package/dist/types/built-in/background/echo-processor.d.ts +7 -0
  296. package/dist/types/built-in/background/log-and-enqueue-echo-processor.d.ts +6 -0
  297. package/dist/types/built-in/background/log-message-background-error-processor.d.ts +5 -0
  298. package/dist/types/built-in/background/no-op-processor.d.ts +6 -0
  299. package/dist/types/built-in/background/retry-processor.d.ts +16 -0
  300. package/dist/types/built-in/background/sample-delay-processor.d.ts +6 -0
  301. package/dist/types/built-in/background/sample-input-validated-processor-data.d.ts +4 -0
  302. package/dist/types/built-in/background/sample-input-validated-processor.d.ts +8 -0
  303. package/dist/types/built-in/built-in-trace-id-generators.d.ts +5 -0
  304. package/dist/types/built-in/daemon/daemon-authorizer-function.d.ts +5 -0
  305. package/dist/types/built-in/daemon/daemon-config.d.ts +8 -0
  306. package/dist/types/built-in/daemon/daemon-group-selection-function.d.ts +4 -0
  307. package/dist/types/built-in/daemon/daemon-handler.d.ts +22 -0
  308. package/dist/types/built-in/daemon/daemon-process-state-list.d.ts +8 -0
  309. package/dist/types/built-in/http/apollo-filter.d.ts +10 -0
  310. package/dist/types/built-in/http/built-in-auth-filters.d.ts +9 -0
  311. package/dist/types/built-in/http/built-in-authorizers.d.ts +8 -0
  312. package/dist/types/built-in/http/built-in-filters.d.ts +25 -0
  313. package/dist/types/built-in/http/built-in-handlers.d.ts +9 -0
  314. package/dist/types/built-in/http/log-level-manipulation-filter.d.ts +9 -0
  315. package/dist/types/built-in/http/run-handler-as-filter.d.ts +12 -0
  316. package/dist/types/cli-bootstrap/epsilon-run-background-process-from-command-line-dry-run.d.ts +2 -0
  317. package/dist/types/config/background/background-aws-config.d.ts +7 -0
  318. package/dist/types/config/background/background-config.d.ts +14 -0
  319. package/dist/types/config/background/background-error-processor.d.ts +4 -0
  320. package/dist/types/config/background/background-processor.d.ts +6 -0
  321. package/dist/types/config/background/background-transaction-log.d.ts +8 -0
  322. package/dist/types/config/background/background-transaction-logger.d.ts +5 -0
  323. package/dist/types/config/cron/abstract-cron-entry.d.ts +12 -0
  324. package/dist/types/config/cron/cron-background-entry.d.ts +15 -0
  325. package/dist/types/config/cron/cron-config.d.ts +6 -0
  326. package/dist/types/config/dynamo-db-config.d.ts +5 -0
  327. package/dist/types/config/epsilon-config.d.ts +20 -0
  328. package/dist/types/config/epsilon-lambda-event-handler.d.ts +7 -0
  329. package/dist/types/config/epsilon-logger-config.d.ts +12 -0
  330. package/dist/types/config/generic-aws-event-handler-function.d.ts +3 -0
  331. package/dist/types/config/http/authorizer-function.d.ts +6 -0
  332. package/dist/types/config/http/epsilon-authorization-context.d.ts +5 -0
  333. package/dist/types/config/http/extended-api-gateway-event.d.ts +7 -0
  334. package/dist/types/config/http/filter-chain-context.d.ts +14 -0
  335. package/dist/types/config/http/filter-function.d.ts +4 -0
  336. package/dist/types/config/http/handler-function.d.ts +5 -0
  337. package/dist/types/config/http/http-config.d.ts +15 -0
  338. package/dist/types/config/http/http-processing-config.d.ts +11 -0
  339. package/dist/types/config/http/mapped-http-processing-config.d.ts +7 -0
  340. package/dist/types/config/http/null-returned-object-handling.d.ts +5 -0
  341. package/dist/types/config/inter-api/inter-api-aws-config.d.ts +5 -0
  342. package/dist/types/config/inter-api/inter-api-config.d.ts +6 -0
  343. package/dist/types/config/inter-api/inter-api-process-mapping.d.ts +11 -0
  344. package/dist/types/config/logging-trace-id-generator.d.ts +4 -0
  345. package/dist/types/config/open-api/open-api-document-components.d.ts +4 -0
  346. package/dist/types/config/open-api/open-api-document-path.d.ts +2 -0
  347. package/dist/types/config/open-api/open-api-document.d.ts +6 -0
  348. package/dist/types/config/s3-config.d.ts +6 -0
  349. package/dist/types/config/sns-config.d.ts +5 -0
  350. package/dist/types/epsilon-build-properties.d.ts +9 -0
  351. package/dist/types/epsilon-constants.d.ts +16 -0
  352. package/dist/types/epsilon-global-handler.d.ts +23 -0
  353. package/dist/types/epsilon-instance.d.ts +19 -0
  354. package/dist/types/epsilon-logging-extension-processor.d.ts +5 -0
  355. package/dist/types/http/auth/api-gateway-adapter-authentication-handler.d.ts +18 -0
  356. package/dist/types/http/auth/auth0-web-token-manipulator.d.ts +13 -0
  357. package/dist/types/http/auth/basic-auth-token.d.ts +7 -0
  358. package/dist/types/http/auth/google-web-token-manipulator.d.ts +14 -0
  359. package/dist/types/http/auth/jwt-ratchet-local-web-token-manipulator.d.ts +13 -0
  360. package/dist/types/http/auth/local-web-token-manipulator.d.ts +20 -0
  361. package/dist/types/http/auth/web-token-manipulator.d.ts +7 -0
  362. package/dist/types/http/error/bad-gateway.d.ts +5 -0
  363. package/dist/types/http/error/bad-request-error.d.ts +5 -0
  364. package/dist/types/http/error/conflict-error.d.ts +5 -0
  365. package/dist/types/http/error/epsilon-http-error.d.ts +41 -0
  366. package/dist/types/http/error/forbidden-error.d.ts +5 -0
  367. package/dist/types/http/error/gateway-timeout.d.ts +5 -0
  368. package/dist/types/http/error/method-not-allowed-error.d.ts +5 -0
  369. package/dist/types/http/error/misconfigured-error.d.ts +5 -0
  370. package/dist/types/http/error/not-found-error.d.ts +5 -0
  371. package/dist/types/http/error/not-implemented.d.ts +5 -0
  372. package/dist/types/http/error/request-timeout-error.d.ts +5 -0
  373. package/dist/types/http/error/service-unavailable.d.ts +5 -0
  374. package/dist/types/http/error/too-many-requests-error.d.ts +5 -0
  375. package/dist/types/http/error/unauthorized-error.d.ts +5 -0
  376. package/dist/types/http/event-util.d.ts +47 -0
  377. package/dist/types/http/response-util.d.ts +11 -0
  378. package/dist/types/http/route/epsilon-router.d.ts +8 -0
  379. package/dist/types/http/route/extended-auth-response-context.d.ts +6 -0
  380. package/dist/types/http/route/route-mapping.d.ts +12 -0
  381. package/dist/types/http/route/route-validator-config.d.ts +5 -0
  382. package/dist/types/http/route/router-util.d.ts +26 -0
  383. package/dist/types/http/web-handler.d.ts +26 -0
  384. package/dist/types/http/web-v2-handler.d.ts +13 -0
  385. package/dist/types/index.d.ts +136 -0
  386. package/dist/types/inter-api/inter-api-entry.d.ts +7 -0
  387. package/dist/types/inter-api/inter-api-util.d.ts +10 -0
  388. package/dist/types/inter-api-manager.d.ts +17 -0
  389. package/dist/types/lambda-event-handler/cron-epsilon-lambda-event-handler.d.ts +14 -0
  390. package/dist/types/lambda-event-handler/dynamo-epsilon-lambda-event-handler.d.ts +11 -0
  391. package/dist/types/lambda-event-handler/generic-sns-epsilon-lambda-event-handler.d.ts +10 -0
  392. package/dist/types/lambda-event-handler/inter-api-epsilon-lambda-event-handler.d.ts +10 -0
  393. package/dist/types/lambda-event-handler/s3-epsilon-lambda-event-handler.d.ts +10 -0
  394. package/dist/types/local-container-server.d.ts +13 -0
  395. package/dist/types/local-server-cert.d.ts +5 -0
  396. package/dist/types/local-server.d.ts +19 -0
  397. package/dist/types/open-api-util/open-api-doc-modifications.d.ts +8 -0
  398. package/dist/types/open-api-util/open-api-doc-modifier.d.ts +10 -0
  399. package/dist/types/open-api-util/yaml-combiner.d.ts +3 -0
  400. package/dist/types/run-background-process-from-command-line.d.ts +13 -0
  401. package/dist/types/sample/sample-batch-only-local-server.d.ts +1 -0
  402. package/dist/types/sample/sample-local-server.d.ts +1 -0
  403. package/dist/types/sample/sample-server-components.d.ts +12 -0
  404. package/dist/types/test-error-server.d.ts +13 -0
  405. package/dist/types/util/aws-util.d.ts +8 -0
  406. package/dist/types/util/context-util.d.ts +33 -0
  407. package/dist/types/util/cron-util.d.ts +11 -0
  408. package/dist/types/util/epsilon-config-parser.d.ts +14 -0
  409. package/package.json +132 -0
@@ -0,0 +1,123 @@
1
+ import { Logger, StopWatch } from '@bitblit/ratchet-common';
2
+ import { BooleanRatchet } from '@bitblit/ratchet-common';
3
+ import { BackgroundProcessHandling } from './background-process-handling';
4
+ import { StringRatchet } from '@bitblit/ratchet-common';
5
+ import { BadRequestError } from '../http/error/bad-request-error';
6
+ import { NotFoundError } from '../http/error/not-found-error';
7
+ import { PromiseRatchet } from '@bitblit/ratchet-common';
8
+ export class BackgroundHttpAdapterHandler {
9
+ constructor(backgroundConfig, modelValidator, backgroundManager, maxWaitInMsForBackgroundJobToStart = 10000) {
10
+ this.backgroundConfig = backgroundConfig;
11
+ this.modelValidator = modelValidator;
12
+ this.backgroundManager = backgroundManager;
13
+ this.maxWaitInMsForBackgroundJobToStart = maxWaitInMsForBackgroundJobToStart;
14
+ }
15
+ get httpMetaEndpoint() {
16
+ return this.backgroundConfig.httpMetaEndpoint;
17
+ }
18
+ get httpSubmissionPath() {
19
+ return this.backgroundConfig.httpSubmissionPath;
20
+ }
21
+ get httpStatusPath() {
22
+ return this.backgroundConfig.httpStatusEndpoint;
23
+ }
24
+ get implyTypeFromPathSuffix() {
25
+ return this.backgroundConfig.implyTypeFromPathSuffix;
26
+ }
27
+ async handleBackgroundStatusRequest(evt, context) {
28
+ Logger.info('handleBackgroundStatusRequest called');
29
+ if (!this.backgroundConfig.transactionLogger) {
30
+ throw new BadRequestError('Process logging not enabled');
31
+ }
32
+ else {
33
+ const guid = StringRatchet.trimToNull(evt.pathParameters['guid']) || StringRatchet.trimToNull(evt.queryStringParameters['guid']);
34
+ if (guid) {
35
+ const sw = new StopWatch();
36
+ let log = null;
37
+ while (!log && sw.elapsedMS() < this.maxWaitInMsForBackgroundJobToStart) {
38
+ log = await this.backgroundConfig.transactionLogger.readTransactionLog(guid);
39
+ if (!log) {
40
+ Logger.debug('No log found yet, waiting 500 ms and retrying (%s of %d waited so far)', sw.dump(), this.maxWaitInMsForBackgroundJobToStart);
41
+ await PromiseRatchet.wait(500);
42
+ }
43
+ }
44
+ if (!log) {
45
+ throw new NotFoundError().withFormattedErrorMessage('No background result found for guid %s', guid);
46
+ }
47
+ return log;
48
+ }
49
+ else {
50
+ throw new BadRequestError('No guid specified');
51
+ }
52
+ }
53
+ }
54
+ async handleBackgroundMetaRequest(evt, context) {
55
+ Logger.info('handleBackgroundMetaRequest called');
56
+ const currentCount = await this.backgroundManager.fetchApproximateNumberOfQueueEntries();
57
+ const valid = this.backgroundConfig.processors.map((b) => b.typeName).filter((a) => !!a);
58
+ valid.sort((a, b) => a.localeCompare(b));
59
+ const rval = {
60
+ currentQueueLength: currentCount,
61
+ validTypes: valid,
62
+ backgroundManagerName: this.backgroundManager.backgroundManagerName,
63
+ };
64
+ return rval;
65
+ }
66
+ async handleBackgroundSubmission(evt, context) {
67
+ Logger.info('handleBackgroundSubmission : %j (mgr:%s)', evt.parsedBody, this.backgroundManager.backgroundManagerName);
68
+ let rval = null;
69
+ const startIdx = evt.path.indexOf(this.httpSubmissionPath) + this.httpSubmissionPath.length;
70
+ let pathSuppliedBackgroundType = this.backgroundConfig.implyTypeFromPathSuffix
71
+ ? evt.path.substring(startIdx).split('-').join('').toLowerCase()
72
+ : '';
73
+ if (pathSuppliedBackgroundType.includes('?')) {
74
+ pathSuppliedBackgroundType = pathSuppliedBackgroundType.substring(0, pathSuppliedBackgroundType.indexOf('?'));
75
+ }
76
+ if (pathSuppliedBackgroundType.includes('#')) {
77
+ pathSuppliedBackgroundType = pathSuppliedBackgroundType.substring(0, pathSuppliedBackgroundType.indexOf('#'));
78
+ }
79
+ const entry = evt.parsedBody || {};
80
+ if (StringRatchet.trimToNull(pathSuppliedBackgroundType)) {
81
+ if (StringRatchet.trimToNull(entry?.type) && entry.type.toLocaleLowerCase() !== pathSuppliedBackgroundType.toLocaleLowerCase()) {
82
+ throw new BadRequestError('Background submission has type but does not match path supplied type');
83
+ }
84
+ else {
85
+ entry.type = pathSuppliedBackgroundType;
86
+ }
87
+ }
88
+ else {
89
+ if (!StringRatchet.trimToNull(entry?.type)) {
90
+ throw new BadRequestError('Background submission missing type and not configured in pathed mode');
91
+ }
92
+ }
93
+ const foundProc = this.backgroundConfig.processors.find((s) => s.typeName.toLowerCase() === entry.type.toLowerCase());
94
+ const immediate = BooleanRatchet.parseBool(evt.queryStringParameters['immediate']);
95
+ const startProcessor = BooleanRatchet.parseBool(evt.queryStringParameters['startProcessor']);
96
+ if (foundProc) {
97
+ if (StringRatchet.trimToNull(foundProc.dataSchemaName)) {
98
+ const errors = this.modelValidator.validate(foundProc.dataSchemaName, entry.data, false, false);
99
+ if (errors.length > 0) {
100
+ throw new BadRequestError().withErrors(errors);
101
+ }
102
+ }
103
+ let result = null;
104
+ if (immediate) {
105
+ result = await this.backgroundManager.fireImmediateProcessRequest(entry);
106
+ }
107
+ else {
108
+ result = await this.backgroundManager.addEntryToQueue(entry, startProcessor);
109
+ }
110
+ rval = {
111
+ processHandling: immediate ? BackgroundProcessHandling.Immediate : BackgroundProcessHandling.Queued,
112
+ startProcessorRequested: startProcessor,
113
+ success: true,
114
+ resultId: result,
115
+ error: null,
116
+ };
117
+ }
118
+ else {
119
+ throw new BadRequestError().withFormattedErrorMessage('Could not find target background processor : %s', entry.type);
120
+ }
121
+ return rval;
122
+ }
123
+ }
@@ -0,0 +1,5 @@
1
+ export var BackgroundProcessHandling;
2
+ (function (BackgroundProcessHandling) {
3
+ BackgroundProcessHandling["Queued"] = "Queued";
4
+ BackgroundProcessHandling["Immediate"] = "Immediate";
5
+ })(BackgroundProcessHandling || (BackgroundProcessHandling = {}));
@@ -0,0 +1,84 @@
1
+ import { Logger } from '@bitblit/ratchet-common';
2
+ import { ErrorRatchet } from '@bitblit/ratchet-common';
3
+ import { StringRatchet } from '@bitblit/ratchet-common';
4
+ export class BackgroundValidator {
5
+ constructor(cfg, modelValidator) {
6
+ this.cfg = cfg;
7
+ this.modelValidator = modelValidator;
8
+ }
9
+ findProcessor(typeName) {
10
+ const rval = this.cfg.processors.find((s) => s.typeName === typeName);
11
+ return rval;
12
+ }
13
+ validType(type) {
14
+ return !!this.findProcessor(type);
15
+ }
16
+ validateEntry(entry) {
17
+ const rval = [];
18
+ if (!entry) {
19
+ rval.push('Entry is null');
20
+ }
21
+ else if (!StringRatchet.trimToNull(entry.type)) {
22
+ rval.push('Entry type is null or empty');
23
+ const proc = this.findProcessor(entry.type);
24
+ if (!proc) {
25
+ rval.push('Entry type is invalid');
26
+ }
27
+ }
28
+ return rval;
29
+ }
30
+ validateEntryAndThrowException(entry) {
31
+ const errors = this.validateEntry(entry);
32
+ if (errors.length > 0) {
33
+ Logger.warn('Invalid entry %j : errors : %j', entry, errors);
34
+ ErrorRatchet.throwFormattedErr('Invalid entry %j : errors : %j', entry, errors);
35
+ }
36
+ }
37
+ static validateAndMapProcessors(processorInput, modelValidator) {
38
+ const rval = new Map();
39
+ processorInput.forEach((p, idx) => {
40
+ if (!p) {
41
+ ErrorRatchet.throwFormattedErr('Null processor provided at index %d', idx);
42
+ }
43
+ if (!StringRatchet.trimToNull(p.typeName)) {
44
+ ErrorRatchet.throwFormattedErr('Processor at index %d defines no name', idx);
45
+ }
46
+ if (rval.has(p.typeName)) {
47
+ ErrorRatchet.throwFormattedErr('More than one processor defined for type %s', p.typeName);
48
+ }
49
+ rval.set(p.typeName, p);
50
+ });
51
+ return rval;
52
+ }
53
+ static validateAwsConfig(cfg) {
54
+ const rval = [];
55
+ if (!cfg) {
56
+ rval.push('Null config');
57
+ }
58
+ else {
59
+ if (!cfg.notificationArn) {
60
+ rval.push('AWS config missing notificationArn');
61
+ }
62
+ if (!cfg.queueUrl) {
63
+ rval.push('AWS config missing queueUrl');
64
+ }
65
+ if ((cfg.sendNotificationOnBackgroundError || cfg.sendNotificationOnBackgroundValidationFailure) &&
66
+ !cfg.backgroundProcessFailureSnsArn) {
67
+ rval.push('At least one send notification flag set to true but no sns arn set');
68
+ }
69
+ }
70
+ return rval;
71
+ }
72
+ static validateConfig(cfg) {
73
+ const rval = [];
74
+ if (!cfg) {
75
+ rval.push('Null config');
76
+ }
77
+ else {
78
+ if (!cfg.processors || cfg.processors.length === 0) {
79
+ rval.push('No processes specified');
80
+ }
81
+ }
82
+ return rval;
83
+ }
84
+ }
@@ -0,0 +1,88 @@
1
+ import util from 'util';
2
+ export class EpsilonBackgroundProcessError extends Error {
3
+ constructor(...errors) {
4
+ super(EpsilonBackgroundProcessError.combineErrorStringsWithDefault(errors));
5
+ Object.setPrototypeOf(this, EpsilonBackgroundProcessError.prototype);
6
+ this._errors = errors;
7
+ this[EpsilonBackgroundProcessError.EPSILON_BACKGROUND_PROCESS_ERROR_FLAG_KEY] = true;
8
+ }
9
+ static combineErrorStringsWithDefault(errors, defMessage = 'Internal Server Error') {
10
+ return errors && errors.length > 0 ? errors.join(',') : defMessage;
11
+ }
12
+ setFormattedErrorMessage(format, ...input) {
13
+ const msg = util.format(format, ...input);
14
+ this.errors = [msg];
15
+ }
16
+ withFormattedErrorMessage(format, ...input) {
17
+ this.setFormattedErrorMessage(format, ...input);
18
+ return this;
19
+ }
20
+ withErrors(errors) {
21
+ this.errors = errors;
22
+ return this;
23
+ }
24
+ withDetailErrorCode(detailErrorCode) {
25
+ this._detailErrorCode = detailErrorCode;
26
+ return this;
27
+ }
28
+ withDetails(details) {
29
+ this._details = details;
30
+ return this;
31
+ }
32
+ withRequestId(requestId) {
33
+ this._requestId = requestId;
34
+ return this;
35
+ }
36
+ withWrappedError(err) {
37
+ this._wrappedError = err;
38
+ return this;
39
+ }
40
+ isWrappedError() {
41
+ return !!this._wrappedError;
42
+ }
43
+ static wrapError(err) {
44
+ let rval = null;
45
+ if (EpsilonBackgroundProcessError.objectIsEpsilonBackgroundProcessError(err)) {
46
+ rval = err;
47
+ }
48
+ else {
49
+ rval = new EpsilonBackgroundProcessError(err.message).withWrappedError(err);
50
+ }
51
+ return rval;
52
+ }
53
+ static objectIsEpsilonBackgroundProcessError(obj) {
54
+ return obj && obj['__epsilonHttpErrorFlag'] === true;
55
+ }
56
+ set errors(value) {
57
+ this._errors = value || ['Internal Server Error'];
58
+ this.message = EpsilonBackgroundProcessError.combineErrorStringsWithDefault(this._errors);
59
+ }
60
+ get errors() {
61
+ return this._errors;
62
+ }
63
+ set detailErrorCode(value) {
64
+ this._detailErrorCode = value;
65
+ }
66
+ get detailErrorCode() {
67
+ return this._detailErrorCode;
68
+ }
69
+ set details(value) {
70
+ this._details = value;
71
+ }
72
+ get details() {
73
+ return this._details;
74
+ }
75
+ set requestId(value) {
76
+ this._requestId = value || 'MISSING';
77
+ }
78
+ get requestId() {
79
+ return this._requestId;
80
+ }
81
+ set wrappedError(value) {
82
+ this._wrappedError = value;
83
+ }
84
+ get wrappedError() {
85
+ return this._wrappedError;
86
+ }
87
+ }
88
+ EpsilonBackgroundProcessError.EPSILON_BACKGROUND_PROCESS_ERROR_FLAG_KEY = '__epsilonBackgroundProcessErrorFlag';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,88 @@
1
+ import { ErrorRatchet, Logger } from '@bitblit/ratchet-common';
2
+ import { StringRatchet } from '@bitblit/ratchet-common';
3
+ import { DateTime } from 'luxon';
4
+ import { RequireRatchet } from '@bitblit/ratchet-common';
5
+ import { ContextUtil } from '../../util/context-util';
6
+ export class AbstractBackgroundManager {
7
+ createEntry(type, data) {
8
+ const rval = {
9
+ type: type,
10
+ data: data,
11
+ };
12
+ return rval;
13
+ }
14
+ wrapEntryForInternal(entry, overrideTraceId, overrideTraceDepth) {
15
+ const rval = Object.assign({}, entry, {
16
+ createdEpochMS: new Date().getTime(),
17
+ guid: AbstractBackgroundManager.generateBackgroundGuid(),
18
+ traceId: overrideTraceId || ContextUtil.currentTraceId(),
19
+ traceDepth: overrideTraceDepth || ContextUtil.currentTraceDepth() + 1,
20
+ });
21
+ return rval;
22
+ }
23
+ async addEntryToQueueByParts(type, data, fireStartMessage) {
24
+ let rval = null;
25
+ const entry = this.createEntry(type, data);
26
+ if (entry) {
27
+ rval = await this.addEntryToQueue(entry, fireStartMessage);
28
+ }
29
+ return rval;
30
+ }
31
+ async addEntriesToQueue(entries, fireStartMessage) {
32
+ const rval = [];
33
+ for (let i = 0; i < entries.length; i++) {
34
+ try {
35
+ const tmp = await this.addEntryToQueue(entries[i], false);
36
+ rval.push(tmp);
37
+ }
38
+ catch (err) {
39
+ Logger.error('Error processing %j : %s', entries[i], err);
40
+ rval.push(err['message']);
41
+ }
42
+ if (fireStartMessage) {
43
+ const fireResult = await this.fireStartProcessingRequest();
44
+ Logger.silly('FireResult : %s', fireResult);
45
+ }
46
+ }
47
+ return rval;
48
+ }
49
+ async fireImmediateProcessRequestByParts(type, data) {
50
+ let rval = null;
51
+ const entry = this.createEntry(type, data);
52
+ if (entry) {
53
+ rval = await this.fireImmediateProcessRequest(entry);
54
+ }
55
+ return rval;
56
+ }
57
+ static generateBackgroundGuid(targetEpochMS = new Date().getTime()) {
58
+ const dt = DateTime.fromMillis(targetEpochMS);
59
+ return dt.toFormat('yyyy-MM-dd-HH-mm-ss-') + StringRatchet.createType4Guid();
60
+ }
61
+ static backgroundGuidToPath(prefix, guid) {
62
+ let path = StringRatchet.trimToEmpty(prefix);
63
+ if (path.length && !path.endsWith('/')) {
64
+ path += '/';
65
+ }
66
+ path += guid.substring(0, 4) + '/' + guid.substring(5, 7) + '/' + guid.substring(8, 10) + '/';
67
+ path += guid + '.json';
68
+ return path;
69
+ }
70
+ static pathToBackgroundGuid(prefix, path) {
71
+ RequireRatchet.notNullOrUndefined(path, 'path');
72
+ let start = 0;
73
+ if (!path.endsWith('.json')) {
74
+ ErrorRatchet.throwFormattedErr('Cannot extract guid, does not end with .json : %s : %s', path, prefix);
75
+ }
76
+ if (StringRatchet.trimToNull(prefix)) {
77
+ if (!path.startsWith(prefix)) {
78
+ ErrorRatchet.throwFormattedErr('Cannot extract guid, does not start with prefix : %s : %s', path, prefix);
79
+ }
80
+ start = prefix.length;
81
+ if (!prefix.endsWith('/')) {
82
+ start++;
83
+ }
84
+ }
85
+ start += 11;
86
+ return path.substring(start, path.length - 5);
87
+ }
88
+ }
@@ -0,0 +1,149 @@
1
+ import { Logger, NumberRatchet } from '@bitblit/ratchet-common';
2
+ import { DeleteMessageCommand, GetQueueAttributesCommand, ReceiveMessageCommand, SendMessageCommand, } from '@aws-sdk/client-sqs';
3
+ import { EpsilonConstants } from '../../epsilon-constants';
4
+ import { AbstractBackgroundManager } from './abstract-background-manager';
5
+ import { BackgroundValidator } from '../background-validator';
6
+ import { ErrorRatchet } from '@bitblit/ratchet-common';
7
+ import { PublishCommand } from '@aws-sdk/client-sns';
8
+ export class AwsSqsSnsBackgroundManager extends AbstractBackgroundManager {
9
+ constructor(_awsConfig, _sqs, _sns) {
10
+ super();
11
+ this._awsConfig = _awsConfig;
12
+ this._sqs = _sqs;
13
+ this._sns = _sns;
14
+ const cfgErrors = BackgroundValidator.validateAwsConfig(_awsConfig);
15
+ if (cfgErrors.length) {
16
+ ErrorRatchet.throwFormattedErr('Cannot start - invalid AWS config : %j', cfgErrors);
17
+ }
18
+ }
19
+ get backgroundManagerName() {
20
+ return 'AwsSqsSnsBackgroundManager';
21
+ }
22
+ get awsConfig() {
23
+ return this._awsConfig;
24
+ }
25
+ get sqs() {
26
+ return this._sqs;
27
+ }
28
+ get sns() {
29
+ return this._sns;
30
+ }
31
+ async addEntryToQueue(entry, fireStartMessage) {
32
+ try {
33
+ const wrapped = this.wrapEntryForInternal(entry);
34
+ const rval = wrapped.guid;
35
+ const params = {
36
+ DelaySeconds: 0,
37
+ MessageBody: JSON.stringify(wrapped),
38
+ MessageGroupId: entry.type,
39
+ QueueUrl: this.awsConfig.queueUrl,
40
+ };
41
+ Logger.info('Add entry to queue (remote) : %j : Start : %s', params, fireStartMessage);
42
+ const result = await this.sqs.send(new SendMessageCommand(params));
43
+ if (fireStartMessage) {
44
+ const fireResult = await this.fireStartProcessingRequest();
45
+ Logger.silly('FireResult : %s', fireResult);
46
+ }
47
+ Logger.info('Background process %s using message id %s', rval, result.MessageId);
48
+ return rval;
49
+ }
50
+ catch (error) {
51
+ Logger.error('Error inserting background entry into SQS queue : %j', error);
52
+ throw new Error('Error inserting background entry into SQS queue : ' + error['code'] + ' : ' + error['name']);
53
+ }
54
+ }
55
+ async fireImmediateProcessRequest(entry) {
56
+ let rval = null;
57
+ const wrapped = this.wrapEntryForInternal(entry);
58
+ rval = wrapped.guid;
59
+ try {
60
+ Logger.info('Fire immediately (remote) : %j ', entry);
61
+ const toWrite = {
62
+ type: EpsilonConstants.BACKGROUND_SNS_IMMEDIATE_RUN_FLAG,
63
+ backgroundEntry: wrapped,
64
+ };
65
+ const msg = JSON.stringify(toWrite);
66
+ const snsId = await this.writeMessageToSnsTopic(msg);
67
+ Logger.debug('Background guid %s Wrote message : %s to SNS : %s', rval, msg, snsId);
68
+ }
69
+ catch (err) {
70
+ Logger.error('Failed to fireImmediateProcessRequest : %s', err, err);
71
+ }
72
+ return rval;
73
+ }
74
+ async fireStartProcessingRequest() {
75
+ let rval = null;
76
+ try {
77
+ Logger.info('Fire start processing request (remote)');
78
+ rval = await this.writeMessageToSnsTopic(EpsilonConstants.BACKGROUND_SNS_START_MARKER);
79
+ }
80
+ catch (err) {
81
+ Logger.error('Failed to fireStartProcessingRequest : %s', err, err);
82
+ }
83
+ return rval;
84
+ }
85
+ async fetchApproximateNumberOfQueueEntries() {
86
+ let rval = null;
87
+ const all = await this.fetchCurrentQueueAttributes();
88
+ rval = NumberRatchet.safeNumber(all.Attributes['ApproximateNumberOfMessages']);
89
+ return rval;
90
+ }
91
+ async fetchCurrentQueueAttributes() {
92
+ let rval = null;
93
+ const req = {
94
+ AttributeNames: ['All'],
95
+ QueueUrl: this.awsConfig.queueUrl,
96
+ };
97
+ rval = await this.sqs.send(new GetQueueAttributesCommand(req));
98
+ return rval;
99
+ }
100
+ async writeMessageToSnsTopic(message) {
101
+ let rval = null;
102
+ const params = {
103
+ Message: message,
104
+ TopicArn: this.awsConfig.notificationArn,
105
+ };
106
+ Logger.debug('Writing message to SNS topic : j', params);
107
+ const result = await this.sns.send(new PublishCommand(params));
108
+ rval = result.MessageId;
109
+ return rval;
110
+ }
111
+ async takeEntryFromBackgroundQueue() {
112
+ const rval = [];
113
+ const params = {
114
+ MaxNumberOfMessages: 1,
115
+ QueueUrl: this.awsConfig.queueUrl,
116
+ VisibilityTimeout: 300,
117
+ WaitTimeSeconds: 0,
118
+ };
119
+ const message = await this.sqs.send(new ReceiveMessageCommand(params));
120
+ if (message && message.Messages && message.Messages.length > 0) {
121
+ for (let i = 0; i < message.Messages.length; i++) {
122
+ const m = message.Messages[i];
123
+ try {
124
+ const parsedBody = JSON.parse(m.Body);
125
+ if (!parsedBody.type) {
126
+ Logger.warn('Dropping invalid background entry : %j', parsedBody);
127
+ }
128
+ else {
129
+ rval.push(parsedBody);
130
+ }
131
+ Logger.debug('Removing message from queue');
132
+ const delParams = {
133
+ QueueUrl: this.awsConfig.queueUrl,
134
+ ReceiptHandle: m.ReceiptHandle,
135
+ };
136
+ const delResult = await this.sqs.send(new DeleteMessageCommand(delParams));
137
+ Logger.silly('Delete result : %j', delResult);
138
+ }
139
+ catch (err) {
140
+ Logger.warn('Error parsing message, dropping : %j', m);
141
+ }
142
+ }
143
+ }
144
+ else {
145
+ Logger.debug('No messages found (likely end of recursion)');
146
+ }
147
+ return rval;
148
+ }
149
+ }
@@ -0,0 +1,45 @@
1
+ import { Subject } from 'rxjs';
2
+ import { Logger } from '@bitblit/ratchet-common';
3
+ import { AbstractBackgroundManager } from './abstract-background-manager';
4
+ export class SingleThreadLocalBackgroundManager extends AbstractBackgroundManager {
5
+ get backgroundManagerName() {
6
+ return 'SingleThreadLocalBackgroundManager';
7
+ }
8
+ constructor() {
9
+ super();
10
+ this._localBus = new Subject();
11
+ }
12
+ immediateProcessQueue() {
13
+ return this._localBus;
14
+ }
15
+ async addEntryToQueue(entry, fireStartMessage) {
16
+ const wrapped = this.wrapEntryForInternal(entry);
17
+ const rval = wrapped.guid;
18
+ Logger.info('Add entry to queue (local) : %j : Start : %s', entry, fireStartMessage);
19
+ this._localBus.next(wrapped);
20
+ return rval;
21
+ }
22
+ async fireImmediateProcessRequest(entry) {
23
+ let rval = null;
24
+ const wrapped = this.wrapEntryForInternal(entry);
25
+ rval = wrapped.guid;
26
+ Logger.info('Fire immediately (local) : %j ', entry);
27
+ this._localBus.next(wrapped);
28
+ return rval;
29
+ }
30
+ async fireStartProcessingRequest() {
31
+ let rval = null;
32
+ Logger.info('Fire start processing request (local, ignored)');
33
+ rval = 'NO-OP';
34
+ return rval;
35
+ }
36
+ async fetchApproximateNumberOfQueueEntries() {
37
+ let rval = null;
38
+ rval = 0;
39
+ return rval;
40
+ }
41
+ async takeEntryFromBackgroundQueue() {
42
+ Logger.info('Called takeEntryFromBackgroundQueue on SingleThreadedLocal - returning empty');
43
+ return [];
44
+ }
45
+ }
@@ -0,0 +1,49 @@
1
+ import { S3CacheRatchet } from '@bitblit/ratchet-aws';
2
+ import { AbstractBackgroundManager } from './manager/abstract-background-manager';
3
+ import { ErrorRatchet, Logger } from '@bitblit/ratchet-common';
4
+ export class S3BackgroundTransactionLogger {
5
+ constructor(cfg) {
6
+ this.cfg = cfg;
7
+ const err = S3BackgroundTransactionLogger.validateConfig(cfg);
8
+ if (err.length) {
9
+ ErrorRatchet.throwFormattedErr('Invalid S3BackgroundTransactionLogger config : %j', err);
10
+ }
11
+ this.s3TransactionLogCacheRatchet = new S3CacheRatchet(this.cfg.s3, this.cfg.bucket);
12
+ }
13
+ async logTransaction(txLog) {
14
+ if (txLog) {
15
+ if (txLog.request?.guid) {
16
+ await this.s3TransactionLogCacheRatchet.writeObjectToCacheFile(AbstractBackgroundManager.backgroundGuidToPath(this.cfg.prefix, txLog.request.guid), txLog);
17
+ }
18
+ else {
19
+ Logger.warn('Could not write transaction record - no guid defined : %j', txLog);
20
+ }
21
+ }
22
+ else {
23
+ Logger.silly('Skipping write of null log');
24
+ }
25
+ }
26
+ async readTransactionLog(txGuid) {
27
+ const path = AbstractBackgroundManager.backgroundGuidToPath(this.cfg.prefix, txGuid);
28
+ const log = await this.s3TransactionLogCacheRatchet.fetchCacheFileAsObject(path);
29
+ return log;
30
+ }
31
+ static validateConfig(cfg) {
32
+ const rval = [];
33
+ if (cfg) {
34
+ if (!cfg.s3) {
35
+ rval.push('You must supply an S3 object');
36
+ }
37
+ if (!cfg.bucket) {
38
+ rval.push('You must supply a bucket');
39
+ }
40
+ if (!cfg.timeToLiveDays) {
41
+ rval.push('You must supply a timeToLiveDays');
42
+ }
43
+ }
44
+ else {
45
+ rval.push('No config defined');
46
+ }
47
+ return rval;
48
+ }
49
+ }
@@ -0,0 +1,14 @@
1
+ export class RatchetEpsilonCommonInfo {
2
+ constructor() { }
3
+ static buildInformation() {
4
+ const val = {
5
+ version: '85',
6
+ hash: '7b2bd151314408f02450300b0d5fb0e008d38deb',
7
+ branch: 'alpha-2023-03-14-1',
8
+ tag: 'alpha-2023-03-14-1',
9
+ timeBuiltISO: '2023-03-14T20:58:46-0700',
10
+ notes: '',
11
+ };
12
+ return val;
13
+ }
14
+ }
@@ -0,0 +1,14 @@
1
+ import { ErrorRatchet, Logger } from '@bitblit/ratchet-common';
2
+ import { StringRatchet } from '@bitblit/ratchet-common';
3
+ export class EchoProcessor {
4
+ get typeName() {
5
+ return EchoProcessor.TYPE_NAME;
6
+ }
7
+ async handleEvent(data, mgr) {
8
+ Logger.info('Echo processing : %j', data);
9
+ if (data && StringRatchet.trimToNull(data['error'])) {
10
+ ErrorRatchet.throwFormattedErr('Forced error : %s', data['error']);
11
+ }
12
+ }
13
+ }
14
+ EchoProcessor.TYPE_NAME = 'EpsilonEcho';