export type PreferenceStatus = 'OPTED_IN' | 'OPTED_OUT' | 'REQUIRED'; export type Rule = {start?: (string | null) | undefined, until: string}; export type ChannelClassification = 'direct_message' | 'email' | 'push' | 'sms' | 'webhook' | 'inbox'; export type ChannelPreference = {channel: ChannelClassification}; export type NotificationPreferenceDetails = {status: PreferenceStatus, rules?: (Array | null) | undefined, channel_preferences?: (Array | null) | undefined}; export type NotificationPreferences = {[key: string]: NotificationPreferenceDetails}; export type RecipientPreferences = {categories?: NotificationPreferences | undefined, notifications?: NotificationPreferences | undefined}; export type UpdateApiListsListIdSubscriptionsUserIdArgs = {list_id: string, user_id: string, body: {preferences?: RecipientPreferences | undefined}}; export type UpdateApiListsListIdSubscriptionsUserIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Subscribe a single user profile to a list * * PUT /lists/{list_id}/subscriptions/{user_id} */ export const updateApiListsListIdSubscriptionsUserId = async (args: UpdateApiListsListIdSubscriptionsUserIdArgs, options?: UpdateApiListsListIdSubscriptionsUserIdOptions) => { 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(/\/+$/, '')}/lists/${encodeURIComponent(String(args.list_id))}/subscriptions/${encodeURIComponent(String(args.user_id))}${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 };