import {z} from 'zod' export type GetApiPasswordmanagerSharedfoldersArgs = {search?: string | undefined, skip?: number | undefined, limit?: number | undefined, sort?: string | undefined}; export type GetApiPasswordmanagerSharedfoldersOptions = {baseUrl?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const jumpcloudPwmFolderInList = z.object({createdAt: z.string().optional(), itemsInFolder: z.number().int().optional(), name: z.string().optional(), passwordsCount: z.number().int().optional(), passwordsScore: z.number().optional(), scoreUpdatedAt: z.string().optional(), usersWithAccess: z.number().int().optional(), uuid: z.string().optional()}); export const jumpcloudPwmGetSharedFoldersResponse = z.object({results: z.array(jumpcloudPwmFolderInList).optional(), totalCount: z.number().int().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 Shared Folders * * GET /passwordmanager/sharedfolders */ export const getApiPasswordmanagerSharedfolders = async (args: GetApiPasswordmanagerSharedfoldersArgs, options?: GetApiPasswordmanagerSharedfoldersOptions) => { 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.search != null) query.append("search", String(args.search)) if (args.skip != null) query.append("skip", String(args.skip)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.sort != null) query.append("sort", String(args.sort)) if (xApiKey !== undefined) headers.set("x-api-key", xApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/passwordmanager/sharedfolders${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(jumpcloudPwmGetSharedFoldersResponse, await res.json()) };