@joystick.js/node-canary 0.0.0-canary.47 → 0.0.0-canary.471

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 (439) hide show
  1. package/.build/getFilesToBuild.js +26 -0
  2. package/.build/getPlatformSafeFilePath.js +6 -0
  3. package/.build/getPlatformSafePath.js +6 -0
  4. package/.build/index.js +88 -0
  5. package/.build/isWindows.js +3 -0
  6. package/dist/action/class.js +1 -82
  7. package/dist/action/index.js +1 -8
  8. package/dist/app/accounts/default_user_output_fields.js +1 -0
  9. package/dist/app/accounts/delete_user.js +1 -0
  10. package/dist/app/accounts/generate_account_session.js +1 -0
  11. package/dist/app/accounts/generate_password_reset_token.js +1 -0
  12. package/dist/app/accounts/get_browser_safe_user.js +1 -0
  13. package/dist/app/accounts/has_login_token_expired.js +1 -0
  14. package/dist/app/accounts/index.js +1 -29
  15. package/dist/app/accounts/login.js +1 -59
  16. package/dist/app/accounts/recover_password.js +1 -0
  17. package/dist/app/accounts/reset_password.js +1 -0
  18. package/dist/app/accounts/roles/add.js +1 -7
  19. package/dist/app/accounts/roles/grant.js +1 -7
  20. package/dist/app/accounts/roles/index.js +1 -17
  21. package/dist/app/accounts/roles/list.js +1 -7
  22. package/dist/app/accounts/roles/remove.js +1 -7
  23. package/dist/app/accounts/roles/revoke.js +1 -7
  24. package/dist/app/accounts/roles/user_has_role.js +1 -0
  25. package/dist/app/accounts/send_email_verification.js +1 -0
  26. package/dist/app/accounts/set_account_cookie.js +1 -0
  27. package/dist/app/accounts/set_password.js +1 -0
  28. package/dist/app/accounts/signup.js +1 -97
  29. package/dist/app/accounts/unset_account_cookie.js +1 -0
  30. package/dist/app/accounts/verify_email.js +1 -0
  31. package/dist/app/api/accounts/authenticated.js +1 -0
  32. package/dist/app/api/accounts/login.js +1 -0
  33. package/dist/app/api/accounts/logout.js +1 -0
  34. package/dist/app/api/accounts/recover_password.js +1 -0
  35. package/dist/app/api/accounts/reset_password.js +1 -0
  36. package/dist/app/api/accounts/signup.js +1 -0
  37. package/dist/app/api/accounts/user.js +1 -0
  38. package/dist/app/api/accounts/verify_email.js +1 -0
  39. package/dist/app/api/format_api_error.js +1 -0
  40. package/dist/app/api/get.js +2 -0
  41. package/dist/app/api/get_api_context.js +1 -0
  42. package/dist/app/api/get_api_for_data_functions.js +1 -0
  43. package/dist/app/api/get_api_url_component.js +1 -0
  44. package/dist/app/api/get_output.js +1 -0
  45. package/dist/app/api/get_value_from_object.js +1 -0
  46. package/dist/app/api/handle_api_error.js +1 -0
  47. package/dist/app/api/input_validators.js +1 -0
  48. package/dist/app/api/is_array_path.js +1 -0
  49. package/dist/app/api/push/health.js +2 -0
  50. package/dist/app/api/register_getters.js +1 -0
  51. package/dist/app/api/register_setters.js +1 -0
  52. package/dist/app/api/sanitize_api_response.js +1 -0
  53. package/dist/app/api/set.js +2 -0
  54. package/dist/app/api/test/accounts/delete.js +1 -0
  55. package/dist/app/api/test/accounts/signup.js +1 -0
  56. package/dist/app/api/test/bootstrap.js +1 -0
  57. package/dist/app/api/test/process.js +1 -0
  58. package/dist/app/api/test/queues.js +1 -0
  59. package/dist/app/api/validate_input.js +1 -0
  60. package/dist/app/api/validate_session.js +1 -0
  61. package/dist/app/api/validate_type.js +1 -0
  62. package/dist/app/browser/hmr_client.js +1 -0
  63. package/dist/app/browser/process_polyfill.js +1 -0
  64. package/dist/app/cron_jobs/register.js +1 -0
  65. package/dist/app/databases/database_type_map.js +1 -0
  66. package/dist/app/databases/get_target_database_connection.js +1 -0
  67. package/dist/app/databases/mongodb/available_query_parameters.js +1 -0
  68. package/dist/app/databases/mongodb/build_connection_string.js +1 -0
  69. package/dist/app/databases/mongodb/build_query_parameters.js +1 -0
  70. package/dist/app/databases/mongodb/connect.js +6 -0
  71. package/dist/app/databases/mongodb/create_indexes.js +1 -0
  72. package/dist/app/databases/postgresql/accounts/create_accounts_metadata_table_columns.js +1 -0
  73. package/dist/app/databases/postgresql/connect.js +30 -0
  74. package/dist/app/databases/postgresql/create_indexes.js +1 -0
  75. package/dist/app/databases/postgresql/create_tables.js +1 -0
  76. package/dist/app/databases/postgresql/handle_cleanup_queues.js +5 -0
  77. package/dist/app/databases/postgresql/handle_cleanup_sessions.js +1 -0
  78. package/dist/app/databases/queries/accounts.js +1 -0
  79. package/dist/app/databases/queries/map.js +1 -0
  80. package/dist/app/databases/queries/mongodb/accounts.js +1 -0
  81. package/dist/app/databases/queries/mongodb/queues.js +1 -0
  82. package/dist/app/databases/queries/mongodb/sessions.js +1 -0
  83. package/dist/app/databases/queries/postgresql/accounts.js +1 -0
  84. package/dist/app/databases/queries/postgresql/queues.js +123 -0
  85. package/dist/app/databases/queries/postgresql/sessions.js +14 -0
  86. package/dist/app/databases/queries/sessions.js +1 -0
  87. package/dist/app/databases/register_database.js +1 -0
  88. package/dist/app/databases/sql.js +1 -0
  89. package/dist/app/email/send.js +1 -0
  90. package/dist/app/email/validate_smtp_settings.js +1 -0
  91. package/dist/app/fixture/index.js +1 -0
  92. package/dist/app/generate_machine_id.js +1 -0
  93. package/dist/app/generate_process_id.js +1 -0
  94. package/dist/app/get_ssl_certificates.js +1 -0
  95. package/dist/app/handle_process_errors.js +1 -0
  96. package/dist/app/index.js +1 -656
  97. package/dist/app/middleware/account.js +1 -0
  98. package/dist/app/middleware/body_parser.js +1 -0
  99. package/dist/app/middleware/build_error.js +1 -0
  100. package/dist/app/middleware/built_in.js +1 -0
  101. package/dist/app/middleware/context.js +1 -0
  102. package/dist/app/middleware/cors.js +1 -22
  103. package/dist/app/middleware/csp.js +1 -48
  104. package/dist/app/middleware/generate_insecure_page.js +65 -0
  105. package/dist/app/middleware/generate_joystick_error_page.js +147 -0
  106. package/dist/app/middleware/hmr_client.js +1 -0
  107. package/dist/app/middleware/insecure.js +1 -11
  108. package/dist/app/middleware/process_browser_polyfill.js +1 -0
  109. package/dist/app/middleware/render/get_url.js +1 -0
  110. package/dist/app/middleware/render/index.js +1 -0
  111. package/dist/app/middleware/request_methods.js +1 -0
  112. package/dist/app/middleware/session.js +1 -24
  113. package/dist/app/push_logs.js +1 -0
  114. package/dist/app/queues/index.js +1 -119
  115. package/dist/app/register_app_options.js +1 -0
  116. package/dist/app/routes/register_route_from_function.js +1 -0
  117. package/dist/app/routes/register_route_from_object.js +1 -0
  118. package/dist/app/routes/supported_http_methods.js +1 -0
  119. package/dist/app/settings/load.js +1 -0
  120. package/dist/app/ssr/index.js +33 -0
  121. package/dist/app/ssr/set_base_attributes_in_html.js +1 -0
  122. package/dist/app/ssr/set_head_tags_in_html.js +1 -0
  123. package/dist/app/start_express.js +1 -0
  124. package/dist/app/start_node_as_cluster.js +1 -0
  125. package/dist/app/uploaders/local_upload_progress_middleware.js +1 -0
  126. package/dist/app/uploaders/register.js +1 -0
  127. package/dist/app/uploaders/run_upload.js +1 -0
  128. package/dist/app/uploaders/validate_options.js +1 -0
  129. package/dist/app/uploaders/validate_uploads.js +1 -0
  130. package/dist/app/websockets/emit_event.js +1 -0
  131. package/dist/app/websockets/index.js +1 -0
  132. package/dist/app/websockets/register.js +1 -0
  133. package/dist/index.js +4 -76
  134. package/dist/lib/camel_pascal_to_snake.js +1 -0
  135. package/dist/lib/constants.js +1 -13
  136. package/dist/lib/dynamic_import.js +1 -0
  137. package/dist/lib/escape_html.js +1 -0
  138. package/dist/lib/escape_key_value_pair.js +1 -0
  139. package/dist/lib/float_to_decimal_place.js +1 -0
  140. package/dist/lib/generate_id.js +1 -0
  141. package/dist/lib/get_browser_safe_request.js +1 -0
  142. package/dist/lib/get_joystick_build_path.js +1 -0
  143. package/dist/lib/get_origin.js +1 -0
  144. package/dist/lib/get_platform_safe_path.js +1 -0
  145. package/dist/lib/get_sanitized_context.js +1 -0
  146. package/dist/lib/get_translations.js +1 -0
  147. package/dist/lib/hash_string.js +1 -0
  148. package/dist/lib/is_valid_json.js +1 -0
  149. package/dist/lib/log.js +13 -49
  150. package/dist/lib/node_path_polyfills.js +1 -0
  151. package/dist/lib/parse_json.js +1 -0
  152. package/dist/lib/path_exists.js +1 -0
  153. package/dist/lib/rainbow_road.js +1 -0
  154. package/dist/lib/serialize_query_parameters.js +1 -0
  155. package/dist/lib/set_cookie.js +1 -0
  156. package/dist/lib/string_to_slug.js +1 -0
  157. package/dist/lib/timestamps.js +1 -0
  158. package/dist/lib/types.js +1 -0
  159. package/dist/lib/unset_cookie.js +1 -0
  160. package/dist/lib/wait.js +1 -0
  161. package/dist/test/track_function_call.js +1 -0
  162. package/increment_version.js +3 -0
  163. package/package.json +27 -44
  164. package/src/action/class.js +137 -0
  165. package/src/action/index.js +8 -0
  166. package/src/app/accounts/default_user_output_fields.js +10 -0
  167. package/src/app/accounts/delete_user.js +18 -0
  168. package/src/app/accounts/generate_account_session.js +11 -0
  169. package/src/app/accounts/generate_password_reset_token.js +16 -0
  170. package/src/app/accounts/get_browser_safe_user.js +29 -0
  171. package/src/app/accounts/has_login_token_expired.js +9 -0
  172. package/src/app/accounts/index.js +38 -0
  173. package/src/app/accounts/login.js +82 -0
  174. package/src/app/accounts/recover_password.js +58 -0
  175. package/src/app/accounts/reset_password.js +69 -0
  176. package/src/app/accounts/roles/add.js +7 -0
  177. package/src/app/accounts/roles/grant.js +7 -0
  178. package/src/app/accounts/roles/index.js +18 -0
  179. package/src/app/accounts/roles/list.js +7 -0
  180. package/src/app/accounts/roles/remove.js +7 -0
  181. package/src/app/accounts/roles/revoke.js +7 -0
  182. package/src/app/accounts/roles/user_has_role.js +7 -0
  183. package/src/app/accounts/send_email_verification.js +48 -0
  184. package/src/app/accounts/set_account_cookie.js +12 -0
  185. package/src/app/accounts/set_password.js +46 -0
  186. package/src/app/accounts/signup.js +158 -0
  187. package/src/app/accounts/unset_account_cookie.js +12 -0
  188. package/src/app/accounts/verify_email.js +32 -0
  189. package/src/app/api/accounts/authenticated.js +17 -0
  190. package/src/app/api/accounts/login.js +36 -0
  191. package/src/app/api/accounts/logout.js +20 -0
  192. package/src/app/api/accounts/recover_password.js +16 -0
  193. package/src/app/api/accounts/reset_password.js +24 -0
  194. package/src/app/api/accounts/signup.js +49 -0
  195. package/src/app/api/accounts/user.js +21 -0
  196. package/src/app/api/accounts/verify_email.js +11 -0
  197. package/src/app/api/format_api_error.js +10 -0
  198. package/src/app/api/get.js +119 -0
  199. package/src/app/api/get_api_context.js +27 -0
  200. package/src/app/api/get_api_for_data_functions.js +37 -0
  201. package/src/app/api/get_api_url_component.js +5 -0
  202. package/src/app/api/get_output.js +116 -0
  203. package/src/app/api/get_value_from_object.js +8 -0
  204. package/src/app/api/handle_api_error.js +28 -0
  205. package/src/app/api/input_validators.js +227 -0
  206. package/src/app/api/is_array_path.js +6 -0
  207. package/src/app/api/push/health.js +17 -0
  208. package/src/app/api/register_getters.js +57 -0
  209. package/src/app/api/register_setters.js +55 -0
  210. package/src/app/api/sanitize_api_response.js +35 -0
  211. package/src/app/api/set.js +119 -0
  212. package/src/app/api/test/accounts/delete.js +8 -0
  213. package/src/app/api/test/accounts/signup.js +50 -0
  214. package/src/app/api/test/bootstrap.js +39 -0
  215. package/src/app/api/test/process.js +7 -0
  216. package/src/app/api/test/queues.js +25 -0
  217. package/src/app/api/validate_input.js +130 -0
  218. package/src/app/api/validate_session.js +20 -0
  219. package/src/app/api/validate_type.js +24 -0
  220. package/src/app/browser/hmr_client.js +196 -0
  221. package/src/app/browser/process_polyfill.js +11 -0
  222. package/src/app/cron_jobs/register.js +29 -0
  223. package/src/app/databases/database_type_map.js +6 -0
  224. package/src/app/databases/get_target_database_connection.js +25 -0
  225. package/{dist/app/databases/mongodb/availableQueryParameters.js → src/app/databases/mongodb/available_query_parameters.js} +3 -4
  226. package/src/app/databases/mongodb/build_connection_string.js +30 -0
  227. package/src/app/databases/mongodb/build_query_parameters.js +17 -0
  228. package/src/app/databases/mongodb/connect.js +42 -0
  229. package/src/app/databases/mongodb/create_indexes.js +35 -0
  230. package/src/app/databases/postgresql/accounts/create_accounts_metadata_table_columns.js +18 -0
  231. package/src/app/databases/postgresql/connect.js +128 -0
  232. package/src/app/databases/postgresql/create_indexes.js +58 -0
  233. package/src/app/databases/postgresql/create_tables.js +70 -0
  234. package/src/app/databases/postgresql/handle_cleanup_queues.js +36 -0
  235. package/src/app/databases/postgresql/handle_cleanup_sessions.js +5 -0
  236. package/src/app/databases/queries/accounts.js +17 -0
  237. package/src/app/databases/queries/map.js +21 -0
  238. package/src/app/databases/queries/mongodb/accounts.js +360 -0
  239. package/src/app/databases/queries/mongodb/queues.js +164 -0
  240. package/src/app/databases/queries/mongodb/sessions.js +22 -0
  241. package/src/app/databases/queries/postgresql/accounts.js +379 -0
  242. package/src/app/databases/queries/postgresql/queues.js +294 -0
  243. package/src/app/databases/queries/postgresql/sessions.js +37 -0
  244. package/src/app/databases/queries/sessions.js +17 -0
  245. package/src/app/databases/register_database.js +30 -0
  246. package/src/app/databases/sql.js +63 -0
  247. package/src/app/email/send.js +108 -0
  248. package/src/app/email/validate_smtp_settings.js +53 -0
  249. package/src/app/fixture/index.js +50 -0
  250. package/src/app/generate_machine_id.js +26 -0
  251. package/src/app/generate_process_id.js +30 -0
  252. package/src/app/get_ssl_certificates.js +23 -0
  253. package/src/app/handle_process_errors.js +101 -0
  254. package/src/app/index.js +253 -0
  255. package/src/app/middleware/account.js +28 -0
  256. package/src/app/middleware/body_parser.js +18 -0
  257. package/src/app/middleware/build_error.js +18 -0
  258. package/src/app/middleware/built_in.js +76 -0
  259. package/src/app/middleware/context.js +34 -0
  260. package/src/app/middleware/cors.js +23 -0
  261. package/src/app/middleware/csp.js +54 -0
  262. package/src/app/middleware/generate_insecure_page.js +71 -0
  263. package/{dist/lib/generateErrorPage.js → src/app/middleware/generate_joystick_error_page.js} +25 -21
  264. package/src/app/middleware/hmr_client.js +12 -0
  265. package/src/app/middleware/insecure.js +22 -0
  266. package/src/app/middleware/process_browser_polyfill.js +12 -0
  267. package/src/app/middleware/render/get_url.js +15 -0
  268. package/src/app/middleware/render/index.js +93 -0
  269. package/src/app/middleware/request_methods.js +21 -0
  270. package/src/app/middleware/session.js +31 -0
  271. package/src/app/push_logs.js +44 -0
  272. package/src/app/queues/index.js +268 -0
  273. package/src/app/register_app_options.js +7 -0
  274. package/src/app/routes/register_route_from_function.js +10 -0
  275. package/src/app/routes/register_route_from_object.js +34 -0
  276. package/src/app/routes/supported_http_methods.js +9 -0
  277. package/src/app/settings/load.js +33 -0
  278. package/src/app/ssr/index.js +133 -0
  279. package/src/app/ssr/set_base_attributes_in_html.js +43 -0
  280. package/src/app/ssr/set_head_tags_in_html.js +104 -0
  281. package/src/app/start_express.js +50 -0
  282. package/src/app/start_node_as_cluster.js +30 -0
  283. package/src/app/uploaders/local_upload_progress_middleware.js +24 -0
  284. package/src/app/uploaders/register.js +169 -0
  285. package/src/app/uploaders/run_upload.js +136 -0
  286. package/src/app/uploaders/validate_options.js +74 -0
  287. package/src/app/uploaders/validate_uploads.js +127 -0
  288. package/src/app/websockets/emit_event.js +14 -0
  289. package/src/app/websockets/index.js +16 -0
  290. package/src/app/websockets/register.js +175 -0
  291. package/src/index.js +81 -0
  292. package/{dist/lib/camelPascalToSnake.js → src/lib/camel_pascal_to_snake.js} +3 -4
  293. package/src/lib/constants.js +21 -0
  294. package/src/lib/dynamic_import.js +8 -0
  295. package/src/lib/escape_html.js +9 -0
  296. package/src/lib/escape_key_value_pair.js +15 -0
  297. package/src/lib/float_to_decimal_place.js +5 -0
  298. package/src/lib/generate_id.js +15 -0
  299. package/src/lib/get_browser_safe_request.js +17 -0
  300. package/src/lib/get_joystick_build_path.js +22 -0
  301. package/src/lib/get_origin.js +7 -0
  302. package/src/lib/get_platform_safe_path.js +8 -0
  303. package/src/lib/get_sanitized_context.js +51 -0
  304. package/src/lib/get_translations.js +109 -0
  305. package/src/lib/hash_string.js +7 -0
  306. package/src/lib/is_valid_json.js +10 -0
  307. package/src/lib/log.js +42 -0
  308. package/src/lib/node_path_polyfills.js +23 -0
  309. package/src/lib/parse_json.js +9 -0
  310. package/src/lib/path_exists.js +12 -0
  311. package/src/lib/rainbow_road.js +7 -0
  312. package/src/lib/serialize_query_parameters.js +7 -0
  313. package/src/lib/set_cookie.js +16 -0
  314. package/src/lib/string_to_slug.js +14 -0
  315. package/src/lib/timestamps.js +48 -0
  316. package/src/lib/types.js +59 -0
  317. package/src/lib/unset_cookie.js +11 -0
  318. package/src/lib/wait.js +9 -0
  319. package/src/test/track_function_call.js +16 -0
  320. package/README.md +0 -8
  321. package/_package.json +0 -63
  322. package/canary.js +0 -12
  323. package/dist/api/get.js +0 -29
  324. package/dist/api/getOrigin.js +0 -6
  325. package/dist/api/index.js +0 -9
  326. package/dist/api/set.js +0 -29
  327. package/dist/app/accounts/defaultUserOutputFields.js +0 -9
  328. package/dist/app/accounts/generateResetToken.js +0 -28
  329. package/dist/app/accounts/generateSession.js +0 -15
  330. package/dist/app/accounts/getBrowserSafeUser.js +0 -24
  331. package/dist/app/accounts/hasLoginTokenExpired.js +0 -17
  332. package/dist/app/accounts/hashString.js +0 -7
  333. package/dist/app/accounts/recoverPassword.js +0 -30
  334. package/dist/app/accounts/resetPassword.js +0 -73
  335. package/dist/app/accounts/roles/userHasRole.js +0 -7
  336. package/dist/app/accounts/runUserQuery.js +0 -15
  337. package/dist/app/accounts/sendEmailVerification.js +0 -65
  338. package/dist/app/accounts/setAuthenticationCookie.js +0 -11
  339. package/dist/app/accounts/setPassword.js +0 -45
  340. package/dist/app/accounts/unsetAuthenticationCookie.js +0 -11
  341. package/dist/app/accounts/verifyEmail.js +0 -46
  342. package/dist/app/databases/getTargetDatabase.js +0 -10
  343. package/dist/app/databases/getTargetDatabaseConnection.js +0 -19
  344. package/dist/app/databases/getTargetDatabaseProvider.js +0 -10
  345. package/dist/app/databases/mongodb/buildConnectionString.js +0 -22
  346. package/dist/app/databases/mongodb/buildQueryParameters.js +0 -14
  347. package/dist/app/databases/mongodb/index.js +0 -40
  348. package/dist/app/databases/mongodb/queries/accounts.js +0 -266
  349. package/dist/app/databases/mongodb/queries/queues.js +0 -111
  350. package/dist/app/databases/postgresql/addColumnToTable.js +0 -6
  351. package/dist/app/databases/postgresql/createAccountsIndexes.js +0 -21
  352. package/dist/app/databases/postgresql/createAccountsTables.js +0 -39
  353. package/dist/app/databases/postgresql/createDatabase.js +0 -0
  354. package/dist/app/databases/postgresql/index.js +0 -55
  355. package/dist/app/databases/postgresql/queries/accounts.js +0 -186
  356. package/dist/app/databases/postgresql/queries/queues.js +0 -211
  357. package/dist/app/databases/queryMap.js +0 -17
  358. package/dist/app/databases/typesMap.js +0 -7
  359. package/dist/app/getAPIContext.js +0 -25
  360. package/dist/app/getAPIURLComponent.js +0 -6
  361. package/dist/app/getBrowserSafeRequest.js +0 -14
  362. package/dist/app/getOutput.js +0 -74
  363. package/dist/app/handleProcessErrors.js +0 -73
  364. package/dist/app/initExpress.js +0 -41
  365. package/dist/app/middleware/bodyParser.js +0 -16
  366. package/dist/app/middleware/hmr/client.js +0 -113
  367. package/dist/app/middleware/index.js +0 -89
  368. package/dist/app/middleware/render.js +0 -213
  369. package/dist/app/middleware/requestMethods.js +0 -19
  370. package/dist/app/registerGetters.js +0 -45
  371. package/dist/app/registerSetters.js +0 -45
  372. package/dist/app/runGetter.js +0 -103
  373. package/dist/app/runSetter.js +0 -103
  374. package/dist/app/runUploader.js +0 -143
  375. package/dist/app/sanitizeAPIResponse.js +0 -27
  376. package/dist/app/utils/process.js +0 -193
  377. package/dist/app/validateSession.js +0 -19
  378. package/dist/app/validateUploaderOptions.js +0 -53
  379. package/dist/app/validateUploads.js +0 -102
  380. package/dist/email/render.js +0 -50
  381. package/dist/email/send.js +0 -55
  382. package/dist/email/templates/base.css +0 -194
  383. package/dist/email/templates/base.html +0 -28
  384. package/dist/email/templates/reset-password.js +0 -13
  385. package/dist/email/validateSMTPSettings.js +0 -27
  386. package/dist/lib/escapeHTML.js +0 -9
  387. package/dist/lib/escapeKeyValuePair.js +0 -13
  388. package/dist/lib/formatAPIError.js +0 -12
  389. package/dist/lib/formatErrorString.js +0 -8
  390. package/dist/lib/generateCookie.js +0 -14
  391. package/dist/lib/generateId.js +0 -13
  392. package/dist/lib/generateMachineId.js +0 -15
  393. package/dist/lib/getBuildPath.js +0 -10
  394. package/dist/lib/getErrorObject.js +0 -9
  395. package/dist/lib/getPlatformSafeFilePath.js +0 -8
  396. package/dist/lib/getPlatformSafePath.js +0 -8
  397. package/dist/lib/getSSLCertificates.js +0 -19
  398. package/dist/lib/isValidHTTPMethod.js +0 -7
  399. package/dist/lib/isValidJSONString.js +0 -11
  400. package/dist/lib/nodeUrlPolyfills.js +0 -14
  401. package/dist/lib/objectToSQLKeysString.js +0 -18
  402. package/dist/lib/objectToSQLValuesString.js +0 -16
  403. package/dist/lib/obscenedb/debounce.js +0 -12
  404. package/dist/lib/obscenedb/index.js +0 -61
  405. package/dist/lib/parseDatabasesFromEnvironment.js +0 -9
  406. package/dist/lib/rainbowRoad.js +0 -7
  407. package/dist/lib/readDirectory.js +0 -24
  408. package/dist/lib/replaceBackslashesWithForwardSlashes.js +0 -8
  409. package/dist/lib/replaceFileProtocol.js +0 -8
  410. package/dist/lib/replaceForwardSlashesWithBackslashes.js +0 -8
  411. package/dist/lib/serializeQueryParameters.js +0 -8
  412. package/dist/lib/serverAvailable.js +0 -0
  413. package/dist/lib/setCookie.js +0 -16
  414. package/dist/lib/supportedHTTPMethods.js +0 -4
  415. package/dist/lib/unsetCookie.js +0 -13
  416. package/dist/push/logs/index.js +0 -55
  417. package/dist/settings/index.js +0 -5
  418. package/dist/settings/load.js +0 -30
  419. package/dist/ssr/compileCSS.js +0 -85
  420. package/dist/ssr/findComponentInTree.js +0 -29
  421. package/dist/ssr/formatCSS.js +0 -6
  422. package/dist/ssr/getCSSFromTree.js +0 -33
  423. package/dist/ssr/index.js +0 -441
  424. package/dist/ssr/replaceWhenTags.js +0 -37
  425. package/dist/ssr/setHeadTagsInHTML.js +0 -84
  426. package/dist/validation/index.js +0 -10
  427. package/dist/validation/index.test.js +0 -463
  428. package/dist/validation/inputWithSchema/index.js +0 -105
  429. package/dist/validation/lib/constants.js +0 -162
  430. package/dist/validation/lib/getValueFromObject.js +0 -12
  431. package/dist/validation/lib/getValueFromObject.test.js +0 -7
  432. package/dist/validation/lib/isArrayPath.js +0 -6
  433. package/dist/validation/lib/throwError.js +0 -6
  434. package/dist/validation/lib/typeValidators.js +0 -38
  435. package/dist/validation/lib/validateType.js +0 -33
  436. package/dist/validation/schema/index.js +0 -44
  437. package/dist/websockets/emitWebsocketEvent.js +0 -12
  438. package/dist/websockets/index.js +0 -12
  439. package/notes +0 -1
@@ -0,0 +1,71 @@
1
+ const generate_insecure_page = (hostname = '', path = '') => {
2
+ const url = `https://${hostname}${path}`;
3
+
4
+ return `
5
+ <html>
6
+ <head>
7
+ <title>Insecure Connection</title>
8
+ <style type="text/css">
9
+ body {
10
+ font-family: "Helvetica Neue", "Helvetica", "Arial", sans-serif;
11
+ font-size: 16px;
12
+ line-height: 24px;
13
+ background: #fafafa;
14
+ display: flex;
15
+ margin: 0;
16
+ padding: 20px;
17
+ justify-content: center;
18
+ }
19
+
20
+ .warning {
21
+ width: 100%;
22
+ max-width: 500px;
23
+ background: #fff;
24
+ border: 1px solid #eee;
25
+ border-radius: 3px;
26
+ padding: 35px;
27
+ align-self: flex-start;
28
+ }
29
+
30
+ .warning h1 {
31
+ color: #000;
32
+ font-size: 22px;
33
+ line-height: 30px;
34
+ margin: 0;
35
+ }
36
+
37
+ .warning p {
38
+ font-size: 16px;
39
+ line-height: 25px;
40
+ font-weight: 400;
41
+ color: #555;
42
+ margin: 10px 0 0;
43
+ }
44
+
45
+ .warning p a {
46
+ color: #555;
47
+ }
48
+
49
+ @media screen and (min-width: 768px) {
50
+ body {
51
+ padding: 40px;
52
+ }
53
+ }
54
+ </style>
55
+ </head>
56
+ <body>
57
+ <div class="warning">
58
+ <h1>Insecure Connection<h1>
59
+ <p>The site at this URL requires an SSL-secured connection. Please visit <a href="${url}">${url}</a> instead. You will be automatically redirected in 15 seconds.</p>
60
+ </div>
61
+ <script>
62
+ setTimeout(() => {
63
+ location.href = '${url}';
64
+ }, 15 * 1000);
65
+ </script>
66
+ </body>
67
+ </html>
68
+ `;
69
+ };
70
+
71
+ export default generate_insecure_page;
@@ -1,18 +1,20 @@
1
- const getErrorTitle = (type = "build") => {
1
+ const get_error_title = (type = 'build') => {
2
2
  return {
3
- build: "Build Error",
4
- layoutNotFound: "Layout Not Found",
5
- pageNotFound: "Page Not Found"
3
+ build: 'Build Error',
4
+ layout_not_found: 'Layout Not Found',
5
+ page_not_found: 'Page Not Found'
6
6
  }[type];
7
7
  };
8
- var generateErrorPage_default = ({ type = "build", frame, path, stack }) => {
9
- const errorTitle = getErrorTitle(type);
8
+
9
+ const generate_joystick_error_page = ({ type = 'build', path, frame, stack }) => {
10
+ const error_title = get_error_title(type);
11
+
10
12
  return `
11
13
  <html>
12
14
  <head>
13
- <title>${errorTitle}</title>
15
+ <title>${error_title}</title>
14
16
  <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.2.0/styles/atom-one-dark.min.css" />
15
- <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.2.0/highlight.min.js"><\/script>
17
+ <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.2.0/highlight.min.js"></script>
16
18
  <style>
17
19
  body {
18
20
  background: #fff;
@@ -103,6 +105,10 @@ var generateErrorPage_default = ({ type = "build", frame, path, stack }) => {
103
105
  border-radius: 0px 0px 3px 3px;
104
106
  }
105
107
 
108
+ .code-block pre code.hljs {
109
+ padding: 15px 20px 20px !important;
110
+ }
111
+
106
112
  @media screen and (min-width: 768px) {
107
113
  .container {
108
114
  max-width: 728px;
@@ -125,33 +131,31 @@ var generateErrorPage_default = ({ type = "build", frame, path, stack }) => {
125
131
  width: 100%;
126
132
  }
127
133
  </style>
128
- <script src="https://kit.fontawesome.com/225f49d71f.js" crossorigin="anonymous"><\/script>
129
134
  </head>
130
135
  <body>
131
136
  <div class="container">
132
137
  <header>
133
- <h1><i class="fas fa-exclamation-triangle"></i> ${errorTitle}</h1>
134
- <h4>${type === "build" ? "in" : "at"} ${path}</h4>
135
- <p><strong>Your app is failing to build</strong>. Review the output below, correct the issue displayed, and then refresh the page:</p>
138
+ <h1>${error_title}</h1>
139
+ <h4>${type === 'build' ? 'in' : 'at'} ${path}</h4>
140
+ ${type === 'build' ? `<p><strong>Your app is failing to build</strong>. Review the output below, correct the issue displayed, and then refresh the page:</p>` : ''}
136
141
  </header>
137
142
  ${frame ? `<div class="code-block">
138
143
  <header>
139
- <h4><i class="fas fa-code"></i> Code Frame</h4>
144
+ <h4>Code Frame</h4>
140
145
  </header>
141
146
  <pre><code>${frame}</code></pre>
142
- </div>` : ""}
147
+ </div>` : ''}
143
148
  ${stack ? `<div class="code-block">
144
149
  <header>
145
- <h4><i class="fas fa-layer-group"></i> Stack Trace</h4>
150
+ <h4>Stack Trace</h4>
146
151
  </header>
147
- <pre><code class="${type !== "build" ? "language-plaintext" : ""}">${stack}</code></pre>
148
- </div>` : ""}
152
+ <pre><code class="${type !== 'build' ? 'language-plaintext' : ''}">${stack}</code></pre>
153
+ </div>` : ''}
149
154
  </div>
150
- <script>hljs.highlightAll();<\/script>
155
+ <script>hljs.highlightAll();</script>
151
156
  </body>
152
157
  </html>
153
158
  `;
154
159
  };
155
- export {
156
- generateErrorPage_default as default
157
- };
160
+
161
+ export default generate_joystick_error_page;
@@ -0,0 +1,12 @@
1
+ import fs from 'fs';
2
+ import node_path_polyfills from '../../lib/node_path_polyfills.js';
3
+
4
+ const { readFile } = fs.promises;
5
+ const hmr_client_script = await readFile(`${node_path_polyfills?.__package}/app/browser/hmr_client.js`, 'utf-8');
6
+
7
+ const hmr_client_middleware = (_req, res) => {
8
+ res.set('Content-Type', 'text/javascript');
9
+ res.send(hmr_client_script);
10
+ };
11
+
12
+ export default hmr_client_middleware;
@@ -0,0 +1,22 @@
1
+ import generate_insecure_page from './generate_insecure_page.js';
2
+
3
+ const insecure_middleware = (req, res, next) => {
4
+ /*
5
+ NOTE:
6
+
7
+ This middleware solves two problems:
8
+
9
+ 1. We're redirecting to or directly accessing an instance that *will* have https but doesn't yet.
10
+ 2. The server has SSL set up properly, but a user typed in http and we want to redirect them.
11
+
12
+ In both cases, we want to render a warning and then after 15 seconds, redirect the user to HTTPS.
13
+ */
14
+
15
+ if (!req.secure) {
16
+ return res.send(generate_insecure_page(req?.headers?.host, req?.url));
17
+ }
18
+
19
+ next();
20
+ };
21
+
22
+ export default insecure_middleware;
@@ -0,0 +1,12 @@
1
+ import fs from 'fs';
2
+ import node_path_polyfills from '../../lib/node_path_polyfills.js';
3
+
4
+ const { readFile } = fs.promises;
5
+ const polyfill = await readFile(`${node_path_polyfills.__package}/app/browser/process_polyfill.js`, 'utf-8');
6
+
7
+ const process_browser_polyfill_middleware = (_req, res) => {
8
+ res.set('Content-Type', 'text/javascript');
9
+ res.send(polyfill?.replace('${NODE_ENV}', process.env.NODE_ENV));
10
+ };
11
+
12
+ export default process_browser_polyfill_middleware;
@@ -0,0 +1,15 @@
1
+ import escape_html from "../../../lib/escape_html.js";
2
+ import escape_key_value_pair from "../../../lib/escape_key_value_pair.js";
3
+
4
+ const get_url = (request = {}) => {
5
+ const [path = null] = request.url?.split('?');
6
+
7
+ return {
8
+ params: escape_key_value_pair(request.params),
9
+ query: escape_key_value_pair(request.query),
10
+ route: escape_html(request.route.path),
11
+ path: escape_html(path),
12
+ };
13
+ };
14
+
15
+ export default get_url;
@@ -0,0 +1,93 @@
1
+ import fs from 'fs';
2
+ import dynamic_import from '../../../lib/dynamic_import.js';
3
+ import generate_joystick_error_page from '../generate_joystick_error_page.js';
4
+ import get_joystick_build_path from '../../../lib/get_joystick_build_path.js';
5
+ import get_translations from '../../../lib/get_translations.js';
6
+ import get_url from './get_url.js';
7
+ import path_exists from '../../../lib/path_exists.js';
8
+ import ssr from '../../ssr/index.js';
9
+ import get_browser_safe_request from '../../../lib/get_browser_safe_request.js';
10
+
11
+ const { readFile } = fs.promises;
12
+
13
+ const joystick_build_path = get_joystick_build_path();
14
+
15
+ const get_base_html = () => {
16
+ return readFile('index.html', 'utf-8');
17
+ };
18
+
19
+ const render_middleware = (req, res, next, app_instance = {}) => {
20
+ // NOTE: Set res.render here so we have access to req, res, and
21
+ // app_instance objects inside of the definition.
22
+ res.render = async (render_component_path = '', render_options = {}) => {
23
+ // NOTE: Safety mechanism. Don't punish a developer if the path they pass to res.render()
24
+ // has a forward slash prepended, just strip it for them.
25
+ const sanitized_render_component_path = render_component_path?.substring(0, 1) === '/' ? render_component_path?.replace('/', '') : render_component_path;
26
+ const sanitized_render_layout_path = render_options?.layout?.substring(0, 1) === '/' ? render_options?.layout?.replace('/', '') : render_options?.layout;
27
+ const component_path = `${joystick_build_path}${sanitized_render_component_path}`;
28
+ const layout_path = render_options?.layout ? `${joystick_build_path}${sanitized_render_layout_path}` : null;
29
+
30
+ if (!(await path_exists(component_path))) {
31
+ return res.status(404).send(
32
+ generate_joystick_error_page({
33
+ type: 'page_not_found',
34
+ path: `res.render('${component_path}')`,
35
+ frame: null,
36
+ stack: `A page component at the path ${component_path} could not be found.`,
37
+ })
38
+ );
39
+ }
40
+
41
+ if (layout_path && !(await path_exists(layout_path))) {
42
+ return res.status(404).send(
43
+ generate_joystick_error_page({
44
+ type: 'layout_not_found',
45
+ path: `res.render('${component_path}', { layout: '${sanitized_render_layout_path}' })`,
46
+ frame: null,
47
+ stack: `A layout component at the path ${render_options?.layout} could not be found.`,
48
+ })
49
+ );
50
+ }
51
+
52
+ const Component = await dynamic_import(`${component_path}?v=${new Date().getTime()}`);
53
+ const Layout = layout_path ? await dynamic_import(`${layout_path}?v=${new Date().getTime()}`) : null;
54
+ const props = { ...(render_options?.props || {}) };
55
+
56
+ if (layout_path) {
57
+ props.page = Component;
58
+ }
59
+
60
+ const base_html = await get_base_html();
61
+ const translations = await get_translations({
62
+ joystick_build_path,
63
+ render_component_path,
64
+ req,
65
+ });
66
+
67
+ const url = get_url(req);
68
+
69
+ const html = await ssr({
70
+ api_schema: app_instance?.options?.api,
71
+ attributes: render_options?.attributes,
72
+ base_html,
73
+ component_options: {
74
+ props,
75
+ translations,
76
+ url,
77
+ },
78
+ // NOTE: If we have a layout, we want to render that as it will have the page embedded
79
+ // via props. If not, fall back to the Component (either a page or an email template).
80
+ component_to_render: Layout || Component,
81
+ head: render_options?.head,
82
+ render_component_path: sanitized_render_component_path,
83
+ render_layout_path: sanitized_render_layout_path,
84
+ req,
85
+ });
86
+
87
+ return res.status(200).send(html);
88
+ };
89
+
90
+ next();
91
+ };
92
+
93
+ export default render_middleware;
@@ -0,0 +1,21 @@
1
+ const request_methods_middleware = (req, res, next) => {
2
+ // NOTE: Exclude TRACE and TRACK methods to avoid XST attacks.
3
+ const allowed_methods = [
4
+ "OPTIONS",
5
+ "HEAD",
6
+ "CONNECT",
7
+ "GET",
8
+ "POST",
9
+ "PUT",
10
+ "DELETE",
11
+ "PATCH",
12
+ ];
13
+
14
+ if (!allowed_methods.includes(req.method)) {
15
+ res.status(405).send(`${req.method} not allowed.`);
16
+ }
17
+
18
+ next();
19
+ };
20
+
21
+ export default request_methods_middleware;
@@ -0,0 +1,31 @@
1
+ import sessions_query from "../databases/queries/sessions.js";
2
+ import set_cookie from '../../lib/set_cookie.js';
3
+
4
+ const session_middleware = async (req, res, next) => {
5
+ let session_id = req?.cookies?.joystick_session;
6
+
7
+ const existing_session = session_id ? await sessions_query('get_session', {
8
+ session_id,
9
+ }) : null;
10
+
11
+ // NOTE: If cookie didn't exist, generate a fresh session and add it to the
12
+ // sessions database along with a new CSRF token.
13
+ if (!existing_session) {
14
+ session_id = await sessions_query('create_session');
15
+ set_cookie(res, 'joystick_session', session_id);
16
+ }
17
+
18
+ req.cookies = {
19
+ ...(req?.cookies || {}),
20
+ joystick_session: session_id,
21
+ }
22
+
23
+ req.context = {
24
+ ...(req?.context || {}),
25
+ session: await sessions_query('get_session', { session_id }),
26
+ };
27
+
28
+ next();
29
+ };
30
+
31
+ export default session_middleware;
@@ -0,0 +1,44 @@
1
+ import winston from 'winston';
2
+ import fs from 'fs';
3
+ import path_exists from '../lib/path_exists.js';
4
+
5
+ const { mkdir } = fs.promises;
6
+
7
+ const push_logs = async () => {
8
+ if (!(await path_exists('/root/push/logs'))) {
9
+ await mkdir('/root/push/logs', { recursive: true });
10
+ }
11
+
12
+ const logger = winston.createLogger({
13
+ format: winston.format.combine(
14
+ winston.format.timestamp(),
15
+ winston.format.json(),
16
+ ),
17
+ transports: [
18
+ new winston.transports.File({
19
+ filename: '/root/push/logs/app.log',
20
+ maxsize: 1024 * 1024 * 20, // 20MB,
21
+ maxFiles: 1,
22
+ tailable: true,
23
+ })
24
+ ],
25
+ });
26
+
27
+ process.stdout.write = (data) => {
28
+ logger.info(data);
29
+ };
30
+
31
+ process.stderr.write = (data) => {
32
+ logger.error(data);
33
+ };
34
+
35
+ process.on('uncaughtException', (error) => {
36
+ logger.error(error instanceof Error ? error?.toString() : error);
37
+ });
38
+
39
+ process.on('unhandledRejection', (error) => {
40
+ logger.error(error instanceof Error ? error?.toString() : error);
41
+ });
42
+ };
43
+
44
+ export default push_logs;
@@ -0,0 +1,268 @@
1
+ import chalk from "chalk";
2
+ import fs from "fs";
3
+ import os from "os";
4
+ import generate_id from "../../lib/generate_id.js";
5
+ import get_target_database_connection from "../databases/get_target_database_connection.js";
6
+ import query_map from "../databases/queries/map.js";
7
+ import timestamps from "../../lib/timestamps.js";
8
+ import types from "../../lib/types.js";
9
+ import track_function_call from '../../test/track_function_call.js';
10
+
11
+ class Queue {
12
+ constructor(queue_name = "", queue_options = {}) {
13
+ this.init_database = this.init_database.bind(this);
14
+
15
+ this.machine_id = fs
16
+ .readFileSync(`${os.homedir()}/.cheatcode/MACHINE_ID`, "utf-8")
17
+ ?.trim()
18
+ .replace(/\n/g, "");
19
+ this.name = queue_name;
20
+ this.options = {
21
+ concurrent_jobs: 1,
22
+ ...queue_options,
23
+ };
24
+
25
+ this.init_database(this?.options?.external, this?.options?.database?.provider);
26
+ }
27
+
28
+ async init_database(is_external = false, database_provider = null) {
29
+ const queues_database = database_provider || (get_target_database_connection("queues"))?.provider;
30
+ const queue_queries_for_database_provider = query_map[queues_database]?.queues;
31
+ const db = this._get_database_connection();
32
+
33
+ if (types.is_object(db) && types.is_object(queue_queries_for_database_provider)) {
34
+ this.db = Object.entries(queue_queries_for_database_provider || {})?.reduce(
35
+ (bound_queries = {}, [query_function_name, query_function]) => {
36
+ bound_queries[query_function_name] = query_function.bind({
37
+ db,
38
+ machine_id: this.machine_id,
39
+ queue: {
40
+ name: this.name,
41
+ options: this.options,
42
+ },
43
+ });
44
+
45
+ return bound_queries;
46
+ },
47
+ { _connection: db },
48
+ );
49
+
50
+ // NOTE: Let an external queue manage its own configuration and operation. We only want
51
+ // a connection to it so we can add jobs remotely.
52
+ if (!is_external) {
53
+ await this.db.initialize_database(queues_database);
54
+
55
+ if (this?.options?.runOnStartup || this?.options?.run_on_startup) {
56
+ this.run();
57
+ }
58
+ }
59
+ }
60
+ }
61
+
62
+ _get_database_connection() {
63
+ // NOTE: This applies to both external and internal databases being specified. If this is passed,
64
+ // we assume that the database exists on the process.
65
+ if (this?.options?.database) {
66
+ const { provider, name } = this?.options?.database;
67
+ const existing_connection = process.databases && process.databases[provider] && process.databases[provider][name];
68
+
69
+ if (!existing_connection) {
70
+ console.warn(chalk.red(`Connection to database ${provider}.${name} not found on process. Cannot start queue.`));
71
+ }
72
+
73
+ return existing_connection || null;
74
+ }
75
+
76
+ // NOTE: Fallback to a default which assumes a single database flagged as queues: true in the
77
+ // app's settings.<env>.json file.
78
+ return process.databases._queues;
79
+ }
80
+
81
+ async add(options = {}) {
82
+ // NOTE: If no next_run_at specified, run the job ASAP.
83
+ const next_run_at =
84
+ (options?.nextRunAt || options?.next_run_at) === "now" || (!options?.nextRunAt && !options?.next_run_at)
85
+ ? timestamps.get_future_time()
86
+ : (options?.nextRunAt || options?.next_run_at);
87
+
88
+ const job_to_add = {
89
+ _id: generate_id(16),
90
+ status: "pending",
91
+ environment: process.env.NODE_ENV,
92
+ next_run_at,
93
+ job: options?.job,
94
+ payload: options?.payload,
95
+ };
96
+
97
+ const job_definition = this?.options?.jobs && this?.options?.jobs[options?.job];
98
+
99
+ // NOTE: This doesn't work on an external queue because external queues
100
+ // do not define the job, only the remote job does. In an external setup,
101
+ // we don't have access to the queue config, only a pointer to the
102
+ // database for the queue. We opt to just add the job blindly, trusting
103
+ // that the external queue will handle validation of the job run.
104
+ if (
105
+ job_definition && (
106
+ types.is_function(job_definition?.preflight?.onBeforeAdd) ||
107
+ types.is_function(job_definition?.preflight?.on_before_add)
108
+ )
109
+ ) {
110
+ const can_add_job = await (job_definition?.preflight?.onBeforeAdd || job_definition?.preflight?.on_before_add)(
111
+ job_to_add,
112
+ this.db._connection,
113
+ `queue_${this.name}`
114
+ );
115
+
116
+ if (!can_add_job) {
117
+ return null;
118
+ }
119
+ }
120
+
121
+ this.db.add_job(job_to_add);
122
+ }
123
+
124
+ async _check_if_okay_to_run_jobs() {
125
+ const jobs_running = await this._get_number_of_jobs_running();
126
+ return jobs_running < (this.options.concurrentJobs || this.options.concurrent_jobs || 1);
127
+ }
128
+
129
+ _get_number_of_jobs_running() {
130
+ return this.db.count_jobs("running");
131
+ }
132
+
133
+ _handle_requeue_jobs_running_before_restart() {
134
+ // NOTE: If we don't want to rerun jobs that were running before restart,
135
+ // mark them as incomplete and then return.
136
+ if (!this.db) {
137
+ return;
138
+ }
139
+
140
+ if (!this.options.retryJobsRunningBeforeRestart && !this.options.retry_jobs_running_before_restart) {
141
+ return this.db.delete_incomplete_jobs_for_machine();
142
+ }
143
+
144
+ return this.db.set_jobs_for_machine_pending();
145
+ }
146
+
147
+ run() {
148
+ if (!this.db) {
149
+ return;
150
+ }
151
+
152
+ if (process.env.NODE_ENV !== 'test') {
153
+ console.log(`Starting ${this.name} queue...`);
154
+ }
155
+
156
+ this._handle_requeue_jobs_running_before_restart().then(() => {
157
+ setInterval(async () => {
158
+ // NOTE: We want to respect concurrent_jobs limit here. If we've maxed out the concurrent
159
+ // jobs limit for this queue, don't run anything until the number running is < than the
160
+ // specified concurrent_jobs threshold.
161
+ const okay_to_run_jobs = await this._check_if_okay_to_run_jobs();
162
+ if (okay_to_run_jobs && !process.env.HALT_QUEUES) {
163
+ const next_job = await this.db.get_next_job_to_run();
164
+ this.handle_next_job(next_job);
165
+ }
166
+ }, 300);
167
+ });
168
+ }
169
+
170
+ async handle_next_job(next_job = {}) {
171
+ const job_definition = this.options.jobs[next_job?.job];
172
+
173
+ if (
174
+ next_job &&
175
+ next_job?.job &&
176
+ job_definition &&
177
+ types.is_function(job_definition?.run)
178
+ ) {
179
+ try {
180
+ if (types.is_function(job_definition?.preflight?.okayToRun) || types.is_function(job_definition?.preflight?.okay_to_run)) {
181
+ const okay_to_run = await (job_definition?.preflight?.okayToRun || job_definition?.preflight?.okay_to_run)(
182
+ next_job?.payload,
183
+ next_job
184
+ );
185
+
186
+ if (!okay_to_run) {
187
+ return this._handle_requeue_job(
188
+ next_job,
189
+ timestamps.get_future_time(
190
+ 'seconds',
191
+ (job_definition?.preflight?.requeueDelayInSeconds || job_definition?.preflight?.requeue_delay_in_seconds) || 10
192
+ )
193
+ );
194
+ }
195
+ }
196
+
197
+ if (types.is_number(job_definition?.maxAttempts) || types.is_number(job_definition?.max_attempts)) {
198
+ if (next_job?.attempts >= parseInt(job_definition?.maxAttempts || job_definition?.max_attempts, 10)) {
199
+ if (
200
+ types.is_function(job_definition?.onMaxAttemptsExhausted ) ||
201
+ types.is_function(job_definition?.on_max_attempts_exhausted)
202
+ ) {
203
+ await (job_definition.onMaxAttemptsExhausted || job_definition.on_max_attempts_exhausted)(next_job);
204
+ }
205
+
206
+ return this._handle_delete_job(next_job?._id);
207
+ }
208
+ }
209
+
210
+ await this._log_attempt(next_job?._id);
211
+ track_function_call(`node.queues.${this?.name}.jobs.${next_job?.job}`, [
212
+ next_job?.payload,
213
+ ]);
214
+
215
+ await job_definition.run(next_job?.payload, {
216
+ ...next_job,
217
+ queue: this,
218
+ completed: () => this._handle_job_completed(next_job?._id),
219
+ failed: (error) => this._handle_job_failed(next_job, job_definition, error),
220
+ delete: () => this._handle_delete_job(next_job?._id),
221
+ requeue: (next_run_at = "") => this._handle_requeue_job(next_job, next_run_at),
222
+ });
223
+ } catch (exception) {
224
+ console.warn(exception);
225
+ this._handle_job_failed(next_job, job_definition, exception);
226
+ }
227
+ }
228
+ }
229
+
230
+ _log_attempt(job_id = "") {
231
+ return this.db.log_attempt(job_id);
232
+ }
233
+
234
+ _handle_job_completed(job_id = "") {
235
+ return this.db.set_job_completed(job_id);
236
+ }
237
+
238
+ _handle_job_failed(next_job = {}, job_definition = {}, error = "") {
239
+ if (job_definition?.requeueOnFailure || job_definition?.requeue_on_failure) {
240
+ return this._handle_requeue_job(
241
+ next_job,
242
+ timestamps.get_future_time('seconds', 10),
243
+ );
244
+ }
245
+
246
+ return this.db.set_job_failed(next_job?._id, error);
247
+ }
248
+
249
+ _handle_delete_job(job_id = "") {
250
+ return this.db.delete_job(job_id);
251
+ }
252
+
253
+ _handle_requeue_job(job = {}, next_run_at = null) {
254
+ return this.db.requeue_job(job?._id, next_run_at || timestamps.get_future_time());
255
+ }
256
+
257
+ list(status = "") {
258
+ const query = {};
259
+
260
+ if (status) {
261
+ query.status = status;
262
+ }
263
+
264
+ return this.db.get_jobs(query);
265
+ }
266
+ }
267
+
268
+ export default Queue;