( params: AgiloftBaseParams, buildRequest: (base: string) => AgiloftRequestConfig, transformResponse: (response: SecureFetchResponse) => Promise<R> )
| 105 | * Server-only — uses node:dns/promises and node:http(s) via the pinned fetch. |
| 106 | */ |
| 107 | export async function executeAgiloftRequest<R extends ToolResponse>( |
| 108 | params: AgiloftBaseParams, |
| 109 | buildRequest: (base: string) => AgiloftRequestConfig, |
| 110 | transformResponse: (response: SecureFetchResponse) => Promise<R> |
| 111 | ): Promise<R> { |
| 112 | const resolvedIP = await resolveAgiloftInstance(params.instanceUrl) |
| 113 | const token = await agiloftLoginPinned(params, resolvedIP) |
| 114 | const base = params.instanceUrl.replace(/\/$/, '') |
| 115 | |
| 116 | try { |
| 117 | const req = buildRequest(base) |
| 118 | const response = await secureFetchWithPinnedIP(req.url, resolvedIP, { |
| 119 | method: req.method, |
| 120 | headers: { |
| 121 | ...req.headers, |
| 122 | Authorization: `Bearer ${token}`, |
| 123 | }, |
| 124 | body: req.body, |
| 125 | }) |
| 126 | return await transformResponse(response) |
| 127 | } finally { |
| 128 | await agiloftLogoutPinned(params.instanceUrl, params.knowledgeBase, token, resolvedIP) |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | export type { SecureFetchResponse } |
no test coverage detected