@joystick.js/node-canary 0.0.0-canary.46 → 0.0.0-canary.461

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 (443) 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/replace_backslashes_with_forward_slashes.js +1 -0
  155. package/dist/lib/replace_file_protocol.js +1 -0
  156. package/dist/lib/serialize_query_parameters.js +1 -0
  157. package/dist/lib/set_cookie.js +1 -0
  158. package/dist/lib/string_to_slug.js +1 -0
  159. package/dist/lib/timestamps.js +1 -0
  160. package/dist/lib/types.js +1 -0
  161. package/dist/lib/unset_cookie.js +1 -0
  162. package/dist/lib/wait.js +1 -0
  163. package/dist/test/track_function_call.js +1 -0
  164. package/increment_version.js +3 -0
  165. package/package.json +27 -44
  166. package/src/action/class.js +137 -0
  167. package/src/action/index.js +8 -0
  168. package/src/app/accounts/default_user_output_fields.js +10 -0
  169. package/src/app/accounts/delete_user.js +18 -0
  170. package/src/app/accounts/generate_account_session.js +11 -0
  171. package/src/app/accounts/generate_password_reset_token.js +16 -0
  172. package/src/app/accounts/get_browser_safe_user.js +29 -0
  173. package/src/app/accounts/has_login_token_expired.js +9 -0
  174. package/src/app/accounts/index.js +38 -0
  175. package/src/app/accounts/login.js +82 -0
  176. package/src/app/accounts/recover_password.js +58 -0
  177. package/src/app/accounts/reset_password.js +69 -0
  178. package/src/app/accounts/roles/add.js +7 -0
  179. package/src/app/accounts/roles/grant.js +7 -0
  180. package/src/app/accounts/roles/index.js +18 -0
  181. package/src/app/accounts/roles/list.js +7 -0
  182. package/src/app/accounts/roles/remove.js +7 -0
  183. package/src/app/accounts/roles/revoke.js +7 -0
  184. package/src/app/accounts/roles/user_has_role.js +7 -0
  185. package/src/app/accounts/send_email_verification.js +48 -0
  186. package/src/app/accounts/set_account_cookie.js +12 -0
  187. package/src/app/accounts/set_password.js +46 -0
  188. package/src/app/accounts/signup.js +158 -0
  189. package/src/app/accounts/unset_account_cookie.js +12 -0
  190. package/src/app/accounts/verify_email.js +32 -0
  191. package/src/app/api/accounts/authenticated.js +17 -0
  192. package/src/app/api/accounts/login.js +36 -0
  193. package/src/app/api/accounts/logout.js +20 -0
  194. package/src/app/api/accounts/recover_password.js +16 -0
  195. package/src/app/api/accounts/reset_password.js +24 -0
  196. package/src/app/api/accounts/signup.js +49 -0
  197. package/src/app/api/accounts/user.js +21 -0
  198. package/src/app/api/accounts/verify_email.js +11 -0
  199. package/src/app/api/format_api_error.js +10 -0
  200. package/src/app/api/get.js +119 -0
  201. package/src/app/api/get_api_context.js +27 -0
  202. package/src/app/api/get_api_for_data_functions.js +37 -0
  203. package/src/app/api/get_api_url_component.js +5 -0
  204. package/src/app/api/get_output.js +116 -0
  205. package/src/app/api/get_value_from_object.js +8 -0
  206. package/src/app/api/handle_api_error.js +28 -0
  207. package/src/app/api/input_validators.js +227 -0
  208. package/src/app/api/is_array_path.js +6 -0
  209. package/src/app/api/push/health.js +17 -0
  210. package/src/app/api/register_getters.js +57 -0
  211. package/src/app/api/register_setters.js +55 -0
  212. package/src/app/api/sanitize_api_response.js +35 -0
  213. package/src/app/api/set.js +119 -0
  214. package/src/app/api/test/accounts/delete.js +8 -0
  215. package/src/app/api/test/accounts/signup.js +50 -0
  216. package/src/app/api/test/bootstrap.js +39 -0
  217. package/src/app/api/test/process.js +7 -0
  218. package/src/app/api/test/queues.js +25 -0
  219. package/src/app/api/validate_input.js +132 -0
  220. package/src/app/api/validate_session.js +20 -0
  221. package/src/app/api/validate_type.js +24 -0
  222. package/src/app/browser/hmr_client.js +196 -0
  223. package/src/app/browser/process_polyfill.js +11 -0
  224. package/src/app/cron_jobs/register.js +29 -0
  225. package/src/app/databases/database_type_map.js +6 -0
  226. package/src/app/databases/get_target_database_connection.js +25 -0
  227. package/{dist/app/databases/mongodb/availableQueryParameters.js → src/app/databases/mongodb/available_query_parameters.js} +3 -4
  228. package/src/app/databases/mongodb/build_connection_string.js +30 -0
  229. package/src/app/databases/mongodb/build_query_parameters.js +17 -0
  230. package/src/app/databases/mongodb/connect.js +42 -0
  231. package/src/app/databases/mongodb/create_indexes.js +35 -0
  232. package/src/app/databases/postgresql/accounts/create_accounts_metadata_table_columns.js +18 -0
  233. package/src/app/databases/postgresql/connect.js +128 -0
  234. package/src/app/databases/postgresql/create_indexes.js +58 -0
  235. package/src/app/databases/postgresql/create_tables.js +70 -0
  236. package/src/app/databases/postgresql/handle_cleanup_queues.js +36 -0
  237. package/src/app/databases/postgresql/handle_cleanup_sessions.js +5 -0
  238. package/src/app/databases/queries/accounts.js +17 -0
  239. package/src/app/databases/queries/map.js +21 -0
  240. package/src/app/databases/queries/mongodb/accounts.js +360 -0
  241. package/src/app/databases/queries/mongodb/queues.js +164 -0
  242. package/src/app/databases/queries/mongodb/sessions.js +22 -0
  243. package/src/app/databases/queries/postgresql/accounts.js +379 -0
  244. package/src/app/databases/queries/postgresql/queues.js +294 -0
  245. package/src/app/databases/queries/postgresql/sessions.js +37 -0
  246. package/src/app/databases/queries/sessions.js +17 -0
  247. package/src/app/databases/register_database.js +30 -0
  248. package/src/app/databases/sql.js +63 -0
  249. package/src/app/email/send.js +108 -0
  250. package/src/app/email/validate_smtp_settings.js +53 -0
  251. package/src/app/fixture/index.js +50 -0
  252. package/src/app/generate_machine_id.js +26 -0
  253. package/src/app/generate_process_id.js +30 -0
  254. package/src/app/get_ssl_certificates.js +23 -0
  255. package/src/app/handle_process_errors.js +101 -0
  256. package/src/app/index.js +253 -0
  257. package/src/app/middleware/account.js +28 -0
  258. package/src/app/middleware/body_parser.js +18 -0
  259. package/src/app/middleware/build_error.js +18 -0
  260. package/src/app/middleware/built_in.js +76 -0
  261. package/src/app/middleware/context.js +34 -0
  262. package/src/app/middleware/cors.js +23 -0
  263. package/src/app/middleware/csp.js +54 -0
  264. package/src/app/middleware/generate_insecure_page.js +71 -0
  265. package/{dist/lib/generateErrorPage.js → src/app/middleware/generate_joystick_error_page.js} +25 -21
  266. package/src/app/middleware/hmr_client.js +12 -0
  267. package/src/app/middleware/insecure.js +22 -0
  268. package/src/app/middleware/process_browser_polyfill.js +12 -0
  269. package/src/app/middleware/render/get_url.js +15 -0
  270. package/src/app/middleware/render/index.js +93 -0
  271. package/src/app/middleware/request_methods.js +21 -0
  272. package/src/app/middleware/session.js +31 -0
  273. package/src/app/push_logs.js +44 -0
  274. package/src/app/queues/index.js +268 -0
  275. package/src/app/register_app_options.js +7 -0
  276. package/src/app/routes/register_route_from_function.js +10 -0
  277. package/src/app/routes/register_route_from_object.js +34 -0
  278. package/src/app/routes/supported_http_methods.js +9 -0
  279. package/src/app/settings/load.js +33 -0
  280. package/src/app/ssr/index.js +133 -0
  281. package/src/app/ssr/set_base_attributes_in_html.js +43 -0
  282. package/src/app/ssr/set_head_tags_in_html.js +104 -0
  283. package/src/app/start_express.js +50 -0
  284. package/src/app/start_node_as_cluster.js +30 -0
  285. package/src/app/uploaders/local_upload_progress_middleware.js +24 -0
  286. package/src/app/uploaders/register.js +169 -0
  287. package/src/app/uploaders/run_upload.js +136 -0
  288. package/src/app/uploaders/validate_options.js +74 -0
  289. package/src/app/uploaders/validate_uploads.js +127 -0
  290. package/src/app/websockets/emit_event.js +14 -0
  291. package/src/app/websockets/index.js +16 -0
  292. package/src/app/websockets/register.js +175 -0
  293. package/src/index.js +81 -0
  294. package/{dist/lib/camelPascalToSnake.js → src/lib/camel_pascal_to_snake.js} +3 -4
  295. package/src/lib/constants.js +21 -0
  296. package/src/lib/dynamic_import.js +8 -0
  297. package/src/lib/escape_html.js +9 -0
  298. package/src/lib/escape_key_value_pair.js +15 -0
  299. package/src/lib/float_to_decimal_place.js +5 -0
  300. package/src/lib/generate_id.js +15 -0
  301. package/src/lib/get_browser_safe_request.js +17 -0
  302. package/src/lib/get_joystick_build_path.js +24 -0
  303. package/src/lib/get_origin.js +7 -0
  304. package/src/lib/get_platform_safe_path.js +8 -0
  305. package/src/lib/get_sanitized_context.js +51 -0
  306. package/src/lib/get_translations.js +111 -0
  307. package/src/lib/hash_string.js +7 -0
  308. package/src/lib/is_valid_json.js +10 -0
  309. package/src/lib/log.js +42 -0
  310. package/src/lib/node_path_polyfills.js +23 -0
  311. package/src/lib/parse_json.js +9 -0
  312. package/src/lib/path_exists.js +12 -0
  313. package/src/lib/rainbow_road.js +7 -0
  314. package/src/lib/replace_backslashes_with_forward_slashes.js +8 -0
  315. package/src/lib/replace_file_protocol.js +8 -0
  316. package/src/lib/serialize_query_parameters.js +7 -0
  317. package/src/lib/set_cookie.js +16 -0
  318. package/src/lib/string_to_slug.js +14 -0
  319. package/src/lib/timestamps.js +48 -0
  320. package/src/lib/types.js +59 -0
  321. package/src/lib/unset_cookie.js +11 -0
  322. package/src/lib/wait.js +9 -0
  323. package/src/test/track_function_call.js +16 -0
  324. package/README.md +0 -8
  325. package/_package.json +0 -54
  326. package/canary.js +0 -12
  327. package/dist/api/get.js +0 -29
  328. package/dist/api/getOrigin.js +0 -6
  329. package/dist/api/index.js +0 -9
  330. package/dist/api/set.js +0 -29
  331. package/dist/app/accounts/defaultUserOutputFields.js +0 -9
  332. package/dist/app/accounts/generateResetToken.js +0 -28
  333. package/dist/app/accounts/generateSession.js +0 -15
  334. package/dist/app/accounts/getBrowserSafeUser.js +0 -24
  335. package/dist/app/accounts/hasLoginTokenExpired.js +0 -17
  336. package/dist/app/accounts/hashString.js +0 -7
  337. package/dist/app/accounts/recoverPassword.js +0 -30
  338. package/dist/app/accounts/resetPassword.js +0 -73
  339. package/dist/app/accounts/roles/userHasRole.js +0 -7
  340. package/dist/app/accounts/runUserQuery.js +0 -15
  341. package/dist/app/accounts/sendEmailVerification.js +0 -65
  342. package/dist/app/accounts/setAuthenticationCookie.js +0 -11
  343. package/dist/app/accounts/setPassword.js +0 -45
  344. package/dist/app/accounts/unsetAuthenticationCookie.js +0 -11
  345. package/dist/app/accounts/verifyEmail.js +0 -46
  346. package/dist/app/databases/getTargetDatabase.js +0 -10
  347. package/dist/app/databases/getTargetDatabaseConnection.js +0 -19
  348. package/dist/app/databases/getTargetDatabaseProvider.js +0 -10
  349. package/dist/app/databases/mongodb/buildConnectionString.js +0 -22
  350. package/dist/app/databases/mongodb/buildQueryParameters.js +0 -14
  351. package/dist/app/databases/mongodb/index.js +0 -40
  352. package/dist/app/databases/mongodb/queries/accounts.js +0 -266
  353. package/dist/app/databases/mongodb/queries/queues.js +0 -111
  354. package/dist/app/databases/postgresql/addColumnToTable.js +0 -6
  355. package/dist/app/databases/postgresql/createAccountsIndexes.js +0 -21
  356. package/dist/app/databases/postgresql/createAccountsTables.js +0 -39
  357. package/dist/app/databases/postgresql/createDatabase.js +0 -0
  358. package/dist/app/databases/postgresql/index.js +0 -55
  359. package/dist/app/databases/postgresql/queries/accounts.js +0 -186
  360. package/dist/app/databases/postgresql/queries/queues.js +0 -211
  361. package/dist/app/databases/queryMap.js +0 -17
  362. package/dist/app/databases/typesMap.js +0 -7
  363. package/dist/app/getAPIContext.js +0 -25
  364. package/dist/app/getAPIURLComponent.js +0 -6
  365. package/dist/app/getBrowserSafeRequest.js +0 -14
  366. package/dist/app/getOutput.js +0 -74
  367. package/dist/app/handleProcessErrors.js +0 -73
  368. package/dist/app/initExpress.js +0 -41
  369. package/dist/app/middleware/bodyParser.js +0 -16
  370. package/dist/app/middleware/hmr/client.js +0 -113
  371. package/dist/app/middleware/index.js +0 -89
  372. package/dist/app/middleware/render.js +0 -213
  373. package/dist/app/middleware/requestMethods.js +0 -19
  374. package/dist/app/registerGetters.js +0 -45
  375. package/dist/app/registerSetters.js +0 -45
  376. package/dist/app/runGetter.js +0 -103
  377. package/dist/app/runSetter.js +0 -103
  378. package/dist/app/runUploader.js +0 -143
  379. package/dist/app/sanitizeAPIResponse.js +0 -27
  380. package/dist/app/utils/process.js +0 -193
  381. package/dist/app/validateSession.js +0 -16
  382. package/dist/app/validateUploaderOptions.js +0 -53
  383. package/dist/app/validateUploads.js +0 -102
  384. package/dist/email/render.js +0 -50
  385. package/dist/email/send.js +0 -55
  386. package/dist/email/templates/base.css +0 -194
  387. package/dist/email/templates/base.html +0 -28
  388. package/dist/email/templates/reset-password.js +0 -13
  389. package/dist/email/validateSMTPSettings.js +0 -27
  390. package/dist/lib/escapeHTML.js +0 -9
  391. package/dist/lib/escapeKeyValuePair.js +0 -13
  392. package/dist/lib/formatAPIError.js +0 -12
  393. package/dist/lib/formatErrorString.js +0 -8
  394. package/dist/lib/generateCookie.js +0 -14
  395. package/dist/lib/generateId.js +0 -13
  396. package/dist/lib/generateMachineId.js +0 -15
  397. package/dist/lib/getBuildPath.js +0 -10
  398. package/dist/lib/getErrorObject.js +0 -9
  399. package/dist/lib/getPlatformSafeFilePath.js +0 -8
  400. package/dist/lib/getPlatformSafePath.js +0 -8
  401. package/dist/lib/getSSLCertificates.js +0 -19
  402. package/dist/lib/isValidHTTPMethod.js +0 -7
  403. package/dist/lib/isValidJSONString.js +0 -11
  404. package/dist/lib/nodeUrlPolyfills.js +0 -14
  405. package/dist/lib/objectToSQLKeysString.js +0 -18
  406. package/dist/lib/objectToSQLValuesString.js +0 -16
  407. package/dist/lib/obscenedb/debounce.js +0 -12
  408. package/dist/lib/obscenedb/index.js +0 -61
  409. package/dist/lib/parseDatabasesFromEnvironment.js +0 -9
  410. package/dist/lib/rainbowRoad.js +0 -7
  411. package/dist/lib/readDirectory.js +0 -24
  412. package/dist/lib/replaceBackslashesWithForwardSlashes.js +0 -8
  413. package/dist/lib/replaceFileProtocol.js +0 -8
  414. package/dist/lib/replaceForwardSlashesWithBackslashes.js +0 -8
  415. package/dist/lib/serializeQueryParameters.js +0 -8
  416. package/dist/lib/serverAvailable.js +0 -0
  417. package/dist/lib/setCookie.js +0 -16
  418. package/dist/lib/supportedHTTPMethods.js +0 -4
  419. package/dist/lib/unsetCookie.js +0 -13
  420. package/dist/push/logs/index.js +0 -55
  421. package/dist/settings/index.js +0 -5
  422. package/dist/settings/load.js +0 -30
  423. package/dist/ssr/compileCSS.js +0 -85
  424. package/dist/ssr/findComponentInTree.js +0 -29
  425. package/dist/ssr/formatCSS.js +0 -6
  426. package/dist/ssr/getCSSFromTree.js +0 -33
  427. package/dist/ssr/index.js +0 -441
  428. package/dist/ssr/replaceWhenTags.js +0 -37
  429. package/dist/ssr/setHeadTagsInHTML.js +0 -84
  430. package/dist/validation/index.js +0 -10
  431. package/dist/validation/index.test.js +0 -463
  432. package/dist/validation/inputWithSchema/index.js +0 -105
  433. package/dist/validation/lib/constants.js +0 -162
  434. package/dist/validation/lib/getValueFromObject.js +0 -12
  435. package/dist/validation/lib/getValueFromObject.test.js +0 -7
  436. package/dist/validation/lib/isArrayPath.js +0 -6
  437. package/dist/validation/lib/throwError.js +0 -6
  438. package/dist/validation/lib/typeValidators.js +0 -38
  439. package/dist/validation/lib/validateType.js +0 -33
  440. package/dist/validation/schema/index.js +0 -44
  441. package/dist/websockets/emitWebsocketEvent.js +0 -12
  442. package/dist/websockets/index.js +0 -12
  443. package/notes +0 -1
package/dist/app/index.js CHANGED
@@ -1,656 +1 @@
1
- import fs from "fs";
2
- import aws from "aws-sdk";
3
- import EventEmitter from "events";
4
- import * as WebSocket from "ws";
5
- import queryString from "query-string";
6
- import multer from "multer";
7
- import cron from "node-cron";
8
- import { execSync } from "child_process";
9
- import initExpress from "./initExpress.js";
10
- import handleProcessErrors from "./handleProcessErrors";
11
- import registerGetters from "./registerGetters.js";
12
- import registerSetters from "./registerSetters.js";
13
- import connectMongoDB from "./databases/mongodb/index.js";
14
- import connectPostgreSQL from "./databases/postgresql/index.js";
15
- import accounts from "./accounts";
16
- import formatAPIError from "../lib/formatAPIError";
17
- import hasLoginTokenExpired from "./accounts/hasLoginTokenExpired.js";
18
- import { isObject } from "../validation/lib/typeValidators.js";
19
- import supportedHTTPMethods from "../lib/supportedHTTPMethods.js";
20
- import getAPIURLComponent from "./getAPIURLComponent";
21
- import validateUploaderOptions from "./validateUploaderOptions.js";
22
- import log from "../lib/log.js";
23
- import validateUploads from "./validateUploads";
24
- import runUploader from "./runUploader";
25
- import generateId from "../lib/generateId.js";
26
- import getOutput from "./getOutput.js";
27
- import defaultUserOutputFields from "./accounts/defaultUserOutputFields.js";
28
- import createPostgreSQLAccountsTables from "./databases/postgresql/createAccountsTables";
29
- import createPostgreSQLAccountsIndexes from "./databases/postgresql/createAccountsIndexes";
30
- import loadSettings from "../settings/load.js";
31
- import Queue from "./queues/index.js";
32
- import readDirectory from "../lib/readDirectory.js";
33
- import getBuildPath from "../lib/getBuildPath.js";
34
- import generateMachineId from "../lib/generateMachineId.js";
35
- import emitWebsocketEvent from "../websockets/emitWebsocketEvent.js";
36
- import getTargetDatabaseConnection from "./databases/getTargetDatabaseConnection.js";
37
- process.setMaxListeners(0);
38
- class App {
39
- constructor(options = {}) {
40
- this.setMachineId();
41
- this.setJoystickProcessId();
42
- handleProcessErrors(options?.events);
43
- const HMRSessions = JSON.parse(process.env.HMR_SESSIONS || "{}");
44
- this.sessions = new Map(HMRSessions ? Object.entries(HMRSessions) : []);
45
- this.databases = [];
46
- this.express = {};
47
- this.options = options || {};
48
- }
49
- async start(options = {}) {
50
- await this.invalidateCache();
51
- this.databases = await this.loadDatabases();
52
- this.express = initExpress(this.onStartApp, options, this);
53
- this.initWebsockets(options?.websockets || {});
54
- this.initDevelopmentRoutes();
55
- this.initAccounts();
56
- this.initDeploy();
57
- this.initAPI(options?.api);
58
- this.initRoutes(options?.routes);
59
- this.initUploaders(options?.uploaders);
60
- this.initFixtures(options?.fixtures);
61
- this.initQueues(options?.queues);
62
- this.initCronJobs(options?.cronJobs);
63
- if (process.env.NODE_ENV === "development") {
64
- process.on("message", (message) => {
65
- const parsedMessage = typeof message === "string" ? JSON.parse(message) : message;
66
- if (parsedMessage?.type === " RESTART_SERVER") {
67
- this.express?.server?.close();
68
- }
69
- });
70
- }
71
- }
72
- async invalidateCache() {
73
- const uiFiles = fs.existsSync(`${getBuildPath()}ui`) ? await readDirectory(`${getBuildPath()}ui`) : [];
74
- const cacheFiles = uiFiles?.filter((filePath) => filePath?.includes("_cache"));
75
- for (let i = 0; i < cacheFiles?.length; i += 1) {
76
- await fs.promises.unlink(cacheFiles[i]);
77
- }
78
- return Promise.resolve();
79
- }
80
- async loadDatabases(callback) {
81
- const settings = loadSettings();
82
- const hasUsersDatabase = settings?.config?.databases?.some((database = {}) => {
83
- return !!database?.users;
84
- });
85
- const hasQueuesDatabase = settings?.config?.databases?.some((database = {}) => {
86
- return !!database?.queues;
87
- });
88
- const hasPostgreSQLUsersDatabase = settings?.config?.databases?.some((database = {}) => {
89
- return database?.provider === "postgresql" && database?.users;
90
- });
91
- const databases = settings?.config?.databases?.map((database) => {
92
- return {
93
- provider: database?.provider,
94
- settings: database
95
- };
96
- });
97
- for (let databaseIndex = 0; databaseIndex < databases?.length; databaseIndex += 1) {
98
- const database = databases[databaseIndex];
99
- const hasMultipleOfProvider = databases?.filter((database2) => database2?.provider === database2?.provider)?.length > 1;
100
- const databasePort = parseInt(process.env.PORT, 10) + 10 + databaseIndex;
101
- if (database?.provider === "mongodb") {
102
- const mongodb = await connectMongoDB(database?.settings, databasePort);
103
- process.databases = {
104
- ...process.databases || {},
105
- mongodb: !hasMultipleOfProvider ? mongodb : {
106
- ...process?.databases?.mongodb || {},
107
- [database?.settings?.name || `mongodb_${databasePort}`]: mongodb
108
- }
109
- };
110
- }
111
- if (database?.provider === "postgresql") {
112
- const postgresql = await connectPostgreSQL(database?.settings, databasePort);
113
- process.databases = {
114
- ...process.databases || {},
115
- postgresql: !hasMultipleOfProvider ? {
116
- ...postgresql?.pool,
117
- query: postgresql?.query
118
- } : {
119
- ...process?.databases?.postgresql || {},
120
- [database?.settings?.name || `postgresql_${databasePort}`]: {
121
- ...postgresql?.pool,
122
- query: postgresql?.query
123
- }
124
- }
125
- };
126
- }
127
- }
128
- if (hasUsersDatabase) {
129
- process.databases._users = getTargetDatabaseConnection("users")?.connection;
130
- }
131
- if (hasQueuesDatabase) {
132
- process.databases._queues = getTargetDatabaseConnection("queues")?.connection;
133
- }
134
- if (hasPostgreSQLUsersDatabase) {
135
- await createPostgreSQLAccountsTables();
136
- await createPostgreSQLAccountsIndexes();
137
- }
138
- return process.databases;
139
- }
140
- onStartApp(express = {}) {
141
- process.on("message", (message) => {
142
- if (typeof message === "string") {
143
- process.BUILD_ERROR = JSON.parse(message);
144
- }
145
- });
146
- if (process.env.NODE_ENV !== "test") {
147
- console.log(`App running at: http://localhost:${express.port}`);
148
- }
149
- }
150
- setMachineId() {
151
- generateMachineId();
152
- }
153
- setJoystickProcessId() {
154
- if (!fs.existsSync("./.joystick")) {
155
- fs.mkdirSync("./.joystick");
156
- }
157
- if (!fs.existsSync("./.joystick/PROCESS_ID")) {
158
- fs.writeFileSync("./.joystick/PROCESS_ID", `${generateId(32)}`);
159
- }
160
- }
161
- initDeploy() {
162
- if (process.env.NODE_ENV === "production" && process.env.IS_PUSH_DEPLOYED) {
163
- this.express.app.get("/api/_push/pre-version", async (req, res) => {
164
- const instanceToken = fs.readFileSync("/root/token.txt", "utf-8");
165
- if (req?.headers["x-instance-token"] === instanceToken?.replace("\n", "")) {
166
- if (this.options?.events?.onBeforeDeployment && typeof this.options?.events?.onBeforeDeployment === "function") {
167
- await this.options.events.onBeforeDeployment(req?.query?.instance || "", req?.query?.version);
168
- return res.status(200).send("ok");
169
- }
170
- return res.status(200).send("ok");
171
- }
172
- return res.status(403).send("Sorry, you must pass a valid instance token to access this endpoint.");
173
- });
174
- this.express.app.get("/api/_push/health", async (req, res) => {
175
- const instanceToken = fs.readFileSync("/root/token.txt", "utf-8");
176
- if (req?.headers["x-instance-token"] === instanceToken?.replace("\n", "")) {
177
- return res.status(200).send("ok");
178
- }
179
- return res.status(403).send("Sorry, you must pass a valid instance token to access this endpoint.");
180
- });
181
- this.express.app.get("/api/_push/logs", async (req, res) => {
182
- const instanceToken = fs.readFileSync("/root/token.txt", "utf-8");
183
- if (req?.headers["x-instance-token"] === instanceToken?.replace("\n", "")) {
184
- const logs = execSync(`export NODE_ENV=production && instance logs${req?.query?.before ? ` --before ${req?.query?.before}` : ""}${req?.query?.after ? ` --after ${req?.query?.after}` : ""}`);
185
- return res.status(200).send(logs);
186
- }
187
- return res.status(403).send("Sorry, you must pass a valid instance token to access this endpoint.");
188
- });
189
- this.express.app.get("/api/_push/metrics", async (req, res) => {
190
- const instanceToken = fs.readFileSync("/root/token.txt", "utf-8");
191
- if (req?.headers["x-instance-token"] === instanceToken?.replace("\n", "")) {
192
- const metrics = execSync(`export NODE_ENV=production && instance metrics`);
193
- return res.status(200).send(metrics);
194
- }
195
- return res.status(403).send("Sorry, you must pass a valid instance token to access this endpoint.");
196
- });
197
- }
198
- }
199
- initAPI(api = {}) {
200
- const getters = api?.getters;
201
- const setters = api?.setters;
202
- const options = api?.options;
203
- const context = api?.context;
204
- if (getters && isObject(getters) && Object.keys(getters).length > 0) {
205
- registerGetters(this.express, Object.entries(getters), context, options, this);
206
- }
207
- if (setters && isObject(setters) && Object.keys(setters).length > 0) {
208
- registerSetters(this.express, Object.entries(setters), context, options, this);
209
- }
210
- }
211
- initRoutes(routes = {}) {
212
- Object.entries(routes).forEach(([path, callback]) => {
213
- const isObjectBasedRoute = path && callback && typeof callback === "object";
214
- const isFunctionBasedRoute = path && callback && typeof callback === "function";
215
- const method = callback?.method?.toLowerCase();
216
- const methods = callback?.methods?.map((method2) => method2?.toLowerCase());
217
- const methodsForRoute = method ? [method] : methods;
218
- const invalidMethods = isObjectBasedRoute ? methodsForRoute.filter((method2) => !supportedHTTPMethods.includes(method2)) : [];
219
- const isValidMethod = Array.isArray(methodsForRoute) && invalidMethods.length === 0;
220
- const isValidHandler = isFunctionBasedRoute && typeof callback === "function" || isObjectBasedRoute && callback && callback.handler && typeof callback.handler === "function";
221
- if (isFunctionBasedRoute && !isValidHandler) {
222
- log(`Cannot register route ${path}. When defining a route using the function-based pattern, route must be set to a function.`, {
223
- level: "danger",
224
- docs: "https://github.com/cheatcode/joystick#defining-routes"
225
- });
226
- }
227
- if (isObjectBasedRoute && !isValidHandler) {
228
- log(`Cannot register route ${path}. When defining a route using the object-based pattern, the handler property must be set to a function.`, {
229
- level: "danger",
230
- docs: "https://github.com/cheatcode/joystick#defining-routes-for-specific-http-methods"
231
- });
232
- }
233
- if (isObjectBasedRoute && invalidMethods.length > 0) {
234
- log(`Cannot register route ${path}. When defining a route using the object-based pattern, you can only set method (single HTTP method as a string) or methods (array of HTTP methods as strings), not both.`, {
235
- level: "danger",
236
- docs: "https://github.com/cheatcode/joystick#defining-routes-for-specific-http-methods"
237
- });
238
- }
239
- if (isObjectBasedRoute && method && methods) {
240
- log(`Cannot register route ${path}. When defining a route using the object-based pattern, you can only set method (single HTTP method as a string) or methods (array of HTTP methods as strings), not both.`, {
241
- level: "danger",
242
- docs: "https://github.com/cheatcode/joystick#defining-routes-for-specific-http-methods"
243
- });
244
- }
245
- if (isObjectBasedRoute && !method && !methods) {
246
- log(`Cannot register route ${path}. When defining a route using the object-based pattern, you must pass a method (single HTTP method as a string) or methods (array of HTTP methods as strings) for the route.`, {
247
- level: "danger",
248
- docs: "https://github.com/cheatcode/joystick#defining-routes-for-specific-http-methods"
249
- });
250
- }
251
- if (isObjectBasedRoute && method && !isValidMethod) {
252
- log(`Cannot register route ${path}. When defining a route using the object-based pattern, the method property must be set to a valid HTTP method: ${supportedHTTPMethods.join(", ")}.`, {
253
- level: "danger",
254
- docs: "https://github.com/cheatcode/joystick#defining-routes-for-specific-http-methods"
255
- });
256
- }
257
- if (isObjectBasedRoute && methods && !isValidMethod) {
258
- log(`Cannot register route ${path}. When defining a route using the object-based pattern, the methods property must be set to an array of valid HTTP methods: ${supportedHTTPMethods.join(", ")}.`, {
259
- level: "danger",
260
- docs: "https://github.com/cheatcode/joystick#defining-routes-for-specific-http-methods"
261
- });
262
- }
263
- if (isObjectBasedRoute && callback && !callback.handler) {
264
- log(`Cannot register route ${path}. When defining a route using the object-based pattern, the handler property must be set to a function.`, {
265
- level: "danger",
266
- docs: "https://github.com/cheatcode/joystick#defining-routes-for-specific-http-methods"
267
- });
268
- }
269
- if (isObjectBasedRoute && methodsForRoute && isValidMethod && callback && callback.handler) {
270
- methodsForRoute.forEach((method2) => {
271
- this.express.app[method2](path, ...[
272
- ...Array.isArray(callback?.middleware) ? callback?.middleware : [],
273
- async (req, res, next) => {
274
- callback.handler(Object.assign(req, {
275
- context: {
276
- ...req?.context || {},
277
- ifLoggedIn: (redirectPath = "", callback2 = null) => {
278
- if (!!req?.context?.user && redirectPath) {
279
- return res.redirect(redirectPath);
280
- }
281
- if (callback2) {
282
- return callback2();
283
- }
284
- },
285
- ifNotLoggedIn: (redirectPath = "", callback2 = null) => {
286
- if (!req?.context?.user && redirectPath) {
287
- return res.redirect(redirectPath);
288
- }
289
- if (callback2) {
290
- return callback2();
291
- }
292
- },
293
- ...process.databases || {}
294
- }
295
- }), res, next);
296
- }
297
- ]);
298
- });
299
- }
300
- if (isFunctionBasedRoute) {
301
- this.express.app.get(path, (req, res, next) => {
302
- callback(Object.assign(req, {
303
- context: {
304
- ...req?.context || {},
305
- ifLoggedIn: (redirectPath = "", callback2 = null) => {
306
- if (!!req?.context?.user && redirectPath) {
307
- return res.redirect(redirectPath);
308
- }
309
- if (callback2) {
310
- return callback2();
311
- }
312
- },
313
- ifNotLoggedIn: (redirectPath = "", callback2 = null) => {
314
- if (!req?.context?.user && redirectPath) {
315
- return res.redirect(redirectPath);
316
- }
317
- if (callback2) {
318
- return callback2();
319
- }
320
- },
321
- ...process.databases || {}
322
- }
323
- }), res, next);
324
- });
325
- }
326
- });
327
- }
328
- initWebsockets(userWebsockets = {}) {
329
- const websocketServers = {
330
- uploaders: {
331
- server: new WebSocket.WebSocketServer({
332
- noServer: true,
333
- path: "/api/_websockets/uploaders"
334
- })
335
- },
336
- ...Object.entries(userWebsockets).reduce((definitions = {}, [userWebsocketName, userWebsocketDefinition]) => {
337
- definitions[userWebsocketName] = {
338
- server: new WebSocket.WebSocketServer({
339
- noServer: true,
340
- path: `/api/_websockets/${userWebsocketName}`
341
- }),
342
- onOpen: userWebsocketDefinition?.onOpen || null,
343
- onMessage: userWebsocketDefinition?.onMessage || null,
344
- onClose: userWebsocketDefinition?.onClose || null
345
- };
346
- return definitions;
347
- }, {})
348
- };
349
- Object.entries(websocketServers).forEach(([websocketName, websocketDefinition]) => {
350
- websocketDefinition.server.on("connection", function connection(websocketConnection, connectionRequest) {
351
- try {
352
- const [_path, params] = connectionRequest?.url?.split("?");
353
- const connectionParams = queryString.parse(params);
354
- const emitter = new EventEmitter();
355
- const emitterId = connectionParams?.id ? `${websocketName}_${connectionParams?.id}` : websocketName;
356
- if (joystick?.emitters[emitterId]) {
357
- joystick.emitters[emitterId].push(emitter);
358
- } else {
359
- joystick.emitters = {
360
- ...joystick?.emitters || {},
361
- [emitterId]: [emitter]
362
- };
363
- }
364
- const connection2 = Object.assign(websocketConnection, {
365
- params: connectionParams
366
- });
367
- if (websocketDefinition?.onOpen) {
368
- websocketDefinition.onOpen(connection2);
369
- }
370
- websocketConnection.on("message", (message) => {
371
- const parsedMessage = JSON.parse(message);
372
- if (websocketDefinition.onMessage) {
373
- websocketDefinition.onMessage(parsedMessage, connection2);
374
- }
375
- });
376
- websocketConnection.on("close", (code = 0, reason = "") => {
377
- if (websocketDefinition?.onClose) {
378
- websocketDefinition.onClose(code, reason?.toString(), connection2);
379
- }
380
- });
381
- emitter.on("message", (message = {}) => {
382
- websocketConnection.send(JSON.stringify(message));
383
- });
384
- emitter.on("progress", (progress = {}) => {
385
- websocketConnection.send(JSON.stringify({ type: "PROGRESS", ...progress }));
386
- });
387
- } catch (exception) {
388
- console.warn(exception);
389
- }
390
- });
391
- });
392
- this.express.server.on("upgrade", (request, socket, head) => {
393
- if (!request?.url?.includes("/api/_websockets/")) {
394
- return;
395
- }
396
- const websocketName = (request?.url?.replace("/api/_websockets/", "").split("?") || [])[0];
397
- const websocket = websocketServers[websocketName];
398
- if (websocket) {
399
- websocket.server.handleUpgrade(request, socket, head, (socket2) => {
400
- websocket.server.emit("connection", socket2, request);
401
- });
402
- }
403
- });
404
- }
405
- initDevelopmentRoutes() {
406
- if (["development", "test"].includes(process.env.NODE_ENV)) {
407
- this.express.app.get("/api/_joystick/sessions", async (req, res) => {
408
- const sessions = Array.from(this.sessions.entries())?.reduce((acc = {}, [key, value]) => {
409
- acc[key] = value;
410
- return acc;
411
- }, {});
412
- res.status(200).send(JSON.stringify(sessions));
413
- });
414
- }
415
- }
416
- initAccounts() {
417
- this.express.app.get("/api/_accounts/authenticated", async (req, res) => {
418
- const loginTokenHasExpired = await hasLoginTokenExpired(res, req?.cookies?.joystickLoginToken, req?.cookies?.joystickLoginTokenExpiresAt);
419
- const status = !loginTokenHasExpired ? 200 : 401;
420
- return res.status(status).send(JSON.stringify({ status, authenticated: !loginTokenHasExpired }));
421
- });
422
- this.express.app.get("/api/_accounts/user", async (req, res) => {
423
- const loginTokenHasExpired = await hasLoginTokenExpired(res, req?.cookies?.joystickLoginToken, req?.cookies?.joystickLoginTokenExpiresAt);
424
- const status = !loginTokenHasExpired ? 200 : 401;
425
- const user = getOutput(req?.context?.user, req?.body?.output || defaultUserOutputFields);
426
- return res.status(status).send(JSON.stringify({ status, user }));
427
- });
428
- this.express.app.post("/api/_accounts/signup", async (req, res) => {
429
- try {
430
- const signup = await accounts.signup({
431
- emailAddress: req?.body?.emailAddress,
432
- password: req?.body?.password,
433
- metadata: req?.body?.metadata,
434
- output: req?.body?.output || defaultUserOutputFields
435
- });
436
- accounts._setAuthenticationCookie(res, {
437
- token: signup?.token,
438
- tokenExpiresAt: signup?.tokenExpiresAt
439
- });
440
- res.status(200).send(JSON.stringify(signup?.user || {}));
441
- } catch (exception) {
442
- console.log(exception);
443
- return res.status(500).send(JSON.stringify({
444
- errors: [formatAPIError(exception, "server")]
445
- }));
446
- }
447
- });
448
- this.express.app.post("/api/_accounts/login", async (req, res) => {
449
- try {
450
- const login = await accounts.login({
451
- emailAddress: req?.body?.emailAddress,
452
- username: req?.body?.username,
453
- password: req?.body?.password,
454
- output: req?.body?.output || defaultUserOutputFields
455
- });
456
- accounts._setAuthenticationCookie(res, {
457
- token: login?.token,
458
- tokenExpiresAt: login?.tokenExpiresAt
459
- });
460
- res.status(200).send(JSON.stringify(login?.user || {}));
461
- } catch (exception) {
462
- console.log(exception);
463
- return res.status(500).send(JSON.stringify({
464
- errors: [formatAPIError(exception, "server")]
465
- }));
466
- }
467
- });
468
- this.express.app.post("/api/_accounts/logout", async (req, res) => {
469
- try {
470
- this.sessions.delete(req?.context?.user?._id || req?.context?.user?.user_id);
471
- accounts._unsetAuthenticationCookie(res);
472
- res.status(200).send(JSON.stringify({}));
473
- } catch (exception) {
474
- console.log(exception);
475
- return res.status(500).send(JSON.stringify({
476
- errors: [formatAPIError(exception, "server")]
477
- }));
478
- }
479
- });
480
- this.express.app.post("/api/_accounts/recover-password", async (req, res) => {
481
- try {
482
- await accounts.recoverPassword({
483
- emailAddress: req?.body?.emailAddress
484
- });
485
- res.status(200).send(JSON.stringify({}));
486
- } catch (exception) {
487
- console.log(exception);
488
- return res.status(500).send(JSON.stringify({
489
- errors: [formatAPIError(exception, "server")]
490
- }));
491
- }
492
- });
493
- this.express.app.post("/api/_accounts/reset-password", async (req, res) => {
494
- try {
495
- const reset = await accounts.resetPassword({
496
- token: req?.body?.token,
497
- password: req?.body?.password,
498
- output: req?.body?.output || defaultUserOutputFields
499
- });
500
- accounts._setAuthenticationCookie(res, {
501
- token: reset?.token,
502
- tokenExpiresAt: reset?.tokenExpiresAt
503
- });
504
- res.status(200).send(JSON.stringify(reset?.user || {}));
505
- } catch (exception) {
506
- console.log(exception);
507
- return res.status(500).send(JSON.stringify({
508
- errors: [formatAPIError(exception, "server")]
509
- }));
510
- }
511
- });
512
- this.express.app.post("/api/_accounts/verify-email", async (req, res) => {
513
- try {
514
- await accounts.verifyEmail({
515
- token: req?.query?.token
516
- });
517
- res.redirect("/");
518
- } catch (exception) {
519
- console.log(exception);
520
- return res.status(500).send(JSON.stringify({
521
- errors: [formatAPIError(exception, "server")]
522
- }));
523
- }
524
- });
525
- }
526
- initUploaders(uploaders = {}) {
527
- const { app } = this.express;
528
- Object.entries(uploaders).forEach(([uploaderName, uploaderOptions]) => {
529
- const errors = validateUploaderOptions(uploaderOptions);
530
- if (errors?.length > 0) {
531
- log(errors, {
532
- level: "danger",
533
- docs: "https://github.com/cheatcode/joystick#uploaders"
534
- });
535
- return;
536
- }
537
- if (errors?.length === 0) {
538
- const formattedUploaderName = getAPIURLComponent(uploaderName);
539
- const upload = multer();
540
- const multerMiddleware = upload.array("files", 12);
541
- app.post(`/api/_uploaders/${formattedUploaderName}`, (req, res, next) => {
542
- let progress = 0;
543
- const fileSize = parseInt(req.headers["content-length"], 10);
544
- const providers = uploaderOptions?.providers?.includes("local") ? uploaderOptions?.providers.length : uploaderOptions?.providers?.length + 1;
545
- const totalFileSizeAllProviders = fileSize * providers;
546
- req.on("data", (chunk) => {
547
- progress += chunk.length;
548
- const percentage = Math.round(progress / totalFileSizeAllProviders * 100);
549
- emitWebsocketEvent(`uploaders_${req?.headers["x-joystick-upload-id"]}`, "progress", { provider: "uploadToServer", progress: percentage });
550
- });
551
- next();
552
- }, multerMiddleware, async (req, res) => {
553
- const input = req?.headers["x-joystick-upload-input"] ? JSON.parse(req?.headers["x-joystick-upload-input"]) : {};
554
- validateUploads({
555
- files: req?.files,
556
- input,
557
- uploaderName,
558
- uploaderOptions
559
- }).then(async (validatedUploads = []) => {
560
- if (typeof uploaderOptions?.onBeforeUpload === "function") {
561
- await uploaderOptions?.onBeforeUpload({
562
- input,
563
- req,
564
- uploads: validatedUploads
565
- });
566
- }
567
- const fileSize = parseInt(req.headers["content-length"], 10);
568
- const providers = uploaderOptions?.providers?.includes("local") ? uploaderOptions?.providers.length : uploaderOptions?.providers?.length + 1;
569
- const totalFileSizeAllProviders = fileSize * providers;
570
- const uploads = await runUploader({
571
- alreadyUploaded: fileSize,
572
- totalFileSizeAllProviders,
573
- uploads: validatedUploads,
574
- input,
575
- req
576
- });
577
- if (typeof uploaderOptions?.onAfterUpload === "function") {
578
- await uploaderOptions?.onAfterUpload({
579
- input,
580
- req,
581
- uploads
582
- });
583
- }
584
- res.status(200).send(JSON.stringify({
585
- status: 200,
586
- uploads
587
- }));
588
- }).catch((errors2) => {
589
- if (typeof errors2 === "string") {
590
- return res.status(403).send(JSON.stringify({
591
- errors: [formatAPIError(new Error(errors2))]
592
- }));
593
- }
594
- if (errors2 instanceof Error) {
595
- return res.status(403).send(JSON.stringify({
596
- errors: [formatAPIError(errors2)]
597
- }));
598
- }
599
- return res.status(403).send(JSON.stringify({
600
- errors: (errors2 || []).map((error) => {
601
- return formatAPIError(new Error(error?.message, "validation"));
602
- })
603
- }));
604
- });
605
- });
606
- }
607
- });
608
- }
609
- initFixtures(fixtures = null) {
610
- if (fixtures && typeof fixtures === "function") {
611
- fixtures();
612
- }
613
- }
614
- initQueues(queues = null) {
615
- if (queues && typeof queues === "object" && !Array.isArray(queues)) {
616
- const queueDefinitions = Object.entries(queues);
617
- for (let i = 0; i < queueDefinitions.length; i += 1) {
618
- const [queueName, queueOptions] = queueDefinitions[i];
619
- process.queues = {
620
- ...process.queues || {},
621
- [queueName]: new Queue(queueName, queueOptions)
622
- };
623
- }
624
- }
625
- }
626
- initCronJobs(cronJobs = null) {
627
- if (cronJobs && typeof cronJobs === "object" && !Array.isArray(cronJobs)) {
628
- const cronJobDefinitions = Object.entries(cronJobs);
629
- for (let i = 0; i < cronJobDefinitions.length; i += 1) {
630
- const [cronJobName, cronJobOptions] = cronJobDefinitions[i];
631
- if (cronJobOptions?.schedule && cronJobOptions?.run && typeof cronJobOptions?.run === "function") {
632
- process.cron = {
633
- ...process.queues || {},
634
- [cronJobName]: cron.schedule(cronJobOptions?.schedule, () => {
635
- if (cronJobOptions?.logAtRunTime && typeof cronJobOptions?.logAtRunTime === "string") {
636
- console.log(cronJobOptions.logAtRunTime);
637
- }
638
- cronJobOptions.run();
639
- })
640
- };
641
- }
642
- }
643
- }
644
- }
645
- }
646
- var app_default = (options = {}) => {
647
- return new Promise(async (resolve) => {
648
- const app = new App(options);
649
- await app.start(options);
650
- return resolve(app.express);
651
- });
652
- };
653
- export {
654
- App,
655
- app_default as default
656
- };
1
+ import m from"./api/accounts/authenticated.js";import h from"./api/accounts/login.js";import g from"./api/accounts/logout.js";import f from"./api/accounts/recover_password.js";import d from"./api/accounts/reset_password.js";import l from"./api/accounts/signup.js";import b from"./api/accounts/user.js";import x from"./api/accounts/verify_email.js";import j from"./api/push/health.js";import w from"./api/test/accounts/delete.js";import y from"./api/test/accounts/signup.js";import q from"./api/test/bootstrap.js";import v from"./api/test/process.js";import O from"./api/test/queues.js";import k from"./databases/mongodb/create_indexes.js";import E from"./databases/postgresql/create_indexes.js";import R from"./databases/postgresql/create_tables.js";import D from"./generate_machine_id.js";import N from"./generate_process_id.js";import _ from"./databases/get_target_database_connection.js";import I from"./handle_process_errors.js";import P from"./settings/load.js";import S from"./queues/index.js";import J from"./register_app_options.js";import L from"./cron_jobs/register.js";import U from"./databases/register_database.js";import A from"./api/register_getters.js";import B from"./routes/register_route_from_function.js";import V from"./routes/register_route_from_object.js";import H from"./api/register_setters.js";import Q from"./uploaders/register.js";import T from"./websockets/register.js";import Y from"./start_express.js";import $ from"./start_node_as_cluster.js";import p from"../lib/types.js";import z from"./push_logs.js";const C=P();process.env.NODE_ENV!=="development"&&process.env.IS_PUSH_DEPLOYED&&z();class F{constructor(t={}){I(t?.events),J(this,t),this.generate_machine_id(),this.generate_process_id(),process.title=process.env.NODE_ENV==="test"?"joystick_test_app":"joystick_app",process.joystick={app_options:t}}async connect_databases(){const t=C?.config?.databases;for(let s=0;s<t?.length;s+=1){const e=t[s],r=parseInt(process.env.PORT,10)+10+s,a=t?.filter(n=>e?.provider===n?.provider)?.length>1;await U(e,r,a)}if(t?.length>0){const s=_("queues"),e=_("sessions"),r=_("users");process.databases._queues=s?.connection,process.databases._sessions=e?.connection,process.databases._users=r?.connection;const a=[s,e,r],n=a?.filter(i=>i?.provider==="mongodb")?.map(i=>i?.database_type);await k(n);const c=a?.filter(i=>i?.provider==="postgresql")?.map(i=>i?.database_type);await R(c),await E(c)}}async generate_machine_id(){this.joystick_machine_id=await D()}async generate_process_id(){this.joystick_process_id=await N()}on_after_start_server(t={}){process.on("message",s=>{typeof s=="string"&&JSON.parse(s)?.type==="BUILD_ERROR"&&(process.BUILD_ERROR=JSON.parse(s))}),console.log(`App running at: http://localhost:${t.port}`)}register_accounts(){this.express.app.get("/api/_accounts/authenticated",m),this.express.app.post("/api/_accounts/user",b),this.express.app.post("/api/_accounts/login",h),this.express.app.post("/api/_accounts/logout",g),this.express.app.post("/api/_accounts/recover-password",f),this.express.app.post("/api/_accounts/reset-password",d),this.express.app.post("/api/_accounts/signup",l),this.express.app.post("/api/_accounts/verify-email",x)}register_api(){const t=this?.options?.api?.getters,s=this?.options?.api?.setters,e=this?.options?.api?.options,r=this?.options?.api?.context;t&&p.is_object(t)&&Object.keys(t||{}).length>0&&A(this.express.app,Object.entries(t||{}),r,e),s&&p.is_object(s)&&Object.keys(s||{}).length>0&&H(this.express.app,Object.entries(s||{}),r,e)}register_cron_jobs(){L(this.options.cronJobs||this.options.cron_jobs)}register_fixtures(){p.is_function(this.options.fixtures)&&this.options.fixtures()}register_indexes(){p.is_function(this.options.indexes)&&this.options.indexes()}register_push(){this.express.app.get("/api/_push/health",j)}register_queues(){if(p.is_object(this.options.queues)){const t=Object.entries(this.options.queues||{});for(let s=0;s<t.length;s+=1){const[e,r]=t[s];process.queues={...process.queues||{},[e]:new S(e,r)}}}}register_routes(){const t=Object.entries(this?.options?.routes||{});for(let s=0;s<t?.length;s+=1){const[e,r]=t[s],a=p.is_object(r);p.is_function(r)&&B(this.express.app,e,r),a&&V(this.express.app,e,r)}}register_tests(){this.express.app.get("/api/_test/bootstrap",(t={},s={})=>q(t,s,this)),this.express.app.get("/api/_test/process",v),this.express.app.delete("/api/_test/accounts",w),this.express.app.post("/api/_test/accounts/signup",y),this.express.app.post("/api/_test/queues",(t={},s={})=>O(t,s,this))}register_uploaders(){Q(this.options.uploaders,this)}register_websockets(){T(this.options.websockets,this)}async start(){await this.connect_databases(),this.register_cron_jobs(),this.register_queues(),this.start_express(),this.register_tests(),this.register_accounts(),this.register_push(),this.register_api(),this.register_routes(),this.register_websockets(),this.register_uploaders(),this.register_fixtures(),this.register_indexes()}start_express(){this.express=Y(this.on_after_start_server,this)}}const u=async(o={})=>{const t=new F(o);return await t.start(o),t},G=(o={})=>new Promise(async t=>{if(o?.cluster)$(async()=>{const s=await u(o);return t(s.express)});else{const s=await u(o);return t(s.express)}});var Is=G;export{Is as default};
@@ -0,0 +1 @@
1
+ import _ from"../databases/queries/accounts.js";import c from"../accounts/has_login_token_expired.js";import s from"../accounts/unset_account_cookie.js";const k=async(o,t,i)=>{const n=c(t,o?.cookies?.joystick_login_token,o?.cookies?.joystick_login_token_expires_at);n&&s(t);const e=n?null:await _("user_with_login_token",{token:o?.cookies?.joystick_login_token});o.context={...o?.context||{},user:e},i()};var u=k;export{u as default};
@@ -0,0 +1 @@
1
+ import d from"express";const p=(r={})=>(e,t,n)=>{const o=e.headers["content-type"];return o&&o==="application/x-www-form-urlencoded"?d.urlencoded({extended:!0,...r?.urlencoded||{}})(e,t,n):d.json(r?.json)(e,t,n)};var c=p;export{c as default};
@@ -0,0 +1 @@
1
+ import t from"./generate_joystick_error_page.js";const p=(a,e,o)=>{if(process.BUILD_ERROR){const r=process.BUILD_ERROR.paths&&process.BUILD_ERROR.paths[0],s=t({path:r.path,stack:r.error.stack,frame:r.error.snippet});return e.send(s)}o()};var c=p;export{c as default};