Skip to content
Snippets Groups Projects
Commit c6a81416 authored by Sky Brewer's avatar Sky Brewer
Browse files

Update common

parent f7690720
No related branches found
No related tags found
2 merge requests!612Release 5.0.0,!562CE-3339: Add vite
This diff is collapsed.
...@@ -2,127 +2,127 @@ ...@@ -2,127 +2,127 @@
/* tslint:disable */ /* tslint:disable */
/** /**
* Mock Service Worker (1.3.2). * Mock Service Worker (1.3.5).
* @see https://github.com/mswjs/msw * @see https://github.com/mswjs/msw
* - Please do NOT modify this file. * - Please do NOT modify this file.
* - Please do NOT serve this file on production. * - Please do NOT serve this file on production.
*/ */
const INTEGRITY_CHECKSUM = "3d6b9f06410d179a7f7404d4bf4c3c70"; const INTEGRITY_CHECKSUM = '3d6b9f06410d179a7f7404d4bf4c3c70'
const activeClientIds = new Set(); const activeClientIds = new Set()
self.addEventListener("install", function () { self.addEventListener('install', function () {
self.skipWaiting(); self.skipWaiting()
}); })
self.addEventListener("activate", function (event) { self.addEventListener('activate', function (event) {
event.waitUntil(self.clients.claim()); event.waitUntil(self.clients.claim())
}); })
self.addEventListener("message", async function (event) { self.addEventListener('message', async function (event) {
const clientId = event.source.id; const clientId = event.source.id
if (!clientId || !self.clients) { if (!clientId || !self.clients) {
return; return
} }
const client = await self.clients.get(clientId); const client = await self.clients.get(clientId)
if (!client) { if (!client) {
return; return
} }
const allClients = await self.clients.matchAll({ const allClients = await self.clients.matchAll({
type: "window" type: 'window',
}); })
switch (event.data) { switch (event.data) {
case "KEEPALIVE_REQUEST": { case 'KEEPALIVE_REQUEST': {
sendToClient(client, { sendToClient(client, {
type: "KEEPALIVE_RESPONSE" type: 'KEEPALIVE_RESPONSE',
}); })
break; break
} }
case "INTEGRITY_CHECK_REQUEST": { case 'INTEGRITY_CHECK_REQUEST': {
sendToClient(client, { sendToClient(client, {
type: "INTEGRITY_CHECK_RESPONSE", type: 'INTEGRITY_CHECK_RESPONSE',
payload: INTEGRITY_CHECKSUM payload: INTEGRITY_CHECKSUM,
}); })
break; break
} }
case "MOCK_ACTIVATE": { case 'MOCK_ACTIVATE': {
activeClientIds.add(clientId); activeClientIds.add(clientId)
sendToClient(client, { sendToClient(client, {
type: "MOCKING_ENABLED", type: 'MOCKING_ENABLED',
payload: true payload: true,
}); })
break; break
} }
case "MOCK_DEACTIVATE": { case 'MOCK_DEACTIVATE': {
activeClientIds.delete(clientId); activeClientIds.delete(clientId)
break; break
} }
case "CLIENT_CLOSED": { case 'CLIENT_CLOSED': {
activeClientIds.delete(clientId); activeClientIds.delete(clientId)
const remainingClients = allClients.filter((client) => { const remainingClients = allClients.filter((client) => {
return client.id !== clientId; return client.id !== clientId
}); })
// Unregister itself when there are no more clients // Unregister itself when there are no more clients
if (remainingClients.length === 0) { if (remainingClients.length === 0) {
self.registration.unregister(); self.registration.unregister()
} }
break; break
} }
} }
}); })
self.addEventListener("fetch", function (event) { self.addEventListener('fetch', function (event) {
const { request } = event; const { request } = event
const accept = request.headers.get("accept") || ""; const accept = request.headers.get('accept') || ''
// Bypass server-sent events. // Bypass server-sent events.
if (accept.includes("text/event-stream")) { if (accept.includes('text/event-stream')) {
return; return
} }
// Bypass navigation requests. // Bypass navigation requests.
if (request.mode === "navigate") { if (request.mode === 'navigate') {
return; return
} }
// Opening the DevTools triggers the "only-if-cached" request // Opening the DevTools triggers the "only-if-cached" request
// that cannot be handled by the worker. Bypass such requests. // that cannot be handled by the worker. Bypass such requests.
if (request.cache === "only-if-cached" && request.mode !== "same-origin") { if (request.cache === 'only-if-cached' && request.mode !== 'same-origin') {
return; return
} }
// Bypass all requests when there are no active clients. // Bypass all requests when there are no active clients.
// Prevents the self-unregistered worked from handling requests // Prevents the self-unregistered worked from handling requests
// after it's been deleted (still remains active until the next reload). // after it's been deleted (still remains active until the next reload).
if (activeClientIds.size === 0) { if (activeClientIds.size === 0) {
return; return
} }
// Generate unique request ID. // Generate unique request ID.
const requestId = Math.random().toString(16).slice(2); const requestId = Math.random().toString(16).slice(2)
event.respondWith( event.respondWith(
handleRequest(event, requestId).catch((error) => { handleRequest(event, requestId).catch((error) => {
if (error.name === "NetworkError") { if (error.name === 'NetworkError') {
console.warn( console.warn(
'[MSW] Successfully emulated a network error for the "%s %s" request.', '[MSW] Successfully emulated a network error for the "%s %s" request.',
request.method, request.method,
request.url request.url,
); )
return; return
} }
// At this point, any exception indicates an issue with the original request/response. // At this point, any exception indicates an issue with the original request/response.
...@@ -131,24 +131,24 @@ self.addEventListener("fetch", function (event) { ...@@ -131,24 +131,24 @@ self.addEventListener("fetch", function (event) {
[MSW] Caught an exception from the "%s %s" request (%s). This is probably not a problem with Mock Service Worker. There is likely an additional logging output above.`, [MSW] Caught an exception from the "%s %s" request (%s). This is probably not a problem with Mock Service Worker. There is likely an additional logging output above.`,
request.method, request.method,
request.url, request.url,
`${error.name}: ${error.message}` `${error.name}: ${error.message}`,
); )
}) }),
); )
}); })
async function handleRequest(event, requestId) { async function handleRequest(event, requestId) {
const client = await resolveMainClient(event); const client = await resolveMainClient(event)
const response = await getResponse(event, client, requestId); const response = await getResponse(event, client, requestId)
// Send back the response clone for the "response:*" life-cycle events. // Send back the response clone for the "response:*" life-cycle events.
// Ensure MSW is active and ready to handle the message, otherwise // Ensure MSW is active and ready to handle the message, otherwise
// this message will pend indefinitely. // this message will pend indefinitely.
if (client && activeClientIds.has(client.id)) { if (client && activeClientIds.has(client.id)) {
(async function () { ;(async function () {
const clonedResponse = response.clone(); const clonedResponse = response.clone()
sendToClient(client, { sendToClient(client, {
type: "RESPONSE", type: 'RESPONSE',
payload: { payload: {
requestId, requestId,
type: clonedResponse.type, type: clonedResponse.type,
...@@ -158,13 +158,13 @@ async function handleRequest(event, requestId) { ...@@ -158,13 +158,13 @@ async function handleRequest(event, requestId) {
body: body:
clonedResponse.body === null ? null : await clonedResponse.text(), clonedResponse.body === null ? null : await clonedResponse.text(),
headers: Object.fromEntries(clonedResponse.headers.entries()), headers: Object.fromEntries(clonedResponse.headers.entries()),
redirected: clonedResponse.redirected redirected: clonedResponse.redirected,
} },
}); })
})(); })()
} }
return response; return response
} }
// Resolve the main client for the given event. // Resolve the main client for the given event.
...@@ -172,49 +172,49 @@ async function handleRequest(event, requestId) { ...@@ -172,49 +172,49 @@ async function handleRequest(event, requestId) {
// that registered the worker. It's with the latter the worker should // that registered the worker. It's with the latter the worker should
// communicate with during the response resolving phase. // communicate with during the response resolving phase.
async function resolveMainClient(event) { async function resolveMainClient(event) {
const client = await self.clients.get(event.clientId); const client = await self.clients.get(event.clientId)
if (client?.frameType === "top-level") { if (client?.frameType === 'top-level') {
return client; return client
} }
const allClients = await self.clients.matchAll({ const allClients = await self.clients.matchAll({
type: "window" type: 'window',
}); })
return allClients return allClients
.filter((client) => { .filter((client) => {
// Get only those clients that are currently visible. // Get only those clients that are currently visible.
return client.visibilityState === "visible"; return client.visibilityState === 'visible'
}) })
.find((client) => { .find((client) => {
// Find the client ID that's recorded in the // Find the client ID that's recorded in the
// set of clients that have registered the worker. // set of clients that have registered the worker.
return activeClientIds.has(client.id); return activeClientIds.has(client.id)
}); })
} }
async function getResponse(event, client, requestId) { async function getResponse(event, client, requestId) {
const { request } = event; const { request } = event
const clonedRequest = request.clone(); const clonedRequest = request.clone()
function passthrough() { function passthrough() {
// Clone the request because it might've been already used // Clone the request because it might've been already used
// (i.e. its body has been read and sent to the client). // (i.e. its body has been read and sent to the client).
const headers = Object.fromEntries(clonedRequest.headers.entries()); const headers = Object.fromEntries(clonedRequest.headers.entries())
// Remove MSW-specific request headers so the bypassed requests // Remove MSW-specific request headers so the bypassed requests
// comply with the server's CORS preflight check. // comply with the server's CORS preflight check.
// Operate with the headers as an object because request "Headers" // Operate with the headers as an object because request "Headers"
// are immutable. // are immutable.
delete headers["x-msw-bypass"]; delete headers['x-msw-bypass']
return fetch(clonedRequest, { headers }); return fetch(clonedRequest, { headers })
} }
// Bypass mocking when the client is not active. // Bypass mocking when the client is not active.
if (!client) { if (!client) {
return passthrough(); return passthrough()
} }
// Bypass initial page load requests (i.e. static assets). // Bypass initial page load requests (i.e. static assets).
...@@ -222,18 +222,18 @@ async function getResponse(event, client, requestId) { ...@@ -222,18 +222,18 @@ async function getResponse(event, client, requestId) {
// means that MSW hasn't dispatched the "MOCK_ACTIVATE" event yet // means that MSW hasn't dispatched the "MOCK_ACTIVATE" event yet
// and is not ready to handle requests. // and is not ready to handle requests.
if (!activeClientIds.has(client.id)) { if (!activeClientIds.has(client.id)) {
return passthrough(); return passthrough()
} }
// Bypass requests with the explicit bypass header. // Bypass requests with the explicit bypass header.
// Such requests can be issued by "ctx.fetch()". // Such requests can be issued by "ctx.fetch()".
if (request.headers.get("x-msw-bypass") === "true") { if (request.headers.get('x-msw-bypass') === 'true') {
return passthrough(); return passthrough()
} }
// Notify the client that a request has been intercepted. // Notify the client that a request has been intercepted.
const clientMessage = await sendToClient(client, { const clientMessage = await sendToClient(client, {
type: "REQUEST", type: 'REQUEST',
payload: { payload: {
id: requestId, id: requestId,
url: request.url, url: request.url,
...@@ -249,55 +249,55 @@ async function getResponse(event, client, requestId) { ...@@ -249,55 +249,55 @@ async function getResponse(event, client, requestId) {
referrerPolicy: request.referrerPolicy, referrerPolicy: request.referrerPolicy,
body: await request.text(), body: await request.text(),
bodyUsed: request.bodyUsed, bodyUsed: request.bodyUsed,
keepalive: request.keepalive keepalive: request.keepalive,
} },
}); })
switch (clientMessage.type) { switch (clientMessage.type) {
case "MOCK_RESPONSE": { case 'MOCK_RESPONSE': {
return respondWithMock(clientMessage.data); return respondWithMock(clientMessage.data)
} }
case "MOCK_NOT_FOUND": { case 'MOCK_NOT_FOUND': {
return passthrough(); return passthrough()
} }
case "NETWORK_ERROR": { case 'NETWORK_ERROR': {
const { name, message } = clientMessage.data; const { name, message } = clientMessage.data
const networkError = new Error(message); const networkError = new Error(message)
networkError.name = name; networkError.name = name
// Rejecting a "respondWith" promise emulates a network error. // Rejecting a "respondWith" promise emulates a network error.
throw networkError; throw networkError
} }
} }
return passthrough(); return passthrough()
} }
function sendToClient(client, message) { function sendToClient(client, message) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const channel = new MessageChannel(); const channel = new MessageChannel()
channel.port1.onmessage = (event) => { channel.port1.onmessage = (event) => {
if (event.data && event.data.error) { if (event.data && event.data.error) {
return reject(event.data.error); return reject(event.data.error)
} }
resolve(event.data); resolve(event.data)
}; }
client.postMessage(message, [channel.port2]); client.postMessage(message, [channel.port2])
}); })
} }
function sleep(timeMs) { function sleep(timeMs) {
return new Promise((resolve) => { return new Promise((resolve) => {
setTimeout(resolve, timeMs); setTimeout(resolve, timeMs)
}); })
} }
async function respondWithMock(response) { async function respondWithMock(response) {
await sleep(response.delay); await sleep(response.delay)
return new Response(response.body, response); return new Response(response.body, response)
} }
...@@ -4,7 +4,8 @@ import { useTypingTimer } from "../../common/SearchBoxFilter/TypingTimer"; ...@@ -4,7 +4,8 @@ import { useTypingTimer } from "../../common/SearchBoxFilter/TypingTimer";
import { useCustomSnackbar } from "../../common/snackbar"; import { useCustomSnackbar } from "../../common/snackbar";
import { RepositoryOptions, WITHOUT_REPO } from "./RepositoryOptions"; import { RepositoryOptions, WITHOUT_REPO } from "./RepositoryOptions";
import { RepositoryName } from "./RepositoryName"; import { RepositoryName } from "./RepositoryName";
import { RootPaper } from "@ess-ics/ce-ui-common/dist/components/common/container/RootPaper"; import { RootPaper, useAPIMethod } from "@ess-ics/ce-ui-common";
import { import {
Alert, Alert,
Autocomplete, Autocomplete,
...@@ -15,7 +16,6 @@ import { ...@@ -15,7 +16,6 @@ import {
TextField, TextField,
Typography Typography
} from "@mui/material"; } from "@mui/material";
import { useAPIMethod } from "@ess-ics/ce-ui-common";
import { apiContext } from "../../../api/DeployApi"; import { apiContext } from "../../../api/DeployApi";
import { getErrorMessage } from "../../common/Helper"; import { getErrorMessage } from "../../common/Helper";
......
import { useAPIMethod } from "@ess-ics/ce-ui-common/dist/hooks/API"; import { useAPIMethod, userContext } from "@ess-ics/ce-ui-common";
import { Avatar, Tooltip, styled } from "@mui/material"; import { Avatar, Tooltip, styled } from "@mui/material";
import { useContext, useEffect, useMemo } from "react"; import { useContext, useEffect, useMemo } from "react";
import { apiContext } from "../../../api/DeployApi"; import { apiContext } from "../../../api/DeployApi";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import { userContext } from "@ess-ics/ce-ui-common/dist/contexts/User";
const unpacker = (data) => { const unpacker = (data) => {
if (data) { if (data) {
......
...@@ -3,10 +3,9 @@ import { IOCDetailsView } from "./IOCDetailsView"; ...@@ -3,10 +3,9 @@ import { IOCDetailsView } from "./IOCDetailsView";
import { LinearProgress } from "@mui/material"; import { LinearProgress } from "@mui/material";
import NotFoundView from "../../components/navigation/NotFoundView/NotFoundView"; import NotFoundView from "../../components/navigation/NotFoundView/NotFoundView";
import { onFetchEntityError } from "../../components/common/Helper"; import { onFetchEntityError } from "../../components/common/Helper";
import { userContext } from "@ess-ics/ce-ui-common/dist/contexts/User"; import { userContext, useAPIMethod } from "@ess-ics/ce-ui-common";
import useUrlState from "@ahooksjs/use-url-state"; import useUrlState from "@ahooksjs/use-url-state";
import { apiContext } from "../../api/DeployApi"; import { apiContext } from "../../api/DeployApi";
import { useAPIMethod } from "@ess-ics/ce-ui-common";
export function IOCDetailsContainer({ id }) { export function IOCDetailsContainer({ id }) {
const { user } = useContext(userContext); const { user } = useContext(userContext);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment