The login flow was near-silent: three info lines with no way to see why a session was considered expired or what happened to the cookies. Debugging a failing login meant guessing. Every login step now logs on debug level with a `phase` field: the login page fetch, the extracted nonce, the POST to /login/api/login.php, the session check, and any request retried after a re-login. Each of those requests is bracketed by a cookie snapshot taken before it is sent and one taken after, plus a delta of added/changed/removed cookies. The "before" snapshot is logged prior to sending, so it survives a hanging request. isLoginRequiredResponse() is split so the criterion that matched (status-401, login-markup, ...) can be reported instead of just a boolean. Secrets stay out of the log: the password is replaced by ***, and cookie values - including those in the raw Set-Cookie header - are truncated to their first four characters plus length. That still shows whether a session id changed without putting the session itself in the log. Detail logging is strictly debug-level via logLoginDetail(); the existing logDebug() falls back to info, which would flood a plain info logger. When no debug logger is attached, no snapshot is taken and nothing is serialized. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
115 lines
5.1 KiB
TypeScript
115 lines
5.1 KiB
TypeScript
import { type AxiosInstance } from 'axios';
|
|
import type { AgrarmonitorApiCustomer, AgrarmonitorConnectorOptions, AgrarmonitorConnectorResult, AgrarmonitorDeviceRegistrationOptions, AgrarmonitorDeviceRegistrationResult, AgrarmonitorFetchCustomersOptions, AgrarmonitorFreischaltungStatus, AgrarmonitorKunde2, AgrarmonitorRegistrierungStatus, Artikel, ArtikelEinheit, ArtikelKategorie, EingangsrechnungLivesearchResult, Firma, Maschine, MaschinenKategorie, Mitarbeiter, Rechnungsdaten } from './types';
|
|
export declare class AgrarmonitorConnector implements AgrarmonitorConnectorResult {
|
|
private readonly options;
|
|
http: AxiosInstance;
|
|
private static readonly s3DateienBaseUrl;
|
|
private readonly baseUrl;
|
|
private readonly apiBaseUrl;
|
|
private readonly timeoutMs;
|
|
private readonly autoLogin;
|
|
private readonly autoRetry;
|
|
private readonly loginStrategy;
|
|
private readonly logger?;
|
|
private cookieJar;
|
|
private apiHttp;
|
|
private loginInProgress;
|
|
constructor(options: AgrarmonitorConnectorOptions);
|
|
init(): Promise<this>;
|
|
login(): Promise<void>;
|
|
clearSession(): Promise<void>;
|
|
saveSession(): Promise<void>;
|
|
getCookieCount(url?: string): Promise<number>;
|
|
checkFreigeschaltet(): Promise<AgrarmonitorFreischaltungStatus>;
|
|
checkRegistriert(): Promise<AgrarmonitorRegistrierungStatus>;
|
|
registerDevice(registration: AgrarmonitorDeviceRegistrationOptions): Promise<AgrarmonitorDeviceRegistrationResult>;
|
|
fetchCustomers(options?: AgrarmonitorFetchCustomersOptions): Promise<AgrarmonitorApiCustomer[]>;
|
|
getKunden2(options?: AgrarmonitorFetchCustomersOptions): Promise<AgrarmonitorKunde2[]>;
|
|
eingangsrechnungenLivesearch(suchstring: string): Promise<EingangsrechnungLivesearchResult[]>;
|
|
eingangsrechnungVorhanden(suchstring: string): Promise<boolean>;
|
|
eingangsrechnungImDateieingangVorhanden(suchstring: string): Promise<boolean>;
|
|
getRechnungsdaten(rechnungId: number): Promise<Rechnungsdaten>;
|
|
setRechnungsdaten(rechnungId: number, daten: Rechnungsdaten): Promise<boolean>;
|
|
setLieferscheinNummer(rechnungId: number, nummer: string): Promise<void>;
|
|
setEingangsdatum(rechnungId: number, datum: Date): Promise<boolean>;
|
|
getCustomerById(id: number): Promise<AgrarmonitorApiCustomer>;
|
|
getMaschinenKategorien(): Promise<MaschinenKategorie[]>;
|
|
getMaschinen(gruppenId: number, suchstring?: string): Promise<Maschine[]>;
|
|
getFirmen(): Promise<Firma[]>;
|
|
getArtikelEinheiten(): Promise<ArtikelEinheit[]>;
|
|
getArtikelKategorien(): Promise<ArtikelKategorie[]>;
|
|
getArtikel(artikelGruppe: number, suchstring?: string): Promise<Artikel[]>;
|
|
getMitarbeiter(suchstring?: string, mitarbeitergruppe?: number): Promise<Mitarbeiter[]>;
|
|
private createHttpClient;
|
|
private createApiHttpClient;
|
|
private apiRequest;
|
|
private fetchAllCustomers;
|
|
private mapKunde2;
|
|
private performLogin;
|
|
private performRedirectLogin;
|
|
private isSessionValid;
|
|
private loginRequestConfig;
|
|
private isLoginRequiredResponse;
|
|
/**
|
|
* Liefert das Kriterium, an dem eine abgelaufene Session erkannt wurde,
|
|
* oder null fuer eine gueltige Session.
|
|
*/
|
|
private loginRequiredReason;
|
|
private retryAfterLogin;
|
|
private createDateienLivesearchParams;
|
|
private getEingangsrechnungEditMeta;
|
|
private getEingangsrechnungDetailMeta;
|
|
private formPostConfig;
|
|
private parseHtmlDocument;
|
|
private hasTableRows;
|
|
private inputValue;
|
|
private selectedNumberValue;
|
|
private parseNumber;
|
|
private parsePositiveNumber;
|
|
private toStringValue;
|
|
private toBoolean;
|
|
private parseJaNein;
|
|
private parseGermanShortDate;
|
|
private requireDate;
|
|
private formatGermanShortDate;
|
|
private lastPathSegment;
|
|
private fileBasename;
|
|
private normalizeApiBaseUrl;
|
|
private isWrappedApiCustomer;
|
|
private isApiCustomer;
|
|
private parseGermanShortDateFromText;
|
|
private logDebug;
|
|
private getResponseUrl;
|
|
private getHeader;
|
|
private isFreischaltungUrl;
|
|
private isLoginPageText;
|
|
private extractNonce;
|
|
private maskNonce;
|
|
private get debugLogging();
|
|
/**
|
|
* Detail-Logging des Login-Flows. Anders als logDebug faellt das bewusst
|
|
* NICHT auf info zurueck - ohne debug-Logger bleiben die Details still.
|
|
*/
|
|
private logLoginDetail;
|
|
private maskValue;
|
|
/**
|
|
* Liest die Cookies des Jars fuer eine URL aus. Liefert eine leere Liste,
|
|
* solange kein debug-Logger haengt - dann wird gar nicht erst serialisiert.
|
|
*/
|
|
private snapshotCookies;
|
|
/**
|
|
* Maskiert die Werte im rohen Set-Cookie-Header - sonst stuende die neue
|
|
* Session-ID im Klartext im Log, obwohl der Jar-Snapshot sie maskiert.
|
|
*/
|
|
private formatSetCookieHeader;
|
|
/** Wie snapshotCookies, aber mit maskierten Werten - nur das geht ins Log. */
|
|
private formatCookies;
|
|
private diffCookies;
|
|
/**
|
|
* Klammert einen Request mit je einem Cookie-Snapshot davor und danach.
|
|
* Der Snapshot davor wird vor dem Absenden geloggt, damit er auch dann
|
|
* im Log steht, wenn der Request haengt oder wirft.
|
|
*/
|
|
private loggedRequest;
|
|
}
|
|
//# sourceMappingURL=AgrarmonitorConnector.d.ts.map
|