@mcp-consultant-tools/rest-api 32.0.0 → 34.0.0-beta.2
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/build/cli.js +0 -0
- package/build/context-factory.d.ts.map +1 -1
- package/build/context-factory.js +5 -0
- package/build/context-factory.js.map +1 -1
- package/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +5 -107
- package/build/index.js.map +1 -1
- package/build/models/api-types.d.ts +9 -1
- package/build/models/api-types.d.ts.map +1 -1
- package/build/services/rest-api-service.d.ts +15 -0
- package/build/services/rest-api-service.d.ts.map +1 -1
- package/build/services/rest-api-service.js +59 -1
- package/build/services/rest-api-service.js.map +1 -1
- package/build/tool-examples.js +1 -1
- package/build/tools/rest-tools.js +1 -1
- package/build/tools/rest-tools.js.map +1 -1
- package/package.json +2 -2
- package/build/RestApiService.d.ts +0 -226
- package/build/RestApiService.d.ts.map +0 -1
- package/build/RestApiService.js +0 -585
- package/build/RestApiService.js.map +0 -1
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* REST API Service
|
|
3
|
-
*
|
|
4
|
-
* Provides HTTP request functionality with multiple authentication methods:
|
|
5
|
-
* - Static Bearer Token
|
|
6
|
-
* - Basic Authentication
|
|
7
|
-
* - API Key (custom header)
|
|
8
|
-
* - OAuth2 Client Credentials Flow (JWT generation)
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Endpoint definition for API discovery
|
|
12
|
-
*/
|
|
13
|
-
export interface EndpointDefinition {
|
|
14
|
-
/** Endpoint path (e.g., "/users", "/sic_exams") */
|
|
15
|
-
path: string;
|
|
16
|
-
/** Supported HTTP methods */
|
|
17
|
-
methods: ("GET" | "POST" | "PUT" | "DELETE" | "PATCH")[];
|
|
18
|
-
/** Entity name (singular) if applicable */
|
|
19
|
-
entityName?: string;
|
|
20
|
-
/** Human-readable description */
|
|
21
|
-
description?: string;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Field definition for entity schema
|
|
25
|
-
*/
|
|
26
|
-
export interface FieldDefinition {
|
|
27
|
-
/** Field name */
|
|
28
|
-
name: string;
|
|
29
|
-
/** Data type (e.g., "string", "Guid", "int", "datetime", "decimal") */
|
|
30
|
-
type: string;
|
|
31
|
-
/** Whether the field is required for creation */
|
|
32
|
-
required: boolean;
|
|
33
|
-
/** Whether the field can be null */
|
|
34
|
-
nullable: boolean;
|
|
35
|
-
/** Maximum length for string fields */
|
|
36
|
-
maxLength?: number;
|
|
37
|
-
/** Human-readable description */
|
|
38
|
-
description?: string;
|
|
39
|
-
/** Foreign key reference */
|
|
40
|
-
foreignKey?: {
|
|
41
|
-
entity: string;
|
|
42
|
-
field: string;
|
|
43
|
-
};
|
|
44
|
-
/** Enum/option set values */
|
|
45
|
-
enumValues?: string[];
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Entity schema definition
|
|
49
|
-
*/
|
|
50
|
-
export interface EntitySchema {
|
|
51
|
-
/** Entity name (singular) */
|
|
52
|
-
entityName: string;
|
|
53
|
-
/** Plural name for the endpoint */
|
|
54
|
-
pluralName: string;
|
|
55
|
-
/** Endpoint path */
|
|
56
|
-
endpoint: string;
|
|
57
|
-
/** Primary key field name */
|
|
58
|
-
primaryKey: string;
|
|
59
|
-
/** Field definitions */
|
|
60
|
-
fields: FieldDefinition[];
|
|
61
|
-
/** Example object for creating/updating */
|
|
62
|
-
example?: Record<string, any>;
|
|
63
|
-
}
|
|
64
|
-
export interface RestApiConfig {
|
|
65
|
-
/** Base URL for all requests (e.g., "https://api.example.com/v1") */
|
|
66
|
-
baseUrl: string;
|
|
67
|
-
/** Response size limit in bytes (default: 10000) */
|
|
68
|
-
responseSizeLimit?: number;
|
|
69
|
-
/** Enable SSL certificate verification (default: true) */
|
|
70
|
-
enableSslVerify?: boolean;
|
|
71
|
-
/** Static bearer token (mutually exclusive with oauth2) */
|
|
72
|
-
bearerToken?: string;
|
|
73
|
-
/** Basic auth credentials */
|
|
74
|
-
basicAuth?: {
|
|
75
|
-
username: string;
|
|
76
|
-
password: string;
|
|
77
|
-
};
|
|
78
|
-
/** API key authentication */
|
|
79
|
-
apiKey?: {
|
|
80
|
-
headerName: string;
|
|
81
|
-
value: string;
|
|
82
|
-
};
|
|
83
|
-
/** OAuth2 client credentials configuration */
|
|
84
|
-
oauth2?: {
|
|
85
|
-
/** Token endpoint URL (e.g., "https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token") */
|
|
86
|
-
tokenUrl: string;
|
|
87
|
-
/** OAuth2 Client ID */
|
|
88
|
-
clientId: string;
|
|
89
|
-
/** OAuth2 Client Secret */
|
|
90
|
-
clientSecret: string;
|
|
91
|
-
/** OAuth2 Scope (e.g., "https://api.example.com/.default") */
|
|
92
|
-
scope: string;
|
|
93
|
-
/** Optional grant type (defaults to "client_credentials") */
|
|
94
|
-
grantType?: string;
|
|
95
|
-
/** Optional additional token request parameters */
|
|
96
|
-
additionalParams?: Record<string, string>;
|
|
97
|
-
};
|
|
98
|
-
/** Custom headers to include in all requests */
|
|
99
|
-
customHeaders?: Record<string, string>;
|
|
100
|
-
/** Request timeout in milliseconds (default: 30000) */
|
|
101
|
-
timeout?: number;
|
|
102
|
-
/** URL to fetch OpenAPI/Swagger spec for dynamic discovery */
|
|
103
|
-
openApiUrl?: string;
|
|
104
|
-
}
|
|
105
|
-
export interface RequestOptions {
|
|
106
|
-
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
107
|
-
endpoint: string;
|
|
108
|
-
body?: any;
|
|
109
|
-
headers?: Record<string, string>;
|
|
110
|
-
/** Override base URL for this request only */
|
|
111
|
-
host?: string;
|
|
112
|
-
}
|
|
113
|
-
export interface RequestResult {
|
|
114
|
-
request: {
|
|
115
|
-
url: string;
|
|
116
|
-
method: string;
|
|
117
|
-
headers: Record<string, string>;
|
|
118
|
-
body?: any;
|
|
119
|
-
authMethod: string;
|
|
120
|
-
};
|
|
121
|
-
response: {
|
|
122
|
-
statusCode: number;
|
|
123
|
-
statusText: string;
|
|
124
|
-
timing: string;
|
|
125
|
-
headers: Record<string, any>;
|
|
126
|
-
body: any;
|
|
127
|
-
};
|
|
128
|
-
validation: {
|
|
129
|
-
isError: boolean;
|
|
130
|
-
messages: string[];
|
|
131
|
-
truncated?: {
|
|
132
|
-
originalSize: number;
|
|
133
|
-
returnedSize: number;
|
|
134
|
-
truncationPoint: number;
|
|
135
|
-
sizeLimit: number;
|
|
136
|
-
};
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
export declare class RestApiService {
|
|
140
|
-
private config;
|
|
141
|
-
private cachedToken;
|
|
142
|
-
private httpsAgent;
|
|
143
|
-
private cachedOpenApi;
|
|
144
|
-
private openApiFetchPromise;
|
|
145
|
-
/** OpenAPI cache TTL in milliseconds (default: 5 minutes) */
|
|
146
|
-
private static readonly OPENAPI_CACHE_TTL;
|
|
147
|
-
constructor(config: RestApiConfig);
|
|
148
|
-
/**
|
|
149
|
-
* Get the current authentication method name
|
|
150
|
-
*/
|
|
151
|
-
getAuthMethod(): string;
|
|
152
|
-
/**
|
|
153
|
-
* Get OAuth2 access token using client credentials flow
|
|
154
|
-
* Caches token and refreshes when expired
|
|
155
|
-
*/
|
|
156
|
-
private getOAuth2Token;
|
|
157
|
-
/**
|
|
158
|
-
* Get the Authorization header value based on configured auth method
|
|
159
|
-
*/
|
|
160
|
-
private getAuthHeader;
|
|
161
|
-
/**
|
|
162
|
-
* Sanitize headers for display (redact sensitive values)
|
|
163
|
-
*/
|
|
164
|
-
private sanitizeHeaders;
|
|
165
|
-
/**
|
|
166
|
-
* Execute an HTTP request
|
|
167
|
-
*/
|
|
168
|
-
request(options: RequestOptions): Promise<RequestResult>;
|
|
169
|
-
/**
|
|
170
|
-
* Force refresh the OAuth2 token (clears cache)
|
|
171
|
-
*/
|
|
172
|
-
clearTokenCache(): void;
|
|
173
|
-
/**
|
|
174
|
-
* Get configuration summary (safe to display)
|
|
175
|
-
*/
|
|
176
|
-
getConfigSummary(): {
|
|
177
|
-
baseUrl: string;
|
|
178
|
-
authMethod: string;
|
|
179
|
-
sslVerification: boolean;
|
|
180
|
-
responseSizeLimit: number;
|
|
181
|
-
customHeaderCount: number;
|
|
182
|
-
oauth2TokenUrl?: string;
|
|
183
|
-
openApiUrl?: string;
|
|
184
|
-
};
|
|
185
|
-
/**
|
|
186
|
-
* Check if OpenAPI URL is configured
|
|
187
|
-
*/
|
|
188
|
-
hasOpenApiConfig(): boolean;
|
|
189
|
-
/**
|
|
190
|
-
* Fetch and parse OpenAPI spec from configured URL
|
|
191
|
-
* Results are cached for OPENAPI_CACHE_TTL
|
|
192
|
-
*/
|
|
193
|
-
private fetchOpenApiSpec;
|
|
194
|
-
/**
|
|
195
|
-
* Actually fetch and parse the OpenAPI spec
|
|
196
|
-
*/
|
|
197
|
-
private doFetchOpenApiSpec;
|
|
198
|
-
/**
|
|
199
|
-
* Parse OpenAPI 3.x spec into our internal format
|
|
200
|
-
*/
|
|
201
|
-
private parseOpenApiSpec;
|
|
202
|
-
/**
|
|
203
|
-
* Map OpenAPI type to simplified type string
|
|
204
|
-
*/
|
|
205
|
-
private mapOpenApiType;
|
|
206
|
-
/**
|
|
207
|
-
* Clear OpenAPI cache (forces re-fetch on next call)
|
|
208
|
-
*/
|
|
209
|
-
clearOpenApiCache(): void;
|
|
210
|
-
/**
|
|
211
|
-
* List all available API endpoints from OpenAPI spec
|
|
212
|
-
* @param filter Optional filter to match endpoint paths (case-insensitive contains match)
|
|
213
|
-
*/
|
|
214
|
-
listEndpointsAsync(filter?: string): Promise<{
|
|
215
|
-
baseUrl: string;
|
|
216
|
-
endpointCount: number;
|
|
217
|
-
endpoints: EndpointDefinition[];
|
|
218
|
-
source: string;
|
|
219
|
-
}>;
|
|
220
|
-
/**
|
|
221
|
-
* Get schema for a specific entity from OpenAPI spec
|
|
222
|
-
* @param entity Entity name (singular or plural)
|
|
223
|
-
*/
|
|
224
|
-
getSchemaAsync(entity: string): Promise<EntitySchema | null>;
|
|
225
|
-
}
|
|
226
|
-
//# sourceMappingURL=RestApiService.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RestApiService.d.ts","sourceRoot":"","sources":["../src/RestApiService.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,6BAA6B;IAC7B,OAAO,EAAE,CAAC,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC,EAAE,CAAC;IACzD,2CAA2C;IAC3C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iCAAiC;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,iBAAiB;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,QAAQ,EAAE,OAAO,CAAC;IAClB,oCAAoC;IACpC,QAAQ,EAAE,OAAO,CAAC;IAClB,uCAAuC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iCAAiC;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4BAA4B;IAC5B,UAAU,CAAC,EAAE;QACX,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF,6BAA6B;IAC7B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,6BAA6B;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,mCAAmC;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,oBAAoB;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,6BAA6B;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,wBAAwB;I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