The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import * as wafv2 from "@distilled.cloud/aws/wafv2"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import * as AWSBindings from "../AWSBindings.ts"; |
| 5 | import { retryOptimisticLock, withWafScope } from "./internal.ts"; |
| 6 | import type { IPSet } from "./IPSet.ts"; |
| 7 | import { UpdateIPSet, type UpdateIPSetRequest } from "./UpdateIPSet.ts"; |
| 8 | |
| 9 | /** |
| 10 | * Bespoke (multi-op) binding: reads the IP set for a fresh `LockToken`, |
| 11 | * applies the full-replacement update, and retries optimistic-lock |
| 12 | * conflicts by re-reading. |
| 13 | */ |
| 14 | export const UpdateIPSetHttp = Layer.effect( |
| 15 | UpdateIPSet, |
| 16 | Effect.gen(function* () { |
| 17 | const bind = yield* AWSBindings.Bind; |
| 18 | const get = yield* AWSBindings.withCredentials(wafv2.getIPSet); |
| 19 | const update = yield* AWSBindings.withCredentials(wafv2.updateIPSet); |
| 20 | |
| 21 | return Effect.fn(function* (ipSet: IPSet) { |
| 22 | const Name = yield* ipSet.ipSetName; |
| 23 | const Id = yield* ipSet.ipSetId; |
| 24 | const Scope = yield* ipSet.scope; |
| 25 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 26 | yield* bind`AWS.WAFv2.UpdateIPSet(${ipSet})`({ |
| 27 | policyStatements: [ |
| 28 | { |
| 29 | Effect: "Allow", |
| 30 | Action: ["wafv2:GetIPSet", "wafv2:UpdateIPSet"], |
| 31 | Resource: [ipSet.ipSetArn], |
| 32 | }, |
| 33 | ], |
| 34 | }); |
| 35 | } |
| 36 | return Effect.fn(`AWS.WAFv2.UpdateIPSet(${ipSet.LogicalId})`)(function* ( |
| 37 | request: UpdateIPSetRequest, |
| 38 | ) { |
| 39 | const scope = yield* Scope; |
| 40 | const key = { Name: yield* Name, Scope: scope, Id: yield* Id }; |
| 41 | return yield* retryOptimisticLock( |
| 42 | withWafScope( |
| 43 | scope, |
| 44 | Effect.gen(function* () { |
| 45 | const fresh = yield* get(key); |
| 46 | return yield* update({ |
| 47 | ...key, |
| 48 | Addresses: request.addresses, |
| 49 | Description: request.description ?? fresh.IPSet?.Description, |
| 50 | LockToken: fresh.LockToken ?? "", |
| 51 | }); |
| 52 | }), |
| 53 | ), |
| 54 | ); |
| 55 | }); |
| 56 | }); |
| 57 | }), |
| 58 | ); |