The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as mi from "@distilled.cloud/aws/iot-managed-integrations"; |
| 2 | import { diffTags } from "alchemy/Tags"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as Redacted from "effect/Redacted"; |
| 5 | |
| 6 | /** |
| 7 | * Unwrap a distilled `SensitiveString` (`string | Redacted<string>`) into a |
| 8 | * plain string, preserving `undefined`. |
| 9 | */ |
| 10 | export const unwrapSensitive = ( |
| 11 | value: string | Redacted.Redacted<string> | undefined, |
| 12 | ): string | undefined => |
| 13 | value === undefined ? undefined : typeof value === "string" ? value : Redacted.value(value); |
| 14 | |
| 15 | /** |
| 16 | * Convert the wire `TagsMap` (`Record<string, string | undefined>`) into a |
| 17 | * plain `Record<string, string>`, dropping entries without a value. |
| 18 | */ |
| 19 | export const toTagRecord = ( |
| 20 | tags: { [key: string]: string | undefined } | undefined, |
| 21 | ): Record<string, string> => |
| 22 | Object.fromEntries( |
| 23 | Object.entries(tags ?? {}).filter( |
| 24 | (entry): entry is [string, string] => typeof entry[1] === "string", |
| 25 | ), |
| 26 | ); |
| 27 | |
| 28 | /** |
| 29 | * Reconcile the tags on an IoT Managed Integrations resource identified by |
| 30 | * ARN: diff OBSERVED cloud tags against the desired set and apply only the |
| 31 | * delta via tagResource/untagResource. |
| 32 | */ |
| 33 | export const syncManagedIntegrationsTags = Effect.fn(function* ( |
| 34 | resourceArn: string, |
| 35 | observedTags: Record<string, string>, |
| 36 | desiredTags: Record<string, string>, |
| 37 | ) { |
| 38 | const { upsert, removed } = diffTags(observedTags, desiredTags); |
| 39 | if (upsert.length > 0) { |
| 40 | yield* mi.tagResource({ |
| 41 | ResourceArn: resourceArn, |
| 42 | Tags: Object.fromEntries(upsert.map((tag) => [tag.Key, tag.Value])), |
| 43 | }); |
| 44 | } |
| 45 | if (removed.length > 0) { |
| 46 | yield* mi.untagResource({ ResourceArn: resourceArn, TagKeys: removed }); |
| 47 | } |
| 48 | }); |