@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,294 @@
|
|
|
1
|
+
import cron from 'node-cron';
|
|
2
|
+
import handle_cleanup_queues from '../../postgresql/handle_cleanup_queues.js';
|
|
3
|
+
import timestamps from "../../../../lib/timestamps.js";
|
|
4
|
+
import wait from '../../../../lib/wait.js';
|
|
5
|
+
|
|
6
|
+
const queues = {
|
|
7
|
+
add_job: async function (job_to_add = {}) {
|
|
8
|
+
const db = this?.db;
|
|
9
|
+
|
|
10
|
+
// NOTE: Ensure that table was created via initialize_database on first startup. If not, wait 1s
|
|
11
|
+
// while PostgreSQL creates the table.
|
|
12
|
+
const [existing_table] = await db?.query(`SELECT * FROM information_schema.tables WHERE table_name = $1`, [
|
|
13
|
+
`queue_${this.queue.name}`
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
if (!existing_table) {
|
|
17
|
+
await wait(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return db?.query(`
|
|
21
|
+
INSERT INTO queue_${this.queue.name} (
|
|
22
|
+
_id,
|
|
23
|
+
status,
|
|
24
|
+
environment,
|
|
25
|
+
job,
|
|
26
|
+
payload,
|
|
27
|
+
next_run_at,
|
|
28
|
+
attempts
|
|
29
|
+
) VALUES (
|
|
30
|
+
$1, $2, $3, $4, $5, $6, $7
|
|
31
|
+
)
|
|
32
|
+
`, [
|
|
33
|
+
job_to_add?._id,
|
|
34
|
+
job_to_add?.status,
|
|
35
|
+
job_to_add?.environment,
|
|
36
|
+
job_to_add?.job,
|
|
37
|
+
JSON.stringify(job_to_add?.payload),
|
|
38
|
+
job_to_add?.nextRunAt || job_to_add?.next_run_at,
|
|
39
|
+
0
|
|
40
|
+
]);
|
|
41
|
+
},
|
|
42
|
+
count_jobs: async function (status = '') {
|
|
43
|
+
const db = this?.db;
|
|
44
|
+
|
|
45
|
+
const [jobs] = await db?.query(`
|
|
46
|
+
SELECT
|
|
47
|
+
count(*)
|
|
48
|
+
FROM
|
|
49
|
+
queue_${this.queue.name}
|
|
50
|
+
WHERE
|
|
51
|
+
status = $1
|
|
52
|
+
AND
|
|
53
|
+
locked_by = $2
|
|
54
|
+
`, [
|
|
55
|
+
status,
|
|
56
|
+
this.machine_id
|
|
57
|
+
]);
|
|
58
|
+
|
|
59
|
+
return Promise.resolve(jobs.count);
|
|
60
|
+
},
|
|
61
|
+
delete_job: function (job_id = '') {
|
|
62
|
+
const db = this?.db;
|
|
63
|
+
|
|
64
|
+
return db?.query(`
|
|
65
|
+
DELETE FROM
|
|
66
|
+
queue_${this.queue.name}
|
|
67
|
+
WHERE
|
|
68
|
+
_id = $1
|
|
69
|
+
`, [
|
|
70
|
+
job_id
|
|
71
|
+
]);
|
|
72
|
+
},
|
|
73
|
+
delete_incomplete_jobs_for_machine: function () {
|
|
74
|
+
const db = this?.db;
|
|
75
|
+
return db?.query(`
|
|
76
|
+
DELETE FROM
|
|
77
|
+
queue_${this.queue.name}
|
|
78
|
+
WHERE
|
|
79
|
+
status = ANY($1)
|
|
80
|
+
AND
|
|
81
|
+
locked_by = $2
|
|
82
|
+
`, [
|
|
83
|
+
['incomplete', 'running'],
|
|
84
|
+
this.machine_id,
|
|
85
|
+
]);
|
|
86
|
+
},
|
|
87
|
+
get_jobs: function (query = {}) {
|
|
88
|
+
const db = this?.db;
|
|
89
|
+
|
|
90
|
+
return db?.query(`
|
|
91
|
+
SELECT * FROM
|
|
92
|
+
queue_${this.queue.name}
|
|
93
|
+
${query?.status ? `
|
|
94
|
+
WHERE
|
|
95
|
+
status = $1
|
|
96
|
+
AND
|
|
97
|
+
environment = $2
|
|
98
|
+
` : ''}
|
|
99
|
+
`, [
|
|
100
|
+
query?.status,
|
|
101
|
+
process.env.NODE_ENV,
|
|
102
|
+
]);
|
|
103
|
+
},
|
|
104
|
+
get_next_job_to_run: async function () {
|
|
105
|
+
const db = this?.db;
|
|
106
|
+
|
|
107
|
+
const [next_job] = await db?.query(`
|
|
108
|
+
SELECT * FROM
|
|
109
|
+
queue_${this.queue.name}
|
|
110
|
+
WHERE
|
|
111
|
+
status = $1
|
|
112
|
+
AND
|
|
113
|
+
environment = $2
|
|
114
|
+
AND
|
|
115
|
+
next_run_at::timestamp <= $3
|
|
116
|
+
AND
|
|
117
|
+
locked_by IS NULL
|
|
118
|
+
ORDER BY
|
|
119
|
+
next_run_at ASC
|
|
120
|
+
`, [
|
|
121
|
+
'pending',
|
|
122
|
+
process.env.NODE_ENV,
|
|
123
|
+
timestamps.get_current_time()
|
|
124
|
+
]);
|
|
125
|
+
|
|
126
|
+
if (next_job?._id) {
|
|
127
|
+
await db?.query(`
|
|
128
|
+
UPDATE
|
|
129
|
+
queue_${this.queue.name}
|
|
130
|
+
SET
|
|
131
|
+
status = $1,
|
|
132
|
+
started_at = $2,
|
|
133
|
+
locked_by = $3
|
|
134
|
+
WHERE
|
|
135
|
+
_id = $4
|
|
136
|
+
`, [
|
|
137
|
+
'running',
|
|
138
|
+
timestamps.get_current_time(),
|
|
139
|
+
this.machine_id,
|
|
140
|
+
next_job?._id,
|
|
141
|
+
]);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return next_job ? {
|
|
145
|
+
...next_job,
|
|
146
|
+
payload: next_job?.payload ? JSON.parse(next_job?.payload || '') : {},
|
|
147
|
+
} : {};
|
|
148
|
+
},
|
|
149
|
+
initialize_database: async function () {
|
|
150
|
+
// NOTE: Add this check to avoid clustered apps from creating a race condition
|
|
151
|
+
// when initializing indexes below (they step on each other's toes and cause
|
|
152
|
+
// errors to be thrown). Only a primary or 1st worker should run this.
|
|
153
|
+
|
|
154
|
+
if (cluster.isPrimary || (cluster.isWorker && cluster.worker.id === 1)) {
|
|
155
|
+
const db = this?.db;
|
|
156
|
+
|
|
157
|
+
await db?.query(`
|
|
158
|
+
CREATE TABLE IF NOT EXISTS queue_${this.queue.name} (
|
|
159
|
+
_id text PRIMARY KEY,
|
|
160
|
+
status text,
|
|
161
|
+
job text,
|
|
162
|
+
payload text,
|
|
163
|
+
next_run_at text,
|
|
164
|
+
locked_by text,
|
|
165
|
+
started_at text,
|
|
166
|
+
completed_at text,
|
|
167
|
+
failed_at text,
|
|
168
|
+
error text,
|
|
169
|
+
environment text,
|
|
170
|
+
attempts smallint
|
|
171
|
+
)
|
|
172
|
+
`);
|
|
173
|
+
|
|
174
|
+
// NOTE: Add additional attempts field as a standalone column to support existing queue_ tables.
|
|
175
|
+
await db?.query(`ALTER TABLE queue_${this.queue.name} ADD COLUMN IF NOT EXISTS environment text`);
|
|
176
|
+
await db?.query(`ALTER TABLE queue_${this.queue.name} ADD COLUMN IF NOT EXISTS attempts smallint`);
|
|
177
|
+
|
|
178
|
+
await db?.query(`CREATE INDEX IF NOT EXISTS status_index ON queue_${this.queue.name} (status)`);
|
|
179
|
+
await db?.query(`CREATE INDEX IF NOT EXISTS status_next_run_at_index ON queue_${this.queue.name} (status, next_run_at)`);
|
|
180
|
+
await db?.query(`CREATE INDEX IF NOT EXISTS next_job_index ON queue_${this.queue.name} (status, environment, next_run_at, locked_by)`);
|
|
181
|
+
|
|
182
|
+
await db?.query(`CREATE INDEX IF NOT EXISTS completed_at_index ON queue_${this.queue.name} (completed_at)`);
|
|
183
|
+
await db?.query(`CREATE INDEX IF NOT EXISTS failed_at_index ON queue_${this.queue.name} (failed_at)`);
|
|
184
|
+
|
|
185
|
+
// NOTE: PostgreSQL does NOT have a TTL index or event-based row expiration feature,
|
|
186
|
+
// so we "polyfill" here with 30 second cron jobs to do the cleanup for us.
|
|
187
|
+
if (this.queue.options?.cleanup?.completedAfterSeconds || this.queue.options?.cleanup?.completed_after_seconds) {
|
|
188
|
+
cron.schedule('*/30 * * * * *', () => {
|
|
189
|
+
handle_cleanup_queues({
|
|
190
|
+
database: db,
|
|
191
|
+
table: `queue_${this.queue.name}`,
|
|
192
|
+
seconds: this.queue.options?.cleanup?.completedAfterSeconds || this.queue.options?.cleanup?.completed_after_seconds,
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (this.queue.options?.cleanup?.failedAfterSeconds || this.queue.options?.cleanup?.failed_after_seconds) {
|
|
198
|
+
cron.schedule('*/30 * * * * *', () => {
|
|
199
|
+
handle_cleanup_queues({
|
|
200
|
+
database: db,
|
|
201
|
+
table: `queue_${this.queue.name}`,
|
|
202
|
+
seconds: this.queue.options?.cleanup?.failedAfterSeconds || this.queue.options?.cleanup?.failed_after_seconds,
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
log_attempt: function (job_id = '') {
|
|
209
|
+
const db = this?.db;
|
|
210
|
+
return db?.query(`
|
|
211
|
+
UPDATE
|
|
212
|
+
queue_${this.queue.name}
|
|
213
|
+
SET
|
|
214
|
+
attempts = attempts + 1
|
|
215
|
+
WHERE
|
|
216
|
+
_id = $1
|
|
217
|
+
`, [
|
|
218
|
+
job_id,
|
|
219
|
+
]);
|
|
220
|
+
},
|
|
221
|
+
requeue_job: function (job_id = '', next_run_at = null) {
|
|
222
|
+
const db = this?.db;
|
|
223
|
+
return db?.query(`
|
|
224
|
+
UPDATE
|
|
225
|
+
queue_${this.queue.name}
|
|
226
|
+
SET
|
|
227
|
+
status = $1,
|
|
228
|
+
next_run_at = $2,
|
|
229
|
+
locked_by = $3
|
|
230
|
+
WHERE
|
|
231
|
+
_id = $4
|
|
232
|
+
`, [
|
|
233
|
+
'pending',
|
|
234
|
+
next_run_at,
|
|
235
|
+
null,
|
|
236
|
+
job_id,
|
|
237
|
+
]);
|
|
238
|
+
},
|
|
239
|
+
set_job_completed: function (job_id = '') {
|
|
240
|
+
const db = this?.db;
|
|
241
|
+
return db?.query(`
|
|
242
|
+
UPDATE
|
|
243
|
+
queue_${this.queue.name}
|
|
244
|
+
SET
|
|
245
|
+
status = $1,
|
|
246
|
+
completed_at = $2
|
|
247
|
+
WHERE
|
|
248
|
+
_id = $3
|
|
249
|
+
`, [
|
|
250
|
+
'completed',
|
|
251
|
+
timestamps.get_current_time(),
|
|
252
|
+
job_id
|
|
253
|
+
]);
|
|
254
|
+
},
|
|
255
|
+
set_job_failed: function (job_id = '', error = '') {
|
|
256
|
+
const db = this?.db;
|
|
257
|
+
return db?.query(`
|
|
258
|
+
UPDATE
|
|
259
|
+
queue_${this.queue.name}
|
|
260
|
+
SET
|
|
261
|
+
status = $1,
|
|
262
|
+
failed_at = $2,
|
|
263
|
+
error = $3
|
|
264
|
+
WHERE
|
|
265
|
+
_id = $4
|
|
266
|
+
`, [
|
|
267
|
+
'failed',
|
|
268
|
+
timestamps.get_current_time(),
|
|
269
|
+
error,
|
|
270
|
+
job_id,
|
|
271
|
+
]);
|
|
272
|
+
},
|
|
273
|
+
set_jobs_for_machine_pending: function () {
|
|
274
|
+
const db = this?.db;
|
|
275
|
+
return db?.query(`
|
|
276
|
+
UPDATE
|
|
277
|
+
queue_${this.queue.name}
|
|
278
|
+
SET
|
|
279
|
+
status = $1,
|
|
280
|
+
locked_by = $2
|
|
281
|
+
WHERE
|
|
282
|
+
status = ANY($3)
|
|
283
|
+
AND
|
|
284
|
+
locked_by = $4
|
|
285
|
+
`, [
|
|
286
|
+
'pending',
|
|
287
|
+
null,
|
|
288
|
+
['pending', 'running'],
|
|
289
|
+
this.machine_id,
|
|
290
|
+
]);
|
|
291
|
+
},
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
export default queues;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import generate_id from "../../../../lib/generate_id.js";
|
|
2
|
+
|
|
3
|
+
const sessions = {
|
|
4
|
+
create_session: async (input = {}) => {
|
|
5
|
+
const session_id = generate_id();
|
|
6
|
+
|
|
7
|
+
await process.databases._sessions?.query(`
|
|
8
|
+
INSERT INTO
|
|
9
|
+
sessions (
|
|
10
|
+
session_id,
|
|
11
|
+
csrf,
|
|
12
|
+
created_at
|
|
13
|
+
)
|
|
14
|
+
VALUES ($1, $2, $3)
|
|
15
|
+
`, [
|
|
16
|
+
session_id,
|
|
17
|
+
generate_id(32),
|
|
18
|
+
new Date().toISOString(),
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
return session_id;
|
|
22
|
+
},
|
|
23
|
+
get_session: async (input = {}) => {
|
|
24
|
+
const [session] = await process.databases._sessions?.query(`
|
|
25
|
+
SELECT * FROM
|
|
26
|
+
sessions
|
|
27
|
+
WHERE
|
|
28
|
+
session_id = $1
|
|
29
|
+
`, [
|
|
30
|
+
input?.session_id,
|
|
31
|
+
]);
|
|
32
|
+
|
|
33
|
+
return session;
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default sessions;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import get_target_database_connection from "../get_target_database_connection.js";
|
|
2
|
+
import query_map from "./map.js";
|
|
3
|
+
|
|
4
|
+
const sessions_query = async (query_name = "", inputs = {}) => {
|
|
5
|
+
const sessions_database = get_target_database_connection('sessions');
|
|
6
|
+
const query_map_for_database = sessions_database && query_map && query_map[sessions_database?.provider] && query_map[sessions_database?.provider]?.sessions;
|
|
7
|
+
const query = query_map_for_database && query_map_for_database[query_name];
|
|
8
|
+
|
|
9
|
+
if (sessions_database?.connection && query) {
|
|
10
|
+
const response = await query_map_for_database[query_name](inputs, sessions_database?.connection);
|
|
11
|
+
return Promise.resolve(response);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return null;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default sessions_query;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import connect_mongodb from "./mongodb/connect.js";
|
|
2
|
+
import connect_postgresql from "./postgresql/connect.js";
|
|
3
|
+
|
|
4
|
+
const register_database = async (database_from_settings = {}, database_port = 2610, has_multiple_of_provider = false) => {
|
|
5
|
+
if (database_from_settings?.provider === 'mongodb') {
|
|
6
|
+
const mongodb_connection = await connect_mongodb(database_from_settings, database_port);
|
|
7
|
+
process.databases = {
|
|
8
|
+
...(process.databases || {}),
|
|
9
|
+
mongodb: !has_multiple_of_provider ? mongodb_connection : {
|
|
10
|
+
...(process?.databases?.mongodb || {}),
|
|
11
|
+
[database_from_settings?.name || `mongodb_${database_port}`]: mongodb_connection,
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (database_from_settings?.provider === 'postgresql') {
|
|
17
|
+
const postgresql_connection = await connect_postgresql(database_from_settings, database_port);
|
|
18
|
+
process.databases = {
|
|
19
|
+
...(process.databases || {}),
|
|
20
|
+
postgresql: !has_multiple_of_provider ? postgresql_connection : {
|
|
21
|
+
...(process?.databases?.postgresql || {}),
|
|
22
|
+
[database_from_settings?.name || `postgresql_${database_port}`]: postgresql_connection,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return Promise.resolve(process.databases);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default register_database;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const sql = {
|
|
2
|
+
create_table: (options = {}) => {
|
|
3
|
+
const columns = Object.entries(options?.columns)?.map(([column_name, column_type]) => {
|
|
4
|
+
return `${column_name} ${column_type}`;
|
|
5
|
+
})?.join(',');
|
|
6
|
+
|
|
7
|
+
return {
|
|
8
|
+
statement: `CREATE TABLE IF NOT EXISTS ${options?.table} (${columns})`,
|
|
9
|
+
columns,
|
|
10
|
+
};
|
|
11
|
+
},
|
|
12
|
+
add_column: (options = {}) => {
|
|
13
|
+
return {
|
|
14
|
+
statement: `ALTER TABLE ${options?.table} ADD COLUMN IF NOT EXISTS ${options?.column_name} ${options?.column_type}`,
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
select: (options = {}) => {
|
|
18
|
+
const column_names = Array.isArray(options?.columns) ? options?.columns?.join(',') : '*';
|
|
19
|
+
const whereEntries = Object.entries(options?.where);
|
|
20
|
+
const where = whereEntries?.map(([key], index) => {
|
|
21
|
+
return `${key} = $${index + 1}`;
|
|
22
|
+
})?.join(',');
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
statement: `SELECT ${column_names} FROM ${options?.table} ${options?.where ? `WHERE ${where}` : ''}`,
|
|
26
|
+
column_names,
|
|
27
|
+
where,
|
|
28
|
+
values: Object.values(options?.where),
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
insert: (options = {}) => {
|
|
32
|
+
const column_names = Object.keys(options?.data)?.join(',');
|
|
33
|
+
const value_placeholders = Object.keys(options?.data)?.map((_, index) => `$${index + 1}`)?.join(',');
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
statement: `INSERT INTO ${options?.table} (${column_names}) VALUES (${value_placeholders})`,
|
|
37
|
+
column_names,
|
|
38
|
+
value_placeholders,
|
|
39
|
+
values: Object.values(options?.data),
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
update: (options = {}) => {
|
|
43
|
+
const whereEntries = Object.entries(options?.where);
|
|
44
|
+
const sets = Object.keys(options?.data).map((key, index) => {
|
|
45
|
+
return `${key} = $${whereEntries.length + index + 1}`;
|
|
46
|
+
})?.join(',');
|
|
47
|
+
const where = whereEntries?.map(([key], index) => {
|
|
48
|
+
return `${key} = $${index + 1}`;
|
|
49
|
+
})?.join(',');
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
statement: `UPDATE ${options?.table} SET ${sets} WHERE ${where}`,
|
|
53
|
+
sets,
|
|
54
|
+
where,
|
|
55
|
+
values: [
|
|
56
|
+
...(Object.values(options?.where)),
|
|
57
|
+
...(Object.values(options?.data))
|
|
58
|
+
],
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export default sql;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { htmlToText } from "html-to-text";
|
|
3
|
+
import juice from "juice";
|
|
4
|
+
import nodemailer from "nodemailer";
|
|
5
|
+
import dynamic_import from "../../lib/dynamic_import.js";
|
|
6
|
+
import get_joystick_build_path from "../../lib/get_joystick_build_path.js";
|
|
7
|
+
import get_translations from "../../lib/get_translations.js";
|
|
8
|
+
import load_settings from "../settings/load.js";
|
|
9
|
+
import path_exists from "../../lib/path_exists.js";
|
|
10
|
+
import ssr from "../ssr/index.js";
|
|
11
|
+
import track_function_call from "../../test/track_function_call.js";
|
|
12
|
+
import validate_smtp_settings from "./validate_smtp_settings.js";
|
|
13
|
+
|
|
14
|
+
const settings = load_settings();
|
|
15
|
+
|
|
16
|
+
const send_email = async (send_email_options = {}, smtp_overrides = {}) => {
|
|
17
|
+
if (process.env.NODE_ENV === 'test') {
|
|
18
|
+
// NOTE: In a test environment, we do not actually want to send an email. Instead,
|
|
19
|
+
// track the call and then return.
|
|
20
|
+
track_function_call('node.email.send', [send_email_options]);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const valid_smtp_settings = validate_smtp_settings(settings?.config?.email?.smtp);
|
|
25
|
+
|
|
26
|
+
if (!valid_smtp_settings) {
|
|
27
|
+
console.warn(chalk.redBright("Invalid SMTP settings. Cannot send email."));
|
|
28
|
+
return Promise.resolve(null);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// NOTE: Check the port number as nodemailer notes most SMTP providers required a plaintext
|
|
32
|
+
// connection *first* before upgrading the connection via STARTTLS. This prevents an SSL error
|
|
33
|
+
// when sending emails via SMTP port 587 or 25. See: https://nodemailer.com/smtp/#tls-options.
|
|
34
|
+
const smtp_port = parseInt(smtp_overrides?.port || settings?.config?.email?.smtp?.port, 10);
|
|
35
|
+
const should_use_secure = smtp_port === 465 || ![25, 587].includes(smtp_port);
|
|
36
|
+
|
|
37
|
+
const smtp = valid_smtp_settings
|
|
38
|
+
? nodemailer.createTransport({
|
|
39
|
+
host: smtp_overrides?.host || settings?.config?.email?.smtp?.host,
|
|
40
|
+
port: smtp_port,
|
|
41
|
+
secure: should_use_secure,
|
|
42
|
+
auth: {
|
|
43
|
+
user: smtp_overrides?.username || settings?.config?.email?.smtp?.username,
|
|
44
|
+
pass: smtp_overrides?.password || settings?.config?.email?.smtp?.password,
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
: null;
|
|
48
|
+
|
|
49
|
+
const joystick_build_path = get_joystick_build_path();
|
|
50
|
+
const template_path = `${joystick_build_path}email/${send_email_options?.template}.js`;
|
|
51
|
+
const template_exists = send_email_options?.template && await path_exists(template_path);
|
|
52
|
+
|
|
53
|
+
const nodemailer_options = {
|
|
54
|
+
from: settings?.config?.email?.from,
|
|
55
|
+
...send_email_options,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
if (smtp_overrides?.headers) {
|
|
59
|
+
nodemailer_options.headers = smtp_overrides?.headers;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (template_exists) {
|
|
63
|
+
const email_template_component = await dynamic_import(`${template_path}?v=${new Date().getTime()}`);
|
|
64
|
+
|
|
65
|
+
const translations = await get_translations({
|
|
66
|
+
is_email: true,
|
|
67
|
+
email_template_name: send_email_options?.template,
|
|
68
|
+
joystick_build_path,
|
|
69
|
+
req: {
|
|
70
|
+
context: {
|
|
71
|
+
user: send_email_options?.user,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const html = await ssr({
|
|
77
|
+
is_email: true,
|
|
78
|
+
component_options: {
|
|
79
|
+
props: send_email_options?.props,
|
|
80
|
+
translations,
|
|
81
|
+
},
|
|
82
|
+
component_to_render: email_template_component,
|
|
83
|
+
email_options: {
|
|
84
|
+
base_html_name: send_email_options?.base,
|
|
85
|
+
subject: send_email_options?.subject,
|
|
86
|
+
preheader: send_email_options?.preheader,
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const text = htmlToText(html);
|
|
91
|
+
const html_with_styles_inlined = juice(html, {
|
|
92
|
+
preserveMediaQueries: true,
|
|
93
|
+
preserveImportant: true,
|
|
94
|
+
removeStyleTags: false,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
nodemailer_options.html = html_with_styles_inlined;
|
|
98
|
+
nodemailer_options.text = text;
|
|
99
|
+
|
|
100
|
+
return smtp.sendMail(nodemailer_options);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
console.warn(`Email template at /email/${send_email_options?.template}.js could not be found.`);
|
|
104
|
+
|
|
105
|
+
return Promise.resolve();
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export default send_email;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
|
|
3
|
+
const validate_smtp_settings = (settings = null) => {
|
|
4
|
+
if (!settings) {
|
|
5
|
+
console.warn(
|
|
6
|
+
chalk.redBright(
|
|
7
|
+
`Invalid SMTP settings: config.smtp not defined in settings.${process.env.NODE_ENV}.js`
|
|
8
|
+
)
|
|
9
|
+
);
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (settings && !settings.host) {
|
|
14
|
+
console.warn(
|
|
15
|
+
chalk.redBright(
|
|
16
|
+
`Invalid SMTP settings: config.smtp.host not defined in settings.${process.env.NODE_ENV}.js`
|
|
17
|
+
)
|
|
18
|
+
);
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (settings && !settings.port) {
|
|
23
|
+
console.warn(
|
|
24
|
+
chalk.redBright(
|
|
25
|
+
`Invalid SMTP settings: config.smtp.port not defined in settings.${process.env.NODE_ENV}.js`
|
|
26
|
+
)
|
|
27
|
+
);
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (settings && !settings.username) {
|
|
32
|
+
console.warn(
|
|
33
|
+
chalk.redBright(
|
|
34
|
+
`Invalid SMTP settings: config.smtp.username not defined in settings.${process.env.NODE_ENV}.js`
|
|
35
|
+
)
|
|
36
|
+
);
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (settings && !settings.password) {
|
|
41
|
+
console.warn(
|
|
42
|
+
chalk.redBright(
|
|
43
|
+
`Invalid SMTP settings: config.smtp.password not defined in settings.${process.env.NODE_ENV}.js`
|
|
44
|
+
)
|
|
45
|
+
);
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return true;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default validate_smtp_settings;
|
|
53
|
+
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import types from "../../lib/types.js";
|
|
2
|
+
|
|
3
|
+
class Fixture {
|
|
4
|
+
constructor(options = {}) {
|
|
5
|
+
this.options = options;
|
|
6
|
+
this.quantity = options?.quantity;
|
|
7
|
+
this.run = this.run.bind(this);
|
|
8
|
+
|
|
9
|
+
return this.run;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async run(input = {}) {
|
|
13
|
+
this.input = input;
|
|
14
|
+
|
|
15
|
+
const skip = typeof this?.options?.skip === 'function' ? await this.options.skip(this, input) : false;
|
|
16
|
+
|
|
17
|
+
let data_to_create = [];
|
|
18
|
+
|
|
19
|
+
if (!skip) {
|
|
20
|
+
data_to_create = await this.generate_data_to_create(input);
|
|
21
|
+
|
|
22
|
+
if (types.is_function(this?.options?.onCreate) || types.is_function(this?.options?.on_create)) {
|
|
23
|
+
await (this.options.onCreate || this.options.on_create)(this, data_to_create, (on_after_create_each_input = {}) => {
|
|
24
|
+
return (this?.options?.onAfterCreateEach || this.options.on_after_create_each)(this, on_after_create_each_input, input);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (types.is_function(this?.options?.onAfterCreateAll) || types.is_function(this?.options?.on_after_create_all)) {
|
|
30
|
+
(this.options.onAfterCreateAll || this.options.on_after_create_all)(this, data_to_create, input);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async generate_data_to_create(input = {}) {
|
|
35
|
+
const data = [];
|
|
36
|
+
|
|
37
|
+
for (let i = 0; i < this?.quantity; i += 1) {
|
|
38
|
+
if (typeof this?.options?.template === 'function') {
|
|
39
|
+
const data_to_create = await this.options?.template(this, i, input);
|
|
40
|
+
data.push(data_to_create);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return data;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default (options = {}) => {
|
|
49
|
+
return new Fixture(options);
|
|
50
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import os from 'os';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import generate_id from '../lib/generate_id.js';
|
|
5
|
+
import path_exists from '../lib/path_exists.js';
|
|
6
|
+
|
|
7
|
+
const { mkdir, writeFile, readFile } = fs.promises;
|
|
8
|
+
|
|
9
|
+
const generate_machine_id = async () => {
|
|
10
|
+
const home = os.homedir();
|
|
11
|
+
const joystick_machine_id_path = `${home}/.cheatcode/MACHINE_ID`;
|
|
12
|
+
const has_joystick_machine_id = await path_exists(joystick_machine_id_path);
|
|
13
|
+
|
|
14
|
+
if (!has_joystick_machine_id) {
|
|
15
|
+
const joystick_machine_id = generate_id(32);
|
|
16
|
+
await mkdir(path.dirname(joystick_machine_id_path), { recursive: true });
|
|
17
|
+
await writeFile(joystick_machine_id_path, joystick_machine_id);
|
|
18
|
+
return joystick_machine_id;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const joystick_machine_id = await readFile(joystick_machine_id_path, 'utf-8');
|
|
22
|
+
|
|
23
|
+
return joystick_machine_id?.trim();
|
|
24
|
+
;}
|
|
25
|
+
|
|
26
|
+
export default generate_machine_id;
|