import {z} from 'zod' export type GetApiAccountAccessConsentsConsentIdArgs = {ConsentId: string, 'x-fapi-financial-id': string, 'x-fapi-customer-last-logged-time'?: string | undefined, 'x-fapi-customer-ip-address'?: string | undefined, 'x-fapi-interaction-id'?: string | undefined, Authorization?: string | undefined, 'x-customer-user-agent'?: string | undefined}; export type GetApiAccountAccessConsentsConsentIdOptions = {baseUrl?: string | undefined, TPPOAuth2Security?: string | undefined, fetch?: typeof fetch | undefined}; export const oBExternalRequestStatus1Code = z.enum(["Authorised", "AwaitingAuthorisation", "Rejected", "Revoked"]); export const oBExternalPermissions1Code = z.enum(["ReadAccountsBasic", "ReadAccountsDetail", "ReadBalances", "ReadBeneficiariesBasic", "ReadBeneficiariesDetail", "ReadDirectDebits", "ReadOffers", "ReadPAN", "ReadParty", "ReadPartyPSU", "ReadProducts", "ReadScheduledPaymentsBasic", "ReadScheduledPaymentsDetail", "ReadStandingOrdersBasic", "ReadStandingOrdersDetail", "ReadStatementsBasic", "ReadStatementsDetail", "ReadTransactionsBasic", "ReadTransactionsCredits", "ReadTransactionsDebits", "ReadTransactionsDetail"]); export const oBRisk2 = z.object({}); export const links = z.object({Self: z.string(), First: z.string().optional(), Prev: z.string().optional(), Next: z.string().optional(), Last: z.string().optional()}); export const iSODateTime = z.string(); export const meta = z.object({TotalPages: z.number().int().optional(), FirstAvailableDateTime: iSODateTime.optional(), LastAvailableDateTime: iSODateTime.optional()}); export const oBReadConsentResponse1 = z.object({Data: z.object({ConsentId: z.string().min(1).max(128), CreationDateTime: z.string(), Status: oBExternalRequestStatus1Code, StatusUpdateDateTime: z.string(), Permissions: z.array(oBExternalPermissions1Code), ExpirationDateTime: z.string().optional(), TransactionFromDateTime: z.string().optional(), TransactionToDateTime: z.string().optional()}), Risk: oBRisk2, Links: links, Meta: meta}); 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 }; /** * Get Account Access Consents * * GET /account-access-consents/{ConsentId} */ export const getApiAccountAccessConsentsConsentId = async (args: GetApiAccountAccessConsentsConsentIdArgs, options?: GetApiAccountAccessConsentsConsentIdOptions) => { const {baseUrl = "https://secure.tell.systems/algbra/open-banking/v3.1/aisp", fetch: fetchFn = fetch, TPPOAuth2Security} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json; charset=utf-8") if (args['x-fapi-financial-id'] != null) headers.set("x-fapi-financial-id", String(args['x-fapi-financial-id'])) if (args['x-fapi-customer-last-logged-time'] != null) headers.set("x-fapi-customer-last-logged-time", String(args['x-fapi-customer-last-logged-time'])) if (args['x-fapi-customer-ip-address'] != null) headers.set("x-fapi-customer-ip-address", String(args['x-fapi-customer-ip-address'])) if (args['x-fapi-interaction-id'] != null) headers.set("x-fapi-interaction-id", String(args['x-fapi-interaction-id'])) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args['x-customer-user-agent'] != null) headers.set("x-customer-user-agent", String(args['x-customer-user-agent'])) if (TPPOAuth2Security !== undefined) headers.set('authorization', `Bearer ${TPPOAuth2Security}`) const url = `${baseUrl.replace(/\/+$/, '')}/account-access-consents/${encodeURIComponent(String(args.ConsentId))}${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(oBReadConsentResponse1, await res.json()) };