MCPcopy
hub / github.com/supermemoryai/cloudflare-saas-stack / extractAccountDetails

Function extractAccountDetails

scripts/setup.ts:29–57  ·  view source on GitHub ↗
(output: string)

Source from the content-addressed store, hash-verified

27
28// Function to extract account IDs from `wrangler whoami` output
29function extractAccountDetails(output: string): { name: string; id: string }[] {
30 const lines = output.split("\n");
31 const accountDetails: { name: string; id: string }[] = [];
32
33 for (const line of lines) {
34 const isValidLine =
35 line.trim().startsWith("│ ") && line.trim().endsWith(" │");
36
37 if (isValidLine) {
38 const regex = /\b[a-f0-9]{32}\b/g;
39 const matches = line.match(regex);
40
41 if (matches && matches.length === 1) {
42 const accountName = line.split("│ ")[1]?.trim();
43 const accountId = matches[0].replace("│ ", "").replace(" │", "");
44 if (accountName === undefined || accountId === undefined) {
45 console.error(
46 "\x1b[31mError extracting account details from wrangler whoami output.\x1b[0m",
47 );
48 cancel("Operation cancelled.");
49 process.exit(1);
50 }
51 accountDetails.push({ name: accountName, id: accountId });
52 }
53 }
54 }
55
56 return accountDetails;
57}
58
59// Function to prompt for account ID if there are multiple accounts
60async function promptForAccountId(

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected