export type CreateApiInstallRepositoriesUserIdRepoTokensTextArgs = {user_id: string, repo: string, body: {name: string}}; export type CreateApiInstallRepositoriesUserIdRepoTokensTextOptions = {baseUrl?: string | undefined, masterToken?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * create read token * * POST /install/repositories/{user_id}/{repo}/tokens.text */ export const createApiInstallRepositoriesUserIdRepoTokensText = async (args: CreateApiInstallRepositoriesUserIdRepoTokensTextArgs, options?: CreateApiInstallRepositoriesUserIdRepoTokensTextOptions) => { const {baseUrl = "https://packagecloud.io", fetch: fetchFn = fetch, masterToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-www-form-urlencoded") headers.set('accept', "text/plain") if (masterToken !== undefined) headers.set('authorization', `Basic ${btoa(`${masterToken.username}:${masterToken.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/install/repositories/${encodeURIComponent(String(args.user_id))}/${encodeURIComponent(String(args.repo))}/tokens.text${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: new URLSearchParams(Object.entries(args.body).flatMap(([key, value]) => (value == null ? [] : [[key, String(value)]])))}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.text() };