@glasstrace/sdk 0.2.0 → 0.2.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.d.cts CHANGED
@@ -1,8 +1,126 @@
1
- import { SdkDiagnosticCode, GlasstraceEnvVars, GlasstraceOptions, SessionId, AnonApiKey, CaptureConfig, SdkInitResponse, ImportGraphPayload, SdkHealthReport, SourceMapUploadResponse } from '@glasstrace/protocol';
1
+ import * as z from './v4/classic/external.cjs';
2
2
  import { Context } from '@opentelemetry/api';
3
3
  import { SpanProcessor, Span, ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
4
4
  import { ExportResult } from '@opentelemetry/core';
5
5
 
6
+ /** Anonymous API key: `gt_anon_` + 48 hex chars. */
7
+ declare const AnonApiKeySchema: z.core.$ZodBranded<z.ZodString, "AnonApiKey", "out">;
8
+ type AnonApiKey = z.infer<typeof AnonApiKeySchema>;
9
+ /** Session ID: 16 hex chars (deterministic, derived from API key + time window). */
10
+ declare const SessionIdSchema: z.core.$ZodBranded<z.ZodString, "SessionId", "out">;
11
+ type SessionId = z.infer<typeof SessionIdSchema>;
12
+
13
+ /**
14
+ * SDK-specific enums.
15
+ */
16
+
17
+ /** Diagnostic codes the SDK can report during health checks. */
18
+ declare const SdkDiagnosticCodeSchema: z.ZodEnum<{
19
+ ingestion_unreachable: "ingestion_unreachable";
20
+ ingestion_auth_failed: "ingestion_auth_failed";
21
+ ingestion_rate_limited: "ingestion_rate_limited";
22
+ config_sync_failed: "config_sync_failed";
23
+ source_map_upload_failed: "source_map_upload_failed";
24
+ }>;
25
+ type SdkDiagnosticCode = z.infer<typeof SdkDiagnosticCodeSchema>;
26
+
27
+ /**
28
+ * SDK configuration types.
29
+ */
30
+
31
+ /** SDK capture configuration: which events to capture. */
32
+ declare const CaptureConfigSchema: z.ZodObject<{
33
+ requestBodies: z.ZodBoolean;
34
+ queryParamValues: z.ZodBoolean;
35
+ envVarValues: z.ZodBoolean;
36
+ fullConsoleOutput: z.ZodBoolean;
37
+ importGraph: z.ZodBoolean;
38
+ consoleErrors: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
39
+ }, z.core.$strip>;
40
+ type CaptureConfig = z.infer<typeof CaptureConfigSchema>;
41
+ /** Developer-facing config for registerGlasstrace(). */
42
+ declare const GlasstraceOptionsSchema: z.ZodObject<{
43
+ apiKey: z.ZodOptional<z.ZodString>;
44
+ endpoint: z.ZodOptional<z.ZodString>;
45
+ forceEnable: z.ZodOptional<z.ZodBoolean>;
46
+ verbose: z.ZodOptional<z.ZodBoolean>;
47
+ }, z.core.$strip>;
48
+ type GlasstraceOptions = z.infer<typeof GlasstraceOptionsSchema>;
49
+ /** All recognized SDK environment variables. */
50
+ declare const GlasstraceEnvVarsSchema: z.ZodObject<{
51
+ GLASSTRACE_API_KEY: z.ZodOptional<z.ZodString>;
52
+ GLASSTRACE_FORCE_ENABLE: z.ZodOptional<z.ZodString>;
53
+ GLASSTRACE_ENV: z.ZodOptional<z.ZodString>;
54
+ GLASSTRACE_COVERAGE_MAP: z.ZodOptional<z.ZodString>;
55
+ NODE_ENV: z.ZodOptional<z.ZodString>;
56
+ VERCEL_ENV: z.ZodOptional<z.ZodString>;
57
+ }, z.core.$strip>;
58
+ type GlasstraceEnvVars = z.infer<typeof GlasstraceEnvVarsSchema>;
59
+
60
+ /**
61
+ * Wire format types for SDK ↔ backend communication.
62
+ *
63
+ * These schemas define the request/response shapes for:
64
+ * - SDK initialization (POST /v1/sdk/init)
65
+ * - SDK health diagnostics (embedded in init requests)
66
+ * - Discovery endpoint (GET /__glasstrace/config)
67
+ * - Source map upload (POST /v1/source-maps)
68
+ */
69
+
70
+ /** Test file import relationships, embedded in SDK init request. */
71
+ declare const ImportGraphPayloadSchema: z.ZodObject<{
72
+ buildHash: z.core.$ZodBranded<z.ZodString, "BuildHash", "out">;
73
+ graph: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
74
+ }, z.core.$strip>;
75
+ type ImportGraphPayload = z.infer<typeof ImportGraphPayloadSchema>;
76
+ /** SDK health diagnostics included in init requests. */
77
+ declare const SdkHealthReportSchema: z.ZodObject<{
78
+ tracesExportedSinceLastInit: z.ZodNumber;
79
+ tracesDropped: z.ZodNumber;
80
+ initFailures: z.ZodNumber;
81
+ configAge: z.ZodNumber;
82
+ sdkVersion: z.ZodString;
83
+ }, z.core.$strip>;
84
+ type SdkHealthReport = z.infer<typeof SdkHealthReportSchema>;
85
+ /**
86
+ * Response from POST /v1/sdk/init.
87
+ *
88
+ * Note: SdkInitRequest is intentionally NOT in the protocol package.
89
+ * The request schema includes backend-specific types (TierLimits,
90
+ * SubscriptionStatus) that are not part of the public contract.
91
+ * The backend owns the request validation; the SDK only needs to
92
+ * understand the response.
93
+ */
94
+ declare const SdkInitResponseSchema: z.ZodObject<{
95
+ config: z.ZodObject<{
96
+ requestBodies: z.ZodBoolean;
97
+ queryParamValues: z.ZodBoolean;
98
+ envVarValues: z.ZodBoolean;
99
+ fullConsoleOutput: z.ZodBoolean;
100
+ importGraph: z.ZodBoolean;
101
+ consoleErrors: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
102
+ }, z.core.$strip>;
103
+ subscriptionStatus: z.ZodString;
104
+ linkedAccountId: z.ZodOptional<z.ZodString>;
105
+ minimumSdkVersion: z.ZodString;
106
+ apiVersion: z.ZodString;
107
+ tierLimits: z.ZodObject<{
108
+ tracesPerMinute: z.ZodNumber;
109
+ storageTtlHours: z.ZodNumber;
110
+ maxTraceSizeBytes: z.ZodNumber;
111
+ maxConcurrentSessions: z.ZodNumber;
112
+ }, z.core.$strip>;
113
+ }, z.core.$strip>;
114
+ type SdkInitResponse = z.infer<typeof SdkInitResponseSchema>;
115
+ /** Response from POST /v1/source-maps. */
116
+ declare const SourceMapUploadResponseSchema: z.ZodObject<{
117
+ success: z.ZodLiteral<true>;
118
+ buildHash: z.core.$ZodBranded<z.ZodString, "BuildHash", "out">;
119
+ fileCount: z.ZodNumber;
120
+ totalSizeBytes: z.ZodNumber;
121
+ }, z.core.$strip>;
122
+ type SourceMapUploadResponse = z.infer<typeof SourceMapUploadResponseSchema>;
123
+
6
124
  /**
7
125
  * Internal SDK error class with a typed diagnostic code.
8
126
  * Caught at the boundary and converted to a log message + diagnostic entry.
package/dist/index.d.ts CHANGED
@@ -1,8 +1,126 @@
1
- import { SdkDiagnosticCode, GlasstraceEnvVars, GlasstraceOptions, SessionId, AnonApiKey, CaptureConfig, SdkInitResponse, ImportGraphPayload, SdkHealthReport, SourceMapUploadResponse } from '@glasstrace/protocol';
1
+ import * as z from './v4/classic/external.cjs';
2
2
  import { Context } from '@opentelemetry/api';
3
3
  import { SpanProcessor, Span, ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
4
4
  import { ExportResult } from '@opentelemetry/core';
5
5
 
6
+ /** Anonymous API key: `gt_anon_` + 48 hex chars. */
7
+ declare const AnonApiKeySchema: z.core.$ZodBranded<z.ZodString, "AnonApiKey", "out">;
8
+ type AnonApiKey = z.infer<typeof AnonApiKeySchema>;
9
+ /** Session ID: 16 hex chars (deterministic, derived from API key + time window). */
10
+ declare const SessionIdSchema: z.core.$ZodBranded<z.ZodString, "SessionId", "out">;
11
+ type SessionId = z.infer<typeof SessionIdSchema>;
12
+
13
+ /**
14
+ * SDK-specific enums.
15
+ */
16
+
17
+ /** Diagnostic codes the SDK can report during health checks. */
18
+ declare const SdkDiagnosticCodeSchema: z.ZodEnum<{
19
+ ingestion_unreachable: "ingestion_unreachable";
20
+ ingestion_auth_failed: "ingestion_auth_failed";
21
+ ingestion_rate_limited: "ingestion_rate_limited";
22
+ config_sync_failed: "config_sync_failed";
23
+ source_map_upload_failed: "source_map_upload_failed";
24
+ }>;
25
+ type SdkDiagnosticCode = z.infer<typeof SdkDiagnosticCodeSchema>;
26
+
27
+ /**
28
+ * SDK configuration types.
29
+ */
30
+
31
+ /** SDK capture configuration: which events to capture. */
32
+ declare const CaptureConfigSchema: z.ZodObject<{
33
+ requestBodies: z.ZodBoolean;
34
+ queryParamValues: z.ZodBoolean;
35
+ envVarValues: z.ZodBoolean;
36
+ fullConsoleOutput: z.ZodBoolean;
37
+ importGraph: z.ZodBoolean;
38
+ consoleErrors: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
39
+ }, z.core.$strip>;
40
+ type CaptureConfig = z.infer<typeof CaptureConfigSchema>;
41
+ /** Developer-facing config for registerGlasstrace(). */
42
+ declare const GlasstraceOptionsSchema: z.ZodObject<{
43
+ apiKey: z.ZodOptional<z.ZodString>;
44
+ endpoint: z.ZodOptional<z.ZodString>;
45
+ forceEnable: z.ZodOptional<z.ZodBoolean>;
46
+ verbose: z.ZodOptional<z.ZodBoolean>;
47
+ }, z.core.$strip>;
48
+ type GlasstraceOptions = z.infer<typeof GlasstraceOptionsSchema>;
49
+ /** All recognized SDK environment variables. */
50
+ declare const GlasstraceEnvVarsSchema: z.ZodObject<{
51
+ GLASSTRACE_API_KEY: z.ZodOptional<z.ZodString>;
52
+ GLASSTRACE_FORCE_ENABLE: z.ZodOptional<z.ZodString>;
53
+ GLASSTRACE_ENV: z.ZodOptional<z.ZodString>;
54
+ GLASSTRACE_COVERAGE_MAP: z.ZodOptional<z.ZodString>;
55
+ NODE_ENV: z.ZodOptional<z.ZodString>;
56
+ VERCEL_ENV: z.ZodOptional<z.ZodString>;
57
+ }, z.core.$strip>;
58
+ type GlasstraceEnvVars = z.infer<typeof GlasstraceEnvVarsSchema>;
59
+
60
+ /**
61
+ * Wire format types for SDK ↔ backend communication.
62
+ *
63
+ * These schemas define the request/response shapes for:
64
+ * - SDK initialization (POST /v1/sdk/init)
65
+ * - SDK health diagnostics (embedded in init requests)
66
+ * - Discovery endpoint (GET /__glasstrace/config)
67
+ * - Source map upload (POST /v1/source-maps)
68
+ */
69
+
70
+ /** Test file import relationships, embedded in SDK init request. */
71
+ declare const ImportGraphPayloadSchema: z.ZodObject<{
72
+ buildHash: z.core.$ZodBranded<z.ZodString, "BuildHash", "out">;
73
+ graph: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
74
+ }, z.core.$strip>;
75
+ type ImportGraphPayload = z.infer<typeof ImportGraphPayloadSchema>;
76
+ /** SDK health diagnostics included in init requests. */
77
+ declare const SdkHealthReportSchema: z.ZodObject<{
78
+ tracesExportedSinceLastInit: z.ZodNumber;
79
+ tracesDropped: z.ZodNumber;
80
+ initFailures: z.ZodNumber;
81
+ configAge: z.ZodNumber;
82
+ sdkVersion: z.ZodString;
83
+ }, z.core.$strip>;
84
+ type SdkHealthReport = z.infer<typeof SdkHealthReportSchema>;
85
+ /**
86
+ * Response from POST /v1/sdk/init.
87
+ *
88
+ * Note: SdkInitRequest is intentionally NOT in the protocol package.
89
+ * The request schema includes backend-specific types (TierLimits,
90
+ * SubscriptionStatus) that are not part of the public contract.
91
+ * The backend owns the request validation; the SDK only needs to
92
+ * understand the response.
93
+ */
94
+ declare const SdkInitResponseSchema: z.ZodObject<{
95
+ config: z.ZodObject<{
96
+ requestBodies: z.ZodBoolean;
97
+ queryParamValues: z.ZodBoolean;
98
+ envVarValues: z.ZodBoolean;
99
+ fullConsoleOutput: z.ZodBoolean;
100
+ importGraph: z.ZodBoolean;
101
+ consoleErrors: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
102
+ }, z.core.$strip>;
103
+ subscriptionStatus: z.ZodString;
104
+ linkedAccountId: z.ZodOptional<z.ZodString>;
105
+ minimumSdkVersion: z.ZodString;
106
+ apiVersion: z.ZodString;
107
+ tierLimits: z.ZodObject<{
108
+ tracesPerMinute: z.ZodNumber;
109
+ storageTtlHours: z.ZodNumber;
110
+ maxTraceSizeBytes: z.ZodNumber;
111
+ maxConcurrentSessions: z.ZodNumber;
112
+ }, z.core.$strip>;
113
+ }, z.core.$strip>;
114
+ type SdkInitResponse = z.infer<typeof SdkInitResponseSchema>;
115
+ /** Response from POST /v1/source-maps. */
116
+ declare const SourceMapUploadResponseSchema: z.ZodObject<{
117
+ success: z.ZodLiteral<true>;
118
+ buildHash: z.core.$ZodBranded<z.ZodString, "BuildHash", "out">;
119
+ fileCount: z.ZodNumber;
120
+ totalSizeBytes: z.ZodNumber;
121
+ }, z.core.$strip>;
122
+ type SourceMapUploadResponse = z.infer<typeof SourceMapUploadResponseSchema>;
123
+
6
124
  /**
7
125
  * Internal SDK error class with a typed diagnostic code.
8
126
  * Caught at the boundary and converted to a log message + diagnostic entry.
package/dist/index.js CHANGED
@@ -1,8 +1,17 @@
1
1
  import {
2
+ AnonApiKeySchema,
3
+ DEFAULT_CAPTURE_CONFIG,
4
+ GLASSTRACE_ATTRIBUTE_NAMES,
5
+ SdkCachedConfigSchema,
6
+ SdkInitResponseSchema,
7
+ SessionIdSchema,
8
+ SourceMapUploadResponseSchema,
2
9
  buildImportGraph,
10
+ createAnonApiKey,
3
11
  discoverTestFiles,
4
12
  extractImports
5
- } from "./chunk-BKMITIEZ.js";
13
+ } from "./chunk-CUFIV225.js";
14
+ import "./chunk-PZ5AY32C.js";
6
15
 
7
16
  // src/errors.ts
8
17
  var SdkError = class extends Error {
@@ -66,7 +75,6 @@ function isAnonymousMode(config) {
66
75
 
67
76
  // src/session.ts
68
77
  import { createHash } from "crypto";
69
- import { SessionIdSchema } from "@glasstrace/protocol";
70
78
  var FOUR_HOURS_MS = 4 * 60 * 60 * 1e3;
71
79
  var cachedGlasstraceEnv = process.env.GLASSTRACE_ENV;
72
80
  var cachedPort = process.env.PORT ?? "3000";
@@ -160,7 +168,6 @@ function classifyFetchTarget(url) {
160
168
  // src/anon-key.ts
161
169
  import { readFile, writeFile, mkdir, chmod } from "fs/promises";
162
170
  import { join } from "path";
163
- import { AnonApiKeySchema, createAnonApiKey } from "@glasstrace/protocol";
164
171
  var GLASSTRACE_DIR = ".glasstrace";
165
172
  var ANON_KEY_FILE = "anon_key";
166
173
  var ephemeralKeyCache = /* @__PURE__ */ new Map();
@@ -211,11 +218,6 @@ async function getOrCreateAnonKey(projectRoot) {
211
218
  import { readFileSync } from "fs";
212
219
  import { writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
213
220
  import { join as join2 } from "path";
214
- import {
215
- SdkInitResponseSchema,
216
- SdkCachedConfigSchema,
217
- DEFAULT_CAPTURE_CONFIG
218
- } from "@glasstrace/protocol";
219
221
  var GLASSTRACE_DIR2 = ".glasstrace";
220
222
  var CONFIG_FILE = "config";
221
223
  var TWENTY_FOUR_HOURS_MS = 24 * 60 * 60 * 1e3;
@@ -411,7 +413,6 @@ var GlasstraceSpanProcessor = class {
411
413
 
412
414
  // src/enriching-exporter.ts
413
415
  import { SpanKind } from "@opentelemetry/api";
414
- import { GLASSTRACE_ATTRIBUTE_NAMES } from "@glasstrace/protocol";
415
416
  var ATTR = GLASSTRACE_ATTRIBUTE_NAMES;
416
417
  var API_KEY_PENDING = "pending";
417
418
  var MAX_PENDING_SPANS = 1024;
@@ -1082,7 +1083,7 @@ function registerGlasstrace(options) {
1082
1083
  if (config.verbose) {
1083
1084
  console.info("[glasstrace] Background init firing.");
1084
1085
  }
1085
- await performInit(config, anonKey, "0.2.0");
1086
+ await performInit(config, anonKey, "0.2.1");
1086
1087
  maybeInstallConsoleCapture();
1087
1088
  } catch (err) {
1088
1089
  console.warn(
@@ -1102,7 +1103,7 @@ function registerGlasstrace(options) {
1102
1103
  if (config.verbose) {
1103
1104
  console.info("[glasstrace] Background init firing.");
1104
1105
  }
1105
- await performInit(config, anonKey, "0.2.0");
1106
+ await performInit(config, anonKey, "0.2.1");
1106
1107
  maybeInstallConsoleCapture();
1107
1108
  } catch (err) {
1108
1109
  console.warn(
@@ -1124,7 +1125,7 @@ function registerGlasstrace(options) {
1124
1125
  if (config.verbose) {
1125
1126
  console.info("[glasstrace] Background init firing.");
1126
1127
  }
1127
- await performInit(config, anonKeyForInit, "0.2.0");
1128
+ await performInit(config, anonKeyForInit, "0.2.1");
1128
1129
  maybeInstallConsoleCapture();
1129
1130
  } catch (err) {
1130
1131
  console.warn(
@@ -1166,9 +1167,6 @@ import * as fs from "fs/promises";
1166
1167
  import * as path from "path";
1167
1168
  import * as crypto from "crypto";
1168
1169
  import { execSync } from "child_process";
1169
- import {
1170
- SourceMapUploadResponseSchema
1171
- } from "@glasstrace/protocol";
1172
1170
  async function collectSourceMaps(buildDir) {
1173
1171
  const results = [];
1174
1172
  try {