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

Function createNamespace

packages/dev/src/cloudflare-api.js:331–352  ·  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

329 * @param {{ accountId: string; accountEmail: string | undefined; apiKey: string; }} args
330 */
331async function createNamespace(title, args) {
332 const response = await fetch(
333 `${apiBase}/accounts/${args.accountId}/storage/kv/namespaces`,
334 {
335 method: 'POST',
336 headers: Object.assign(
337 { 'content-type': 'application/json' },
338 buildAuthHeaders(args.apiKey, args.accountEmail)
339 ),
340 body: JSON.stringify({ title })
341 }
342 );
343 if (!response.ok) {
344 throw new Error(
345 `Error creating namespace - ${response.status}: ${
346 response.statusText
347 }\n${await response.text()}`
348 );
349 }
350 const data2 = await response.json();
351 return data2.result;
352}
353
354/**
355 * @param {{ site: StaticSite | null; name: string; accountId: string; accountEmail: string | undefined; apiKey: string; }} args

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