@saptools/bruno 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +852 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +259 -0
- package/dist/index.js +801 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts","../src/context.ts","../src/paths.ts","../src/run.ts","../src/cf-meta.ts","../src/bru-parser.ts","../src/bru-writer.ts","../src/folder-scan.ts","../src/setup-app.ts","../src/cf-info.ts","../src/use.ts"],"sourcesContent":["import process from \"node:process\";\n\nimport { checkbox, confirm, input, select } from \"@inquirer/prompts\";\nimport { Command } from \"commander\";\n\nimport { readContext } from \"./context.js\";\nimport { runBruno } from \"./run.js\";\nimport { setupApp } from \"./setup-app.js\";\nimport { useContext } from \"./use.js\";\n\nfunction resolveRoot(explicit: string | undefined): string {\n if (explicit) {\n return explicit;\n }\n if (process.env[\"SAPTOOLS_BRUNO_ROOT\"]) {\n return process.env[\"SAPTOOLS_BRUNO_ROOT\"];\n }\n return process.cwd();\n}\n\nexport async function main(argv: readonly string[]): Promise<void> {\n const program = new Command();\n\n program\n .name(\"saptools-bruno\")\n .description(\"Smart runner for Bruno with CF-aware env metadata and automatic token injection\")\n .option(\"--root <dir>\", \"Root directory of the bruno collection (default: cwd)\");\n\n program\n .command(\"setup-app\")\n .description(\"Interactively scaffold a bruno app folder and seed __cf_* variables\")\n .action(async (): Promise<void> => {\n const root = resolveRoot(program.opts<{ root?: string }>().root);\n const result = await setupApp({\n root,\n prompts: {\n selectRegion: async (choices) => await select({ message: \"Select region\", choices: [...choices] }),\n selectOrg: async (choices) => await select({ message: \"Select org\", choices: [...choices] }),\n selectSpace: async (choices) => await select({ message: \"Select space\", choices: [...choices] }),\n selectApp: async (choices) => await select({ message: \"Select app\", choices: [...choices] }),\n confirmCreate: async (path) => await confirm({ message: `Create ${path}?`, default: true }),\n selectEnvironments: async ({ common, existing }) => {\n const seen = new Set<string>();\n const all = [...common, ...existing].filter((name) => {\n if (seen.has(name)) {\n return false;\n }\n seen.add(name);\n return true;\n });\n return await checkbox({\n message: \"Environments to create (space to toggle, enter to confirm)\",\n choices: all.map((name) => ({\n name,\n value: name,\n checked: existing.includes(name),\n })),\n });\n },\n inputCustomEnvName: async () => {\n const raw = await input({\n message: \"Custom environment name (leave empty to skip)\",\n default: \"\",\n validate: (v) => {\n const t = v.trim();\n if (t.length === 0) {\n return true;\n }\n return /^[A-Za-z0-9._-]+$/.test(t)\n ? true\n : \"Only letters, digits, dot, underscore, and dash are allowed.\";\n },\n });\n const trimmed = raw.trim();\n return trimmed.length > 0 ? trimmed : null;\n },\n },\n log: (msg) => {\n process.stdout.write(`${msg}\\n`);\n },\n });\n if (!result.created) {\n process.stdout.write(\"Aborted.\\n\");\n return;\n }\n process.stdout.write(`✔ App folder ready at ${result.appPath}\\n`);\n });\n\n program\n .command(\"run\")\n .description(\"Run a bruno request or folder, auto-injecting an XSUAA token\")\n .argument(\"[target]\", \"Shorthand path (region/org/space/app[/folder/file.bru]) or real path\")\n .option(\"-e, --env <name>\", \"Environment name (default: context or first)\")\n .action(\n async (\n target: string | undefined,\n opts: { env?: string },\n ): Promise<void> => {\n const root = resolveRoot(program.opts<{ root?: string }>().root);\n let effectiveTarget = target;\n\n if (!effectiveTarget) {\n const ctx = await readContext();\n if (!ctx) {\n throw new Error(\n \"No target specified and no default context is set. Run `saptools-bruno use <region/org/space/app>` first.\",\n );\n }\n effectiveTarget = `${ctx.region}/${ctx.org}/${ctx.space}/${ctx.app}`;\n }\n\n const result = await runBruno({\n root,\n target: effectiveTarget,\n ...(opts.env ? { environment: opts.env } : {}),\n log: (msg) => {\n process.stdout.write(`${msg}\\n`);\n },\n });\n process.exit(result.code);\n },\n );\n\n program\n .command(\"use\")\n .description(\"Set the default CF context (region/org/space/app) for future `run` calls\")\n .argument(\"<shorthand>\", \"region/org/space/app\")\n .option(\"--no-verify\", \"Skip verifying the context against the cached CF structure\")\n .action(async (shorthand: string, opts: { verify?: boolean }): Promise<void> => {\n const ctx = await useContext({\n shorthand,\n verify: opts.verify !== false,\n });\n process.stdout.write(`✔ Default context set to ${ctx.region}/${ctx.org}/${ctx.space}/${ctx.app}\\n`);\n });\n\n await program.parseAsync([...argv]);\n}\n\ntry {\n await main(process.argv);\n} catch (err: unknown) {\n const msg = err instanceof Error ? err.message : String(err);\n process.stderr.write(`Error: ${msg}\\n`);\n process.exit(1);\n}\n","import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\n\nimport { brunoContextPath } from \"./paths.js\";\nimport type { BrunoContext } from \"./types.js\";\n\nexport async function readContext(): Promise<BrunoContext | undefined> {\n try {\n const raw = await readFile(brunoContextPath(), \"utf8\");\n return JSON.parse(raw) as BrunoContext;\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") {\n return undefined;\n }\n throw err;\n }\n}\n\nexport async function writeContext(ctx: Omit<BrunoContext, \"updatedAt\">): Promise<BrunoContext> {\n const updated: BrunoContext = { ...ctx, updatedAt: new Date().toISOString() };\n const path = brunoContextPath();\n await mkdir(dirname(path), { recursive: true });\n await writeFile(path, `${JSON.stringify(updated, null, 2)}\\n`, \"utf8\");\n return updated;\n}\n","import { homedir } from \"node:os\";\nimport { join } from \"node:path\";\n\nexport const SAPTOOLS_DIR_NAME = \".saptools\";\nexport const BRUNO_CONTEXT_FILENAME = \"bruno-context.json\";\n\nexport const REGION_FOLDER_PREFIX = \"region__\";\nexport const ORG_FOLDER_PREFIX = \"org__\";\nexport const SPACE_FOLDER_PREFIX = \"space__\";\nexport const ENVIRONMENTS_DIR = \"environments\";\n\nexport function saptoolsDir(): string {\n return join(homedir(), SAPTOOLS_DIR_NAME);\n}\n\nexport function brunoContextPath(): string {\n return join(saptoolsDir(), BRUNO_CONTEXT_FILENAME);\n}\n\nexport function regionFolderName(key: string): string {\n return `${REGION_FOLDER_PREFIX}${key}`;\n}\n\nexport function orgFolderName(name: string): string {\n return `${ORG_FOLDER_PREFIX}${name}`;\n}\n\nexport function spaceFolderName(name: string): string {\n return `${SPACE_FOLDER_PREFIX}${name}`;\n}\n\nexport function parsePrefixedName(\n dirName: string,\n prefix: string,\n): string | undefined {\n if (!dirName.startsWith(prefix)) {\n return undefined;\n }\n return dirName.slice(prefix.length);\n}\n","import { spawn } from \"node:child_process\";\nimport { stat } from \"node:fs/promises\";\nimport { isAbsolute, join, relative, resolve, sep } from \"node:path\";\n\nimport type { AppRef } from \"@saptools/cf-xsuaa\";\nimport { getTokenCached as getTokenCachedApi } from \"@saptools/cf-xsuaa\";\n\nimport { readCfMetaFromFile } from \"./cf-meta.js\";\nimport { parseShorthandPath, scanCollection } from \"./folder-scan.js\";\nimport type { ShorthandRef } from \"./folder-scan.js\";\nimport {\n ENVIRONMENTS_DIR,\n orgFolderName,\n regionFolderName,\n spaceFolderName,\n} from \"./paths.js\";\n\nexport type GetTokenCachedFn = (ref: AppRef) => Promise<string>;\n\nexport interface RunSpawnResult {\n readonly code: number;\n readonly stdout: string;\n readonly stderr: string;\n}\n\nexport type SpawnBruFn = (\n args: readonly string[],\n env: NodeJS.ProcessEnv,\n cwd: string,\n) => Promise<RunSpawnResult>;\n\nexport interface RunOptions {\n readonly root: string;\n readonly target: string;\n readonly environment?: string;\n readonly extraArgs?: readonly string[];\n readonly getTokenCached?: GetTokenCachedFn;\n readonly spawnBru?: SpawnBruFn;\n readonly log?: (msg: string) => void;\n}\n\nexport interface RunPlan {\n readonly filePath: string;\n readonly environment: string;\n readonly envFile: string;\n readonly meta: { readonly region: string; readonly org: string; readonly space: string; readonly app: string };\n readonly token: string;\n readonly bruArgs: readonly string[];\n readonly cwd: string;\n}\n\nexport interface RunResult extends RunPlan {\n readonly code: number;\n readonly stdout: string;\n readonly stderr: string;\n}\n\nfunction defaultSpawnBru(\n args: readonly string[],\n env: NodeJS.ProcessEnv,\n cwd: string,\n): Promise<RunSpawnResult> {\n return new Promise((resolvePromise, rejectPromise) => {\n const child = spawn(\"bru\", [...args], { cwd, env, stdio: \"pipe\" });\n let stdout = \"\";\n let stderr = \"\";\n child.stdout.on(\"data\", (chunk: Buffer) => {\n stdout += chunk.toString(\"utf8\");\n process.stdout.write(chunk);\n });\n child.stderr.on(\"data\", (chunk: Buffer) => {\n stderr += chunk.toString(\"utf8\");\n process.stderr.write(chunk);\n });\n child.on(\"error\", rejectPromise);\n child.on(\"close\", (code) => {\n resolvePromise({ code: code ?? 0, stdout, stderr });\n });\n });\n}\n\nasync function exists(path: string): Promise<boolean> {\n try {\n await stat(path);\n return true;\n } catch {\n return false;\n }\n}\n\nasync function resolveTarget(\n root: string,\n target: string,\n): Promise<{ readonly filePath: string; readonly shorthand: ShorthandRef | undefined }> {\n const direct = isAbsolute(target) ? target : resolve(process.cwd(), target);\n if (await exists(direct)) {\n return { filePath: direct, shorthand: undefined };\n }\n\n const shorthand = parseShorthandPath(target);\n if (!shorthand) {\n throw new Error(`Target not found: ${target}`);\n }\n\n const { region, org, space, app, filePath } = shorthand;\n const appDir = join(\n root,\n regionFolderName(region),\n orgFolderName(org),\n spaceFolderName(space),\n app,\n );\n\n if (!filePath) {\n return { filePath: appDir, shorthand };\n }\n\n const candidate = join(appDir, filePath);\n if (await exists(candidate)) {\n return { filePath: candidate, shorthand };\n }\n\n const withExt = candidate.endsWith(\".bru\") ? candidate : `${candidate}.bru`;\n if (await exists(withExt)) {\n return { filePath: withExt, shorthand };\n }\n\n throw new Error(`File not found: ${candidate}`);\n}\n\nasync function chooseEnvironmentFile(\n appDir: string,\n environment: string | undefined,\n): Promise<{ readonly envFile: string; readonly environment: string }> {\n if (environment) {\n const envFile = join(appDir, ENVIRONMENTS_DIR, `${environment}.bru`);\n if (!(await exists(envFile))) {\n throw new Error(`Environment file not found: ${envFile}`);\n }\n return { envFile, environment };\n }\n\n const collection = await scanCollection(resolve(appDir, \"..\", \"..\", \"..\", \"..\"));\n for (const region of collection.regions) {\n for (const org of region.orgs) {\n for (const space of org.spaces) {\n for (const app of space.apps) {\n if (app.path === appDir && app.environments.length > 0) {\n const first = app.environments[0];\n if (first) {\n return { envFile: first.path, environment: first.name };\n }\n }\n }\n }\n }\n }\n throw new Error(`No environment files found under ${appDir}/${ENVIRONMENTS_DIR}`);\n}\n\nfunction findAppDirFromFile(filePath: string, root: string): string {\n const rel = relative(root, filePath).split(sep);\n if (rel.length < 4) {\n throw new Error(`File is not inside a CF-structured bruno collection: ${filePath}`);\n }\n const [regionDir, orgDir, spaceDir, appDir] = rel;\n if (!regionDir || !orgDir || !spaceDir || !appDir) {\n throw new Error(`File is not inside a CF-structured bruno collection: ${filePath}`);\n }\n return join(root, regionDir, orgDir, spaceDir, appDir);\n}\n\nexport async function buildRunPlan(options: RunOptions): Promise<RunPlan> {\n const { filePath } = await resolveTarget(options.root, options.target);\n const stats = await stat(filePath);\n\n let appDir: string;\n let requestFile: string | undefined;\n\n if (stats.isDirectory()) {\n appDir = filePath;\n requestFile = undefined;\n } else {\n appDir = findAppDirFromFile(filePath, options.root);\n requestFile = filePath;\n }\n\n const { envFile, environment } = await chooseEnvironmentFile(appDir, options.environment);\n\n const meta = await readCfMetaFromFile(envFile);\n if (!meta) {\n throw new Error(\n `Missing __cf_region/__cf_org/__cf_space/__cf_app in ${envFile}. Run \\`saptools-bruno setup-app\\` first.`,\n );\n }\n\n const getToken = options.getTokenCached ?? getTokenCachedApi;\n const token = await getToken(meta);\n\n const bruArgs: string[] = [\"run\"];\n if (requestFile) {\n bruArgs.push(relative(appDir, requestFile) || \".\");\n }\n bruArgs.push(\"--env\", environment, \"--env-var\", `accessToken=${token}`);\n if (options.extraArgs) {\n bruArgs.push(...options.extraArgs);\n }\n\n return {\n filePath,\n environment,\n envFile,\n meta,\n token,\n bruArgs,\n cwd: appDir,\n };\n}\n\nexport async function runBruno(options: RunOptions): Promise<RunResult> {\n const plan = await buildRunPlan(options);\n const spawnFn = options.spawnBru ?? defaultSpawnBru;\n const env: NodeJS.ProcessEnv = { ...process.env, SAPTOOLS_ACCESS_TOKEN: plan.token };\n options.log?.(`▶ bru ${plan.bruArgs.join(\" \")} (cwd=${plan.cwd})`);\n const result = await spawnFn(plan.bruArgs, env, plan.cwd);\n return { ...plan, ...result };\n}\n","import { readFile, writeFile } from \"node:fs/promises\";\n\nimport { parseBruEnvFile } from \"./bru-parser.js\";\nimport { upsertVars } from \"./bru-writer.js\";\nimport { CF_META_KEYS } from \"./types.js\";\nimport type { CfAppRef, CfMetaKey } from \"./types.js\";\n\nexport interface CfMeta {\n readonly region: string;\n readonly org: string;\n readonly space: string;\n readonly app: string;\n}\n\nexport function readCfMetaFromVars(vars: ReadonlyMap<string, string>): CfMeta | undefined {\n const region = vars.get(\"__cf_region\");\n const org = vars.get(\"__cf_org\");\n const space = vars.get(\"__cf_space\");\n const app = vars.get(\"__cf_app\");\n if (!region || !org || !space || !app) {\n return undefined;\n }\n return { region, org, space, app };\n}\n\nexport function buildCfMetaUpdates(ref: CfAppRef, baseUrl?: string): Map<string, string> {\n const updates = new Map<string, string>();\n const pairs: readonly [CfMetaKey, string][] = [\n [\"__cf_region\", ref.region],\n [\"__cf_org\", ref.org],\n [\"__cf_space\", ref.space],\n [\"__cf_app\", ref.app],\n ];\n for (const [k, v] of pairs) {\n updates.set(k, v);\n }\n if (baseUrl !== undefined) {\n updates.set(\"baseUrl\", baseUrl);\n }\n return updates;\n}\n\nexport function hasCfMeta(vars: ReadonlyMap<string, string>): boolean {\n return CF_META_KEYS.every((k) => {\n const v = vars.get(k);\n return v !== undefined && v.length > 0;\n });\n}\n\nexport async function readCfMetaFromFile(path: string): Promise<CfMeta | undefined> {\n const raw = await readFile(path, \"utf8\");\n const parsed = parseBruEnvFile(raw);\n return readCfMetaFromVars(parsed.vars.entries);\n}\n\nexport async function writeCfMetaToFile(\n path: string,\n ref: CfAppRef,\n baseUrl?: string,\n): Promise<boolean> {\n const raw = await readFile(path, \"utf8\");\n const updates = buildCfMetaUpdates(ref, baseUrl);\n const { content, changed } = upsertVars(raw, updates);\n if (changed) {\n await writeFile(path, content, \"utf8\");\n }\n return changed;\n}\n","import type { BruVarsBlock } from \"./types.js\";\n\ninterface BlockRange {\n readonly header: string;\n readonly start: number;\n readonly end: number;\n readonly bodyStart: number;\n readonly bodyEnd: number;\n readonly open: \"{\" | \"[\";\n readonly close: \"}\" | \"]\";\n}\n\nconst HEADER_REGEX = /(^|\\n)\\s*([a-zA-Z][a-zA-Z0-9:_-]*)\\s*([{[])/g;\n\nfunction findMatchingClose(raw: string, open: \"{\" | \"[\", openIdx: number): number {\n const close = open === \"{\" ? \"}\" : \"]\";\n let depth = 1;\n let i = openIdx + 1;\n while (i < raw.length) {\n const ch = raw[i];\n if (ch === open) {\n depth++;\n } else if (ch === close) {\n depth--;\n if (depth === 0) {\n return i;\n }\n }\n i++;\n }\n return -1;\n}\n\nexport function listBlocks(raw: string): readonly BlockRange[] {\n const blocks: BlockRange[] = [];\n HEADER_REGEX.lastIndex = 0;\n let match: RegExpExecArray | null;\n while ((match = HEADER_REGEX.exec(raw)) !== null) {\n const leadingNewline = match[1] ?? \"\";\n const header = match[2];\n const open = match[3];\n if (header === undefined || (open !== \"{\" && open !== \"[\")) {\n continue;\n }\n const headerStart = match.index + leadingNewline.length;\n const openIdx = match.index + match[0].length - 1;\n const closeIdx = findMatchingClose(raw, open, openIdx);\n if (closeIdx === -1) {\n continue;\n }\n blocks.push({\n header,\n start: headerStart,\n end: closeIdx + 1,\n bodyStart: openIdx + 1,\n bodyEnd: closeIdx,\n open,\n close: open === \"{\" ? \"}\" : \"]\",\n });\n }\n return blocks;\n}\n\nexport function parseKeyValueBody(body: string): Map<string, string> {\n const entries = new Map<string, string>();\n for (const lineRaw of body.split(\"\\n\")) {\n const line = lineRaw.trim();\n if (line.length === 0 || line.startsWith(\"//\")) {\n continue;\n }\n const colon = line.indexOf(\":\");\n if (colon === -1) {\n continue;\n }\n const key = line.slice(0, colon).trim();\n const value = line.slice(colon + 1).trim();\n if (key.length > 0) {\n entries.set(key, value);\n }\n }\n return entries;\n}\n\nexport function parseListBody(body: string): string[] {\n const items: string[] = [];\n for (const lineRaw of body.split(\"\\n\")) {\n const line = lineRaw.trim();\n if (line.length === 0 || line.startsWith(\"//\")) {\n continue;\n }\n items.push(line);\n }\n return items;\n}\n\nexport interface ParsedBruEnv {\n readonly vars: BruVarsBlock;\n readonly secrets: readonly string[];\n}\n\nexport function parseBruEnvFile(raw: string): ParsedBruEnv {\n const blocks = listBlocks(raw);\n const varsBlock = blocks.find((b) => b.header === \"vars\" && b.open === \"{\");\n const secretsBlock = blocks.find((b) => b.header === \"vars:secret\" && b.open === \"[\");\n\n const entries = varsBlock\n ? parseKeyValueBody(raw.slice(varsBlock.bodyStart, varsBlock.bodyEnd))\n : new Map<string, string>();\n const secrets = secretsBlock\n ? parseListBody(raw.slice(secretsBlock.bodyStart, secretsBlock.bodyEnd))\n : [];\n\n return { vars: { entries }, secrets };\n}\n","import { listBlocks, parseKeyValueBody } from \"./bru-parser.js\";\n\nexport interface UpsertResult {\n readonly content: string;\n readonly changed: boolean;\n}\n\nfunction formatVarsBlock(entries: ReadonlyMap<string, string>): string {\n const lines: string[] = [];\n for (const [key, value] of entries) {\n lines.push(` ${key}: ${value}`);\n }\n return lines.join(\"\\n\");\n}\n\nexport function upsertVars(\n raw: string,\n updates: ReadonlyMap<string, string>,\n): UpsertResult {\n const blocks = listBlocks(raw);\n const varsBlock = blocks.find((b) => b.header === \"vars\" && b.open === \"{\");\n\n if (!varsBlock) {\n const newBlock = `vars {\\n${formatVarsBlock(updates)}\\n}\\n`;\n const sep = raw.length > 0 && !raw.endsWith(\"\\n\") ? \"\\n\\n\" : raw.length > 0 ? \"\\n\" : \"\";\n return { content: `${raw}${sep}${newBlock}`, changed: updates.size > 0 };\n }\n\n const body = raw.slice(varsBlock.bodyStart, varsBlock.bodyEnd);\n const existing = parseKeyValueBody(body);\n let changed = false;\n for (const [k, v] of updates) {\n if (existing.get(k) !== v) {\n existing.set(k, v);\n changed = true;\n }\n }\n\n if (!changed) {\n return { content: raw, changed: false };\n }\n\n const rebuilt = `\\n${formatVarsBlock(existing)}\\n`;\n const before = raw.slice(0, varsBlock.bodyStart);\n const after = raw.slice(varsBlock.bodyEnd);\n return { content: `${before}${rebuilt}${after}`, changed: true };\n}\n\nexport function ensureSecretEntry(raw: string, secretName: string): UpsertResult {\n const blocks = listBlocks(raw);\n const secretsBlock = blocks.find((b) => b.header === \"vars:secret\" && b.open === \"[\");\n\n if (!secretsBlock) {\n const newBlock = `vars:secret [\\n ${secretName}\\n]\\n`;\n const sep = raw.length > 0 && !raw.endsWith(\"\\n\") ? \"\\n\\n\" : raw.length > 0 ? \"\\n\" : \"\";\n return { content: `${raw}${sep}${newBlock}`, changed: true };\n }\n\n const body = raw.slice(secretsBlock.bodyStart, secretsBlock.bodyEnd);\n const items = body\n .split(\"\\n\")\n .map((l) => l.trim())\n .filter((l) => l.length > 0 && !l.startsWith(\"//\"));\n if (items.includes(secretName)) {\n return { content: raw, changed: false };\n }\n items.push(secretName);\n const rebuilt = `\\n ${items.join(\"\\n \")}\\n`;\n const before = raw.slice(0, secretsBlock.bodyStart);\n const after = raw.slice(secretsBlock.bodyEnd);\n return { content: `${before}${rebuilt}${after}`, changed: true };\n}\n","import { readdir, readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\n\nimport { parseBruEnvFile } from \"./bru-parser.js\";\nimport {\n ENVIRONMENTS_DIR,\n ORG_FOLDER_PREFIX,\n parsePrefixedName,\n REGION_FOLDER_PREFIX,\n SPACE_FOLDER_PREFIX,\n} from \"./paths.js\";\nimport type {\n AppFolder,\n BrunoCollection,\n BruEnvFile,\n OrgFolder,\n RegionFolder,\n SpaceFolder,\n} from \"./types.js\";\n\nasync function safeReaddir(path: string): Promise<readonly string[]> {\n try {\n const entries = await readdir(path, { withFileTypes: true });\n return entries.filter((e) => e.isDirectory()).map((e) => e.name);\n } catch {\n return [];\n }\n}\n\nasync function listFiles(path: string): Promise<readonly string[]> {\n try {\n const entries = await readdir(path, { withFileTypes: true });\n return entries.filter((e) => e.isFile()).map((e) => e.name);\n } catch {\n return [];\n }\n}\n\nasync function loadEnvFile(path: string, name: string): Promise<BruEnvFile> {\n const raw = await readFile(path, \"utf8\");\n const parsed = parseBruEnvFile(raw);\n return {\n path,\n name: name.replace(/\\.bru$/, \"\"),\n raw,\n vars: parsed.vars,\n secrets: parsed.secrets,\n };\n}\n\nasync function scanAppEnvironments(appPath: string): Promise<readonly BruEnvFile[]> {\n const envDir = join(appPath, ENVIRONMENTS_DIR);\n const files = await listFiles(envDir);\n const bruFiles = files.filter((f) => f.endsWith(\".bru\"));\n const loaded: BruEnvFile[] = [];\n for (const file of bruFiles) {\n loaded.push(await loadEnvFile(join(envDir, file), file));\n }\n return loaded;\n}\n\nasync function scanApp(spacePath: string, name: string): Promise<AppFolder> {\n const appPath = join(spacePath, name);\n const environments = await scanAppEnvironments(appPath);\n return { path: appPath, name, environments };\n}\n\nasync function scanSpace(orgPath: string, dirName: string): Promise<SpaceFolder | undefined> {\n const name = parsePrefixedName(dirName, SPACE_FOLDER_PREFIX);\n if (name === undefined) {\n return undefined;\n }\n const spacePath = join(orgPath, dirName);\n const appDirs = await safeReaddir(spacePath);\n const apps: AppFolder[] = [];\n for (const appDir of appDirs) {\n apps.push(await scanApp(spacePath, appDir));\n }\n return { path: spacePath, name, apps };\n}\n\nasync function scanOrg(regionPath: string, dirName: string): Promise<OrgFolder | undefined> {\n const name = parsePrefixedName(dirName, ORG_FOLDER_PREFIX);\n if (name === undefined) {\n return undefined;\n }\n const orgPath = join(regionPath, dirName);\n const spaceDirs = await safeReaddir(orgPath);\n const spaces: SpaceFolder[] = [];\n for (const spaceDir of spaceDirs) {\n const space = await scanSpace(orgPath, spaceDir);\n if (space) {\n spaces.push(space);\n }\n }\n return { path: orgPath, name, spaces };\n}\n\nasync function scanRegion(root: string, dirName: string): Promise<RegionFolder | undefined> {\n const key = parsePrefixedName(dirName, REGION_FOLDER_PREFIX);\n if (key === undefined) {\n return undefined;\n }\n const regionPath = join(root, dirName);\n const orgDirs = await safeReaddir(regionPath);\n const orgs: OrgFolder[] = [];\n for (const orgDir of orgDirs) {\n const org = await scanOrg(regionPath, orgDir);\n if (org) {\n orgs.push(org);\n }\n }\n return { path: regionPath, key, orgs };\n}\n\nexport async function scanCollection(root: string): Promise<BrunoCollection> {\n const regionDirs = await safeReaddir(root);\n const regions: RegionFolder[] = [];\n for (const dir of regionDirs) {\n const region = await scanRegion(root, dir);\n if (region) {\n regions.push(region);\n }\n }\n return { root, regions };\n}\n\nexport interface ShorthandRef {\n readonly region: string;\n readonly org: string;\n readonly space: string;\n readonly app: string;\n readonly environment?: string;\n readonly filePath?: string;\n}\n\nexport function parseShorthandPath(shorthand: string): ShorthandRef | undefined {\n const cleaned = shorthand.replace(/^[./]+/, \"\").replace(/\\\\/g, \"/\");\n const segs = cleaned.split(\"/\").filter((s) => s.length > 0);\n if (segs.length < 4) {\n return undefined;\n }\n const [region, org, space, app, ...rest] = segs;\n if (!region || !org || !space || !app) {\n return undefined;\n }\n if (rest.length === 0) {\n return { region, org, space, app };\n }\n const filePath = rest.join(\"/\");\n const last = rest[rest.length - 1] ?? \"\";\n const environment = last.endsWith(\".bru\") ? last.replace(/\\.bru$/, \"\") : undefined;\n return environment\n ? { region, org, space, app, environment, filePath }\n : { region, org, space, app, filePath };\n}\n","import { mkdir, readdir, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\n\nimport type { OrgNode, RegionKey, RegionNode, SpaceNode } from \"@saptools/cf-sync\";\n\nimport type { CfInfoDeps } from \"./cf-info.js\";\nimport { defaultCfInfoDeps, listRegionsWithContent } from \"./cf-info.js\";\nimport { writeCfMetaToFile } from \"./cf-meta.js\";\nimport {\n ENVIRONMENTS_DIR,\n orgFolderName,\n regionFolderName,\n spaceFolderName,\n} from \"./paths.js\";\nimport type { CfAppRef } from \"./types.js\";\n\nexport interface EnvironmentSelection {\n readonly common: readonly string[];\n readonly existing: readonly string[];\n}\n\nexport interface SetupAppPrompts {\n readonly selectRegion: (choices: readonly { value: RegionKey; name: string }[]) => Promise<RegionKey>;\n readonly selectOrg: (choices: readonly { value: string; name: string }[]) => Promise<string>;\n readonly selectSpace: (choices: readonly { value: string; name: string }[]) => Promise<string>;\n readonly selectApp: (choices: readonly { value: string; name: string }[]) => Promise<string>;\n readonly confirmCreate: (path: string) => Promise<boolean>;\n readonly selectEnvironments: (opts: EnvironmentSelection) => Promise<readonly string[]>;\n readonly inputCustomEnvName: () => Promise<string | null>;\n}\n\nexport interface SetupAppOptions {\n readonly root: string;\n readonly prompts: SetupAppPrompts;\n readonly deps?: CfInfoDeps;\n readonly log?: (msg: string) => void;\n}\n\nexport interface SetupAppResult {\n readonly ref: CfAppRef;\n readonly appPath: string;\n readonly environments: readonly string[];\n readonly created: boolean;\n}\n\nexport const COMMON_ENVIRONMENTS = [\"local\", \"dev\", \"staging\", \"prod\"] as const;\n\nfunction emptyEnvContent(envName: string, ref: CfAppRef): string {\n const lines = [\n \"vars {\",\n ` __cf_region: ${ref.region}`,\n ` __cf_org: ${ref.org}`,\n ` __cf_space: ${ref.space}`,\n ` __cf_app: ${ref.app}`,\n ` environment: ${envName}`,\n \" baseUrl: \",\n \"}\",\n \"\",\n ];\n return lines.join(\"\\n\");\n}\n\nasync function ensureEnvFile(appPath: string, envName: string, ref: CfAppRef): Promise<string> {\n const envDir = join(appPath, ENVIRONMENTS_DIR);\n await mkdir(envDir, { recursive: true });\n const filePath = join(envDir, `${envName}.bru`);\n try {\n await writeFile(filePath, emptyEnvContent(envName, ref), { encoding: \"utf8\", flag: \"wx\" });\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== \"EEXIST\") {\n throw err;\n }\n await writeCfMetaToFile(filePath, ref);\n }\n return filePath;\n}\n\nfunction pickRegion(regions: readonly { key: RegionKey; label: string; orgCount: number }[]): readonly {\n readonly value: RegionKey;\n readonly name: string;\n}[] {\n return regions.map((r) => ({ value: r.key, name: `${r.key} — ${r.label} (${r.orgCount.toString()} org${r.orgCount === 1 ? \"\" : \"s\"})` }));\n}\n\nfunction pickOrg(region: RegionNode): readonly { value: string; name: string }[] {\n return region.orgs.map((o) => ({ value: o.name, name: `${o.name} (${o.spaces.length.toString()} space${o.spaces.length === 1 ? \"\" : \"s\"})` }));\n}\n\nfunction pickSpace(org: OrgNode): readonly { value: string; name: string }[] {\n return org.spaces.map((s) => ({ value: s.name, name: `${s.name} (${s.apps.length.toString()} app${s.apps.length === 1 ? \"\" : \"s\"})` }));\n}\n\nfunction pickApp(space: SpaceNode): readonly { value: string; name: string }[] {\n return space.apps.map((a) => ({ value: a.name, name: a.name }));\n}\n\nexport async function setupApp(options: SetupAppOptions): Promise<SetupAppResult> {\n const deps = options.deps ?? defaultCfInfoDeps;\n const log = options.log ?? ((): void => undefined);\n\n const regions = await listRegionsWithContent(deps);\n if (regions.length === 0) {\n throw new Error(\n \"No CF regions with orgs are cached. Run `cf-sync sync` first, or pass SAP_EMAIL/SAP_PASSWORD to refresh.\",\n );\n }\n\n const regionKey = await options.prompts.selectRegion(pickRegion(regions));\n const regionView = await deps.readRegionView(regionKey);\n if (!regionView) {\n throw new Error(`Region ${regionKey} is not cached. Run \\`cf-sync sync\\` or \\`cf-sync region ${regionKey}\\`.`);\n }\n const region = regionView.region;\n\n if (region.orgs.length === 0) {\n throw new Error(`Region ${regionKey} has no accessible orgs.`);\n }\n\n const orgName = await options.prompts.selectOrg(pickOrg(region));\n const org = region.orgs.find((o) => o.name === orgName);\n if (!org) {\n throw new Error(`Org ${orgName} not found in region ${regionKey}`);\n }\n if (org.spaces.length === 0) {\n throw new Error(`Org ${orgName} has no spaces.`);\n }\n\n const spaceName = await options.prompts.selectSpace(pickSpace(org));\n const space = org.spaces.find((s) => s.name === spaceName);\n if (!space) {\n throw new Error(`Space ${spaceName} not found in org ${orgName}`);\n }\n if (space.apps.length === 0) {\n throw new Error(`Space ${spaceName} has no apps.`);\n }\n\n const appName = await options.prompts.selectApp(pickApp(space));\n const ref: CfAppRef = { region: regionKey, org: orgName, space: spaceName, app: appName };\n\n const appPath = join(\n options.root,\n regionFolderName(regionKey),\n orgFolderName(orgName),\n spaceFolderName(spaceName),\n appName,\n );\n\n const confirmed = await options.prompts.confirmCreate(appPath);\n if (!confirmed) {\n return { ref, appPath, environments: [], created: false };\n }\n\n await mkdir(appPath, { recursive: true });\n\n const existingEnvs = await listExistingEnvs(appPath);\n const common = [...COMMON_ENVIRONMENTS];\n const selected = await options.prompts.selectEnvironments({ common, existing: existingEnvs });\n const custom = await options.prompts.inputCustomEnvName();\n const merged: string[] = [];\n for (const name of [...selected, ...(custom ? [custom] : [])]) {\n const trimmed = name.trim();\n if (trimmed.length > 0 && !merged.includes(trimmed)) {\n merged.push(trimmed);\n }\n }\n if (merged.length === 0) {\n throw new Error(\"At least one environment is required.\");\n }\n\n const created: string[] = [];\n for (const envName of merged) {\n const path = await ensureEnvFile(appPath, envName, ref);\n created.push(path);\n log(`• ${path}`);\n }\n\n return { ref, appPath, environments: created, created: true };\n}\n\nasync function listExistingEnvs(appPath: string): Promise<readonly string[]> {\n try {\n const entries = await readdir(join(appPath, ENVIRONMENTS_DIR), { withFileTypes: true });\n return entries\n .filter((e) => e.isFile() && e.name.endsWith(\".bru\"))\n .map((e) => e.name.replace(/\\.bru$/, \"\"));\n } catch {\n return [];\n }\n}\n","import type {\n CfStructure,\n OrgNode,\n RegionKey,\n RegionNode,\n RegionsView,\n RegionView,\n SpaceNode,\n StructureView,\n} from \"@saptools/cf-sync\";\nimport {\n getRegionView as getRegionViewApi,\n readRegionsView,\n readRegionView,\n readStructureView,\n REGION_KEYS,\n} from \"@saptools/cf-sync\";\n\nexport interface CfInfoDeps {\n readonly readStructureView: () => Promise<StructureView | undefined>;\n readonly readRegionsView: () => Promise<RegionsView>;\n readonly readRegionView: (key: RegionKey) => Promise<RegionView | undefined>;\n readonly getRegionView: (opts: {\n readonly regionKey: RegionKey;\n readonly email?: string;\n readonly password?: string;\n readonly refreshIfMissing?: boolean;\n }) => Promise<RegionView | undefined>;\n}\n\nexport const defaultCfInfoDeps: CfInfoDeps = {\n readStructureView,\n readRegionsView,\n readRegionView,\n getRegionView: getRegionViewApi,\n};\n\nexport function isValidRegionKey(value: string): value is RegionKey {\n return (REGION_KEYS as readonly string[]).includes(value);\n}\n\nexport interface StructureSnapshot {\n readonly source: \"runtime\" | \"stable\" | \"empty\";\n readonly structure: CfStructure | undefined;\n readonly stale: boolean;\n readonly message: string | undefined;\n}\n\nexport async function getStructureSnapshot(\n deps: CfInfoDeps = defaultCfInfoDeps,\n): Promise<StructureSnapshot> {\n const view = await deps.readStructureView();\n if (!view) {\n return {\n source: \"empty\",\n structure: undefined,\n stale: true,\n message: \"No CF structure cached. Run `cf-sync sync` first.\",\n };\n }\n\n const stale = view.source === \"runtime\" && view.metadata?.status === \"running\";\n return {\n source: view.source,\n structure: view.structure,\n stale,\n message: stale ? \"A CF sync is still running — showing partial data.\" : undefined,\n };\n}\n\nexport interface RegionSuggestion {\n readonly key: RegionKey;\n readonly label: string;\n readonly orgCount: number;\n}\n\nexport async function listRegionsWithContent(\n deps: CfInfoDeps = defaultCfInfoDeps,\n): Promise<readonly RegionSuggestion[]> {\n const snapshot = await getStructureSnapshot(deps);\n if (!snapshot.structure) {\n return [];\n }\n return snapshot.structure.regions\n .filter((r) => r.accessible && r.orgs.length > 0)\n .map((r) => ({ key: r.key, label: r.label, orgCount: r.orgs.length }));\n}\n\nexport async function getRegion(\n key: RegionKey,\n deps: CfInfoDeps = defaultCfInfoDeps,\n): Promise<RegionNode | undefined> {\n const view = await deps.readRegionView(key);\n return view?.region;\n}\n\nexport function findOrg(region: RegionNode, orgName: string): OrgNode | undefined {\n return region.orgs.find((o) => o.name === orgName);\n}\n\nexport function findSpace(org: OrgNode, spaceName: string): SpaceNode | undefined {\n return org.spaces.find((s) => s.name === spaceName);\n}\n\nexport function findApp(space: SpaceNode, appName: string): { readonly name: string } | undefined {\n return space.apps.find((a) => a.name === appName);\n}\n\nexport interface ResolvedRef {\n readonly region: RegionNode;\n readonly org: OrgNode;\n readonly space: SpaceNode;\n readonly app: { readonly name: string };\n}\n\nexport async function resolveRef(\n ref: {\n readonly region: RegionKey;\n readonly org: string;\n readonly space: string;\n readonly app: string;\n },\n deps: CfInfoDeps = defaultCfInfoDeps,\n): Promise<ResolvedRef | undefined> {\n const region = await getRegion(ref.region, deps);\n if (!region) {\n return undefined;\n }\n const org = findOrg(region, ref.org);\n if (!org) {\n return undefined;\n }\n const space = findSpace(org, ref.space);\n if (!space) {\n return undefined;\n }\n const app = findApp(space, ref.app);\n if (!app) {\n return undefined;\n }\n return { region, org, space, app };\n}\n","import type { CfInfoDeps } from \"./cf-info.js\";\nimport { isValidRegionKey, resolveRef } from \"./cf-info.js\";\nimport { writeContext } from \"./context.js\";\nimport type { BrunoContext } from \"./types.js\";\n\nexport function parseContextShorthand(shorthand: string): {\n readonly region: string;\n readonly org: string;\n readonly space: string;\n readonly app: string;\n} | undefined {\n const segs = shorthand.split(\"/\").filter((s) => s.length > 0);\n if (segs.length !== 4) {\n return undefined;\n }\n const [region, org, space, app] = segs;\n if (!region || !org || !space || !app) {\n return undefined;\n }\n return { region, org, space, app };\n}\n\nexport interface UseOptions {\n readonly shorthand: string;\n readonly deps?: CfInfoDeps;\n readonly verify?: boolean;\n}\n\nexport async function useContext(options: UseOptions): Promise<BrunoContext> {\n const parsed = parseContextShorthand(options.shorthand);\n if (!parsed) {\n throw new Error(\n `Invalid context shorthand: ${options.shorthand}. Expected <region>/<org>/<space>/<app>.`,\n );\n }\n\n if (!isValidRegionKey(parsed.region)) {\n throw new Error(`Unknown region key: ${parsed.region}`);\n }\n\n if (options.verify !== false) {\n const resolved = await resolveRef({ ...parsed, region: parsed.region }, options.deps);\n if (!resolved) {\n throw new Error(\n `Could not verify ${options.shorthand} against the cached CF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,QAAQ,KAAK,EACb,YAAY,0EAA0E,EACtF,SAAS,eAAe,sBAAsB,EAC9C,OAAO,eAAe,4DAA4D,EAClF,OAAO,OAAO,WAAmB,SAA8C;AAC9E,UAAM,MAAM,MAAM,WAAW;AAAA,MAC3B;AAAA,MACA,QAAQ,KAAK,WAAW;AAAA,IAC1B,CAAC;AACD,IAAAA,SAAQ,OAAO,MAAM,iCAA4B,IAAI,MAAM,IAAI,IAAI,GAAG,IAAI,IAAI,KAAK,IAAI,IAAI,GAAG;AAAA,CAAI;AAAA,EACpG,CAAC;AAEH,QAAM,QAAQ,WAAW,CAAC,GAAG,IAAI,CAAC;AACpC;AAEA,IAAI;AACF,QAAM,KAAKA,SAAQ,IAAI;AACzB,SAAS,KAAc;AACrB,QAAM,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAC3D,EAAAA,SAAQ,OAAO,MAAM,UAAU,GAAG;AAAA,CAAI;AACtC,EAAAA,SAAQ,KAAK,CAAC;AAChB;","names":["process","join","readFile","writeFile","sep","readFile","writeFile","readFile","join","readFile","join","join","mkdir","readdir","writeFile","join","join","mkdir","writeFile","readdir","process"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { RegionKey, StructureView, RegionsView, RegionView, RegionNode, OrgNode, SpaceNode, CfStructure } from '@saptools/cf-sync';
|
|
2
|
+
import { AppRef } from '@saptools/cf-xsuaa';
|
|
3
|
+
|
|
4
|
+
interface CfAppRef {
|
|
5
|
+
readonly region: RegionKey;
|
|
6
|
+
readonly org: string;
|
|
7
|
+
readonly space: string;
|
|
8
|
+
readonly app: string;
|
|
9
|
+
}
|
|
10
|
+
interface BruVarsBlock {
|
|
11
|
+
readonly entries: ReadonlyMap<string, string>;
|
|
12
|
+
}
|
|
13
|
+
interface BruEnvFile {
|
|
14
|
+
readonly path: string;
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly raw: string;
|
|
17
|
+
readonly vars: BruVarsBlock;
|
|
18
|
+
readonly secrets: readonly string[];
|
|
19
|
+
}
|
|
20
|
+
interface AppFolder {
|
|
21
|
+
readonly path: string;
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly environments: readonly BruEnvFile[];
|
|
24
|
+
}
|
|
25
|
+
interface SpaceFolder {
|
|
26
|
+
readonly path: string;
|
|
27
|
+
readonly name: string;
|
|
28
|
+
readonly apps: readonly AppFolder[];
|
|
29
|
+
}
|
|
30
|
+
interface OrgFolder {
|
|
31
|
+
readonly path: string;
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly spaces: readonly SpaceFolder[];
|
|
34
|
+
}
|
|
35
|
+
interface RegionFolder {
|
|
36
|
+
readonly path: string;
|
|
37
|
+
readonly key: string;
|
|
38
|
+
readonly orgs: readonly OrgFolder[];
|
|
39
|
+
}
|
|
40
|
+
interface BrunoCollection {
|
|
41
|
+
readonly root: string;
|
|
42
|
+
readonly regions: readonly RegionFolder[];
|
|
43
|
+
}
|
|
44
|
+
interface BrunoContext {
|
|
45
|
+
readonly region: string;
|
|
46
|
+
readonly org: string;
|
|
47
|
+
readonly space: string;
|
|
48
|
+
readonly app: string;
|
|
49
|
+
readonly updatedAt: string;
|
|
50
|
+
}
|
|
51
|
+
interface CfRoute {
|
|
52
|
+
readonly url: string;
|
|
53
|
+
}
|
|
54
|
+
declare const CF_META_KEYS: readonly ["__cf_region", "__cf_org", "__cf_space", "__cf_app"];
|
|
55
|
+
type CfMetaKey = (typeof CF_META_KEYS)[number];
|
|
56
|
+
|
|
57
|
+
declare const SAPTOOLS_DIR_NAME = ".saptools";
|
|
58
|
+
declare const BRUNO_CONTEXT_FILENAME = "bruno-context.json";
|
|
59
|
+
declare const REGION_FOLDER_PREFIX = "region__";
|
|
60
|
+
declare const ORG_FOLDER_PREFIX = "org__";
|
|
61
|
+
declare const SPACE_FOLDER_PREFIX = "space__";
|
|
62
|
+
declare const ENVIRONMENTS_DIR = "environments";
|
|
63
|
+
declare function saptoolsDir(): string;
|
|
64
|
+
declare function brunoContextPath(): string;
|
|
65
|
+
declare function regionFolderName(key: string): string;
|
|
66
|
+
declare function orgFolderName(name: string): string;
|
|
67
|
+
declare function spaceFolderName(name: string): string;
|
|
68
|
+
declare function parsePrefixedName(dirName: string, prefix: string): string | undefined;
|
|
69
|
+
|
|
70
|
+
interface BlockRange {
|
|
71
|
+
readonly header: string;
|
|
72
|
+
readonly start: number;
|
|
73
|
+
readonly end: number;
|
|
74
|
+
readonly bodyStart: number;
|
|
75
|
+
readonly bodyEnd: number;
|
|
76
|
+
readonly open: "{" | "[";
|
|
77
|
+
readonly close: "}" | "]";
|
|
78
|
+
}
|
|
79
|
+
declare function listBlocks(raw: string): readonly BlockRange[];
|
|
80
|
+
declare function parseKeyValueBody(body: string): Map<string, string>;
|
|
81
|
+
declare function parseListBody(body: string): string[];
|
|
82
|
+
interface ParsedBruEnv {
|
|
83
|
+
readonly vars: BruVarsBlock;
|
|
84
|
+
readonly secrets: readonly string[];
|
|
85
|
+
}
|
|
86
|
+
declare function parseBruEnvFile(raw: string): ParsedBruEnv;
|
|
87
|
+
|
|
88
|
+
interface UpsertResult {
|
|
89
|
+
readonly content: string;
|
|
90
|
+
readonly changed: boolean;
|
|
91
|
+
}
|
|
92
|
+
declare function upsertVars(raw: string, updates: ReadonlyMap<string, string>): UpsertResult;
|
|
93
|
+
declare function ensureSecretEntry(raw: string, secretName: string): UpsertResult;
|
|
94
|
+
|
|
95
|
+
interface CfInfoDeps {
|
|
96
|
+
readonly readStructureView: () => Promise<StructureView | undefined>;
|
|
97
|
+
readonly readRegionsView: () => Promise<RegionsView>;
|
|
98
|
+
readonly readRegionView: (key: RegionKey) => Promise<RegionView | undefined>;
|
|
99
|
+
readonly getRegionView: (opts: {
|
|
100
|
+
readonly regionKey: RegionKey;
|
|
101
|
+
readonly email?: string;
|
|
102
|
+
readonly password?: string;
|
|
103
|
+
readonly refreshIfMissing?: boolean;
|
|
104
|
+
}) => Promise<RegionView | undefined>;
|
|
105
|
+
}
|
|
106
|
+
declare const defaultCfInfoDeps: CfInfoDeps;
|
|
107
|
+
declare function isValidRegionKey(value: string): value is RegionKey;
|
|
108
|
+
interface StructureSnapshot {
|
|
109
|
+
readonly source: "runtime" | "stable" | "empty";
|
|
110
|
+
readonly structure: CfStructure | undefined;
|
|
111
|
+
readonly stale: boolean;
|
|
112
|
+
readonly message: string | undefined;
|
|
113
|
+
}
|
|
114
|
+
declare function getStructureSnapshot(deps?: CfInfoDeps): Promise<StructureSnapshot>;
|
|
115
|
+
interface RegionSuggestion {
|
|
116
|
+
readonly key: RegionKey;
|
|
117
|
+
readonly label: string;
|
|
118
|
+
readonly orgCount: number;
|
|
119
|
+
}
|
|
120
|
+
declare function listRegionsWithContent(deps?: CfInfoDeps): Promise<readonly RegionSuggestion[]>;
|
|
121
|
+
declare function getRegion(key: RegionKey, deps?: CfInfoDeps): Promise<RegionNode | undefined>;
|
|
122
|
+
declare function findOrg(region: RegionNode, orgName: string): OrgNode | undefined;
|
|
123
|
+
declare function findSpace(org: OrgNode, spaceName: string): SpaceNode | undefined;
|
|
124
|
+
declare function findApp(space: SpaceNode, appName: string): {
|
|
125
|
+
readonly name: string;
|
|
126
|
+
} | undefined;
|
|
127
|
+
interface ResolvedRef {
|
|
128
|
+
readonly region: RegionNode;
|
|
129
|
+
readonly org: OrgNode;
|
|
130
|
+
readonly space: SpaceNode;
|
|
131
|
+
readonly app: {
|
|
132
|
+
readonly name: string;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
declare function resolveRef(ref: {
|
|
136
|
+
readonly region: RegionKey;
|
|
137
|
+
readonly org: string;
|
|
138
|
+
readonly space: string;
|
|
139
|
+
readonly app: string;
|
|
140
|
+
}, deps?: CfInfoDeps): Promise<ResolvedRef | undefined>;
|
|
141
|
+
|
|
142
|
+
interface CfMeta {
|
|
143
|
+
readonly region: string;
|
|
144
|
+
readonly org: string;
|
|
145
|
+
readonly space: string;
|
|
146
|
+
readonly app: string;
|
|
147
|
+
}
|
|
148
|
+
declare function readCfMetaFromVars(vars: ReadonlyMap<string, string>): CfMeta | undefined;
|
|
149
|
+
declare function buildCfMetaUpdates(ref: CfAppRef, baseUrl?: string): Map<string, string>;
|
|
150
|
+
declare function hasCfMeta(vars: ReadonlyMap<string, string>): boolean;
|
|
151
|
+
declare function readCfMetaFromFile(path: string): Promise<CfMeta | undefined>;
|
|
152
|
+
declare function writeCfMetaToFile(path: string, ref: CfAppRef, baseUrl?: string): Promise<boolean>;
|
|
153
|
+
|
|
154
|
+
declare function scanCollection(root: string): Promise<BrunoCollection>;
|
|
155
|
+
interface ShorthandRef {
|
|
156
|
+
readonly region: string;
|
|
157
|
+
readonly org: string;
|
|
158
|
+
readonly space: string;
|
|
159
|
+
readonly app: string;
|
|
160
|
+
readonly environment?: string;
|
|
161
|
+
readonly filePath?: string;
|
|
162
|
+
}
|
|
163
|
+
declare function parseShorthandPath(shorthand: string): ShorthandRef | undefined;
|
|
164
|
+
|
|
165
|
+
declare function readContext(): Promise<BrunoContext | undefined>;
|
|
166
|
+
declare function writeContext(ctx: Omit<BrunoContext, "updatedAt">): Promise<BrunoContext>;
|
|
167
|
+
|
|
168
|
+
interface EnvironmentSelection {
|
|
169
|
+
readonly common: readonly string[];
|
|
170
|
+
readonly existing: readonly string[];
|
|
171
|
+
}
|
|
172
|
+
interface SetupAppPrompts {
|
|
173
|
+
readonly selectRegion: (choices: readonly {
|
|
174
|
+
value: RegionKey;
|
|
175
|
+
name: string;
|
|
176
|
+
}[]) => Promise<RegionKey>;
|
|
177
|
+
readonly selectOrg: (choices: readonly {
|
|
178
|
+
value: string;
|
|
179
|
+
name: string;
|
|
180
|
+
}[]) => Promise<string>;
|
|
181
|
+
readonly selectSpace: (choices: readonly {
|
|
182
|
+
value: string;
|
|
183
|
+
name: string;
|
|
184
|
+
}[]) => Promise<string>;
|
|
185
|
+
readonly selectApp: (choices: readonly {
|
|
186
|
+
value: string;
|
|
187
|
+
name: string;
|
|
188
|
+
}[]) => Promise<string>;
|
|
189
|
+
readonly confirmCreate: (path: string) => Promise<boolean>;
|
|
190
|
+
readonly selectEnvironments: (opts: EnvironmentSelection) => Promise<readonly string[]>;
|
|
191
|
+
readonly inputCustomEnvName: () => Promise<string | null>;
|
|
192
|
+
}
|
|
193
|
+
interface SetupAppOptions {
|
|
194
|
+
readonly root: string;
|
|
195
|
+
readonly prompts: SetupAppPrompts;
|
|
196
|
+
readonly deps?: CfInfoDeps;
|
|
197
|
+
readonly log?: (msg: string) => void;
|
|
198
|
+
}
|
|
199
|
+
interface SetupAppResult {
|
|
200
|
+
readonly ref: CfAppRef;
|
|
201
|
+
readonly appPath: string;
|
|
202
|
+
readonly environments: readonly string[];
|
|
203
|
+
readonly created: boolean;
|
|
204
|
+
}
|
|
205
|
+
declare const COMMON_ENVIRONMENTS: readonly ["local", "dev", "staging", "prod"];
|
|
206
|
+
declare function setupApp(options: SetupAppOptions): Promise<SetupAppResult>;
|
|
207
|
+
|
|
208
|
+
type GetTokenCachedFn = (ref: AppRef) => Promise<string>;
|
|
209
|
+
interface RunSpawnResult {
|
|
210
|
+
readonly code: number;
|
|
211
|
+
readonly stdout: string;
|
|
212
|
+
readonly stderr: string;
|
|
213
|
+
}
|
|
214
|
+
type SpawnBruFn = (args: readonly string[], env: NodeJS.ProcessEnv, cwd: string) => Promise<RunSpawnResult>;
|
|
215
|
+
interface RunOptions {
|
|
216
|
+
readonly root: string;
|
|
217
|
+
readonly target: string;
|
|
218
|
+
readonly environment?: string;
|
|
219
|
+
readonly extraArgs?: readonly string[];
|
|
220
|
+
readonly getTokenCached?: GetTokenCachedFn;
|
|
221
|
+
readonly spawnBru?: SpawnBruFn;
|
|
222
|
+
readonly log?: (msg: string) => void;
|
|
223
|
+
}
|
|
224
|
+
interface RunPlan {
|
|
225
|
+
readonly filePath: string;
|
|
226
|
+
readonly environment: string;
|
|
227
|
+
readonly envFile: string;
|
|
228
|
+
readonly meta: {
|
|
229
|
+
readonly region: string;
|
|
230
|
+
readonly org: string;
|
|
231
|
+
readonly space: string;
|
|
232
|
+
readonly app: string;
|
|
233
|
+
};
|
|
234
|
+
readonly token: string;
|
|
235
|
+
readonly bruArgs: readonly string[];
|
|
236
|
+
readonly cwd: string;
|
|
237
|
+
}
|
|
238
|
+
interface RunResult extends RunPlan {
|
|
239
|
+
readonly code: number;
|
|
240
|
+
readonly stdout: string;
|
|
241
|
+
readonly stderr: string;
|
|
242
|
+
}
|
|
243
|
+
declare function buildRunPlan(options: RunOptions): Promise<RunPlan>;
|
|
244
|
+
declare function runBruno(options: RunOptions): Promise<RunResult>;
|
|
245
|
+
|
|
246
|
+
declare function parseContextShorthand(shorthand: string): {
|
|
247
|
+
readonly region: string;
|
|
248
|
+
readonly org: string;
|
|
249
|
+
readonly space: string;
|
|
250
|
+
readonly app: string;
|
|
251
|
+
} | undefined;
|
|
252
|
+
interface UseOptions {
|
|
253
|
+
readonly shorthand: string;
|
|
254
|
+
readonly deps?: CfInfoDeps;
|
|
255
|
+
readonly verify?: boolean;
|
|
256
|
+
}
|
|
257
|
+
declare function useContext(options: UseOptions): Promise<BrunoContext>;
|
|
258
|
+
|
|
259
|
+
export { type AppFolder, BRUNO_CONTEXT_FILENAME, type BruEnvFile, type BruVarsBlock, type BrunoCollection, type BrunoContext, CF_META_KEYS, COMMON_ENVIRONMENTS, type CfAppRef, type CfInfoDeps, type CfMeta, type CfMetaKey, type CfRoute, ENVIRONMENTS_DIR, type EnvironmentSelection, type GetTokenCachedFn, ORG_FOLDER_PREFIX, type OrgFolder, type ParsedBruEnv, REGION_FOLDER_PREFIX, type RegionFolder, type RegionSuggestion, type ResolvedRef, type RunOptions, type RunPlan, type RunResult, type RunSpawnResult, SAPTOOLS_DIR_NAME, SPACE_FOLDER_PREFIX, type SetupAppOptions, type SetupAppPrompts, type SetupAppResult, type ShorthandRef, type SpaceFolder, type SpawnBruFn, type StructureSnapshot, type UpsertResult, type UseOptions, brunoContextPath, buildCfMetaUpdates, buildRunPlan, defaultCfInfoDeps, ensureSecretEntry, findApp, findOrg, findSpace, getRegion, getStructureSnapshot, hasCfMeta, isValidRegionKey, listBlocks, listRegionsWithContent, orgFolderName, parseBruEnvFile, parseContextShorthand, parseKeyValueBody, parseListBody, parsePrefixedName, parseShorthandPath, readCfMetaFromFile, readCfMetaFromVars, readContext, regionFolderName, resolveRef, runBruno, saptoolsDir, scanCollection, setupApp, spaceFolderName, upsertVars, useContext, writeCfMetaToFile, writeContext };
|