import {z} from 'zod' export type JumpcloudPrivilegedAccessGroupAccess = {id?: number | undefined, isResourceManager?: boolean | undefined, name?: string | undefined, permissions?: Array | undefined}; export type JumpcloudPrivilegedAccessUserAccess = {email?: string | undefined, id?: number | undefined, isAdmin?: boolean | undefined, isUser?: boolean | undefined, name?: string | undefined, permissions?: Array | undefined}; export type JumpcloudPrivilegedAccessAccessPolicies = {groups?: Array | undefined, isPrivate?: boolean | undefined, users?: Array | undefined}; export type JumpcloudPrivilegedAccessCredentialType = 'UNDEFINED' | 'PASSWORD' | 'KEY' | 'CONNECTION_STRING' | 'SECURE_NOTE' | 'TWO_FA' | 'CREDIT_CARD' | 'ID_CARD' | 'IDENTITY'; export type JumpcloudPrivilegedAccessCreditCardMetadata = {cardholderName?: string | undefined, expiryMonth?: string | undefined, expiryYear?: string | undefined, last4Digits?: string | undefined}; export type JumpcloudPrivilegedAccessCreditCardSecret = {cardNumber?: string | undefined, cvv?: string | undefined}; export type JumpcloudPrivilegedAccessCreditCardSection = {metadata?: JumpcloudPrivilegedAccessCreditCardMetadata | undefined, secret?: JumpcloudPrivilegedAccessCreditCardSecret | undefined}; export type JumpcloudPrivilegedAccessIdCardMetadata = {country?: string | undefined, idCardExpirationDate?: string | undefined, idType?: string | undefined, issuanceDate?: string | undefined, nameOnId?: string | undefined}; export type JumpcloudPrivilegedAccessIdCardSecret = {idNumber?: string | undefined}; export type JumpcloudPrivilegedAccessIdCardSection = {metadata?: JumpcloudPrivilegedAccessIdCardMetadata | undefined, secret?: JumpcloudPrivilegedAccessIdCardSecret | undefined}; export type JumpcloudPrivilegedAccessIdentityMetadata = {city?: string | undefined, country?: string | undefined, email?: string | undefined, firstAddressLine?: string | undefined, firstName?: string | undefined, gender?: string | undefined, lastName?: string | undefined, middleName?: string | undefined, phone?: string | undefined, secondAddressLine?: string | undefined, title?: string | undefined, zipCode?: string | undefined}; export type JumpcloudPrivilegedAccessKeySection = {passphrase?: string | undefined, privateKey?: string | undefined, publicKey?: string | undefined}; export type JumpcloudPrivilegedAccessLinkedWebsite = {id?: string | undefined, name?: string | undefined, permissions?: Array | undefined, uri?: string | undefined}; export type JumpcloudPrivilegedAccessSecureNote = {note?: string | undefined}; export type JumpcloudPrivilegedAccessTwoFa = {twoFaSecret?: string | undefined}; export type JumpcloudPrivilegedAccessUpsertCredentialRequest = {accessPolicies?: JumpcloudPrivilegedAccessAccessPolicies | undefined, approverRequiresJustification?: boolean | undefined, approvers?: Array | undefined, connectionString?: string | undefined, credentialRotationId?: string | undefined, credentialType?: JumpcloudPrivilegedAccessCredentialType | undefined, creditCard?: JumpcloudPrivilegedAccessCreditCardSection | undefined, domain?: string | undefined, editLinkedWebsites?: boolean | undefined, expirationDate?: string | undefined, folderId?: string | undefined, id?: string | undefined, idCard?: JumpcloudPrivilegedAccessIdCardSection | undefined, identity?: JumpcloudPrivilegedAccessIdentityMetadata | undefined, key?: JumpcloudPrivilegedAccessKeySection | undefined, linkedWebsites?: Array | undefined, mfaEnabled?: boolean | undefined, mfaKey?: string | undefined, name?: string | undefined, notes?: string | undefined, password?: string | undefined, passwordStrength?: number | undefined, requiredApprovers?: boolean | undefined, secureNote?: JumpcloudPrivilegedAccessSecureNote | undefined, sequentialApprovers?: boolean | undefined, tags?: string | undefined, twoFa?: JumpcloudPrivilegedAccessTwoFa | undefined, username?: string | undefined}; export type UpdateApiPasswordVaultCredentialsArgs = {body: JumpcloudPrivilegedAccessUpsertCredentialRequest}; export type UpdateApiPasswordVaultCredentialsOptions = {baseUrl?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const jumpcloudPrivilegedAccessUpsertCredentialReply = z.object({id: z.string().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 }; /** * Update Credential * * PUT /password-vault/credentials */ export const updateApiPasswordVaultCredentials = async (args: UpdateApiPasswordVaultCredentialsArgs, options?: UpdateApiPasswordVaultCredentialsOptions) => { const {baseUrl = "https://console.jumpcloud.com/api/v2", fetch: fetchFn = fetch, xApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (xApiKey !== undefined) headers.set("x-api-key", xApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/password-vault/credentials${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(jumpcloudPrivilegedAccessUpsertCredentialReply, await res.json()) };