[skip ci] Initial commit — CodexBar Mobile Expo app
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import type { ClaudeOrg, ClaudeUsageResponse } from "@/types/claude";
|
||||
|
||||
const BASE_URL = "https://claude.ai/api";
|
||||
|
||||
function cookieHeader(sessionKey: string): Record<string, string> {
|
||||
return {
|
||||
Cookie: `sessionKey=${sessionKey}`,
|
||||
"Accept": "application/json",
|
||||
"Origin": "https://claude.ai",
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchClaudeOrgs(sessionKey: string): Promise<ClaudeOrg[]> {
|
||||
const response = await fetch(`${BASE_URL}/organizations`, {
|
||||
headers: cookieHeader(sessionKey),
|
||||
});
|
||||
|
||||
if (response.status === 401 || response.status === 403) {
|
||||
throw new Error("TOKEN_EXPIRED");
|
||||
}
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP_ERROR_${response.status}`);
|
||||
}
|
||||
|
||||
return response.json() as Promise<ClaudeOrg[]>;
|
||||
}
|
||||
|
||||
export async function fetchClaudeUsage(
|
||||
sessionKey: string,
|
||||
orgUuid: string
|
||||
): Promise<ClaudeUsageResponse> {
|
||||
const response = await fetch(`${BASE_URL}/organizations/${orgUuid}/usage`, {
|
||||
headers: cookieHeader(sessionKey),
|
||||
});
|
||||
|
||||
if (response.status === 401 || response.status === 403) {
|
||||
throw new Error("TOKEN_EXPIRED");
|
||||
}
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP_ERROR_${response.status}`);
|
||||
}
|
||||
|
||||
return response.json() as Promise<ClaudeUsageResponse>;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { CodexAuth, CodexUsageResponse } from "@/types/codex";
|
||||
|
||||
const USAGE_URL = "https://chatgpt.com/backend-api/wham/usage";
|
||||
|
||||
export async function fetchCodexUsage(auth: CodexAuth): Promise<CodexUsageResponse> {
|
||||
const headers: Record<string, string> = {
|
||||
Authorization: `Bearer ${auth.accessToken}`,
|
||||
"Content-Type": "application/json",
|
||||
};
|
||||
|
||||
if (auth.accountId) {
|
||||
headers["ChatGPT-Account-Id"] = auth.accountId;
|
||||
}
|
||||
|
||||
const response = await fetch(USAGE_URL, { headers });
|
||||
|
||||
if (response.status === 401 || response.status === 403) {
|
||||
throw new Error("TOKEN_EXPIRED");
|
||||
}
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP_ERROR_${response.status}`);
|
||||
}
|
||||
|
||||
return response.json() as Promise<CodexUsageResponse>;
|
||||
}
|
||||
Reference in New Issue
Block a user