{"version":3,"file":"index.js","sources":["../src/cookieHelper.js","../src/constants.js","../src/client.js","../src/icons.js","../src/incidentwebcomponent.js","../src/incident.js"],"sourcesContent":["function setCookie(name, value, minutes) {\r\n const date = new Date();\r\n date.setTime(date.getTime() + minutes * 60 * 1000);\r\n const expires = 'expires=' + date.toUTCString();\r\n document.cookie = `${name}=${value}; SameSite=Strict; Secure; ${expires}`;\r\n}\r\n\r\nfunction cookieExists(name) {\r\n const cookies = document.cookie.split(';');\r\n for (let i = 0; i < cookies.length; i++) {\r\n const cookie = cookies[i].trim();\r\n // Check if the cookie name matches the one you're looking for\r\n if (cookie.startsWith(name + '=')) {\r\n return true; // The cookie exists\r\n }\r\n }\r\n return false; // The cookie does not exist\r\n}\r\n\r\nexport { setCookie, cookieExists };\r\n","const IMPACTS = {\r\n DEGRADEDPERFORMANCE: 'DEGRADEDPERFORMANCE',\r\n PARTIALOUTAGE: 'PARTIALOUTAGE',\r\n MAJOROUTAGE: 'MAJOROUTAGE',\r\n};\r\n\r\nconst BASEURL = {\r\n Development: 'https://byggtjanstdev.instatus.com',\r\n Production: 'https://status.byggtjanst.se',\r\n};\r\n\r\nexport { IMPACTS, BASEURL };\r\n","import { cookieExists } from './cookieHelper';\r\nimport { BASEURL, IMPACTS } from './constants';\r\n\r\nasync function fetchComponents(baseUrl) {\r\n const res = await fetch(baseUrl + '/components.json', { mode: 'cors' });\r\n const data = await res.json();\r\n return data;\r\n}\r\n\r\nconst statusPageClient = ({ componentId, isDevelopment, summary = false }) => {\r\n const baseUrl = isDevelopment ? BASEURL.Development : BASEURL.Production;\r\n\r\n const getSummaryStatus = async () => {\r\n const data = await fetchComponents(baseUrl);\r\n\r\n var components = data.components.filter(\r\n (d) => d.id === componentId || d.status === IMPACTS.MAJOROUTAGE\r\n );\r\n\r\n var incidents = components\r\n .flatMap((obj) => obj.activeIncidents && obj.activeIncidents)\r\n .filter(\r\n (v, i, a) =>\r\n v != undefined && a.findIndex((v2) => v2?.id === v?.id) === i\r\n )\r\n .map((incident) => {\r\n return {\r\n ...incident,\r\n started: new Date(incident.started).toISOString(),\r\n };\r\n });\r\n\r\n return {\r\n activeIncidents: incidents || [],\r\n activeMaintenance:\r\n components\r\n .find((c) => c.id === componentId)\r\n ?.activeMaintenances?.map((maintenance) => {\r\n return {\r\n ...maintenance,\r\n start: new Date(maintenance.start).toISOString(),\r\n end: new Date(\r\n new Date(maintenance.start).getTime() +\r\n parseInt(maintenance.duration) * 60000\r\n ).toISOString(),\r\n };\r\n }) || [],\r\n };\r\n };\r\n\r\n const getStatus = async () => {\r\n if (summary) {\r\n return await getSummaryStatus();\r\n }\r\n\r\n const { components } = await fetchComponents(baseUrl);\r\n const component = components.find((c) => c.id == componentId);\r\n return {\r\n id: component.id,\r\n name: component.name,\r\n activeIncidents:\r\n component.activeIncidents?.map((incident) => {\r\n return {\r\n ...incident,\r\n started: new Date(incident.started).toISOString(),\r\n };\r\n }) || [],\r\n activeMaintenance:\r\n component.activeMaintenances?.map((maintenance) => {\r\n return {\r\n ...maintenance,\r\n start: new Date(maintenance.start).toISOString(),\r\n end: new Date(\r\n new Date(maintenance.start).getTime() +\r\n parseInt(maintenance.duration) * 60000\r\n ).toISOString(),\r\n };\r\n }) || [],\r\n };\r\n };\r\n\r\n return {\r\n getStatus,\r\n };\r\n};\r\n\r\nexport { statusPageClient };\r\n","import { IMPACTS } from './constants';\r\n\r\nconst iconSize = '18px';\r\n\r\nfunction closeIcon(color) {\r\n return `\r\n `;\r\n}\r\n\r\nfunction impactIcon(impact) {\r\n switch (impact) {\r\n case IMPACTS.DEGRADEDPERFORMANCE:\r\n case IMPACTS.PARTIALOUTAGE:\r\n return ``;\r\n case IMPACTS.MAJOROUTAGE:\r\n return `\r\n `;\r\n default:\r\n return `\r\n `;\r\n }\r\n}\r\n\r\nexport { closeIcon, impactIcon };\r\n","import { statusPageClient } from './client';\r\nimport { incidentTemplate, maintenanceTemplate } from './incident';\r\nimport { setCookie, cookieExists } from './cookieHelper';\r\n\r\nclass SbIncident extends HTMLElement {\r\n connectedCallback() {\r\n this.init();\r\n }\r\n\r\n init() {\r\n this.client = statusPageClient({\r\n componentId: this.getAttribute('componentid'),\r\n isDevelopment: this.getAttribute('development') === 'true',\r\n summary: this.getAttribute('summary') === 'true',\r\n });\r\n\r\n this.closeTimer = parseInt(this.getAttribute('closetimer')) || 60;\r\n\r\n this.client.getStatus().then((incidents) => {\r\n this.incidents = incidents;\r\n let shadowRoot = this.attachShadow({ mode: 'open' });\r\n\r\n shadowRoot.innerHTML = this.style;\r\n shadowRoot.innerHTML += this.getIncidents;\r\n shadowRoot.innerHTML += this.getMaintenance;\r\n\r\n shadowRoot\r\n .querySelectorAll('.close-icon')\r\n .forEach((element) =>\r\n element.addEventListener('click', () =>\r\n this.handleCloseIncidentClick(element)\r\n )\r\n );\r\n });\r\n }\r\n\r\n handleCloseIncidentClick(element) {\r\n const incidentId = element.getAttribute('data-id');\r\n\r\n // User closed this incident, persist it in a cookie.\r\n setCookie(incidentId, incidentId, this.closeTimer);\r\n\r\n // Find the parent incident element\r\n const parentIncident = element.closest('.incident');\r\n\r\n if (parentIncident) {\r\n // fade it out\r\n parentIncident.classList.add('fade-out');\r\n\r\n // Then remove it from the layout\r\n parentIncident.addEventListener('transitionend', () => {\r\n parentIncident.style.display = 'none';\r\n });\r\n }\r\n }\r\n\r\n get style() {\r\n return `\r\n \r\n `;\r\n }\r\n\r\n get getMaintenance() {\r\n let maintenances = this.incidents.activeMaintenance;\r\n if (maintenances) {\r\n return maintenances\r\n .filter((m) => !cookieExists(m.id))\r\n .map((m) => maintenanceTemplate(m))\r\n .join('');\r\n }\r\n }\r\n\r\n get getIncidents() {\r\n let incidents = this.incidents.activeIncidents;\r\n if (incidents) {\r\n return incidents\r\n .filter((incident) => !cookieExists(incident.id))\r\n .map((incident) => incidentTemplate(incident))\r\n .join('');\r\n }\r\n }\r\n}\r\n\r\ncustomElements.define('sb-incident', SbIncident);\r\n","import { impactIcon, closeIcon } from './icons';\r\nimport { IMPACTS } from './constants';\r\n\r\nfunction incidentTemplate({ name, url, impact, id }) {\r\n if (!id) {\r\n return '';\r\n }\r\n switch (impact) {\r\n case IMPACTS.DEGRADEDPERFORMANCE:\r\n case IMPACTS.PARTIALOUTAGE:\r\n return `\r\n
${name}
\r\n${name}
\r\n${name}
\r\n \r\n