Repository navigation
Commit 87a474c
authored
feat: add createUsageTracking for shared CLI request headers (#176)
* feat: add createUsageTracking for shared CLI request headers
Every Doist CLI should identify itself to the backends the same way, so
API logs can tell CLI traffic apart and attribute it to a version, an OS,
one CLI run and the command that made the request. todoist-cli has its
own copy of this; comms-cli and automations-cli send only part of it.
createUsageTracking({ cliName, version }) returns a per-process tracker:
- headers() gives User-Agent, doist-platform, doist-version, doist-os,
a fresh request-id per call, a session-id fixed for the process and
cli-command.
- setCommand() takes the Commander command from a preAction hook and
labels it by its path below the program (td task add -> task:add), or
takes a string label for work outside Commander.
- mergeHeaders(init) merges the usage headers into a request's own,
winning over a caller header of the same name in any case.
request-id is separate from the X-Request-Id the Doist SDKs send. That
one is an idempotency key the caller controls and is absent on most
requests, so it can't double as a trace ID.
* fix: keep commander out of the root entry's types
setCommand took a Commander Command, so the emitted usage-tracking.d.ts
imported the optional commander peer and a consumer of the root entry
without it would fail to type-check. It now takes CommandLike, the
name() and parent that labelling reads, which a real Command satisfies.
A new root-entry test walks every module src/index.ts reaches and fails
if any imports an optional peer, type-only imports included.
The session ID is per tracker, not per process, so the README and docs
now say so and tell CLIs to create one tracker per process.1 parent 640b305 commit 87a474c
6 files changed
Lines changed: 403 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
0 commit comments