import {z} from 'zod' export type PersonNotification = {channels?: (Array<'EMAIL' | 'PUSH_NOTIFICATION' | 'SMS'>) | undefined, emailFooter?: string | undefined, emailSubject?: string | undefined, note?: string | undefined, params?: {[key: string]: string} | undefined, secureContent?: string | undefined, sourceId?: string | undefined, sourceName?: string | undefined, type?: string | undefined}; export type CreateApiApiPersonsPersonIdNotifyArgs = {'accept-language'?: string | undefined, personId: string, body: PersonNotification}; export type CreateApiApiPersonsPersonIdNotifyOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const accessPolicyMessageSourceWithCodeView = z.object({}); export const timestampMessageSourceWithCodeView = z.object({}); export const messageInfoMessageSourceWithCodeView = z.object({}); export const sourceInfoMessageSourceWithCodeView = z.object({}); export const messageMessageSourceWithCodeView = z.object({accessPolicy: accessPolicyMessageSourceWithCodeView.optional(), availableToDestination: z.boolean().optional(), code: z.string().optional(), createdDtm: timestampMessageSourceWithCodeView.optional(), destId: z.string().optional(), destName: z.string().optional(), destType: z.enum(["CREDENTIAL_PROVIDER", "PERSON", "SERVICE_PROVIDER", "SYSTEM"]).optional(), emailTo: z.string().optional(), expiringDtm: timestampMessageSourceWithCodeView.optional(), footer: z.string().optional(), id: z.string().optional(), info: messageInfoMessageSourceWithCodeView.optional(), lastUpdatedDtm: timestampMessageSourceWithCodeView.optional(), notBeforeDtm: timestampMessageSourceWithCodeView.optional(), note: z.string().optional(), previousMessageId: z.string().optional(), readCount: z.number().int().optional(), secureContent: z.string().optional(), sourceId: z.string().optional(), sourceInfo: sourceInfoMessageSourceWithCodeView.optional(), sourceName: z.string().optional(), sourceType: z.enum(["CREDENTIAL_PROVIDER", "PERSON", "SERVICE_PROVIDER", "SYSTEM"]).optional(), status: z.enum(["ACTIVE", "ASSOC_REQ_ACCEPTED", "ASSOC_REQ_DECLINED", "DELETED", "EXPIRED", "INVITE_ACCEPTED", "INVITE_DECLINED", "NOT_SENT", "PENDING"]).optional(), subject: z.string().optional(), type: z.enum(["ASSOCIATION_REQUEST", "CREDENTIAL", "INVITATION", "NOTICE", "PERSON_NOTIFICATION"]).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 }; /** * Send a notification of an event to a person * * POST /api/persons/{personId}/notify */ export const createApiApiPersonsPersonIdNotify = async (args: CreateApiApiPersonsPersonIdNotifyArgs, options: CreateApiApiPersonsPersonIdNotifyOptions) => { 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") if (args['accept-language'] != null) headers.set("accept-language", String(args['accept-language'])) const url = `${baseUrl.replace(/\/+$/, '')}/api/persons/${encodeURIComponent(String(args.personId))}/notify${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(messageMessageSourceWithCodeView, await res.json()) };