import {z} from 'zod' export type CampaignContentLinkRequest = {label: string, url: string}; export type CampaignContentAskRequest = {links?: Array | undefined, text?: (string | null) | undefined, title?: (string | null) | undefined}; export type CampaignContentThankYouRequest = {redirect_url?: (string | null) | undefined, sharing_message?: (string | null) | undefined, sharing_url?: (string | null) | undefined}; export type CampaignContentPageRequest = {links?: Array | undefined, text?: (string | null) | undefined, thank_you?: CampaignContentThankYouRequest | undefined, title?: (string | null) | undefined}; export type CampaignContentConsentRequest = {additional_info?: (string | null) | undefined, checkbox_text?: (string | null) | undefined, details?: (string | null) | undefined}; export type CampaignLanguageContentRequest = {ask?: CampaignContentAskRequest | undefined, campaign_page?: CampaignContentPageRequest | undefined, consent?: CampaignContentConsentRequest | undefined, disclaimer_text?: (string | null) | undefined, phone_legal_text?: (string | null) | undefined, terms_text?: (string | null) | undefined, thank_you?: CampaignContentThankYouRequest | undefined}; export type CampaignContentRequest = {ar?: CampaignLanguageContentRequest | undefined, da?: CampaignLanguageContentRequest | undefined, de?: CampaignLanguageContentRequest | undefined, en?: CampaignLanguageContentRequest | undefined, es?: CampaignLanguageContentRequest | undefined, fi?: CampaignLanguageContentRequest | undefined, fr?: CampaignLanguageContentRequest | undefined, he?: CampaignLanguageContentRequest | undefined, hu?: CampaignLanguageContentRequest | undefined, it?: CampaignLanguageContentRequest | undefined, ja?: CampaignLanguageContentRequest | undefined, ko?: CampaignLanguageContentRequest | undefined, nl?: CampaignLanguageContentRequest | undefined, no?: CampaignLanguageContentRequest | undefined, pl?: CampaignLanguageContentRequest | undefined, pt?: CampaignLanguageContentRequest | undefined, ru?: CampaignLanguageContentRequest | undefined, sv?: CampaignLanguageContentRequest | undefined, zh?: CampaignLanguageContentRequest | undefined}; export type CampaignFrequencyRequest = {default?: boolean | undefined, default_amount?: (string | null) | undefined, enabled?: boolean | undefined, impact_descriptions_enabled?: boolean | undefined, minimum_amount?: (string | null) | undefined, suggested_amounts?: (Array) | undefined}; export type CampaignFrequenciesRequest = {annual?: CampaignFrequencyRequest | undefined, bimonthly?: CampaignFrequencyRequest | undefined, biweekly?: CampaignFrequencyRequest | undefined, daily?: CampaignFrequencyRequest | undefined, every4weeks?: CampaignFrequencyRequest | undefined, monthly?: CampaignFrequencyRequest | undefined, once?: CampaignFrequencyRequest | undefined, quarterly?: CampaignFrequencyRequest | undefined, semiannual?: CampaignFrequencyRequest | undefined, weekly?: CampaignFrequencyRequest | undefined}; export type CampaignMediaSlotRequest = {image_crop?: ('smart' | 'center' | 'smart_faces' | 'smart_objects' | 'smart_faces_objects') | undefined, image_url?: (string | null) | undefined, logo_crop?: ('smart' | 'center' | 'smart_faces' | 'smart_objects' | 'smart_faces_objects') | undefined, logo_url?: (string | null) | undefined, video_url?: (string | null) | undefined}; export type CampaignMediaRequest = {ask?: CampaignMediaSlotRequest | undefined, campaign_page?: CampaignMediaSlotRequest | undefined}; export type CampaignPageSharingChannelsRequest = {copy_link?: boolean | undefined, email?: boolean | undefined, facebook?: boolean | undefined, linkedin?: boolean | undefined, twitter?: boolean | undefined}; export type CampaignSharingChannelsRequest = {email?: boolean | undefined, facebook?: boolean | undefined, linkedin?: boolean | undefined, twitter?: boolean | undefined}; export type CampaignThankYouRequest = {include_supporter_data?: boolean | undefined, sharing?: CampaignSharingChannelsRequest | undefined, type?: ('thank_you_screen' | 'redirect') | undefined}; export type CampaignPageSettingsRequest = {sharing?: CampaignPageSharingChannelsRequest | undefined, thank_you?: CampaignThankYouRequest | undefined}; export type CampaignConsentChannelsRequest = {email?: boolean | undefined, phone_calls?: boolean | undefined, postal_mail?: boolean | undefined, sms?: boolean | undefined, social_media?: boolean | undefined}; export type CampaignCustomizedConsentRequest = {channels?: CampaignConsentChannelsRequest | undefined, collection_method?: ('explicit_opt_in' | 'pre_checked_opt_in' | 'auto_opt_in') | undefined, show_if_required_by_law?: boolean | undefined}; export type CampaignGeneralConsentRequest = {prechecked?: boolean | undefined, show_if_required_by_law?: boolean | undefined}; export type CampaignConsentRequest = {customized?: CampaignCustomizedConsentRequest | undefined, general?: CampaignGeneralConsentRequest | undefined, type?: ('none' | 'general' | 'customized') | undefined}; export type CampaignCustomFieldRequest = {name: string, value: string}; export type CampaignDonationMatchingRequest = {enabled?: boolean | undefined, end_date?: (string | null) | undefined, end_date_enabled?: boolean | undefined, limit?: (string | null) | undefined, limit_enabled?: boolean | undefined, minimum_amount?: (string | null) | undefined, ratio?: ('2:1' | '1:1' | '1:2' | '1:3' | '1:4' | '1:5' | '1:6' | '1:7' | '1:8' | '1:9' | '1:10' | null) | undefined, sponsor_enabled?: boolean | undefined, sponsor_logo?: (string | null) | undefined, sponsor_logo_crop?: ('smart' | 'center' | 'smart_faces' | 'smart_objects' | 'smart_faces_objects') | undefined, sponsor_name?: (string | null) | undefined, start_date?: (string | null) | undefined}; export type CampaignPhoneRequest = {enabled: boolean, legal_text_enabled: boolean, required: boolean}; export type CampaignTributeRequest = {delivery_email?: boolean | undefined, delivery_postal_mail?: boolean | undefined, highlight_name?: boolean | undefined}; export type CampaignSettingsRequest = {ai_default_frequency?: boolean | undefined, anonymous_enabled?: boolean | undefined, ask_page_enabled?: boolean | undefined, campaign_page?: CampaignPageSettingsRequest | undefined, comment_enabled?: boolean | undefined, consent?: CampaignConsentRequest | undefined, crypto_enabled?: boolean | undefined, custom_fields?: Array | undefined, default_language?: string | undefined, default_payment_type?: ('money' | 'crypto') | undefined, disclaimer_enabled?: boolean | undefined, donation_matching?: CampaignDonationMatchingRequest | undefined, mailing_enabled?: boolean | undefined, mailing_from_amount?: string | undefined, mailing_required?: boolean | undefined, mailing_required_from_amount?: string | undefined, money_enabled?: boolean | undefined, on_behalf_of_org_enabled?: boolean | undefined, personalized_amounts?: boolean | undefined, phone?: CampaignPhoneRequest | undefined, post_donation_upsell?: boolean | undefined, pre_donation_upsell?: boolean | undefined, questions?: Array | undefined, questions_enabled?: boolean | undefined, supported_languages?: (Array<'en' | 'es' | 'fr' | 'nl' | 'no' | 'de' | 'fi' | 'ar' | 'sv' | 'it' | 'pt' | 'zh' | 'ja' | 'ko' | 'hu' | 'da' | 'ru' | 'pl' | 'he'>) | undefined, terms_enabled?: boolean | undefined, terms_prechecked?: boolean | undefined, thank_you?: CampaignThankYouRequest | undefined, title_enabled?: boolean | undefined, title_required?: boolean | undefined, transaction_costs?: ('default_yes' | 'default_no' | 'only_yes' | 'only_no' | 'smart_covering') | undefined, tribute?: CampaignTributeRequest | undefined, tribute_enabled?: boolean | undefined}; export type UpdateCampaignRequest = {code?: (string | null) | undefined, content?: CampaignContentRequest | undefined, end_date?: (string | null) | undefined, formats?: (Array<'checkout_modal' | 'campaign_page'>) | undefined, frequencies?: CampaignFrequenciesRequest | undefined, livemode?: boolean | undefined, media?: CampaignMediaRequest | undefined, name?: string | undefined, settings?: CampaignSettingsRequest | undefined, url_path?: (string | null) | undefined}; export type CreateApiV1CampaignsIdArgs = {id: string, body: UpdateCampaignRequest}; export type CreateApiV1CampaignsIdOptions = {baseUrl: string, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const accountResponse = z.object({code: z.string().nullable(), id: z.string(), name: z.string()}); export const campaignLinkResponse = z.object({label: z.string(), url: z.string()}); export const campaignPageContentResponse = z.object({links: z.array(campaignLinkResponse), text: z.string().nullable(), title: z.string().nullable()}); export const campaignThankYouContentResponse = z.object({redirect_url: z.string().nullable(), sharing_message: z.string().nullable(), sharing_url: z.string().nullable()}); export const campaignPageWithThankYouContentResponse = z.object({links: z.array(campaignLinkResponse), text: z.string().nullable(), thank_you: campaignThankYouContentResponse, title: z.string().nullable()}); export const campaignConsentContentResponse = z.object({additional_info: z.string().nullable(), checkbox_text: z.string().nullable(), details: z.string().nullable()}); export const campaignContentResponse = z.object({ask: campaignPageContentResponse, campaign_page: campaignPageWithThankYouContentResponse, consent: campaignConsentContentResponse, disclaimer_text: z.string().nullable(), phone_legal_text: z.string().nullable(), terms_text: z.string().nullable(), thank_you: campaignThankYouContentResponse}); export const campaignDesignation = z.object({code: z.string().nullable(), frequencies: z.array(z.enum(["once", "daily", "weekly", "biweekly", "every4weeks", "monthly", "bimonthly", "quarterly", "semiannual", "annual"])), id: z.string(), is_default: z.boolean(), name: z.string(), type: z.literal("designation")}); export const campaignDesignationGroup: z.ZodType = z.object({children: z.array(z.discriminatedUnion("type", [campaignDesignation, z.lazy(() => campaignDesignationGroup)])), id: z.string(), name: z.string(), type: z.literal("designation_group")}); export const campaignFrequencySettingsResponse = z.object({default: z.boolean(), default_amount: z.string().nullable(), impact_descriptions_enabled: z.boolean(), minimum_amount: z.string(), suggested_amounts: z.array(z.string().nullable()), type: z.enum(["once", "daily", "weekly", "biweekly", "every4weeks", "monthly", "bimonthly", "quarterly", "semiannual", "annual"])}); export const campaignImageResponse = z.object({height: z.number().nullable(), url: z.string(), width: z.number().nullable()}); export const campaignVideoResponse = z.object({provider: z.string(), url: z.string()}); export const campaignMediaSlotResponse = z.object({image: campaignImageResponse.nullable(), logo: campaignImageResponse.nullable(), video: campaignVideoResponse.nullable()}); export const campaignMediaResponse = z.object({ask: campaignMediaSlotResponse, campaign_page: campaignMediaSlotResponse}); export const campaignPageSharingChannelsResponse = z.object({copy_link: z.boolean(), email: z.boolean(), facebook: z.boolean(), linkedin: z.boolean(), twitter: z.boolean()}); export const campaignSharingChannelsResponse = z.object({email: z.boolean(), facebook: z.boolean(), linkedin: z.boolean(), twitter: z.boolean()}); export const campaignThankYouSettingsResponse = z.object({include_supporter_data: z.boolean(), sharing: campaignSharingChannelsResponse, type: z.enum(["thank_you_screen", "redirect", "fundraising_page"])}); export const campaignPageSettingsResponse = z.object({sharing: campaignPageSharingChannelsResponse, thank_you: campaignThankYouSettingsResponse}); export const campaignConsentChannelsResponse = z.object({email: z.boolean(), phone_calls: z.boolean(), postal_mail: z.boolean(), sms: z.boolean(), social_media: z.boolean()}); export const campaignCustomizedConsentSettingsResponse = z.object({channels: campaignConsentChannelsResponse, collection_method: z.enum(["explicit_opt_in", "pre_checked_opt_in", "auto_opt_in"]), show_if_required_by_law: z.boolean()}); export const campaignGeneralConsentSettingsResponse = z.object({prechecked: z.boolean(), show_if_required_by_law: z.boolean()}); export const campaignConsentSettingsResponse = z.object({customized: campaignCustomizedConsentSettingsResponse, general: campaignGeneralConsentSettingsResponse, type: z.enum(["none", "general", "customized"])}); export const campaignCustomFieldResponse = z.object({name: z.string(), value: z.string()}); export const campaignDonationMatchingSettingsResponse = z.object({enabled: z.boolean(), end_date: z.string().nullable(), end_date_enabled: z.boolean(), limit: z.string().nullable(), limit_enabled: z.boolean(), minimum_amount: z.string().nullable(), ratio: z.enum(["2:1", "1:1", "1:2", "1:3", "1:4", "1:5", "1:6", "1:7", "1:8", "1:9", "1:10"]).nullable(), sponsor_enabled: z.boolean(), sponsor_logo: campaignImageResponse.nullable(), sponsor_name: z.string().nullable(), start_date: z.string().nullable()}); export const campaignPhoneSettingsResponse = z.object({enabled: z.boolean(), legal_text_enabled: z.boolean(), required: z.boolean()}); export const campaignTributeSettingsResponse = z.object({delivery_email: z.boolean(), delivery_postal_mail: z.boolean(), highlight_name: z.boolean()}); export const campaignSettingsResponse = z.object({ai_default_frequency: z.boolean(), anonymous_enabled: z.boolean(), ask_page_enabled: z.boolean(), campaign_page: campaignPageSettingsResponse, comment_enabled: z.boolean(), consent: campaignConsentSettingsResponse, crypto_enabled: z.boolean(), custom_fields: z.array(campaignCustomFieldResponse), default_language: z.enum(["en-US", "en-GB", "en-CA", "fr-CA", "fr-FR", "es", "nl", "no", "de", "de-x-informal", "fi-FI", "ar-001", "sv", "it", "pt-PT", "pt-BR", "zh-CN", "zh-TW", "ja", "ko", "hu", "da", "ru-RU", "es-US", "pl-PL", "he"]), default_payment_type: z.enum(["money", "crypto"]), disclaimer_enabled: z.boolean(), donation_matching: campaignDonationMatchingSettingsResponse, mailing_enabled: z.boolean(), mailing_from_amount: z.string(), mailing_required: z.boolean(), mailing_required_from_amount: z.string(), money_enabled: z.boolean(), on_behalf_of_org_enabled: z.boolean(), personalized_amounts: z.boolean(), phone: campaignPhoneSettingsResponse, post_donation_upsell: z.boolean(), pre_donation_upsell: z.boolean(), questions: z.array(z.string()), questions_enabled: z.boolean(), supported_languages: z.array(z.enum(["en", "es", "fr", "nl", "no", "de", "fi", "ar", "sv", "it", "pt", "zh", "ja", "ko", "hu", "da", "ru", "pl", "he"])), terms_enabled: z.boolean(), terms_prechecked: z.boolean(), thank_you: campaignThankYouSettingsResponse, title_enabled: z.boolean(), title_required: z.boolean(), transaction_costs: z.enum(["default_yes", "default_no", "only_yes", "only_no", "smart_covering"]), tribute: campaignTributeSettingsResponse, tribute_enabled: z.boolean()}); export const campaignFullResponse = z.object({account: accountResponse, campaign_page_url: z.string().nullable(), code: z.string().nullable(), content: z.record(z.string(), campaignContentResponse), currency: z.enum(["shp", "eur", "aed", "afn", "xcd", "all", "amd", "aoa", "ars", "usd", "aud", "ang", "xcg", "awg", "azn", "bam", "bbd", "inr", "pkr", "bdt", "xof", "bgn", "bhd", "bif", "bmd", "myr", "bnd", "bob", "brl", "bsd", "btn", "nok", "zar", "bwp", "byn", "bzd", "cad", "cdf", "xaf", "chf", "nzd", "clp", "cny", "cop", "crc", "cve", "czk", "djf", "dkk", "dop", "dzd", "egp", "mad", "etb", "fjd", "fkp", "jpy", "gbp", "gel", "ghs", "gip", "gmd", "gnf", "gtq", "gyd", "hkd", "hnl", "hrk", "htg", "huf", "idr", "ils", "isk", "jmd", "jod", "kes", "kgs", "khr", "kmf", "krw", "kwd", "kyd", "kzt", "lak", "lbp", "lkr", "lrd", "lsl", "mdl", "mga", "mkd", "mmk", "mnt", "mop", "mro", "mur", "mvr", "mwk", "mxn", "mzn", "nad", "xpf", "ngn", "nio", "sek", "npr", "omr", "pab", "pen", "pgk", "php", "pln", "pyg", "qar", "ron", "rsd", "rub", "rwf", "sar", "sbd", "scr", "sgd", "sll", "sle", "sos", "srd", "std", "svc", "szl", "thb", "tjs", "tnd", "top", "try", "ttd", "twd", "tzs", "uah", "uyu", "uzs", "vnd", "vuv", "wst", "yer", "zmw", "btc", "eth", "usdt", "usdc", "sol", "dot", "doge", "shib", "ltc", "bch", "xtz", "fil", "ftm", "gala", "paxg", "zec"]), designation_mode: z.enum(["select", "assign"]), designations: z.array(z.discriminatedUnion("type", [campaignDesignation, campaignDesignationGroup])), end_date: z.string().nullable(), formats: z.array(z.enum(["checkout_modal", "campaign_page"])), frequencies: z.array(campaignFrequencySettingsResponse), id: z.string(), media: campaignMediaResponse, name: z.string(), settings: campaignSettingsResponse, status: z.enum(["active", "disabled", "auto_archive", "archived"]), tags: z.array(z.string()), type: z.literal("regular"), url_path: z.string().nullable()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Update a campaign * * POST /v1/campaigns/{id} */ export const createApiV1CampaignsId = async (args: CreateApiV1CampaignsIdArgs, options: CreateApiV1CampaignsIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/campaigns/${encodeURIComponent(String(args.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 validateResponse(campaignFullResponse, await res.json()) };