export type OcapiV1PushNotificationTokenType = 'Android' | 'Ios'; export type OcapiV1PushNotificationToken = {id: string, type: OcapiV1PushNotificationTokenType}; export type UpdateApiOcapiV1MembersCurrentPushNotificationTokenArgs = {'Connect-Region-Code'?: string | undefined, body: OcapiV1PushNotificationToken}; export type UpdateApiOcapiV1MembersCurrentPushNotificationTokenOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Updates the push notification token of the currently authenticated member allowing * their mobile device to receive push notifications * * PUT /ocapi/v1/members/current/push-notification-token */ export const updateApiOcapiV1MembersCurrentPushNotificationToken = async (args: UpdateApiOcapiV1MembersCurrentPushNotificationTokenArgs, options: UpdateApiOcapiV1MembersCurrentPushNotificationTokenOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['Connect-Region-Code'] != null) headers.set("Connect-Region-Code", String(args['Connect-Region-Code'])) const url = `${baseUrl.replace(/\/+$/, '')}/ocapi/v1/members/current/push-notification-token${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 };