import {z} from 'zod' export type CallbackUrlSettings = {callBackUrl?: (string | null) | undefined, authenticationType?: (string | null) | undefined, userName?: (string | null) | undefined, password?: (string | null) | undefined, tokenAuthority?: (string | null) | undefined, clientId?: (string | null) | undefined, clientSecret?: (string | null) | undefined, clientScope?: (string | null) | undefined}; export type StatusUrlSettings = {statusUrl?: (string | null) | undefined, authenticationType?: (string | null) | undefined, userName?: (string | null) | undefined, password?: (string | null) | undefined, tokenAuthority?: (string | null) | undefined, clientId?: (string | null) | undefined, clientSecret?: (string | null) | undefined, clientScope?: (string | null) | undefined}; export type PersonalLinkSettings = {personallinkurl?: (string | null) | undefined, authenticationType?: (string | null) | undefined, userName?: (string | null) | undefined, password?: (string | null) | undefined, tokenAuthority?: (string | null) | undefined, clientId?: (string | null) | undefined, clientSecret?: (string | null) | undefined, clientScope?: (string | null) | undefined}; export type WebHook = {callbackUrlEnabled?: boolean | undefined, statusUrlEnabled?: boolean | undefined, personalUrlEnabled?: boolean | undefined, callbackUrlSettings?: (Array | null) | undefined, statusUrlSettings?: (Array | null) | undefined, personalUrlSettings?: (Array | null) | undefined}; export type PatchApiOrgunitOrgunitIdGroupsGroupIdNotificationUrlArgs = {orgunitId: string, groupId: string, body: WebHook}; export type PatchApiOrgunitOrgunitIdGroupsGroupIdNotificationUrlOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const externalApiResponseNew = z.object({appCode: z.string().optional(), message: z.string().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 }; /** * Update notification setting * * PATCH /orgunit/{orgunitId}/groups/{groupId}/notification-url */ export const patchApiOrgunitOrgunitIdGroupsGroupIdNotificationUrl = async (args: PatchApiOrgunitOrgunitIdGroupsGroupIdNotificationUrlArgs, options: PatchApiOrgunitOrgunitIdGroupsGroupIdNotificationUrlOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/orgunit/${encodeURIComponent(String(args.orgunitId))}/groups/${encodeURIComponent(String(args.groupId))}/notification-url${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(externalApiResponseNew, await res.json()) };