import {z} from 'zod' export type UpdateCampaignRequest = {resellerId?: string | undefined, sample1?: string | undefined, sample2?: string | undefined, sample3?: string | undefined, sample4?: string | undefined, sample5?: string | undefined, messageFlow?: string | undefined, helpMessage?: string | undefined, autoRenewal?: boolean | undefined, webhookURL?: string | undefined, webhookFailoverURL?: string | undefined}; export type UpdateApi10dlcCampaignCampaignIdArgs = {campaignId: string, body: UpdateCampaignRequest}; export type UpdateApi10dlcCampaignCampaignIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const telnyxCampaignCSP = z.object({ageGated: z.boolean().optional(), autoRenewal: z.boolean().optional(), billedDate: z.string().optional(), brandId: z.string(), brandDisplayName: z.string().optional(), campaignId: z.string(), tcrBrandId: z.string().optional(), tcrCampaignId: z.string().optional(), createDate: z.string().optional(), cspId: z.string(), description: z.string(), directLending: z.boolean().optional(), embeddedLink: z.boolean().optional(), embeddedPhone: z.boolean().optional(), helpKeywords: z.string().optional(), helpMessage: z.string().optional(), messageFlow: z.string().optional(), mock: z.boolean(), nextRenewalOrExpirationDate: z.string().optional(), numberPool: z.boolean().optional(), optinKeywords: z.string().optional(), optinMessage: z.string().optional(), optoutKeywords: z.string().optional(), optoutMessage: z.string().optional(), referenceId: z.string().optional(), resellerId: z.string().optional(), sample1: z.string().optional(), sample2: z.string().optional(), sample3: z.string().optional(), sample4: z.string().optional(), sample5: z.string().optional(), status: z.string().optional(), subUsecases: z.array(z.string()), subscriberHelp: z.boolean().optional(), subscriberOptin: z.boolean().optional(), subscriberOptout: z.boolean().optional(), termsAndConditions: z.boolean(), usecase: z.string(), vertical: z.string().optional(), webhookURL: z.string().optional(), webhookFailoverURL: z.string().optional(), isTMobileRegistered: z.boolean().optional(), isTMobileSuspended: z.boolean().optional(), isTMobileNumberPoolingEnabled: z.boolean().optional(), failureReasons: z.string().optional(), submissionStatus: z.enum(["CREATED", "FAILED", "PENDING"]).optional(), campaignStatus: z.enum(["TCR_PENDING", "TCR_SUSPENDED", "TCR_EXPIRED", "TCR_ACCEPTED", "TCR_FAILED", "TELNYX_ACCEPTED", "TELNYX_FAILED", "MNO_PENDING", "MNO_ACCEPTED", "MNO_REJECTED", "MNO_PROVISIONED", "MNO_PROVISIONING_FAILED"]).optional(), privacyPolicyLink: z.string().optional(), termsAndConditionsLink: z.string().optional(), embeddedLinkSample: z.string().optional()}); 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 campaign * * PUT /10dlc/campaign/{campaignId} */ export const updateApi10dlcCampaignCampaignId = async (args: UpdateApi10dlcCampaignCampaignIdArgs, options?: UpdateApi10dlcCampaignCampaignIdOptions) => { const {baseUrl = "https://api.telnyx.com/v2", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/10dlc/campaign/${encodeURIComponent(String(args.campaignId))}${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 validateResponse(telnyxCampaignCSP, await res.json()) };