import {z} from 'zod' export type GetApiVaultsVaultUuidItemsArgs = {vaultUuid: string, filter?: string | undefined}; export type GetApiVaultsVaultUuidItemsOptions = {baseUrl?: string | undefined, ConnectToken?: string | undefined, fetch?: typeof fetch | undefined}; export const item = z.object({id: z.string().optional(), title: z.string().optional(), vault: z.object({id: z.string()}), category: z.enum(["LOGIN", "PASSWORD", "API_CREDENTIAL", "SERVER", "DATABASE", "CREDIT_CARD", "MEMBERSHIP", "PASSPORT", "SOFTWARE_LICENSE", "OUTDOOR_LICENSE", "SECURE_NOTE", "WIRELESS_ROUTER", "BANK_ACCOUNT", "DRIVER_LICENSE", "IDENTITY", "REWARD_PROGRAM", "DOCUMENT", "EMAIL_ACCOUNT", "SOCIAL_SECURITY_NUMBER", "MEDICAL_RECORD", "SSH_KEY", "CUSTOM"]), urls: z.array(z.object({label: z.string().optional(), primary: z.boolean().optional(), href: z.string()})).optional(), favorite: z.boolean().optional(), tags: z.array(z.string()).optional(), version: z.number().int().optional(), state: z.enum(["ARCHIVED", "DELETED"]).optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), lastEditedBy: z.string().optional()}); export const getApiVaultsVaultUuidItemsResponse = z.array(item); 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 }; /** * Get all items for inside a Vault * * GET /vaults/{vaultUuid}/items */ export const getApiVaultsVaultUuidItems = async (args: GetApiVaultsVaultUuidItemsArgs, options?: GetApiVaultsVaultUuidItemsOptions) => { const {baseUrl = "http://localhost:8080/v1", fetch: fetchFn = fetch, ConnectToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.filter != null) query.append("filter", String(args.filter)) if (ConnectToken !== undefined) headers.set('authorization', `Bearer ${ConnectToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/vaults/${encodeURIComponent(String(args.vaultUuid))}/items${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(getApiVaultsVaultUuidItemsResponse, await res.json()) };