@mushi-mushi/cli 0.22.1 → 0.23.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.
- package/README.md +28 -2
- package/dist/{chunk-JAUKBLPK.js → chunk-AIZRI665.js} +102 -2
- package/dist/chunk-I4UK3WTN.js +6 -0
- package/dist/{chunk-R2HPR2FV.js → chunk-M6L22NJU.js} +534 -27
- package/dist/chunk-NZ64LBLU.js +437 -0
- package/dist/{connect-JIEIWTF3.js → connect-5VPUYE6H.js} +1 -1
- package/dist/{connect-2RM43XHO.js → connect-IWFKKXGZ.js} +10 -7
- package/dist/detect.d.ts +1 -1
- package/dist/detect.js +1 -1
- package/dist/index.js +269 -423
- package/dist/init.js +106 -255
- package/dist/version.js +1 -1
- package/package.json +12 -14
- package/dist/chunk-XEXYGDQV.js +0 -137
- package/dist/chunk-YK4LF7AM.js +0 -6
package/dist/chunk-XEXYGDQV.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
// src/config.ts
|
|
2
|
-
import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from "fs";
|
|
3
|
-
import { homedir } from "os";
|
|
4
|
-
import { dirname, join } from "path";
|
|
5
|
-
var SECURE_FILE_MODE = 384;
|
|
6
|
-
var SECURE_DIR_MODE = 448;
|
|
7
|
-
function resolveXdgConfigPath() {
|
|
8
|
-
const xdg = process.env["XDG_CONFIG_HOME"];
|
|
9
|
-
if (xdg && xdg.length > 0) {
|
|
10
|
-
return join(xdg, "mushi", "config.json");
|
|
11
|
-
}
|
|
12
|
-
if (process.platform === "win32") {
|
|
13
|
-
const appData = process.env["APPDATA"];
|
|
14
|
-
if (appData && appData.length > 0) {
|
|
15
|
-
return join(appData, "mushi", "config.json");
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return join(homedir(), ".config", "mushi", "config.json");
|
|
19
|
-
}
|
|
20
|
-
var LEGACY_CONFIG_PATH = join(homedir(), ".mushirc");
|
|
21
|
-
var CONFIG_PATH = resolveXdgConfigPath();
|
|
22
|
-
function loadConfig(path = CONFIG_PATH) {
|
|
23
|
-
let file = {};
|
|
24
|
-
if (existsSync(path)) {
|
|
25
|
-
tightenPermissions(path);
|
|
26
|
-
try {
|
|
27
|
-
file = JSON.parse(readFileSync(path, "utf-8"));
|
|
28
|
-
} catch {
|
|
29
|
-
}
|
|
30
|
-
} else if (path === CONFIG_PATH && existsSync(LEGACY_CONFIG_PATH)) {
|
|
31
|
-
file = migrateLegacyConfig() ?? {};
|
|
32
|
-
}
|
|
33
|
-
const endpointFromEnv = process.env["MUSHI_API_ENDPOINT"] ?? process.env["MUSHI_ENDPOINT"] ?? void 0;
|
|
34
|
-
const fromEnv = {
|
|
35
|
-
...process.env["MUSHI_API_KEY"] ? { apiKey: process.env["MUSHI_API_KEY"] } : {},
|
|
36
|
-
...process.env["MUSHI_PROJECT_ID"] ? { projectId: process.env["MUSHI_PROJECT_ID"] } : {},
|
|
37
|
-
...endpointFromEnv ? { endpoint: endpointFromEnv } : {},
|
|
38
|
-
...process.env["MUSHI_CONSOLE_URL"] ? { consoleUrl: process.env["MUSHI_CONSOLE_URL"].trim() } : {}
|
|
39
|
-
};
|
|
40
|
-
return { ...file, ...fromEnv };
|
|
41
|
-
}
|
|
42
|
-
function saveConfig(config, path = CONFIG_PATH) {
|
|
43
|
-
const dir = dirname(path);
|
|
44
|
-
if (!existsSync(dir)) {
|
|
45
|
-
mkdirSync(dir, { recursive: true, mode: SECURE_DIR_MODE });
|
|
46
|
-
} else {
|
|
47
|
-
tightenDirPermissions(dir);
|
|
48
|
-
}
|
|
49
|
-
writeFileSync(path, JSON.stringify(config, null, 2), { mode: SECURE_FILE_MODE });
|
|
50
|
-
tightenPermissions(path);
|
|
51
|
-
}
|
|
52
|
-
function migrateLegacyConfig(legacyPath = LEGACY_CONFIG_PATH, destPath = CONFIG_PATH) {
|
|
53
|
-
if (!existsSync(legacyPath)) return null;
|
|
54
|
-
let parsed;
|
|
55
|
-
try {
|
|
56
|
-
parsed = JSON.parse(readFileSync(legacyPath, "utf-8"));
|
|
57
|
-
} catch {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
const dir = dirname(destPath);
|
|
61
|
-
if (!existsSync(dir)) {
|
|
62
|
-
mkdirSync(dir, { recursive: true, mode: SECURE_DIR_MODE });
|
|
63
|
-
}
|
|
64
|
-
try {
|
|
65
|
-
renameSync(legacyPath, destPath);
|
|
66
|
-
} catch {
|
|
67
|
-
writeFileSync(destPath, JSON.stringify(parsed, null, 2), { mode: SECURE_FILE_MODE });
|
|
68
|
-
try {
|
|
69
|
-
unlinkSync(legacyPath);
|
|
70
|
-
} catch {
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
tightenPermissions(destPath);
|
|
74
|
-
tightenDirPermissions(dir);
|
|
75
|
-
return parsed;
|
|
76
|
-
}
|
|
77
|
-
function tightenPermissions(path) {
|
|
78
|
-
if (process.platform === "win32") return;
|
|
79
|
-
try {
|
|
80
|
-
const current = statSync(path).mode & 511;
|
|
81
|
-
if (current !== SECURE_FILE_MODE) chmodSync(path, SECURE_FILE_MODE);
|
|
82
|
-
} catch {
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
function tightenDirPermissions(path) {
|
|
86
|
-
if (process.platform === "win32") return;
|
|
87
|
-
try {
|
|
88
|
-
const current = statSync(path).mode & 511;
|
|
89
|
-
if (current !== SECURE_DIR_MODE) chmodSync(path, SECURE_DIR_MODE);
|
|
90
|
-
} catch {
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// src/endpoint.ts
|
|
95
|
-
var TEST_REPORT_TIMEOUT_MS = 1e4;
|
|
96
|
-
var TEST_REPORT_FETCH_TIMEOUT_MS = TEST_REPORT_TIMEOUT_MS;
|
|
97
|
-
var CLOUD_API_ENDPOINT = "https://dxptnwrhwsqckaftyymj.supabase.co/functions/v1/api";
|
|
98
|
-
function resolveCloudEndpoint(explicit) {
|
|
99
|
-
if (explicit?.trim()) return explicit.trim();
|
|
100
|
-
const fromEnv = process.env.MUSHI_API_ENDPOINT?.trim();
|
|
101
|
-
if (fromEnv) return fromEnv;
|
|
102
|
-
return CLOUD_API_ENDPOINT;
|
|
103
|
-
}
|
|
104
|
-
function assertEndpoint(url) {
|
|
105
|
-
let parsed;
|
|
106
|
-
try {
|
|
107
|
-
parsed = new URL(url);
|
|
108
|
-
} catch {
|
|
109
|
-
throw new Error(`Invalid endpoint URL: ${url}`);
|
|
110
|
-
}
|
|
111
|
-
const host = parsed.hostname;
|
|
112
|
-
const isLocal = host === "localhost" || host === "127.0.0.1" || host === "::1" || host.endsWith(".local");
|
|
113
|
-
if (parsed.protocol !== "https:" && !isLocal) {
|
|
114
|
-
throw new Error(`Endpoint must use https:// (got ${parsed.protocol}//${host}).`);
|
|
115
|
-
}
|
|
116
|
-
return normalizeEndpoint(parsed.origin + parsed.pathname);
|
|
117
|
-
}
|
|
118
|
-
function normalizeEndpoint(url) {
|
|
119
|
-
if (!url) {
|
|
120
|
-
throw new Error(
|
|
121
|
-
"No API endpoint configured. Run `mushi init` or set MUSHI_API_ENDPOINT. Set endpoint to your Supabase edge function URL, e.g. https://xyz.supabase.co/functions/v1/api"
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
let end = url.length;
|
|
125
|
-
while (end > 0 && url.charCodeAt(end - 1) === 47) end--;
|
|
126
|
-
return url.slice(0, end);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export {
|
|
130
|
-
CONFIG_PATH,
|
|
131
|
-
loadConfig,
|
|
132
|
-
saveConfig,
|
|
133
|
-
TEST_REPORT_FETCH_TIMEOUT_MS,
|
|
134
|
-
resolveCloudEndpoint,
|
|
135
|
-
assertEndpoint,
|
|
136
|
-
normalizeEndpoint
|
|
137
|
-
};
|