SPB Git forge

spb/fetcha

Public
11commits 1branches 0releases
1.5 MBsize
maindefault branch
16 days agolast push
TypeScript 97.5% SQL 1.4% Python 0.8%
1.4 KB · 28 lines typescript
Raw Blame History
1import { API_PUBLIC_URL } from "./utils";23/** Ready-to-run cURL call against /v1/fetch for a freshly created key. */4export function curlSnippet(apiKey: string, opts: { url?: string; country?: string } = {}): string {5  const url = opts.url ?? "https://example.com";6  const country = opts.country ?? "US";7  return [8    `curl -X POST ${API_PUBLIC_URL}/v1/fetch \\`,9    `  -H "Authorization: Bearer ${apiKey}" \\`,10    `  -H "Content-Type: application/json" \\`,11    `  -d '{"url": "${url}", "country": "${country}", "format": "text"}'`,12  ].join("\n");13}1415/** Masked display of a key: prefix + bullets + last 4 (never the secret). */16export function maskedKey(prefix: string, last4: string): string {17  return `${prefix}••••••••${last4}`;18}1920export const SCOPE_INFO: Record<string, { label: string; description: string; comingSoon?: boolean }> = {21  "fetch:execute": { label: "fetch:execute", description: "Call POST /v1/fetch to retrieve pages through the network." },22  "sessions:write": { label: "sessions:write", description: "Create, list and close sticky sessions (/v1/sessions)." },23  "usage:read": { label: "usage:read", description: "Read usage summaries (/v1/usage) and project info (/v1/me)." },24  "browser:use": { label: "browser:use", description: "Managed browser rendering. Not available yet.", comingSoon: true },25};2627export const DEFAULT_SCOPES = ["fetch:execute", "sessions:write", "usage:read"];28