MCPcopy Create free account
hub / github.com/cfworker/cfworker / getNamespace

Function getNamespace

packages/dev/src/cloudflare-api.js:282–299  ·  view source on GitHub ↗

* * @param {string} title * @param {{ accountId: string; accountEmail: string | undefined; apiKey: string; }} args

(title, args)

Source from the content-addressed store, hash-verified

280 * @param {{ accountId: string; accountEmail: string | undefined; apiKey: string; }} args
281 */
282async function getNamespace(title, args) {
283 const response = await fetch(
284 `${apiBase}/accounts/${args.accountId}/storage/kv/namespaces?per_page=100`,
285 {
286 headers: buildAuthHeaders(args.apiKey, args.accountEmail)
287 }
288 );
289 if (!response.ok) {
290 throw new Error(
291 `Error fetching namespaces - ${response.status}: ${
292 response.statusText
293 }\n${await response.text()}`
294 );
295 }
296 const data = await response.json();
297 // @ts-ignore
298 return data.result.find(x => x.title === title);
299}
300
301/**
302 *

Callers 2

getSiteBindingsFunction · 0.85
getKVBindingsFunction · 0.85

Calls 3

buildAuthHeadersFunction · 0.85
textMethod · 0.45
jsonMethod · 0.45

Tested by

no test coverage detected