first commit
This commit is contained in:
201
build/node_modules/sw-toolbox/LICENSE
generated
vendored
Normal file
201
build/node_modules/sw-toolbox/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright ${copyright_attribution}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
73
build/node_modules/sw-toolbox/README.md
generated
vendored
Normal file
73
build/node_modules/sw-toolbox/README.md
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
# Service Worker Toolbox
|
||||
|
||||
[](https://travis-ci.org/GoogleChrome/sw-toolbox) [](https://david-dm.org/googlechrome/sw-toolbox) [](https://david-dm.org/googlechrome/sw-toolbox?type=dev)
|
||||
|
||||
> A collection of tools for [service workers](https://w3c.github.io/ServiceWorker/)
|
||||
|
||||
Service Worker Toolbox provides some simple helpers for use in creating your own service workers. Specifically, it provides common caching strategies for dynamic content, such as API calls, third-party resources, and large or infrequently used local resources that you don't want precached.
|
||||
|
||||
Service Worker Toolbox provides an [expressive approach](https://googlechrome.github.io/sw-toolbox/usage.html#express-style-routes) to using those strategies for runtime requests. If you're not sure what service workers are or what they are for, start with [the explainer doc](https://github.com/slightlyoff/ServiceWorker/blob/master/explainer.md).
|
||||
|
||||
## What if I need precaching as well?
|
||||
|
||||
Then you should go check out [`sw-precache`](https://github.com/GoogleChrome/sw-precache) before doing anything else. In addition to precaching static resources, `sw-precache` supports optional [runtime caching](https://github.com/GoogleChrome/sw-precache#runtime-caching) through a simple, declarative configuration that incorporates Service Worker Toolbox under the hood.
|
||||
|
||||
## Install
|
||||
|
||||
Service Worker Toolbox is available through Bower, npm or direct from GitHub:
|
||||
|
||||
`bower install --save sw-toolbox`
|
||||
|
||||
`npm install --save sw-toolbox`
|
||||
|
||||
`git clone https://github.com/GoogleChrome/sw-toolbox.git`
|
||||
|
||||
### Register your service worker
|
||||
|
||||
From your registering page, register your service worker in the normal way. For example:
|
||||
|
||||
```javascript
|
||||
navigator.serviceWorker.register('my-service-worker.js');
|
||||
```
|
||||
|
||||
As implemented in Chrome 40 or later, a service worker must exist at the root of the scope that you intend it to control, or higher. So if you want all of the pages under `/myapp/` to be controlled by the worker, the worker script itself must be served from either `/` or `/myapp/`. The default scope is the containing path of the service worker script.
|
||||
|
||||
For even lower friction, you can instead include the Service Worker Toolbox companion script in your HTML as shown below. Be aware that this is not customizable. If you need to do anything fancier than register with a default scope, you'll need to use the standard registration.
|
||||
|
||||
```html
|
||||
<script src="/path/to/sw-toolbox/companion.js" data-service-worker="my-service-worker.js"></script>
|
||||
```
|
||||
|
||||
### Add Service Worker Toolbox to your service worker script
|
||||
|
||||
In your service worker you just need to use `importScripts` to load Service Worker Toolbox:
|
||||
|
||||
```javascript
|
||||
importScripts('bower_components/sw-toolbox/sw-toolbox.js'); // Update path to match your own setup.
|
||||
```
|
||||
|
||||
### Use the toolbox
|
||||
|
||||
To understand how to use the toolbox read the [Usage](https://googlechrome.github.io/sw-toolbox/usage.html#main) and [API](https://googlechrome.github.io/sw-toolbox/api.html#main) documentation.
|
||||
|
||||
## Support
|
||||
|
||||
If you’ve found an error in this library, please file an issue at https://github.com/GoogleChrome/sw-toolbox/issues.
|
||||
|
||||
Patches are encouraged, and may be submitted by forking this project and submitting a [pull request through this GitHub repo](https://github.com/GoogleChrome/sw-toolbox/pulls).
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2015-2016 Google, Inc.
|
||||
|
||||
Licensed under the [Apache License, Version 2.0](LICENSE) (the "License");
|
||||
you may not use this file except in compliance with the License. You may
|
||||
obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
23
build/node_modules/sw-toolbox/companion.js
generated
vendored
Normal file
23
build/node_modules/sw-toolbox/companion.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
Copyright 2016 Google Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
(function() {
|
||||
'use strict';
|
||||
var workerScript = document.currentScript && document.currentScript.dataset.serviceWorker;
|
||||
|
||||
if (workerScript && 'serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.register(workerScript);
|
||||
}
|
||||
})();
|
||||
48
build/node_modules/sw-toolbox/index.d.ts
generated
vendored
Normal file
48
build/node_modules/sw-toolbox/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
declare module 'sw-toolbox' {
|
||||
type URLPattern = string | RegExp
|
||||
type PrecacheURL = Request | string
|
||||
type PrecacheURLs = Promise<PrecacheURL[]> | PrecacheURL[]
|
||||
|
||||
interface Request {
|
||||
}
|
||||
interface Response {
|
||||
}
|
||||
|
||||
export interface CacheOptions {
|
||||
name: string
|
||||
maxEntries: number
|
||||
maxAgeSeconds: number
|
||||
}
|
||||
export interface Options {
|
||||
debug: boolean
|
||||
networkTimeoutSeconds: number
|
||||
cache: CacheOptions
|
||||
}
|
||||
export interface Handler {
|
||||
(request: Request): Promise<Response>
|
||||
}
|
||||
|
||||
export interface Router {
|
||||
any(urlPattern: URLPattern, handler: Handler, options?: Options): void
|
||||
default(handler: Handler, options?: Options): void
|
||||
delete(urlPattern: URLPattern, handler: Handler, options?: Options): void
|
||||
get(urlPattern: URLPattern, handler: Handler, options?: Options): void
|
||||
head(urlPattern: URLPattern, handler: Handler, options?: Options): void
|
||||
post(urlPattern: URLPattern, handler: Handler, options?: Options): void
|
||||
put(urlPattern: URLPattern, handler: Handler, options?: Options): void
|
||||
}
|
||||
|
||||
export const cacheFirst: Handler
|
||||
export const cacheOnly: Handler
|
||||
export const fastest: Handler
|
||||
export const networkFirst: Handler
|
||||
export const networkOnly: Handler
|
||||
export const options: Options
|
||||
export const router: Router
|
||||
|
||||
export function cache(url: string, options: Options): void
|
||||
|
||||
export function precache(urls: PrecacheURLs): void
|
||||
|
||||
export function uncache(url: string): Promise<void>
|
||||
}
|
||||
211
build/node_modules/sw-toolbox/lib/helpers.js
generated
vendored
Normal file
211
build/node_modules/sw-toolbox/lib/helpers.js
generated
vendored
Normal file
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
Copyright 2014 Google Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var globalOptions = require('./options');
|
||||
var idbCacheExpiration = require('./idb-cache-expiration');
|
||||
|
||||
function debug(message, options) {
|
||||
options = options || {};
|
||||
var flag = options.debug || globalOptions.debug;
|
||||
if (flag) {
|
||||
console.log('[sw-toolbox] ' + message);
|
||||
}
|
||||
}
|
||||
|
||||
function openCache(options) {
|
||||
var cacheName;
|
||||
if (options && options.cache) {
|
||||
cacheName = options.cache.name;
|
||||
}
|
||||
cacheName = cacheName || globalOptions.cache.name;
|
||||
|
||||
return caches.open(cacheName);
|
||||
}
|
||||
|
||||
function fetchAndCache(request, options) {
|
||||
options = options || {};
|
||||
var successResponses = options.successResponses ||
|
||||
globalOptions.successResponses;
|
||||
|
||||
return fetch(request.clone()).then(function(response) {
|
||||
// Only cache GET requests with successful responses.
|
||||
// Since this is not part of the promise chain, it will be done
|
||||
// asynchronously and will not block the response from being returned to the
|
||||
// page.
|
||||
if (request.method === 'GET' && successResponses.test(response.status)) {
|
||||
openCache(options).then(function(cache) {
|
||||
cache.put(request, response).then(function() {
|
||||
// If any of the options are provided in options.cache then use them.
|
||||
// Do not fallback to the global options for any that are missing
|
||||
// unless they are all missing.
|
||||
var cacheOptions = options.cache || globalOptions.cache;
|
||||
|
||||
// Only run the cache expiration logic if at least one of the maximums
|
||||
// is set, and if we have a name for the cache that the options are
|
||||
// being applied to.
|
||||
if ((cacheOptions.maxEntries || cacheOptions.maxAgeSeconds) &&
|
||||
cacheOptions.name) {
|
||||
queueCacheExpiration(request, cache, cacheOptions);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return response.clone();
|
||||
});
|
||||
}
|
||||
|
||||
var cleanupQueue;
|
||||
function queueCacheExpiration(request, cache, cacheOptions) {
|
||||
var cleanup = cleanupCache.bind(null, request, cache, cacheOptions);
|
||||
|
||||
if (cleanupQueue) {
|
||||
cleanupQueue = cleanupQueue.then(cleanup);
|
||||
} else {
|
||||
cleanupQueue = cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
function cleanupCache(request, cache, cacheOptions) {
|
||||
var requestUrl = request.url;
|
||||
var maxAgeSeconds = cacheOptions.maxAgeSeconds;
|
||||
var maxEntries = cacheOptions.maxEntries;
|
||||
var cacheName = cacheOptions.name;
|
||||
|
||||
var now = Date.now();
|
||||
debug('Updating LRU order for ' + requestUrl + '. Max entries is ' +
|
||||
maxEntries + ', max age is ' + maxAgeSeconds);
|
||||
|
||||
return idbCacheExpiration.getDb(cacheName).then(function(db) {
|
||||
return idbCacheExpiration.setTimestampForUrl(db, requestUrl, now);
|
||||
}).then(function(db) {
|
||||
return idbCacheExpiration.expireEntries(db, maxEntries, maxAgeSeconds, now);
|
||||
}).then(function(urlsToDelete) {
|
||||
debug('Successfully updated IDB.');
|
||||
|
||||
var deletionPromises = urlsToDelete.map(function(urlToDelete) {
|
||||
return cache.delete(urlToDelete);
|
||||
});
|
||||
|
||||
return Promise.all(deletionPromises).then(function() {
|
||||
debug('Done with cache cleanup.');
|
||||
});
|
||||
}).catch(function(error) {
|
||||
debug(error);
|
||||
});
|
||||
}
|
||||
|
||||
function renameCache(source, destination, options) {
|
||||
debug('Renaming cache: [' + source + '] to [' + destination + ']', options);
|
||||
return caches.delete(destination).then(function() {
|
||||
return Promise.all([
|
||||
caches.open(source),
|
||||
caches.open(destination)
|
||||
]).then(function(results) {
|
||||
var sourceCache = results[0];
|
||||
var destCache = results[1];
|
||||
|
||||
return sourceCache.keys().then(function(requests) {
|
||||
return Promise.all(requests.map(function(request) {
|
||||
return sourceCache.match(request).then(function(response) {
|
||||
return destCache.put(request, response);
|
||||
});
|
||||
}));
|
||||
}).then(function() {
|
||||
return caches.delete(source);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function cache(url, options) {
|
||||
return openCache(options).then(function(cache) {
|
||||
return cache.add(url);
|
||||
});
|
||||
}
|
||||
|
||||
function uncache(url, options) {
|
||||
return openCache(options).then(function(cache) {
|
||||
return cache.delete(url);
|
||||
});
|
||||
}
|
||||
|
||||
function precache(items) {
|
||||
if (!(items instanceof Promise)) {
|
||||
validatePrecacheInput(items);
|
||||
}
|
||||
|
||||
globalOptions.preCacheItems = globalOptions.preCacheItems.concat(items);
|
||||
}
|
||||
|
||||
function validatePrecacheInput(items) {
|
||||
var isValid = Array.isArray(items);
|
||||
if (isValid) {
|
||||
items.forEach(function(item) {
|
||||
if (!(typeof item === 'string' || (item instanceof Request))) {
|
||||
isValid = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!isValid) {
|
||||
throw new TypeError('The precache method expects either an array of ' +
|
||||
'strings and/or Requests or a Promise that resolves to an array of ' +
|
||||
'strings and/or Requests.');
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
function isResponseFresh(response, maxAgeSeconds, now) {
|
||||
// If we don't have a response, then it's not fresh.
|
||||
if (!response) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only bother checking the age of the response if maxAgeSeconds is set.
|
||||
if (maxAgeSeconds) {
|
||||
var dateHeader = response.headers.get('date');
|
||||
// If there's no Date: header, then fall through and return true.
|
||||
if (dateHeader) {
|
||||
var parsedDate = new Date(dateHeader);
|
||||
// If the Date: header was invalid for some reason, parsedDate.getTime()
|
||||
// will return NaN, and the comparison will always be false. That means
|
||||
// that an invalid date will be treated as if the response is fresh.
|
||||
if ((parsedDate.getTime() + (maxAgeSeconds * 1000)) < now) {
|
||||
// Only return false if all the other conditions are met.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back on returning true by default, to match the previous behavior in
|
||||
// which we never bothered checking to see whether the response was fresh.
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
debug: debug,
|
||||
fetchAndCache: fetchAndCache,
|
||||
openCache: openCache,
|
||||
renameCache: renameCache,
|
||||
cache: cache,
|
||||
uncache: uncache,
|
||||
precache: precache,
|
||||
validatePrecacheInput: validatePrecacheInput,
|
||||
isResponseFresh: isResponseFresh
|
||||
};
|
||||
158
build/node_modules/sw-toolbox/lib/idb-cache-expiration.js
generated
vendored
Normal file
158
build/node_modules/sw-toolbox/lib/idb-cache-expiration.js
generated
vendored
Normal file
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
Copyright 2015 Google Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var DB_PREFIX = 'sw-toolbox-';
|
||||
var DB_VERSION = 1;
|
||||
var STORE_NAME = 'store';
|
||||
var URL_PROPERTY = 'url';
|
||||
var TIMESTAMP_PROPERTY = 'timestamp';
|
||||
var cacheNameToDbPromise = {};
|
||||
|
||||
function openDb(cacheName) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var request = indexedDB.open(DB_PREFIX + cacheName, DB_VERSION);
|
||||
|
||||
request.onupgradeneeded = function() {
|
||||
var objectStore = request.result.createObjectStore(STORE_NAME,
|
||||
{keyPath: URL_PROPERTY});
|
||||
objectStore.createIndex(TIMESTAMP_PROPERTY, TIMESTAMP_PROPERTY,
|
||||
{unique: false});
|
||||
};
|
||||
|
||||
request.onsuccess = function() {
|
||||
resolve(request.result);
|
||||
};
|
||||
|
||||
request.onerror = function() {
|
||||
reject(request.error);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function getDb(cacheName) {
|
||||
if (!(cacheName in cacheNameToDbPromise)) {
|
||||
cacheNameToDbPromise[cacheName] = openDb(cacheName);
|
||||
}
|
||||
|
||||
return cacheNameToDbPromise[cacheName];
|
||||
}
|
||||
|
||||
function setTimestampForUrl(db, url, now) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var transaction = db.transaction(STORE_NAME, 'readwrite');
|
||||
var objectStore = transaction.objectStore(STORE_NAME);
|
||||
objectStore.put({url: url, timestamp: now});
|
||||
|
||||
transaction.oncomplete = function() {
|
||||
resolve(db);
|
||||
};
|
||||
|
||||
transaction.onabort = function() {
|
||||
reject(transaction.error);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function expireOldEntries(db, maxAgeSeconds, now) {
|
||||
// Bail out early by resolving with an empty array if we're not using
|
||||
// maxAgeSeconds.
|
||||
if (!maxAgeSeconds) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
var maxAgeMillis = maxAgeSeconds * 1000;
|
||||
var urls = [];
|
||||
|
||||
var transaction = db.transaction(STORE_NAME, 'readwrite');
|
||||
var objectStore = transaction.objectStore(STORE_NAME);
|
||||
var index = objectStore.index(TIMESTAMP_PROPERTY);
|
||||
|
||||
index.openCursor().onsuccess = function(cursorEvent) {
|
||||
var cursor = cursorEvent.target.result;
|
||||
if (cursor) {
|
||||
if (now - maxAgeMillis > cursor.value[TIMESTAMP_PROPERTY]) {
|
||||
var url = cursor.value[URL_PROPERTY];
|
||||
urls.push(url);
|
||||
objectStore.delete(url);
|
||||
cursor.continue();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
transaction.oncomplete = function() {
|
||||
resolve(urls);
|
||||
};
|
||||
|
||||
transaction.onabort = reject;
|
||||
});
|
||||
}
|
||||
|
||||
function expireExtraEntries(db, maxEntries) {
|
||||
// Bail out early by resolving with an empty array if we're not using
|
||||
// maxEntries.
|
||||
if (!maxEntries) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
var urls = [];
|
||||
|
||||
var transaction = db.transaction(STORE_NAME, 'readwrite');
|
||||
var objectStore = transaction.objectStore(STORE_NAME);
|
||||
var index = objectStore.index(TIMESTAMP_PROPERTY);
|
||||
|
||||
var countRequest = index.count();
|
||||
index.count().onsuccess = function() {
|
||||
var initialCount = countRequest.result;
|
||||
|
||||
if (initialCount > maxEntries) {
|
||||
index.openCursor().onsuccess = function(cursorEvent) {
|
||||
var cursor = cursorEvent.target.result;
|
||||
if (cursor) {
|
||||
var url = cursor.value[URL_PROPERTY];
|
||||
urls.push(url);
|
||||
objectStore.delete(url);
|
||||
if (initialCount - urls.length > maxEntries) {
|
||||
cursor.continue();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
transaction.oncomplete = function() {
|
||||
resolve(urls);
|
||||
};
|
||||
|
||||
transaction.onabort = reject;
|
||||
});
|
||||
}
|
||||
|
||||
function expireEntries(db, maxEntries, maxAgeSeconds, now) {
|
||||
return expireOldEntries(db, maxAgeSeconds, now).then(function(oldUrls) {
|
||||
return expireExtraEntries(db, maxEntries).then(function(extraUrls) {
|
||||
return oldUrls.concat(extraUrls);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getDb: getDb,
|
||||
setTimestampForUrl: setTimestampForUrl,
|
||||
expireEntries: expireEntries
|
||||
};
|
||||
75
build/node_modules/sw-toolbox/lib/listeners.js
generated
vendored
Normal file
75
build/node_modules/sw-toolbox/lib/listeners.js
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
Copyright 2014 Google Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
// For cache.addAll.
|
||||
require('serviceworker-cache-polyfill');
|
||||
|
||||
var helpers = require('./helpers');
|
||||
var router = require('./router');
|
||||
var options = require('./options');
|
||||
|
||||
// Event listeners
|
||||
|
||||
function fetchListener(event) {
|
||||
var handler = router.match(event.request);
|
||||
|
||||
if (handler) {
|
||||
event.respondWith(handler(event.request));
|
||||
} else if (router.default &&
|
||||
event.request.method === 'GET' &&
|
||||
// Ensure that chrome-extension:// requests don't trigger the default route.
|
||||
event.request.url.indexOf('http') === 0) {
|
||||
event.respondWith(router.default(event.request));
|
||||
}
|
||||
}
|
||||
|
||||
function activateListener(event) {
|
||||
helpers.debug('activate event fired');
|
||||
var inactiveCache = options.cache.name + '$$$inactive$$$';
|
||||
event.waitUntil(helpers.renameCache(inactiveCache, options.cache.name));
|
||||
}
|
||||
|
||||
function flatten(items) {
|
||||
return items.reduce(function(a, b) {
|
||||
return a.concat(b);
|
||||
}, []);
|
||||
}
|
||||
|
||||
function installListener(event) {
|
||||
var inactiveCache = options.cache.name + '$$$inactive$$$';
|
||||
helpers.debug('install event fired');
|
||||
helpers.debug('creating cache [' + inactiveCache + ']');
|
||||
event.waitUntil(
|
||||
helpers.openCache({cache: {name: inactiveCache}})
|
||||
.then(function(cache) {
|
||||
return Promise.all(options.preCacheItems)
|
||||
.then(flatten)
|
||||
.then(helpers.validatePrecacheInput)
|
||||
.then(function(preCacheItems) {
|
||||
helpers.debug('preCache list: ' +
|
||||
(preCacheItems.join(', ') || '(none)'));
|
||||
return cache.addAll(preCacheItems);
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fetchListener: fetchListener,
|
||||
activateListener: activateListener,
|
||||
installListener: installListener
|
||||
};
|
||||
40
build/node_modules/sw-toolbox/lib/options.js
generated
vendored
Normal file
40
build/node_modules/sw-toolbox/lib/options.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
Copyright 2015 Google Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
// TODO: This is necessary to handle different implementations in the wild
|
||||
// The spec defines self.registration, but it was not implemented in Chrome 40.
|
||||
var scope;
|
||||
if (self.registration) {
|
||||
scope = self.registration.scope;
|
||||
} else {
|
||||
scope = self.scope || new URL('./', self.location).href;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
cache: {
|
||||
name: '$$$toolbox-cache$$$' + scope + '$$$',
|
||||
maxAgeSeconds: null,
|
||||
maxEntries: null
|
||||
},
|
||||
debug: false,
|
||||
networkTimeoutSeconds: null,
|
||||
preCacheItems: [],
|
||||
// A regular expression to apply to HTTP response codes. Codes that match
|
||||
// will be considered successes, while others will not, and will not be
|
||||
// cached.
|
||||
successResponses: /^0|([123]\d\d)|(40[14567])|410$/
|
||||
};
|
||||
60
build/node_modules/sw-toolbox/lib/route.js
generated
vendored
Normal file
60
build/node_modules/sw-toolbox/lib/route.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
Copyright 2014 Google Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
// TODO: Use self.registration.scope instead of self.location
|
||||
var url = new URL('./', self.location);
|
||||
var basePath = url.pathname;
|
||||
var pathRegexp = require('path-to-regexp');
|
||||
|
||||
var Route = function(method, path, handler, options) {
|
||||
if (path instanceof RegExp) {
|
||||
this.fullUrlRegExp = path;
|
||||
} else {
|
||||
// The URL() constructor can't parse express-style routes as they are not
|
||||
// valid urls. This means we have to manually manipulate relative urls into
|
||||
// absolute ones. This check is extremely naive but implementing a tweaked
|
||||
// version of the full algorithm seems like overkill
|
||||
// (https://url.spec.whatwg.org/#concept-basic-url-parser)
|
||||
if (path.indexOf('/') !== 0) {
|
||||
path = basePath + path;
|
||||
}
|
||||
|
||||
this.keys = [];
|
||||
this.regexp = pathRegexp(path, this.keys);
|
||||
}
|
||||
|
||||
this.method = method;
|
||||
this.options = options;
|
||||
this.handler = handler;
|
||||
};
|
||||
|
||||
Route.prototype.makeHandler = function(url) {
|
||||
var values;
|
||||
if (this.regexp) {
|
||||
var match = this.regexp.exec(url);
|
||||
values = {};
|
||||
this.keys.forEach(function(key, index) {
|
||||
values[key.name] = match[index + 1];
|
||||
});
|
||||
}
|
||||
|
||||
return function(request) {
|
||||
return this.handler(request, values, this.options);
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
module.exports = Route;
|
||||
133
build/node_modules/sw-toolbox/lib/router.js
generated
vendored
Normal file
133
build/node_modules/sw-toolbox/lib/router.js
generated
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
Copyright 2014 Google Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var Route = require('./route');
|
||||
var helpers = require('./helpers');
|
||||
|
||||
function regexEscape(s) {
|
||||
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
||||
}
|
||||
|
||||
var keyMatch = function(map, string) {
|
||||
// This would be better written as a for..of loop, but that would break the
|
||||
// minifyify process in the build.
|
||||
var entriesIterator = map.entries();
|
||||
var item = entriesIterator.next();
|
||||
var matches = [];
|
||||
while (!item.done) {
|
||||
var pattern = new RegExp(item.value[0]);
|
||||
if (pattern.test(string)) {
|
||||
matches.push(item.value[1]);
|
||||
}
|
||||
item = entriesIterator.next();
|
||||
}
|
||||
return matches;
|
||||
};
|
||||
|
||||
var Router = function() {
|
||||
this.routes = new Map();
|
||||
// Create the dummy origin for RegExp-based routes
|
||||
this.routes.set(RegExp, new Map());
|
||||
this.default = null;
|
||||
};
|
||||
|
||||
['get', 'post', 'put', 'delete', 'head', 'any'].forEach(function(method) {
|
||||
Router.prototype[method] = function(path, handler, options) {
|
||||
return this.add(method, path, handler, options);
|
||||
};
|
||||
});
|
||||
|
||||
Router.prototype.add = function(method, path, handler, options) {
|
||||
options = options || {};
|
||||
var origin;
|
||||
|
||||
if (path instanceof RegExp) {
|
||||
// We need a unique key to use in the Map to distinguish RegExp paths
|
||||
// from Express-style paths + origins. Since we can use any object as the
|
||||
// key in a Map, let's use the RegExp constructor!
|
||||
origin = RegExp;
|
||||
} else {
|
||||
origin = options.origin || self.location.origin;
|
||||
if (origin instanceof RegExp) {
|
||||
origin = origin.source;
|
||||
} else {
|
||||
origin = regexEscape(origin);
|
||||
}
|
||||
}
|
||||
|
||||
method = method.toLowerCase();
|
||||
|
||||
var route = new Route(method, path, handler, options);
|
||||
|
||||
if (!this.routes.has(origin)) {
|
||||
this.routes.set(origin, new Map());
|
||||
}
|
||||
|
||||
var methodMap = this.routes.get(origin);
|
||||
if (!methodMap.has(method)) {
|
||||
methodMap.set(method, new Map());
|
||||
}
|
||||
|
||||
var routeMap = methodMap.get(method);
|
||||
var regExp = route.regexp || route.fullUrlRegExp;
|
||||
|
||||
if (routeMap.has(regExp.source)) {
|
||||
helpers.debug('"' + path + '" resolves to same regex as existing route.');
|
||||
}
|
||||
|
||||
routeMap.set(regExp.source, route);
|
||||
};
|
||||
|
||||
Router.prototype.matchMethod = function(method, url) {
|
||||
var urlObject = new URL(url);
|
||||
var origin = urlObject.origin;
|
||||
var path = urlObject.pathname;
|
||||
|
||||
// We want to first check to see if there's a match against any
|
||||
// "Express-style" routes (string for the path, RegExp for the origin).
|
||||
// Checking for Express-style matches first maintains the legacy behavior.
|
||||
// If there's no match, we next check for a match against any RegExp routes,
|
||||
// where the RegExp in question matches the full URL (both origin and path).
|
||||
return this._match(method, keyMatch(this.routes, origin), path) ||
|
||||
this._match(method, [this.routes.get(RegExp)], url);
|
||||
};
|
||||
|
||||
Router.prototype._match = function(method, methodMaps, pathOrUrl) {
|
||||
if (methodMaps.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (var i = 0; i < methodMaps.length; i++) {
|
||||
var methodMap = methodMaps[i];
|
||||
var routeMap = methodMap && methodMap.get(method.toLowerCase());
|
||||
if (routeMap) {
|
||||
var routes = keyMatch(routeMap, pathOrUrl);
|
||||
if (routes.length > 0) {
|
||||
return routes[0].makeHandler(pathOrUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
Router.prototype.match = function(request) {
|
||||
return this.matchMethod(request.method, request.url) ||
|
||||
this.matchMethod('any', request.url);
|
||||
};
|
||||
|
||||
module.exports = new Router();
|
||||
36
build/node_modules/sw-toolbox/lib/strategies/cacheFirst.js
generated
vendored
Normal file
36
build/node_modules/sw-toolbox/lib/strategies/cacheFirst.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
Copyright 2014 Google Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
var globalOptions = require('../options');
|
||||
var helpers = require('../helpers');
|
||||
|
||||
function cacheFirst(request, values, options) {
|
||||
options = options || {};
|
||||
helpers.debug('Strategy: cache first [' + request.url + ']', options);
|
||||
return helpers.openCache(options).then(function(cache) {
|
||||
return cache.match(request).then(function(response) {
|
||||
var cacheOptions = options.cache || globalOptions.cache;
|
||||
var now = Date.now();
|
||||
if (helpers.isResponseFresh(response, cacheOptions.maxAgeSeconds, now)) {
|
||||
return response;
|
||||
}
|
||||
|
||||
return helpers.fetchAndCache(request, options);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = cacheFirst;
|
||||
36
build/node_modules/sw-toolbox/lib/strategies/cacheOnly.js
generated
vendored
Normal file
36
build/node_modules/sw-toolbox/lib/strategies/cacheOnly.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
Copyright 2014 Google Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
var globalOptions = require('../options');
|
||||
var helpers = require('../helpers');
|
||||
|
||||
function cacheOnly(request, values, options) {
|
||||
options = options || {};
|
||||
helpers.debug('Strategy: cache only [' + request.url + ']', options);
|
||||
return helpers.openCache(options).then(function(cache) {
|
||||
return cache.match(request).then(function(response) {
|
||||
var cacheOptions = options.cache || globalOptions.cache;
|
||||
var now = Date.now();
|
||||
if (helpers.isResponseFresh(response, cacheOptions.maxAgeSeconds, now)) {
|
||||
return response;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = cacheOnly;
|
||||
53
build/node_modules/sw-toolbox/lib/strategies/fastest.js
generated
vendored
Normal file
53
build/node_modules/sw-toolbox/lib/strategies/fastest.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
Copyright 2014 Google Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
var helpers = require('../helpers');
|
||||
var cacheOnly = require('./cacheOnly');
|
||||
|
||||
function fastest(request, values, options) {
|
||||
helpers.debug('Strategy: fastest [' + request.url + ']', options);
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
var rejected = false;
|
||||
var reasons = [];
|
||||
|
||||
var maybeReject = function(reason) {
|
||||
reasons.push(reason.toString());
|
||||
if (rejected) {
|
||||
reject(new Error('Both cache and network failed: "' +
|
||||
reasons.join('", "') + '"'));
|
||||
} else {
|
||||
rejected = true;
|
||||
}
|
||||
};
|
||||
|
||||
var maybeResolve = function(result) {
|
||||
if (result instanceof Response) {
|
||||
resolve(result);
|
||||
} else {
|
||||
maybeReject('No result returned');
|
||||
}
|
||||
};
|
||||
|
||||
helpers.fetchAndCache(request.clone(), options)
|
||||
.then(maybeResolve, maybeReject);
|
||||
|
||||
cacheOnly(request, values, options)
|
||||
.then(maybeResolve, maybeReject);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = fastest;
|
||||
22
build/node_modules/sw-toolbox/lib/strategies/index.js
generated
vendored
Normal file
22
build/node_modules/sw-toolbox/lib/strategies/index.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
Copyright 2014 Google Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
module.exports = {
|
||||
networkOnly: require('./networkOnly'),
|
||||
networkFirst: require('./networkFirst'),
|
||||
cacheOnly: require('./cacheOnly'),
|
||||
cacheFirst: require('./cacheFirst'),
|
||||
fastest: require('./fastest')
|
||||
};
|
||||
97
build/node_modules/sw-toolbox/lib/strategies/networkFirst.js
generated
vendored
Normal file
97
build/node_modules/sw-toolbox/lib/strategies/networkFirst.js
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
Copyright 2015 Google Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
var globalOptions = require('../options');
|
||||
var helpers = require('../helpers');
|
||||
|
||||
function networkFirst(request, values, options) {
|
||||
options = options || {};
|
||||
var successResponses = options.successResponses ||
|
||||
globalOptions.successResponses;
|
||||
// This will bypass options.networkTimeout if it's set to a false-y value like
|
||||
// 0, but that's the sane thing to do anyway.
|
||||
var networkTimeoutSeconds = options.networkTimeoutSeconds ||
|
||||
globalOptions.networkTimeoutSeconds;
|
||||
helpers.debug('Strategy: network first [' + request.url + ']', options);
|
||||
|
||||
return helpers.openCache(options).then(function(cache) {
|
||||
var timeoutId;
|
||||
var promises = [];
|
||||
var originalResponse;
|
||||
|
||||
if (networkTimeoutSeconds) {
|
||||
var cacheWhenTimedOutPromise = new Promise(function(resolve) {
|
||||
timeoutId = setTimeout(function() {
|
||||
cache.match(request).then(function(response) {
|
||||
var cacheOptions = options.cache || globalOptions.cache;
|
||||
// Only resolve this promise if there's a valid response in the
|
||||
// cache. This ensures that we won't time out a network request
|
||||
// unless there's a cached entry to fallback on, which is arguably
|
||||
// the preferable behavior.
|
||||
var now = Date.now();
|
||||
var maxAgeSeconds = cacheOptions.maxAgeSeconds;
|
||||
if (helpers.isResponseFresh(response, maxAgeSeconds, now)) {
|
||||
resolve(response);
|
||||
}
|
||||
});
|
||||
}, networkTimeoutSeconds * 1000);
|
||||
});
|
||||
promises.push(cacheWhenTimedOutPromise);
|
||||
}
|
||||
|
||||
var networkPromise = helpers.fetchAndCache(request, options)
|
||||
.then(function(response) {
|
||||
// We've got a response, so clear the network timeout if there is one.
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
|
||||
if (successResponses.test(response.status)) {
|
||||
return response;
|
||||
}
|
||||
|
||||
helpers.debug('Response was an HTTP error: ' + response.statusText,
|
||||
options);
|
||||
originalResponse = response;
|
||||
throw new Error('Bad response');
|
||||
}).catch(function(error) {
|
||||
helpers.debug('Network or response error, fallback to cache [' +
|
||||
request.url + ']', options);
|
||||
return cache.match(request).then(function(response) {
|
||||
// If there's a match in the cache, resolve with that.
|
||||
if (response) {
|
||||
return response;
|
||||
}
|
||||
|
||||
// If we have a Response object from the previous fetch, then resolve
|
||||
// with that, even though it corresponds to an error status code.
|
||||
if (originalResponse) {
|
||||
return originalResponse;
|
||||
}
|
||||
|
||||
// If we don't have a Response object from the previous fetch, likely
|
||||
// due to a network failure, then reject with the failure error.
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
|
||||
promises.push(networkPromise);
|
||||
|
||||
return Promise.race(promises);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = networkFirst;
|
||||
24
build/node_modules/sw-toolbox/lib/strategies/networkOnly.js
generated
vendored
Normal file
24
build/node_modules/sw-toolbox/lib/strategies/networkOnly.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
Copyright 2014 Google Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
var helpers = require('../helpers');
|
||||
|
||||
function networkOnly(request, values, options) {
|
||||
helpers.debug('Strategy: network only [' + request.url + ']', options);
|
||||
return fetch(request);
|
||||
}
|
||||
|
||||
module.exports = networkOnly;
|
||||
46
build/node_modules/sw-toolbox/lib/sw-toolbox.js
generated
vendored
Normal file
46
build/node_modules/sw-toolbox/lib/sw-toolbox.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
Copyright 2014 Google Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
// This is the entrypoint for the sw-toolbox bundle. All code with
|
||||
// side effects (e.g. adding event listeners) should be in this file.
|
||||
|
||||
var options = require('./options');
|
||||
var router = require('./router');
|
||||
var helpers = require('./helpers');
|
||||
var strategies = require('./strategies');
|
||||
var listeners = require('./listeners');
|
||||
|
||||
helpers.debug('Service Worker Toolbox is loading');
|
||||
|
||||
// Set up listeners.
|
||||
|
||||
self.addEventListener('install', listeners.installListener);
|
||||
self.addEventListener('activate', listeners.activateListener);
|
||||
self.addEventListener('fetch', listeners.fetchListener);
|
||||
|
||||
module.exports = {
|
||||
networkOnly: strategies.networkOnly,
|
||||
networkFirst: strategies.networkFirst,
|
||||
cacheOnly: strategies.cacheOnly,
|
||||
cacheFirst: strategies.cacheFirst,
|
||||
fastest: strategies.fastest,
|
||||
router: router,
|
||||
options: options,
|
||||
cache: helpers.cache,
|
||||
uncache: helpers.uncache,
|
||||
precache: helpers.precache
|
||||
};
|
||||
82
build/node_modules/sw-toolbox/package.json
generated
vendored
Normal file
82
build/node_modules/sw-toolbox/package.json
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
{
|
||||
"_from": "sw-toolbox@^3.4.0",
|
||||
"_id": "sw-toolbox@3.6.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-Jt8dHHA0hljk3qKIQxkUm3sxg7U=",
|
||||
"_location": "/sw-toolbox",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "sw-toolbox@^3.4.0",
|
||||
"name": "sw-toolbox",
|
||||
"escapedName": "sw-toolbox",
|
||||
"rawSpec": "^3.4.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^3.4.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/sw-precache"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/sw-toolbox/-/sw-toolbox-3.6.0.tgz",
|
||||
"_shasum": "26df1d1c70348658e4dea2884319149b7b3183b5",
|
||||
"_spec": "sw-toolbox@^3.4.0",
|
||||
"_where": "/Users/asciidisco/Desktop/asciidisco.com/build/node_modules/sw-precache",
|
||||
"bugs": {
|
||||
"url": "https://github.com/GoogleChrome/sw-toolbox/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"path-to-regexp": "^1.0.1",
|
||||
"serviceworker-cache-polyfill": "^4.0.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Service Worker Toolbox provides some simple helpers for use in creating your own service workers.",
|
||||
"devDependencies": {
|
||||
"browserify": "^13.1.0",
|
||||
"chai": "^3.4.1",
|
||||
"chromedriver": "^2.27.2",
|
||||
"cookie-parser": "^1.4.1",
|
||||
"eslint": "^3.13.1",
|
||||
"eslint-config-google": "^0.7.1",
|
||||
"express": "^4.13.3",
|
||||
"geckodriver": "^1.3.0",
|
||||
"gulp": "^3.9.0",
|
||||
"gulp-eslint": "^3.0.1",
|
||||
"gulp-gh-pages": "^0.5.4",
|
||||
"gulp-header": "^1.8.8",
|
||||
"gulp-sourcemaps": "^2.3.1",
|
||||
"gulp-uglify": "^2.0.0",
|
||||
"jsdoc": "^3.4.0",
|
||||
"mocha": "^3.2.0",
|
||||
"npm-publish-scripts": "^4.1.0",
|
||||
"operadriver": "^1.0.0",
|
||||
"selenium-assistant": "^5.0.2",
|
||||
"sw-testing-helpers": "1.0.1",
|
||||
"temp": "^0.8.3",
|
||||
"vinyl-buffer": "^1.0.0",
|
||||
"vinyl-source-stream": "^1.1.0",
|
||||
"which": "^1.2.4"
|
||||
},
|
||||
"files": [
|
||||
"lib/",
|
||||
"companion.js",
|
||||
"sw-toolbox.js",
|
||||
"sw-toolbox.js.map",
|
||||
"index.d.ts"
|
||||
],
|
||||
"homepage": "https://github.com/GoogleChrome/sw-toolbox#readme",
|
||||
"license": "Apache-2.0",
|
||||
"main": "lib/sw-toolbox.js",
|
||||
"name": "sw-toolbox",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/GoogleChrome/sw-toolbox.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "gulp default",
|
||||
"publish-release": "npm-publish-scripts publish-release",
|
||||
"test": "gulp lint default && node ./test/helpers/download-browsers.js && mocha"
|
||||
},
|
||||
"version": "3.6.0"
|
||||
}
|
||||
16
build/node_modules/sw-toolbox/sw-toolbox.js
generated
vendored
Normal file
16
build/node_modules/sw-toolbox/sw-toolbox.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
build/node_modules/sw-toolbox/sw-toolbox.js.map
generated
vendored
Normal file
1
build/node_modules/sw-toolbox/sw-toolbox.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user