wgc 0.79.2 → 0.79.4
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/README.md +253 -29
- package/dist/package.json +2 -2
- package/dist/src/core/config.d.ts +4 -0
- package/dist/src/core/config.js +1 -1
- package/dist/src/core/config.js.map +1 -1
- package/dist/src/core/telemetry.d.ts +5 -1
- package/dist/src/core/telemetry.js +61 -14
- package/dist/src/core/telemetry.js.map +1 -1
- package/dist/src/index.js +10 -1
- package/dist/src/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,55 +1,279 @@
|
|
|
1
|
-
# WunderGraph Cosmo CLI
|
|
1
|
+
# WunderGraph Cosmo CLI (`wgc`)
|
|
2
2
|
|
|
3
|
-
[
|
|
3
|
+
**The all-in-one CLI for managing federated GraphQL APIs with [WunderGraph Cosmo](https://cosmo-docs.wundergraph.com/).**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
  
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 🚀 What is `wgc`?
|
|
10
|
+
|
|
11
|
+
`wgc` is the official CLI for [WunderGraph Cosmo](https://cosmo-docs.wundergraph.com/), an open-source, full-lifecycle GraphQL API management platform.
|
|
12
|
+
|
|
13
|
+
With `wgc`, you can:
|
|
14
|
+
|
|
15
|
+
* Create and manage **federated GraphQL APIs** and **subgraphs**
|
|
16
|
+
* Perform **schema checks** and **composition validations**
|
|
17
|
+
* Generate and deploy **router configurations**
|
|
18
|
+
* Integrate with **CI/CD pipelines** for automated workflows
|
|
19
|
+
* Manage **namespaces**, **API keys**, and more
|
|
20
|
+
|
|
21
|
+
Whether you're building monolithic or federated GraphQL architectures, `wgc` provides the tools to manage your development and deployment processes.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 🧰 Cosmo Features
|
|
26
|
+
|
|
27
|
+
* **Federation Support**: Compatible with GraphQL Federation v1 and v2
|
|
28
|
+
* **Schema Registry**: Centralized management of your GraphQL schemas with versioning and change tracking
|
|
29
|
+
* **Composition Checks**: Automated validation to ensure subgraphs compose correctly without breaking changes
|
|
30
|
+
* **Router Configuration**: Generate and manage router configurations for efficient query planning and execution
|
|
31
|
+
* **Observability**: Integrated with OpenTelemetry and Prometheus for metrics, tracing, and monitoring
|
|
32
|
+
* **Access Control**: Fine-grained access controls with support for OIDC, RBAC, and SCIM
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 📦 Installation
|
|
8
37
|
|
|
9
38
|
### Prerequisites
|
|
10
39
|
|
|
11
|
-
|
|
40
|
+
* [Node.js](https://nodejs.org/) v20 LTS or higher
|
|
41
|
+
|
|
42
|
+
### Install via npm
|
|
12
43
|
|
|
13
|
-
|
|
44
|
+
```bash
|
|
45
|
+
npm install -g wgc@latest
|
|
46
|
+
```
|
|
14
47
|
|
|
15
|
-
|
|
48
|
+
Or use `npx`:
|
|
16
49
|
|
|
17
50
|
```bash
|
|
18
|
-
npx wgc
|
|
19
|
-
# or install it globally
|
|
20
|
-
npm install -g wgc --help
|
|
51
|
+
npx -y wgc@latest
|
|
21
52
|
```
|
|
22
53
|
|
|
23
|
-
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 🛠️ Getting Started
|
|
57
|
+
|
|
58
|
+
### 1. Clone the Example Project
|
|
24
59
|
|
|
25
|
-
|
|
60
|
+
Start with the [Cosmo Demo](https://github.com/wundergraph/cosmo-demo), which includes two subgraphs (`posts` and `users`) and a router configuration.
|
|
26
61
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
62
|
+
```bash
|
|
63
|
+
git clone https://github.com/wundergraph/cosmo-demo.git
|
|
64
|
+
cd cosmo-demo
|
|
65
|
+
```
|
|
31
66
|
|
|
32
|
-
2.
|
|
33
|
-
```shell
|
|
34
|
-
export DO_NOT_TRACK=1
|
|
35
|
-
```
|
|
67
|
+
### 2. Install `wgc`
|
|
36
68
|
|
|
37
|
-
|
|
69
|
+
Ensure you have `wgc` installed globally:
|
|
38
70
|
|
|
39
|
-
|
|
71
|
+
```bash
|
|
72
|
+
npm install -g wgc@latest
|
|
73
|
+
```
|
|
40
74
|
|
|
41
|
-
|
|
75
|
+
### 3. Start Subgraphs
|
|
42
76
|
|
|
43
|
-
|
|
77
|
+
Make the startup script executable and run it:
|
|
44
78
|
|
|
45
79
|
```bash
|
|
46
|
-
|
|
80
|
+
chmod +x start-subgraphs.sh
|
|
81
|
+
./start-subgraphs.sh
|
|
47
82
|
```
|
|
48
83
|
|
|
49
|
-
|
|
84
|
+
Verify the subgraphs are running:
|
|
85
|
+
|
|
86
|
+
* [Posts Subgraph](http://localhost:4001/graphql)
|
|
87
|
+
* [Users Subgraph](http://localhost:4002/graphql)
|
|
88
|
+
|
|
89
|
+
### 4. Generate Router Configuration
|
|
50
90
|
|
|
51
|
-
|
|
91
|
+
Navigate to the `router` directory and compose the router configuration:
|
|
52
92
|
|
|
53
93
|
```bash
|
|
54
|
-
|
|
55
|
-
|
|
94
|
+
cd router
|
|
95
|
+
wgc router compose --input graph.localhost.yaml --out config.json
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 5. Run the Router
|
|
99
|
+
|
|
100
|
+
Start the router using Docker:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
docker run \
|
|
104
|
+
--name cosmo-router \
|
|
105
|
+
--rm \
|
|
106
|
+
-p 3002:3002 \
|
|
107
|
+
--add-host=host.docker.internal:host-gateway \
|
|
108
|
+
--platform=linux/amd64 \
|
|
109
|
+
-e pull=always \
|
|
110
|
+
-e DEV_MODE=true \
|
|
111
|
+
-e LISTEN_ADDR=0.0.0.0:3002 \
|
|
112
|
+
-e EXECUTION_CONFIG_FILE_PATH="/config/config.json" \
|
|
113
|
+
-v "$(pwd)/config.json:/config/config.json" \
|
|
114
|
+
ghcr.io/wundergraph/cosmo/router:latest
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### 6. Query the Federated Graph
|
|
118
|
+
|
|
119
|
+
Access the federated GraphQL API at [http://localhost:3002](http://localhost:3002).
|
|
120
|
+
|
|
121
|
+
Example query:
|
|
122
|
+
|
|
123
|
+
```graphql
|
|
124
|
+
query {
|
|
125
|
+
posts {
|
|
126
|
+
id
|
|
127
|
+
content
|
|
128
|
+
author {
|
|
129
|
+
id
|
|
130
|
+
name
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## 📚 Documentation
|
|
139
|
+
|
|
140
|
+
* **CLI Reference**: [https://cosmo-docs.wundergraph.com/cli](https://cosmo-docs.wundergraph.com/cli)
|
|
141
|
+
* **Zero to Federation Tutorial**: [https://cosmo-docs.wundergraph.com/tutorial/from-zero-to-federation-in-5-steps-using-cosmo](https://cosmo-docs.wundergraph.com/tutorial/from-zero-to-federation-in-5-steps-using-cosmo)
|
|
142
|
+
* **Full Documentation**: [https://cosmo-docs.wundergraph.com/](https://cosmo-docs.wundergraph.com/)
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## 🌐 About WunderGraph Cosmo
|
|
147
|
+
|
|
148
|
+
WunderGraph Cosmo is a comprehensive, open-source platform for managing GraphQL APIs at scale. It offers:
|
|
149
|
+
|
|
150
|
+
* **Schema Registry**: Centralized schema management with versioning and validation
|
|
151
|
+
* **Cosmo Studio**: A web interface for exploring schemas, monitoring performance, and managing access
|
|
152
|
+
* **Cosmo Router**: A high-performance, Go-based router supporting federation, subscriptions, and more
|
|
153
|
+
* **Observability**: Built-in support for OpenTelemetry and Prometheus
|
|
154
|
+
* **Security**: Fine-grained access controls with OIDC, RBAC, and SCIM support
|
|
155
|
+
|
|
156
|
+
Cosmo can be deployed on-premises, in the cloud, or used as a managed service.
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## 🧪 Example Commands
|
|
161
|
+
|
|
162
|
+
* **Create Namespace**:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
npx wgc namespace create production
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
* **Create Federated Graph**:
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
npx wgc federated-graph create main -r http://router.example.com/graphql -n production
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
* **Create Subgraph**:
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
npx wgc subgraph create products --routing-url http://localhost:4001/graphql
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
* **Check Subgraph Schema Changes**:
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
npx wgc subgraph check products -n production --schema ./schemas/products.graphql
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
* **Generate Router Configuration locally**:
|
|
187
|
+
|
|
188
|
+
Composition Configuration (graph.yaml):
|
|
189
|
+
|
|
190
|
+
```yaml
|
|
191
|
+
version: 1
|
|
192
|
+
subgraphs:
|
|
193
|
+
- name: products
|
|
194
|
+
routing_url: http://localhost:4001/graphql
|
|
195
|
+
schema:
|
|
196
|
+
file: ./schemas/products.graphql
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Generate CMD:
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
npx wgc router compose -i graph.yaml -o config.json
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
* **Run Router**:
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
docker run \
|
|
209
|
+
--name cosmo-router \
|
|
210
|
+
--rm \
|
|
211
|
+
-p 3002:3002 \
|
|
212
|
+
--add-host=host.docker.internal:host-gateway \
|
|
213
|
+
--platform=linux/amd64 \
|
|
214
|
+
-e pull=always \
|
|
215
|
+
-e DEV_MODE=true \
|
|
216
|
+
-e LISTEN_ADDR=0.0.0.0:3002 \
|
|
217
|
+
-e EXECUTION_CONFIG_FILE_PATH="/config/config.json" \
|
|
218
|
+
-v "$(pwd)/config.json:/config/config.json" \
|
|
219
|
+
ghcr.io/wundergraph/cosmo/router:latest
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## 🔗 Related Projects
|
|
225
|
+
|
|
226
|
+
* **Cosmo Demo**: [https://github.com/wundergraph/cosmo-demo](https://github.com/wundergraph/cosmo-demo)
|
|
227
|
+
* **Cosmo GitHub Repository**: [https://github.com/wundergraph/cosmo](https://github.com/wundergraph/cosmo)
|
|
228
|
+
* **WunderGraph Website**: [https://wundergraph.com](https://wundergraph.com)
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## 🔗 From the WunderGraph Blog
|
|
233
|
+
|
|
234
|
+
Here's a selection of blog posts that focus on the technical aspects of Cosmo:
|
|
235
|
+
|
|
236
|
+
- [**How we scaled Cosmo Router for the SuperBowl**](https://wundergraph.com/blog/scaling-graphql-federation-for-the-superbowl)
|
|
237
|
+
- [**The Architecture of our Observability Stack**](https://wundergraph.com/blog/scaling_graphql_observability)
|
|
238
|
+
- [**How Normalization affects Query Planning**](https://wundergraph.com/blog/normalization_query_planning_graphql_federation)
|
|
239
|
+
- [**Zero cost abstraction for the @skip and @include Directives**](https://wundergraph.com/blog/zero_cost_abstraction_for_skip_include_in_federated_graphql)
|
|
240
|
+
- [**Algorithm to minify GraphQL ASTs by up to 99%**](https://wundergraph.com/blog/graphql_query_ast_minification)
|
|
241
|
+
- [**Federated GraphQL Subscriptions with NATS and Event Driven Architecture**](https://wundergraph.com/blog/distributed_graphql_subscriptions_with_nats_and_event_driven_architecture)
|
|
242
|
+
- [**Implementing the viewer pattern in GraphQL Federation**](https://wundergraph.com/blog/graphql_federation_viewer_pattern)
|
|
243
|
+
- [**How we're using Epoll/Kqueue to scale GraphQL Subscriptions**](https://wundergraph.com/blog/edfs_scaling_graphql_subscriptions_in_go)
|
|
244
|
+
- [**ASTJSON - A fast way to merge JSON objects**](https://wundergraph.com/blog/astjson_high_performance_json_transformations_in_golang)
|
|
245
|
+
- [**Dataloader 3.0, an efficient algorithm for Federation data loading**](https://wundergraph.com/blog/dataloader_3_0_breadth_first_data_loading)
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## Telemetry
|
|
250
|
+
|
|
251
|
+
The CLI tool collects usage data to help us improve the tool and understand how users interact with it.
|
|
252
|
+
You can disable telemetry in one of the following ways:
|
|
253
|
+
|
|
254
|
+
```shell
|
|
255
|
+
export COSMO_TELEMETRY_DISABLED=true
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
or
|
|
259
|
+
|
|
260
|
+
```shell
|
|
261
|
+
export DO_NOT_TRACK=1
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## 📄 License
|
|
267
|
+
|
|
268
|
+
This project is licensed under the [Apache 2.0 License](https://github.com/wundergraph/cosmo/blob/main/LICENSE).
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
## 📬 Support & Community
|
|
273
|
+
|
|
274
|
+
* **Discord**: Join our [Discord community](https://wundergraph.com/discord) for support and discussions
|
|
275
|
+
* **GitHub Issues**: Report issues or request features on our [GitHub repository](https://github.com/wundergraph/cosmo/issues)
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
Empower your GraphQL Federation development with `wgc` and WunderGraph Cosmo!
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wgc",
|
|
3
|
-
"version": "0.79.
|
|
3
|
+
"version": "0.79.4",
|
|
4
4
|
"description": "The official CLI tool to manage the GraphQL Federation Platform Cosmo",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"js-yaml": "^4.1.0",
|
|
63
63
|
"jwt-decode": "^3.1.2",
|
|
64
64
|
"log-symbols": "^5.1.0",
|
|
65
|
-
"octokit": "^
|
|
65
|
+
"octokit": "^4.1.3",
|
|
66
66
|
"open": "^9.1.0",
|
|
67
67
|
"ora": "^8.0.1",
|
|
68
68
|
"pathe": "^1.1.1",
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export declare const configDir: string;
|
|
2
2
|
export declare const configFile: string;
|
|
3
|
+
export declare const getLoginDetails: () => {
|
|
4
|
+
accessToken: string;
|
|
5
|
+
organizationSlug: string;
|
|
6
|
+
} | null;
|
|
3
7
|
export declare const config: {
|
|
4
8
|
version: string;
|
|
5
9
|
baseURL: string;
|
package/dist/src/core/config.js
CHANGED
|
@@ -6,7 +6,7 @@ import info from '../../package.json' with { type: 'json' };
|
|
|
6
6
|
const paths = envPaths('cosmo', { suffix: '' });
|
|
7
7
|
export const configDir = paths.config;
|
|
8
8
|
export const configFile = join(configDir, 'config.yaml');
|
|
9
|
-
const getLoginDetails = () => {
|
|
9
|
+
export const getLoginDetails = () => {
|
|
10
10
|
try {
|
|
11
11
|
const data = yaml.load(readFileSync(configFile, 'utf8'));
|
|
12
12
|
const loginData = JSON.parse(JSON.stringify(data));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/core/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAC7B,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,QAAQ,MAAM,WAAW,CAAC;AAEjC,OAAO,IAAI,MAAM,oBAAoB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAE5D,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;AAChD,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAA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AAa,IAAI,kCAAkC;IACxE,4CAA4C;IAC5C,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa;IACjC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,uCAAuC;IAC3E,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,+BAA+B;IACpE,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,WAAW;IACnD,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,OAAO;IACxC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,mCAAmC;IAClE,kBAAkB,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,OAAO;IAC/D,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,EAAE;IAC/C,cAAc,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,EAAE;IAClD,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,EAAE;CAChD,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,GAAgB,EAAE;;IAC9C,OAAO;QACL,YAAY,EAAE,aAAa,IAAI,CAAC,OAAO,EAAE;QACzC,aAAa,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM;QACxC,gBAAgB,EAAE,CAAA,MAAA,eAAe,EAAE,0CAAE,gBAAgB,KAAI,EAAE;KAC5D,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -6,7 +6,11 @@ export declare const initTelemetry: () => void;
|
|
|
6
6
|
/**
|
|
7
7
|
* Capture a usage event
|
|
8
8
|
*/
|
|
9
|
-
export declare const capture: (eventName: string, properties?: Record<string, any>) => void
|
|
9
|
+
export declare const capture: (eventName: string, properties?: Record<string, any>) => Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Capture a command failure event with error details
|
|
12
|
+
*/
|
|
13
|
+
export declare const captureCommandFailure: (command: string, error: Error | string) => Promise<void>;
|
|
10
14
|
/**
|
|
11
15
|
* Shutdown PostHog client - should be called before CLI exits
|
|
12
16
|
*/
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import os from 'node:os';
|
|
2
2
|
import { PostHog } from 'posthog-node';
|
|
3
|
-
import {
|
|
3
|
+
import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb';
|
|
4
|
+
import { config, getBaseHeaders, getLoginDetails } from './config.js';
|
|
5
|
+
import { CreateClient } from './client/client.js';
|
|
4
6
|
// Environment variables to allow opting out of telemetry
|
|
5
7
|
// Support for COSMO_TELEMETRY_DISABLED and Console Do Not Track standard
|
|
6
|
-
const TELEMETRY_DISABLED = process.env.COSMO_TELEMETRY_DISABLED === 'true' || process.env.DO_NOT_TRACK === '1'
|
|
8
|
+
const TELEMETRY_DISABLED = process.env.COSMO_TELEMETRY_DISABLED === 'true' || process.env.DO_NOT_TRACK === '1';
|
|
7
9
|
let client = null;
|
|
10
|
+
let apiClient = null;
|
|
8
11
|
// Detect if running in a CI environment
|
|
9
12
|
const isCI = () => {
|
|
10
13
|
return Boolean(process.env.CI || // Travis CI, CircleCI, GitLab CI, GitHub Actions, etc.
|
|
@@ -15,6 +18,13 @@ const isCI = () => {
|
|
|
15
18
|
process.env.GITHUB_ACTIONS ||
|
|
16
19
|
process.env.BUILDKITE);
|
|
17
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* Check if the CLI is talking to Cosmo Cloud or a self-hosted instance
|
|
23
|
+
*/
|
|
24
|
+
const isTalkingToCosmoCloud = () => {
|
|
25
|
+
const cloudUrl = 'https://cosmo-cp.wundergraph.com';
|
|
26
|
+
return config.baseURL.startsWith(cloudUrl);
|
|
27
|
+
};
|
|
18
28
|
/**
|
|
19
29
|
* Initialize PostHog client
|
|
20
30
|
* This should be called once at the start of the CLI
|
|
@@ -23,7 +33,7 @@ export const initTelemetry = () => {
|
|
|
23
33
|
if (TELEMETRY_DISABLED) {
|
|
24
34
|
return;
|
|
25
35
|
}
|
|
26
|
-
const posthogApiKey = process.env.POSTHOG_API_KEY || '';
|
|
36
|
+
const posthogApiKey = process.env.POSTHOG_API_KEY || 'phc_CEnvoyw3KcTuC5E1seDPrgvAamgGRDLfzPi1e7RU1G1';
|
|
27
37
|
const posthogHost = process.env.POSTHOG_HOST || 'https://eu.i.posthog.com';
|
|
28
38
|
client = new PostHog(posthogApiKey, {
|
|
29
39
|
host: posthogHost,
|
|
@@ -31,6 +41,12 @@ export const initTelemetry = () => {
|
|
|
31
41
|
flushInterval: 0, // Don't wait to flush events
|
|
32
42
|
disableGeoip: false,
|
|
33
43
|
});
|
|
44
|
+
const proxyUrl = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
|
|
45
|
+
apiClient = CreateClient({
|
|
46
|
+
baseUrl: config.baseURL,
|
|
47
|
+
apiKey: config.apiKey,
|
|
48
|
+
proxyUrl,
|
|
49
|
+
});
|
|
34
50
|
// Handle errors silently to not interrupt CLI operations
|
|
35
51
|
client.on('error', (err) => {
|
|
36
52
|
if (process.env.DEBUG) {
|
|
@@ -38,18 +54,47 @@ export const initTelemetry = () => {
|
|
|
38
54
|
}
|
|
39
55
|
});
|
|
40
56
|
};
|
|
57
|
+
/**
|
|
58
|
+
* Generate a consistent distinct ID
|
|
59
|
+
* Uses the platform API to get the organization slug if available
|
|
60
|
+
*/
|
|
61
|
+
const getIdentity = async () => {
|
|
62
|
+
var _a;
|
|
63
|
+
try {
|
|
64
|
+
// First try to get the identity from the config file
|
|
65
|
+
const loginDetails = getLoginDetails();
|
|
66
|
+
if (loginDetails === null || loginDetails === void 0 ? void 0 : loginDetails.organizationSlug) {
|
|
67
|
+
return loginDetails.organizationSlug;
|
|
68
|
+
}
|
|
69
|
+
// If not found, the user might be using an API key.
|
|
70
|
+
// Call the whoAmI API to get organization information
|
|
71
|
+
if (!apiClient) {
|
|
72
|
+
return 'anonymous';
|
|
73
|
+
}
|
|
74
|
+
const resp = await apiClient.platform.whoAmI({}, {
|
|
75
|
+
headers: getBaseHeaders(),
|
|
76
|
+
});
|
|
77
|
+
if (((_a = resp.response) === null || _a === void 0 ? void 0 : _a.code) === EnumStatusCode.OK) {
|
|
78
|
+
return resp.organizationSlug;
|
|
79
|
+
}
|
|
80
|
+
return 'anonymous';
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return 'anonymous';
|
|
84
|
+
}
|
|
85
|
+
};
|
|
41
86
|
/**
|
|
42
87
|
* Capture a usage event
|
|
43
88
|
*/
|
|
44
|
-
export const capture = (eventName, properties = {}) => {
|
|
89
|
+
export const capture = async (eventName, properties = {}) => {
|
|
45
90
|
if (TELEMETRY_DISABLED || !client) {
|
|
46
91
|
return;
|
|
47
92
|
}
|
|
48
93
|
try {
|
|
49
|
-
const
|
|
94
|
+
const identity = await getIdentity();
|
|
50
95
|
const metadata = getMetadata();
|
|
51
96
|
client.capture({
|
|
52
|
-
distinctId,
|
|
97
|
+
distinctId: identity,
|
|
53
98
|
event: eventName,
|
|
54
99
|
properties: {
|
|
55
100
|
...metadata,
|
|
@@ -65,15 +110,16 @@ export const capture = (eventName, properties = {}) => {
|
|
|
65
110
|
}
|
|
66
111
|
};
|
|
67
112
|
/**
|
|
68
|
-
*
|
|
113
|
+
* Capture a command failure event with error details
|
|
69
114
|
*/
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
115
|
+
export const captureCommandFailure = async (command, error) => {
|
|
116
|
+
const errorMessage = error instanceof Error ? error.message : error;
|
|
117
|
+
const errorStack = error instanceof Error ? error.stack : undefined;
|
|
118
|
+
await capture('command_failure', {
|
|
119
|
+
command,
|
|
120
|
+
error_message: errorMessage,
|
|
121
|
+
error_stack: errorStack,
|
|
122
|
+
});
|
|
77
123
|
};
|
|
78
124
|
/**
|
|
79
125
|
* Get CLI metadata to include with all events
|
|
@@ -88,6 +134,7 @@ const getMetadata = () => {
|
|
|
88
134
|
platform: process.arch,
|
|
89
135
|
machine_id: os.hostname(),
|
|
90
136
|
is_ci: isCI(),
|
|
137
|
+
is_cosmo_cloud: isTalkingToCosmoCloud(),
|
|
91
138
|
};
|
|
92
139
|
};
|
|
93
140
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../../../src/core/telemetry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../../../src/core/telemetry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,kDAAkD,CAAC;AAClF,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,yDAAyD;AACzD,yEAAyE;AACzE,MAAM,kBAAkB,GAAG,OAAO,CAAC,GAAG,CAAC,wBAAwB,KAAK,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,KAAK,GAAG,CAAC;AAE/G,IAAI,MAAM,GAAmB,IAAI,CAAC;AAElC,IAAI,SAAS,GAA2C,IAAI,CAAC;AAE7D,wCAAwC;AACxC,MAAM,IAAI,GAAG,GAAY,EAAE;IACzB,OAAO,OAAO,CACZ,OAAO,CAAC,GAAG,CAAC,EAAE,IAAI,uDAAuD;QACvE,OAAO,CAAC,GAAG,CAAC,sBAAsB;QAClC,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,UAAU;QACtC,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,WAAW;QAC3C,OAAO,CAA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AAgB;YAChB,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;gBACtB,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,GAAG,CAAC,CAAC;YACtD,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as dotenv from 'dotenv';
|
|
|
3
3
|
import pc from 'picocolors';
|
|
4
4
|
import boxen from 'boxen';
|
|
5
5
|
import program from './commands/index.js';
|
|
6
|
-
import { initTelemetry, shutdownTelemetry } from './core/telemetry.js';
|
|
6
|
+
import { initTelemetry, shutdownTelemetry, captureCommandFailure } from './core/telemetry.js';
|
|
7
7
|
dotenv.config();
|
|
8
8
|
initTelemetry();
|
|
9
9
|
try {
|
|
@@ -11,6 +11,15 @@ try {
|
|
|
11
11
|
await shutdownTelemetry();
|
|
12
12
|
}
|
|
13
13
|
catch (e) {
|
|
14
|
+
try {
|
|
15
|
+
const commandPath = process.argv.slice(2).join(' ');
|
|
16
|
+
await captureCommandFailure(commandPath, e);
|
|
17
|
+
}
|
|
18
|
+
catch (telemetryError) {
|
|
19
|
+
if (process.env.DEBUG) {
|
|
20
|
+
console.error('Failed to capture command failure telemetry:', telemetryError);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
14
23
|
console.log('');
|
|
15
24
|
console.error(e);
|
|
16
25
|
const message = `\
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,OAAO,MAAM,qBAAqB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"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