@prisma-next/cli-telemetry 0.10.0-dev.8
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 +201 -0
- package/README.md +43 -0
- package/dist/exports/index.d.mts +278 -0
- package/dist/exports/index.d.mts.map +1 -0
- package/dist/exports/index.mjs +266 -0
- package/dist/exports/index.mjs.map +1 -0
- package/dist/sender.d.mts +1 -0
- package/dist/sender.mjs +253 -0
- package/dist/sender.mjs.map +1 -0
- package/package.json +50 -0
- package/src/detect-agent.ts +68 -0
- package/src/endpoint.ts +33 -0
- package/src/enrich.ts +147 -0
- package/src/exports/index.ts +14 -0
- package/src/gating.ts +71 -0
- package/src/payload.ts +74 -0
- package/src/sanitize.ts +78 -0
- package/src/sender.ts +80 -0
- package/src/spawn.ts +124 -0
- package/src/user-config.ts +111 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [2026] [Prisma Data, Inc]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# `@prisma-next/cli-telemetry`
|
|
2
|
+
|
|
3
|
+
Anonymous CLI usage telemetry client for Prisma Next. Runs in a
|
|
4
|
+
detached child process at command start, never blocks the parent,
|
|
5
|
+
and silently swallows every error in the sending path.
|
|
6
|
+
|
|
7
|
+
## Responsibilities
|
|
8
|
+
|
|
9
|
+
- **User config store.** Read/write `$XDG_CONFIG_HOME/prisma-next/config.json`
|
|
10
|
+
(or platform equivalent), holding the consent flag (`enableTelemetry`) and
|
|
11
|
+
the per-installation random UUID (`installationId`). Atomic writes;
|
|
12
|
+
unknown fields preserved.
|
|
13
|
+
- **Gating.** Pure-function resolution over the two opt-out env vars
|
|
14
|
+
(`PRISMA_NEXT_DISABLE_TELEMETRY`, `DO_NOT_TRACK=1`), the stored
|
|
15
|
+
preference, and the default-off fallback when the file is missing.
|
|
16
|
+
- **Sanitization.** Project the parent's parsed commander result into
|
|
17
|
+
the command name plus the array of flag names; never values, never
|
|
18
|
+
positionals.
|
|
19
|
+
- **Agent detection.** Best-effort identification of AI coding-agent
|
|
20
|
+
sessions from an env-var allowlist. Detector runs in the child.
|
|
21
|
+
- **Detached send.** Fork the sender script via
|
|
22
|
+
`child_process.fork(..., { detached: true, stdio: ['pipe','ignore','ignore','ipc'] })`,
|
|
23
|
+
pipe the payload over IPC, `disconnect()` + `unref()`, return to the
|
|
24
|
+
parent. The child enriches with system probes, POSTs to the backend
|
|
25
|
+
with a 1–2 s timeout, exits.
|
|
26
|
+
|
|
27
|
+
## Dependencies
|
|
28
|
+
|
|
29
|
+
- Node built-ins only. Config-dir resolution follows the XDG Base
|
|
30
|
+
Directory Specification on Unix (incl. macOS — the spec deliberately
|
|
31
|
+
picks XDG over the macOS-native `~/Library/Preferences/` convention so
|
|
32
|
+
the path is test-overridable and consistent across platforms) and uses
|
|
33
|
+
`%APPDATA%` on Windows. `child_process`, `node:crypto.randomUUID`,
|
|
34
|
+
`node:fs`, `node:os`, `node:path` are the only inbound modules.
|
|
35
|
+
|
|
36
|
+
## For contributors
|
|
37
|
+
|
|
38
|
+
The endpoint URL is a module-level constant pinned to the deployed
|
|
39
|
+
backend. For local-development testing, set
|
|
40
|
+
`PRISMA_NEXT_TELEMETRY_ENDPOINT` to override the destination URL
|
|
41
|
+
(used by the integration tests to spin up a mock HTTP server on an
|
|
42
|
+
ephemeral port). This is an integration-testing affordance, not a
|
|
43
|
+
public knob: do not surface it in user-facing docs.
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
//#region src/endpoint.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Production endpoint pinned to the deployed Prisma Compute backend.
|
|
4
|
+
* Compiled as a build-time constant; not user-configurable.
|
|
5
|
+
*/
|
|
6
|
+
declare const TELEMETRY_BACKEND_URL = "https://cmpbfbsdp09hr3jf7pojjs5qs.ewr.prisma.build";
|
|
7
|
+
/**
|
|
8
|
+
* Path within the backend that accepts telemetry POSTs.
|
|
9
|
+
*/
|
|
10
|
+
declare const TELEMETRY_ENDPOINT_PATH = "/events";
|
|
11
|
+
/**
|
|
12
|
+
* Resolve the full POST URL the sender targets. The
|
|
13
|
+
* `PRISMA_NEXT_TELEMETRY_ENDPOINT` env var is an integration-testing
|
|
14
|
+
* affordance only — it lets the test suite spin up a mock HTTP server
|
|
15
|
+
* on an ephemeral port and point the spawned sender at it. The override
|
|
16
|
+
* is intentionally undocumented in user-facing material.
|
|
17
|
+
*
|
|
18
|
+
* Fail-open: a malformed override (typo in a dev shell, bad CI config)
|
|
19
|
+
* silently falls back to the production backend rather than throwing,
|
|
20
|
+
* matching the telemetry layer's broader silent-on-failure contract.
|
|
21
|
+
*/
|
|
22
|
+
declare function resolveTelemetryEndpoint(env?: Readonly<Record<string, string | undefined>>): string;
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/user-config.d.ts
|
|
25
|
+
/**
|
|
26
|
+
* The user-level config file. Persists the consent flag and the
|
|
27
|
+
* installation UUID together so an env-var opt-out never mutates disk,
|
|
28
|
+
* and so an opt-in → opt-out → opt-in cycle keeps the same UUID (correct
|
|
29
|
+
* for MAU continuity).
|
|
30
|
+
*
|
|
31
|
+
* Readers tolerate unknown fields for forward compat; writers merge
|
|
32
|
+
* partials into the existing object so unknown fields are preserved.
|
|
33
|
+
*/
|
|
34
|
+
interface UserConfig {
|
|
35
|
+
readonly enableTelemetry?: boolean;
|
|
36
|
+
readonly installationId?: string;
|
|
37
|
+
readonly [key: string]: unknown;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Path to the user-level config file. Resolved per call so test
|
|
41
|
+
* harnesses can mutate `$XDG_CONFIG_HOME` between cases.
|
|
42
|
+
*/
|
|
43
|
+
declare function userConfigPath(): string;
|
|
44
|
+
/**
|
|
45
|
+
* Reads the user-level config. File-missing, unreadable, or malformed →
|
|
46
|
+
* `{}` (the absence of consent is the same answer in every error mode).
|
|
47
|
+
* Unknown fields from a future client are passed through verbatim.
|
|
48
|
+
*/
|
|
49
|
+
declare function readUserConfig(): UserConfig;
|
|
50
|
+
/**
|
|
51
|
+
* Merges `partial` into the current config and writes the result
|
|
52
|
+
* atomically (temp file + rename) so a crash mid-write never leaves a
|
|
53
|
+
* half-baked file readable on disk. Unknown fields already on disk are
|
|
54
|
+
* preserved.
|
|
55
|
+
*
|
|
56
|
+
* When `partial.enableTelemetry === true` and no `installationId` is
|
|
57
|
+
* stored yet, generates a v4 random UUID and persists both fields in
|
|
58
|
+
* the same write. An existing `installationId` is never rotated.
|
|
59
|
+
*
|
|
60
|
+
* `writeUserConfig({ enableTelemetry: false })` does *not* generate an
|
|
61
|
+
* installation id — only an affirmative consent answer produces one.
|
|
62
|
+
*/
|
|
63
|
+
declare function writeUserConfig(partial: Partial<UserConfig>): void;
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/gating.d.ts
|
|
66
|
+
/**
|
|
67
|
+
* Why telemetry was disabled. Useful for debug-mode logging in the
|
|
68
|
+
* parent; never surfaces to users.
|
|
69
|
+
*/
|
|
70
|
+
type GatingDisabledReason = 'env-override' | 'stored-opt-out' | 'default-off';
|
|
71
|
+
type GatingResolution = {
|
|
72
|
+
readonly enabled: true;
|
|
73
|
+
} | {
|
|
74
|
+
readonly enabled: false;
|
|
75
|
+
readonly reason: GatingDisabledReason;
|
|
76
|
+
};
|
|
77
|
+
interface GatingInputs {
|
|
78
|
+
/**
|
|
79
|
+
* Environment-variable lookups the resolver consults. Tests pass a
|
|
80
|
+
* literal record; production passes `process.env`. The two opt-out
|
|
81
|
+
* signals are `PRISMA_NEXT_DISABLE_TELEMETRY` (Prisma-specific) and
|
|
82
|
+
* `DO_NOT_TRACK` (community convention).
|
|
83
|
+
*/
|
|
84
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
85
|
+
/** Result of `readUserConfig()` — file-missing tolerated as `{}`. */
|
|
86
|
+
readonly config: UserConfig;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Pure-function resolution of the gating decision. Same input → same
|
|
90
|
+
* output; no I/O. The caller is responsible for reading the env and the
|
|
91
|
+
* user config.
|
|
92
|
+
*
|
|
93
|
+
* Decision order:
|
|
94
|
+
* 1. Env-var override (`PRISMA_NEXT_DISABLE_TELEMETRY` truthy, or
|
|
95
|
+
* `DO_NOT_TRACK=1`) → disabled.
|
|
96
|
+
* 2. Stored `enableTelemetry === true` → enabled.
|
|
97
|
+
* 3. Stored `enableTelemetry === false` → disabled (`stored-opt-out`).
|
|
98
|
+
* 4. Stored `enableTelemetry === undefined` (file missing, or field
|
|
99
|
+
* not set) → disabled (`default-off`).
|
|
100
|
+
*
|
|
101
|
+
* Telemetry is enabled only when no env override is active **and**
|
|
102
|
+
* `enableTelemetry` is explicitly `true`.
|
|
103
|
+
*/
|
|
104
|
+
declare function resolveGating(inputs: GatingInputs): GatingResolution;
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/payload.d.ts
|
|
107
|
+
/**
|
|
108
|
+
* Wire-shape payload the parent IPC-sends to the forked child sender.
|
|
109
|
+
* Mirrors the fields the parent has naturally in hand at command start
|
|
110
|
+
* (installation id, sanitised command + flags, CLI version, db target,
|
|
111
|
+
* extension-pack ids, project root for TS-version lookup). The child
|
|
112
|
+
* fills in the rest (runtime/os/arch, package manager, ts version,
|
|
113
|
+
* agent) on its side.
|
|
114
|
+
*
|
|
115
|
+
* Both sides version-couple on this shape because the IPC carrier is
|
|
116
|
+
* structured-cloned by Node and there's no on-wire compat to maintain.
|
|
117
|
+
*/
|
|
118
|
+
interface ParentToSenderPayload {
|
|
119
|
+
readonly installationId: string;
|
|
120
|
+
readonly version: string;
|
|
121
|
+
readonly command: string;
|
|
122
|
+
readonly flags: readonly string[];
|
|
123
|
+
readonly databaseTarget: string | null;
|
|
124
|
+
readonly extensions: readonly string[];
|
|
125
|
+
/** Absolute path of the user's project. The child reads `<projectRoot>/package.json` for `tsVersion`. */
|
|
126
|
+
readonly projectRoot: string;
|
|
127
|
+
/** Resolved endpoint URL (already includes the `/events` path). */
|
|
128
|
+
readonly endpoint: string;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The full event the child POSTs to the backend. Shape matches the
|
|
132
|
+
* backend's arktype schema (`apps/telemetry-backend/src/schema.ts`).
|
|
133
|
+
*/
|
|
134
|
+
interface TelemetryEvent {
|
|
135
|
+
readonly installationId: string;
|
|
136
|
+
readonly version: string;
|
|
137
|
+
readonly command: string;
|
|
138
|
+
readonly flags: readonly string[];
|
|
139
|
+
readonly runtimeName: string;
|
|
140
|
+
readonly runtimeVersion: string;
|
|
141
|
+
readonly os: string;
|
|
142
|
+
readonly arch: string;
|
|
143
|
+
readonly packageManager: string | null;
|
|
144
|
+
readonly databaseTarget: string | null;
|
|
145
|
+
readonly tsVersion: string | null;
|
|
146
|
+
readonly agent: string | null;
|
|
147
|
+
readonly extensions: readonly string[];
|
|
148
|
+
}
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/sanitize.d.ts
|
|
151
|
+
interface CommanderOptionShape {
|
|
152
|
+
/** Commander's option attribute name, e.g. `dryRun` for `--dry-run`. */
|
|
153
|
+
readonly attributeName: string;
|
|
154
|
+
/** Commander's long, user-facing flag spelling, e.g. `--dry-run` or `--no-install`. */
|
|
155
|
+
readonly longName: string | null;
|
|
156
|
+
/** Commander's value source for this option. Only `cli` is user-supplied. */
|
|
157
|
+
readonly source: string | null;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Input shape: a thin projection of commander's parsed-result surface.
|
|
161
|
+
* The parent extracts the command path, positional args, and per-option
|
|
162
|
+
* metadata from the leaf command. The sanitiser never consumes raw
|
|
163
|
+
* argv, never reads `process.argv`, and never sees flag values.
|
|
164
|
+
*/
|
|
165
|
+
interface CommanderResultShape {
|
|
166
|
+
/**
|
|
167
|
+
* The full command path from the root program to the leaf, including
|
|
168
|
+
* the root program name as the first element (the sanitiser drops it).
|
|
169
|
+
* Example: `['prisma-next', 'migration', 'new']`.
|
|
170
|
+
*/
|
|
171
|
+
readonly commandPath: readonly string[];
|
|
172
|
+
/**
|
|
173
|
+
* Positional arguments commander parsed for the leaf command.
|
|
174
|
+
* **Intentionally never read.** Accepted so the call site doesn't have
|
|
175
|
+
* to think about whether to pass it; the sanitiser's contract is that
|
|
176
|
+
* positionals never leave the parent process.
|
|
177
|
+
*/
|
|
178
|
+
readonly positionalArgs: readonly string[];
|
|
179
|
+
/**
|
|
180
|
+
* Per-option Commander metadata. The sanitiser emits only options whose
|
|
181
|
+
* source is `cli`, and uses `longName` so telemetry sees user-facing
|
|
182
|
+
* names (`dry-run`, `connection-string`, `no-install`) rather than
|
|
183
|
+
* Commander's internal camelCase attribute names or defaulted options.
|
|
184
|
+
*/
|
|
185
|
+
readonly options: readonly CommanderOptionShape[];
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Output shape: the sanitised projection that flows into the telemetry
|
|
189
|
+
* payload. Two fields only — command name (space-delimited subcommand
|
|
190
|
+
* path) and flag names (in commander's option declaration order).
|
|
191
|
+
*/
|
|
192
|
+
interface SanitisedCommand {
|
|
193
|
+
readonly command: string;
|
|
194
|
+
readonly flags: readonly string[];
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Project commander's parsed result into the wire-shape command and
|
|
198
|
+
* flag-name list. Pure; the only allowed inputs are the fields of
|
|
199
|
+
* `CommanderResultShape`.
|
|
200
|
+
*
|
|
201
|
+
* Sanitiser contract — no flag values, no positionals, no raw argv:
|
|
202
|
+
* - Drop the root program name (`commandPath[0]`); the wire ships
|
|
203
|
+
* `migration new`, not `prisma-next migration new`.
|
|
204
|
+
* - Emit only options whose Commander source is `cli`.
|
|
205
|
+
* - Emit the long user-facing flag spelling without the `--` prefix;
|
|
206
|
+
* never emit Commander's camelCase attribute names.
|
|
207
|
+
* - `positionalArgs` is accepted but never consumed; the field exists
|
|
208
|
+
* in the input type to make it obvious at the call site that
|
|
209
|
+
* positionals were deliberately excluded.
|
|
210
|
+
*/
|
|
211
|
+
declare function sanitizeCommanderResult(input: CommanderResultShape): SanitisedCommand;
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/spawn.d.ts
|
|
214
|
+
/**
|
|
215
|
+
* Inputs the CLI entry point hands the telemetry layer at command
|
|
216
|
+
* start. The CLI is responsible for stitching commander's result, the
|
|
217
|
+
* loaded config, and the project root together; the telemetry module
|
|
218
|
+
* does no I/O of its own except for the user-config read (skipped when
|
|
219
|
+
* `userConfig` is provided).
|
|
220
|
+
*/
|
|
221
|
+
interface RunTelemetryInputs {
|
|
222
|
+
/** Sanitised commander snapshot — see `CommanderResultShape`. */
|
|
223
|
+
readonly command: CommanderResultShape;
|
|
224
|
+
/** This CLI's own version (from its `package.json`). */
|
|
225
|
+
readonly version: string;
|
|
226
|
+
/** Resolved `config.target.targetId`, or `null` when the config could not be loaded. */
|
|
227
|
+
readonly databaseTarget: string | null;
|
|
228
|
+
/** Declared extension-pack IDs, in any deterministic order. */
|
|
229
|
+
readonly extensions: readonly string[];
|
|
230
|
+
/** Absolute path of the project root (typically `process.cwd()`). */
|
|
231
|
+
readonly projectRoot: string;
|
|
232
|
+
/**
|
|
233
|
+
* Path to the sender entry compiled into this package's `dist/`.
|
|
234
|
+
* Resolved by the caller because the compiled sender lives at
|
|
235
|
+
* `<package>/dist/sender.mjs` and only the consumer knows its own
|
|
236
|
+
* `import.meta.url`.
|
|
237
|
+
*/
|
|
238
|
+
readonly senderPath: string;
|
|
239
|
+
/**
|
|
240
|
+
* `isCI()` result from the consumer. Telemetry is suppressed when
|
|
241
|
+
* `true` regardless of the stored consent answer — CI environments
|
|
242
|
+
* never emit (matches the colour-output convention's CI suppression).
|
|
243
|
+
*/
|
|
244
|
+
readonly isCI: boolean;
|
|
245
|
+
/** Process env to read for opt-out signals. Defaults to `process.env`. */
|
|
246
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
247
|
+
/** Cached user config when the caller already read it to resolve gates before other work. */
|
|
248
|
+
readonly userConfig?: UserConfig;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Best-effort telemetry spawn at command start. Returns synchronously —
|
|
252
|
+
* the fork runs in the background and never blocks the parent. Every
|
|
253
|
+
* failure mode is swallowed; the parent's stdout/stderr is untouched in
|
|
254
|
+
* normal operation, the only escape valve being
|
|
255
|
+
* `PRISMA_NEXT_DEBUG=1` which routes diagnostics to stderr.
|
|
256
|
+
*
|
|
257
|
+
* Returns the spawn outcome so debug-mode logging and the test-harness
|
|
258
|
+
* probe (which verifies test runs short-circuit the fork) can inspect
|
|
259
|
+
* the decision without scraping stderr.
|
|
260
|
+
*/
|
|
261
|
+
type TelemetryRunOutcome = {
|
|
262
|
+
readonly spawned: true;
|
|
263
|
+
} | {
|
|
264
|
+
readonly spawned: false;
|
|
265
|
+
readonly reason: 'gated-off' | 'ci' | 'fork-failed';
|
|
266
|
+
};
|
|
267
|
+
declare function runTelemetry(inputs: RunTelemetryInputs): TelemetryRunOutcome;
|
|
268
|
+
/**
|
|
269
|
+
* Resolve the path to the compiled sender entry relative to a consumer
|
|
270
|
+
* that has captured its own `import.meta.url`. The CLI's
|
|
271
|
+
* `tsdown`-emitted entry sits at `<package>/dist/sender.mjs`; the
|
|
272
|
+
* consumer asks `senderModuleUrl()` and forwards the result to
|
|
273
|
+
* `runTelemetry({ senderPath })`.
|
|
274
|
+
*/
|
|
275
|
+
declare function senderModuleUrl(importMetaUrl: string): string;
|
|
276
|
+
//#endregion
|
|
277
|
+
export { type CommanderOptionShape, type CommanderResultShape, type GatingDisabledReason, type GatingInputs, type GatingResolution, type ParentToSenderPayload, type RunTelemetryInputs, type SanitisedCommand, TELEMETRY_BACKEND_URL, TELEMETRY_ENDPOINT_PATH, type TelemetryEvent, type TelemetryRunOutcome, type UserConfig, readUserConfig, resolveGating, resolveTelemetryEndpoint, runTelemetry, sanitizeCommanderResult, senderModuleUrl, userConfigPath, writeUserConfig };
|
|
278
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/endpoint.ts","../../src/user-config.ts","../../src/gating.ts","../../src/payload.ts","../../src/sanitize.ts","../../src/spawn.ts"],"mappings":";;;;AAIA;cAAa,qBAAA;;;;cAKA,uBAAA;;;;;AAab;;;;;;;iBAAgB,wBAAA,CACd,GAAA,GAAK,QAAA,CAAS,MAAA;;;;;;AAnBhB;;;;;AAKA;UCKiB,UAAA;EAAA,SACN,eAAA;EAAA,SACA,cAAA;EAAA,UACC,GAAA;AAAA;;;;;iBA0CI,cAAA,CAAA;;;;;;iBASA,cAAA,CAAA,GAAkB,UAAA;AAtDlC;;;;;;;;;AA6CA;;;;AA7CA,iBAkFgB,eAAA,CAAgB,OAAA,EAAS,OAAA,CAAQ,UAAA;;;;;AD5FjD;;KEEY,oBAAA;AAAA,KAEA,gBAAA;EAAA,SACG,OAAA;AAAA;EAAA,SACA,OAAA;EAAA,SAAyB,MAAA,EAAQ,oBAAA;AAAA;AAAA,UAE/B,YAAA;EFUD;;;;;;EAAA,SEHL,GAAA,EAAK,QAAA,CAAS,MAAA;EFIwC;EAAA,SEFtD,MAAA,EAAQ,UAAA;AAAA;;;ADPnB;;;;;;;;;AA6CA;;;;;iBCHgB,aAAA,CAAc,MAAA,EAAQ,YAAA,GAAe,gBAAA;;;;;;AFpDrD;;;;;AAKA;;;UGIiB,qBAAA;EAAA,SACN,cAAA;EAAA,SACA,OAAA;EAAA,SACA,OAAA;EAAA,SACA,KAAA;EAAA,SACA,cAAA;EAAA,SACA,UAAA;EHIK;EAAA,SGFL,WAAA;EHEsD;EAAA,SGAtD,QAAA;AAAA;AFTX;;;;AAAA,UE6CiB,cAAA;EAAA,SACN,cAAA;EAAA,SACA,OAAA;EAAA,SACA,OAAA;EAAA,SACA,KAAA;EAAA,SACA,WAAA;EAAA,SACA,cAAA;EAAA,SACA,EAAA;EAAA,SACA,IAAA;EAAA,SACA,cAAA;EAAA,SACA,cAAA;EAAA,SACA,SAAA;EAAA,SACA,KAAA;EAAA,SACA,UAAA;AAAA;;;UCxEM,oBAAA;;WAEN,aAAA;EJEE;EAAA,SIAF,QAAA;;WAEA,MAAA;AAAA;AJGX;;;;;AAaA;AAbA,UIMiB,oBAAA;;;;;;WAMN,WAAA;EJEsD;;;;ACTjE;;EDSiE,SIKtD,cAAA;EHdgB;;;;;;EAAA,SGqBhB,OAAA,WAAkB,oBAAA;AAAA;;;;AHiC7B;;UGzBiB,gBAAA;EAAA,SACN,OAAA;EAAA,SACA,KAAA;AAAA;;;;;;;;;;;;AFvCX;;;;iBE+DgB,uBAAA,CAAwB,KAAA,EAAO,oBAAA,GAAuB,gBAAA;;;;AJjEtE;;;;;AAKA;UKMiB,kBAAA;;WAEN,OAAA,EAAS,oBAAA;ELRgB;EAAA,SKUzB,OAAA;ELG6B;EAAA,SKD7B,cAAA;ELEI;EAAA,SKAJ,UAAA;ELAK;EAAA,SKEL,WAAA;ELFsD;;;;;ACTjE;EDSiE,SKStD,UAAA;;;;;;WAMA,IAAA;EJrBY;EAAA,SIuBZ,GAAA,GAAM,QAAA,CAAS,MAAA;EJmBI;EAAA,SIjBnB,UAAA,GAAa,UAAA;AAAA;;AJ0BxB;;;;;AA4BA;;;;;KIxCY,mBAAA;EAAA,SACG,OAAA;AAAA;EAAA,SACA,OAAA;EAAA,SAAyB,MAAA;AAAA;AAAA,iBAExB,YAAA,CAAa,MAAA,EAAQ,kBAAA,GAAqB,mBAAA;AHtD1D;;;;;AAEA;;AAFA,iBGmHgB,eAAA,CAAgB,aAAA"}
|