@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
ts 82 lines 2.73 KB
Raw
1 import * as appsignals from "@distilled.cloud/aws/application-signals";
2 import * as Provider from "alchemy/Provider";
3 import { Resource } from "alchemy/Resource";
4 import * as Effect from "effect/Effect";
5 import { AWSEnvironment } from "../Environment.ts";
6 import type { Providers } from "../Providers.ts";
7
8 export interface DiscoveryProps {}
9
10 export interface Discovery extends Resource<
11 "AWS.ApplicationSignals.Discovery",
12 DiscoveryProps,
13 {
14 /**
15 * The AWS account in which Application Signals discovery was enabled.
16 */
17 accountId: string;
18 /**
19 * The region in which Application Signals discovery was enabled.
20 */
21 region: string;
22 },
23 never,
24 Providers
25 > {}
26
27 /**
28 * Enables CloudWatch Application Signals for this account by creating the
29 * `AWSServiceRoleForCloudWatchApplicationSignals` service-linked role and the
30 * service-linked CloudTrail event channel used for change-event correlation
31 * (mirrors CloudFormation's `AWS::ApplicationSignals::Discovery`).
32 *
33 * `StartDiscovery` is idempotent, and AWS provides no API to disable
34 * discovery or observe its enablement, so this resource is
35 * provision-only: deleting it from the stack leaves discovery enabled
36 * (the delete is a no-op, matching CloudFormation's behavior).
37 *
38 * ### Enabling Application Signals
39 * **Example:** Enable Discovery for the Account
40 * ```typescript
41 * import * as AWS from "@alchemy.run/aws";
42 *
43 * const discovery = yield* AWS.ApplicationSignals.Discovery("Discovery", {});
44 * ```
45 *
46 * @resource
47 */
48 export const Discovery = Resource<Discovery>("AWS.ApplicationSignals.Discovery");
49
50 export const DiscoveryProvider = () =>
51 Provider.effect(
52 Discovery,
53 Effect.gen(function* () {
54 return {
55 stables: ["accountId", "region"],
56
57 read: Effect.fn(function* ({ output }) {
58 // There is no API to observe whether discovery is enabled — echo
59 // the recorded state; a lost state falls through to a (harmless,
60 // idempotent) re-enable on the next reconcile.
61 return output;
62 }),
63
64 reconcile: Effect.fn(function* ({ session }) {
65 const { accountId, region } = yield* AWSEnvironment.current;
66 // StartDiscovery is idempotent: re-enabling an already-enabled
67 // account succeeds without side effects.
68 yield* appsignals.startDiscovery({});
69 yield* session.note(`application-signals discovery ${accountId}`);
70 return { accountId, region };
71 }),
72
73 delete: Effect.fn(function* () {
74 // Discovery cannot be disabled via API — deletion is a no-op
75 // (CloudFormation's AWS::ApplicationSignals::Discovery behaves the
76 // same way).
77 }),
78
79 list: () => Effect.succeed([]),
80 };
81 }),
82 );