@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,458 +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.detectFramework = detectFramework;
7
- exports.getSetupSnippet = getSetupSnippet;
8
- exports.getFrameworkDisplayName = getFrameworkDisplayName;
9
- const fs_1 = __importDefault(require("fs"));
10
- const path_1 = __importDefault(require("path"));
11
- function detectFramework(projectDir) {
12
- const pkgPath = path_1.default.join(projectDir, 'package.json');
13
- const hasPkgJson = fs_1.default.existsSync(pkgPath);
14
- // Read package.json early so we can dedupe iOS-vs-React-Native (RN repos
15
- // commonly host an `ios/MyApp.xcodeproj` and a top-level Package.swift in
16
- // monorepos — without the RN check first we'd return `ios-swift` and ship
17
- // the wrong SDK snippet).
18
- let deps = {};
19
- if (hasPkgJson) {
20
- try {
21
- const pkg = JSON.parse(fs_1.default.readFileSync(pkgPath, 'utf-8'));
22
- deps = { ...pkg.dependencies, ...pkg.devDependencies };
23
- }
24
- catch {
25
- /* malformed package.json — fall through to filesystem detection */
26
- }
27
- if (deps['react-native'])
28
- return 'react-native';
29
- }
30
- // Mobile framework detection (non-package.json based)
31
- if (fs_1.default.existsSync(path_1.default.join(projectDir, 'pubspec.yaml')))
32
- return 'flutter';
33
- const hasSwiftPkg = fs_1.default.existsSync(path_1.default.join(projectDir, 'Package.swift'));
34
- let hasXcodeProj = false;
35
- try {
36
- hasXcodeProj = fs_1.default
37
- .readdirSync(projectDir)
38
- .some((f) => f.endsWith('.xcodeproj') || f.endsWith('.xcworkspace'));
39
- }
40
- catch {
41
- /* unreadable dir — treat as no Xcode project */
42
- }
43
- if (hasSwiftPkg || hasXcodeProj)
44
- return 'ios-swift';
45
- if (!hasPkgJson) {
46
- // Android detection (no package.json means no RN false positive)
47
- if (fs_1.default.existsSync(path_1.default.join(projectDir, 'build.gradle.kts')) ||
48
- fs_1.default.existsSync(path_1.default.join(projectDir, 'build.gradle')) ||
49
- fs_1.default.existsSync(path_1.default.join(projectDir, 'app', 'build.gradle')) ||
50
- fs_1.default.existsSync(path_1.default.join(projectDir, 'app', 'build.gradle.kts'))) {
51
- return 'android-kotlin';
52
- }
53
- return 'html';
54
- }
55
- if (deps['next']) {
56
- // Check for app router
57
- if (fs_1.default.existsSync(path_1.default.join(projectDir, 'src', 'app')) || fs_1.default.existsSync(path_1.default.join(projectDir, 'app'))) {
58
- return 'nextjs-app';
59
- }
60
- return 'nextjs-pages';
61
- }
62
- if (deps['@nestjs/core'])
63
- return 'nestjs';
64
- if (deps['nuxt'])
65
- return 'nuxt3';
66
- if (deps['@sveltejs/kit'])
67
- return 'sveltekit';
68
- if (deps['svelte'])
69
- return 'svelte';
70
- if (deps['astro'])
71
- return 'astro';
72
- if (deps['vue'])
73
- return 'vue3';
74
- if (deps['@vitejs/plugin-react'])
75
- return 'react-vite';
76
- if (deps['react-scripts'])
77
- return 'react-cra';
78
- if (deps['fastify'])
79
- return 'fastify';
80
- if (deps['hono'])
81
- return 'hono';
82
- if (deps['express'])
83
- return 'express';
84
- return 'unknown';
85
- }
86
- function getSetupSnippet(framework, siteId, token) {
87
- switch (framework) {
88
- case 'nextjs-app':
89
- return {
90
- file: 'src/lib/gurulu.tsx',
91
- code: `'use client';
92
- import { useEffect } from 'react';
93
- import { usePathname, useSearchParams } from 'next/navigation';
94
-
95
- export function GuruluProvider() {
96
- const pathname = usePathname();
97
- const searchParams = useSearchParams();
98
-
99
- useEffect(() => {
100
- const script = document.createElement('script');
101
- script.src = 'https://cdn.gurulu.io/t.js';
102
- script.async = true;
103
- script.dataset.siteId = '${siteId}';
104
- script.dataset.token = '${token}';
105
- document.head.appendChild(script);
106
- return () => { document.head.removeChild(script); };
107
- }, []);
108
-
109
- useEffect(() => {
110
- if (typeof window !== 'undefined' && (window as any).gurulu) {
111
- (window as any).gurulu.track('pageview', {
112
- page_url: pathname + (searchParams?.toString() ? '?' + searchParams.toString() : ''),
113
- });
114
- }
115
- }, [pathname, searchParams]);
116
-
117
- return null;
118
- }`,
119
- instruction: 'Add <GuruluProvider /> inside <body> in your root layout.tsx',
120
- };
121
- case 'nextjs-pages':
122
- return {
123
- file: 'src/lib/gurulu.tsx',
124
- code: `import Script from 'next/script';
125
-
126
- export function GuruluScript() {
127
- return (
128
- <Script
129
- src="https://cdn.gurulu.io/t.js"
130
- data-site-id="${siteId}"
131
- data-token="${token}"
132
- strategy="afterInteractive"
133
- />
134
- );
135
- }`,
136
- instruction: 'Add <GuruluScript /> in your _app.tsx',
137
- };
138
- case 'react-vite':
139
- case 'react-cra':
140
- return {
141
- file: 'src/gurulu.ts',
142
- code: `// Gurulu.io Analytics
143
- export function initGurulu() {
144
- if (typeof document === 'undefined') return;
145
- const script = document.createElement('script');
146
- script.src = 'https://cdn.gurulu.io/t.js';
147
- script.async = true;
148
- script.dataset.siteId = '${siteId}';
149
- script.dataset.token = '${token}';
150
- document.head.appendChild(script);
151
- }`,
152
- instruction: 'Call initGurulu() in your main.tsx or index.tsx entry point',
153
- };
154
- case 'vue3':
155
- return {
156
- file: 'src/plugins/gurulu.ts',
157
- code: `// Gurulu.io Analytics Plugin
158
- import type { App } from 'vue';
159
-
160
- export const guruluPlugin = {
161
- install(app: App) {
162
- if (typeof document === 'undefined') return;
163
- const script = document.createElement('script');
164
- script.src = 'https://cdn.gurulu.io/t.js';
165
- script.async = true;
166
- script.dataset.siteId = '${siteId}';
167
- script.dataset.token = '${token}';
168
- document.head.appendChild(script);
169
- },
170
- };`,
171
- instruction: 'Add app.use(guruluPlugin) in your main.ts',
172
- };
173
- case 'nuxt3':
174
- return {
175
- file: 'plugins/gurulu.client.ts',
176
- code: `// Gurulu.io Analytics Plugin
177
- export default defineNuxtPlugin(() => {
178
- if (typeof document === 'undefined') return;
179
- const script = document.createElement('script');
180
- script.src = 'https://cdn.gurulu.io/t.js';
181
- script.async = true;
182
- script.dataset.siteId = '${siteId}';
183
- script.dataset.token = '${token}';
184
- document.head.appendChild(script);
185
- });`,
186
- instruction: 'Plugin auto-registered via plugins/ directory',
187
- };
188
- case 'svelte':
189
- return {
190
- file: 'src/lib/gurulu.ts',
191
- code: `// Gurulu.io Analytics
192
- import { onMount } from 'svelte';
193
-
194
- export function initGurulu() {
195
- onMount(() => {
196
- const script = document.createElement('script');
197
- script.src = 'https://cdn.gurulu.io/t.js';
198
- script.async = true;
199
- script.dataset.siteId = '${siteId}';
200
- script.dataset.token = '${token}';
201
- document.head.appendChild(script);
202
- });
203
- }`,
204
- instruction: 'Call initGurulu() in your root +layout.svelte or App.svelte',
205
- };
206
- case 'sveltekit':
207
- return {
208
- file: 'src/lib/gurulu.ts',
209
- code: `// Gurulu.io Analytics
210
- import { browser } from '$app/environment';
211
-
212
- export function initGurulu() {
213
- if (!browser) return;
214
- const script = document.createElement('script');
215
- script.src = 'https://cdn.gurulu.io/t.js';
216
- script.async = true;
217
- script.dataset.siteId = '${siteId}';
218
- script.dataset.token = '${token}';
219
- document.head.appendChild(script);
220
- }`,
221
- instruction: 'Call initGurulu() in your root +layout.svelte onMount',
222
- };
223
- case 'astro':
224
- return {
225
- file: 'src/components/Gurulu.astro',
226
- code: `---
227
- // Gurulu.io Analytics
228
- ---
229
- <script src="https://cdn.gurulu.io/t.js" data-site-id="${siteId}" data-token="${token}" async></script>`,
230
- instruction: 'Add <Gurulu /> in your Layout.astro <head>',
231
- };
232
- case 'express':
233
- return {
234
- file: 'src/gurulu.ts',
235
- code: `// Gurulu.io Server Analytics — Phase 32 P32-A2 fix
236
- // Use the @gurulu/node SDK so retry, identity propagation, and the
237
- // correct ingest endpoint (/api/ingest/v1/server) are handled for you.
238
- // npm install @gurulu/node
239
- import { Gurulu } from '@gurulu/node';
240
- import type { Request, Response, NextFunction } from 'express';
241
-
242
- export const gurulu = new Gurulu({
243
- siteId: '${siteId}',
244
- token: '${token}',
245
- endpoint: 'https://gurulu.io',
246
- });
247
-
248
- export function guruluMiddleware(req: Request, res: Response, next: NextFunction) {
249
- // Identity propagation: read the anonymous_id the browser SDK set in a
250
- // cookie / header so server-side events stitch onto the same user.
251
- const anonymousId = (req.headers['x-gurulu-anonymous-id'] as string)
252
- || (req.cookies?._gurulu_id as string)
253
- || undefined;
254
- gurulu.track({
255
- eventName: 'pageview',
256
- anonymousId,
257
- properties: {
258
- url: req.originalUrl,
259
- referrer: req.headers.referer || '',
260
- user_agent: req.headers['user-agent'] || '',
261
- },
262
- }).catch(() => {});
263
- next();
264
- }`,
265
- instruction: 'Add app.use(guruluMiddleware) in your Express app',
266
- };
267
- case 'fastify':
268
- return {
269
- file: 'src/gurulu.ts',
270
- code: `// Gurulu.io Server Analytics — Fastify plugin (Phase 32 P32-A2 fix)
271
- // npm install @gurulu/node
272
- import { Gurulu } from '@gurulu/node';
273
- import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
274
-
275
- export const gurulu = new Gurulu({
276
- siteId: '${siteId}',
277
- token: '${token}',
278
- endpoint: 'https://gurulu.io',
279
- });
280
-
281
- export async function guruluPlugin(fastify: FastifyInstance) {
282
- fastify.addHook('onRequest', async (req: FastifyRequest, _reply: FastifyReply) => {
283
- const anonymousId = (req.headers['x-gurulu-anonymous-id'] as string) || undefined;
284
- gurulu.track({
285
- eventName: 'pageview',
286
- anonymousId,
287
- properties: {
288
- url: req.url,
289
- referrer: (req.headers.referer as string) || '',
290
- user_agent: (req.headers['user-agent'] as string) || '',
291
- },
292
- }).catch(() => {});
293
- });
294
- }`,
295
- instruction: 'Register with fastify.register(guruluPlugin) in your Fastify app',
296
- };
297
- case 'hono':
298
- return {
299
- file: 'src/gurulu.ts',
300
- code: `// Gurulu.io Server Analytics — Hono middleware (Phase 32 P32-A2 fix)
301
- // npm install @gurulu/node
302
- import { Gurulu } from '@gurulu/node';
303
- import type { MiddlewareHandler } from 'hono';
304
-
305
- export const gurulu = new Gurulu({
306
- siteId: '${siteId}',
307
- token: '${token}',
308
- endpoint: 'https://gurulu.io',
309
- });
310
-
311
- export const guruluMiddleware: MiddlewareHandler = async (c, next) => {
312
- const anonymousId = c.req.header('x-gurulu-anonymous-id') || undefined;
313
- gurulu.track({
314
- eventName: 'pageview',
315
- anonymousId,
316
- properties: {
317
- url: c.req.url,
318
- referrer: c.req.header('referer') || '',
319
- user_agent: c.req.header('user-agent') || '',
320
- },
321
- }).catch(() => {});
322
- await next();
323
- };`,
324
- instruction: 'Add app.use(guruluMiddleware) in your Hono app',
325
- };
326
- case 'nestjs':
327
- return {
328
- file: 'src/gurulu.middleware.ts',
329
- code: `// Gurulu.io Server Analytics Middleware (Phase 32 P32-A2 fix)
330
- // npm install @gurulu/node
331
- import { Injectable, NestMiddleware } from '@nestjs/common';
332
- import { Request, Response, NextFunction } from 'express';
333
- import { Gurulu } from '@gurulu/node';
334
-
335
- const gurulu = new Gurulu({
336
- siteId: '${siteId}',
337
- token: '${token}',
338
- endpoint: 'https://gurulu.io',
339
- });
340
-
341
- @Injectable()
342
- export class GuruluMiddleware implements NestMiddleware {
343
- use(req: Request, res: Response, next: NextFunction) {
344
- const anonymousId = (req.headers['x-gurulu-anonymous-id'] as string) || undefined;
345
- gurulu.track({
346
- eventName: 'pageview',
347
- anonymousId,
348
- properties: {
349
- url: req.originalUrl,
350
- referrer: req.headers.referer || '',
351
- user_agent: req.headers['user-agent'] || '',
352
- },
353
- }).catch(() => {});
354
- next();
355
- }
356
- }`,
357
- instruction: 'Apply GuruluMiddleware in your AppModule configure()',
358
- };
359
- case 'react-native':
360
- return {
361
- file: '',
362
- code: `// npm install @gurulu/react-native
363
- import Gurulu from '@gurulu/react-native';
364
-
365
- Gurulu.initialize({
366
- siteId: '${siteId}',
367
- token: '${token}',
368
- endpoint: 'https://ingest.gurulu.io/api/ingest/v1/collect',
369
- });`,
370
- instruction: 'Run "npm install @gurulu/react-native" and add initialization to your App entry point',
371
- };
372
- case 'ios-swift':
373
- return {
374
- file: '',
375
- code: `// Package.swift: add .package(url: "https://github.com/Preatan/gurulu-ios-sdk", from: "0.1.0")
376
- // AppDelegate.swift or @main App:
377
- import GuruluSDK
378
-
379
- GuruluSDK.shared.initialize(config: GuruluConfig(
380
- siteId: "${siteId}",
381
- token: "${token}",
382
- endpoint: URL(string: "https://ingest.gurulu.io/api/ingest/v1/collect")!
383
- ))`,
384
- instruction: 'Add the SPM dependency and initialize in your AppDelegate or @main App struct',
385
- };
386
- case 'android-kotlin':
387
- return {
388
- file: '',
389
- code: `// build.gradle.kts: implementation("com.github.Preatan:gurulu.io:android-sdk-0.1.0")
390
- // repositories: maven { url = uri("https://jitpack.io") }
391
- // Application.onCreate():
392
- import io.gurulu.sdk.GuruluSdk
393
- import io.gurulu.sdk.GuruluConfig
394
-
395
- GuruluSdk.initialize(GuruluConfig(
396
- siteId = "${siteId}",
397
- token = "${token}",
398
- endpoint = "https://ingest.gurulu.io/api/ingest/v1/collect"
399
- ))`,
400
- instruction: 'Add JitPack repository and dependency, then initialize in your Application.onCreate()',
401
- };
402
- case 'flutter':
403
- return {
404
- file: '',
405
- code: `// pubspec.yaml: gurulu_flutter: ^0.1.0
406
- import 'package:gurulu_flutter/gurulu_flutter.dart';
407
-
408
- await GuruluFlutter.initialize(config: {
409
- 'siteId': '${siteId}',
410
- 'token': '${token}',
411
- 'endpoint': 'https://ingest.gurulu.io/api/ingest/v1/collect',
412
- });`,
413
- instruction: 'Add gurulu_flutter to pubspec.yaml and initialize in your main() function',
414
- };
415
- case 'html':
416
- return {
417
- file: '',
418
- code: `<script src="https://cdn.gurulu.io/t.js" data-site-id="${siteId}" data-token="${token}" async></script>`,
419
- instruction: 'Add this script tag before </head> in your HTML',
420
- };
421
- default:
422
- return {
423
- file: 'src/gurulu.ts',
424
- code: `// Gurulu.io Analytics
425
- const script = document.createElement('script');
426
- script.src = 'https://cdn.gurulu.io/t.js';
427
- script.async = true;
428
- script.dataset.siteId = '${siteId}';
429
- script.dataset.token = '${token}';
430
- document.head.appendChild(script);`,
431
- instruction: 'Import this file in your app entry point',
432
- };
433
- }
434
- }
435
- function getFrameworkDisplayName(fw) {
436
- const names = {
437
- 'nextjs-app': 'Next.js (App Router)',
438
- 'nextjs-pages': 'Next.js (Pages Router)',
439
- 'react-vite': 'React (Vite)',
440
- 'react-cra': 'React (CRA)',
441
- 'vue3': 'Vue 3',
442
- 'nuxt3': 'Nuxt 3',
443
- 'svelte': 'Svelte',
444
- 'sveltekit': 'SvelteKit',
445
- 'astro': 'Astro',
446
- 'express': 'Express',
447
- 'fastify': 'Fastify',
448
- 'hono': 'Hono',
449
- 'nestjs': 'NestJS',
450
- 'html': 'HTML',
451
- 'react-native': 'React Native',
452
- 'ios-swift': 'iOS (Swift)',
453
- 'android-kotlin': 'Android (Kotlin)',
454
- 'flutter': 'Flutter',
455
- 'unknown': 'Unknown',
456
- };
457
- return names[fw];
458
- }
@@ -1,99 +0,0 @@
1
- /**
2
- * Phase 18.6 — CLI install-time intent proposal rendering + interaction.
3
- *
4
- * Pure UI logic (plus a small interactive loop) that turns an `InstallIntent`
5
- * payload into a human-readable proposal and lets the user toggle individual
6
- * events/funnels before sending the accepted subset to the backend. This file
7
- * has NO hard limit on event/funnel count — a full iGaming intent with 20
8
- * events is rendered in full.
9
- *
10
- * Testability: the render function returns a plain string so snapshot-style
11
- * tests can assert structure. The interactive runner accepts injected I/O so
12
- * tests can drive it without real stdin/stdout.
13
- */
14
- export type Confidence = 'high' | 'medium' | 'low';
15
- export interface ProposedEvent {
16
- name: string;
17
- category: 'acquisition' | 'activation' | 'retention' | 'revenue' | 'referral' | 'compliance' | 'support' | 'engagement';
18
- source: {
19
- route?: string;
20
- mutation?: string;
21
- inferred?: boolean;
22
- inferredFrom?: string;
23
- };
24
- properties: string[];
25
- confidence: Confidence;
26
- reasoning: string;
27
- }
28
- export interface ProposedFunnel {
29
- name: string;
30
- category: 'activation' | 'monetization' | 'retention' | 'compliance' | 'engagement';
31
- steps: string[];
32
- reasoning: string;
33
- }
34
- export interface InstallIntent {
35
- vertical: string;
36
- confidence: Confidence;
37
- reasoning: string;
38
- alternativeVerticals: Array<{
39
- name: string;
40
- confidence: Confidence;
41
- note?: string;
42
- }>;
43
- events: ProposedEvent[];
44
- funnels: ProposedFunnel[];
45
- analyzerMode: 'llm' | 'heuristic';
46
- modelVersion?: string;
47
- promptVersion?: string;
48
- }
49
- export interface ProposalState {
50
- intent: InstallIntent;
51
- eventSelected: boolean[];
52
- funnelSelected: boolean[];
53
- }
54
- export declare function initProposalState(intent: InstallIntent): ProposalState;
55
- /**
56
- * Render the proposal to a plain string (TTY colour escapes applied by the
57
- * caller if `colorize` is true). No truncation — every event/funnel is shown.
58
- */
59
- export declare function renderProposal(state: ProposalState, opts?: {
60
- colorize?: boolean;
61
- }): string;
62
- export interface ApplyCommandResult {
63
- state: ProposalState;
64
- done: boolean;
65
- quit: boolean;
66
- }
67
- /**
68
- * Apply a single user command to the proposal state. Exported so tests can
69
- * exercise the state machine directly without any I/O.
70
- */
71
- export declare function applyCommand(state: ProposalState, raw: string): ApplyCommandResult;
72
- export interface ProposalIo {
73
- print: (line: string) => void;
74
- prompt: (q: string) => Promise<string>;
75
- isPiped: boolean;
76
- }
77
- export interface ProposalDecision {
78
- accepted: {
79
- events: ProposedEvent[];
80
- funnels: ProposedFunnel[];
81
- };
82
- rejected: {
83
- events: ProposedEvent[];
84
- funnels: ProposedFunnel[];
85
- };
86
- quit: boolean;
87
- }
88
- export declare function splitDecision(state: ProposalState): ProposalDecision;
89
- export interface RunProposalOpts {
90
- intent: InstallIntent;
91
- io: ProposalIo;
92
- /** If true (piped / --yes / CI), skip interactive loop and accept everything. */
93
- nonInteractive?: boolean;
94
- }
95
- /**
96
- * Drive the interactive proposal loop. Returns the accepted + rejected split
97
- * plus a `quit` flag the caller uses to decide whether to continue the install.
98
- */
99
- export declare function runProposal(opts: RunProposalOpts): Promise<ProposalDecision>;