import {z} from 'zod' export type AccessPolicy = {accessPattern?: ('NUMBER_LIMITED' | 'READ_CONFIRM' | 'TIME_LIMITED' | 'UNRESTRICTED') | undefined, count?: number | undefined, numberLimit?: number | undefined}; 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 CPAssociationRequest = {visibility?: ('PRIVATE' | 'PUBLIC' | 'RESTRICTED') | undefined}; export type AssociationRequest = {aliases?: {[key: string]: string} | undefined, termsAndConditionsUrl?: string | undefined}; export type Invitation = {associationRequest?: AssociationRequest | undefined, serviceUrls?: Array | undefined}; export type PersonCredentialIssuanceNotification = {credentialTypeExtendedName?: string | undefined, credentialTypeHref?: string | undefined, personEmail?: string | undefined, personHref?: string | undefined, result?: ('FAILED_ISSUANCE' | 'SUCCESSFUL_ISSUANCE') | undefined}; export type ChannelSendError = {channel?: ('EMAIL' | 'PUSH_NOTIFICATION' | 'SMS') | undefined, code?: number | undefined}; export type PersonInfoNotification = {params?: {[key: string]: string} | undefined, requestedChannels?: (Array<'EMAIL' | 'PUSH_NOTIFICATION' | 'SMS'>) | undefined, sendErrors?: Array | undefined, type?: string | undefined}; export type MessageInfo = {cpAssociationRequest?: CPAssociationRequest | undefined, credentials?: Array | undefined, invitation?: Invitation | undefined, personCredentialIssuanceNotification?: PersonCredentialIssuanceNotification | undefined, personInfoNotification?: PersonInfoNotification | undefined}; export type SourceInfo = Record; export type MessageReq = {accessPolicy?: AccessPolicy | undefined, availableToDestination?: boolean | undefined, code?: string | undefined, createdDtm?: TimestampReq | undefined, destId?: string | undefined, destName?: string | undefined, destType?: ('CREDENTIAL_PROVIDER' | 'PERSON' | 'SERVICE_PROVIDER' | 'SYSTEM') | undefined, emailDetails?: Record | undefined, emailTo?: string | undefined, expiringDtm?: TimestampReq | undefined, footer?: string | undefined, id?: string | undefined, info?: MessageInfo | undefined, lastUpdatedDtm?: TimestampReq | undefined, notBeforeDtm?: TimestampReq | undefined, note?: string | undefined, permittedOperations?: Array | undefined, previousMessageId?: string | undefined, readCount?: number | undefined, secureContent?: string | undefined, sourceId?: string | undefined, sourceInfo?: SourceInfo | undefined, sourceName?: string | undefined, sourceType?: ('CREDENTIAL_PROVIDER' | 'PERSON' | 'SERVICE_PROVIDER' | 'SYSTEM') | undefined, status?: ('ACTIVE' | 'ASSOC_REQ_ACCEPTED' | 'ASSOC_REQ_DECLINED' | 'DELETED' | 'EXPIRED' | 'INVITE_ACCEPTED' | 'INVITE_DECLINED' | 'NOT_SENT' | 'PENDING') | undefined, subject?: string | undefined, type?: ('ASSOCIATION_REQUEST' | 'CREDENTIAL' | 'INVITATION' | 'NOTICE' | 'PERSON_NOTIFICATION') | undefined}; export type CreateApiApiCredentialProvidersCredentialProviderIdAssociationRequestArgs = {credentialProviderId: string, body: MessageReq}; export type CreateApiApiCredentialProvidersCredentialProviderIdAssociationRequestOptions = {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 }; /** * Create an association code for a credential provider. * * POST /api/credentialProviders/{credentialProviderId}/associationRequest */ export const createApiApiCredentialProvidersCredentialProviderIdAssociationRequest = async (args: CreateApiApiCredentialProvidersCredentialProviderIdAssociationRequestArgs, options: CreateApiApiCredentialProvidersCredentialProviderIdAssociationRequestOptions) => { 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/credentialProviders/${encodeURIComponent(String(args.credentialProviderId))}/associationRequest${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()) };