@observa/sdk 2.4.0 → 2.4.5

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 (79) hide show
  1. package/README.md +140 -176
  2. package/dist/apis/ingestApi.d.ts +1 -15
  3. package/dist/apis/ingestApi.d.ts.map +1 -1
  4. package/dist/apis/ingestApi.js +2 -151
  5. package/dist/apis/ingestApi.js.map +1 -1
  6. package/dist/apis/uptimeApi.js +1 -1
  7. package/dist/apis/uptimeApi.js.map +1 -1
  8. package/dist/domain/ingest.d.ts +4 -33
  9. package/dist/domain/ingest.d.ts.map +1 -1
  10. package/dist/http/httpClient.d.ts +5 -2
  11. package/dist/http/httpClient.d.ts.map +1 -1
  12. package/dist/http/httpClient.js +44 -8
  13. package/dist/http/httpClient.js.map +1 -1
  14. package/dist/index.d.ts +18 -507
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +17 -582
  17. package/dist/index.js.map +1 -1
  18. package/dist/sdk.d.ts +4 -9
  19. package/dist/sdk.d.ts.map +1 -1
  20. package/dist/sdk.js +7 -19
  21. package/dist/sdk.js.map +1 -1
  22. package/package.json +9 -16
  23. package/dist/src/apis/ingestApi.d.ts +0 -22
  24. package/dist/src/apis/ingestApi.js +0 -167
  25. package/dist/src/apis/ingestApi.js.map +0 -1
  26. package/dist/src/apis/uptimeApi.d.ts +0 -11
  27. package/dist/src/apis/uptimeApi.js +0 -39
  28. package/dist/src/apis/uptimeApi.js.map +0 -1
  29. package/dist/src/domain/ingest.d.ts +0 -47
  30. package/dist/src/domain/ingest.js +0 -2
  31. package/dist/src/domain/ingest.js.map +0 -1
  32. package/dist/src/domain/uptime.d.ts +0 -23
  33. package/dist/src/domain/uptime.js +0 -2
  34. package/dist/src/domain/uptime.js.map +0 -1
  35. package/dist/src/http/errors.d.ts +0 -33
  36. package/dist/src/http/errors.js +0 -54
  37. package/dist/src/http/errors.js.map +0 -1
  38. package/dist/src/http/httpClient.d.ts +0 -45
  39. package/dist/src/http/httpClient.js +0 -165
  40. package/dist/src/http/httpClient.js.map +0 -1
  41. package/dist/src/index.d.ts +0 -12
  42. package/dist/src/index.js +0 -7
  43. package/dist/src/index.js.map +0 -1
  44. package/dist/src/sdk.d.ts +0 -23
  45. package/dist/src/sdk.js +0 -40
  46. package/dist/src/sdk.js.map +0 -1
  47. package/dist/src/utils/processContext.d.ts +0 -34
  48. package/dist/src/utils/processContext.js +0 -47
  49. package/dist/src/utils/processContext.js.map +0 -1
  50. package/dist/src/utils/validate.d.ts +0 -2
  51. package/dist/src/utils/validate.js +0 -12
  52. package/dist/src/utils/validate.js.map +0 -1
  53. package/dist/tests/httpClient.test.d.ts +0 -1
  54. package/dist/tests/httpClient.test.js +0 -47
  55. package/dist/tests/httpClient.test.js.map +0 -1
  56. package/dist/tests/ingestApi.test.d.ts +0 -1
  57. package/dist/tests/ingestApi.test.js +0 -65
  58. package/dist/tests/ingestApi.test.js.map +0 -1
  59. package/dist/tests/observaSdk.integration.test.d.ts +0 -1
  60. package/dist/tests/observaSdk.integration.test.js +0 -51
  61. package/dist/tests/observaSdk.integration.test.js.map +0 -1
  62. package/dist/tests/sdk.test.d.ts +0 -1
  63. package/dist/tests/sdk.test.js +0 -104
  64. package/dist/tests/sdk.test.js.map +0 -1
  65. package/dist/tsconfig.build.tsbuildinfo +0 -1
  66. package/dist/utils/processContext.d.ts +0 -35
  67. package/dist/utils/processContext.d.ts.map +0 -1
  68. package/dist/utils/processContext.js +0 -47
  69. package/dist/utils/processContext.js.map +0 -1
  70. package/src/apis/ingestApi.ts +0 -199
  71. package/src/apis/uptimeApi.ts +0 -58
  72. package/src/domain/ingest.ts +0 -93
  73. package/src/domain/uptime.ts +0 -86
  74. package/src/http/errors.ts +0 -88
  75. package/src/http/httpClient.ts +0 -284
  76. package/src/index.ts +0 -68
  77. package/src/sdk.ts +0 -107
  78. package/src/utils/processContext.ts +0 -84
  79. package/src/utils/validate.ts +0 -19
package/dist/index.js CHANGED
@@ -1,583 +1,18 @@
1
- // src/apis/ingestApi.ts
2
- import { randomUUID } from "crypto";
3
-
4
- // src/http/errors.ts
5
- var SdkError = class extends Error {
6
- status;
7
- code;
8
- details;
9
- /**
10
- * Creates an error with optional metadata.
11
- */
12
- constructor(message, details) {
13
- super(message);
14
- this.name = new.target.name;
15
- this.status = details?.status;
16
- this.code = details?.code;
17
- this.details = details?.details;
18
- }
19
- };
20
- var ValidationError = class extends SdkError {
21
- };
22
- var AuthError = class extends SdkError {
23
- };
24
- var ForbiddenError = class extends SdkError {
25
- };
26
- var NotFoundError = class extends SdkError {
27
- };
28
- var ConflictError = class extends SdkError {
29
- };
30
- var RateLimitError = class extends SdkError {
31
- retryAfter;
32
- constructor(message, details) {
33
- super(message, details);
34
- this.retryAfter = details?.retryAfter;
35
- }
36
- };
37
- var ServerError = class extends SdkError {
38
- };
39
- var NetworkError = class extends SdkError {
40
- };
41
- var TimeoutError = class extends SdkError {
42
- };
43
- function mapHttpError(status, details, retryAfter) {
44
- const info = { status, details, retryAfter };
45
- if (status === 400) return new ValidationError("Invalid request", info);
46
- if (status === 401) return new AuthError("Unauthorized", info);
47
- if (status === 403) return new ForbiddenError("Forbidden", info);
48
- if (status === 404) return new NotFoundError("Resource not found", info);
49
- if (status === 409) return new ConflictError("Conflict", info);
50
- if (status === 429) return new RateLimitError("Rate limit exceeded", info);
51
- if (status >= 500) return new ServerError("Server error", info);
52
- return new SdkError("HTTP error", info);
53
- }
54
-
55
- // src/utils/processContext.ts
56
- function getProcessContext(options) {
57
- const includeStatic = options?.includeStatic ?? true;
58
- const includeDynamic = options?.includeDynamic ?? true;
59
- const includeVersions = options?.includeVersions ?? true;
60
- const includeRuntime = options?.includeRuntime ?? true;
61
- const includePid = options?.includePid ?? true;
62
- const includeUptime = options?.includeUptime ?? true;
63
- const includeMemory = options?.includeMemory ?? true;
64
- const context = {};
65
- if (includeDynamic) {
66
- if (includePid) context.pid = process.pid;
67
- if (includeUptime) context.uptimeSeconds = Math.round(process.uptime());
68
- if (includeMemory) context.memory = process.memoryUsage();
69
- }
70
- if (includeStatic) {
71
- if (includeVersions) context.versions = process.versions;
72
- if (includeRuntime) {
73
- context.node = process.versions.node;
74
- context.platform = process.platform;
75
- context.arch = process.arch;
76
- context.releaseName = process.release?.name;
77
- }
78
- }
79
- return context;
80
- }
81
- function getProcessContextStatic(options) {
82
- return getProcessContext({
83
- includeDynamic: false,
84
- includeStatic: true,
85
- includeVersions: options?.includeVersions,
86
- includeRuntime: options?.includeRuntime
87
- });
88
- }
89
- function getProcessContextDynamic(options) {
90
- return getProcessContext({
91
- includeStatic: false,
92
- includeDynamic: true,
93
- includePid: options?.includePid,
94
- includeUptime: options?.includeUptime,
95
- includeMemory: options?.includeMemory
96
- });
97
- }
98
-
99
- // src/utils/validate.ts
100
- function ensureNonEmpty(value, name) {
101
- if (!value || value.trim().length === 0) {
102
- throw new ValidationError(`${name} is required`);
103
- }
104
- }
105
- function ensureDefined(value, name) {
106
- if (value === null || value === void 0) {
107
- throw new ValidationError(`${name} is required`);
108
- }
109
- }
110
-
111
- // src/apis/ingestApi.ts
112
- var DEFAULT_NORMALIZATION = {
113
- schemaVersion: 1,
114
- includeContext: true,
115
- includeSystemContext: true,
116
- includeRuntimeContext: true,
117
- maxEventBytes: 64 * 1024,
118
- maxFrames: 60,
119
- maxMessageLength: 4e3,
120
- maxExceptionValueLength: 4e3
121
- };
122
- var IngestApi = class {
123
- /**
124
- * Creates the ingestion client with an optional default DSN and PublicKey.
125
- */
126
- constructor(http, defaultDsnKey, normalization, defaultPublicKey) {
127
- this.http = http;
128
- this.defaultDsnKey = defaultDsnKey;
129
- this.normalization = normalization;
130
- this.defaultPublicKey = defaultPublicKey;
131
- }
132
- /**
133
- * Sends an event to the ingestion backend.
134
- */
135
- async event(input) {
136
- ensureDefined(input, "input");
137
- const dsnKey = input.dsnKey ?? this.defaultDsnKey;
138
- const publicKey = input.publicKey ?? this.defaultPublicKey;
139
- ensureDefined(dsnKey, "dsnKey");
140
- ensureNonEmpty(dsnKey, "dsnKey");
141
- ensureDefined(input.event, "event");
142
- if (!this.http.hasApiKey() && !publicKey) {
143
- throw new ValidationError("publicKey is required when apiKey is not provided");
144
- }
145
- if (input.idempotencyKey && input.idempotencyKey.length > 128) {
146
- throw new ValidationError("idempotencyKey must be at most 128 characters");
147
- }
148
- const headers = {};
149
- if (input.idempotencyKey) headers["x-idempotency-key"] = input.idempotencyKey;
150
- if (input.sdkVersion) headers["x-sdk-version"] = input.sdkVersion;
151
- const { idempotencyKey, sdkVersion, event, ...body } = input;
152
- const normalizedEvent = normalizeEvent(event, this.normalization);
153
- const authMode = this.http.hasApiKey() ? "apiKey" : "none";
154
- return this.http.post("/ingest/events", { ...body, dsnKey, publicKey, event: normalizedEvent }, { auth: authMode, headers });
155
- }
156
- async health(dsnKey, publicKey) {
157
- const resolvedDsnKey = dsnKey ?? this.defaultDsnKey;
158
- const resolvedPublicKey = publicKey ?? this.defaultPublicKey;
159
- ensureDefined(resolvedDsnKey, "dsnKey");
160
- ensureNonEmpty(resolvedDsnKey, "dsnKey");
161
- const authMode = this.http.hasApiKey() ? "apiKey" : "none";
162
- return this.http.post("/ingest/health", { dsnKey: resolvedDsnKey, publicKey: resolvedPublicKey }, { auth: authMode });
163
- }
164
- };
165
- function normalizeEvent(event, options) {
166
- const config = { ...DEFAULT_NORMALIZATION, ...options };
167
- const normalizedTimestamp = normalizeTimestamp(event.timestamp);
168
- const normalizedLevel = event.level ? event.level.toLowerCase() : void 0;
169
- const normalizedMessage = event.message ? truncate(event.message, config.maxMessageLength) : void 0;
170
- const normalizedException = normalizeException(event.exception, config);
171
- if (!normalizedMessage && !normalizedException) {
172
- throw new ValidationError("event message or exception is required");
173
- }
174
- const normalizedContext = normalizeContext(event.context, config);
175
- const normalizedEvent = {
176
- ...event,
177
- event_id: event.event_id ?? randomUUID(),
178
- timestamp: normalizedTimestamp,
179
- schema_version: event.schema_version ?? config.schemaVersion,
180
- level: normalizedLevel,
181
- message: normalizedMessage,
182
- exception: normalizedException,
183
- context: normalizedContext
184
- };
185
- return enforceSizeLimit(normalizedEvent, config);
186
- }
187
- function normalizeTimestamp(timestamp) {
188
- if (!timestamp) return (/* @__PURE__ */ new Date()).toISOString();
189
- const parsed = new Date(timestamp);
190
- if (Number.isNaN(parsed.getTime())) {
191
- throw new ValidationError("timestamp must be a valid ISO date");
192
- }
193
- return parsed.toISOString();
194
- }
195
- function normalizeException(exception, config) {
196
- if (!exception) return void 0;
197
- if (!exception.type || !exception.value) {
198
- throw new ValidationError("exception.type and exception.value are required");
199
- }
200
- return {
201
- ...exception,
202
- value: truncate(exception.value, config.maxExceptionValueLength),
203
- stacktrace: normalizeStacktrace(exception.stacktrace, config.maxFrames)
204
- };
205
- }
206
- function normalizeStacktrace(stacktrace, maxFrames) {
207
- if (!stacktrace || !Array.isArray(stacktrace.frames)) return void 0;
208
- const frames = stacktrace.frames;
209
- const normalizedFrames = frames.slice(0, maxFrames).map((frame) => {
210
- const filename = typeof frame?.filename === "string" ? frame.filename : void 0;
211
- const functionName = typeof frame?.function === "string" ? frame.function : void 0;
212
- const lineno = typeof frame?.lineno === "number" ? frame.lineno : void 0;
213
- const colno = typeof frame?.colno === "number" ? frame.colno : void 0;
214
- const inferredInApp = filename ? !filename.includes("node_modules") : false;
215
- return {
216
- filename,
217
- function: functionName,
218
- lineno,
219
- colno,
220
- in_app: typeof frame?.in_app === "boolean" ? frame.in_app : inferredInApp
221
- };
222
- });
223
- return { frames: normalizedFrames };
224
- }
225
- function normalizeContext(context, config) {
226
- if (!config.includeContext) return context;
227
- const systemContext = config.includeSystemContext ? getProcessContextDynamic() : void 0;
228
- const runtimeContext = config.includeRuntimeContext ? getProcessContextStatic({ includeVersions: false }) : void 0;
229
- const mergedContext = {
230
- ...context,
231
- system: context?.system ?? systemContext,
232
- runtime: context?.runtime ?? runtimeContext
233
- };
234
- return mergedContext;
235
- }
236
- function enforceSizeLimit(event, config) {
237
- let normalized = event;
238
- if (getSize(normalized) <= config.maxEventBytes) return normalized;
239
- if (normalized.extra) {
240
- normalized = { ...normalized, extra: void 0 };
241
- }
242
- if (getSize(normalized) <= config.maxEventBytes) return normalized;
243
- if (normalized.tags) {
244
- normalized = { ...normalized, tags: void 0 };
245
- }
246
- if (getSize(normalized) <= config.maxEventBytes) return normalized;
247
- if (normalized.exception?.stacktrace) {
248
- normalized = {
249
- ...normalized,
250
- exception: { ...normalized.exception, stacktrace: void 0 }
251
- };
252
- }
253
- if (getSize(normalized) <= config.maxEventBytes) return normalized;
254
- if (normalized.message) {
255
- normalized = { ...normalized, message: truncate(normalized.message, config.maxMessageLength) };
256
- }
257
- if (normalized.exception?.value) {
258
- normalized = {
259
- ...normalized,
260
- exception: { ...normalized.exception, value: truncate(normalized.exception.value, config.maxExceptionValueLength) }
261
- };
262
- }
263
- if (getSize(normalized) <= config.maxEventBytes) return normalized;
264
- throw new ValidationError("event payload exceeds size limit");
265
- }
266
- function getSize(value) {
267
- return Buffer.byteLength(JSON.stringify(value), "utf8");
268
- }
269
- function truncate(value, maxLength) {
270
- if (value.length <= maxLength) return value;
271
- return value.slice(0, maxLength);
272
- }
273
-
274
- // src/apis/uptimeApi.ts
275
- var UptimeApi = class {
276
- /**
277
- * Creates the uptime client with an optional default DSN.
278
- */
279
- constructor(http, defaultDsnKey) {
280
- this.http = http;
281
- this.defaultDsnKey = defaultDsnKey;
282
- }
283
- /**
284
- * Records an uptime heartbeat.
285
- */
286
- async recordHeartbeat(input) {
287
- ensureDefined(input, "input");
288
- const dsnKey = input.dsnKey ?? this.defaultDsnKey;
289
- ensureDefined(dsnKey, "dsnKey");
290
- ensureNonEmpty(dsnKey, "dsnKey");
291
- ensureNonEmpty(input.status, "status");
292
- return this.http.post("/uptime/heartbeats", { ...input, dsnKey }, { auth: "apiKey" });
293
- }
294
- /**
295
- * Lists a project's daily uptime history.
296
- */
297
- async history(projectId, date) {
298
- ensureNonEmpty(projectId, "projectId");
299
- ensureNonEmpty(date, "date");
300
- return this.http.get(`/projects/${encodeURIComponent(projectId)}/uptime/history`, {
301
- query: { date },
302
- auth: "none"
303
- });
304
- }
305
- /**
306
- * Gets the latest uptime event for a project.
307
- */
308
- async latest(projectId) {
309
- ensureNonEmpty(projectId, "projectId");
310
- return this.http.get(`/projects/${encodeURIComponent(projectId)}/uptime/latest`, {
311
- auth: "none"
312
- });
313
- }
314
- /**
315
- * Summarizes daily uptime.
316
- */
317
- async summary(projectId, days, delayThresholdMinutes) {
318
- ensureNonEmpty(projectId, "projectId");
319
- return this.http.get(`/projects/${encodeURIComponent(projectId)}/uptime/summary`, {
320
- query: { days, delayThresholdMinutes },
321
- auth: "none"
322
- });
323
- }
324
- };
325
-
326
- // src/http/httpClient.ts
327
- var HttpClient = class {
328
- apiKey;
329
- baseUrl;
330
- timeoutMs;
331
- headers;
332
- retry;
333
- healthCheckPromise;
334
- /**
335
- * Creates an HTTP client with baseUrl and optional apiKey.
336
- */
337
- constructor(options) {
338
- this.baseUrl = options.baseUrl.replace(/\/+$/, "");
339
- this.apiKey = options.apiKey;
340
- this.timeoutMs = options.timeoutMs ?? 5e3;
341
- this.headers = options.headers ?? {};
342
- this.retry = options.retry;
343
- }
344
- /**
345
- * Updates the API key at runtime.
346
- */
347
- setApiKey(apiKey) {
348
- this.apiKey = apiKey;
349
- }
350
- /**
351
- * Checks if an API key is configured.
352
- */
353
- hasApiKey() {
354
- return !!this.apiKey;
355
- }
356
- startHealthCheck(healthCheck) {
357
- if (!this.healthCheckPromise) {
358
- const promise = healthCheck();
359
- this.healthCheckPromise = promise;
360
- promise.catch(() => void 0);
361
- }
362
- }
363
- /**
364
- * GET request.
365
- */
366
- async get(path, options) {
367
- return this.request({ method: "GET", path, ...options });
368
- }
369
- /**
370
- * POST request.
371
- */
372
- async post(path, body, options) {
373
- return this.request({ method: "POST", path, body, ...options });
374
- }
375
- /**
376
- * PUT request.
377
- */
378
- async put(path, body, options) {
379
- return this.request({ method: "PUT", path, body, ...options });
380
- }
381
- /**
382
- * PATCH request.
383
- */
384
- async patch(path, body, options) {
385
- return this.request({ method: "PATCH", path, body, ...options });
386
- }
387
- /**
388
- * DELETE request.
389
- */
390
- async delete(path, options) {
391
- return this.request({ method: "DELETE", path, ...options });
392
- }
393
- /**
394
- * Executes a request with retry logic.
395
- */
396
- async request(options) {
397
- if (this.healthCheckPromise) {
398
- await this.healthCheckPromise;
399
- }
400
- const retry = this.retry ?? { retries: 0 };
401
- const retryOn = retry.retryOn ?? ((response, error) => {
402
- if (response) return response.status === 429 || response.status >= 500;
403
- return error instanceof NetworkError || error instanceof TimeoutError || error instanceof TypeError;
404
- });
405
- const retryDelayMs = retry.retryDelayMs ?? ((attempt) => Math.min(1e3 * 2 ** (attempt - 1), 8e3));
406
- let lastError;
407
- for (let attempt = 0; attempt <= retry.retries; attempt += 1) {
408
- try {
409
- const { response, data } = await this.execute(options);
410
- if (!response.ok) {
411
- const retryAfter = this.parseRetryAfter(response.headers.get("retry-after"));
412
- const error = mapHttpError(response.status, data, retryAfter);
413
- if (retryOn(response, error) && attempt < retry.retries) {
414
- await this.delay(retryDelayMs(attempt + 1, response, error));
415
- continue;
416
- }
417
- throw error;
418
- }
419
- return data;
420
- } catch (error) {
421
- lastError = error;
422
- if (retryOn(void 0, error) && attempt < retry.retries) {
423
- await this.delay(retryDelayMs(attempt + 1, void 0, error));
424
- continue;
425
- }
426
- throw error;
427
- }
428
- }
429
- throw lastError;
430
- }
431
- /**
432
- * Executes a request without retry and returns response + data.
433
- */
434
- async execute(options) {
435
- const url = this.buildUrl(options.path, options.query);
436
- const headers = { ...this.headers, ...options.headers };
437
- if (options.body !== void 0) headers["content-type"] = "application/json";
438
- const authMode = options.auth ?? "none";
439
- if (authMode === "apiKey") {
440
- if (!this.apiKey) throw new AuthError("API key is required");
441
- headers["x-api-key"] = this.apiKey;
442
- }
443
- const controller = new AbortController();
444
- const timer = setTimeout(() => controller.abort(), this.timeoutMs);
445
- try {
446
- const response = await fetch(url, {
447
- method: options.method,
448
- headers,
449
- body: options.body === void 0 ? void 0 : JSON.stringify(options.body),
450
- signal: controller.signal
451
- });
452
- const data = await this.readBody(response);
453
- return { response, data };
454
- } catch (error) {
455
- if (error?.name === "AbortError") {
456
- throw new TimeoutError("Request timeout");
457
- }
458
- if (error instanceof NetworkError || error instanceof TimeoutError) throw error;
459
- if (error instanceof Error) {
460
- if (error instanceof AuthError) throw error;
461
- }
462
- if (error instanceof Error && "status" in error) throw error;
463
- throw new NetworkError("Network error", { details: error });
464
- } finally {
465
- clearTimeout(timer);
466
- }
467
- }
468
- /**
469
- * Builds the final URL with query params.
470
- */
471
- buildUrl(path, query) {
472
- const base = this.baseUrl;
473
- const fullPath = path.startsWith("http") ? path : `${base}${path.startsWith("/") ? "" : "/"}${path}`;
474
- if (!query) return fullPath;
475
- const params = new URLSearchParams();
476
- for (const [key, value] of Object.entries(query)) {
477
- if (value === void 0) continue;
478
- params.set(key, String(value));
479
- }
480
- const suffix = params.toString();
481
- return suffix ? `${fullPath}?${suffix}` : fullPath;
482
- }
483
- /**
484
- * Parses the body as JSON when possible.
485
- */
486
- async readBody(response) {
487
- if (response.status === 204) return void 0;
488
- const text = await response.text();
489
- if (!text) return void 0;
490
- try {
491
- return JSON.parse(text);
492
- } catch {
493
- return text;
494
- }
495
- }
496
- parseRetryAfter(value) {
497
- if (!value) return void 0;
498
- const seconds = Number(value);
499
- if (!Number.isNaN(seconds) && Number.isFinite(seconds)) {
500
- return Math.max(0, seconds);
501
- }
502
- const parsedDate = Date.parse(value);
503
- if (Number.isNaN(parsedDate)) return void 0;
504
- const diffMs = parsedDate - Date.now();
505
- if (diffMs <= 0) return 0;
506
- return Math.ceil(diffMs / 1e3);
507
- }
508
- /**
509
- * Simple delay for retries.
510
- */
511
- async delay(ms) {
512
- await new Promise((resolve) => setTimeout(resolve, ms));
513
- }
514
- };
515
-
516
- // src/sdk.ts
517
- var DEFAULT_BASE_URL = "https://backend-observa-production.up.railway.app/v1";
518
- var ObservaSDK = class {
519
- /**
520
- * Uptime API (heartbeats and public reads).
521
- */
522
- uptime;
523
- /**
524
- * Event ingestion API.
525
- */
526
- ingest;
527
- http;
528
- /**
529
- * Creates an SDK instance with required dsnKey and either apiKey or publicKey.
530
- */
531
- constructor(options) {
532
- if (!options || !options.apiKey && !options.publicKey || !options.dsnKey) {
533
- throw new Error("ObservaSDK requires dsnKey and either apiKey or publicKey");
534
- }
535
- const baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
536
- const normalizedBaseUrl = baseUrl.endsWith("/v1") ? baseUrl : `${baseUrl}/v1`;
537
- this.http = new HttpClient({
538
- baseUrl: normalizedBaseUrl,
539
- apiKey: options.apiKey,
540
- timeoutMs: options.timeoutMs,
541
- retry: options.retry,
542
- headers: options.headers
543
- });
544
- this.ingest = new IngestApi(this.http, options.dsnKey, options.ingest, options.publicKey);
545
- this.uptime = new UptimeApi(this.http, options.dsnKey);
546
- this.http.startHealthCheck(() => this.ingest.health(options.dsnKey, options.publicKey));
547
- }
548
- /**
549
- * Updates the API key used by the SDK at runtime.
550
- */
551
- setApiKey(apiKey) {
552
- this.http.setApiKey(apiKey);
553
- }
554
- getProcessContext(options) {
555
- return getProcessContext(options);
556
- }
557
- getProcessContextStatic(options) {
558
- return getProcessContextStatic(options);
559
- }
560
- getProcessContextDynamic(options) {
561
- return getProcessContextDynamic(options);
562
- }
563
- };
564
- export {
565
- AuthError,
566
- ConflictError,
567
- ForbiddenError,
568
- HttpClient,
569
- IngestApi,
570
- NetworkError,
571
- NotFoundError,
572
- ObservaSDK,
573
- RateLimitError,
574
- SdkError,
575
- ServerError,
576
- TimeoutError,
577
- UptimeApi,
578
- ValidationError,
579
- getProcessContext,
580
- getProcessContextDynamic,
581
- getProcessContextStatic
582
- };
1
+ /**
2
+ * Main SDK.
3
+ */
4
+ export { ObservaSDK } from './sdk';
5
+ /**
6
+ * Base HTTP client.
7
+ */
8
+ export { HttpClient } from './http/httpClient';
9
+ /**
10
+ * Typed SDK errors.
11
+ */
12
+ export { SdkError, ValidationError, AuthError, ForbiddenError, NotFoundError, ConflictError, RateLimitError, ServerError, NetworkError, TimeoutError, } from './http/errors';
13
+ /**
14
+ * Domain APIs.
15
+ */
16
+ export { UptimeApi } from './apis/uptimeApi';
17
+ export { IngestApi } from './apis/ingestApi';
583
18
  //# sourceMappingURL=index.js.map