A TypeScript/JavaScript client library for authenticating with the Hermes Business Customer Authentication API, implementing OAuth 2.0 with support for Password Grant, Authorization Code Grant, and Refresh Token flows.
bun install- OAuth 2.0 Grant Types:
- Password Grant
- Authorization Code Grant
- Refresh Token Grant
- Automatic Token Management:
- Token refresh on expiry
- Configurable expiry buffer
- Persistent token storage (browser)
- API Client with Auth Middleware:
- Automatic Authorization header injection
- Automatic token refresh and request retry
- JWT Token Utilities:
- Token decoding
- Expiry checking
- User info extraction
import{HermesAuthClient,HermesApiClient}from'hermes-api';constauthClient=newHermesAuthClient({clientId: 'your-client-id',clientSecret: 'your-client-secret',// OptionalauthBaseUrl: 'https://authme.myhermes.de',// Production});// AuthenticateconsttokenResponse=awaitauthClient.authenticateWithPassword('username','password');// Create API client for authenticated requestsconstapiClient=newHermesApiClient(authClient,'https://your-api.myhermes.de');// Make authenticated API callsconstdata=awaitapiClient.get('/api/endpoint');// Step 1: Get authorization URLconstauthUrl=authClient.getAuthorizationUrl('https://your-app.com/callback','optional-state-string');// Redirect user to authUrl// Step 2: Exchange code for tokensconsttokenResponse=awaitauthClient.exchangeAuthorizationCode('authorization-code-from-redirect','https://your-app.com/callback');The API client automatically handles token refresh:
// Token will be refreshed automatically if expiredconstdata=awaitapiClient.get('/api/protected-endpoint');Track Hermes shipments using the HSI API:
import{HermesShipmentApi}from'hermes-api';// Create shipment API instanceconstshipmentApi=newHermesShipmentApi(apiClient);// Get shipment informationconstshipmentInfo=awaitshipmentApi.getShipmentInfo('1234567890123456');console.log('Status:',shipmentInfo.statusLangText);console.log('Expected Delivery:',shipmentInfo.voraussichtlicherZustelltag);// Check if deliveredconstisDelivered=awaitshipmentApi.isShipmentDelivered('1234567890123456');// Get tracking historyconsthistory=awaitshipmentApi.getTrackingHistory('1234567890123456');// Get proof of deliveryconstpod=awaitshipmentApi.getProofOfDelivery('1234567890123456');authenticateWithPassword(username, password)- Password grant authenticationexchangeAuthorizationCode(code, redirectUri)- Exchange auth code for tokensrefreshAccessToken(refreshToken?)- Refresh access tokengetAuthorizationUrl(redirectUri, state?)- Get OAuth authorization URLgetAccessToken()- Get current access token (auto-refresh if expired)getAuthorizationHeader()- Get Bearer token header valueisAuthenticated()- Check if authenticated with valid tokenlogout()- Clear stored tokens
get(endpoint, options?)- GET requestpost(endpoint, data?, options?)- POST requestput(endpoint, data?, options?)- PUT requestdelete(endpoint, options?)- DELETE requestpatch(endpoint, data?, options?)- PATCH request
getShipmentInfo(trackingNumber)- Get complete shipment informationgetMultipleShipmentInfo(trackingNumbers[])- Get info for multiple shipmentsgetShipmentStatus(trackingNumber)- Get current status textisShipmentDelivered(trackingNumber)- Check if deliveredgetEstimatedDeliveryDate(trackingNumber)- Get expected delivery dategetTrackingHistory(trackingNumber)- Get full tracking historygetProofOfDelivery(trackingNumber)- Get proof of delivery detailsgetRecipientInfo(trackingNumber)- Get recipient informationgetEcoInfo(trackingNumber)- Get ecological impact informationgetReturnInfo(trackingNumber)- Get return label information
saveToken(token)- Save token to localStoragegetToken()- Retrieve saved tokenclearToken()- Remove saved tokendecodeToken(token)- Decode JWT without verificationisTokenExpired(token)- Check token expirygetTokenTimeToLive(token)- Get seconds until expiryextractUserInfo(token)- Extract user claims from token
- Production:
https://authme.myhermes.de - Integration:
https://authme-int.myhermes.de
- Access tokens are valid for 1 hour
- Tokens are JWT format with max size of 8KB
- Automatic refresh occurs 5 minutes before expiry
examples/usage.ts- Authentication and API usage examplesexamples/shipment-tracking.ts- Shipment tracking examples
This project uses Bun runtime.
# Install dependencies
bun install
# Run examples
bun run examples/usage.ts