import {z} from 'zod' export type GetApiBusinessV2WebhooksSubscriptionsWebhookSubscriptionsIdArgs = {webhookSubscriptionsId: string}; export type GetApiBusinessV2WebhooksSubscriptionsWebhookSubscriptionsIdOptions = {baseUrl?: string | undefined, standardAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const webhookEventName = z.enum(["business_trip_created", "business_trip_updated", "business_trip_deleted", "card_activated", "card_change_status", "card_creation", "card_destroyed", "card_lost", "card_replaced", "card_stolen", "card_label_updated", "card_assignee_updated", "add_resources_card", "add_resources_member", "add_resources_wallet", "create_group", "delete_group", "move_resources_card", "move_resources_member", "move_resources_wallet", "remove_resources_card", "remove_resources_member", "remove_resources_wallet", "update_group", "store_order_completed", "store_order_placed", "balanced_transfer", "billing", "card_authorization", "conversion", "customer_care_deposit", "customer_care_withdraw", "edit_tag", "inbound_payment", "inbound_payment_reversal", "internal_transfer", "inter_account_transfer", "inter_account_transfer_recurring_billing", "joule_feed", "load_failed", "load_money", "recurring_billing", "scheduled_transfer", "transaction_adjustment", "unload_money", "wiretransfer", "upload_completed", "attachment_delete", "new_user", "user_status_changed", "user_updated", "user_deleted", "wallet_created", "wallet_deleted", "vehicle_create", "vehicle_update", "vehicle_delete", "purchase_create", "purchase_update", "purchase_delete", "purchase_redeem_card", "created_expense_configuration", "disabled_expense_configuration", "enabled_expense_configuration", "updated_expense_configuration", "completed_transactions_import", "updated_transaction", "change_expense_type", "subscription_activated", "subscription_created", "subscription_updated", "subscription_deleted", "subscription_assignee_added", "subscription_assignee_removed", "online_ads_activated", "online_ads_created", "online_ads_updated", "online_ads_deleted", "online_ads_assignee_added", "online_ads_assignee_removed", "transaction_created", "transaction_modified", "transaction_deleted", "transaction_business_trip_linked", "transaction_business_trip_unlinked", "contact_created", "contact_updated", "contact_deleted", "refueling_created", "refueling_updated", "refueling_deleted"]); export const webhookSubscription = z.object({id: z.string().optional(), webhook_url: z.string().optional(), enabled_events: z.array(webhookEventName).optional(), description: z.string().optional(), active: z.boolean().optional(), creation_date: z.string().optional(), last_update: 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 }; /** * Get Webhook Subscription * * GET /business/v2/webhooks/subscriptions/{webhookSubscriptionsId} */ export const getApiBusinessV2WebhooksSubscriptionsWebhookSubscriptionsId = async (args: GetApiBusinessV2WebhooksSubscriptionsWebhookSubscriptionsIdArgs, options?: GetApiBusinessV2WebhooksSubscriptionsWebhookSubscriptionsIdOptions) => { const {baseUrl = "https://api.soldo.com", fetch: fetchFn = fetch, standardAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (standardAuth !== undefined) headers.set('authorization', `Bearer ${standardAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/business/v2/webhooks/subscriptions/${encodeURIComponent(String(args.webhookSubscriptionsId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(webhookSubscription, await res.json()) };