(
ctx: ServiceSyncContext,
service: KonnectService,
existingWorkspace: Workspace | undefined,
counts: { services: SyncCounts; routes: SyncCounts },
skippedRoutes: SkippedRoute[],
)
| 421 | } |
| 422 | |
| 423 | async function syncServiceWorkspace( |
| 424 | ctx: ServiceSyncContext, |
| 425 | service: KonnectService, |
| 426 | existingWorkspace: Workspace | undefined, |
| 427 | counts: { services: SyncCounts; routes: SyncCounts }, |
| 428 | skippedRoutes: SkippedRoute[], |
| 429 | ): Promise<void> { |
| 430 | const { pat, controlPlane, project, region, globalEnvironmentId, signal, onProgress } = ctx; |
| 431 | |
| 432 | const serviceName = service.name ?? `Gateway Service ${service.id}`; |
| 433 | |
| 434 | // Upsert workspace for this service |
| 435 | let workspace: Workspace; |
| 436 | if (existingWorkspace) { |
| 437 | if (existingWorkspace.name !== serviceName) { |
| 438 | workspace = await insoservices.workspace.update(existingWorkspace, { name: serviceName }); |
| 439 | counts.services.updated++; |
| 440 | } else { |
| 441 | workspace = existingWorkspace; |
| 442 | } |
| 443 | } else { |
| 444 | workspace = await insoservices.workspace.create({ |
| 445 | parentId: project._id, |
| 446 | name: serviceName, |
| 447 | scope: 'collection', |
| 448 | konnectServiceId: service.id, |
| 449 | }); |
| 450 | counts.services.created++; |
| 451 | } |
| 452 | counts.services.total++; |
| 453 | |
| 454 | // Set project-level env as the active global env for this workspace |
| 455 | const workspaceMeta = await insoservices.workspaceMeta.getOrCreateByParentId(workspace._id); |
| 456 | if (workspaceMeta.activeGlobalEnvironmentId !== globalEnvironmentId) { |
| 457 | await insoservices.workspaceMeta.update(workspaceMeta, { activeGlobalEnvironmentId: globalEnvironmentId }); |
| 458 | } |
| 459 | await insoservices.cookieJar.getOrCreateForParentId(workspace._id); |
| 460 | |
| 461 | const incomingRoutes = (await fetchRoutesForService(pat, controlPlane.id, service.id, region, signal)).map( |
| 462 | sanitizeRoute, |
| 463 | ); |
| 464 | const existingData = await loadExistingRequestData(workspace._id); |
| 465 | const incomingKeys = new Set<string>(); |
| 466 | const incomingRouteIds = new Set<string>(); |
| 467 | |
| 468 | for (const route of incomingRoutes) { |
| 469 | signal?.throwIfAborted(); |
| 470 | incomingRouteIds.add(route.id); |
| 471 | |
| 472 | const expressionResult = applyExpressionFields(route); |
| 473 | if (!expressionResult.syncable) { |
| 474 | counts.routes.skipped++; |
| 475 | skippedRoutes.push({ routeName: expressionResult.routeName, reason: expressionResult.reason, serviceName }); |
| 476 | continue; |
| 477 | } |
| 478 | const effectiveRoute = expressionResult.route; |
| 479 | |
| 480 | const isL4 = effectiveRoute.protocols.every(p => L4_PROTOCOLS.has(p)); |
no test coverage detected