import {z} from 'zod' export type TimestampReq = {date?: number | undefined, hours?: number | undefined, minutes?: number | undefined, month?: number | undefined, nanos?: number | undefined, seconds?: number | undefined, time?: number | undefined, year?: number | undefined}; export type ApprovalReq = {createdDtm?: TimestampReq | undefined, id?: string | undefined, provider?: string | undefined, url?: string | undefined}; export type ApprovalNotifiedAboutReq = {emailDateTime?: TimestampReq | undefined, errorInfo?: string | undefined, url?: string | undefined}; export type AttributePermissionReq = {createdDtm?: TimestampReq | undefined, decision?: ('ALWAYS' | 'JUST_ONCE' | 'NEVER') | undefined, providerId?: string | undefined, providerType?: ('CREDENTIAL_PROVIDER' | 'SERVICE_PROVIDER') | undefined, requestedAttributeType?: ('ANONYMOUS' | 'EMAIL' | 'ID_TOKEN' | 'NAME' | 'PHOTO' | 'SYSTEM_ID') | undefined, updatedDtm?: TimestampReq | undefined}; export type CredentialTypePermissionReq = {createdDtm?: TimestampReq | undefined, credentialTypeHref?: string | undefined, decision?: ('ALWAYS' | 'JUST_ONCE' | 'NEVER') | undefined, providerId?: string | undefined, providerType?: ('CREDENTIAL_PROVIDER' | 'SERVICE_PROVIDER') | undefined, updatedDtm?: TimestampReq | undefined}; export type ServiceDetails = {connectTimeout?: number | undefined, contentType?: string | undefined, headers?: {[key: string]: string} | undefined, name?: string | undefined, proxyHost?: string | undefined, proxyPort?: number | undefined, readTimeout?: number | undefined, url?: string | undefined}; export type Tag = {id?: string | undefined, value?: string | undefined}; export type PersonInfoReq = {approvals?: Array | undefined, approvalsNotifiedAbout?: Array | undefined, attributePermissions?: Array | undefined, credentialTypePermissions?: Array | undefined, notificationEmailValidated?: boolean | undefined, registeredApiMap?: {[key: string]: Array} | undefined, tags?: Array | undefined}; export type LockInfoReq = {attemptsMade?: number | undefined, attemptsRemaining?: number | undefined, lockedUntil?: TimestampReq | undefined, subType?: string | undefined, type?: string | undefined}; export type AreasOfBusiness = {areas?: Array | undefined}; export type CredentialTypeOfInterest = {credentialTypeHrefRegEx?: string | undefined, eventTypes?: (Array<'FAILED_ISSUANCE' | 'SUCCESSFUL_ISSUANCE'>) | undefined}; export type ServiceProviderReq = {archivedDtm?: TimestampReq | undefined, areasOfBusiness?: AreasOfBusiness | undefined, createdDtm?: TimestampReq | undefined, credTypesOfInterest?: Array | undefined, description?: string | undefined, i18nInfo?: {[key: string]: {[key: string]: string}} | undefined, icon?: string | undefined, id?: string | undefined, lastUpdatedBy?: string | undefined, lastUpdatedDtm?: TimestampReq | undefined, name?: string | undefined, notificationEmail?: string | undefined, permittedOperations?: Array | undefined, status?: ('ACTIVE' | 'ARCHIVED' | 'BLOCKED' | 'PENDING') | undefined, visibility?: ('PRIVATE' | 'PUBLIC' | 'RESTRICTED') | undefined}; export type TimestampRes = {date?: number | undefined, day?: number | undefined, hours?: number | undefined, minutes?: number | undefined, month?: number | undefined, nanos?: number | undefined, seconds?: number | undefined, time?: number | undefined, timezoneOffset?: number | undefined, year?: number | undefined}; export type Approval = {createdDtm?: TimestampRes | undefined, id?: string | undefined, provider?: string | undefined, url?: string | undefined}; export type RegionReq = {approvals?: {[key: string]: Approval} | undefined, createdDtm?: TimestampReq | undefined, description?: string | undefined, id?: string | undefined, locales?: Array | undefined, name?: string | undefined, permittedOperations?: Array | undefined, status?: ('ACTIVE' | 'ARCHIVED' | 'PENDING') | undefined}; export type RegChallenge = {fidoRegRequest?: string | undefined, fidoRegResponse?: string | undefined, fidoResponseCode?: number | undefined, fidoResponseMessage?: string | undefined, id?: string | undefined, status?: ('ERROR' | 'FAILED' | 'PENDING' | 'SUCCESS') | undefined}; export type SessionInfo = {bearerToken?: string | undefined, invitationCode?: string | undefined, regChallenges?: Array | undefined}; export type IdTokenInfo = {audience?: string | undefined, issuer?: string | undefined, timeToLive?: number | undefined}; export type TenantReq = {archivedDtm?: TimestampReq | undefined, createdDtm?: TimestampReq | undefined, id?: string | undefined, idTokenInfo?: IdTokenInfo | undefined, lastUpdatedDtm?: TimestampReq | undefined, name?: string | undefined, notificationEmail?: string | undefined, permittedOperations?: Array | undefined, status?: ('ACTIVE' | 'ARCHIVED' | 'BLOCKED' | 'PENDING') | undefined}; export type PersonReq = {aliases?: {[key: string]: string} | undefined, archivedDtm?: TimestampReq | undefined, createdDtm?: TimestampReq | undefined, email?: string | undefined, expiringDtm?: string | undefined, extendedAttributes?: Record | undefined, firstName?: string | undefined, id?: string | undefined, idxId?: string | undefined, idxInstanceId?: string | undefined, idxTenant?: string | undefined, idxUserId?: string | undefined, info?: PersonInfoReq | undefined, initialFields?: PersonReq | undefined, lastName?: string | undefined, lastUpdatedDtm?: TimestampReq | undefined, lastUsedDtm?: TimestampReq | undefined, locks?: Array | undefined, permittedOperations?: Array | undefined, publicAliasesFor?: ServiceProviderReq | undefined, region?: RegionReq | undefined, sessionInfo?: SessionInfo | undefined, status?: ('ACTIVE' | 'ARCHIVED' | 'BLOCKED' | 'PENDING' | 'REREG_CONFIRMED') | undefined, tenant?: TenantReq | undefined}; export type CreateApiApiPersonsArgs = {body: PersonReq}; export type CreateApiApiPersonsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const timestampRes = z.object({date: z.number().int().optional(), day: z.number().int().optional(), hours: z.number().int().optional(), minutes: z.number().int().optional(), month: z.number().int().optional(), nanos: z.number().int().optional(), seconds: z.number().int().optional(), time: z.number().int().optional(), timezoneOffset: z.number().int().optional(), year: z.number().int().optional()}); export const approvalRes = z.object({createdDtm: timestampRes.optional(), id: z.string().optional(), provider: z.string().optional(), url: z.string().optional()}); export const approvalNotifiedAboutRes = z.object({emailDateTime: timestampRes.optional(), errorInfo: z.string().optional(), url: z.string().optional()}); export const attributePermissionRes = z.object({createdDtm: timestampRes.optional(), decision: z.enum(["ALWAYS", "JUST_ONCE", "NEVER"]).optional(), providerId: z.string().optional(), providerType: z.enum(["CREDENTIAL_PROVIDER", "SERVICE_PROVIDER"]).optional(), requestedAttributeType: z.enum(["ANONYMOUS", "EMAIL", "ID_TOKEN", "NAME", "PHOTO", "SYSTEM_ID"]).optional(), updatedDtm: timestampRes.optional()}); export const credentialTypePermissionRes = z.object({createdDtm: timestampRes.optional(), credentialTypeHref: z.string().optional(), decision: z.enum(["ALWAYS", "JUST_ONCE", "NEVER"]).optional(), providerId: z.string().optional(), providerType: z.enum(["CREDENTIAL_PROVIDER", "SERVICE_PROVIDER"]).optional(), updatedDtm: timestampRes.optional()}); export const serviceDetails = z.object({connectTimeout: z.number().int().optional(), contentType: z.string().optional(), headers: z.record(z.string(), z.string()).optional(), name: z.string().optional(), proxyHost: z.string().optional(), proxyPort: z.number().int().optional(), readTimeout: z.number().int().optional(), url: z.string().optional()}); export const tag = z.object({id: z.string().optional(), value: z.string().optional()}); export const personInfoRes = z.object({approvals: z.array(approvalRes).optional(), approvalsNotifiedAbout: z.array(approvalNotifiedAboutRes).optional(), attributePermissions: z.array(attributePermissionRes).optional(), credentialTypePermissions: z.array(credentialTypePermissionRes).optional(), notificationEmailValidated: z.boolean().optional(), registeredApiMap: z.record(z.string(), z.array(serviceDetails)).optional(), tags: z.array(tag).optional()}); export const lockInfoRes = z.object({attemptsMade: z.number().int().optional(), attemptsRemaining: z.number().int().optional(), lockedUntil: timestampRes.optional(), subType: z.string().optional(), type: z.string().optional()}); export const approval = z.object({createdDtm: timestampRes.optional(), id: z.string().optional(), provider: z.string().optional(), url: z.string().optional()}); export const regionRes = z.object({approvals: z.record(z.string(), approval).optional(), createdDtm: timestampRes.optional(), description: z.string().optional(), href: z.string().optional(), id: z.string().optional(), locales: z.array(z.string()).optional(), name: z.string().optional(), permittedOperations: z.array(z.string()).optional(), status: z.enum(["ACTIVE", "ARCHIVED", "PENDING"]).optional()}); export const regChallenge = z.object({fidoRegRequest: z.string().optional(), fidoRegResponse: z.string().optional(), fidoResponseCode: z.number().int().optional(), fidoResponseMessage: z.string().optional(), id: z.string().optional(), status: z.enum(["ERROR", "FAILED", "PENDING", "SUCCESS"]).optional()}); export const sessionInfo = z.object({bearerToken: z.string().optional(), invitationCode: z.string().optional(), regChallenges: z.array(regChallenge).optional()}); export const idTokenInfo = z.object({audience: z.string().optional(), issuer: z.string().optional(), timeToLive: z.number().int().optional()}); export const tenantRes = z.object({archivedDtm: timestampRes.optional(), createdDtm: timestampRes.optional(), href: z.string().optional(), id: z.string().optional(), idTokenInfo: idTokenInfo.optional(), lastUpdatedDtm: timestampRes.optional(), name: z.string().optional(), notificationEmail: z.string().optional(), permittedOperations: z.array(z.string()).optional(), status: z.enum(["ACTIVE", "ARCHIVED", "BLOCKED", "PENDING"]).optional()}); export const personRes = z.object({aliases: z.record(z.string(), z.string()).optional(), archivedDtm: timestampRes.optional(), createdDtm: timestampRes.optional(), email: z.string().optional(), expiringDtm: z.string().optional(), extendedAttributes: z.object({}).optional(), firstName: z.string().optional(), href: z.string().optional(), id: z.string().optional(), idxId: z.string().optional(), idxInstanceId: z.string().optional(), idxTenant: z.string().optional(), idxUserId: z.string().optional(), info: personInfoRes.optional(), lastName: z.string().optional(), lastUpdatedDtm: timestampRes.optional(), lastUsedDtm: timestampRes.optional(), locks: z.array(lockInfoRes).optional(), permittedOperations: z.array(z.string()).optional(), region: regionRes.optional(), sessionInfo: sessionInfo.optional(), status: z.enum(["ACTIVE", "ARCHIVED", "BLOCKED", "PENDING", "REREG_CONFIRMED"]).optional(), tenant: tenantRes.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 }; /** * Add a person * * POST /api/persons */ export const createApiApiPersons = async (args: CreateApiApiPersonsArgs, options: CreateApiApiPersonsOptions) => { 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(/\/+$/, '')}/api/persons${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(personRes, await res.json()) };