Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule fetch
*
*/
/* globals Headers, Request, Response */
'use strict';
import whatwg from 'whatwg-fetch';
if (whatwg && whatwg.fetch) {
module.exports = whatwg;
} else {
module.exports = {fetch, Headers, Request, Response};
}
function ensurePageDescStorage(targetPath) {
if (!pageOutlines) {
throw new Error('Outline data is not loaded.');
}
let pagePath = targetPath.split('.')[0];
// Configuration like `option.color`, `option.backgroundColor` is in the `option` page.
// Configuration like `option.series-bar` is in the `option.series-bar` page.
let partionKey = !pageOutlines[pagePath] || !targetPath
? rootName
: rootName + '.' + pagePath;
if (!descStorage[partionKey]) {
let url = `${baseUrl}/${partionKey}.json?${docVersion}`;
let fetcher = fetch(url).then(response => response.json());
descStorage[partionKey] = {
fetcher
};
fetcher.then(map => {
descStorage[partionKey].indexer = createIndexer(map, pagePath);
});
}
return descStorage[partionKey];
}
/**
async cleanUp() {
return fetch('/__cleanup-mocks');
}
};
async componentDidMount() {
const res = await fetch('/playground/context');
const result = await res.json();
this.setState({
cubejsToken: result.cubejsToken,
apiUrl: result.apiUrl || window.location.href.split('#')[0].replace(/\/$/, '')
});
}
loadScene = (url = this.getJSONUrl()) => {
if (getWindow()) {
return fetch(url)
.then(res => res.json())
.then(this.parseScene)
.catch(() => Promise.resolve());
}
return Promise.resolve();
}
import "babel-polyfill";
import { fetch } from "whatwg-fetch";
import * as dat from "dat.gui";
export const gui = new dat.GUI({ width: 500 });
const hooks = {};
const token = fetch("/api/v1/user/authenticate", {
method: "POST",
headers: {
"Content-Type": "application/json; charset=utf-8"
},
body: JSON.stringify({
Identifier: {
UserKey: "Administrator"
},
password: prompt("What is the password")
})
})
.then(r => r.json())
.then(({ response }) => response.token)
.then(r => {
fetch("/api/v1/server/hook", {
method: "POST",
const fetchRequest = (url, fetchOptions) => {
const controller = new AbortController();
const request = fetch(url, {
method: fetchOptions.method,
headers: fetchOptions.headers,
body: fetchOptions.body,
signal: controller.signal
}).then(response => {
if (!response.ok) {
throw new StatusCodeError(response.status, null, null, response);
}
return response.arrayBuffer().then(arrayBuffer => {
return {response, arrayBuffer};
});
});
request.abort = () => {
controller.abort();
"confType": targetPlatform.id,
"originUrl": null,
"files": files,
"readOnlyFileNames": []
});
const body = new URLSearchParams();
body.set('filename', DEFAULT_FILE_NAME);
body.set('project', projectJson);
if (options !== undefined) {
for (let option in options) {
body.set(option, options[option])
}
}
return fetch(url + targetPlatform.id, {
method: 'POST',
body: body.toString(),
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
}
}).then(response => response.json())
}
public roundTrip(request: BasicRequest): Promise {
const responsePromise = fetch(request.url, {
body: request.body,
headers: request.headers,
method: request.method,
mode: 'cors'
});
const responseTextPromise = responsePromise.then(response =>
response.text()
);
return Promise.all([responsePromise, responseTextPromise]).then(values => {
const response = values[0];
const body = values[1];
const headers: { [key: string]: string } = {};
response.headers.forEach((value, key) => {
headers[key] = value;