@getargvio/argvio 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +120 -0
- package/dist/index.cjs +821 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +454 -0
- package/dist/index.d.ts +454 -0
- package/dist/index.js +785 -0
- package/dist/index.js.map +1 -0
- package/package.json +74 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 getargvio
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# @getargvio/argvio
|
|
2
|
+
|
|
3
|
+
A Node.js SDK for emitting CLI usage telemetry to Argvio's ingest
|
|
4
|
+
server, built around a tiered consent model that this package enforces
|
|
5
|
+
on the client side. Works standalone for any CLI; see
|
|
6
|
+
[`@getargvio/yargs`](https://www.npmjs.com/package/@getargvio/yargs) and
|
|
7
|
+
[`@getargvio/commander`](https://www.npmjs.com/package/@getargvio/commander)
|
|
8
|
+
for drop-in framework integrations.
|
|
9
|
+
|
|
10
|
+
> **Status:** pre-v0.1.0. The taxonomy field list and exact wire values
|
|
11
|
+
> for `cli.analytics.tier` mirror what the server-side allowlist is
|
|
12
|
+
> expected to look like, but have not yet been checked against that
|
|
13
|
+
> file directly (see `TODO(schema)` comments in `tier.ts` and
|
|
14
|
+
> `taxonomy.ts`). Treat the public API shape as stable, the exact wire
|
|
15
|
+
> values as provisional until that's confirmed.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm install @getargvio/argvio
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Requires Node.js 22+.
|
|
24
|
+
|
|
25
|
+
## Quickstart
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { createClient } from '@getargvio/argvio'
|
|
29
|
+
|
|
30
|
+
const client = createClient(process.env.MYCLI_ARGVIO_KEY ?? '', 'mycli', '1.4.0')
|
|
31
|
+
// client is always safe to use, even if construction hit a problem —
|
|
32
|
+
// check client.initError if you want to log why it degraded.
|
|
33
|
+
|
|
34
|
+
client.recordSessionStart()
|
|
35
|
+
process.on('exit', () => client.recordSessionEnd())
|
|
36
|
+
|
|
37
|
+
const start = Date.now()
|
|
38
|
+
try {
|
|
39
|
+
await runCommand()
|
|
40
|
+
client.recordExitCode('mycli run', 0)
|
|
41
|
+
} catch (err) {
|
|
42
|
+
client.recordExitCode('mycli run', 1)
|
|
43
|
+
client.recordError('mycli run', 'internal')
|
|
44
|
+
} finally {
|
|
45
|
+
client.recordLatency('mycli run', Date.now() - start)
|
|
46
|
+
await client.shutdown(3000)
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
For yargs or commander, use the dedicated integration packages instead
|
|
51
|
+
of wiring this up by hand.
|
|
52
|
+
|
|
53
|
+
## Consent tiers
|
|
54
|
+
|
|
55
|
+
Every signal this SDK emits carries a `cli.analytics.tier` attribute
|
|
56
|
+
and is shaped by the tier the current session resolved to:
|
|
57
|
+
|
|
58
|
+
| Tier | Adds |
|
|
59
|
+
| --------------------- | -------------------------------------------------------------- |
|
|
60
|
+
| `Anonymous` (default) | aggregate invocation/session/exit counts only, no identifiers |
|
|
61
|
+
| `Basic` | command path, flag names, exit code w/ path, latency w/ path |
|
|
62
|
+
| `Full` | session correlation ID, classified error signatures |
|
|
63
|
+
| `OptIn` | raw error messages and stack traces, via `client.optIn()` only |
|
|
64
|
+
|
|
65
|
+
The SDK enforces this client-side — it is structurally difficult to
|
|
66
|
+
call a lower-tier method with a higher-tier field (e.g. `recordError`
|
|
67
|
+
has no parameter for a stack trace at all; that only exists on the
|
|
68
|
+
`OptInScope` returned by `client.optIn()`, which itself only returns
|
|
69
|
+
something usable at `Tier.OptIn`). Server-side allowlist stripping is a
|
|
70
|
+
backstop, not the primary mechanism. See [docs/consent.md](docs/consent.md)
|
|
71
|
+
for the full model.
|
|
72
|
+
|
|
73
|
+
## Disabling telemetry
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
const client = createClient(apiKey, 'mycli', '1.4.0', { disabled: true })
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
or set `ARGVIO_DISABLED=1`. Either produces a `Client` that performs
|
|
80
|
+
**zero network calls** and adds negligible overhead.
|
|
81
|
+
|
|
82
|
+
The `DO_NOT_TRACK` environment variable ([convention](https://do-not-track.dev))
|
|
83
|
+
is also honored automatically. Running in CI (common CI env vars
|
|
84
|
+
detected automatically via `isCI()`) does not disable telemetry by
|
|
85
|
+
default — pair `EnvConsentProvider` with `chainProviders` to cap CI runs
|
|
86
|
+
at `Tier.Anonymous` instead.
|
|
87
|
+
|
|
88
|
+
## Reliability
|
|
89
|
+
|
|
90
|
+
No exported method throws under any input (bad options, network
|
|
91
|
+
failure, malformed consent config, unreachable endpoint) — every one is
|
|
92
|
+
wrapped so a bug here degrades to a no-op instead of crashing the host
|
|
93
|
+
CLI. `flush`/`shutdown` are idempotent and bounded by a timeout you
|
|
94
|
+
control.
|
|
95
|
+
|
|
96
|
+
## Design notes
|
|
97
|
+
|
|
98
|
+
- **Default OTLP transport is HTTP, not gRPC** (`options.transport`
|
|
99
|
+
defaults to `'http'`). This avoids pulling `@grpc/grpc-js` into every
|
|
100
|
+
consumer's dependency tree by default; pass `transport: 'grpc'` if
|
|
101
|
+
you need gRPC.
|
|
102
|
+
- **`ConsentProvider.resolve()` is synchronous**, not
|
|
103
|
+
`async (...) => ...`. `createClient` is a synchronous factory (never
|
|
104
|
+
returns a `Promise`), so consent resolution has to be synchronous and
|
|
105
|
+
fast too — see [docs/consent.md](docs/consent.md#why-resolve-is-synchronous).
|
|
106
|
+
- **Options are a plain object** (`ClientOptions`) rather than a
|
|
107
|
+
builder pattern — object literals and optional properties already
|
|
108
|
+
cover the need.
|
|
109
|
+
- **`createClient` never throws** and returns `client.initError`
|
|
110
|
+
instead.
|
|
111
|
+
|
|
112
|
+
## Documentation
|
|
113
|
+
|
|
114
|
+
- [docs/consent.md](docs/consent.md) — the tier model in depth
|
|
115
|
+
- [`@getargvio/yargs`](https://www.npmjs.com/package/@getargvio/yargs) — yargs integration
|
|
116
|
+
- [`@getargvio/commander`](https://www.npmjs.com/package/@getargvio/commander) — commander integration
|
|
117
|
+
|
|
118
|
+
## License
|
|
119
|
+
|
|
120
|
+
MIT — see [LICENSE](../../LICENSE).
|