@glasstrace/sdk 0.11.0 → 0.12.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/dist/adapters/drizzle.js +1 -1
- package/dist/{chunk-2JUH3VGJ.js → chunk-6GRNJ722.js} +38 -17
- package/dist/chunk-6GRNJ722.js.map +1 -0
- package/dist/chunk-IPGOKORJ.js +580 -0
- package/dist/chunk-IPGOKORJ.js.map +1 -0
- package/dist/{chunk-M7RDFOFR.js → chunk-LW7DPKBA.js} +2 -2
- package/dist/{chunk-SLSWEQCC.js → chunk-MSMOH6IH.js} +108 -38
- package/dist/chunk-MSMOH6IH.js.map +1 -0
- package/dist/chunk-NSBPE2FW.js +17 -0
- package/dist/{chunk-D3JC3LAK.js → chunk-OKIP4SRG.js} +2 -2
- package/dist/cli/init.cjs +454 -329
- package/dist/cli/init.cjs.map +1 -1
- package/dist/cli/init.d.cts +25 -1
- package/dist/cli/init.d.ts +25 -1
- package/dist/cli/init.js +114 -4
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/mcp-add.cjs +60 -46
- package/dist/cli/mcp-add.cjs.map +1 -1
- package/dist/cli/mcp-add.js +3 -3
- package/dist/cli/uninit.js +15 -564
- package/dist/cli/uninit.js.map +1 -1
- package/dist/{esm-POMEQPKL.js → esm-KBPHCVB4.js} +2 -2
- package/dist/{getMachineId-bsd-TC3JSTY5.js → getMachineId-bsd-345PYXFX.js} +2 -2
- package/dist/{getMachineId-darwin-2SUKQCE6.js → getMachineId-darwin-5L2D25AD.js} +2 -2
- package/dist/{getMachineId-linux-PNAFHLXH.js → getMachineId-linux-KJR4P5HN.js} +2 -2
- package/dist/{getMachineId-unsupported-L2MNYW3W.js → getMachineId-unsupported-NDNXDYDY.js} +2 -2
- package/dist/{getMachineId-win-D6D42WOQ.js → getMachineId-win-T7PJNJXG.js} +2 -2
- package/dist/index.cjs +297 -154
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -10
- package/dist/index.d.ts +51 -10
- package/dist/index.js +133 -78
- package/dist/index.js.map +1 -1
- package/dist/{source-map-uploader-OFEM54UE.js → source-map-uploader-ZFCYOURS.js} +6 -4
- package/package.json +1 -1
- package/dist/chunk-2JUH3VGJ.js.map +0 -1
- package/dist/chunk-PZ5AY32C.js +0 -10
- package/dist/chunk-SLSWEQCC.js.map +0 -1
- /package/dist/{chunk-M7RDFOFR.js.map → chunk-LW7DPKBA.js.map} +0 -0
- /package/dist/{chunk-PZ5AY32C.js.map → chunk-NSBPE2FW.js.map} +0 -0
- /package/dist/{chunk-D3JC3LAK.js.map → chunk-OKIP4SRG.js.map} +0 -0
- /package/dist/{esm-POMEQPKL.js.map → esm-KBPHCVB4.js.map} +0 -0
- /package/dist/{getMachineId-bsd-TC3JSTY5.js.map → getMachineId-bsd-345PYXFX.js.map} +0 -0
- /package/dist/{getMachineId-darwin-2SUKQCE6.js.map → getMachineId-darwin-5L2D25AD.js.map} +0 -0
- /package/dist/{getMachineId-linux-PNAFHLXH.js.map → getMachineId-linux-KJR4P5HN.js.map} +0 -0
- /package/dist/{getMachineId-unsupported-L2MNYW3W.js.map → getMachineId-unsupported-NDNXDYDY.js.map} +0 -0
- /package/dist/{getMachineId-win-D6D42WOQ.js.map → getMachineId-win-T7PJNJXG.js.map} +0 -0
- /package/dist/{source-map-uploader-OFEM54UE.js.map → source-map-uploader-ZFCYOURS.js.map} +0 -0
package/dist/adapters/drizzle.js
CHANGED
|
@@ -1,24 +1,40 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AnonApiKeySchema,
|
|
3
3
|
createAnonApiKey
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-OKIP4SRG.js";
|
|
5
5
|
|
|
6
6
|
// src/anon-key.ts
|
|
7
|
-
import { readFile, writeFile, mkdir, chmod } from "fs/promises";
|
|
8
|
-
import { join } from "path";
|
|
9
7
|
var GLASSTRACE_DIR = ".glasstrace";
|
|
10
8
|
var ANON_KEY_FILE = "anon_key";
|
|
9
|
+
var fsPathCache;
|
|
10
|
+
async function loadFsPath() {
|
|
11
|
+
if (fsPathCache !== void 0) return fsPathCache;
|
|
12
|
+
try {
|
|
13
|
+
const [fs, path] = await Promise.all([
|
|
14
|
+
import("fs/promises"),
|
|
15
|
+
import("path")
|
|
16
|
+
]);
|
|
17
|
+
fsPathCache = { fs, path };
|
|
18
|
+
return fsPathCache;
|
|
19
|
+
} catch {
|
|
20
|
+
fsPathCache = null;
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
11
24
|
var ephemeralKeyCache = /* @__PURE__ */ new Map();
|
|
12
25
|
async function readAnonKey(projectRoot) {
|
|
13
26
|
const root = projectRoot ?? process.cwd();
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
27
|
+
const modules = await loadFsPath();
|
|
28
|
+
if (modules) {
|
|
29
|
+
const keyPath = modules.path.join(root, GLASSTRACE_DIR, ANON_KEY_FILE);
|
|
30
|
+
try {
|
|
31
|
+
const content = await modules.fs.readFile(keyPath, "utf-8");
|
|
32
|
+
const result = AnonApiKeySchema.safeParse(content);
|
|
33
|
+
if (result.success) {
|
|
34
|
+
return result.data;
|
|
35
|
+
}
|
|
36
|
+
} catch {
|
|
20
37
|
}
|
|
21
|
-
} catch {
|
|
22
38
|
}
|
|
23
39
|
const cached = ephemeralKeyCache.get(root);
|
|
24
40
|
if (cached !== void 0) {
|
|
@@ -28,8 +44,6 @@ async function readAnonKey(projectRoot) {
|
|
|
28
44
|
}
|
|
29
45
|
async function getOrCreateAnonKey(projectRoot) {
|
|
30
46
|
const root = projectRoot ?? process.cwd();
|
|
31
|
-
const dirPath = join(root, GLASSTRACE_DIR);
|
|
32
|
-
const keyPath = join(dirPath, ANON_KEY_FILE);
|
|
33
47
|
const existingKey = await readAnonKey(root);
|
|
34
48
|
if (existingKey !== null) {
|
|
35
49
|
return existingKey;
|
|
@@ -39,9 +53,16 @@ async function getOrCreateAnonKey(projectRoot) {
|
|
|
39
53
|
return cached;
|
|
40
54
|
}
|
|
41
55
|
const newKey = createAnonApiKey();
|
|
56
|
+
const modules = await loadFsPath();
|
|
57
|
+
if (!modules) {
|
|
58
|
+
ephemeralKeyCache.set(root, newKey);
|
|
59
|
+
return newKey;
|
|
60
|
+
}
|
|
61
|
+
const dirPath = modules.path.join(root, GLASSTRACE_DIR);
|
|
62
|
+
const keyPath = modules.path.join(dirPath, ANON_KEY_FILE);
|
|
42
63
|
try {
|
|
43
|
-
await mkdir(dirPath, { recursive: true, mode: 448 });
|
|
44
|
-
await writeFile(keyPath, newKey, { flag: "wx", mode: 384 });
|
|
64
|
+
await modules.fs.mkdir(dirPath, { recursive: true, mode: 448 });
|
|
65
|
+
await modules.fs.writeFile(keyPath, newKey, { flag: "wx", mode: 384 });
|
|
45
66
|
return newKey;
|
|
46
67
|
} catch (err) {
|
|
47
68
|
const code = err.code;
|
|
@@ -56,8 +77,8 @@ async function getOrCreateAnonKey(projectRoot) {
|
|
|
56
77
|
}
|
|
57
78
|
}
|
|
58
79
|
try {
|
|
59
|
-
await writeFile(keyPath, newKey, { mode: 384 });
|
|
60
|
-
await chmod(keyPath, 384);
|
|
80
|
+
await modules.fs.writeFile(keyPath, newKey, { mode: 384 });
|
|
81
|
+
await modules.fs.chmod(keyPath, 384);
|
|
61
82
|
return newKey;
|
|
62
83
|
} catch {
|
|
63
84
|
}
|
|
@@ -74,4 +95,4 @@ export {
|
|
|
74
95
|
readAnonKey,
|
|
75
96
|
getOrCreateAnonKey
|
|
76
97
|
};
|
|
77
|
-
//# sourceMappingURL=chunk-
|
|
98
|
+
//# sourceMappingURL=chunk-6GRNJ722.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/anon-key.ts"],"sourcesContent":["import { AnonApiKeySchema, createAnonApiKey } from \"@glasstrace/protocol\";\nimport type { AnonApiKey } from \"@glasstrace/protocol\";\n\nconst GLASSTRACE_DIR = \".glasstrace\";\nconst ANON_KEY_FILE = \"anon_key\";\n\n/**\n * Lazily imports `node:fs/promises` and `node:path`. Returns `null` if\n * the modules are unavailable (non-Node environments). The result is\n * cached after first resolution.\n */\nlet fsPathCache: { fs: typeof import(\"node:fs/promises\"); path: typeof import(\"node:path\") } | null | undefined;\n\nasync function loadFsPath(): Promise<{ fs: typeof import(\"node:fs/promises\"); path: typeof import(\"node:path\") } | null> {\n if (fsPathCache !== undefined) return fsPathCache;\n try {\n const [fs, path] = await Promise.all([\n import(\"node:fs/promises\"),\n import(\"node:path\"),\n ]);\n fsPathCache = { fs, path };\n return fsPathCache;\n } catch {\n fsPathCache = null;\n return null;\n }\n}\n\n/**\n * In-memory cache for ephemeral keys when filesystem persistence fails.\n * Keyed by resolved project root to support multiple roots in tests.\n */\nconst ephemeralKeyCache = new Map<string, AnonApiKey>();\n\n/**\n * Reads an existing anonymous key from the filesystem.\n * Returns the key if valid, or null if:\n * - The file does not exist\n * - The file content is invalid\n * - An I/O error occurs\n * - `node:fs` is unavailable (non-Node environment)\n */\nexport async function readAnonKey(projectRoot?: string): Promise<AnonApiKey | null> {\n const root = projectRoot ?? process.cwd();\n\n const modules = await loadFsPath();\n if (modules) {\n const keyPath = modules.path.join(root, GLASSTRACE_DIR, ANON_KEY_FILE);\n try {\n const content = await modules.fs.readFile(keyPath, \"utf-8\");\n const result = AnonApiKeySchema.safeParse(content);\n if (result.success) {\n return result.data;\n }\n } catch {\n // Fall through to check ephemeral cache\n }\n }\n\n // Check in-memory cache (used when filesystem persistence failed\n // or when node:fs is unavailable)\n const cached = ephemeralKeyCache.get(root);\n if (cached !== undefined) {\n return cached;\n }\n\n return null;\n}\n\n/**\n * Gets an existing anonymous key from the filesystem, or creates a new one.\n *\n * - If file exists and contains a valid key, returns it\n * - If file does not exist or content is invalid, generates a new key via createAnonApiKey()\n * - Writes the new key to `.glasstrace/anon_key`, creating the directory if needed\n * - On file write failure: logs a warning, caches an ephemeral in-memory key so\n * repeated calls in the same process return the same key\n * - In non-Node environments: returns an ephemeral in-memory key\n */\nexport async function getOrCreateAnonKey(projectRoot?: string): Promise<AnonApiKey> {\n const root = projectRoot ?? process.cwd();\n\n // Try reading existing key from filesystem\n const existingKey = await readAnonKey(root);\n if (existingKey !== null) {\n return existingKey;\n }\n\n // Check in-memory cache (used when filesystem is unavailable)\n const cached = ephemeralKeyCache.get(root);\n if (cached !== undefined) {\n return cached;\n }\n\n // Generate a new key\n const newKey = createAnonApiKey();\n\n // Attempt filesystem persistence (only in Node.js environments)\n const modules = await loadFsPath();\n if (!modules) {\n // No filesystem access — cache in memory\n ephemeralKeyCache.set(root, newKey);\n return newKey;\n }\n\n const dirPath = modules.path.join(root, GLASSTRACE_DIR);\n const keyPath = modules.path.join(dirPath, ANON_KEY_FILE);\n\n // Persist to filesystem using atomic create-or-fail (O_CREAT | O_EXCL)\n // to prevent TOCTOU races where concurrent cold starts both generate keys.\n try {\n await modules.fs.mkdir(dirPath, { recursive: true, mode: 0o700 });\n await modules.fs.writeFile(keyPath, newKey, { flag: \"wx\", mode: 0o600 });\n return newKey;\n } catch (err) {\n const code = (err as NodeJS.ErrnoException).code;\n if (code === \"EEXIST\") {\n // Another process won the race. Retry reading their key with\n // short delays — the winner's writeFile is atomic for small\n // payloads but the filesystem may not have flushed yet.\n for (let attempt = 0; attempt < 3; attempt++) {\n const winnerKey = await readAnonKey(root);\n if (winnerKey !== null) {\n return winnerKey;\n }\n // Short delay before next retry (50ms), skip after final attempt\n if (attempt < 2) {\n await new Promise((resolve) => setTimeout(resolve, 50));\n }\n }\n // All retries exhausted — overwrite as last resort.\n // Use explicit chmod after overwrite since writeFile mode only\n // applies on creation on some platforms.\n try {\n await modules.fs.writeFile(keyPath, newKey, { mode: 0o600 });\n await modules.fs.chmod(keyPath, 0o600);\n return newKey;\n } catch {\n // Overwrite failed — fall through to ephemeral cache\n }\n }\n\n // Non-EEXIST error (EACCES, ENOTDIR, etc.) — cache in memory so\n // repeated calls get the same ephemeral key within this process.\n ephemeralKeyCache.set(root, newKey);\n console.warn(\n `[glasstrace] Failed to persist anonymous key to ${keyPath}: ${err instanceof Error ? err.message : String(err)}. Using ephemeral key.`,\n );\n return newKey;\n }\n}\n"],"mappings":";;;;;;AAGA,IAAM,iBAAiB;AACvB,IAAM,gBAAgB;AAOtB,IAAI;AAEJ,eAAe,aAA0G;AACvH,MAAI,gBAAgB,OAAW,QAAO;AACtC,MAAI;AACF,UAAM,CAAC,IAAI,IAAI,IAAI,MAAM,QAAQ,IAAI;AAAA,MACnC,OAAO,aAAkB;AAAA,MACzB,OAAO,MAAW;AAAA,IACpB,CAAC;AACD,kBAAc,EAAE,IAAI,KAAK;AACzB,WAAO;AAAA,EACT,QAAQ;AACN,kBAAc;AACd,WAAO;AAAA,EACT;AACF;AAMA,IAAM,oBAAoB,oBAAI,IAAwB;AAUtD,eAAsB,YAAY,aAAkD;AAClF,QAAM,OAAO,eAAe,QAAQ,IAAI;AAExC,QAAM,UAAU,MAAM,WAAW;AACjC,MAAI,SAAS;AACX,UAAM,UAAU,QAAQ,KAAK,KAAK,MAAM,gBAAgB,aAAa;AACrE,QAAI;AACF,YAAM,UAAU,MAAM,QAAQ,GAAG,SAAS,SAAS,OAAO;AAC1D,YAAM,SAAS,iBAAiB,UAAU,OAAO;AACjD,UAAI,OAAO,SAAS;AAClB,eAAO,OAAO;AAAA,MAChB;AAAA,IACF,QAAQ;AAAA,IAER;AAAA,EACF;AAIA,QAAM,SAAS,kBAAkB,IAAI,IAAI;AACzC,MAAI,WAAW,QAAW;AACxB,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAYA,eAAsB,mBAAmB,aAA2C;AAClF,QAAM,OAAO,eAAe,QAAQ,IAAI;AAGxC,QAAM,cAAc,MAAM,YAAY,IAAI;AAC1C,MAAI,gBAAgB,MAAM;AACxB,WAAO;AAAA,EACT;AAGA,QAAM,SAAS,kBAAkB,IAAI,IAAI;AACzC,MAAI,WAAW,QAAW;AACxB,WAAO;AAAA,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