| 1 | import type * as cloudfront from "@distilled.cloud/aws/cloudfront"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { Distribution } from "./Distribution.ts"; |
| 5 | |
| 6 | export interface CreateInvalidationRequest extends Omit< |
| 7 | cloudfront.CreateInvalidationRequest, |
| 8 | "DistributionId" |
| 9 | > {} |
| 10 | |
| 11 | /** |
| 12 | * Grants a Function permission to create CloudFront cache invalidations for a |
| 13 | * distribution at runtime — the classic post-publish/CMS purge pattern. |
| 14 | * ### Invalidating from a Function |
| 15 | * **Example:** Purge Paths After a Content Update |
| 16 | * ```typescript |
| 17 | * const invalidate = yield* CloudFront.CreateInvalidation(distribution); |
| 18 | * |
| 19 | * const response = yield* invalidate({ |
| 20 | * InvalidationBatch: { |
| 21 | * CallerReference: crypto.randomUUID(), |
| 22 | * Paths: { Quantity: 1, Items: ["/blog/*"] }, |
| 23 | * }, |
| 24 | * }); |
| 25 | * // response.Invalidation?.Id |
| 26 | * ``` |
| 27 | * |
| 28 | * @binding |
| 29 | */ |
| 30 | export interface CreateInvalidation extends Binding.Service< |
| 31 | CreateInvalidation, |
| 32 | "AWS.CloudFront.CreateInvalidation", |
| 33 | ( |
| 34 | distribution: Distribution, |
| 35 | ) => Effect.Effect< |
| 36 | ( |
| 37 | request: CreateInvalidationRequest, |
| 38 | ) => Effect.Effect< |
| 39 | cloudfront.CreateInvalidationResult, |
| 40 | cloudfront.CreateInvalidationError |
| 41 | > |
| 42 | > |
| 43 | > {} |
| 44 | |
| 45 | export const CreateInvalidation = Binding.Service<CreateInvalidation>( |
| 46 | "AWS.CloudFront.CreateInvalidation", |
| 47 | ); |