1import * as Effect from "effect/Effect";
2import * as Schedule from "effect/Schedule";
3
4/**
5 * Shared Amazon Macie provider scaffolding. NOT exported from `index.ts`.
6 */
7
8/**
9 * Macie enablement is eventually consistent — resource creation can briefly
10 * reject with the synthetic `MacieNotEnabled` tag right after the session is
11 * enabled. Retry on a bounded schedule (< 30s total). The explicit
12 * `Effect.Effect<A, E, R>` return annotation keeps `Retry.Return`'s
13 * conditional type out of declaration emit, which would otherwise widen the
14 * provider layer's `R` to `unknown` and poison every consumer of
15 * `AWS.providers()`.
16 */
17export const retryThroughEnablement = <A, E extends { _tag: string }, R>(
18 self: Effect.Effect<A, E, R>,
19): Effect.Effect<A, E, R> =>
20 Effect.retry(self, {
21 while: (e) => e._tag === "MacieNotEnabled",
22 schedule: Schedule.max([Schedule.spaced("3 seconds"), Schedule.recurs(8)]),
23 });