@joystick.js/node-canary 0.0.0-canary.47 → 0.0.0-canary.470
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.build/getFilesToBuild.js +26 -0
- package/.build/getPlatformSafeFilePath.js +6 -0
- package/.build/getPlatformSafePath.js +6 -0
- package/.build/index.js +88 -0
- package/.build/isWindows.js +3 -0
- package/dist/action/class.js +1 -82
- package/dist/action/index.js +1 -8
- package/dist/app/accounts/default_user_output_fields.js +1 -0
- package/dist/app/accounts/delete_user.js +1 -0
- package/dist/app/accounts/generate_account_session.js +1 -0
- package/dist/app/accounts/generate_password_reset_token.js +1 -0
- package/dist/app/accounts/get_browser_safe_user.js +1 -0
- package/dist/app/accounts/has_login_token_expired.js +1 -0
- package/dist/app/accounts/index.js +1 -29
- package/dist/app/accounts/login.js +1 -59
- package/dist/app/accounts/recover_password.js +1 -0
- package/dist/app/accounts/reset_password.js +1 -0
- package/dist/app/accounts/roles/add.js +1 -7
- package/dist/app/accounts/roles/grant.js +1 -7
- package/dist/app/accounts/roles/index.js +1 -17
- package/dist/app/accounts/roles/list.js +1 -7
- package/dist/app/accounts/roles/remove.js +1 -7
- package/dist/app/accounts/roles/revoke.js +1 -7
- package/dist/app/accounts/roles/user_has_role.js +1 -0
- package/dist/app/accounts/send_email_verification.js +1 -0
- package/dist/app/accounts/set_account_cookie.js +1 -0
- package/dist/app/accounts/set_password.js +1 -0
- package/dist/app/accounts/signup.js +1 -97
- package/dist/app/accounts/unset_account_cookie.js +1 -0
- package/dist/app/accounts/verify_email.js +1 -0
- package/dist/app/api/accounts/authenticated.js +1 -0
- package/dist/app/api/accounts/login.js +1 -0
- package/dist/app/api/accounts/logout.js +1 -0
- package/dist/app/api/accounts/recover_password.js +1 -0
- package/dist/app/api/accounts/reset_password.js +1 -0
- package/dist/app/api/accounts/signup.js +1 -0
- package/dist/app/api/accounts/user.js +1 -0
- package/dist/app/api/accounts/verify_email.js +1 -0
- package/dist/app/api/format_api_error.js +1 -0
- package/dist/app/api/get.js +2 -0
- package/dist/app/api/get_api_context.js +1 -0
- package/dist/app/api/get_api_for_data_functions.js +1 -0
- package/dist/app/api/get_api_url_component.js +1 -0
- package/dist/app/api/get_output.js +1 -0
- package/dist/app/api/get_value_from_object.js +1 -0
- package/dist/app/api/handle_api_error.js +1 -0
- package/dist/app/api/input_validators.js +1 -0
- package/dist/app/api/is_array_path.js +1 -0
- package/dist/app/api/push/health.js +2 -0
- package/dist/app/api/register_getters.js +1 -0
- package/dist/app/api/register_setters.js +1 -0
- package/dist/app/api/sanitize_api_response.js +1 -0
- package/dist/app/api/set.js +2 -0
- package/dist/app/api/test/accounts/delete.js +1 -0
- package/dist/app/api/test/accounts/signup.js +1 -0
- package/dist/app/api/test/bootstrap.js +1 -0
- package/dist/app/api/test/process.js +1 -0
- package/dist/app/api/test/queues.js +1 -0
- package/dist/app/api/validate_input.js +1 -0
- package/dist/app/api/validate_session.js +1 -0
- package/dist/app/api/validate_type.js +1 -0
- package/dist/app/browser/hmr_client.js +1 -0
- package/dist/app/browser/process_polyfill.js +1 -0
- package/dist/app/cron_jobs/register.js +1 -0
- package/dist/app/databases/database_type_map.js +1 -0
- package/dist/app/databases/get_target_database_connection.js +1 -0
- package/dist/app/databases/mongodb/available_query_parameters.js +1 -0
- package/dist/app/databases/mongodb/build_connection_string.js +1 -0
- package/dist/app/databases/mongodb/build_query_parameters.js +1 -0
- package/dist/app/databases/mongodb/connect.js +6 -0
- package/dist/app/databases/mongodb/create_indexes.js +1 -0
- package/dist/app/databases/postgresql/accounts/create_accounts_metadata_table_columns.js +1 -0
- package/dist/app/databases/postgresql/connect.js +30 -0
- package/dist/app/databases/postgresql/create_indexes.js +1 -0
- package/dist/app/databases/postgresql/create_tables.js +1 -0
- package/dist/app/databases/postgresql/handle_cleanup_queues.js +5 -0
- package/dist/app/databases/postgresql/handle_cleanup_sessions.js +1 -0
- package/dist/app/databases/queries/accounts.js +1 -0
- package/dist/app/databases/queries/map.js +1 -0
- package/dist/app/databases/queries/mongodb/accounts.js +1 -0
- package/dist/app/databases/queries/mongodb/queues.js +1 -0
- package/dist/app/databases/queries/mongodb/sessions.js +1 -0
- package/dist/app/databases/queries/postgresql/accounts.js +1 -0
- package/dist/app/databases/queries/postgresql/queues.js +123 -0
- package/dist/app/databases/queries/postgresql/sessions.js +14 -0
- package/dist/app/databases/queries/sessions.js +1 -0
- package/dist/app/databases/register_database.js +1 -0
- package/dist/app/databases/sql.js +1 -0
- package/dist/app/email/send.js +1 -0
- package/dist/app/email/validate_smtp_settings.js +1 -0
- package/dist/app/fixture/index.js +1 -0
- package/dist/app/generate_machine_id.js +1 -0
- package/dist/app/generate_process_id.js +1 -0
- package/dist/app/get_ssl_certificates.js +1 -0
- package/dist/app/handle_process_errors.js +1 -0
- package/dist/app/index.js +1 -656
- package/dist/app/middleware/account.js +1 -0
- package/dist/app/middleware/body_parser.js +1 -0
- package/dist/app/middleware/build_error.js +1 -0
- package/dist/app/middleware/built_in.js +1 -0
- package/dist/app/middleware/context.js +1 -0
- package/dist/app/middleware/cors.js +1 -22
- package/dist/app/middleware/csp.js +1 -48
- package/dist/app/middleware/generate_insecure_page.js +65 -0
- package/dist/app/middleware/generate_joystick_error_page.js +147 -0
- package/dist/app/middleware/hmr_client.js +1 -0
- package/dist/app/middleware/insecure.js +1 -11
- package/dist/app/middleware/process_browser_polyfill.js +1 -0
- package/dist/app/middleware/render/get_url.js +1 -0
- package/dist/app/middleware/render/index.js +1 -0
- package/dist/app/middleware/request_methods.js +1 -0
- package/dist/app/middleware/session.js +1 -24
- package/dist/app/push_logs.js +1 -0
- package/dist/app/queues/index.js +1 -119
- package/dist/app/register_app_options.js +1 -0
- package/dist/app/routes/register_route_from_function.js +1 -0
- package/dist/app/routes/register_route_from_object.js +1 -0
- package/dist/app/routes/supported_http_methods.js +1 -0
- package/dist/app/settings/load.js +1 -0
- package/dist/app/ssr/index.js +33 -0
- package/dist/app/ssr/set_base_attributes_in_html.js +1 -0
- package/dist/app/ssr/set_head_tags_in_html.js +1 -0
- package/dist/app/start_express.js +1 -0
- package/dist/app/start_node_as_cluster.js +1 -0
- package/dist/app/uploaders/local_upload_progress_middleware.js +1 -0
- package/dist/app/uploaders/register.js +1 -0
- package/dist/app/uploaders/run_upload.js +1 -0
- package/dist/app/uploaders/validate_options.js +1 -0
- package/dist/app/uploaders/validate_uploads.js +1 -0
- package/dist/app/websockets/emit_event.js +1 -0
- package/dist/app/websockets/index.js +1 -0
- package/dist/app/websockets/register.js +1 -0
- package/dist/index.js +4 -76
- package/dist/lib/camel_pascal_to_snake.js +1 -0
- package/dist/lib/constants.js +1 -13
- package/dist/lib/dynamic_import.js +1 -0
- package/dist/lib/escape_html.js +1 -0
- package/dist/lib/escape_key_value_pair.js +1 -0
- package/dist/lib/float_to_decimal_place.js +1 -0
- package/dist/lib/generate_id.js +1 -0
- package/dist/lib/get_browser_safe_request.js +1 -0
- package/dist/lib/get_joystick_build_path.js +1 -0
- package/dist/lib/get_origin.js +1 -0
- package/dist/lib/get_platform_safe_path.js +1 -0
- package/dist/lib/get_sanitized_context.js +1 -0
- package/dist/lib/get_translations.js +1 -0
- package/dist/lib/hash_string.js +1 -0
- package/dist/lib/is_valid_json.js +1 -0
- package/dist/lib/log.js +13 -49
- package/dist/lib/node_path_polyfills.js +1 -0
- package/dist/lib/parse_json.js +1 -0
- package/dist/lib/path_exists.js +1 -0
- package/dist/lib/rainbow_road.js +1 -0
- package/dist/lib/serialize_query_parameters.js +1 -0
- package/dist/lib/set_cookie.js +1 -0
- package/dist/lib/string_to_slug.js +1 -0
- package/dist/lib/timestamps.js +1 -0
- package/dist/lib/types.js +1 -0
- package/dist/lib/unset_cookie.js +1 -0
- package/dist/lib/wait.js +1 -0
- package/dist/test/track_function_call.js +1 -0
- package/increment_version.js +3 -0
- package/package.json +27 -44
- package/src/action/class.js +137 -0
- package/src/action/index.js +8 -0
- package/src/app/accounts/default_user_output_fields.js +10 -0
- package/src/app/accounts/delete_user.js +18 -0
- package/src/app/accounts/generate_account_session.js +11 -0
- package/src/app/accounts/generate_password_reset_token.js +16 -0
- package/src/app/accounts/get_browser_safe_user.js +29 -0
- package/src/app/accounts/has_login_token_expired.js +9 -0
- package/src/app/accounts/index.js +38 -0
- package/src/app/accounts/login.js +82 -0
- package/src/app/accounts/recover_password.js +58 -0
- package/src/app/accounts/reset_password.js +69 -0
- package/src/app/accounts/roles/add.js +7 -0
- package/src/app/accounts/roles/grant.js +7 -0
- package/src/app/accounts/roles/index.js +18 -0
- package/src/app/accounts/roles/list.js +7 -0
- package/src/app/accounts/roles/remove.js +7 -0
- package/src/app/accounts/roles/revoke.js +7 -0
- package/src/app/accounts/roles/user_has_role.js +7 -0
- package/src/app/accounts/send_email_verification.js +48 -0
- package/src/app/accounts/set_account_cookie.js +12 -0
- package/src/app/accounts/set_password.js +46 -0
- package/src/app/accounts/signup.js +158 -0
- package/src/app/accounts/unset_account_cookie.js +12 -0
- package/src/app/accounts/verify_email.js +32 -0
- package/src/app/api/accounts/authenticated.js +17 -0
- package/src/app/api/accounts/login.js +36 -0
- package/src/app/api/accounts/logout.js +20 -0
- package/src/app/api/accounts/recover_password.js +16 -0
- package/src/app/api/accounts/reset_password.js +24 -0
- package/src/app/api/accounts/signup.js +49 -0
- package/src/app/api/accounts/user.js +21 -0
- package/src/app/api/accounts/verify_email.js +11 -0
- package/src/app/api/format_api_error.js +10 -0
- package/src/app/api/get.js +119 -0
- package/src/app/api/get_api_context.js +27 -0
- package/src/app/api/get_api_for_data_functions.js +37 -0
- package/src/app/api/get_api_url_component.js +5 -0
- package/src/app/api/get_output.js +116 -0
- package/src/app/api/get_value_from_object.js +8 -0
- package/src/app/api/handle_api_error.js +28 -0
- package/src/app/api/input_validators.js +227 -0
- package/src/app/api/is_array_path.js +6 -0
- package/src/app/api/push/health.js +17 -0
- package/src/app/api/register_getters.js +57 -0
- package/src/app/api/register_setters.js +55 -0
- package/src/app/api/sanitize_api_response.js +35 -0
- package/src/app/api/set.js +119 -0
- package/src/app/api/test/accounts/delete.js +8 -0
- package/src/app/api/test/accounts/signup.js +50 -0
- package/src/app/api/test/bootstrap.js +39 -0
- package/src/app/api/test/process.js +7 -0
- package/src/app/api/test/queues.js +25 -0
- package/src/app/api/validate_input.js +130 -0
- package/src/app/api/validate_session.js +20 -0
- package/src/app/api/validate_type.js +24 -0
- package/src/app/browser/hmr_client.js +196 -0
- package/src/app/browser/process_polyfill.js +11 -0
- package/src/app/cron_jobs/register.js +29 -0
- package/src/app/databases/database_type_map.js +6 -0
- package/src/app/databases/get_target_database_connection.js +25 -0
- package/{dist/app/databases/mongodb/availableQueryParameters.js → src/app/databases/mongodb/available_query_parameters.js} +3 -4
- package/src/app/databases/mongodb/build_connection_string.js +30 -0
- package/src/app/databases/mongodb/build_query_parameters.js +17 -0
- package/src/app/databases/mongodb/connect.js +42 -0
- package/src/app/databases/mongodb/create_indexes.js +35 -0
- package/src/app/databases/postgresql/accounts/create_accounts_metadata_table_columns.js +18 -0
- package/src/app/databases/postgresql/connect.js +128 -0
- package/src/app/databases/postgresql/create_indexes.js +58 -0
- package/src/app/databases/postgresql/create_tables.js +70 -0
- package/src/app/databases/postgresql/handle_cleanup_queues.js +36 -0
- package/src/app/databases/postgresql/handle_cleanup_sessions.js +5 -0
- package/src/app/databases/queries/accounts.js +17 -0
- package/src/app/databases/queries/map.js +21 -0
- package/src/app/databases/queries/mongodb/accounts.js +360 -0
- package/src/app/databases/queries/mongodb/queues.js +164 -0
- package/src/app/databases/queries/mongodb/sessions.js +22 -0
- package/src/app/databases/queries/postgresql/accounts.js +379 -0
- package/src/app/databases/queries/postgresql/queues.js +294 -0
- package/src/app/databases/queries/postgresql/sessions.js +37 -0
- package/src/app/databases/queries/sessions.js +17 -0
- package/src/app/databases/register_database.js +30 -0
- package/src/app/databases/sql.js +63 -0
- package/src/app/email/send.js +108 -0
- package/src/app/email/validate_smtp_settings.js +53 -0
- package/src/app/fixture/index.js +50 -0
- package/src/app/generate_machine_id.js +26 -0
- package/src/app/generate_process_id.js +30 -0
- package/src/app/get_ssl_certificates.js +23 -0
- package/src/app/handle_process_errors.js +101 -0
- package/src/app/index.js +253 -0
- package/src/app/middleware/account.js +28 -0
- package/src/app/middleware/body_parser.js +18 -0
- package/src/app/middleware/build_error.js +18 -0
- package/src/app/middleware/built_in.js +76 -0
- package/src/app/middleware/context.js +34 -0
- package/src/app/middleware/cors.js +23 -0
- package/src/app/middleware/csp.js +54 -0
- package/src/app/middleware/generate_insecure_page.js +71 -0
- package/{dist/lib/generateErrorPage.js → src/app/middleware/generate_joystick_error_page.js} +25 -21
- package/src/app/middleware/hmr_client.js +12 -0
- package/src/app/middleware/insecure.js +22 -0
- package/src/app/middleware/process_browser_polyfill.js +12 -0
- package/src/app/middleware/render/get_url.js +15 -0
- package/src/app/middleware/render/index.js +93 -0
- package/src/app/middleware/request_methods.js +21 -0
- package/src/app/middleware/session.js +31 -0
- package/src/app/push_logs.js +44 -0
- package/src/app/queues/index.js +268 -0
- package/src/app/register_app_options.js +7 -0
- package/src/app/routes/register_route_from_function.js +10 -0
- package/src/app/routes/register_route_from_object.js +34 -0
- package/src/app/routes/supported_http_methods.js +9 -0
- package/src/app/settings/load.js +33 -0
- package/src/app/ssr/index.js +133 -0
- package/src/app/ssr/set_base_attributes_in_html.js +43 -0
- package/src/app/ssr/set_head_tags_in_html.js +104 -0
- package/src/app/start_express.js +50 -0
- package/src/app/start_node_as_cluster.js +30 -0
- package/src/app/uploaders/local_upload_progress_middleware.js +24 -0
- package/src/app/uploaders/register.js +169 -0
- package/src/app/uploaders/run_upload.js +136 -0
- package/src/app/uploaders/validate_options.js +74 -0
- package/src/app/uploaders/validate_uploads.js +127 -0
- package/src/app/websockets/emit_event.js +14 -0
- package/src/app/websockets/index.js +16 -0
- package/src/app/websockets/register.js +175 -0
- package/src/index.js +81 -0
- package/{dist/lib/camelPascalToSnake.js → src/lib/camel_pascal_to_snake.js} +3 -4
- package/src/lib/constants.js +21 -0
- package/src/lib/dynamic_import.js +8 -0
- package/src/lib/escape_html.js +9 -0
- package/src/lib/escape_key_value_pair.js +15 -0
- package/src/lib/float_to_decimal_place.js +5 -0
- package/src/lib/generate_id.js +15 -0
- package/src/lib/get_browser_safe_request.js +17 -0
- package/src/lib/get_joystick_build_path.js +22 -0
- package/src/lib/get_origin.js +7 -0
- package/src/lib/get_platform_safe_path.js +8 -0
- package/src/lib/get_sanitized_context.js +51 -0
- package/src/lib/get_translations.js +109 -0
- package/src/lib/hash_string.js +7 -0
- package/src/lib/is_valid_json.js +10 -0
- package/src/lib/log.js +42 -0
- package/src/lib/node_path_polyfills.js +23 -0
- package/src/lib/parse_json.js +9 -0
- package/src/lib/path_exists.js +12 -0
- package/src/lib/rainbow_road.js +7 -0
- package/src/lib/serialize_query_parameters.js +7 -0
- package/src/lib/set_cookie.js +16 -0
- package/src/lib/string_to_slug.js +14 -0
- package/src/lib/timestamps.js +48 -0
- package/src/lib/types.js +59 -0
- package/src/lib/unset_cookie.js +11 -0
- package/src/lib/wait.js +9 -0
- package/src/test/track_function_call.js +16 -0
- package/README.md +0 -8
- package/_package.json +0 -63
- package/canary.js +0 -12
- package/dist/api/get.js +0 -29
- package/dist/api/getOrigin.js +0 -6
- package/dist/api/index.js +0 -9
- package/dist/api/set.js +0 -29
- package/dist/app/accounts/defaultUserOutputFields.js +0 -9
- package/dist/app/accounts/generateResetToken.js +0 -28
- package/dist/app/accounts/generateSession.js +0 -15
- package/dist/app/accounts/getBrowserSafeUser.js +0 -24
- package/dist/app/accounts/hasLoginTokenExpired.js +0 -17
- package/dist/app/accounts/hashString.js +0 -7
- package/dist/app/accounts/recoverPassword.js +0 -30
- package/dist/app/accounts/resetPassword.js +0 -73
- package/dist/app/accounts/roles/userHasRole.js +0 -7
- package/dist/app/accounts/runUserQuery.js +0 -15
- package/dist/app/accounts/sendEmailVerification.js +0 -65
- package/dist/app/accounts/setAuthenticationCookie.js +0 -11
- package/dist/app/accounts/setPassword.js +0 -45
- package/dist/app/accounts/unsetAuthenticationCookie.js +0 -11
- package/dist/app/accounts/verifyEmail.js +0 -46
- package/dist/app/databases/getTargetDatabase.js +0 -10
- package/dist/app/databases/getTargetDatabaseConnection.js +0 -19
- package/dist/app/databases/getTargetDatabaseProvider.js +0 -10
- package/dist/app/databases/mongodb/buildConnectionString.js +0 -22
- package/dist/app/databases/mongodb/buildQueryParameters.js +0 -14
- package/dist/app/databases/mongodb/index.js +0 -40
- package/dist/app/databases/mongodb/queries/accounts.js +0 -266
- package/dist/app/databases/mongodb/queries/queues.js +0 -111
- package/dist/app/databases/postgresql/addColumnToTable.js +0 -6
- package/dist/app/databases/postgresql/createAccountsIndexes.js +0 -21
- package/dist/app/databases/postgresql/createAccountsTables.js +0 -39
- package/dist/app/databases/postgresql/createDatabase.js +0 -0
- package/dist/app/databases/postgresql/index.js +0 -55
- package/dist/app/databases/postgresql/queries/accounts.js +0 -186
- package/dist/app/databases/postgresql/queries/queues.js +0 -211
- package/dist/app/databases/queryMap.js +0 -17
- package/dist/app/databases/typesMap.js +0 -7
- package/dist/app/getAPIContext.js +0 -25
- package/dist/app/getAPIURLComponent.js +0 -6
- package/dist/app/getBrowserSafeRequest.js +0 -14
- package/dist/app/getOutput.js +0 -74
- package/dist/app/handleProcessErrors.js +0 -73
- package/dist/app/initExpress.js +0 -41
- package/dist/app/middleware/bodyParser.js +0 -16
- package/dist/app/middleware/hmr/client.js +0 -113
- package/dist/app/middleware/index.js +0 -89
- package/dist/app/middleware/render.js +0 -213
- package/dist/app/middleware/requestMethods.js +0 -19
- package/dist/app/registerGetters.js +0 -45
- package/dist/app/registerSetters.js +0 -45
- package/dist/app/runGetter.js +0 -103
- package/dist/app/runSetter.js +0 -103
- package/dist/app/runUploader.js +0 -143
- package/dist/app/sanitizeAPIResponse.js +0 -27
- package/dist/app/utils/process.js +0 -193
- package/dist/app/validateSession.js +0 -19
- package/dist/app/validateUploaderOptions.js +0 -53
- package/dist/app/validateUploads.js +0 -102
- package/dist/email/render.js +0 -50
- package/dist/email/send.js +0 -55
- package/dist/email/templates/base.css +0 -194
- package/dist/email/templates/base.html +0 -28
- package/dist/email/templates/reset-password.js +0 -13
- package/dist/email/validateSMTPSettings.js +0 -27
- package/dist/lib/escapeHTML.js +0 -9
- package/dist/lib/escapeKeyValuePair.js +0 -13
- package/dist/lib/formatAPIError.js +0 -12
- package/dist/lib/formatErrorString.js +0 -8
- package/dist/lib/generateCookie.js +0 -14
- package/dist/lib/generateId.js +0 -13
- package/dist/lib/generateMachineId.js +0 -15
- package/dist/lib/getBuildPath.js +0 -10
- package/dist/lib/getErrorObject.js +0 -9
- package/dist/lib/getPlatformSafeFilePath.js +0 -8
- package/dist/lib/getPlatformSafePath.js +0 -8
- package/dist/lib/getSSLCertificates.js +0 -19
- package/dist/lib/isValidHTTPMethod.js +0 -7
- package/dist/lib/isValidJSONString.js +0 -11
- package/dist/lib/nodeUrlPolyfills.js +0 -14
- package/dist/lib/objectToSQLKeysString.js +0 -18
- package/dist/lib/objectToSQLValuesString.js +0 -16
- package/dist/lib/obscenedb/debounce.js +0 -12
- package/dist/lib/obscenedb/index.js +0 -61
- package/dist/lib/parseDatabasesFromEnvironment.js +0 -9
- package/dist/lib/rainbowRoad.js +0 -7
- package/dist/lib/readDirectory.js +0 -24
- package/dist/lib/replaceBackslashesWithForwardSlashes.js +0 -8
- package/dist/lib/replaceFileProtocol.js +0 -8
- package/dist/lib/replaceForwardSlashesWithBackslashes.js +0 -8
- package/dist/lib/serializeQueryParameters.js +0 -8
- package/dist/lib/serverAvailable.js +0 -0
- package/dist/lib/setCookie.js +0 -16
- package/dist/lib/supportedHTTPMethods.js +0 -4
- package/dist/lib/unsetCookie.js +0 -13
- package/dist/push/logs/index.js +0 -55
- package/dist/settings/index.js +0 -5
- package/dist/settings/load.js +0 -30
- package/dist/ssr/compileCSS.js +0 -85
- package/dist/ssr/findComponentInTree.js +0 -29
- package/dist/ssr/formatCSS.js +0 -6
- package/dist/ssr/getCSSFromTree.js +0 -33
- package/dist/ssr/index.js +0 -441
- package/dist/ssr/replaceWhenTags.js +0 -37
- package/dist/ssr/setHeadTagsInHTML.js +0 -84
- package/dist/validation/index.js +0 -10
- package/dist/validation/index.test.js +0 -463
- package/dist/validation/inputWithSchema/index.js +0 -105
- package/dist/validation/lib/constants.js +0 -162
- package/dist/validation/lib/getValueFromObject.js +0 -12
- package/dist/validation/lib/getValueFromObject.test.js +0 -7
- package/dist/validation/lib/isArrayPath.js +0 -6
- package/dist/validation/lib/throwError.js +0 -6
- package/dist/validation/lib/typeValidators.js +0 -38
- package/dist/validation/lib/validateType.js +0 -33
- package/dist/validation/schema/index.js +0 -44
- package/dist/websockets/emitWebsocketEvent.js +0 -12
- package/dist/websockets/index.js +0 -12
- package/notes +0 -1
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import types from '../../lib/types.js';
|
|
2
|
+
import validate_type from "./validate_type.js";
|
|
3
|
+
import is_array_path from "./is_array_path.js";
|
|
4
|
+
|
|
5
|
+
const allowed_values = (rule_value, input_value, parent_path) => {
|
|
6
|
+
const isValid = rule_value.includes(input_value);
|
|
7
|
+
|
|
8
|
+
if (!isValid) {
|
|
9
|
+
return {
|
|
10
|
+
valid: false,
|
|
11
|
+
errors: [
|
|
12
|
+
`Field ${parent_path} only allows the following values: ${rule_value.join(
|
|
13
|
+
", "
|
|
14
|
+
)}.`,
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
valid: true,
|
|
21
|
+
errors: [],
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const max_length = (rule_value, input_value, parent_path) => {
|
|
26
|
+
const valid = types.is_array(input_value) && input_value?.length <= rule_value;
|
|
27
|
+
|
|
28
|
+
if (!valid) {
|
|
29
|
+
return {
|
|
30
|
+
valid: false,
|
|
31
|
+
errors: [
|
|
32
|
+
`Field ${parent_path} length must be less than or equal to ${rule_value}.`,
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
valid: true,
|
|
39
|
+
errors: [],
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const min_length = (rule_value, input_value, parent_path) => {
|
|
44
|
+
const valid = types.is_array(input_value) && input_value?.length >= rule_value;
|
|
45
|
+
|
|
46
|
+
if (!valid) {
|
|
47
|
+
return {
|
|
48
|
+
valid: false,
|
|
49
|
+
errors: [
|
|
50
|
+
`Field ${parent_path} length must be greater than or equal to ${rule_value}.`,
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
valid: true,
|
|
57
|
+
errors: [],
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const input_validators = {
|
|
62
|
+
types: [
|
|
63
|
+
"any",
|
|
64
|
+
"array",
|
|
65
|
+
"boolean",
|
|
66
|
+
"float",
|
|
67
|
+
"integer",
|
|
68
|
+
"number",
|
|
69
|
+
"object",
|
|
70
|
+
"string",
|
|
71
|
+
],
|
|
72
|
+
rules: {
|
|
73
|
+
allowed_values,
|
|
74
|
+
allowedValues: allowed_values,
|
|
75
|
+
element: async (rule_value, input_value, parent_path, validate_input) => {
|
|
76
|
+
// NOTE: Allow for element to be passed as a type string so you can do arrays of single
|
|
77
|
+
// primitive elements (e.g., ['a', 'b', 'c'] or [1, 2, 3]).
|
|
78
|
+
|
|
79
|
+
if (
|
|
80
|
+
input_value &&
|
|
81
|
+
(types.is_object(rule_value) || types.is_string(rule_value)) &&
|
|
82
|
+
types.is_array(input_value)
|
|
83
|
+
) {
|
|
84
|
+
// NOTE: Usage of .flatMap may seem excessive here but it's required because we're
|
|
85
|
+
// doing recursive calls to validate_input of n depth. Each call returns
|
|
86
|
+
// an array which means on complex nested schemas, we get back arrays of arrays of
|
|
87
|
+
// error strings when really we just want one flat array for the full tree.
|
|
88
|
+
const element_errors = await Promise.all(
|
|
89
|
+
input_value.flatMap(async (element, element_index) => {
|
|
90
|
+
const errors = await validate_input(
|
|
91
|
+
element,
|
|
92
|
+
types.is_string(rule_value) ? { type: rule_value } : rule_value,
|
|
93
|
+
`${parent_path}.${element_index}`
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
return errors.flatMap((error) => error);
|
|
97
|
+
})
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
valid: element_errors.length === 0,
|
|
102
|
+
errors: element_errors.flatMap((element_error) => element_error),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
valid: true,
|
|
108
|
+
errors: [],
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
fields: async (rule_value, input_value, parent_path, validate_input) => {
|
|
112
|
+
if (types.is_object(rule_value) && types.is_object(input_value)) {
|
|
113
|
+
const errors = await validate_input(input_value, rule_value, parent_path);
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
valid: errors.length === 0,
|
|
117
|
+
errors: [...errors],
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
valid: false,
|
|
123
|
+
errors: [
|
|
124
|
+
`Field ${parent_path} must be of type object.`,
|
|
125
|
+
],
|
|
126
|
+
};
|
|
127
|
+
},
|
|
128
|
+
max: (rule_value, input_value, parent_path) => {
|
|
129
|
+
const valid = input_value <= rule_value;
|
|
130
|
+
|
|
131
|
+
if (!valid) {
|
|
132
|
+
return {
|
|
133
|
+
valid: false,
|
|
134
|
+
errors: [`Field ${parent_path} must be less than or equal to ${rule_value}.`],
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
valid: true,
|
|
140
|
+
errors: [],
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
max_length,
|
|
144
|
+
maxLength: max_length,
|
|
145
|
+
min: (rule_value, input_value, parent_path) => {
|
|
146
|
+
const valid = input_value >= rule_value;
|
|
147
|
+
|
|
148
|
+
if (!valid) {
|
|
149
|
+
return {
|
|
150
|
+
valid: false,
|
|
151
|
+
errors: [
|
|
152
|
+
`Field ${parent_path} must be greater than or equal to ${rule_value}.`,
|
|
153
|
+
],
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
valid: true,
|
|
159
|
+
errors: [],
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
min_length,
|
|
163
|
+
minLength: min_length,
|
|
164
|
+
optional: (rule_value, input_value, parent_path) => {
|
|
165
|
+
const valid = rule_value === false ? !!input_value : true;
|
|
166
|
+
|
|
167
|
+
if (!valid) {
|
|
168
|
+
return {
|
|
169
|
+
valid: false,
|
|
170
|
+
errors: [`Field ${parent_path} is required.`],
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
valid: true,
|
|
176
|
+
errors: [],
|
|
177
|
+
};
|
|
178
|
+
},
|
|
179
|
+
regex: (rule_value, input_value, parent_path) => {
|
|
180
|
+
const valid = new RegExp(rule_value).test(input_value);
|
|
181
|
+
|
|
182
|
+
if (!valid) {
|
|
183
|
+
return {
|
|
184
|
+
valid: false,
|
|
185
|
+
errors: [`Field ${parent_path} must conform to regex: ${rule_value}.`],
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
valid: true,
|
|
191
|
+
errors: [],
|
|
192
|
+
};
|
|
193
|
+
},
|
|
194
|
+
required: (rule_value, input_value, parent_path) => {
|
|
195
|
+
const valid = rule_value === false ? true : !!input_value;
|
|
196
|
+
|
|
197
|
+
if (!valid) {
|
|
198
|
+
return {
|
|
199
|
+
valid: false,
|
|
200
|
+
errors: [`Field ${parent_path} is required.`],
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
valid: true,
|
|
206
|
+
errors: [],
|
|
207
|
+
};
|
|
208
|
+
},
|
|
209
|
+
type: (rule_value, input_value, parent_path) => {
|
|
210
|
+
const valid = validate_type(rule_value, input_value);
|
|
211
|
+
|
|
212
|
+
if (input_value && !valid) {
|
|
213
|
+
return {
|
|
214
|
+
valid: false,
|
|
215
|
+
errors: [`Field ${parent_path} must be of type ${rule_value}.`],
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return {
|
|
220
|
+
valid: true,
|
|
221
|
+
errors: [],
|
|
222
|
+
};
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
export default input_validators;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
|
|
3
|
+
const { readFile } = fs.promises;
|
|
4
|
+
|
|
5
|
+
const health = async (req = {}, res = {}) => {
|
|
6
|
+
const instance_token = await readFile("/root/push/instance_token.txt", "utf-8");
|
|
7
|
+
|
|
8
|
+
if (req?.headers["x-instance-token"] === instance_token?.replace("\n", "")) {
|
|
9
|
+
return res.status(200).send("ok");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return res
|
|
13
|
+
.status(403)
|
|
14
|
+
.send("Sorry, you must pass a valid instance token to access this endpoint.");
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default health;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import format_api_error from "./format_api_error.js";
|
|
2
|
+
import get from "./get.js";
|
|
3
|
+
import get_api_context from "./get_api_context.js";
|
|
4
|
+
import get_api_url_component from "./get_api_url_component.js";
|
|
5
|
+
import handle_api_error from "./handle_api_error.js";
|
|
6
|
+
import is_valid_json from "../../lib/is_valid_json.js";
|
|
7
|
+
import types from "../../lib/types.js";
|
|
8
|
+
import validate_session from "./validate_session.js";
|
|
9
|
+
|
|
10
|
+
const register_getters = (express_app = {}, getter_definitions = [], api_context = {}, api_schema_options = {}) => {
|
|
11
|
+
for (let i = 0; i < getter_definitions?.length; i += 1) {
|
|
12
|
+
const [getter_name, getter_definition] = getter_definitions[i];
|
|
13
|
+
express_app.get(
|
|
14
|
+
`/api/_getters/${get_api_url_component(getter_name)}`,
|
|
15
|
+
...(types.is_array(getter_definition?.middleware) ? getter_definition?.middleware : []),
|
|
16
|
+
async (req = {}, res = {}) => {
|
|
17
|
+
if (process.databases?._sessions) {
|
|
18
|
+
const is_valid_session = await validate_session(req, res);
|
|
19
|
+
|
|
20
|
+
if (!is_valid_session) {
|
|
21
|
+
return res.status(403).send(
|
|
22
|
+
JSON.stringify({
|
|
23
|
+
errors: [format_api_error(new Error('Unauthorized request.'))],
|
|
24
|
+
})
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const context = await get_api_context(req, res, api_context);
|
|
30
|
+
|
|
31
|
+
const decoded_input = decodeURIComponent(req?.query?.input);
|
|
32
|
+
const input = is_valid_json(decoded_input) ? JSON.parse(decoded_input) : null;
|
|
33
|
+
|
|
34
|
+
const decoded_output = decodeURIComponent(req?.query?.output);
|
|
35
|
+
const output = is_valid_json(decoded_output) ? JSON.parse(decoded_output) : null;
|
|
36
|
+
|
|
37
|
+
get({
|
|
38
|
+
get_name: getter_name,
|
|
39
|
+
get_options: {
|
|
40
|
+
input,
|
|
41
|
+
output,
|
|
42
|
+
},
|
|
43
|
+
getter_definition,
|
|
44
|
+
request_context: context,
|
|
45
|
+
api_schema_options,
|
|
46
|
+
}).then((response) => {
|
|
47
|
+
return res.status(200).send(JSON.stringify(response));
|
|
48
|
+
}).catch((error) => {
|
|
49
|
+
handle_api_error(`api.getters.${getter_name}`, error, res);
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export default register_getters;
|
|
57
|
+
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import format_api_error from "./format_api_error.js";
|
|
2
|
+
import get_api_context from "./get_api_context.js";
|
|
3
|
+
import get_api_url_component from "./get_api_url_component.js";
|
|
4
|
+
import handle_api_error from "./handle_api_error.js";
|
|
5
|
+
import set from "./set.js";
|
|
6
|
+
import types from "../../lib/types.js";
|
|
7
|
+
import validate_session from "./validate_session.js";
|
|
8
|
+
|
|
9
|
+
const register_setters = (express_app = {}, setter_definitions = [], api_context = {}, api_schema_options = {}) => {
|
|
10
|
+
for (let i = 0; i < setter_definitions?.length; i += 1) {
|
|
11
|
+
const [setter_name, setter_definition] = setter_definitions[i];
|
|
12
|
+
express_app.post(
|
|
13
|
+
`/api/_setters/${get_api_url_component(setter_name)}`,
|
|
14
|
+
...(types.is_array(setter_definition?.middleware) ? setter_definition?.middleware : []),
|
|
15
|
+
async (req = {}, res = {}) => {
|
|
16
|
+
if (process.databases?._sessions) {
|
|
17
|
+
const is_valid_session = await validate_session(req, res);
|
|
18
|
+
|
|
19
|
+
if (!is_valid_session) {
|
|
20
|
+
return res.status(403).send(
|
|
21
|
+
JSON.stringify({
|
|
22
|
+
errors: [format_api_error(new Error('Unauthorized request.'))],
|
|
23
|
+
})
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const context = await get_api_context(req, res, api_context);
|
|
29
|
+
|
|
30
|
+
// NOTE: No need for URL decoding or JSON integrity check like getters as these are passed
|
|
31
|
+
// via the body, not query parameters.
|
|
32
|
+
const input = req?.body?.input || null;
|
|
33
|
+
const output = req?.body?.output || null;
|
|
34
|
+
|
|
35
|
+
set({
|
|
36
|
+
set_name: setter_name,
|
|
37
|
+
set_options: {
|
|
38
|
+
input,
|
|
39
|
+
output,
|
|
40
|
+
},
|
|
41
|
+
setter_definition,
|
|
42
|
+
request_context: context,
|
|
43
|
+
api_schema_options,
|
|
44
|
+
}).then((response) => {
|
|
45
|
+
return res.status(200).send(JSON.stringify(response));
|
|
46
|
+
}).catch((error) => {
|
|
47
|
+
handle_api_error(`api.setters.${setter_name}`, error, res);
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default register_setters;
|
|
55
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import escape_html from "../../lib/escape_html.js";
|
|
2
|
+
import types from '../../lib/types.js';
|
|
3
|
+
|
|
4
|
+
const sanitized_api_response = (data = null) => {
|
|
5
|
+
let sanitized_data = data;
|
|
6
|
+
|
|
7
|
+
if (
|
|
8
|
+
!types.is_string(sanitized_data) &&
|
|
9
|
+
!types.is_object(sanitized_data) &&
|
|
10
|
+
!types.is_array(sanitized_data)
|
|
11
|
+
) {
|
|
12
|
+
return sanitized_data;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (types.is_string(sanitized_data)) {
|
|
16
|
+
sanitized_data = (escape_html(sanitized_data))?.trim();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (types.is_object(sanitized_data) && !types.is_array(sanitized_data)) {
|
|
20
|
+
sanitized_data = Object.entries(sanitized_data || {})?.reduce((result = {}, [key, value]) => {
|
|
21
|
+
result[key] = sanitized_api_response(value);
|
|
22
|
+
return result;
|
|
23
|
+
}, {});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (types.is_array(sanitized_data)) {
|
|
27
|
+
sanitized_data = sanitized_data.map((array_item = null) => {
|
|
28
|
+
return sanitized_api_response(array_item);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return sanitized_data;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default sanitized_api_response;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import format_api_error from "./format_api_error.js";
|
|
2
|
+
import get_output from "./get_output.js";
|
|
3
|
+
import get_sanitized_context from "../../lib/get_sanitized_context.js";
|
|
4
|
+
import sanitize_api_response from "./sanitize_api_response.js";
|
|
5
|
+
import track_function_call from "../../test/track_function_call.js";
|
|
6
|
+
import types from "../../lib/types.js";
|
|
7
|
+
import validate_input from "./validate_input.js";
|
|
8
|
+
|
|
9
|
+
const run_setter = async (
|
|
10
|
+
set_name = '',
|
|
11
|
+
setter_definition = {},
|
|
12
|
+
input = {},
|
|
13
|
+
output = {},
|
|
14
|
+
context = {},
|
|
15
|
+
api_schema_options = {}
|
|
16
|
+
) => {
|
|
17
|
+
const should_disable_sanitization = setter_definition?.sanitize === false;
|
|
18
|
+
const should_sanitize_output = (setter_definition?.sanitize || api_schema_options?.sanitize) === true;
|
|
19
|
+
|
|
20
|
+
track_function_call(`node.api.setters.${set_name}`, [
|
|
21
|
+
input,
|
|
22
|
+
get_sanitized_context(context),
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
const data = (await setter_definition?.set(input, context));
|
|
26
|
+
const response = output ? get_output(data, output) : data;
|
|
27
|
+
|
|
28
|
+
return !should_disable_sanitization && should_sanitize_output ? sanitize_api_response(
|
|
29
|
+
response
|
|
30
|
+
) : response;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const run_authorization = async (setter_name = '', setter_definition = {}, input = {}, context = {}) => {
|
|
34
|
+
track_function_call(`node.api.setters.${setter_name}.authorized`, [
|
|
35
|
+
input,
|
|
36
|
+
get_sanitized_context(context),
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
const authorization = await setter_definition?.authorized(input, context);
|
|
40
|
+
|
|
41
|
+
if (typeof authorization === 'boolean') {
|
|
42
|
+
return authorization;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (types.is_object(authorization) && !types.is_array(authorization) && !types.is_undefined(authorization?.authorized)) {
|
|
46
|
+
return authorization?.authorized ? true : authorization?.message;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const handle_log_validation_errors = (validation_errors = [], setter_name = '') => {
|
|
51
|
+
console.log(
|
|
52
|
+
`Input validation for setter "${setter_name}" failed with the following errors:\n`
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
for (let i = 0; i < validation_errors?.length; i += 1) {
|
|
56
|
+
const validation_error = validation_errors[i];
|
|
57
|
+
console.log(`${i + 1}. ${validation_error}`);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const run_validation = (set_request_input = {}, setter_definition_input = {}) => {
|
|
62
|
+
return validate_input(set_request_input, setter_definition_input);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const set = async ({
|
|
66
|
+
set_name,
|
|
67
|
+
set_options, // NOTE: skip, input, output.
|
|
68
|
+
setter_definition,
|
|
69
|
+
request_context,
|
|
70
|
+
api_schema_options,
|
|
71
|
+
}) => {
|
|
72
|
+
const should_run_validation = setter_definition?.input && Object.keys(setter_definition?.input)?.length > 0;
|
|
73
|
+
const should_run_authorization = types.is_function(setter_definition?.authorized);
|
|
74
|
+
|
|
75
|
+
if (should_run_validation) {
|
|
76
|
+
const validation_errors = await run_validation(set_options?.input, setter_definition?.input);
|
|
77
|
+
|
|
78
|
+
if (validation_errors?.length > 0) {
|
|
79
|
+
handle_log_validation_errors(validation_errors, set_name);
|
|
80
|
+
|
|
81
|
+
return Promise.reject({
|
|
82
|
+
errors: validation_errors.map((error) => {
|
|
83
|
+
return format_api_error(new Error(error), `setters.${set_name}.input`, 401);
|
|
84
|
+
}),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (should_run_authorization) {
|
|
90
|
+
const authorized = await run_authorization(set_name, setter_definition, set_options?.input, request_context);
|
|
91
|
+
|
|
92
|
+
if (!authorized || types.is_string(authorized)) {
|
|
93
|
+
return Promise.reject({
|
|
94
|
+
errors: [
|
|
95
|
+
format_api_error(
|
|
96
|
+
new Error(typeof authorized === 'string' ? authorized : `Not authorized to access ${set_name}.`),
|
|
97
|
+
`setters.${set_name}.authorized`,
|
|
98
|
+
403
|
|
99
|
+
),
|
|
100
|
+
],
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (types.is_function(setter_definition?.set)) {
|
|
106
|
+
const response = await run_setter(
|
|
107
|
+
set_name,
|
|
108
|
+
setter_definition,
|
|
109
|
+
set_options?.input,
|
|
110
|
+
set_options?.output,
|
|
111
|
+
request_context,
|
|
112
|
+
api_schema_options,
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
return Promise.resolve(response);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export default set;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import accounts_query from "../../../databases/queries/accounts.js";
|
|
2
|
+
|
|
3
|
+
const test_accounts_delete = async (req = {}, res = {}) => {
|
|
4
|
+
await accounts_query('delete_user', { user_id: req?.body?.user_id });
|
|
5
|
+
res.status(200).send({ data: {} });
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export default test_accounts_delete;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import accounts_query from "../../../databases/queries/accounts.js";
|
|
2
|
+
import default_user_output_fields from "../../../accounts/default_user_output_fields.js";
|
|
3
|
+
import format_api_error from "../../format_api_error.js";
|
|
4
|
+
import handle_api_error from "../../handle_api_error.js";
|
|
5
|
+
import validate_input from "../../validate_input.js";
|
|
6
|
+
import signup from "../../../accounts/signup.js";
|
|
7
|
+
|
|
8
|
+
const test_accounts_signup = async (req = {}, res = {}) => {
|
|
9
|
+
try {
|
|
10
|
+
// NOTE: Assume accounts created in tests are ephemeral on a per-run basis.
|
|
11
|
+
// When signing up, automatically delete an existing user to avoid fragile
|
|
12
|
+
// tests and conflicts between runs.
|
|
13
|
+
const existing_user_with_email = await accounts_query('user', { email_address: req?.body?.emailAddress || req?.body?.email_address });
|
|
14
|
+
const existing_user_with_username = await accounts_query('user', { username: req?.body?.username });
|
|
15
|
+
const existing_user = existing_user_with_email || existing_user_with_username;
|
|
16
|
+
|
|
17
|
+
if (existing_user) {
|
|
18
|
+
await accounts_query('delete_user', { user_id: existing_user?._id || existing_user?.user_id });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const metadata_schema = process.joystick?.app_options?.accounts?.signup?.metadata;
|
|
22
|
+
const metadata_errors = metadata_schema ? await validate_input(req?.body?.metadata, metadata_schema) : [];
|
|
23
|
+
|
|
24
|
+
if (metadata_errors?.length > 0) {
|
|
25
|
+
return handle_api_error('accounts.signup', {
|
|
26
|
+
errors: metadata_errors.map((error) => {
|
|
27
|
+
return format_api_error(new Error(error), `accounts.signup.metadata`, 401);
|
|
28
|
+
}),
|
|
29
|
+
}, res);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const signup_response = await signup({
|
|
33
|
+
email_address: req?.body?.emailAddress || req?.body?.email_address,
|
|
34
|
+
username: req?.body?.username,
|
|
35
|
+
password: req?.body?.password,
|
|
36
|
+
metadata: req?.body?.metadata,
|
|
37
|
+
output: req?.body?.output || default_user_output_fields,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
res.status(200).send(JSON.stringify({
|
|
41
|
+
...(signup_response?.user || {}),
|
|
42
|
+
joystick_login_token: signup_response?.token,
|
|
43
|
+
joystick_login_token_expires_at: signup_response?.token_expires_at,
|
|
44
|
+
}));
|
|
45
|
+
} catch(error) {
|
|
46
|
+
handle_api_error('test.accounts.signup', error, res);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default test_accounts_signup;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import dynamic_import from "../../../lib/dynamic_import.js";
|
|
2
|
+
import get_api_for_data_functions from "../get_api_for_data_functions.js";
|
|
3
|
+
import get_browser_safe_request from "../../../lib/get_browser_safe_request.js";
|
|
4
|
+
import get_platform_safe_path from "../../../lib/get_platform_safe_path.js";
|
|
5
|
+
import get_translations from "../../../lib/get_translations.js";
|
|
6
|
+
import load_settings from "../../settings/load.js";
|
|
7
|
+
|
|
8
|
+
const test_bootstrap = async (req = {}, res = {}, app_instance = {}) => {
|
|
9
|
+
const joystick_build_path = `${process.cwd()}/.joystick/build/`;
|
|
10
|
+
const component_to_render = req?.query?.path_to_component ?
|
|
11
|
+
await dynamic_import(
|
|
12
|
+
get_platform_safe_path(`${joystick_build_path}/${req?.query?.path_to_component}?v=${new Date().getTime()}`)
|
|
13
|
+
) :
|
|
14
|
+
null;
|
|
15
|
+
|
|
16
|
+
if (component_to_render) {
|
|
17
|
+
const component_instance = component_to_render();
|
|
18
|
+
const api_for_data_functions = get_api_for_data_functions(req, app_instance?.options?.api);
|
|
19
|
+
const browser_safe_request = get_browser_safe_request(req);
|
|
20
|
+
const data = await component_instance.fetch_data(api_for_data_functions, browser_safe_request, {}, component_instance);
|
|
21
|
+
|
|
22
|
+
return res.status(200).send({
|
|
23
|
+
data: {
|
|
24
|
+
[component_instance?.id]: data,
|
|
25
|
+
},
|
|
26
|
+
req: browser_safe_request,
|
|
27
|
+
settings: load_settings(),
|
|
28
|
+
translations: await get_translations({
|
|
29
|
+
joystick_build_path,
|
|
30
|
+
render_component_path: req?.query?.path_to_component,
|
|
31
|
+
req,
|
|
32
|
+
}),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
res.status(200).send({ data: {}, translations: {} });
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default test_bootstrap;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const test_queues = async (req = {}, res = {}, app_instance = {}) => {
|
|
2
|
+
const queue = process?.queues[req?.body?.queue];
|
|
3
|
+
const job = app_instance?.options?.queues[req?.body?.queue]?.jobs[req?.body?.job];
|
|
4
|
+
|
|
5
|
+
if (!queue) {
|
|
6
|
+
return res.status(404).send({ status: 404, error: `Queue ${req?.body?.queue} not found.` });
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (!job) {
|
|
10
|
+
return res.status(400).send({
|
|
11
|
+
status: 400,
|
|
12
|
+
error: `Couldn't find a job called ${req?.body?.job} for the ${req?.body?.queue} queue.`
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
await queue.handle_next_job({
|
|
17
|
+
_id: 'joystick_test',
|
|
18
|
+
job: req?.body?.job,
|
|
19
|
+
payload: req?.body?.payload,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
res.status(200).send({ status: 200, data: {} });
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default test_queues;
|