import {z} from 'zod' export type PatchApiApiOrganizationsNameServiceAccountsServiceAccountIdTokensTokenIdArgs = {name: string, serviceAccountId: string, tokenId: string, body: {displayName?: string | undefined, permissions?: (Array<'repo.content.read' | 'repo.contribute.write' | 'repo.write' | 'inference.serverless.write' | 'inference.endpoints.infer.write' | 'inference.endpoints.write' | 'org.read' | 'org.write' | 'collection.read' | 'collection.write' | 'resourceGroup.write' | 'job.write' | 'org.serviceAccounts.read' | 'org.serviceAccounts.write' | 'org.auditLog.write'>) | undefined, repoIds?: Array | undefined, repoPermissions?: (Array<'repo.content.read' | 'repo.write'>) | undefined, userPermissions?: Array<'user.gated-repos-requests.write'> | undefined, endpointPatterns?: Array | undefined, skipNetworkSecurity?: boolean | undefined, canReadGatedRepos?: boolean | undefined}}; export type PatchApiApiOrganizationsNameServiceAccountsServiceAccountIdTokensTokenIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiApiOrganizationsNameServiceAccountsServiceAccountIdTokensTokenIdResponse = z.object({_id: z.string(), displayName: z.string(), permissions: z.array(z.string()), repoIds: z.array(z.string()), repoPermissions: z.array(z.string()), userPermissions: z.array(z.string()), endpointPatterns: z.array(z.string()), skipNetworkSecurity: z.boolean(), canReadGatedRepos: z.boolean()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Update service-account token * * PATCH /api/organizations/{name}/service-accounts/{serviceAccountId}/tokens/{tokenId} */ export const patchApiApiOrganizationsNameServiceAccountsServiceAccountIdTokensTokenId = async (args: PatchApiApiOrganizationsNameServiceAccountsServiceAccountIdTokensTokenIdArgs, options?: PatchApiApiOrganizationsNameServiceAccountsServiceAccountIdTokensTokenIdOptions) => { const {baseUrl = "https://huggingface.co", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/organizations/${encodeURIComponent(String(args.name))}/service-accounts/${encodeURIComponent(String(args.serviceAccountId))}/tokens/${encodeURIComponent(String(args.tokenId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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 validateResponse(patchApiApiOrganizationsNameServiceAccountsServiceAccountIdTokensTokenIdResponse, await res.json()) };