@joystick.js/node-canary 0.0.0-canary.47 → 0.0.0-canary.471
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,136 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { S3Client } from '@aws-sdk/client-s3';
|
|
4
|
+
import { Upload } from '@aws-sdk/lib-storage';
|
|
5
|
+
import emit_websocket_event from "../websockets/emit_event.js";
|
|
6
|
+
import float_to_decimal_place from "../../lib/float_to_decimal_place.js";
|
|
7
|
+
import path_exists from "../../lib/path_exists.js";
|
|
8
|
+
|
|
9
|
+
const { mkdir, writeFile } = fs.promises;
|
|
10
|
+
|
|
11
|
+
const upload_to_s3 = async (upload = {}, upload_options = {}, on_upload_progress = {}) => {
|
|
12
|
+
return new Promise(async (resolve, reject) => {
|
|
13
|
+
try {
|
|
14
|
+
const s3_upload = new Upload({
|
|
15
|
+
client: new S3Client({
|
|
16
|
+
region: upload?.s3?.region,
|
|
17
|
+
credentials:{
|
|
18
|
+
accessKeyId: upload?.s3?.accessKeyId || upload?.s3?.access_key_id,
|
|
19
|
+
secretAccessKey: upload?.s3?.secretAccessKey || upload?.s3?.secret_access_key,
|
|
20
|
+
},
|
|
21
|
+
}),
|
|
22
|
+
params: {
|
|
23
|
+
Bucket: upload?.s3?.bucket,
|
|
24
|
+
Key: upload.file_name,
|
|
25
|
+
Body: upload.content,
|
|
26
|
+
ContentType: upload.mime_type,
|
|
27
|
+
},
|
|
28
|
+
queueSize: 4, // NOTE: How many parts to upload concurrently.
|
|
29
|
+
partSize: 1024 * 1024 * 5, // NOTE: Size of each part (5MB).
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
let previous = 0;
|
|
33
|
+
|
|
34
|
+
s3_upload.on("httpUploadProgress", (progress) => {
|
|
35
|
+
on_upload_progress('s3', progress?.loaded - previous);
|
|
36
|
+
previous = progress?.loaded;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const upload_result = await s3_upload.done();
|
|
40
|
+
|
|
41
|
+
return resolve({
|
|
42
|
+
id: upload_options?.req?.headers['x-joystick-upload-id'],
|
|
43
|
+
provider: 's3',
|
|
44
|
+
url: upload_result?.Location,
|
|
45
|
+
size: upload?.fileSize,
|
|
46
|
+
file_name: upload?.file_name,
|
|
47
|
+
fileName: upload?.file_name,
|
|
48
|
+
original_file_name: upload?.original_file_name,
|
|
49
|
+
originalFileName: upload?.original_file_name,
|
|
50
|
+
mime_type: upload?.mime_type,
|
|
51
|
+
mimeType: upload?.mime_type,
|
|
52
|
+
});
|
|
53
|
+
} catch (error) {
|
|
54
|
+
reject(error?.message || 'There was an error uploading your file to Amazon S3. Check the server logs for more information.');
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const upload_to_local = async (upload = {}, upload_options = {}) => {
|
|
60
|
+
if (upload?.local?.path) {
|
|
61
|
+
return new Promise(async (resolve, reject) => {
|
|
62
|
+
try {
|
|
63
|
+
if (!(await path_exists(upload?.local?.path))) {
|
|
64
|
+
await mkdir(upload?.local?.path, { recursive: true });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const directory_path = path.dirname(`${upload?.local?.path}/${upload?.file_name}`);
|
|
68
|
+
|
|
69
|
+
if (!fs.existsSync(directory_path)) {
|
|
70
|
+
fs.mkdirSync(directory_path, { recursive: true });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const file_path = `${upload?.local?.path}/${upload?.file_name}` || `_uploads/${upload?.file_name}`;
|
|
74
|
+
|
|
75
|
+
await writeFile(file_path, upload.content);
|
|
76
|
+
|
|
77
|
+
resolve({
|
|
78
|
+
id: upload_options?.req?.headers['x-joystick-upload-id'],
|
|
79
|
+
provider: 'local',
|
|
80
|
+
url: file_path,
|
|
81
|
+
size: upload?.file_size,
|
|
82
|
+
file_name: upload?.file_name,
|
|
83
|
+
fileName: upload?.file_name,
|
|
84
|
+
original_file_name: upload?.original_file_name,
|
|
85
|
+
originalFileName: upload?.original_file_name,
|
|
86
|
+
mime_type: upload?.mime_type,
|
|
87
|
+
mimeType: upload?.mime_type,
|
|
88
|
+
});
|
|
89
|
+
} catch(error) {
|
|
90
|
+
reject(error);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const run_upload = async (run_upload_options = {}) => {
|
|
97
|
+
const uploads = [];
|
|
98
|
+
let existing_upload_progress = run_upload_options?.existing_upload_progress;
|
|
99
|
+
|
|
100
|
+
// NOTE: Use a closure here so we can pass it into the provider uploaders and avoid the
|
|
101
|
+
// existing_upload_progress value being cached (leading to incorrect progress percentage).
|
|
102
|
+
const on_upload_progress = (provider = '', chunk = 0) => {
|
|
103
|
+
const progress = existing_upload_progress + chunk;
|
|
104
|
+
const percentage = float_to_decimal_place(((progress / run_upload_options?.total_upload_size_all_providers) * 100));
|
|
105
|
+
|
|
106
|
+
emit_websocket_event(
|
|
107
|
+
`uploaders_${run_upload_options?.req?.headers['x-joystick-upload-id']}`,
|
|
108
|
+
'progress',
|
|
109
|
+
{ provider, progress: percentage }
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
existing_upload_progress += chunk;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
for (let i = 0; i < run_upload_options?.uploads?.length; i += 1) {
|
|
116
|
+
const upload = run_upload_options?.uploads[i];
|
|
117
|
+
|
|
118
|
+
if (upload?.providers?.includes('local')) {
|
|
119
|
+
// NOTE: Do not pass existing_upload_progress or onProgress to upload_to_local as the existing total reflects
|
|
120
|
+
// the transfer from the browser to the server (we assume that value is 1:1 with writing to disk
|
|
121
|
+
// as the disk write is near-instant).
|
|
122
|
+
const result = await upload_to_local(upload, run_upload_options);
|
|
123
|
+
|
|
124
|
+
uploads.push(result);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (upload?.providers?.includes('s3')) {
|
|
128
|
+
const result = await upload_to_s3(upload, run_upload_options, on_upload_progress);
|
|
129
|
+
uploads.push(result);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return uploads;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export default run_upload;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const allowed_options = [
|
|
2
|
+
'mimeTypes',
|
|
3
|
+
'mime_types',
|
|
4
|
+
'maxSizeInMegabytes',
|
|
5
|
+
'max_size_in_megabytes',
|
|
6
|
+
'fileName',
|
|
7
|
+
'file_name',
|
|
8
|
+
'providers',
|
|
9
|
+
'local',
|
|
10
|
+
's3',
|
|
11
|
+
'onBeforeUpload',
|
|
12
|
+
'on_before_upload',
|
|
13
|
+
'onAfterUpload',
|
|
14
|
+
'on_after_upload',
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
const allowed_local_options = [
|
|
18
|
+
'path',
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const allowed_s3_options = [
|
|
22
|
+
'region',
|
|
23
|
+
'accessKeyId',
|
|
24
|
+
'access_key_id',
|
|
25
|
+
'secretAccessKey',
|
|
26
|
+
'secret_access_key',
|
|
27
|
+
'bucket',
|
|
28
|
+
'acl',
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
const validate_options = (uploader_options = {}) => {
|
|
32
|
+
const errors = [];
|
|
33
|
+
const option_names = Object.keys(uploader_options || {});
|
|
34
|
+
|
|
35
|
+
for (let i = 0; i < option_names?.length; i += 1) {
|
|
36
|
+
const option_name = option_names[i];
|
|
37
|
+
if (!allowed_options.includes(option_name)) {
|
|
38
|
+
errors.push(`${option_name} is not an allowed uploader option.`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (uploader_options?.providers?.includes('local') && !uploader_options?.local) {
|
|
43
|
+
errors.push(`If an uploader provider is 'local', local object must be specified in uploader_options with a storage path.`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (uploader_options?.providers?.includes('s3') && !uploader_options?.s3) {
|
|
47
|
+
errors.push(`If an uploader provider is 's3', s3 object must be specified with configuration.`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (uploader_options?.provider?.includes('local') && uploader_options.local) {
|
|
51
|
+
const local_uploader_options = Object.keys(uploader_options?.local);
|
|
52
|
+
for (let i = 0; i < local_uploader_options?.length; i += 1) {
|
|
53
|
+
const local_uploader_option = local_uploader_options[i];
|
|
54
|
+
if (!allowed_local_options.includes(local_uploader_option)) {
|
|
55
|
+
errors.push(`local.${local_uploader_option} is not an allowed uploader option.`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (uploader_options?.provider?.includes('s3') && uploader_options.s3) {
|
|
61
|
+
const s3_uploader_options = Object.keys(uploader_options.s3 || {});
|
|
62
|
+
|
|
63
|
+
for (let i = 0; i < s3_uploader_options?.length; i += 1) {
|
|
64
|
+
const s3_uploader_option = s3_uploader_options[i];
|
|
65
|
+
if (!allowed_s3_options.includes(s3_uploader_option)) {
|
|
66
|
+
errors.push(`local.${s3_uploader_option} is not an allowed uploader option.`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return errors;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export default validate_options;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import log from "../../lib/log.js";
|
|
2
|
+
import track_function_call from "../../test/track_function_call.js";
|
|
3
|
+
import types from "../../lib/types.js";
|
|
4
|
+
|
|
5
|
+
const handle_check_upload = ({
|
|
6
|
+
uploader_name,
|
|
7
|
+
max_size_in_megabytes,
|
|
8
|
+
mime_types,
|
|
9
|
+
original_file_name,
|
|
10
|
+
file_size,
|
|
11
|
+
mime_type,
|
|
12
|
+
}) => {
|
|
13
|
+
const max_size_in_bytes = max_size_in_megabytes * 1024 * 1024;
|
|
14
|
+
const errors = [];
|
|
15
|
+
|
|
16
|
+
if (types.is_number(max_size_in_bytes) && file_size && file_size > max_size_in_bytes) {
|
|
17
|
+
const error = `The file ${original_file_name} is too big. Max file size is ${max_size_in_megabytes}MB.`;
|
|
18
|
+
|
|
19
|
+
log(error, {
|
|
20
|
+
level: 'danger',
|
|
21
|
+
docs: 'https://docs.cheatcode.co/joystick/node/uploaders',
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
errors.push({ status: 400, error: new Error(error), message: error, location: `uploaders.${uploader_name}` });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (mime_types?.length > 0 && !mime_types.includes(mime_type)) {
|
|
28
|
+
const error = `The MIME type for the file ${original_file_name} is not supported by the uploader ${uploader_name} (only ${mime_types?.join(', ')}).`;
|
|
29
|
+
|
|
30
|
+
log(error, {
|
|
31
|
+
level: 'danger',
|
|
32
|
+
docs: 'https://docs.cheatcode.co/joystick/node/uploaders',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
errors.push({ status: 400, error: new Error(error), message: error, location: `uploaders.${uploader_name}` });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return errors;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const handle_check_uploads = (uploads = []) => {
|
|
42
|
+
return uploads.flatMap((upload = {}) => {
|
|
43
|
+
return handle_check_upload(upload);
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const format_uploads = ({
|
|
48
|
+
files: uploads = [],
|
|
49
|
+
uploader_name = '',
|
|
50
|
+
uploader_options = {},
|
|
51
|
+
uploader_input = {},
|
|
52
|
+
}) => {
|
|
53
|
+
return Promise.all(uploads.map(async (upload) => {
|
|
54
|
+
// NOTE: The upload passed in here is controlled by multer, not Joystick.
|
|
55
|
+
// This is why property names are not converted to snake_case.
|
|
56
|
+
const file_extension = upload?.mimetype?.split('/').pop();
|
|
57
|
+
const file_name_is_function = types.is_function(uploader_options?.fileName) || types.is_function(uploader_options?.file_name);
|
|
58
|
+
const max_size_is_function = types.is_function(uploader_options?.maxSizeInMegabytes) || types.is_function(uploader_options?.max_size_in_megabytes);
|
|
59
|
+
|
|
60
|
+
if (file_name_is_function) {
|
|
61
|
+
track_function_call(`node.uploaders.${uploader_name}.file_name`, [{
|
|
62
|
+
uploader_input,
|
|
63
|
+
file_name: upload?.originalname,
|
|
64
|
+
file_size: upload?.size,
|
|
65
|
+
file_extension,
|
|
66
|
+
mime_type: upload?.mimetype
|
|
67
|
+
}]);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (max_size_is_function) {
|
|
71
|
+
track_function_call(`node.uploaders.${uploader_name}.max_size_in_megabytes`, [
|
|
72
|
+
{ input: uploader_input, upload }
|
|
73
|
+
]);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const max_size_in_megabytes = max_size_is_function ?
|
|
77
|
+
await (uploader_options?.maxSizeInMegabytes || uploader_options?.max_size_in_megabytes)({ input: uploader_input, upload }) :
|
|
78
|
+
(uploader_options?.maxSizeInMegabytes || uploader_options?.max_size_in_megabytes);
|
|
79
|
+
|
|
80
|
+
const file_name = file_name_is_function ?
|
|
81
|
+
(uploader_options.fileName || uploader_options?.file_name)({
|
|
82
|
+
input: uploader_input,
|
|
83
|
+
fileName: upload?.originalname,
|
|
84
|
+
file_name: upload?.originalname,
|
|
85
|
+
fileSize: upload?.size,
|
|
86
|
+
file_size: upload?.size,
|
|
87
|
+
fileExtension: file_extension,
|
|
88
|
+
file_extension,
|
|
89
|
+
mimeType: upload?.mimetype,
|
|
90
|
+
mime_type: upload?.mimetype
|
|
91
|
+
}) :
|
|
92
|
+
upload?.originalname;
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
uploader_name,
|
|
96
|
+
providers: uploader_options?.providers,
|
|
97
|
+
local: uploader_options?.local,
|
|
98
|
+
s3: uploader_options?.s3,
|
|
99
|
+
maxSizeInMegabytes: max_size_in_megabytes,
|
|
100
|
+
max_size_in_megabytes,
|
|
101
|
+
mimeTypes: uploader_options?.mimeTypes,
|
|
102
|
+
mime_types: uploader_options?.mimeTypes,
|
|
103
|
+
fileName: file_name,
|
|
104
|
+
file_name,
|
|
105
|
+
original_file_name: upload?.originalname,
|
|
106
|
+
originalFileName: upload?.originalname,
|
|
107
|
+
file_size: upload?.size,
|
|
108
|
+
fileSize: upload?.size,
|
|
109
|
+
mime_type: upload?.mimetype,
|
|
110
|
+
mimeType: upload?.mimetype,
|
|
111
|
+
content: upload?.buffer,
|
|
112
|
+
};
|
|
113
|
+
}));
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const validate_uploads = async (validate_uploads_options = {}) => {
|
|
117
|
+
const formatted_uploads = await format_uploads(validate_uploads_options);
|
|
118
|
+
const errors = handle_check_uploads(formatted_uploads);
|
|
119
|
+
|
|
120
|
+
if (errors?.length > 0) {
|
|
121
|
+
return { errors };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return formatted_uploads;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export default validate_uploads;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import types from "../../lib/types.js";
|
|
2
|
+
|
|
3
|
+
const emit_event = (emitter_id = '', event_name = '', payload = {}) => {
|
|
4
|
+
const emitters = joystick?.emitters[emitter_id];
|
|
5
|
+
|
|
6
|
+
if (types.is_array(emitters)) {
|
|
7
|
+
for (let i = 0; i < emitters?.length; i += 1) {
|
|
8
|
+
const emitter_recipient = emitters[i];
|
|
9
|
+
emitter_recipient.emit(event_name, payload);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default emit_event;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import emit_websocket_event from "./emit_event.js";
|
|
2
|
+
import track_function_call from "../../test/track_function_call.js";
|
|
3
|
+
|
|
4
|
+
const websockets = (server_name = '') => {
|
|
5
|
+
return {
|
|
6
|
+
send: (payload = {}, unique_connection_id = '') => {
|
|
7
|
+
const emitter_name = unique_connection_id ? `${server_name}_${unique_connection_id}` : server_name;
|
|
8
|
+
emit_websocket_event(emitter_name, 'message', payload);
|
|
9
|
+
track_function_call(`node.websockets.${server_name}.send`, [
|
|
10
|
+
payload
|
|
11
|
+
]);
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default websockets;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import EventEmitter from "events";
|
|
2
|
+
import queryString from 'query-string';
|
|
3
|
+
import * as WebSocket from "ws";
|
|
4
|
+
import track_function_call from "../../test/track_function_call.js";
|
|
5
|
+
import types from "../../lib/types.js";
|
|
6
|
+
|
|
7
|
+
const handle_websocket_connection_upgrade = (express_server = {}, websocket_servers = {}) => {
|
|
8
|
+
express_server.on('upgrade', (request, socket, head) => {
|
|
9
|
+
if (request?.url?.includes('/api/_websockets')) {
|
|
10
|
+
const websocket_name = (request?.url?.replace('/api/_websockets/', '')?.split('?') || [])[0];
|
|
11
|
+
const websocket_definition = websocket_servers[websocket_name];
|
|
12
|
+
|
|
13
|
+
if (websocket_definition) {
|
|
14
|
+
websocket_definition.server.handleUpgrade(request, socket, head, (socket) => {
|
|
15
|
+
websocket_definition.server.emit('connection', socket, request);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const handle_websocket_connection_events = (websocket_connection = {}, connection_params = {}, websocket_definition = {}) => {
|
|
23
|
+
const connection = Object.assign(websocket_connection, { params: connection_params });
|
|
24
|
+
|
|
25
|
+
if (types.is_function(websocket_definition?.onOpen) || types.is_function(websocket_definition?.on_open)) {
|
|
26
|
+
(websocket_definition?.onOpen || websocket_definition?.on_open)(connection);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// NOTE: This is a message being sent inbound by the client.
|
|
30
|
+
websocket_connection.on("message", (message) => {
|
|
31
|
+
const message_as_json = JSON.parse(message);
|
|
32
|
+
|
|
33
|
+
if (types.is_function(websocket_definition?.on_message)) {
|
|
34
|
+
websocket_definition?.on_message(message_as_json, websocket_connection);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
websocket_connection.on("close", (code = 0, reason = "") => {
|
|
39
|
+
if (types.is_function(websocket_definition?.on_close)) {
|
|
40
|
+
websocket_definition?.on_close(code, reason?.toString(), websocket_connection);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const register_websocket_event_emitter = (websocket_name = '', connection_params = {}, websocket_connection = {}) => {
|
|
46
|
+
const emitter = new EventEmitter();
|
|
47
|
+
const emitter_id = connection_params?.id ? `${websocket_name}_${connection_params?.id}` : websocket_name;
|
|
48
|
+
|
|
49
|
+
if (joystick?.emitters && joystick?.emitters[emitter_id]) {
|
|
50
|
+
joystick.emitters[emitter_id].push(emitter);
|
|
51
|
+
} else {
|
|
52
|
+
joystick.emitters = {
|
|
53
|
+
...(joystick?.emitters || {}),
|
|
54
|
+
[emitter_id]: [emitter],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// NOTE: This is a message being sent outbound by the server. This is already contextualized
|
|
59
|
+
// to a unique ID (if applicable) via the joystick.emitters.<emitterId> pattern above.
|
|
60
|
+
emitter.on("message", (message = {}) => {
|
|
61
|
+
websocket_connection.send(JSON.stringify(message));
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// NOTE: This is an internal emitter for handling progress events via uploaders.
|
|
65
|
+
emitter.on("progress", (progress = {}) => {
|
|
66
|
+
websocket_connection.send(
|
|
67
|
+
JSON.stringify({ type: "PROGRESS", ...progress })
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const get_websocket_connection_params = (websocket_connection_request = {}) => {
|
|
73
|
+
const [_path, params] = websocket_connection_request?.url?.split("?");
|
|
74
|
+
return queryString.parse(params);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const handle_websocket_connection = (websocket_name = '', websocket_definition = {}) => {
|
|
78
|
+
websocket_definition?.server.on('connection', (websocket_connection = {}, websocket_connection_request = {}) => {
|
|
79
|
+
const connection_params = get_websocket_connection_params(websocket_connection_request);
|
|
80
|
+
register_websocket_event_emitter(websocket_name, connection_params, websocket_connection);
|
|
81
|
+
handle_websocket_connection_events(websocket_connection, connection_params, websocket_definition);
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const handle_on_close_event = (user_websocket_name = '', user_websocket_definition = {}, websocket_event_args = []) => {
|
|
86
|
+
track_function_call(`node.websockets.${user_websocket_name}.on_close`, websocket_event_args);
|
|
87
|
+
return (user_websocket_definition?.onClose || user_websocket_definition?.on_close) ?
|
|
88
|
+
(user_websocket_definition?.onClose || user_websocket_definition?.on_close)(...websocket_event_args) :
|
|
89
|
+
null;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const handle_on_message_event = (user_websocket_name = '', user_websocket_definition = {}, websocket_event_args = []) => {
|
|
93
|
+
track_function_call(`node.websockets.${user_websocket_name}.on_message`, websocket_event_args);
|
|
94
|
+
return (user_websocket_definition?.onMessage || user_websocket_definition?.on_message) ?
|
|
95
|
+
(user_websocket_definition?.onMessage || user_websocket_definition?.on_message)(...websocket_event_args) :
|
|
96
|
+
null;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const handle_on_open_event = (user_websocket_name = '', user_websocket_definition = {}, websocket_event_args = []) => {
|
|
100
|
+
track_function_call(`node.websockets.${user_websocket_name}.on_open`, websocket_event_args);
|
|
101
|
+
return (user_websocket_definition?.onOpen || user_websocket_definition?.on_open) ?
|
|
102
|
+
(user_websocket_definition?.onOpen || user_websocket_definition?.on_open)(...websocket_event_args) :
|
|
103
|
+
null;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const get_websocket_server = (websocket_name = '') => {
|
|
107
|
+
return new WebSocket.WebSocketServer({
|
|
108
|
+
noServer: true,
|
|
109
|
+
path: `/api/_websockets/${websocket_name}`,
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const get_websocket_servers = (user_websocket_definitions = {}) => {
|
|
114
|
+
return {
|
|
115
|
+
uploaders: {
|
|
116
|
+
server: get_websocket_server('uploaders'),
|
|
117
|
+
},
|
|
118
|
+
...Object.entries(user_websocket_definitions || {}).reduce(
|
|
119
|
+
(websockets_to_define = {}, [user_websocket_name, user_websocket_definition]) => {
|
|
120
|
+
websockets_to_define[user_websocket_name] = {
|
|
121
|
+
server: get_websocket_server(user_websocket_name),
|
|
122
|
+
on_open: (...websocket_event_args) => handle_on_open_event(
|
|
123
|
+
user_websocket_name,
|
|
124
|
+
user_websocket_definition,
|
|
125
|
+
websocket_event_args,
|
|
126
|
+
),
|
|
127
|
+
onOpen: (...websocket_event_args) => handle_on_open_event(
|
|
128
|
+
user_websocket_name,
|
|
129
|
+
user_websocket_definition,
|
|
130
|
+
websocket_event_args,
|
|
131
|
+
),
|
|
132
|
+
on_message: (...websocket_event_args) => handle_on_message_event(
|
|
133
|
+
user_websocket_name,
|
|
134
|
+
user_websocket_definition,
|
|
135
|
+
websocket_event_args,
|
|
136
|
+
),
|
|
137
|
+
onMessage: (...websocket_event_args) => handle_on_message_event(
|
|
138
|
+
user_websocket_name,
|
|
139
|
+
user_websocket_definition,
|
|
140
|
+
websocket_event_args,
|
|
141
|
+
),
|
|
142
|
+
on_close: (...websocket_event_args) => handle_on_close_event(
|
|
143
|
+
user_websocket_name,
|
|
144
|
+
user_websocket_definition,
|
|
145
|
+
websocket_event_args,
|
|
146
|
+
),
|
|
147
|
+
onClose: (...websocket_event_args) => handle_on_close_event(
|
|
148
|
+
user_websocket_name,
|
|
149
|
+
user_websocket_definition,
|
|
150
|
+
websocket_event_args,
|
|
151
|
+
),
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
return websockets_to_define;
|
|
155
|
+
},
|
|
156
|
+
{}
|
|
157
|
+
),
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const register = (user_websocket_definitions = {}, app_instance = {}) => {
|
|
162
|
+
const websocket_servers_to_create = get_websocket_servers(user_websocket_definitions);
|
|
163
|
+
const websocket_servers = Object.entries(websocket_servers_to_create);
|
|
164
|
+
|
|
165
|
+
for (let i = 0; i < websocket_servers?.length; i += 1) {
|
|
166
|
+
const [websocket_name, websocket_definition] = websocket_servers[i];
|
|
167
|
+
handle_websocket_connection(websocket_name, websocket_definition);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// NOTE: Doing this here is intentional. Because the upgrade emits a connection event,
|
|
171
|
+
// the connection event handler must be defined first (what we're doing above).
|
|
172
|
+
handle_websocket_connection_upgrade(app_instance.express.server, websocket_servers_to_create);
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export default register;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import _accounts from './app/accounts/index.js';
|
|
3
|
+
import _action from "./action/index.js";
|
|
4
|
+
import _escape_html from './lib/escape_html.js';
|
|
5
|
+
import _fixture from './app/fixture/index.js';
|
|
6
|
+
import _sql from './app/databases/sql.js';
|
|
7
|
+
import _validate_input from './app/api/validate_input.js';
|
|
8
|
+
import _websockets from './app/websockets/index.js';
|
|
9
|
+
import app from './app/index.js';
|
|
10
|
+
import generate_id from './lib/generate_id.js';
|
|
11
|
+
import get_origin from './lib/get_origin.js';
|
|
12
|
+
import load_settings from './app/settings/load.js';
|
|
13
|
+
import node_path_polyfills from './lib/node_path_polyfills.js';
|
|
14
|
+
import path_exists from './lib/path_exists.js';
|
|
15
|
+
import send_email from './app/email/send.js';
|
|
16
|
+
|
|
17
|
+
const { readFile } = fs.promises;
|
|
18
|
+
|
|
19
|
+
// NOTE: Ensure backwards compatibility for existing apps by offering
|
|
20
|
+
// original camelCase versions of methods.
|
|
21
|
+
export const accounts = {
|
|
22
|
+
..._accounts,
|
|
23
|
+
deleteUser: _accounts.delete_user,
|
|
24
|
+
recoverPassword: _accounts.recover_password,
|
|
25
|
+
resetPassword: _accounts.reset_password,
|
|
26
|
+
sendEmailVerification: _accounts.send_email_verification,
|
|
27
|
+
setPassword: _accounts.set_password,
|
|
28
|
+
verifyEmail: _accounts.verify_email,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const action = _action;
|
|
32
|
+
|
|
33
|
+
export const __dirname = node_path_polyfills.__dirname;
|
|
34
|
+
|
|
35
|
+
export const email = {
|
|
36
|
+
send: send_email,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const escape_html = _escape_html;
|
|
40
|
+
|
|
41
|
+
export const __filename = node_path_polyfills.__filename;
|
|
42
|
+
|
|
43
|
+
export const fixture = _fixture;
|
|
44
|
+
|
|
45
|
+
export const origin = get_origin();
|
|
46
|
+
|
|
47
|
+
export const push = {
|
|
48
|
+
continent: (await path_exists('/root/push/continent.txt')) ? (await readFile('/root/push/continent.txt', 'utf-8'))?.replace('\n', '') : null,
|
|
49
|
+
instance_token: (await path_exists('/root/push/instance_token.txt')) ? (await readFile('/root/push/instance_token.txt', 'utf-8'))?.replace('\n', '') : null,
|
|
50
|
+
current_version: (await path_exists('/root/push/versions/current')) ? (await readFile('/root/push/versions/current', 'utf-8'))?.replace('\n', '') : null,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const settings = load_settings();
|
|
54
|
+
|
|
55
|
+
export const sql = _sql;
|
|
56
|
+
|
|
57
|
+
export const validate_input = _validate_input;
|
|
58
|
+
|
|
59
|
+
export const websockets = _websockets;
|
|
60
|
+
|
|
61
|
+
const joystick = {
|
|
62
|
+
app,
|
|
63
|
+
accounts,
|
|
64
|
+
action,
|
|
65
|
+
email,
|
|
66
|
+
emitters: {},
|
|
67
|
+
escape_html,
|
|
68
|
+
fixture,
|
|
69
|
+
id: generate_id,
|
|
70
|
+
origin,
|
|
71
|
+
push,
|
|
72
|
+
settings,
|
|
73
|
+
sql,
|
|
74
|
+
validate_input,
|
|
75
|
+
websockets,
|
|
76
|
+
...node_path_polyfills,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
global.joystick = joystick;
|
|
80
|
+
|
|
81
|
+
export default joystick;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
const camel_pascal_to_snake = (string = '') => {
|
|
2
2
|
return string.replace(/[A-Z]/g, (letter, index) => {
|
|
3
3
|
return index == 0 ? letter.toLowerCase() : `_${letter.toLowerCase()}`;
|
|
4
4
|
});
|
|
5
5
|
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
6
|
+
|
|
7
|
+
export default camel_pascal_to_snake;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const HTML_ENTITY_MAP = {
|
|
2
|
+
'&': '&',
|
|
3
|
+
'<': '<',
|
|
4
|
+
'>': '>',
|
|
5
|
+
'"': '"',
|
|
6
|
+
"'": ''',
|
|
7
|
+
'/': '/',
|
|
8
|
+
'`': '`',
|
|
9
|
+
'=': '='
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const KILOBYTE = 1000;
|
|
13
|
+
export const MEGABYTE = KILOBYTE * 1000;
|
|
14
|
+
|
|
15
|
+
const constants = {
|
|
16
|
+
HTML_ENTITY_MAP,
|
|
17
|
+
KILOBYTE,
|
|
18
|
+
MEGABYTE,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default constants;
|