MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / usageEvents

Function usageEvents

e2e/src/surfaces/autumn.ts:90–122  ·  view source on GitHub ↗
(query: UsageQuery)

Source from the content-addressed store, hash-verified

88
89export const makeAutumnSurface = (autumnUrl: string): AutumnSurface => {
90 const usageEvents = (query: UsageQuery) =>
91 Effect.gen(function* () {
92 // The emulator's ledger endpoint returns every recorded track event;
93 // filter to this customer + feature. (autumn-js drives /v1/* RPC-style.)
94 const response = yield* Effect.promise(() =>
95 fetch(`${autumnUrl}/v1/events.list`, {
96 method: "POST",
97 headers: { "content-type": "application/json" },
98 body: "{}",
99 }),
100 );
101 if (!response.ok) {
102 return yield* Effect.fail(
103 `autumn events.list responded ${response.status}: ${yield* Effect.promise(() => response.text())}`,
104 );
105 }
106 const body = (yield* Effect.promise(() => response.json())) as {
107 readonly list?: ReadonlyArray<{
108 readonly customer_id: string;
109 readonly feature_id: string;
110 readonly value: number;
111 }>;
112 };
113 return (body.list ?? [])
114 .filter(
115 (event) => event.customer_id === query.customerId && event.feature_id === query.featureId,
116 )
117 .map((event) => ({
118 customerId: event.customer_id,
119 featureId: event.feature_id,
120 value: event.value,
121 }));
122 });
123
124 const settleCheckout = (sessionId: string) =>
125 Effect.gen(function* () {

Callers 1

makeAutumnSurfaceFunction · 0.85

Calls 3

textMethod · 0.65
jsonMethod · 0.65
fetchFunction · 0.50

Tested by

no test coverage detected