import {z} from 'zod' export type MethodCallExpression = {line_number: number, call_position: 'first' | 'last' | 'any'}; export type WhitelistedCallerExpression = {addresses: Array}; export type BlacklistedCallerExpression = {addresses: Array}; export type ContractAddressExpression = {address: string, transaction_type?: ('direct' | 'source' | 'internal') | undefined}; export type NetworkExpression = {network_id: string}; export type TagExpression = {tag: string, transaction_type?: ('direct' | 'source' | 'internal') | undefined}; export type TxStatusExpression = {transaction_success?: boolean | undefined}; export type ParameterCondition = {parameter_name: string, operator: '>' | '>=' | '<' | '<=' | '==' | '!=' | 'contains' | 'notContains', parameter_type: 'uint' | 'int' | 'bool' | 'address' | 'string' | 'byte', nested_parameter_type?: string | undefined, comparison_value: string}; export type FunctionParamsExpression = {address: string, function_line_number: number, parameter_conditions: Array}; export type TxValueExpression = {transaction_value: string, operator: '>' | '>=' | '<' | '<=' | '==' | '!='}; export type EmittedLogExpression = {address: string, event_name: string, event_id: string, match_any?: boolean | undefined, decode_events?: boolean | undefined, match_non_project_contracts?: boolean | undefined, parameter_conditions?: Array | undefined}; export type StateChangeExpression = {address: string, parameter_conditions: Array<{parameter_name: string, parameter_type: string, compare_change?: boolean | undefined, compare_threshold?: boolean | undefined, compare_percentage?: boolean | undefined, comparison_value?: string | undefined, operator?: ('>' | '<' | '==' | '>=' | '<=') | undefined}>}; export type ViewFunctionExpression = {address: string, input: string, network_id: string, parameter_condition?: ({compare_threshold?: boolean | undefined, comparison_value?: string | undefined, operator?: ('>' | '<' | '==' | '>=' | '<=') | undefined, parameter_type?: string | undefined}) | undefined}; export type EthBalanceExpression = {address: string, threshold: string}; export type ERC20TransferMatcherExpression = {address: string, log_name: string, balances: string}; export type TxErrorExpression = {addresses_to_ignore?: Array | undefined}; export type TxInternalErrorExpression = {addresses_to_match?: Array | undefined}; export type NoActionExpression = {no_log?: ({address?: string | undefined, network_id?: string | undefined, event_id?: string | undefined, event_name?: string | undefined}) | undefined, no_transaction?: ({address?: string | undefined, is_from_address?: boolean | undefined, network_id?: string | undefined, transaction_success?: boolean | undefined}) | undefined, check_after_seconds: number}; export type SandwichTransactionExpression = {address: string, transaction_type?: ('direct' | 'source' | 'internal') | undefined}; export type AlertExpression = {type: 'method_call' | 'whitelisted_caller_addresses' | 'blacklisted_caller_addresses' | 'contract_address' | 'network' | 'tag' | 'tx_status' | 'function_params' | 'tx_value' | 'emitted_log' | 'state_change' | 'view_function' | 'eth_balance' | 'erc20_transfer_matcher' | 'tx_error' | 'tx_internal_error' | 'no_action' | 'sandwich_transaction', expression: MethodCallExpression | WhitelistedCallerExpression | BlacklistedCallerExpression | ContractAddressExpression | NetworkExpression | TagExpression | TxStatusExpression | FunctionParamsExpression | TxValueExpression | EmittedLogExpression | StateChangeExpression | ViewFunctionExpression | EthBalanceExpression | ERC20TransferMatcherExpression | TxErrorExpression | TxInternalErrorExpression | NoActionExpression | SandwichTransactionExpression}; export type CreateAlertPayload = {name: string, description?: string | undefined, color?: ('#eeeeee' | '#34ace0' | '#ffda79' | '#ff5252' | '#33d9b2') | undefined, simple_type: 'successful_tx' | 'failed_tx' | 'allowlisted_callers' | 'blocklisted_callers' | 'log_emitted' | 'erc20_transfer_log_emitted' | 'emitted_log_parameter' | 'function_called' | 'called_function_parameter' | 'state_change' | 'eth_balance' | 'tx_value' | 'view_function', enabled?: boolean | undefined, expressions: Array, delivery_channels: Array<{enabled?: boolean | undefined, id?: string | undefined}>}; export type PatchApiV1AccountAccountSlugProjectProjectSlugAlertAlertIdArgs = {accountSlug: string, projectSlug: string, alertId: string, body: CreateAlertPayload}; export type PatchApiV1AccountAccountSlugProjectProjectSlugAlertAlertIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const updateAlertPatchResponse = z.object({}); 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 Alert * * PATCH /v1/account/{accountSlug}/project/{projectSlug}/alert/{alertId} * * Also accepts auth: BearerAuth */ export const patchApiV1AccountAccountSlugProjectProjectSlugAlertAlertId = async (args: PatchApiV1AccountAccountSlugProjectProjectSlugAlertAlertIdArgs, options?: PatchApiV1AccountAccountSlugProjectProjectSlugAlertAlertIdOptions) => { const {baseUrl = "https://api.tenderly.co/api", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-Access-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/account/${encodeURIComponent(String(args.accountSlug))}/project/${encodeURIComponent(String(args.projectSlug))}/alert/${encodeURIComponent(String(args.alertId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(updateAlertPatchResponse, await res.json()) };