import {z} from 'zod' export type GetApiPasswordVaultCredentialsIdSecretArgs = {id: string, resourceId?: string | undefined, credentialVersion?: string | undefined, domain?: string | undefined}; export type GetApiPasswordVaultCredentialsIdSecretOptions = {baseUrl?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const jumpcloudPrivilegedAccessLinkedWebsite = z.object({id: z.string().optional(), name: z.string().optional(), permissions: z.array(z.string()).optional(), uri: z.string().optional()}); export const jumpcloudPrivilegedAccessCreditCardSecret = z.object({cardNumber: z.string().optional(), cvv: z.string().optional()}); export const jumpcloudPrivilegedAccessIdCardSecret = z.object({idNumber: z.string().optional()}); export const jumpcloudPrivilegedAccessSecureNote = z.object({note: z.string().optional()}); export const jumpcloudPrivilegedAccessTwoFa = z.object({twoFaSecret: z.string().optional()}); export const jumpcloudPrivilegedAccessSecretValuePayload = z.object({connectionString: z.string().optional(), creditCard: jumpcloudPrivilegedAccessCreditCardSecret.optional(), idCard: jumpcloudPrivilegedAccessIdCardSecret.optional(), mfaKey: z.string().optional(), passphrase: z.string().optional(), password: z.string().optional(), privateKey: z.string().optional(), publicKey: z.string().optional(), secureNote: jumpcloudPrivilegedAccessSecureNote.optional(), twoFa: jumpcloudPrivilegedAccessTwoFa.optional()}); export const jumpcloudPrivilegedAccessGetCredentialSecretReply = z.object({linkedWebsites: z.array(jumpcloudPrivilegedAccessLinkedWebsite).optional(), secret: jumpcloudPrivilegedAccessSecretValuePayload.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 }; /** * List Credential Secret * * GET /password-vault/credentials/{id}/secret */ export const getApiPasswordVaultCredentialsIdSecret = async (args: GetApiPasswordVaultCredentialsIdSecretArgs, options?: GetApiPasswordVaultCredentialsIdSecretOptions) => { const {baseUrl = "https://console.jumpcloud.com/api/v2", fetch: fetchFn = fetch, xApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.resourceId != null) query.append("resourceId", String(args.resourceId)) if (args.credentialVersion != null) query.append("credentialVersion", String(args.credentialVersion)) if (args.domain != null) query.append("domain", String(args.domain)) if (xApiKey !== undefined) headers.set("x-api-key", xApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/password-vault/credentials/${encodeURIComponent(String(args.id))}/secret${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(jumpcloudPrivilegedAccessGetCredentialSecretReply, await res.json()) };