@elliemae/microfe-common 2.0.0-next.40 → 2.0.0-next.42
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/index.js +2 -0
- package/dist/cjs/remoting.js +279 -317
- package/dist/cjs/scriptingObject.js +47 -73
- package/dist/cjs/scriptingObjectManager.js +211 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/remoting.js +279 -318
- package/dist/esm/scriptingObject.js +47 -74
- package/dist/esm/scriptingObjectManager.js +191 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/scriptingObjectManager.d.ts +97 -0
- package/package.json +4 -4
|
@@ -1,32 +1,15 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => {
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
7
|
-
var __accessCheck = (obj, member, msg) => {
|
|
8
|
-
if (!member.has(obj))
|
|
9
|
-
throw TypeError("Cannot " + msg);
|
|
10
|
-
};
|
|
11
|
-
var __privateGet = (obj, member, getter) => {
|
|
12
|
-
__accessCheck(obj, member, "read from private field");
|
|
13
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
14
|
-
};
|
|
15
|
-
var __privateAdd = (obj, member, value) => {
|
|
16
|
-
if (member.has(obj))
|
|
17
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
18
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
19
|
-
};
|
|
20
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
21
|
-
__accessCheck(obj, member, "write to private field");
|
|
22
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
23
|
-
return value;
|
|
24
|
-
};
|
|
25
|
-
var _id, _objectType;
|
|
26
1
|
import { isEvent } from "./event.js";
|
|
27
2
|
const FUNCTION = "function";
|
|
28
3
|
const isPublicFunction = (value, fnName) => typeof value === FUNCTION && !!fnName && !fnName.startsWith("_");
|
|
29
4
|
class ScriptingObject {
|
|
5
|
+
/**
|
|
6
|
+
* unique id of the scripting object
|
|
7
|
+
*/
|
|
8
|
+
#id;
|
|
9
|
+
/**
|
|
10
|
+
* type of the scripting object
|
|
11
|
+
*/
|
|
12
|
+
#objectType = "Object";
|
|
30
13
|
/**
|
|
31
14
|
* Creates an instance of ScriptingObject.
|
|
32
15
|
*
|
|
@@ -34,67 +17,57 @@ class ScriptingObject {
|
|
|
34
17
|
* @param objectType type of the scripting object
|
|
35
18
|
*/
|
|
36
19
|
constructor(objectId, objectType) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
*/
|
|
40
|
-
__privateAdd(this, _id, void 0);
|
|
41
|
-
/**
|
|
42
|
-
* type of the scripting object
|
|
43
|
-
*/
|
|
44
|
-
__privateAdd(this, _objectType, "Object");
|
|
45
|
-
/**
|
|
46
|
-
* transform the scripting object to a format suitable for transmitting over window.postMessage
|
|
47
|
-
*
|
|
48
|
-
* @returns marshalled scripting object
|
|
49
|
-
*/
|
|
50
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
51
|
-
__publicField(this, "_toJSON", () => {
|
|
52
|
-
const functions = [];
|
|
53
|
-
const events = [];
|
|
54
|
-
Object.keys(this).forEach((property) => {
|
|
55
|
-
const value = this[property];
|
|
56
|
-
if (isEvent(value)) {
|
|
57
|
-
events.push(property);
|
|
58
|
-
} else if (isPublicFunction(value, property)) {
|
|
59
|
-
functions.push(property);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
return {
|
|
63
|
-
objectId: __privateGet(this, _id),
|
|
64
|
-
objectType: __privateGet(this, _objectType),
|
|
65
|
-
functions,
|
|
66
|
-
events
|
|
67
|
-
};
|
|
68
|
-
});
|
|
69
|
-
/**
|
|
70
|
-
* dispose the scripting object
|
|
71
|
-
*/
|
|
72
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
73
|
-
__publicField(this, "_dispose", () => {
|
|
74
|
-
});
|
|
75
|
-
/**
|
|
76
|
-
* dispose the scripting object
|
|
77
|
-
*/
|
|
78
|
-
__publicField(this, "dispose", () => {
|
|
79
|
-
});
|
|
80
|
-
__privateSet(this, _id, objectId);
|
|
81
|
-
__privateSet(this, _objectType, objectType || __privateGet(this, _objectType));
|
|
20
|
+
this.#id = objectId;
|
|
21
|
+
this.#objectType = objectType || this.#objectType;
|
|
82
22
|
}
|
|
83
23
|
/**
|
|
84
24
|
* get unique id of the scripting object
|
|
85
25
|
*/
|
|
86
26
|
get id() {
|
|
87
|
-
return
|
|
27
|
+
return this.#id;
|
|
88
28
|
}
|
|
89
29
|
/**
|
|
90
30
|
* get type of the scripting object
|
|
91
31
|
*/
|
|
92
32
|
get objectType() {
|
|
93
|
-
return
|
|
33
|
+
return this.#objectType;
|
|
94
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* transform the scripting object to a format suitable for transmitting over window.postMessage
|
|
37
|
+
*
|
|
38
|
+
* @returns marshalled scripting object
|
|
39
|
+
*/
|
|
40
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
41
|
+
_toJSON = () => {
|
|
42
|
+
const functions = [];
|
|
43
|
+
const events = [];
|
|
44
|
+
Object.keys(this).forEach((property) => {
|
|
45
|
+
const value = this[property];
|
|
46
|
+
if (isEvent(value)) {
|
|
47
|
+
events.push(property);
|
|
48
|
+
} else if (isPublicFunction(value, property)) {
|
|
49
|
+
functions.push(property);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return {
|
|
53
|
+
objectId: this.#id,
|
|
54
|
+
objectType: this.#objectType,
|
|
55
|
+
functions,
|
|
56
|
+
events
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* dispose the scripting object
|
|
61
|
+
*/
|
|
62
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
63
|
+
_dispose = () => {
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* dispose the scripting object
|
|
67
|
+
*/
|
|
68
|
+
dispose = () => {
|
|
69
|
+
};
|
|
95
70
|
}
|
|
96
|
-
_id = new WeakMap();
|
|
97
|
-
_objectType = new WeakMap();
|
|
98
71
|
export {
|
|
99
72
|
ScriptingObject
|
|
100
73
|
};
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
var SecurityContext = /* @__PURE__ */ ((SecurityContext2) => {
|
|
2
|
+
SecurityContext2["USER"] = "USER";
|
|
3
|
+
SecurityContext2["PARTNER"] = "PARTNER";
|
|
4
|
+
return SecurityContext2;
|
|
5
|
+
})(SecurityContext || {});
|
|
6
|
+
class ScriptingObjectManager {
|
|
7
|
+
/**
|
|
8
|
+
* collection of registered scripting objects
|
|
9
|
+
*/
|
|
10
|
+
#scriptingObjects = /* @__PURE__ */ new Map();
|
|
11
|
+
/**
|
|
12
|
+
* collection of proxied scripting objects for each guest
|
|
13
|
+
*/
|
|
14
|
+
#guestScriptingObjects = /* @__PURE__ */ new Map();
|
|
15
|
+
#addGuestScriptingObject = (params) => {
|
|
16
|
+
const { so, guestId } = params;
|
|
17
|
+
const objectId = so.id.toLowerCase();
|
|
18
|
+
const guestSOs = this.#guestScriptingObjects.get(guestId);
|
|
19
|
+
if (!guestSOs) {
|
|
20
|
+
this.#guestScriptingObjects.set(guestId, /* @__PURE__ */ new Map([[objectId, params]]));
|
|
21
|
+
} else {
|
|
22
|
+
if (guestSOs.has(objectId))
|
|
23
|
+
throw new Error(
|
|
24
|
+
`Scripting Object ${so.id} already exists for guest ${guestId}`
|
|
25
|
+
);
|
|
26
|
+
guestSOs.set(objectId, params);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
#disposeSO = ({ so }) => {
|
|
30
|
+
if (so._dispose && typeof so._dispose === "function") {
|
|
31
|
+
so._dispose();
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
#getGuestScriptingObject = ({
|
|
35
|
+
objectId,
|
|
36
|
+
guestId
|
|
37
|
+
}) => {
|
|
38
|
+
const moduleSOs = this.#guestScriptingObjects.get(guestId);
|
|
39
|
+
if (moduleSOs) {
|
|
40
|
+
return moduleSOs.get(objectId) ?? null;
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
};
|
|
44
|
+
#removeGuestScriptingObject = ({
|
|
45
|
+
objectId,
|
|
46
|
+
guestId
|
|
47
|
+
} = {}) => {
|
|
48
|
+
if (guestId) {
|
|
49
|
+
if (!objectId) {
|
|
50
|
+
const sosInfo = this.#guestScriptingObjects.get(guestId);
|
|
51
|
+
if (sosInfo) {
|
|
52
|
+
sosInfo.forEach(this.#disposeSO);
|
|
53
|
+
}
|
|
54
|
+
this.#guestScriptingObjects.delete(guestId);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const moduleSOs = this.#guestScriptingObjects.get(guestId);
|
|
58
|
+
if (moduleSOs) {
|
|
59
|
+
const soInfo = moduleSOs.get(objectId);
|
|
60
|
+
if (soInfo)
|
|
61
|
+
this.#disposeSO(soInfo);
|
|
62
|
+
moduleSOs.delete(objectId);
|
|
63
|
+
}
|
|
64
|
+
} else if (objectId) {
|
|
65
|
+
this.#guestScriptingObjects.forEach((moduleSOs) => {
|
|
66
|
+
const soInfo = moduleSOs.get(objectId);
|
|
67
|
+
if (soInfo)
|
|
68
|
+
this.#disposeSO(soInfo);
|
|
69
|
+
moduleSOs.delete(objectId);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* attach guest context to the scripting object methods
|
|
75
|
+
*
|
|
76
|
+
* @param root0
|
|
77
|
+
* @param root0.so
|
|
78
|
+
* @param root0.guest
|
|
79
|
+
* @returns proxies scripting object that has call context set to the guest
|
|
80
|
+
*/
|
|
81
|
+
#attachCallContext = ({
|
|
82
|
+
so,
|
|
83
|
+
guest
|
|
84
|
+
}) => new Proxy(so, {
|
|
85
|
+
get(target, prop, receiver) {
|
|
86
|
+
const value = target[prop];
|
|
87
|
+
if (value instanceof Function && prop !== "constructor") {
|
|
88
|
+
return function(...args) {
|
|
89
|
+
const proxyRef = this;
|
|
90
|
+
Object.defineProperty(value, "callContext", {
|
|
91
|
+
value: guest,
|
|
92
|
+
enumerable: false,
|
|
93
|
+
writable: true
|
|
94
|
+
});
|
|
95
|
+
return value.apply(proxyRef === receiver ? target : proxyRef, args);
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
/**
|
|
102
|
+
* registers scripting object to the host
|
|
103
|
+
*
|
|
104
|
+
* @param so scripting object to register
|
|
105
|
+
* @param {AddScriptingObjectParams<ValueOf<AppObjects>>}
|
|
106
|
+
* @param params
|
|
107
|
+
*/
|
|
108
|
+
addScriptingObject = (so, params) => {
|
|
109
|
+
const { guestId } = params || {};
|
|
110
|
+
if (!so?.id || !so?._toJSON) {
|
|
111
|
+
throw new Error("Object is not derived from ScriptingObject");
|
|
112
|
+
}
|
|
113
|
+
const objectId = so.id.toLowerCase();
|
|
114
|
+
if (objectId === "module" && !guestId) {
|
|
115
|
+
throw new Error(`Guest id is required to add Module scripting object`);
|
|
116
|
+
}
|
|
117
|
+
if (guestId) {
|
|
118
|
+
this.#addGuestScriptingObject({ so, ...params, guestId });
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (this.#scriptingObjects.has(objectId))
|
|
122
|
+
throw new Error(`Scripting Object ${so.id} already exists`);
|
|
123
|
+
this.#scriptingObjects.set(objectId, { so, ...params });
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Get reference to the scripting object proxy for a guest
|
|
127
|
+
*
|
|
128
|
+
* @param {string} objectId scripting object id
|
|
129
|
+
* @param {GuestContext} guest that is requesting the scripting object
|
|
130
|
+
* @returns proxied scripting object reference
|
|
131
|
+
*/
|
|
132
|
+
getObject = (objectId, guest) => {
|
|
133
|
+
const id = objectId.toLowerCase();
|
|
134
|
+
let soInfo = null;
|
|
135
|
+
if (guest?.id) {
|
|
136
|
+
soInfo = this.#getGuestScriptingObject({
|
|
137
|
+
objectId: id,
|
|
138
|
+
guestId: guest.id
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
soInfo = soInfo ?? this.#scriptingObjects.get(id);
|
|
142
|
+
const { so } = soInfo || {};
|
|
143
|
+
if (!so)
|
|
144
|
+
return null;
|
|
145
|
+
if (!guest)
|
|
146
|
+
return so;
|
|
147
|
+
const guestSO = this.#attachCallContext({ so, guest });
|
|
148
|
+
Object.defineProperty(guestSO, "target", {
|
|
149
|
+
value: so,
|
|
150
|
+
enumerable: false,
|
|
151
|
+
configurable: false,
|
|
152
|
+
writable: true
|
|
153
|
+
});
|
|
154
|
+
return guestSO;
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* removes scripting object
|
|
158
|
+
*
|
|
159
|
+
* @param objectId unique id of the scripting object
|
|
160
|
+
* @param guestId unique id of the guest
|
|
161
|
+
*/
|
|
162
|
+
removeScriptingObject = (objectId, guestId) => {
|
|
163
|
+
const id = objectId.toLowerCase();
|
|
164
|
+
if (guestId) {
|
|
165
|
+
this.#removeGuestScriptingObject({ objectId: id, guestId });
|
|
166
|
+
} else {
|
|
167
|
+
this.#removeGuestScriptingObject({ objectId: id });
|
|
168
|
+
const soInfo = this.#scriptingObjects.get(id);
|
|
169
|
+
if (soInfo)
|
|
170
|
+
this.#disposeSO(soInfo);
|
|
171
|
+
this.#scriptingObjects.delete(id);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* removes all scripting objects
|
|
176
|
+
*
|
|
177
|
+
* @param guestId unique id of the guest
|
|
178
|
+
*/
|
|
179
|
+
removeAllScriptingObjects = (guestId) => {
|
|
180
|
+
if (!guestId) {
|
|
181
|
+
this.#scriptingObjects.forEach(this.#disposeSO);
|
|
182
|
+
this.#scriptingObjects.clear();
|
|
183
|
+
} else {
|
|
184
|
+
this.#removeGuestScriptingObject({ guestId });
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
export {
|
|
189
|
+
ScriptingObjectManager,
|
|
190
|
+
SecurityContext
|
|
191
|
+
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -8,3 +8,5 @@ export { ScriptingObject } from './scriptingObject.js';
|
|
|
8
8
|
export { MessageType } from './messageType.js';
|
|
9
9
|
export type { EventListeners, Listener } from './common.js';
|
|
10
10
|
export type { ISSFGuest, ConnectParam, SubscribeParam as GuestSubscribeParam, UnsubscribeParam as GuestUnsubscribeParam, } from './guest.js';
|
|
11
|
+
export { ScriptingObjectManager } from './scriptingObjectManager.js';
|
|
12
|
+
export type { AddScriptingObjectParams, GetObjectParams, GuestContext, } from './scriptingObjectManager.js';
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ScriptingObjectTypes, IScriptingObject } from '@elliemae/pui-scripting-object';
|
|
2
|
+
type ValueOf<T> = T[keyof T];
|
|
3
|
+
/**
|
|
4
|
+
* collection of scripting objects
|
|
5
|
+
*/
|
|
6
|
+
export type ScriptingObjects = Record<string, IScriptingObject>;
|
|
7
|
+
/**
|
|
8
|
+
* information about the guest
|
|
9
|
+
*/
|
|
10
|
+
export type GuestContext = {
|
|
11
|
+
/**
|
|
12
|
+
* unique id of the guest application
|
|
13
|
+
*/
|
|
14
|
+
id: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* security context under which the guest application is running
|
|
18
|
+
*/
|
|
19
|
+
export declare enum SecurityContext {
|
|
20
|
+
/**
|
|
21
|
+
* application is using the same security context as the host
|
|
22
|
+
*/
|
|
23
|
+
USER = "USER",
|
|
24
|
+
/**
|
|
25
|
+
* application is using the partner security context
|
|
26
|
+
*/
|
|
27
|
+
PARTNER = "PARTNER"
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* parameters to add scripting object
|
|
31
|
+
*/
|
|
32
|
+
export type AddScriptingObjectParams = {
|
|
33
|
+
/**
|
|
34
|
+
* limit scripting object only to the specified guest
|
|
35
|
+
*/
|
|
36
|
+
guestId?: string;
|
|
37
|
+
/**
|
|
38
|
+
* security context under which the scripting object is available
|
|
39
|
+
*/
|
|
40
|
+
securityContext?: SecurityContext;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* parameters to get scripting object
|
|
44
|
+
*/
|
|
45
|
+
export type GetObjectParams = {
|
|
46
|
+
guest: GuestContext;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* scripting object details
|
|
50
|
+
*/
|
|
51
|
+
export type SOInfo<Objects extends ScriptingObjects> = {
|
|
52
|
+
/**
|
|
53
|
+
* scripting object to add
|
|
54
|
+
*/
|
|
55
|
+
so: ValueOf<Objects>;
|
|
56
|
+
/**
|
|
57
|
+
* limit scripting object only to the specified guest
|
|
58
|
+
*/
|
|
59
|
+
guestId?: string;
|
|
60
|
+
/**
|
|
61
|
+
* security context under which the scripting object is available
|
|
62
|
+
*/
|
|
63
|
+
securityContext?: SecurityContext;
|
|
64
|
+
};
|
|
65
|
+
export declare class ScriptingObjectManager<AppObjects extends ScriptingObjects = Partial<ScriptingObjectTypes>> {
|
|
66
|
+
#private;
|
|
67
|
+
/**
|
|
68
|
+
* registers scripting object to the host
|
|
69
|
+
*
|
|
70
|
+
* @param so scripting object to register
|
|
71
|
+
* @param {AddScriptingObjectParams<ValueOf<AppObjects>>}
|
|
72
|
+
* @param params
|
|
73
|
+
*/
|
|
74
|
+
addScriptingObject: <SO extends ValueOf<AppObjects>>(so: SO, params?: AddScriptingObjectParams) => void;
|
|
75
|
+
/**
|
|
76
|
+
* Get reference to the scripting object proxy for a guest
|
|
77
|
+
*
|
|
78
|
+
* @param {string} objectId scripting object id
|
|
79
|
+
* @param {GuestContext} guest that is requesting the scripting object
|
|
80
|
+
* @returns proxied scripting object reference
|
|
81
|
+
*/
|
|
82
|
+
getObject: <ObjectId extends Extract<keyof AppObjects, string>>(objectId: ObjectId, guest?: GuestContext) => AppObjects[ObjectId] | null;
|
|
83
|
+
/**
|
|
84
|
+
* removes scripting object
|
|
85
|
+
*
|
|
86
|
+
* @param objectId unique id of the scripting object
|
|
87
|
+
* @param guestId unique id of the guest
|
|
88
|
+
*/
|
|
89
|
+
removeScriptingObject: (objectId: Extract<keyof AppObjects, string>, guestId?: string) => void;
|
|
90
|
+
/**
|
|
91
|
+
* removes all scripting objects
|
|
92
|
+
*
|
|
93
|
+
* @param guestId unique id of the guest
|
|
94
|
+
*/
|
|
95
|
+
removeAllScriptingObjects: (guestId?: string) => void;
|
|
96
|
+
}
|
|
97
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/microfe-common",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.42",
|
|
4
4
|
"description": "common micro frontend functional modules",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"uuid": "~9.0.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@elliemae/browserslist-config-elliemae-latest-browsers": "~1.
|
|
41
|
-
"@elliemae/pui-diagnostics": "~3.
|
|
42
|
-
"@elliemae/pui-scripting-object": "~1.
|
|
40
|
+
"@elliemae/browserslist-config-elliemae-latest-browsers": "~1.7.0",
|
|
41
|
+
"@elliemae/pui-diagnostics": "~3.2.0",
|
|
42
|
+
"@elliemae/pui-scripting-object": "~1.20.0",
|
|
43
43
|
"@types/uuid": "~9.0.1"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|