@serwist/core 8.4.3 → 9.0.0-preview.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_private/Deferred.d.ts +1 -0
- package/dist/_private/Deferred.d.ts.map +1 -0
- package/dist/_private/SerwistError.d.ts +1 -0
- package/dist/_private/SerwistError.d.ts.map +1 -0
- package/dist/_private/assert.d.ts +1 -0
- package/dist/_private/assert.d.ts.map +1 -0
- package/dist/_private/cacheMatchIgnoreParams.d.ts +1 -0
- package/dist/_private/cacheMatchIgnoreParams.d.ts.map +1 -0
- package/dist/_private/cacheNames.d.ts +1 -0
- package/dist/_private/cacheNames.d.ts.map +1 -0
- package/dist/_private/canConstructReadableStream.d.ts +1 -0
- package/dist/_private/canConstructReadableStream.d.ts.map +1 -0
- package/dist/_private/canConstructResponseFromBodyStream.d.ts +1 -0
- package/dist/_private/canConstructResponseFromBodyStream.d.ts.map +1 -0
- package/dist/_private/dontWaitFor.d.ts +1 -0
- package/dist/_private/dontWaitFor.d.ts.map +1 -0
- package/dist/_private/executeQuotaErrorCallbacks.d.ts +1 -0
- package/dist/_private/executeQuotaErrorCallbacks.d.ts.map +1 -0
- package/dist/_private/getFriendlyURL.d.ts +1 -0
- package/dist/_private/getFriendlyURL.d.ts.map +1 -0
- package/dist/_private/logger.d.ts +1 -0
- package/dist/_private/logger.d.ts.map +1 -0
- package/dist/_private/resultingClientExists.d.ts +1 -0
- package/dist/_private/resultingClientExists.d.ts.map +1 -0
- package/dist/_private/timeout.d.ts +1 -0
- package/dist/_private/timeout.d.ts.map +1 -0
- package/dist/_private/waitUntil.d.ts +1 -0
- package/dist/_private/waitUntil.d.ts.map +1 -0
- package/dist/cacheNames.d.ts +1 -0
- package/dist/cacheNames.d.ts.map +1 -0
- package/dist/clientsClaim.d.ts +1 -0
- package/dist/clientsClaim.d.ts.map +1 -0
- package/dist/copyResponse.d.ts +1 -0
- package/dist/copyResponse.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.internal.d.ts +1 -0
- package/dist/index.internal.d.ts.map +1 -0
- package/dist/index.internal.js +2 -2
- package/dist/index.js +1 -1
- package/dist/models/messages/messageGenerator.d.ts +1 -0
- package/dist/models/messages/messageGenerator.d.ts.map +1 -0
- package/dist/models/messages/messages.d.ts +1 -0
- package/dist/models/messages/messages.d.ts.map +1 -0
- package/dist/models/pluginEvents.d.ts +1 -0
- package/dist/models/pluginEvents.d.ts.map +1 -0
- package/dist/models/quotaErrorCallbacks.d.ts +1 -0
- package/dist/models/quotaErrorCallbacks.d.ts.map +1 -0
- package/dist/registerQuotaErrorCallback.d.ts +1 -0
- package/dist/registerQuotaErrorCallback.d.ts.map +1 -0
- package/dist/setCacheNameDetails.d.ts +1 -0
- package/dist/setCacheNameDetails.d.ts.map +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/pluginUtils.d.ts +1 -0
- package/dist/utils/pluginUtils.d.ts.map +1 -0
- package/dist/utils/welcome.d.ts +1 -0
- package/dist/utils/welcome.d.ts.map +1 -0
- package/package.json +18 -22
- package/src/_private/Deferred.ts +33 -0
- package/src/_private/SerwistError.ts +42 -0
- package/src/_private/assert.ts +89 -0
- package/src/_private/cacheMatchIgnoreParams.ts +54 -0
- package/src/_private/cacheNames.ts +87 -0
- package/src/_private/canConstructReadableStream.ts +34 -0
- package/src/_private/canConstructResponseFromBodyStream.ts +37 -0
- package/src/_private/dontWaitFor.ts +16 -0
- package/src/_private/executeQuotaErrorCallbacks.ts +35 -0
- package/src/_private/getFriendlyURL.ts +16 -0
- package/src/_private/logger.ts +92 -0
- package/src/_private/resultingClientExists.ts +58 -0
- package/src/_private/timeout.ts +19 -0
- package/src/_private/waitUntil.ts +23 -0
- package/src/cacheNames.ts +41 -0
- package/src/clientsClaim.ts +20 -0
- package/src/copyResponse.ts +62 -0
- package/src/index.internal.ts +33 -0
- package/{dist/index.d.cts → src/index.ts} +9 -0
- package/src/models/messages/messageGenerator.ts +28 -0
- package/src/models/messages/messages.ts +231 -0
- package/src/models/pluginEvents.ts +17 -0
- package/src/models/quotaErrorCallbacks.ts +13 -0
- package/src/registerQuotaErrorCallback.ts +36 -0
- package/src/setCacheNameDetails.ts +55 -0
- package/src/types.ts +315 -0
- package/src/utils/pluginUtils.ts +15 -0
- package/src/utils/welcome.ts +25 -0
- package/dist/_private/Deferred.d.cts +0 -18
- package/dist/_private/SerwistError.d.cts +0 -23
- package/dist/_private/assert.d.cts +0 -10
- package/dist/_private/cacheMatchIgnoreParams.d.cts +0 -14
- package/dist/_private/cacheNames.d.cts +0 -39
- package/dist/_private/canConstructReadableStream.d.cts +0 -11
- package/dist/_private/canConstructResponseFromBodyStream.d.cts +0 -10
- package/dist/_private/dontWaitFor.d.cts +0 -6
- package/dist/_private/executeQuotaErrorCallbacks.d.cts +0 -8
- package/dist/_private/getFriendlyURL.d.cts +0 -2
- package/dist/_private/logger.d.cts +0 -10
- package/dist/_private/resultingClientExists.d.cts +0 -11
- package/dist/_private/timeout.d.cts +0 -9
- package/dist/_private/waitUntil.d.cts +0 -0
- package/dist/cacheNames.d.cts +0 -20
- package/dist/clientsClaim.d.cts +0 -6
- package/dist/copyResponse.d.cts +0 -20
- package/dist/index.cjs +0 -153
- package/dist/index.internal.cjs +0 -243
- package/dist/index.internal.d.cts +0 -0
- package/dist/models/messages/messageGenerator.d.cts +0 -1
- package/dist/models/messages/messages.d.cts +0 -8
- package/dist/models/pluginEvents.d.cts +0 -9
- package/dist/models/quotaErrorCallbacks.d.cts +0 -2
- package/dist/quotaErrorCallbacks.cjs +0 -432
- package/dist/registerQuotaErrorCallback.d.cts +0 -0
- package/dist/setCacheNameDetails.d.cts +0 -0
- package/dist/types.d.cts +0 -272
- package/dist/utils/pluginUtils.d.cts +0 -4
- package/dist/utils/welcome.d.cts +0 -1
- /package/dist/{quotaErrorCallbacks.js → chunks/quotaErrorCallbacks.js} +0 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2019 Google LLC
|
|
3
|
+
|
|
4
|
+
Use of this source code is governed by an MIT-style
|
|
5
|
+
license that can be found in the LICENSE file or at
|
|
6
|
+
https://opensource.org/licenses/MIT.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { logger } from "../_private/logger.js";
|
|
10
|
+
|
|
11
|
+
// A SerwistCore instance must be exported before we can use the logger.
|
|
12
|
+
// This is so it can get the current log level.
|
|
13
|
+
if (process.env.NODE_ENV !== "production") {
|
|
14
|
+
const padding = " ";
|
|
15
|
+
logger.groupCollapsed("Welcome to Serwist!");
|
|
16
|
+
logger.log(
|
|
17
|
+
"You are currently using a development build. " +
|
|
18
|
+
"By default this will switch to prod builds when not on localhost. " +
|
|
19
|
+
"You can force this with serwist.setConfig({debug: true|false}).",
|
|
20
|
+
);
|
|
21
|
+
logger.log(`📖 Read the guides and documentation\n${padding}https://developers.google.com/web/tools/workbox/`);
|
|
22
|
+
logger.log(`❓ Use the Discussions tab on Github to ask questions\n${padding}https://github.com/serwist/serwist/discussions`);
|
|
23
|
+
logger.log(`🐛 Found a bug? Report it on GitHub\n${padding}https://github.com/serwist/serwist/issues/new`);
|
|
24
|
+
logger.groupEnd();
|
|
25
|
+
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The Deferred class composes Promises in a way that allows for them to be
|
|
3
|
-
* resolved or rejected from outside the constructor. In most cases promises
|
|
4
|
-
* should be used directly, but Deferreds can be necessary when the logic to
|
|
5
|
-
* resolve a promise must be separate.
|
|
6
|
-
*
|
|
7
|
-
* @private
|
|
8
|
-
*/
|
|
9
|
-
declare class Deferred<T> {
|
|
10
|
-
promise: Promise<T>;
|
|
11
|
-
resolve: (value: T) => void;
|
|
12
|
-
reject: (reason?: any) => void;
|
|
13
|
-
/**
|
|
14
|
-
* Creates a promise and exposes its resolve and reject functions as methods.
|
|
15
|
-
*/
|
|
16
|
-
constructor();
|
|
17
|
-
}
|
|
18
|
-
export { Deferred };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { MapLikeObject } from "../types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Serwist errors should be thrown with this class.
|
|
4
|
-
* This allows use to ensure the type easily in tests,
|
|
5
|
-
* helps developers identify errors from Serwist
|
|
6
|
-
* easily and allows use to optimise error
|
|
7
|
-
* messages correctly.
|
|
8
|
-
*
|
|
9
|
-
* @private
|
|
10
|
-
*/
|
|
11
|
-
declare class SerwistError extends Error {
|
|
12
|
-
details?: MapLikeObject;
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
* @param errorCode The error code that
|
|
16
|
-
* identifies this particular error.
|
|
17
|
-
* @param details Any relevant arguments
|
|
18
|
-
* that will help developers identify issues should
|
|
19
|
-
* be added as a key on the context object.
|
|
20
|
-
*/
|
|
21
|
-
constructor(errorCode: string, details?: MapLikeObject);
|
|
22
|
-
}
|
|
23
|
-
export { SerwistError };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { MapLikeObject } from "../types.js";
|
|
2
|
-
declare const finalAssertExports: {
|
|
3
|
-
hasMethod: (object: MapLikeObject, expectedMethod: string, details: MapLikeObject) => void;
|
|
4
|
-
isArray: (value: any[], details: MapLikeObject) => void;
|
|
5
|
-
isInstance: (object: unknown, expectedClass: Function, details: MapLikeObject) => void;
|
|
6
|
-
isOneOf: (value: any, validValues: any[], details: MapLikeObject) => void;
|
|
7
|
-
isType: (object: unknown, expectedType: string, details: MapLikeObject) => void;
|
|
8
|
-
isArrayOfClass: (value: any, expectedClass: Function, details: MapLikeObject) => void;
|
|
9
|
-
} | null;
|
|
10
|
-
export { finalAssertExports as assert };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Matches an item in the cache, ignoring specific URL params. This is similar
|
|
3
|
-
* to the `ignoreSearch` option, but it allows you to ignore just specific
|
|
4
|
-
* params (while continuing to match on the others).
|
|
5
|
-
*
|
|
6
|
-
* @private
|
|
7
|
-
* @param cache
|
|
8
|
-
* @param request
|
|
9
|
-
* @param matchOptions
|
|
10
|
-
* @param ignoreParams
|
|
11
|
-
* @returns
|
|
12
|
-
*/
|
|
13
|
-
declare function cacheMatchIgnoreParams(cache: Cache, request: Request, ignoreParams: string[], matchOptions?: CacheQueryOptions): Promise<Response | undefined>;
|
|
14
|
-
export { cacheMatchIgnoreParams };
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export interface CacheNameDetails {
|
|
2
|
-
googleAnalytics: string;
|
|
3
|
-
precache: string;
|
|
4
|
-
prefix: string;
|
|
5
|
-
runtime: string;
|
|
6
|
-
suffix: string;
|
|
7
|
-
}
|
|
8
|
-
export interface PartialCacheNameDetails {
|
|
9
|
-
/**
|
|
10
|
-
* The string to add to the beginning of the precache and runtime cache names.
|
|
11
|
-
*/
|
|
12
|
-
prefix?: string;
|
|
13
|
-
/**
|
|
14
|
-
* The string to add to the end of the precache and runtime cache names.
|
|
15
|
-
*/
|
|
16
|
-
suffix?: string;
|
|
17
|
-
/**
|
|
18
|
-
* The cache name to use for precache caching.
|
|
19
|
-
*/
|
|
20
|
-
precache?: string;
|
|
21
|
-
/**
|
|
22
|
-
* The cache name to use for runtime caching.
|
|
23
|
-
*/
|
|
24
|
-
runtime?: string;
|
|
25
|
-
/**
|
|
26
|
-
* The cache name to use for `@serwist/google-analytics` caching.
|
|
27
|
-
*/
|
|
28
|
-
googleAnalytics?: string;
|
|
29
|
-
[propName: string]: string | undefined;
|
|
30
|
-
}
|
|
31
|
-
export type CacheNameDetailsProp = "googleAnalytics" | "precache" | "prefix" | "runtime" | "suffix";
|
|
32
|
-
export declare const cacheNames: {
|
|
33
|
-
updateDetails: (details: PartialCacheNameDetails) => void;
|
|
34
|
-
getGoogleAnalyticsName: (userCacheName?: string) => string;
|
|
35
|
-
getPrecacheName: (userCacheName?: string) => string;
|
|
36
|
-
getPrefix: () => string;
|
|
37
|
-
getRuntimeName: (userCacheName?: string) => string;
|
|
38
|
-
getSuffix: () => string;
|
|
39
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A utility function that determines whether the current browser supports
|
|
3
|
-
* constructing a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/ReadableStream)
|
|
4
|
-
* object.
|
|
5
|
-
*
|
|
6
|
-
* @returns `true`, if the current browser can successfully construct a `ReadableStream`, `false` otherwise.
|
|
7
|
-
*
|
|
8
|
-
* @private
|
|
9
|
-
*/
|
|
10
|
-
declare function canConstructReadableStream(): boolean;
|
|
11
|
-
export { canConstructReadableStream };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A utility function that determines whether the current browser supports
|
|
3
|
-
* constructing a new `Response` from a `response.body` stream.
|
|
4
|
-
*
|
|
5
|
-
* @returns `true`, if the current browser can successfully construct
|
|
6
|
-
* a `Response` from a `response.body` stream, `false` otherwise.
|
|
7
|
-
* @private
|
|
8
|
-
*/
|
|
9
|
-
declare function canConstructResponseFromBodyStream(): boolean;
|
|
10
|
-
export { canConstructResponseFromBodyStream };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns a promise that resolves to a window client matching the passed
|
|
3
|
-
* `resultingClientId`. For browsers that don't support `resultingClientId`
|
|
4
|
-
* or if waiting for the resulting client to apper takes too long, resolve to
|
|
5
|
-
* `undefined`.
|
|
6
|
-
*
|
|
7
|
-
* @param resultingClientId
|
|
8
|
-
* @returns
|
|
9
|
-
* @private
|
|
10
|
-
*/
|
|
11
|
-
export declare function resultingClientExists(resultingClientId?: string): Promise<Client | undefined>;
|
|
File without changes
|
package/dist/cacheNames.d.cts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get the current cache names and prefix/suffix used by Workbox.
|
|
3
|
-
*
|
|
4
|
-
* `cacheNames.precache` is used for precached assets,
|
|
5
|
-
* `cacheNames.googleAnalytics` is used by `@serwist/google-analytics` to
|
|
6
|
-
* store `analytics.js`, and `cacheNames.runtime` is used for everything else.
|
|
7
|
-
*
|
|
8
|
-
* `cacheNames.prefix` can be used to retrieve just the current prefix value.
|
|
9
|
-
* `cacheNames.suffix` can be used to retrieve just the current suffix value.
|
|
10
|
-
*
|
|
11
|
-
* @returns An object with `precache`, `runtime`, `prefix`, and `googleAnalytics` properties.
|
|
12
|
-
*/
|
|
13
|
-
declare const cacheNames: {
|
|
14
|
-
readonly googleAnalytics: string;
|
|
15
|
-
readonly precache: string;
|
|
16
|
-
readonly prefix: string;
|
|
17
|
-
readonly runtime: string;
|
|
18
|
-
readonly suffix: string;
|
|
19
|
-
};
|
|
20
|
-
export { cacheNames };
|
package/dist/clientsClaim.d.cts
DELETED
package/dist/copyResponse.d.cts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Allows developers to copy a response and modify its `headers`, `status`,
|
|
3
|
-
* or `statusText` values (the values settable via a
|
|
4
|
-
* [`ResponseInit`](https://developer.mozilla.org/en-US/docs/Web/API/Response/Response#Syntax)
|
|
5
|
-
* object in the constructor).
|
|
6
|
-
* To modify these values, pass a function as the second argument. That
|
|
7
|
-
* function will be invoked with a single object with the response properties
|
|
8
|
-
* `{headers, status, statusText}`. The return value of this function will
|
|
9
|
-
* be used as the `ResponseInit` for the new `Response`. To change the values
|
|
10
|
-
* either modify the passed parameter(s) and return it, or return a totally
|
|
11
|
-
* new object.
|
|
12
|
-
*
|
|
13
|
-
* This method is intentionally limited to same-origin responses, regardless of
|
|
14
|
-
* whether CORS was used or not.
|
|
15
|
-
*
|
|
16
|
-
* @param response
|
|
17
|
-
* @param modifier
|
|
18
|
-
*/
|
|
19
|
-
declare function copyResponse(response: Response, modifier?: (responseInit: ResponseInit) => ResponseInit): Promise<Response>;
|
|
20
|
-
export { copyResponse };
|
package/dist/index.cjs
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var quotaErrorCallbacks = require('./quotaErrorCallbacks.cjs');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Get the current cache names and prefix/suffix used by Workbox.
|
|
7
|
-
*
|
|
8
|
-
* `cacheNames.precache` is used for precached assets,
|
|
9
|
-
* `cacheNames.googleAnalytics` is used by `@serwist/google-analytics` to
|
|
10
|
-
* store `analytics.js`, and `cacheNames.runtime` is used for everything else.
|
|
11
|
-
*
|
|
12
|
-
* `cacheNames.prefix` can be used to retrieve just the current prefix value.
|
|
13
|
-
* `cacheNames.suffix` can be used to retrieve just the current suffix value.
|
|
14
|
-
*
|
|
15
|
-
* @returns An object with `precache`, `runtime`, `prefix`, and `googleAnalytics` properties.
|
|
16
|
-
*/ const cacheNames = {
|
|
17
|
-
get googleAnalytics () {
|
|
18
|
-
return quotaErrorCallbacks.cacheNames.getGoogleAnalyticsName();
|
|
19
|
-
},
|
|
20
|
-
get precache () {
|
|
21
|
-
return quotaErrorCallbacks.cacheNames.getPrecacheName();
|
|
22
|
-
},
|
|
23
|
-
get prefix () {
|
|
24
|
-
return quotaErrorCallbacks.cacheNames.getPrefix();
|
|
25
|
-
},
|
|
26
|
-
get runtime () {
|
|
27
|
-
return quotaErrorCallbacks.cacheNames.getRuntimeName();
|
|
28
|
-
},
|
|
29
|
-
get suffix () {
|
|
30
|
-
return quotaErrorCallbacks.cacheNames.getSuffix();
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/*
|
|
35
|
-
Copyright 2019 Google LLC
|
|
36
|
-
|
|
37
|
-
Use of this source code is governed by an MIT-style
|
|
38
|
-
license that can be found in the LICENSE file or at
|
|
39
|
-
https://opensource.org/licenses/MIT.
|
|
40
|
-
*/ // Give TypeScript the correct global.
|
|
41
|
-
/**
|
|
42
|
-
* Claim any currently available clients once the service worker
|
|
43
|
-
* becomes active. This is normally used in conjunction with `skipWaiting()`.
|
|
44
|
-
*/ function clientsClaim() {
|
|
45
|
-
self.addEventListener("activate", ()=>self.clients.claim());
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Allows developers to copy a response and modify its `headers`, `status`,
|
|
50
|
-
* or `statusText` values (the values settable via a
|
|
51
|
-
* [`ResponseInit`](https://developer.mozilla.org/en-US/docs/Web/API/Response/Response#Syntax)
|
|
52
|
-
* object in the constructor).
|
|
53
|
-
* To modify these values, pass a function as the second argument. That
|
|
54
|
-
* function will be invoked with a single object with the response properties
|
|
55
|
-
* `{headers, status, statusText}`. The return value of this function will
|
|
56
|
-
* be used as the `ResponseInit` for the new `Response`. To change the values
|
|
57
|
-
* either modify the passed parameter(s) and return it, or return a totally
|
|
58
|
-
* new object.
|
|
59
|
-
*
|
|
60
|
-
* This method is intentionally limited to same-origin responses, regardless of
|
|
61
|
-
* whether CORS was used or not.
|
|
62
|
-
*
|
|
63
|
-
* @param response
|
|
64
|
-
* @param modifier
|
|
65
|
-
*/ async function copyResponse(response, modifier) {
|
|
66
|
-
let origin = null;
|
|
67
|
-
// If response.url isn't set, assume it's cross-origin and keep origin null.
|
|
68
|
-
if (response.url) {
|
|
69
|
-
const responseURL = new URL(response.url);
|
|
70
|
-
origin = responseURL.origin;
|
|
71
|
-
}
|
|
72
|
-
if (origin !== self.location.origin) {
|
|
73
|
-
throw new quotaErrorCallbacks.SerwistError("cross-origin-copy-response", {
|
|
74
|
-
origin
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
const clonedResponse = response.clone();
|
|
78
|
-
// Create a fresh `ResponseInit` object by cloning the headers.
|
|
79
|
-
const responseInit = {
|
|
80
|
-
headers: new Headers(clonedResponse.headers),
|
|
81
|
-
status: clonedResponse.status,
|
|
82
|
-
statusText: clonedResponse.statusText
|
|
83
|
-
};
|
|
84
|
-
// Apply any user modifications.
|
|
85
|
-
const modifiedResponseInit = modifier ? modifier(responseInit) : responseInit;
|
|
86
|
-
// Create the new response from the body stream and `ResponseInit`
|
|
87
|
-
// modifications. Note: not all browsers support the Response.body stream,
|
|
88
|
-
// so fall back to reading the entire body into memory as a blob.
|
|
89
|
-
const body = quotaErrorCallbacks.canConstructResponseFromBodyStream() ? clonedResponse.body : await clonedResponse.blob();
|
|
90
|
-
return new Response(body, modifiedResponseInit);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Adds a function to the set of quotaErrorCallbacks that will be executed if
|
|
95
|
-
* there's a quota error.
|
|
96
|
-
*
|
|
97
|
-
* @param callback
|
|
98
|
-
*/ // biome-ignore lint/complexity/noBannedTypes: Can't change Function type
|
|
99
|
-
function registerQuotaErrorCallback(callback) {
|
|
100
|
-
if (process.env.NODE_ENV !== "production") {
|
|
101
|
-
quotaErrorCallbacks.finalAssertExports.isType(callback, "function", {
|
|
102
|
-
moduleName: "@serwist/core",
|
|
103
|
-
funcName: "register",
|
|
104
|
-
paramName: "callback"
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
quotaErrorCallbacks.quotaErrorCallbacks.add(callback);
|
|
108
|
-
if (process.env.NODE_ENV !== "production") {
|
|
109
|
-
quotaErrorCallbacks.logger.log("Registered a callback to respond to quota errors.", callback);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Modifies the default cache names used by the Serwist packages.
|
|
115
|
-
* Cache names are generated as `<prefix>-<Cache Name>-<suffix>`.
|
|
116
|
-
*
|
|
117
|
-
* @param details
|
|
118
|
-
*/ function setCacheNameDetails(details) {
|
|
119
|
-
if (process.env.NODE_ENV !== "production") {
|
|
120
|
-
for (const key of Object.keys(details)){
|
|
121
|
-
quotaErrorCallbacks.finalAssertExports.isType(details[key], "string", {
|
|
122
|
-
moduleName: "@serwist/core",
|
|
123
|
-
funcName: "setCacheNameDetails",
|
|
124
|
-
paramName: `details.${key}`
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
if (details.precache?.length === 0) {
|
|
128
|
-
throw new quotaErrorCallbacks.SerwistError("invalid-cache-name", {
|
|
129
|
-
cacheNameId: "precache",
|
|
130
|
-
value: details.precache
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
if (details.runtime?.length === 0) {
|
|
134
|
-
throw new quotaErrorCallbacks.SerwistError("invalid-cache-name", {
|
|
135
|
-
cacheNameId: "runtime",
|
|
136
|
-
value: details.runtime
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
if (details.googleAnalytics?.length === 0) {
|
|
140
|
-
throw new quotaErrorCallbacks.SerwistError("invalid-cache-name", {
|
|
141
|
-
cacheNameId: "googleAnalytics",
|
|
142
|
-
value: details.googleAnalytics
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
quotaErrorCallbacks.cacheNames.updateDetails(details);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
exports.cacheNames = cacheNames;
|
|
150
|
-
exports.clientsClaim = clientsClaim;
|
|
151
|
-
exports.copyResponse = copyResponse;
|
|
152
|
-
exports.registerQuotaErrorCallback = registerQuotaErrorCallback;
|
|
153
|
-
exports.setCacheNameDetails = setCacheNameDetails;
|
package/dist/index.internal.cjs
DELETED
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var quotaErrorCallbacks = require('./quotaErrorCallbacks.cjs');
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
Copyright 2018 Google LLC
|
|
7
|
-
|
|
8
|
-
Use of this source code is governed by an MIT-style
|
|
9
|
-
license that can be found in the LICENSE file or at
|
|
10
|
-
https://opensource.org/licenses/MIT.
|
|
11
|
-
*/ /**
|
|
12
|
-
* The Deferred class composes Promises in a way that allows for them to be
|
|
13
|
-
* resolved or rejected from outside the constructor. In most cases promises
|
|
14
|
-
* should be used directly, but Deferreds can be necessary when the logic to
|
|
15
|
-
* resolve a promise must be separate.
|
|
16
|
-
*
|
|
17
|
-
* @private
|
|
18
|
-
*/ class Deferred {
|
|
19
|
-
promise;
|
|
20
|
-
resolve;
|
|
21
|
-
reject;
|
|
22
|
-
/**
|
|
23
|
-
* Creates a promise and exposes its resolve and reject functions as methods.
|
|
24
|
-
*/ constructor(){
|
|
25
|
-
this.promise = new Promise((resolve, reject)=>{
|
|
26
|
-
this.resolve = resolve;
|
|
27
|
-
this.reject = reject;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/*
|
|
33
|
-
Copyright 2020 Google LLC
|
|
34
|
-
Use of this source code is governed by an MIT-style
|
|
35
|
-
license that can be found in the LICENSE file or at
|
|
36
|
-
https://opensource.org/licenses/MIT.
|
|
37
|
-
*/ function stripParams(fullURL, ignoreParams) {
|
|
38
|
-
const strippedURL = new URL(fullURL);
|
|
39
|
-
for (const param of ignoreParams){
|
|
40
|
-
strippedURL.searchParams.delete(param);
|
|
41
|
-
}
|
|
42
|
-
return strippedURL.href;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Matches an item in the cache, ignoring specific URL params. This is similar
|
|
46
|
-
* to the `ignoreSearch` option, but it allows you to ignore just specific
|
|
47
|
-
* params (while continuing to match on the others).
|
|
48
|
-
*
|
|
49
|
-
* @private
|
|
50
|
-
* @param cache
|
|
51
|
-
* @param request
|
|
52
|
-
* @param matchOptions
|
|
53
|
-
* @param ignoreParams
|
|
54
|
-
* @returns
|
|
55
|
-
*/ async function cacheMatchIgnoreParams(cache, request, ignoreParams, matchOptions) {
|
|
56
|
-
const strippedRequestURL = stripParams(request.url, ignoreParams);
|
|
57
|
-
// If the request doesn't include any ignored params, match as normal.
|
|
58
|
-
if (request.url === strippedRequestURL) {
|
|
59
|
-
return cache.match(request, matchOptions);
|
|
60
|
-
}
|
|
61
|
-
// Otherwise, match by comparing keys
|
|
62
|
-
const keysOptions = {
|
|
63
|
-
...matchOptions,
|
|
64
|
-
ignoreSearch: true
|
|
65
|
-
};
|
|
66
|
-
const cacheKeys = await cache.keys(request, keysOptions);
|
|
67
|
-
for (const cacheKey of cacheKeys){
|
|
68
|
-
const strippedCacheKeyURL = stripParams(cacheKey.url, ignoreParams);
|
|
69
|
-
if (strippedRequestURL === strippedCacheKeyURL) {
|
|
70
|
-
return cache.match(cacheKey, matchOptions);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/*
|
|
77
|
-
Copyright 2019 Google LLC
|
|
78
|
-
|
|
79
|
-
Use of this source code is governed by an MIT-style
|
|
80
|
-
license that can be found in the LICENSE file or at
|
|
81
|
-
https://opensource.org/licenses/MIT.
|
|
82
|
-
*/ let supportStatus;
|
|
83
|
-
/**
|
|
84
|
-
* A utility function that determines whether the current browser supports
|
|
85
|
-
* constructing a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/ReadableStream)
|
|
86
|
-
* object.
|
|
87
|
-
*
|
|
88
|
-
* @returns `true`, if the current browser can successfully construct a `ReadableStream`, `false` otherwise.
|
|
89
|
-
*
|
|
90
|
-
* @private
|
|
91
|
-
*/ function canConstructReadableStream() {
|
|
92
|
-
if (supportStatus === undefined) {
|
|
93
|
-
// See https://github.com/GoogleChrome/workbox/issues/1473
|
|
94
|
-
try {
|
|
95
|
-
new ReadableStream({
|
|
96
|
-
start () {}
|
|
97
|
-
});
|
|
98
|
-
supportStatus = true;
|
|
99
|
-
} catch (error) {
|
|
100
|
-
supportStatus = false;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return supportStatus;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/*
|
|
107
|
-
Copyright 2019 Google LLC
|
|
108
|
-
Use of this source code is governed by an MIT-style
|
|
109
|
-
license that can be found in the LICENSE file or at
|
|
110
|
-
https://opensource.org/licenses/MIT.
|
|
111
|
-
*/ /**
|
|
112
|
-
* A helper function that prevents a promise from being flagged as unused.
|
|
113
|
-
*
|
|
114
|
-
* @private
|
|
115
|
-
**/ function dontWaitFor(promise) {
|
|
116
|
-
// Effective no-op.
|
|
117
|
-
void promise.then(()=>{});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Runs all of the callback functions, one at a time sequentially, in the order
|
|
122
|
-
* in which they were registered.
|
|
123
|
-
*
|
|
124
|
-
* @private
|
|
125
|
-
*/ async function executeQuotaErrorCallbacks() {
|
|
126
|
-
if (process.env.NODE_ENV !== "production") {
|
|
127
|
-
quotaErrorCallbacks.logger.log(`About to run ${quotaErrorCallbacks.quotaErrorCallbacks.size} callbacks to clean up caches.`);
|
|
128
|
-
}
|
|
129
|
-
for (const callback of quotaErrorCallbacks.quotaErrorCallbacks){
|
|
130
|
-
await callback();
|
|
131
|
-
if (process.env.NODE_ENV !== "production") {
|
|
132
|
-
quotaErrorCallbacks.logger.log(callback, "is complete.");
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (process.env.NODE_ENV !== "production") {
|
|
136
|
-
quotaErrorCallbacks.logger.log("Finished running callbacks.");
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/*
|
|
141
|
-
Copyright 2018 Google LLC
|
|
142
|
-
|
|
143
|
-
Use of this source code is governed by an MIT-style
|
|
144
|
-
license that can be found in the LICENSE file or at
|
|
145
|
-
https://opensource.org/licenses/MIT.
|
|
146
|
-
*/ const getFriendlyURL = (url)=>{
|
|
147
|
-
const urlObj = new URL(String(url), location.href);
|
|
148
|
-
// See https://github.com/GoogleChrome/workbox/issues/2323
|
|
149
|
-
// We want to include everything, except for the origin if it's same-origin.
|
|
150
|
-
return urlObj.href.replace(new RegExp(`^${location.origin}`), "");
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
/*
|
|
154
|
-
Copyright 2019 Google LLC
|
|
155
|
-
Use of this source code is governed by an MIT-style
|
|
156
|
-
license that can be found in the LICENSE file or at
|
|
157
|
-
https://opensource.org/licenses/MIT.
|
|
158
|
-
*/ /**
|
|
159
|
-
* Returns a promise that resolves and the passed number of milliseconds.
|
|
160
|
-
* This utility is an async/await-friendly version of `setTimeout`.
|
|
161
|
-
*
|
|
162
|
-
* @param ms
|
|
163
|
-
* @returns
|
|
164
|
-
* @private
|
|
165
|
-
*/ function timeout(ms) {
|
|
166
|
-
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const MAX_RETRY_TIME = 2000;
|
|
170
|
-
/**
|
|
171
|
-
* Returns a promise that resolves to a window client matching the passed
|
|
172
|
-
* `resultingClientId`. For browsers that don't support `resultingClientId`
|
|
173
|
-
* or if waiting for the resulting client to apper takes too long, resolve to
|
|
174
|
-
* `undefined`.
|
|
175
|
-
*
|
|
176
|
-
* @param resultingClientId
|
|
177
|
-
* @returns
|
|
178
|
-
* @private
|
|
179
|
-
*/ async function resultingClientExists(resultingClientId) {
|
|
180
|
-
if (!resultingClientId) {
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
let existingWindows = await self.clients.matchAll({
|
|
184
|
-
type: "window"
|
|
185
|
-
});
|
|
186
|
-
const existingWindowIds = new Set(existingWindows.map((w)=>w.id));
|
|
187
|
-
let resultingWindow = undefined;
|
|
188
|
-
const startTime = performance.now();
|
|
189
|
-
// Only wait up to `MAX_RETRY_TIME` to find a matching client.
|
|
190
|
-
while(performance.now() - startTime < MAX_RETRY_TIME){
|
|
191
|
-
existingWindows = await self.clients.matchAll({
|
|
192
|
-
type: "window"
|
|
193
|
-
});
|
|
194
|
-
resultingWindow = existingWindows.find((w)=>{
|
|
195
|
-
if (resultingClientId) {
|
|
196
|
-
// If we have a `resultingClientId`, we can match on that.
|
|
197
|
-
return w.id === resultingClientId;
|
|
198
|
-
}
|
|
199
|
-
// Otherwise match on finding a window not in `existingWindowIds`.
|
|
200
|
-
return !existingWindowIds.has(w.id);
|
|
201
|
-
});
|
|
202
|
-
if (resultingWindow) {
|
|
203
|
-
break;
|
|
204
|
-
}
|
|
205
|
-
// Sleep for 100ms and retry.
|
|
206
|
-
await timeout(100);
|
|
207
|
-
}
|
|
208
|
-
return resultingWindow;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/*
|
|
212
|
-
Copyright 2020 Google LLC
|
|
213
|
-
Use of this source code is governed by an MIT-style
|
|
214
|
-
license that can be found in the LICENSE file or at
|
|
215
|
-
https://opensource.org/licenses/MIT.
|
|
216
|
-
*/ /**
|
|
217
|
-
* A utility method that makes it easier to use `event.waitUntil` with
|
|
218
|
-
* async functions and return the result.
|
|
219
|
-
*
|
|
220
|
-
* @param event
|
|
221
|
-
* @param asyncFn
|
|
222
|
-
* @returns
|
|
223
|
-
* @private
|
|
224
|
-
*/ function waitUntil(event, asyncFn) {
|
|
225
|
-
const returnPromise = asyncFn();
|
|
226
|
-
event.waitUntil(returnPromise);
|
|
227
|
-
return returnPromise;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
exports.SerwistError = quotaErrorCallbacks.SerwistError;
|
|
231
|
-
exports.assert = quotaErrorCallbacks.finalAssertExports;
|
|
232
|
-
exports.canConstructResponseFromBodyStream = quotaErrorCallbacks.canConstructResponseFromBodyStream;
|
|
233
|
-
exports.logger = quotaErrorCallbacks.logger;
|
|
234
|
-
exports.privateCacheNames = quotaErrorCallbacks.cacheNames;
|
|
235
|
-
exports.Deferred = Deferred;
|
|
236
|
-
exports.cacheMatchIgnoreParams = cacheMatchIgnoreParams;
|
|
237
|
-
exports.canConstructReadableStream = canConstructReadableStream;
|
|
238
|
-
exports.dontWaitFor = dontWaitFor;
|
|
239
|
-
exports.executeQuotaErrorCallbacks = executeQuotaErrorCallbacks;
|
|
240
|
-
exports.getFriendlyURL = getFriendlyURL;
|
|
241
|
-
exports.resultingClientExists = resultingClientExists;
|
|
242
|
-
exports.timeout = timeout;
|
|
243
|
-
exports.waitUntil = waitUntil;
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const messageGenerator: ((code: string, ...args: any[]) => string) | ((code: string, details?: {}) => string);
|