import {z} from 'zod' export type GetApiResourcesV1ConfigurationsScim2Args = {tenantId?: string | undefined, source?: string | undefined, connectionName?: string | undefined, id?: string | undefined}; export type GetApiResourcesV1ConfigurationsScim2Options = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const scim2ConnectionConfigResponse = z.object({id: z.string(), tenantId: z.string(), connectionName: z.string(), source: z.string(), syncToUserManagement: z.boolean(), lastSync: z.string().nullable(), createdAt: z.string()}); export const getApiResourcesV1ConfigurationsScim2Response = z.array(scim2ConnectionConfigResponse); 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 SCIM configurations * * GET /resources/v1/configurations/scim2 */ export const getApiResourcesV1ConfigurationsScim2 = async (args: GetApiResourcesV1ConfigurationsScim2Args, options?: GetApiResourcesV1ConfigurationsScim2Options) => { const {baseUrl = "http://localhost:8181", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.tenantId != null) query.append("tenantId", String(args.tenantId)) if (args.source != null) query.append("source", String(args.source)) if (args.connectionName != null) query.append("connectionName", String(args.connectionName)) if (args.id != null) query.append("id", String(args.id)) const url = `${baseUrl.replace(/\/+$/, '')}/resources/v1/configurations/scim2${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(getApiResourcesV1ConfigurationsScim2Response, await res.json()) };