import {z} from 'zod' export type GetApiRestapiJsonV1ResourcesResourceIdAccountsArgs = {orgName?: string | undefined, resourceId: number, INPUT_DATA?: ({operation?: ({Details?: ({VIEWTYPE?: ('ALLMYPASSWORD' | 'FAVOURITEPASSWORD' | 'RECENTLYACCESSEDPASSWORD' | 'LINUXSSHPASSWORD' | 'WINDOWSRDPPASSWORD') | undefined, GROUPID?: string | undefined, STARTINDEX?: string | undefined, LIMIT?: string | undefined, SEARCHTYPE?: ('ACCOUNT' | 'RESOURCE') | undefined, SEARCHVALUE?: string | undefined, SEARCHCOLUMN?: ('ALL' | 'ACCOUNT_NAME' | 'RESOURCE_TYPE' | 'RESOURCENAME' | 'RESOURCE_DESCRIPTION' | 'RESOURCE_URL' | 'DNS_NAME' | 'DEPARTMENT' | 'LOCATION') | undefined}) | undefined}) | undefined}) | undefined}; export type GetApiRestapiJsonV1ResourcesResourceIdAccountsOptions = {baseUrl?: string | undefined, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const operationResult = z.object({message: z.string().optional(), status: z.string().optional()}); export const accountDetails = z.object({"ACCOUNT NAME": z.string().optional(), "ACCOUNT ID": z.string().optional(), ACCOUNT_DESCRIPTION: z.string().optional(), "ACCOUNT PASSWORD POLICY": z.string().optional(), "PASSWORD STATUS": z.string().optional(), ISFAVPASS: z.string().optional(), PASSWORDREQUEST_REASON_MANDATORY: z.string().optional(), AUTOLOGONLIST: z.array(z.string()).optional(), AUTOLOGONSTATUS: z.string().optional(), ISREMOTEAPPONLY: z.string().optional(), REMOTEAPPLIST: z.record(z.string(), z.string()).optional(), IS_USER_WITH_COMMAND_CONTROL_ROLE: z.string().optional(), IS_COMMAND_CONTROL_CONFIGURED: z.string().optional(), PASSWDID: z.string().optional(), IS_TICKETID_REQD: z.string().optional(), IS_TICKETID_REQD_MANDATORY: z.string().optional(), IS_TICKETID_REQD_ACW: z.string().optional(), IS_TOTP_CONFIGURED: z.string().optional(), TOTP_VALIDITY: z.string().optional(), IS_PRIVATE_KEY_LOGIN_ENABLED: z.string().optional(), IS_GATEWAY_SESSION_RECORDING_ENABLED: z.string().optional(), IS_WEB_SESSION_RECORDING_ENABLED: z.string().optional(), ISREASONREQUIRED: z.string().optional()}); export const getAccountsForResourceResponse = z.object({operation: z.object({result: operationResult.optional(), Details: z.object({"RESOURCE NAME": z.string().optional(), "RESOURCE ID": z.string().optional(), "RESOURCE TYPE": z.string().optional(), "RESOURCE DESCRIPTION": z.string().optional(), LOCATION: z.string().optional(), "DNS NAME": z.string().optional(), "DOMAIN NAME": z.string().optional(), "RESOURCE URL": z.string().optional(), "RESOURCE OWNER": z.string().optional(), DEPARTMENT: z.string().optional(), "RESOURCE PASSWORD POLICY": z.string().optional(), PASSWORDREQUEST_REASON_MANDATORY: z.string().optional(), IS_LOCAL_ACCOUNTS_AUTOLOGON_RESTRICTED: z.string().optional(), IS_SSH_RESTRICTED: z.string().optional(), NEWSSHTERMINAL: z.string().optional(), IS_TOTP_SUPPORTED: z.string().optional(), ALLOWOPENURLINBROWSER: z.string().optional(), ISRDPRESTRICTED: z.string().optional(), ALLACCOUNTCOUNT: z.string().optional(), "CUSTOM FIELD": z.array(z.object({CUSTOMFIELDLABEL: z.string().optional(), CUSTOMFIELDTYPE: z.enum(["Character", "Date", "Numeric", "Password", "File"]).optional(), CUSTOMFIELDCOLUMNNAME: z.string().optional(), CUSTOMFIELDVALUE: z.string().optional()})).optional(), "ACCOUNT LIST": z.array(accountDetails).optional()}).optional()}).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 }; /** * Fetch all accounts for a resource * * GET /restapi/json/v1/resources/{resourceId}/accounts */ export const getApiRestapiJsonV1ResourcesResourceIdAccounts = async (args: GetApiRestapiJsonV1ResourcesResourceIdAccountsArgs, options?: GetApiRestapiJsonV1ResourcesResourceIdAccountsOptions) => { const {baseUrl = "https://Hostname:Port", fetch: fetchFn = fetch, AuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.orgName != null) headers.set("orgName", String(args.orgName)) if (args.INPUT_DATA != null) query.append("INPUT_DATA", JSON.stringify(args.INPUT_DATA)) if (AuthToken !== undefined) headers.set("AUTHTOKEN", AuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/restapi/json/v1/resources/${encodeURIComponent(String(args.resourceId))}/accounts${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(getAccountsForResourceResponse, await res.json()) };