UNPKG

2.19 kBPlain TextView Raw
1/**
2 * Copyright 2020 Inrupt Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal in
6 * the Software without restriction, including without limitation the rights to use,
7 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8 * Software, and to permit persons to whom the Software is furnished to do so,
9 * subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 */
21
22/**
23 * @ignore Internal fallback for when no fetcher is provided; not to be used downstream.
24 */
25export const fetch: typeof window.fetch = (resource, init) => {
26 // Implementation note: it's up to the client application to resolve these module names to the
27 // respective npm packages. At least one commonly used tool (Webpack) is only able to do that if
28 // the module names are literal strings.
29 // Additionally, Webpack throws a warning in a way that halts compilation for at least Next.js
30 // when using native Javascript dynamic imports (`import()`), whereas `require()` just logs a
31 // warning. Since the use of package names instead of file names requires a bundles anyway, this
32 // should not have any practical consequences. For more background, see:
33 // https://github.com/webpack/webpack/issues/7713
34 let fetch;
35
36 try {
37 fetch = require("@inrupt/solid-auth-fetcher").fetch;
38 } catch (e) {
39 try {
40 fetch = require("solid-auth-client").fetch;
41 } catch (e) {
42 fetch = require("cross-fetch");
43 }
44 }
45
46 return fetch(resource, init);
47};