@kenkaiiii/gg-pixel 4.3.84 → 4.3.86
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/cli.js +59 -49
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +59 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +59 -49
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -491,8 +491,8 @@ async function install(opts = {}) {
|
|
|
491
491
|
const existingKey = readEnvKey(envFilePath, "GG_PIXEL_KEY");
|
|
492
492
|
let created;
|
|
493
493
|
let reused = false;
|
|
494
|
-
if (existing && existingKey) {
|
|
495
|
-
created = { id: existing.id, key: existingKey };
|
|
494
|
+
if (existing && existing.secret && existingKey) {
|
|
495
|
+
created = { id: existing.id, key: existingKey, secret: existing.secret };
|
|
496
496
|
reused = true;
|
|
497
497
|
} else {
|
|
498
498
|
created = await createProject(fetchFn, ingestUrl, projectName);
|
|
@@ -509,10 +509,11 @@ async function install(opts = {}) {
|
|
|
509
509
|
if (kind !== "browser" && kind !== "tauri") {
|
|
510
510
|
writeEnvKey(envFilePath, "GG_PIXEL_KEY", created.key);
|
|
511
511
|
}
|
|
512
|
-
writeProjectsMapping(projectsJsonPath, created.id, projectName, nodeRoot);
|
|
512
|
+
writeProjectsMapping(projectsJsonPath, created.id, projectName, nodeRoot, created.secret);
|
|
513
513
|
return {
|
|
514
514
|
projectId: created.id,
|
|
515
515
|
projectKey: created.key,
|
|
516
|
+
projectSecret: created.secret,
|
|
516
517
|
projectName,
|
|
517
518
|
projectKind: kind,
|
|
518
519
|
initFilePath: wired.primaryInitPath,
|
|
@@ -569,8 +570,10 @@ async function createProject(fetchFn, ingestUrl, name) {
|
|
|
569
570
|
throw new Error(`POST /api/projects failed: ${res.status} ${await safeText(res)}`);
|
|
570
571
|
}
|
|
571
572
|
const body = await res.json();
|
|
572
|
-
if (!body.id || !body.key
|
|
573
|
-
|
|
573
|
+
if (!body.id || !body.key || !body.secret) {
|
|
574
|
+
throw new Error("response missing id/key/secret");
|
|
575
|
+
}
|
|
576
|
+
return { id: body.id, key: body.key, secret: body.secret };
|
|
574
577
|
}
|
|
575
578
|
async function safeText(r) {
|
|
576
579
|
try {
|
|
@@ -818,11 +821,11 @@ function wireNextjs({ projectRoot, projectKey, ingestUrl }) {
|
|
|
818
821
|
}
|
|
819
822
|
function writeNextInstrumentation(path, ingestUrl, projectKey) {
|
|
820
823
|
const existing = (0, import_node_fs3.existsSync)(path) ? (0, import_node_fs3.readFileSync)(path, "utf8") : "";
|
|
821
|
-
|
|
822
|
-
const
|
|
823
|
-
(0, import_node_fs3.writeFileSync)(path,
|
|
824
|
+
const block = nextInstrumentationBlock(ingestUrl, projectKey);
|
|
825
|
+
const next = upsertPixelBlock(existing, block);
|
|
826
|
+
if (next !== existing) (0, import_node_fs3.writeFileSync)(path, next, "utf8");
|
|
824
827
|
}
|
|
825
|
-
function
|
|
828
|
+
function nextInstrumentationBlock(ingestUrl, projectKey) {
|
|
826
829
|
const fallback = projectKey ? ` ?? ${JSON.stringify(projectKey)}` : "";
|
|
827
830
|
return `// Next.js auto-loads this file on server start. Pixel hooks the
|
|
828
831
|
// uncaughtExceptionMonitor + unhandledRejection events for API routes,
|
|
@@ -835,20 +838,7 @@ export async function register() {
|
|
|
835
838
|
sink: { kind: "http", ingestUrl: ${JSON.stringify(`${ingestUrl}/ingest`)} },
|
|
836
839
|
});
|
|
837
840
|
}
|
|
838
|
-
}
|
|
839
|
-
`;
|
|
840
|
-
}
|
|
841
|
-
function nextInstrumentationAppend(ingestUrl, projectKey) {
|
|
842
|
-
const fallback = projectKey ? ` ?? ${JSON.stringify(projectKey)}` : "";
|
|
843
|
-
return `// gg-pixel: server-side error tracking
|
|
844
|
-
import { initPixel } from "@kenkaiiii/gg-pixel";
|
|
845
|
-
if (typeof process !== "undefined" && process.env.NEXT_RUNTIME === "nodejs") {
|
|
846
|
-
initPixel({
|
|
847
|
-
projectKey: process.env.GG_PIXEL_KEY${fallback},
|
|
848
|
-
sink: { kind: "http", ingestUrl: ${JSON.stringify(`${ingestUrl}/ingest`)} },
|
|
849
|
-
});
|
|
850
|
-
}
|
|
851
|
-
`;
|
|
841
|
+
}`;
|
|
852
842
|
}
|
|
853
843
|
function findNextLayout(projectRoot) {
|
|
854
844
|
const candidates = [
|
|
@@ -981,25 +971,21 @@ function wireSveltekit({ projectRoot, projectKey, ingestUrl }) {
|
|
|
981
971
|
const serverPath = (0, import_node_path2.join)(projectRoot, "src/hooks.server.ts");
|
|
982
972
|
const clientPath = (0, import_node_path2.join)(projectRoot, "src/hooks.client.ts");
|
|
983
973
|
if (!(0, import_node_fs3.existsSync)((0, import_node_path2.dirname)(serverPath))) (0, import_node_fs3.mkdirSync)((0, import_node_path2.dirname)(serverPath), { recursive: true });
|
|
984
|
-
|
|
974
|
+
upsertPixelBlockInFile(
|
|
985
975
|
serverPath,
|
|
986
976
|
`import { initPixel } from "@kenkaiiii/gg-pixel";
|
|
987
977
|
initPixel({
|
|
988
978
|
projectKey: process.env.GG_PIXEL_KEY ?? ${JSON.stringify(projectKey)},
|
|
989
979
|
sink: { kind: "http", ingestUrl: ${JSON.stringify(`${ingestUrl}/ingest`)} },
|
|
990
|
-
})
|
|
991
|
-
`,
|
|
992
|
-
"@kenkaiiii/gg-pixel"
|
|
980
|
+
});`
|
|
993
981
|
);
|
|
994
|
-
|
|
982
|
+
upsertPixelBlockInFile(
|
|
995
983
|
clientPath,
|
|
996
984
|
`import { initPixel } from "@kenkaiiii/gg-pixel/browser";
|
|
997
985
|
initPixel({
|
|
998
986
|
projectKey: ${JSON.stringify(projectKey)},
|
|
999
987
|
ingestUrl: ${JSON.stringify(ingestUrl)},
|
|
1000
|
-
})
|
|
1001
|
-
`,
|
|
1002
|
-
"@kenkaiiii/gg-pixel/browser"
|
|
988
|
+
});`
|
|
1003
989
|
);
|
|
1004
990
|
return {
|
|
1005
991
|
primaryInitPath: clientPath,
|
|
@@ -1341,14 +1327,33 @@ function pickPath(root, candidates) {
|
|
|
1341
1327
|
}
|
|
1342
1328
|
return null;
|
|
1343
1329
|
}
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1330
|
+
var PIXEL_MARK_BEGIN = "// >>> gg-pixel auto-generated \u2014 do not edit between these markers <<<";
|
|
1331
|
+
var PIXEL_MARK_END = "// >>> /gg-pixel <<<";
|
|
1332
|
+
function wrapPixelBlock(content) {
|
|
1333
|
+
return `${PIXEL_MARK_BEGIN}
|
|
1334
|
+
${content.replace(/\s+$/, "")}
|
|
1335
|
+
${PIXEL_MARK_END}
|
|
1336
|
+
`;
|
|
1337
|
+
}
|
|
1338
|
+
function upsertPixelBlock(existing, block) {
|
|
1339
|
+
const wrapped = wrapPixelBlock(block);
|
|
1340
|
+
const beginIdx = existing.indexOf(PIXEL_MARK_BEGIN);
|
|
1341
|
+
if (beginIdx !== -1) {
|
|
1342
|
+
const endIdx = existing.indexOf(PIXEL_MARK_END, beginIdx);
|
|
1343
|
+
if (endIdx !== -1) {
|
|
1344
|
+
const after = endIdx + PIXEL_MARK_END.length;
|
|
1345
|
+
const trailNL = existing[after] === "\n" ? 1 : 0;
|
|
1346
|
+
return existing.slice(0, beginIdx) + wrapped + existing.slice(after + trailNL);
|
|
1347
|
+
}
|
|
1350
1348
|
}
|
|
1351
|
-
(0
|
|
1349
|
+
if (existing.length === 0) return wrapped;
|
|
1350
|
+
const sep2 = existing.endsWith("\n") ? "" : "\n";
|
|
1351
|
+
return existing + sep2 + "\n" + wrapped;
|
|
1352
|
+
}
|
|
1353
|
+
function upsertPixelBlockInFile(filePath, block) {
|
|
1354
|
+
const existing = (0, import_node_fs3.existsSync)(filePath) ? (0, import_node_fs3.readFileSync)(filePath, "utf8") : "";
|
|
1355
|
+
const next = upsertPixelBlock(existing, block);
|
|
1356
|
+
if (next !== existing) (0, import_node_fs3.writeFileSync)(filePath, next, "utf8");
|
|
1352
1357
|
}
|
|
1353
1358
|
function injectImport(entryPath, initFilePath) {
|
|
1354
1359
|
let content;
|
|
@@ -1476,8 +1481,8 @@ async function installGo(ctx) {
|
|
|
1476
1481
|
const existingKey = readEnvKey(envFilePath, "GG_PIXEL_KEY");
|
|
1477
1482
|
let created;
|
|
1478
1483
|
let reused = false;
|
|
1479
|
-
if (existing && existingKey) {
|
|
1480
|
-
created = { id: existing.id, key: existingKey };
|
|
1484
|
+
if (existing && existing.secret && existingKey) {
|
|
1485
|
+
created = { id: existing.id, key: existingKey, secret: existing.secret };
|
|
1481
1486
|
reused = true;
|
|
1482
1487
|
} else {
|
|
1483
1488
|
created = await createProject(fetchFn, ingestUrl, projectName);
|
|
@@ -1505,10 +1510,11 @@ func init() {
|
|
|
1505
1510
|
"utf8"
|
|
1506
1511
|
);
|
|
1507
1512
|
writeEnvKey(envFilePath, "GG_PIXEL_KEY", created.key);
|
|
1508
|
-
writeProjectsMapping(projectsJsonPath, created.id, projectName, projectRoot);
|
|
1513
|
+
writeProjectsMapping(projectsJsonPath, created.id, projectName, projectRoot, created.secret);
|
|
1509
1514
|
return {
|
|
1510
1515
|
projectId: created.id,
|
|
1511
1516
|
projectKey: created.key,
|
|
1517
|
+
projectSecret: created.secret,
|
|
1512
1518
|
projectName,
|
|
1513
1519
|
projectKind: "go",
|
|
1514
1520
|
initFilePath,
|
|
@@ -1549,8 +1555,8 @@ async function installRuby(ctx) {
|
|
|
1549
1555
|
const existingKey = readEnvKey(envFilePath, "GG_PIXEL_KEY");
|
|
1550
1556
|
let created;
|
|
1551
1557
|
let reused = false;
|
|
1552
|
-
if (existing && existingKey) {
|
|
1553
|
-
created = { id: existing.id, key: existingKey };
|
|
1558
|
+
if (existing && existing.secret && existingKey) {
|
|
1559
|
+
created = { id: existing.id, key: existingKey, secret: existing.secret };
|
|
1554
1560
|
reused = true;
|
|
1555
1561
|
} else {
|
|
1556
1562
|
created = await createProject(fetchFn, ingestUrl, projectName);
|
|
@@ -1569,10 +1575,11 @@ GGPixel.init(
|
|
|
1569
1575
|
"utf8"
|
|
1570
1576
|
);
|
|
1571
1577
|
writeEnvKey(envFilePath, "GG_PIXEL_KEY", created.key);
|
|
1572
|
-
writeProjectsMapping(projectsJsonPath, created.id, projectName, projectRoot);
|
|
1578
|
+
writeProjectsMapping(projectsJsonPath, created.id, projectName, projectRoot, created.secret);
|
|
1573
1579
|
return {
|
|
1574
1580
|
projectId: created.id,
|
|
1575
1581
|
projectKey: created.key,
|
|
1582
|
+
projectSecret: created.secret,
|
|
1576
1583
|
projectName,
|
|
1577
1584
|
projectKind: "ruby",
|
|
1578
1585
|
initFilePath,
|
|
@@ -1625,8 +1632,8 @@ async function installPython(ctx) {
|
|
|
1625
1632
|
const existingKey = readEnvKey(envFilePath, "GG_PIXEL_KEY");
|
|
1626
1633
|
let created;
|
|
1627
1634
|
let reused = false;
|
|
1628
|
-
if (existing && existingKey) {
|
|
1629
|
-
created = { id: existing.id, key: existingKey };
|
|
1635
|
+
if (existing && existing.secret && existingKey) {
|
|
1636
|
+
created = { id: existing.id, key: existingKey, secret: existing.secret };
|
|
1630
1637
|
reused = true;
|
|
1631
1638
|
} else {
|
|
1632
1639
|
created = await createProject(fetchFn, ingestUrl, projectName);
|
|
@@ -1636,11 +1643,12 @@ async function installPython(ctx) {
|
|
|
1636
1643
|
const initFilePath = (0, import_node_path2.join)(projectRoot, "gg_pixel_init.py");
|
|
1637
1644
|
(0, import_node_fs3.writeFileSync)(initFilePath, renderPythonInitFile(ingestUrl, created.key), "utf8");
|
|
1638
1645
|
writeEnvKey(envFilePath, "GG_PIXEL_KEY", created.key);
|
|
1639
|
-
writeProjectsMapping(projectsJsonPath, created.id, projectName, projectRoot);
|
|
1646
|
+
writeProjectsMapping(projectsJsonPath, created.id, projectName, projectRoot, created.secret);
|
|
1640
1647
|
const entryWiring = wirePythonEntry(projectRoot, initFilePath);
|
|
1641
1648
|
return {
|
|
1642
1649
|
projectId: created.id,
|
|
1643
1650
|
projectKey: created.key,
|
|
1651
|
+
projectSecret: created.secret,
|
|
1644
1652
|
projectName,
|
|
1645
1653
|
projectKind: "python",
|
|
1646
1654
|
initFilePath,
|
|
@@ -1758,7 +1766,7 @@ function findPythonEntryFile(projectRoot) {
|
|
|
1758
1766
|
}
|
|
1759
1767
|
return null;
|
|
1760
1768
|
}
|
|
1761
|
-
function writeProjectsMapping(projectsJsonPath, projectId, name, path) {
|
|
1769
|
+
function writeProjectsMapping(projectsJsonPath, projectId, name, path, secret) {
|
|
1762
1770
|
(0, import_node_fs3.mkdirSync)((0, import_node_path2.dirname)(projectsJsonPath), { recursive: true });
|
|
1763
1771
|
let map = {};
|
|
1764
1772
|
if ((0, import_node_fs3.existsSync)(projectsJsonPath)) {
|
|
@@ -1767,7 +1775,9 @@ function writeProjectsMapping(projectsJsonPath, projectId, name, path) {
|
|
|
1767
1775
|
} catch {
|
|
1768
1776
|
}
|
|
1769
1777
|
}
|
|
1770
|
-
|
|
1778
|
+
const entry = { name, path };
|
|
1779
|
+
if (secret) entry.secret = secret;
|
|
1780
|
+
map[projectId] = entry;
|
|
1771
1781
|
(0, import_node_fs3.writeFileSync)(projectsJsonPath, `${JSON.stringify(map, null, 2)}
|
|
1772
1782
|
`, "utf8");
|
|
1773
1783
|
}
|