@gurulu/cli 0.4.3 → 0.4.5
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 +24 -0
- package/dist/commands/audiences.d.ts +4 -0
- package/dist/commands/audiences.js +37 -1
- package/dist/commands/consent.d.ts +27 -0
- package/dist/commands/consent.js +233 -0
- package/dist/commands/db.js +8 -0
- package/dist/commands/events.js +25 -4
- package/dist/commands/heatmap.d.ts +27 -0
- package/dist/commands/heatmap.js +112 -0
- package/dist/commands/identity.d.ts +3 -0
- package/dist/commands/identity.js +138 -1
- package/dist/commands/install.d.ts +16 -3
- package/dist/commands/install.js +389 -30
- package/dist/commands/secrets.d.ts +19 -0
- package/dist/commands/secrets.js +145 -0
- package/dist/commands/upgrade.d.ts +21 -0
- package/dist/commands/upgrade.js +183 -0
- package/dist/index.js +121 -4
- package/dist/utils/redact.d.ts +14 -0
- package/dist/utils/redact.js +48 -0
- package/package.json +1 -1
- package/scripts/bootstrap-runtime-schema.mjs +7 -25
package/README.md
CHANGED
|
@@ -101,3 +101,27 @@ gurulu events list --json
|
|
|
101
101
|
gurulu status --json
|
|
102
102
|
gurulu doctor --json
|
|
103
103
|
```
|
|
104
|
+
|
|
105
|
+
## Telemetry
|
|
106
|
+
|
|
107
|
+
`gurulu install` records anonymous install telemetry — framework, CLI version,
|
|
108
|
+
install status, and a SHA-256 hash of the absolute repo path — to help us
|
|
109
|
+
improve framework detection and patch reliability. **No source code, file
|
|
110
|
+
contents, or environment variables are ever sent.**
|
|
111
|
+
|
|
112
|
+
On the first interactive install you'll be asked to opt in. Your choice is
|
|
113
|
+
persisted to `~/.gurulu/config.json` (`telemetry: true|false`) and never
|
|
114
|
+
re-asked.
|
|
115
|
+
|
|
116
|
+
To opt out:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
gurulu install --no-telemetry # one-off
|
|
120
|
+
export GURULU_TELEMETRY=off # session / shell
|
|
121
|
+
export DO_NOT_TRACK=1 # honored across most CLI tools
|
|
122
|
+
echo '{"telemetry": false}' > ~/.gurulu/config.json # permanent
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Any of `GURULU_TELEMETRY=off|0|false|no`, `DO_NOT_TRACK=1`, `--no-telemetry`,
|
|
126
|
+
or `telemetry: false` in `~/.gurulu/config.json` disables telemetry — the repo
|
|
127
|
+
hash is never computed and no network request is made.
|
|
@@ -15,5 +15,9 @@ export interface AudiencesArgs {
|
|
|
15
15
|
rules?: string;
|
|
16
16
|
yes?: boolean;
|
|
17
17
|
dryRun?: boolean;
|
|
18
|
+
format?: 'csv' | 'json' | string;
|
|
19
|
+
output?: string;
|
|
20
|
+
preview?: boolean;
|
|
21
|
+
limit?: number;
|
|
18
22
|
}
|
|
19
23
|
export declare function audiencesCommand(args: AudiencesArgs): Promise<void>;
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.audiencesCommand = audiencesCommand;
|
|
8
|
+
const node_fs_1 = require("node:fs");
|
|
8
9
|
const api_client_1 = require("../api-client");
|
|
9
10
|
const ui_1 = require("../utils/ui");
|
|
10
11
|
const confirm_1 = require("../utils/confirm");
|
|
@@ -23,9 +24,11 @@ async function audiencesCommand(args) {
|
|
|
23
24
|
return updateCmd(args);
|
|
24
25
|
case 'delete':
|
|
25
26
|
return deleteCmd(args);
|
|
27
|
+
case 'export':
|
|
28
|
+
return exportCmd(args);
|
|
26
29
|
default:
|
|
27
30
|
(0, ui_1.error)(`Unknown audiences action: ${action}`);
|
|
28
|
-
(0, ui_1.info)('Usage: gurulu audiences [list|show|create|update|delete]');
|
|
31
|
+
(0, ui_1.info)('Usage: gurulu audiences [list|show|create|update|delete|export]');
|
|
29
32
|
process.exit(1);
|
|
30
33
|
}
|
|
31
34
|
}
|
|
@@ -205,3 +208,36 @@ async function deleteCmd(args) {
|
|
|
205
208
|
});
|
|
206
209
|
(0, ui_1.success)(`Deleted audience ${id}`);
|
|
207
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* AU5 (audit-2026-04-29-audience.md) — `gurulu audiences export <name-or-id>`.
|
|
213
|
+
* Streams the current audience membership as CSV (default) or JSON. With
|
|
214
|
+
* `--output <path>` we write to disk; otherwise the body goes to stdout.
|
|
215
|
+
*/
|
|
216
|
+
async function exportCmd(args) {
|
|
217
|
+
const target = args.target;
|
|
218
|
+
if (!target) {
|
|
219
|
+
(0, ui_1.error)('Usage: gurulu audiences export <name-or-id> [--format csv|json] [--output file]');
|
|
220
|
+
process.exit(1);
|
|
221
|
+
}
|
|
222
|
+
const id = await resolveId(target, args.profile);
|
|
223
|
+
const format = (args.format || 'csv').toLowerCase();
|
|
224
|
+
if (format !== 'csv' && format !== 'json') {
|
|
225
|
+
(0, ui_1.error)('--format must be csv or json');
|
|
226
|
+
process.exit(1);
|
|
227
|
+
}
|
|
228
|
+
const path = `/api/cli/audiences/${encodeURIComponent(id)}/export?format=${format}&destination=download`;
|
|
229
|
+
const res = await (0, api_client_1.cliApi)(path, { profile: args.profile });
|
|
230
|
+
const body = await res.text();
|
|
231
|
+
if (!res.ok) {
|
|
232
|
+
(0, ui_1.error)(`Export failed (HTTP ${res.status}): ${body.slice(0, 200)}`);
|
|
233
|
+
process.exit(1);
|
|
234
|
+
}
|
|
235
|
+
if (args.output) {
|
|
236
|
+
(0, node_fs_1.writeFileSync)(args.output, body, 'utf8');
|
|
237
|
+
(0, ui_1.success)(`Wrote ${body.length} bytes to ${args.output}`);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
process.stdout.write(body);
|
|
241
|
+
if (!body.endsWith('\n'))
|
|
242
|
+
process.stdout.write('\n');
|
|
243
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI@0.4.4 — `gurulu consent` — manage per-user consent scopes (GDPR).
|
|
3
|
+
*
|
|
4
|
+
* Subcommands:
|
|
5
|
+
* gurulu consent set --user-id X --scope marketing_external --state granted|denied
|
|
6
|
+
* gurulu consent get --user-id X
|
|
7
|
+
* gurulu consent revoke --user-id X
|
|
8
|
+
* gurulu consent check --user-id X --destination capi
|
|
9
|
+
*
|
|
10
|
+
* TODO(Sprint K): backend endpoints below are not yet live. The CLI command
|
|
11
|
+
* surface is implemented now so customers can wire automation; once the API
|
|
12
|
+
* routes ship, the cliApi calls will succeed without any further CLI changes.
|
|
13
|
+
* - POST /api/cli/consent/set { userId, scope, state }
|
|
14
|
+
* - GET /api/cli/consent/get?userId=... (returns scopes[])
|
|
15
|
+
* - POST /api/cli/consent/revoke { userId } (denies all scopes)
|
|
16
|
+
* - GET /api/cli/consent/check?userId=...&destination=... (returns { allowed: boolean })
|
|
17
|
+
*/
|
|
18
|
+
export interface ConsentArgs {
|
|
19
|
+
action?: string;
|
|
20
|
+
userId?: string;
|
|
21
|
+
scope?: string;
|
|
22
|
+
state?: string;
|
|
23
|
+
destination?: string;
|
|
24
|
+
json?: boolean;
|
|
25
|
+
profile?: string;
|
|
26
|
+
}
|
|
27
|
+
export declare function consentCommand(args: ConsentArgs): Promise<void>;
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* CLI@0.4.4 — `gurulu consent` — manage per-user consent scopes (GDPR).
|
|
4
|
+
*
|
|
5
|
+
* Subcommands:
|
|
6
|
+
* gurulu consent set --user-id X --scope marketing_external --state granted|denied
|
|
7
|
+
* gurulu consent get --user-id X
|
|
8
|
+
* gurulu consent revoke --user-id X
|
|
9
|
+
* gurulu consent check --user-id X --destination capi
|
|
10
|
+
*
|
|
11
|
+
* TODO(Sprint K): backend endpoints below are not yet live. The CLI command
|
|
12
|
+
* surface is implemented now so customers can wire automation; once the API
|
|
13
|
+
* routes ship, the cliApi calls will succeed without any further CLI changes.
|
|
14
|
+
* - POST /api/cli/consent/set { userId, scope, state }
|
|
15
|
+
* - GET /api/cli/consent/get?userId=... (returns scopes[])
|
|
16
|
+
* - POST /api/cli/consent/revoke { userId } (denies all scopes)
|
|
17
|
+
* - GET /api/cli/consent/check?userId=...&destination=... (returns { allowed: boolean })
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.consentCommand = consentCommand;
|
|
21
|
+
const config_1 = require("../config");
|
|
22
|
+
const api_client_1 = require("../api-client");
|
|
23
|
+
const ui_1 = require("../utils/ui");
|
|
24
|
+
async function consentCommand(args) {
|
|
25
|
+
switch (args.action) {
|
|
26
|
+
case 'set':
|
|
27
|
+
return consentSet(args);
|
|
28
|
+
case 'get':
|
|
29
|
+
return consentGet(args);
|
|
30
|
+
case 'revoke':
|
|
31
|
+
return consentRevoke(args);
|
|
32
|
+
case 'check':
|
|
33
|
+
return consentCheck(args);
|
|
34
|
+
default:
|
|
35
|
+
(0, ui_1.error)(`Unknown action: ${args.action}. Use: set, get, revoke, check`);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function loadProfileOrExit(args) {
|
|
40
|
+
try {
|
|
41
|
+
return await (0, config_1.loadActiveProfile)({ profile: args.profile });
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
(0, ui_1.error)('Not authenticated. Run "gurulu login" first.');
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function emitFallbackNotice(json) {
|
|
49
|
+
if (json)
|
|
50
|
+
return;
|
|
51
|
+
(0, ui_1.info)((0, ui_1.dim)('Note: backend endpoint not yet live (Sprint K candidate). Command-shape is stable.'));
|
|
52
|
+
}
|
|
53
|
+
// ── set ────────────────────────────────────────────────────────────────────
|
|
54
|
+
async function consentSet(args) {
|
|
55
|
+
if (!args.userId || !args.scope || !args.state) {
|
|
56
|
+
(0, ui_1.error)('Usage: gurulu consent set --user-id <id> --scope <scope> --state <granted|denied>');
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
if (args.state !== 'granted' && args.state !== 'denied') {
|
|
60
|
+
(0, ui_1.error)('--state must be one of: granted, denied');
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
const profile = await loadProfileOrExit(args);
|
|
64
|
+
try {
|
|
65
|
+
const res = await (0, api_client_1.cliApi)('/api/cli/consent/set', {
|
|
66
|
+
method: 'POST',
|
|
67
|
+
body: JSON.stringify({ userId: args.userId, scope: args.scope, state: args.state }),
|
|
68
|
+
preloadedProfile: profile,
|
|
69
|
+
});
|
|
70
|
+
const data = await res.json().catch(() => ({}));
|
|
71
|
+
if (res.status === 404) {
|
|
72
|
+
emitFallbackNotice(args.json);
|
|
73
|
+
if (args.json) {
|
|
74
|
+
console.log(JSON.stringify({ ok: false, pending: true, userId: args.userId, scope: args.scope, state: args.state }));
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
(0, ui_1.info)(`Pending: would set consent[${args.scope}] = ${args.state} for ${args.userId}`);
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (!res.ok) {
|
|
82
|
+
const msg = data.message || data.error || `HTTP ${res.status}`;
|
|
83
|
+
if (args.json)
|
|
84
|
+
console.log(JSON.stringify({ ok: false, error: msg }));
|
|
85
|
+
else
|
|
86
|
+
(0, ui_1.error)(msg);
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
if (args.json)
|
|
90
|
+
console.log(JSON.stringify(data, null, 2));
|
|
91
|
+
else
|
|
92
|
+
(0, ui_1.success)(`Consent[${args.scope}] = ${args.state} for ${args.userId}`);
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
if (args.json)
|
|
96
|
+
console.log(JSON.stringify({ ok: false, error: err.message }));
|
|
97
|
+
else
|
|
98
|
+
(0, ui_1.error)(`Failed: ${err.message}`);
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// ── get ────────────────────────────────────────────────────────────────────
|
|
103
|
+
async function consentGet(args) {
|
|
104
|
+
if (!args.userId) {
|
|
105
|
+
(0, ui_1.error)('Usage: gurulu consent get --user-id <id>');
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
const profile = await loadProfileOrExit(args);
|
|
109
|
+
try {
|
|
110
|
+
const res = await (0, api_client_1.cliApi)(`/api/cli/consent/get?userId=${encodeURIComponent(args.userId)}`, { preloadedProfile: profile });
|
|
111
|
+
const data = await res.json().catch(() => ({}));
|
|
112
|
+
if (res.status === 404) {
|
|
113
|
+
emitFallbackNotice(args.json);
|
|
114
|
+
if (args.json)
|
|
115
|
+
console.log(JSON.stringify({ ok: false, pending: true, userId: args.userId, scopes: [] }));
|
|
116
|
+
else
|
|
117
|
+
(0, ui_1.info)(`Pending: would fetch consent scopes for ${args.userId}`);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (!res.ok) {
|
|
121
|
+
const msg = data.message || data.error || `HTTP ${res.status}`;
|
|
122
|
+
if (args.json)
|
|
123
|
+
console.log(JSON.stringify({ ok: false, error: msg }));
|
|
124
|
+
else
|
|
125
|
+
(0, ui_1.error)(msg);
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
if (args.json) {
|
|
129
|
+
console.log(JSON.stringify(data, null, 2));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const scopes = data.scopes || [];
|
|
133
|
+
if (scopes.length === 0) {
|
|
134
|
+
(0, ui_1.info)(`No consent records for ${args.userId}`);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
console.log((0, ui_1.bold)(`Consent scopes for ${args.userId}:`));
|
|
138
|
+
for (const s of scopes) {
|
|
139
|
+
const ts = s.updatedAt ? (0, ui_1.dim)(` (${s.updatedAt})`) : '';
|
|
140
|
+
(0, ui_1.step)(`${s.scope}: ${s.state}${ts}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
if (args.json)
|
|
145
|
+
console.log(JSON.stringify({ ok: false, error: err.message }));
|
|
146
|
+
else
|
|
147
|
+
(0, ui_1.error)(`Failed: ${err.message}`);
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// ── revoke ─────────────────────────────────────────────────────────────────
|
|
152
|
+
async function consentRevoke(args) {
|
|
153
|
+
if (!args.userId) {
|
|
154
|
+
(0, ui_1.error)('Usage: gurulu consent revoke --user-id <id>');
|
|
155
|
+
process.exit(1);
|
|
156
|
+
}
|
|
157
|
+
const profile = await loadProfileOrExit(args);
|
|
158
|
+
try {
|
|
159
|
+
const res = await (0, api_client_1.cliApi)('/api/cli/consent/revoke', {
|
|
160
|
+
method: 'POST',
|
|
161
|
+
body: JSON.stringify({ userId: args.userId }),
|
|
162
|
+
preloadedProfile: profile,
|
|
163
|
+
});
|
|
164
|
+
const data = await res.json().catch(() => ({}));
|
|
165
|
+
if (res.status === 404) {
|
|
166
|
+
emitFallbackNotice(args.json);
|
|
167
|
+
if (args.json)
|
|
168
|
+
console.log(JSON.stringify({ ok: false, pending: true, userId: args.userId }));
|
|
169
|
+
else
|
|
170
|
+
(0, ui_1.info)(`Pending: would deny all consent scopes for ${args.userId}`);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (!res.ok) {
|
|
174
|
+
const msg = data.message || data.error || `HTTP ${res.status}`;
|
|
175
|
+
if (args.json)
|
|
176
|
+
console.log(JSON.stringify({ ok: false, error: msg }));
|
|
177
|
+
else
|
|
178
|
+
(0, ui_1.error)(msg);
|
|
179
|
+
process.exit(1);
|
|
180
|
+
}
|
|
181
|
+
if (args.json)
|
|
182
|
+
console.log(JSON.stringify(data, null, 2));
|
|
183
|
+
else
|
|
184
|
+
(0, ui_1.success)(`All consent scopes revoked for ${args.userId}`);
|
|
185
|
+
}
|
|
186
|
+
catch (err) {
|
|
187
|
+
if (args.json)
|
|
188
|
+
console.log(JSON.stringify({ ok: false, error: err.message }));
|
|
189
|
+
else
|
|
190
|
+
(0, ui_1.error)(`Failed: ${err.message}`);
|
|
191
|
+
process.exit(1);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// ── check ─────────────────────────────────────────────────────────────────
|
|
195
|
+
async function consentCheck(args) {
|
|
196
|
+
if (!args.userId || !args.destination) {
|
|
197
|
+
(0, ui_1.error)('Usage: gurulu consent check --user-id <id> --destination <capi|ga4|...>');
|
|
198
|
+
process.exit(1);
|
|
199
|
+
}
|
|
200
|
+
const profile = await loadProfileOrExit(args);
|
|
201
|
+
try {
|
|
202
|
+
const data = await (0, api_client_1.cliApiJson)(`/api/cli/consent/check?userId=${encodeURIComponent(args.userId)}&destination=${encodeURIComponent(args.destination)}`, { preloadedProfile: profile });
|
|
203
|
+
if (args.json) {
|
|
204
|
+
console.log(JSON.stringify(data, null, 2));
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (data.allowed) {
|
|
208
|
+
(0, ui_1.success)(`Dispatch ALLOWED to ${args.destination} for ${args.userId}`);
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
(0, ui_1.info)(`Dispatch DENIED to ${args.destination} for ${args.userId}${data.reason ? ` (${data.reason})` : ''}`);
|
|
212
|
+
}
|
|
213
|
+
// Exit code mirrors the boolean for shell scripting.
|
|
214
|
+
process.exit(data.allowed ? 0 : 2);
|
|
215
|
+
}
|
|
216
|
+
catch (err) {
|
|
217
|
+
const msg = err.message || '';
|
|
218
|
+
// 404 from the API client means the endpoint isn't live yet.
|
|
219
|
+
if (/HTTP 404|Not Found/i.test(msg)) {
|
|
220
|
+
emitFallbackNotice(args.json);
|
|
221
|
+
if (args.json)
|
|
222
|
+
console.log(JSON.stringify({ ok: false, pending: true, allowed: null, userId: args.userId, destination: args.destination }));
|
|
223
|
+
else
|
|
224
|
+
(0, ui_1.info)(`Pending: would check consent for ${args.userId} → ${args.destination}`);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (args.json)
|
|
228
|
+
console.log(JSON.stringify({ ok: false, error: msg }));
|
|
229
|
+
else
|
|
230
|
+
(0, ui_1.error)(`Failed: ${msg}`);
|
|
231
|
+
process.exit(1);
|
|
232
|
+
}
|
|
233
|
+
}
|
package/dist/commands/db.js
CHANGED
|
@@ -13,6 +13,7 @@ exports.dbCommand = dbCommand;
|
|
|
13
13
|
const config_1 = require("../config");
|
|
14
14
|
const api_client_1 = require("../api-client");
|
|
15
15
|
const ui_1 = require("../utils/ui");
|
|
16
|
+
const redact_1 = require("../utils/redact");
|
|
16
17
|
async function dbCommand(args) {
|
|
17
18
|
switch (args.action) {
|
|
18
19
|
case 'connect':
|
|
@@ -79,6 +80,13 @@ async function dbConnect(args) {
|
|
|
79
80
|
}
|
|
80
81
|
const effectivePort = port || (dbType === 'mysql' ? 3306 : 5432);
|
|
81
82
|
(0, ui_1.info)('Testing connection...');
|
|
83
|
+
// CLI@0.4.4 P0 security — never echo password to stdout/telemetry.
|
|
84
|
+
// The verbose/debug path used to dump the raw args object; route it through
|
|
85
|
+
// the redaction helper so password/token/secret keys are masked.
|
|
86
|
+
if (process.env.GURULU_DEBUG === '1') {
|
|
87
|
+
const safeArgs = (0, redact_1.redactSensitiveArgs)({ ...args });
|
|
88
|
+
console.log(`[debug] db connect args: ${(0, redact_1.safeStringifyArgs)(safeArgs)}`);
|
|
89
|
+
}
|
|
82
90
|
try {
|
|
83
91
|
// First call: test + potentially list tables
|
|
84
92
|
const body = {
|
package/dist/commands/events.js
CHANGED
|
@@ -184,7 +184,13 @@ async function defineCmd(args) {
|
|
|
184
184
|
process.exit(1);
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
|
-
|
|
187
|
+
// Use the user-provided name verbatim. The CLI used to force a `$` prefix
|
|
188
|
+
// because Gurulu's built-ins use one (`$page_view`, `$session_start`), but
|
|
189
|
+
// built-ins are inconsistent (`click`, `engaged_session` have none) and
|
|
190
|
+
// mutating the customer's chosen name silently broke schema lookups + made
|
|
191
|
+
// the generated SDK snippets reference a name that no longer matched the
|
|
192
|
+
// ingest payload.
|
|
193
|
+
const eventName = args.eventName;
|
|
188
194
|
const body = {
|
|
189
195
|
siteId: args.site,
|
|
190
196
|
eventName,
|
|
@@ -207,10 +213,14 @@ async function verifyCmd(args) {
|
|
|
207
213
|
(0, ui_1.error)('--site is required.');
|
|
208
214
|
process.exit(1);
|
|
209
215
|
}
|
|
216
|
+
// Accept both `--event` (verify-original) and `--event-name` (used by
|
|
217
|
+
// every other events subcommand). Removes the surprising flag-name
|
|
218
|
+
// inconsistency without breaking existing scripts.
|
|
219
|
+
const filterEvent = args.event || args.eventName;
|
|
210
220
|
const qs = new URLSearchParams();
|
|
211
221
|
qs.set('siteId', args.site);
|
|
212
|
-
if (
|
|
213
|
-
qs.set('eventName',
|
|
222
|
+
if (filterEvent)
|
|
223
|
+
qs.set('eventName', filterEvent);
|
|
214
224
|
const path = `/api/cli/events/health?${qs.toString()}`;
|
|
215
225
|
const data = await (0, api_client_1.cliApiJson)(path, { profile: args.profile });
|
|
216
226
|
if (args.json) {
|
|
@@ -220,7 +230,7 @@ async function verifyCmd(args) {
|
|
|
220
230
|
console.log((0, ui_1.bold)('\nEvent Health Report'));
|
|
221
231
|
console.log(`Site: ${args.site}`);
|
|
222
232
|
console.log('');
|
|
223
|
-
if (Array.isArray(data.events)) {
|
|
233
|
+
if (Array.isArray(data.events) && data.events.length > 0) {
|
|
224
234
|
for (const ev of data.events) {
|
|
225
235
|
const statusIcon = ev.status === 'active'
|
|
226
236
|
? (0, ui_1.green)('●')
|
|
@@ -237,6 +247,17 @@ async function verifyCmd(args) {
|
|
|
237
247
|
console.log(`Total events (24h): ${data.total_events}`);
|
|
238
248
|
console.log(`Unique event types: ${data.unique_types ?? 'N/A'}`);
|
|
239
249
|
}
|
|
250
|
+
else {
|
|
251
|
+
// Empty: no telemetry yet for the requested filter / definition. Without
|
|
252
|
+
// this branch the report printed only its header — users couldn't tell
|
|
253
|
+
// success from "no data found".
|
|
254
|
+
if (filterEvent) {
|
|
255
|
+
(0, ui_1.info)(`No telemetry yet for "${filterEvent}". Track it from your app and run verify again.`);
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
(0, ui_1.info)('No telemetry data found for this site in the last 24h.');
|
|
259
|
+
}
|
|
260
|
+
}
|
|
240
261
|
console.log('');
|
|
241
262
|
}
|
|
242
263
|
/* ── templates: list vertical event template catalogs ───────────── */
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sprint J-Heat HM10 — `gurulu heatmap ...` subcommands.
|
|
3
|
+
*
|
|
4
|
+
* Read-only surface backed by `/api/cli/heatmap/list` and
|
|
5
|
+
* `/api/cli/heatmap/get`. Lets agents and operators inspect heatmap
|
|
6
|
+
* snapshots without opening the dashboard.
|
|
7
|
+
*
|
|
8
|
+
* gurulu heatmap list --site <id|name> [--range 7d|30d] [--json]
|
|
9
|
+
* gurulu heatmap export --site <id|name> --page <pageUrl>
|
|
10
|
+
* [--type click|scroll]
|
|
11
|
+
* [--range 7d|30d]
|
|
12
|
+
* [--viewport mobile|tablet|desktop]
|
|
13
|
+
* [--page-id <hash>]
|
|
14
|
+
* [--json]
|
|
15
|
+
*/
|
|
16
|
+
export interface HeatmapArgs {
|
|
17
|
+
action?: string;
|
|
18
|
+
site?: string;
|
|
19
|
+
page?: string;
|
|
20
|
+
pageId?: string;
|
|
21
|
+
type?: string;
|
|
22
|
+
range?: string;
|
|
23
|
+
viewport?: string;
|
|
24
|
+
json?: boolean;
|
|
25
|
+
profile?: string;
|
|
26
|
+
}
|
|
27
|
+
export declare function heatmapCommand(args: HeatmapArgs): Promise<void>;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Sprint J-Heat HM10 — `gurulu heatmap ...` subcommands.
|
|
4
|
+
*
|
|
5
|
+
* Read-only surface backed by `/api/cli/heatmap/list` and
|
|
6
|
+
* `/api/cli/heatmap/get`. Lets agents and operators inspect heatmap
|
|
7
|
+
* snapshots without opening the dashboard.
|
|
8
|
+
*
|
|
9
|
+
* gurulu heatmap list --site <id|name> [--range 7d|30d] [--json]
|
|
10
|
+
* gurulu heatmap export --site <id|name> --page <pageUrl>
|
|
11
|
+
* [--type click|scroll]
|
|
12
|
+
* [--range 7d|30d]
|
|
13
|
+
* [--viewport mobile|tablet|desktop]
|
|
14
|
+
* [--page-id <hash>]
|
|
15
|
+
* [--json]
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.heatmapCommand = heatmapCommand;
|
|
19
|
+
const api_client_1 = require("../api-client");
|
|
20
|
+
const ui_1 = require("../utils/ui");
|
|
21
|
+
async function resolveSiteId(target, profile) {
|
|
22
|
+
if (!target)
|
|
23
|
+
throw new Error('--site is required');
|
|
24
|
+
const body = await (0, api_client_1.cliApiJson)('/api/cli/sites', { profile });
|
|
25
|
+
const sites = body.sites || [];
|
|
26
|
+
const byId = sites.find((s) => s.id === target);
|
|
27
|
+
if (byId)
|
|
28
|
+
return byId.id;
|
|
29
|
+
const byName = sites.find((s) => s.name === target);
|
|
30
|
+
if (byName)
|
|
31
|
+
return byName.id;
|
|
32
|
+
const byDomain = sites.find((s) => s.domain === target);
|
|
33
|
+
if (byDomain)
|
|
34
|
+
return byDomain.id;
|
|
35
|
+
const prefix = sites.find((s) => s.id.startsWith(target));
|
|
36
|
+
if (prefix)
|
|
37
|
+
return prefix.id;
|
|
38
|
+
throw new Error(`Site '${target}' not found.`);
|
|
39
|
+
}
|
|
40
|
+
async function heatmapCommand(args) {
|
|
41
|
+
const action = args.action || 'list';
|
|
42
|
+
switch (action) {
|
|
43
|
+
case 'list':
|
|
44
|
+
return listCmd(args);
|
|
45
|
+
case 'export':
|
|
46
|
+
return exportCmd(args);
|
|
47
|
+
default:
|
|
48
|
+
(0, ui_1.error)(`Unknown heatmap action: ${action}`);
|
|
49
|
+
(0, ui_1.info)('Usage: gurulu heatmap [list|export]');
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async function listCmd(args) {
|
|
54
|
+
if (!args.site) {
|
|
55
|
+
(0, ui_1.error)('--site is required.');
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
const siteId = await resolveSiteId(args.site, args.profile);
|
|
59
|
+
const range = args.range === '30d' ? '30d' : '7d';
|
|
60
|
+
const body = await (0, api_client_1.cliApiJson)(`/api/cli/heatmap/list?siteId=${encodeURIComponent(siteId)}&range=${range}`, {
|
|
61
|
+
profile: args.profile,
|
|
62
|
+
});
|
|
63
|
+
if (args.json) {
|
|
64
|
+
process.stdout.write(JSON.stringify(body, null, 2) + '\n');
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const pages = body.pages || [];
|
|
68
|
+
if (pages.length === 0) {
|
|
69
|
+
(0, ui_1.info)(`No heatmap data for site '${body.siteName}' (range=${range}).`);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
process.stdout.write(['CLICKS', 'VISITORS', 'M/T/D', 'LAST SEEN', 'PAGE URL'].join('\t') + '\n');
|
|
73
|
+
for (const p of pages) {
|
|
74
|
+
const mtd = `${p.viewportBuckets.mobile}/${p.viewportBuckets.tablet}/${p.viewportBuckets.desktop}`;
|
|
75
|
+
process.stdout.write([
|
|
76
|
+
String(p.clickCount),
|
|
77
|
+
String(p.visitors),
|
|
78
|
+
mtd,
|
|
79
|
+
String(p.lastSeen).slice(0, 19),
|
|
80
|
+
p.pageUrl,
|
|
81
|
+
].join('\t') + '\n');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async function exportCmd(args) {
|
|
85
|
+
if (!args.site) {
|
|
86
|
+
(0, ui_1.error)('--site is required.');
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
if (!args.page) {
|
|
90
|
+
(0, ui_1.error)('--page <pageUrl> is required.');
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
const siteId = await resolveSiteId(args.site, args.profile);
|
|
94
|
+
const range = args.range === '30d' ? '30d' : '7d';
|
|
95
|
+
const type = args.type === 'scroll' ? 'scroll' : 'click';
|
|
96
|
+
const qp = new URLSearchParams({
|
|
97
|
+
siteId,
|
|
98
|
+
pageUrl: args.page,
|
|
99
|
+
range,
|
|
100
|
+
type,
|
|
101
|
+
});
|
|
102
|
+
if (args.pageId)
|
|
103
|
+
qp.set('pageId', args.pageId);
|
|
104
|
+
if (args.viewport)
|
|
105
|
+
qp.set('viewportBucket', args.viewport);
|
|
106
|
+
const body = await (0, api_client_1.cliApiJson)(`/api/cli/heatmap/get?${qp.toString()}`, {
|
|
107
|
+
profile: args.profile,
|
|
108
|
+
});
|
|
109
|
+
// Export commands always emit machine-readable output by default; the
|
|
110
|
+
// `--json` flag is accepted for symmetry with the rest of the CLI.
|
|
111
|
+
process.stdout.write(JSON.stringify(body, null, args.json ? 2 : 0) + '\n');
|
|
112
|
+
}
|