@glasstrace/sdk 0.10.0 → 0.11.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/index.d.cts CHANGED
@@ -314,6 +314,14 @@ declare function performInit(config: ResolvedConfig, anonKey: AnonApiKey | null,
314
314
  * every span export batch).
315
315
  */
316
316
  declare function getActiveConfig(): CaptureConfig;
317
+ /**
318
+ * Returns the `linkedAccountId` from the current in-memory init response,
319
+ * or `undefined` if no init response is available or no account is linked.
320
+ *
321
+ * Used by the discovery endpoint to determine whether `claimed: true`
322
+ * should be included in the response.
323
+ */
324
+ declare function getLinkedAccountId(): string | undefined;
317
325
 
318
326
  /**
319
327
  * Lightweight SpanProcessor that delegates to a wrapped processor.
@@ -417,6 +425,17 @@ declare class GlasstraceExporter implements SpanExporter {
417
425
  private flushPending;
418
426
  }
419
427
 
428
+ /**
429
+ * Claim state returned by the `getClaimState` callback.
430
+ *
431
+ * - `claimed` — `true` when the anonymous key has been linked to an account.
432
+ * - `accountHint` — optional masked identifier (e.g. `"er***@example.com"`)
433
+ * for the browser extension to display to the user.
434
+ */
435
+ interface ClaimState {
436
+ claimed: boolean;
437
+ accountHint?: string;
438
+ }
420
439
  /**
421
440
  * Creates a request handler for the `/__glasstrace/config` discovery endpoint.
422
441
  *
@@ -424,10 +443,14 @@ declare class GlasstraceExporter implements SpanExporter {
424
443
  * If not, returns `null` (pass-through). If it matches, returns a `DiscoveryResponse`
425
444
  * with the anonymous key and current session ID.
426
445
  *
446
+ * When `getClaimState` returns a non-null value with `claimed: true`, the
447
+ * response includes `claimed` and (optionally) `accountHint` so the browser
448
+ * extension can prompt the user to sign in.
449
+ *
427
450
  * The triple guard (anonymous + dev + active) is enforced by the caller,
428
451
  * not by this module. If the handler is registered, it serves.
429
452
  */
430
- declare function createDiscoveryHandler(getAnonKey: () => Promise<AnonApiKey | null>, getSessionId: () => SessionId): (request: Request) => Promise<Response | null>;
453
+ declare function createDiscoveryHandler(getAnonKey: () => Promise<AnonApiKey | null>, getSessionId: () => SessionId, getClaimState?: () => ClaimState | null): (request: Request) => Promise<Response | null>;
431
454
 
432
455
  /**
433
456
  * The primary SDK entry point called by developers in their `instrumentation.ts`.
@@ -588,4 +611,4 @@ declare function extractImports(fileContent: string): string[];
588
611
  */
589
612
  declare function buildImportGraph(projectRoot: string): Promise<ImportGraphPayload>;
590
613
 
591
- export { type AutoUploadOptions, type BlobUploader, type FetchTarget, GlasstraceExporter, type GlasstraceExporterOptions, GlasstraceSpanProcessor, type InitClaimResult, PRESIGNED_THRESHOLD_BYTES, type ResolvedConfig, SdkError, SessionManager, type SourceMapEntry, buildImportGraph, captureError, classifyFetchTarget, collectSourceMaps, computeBuildHash, createDiscoveryHandler, deriveSessionId, discoverTestFiles, extractImports, getActiveConfig, getDateString, getDiscoveryHandler, getOrCreateAnonKey, getOrigin, isAnonymousMode, isProductionDisabled, loadCachedConfig, performInit, readAnonKey, readEnvVars, registerGlasstrace, resolveConfig, saveCachedConfig, sendInitRequest, uploadSourceMaps, uploadSourceMapsAuto, uploadSourceMapsPresigned, withGlasstraceConfig };
614
+ export { type AutoUploadOptions, type BlobUploader, type ClaimState, type FetchTarget, GlasstraceExporter, type GlasstraceExporterOptions, GlasstraceSpanProcessor, type InitClaimResult, PRESIGNED_THRESHOLD_BYTES, type ResolvedConfig, SdkError, SessionManager, type SourceMapEntry, buildImportGraph, captureError, classifyFetchTarget, collectSourceMaps, computeBuildHash, createDiscoveryHandler, deriveSessionId, discoverTestFiles, extractImports, getActiveConfig, getDateString, getDiscoveryHandler, getLinkedAccountId, getOrCreateAnonKey, getOrigin, isAnonymousMode, isProductionDisabled, loadCachedConfig, performInit, readAnonKey, readEnvVars, registerGlasstrace, resolveConfig, saveCachedConfig, sendInitRequest, uploadSourceMaps, uploadSourceMapsAuto, uploadSourceMapsPresigned, withGlasstraceConfig };
package/dist/index.d.ts CHANGED
@@ -314,6 +314,14 @@ declare function performInit(config: ResolvedConfig, anonKey: AnonApiKey | null,
314
314
  * every span export batch).
315
315
  */
316
316
  declare function getActiveConfig(): CaptureConfig;
317
+ /**
318
+ * Returns the `linkedAccountId` from the current in-memory init response,
319
+ * or `undefined` if no init response is available or no account is linked.
320
+ *
321
+ * Used by the discovery endpoint to determine whether `claimed: true`
322
+ * should be included in the response.
323
+ */
324
+ declare function getLinkedAccountId(): string | undefined;
317
325
 
318
326
  /**
319
327
  * Lightweight SpanProcessor that delegates to a wrapped processor.
@@ -417,6 +425,17 @@ declare class GlasstraceExporter implements SpanExporter {
417
425
  private flushPending;
418
426
  }
419
427
 
428
+ /**
429
+ * Claim state returned by the `getClaimState` callback.
430
+ *
431
+ * - `claimed` — `true` when the anonymous key has been linked to an account.
432
+ * - `accountHint` — optional masked identifier (e.g. `"er***@example.com"`)
433
+ * for the browser extension to display to the user.
434
+ */
435
+ interface ClaimState {
436
+ claimed: boolean;
437
+ accountHint?: string;
438
+ }
420
439
  /**
421
440
  * Creates a request handler for the `/__glasstrace/config` discovery endpoint.
422
441
  *
@@ -424,10 +443,14 @@ declare class GlasstraceExporter implements SpanExporter {
424
443
  * If not, returns `null` (pass-through). If it matches, returns a `DiscoveryResponse`
425
444
  * with the anonymous key and current session ID.
426
445
  *
446
+ * When `getClaimState` returns a non-null value with `claimed: true`, the
447
+ * response includes `claimed` and (optionally) `accountHint` so the browser
448
+ * extension can prompt the user to sign in.
449
+ *
427
450
  * The triple guard (anonymous + dev + active) is enforced by the caller,
428
451
  * not by this module. If the handler is registered, it serves.
429
452
  */
430
- declare function createDiscoveryHandler(getAnonKey: () => Promise<AnonApiKey | null>, getSessionId: () => SessionId): (request: Request) => Promise<Response | null>;
453
+ declare function createDiscoveryHandler(getAnonKey: () => Promise<AnonApiKey | null>, getSessionId: () => SessionId, getClaimState?: () => ClaimState | null): (request: Request) => Promise<Response | null>;
431
454
 
432
455
  /**
433
456
  * The primary SDK entry point called by developers in their `instrumentation.ts`.
@@ -588,4 +611,4 @@ declare function extractImports(fileContent: string): string[];
588
611
  */
589
612
  declare function buildImportGraph(projectRoot: string): Promise<ImportGraphPayload>;
590
613
 
591
- export { type AutoUploadOptions, type BlobUploader, type FetchTarget, GlasstraceExporter, type GlasstraceExporterOptions, GlasstraceSpanProcessor, type InitClaimResult, PRESIGNED_THRESHOLD_BYTES, type ResolvedConfig, SdkError, SessionManager, type SourceMapEntry, buildImportGraph, captureError, classifyFetchTarget, collectSourceMaps, computeBuildHash, createDiscoveryHandler, deriveSessionId, discoverTestFiles, extractImports, getActiveConfig, getDateString, getDiscoveryHandler, getOrCreateAnonKey, getOrigin, isAnonymousMode, isProductionDisabled, loadCachedConfig, performInit, readAnonKey, readEnvVars, registerGlasstrace, resolveConfig, saveCachedConfig, sendInitRequest, uploadSourceMaps, uploadSourceMapsAuto, uploadSourceMapsPresigned, withGlasstraceConfig };
614
+ export { type AutoUploadOptions, type BlobUploader, type ClaimState, type FetchTarget, GlasstraceExporter, type GlasstraceExporterOptions, GlasstraceSpanProcessor, type InitClaimResult, PRESIGNED_THRESHOLD_BYTES, type ResolvedConfig, SdkError, SessionManager, type SourceMapEntry, buildImportGraph, captureError, classifyFetchTarget, collectSourceMaps, computeBuildHash, createDiscoveryHandler, deriveSessionId, discoverTestFiles, extractImports, getActiveConfig, getDateString, getDiscoveryHandler, getLinkedAccountId, getOrCreateAnonKey, getOrigin, isAnonymousMode, isProductionDisabled, loadCachedConfig, performInit, readAnonKey, readEnvVars, registerGlasstrace, resolveConfig, saveCachedConfig, sendInitRequest, uploadSourceMaps, uploadSourceMapsAuto, uploadSourceMapsPresigned, withGlasstraceConfig };
package/dist/index.js CHANGED
@@ -11,23 +11,23 @@ import {
11
11
  uploadSourceMaps,
12
12
  uploadSourceMapsAuto,
13
13
  uploadSourceMapsPresigned
14
- } from "./chunk-KOYJ2UQE.js";
14
+ } from "./chunk-SLSWEQCC.js";
15
15
  import {
16
16
  buildImportGraph,
17
17
  discoverTestFiles,
18
18
  extractImports
19
- } from "./chunk-5MAHIPFH.js";
19
+ } from "./chunk-M7RDFOFR.js";
20
20
  import {
21
21
  getOrCreateAnonKey,
22
22
  readAnonKey
23
- } from "./chunk-ZRNG36LU.js";
23
+ } from "./chunk-2JUH3VGJ.js";
24
24
  import {
25
25
  DEFAULT_CAPTURE_CONFIG,
26
26
  GLASSTRACE_ATTRIBUTE_NAMES,
27
27
  SdkCachedConfigSchema,
28
28
  SdkInitResponseSchema,
29
29
  SessionIdSchema
30
- } from "./chunk-O3Y45VGV.js";
30
+ } from "./chunk-D3JC3LAK.js";
31
31
  import {
32
32
  INVALID_SPAN_CONTEXT,
33
33
  SamplingDecision,
@@ -408,6 +408,12 @@ function getActiveConfig() {
408
408
  }
409
409
  return { ...DEFAULT_CAPTURE_CONFIG };
410
410
  }
411
+ function getLinkedAccountId() {
412
+ return currentConfig?.linkedAccountId;
413
+ }
414
+ function getClaimResult() {
415
+ return currentConfig?.claimResult;
416
+ }
411
417
  function _setCurrentConfig(config) {
412
418
  currentConfig = config;
413
419
  }
@@ -719,7 +725,7 @@ function buildCorsHeaders(origin) {
719
725
  }
720
726
  return headers;
721
727
  }
722
- function createDiscoveryHandler(getAnonKey, getSessionId) {
728
+ function createDiscoveryHandler(getAnonKey, getSessionId, getClaimState) {
723
729
  return async (request) => {
724
730
  let url;
725
731
  try {
@@ -763,8 +769,16 @@ function createDiscoveryHandler(getAnonKey, getSessionId) {
763
769
  );
764
770
  }
765
771
  const sessionId = getSessionId();
772
+ const responseBody = { key: anonKey, sessionId };
773
+ const claimState = getClaimState?.();
774
+ if (claimState?.claimed) {
775
+ responseBody.claimed = true;
776
+ if (claimState.accountHint) {
777
+ responseBody.accountHint = claimState.accountHint;
778
+ }
779
+ }
766
780
  return new Response(
767
- JSON.stringify({ key: anonKey, sessionId }),
781
+ JSON.stringify(responseBody),
768
782
  {
769
783
  status: 200,
770
784
  headers: corsHeaders
@@ -3522,9 +3536,15 @@ function registerGlasstrace(options) {
3522
3536
  if (isDiscoveryEnabled(config)) {
3523
3537
  let resolvedAnonKey = null;
3524
3538
  const anonKeyPromise = getOrCreateAnonKey();
3539
+ const getClaimState = () => {
3540
+ if (getLinkedAccountId()) return { claimed: true };
3541
+ if (getClaimResult()) return { claimed: true };
3542
+ return null;
3543
+ };
3525
3544
  discoveryHandler = createDiscoveryHandler(
3526
3545
  async () => resolvedAnonKey,
3527
- () => sessionManager.getSessionId(getResolvedApiKey())
3546
+ () => sessionManager.getSessionId(getResolvedApiKey()),
3547
+ getClaimState
3528
3548
  );
3529
3549
  if (config.verbose) {
3530
3550
  console.info("[glasstrace] Discovery endpoint registered (key pending).");
@@ -3540,7 +3560,8 @@ function registerGlasstrace(options) {
3540
3560
  if (currentGeneration !== registrationGeneration) return;
3541
3561
  discoveryHandler = createDiscoveryHandler(
3542
3562
  () => Promise.resolve(anonKey),
3543
- () => sessionManager.getSessionId(getResolvedApiKey())
3563
+ () => sessionManager.getSessionId(getResolvedApiKey()),
3564
+ getClaimState
3544
3565
  );
3545
3566
  await backgroundInit(config, anonKey, currentGeneration);
3546
3567
  } catch (err) {
@@ -3597,7 +3618,7 @@ async function backgroundInit(config, anonKeyForInit, generation) {
3597
3618
  if (config.verbose) {
3598
3619
  console.info("[glasstrace] Background init firing.");
3599
3620
  }
3600
- const initResult = await performInit(config, anonKeyForInit, "0.10.0");
3621
+ const initResult = await performInit(config, anonKeyForInit, "0.11.0");
3601
3622
  if (generation !== registrationGeneration) return;
3602
3623
  if (initResult?.claimResult) {
3603
3624
  setResolvedApiKey(initResult.claimResult.newApiKey);
@@ -3671,7 +3692,7 @@ async function handleSourceMapUpload(distDir) {
3671
3692
  );
3672
3693
  return;
3673
3694
  }
3674
- const { collectSourceMaps: collectSourceMaps2, computeBuildHash: computeBuildHash2, uploadSourceMaps: uploadSourceMaps2 } = await import("./source-map-uploader-OA5NCDOK.js");
3695
+ const { collectSourceMaps: collectSourceMaps2, computeBuildHash: computeBuildHash2, uploadSourceMaps: uploadSourceMaps2 } = await import("./source-map-uploader-OFEM54UE.js");
3675
3696
  const maps = await collectSourceMaps2(distDir);
3676
3697
  if (maps.length === 0) {
3677
3698
  console.info("[glasstrace] No source map files found. Skipping upload.");
@@ -3727,6 +3748,7 @@ export {
3727
3748
  getActiveConfig,
3728
3749
  getDateString,
3729
3750
  getDiscoveryHandler,
3751
+ getLinkedAccountId,
3730
3752
  getOrCreateAnonKey,
3731
3753
  getOrigin,
3732
3754
  isAnonymousMode,