async function bb(
link
, {
endpoint = "repositories",
username = credentials[0].username,
password = credentials[0].password,
debug = false
} = {}) {
const URL_PREFIX = 'https://api.bitbucket.org/2.0'
if (link == undefined) { return "Include Bitbucket Link (Docs: https://observablehq.com/@periscopic/bitbucket-api-in-observable)"}
const rawLink = String(link)
let urlLink = rawLink
if (urlLink.startsWith("https://bitbucket.org/")) { urlLink = urlLink.split('/').slice(3).join("/") }
if (!urlLink.startsWith("/") & urlLink !== "") { urlLink = '/' + urlLink }
const rawEndpoint = String(endpoint)
let urlEndpoint = rawEndpoint
if (!urlEndpoint.startsWith("/")) { urlEndpoint = '/' + urlEndpoint }
const fetchQuery = `${URL_PREFIX}${urlEndpoint}${urlLink}`
if (debug) { return fetchQuery }
const headers = (username !== null & password !== null)
? {Authorization: 'Basic ' + base64.encode(username + ':' + password)}
: {}
const response = await fetch(fetchQuery, {
headers: headers
})
return response
}