import {z} from 'zod' export type BasketId = string; export type GetApiV1SigningBasketsBasketIdArgs = {basketId: BasketId, 'X-Request-ID': string, Digest?: string | undefined, Signature?: string | undefined, 'TPP-Signature-Certificate'?: 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}; export type GetApiV1SigningBasketsBasketIdOptions = {baseUrl?: string | undefined, BearerAuthOAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const paymentId = z.string(); export const paymentIdList = z.array(paymentId); export const consentId = z.string(); export const consentIdList = z.array(consentId); export const transactionStatusSBS = z.enum(["ACSC", "ACTC", "PATC", "RCVD", "RJCT", "CANC"]); export const hrefEntry = z.string(); export const hrefType = z.object({href: hrefEntry.optional()}); export const linksSigningBasket = z.object({scaRedirect: hrefType.optional(), scaOAuth: hrefType.optional(), startAuthorisation: hrefType.optional(), startAuthorisationWithPsuIdentification: hrefType.optional(), startAuthorisationWithPsuAuthentication: hrefType.optional(), startAuthorisationWithEncryptedPsuAuthentication: hrefType.optional(), startAuthorisationWithAuthenticationMethodSelection: hrefType.optional(), startAuthorisationWithTransactionAuthorisation: hrefType.optional(), self: hrefType.optional(), status: hrefType.optional(), scaStatus: hrefType.optional()}); export const signingBasketResponse200 = z.object({payments: paymentIdList.optional(), consents: consentIdList.optional(), transactionStatus: transactionStatusSBS, _links: linksSigningBasket.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 }; /** * Returns the content of an signing basket object * * GET /v1/signing-baskets/{basketId} */ export const getApiV1SigningBasketsBasketId = async (args: GetApiV1SigningBasketsBasketIdArgs, options?: GetApiV1SigningBasketsBasketIdOptions) => { const {baseUrl = "https://api.dev.openbankingproject.ch", fetch: fetchFn = fetch, BearerAuthOAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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-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/signing-baskets/${encodeURIComponent(String(args.basketId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(signingBasketResponse200, await res.json()) };