Public
Edited
Oct 5, 2024
1 fork
Importers
37 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function enableGithubBackups({ owner, repo, debugProxy, allow } = {}) {
// Create onVersion hook, which simply forwards to the dispatchProxyEndpoint
onVersion(async ({ id, version } = {}) => {
// To check if this was called send a request to a honeypot
fetch(
`https://webcode.run/observablehq.com/@endpointservices/realtime-request-log` +
`/version-${id}@${version}`
);

// Endpoints don't work in the thumbnail process, as they cannot figure out their top level slugs
// However, as we have the id and version passed in we can derive it.
let dispatchURL = `https://webcode.run/observablehq.com/d/${id};${dispatchProxyName(
{ owner, repo, event_type: "new_notebook_version" }
)}`;
// Now we forward this information to the dispatch function
fetch(dispatchURL, {
method: "POST",
body: JSON.stringify({ url: await urlFromId(id), id, version })
});
});

const dispatchBackup = createDispatchProxy({
owner,
repo,
event_type: "new_notebook_version",
client_payload: null,
debug: debugProxy,
beforeDispatch: async ({ client_payload } = {}, ctx) => {
// Mixin the apiKey so Github can access private code exports
client_payload.api_key = ctx.secrets.api_key;
}
});

return dispatchBackup;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
Insert cell
trusted_domain = ["api.observablehq.com"]
Insert cell
Insert cell
Insert cell
Insert cell
import { fetchp } with { trusted_domain as ALLOW_DOMAINS } from "@tomlarkworthy/fetchp"
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more