import { BaseClient } from "../client/baseClient"; import { AuthChallengeResponse, AuthTokenRedeemResponse, InitTokenAuthenticationRequest, RefreshTokenResponse, } from "../types/auth"; import { AuthenticationInitResponse, AuthenticationOperationStatusResponse } from "../types/common"; import { normalizeAuthenticationOperationStatusResponse } from "../utils/authenticationMethodInfo"; export class AuthClient extends BaseClient { async getChallenge(): Promise { return this.http.request({ method: "POST", path: "/auth/challenge", }); } async authenticateWithKsefToken( request: InitTokenAuthenticationRequest, ): Promise { return this.http.request({ method: "POST", path: "/auth/ksef-token", body: request, }); } async authenticateWithXadesSignature( signedXml: string, verifyCertificateChain?: boolean, enforceXadesCompliance?: boolean, ): Promise { return this.http.request({ method: "POST", path: "/auth/xades-signature", ...(verifyCertificateChain !== undefined && { query: { verifyCertificateChain }, }), body: signedXml, headers: { "Content-Type": "application/xml", Accept: "application/json", ...(enforceXadesCompliance && { "X-KSeF-Feature": "enforce-xades-compliance", }), }, }); } async getAuthStatus( referenceNumber: string, authenticationToken: string, ): Promise { const response = await this.http.request({ method: "GET", path: `/auth/${encodeURIComponent(referenceNumber)}`, authToken: authenticationToken, }); return normalizeAuthenticationOperationStatusResponse(response); } async redeemToken(authenticationToken: string): Promise { return this.http.request({ method: "POST", path: "/auth/token/redeem", authToken: authenticationToken, }); } async refreshAccessToken(refreshToken: string): Promise { return this.http.request({ method: "POST", path: "/auth/token/refresh", authToken: refreshToken, }); } }