@elliemae/microfe-common 2.27.0 → 2.28.1
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.
- package/dist/cjs/filterCriteria.js +67 -0
- package/dist/cjs/guestCapabilities.js +36 -0
- package/dist/cjs/index.js +8 -0
- package/dist/esm/filterCriteria.js +47 -0
- package/dist/esm/guestCapabilities.js +16 -0
- package/dist/esm/index.js +16 -0
- package/dist/types/lib/event.d.ts +5 -0
- package/dist/types/lib/filterCriteria.d.ts +28 -0
- package/dist/types/lib/guestCapabilities.d.ts +20 -0
- package/dist/types/lib/index.d.ts +4 -0
- package/dist/types/lib/tests/filterCriteria.test.d.ts +1 -0
- package/dist/types/lib/tests/guestCapabilities.test.d.ts +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,67 @@
|
|
|
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 filterCriteria_exports = {};
|
|
20
|
+
__export(filterCriteria_exports, {
|
|
21
|
+
hasFilterCriteria: () => hasFilterCriteria,
|
|
22
|
+
isFilterOperator: () => isFilterOperator,
|
|
23
|
+
matchesFilterCriteria: () => matchesFilterCriteria,
|
|
24
|
+
matchesFilterOperator: () => matchesFilterOperator
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(filterCriteria_exports);
|
|
27
|
+
const defaultRegexCache = /* @__PURE__ */ new Map();
|
|
28
|
+
function isFilterOperator(value) {
|
|
29
|
+
return typeof value === "object" && value !== null && ("eq" in value || "in" in value || "includes" in value || "gt" in value || "lt" in value || "regex" in value);
|
|
30
|
+
}
|
|
31
|
+
function matchesFilterOperator(value, condition, regexCache) {
|
|
32
|
+
if ("eq" in condition) return value === condition.eq;
|
|
33
|
+
if ("in" in condition)
|
|
34
|
+
return Array.isArray(condition.in) && condition.in.includes(value);
|
|
35
|
+
if ("includes" in condition)
|
|
36
|
+
return Array.isArray(value) && value.includes(condition.includes);
|
|
37
|
+
if ("gt" in condition) {
|
|
38
|
+
const numValue = typeof value === "number" ? value : Number(value);
|
|
39
|
+
return !Number.isNaN(numValue) && numValue > condition.gt;
|
|
40
|
+
}
|
|
41
|
+
if ("lt" in condition) {
|
|
42
|
+
const numValue = typeof value === "number" ? value : Number(value);
|
|
43
|
+
return !Number.isNaN(numValue) && numValue < condition.lt;
|
|
44
|
+
}
|
|
45
|
+
if ("regex" in condition) {
|
|
46
|
+
const cache = regexCache ?? defaultRegexCache;
|
|
47
|
+
let regex = cache.get(condition.regex);
|
|
48
|
+
if (regex === void 0) {
|
|
49
|
+
try {
|
|
50
|
+
regex = new RegExp(condition.regex);
|
|
51
|
+
} catch {
|
|
52
|
+
regex = null;
|
|
53
|
+
}
|
|
54
|
+
cache.set(condition.regex, regex);
|
|
55
|
+
}
|
|
56
|
+
return regex !== null && typeof value === "string" && regex.test(value);
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
function hasFilterCriteria(criteria) {
|
|
61
|
+
return criteria != null && Object.keys(criteria).length > 0;
|
|
62
|
+
}
|
|
63
|
+
function matchesFilterCriteria(payload, criteria, options) {
|
|
64
|
+
return Object.entries(criteria).every(
|
|
65
|
+
([key, condition]) => matchesFilterOperator(payload[key], condition, options?.regexCache)
|
|
66
|
+
);
|
|
67
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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 guestCapabilities_exports = {};
|
|
20
|
+
__export(guestCapabilities_exports, {
|
|
21
|
+
RESERVED_GUEST_CAPABILITIES: () => RESERVED_GUEST_CAPABILITIES,
|
|
22
|
+
matchesGuestCapabilities: () => matchesGuestCapabilities
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(guestCapabilities_exports);
|
|
25
|
+
var import_filterCriteria = require("./filterCriteria.js");
|
|
26
|
+
const RESERVED_GUEST_CAPABILITIES = [
|
|
27
|
+
"eventFeedback",
|
|
28
|
+
"onReady",
|
|
29
|
+
"window"
|
|
30
|
+
];
|
|
31
|
+
function matchesGuestCapabilities(declared, criteria) {
|
|
32
|
+
if (!(0, import_filterCriteria.hasFilterCriteria)(criteria)) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
return (0, import_filterCriteria.matchesFilterCriteria)(declared, criteria);
|
|
36
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -22,20 +22,28 @@ __export(index_exports, {
|
|
|
22
22
|
Event: () => import_event2.Event,
|
|
23
23
|
MessageType: () => import_messageType.MessageType,
|
|
24
24
|
ProxyEvent: () => import_event.ProxyEvent,
|
|
25
|
+
RESERVED_GUEST_CAPABILITIES: () => import_guestCapabilities.RESERVED_GUEST_CAPABILITIES,
|
|
25
26
|
Remoting: () => import_remoting.Remoting,
|
|
26
27
|
ScriptingObject: () => import_scriptingObject.ScriptingObject,
|
|
27
28
|
ScriptingObjectManager: () => import_scriptingObjectManager.ScriptingObjectManager,
|
|
28
29
|
ScriptingObjectProxy: () => import_proxy.ScriptingObjectProxy,
|
|
29
30
|
SecurityContext: () => import_scriptingObjectManager.SecurityContext,
|
|
30
31
|
getEventId: () => import_event.getEventId,
|
|
32
|
+
hasFilterCriteria: () => import_filterCriteria.hasFilterCriteria,
|
|
33
|
+
isFilterOperator: () => import_filterCriteria.isFilterOperator,
|
|
31
34
|
isPublicFunction: () => import_scriptingObject.isPublicFunction,
|
|
32
35
|
isScriptingObjectProxy: () => import_proxy.isScriptingObjectProxy,
|
|
36
|
+
matchesFilterCriteria: () => import_filterCriteria.matchesFilterCriteria,
|
|
37
|
+
matchesFilterOperator: () => import_filterCriteria.matchesFilterOperator,
|
|
38
|
+
matchesGuestCapabilities: () => import_guestCapabilities.matchesGuestCapabilities,
|
|
33
39
|
sendMessage: () => import_remoting.sendMessage
|
|
34
40
|
});
|
|
35
41
|
module.exports = __toCommonJS(index_exports);
|
|
36
42
|
var import_remoting = require("./remoting.js");
|
|
37
43
|
var import_event = require("./event.js");
|
|
38
44
|
var import_event2 = require("./event.js");
|
|
45
|
+
var import_filterCriteria = require("./filterCriteria.js");
|
|
46
|
+
var import_guestCapabilities = require("./guestCapabilities.js");
|
|
39
47
|
var import_scriptingObject = require("./scriptingObject.js");
|
|
40
48
|
var import_messageType = require("./messageType.js");
|
|
41
49
|
var import_scriptingObjectManager = require("./scriptingObjectManager.js");
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const defaultRegexCache = /* @__PURE__ */ new Map();
|
|
2
|
+
function isFilterOperator(value) {
|
|
3
|
+
return typeof value === "object" && value !== null && ("eq" in value || "in" in value || "includes" in value || "gt" in value || "lt" in value || "regex" in value);
|
|
4
|
+
}
|
|
5
|
+
function matchesFilterOperator(value, condition, regexCache) {
|
|
6
|
+
if ("eq" in condition) return value === condition.eq;
|
|
7
|
+
if ("in" in condition)
|
|
8
|
+
return Array.isArray(condition.in) && condition.in.includes(value);
|
|
9
|
+
if ("includes" in condition)
|
|
10
|
+
return Array.isArray(value) && value.includes(condition.includes);
|
|
11
|
+
if ("gt" in condition) {
|
|
12
|
+
const numValue = typeof value === "number" ? value : Number(value);
|
|
13
|
+
return !Number.isNaN(numValue) && numValue > condition.gt;
|
|
14
|
+
}
|
|
15
|
+
if ("lt" in condition) {
|
|
16
|
+
const numValue = typeof value === "number" ? value : Number(value);
|
|
17
|
+
return !Number.isNaN(numValue) && numValue < condition.lt;
|
|
18
|
+
}
|
|
19
|
+
if ("regex" in condition) {
|
|
20
|
+
const cache = regexCache ?? defaultRegexCache;
|
|
21
|
+
let regex = cache.get(condition.regex);
|
|
22
|
+
if (regex === void 0) {
|
|
23
|
+
try {
|
|
24
|
+
regex = new RegExp(condition.regex);
|
|
25
|
+
} catch {
|
|
26
|
+
regex = null;
|
|
27
|
+
}
|
|
28
|
+
cache.set(condition.regex, regex);
|
|
29
|
+
}
|
|
30
|
+
return regex !== null && typeof value === "string" && regex.test(value);
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
function hasFilterCriteria(criteria) {
|
|
35
|
+
return criteria != null && Object.keys(criteria).length > 0;
|
|
36
|
+
}
|
|
37
|
+
function matchesFilterCriteria(payload, criteria, options) {
|
|
38
|
+
return Object.entries(criteria).every(
|
|
39
|
+
([key, condition]) => matchesFilterOperator(payload[key], condition, options?.regexCache)
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
hasFilterCriteria,
|
|
44
|
+
isFilterOperator,
|
|
45
|
+
matchesFilterCriteria,
|
|
46
|
+
matchesFilterOperator
|
|
47
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { hasFilterCriteria, matchesFilterCriteria } from "./filterCriteria.js";
|
|
2
|
+
const RESERVED_GUEST_CAPABILITIES = [
|
|
3
|
+
"eventFeedback",
|
|
4
|
+
"onReady",
|
|
5
|
+
"window"
|
|
6
|
+
];
|
|
7
|
+
function matchesGuestCapabilities(declared, criteria) {
|
|
8
|
+
if (!hasFilterCriteria(criteria)) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
return matchesFilterCriteria(declared, criteria);
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
RESERVED_GUEST_CAPABILITIES,
|
|
15
|
+
matchesGuestCapabilities
|
|
16
|
+
};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { Remoting, sendMessage } from "./remoting.js";
|
|
2
2
|
import { getEventId, ProxyEvent } from "./event.js";
|
|
3
3
|
import { Event } from "./event.js";
|
|
4
|
+
import {
|
|
5
|
+
hasFilterCriteria,
|
|
6
|
+
isFilterOperator,
|
|
7
|
+
matchesFilterCriteria,
|
|
8
|
+
matchesFilterOperator
|
|
9
|
+
} from "./filterCriteria.js";
|
|
10
|
+
import {
|
|
11
|
+
matchesGuestCapabilities,
|
|
12
|
+
RESERVED_GUEST_CAPABILITIES
|
|
13
|
+
} from "./guestCapabilities.js";
|
|
4
14
|
import { ScriptingObject, isPublicFunction } from "./scriptingObject.js";
|
|
5
15
|
import { MessageType } from "./messageType.js";
|
|
6
16
|
import {
|
|
@@ -14,13 +24,19 @@ export {
|
|
|
14
24
|
Event,
|
|
15
25
|
MessageType,
|
|
16
26
|
ProxyEvent,
|
|
27
|
+
RESERVED_GUEST_CAPABILITIES,
|
|
17
28
|
Remoting,
|
|
18
29
|
ScriptingObject,
|
|
19
30
|
ScriptingObjectManager,
|
|
20
31
|
ScriptingObjectProxy,
|
|
21
32
|
SecurityContext,
|
|
22
33
|
getEventId,
|
|
34
|
+
hasFilterCriteria,
|
|
35
|
+
isFilterOperator,
|
|
23
36
|
isPublicFunction,
|
|
24
37
|
isScriptingObjectProxy,
|
|
38
|
+
matchesFilterCriteria,
|
|
39
|
+
matchesFilterOperator,
|
|
40
|
+
matchesGuestCapabilities,
|
|
25
41
|
sendMessage
|
|
26
42
|
};
|
|
@@ -211,6 +211,11 @@ export type EventOptions = {
|
|
|
211
211
|
* global function that handles the event on the guest
|
|
212
212
|
*/
|
|
213
213
|
eventHandler?: string;
|
|
214
|
+
/**
|
|
215
|
+
* {@link FilterCriteria} for matching `guest.capabilities`. Used by SSF Host
|
|
216
|
+
* `dispatchEvent` to select guests; may be used for other host logic.
|
|
217
|
+
*/
|
|
218
|
+
guestCapabilities?: FilterCriteria;
|
|
214
219
|
};
|
|
215
220
|
/**
|
|
216
221
|
* parameters for dispatching an event
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { FilterCriteria, FilterOperator } from './event.js';
|
|
2
|
+
/**
|
|
3
|
+
* Returns true if `value` is a filter operator object (eq, in, gt, …).
|
|
4
|
+
* @param value
|
|
5
|
+
*/
|
|
6
|
+
export declare function isFilterOperator(value: unknown): value is FilterOperator;
|
|
7
|
+
/**
|
|
8
|
+
* Evaluates a single filter operator against a payload field value.
|
|
9
|
+
* @param value
|
|
10
|
+
* @param condition
|
|
11
|
+
* @param regexCache
|
|
12
|
+
*/
|
|
13
|
+
export declare function matchesFilterOperator(value: unknown, condition: FilterOperator, regexCache?: Map<string, RegExp | null>): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Returns true when `criteria` is present and has at least one key.
|
|
16
|
+
* @param criteria
|
|
17
|
+
*/
|
|
18
|
+
export declare function hasFilterCriteria(criteria?: FilterCriteria): criteria is FilterCriteria;
|
|
19
|
+
export type MatchesFilterCriteriaOptions = {
|
|
20
|
+
regexCache?: Map<string, RegExp | null>;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Returns whether `payload` satisfies `criteria` (AND across keys; same as event subscribe).
|
|
24
|
+
* @param payload - values to test (e.g. eventParams or guest.capabilities)
|
|
25
|
+
* @param criteria - per-field operators (`eq`, `in`, `includes`, `gt`, `lt`, `regex`)
|
|
26
|
+
* @param options
|
|
27
|
+
*/
|
|
28
|
+
export declare function matchesFilterCriteria(payload: Record<string, unknown>, criteria: FilterCriteria, options?: MatchesFilterCriteriaOptions): boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { FilterCriteria } from './event.js';
|
|
2
|
+
/**
|
|
3
|
+
* Primitive values a guest may declare at connect via `guest:ready` (and that the
|
|
4
|
+
* host stores on `guest.capabilities`). Applications define their own keys.
|
|
5
|
+
*/
|
|
6
|
+
export type GuestCapabilityValue = boolean | string | number | null;
|
|
7
|
+
/**
|
|
8
|
+
* Map of capability keys to values (connect declaration).
|
|
9
|
+
*/
|
|
10
|
+
export type GuestCapabilities = Record<string, GuestCapabilityValue>;
|
|
11
|
+
/**
|
|
12
|
+
* Keys reserved for the SSF connect handshake (not application-defined capabilities).
|
|
13
|
+
*/
|
|
14
|
+
export declare const RESERVED_GUEST_CAPABILITIES: readonly ["eventFeedback", "onReady", "window"];
|
|
15
|
+
/**
|
|
16
|
+
* Returns whether `declared` satisfies `criteria` using subscribe-style filter operators (AND across keys).
|
|
17
|
+
* @param declared - capabilities from guest:ready (e.g. host `guest.capabilities`)
|
|
18
|
+
* @param criteria - {@link FilterCriteria}; omitted or empty matches any declared map
|
|
19
|
+
*/
|
|
20
|
+
export declare function matchesGuestCapabilities(declared: Record<string, unknown>, criteria?: FilterCriteria): boolean;
|
|
@@ -4,6 +4,10 @@ export type { RemotingEventMessage } from './remotingEventMessage.js';
|
|
|
4
4
|
export { getEventId, ProxyEvent } from './event.js';
|
|
5
5
|
export type { IScriptingObjectProxyEvent, EventParam, DispatchEventParam, EventOptions, SubscribeParam, UnsubscribeParam, IEventManager, FilterCriteria, FilterOperator, } from './event.js';
|
|
6
6
|
export { Event } from './event.js';
|
|
7
|
+
export { hasFilterCriteria, isFilterOperator, matchesFilterCriteria, matchesFilterOperator, } from './filterCriteria.js';
|
|
8
|
+
export type { MatchesFilterCriteriaOptions } from './filterCriteria.js';
|
|
9
|
+
export { matchesGuestCapabilities, RESERVED_GUEST_CAPABILITIES, } from './guestCapabilities.js';
|
|
10
|
+
export type { GuestCapabilities, GuestCapabilityValue, } from './guestCapabilities.js';
|
|
7
11
|
export { ScriptingObject, isPublicFunction } from './scriptingObject.js';
|
|
8
12
|
export type { ScriptingObjects } from './scriptingObject.js';
|
|
9
13
|
export { MessageType } from './messageType.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|