1. /**
  2. * Reloads the log entry configuration for sandbox usage with manual overrides.
  3. *
  4. * @param {object} config - The base configuration object.
  5. * @param {object} overrides - An object containing manual overrides for specific settings.
  6. * @returns {Promise<object>} - A promise that resolves with the updated configuration.
  7. */
  8. async function reloadSandboxLogConfig(config, overrides) {
  9. try {
  10. // Simulate fetching the new configuration. Replace with actual API call.
  11. const newConfig = await fetchConfig();
  12. // Merge the new configuration with the existing configuration, applying overrides.
  13. const updatedConfig = mergeConfigurations(newConfig, config, overrides);
  14. return updatedConfig;
  15. } catch (error) {
  16. console.error("Error reloading sandbox log config:", error);
  17. throw error; // Re-throw the error for handling upstream.
  18. }
  19. }
  20. /**
  21. * Simulates fetching the configuration from an API. Replace with your actual API call.
  22. * @returns {Promise<object>}
  23. */
  24. async function fetchConfig() {
  25. // Dummy configuration - replace with your actual API endpoint.
  26. return new Promise((resolve) => {
  27. setTimeout(() => {
  28. resolve({
  29. logLevel: "info",
  30. includeUserAgent: true,
  31. excludeIPs: ["127.0.0.1", "192.168.1.1"],
  32. // Add other settings here
  33. });
  34. }, 500); // Simulate network latency
  35. });
  36. }
  37. /**
  38. * Merges two configuration objects, prioritizing overrides.
  39. * @param {object} baseConfig - The base configuration.
  40. * @param {object} overrides - The overrides configuration.
  41. * @returns {object} - The merged configuration.
  42. */
  43. function mergeConfigurations(baseConfig, overrides, manualOverrides) {
  44. const mergedConfig = { ...baseConfig }; // Start with a copy of the base config
  45. // Apply manual overrides
  46. if (manualOverrides) {
  47. for (const key in manualOverrides) {
  48. if (manualOverrides.hasOwnProperty(key)) {
  49. mergedConfig[key] = manualOverrides[key];
  50. }
  51. }
  52. }
  53. // Apply overrides - overwrite base config values
  54. for (const key in overrides) {
  55. if (overrides.hasOwnProperty(key)) {
  56. mergedConfig[key] = overrides[key];
  57. }
  58. }
  59. return mergedConfig;
  60. }
  61. // Export the function if needed.
  62. export { reloadSandboxLogConfig };

Add your comment