import {z} from 'zod' export type DeleteApiCompaniesCompanyKeyConfigCallbacksCallbackIdArgs = {'X-API-Version'?: string | undefined, 'Content-Type': string, company_key: string, callback_id: string}; export type DeleteApiCompaniesCompanyKeyConfigCallbacksCallbackIdOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const callbackResponse = z.object({callback_id: z.string().optional(), callback_type: z.string().optional(), ack_participant_changed: z.object({campaign_id: z.string().optional()}).optional(), ack_participant_added: z.object({campaign_id: z.string().optional()}).optional(), subscription_added: z.object({list_id: z.string().optional()}).optional(), subscription_removed: z.object({list_id: z.string().optional()}).optional(), unmatched_message_received: z.object({source_code: z.string().optional(), country_code: z.string().optional()}).optional(), wallet_item_install: z.object({campaign_token: z.string().optional()}).optional(), wallet_item_remove: z.object({campaign_token: z.string().optional()}).optional(), device_added: z.object({app_id: z.string().optional()}).optional(), device_removed: z.object({app_id: z.string().optional()}).optional(), device_updated: z.object({app_id: z.string().optional()}).optional(), event_processed: z.object({event_type: z.string().optional(), callbacks_to_send: z.enum(["all", "only_failures", "routing", "carrier_dlr", "handset_dlr"]).optional()}).optional(), destination: z.object({url: z.string().optional(), method: z.enum(["POST", "PUT"]).optional(), content_type: z.enum(["application/json", "text/json"]).optional()}).optional(), start_date: z.string().optional(), end_date: z.string().optional(), url: z.string().optional(), created_date: z.string().optional(), updated_date: 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 }; /** * Cancel a callback * * DELETE /companies/{company_key}/config/callbacks/{callback_id} */ export const deleteApiCompaniesCompanyKeyConfigCallbacksCallbackId = async (args: DeleteApiCompaniesCompanyKeyConfigCallbacksCallbackIdArgs, options?: DeleteApiCompaniesCompanyKeyConfigCallbacksCallbackIdOptions) => { const {baseUrl = "https://public-api.vibescm.com", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-API-Version'] != null) headers.set("X-API-Version", String(args['X-API-Version'])) if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/companies/${encodeURIComponent(String(args.company_key))}/config/callbacks/${encodeURIComponent(String(args.callback_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(callbackResponse, await res.json()) };