1import * as Alchemy from "alchemy";
2import * as Axiom from "alchemy/Axiom";
3import * as Output from "alchemy/Output";
4import { Effect } from "effect";
5import { Logs, Metrics, Traces } from "./Datasets.ts";
6
7export const IngestToken = Axiom.ApiToken(
8 "IngestToken",
9 Effect.all([Alchemy.Stack, Traces, Logs, Metrics]).pipe(
10 Effect.map(([stack, traces, logs, metrics]) => ({
11 name: `${stack.stage}-otel-ingest`,
12 description: `Ingest-only token for ${stack.stage} OTEL datasets`,
13 // Reference dataset Outputs (rather than literal strings) so Alchemy
14 // sequences the token after the datasets exist.
15 datasetCapabilities: Output.all(
16 traces.name,
17 logs.name,
18 metrics.name,
19 ).pipe(
20 Output.map(([t, l, m]) => ({
21 [t]: { ingest: ["create"] },
22 [l]: { ingest: ["create"] },
23 [m]: { ingest: ["create"] },
24 })),
25 ),
26 })),
27 ),
28);