import {z} from 'zod' export type GetApiV0OpenBankingTellConsentsConsentIdArgs = {'consent-id': string}; export type GetApiV0OpenBankingTellConsentsConsentIdOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV0OpenBankingTellConsentsConsentIdResponse = z.object({"tell-consent-expiry": z.string().optional(), "tell-gateway-id": z.string(), "created-at": z.string(), "tell-consent-id": z.string(), "tell-consent-scope": z.union([z.enum(["payments", "accounts"]), z.string()]), "tell-consent-consumed-at": z.string().optional(), "tell-consent-url": z.union([z.string(), z.string()]), "tell-consent-status": z.union([z.enum(["revoked", "consumed", "authorised"]), z.string()]), "tell-consent-permissions": z.array(z.union([z.enum(["ReadPartyPSU", "ReadTransactionsDetail", "ReadProducts", "ReadStatementsDetail", "ReadDirectDebits", "ReadTransactionsDebits", "ReadTransactionsCredits", "ReadBeneficiariesDetail", "ReadBalances", "ReadPAN", "ReadScheduledPaymentsDetail", "ReadAccountsDetail", "ReadAccountsBasic", "ReadOffers", "ReadBeneficiariesBasic", "ReadStandingOrdersBasic", "ReadStandingOrdersDetail", "ReadTransactionsBasic", "ReadParty", "ReadStatementsBasic", "ReadScheduledPaymentsBasic"]), z.string()])), "bank-account-urls": z.array(z.union([z.string(), z.string()])), "tell-consent-revoked-at": z.string().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 }; /** * Get Tell consent * * GET /v0/open-banking/tell-consents/{consent-id} */ export const getApiV0OpenBankingTellConsentsConsentId = async (args: GetApiV0OpenBankingTellConsentsConsentIdArgs, options?: GetApiV0OpenBankingTellConsentsConsentIdOptions) => { const {baseUrl = "https://api.griffin.com", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set("Authorization", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v0/open-banking/tell-consents/${encodeURIComponent(String(args['consent-id']))}${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(getApiV0OpenBankingTellConsentsConsentIdResponse, await res.json()) };