@gurulu/cli 0.4.7 → 1.0.0
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/LICENSE +92 -0
- package/README.md +35 -106
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +25410 -0
- package/dist/commands/auth.d.ts +23 -20
- package/dist/commands/auth.d.ts.map +1 -0
- package/dist/commands/doctor.d.ts +20 -6
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/init.d.ts +25 -11
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/pull.d.ts +13 -0
- package/dist/commands/pull.d.ts.map +1 -0
- package/dist/commands/push.d.ts +40 -0
- package/dist/commands/push.d.ts.map +1 -0
- package/dist/commands/validate.d.ts +36 -0
- package/dist/commands/validate.d.ts.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24985 -876
- package/dist/lib/api.d.ts +139 -0
- package/dist/lib/api.d.ts.map +1 -0
- package/dist/lib/codegen.d.ts +4 -0
- package/dist/lib/codegen.d.ts.map +1 -0
- package/dist/lib/config.d.ts +43 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/package.json +40 -20
- package/bin/gurulu.js +0 -2
- package/dist/api-client.d.ts +0 -33
- package/dist/api-client.js +0 -175
- package/dist/commands/add-server.d.ts +0 -9
- package/dist/commands/add-server.js +0 -162
- package/dist/commands/alerts.d.ts +0 -27
- package/dist/commands/alerts.js +0 -309
- package/dist/commands/api-keys.d.ts +0 -20
- package/dist/commands/api-keys.js +0 -130
- package/dist/commands/attribution.d.ts +0 -22
- package/dist/commands/attribution.js +0 -111
- package/dist/commands/audiences.d.ts +0 -23
- package/dist/commands/audiences.js +0 -243
- package/dist/commands/audit.d.ts +0 -20
- package/dist/commands/audit.js +0 -130
- package/dist/commands/auth.js +0 -249
- package/dist/commands/chat.d.ts +0 -19
- package/dist/commands/chat.js +0 -118
- package/dist/commands/config.d.ts +0 -10
- package/dist/commands/config.js +0 -92
- package/dist/commands/consent.d.ts +0 -27
- package/dist/commands/consent.js +0 -233
- package/dist/commands/conversion-paths.d.ts +0 -19
- package/dist/commands/conversion-paths.js +0 -55
- package/dist/commands/db.d.ts +0 -25
- package/dist/commands/db.js +0 -330
- package/dist/commands/destinations.d.ts +0 -20
- package/dist/commands/destinations.js +0 -191
- package/dist/commands/doctor.js +0 -360
- package/dist/commands/errors.d.ts +0 -27
- package/dist/commands/errors.js +0 -121
- package/dist/commands/events.d.ts +0 -33
- package/dist/commands/events.js +0 -371
- package/dist/commands/experiments.d.ts +0 -22
- package/dist/commands/experiments.js +0 -264
- package/dist/commands/funnels.d.ts +0 -17
- package/dist/commands/funnels.js +0 -203
- package/dist/commands/goals.d.ts +0 -18
- package/dist/commands/goals.js +0 -214
- package/dist/commands/heatmap.d.ts +0 -27
- package/dist/commands/heatmap.js +0 -112
- package/dist/commands/identity.d.ts +0 -29
- package/dist/commands/identity.js +0 -328
- package/dist/commands/init.js +0 -215
- package/dist/commands/insights.d.ts +0 -10
- package/dist/commands/insights.js +0 -77
- package/dist/commands/install.d.ts +0 -259
- package/dist/commands/install.js +0 -1590
- package/dist/commands/login.d.ts +0 -20
- package/dist/commands/login.js +0 -170
- package/dist/commands/logout.d.ts +0 -10
- package/dist/commands/logout.js +0 -41
- package/dist/commands/playground.d.ts +0 -11
- package/dist/commands/playground.js +0 -47
- package/dist/commands/releases.d.ts +0 -17
- package/dist/commands/releases.js +0 -54
- package/dist/commands/replay.d.ts +0 -18
- package/dist/commands/replay.js +0 -64
- package/dist/commands/secrets.d.ts +0 -19
- package/dist/commands/secrets.js +0 -145
- package/dist/commands/setup.d.ts +0 -21
- package/dist/commands/setup.js +0 -67
- package/dist/commands/sites.d.ts +0 -18
- package/dist/commands/sites.js +0 -139
- package/dist/commands/skad.d.ts +0 -18
- package/dist/commands/skad.js +0 -53
- package/dist/commands/sourcemap.d.ts +0 -33
- package/dist/commands/sourcemap.js +0 -204
- package/dist/commands/status.d.ts +0 -7
- package/dist/commands/status.js +0 -136
- package/dist/commands/upgrade.d.ts +0 -21
- package/dist/commands/upgrade.js +0 -183
- package/dist/commands/warehouse.d.ts +0 -20
- package/dist/commands/warehouse.js +0 -65
- package/dist/commands/warehouses.d.ts +0 -17
- package/dist/commands/warehouses.js +0 -182
- package/dist/commands/watch.d.ts +0 -45
- package/dist/commands/watch.js +0 -258
- package/dist/commands/whoami.d.ts +0 -9
- package/dist/commands/whoami.js +0 -50
- package/dist/config.d.ts +0 -75
- package/dist/config.js +0 -329
- package/dist/frameworks/detect.d.ts +0 -8
- package/dist/frameworks/detect.js +0 -458
- package/dist/install-intent-proposal.d.ts +0 -99
- package/dist/install-intent-proposal.js +0 -202
- package/dist/utils/api.d.ts +0 -20
- package/dist/utils/api.js +0 -47
- package/dist/utils/config.d.ts +0 -13
- package/dist/utils/config.js +0 -30
- package/dist/utils/confirm.d.ts +0 -17
- package/dist/utils/confirm.js +0 -40
- package/dist/utils/dry-run.d.ts +0 -20
- package/dist/utils/dry-run.js +0 -67
- package/dist/utils/from-file.d.ts +0 -9
- package/dist/utils/from-file.js +0 -72
- package/dist/utils/redact.d.ts +0 -14
- package/dist/utils/redact.js +0 -48
- package/dist/utils/ui.d.ts +0 -14
- package/dist/utils/ui.js +0 -59
- package/scripts/.gitkeep +0 -0
- package/scripts/README-gurulu-agentic-install.md +0 -114
- package/scripts/README-gurulu-scan.md +0 -98
- package/scripts/audit-cli-scopes.mjs +0 -204
- package/scripts/backfill-tenant-id.mjs +0 -172
- package/scripts/backfill-tenant-links.ts +0 -252
- package/scripts/backup-clickhouse.sh +0 -27
- package/scripts/backup-postgres.sh +0 -19
- package/scripts/bootstrap-runtime-schema.mjs +0 -87
- package/scripts/bootstrap-stripe.mjs +0 -158
- package/scripts/gurulu-agentic-install.lib.cjs +0 -762
- package/scripts/gurulu-agentic-install.mjs +0 -623
- package/scripts/gurulu-scan.lib.cjs +0 -1509
- package/scripts/gurulu-scan.mjs +0 -91
- package/scripts/gurulu-verify-install.lib.cjs +0 -334
- package/scripts/gurulu-verify-install.mjs +0 -59
- package/scripts/init-ssl.sh +0 -26
- package/scripts/migrate-flow-graph-enums.sh +0 -86
- package/scripts/monitor-disk.sh +0 -24
- package/scripts/patches/astro.patch.cjs +0 -74
- package/scripts/patches/auto-instrument/ast-helper.cjs +0 -480
- package/scripts/patches/auto-instrument/astro.cjs +0 -273
- package/scripts/patches/auto-instrument/express.cjs +0 -383
- package/scripts/patches/auto-instrument/fastify.cjs +0 -262
- package/scripts/patches/auto-instrument/hono.cjs +0 -392
- package/scripts/patches/auto-instrument/index.cjs +0 -80
- package/scripts/patches/auto-instrument/nestjs.cjs +0 -286
- package/scripts/patches/auto-instrument/nextjs-app-router.cjs +0 -345
- package/scripts/patches/auto-instrument/nextjs-pages.cjs +0 -361
- package/scripts/patches/auto-instrument/remix.cjs +0 -168
- package/scripts/patches/auto-instrument/sdk-helper-map.cjs +0 -241
- package/scripts/patches/auto-instrument/singleton-helper.cjs +0 -193
- package/scripts/patches/auto-instrument/sveltekit.cjs +0 -161
- package/scripts/patches/auto-instrument/vite-react.cjs +0 -37
- package/scripts/patches/auto-instrument/vue.cjs +0 -196
- package/scripts/patches/express.patch.cjs +0 -99
- package/scripts/patches/fastify.patch.cjs +0 -108
- package/scripts/patches/index.cjs +0 -300
- package/scripts/patches/nestjs.patch.cjs +0 -112
- package/scripts/patches/nextjs-app-router.patch.cjs +0 -97
- package/scripts/patches/nextjs-pages.patch.cjs +0 -97
- package/scripts/patches/remix.patch.cjs +0 -75
- package/scripts/patches/sveltekit.patch.cjs +0 -72
- package/scripts/patches/vite-react.patch.cjs +0 -73
- package/scripts/patches/vue.patch.cjs +0 -82
- package/scripts/renew-ssl.sh +0 -14
- package/scripts/resolve-migration.sh +0 -23
- package/scripts/seed-cli-dev-keys.mjs +0 -130
- package/scripts/seed-test-data.mjs +0 -391
- package/scripts/spike-browserless.ts +0 -65
- package/scripts/tenant-pivot-consistency-check.mjs +0 -205
- package/scripts/tenant-pivot-phase-3-cleanup.lib.cjs +0 -258
- package/scripts/tenant-pivot-phase-3-cleanup.mjs +0 -98
- package/scripts/test-identity-resolution.ts +0 -804
- package/scripts/validate-gurulu-schemas.mjs +0 -79
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
export interface ApiClientOptions {
|
|
2
|
+
endpoint: string;
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ApiError {
|
|
6
|
+
code: string;
|
|
7
|
+
message: string;
|
|
8
|
+
status: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class ApiHttpError extends Error {
|
|
11
|
+
status: number;
|
|
12
|
+
code: string;
|
|
13
|
+
constructor(opts: {
|
|
14
|
+
status: number;
|
|
15
|
+
code: string;
|
|
16
|
+
message: string;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export declare class ApiClient {
|
|
20
|
+
private opts;
|
|
21
|
+
constructor(opts: ApiClientOptions);
|
|
22
|
+
private headers;
|
|
23
|
+
get<T>(path: string, query?: Record<string, string | number>): Promise<T>;
|
|
24
|
+
post<T>(path: string, body: unknown): Promise<T>;
|
|
25
|
+
private handle;
|
|
26
|
+
}
|
|
27
|
+
export interface RegistryPullResponse {
|
|
28
|
+
manifest_version: string;
|
|
29
|
+
schema_version: number;
|
|
30
|
+
workspace_id: string;
|
|
31
|
+
exported_at: string;
|
|
32
|
+
events: ManifestEvent[];
|
|
33
|
+
}
|
|
34
|
+
export interface ManifestEvent {
|
|
35
|
+
key: string;
|
|
36
|
+
name: string;
|
|
37
|
+
meaning: string;
|
|
38
|
+
type: 'interaction' | 'intent' | 'outcome';
|
|
39
|
+
lifecycle: 'draft' | 'active' | 'deprecated' | 'archived';
|
|
40
|
+
producerPrimary: string;
|
|
41
|
+
producerAllowed: string[];
|
|
42
|
+
producerForbidden: string[];
|
|
43
|
+
schemaVersion: number;
|
|
44
|
+
properties: ManifestProperty[];
|
|
45
|
+
}
|
|
46
|
+
export interface ManifestProperty {
|
|
47
|
+
name: string;
|
|
48
|
+
type: 'string' | 'number' | 'boolean' | 'date' | 'json' | 'array';
|
|
49
|
+
required: boolean;
|
|
50
|
+
format?: string;
|
|
51
|
+
position?: number;
|
|
52
|
+
}
|
|
53
|
+
export interface RegistryPushBody {
|
|
54
|
+
action: 'add_event' | 'add_property' | 'modify_event';
|
|
55
|
+
source: 'cli' | 'mcp:cursor' | 'mcp:claude_code' | 'mcp:codex' | 'mcp:lovable' | 'mcp:generic';
|
|
56
|
+
payload: {
|
|
57
|
+
event_key: string;
|
|
58
|
+
name?: string;
|
|
59
|
+
meaning: string;
|
|
60
|
+
event_type: 'interaction' | 'intent' | 'outcome';
|
|
61
|
+
primary_producer?: 'script' | 'sdk_web' | 'sdk_server' | 'webhook' | 'playground' | 'agent' | 'cli';
|
|
62
|
+
required_properties?: Array<{
|
|
63
|
+
name: string;
|
|
64
|
+
type: string;
|
|
65
|
+
format?: string;
|
|
66
|
+
}>;
|
|
67
|
+
optional_properties?: Array<{
|
|
68
|
+
name: string;
|
|
69
|
+
type: string;
|
|
70
|
+
}>;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export interface RegistryPushResponse {
|
|
74
|
+
verification_id: string;
|
|
75
|
+
status: 'pending_approval';
|
|
76
|
+
event_key: string;
|
|
77
|
+
lifecycle: string;
|
|
78
|
+
message: string;
|
|
79
|
+
}
|
|
80
|
+
export interface RecentEventsResponse {
|
|
81
|
+
workspace_id: string;
|
|
82
|
+
count: number;
|
|
83
|
+
events: Array<{
|
|
84
|
+
event_id: string;
|
|
85
|
+
event_key: string;
|
|
86
|
+
event_type: 'interaction' | 'intent' | 'outcome';
|
|
87
|
+
occurred_at: string;
|
|
88
|
+
anonymous_id: string | null;
|
|
89
|
+
person_id: string | null;
|
|
90
|
+
properties: Record<string, unknown>;
|
|
91
|
+
}>;
|
|
92
|
+
note?: string;
|
|
93
|
+
}
|
|
94
|
+
export interface HealthOverviewResponse {
|
|
95
|
+
workspace_id: string;
|
|
96
|
+
registry: {
|
|
97
|
+
total_events: number;
|
|
98
|
+
by_type: {
|
|
99
|
+
interaction: number;
|
|
100
|
+
intent: number;
|
|
101
|
+
outcome: number;
|
|
102
|
+
};
|
|
103
|
+
by_lifecycle: {
|
|
104
|
+
draft: number;
|
|
105
|
+
active: number;
|
|
106
|
+
deprecated: number;
|
|
107
|
+
archived: number;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
alarms: {
|
|
111
|
+
total: number;
|
|
112
|
+
active: number;
|
|
113
|
+
by_severity: {
|
|
114
|
+
critical: number;
|
|
115
|
+
warn: number;
|
|
116
|
+
info: number;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
traffic: {
|
|
120
|
+
recent_events_24h: number;
|
|
121
|
+
clickhouse_available: boolean;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export interface DeviceStartResponse {
|
|
125
|
+
device_code: string;
|
|
126
|
+
user_code: string;
|
|
127
|
+
verification_url: string;
|
|
128
|
+
verification_url_complete: string;
|
|
129
|
+
expires_in: number;
|
|
130
|
+
interval: number;
|
|
131
|
+
}
|
|
132
|
+
export interface DeviceTokenResponse {
|
|
133
|
+
access_token: string;
|
|
134
|
+
token_type: 'Bearer';
|
|
135
|
+
workspace_id: string;
|
|
136
|
+
tenant_id: string;
|
|
137
|
+
expires_in: number | null;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/lib/api.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,M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IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,QAAQ,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../../src/lib/codegen.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAmC,oBAAoB,EAAE,MAAM,UAAU,CAAC;AA8BtF,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,MAAM,CAwDzE;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,MAAM,CAE3E"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export interface ProjectConfig {
|
|
2
|
+
workspace_id: string;
|
|
3
|
+
endpoint: string;
|
|
4
|
+
sdk_preference: 'web' | 'node' | 'react';
|
|
5
|
+
registry_path: string;
|
|
6
|
+
generated_path: string;
|
|
7
|
+
manifest_lock_path: string;
|
|
8
|
+
auto_pull_on_init: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface GlobalCredentialEntry {
|
|
11
|
+
workspace_id: string;
|
|
12
|
+
api_key: string;
|
|
13
|
+
endpoint: string;
|
|
14
|
+
last_used: string;
|
|
15
|
+
}
|
|
16
|
+
export interface GlobalCredentials {
|
|
17
|
+
workspaces: GlobalCredentialEntry[];
|
|
18
|
+
default_workspace_id?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare const DEFAULT_ENDPOINT: string;
|
|
21
|
+
export declare function projectRoot(cwd?: string): string;
|
|
22
|
+
export declare function projectConfigPath(cwd?: string): string;
|
|
23
|
+
export declare function projectRegistryPath(cwd?: string): string;
|
|
24
|
+
export declare function projectGeneratedPath(cwd?: string): string;
|
|
25
|
+
export declare function projectManifestLockPath(cwd?: string): string;
|
|
26
|
+
export declare function globalCredentialsPath(): string;
|
|
27
|
+
export declare function ensureDir(path: string): void;
|
|
28
|
+
export declare function readProjectConfig(cwd?: string): ProjectConfig | null;
|
|
29
|
+
export declare function writeProjectConfig(cfg: ProjectConfig, cwd?: string): void;
|
|
30
|
+
export declare function readGlobalCredentials(): GlobalCredentials;
|
|
31
|
+
export declare function writeGlobalCredentials(creds: GlobalCredentials): void;
|
|
32
|
+
export declare function findCredentialForWorkspace(workspaceId: string): GlobalCredentialEntry | null;
|
|
33
|
+
export declare function upsertCredential(entry: GlobalCredentialEntry): void;
|
|
34
|
+
export declare function removeCredential(workspaceId: string): boolean;
|
|
35
|
+
export declare function resolveActiveCredential(opts: {
|
|
36
|
+
workspaceId?: string;
|
|
37
|
+
cwd?: string;
|
|
38
|
+
}): {
|
|
39
|
+
workspaceId: string;
|
|
40
|
+
apiKey: string;
|
|
41
|
+
endpoint: string;
|
|
42
|
+
} | null;
|
|
43
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC;IACzC,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,qBAAqB;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBA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C;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAmBnE"}
|
package/package.json
CHANGED
|
@@ -1,33 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gurulu/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"license": "BUSL-1.1",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"description": "Gurulu CLI. init / pull / push / validate / doctor — registry as code, local schema sync.",
|
|
11
|
+
"homepage": "https://gurulu.io",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/Preatan/gurulu.io.git",
|
|
15
|
+
"directory": "packages/cli"
|
|
16
|
+
},
|
|
5
17
|
"bin": {
|
|
6
|
-
"gurulu": "bin
|
|
18
|
+
"gurulu": "./dist/bin.js"
|
|
19
|
+
},
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"module": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./package.json": "./package.json"
|
|
7
30
|
},
|
|
8
|
-
"main": "dist/index.js",
|
|
9
31
|
"files": [
|
|
10
32
|
"dist",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
33
|
+
"README.md",
|
|
34
|
+
"LICENSE"
|
|
13
35
|
],
|
|
14
36
|
"scripts": {
|
|
15
|
-
"build": "
|
|
16
|
-
"
|
|
37
|
+
"build": "rm -rf dist && bun run build:js && bun run build:types && bun run build:bin",
|
|
38
|
+
"build:js": "bun build ./src/index.ts --outdir ./dist --target node --format=esm",
|
|
39
|
+
"build:bin": "bun build ./src/bin.ts --outdir ./dist --target node --format=esm && chmod +x dist/bin.js",
|
|
40
|
+
"build:types": "tsc -p tsconfig.build.json",
|
|
41
|
+
"typecheck": "tsc --noEmit",
|
|
42
|
+
"test": "echo no-tests-yet",
|
|
43
|
+
"prepublishOnly": "bun run build",
|
|
44
|
+
"clean": "rm -rf dist .turbo"
|
|
17
45
|
},
|
|
18
46
|
"dependencies": {
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"@babel/traverse": "^7.24.0",
|
|
22
|
-
"@babel/generator": "^7.24.0"
|
|
47
|
+
"citty": "^0.1.6",
|
|
48
|
+
"undici": "^7.0.0"
|
|
23
49
|
},
|
|
24
50
|
"devDependencies": {
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
"@types/node": "^20.0.0"
|
|
28
|
-
},
|
|
29
|
-
"engines": {
|
|
30
|
-
"node": ">=18.0.0"
|
|
31
|
-
},
|
|
32
|
-
"license": "MIT"
|
|
51
|
+
"typescript": "^5.6.0"
|
|
52
|
+
}
|
|
33
53
|
}
|
package/bin/gurulu.js
DELETED
package/dist/api-client.d.ts
DELETED
|
@@ -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>;
|
package/dist/api-client.js
DELETED
|
@@ -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,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
|
-
}
|