MCPcopy
hub / github.com/Kong/insomnia / syncHttpRoute

Function syncHttpRoute

packages/insomnia/src/konnect/sync.ts:284–358  ·  view source on GitHub ↗
(
  route: KonnectRoute,
  workspaceId: string,
  headers: { name: string; value: string }[],
  existingByKey: Map<string, Request>,
  routeCounts: SyncCounts,
  incomingKeys: Set<string>,
)

Source from the content-addressed store, hash-verified

282}
283
284async function syncHttpRoute(
285 route: KonnectRoute,
286 workspaceId: string,
287 headers: { name: string; value: string }[],
288 existingByKey: Map<string, Request>,
289 routeCounts: SyncCounts,
290 incomingKeys: Set<string>,
291): Promise<void> {
292 const methods = route.methods ?? ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'];
293 const paths = route.paths ?? [null];
294 const httpProtocols = route.protocols.filter(p => p === 'http' || p === 'https') as ('http' | 'https')[];
295 const multiProtocol = httpProtocols.length > 1;
296 const needsSubFolders = multiProtocol || paths.length > 1;
297
298 const routeFolderId = await upsertRouteFolder(workspaceId, routeDisplayName(route), route.id);
299
300 for (const routePath of paths) {
301 const { path: resolvedPath, pathParameters } = resolvePath(routePath);
302 const pathSegment = routePath ?? '';
303 const baseName = buildRequestName({ ...route, paths: routePath !== null ? [routePath] : null });
304
305 for (const protocol of httpProtocols) {
306 let parentId = routeFolderId;
307 if (needsSubFolders) {
308 const subFolderName = multiProtocol ? `${protocol.toUpperCase()} ${baseName}` : baseName;
309 parentId = await upsertFolder(routeFolderId, subFolderName, route.id);
310 }
311
312 for (const method of methods) {
313 const key = `${route.id}:${method}:${pathSegment}:${protocol}`;
314 incomingKeys.add(key);
315 routeCounts.total++;
316
317 const url = `${protocol}://{{ _.proxy_host }}${resolvedPath}`;
318 const name = baseName;
319 const existing = existingByKey.get(key);
320
321 const konnectManagedHeaderNames = headers.map(h => h.name);
322 if (existing) {
323 const merged = mergeHeaders(existing.headers ?? [], headers, existing.konnectManagedHeaderNames ?? []);
324 const mergedPathParams = mergePathParameters(existing.pathParameters ?? [], pathParameters);
325 if (
326 existing.method !== method ||
327 existing.url !== url ||
328 existing.name !== name ||
329 konnectHeadersChanged(existing.headers ?? [], headers, existing.konnectManagedHeaderNames ?? []) ||
330 pathParametersChanged(existing.pathParameters ?? [], pathParameters)
331 ) {
332 await insoservices.request.update(existing, {
333 method,
334 url,
335 name,
336 headers: merged,
337 pathParameters: mergedPathParams,
338 konnectManagedHeaderNames,
339 });
340 routeCounts.updated++;
341 }

Callers 1

syncServiceWorkspaceFunction · 0.85

Calls 15

routeDisplayNameFunction · 0.90
resolvePathFunction · 0.90
buildRequestNameFunction · 0.90
mergeHeadersFunction · 0.90
mergePathParametersFunction · 0.90
konnectHeadersChangedFunction · 0.90
pathParametersChangedFunction · 0.90
upsertRouteFolderFunction · 0.85
upsertFolderFunction · 0.85
mapMethod · 0.80
updateMethod · 0.65
filterMethod · 0.45

Tested by

no test coverage detected