| author | |
| committer | |
| log | 477b4f9d0ec7e7a48cb74357ea00ecf7bddfc62f |
| tree | 9ab54bd81a91cda272bd193f8a0ae5e1aaee94f7 |
| parent | d5d88270f0d9cdc9797a650ed6ccace28cb1dc39 |
- move `AnalyticsServiceLayerLive` from CLI runtime setup into `main` server layer
- persist telemetry `anonymous-id` under configured `stateDir` instead of home directory
- add `FetchHttpClient.layer` to `main.test.ts` test layer wiring4 files changed, 7 insertions(+), 3 deletions(-)
apps/server/src/index.ts-2| ... | ... | @@ -9,12 +9,10 @@ import { Command } from "effect/unstable/cli"; |
| 9 | 9 | import { version } from "../package.json" with { type: "json" }; |
| 10 | 10 | import { ServerLive } from "./wsServer"; |
| 11 | 11 | import { NetService } from "@t3tools/shared/Net"; |
| 12 | import { AnalyticsServiceLayerLive } from "./telemetry/Layers/AnalyticsService"; | |
| 13 | 12 | import { FetchHttpClient } from "effect/unstable/http"; |
| 14 | 13 | |
| 15 | 14 | const RuntimeLayer = Layer.empty.pipe( |
| 16 | 15 | Layer.provideMerge(CliConfig.layer), |
| 17 | Layer.provideMerge(AnalyticsServiceLayerLive), | |
| 18 | 16 | Layer.provideMerge(ServerLive), |
| 19 | 17 | Layer.provideMerge(OpenLive), |
| 20 | 18 | Layer.provideMerge(NetService.layer), |
apps/server/src/main.test.ts+2| ... | ... | @@ -5,6 +5,7 @@ import * as ConfigProvider from "effect/ConfigProvider"; |
| 5 | 5 | import * as Effect from "effect/Effect"; |
| 6 | 6 | import * as Layer from "effect/Layer"; |
| 7 | 7 | import * as Command from "effect/unstable/cli/Command"; |
| 8 | import { FetchHttpClient } from "effect/unstable/http"; | |
| 8 | 9 | import { beforeEach } from "vitest"; |
| 9 | 10 | import { NetService } from "@t3tools/shared/Net"; |
| 10 | 11 | |
| ... | ... | @@ -52,6 +53,7 @@ const testLayer = Layer.mergeAll( |
| 52 | 53 | record: () => Effect.void, |
| 53 | 54 | flush: Effect.void, |
| 54 | 55 | }), |
| 56 | FetchHttpClient.layer, | |
| 55 | 57 | NodeServices.layer, |
| 56 | 58 | ); |
| 57 | 59 |
apps/server/src/main.ts+2| ... | ... | @@ -23,6 +23,7 @@ import { makeServerProviderLayer, makeServerRuntimeServicesLayer } from "./serve |
| 23 | 23 | import { ProviderHealthLive } from "./provider/Layers/ProviderHealth"; |
| 24 | 24 | import { Server } from "./wsServer"; |
| 25 | 25 | import { ServerLoggerLive } from "./serverLogger"; |
| 26 | import { AnalyticsServiceLayerLive } from "./telemetry/Layers/AnalyticsService"; | |
| 26 | 27 | |
| 27 | 28 | export class StartupError extends Data.TaggedError("StartupError")<{ |
| 28 | 29 | readonly message: string; |
| ... | ... | @@ -197,6 +198,7 @@ const LayerLive = (input: CliInput) => |
| 197 | 198 | Layer.provideMerge(ProviderHealthLive), |
| 198 | 199 | Layer.provideMerge(SqlitePersistence.layerConfig), |
| 199 | 200 | Layer.provideMerge(ServerLoggerLive), |
| 201 | Layer.provideMerge(AnalyticsServiceLayerLive), | |
| 200 | 202 | Layer.provideMerge(ServerConfigLive(input)), |
| 201 | 203 | ); |
| 202 | 204 |
apps/server/src/telemetry/Identify.ts+3-1| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | import { Effect, FileSystem, Path, Random, Schema } from "effect"; |
| 2 | 2 | import * as Crypto from "node:crypto"; |
| 3 | 3 | import { homedir } from "node:os"; |
| 4 | import { ServerConfig } from "../config"; | |
| 4 | 5 | |
| 5 | 6 | const CodexAuthJsonSchema = Schema.Struct({ |
| 6 | 7 | tokens: Schema.Struct({ |
| ... | ... | @@ -39,8 +40,9 @@ const getCodexAccountId = Effect.gen(function* () { |
| 39 | 40 | const upsertAnonymousId = Effect.gen(function* () { |
| 40 | 41 | const fileSystem = yield* FileSystem.FileSystem; |
| 41 | 42 | const path = yield* Path.Path; |
| 43 | const serverConfig = yield* ServerConfig; | |
| 42 | 44 | |
| 43 | const anonymousIdPath = path.join(homedir(), ".t3", "telemetry", "anonymous-id"); | |
| 45 | const anonymousIdPath = path.join(serverConfig.stateDir, "anonymous-id"); | |
| 44 | 46 | const anonymousId = yield* fileSystem.readFileString(anonymousIdPath).pipe( |
| 45 | 47 | Effect.catch(() => |
| 46 | 48 | Effect.gen(function* () { |