1. /**
  2. * Configures cookies for maintenance tasks with manual overrides.
  3. *
  4. * @param {object} options - Configuration options for the cookies.
  5. * @param {object} [options.defaults] - Default cookie values.
  6. * @param {object} [options.overrides] - Manual overrides for specific cookies.
  7. * @param {string} [options.domain] - The domain for the cookies (optional).
  8. * @param {string} [options.path] - The path for the cookies (optional).
  9. * @param {boolean} [options.secure] - Whether to set the cookie securely (HTTPS only) (optional).
  10. * @param {boolean} [options.httpOnly] - Whether to set the cookie as HTTPOnly (optional).
  11. */
  12. function configureMaintenanceCookies(options) {
  13. const defaults = options.defaults || {};
  14. const overrides = options.overrides || {};
  15. const domain = options.domain;
  16. const path = options.path || '/';
  17. const secure = options.secure || false;
  18. const httpOnly = options.httpOnly || false;
  19. for (const cookieName in defaults) {
  20. document.cookie = `${cookieName}=${defaults[cookieName]}; path=${path}`;
  21. }
  22. for (const cookieName in overrides) {
  23. document.cookie = `${cookieName}=${overrides[cookieName]}; path=${path}`;
  24. }
  25. if (domain) {
  26. document.cookie = `${defaults.sessionCookie}=${defaults.sessionValue}; domain=${domain}; path=${path}`;
  27. }
  28. if (secure) {
  29. document.cookie = `${defaults.sessionCookie}=${defaults.sessionValue}; secure; path=${path}`;
  30. }
  31. if (httpOnly) {
  32. document.cookie = `${defaults.sessionCookie}=${defaults.sessionValue}; httpOnly; path=${path}`;
  33. }
  34. }

Add your comment