New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@serwist/sw

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@serwist/sw - npm Package Compare versions

Comparing version 9.0.0-preview.16 to 9.0.0-preview.17

dist/Serwist.d.ts

11

dist/handlePrecaching.d.ts
import type { PrecacheEntry, PrecacheRouteOptions } from "@serwist/precaching";
export type HandlePrecachingOptions = {
export interface HandlePrecachingOptions {
/**

@@ -17,3 +17,2 @@ * A list of fallback entries.

cleanupOutdatedCaches?: boolean;
} & ({
/**

@@ -23,3 +22,3 @@ * An URL that should point to a HTML file with which navigation requests for URLs that aren't

*/
navigateFallback: string;
navigateFallback?: string;
/**

@@ -34,9 +33,7 @@ * URLs that should be allowed to use the `navigateFallback` handler.

navigateFallbackDenylist?: RegExp[];
} | {
navigateFallback?: never;
});
}
/**
* Handles a list of precache entries and cleans up outdated caches.
*
* @see https://serwist.pages.dev/docs/sw/handlePrecaching
* @see https://serwist.pages.dev/docs/sw/handle-precaching
* @param options

@@ -43,0 +40,0 @@ */

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

import { Serwist, type SerwistOptions, type SerwistInstallOptions } from "./Serwist.js";
import { disableDevLogs } from "./disableDevLogs.js";

@@ -8,4 +9,4 @@ import type { FallbackEntry, FallbackMatcher, FallbacksOptions } from "./fallbacks.js";

import type { RuntimeCaching } from "./types.js";
export { disableDevLogs, fallbacks, handlePrecaching, installSerwist, registerRuntimeCaching };
export type { FallbackEntry, FallbackMatcher, FallbacksOptions, HandlePrecachingOptions, InstallSerwistOptions as SerwistOptions, RuntimeCaching };
export { disableDevLogs, fallbacks, handlePrecaching, installSerwist, Serwist, registerRuntimeCaching };
export type { FallbackEntry, FallbackMatcher, FallbacksOptions, HandlePrecachingOptions, InstallSerwistOptions, SerwistOptions, SerwistInstallOptions, RuntimeCaching, };
//# sourceMappingURL=index.d.ts.map

@@ -1,7 +0,10 @@

import { precacheAndRoute, PrecacheFallbackPlugin, cleanupOutdatedCaches, createHandlerBoundToURL } from '@serwist/precaching';
import { Strategy } from '@serwist/strategies';
import { registerRoute, NavigationRoute } from '@serwist/routing';
import { setCacheNameDetails, clientsClaim } from '@serwist/core';
import { initialize } from '@serwist/google-analytics/initialize';
import { enable } from '@serwist/navigation-preload';
import { precacheAndRoute, PrecacheFallbackPlugin, PrecacheController, PrecacheRoute, cleanupOutdatedCaches, createHandlerBoundToURL } from '@serwist/precaching';
import { Router, NavigationRoute, registerRoute } from '@serwist/routing';
import { parseRoute, getOrCreateDefaultRouter } from '@serwist/routing/internal';
import { Strategy } from '@serwist/strategies';
import { logger } from '@serwist/core/internal';
import { getOrCreatePrecacheController } from '@serwist/precaching/internal';

@@ -26,2 +29,60 @@ const disableDevLogs = ()=>{

class Serwist {
_precacheController;
_router;
constructor({ precacheController = new PrecacheController(), router = new Router() } = {}){
this._precacheController = precacheController;
this._router = router;
}
install({ precacheEntries, precacheOptions, cleanupOutdatedCaches: cleanupOutdatedCaches$1, navigateFallback, navigateFallbackAllowlist, navigateFallbackDenylist, skipWaiting = false, importScripts, navigationPreload = false, cacheId, clientsClaim: clientsClaim$1 = false, runtimeCaching, offlineAnalyticsConfig, disableDevLogs: disableDevLogs$1 = false, fallbacks: fallbacks$1 }) {
if (!!importScripts && importScripts.length > 0) self.importScripts(...importScripts);
if (navigationPreload) enable();
if (cacheId !== undefined) {
setCacheNameDetails({
prefix: cacheId
});
}
if (skipWaiting) {
self.skipWaiting();
} else {
self.addEventListener("message", (event)=>{
if (event.data && event.data.type === "SKIP_WAITING") {
self.skipWaiting();
}
});
}
if (clientsClaim$1) clientsClaim();
if (!!precacheEntries && precacheEntries.length > 0) {
this._precacheController.precache(precacheEntries);
this._router.registerRoute(new PrecacheRoute(this._precacheController, precacheOptions));
if (cleanupOutdatedCaches$1) cleanupOutdatedCaches();
if (navigateFallback) {
this._router.registerRoute(new NavigationRoute(createHandlerBoundToURL(navigateFallback), {
allowlist: navigateFallbackAllowlist,
denylist: navigateFallbackDenylist
}));
}
}
if (offlineAnalyticsConfig !== undefined) {
if (typeof offlineAnalyticsConfig === "boolean") {
offlineAnalyticsConfig && initialize();
} else {
initialize(offlineAnalyticsConfig);
}
}
if (runtimeCaching !== undefined) {
if (fallbacks$1 !== undefined) {
fallbacks({
...fallbacks$1,
runtimeCaching
});
}
for (const entry of runtimeCaching){
this._router.registerRoute(parseRoute(entry.matcher, entry.handler, entry.method));
}
}
if (disableDevLogs$1) disableDevLogs();
}
}
const handlePrecaching = ({ precacheEntries, precacheOptions, cleanupOutdatedCaches: cleanupOutdatedCaches$1 = false, ...options })=>{

@@ -40,2 +101,13 @@ if (!!precacheEntries && precacheEntries.length > 0) {

const installSerwist = (options)=>{
if (process.env.NODE_ENV !== "production") {
logger.warn("'installSerwist' has been deprecated. Please migrate to 'new Serwist().install()'.");
}
const serwist = new Serwist({
precacheController: getOrCreatePrecacheController(),
router: getOrCreateDefaultRouter()
});
serwist.install(options);
};
const registerRuntimeCaching = (...runtimeCachingList)=>{

@@ -47,49 +119,2 @@ for (const entry of runtimeCachingList){

const installSerwist = ({ precacheEntries, precacheOptions, cleanupOutdatedCaches, skipWaiting = false, importScripts, navigationPreload = false, cacheId, clientsClaim: clientsClaim$1 = false, runtimeCaching, offlineAnalyticsConfig, disableDevLogs: disableDevLogs$1 = false, fallbacks: fallbacks$1, ...options })=>{
if (!!importScripts && importScripts.length > 0) self.importScripts(...importScripts);
if (navigationPreload) enable();
if (cacheId !== undefined) {
setCacheNameDetails({
prefix: cacheId
});
}
if (skipWaiting) {
self.skipWaiting();
} else {
self.addEventListener("message", (event)=>{
if (event.data && event.data.type === "SKIP_WAITING") {
self.skipWaiting();
}
});
}
if (clientsClaim$1) clientsClaim();
handlePrecaching({
precacheEntries,
precacheOptions,
cleanupOutdatedCaches,
...options.navigateFallback && {
navigateFallback: options.navigateFallback,
navigateFallbackAllowlist: options.navigateFallbackAllowlist,
navigateFallbackDenylist: options.navigateFallbackDenylist
}
});
if (offlineAnalyticsConfig !== undefined) {
if (typeof offlineAnalyticsConfig === "boolean") {
offlineAnalyticsConfig && initialize();
} else {
initialize(offlineAnalyticsConfig);
}
}
if (runtimeCaching !== undefined) {
if (fallbacks$1 !== undefined) {
fallbacks({
...fallbacks$1,
runtimeCaching
});
}
registerRuntimeCaching(...runtimeCaching);
}
if (disableDevLogs$1) disableDevLogs();
};
export { disableDevLogs, fallbacks, handlePrecaching, installSerwist, registerRuntimeCaching };
export { Serwist, disableDevLogs, fallbacks, handlePrecaching, installSerwist, registerRuntimeCaching };

@@ -1,68 +0,15 @@

import { type GoogleAnalyticsInitializeOptions } from "@serwist/google-analytics/initialize";
import type { FallbacksOptions } from "./fallbacks.js";
import { type HandlePrecachingOptions } from "./handlePrecaching.js";
import type { RuntimeCaching } from "./types.js";
export type InstallSerwistOptions = HandlePrecachingOptions & {
/**
* Forces the waiting service worker to become the active one.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/skipWaiting
*/
skipWaiting?: boolean;
/**
* Imports external scripts. They are executed in the order they
* are passed.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts
*/
importScripts?: string[];
/**
* Enables navigation preloading if it is supported.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/navigationPreload
*/
navigationPreload?: boolean;
/**
* Modifies the prefix of the default cache names used by Serwist packages.
*/
cacheId?: string | undefined;
/**
* Claims any currently available clients once the service worker
* becomes active. This is normally used in conjunction with `skipWaiting()`.
*
* @default false
*/
clientsClaim?: boolean;
/**
* A list of caching strategies.
*
* @see https://serwist.pages.dev/docs/sw/register-runtime-caching
*/
runtimeCaching?: RuntimeCaching[];
/**
* Your configuration for `@serwist/google-analytics`. This plugin is
* only initialized when this option is not `undefined` or `false`.
*/
offlineAnalyticsConfig?: GoogleAnalyticsInitializeOptions | boolean;
/**
* Disables Serwist's logging in development mode.
*
* @default false
* @see https://serwist.pages.dev/docs/sw/disable-dev-logs
*/
disableDevLogs?: boolean;
/**
* Precaches routes so that they can be used as a fallback when
* a Strategy fails to generate a response.
* Note: This option mutates `runtimeCaching`!
*
* @see https://serwist.pages.dev/docs/sw/fallbacks
*/
fallbacks?: Omit<FallbacksOptions, "runtimeCaching">;
};
import { type SerwistInstallOptions } from "./Serwist.js";
/**
* Options for `installSerwist`.
*
* @deprecated
*/
export type InstallSerwistOptions = SerwistInstallOptions;
/**
* Abstracts away the core APIs of Serwist.
*
* @param options - `installSerwist` options.
* @deprecated
*/
export declare const installSerwist: ({ precacheEntries, precacheOptions, cleanupOutdatedCaches, skipWaiting, importScripts, navigationPreload, cacheId, clientsClaim, runtimeCaching, offlineAnalyticsConfig, disableDevLogs, fallbacks, ...options }: InstallSerwistOptions) => void;
export declare const installSerwist: (options: InstallSerwistOptions) => void;
//# sourceMappingURL=installSerwist.d.ts.map

@@ -6,3 +6,3 @@ import type { RuntimeCaching } from "./types.js";

*
* @see https://serwist.pages.dev/docs/sw/registerRuntimeCaching
* @see https://serwist.pages.dev/docs/sw/register-runtime-caching
* @param runtimeCachingList

@@ -9,0 +9,0 @@ * @returns

{
"name": "@serwist/sw",
"version": "9.0.0-preview.16",
"version": "9.0.0-preview.17",
"type": "module",

@@ -49,13 +49,13 @@ "description": "A module that makes it easy to get started with the Serwist service worker libraries.",

"dependencies": {
"@serwist/background-sync": "9.0.0-preview.16",
"@serwist/broadcast-update": "9.0.0-preview.16",
"@serwist/cacheable-response": "9.0.0-preview.16",
"@serwist/core": "9.0.0-preview.16",
"@serwist/expiration": "9.0.0-preview.16",
"@serwist/google-analytics": "9.0.0-preview.16",
"@serwist/navigation-preload": "9.0.0-preview.16",
"@serwist/precaching": "9.0.0-preview.16",
"@serwist/range-requests": "9.0.0-preview.16",
"@serwist/routing": "9.0.0-preview.16",
"@serwist/strategies": "9.0.0-preview.16"
"@serwist/background-sync": "9.0.0-preview.17",
"@serwist/broadcast-update": "9.0.0-preview.17",
"@serwist/cacheable-response": "9.0.0-preview.17",
"@serwist/core": "9.0.0-preview.17",
"@serwist/expiration": "9.0.0-preview.17",
"@serwist/google-analytics": "9.0.0-preview.17",
"@serwist/navigation-preload": "9.0.0-preview.17",
"@serwist/precaching": "9.0.0-preview.17",
"@serwist/range-requests": "9.0.0-preview.17",
"@serwist/routing": "9.0.0-preview.17",
"@serwist/strategies": "9.0.0-preview.17"
},

@@ -65,4 +65,4 @@ "devDependencies": {

"typescript": "5.5.0-dev.20240323",
"@serwist/constants": "9.0.0-preview.16",
"@serwist/utils": "9.0.0-preview.16"
"@serwist/constants": "9.0.0-preview.17",
"@serwist/utils": "9.0.0-preview.17"
},

@@ -69,0 +69,0 @@ "peerDependencies": {

@@ -5,3 +5,3 @@ import type { PrecacheEntry, PrecacheRouteOptions } from "@serwist/precaching";

export type HandlePrecachingOptions = {
export interface HandlePrecachingOptions {
/**

@@ -21,21 +21,17 @@ * A list of fallback entries.

cleanupOutdatedCaches?: boolean;
} & (
| {
/**
* An URL that should point to a HTML file with which navigation requests for URLs that aren't
* precached will be fulfilled.
*/
navigateFallback: string;
/**
* URLs that should be allowed to use the `navigateFallback` handler.
*/
navigateFallbackAllowlist?: RegExp[];
/**
* URLs that should not be allowed to use the `navigateFallback` handler. This takes precedence
* over `navigateFallbackAllowlist`.
*/
navigateFallbackDenylist?: RegExp[];
}
| { navigateFallback?: never }
);
/**
* An URL that should point to a HTML file with which navigation requests for URLs that aren't
* precached will be fulfilled.
*/
navigateFallback?: string;
/**
* URLs that should be allowed to use the `navigateFallback` handler.
*/
navigateFallbackAllowlist?: RegExp[];
/**
* URLs that should not be allowed to use the `navigateFallback` handler. This takes precedence
* over `navigateFallbackAllowlist`.
*/
navigateFallbackDenylist?: RegExp[];
}

@@ -45,3 +41,3 @@ /**

*
* @see https://serwist.pages.dev/docs/sw/handlePrecaching
* @see https://serwist.pages.dev/docs/sw/handle-precaching
* @param options

@@ -48,0 +44,0 @@ */

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

import { Serwist, type SerwistOptions, type SerwistInstallOptions } from "./Serwist.js";
import { disableDevLogs } from "./disableDevLogs.js";

@@ -9,3 +10,12 @@ import type { FallbackEntry, FallbackMatcher, FallbacksOptions } from "./fallbacks.js";

export { disableDevLogs, fallbacks, handlePrecaching, installSerwist, registerRuntimeCaching };
export type { FallbackEntry, FallbackMatcher, FallbacksOptions, HandlePrecachingOptions, InstallSerwistOptions as SerwistOptions, RuntimeCaching };
export { disableDevLogs, fallbacks, handlePrecaching, installSerwist, Serwist, registerRuntimeCaching };
export type {
FallbackEntry,
FallbackMatcher,
FallbacksOptions,
HandlePrecachingOptions,
InstallSerwistOptions,
SerwistOptions,
SerwistInstallOptions,
RuntimeCaching,
};

@@ -1,142 +0,28 @@

import { clientsClaim as clientsClaimImpl, setCacheNameDetails } from "@serwist/core";
import { type GoogleAnalyticsInitializeOptions, initialize } from "@serwist/google-analytics/initialize";
import { enable } from "@serwist/navigation-preload";
import { logger } from "@serwist/core/internal";
import { getOrCreatePrecacheController } from "@serwist/precaching/internal";
import { getOrCreateDefaultRouter } from "@serwist/routing/internal";
import { Serwist, type SerwistInstallOptions } from "./Serwist.js";
import { disableDevLogs as disableDevLogsImpl } from "./disableDevLogs.js";
import { fallbacks as fallbacksImpl } from "./fallbacks.js";
import type { FallbacksOptions } from "./fallbacks.js";
import { type HandlePrecachingOptions, handlePrecaching } from "./handlePrecaching.js";
import { registerRuntimeCaching } from "./registerRuntimeCaching.js";
import type { RuntimeCaching } from "./types.js";
/**
* Options for `installSerwist`.
*
* @deprecated
*/
export type InstallSerwistOptions = SerwistInstallOptions;
declare const self: ServiceWorkerGlobalScope;
export type InstallSerwistOptions = HandlePrecachingOptions & {
/**
* Forces the waiting service worker to become the active one.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/skipWaiting
*/
skipWaiting?: boolean;
/**
* Imports external scripts. They are executed in the order they
* are passed.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts
*/
importScripts?: string[];
/**
* Enables navigation preloading if it is supported.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/navigationPreload
*/
navigationPreload?: boolean;
/**
* Modifies the prefix of the default cache names used by Serwist packages.
*/
cacheId?: string | undefined;
/**
* Claims any currently available clients once the service worker
* becomes active. This is normally used in conjunction with `skipWaiting()`.
*
* @default false
*/
clientsClaim?: boolean;
/**
* A list of caching strategies.
*
* @see https://serwist.pages.dev/docs/sw/register-runtime-caching
*/
runtimeCaching?: RuntimeCaching[];
/**
* Your configuration for `@serwist/google-analytics`. This plugin is
* only initialized when this option is not `undefined` or `false`.
*/
offlineAnalyticsConfig?: GoogleAnalyticsInitializeOptions | boolean;
/**
* Disables Serwist's logging in development mode.
*
* @default false
* @see https://serwist.pages.dev/docs/sw/disable-dev-logs
*/
disableDevLogs?: boolean;
/**
* Precaches routes so that they can be used as a fallback when
* a Strategy fails to generate a response.
* Note: This option mutates `runtimeCaching`!
*
* @see https://serwist.pages.dev/docs/sw/fallbacks
*/
fallbacks?: Omit<FallbacksOptions, "runtimeCaching">;
};
/**
* Abstracts away the core APIs of Serwist.
*
* @param options - `installSerwist` options.
* @deprecated
*/
export const installSerwist = ({
precacheEntries,
precacheOptions,
cleanupOutdatedCaches,
skipWaiting = false,
importScripts,
navigationPreload = false,
cacheId,
clientsClaim = false,
runtimeCaching,
offlineAnalyticsConfig,
disableDevLogs = false,
fallbacks,
...options
}: InstallSerwistOptions): void => {
if (!!importScripts && importScripts.length > 0) self.importScripts(...importScripts);
if (navigationPreload) enable();
if (cacheId !== undefined) {
setCacheNameDetails({
prefix: cacheId,
});
export const installSerwist = (options: InstallSerwistOptions): void => {
if (process.env.NODE_ENV !== "production") {
logger.warn("'installSerwist' has been deprecated. Please migrate to 'new Serwist().install()'.");
}
if (skipWaiting) {
self.skipWaiting();
} else {
self.addEventListener("message", (event) => {
if (event.data && event.data.type === "SKIP_WAITING") {
self.skipWaiting();
}
});
}
if (clientsClaim) clientsClaimImpl();
handlePrecaching({
precacheEntries,
precacheOptions,
cleanupOutdatedCaches,
...(options.navigateFallback && {
navigateFallback: options.navigateFallback,
navigateFallbackAllowlist: options.navigateFallbackAllowlist,
navigateFallbackDenylist: options.navigateFallbackDenylist,
}),
const serwist = new Serwist({
precacheController: getOrCreatePrecacheController(),
router: getOrCreateDefaultRouter(),
});
if (offlineAnalyticsConfig !== undefined) {
if (typeof offlineAnalyticsConfig === "boolean") {
offlineAnalyticsConfig && initialize();
} else {
initialize(offlineAnalyticsConfig);
}
}
if (runtimeCaching !== undefined) {
if (fallbacks !== undefined) {
fallbacksImpl({ ...fallbacks, runtimeCaching });
}
registerRuntimeCaching(...runtimeCaching);
}
if (disableDevLogs) disableDevLogsImpl();
serwist.install(options);
};

@@ -9,3 +9,3 @@ import { registerRoute } from "@serwist/routing";

*
* @see https://serwist.pages.dev/docs/sw/registerRuntimeCaching
* @see https://serwist.pages.dev/docs/sw/register-runtime-caching
* @param runtimeCachingList

@@ -12,0 +12,0 @@ * @returns

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