@gurulu/cli 0.1.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/README.md +66 -0
- package/bin/gurulu.js +2 -0
- package/dist/api-client.d.ts +27 -0
- package/dist/api-client.js +150 -0
- package/dist/commands/add-server.d.ts +9 -0
- package/dist/commands/add-server.js +155 -0
- package/dist/commands/alerts.d.ts +22 -0
- package/dist/commands/alerts.js +281 -0
- package/dist/commands/api-keys.d.ts +20 -0
- package/dist/commands/api-keys.js +130 -0
- package/dist/commands/audiences.d.ts +16 -0
- package/dist/commands/audiences.js +180 -0
- package/dist/commands/audit.d.ts +20 -0
- package/dist/commands/audit.js +130 -0
- package/dist/commands/auth.d.ts +20 -0
- package/dist/commands/auth.js +214 -0
- package/dist/commands/chat.d.ts +18 -0
- package/dist/commands/chat.js +117 -0
- package/dist/commands/config.d.ts +10 -0
- package/dist/commands/config.js +92 -0
- package/dist/commands/db.d.ts +25 -0
- package/dist/commands/db.js +322 -0
- package/dist/commands/destinations.d.ts +20 -0
- package/dist/commands/destinations.js +191 -0
- package/dist/commands/doctor.d.ts +7 -0
- package/dist/commands/doctor.js +318 -0
- package/dist/commands/events.d.ts +27 -0
- package/dist/commands/events.js +147 -0
- package/dist/commands/experiments.d.ts +18 -0
- package/dist/commands/experiments.js +233 -0
- package/dist/commands/identity.d.ts +13 -0
- package/dist/commands/identity.js +107 -0
- package/dist/commands/init.d.ts +11 -0
- package/dist/commands/init.js +215 -0
- package/dist/commands/insights.d.ts +10 -0
- package/dist/commands/insights.js +65 -0
- package/dist/commands/install.d.ts +233 -0
- package/dist/commands/install.js +920 -0
- package/dist/commands/login.d.ts +20 -0
- package/dist/commands/login.js +170 -0
- package/dist/commands/logout.d.ts +10 -0
- package/dist/commands/logout.js +41 -0
- package/dist/commands/playground.d.ts +11 -0
- package/dist/commands/playground.js +47 -0
- package/dist/commands/sites.d.ts +18 -0
- package/dist/commands/sites.js +139 -0
- package/dist/commands/sourcemap.d.ts +21 -0
- package/dist/commands/sourcemap.js +137 -0
- package/dist/commands/status.d.ts +7 -0
- package/dist/commands/status.js +136 -0
- package/dist/commands/warehouse.d.ts +20 -0
- package/dist/commands/warehouse.js +65 -0
- package/dist/commands/warehouses.d.ts +17 -0
- package/dist/commands/warehouses.js +182 -0
- package/dist/commands/whoami.d.ts +9 -0
- package/dist/commands/whoami.js +47 -0
- package/dist/config.d.ts +75 -0
- package/dist/config.js +329 -0
- package/dist/frameworks/detect.d.ts +8 -0
- package/dist/frameworks/detect.js +362 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +429 -0
- package/dist/install-intent-proposal.d.ts +99 -0
- package/dist/install-intent-proposal.js +202 -0
- package/dist/utils/api.d.ts +20 -0
- package/dist/utils/api.js +47 -0
- package/dist/utils/config.d.ts +13 -0
- package/dist/utils/config.js +30 -0
- package/dist/utils/confirm.d.ts +17 -0
- package/dist/utils/confirm.js +40 -0
- package/dist/utils/dry-run.d.ts +20 -0
- package/dist/utils/dry-run.js +67 -0
- package/dist/utils/from-file.d.ts +9 -0
- package/dist/utils/from-file.js +72 -0
- package/dist/utils/ui.d.ts +14 -0
- package/dist/utils/ui.js +59 -0
- package/package.json +26 -0
|
@@ -0,0 +1,136 @@
|
|
|
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.statusCommand = statusCommand;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const config_1 = require("../config");
|
|
10
|
+
const api_client_1 = require("../api-client");
|
|
11
|
+
const detect_1 = require("../frameworks/detect");
|
|
12
|
+
const ui_1 = require("../utils/ui");
|
|
13
|
+
async function statusCommand(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 statusJSON(siteId, profile, projectDir);
|
|
25
|
+
}
|
|
26
|
+
(0, ui_1.banner)();
|
|
27
|
+
console.log((0, ui_1.bold)(' Status Check'));
|
|
28
|
+
console.log('');
|
|
29
|
+
// 1. Framework detection
|
|
30
|
+
const framework = (0, detect_1.detectFramework)(projectDir);
|
|
31
|
+
console.log(` ${(0, ui_1.dim)('Framework:')} ${(0, detect_1.getFrameworkDisplayName)(framework)}`);
|
|
32
|
+
// 2. SDK installed check
|
|
33
|
+
const pkgPath = path_1.default.join(projectDir, 'package.json');
|
|
34
|
+
let sdkInstalled = false;
|
|
35
|
+
if (fs_1.default.existsSync(pkgPath)) {
|
|
36
|
+
const pkg = JSON.parse(fs_1.default.readFileSync(pkgPath, 'utf-8'));
|
|
37
|
+
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
38
|
+
sdkInstalled = !!allDeps['@gurulu/web-sdk'] || !!allDeps['@gurulu/node'] || !!allDeps['@gurulu/react-native'];
|
|
39
|
+
}
|
|
40
|
+
// Check for mobile SDKs (non-npm based)
|
|
41
|
+
let mobileSDKFound = false;
|
|
42
|
+
const pubspecPath = path_1.default.join(projectDir, 'pubspec.yaml');
|
|
43
|
+
if (fs_1.default.existsSync(pubspecPath) && fs_1.default.readFileSync(pubspecPath, 'utf-8').includes('gurulu_flutter')) {
|
|
44
|
+
mobileSDKFound = true;
|
|
45
|
+
}
|
|
46
|
+
const swiftPkgPath = path_1.default.join(projectDir, 'Package.swift');
|
|
47
|
+
if (!mobileSDKFound && fs_1.default.existsSync(swiftPkgPath) && fs_1.default.readFileSync(swiftPkgPath, 'utf-8').includes('gurulu-ios-sdk')) {
|
|
48
|
+
mobileSDKFound = true;
|
|
49
|
+
}
|
|
50
|
+
for (const gFile of ['build.gradle.kts', 'build.gradle']) {
|
|
51
|
+
const gPath = path_1.default.join(projectDir, gFile);
|
|
52
|
+
if (!mobileSDKFound && fs_1.default.existsSync(gPath)) {
|
|
53
|
+
const content = fs_1.default.readFileSync(gPath, 'utf-8');
|
|
54
|
+
if (content.includes('gurulu') || content.includes('jitpack')) {
|
|
55
|
+
mobileSDKFound = true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Also check for gurulu setup file
|
|
60
|
+
const hasSetupFile = checkSetupFile(projectDir);
|
|
61
|
+
const installed = sdkInstalled || hasSetupFile || mobileSDKFound;
|
|
62
|
+
console.log(` ${(0, ui_1.dim)('SDK:')} ${installed ? (0, ui_1.green)('Installed') : (0, ui_1.yellow)('Not detected')}`);
|
|
63
|
+
// 3. Auth check
|
|
64
|
+
const authed = !!profile;
|
|
65
|
+
console.log(` ${(0, ui_1.dim)('Auth:')} ${authed ? (0, ui_1.green)('Authenticated') : (0, ui_1.yellow)('Not authenticated')}`);
|
|
66
|
+
// 4. Site check
|
|
67
|
+
console.log(` ${(0, ui_1.dim)('Site ID:')} ${siteId ? siteId : (0, ui_1.yellow)('Not set')}`);
|
|
68
|
+
// 5. Connection check via /api/cli/sites/:id/health
|
|
69
|
+
if (siteId && profile) {
|
|
70
|
+
try {
|
|
71
|
+
const health = await (0, api_client_1.cliApiJson)(`/api/cli/sites/${siteId}/health`, { preloadedProfile: profile });
|
|
72
|
+
if (health.healthy) {
|
|
73
|
+
console.log(` ${(0, ui_1.dim)('Connection:')} ${(0, ui_1.green)('All services healthy')}`);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const failing = Object.entries(health.checks)
|
|
77
|
+
.filter(([, s]) => s === 'fail')
|
|
78
|
+
.map(([k]) => k)
|
|
79
|
+
.join(', ');
|
|
80
|
+
console.log(` ${(0, ui_1.dim)('Connection:')} ${(0, ui_1.red)(`Unhealthy: ${failing}`)}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
console.log(` ${(0, ui_1.dim)('Connection:')} ${(0, ui_1.yellow)('Could not reach health endpoint')}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
if (!siteId) {
|
|
89
|
+
console.log(` ${(0, ui_1.dim)('Connection:')} ${(0, ui_1.dim)('Skipped (no site)')}`);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
console.log(` ${(0, ui_1.dim)('Connection:')} ${(0, ui_1.dim)('Skipped (not authenticated)')}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
console.log('');
|
|
96
|
+
if (!installed) {
|
|
97
|
+
(0, ui_1.info)(`Run ${(0, ui_1.cyan)('gurulu init')} to set up analytics`);
|
|
98
|
+
}
|
|
99
|
+
if (!authed) {
|
|
100
|
+
(0, ui_1.info)(`Run ${(0, ui_1.cyan)('gurulu login')} to authenticate`);
|
|
101
|
+
}
|
|
102
|
+
console.log('');
|
|
103
|
+
}
|
|
104
|
+
function checkSetupFile(projectDir) {
|
|
105
|
+
const candidates = [
|
|
106
|
+
'src/lib/gurulu.tsx',
|
|
107
|
+
'src/lib/gurulu.ts',
|
|
108
|
+
'src/gurulu.ts',
|
|
109
|
+
'src/plugins/gurulu.ts',
|
|
110
|
+
'plugins/gurulu.client.ts',
|
|
111
|
+
'src/components/Gurulu.astro',
|
|
112
|
+
'src/gurulu.middleware.ts',
|
|
113
|
+
];
|
|
114
|
+
return candidates.some(f => fs_1.default.existsSync(path_1.default.join(projectDir, f)));
|
|
115
|
+
}
|
|
116
|
+
async function statusJSON(siteId, profile, projectDir) {
|
|
117
|
+
const framework = (0, detect_1.detectFramework)(projectDir);
|
|
118
|
+
const hasSetupFile = checkSetupFile(projectDir);
|
|
119
|
+
const result = {
|
|
120
|
+
framework,
|
|
121
|
+
frameworkName: (0, detect_1.getFrameworkDisplayName)(framework),
|
|
122
|
+
sdkDetected: hasSetupFile,
|
|
123
|
+
authenticated: !!profile,
|
|
124
|
+
siteId: siteId || null,
|
|
125
|
+
connection: null,
|
|
126
|
+
};
|
|
127
|
+
if (siteId && profile) {
|
|
128
|
+
try {
|
|
129
|
+
result.connection = await (0, api_client_1.cliApiJson)(`/api/cli/sites/${siteId}/health`, { preloadedProfile: profile });
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
// leave as null
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
console.log(JSON.stringify(result, null, 2));
|
|
136
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 18 B1 — `gurulu warehouse export` — manually trigger a warehouse
|
|
3
|
+
* export run from the CLI. Uses the multi-profile config and Bearer auth
|
|
4
|
+
* via cliApi.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* gurulu warehouse export --export <warehouseExportId>
|
|
8
|
+
*
|
|
9
|
+
* The `--tenant` flag is accepted for forward compatibility (Phase 18 B2
|
|
10
|
+
* will route to a tenant-aware endpoint) but is not required today —
|
|
11
|
+
* tenant scoping is derived server-side from the authenticated session.
|
|
12
|
+
*/
|
|
13
|
+
interface WarehouseArgs {
|
|
14
|
+
tenant?: string;
|
|
15
|
+
export?: string;
|
|
16
|
+
json?: boolean;
|
|
17
|
+
profile?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function warehouseExportCommand(args: WarehouseArgs): Promise<void>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Phase 18 B1 — `gurulu warehouse export` — manually trigger a warehouse
|
|
4
|
+
* export run from the CLI. Uses the multi-profile config and Bearer auth
|
|
5
|
+
* via cliApi.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* gurulu warehouse export --export <warehouseExportId>
|
|
9
|
+
*
|
|
10
|
+
* The `--tenant` flag is accepted for forward compatibility (Phase 18 B2
|
|
11
|
+
* will route to a tenant-aware endpoint) but is not required today —
|
|
12
|
+
* tenant scoping is derived server-side from the authenticated session.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.warehouseExportCommand = warehouseExportCommand;
|
|
16
|
+
const config_1 = require("../config");
|
|
17
|
+
const api_client_1 = require("../api-client");
|
|
18
|
+
const ui_1 = require("../utils/ui");
|
|
19
|
+
async function warehouseExportCommand(args) {
|
|
20
|
+
let profile;
|
|
21
|
+
try {
|
|
22
|
+
profile = await (0, config_1.loadActiveProfile)({ profile: args.profile });
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
if (args.json)
|
|
26
|
+
console.log(JSON.stringify({ error: 'not_authenticated' }));
|
|
27
|
+
else
|
|
28
|
+
(0, ui_1.error)('Not authenticated. Run "gurulu login" first.');
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
if (!args.export) {
|
|
32
|
+
if (args.json)
|
|
33
|
+
console.log(JSON.stringify({ error: 'export_id_required' }));
|
|
34
|
+
else
|
|
35
|
+
(0, ui_1.error)('--export <id> is required');
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
const url = `/api/warehouses/exports/${encodeURIComponent(args.export)}/trigger`;
|
|
39
|
+
try {
|
|
40
|
+
const res = await (0, api_client_1.cliApi)(url, {
|
|
41
|
+
method: 'POST',
|
|
42
|
+
preloadedProfile: profile,
|
|
43
|
+
});
|
|
44
|
+
if (!res.ok) {
|
|
45
|
+
const text = await res.text();
|
|
46
|
+
throw new Error(`HTTP ${res.status}: ${text}`);
|
|
47
|
+
}
|
|
48
|
+
const body = await res.json();
|
|
49
|
+
if (args.json) {
|
|
50
|
+
console.log(JSON.stringify(body, null, 2));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
(0, ui_1.info)(`Warehouse export ${args.export} triggered`);
|
|
54
|
+
(0, ui_1.success)(`Status: ${body?.result?.status ?? 'ok'}`);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
if (args.json) {
|
|
58
|
+
console.log(JSON.stringify({ error: err.message }));
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
(0, ui_1.error)(`Trigger failed: ${err.message}`);
|
|
62
|
+
}
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 19.5 W2 B6 — `gurulu warehouses list|runs <id>`.
|
|
3
|
+
* Phase 20 W2 B5 — `create|update|delete|run`.
|
|
4
|
+
*/
|
|
5
|
+
export interface WarehousesArgs {
|
|
6
|
+
action?: string;
|
|
7
|
+
target?: string;
|
|
8
|
+
json?: boolean;
|
|
9
|
+
profile?: string;
|
|
10
|
+
fromFile?: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
type?: string;
|
|
13
|
+
schedule?: string;
|
|
14
|
+
yes?: boolean;
|
|
15
|
+
dryRun?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare function warehousesCommand(args: WarehousesArgs): Promise<void>;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Phase 19.5 W2 B6 — `gurulu warehouses list|runs <id>`.
|
|
4
|
+
* Phase 20 W2 B5 — `create|update|delete|run`.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.warehousesCommand = warehousesCommand;
|
|
8
|
+
const api_client_1 = require("../api-client");
|
|
9
|
+
const ui_1 = require("../utils/ui");
|
|
10
|
+
const confirm_1 = require("../utils/confirm");
|
|
11
|
+
const dry_run_1 = require("../utils/dry-run");
|
|
12
|
+
const from_file_1 = require("../utils/from-file");
|
|
13
|
+
async function warehousesCommand(args) {
|
|
14
|
+
const action = args.action || 'list';
|
|
15
|
+
switch (action) {
|
|
16
|
+
case 'list':
|
|
17
|
+
return listCmd(args);
|
|
18
|
+
case 'runs':
|
|
19
|
+
return runsCmd(args);
|
|
20
|
+
case 'create':
|
|
21
|
+
return createCmd(args);
|
|
22
|
+
case 'update':
|
|
23
|
+
return updateCmd(args);
|
|
24
|
+
case 'delete':
|
|
25
|
+
return deleteCmd(args);
|
|
26
|
+
case 'run':
|
|
27
|
+
return runManualCmd(args);
|
|
28
|
+
default:
|
|
29
|
+
(0, ui_1.error)(`Unknown warehouses action: ${action}`);
|
|
30
|
+
(0, ui_1.info)('Usage: gurulu warehouses [list|runs|create|update|delete|run]');
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function listCmd(args) {
|
|
35
|
+
const body = await (0, api_client_1.cliApiJson)('/api/cli/warehouses', {
|
|
36
|
+
profile: args.profile,
|
|
37
|
+
});
|
|
38
|
+
if (args.json) {
|
|
39
|
+
process.stdout.write(JSON.stringify(body, null, 2) + '\n');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const rows = body.exports || [];
|
|
43
|
+
if (rows.length === 0) {
|
|
44
|
+
(0, ui_1.info)('No warehouse exports configured.');
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
process.stdout.write(['ID', 'NAME', 'TYPE', 'SCHEDULE', 'LAST_RUN', 'STATUS'].join('\t') + '\n');
|
|
48
|
+
for (const e of rows) {
|
|
49
|
+
process.stdout.write([
|
|
50
|
+
e.id,
|
|
51
|
+
e.name,
|
|
52
|
+
e.type,
|
|
53
|
+
e.schedule,
|
|
54
|
+
String(e.lastRunAt || '-'),
|
|
55
|
+
e.lastRunStatus || '-',
|
|
56
|
+
].join('\t') + '\n');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function runsCmd(args) {
|
|
60
|
+
if (!args.target) {
|
|
61
|
+
(0, ui_1.error)('Usage: gurulu warehouses runs <export-id>');
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
const body = await (0, api_client_1.cliApiJson)(`/api/cli/warehouses/${encodeURIComponent(args.target)}/runs`, { profile: args.profile });
|
|
65
|
+
if (args.json) {
|
|
66
|
+
process.stdout.write(JSON.stringify(body, null, 2) + '\n');
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const rows = body.runs || [];
|
|
70
|
+
if (rows.length === 0) {
|
|
71
|
+
(0, ui_1.info)('No runs yet.');
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
process.stdout.write(['ID', 'STARTED', 'STATUS', 'TABLE', 'ROWS', 'BYTES'].join('\t') + '\n');
|
|
75
|
+
for (const r of rows) {
|
|
76
|
+
process.stdout.write([r.id, String(r.startedAt), r.status, r.tableName, r.rowsExported, r.bytesExported].join('\t') + '\n');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async function createCmd(args) {
|
|
80
|
+
let payload = {};
|
|
81
|
+
if (args.fromFile)
|
|
82
|
+
payload = (0, from_file_1.loadFromFile)(args.fromFile);
|
|
83
|
+
if (args.name)
|
|
84
|
+
payload.name = args.name;
|
|
85
|
+
if (args.type)
|
|
86
|
+
payload.type = args.type;
|
|
87
|
+
if (args.schedule)
|
|
88
|
+
payload.schedule = args.schedule;
|
|
89
|
+
if (!payload.name || !payload.type || !payload.credentialVaultId || !payload.config) {
|
|
90
|
+
(0, ui_1.error)('name, type, credentialVaultId, and config are all required.');
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
if (args.dryRun) {
|
|
94
|
+
const body = await (0, api_client_1.cliApiJson)('/api/cli/warehouses?dryRun=1', {
|
|
95
|
+
profile: args.profile,
|
|
96
|
+
method: 'POST',
|
|
97
|
+
json: payload,
|
|
98
|
+
});
|
|
99
|
+
(0, dry_run_1.printDryRun)(body, args.json);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const ok = await (0, confirm_1.promptConfirm)(`Create warehouse export '${payload.name}'?`, {
|
|
103
|
+
yes: args.yes,
|
|
104
|
+
defaultYes: true,
|
|
105
|
+
});
|
|
106
|
+
if (!ok)
|
|
107
|
+
return (0, ui_1.info)('Aborted.');
|
|
108
|
+
const body = await (0, api_client_1.cliApiJson)('/api/cli/warehouses', {
|
|
109
|
+
profile: args.profile,
|
|
110
|
+
method: 'POST',
|
|
111
|
+
json: payload,
|
|
112
|
+
});
|
|
113
|
+
if (args.json) {
|
|
114
|
+
process.stdout.write(JSON.stringify(body, null, 2) + '\n');
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
(0, ui_1.success)(`Created warehouse export ${body.export?.id ?? ''}`);
|
|
118
|
+
}
|
|
119
|
+
async function updateCmd(args) {
|
|
120
|
+
if (!args.target) {
|
|
121
|
+
(0, ui_1.error)('Usage: gurulu warehouses update <id>');
|
|
122
|
+
process.exit(1);
|
|
123
|
+
}
|
|
124
|
+
let payload = {};
|
|
125
|
+
if (args.fromFile)
|
|
126
|
+
payload = (0, from_file_1.loadFromFile)(args.fromFile);
|
|
127
|
+
if (args.schedule)
|
|
128
|
+
payload.schedule = args.schedule;
|
|
129
|
+
if (args.dryRun) {
|
|
130
|
+
const body = await (0, api_client_1.cliApiJson)(`/api/cli/warehouses/${encodeURIComponent(args.target)}?dryRun=1`, { profile: args.profile, method: 'PATCH', json: payload });
|
|
131
|
+
(0, dry_run_1.printDryRun)(body, args.json);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const ok = await (0, confirm_1.promptConfirm)(`Update warehouse export '${args.target}'?`, {
|
|
135
|
+
yes: args.yes,
|
|
136
|
+
defaultYes: true,
|
|
137
|
+
});
|
|
138
|
+
if (!ok)
|
|
139
|
+
return (0, ui_1.info)('Aborted.');
|
|
140
|
+
const body = await (0, api_client_1.cliApiJson)(`/api/cli/warehouses/${encodeURIComponent(args.target)}`, { profile: args.profile, method: 'PATCH', json: payload });
|
|
141
|
+
if (args.json) {
|
|
142
|
+
process.stdout.write(JSON.stringify(body, null, 2) + '\n');
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
(0, ui_1.success)(`Updated warehouse export ${args.target}`);
|
|
146
|
+
}
|
|
147
|
+
async function deleteCmd(args) {
|
|
148
|
+
if (!args.target) {
|
|
149
|
+
(0, ui_1.error)('Usage: gurulu warehouses delete <id>');
|
|
150
|
+
process.exit(1);
|
|
151
|
+
}
|
|
152
|
+
if (args.dryRun) {
|
|
153
|
+
const body = await (0, api_client_1.cliApiJson)(`/api/cli/warehouses/${encodeURIComponent(args.target)}?dryRun=1`, { profile: args.profile, method: 'DELETE' });
|
|
154
|
+
(0, dry_run_1.printDryRun)(body, args.json);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const ok = await (0, confirm_1.promptConfirm)(`About to delete warehouse export '${args.target}'. Continue?`, { yes: args.yes, defaultYes: false });
|
|
158
|
+
if (!ok)
|
|
159
|
+
return (0, ui_1.info)('Aborted.');
|
|
160
|
+
await (0, api_client_1.cliApiJson)(`/api/cli/warehouses/${encodeURIComponent(args.target)}`, { profile: args.profile, method: 'DELETE' });
|
|
161
|
+
(0, ui_1.success)(`Deleted warehouse export ${args.target}`);
|
|
162
|
+
}
|
|
163
|
+
async function runManualCmd(args) {
|
|
164
|
+
if (!args.target) {
|
|
165
|
+
(0, ui_1.error)('Usage: gurulu warehouses run <id>');
|
|
166
|
+
process.exit(1);
|
|
167
|
+
}
|
|
168
|
+
const ok = await (0, confirm_1.promptConfirm)(`Trigger warehouse export '${args.target}' now?`, {
|
|
169
|
+
yes: args.yes,
|
|
170
|
+
defaultYes: true,
|
|
171
|
+
});
|
|
172
|
+
if (!ok)
|
|
173
|
+
return (0, ui_1.info)('Aborted.');
|
|
174
|
+
const body = await (0, api_client_1.cliApiJson)(`/api/cli/warehouses/${encodeURIComponent(args.target)}/run${args.dryRun ? '?dryRun=1' : ''}`, { profile: args.profile, method: 'POST', json: {} });
|
|
175
|
+
if (args.dryRun)
|
|
176
|
+
return (0, dry_run_1.printDryRun)(body, args.json);
|
|
177
|
+
if (args.json) {
|
|
178
|
+
process.stdout.write(JSON.stringify(body, null, 2) + '\n');
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
(0, ui_1.success)(`Triggered run for ${args.target}`);
|
|
182
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 18.5 W2 — `gurulu whoami`. Loads the active profile and hits
|
|
3
|
+
* `/api/cli/me` for a concise one-line summary. Supports --json.
|
|
4
|
+
*/
|
|
5
|
+
export interface WhoamiArgs {
|
|
6
|
+
profile?: string;
|
|
7
|
+
json?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function whoamiCommand(args: WhoamiArgs): Promise<void>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Phase 18.5 W2 — `gurulu whoami`. Loads the active profile and hits
|
|
4
|
+
* `/api/cli/me` for a concise one-line summary. Supports --json.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.whoamiCommand = whoamiCommand;
|
|
8
|
+
const config_1 = require("../config");
|
|
9
|
+
const api_client_1 = require("../api-client");
|
|
10
|
+
const ui_1 = require("../utils/ui");
|
|
11
|
+
async function whoamiCommand(args) {
|
|
12
|
+
let profile;
|
|
13
|
+
try {
|
|
14
|
+
profile = await (0, config_1.loadActiveProfile)({ profile: args.profile });
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
if (args.json) {
|
|
18
|
+
process.stdout.write(JSON.stringify({ error: 'not_logged_in' }) + '\n');
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
(0, ui_1.error)('Not logged in. Run `gurulu login` first.');
|
|
22
|
+
}
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const me = await (0, api_client_1.cliApiJson)('/api/cli/me', { preloadedProfile: profile });
|
|
27
|
+
if (args.json) {
|
|
28
|
+
process.stdout.write(JSON.stringify(me, null, 2) + '\n');
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const sites = (me.sites || []).length;
|
|
32
|
+
const keys = (me.apiKeys || []).length;
|
|
33
|
+
const installs = me.quota?.installsThisMonth ?? 0;
|
|
34
|
+
const limit = me.quota?.installsLimit ?? '∞';
|
|
35
|
+
process.stdout.write(`${me.user?.email} · ${me.tenant?.name} · ${me.tenant?.plan} plan · ${me.tenant?.id}\n`);
|
|
36
|
+
process.stdout.write(`Sites: ${sites} | API keys: ${keys} | Installs this month: ${installs}/${limit}\n`);
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
if (args.json) {
|
|
40
|
+
process.stdout.write(JSON.stringify({ error: err.message }) + '\n');
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
(0, ui_1.error)(`whoami failed: ${err.message}`);
|
|
44
|
+
}
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 18.5 W2 — Multi-profile CLI config.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the single-profile `~/.gurulu/config.json` used by earlier phases
|
|
5
|
+
* with a profile-aware store, while keeping backward compatibility for
|
|
6
|
+
* commands that still call `utils/config.ts` (they now read from the
|
|
7
|
+
* currently-active profile).
|
|
8
|
+
*
|
|
9
|
+
* Resolution order for a live session:
|
|
10
|
+
* 1. GURULU_SECRET_KEY (env-var override — bypasses the file entirely)
|
|
11
|
+
* 2. --profile <name> (CLI flag)
|
|
12
|
+
* 3. GURULU_PROFILE (env)
|
|
13
|
+
* 4. default_profile (from file)
|
|
14
|
+
* 5. 'personal' (final fallback)
|
|
15
|
+
*
|
|
16
|
+
* Optional macOS keychain integration: if `keytar` is available at runtime,
|
|
17
|
+
* secrets can be stored there under service 'io.gurulu.cli' account
|
|
18
|
+
* `<profile>`. If unavailable, secrets fall back to the plaintext file.
|
|
19
|
+
* Keytar is a **soft runtime require** — never a hard dependency, because
|
|
20
|
+
* it's a native module and we don't want to force its install.
|
|
21
|
+
*/
|
|
22
|
+
export interface ProfileConfig {
|
|
23
|
+
email: string;
|
|
24
|
+
secret_key: string;
|
|
25
|
+
api_base: string;
|
|
26
|
+
}
|
|
27
|
+
export interface StoredProfile {
|
|
28
|
+
email: string;
|
|
29
|
+
secret_key?: string;
|
|
30
|
+
api_base: string;
|
|
31
|
+
keychain?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface ConfigFile {
|
|
34
|
+
default_profile: string;
|
|
35
|
+
profiles: Record<string, StoredProfile>;
|
|
36
|
+
}
|
|
37
|
+
export interface ActiveProfile extends ProfileConfig {
|
|
38
|
+
name: string;
|
|
39
|
+
source: 'env' | 'file' | 'keychain';
|
|
40
|
+
}
|
|
41
|
+
export interface CliFlags {
|
|
42
|
+
profile?: string;
|
|
43
|
+
}
|
|
44
|
+
export declare function configPath(): string;
|
|
45
|
+
export declare function readKeychainSecret(profile: string): Promise<string | null>;
|
|
46
|
+
export declare function writeKeychainSecret(profile: string, secret: string): Promise<boolean>;
|
|
47
|
+
export declare function deleteKeychainSecret(profile: string): Promise<void>;
|
|
48
|
+
export declare function isKeychainAvailable(): boolean;
|
|
49
|
+
export declare function listProfiles(): Array<{
|
|
50
|
+
name: string;
|
|
51
|
+
email: string;
|
|
52
|
+
api_base: string;
|
|
53
|
+
isDefault: boolean;
|
|
54
|
+
keychain: boolean;
|
|
55
|
+
}>;
|
|
56
|
+
export declare function getStoredProfile(name: string): StoredProfile | null;
|
|
57
|
+
export declare function getDefaultProfileName(): string;
|
|
58
|
+
export declare function setDefaultProfile(name: string): void;
|
|
59
|
+
export declare function saveProfile(name: string, profile: ProfileConfig, opts?: {
|
|
60
|
+
useKeychain?: boolean;
|
|
61
|
+
}): Promise<{
|
|
62
|
+
storedInKeychain: boolean;
|
|
63
|
+
}>;
|
|
64
|
+
export declare function deleteProfile(name: string): Promise<boolean>;
|
|
65
|
+
export declare function deleteAllProfiles(): Promise<string[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Resolve the active profile given CLI flags. Throws if no usable profile.
|
|
68
|
+
* Accepts the `GURULU_SECRET_KEY` env var as an override for CI.
|
|
69
|
+
*/
|
|
70
|
+
export declare function loadActiveProfile(flags?: CliFlags): Promise<ActiveProfile>;
|
|
71
|
+
export declare function getActiveProfile(flags?: CliFlags): Promise<ActiveProfile | null>;
|
|
72
|
+
export declare class ProfileNotFoundError extends Error {
|
|
73
|
+
constructor(name: string);
|
|
74
|
+
}
|
|
75
|
+
export declare function defaultApiBase(): string;
|