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 CreateApiListsListIdSubscriptionsArgs = {'Idempotency-Key'?: string | undefined, 'x-idempotency-expiration'?: string | undefined, list_id: string, body: {recipients: Array}}; export type CreateApiListsListIdSubscriptionsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Add subscribers to a list * * POST /lists/{list_id}/subscriptions */ export const createApiListsListIdSubscriptions = async (args: CreateApiListsListIdSubscriptionsArgs, options?: CreateApiListsListIdSubscriptionsOptions) => { 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 (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (args['x-idempotency-expiration'] != null) headers.set("x-idempotency-expiration", String(args['x-idempotency-expiration'])) 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: "POST", 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 };