export type UsersPatchOperation = {op: string, path: string, value?: (string | null) | undefined}; export type UsersPatchUserTokenOpts = {patch: Array}; export type PatchApiUsersUserIdTokensTokenArgs = {user_id: string, token: string, body: UsersPatchUserTokenOpts}; export type PatchApiUsersUserIdTokensTokenOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Update a token * * PATCH /users/{user_id}/tokens/{token} */ export const patchApiUsersUserIdTokensToken = async (args: PatchApiUsersUserIdTokensTokenArgs, options?: PatchApiUsersUserIdTokensTokenOptions) => { const {baseUrl = "https://api.courier.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/users/${encodeURIComponent(String(args.user_id))}/tokens/${encodeURIComponent(String(args.token))}${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 undefined };