@onlyflows/servicenow-mcp 1.0.0 → 2.0.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/.env.example +56 -0
- package/CHANGELOG.md +153 -0
- package/README.md +939 -101
- package/dist/auth.d.ts +88 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +396 -0
- package/dist/auth.js.map +1 -0
- package/dist/client.d.ts +111 -17
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +554 -79
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +41 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +44 -34
- package/dist/config.js.map +1 -1
- package/dist/encoded-query-policy.d.ts +72 -0
- package/dist/encoded-query-policy.d.ts.map +1 -0
- package/dist/encoded-query-policy.js +409 -0
- package/dist/encoded-query-policy.js.map +1 -0
- package/dist/execution-context.d.ts +235 -0
- package/dist/execution-context.d.ts.map +1 -0
- package/dist/execution-context.js +439 -0
- package/dist/execution-context.js.map +1 -0
- package/dist/field-policy.d.ts +117 -0
- package/dist/field-policy.d.ts.map +1 -0
- package/dist/field-policy.js +1684 -0
- package/dist/field-policy.js.map +1 -0
- package/dist/http-auth.d.ts +131 -0
- package/dist/http-auth.d.ts.map +1 -0
- package/dist/http-auth.js +347 -0
- package/dist/http-auth.js.map +1 -0
- package/dist/http-entrypoint.d.ts +26 -0
- package/dist/http-entrypoint.d.ts.map +1 -0
- package/dist/http-entrypoint.js +255 -0
- package/dist/http-entrypoint.js.map +1 -0
- package/dist/http-observability.d.ts +147 -0
- package/dist/http-observability.d.ts.map +1 -0
- package/dist/http-observability.js +703 -0
- package/dist/http-observability.js.map +1 -0
- package/dist/http-request-policy.d.ts +72 -0
- package/dist/http-request-policy.d.ts.map +1 -0
- package/dist/http-request-policy.js +463 -0
- package/dist/http-request-policy.js.map +1 -0
- package/dist/http-request-signal.d.ts +12 -0
- package/dist/http-request-signal.d.ts.map +1 -0
- package/dist/http-request-signal.js +39 -0
- package/dist/http-request-signal.js.map +1 -0
- package/dist/http-runtime.d.ts +77 -0
- package/dist/http-runtime.d.ts.map +1 -0
- package/dist/http-runtime.js +1321 -0
- package/dist/http-runtime.js.map +1 -0
- package/dist/incident-journal-policy.d.ts +22 -0
- package/dist/incident-journal-policy.d.ts.map +1 -0
- package/dist/incident-journal-policy.js +115 -0
- package/dist/incident-journal-policy.js.map +1 -0
- package/dist/incident-write-policy.d.ts +20 -0
- package/dist/incident-write-policy.d.ts.map +1 -0
- package/dist/incident-write-policy.js +196 -0
- package/dist/incident-write-policy.js.map +1 -0
- package/dist/index.d.ts +14 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +140 -36
- package/dist/index.js.map +1 -1
- package/dist/metadata-cache.d.ts +71 -0
- package/dist/metadata-cache.d.ts.map +1 -0
- package/dist/metadata-cache.js +397 -0
- package/dist/metadata-cache.js.map +1 -0
- package/dist/profile-admin.d.ts +64 -0
- package/dist/profile-admin.d.ts.map +1 -0
- package/dist/profile-admin.js +351 -0
- package/dist/profile-admin.js.map +1 -0
- package/dist/profile-credentials.d.ts +68 -0
- package/dist/profile-credentials.d.ts.map +1 -0
- package/dist/profile-credentials.js +329 -0
- package/dist/profile-credentials.js.map +1 -0
- package/dist/profile-manager.d.ts +187 -0
- package/dist/profile-manager.d.ts.map +1 -0
- package/dist/profile-manager.js +1026 -0
- package/dist/profile-manager.js.map +1 -0
- package/dist/record-identifier-policy.d.ts +39 -0
- package/dist/record-identifier-policy.d.ts.map +1 -0
- package/dist/record-identifier-policy.js +203 -0
- package/dist/record-identifier-policy.js.map +1 -0
- package/dist/runtime-environment.d.ts +23 -0
- package/dist/runtime-environment.d.ts.map +1 -0
- package/dist/runtime-environment.js +58 -0
- package/dist/runtime-environment.js.map +1 -0
- package/dist/server.d.ts +33 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +73 -0
- package/dist/server.js.map +1 -0
- package/dist/servicenow-identifiers.d.ts +8 -0
- package/dist/servicenow-identifiers.d.ts.map +1 -0
- package/dist/servicenow-identifiers.js +22 -0
- package/dist/servicenow-identifiers.js.map +1 -0
- package/dist/setup-prompts.d.ts +7 -0
- package/dist/setup-prompts.d.ts.map +1 -0
- package/dist/setup-prompts.js +123 -0
- package/dist/setup-prompts.js.map +1 -0
- package/dist/setup.d.ts +109 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/setup.js +1903 -0
- package/dist/setup.js.map +1 -0
- package/dist/startup.d.ts +43 -0
- package/dist/startup.d.ts.map +1 -0
- package/dist/startup.js +75 -0
- package/dist/startup.js.map +1 -0
- package/dist/stdio-runtime.d.ts +106 -0
- package/dist/stdio-runtime.d.ts.map +1 -0
- package/dist/stdio-runtime.js +231 -0
- package/dist/stdio-runtime.js.map +1 -0
- package/dist/structured-query.d.ts +187 -0
- package/dist/structured-query.d.ts.map +1 -0
- package/dist/structured-query.js +503 -0
- package/dist/structured-query.js.map +1 -0
- package/dist/table-defaults.d.ts +28 -0
- package/dist/table-defaults.d.ts.map +1 -0
- package/dist/table-defaults.js +85 -0
- package/dist/table-defaults.js.map +1 -0
- package/dist/table-policy.d.ts +71 -0
- package/dist/table-policy.d.ts.map +1 -0
- package/dist/table-policy.js +290 -0
- package/dist/table-policy.js.map +1 -0
- package/dist/tool-error.d.ts +48 -0
- package/dist/tool-error.d.ts.map +1 -0
- package/dist/tool-error.js +139 -0
- package/dist/tool-error.js.map +1 -0
- package/dist/tool-table-access.d.ts +19 -0
- package/dist/tool-table-access.d.ts.map +1 -0
- package/dist/tool-table-access.js +388 -0
- package/dist/tool-table-access.js.map +1 -0
- package/dist/tools/aggregate.d.ts +22 -42
- package/dist/tools/aggregate.d.ts.map +1 -1
- package/dist/tools/aggregate.js +103 -47
- package/dist/tools/aggregate.js.map +1 -1
- package/dist/tools/all-fields-cap.d.ts +45 -0
- package/dist/tools/all-fields-cap.d.ts.map +1 -0
- package/dist/tools/all-fields-cap.js +151 -0
- package/dist/tools/all-fields-cap.js.map +1 -0
- package/dist/tools/atf.d.ts +21 -60
- package/dist/tools/atf.d.ts.map +1 -1
- package/dist/tools/atf.js +180 -116
- package/dist/tools/atf.js.map +1 -1
- package/dist/tools/attach.d.ts +31 -45
- package/dist/tools/attach.d.ts.map +1 -1
- package/dist/tools/attach.js +175 -137
- package/dist/tools/attach.js.map +1 -1
- package/dist/tools/batch.d.ts +78 -42
- package/dist/tools/batch.d.ts.map +1 -1
- package/dist/tools/batch.js +172 -68
- package/dist/tools/batch.js.map +1 -1
- package/dist/tools/catalog.d.ts +6 -0
- package/dist/tools/catalog.d.ts.map +1 -0
- package/dist/tools/catalog.js +203 -0
- package/dist/tools/catalog.js.map +1 -0
- package/dist/tools/codesearch.d.ts +14 -25
- package/dist/tools/codesearch.d.ts.map +1 -1
- package/dist/tools/codesearch.js +60 -48
- package/dist/tools/codesearch.js.map +1 -1
- package/dist/tools/create-module.d.ts +48 -0
- package/dist/tools/create-module.d.ts.map +1 -0
- package/dist/tools/create-module.js +94 -0
- package/dist/tools/create-module.js.map +1 -0
- package/dist/tools/create.d.ts +2 -38
- package/dist/tools/create.d.ts.map +1 -1
- package/dist/tools/create.js +9 -41
- package/dist/tools/create.js.map +1 -1
- package/dist/tools/delete.d.ts +13 -23
- package/dist/tools/delete.d.ts.map +1 -1
- package/dist/tools/delete.js +30 -33
- package/dist/tools/delete.js.map +1 -1
- package/dist/tools/discover.d.ts +15 -27
- package/dist/tools/discover.d.ts.map +1 -1
- package/dist/tools/discover.js +103 -60
- package/dist/tools/discover.js.map +1 -1
- package/dist/tools/get-module.d.ts +85 -0
- package/dist/tools/get-module.d.ts.map +1 -0
- package/dist/tools/get-module.js +221 -0
- package/dist/tools/get-module.js.map +1 -0
- package/dist/tools/get.d.ts +2 -51
- package/dist/tools/get.d.ts.map +1 -1
- package/dist/tools/get.js +9 -49
- package/dist/tools/get.js.map +1 -1
- package/dist/tools/handler-result.d.ts +14 -0
- package/dist/tools/handler-result.d.ts.map +1 -0
- package/dist/tools/handler-result.js +177 -0
- package/dist/tools/handler-result.js.map +1 -0
- package/dist/tools/health.d.ts +12 -15
- package/dist/tools/health.d.ts.map +1 -1
- package/dist/tools/health.js +55 -36
- package/dist/tools/health.js.map +1 -1
- package/dist/tools/incident-journal-module.d.ts +12 -0
- package/dist/tools/incident-journal-module.d.ts.map +1 -0
- package/dist/tools/incident-journal-module.js +61 -0
- package/dist/tools/incident-journal-module.js.map +1 -0
- package/dist/tools/incident-write-shared.d.ts +6 -0
- package/dist/tools/incident-write-shared.d.ts.map +1 -0
- package/dist/tools/incident-write-shared.js +64 -0
- package/dist/tools/incident-write-shared.js.map +1 -0
- package/dist/tools/index.d.ts +47 -36
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +795 -35
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/nl.d.ts +10 -24
- package/dist/tools/nl.d.ts.map +1 -1
- package/dist/tools/nl.js +37 -147
- package/dist/tools/nl.js.map +1 -1
- package/dist/tools/profile.d.ts +37 -0
- package/dist/tools/profile.d.ts.map +1 -0
- package/dist/tools/profile.js +39 -0
- package/dist/tools/profile.js.map +1 -0
- package/dist/tools/query-module.d.ts +119 -0
- package/dist/tools/query-module.d.ts.map +1 -0
- package/dist/tools/query-module.js +324 -0
- package/dist/tools/query-module.js.map +1 -0
- package/dist/tools/query.d.ts +2 -72
- package/dist/tools/query.d.ts.map +1 -1
- package/dist/tools/query.js +8 -72
- package/dist/tools/query.js.map +1 -1
- package/dist/tools/relationships.d.ts +21 -42
- package/dist/tools/relationships.d.ts.map +1 -1
- package/dist/tools/relationships.js +70 -56
- package/dist/tools/relationships.js.map +1 -1
- package/dist/tools/result-envelope.d.ts +603 -0
- package/dist/tools/result-envelope.d.ts.map +1 -0
- package/dist/tools/result-envelope.js +767 -0
- package/dist/tools/result-envelope.js.map +1 -0
- package/dist/tools/schema-module.d.ts +64 -0
- package/dist/tools/schema-module.d.ts.map +1 -0
- package/dist/tools/schema-module.js +367 -0
- package/dist/tools/schema-module.js.map +1 -0
- package/dist/tools/schema.d.ts +2 -37
- package/dist/tools/schema.d.ts.map +1 -1
- package/dist/tools/schema.js +6 -57
- package/dist/tools/schema.js.map +1 -1
- package/dist/tools/script.d.ts +33 -27
- package/dist/tools/script.d.ts.map +1 -1
- package/dist/tools/script.js +43 -37
- package/dist/tools/script.js.map +1 -1
- package/dist/tools/syslog.d.ts +19 -46
- package/dist/tools/syslog.d.ts.map +1 -1
- package/dist/tools/syslog.js +101 -67
- package/dist/tools/syslog.js.map +1 -1
- package/dist/tools/tool-module.d.ts +143 -0
- package/dist/tools/tool-module.d.ts.map +1 -0
- package/dist/tools/tool-module.js +1095 -0
- package/dist/tools/tool-module.js.map +1 -0
- package/dist/tools/update-module.d.ts +51 -0
- package/dist/tools/update-module.d.ts.map +1 -0
- package/dist/tools/update-module.js +107 -0
- package/dist/tools/update-module.js.map +1 -0
- package/dist/tools/update.d.ts +2 -45
- package/dist/tools/update.d.ts.map +1 -1
- package/dist/tools/update.js +9 -41
- package/dist/tools/update.js.map +1 -1
- package/dist/utils.d.ts +68 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +114 -16
- package/dist/utils.js.map +1 -1
- package/dist/version.d.ts +10 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +13 -0
- package/dist/version.js.map +1 -0
- package/docs/ADDING-TOOLS.md +227 -0
- package/docs/CLIENT-SETUP.md +914 -0
- package/docs/CONTAINER-DEPLOYMENT.md +310 -0
- package/docs/CROSS-CLIENT-RELEASE-MATRIX.md +63 -0
- package/docs/ENTERPRISE-RELEASE-BOUNDARY.md +149 -0
- package/docs/OPERATIONS-RUNBOOK.md +383 -0
- package/docs/PRIVATE-CHATGPT-CONNECTIVITY.md +347 -0
- package/docs/PRODUCTION-SECURITY.md +368 -0
- package/docs/PROFILE-CREDENTIALS.md +126 -0
- package/docs/RELEASE-VALIDATION.md +140 -0
- package/docs/TESTING-OAUTH.md +101 -0
- package/docs/V2-MIGRATION.md +493 -0
- package/package.json +60 -13
- package/scripts/inspector.mjs +140 -0
- package/scripts/release-validate.mjs +201 -0
- package/scripts/smoke-test.mjs +274 -0
- package/tools/inspector/package-lock.json +3812 -0
- package/tools/inspector/package.json +12 -0
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication providers for the ServiceNow HTTP client.
|
|
3
|
+
*
|
|
4
|
+
* Each provider produces the auth headers for a request and decides
|
|
5
|
+
* whether a 401 response is worth retrying after a credential refresh.
|
|
6
|
+
*
|
|
7
|
+
* Supported schemes:
|
|
8
|
+
* - basic: Authorization: Basic <user:password> (deprecated by
|
|
9
|
+
* ServiceNow's inbound Basic Auth restriction program)
|
|
10
|
+
* - oauth: Authorization: Bearer <token> from {instance}/oauth_token.do
|
|
11
|
+
* (grant_type client_credentials or password), with token
|
|
12
|
+
* caching, expiry tracking, and single-flight refresh
|
|
13
|
+
* - apikey: the key in a configurable header (default "x-sn-apikey")
|
|
14
|
+
*
|
|
15
|
+
* SECURITY: token responses and secrets are never logged; error messages
|
|
16
|
+
* from the token endpoint are redacted before being thrown.
|
|
17
|
+
*
|
|
18
|
+
* @module auth
|
|
19
|
+
*/
|
|
20
|
+
import { GrantType, ServiceNowConfig } from "./config.js";
|
|
21
|
+
export type AuthKind = "basic" | "oauth" | "apikey";
|
|
22
|
+
export declare const DEFAULT_API_KEY_HEADER = "x-sn-apikey";
|
|
23
|
+
export interface AuthProvider {
|
|
24
|
+
/** Which auth scheme this provider implements. */
|
|
25
|
+
readonly kind: AuthKind;
|
|
26
|
+
/** Headers to attach to an outgoing request (may refresh credentials). */
|
|
27
|
+
getAuthHeaders(signal?: AbortSignal): Promise<Record<string, string>>;
|
|
28
|
+
/**
|
|
29
|
+
* Called by the client when a request returns 401.
|
|
30
|
+
* Returns true when credentials were refreshed and a single retry
|
|
31
|
+
* of the original request makes sense.
|
|
32
|
+
*/
|
|
33
|
+
onAuthFailure(signal?: AbortSignal): Promise<boolean>;
|
|
34
|
+
}
|
|
35
|
+
export declare class BasicAuthProvider implements AuthProvider {
|
|
36
|
+
readonly kind: "basic";
|
|
37
|
+
private readonly header;
|
|
38
|
+
constructor(user: string, password: string);
|
|
39
|
+
getAuthHeaders(): Promise<Record<string, string>>;
|
|
40
|
+
onAuthFailure(): Promise<boolean>;
|
|
41
|
+
}
|
|
42
|
+
export interface OAuthProviderOptions {
|
|
43
|
+
/** Instance base URL (e.g. "https://myinstance.service-now.com") */
|
|
44
|
+
instance: string;
|
|
45
|
+
clientId: string;
|
|
46
|
+
clientSecret: string;
|
|
47
|
+
/** Defaults to "client_credentials". */
|
|
48
|
+
grantType?: GrantType;
|
|
49
|
+
/** Required for the "password" grant. */
|
|
50
|
+
username?: string;
|
|
51
|
+
/** Required for the "password" grant. */
|
|
52
|
+
password?: string;
|
|
53
|
+
/** Timeout for the token request itself (default 30000). */
|
|
54
|
+
timeoutMs?: number;
|
|
55
|
+
}
|
|
56
|
+
export declare class OAuthProvider implements AuthProvider {
|
|
57
|
+
private readonly options;
|
|
58
|
+
readonly kind: "oauth";
|
|
59
|
+
private token;
|
|
60
|
+
private expiresAt;
|
|
61
|
+
private refresh;
|
|
62
|
+
constructor(options: OAuthProviderOptions);
|
|
63
|
+
getAuthHeaders(signal?: AbortSignal): Promise<Record<string, string>>;
|
|
64
|
+
onAuthFailure(signal?: AbortSignal): Promise<boolean>;
|
|
65
|
+
private invalidate;
|
|
66
|
+
/**
|
|
67
|
+
* Return a cached, unexpired token or refresh it. Concurrent callers
|
|
68
|
+
* share a single in-flight refresh (single-flight).
|
|
69
|
+
*/
|
|
70
|
+
private getToken;
|
|
71
|
+
private startRefresh;
|
|
72
|
+
private subscribeToRefresh;
|
|
73
|
+
private fetchToken;
|
|
74
|
+
}
|
|
75
|
+
export declare class ApiKeyProvider implements AuthProvider {
|
|
76
|
+
private readonly key;
|
|
77
|
+
private readonly headerName;
|
|
78
|
+
readonly kind: "apikey";
|
|
79
|
+
constructor(key: string, headerName?: string);
|
|
80
|
+
getAuthHeaders(): Promise<Record<string, string>>;
|
|
81
|
+
onAuthFailure(): Promise<boolean>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Build the right AuthProvider for a resolved profile config.
|
|
85
|
+
* Defaults to basic auth for full backward compatibility.
|
|
86
|
+
*/
|
|
87
|
+
export declare function createAuthProvider(config: ServiceNowConfig): AuthProvider;
|
|
88
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAM1D,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEpD,eAAO,MAAM,sBAAsB,gBAAgB,CAAC;AAOpD,MAAM,WAAW,YAAY;IAC3B,kDAAkD;IAClD,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,0EAA0E;IAC1E,cAAc,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACtE;;;;OAIG;IACH,aAAa,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACvD;AAID,qBAAa,iBAAkB,YAAW,YAAY;IACpD,QAAQ,CAAC,IAAI,EAAG,OAAO,CAAU;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAKpC,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAIjD,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC;CAIxC;AAID,MAAM,WAAW,oBAAoB;IACnC,oEA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AgB,GAAG,YAAY,CAgCzE"}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Authentication providers for the ServiceNow HTTP client.
|
|
4
|
+
*
|
|
5
|
+
* Each provider produces the auth headers for a request and decides
|
|
6
|
+
* whether a 401 response is worth retrying after a credential refresh.
|
|
7
|
+
*
|
|
8
|
+
* Supported schemes:
|
|
9
|
+
* - basic: Authorization: Basic <user:password> (deprecated by
|
|
10
|
+
* ServiceNow's inbound Basic Auth restriction program)
|
|
11
|
+
* - oauth: Authorization: Bearer <token> from {instance}/oauth_token.do
|
|
12
|
+
* (grant_type client_credentials or password), with token
|
|
13
|
+
* caching, expiry tracking, and single-flight refresh
|
|
14
|
+
* - apikey: the key in a configurable header (default "x-sn-apikey")
|
|
15
|
+
*
|
|
16
|
+
* SECURITY: token responses and secrets are never logged; error messages
|
|
17
|
+
* from the token endpoint are redacted before being thrown.
|
|
18
|
+
*
|
|
19
|
+
* @module auth
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.ApiKeyProvider = exports.OAuthProvider = exports.BasicAuthProvider = exports.DEFAULT_API_KEY_HEADER = void 0;
|
|
23
|
+
exports.createAuthProvider = createAuthProvider;
|
|
24
|
+
const tool_error_js_1 = require("./tool-error.js");
|
|
25
|
+
exports.DEFAULT_API_KEY_HEADER = "x-sn-apikey";
|
|
26
|
+
/** Refresh tokens this many ms before their reported expiry. */
|
|
27
|
+
const TOKEN_EXPIRY_MARGIN_MS = 60_000;
|
|
28
|
+
const TOKEN_REQUEST_TIMEOUT_MS = 30_000;
|
|
29
|
+
const MAX_TOKEN_RESPONSE_BYTES = 64 * 1024;
|
|
30
|
+
// ── Basic ──────────────────────────────────────────────────────────
|
|
31
|
+
class BasicAuthProvider {
|
|
32
|
+
kind = "basic";
|
|
33
|
+
header;
|
|
34
|
+
constructor(user, password) {
|
|
35
|
+
this.header =
|
|
36
|
+
"Basic " + Buffer.from(`${user}:${password}`).toString("base64");
|
|
37
|
+
}
|
|
38
|
+
async getAuthHeaders() {
|
|
39
|
+
return { Authorization: this.header };
|
|
40
|
+
}
|
|
41
|
+
async onAuthFailure() {
|
|
42
|
+
// Basic credentials cannot be refreshed -- a 401 is final.
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.BasicAuthProvider = BasicAuthProvider;
|
|
47
|
+
class OAuthProvider {
|
|
48
|
+
options;
|
|
49
|
+
kind = "oauth";
|
|
50
|
+
token = null;
|
|
51
|
+
expiresAt = 0;
|
|
52
|
+
refresh = null;
|
|
53
|
+
constructor(options) {
|
|
54
|
+
this.options = options;
|
|
55
|
+
const grantType = options.grantType ?? "client_credentials";
|
|
56
|
+
if (grantType === "password" && (!options.username || !options.password)) {
|
|
57
|
+
throw (0, tool_error_js_1.createToolError)("authentication", "retry_after_correction");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async getAuthHeaders(signal) {
|
|
61
|
+
const token = await this.getToken(signal);
|
|
62
|
+
return { Authorization: `Bearer ${token}` };
|
|
63
|
+
}
|
|
64
|
+
async onAuthFailure(signal) {
|
|
65
|
+
// The instance rejected our token -- drop it, fetch a fresh one, and
|
|
66
|
+
// let the client retry the original request exactly once.
|
|
67
|
+
this.invalidate();
|
|
68
|
+
await this.getToken(signal);
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
invalidate() {
|
|
72
|
+
this.token = null;
|
|
73
|
+
this.expiresAt = 0;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Return a cached, unexpired token or refresh it. Concurrent callers
|
|
77
|
+
* share a single in-flight refresh (single-flight).
|
|
78
|
+
*/
|
|
79
|
+
async getToken(signal) {
|
|
80
|
+
throwIfOAuthCancelled(signal);
|
|
81
|
+
if (this.token && Date.now() < this.expiresAt) {
|
|
82
|
+
return this.token;
|
|
83
|
+
}
|
|
84
|
+
const refresh = this.refresh ?? this.startRefresh();
|
|
85
|
+
return this.subscribeToRefresh(refresh, signal);
|
|
86
|
+
}
|
|
87
|
+
startRefresh() {
|
|
88
|
+
const controller = new AbortController();
|
|
89
|
+
const refresh = {
|
|
90
|
+
controller,
|
|
91
|
+
promise: null,
|
|
92
|
+
subscribers: 0,
|
|
93
|
+
settled: false,
|
|
94
|
+
};
|
|
95
|
+
this.refresh = refresh;
|
|
96
|
+
refresh.promise = this.fetchToken(controller.signal)
|
|
97
|
+
.then((result) => {
|
|
98
|
+
// A fetch implementation may ignore AbortSignal and resolve late. A
|
|
99
|
+
// detached/aborted flight never gets to mutate the credential cache.
|
|
100
|
+
if (controller.signal.aborted || this.refresh !== refresh) {
|
|
101
|
+
throw oauthCancellationError();
|
|
102
|
+
}
|
|
103
|
+
this.token = result.accessToken;
|
|
104
|
+
this.expiresAt = result.expiresAt;
|
|
105
|
+
return result.accessToken;
|
|
106
|
+
})
|
|
107
|
+
.finally(() => {
|
|
108
|
+
refresh.settled = true;
|
|
109
|
+
if (this.refresh === refresh)
|
|
110
|
+
this.refresh = null;
|
|
111
|
+
});
|
|
112
|
+
return refresh;
|
|
113
|
+
}
|
|
114
|
+
subscribeToRefresh(refresh, signal) {
|
|
115
|
+
if (signal?.aborted)
|
|
116
|
+
return Promise.reject(oauthCancellationError());
|
|
117
|
+
const operation = refresh.promise;
|
|
118
|
+
if (!operation) {
|
|
119
|
+
return Promise.reject((0, tool_error_js_1.createToolError)("internal", "do_not_retry"));
|
|
120
|
+
}
|
|
121
|
+
refresh.subscribers += 1;
|
|
122
|
+
return new Promise((resolve, reject) => {
|
|
123
|
+
let released = false;
|
|
124
|
+
const release = (cancelled) => {
|
|
125
|
+
if (released)
|
|
126
|
+
return;
|
|
127
|
+
released = true;
|
|
128
|
+
signal?.removeEventListener("abort", onAbort);
|
|
129
|
+
refresh.subscribers = Math.max(0, refresh.subscribers - 1);
|
|
130
|
+
if (cancelled && refresh.subscribers === 0 && !refresh.settled) {
|
|
131
|
+
// Detach first so a new caller can start a healthy flight while the
|
|
132
|
+
// abandoned fetch is unwinding. Cache fencing above handles a fetch
|
|
133
|
+
// implementation that resolves despite the abort.
|
|
134
|
+
if (this.refresh === refresh)
|
|
135
|
+
this.refresh = null;
|
|
136
|
+
refresh.controller.abort(oauthCancellationError());
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
const onAbort = () => {
|
|
140
|
+
release(true);
|
|
141
|
+
reject(oauthCancellationError());
|
|
142
|
+
};
|
|
143
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
144
|
+
void operation.then((token) => {
|
|
145
|
+
if (released)
|
|
146
|
+
return;
|
|
147
|
+
release(false);
|
|
148
|
+
resolve(token);
|
|
149
|
+
}, (error) => {
|
|
150
|
+
if (released)
|
|
151
|
+
return;
|
|
152
|
+
release(false);
|
|
153
|
+
reject(error);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
async fetchToken(refreshSignal) {
|
|
158
|
+
const grantType = this.options.grantType ?? "client_credentials";
|
|
159
|
+
const url = new URL("/oauth_token.do", this.options.instance).toString();
|
|
160
|
+
const timeoutMs = this.options.timeoutMs ?? TOKEN_REQUEST_TIMEOUT_MS;
|
|
161
|
+
const form = new URLSearchParams({
|
|
162
|
+
grant_type: grantType,
|
|
163
|
+
client_id: this.options.clientId,
|
|
164
|
+
client_secret: this.options.clientSecret,
|
|
165
|
+
});
|
|
166
|
+
if (grantType === "password") {
|
|
167
|
+
form.set("username", this.options.username ?? "");
|
|
168
|
+
form.set("password", this.options.password ?? "");
|
|
169
|
+
}
|
|
170
|
+
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
171
|
+
const tokenSignal = AbortSignal.any([refreshSignal, timeoutSignal]);
|
|
172
|
+
let response;
|
|
173
|
+
try {
|
|
174
|
+
response = await fetch(url, {
|
|
175
|
+
method: "POST",
|
|
176
|
+
headers: {
|
|
177
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
178
|
+
Accept: "application/json",
|
|
179
|
+
},
|
|
180
|
+
body: form.toString(),
|
|
181
|
+
signal: tokenSignal,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
if (refreshSignal.aborted)
|
|
186
|
+
throw oauthCancellationError();
|
|
187
|
+
if (timeoutSignal.aborted) {
|
|
188
|
+
throw (0, tool_error_js_1.createToolError)("timeout", "retry_if_safe_and_idempotent");
|
|
189
|
+
}
|
|
190
|
+
throw (0, tool_error_js_1.createToolError)("upstream", "retry_if_safe_and_idempotent");
|
|
191
|
+
}
|
|
192
|
+
if (!response.ok) {
|
|
193
|
+
try {
|
|
194
|
+
await consumeTokenFailure(response, tokenSignal);
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
if (refreshSignal.aborted)
|
|
198
|
+
throw oauthCancellationError();
|
|
199
|
+
if (timeoutSignal.aborted) {
|
|
200
|
+
throw (0, tool_error_js_1.createToolError)("timeout", "retry_if_safe_and_idempotent");
|
|
201
|
+
}
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
throw oauthHttpError(response);
|
|
205
|
+
}
|
|
206
|
+
let json;
|
|
207
|
+
try {
|
|
208
|
+
const text = await readBoundedResponseText(response, MAX_TOKEN_RESPONSE_BYTES, tokenSignal);
|
|
209
|
+
const candidate = JSON.parse(text);
|
|
210
|
+
if (typeof candidate !== "object" || candidate === null || Array.isArray(candidate)) {
|
|
211
|
+
throw new TypeError("OAuth token response must be a JSON object");
|
|
212
|
+
}
|
|
213
|
+
json = candidate;
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
if (refreshSignal.aborted)
|
|
217
|
+
throw oauthCancellationError();
|
|
218
|
+
if (timeoutSignal.aborted) {
|
|
219
|
+
throw (0, tool_error_js_1.createToolError)("timeout", "retry_if_safe_and_idempotent");
|
|
220
|
+
}
|
|
221
|
+
// Never echo the raw body -- it may contain token material.
|
|
222
|
+
throw (0, tool_error_js_1.createToolError)("upstream", "retry_if_safe_and_idempotent");
|
|
223
|
+
}
|
|
224
|
+
const accessToken = json.access_token;
|
|
225
|
+
if (typeof accessToken !== "string" || accessToken.length === 0) {
|
|
226
|
+
throw (0, tool_error_js_1.createToolError)("upstream", "retry_if_safe_and_idempotent");
|
|
227
|
+
}
|
|
228
|
+
const expiresIn = typeof json.expires_in === "number"
|
|
229
|
+
? json.expires_in
|
|
230
|
+
: parseInt(String(json.expires_in ?? ""), 10);
|
|
231
|
+
const expiresInMs = (isNaN(expiresIn) ? 1800 : expiresIn) * 1000;
|
|
232
|
+
return Object.freeze({
|
|
233
|
+
accessToken,
|
|
234
|
+
expiresAt: Date.now() + expiresInMs - TOKEN_EXPIRY_MARGIN_MS,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
exports.OAuthProvider = OAuthProvider;
|
|
239
|
+
// ── API key ────────────────────────────────────────────────────────
|
|
240
|
+
class ApiKeyProvider {
|
|
241
|
+
key;
|
|
242
|
+
headerName;
|
|
243
|
+
kind = "apikey";
|
|
244
|
+
constructor(key, headerName = exports.DEFAULT_API_KEY_HEADER) {
|
|
245
|
+
this.key = key;
|
|
246
|
+
this.headerName = headerName;
|
|
247
|
+
}
|
|
248
|
+
async getAuthHeaders() {
|
|
249
|
+
return { [this.headerName]: this.key };
|
|
250
|
+
}
|
|
251
|
+
async onAuthFailure() {
|
|
252
|
+
// A static key cannot be refreshed -- a 401 is final.
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
exports.ApiKeyProvider = ApiKeyProvider;
|
|
257
|
+
// ── Factory ────────────────────────────────────────────────────────
|
|
258
|
+
/**
|
|
259
|
+
* Build the right AuthProvider for a resolved profile config.
|
|
260
|
+
* Defaults to basic auth for full backward compatibility.
|
|
261
|
+
*/
|
|
262
|
+
function createAuthProvider(config) {
|
|
263
|
+
const authType = config.authType ?? "basic";
|
|
264
|
+
switch (authType) {
|
|
265
|
+
case "oauth": {
|
|
266
|
+
if (!config.clientId || !config.clientSecret) {
|
|
267
|
+
throw (0, tool_error_js_1.createToolError)("authentication", "retry_after_correction");
|
|
268
|
+
}
|
|
269
|
+
return new OAuthProvider({
|
|
270
|
+
instance: config.instance,
|
|
271
|
+
clientId: config.clientId,
|
|
272
|
+
clientSecret: config.clientSecret,
|
|
273
|
+
grantType: config.grantType,
|
|
274
|
+
username: config.user || undefined,
|
|
275
|
+
password: config.password || undefined,
|
|
276
|
+
timeoutMs: config.timeoutMs,
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
case "apikey": {
|
|
280
|
+
if (!config.apiKey) {
|
|
281
|
+
throw (0, tool_error_js_1.createToolError)("authentication", "retry_after_correction");
|
|
282
|
+
}
|
|
283
|
+
return new ApiKeyProvider(config.apiKey, config.apiKeyHeader || exports.DEFAULT_API_KEY_HEADER);
|
|
284
|
+
}
|
|
285
|
+
default:
|
|
286
|
+
return new BasicAuthProvider(config.user, config.password);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
// ── Module-level helpers ───────────────────────────────────────────
|
|
290
|
+
async function consumeTokenFailure(response, signal) {
|
|
291
|
+
try {
|
|
292
|
+
await readBoundedResponseText(response, MAX_TOKEN_RESPONSE_BYTES, signal);
|
|
293
|
+
}
|
|
294
|
+
catch {
|
|
295
|
+
if (signal.aborted)
|
|
296
|
+
throw oauthCancellationError();
|
|
297
|
+
// A bounded/unreadable error body never changes the structural HTTP map.
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function oauthHttpError(response) {
|
|
301
|
+
const status = response.status;
|
|
302
|
+
if (status === 408) {
|
|
303
|
+
return (0, tool_error_js_1.createToolError)("timeout", "retry_if_safe_and_idempotent");
|
|
304
|
+
}
|
|
305
|
+
if (status === 409) {
|
|
306
|
+
return (0, tool_error_js_1.createToolError)("conflict", "retry_after_correction");
|
|
307
|
+
}
|
|
308
|
+
if (status === 429) {
|
|
309
|
+
return (0, tool_error_js_1.createToolError)("rate_limit", "retry_later", (0, tool_error_js_1.boundedRetryAfterSeconds)(parseOAuthRetryAfterMs(response.headers.get("retry-after"))));
|
|
310
|
+
}
|
|
311
|
+
if (status >= 500) {
|
|
312
|
+
return (0, tool_error_js_1.createToolError)("upstream", "retry_if_safe_and_idempotent");
|
|
313
|
+
}
|
|
314
|
+
if (status >= 400) {
|
|
315
|
+
// Token-endpoint rejections are intentionally indistinguishable from a
|
|
316
|
+
// locally unavailable credential reference at the public boundary.
|
|
317
|
+
return (0, tool_error_js_1.createToolError)("authentication", "retry_after_correction");
|
|
318
|
+
}
|
|
319
|
+
return (0, tool_error_js_1.createToolError)("upstream", "do_not_retry");
|
|
320
|
+
}
|
|
321
|
+
function parseOAuthRetryAfterMs(value) {
|
|
322
|
+
if (value === null)
|
|
323
|
+
return undefined;
|
|
324
|
+
if (/^(?:0|[1-9][0-9]*)$/u.test(value)) {
|
|
325
|
+
const seconds = Number(value);
|
|
326
|
+
return Number.isSafeInteger(seconds) ? seconds * 1_000 : undefined;
|
|
327
|
+
}
|
|
328
|
+
const date = Date.parse(value);
|
|
329
|
+
return Number.isNaN(date) ? undefined : Math.max(0, date - Date.now());
|
|
330
|
+
}
|
|
331
|
+
function oauthCancellationError() {
|
|
332
|
+
const error = new Error("OAuth token request cancelled");
|
|
333
|
+
error.name = "AbortError";
|
|
334
|
+
return error;
|
|
335
|
+
}
|
|
336
|
+
function throwIfOAuthCancelled(signal) {
|
|
337
|
+
if (signal?.aborted)
|
|
338
|
+
throw oauthCancellationError();
|
|
339
|
+
}
|
|
340
|
+
async function readBoundedResponseText(response, maximum, signal) {
|
|
341
|
+
const declaredLength = response.headers.get("content-length");
|
|
342
|
+
if (declaredLength !== null) {
|
|
343
|
+
const parsedLength = parseDeclaredLength(declaredLength);
|
|
344
|
+
if (parsedLength === undefined || parsedLength > maximum) {
|
|
345
|
+
await cancelResponseBody(response, "OAuth response exceeds byte limit");
|
|
346
|
+
throw new RangeError("OAuth response exceeds configured byte limit");
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
throwIfOAuthCancelled(signal);
|
|
350
|
+
if (!response.body)
|
|
351
|
+
return "";
|
|
352
|
+
const reader = response.body.getReader();
|
|
353
|
+
const chunks = [];
|
|
354
|
+
let total = 0;
|
|
355
|
+
const onAbort = () => {
|
|
356
|
+
void reader.cancel("OAuth request cancelled").catch(() => { });
|
|
357
|
+
};
|
|
358
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
359
|
+
try {
|
|
360
|
+
for (;;) {
|
|
361
|
+
throwIfOAuthCancelled(signal);
|
|
362
|
+
const next = await reader.read();
|
|
363
|
+
throwIfOAuthCancelled(signal);
|
|
364
|
+
if (next.done)
|
|
365
|
+
break;
|
|
366
|
+
const chunk = Buffer.from(next.value);
|
|
367
|
+
total += chunk.length;
|
|
368
|
+
if (total > maximum) {
|
|
369
|
+
await reader.cancel("OAuth response exceeds byte limit");
|
|
370
|
+
throw new RangeError("OAuth response exceeds configured byte limit");
|
|
371
|
+
}
|
|
372
|
+
chunks.push(chunk);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
finally {
|
|
376
|
+
signal.removeEventListener("abort", onAbort);
|
|
377
|
+
reader.releaseLock();
|
|
378
|
+
}
|
|
379
|
+
throwIfOAuthCancelled(signal);
|
|
380
|
+
return Buffer.concat(chunks, total).toString("utf8");
|
|
381
|
+
}
|
|
382
|
+
function parseDeclaredLength(value) {
|
|
383
|
+
if (!/^(?:0|[1-9]\d*)$/u.test(value))
|
|
384
|
+
return undefined;
|
|
385
|
+
const parsed = Number(value);
|
|
386
|
+
return Number.isSafeInteger(parsed) ? parsed : undefined;
|
|
387
|
+
}
|
|
388
|
+
async function cancelResponseBody(response, reason) {
|
|
389
|
+
try {
|
|
390
|
+
await response.body?.cancel(reason);
|
|
391
|
+
}
|
|
392
|
+
catch {
|
|
393
|
+
// Cancellation is best effort after rejecting a hostile declaration.
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
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AAC,CAAC;IAC7B,OAAO,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3D,CAAC;AAED,KAAK,UAAU,kBAAkB,CAAC,QAAkB,EAAE,MAAc;IAClE,IAAI,CAAC;QACH,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;IAAC,MAAM,CAAC;QACP,qEAAqE;IACvE,CAAC;AACH,CAAC"}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,40 +1,134 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ServiceNow HTTP client — native fetch-based, zero external dependencies.
|
|
3
3
|
*
|
|
4
|
+
* Every request is bounded by an AbortSignal timeout and retried with
|
|
5
|
+
* exponential backoff + jitter on rate-limit / transient failures:
|
|
6
|
+
* - GET/PATCH/PUT/DELETE retry on 429, 502, 503, 504 and transient
|
|
7
|
+
* network errors (max 2 retries).
|
|
8
|
+
* - POST retries ONLY on 429 — a 429 is rejected before processing, so
|
|
9
|
+
* a retry is safe; a 5xx POST may have executed side effects.
|
|
10
|
+
* - Retry-After headers (delta-seconds and HTTP-date) are honored,
|
|
11
|
+
* capped at MAX_RETRY_DELAY_MS per wait.
|
|
12
|
+
* - A 401 triggers at most one AuthProvider refresh + retry.
|
|
13
|
+
*
|
|
4
14
|
* @module client
|
|
5
15
|
*/
|
|
6
16
|
import { ServiceNowConfig } from "./config.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
17
|
+
import { AuthProvider } from "./auth.js";
|
|
18
|
+
/** @deprecated Inspect trusted tool-error provenance instead of raw fields. */
|
|
19
|
+
export type ServiceNowError = Error;
|
|
20
|
+
type ParsedJson = Awaited<ReturnType<Response["json"]>>;
|
|
21
|
+
/** A parsed response body plus the HTTP status and headers it came with. */
|
|
22
|
+
export interface RequestResult<T = ParsedJson> {
|
|
23
|
+
data: T | null;
|
|
24
|
+
status: number;
|
|
25
|
+
headers: Headers;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Narrow ServiceNow operation capability exposed to tool modules.
|
|
29
|
+
*
|
|
30
|
+
* The facade deliberately omits client configuration, authentication,
|
|
31
|
+
* retry internals, and the generic request primitive. Implementations are
|
|
32
|
+
* closure-bound so a module cannot recover the underlying credential-bearing
|
|
33
|
+
* client through `this`, own properties, or the prototype chain.
|
|
34
|
+
*/
|
|
35
|
+
export interface ServiceNowOperations {
|
|
36
|
+
get<T = ParsedJson>(path: string, params?: Record<string, string>): Promise<T | null>;
|
|
37
|
+
getWithMeta<T = ParsedJson>(path: string, params?: Record<string, string>): Promise<RequestResult<T>>;
|
|
38
|
+
post<T = ParsedJson>(path: string, body?: unknown): Promise<T | null>;
|
|
39
|
+
patch<T = ParsedJson>(path: string, body?: unknown): Promise<T | null>;
|
|
40
|
+
delete(path: string): Promise<{
|
|
41
|
+
status: number;
|
|
42
|
+
}>;
|
|
43
|
+
postBinary<T = ParsedJson>(path: string, data: Buffer, contentType: string, params?: Record<string, string>): Promise<T>;
|
|
44
|
+
getRaw(path: string, options?: {
|
|
45
|
+
readonly maxBytes?: number;
|
|
46
|
+
}): Promise<{
|
|
47
|
+
data: Buffer;
|
|
48
|
+
contentType: string;
|
|
49
|
+
}>;
|
|
11
50
|
}
|
|
51
|
+
export interface ClientOptions {
|
|
52
|
+
/** Auth provider override (defaults to one derived from the config). */
|
|
53
|
+
auth?: AuthProvider;
|
|
54
|
+
/** Max retries after the initial attempt (default 2). */
|
|
55
|
+
maxRetries?: number;
|
|
56
|
+
/** Base backoff delay in ms (default 500). */
|
|
57
|
+
baseRetryDelayMs?: number;
|
|
58
|
+
/** Sleep implementation override (for tests). */
|
|
59
|
+
sleep?: (ms: number) => Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
type HttpMethod = "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
|
|
62
|
+
export declare const DEFAULT_TIMEOUT_MS = 30000;
|
|
63
|
+
export declare const MAX_RETRY_DELAY_MS = 30000;
|
|
64
|
+
export declare const MAX_CUMULATIVE_UPSTREAM_JSON_BYTES: number;
|
|
65
|
+
export declare const MAX_CUMULATIVE_RAW_RESPONSE_BYTES: number;
|
|
66
|
+
export declare const DEFAULT_MAX_JSON_RESPONSE_BYTES: number;
|
|
67
|
+
export declare const MAX_ERROR_RESPONSE_BYTES: number;
|
|
68
|
+
/** Guidance appended to 401 errors on basic-auth profiles. */
|
|
69
|
+
export declare const BASIC_AUTH_401_HINT: string;
|
|
70
|
+
export declare const DEFAULT_MAX_CONCURRENT_REQUESTS = 4;
|
|
71
|
+
/**
|
|
72
|
+
* Bind one immutable execution-context signal and fresh atomic upstream byte
|
|
73
|
+
* budgets to cached clients without adding mutable state to the client/cache.
|
|
74
|
+
*/
|
|
75
|
+
export declare function runWithServiceNowRequestSignal<T>(signal: AbortSignal, operation: () => Promise<T>): Promise<T>;
|
|
12
76
|
export declare class ServiceNowClient {
|
|
13
|
-
private
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
post(path: string, body?: unknown): Promise<
|
|
19
|
-
patch(path: string, body?: unknown): Promise<
|
|
20
|
-
put(path: string, body?: unknown): Promise<
|
|
77
|
+
#private;
|
|
78
|
+
constructor(config: ServiceNowConfig, options?: ClientOptions);
|
|
79
|
+
get<T = ParsedJson>(path: string, params?: Record<string, string>): Promise<T | null>;
|
|
80
|
+
/** GET that also exposes the response status + headers (e.g. X-Total-Count). */
|
|
81
|
+
getWithMeta<T = ParsedJson>(path: string, params?: Record<string, string>): Promise<RequestResult<T>>;
|
|
82
|
+
post<T = ParsedJson>(path: string, body?: unknown): Promise<T | null>;
|
|
83
|
+
patch<T = ParsedJson>(path: string, body?: unknown): Promise<T | null>;
|
|
84
|
+
put<T = ParsedJson>(path: string, body?: unknown): Promise<T | null>;
|
|
21
85
|
delete(path: string): Promise<{
|
|
22
86
|
status: number;
|
|
23
87
|
}>;
|
|
24
88
|
/**
|
|
25
89
|
* POST binary data (for attachment uploads).
|
|
26
90
|
*/
|
|
27
|
-
postBinary(path: string, data: Buffer, contentType: string, params?: Record<string, string>): Promise<
|
|
91
|
+
postBinary<T = ParsedJson>(path: string, data: Buffer, contentType: string, params?: Record<string, string>): Promise<T>;
|
|
28
92
|
/**
|
|
29
93
|
* GET raw response (for attachment downloads).
|
|
30
94
|
*/
|
|
31
|
-
getRaw(path: string
|
|
95
|
+
getRaw(path: string, options?: {
|
|
96
|
+
readonly maxBytes?: number;
|
|
97
|
+
}): Promise<{
|
|
32
98
|
data: Buffer;
|
|
33
99
|
contentType: string;
|
|
34
100
|
}>;
|
|
101
|
+
/**
|
|
102
|
+
* Perform a JSON request and return the parsed body together with the
|
|
103
|
+
* response status and headers. The convenience methods above delegate here.
|
|
104
|
+
*/
|
|
105
|
+
requestWithMeta<T = ParsedJson>(method: HttpMethod, path: string, options?: {
|
|
106
|
+
params?: Record<string, string>;
|
|
107
|
+
body?: unknown;
|
|
108
|
+
}): Promise<RequestResult<T>>;
|
|
35
109
|
private buildUrl;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
110
|
+
/**
|
|
111
|
+
* fetch() with the full request policy applied: auth headers, timeout,
|
|
112
|
+
* bounded retries with backoff, Retry-After, and a single 401
|
|
113
|
+
* refresh-and-retry via the AuthProvider.
|
|
114
|
+
*/
|
|
115
|
+
private fetchWithPolicy;
|
|
116
|
+
private consumeErrorBody;
|
|
117
|
+
private buildHttpError;
|
|
39
118
|
}
|
|
119
|
+
/** Build an immutable, reflection-safe capability around a resolved client. */
|
|
120
|
+
export declare function createServiceNowOperations(client: ServiceNowOperations): ServiceNowOperations;
|
|
121
|
+
/**
|
|
122
|
+
* Parse a Retry-After header value into milliseconds.
|
|
123
|
+
* Supports both delta-seconds ("120") and HTTP-date forms.
|
|
124
|
+
* Returns undefined when the value is absent or unparseable.
|
|
125
|
+
*/
|
|
126
|
+
export declare function parseRetryAfterMs(value: string | null): number | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* Delay before retry `attempt` (1-based): the Retry-After header when
|
|
129
|
+
* present, otherwise exponential backoff with jitter. Capped at
|
|
130
|
+
* MAX_RETRY_DELAY_MS either way.
|
|
131
|
+
*/
|
|
132
|
+
export declare function retryDelayMs(retryAfter: string | null, attempt: number, baseDelayMs: number): number;
|
|
133
|
+
export {};
|
|
40
134
|
//# sourceMappingURL=client.d.ts.map
|