(options: {
serverUrl: string
apiKey: string
path: string
method: string
body?: unknown
query?: string
})
| 330 | |
| 331 | /** Proxy a request to the 1Password Connect Server. */ |
| 332 | export async function connectRequest(options: { |
| 333 | serverUrl: string |
| 334 | apiKey: string |
| 335 | path: string |
| 336 | method: string |
| 337 | body?: unknown |
| 338 | query?: string |
| 339 | }): Promise<ConnectResponse> { |
| 340 | const resolvedIP = await validateConnectServerUrl(options.serverUrl) |
| 341 | |
| 342 | const base = options.serverUrl.replace(/\/$/, '') |
| 343 | const queryStr = options.query ? `?${options.query}` : '' |
| 344 | const url = `${base}${options.path}${queryStr}` |
| 345 | |
| 346 | const headers: Record<string, string> = { |
| 347 | Authorization: `Bearer ${options.apiKey}`, |
| 348 | } |
| 349 | |
| 350 | if (options.body) { |
| 351 | headers['Content-Type'] = 'application/json' |
| 352 | } |
| 353 | |
| 354 | return secureFetchWithPinnedIP(url, resolvedIP, { |
| 355 | method: options.method, |
| 356 | headers, |
| 357 | body: options.body ? JSON.stringify(options.body) : undefined, |
| 358 | allowHttp: true, |
| 359 | }) |
| 360 | } |
| 361 | |
| 362 | /** Normalize an SDK VaultOverview to match Connect API vault shape. */ |
| 363 | export function normalizeSdkVault(vault: VaultOverview): NormalizedVault { |
no test coverage detected