min,
once,
promiseWithTimeout,
- roundTo,
secureRandom,
sleep,
watchJsonFile,
? reconnectDelay - Constants.DEFAULT_WS_RECONNECT_TIMEOUT_OFFSET
: 0
logger.error(
- `${this.logPrefix()} WebSocket connection retry in ${roundTo(
- reconnectDelay,
- 2
- ).toString()}ms, timeout ${reconnectTimeout.toString()}ms`
+ `${this.logPrefix()} WebSocket connection retry in ${formatDurationMilliSeconds(reconnectDelay)}, timeout ${formatDurationMilliSeconds(reconnectTimeout)}`
)
await sleep(reconnectDelay)
logger.error(
-import { secondsToMilliseconds } from 'date-fns'
+import { millisecondsToSeconds, secondsToMilliseconds } from 'date-fns'
import type { ChargingStation } from '../../../charging-station/index.js'
import type { JsonType, OCPP20SignCertificateResponse } from '../../../types/index.js'
})
logger.debug(
- `${this.chargingStation.logPrefix()} ${moduleName}.scheduleNextRetry: Scheduling retry ${(this.retryCount + 1).toString()}/${maxRetries.toString()} in ${Math.round(delayMs / 1000).toString()}s`
+ `${this.chargingStation.logPrefix()} ${moduleName}.scheduleNextRetry: Scheduling retry ${(this.retryCount + 1).toString()}/${maxRetries.toString()} in ${millisecondsToSeconds(delayMs).toString()}s`
)
this.retryTimer = setTimeout(() => {
import type { ValidateFunction } from 'ajv'
+import { secondsToMilliseconds } from 'date-fns'
+
import type { ChargingStation } from '../../../charging-station/index.js'
import type { OCPP20IdTokenEnumType } from '../../../types/index.js'
if (location.trim() === '' || !this.isValidFirmwareLocation(location)) {
// L01.FR.30: Simulate download retries before reporting DownloadFailed
const maxRetries = retries ?? 0
- const retryDelayMs = (retryInterval ?? 0) * 1000
+ const retryDelayMs = secondsToMilliseconds(retryInterval ?? 0)
for (let attempt = 1; attempt <= maxRetries; attempt++) {
logger.warn(
`${chargingStation.logPrefix()} ${moduleName}.simulateFirmwareUpdateLifecycle: Download failed for requestId ${requestId.toString()} - invalid location '${location}' (attempt ${attempt.toString()}/${maxRetries.toString()}, retrying in ${retryInterval?.toString() ?? '0'}s)`
import type { ChargingStation } from '../../../charging-station/index.js'
import type { OCPPResponseService } from '../OCPPResponseService.js'
+import { getConfigurationKey } from '../../../charging-station/index.js'
import { OCPPError } from '../../../exception/index.js'
import {
type CertificateSigningUseEnumType,
case OCPP20RequestCommand.SIGN_CERTIFICATE: {
let csr: string
try {
- const configKey = chargingStation.ocppConfiguration?.configurationKey?.find(
- key => key.key === 'SecurityCtrlr.OrganizationName'
- )
+ const configKey = getConfigurationKey(chargingStation, 'SecurityCtrlr.OrganizationName')
const orgName = configKey?.value ?? 'Unknown'
const stationId = chargingStation.stationInfo?.chargingStationId ?? 'Unknown'
+import { secondsToMilliseconds } from 'date-fns'
+
import type { AuthCache, CacheStats } from '../interfaces/OCPPAuthService.js'
import type { AuthorizationResult } from '../types/AuthTypes.js'
const cleanupSeconds = options?.cleanupIntervalSeconds ?? 300
if (cleanupSeconds > 0) {
- const intervalMs = cleanupSeconds * 1000
+ const intervalMs = secondsToMilliseconds(cleanupSeconds)
this.cleanupInterval = setInterval(() => {
this.runCleanup()
}, intervalMs)
if (!authCacheEntry.hasExplicitTtl) {
const absoluteDeadline = authCacheEntry.createdAt + this.maxAbsoluteLifetimeMs
if (absoluteDeadline > now) {
- authCacheEntry.expiresAt = Math.min(now + this.defaultTtl * 1000, absoluteDeadline)
+ authCacheEntry.expiresAt = Math.min(
+ now + secondsToMilliseconds(this.defaultTtl),
+ absoluteDeadline
+ )
}
}
this.lruOrder.set(identifier, now)
!authCacheEntry.hasExplicitTtl &&
authCacheEntry.createdAt + this.maxAbsoluteLifetimeMs > now
) {
- authCacheEntry.expiresAt = now + this.defaultTtl * 1000
+ authCacheEntry.expiresAt = now + secondsToMilliseconds(this.defaultTtl)
}
logger.debug(`${moduleName}: Cache hit for identifier: '${truncateId(identifier)}'`)
if (!entry.hasExplicitTtl) {
const absoluteDeadline = entry.createdAt + this.maxAbsoluteLifetimeMs
if (absoluteDeadline > now) {
- entry.expiresAt = Math.min(now + this.defaultTtl * 1000, absoluteDeadline)
+ entry.expiresAt = Math.min(
+ now + secondsToMilliseconds(this.defaultTtl),
+ absoluteDeadline
+ )
}
}
this.stats.expired++
const maxTtlSeconds = this.maxAbsoluteLifetimeMs / 1000
const clampedTtl = Math.min(Math.max(0, ttlSeconds), maxTtlSeconds)
const now = Date.now()
- const expiresAt = now + clampedTtl * 1000
+ const expiresAt = now + secondsToMilliseconds(clampedTtl)
this.cache.set(identifier, {
createdAt: now,
+import { millisecondsToSeconds } from 'date-fns'
+
import type { OCPPAuthAdapter } from '../interfaces/OCPPAuthService.js'
import { OCPPError } from '../../../../exception/index.js'
convertToDate,
ensureError,
getErrorMessage,
+ has,
logger,
truncateId,
} from '../../../../utils/index.js'
const remoteStrategy = this.strategies.get('remote')
if (remoteStrategy?.getStats) {
const strategyStatistics = remoteStrategy.getStats()
- if ('cache' in strategyStatistics) {
+ if (has('cache', strategyStatistics)) {
const cacheStatistics = strategyStatistics.cache as {
rateLimit?: {
blockedRequests: number
if (expiryDate != null) {
const expiry = convertToDate(expiryDate)
if (expiry != null) {
- const ttlSeconds = Math.floor((expiry.getTime() - Date.now()) / 1000)
+ const ttlSeconds = millisecondsToSeconds(expiry.getTime() - Date.now())
if (ttlSeconds <= 0) {
logger.debug(
`${this.chargingStation.logPrefix()} ${moduleName}.updateCacheEntry: Skipping expired entry for '${truncateId(identifier)}'`
obj: AuthStrategy
): obj is AuthStrategy & { configure: (config: Record<string, unknown>) => void } => {
return (
- 'configure' in obj &&
+ has('configure', obj) &&
typeof (obj as AuthStrategy & { configure?: unknown }).configure === 'function'
)
}
+import { secondsToMilliseconds } from 'date-fns'
+
import type { JsonObject } from '../../../../types/index.js'
import type {
AuthCache,
config: AuthConfiguration,
startTime: number
): Promise<AuthorizationResult | undefined> {
- const timeout = config.authorizationTimeout * 1000
+ const timeout = secondsToMilliseconds(config.authorizationTimeout)
try {
const authPromise = adapter.authorizeRemote(
+import { millisecondsToSeconds } from 'date-fns'
+
import type {
AuthContext,
AuthenticationMethod,
return undefined
}
- return Math.floor(ttlMs / 1000)
+ return millisecondsToSeconds(ttlMs)
}
/**