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 PutSubscriptionsRecipient = {recipientId: string, preferences?: RecipientPreferences | undefined}; export type UpdateApiListsListIdSubscriptionsArgs = {list_id: string, body: {recipients: Array}}; export type UpdateApiListsListIdSubscriptionsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Subscribe users to a list * * PUT /lists/{list_id}/subscriptions */ export const updateApiListsListIdSubscriptions = async (args: UpdateApiListsListIdSubscriptionsArgs, options?: UpdateApiListsListIdSubscriptionsOptions) => { 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${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 };