!empty($source_config['allow_private_network']), 'local_dispatch_host' => isset($source_config['local_dispatch_host']) ? sanitize_text_field((string) $source_config['local_dispatch_host']) : '', 'record_internal_events' => !empty($source_config['record_internal_events']), 'environment_label' => isset($source_config['environment_label']) ? sanitize_text_field((string) $source_config['environment_label']) : '', 'verification_domain' => isset($source_config['verification_domain']) ? esc_url_raw((string) $source_config['verification_domain']) : '', 'plugin_update_info_url' => isset($source_config['plugin_update_info_url']) ? esc_url_raw((string) $source_config['plugin_update_info_url']) : '', 'plugin_update_icon_1x_url' => isset($source_config['plugin_update_icon_1x_url']) ? esc_url_raw((string) $source_config['plugin_update_icon_1x_url']) : '', 'plugin_update_icon_2x_url' => isset($source_config['plugin_update_icon_2x_url']) ? esc_url_raw((string) $source_config['plugin_update_icon_2x_url']) : '', ]; $source_config['debug'] = defined('WP_DEBUG') && WP_DEBUG; $config = apply_filters('vasp_config', $source_config); if (!is_array($config)) { $config = []; } foreach ($deployment_policy as $policy_key => $policy_value) { $config[$policy_key] = $policy_value; } // Route paths are application contracts, not deployment settings. // Derive them after the public filter so individual endpoints cannot be // redirected independently of their owning service origin. $config = vasp_add_fixed_endpoint_urls($config); $cached_config = vasp_validate_config($config, vasp_get_environment()); } if ($key !== null) { return array_key_exists($key, $cached_config) ? $cached_config[$key] : null; } return $cached_config; } /** Add fixed Dashboard and Gateway routes to effective configuration. */ function vasp_add_fixed_endpoint_urls(array $config): array { $routes = [ 'client_registration_endpoint' => ['dashboard_domain', '/connect/register'], 'auth_base_url' => ['gateway_domain', '/connect/authorize'], 'token_endpoint' => ['gateway_domain', '/connect/token'], 'revocation_endpoint' => ['gateway_domain', '/connect/revoke'], 'userinfo_endpoint' => ['gateway_domain', '/connect/userinfo'], 'status_endpoint' => ['gateway_domain', '/connect/token/status'], 'wordpress_status_endpoint' => ['gateway_domain', '/api/wordpress/status'], 'wordpress_authorize_endpoint' => ['gateway_domain', '/api/wordpress/authorize'], 'woocommerce_status_endpoint' => ['gateway_domain', '/api/woocommerce/status'], 'woocommerce_authorize_endpoint' => ['gateway_domain', '/api/woocommerce/authorize'], 'valuespace_status_endpoint' => ['gateway_domain', '/api/valuespace/status'], 'wordpress_ingestion_start_endpoint' => ['gateway_domain', '/api/wordpress/ingestion/start'], 'wordpress_ingestion_progress_endpoint' => ['gateway_domain', '/api/wordpress/ingestion/progress'], 'ecommerce_catalog_products_endpoint' => ['gateway_domain', '/api/v1/ecommerce/products'], 'ecommerce_catalog_product_sync_requests_endpoint' => ['gateway_domain', '/api/v1/ecommerce/products/sync-requests'], 'ecommerce_catalog_image_sync_requests_endpoint' => ['gateway_domain', '/api/v1/ecommerce/images/sync-requests'], 'ecommerce_catalog_store_endpoint' => ['gateway_domain', '/api/v1/ecommerce/store'], 'ecommerce_catalog_brands_endpoint' => ['gateway_domain', '/api/v1/ecommerce/brands'], 'ecommerce_catalog_categories_endpoint' => ['gateway_domain', '/api/v1/ecommerce/categories'], 'ecommerce_catalog_tags_endpoint' => ['gateway_domain', '/api/v1/ecommerce/tags'], 'ecommerce_catalog_attributes_endpoint' => ['gateway_domain', '/api/v1/ecommerce/attributes'], 'ecommerce_catalog_object_ids_endpoint' => ['gateway_domain', '/api/v1/ecommerce/object-ids'], 'ecommerce_catalog_phase_endpoint' => ['gateway_domain', '/api/v1/ecommerce/acquisition/phase'], 'ecommerce_catalog_progress_endpoint' => ['gateway_domain', '/api/v1/ecommerce/pipeline/progress'], 'ecommerce_catalog_complete_endpoint' => ['gateway_domain', '/api/v1/ecommerce/complete'], 'ecommerce_catalog_images_endpoint' => ['gateway_domain', '/api/v1/ecommerce/images'], 'plugin_deactivation_feedback_endpoint' => ['gateway_domain', '/api/plugin/deactivation-feedback'], 'events_batch_endpoint' => ['gateway_domain', '/api/plugin/events/batch'], 'events_erase_endpoint' => ['gateway_domain', '/api/plugin/events/erase'], 'wordpress_integration_enable_endpoint' => ['gateway_domain', '/api/plugin/integrations/wordpress/enable'], 'wordpress_integration_authorize_endpoint' => ['gateway_domain', '/api/plugin/integrations/wordpress/authorize'], 'wordpress_integration_disable_endpoint' => ['gateway_domain', '/api/plugin/integrations/wordpress/disable'], 'wordpress_user_access_revoked_endpoint' => ['gateway_domain', '/api/plugin/wordpress-user-access-revoked'], 'woocommerce_integration_enable_endpoint' => ['gateway_domain', '/api/plugin/integrations/woocommerce/enable'], 'woocommerce_integration_authorize_endpoint' => ['gateway_domain', '/api/plugin/integrations/woocommerce/authorize'], 'woocommerce_integration_disable_endpoint' => ['gateway_domain', '/api/plugin/integrations/woocommerce/disable'], 'contact_form_endpoint' => ['gateway_domain', '/api/chat/postMessage'], 'support_contact_form_endpoint' => ['gateway_domain', '/api/chat/postMessage'], 'turnstile_bridge_url' => ['verification_domain', '/turnstile/wordpress/'], ]; foreach ($routes as $endpoint => [$origin_key, $path]) { $origin = isset($config[$origin_key]) ? (string) $config[$origin_key] : ''; $config[$endpoint] = $origin === '' ? '' : rtrim($origin, '/') . $path; } return $config; } /** Validate endpoint and transport invariants without logging endpoint values. */ function vasp_validate_config($config, $environment) { $errors = []; if (!is_array($config)) { $config = []; $errors[] = 'invalid_configuration_type'; } $allow_private_network = !empty($config['allow_private_network']); foreach (['dashboard_domain', 'gateway_domain', 'widget_portal_url', 'verification_domain'] as $key) { $value = isset($config[$key]) ? (string) $config[$key] : ''; $parts = $value !== '' ? wp_parse_url($value) : false; if (!is_array($parts) || empty($parts['scheme']) || empty($parts['host'])) { $errors[] = 'invalid_' . $key; continue; } $scheme = strtolower((string) $parts['scheme']); if (!in_array($scheme, ['http', 'https'], true)) { $errors[] = 'invalid_scheme_' . $key; } elseif (!$allow_private_network && $scheme !== 'https') { $errors[] = 'https_required_' . $key; } } if (!$allow_private_network) { $config['ssl_verify'] = true; } else { $config['ssl_verify'] = !empty($config['ssl_verify']); } $config['environment'] = $environment; $config['configuration_errors'] = array_values(array_unique($errors)); $config['configuration_valid'] = empty($config['configuration_errors']); if (!$config['configuration_valid'] && function_exists('vasp_log')) { vasp_log('ValueSpace configuration validation failed', 'error', [ 'environment' => $environment, 'error_codes' => $config['configuration_errors'], ]); } return $config; } /** Return the deployment identity embedded in the selected runtime file. */ function vasp_get_environment() { return defined('VASP_RUNTIME_ENVIRONMENT') ? sanitize_key((string) VASP_RUNTIME_ENVIRONMENT) : 'unconfigured'; } /** Return one fixed application endpoint URL with optional query parameters. */ function vasp_get_endpoint_url($endpoint, $params = []) { $endpoint = (string) $endpoint; $url = (string) vasp_get_config($endpoint); $parts = $url !== '' ? wp_parse_url($url) : false; if (!is_array($parts) || empty($parts['scheme']) || empty($parts['host'])) { return vasp_create_error(VASP_ERROR_MISSING_ENDPOINT, [ 'endpoint' => sanitize_key($endpoint), ]); } return empty($params) ? $url : add_query_arg($params, $url); }