import {z} from 'zod' export type CreateApiApiV2SecretRotationsDbtServiceTokenArgs = {body: {name: string, projectId: string, description?: (string | null) | undefined, connectionId: string, environment: string, secretPath: string, isAutoRotationEnabled?: boolean | undefined, rotationInterval: number, rotateAtUtc?: {hours: number, minutes: number} | undefined, parameters: {tokenName: string, permissionGrants: Array<{permissionSet: '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?: number | undefined}>}, secretsMapping: {serviceToken: string}}}; export type CreateApiApiV2SecretRotationsDbtServiceTokenOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV2SecretRotationsDbtServiceTokenResponse = z.object({secretRotation: 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 }; /** * Create a DBT Service Token Rotation for the specified project. * * POST /api/v2/secret-rotations/dbt-service-token */ export const createApiApiV2SecretRotationsDbtServiceToken = async (args: CreateApiApiV2SecretRotationsDbtServiceTokenArgs, options?: CreateApiApiV2SecretRotationsDbtServiceTokenOptions) => { const {baseUrl = "https://us.infisical.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/secret-rotations/dbt-service-token${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiApiV2SecretRotationsDbtServiceTokenResponse, await res.json()) };