@logbrew/sdk 0.1.18 → 0.1.19

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 CHANGED
@@ -25,7 +25,7 @@ node node_modules/@logbrew/sdk/examples/index.mjs agent-timeline
25
25
  npm --prefix node_modules/@logbrew/sdk/examples run agent-timeline
26
26
  ```
27
27
 
28
- For Vite apps, add the build-time release-artifact plugin to `vite.config.js`. It enables hidden source maps when your config has not chosen a source-map mode, injects matching Debug IDs after the build, strips embedded source text and local source prefixes, writes a privacy-bounded manifest, and can upload the prepared artifacts before the build completes:
28
+ For Vite apps, add the build-time release-artifact plugin to `vite.config.js`. It enables hidden source maps and function-name preservation when your config has not made either choice, injects matching Debug IDs after the build, strips embedded source text and local source prefixes, writes a privacy-bounded manifest, and can upload the prepared artifacts before the build completes:
29
29
 
30
30
  ```js
31
31
  import { createLogBrewViteReleaseArtifactsPlugin } from "@logbrew/sdk/vite-release-artifacts";
@@ -48,7 +48,7 @@ export default {
48
48
  };
49
49
  ```
50
50
 
51
- Set `LOGBREW_RELEASE_ARTIFACT_TOKEN` in the build environment to a dedicated release-artifact token. Use `tokenEnv` when your CI uses a different environment variable name, or `dryRun: true` to prepare the complete build output without a network request. The plugin runs only during Vite builds, keeps upload disabled when `upload` is omitted, and fails the build when preparation or upload cannot complete safely. It never uses normal SDK ingest keys or account/session API values.
51
+ Set `LOGBREW_RELEASE_ARTIFACT_TOKEN` in the build environment to a dedicated release-artifact token. Use `tokenEnv` when your CI uses a different environment variable name, or `dryRun: true` to prepare the complete build output without a network request. The plugin runs only during Vite builds, keeps upload disabled when `upload` is omitted, and fails the build when preparation or upload cannot complete safely. It never uses normal SDK ingest keys or account/session API values. When your app chooses `build.minify` or multiple Rolldown outputs explicitly, configure `keepNames` for that build; otherwise captured stacks retain shortened function labels.
52
52
 
53
53
  The package also ships the dependency-free `logbrew-release-artifacts` command for JavaScript source-map preparation and upload. Use it after your frontend build to inject matching Debug IDs, strip embedded source text by default, and create a privacy-bounded manifest that can be inspected before upload:
54
54
 
@@ -102,7 +102,7 @@ npx logbrew-release-artifacts upload-js \
102
102
 
103
103
  Non-loopback endpoints require `--allow-hosted`, a UUID `projectId` created by `manifest-js --project-id`, HTTPS, and no embedded auth values, query strings, or fragments. Local loopback preparation remains valid without a project ID. The upload command never uses normal SDK ingest keys or account/session API auth values. Full backend-symbolicated issue support is separate from artifact upload until your project has completed hosted symbolication for its release.
104
104
 
105
- When you capture a JavaScript error, use `createIssueAttributesFromError()` to keep error metadata structured and source-map-friendly without sending raw stack text by default. The helper also follows `Error.cause` and `AggregateError.errors` into a bounded parent-first exception graph. Automatic messages are marked redacted, every node reports whether frames were captured, truncated, or unavailable, and unsafe accessors, cycles, or the eight-node cap mark the graph truncated instead of inventing evidence. React, browser, Node, Next.js, and React Native helpers reuse this same core projection. See the shared [exception-chain contract](../../docs/exception-chain-evidence.md). Pass a Debug ID map from your app-owned build setup when you want the issue event to carry release-artifact metadata:
105
+ When you capture a JavaScript error, use `createIssueAttributesFromError()` to keep error metadata structured and source-map-friendly without sending raw stack text by default. The helper also follows `Error.cause` and `AggregateError.errors` into a bounded parent-first exception graph. Automatic messages are marked redacted, every node reports whether frames were captured, truncated, or unavailable, and unsafe accessors, cycles, or the eight-node cap mark the graph truncated instead of inventing evidence. React, browser, Node, Next.js, and React Native helpers reuse this same core projection. See the shared [exception-chain contract](../../docs/exception-chain-evidence.md). A bundle prepared by the Vite plugin registers its Debug ID automatically; use `debugIdMap` only for a different app-owned build flow:
106
106
 
107
107
  ```js
108
108
  import { createIssueAttributesFromError, LogBrewClient } from "@logbrew/sdk";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logbrew/sdk",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "description": "Public LogBrew JavaScript SDK for building, validating, and flushing event batches.",
5
5
  "type": "module",
6
6
  "main": "./index.cjs",
@@ -55,6 +55,16 @@ function resolveBuildDir(root, outDir, explicitBuildDir) {
55
55
  return resolvePathFromRoot(root, outDir || "dist");
56
56
  }
57
57
 
58
+ function viteMajorVersion(root) {
59
+ try {
60
+ const manifestPath = require.resolve("vite/package.json", { paths: [path.resolve(root || process.cwd())] });
61
+ const version = JSON.parse(fs.readFileSync(manifestPath, "utf8")).version;
62
+ return Number.parseInt(version, 10) || 0;
63
+ } catch {
64
+ return 0;
65
+ }
66
+ }
67
+
58
68
  function createLogBrewViteReleaseArtifactsPlugin(options) {
59
69
  const release = requiredString(options, "release");
60
70
  const environment = requiredString(options, "environment");
@@ -78,10 +88,21 @@ function createLogBrewViteReleaseArtifactsPlugin(options) {
78
88
  apply: "build",
79
89
  enforce: "post",
80
90
  config(config = {}) {
81
- if (!enableSourceMaps || config.build?.sourcemap !== undefined) {
82
- return null;
83
- }
84
- return { build: { sourcemap: "hidden" } };
91
+ const sourceMap = enableSourceMaps && config.build?.sourcemap === undefined;
92
+ const keepNames = config.build?.minify === undefined;
93
+ const output = config.build?.rolldownOptions?.output;
94
+ const viteMajor = viteMajorVersion(config.root);
95
+ const modernNames = keepNames && viteMajor >= 8
96
+ && !Array.isArray(output) && output?.keepNames === undefined;
97
+ const legacyNames = keepNames && viteMajor < 8
98
+ && config.esbuild !== false && config.esbuild?.keepNames === undefined;
99
+ return sourceMap || modernNames || legacyNames ? {
100
+ ...(sourceMap || modernNames ? { build: {
101
+ ...(sourceMap ? { sourcemap: "hidden" } : {}),
102
+ ...(modernNames ? { rolldownOptions: { output: { keepNames: true } } } : {})
103
+ } } : {}),
104
+ ...(legacyNames ? { esbuild: { keepNames: true } } : {})
105
+ } : null;
85
106
  },
86
107
  configResolved(config) {
87
108
  viteRoot = config?.root ? path.resolve(config.root) : process.cwd();
@@ -28,7 +28,7 @@ export interface LogBrewViteReleaseArtifactsPlugin {
28
28
  name: "logbrew-vite-release-artifacts";
29
29
  apply: "build";
30
30
  enforce: "post";
31
- config(config?: { build?: { sourcemap?: unknown } }): null | { build: { sourcemap: "hidden" } };
31
+ config(config?: { root?: string; build?: { sourcemap?: unknown; minify?: unknown; rolldownOptions?: { output?: { keepNames?: boolean } | Array<{ keepNames?: boolean }> } }; esbuild?: false | { keepNames?: boolean } }): null | { build?: { sourcemap?: "hidden"; rolldownOptions?: { output: { keepNames: true } } }; esbuild?: { keepNames: true } };
32
32
  configResolved(config: {
33
33
  root?: string;
34
34
  build?: { outDir?: string };
@@ -28,7 +28,7 @@ export interface LogBrewViteReleaseArtifactsPlugin {
28
28
  name: "logbrew-vite-release-artifacts";
29
29
  apply: "build";
30
30
  enforce: "post";
31
- config(config?: { build?: { sourcemap?: unknown } }): null | { build: { sourcemap: "hidden" } };
31
+ config(config?: { root?: string; build?: { sourcemap?: unknown; minify?: unknown; rolldownOptions?: { output?: { keepNames?: boolean } | Array<{ keepNames?: boolean }> } }; esbuild?: false | { keepNames?: boolean } }): null | { build?: { sourcemap?: "hidden"; rolldownOptions?: { output: { keepNames: true } } }; esbuild?: { keepNames: true } };
32
32
  configResolved(config: {
33
33
  root?: string;
34
34
  build?: { outDir?: string };