All files / mgmt-lambda/utils cloudfrontUtils.ts

100% Statements 6/6
83.33% Branches 5/6
100% Functions 6/6
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27            8x             14x             8x   4x        
import type { CacheBehavior, DefaultCacheBehavior, DistributionConfig, Origin } from '@aws-sdk/client-cloudfront'
import { EventType } from '@aws-sdk/client-cloudfront'
import { defaults } from '../DefaultSettings.ts'
import type { LambdaFunctionAssociation } from '@aws-sdk/client-cloudfront'
 
export function getFPCDNOrigins(distributionConfig: DistributionConfig | undefined): Origin[] {
  return distributionConfig?.Origins?.Items?.filter((it) => it.DomainName === defaults.FP_CDN_URL) ?? []
}
 
export function doesCacheBehaviorUseOrigins(
  cacheBehavior: DefaultCacheBehavior | CacheBehavior | undefined,
  origins: Origin[]
): boolean {
  return origins.some((origin) => origin.Id === cacheBehavior?.TargetOriginId)
}
 
export function getCacheBehaviorLambdaFunctionAssociations(
  cacheBehavior: DefaultCacheBehavior | CacheBehavior | undefined,
  functionName: string
): LambdaFunctionAssociation[] {
  return (
    cacheBehavior?.LambdaFunctionAssociations?.Items?.filter(
      (it) => it.EventType === EventType.origin_request && it.LambdaFunctionARN?.includes(`${functionName}:`) === true
    ) ?? []
  )
}