Socket
Socket
Sign inDemoInstall

workbox-core

Package Overview
Dependencies
Maintainers
4
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

workbox-core - npm Package Compare versions

Comparing version 4.1.1 to 4.2.0

131

build/workbox-core.dev.js

@@ -6,3 +6,3 @@ this.workbox = this.workbox || {};

try {
self['workbox:core:4.1.1'] && _();
self['workbox:core:4.2.0'] && _();
} catch (e) {} // eslint-disable-line

@@ -977,4 +977,10 @@

},
getPrefix: () => {
return _cacheNameDetails.prefix;
},
getRuntimeName: userCacheName => {
return userCacheName || _createCacheName(_cacheNameDetails.runtime);
},
getSuffix: () => {
return _cacheNameDetails.suffix;
}

@@ -992,2 +998,3 @@ };

CACHE_DID_UPDATE: 'cacheDidUpdate',
CACHE_KEY_WILL_BE_USED: 'cacheKeyWillBeUsed',
CACHE_WILL_UPDATE: 'cacheWillUpdate',

@@ -1064,9 +1071,24 @@ CACHED_RESPONSE_WILL_BE_USED: 'cachedResponseWillBeUsed',

} = {}) => {
{
if (request.method && request.method !== 'GET') {
throw new WorkboxError('attempt-to-cache-non-get-request', {
url: getFriendlyURL(request.url),
method: request.method
});
}
}
const effectiveRequest = await _getEffectiveRequest({
plugins,
request,
mode: 'write'
});
if (!response) {
{
logger.error(`Cannot cache non-existent response for ` + `'${getFriendlyURL(request.url)}'.`);
logger.error(`Cannot cache non-existent response for ` + `'${getFriendlyURL(effectiveRequest.url)}'.`);
}
throw new WorkboxError('cache-put-with-no-response', {
url: getFriendlyURL(request.url)
url: getFriendlyURL(effectiveRequest.url)
});

@@ -1076,6 +1098,6 @@ }

let responseToCache = await _isResponseSafeToCache({
request,
event,
plugins,
response,
event,
plugins
request: effectiveRequest
});

@@ -1085,3 +1107,3 @@

{
logger.debug(`Response '${getFriendlyURL(request.url)}' will not be ` + `cached.`, responseToCache);
logger.debug(`Response '${getFriendlyURL(effectiveRequest.url)}' will ` + `not be cached.`, responseToCache);
}

@@ -1092,11 +1114,2 @@

{
if (responseToCache.method && responseToCache.method !== 'GET') {
throw new WorkboxError('attempt-to-cache-non-get-request', {
url: getFriendlyURL(request.url),
method: responseToCache.method
});
}
}
const cache = await caches.open(cacheName);

@@ -1106,12 +1119,12 @@ const updatePlugins = pluginUtils.filter(plugins, pluginEvents.CACHE_DID_UPDATE);

cacheName,
request,
matchOptions
matchOptions,
request: effectiveRequest
}) : null;
{
logger.debug(`Updating the '${cacheName}' cache with a new Response for ` + `${getFriendlyURL(request.url)}.`);
logger.debug(`Updating the '${cacheName}' cache with a new Response for ` + `${getFriendlyURL(effectiveRequest.url)}.`);
}
try {
await cache.put(request, responseToCache);
await cache.put(effectiveRequest, responseToCache);
} catch (error) {

@@ -1129,6 +1142,6 @@ // See https://developer.mozilla.org/en-US/docs/Web/API/DOMException#exception-QuotaExceededError

cacheName,
request,
event,
oldResponse,
newResponse: responseToCache
newResponse: responseToCache,
request: effectiveRequest
});

@@ -1162,3 +1175,8 @@ }

const cache = await caches.open(cacheName);
let cachedResponse = await cache.match(request, matchOptions);
const effectiveRequest = await _getEffectiveRequest({
plugins,
request,
mode: 'read'
});
let cachedResponse = await cache.match(effectiveRequest, matchOptions);

@@ -1177,6 +1195,6 @@ {

cacheName,
request,
event,
matchOptions,
cachedResponse
cachedResponse,
request: effectiveRequest
});

@@ -1264,3 +1282,49 @@

};
/**
* Checks the list of plugins for the cacheKeyWillBeUsed callback, and
* executes any of those callbacks found in sequence. The final `Request` object
* returned by the last plugin is treated as the cache key for cache reads
* and/or writes.
*
* @param {Object} options
* @param {Request} options.request
* @param {string} options.mode
* @param {Array<Object>} [options.plugins=[]]
* @return {Promise<Request>}
*
* @private
* @memberof module:workbox-core
*/
const _getEffectiveRequest = async ({
request,
mode,
plugins
}) => {
const cacheKeyWillBeUsedPlugins = pluginUtils.filter(plugins, pluginEvents.CACHE_KEY_WILL_BE_USED);
let effectiveRequest = request;
for (const plugin of cacheKeyWillBeUsedPlugins) {
effectiveRequest = await plugin[pluginEvents.CACHE_KEY_WILL_BE_USED].call(plugin, {
mode,
request: effectiveRequest
});
if (typeof effectiveRequest === 'string') {
effectiveRequest = new Request(effectiveRequest);
}
{
finalAssertExports.isInstance(effectiveRequest, Request, {
moduleName: 'Plugin',
funcName: pluginEvents.CACHE_KEY_WILL_BE_USED,
isReturnValueProblem: true
});
}
}
return effectiveRequest;
};
const cacheWrapper = {

@@ -1467,3 +1531,3 @@ put: putWrapper,

/**
* Get the current cache names used by Workbox.
* Get the current cache names and prefix/suffix used by Workbox.
*

@@ -1474,5 +1538,8 @@ * `cacheNames.precache` is used for precached assets,

*
* @return {Object} An object with `precache`, `runtime`, and
* `googleAnalytics` cache names.
* `cacheNames.prefix` can be used to retrieve just the current prefix value.
* `cacheNames.suffix` can be used to retrieve just the current suffix value.
*
* @return {Object} An object with `precache`, `runtime`, `prefix`, and
* `googleAnalytics` properties.
*
* @alias workbox.core.cacheNames

@@ -1490,4 +1557,12 @@ */

get prefix() {
return cacheNames.getPrefix();
},
get runtime() {
return cacheNames.getRuntimeName();
},
get suffix() {
return cacheNames.getSuffix();
}

@@ -1494,0 +1569,0 @@

@@ -1,2 +0,2 @@

this.workbox=this.workbox||{},this.workbox.core=function(e){"use strict";try{self["workbox:core:4.1.1"]&&_()}catch(e){}const t=(e,...t)=>{let n=e;return t.length>0&&(n+=` :: ${JSON.stringify(t)}`),n};class n extends Error{constructor(e,n){super(t(e,n)),this.name=e,this.details=n}}const s=new Set;class r{constructor(e,t,{onupgradeneeded:n,onversionchange:s=this.t}={}){this.s=e,this.i=t,this.o=n,this.t=s,this.l=null}get db(){return this.l}async open(){if(!this.l)return this.l=await new Promise((e,t)=>{let n=!1;setTimeout(()=>{n=!0,t(new Error("The open request was blocked and timed out"))},this.OPEN_TIMEOUT);const s=indexedDB.open(this.s,this.i);s.onerror=(()=>t(s.error)),s.onupgradeneeded=(e=>{n?(s.transaction.abort(),e.target.result.close()):this.o&&this.o(e)}),s.onsuccess=(({target:t})=>{const s=t.result;n?s.close():(s.onversionchange=this.t.bind(this),e(s))})}),this}async getKey(e,t){return(await this.getAllKeys(e,t,1))[0]}async getAll(e,t,n){return await this.getAllMatching(e,{query:t,count:n})}async getAllKeys(e,t,n){return(await this.getAllMatching(e,{query:t,count:n,includeKeys:!0})).map(({key:e})=>e)}async getAllMatching(e,{index:t,query:n=null,direction:s="next",count:r,includeKeys:a}={}){return await this.transaction([e],"readonly",(i,c)=>{const o=i.objectStore(e),l=t?o.index(t):o,u=[];l.openCursor(n,s).onsuccess=(({target:e})=>{const t=e.result;if(t){const{primaryKey:e,key:n,value:s}=t;u.push(a?{primaryKey:e,key:n,value:s}:s),r&&u.length>=r?c(u):t.continue()}else c(u)})})}async transaction(e,t,n){return await this.open(),await new Promise((s,r)=>{const a=this.l.transaction(e,t);a.onabort=(({target:e})=>r(e.error)),a.oncomplete=(()=>s()),n(a,e=>s(e))})}async u(e,t,n,...s){return await this.transaction([t],n,(n,r)=>{n.objectStore(t)[e](...s).onsuccess=(({target:e})=>{r(e.result)})})}t(){this.close()}close(){this.l&&(this.l.close(),this.l=null)}}r.prototype.OPEN_TIMEOUT=2e3;const a={readonly:["get","count","getKey","getAll","getAllKeys"],readwrite:["add","put","clear","delete"]};for(const[e,t]of Object.entries(a))for(const n of t)n in IDBObjectStore.prototype&&(r.prototype[n]=async function(t,...s){return await this.u(n,t,e,...s)});const i={googleAnalytics:"googleAnalytics",precache:"precache-v2",prefix:"workbox",runtime:"runtime",suffix:self.registration.scope},c=e=>[i.prefix,e,i.suffix].filter(e=>e.length>0).join("-"),o={updateDetails:e=>{Object.keys(i).forEach(t=>{void 0!==e[t]&&(i[t]=e[t])})},getGoogleAnalyticsName:e=>e||c(i.googleAnalytics),getPrecacheName:e=>e||c(i.precache),getRuntimeName:e=>e||c(i.runtime)},l="cacheDidUpdate",u="cacheWillUpdate",h="cachedResponseWillBeUsed",w="fetchDidFail",f="fetchDidSucceed",p="requestWillFetch",d=(e,t)=>e.filter(e=>t in e),g=e=>{const t=new URL(e,location);return t.origin===location.origin?t.pathname:t.href},y=async({cacheName:e,request:t,event:n,matchOptions:s,plugins:r=[]})=>{const a=await caches.open(e);let i=await a.match(t,s);for(const a of r)h in a&&(i=await a[h].call(a,{cacheName:e,request:t,event:n,matchOptions:s,cachedResponse:i}));return i},m=async({request:e,response:t,event:n,plugins:s})=>{let r=t,a=!1;for(let t of s)if(u in t&&(a=!0,!(r=await t[u].call(t,{request:e,response:r,event:n}))))break;return a||(r=200===r.status?r:null),r||null},v={put:async({cacheName:e,request:t,response:r,event:a,plugins:i=[],matchOptions:c}={})=>{if(!r)throw new n("cache-put-with-no-response",{url:g(t.url)});let o=await m({request:t,response:r,event:a,plugins:i});if(!o)return;const u=await caches.open(e),h=d(i,l);let w=h.length>0?await y({cacheName:e,request:t,matchOptions:c}):null;try{await u.put(t,o)}catch(e){throw"QuotaExceededError"===e.name&&await async function(){for(const e of s)await e()}(),e}for(let n of h)await n[l].call(n,{cacheName:e,request:t,event:a,oldResponse:w,newResponse:o})},match:y},q={fetch:async({request:e,fetchOptions:t,event:s,plugins:r=[]})=>{if(s&&s.preloadResponse){const e=await s.preloadResponse;if(e)return e}"string"==typeof e&&(e=new Request(e));const a=d(r,w),i=a.length>0?e.clone():null;try{for(let t of r)p in t&&(e=await t[p].call(t,{request:e.clone(),event:s}))}catch(e){throw new n("plugin-error-request-will-fetch",{thrownError:e})}let c=e.clone();try{let n;n="navigate"===e.mode?await fetch(e):await fetch(e,t);for(const e of r)f in e&&(n=await e[f].call(e,{event:s,request:c,response:n}));return n}catch(e){for(const t of a)await t[w].call(t,{error:e,event:s,originalRequest:i.clone(),request:c.clone()});throw e}}};var b=Object.freeze({DBWrapper:r,deleteDatabase:async e=>{await new Promise((t,n)=>{const s=indexedDB.deleteDatabase(e);s.onerror=(({target:e})=>{n(e.error)}),s.onblocked=(()=>{n(new Error("Delete blocked"))}),s.onsuccess=(()=>{t()})})},WorkboxError:n,assert:null,cacheNames:o,cacheWrapper:v,fetchWrapper:q,getFriendlyURL:g,logger:null});const x={get googleAnalytics(){return o.getGoogleAnalyticsName()},get precache(){return o.getPrecacheName()},get runtime(){return o.getRuntimeName()}};try{self.workbox.v=self.workbox.v||{}}catch(e){}return e._private=b,e.clientsClaim=(()=>{addEventListener("activate",()=>clients.claim())}),e.cacheNames=x,e.registerQuotaErrorCallback=function(e){s.add(e)},e.setCacheNameDetails=(e=>{o.updateDetails(e)}),e.skipWaiting=(()=>{addEventListener("install",()=>self.skipWaiting())}),e}({});
this.workbox=this.workbox||{},this.workbox.core=function(e){"use strict";try{self["workbox:core:4.2.0"]&&_()}catch(e){}const t=(e,...t)=>{let n=e;return t.length>0&&(n+=` :: ${JSON.stringify(t)}`),n};class n extends Error{constructor(e,n){super(t(e,n)),this.name=e,this.details=n}}const s=new Set;class r{constructor(e,t,{onupgradeneeded:n,onversionchange:s=this.t}={}){this.s=e,this.i=t,this.o=n,this.t=s,this.l=null}get db(){return this.l}async open(){if(!this.l)return this.l=await new Promise((e,t)=>{let n=!1;setTimeout(()=>{n=!0,t(new Error("The open request was blocked and timed out"))},this.OPEN_TIMEOUT);const s=indexedDB.open(this.s,this.i);s.onerror=(()=>t(s.error)),s.onupgradeneeded=(e=>{n?(s.transaction.abort(),e.target.result.close()):this.o&&this.o(e)}),s.onsuccess=(({target:t})=>{const s=t.result;n?s.close():(s.onversionchange=this.t.bind(this),e(s))})}),this}async getKey(e,t){return(await this.getAllKeys(e,t,1))[0]}async getAll(e,t,n){return await this.getAllMatching(e,{query:t,count:n})}async getAllKeys(e,t,n){return(await this.getAllMatching(e,{query:t,count:n,includeKeys:!0})).map(({key:e})=>e)}async getAllMatching(e,{index:t,query:n=null,direction:s="next",count:r,includeKeys:a}={}){return await this.transaction([e],"readonly",(i,c)=>{const o=i.objectStore(e),l=t?o.index(t):o,u=[];l.openCursor(n,s).onsuccess=(({target:e})=>{const t=e.result;if(t){const{primaryKey:e,key:n,value:s}=t;u.push(a?{primaryKey:e,key:n,value:s}:s),r&&u.length>=r?c(u):t.continue()}else c(u)})})}async transaction(e,t,n){return await this.open(),await new Promise((s,r)=>{const a=this.l.transaction(e,t);a.onabort=(({target:e})=>r(e.error)),a.oncomplete=(()=>s()),n(a,e=>s(e))})}async u(e,t,n,...s){return await this.transaction([t],n,(n,r)=>{n.objectStore(t)[e](...s).onsuccess=(({target:e})=>{r(e.result)})})}t(){this.close()}close(){this.l&&(this.l.close(),this.l=null)}}r.prototype.OPEN_TIMEOUT=2e3;const a={readonly:["get","count","getKey","getAll","getAllKeys"],readwrite:["add","put","clear","delete"]};for(const[e,t]of Object.entries(a))for(const n of t)n in IDBObjectStore.prototype&&(r.prototype[n]=async function(t,...s){return await this.u(n,t,e,...s)});const i={googleAnalytics:"googleAnalytics",precache:"precache-v2",prefix:"workbox",runtime:"runtime",suffix:self.registration.scope},c=e=>[i.prefix,e,i.suffix].filter(e=>e.length>0).join("-"),o={updateDetails:e=>{Object.keys(i).forEach(t=>{void 0!==e[t]&&(i[t]=e[t])})},getGoogleAnalyticsName:e=>e||c(i.googleAnalytics),getPrecacheName:e=>e||c(i.precache),getPrefix:()=>i.prefix,getRuntimeName:e=>e||c(i.runtime),getSuffix:()=>i.suffix},l="cacheDidUpdate",u="cacheKeyWillBeUsed",h="cacheWillUpdate",f="cachedResponseWillBeUsed",w="fetchDidFail",g="fetchDidSucceed",d="requestWillFetch",p=(e,t)=>e.filter(e=>t in e),y=e=>{const t=new URL(e,location);return t.origin===location.origin?t.pathname:t.href},m=async({cacheName:e,request:t,event:n,matchOptions:s,plugins:r=[]})=>{const a=await caches.open(e),i=await v({plugins:r,request:t,mode:"read"});let c=await a.match(i,s);for(const t of r)f in t&&(c=await t[f].call(t,{cacheName:e,event:n,matchOptions:s,cachedResponse:c,request:i}));return c},q=async({request:e,response:t,event:n,plugins:s})=>{let r=t,a=!1;for(let t of s)if(h in t&&(a=!0,!(r=await t[h].call(t,{request:e,response:r,event:n}))))break;return a||(r=200===r.status?r:null),r||null},v=async({request:e,mode:t,plugins:n})=>{const s=p(n,u);let r=e;for(const e of s)"string"==typeof(r=await e[u].call(e,{mode:t,request:r}))&&(r=new Request(r));return r},x={put:async({cacheName:e,request:t,response:r,event:a,plugins:i=[],matchOptions:c}={})=>{const o=await v({plugins:i,request:t,mode:"write"});if(!r)throw new n("cache-put-with-no-response",{url:y(o.url)});let u=await q({event:a,plugins:i,response:r,request:o});if(!u)return;const h=await caches.open(e),f=p(i,l);let w=f.length>0?await m({cacheName:e,matchOptions:c,request:o}):null;try{await h.put(o,u)}catch(e){throw"QuotaExceededError"===e.name&&await async function(){for(const e of s)await e()}(),e}for(let t of f)await t[l].call(t,{cacheName:e,event:a,oldResponse:w,newResponse:u,request:o})},match:m},b={fetch:async({request:e,fetchOptions:t,event:s,plugins:r=[]})=>{if(s&&s.preloadResponse){const e=await s.preloadResponse;if(e)return e}"string"==typeof e&&(e=new Request(e));const a=p(r,w),i=a.length>0?e.clone():null;try{for(let t of r)d in t&&(e=await t[d].call(t,{request:e.clone(),event:s}))}catch(e){throw new n("plugin-error-request-will-fetch",{thrownError:e})}let c=e.clone();try{let n;n="navigate"===e.mode?await fetch(e):await fetch(e,t);for(const e of r)g in e&&(n=await e[g].call(e,{event:s,request:c,response:n}));return n}catch(e){for(const t of a)await t[w].call(t,{error:e,event:s,originalRequest:i.clone(),request:c.clone()});throw e}}};var D=Object.freeze({DBWrapper:r,deleteDatabase:async e=>{await new Promise((t,n)=>{const s=indexedDB.deleteDatabase(e);s.onerror=(({target:e})=>{n(e.error)}),s.onblocked=(()=>{n(new Error("Delete blocked"))}),s.onsuccess=(()=>{t()})})},WorkboxError:n,assert:null,cacheNames:o,cacheWrapper:x,fetchWrapper:b,getFriendlyURL:y,logger:null});const N={get googleAnalytics(){return o.getGoogleAnalyticsName()},get precache(){return o.getPrecacheName()},get prefix(){return o.getPrefix()},get runtime(){return o.getRuntimeName()},get suffix(){return o.getSuffix()}};try{self.workbox.v=self.workbox.v||{}}catch(e){}return e._private=D,e.clientsClaim=(()=>{addEventListener("activate",()=>clients.claim())}),e.cacheNames=N,e.registerQuotaErrorCallback=function(e){s.add(e)},e.setCacheNameDetails=(e=>{o.updateDetails(e)}),e.skipWaiting=(()=>{addEventListener("install",()=>self.skipWaiting())}),e}({});
//# sourceMappingURL=workbox-core.prod.js.map
{
"name": "workbox-core",
"version": "4.1.1",
"version": "4.2.0",
"license": "MIT",

@@ -27,3 +27,3 @@ "author": "Google's Web DevRel Team",

"module": "index.mjs",
"gitHead": "fb837ca0bd15bdc8f4e5563ee28957dc266c31f6"
"gitHead": "60f99c8c017b62ffe90b591b7f4be37dc44d92f6"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc