@gurulu/cli 0.4.7 → 1.0.1

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.
Files changed (190) hide show
  1. package/LICENSE +92 -0
  2. package/README.md +35 -106
  3. package/dist/bin.d.ts +3 -0
  4. package/dist/bin.d.ts.map +1 -0
  5. package/dist/bin.js +25751 -0
  6. package/dist/commands/auth.d.ts +23 -20
  7. package/dist/commands/auth.d.ts.map +1 -0
  8. package/dist/commands/doctor.d.ts +20 -6
  9. package/dist/commands/doctor.d.ts.map +1 -0
  10. package/dist/commands/init.d.ts +33 -11
  11. package/dist/commands/init.d.ts.map +1 -0
  12. package/dist/commands/pull.d.ts +13 -0
  13. package/dist/commands/pull.d.ts.map +1 -0
  14. package/dist/commands/push.d.ts +40 -0
  15. package/dist/commands/push.d.ts.map +1 -0
  16. package/dist/commands/validate.d.ts +36 -0
  17. package/dist/commands/validate.d.ts.map +1 -0
  18. package/dist/index.d.ts +4 -1
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +25326 -876
  21. package/dist/lib/api.d.ts +139 -0
  22. package/dist/lib/api.d.ts.map +1 -0
  23. package/dist/lib/codegen.d.ts +4 -0
  24. package/dist/lib/codegen.d.ts.map +1 -0
  25. package/dist/lib/config.d.ts +43 -0
  26. package/dist/lib/config.d.ts.map +1 -0
  27. package/dist/lib/detect.d.ts +27 -0
  28. package/dist/lib/detect.d.ts.map +1 -0
  29. package/dist/lib/detect.js +106 -0
  30. package/dist/lib/exec-install.d.ts +21 -0
  31. package/dist/lib/exec-install.d.ts.map +1 -0
  32. package/dist/lib/install-plan.d.ts +25 -0
  33. package/dist/lib/install-plan.d.ts.map +1 -0
  34. package/dist/lib/install-plan.js +161 -0
  35. package/package.json +51 -20
  36. package/bin/gurulu.js +0 -2
  37. package/dist/api-client.d.ts +0 -33
  38. package/dist/api-client.js +0 -175
  39. package/dist/commands/add-server.d.ts +0 -9
  40. package/dist/commands/add-server.js +0 -162
  41. package/dist/commands/alerts.d.ts +0 -27
  42. package/dist/commands/alerts.js +0 -309
  43. package/dist/commands/api-keys.d.ts +0 -20
  44. package/dist/commands/api-keys.js +0 -130
  45. package/dist/commands/attribution.d.ts +0 -22
  46. package/dist/commands/attribution.js +0 -111
  47. package/dist/commands/audiences.d.ts +0 -23
  48. package/dist/commands/audiences.js +0 -243
  49. package/dist/commands/audit.d.ts +0 -20
  50. package/dist/commands/audit.js +0 -130
  51. package/dist/commands/auth.js +0 -249
  52. package/dist/commands/chat.d.ts +0 -19
  53. package/dist/commands/chat.js +0 -118
  54. package/dist/commands/config.d.ts +0 -10
  55. package/dist/commands/config.js +0 -92
  56. package/dist/commands/consent.d.ts +0 -27
  57. package/dist/commands/consent.js +0 -233
  58. package/dist/commands/conversion-paths.d.ts +0 -19
  59. package/dist/commands/conversion-paths.js +0 -55
  60. package/dist/commands/db.d.ts +0 -25
  61. package/dist/commands/db.js +0 -330
  62. package/dist/commands/destinations.d.ts +0 -20
  63. package/dist/commands/destinations.js +0 -191
  64. package/dist/commands/doctor.js +0 -360
  65. package/dist/commands/errors.d.ts +0 -27
  66. package/dist/commands/errors.js +0 -121
  67. package/dist/commands/events.d.ts +0 -33
  68. package/dist/commands/events.js +0 -371
  69. package/dist/commands/experiments.d.ts +0 -22
  70. package/dist/commands/experiments.js +0 -264
  71. package/dist/commands/funnels.d.ts +0 -17
  72. package/dist/commands/funnels.js +0 -203
  73. package/dist/commands/goals.d.ts +0 -18
  74. package/dist/commands/goals.js +0 -214
  75. package/dist/commands/heatmap.d.ts +0 -27
  76. package/dist/commands/heatmap.js +0 -112
  77. package/dist/commands/identity.d.ts +0 -29
  78. package/dist/commands/identity.js +0 -328
  79. package/dist/commands/init.js +0 -215
  80. package/dist/commands/insights.d.ts +0 -10
  81. package/dist/commands/insights.js +0 -77
  82. package/dist/commands/install.d.ts +0 -259
  83. package/dist/commands/install.js +0 -1590
  84. package/dist/commands/login.d.ts +0 -20
  85. package/dist/commands/login.js +0 -170
  86. package/dist/commands/logout.d.ts +0 -10
  87. package/dist/commands/logout.js +0 -41
  88. package/dist/commands/playground.d.ts +0 -11
  89. package/dist/commands/playground.js +0 -47
  90. package/dist/commands/releases.d.ts +0 -17
  91. package/dist/commands/releases.js +0 -54
  92. package/dist/commands/replay.d.ts +0 -18
  93. package/dist/commands/replay.js +0 -64
  94. package/dist/commands/secrets.d.ts +0 -19
  95. package/dist/commands/secrets.js +0 -145
  96. package/dist/commands/setup.d.ts +0 -21
  97. package/dist/commands/setup.js +0 -67
  98. package/dist/commands/sites.d.ts +0 -18
  99. package/dist/commands/sites.js +0 -139
  100. package/dist/commands/skad.d.ts +0 -18
  101. package/dist/commands/skad.js +0 -53
  102. package/dist/commands/sourcemap.d.ts +0 -33
  103. package/dist/commands/sourcemap.js +0 -204
  104. package/dist/commands/status.d.ts +0 -7
  105. package/dist/commands/status.js +0 -136
  106. package/dist/commands/upgrade.d.ts +0 -21
  107. package/dist/commands/upgrade.js +0 -183
  108. package/dist/commands/warehouse.d.ts +0 -20
  109. package/dist/commands/warehouse.js +0 -65
  110. package/dist/commands/warehouses.d.ts +0 -17
  111. package/dist/commands/warehouses.js +0 -182
  112. package/dist/commands/watch.d.ts +0 -45
  113. package/dist/commands/watch.js +0 -258
  114. package/dist/commands/whoami.d.ts +0 -9
  115. package/dist/commands/whoami.js +0 -50
  116. package/dist/config.d.ts +0 -75
  117. package/dist/config.js +0 -329
  118. package/dist/frameworks/detect.d.ts +0 -8
  119. package/dist/frameworks/detect.js +0 -458
  120. package/dist/install-intent-proposal.d.ts +0 -99
  121. package/dist/install-intent-proposal.js +0 -202
  122. package/dist/utils/api.d.ts +0 -20
  123. package/dist/utils/api.js +0 -47
  124. package/dist/utils/config.d.ts +0 -13
  125. package/dist/utils/config.js +0 -30
  126. package/dist/utils/confirm.d.ts +0 -17
  127. package/dist/utils/confirm.js +0 -40
  128. package/dist/utils/dry-run.d.ts +0 -20
  129. package/dist/utils/dry-run.js +0 -67
  130. package/dist/utils/from-file.d.ts +0 -9
  131. package/dist/utils/from-file.js +0 -72
  132. package/dist/utils/redact.d.ts +0 -14
  133. package/dist/utils/redact.js +0 -48
  134. package/dist/utils/ui.d.ts +0 -14
  135. package/dist/utils/ui.js +0 -59
  136. package/scripts/.gitkeep +0 -0
  137. package/scripts/README-gurulu-agentic-install.md +0 -114
  138. package/scripts/README-gurulu-scan.md +0 -98
  139. package/scripts/audit-cli-scopes.mjs +0 -204
  140. package/scripts/backfill-tenant-id.mjs +0 -172
  141. package/scripts/backfill-tenant-links.ts +0 -252
  142. package/scripts/backup-clickhouse.sh +0 -27
  143. package/scripts/backup-postgres.sh +0 -19
  144. package/scripts/bootstrap-runtime-schema.mjs +0 -87
  145. package/scripts/bootstrap-stripe.mjs +0 -158
  146. package/scripts/gurulu-agentic-install.lib.cjs +0 -762
  147. package/scripts/gurulu-agentic-install.mjs +0 -623
  148. package/scripts/gurulu-scan.lib.cjs +0 -1509
  149. package/scripts/gurulu-scan.mjs +0 -91
  150. package/scripts/gurulu-verify-install.lib.cjs +0 -334
  151. package/scripts/gurulu-verify-install.mjs +0 -59
  152. package/scripts/init-ssl.sh +0 -26
  153. package/scripts/migrate-flow-graph-enums.sh +0 -86
  154. package/scripts/monitor-disk.sh +0 -24
  155. package/scripts/patches/astro.patch.cjs +0 -74
  156. package/scripts/patches/auto-instrument/ast-helper.cjs +0 -480
  157. package/scripts/patches/auto-instrument/astro.cjs +0 -273
  158. package/scripts/patches/auto-instrument/express.cjs +0 -383
  159. package/scripts/patches/auto-instrument/fastify.cjs +0 -262
  160. package/scripts/patches/auto-instrument/hono.cjs +0 -392
  161. package/scripts/patches/auto-instrument/index.cjs +0 -80
  162. package/scripts/patches/auto-instrument/nestjs.cjs +0 -286
  163. package/scripts/patches/auto-instrument/nextjs-app-router.cjs +0 -345
  164. package/scripts/patches/auto-instrument/nextjs-pages.cjs +0 -361
  165. package/scripts/patches/auto-instrument/remix.cjs +0 -168
  166. package/scripts/patches/auto-instrument/sdk-helper-map.cjs +0 -241
  167. package/scripts/patches/auto-instrument/singleton-helper.cjs +0 -193
  168. package/scripts/patches/auto-instrument/sveltekit.cjs +0 -161
  169. package/scripts/patches/auto-instrument/vite-react.cjs +0 -37
  170. package/scripts/patches/auto-instrument/vue.cjs +0 -196
  171. package/scripts/patches/express.patch.cjs +0 -99
  172. package/scripts/patches/fastify.patch.cjs +0 -108
  173. package/scripts/patches/index.cjs +0 -300
  174. package/scripts/patches/nestjs.patch.cjs +0 -112
  175. package/scripts/patches/nextjs-app-router.patch.cjs +0 -97
  176. package/scripts/patches/nextjs-pages.patch.cjs +0 -97
  177. package/scripts/patches/remix.patch.cjs +0 -75
  178. package/scripts/patches/sveltekit.patch.cjs +0 -72
  179. package/scripts/patches/vite-react.patch.cjs +0 -73
  180. package/scripts/patches/vue.patch.cjs +0 -82
  181. package/scripts/renew-ssl.sh +0 -14
  182. package/scripts/resolve-migration.sh +0 -23
  183. package/scripts/seed-cli-dev-keys.mjs +0 -130
  184. package/scripts/seed-test-data.mjs +0 -391
  185. package/scripts/spike-browserless.ts +0 -65
  186. package/scripts/tenant-pivot-consistency-check.mjs +0 -205
  187. package/scripts/tenant-pivot-phase-3-cleanup.lib.cjs +0 -258
  188. package/scripts/tenant-pivot-phase-3-cleanup.mjs +0 -98
  189. package/scripts/test-identity-resolution.ts +0 -804
  190. package/scripts/validate-gurulu-schemas.mjs +0 -79
@@ -1,33 +0,0 @@
1
- /**
2
- * Phase 18.5 W2 — Thin fetch wrapper used by all authenticated CLI
3
- * commands. Handles auth header injection, user-agent, and the common
4
- * 401/402/429/5xx error presentations.
5
- */
6
- import { type ActiveProfile } from './config';
7
- export declare function userAgent(): string;
8
- export interface CliApiOptions extends RequestInit {
9
- profile?: string;
10
- skipAuth?: boolean;
11
- /** Used internally by tests — inject a pre-resolved profile. */
12
- preloadedProfile?: ActiveProfile;
13
- /** Disable process.exit for tests. */
14
- noExitOnError?: boolean;
15
- /**
16
- * Surface raw error bodies on 5xx instead of the generic "temporarily
17
- * unavailable" message. Caller should pass true when --json / --show-sql
18
- * / any verbose flag is set. GURULU_DEBUG=1 also forces verbose globally.
19
- */
20
- verbose?: boolean;
21
- }
22
- export declare class CliApiError extends Error {
23
- status: number;
24
- code: string;
25
- details: unknown;
26
- constructor(status: number, code: string, message: string, details?: unknown);
27
- }
28
- export declare function cliApi(path: string, init?: CliApiOptions): Promise<Response>;
29
- /** Helper: POST JSON and return parsed body, with rich error reporting. */
30
- export declare function cliApiJson<T = unknown>(path: string, init?: CliApiOptions & {
31
- method?: string;
32
- json?: unknown;
33
- }): Promise<T>;
@@ -1,175 +0,0 @@
1
- "use strict";
2
- /**
3
- * Phase 18.5 W2 — Thin fetch wrapper used by all authenticated CLI
4
- * commands. Handles auth header injection, user-agent, and the common
5
- * 401/402/429/5xx error presentations.
6
- */
7
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
- if (k2 === undefined) k2 = k;
9
- var desc = Object.getOwnPropertyDescriptor(m, k);
10
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
- desc = { enumerable: true, get: function() { return m[k]; } };
12
- }
13
- Object.defineProperty(o, k2, desc);
14
- }) : (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- o[k2] = m[k];
17
- }));
18
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
- Object.defineProperty(o, "default", { enumerable: true, value: v });
20
- }) : function(o, v) {
21
- o["default"] = v;
22
- });
23
- var __importStar = (this && this.__importStar) || (function () {
24
- var ownKeys = function(o) {
25
- ownKeys = Object.getOwnPropertyNames || function (o) {
26
- var ar = [];
27
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
- return ar;
29
- };
30
- return ownKeys(o);
31
- };
32
- return function (mod) {
33
- if (mod && mod.__esModule) return mod;
34
- var result = {};
35
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
- __setModuleDefault(result, mod);
37
- return result;
38
- };
39
- })();
40
- Object.defineProperty(exports, "__esModule", { value: true });
41
- exports.CliApiError = void 0;
42
- exports.userAgent = userAgent;
43
- exports.cliApi = cliApi;
44
- exports.cliApiJson = cliApiJson;
45
- const os = __importStar(require("os"));
46
- const config_1 = require("./config");
47
- let cachedVersion = null;
48
- function cliVersion() {
49
- if (cachedVersion)
50
- return cachedVersion;
51
- try {
52
- // eslint-disable-next-line @typescript-eslint/no-var-requires
53
- const pkg = require('../package.json');
54
- cachedVersion = pkg.version || '0.0.0';
55
- }
56
- catch {
57
- cachedVersion = '0.0.0';
58
- }
59
- return cachedVersion;
60
- }
61
- function userAgent() {
62
- return `gurulu-cli/${cliVersion()} (node/${process.versions.node}; ${os.platform()})`;
63
- }
64
- class CliApiError extends Error {
65
- status;
66
- code;
67
- details;
68
- constructor(status, code, message, details) {
69
- super(message);
70
- this.status = status;
71
- this.code = code;
72
- this.details = details;
73
- }
74
- }
75
- exports.CliApiError = CliApiError;
76
- function fatal(msg, opts) {
77
- process.stderr.write(`${msg}\n`);
78
- if (!opts.noExitOnError)
79
- process.exit(1);
80
- throw new CliApiError(0, 'fatal', msg);
81
- }
82
- async function cliApi(path, init = {}) {
83
- let profile = init.preloadedProfile || null;
84
- if (!profile && !init.skipAuth) {
85
- try {
86
- profile = await (0, config_1.loadActiveProfile)({ profile: init.profile });
87
- }
88
- catch (err) {
89
- fatal(`Not logged in. Run \`gurulu login\` first. (${err.message})`, init);
90
- }
91
- }
92
- const base = profile?.api_base || process.env.GURULU_API_BASE || 'https://gurulu.io';
93
- const url = path.startsWith('http') ? path : `${base}${path}`;
94
- const headers = new Headers(init.headers || {});
95
- if (!headers.has('user-agent'))
96
- headers.set('user-agent', userAgent());
97
- if (!init.skipAuth && profile) {
98
- headers.set('authorization', `Bearer ${profile.secret_key}`);
99
- }
100
- if (init.body && !headers.has('content-type') && !(init.body instanceof FormData)) {
101
- headers.set('content-type', 'application/json');
102
- }
103
- let res;
104
- try {
105
- res = await globalThis.fetch(url, { ...init, headers });
106
- }
107
- catch (err) {
108
- fatal(`Gurulu is temporarily unavailable (network error): ${err.message}`, init);
109
- }
110
- if (res.status === 401) {
111
- fatal('Your session is invalid. Run `gurulu login` again.', init);
112
- }
113
- if (res.status === 402) {
114
- let msg = 'Quota exceeded. Upgrade at https://gurulu.io/settings/billing';
115
- try {
116
- const body = await res.clone().json();
117
- if (body?.message)
118
- msg = `Quota exceeded: ${body.message}`;
119
- if (body?.upgradeUrl)
120
- msg += `\n → ${body.upgradeUrl}`;
121
- }
122
- catch {
123
- /* ignore */
124
- }
125
- fatal(msg, init);
126
- }
127
- if (res.status === 429) {
128
- const retry = res.headers.get('retry-after') || '';
129
- fatal(`Rate limited by Gurulu${retry ? ` — try again in ${retry}s` : ''}. Try again shortly.`, init);
130
- }
131
- if (res.status >= 500) {
132
- const verbose = init.verbose === true || process.env.GURULU_DEBUG === '1';
133
- if (verbose) {
134
- let detail = '';
135
- try {
136
- const body = await res.clone().json();
137
- const msg = body?.error || body?.message;
138
- if (msg) {
139
- detail = ` ${typeof msg === 'string' ? msg : JSON.stringify(msg)}`;
140
- }
141
- else {
142
- detail = ` ${JSON.stringify(body)}`;
143
- }
144
- }
145
- catch {
146
- try {
147
- const txt = await res.clone().text();
148
- if (txt)
149
- detail = ` ${txt.slice(0, 500)}`;
150
- }
151
- catch {
152
- /* ignore */
153
- }
154
- }
155
- fatal(`Gurulu is temporarily unavailable (HTTP ${res.status}).${detail}`, init);
156
- }
157
- fatal(`Gurulu is temporarily unavailable (HTTP ${res.status}).`, init);
158
- }
159
- return res;
160
- }
161
- /** Helper: POST JSON and return parsed body, with rich error reporting. */
162
- async function cliApiJson(path, init = {}) {
163
- const { json, ...rest } = init;
164
- const res = await cliApi(path, {
165
- ...rest,
166
- method: init.method || (json ? 'POST' : 'GET'),
167
- body: json !== undefined ? JSON.stringify(json) : rest.body,
168
- });
169
- const text = await res.text();
170
- const parsed = text ? JSON.parse(text) : {};
171
- if (!res.ok) {
172
- throw new CliApiError(res.status, parsed?.error || 'http_error', parsed?.message || `HTTP ${res.status}`, parsed);
173
- }
174
- return parsed;
175
- }
@@ -1,9 +0,0 @@
1
- interface AddServerArgs {
2
- site?: string;
3
- noInteractive?: boolean;
4
- dryRun?: boolean;
5
- json?: boolean;
6
- profile?: string;
7
- }
8
- export declare function addServerCommand(args: AddServerArgs): Promise<void>;
9
- export {};
@@ -1,162 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.addServerCommand = addServerCommand;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- const child_process_1 = require("child_process");
10
- const config_1 = require("../config");
11
- const api_client_1 = require("../api-client");
12
- const ui_1 = require("../utils/ui");
13
- async function addServerCommand(args) {
14
- let profile;
15
- try {
16
- profile = await (0, config_1.loadActiveProfile)({ profile: args.profile });
17
- }
18
- catch {
19
- profile = null;
20
- }
21
- const siteId = args.site;
22
- const projectDir = process.cwd();
23
- if (args.json) {
24
- return addServerJSON(siteId, profile, projectDir, args);
25
- }
26
- (0, ui_1.banner)();
27
- console.log((0, ui_1.bold)(' Add Server SDK'));
28
- console.log('');
29
- // Check for package.json
30
- const pkgPath = path_1.default.join(projectDir, 'package.json');
31
- if (!fs_1.default.existsSync(pkgPath)) {
32
- (0, ui_1.error)('No package.json found in current directory.');
33
- process.exit(1);
34
- }
35
- // Check if already installed
36
- const pkg = JSON.parse(fs_1.default.readFileSync(pkgPath, 'utf-8'));
37
- const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
38
- if (allDeps['@gurulu/node']) {
39
- (0, ui_1.info)('@gurulu/node is already installed.');
40
- }
41
- if (!siteId) {
42
- (0, ui_1.error)('No site selected. Run "gurulu login" first or use --site <id>.');
43
- process.exit(1);
44
- }
45
- // Get server API key
46
- let serverApiKey = process.env.GURULU_SERVER_API_KEY;
47
- if (!serverApiKey && profile) {
48
- try {
49
- (0, ui_1.step)('Creating server API key...');
50
- const data = await (0, api_client_1.cliApiJson)(`/api/cli/sites/${encodeURIComponent(siteId)}/server-keys`, {
51
- preloadedProfile: profile,
52
- json: { name: `cli-${new Date().toISOString().slice(0, 10)}` },
53
- });
54
- serverApiKey = data.key || '';
55
- if (serverApiKey) {
56
- (0, ui_1.success)(`Server API key created (${data.keyId})`);
57
- }
58
- }
59
- catch (err) {
60
- (0, ui_1.warn)(`Could not create server API key: ${err.message}`);
61
- }
62
- }
63
- if (!serverApiKey && !args.noInteractive) {
64
- serverApiKey = await (0, ui_1.prompt)(' Server API Key: ');
65
- }
66
- if (!serverApiKey) {
67
- (0, ui_1.error)('Server API key required. Set GURULU_SERVER_API_KEY or run "gurulu login" first.');
68
- process.exit(1);
69
- }
70
- if (args.dryRun) {
71
- (0, ui_1.info)('Dry run - would perform the following:');
72
- (0, ui_1.step)('Install @gurulu/node package');
73
- (0, ui_1.step)('Create server SDK config file');
74
- (0, ui_1.step)('Add GURULU_SERVER_API_KEY to .env');
75
- return;
76
- }
77
- // Step 1: Install package
78
- (0, ui_1.step)('Installing @gurulu/node...');
79
- try {
80
- // Detect package manager
81
- let pm = 'npm install';
82
- if (fs_1.default.existsSync(path_1.default.join(projectDir, 'pnpm-lock.yaml'))) {
83
- pm = 'pnpm add';
84
- }
85
- else if (fs_1.default.existsSync(path_1.default.join(projectDir, 'yarn.lock'))) {
86
- pm = 'yarn add';
87
- }
88
- else if (fs_1.default.existsSync(path_1.default.join(projectDir, 'bun.lockb'))) {
89
- pm = 'bun add';
90
- }
91
- (0, child_process_1.execSync)(`${pm} @gurulu/node`, { cwd: projectDir, stdio: 'pipe' });
92
- (0, ui_1.success)('Installed @gurulu/node');
93
- }
94
- catch (err) {
95
- (0, ui_1.warn)(`Could not auto-install. Run manually: npm install @gurulu/node`);
96
- }
97
- // Step 2: Create server config file
98
- const configFilePath = path_1.default.join(projectDir, 'src', 'lib', 'gurulu-server.ts');
99
- const configCode = `import { Gurulu } from '@gurulu/node';
100
-
101
- export const gurulu = new Gurulu({
102
- siteId: process.env.GURULU_SITE_ID || '${siteId}',
103
- apiKey: process.env.GURULU_SERVER_API_KEY || '',
104
- });
105
- `;
106
- if (!fs_1.default.existsSync(configFilePath)) {
107
- const configDir = path_1.default.dirname(configFilePath);
108
- fs_1.default.mkdirSync(configDir, { recursive: true });
109
- fs_1.default.writeFileSync(configFilePath, configCode);
110
- (0, ui_1.success)('Created src/lib/gurulu-server.ts');
111
- }
112
- else {
113
- (0, ui_1.info)('src/lib/gurulu-server.ts already exists, skipping.');
114
- }
115
- // Step 3: Update .env
116
- const envFile = path_1.default.join(projectDir, '.env');
117
- const envLines = [
118
- `GURULU_SITE_ID=${siteId}`,
119
- `GURULU_SERVER_API_KEY=${serverApiKey}`,
120
- ];
121
- let existingEnv = '';
122
- if (fs_1.default.existsSync(envFile)) {
123
- existingEnv = fs_1.default.readFileSync(envFile, 'utf-8');
124
- }
125
- const newLines = envLines.filter(line => {
126
- const key = line.split('=')[0];
127
- return !existingEnv.includes(key);
128
- });
129
- if (newLines.length > 0) {
130
- const separator = existingEnv && !existingEnv.endsWith('\n') ? '\n' : '';
131
- const header = existingEnv.includes('GURULU') ? '' : '# Gurulu.io Server SDK\n';
132
- fs_1.default.appendFileSync(envFile, `${separator}${header}${newLines.join('\n')}\n`);
133
- (0, ui_1.success)('Updated .env with server credentials');
134
- }
135
- else {
136
- (0, ui_1.info)('.env already has Gurulu server credentials');
137
- }
138
- // Done
139
- console.log('');
140
- console.log((0, ui_1.bold)(' Next steps:'));
141
- console.log('');
142
- (0, ui_1.step)('Import gurulu from src/lib/gurulu-server.ts in your API routes');
143
- (0, ui_1.step)(`Use ${(0, ui_1.cyan)('gurulu.track(event, properties)')} to send server-side events`);
144
- (0, ui_1.step)(`Use ${(0, ui_1.cyan)("await gurulu.identify({ userId: '...', anonymousId: '...', traits: {} })")} to identify users`);
145
- (0, ui_1.step)(`Run ${(0, ui_1.cyan)('gurulu doctor')} to verify the setup`);
146
- console.log('');
147
- (0, ui_1.success)('Server SDK setup complete!');
148
- console.log('');
149
- }
150
- async function addServerJSON(siteId, profile, projectDir, args) {
151
- const result = {
152
- siteId: siteId || null,
153
- authenticated: !!profile,
154
- dryRun: !!args.dryRun,
155
- steps: [
156
- { action: 'install', package: '@gurulu/node' },
157
- { action: 'create', file: 'src/lib/gurulu-server.ts' },
158
- { action: 'update', file: '.env', keys: ['GURULU_SITE_ID', 'GURULU_SERVER_API_KEY'] },
159
- ],
160
- };
161
- console.log(JSON.stringify(result, null, 2));
162
- }
@@ -1,27 +0,0 @@
1
- /**
2
- * Phase 19.5 W2 B4 — `gurulu alerts list|show|channels list`.
3
- * Phase 20 W2 B3 — `create|update|delete` + channels create/update/delete.
4
- */
5
- export interface AlertsArgs {
6
- action?: string;
7
- sub?: string;
8
- target?: string;
9
- severity?: string;
10
- acknowledged?: string;
11
- limit?: number;
12
- json?: boolean;
13
- profile?: string;
14
- fromFile?: string;
15
- site?: string;
16
- id?: string;
17
- name?: string;
18
- type?: string;
19
- metric?: string;
20
- thresholdType?: string;
21
- thresholdValue?: number;
22
- channel?: string;
23
- note?: string;
24
- yes?: boolean;
25
- dryRun?: boolean;
26
- }
27
- export declare function alertsCommand(args: AlertsArgs): Promise<void>;