@glasstrace/sdk 0.7.0 → 0.7.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/dist/index.cjs +81 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +82 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -15850,12 +15850,14 @@ async function saveCachedConfig(response, projectRoot) {
|
|
|
15850
15850
|
const dirPath = (0, import_node_path2.join)(root, GLASSTRACE_DIR2);
|
|
15851
15851
|
const configPath = (0, import_node_path2.join)(dirPath, CONFIG_FILE);
|
|
15852
15852
|
try {
|
|
15853
|
-
await (0, import_promises2.mkdir)(dirPath, { recursive: true });
|
|
15853
|
+
await (0, import_promises2.mkdir)(dirPath, { recursive: true, mode: 448 });
|
|
15854
|
+
await (0, import_promises2.chmod)(dirPath, 448);
|
|
15854
15855
|
const cached2 = {
|
|
15855
15856
|
response,
|
|
15856
15857
|
cachedAt: Date.now()
|
|
15857
15858
|
};
|
|
15858
|
-
await (0, import_promises2.writeFile)(configPath, JSON.stringify(cached2), "utf-8");
|
|
15859
|
+
await (0, import_promises2.writeFile)(configPath, JSON.stringify(cached2), { encoding: "utf-8", mode: 384 });
|
|
15860
|
+
await (0, import_promises2.chmod)(configPath, 384);
|
|
15859
15861
|
} catch (err) {
|
|
15860
15862
|
console.warn(
|
|
15861
15863
|
`[glasstrace] Failed to cache config to ${configPath}: ${err instanceof Error ? err.message : String(err)}`
|
|
@@ -15908,6 +15910,78 @@ async function sendInitRequest(config2, anonKey, sdkVersion, importGraph, health
|
|
|
15908
15910
|
const body = await response.json();
|
|
15909
15911
|
return SdkInitResponseSchema.parse(body);
|
|
15910
15912
|
}
|
|
15913
|
+
async function writeClaimedKey(newApiKey, projectRoot) {
|
|
15914
|
+
const root = projectRoot ?? process.cwd();
|
|
15915
|
+
const envLocalPath = (0, import_node_path2.join)(root, ".env.local");
|
|
15916
|
+
let envLocalWritten = false;
|
|
15917
|
+
try {
|
|
15918
|
+
let content;
|
|
15919
|
+
try {
|
|
15920
|
+
content = await (0, import_promises2.readFile)(envLocalPath, "utf-8");
|
|
15921
|
+
if (/^GLASSTRACE_API_KEY=.*/m.test(content)) {
|
|
15922
|
+
content = content.replace(
|
|
15923
|
+
/^GLASSTRACE_API_KEY=.*$/gm,
|
|
15924
|
+
`GLASSTRACE_API_KEY=${newApiKey}`
|
|
15925
|
+
);
|
|
15926
|
+
} else {
|
|
15927
|
+
if (content.length > 0 && !content.endsWith("\n")) {
|
|
15928
|
+
content += "\n";
|
|
15929
|
+
}
|
|
15930
|
+
content += `GLASSTRACE_API_KEY=${newApiKey}
|
|
15931
|
+
`;
|
|
15932
|
+
}
|
|
15933
|
+
} catch (readErr) {
|
|
15934
|
+
const code = readErr instanceof Error ? readErr.code : void 0;
|
|
15935
|
+
if (code !== "ENOENT") {
|
|
15936
|
+
throw readErr;
|
|
15937
|
+
}
|
|
15938
|
+
content = `GLASSTRACE_API_KEY=${newApiKey}
|
|
15939
|
+
`;
|
|
15940
|
+
}
|
|
15941
|
+
await (0, import_promises2.writeFile)(envLocalPath, content, { encoding: "utf-8", mode: 384 });
|
|
15942
|
+
await (0, import_promises2.chmod)(envLocalPath, 384);
|
|
15943
|
+
envLocalWritten = true;
|
|
15944
|
+
} catch {
|
|
15945
|
+
}
|
|
15946
|
+
if (envLocalWritten) {
|
|
15947
|
+
try {
|
|
15948
|
+
process.stderr.write(
|
|
15949
|
+
"[glasstrace] Account claimed! API key written to .env.local. Restart your dev server to use it.\n"
|
|
15950
|
+
);
|
|
15951
|
+
} catch {
|
|
15952
|
+
}
|
|
15953
|
+
return;
|
|
15954
|
+
}
|
|
15955
|
+
let claimedKeyWritten = false;
|
|
15956
|
+
try {
|
|
15957
|
+
const dirPath = (0, import_node_path2.join)(root, GLASSTRACE_DIR2);
|
|
15958
|
+
await (0, import_promises2.mkdir)(dirPath, { recursive: true, mode: 448 });
|
|
15959
|
+
await (0, import_promises2.chmod)(dirPath, 448);
|
|
15960
|
+
const claimedKeyPath = (0, import_node_path2.join)(dirPath, "claimed-key");
|
|
15961
|
+
await (0, import_promises2.writeFile)(claimedKeyPath, newApiKey, {
|
|
15962
|
+
encoding: "utf-8",
|
|
15963
|
+
mode: 384
|
|
15964
|
+
});
|
|
15965
|
+
await (0, import_promises2.chmod)(claimedKeyPath, 384);
|
|
15966
|
+
claimedKeyWritten = true;
|
|
15967
|
+
} catch {
|
|
15968
|
+
}
|
|
15969
|
+
if (claimedKeyWritten) {
|
|
15970
|
+
try {
|
|
15971
|
+
process.stderr.write(
|
|
15972
|
+
"[glasstrace] Account claimed! API key written to .glasstrace/claimed-key. Copy it to your .env.local file.\n"
|
|
15973
|
+
);
|
|
15974
|
+
} catch {
|
|
15975
|
+
}
|
|
15976
|
+
return;
|
|
15977
|
+
}
|
|
15978
|
+
try {
|
|
15979
|
+
process.stderr.write(
|
|
15980
|
+
"[glasstrace] Account claimed but could not write key to disk. Visit your dashboard settings to rotate and retrieve a new API key.\n"
|
|
15981
|
+
);
|
|
15982
|
+
} catch {
|
|
15983
|
+
}
|
|
15984
|
+
}
|
|
15911
15985
|
async function performInit(config2, anonKey, sdkVersion) {
|
|
15912
15986
|
if (rateLimitBackoff) {
|
|
15913
15987
|
rateLimitBackoff = false;
|
|
@@ -15936,14 +16010,8 @@ async function performInit(config2, anonKey, sdkVersion) {
|
|
|
15936
16010
|
await saveCachedConfig(result);
|
|
15937
16011
|
if (result.claimResult) {
|
|
15938
16012
|
try {
|
|
15939
|
-
|
|
15940
|
-
|
|
15941
|
-
`
|
|
15942
|
-
);
|
|
15943
|
-
} catch (logErr) {
|
|
15944
|
-
console.warn(
|
|
15945
|
-
`[glasstrace] Failed to write claim migration message: ${logErr instanceof Error ? logErr.message : String(logErr)}`
|
|
15946
|
-
);
|
|
16013
|
+
await writeClaimedKey(result.claimResult.newApiKey);
|
|
16014
|
+
} catch {
|
|
15947
16015
|
}
|
|
15948
16016
|
return { claimResult: result.claimResult };
|
|
15949
16017
|
}
|
|
@@ -19226,7 +19294,7 @@ function registerGlasstrace(options) {
|
|
|
19226
19294
|
if (config2.verbose) {
|
|
19227
19295
|
console.info("[glasstrace] Background init firing.");
|
|
19228
19296
|
}
|
|
19229
|
-
const initResult = await performInit(config2, anonKey, "0.7.
|
|
19297
|
+
const initResult = await performInit(config2, anonKey, "0.7.1");
|
|
19230
19298
|
if (initResult?.claimResult) {
|
|
19231
19299
|
setResolvedApiKey(initResult.claimResult.newApiKey);
|
|
19232
19300
|
notifyApiKeyResolved();
|
|
@@ -19250,7 +19318,7 @@ function registerGlasstrace(options) {
|
|
|
19250
19318
|
if (config2.verbose) {
|
|
19251
19319
|
console.info("[glasstrace] Background init firing.");
|
|
19252
19320
|
}
|
|
19253
|
-
const initResult = await performInit(config2, anonKey, "0.7.
|
|
19321
|
+
const initResult = await performInit(config2, anonKey, "0.7.1");
|
|
19254
19322
|
if (initResult?.claimResult) {
|
|
19255
19323
|
setResolvedApiKey(initResult.claimResult.newApiKey);
|
|
19256
19324
|
notifyApiKeyResolved();
|
|
@@ -19276,7 +19344,7 @@ function registerGlasstrace(options) {
|
|
|
19276
19344
|
if (config2.verbose) {
|
|
19277
19345
|
console.info("[glasstrace] Background init firing.");
|
|
19278
19346
|
}
|
|
19279
|
-
await performInit(config2, anonKeyForInit, "0.7.
|
|
19347
|
+
await performInit(config2, anonKeyForInit, "0.7.1");
|
|
19280
19348
|
maybeInstallConsoleCapture();
|
|
19281
19349
|
} catch (err) {
|
|
19282
19350
|
console.warn(
|