@glasstrace/sdk 0.18.0 → 0.20.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.
Files changed (36) hide show
  1. package/README.md +79 -0
  2. package/dist/{chunk-GSGX76Q5.js → chunk-5N2IR4EO.js} +146 -3
  3. package/dist/chunk-5N2IR4EO.js.map +1 -0
  4. package/dist/{chunk-XNDHQN4S.js → chunk-6JRI4OGB.js} +286 -54
  5. package/dist/chunk-6JRI4OGB.js.map +1 -0
  6. package/dist/{chunk-IOPCSX6C.js → chunk-F2TZRBEH.js} +2 -2
  7. package/dist/{chunk-E33Y7BQH.js → chunk-VN3GZDV6.js} +2 -2
  8. package/dist/{chunk-J5BW7V2D.js → chunk-YPXW2TN3.js} +2 -2
  9. package/dist/cli/init.cjs +548 -153
  10. package/dist/cli/init.cjs.map +1 -1
  11. package/dist/cli/init.d.cts +48 -2
  12. package/dist/cli/init.d.ts +48 -2
  13. package/dist/cli/init.js +106 -6
  14. package/dist/cli/init.js.map +1 -1
  15. package/dist/cli/mcp-add.cjs +66 -0
  16. package/dist/cli/mcp-add.cjs.map +1 -1
  17. package/dist/cli/mcp-add.js +2 -2
  18. package/dist/cli/uninit.cjs +172 -54
  19. package/dist/cli/uninit.cjs.map +1 -1
  20. package/dist/cli/uninit.d.cts +2 -0
  21. package/dist/cli/uninit.d.ts +2 -0
  22. package/dist/cli/uninit.js +2 -1
  23. package/dist/index.cjs +157 -34
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +43 -12
  26. package/dist/index.d.ts +43 -12
  27. package/dist/index.js +19 -39
  28. package/dist/index.js.map +1 -1
  29. package/dist/{source-map-uploader-26QPRSCG.js → source-map-uploader-VPDZWWM2.js} +3 -3
  30. package/package.json +1 -1
  31. package/dist/chunk-GSGX76Q5.js.map +0 -1
  32. package/dist/chunk-XNDHQN4S.js.map +0 -1
  33. /package/dist/{chunk-IOPCSX6C.js.map → chunk-F2TZRBEH.js.map} +0 -0
  34. /package/dist/{chunk-E33Y7BQH.js.map → chunk-VN3GZDV6.js.map} +0 -0
  35. /package/dist/{chunk-J5BW7V2D.js.map → chunk-YPXW2TN3.js.map} +0 -0
  36. /package/dist/{source-map-uploader-26QPRSCG.js.map → source-map-uploader-VPDZWWM2.js.map} +0 -0
package/README.md CHANGED
@@ -155,6 +155,85 @@ GLASSTRACE_SUPPRESS_ACTION_NUDGE=1
155
155
  The nudge never fires in production (detected via `NODE_ENV` or
156
156
  `VERCEL_ENV`) unless `GLASSTRACE_FORCE_ENABLE=true` is also set.
157
157
 
158
+ ## Browser-extension discovery
159
+
160
+ `glasstrace init` writes a small static file at
161
+ `public/.well-known/glasstrace.json` (or `static/.well-known/glasstrace.json`
162
+ on SvelteKit) so the Glasstrace browser extension can discover your
163
+ project's anonymous key without a runtime HTTP handler. The file
164
+ contains only a schema version and the project's anonymous key — it
165
+ is public metadata, not a secret, and should be committed to source
166
+ control alongside the rest of your project.
167
+
168
+ The SDK no longer requires `createDiscoveryHandler` to be wired into
169
+ your server. If you previously registered the handler (for example,
170
+ inside `middleware.ts` or `proxy.ts` on Next.js), you can remove the
171
+ handler code and the extension will read the static file instead.
172
+
173
+ ### Migration: removing the runtime discovery handler
174
+
175
+ **Next.js 15 and earlier (`middleware.ts`):**
176
+
177
+ ```ts
178
+ // Before: middleware.ts
179
+ import { createDiscoveryHandler } from "@glasstrace/sdk";
180
+ import { NextResponse } from "next/server";
181
+
182
+ const discoveryHandler = createDiscoveryHandler(/* getAnonKey */, /* getSessionId */);
183
+
184
+ export async function middleware(req: Request) {
185
+ const response = await discoveryHandler(req);
186
+ if (response !== null) return response;
187
+ return NextResponse.next();
188
+ }
189
+ ```
190
+
191
+ ```ts
192
+ // After: middleware.ts (only the non-Glasstrace logic remains)
193
+ import { NextResponse } from "next/server";
194
+
195
+ export function middleware(_req: Request) {
196
+ return NextResponse.next();
197
+ }
198
+ ```
199
+
200
+ **Next.js 16 and later (`proxy.ts`):**
201
+
202
+ Next.js 16 replaces `middleware.ts` with `proxy.ts`. If your project
203
+ invoked the discovery handler from `middleware.ts`, migrate it to the
204
+ new file convention and drop the handler in the same edit:
205
+
206
+ ```ts
207
+ // Before: proxy.ts (Next 16+)
208
+ import { createDiscoveryHandler } from "@glasstrace/sdk";
209
+ import { NextResponse } from "next/server";
210
+
211
+ const discoveryHandler = createDiscoveryHandler(/* getAnonKey */, /* getSessionId */);
212
+
213
+ export async function proxy(req: Request) {
214
+ const response = await discoveryHandler(req);
215
+ if (response !== null) return response;
216
+ return NextResponse.next();
217
+ }
218
+ ```
219
+
220
+ ```ts
221
+ // After: proxy.ts (Next 16+)
222
+ import { NextResponse } from "next/server";
223
+
224
+ export function proxy(_req: Request) {
225
+ return NextResponse.next();
226
+ }
227
+ ```
228
+
229
+ If `proxy.ts` no longer does anything else, you can delete it entirely.
230
+
231
+ `createDiscoveryHandler` remains available for one more major version
232
+ to avoid breaking integrations that depend on it, but it now prints a
233
+ one-time deprecation warning on first use and will be removed in
234
+ `v1.0.0`. Run `npx glasstrace init` after upgrading to generate the
235
+ static file.
236
+
158
237
  ## Security
159
238
 
160
239
  The SDK transmits your API key exclusively via the `Authorization: Bearer`
@@ -13953,10 +13953,152 @@ var DEFAULT_CAPTURE_CONFIG = {
13953
13953
  consoleErrors: false,
13954
13954
  errorResponseBodies: false
13955
13955
  };
13956
+ var K = new Uint32Array([
13957
+ 1116352408,
13958
+ 1899447441,
13959
+ 3049323471,
13960
+ 3921009573,
13961
+ 961987163,
13962
+ 1508970993,
13963
+ 2453635748,
13964
+ 2870763221,
13965
+ 3624381080,
13966
+ 310598401,
13967
+ 607225278,
13968
+ 1426881987,
13969
+ 1925078388,
13970
+ 2162078206,
13971
+ 2614888103,
13972
+ 3248222580,
13973
+ 3835390401,
13974
+ 4022224774,
13975
+ 264347078,
13976
+ 604807628,
13977
+ 770255983,
13978
+ 1249150122,
13979
+ 1555081692,
13980
+ 1996064986,
13981
+ 2554220882,
13982
+ 2821834349,
13983
+ 2952996808,
13984
+ 3210313671,
13985
+ 3336571891,
13986
+ 3584528711,
13987
+ 113926993,
13988
+ 338241895,
13989
+ 666307205,
13990
+ 773529912,
13991
+ 1294757372,
13992
+ 1396182291,
13993
+ 1695183700,
13994
+ 1986661051,
13995
+ 2177026350,
13996
+ 2456956037,
13997
+ 2730485921,
13998
+ 2820302411,
13999
+ 3259730800,
14000
+ 3345764771,
14001
+ 3516065817,
14002
+ 3600352804,
14003
+ 4094571909,
14004
+ 275423344,
14005
+ 430227734,
14006
+ 506948616,
14007
+ 659060556,
14008
+ 883997877,
14009
+ 958139571,
14010
+ 1322822218,
14011
+ 1537002063,
14012
+ 1747873779,
14013
+ 1955562222,
14014
+ 2024104815,
14015
+ 2227730452,
14016
+ 2361852424,
14017
+ 2428436474,
14018
+ 2756734187,
14019
+ 3204031479,
14020
+ 3329325298
14021
+ ]);
14022
+ function rotr(x, n) {
14023
+ return (x >>> n | x << 32 - n) >>> 0;
14024
+ }
14025
+ function sha256Hex(input) {
14026
+ const message = new TextEncoder().encode(input);
14027
+ const bitLength = message.length * 8;
14028
+ const paddedLength = Math.ceil((message.length + 9) / 64) * 64;
14029
+ const padded = new Uint8Array(paddedLength);
14030
+ padded.set(message);
14031
+ padded[message.length] = 128;
14032
+ const view = new DataView(padded.buffer);
14033
+ view.setUint32(paddedLength - 8, Math.floor(bitLength / 4294967296), false);
14034
+ view.setUint32(paddedLength - 4, bitLength >>> 0, false);
14035
+ const H = new Uint32Array([
14036
+ 1779033703,
14037
+ 3144134277,
14038
+ 1013904242,
14039
+ 2773480762,
14040
+ 1359893119,
14041
+ 2600822924,
14042
+ 528734635,
14043
+ 1541459225
14044
+ ]);
14045
+ const W = new Uint32Array(64);
14046
+ for (let offset = 0; offset < paddedLength; offset += 64) {
14047
+ for (let i = 0; i < 16; i++) {
14048
+ W[i] = view.getUint32(offset + i * 4, false);
14049
+ }
14050
+ for (let i = 16; i < 64; i++) {
14051
+ const s0 = rotr(W[i - 15], 7) ^ rotr(W[i - 15], 18) ^ W[i - 15] >>> 3;
14052
+ const s1 = rotr(W[i - 2], 17) ^ rotr(W[i - 2], 19) ^ W[i - 2] >>> 10;
14053
+ W[i] = W[i - 16] + s0 + W[i - 7] + s1 >>> 0;
14054
+ }
14055
+ let a = H[0];
14056
+ let b = H[1];
14057
+ let c = H[2];
14058
+ let d = H[3];
14059
+ let e = H[4];
14060
+ let f = H[5];
14061
+ let g = H[6];
14062
+ let h = H[7];
14063
+ for (let i = 0; i < 64; i++) {
14064
+ const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
14065
+ const ch = e & f ^ ~e & g;
14066
+ const temp1 = h + S1 + ch + K[i] + W[i] >>> 0;
14067
+ const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
14068
+ const maj = a & b ^ a & c ^ b & c;
14069
+ const temp2 = S0 + maj >>> 0;
14070
+ h = g;
14071
+ g = f;
14072
+ f = e;
14073
+ e = d + temp1 >>> 0;
14074
+ d = c;
14075
+ c = b;
14076
+ b = a;
14077
+ a = temp1 + temp2 >>> 0;
14078
+ }
14079
+ H[0] = H[0] + a >>> 0;
14080
+ H[1] = H[1] + b >>> 0;
14081
+ H[2] = H[2] + c >>> 0;
14082
+ H[3] = H[3] + d >>> 0;
14083
+ H[4] = H[4] + e >>> 0;
14084
+ H[5] = H[5] + f >>> 0;
14085
+ H[6] = H[6] + g >>> 0;
14086
+ H[7] = H[7] + h >>> 0;
14087
+ }
14088
+ let out = "";
14089
+ for (let i = 0; i < 8; i++) {
14090
+ out += H[i].toString(16).padStart(8, "0");
14091
+ }
14092
+ return out;
14093
+ }
14094
+ function deriveSessionId(apiKey, origin, date5, windowIndex) {
14095
+ const input = JSON.stringify([apiKey, origin, date5, windowIndex]);
14096
+ const digest = sha256Hex(input).slice(0, 16);
14097
+ return SessionIdSchema.parse(digest);
14098
+ }
13956
14099
 
13957
14100
  export {
13958
14101
  AnonApiKeySchema,
13959
- SessionIdSchema,
13960
14102
  createAnonApiKey,
13961
14103
  createBuildHash,
13962
14104
  SdkCachedConfigSchema,
@@ -13965,6 +14107,7 @@ export {
13965
14107
  PresignedUploadResponseSchema,
13966
14108
  SourceMapManifestResponseSchema,
13967
14109
  GLASSTRACE_ATTRIBUTE_NAMES,
13968
- DEFAULT_CAPTURE_CONFIG
14110
+ DEFAULT_CAPTURE_CONFIG,
14111
+ deriveSessionId
13969
14112
  };
13970
- //# sourceMappingURL=chunk-GSGX76Q5.js.map
14113
+ //# sourceMappingURL=chunk-5N2IR4EO.js.map