import {z} from 'zod' export type GetApiApiV2SecretRotationsDbtServiceTokenArgs = {projectId: string}; export type GetApiApiV2SecretRotationsDbtServiceTokenOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV2SecretRotationsDbtServiceTokenResponse = z.object({secretRotations: z.array(z.object({id: z.string(), name: z.string(), description: z.string().nullable().optional(), isAutoRotationEnabled: z.boolean().optional(), activeIndex: z.number().optional(), folderId: z.string(), connectionId: z.string(), createdAt: z.string(), updatedAt: z.string(), rotationInterval: z.number(), rotationStatus: z.string(), lastRotationAttemptedAt: z.string(), lastRotatedAt: z.string(), lastRotationJobId: z.string().nullable().optional(), nextRotationAt: z.string().nullable().optional(), isLastRotationManual: z.boolean().optional(), connection: z.object({app: z.literal("dbt"), name: z.string(), id: z.string()}), environment: z.object({slug: z.string(), name: z.string(), id: z.string()}), projectId: z.string(), folder: z.object({id: z.string(), path: z.string()}), rotateAtUtc: z.object({hours: z.number().gte(0).lte(23), minutes: z.number().gte(0).lte(59)}), lastRotationMessage: z.string().nullable().optional(), type: z.literal("dbt-service-token"), parameters: z.object({tokenName: z.string().min(1).max(255), permissionGrants: z.array(z.object({permissionSet: z.enum(["account_admin", "account_viewer", "admin", "analyst", "billing_admin", "cost_insights_admin", "cost_insights_viewer", "cost_management_admin", "cost_management_viewer", "database_admin", "developer", "fusion_admin", "git_admin", "job_admin", "job_runner", "job_viewer", "manage_marketplace_apps", "member", "metadata_only", "owner", "project_creator", "readonly", "scim_only", "security_admin", "semantic_layer_only", "stakeholder", "team_admin", "webhooks_only"]), projectId: z.number().optional()}))}), secretsMapping: z.object({serviceToken: z.string().min(1)})}))}); 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 }; /** * List the DBT Service Token Rotations for the specified project. * * GET /api/v2/secret-rotations/dbt-service-token */ export const getApiApiV2SecretRotationsDbtServiceToken = async (args: GetApiApiV2SecretRotationsDbtServiceTokenArgs, options?: GetApiApiV2SecretRotationsDbtServiceTokenOptions) => { const {baseUrl = "https://us.infisical.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.projectId != null) query.append("projectId", String(args.projectId)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/secret-rotations/dbt-service-token${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(getApiApiV2SecretRotationsDbtServiceTokenResponse, await res.json()) };