@elliemae/microfe-common 2.24.0 → 2.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var auditThrottler_exports = {};
20
+ __export(auditThrottler_exports, {
21
+ AuditThrottler: () => AuditThrottler
22
+ });
23
+ module.exports = __toCommonJS(auditThrottler_exports);
24
+ class AuditThrottler {
25
+ #logger;
26
+ #enabled;
27
+ #throttleMs;
28
+ #lastAudited = /* @__PURE__ */ new Map();
29
+ static DEFAULT_THROTTLE_MS = 1e4;
30
+ constructor(options) {
31
+ this.#logger = options.logger;
32
+ this.#enabled = options.enabled ?? true;
33
+ this.#throttleMs = options.throttleMs ?? AuditThrottler.DEFAULT_THROTTLE_MS;
34
+ }
35
+ get enabled() {
36
+ return this.#enabled;
37
+ }
38
+ /**
39
+ * Log a high-frequency operation. When audit is enabled and the throttle
40
+ * window allows it the payload is sent at `audit` level; otherwise `debug`.
41
+ * @param {string} key - dedup key for throttling (e.g. `invoke:loan.getField`)
42
+ * @param {LogRecord} payload - structured log payload
43
+ */
44
+ log(key, payload) {
45
+ if (!this.#enabled) {
46
+ this.#logger.debug(payload);
47
+ return;
48
+ }
49
+ if (this.#throttleMs > 0) {
50
+ const now = performance.now();
51
+ const last = this.#lastAudited.get(key);
52
+ if (last !== void 0 && now - last < this.#throttleMs) {
53
+ this.#logger.debug(payload);
54
+ return;
55
+ }
56
+ this.#lastAudited.set(key, now);
57
+ }
58
+ this.#logger.audit(payload);
59
+ }
60
+ }
package/dist/cjs/index.js CHANGED
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var index_exports = {};
20
20
  __export(index_exports, {
21
+ AuditThrottler: () => import_auditThrottler.AuditThrottler,
21
22
  Event: () => import_event2.Event,
22
23
  MessageType: () => import_messageType.MessageType,
23
24
  ProxyEvent: () => import_event.ProxyEvent,
@@ -39,3 +40,4 @@ var import_scriptingObject = require("./scriptingObject.js");
39
40
  var import_messageType = require("./messageType.js");
40
41
  var import_scriptingObjectManager = require("./scriptingObjectManager.js");
41
42
  var import_proxy = require("./proxy.js");
43
+ var import_auditThrottler = require("./auditThrottler.js");
@@ -0,0 +1,40 @@
1
+ class AuditThrottler {
2
+ #logger;
3
+ #enabled;
4
+ #throttleMs;
5
+ #lastAudited = /* @__PURE__ */ new Map();
6
+ static DEFAULT_THROTTLE_MS = 1e4;
7
+ constructor(options) {
8
+ this.#logger = options.logger;
9
+ this.#enabled = options.enabled ?? true;
10
+ this.#throttleMs = options.throttleMs ?? AuditThrottler.DEFAULT_THROTTLE_MS;
11
+ }
12
+ get enabled() {
13
+ return this.#enabled;
14
+ }
15
+ /**
16
+ * Log a high-frequency operation. When audit is enabled and the throttle
17
+ * window allows it the payload is sent at `audit` level; otherwise `debug`.
18
+ * @param {string} key - dedup key for throttling (e.g. `invoke:loan.getField`)
19
+ * @param {LogRecord} payload - structured log payload
20
+ */
21
+ log(key, payload) {
22
+ if (!this.#enabled) {
23
+ this.#logger.debug(payload);
24
+ return;
25
+ }
26
+ if (this.#throttleMs > 0) {
27
+ const now = performance.now();
28
+ const last = this.#lastAudited.get(key);
29
+ if (last !== void 0 && now - last < this.#throttleMs) {
30
+ this.#logger.debug(payload);
31
+ return;
32
+ }
33
+ this.#lastAudited.set(key, now);
34
+ }
35
+ this.#logger.audit(payload);
36
+ }
37
+ }
38
+ export {
39
+ AuditThrottler
40
+ };
package/dist/esm/index.js CHANGED
@@ -8,7 +8,9 @@ import {
8
8
  SecurityContext
9
9
  } from "./scriptingObjectManager.js";
10
10
  import { ScriptingObjectProxy, isScriptingObjectProxy } from "./proxy.js";
11
+ import { AuditThrottler } from "./auditThrottler.js";
11
12
  export {
13
+ AuditThrottler,
12
14
  Event,
13
15
  MessageType,
14
16
  ProxyEvent,
@@ -0,0 +1,29 @@
1
+ import type { Logger, LogRecord } from '@elliemae/pui-diagnostics';
2
+ export type AuditThrottlerOptions = {
3
+ logger: Logger;
4
+ /** When `true`, high-frequency operations are logged at `audit` level. @default true */
5
+ enabled?: boolean;
6
+ /** Throttle window (ms). Same operation key is audited at most once per window. @default 10000 */
7
+ throttleMs?: number;
8
+ };
9
+ /**
10
+ * Controls whether high-frequency operations are logged at `audit` level
11
+ * (sent to Splunk) or `debug` level (local only).
12
+ *
13
+ * When enabled, a per-key throttle window prevents the same operation from
14
+ * flooding Splunk. Operations outside the window or with throttling disabled
15
+ * (`throttleMs === 0`) go straight to `audit`.
16
+ */
17
+ export declare class AuditThrottler {
18
+ #private;
19
+ static readonly DEFAULT_THROTTLE_MS = 10000;
20
+ constructor(options: AuditThrottlerOptions);
21
+ get enabled(): boolean;
22
+ /**
23
+ * Log a high-frequency operation. When audit is enabled and the throttle
24
+ * window allows it the payload is sent at `audit` level; otherwise `debug`.
25
+ * @param {string} key - dedup key for throttling (e.g. `invoke:loan.getField`)
26
+ * @param {LogRecord} payload - structured log payload
27
+ */
28
+ log(key: string, payload: LogRecord): void;
29
+ }
@@ -12,3 +12,5 @@ export type { ISSFGuest, ConnectParam } from './guest.js';
12
12
  export { ScriptingObjectManager, SecurityContext, } from './scriptingObjectManager.js';
13
13
  export type { AddScriptingObjectParams, CallContext, CallerInfo, GetObjectParams, GuestContext, } from './scriptingObjectManager.js';
14
14
  export { ScriptingObjectProxy, isScriptingObjectProxy } from './proxy.js';
15
+ export { AuditThrottler } from './auditThrottler.js';
16
+ export type { AuditThrottlerOptions } from './auditThrottler.js';
@@ -0,0 +1 @@
1
+ export {};