async function getDefaultToggleValues() { try { const togglesResp = await fetch( 'https://toggles.wellcomecollection.org/toggles.json' ).then(response => response.json()); defaultToggleValues = togglesResp.toggles.reduce( (acc, toggle) => ({ ...acc, [toggle.id]: toggle.defaultValue }), {} ); } catch (e) {} }
const fetchAuthenticated = (method, url, request = {}) => { const options = { method, headers: { Authorization: 'Basic ' + Buffer.from('anystring:' + MAILCHIMP_API_KEY).toString('base64') }, ...request } return fetch(url, options) .then(r => r.json()) }
async fetch(url) { if (!url) return null; let response = await fetch(url); if (response.status === 200) { return new Promise((resolve, reject) => { let concatStream = concat(resolve); response.body.on("error", reject); response.body.pipe(concatStream); }); } return null; }
fetch(`${MAILCHIMP_URL}/3.0/campaigns/${id}`, { method: 'GET', headers: { 'Content-Type': 'application/json', Authorization: `Basic ${Buffer.from('anystring:' + MAILCHIMP_API_KEY).toString('base64')}` } }) .then(response => response.json()) .catch(error => console.error('updateMailchimp failed', { error }))
fetch(`${MAILCHIMP_URL}/3.0/campaigns/${campaignId}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json', Authorization: `Basic ${Buffer.from('anystring:' + MAILCHIMP_API_KEY).toString('base64')}` }, body: JSON.stringify(body) }) .then(response => { if (!response.ok) { throw Error(response.statusText) } return response })
const importFromRepo = async (url, images, repoId) => { if (isFromDifferentRepo(url, repoId)) { try { const blob = await fetch(url).then(result => result.buffer()) const { image, imageUrl } = await generateImageData(blob) images.push(image) return imageUrl } catch (e) { console.error('failed to transfer image', repoId, url, e) } } return url }
const unfetchPOEditor = (url, data = {}) => fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: encodeFormURL({ ...data, api_token: TOKEN, id: ID }), }).then(res => res.ok && res.json())
const fetchAuthenticated = (method, url, request = {}) => { const options = { method, headers: { Authorization: 'Basic ' + Buffer.from('anystring:' + MAILCHIMP_API_KEY).toString('base64') }, ...request } return fetch(url, options) .then(r => r.json()) }
fetch(`${MAILCHIMP_URL}/3.0/campaigns/${id}`, { method: 'GET', headers: { 'Content-Type': 'application/json', Authorization: `Basic ${Buffer.from('anystring:' + MAILCHIMP_API_KEY).toString('base64')}` } }) .then(response => response.json()) .catch(error => console.error('updateMailchimp failed', { error }))
const fetchAuthenticated = (method, url, request = {}) => { const options = { method, headers: { Authorization: 'Basic ' + Buffer.from('anystring:' + MAILCHIMP_API_KEY).toString('base64') }, ...request } return fetch(url, options) .then(r => r.json()) }
const fetchAuthenticated = (method, url, request = {}) => { const options = { method, headers: { Authorization: 'Basic ' + Buffer.from('anystring:' + MAILCHIMP_API_KEY).toString('base64') }, ...request } return fetch(url, options) .then(r => r.json()) }
const fetchAuthenticated = (method, url, request = {}) => { const options = { method, headers: { Authorization: 'Basic ' + Buffer.from('anystring:' + MAILCHIMP_API_KEY).toString('base64') }, ...request } return fetch(url, options) .then(r => r.json()) }
const fetchAuthenticated = (method, url, request = {}) => { const options = { method, headers: { Authorization: 'Basic ' + Buffer.from('anystring:' + MAILCHIMP_API_KEY).toString('base64') }, ...request } return fetch(url, options) .then(r => r.json()) }
const fetchAuthenticated = (method, url, request = {}) => { const options = { method, headers: { Authorization: 'Basic ' + Buffer.from('anystring:' + MAILCHIMP_API_KEY).toString('base64') }, ...request } return fetch(url, options) .then(r => r.json()) }
const importFromRepo = async (url, images, repoId) => { if (isFromDifferentRepo(url, repoId)) { try { const blob = await fetch(url).then(result => result.buffer()) const { image, imageUrl } = await generateImageData(blob) images.push(image) return imageUrl } catch (e) { console.error('failed to transfer image', repoId, url, e) } } return url }