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

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 +28 -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
@@ -1,213 +0,0 @@
1
- import fs from "fs";
2
- import dayjs from "dayjs";
3
- import crypto from "crypto";
4
- import ssr from "../../ssr/index.js";
5
- import { isObject } from "../../validation/lib/typeValidators";
6
- import settings from "../../settings";
7
- import generateErrorPage from "../../lib/generateErrorPage.js";
8
- import replaceFileProtocol from "../../lib/replaceFileProtocol.js";
9
- import replaceBackslashesWithForwardSlashes from "../../lib/replaceBackslashesWithForwardSlashes.js";
10
- import getBuildPath from "../../lib/getBuildPath.js";
11
- import escapeHTML from "../../lib/escapeHTML.js";
12
- import escapeKeyValuePair from "../../lib/escapeKeyValuePair.js";
13
- const generateHash = (input = "") => {
14
- return crypto.createHash("sha256").update(input).digest("hex");
15
- };
16
- const getCacheDiff = async (diffFunction = null) => {
17
- if (diffFunction) {
18
- const diff = await diffFunction();
19
- const diffHash = typeof diff === "string" ? generateHash(diff) : null;
20
- return diffHash;
21
- }
22
- return null;
23
- };
24
- const writeCacheFileToDisk = ({
25
- expiresAfterMinutes = "",
26
- cachePath = "",
27
- cacheFileName = "index",
28
- currentDiff = null,
29
- html = ""
30
- }) => {
31
- const expiresAt = dayjs().add(expiresAfterMinutes, "minutes").unix();
32
- fs.mkdir(`${cachePath}/_cache`, { recursive: true }, () => {
33
- fs.writeFile(`${cachePath}/_cache/${cacheFileName}_${expiresAt}.html`, html, (error) => {
34
- if (error) {
35
- console.warn(error);
36
- }
37
- });
38
- if (currentDiff) {
39
- fs.writeFile(`${cachePath}/_cache/diff_${expiresAt}`, currentDiff, (error) => {
40
- if (error) {
41
- console.warn(error);
42
- }
43
- });
44
- }
45
- });
46
- };
47
- const getCachedHTML = ({ cachePath, cacheFileName, currentDiff }) => {
48
- const files = fs.existsSync(`${cachePath}/_cache`) ? fs.readdirSync(`${cachePath}/_cache`) : [];
49
- const cacheFile = files?.find((file) => file?.includes(cacheFileName));
50
- const cacheFileExpiresAtUnix = cacheFile?.replace(`${cacheFileName}_`, "").replace(".html", "");
51
- const existingDiff = fs.existsSync(`${cachePath}/_cache/diff_${cacheFileExpiresAtUnix}`) ? fs.readFileSync(`${cachePath}/_cache/diff_${cacheFileExpiresAtUnix}`, "utf-8") : null;
52
- const cacheFileDiffHasChanged = existingDiff !== currentDiff;
53
- const cacheFileExpiresAtHasPassed = dayjs().isAfter(dayjs.unix(parseInt(cacheFileExpiresAtUnix)));
54
- const cacheFileHasExpired = cacheFileDiffHasChanged || cacheFileExpiresAtHasPassed;
55
- if (cacheFileDiffHasChanged || cacheFileExpiresAtHasPassed) {
56
- fs.unlink(`${cachePath}/_cache/${cacheFile}`, (error) => {
57
- if (error)
58
- return;
59
- });
60
- fs.unlink(`${cachePath}/_cache/diff_${cacheFileExpiresAtUnix}`, (error) => {
61
- if (error)
62
- return;
63
- });
64
- }
65
- return cacheFile && !cacheFileHasExpired ? fs.readFileSync(`${cachePath}/_cache/${cacheFile}`, "utf-8") : null;
66
- };
67
- const getUrl = (request = {}) => {
68
- const [path = null] = request.url?.split("?");
69
- return {
70
- params: escapeKeyValuePair(request.params),
71
- query: escapeKeyValuePair(request.query),
72
- route: escapeHTML(request.route.path),
73
- path: escapeHTML(path)
74
- };
75
- };
76
- const getFile = async (buildPath = "") => {
77
- const file = await import(buildPath);
78
- return file.default;
79
- };
80
- const getTranslationsFile = async (languageFilePath = "", paths = "") => {
81
- const languageFile = await getFile(`${paths.build}/i18n/${languageFilePath}`);
82
- const isValidLanguageFile = languageFile && isObject(languageFile);
83
- if (isValidLanguageFile) {
84
- const translationsForPage = languageFile[paths.page];
85
- return translationsForPage ? translationsForPage : languageFile;
86
- }
87
- return {};
88
- };
89
- const getTranslations = async (paths = {}, languagePreferences = []) => {
90
- const languageFiles = fs.readdirSync(`${paths.build}/i18n`);
91
- let matchingFile = null;
92
- for (let i = 0; i < languagePreferences.length; i += 1) {
93
- const languageRegex = languagePreferences[i];
94
- const match = languageFiles.find((languageFile) => !!languageFile.match(languageRegex));
95
- if (match) {
96
- matchingFile = match;
97
- break;
98
- }
99
- }
100
- const translationsFile = await getTranslationsFile(matchingFile, paths);
101
- return translationsFile;
102
- };
103
- const getLanguagePreferenceRegexes = (userLanguage = "", browserLanguages = []) => {
104
- let languagePreferences = [];
105
- if (userLanguage) {
106
- languagePreferences.push(userLanguage);
107
- }
108
- const filteredBrowserLanguages = browserLanguages?.filter((language) => {
109
- return !language?.includes("*");
110
- });
111
- languagePreferences.push(...filteredBrowserLanguages);
112
- languagePreferences.push(settings?.config?.i18n?.defaultLanguage);
113
- return languagePreferences?.flatMap((language) => {
114
- const variants = [language];
115
- if (language?.length === 2) {
116
- variants.push(`${language.substring(0, 2)}-`);
117
- }
118
- if (language?.length > 2) {
119
- variants.push(`${language?.split("-")[0]}`);
120
- variants.push(`${language?.split("-")[0]}-`);
121
- }
122
- return variants;
123
- })?.map((languageString) => {
124
- const lastCharacter = languageString[languageString.length - 1];
125
- if (lastCharacter === "-") {
126
- return new RegExp(`^${languageString}[A-Z]+.js`, "g");
127
- }
128
- return new RegExp(`^${languageString}.js`, "g");
129
- });
130
- };
131
- const parseBrowserLanguages = (languages = "") => {
132
- const rawLanguages = languages.split(",");
133
- return rawLanguages?.map((rawLanguage) => rawLanguage.split(";")[0]);
134
- };
135
- var render_default = (req, res, next, appInstance = {}) => {
136
- res.render = async function(path = "", options = {}) {
137
- const urlFormattedForCache = req?.url?.split("/")?.filter((part) => !!part)?.join("_");
138
- const buildPathForEnvironment = getBuildPath();
139
- const buildPath = replaceFileProtocol(replaceBackslashesWithForwardSlashes(`${process.cwd().replace(buildPathForEnvironment, "")}/${buildPathForEnvironment}`));
140
- const pagePath = `${buildPath}${path}`;
141
- const layoutPath = options.layout ? `${buildPath}${options.layout}` : null;
142
- const pagePathParts = `${buildPathForEnvironment}${path}`?.split("/")?.filter((part) => !!part);
143
- const cachePath = pagePathParts?.slice(0, pagePathParts.length - 1)?.join("/");
144
- let currentDiff;
145
- if (!fs.existsSync(pagePath)) {
146
- return res.status(404).send(generateErrorPage({
147
- type: "pageNotFound",
148
- path: `res.render('${path}')`,
149
- frame: null,
150
- stack: `A page component at the path ${path} could not be found.`
151
- }));
152
- }
153
- if (layoutPath && !fs.existsSync(layoutPath)) {
154
- return res.status(404).send(generateErrorPage({
155
- type: "layoutNotFound",
156
- path: `res.render('${path}', { layout: '${options.layout}' })`,
157
- frame: null,
158
- stack: `A layout component at the path ${options.layout} could not be found.`
159
- }));
160
- }
161
- if (options?.cache?.expiresAfterMinutes) {
162
- currentDiff = typeof options?.cache?.diff === "function" ? await getCacheDiff(options?.cache?.diff) : null;
163
- const cachedHTML = await getCachedHTML({
164
- cachePath,
165
- cacheFileName: urlFormattedForCache?.trim() === "" ? "index" : urlFormattedForCache,
166
- currentDiff
167
- });
168
- if (cachedHTML) {
169
- return res.send(cachedHTML);
170
- }
171
- }
172
- const pageFile = await getFile(pagePath);
173
- const Page = pageFile;
174
- const layoutFile = layoutPath ? await getFile(layoutPath) : null;
175
- const Layout = layoutFile;
176
- const browserLanguages = parseBrowserLanguages(req?.headers["accept-language"]);
177
- const languagePreferenceRegexes = getLanguagePreferenceRegexes(req?.context?.user?.language, browserLanguages);
178
- const translations = await getTranslations({ build: buildPath, page: path }, languagePreferenceRegexes);
179
- const url = getUrl(req);
180
- const props = { ...options?.props || {} };
181
- if (layoutPath && fs.existsSync(layoutPath)) {
182
- props.page = Page;
183
- }
184
- const html = await ssr({
185
- componentFunction: Layout || Page,
186
- req,
187
- props,
188
- url,
189
- translations,
190
- attributes: options?.attributes,
191
- email: false,
192
- baseHTMLPath: null,
193
- layoutComponentPath: options?.layout,
194
- pageComponentPath: path?.substring(0, 1) === "/" ? path?.replace("/", "") : path,
195
- head: options?.head,
196
- api: appInstance?.options?.api
197
- });
198
- if (options?.cache?.expiresAfterMinutes) {
199
- writeCacheFileToDisk({
200
- expiresAfterMinutes: parseInt(options?.cache?.expiresAfterMinutes),
201
- cachePath,
202
- cacheFileName: urlFormattedForCache?.trim() === "" ? "index" : urlFormattedForCache,
203
- currentDiff,
204
- html
205
- });
206
- }
207
- return res.status(200).send(html);
208
- };
209
- next();
210
- };
211
- export {
212
- render_default as default
213
- };
@@ -1,19 +0,0 @@
1
- var requestMethods_default = (req, res, next) => {
2
- const allowedMethods = [
3
- "OPTIONS",
4
- "HEAD",
5
- "CONNECT",
6
- "GET",
7
- "POST",
8
- "PUT",
9
- "DELETE",
10
- "PATCH"
11
- ];
12
- if (!allowedMethods.includes(req.method)) {
13
- res.status(405).send(`${req.method} not allowed.`);
14
- }
15
- next();
16
- };
17
- export {
18
- requestMethods_default as default
19
- };
@@ -1,45 +0,0 @@
1
- import getAPIURLComponent from "./getAPIURLComponent";
2
- import getAPIContext from "./getAPIContext";
3
- import formatAPIError from "../lib/formatAPIError";
4
- import validate from "../validation/index.js";
5
- import getOutput from "./getOutput";
6
- import sanitizeAPIResponse from "./sanitizeAPIResponse";
7
- import { isObject } from "../validation/lib/typeValidators";
8
- import validateSession from "./validateSession.js";
9
- import runGetter from "./runGetter.js";
10
- var registerGetters_default = (express, getters = [], context = {}, APIOptions = {}, appInstance = {}) => {
11
- const { app } = express;
12
- if (app) {
13
- for (const [getterName, getterOptions] of getters) {
14
- app.get(`/api/_getters/${getAPIURLComponent(getterName)}`, ...Array.isArray(getterOptions?.middleware) ? getterOptions?.middleware : [], async (req, res) => {
15
- const isValidSession = validateSession(req, res, appInstance?.sessions);
16
- if (!isValidSession) {
17
- return;
18
- }
19
- const getterContext = await getAPIContext({ req, res }, context);
20
- const input = req?.query?.input ? JSON.parse(req?.query?.input) : null;
21
- const output = req?.query?.output ? JSON.parse(req?.query?.output) : null;
22
- runGetter({
23
- getterName,
24
- getterOptions,
25
- input,
26
- output,
27
- APIOptions,
28
- context: getterContext
29
- }).then((response) => {
30
- return res.status(200).send(JSON.stringify(response));
31
- }).catch((error) => {
32
- if (typeof error === "string") {
33
- return res.status(500).send(error);
34
- }
35
- if (typeof error === "object" && !Array.isArray(error)) {
36
- return res.status(error?.errors && error?.errors[0]?.status || 400).send(JSON.stringify(error));
37
- }
38
- });
39
- });
40
- }
41
- }
42
- };
43
- export {
44
- registerGetters_default as default
45
- };
@@ -1,45 +0,0 @@
1
- import getAPIURLComponent from "./getAPIURLComponent.js";
2
- import getAPIContext from "./getAPIContext.js";
3
- import formatAPIError from "../lib/formatAPIError.js";
4
- import validate from "../validation/index.js";
5
- import getOutput from "./getOutput.js";
6
- import sanitizeAPIResponse from "./sanitizeAPIResponse.js";
7
- import { isObject } from "../validation/lib/typeValidators.js";
8
- import validateSession from "./validateSession.js";
9
- import runSetter from "./runSetter.js";
10
- var registerSetters_default = (express, setters = [], context = {}, APIOptions = {}, appInstance = {}) => {
11
- const { app } = express;
12
- if (app) {
13
- for (const [setterName, setterOptions] of setters) {
14
- app.post(`/api/_setters/${getAPIURLComponent(setterName)}`, ...Array.isArray(setterOptions?.middleware) ? setterOptions?.middleware : [], async (req, res) => {
15
- const isValidSession = validateSession(req, res, appInstance?.sessions);
16
- if (!isValidSession) {
17
- return;
18
- }
19
- const setterContext = await getAPIContext({ req, res }, context);
20
- const input = req?.body?.input || null;
21
- const output = req?.body?.output || null;
22
- runSetter({
23
- setterName,
24
- setterOptions,
25
- input,
26
- output,
27
- APIOptions,
28
- context: setterContext
29
- }).then((response) => {
30
- return res.status(200).send(JSON.stringify(response));
31
- }).catch((error) => {
32
- if (typeof error === "string") {
33
- return res.status(500).send(error);
34
- }
35
- if (typeof error === "object" && !Array.isArray(error)) {
36
- return res.status(error?.errors && error?.errors[0]?.status || 400).send(JSON.stringify(error));
37
- }
38
- });
39
- });
40
- }
41
- }
42
- };
43
- export {
44
- registerSetters_default as default
45
- };
@@ -1,103 +0,0 @@
1
- import validate from "../validation/index.js";
2
- import formatAPIError from "../lib/formatAPIError.js";
3
- import { isObject } from "../validation/lib/typeValidators.js";
4
- import getOutput from "./getOutput.js";
5
- import sanitizeAPIResponse from "./sanitizeAPIResponse.js";
6
- const handleRunGetter = async (getterOptions = {}, input = {}, output = {}, context = {}, APIOptions = {}) => {
7
- try {
8
- const shouldDisableSanitizationForGetter = getterOptions?.sanitize === false;
9
- const shouldSanitizeOutput = (getterOptions?.sanitize || APIOptions?.sanitize) === true || isObject(APIOptions?.sanitize || getterOptions?.sanitize);
10
- const data = await getterOptions?.get(input, context) || {};
11
- const response = output ? getOutput(data, output) : data;
12
- return !shouldDisableSanitizationForGetter && shouldSanitizeOutput ? sanitizeAPIResponse(response, getterOptions?.sanitize || APIOptions?.sanitize) : response;
13
- } catch (exception) {
14
- throw new Error(`[runGetter.handleRunGetter] ${exception.message}`);
15
- }
16
- };
17
- const handleRunAuthorization = async (getterOptions = {}, input = {}, context = {}) => {
18
- try {
19
- const authorization = await getterOptions?.authorized(input, context);
20
- if (typeof authorization === "boolean") {
21
- return authorization;
22
- }
23
- if (typeof authorization === "object" && !Array.isArray(authorization) && typeof authorization?.authorized !== "undefined") {
24
- return authorization?.authorized ? true : authorization?.message;
25
- }
26
- } catch (exception) {
27
- throw new Error(`[runGetter.runAuthorization] ${exception.message}`);
28
- }
29
- };
30
- const handleLogValidationErrors = (validationErrors = [], getterName = "") => {
31
- try {
32
- console.log(`Input validation for getter "${getterName}" failed with the following errors:
33
- `);
34
- for (let i = 0; i < validationErrors?.length; i += 1) {
35
- const validationError = validationErrors[i];
36
- console.log(`${i + 1}. ${validationError}`);
37
- }
38
- } catch (exception) {
39
- throw new Error(`[runGetter.handleLogValidationErrors] ${exception.message}`);
40
- }
41
- };
42
- const handleRunValidation = async (input = {}, getterOptions = {}) => {
43
- try {
44
- let validationErrors = [];
45
- if (Object.keys(getterOptions?.input || {})?.length > 0) {
46
- validationErrors = await validate.inputWithSchema(input, getterOptions.input);
47
- }
48
- return validationErrors;
49
- } catch (exception) {
50
- throw new Error(`[runGetter.runValidation] ${exception.message}`);
51
- }
52
- };
53
- const validateOptions = (options) => {
54
- try {
55
- if (!options)
56
- throw new Error("options object is required.");
57
- if (!options.getterName)
58
- throw new Error("options.getterName is required.");
59
- if (!options.getterOptions)
60
- throw new Error("options.getterOptions is required.");
61
- } catch (exception) {
62
- throw new Error(`[runGetter.validateOptions] ${exception.message}`);
63
- }
64
- };
65
- const runGetter = async (options, { resolve, reject }) => {
66
- try {
67
- validateOptions(options);
68
- if (Object?.keys(options?.getterOptions?.input || {})?.length > 0) {
69
- const validationErrors = await handleRunValidation(options?.input, options?.getterOptions);
70
- if (validationErrors?.length > 0) {
71
- handleLogValidationErrors(validationErrors, options?.getterName);
72
- return reject({
73
- errors: validationErrors.map((error) => {
74
- return formatAPIError(new Error(error), "validation", 401);
75
- })
76
- });
77
- }
78
- }
79
- if (typeof options?.getterOptions?.authorized === "function") {
80
- const authorized = await handleRunAuthorization(options?.getterOptions, options?.input, options?.context);
81
- if (!authorized || typeof authorized === "string") {
82
- return reject({
83
- errors: [
84
- formatAPIError(new Error(typeof authorized === "string" ? authorized : `Not authorized to access ${options?.getterName}.`), "authorized", 403)
85
- ]
86
- });
87
- }
88
- }
89
- if (typeof options?.getterOptions?.get === "function") {
90
- const response = await handleRunGetter(options?.getterOptions, options?.input, options?.output, options?.context, options?.APIOptions);
91
- return resolve(response);
92
- }
93
- resolve();
94
- } catch (exception) {
95
- reject(`[runGetter] ${exception.message}`);
96
- }
97
- };
98
- var runGetter_default = (options) => new Promise((resolve, reject) => {
99
- runGetter(options, { resolve, reject });
100
- });
101
- export {
102
- runGetter_default as default
103
- };
@@ -1,103 +0,0 @@
1
- import validate from "../validation/index.js";
2
- import formatAPIError from "../lib/formatAPIError.js";
3
- import { isObject } from "../validation/lib/typeValidators.js";
4
- import getOutput from "./getOutput.js";
5
- import sanitizeAPIResponse from "./sanitizeAPIResponse.js";
6
- const handleRunSetter = async (setterOptions = {}, input = {}, output = {}, context = {}, APIOptions = {}) => {
7
- try {
8
- const shouldDisableSanitizationForSetter = setterOptions?.sanitize === false;
9
- const shouldSanitizeOutput = (setterOptions?.sanitize || APIOptions?.sanitize) === true || isObject(APIOptions?.sanitize || setterOptions?.sanitize);
10
- const data = await setterOptions?.set(input, context) || {};
11
- const response = output ? getOutput(data, output) : data;
12
- return !shouldDisableSanitizationForSetter && shouldSanitizeOutput ? sanitizeAPIResponse(response, setterOptions?.sanitize || APIOptions?.sanitize) : response;
13
- } catch (exception) {
14
- throw new Error(`[runSetter.handleRunSetter] ${exception.message}`);
15
- }
16
- };
17
- const handleRunAuthorization = async (getterOptions = {}, input = {}, context = {}) => {
18
- try {
19
- const authorization = await getterOptions?.authorized(input, context);
20
- if (typeof authorization === "boolean") {
21
- return authorization;
22
- }
23
- if (typeof authorization === "object" && !Array.isArray(authorization) && typeof authorization?.authorized !== "undefined") {
24
- return authorization?.authorized ? true : authorization?.message;
25
- }
26
- } catch (exception) {
27
- throw new Error(`[runSetter.runAuthorization] ${exception.message}`);
28
- }
29
- };
30
- const handleLogValidationErrors = (validationErrors = [], setterName = "") => {
31
- try {
32
- console.log(`Input validation for setter "${setterName}" failed with the following errors:
33
- `);
34
- for (let i = 0; i < validationErrors?.length; i += 1) {
35
- const validationError = validationErrors[i];
36
- console.log(`${i + 1}. ${validationError}`);
37
- }
38
- } catch (exception) {
39
- throw new Error(`[runSetter.handleLogValidationErrors] ${exception.message}`);
40
- }
41
- };
42
- const handleRunValidation = async (input = {}, setterOptions = {}) => {
43
- try {
44
- let validationErrors = [];
45
- if (Object.keys(setterOptions?.input || {})?.length > 0) {
46
- validationErrors = await validate.inputWithSchema(input, setterOptions.input);
47
- }
48
- return validationErrors;
49
- } catch (exception) {
50
- throw new Error(`[runSetter.runValidation] ${exception.message}`);
51
- }
52
- };
53
- const validateOptions = (options) => {
54
- try {
55
- if (!options)
56
- throw new Error("options object is required.");
57
- if (!options.setterName)
58
- throw new Error("options.setterName is required.");
59
- if (!options.setterOptions)
60
- throw new Error("options.setterOptions is required.");
61
- } catch (exception) {
62
- throw new Error(`[runSetter.validateOptions] ${exception.message}`);
63
- }
64
- };
65
- const runSetter = async (options, { resolve, reject }) => {
66
- try {
67
- validateOptions(options);
68
- if (Object?.keys(options?.setterOptions?.input || {})?.length > 0) {
69
- const validationErrors = await handleRunValidation(options?.input, options?.setterOptions);
70
- if (validationErrors?.length > 0) {
71
- handleLogValidationErrors(validationErrors, options?.setterName);
72
- return reject({
73
- errors: validationErrors.map((error) => {
74
- return formatAPIError(new Error(error), `setters.${options?.setterName}.validation`, 401);
75
- })
76
- });
77
- }
78
- }
79
- if (typeof options?.setterOptions?.authorized === "function") {
80
- const authorized = await handleRunAuthorization(options?.setterOptions, options?.input, options?.context);
81
- if (!authorized || typeof authorized === "string") {
82
- return reject({
83
- errors: [
84
- formatAPIError(new Error(typeof authorized === "string" ? authorized : `Not authorized to access ${options?.setterName}.`), `setters.${options?.setterName}.authorized`, 403)
85
- ]
86
- });
87
- }
88
- }
89
- if (typeof options?.setterOptions?.set === "function") {
90
- const response = await handleRunSetter(options?.setterOptions, options?.input, options?.output, options?.context, options?.APIOptions);
91
- return resolve(response);
92
- }
93
- resolve();
94
- } catch (exception) {
95
- reject(`[runSetter] ${exception.message}`);
96
- }
97
- };
98
- var runSetter_default = (options) => new Promise((resolve, reject) => {
99
- runSetter(options, { resolve, reject });
100
- });
101
- export {
102
- runSetter_default as default
103
- };
@@ -1,143 +0,0 @@
1
- import fs from "fs";
2
- import AWS from "aws-sdk";
3
- import path from "path";
4
- import emitWebsocketEvent from "../websockets/emitWebsocketEvent";
5
- const uploadToS3 = (upload = {}, options = {}, onUploadProgress) => {
6
- try {
7
- return new Promise((resolve) => {
8
- const temporaryFilePath = `.joystick/uploads/_tmp/${upload?.fileName}`;
9
- if (!fs.existsSync(".joystick/uploads/_tmp")) {
10
- fs.mkdirSync(".joystick/uploads/_tmp", { recursive: true });
11
- }
12
- const uploadParams = {
13
- Bucket: upload?.s3?.bucket,
14
- Key: upload?.fileName,
15
- Body: upload?.content
16
- };
17
- if (upload?.fileName?.includes(".svg")) {
18
- uploadParams.ContentType = "image/svg+xml";
19
- }
20
- if (upload?.s3?.acl) {
21
- uploadParams.ACL = upload?.s3?.acl;
22
- }
23
- const s3 = new AWS.S3({
24
- accessKeyId: upload?.s3?.accessKeyId,
25
- secretAccessKey: upload?.s3?.secretAccessKey,
26
- region: upload?.s3?.region
27
- });
28
- const s3Upload = s3.upload(uploadParams, {
29
- partSize: 5 * 1024 * 1024,
30
- queueSize: 3
31
- });
32
- let previous = 0;
33
- s3Upload.on("httpUploadProgress", (s3UploadProgress) => {
34
- onUploadProgress("s3", s3UploadProgress?.loaded - previous);
35
- previous = s3UploadProgress?.loaded;
36
- });
37
- s3Upload.send((error, data) => {
38
- if (error) {
39
- console.warn(error);
40
- }
41
- fs.unlink(temporaryFilePath, () => {
42
- const response = {
43
- id: options?.req?.headers["x-joystick-upload-id"],
44
- provider: "s3",
45
- url: data?.Location,
46
- size: upload?.fileSize,
47
- fileName: upload?.fileName,
48
- originalFileName: upload?.originalFileName,
49
- mimeType: upload?.mimeType
50
- };
51
- if (error) {
52
- response.error = error?.message || "There was an error uploading your file to Amazon S3. Check the server logs for more information.";
53
- }
54
- resolve(response);
55
- });
56
- });
57
- });
58
- } catch (exception) {
59
- throw new Error(`[runUploader.uploadToS3] ${exception.message}`);
60
- }
61
- };
62
- const uploadToLocal = (upload = {}, options = {}) => {
63
- try {
64
- return new Promise((resolve) => {
65
- if (upload?.local?.path) {
66
- if (!fs.existsSync(upload?.local?.path)) {
67
- fs.mkdirSync(upload?.local?.path, { recursive: true });
68
- }
69
- const directoryPath = path.dirname(`${upload?.local?.path}/${upload?.fileName}`);
70
- if (!fs.existsSync(directoryPath)) {
71
- fs.mkdirSync(directoryPath, { recursive: true });
72
- }
73
- const filePath = `${upload?.local?.path}/${upload?.fileName}` || `./_uploads/${upload?.fileName}`;
74
- fs.writeFile(filePath, upload?.content, () => {
75
- resolve({
76
- id: options?.req?.headers["x-joystick-upload-id"],
77
- provider: "local",
78
- url: filePath,
79
- size: upload?.fileSize,
80
- fileName: upload?.fileName,
81
- originalFileName: upload?.originalFileName,
82
- mimeType: upload?.mimeType
83
- });
84
- });
85
- }
86
- });
87
- } catch (exception) {
88
- throw new Error(`[runUploader.uploadToLocal] ${exception.message}`);
89
- }
90
- };
91
- const handleUploads = async (options = {}) => {
92
- try {
93
- const uploads = [];
94
- let alreadyUploaded = options?.alreadyUploaded;
95
- const onUploadProgress = (provider = "", chunk = 0) => {
96
- const progress = alreadyUploaded + chunk;
97
- const percentage = Math.round(progress / options?.totalFileSizeAllProviders * 100);
98
- emitWebsocketEvent(`uploaders_${options?.req?.headers["x-joystick-upload-id"]}`, "progress", { provider, progress: percentage });
99
- alreadyUploaded += chunk;
100
- };
101
- for (let i = 0; i < options?.uploads?.length; i += 1) {
102
- const upload = options?.uploads[i];
103
- if (upload?.providers?.includes("local")) {
104
- const result = await uploadToLocal(upload, { ...options });
105
- uploads.push(result);
106
- }
107
- if (upload?.providers?.includes("s3")) {
108
- const result = await uploadToS3(upload, { ...options }, onUploadProgress);
109
- uploads.push(result);
110
- }
111
- }
112
- return uploads;
113
- } catch (exception) {
114
- throw new Error(`[runUploader.handleUploads] ${exception.message}`);
115
- }
116
- };
117
- const validateOptions = (options) => {
118
- try {
119
- if (!options)
120
- throw new Error("options object is required.");
121
- if (!options.uploads)
122
- throw new Error("options.uploads is required.");
123
- if (!options.req)
124
- throw new Error("options.req is required.");
125
- } catch (exception) {
126
- throw new Error(`[runUploader.validateOptions] ${exception.message}`);
127
- }
128
- };
129
- const runUploader = async (options, promise = {}) => {
130
- try {
131
- validateOptions(options);
132
- const completedUploads = await handleUploads(options);
133
- promise.resolve(completedUploads);
134
- } catch (exception) {
135
- promise.reject(exception.message);
136
- }
137
- };
138
- var runUploader_default = (options) => new Promise((resolve, reject) => {
139
- runUploader(options, { resolve, reject });
140
- });
141
- export {
142
- runUploader_default as default
143
- };