export type ScopeGrantRequestJson = {grants?: {[key: string]: Array} | undefined, subject?: (string | null) | undefined}; export type CreateApiApiV1ContextIdScopeGrantsArgs = {context_id: string, body: ScopeGrantRequestJson}; export type CreateApiApiV1ContextIdScopeGrantsOptions = {baseUrl: string, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Grant scope patterns to a principal (not implemented — surface locked) * * POST /api/v1/{context_id}/scope-grants */ export const createApiApiV1ContextIdScopeGrants = async (args: CreateApiApiV1ContextIdScopeGrantsArgs, options: CreateApiApiV1ContextIdScopeGrantsOptions) => { const {baseUrl, fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (apiKey !== undefined) headers.set('authorization', `Bearer ${apiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/${encodeURIComponent(String(args.context_id))}/scope-grants${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };