export type OcapiV1LoyaltyMembersUpdateMemberUsernameUpdate = {username: string, currentPassword: string}; export type UpdateApiOcapiV1MembersCurrentCredentialsUsernameArgs = {loyaltySessionToken?: string | undefined, 'Connect-Region-Code'?: string | undefined, body: OcapiV1LoyaltyMembersUpdateMemberUsernameUpdate}; export type UpdateApiOcapiV1MembersCurrentCredentialsUsernameOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Updates the username of the currently authenticated member * * PUT /ocapi/v1/members/current/credentials/username */ export const updateApiOcapiV1MembersCurrentCredentialsUsername = async (args: UpdateApiOcapiV1MembersCurrentCredentialsUsernameArgs, options: UpdateApiOcapiV1MembersCurrentCredentialsUsernameOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args.loyaltySessionToken != null) headers.set("loyaltySessionToken", String(args.loyaltySessionToken)) if (args['Connect-Region-Code'] != null) headers.set("Connect-Region-Code", String(args['Connect-Region-Code'])) const url = `${baseUrl.replace(/\/+$/, '')}/ocapi/v1/members/current/credentials/username${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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 };