UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.08 kB
import{t as pruneMapToMaxSize}from"./map-size-DLQqorvK.mjs"; //!src/gateway/server/ws-connection/handshake-auth-log-limiter.ts var HandshakeAuthLogLimiter=class{constructor(){this.entries=/* @__PURE__ */ new Map}missingCredentialLogSuffix(e,t){if(e.authProvided!==`none`||e.reason!==`token_missing`&&e.reason!==`password_missing`)return``;const n=[e.reason,e.remoteAddr??`?`,e.client??`?`,e.mode??`?`,e.authProvided].join(`|`);return this.logSuffix(n,t)}nativeAuthUnavailableLogSuffix(e,t){if(e.code!==4008||e.reason!==`native authorization unavailable`)return``;const n=JSON.stringify([`native-auth-unavailable`,e.remoteAddr??`?`,e.origin??`?`,e.userAgent??`?`]);return this.logSuffix(n,t)}logSuffix(e,t){const n=t??Date.now();const r=this.entries.get(e);if(!r){pruneMapToMaxSize(this.entries,255);this.entries.set(e,{lastLoggedAtMs:n,suppressedSinceLastLog:0});return``}if(n-r.lastLoggedAtMs<3e4){r.suppressedSinceLastLog+=1;return}const i=r.suppressedSinceLastLog;r.lastLoggedAtMs=n;r.suppressedSinceLastLog=0;return i>0?` suppressed=${i}`:``}};export{HandshakeAuthLogLimiter as t};