export type RegisterDevicePushRequest = {endpoint: string | null, p256dh: string | null, auth: string | null, userAgent: string | null}; export type UpdateApiDevicesMePushSubscriptionArgs = {body: RegisterDevicePushRequest | null}; export type UpdateApiDevicesMePushSubscriptionOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * Registers this browser's subscription for the tablet (upsert by endpoint). 204; 400 for a bad * endpoint or keys; 409 `push_unavailable` when tablet push is off for the clinic; 403 * `session_ended` when the tablet's session was revoked or re-coded meanwhile. * * PUT /devices/me/push-subscription */ export const updateApiDevicesMePushSubscription = async (args: UpdateApiDevicesMePushSubscriptionArgs, options?: UpdateApiDevicesMePushSubscriptionOptions) => { const {baseUrl = "https://api.clinicos.vet/backend/business", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/devices/me/push-subscription${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 };