export type ClickTrackingOptedIn = string; export type ClickTrackingOptedOut = string; export type CommercialOptedIn = string; export type CommercialOptedOut = string; export type OpenTrackingOptedIn = string; export type OpenTrackingOptedOut = string; export type SuppressionState = 'spam_complaint' | 'commercial_spam_complaint' | 'bounce' | 'imported' | 'carrier_deactivation'; export type TransactionalOptedIn = string; export type TransactionalOptedOut = string; export type TagArray = Array; export type TagGroupObject = {[key: string]: TagArray}; export type EmailChannelObject = {attributes?: Record | undefined, channel: {address: string, click_tracking_opted_in?: ClickTrackingOptedIn | undefined, click_tracking_opted_out?: ClickTrackingOptedOut | undefined, commercial_opted_in?: CommercialOptedIn | undefined, commercial_opted_out?: CommercialOptedOut | undefined, locale_country?: string | undefined, locale_language?: string | undefined, open_tracking_opted_in?: OpenTrackingOptedIn | undefined, open_tracking_opted_out?: OpenTrackingOptedOut | undefined, suppression_state?: SuppressionState | undefined, timezone?: string | undefined, transactional_opted_in?: TransactionalOptedIn | undefined, transactional_opted_out?: TransactionalOptedOut | undefined, type: 'email'}, opt_in_mode?: ('classic' | 'double') | undefined, properties?: {[key: string]: unknown} | undefined, tag_operations?: TagGroupObject | undefined}; export type CreateApiApiChannelsEmailReplaceChannelIdArgs = {channel_id: string, body: EmailChannelObject}; export type CreateApiApiChannelsEmailReplaceChannelIdOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Replace email channel * * POST /api/channels/email/replace/{channel_id} * * Also accepts auth: bearerAuth, oauth2Token */ export const createApiApiChannelsEmailReplaceChannelId = async (args: CreateApiApiChannelsEmailReplaceChannelIdArgs, options?: CreateApiApiChannelsEmailReplaceChannelIdOptions) => { const {baseUrl = "https://go.urbanairship.com", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "text/plain") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/channels/email/replace/${encodeURIComponent(String(args.channel_id))}${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 res.text() };