b47cbc00a8a96be6aa64d08e783de5faab4fdb47
Agrarmonitor Connector
TypeScript MVP connector for Agrarmonitor with shared cookie persistence, optional AES-GCM cookie encryption, automatic login, retry after expired sessions, device registration checks, and customer detail extraction.
Installation
npm install
Build
npm run build
Example
import {
AesGcmCookieEncryptor,
FileCookieStore,
createAgrarmonitorClient,
} from 'agrarmonitor-connector';
const agrarmonitor = await createAgrarmonitorClient({
baseUrl: 'https://admin7.agrarmonitor.de',
apiToken: process.env.AGRARMONITOR_API_TOKEN,
username: process.env.AGRARMONITOR_USERNAME ?? '',
password: process.env.AGRARMONITOR_PASSWORD ?? '',
cookieStore: new FileCookieStore(
process.env.AGRARMONITOR_COOKIE_PATH ?? './data/agrarmonitor-cookies.json',
{
encryptor: process.env.AGRARMONITOR_ENCRYPTION_KEY
? new AesGcmCookieEncryptor(process.env.AGRARMONITOR_ENCRYPTION_KEY)
: undefined,
logger: console,
}
),
logger: console,
});
const freischaltung = await agrarmonitor.checkFreigeschaltet();
console.log(freischaltung.freigeschaltet);
const registrierung = await agrarmonitor.checkRegistriert();
console.log(registrierung.registriert);
const response = await agrarmonitor.http.get('/kunden/detail/123');
console.log(response.status);
Cookie Persistence
FileCookieStore keeps one shared CookieJar per file path inside the Node process. Multiple connector instances that use the same cookie file therefore reuse the same session and every successful request saves the latest cookies back to disk.
The store can read both the connector format and the older Telefonbuch cookie-array format.
Useful Methods
checkFreigeschaltet()checks whether Agrarmonitor redirects to/freischaltung/.checkRegistriert()checks whether the page still containsNeues Gerät registrieren.registerDevice({ agrarmonitorId, pcName })loads/freischaltung/, extracts the nonce, and posts the registration request.fetchCustomers()loads customers fromhttps://api.agrarmonitor.de/v1/kunden.saveSession()explicitly persists the current cookie jar.
Description
Languages
TypeScript
94.2%
JavaScript
5.8%