import {z} from 'zod' export type Id = string; export type LoginMethod = {key?: number | undefined, value?: string | undefined}; export type FirstName2 = string | null; export type Initials3 = string; export type Prefix2 = string | null; export type LastName2 = string; export type ContactInformation4 = {placeOfEmployment?: (string | null) | undefined, phoneNumber?: (string | null) | undefined, emailAddress?: string | undefined}; export type UserSpecifiedRole = {key?: number | undefined, value?: string | undefined} | null; export type UserCustomSpecifiedRole = string | null; export type HasAccessToPayrollingTestData = boolean; export type AccessStatus = {key?: number | undefined, value?: string | undefined}; export type HasMultiFactorAuthentication = boolean; export type TwoFactorAuthenticationRequired = boolean; export type AzureActiveDirectory2 = {tenant?: ({id?: string | undefined, description?: string | undefined, tenantRegistrationLevel?: ('provider' | 'employer') | undefined}) | undefined, userId?: string | undefined} | null; export type UserNameReadOnly = string | null; export type IsDepartmentManager = boolean; export type IsLinkedToMultipleEmployers = boolean; export type HasIntegrations2 = boolean; export type HasConnectedApplications2 = boolean; export type DateTimeLastLogin = string | null; export type DateTimeCreation = string; export type UserGetAndPut2 = {id?: Id | undefined, loginMethod?: LoginMethod | undefined, personalDetails?: ({firstName?: FirstName2 | undefined, initials?: Initials3 | undefined, prefix?: Prefix2 | undefined, lastName?: LastName2 | undefined}) | undefined, contactInformation?: ContactInformation4 | undefined, userSpecifiedRole?: UserSpecifiedRole | undefined, userCustomSpecifiedRole?: UserCustomSpecifiedRole | undefined, hasAccessToPayrollingTestData?: HasAccessToPayrollingTestData | undefined, accessStatus?: AccessStatus | undefined, hasMultiFactorAuthentication?: HasMultiFactorAuthentication | undefined, twoFactorAuthenticationRequired?: TwoFactorAuthenticationRequired | undefined, azureActiveDirectory?: AzureActiveDirectory2 | undefined, userName?: UserNameReadOnly | undefined, isDepartmentManager?: IsDepartmentManager | undefined, isLinkedToMultipleEmployers?: IsLinkedToMultipleEmployers | undefined, hasIntegrations?: HasIntegrations2 | undefined, hasConnectedApplications?: HasConnectedApplications2 | undefined, dateTimeLastLogin?: DateTimeLastLogin | undefined, dateTimeCreation?: DateTimeCreation | undefined}; export type UpdateApiV2ProvidersEmployersUsersUserIdArgs = {userId: string, Authorization: string, Accept: string, body: UserGetAndPut2}; export type UpdateApiV2ProvidersEmployersUsersUserIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const version = z.object({obsoleteDate: z.string().nullable().optional(), resourceVersion: z.string().optional()}); export const messageWarning = z.array(z.object({type: z.string().optional(), description: z.string().optional(), id: z.string().nullable().optional(), code: z.number().int().optional(), properties: z.array(z.string()).optional()})); export const id = z.string(); export const loginMethod = z.object({key: z.number().int().optional(), value: z.string().max(50).optional()}); export const firstName2 = z.string().min(1).max(28).nullable(); export const initials3 = z.string().min(1).max(6); export const prefix2 = z.string().min(1).max(10).nullable(); export const lastName2 = z.string().min(1).max(25); export const contactInformation4 = z.object({placeOfEmployment: z.string().min(1).max(24).nullable().optional(), phoneNumber: z.string().min(1).max(15).nullable().optional(), emailAddress: z.string().max(255).optional()}); export const userSpecifiedRole = z.object({key: z.number().int().optional(), value: z.string().max(50).optional()}).nullable(); export const userCustomSpecifiedRole = z.string().max(50).nullable(); export const hasAccessToPayrollingTestData = z.boolean(); export const accessStatus = z.object({key: z.number().int().optional(), value: z.string().max(255).optional()}); export const hasMultiFactorAuthentication = z.boolean(); export const twoFactorAuthenticationRequired = z.boolean(); export const azureActiveDirectory2 = z.object({tenant: z.object({id: z.string().optional(), description: z.string().max(100).optional(), tenantRegistrationLevel: z.enum(["provider", "employer"]).optional()}).optional(), userId: z.string().optional()}).nullable(); export const userNameReadOnly = z.string().min(3).max(50).nullable(); export const isDepartmentManager = z.boolean(); export const isLinkedToMultipleEmployers = z.boolean(); export const hasIntegrations2 = z.boolean(); export const hasConnectedApplications2 = z.boolean(); export const dateTimeLastLogin = z.string().nullable(); export const dateTimeCreation = z.string(); export const userGetAndPut2 = z.object({id: id.optional(), loginMethod: loginMethod.optional(), personalDetails: z.object({firstName: firstName2.optional(), initials: initials3.optional(), prefix: prefix2.optional(), lastName: lastName2.optional()}).optional(), contactInformation: contactInformation4.optional(), userSpecifiedRole: userSpecifiedRole.optional(), userCustomSpecifiedRole: userCustomSpecifiedRole.optional(), hasAccessToPayrollingTestData: hasAccessToPayrollingTestData.optional(), accessStatus: accessStatus.optional(), hasMultiFactorAuthentication: hasMultiFactorAuthentication.optional(), twoFactorAuthenticationRequired: twoFactorAuthenticationRequired.optional(), azureActiveDirectory: azureActiveDirectory2.optional(), userName: userNameReadOnly.optional(), isDepartmentManager: isDepartmentManager.optional(), isLinkedToMultipleEmployers: isLinkedToMultipleEmployers.optional(), hasIntegrations: hasIntegrations2.optional(), hasConnectedApplications: hasConnectedApplications2.optional(), dateTimeLastLogin: dateTimeLastLogin.optional(), dateTimeCreation: dateTimeCreation.optional()}); export const updateApiV2ProvidersEmployersUsersUserIdResponse = z.object({version: version.optional(), messages: messageWarning.optional(), content: userGetAndPut2.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 }; /** * Edit the details of an employer user user * * PUT /v2/providers/employers/users/{userId} */ export const updateApiV2ProvidersEmployersUsersUserId = async (args: UpdateApiV2ProvidersEmployersUsersUserIdArgs, options?: UpdateApiV2ProvidersEmployersUsersUserIdOptions) => { const {baseUrl = "https://api.loket.nl", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json;version=2018-01-01") headers.set('accept', "application/json;version=2018-01-01") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args.Accept != null) headers.set("Accept", String(args.Accept)) const url = `${baseUrl.replace(/\/+$/, '')}/v2/providers/employers/users/${encodeURIComponent(String(args.userId))}${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(updateApiV2ProvidersEmployersUsersUserIdResponse, await res.json()) };