import {z} from 'zod' export type ConsentId = string; export type AuthorisationId = string; export type PsuData = {password?: string | undefined, encryptedPassword?: string | undefined, additionalPassword?: string | undefined, additionalEncryptedPassword?: string | undefined}; export type UpdatePsuAuthentication = {psuData: PsuData}; export type AuthenticationMethodId = string; export type SelectPsuAuthenticationMethod = {authenticationMethodId: AuthenticationMethodId}; export type ScaAuthenticationData = string; export type TransactionAuthorisation = {scaAuthenticationData: ScaAuthenticationData}; export type AuthorisationConfirmation = {confirmationCode: string}; export type UpdateApiV1ConsentsConsentIdAuthorisationsAuthorisationIdArgs = {consentId: ConsentId, authorisationId: AuthorisationId, 'X-Request-ID': string, Digest?: string | undefined, Signature?: string | undefined, 'TPP-Signature-Certificate'?: string | undefined, 'PSU-ID'?: string | undefined, 'PSU-ID-Type'?: string | undefined, 'PSU-Corporate-ID'?: string | undefined, 'PSU-Corporate-ID-Type'?: string | undefined, 'PSU-IP-Address'?: string | undefined, 'PSU-IP-Port'?: string | undefined, 'PSU-Accept'?: string | undefined, 'PSU-Accept-Charset'?: string | undefined, 'PSU-Accept-Encoding'?: string | undefined, 'PSU-Accept-Language'?: string | undefined, 'PSU-User-Agent'?: string | undefined, 'PSU-Http-Method'?: ('GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE') | undefined, 'PSU-Device-ID'?: string | undefined, 'PSU-Geo-Location'?: string | undefined, body: unknown | UpdatePsuAuthentication | SelectPsuAuthenticationMethod | TransactionAuthorisation | AuthorisationConfirmation}; export type UpdateApiV1ConsentsConsentIdAuthorisationsAuthorisationIdOptions = {baseUrl?: string | undefined, BearerAuthOAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const currencyCode = z.string(); export const amountValue = z.string(); export const amount = z.object({currency: currencyCode, amount: amountValue}); export const authenticationType = z.enum(["SMS_OTP", "CHIP_OTP", "PHOTO_OTP", "PUSH_OTP", "SMTP_OTP"]); export const authenticationMethodId = z.string().max(35); export const authenticationObject = z.object({authenticationType: authenticationType, authenticationVersion: z.string().optional(), authenticationMethodId: authenticationMethodId, name: z.string().optional(), explanation: z.string().optional()}); export const scaMethods = z.array(authenticationObject); export const hrefEntry = z.string(); export const hrefType = z.object({href: hrefEntry.optional()}); export const linksUpdatePsuIdentification = z.object({scaStatus: hrefType.optional(), selectAuthenticationMethod: hrefType.optional()}).and(z.record(z.string(), hrefType)); export const scaStatus = z.enum(["received", "psuIdentified", "psuAuthenticated", "scaMethodSelected", "started", "unconfirmed", "finalised", "failed", "exempted"]); export const psuMessageText = z.string().max(500); export const updatePsuIdenticationResponse = z.object({transactionFees: amount.optional(), currencyConversionFees: amount.optional(), estimatedTotalAmount: amount.optional(), estimatedInterbankSettlementAmount: amount.optional(), scaMethods: scaMethods.optional(), _links: linksUpdatePsuIdentification, scaStatus: scaStatus, psuMessage: psuMessageText.optional()}); export const chosenScaMethod = z.object({authenticationType: authenticationType, authenticationVersion: z.string().optional(), authenticationMethodId: authenticationMethodId, name: z.string().optional(), explanation: z.string().optional()}); export const challengeData = z.object({image: z.string().optional(), data: z.array(z.string()).optional(), imageLink: z.string().optional(), otpMaxLength: z.number().int().optional(), otpFormat: z.enum(["characters", "integer"]).optional(), additionalInformation: z.string().optional()}); export const linksUpdatePsuAuthentication = z.object({updateAdditionalPsuAuthentication: hrefType.optional(), updateAdditionalEncryptedPsuAuthentication: hrefType.optional(), selectAuthenticationMethod: hrefType.optional(), authoriseTransaction: hrefType.optional(), scaStatus: hrefType.optional()}).and(z.record(z.string(), hrefType)); export const authorisationId = z.string(); export const updatePsuAuthenticationResponse = z.object({transactionFees: amount.optional(), currencyConversionFees: amount.optional(), estimatedTotalAmount: amount.optional(), estimatedInterbankSettlementAmount: amount.optional(), chosenScaMethod: chosenScaMethod.optional(), challengeData: challengeData.optional(), scaMethods: scaMethods.optional(), _links: linksUpdatePsuAuthentication.optional(), scaStatus: scaStatus, psuMessage: psuMessageText.optional(), authorisationId: authorisationId.optional()}); export const linksSelectPsuAuthenticationMethod = z.object({scaRedirect: hrefType.optional(), scaOAuth: hrefType.optional(), confirmation: hrefType.optional(), updatePsuIdentification: hrefType.optional(), updatePsuAuthentication: hrefType.optional(), updateAdditionalPsuAuthentication: hrefType.optional(), updateAdditionalEncryptedPsuAuthentication: hrefType.optional(), authoriseTransaction: hrefType.optional(), scaStatus: hrefType.optional()}).and(z.record(z.string(), hrefType)); export const selectPsuAuthenticationMethodResponse = z.object({transactionFees: amount.optional(), currencyConversionFees: amount.optional(), estimatedTotalAmount: amount.optional(), estimatedInterbankSettlementAmount: amount.optional(), chosenScaMethod: chosenScaMethod.optional(), challengeData: challengeData.optional(), _links: linksSelectPsuAuthenticationMethod.optional(), scaStatus: scaStatus, psuMessage: psuMessageText.optional()}); export const trustedBeneficiaryFlag = z.boolean(); export const scaStatusResponse = z.object({scaStatus: scaStatus, psuMessage: psuMessageText.optional(), trustedBeneficiaryFlag: trustedBeneficiaryFlag.optional()}); export const scaStatusAuthorisationConfirmation = z.enum(["finalised", "failed"]); export const linksAuthorisationConfirmation = z.object({scaStatus: hrefType.optional()}).and(z.record(z.string(), hrefType)); export const authorisationConfirmationResponse = z.object({scaStatus: scaStatusAuthorisationConfirmation, _links: linksAuthorisationConfirmation, psuMessage: psuMessageText.optional()}); export const updateApiV1ConsentsConsentIdAuthorisationsAuthorisationIdResponse = z.union([updatePsuIdenticationResponse, updatePsuAuthenticationResponse, selectPsuAuthenticationMethodResponse, scaStatusResponse, authorisationConfirmationResponse]); 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 PSU Data for consents * * PUT /v1/consents/{consentId}/authorisations/{authorisationId} */ export const updateApiV1ConsentsConsentIdAuthorisationsAuthorisationId = async (args: UpdateApiV1ConsentsConsentIdAuthorisationsAuthorisationIdArgs, options?: UpdateApiV1ConsentsConsentIdAuthorisationsAuthorisationIdOptions) => { const {baseUrl = "https://api.dev.openbankingproject.ch", fetch: fetchFn = fetch, BearerAuthOAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-Request-ID'] != null) headers.set("X-Request-ID", String(args['X-Request-ID'])) if (args.Digest != null) headers.set("Digest", String(args.Digest)) if (args.Signature != null) headers.set("Signature", String(args.Signature)) if (args['TPP-Signature-Certificate'] != null) headers.set("TPP-Signature-Certificate", String(args['TPP-Signature-Certificate'])) if (args['PSU-ID'] != null) headers.set("PSU-ID", String(args['PSU-ID'])) if (args['PSU-ID-Type'] != null) headers.set("PSU-ID-Type", String(args['PSU-ID-Type'])) if (args['PSU-Corporate-ID'] != null) headers.set("PSU-Corporate-ID", String(args['PSU-Corporate-ID'])) if (args['PSU-Corporate-ID-Type'] != null) headers.set("PSU-Corporate-ID-Type", String(args['PSU-Corporate-ID-Type'])) if (args['PSU-IP-Address'] != null) headers.set("PSU-IP-Address", String(args['PSU-IP-Address'])) if (args['PSU-IP-Port'] != null) headers.set("PSU-IP-Port", String(args['PSU-IP-Port'])) if (args['PSU-Accept'] != null) headers.set("PSU-Accept", String(args['PSU-Accept'])) if (args['PSU-Accept-Charset'] != null) headers.set("PSU-Accept-Charset", String(args['PSU-Accept-Charset'])) if (args['PSU-Accept-Encoding'] != null) headers.set("PSU-Accept-Encoding", String(args['PSU-Accept-Encoding'])) if (args['PSU-Accept-Language'] != null) headers.set("PSU-Accept-Language", String(args['PSU-Accept-Language'])) if (args['PSU-User-Agent'] != null) headers.set("PSU-User-Agent", String(args['PSU-User-Agent'])) if (args['PSU-Http-Method'] != null) headers.set("PSU-Http-Method", String(args['PSU-Http-Method'])) if (args['PSU-Device-ID'] != null) headers.set("PSU-Device-ID", String(args['PSU-Device-ID'])) if (args['PSU-Geo-Location'] != null) headers.set("PSU-Geo-Location", String(args['PSU-Geo-Location'])) if (BearerAuthOAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuthOAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/consents/${encodeURIComponent(String(args.consentId))}/authorisations/${encodeURIComponent(String(args.authorisationId))}${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(updateApiV1ConsentsConsentIdAuthorisationsAuthorisationIdResponse, await res.json()) };