@elliemae/microfe-common 2.0.0-next.40 → 2.0.0-next.41
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
CHANGED
|
@@ -22,6 +22,7 @@ __export(lib_exports, {
|
|
|
22
22
|
MessageType: () => import_messageType.MessageType,
|
|
23
23
|
Remoting: () => import_remoting.Remoting,
|
|
24
24
|
ScriptingObject: () => import_scriptingObject.ScriptingObject,
|
|
25
|
+
ScriptingObjectManager: () => import_scriptingObjectManager.ScriptingObjectManager,
|
|
25
26
|
getEventId: () => import_event.getEventId,
|
|
26
27
|
sendMessage: () => import_remoting.sendMessage
|
|
27
28
|
});
|
|
@@ -31,3 +32,4 @@ var import_event = require("./event.js");
|
|
|
31
32
|
var import_event2 = require("./event.js");
|
|
32
33
|
var import_scriptingObject = require("./scriptingObject.js");
|
|
33
34
|
var import_messageType = require("./messageType.js");
|
|
35
|
+
var import_scriptingObjectManager = require("./scriptingObjectManager.js");
|
|
@@ -0,0 +1,239 @@
|
|
|
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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var __publicField = (obj, key, value) => {
|
|
21
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
|
+
return value;
|
|
23
|
+
};
|
|
24
|
+
var __accessCheck = (obj, member, msg) => {
|
|
25
|
+
if (!member.has(obj))
|
|
26
|
+
throw TypeError("Cannot " + msg);
|
|
27
|
+
};
|
|
28
|
+
var __privateGet = (obj, member, getter) => {
|
|
29
|
+
__accessCheck(obj, member, "read from private field");
|
|
30
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
31
|
+
};
|
|
32
|
+
var __privateAdd = (obj, member, value) => {
|
|
33
|
+
if (member.has(obj))
|
|
34
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
35
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
36
|
+
};
|
|
37
|
+
var scriptingObjectManager_exports = {};
|
|
38
|
+
__export(scriptingObjectManager_exports, {
|
|
39
|
+
ScriptingObjectManager: () => ScriptingObjectManager,
|
|
40
|
+
SecurityContext: () => SecurityContext
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(scriptingObjectManager_exports);
|
|
43
|
+
var _scriptingObjects, _guestScriptingObjects, _addGuestScriptingObject, _disposeSO, _getGuestScriptingObject, _removeGuestScriptingObject, _attachCallContext;
|
|
44
|
+
var SecurityContext = /* @__PURE__ */ ((SecurityContext2) => {
|
|
45
|
+
SecurityContext2["USER"] = "USER";
|
|
46
|
+
SecurityContext2["PARTNER"] = "PARTNER";
|
|
47
|
+
return SecurityContext2;
|
|
48
|
+
})(SecurityContext || {});
|
|
49
|
+
class ScriptingObjectManager {
|
|
50
|
+
constructor() {
|
|
51
|
+
/**
|
|
52
|
+
* collection of registered scripting objects
|
|
53
|
+
*/
|
|
54
|
+
__privateAdd(this, _scriptingObjects, /* @__PURE__ */ new Map());
|
|
55
|
+
/**
|
|
56
|
+
* collection of proxied scripting objects for each guest
|
|
57
|
+
*/
|
|
58
|
+
__privateAdd(this, _guestScriptingObjects, /* @__PURE__ */ new Map());
|
|
59
|
+
__privateAdd(this, _addGuestScriptingObject, (params) => {
|
|
60
|
+
const { so, guestId } = params;
|
|
61
|
+
const objectId = so.id.toLowerCase();
|
|
62
|
+
const guestSOs = __privateGet(this, _guestScriptingObjects).get(guestId);
|
|
63
|
+
if (!guestSOs) {
|
|
64
|
+
__privateGet(this, _guestScriptingObjects).set(guestId, /* @__PURE__ */ new Map([[objectId, params]]));
|
|
65
|
+
} else {
|
|
66
|
+
if (guestSOs.has(objectId))
|
|
67
|
+
throw new Error(
|
|
68
|
+
`Scripting Object ${so.id} already exists for guest ${guestId}`
|
|
69
|
+
);
|
|
70
|
+
guestSOs.set(objectId, params);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
__privateAdd(this, _disposeSO, ({ so }) => {
|
|
74
|
+
if (so._dispose && typeof so._dispose === "function") {
|
|
75
|
+
so._dispose();
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
__privateAdd(this, _getGuestScriptingObject, ({
|
|
79
|
+
objectId,
|
|
80
|
+
guestId
|
|
81
|
+
}) => {
|
|
82
|
+
const moduleSOs = __privateGet(this, _guestScriptingObjects).get(guestId);
|
|
83
|
+
if (moduleSOs) {
|
|
84
|
+
return moduleSOs.get(objectId) ?? null;
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
});
|
|
88
|
+
__privateAdd(this, _removeGuestScriptingObject, ({
|
|
89
|
+
objectId,
|
|
90
|
+
guestId
|
|
91
|
+
} = {}) => {
|
|
92
|
+
if (guestId) {
|
|
93
|
+
if (!objectId) {
|
|
94
|
+
const sosInfo = __privateGet(this, _guestScriptingObjects).get(guestId);
|
|
95
|
+
if (sosInfo) {
|
|
96
|
+
sosInfo.forEach(__privateGet(this, _disposeSO));
|
|
97
|
+
}
|
|
98
|
+
__privateGet(this, _guestScriptingObjects).delete(guestId);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const moduleSOs = __privateGet(this, _guestScriptingObjects).get(guestId);
|
|
102
|
+
if (moduleSOs) {
|
|
103
|
+
const soInfo = moduleSOs.get(objectId);
|
|
104
|
+
if (soInfo)
|
|
105
|
+
__privateGet(this, _disposeSO).call(this, soInfo);
|
|
106
|
+
moduleSOs.delete(objectId);
|
|
107
|
+
}
|
|
108
|
+
} else if (objectId) {
|
|
109
|
+
__privateGet(this, _guestScriptingObjects).forEach((moduleSOs) => {
|
|
110
|
+
const soInfo = moduleSOs.get(objectId);
|
|
111
|
+
if (soInfo)
|
|
112
|
+
__privateGet(this, _disposeSO).call(this, soInfo);
|
|
113
|
+
moduleSOs.delete(objectId);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
/**
|
|
118
|
+
* attach guest context to the scripting object methods
|
|
119
|
+
*
|
|
120
|
+
* @param root0
|
|
121
|
+
* @param root0.so
|
|
122
|
+
* @param root0.guest
|
|
123
|
+
* @returns proxies scripting object that has call context set to the guest
|
|
124
|
+
*/
|
|
125
|
+
__privateAdd(this, _attachCallContext, ({
|
|
126
|
+
so,
|
|
127
|
+
guest
|
|
128
|
+
}) => new Proxy(so, {
|
|
129
|
+
get(target, prop, receiver) {
|
|
130
|
+
const value = target[prop];
|
|
131
|
+
if (value instanceof Function && prop !== "constructor") {
|
|
132
|
+
return function(...args) {
|
|
133
|
+
const proxyRef = this;
|
|
134
|
+
Object.defineProperty(value, "callContext", {
|
|
135
|
+
value: guest,
|
|
136
|
+
enumerable: false,
|
|
137
|
+
writable: true
|
|
138
|
+
});
|
|
139
|
+
return value.apply(proxyRef === receiver ? target : proxyRef, args);
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return value;
|
|
143
|
+
}
|
|
144
|
+
}));
|
|
145
|
+
/**
|
|
146
|
+
* registers scripting object to the host
|
|
147
|
+
*
|
|
148
|
+
* @param so scripting object to register
|
|
149
|
+
* @param {AddScriptingObjectParams<ValueOf<AppObjects>>}
|
|
150
|
+
* @param params
|
|
151
|
+
*/
|
|
152
|
+
__publicField(this, "addScriptingObject", (so, params) => {
|
|
153
|
+
const { guestId } = params || {};
|
|
154
|
+
if (!so?.id || !so?._toJSON) {
|
|
155
|
+
throw new Error("Object is not derived from ScriptingObject");
|
|
156
|
+
}
|
|
157
|
+
const objectId = so.id.toLowerCase();
|
|
158
|
+
if (objectId === "module" && !guestId) {
|
|
159
|
+
throw new Error(`Guest id is required to add Module scripting object`);
|
|
160
|
+
}
|
|
161
|
+
if (guestId) {
|
|
162
|
+
__privateGet(this, _addGuestScriptingObject).call(this, { so, ...params, guestId });
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (__privateGet(this, _scriptingObjects).has(objectId))
|
|
166
|
+
throw new Error(`Scripting Object ${so.id} already exists`);
|
|
167
|
+
__privateGet(this, _scriptingObjects).set(objectId, { so, ...params });
|
|
168
|
+
});
|
|
169
|
+
/**
|
|
170
|
+
* Get reference to the scripting object proxy for a guest
|
|
171
|
+
*
|
|
172
|
+
* @param {string} objectId scripting object id
|
|
173
|
+
* @param {GuestContext} guest that is requesting the scripting object
|
|
174
|
+
* @returns proxied scripting object reference
|
|
175
|
+
*/
|
|
176
|
+
__publicField(this, "getObject", (objectId, guest) => {
|
|
177
|
+
const id = objectId.toLowerCase();
|
|
178
|
+
let soInfo = null;
|
|
179
|
+
if (guest?.id) {
|
|
180
|
+
soInfo = __privateGet(this, _getGuestScriptingObject).call(this, {
|
|
181
|
+
objectId: id,
|
|
182
|
+
guestId: guest.id
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
soInfo = soInfo ?? __privateGet(this, _scriptingObjects).get(id);
|
|
186
|
+
const { so } = soInfo || {};
|
|
187
|
+
if (!so)
|
|
188
|
+
return null;
|
|
189
|
+
if (!guest)
|
|
190
|
+
return so;
|
|
191
|
+
const guestSO = __privateGet(this, _attachCallContext).call(this, { so, guest });
|
|
192
|
+
Object.defineProperty(guestSO, "target", {
|
|
193
|
+
value: so,
|
|
194
|
+
enumerable: false,
|
|
195
|
+
configurable: false,
|
|
196
|
+
writable: true
|
|
197
|
+
});
|
|
198
|
+
return guestSO;
|
|
199
|
+
});
|
|
200
|
+
/**
|
|
201
|
+
* removes scripting object
|
|
202
|
+
*
|
|
203
|
+
* @param objectId unique id of the scripting object
|
|
204
|
+
* @param guestId unique id of the guest
|
|
205
|
+
*/
|
|
206
|
+
__publicField(this, "removeScriptingObject", (objectId, guestId) => {
|
|
207
|
+
const id = objectId.toLowerCase();
|
|
208
|
+
if (guestId) {
|
|
209
|
+
__privateGet(this, _removeGuestScriptingObject).call(this, { objectId: id, guestId });
|
|
210
|
+
} else {
|
|
211
|
+
__privateGet(this, _removeGuestScriptingObject).call(this, { objectId: id });
|
|
212
|
+
const soInfo = __privateGet(this, _scriptingObjects).get(id);
|
|
213
|
+
if (soInfo)
|
|
214
|
+
__privateGet(this, _disposeSO).call(this, soInfo);
|
|
215
|
+
__privateGet(this, _scriptingObjects).delete(id);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
/**
|
|
219
|
+
* removes all scripting objects
|
|
220
|
+
*
|
|
221
|
+
* @param guestId unique id of the guest
|
|
222
|
+
*/
|
|
223
|
+
__publicField(this, "removeAllScriptingObjects", (guestId) => {
|
|
224
|
+
if (!guestId) {
|
|
225
|
+
__privateGet(this, _scriptingObjects).forEach(__privateGet(this, _disposeSO));
|
|
226
|
+
__privateGet(this, _scriptingObjects).clear();
|
|
227
|
+
} else {
|
|
228
|
+
__privateGet(this, _removeGuestScriptingObject).call(this, { guestId });
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
_scriptingObjects = new WeakMap();
|
|
234
|
+
_guestScriptingObjects = new WeakMap();
|
|
235
|
+
_addGuestScriptingObject = new WeakMap();
|
|
236
|
+
_disposeSO = new WeakMap();
|
|
237
|
+
_getGuestScriptingObject = new WeakMap();
|
|
238
|
+
_removeGuestScriptingObject = new WeakMap();
|
|
239
|
+
_attachCallContext = new WeakMap();
|
package/dist/esm/index.js
CHANGED
|
@@ -3,11 +3,13 @@ import { getEventId } from "./event.js";
|
|
|
3
3
|
import { Event } from "./event.js";
|
|
4
4
|
import { ScriptingObject } from "./scriptingObject.js";
|
|
5
5
|
import { MessageType } from "./messageType.js";
|
|
6
|
+
import { ScriptingObjectManager } from "./scriptingObjectManager.js";
|
|
6
7
|
export {
|
|
7
8
|
Event,
|
|
8
9
|
MessageType,
|
|
9
10
|
Remoting,
|
|
10
11
|
ScriptingObject,
|
|
12
|
+
ScriptingObjectManager,
|
|
11
13
|
getEventId,
|
|
12
14
|
sendMessage
|
|
13
15
|
};
|
|
@@ -0,0 +1,220 @@
|
|
|
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 _scriptingObjects, _guestScriptingObjects, _addGuestScriptingObject, _disposeSO, _getGuestScriptingObject, _removeGuestScriptingObject, _attachCallContext;
|
|
21
|
+
var SecurityContext = /* @__PURE__ */ ((SecurityContext2) => {
|
|
22
|
+
SecurityContext2["USER"] = "USER";
|
|
23
|
+
SecurityContext2["PARTNER"] = "PARTNER";
|
|
24
|
+
return SecurityContext2;
|
|
25
|
+
})(SecurityContext || {});
|
|
26
|
+
class ScriptingObjectManager {
|
|
27
|
+
constructor() {
|
|
28
|
+
/**
|
|
29
|
+
* collection of registered scripting objects
|
|
30
|
+
*/
|
|
31
|
+
__privateAdd(this, _scriptingObjects, /* @__PURE__ */ new Map());
|
|
32
|
+
/**
|
|
33
|
+
* collection of proxied scripting objects for each guest
|
|
34
|
+
*/
|
|
35
|
+
__privateAdd(this, _guestScriptingObjects, /* @__PURE__ */ new Map());
|
|
36
|
+
__privateAdd(this, _addGuestScriptingObject, (params) => {
|
|
37
|
+
const { so, guestId } = params;
|
|
38
|
+
const objectId = so.id.toLowerCase();
|
|
39
|
+
const guestSOs = __privateGet(this, _guestScriptingObjects).get(guestId);
|
|
40
|
+
if (!guestSOs) {
|
|
41
|
+
__privateGet(this, _guestScriptingObjects).set(guestId, /* @__PURE__ */ new Map([[objectId, params]]));
|
|
42
|
+
} else {
|
|
43
|
+
if (guestSOs.has(objectId))
|
|
44
|
+
throw new Error(
|
|
45
|
+
`Scripting Object ${so.id} already exists for guest ${guestId}`
|
|
46
|
+
);
|
|
47
|
+
guestSOs.set(objectId, params);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
__privateAdd(this, _disposeSO, ({ so }) => {
|
|
51
|
+
if (so._dispose && typeof so._dispose === "function") {
|
|
52
|
+
so._dispose();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
__privateAdd(this, _getGuestScriptingObject, ({
|
|
56
|
+
objectId,
|
|
57
|
+
guestId
|
|
58
|
+
}) => {
|
|
59
|
+
const moduleSOs = __privateGet(this, _guestScriptingObjects).get(guestId);
|
|
60
|
+
if (moduleSOs) {
|
|
61
|
+
return moduleSOs.get(objectId) ?? null;
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
});
|
|
65
|
+
__privateAdd(this, _removeGuestScriptingObject, ({
|
|
66
|
+
objectId,
|
|
67
|
+
guestId
|
|
68
|
+
} = {}) => {
|
|
69
|
+
if (guestId) {
|
|
70
|
+
if (!objectId) {
|
|
71
|
+
const sosInfo = __privateGet(this, _guestScriptingObjects).get(guestId);
|
|
72
|
+
if (sosInfo) {
|
|
73
|
+
sosInfo.forEach(__privateGet(this, _disposeSO));
|
|
74
|
+
}
|
|
75
|
+
__privateGet(this, _guestScriptingObjects).delete(guestId);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const moduleSOs = __privateGet(this, _guestScriptingObjects).get(guestId);
|
|
79
|
+
if (moduleSOs) {
|
|
80
|
+
const soInfo = moduleSOs.get(objectId);
|
|
81
|
+
if (soInfo)
|
|
82
|
+
__privateGet(this, _disposeSO).call(this, soInfo);
|
|
83
|
+
moduleSOs.delete(objectId);
|
|
84
|
+
}
|
|
85
|
+
} else if (objectId) {
|
|
86
|
+
__privateGet(this, _guestScriptingObjects).forEach((moduleSOs) => {
|
|
87
|
+
const soInfo = moduleSOs.get(objectId);
|
|
88
|
+
if (soInfo)
|
|
89
|
+
__privateGet(this, _disposeSO).call(this, soInfo);
|
|
90
|
+
moduleSOs.delete(objectId);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
/**
|
|
95
|
+
* attach guest context to the scripting object methods
|
|
96
|
+
*
|
|
97
|
+
* @param root0
|
|
98
|
+
* @param root0.so
|
|
99
|
+
* @param root0.guest
|
|
100
|
+
* @returns proxies scripting object that has call context set to the guest
|
|
101
|
+
*/
|
|
102
|
+
__privateAdd(this, _attachCallContext, ({
|
|
103
|
+
so,
|
|
104
|
+
guest
|
|
105
|
+
}) => new Proxy(so, {
|
|
106
|
+
get(target, prop, receiver) {
|
|
107
|
+
const value = target[prop];
|
|
108
|
+
if (value instanceof Function && prop !== "constructor") {
|
|
109
|
+
return function(...args) {
|
|
110
|
+
const proxyRef = this;
|
|
111
|
+
Object.defineProperty(value, "callContext", {
|
|
112
|
+
value: guest,
|
|
113
|
+
enumerable: false,
|
|
114
|
+
writable: true
|
|
115
|
+
});
|
|
116
|
+
return value.apply(proxyRef === receiver ? target : proxyRef, args);
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
return value;
|
|
120
|
+
}
|
|
121
|
+
}));
|
|
122
|
+
/**
|
|
123
|
+
* registers scripting object to the host
|
|
124
|
+
*
|
|
125
|
+
* @param so scripting object to register
|
|
126
|
+
* @param {AddScriptingObjectParams<ValueOf<AppObjects>>}
|
|
127
|
+
* @param params
|
|
128
|
+
*/
|
|
129
|
+
__publicField(this, "addScriptingObject", (so, params) => {
|
|
130
|
+
const { guestId } = params || {};
|
|
131
|
+
if (!so?.id || !so?._toJSON) {
|
|
132
|
+
throw new Error("Object is not derived from ScriptingObject");
|
|
133
|
+
}
|
|
134
|
+
const objectId = so.id.toLowerCase();
|
|
135
|
+
if (objectId === "module" && !guestId) {
|
|
136
|
+
throw new Error(`Guest id is required to add Module scripting object`);
|
|
137
|
+
}
|
|
138
|
+
if (guestId) {
|
|
139
|
+
__privateGet(this, _addGuestScriptingObject).call(this, { so, ...params, guestId });
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (__privateGet(this, _scriptingObjects).has(objectId))
|
|
143
|
+
throw new Error(`Scripting Object ${so.id} already exists`);
|
|
144
|
+
__privateGet(this, _scriptingObjects).set(objectId, { so, ...params });
|
|
145
|
+
});
|
|
146
|
+
/**
|
|
147
|
+
* Get reference to the scripting object proxy for a guest
|
|
148
|
+
*
|
|
149
|
+
* @param {string} objectId scripting object id
|
|
150
|
+
* @param {GuestContext} guest that is requesting the scripting object
|
|
151
|
+
* @returns proxied scripting object reference
|
|
152
|
+
*/
|
|
153
|
+
__publicField(this, "getObject", (objectId, guest) => {
|
|
154
|
+
const id = objectId.toLowerCase();
|
|
155
|
+
let soInfo = null;
|
|
156
|
+
if (guest?.id) {
|
|
157
|
+
soInfo = __privateGet(this, _getGuestScriptingObject).call(this, {
|
|
158
|
+
objectId: id,
|
|
159
|
+
guestId: guest.id
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
soInfo = soInfo ?? __privateGet(this, _scriptingObjects).get(id);
|
|
163
|
+
const { so } = soInfo || {};
|
|
164
|
+
if (!so)
|
|
165
|
+
return null;
|
|
166
|
+
if (!guest)
|
|
167
|
+
return so;
|
|
168
|
+
const guestSO = __privateGet(this, _attachCallContext).call(this, { so, guest });
|
|
169
|
+
Object.defineProperty(guestSO, "target", {
|
|
170
|
+
value: so,
|
|
171
|
+
enumerable: false,
|
|
172
|
+
configurable: false,
|
|
173
|
+
writable: true
|
|
174
|
+
});
|
|
175
|
+
return guestSO;
|
|
176
|
+
});
|
|
177
|
+
/**
|
|
178
|
+
* removes scripting object
|
|
179
|
+
*
|
|
180
|
+
* @param objectId unique id of the scripting object
|
|
181
|
+
* @param guestId unique id of the guest
|
|
182
|
+
*/
|
|
183
|
+
__publicField(this, "removeScriptingObject", (objectId, guestId) => {
|
|
184
|
+
const id = objectId.toLowerCase();
|
|
185
|
+
if (guestId) {
|
|
186
|
+
__privateGet(this, _removeGuestScriptingObject).call(this, { objectId: id, guestId });
|
|
187
|
+
} else {
|
|
188
|
+
__privateGet(this, _removeGuestScriptingObject).call(this, { objectId: id });
|
|
189
|
+
const soInfo = __privateGet(this, _scriptingObjects).get(id);
|
|
190
|
+
if (soInfo)
|
|
191
|
+
__privateGet(this, _disposeSO).call(this, soInfo);
|
|
192
|
+
__privateGet(this, _scriptingObjects).delete(id);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
/**
|
|
196
|
+
* removes all scripting objects
|
|
197
|
+
*
|
|
198
|
+
* @param guestId unique id of the guest
|
|
199
|
+
*/
|
|
200
|
+
__publicField(this, "removeAllScriptingObjects", (guestId) => {
|
|
201
|
+
if (!guestId) {
|
|
202
|
+
__privateGet(this, _scriptingObjects).forEach(__privateGet(this, _disposeSO));
|
|
203
|
+
__privateGet(this, _scriptingObjects).clear();
|
|
204
|
+
} else {
|
|
205
|
+
__privateGet(this, _removeGuestScriptingObject).call(this, { guestId });
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
_scriptingObjects = new WeakMap();
|
|
211
|
+
_guestScriptingObjects = new WeakMap();
|
|
212
|
+
_addGuestScriptingObject = new WeakMap();
|
|
213
|
+
_disposeSO = new WeakMap();
|
|
214
|
+
_getGuestScriptingObject = new WeakMap();
|
|
215
|
+
_removeGuestScriptingObject = new WeakMap();
|
|
216
|
+
_attachCallContext = new WeakMap();
|
|
217
|
+
export {
|
|
218
|
+
ScriptingObjectManager,
|
|
219
|
+
SecurityContext
|
|
220
|
+
};
|
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 {};
|