@joystick.js/node-canary 0.0.0-canary.47 → 0.0.0-canary.470
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.build/getFilesToBuild.js +26 -0
- package/.build/getPlatformSafeFilePath.js +6 -0
- package/.build/getPlatformSafePath.js +6 -0
- package/.build/index.js +88 -0
- package/.build/isWindows.js +3 -0
- package/dist/action/class.js +1 -82
- package/dist/action/index.js +1 -8
- package/dist/app/accounts/default_user_output_fields.js +1 -0
- package/dist/app/accounts/delete_user.js +1 -0
- package/dist/app/accounts/generate_account_session.js +1 -0
- package/dist/app/accounts/generate_password_reset_token.js +1 -0
- package/dist/app/accounts/get_browser_safe_user.js +1 -0
- package/dist/app/accounts/has_login_token_expired.js +1 -0
- package/dist/app/accounts/index.js +1 -29
- package/dist/app/accounts/login.js +1 -59
- package/dist/app/accounts/recover_password.js +1 -0
- package/dist/app/accounts/reset_password.js +1 -0
- package/dist/app/accounts/roles/add.js +1 -7
- package/dist/app/accounts/roles/grant.js +1 -7
- package/dist/app/accounts/roles/index.js +1 -17
- package/dist/app/accounts/roles/list.js +1 -7
- package/dist/app/accounts/roles/remove.js +1 -7
- package/dist/app/accounts/roles/revoke.js +1 -7
- package/dist/app/accounts/roles/user_has_role.js +1 -0
- package/dist/app/accounts/send_email_verification.js +1 -0
- package/dist/app/accounts/set_account_cookie.js +1 -0
- package/dist/app/accounts/set_password.js +1 -0
- package/dist/app/accounts/signup.js +1 -97
- package/dist/app/accounts/unset_account_cookie.js +1 -0
- package/dist/app/accounts/verify_email.js +1 -0
- package/dist/app/api/accounts/authenticated.js +1 -0
- package/dist/app/api/accounts/login.js +1 -0
- package/dist/app/api/accounts/logout.js +1 -0
- package/dist/app/api/accounts/recover_password.js +1 -0
- package/dist/app/api/accounts/reset_password.js +1 -0
- package/dist/app/api/accounts/signup.js +1 -0
- package/dist/app/api/accounts/user.js +1 -0
- package/dist/app/api/accounts/verify_email.js +1 -0
- package/dist/app/api/format_api_error.js +1 -0
- package/dist/app/api/get.js +2 -0
- package/dist/app/api/get_api_context.js +1 -0
- package/dist/app/api/get_api_for_data_functions.js +1 -0
- package/dist/app/api/get_api_url_component.js +1 -0
- package/dist/app/api/get_output.js +1 -0
- package/dist/app/api/get_value_from_object.js +1 -0
- package/dist/app/api/handle_api_error.js +1 -0
- package/dist/app/api/input_validators.js +1 -0
- package/dist/app/api/is_array_path.js +1 -0
- package/dist/app/api/push/health.js +2 -0
- package/dist/app/api/register_getters.js +1 -0
- package/dist/app/api/register_setters.js +1 -0
- package/dist/app/api/sanitize_api_response.js +1 -0
- package/dist/app/api/set.js +2 -0
- package/dist/app/api/test/accounts/delete.js +1 -0
- package/dist/app/api/test/accounts/signup.js +1 -0
- package/dist/app/api/test/bootstrap.js +1 -0
- package/dist/app/api/test/process.js +1 -0
- package/dist/app/api/test/queues.js +1 -0
- package/dist/app/api/validate_input.js +1 -0
- package/dist/app/api/validate_session.js +1 -0
- package/dist/app/api/validate_type.js +1 -0
- package/dist/app/browser/hmr_client.js +1 -0
- package/dist/app/browser/process_polyfill.js +1 -0
- package/dist/app/cron_jobs/register.js +1 -0
- package/dist/app/databases/database_type_map.js +1 -0
- package/dist/app/databases/get_target_database_connection.js +1 -0
- package/dist/app/databases/mongodb/available_query_parameters.js +1 -0
- package/dist/app/databases/mongodb/build_connection_string.js +1 -0
- package/dist/app/databases/mongodb/build_query_parameters.js +1 -0
- package/dist/app/databases/mongodb/connect.js +6 -0
- package/dist/app/databases/mongodb/create_indexes.js +1 -0
- package/dist/app/databases/postgresql/accounts/create_accounts_metadata_table_columns.js +1 -0
- package/dist/app/databases/postgresql/connect.js +30 -0
- package/dist/app/databases/postgresql/create_indexes.js +1 -0
- package/dist/app/databases/postgresql/create_tables.js +1 -0
- package/dist/app/databases/postgresql/handle_cleanup_queues.js +5 -0
- package/dist/app/databases/postgresql/handle_cleanup_sessions.js +1 -0
- package/dist/app/databases/queries/accounts.js +1 -0
- package/dist/app/databases/queries/map.js +1 -0
- package/dist/app/databases/queries/mongodb/accounts.js +1 -0
- package/dist/app/databases/queries/mongodb/queues.js +1 -0
- package/dist/app/databases/queries/mongodb/sessions.js +1 -0
- package/dist/app/databases/queries/postgresql/accounts.js +1 -0
- package/dist/app/databases/queries/postgresql/queues.js +123 -0
- package/dist/app/databases/queries/postgresql/sessions.js +14 -0
- package/dist/app/databases/queries/sessions.js +1 -0
- package/dist/app/databases/register_database.js +1 -0
- package/dist/app/databases/sql.js +1 -0
- package/dist/app/email/send.js +1 -0
- package/dist/app/email/validate_smtp_settings.js +1 -0
- package/dist/app/fixture/index.js +1 -0
- package/dist/app/generate_machine_id.js +1 -0
- package/dist/app/generate_process_id.js +1 -0
- package/dist/app/get_ssl_certificates.js +1 -0
- package/dist/app/handle_process_errors.js +1 -0
- package/dist/app/index.js +1 -656
- package/dist/app/middleware/account.js +1 -0
- package/dist/app/middleware/body_parser.js +1 -0
- package/dist/app/middleware/build_error.js +1 -0
- package/dist/app/middleware/built_in.js +1 -0
- package/dist/app/middleware/context.js +1 -0
- package/dist/app/middleware/cors.js +1 -22
- package/dist/app/middleware/csp.js +1 -48
- package/dist/app/middleware/generate_insecure_page.js +65 -0
- package/dist/app/middleware/generate_joystick_error_page.js +147 -0
- package/dist/app/middleware/hmr_client.js +1 -0
- package/dist/app/middleware/insecure.js +1 -11
- package/dist/app/middleware/process_browser_polyfill.js +1 -0
- package/dist/app/middleware/render/get_url.js +1 -0
- package/dist/app/middleware/render/index.js +1 -0
- package/dist/app/middleware/request_methods.js +1 -0
- package/dist/app/middleware/session.js +1 -24
- package/dist/app/push_logs.js +1 -0
- package/dist/app/queues/index.js +1 -119
- package/dist/app/register_app_options.js +1 -0
- package/dist/app/routes/register_route_from_function.js +1 -0
- package/dist/app/routes/register_route_from_object.js +1 -0
- package/dist/app/routes/supported_http_methods.js +1 -0
- package/dist/app/settings/load.js +1 -0
- package/dist/app/ssr/index.js +33 -0
- package/dist/app/ssr/set_base_attributes_in_html.js +1 -0
- package/dist/app/ssr/set_head_tags_in_html.js +1 -0
- package/dist/app/start_express.js +1 -0
- package/dist/app/start_node_as_cluster.js +1 -0
- package/dist/app/uploaders/local_upload_progress_middleware.js +1 -0
- package/dist/app/uploaders/register.js +1 -0
- package/dist/app/uploaders/run_upload.js +1 -0
- package/dist/app/uploaders/validate_options.js +1 -0
- package/dist/app/uploaders/validate_uploads.js +1 -0
- package/dist/app/websockets/emit_event.js +1 -0
- package/dist/app/websockets/index.js +1 -0
- package/dist/app/websockets/register.js +1 -0
- package/dist/index.js +4 -76
- package/dist/lib/camel_pascal_to_snake.js +1 -0
- package/dist/lib/constants.js +1 -13
- package/dist/lib/dynamic_import.js +1 -0
- package/dist/lib/escape_html.js +1 -0
- package/dist/lib/escape_key_value_pair.js +1 -0
- package/dist/lib/float_to_decimal_place.js +1 -0
- package/dist/lib/generate_id.js +1 -0
- package/dist/lib/get_browser_safe_request.js +1 -0
- package/dist/lib/get_joystick_build_path.js +1 -0
- package/dist/lib/get_origin.js +1 -0
- package/dist/lib/get_platform_safe_path.js +1 -0
- package/dist/lib/get_sanitized_context.js +1 -0
- package/dist/lib/get_translations.js +1 -0
- package/dist/lib/hash_string.js +1 -0
- package/dist/lib/is_valid_json.js +1 -0
- package/dist/lib/log.js +13 -49
- package/dist/lib/node_path_polyfills.js +1 -0
- package/dist/lib/parse_json.js +1 -0
- package/dist/lib/path_exists.js +1 -0
- package/dist/lib/rainbow_road.js +1 -0
- package/dist/lib/serialize_query_parameters.js +1 -0
- package/dist/lib/set_cookie.js +1 -0
- package/dist/lib/string_to_slug.js +1 -0
- package/dist/lib/timestamps.js +1 -0
- package/dist/lib/types.js +1 -0
- package/dist/lib/unset_cookie.js +1 -0
- package/dist/lib/wait.js +1 -0
- package/dist/test/track_function_call.js +1 -0
- package/increment_version.js +3 -0
- package/package.json +27 -44
- package/src/action/class.js +137 -0
- package/src/action/index.js +8 -0
- package/src/app/accounts/default_user_output_fields.js +10 -0
- package/src/app/accounts/delete_user.js +18 -0
- package/src/app/accounts/generate_account_session.js +11 -0
- package/src/app/accounts/generate_password_reset_token.js +16 -0
- package/src/app/accounts/get_browser_safe_user.js +29 -0
- package/src/app/accounts/has_login_token_expired.js +9 -0
- package/src/app/accounts/index.js +38 -0
- package/src/app/accounts/login.js +82 -0
- package/src/app/accounts/recover_password.js +58 -0
- package/src/app/accounts/reset_password.js +69 -0
- package/src/app/accounts/roles/add.js +7 -0
- package/src/app/accounts/roles/grant.js +7 -0
- package/src/app/accounts/roles/index.js +18 -0
- package/src/app/accounts/roles/list.js +7 -0
- package/src/app/accounts/roles/remove.js +7 -0
- package/src/app/accounts/roles/revoke.js +7 -0
- package/src/app/accounts/roles/user_has_role.js +7 -0
- package/src/app/accounts/send_email_verification.js +48 -0
- package/src/app/accounts/set_account_cookie.js +12 -0
- package/src/app/accounts/set_password.js +46 -0
- package/src/app/accounts/signup.js +158 -0
- package/src/app/accounts/unset_account_cookie.js +12 -0
- package/src/app/accounts/verify_email.js +32 -0
- package/src/app/api/accounts/authenticated.js +17 -0
- package/src/app/api/accounts/login.js +36 -0
- package/src/app/api/accounts/logout.js +20 -0
- package/src/app/api/accounts/recover_password.js +16 -0
- package/src/app/api/accounts/reset_password.js +24 -0
- package/src/app/api/accounts/signup.js +49 -0
- package/src/app/api/accounts/user.js +21 -0
- package/src/app/api/accounts/verify_email.js +11 -0
- package/src/app/api/format_api_error.js +10 -0
- package/src/app/api/get.js +119 -0
- package/src/app/api/get_api_context.js +27 -0
- package/src/app/api/get_api_for_data_functions.js +37 -0
- package/src/app/api/get_api_url_component.js +5 -0
- package/src/app/api/get_output.js +116 -0
- package/src/app/api/get_value_from_object.js +8 -0
- package/src/app/api/handle_api_error.js +28 -0
- package/src/app/api/input_validators.js +227 -0
- package/src/app/api/is_array_path.js +6 -0
- package/src/app/api/push/health.js +17 -0
- package/src/app/api/register_getters.js +57 -0
- package/src/app/api/register_setters.js +55 -0
- package/src/app/api/sanitize_api_response.js +35 -0
- package/src/app/api/set.js +119 -0
- package/src/app/api/test/accounts/delete.js +8 -0
- package/src/app/api/test/accounts/signup.js +50 -0
- package/src/app/api/test/bootstrap.js +39 -0
- package/src/app/api/test/process.js +7 -0
- package/src/app/api/test/queues.js +25 -0
- package/src/app/api/validate_input.js +130 -0
- package/src/app/api/validate_session.js +20 -0
- package/src/app/api/validate_type.js +24 -0
- package/src/app/browser/hmr_client.js +196 -0
- package/src/app/browser/process_polyfill.js +11 -0
- package/src/app/cron_jobs/register.js +29 -0
- package/src/app/databases/database_type_map.js +6 -0
- package/src/app/databases/get_target_database_connection.js +25 -0
- package/{dist/app/databases/mongodb/availableQueryParameters.js → src/app/databases/mongodb/available_query_parameters.js} +3 -4
- package/src/app/databases/mongodb/build_connection_string.js +30 -0
- package/src/app/databases/mongodb/build_query_parameters.js +17 -0
- package/src/app/databases/mongodb/connect.js +42 -0
- package/src/app/databases/mongodb/create_indexes.js +35 -0
- package/src/app/databases/postgresql/accounts/create_accounts_metadata_table_columns.js +18 -0
- package/src/app/databases/postgresql/connect.js +128 -0
- package/src/app/databases/postgresql/create_indexes.js +58 -0
- package/src/app/databases/postgresql/create_tables.js +70 -0
- package/src/app/databases/postgresql/handle_cleanup_queues.js +36 -0
- package/src/app/databases/postgresql/handle_cleanup_sessions.js +5 -0
- package/src/app/databases/queries/accounts.js +17 -0
- package/src/app/databases/queries/map.js +21 -0
- package/src/app/databases/queries/mongodb/accounts.js +360 -0
- package/src/app/databases/queries/mongodb/queues.js +164 -0
- package/src/app/databases/queries/mongodb/sessions.js +22 -0
- package/src/app/databases/queries/postgresql/accounts.js +379 -0
- package/src/app/databases/queries/postgresql/queues.js +294 -0
- package/src/app/databases/queries/postgresql/sessions.js +37 -0
- package/src/app/databases/queries/sessions.js +17 -0
- package/src/app/databases/register_database.js +30 -0
- package/src/app/databases/sql.js +63 -0
- package/src/app/email/send.js +108 -0
- package/src/app/email/validate_smtp_settings.js +53 -0
- package/src/app/fixture/index.js +50 -0
- package/src/app/generate_machine_id.js +26 -0
- package/src/app/generate_process_id.js +30 -0
- package/src/app/get_ssl_certificates.js +23 -0
- package/src/app/handle_process_errors.js +101 -0
- package/src/app/index.js +253 -0
- package/src/app/middleware/account.js +28 -0
- package/src/app/middleware/body_parser.js +18 -0
- package/src/app/middleware/build_error.js +18 -0
- package/src/app/middleware/built_in.js +76 -0
- package/src/app/middleware/context.js +34 -0
- package/src/app/middleware/cors.js +23 -0
- package/src/app/middleware/csp.js +54 -0
- package/src/app/middleware/generate_insecure_page.js +71 -0
- package/{dist/lib/generateErrorPage.js → src/app/middleware/generate_joystick_error_page.js} +25 -21
- package/src/app/middleware/hmr_client.js +12 -0
- package/src/app/middleware/insecure.js +22 -0
- package/src/app/middleware/process_browser_polyfill.js +12 -0
- package/src/app/middleware/render/get_url.js +15 -0
- package/src/app/middleware/render/index.js +93 -0
- package/src/app/middleware/request_methods.js +21 -0
- package/src/app/middleware/session.js +31 -0
- package/src/app/push_logs.js +44 -0
- package/src/app/queues/index.js +268 -0
- package/src/app/register_app_options.js +7 -0
- package/src/app/routes/register_route_from_function.js +10 -0
- package/src/app/routes/register_route_from_object.js +34 -0
- package/src/app/routes/supported_http_methods.js +9 -0
- package/src/app/settings/load.js +33 -0
- package/src/app/ssr/index.js +133 -0
- package/src/app/ssr/set_base_attributes_in_html.js +43 -0
- package/src/app/ssr/set_head_tags_in_html.js +104 -0
- package/src/app/start_express.js +50 -0
- package/src/app/start_node_as_cluster.js +30 -0
- package/src/app/uploaders/local_upload_progress_middleware.js +24 -0
- package/src/app/uploaders/register.js +169 -0
- package/src/app/uploaders/run_upload.js +136 -0
- package/src/app/uploaders/validate_options.js +74 -0
- package/src/app/uploaders/validate_uploads.js +127 -0
- package/src/app/websockets/emit_event.js +14 -0
- package/src/app/websockets/index.js +16 -0
- package/src/app/websockets/register.js +175 -0
- package/src/index.js +81 -0
- package/{dist/lib/camelPascalToSnake.js → src/lib/camel_pascal_to_snake.js} +3 -4
- package/src/lib/constants.js +21 -0
- package/src/lib/dynamic_import.js +8 -0
- package/src/lib/escape_html.js +9 -0
- package/src/lib/escape_key_value_pair.js +15 -0
- package/src/lib/float_to_decimal_place.js +5 -0
- package/src/lib/generate_id.js +15 -0
- package/src/lib/get_browser_safe_request.js +17 -0
- package/src/lib/get_joystick_build_path.js +22 -0
- package/src/lib/get_origin.js +7 -0
- package/src/lib/get_platform_safe_path.js +8 -0
- package/src/lib/get_sanitized_context.js +51 -0
- package/src/lib/get_translations.js +109 -0
- package/src/lib/hash_string.js +7 -0
- package/src/lib/is_valid_json.js +10 -0
- package/src/lib/log.js +42 -0
- package/src/lib/node_path_polyfills.js +23 -0
- package/src/lib/parse_json.js +9 -0
- package/src/lib/path_exists.js +12 -0
- package/src/lib/rainbow_road.js +7 -0
- package/src/lib/serialize_query_parameters.js +7 -0
- package/src/lib/set_cookie.js +16 -0
- package/src/lib/string_to_slug.js +14 -0
- package/src/lib/timestamps.js +48 -0
- package/src/lib/types.js +59 -0
- package/src/lib/unset_cookie.js +11 -0
- package/src/lib/wait.js +9 -0
- package/src/test/track_function_call.js +16 -0
- package/README.md +0 -8
- package/_package.json +0 -63
- package/canary.js +0 -12
- package/dist/api/get.js +0 -29
- package/dist/api/getOrigin.js +0 -6
- package/dist/api/index.js +0 -9
- package/dist/api/set.js +0 -29
- package/dist/app/accounts/defaultUserOutputFields.js +0 -9
- package/dist/app/accounts/generateResetToken.js +0 -28
- package/dist/app/accounts/generateSession.js +0 -15
- package/dist/app/accounts/getBrowserSafeUser.js +0 -24
- package/dist/app/accounts/hasLoginTokenExpired.js +0 -17
- package/dist/app/accounts/hashString.js +0 -7
- package/dist/app/accounts/recoverPassword.js +0 -30
- package/dist/app/accounts/resetPassword.js +0 -73
- package/dist/app/accounts/roles/userHasRole.js +0 -7
- package/dist/app/accounts/runUserQuery.js +0 -15
- package/dist/app/accounts/sendEmailVerification.js +0 -65
- package/dist/app/accounts/setAuthenticationCookie.js +0 -11
- package/dist/app/accounts/setPassword.js +0 -45
- package/dist/app/accounts/unsetAuthenticationCookie.js +0 -11
- package/dist/app/accounts/verifyEmail.js +0 -46
- package/dist/app/databases/getTargetDatabase.js +0 -10
- package/dist/app/databases/getTargetDatabaseConnection.js +0 -19
- package/dist/app/databases/getTargetDatabaseProvider.js +0 -10
- package/dist/app/databases/mongodb/buildConnectionString.js +0 -22
- package/dist/app/databases/mongodb/buildQueryParameters.js +0 -14
- package/dist/app/databases/mongodb/index.js +0 -40
- package/dist/app/databases/mongodb/queries/accounts.js +0 -266
- package/dist/app/databases/mongodb/queries/queues.js +0 -111
- package/dist/app/databases/postgresql/addColumnToTable.js +0 -6
- package/dist/app/databases/postgresql/createAccountsIndexes.js +0 -21
- package/dist/app/databases/postgresql/createAccountsTables.js +0 -39
- package/dist/app/databases/postgresql/createDatabase.js +0 -0
- package/dist/app/databases/postgresql/index.js +0 -55
- package/dist/app/databases/postgresql/queries/accounts.js +0 -186
- package/dist/app/databases/postgresql/queries/queues.js +0 -211
- package/dist/app/databases/queryMap.js +0 -17
- package/dist/app/databases/typesMap.js +0 -7
- package/dist/app/getAPIContext.js +0 -25
- package/dist/app/getAPIURLComponent.js +0 -6
- package/dist/app/getBrowserSafeRequest.js +0 -14
- package/dist/app/getOutput.js +0 -74
- package/dist/app/handleProcessErrors.js +0 -73
- package/dist/app/initExpress.js +0 -41
- package/dist/app/middleware/bodyParser.js +0 -16
- package/dist/app/middleware/hmr/client.js +0 -113
- package/dist/app/middleware/index.js +0 -89
- package/dist/app/middleware/render.js +0 -213
- package/dist/app/middleware/requestMethods.js +0 -19
- package/dist/app/registerGetters.js +0 -45
- package/dist/app/registerSetters.js +0 -45
- package/dist/app/runGetter.js +0 -103
- package/dist/app/runSetter.js +0 -103
- package/dist/app/runUploader.js +0 -143
- package/dist/app/sanitizeAPIResponse.js +0 -27
- package/dist/app/utils/process.js +0 -193
- package/dist/app/validateSession.js +0 -19
- package/dist/app/validateUploaderOptions.js +0 -53
- package/dist/app/validateUploads.js +0 -102
- package/dist/email/render.js +0 -50
- package/dist/email/send.js +0 -55
- package/dist/email/templates/base.css +0 -194
- package/dist/email/templates/base.html +0 -28
- package/dist/email/templates/reset-password.js +0 -13
- package/dist/email/validateSMTPSettings.js +0 -27
- package/dist/lib/escapeHTML.js +0 -9
- package/dist/lib/escapeKeyValuePair.js +0 -13
- package/dist/lib/formatAPIError.js +0 -12
- package/dist/lib/formatErrorString.js +0 -8
- package/dist/lib/generateCookie.js +0 -14
- package/dist/lib/generateId.js +0 -13
- package/dist/lib/generateMachineId.js +0 -15
- package/dist/lib/getBuildPath.js +0 -10
- package/dist/lib/getErrorObject.js +0 -9
- package/dist/lib/getPlatformSafeFilePath.js +0 -8
- package/dist/lib/getPlatformSafePath.js +0 -8
- package/dist/lib/getSSLCertificates.js +0 -19
- package/dist/lib/isValidHTTPMethod.js +0 -7
- package/dist/lib/isValidJSONString.js +0 -11
- package/dist/lib/nodeUrlPolyfills.js +0 -14
- package/dist/lib/objectToSQLKeysString.js +0 -18
- package/dist/lib/objectToSQLValuesString.js +0 -16
- package/dist/lib/obscenedb/debounce.js +0 -12
- package/dist/lib/obscenedb/index.js +0 -61
- package/dist/lib/parseDatabasesFromEnvironment.js +0 -9
- package/dist/lib/rainbowRoad.js +0 -7
- package/dist/lib/readDirectory.js +0 -24
- package/dist/lib/replaceBackslashesWithForwardSlashes.js +0 -8
- package/dist/lib/replaceFileProtocol.js +0 -8
- package/dist/lib/replaceForwardSlashesWithBackslashes.js +0 -8
- package/dist/lib/serializeQueryParameters.js +0 -8
- package/dist/lib/serverAvailable.js +0 -0
- package/dist/lib/setCookie.js +0 -16
- package/dist/lib/supportedHTTPMethods.js +0 -4
- package/dist/lib/unsetCookie.js +0 -13
- package/dist/push/logs/index.js +0 -55
- package/dist/settings/index.js +0 -5
- package/dist/settings/load.js +0 -30
- package/dist/ssr/compileCSS.js +0 -85
- package/dist/ssr/findComponentInTree.js +0 -29
- package/dist/ssr/formatCSS.js +0 -6
- package/dist/ssr/getCSSFromTree.js +0 -33
- package/dist/ssr/index.js +0 -441
- package/dist/ssr/replaceWhenTags.js +0 -37
- package/dist/ssr/setHeadTagsInHTML.js +0 -84
- package/dist/validation/index.js +0 -10
- package/dist/validation/index.test.js +0 -463
- package/dist/validation/inputWithSchema/index.js +0 -105
- package/dist/validation/lib/constants.js +0 -162
- package/dist/validation/lib/getValueFromObject.js +0 -12
- package/dist/validation/lib/getValueFromObject.test.js +0 -7
- package/dist/validation/lib/isArrayPath.js +0 -6
- package/dist/validation/lib/throwError.js +0 -6
- package/dist/validation/lib/typeValidators.js +0 -38
- package/dist/validation/lib/validateType.js +0 -33
- package/dist/validation/schema/index.js +0 -44
- package/dist/websockets/emitWebsocketEvent.js +0 -12
- package/dist/websockets/index.js +0 -12
- package/notes +0 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import generate_id from '../lib/generate_id.js';
|
|
3
|
+
import path_exists from '../lib/path_exists.js';
|
|
4
|
+
|
|
5
|
+
const { mkdir, writeFile, readFile } = fs.promises;
|
|
6
|
+
|
|
7
|
+
const generate_process_id = async () => {
|
|
8
|
+
// NOTE: Taint machine with a unique ID that can be used to identify a single running
|
|
9
|
+
// process/instance of Joystick (helpful when running in cluster mode or multiple servers).
|
|
10
|
+
const joystick_folder_path = './.joystick';
|
|
11
|
+
const joystick_process_id_path = './.joystick/PROCESS_ID';
|
|
12
|
+
const has_joystick_folder = await path_exists(joystick_folder_path);
|
|
13
|
+
const has_joystick_process_id = await path_exists(joystick_process_id_path);
|
|
14
|
+
|
|
15
|
+
if (!has_joystick_folder) {
|
|
16
|
+
await mkdir(joystick_folder_path);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (!has_joystick_process_id) {
|
|
20
|
+
const joystick_process_id = generate_id(32);
|
|
21
|
+
await writeFile(joystick_process_id_path, `${generate_id(32)}`);
|
|
22
|
+
return joystick_process_id;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const joystick_process_id = await readFile(joystick_process_id_path, 'utf-8');
|
|
26
|
+
|
|
27
|
+
return joystick_process_id?.trim();
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default generate_process_id;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
|
|
3
|
+
const get_ssl_certificates = (ssl = null) => {
|
|
4
|
+
const push_certificate_path = '/root/push/certs/cert.pem';
|
|
5
|
+
const push_key_path = '/root/push/certs/key.pem';
|
|
6
|
+
|
|
7
|
+
const certificate_path = process.env.IS_PUSH_DEPLOYED ? push_certificate_path : (ssl?.certificate || null);
|
|
8
|
+
const key_path = process.env.IS_PUSH_DEPLOYED ? push_key_path : (ssl?.key || null);
|
|
9
|
+
|
|
10
|
+
const certificate_exists = certificate_path && fs.existsSync(certificate_path);
|
|
11
|
+
const key_exists = key_path && fs.existsSync(key_path);
|
|
12
|
+
|
|
13
|
+
if (['development', 'test'].includes(process.env.NODE_ENV) || !certificate_exists || !key_exists) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
cert: fs.readFileSync(certificate_path),
|
|
19
|
+
key: fs.readFileSync(key_path),
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default get_ssl_certificates;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
const handle_process_errors = (event_listeners = {}) => {
|
|
2
|
+
process.on("disconnect", async () => {
|
|
3
|
+
if (event_listeners?.disconnect && typeof event_listeners.disconnect === "function") {
|
|
4
|
+
event_listeners.disconnect();
|
|
5
|
+
}
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
process.on("beforeExit", async (code) => {
|
|
9
|
+
if (event_listeners?.beforeExit && typeof event_listeners.beforeExit === "function") {
|
|
10
|
+
event_listeners.beforeExit(code);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
process.on("exit", async (code) => {
|
|
15
|
+
if (event_listeners?.exit && typeof event_listeners.exit === "function") {
|
|
16
|
+
event_listeners.exit(code);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
process.on("message", async (message, sendHandle) => {
|
|
21
|
+
if (process.env.NODE_ENV !== "test") {
|
|
22
|
+
console.log(message);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (event_listeners?.message && typeof event_listeners.message === "function") {
|
|
26
|
+
event_listeners.message(message, sendHandle);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
process.on("multipleResolves", async (type, promise, value) => {
|
|
31
|
+
if (
|
|
32
|
+
event_listeners?.multipleResolves &&
|
|
33
|
+
typeof event_listeners.multipleResolves === "function"
|
|
34
|
+
) {
|
|
35
|
+
event_listeners.multipleResolves(type, promise, value);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
process.on("rejectionHandled", async (promise) => {
|
|
40
|
+
if (
|
|
41
|
+
event_listeners?.rejectionHandled &&
|
|
42
|
+
typeof event_listeners.rejectionHandled === "function"
|
|
43
|
+
) {
|
|
44
|
+
event_listeners.rejectionHandled(promise);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
process.on("uncaughtException", async (error, origin) => {
|
|
49
|
+
console.warn(error);
|
|
50
|
+
|
|
51
|
+
if (event_listeners?.error && typeof event_listeners.error === "function") {
|
|
52
|
+
event_listeners.error(error);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (
|
|
56
|
+
event_listeners?.uncaughtException &&
|
|
57
|
+
typeof event_listeners.uncaughtException === "function"
|
|
58
|
+
) {
|
|
59
|
+
event_listeners.uncaughtException(error, origin);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
process.on("uncaughtExceptionMonitor", async (error) => {
|
|
64
|
+
if (
|
|
65
|
+
event_listeners?.uncaughtExceptionMonitor &&
|
|
66
|
+
typeof event_listeners.uncaughtExceptionMonitor === "function"
|
|
67
|
+
) {
|
|
68
|
+
event_listeners.uncaughtExceptionMonitor(error);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
process.on("unhandledRejection", async (error) => {
|
|
73
|
+
console.warn(error);
|
|
74
|
+
|
|
75
|
+
if (event_listeners?.error && typeof event_listeners.error === "function") {
|
|
76
|
+
event_listeners.error(error);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (
|
|
80
|
+
event_listeners?.unhandledRejection &&
|
|
81
|
+
typeof event_listeners.unhandledRejection === "function"
|
|
82
|
+
) {
|
|
83
|
+
event_listeners.unhandledRejection(error);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
process.on("warning", async (warning) => {
|
|
88
|
+
if (event_listeners?.warning && typeof event_listeners.warning === "function") {
|
|
89
|
+
event_listeners.warning(warning);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
process.on("worker", async (event) => {
|
|
94
|
+
if (event_listeners?.worker && typeof event_listeners.worker === "function") {
|
|
95
|
+
event_listeners.worker(event);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export default handle_process_errors;
|
|
101
|
+
|
package/src/app/index.js
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import api_accounts_authenticated from "./api/accounts/authenticated.js";
|
|
2
|
+
import api_accounts_login from "./api/accounts/login.js";
|
|
3
|
+
import api_accounts_logout from "./api/accounts/logout.js";
|
|
4
|
+
import api_accounts_recover_password from "./api/accounts/recover_password.js";
|
|
5
|
+
import api_accounts_reset_password from "./api/accounts/reset_password.js";
|
|
6
|
+
import api_accounts_signup from "./api/accounts/signup.js";
|
|
7
|
+
import api_accounts_user from "./api/accounts/user.js";
|
|
8
|
+
import api_accounts_verify_email from "./api/accounts/verify_email.js";
|
|
9
|
+
import api_push_health from './api/push/health.js';
|
|
10
|
+
import api_test_accounts_delete from "./api/test/accounts/delete.js";
|
|
11
|
+
import api_test_accounts_signup from "./api/test/accounts/signup.js";
|
|
12
|
+
import api_test_bootstrap from "./api/test/bootstrap.js";
|
|
13
|
+
import api_test_process from "./api/test/process.js";
|
|
14
|
+
import api_test_queues from "./api/test/queues.js";
|
|
15
|
+
import create_mongodb_indexes from "./databases/mongodb/create_indexes.js";
|
|
16
|
+
import create_postgresql_indexes from "./databases/postgresql/create_indexes.js";
|
|
17
|
+
import create_postgresql_tables from "./databases/postgresql/create_tables.js";
|
|
18
|
+
import generate_machine_id from "./generate_machine_id.js";
|
|
19
|
+
import generate_process_id from "./generate_process_id.js";
|
|
20
|
+
import get_target_database_connection from "./databases/get_target_database_connection.js";
|
|
21
|
+
import handle_process_errors from "./handle_process_errors.js";
|
|
22
|
+
import load_settings from "./settings/load.js";
|
|
23
|
+
import Queue from "./queues/index.js";
|
|
24
|
+
import register_app_options from "./register_app_options.js";
|
|
25
|
+
import register_cron_jobs from "./cron_jobs/register.js";
|
|
26
|
+
import register_database from './databases/register_database.js';
|
|
27
|
+
import register_getters from "./api/register_getters.js";
|
|
28
|
+
import register_route_from_function from './routes/register_route_from_function.js';
|
|
29
|
+
import register_route_from_object from './routes/register_route_from_object.js';
|
|
30
|
+
import register_setters from "./api/register_setters.js";
|
|
31
|
+
import register_uploaders from "./uploaders/register.js";
|
|
32
|
+
import register_websockets from "./websockets/register.js";
|
|
33
|
+
import start_express from "./start_express.js";
|
|
34
|
+
import start_node_as_cluster from "./start_node_as_cluster.js";
|
|
35
|
+
import types from "../lib/types.js";
|
|
36
|
+
import push_logs from "./push_logs.js";
|
|
37
|
+
|
|
38
|
+
const app_settings = load_settings();
|
|
39
|
+
|
|
40
|
+
if (process.env.NODE_ENV !== "development" && process.env.IS_PUSH_DEPLOYED) {
|
|
41
|
+
push_logs();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
class App {
|
|
45
|
+
constructor(app_options = {}) {
|
|
46
|
+
handle_process_errors(app_options?.events);
|
|
47
|
+
|
|
48
|
+
register_app_options(this, app_options);
|
|
49
|
+
|
|
50
|
+
this.generate_machine_id();
|
|
51
|
+
this.generate_process_id();
|
|
52
|
+
|
|
53
|
+
process.title = process.env.NODE_ENV === 'test' ? "joystick_test_app" : 'joystick_app';
|
|
54
|
+
|
|
55
|
+
// NOTE: Make app_options passed to node.app() accessible globally. This is used
|
|
56
|
+
// for things like the account hooks.
|
|
57
|
+
process.joystick = {
|
|
58
|
+
app_options,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async connect_databases() {
|
|
63
|
+
const databases_from_settings = app_settings?.config?.databases;
|
|
64
|
+
|
|
65
|
+
for (let i = 0; i < databases_from_settings?.length; i += 1) {
|
|
66
|
+
const database_from_settings = databases_from_settings[i];
|
|
67
|
+
const database_port = parseInt(process.env.PORT, 10) + 10 + i;
|
|
68
|
+
const has_multiple_of_provider = (databases_from_settings?.filter((database) => database_from_settings?.provider === database?.provider))?.length > 1;
|
|
69
|
+
|
|
70
|
+
await register_database(database_from_settings, database_port, has_multiple_of_provider);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (databases_from_settings?.length > 0) {
|
|
74
|
+
const queues_database = get_target_database_connection('queues');
|
|
75
|
+
const sessions_database = get_target_database_connection('sessions');
|
|
76
|
+
const users_database = get_target_database_connection('users');
|
|
77
|
+
|
|
78
|
+
process.databases._queues = queues_database?.connection;
|
|
79
|
+
process.databases._sessions = sessions_database?.connection;
|
|
80
|
+
process.databases._users = users_database?.connection;
|
|
81
|
+
|
|
82
|
+
const internal_database_targets = [queues_database, sessions_database, users_database];
|
|
83
|
+
|
|
84
|
+
const mongodb_targets = internal_database_targets?.filter((target) => target?.provider === 'mongodb')?.map((target) => target?.database_type);
|
|
85
|
+
await create_mongodb_indexes(mongodb_targets);
|
|
86
|
+
|
|
87
|
+
const postgresql_targets = internal_database_targets?.filter((target) => target?.provider === 'postgresql')?.map((target) => target?.database_type);
|
|
88
|
+
await create_postgresql_tables(postgresql_targets);
|
|
89
|
+
await create_postgresql_indexes(postgresql_targets);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async generate_machine_id() {
|
|
94
|
+
this.joystick_machine_id = await generate_machine_id();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async generate_process_id() {
|
|
98
|
+
this.joystick_process_id = await generate_process_id();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
on_after_start_server(express = {}) {
|
|
102
|
+
// NOTE: Any console.log here is picked up by the stdout listener inside of
|
|
103
|
+
// the start script of the CLI.
|
|
104
|
+
process.on("message", (message) => {
|
|
105
|
+
if (typeof message === 'string') {
|
|
106
|
+
const parsed_message = JSON.parse(message);
|
|
107
|
+
|
|
108
|
+
if (parsed_message?.type === 'BUILD_ERROR') {
|
|
109
|
+
process.BUILD_ERROR = JSON.parse(message);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
console.log(`App running at: http://localhost:${express.port}`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
register_accounts() {
|
|
118
|
+
this.express.app.get('/api/_accounts/authenticated', api_accounts_authenticated);
|
|
119
|
+
this.express.app.post('/api/_accounts/user', api_accounts_user);
|
|
120
|
+
this.express.app.post('/api/_accounts/login', api_accounts_login);
|
|
121
|
+
this.express.app.post('/api/_accounts/logout', api_accounts_logout);
|
|
122
|
+
this.express.app.post('/api/_accounts/recover-password', api_accounts_recover_password);
|
|
123
|
+
this.express.app.post('/api/_accounts/reset-password', api_accounts_reset_password);
|
|
124
|
+
this.express.app.post('/api/_accounts/signup', api_accounts_signup);
|
|
125
|
+
this.express.app.post('/api/_accounts/verify-email', api_accounts_verify_email);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
register_api() {
|
|
129
|
+
const getters = this?.options?.api?.getters;
|
|
130
|
+
const setters = this?.options?.api?.setters;
|
|
131
|
+
const api_options = this?.options?.api?.options;
|
|
132
|
+
const api_context = this?.options?.api?.context;
|
|
133
|
+
|
|
134
|
+
if (getters && types.is_object(getters) && Object.keys(getters || {}).length > 0) {
|
|
135
|
+
register_getters(this.express.app, Object.entries(getters || {}), api_context, api_options);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (setters && types.is_object(setters) && Object.keys(setters || {}).length > 0) {
|
|
139
|
+
register_setters(this.express.app, Object.entries(setters || {}), api_context, api_options);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
register_cron_jobs() {
|
|
144
|
+
register_cron_jobs(this.options.cronJobs || this.options.cron_jobs);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
register_fixtures() {
|
|
148
|
+
if (types.is_function(this.options.fixtures)) {
|
|
149
|
+
this.options.fixtures();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
register_indexes() {
|
|
154
|
+
if (types.is_function(this.options.indexes)) {
|
|
155
|
+
this.options.indexes();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
register_push() {
|
|
160
|
+
this.express.app.get("/api/_push/health", api_push_health);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
register_queues() {
|
|
164
|
+
if (types.is_object(this.options.queues)) {
|
|
165
|
+
const queue_definitions = Object.entries(this.options.queues || {});
|
|
166
|
+
for (let i = 0; i < queue_definitions.length; i += 1) {
|
|
167
|
+
const [queue_name, queue_options] = queue_definitions[i];
|
|
168
|
+
process.queues = {
|
|
169
|
+
...(process.queues || {}),
|
|
170
|
+
[queue_name]: new Queue(queue_name, queue_options),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
register_routes() {
|
|
177
|
+
const routes = Object.entries(this?.options?.routes || {});
|
|
178
|
+
|
|
179
|
+
for (let i = 0; i < routes?.length; i += 1) {
|
|
180
|
+
const [route_path, route_handler] = routes[i];
|
|
181
|
+
const is_object_route = types.is_object(route_handler);
|
|
182
|
+
const is_function_route = types.is_function(route_handler);
|
|
183
|
+
|
|
184
|
+
if (is_function_route) {
|
|
185
|
+
register_route_from_function(this.express.app, route_path, route_handler);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (is_object_route) {
|
|
189
|
+
register_route_from_object(this.express.app, route_path, route_handler);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
register_tests() {
|
|
195
|
+
this.express.app.get('/api/_test/bootstrap', (req = {}, res = {}) => api_test_bootstrap(req, res, this));
|
|
196
|
+
this.express.app.get('/api/_test/process', api_test_process);
|
|
197
|
+
this.express.app.delete('/api/_test/accounts', api_test_accounts_delete);
|
|
198
|
+
this.express.app.post('/api/_test/accounts/signup', api_test_accounts_signup);
|
|
199
|
+
this.express.app.post('/api/_test/queues', (req = {}, res = {}) => api_test_queues(req, res, this));
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
register_uploaders() {
|
|
203
|
+
register_uploaders(this.options.uploaders, this);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
register_websockets() {
|
|
207
|
+
register_websockets(this.options.websockets, this);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async start() {
|
|
211
|
+
// NOTE: Order here is intentionally not alphabetical to ensure load
|
|
212
|
+
// order plays nice with things like tests.
|
|
213
|
+
await this.connect_databases();
|
|
214
|
+
this.register_cron_jobs();
|
|
215
|
+
this.register_queues();
|
|
216
|
+
this.start_express();
|
|
217
|
+
this.register_tests();
|
|
218
|
+
this.register_accounts();
|
|
219
|
+
this.register_push();
|
|
220
|
+
this.register_api();
|
|
221
|
+
this.register_routes();
|
|
222
|
+
this.register_websockets();
|
|
223
|
+
this.register_uploaders();
|
|
224
|
+
this.register_fixtures();
|
|
225
|
+
this.register_indexes();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
start_express() {
|
|
229
|
+
this.express = start_express(this.on_after_start_server, this);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const start_app = async (options = {}) => {
|
|
234
|
+
const app = new App(options);
|
|
235
|
+
await app.start(options);
|
|
236
|
+
return app;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const app = (options = {}) => {
|
|
240
|
+
return new Promise(async (resolve) => {
|
|
241
|
+
if (options?.cluster) {
|
|
242
|
+
start_node_as_cluster(async () => {
|
|
243
|
+
const app = await start_app(options);
|
|
244
|
+
return resolve(app.express);
|
|
245
|
+
});
|
|
246
|
+
} else {
|
|
247
|
+
const app = await start_app(options);
|
|
248
|
+
return resolve(app.express);
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
export default app;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import accounts_query from '../databases/queries/accounts.js';
|
|
2
|
+
import has_login_token_expired from '../accounts/has_login_token_expired.js';
|
|
3
|
+
import unset_account_cookie from "../accounts/unset_account_cookie.js";
|
|
4
|
+
|
|
5
|
+
const account_middleware = async (req, res, next) => {
|
|
6
|
+
const login_token_has_expired = has_login_token_expired(
|
|
7
|
+
res,
|
|
8
|
+
req?.cookies?.joystick_login_token,
|
|
9
|
+
req?.cookies?.joystick_login_token_expires_at
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
if (login_token_has_expired) {
|
|
13
|
+
unset_account_cookie(res);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const user = !login_token_has_expired ? await accounts_query("user_with_login_token", {
|
|
17
|
+
token: req?.cookies?.joystick_login_token,
|
|
18
|
+
}) : null;
|
|
19
|
+
|
|
20
|
+
req.context = {
|
|
21
|
+
...(req?.context || {}),
|
|
22
|
+
user,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
next();
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default account_middleware;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
|
|
3
|
+
const body_parser = (config = {}) => {
|
|
4
|
+
return (req, res, next) => {
|
|
5
|
+
const content_Type = req.headers["content-type"];
|
|
6
|
+
|
|
7
|
+
if (content_Type && content_Type === "application/x-www-form-urlencoded") {
|
|
8
|
+
return express.urlencoded({
|
|
9
|
+
extended: true,
|
|
10
|
+
...(config?.urlencoded || {}),
|
|
11
|
+
})(req, res, next);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return express.json(config?.json)(req, res, next);
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default body_parser;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import generate_joystick_error_page from './generate_joystick_error_page.js';
|
|
2
|
+
|
|
3
|
+
const build_error_middleware = (_req, res, next) => {
|
|
4
|
+
if (process.BUILD_ERROR) {
|
|
5
|
+
const error = process.BUILD_ERROR.paths && process.BUILD_ERROR.paths[0];
|
|
6
|
+
const joystick_error_page = generate_joystick_error_page({
|
|
7
|
+
path: error.path,
|
|
8
|
+
stack: error.error.stack,
|
|
9
|
+
frame: error.error.snippet,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
return res.send(joystick_error_page);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
next();
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default build_error_middleware;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import compression from 'compression';
|
|
2
|
+
import cookieParser from "cookie-parser";
|
|
3
|
+
import cors from 'cors';
|
|
4
|
+
import express from 'express';
|
|
5
|
+
import favicon from "serve-favicon";
|
|
6
|
+
import account_middleware from './account.js';
|
|
7
|
+
import body_parser from './body_parser.js';
|
|
8
|
+
import build_error_middleware from './build_error.js';
|
|
9
|
+
import context_middleware from './context.js';
|
|
10
|
+
import get_joystick_build_path from '../../lib/get_joystick_build_path.js';
|
|
11
|
+
import hmr_client_middleware from './hmr_client.js';
|
|
12
|
+
import insecure_middleware from './insecure.js';
|
|
13
|
+
import path_exists from '../../lib/path_exists.js';
|
|
14
|
+
import process_browser_polyfill_middleware from './process_browser_polyfill.js';
|
|
15
|
+
import render_middleware from './render/index.js';
|
|
16
|
+
import request_methods_middleware from './request_methods.js';
|
|
17
|
+
import session_middleware from './session.js';
|
|
18
|
+
|
|
19
|
+
const build_path = get_joystick_build_path();
|
|
20
|
+
|
|
21
|
+
const built_in = (options = {}) => {
|
|
22
|
+
options.express_app.set('trust proxy', 1);
|
|
23
|
+
|
|
24
|
+
if (!['development', 'test'].includes(process.env.NODE_ENV)) {
|
|
25
|
+
options.express_app.use(insecure_middleware);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
options.express_app.use(build_error_middleware);
|
|
29
|
+
options.express_app.use(request_methods_middleware);
|
|
30
|
+
|
|
31
|
+
if (options?.csp_config) {
|
|
32
|
+
options.express_app.use((req, res, next) => csp(req, res, next, options?.csp_config));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (process.env.NODE_ENV !== 'development') {
|
|
36
|
+
options.express_app.use(compression());
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
options.express_app.use(express.static('public'));
|
|
40
|
+
options.express_app.use('/css', express.static('css'));
|
|
41
|
+
options.express_app.use('/_joystick/utils/process.js', process_browser_polyfill_middleware);
|
|
42
|
+
options.express_app.use('/_joystick/index.client.js', express.static(`${options?.joystick_build_path}index.client.js`));
|
|
43
|
+
options.express_app.use('/_joystick/index.css', express.static(`${options?.joystick_build_path}index.css`));
|
|
44
|
+
options.express_app.use('/_joystick/ui', express.static(`${build_path}ui`));
|
|
45
|
+
|
|
46
|
+
if (process.env.NODE_ENV === 'development') {
|
|
47
|
+
options.express_app.use("/_joystick/hmr/client.js", hmr_client_middleware);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
options.express_app.use(async (req, res, next) => {
|
|
51
|
+
const favicon_exists = await path_exists('public/favicon.ico');
|
|
52
|
+
if (favicon_exists) {
|
|
53
|
+
favicon('public/favicon.ico')(req, res, next);
|
|
54
|
+
} else {
|
|
55
|
+
next();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
options.express_app.use(cookieParser());
|
|
60
|
+
options.express_app.use(body_parser(options?.middleware_config?.bodyParser));
|
|
61
|
+
options.express_app.use(cors(options?.middleware_config?.cors, options?.port));
|
|
62
|
+
|
|
63
|
+
if (process.databases?._sessions) {
|
|
64
|
+
options.express_app.use((req, res, next) => session_middleware(req, res, next));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (process.databases?._users) {
|
|
68
|
+
options.express_app.use((req, res, next) => account_middleware(req, res, next));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
options.express_app.use((req, res, next) => context_middleware(req, res, next));
|
|
72
|
+
|
|
73
|
+
options.express_app.use((req, res, next) => render_middleware(req, res, next, options?.app_instance));
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export default built_in;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const if_logged_in = (redirect_path = "", callback = null, http = {}) => {
|
|
2
|
+
if (!!http?.req?.context?.user && redirect_path) {
|
|
3
|
+
return http?.res.redirect(redirect_path);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
if (callback) {
|
|
7
|
+
return callback();
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const if_not_logged_in = (redirect_path = "", callback = null, http = {}) => {
|
|
12
|
+
if (!http?.req?.context?.user && redirect_path) {
|
|
13
|
+
return http?.res.redirect(redirect_path);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (callback) {
|
|
17
|
+
return callback();
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const context_middleware = async (req, res, next) => {
|
|
22
|
+
req.context = {
|
|
23
|
+
...(req?.context || {}),
|
|
24
|
+
if_logged_in: (redirect_path = '', callback) => if_logged_in(redirect_path, callback, { req, res }),
|
|
25
|
+
ifLoggedIn: (redirect_path = '', callback) => if_logged_in(redirect_path, callback, { req, res }),
|
|
26
|
+
if_not_logged_in: (redirect_path = '', callback) => if_not_logged_in(redirect_path, callback, { req, res }),
|
|
27
|
+
ifNotLoggedIn: (redirect_path = '', callback) => if_not_logged_in(redirect_path, callback, { req, res }),
|
|
28
|
+
...(process.databases || {}),
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
next();
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default context_middleware;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import cors from "cors";
|
|
2
|
+
|
|
3
|
+
const cors_middleware = (config = {}, port = "") => {
|
|
4
|
+
return (req, res, next) => {
|
|
5
|
+
const allowed_urls = [
|
|
6
|
+
`http://localhost:${port}`,
|
|
7
|
+
...(config?.allowedUrls || []),
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
return cors({
|
|
11
|
+
credentials: true,
|
|
12
|
+
origin: function (origin, callback) {
|
|
13
|
+
if (!origin || allowed_urls.includes(origin)) {
|
|
14
|
+
callback(null, true);
|
|
15
|
+
} else {
|
|
16
|
+
callback(new Error(`${origin} not permitted by CORS policy.`));
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
})(req, res, next);
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default cors_middleware;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import types from '../../lib/types.js';
|
|
2
|
+
|
|
3
|
+
const csp_middleware = (_req, res, next, csp_config = null) => {
|
|
4
|
+
if (csp_config && types.is_object(csp_config)) {
|
|
5
|
+
// NOTE: Redefine for each request so it doesn't get stuck in memory.
|
|
6
|
+
const directive_defaults = {
|
|
7
|
+
'base-uri': ["'self'"],
|
|
8
|
+
'child-src': ["'self'"],
|
|
9
|
+
'connect-src': ["'self'", "wss:"],
|
|
10
|
+
'default-src': ["'self'"],
|
|
11
|
+
'font-src': ["'self'"],
|
|
12
|
+
'form-action': ["'self'"],
|
|
13
|
+
'frame-src': ["'self'"],
|
|
14
|
+
'img-src': ["'self'"],
|
|
15
|
+
'manifest-src': ["'self'"],
|
|
16
|
+
'media-src': ["'self'"],
|
|
17
|
+
'navigate-to': ["'self'"],
|
|
18
|
+
'object-src': ["'self'"],
|
|
19
|
+
'script-src': ["'self'"],
|
|
20
|
+
'script-src-attr': ["'self'"],
|
|
21
|
+
'script-src-elem': ["'self'"],
|
|
22
|
+
'style-src': ["'self'"],
|
|
23
|
+
'style-src-attr': ["'self'"],
|
|
24
|
+
'style-src-elem': ["'self'"],
|
|
25
|
+
'worker-src': ["'self'"],
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
if (process.env.NODE_ENV === "development") {
|
|
29
|
+
directive_defaults["script-src"].push("'unsafe-eval'");
|
|
30
|
+
directive_defaults["connect-src"].push("ws:");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const directive_names = Object.keys(directive_defaults || {});
|
|
34
|
+
|
|
35
|
+
for (let i = 0; i < directive_names?.length; i += 1) {
|
|
36
|
+
const directive = directive_names[i];
|
|
37
|
+
directive_defaults[directive] = [
|
|
38
|
+
...(directive_defaults[directive] || []),
|
|
39
|
+
...(csp_config?.unrestrictedOrigins || csp_config?.unrestricted_origins || []),
|
|
40
|
+
...((csp_config?.directives && csp_config?.directives[directive]) || []),
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const csp = Object.keys(directive_defaults || {}).map((source) => {
|
|
45
|
+
return `${source} ${directive_defaults[source].join(" ")}`;
|
|
46
|
+
})?.join('; ');
|
|
47
|
+
|
|
48
|
+
res.setHeader('Content-Security-Policy', csp);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
next();
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default csp_middleware;
|