import {z} from 'zod' export type GetApiOrgunitOrgunitIdGroupsGroupIdKeywordsArgs = {orgunitId: string, groupId: string, filter?: string | undefined, pageNumber?: number | undefined, pageSize?: number | undefined}; export type GetApiOrgunitOrgunitIdGroupsGroupIdKeywordsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const keywordsResponse = z.object({name: z.string().nullable().optional(), onContact: z.string().nullable().optional(), notificationEmails: z.array(z.string()).nullable().optional(), notificationMobileNos: z.array(z.string()).nullable().optional()}); export const keywordsResponsePaginatedResponse4 = z.object({totalCount: z.number().int().optional(), filterCount: z.number().int().optional(), totalPages: z.number().int().optional(), data: z.array(keywordsResponse).nullable().optional()}); export const keywordsResponsePaginatedResponse4ExternalApiResponseNew = z.object({data: keywordsResponsePaginatedResponse4.optional(), appCode: z.string().nullable().optional(), message: z.string().nullable().optional(), isError: z.boolean().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 }; /** * Get all Keywords based on GroupId * * GET /orgunit/{orgunitId}/groups/{groupId}/keywords */ export const getApiOrgunitOrgunitIdGroupsGroupIdKeywords = async (args: GetApiOrgunitOrgunitIdGroupsGroupIdKeywordsArgs, options: GetApiOrgunitOrgunitIdGroupsGroupIdKeywordsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = 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 (args.pageNumber != null) query.append("pageNumber", String(args.pageNumber)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) const url = `${baseUrl.replace(/\/+$/, '')}/orgunit/${encodeURIComponent(String(args.orgunitId))}/groups/${encodeURIComponent(String(args.groupId))}/keywords${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(keywordsResponsePaginatedResponse4ExternalApiResponseNew, await res.json()) };