(organizationId: string)
| 279 | * known-paid org into a block mid-workload. |
| 280 | */ |
| 281 | const resolveExemption = (organizationId: string): Effect.Effect<boolean> => |
| 282 | Effect.suspend(() => { |
| 283 | if (!isExempt) return Effect.succeed(false); |
| 284 | const nowMs = now(); |
| 285 | const cached = exemptionCache.get(organizationId); |
| 286 | if (cached && cached.expiresAtMs > nowMs) return Effect.succeed(cached.exempt); |
| 287 | return isExempt(organizationId).pipe( |
| 288 | Effect.timeoutOrElse({ |
| 289 | duration: `${EXEMPTION_CHECK_TIMEOUT_MS} millis`, |
| 290 | orElse: () => |
| 291 | Effect.fail(new ExemptionCheckTimeoutError({ timeoutMs: EXEMPTION_CHECK_TIMEOUT_MS })), |
| 292 | }), |
| 293 | Effect.map((exempt) => { |
| 294 | writeExemptionCache(organizationId, exempt, nowMs); |
| 295 | return exempt; |
| 296 | }), |
| 297 | Effect.catch((error: unknown) => |
| 298 | Effect.gen(function* () { |
| 299 | yield* Effect.sync(() => { |
| 300 | console.warn( |
| 301 | `[rate-limit] exemption lookup failed for ${organizationId}; treating as ${ |
| 302 | cached ? "last known" : "not exempt" |
| 303 | }:`, |
| 304 | error, |
| 305 | ); |
| 306 | }); |
| 307 | yield* captureCauseEffect(error); |
| 308 | return cached?.exempt ?? false; |
| 309 | }), |
| 310 | ), |
| 311 | ); |
| 312 | }); |
| 313 | |
| 314 | const decide = (organizationId: string): Effect.Effect<GateDecision> => |
| 315 | Effect.suspend(() => { |
no test coverage detected