@elliemae/microfe-common 2.28.3 → 2.28.5

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
@@ -21,6 +21,7 @@ __export(index_exports, {
21
21
  AuditThrottler: () => import_auditThrottler.AuditThrottler,
22
22
  Event: () => import_event2.Event,
23
23
  MessageType: () => import_messageType.MessageType,
24
+ OnDuplicate: () => import_scriptingObjectManager.OnDuplicate,
24
25
  ProxyEvent: () => import_event.ProxyEvent,
25
26
  RESERVED_GUEST_CAPABILITIES: () => import_guestCapabilities.RESERVED_GUEST_CAPABILITIES,
26
27
  Remoting: () => import_remoting.Remoting,
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var scriptingObjectManager_exports = {};
20
20
  __export(scriptingObjectManager_exports, {
21
21
  MODULE_OBJECT: () => MODULE_OBJECT,
22
+ OnDuplicate: () => OnDuplicate,
22
23
  ScriptingObjectManager: () => ScriptingObjectManager,
23
24
  SecurityContext: () => SecurityContext
24
25
  });
@@ -29,6 +30,11 @@ var SecurityContext = /* @__PURE__ */ ((SecurityContext2) => {
29
30
  SecurityContext2["PARTNER"] = "PARTNER";
30
31
  return SecurityContext2;
31
32
  })(SecurityContext || {});
33
+ var OnDuplicate = /* @__PURE__ */ ((OnDuplicate2) => {
34
+ OnDuplicate2["THROW"] = "throw";
35
+ OnDuplicate2["IGNORE"] = "ignore";
36
+ return OnDuplicate2;
37
+ })(OnDuplicate || {});
32
38
  class ScriptingObjectManager {
33
39
  #normalizeId = (id) => id.trim().toLowerCase();
34
40
  /**
@@ -40,18 +46,26 @@ class ScriptingObjectManager {
40
46
  */
41
47
  #guestScriptingObjects = /* @__PURE__ */ new Map();
42
48
  #addGuestScriptingObject = (params) => {
43
- const { so, guestId } = params;
49
+ const {
50
+ so,
51
+ guestId,
52
+ onDuplicate = "throw" /* THROW */,
53
+ securityContext
54
+ } = params;
44
55
  const objectId = this.#normalizeId(so.id);
56
+ const soInfo = { so, guestId, securityContext };
45
57
  const guestSOs = this.#guestScriptingObjects.get(guestId);
46
58
  if (!guestSOs) {
47
- this.#guestScriptingObjects.set(guestId, /* @__PURE__ */ new Map([[objectId, params]]));
48
- } else {
49
- if (guestSOs.has(objectId))
50
- throw new Error(
51
- `Scripting Object ${so.id} already exists for guest ${guestId}`
52
- );
53
- guestSOs.set(objectId, params);
59
+ this.#guestScriptingObjects.set(guestId, /* @__PURE__ */ new Map([[objectId, soInfo]]));
60
+ return;
54
61
  }
62
+ if (guestSOs.has(objectId)) {
63
+ if (onDuplicate === "ignore" /* IGNORE */) return;
64
+ throw new Error(
65
+ `Scripting Object ${so.id} already exists for guest ${guestId}`
66
+ );
67
+ }
68
+ guestSOs.set(objectId, soInfo);
55
69
  };
56
70
  #disposeSO = ({ so }) => {
57
71
  if (so._dispose && typeof so._dispose === "function") {
@@ -119,7 +133,11 @@ class ScriptingObjectManager {
119
133
  * @param params
120
134
  */
121
135
  addScriptingObject = (so, params) => {
122
- const { guestId } = params || {};
136
+ const {
137
+ guestId,
138
+ onDuplicate = "throw" /* THROW */,
139
+ securityContext
140
+ } = params || {};
123
141
  if (!so?.id || !so?._toJSON) {
124
142
  throw new Error("Object is not derived from ScriptingObject");
125
143
  }
@@ -128,12 +146,14 @@ class ScriptingObjectManager {
128
146
  throw new Error(`Guest id is required to add Module scripting object`);
129
147
  }
130
148
  if (guestId) {
131
- this.#addGuestScriptingObject({ so, ...params, guestId });
149
+ this.#addGuestScriptingObject({ so, ...params, guestId, onDuplicate });
132
150
  return;
133
151
  }
134
- if (this.#scriptingObjects.has(objectId))
152
+ if (this.#scriptingObjects.has(objectId)) {
153
+ if (onDuplicate === "ignore" /* IGNORE */) return;
135
154
  throw new Error(`Scripting Object ${so.id} already exists`);
136
- this.#scriptingObjects.set(objectId, { so, ...params });
155
+ }
156
+ this.#scriptingObjects.set(objectId, { so, guestId, securityContext });
137
157
  };
138
158
  /**
139
159
  * Get reference to the scripting object proxy for a guest
package/dist/esm/index.js CHANGED
@@ -15,7 +15,8 @@ import { ScriptingObject, isPublicFunction } from "./scriptingObject.js";
15
15
  import { MessageType } from "./messageType.js";
16
16
  import {
17
17
  ScriptingObjectManager,
18
- SecurityContext
18
+ SecurityContext,
19
+ OnDuplicate
19
20
  } from "./scriptingObjectManager.js";
20
21
  import { ScriptingObjectProxy, isScriptingObjectProxy } from "./proxy.js";
21
22
  import { AuditThrottler } from "./auditThrottler.js";
@@ -23,6 +24,7 @@ export {
23
24
  AuditThrottler,
24
25
  Event,
25
26
  MessageType,
27
+ OnDuplicate,
26
28
  ProxyEvent,
27
29
  RESERVED_GUEST_CAPABILITIES,
28
30
  Remoting,
@@ -4,6 +4,11 @@ var SecurityContext = /* @__PURE__ */ ((SecurityContext2) => {
4
4
  SecurityContext2["PARTNER"] = "PARTNER";
5
5
  return SecurityContext2;
6
6
  })(SecurityContext || {});
7
+ var OnDuplicate = /* @__PURE__ */ ((OnDuplicate2) => {
8
+ OnDuplicate2["THROW"] = "throw";
9
+ OnDuplicate2["IGNORE"] = "ignore";
10
+ return OnDuplicate2;
11
+ })(OnDuplicate || {});
7
12
  class ScriptingObjectManager {
8
13
  #normalizeId = (id) => id.trim().toLowerCase();
9
14
  /**
@@ -15,18 +20,26 @@ class ScriptingObjectManager {
15
20
  */
16
21
  #guestScriptingObjects = /* @__PURE__ */ new Map();
17
22
  #addGuestScriptingObject = (params) => {
18
- const { so, guestId } = params;
23
+ const {
24
+ so,
25
+ guestId,
26
+ onDuplicate = "throw" /* THROW */,
27
+ securityContext
28
+ } = params;
19
29
  const objectId = this.#normalizeId(so.id);
30
+ const soInfo = { so, guestId, securityContext };
20
31
  const guestSOs = this.#guestScriptingObjects.get(guestId);
21
32
  if (!guestSOs) {
22
- this.#guestScriptingObjects.set(guestId, /* @__PURE__ */ new Map([[objectId, params]]));
23
- } else {
24
- if (guestSOs.has(objectId))
25
- throw new Error(
26
- `Scripting Object ${so.id} already exists for guest ${guestId}`
27
- );
28
- guestSOs.set(objectId, params);
33
+ this.#guestScriptingObjects.set(guestId, /* @__PURE__ */ new Map([[objectId, soInfo]]));
34
+ return;
29
35
  }
36
+ if (guestSOs.has(objectId)) {
37
+ if (onDuplicate === "ignore" /* IGNORE */) return;
38
+ throw new Error(
39
+ `Scripting Object ${so.id} already exists for guest ${guestId}`
40
+ );
41
+ }
42
+ guestSOs.set(objectId, soInfo);
30
43
  };
31
44
  #disposeSO = ({ so }) => {
32
45
  if (so._dispose && typeof so._dispose === "function") {
@@ -94,7 +107,11 @@ class ScriptingObjectManager {
94
107
  * @param params
95
108
  */
96
109
  addScriptingObject = (so, params) => {
97
- const { guestId } = params || {};
110
+ const {
111
+ guestId,
112
+ onDuplicate = "throw" /* THROW */,
113
+ securityContext
114
+ } = params || {};
98
115
  if (!so?.id || !so?._toJSON) {
99
116
  throw new Error("Object is not derived from ScriptingObject");
100
117
  }
@@ -103,12 +120,14 @@ class ScriptingObjectManager {
103
120
  throw new Error(`Guest id is required to add Module scripting object`);
104
121
  }
105
122
  if (guestId) {
106
- this.#addGuestScriptingObject({ so, ...params, guestId });
123
+ this.#addGuestScriptingObject({ so, ...params, guestId, onDuplicate });
107
124
  return;
108
125
  }
109
- if (this.#scriptingObjects.has(objectId))
126
+ if (this.#scriptingObjects.has(objectId)) {
127
+ if (onDuplicate === "ignore" /* IGNORE */) return;
110
128
  throw new Error(`Scripting Object ${so.id} already exists`);
111
- this.#scriptingObjects.set(objectId, { so, ...params });
129
+ }
130
+ this.#scriptingObjects.set(objectId, { so, guestId, securityContext });
112
131
  };
113
132
  /**
114
133
  * Get reference to the scripting object proxy for a guest
@@ -178,6 +197,7 @@ class ScriptingObjectManager {
178
197
  }
179
198
  export {
180
199
  MODULE_OBJECT,
200
+ OnDuplicate,
181
201
  ScriptingObjectManager,
182
202
  SecurityContext
183
203
  };
@@ -13,7 +13,7 @@ export type { ScriptingObjects } from './scriptingObject.js';
13
13
  export { MessageType } from './messageType.js';
14
14
  export type { EventListeners, Listener } from './common.js';
15
15
  export type { ISSFGuest, ConnectParam } from './guest.js';
16
- export { ScriptingObjectManager, SecurityContext, } from './scriptingObjectManager.js';
16
+ export { ScriptingObjectManager, SecurityContext, OnDuplicate, } from './scriptingObjectManager.js';
17
17
  export type { AddScriptingObjectParams, CallContext, CallerInfo, GetObjectParams, GuestContext, } from './scriptingObjectManager.js';
18
18
  export { ScriptingObjectProxy, isScriptingObjectProxy } from './proxy.js';
19
19
  export { AuditThrottler } from './auditThrottler.js';
@@ -60,6 +60,15 @@ export declare enum SecurityContext {
60
60
  */
61
61
  PARTNER = "PARTNER"
62
62
  }
63
+ /**
64
+ * Behavior when registering a scripting object whose id already exists.
65
+ */
66
+ export declare enum OnDuplicate {
67
+ /** Throw an error (default). */
68
+ THROW = "throw",
69
+ /** Keep the existing registration and skip the new object. */
70
+ IGNORE = "ignore"
71
+ }
63
72
  /**
64
73
  * parameters to add scripting object
65
74
  */
@@ -72,6 +81,11 @@ export type AddScriptingObjectParams = {
72
81
  * security context under which the scripting object is available
73
82
  */
74
83
  securityContext?: SecurityContext;
84
+ /**
85
+ * How to handle duplicate scripting object ids.
86
+ * Defaults to {@link OnDuplicate.THROW}.
87
+ */
88
+ onDuplicate?: OnDuplicate;
75
89
  };
76
90
  /**
77
91
  * parameters to get scripting object