import {z} from 'zod' export type GetApiApiOrganizationsNameServiceAccountsServiceAccountIdArgs = {name: string, serviceAccountId: string}; export type GetApiApiOrganizationsNameServiceAccountsServiceAccountIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiOrganizationsNameServiceAccountsServiceAccountIdResponse = z.object({_id: z.string().min(24).max(24), user: z.string(), name: z.string(), email: z.string(), description: z.string().optional(), createdAt: z.string(), accessTokens: z.array(z.object({_id: z.string().min(24).max(24), displayName: z.string(), createdAt: z.string(), lastUsedAt: z.string().optional(), expiration: z.string().optional(), role: z.enum(["read", "write", "fineGrained"]), permissions: z.array(z.enum(["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"])), repoIds: z.array(z.string().min(24).max(24)), repoPermissions: z.array(z.enum(["repo.content.read", "repo.write"])), endpointPatterns: z.array(z.string()), last4: z.string().optional(), skipNetworkSecurity: z.boolean().optional(), s3AccessKey: z.string().optional()})).optional()}); 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 }; /** * Get service account * * GET /api/organizations/{name}/service-accounts/{serviceAccountId} */ export const getApiApiOrganizationsNameServiceAccountsServiceAccountId = async (args: GetApiApiOrganizationsNameServiceAccountsServiceAccountIdArgs, options?: GetApiApiOrganizationsNameServiceAccountsServiceAccountIdOptions) => { const {baseUrl = "https://huggingface.co", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiApiOrganizationsNameServiceAccountsServiceAccountIdResponse, await res.json()) };