Files
simstudioai--sim/apps/sim/tools/zerobounce/get_credits.ts
T
wehub-resource-sync d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

59 lines
1.8 KiB
TypeScript

import type { ToolConfig } from '@/tools/types'
import type {
ZeroBounceGetCreditsParams,
ZeroBounceGetCreditsResponse,
} from '@/tools/zerobounce/types'
export const getCreditsTool: ToolConfig<ZeroBounceGetCreditsParams, ZeroBounceGetCreditsResponse> =
{
id: 'zerobounce_get_credits',
name: 'ZeroBounce Get Credits',
description: 'Retrieve the remaining validation credits for the authenticated account.',
version: '1.0.0',
params: {
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'ZeroBounce API Key',
},
},
request: {
url: (params) =>
`https://api.zerobounce.net/v2/getcredits?api_key=${encodeURIComponent(params.apiKey.trim())}`,
method: 'GET',
headers: () => ({ Accept: 'application/json' }),
},
transformResponse: async (response: Response) => {
const data = await response.json().catch(() => ({}))
// ZeroBounce returns HTTP 200 with an `{ error }` envelope on auth failure,
// so detect API-level errors from the body, not just the HTTP status.
const errorMessage =
typeof data === 'object' && data !== null && typeof data.error === 'string'
? data.error
: ''
if (!response.ok || errorMessage.length > 0) {
return {
success: false,
error: errorMessage || `ZeroBounce API error: ${response.status} ${response.statusText}`,
output: { credits: 0 },
}
}
const credits = Number(data.Credits ?? 0)
return {
success: true,
output: { credits: Number.isNaN(credits) ? 0 : credits },
}
},
outputs: {
credits: {
type: 'number',
description: 'Remaining validation credits (-1 if unavailable)',
},
},
}