Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
api(endpoint, method='GET', body=undefined) {
const headers = {};
const cachable = (method.toUpperCase() == 'GET');
const url = `${API_ROOT}/${endpoint}?token=${this.config.slack.apiKey}`;
if (!this.isEnabled()) {
return Promise.reject('The slack API is not configured.');
}
if (typeof body === 'object') {
body = urlencoded(body);
}
if (method === 'POST') {
headers['Content-Type'] = 'application/x-www-form-urlencoded';
}
else if (cachable && cache[url]) {
return Promise.resolve(cache[url]);
}
else if (method === 'GET' && pending[url]) {
return pending[url];
}
pending[url] = fetch(url, { method, body, headers })
.then(res => res.json())
.then((data) => {
// Cache result
if (cachable && data && data.ok) {
export function aggregationQS(params) {
const o = {
drilldown: params.drilldown.map(l => l.full_name),
measures: params.measures.map(m => m.name),
cut: params.cut,
nonempty: params.nonempty ? 'true' : 'false',
distinct: params.distinct ? 'true' : 'false',
parents: params.parents ? 'true' : 'false',
debug: 'true' // TODO: debug enabled by default
};
return formurlencoded(o);
}
e.preventDefault();
e.stopPropagation();
if (!this.state.mailingListPrivacy) return;
const url = "https://www.mozilla.org/en-US/newsletter/";
const payload = {
email: this.state.mailingListEmail,
newsletters: "hubs",
privacy: true,
fmt: "H",
source_url: document.location.href
};
await fetch(url, {
body: formurlencoded(payload),
method: "POST",
headers: { "content-type": "application/x-www-form-urlencoded" }
}).then(onSubmittedEmail);
};
export function formUrlEncode(body: Object): Object {
return formurlencoded(body);
}
this.showExt = function(title, scrambleRequest, password, ext, {target, doFetch}, competitionJson) {
var body = {};
body.sheets = JSON.stringify(scrambleRequest);
if(password) {
body.password = password;
}
body.generationUrl = location.href;
let url = that.viewUrl + encodeURIComponent(title) + '.' + ext;
body.schedule = JSON.stringify(competitionJson.schedule);
if(doFetch) {
return fetch(url, {
method: "POST",
body: formurlencoded(body),
headers: {
'Content-type': 'application/x-www-form-urlencoded',
},
}).then(res => {
if(res.status != 200) {
return res.text().then(text => {
throw new Error(`Fetch returned ${res.status}: ${text}`);
});
}
return res.blob();
}).then(blob => { return {title, blob}; });
} else {
tnoodle.postToUrl(url, body, "POST", target);
}
};
this.fetchPdf = function(title, scrambleRequest, password) {
const IssueButton = function({error, location, message, permalink, t}) {
const issueParams = formUrlEncode({
body: [
`**Permalink**: ${location.origin + location.pathname}?${permalink}`,
`**Error**: ${error}`,
message ? `**Error details:** ${message}\n` : "",
"**Detail of the issue:**\n"
].join("\n"),
title: `[report/vizbuilder${location.pathname}] `
});
return (
function updateToken(params) {
const url = buildUrl('/api/oauth2/token')
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'User-Agent': userAgentString()
},
body: formurlencoded(params),
params: params,
credentials: 'include',
compress: false
}
return fetch(url, options)
.then(checkStatus)
.then(getJson)
.then(json => {
return (json.error)
? Promise.reject({
message: errMap(json.error, params),
body: json,
params
})
: Promise.resolve(json)
postForm(path, data, options) {
if (!options) {
options = {};
}
if (!options.headers) {
options.headers = {};
}
options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
options.headers['Accept'] = 'application/json';
return this._createRequest({
method: 'POST',
path: path,
body: formUrlencoded(data),
...options
});
}