wgc 0.79.1 → 0.79.3
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 +1 -1
- package/dist/src/commands/feature-flag/index.js +1 -1
- package/dist/src/commands/feature-flag/index.js.map +1 -1
- package/dist/src/core/telemetry.d.ts +1 -1
- package/dist/src/core/telemetry.js +49 -16
- package/dist/src/core/telemetry.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
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
|
@@ -8,7 +8,7 @@ import UpdateFeatureFlagCommand from './commands/update.js';
|
|
|
8
8
|
import ListFeatureFlagCommand from './commands/list.js';
|
|
9
9
|
export default (opts) => {
|
|
10
10
|
const command = new Command('feature-flag').alias('ff');
|
|
11
|
-
command.description('Provides commands for creating and managing
|
|
11
|
+
command.description('Provides commands for creating and managing feature flags.');
|
|
12
12
|
command.addCommand(CreateFeatureFlagCommand(opts));
|
|
13
13
|
command.addCommand(DeleteFeatureFlagCommand(opts));
|
|
14
14
|
command.addCommand(EnableFeatureFlagCommand(opts));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/commands/feature-flag/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,wBAAwB,MAAM,sBAAsB,CAAC;AAC5D,OAAO,wBAAwB,MAAM,sBAAsB,CAAC;AAC5D,OAAO,wBAAwB,MAAM,sBAAsB,CAAC;AAC5D,OAAO,yBAAyB,MAAM,uBAAuB,CAAC;AAC9D,OAAO,wBAAwB,MAAM,sBAAsB,CAAC;AAC5D,OAAO,sBAAsB,MAAM,oBAAoB,CAAC;AAExD,eAAe,CAAC,IAAwB,EAAE,EAAE;IAC1C,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACxD,OAAO,CAAC,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/commands/feature-flag/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,wBAAwB,MAAM,sBAAsB,CAAC;AAC5D,OAAO,wBAAwB,MAAM,sBAAsB,CAAC;AAC5D,OAAO,wBAAwB,MAAM,sBAAsB,CAAC;AAC5D,OAAO,yBAAyB,MAAM,uBAAuB,CAAC;AAC9D,OAAO,wBAAwB,MAAM,sBAAsB,CAAC;AAC5D,OAAO,sBAAsB,MAAM,oBAAoB,CAAC;AAExD,eAAe,CAAC,IAAwB,EAAE,EAAE;IAC1C,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACxD,OAAO,CAAC,WAAW,CAAC,4DAA4D,CAAC,CAAC;IAElF,OAAO,CAAC,UAAU,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,OAAO,CAAC,UAAU,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,OAAO,CAAC,UAAU,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,OAAO,CAAC,UAAU,CAAC,yBAAyB,CAAC,IAAI,CAAC,CAAC,CAAC;IACpD,OAAO,CAAC,UAAU,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,OAAO,CAAC,UAAU,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC;IAEjD,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,IAAI,EAAE;QACnC,MAAM,SAAS,EAAE,CAAC;IACpB,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC"}
|
|
@@ -6,7 +6,7 @@ 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
10
|
/**
|
|
11
11
|
* Shutdown PostHog client - should be called before CLI exits
|
|
12
12
|
*/
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import os from 'node:os';
|
|
2
2
|
import { PostHog } from 'posthog-node';
|
|
3
|
+
import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb';
|
|
3
4
|
import { config, getBaseHeaders } 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.
|
|
@@ -23,7 +26,7 @@ export const initTelemetry = () => {
|
|
|
23
26
|
if (TELEMETRY_DISABLED) {
|
|
24
27
|
return;
|
|
25
28
|
}
|
|
26
|
-
const posthogApiKey = process.env.POSTHOG_API_KEY || '';
|
|
29
|
+
const posthogApiKey = process.env.POSTHOG_API_KEY || 'phc_CEnvoyw3KcTuC5E1seDPrgvAamgGRDLfzPi1e7RU1G1';
|
|
27
30
|
const posthogHost = process.env.POSTHOG_HOST || 'https://eu.i.posthog.com';
|
|
28
31
|
client = new PostHog(posthogApiKey, {
|
|
29
32
|
host: posthogHost,
|
|
@@ -31,6 +34,12 @@ export const initTelemetry = () => {
|
|
|
31
34
|
flushInterval: 0, // Don't wait to flush events
|
|
32
35
|
disableGeoip: false,
|
|
33
36
|
});
|
|
37
|
+
const proxyUrl = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
|
|
38
|
+
apiClient = CreateClient({
|
|
39
|
+
baseUrl: config.baseURL,
|
|
40
|
+
apiKey: config.apiKey,
|
|
41
|
+
proxyUrl,
|
|
42
|
+
});
|
|
34
43
|
// Handle errors silently to not interrupt CLI operations
|
|
35
44
|
client.on('error', (err) => {
|
|
36
45
|
if (process.env.DEBUG) {
|
|
@@ -38,18 +47,53 @@ export const initTelemetry = () => {
|
|
|
38
47
|
}
|
|
39
48
|
});
|
|
40
49
|
};
|
|
50
|
+
// Fallback to using headers if the API call fails
|
|
51
|
+
const getFallbackIdentity = () => {
|
|
52
|
+
const headers = getBaseHeaders();
|
|
53
|
+
const headersRecord = Object.fromEntries(Object.entries(headers).map(([key, value]) => [key, value.toString()]));
|
|
54
|
+
const organizationSlug = headersRecord['cosmo-org-slug'] || 'anonymous';
|
|
55
|
+
return organizationSlug;
|
|
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
|
+
// If no API key is available, return anonymous
|
|
65
|
+
if (!config.apiKey) {
|
|
66
|
+
return 'anonymous';
|
|
67
|
+
}
|
|
68
|
+
// If the API client is not initialized, return anonymous
|
|
69
|
+
if (!apiClient) {
|
|
70
|
+
return 'anonymous';
|
|
71
|
+
}
|
|
72
|
+
// Call the whoAmI API to get organization information
|
|
73
|
+
const resp = await apiClient.platform.whoAmI({}, {
|
|
74
|
+
headers: getBaseHeaders(),
|
|
75
|
+
});
|
|
76
|
+
if (((_a = resp.response) === null || _a === void 0 ? void 0 : _a.code) === EnumStatusCode.OK) {
|
|
77
|
+
return resp.organizationSlug;
|
|
78
|
+
}
|
|
79
|
+
return getFallbackIdentity();
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return getFallbackIdentity();
|
|
83
|
+
}
|
|
84
|
+
};
|
|
41
85
|
/**
|
|
42
86
|
* Capture a usage event
|
|
43
87
|
*/
|
|
44
|
-
export const capture = (eventName, properties = {}) => {
|
|
88
|
+
export const capture = async (eventName, properties = {}) => {
|
|
45
89
|
if (TELEMETRY_DISABLED || !client) {
|
|
46
90
|
return;
|
|
47
91
|
}
|
|
48
92
|
try {
|
|
49
|
-
const
|
|
93
|
+
const identity = await getIdentity();
|
|
50
94
|
const metadata = getMetadata();
|
|
51
95
|
client.capture({
|
|
52
|
-
distinctId,
|
|
96
|
+
distinctId: identity,
|
|
53
97
|
event: eventName,
|
|
54
98
|
properties: {
|
|
55
99
|
...metadata,
|
|
@@ -64,17 +108,6 @@ export const capture = (eventName, properties = {}) => {
|
|
|
64
108
|
}
|
|
65
109
|
}
|
|
66
110
|
};
|
|
67
|
-
/**
|
|
68
|
-
* Generate a consistent distinct ID
|
|
69
|
-
*/
|
|
70
|
-
const getDistinctId = () => {
|
|
71
|
-
// Use organization slug if available
|
|
72
|
-
const headers = getBaseHeaders();
|
|
73
|
-
// Convert HeadersInit to Record to safely access properties
|
|
74
|
-
const headersRecord = Object.fromEntries(Object.entries(headers).map(([key, value]) => [key, value.toString()]));
|
|
75
|
-
const organizationSlug = headersRecord['cosmo-org-slug'] || 'anonymous';
|
|
76
|
-
return `cli_${organizationSlug}`;
|
|
77
|
-
};
|
|
78
111
|
/**
|
|
79
112
|
* Get CLI metadata to include with all events
|
|
80
113
|
*/
|
|
@@ -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,MAAM,aAAa,CAAC;AACrD,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,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