The best way to control Claude Code, Codex and more from any computer or phone

main
ts 35 lines 1.46 KB
Raw
1 import * as securitylake from "@distilled.cloud/aws/securitylake";
2 import * as Effect from "effect/Effect";
3 import * as Schedule from "effect/Schedule";
4
5 /**
6 * Security Lake tags use lowercase `{ key, value }` wire members (unlike most
7 * AWS services' `{ Key, Value }`), so the generic Tags.ts converters don't
8 * apply directly.
9 */
10 export const toTagList = (tags: Record<string, string>): securitylake.Tag[] =>
11 Object.entries(tags).map(([key, value]) => ({ key, value }));
12
13 export const fromTagList = (
14 tags: readonly securitylake.Tag[] | undefined,
15 ): Record<string, string> => Object.fromEntries((tags ?? []).map((tag) => [tag.key, tag.value]));
16
17 /** Observed cloud tags for a Security Lake resource ARN ({} on any failure). */
18 export const readSecurityLakeTags = (resourceArn: string) =>
19 securitylake.listTagsForResource({ resourceArn }).pipe(
20 Effect.map((response) => fromTagList(response.tags)),
21 Effect.orElseSucceed(() => ({})),
22 );
23
24 /**
25 * Bounded retry through transient `ConflictException`s (e.g. a subscriber or
26 * data-lake mutation racing an in-flight update). Explicitly annotated so the
27 * `Retry.Return` conditional never leaks into declaration emit.
28 */
29 export const retryWhileConflict = <A, E extends { readonly _tag: string }, R>(
30 self: Effect.Effect<A, E, R>,
31 ): Effect.Effect<A, E, R> =>
32 Effect.retry(self, {
33 while: (error) => error._tag === "ConflictException",
34 schedule: Schedule.max([Schedule.fixed("5 seconds"), Schedule.recurs(8)]),
35 });