(
agent: AuthorizedAgentEntry,
normalizedDomain: string,
scope: NormalizedScope,
authorizedProperties: PropertyDefinition[],
placements: PlacementDefinition[],
placementTagDefinitions: Record<string, PlacementTagDefinition>
)
| 353 | } |
| 354 | |
| 355 | private matchesPlacements( |
| 356 | agent: AuthorizedAgentEntry, |
| 357 | normalizedDomain: string, |
| 358 | scope: NormalizedScope, |
| 359 | authorizedProperties: PropertyDefinition[], |
| 360 | placements: PlacementDefinition[], |
| 361 | placementTagDefinitions: Record<string, PlacementTagDefinition> |
| 362 | ): boolean { |
| 363 | const hasAgentPlacementScope = !!agent.placement_ids?.length || !!agent.placement_tags?.length; |
| 364 | const hasRequestedPlacementScope = !!scope.placement_ids?.length || !!scope.placement_tags?.length; |
| 365 | |
| 366 | if (!hasAgentPlacementScope && !hasRequestedPlacementScope) { |
| 367 | return true; |
| 368 | } |
| 369 | |
| 370 | const requestedPlacements = this.resolveRequestedPlacements( |
| 371 | normalizedDomain, |
| 372 | scope, |
| 373 | placements, |
| 374 | placementTagDefinitions |
| 375 | ); |
| 376 | if (requestedPlacements.length === 0) { |
| 377 | return false; |
| 378 | } |
| 379 | |
| 380 | const scopedPlacements = requestedPlacements.filter((placement) => |
| 381 | this.placementMatchesAuthorizedScope(placement, authorizedProperties, scope) |
| 382 | ); |
| 383 | if (scopedPlacements.length === 0) { |
| 384 | return false; |
| 385 | } |
| 386 | |
| 387 | if (agent.placement_ids?.length) { |
| 388 | const agentPlacementIds = new Set(agent.placement_ids); |
| 389 | if (!scopedPlacements.some((placement) => agentPlacementIds.has(placement.placement_id))) { |
| 390 | return false; |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | if (agent.placement_tags?.length) { |
| 395 | const scopedTags = new Set(scopedPlacements.flatMap((placement) => placement.tags || [])); |
| 396 | if (scopedTags.size === 0) { |
| 397 | return false; |
| 398 | } |
| 399 | if (!agent.placement_tags.some((tag) => scopedTags.has(tag))) { |
| 400 | return false; |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | return true; |
| 405 | } |
| 406 | |
| 407 | private matchesCountry(agent: AuthorizedAgentEntry, scope: NormalizedScope): boolean { |
| 408 | if (!agent.countries?.length) { |
no test coverage detected