serwist 9.0.0-preview.24 → 9.0.0-preview.26

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.
Files changed (232) hide show
  1. package/dist/NavigationRoute.d.ts +6 -7
  2. package/dist/NavigationRoute.d.ts.map +1 -1
  3. package/dist/PrecacheRoute.d.ts +2 -2
  4. package/dist/PrecacheRoute.d.ts.map +1 -1
  5. package/dist/RegExpRoute.d.ts +4 -4
  6. package/dist/RegExpRoute.d.ts.map +1 -1
  7. package/dist/Route.d.ts +10 -10
  8. package/dist/Route.d.ts.map +1 -1
  9. package/dist/Serwist.d.ts +39 -44
  10. package/dist/Serwist.d.ts.map +1 -1
  11. package/dist/chunks/printInstallDetails.js +1587 -0
  12. package/dist/chunks/resultingClientExists.js +1 -1
  13. package/dist/chunks/waitUntil.js +426 -1
  14. package/dist/copyResponse.d.ts +8 -10
  15. package/dist/copyResponse.d.ts.map +1 -1
  16. package/dist/disableDevLogs.d.ts +1 -1
  17. package/dist/index.d.ts +41 -12
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.internal.d.ts +3 -1
  20. package/dist/index.internal.d.ts.map +1 -1
  21. package/dist/index.internal.js +1 -2
  22. package/dist/index.js +1464 -8
  23. package/dist/index.legacy.d.ts +4 -8
  24. package/dist/index.legacy.d.ts.map +1 -1
  25. package/dist/index.legacy.js +166 -16
  26. package/dist/legacy/PrecacheController.d.ts +1 -1
  27. package/dist/legacy/PrecacheController.d.ts.map +1 -1
  28. package/dist/legacy/PrecacheRoute.d.ts.map +1 -1
  29. package/dist/legacy/Router.d.ts +1 -1
  30. package/dist/legacy/Router.d.ts.map +1 -1
  31. package/dist/legacy/constants.d.ts.map +1 -0
  32. package/dist/legacy/fallbacks.d.ts +1 -1
  33. package/dist/legacy/fallbacks.d.ts.map +1 -1
  34. package/dist/legacy/handlePrecaching.d.ts.map +1 -1
  35. package/dist/legacy/initializeGoogleAnalytics.d.ts +38 -0
  36. package/dist/legacy/initializeGoogleAnalytics.d.ts.map +1 -0
  37. package/dist/legacy/installSerwist.d.ts +69 -3
  38. package/dist/legacy/installSerwist.d.ts.map +1 -1
  39. package/dist/legacy/registerRoute.d.ts +1 -1
  40. package/dist/legacy/registerRoute.d.ts.map +1 -1
  41. package/dist/{plugins → lib}/backgroundSync/BackgroundSyncPlugin.d.ts +3 -3
  42. package/dist/lib/backgroundSync/BackgroundSyncPlugin.d.ts.map +1 -0
  43. package/dist/{plugins/backgroundSync/Queue.d.ts → lib/backgroundSync/BackgroundSyncQueue.d.ts} +29 -13
  44. package/dist/lib/backgroundSync/BackgroundSyncQueue.d.ts.map +1 -0
  45. package/dist/{plugins/backgroundSync/QueueDb.d.ts → lib/backgroundSync/BackgroundSyncQueueDb.d.ts} +7 -7
  46. package/dist/lib/backgroundSync/BackgroundSyncQueueDb.d.ts.map +1 -0
  47. package/dist/{plugins/backgroundSync/QueueStore.d.ts → lib/backgroundSync/BackgroundSyncQueueStore.d.ts} +7 -7
  48. package/dist/lib/backgroundSync/BackgroundSyncQueueStore.d.ts.map +1 -0
  49. package/dist/lib/backgroundSync/StorableRequest.d.ts.map +1 -0
  50. package/dist/lib/broadcastUpdate/BroadcastCacheUpdate.d.ts.map +1 -0
  51. package/dist/{plugins → lib}/broadcastUpdate/BroadcastUpdatePlugin.d.ts +1 -1
  52. package/dist/lib/broadcastUpdate/BroadcastUpdatePlugin.d.ts.map +1 -0
  53. package/dist/lib/broadcastUpdate/constants.d.ts +5 -0
  54. package/dist/lib/broadcastUpdate/constants.d.ts.map +1 -0
  55. package/dist/lib/broadcastUpdate/responsesAreSame.d.ts.map +1 -0
  56. package/dist/{plugins → lib}/broadcastUpdate/types.d.ts +3 -3
  57. package/dist/lib/broadcastUpdate/types.d.ts.map +1 -0
  58. package/dist/lib/cacheableResponse/CacheableResponse.d.ts.map +1 -0
  59. package/dist/lib/cacheableResponse/CacheableResponsePlugin.d.ts.map +1 -0
  60. package/dist/{plugins → lib}/expiration/CacheExpiration.d.ts +1 -1
  61. package/dist/lib/expiration/CacheExpiration.d.ts.map +1 -0
  62. package/dist/{plugins → lib}/expiration/ExpirationPlugin.d.ts +1 -1
  63. package/dist/lib/expiration/ExpirationPlugin.d.ts.map +1 -0
  64. package/dist/lib/expiration/models/CacheTimestampsModel.d.ts.map +1 -0
  65. package/dist/lib/googleAnalytics/constants.d.ts +10 -0
  66. package/dist/lib/googleAnalytics/constants.d.ts.map +1 -0
  67. package/dist/{plugins/googleAnalytics/initialize.d.ts → lib/googleAnalytics/initializeGoogleAnalytics.d.ts} +2 -2
  68. package/dist/lib/googleAnalytics/initializeGoogleAnalytics.d.ts.map +1 -0
  69. package/dist/{plugins → lib}/precaching/PrecacheFallbackPlugin.d.ts +1 -1
  70. package/dist/lib/precaching/PrecacheFallbackPlugin.d.ts.map +1 -0
  71. package/dist/lib/rangeRequests/RangeRequestsPlugin.d.ts.map +1 -0
  72. package/dist/lib/rangeRequests/createPartialResponse.d.ts.map +1 -0
  73. package/dist/lib/rangeRequests/utils/calculateEffectiveBoundaries.d.ts.map +1 -0
  74. package/dist/lib/rangeRequests/utils/parseRangeHeader.d.ts.map +1 -0
  75. package/dist/{strategies → lib/strategies}/CacheFirst.d.ts +1 -1
  76. package/dist/lib/strategies/CacheFirst.d.ts.map +1 -0
  77. package/dist/{strategies → lib/strategies}/CacheOnly.d.ts +2 -2
  78. package/dist/lib/strategies/CacheOnly.d.ts.map +1 -0
  79. package/dist/{strategies → lib/strategies}/NetworkFirst.d.ts +2 -2
  80. package/dist/lib/strategies/NetworkFirst.d.ts.map +1 -0
  81. package/dist/{strategies → lib/strategies}/NetworkOnly.d.ts +2 -2
  82. package/dist/lib/strategies/NetworkOnly.d.ts.map +1 -0
  83. package/dist/{PrecacheStrategy.d.ts → lib/strategies/PrecacheStrategy.d.ts} +5 -5
  84. package/dist/lib/strategies/PrecacheStrategy.d.ts.map +1 -0
  85. package/dist/{strategies → lib/strategies}/StaleWhileRevalidate.d.ts +1 -1
  86. package/dist/lib/strategies/StaleWhileRevalidate.d.ts.map +1 -0
  87. package/dist/{strategies → lib/strategies}/Strategy.d.ts +15 -17
  88. package/dist/lib/strategies/Strategy.d.ts.map +1 -0
  89. package/dist/{strategies → lib/strategies}/StrategyHandler.d.ts +35 -41
  90. package/dist/lib/strategies/StrategyHandler.d.ts.map +1 -0
  91. package/dist/lib/strategies/plugins/cacheOkAndOpaquePlugin.d.ts +3 -0
  92. package/dist/lib/strategies/plugins/cacheOkAndOpaquePlugin.d.ts.map +1 -0
  93. package/dist/lib/strategies/utils/messages.d.ts.map +1 -0
  94. package/dist/navigationPreload.d.ts +3 -3
  95. package/dist/types.d.ts +12 -7
  96. package/dist/types.d.ts.map +1 -1
  97. package/dist/utils/PrecacheCacheKeyPlugin.d.ts +1 -1
  98. package/dist/utils/PrecacheCacheKeyPlugin.d.ts.map +1 -1
  99. package/dist/utils/assert.d.ts.map +1 -1
  100. package/dist/utils/cleanupOutdatedCaches.d.ts.map +1 -0
  101. package/dist/utils/clientsClaim.d.ts.map +1 -0
  102. package/dist/{parseRoute.d.ts → utils/parseRoute.d.ts} +3 -3
  103. package/dist/utils/parseRoute.d.ts.map +1 -0
  104. package/package.json +7 -21
  105. package/src/NavigationRoute.ts +6 -7
  106. package/src/PrecacheRoute.ts +5 -5
  107. package/src/RegExpRoute.ts +5 -5
  108. package/src/Route.ts +11 -11
  109. package/src/Serwist.ts +73 -80
  110. package/src/copyResponse.ts +7 -9
  111. package/src/disableDevLogs.ts +1 -1
  112. package/src/index.internal.ts +4 -0
  113. package/src/index.legacy.ts +14 -18
  114. package/src/index.ts +105 -19
  115. package/src/legacy/PrecacheController.ts +8 -8
  116. package/src/legacy/PrecacheFallbackPlugin.ts +1 -1
  117. package/src/legacy/PrecacheRoute.ts +3 -3
  118. package/src/legacy/Router.ts +5 -5
  119. package/src/legacy/fallbacks.ts +3 -3
  120. package/src/legacy/handlePrecaching.ts +1 -1
  121. package/src/legacy/initializeGoogleAnalytics.ts +218 -0
  122. package/src/legacy/installSerwist.ts +156 -5
  123. package/src/legacy/registerRoute.ts +1 -1
  124. package/src/{plugins → lib}/backgroundSync/BackgroundSyncPlugin.ts +6 -6
  125. package/src/{plugins/backgroundSync/Queue.ts → lib/backgroundSync/BackgroundSyncQueue.ts} +47 -26
  126. package/src/{plugins/backgroundSync/QueueDb.ts → lib/backgroundSync/BackgroundSyncQueueDb.ts} +16 -16
  127. package/src/{plugins/backgroundSync/QueueStore.ts → lib/backgroundSync/BackgroundSyncQueueStore.ts} +13 -13
  128. package/src/{plugins → lib}/backgroundSync/StorableRequest.ts +2 -2
  129. package/src/{plugins → lib}/broadcastUpdate/BroadcastCacheUpdate.ts +14 -9
  130. package/src/{plugins → lib}/broadcastUpdate/BroadcastUpdatePlugin.ts +1 -1
  131. package/src/lib/broadcastUpdate/constants.ts +12 -0
  132. package/src/{plugins → lib}/broadcastUpdate/types.ts +3 -3
  133. package/src/{plugins → lib}/cacheableResponse/CacheableResponse.ts +5 -5
  134. package/src/{plugins → lib}/expiration/CacheExpiration.ts +7 -7
  135. package/src/{plugins → lib}/expiration/ExpirationPlugin.ts +10 -10
  136. package/src/lib/googleAnalytics/constants.ts +22 -0
  137. package/src/{plugins/googleAnalytics/initialize.ts → lib/googleAnalytics/initializeGoogleAnalytics.ts} +9 -9
  138. package/src/{strategies → lib/strategies}/CacheFirst.ts +5 -5
  139. package/src/{strategies → lib/strategies}/CacheOnly.ts +6 -6
  140. package/src/{strategies → lib/strategies}/NetworkFirst.ts +7 -7
  141. package/src/{strategies → lib/strategies}/NetworkOnly.ts +7 -7
  142. package/src/{PrecacheStrategy.ts → lib/strategies/PrecacheStrategy.ts} +14 -10
  143. package/src/{strategies → lib/strategies}/StaleWhileRevalidate.ts +5 -5
  144. package/src/{strategies → lib/strategies}/Strategy.ts +19 -21
  145. package/src/{strategies → lib/strategies}/StrategyHandler.ts +45 -51
  146. package/src/{strategies → lib/strategies}/plugins/cacheOkAndOpaquePlugin.ts +1 -1
  147. package/src/{strategies → lib/strategies}/utils/messages.ts +2 -2
  148. package/src/models/messages/messages.ts +1 -1
  149. package/src/navigationPreload.ts +3 -3
  150. package/src/registerQuotaErrorCallback.ts +1 -1
  151. package/src/types.ts +12 -7
  152. package/src/utils/PrecacheCacheKeyPlugin.ts +1 -1
  153. package/src/utils/assert.ts +1 -1
  154. package/src/{cleanupOutdatedCaches.ts → utils/cleanupOutdatedCaches.ts} +3 -4
  155. package/src/utils/executeQuotaErrorCallbacks.ts +1 -1
  156. package/src/{parseRoute.ts → utils/parseRoute.ts} +21 -23
  157. package/src/utils/welcome.ts +1 -1
  158. package/dist/PrecacheStrategy.d.ts.map +0 -1
  159. package/dist/chunks/NetworkOnly.js +0 -599
  160. package/dist/chunks/PrecacheFallbackPlugin.js +0 -634
  161. package/dist/chunks/Serwist.js +0 -1034
  162. package/dist/chunks/registerQuotaErrorCallback.js +0 -17
  163. package/dist/chunks/timeout.js +0 -400
  164. package/dist/cleanupOutdatedCaches.d.ts.map +0 -1
  165. package/dist/clientsClaim.d.ts.map +0 -1
  166. package/dist/index.plugins.d.ts +0 -41
  167. package/dist/index.plugins.d.ts.map +0 -1
  168. package/dist/index.plugins.js +0 -669
  169. package/dist/index.strategies.d.ts +0 -22
  170. package/dist/index.strategies.d.ts.map +0 -1
  171. package/dist/index.strategies.js +0 -144
  172. package/dist/parseRoute.d.ts.map +0 -1
  173. package/dist/plugins/backgroundSync/BackgroundSyncPlugin.d.ts.map +0 -1
  174. package/dist/plugins/backgroundSync/Queue.d.ts.map +0 -1
  175. package/dist/plugins/backgroundSync/QueueDb.d.ts.map +0 -1
  176. package/dist/plugins/backgroundSync/QueueStore.d.ts.map +0 -1
  177. package/dist/plugins/backgroundSync/StorableRequest.d.ts.map +0 -1
  178. package/dist/plugins/broadcastUpdate/BroadcastCacheUpdate.d.ts.map +0 -1
  179. package/dist/plugins/broadcastUpdate/BroadcastUpdatePlugin.d.ts.map +0 -1
  180. package/dist/plugins/broadcastUpdate/constants.d.ts +0 -5
  181. package/dist/plugins/broadcastUpdate/constants.d.ts.map +0 -1
  182. package/dist/plugins/broadcastUpdate/responsesAreSame.d.ts.map +0 -1
  183. package/dist/plugins/broadcastUpdate/types.d.ts.map +0 -1
  184. package/dist/plugins/cacheableResponse/CacheableResponse.d.ts.map +0 -1
  185. package/dist/plugins/cacheableResponse/CacheableResponsePlugin.d.ts.map +0 -1
  186. package/dist/plugins/expiration/CacheExpiration.d.ts.map +0 -1
  187. package/dist/plugins/expiration/ExpirationPlugin.d.ts.map +0 -1
  188. package/dist/plugins/expiration/models/CacheTimestampsModel.d.ts.map +0 -1
  189. package/dist/plugins/googleAnalytics/constants.d.ts.map +0 -1
  190. package/dist/plugins/googleAnalytics/initialize.d.ts.map +0 -1
  191. package/dist/plugins/precaching/PrecacheFallbackPlugin.d.ts.map +0 -1
  192. package/dist/plugins/rangeRequests/RangeRequestsPlugin.d.ts.map +0 -1
  193. package/dist/plugins/rangeRequests/createPartialResponse.d.ts.map +0 -1
  194. package/dist/plugins/rangeRequests/utils/calculateEffectiveBoundaries.d.ts.map +0 -1
  195. package/dist/plugins/rangeRequests/utils/parseRangeHeader.d.ts.map +0 -1
  196. package/dist/strategies/CacheFirst.d.ts.map +0 -1
  197. package/dist/strategies/CacheOnly.d.ts.map +0 -1
  198. package/dist/strategies/NetworkFirst.d.ts.map +0 -1
  199. package/dist/strategies/NetworkOnly.d.ts.map +0 -1
  200. package/dist/strategies/StaleWhileRevalidate.d.ts.map +0 -1
  201. package/dist/strategies/Strategy.d.ts.map +0 -1
  202. package/dist/strategies/StrategyHandler.d.ts.map +0 -1
  203. package/dist/strategies/plugins/cacheOkAndOpaquePlugin.d.ts +0 -3
  204. package/dist/strategies/plugins/cacheOkAndOpaquePlugin.d.ts.map +0 -1
  205. package/dist/strategies/utils/messages.d.ts.map +0 -1
  206. package/src/index.plugins.ts +0 -95
  207. package/src/index.strategies.ts +0 -26
  208. package/src/plugins/broadcastUpdate/constants.ts +0 -12
  209. package/dist/{plugins/googleAnalytics → legacy}/constants.d.ts +0 -0
  210. package/dist/{plugins → lib}/backgroundSync/StorableRequest.d.ts +0 -0
  211. package/dist/{plugins → lib}/broadcastUpdate/BroadcastCacheUpdate.d.ts +0 -0
  212. package/dist/{plugins → lib}/broadcastUpdate/responsesAreSame.d.ts +0 -0
  213. package/dist/{plugins → lib}/cacheableResponse/CacheableResponse.d.ts +0 -0
  214. package/dist/{plugins → lib}/cacheableResponse/CacheableResponsePlugin.d.ts +0 -0
  215. package/dist/{plugins → lib}/expiration/models/CacheTimestampsModel.d.ts +0 -0
  216. package/dist/{plugins → lib}/rangeRequests/RangeRequestsPlugin.d.ts +0 -0
  217. package/dist/{plugins → lib}/rangeRequests/createPartialResponse.d.ts +0 -0
  218. package/dist/{plugins → lib}/rangeRequests/utils/calculateEffectiveBoundaries.d.ts +0 -0
  219. package/dist/{plugins → lib}/rangeRequests/utils/parseRangeHeader.d.ts +0 -0
  220. package/dist/{strategies → lib/strategies}/utils/messages.d.ts +0 -0
  221. package/dist/{cleanupOutdatedCaches.d.ts → utils/cleanupOutdatedCaches.d.ts} +0 -0
  222. package/dist/{clientsClaim.d.ts → utils/clientsClaim.d.ts} +0 -0
  223. package/src/{plugins/googleAnalytics → legacy}/constants.ts +0 -0
  224. package/src/{plugins → lib}/broadcastUpdate/responsesAreSame.ts +0 -0
  225. package/src/{plugins → lib}/cacheableResponse/CacheableResponsePlugin.ts +0 -0
  226. package/src/{plugins → lib}/expiration/models/CacheTimestampsModel.ts +0 -0
  227. package/src/{plugins → lib}/precaching/PrecacheFallbackPlugin.ts +1 -1
  228. package/src/{plugins → lib}/rangeRequests/RangeRequestsPlugin.ts +0 -0
  229. package/src/{plugins → lib}/rangeRequests/createPartialResponse.ts +1 -1
  230. package/src/{plugins → lib}/rangeRequests/utils/calculateEffectiveBoundaries.ts +1 -1
  231. package/src/{plugins → lib}/rangeRequests/utils/parseRangeHeader.ts +1 -1
  232. /package/src/{clientsClaim.ts → utils/clientsClaim.ts} +0 -0
@@ -11,16 +11,16 @@ import { openDB } from "idb";
11
11
 
12
12
  import type { RequestData } from "./StorableRequest.js";
13
13
 
14
- interface QueueDBSchema extends DBSchema {
14
+ interface BackgroundSyncQueueDBSchema extends DBSchema {
15
15
  requests: {
16
16
  key: number;
17
- value: QueueStoreEntry;
17
+ value: BackgroundSyncQueueStoreEntry;
18
18
  indexes: { queueName: string };
19
19
  };
20
20
  }
21
21
 
22
- const DB_VERSION = 3;
23
- const DB_NAME = "serwist-background-sync";
22
+ const BACKGROUND_SYNC_DB_VERSION = 3;
23
+ const BACKGROUND_SYNC_DB_NAME = "serwist-background-sync";
24
24
  const REQUEST_OBJECT_STORE_NAME = "requests";
25
25
  const QUEUE_NAME_INDEX = "queueName";
26
26
 
@@ -32,7 +32,7 @@ export interface UnidentifiedQueueStoreEntry {
32
32
  metadata?: Record<string, unknown>;
33
33
  }
34
34
 
35
- export interface QueueStoreEntry extends UnidentifiedQueueStoreEntry {
35
+ export interface BackgroundSyncQueueStoreEntry extends UnidentifiedQueueStoreEntry {
36
36
  id: number;
37
37
  }
38
38
 
@@ -44,8 +44,8 @@ export interface QueueStoreEntry extends UnidentifiedQueueStoreEntry {
44
44
  * @private
45
45
  */
46
46
 
47
- export class QueueDb {
48
- private _db: IDBPDatabase<QueueDBSchema> | null = null;
47
+ export class BackgroundSyncQueueDb {
48
+ private _db: IDBPDatabase<BackgroundSyncQueueDBSchema> | null = null;
49
49
 
50
50
  /**
51
51
  * Add QueueStoreEntry to underlying db.
@@ -57,7 +57,7 @@ export class QueueDb {
57
57
  const tx = db.transaction(REQUEST_OBJECT_STORE_NAME, "readwrite", {
58
58
  durability: "relaxed",
59
59
  });
60
- await tx.store.add(entry as QueueStoreEntry);
60
+ await tx.store.add(entry as BackgroundSyncQueueStoreEntry);
61
61
  await tx.done;
62
62
  }
63
63
 
@@ -78,10 +78,10 @@ export class QueueDb {
78
78
  * @param queueName
79
79
  * @returns
80
80
  */
81
- async getAllEntriesByQueueName(queueName: string): Promise<QueueStoreEntry[]> {
81
+ async getAllEntriesByQueueName(queueName: string): Promise<BackgroundSyncQueueStoreEntry[]> {
82
82
  const db = await this.getDb();
83
83
  const results = await db.getAllFromIndex(REQUEST_OBJECT_STORE_NAME, QUEUE_NAME_INDEX, IDBKeyRange.only(queueName));
84
- return results ? results : new Array<QueueStoreEntry>();
84
+ return results ? results : new Array<BackgroundSyncQueueStoreEntry>();
85
85
  }
86
86
 
87
87
  /**
@@ -110,7 +110,7 @@ export class QueueDb {
110
110
  * @param queueName
111
111
  * @returns
112
112
  */
113
- async getFirstEntryByQueueName(queueName: string): Promise<QueueStoreEntry | undefined> {
113
+ async getFirstEntryByQueueName(queueName: string): Promise<BackgroundSyncQueueStoreEntry | undefined> {
114
114
  return await this.getEndEntryFromIndex(IDBKeyRange.only(queueName), "next");
115
115
  }
116
116
 
@@ -119,7 +119,7 @@ export class QueueDb {
119
119
  * @param queueName
120
120
  * @returns
121
121
  */
122
- async getLastEntryByQueueName(queueName: string): Promise<QueueStoreEntry | undefined> {
122
+ async getLastEntryByQueueName(queueName: string): Promise<BackgroundSyncQueueStoreEntry | undefined> {
123
123
  return await this.getEndEntryFromIndex(IDBKeyRange.only(queueName), "prev");
124
124
  }
125
125
 
@@ -132,7 +132,7 @@ export class QueueDb {
132
132
  * @returns
133
133
  * @private
134
134
  */
135
- async getEndEntryFromIndex(query: IDBKeyRange, direction: IDBCursorDirection): Promise<QueueStoreEntry | undefined> {
135
+ async getEndEntryFromIndex(query: IDBKeyRange, direction: IDBCursorDirection): Promise<BackgroundSyncQueueStoreEntry | undefined> {
136
136
  const db = await this.getDb();
137
137
 
138
138
  const cursor = await db.transaction(REQUEST_OBJECT_STORE_NAME).store.index(QUEUE_NAME_INDEX).openCursor(query, direction);
@@ -146,7 +146,7 @@ export class QueueDb {
146
146
  */
147
147
  private async getDb() {
148
148
  if (!this._db) {
149
- this._db = await openDB(DB_NAME, DB_VERSION, {
149
+ this._db = await openDB(BACKGROUND_SYNC_DB_NAME, BACKGROUND_SYNC_DB_VERSION, {
150
150
  upgrade: this._upgradeDb,
151
151
  });
152
152
  }
@@ -160,8 +160,8 @@ export class QueueDb {
160
160
  * @param oldVersion
161
161
  * @private
162
162
  */
163
- private _upgradeDb(db: IDBPDatabase<QueueDBSchema>, oldVersion: number) {
164
- if (oldVersion > 0 && oldVersion < DB_VERSION) {
163
+ private _upgradeDb(db: IDBPDatabase<BackgroundSyncQueueDBSchema>, oldVersion: number) {
164
+ if (oldVersion > 0 && oldVersion < BACKGROUND_SYNC_DB_VERSION) {
165
165
  if (db.objectStoreNames.contains(REQUEST_OBJECT_STORE_NAME)) {
166
166
  db.deleteObjectStore(REQUEST_OBJECT_STORE_NAME);
167
167
  }
@@ -6,8 +6,8 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
  import { assert } from "../../utils/assert.js";
9
- import type { QueueStoreEntry, UnidentifiedQueueStoreEntry } from "./QueueDb.js";
10
- import { QueueDb } from "./QueueDb.js";
9
+ import type { BackgroundSyncQueueStoreEntry, UnidentifiedQueueStoreEntry } from "./BackgroundSyncQueueDb.js";
10
+ import { BackgroundSyncQueueDb } from "./BackgroundSyncQueueDb.js";
11
11
 
12
12
  /**
13
13
  * A class to manage storing requests from a Queue in IndexedDB,
@@ -16,9 +16,9 @@ import { QueueDb } from "./QueueDb.js";
16
16
  * Most developers will not need to access this class directly;
17
17
  * it is exposed for advanced use cases.
18
18
  */
19
- export class QueueStore {
19
+ export class BackgroundSyncQueueStore {
20
20
  private readonly _queueName: string;
21
- private readonly _queueDb: QueueDb;
21
+ private readonly _queueDb: BackgroundSyncQueueDb;
22
22
 
23
23
  /**
24
24
  * Associates this instance with a Queue instance, so entries added can be
@@ -28,7 +28,7 @@ export class QueueStore {
28
28
  */
29
29
  constructor(queueName: string) {
30
30
  this._queueName = queueName;
31
- this._queueDb = new QueueDb();
31
+ this._queueDb = new BackgroundSyncQueueDb();
32
32
  }
33
33
 
34
34
  /**
@@ -39,13 +39,13 @@ export class QueueStore {
39
39
  async pushEntry(entry: UnidentifiedQueueStoreEntry): Promise<void> {
40
40
  if (process.env.NODE_ENV !== "production") {
41
41
  assert!.isType(entry, "object", {
42
- moduleName: "serwist/plugins",
42
+ moduleName: "serwist",
43
43
  className: "BackgroundSyncQueueStore",
44
44
  funcName: "pushEntry",
45
45
  paramName: "entry",
46
46
  });
47
47
  assert!.isType(entry.requestData, "object", {
48
- moduleName: "serwist/plugins",
48
+ moduleName: "serwist",
49
49
  className: "BackgroundSyncQueueStore",
50
50
  funcName: "pushEntry",
51
51
  paramName: "entry.requestData",
@@ -67,13 +67,13 @@ export class QueueStore {
67
67
  async unshiftEntry(entry: UnidentifiedQueueStoreEntry): Promise<void> {
68
68
  if (process.env.NODE_ENV !== "production") {
69
69
  assert!.isType(entry, "object", {
70
- moduleName: "serwist/plugins",
70
+ moduleName: "serwist",
71
71
  className: "BackgroundSyncQueueStore",
72
72
  funcName: "unshiftEntry",
73
73
  paramName: "entry",
74
74
  });
75
75
  assert!.isType(entry.requestData, "object", {
76
- moduleName: "serwist/plugins",
76
+ moduleName: "serwist",
77
77
  className: "BackgroundSyncQueueStore",
78
78
  funcName: "unshiftEntry",
79
79
  paramName: "entry.requestData",
@@ -99,7 +99,7 @@ export class QueueStore {
99
99
  *
100
100
  * @returns
101
101
  */
102
- async popEntry(): Promise<QueueStoreEntry | undefined> {
102
+ async popEntry(): Promise<BackgroundSyncQueueStoreEntry | undefined> {
103
103
  return this._removeEntry(await this._queueDb.getLastEntryByQueueName(this._queueName));
104
104
  }
105
105
 
@@ -108,7 +108,7 @@ export class QueueStore {
108
108
  *
109
109
  * @returns
110
110
  */
111
- async shiftEntry(): Promise<QueueStoreEntry | undefined> {
111
+ async shiftEntry(): Promise<BackgroundSyncQueueStoreEntry | undefined> {
112
112
  return this._removeEntry(await this._queueDb.getFirstEntryByQueueName(this._queueName));
113
113
  }
114
114
 
@@ -117,7 +117,7 @@ export class QueueStore {
117
117
  *
118
118
  * @returns
119
119
  */
120
- async getAll(): Promise<QueueStoreEntry[]> {
120
+ async getAll(): Promise<BackgroundSyncQueueStoreEntry[]> {
121
121
  return await this._queueDb.getAllEntriesByQueueName(this._queueName);
122
122
  }
123
123
 
@@ -151,7 +151,7 @@ export class QueueStore {
151
151
  * @returns
152
152
  * @private
153
153
  */
154
- async _removeEntry(entry?: QueueStoreEntry): Promise<QueueStoreEntry | undefined> {
154
+ async _removeEntry(entry?: BackgroundSyncQueueStoreEntry): Promise<BackgroundSyncQueueStoreEntry | undefined> {
155
155
  if (entry) {
156
156
  await this.deleteEntry(entry.id);
157
157
  }
@@ -85,13 +85,13 @@ export class StorableRequest {
85
85
  constructor(requestData: RequestData) {
86
86
  if (process.env.NODE_ENV !== "production") {
87
87
  assert!.isType(requestData, "object", {
88
- moduleName: "serwist/plugins",
88
+ moduleName: "serwist",
89
89
  className: "StorableRequest",
90
90
  funcName: "constructor",
91
91
  paramName: "requestData",
92
92
  });
93
93
  assert!.isType(requestData.url, "string", {
94
- moduleName: "serwist/plugins",
94
+ moduleName: "serwist",
95
95
  className: "StorableRequest",
96
96
  funcName: "constructor",
97
97
  paramName: "requestData.url",
@@ -11,7 +11,12 @@ import { assert } from "../../utils/assert.js";
11
11
  import { logger } from "../../utils/logger.js";
12
12
  import { resultingClientExists } from "../../utils/resultingClientExists.js";
13
13
  import { timeout } from "../../utils/timeout.js";
14
- import { CACHE_UPDATED_MESSAGE_META, CACHE_UPDATED_MESSAGE_TYPE, defaultHeadersToCheck, defaultNotifyAllClients } from "./constants.js";
14
+ import {
15
+ BROADCAST_UPDATE_DEFAULT_HEADERS,
16
+ BROADCAST_UPDATE_DEFAULT_NOTIFY,
17
+ BROADCAST_UPDATE_MESSAGE_META,
18
+ BROADCAST_UPDATE_MESSAGE_TYPE,
19
+ } from "./constants.js";
15
20
  import { responsesAreSame } from "./responsesAreSame.js";
16
21
  import type { BroadcastCacheUpdateOptions, BroadcastMessage, BroadcastPayload, BroadcastPayloadGenerator } from "./types.js";
17
22
 
@@ -21,7 +26,7 @@ import type { BroadcastCacheUpdateOptions, BroadcastMessage, BroadcastPayload, B
21
26
  const isSafari = typeof navigator !== "undefined" && /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
22
27
 
23
28
  // Give TypeScript the correct global.
24
- declare let self: ServiceWorkerGlobalScope;
29
+ declare const self: ServiceWorkerGlobalScope;
25
30
  /**
26
31
  * Generates the default payload used in update messages. By default the
27
32
  * payload includes the `cacheName` and `updatedURL` fields.
@@ -55,9 +60,9 @@ export class BroadcastCacheUpdate {
55
60
  * @param options
56
61
  */
57
62
  constructor({ generatePayload, headersToCheck, notifyAllClients }: BroadcastCacheUpdateOptions = {}) {
58
- this._headersToCheck = headersToCheck || defaultHeadersToCheck;
63
+ this._headersToCheck = headersToCheck || BROADCAST_UPDATE_DEFAULT_HEADERS;
59
64
  this._generatePayload = generatePayload || defaultPayloadGenerator;
60
- this._notifyAllClients = notifyAllClients ?? defaultNotifyAllClients;
65
+ this._notifyAllClients = notifyAllClients ?? BROADCAST_UPDATE_DEFAULT_NOTIFY;
61
66
  }
62
67
 
63
68
  /**
@@ -85,19 +90,19 @@ export class BroadcastCacheUpdate {
85
90
  async notifyIfUpdated(options: CacheDidUpdateCallbackParam): Promise<void> {
86
91
  if (process.env.NODE_ENV !== "production") {
87
92
  assert!.isType(options.cacheName, "string", {
88
- moduleName: "serwist/plugins",
93
+ moduleName: "serwist",
89
94
  className: "BroadcastCacheUpdate",
90
95
  funcName: "notifyIfUpdated",
91
96
  paramName: "cacheName",
92
97
  });
93
98
  assert!.isInstance(options.newResponse, Response, {
94
- moduleName: "serwist/plugins",
99
+ moduleName: "serwist",
95
100
  className: "BroadcastCacheUpdate",
96
101
  funcName: "notifyIfUpdated",
97
102
  paramName: "newResponse",
98
103
  });
99
104
  assert!.isInstance(options.request, Request, {
100
- moduleName: "serwist/plugins",
105
+ moduleName: "serwist",
101
106
  className: "BroadcastCacheUpdate",
102
107
  funcName: "notifyIfUpdated",
103
108
  paramName: "request",
@@ -115,8 +120,8 @@ export class BroadcastCacheUpdate {
115
120
  }
116
121
 
117
122
  const messageData = {
118
- type: CACHE_UPDATED_MESSAGE_TYPE,
119
- meta: CACHE_UPDATED_MESSAGE_META,
123
+ type: BROADCAST_UPDATE_MESSAGE_TYPE,
124
+ meta: BROADCAST_UPDATE_MESSAGE_META,
120
125
  payload: this._generatePayload(options),
121
126
  } satisfies BroadcastMessage;
122
127
 
@@ -18,7 +18,7 @@ export class BroadcastUpdatePlugin implements SerwistPlugin {
18
18
  private readonly _broadcastUpdate: BroadcastCacheUpdate;
19
19
 
20
20
  /**
21
- * Construct a `serwist/plugins.BroadcastCacheUpdate` instance with
21
+ * Construct a `serwist.BroadcastCacheUpdate` instance with
22
22
  * the passed options and calls its `notifyIfUpdated` method whenever the
23
23
  * plugin's `cacheDidUpdate` callback is invoked.
24
24
  *
@@ -0,0 +1,12 @@
1
+ /*
2
+ Copyright 2018 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
+ export const BROADCAST_UPDATE_MESSAGE_TYPE = "CACHE_UPDATED";
10
+ export const BROADCAST_UPDATE_MESSAGE_META = "serwist-broadcast-update";
11
+ export const BROADCAST_UPDATE_DEFAULT_NOTIFY = true;
12
+ export const BROADCAST_UPDATE_DEFAULT_HEADERS = ["content-length", "etag", "last-modified"];
@@ -1,5 +1,5 @@
1
1
  import type { CacheDidUpdateCallbackParam } from "../../types.js";
2
- import type { CACHE_UPDATED_MESSAGE_META, CACHE_UPDATED_MESSAGE_TYPE } from "./constants.js";
2
+ import type { BROADCAST_UPDATE_MESSAGE_META, BROADCAST_UPDATE_MESSAGE_TYPE } from "./constants.js";
3
3
 
4
4
  export interface BroadcastCacheUpdateOptions {
5
5
  /**
@@ -31,7 +31,7 @@ export type BroadcastPayload = Record<string, any>;
31
31
  export type BroadcastPayloadGenerator = (options: CacheDidUpdateCallbackParam) => BroadcastPayload;
32
32
 
33
33
  export interface BroadcastMessage {
34
- type: typeof CACHE_UPDATED_MESSAGE_TYPE;
35
- meta: typeof CACHE_UPDATED_MESSAGE_META;
34
+ type: typeof BROADCAST_UPDATE_MESSAGE_TYPE;
35
+ meta: typeof BROADCAST_UPDATE_MESSAGE_META;
36
36
  payload: BroadcastPayload;
37
37
  }
@@ -6,8 +6,8 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { assert } from "../../utils/assert.js";
10
9
  import { SerwistError } from "../../utils/SerwistError.js";
10
+ import { assert } from "../../utils/assert.js";
11
11
  import { getFriendlyURL } from "../../utils/getFriendlyURL.js";
12
12
  import { logger } from "../../utils/logger.js";
13
13
 
@@ -45,7 +45,7 @@ export class CacheableResponse {
45
45
  if (process.env.NODE_ENV !== "production") {
46
46
  if (!(config.statuses || config.headers)) {
47
47
  throw new SerwistError("statuses-or-headers-required", {
48
- moduleName: "serwist/plugins",
48
+ moduleName: "serwist",
49
49
  className: "CacheableResponse",
50
50
  funcName: "constructor",
51
51
  });
@@ -53,7 +53,7 @@ export class CacheableResponse {
53
53
 
54
54
  if (config.statuses) {
55
55
  assert!.isArray(config.statuses, {
56
- moduleName: "serwist/plugins",
56
+ moduleName: "serwist",
57
57
  className: "CacheableResponse",
58
58
  funcName: "constructor",
59
59
  paramName: "config.statuses",
@@ -62,7 +62,7 @@ export class CacheableResponse {
62
62
 
63
63
  if (config.headers) {
64
64
  assert!.isType(config.headers, "object", {
65
- moduleName: "serwist/plugins",
65
+ moduleName: "serwist",
66
66
  className: "CacheableResponse",
67
67
  funcName: "constructor",
68
68
  paramName: "config.headers",
@@ -87,7 +87,7 @@ export class CacheableResponse {
87
87
  isResponseCacheable(response: Response): boolean {
88
88
  if (process.env.NODE_ENV !== "production") {
89
89
  assert!.isInstance(response, Response, {
90
- moduleName: "serwist/plugins",
90
+ moduleName: "serwist",
91
91
  className: "CacheableResponse",
92
92
  funcName: "isResponseCacheable",
93
93
  paramName: "response",
@@ -6,8 +6,8 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { assert } from "../../utils/assert.js";
10
9
  import { SerwistError } from "../../utils/SerwistError.js";
10
+ import { assert } from "../../utils/assert.js";
11
11
  import { logger } from "../../utils/logger.js";
12
12
  import { CacheTimestampsModel } from "./models/CacheTimestampsModel.js";
13
13
 
@@ -30,7 +30,7 @@ interface CacheExpirationConfig {
30
30
 
31
31
  /**
32
32
  * Allows you to expires cached responses based on age or maximum number of entries.
33
- * @see https://serwist.pages.dev/docs/expiration/cache-expiration
33
+ * @see https://serwist.pages.dev/docs/serwist/core/cache-expiration
34
34
  */
35
35
  export class CacheExpiration {
36
36
  private _isRunning = false;
@@ -51,7 +51,7 @@ export class CacheExpiration {
51
51
  constructor(cacheName: string, config: CacheExpirationConfig = {}) {
52
52
  if (process.env.NODE_ENV !== "production") {
53
53
  assert!.isType(cacheName, "string", {
54
- moduleName: "serwist/plugins",
54
+ moduleName: "serwist",
55
55
  className: "CacheExpiration",
56
56
  funcName: "constructor",
57
57
  paramName: "cacheName",
@@ -59,7 +59,7 @@ export class CacheExpiration {
59
59
 
60
60
  if (!(config.maxEntries || config.maxAgeSeconds)) {
61
61
  throw new SerwistError("max-entries-or-age-required", {
62
- moduleName: "serwist/plugins",
62
+ moduleName: "serwist",
63
63
  className: "CacheExpiration",
64
64
  funcName: "constructor",
65
65
  });
@@ -67,7 +67,7 @@ export class CacheExpiration {
67
67
 
68
68
  if (config.maxEntries) {
69
69
  assert!.isType(config.maxEntries, "number", {
70
- moduleName: "serwist/plugins",
70
+ moduleName: "serwist",
71
71
  className: "CacheExpiration",
72
72
  funcName: "constructor",
73
73
  paramName: "config.maxEntries",
@@ -76,7 +76,7 @@ export class CacheExpiration {
76
76
 
77
77
  if (config.maxAgeSeconds) {
78
78
  assert!.isType(config.maxAgeSeconds, "number", {
79
- moduleName: "serwist/plugins",
79
+ moduleName: "serwist",
80
80
  className: "CacheExpiration",
81
81
  funcName: "constructor",
82
82
  paramName: "config.maxAgeSeconds",
@@ -145,7 +145,7 @@ export class CacheExpiration {
145
145
  async updateTimestamp(url: string): Promise<void> {
146
146
  if (process.env.NODE_ENV !== "production") {
147
147
  assert!.isType(url, "string", {
148
- moduleName: "serwist/plugins",
148
+ moduleName: "serwist",
149
149
  className: "CacheExpiration",
150
150
  funcName: "updateTimestamp",
151
151
  paramName: "url",
@@ -6,13 +6,13 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import type { CacheDidUpdateCallbackParam, CachedResponseWillBeUsedCallbackParam, SerwistPlugin } from "../../types.js";
10
9
  import { registerQuotaErrorCallback } from "../../registerQuotaErrorCallback.js";
11
- import { assert } from "../../utils/assert.js";
10
+ import type { CacheDidUpdateCallbackParam, CachedResponseWillBeUsedCallbackParam, SerwistPlugin } from "../../types.js";
12
11
  import { SerwistError } from "../../utils/SerwistError.js";
12
+ import { assert } from "../../utils/assert.js";
13
+ import { cacheNames as privateCacheNames } from "../../utils/cacheNames.js";
13
14
  import { getFriendlyURL } from "../../utils/getFriendlyURL.js";
14
15
  import { logger } from "../../utils/logger.js";
15
- import { cacheNames as privateCacheNames } from "../../utils/cacheNames.js";
16
16
  import { CacheExpiration } from "./CacheExpiration.js";
17
17
 
18
18
  export interface ExpirationPluginOptions {
@@ -62,7 +62,7 @@ export interface ExpirationPluginOptions {
62
62
  * When using `maxEntries`, the least recently requested entry will be removed
63
63
  * from the cache.
64
64
  *
65
- * @see https://serwist.pages.dev/docs/expiration/expiration-plugin
65
+ * @see https://serwist.pages.dev/docs/serwist/runtime-caching/plugins/expiration-plugin
66
66
  */
67
67
  export class ExpirationPlugin implements SerwistPlugin {
68
68
  private readonly _config: ExpirationPluginOptions;
@@ -75,7 +75,7 @@ export class ExpirationPlugin implements SerwistPlugin {
75
75
  if (process.env.NODE_ENV !== "production") {
76
76
  if (!(config.maxEntries || config.maxAgeSeconds)) {
77
77
  throw new SerwistError("max-entries-or-age-required", {
78
- moduleName: "serwist/plugins",
78
+ moduleName: "serwist",
79
79
  className: "ExpirationPlugin",
80
80
  funcName: "constructor",
81
81
  });
@@ -83,7 +83,7 @@ export class ExpirationPlugin implements SerwistPlugin {
83
83
 
84
84
  if (config.maxEntries) {
85
85
  assert!.isType(config.maxEntries, "number", {
86
- moduleName: "serwist/plugins",
86
+ moduleName: "serwist",
87
87
  className: "ExpirationPlugin",
88
88
  funcName: "constructor",
89
89
  paramName: "config.maxEntries",
@@ -92,7 +92,7 @@ export class ExpirationPlugin implements SerwistPlugin {
92
92
 
93
93
  if (config.maxAgeSeconds) {
94
94
  assert!.isType(config.maxAgeSeconds, "number", {
95
- moduleName: "serwist/plugins",
95
+ moduleName: "serwist",
96
96
  className: "ExpirationPlugin",
97
97
  funcName: "constructor",
98
98
  paramName: "config.maxAgeSeconds",
@@ -101,7 +101,7 @@ export class ExpirationPlugin implements SerwistPlugin {
101
101
 
102
102
  if (config.maxAgeFrom) {
103
103
  assert!.isType(config.maxAgeFrom, "string", {
104
- moduleName: "serwist/plugins",
104
+ moduleName: "serwist",
105
105
  className: "ExpirationPlugin",
106
106
  funcName: "constructor",
107
107
  paramName: "config.maxAgeFrom",
@@ -256,13 +256,13 @@ export class ExpirationPlugin implements SerwistPlugin {
256
256
  async cacheDidUpdate({ cacheName, request }: CacheDidUpdateCallbackParam) {
257
257
  if (process.env.NODE_ENV !== "production") {
258
258
  assert!.isType(cacheName, "string", {
259
- moduleName: "serwist/plugins",
259
+ moduleName: "serwist",
260
260
  className: "Plugin",
261
261
  funcName: "cacheDidUpdate",
262
262
  paramName: "cacheName",
263
263
  });
264
264
  assert!.isInstance(request, Request, {
265
- moduleName: "serwist/plugins",
265
+ moduleName: "serwist",
266
266
  className: "Plugin",
267
267
  funcName: "cacheDidUpdate",
268
268
  paramName: "request",
@@ -0,0 +1,22 @@
1
+ /*
2
+ Copyright 2018 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
+ export const QUEUE_NAME = "serwist-google-analytics";
10
+ export const MAX_RETENTION_TIME = 60 * 48; // Two days in minutes
11
+ export const GOOGLE_ANALYTICS_HOST = "www.google-analytics.com";
12
+ export const GTM_HOST = "www.googletagmanager.com";
13
+ export const ANALYTICS_JS_PATH = "/analytics.js";
14
+ export const GTAG_JS_PATH = "/gtag/js";
15
+ export const GTM_JS_PATH = "/gtm.js";
16
+ export const COLLECT_DEFAULT_PATH = "/collect";
17
+
18
+ // This RegExp matches all known Measurement Protocol single-hit collect
19
+ // endpoints. Most of the time the default path (/collect) is used, but
20
+ // occasionally an experimental endpoint is used when testing new features,
21
+ // (e.g. /r/collect or /j/collect)
22
+ export const COLLECT_PATHS_REGEX = /^\/(\w+\/)?collect/;
@@ -6,15 +6,16 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
+ import { Route } from "../../Route.js";
10
+ import type { Serwist } from "../../Serwist.js";
11
+ import { NetworkFirst } from "../../lib/strategies/NetworkFirst.js";
12
+ import { NetworkOnly } from "../../lib/strategies/NetworkOnly.js";
9
13
  import type { RouteMatchCallbackOptions } from "../../types.js";
14
+ import { cacheNames as privateCacheNames } from "../../utils/cacheNames.js";
10
15
  import { getFriendlyURL } from "../../utils/getFriendlyURL.js";
11
16
  import { logger } from "../../utils/logger.js";
12
- import { cacheNames as privateCacheNames } from "../../utils/cacheNames.js";
13
- import { Route } from "../../Route.js";
14
- import { NetworkFirst } from "../../strategies/NetworkFirst.js";
15
- import { NetworkOnly } from "../../strategies/NetworkOnly.js";
16
17
  import { BackgroundSyncPlugin } from "../backgroundSync/BackgroundSyncPlugin.js";
17
- import type { Queue, QueueEntry } from "../backgroundSync/Queue.js";
18
+ import type { BackgroundSyncQueue, BackgroundSyncQueueEntry } from "../backgroundSync/BackgroundSyncQueue.js";
18
19
  import {
19
20
  ANALYTICS_JS_PATH,
20
21
  COLLECT_PATHS_REGEX,
@@ -25,7 +26,6 @@ import {
25
26
  MAX_RETENTION_TIME,
26
27
  QUEUE_NAME,
27
28
  } from "./constants.js";
28
- import type { Serwist } from "../../Serwist.js";
29
29
 
30
30
  export interface GoogleAnalyticsInitializeOptions {
31
31
  serwist: Serwist;
@@ -59,8 +59,8 @@ export interface GoogleAnalyticsInitializeOptions {
59
59
  * @private
60
60
  */
61
61
  const createOnSyncCallback = (config: Pick<GoogleAnalyticsInitializeOptions, "parameterOverrides" | "hitFilter">) => {
62
- return async ({ queue }: { queue: Queue }) => {
63
- let entry: QueueEntry | undefined = undefined;
62
+ return async ({ queue }: { queue: BackgroundSyncQueue }) => {
63
+ let entry: BackgroundSyncQueueEntry | undefined = undefined;
64
64
  while ((entry = await queue.shiftRequest())) {
65
65
  const { request, timestamp } = entry;
66
66
  const url = new URL(request.url);
@@ -188,7 +188,7 @@ const createGtmJsRoute = (cacheName: string) => {
188
188
  *
189
189
  * @param options
190
190
  */
191
- export const initialize = ({ serwist, cacheName, ...options }: GoogleAnalyticsInitializeOptions): void => {
191
+ export const initializeGoogleAnalytics = ({ serwist, cacheName, ...options }: GoogleAnalyticsInitializeOptions): void => {
192
192
  const resolvedCacheName = privateCacheNames.getGoogleAnalyticsName(cacheName);
193
193
 
194
194
  const bgSyncPlugin = new BackgroundSyncPlugin(QUEUE_NAME, {
@@ -6,9 +6,9 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { assert } from "../utils/assert.js";
10
- import { SerwistError } from "../utils/SerwistError.js";
11
- import { logger } from "../utils/logger.js";
9
+ import { SerwistError } from "../../utils/SerwistError.js";
10
+ import { assert } from "../../utils/assert.js";
11
+ import { logger } from "../../utils/logger.js";
12
12
  import { Strategy } from "./Strategy.js";
13
13
  import type { StrategyHandler } from "./StrategyHandler.js";
14
14
  import { messages } from "./utils/messages.js";
@@ -18,7 +18,7 @@ import { messages } from "./utils/messages.js";
18
18
  * request strategy.
19
19
  *
20
20
  * A cache first strategy is useful for assets that have been revisioned,
21
- * such as URLs like `/styles/example.a8f5f1.css`, since they
21
+ * such as URLs like "/styles/example.a8f5f1.css", since they
22
22
  * can be cached for long periods of time.
23
23
  *
24
24
  * If the network request fails, and there is no cache match, this will throw
@@ -36,7 +36,7 @@ export class CacheFirst extends Strategy {
36
36
 
37
37
  if (process.env.NODE_ENV !== "production") {
38
38
  assert!.isInstance(request, Request, {
39
- moduleName: "serwist/strategies",
39
+ moduleName: "serwist",
40
40
  className: this.constructor.name,
41
41
  funcName: "makeRequest",
42
42
  paramName: "request",
@@ -6,18 +6,18 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { assert } from "../utils/assert.js";
10
- import { SerwistError } from "../utils/SerwistError.js";
11
- import { logger } from "../utils/logger.js";
9
+ import { SerwistError } from "../../utils/SerwistError.js";
10
+ import { assert } from "../../utils/assert.js";
11
+ import { logger } from "../../utils/logger.js";
12
12
  import { Strategy } from "./Strategy.js";
13
13
  import type { StrategyHandler } from "./StrategyHandler.js";
14
14
  import { messages } from "./utils/messages.js";
15
15
 
16
16
  /**
17
- * An implementation of the [cache only](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#cache-only)
17
+ * An implementation of the [cache only](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#cache_only)
18
18
  * request strategy.
19
19
  *
20
- * This class is useful if you want to take advantage of any Serwist plugin.
20
+ * This class is useful if you already have your own precaching step.
21
21
  *
22
22
  * If there is no cache match, this will throw a `SerwistError` exception.
23
23
  */
@@ -31,7 +31,7 @@ export class CacheOnly extends Strategy {
31
31
  async _handle(request: Request, handler: StrategyHandler): Promise<Response> {
32
32
  if (process.env.NODE_ENV !== "production") {
33
33
  assert!.isInstance(request, Request, {
34
- moduleName: "serwist/strategies",
34
+ moduleName: "serwist",
35
35
  className: this.constructor.name,
36
36
  funcName: "makeRequest",
37
37
  paramName: "request",