@elliemae/microfe-common 2.23.6 → 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
+ }
@@ -10,5 +10,7 @@ export { MessageType } from './messageType.js';
10
10
  export type { EventListeners, Listener } from './common.js';
11
11
  export type { ISSFGuest, ConnectParam } from './guest.js';
12
12
  export { ScriptingObjectManager, SecurityContext, } from './scriptingObjectManager.js';
13
- export type { AddScriptingObjectParams, GetObjectParams, GuestContext, } from './scriptingObjectManager.js';
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';
@@ -11,6 +11,41 @@ export type GuestContext = {
11
11
  */
12
12
  id: string;
13
13
  };
14
+ /**
15
+ * identity and optional host-supplied metadata for a caller
16
+ * in the call chain.
17
+ */
18
+ export type CallerInfo = GuestContext & {
19
+ /**
20
+ * arbitrary metadata the intermediate host associates with
21
+ * this guest (e.g. security role, tenant id, permissions).
22
+ * Supplied via the `metadata` option in loadGuest().
23
+ */
24
+ metadata?: Record<string, unknown>;
25
+ };
26
+ /**
27
+ * Context attached to scripting object method calls.
28
+ * `guest` identifies the direct caller (verified via sourceWin);
29
+ * `callChain` traces the full path from the original caller when
30
+ * the call is forwarded through intermediate host/guest layers.
31
+ *
32
+ * **Trust model**: `guest` is host-verified (derived from the
33
+ * message source window). `callChain` is self-reported by the
34
+ * intermediate guest and carries the same trust level as the
35
+ * direct caller — if you trust guest B, you can trust the
36
+ * callChain it supplies.
37
+ */
38
+ export type CallContext = {
39
+ guest: GuestContext;
40
+ /**
41
+ * Ordered list of callers when a call is forwarded through
42
+ * intermediate guests (e.g. A hosts B hosts C, C calls a
43
+ * scripting object — callChain will be [{ id: "C" }]).
44
+ * Each entry may carry host-supplied metadata.
45
+ * Absent for direct (non-forwarded) calls.
46
+ */
47
+ callChain?: CallerInfo[];
48
+ };
14
49
  /**
15
50
  * security context under which the guest application is running
16
51
  */
@@ -0,0 +1 @@
1
+ export {};