jekyll-pwa-workbox 0.0.6 → 0.0.7.alpha

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 (125) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jekyll-pwa-workbox.rb +1 -1
  3. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-background-sync.dev.js +819 -0
  4. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-background-sync.dev.js.map +1 -0
  5. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-background-sync.prod.js +2 -0
  6. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-background-sync.prod.js.map +1 -0
  7. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.dev.js +486 -0
  8. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.dev.js.map +1 -0
  9. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.prod.js +2 -0
  10. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.prod.js.map +1 -0
  11. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-cacheable-response.dev.js +192 -0
  12. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-cacheable-response.dev.js.map +1 -0
  13. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-cacheable-response.prod.js +2 -0
  14. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-cacheable-response.prod.js.map +1 -0
  15. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-core.dev.js +1643 -0
  16. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-core.dev.js.map +1 -0
  17. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-core.prod.js +2 -0
  18. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-core.prod.js.map +1 -0
  19. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-expiration.dev.js +652 -0
  20. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-expiration.dev.js.map +1 -0
  21. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-expiration.prod.js +2 -0
  22. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-expiration.prod.js.map +1 -0
  23. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-navigation-preload.dev.js +103 -0
  24. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-navigation-preload.dev.js.map +1 -0
  25. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-navigation-preload.prod.js +2 -0
  26. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-navigation-preload.prod.js.map +1 -0
  27. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-offline-ga.dev.js +236 -0
  28. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-offline-ga.dev.js.map +1 -0
  29. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-offline-ga.prod.js +2 -0
  30. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-offline-ga.prod.js.map +1 -0
  31. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-precaching.dev.js +994 -0
  32. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-precaching.dev.js.map +1 -0
  33. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-precaching.prod.js +2 -0
  34. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-precaching.prod.js.map +1 -0
  35. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-range-requests.dev.js +263 -0
  36. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-range-requests.dev.js.map +1 -0
  37. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-range-requests.prod.js +2 -0
  38. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-range-requests.prod.js.map +1 -0
  39. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-routing.dev.js +1026 -0
  40. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-routing.dev.js.map +1 -0
  41. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-routing.prod.js +2 -0
  42. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-routing.prod.js.map +1 -0
  43. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-strategies.dev.js +1127 -0
  44. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-strategies.dev.js.map +1 -0
  45. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-strategies.prod.js +2 -0
  46. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-strategies.prod.js.map +1 -0
  47. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-streams.dev.js +333 -0
  48. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-streams.dev.js.map +1 -0
  49. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-streams.prod.js +2 -0
  50. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-streams.prod.js.map +1 -0
  51. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-sw.js +2 -0
  52. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-sw.js.map +1 -0
  53. data/lib/vendor/{workbox-v4.3.1 → workbox-v5.0.0.alpha1}/workbox-window.dev.es5.mjs +248 -262
  54. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.dev.es5.mjs.map +1 -0
  55. data/lib/vendor/{workbox-v4.3.1 → workbox-v5.0.0.alpha1}/workbox-window.dev.mjs +234 -242
  56. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.dev.mjs.map +1 -0
  57. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.dev.umd.js +882 -0
  58. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.dev.umd.js.map +1 -0
  59. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.es5.mjs +2 -0
  60. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.es5.mjs.map +1 -0
  61. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.mjs +2 -0
  62. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.mjs.map +1 -0
  63. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.umd.js +2 -0
  64. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.umd.js.map +1 -0
  65. metadata +75 -80
  66. data/lib/vendor/workbox-v4.3.1/workbox-background-sync.dev.js +0 -822
  67. data/lib/vendor/workbox-v4.3.1/workbox-background-sync.dev.js.map +0 -1
  68. data/lib/vendor/workbox-v4.3.1/workbox-background-sync.prod.js +0 -2
  69. data/lib/vendor/workbox-v4.3.1/workbox-background-sync.prod.js.map +0 -1
  70. data/lib/vendor/workbox-v4.3.1/workbox-broadcast-update.dev.js +0 -496
  71. data/lib/vendor/workbox-v4.3.1/workbox-broadcast-update.dev.js.map +0 -1
  72. data/lib/vendor/workbox-v4.3.1/workbox-broadcast-update.prod.js +0 -2
  73. data/lib/vendor/workbox-v4.3.1/workbox-broadcast-update.prod.js.map +0 -1
  74. data/lib/vendor/workbox-v4.3.1/workbox-cacheable-response.dev.js +0 -200
  75. data/lib/vendor/workbox-v4.3.1/workbox-cacheable-response.dev.js.map +0 -1
  76. data/lib/vendor/workbox-v4.3.1/workbox-cacheable-response.prod.js +0 -2
  77. data/lib/vendor/workbox-v4.3.1/workbox-cacheable-response.prod.js.map +0 -1
  78. data/lib/vendor/workbox-v4.3.1/workbox-core.dev.js +0 -1712
  79. data/lib/vendor/workbox-v4.3.1/workbox-core.dev.js.map +0 -1
  80. data/lib/vendor/workbox-v4.3.1/workbox-core.prod.js +0 -2
  81. data/lib/vendor/workbox-v4.3.1/workbox-core.prod.js.map +0 -1
  82. data/lib/vendor/workbox-v4.3.1/workbox-expiration.dev.js +0 -652
  83. data/lib/vendor/workbox-v4.3.1/workbox-expiration.dev.js.map +0 -1
  84. data/lib/vendor/workbox-v4.3.1/workbox-expiration.prod.js +0 -2
  85. data/lib/vendor/workbox-v4.3.1/workbox-expiration.prod.js.map +0 -1
  86. data/lib/vendor/workbox-v4.3.1/workbox-navigation-preload.dev.js +0 -110
  87. data/lib/vendor/workbox-v4.3.1/workbox-navigation-preload.dev.js.map +0 -1
  88. data/lib/vendor/workbox-v4.3.1/workbox-navigation-preload.prod.js +0 -2
  89. data/lib/vendor/workbox-v4.3.1/workbox-navigation-preload.prod.js.map +0 -1
  90. data/lib/vendor/workbox-v4.3.1/workbox-offline-ga.dev.js +0 -243
  91. data/lib/vendor/workbox-v4.3.1/workbox-offline-ga.dev.js.map +0 -1
  92. data/lib/vendor/workbox-v4.3.1/workbox-offline-ga.prod.js +0 -2
  93. data/lib/vendor/workbox-v4.3.1/workbox-offline-ga.prod.js.map +0 -1
  94. data/lib/vendor/workbox-v4.3.1/workbox-precaching.dev.js +0 -989
  95. data/lib/vendor/workbox-v4.3.1/workbox-precaching.dev.js.map +0 -1
  96. data/lib/vendor/workbox-v4.3.1/workbox-precaching.prod.js +0 -2
  97. data/lib/vendor/workbox-v4.3.1/workbox-precaching.prod.js.map +0 -1
  98. data/lib/vendor/workbox-v4.3.1/workbox-range-requests.dev.js +0 -268
  99. data/lib/vendor/workbox-v4.3.1/workbox-range-requests.dev.js.map +0 -1
  100. data/lib/vendor/workbox-v4.3.1/workbox-range-requests.prod.js +0 -2
  101. data/lib/vendor/workbox-v4.3.1/workbox-range-requests.prod.js.map +0 -1
  102. data/lib/vendor/workbox-v4.3.1/workbox-routing.dev.js +0 -1020
  103. data/lib/vendor/workbox-v4.3.1/workbox-routing.dev.js.map +0 -1
  104. data/lib/vendor/workbox-v4.3.1/workbox-routing.prod.js +0 -2
  105. data/lib/vendor/workbox-v4.3.1/workbox-routing.prod.js.map +0 -1
  106. data/lib/vendor/workbox-v4.3.1/workbox-strategies.dev.js +0 -1138
  107. data/lib/vendor/workbox-v4.3.1/workbox-strategies.dev.js.map +0 -1
  108. data/lib/vendor/workbox-v4.3.1/workbox-strategies.prod.js +0 -2
  109. data/lib/vendor/workbox-v4.3.1/workbox-strategies.prod.js.map +0 -1
  110. data/lib/vendor/workbox-v4.3.1/workbox-streams.dev.js +0 -337
  111. data/lib/vendor/workbox-v4.3.1/workbox-streams.dev.js.map +0 -1
  112. data/lib/vendor/workbox-v4.3.1/workbox-streams.prod.js +0 -2
  113. data/lib/vendor/workbox-v4.3.1/workbox-streams.prod.js.map +0 -1
  114. data/lib/vendor/workbox-v4.3.1/workbox-sw.js +0 -2
  115. data/lib/vendor/workbox-v4.3.1/workbox-sw.js.map +0 -1
  116. data/lib/vendor/workbox-v4.3.1/workbox-window.dev.es5.mjs.map +0 -1
  117. data/lib/vendor/workbox-v4.3.1/workbox-window.dev.mjs.map +0 -1
  118. data/lib/vendor/workbox-v4.3.1/workbox-window.dev.umd.js +0 -896
  119. data/lib/vendor/workbox-v4.3.1/workbox-window.dev.umd.js.map +0 -1
  120. data/lib/vendor/workbox-v4.3.1/workbox-window.prod.es5.mjs +0 -2
  121. data/lib/vendor/workbox-v4.3.1/workbox-window.prod.es5.mjs.map +0 -1
  122. data/lib/vendor/workbox-v4.3.1/workbox-window.prod.mjs +0 -2
  123. data/lib/vendor/workbox-v4.3.1/workbox-window.prod.mjs.map +0 -1
  124. data/lib/vendor/workbox-v4.3.1/workbox-window.prod.umd.js +0 -2
  125. data/lib/vendor/workbox-v4.3.1/workbox-window.prod.umd.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workbox-broadcast-update.dev.js","sources":["../_version.js","../responsesAreSame.js","../utils/constants.js","../broadcastUpdate.js","../BroadcastCacheUpdate.js","../Plugin.js"],"sourcesContent":["// @ts-ignore\ntry {\n self['workbox:broadcast-update:5.0.0-alpha.0'] && _();\n}\ncatch (e) { }\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport './_version.js';\n/**\n * Given two `Response's`, compares several header values to see if they are\n * the same or not.\n *\n * @param {Response} firstResponse\n * @param {Response} secondResponse\n * @param {Array<string>} headersToCheck\n * @return {boolean}\n *\n * @memberof workbox.broadcastUpdate\n * @private\n */\nconst responsesAreSame = (firstResponse, secondResponse, headersToCheck) => {\n if (process.env.NODE_ENV !== 'production') {\n if (!(firstResponse instanceof Response &&\n secondResponse instanceof Response)) {\n throw new WorkboxError('invalid-responses-are-same-args');\n }\n }\n const atLeastOneHeaderAvailable = headersToCheck.some((header) => {\n return firstResponse.headers.has(header) &&\n secondResponse.headers.has(header);\n });\n if (!atLeastOneHeaderAvailable) {\n if (process.env.NODE_ENV !== 'production') {\n logger.warn(`Unable to determine where the response has been updated ` +\n `because none of the headers that would be checked are present.`);\n logger.debug(`Attempting to compare the following: `, firstResponse, secondResponse, headersToCheck);\n }\n // Just return true, indicating the that responses are the same, since we\n // can't determine otherwise.\n return true;\n }\n return headersToCheck.every((header) => {\n const headerStateComparison = firstResponse.headers.has(header) ===\n secondResponse.headers.has(header);\n const headerValueComparison = firstResponse.headers.get(header) ===\n secondResponse.headers.get(header);\n return headerStateComparison && headerValueComparison;\n });\n};\nexport { responsesAreSame };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport '../_version.js';\nexport const CACHE_UPDATED_MESSAGE_TYPE = 'CACHE_UPDATED';\nexport const CACHE_UPDATED_MESSAGE_META = 'workbox-broadcast-update';\nexport const DEFAULT_BROADCAST_CHANNEL_NAME = 'workbox';\nexport const DEFAULT_DEFER_NOTIFICATION_TIMEOUT = 10000;\nexport const DEFAULT_HEADERS_TO_CHECK = [\n 'content-length',\n 'etag',\n 'last-modified',\n];\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { CACHE_UPDATED_MESSAGE_TYPE, CACHE_UPDATED_MESSAGE_META } from './utils/constants.js';\nimport './_version.js';\n/**\n * You would not normally call this method directly; it's called automatically\n * by an instance of the {@link BroadcastCacheUpdate} class. It's exposed here\n * for the benefit of developers who would rather not use the full\n * `BroadcastCacheUpdate` implementation.\n *\n * Calling this will dispatch a message on the provided\n * {@link https://developers.google.com/web/updates/2016/09/broadcastchannel|Broadcast Channel}\n * to notify interested subscribers about a change to a cached resource.\n *\n * The message that's posted has a formation inspired by the\n * [Flux standard action](https://github.com/acdlite/flux-standard-action#introduction)\n * format like so:\n *\n * ```\n * {\n * type: 'CACHE_UPDATED',\n * meta: 'workbox-broadcast-update',\n * payload: {\n * cacheName: 'the-cache-name',\n * updatedURL: 'https://example.com/'\n * }\n * }\n * ```\n *\n * (Usage of [Flux](https://facebook.github.io/flux/) itself is not at\n * all required.)\n *\n * @param {Object} options\n * @param {string} options.cacheName The name of the cache in which the updated\n * `Response` was stored.\n * @param {string} options.url The URL associated with the updated `Response`.\n * @param {BroadcastChannel} [options.channel] The `BroadcastChannel` to use.\n * If no channel is set or the browser doesn't support the BroadcastChannel\n * api, then an attempt will be made to `postMessage` each window client.\n *\n * @memberof workbox.broadcastUpdate\n */\nconst broadcastUpdate = async ({ channel, cacheName, url }) => {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(cacheName, 'string', {\n moduleName: 'workbox-broadcast-update',\n className: '~',\n funcName: 'broadcastUpdate',\n paramName: 'cacheName',\n });\n assert.isType(url, 'string', {\n moduleName: 'workbox-broadcast-update',\n className: '~',\n funcName: 'broadcastUpdate',\n paramName: 'url',\n });\n }\n const data = {\n type: CACHE_UPDATED_MESSAGE_TYPE,\n meta: CACHE_UPDATED_MESSAGE_META,\n payload: {\n cacheName: cacheName,\n updatedURL: url,\n },\n };\n if (channel) {\n channel.postMessage(data);\n }\n else {\n const windows = await self.clients.matchAll({ type: 'window' });\n for (const win of windows) {\n win.postMessage(data);\n }\n }\n};\nexport { broadcastUpdate };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { getFriendlyURL } from 'workbox-core/_private/getFriendlyURL.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { Deferred } from 'workbox-core/_private/Deferred.js';\nimport { responsesAreSame } from './responsesAreSame.js';\nimport { broadcastUpdate } from './broadcastUpdate.js';\nimport { DEFAULT_HEADERS_TO_CHECK, DEFAULT_BROADCAST_CHANNEL_NAME, DEFAULT_DEFER_NOTIFICATION_TIMEOUT } from './utils/constants.js';\nimport './_version.js';\n/**\n * Uses the [Broadcast Channel API]{@link https://developers.google.com/web/updates/2016/09/broadcastchannel}\n * to notify interested parties when a cached response has been updated.\n * In browsers that do not support the Broadcast Channel API, the instance\n * falls back to sending the update via `postMessage()` to all window clients.\n *\n * For efficiency's sake, the underlying response bodies are not compared;\n * only specific response headers are checked.\n *\n * @memberof workbox.broadcastUpdate\n */\nclass BroadcastCacheUpdate {\n /**\n * Construct a BroadcastCacheUpdate instance with a specific `channelName` to\n * broadcast messages on\n *\n * @param {Object} options\n * @param {Array<string>}\n * [options.headersToCheck=['content-length', 'etag', 'last-modified']]\n * A list of headers that will be used to determine whether the responses\n * differ.\n * @param {string} [options.channelName='workbox'] The name that will be used\n *. when creating the `BroadcastChannel`, which defaults to 'workbox' (the\n * channel name used by the `workbox-window` package).\n * @param {string} [options.deferNoticationTimeout=10000] The amount of time\n * to wait for a ready message from the window on navigation requests\n * before sending the update.\n */\n constructor({ headersToCheck, channelName, deferNoticationTimeout, } = {}) {\n this._headersToCheck = headersToCheck || DEFAULT_HEADERS_TO_CHECK;\n this._channelName = channelName || DEFAULT_BROADCAST_CHANNEL_NAME;\n this._deferNoticationTimeout =\n deferNoticationTimeout || DEFAULT_DEFER_NOTIFICATION_TIMEOUT;\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(this._channelName, 'string', {\n moduleName: 'workbox-broadcast-update',\n className: 'BroadcastCacheUpdate',\n funcName: 'constructor',\n paramName: 'channelName',\n });\n assert.isArray(this._headersToCheck, {\n moduleName: 'workbox-broadcast-update',\n className: 'BroadcastCacheUpdate',\n funcName: 'constructor',\n paramName: 'headersToCheck',\n });\n }\n this._initWindowReadyDeferreds();\n }\n /**\n * Compare two [Responses](https://developer.mozilla.org/en-US/docs/Web/API/Response)\n * and send a message via the\n * {@link https://developers.google.com/web/updates/2016/09/broadcastchannel|Broadcast Channel API}\n * if they differ.\n *\n * Neither of the Responses can be {@link http://stackoverflow.com/questions/39109789|opaque}.\n *\n * @param {Object} options\n * @param {Response} options.oldResponse Cached response to compare.\n * @param {Response} options.newResponse Possibly updated response to compare.\n * @param {string} options.url The URL of the request.\n * @param {string} options.cacheName Name of the cache the responses belong\n * to. This is included in the broadcast message.\n * @param {Event} [options.event] event An optional event that triggered\n * this possible cache update.\n * @return {Promise} Resolves once the update is sent.\n */\n notifyIfUpdated({ oldResponse, newResponse, url, cacheName, event }) {\n if (!responsesAreSame(oldResponse, newResponse, this._headersToCheck)) {\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`Newer response found (and cached) for:`, url);\n }\n const sendUpdate = async () => {\n // In the case of a navigation request, the requesting page will likely\n // not have loaded its JavaScript in time to recevied the update\n // notification, so we defer it until ready (or we timeout waiting).\n if (event && event.request && event.request.mode === 'navigate') {\n if (process.env.NODE_ENV !== 'production') {\n logger.debug(`Original request was a navigation request, ` +\n `waiting for a ready message from the window`, event.request);\n }\n await this._windowReadyOrTimeout(event);\n }\n await this._broadcastUpdate({\n channel: this._getChannel(),\n cacheName,\n url,\n });\n };\n // Send the update and ensure the SW stays alive until it's sent.\n const done = sendUpdate();\n if (event) {\n try {\n event.waitUntil(done);\n }\n catch (error) {\n if (process.env.NODE_ENV !== 'production') {\n logger.warn(`Unable to ensure service worker stays alive ` +\n `when broadcasting cache update for ` +\n `${getFriendlyURL(event.request.url)}'.`);\n }\n }\n }\n return done;\n }\n }\n /**\n * NOTE: this is exposed on the instance primarily so it can be spied on\n * in tests.\n *\n * @param {Object} opts\n * @private\n */\n async _broadcastUpdate(opts) {\n await broadcastUpdate(opts);\n }\n /**\n * @return {BroadcastChannel|undefined} The BroadcastChannel instance used for\n * broadcasting updates, or undefined if the browser doesn't support the\n * Broadcast Channel API.\n *\n * @private\n */\n _getChannel() {\n if (('BroadcastChannel' in self) && !this._channel) {\n this._channel = new BroadcastChannel(this._channelName);\n }\n return this._channel;\n }\n /**\n * Waits for a message from the window indicating that it's capable of\n * receiving broadcasts. By default, this will only wait for the amount of\n * time specified via the `deferNoticationTimeout` option.\n *\n * @param {Event} event The navigation fetch event.\n * @return {Promise}\n * @private\n */\n _windowReadyOrTimeout(event) {\n if (!this._navigationEventsDeferreds.has(event)) {\n const deferred = new Deferred();\n // Set the deferred on the `_navigationEventsDeferreds` map so it will\n // be resolved when the next ready message event comes.\n this._navigationEventsDeferreds.set(event, deferred);\n // But don't wait too long for the message since it may never come.\n const timeout = setTimeout(() => {\n if (process.env.NODE_ENV !== 'production') {\n logger.debug(`Timed out after ${this._deferNoticationTimeout}` +\n `ms waiting for message from window`);\n }\n deferred.resolve();\n }, this._deferNoticationTimeout);\n // Ensure the timeout is cleared if the deferred promise is resolved.\n deferred.promise.then(() => clearTimeout(timeout));\n }\n return this._navigationEventsDeferreds.get(event).promise;\n }\n /**\n * Creates a mapping between navigation fetch events and deferreds, and adds\n * a listener for message events from the window. When message events arrive,\n * all deferreds in the mapping are resolved.\n *\n * Note: it would be easier if we could only resolve the deferred of\n * navigation fetch event whose client ID matched the source ID of the\n * message event, but currently client IDs are not exposed on navigation\n * fetch events: https://www.chromestatus.com/feature/4846038800138240\n *\n * @private\n */\n _initWindowReadyDeferreds() {\n // A mapping between navigation events and their deferreds.\n this._navigationEventsDeferreds = new Map();\n // The message listener needs to be added in the initial run of the\n // service worker, but since we don't actually need to be listening for\n // messages until the cache updates, we only invoke the callback if set.\n self.addEventListener('message', (event) => {\n if (event.data.type === 'WINDOW_READY' &&\n event.data.meta === 'workbox-window' &&\n this._navigationEventsDeferreds.size > 0) {\n if (process.env.NODE_ENV !== 'production') {\n logger.debug(`Received WINDOW_READY event: `, event);\n }\n // Resolve any pending deferreds.\n for (const deferred of this._navigationEventsDeferreds.values()) {\n deferred.resolve();\n }\n this._navigationEventsDeferreds.clear();\n }\n });\n }\n}\nexport { BroadcastCacheUpdate };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { BroadcastCacheUpdate } from './BroadcastCacheUpdate.js';\nimport './_version.js';\n/**\n * This plugin will automatically broadcast a message whenever a cached response\n * is updated.\n *\n * @memberof workbox.broadcastUpdate\n */\nclass Plugin {\n /**\n * Construct a BroadcastCacheUpdate instance with the passed options and\n * calls its `notifyIfUpdated()` method whenever the plugin's\n * `cacheDidUpdate` callback is invoked.\n *\n * @param {Object} options\n * @param {Array<string>}\n * [options.headersToCheck=['content-length', 'etag', 'last-modified']]\n * A list of headers that will be used to determine whether the responses\n * differ.\n * @param {string} [options.channelName='workbox'] The name that will be used\n *. when creating the `BroadcastChannel`, which defaults to 'workbox' (the\n * channel name used by the `workbox-window` package).\n * @param {string} [options.deferNoticationTimeout=10000] The amount of time\n * to wait for a ready message from the window on navigation requests\n * before sending the update.\n */\n constructor(options) {\n /**\n * A \"lifecycle\" callback that will be triggered automatically by the\n * `workbox-sw` and `workbox-runtime-caching` handlers when an entry is\n * added to a cache.\n *\n * @private\n * @param {Object} options The input object to this function.\n * @param {string} options.cacheName Name of the cache being updated.\n * @param {Response} [options.oldResponse] The previous cached value, if any.\n * @param {Response} options.newResponse The new value in the cache.\n * @param {Request} options.request The request that triggered the udpate.\n * @param {Request} [options.event] The event that triggered the update.\n */\n this.cacheDidUpdate = async ({ cacheName, oldResponse, newResponse, request, event }) => {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(cacheName, 'string', {\n moduleName: 'workbox-broadcast-update',\n className: 'Plugin',\n funcName: 'cacheDidUpdate',\n paramName: 'cacheName',\n });\n assert.isInstance(newResponse, Response, {\n moduleName: 'workbox-broadcast-update',\n className: 'Plugin',\n funcName: 'cacheDidUpdate',\n paramName: 'newResponse',\n });\n assert.isInstance(request, Request, {\n moduleName: 'workbox-broadcast-update',\n className: 'Plugin',\n funcName: 'cacheDidUpdate',\n paramName: 'request',\n });\n }\n // Without a two responses there is nothing to compare.\n if (oldResponse) {\n this._broadcastUpdate.notifyIfUpdated({\n cacheName,\n oldResponse,\n newResponse,\n event,\n url: request.url,\n });\n }\n };\n this._broadcastUpdate = new BroadcastCacheUpdate(options);\n }\n}\nexport { Plugin };\n"],"names":["self","_","e","responsesAreSame","firstResponse","secondResponse","headersToCheck","Response","WorkboxError","atLeastOneHeaderAvailable","some","header","headers","has","logger","warn","debug","every","headerStateComparison","headerValueComparison","get","CACHE_UPDATED_MESSAGE_TYPE","CACHE_UPDATED_MESSAGE_META","DEFAULT_BROADCAST_CHANNEL_NAME","DEFAULT_DEFER_NOTIFICATION_TIMEOUT","DEFAULT_HEADERS_TO_CHECK","broadcastUpdate","channel","cacheName","url","assert","isType","moduleName","className","funcName","paramName","data","type","meta","payload","updatedURL","postMessage","windows","clients","matchAll","win","BroadcastCacheUpdate","constructor","channelName","deferNoticationTimeout","_headersToCheck","_channelName","_deferNoticationTimeout","isArray","_initWindowReadyDeferreds","notifyIfUpdated","oldResponse","newResponse","event","log","sendUpdate","request","mode","_windowReadyOrTimeout","_broadcastUpdate","_getChannel","done","waitUntil","error","getFriendlyURL","opts","_channel","BroadcastChannel","_navigationEventsDeferreds","deferred","Deferred","set","timeout","setTimeout","resolve","promise","then","clearTimeout","Map","addEventListener","size","values","clear","Plugin","options","cacheDidUpdate","isInstance","Request"],"mappings":";;;;IAAA;IACA,IAAI;IACAA,EAAAA,IAAI,CAAC,wCAAD,CAAJ,IAAkDC,CAAC,EAAnD;IACH,CAFD,CAGA,OAAOC,CAAP,EAAU;;ICJV;;;;;;;AAOA,IAGA;;;;;;;;;;;;;AAYA,UAAMC,g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AEgC,OAAO,CAAChC;IALqB,SAAtC;IAOH;IACJ,KA/BD;;IAgCA,SAAKmC,gBAAL,GAAwB,IAAIlB,oBAAJ,CAAyB2C,OAAzB,CAAxB;IACH;;IAjEQ;;;;;;;;;;;;;"}
@@ -0,0 +1,2 @@
1
+ this.workbox=this.workbox||{},this.workbox.broadcastUpdate=function(e,t){"use strict";try{self["workbox:broadcast-update:5.0.0-alpha.0"]&&_()}catch(e){}const s=(e,t,s)=>{return!s.some(s=>e.headers.has(s)&&t.headers.has(s))||s.every(s=>{const n=e.headers.has(s)===t.headers.has(s),a=e.headers.get(s)===t.headers.get(s);return n&&a})},n="workbox",a=1e4,i=["content-length","etag","last-modified"],o=async({channel:e,cacheName:t,url:s})=>{const n={type:"CACHE_UPDATED",meta:"workbox-broadcast-update",payload:{cacheName:t,updatedURL:s}};if(e)e.postMessage(n);else{const e=await self.clients.matchAll({type:"window"});for(const t of e)t.postMessage(n)}};class c{constructor({headersToCheck:e,channelName:t,deferNoticationTimeout:s}={}){this.t=e||i,this.s=t||n,this.i=s||a,this.o()}notifyIfUpdated({oldResponse:e,newResponse:t,url:n,cacheName:a,event:i}){if(!s(e,t,this.t)){const e=(async()=>{i&&i.request&&"navigate"===i.request.mode&&await this.h(i),await this.l({channel:this.u(),cacheName:a,url:n})})();if(i)try{i.waitUntil(e)}catch(e){}return e}}async l(e){await o(e)}u(){return"BroadcastChannel"in self&&!this.m&&(this.m=new BroadcastChannel(this.s)),this.m}h(e){if(!this.p.has(e)){const s=new t.Deferred;this.p.set(e,s);const n=setTimeout(()=>{s.resolve()},this.i);s.promise.then(()=>clearTimeout(n))}return this.p.get(e).promise}o(){this.p=new Map,self.addEventListener("message",e=>{if("WINDOW_READY"===e.data.type&&"workbox-window"===e.data.meta&&this.p.size>0){for(const e of this.p.values())e.resolve();this.p.clear()}})}}return e.BroadcastCacheUpdate=c,e.Plugin=class{constructor(e){this.cacheDidUpdate=(async({cacheName:e,oldResponse:t,newResponse:s,request:n,event:a})=>{t&&this.l.notifyIfUpdated({cacheName:e,oldResponse:t,newResponse:s,event:a,url:n.url})}),this.l=new c(e)}},e.broadcastUpdate=o,e.responsesAreSame=s,e}({},workbox.core._private);
2
+ //# sourceMappingURL=workbox-broadcast-update.prod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workbox-broadcast-update.prod.js","sources":["../_version.js","../responsesAreSame.js","../utils/constants.js","../broadcastUpdate.js","../BroadcastCacheUpdate.js","../Plugin.js"],"sourcesContent":["// @ts-ignore\ntry {\n self['workbox:broadcast-update:5.0.0-alpha.0'] && _();\n}\ncatch (e) { }\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport './_version.js';\n/**\n * Given two `Response's`, compares several header values to see if they are\n * the same or not.\n *\n * @param {Response} firstResponse\n * @param {Response} secondResponse\n * @param {Array<string>} headersToCheck\n * @return {boolean}\n *\n * @memberof workbox.broadcastUpdate\n * @private\n */\nconst responsesAreSame = (firstResponse, secondResponse, headersToCheck) => {\n if (process.env.NODE_ENV !== 'production') {\n if (!(firstResponse instanceof Response &&\n secondResponse instanceof Response)) {\n throw new WorkboxError('invalid-responses-are-same-args');\n }\n }\n const atLeastOneHeaderAvailable = headersToCheck.some((header) => {\n return firstResponse.headers.has(header) &&\n secondResponse.headers.has(header);\n });\n if (!atLeastOneHeaderAvailable) {\n if (process.env.NODE_ENV !== 'production') {\n logger.warn(`Unable to determine where the response has been updated ` +\n `because none of the headers that would be checked are present.`);\n logger.debug(`Attempting to compare the following: `, firstResponse, secondResponse, headersToCheck);\n }\n // Just return true, indicating the that responses are the same, since we\n // can't determine otherwise.\n return true;\n }\n return headersToCheck.every((header) => {\n const headerStateComparison = firstResponse.headers.has(header) ===\n secondResponse.headers.has(header);\n const headerValueComparison = firstResponse.headers.get(header) ===\n secondResponse.headers.get(header);\n return headerStateComparison && headerValueComparison;\n });\n};\nexport { responsesAreSame };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport '../_version.js';\nexport const CACHE_UPDATED_MESSAGE_TYPE = 'CACHE_UPDATED';\nexport const CACHE_UPDATED_MESSAGE_META = 'workbox-broadcast-update';\nexport const DEFAULT_BROADCAST_CHANNEL_NAME = 'workbox';\nexport const DEFAULT_DEFER_NOTIFICATION_TIMEOUT = 10000;\nexport const DEFAULT_HEADERS_TO_CHECK = [\n 'content-length',\n 'etag',\n 'last-modified',\n];\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { CACHE_UPDATED_MESSAGE_TYPE, CACHE_UPDATED_MESSAGE_META } from './utils/constants.js';\nimport './_version.js';\n/**\n * You would not normally call this method directly; it's called automatically\n * by an instance of the {@link BroadcastCacheUpdate} class. It's exposed here\n * for the benefit of developers who would rather not use the full\n * `BroadcastCacheUpdate` implementation.\n *\n * Calling this will dispatch a message on the provided\n * {@link https://developers.google.com/web/updates/2016/09/broadcastchannel|Broadcast Channel}\n * to notify interested subscribers about a change to a cached resource.\n *\n * The message that's posted has a formation inspired by the\n * [Flux standard action](https://github.com/acdlite/flux-standard-action#introduction)\n * format like so:\n *\n * ```\n * {\n * type: 'CACHE_UPDATED',\n * meta: 'workbox-broadcast-update',\n * payload: {\n * cacheName: 'the-cache-name',\n * updatedURL: 'https://example.com/'\n * }\n * }\n * ```\n *\n * (Usage of [Flux](https://facebook.github.io/flux/) itself is not at\n * all required.)\n *\n * @param {Object} options\n * @param {string} options.cacheName The name of the cache in which the updated\n * `Response` was stored.\n * @param {string} options.url The URL associated with the updated `Response`.\n * @param {BroadcastChannel} [options.channel] The `BroadcastChannel` to use.\n * If no channel is set or the browser doesn't support the BroadcastChannel\n * api, then an attempt will be made to `postMessage` each window client.\n *\n * @memberof workbox.broadcastUpdate\n */\nconst broadcastUpdate = async ({ channel, cacheName, url }) => {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(cacheName, 'string', {\n moduleName: 'workbox-broadcast-update',\n className: '~',\n funcName: 'broadcastUpdate',\n paramName: 'cacheName',\n });\n assert.isType(url, 'string', {\n moduleName: 'workbox-broadcast-update',\n className: '~',\n funcName: 'broadcastUpdate',\n paramName: 'url',\n });\n }\n const data = {\n type: CACHE_UPDATED_MESSAGE_TYPE,\n meta: CACHE_UPDATED_MESSAGE_META,\n payload: {\n cacheName: cacheName,\n updatedURL: url,\n },\n };\n if (channel) {\n channel.postMessage(data);\n }\n else {\n const windows = await self.clients.matchAll({ type: 'window' });\n for (const win of windows) {\n win.postMessage(data);\n }\n }\n};\nexport { broadcastUpdate };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { getFriendlyURL } from 'workbox-core/_private/getFriendlyURL.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { Deferred } from 'workbox-core/_private/Deferred.js';\nimport { responsesAreSame } from './responsesAreSame.js';\nimport { broadcastUpdate } from './broadcastUpdate.js';\nimport { DEFAULT_HEADERS_TO_CHECK, DEFAULT_BROADCAST_CHANNEL_NAME, DEFAULT_DEFER_NOTIFICATION_TIMEOUT } from './utils/constants.js';\nimport './_version.js';\n/**\n * Uses the [Broadcast Channel API]{@link https://developers.google.com/web/updates/2016/09/broadcastchannel}\n * to notify interested parties when a cached response has been updated.\n * In browsers that do not support the Broadcast Channel API, the instance\n * falls back to sending the update via `postMessage()` to all window clients.\n *\n * For efficiency's sake, the underlying response bodies are not compared;\n * only specific response headers are checked.\n *\n * @memberof workbox.broadcastUpdate\n */\nclass BroadcastCacheUpdate {\n /**\n * Construct a BroadcastCacheUpdate instance with a specific `channelName` to\n * broadcast messages on\n *\n * @param {Object} options\n * @param {Array<string>}\n * [options.headersToCheck=['content-length', 'etag', 'last-modified']]\n * A list of headers that will be used to determine whether the responses\n * differ.\n * @param {string} [options.channelName='workbox'] The name that will be used\n *. when creating the `BroadcastChannel`, which defaults to 'workbox' (the\n * channel name used by the `workbox-window` package).\n * @param {string} [options.deferNoticationTimeout=10000] The amount of time\n * to wait for a ready message from the window on navigation requests\n * before sending the update.\n */\n constructor({ headersToCheck, channelName, deferNoticationTimeout, } = {}) {\n this._headersToCheck = headersToCheck || DEFAULT_HEADERS_TO_CHECK;\n this._channelName = channelName || DEFAULT_BROADCAST_CHANNEL_NAME;\n this._deferNoticationTimeout =\n deferNoticationTimeout || DEFAULT_DEFER_NOTIFICATION_TIMEOUT;\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(this._channelName, 'string', {\n moduleName: 'workbox-broadcast-update',\n className: 'BroadcastCacheUpdate',\n funcName: 'constructor',\n paramName: 'channelName',\n });\n assert.isArray(this._headersToCheck, {\n moduleName: 'workbox-broadcast-update',\n className: 'BroadcastCacheUpdate',\n funcName: 'constructor',\n paramName: 'headersToCheck',\n });\n }\n this._initWindowReadyDeferreds();\n }\n /**\n * Compare two [Responses](https://developer.mozilla.org/en-US/docs/Web/API/Response)\n * and send a message via the\n * {@link https://developers.google.com/web/updates/2016/09/broadcastchannel|Broadcast Channel API}\n * if they differ.\n *\n * Neither of the Responses can be {@link http://stackoverflow.com/questions/39109789|opaque}.\n *\n * @param {Object} options\n * @param {Response} options.oldResponse Cached response to compare.\n * @param {Response} options.newResponse Possibly updated response to compare.\n * @param {string} options.url The URL of the request.\n * @param {string} options.cacheName Name of the cache the responses belong\n * to. This is included in the broadcast message.\n * @param {Event} [options.event] event An optional event that triggered\n * this possible cache update.\n * @return {Promise} Resolves once the update is sent.\n */\n notifyIfUpdated({ oldResponse, newResponse, url, cacheName, event }) {\n if (!responsesAreSame(oldResponse, newResponse, this._headersToCheck)) {\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`Newer response found (and cached) for:`, url);\n }\n const sendUpdate = async () => {\n // In the case of a navigation request, the requesting page will likely\n // not have loaded its JavaScript in time to recevied the update\n // notification, so we defer it until ready (or we timeout waiting).\n if (event && event.request && event.request.mode === 'navigate') {\n if (process.env.NODE_ENV !== 'production') {\n logger.debug(`Original request was a navigation request, ` +\n `waiting for a ready message from the window`, event.request);\n }\n await this._windowReadyOrTimeout(event);\n }\n await this._broadcastUpdate({\n channel: this._getChannel(),\n cacheName,\n url,\n });\n };\n // Send the update and ensure the SW stays alive until it's sent.\n const done = sendUpdate();\n if (event) {\n try {\n event.waitUntil(done);\n }\n catch (error) {\n if (process.env.NODE_ENV !== 'production') {\n logger.warn(`Unable to ensure service worker stays alive ` +\n `when broadcasting cache update for ` +\n `${getFriendlyURL(event.request.url)}'.`);\n }\n }\n }\n return done;\n }\n }\n /**\n * NOTE: this is exposed on the instance primarily so it can be spied on\n * in tests.\n *\n * @param {Object} opts\n * @private\n */\n async _broadcastUpdate(opts) {\n await broadcastUpdate(opts);\n }\n /**\n * @return {BroadcastChannel|undefined} The BroadcastChannel instance used for\n * broadcasting updates, or undefined if the browser doesn't support the\n * Broadcast Channel API.\n *\n * @private\n */\n _getChannel() {\n if (('BroadcastChannel' in self) && !this._channel) {\n this._channel = new BroadcastChannel(this._channelName);\n }\n return this._channel;\n }\n /**\n * Waits for a message from the window indicating that it's capable of\n * receiving broadcasts. By default, this will only wait for the amount of\n * time specified via the `deferNoticationTimeout` option.\n *\n * @param {Event} event The navigation fetch event.\n * @return {Promise}\n * @private\n */\n _windowReadyOrTimeout(event) {\n if (!this._navigationEventsDeferreds.has(event)) {\n const deferred = new Deferred();\n // Set the deferred on the `_navigationEventsDeferreds` map so it will\n // be resolved when the next ready message event comes.\n this._navigationEventsDeferreds.set(event, deferred);\n // But don't wait too long for the message since it may never come.\n const timeout = setTimeout(() => {\n if (process.env.NODE_ENV !== 'production') {\n logger.debug(`Timed out after ${this._deferNoticationTimeout}` +\n `ms waiting for message from window`);\n }\n deferred.resolve();\n }, this._deferNoticationTimeout);\n // Ensure the timeout is cleared if the deferred promise is resolved.\n deferred.promise.then(() => clearTimeout(timeout));\n }\n return this._navigationEventsDeferreds.get(event).promise;\n }\n /**\n * Creates a mapping between navigation fetch events and deferreds, and adds\n * a listener for message events from the window. When message events arrive,\n * all deferreds in the mapping are resolved.\n *\n * Note: it would be easier if we could only resolve the deferred of\n * navigation fetch event whose client ID matched the source ID of the\n * message event, but currently client IDs are not exposed on navigation\n * fetch events: https://www.chromestatus.com/feature/4846038800138240\n *\n * @private\n */\n _initWindowReadyDeferreds() {\n // A mapping between navigation events and their deferreds.\n this._navigationEventsDeferreds = new Map();\n // The message listener needs to be added in the initial run of the\n // service worker, but since we don't actually need to be listening for\n // messages until the cache updates, we only invoke the callback if set.\n self.addEventListener('message', (event) => {\n if (event.data.type === 'WINDOW_READY' &&\n event.data.meta === 'workbox-window' &&\n this._navigationEventsDeferreds.size > 0) {\n if (process.env.NODE_ENV !== 'production') {\n logger.debug(`Received WINDOW_READY event: `, event);\n }\n // Resolve any pending deferreds.\n for (const deferred of this._navigationEventsDeferreds.values()) {\n deferred.resolve();\n }\n this._navigationEventsDeferreds.clear();\n }\n });\n }\n}\nexport { BroadcastCacheUpdate };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { BroadcastCacheUpdate } from './BroadcastCacheUpdate.js';\nimport './_version.js';\n/**\n * This plugin will automatically broadcast a message whenever a cached response\n * is updated.\n *\n * @memberof workbox.broadcastUpdate\n */\nclass Plugin {\n /**\n * Construct a BroadcastCacheUpdate instance with the passed options and\n * calls its `notifyIfUpdated()` method whenever the plugin's\n * `cacheDidUpdate` callback is invoked.\n *\n * @param {Object} options\n * @param {Array<string>}\n * [options.headersToCheck=['content-length', 'etag', 'last-modified']]\n * A list of headers that will be used to determine whether the responses\n * differ.\n * @param {string} [options.channelName='workbox'] The name that will be used\n *. when creating the `BroadcastChannel`, which defaults to 'workbox' (the\n * channel name used by the `workbox-window` package).\n * @param {string} [options.deferNoticationTimeout=10000] The amount of time\n * to wait for a ready message from the window on navigation requests\n * before sending the update.\n */\n constructor(options) {\n /**\n * A \"lifecycle\" callback that will be triggered automatically by the\n * `workbox-sw` and `workbox-runtime-caching` handlers when an entry is\n * added to a cache.\n *\n * @private\n * @param {Object} options The input object to this function.\n * @param {string} options.cacheName Name of the cache being updated.\n * @param {Response} [options.oldResponse] The previous cached value, if any.\n * @param {Response} options.newResponse The new value in the cache.\n * @param {Request} options.request The request that triggered the udpate.\n * @param {Request} [options.event] The event that triggered the update.\n */\n this.cacheDidUpdate = async ({ cacheName, oldResponse, newResponse, request, event }) => {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(cacheName, 'string', {\n moduleName: 'workbox-broadcast-update',\n className: 'Plugin',\n funcName: 'cacheDidUpdate',\n paramName: 'cacheName',\n });\n assert.isInstance(newResponse, Response, {\n moduleName: 'workbox-broadcast-update',\n className: 'Plugin',\n funcName: 'cacheDidUpdate',\n paramName: 'newResponse',\n });\n assert.isInstance(request, Request, {\n moduleName: 'workbox-broadcast-update',\n className: 'Plugin',\n funcName: 'cacheDidUpdate',\n paramName: 'request',\n });\n }\n // Without a two responses there is nothing to compare.\n if (oldResponse) {\n this._broadcastUpdate.notifyIfUpdated({\n cacheName,\n oldResponse,\n newResponse,\n event,\n url: request.url,\n });\n }\n };\n this._broadcastUpdate = new BroadcastCacheUpdate(options);\n }\n}\nexport { Plugin };\n"],"names":["self","_","e","responsesAreSame","firstResponse","secondResponse","headersToCheck","some","header","headers","has","every","headerStateComparison","headerValueComparison","get","DEFAULT_BROADCAST_CHANNEL_NAME","DEFAULT_DEFER_NOTIFICATION_TIMEOUT","DEFAULT_HEADERS_TO_CHECK","broadcastUpdate","async","channel","cacheName","url","data","type","meta","payload","updatedURL","postMessage","windows","clients","matchAll","win","BroadcastCacheUpdate","constructor","channelName","deferNoticationTimeout","_headersToCheck","_channelName","_deferNoticationTimeout","_initWindowReadyDeferreds","notifyIfUpdated","oldResponse","newResponse","event","this","done","request","mode","_windowReadyOrTimeout","_broadcastUpdate","_getChannel","sendUpdate","waitUntil","error","opts","_channel","BroadcastChannel","_navigationEventsDeferreds","deferred","Deferred","set","timeout","setTimeout","resolve","promise","then","clearTimeout","Map","addEventListener","size","values","clear","options","cacheDidUpdate"],"mappings":"sFACA,IACIA,KAAK,2CAA6CC,IAEtD,MAAOC,UCkBDC,EAAmB,CAACC,EAAeC,EAAgBC,YAOnBA,EAAeC,KAAMC,GAC5CJ,EAAcK,QAAQC,IAAIF,IAC7BH,EAAeI,QAAQC,IAAIF,KAY5BF,EAAeK,MAAOH,UACnBI,EAAwBR,EAAcK,QAAQC,IAAIF,KACpDH,EAAeI,QAAQC,IAAIF,GACzBK,EAAwBT,EAAcK,QAAQK,IAAIN,KACpDH,EAAeI,QAAQK,IAAIN,UACxBI,GAAyBC,KCtC3BE,EAAiC,UACjCC,EAAqC,IACrCC,EAA2B,CACpC,iBACA,OACA,iBCiCEC,EAAkBC,OAASC,QAAAA,EAASC,UAAAA,EAAWC,IAAAA,YAe3CC,EAAO,CACTC,KDxDkC,gBCyDlCC,KDxDkC,2BCyDlCC,QAAS,CACLL,UAAWA,EACXM,WAAYL,OAGhBF,EACAA,EAAQQ,YAAYL,OAEnB,OACKM,QAAgB7B,KAAK8B,QAAQC,SAAS,CAAEP,KAAM,eAC/C,MAAMQ,KAAOH,EACdG,EAAIJ,YAAYL,KCnD5B,MAAMU,EAiBFC,aAAY5B,eAAEA,EAAF6B,YAAkBA,EAAlBC,uBAA+BA,GAA4B,SAC9DC,EAAkB/B,GAAkBW,OACpCqB,EAAeH,GAAepB,OAC9BwB,EACDH,GAA0BpB,OAezBwB,IAoBTC,iBAAgBC,YAAEA,EAAFC,YAA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.workbox.cacheableResponse = (function (exports, assert_js, WorkboxError_js, getFriendlyURL_js, logger_js) {
3
+ 'use strict';
4
+
5
+ // @ts-ignore
6
+ try {
7
+ self['workbox:cacheable-response:5.0.0-alpha.0'] && _();
8
+ } catch (e) {}
9
+
10
+ /*
11
+ Copyright 2018 Google LLC
12
+
13
+ Use of this source code is governed by an MIT-style
14
+ license that can be found in the LICENSE file or at
15
+ https://opensource.org/licenses/MIT.
16
+ */
17
+ /**
18
+ * This class allows you to set up rules determining what
19
+ * status codes and/or headers need to be present in order for a
20
+ * [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
21
+ * to be considered cacheable.
22
+ *
23
+ * @memberof workbox.cacheableResponse
24
+ */
25
+
26
+ class CacheableResponse {
27
+ /**
28
+ * To construct a new CacheableResponse instance you must provide at least
29
+ * one of the `config` properties.
30
+ *
31
+ * If both `statuses` and `headers` are specified, then both conditions must
32
+ * be met for the `Response` to be considered cacheable.
33
+ *
34
+ * @param {Object} config
35
+ * @param {Array<number>} [config.statuses] One or more status codes that a
36
+ * `Response` can have and be considered cacheable.
37
+ * @param {Object<string,string>} [config.headers] A mapping of header names
38
+ * and expected values that a `Response` can have and be considered cacheable.
39
+ * If multiple headers are provided, only one needs to be present.
40
+ */
41
+ constructor(config = {}) {
42
+ {
43
+ if (!(config.statuses || config.headers)) {
44
+ throw new WorkboxError_js.WorkboxError('statuses-or-headers-required', {
45
+ moduleName: 'workbox-cacheable-response',
46
+ className: 'CacheableResponse',
47
+ funcName: 'constructor'
48
+ });
49
+ }
50
+
51
+ if (config.statuses) {
52
+ assert_js.assert.isArray(config.statuses, {
53
+ moduleName: 'workbox-cacheable-response',
54
+ className: 'CacheableResponse',
55
+ funcName: 'constructor',
56
+ paramName: 'config.statuses'
57
+ });
58
+ }
59
+
60
+ if (config.headers) {
61
+ assert_js.assert.isType(config.headers, 'object', {
62
+ moduleName: 'workbox-cacheable-response',
63
+ className: 'CacheableResponse',
64
+ funcName: 'constructor',
65
+ paramName: 'config.headers'
66
+ });
67
+ }
68
+ }
69
+
70
+ this._statuses = config.statuses;
71
+ this._headers = config.headers;
72
+ }
73
+ /**
74
+ * Checks a response to see whether it's cacheable or not, based on this
75
+ * object's configuration.
76
+ *
77
+ * @param {Response} response The response whose cacheability is being
78
+ * checked.
79
+ * @return {boolean} `true` if the `Response` is cacheable, and `false`
80
+ * otherwise.
81
+ */
82
+
83
+
84
+ isResponseCacheable(response) {
85
+ {
86
+ assert_js.assert.isInstance(response, Response, {
87
+ moduleName: 'workbox-cacheable-response',
88
+ className: 'CacheableResponse',
89
+ funcName: 'isResponseCacheable',
90
+ paramName: 'response'
91
+ });
92
+ }
93
+
94
+ let cacheable = true;
95
+
96
+ if (this._statuses) {
97
+ cacheable = this._statuses.includes(response.status);
98
+ }
99
+
100
+ if (this._headers && cacheable) {
101
+ cacheable = Object.keys(this._headers).some(headerName => {
102
+ return response.headers.get(headerName) === this._headers[headerName];
103
+ });
104
+ }
105
+
106
+ {
107
+ if (!cacheable) {
108
+ logger_js.logger.groupCollapsed(`The request for ` + `'${getFriendlyURL_js.getFriendlyURL(response.url)}' returned a response that does ` + `not meet the criteria for being cached.`);
109
+ logger_js.logger.groupCollapsed(`View cacheability criteria here.`);
110
+ logger_js.logger.log(`Cacheable statuses: ` + JSON.stringify(this._statuses));
111
+ logger_js.logger.log(`Cacheable headers: ` + JSON.stringify(this._headers, null, 2));
112
+ logger_js.logger.groupEnd();
113
+ const logFriendlyHeaders = {};
114
+ response.headers.forEach((value, key) => {
115
+ logFriendlyHeaders[key] = value;
116
+ });
117
+ logger_js.logger.groupCollapsed(`View response status and headers here.`);
118
+ logger_js.logger.log(`Response status: ` + response.status);
119
+ logger_js.logger.log(`Response headers: ` + JSON.stringify(logFriendlyHeaders, null, 2));
120
+ logger_js.logger.groupEnd();
121
+ logger_js.logger.groupCollapsed(`View full response details here.`);
122
+ logger_js.logger.log(response.headers);
123
+ logger_js.logger.log(response);
124
+ logger_js.logger.groupEnd();
125
+ logger_js.logger.groupEnd();
126
+ }
127
+ }
128
+
129
+ return cacheable;
130
+ }
131
+
132
+ }
133
+
134
+ /*
135
+ Copyright 2018 Google LLC
136
+
137
+ Use of this source code is governed by an MIT-style
138
+ license that can be found in the LICENSE file or at
139
+ https://opensource.org/licenses/MIT.
140
+ */
141
+ /**
142
+ * A class implementing the `cacheWillUpdate` lifecycle callback. This makes it
143
+ * easier to add in cacheability checks to requests made via Workbox's built-in
144
+ * strategies.
145
+ *
146
+ * @memberof workbox.cacheableResponse
147
+ */
148
+
149
+ class Plugin {
150
+ /**
151
+ * To construct a new cacheable response Plugin instance you must provide at
152
+ * least one of the `config` properties.
153
+ *
154
+ * If both `statuses` and `headers` are specified, then both conditions must
155
+ * be met for the `Response` to be considered cacheable.
156
+ *
157
+ * @param {Object} config
158
+ * @param {Array<number>} [config.statuses] One or more status codes that a
159
+ * `Response` can have and be considered cacheable.
160
+ * @param {Object<string,string>} [config.headers] A mapping of header names
161
+ * and expected values that a `Response` can have and be considered cacheable.
162
+ * If multiple headers are provided, only one needs to be present.
163
+ */
164
+ constructor(config) {
165
+ /**
166
+ * @param {Object} options
167
+ * @param {Response} options.response
168
+ * @return {Response|null}
169
+ * @private
170
+ */
171
+ this.cacheWillUpdate = async ({
172
+ response
173
+ }) => {
174
+ if (this._cacheableResponse.isResponseCacheable(response)) {
175
+ return response;
176
+ }
177
+
178
+ return null;
179
+ };
180
+
181
+ this._cacheableResponse = new CacheableResponse(config);
182
+ }
183
+
184
+ }
185
+
186
+ exports.CacheableResponse = CacheableResponse;
187
+ exports.Plugin = Plugin;
188
+
189
+ return exports;
190
+
191
+ }({}, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private));
192
+ //# sourceMappingURL=workbox-cacheable-response.dev.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workbox-cacheable-response.dev.js","sources":["../_version.js","../CacheableResponse.js","../Plugin.js"],"sourcesContent":["// @ts-ignore\ntry {\n self['workbox:cacheable-response:5.0.0-alpha.0'] && _();\n}\ncatch (e) { }\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { getFriendlyURL } from 'workbox-core/_private/getFriendlyURL.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport './_version.js';\n/**\n * This class allows you to set up rules determining what\n * status codes and/or headers need to be present in order for a\n * [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)\n * to be considered cacheable.\n *\n * @memberof workbox.cacheableResponse\n */\nclass CacheableResponse {\n /**\n * To construct a new CacheableResponse instance you must provide at least\n * one of the `config` properties.\n *\n * If both `statuses` and `headers` are specified, then both conditions must\n * be met for the `Response` to be considered cacheable.\n *\n * @param {Object} config\n * @param {Array<number>} [config.statuses] One or more status codes that a\n * `Response` can have and be considered cacheable.\n * @param {Object<string,string>} [config.headers] A mapping of header names\n * and expected values that a `Response` can have and be considered cacheable.\n * If multiple headers are provided, only one needs to be present.\n */\n constructor(config = {}) {\n if (process.env.NODE_ENV !== 'production') {\n if (!(config.statuses || config.headers)) {\n throw new WorkboxError('statuses-or-headers-required', {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'constructor',\n });\n }\n if (config.statuses) {\n assert.isArray(config.statuses, {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'constructor',\n paramName: 'config.statuses',\n });\n }\n if (config.headers) {\n assert.isType(config.headers, 'object', {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'constructor',\n paramName: 'config.headers',\n });\n }\n }\n this._statuses = config.statuses;\n this._headers = config.headers;\n }\n /**\n * Checks a response to see whether it's cacheable or not, based on this\n * object's configuration.\n *\n * @param {Response} response The response whose cacheability is being\n * checked.\n * @return {boolean} `true` if the `Response` is cacheable, and `false`\n * otherwise.\n */\n isResponseCacheable(response) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isInstance(response, Response, {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'isResponseCacheable',\n paramName: 'response',\n });\n }\n let cacheable = true;\n if (this._statuses) {\n cacheable = this._statuses.includes(response.status);\n }\n if (this._headers && cacheable) {\n cacheable = Object.keys(this._headers).some((headerName) => {\n return response.headers.get(headerName) === this._headers[headerName];\n });\n }\n if (process.env.NODE_ENV !== 'production') {\n if (!cacheable) {\n logger.groupCollapsed(`The request for ` +\n `'${getFriendlyURL(response.url)}' returned a response that does ` +\n `not meet the criteria for being cached.`);\n logger.groupCollapsed(`View cacheability criteria here.`);\n logger.log(`Cacheable statuses: ` +\n JSON.stringify(this._statuses));\n logger.log(`Cacheable headers: ` +\n JSON.stringify(this._headers, null, 2));\n logger.groupEnd();\n const logFriendlyHeaders = {};\n response.headers.forEach((value, key) => {\n logFriendlyHeaders[key] = value;\n });\n logger.groupCollapsed(`View response status and headers here.`);\n logger.log(`Response status: ` + response.status);\n logger.log(`Response headers: ` +\n JSON.stringify(logFriendlyHeaders, null, 2));\n logger.groupEnd();\n logger.groupCollapsed(`View full response details here.`);\n logger.log(response.headers);\n logger.log(response);\n logger.groupEnd();\n logger.groupEnd();\n }\n }\n return cacheable;\n }\n}\nexport { CacheableResponse };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { CacheableResponse } from './CacheableResponse.js';\nimport './_version.js';\n/**\n * A class implementing the `cacheWillUpdate` lifecycle callback. This makes it\n * easier to add in cacheability checks to requests made via Workbox's built-in\n * strategies.\n *\n * @memberof workbox.cacheableResponse\n */\nclass Plugin {\n /**\n * To construct a new cacheable response Plugin instance you must provide at\n * least one of the `config` properties.\n *\n * If both `statuses` and `headers` are specified, then both conditions must\n * be met for the `Response` to be considered cacheable.\n *\n * @param {Object} config\n * @param {Array<number>} [config.statuses] One or more status codes that a\n * `Response` can have and be considered cacheable.\n * @param {Object<string,string>} [config.headers] A mapping of header names\n * and expected values that a `Response` can have and be considered cacheable.\n * If multiple headers are provided, only one needs to be present.\n */\n constructor(config) {\n /**\n * @param {Object} options\n * @param {Response} options.response\n * @return {Response|null}\n * @private\n */\n this.cacheWillUpdate = async ({ response }) => {\n if (this._cacheableResponse.isResponseCacheable(response)) {\n return response;\n }\n return null;\n };\n this._cacheableResponse = new CacheableResponse(config);\n }\n}\nexport { Plugin };\n"],"names":["self","_","e","CacheableResponse","constructor","config","statuses","headers","WorkboxError","moduleName","className","funcName","assert","isArray","paramName","isType","_statuses","_headers","isResponseCacheable","response","isInstance","Response","cacheable","includes","status","Object","keys","some","headerName","get","logger","groupCollapsed","getFriendlyURL","url","log","JSON","stringify","groupEnd","logFriendlyHeaders","forEach","value","key","Plugin","cacheWillUpdate","_cacheableResponse"],"mappings":";;;;IAAA;IACA,IAAI;IACAA,EAAAA,IAAI,CAAC,0CAAD,CAAJ,IAAoDC,CAAC,EAArD;IACH,CAFD,CAGA,OAAOC,CAAP,EAAU;;ICJV;;;;;;;AAOA,IAKA;;;;;;;;;IAQA,MAAMC,iBAAN,CAAwB;IACpB;;;;;;;;;;;;;;IAcAC,EAAAA,WAAW,CAACC,MAAM,GAAG,EAAV,EAAc;IACrB,IAA2C;IACvC,UAAI,EAAEA,MAAM,CAACC,QAAP,IAAmBD,MAAM,CAACE,OAA5B,CAAJ,EAA0C;IACtC,cAAM,IAAIC,4BAAJ,CAAiB,8BAAjB,EAAiD;IACnDC,UAAAA,UAAU,EAAE,4BADuC;IAEnDC,UAAAA,SAAS,EAAE,mBAFwC;IAGnDC,UAAAA,QAAQ,EAAE;IAHyC,SAAjD,CAAN;IAKH;;IACD,UAAIN,MAAM,CAACC,QAAX,EAAqB;IACjBM,QAAAA,gBAAM,CAACC,OAAP,CAAeR,MAAM,CAACC,QAAtB,EAAgC;IAC5BG,UAAAA,UAAU,EAAE,4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;;;AAOA,IAEA;;;;;;;;IAOA,MAAMoB,MAAN,CAAa;IACT;;;;;;;;;;;;;;IAcAtC,EAAAA,WAAW,CAACC,MAAD,EAAS;IAChB;;;;;;IAMA,SAAKsC,eAAL,GAAuB,OAAO;IAAExB,MAAAA;IAAF,KAAP,KAAwB;IAC3C,UAAI,KAAKyB,kBAAL,CAAwB1B,mBAAxB,CAA4CC,QAA5C,CAAJ,EAA2D;IACvD,eAAOA,QAAP;IACH;;IACD,aAAO,IAAP;IACH,KALD;;IAMA,SAAKyB,kBAAL,GAA0B,IAAIzC,iBAAJ,CAAsBE,MAAtB,CAA1B;IACH;;IA7BQ;;;;;;;;;;;"}
@@ -0,0 +1,2 @@
1
+ this.workbox=this.workbox||{},this.workbox.cacheableResponse=function(s){"use strict";try{self["workbox:cacheable-response:5.0.0-alpha.0"]&&_()}catch(s){}class t{constructor(s={}){this.s=s.statuses,this.t=s.headers}isResponseCacheable(s){let t=!0;return this.s&&(t=this.s.includes(s.status)),this.t&&t&&(t=Object.keys(this.t).some(t=>s.headers.get(t)===this.t[t])),t}}return s.CacheableResponse=t,s.Plugin=class{constructor(s){this.cacheWillUpdate=(async({response:s})=>this.i.isResponseCacheable(s)?s:null),this.i=new t(s)}},s}({});
2
+ //# sourceMappingURL=workbox-cacheable-response.prod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workbox-cacheable-response.prod.js","sources":["../_version.js","../CacheableResponse.js","../Plugin.js"],"sourcesContent":["// @ts-ignore\ntry {\n self['workbox:cacheable-response:5.0.0-alpha.0'] && _();\n}\ncatch (e) { }\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { getFriendlyURL } from 'workbox-core/_private/getFriendlyURL.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport './_version.js';\n/**\n * This class allows you to set up rules determining what\n * status codes and/or headers need to be present in order for a\n * [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)\n * to be considered cacheable.\n *\n * @memberof workbox.cacheableResponse\n */\nclass CacheableResponse {\n /**\n * To construct a new CacheableResponse instance you must provide at least\n * one of the `config` properties.\n *\n * If both `statuses` and `headers` are specified, then both conditions must\n * be met for the `Response` to be considered cacheable.\n *\n * @param {Object} config\n * @param {Array<number>} [config.statuses] One or more status codes that a\n * `Response` can have and be considered cacheable.\n * @param {Object<string,string>} [config.headers] A mapping of header names\n * and expected values that a `Response` can have and be considered cacheable.\n * If multiple headers are provided, only one needs to be present.\n */\n constructor(config = {}) {\n if (process.env.NODE_ENV !== 'production') {\n if (!(config.statuses || config.headers)) {\n throw new WorkboxError('statuses-or-headers-required', {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'constructor',\n });\n }\n if (config.statuses) {\n assert.isArray(config.statuses, {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'constructor',\n paramName: 'config.statuses',\n });\n }\n if (config.headers) {\n assert.isType(config.headers, 'object', {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'constructor',\n paramName: 'config.headers',\n });\n }\n }\n this._statuses = config.statuses;\n this._headers = config.headers;\n }\n /**\n * Checks a response to see whether it's cacheable or not, based on this\n * object's configuration.\n *\n * @param {Response} response The response whose cacheability is being\n * checked.\n * @return {boolean} `true` if the `Response` is cacheable, and `false`\n * otherwise.\n */\n isResponseCacheable(response) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isInstance(response, Response, {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'isResponseCacheable',\n paramName: 'response',\n });\n }\n let cacheable = true;\n if (this._statuses) {\n cacheable = this._statuses.includes(response.status);\n }\n if (this._headers && cacheable) {\n cacheable = Object.keys(this._headers).some((headerName) => {\n return response.headers.get(headerName) === this._headers[headerName];\n });\n }\n if (process.env.NODE_ENV !== 'production') {\n if (!cacheable) {\n logger.groupCollapsed(`The request for ` +\n `'${getFriendlyURL(response.url)}' returned a response that does ` +\n `not meet the criteria for being cached.`);\n logger.groupCollapsed(`View cacheability criteria here.`);\n logger.log(`Cacheable statuses: ` +\n JSON.stringify(this._statuses));\n logger.log(`Cacheable headers: ` +\n JSON.stringify(this._headers, null, 2));\n logger.groupEnd();\n const logFriendlyHeaders = {};\n response.headers.forEach((value, key) => {\n logFriendlyHeaders[key] = value;\n });\n logger.groupCollapsed(`View response status and headers here.`);\n logger.log(`Response status: ` + response.status);\n logger.log(`Response headers: ` +\n JSON.stringify(logFriendlyHeaders, null, 2));\n logger.groupEnd();\n logger.groupCollapsed(`View full response details here.`);\n logger.log(response.headers);\n logger.log(response);\n logger.groupEnd();\n logger.groupEnd();\n }\n }\n return cacheable;\n }\n}\nexport { CacheableResponse };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { CacheableResponse } from './CacheableResponse.js';\nimport './_version.js';\n/**\n * A class implementing the `cacheWillUpdate` lifecycle callback. This makes it\n * easier to add in cacheability checks to requests made via Workbox's built-in\n * strategies.\n *\n * @memberof workbox.cacheableResponse\n */\nclass Plugin {\n /**\n * To construct a new cacheable response Plugin instance you must provide at\n * least one of the `config` properties.\n *\n * If both `statuses` and `headers` are specified, then both conditions must\n * be met for the `Response` to be considered cacheable.\n *\n * @param {Object} config\n * @param {Array<number>} [config.statuses] One or more status codes that a\n * `Response` can have and be considered cacheable.\n * @param {Object<string,string>} [config.headers] A mapping of header names\n * and expected values that a `Response` can have and be considered cacheable.\n * If multiple headers are provided, only one needs to be present.\n */\n constructor(config) {\n /**\n * @param {Object} options\n * @param {Response} options.response\n * @return {Response|null}\n * @private\n */\n this.cacheWillUpdate = async ({ response }) => {\n if (this._cacheableResponse.isResponseCacheable(response)) {\n return response;\n }\n return null;\n };\n this._cacheableResponse = new CacheableResponse(config);\n }\n}\nexport { Plugin };\n"],"names":["self","_","e","CacheableResponse","constructor","config","_statuses","statuses","_headers","headers","isResponseCacheable","response","cacheable","this","includes","status","Object","keys","some","headerName","get","cacheWillUpdate","async","_cacheableResponse"],"mappings":"sFACA,IACIA,KAAK,6CAA+CC,IAExD,MAAOC,ICgBP,MAAMC,EAeFC,YAAYC,EAAS,SA0BZC,EAAYD,EAAOE,cACnBC,EAAWH,EAAOI,QAW3BC,oBAAoBC,OASZC,GAAY,SACZC,KAAKP,IACLM,EAAYC,KAAKP,EAAUQ,SAASH,EAASI,SAE7CF,KAAKL,GAAYI,IACjBA,EAAYI,OAAOC,KAAKJ,KAAKL,GAAUU,KAAMC,GAClCR,EAASF,QAAQW,IAAID,KAAgBN,KAAKL,EAASW,KA8B3DP,yCCtGf,MAeIR,YAAYC,QAOHgB,gBAAkBC,QAASX,SAAAA,KACxBE,KAAKU,EAAmBb,oBAAoBC,GACrCA,EAEJ,WAENY,EAAqB,IAAIpB,EAAkBE"}
@@ -0,0 +1,1643 @@
1
+ this.workbox = this.workbox || {};
2
+ this.workbox.core = (function (exports) {
3
+ 'use strict';
4
+
5
+ // @ts-ignore
6
+ try {
7
+ self['workbox:core:5.0.0-alpha.0'] && _();
8
+ } catch (e) {}
9
+
10
+ /*
11
+ Copyright 2019 Google LLC
12
+ Use of this source code is governed by an MIT-style
13
+ license that can be found in the LICENSE file or at
14
+ https://opensource.org/licenses/MIT.
15
+ */
16
+ const logger = (() => {
17
+ let inGroup = false;
18
+ const methodToColorMap = {
19
+ debug: `#7f8c8d`,
20
+ log: `#2ecc71`,
21
+ warn: `#f39c12`,
22
+ error: `#c0392b`,
23
+ groupCollapsed: `#3498db`,
24
+ groupEnd: null
25
+ };
26
+
27
+ const print = function (method, args) {
28
+ if (method === 'groupCollapsed') {
29
+ // Safari doesn't print all console.groupCollapsed() arguments:
30
+ // https://bugs.webkit.org/show_bug.cgi?id=182754
31
+ if (/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
32
+ console[method](...args);
33
+ return;
34
+ }
35
+ }
36
+
37
+ const styles = [`background: ${methodToColorMap[method]}`, `border-radius: 0.5em`, `color: white`, `font-weight: bold`, `padding: 2px 0.5em`]; // When in a group, the workbox prefix is not displayed.
38
+
39
+ const logPrefix = inGroup ? [] : ['%cworkbox', styles.join(';')];
40
+ console[method](...logPrefix, ...args);
41
+
42
+ if (method === 'groupCollapsed') {
43
+ inGroup = true;
44
+ }
45
+
46
+ if (method === 'groupEnd') {
47
+ inGroup = false;
48
+ }
49
+ };
50
+
51
+ const api = {};
52
+ const loggerMethods = Object.keys(methodToColorMap);
53
+
54
+ for (const key of loggerMethods) {
55
+ const method = key;
56
+
57
+ api[method] = (...args) => {
58
+ print(method, args);
59
+ };
60
+ }
61
+
62
+ return api;
63
+ })();
64
+
65
+ /*
66
+ Copyright 2018 Google LLC
67
+
68
+ Use of this source code is governed by an MIT-style
69
+ license that can be found in the LICENSE file or at
70
+ https://opensource.org/licenses/MIT.
71
+ */
72
+ const messages = {
73
+ 'invalid-value': ({
74
+ paramName,
75
+ validValueDescription,
76
+ value
77
+ }) => {
78
+ if (!paramName || !validValueDescription) {
79
+ throw new Error(`Unexpected input to 'invalid-value' error.`);
80
+ }
81
+
82
+ return `The '${paramName}' parameter was given a value with an ` + `unexpected value. ${validValueDescription} Received a value of ` + `${JSON.stringify(value)}.`;
83
+ },
84
+ 'not-in-sw': ({
85
+ moduleName
86
+ }) => {
87
+ if (!moduleName) {
88
+ throw new Error(`Unexpected input to 'not-in-sw' error.`);
89
+ }
90
+
91
+ return `The '${moduleName}' must be used in a service worker.`;
92
+ },
93
+ 'not-an-array': ({
94
+ moduleName,
95
+ className,
96
+ funcName,
97
+ paramName
98
+ }) => {
99
+ if (!moduleName || !className || !funcName || !paramName) {
100
+ throw new Error(`Unexpected input to 'not-an-array' error.`);
101
+ }
102
+
103
+ return `The parameter '${paramName}' passed into ` + `'${moduleName}.${className}.${funcName}()' must be an array.`;
104
+ },
105
+ 'incorrect-type': ({
106
+ expectedType,
107
+ paramName,
108
+ moduleName,
109
+ className,
110
+ funcName
111
+ }) => {
112
+ if (!expectedType || !paramName || !moduleName || !funcName) {
113
+ throw new Error(`Unexpected input to 'incorrect-type' error.`);
114
+ }
115
+
116
+ return `The parameter '${paramName}' passed into ` + `'${moduleName}.${className ? className + '.' : ''}` + `${funcName}()' must be of type ${expectedType}.`;
117
+ },
118
+ 'incorrect-class': ({
119
+ expectedClass,
120
+ paramName,
121
+ moduleName,
122
+ className,
123
+ funcName,
124
+ isReturnValueProblem
125
+ }) => {
126
+ if (!expectedClass || !moduleName || !funcName) {
127
+ throw new Error(`Unexpected input to 'incorrect-class' error.`);
128
+ }
129
+
130
+ if (isReturnValueProblem) {
131
+ return `The return value from ` + `'${moduleName}.${className ? className + '.' : ''}${funcName}()' ` + `must be an instance of class ${expectedClass.name}.`;
132
+ }
133
+
134
+ return `The parameter '${paramName}' passed into ` + `'${moduleName}.${className ? className + '.' : ''}${funcName}()' ` + `must be an instance of class ${expectedClass.name}.`;
135
+ },
136
+ 'missing-a-method': ({
137
+ expectedMethod,
138
+ paramName,
139
+ moduleName,
140
+ className,
141
+ funcName
142
+ }) => {
143
+ if (!expectedMethod || !paramName || !moduleName || !className || !funcName) {
144
+ throw new Error(`Unexpected input to 'missing-a-method' error.`);
145
+ }
146
+
147
+ return `${moduleName}.${className}.${funcName}() expected the ` + `'${paramName}' parameter to expose a '${expectedMethod}' method.`;
148
+ },
149
+ 'add-to-cache-list-unexpected-type': ({
150
+ entry
151
+ }) => {
152
+ return `An unexpected entry was passed to ` + `'workbox-precaching.PrecacheController.addToCacheList()' The entry ` + `'${JSON.stringify(entry)}' isn't supported. You must supply an array of ` + `strings with one or more characters, objects with a url property or ` + `Request objects.`;
153
+ },
154
+ 'add-to-cache-list-conflicting-entries': ({
155
+ firstEntry,
156
+ secondEntry
157
+ }) => {
158
+ if (!firstEntry || !secondEntry) {
159
+ throw new Error(`Unexpected input to ` + `'add-to-cache-list-duplicate-entries' error.`);
160
+ }
161
+
162
+ return `Two of the entries passed to ` + `'workbox-precaching.PrecacheController.addToCacheList()' had the URL ` + `${firstEntry._entryId} but different revision details. Workbox is ` + `is unable to cache and version the asset correctly. Please remove one ` + `of the entries.`;
163
+ },
164
+ 'plugin-error-request-will-fetch': ({
165
+ thrownError
166
+ }) => {
167
+ if (!thrownError) {
168
+ throw new Error(`Unexpected input to ` + `'plugin-error-request-will-fetch', error.`);
169
+ }
170
+
171
+ return `An error was thrown by a plugins 'requestWillFetch()' method. ` + `The thrown error message was: '${thrownError.message}'.`;
172
+ },
173
+ 'invalid-cache-name': ({
174
+ cacheNameId,
175
+ value
176
+ }) => {
177
+ if (!cacheNameId) {
178
+ throw new Error(`Expected a 'cacheNameId' for error 'invalid-cache-name'`);
179
+ }
180
+
181
+ return `You must provide a name containing at least one character for ` + `setCacheDeatils({${cacheNameId}: '...'}). Received a value of ` + `'${JSON.stringify(value)}'`;
182
+ },
183
+ 'unregister-route-but-not-found-with-method': ({
184
+ method
185
+ }) => {
186
+ if (!method) {
187
+ throw new Error(`Unexpected input to ` + `'unregister-route-but-not-found-with-method' error.`);
188
+ }
189
+
190
+ return `The route you're trying to unregister was not previously ` + `registered for the method type '${method}'.`;
191
+ },
192
+ 'unregister-route-route-not-registered': () => {
193
+ return `The route you're trying to unregister was not previously ` + `registered.`;
194
+ },
195
+ 'queue-replay-failed': ({
196
+ name
197
+ }) => {
198
+ return `Replaying the background sync queue '${name}' failed.`;
199
+ },
200
+ 'duplicate-queue-name': ({
201
+ name
202
+ }) => {
203
+ return `The Queue name '${name}' is already being used. ` + `All instances of backgroundSync.Queue must be given unique names.`;
204
+ },
205
+ 'expired-test-without-max-age': ({
206
+ methodName,
207
+ paramName
208
+ }) => {
209
+ return `The '${methodName}()' method can only be used when the ` + `'${paramName}' is used in the constructor.`;
210
+ },
211
+ 'unsupported-route-type': ({
212
+ moduleName,
213
+ className,
214
+ funcName,
215
+ paramName
216
+ }) => {
217
+ return `The supplied '${paramName}' parameter was an unsupported type. ` + `Please check the docs for ${moduleName}.${className}.${funcName} for ` + `valid input types.`;
218
+ },
219
+ 'not-array-of-class': ({
220
+ value,
221
+ expectedClass,
222
+ moduleName,
223
+ className,
224
+ funcName,
225
+ paramName
226
+ }) => {
227
+ return `The supplied '${paramName}' parameter must be an array of ` + `'${expectedClass}' objects. Received '${JSON.stringify(value)},'. ` + `Please check the call to ${moduleName}.${className}.${funcName}() ` + `to fix the issue.`;
228
+ },
229
+ 'max-entries-or-age-required': ({
230
+ moduleName,
231
+ className,
232
+ funcName
233
+ }) => {
234
+ return `You must define either config.maxEntries or config.maxAgeSeconds` + `in ${moduleName}.${className}.${funcName}`;
235
+ },
236
+ 'statuses-or-headers-required': ({
237
+ moduleName,
238
+ className,
239
+ funcName
240
+ }) => {
241
+ return `You must define either config.statuses or config.headers` + `in ${moduleName}.${className}.${funcName}`;
242
+ },
243
+ 'invalid-string': ({
244
+ moduleName,
245
+ funcName,
246
+ paramName
247
+ }) => {
248
+ if (!paramName || !moduleName || !funcName) {
249
+ throw new Error(`Unexpected input to 'invalid-string' error.`);
250
+ }
251
+
252
+ return `When using strings, the '${paramName}' parameter must start with ` + `'http' (for cross-origin matches) or '/' (for same-origin matches). ` + `Please see the docs for ${moduleName}.${funcName}() for ` + `more info.`;
253
+ },
254
+ 'channel-name-required': () => {
255
+ return `You must provide a channelName to construct a ` + `BroadcastCacheUpdate instance.`;
256
+ },
257
+ 'invalid-responses-are-same-args': () => {
258
+ return `The arguments passed into responsesAreSame() appear to be ` + `invalid. Please ensure valid Responses are used.`;
259
+ },
260
+ 'expire-custom-caches-only': () => {
261
+ return `You must provide a 'cacheName' property when using the ` + `expiration plugin with a runtime caching strategy.`;
262
+ },
263
+ 'unit-must-be-bytes': ({
264
+ normalizedRangeHeader
265
+ }) => {
266
+ if (!normalizedRangeHeader) {
267
+ throw new Error(`Unexpected input to 'unit-must-be-bytes' error.`);
268
+ }
269
+
270
+ return `The 'unit' portion of the Range header must be set to 'bytes'. ` + `The Range header provided was "${normalizedRangeHeader}"`;
271
+ },
272
+ 'single-range-only': ({
273
+ normalizedRangeHeader
274
+ }) => {
275
+ if (!normalizedRangeHeader) {
276
+ throw new Error(`Unexpected input to 'single-range-only' error.`);
277
+ }
278
+
279
+ return `Multiple ranges are not supported. Please use a single start ` + `value, and optional end value. The Range header provided was ` + `"${normalizedRangeHeader}"`;
280
+ },
281
+ 'invalid-range-values': ({
282
+ normalizedRangeHeader
283
+ }) => {
284
+ if (!normalizedRangeHeader) {
285
+ throw new Error(`Unexpected input to 'invalid-range-values' error.`);
286
+ }
287
+
288
+ return `The Range header is missing both start and end values. At least ` + `one of those values is needed. The Range header provided was ` + `"${normalizedRangeHeader}"`;
289
+ },
290
+ 'no-range-header': () => {
291
+ return `No Range header was found in the Request provided.`;
292
+ },
293
+ 'range-not-satisfiable': ({
294
+ size,
295
+ start,
296
+ end
297
+ }) => {
298
+ return `The start (${start}) and end (${end}) values in the Range are ` + `not satisfiable by the cached response, which is ${size} bytes.`;
299
+ },
300
+ 'attempt-to-cache-non-get-request': ({
301
+ url,
302
+ method
303
+ }) => {
304
+ return `Unable to cache '${url}' because it is a '${method}' request and ` + `only 'GET' requests can be cached.`;
305
+ },
306
+ 'cache-put-with-no-response': ({
307
+ url
308
+ }) => {
309
+ return `There was an attempt to cache '${url}' but the response was not ` + `defined.`;
310
+ },
311
+ 'no-response': ({
312
+ url,
313
+ error
314
+ }) => {
315
+ let message = `The strategy could not generate a response for '${url}'.`;
316
+
317
+ if (error) {
318
+ message += ` The underlying error is ${error}.`;
319
+ }
320
+
321
+ return message;
322
+ },
323
+ 'bad-precaching-response': ({
324
+ url,
325
+ status
326
+ }) => {
327
+ return `The precaching request for '${url}' failed with an HTTP ` + `status of ${status}.`;
328
+ }
329
+ };
330
+
331
+ /*
332
+ Copyright 2018 Google LLC
333
+
334
+ Use of this source code is governed by an MIT-style
335
+ license that can be found in the LICENSE file or at
336
+ https://opensource.org/licenses/MIT.
337
+ */
338
+
339
+ const generatorFunction = (code, details = {}) => {
340
+ const message = messages[code];
341
+
342
+ if (!message) {
343
+ throw new Error(`Unable to find message for code '${code}'.`);
344
+ }
345
+
346
+ return message(details);
347
+ };
348
+
349
+ const messageGenerator = generatorFunction;
350
+
351
+ /*
352
+ Copyright 2018 Google LLC
353
+
354
+ Use of this source code is governed by an MIT-style
355
+ license that can be found in the LICENSE file or at
356
+ https://opensource.org/licenses/MIT.
357
+ */
358
+ /**
359
+ * Workbox errors should be thrown with this class.
360
+ * This allows use to ensure the type easily in tests,
361
+ * helps developers identify errors from workbox
362
+ * easily and allows use to optimise error
363
+ * messages correctly.
364
+ *
365
+ * @private
366
+ */
367
+
368
+ class WorkboxError extends Error {
369
+ /**
370
+ *
371
+ * @param {string} errorCode The error code that
372
+ * identifies this particular error.
373
+ * @param {Object=} details Any relevant arguments
374
+ * that will help developers identify issues should
375
+ * be added as a key on the context object.
376
+ */
377
+ constructor(errorCode, details) {
378
+ let message = messageGenerator(errorCode, details);
379
+ super(message);
380
+ this.name = errorCode;
381
+ this.details = details;
382
+ }
383
+
384
+ }
385
+
386
+ /*
387
+ Copyright 2018 Google LLC
388
+
389
+ Use of this source code is governed by an MIT-style
390
+ license that can be found in the LICENSE file or at
391
+ https://opensource.org/licenses/MIT.
392
+ */
393
+ /*
394
+ * This method returns true if the current context is a service worker.
395
+ */
396
+
397
+ const isSWEnv = moduleName => {
398
+ if (!('ServiceWorkerGlobalScope' in self)) {
399
+ throw new WorkboxError('not-in-sw', {
400
+ moduleName
401
+ });
402
+ }
403
+ };
404
+ /*
405
+ * This method throws if the supplied value is not an array.
406
+ * The destructed values are required to produce a meaningful error for users.
407
+ * The destructed and restructured object is so it's clear what is
408
+ * needed.
409
+ */
410
+
411
+
412
+ const isArray = (value, details) => {
413
+ if (!Array.isArray(value)) {
414
+ throw new WorkboxError('not-an-array', details);
415
+ }
416
+ };
417
+
418
+ const hasMethod = (object, expectedMethod, details) => {
419
+ const type = typeof object[expectedMethod];
420
+
421
+ if (type !== 'function') {
422
+ details.expectedMethod = expectedMethod;
423
+ throw new WorkboxError('missing-a-method', details);
424
+ }
425
+ };
426
+
427
+ const isType = (object, expectedType, details) => {
428
+ if (typeof object !== expectedType) {
429
+ details.expectedType = expectedType;
430
+ throw new WorkboxError('incorrect-type', details);
431
+ }
432
+ };
433
+
434
+ const isInstance = (object, expectedClass, details) => {
435
+ if (!(object instanceof expectedClass)) {
436
+ details.expectedClass = expectedClass;
437
+ throw new WorkboxError('incorrect-class', details);
438
+ }
439
+ };
440
+
441
+ const isOneOf = (value, validValues, details) => {
442
+ if (!validValues.includes(value)) {
443
+ details.validValueDescription = `Valid values are ${JSON.stringify(validValues)}.`;
444
+ throw new WorkboxError('invalid-value', details);
445
+ }
446
+ };
447
+
448
+ const isArrayOfClass = (value, expectedClass, details) => {
449
+ const error = new WorkboxError('not-array-of-class', details);
450
+
451
+ if (!Array.isArray(value)) {
452
+ throw error;
453
+ }
454
+
455
+ for (let item of value) {
456
+ if (!(item instanceof expectedClass)) {
457
+ throw error;
458
+ }
459
+ }
460
+ };
461
+
462
+ const finalAssertExports = {
463
+ hasMethod,
464
+ isArray,
465
+ isInstance,
466
+ isOneOf,
467
+ isSWEnv,
468
+ isType,
469
+ isArrayOfClass
470
+ };
471
+
472
+ /*
473
+ Copyright 2018 Google LLC
474
+
475
+ Use of this source code is governed by an MIT-style
476
+ license that can be found in the LICENSE file or at
477
+ https://opensource.org/licenses/MIT.
478
+ */
479
+
480
+ const quotaErrorCallbacks = new Set();
481
+
482
+ /*
483
+ Copyright 2019 Google LLC
484
+
485
+ Use of this source code is governed by an MIT-style
486
+ license that can be found in the LICENSE file or at
487
+ https://opensource.org/licenses/MIT.
488
+ */
489
+ /**
490
+ * Adds a function to the set of quotaErrorCallbacks that will be executed if
491
+ * there's a quota error.
492
+ *
493
+ * @param {Function} callback
494
+ * @memberof workbox.core
495
+ */
496
+
497
+ function registerQuotaErrorCallback(callback) {
498
+ {
499
+ finalAssertExports.isType(callback, 'function', {
500
+ moduleName: 'workbox-core',
501
+ funcName: 'register',
502
+ paramName: 'callback'
503
+ });
504
+ }
505
+
506
+ quotaErrorCallbacks.add(callback);
507
+
508
+ {
509
+ logger.log('Registered a callback to respond to quota errors.', callback);
510
+ }
511
+ }
512
+
513
+ /*
514
+ Copyright 2018 Google LLC
515
+
516
+ Use of this source code is governed by an MIT-style
517
+ license that can be found in the LICENSE file or at
518
+ https://opensource.org/licenses/MIT.
519
+ */
520
+ const _cacheNameDetails = {
521
+ googleAnalytics: 'googleAnalytics',
522
+ precache: 'precache-v2',
523
+ prefix: 'workbox',
524
+ runtime: 'runtime',
525
+ suffix: registration.scope
526
+ };
527
+
528
+ const _createCacheName = cacheName => {
529
+ return [_cacheNameDetails.prefix, cacheName, _cacheNameDetails.suffix].filter(value => value && value.length > 0).join('-');
530
+ };
531
+
532
+ const eachCacheNameDetail = fn => {
533
+ for (const key of Object.keys(_cacheNameDetails)) {
534
+ fn(key);
535
+ }
536
+ };
537
+
538
+ const cacheNames = {
539
+ updateDetails: details => {
540
+ eachCacheNameDetail(key => {
541
+ if (typeof details[key] === 'string') {
542
+ _cacheNameDetails[key] = details[key];
543
+ }
544
+ });
545
+ },
546
+ getGoogleAnalyticsName: userCacheName => {
547
+ return userCacheName || _createCacheName(_cacheNameDetails.googleAnalytics);
548
+ },
549
+ getPrecacheName: userCacheName => {
550
+ return userCacheName || _createCacheName(_cacheNameDetails.precache);
551
+ },
552
+ getPrefix: () => {
553
+ return _cacheNameDetails.prefix;
554
+ },
555
+ getRuntimeName: userCacheName => {
556
+ return userCacheName || _createCacheName(_cacheNameDetails.runtime);
557
+ },
558
+ getSuffix: () => {
559
+ return _cacheNameDetails.suffix;
560
+ }
561
+ };
562
+
563
+ /*
564
+ Copyright 2018 Google LLC
565
+
566
+ Use of this source code is governed by an MIT-style
567
+ license that can be found in the LICENSE file or at
568
+ https://opensource.org/licenses/MIT.
569
+ */
570
+
571
+ const getFriendlyURL = url => {
572
+ const urlObj = new URL(String(url), location.href);
573
+
574
+ if (urlObj.origin === location.origin) {
575
+ return urlObj.pathname;
576
+ }
577
+
578
+ return urlObj.href;
579
+ };
580
+
581
+ /*
582
+ Copyright 2018 Google LLC
583
+
584
+ Use of this source code is governed by an MIT-style
585
+ license that can be found in the LICENSE file or at
586
+ https://opensource.org/licenses/MIT.
587
+ */
588
+ /**
589
+ * Runs all of the callback functions, one at a time sequentially, in the order
590
+ * in which they were registered.
591
+ *
592
+ * @memberof workbox.core
593
+ * @private
594
+ */
595
+
596
+ async function executeQuotaErrorCallbacks() {
597
+ {
598
+ logger.log(`About to run ${quotaErrorCallbacks.size} ` + `callbacks to clean up caches.`);
599
+ }
600
+
601
+ for (const callback of quotaErrorCallbacks) {
602
+ await callback();
603
+
604
+ {
605
+ logger.log(callback, 'is complete.');
606
+ }
607
+ }
608
+
609
+ {
610
+ logger.log('Finished running callbacks.');
611
+ }
612
+ }
613
+
614
+ /*
615
+ Copyright 2018 Google LLC
616
+
617
+ Use of this source code is governed by an MIT-style
618
+ license that can be found in the LICENSE file or at
619
+ https://opensource.org/licenses/MIT.
620
+ */
621
+ const pluginUtils = {
622
+ filter: (plugins, callbackName) => {
623
+ return plugins.filter(plugin => callbackName in plugin);
624
+ }
625
+ };
626
+
627
+ /*
628
+ Copyright 2018 Google LLC
629
+
630
+ Use of this source code is governed by an MIT-style
631
+ license that can be found in the LICENSE file or at
632
+ https://opensource.org/licenses/MIT.
633
+ */
634
+ /**
635
+ * Wrapper around cache.put().
636
+ *
637
+ * Will call `cacheDidUpdate` on plugins if the cache was updated, using
638
+ * `matchOptions` when determining what the old entry is.
639
+ *
640
+ * @param {Object} options
641
+ * @param {string} options.cacheName
642
+ * @param {Request} options.request
643
+ * @param {Response} options.response
644
+ * @param {Event} [options.event]
645
+ * @param {Array<Object>} [options.plugins=[]]
646
+ * @param {Object} [options.matchOptions]
647
+ *
648
+ * @private
649
+ * @memberof module:workbox-core
650
+ */
651
+
652
+ const putWrapper = async ({
653
+ cacheName,
654
+ request,
655
+ response,
656
+ event,
657
+ plugins = [],
658
+ matchOptions
659
+ }) => {
660
+ {
661
+ if (request.method && request.method !== 'GET') {
662
+ throw new WorkboxError('attempt-to-cache-non-get-request', {
663
+ url: getFriendlyURL(request.url),
664
+ method: request.method
665
+ });
666
+ }
667
+ }
668
+
669
+ const effectiveRequest = await _getEffectiveRequest({
670
+ plugins,
671
+ request,
672
+ mode: 'write'
673
+ });
674
+
675
+ if (!response) {
676
+ {
677
+ logger.error(`Cannot cache non-existent response for ` + `'${getFriendlyURL(effectiveRequest.url)}'.`);
678
+ }
679
+
680
+ throw new WorkboxError('cache-put-with-no-response', {
681
+ url: getFriendlyURL(effectiveRequest.url)
682
+ });
683
+ }
684
+
685
+ let responseToCache = await _isResponseSafeToCache({
686
+ event,
687
+ plugins,
688
+ response,
689
+ request: effectiveRequest
690
+ });
691
+
692
+ if (!responseToCache) {
693
+ {
694
+ logger.debug(`Response '${getFriendlyURL(effectiveRequest.url)}' will ` + `not be cached.`, responseToCache);
695
+ }
696
+
697
+ return;
698
+ }
699
+
700
+ const cache = await caches.open(cacheName);
701
+ const updatePlugins = pluginUtils.filter(plugins, "cacheDidUpdate"
702
+ /* CACHE_DID_UPDATE */
703
+ );
704
+ let oldResponse = updatePlugins.length > 0 ? await matchWrapper({
705
+ cacheName,
706
+ matchOptions,
707
+ request: effectiveRequest
708
+ }) : null;
709
+
710
+ {
711
+ logger.debug(`Updating the '${cacheName}' cache with a new Response for ` + `${getFriendlyURL(effectiveRequest.url)}.`);
712
+ }
713
+
714
+ try {
715
+ await cache.put(effectiveRequest, responseToCache);
716
+ } catch (error) {
717
+ // See https://developer.mozilla.org/en-US/docs/Web/API/DOMException#exception-QuotaExceededError
718
+ if (error.name === 'QuotaExceededError') {
719
+ await executeQuotaErrorCallbacks();
720
+ }
721
+
722
+ throw error;
723
+ }
724
+
725
+ for (let plugin of updatePlugins) {
726
+ await plugin["cacheDidUpdate"
727
+ /* CACHE_DID_UPDATE */
728
+ ].call(plugin, {
729
+ cacheName,
730
+ event,
731
+ oldResponse,
732
+ newResponse: responseToCache,
733
+ request: effectiveRequest
734
+ });
735
+ }
736
+ };
737
+ /**
738
+ * This is a wrapper around cache.match().
739
+ *
740
+ * @param {Object} options
741
+ * @param {string} options.cacheName Name of the cache to match against.
742
+ * @param {Request} options.request The Request that will be used to look up
743
+ * cache entries.
744
+ * @param {Event} [options.event] The event that propted the action.
745
+ * @param {Object} [options.matchOptions] Options passed to cache.match().
746
+ * @param {Array<Object>} [options.plugins=[]] Array of plugins.
747
+ * @return {Response} A cached response if available.
748
+ *
749
+ * @private
750
+ * @memberof module:workbox-core
751
+ */
752
+
753
+
754
+ const matchWrapper = async ({
755
+ cacheName,
756
+ request,
757
+ event,
758
+ matchOptions,
759
+ plugins = []
760
+ }) => {
761
+ const cache = await caches.open(cacheName);
762
+ const effectiveRequest = await _getEffectiveRequest({
763
+ plugins,
764
+ request,
765
+ mode: 'read'
766
+ });
767
+ let cachedResponse = await cache.match(effectiveRequest, matchOptions);
768
+
769
+ {
770
+ if (cachedResponse) {
771
+ logger.debug(`Found a cached response in '${cacheName}'.`);
772
+ } else {
773
+ logger.debug(`No cached response found in '${cacheName}'.`);
774
+ }
775
+ }
776
+
777
+ for (const plugin of plugins) {
778
+ if ("cachedResponseWillBeUsed"
779
+ /* CACHED_RESPONSE_WILL_BE_USED */
780
+ in plugin) {
781
+ const pluginMethod = plugin["cachedResponseWillBeUsed"
782
+ /* CACHED_RESPONSE_WILL_BE_USED */
783
+ ];
784
+ cachedResponse = await pluginMethod.call(plugin, {
785
+ cacheName,
786
+ event,
787
+ matchOptions,
788
+ cachedResponse,
789
+ request: effectiveRequest
790
+ });
791
+
792
+ {
793
+ if (cachedResponse) {
794
+ finalAssertExports.isInstance(cachedResponse, Response, {
795
+ moduleName: 'Plugin',
796
+ funcName: "cachedResponseWillBeUsed"
797
+ /* CACHED_RESPONSE_WILL_BE_USED */
798
+ ,
799
+ isReturnValueProblem: true
800
+ });
801
+ }
802
+ }
803
+ }
804
+ }
805
+
806
+ return cachedResponse;
807
+ };
808
+ /**
809
+ * This method will call cacheWillUpdate on the available plugins (or use
810
+ * status === 200) to determine if the Response is safe and valid to cache.
811
+ *
812
+ * @param {Object} options
813
+ * @param {Request} options.request
814
+ * @param {Response} options.response
815
+ * @param {Event} [options.event]
816
+ * @param {Array<Object>} [options.plugins=[]]
817
+ * @return {Promise<Response>}
818
+ *
819
+ * @private
820
+ * @memberof module:workbox-core
821
+ */
822
+
823
+
824
+ const _isResponseSafeToCache = async ({
825
+ request,
826
+ response,
827
+ event,
828
+ plugins = []
829
+ }) => {
830
+ let responseToCache = response;
831
+ let pluginsUsed = false;
832
+
833
+ for (let plugin of plugins) {
834
+ if ("cacheWillUpdate"
835
+ /* CACHE_WILL_UPDATE */
836
+ in plugin) {
837
+ pluginsUsed = true;
838
+ const pluginMethod = plugin["cacheWillUpdate"
839
+ /* CACHE_WILL_UPDATE */
840
+ ];
841
+ responseToCache = await pluginMethod.call(plugin, {
842
+ request,
843
+ response: responseToCache,
844
+ event
845
+ });
846
+
847
+ {
848
+ if (responseToCache) {
849
+ finalAssertExports.isInstance(responseToCache, Response, {
850
+ moduleName: 'Plugin',
851
+ funcName: "cacheWillUpdate"
852
+ /* CACHE_WILL_UPDATE */
853
+ ,
854
+ isReturnValueProblem: true
855
+ });
856
+ }
857
+ }
858
+
859
+ if (!responseToCache) {
860
+ break;
861
+ }
862
+ }
863
+ }
864
+
865
+ if (!pluginsUsed) {
866
+ {
867
+ if (responseToCache) {
868
+ if (responseToCache.status !== 200) {
869
+ if (responseToCache.status === 0) {
870
+ logger.warn(`The response for '${request.url}' is an opaque ` + `response. The caching strategy that you're using will not ` + `cache opaque responses by default.`);
871
+ } else {
872
+ logger.debug(`The response for '${request.url}' returned ` + `a status code of '${response.status}' and won't be cached as a ` + `result.`);
873
+ }
874
+ }
875
+ }
876
+ }
877
+
878
+ responseToCache = responseToCache && responseToCache.status === 200 ? responseToCache : undefined;
879
+ }
880
+
881
+ return responseToCache ? responseToCache : null;
882
+ };
883
+ /**
884
+ * Checks the list of plugins for the cacheKeyWillBeUsed callback, and
885
+ * executes any of those callbacks found in sequence. The final `Request` object
886
+ * returned by the last plugin is treated as the cache key for cache reads
887
+ * and/or writes.
888
+ *
889
+ * @param {Object} options
890
+ * @param {Request} options.request
891
+ * @param {string} options.mode
892
+ * @param {Array<Object>} [options.plugins=[]]
893
+ * @return {Promise<Request>}
894
+ *
895
+ * @private
896
+ * @memberof module:workbox-core
897
+ */
898
+
899
+
900
+ const _getEffectiveRequest = async ({
901
+ request,
902
+ mode,
903
+ plugins = []
904
+ }) => {
905
+ const cacheKeyWillBeUsedPlugins = pluginUtils.filter(plugins, "cacheKeyWillBeUsed"
906
+ /* CACHE_KEY_WILL_BE_USED */
907
+ );
908
+ let effectiveRequest = request;
909
+
910
+ for (const plugin of cacheKeyWillBeUsedPlugins) {
911
+ effectiveRequest = await plugin["cacheKeyWillBeUsed"
912
+ /* CACHE_KEY_WILL_BE_USED */
913
+ ].call(plugin, {
914
+ mode,
915
+ request: effectiveRequest
916
+ });
917
+
918
+ if (typeof effectiveRequest === 'string') {
919
+ effectiveRequest = new Request(effectiveRequest);
920
+ }
921
+
922
+ {
923
+ finalAssertExports.isInstance(effectiveRequest, Request, {
924
+ moduleName: 'Plugin',
925
+ funcName: "cacheKeyWillBeUsed"
926
+ /* CACHE_KEY_WILL_BE_USED */
927
+ ,
928
+ isReturnValueProblem: true
929
+ });
930
+ }
931
+ }
932
+
933
+ return effectiveRequest;
934
+ };
935
+
936
+ const cacheWrapper = {
937
+ put: putWrapper,
938
+ match: matchWrapper
939
+ };
940
+
941
+ /*
942
+ Copyright 2018 Google LLC
943
+
944
+ Use of this source code is governed by an MIT-style
945
+ license that can be found in the LICENSE file or at
946
+ https://opensource.org/licenses/MIT.
947
+ */
948
+ /**
949
+ * A class that wraps common IndexedDB functionality in a promise-based API.
950
+ * It exposes all the underlying power and functionality of IndexedDB, but
951
+ * wraps the most commonly used features in a way that's much simpler to use.
952
+ *
953
+ * @private
954
+ */
955
+
956
+ class DBWrapper {
957
+ /**
958
+ * @param {string} name
959
+ * @param {number} version
960
+ * @param {Object=} [callback]
961
+ * @param {!Function} [callbacks.onupgradeneeded]
962
+ * @param {!Function} [callbacks.onversionchange] Defaults to
963
+ * DBWrapper.prototype._onversionchange when not specified.
964
+ * @private
965
+ */
966
+ constructor(name, version, {
967
+ onupgradeneeded,
968
+ onversionchange
969
+ } = {}) {
970
+ this._db = null;
971
+ this._name = name;
972
+ this._version = version;
973
+ this._onupgradeneeded = onupgradeneeded;
974
+
975
+ this._onversionchange = onversionchange || (() => this.close());
976
+ }
977
+ /**
978
+ * Returns the IDBDatabase instance (not normally needed).
979
+ * @return {IDBDatabase|undefined}
980
+ *
981
+ * @private
982
+ */
983
+
984
+
985
+ get db() {
986
+ return this._db;
987
+ }
988
+ /**
989
+ * Opens a connected to an IDBDatabase, invokes any onupgradedneeded
990
+ * callback, and added an onversionchange callback to the database.
991
+ *
992
+ * @return {IDBDatabase}
993
+ * @private
994
+ */
995
+
996
+
997
+ async open() {
998
+ if (this._db) return;
999
+ this._db = await new Promise((resolve, reject) => {
1000
+ // This flag is flipped to true if the timeout callback runs prior
1001
+ // to the request failing or succeeding. Note: we use a timeout instead
1002
+ // of an onblocked handler since there are cases where onblocked will
1003
+ // never never run. A timeout better handles all possible scenarios:
1004
+ // https://github.com/w3c/IndexedDB/issues/223
1005
+ let openRequestTimedOut = false;
1006
+ setTimeout(() => {
1007
+ openRequestTimedOut = true;
1008
+ reject(new Error('The open request was blocked and timed out'));
1009
+ }, this.OPEN_TIMEOUT);
1010
+ const openRequest = indexedDB.open(this._name, this._version);
1011
+
1012
+ openRequest.onerror = () => reject(openRequest.error);
1013
+
1014
+ openRequest.onupgradeneeded = evt => {
1015
+ if (openRequestTimedOut) {
1016
+ openRequest.transaction.abort();
1017
+ openRequest.result.close();
1018
+ } else if (typeof this._onupgradeneeded === 'function') {
1019
+ this._onupgradeneeded(evt);
1020
+ }
1021
+ };
1022
+
1023
+ openRequest.onsuccess = () => {
1024
+ const db = openRequest.result;
1025
+
1026
+ if (openRequestTimedOut) {
1027
+ db.close();
1028
+ } else {
1029
+ db.onversionchange = this._onversionchange.bind(this);
1030
+ resolve(db);
1031
+ }
1032
+ };
1033
+ });
1034
+ return this;
1035
+ }
1036
+ /**
1037
+ * Polyfills the native `getKey()` method. Note, this is overridden at
1038
+ * runtime if the browser supports the native method.
1039
+ *
1040
+ * @param {string} storeName
1041
+ * @param {*} query
1042
+ * @return {Array}
1043
+ * @private
1044
+ */
1045
+
1046
+
1047
+ async getKey(storeName, query) {
1048
+ return (await this.getAllKeys(storeName, query, 1))[0];
1049
+ }
1050
+ /**
1051
+ * Polyfills the native `getAll()` method. Note, this is overridden at
1052
+ * runtime if the browser supports the native method.
1053
+ *
1054
+ * @param {string} storeName
1055
+ * @param {*} query
1056
+ * @param {number} count
1057
+ * @return {Array}
1058
+ * @private
1059
+ */
1060
+
1061
+
1062
+ async getAll(storeName, query, count) {
1063
+ return await this.getAllMatching(storeName, {
1064
+ query,
1065
+ count
1066
+ });
1067
+ }
1068
+ /**
1069
+ * Polyfills the native `getAllKeys()` method. Note, this is overridden at
1070
+ * runtime if the browser supports the native method.
1071
+ *
1072
+ * @param {string} storeName
1073
+ * @param {*} query
1074
+ * @param {number} count
1075
+ * @return {Array}
1076
+ * @private
1077
+ */
1078
+
1079
+
1080
+ async getAllKeys(storeName, query, count) {
1081
+ const entries = await this.getAllMatching(storeName, {
1082
+ query,
1083
+ count,
1084
+ includeKeys: true
1085
+ });
1086
+ return entries.map(entry => entry.key);
1087
+ }
1088
+ /**
1089
+ * Supports flexible lookup in an object store by specifying an index,
1090
+ * query, direction, and count. This method returns an array of objects
1091
+ * with the signature .
1092
+ *
1093
+ * @param {string} storeName
1094
+ * @param {Object} [opts]
1095
+ * @param {string} [opts.index] The index to use (if specified).
1096
+ * @param {*} [opts.query]
1097
+ * @param {IDBCursorDirection} [opts.direction]
1098
+ * @param {number} [opts.count] The max number of results to return.
1099
+ * @param {boolean} [opts.includeKeys] When true, the structure of the
1100
+ * returned objects is changed from an array of values to an array of
1101
+ * objects in the form {key, primaryKey, value}.
1102
+ * @return {Array}
1103
+ * @private
1104
+ */
1105
+
1106
+
1107
+ async getAllMatching(storeName, {
1108
+ index,
1109
+ query = null,
1110
+ // IE/Edge errors if query === `undefined`.
1111
+ direction = 'next',
1112
+ count,
1113
+ includeKeys = false
1114
+ } = {}) {
1115
+ return await this.transaction([storeName], 'readonly', (txn, done) => {
1116
+ const store = txn.objectStore(storeName);
1117
+ const target = index ? store.index(index) : store;
1118
+ const results = [];
1119
+ const request = target.openCursor(query, direction);
1120
+
1121
+ request.onsuccess = () => {
1122
+ const cursor = request.result;
1123
+
1124
+ if (cursor) {
1125
+ results.push(includeKeys ? cursor : cursor.value);
1126
+
1127
+ if (count && results.length >= count) {
1128
+ done(results);
1129
+ } else {
1130
+ cursor.continue();
1131
+ }
1132
+ } else {
1133
+ done(results);
1134
+ }
1135
+ };
1136
+ });
1137
+ }
1138
+ /**
1139
+ * Accepts a list of stores, a transaction type, and a callback and
1140
+ * performs a transaction. A promise is returned that resolves to whatever
1141
+ * value the callback chooses. The callback holds all the transaction logic
1142
+ * and is invoked with two arguments:
1143
+ * 1. The IDBTransaction object
1144
+ * 2. A `done` function, that's used to resolve the promise when
1145
+ * when the transaction is done, if passed a value, the promise is
1146
+ * resolved to that value.
1147
+ *
1148
+ * @param {Array<string>} storeNames An array of object store names
1149
+ * involved in the transaction.
1150
+ * @param {string} type Can be `readonly` or `readwrite`.
1151
+ * @param {!Function} callback
1152
+ * @return {*} The result of the transaction ran by the callback.
1153
+ * @private
1154
+ */
1155
+
1156
+
1157
+ async transaction(storeNames, type, callback) {
1158
+ await this.open();
1159
+ return await new Promise((resolve, reject) => {
1160
+ const txn = this._db.transaction(storeNames, type);
1161
+
1162
+ txn.onabort = () => reject(txn.error);
1163
+
1164
+ txn.oncomplete = () => resolve();
1165
+
1166
+ callback(txn, value => resolve(value));
1167
+ });
1168
+ }
1169
+ /**
1170
+ * Delegates async to a native IDBObjectStore method.
1171
+ *
1172
+ * @param {string} method The method name.
1173
+ * @param {string} storeName The object store name.
1174
+ * @param {string} type Can be `readonly` or `readwrite`.
1175
+ * @param {...*} args The list of args to pass to the native method.
1176
+ * @return {*} The result of the transaction.
1177
+ * @private
1178
+ */
1179
+
1180
+
1181
+ async _call(method, storeName, type, ...args) {
1182
+ const callback = (txn, done) => {
1183
+ const objStore = txn.objectStore(storeName);
1184
+ const request = objStore[method].apply(objStore, args);
1185
+
1186
+ request.onsuccess = () => done(request.result);
1187
+ };
1188
+
1189
+ return await this.transaction([storeName], type, callback);
1190
+ }
1191
+ /**
1192
+ * Closes the connection opened by `DBWrapper.open()`. Generally this method
1193
+ * doesn't need to be called since:
1194
+ * 1. It's usually better to keep a connection open since opening
1195
+ * a new connection is somewhat slow.
1196
+ * 2. Connections are automatically closed when the reference is
1197
+ * garbage collected.
1198
+ * The primary use case for needing to close a connection is when another
1199
+ * reference (typically in another tab) needs to upgrade it and would be
1200
+ * blocked by the current, open connection.
1201
+ *
1202
+ * @private
1203
+ */
1204
+
1205
+
1206
+ close() {
1207
+ if (this._db) {
1208
+ this._db.close();
1209
+
1210
+ this._db = null;
1211
+ }
1212
+ }
1213
+
1214
+ } // Exposed on the prototype to let users modify the default timeout on a
1215
+ // per-instance or global basis.
1216
+
1217
+ DBWrapper.prototype.OPEN_TIMEOUT = 2000; // Wrap native IDBObjectStore methods according to their mode.
1218
+
1219
+ const methodsToWrap = {
1220
+ readonly: ['get', 'count', 'getKey', 'getAll', 'getAllKeys'],
1221
+ readwrite: ['add', 'put', 'clear', 'delete']
1222
+ };
1223
+
1224
+ for (const [mode, methods] of Object.entries(methodsToWrap)) {
1225
+ for (const method of methods) {
1226
+ if (method in IDBObjectStore.prototype) {
1227
+ // Don't use arrow functions here since we're outside of the class.
1228
+ DBWrapper.prototype[method] = async function (storeName, ...args) {
1229
+ return await this._call(method, storeName, mode, ...args);
1230
+ };
1231
+ }
1232
+ }
1233
+ }
1234
+
1235
+ /*
1236
+ Copyright 2018 Google LLC
1237
+
1238
+ Use of this source code is governed by an MIT-style
1239
+ license that can be found in the LICENSE file or at
1240
+ https://opensource.org/licenses/MIT.
1241
+ */
1242
+ /**
1243
+ * The Deferred class composes Promises in a way that allows for them to be
1244
+ * resolved or rejected from outside the constructor. In most cases promises
1245
+ * should be used directly, but Deferreds can be necessary when the logic to
1246
+ * resolve a promise must be separate.
1247
+ *
1248
+ * @private
1249
+ */
1250
+
1251
+ class Deferred {
1252
+ /**
1253
+ * Creates a promise and exposes its resolve and reject functions as methods.
1254
+ */
1255
+ constructor() {
1256
+ this.promise = new Promise((resolve, reject) => {
1257
+ this.resolve = resolve;
1258
+ this.reject = reject;
1259
+ });
1260
+ }
1261
+
1262
+ }
1263
+
1264
+ /*
1265
+ Copyright 2018 Google LLC
1266
+
1267
+ Use of this source code is governed by an MIT-style
1268
+ license that can be found in the LICENSE file or at
1269
+ https://opensource.org/licenses/MIT.
1270
+ */
1271
+ /**
1272
+ * Deletes the database.
1273
+ * Note: this is exported separately from the DBWrapper module because most
1274
+ * usages of IndexedDB in workbox dont need deleting, and this way it can be
1275
+ * reused in tests to delete databases without creating DBWrapper instances.
1276
+ *
1277
+ * @param {string} name The database name.
1278
+ * @private
1279
+ */
1280
+
1281
+ const deleteDatabase = async name => {
1282
+ await new Promise((resolve, reject) => {
1283
+ const request = indexedDB.deleteDatabase(name);
1284
+
1285
+ request.onerror = () => {
1286
+ reject(request.error);
1287
+ };
1288
+
1289
+ request.onblocked = () => {
1290
+ reject(new Error('Delete blocked'));
1291
+ };
1292
+
1293
+ request.onsuccess = () => {
1294
+ resolve();
1295
+ };
1296
+ });
1297
+ };
1298
+
1299
+ /*
1300
+ Copyright 2018 Google LLC
1301
+
1302
+ Use of this source code is governed by an MIT-style
1303
+ license that can be found in the LICENSE file or at
1304
+ https://opensource.org/licenses/MIT.
1305
+ */
1306
+ /**
1307
+ * Wrapper around the fetch API.
1308
+ *
1309
+ * Will call requestWillFetch on available plugins.
1310
+ *
1311
+ * @param {Object} options
1312
+ * @param {Request|string} options.request
1313
+ * @param {Object} [options.fetchOptions]
1314
+ * @param {Event} [options.event]
1315
+ * @param {Array<Object>} [options.plugins=[]]
1316
+ * @return {Promise<Response>}
1317
+ *
1318
+ * @private
1319
+ * @memberof module:workbox-core
1320
+ */
1321
+
1322
+ const wrappedFetch = async ({
1323
+ request,
1324
+ fetchOptions,
1325
+ event,
1326
+ plugins = []
1327
+ }) => {
1328
+ if (typeof request === 'string') {
1329
+ request = new Request(request);
1330
+ } // We *should* be able to call `await event.preloadResponse` even if it's
1331
+ // undefined, but for some reason, doing so leads to errors in our Node unit
1332
+ // tests. To work around that, explicitly check preloadResponse's value first.
1333
+
1334
+
1335
+ if (event instanceof FetchEvent && event.preloadResponse) {
1336
+ const possiblePreloadResponse = await event.preloadResponse;
1337
+
1338
+ if (possiblePreloadResponse) {
1339
+ {
1340
+ logger.log(`Using a preloaded navigation response for ` + `'${getFriendlyURL(request.url)}'`);
1341
+ }
1342
+
1343
+ return possiblePreloadResponse;
1344
+ }
1345
+ }
1346
+
1347
+ {
1348
+ finalAssertExports.isInstance(request, Request, {
1349
+ paramName: 'request',
1350
+ expectedClass: Request,
1351
+ moduleName: 'workbox-core',
1352
+ className: 'fetchWrapper',
1353
+ funcName: 'wrappedFetch'
1354
+ });
1355
+ }
1356
+
1357
+ const failedFetchPlugins = pluginUtils.filter(plugins, "fetchDidFail"
1358
+ /* FETCH_DID_FAIL */
1359
+ ); // If there is a fetchDidFail plugin, we need to save a clone of the
1360
+ // original request before it's either modified by a requestWillFetch
1361
+ // plugin or before the original request's body is consumed via fetch().
1362
+
1363
+ const originalRequest = failedFetchPlugins.length > 0 ? request.clone() : null;
1364
+
1365
+ try {
1366
+ for (let plugin of plugins) {
1367
+ if ("requestWillFetch"
1368
+ /* REQUEST_WILL_FETCH */
1369
+ in plugin) {
1370
+ const pluginMethod = plugin["requestWillFetch"
1371
+ /* REQUEST_WILL_FETCH */
1372
+ ];
1373
+ const requestClone = request.clone();
1374
+ request = await pluginMethod.call(plugin, {
1375
+ request: requestClone,
1376
+ event
1377
+ });
1378
+
1379
+ if ("dev" !== 'production') {
1380
+ if (request) {
1381
+ finalAssertExports.isInstance(request, Request, {
1382
+ moduleName: 'Plugin',
1383
+ funcName: "cachedResponseWillBeUsed"
1384
+ /* CACHED_RESPONSE_WILL_BE_USED */
1385
+ ,
1386
+ isReturnValueProblem: true
1387
+ });
1388
+ }
1389
+ }
1390
+ }
1391
+ }
1392
+ } catch (err) {
1393
+ throw new WorkboxError('plugin-error-request-will-fetch', {
1394
+ thrownError: err
1395
+ });
1396
+ } // The request can be altered by plugins with `requestWillFetch` making
1397
+ // the original request (Most likely from a `fetch` event) to be different
1398
+ // to the Request we make. Pass both to `fetchDidFail` to aid debugging.
1399
+
1400
+
1401
+ let pluginFilteredRequest = request.clone();
1402
+
1403
+ try {
1404
+ let fetchResponse; // See https://github.com/GoogleChrome/workbox/issues/1796
1405
+
1406
+ if (request.mode === 'navigate') {
1407
+ fetchResponse = await fetch(request);
1408
+ } else {
1409
+ fetchResponse = await fetch(request, fetchOptions);
1410
+ }
1411
+
1412
+ if ("dev" !== 'production') {
1413
+ logger.debug(`Network request for ` + `'${getFriendlyURL(request.url)}' returned a response with ` + `status '${fetchResponse.status}'.`);
1414
+ }
1415
+
1416
+ for (const plugin of plugins) {
1417
+ if ("fetchDidSucceed"
1418
+ /* FETCH_DID_SUCCEED */
1419
+ in plugin) {
1420
+ fetchResponse = await plugin["fetchDidSucceed"
1421
+ /* FETCH_DID_SUCCEED */
1422
+ ].call(plugin, {
1423
+ event,
1424
+ request: pluginFilteredRequest,
1425
+ response: fetchResponse
1426
+ });
1427
+
1428
+ if ("dev" !== 'production') {
1429
+ if (fetchResponse) {
1430
+ finalAssertExports.isInstance(fetchResponse, Response, {
1431
+ moduleName: 'Plugin',
1432
+ funcName: "fetchDidSucceed"
1433
+ /* FETCH_DID_SUCCEED */
1434
+ ,
1435
+ isReturnValueProblem: true
1436
+ });
1437
+ }
1438
+ }
1439
+ }
1440
+ }
1441
+
1442
+ return fetchResponse;
1443
+ } catch (error) {
1444
+ {
1445
+ logger.error(`Network request for ` + `'${getFriendlyURL(request.url)}' threw an error.`, error);
1446
+ }
1447
+
1448
+ for (const plugin of failedFetchPlugins) {
1449
+ await plugin["fetchDidFail"
1450
+ /* FETCH_DID_FAIL */
1451
+ ].call(plugin, {
1452
+ error,
1453
+ event,
1454
+ originalRequest: originalRequest.clone(),
1455
+ request: pluginFilteredRequest.clone()
1456
+ });
1457
+ }
1458
+
1459
+ throw error;
1460
+ }
1461
+ };
1462
+
1463
+ const fetchWrapper = {
1464
+ fetch: wrappedFetch
1465
+ };
1466
+
1467
+ /*
1468
+ Copyright 2018 Google LLC
1469
+
1470
+ Use of this source code is governed by an MIT-style
1471
+ license that can be found in the LICENSE file or at
1472
+ https://opensource.org/licenses/MIT.
1473
+ */
1474
+
1475
+ var _private = /*#__PURE__*/Object.freeze({
1476
+ assert: finalAssertExports,
1477
+ cacheNames: cacheNames,
1478
+ cacheWrapper: cacheWrapper,
1479
+ DBWrapper: DBWrapper,
1480
+ Deferred: Deferred,
1481
+ deleteDatabase: deleteDatabase,
1482
+ executeQuotaErrorCallbacks: executeQuotaErrorCallbacks,
1483
+ fetchWrapper: fetchWrapper,
1484
+ getFriendlyURL: getFriendlyURL,
1485
+ logger: logger,
1486
+ WorkboxError: WorkboxError
1487
+ });
1488
+
1489
+ /*
1490
+ Copyright 2019 Google LLC
1491
+
1492
+ Use of this source code is governed by an MIT-style
1493
+ license that can be found in the LICENSE file or at
1494
+ https://opensource.org/licenses/MIT.
1495
+ */
1496
+ /**
1497
+ * Claim any currently available clients once the service worker
1498
+ * becomes active. This is normally used in conjunction with `skipWaiting()`.
1499
+ *
1500
+ * @alias workbox.core.clientsClaim
1501
+ */
1502
+
1503
+ const clientsClaim = () => {
1504
+ addEventListener('activate', () => self.clients.claim());
1505
+ };
1506
+
1507
+ /*
1508
+ Copyright 2019 Google LLC
1509
+
1510
+ Use of this source code is governed by an MIT-style
1511
+ license that can be found in the LICENSE file or at
1512
+ https://opensource.org/licenses/MIT.
1513
+ */
1514
+ /**
1515
+ * Get the current cache names and prefix/suffix used by Workbox.
1516
+ *
1517
+ * `cacheNames.precache` is used for precached assets,
1518
+ * `cacheNames.googleAnalytics` is used by `workbox-google-analytics` to
1519
+ * store `analytics.js`, and `cacheNames.runtime` is used for everything else.
1520
+ *
1521
+ * `cacheNames.prefix` can be used to retrieve just the current prefix value.
1522
+ * `cacheNames.suffix` can be used to retrieve just the current suffix value.
1523
+ *
1524
+ * @return {Object} An object with `precache`, `runtime`, `prefix`, and
1525
+ * `googleAnalytics` properties.
1526
+ *
1527
+ * @alias workbox.core.cacheNames
1528
+ */
1529
+
1530
+ const cacheNames$1 = {
1531
+ get googleAnalytics() {
1532
+ return cacheNames.getGoogleAnalyticsName();
1533
+ },
1534
+
1535
+ get precache() {
1536
+ return cacheNames.getPrecacheName();
1537
+ },
1538
+
1539
+ get prefix() {
1540
+ return cacheNames.getPrefix();
1541
+ },
1542
+
1543
+ get runtime() {
1544
+ return cacheNames.getRuntimeName();
1545
+ },
1546
+
1547
+ get suffix() {
1548
+ return cacheNames.getSuffix();
1549
+ }
1550
+
1551
+ };
1552
+
1553
+ /*
1554
+ Copyright 2019 Google LLC
1555
+
1556
+ Use of this source code is governed by an MIT-style
1557
+ license that can be found in the LICENSE file or at
1558
+ https://opensource.org/licenses/MIT.
1559
+ */
1560
+ /**
1561
+ * Modifies the default cache names used by the Workbox packages.
1562
+ * Cache names are generated as `<prefix>-<Cache Name>-<suffix>`.
1563
+ *
1564
+ * @param {Object} details
1565
+ * @param {Object} [details.prefix] The string to add to the beginning of
1566
+ * the precache and runtime cache names.
1567
+ * @param {Object} [details.suffix] The string to add to the end of
1568
+ * the precache and runtime cache names.
1569
+ * @param {Object} [details.precache] The cache name to use for precache
1570
+ * caching.
1571
+ * @param {Object} [details.runtime] The cache name to use for runtime caching.
1572
+ * @param {Object} [details.googleAnalytics] The cache name to use for
1573
+ * `workbox-google-analytics` caching.
1574
+ *
1575
+ * @alias workbox.core.setCacheNameDetails
1576
+ */
1577
+
1578
+ const setCacheNameDetails = details => {
1579
+ {
1580
+ Object.keys(details).forEach(key => {
1581
+ finalAssertExports.isType(details[key], 'string', {
1582
+ moduleName: 'workbox-core',
1583
+ funcName: 'setCacheNameDetails',
1584
+ paramName: `details.${key}`
1585
+ });
1586
+ });
1587
+
1588
+ if ('precache' in details && details.precache.length === 0) {
1589
+ throw new WorkboxError('invalid-cache-name', {
1590
+ cacheNameId: 'precache',
1591
+ value: details.precache
1592
+ });
1593
+ }
1594
+
1595
+ if ('runtime' in details && details.runtime.length === 0) {
1596
+ throw new WorkboxError('invalid-cache-name', {
1597
+ cacheNameId: 'runtime',
1598
+ value: details.runtime
1599
+ });
1600
+ }
1601
+
1602
+ if ('googleAnalytics' in details && details.googleAnalytics.length === 0) {
1603
+ throw new WorkboxError('invalid-cache-name', {
1604
+ cacheNameId: 'googleAnalytics',
1605
+ value: details.googleAnalytics
1606
+ });
1607
+ }
1608
+ }
1609
+
1610
+ cacheNames.updateDetails(details);
1611
+ };
1612
+
1613
+ /*
1614
+ Copyright 2019 Google LLC
1615
+
1616
+ Use of this source code is governed by an MIT-style
1617
+ license that can be found in the LICENSE file or at
1618
+ https://opensource.org/licenses/MIT.
1619
+ */
1620
+ /**
1621
+ * Force a service worker to become active, instead of waiting. This is
1622
+ * normally used in conjunction with `clientsClaim()`.
1623
+ *
1624
+ * @alias workbox.core.skipWaiting
1625
+ */
1626
+
1627
+ const skipWaiting = () => {
1628
+ // We need to explicitly call `self.skipWaiting()` here because we're
1629
+ // shadowing `skipWaiting` with this local function.
1630
+ addEventListener('install', () => self.skipWaiting());
1631
+ };
1632
+
1633
+ exports._private = _private;
1634
+ exports.cacheNames = cacheNames$1;
1635
+ exports.clientsClaim = clientsClaim;
1636
+ exports.registerQuotaErrorCallback = registerQuotaErrorCallback;
1637
+ exports.setCacheNameDetails = setCacheNameDetails;
1638
+ exports.skipWaiting = skipWaiting;
1639
+
1640
+ return exports;
1641
+
1642
+ }({}));
1643
+ //# sourceMappingURL=workbox-core.dev.js.map