apps/web/lib/admin-api.ts
Metadata
- Purpose: Frontend data/service utility module.
- Domain:
applications - Language:
ts - Bytes: 1318
- Lines: 54
- Content hash (short):
76457ced - Source (start): apps/web/lib/admin-api.ts:1
- Source (end): apps/web/lib/admin-api.ts:54
Indexed Symbols
baseHeaders(line 6, function) - Implements base headers for module behavior.proxyGatewayJson(line 14, function) - Implements proxy gateway json for module behavior.idempotencyHeaders(line 49, function) - Implements idempotency headers for module behavior.
Markdown Headings (if applicable)
No markdown headings detected.
Source Preview
import { randomUUID } from "node:crypto";
import { resolveOperatorAuthToken } from "./operator-session";
const apiBaseUrl = process.env.API_BASE_URL ?? process.env.NEXT_PUBLIC_API_BASE_URL ?? "http://localhost:8080";
function baseHeaders(workspaceId: string, operatorJwt: string | null) {
return {
"content-type": "application/json",
"x-workspace-id": workspaceId,
...(operatorJwt ? { authorization: `Bearer ${operatorJwt}` } : {})
};
}
export async function proxyGatewayJson(path: string, workspaceId: string, init: RequestInit = {}) {
const operatorJwt = await resolveOperatorAuthToken(workspaceId, [
"msp_admin",
"platform_admin",
"ops_engineer",
"viewer",
"data_admin"
]);
const response = await fetch(`${apiBaseUrl}${path}`, {
...init,
headers: {
...baseHeaders(workspaceId, operatorJwt),