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

Function loadOrMintAnonymousId

packages/core/analytics/src/analytics.ts:124–139  ·  view source on GitHub ↗
(
  dataDir: string,
)

Source from the content-addressed store, hash-verified

122// generate-and-persist secret.key shape, minus the secrecy — this id is not a
123// credential, it is the anonymous distinct_id the events file under).
124const loadOrMintAnonymousId = (
125 dataDir: string,
126): Effect.Effect<string, never, FileSystem.FileSystem> =>
127 Effect.gen(function* () {
128 const fs = yield* FileSystem.FileSystem;
129 const idPath = `${dataDir}/${ANALYTICS_ID_FILE}`;
130 const existing = yield* fs.readFileString(idPath).pipe(
131 Effect.map((raw) => raw.trim()),
132 Effect.catch(() => Effect.succeed("")),
133 );
134 if (existing.length > 0) return existing;
135 const minted = crypto.randomUUID();
136 yield* fs.makeDirectory(dataDir, { recursive: true }).pipe(Effect.ignore);
137 yield* fs.writeFileString(idPath, minted).pipe(Effect.ignore);
138 return minted;
139 });
140
141// ---------------------------------------------------------------------------
142// Layer

Callers 1

layerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected