@sonisoft/now-sdk-ext-core 5.1.0 → 5.3.0
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/auth/NowSDKAuthenticationHandler.js +17 -3
- package/dist/auth/NowSDKAuthenticationHandler.js.map +1 -1
- package/dist/comm/http/IRequestHandler.d.ts +20 -1
- package/dist/comm/http/RequestHandler.d.ts +31 -1
- package/dist/comm/http/RequestHandler.js +90 -5
- package/dist/comm/http/RequestHandler.js.map +1 -1
- package/dist/comm/http/ServiceNowRequest.d.ts +2 -0
- package/dist/comm/http/ServiceNowRequest.js +9 -0
- package/dist/comm/http/ServiceNowRequest.js.map +1 -1
- package/dist/comm/http/SessionManager.d.ts +10 -0
- package/dist/comm/http/SessionManager.js +43 -1
- package/dist/comm/http/SessionManager.js.map +1 -1
- package/dist/exception/StaleInstanceError.d.ts +50 -0
- package/dist/exception/StaleInstanceError.js +63 -0
- package/dist/exception/StaleInstanceError.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/sn/BackgroundScriptExecutor.js +4 -1
- package/dist/sn/BackgroundScriptExecutor.js.map +1 -1
- package/dist/sn/IServiceNowInstance.d.ts +10 -0
- package/dist/sn/OperationProgress.d.ts +63 -0
- package/dist/sn/OperationProgress.js +69 -0
- package/dist/sn/OperationProgress.js.map +1 -0
- package/dist/sn/SNRequestBase.d.ts +13 -0
- package/dist/sn/SNRequestBase.js +17 -0
- package/dist/sn/SNRequestBase.js.map +1 -1
- package/dist/sn/ServiceNowInstance.d.ts +9 -0
- package/dist/sn/ServiceNowInstance.js +25 -0
- package/dist/sn/ServiceNowInstance.js.map +1 -1
- package/dist/sn/application/AppRepoApplication.d.ts +3 -2
- package/dist/sn/application/AppRepoApplication.js +9 -5
- package/dist/sn/application/AppRepoApplication.js.map +1 -1
- package/dist/sn/application/ApplicationManager.d.ts +3 -2
- package/dist/sn/application/ApplicationManager.js +9 -5
- package/dist/sn/application/ApplicationManager.js.map +1 -1
- package/dist/sn/atf/ATFTestExecutor.d.ts +4 -3
- package/dist/sn/atf/ATFTestExecutor.js +9 -5
- package/dist/sn/atf/ATFTestExecutor.js.map +1 -1
- package/dist/util/Logger.d.ts +13 -0
- package/dist/util/Logger.js +30 -1
- package/dist/util/Logger.js.map +1 -1
- package/dist/util/redact.d.ts +47 -0
- package/dist/util/redact.js +228 -0
- package/dist/util/redact.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Logger } from "../util/Logger.js";
|
|
2
2
|
import { getSafeUserSession } from "@servicenow/sdk-cli-core/dist/util/sessionToken.js";
|
|
3
|
+
import { stripSecretsFromError } from "../util/redact.js";
|
|
3
4
|
export class NowSDKAuthenticationHandler {
|
|
4
5
|
_requestHandler;
|
|
5
6
|
_isLoggedIn = false;
|
|
@@ -20,7 +21,16 @@ export class NowSDKAuthenticationHandler {
|
|
|
20
21
|
const auth = { credentials: this._instance.credential };
|
|
21
22
|
const session = await getSafeUserSession(auth, this._logger);
|
|
22
23
|
if (session) {
|
|
23
|
-
this
|
|
24
|
+
// Recording WHICH instance this session was minted for is the whole
|
|
25
|
+
// point: RequestHandler compares it against the instance it is bound to
|
|
26
|
+
// before every dispatch, which is where a mismatch is actually caught.
|
|
27
|
+
//
|
|
28
|
+
// There is deliberately no re-check of this._instance across the await.
|
|
29
|
+
// It is assigned once in the constructor and never reassigned, and
|
|
30
|
+
// AuthenticationHandlerFactory builds a fresh handler per instance, so
|
|
31
|
+
// such a check could not fire — it would only imply a protection that
|
|
32
|
+
// does not exist here.
|
|
33
|
+
this._requestHandler.setSession(session, this._instance);
|
|
24
34
|
this.setLoggedIn(true);
|
|
25
35
|
}
|
|
26
36
|
else {
|
|
@@ -30,8 +40,12 @@ export class NowSDKAuthenticationHandler {
|
|
|
30
40
|
return session;
|
|
31
41
|
}
|
|
32
42
|
catch (e) {
|
|
33
|
-
|
|
34
|
-
|
|
43
|
+
// Of every error in the codebase this is the one most likely to be carrying
|
|
44
|
+
// the credential it just failed to use, and it propagates out to consumers
|
|
45
|
+
// whose loggers have no redaction format of their own.
|
|
46
|
+
const safe = stripSecretsFromError(e);
|
|
47
|
+
this._logger.error("Error during login.", safe);
|
|
48
|
+
throw safe;
|
|
35
49
|
}
|
|
36
50
|
return null;
|
|
37
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NowSDKAuthenticationHandler.js","sourceRoot":"","sources":["../../src/auth/NowSDKAuthenticationHandler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAKxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,oDAAoD,CAAC;
|
|
1
|
+
{"version":3,"file":"NowSDKAuthenticationHandler.js","sourceRoot":"","sources":["../../src/auth/NowSDKAuthenticationHandler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAKxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,oDAAoD,CAAC;AACxF,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAGvD,MAAM,OAAO,2BAA2B;IAE5B,eAAe,CAAiB;IAEhC,WAAW,GAAW,KAAK,CAAC;IAE5B,QAAQ,CAAS;IAEjB,OAAO,CAAQ;IAEf,SAAS,CAAoB;IAErC,YAAmB,QAA2B;QAC1C,IAAI,CAAC,OAAO,GAAG,IAAI,MAAM,CAAC,6BAA6B,CAAC,CAAC;QACzD,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC9B,CAAC;IAEM,KAAK,CAAC,OAAO;QAChB,MAAM,OAAO,GAAY,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QAC5C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QAExB,OAAO,OAAO,CAAC;IACnB,CAAC;IAEO,KAAK,CAAC,KAAK;QAEf,IAAG,CAAC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AQ;QACX,6DAA6D;QAC7D,OAAQ,IAAI,CAAC,QAAgB,CAAC,QAAQ,EAAY,CAAC;IACvD,CAAC;IAEM,UAAU;QACb,kGAAkG;QAClG,OAAQ,IAAI,CAAC,QAAgB,CAAC,UAAU,EAAE,CAAC;IAC/C,CAAC;IAEM,UAAU;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;CACJ"}
|
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
import { HTTPRequest } from "./HTTPRequest.js";
|
|
2
2
|
import { IHttpResponse } from "./IHttpResponse.js";
|
|
3
|
+
import { IServiceNowInstance } from "../../sn/IServiceNowInstance.js";
|
|
3
4
|
export interface IRequestHandler {
|
|
4
5
|
post<T>(request: HTTPRequest): Promise<IHttpResponse<T>>;
|
|
5
6
|
put<T>(request: HTTPRequest): Promise<IHttpResponse<T>>;
|
|
6
7
|
get<T>(request: HTTPRequest): Promise<IHttpResponse<T>>;
|
|
7
8
|
delete<T>(request: HTTPRequest): Promise<IHttpResponse<T>>;
|
|
8
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Records the session to use for outgoing requests, together with the instance
|
|
11
|
+
* it was minted for.
|
|
12
|
+
*
|
|
13
|
+
* `instance` is optional so existing callers keep compiling, but omitting it
|
|
14
|
+
* disables the cross-instance guard for this handler — pass it wherever the
|
|
15
|
+
* owning instance is known.
|
|
16
|
+
*/
|
|
17
|
+
setSession(session: any, instance?: IServiceNowInstance): any;
|
|
18
|
+
/**
|
|
19
|
+
* Declares which instance this handler serves. Set once, at construction.
|
|
20
|
+
* A session recorded for any other instance will be refused at dispatch.
|
|
21
|
+
*
|
|
22
|
+
* Optional so that adding it is not a breaking change for anyone implementing
|
|
23
|
+
* this interface outside the repo. A handler that does not implement it simply
|
|
24
|
+
* has no bound identity, and the dispatch guard stays permissive — the same
|
|
25
|
+
* behaviour as a handler built without an instance.
|
|
26
|
+
*/
|
|
27
|
+
bindInstance?(instance: IServiceNowInstance): any;
|
|
9
28
|
}
|
|
@@ -5,18 +5,48 @@ import { Cookie } from 'tough-cookie';
|
|
|
5
5
|
import { ICookieStore } from './ICookieStore.js';
|
|
6
6
|
import { IAuthenticationHandler } from '../../auth/IAuthenticationHandler.js';
|
|
7
7
|
import { Logger } from '../../util/Logger.js';
|
|
8
|
+
import { IServiceNowInstance } from '../../sn/IServiceNowInstance.js';
|
|
8
9
|
export declare class RequestHandler implements IRequestHandler {
|
|
9
10
|
_logger: Logger;
|
|
10
11
|
_cookies: Cookie[];
|
|
11
12
|
_cookieStore: ICookieStore;
|
|
12
13
|
_authHandler: IAuthenticationHandler;
|
|
13
14
|
_session: any;
|
|
15
|
+
/** Identity of the instance this handler serves. Set once, at construction. */
|
|
16
|
+
private _boundInstanceId;
|
|
17
|
+
/** Identity of the instance the current `_session` was minted for. Written with the session. */
|
|
18
|
+
private _sessionInstanceId;
|
|
14
19
|
/**
|
|
15
20
|
* The Singleton's constructor should always be private to prevent direct
|
|
16
21
|
* construction calls with the `new` operator.
|
|
17
22
|
*/
|
|
18
23
|
constructor(authHandler: IAuthenticationHandler);
|
|
19
|
-
setSession(session: any): void;
|
|
24
|
+
setSession(session: any, instance?: IServiceNowInstance): void;
|
|
25
|
+
bindInstance(instance: IServiceNowInstance): void;
|
|
26
|
+
/**
|
|
27
|
+
* Refuses to build a request whose session belongs to a different instance.
|
|
28
|
+
*
|
|
29
|
+
* Placed immediately before `this._session` is read into the outgoing config,
|
|
30
|
+
* because that is the one point every request passes through — both the
|
|
31
|
+
* SessionManager-managed handlers and the ~21 managers that construct their own
|
|
32
|
+
* ServiceNowRequest and never touch SessionManager at all.
|
|
33
|
+
*
|
|
34
|
+
* Permissive when either side is unknown. A handler built without an instance
|
|
35
|
+
* (ATFTestExecutor does this, then immediately replaces it) or a session set by
|
|
36
|
+
* a caller that predates the second parameter would otherwise start throwing on
|
|
37
|
+
* a path that was never actually unsafe.
|
|
38
|
+
*/
|
|
39
|
+
/**
|
|
40
|
+
* Prepares a caught value for rethrowing.
|
|
41
|
+
*
|
|
42
|
+
* The original error is preserved rather than wrapped: `new Error(ex)` stringified
|
|
43
|
+
* the cause, discarded the stack, and flattened typed errors so `instanceof` failed
|
|
44
|
+
* at every call site — which would make StaleInstanceError unidentifiable. Secrets
|
|
45
|
+
* are stripped first, because the consumer's logger has no redaction format of its
|
|
46
|
+
* own.
|
|
47
|
+
*/
|
|
48
|
+
private toThrowable;
|
|
49
|
+
private assertSessionMatchesBoundInstance;
|
|
20
50
|
isValidXmlString(xmlString: any): boolean;
|
|
21
51
|
private doRequest;
|
|
22
52
|
post<T>(request: HTTPRequest): Promise<IHttpResponse<T>>;
|
|
@@ -2,6 +2,8 @@ import { HttpResponse } from './HttpResponse.js';
|
|
|
2
2
|
import { Logger } from '../../util/Logger.js';
|
|
3
3
|
import { makeRequest } from "@servicenow/sdk-cli-core/dist/http/index.js";
|
|
4
4
|
import { DOMParser } from '@xmldom/xmldom';
|
|
5
|
+
import { StaleInstanceError } from '../../exception/StaleInstanceError.js';
|
|
6
|
+
import { stripSecretsFromError, redactValue } from '../../util/redact.js';
|
|
5
7
|
//axios.defaults.withCredentials = true;
|
|
6
8
|
export class RequestHandler {
|
|
7
9
|
_logger = new Logger("RequestHandler");
|
|
@@ -11,6 +13,10 @@ export class RequestHandler {
|
|
|
11
13
|
_cookieStore;
|
|
12
14
|
_authHandler;
|
|
13
15
|
_session;
|
|
16
|
+
/** Identity of the instance this handler serves. Set once, at construction. */
|
|
17
|
+
_boundInstanceId;
|
|
18
|
+
/** Identity of the instance the current `_session` was minted for. Written with the session. */
|
|
19
|
+
_sessionInstanceId;
|
|
14
20
|
/**
|
|
15
21
|
* The Singleton's constructor should always be private to prevent direct
|
|
16
22
|
* construction calls with the `new` operator.
|
|
@@ -27,8 +33,83 @@ export class RequestHandler {
|
|
|
27
33
|
// });
|
|
28
34
|
// this.httpClient.defaults.maxRedirects = 0;
|
|
29
35
|
}
|
|
30
|
-
setSession(session) {
|
|
36
|
+
setSession(session, instance) {
|
|
37
|
+
const previous = this._sessionInstanceId;
|
|
31
38
|
this._session = session;
|
|
39
|
+
// Deliberately reset to undefined when no instance is supplied: the session
|
|
40
|
+
// changed and we no longer know whose it is, so the guard must go permissive
|
|
41
|
+
// rather than keep asserting against the previous owner's id.
|
|
42
|
+
this._sessionInstanceId = instance?.getInstanceId?.();
|
|
43
|
+
// Going from known to unknown silently disables the cross-instance guard for
|
|
44
|
+
// this handler. `instance` is optional and easy to forget, so say so out loud
|
|
45
|
+
// rather than only at debug level from inside the assertion.
|
|
46
|
+
if (previous !== undefined && this._sessionInstanceId === undefined) {
|
|
47
|
+
this._logger.warn("Session replaced without an owning instance; the cross-instance guard is now inactive for this handler.", { previousSessionInstanceId: previous });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
bindInstance(instance) {
|
|
51
|
+
this._boundInstanceId = instance?.getInstanceId?.();
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Refuses to build a request whose session belongs to a different instance.
|
|
55
|
+
*
|
|
56
|
+
* Placed immediately before `this._session` is read into the outgoing config,
|
|
57
|
+
* because that is the one point every request passes through — both the
|
|
58
|
+
* SessionManager-managed handlers and the ~21 managers that construct their own
|
|
59
|
+
* ServiceNowRequest and never touch SessionManager at all.
|
|
60
|
+
*
|
|
61
|
+
* Permissive when either side is unknown. A handler built without an instance
|
|
62
|
+
* (ATFTestExecutor does this, then immediately replaces it) or a session set by
|
|
63
|
+
* a caller that predates the second parameter would otherwise start throwing on
|
|
64
|
+
* a path that was never actually unsafe.
|
|
65
|
+
*/
|
|
66
|
+
/**
|
|
67
|
+
* Prepares a caught value for rethrowing.
|
|
68
|
+
*
|
|
69
|
+
* The original error is preserved rather than wrapped: `new Error(ex)` stringified
|
|
70
|
+
* the cause, discarded the stack, and flattened typed errors so `instanceof` failed
|
|
71
|
+
* at every call site — which would make StaleInstanceError unidentifiable. Secrets
|
|
72
|
+
* are stripped first, because the consumer's logger has no redaction format of its
|
|
73
|
+
* own.
|
|
74
|
+
*/
|
|
75
|
+
toThrowable(ex) {
|
|
76
|
+
if (ex instanceof Error) {
|
|
77
|
+
return stripSecretsFromError(ex);
|
|
78
|
+
}
|
|
79
|
+
// A thrown non-Error still has to be described, and String() on an object
|
|
80
|
+
// yields "[object Object]" — useless in a log. Redact before serializing,
|
|
81
|
+
// since a thrown plain object can carry credentials just as easily.
|
|
82
|
+
if (typeof ex === "string") {
|
|
83
|
+
return new Error(ex);
|
|
84
|
+
}
|
|
85
|
+
// `Object.prototype.toString.call` is typed as returning `any`; the cast keeps
|
|
86
|
+
// the type-checked lint rules satisfied without loosening anything real.
|
|
87
|
+
const fallback = Object.prototype.toString.call(ex);
|
|
88
|
+
let described;
|
|
89
|
+
try {
|
|
90
|
+
described = JSON.stringify(redactValue(ex)) ?? fallback;
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// Cycles and throwing getters are already handled inside redactValue, but
|
|
94
|
+
// a hostile toJSON can still break stringify.
|
|
95
|
+
described = fallback;
|
|
96
|
+
}
|
|
97
|
+
return new Error(described);
|
|
98
|
+
}
|
|
99
|
+
assertSessionMatchesBoundInstance() {
|
|
100
|
+
const bound = this._boundInstanceId;
|
|
101
|
+
const forSession = this._sessionInstanceId;
|
|
102
|
+
if (bound === undefined || forSession === undefined) {
|
|
103
|
+
this._logger.debug("Instance binding not asserted; identity unknown on one side.", {
|
|
104
|
+
boundInstanceId: bound,
|
|
105
|
+
sessionInstanceId: forSession,
|
|
106
|
+
});
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (bound !== forSession) {
|
|
110
|
+
throw new StaleInstanceError(`Refusing to send a request for instance #${bound} using a session minted for instance #${forSession}.`, "The connection was replaced while this request was in flight. Retry the operation; " +
|
|
111
|
+
"a fresh session will be established for the correct instance.");
|
|
112
|
+
}
|
|
32
113
|
}
|
|
33
114
|
// public async request(config:AxiosRequestConfig):Promise<AxiosResponse<any,any>>{
|
|
34
115
|
// for(var prop in this._defaultHeaders){
|
|
@@ -147,7 +228,7 @@ export class RequestHandler {
|
|
|
147
228
|
}
|
|
148
229
|
catch (ex) {
|
|
149
230
|
this._logger.error("Error during POST request.", { error: ex, response: response, request: request });
|
|
150
|
-
throw
|
|
231
|
+
throw this.toThrowable(ex);
|
|
151
232
|
}
|
|
152
233
|
}
|
|
153
234
|
async put(request) {
|
|
@@ -169,7 +250,7 @@ export class RequestHandler {
|
|
|
169
250
|
}
|
|
170
251
|
catch (ex) {
|
|
171
252
|
this._logger.error("Error during PUT request.", { error: ex, response: response, request: request });
|
|
172
|
-
throw
|
|
253
|
+
throw this.toThrowable(ex);
|
|
173
254
|
}
|
|
174
255
|
}
|
|
175
256
|
async get(request) {
|
|
@@ -191,7 +272,7 @@ export class RequestHandler {
|
|
|
191
272
|
}
|
|
192
273
|
catch (ex) {
|
|
193
274
|
this._logger.error("Error during GET request.", { error: ex, response: response, request: request });
|
|
194
|
-
throw
|
|
275
|
+
throw this.toThrowable(ex);
|
|
195
276
|
}
|
|
196
277
|
}
|
|
197
278
|
async delete(request) {
|
|
@@ -212,10 +293,14 @@ export class RequestHandler {
|
|
|
212
293
|
}
|
|
213
294
|
catch (ex) {
|
|
214
295
|
this._logger.error("Error during DELETE request.", { error: ex, response: response, request: request });
|
|
215
|
-
throw
|
|
296
|
+
throw this.toThrowable(ex);
|
|
216
297
|
}
|
|
217
298
|
}
|
|
218
299
|
async getRequestConfig(request) {
|
|
300
|
+
// Before the session is bound into the request. makeRequest derives the
|
|
301
|
+
// destination host from auth.instanceUrl, so a mismatch here does not send a
|
|
302
|
+
// bad cookie to the right host — it sends a valid session to the wrong one.
|
|
303
|
+
this.assertSessionMatchesBoundInstance();
|
|
219
304
|
const config = {
|
|
220
305
|
auth: this._session,
|
|
221
306
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequestHandler.js","sourceRoot":"","sources":["../../../src/comm/http/RequestHandler.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAA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AAI,GAAG,OAAO,CAAC,IAAI,CAAC;QAC/B,CAAC;QAED,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;QAC9B,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAEjC,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QAC3B,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAE/B,OAAO,EAAC,MAAM,EAAE,MAAM,EAAC,CAAC;IAC5B,CAAC;IAEO,cAAc,CAAC,QAAe;QAElC,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;QAGrC,KAAI,MAAM,IAAI,IAAI,QAAQ,EAAC,CAAC;YACxB,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;QACrC,CAAC;QAED,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAC;QAAA,CAAC;IAC9B,CAAC;CAKJ"}
|
|
@@ -8,6 +8,8 @@ export declare class ServiceNowRequest {
|
|
|
8
8
|
auth: IAuthenticationHandler;
|
|
9
9
|
private _instance;
|
|
10
10
|
constructor(instance?: ServiceNowInstance);
|
|
11
|
+
/** The instance this request is bound to. Fixed at construction. */
|
|
12
|
+
getInstance(): ServiceNowInstance;
|
|
11
13
|
executeRequest<T>(request: HTTPRequest): Promise<IHttpResponse<T>>;
|
|
12
14
|
put<T>(request: HTTPRequest): Promise<IHttpResponse<T>>;
|
|
13
15
|
post<T>(request: HTTPRequest): Promise<IHttpResponse<T>>;
|
|
@@ -12,6 +12,15 @@ export class ServiceNowRequest {
|
|
|
12
12
|
this.auth = AuthenticationHandlerFactory.createAuthHandler(this._instance);
|
|
13
13
|
this._requestHandler = RequestHandlerFactory.createRequestHandler(this.auth);
|
|
14
14
|
this.auth.setRequestHandler(this._requestHandler);
|
|
15
|
+
// Declare which instance this handler serves, so a session minted for any
|
|
16
|
+
// other instance is refused before it reaches the wire.
|
|
17
|
+
if (this._instance) {
|
|
18
|
+
this._requestHandler.bindInstance?.(this._instance);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** The instance this request is bound to. Fixed at construction. */
|
|
22
|
+
getInstance() {
|
|
23
|
+
return this._instance;
|
|
15
24
|
}
|
|
16
25
|
async executeRequest(request) {
|
|
17
26
|
let httpMethod = request.method;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceNowRequest.js","sourceRoot":"","sources":["../../../src/comm/http/ServiceNowRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAC;AAMvF,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAGhE,MAAM,OAAO,iBAAiB;IAE1B,eAAe,CAAiB;IAChC,IAAI,CAAwB;IAEpB,SAAS,CAAoB;IAErC,YAAmB,WAA8B,IAAI;QAClD,qCAAqC;QAEpC,IAAI,QAAQ,EAAE,CAAC;YACX,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC9B,CAAC;QAED,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC,iBAAiB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC3E,IAAI,CAAC,eAAe,GAAG,qBAAqB,CAAC,oBAAoB,CAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9E,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"ServiceNowRequest.js","sourceRoot":"","sources":["../../../src/comm/http/ServiceNowRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAC;AAMvF,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAGhE,MAAM,OAAO,iBAAiB;IAE1B,eAAe,CAAiB;IAChC,IAAI,CAAwB;IAEpB,SAAS,CAAoB;IAErC,YAA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C/B,CAAC;IACL,CAAC;IAGO,KAAK,CAAC,cAAc;QAGxB,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;IAG9B,CAAC;IAED,UAAU;QACN,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,UAAU,EAAE,CAAC;IACvC,CAAC;IAEM,OAAO;QACV,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;CAEJ"}
|
|
@@ -18,6 +18,16 @@ export declare class SessionManager {
|
|
|
18
18
|
* Keyed by alias (falls back to host).
|
|
19
19
|
*/
|
|
20
20
|
getRequest(instance: ServiceNowInstance): ServiceNowRequest;
|
|
21
|
+
/**
|
|
22
|
+
* True when the cached request was built for exactly this instance.
|
|
23
|
+
*
|
|
24
|
+
* Answers "leave the cache alone" whenever identity cannot be established on
|
|
25
|
+
* either side — a request built without an instance, or a caller passing a
|
|
26
|
+
* duck-typed instance that predates getInstanceId(). Evicting on unknown
|
|
27
|
+
* identity would throw away a good session and force a fresh login on every
|
|
28
|
+
* single lookup, which is a worse failure than the one being guarded against.
|
|
29
|
+
*/
|
|
30
|
+
private isBoundTo;
|
|
21
31
|
/**
|
|
22
32
|
* Get or create a ServiceNowRequest and ensure it is authenticated.
|
|
23
33
|
* Uses an in-flight promise guard to prevent duplicate concurrent auth calls.
|
|
@@ -27,6 +27,17 @@ export class SessionManager {
|
|
|
27
27
|
getRequest(instance) {
|
|
28
28
|
const key = this.getKey(instance);
|
|
29
29
|
let request = this._sessions.get(key);
|
|
30
|
+
// The key is alias-or-host, which says nothing about *which* ServiceNowInstance
|
|
31
|
+
// object asked. A consumer that rebuilds its connection — now-sdk-ext-mcp evicts
|
|
32
|
+
// on a 30-minute TTL — passes a new instance under the same alias and would
|
|
33
|
+
// otherwise be handed the previous one's request, still holding the previous
|
|
34
|
+
// session. Recreate instead: this is recoverable, so self-heal rather than throw.
|
|
35
|
+
if (request && !this.isBoundTo(request, instance)) {
|
|
36
|
+
this._logger.debug(`Instance replaced for alias: ${key}; discarding the cached session.`);
|
|
37
|
+
this._sessions.delete(key);
|
|
38
|
+
this._authPromises.delete(key);
|
|
39
|
+
request = undefined;
|
|
40
|
+
}
|
|
30
41
|
if (!request) {
|
|
31
42
|
this._logger.debug(`Creating new session for alias: ${key}`);
|
|
32
43
|
request = new ServiceNowRequest(instance);
|
|
@@ -34,6 +45,27 @@ export class SessionManager {
|
|
|
34
45
|
}
|
|
35
46
|
return request;
|
|
36
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* True when the cached request was built for exactly this instance.
|
|
50
|
+
*
|
|
51
|
+
* Answers "leave the cache alone" whenever identity cannot be established on
|
|
52
|
+
* either side — a request built without an instance, or a caller passing a
|
|
53
|
+
* duck-typed instance that predates getInstanceId(). Evicting on unknown
|
|
54
|
+
* identity would throw away a good session and force a fresh login on every
|
|
55
|
+
* single lookup, which is a worse failure than the one being guarded against.
|
|
56
|
+
*/
|
|
57
|
+
isBoundTo(request, instance) {
|
|
58
|
+
const bound = request.getInstance?.();
|
|
59
|
+
if (!bound) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
const boundId = bound.getInstanceId?.();
|
|
63
|
+
const requestedId = instance?.getInstanceId?.();
|
|
64
|
+
if (boundId === undefined || requestedId === undefined) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
return boundId === requestedId;
|
|
68
|
+
}
|
|
37
69
|
/**
|
|
38
70
|
* Get or create a ServiceNowRequest and ensure it is authenticated.
|
|
39
71
|
* Uses an in-flight promise guard to prevent duplicate concurrent auth calls.
|
|
@@ -56,7 +88,13 @@ export class SessionManager {
|
|
|
56
88
|
return request;
|
|
57
89
|
}
|
|
58
90
|
finally {
|
|
59
|
-
this
|
|
91
|
+
// Only clear our own entry. An instance swap on this alias evicts the
|
|
92
|
+
// map and a fresh caller can install a NEW promise under the same key
|
|
93
|
+
// while this one is still settling — an unconditional delete would
|
|
94
|
+
// remove theirs, costing a duplicate login.
|
|
95
|
+
if (this._authPromises.get(key) === authPromise) {
|
|
96
|
+
this._authPromises.delete(key);
|
|
97
|
+
}
|
|
60
98
|
}
|
|
61
99
|
})();
|
|
62
100
|
this._authPromises.set(key, authPromise);
|
|
@@ -68,6 +106,9 @@ export class SessionManager {
|
|
|
68
106
|
clearSession(alias) {
|
|
69
107
|
this._logger.debug(`Clearing session for alias: ${alias}`);
|
|
70
108
|
this._sessions.delete(alias);
|
|
109
|
+
// An auth started before the clear would otherwise resolve after it and hand
|
|
110
|
+
// the caller the request we just evicted.
|
|
111
|
+
this._authPromises.delete(alias);
|
|
71
112
|
}
|
|
72
113
|
/**
|
|
73
114
|
* Remove all cached sessions.
|
|
@@ -75,6 +116,7 @@ export class SessionManager {
|
|
|
75
116
|
clearAll() {
|
|
76
117
|
this._logger.debug(`Clearing all ${this._sessions.size} sessions`);
|
|
77
118
|
this._sessions.clear();
|
|
119
|
+
this._authPromises.clear();
|
|
78
120
|
}
|
|
79
121
|
/**
|
|
80
122
|
* Check if a session exists for a given alias.
|
|
@@ -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;;;GAGG;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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Q;QACJ,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,gBAAgB,IAAI,CAAC,SAAS,CAAC,IAAI,WAAW,CAAC,CAAC;QACnE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACvB,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,KAAa;QACpB,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;IAEO,MAAM,CAAC,QAA4B;QACvC,MAAM,GAAG,GAAG,QAAQ,CAAC,QAAQ,EAAE,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;QACtD,IAAI,CAAC,GAAG,EAAE,CAAC;YACP,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAC;QAC7F,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when a request is about to be dispatched with a session that was minted
|
|
3
|
+
* for a different ServiceNow instance.
|
|
4
|
+
*
|
|
5
|
+
* This is worth failing loudly over, because the consequence is not a rejected
|
|
6
|
+
* request. `makeRequest` derives the destination host from `auth.instanceUrl`, so a
|
|
7
|
+
* mismatched session sends the request *to the wrong instance*, authenticated as
|
|
8
|
+
* that instance's user. A write intended for dev can land on prod and succeed.
|
|
9
|
+
*
|
|
10
|
+
* The shape here — `code`, `remediation`, `cause` — deliberately mirrors the error
|
|
11
|
+
* taxonomy in `@sonisoft/sn-credstore` so that consumers which already read
|
|
12
|
+
* `remediation` off an unknown error (`now-sdk-ext-cli`'s authenticated-command,
|
|
13
|
+
* `now-sdk-ext-mcp`'s credstore-boot) surface it with no change. It does not import
|
|
14
|
+
* that taxonomy: sn-credstore is an *optional* dependency of this package, so a
|
|
15
|
+
* static value import would crash any install that skipped it, and `instanceof`
|
|
16
|
+
* across its dual ESM/CJS build is unreliable regardless.
|
|
17
|
+
*/
|
|
18
|
+
export declare class StaleInstanceError extends Error {
|
|
19
|
+
/**
|
|
20
|
+
* The code as a CLASS constant, for comparing against an error you were handed:
|
|
21
|
+
* `err?.code === StaleInstanceError.code`. Prefer this over `instanceof` across
|
|
22
|
+
* module boundaries, where a second copy of the class breaks prototype checks.
|
|
23
|
+
*
|
|
24
|
+
* Distinct from the instance field of the same name below — static and prototype
|
|
25
|
+
* members do not collide, and both spellings are useful: this one at the call
|
|
26
|
+
* site, the instance one on the error itself.
|
|
27
|
+
*/
|
|
28
|
+
static readonly code: string;
|
|
29
|
+
/** The code as carried BY an instance. Always equal to the static above. */
|
|
30
|
+
readonly code: string;
|
|
31
|
+
readonly remediation: string;
|
|
32
|
+
constructor(message: string, remediation: string, options?: {
|
|
33
|
+
cause?: unknown;
|
|
34
|
+
});
|
|
35
|
+
toJSON(): {
|
|
36
|
+
name: string;
|
|
37
|
+
message: string;
|
|
38
|
+
code: string;
|
|
39
|
+
remediation: string;
|
|
40
|
+
};
|
|
41
|
+
toString(): string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Structural guard for {@link StaleInstanceError}.
|
|
45
|
+
*
|
|
46
|
+
* Matches on `code` rather than `instanceof` so it still works when the error has
|
|
47
|
+
* crossed a module boundary, been serialized, or been rebuilt by a consumer that
|
|
48
|
+
* loaded a second copy of this package.
|
|
49
|
+
*/
|
|
50
|
+
export declare function isStaleInstanceError(error: unknown): boolean;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when a request is about to be dispatched with a session that was minted
|
|
3
|
+
* for a different ServiceNow instance.
|
|
4
|
+
*
|
|
5
|
+
* This is worth failing loudly over, because the consequence is not a rejected
|
|
6
|
+
* request. `makeRequest` derives the destination host from `auth.instanceUrl`, so a
|
|
7
|
+
* mismatched session sends the request *to the wrong instance*, authenticated as
|
|
8
|
+
* that instance's user. A write intended for dev can land on prod and succeed.
|
|
9
|
+
*
|
|
10
|
+
* The shape here — `code`, `remediation`, `cause` — deliberately mirrors the error
|
|
11
|
+
* taxonomy in `@sonisoft/sn-credstore` so that consumers which already read
|
|
12
|
+
* `remediation` off an unknown error (`now-sdk-ext-cli`'s authenticated-command,
|
|
13
|
+
* `now-sdk-ext-mcp`'s credstore-boot) surface it with no change. It does not import
|
|
14
|
+
* that taxonomy: sn-credstore is an *optional* dependency of this package, so a
|
|
15
|
+
* static value import would crash any install that skipped it, and `instanceof`
|
|
16
|
+
* across its dual ESM/CJS build is unreliable regardless.
|
|
17
|
+
*/
|
|
18
|
+
export class StaleInstanceError extends Error {
|
|
19
|
+
/**
|
|
20
|
+
* The code as a CLASS constant, for comparing against an error you were handed:
|
|
21
|
+
* `err?.code === StaleInstanceError.code`. Prefer this over `instanceof` across
|
|
22
|
+
* module boundaries, where a second copy of the class breaks prototype checks.
|
|
23
|
+
*
|
|
24
|
+
* Distinct from the instance field of the same name below — static and prototype
|
|
25
|
+
* members do not collide, and both spellings are useful: this one at the call
|
|
26
|
+
* site, the instance one on the error itself.
|
|
27
|
+
*/
|
|
28
|
+
static code = "INSTANCE_STALE_DURING_REQUEST";
|
|
29
|
+
/** The code as carried BY an instance. Always equal to the static above. */
|
|
30
|
+
code;
|
|
31
|
+
remediation;
|
|
32
|
+
constructor(message, remediation, options = {}) {
|
|
33
|
+
super(message, options.cause !== undefined ? { cause: options.cause } : undefined);
|
|
34
|
+
this.name = new.target.name;
|
|
35
|
+
this.code = StaleInstanceError.code;
|
|
36
|
+
this.remediation = remediation;
|
|
37
|
+
}
|
|
38
|
+
toJSON() {
|
|
39
|
+
return {
|
|
40
|
+
name: this.name,
|
|
41
|
+
message: this.message,
|
|
42
|
+
code: this.code,
|
|
43
|
+
remediation: this.remediation,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
toString() {
|
|
47
|
+
return `${this.name}: ${this.message}\n\nRemediation: ${this.remediation}`;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Structural guard for {@link StaleInstanceError}.
|
|
52
|
+
*
|
|
53
|
+
* Matches on `code` rather than `instanceof` so it still works when the error has
|
|
54
|
+
* crossed a module boundary, been serialized, or been rebuilt by a consumer that
|
|
55
|
+
* loaded a second copy of this package.
|
|
56
|
+
*/
|
|
57
|
+
export function isStaleInstanceError(error) {
|
|
58
|
+
if (error instanceof StaleInstanceError) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return error?.code === StaleInstanceError.code;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=StaleInstanceError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StaleInstanceError.js","sourceRoot":"","sources":["../../src/exception/StaleInstanceError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAEzC;;;;;;;;OAQG;IACI,MAAM,CAAU,IAAI,GAAW,+BAA+B,CAAC;IAEtE,4EAA4E;IAC5D,IAAI,CAAS;IAEb,WAAW,CAAS;IAEpC,YAAmB,OAAe,EAAE,WAAmB,EAAE,UAA+B,EAAE;QACtF,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACnF,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC,IAAI,CAAC;QACpC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACnC,CAAC;IAEM,MAAM;QACT,OAAO;YACH,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW;SAChC,CAAC;IACN,CAAC;IAEM,QAAQ;QACX,OAAO,GAAG,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,OAAO,oBAAoB,IAAI,CAAC,WAAW,EAAE,CAAC;IAC/E,CAAC;;AAGL;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAc;IAC/C,IAAI,KAAK,YAAY,kBAAkB,EAAE,CAAC;QACtC,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,OAAQ,KAA2B,EAAE,IAAI,KAAK,kBAAkB,CAAC,IAAI,CAAC;AAC1E,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,10 +8,12 @@ export * from './exception/FileException.js';
|
|
|
8
8
|
export * from './exception/FileExistsException.js';
|
|
9
9
|
export * from './exception/InvalidParameterException.js';
|
|
10
10
|
export * from './exception/PathException.js';
|
|
11
|
+
export * from './exception/StaleInstanceError.js';
|
|
11
12
|
export * from './model/types.js';
|
|
12
13
|
export * from './sn/Application.js';
|
|
13
14
|
export * from './sn/BackgroundScriptExecutor.js';
|
|
14
15
|
export * from './sn/IServiceNowInstance.js';
|
|
16
|
+
export * from './sn/OperationProgress.js';
|
|
15
17
|
export * from './sn/ProgressWorker.js';
|
|
16
18
|
export * from './sn/ServiceNowInstance.js';
|
|
17
19
|
export * from './sn/SNRequestBase.js';
|
|
@@ -19,6 +21,7 @@ export * from './util/AppUtil.js';
|
|
|
19
21
|
export * from './util/CSRFTokenHelper.js';
|
|
20
22
|
export * from './util/Logger.js';
|
|
21
23
|
export * from './util/NowStringUtil.js';
|
|
24
|
+
export * from './util/redact.js';
|
|
22
25
|
export * from './util/utils.js';
|
|
23
26
|
export * from './comm/http/ActiveSessionRegistry.js';
|
|
24
27
|
export * from './comm/http/HTTPRequest.js';
|
package/dist/index.js
CHANGED
|
@@ -8,10 +8,12 @@ export * from './exception/FileException.js';
|
|
|
8
8
|
export * from './exception/FileExistsException.js';
|
|
9
9
|
export * from './exception/InvalidParameterException.js';
|
|
10
10
|
export * from './exception/PathException.js';
|
|
11
|
+
export * from './exception/StaleInstanceError.js';
|
|
11
12
|
export * from './model/types.js';
|
|
12
13
|
export * from './sn/Application.js';
|
|
13
14
|
export * from './sn/BackgroundScriptExecutor.js';
|
|
14
15
|
export * from './sn/IServiceNowInstance.js';
|
|
16
|
+
export * from './sn/OperationProgress.js';
|
|
15
17
|
export * from './sn/ProgressWorker.js';
|
|
16
18
|
export * from './sn/ServiceNowInstance.js';
|
|
17
19
|
export * from './sn/SNRequestBase.js';
|
|
@@ -19,6 +21,7 @@ export * from './util/AppUtil.js';
|
|
|
19
21
|
export * from './util/CSRFTokenHelper.js';
|
|
20
22
|
export * from './util/Logger.js';
|
|
21
23
|
export * from './util/NowStringUtil.js';
|
|
24
|
+
export * from './util/redact.js';
|
|
22
25
|
export * from './util/utils.js';
|
|
23
26
|
export * from './comm/http/ActiveSessionRegistry.js';
|
|
24
27
|
export * from './comm/http/HTTPRequest.js';
|