import {z} from 'zod' export type GroupMembership = {display?: string | undefined, ref?: string | undefined, type?: ('USER' | 'GROUP') | undefined, value?: string | undefined}; export type Meta = {created?: string | undefined, lastModified?: string | undefined, location?: string | undefined, resourceType?: string | undefined, version?: string | undefined}; export type ScimGroup = {displayName?: string | undefined, externalId?: string | undefined, id?: string | undefined, members?: Array | undefined, meta: Meta, schemas?: Array | undefined}; export type UpdateApiV1DirectoryIntegrationScimV2GroupsIdArgs = {id: string, body: ScimGroup}; export type UpdateApiV1DirectoryIntegrationScimV2GroupsIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const groupMembership = z.object({display: z.string().optional(), ref: z.string().optional(), type: z.enum(["USER", "GROUP"]).optional(), value: z.string().optional()}); export const meta = z.object({created: z.string().optional(), lastModified: z.string().optional(), location: z.string().optional(), resourceType: z.string().min(1).max(2147483647).optional(), version: z.string().optional()}); export const enhancedScimGroup = z.object({accountId: z.string().optional(), accountName: z.string().optional(), displayName: z.string().optional(), environment: z.string().optional(), externalId: z.string().optional(), id: z.string().min(1).max(2147483647).optional(), members: z.array(groupMembership).optional(), meta: meta, projectId: z.string().optional(), projectName: z.string().optional(), role: z.string().optional(), schemas: z.array(z.string()).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 SCIM Group * * PUT /v1/directory-integration/scim/v2/Groups/{id} */ export const updateApiV1DirectoryIntegrationScimV2GroupsId = async (args: UpdateApiV1DirectoryIntegrationScimV2GroupsIdArgs, options?: UpdateApiV1DirectoryIntegrationScimV2GroupsIdOptions) => { const {baseUrl = "https://eu1.api.matillion.com/dpc", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/directory-integration/scim/v2/Groups/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(enhancedScimGroup, await res.json()) };