Skip to content

Commit

Permalink
no console noise
Browse files Browse the repository at this point in the history
  • Loading branch information
zburke committed Oct 10, 2023
1 parent 5b3a49c commit a3fe0be
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const IS_ROTATING_INTERVAL = 100;
* @returns boolean
*/
export const isValidAT = (te) => {
console.log(`-- (rtr-sw) => at expires ${new Date(te?.atExpires || null).toISOString()}`);
// console.log(`-- (rtr-sw) => at expires ${new Date(te?.atExpires || null).toISOString()}`);
return !!(te?.atExpires > Date.now());
};

Expand All @@ -80,7 +80,7 @@ export const isValidAT = (te) => {
* @returns boolean
*/
export const isValidRT = (te) => {
console.log(`-- (rtr-sw) => rt expires ${new Date(te?.rtExpires || null).toISOString()}`);
// console.log(`-- (rtr-sw) => rt expires ${new Date(te?.rtExpires || null).toISOString()}`);
return !!(te?.rtExpires > Date.now());
};

Expand All @@ -95,7 +95,7 @@ export const messageToClient = async (event, message) => {
// Exit early if we don't have access to the client.
// Eg, if it's cross-origin.
if (!event.clientId) {
console.log('-- (rtr-sw) PASSTHROUGH: no clientId');
// console.log('-- (rtr-sw) PASSTHROUGH: no clientId');
return;
}

Expand All @@ -104,12 +104,12 @@ export const messageToClient = async (event, message) => {
// Exit early if we don't get the client.
// Eg, if it closed.
if (!client) {
console.log('-- (rtr-sw) PASSTHROUGH: no client');
// console.log('-- (rtr-sw) PASSTHROUGH: no client');
return;
}

// Send a message to the client.
console.log('-- (rtr-sw) => sending', message);
// console.log('-- (rtr-sw) => sending', message);
client.postMessage({ ...message, source: '@folio/stripes-core' });
};

Expand All @@ -124,7 +124,7 @@ export const messageToClient = async (event, message) => {
* @throws if RTR fails
*/
export const rtr = async (event) => {
console.log('-- (rtr-sw) ** RTR ...');
// console.log('-- (rtr-sw) ** RTR ...');

// if several fetches trigger rtr in a short window, all but the first will
// fail because the RT will be stale after the first request rotates it.
Expand All @@ -135,7 +135,7 @@ export const rtr = async (event) => {
// IS_ROTATING_RETRIES * IS_ROTATING_INTERVAL milliseconds and return failure.
if (isRotating) {
for (let i = 0; i < IS_ROTATING_RETRIES; i++) {
console.log(`-- (rtr-sw) ** is rotating; waiting ${IS_ROTATING_INTERVAL}ms`);
// console.log(`-- (rtr-sw) ** is rotating; waiting ${IS_ROTATING_INTERVAL}ms`);
await new Promise(resolve => setTimeout(resolve, IS_ROTATING_INTERVAL));
if (!isRotating) {
return Promise.resolve();
Expand Down Expand Up @@ -173,7 +173,7 @@ export const rtr = async (event) => {
});
})
.then(json => {
console.log('-- (rtr-sw) ** success!');
// console.log('-- (rtr-sw) ** success!');
isRotating = false;
tokenExpiration = {
atExpires: new Date(json.accessTokenExpiration).getTime(),
Expand Down Expand Up @@ -208,7 +208,7 @@ export const isPermissibleRequest = (req, te, oUrl) => {
'/saml/check',
];

// console.log(`-- (rtr-sw) AT invalid for ${req.url}`);
// // console.log(`-- (rtr-sw) AT invalid for ${req.url}`);
return !!permissible.find(i => req.url.startsWith(`${oUrl}${i}`));
};

Expand Down Expand Up @@ -252,10 +252,10 @@ export const isOkapiRequest = (req, oUrl) => {
* @returns Promise
*/
const passThroughWithRT = (event) => {
const req = event.request.clone();
return rtr(event)
.then(() => {
console.log('-- (rtr-sw) => post-rtr-fetch', req.url);
// const req = event.request.clone();
// console.log('-- (rtr-sw) => post-rtr-fetch', req.url);
return fetch(event.request, { credentials: 'include' });
})
.catch((rtre) => {
Expand Down Expand Up @@ -284,15 +284,15 @@ const passThroughWithRT = (event) => {
* @throws if any fetch fails
*/
const passThroughWithAT = (event) => {
console.log('-- (rtr-sw) (valid AT or authn request)');
// console.log('-- (rtr-sw) (valid AT or authn request)');
return fetch(event.request, { credentials: 'include' })
.then(response => {
if (response.ok) {
return response;
} else {
// we thought the AT was valid but it wasn't, so try again.
// if we fail this time, we're done.
console.log('-- (rtr-sw) (whoops, invalid AT; retrying)');
// console.log('-- (rtr-sw) (whoops, invalid AT; retrying)');
return passThroughWithRT(event);
}
});
Expand All @@ -308,7 +308,7 @@ const passThroughWithAT = (event) => {
* @returns Promise
*/
export const passThroughLogout = (event) => {
console.log('-- (rtr-sw) (logout request)');
// console.log('-- (rtr-sw) (logout request)');
return fetch(event.request, { credentials: 'include' })
.catch(e => {
// kill me softly: return an empty response to allow graceful failure
Expand All @@ -335,7 +335,7 @@ export const passThrough = (event, te, oUrl) => {

// okapi requests are subject to RTR
if (isOkapiRequest(req, oUrl)) {
console.log('-- (rtr-sw) => will fetch', req.url);
// console.log('-- (rtr-sw) => will fetch', req.url);
if (isLogoutRequest(req, oUrl)) {
return passThroughLogout(event);
}
Expand All @@ -345,7 +345,7 @@ export const passThrough = (event, te, oUrl) => {
}

if (isValidRT(te)) {
console.log('-- (rtr-sw) => valid RT');
// console.log('-- (rtr-sw) => valid RT');
return passThroughWithRT(event);
}

Expand All @@ -371,8 +371,8 @@ export const passThrough = (event, te, oUrl) => {
* install
* on install, force this SW to be the active SW
*/
self.addEventListener('install', (event) => {
console.log('-- (rtr-sw) => install', event);
self.addEventListener('install', (_event) => {
// console.log('-- (rtr-sw) => install', event);
return self.skipWaiting();
});

Expand All @@ -382,7 +382,7 @@ self.addEventListener('install', (event) => {
* even those that loaded before this SW was registered.
*/
self.addEventListener('activate', async (event) => {
console.log('-- (rtr-sw) => activate', event);
// console.log('-- (rtr-sw) => activate', event);
event.waitUntil(self.clients.claim());
});

Expand Down

0 comments on commit a3fe0be

Please sign in to comment.