@sonisoft/now-sdk-ext-core 6.18.3 → 6.18.4
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.
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ServiceNowInstance } from "../../sn/ServiceNowInstance.js";
|
|
2
2
|
import { ServiceNowRequest } from "./ServiceNowRequest.js";
|
|
3
3
|
/**
|
|
4
|
-
* Singleton registry of authenticated ServiceNowRequest instances keyed by instance alias
|
|
4
|
+
* Singleton registry of authenticated ServiceNowRequest instances keyed by instance alias (or host), plus the
|
|
5
|
+
* instance's elevated roles when it has any: an elevated session is a separate server session.
|
|
5
6
|
* Ensures all components sharing the same alias reuse the same HTTP session.
|
|
6
7
|
*/
|
|
7
8
|
export declare class SessionManager {
|
|
@@ -15,7 +16,7 @@ export declare class SessionManager {
|
|
|
15
16
|
static resetInstance(): void;
|
|
16
17
|
/**
|
|
17
18
|
* Get or create a ServiceNowRequest for this instance.
|
|
18
|
-
* Keyed by alias (falls back to host).
|
|
19
|
+
* Keyed by alias (falls back to host) and elevated roles.
|
|
19
20
|
*/
|
|
20
21
|
getRequest(instance: ServiceNowInstance): ServiceNowRequest;
|
|
21
22
|
/**
|
|
@@ -34,7 +35,7 @@ export declare class SessionManager {
|
|
|
34
35
|
*/
|
|
35
36
|
getAuthenticatedRequest(instance: ServiceNowInstance): Promise<ServiceNowRequest>;
|
|
36
37
|
/**
|
|
37
|
-
* Remove cached
|
|
38
|
+
* Remove the cached sessions of an alias (or host): the plain one and every elevated one.
|
|
38
39
|
*/
|
|
39
40
|
clearSession(alias: string): void;
|
|
40
41
|
/**
|
|
@@ -42,7 +43,8 @@ export declare class SessionManager {
|
|
|
42
43
|
*/
|
|
43
44
|
clearAll(): void;
|
|
44
45
|
/**
|
|
45
|
-
* Check if a session exists for a
|
|
46
|
+
* Check if a session exists under a key: the alias (or host) for a plain session; an elevated
|
|
47
|
+
* session's key is `alias#elevated:<roles, sorted, comma-separated>`.
|
|
46
48
|
*/
|
|
47
49
|
hasSession(alias: string): boolean;
|
|
48
50
|
private getKey;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { ServiceNowRequest } from "./ServiceNowRequest.js";
|
|
2
2
|
import { Logger } from "../../util/Logger.js";
|
|
3
|
+
/** Separates an elevated session's key from its alias: `dev#elevated:security_admin`. */
|
|
4
|
+
const ELEVATED_KEY = '#elevated:';
|
|
3
5
|
/**
|
|
4
|
-
* Singleton registry of authenticated ServiceNowRequest instances keyed by instance alias
|
|
6
|
+
* Singleton registry of authenticated ServiceNowRequest instances keyed by instance alias (or host), plus the
|
|
7
|
+
* instance's elevated roles when it has any: an elevated session is a separate server session.
|
|
5
8
|
* Ensures all components sharing the same alias reuse the same HTTP session.
|
|
6
9
|
*/
|
|
7
10
|
export class SessionManager {
|
|
@@ -22,12 +25,12 @@ export class SessionManager {
|
|
|
22
25
|
}
|
|
23
26
|
/**
|
|
24
27
|
* Get or create a ServiceNowRequest for this instance.
|
|
25
|
-
* Keyed by alias (falls back to host).
|
|
28
|
+
* Keyed by alias (falls back to host) and elevated roles.
|
|
26
29
|
*/
|
|
27
30
|
getRequest(instance) {
|
|
28
31
|
const key = this.getKey(instance);
|
|
29
32
|
let request = this._sessions.get(key);
|
|
30
|
-
// The key is alias-or-host, which says nothing about *which* ServiceNowInstance
|
|
33
|
+
// The key is alias-or-host (and elevation), which says nothing about *which* ServiceNowInstance
|
|
31
34
|
// object asked. A consumer that rebuilds its connection — now-sdk-ext-mcp evicts
|
|
32
35
|
// on a 30-minute TTL — passes a new instance under the same alias and would
|
|
33
36
|
// otherwise be handed the previous one's request, still holding the previous
|
|
@@ -102,14 +105,19 @@ export class SessionManager {
|
|
|
102
105
|
return authPromise;
|
|
103
106
|
}
|
|
104
107
|
/**
|
|
105
|
-
* Remove cached
|
|
108
|
+
* Remove the cached sessions of an alias (or host): the plain one and every elevated one.
|
|
106
109
|
*/
|
|
107
110
|
clearSession(alias) {
|
|
108
111
|
this._logger.debug(`Clearing session for alias: ${alias}`);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
112
|
+
// The alias's elevated sessions go with it: they log in with the same credentials.
|
|
113
|
+
const keys = [...new Set([...this._sessions.keys(), ...this._authPromises.keys()])]
|
|
114
|
+
.filter(key => key === alias || key.startsWith(`${alias}${ELEVATED_KEY}`));
|
|
115
|
+
for (const key of keys) {
|
|
116
|
+
this._sessions.delete(key);
|
|
117
|
+
// An auth started before the clear would otherwise resolve after it and hand
|
|
118
|
+
// the caller the request we just evicted.
|
|
119
|
+
this._authPromises.delete(key);
|
|
120
|
+
}
|
|
113
121
|
}
|
|
114
122
|
/**
|
|
115
123
|
* Remove all cached sessions.
|
|
@@ -120,7 +128,8 @@ export class SessionManager {
|
|
|
120
128
|
this._authPromises.clear();
|
|
121
129
|
}
|
|
122
130
|
/**
|
|
123
|
-
* Check if a session exists for a
|
|
131
|
+
* Check if a session exists under a key: the alias (or host) for a plain session; an elevated
|
|
132
|
+
* session's key is `alias#elevated:<roles, sorted, comma-separated>`.
|
|
124
133
|
*/
|
|
125
134
|
hasSession(alias) {
|
|
126
135
|
return this._sessions.has(alias);
|
|
@@ -130,7 +139,14 @@ export class SessionManager {
|
|
|
130
139
|
if (!key) {
|
|
131
140
|
throw new Error("ServiceNowInstance must have an alias or host to identify the session");
|
|
132
141
|
}
|
|
133
|
-
|
|
142
|
+
// The marker would let a plain instance's key equal an elevated one's.
|
|
143
|
+
if (key.includes(ELEVATED_KEY)) {
|
|
144
|
+
throw new Error(`ServiceNowInstance alias or host may not contain "${ELEVATED_KEY}"`);
|
|
145
|
+
}
|
|
146
|
+
// An elevated session is a different server session: a long-lived consumer (now-sdk-ext-mcp) keeps a plain
|
|
147
|
+
// and an elevated instance for one alias side by side, and neither may replace the other's session.
|
|
148
|
+
const elevated = instance.elevatedRoles ?? [];
|
|
149
|
+
return elevated.length ? `${key}${ELEVATED_KEY}${[...elevated].sort().join(',')}` : key;
|
|
134
150
|
}
|
|
135
151
|
}
|
|
136
152
|
//# sourceMappingURL=SessionManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SessionManager.js","sourceRoot":"","sources":["../../../src/comm/http/SessionManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C
|
|
1
|
+
{"version":3,"file":"SessionManager.js","sourceRoot":"","sources":["../../../src/comm/http/SessionManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,yFAAyF;AACzF,MAAM,YAAY,GAAG,YAAY,CAAC;AAElC;;;;GAIG;AACH,MAAM,OAAO,cAAc;IAEf,MAAM,CAAC,SAAS,GAA0B,IAAI,CAAC;IAC/C,SAAS,GAAmC,IAAI,GAAG,EAAE,CAAC;IACtD,aAAa,GAA4C,IAAI,GAAG,EAAE,CAAC;IACnE,OAAO,GAAW,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAEvD,gBAAuB,CAAC;IAExB,MAAM,CAAC,WAAW;QACd,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,CAAC;YAC5B,cAAc,CAAC,SAAS,GAAG,IAAI,cAAc,EAAE,CAAC;QACpD,CAAC;QACD,OAAO,cAAc,CAAC,SAAS,CAAC;IACpC,CAAC;IAED,sEAAsE;IACtE,MAAM,CAAC,aAAa;QAChB,cAAc,CAAC,SAAS,GAAG,IAAI,CAAC;IACpC,CAAC;IAED;;;OAGG;IACH,UAAU,CAAC,QAA4B;QACnC,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAClC,IAAI,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;Q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C;QAC9C,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,YAAY,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;IAC5F,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sonisoft/now-sdk-ext-core",
|
|
3
|
-
"version": "6.18.
|
|
3
|
+
"version": "6.18.4",
|
|
4
4
|
"description": "Comprehensive TypeScript library extending ServiceNow SDK with application management, ATF testing, real-time log monitoring, AMB event subscriptions, and automation tools",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"servicenow",
|