export type SetPasswordAttributes = {password: string}; export type SetPasswordData = {type: 'password-sets', attributes: SetPasswordAttributes}; export type SetPasswordRequestEnvelope = {data: SetPasswordData}; export type CreateApiV2StudentsIdSetPasswordArgs = {id: string, body: SetPasswordRequestEnvelope}; export type CreateApiV2StudentsIdSetPasswordOptions = {baseUrl: string, JWTAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Set student password * * POST /v2/students/{id}/set-password/ */ export const createApiV2StudentsIdSetPassword = async (args: CreateApiV2StudentsIdSetPasswordArgs, options: CreateApiV2StudentsIdSetPasswordOptions) => { const {baseUrl, fetch: fetchFn = fetch, JWTAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (JWTAuth !== undefined) headers.set('authorization', `Bearer ${JWTAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/students/${encodeURIComponent(String(args.id))}/set-password/${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 };