@observa/sdk 2.3.1 → 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 -157
  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 -494
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +17 -568
  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 -185
  71. package/src/apis/uptimeApi.ts +0 -58
  72. package/src/domain/ingest.ts +0 -89
  73. package/src/domain/uptime.ts +0 -86
  74. package/src/http/errors.ts +0 -88
  75. package/src/http/httpClient.ts +0 -277
  76. package/src/index.ts +0 -68
  77. package/src/sdk.ts +0 -103
  78. package/src/utils/processContext.ts +0 -84
  79. package/src/utils/validate.ts +0 -19
package/src/sdk.ts DELETED
@@ -1,103 +0,0 @@
1
- import { IngestApi, type IngestNormalizationOptions } from './apis/ingestApi'
2
- import { UptimeApi } from './apis/uptimeApi'
3
- import { HttpClient, type RetryPolicy } from './http/httpClient'
4
- import {
5
- getProcessContext,
6
- getProcessContextDynamic,
7
- getProcessContextStatic,
8
- type ProcessContext,
9
- type ProcessContextDynamic,
10
- type ProcessContextDynamicOptions,
11
- type ProcessContextOptions,
12
- type ProcessContextStatic,
13
- type ProcessContextStaticOptions,
14
- } from './utils/processContext'
15
-
16
- /**
17
- * SDK configuration options.
18
- */
19
- export type ObservaSDKOptions = {
20
- /**
21
- * Organization API key used to authenticate SDK requests.
22
- */
23
- apiKey: string
24
- /**
25
- * Project DSN used to identify the destination of events and heartbeats.
26
- */
27
- dsnKey: string
28
- baseUrl?: string
29
- /**
30
- * HTTP request timeout in milliseconds.
31
- */
32
- timeoutMs?: number
33
- /**
34
- * Retry policy for transient errors.
35
- */
36
- retry?: RetryPolicy
37
- /**
38
- * Additional headers sent with every request.
39
- */
40
- headers?: Record<string, string>
41
- ingest?: IngestNormalizationOptions
42
- }
43
-
44
- /**
45
- * Fixed backend target for the SDK.
46
- */
47
- const DEFAULT_BASE_URL = 'https://backend-observa-production.up.railway.app/v1'
48
-
49
- /**
50
- * Main SDK for error ingestion and uptime heartbeats.
51
- */
52
- export class ObservaSDK {
53
- /**
54
- * Uptime API (heartbeats and public reads).
55
- */
56
- readonly uptime: UptimeApi
57
- /**
58
- * Event ingestion API.
59
- */
60
- readonly ingest: IngestApi
61
-
62
- private readonly http: HttpClient
63
-
64
- /**
65
- * Creates an SDK instance with required apiKey and dsnKey.
66
- */
67
- constructor(options: ObservaSDKOptions) {
68
- if (!options || !options.apiKey || !options.dsnKey) {
69
- throw new Error('ObservaSDK requires both apiKey and dsnKey')
70
- }
71
- const baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, '')
72
- const normalizedBaseUrl = baseUrl.endsWith('/v1') ? baseUrl : `${baseUrl}/v1`
73
- this.http = new HttpClient({
74
- baseUrl: normalizedBaseUrl,
75
- apiKey: options.apiKey,
76
- timeoutMs: options.timeoutMs,
77
- retry: options.retry,
78
- headers: options.headers,
79
- })
80
- this.ingest = new IngestApi(this.http, options.dsnKey, options.ingest)
81
- this.uptime = new UptimeApi(this.http, options.dsnKey)
82
- this.http.startHealthCheck(() => this.ingest.health(options.dsnKey))
83
- }
84
-
85
- /**
86
- * Updates the API key used by the SDK at runtime.
87
- */
88
- setApiKey(apiKey: string) {
89
- this.http.setApiKey(apiKey)
90
- }
91
-
92
- getProcessContext(options?: ProcessContextOptions): ProcessContext {
93
- return getProcessContext(options)
94
- }
95
-
96
- getProcessContextStatic(options?: ProcessContextStaticOptions): ProcessContextStatic {
97
- return getProcessContextStatic(options)
98
- }
99
-
100
- getProcessContextDynamic(options?: ProcessContextDynamicOptions): ProcessContextDynamic {
101
- return getProcessContextDynamic(options)
102
- }
103
- }
@@ -1,84 +0,0 @@
1
- export type ProcessContextStatic = {
2
- versions?: NodeJS.ProcessVersions
3
- node?: string
4
- platform?: NodeJS.Platform
5
- arch?: string
6
- releaseName?: string
7
- }
8
-
9
- export type ProcessContextDynamic = {
10
- pid?: number
11
- uptimeSeconds?: number
12
- memory?: NodeJS.MemoryUsage
13
- }
14
-
15
- export type ProcessContext = ProcessContextStatic & ProcessContextDynamic
16
-
17
- export type ProcessContextOptions = {
18
- includeStatic?: boolean
19
- includeDynamic?: boolean
20
- includeVersions?: boolean
21
- includeRuntime?: boolean
22
- includePid?: boolean
23
- includeUptime?: boolean
24
- includeMemory?: boolean
25
- }
26
-
27
- export type ProcessContextStaticOptions = {
28
- includeVersions?: boolean
29
- includeRuntime?: boolean
30
- }
31
-
32
- export type ProcessContextDynamicOptions = {
33
- includePid?: boolean
34
- includeUptime?: boolean
35
- includeMemory?: boolean
36
- }
37
-
38
- export function getProcessContext(options?: ProcessContextOptions): ProcessContext {
39
- const includeStatic = options?.includeStatic ?? true
40
- const includeDynamic = options?.includeDynamic ?? true
41
- const includeVersions = options?.includeVersions ?? true
42
- const includeRuntime = options?.includeRuntime ?? true
43
- const includePid = options?.includePid ?? true
44
- const includeUptime = options?.includeUptime ?? true
45
- const includeMemory = options?.includeMemory ?? true
46
- const context: ProcessContext = {}
47
-
48
- if (includeDynamic) {
49
- if (includePid) context.pid = process.pid
50
- if (includeUptime) context.uptimeSeconds = Math.round(process.uptime())
51
- if (includeMemory) context.memory = process.memoryUsage()
52
- }
53
-
54
- if (includeStatic) {
55
- if (includeVersions) context.versions = process.versions
56
- if (includeRuntime) {
57
- context.node = process.versions.node
58
- context.platform = process.platform
59
- context.arch = process.arch
60
- context.releaseName = process.release?.name
61
- }
62
- }
63
-
64
- return context
65
- }
66
-
67
- export function getProcessContextStatic(options?: ProcessContextStaticOptions): ProcessContextStatic {
68
- return getProcessContext({
69
- includeDynamic: false,
70
- includeStatic: true,
71
- includeVersions: options?.includeVersions,
72
- includeRuntime: options?.includeRuntime,
73
- })
74
- }
75
-
76
- export function getProcessContextDynamic(options?: ProcessContextDynamicOptions): ProcessContextDynamic {
77
- return getProcessContext({
78
- includeStatic: false,
79
- includeDynamic: true,
80
- includePid: options?.includePid,
81
- includeUptime: options?.includeUptime,
82
- includeMemory: options?.includeMemory,
83
- })
84
- }
@@ -1,19 +0,0 @@
1
- import { ValidationError } from '../http/errors'
2
-
3
- /**
4
- * Ensures a string is present and non-empty.
5
- */
6
- export function ensureNonEmpty(value: string, name: string) {
7
- if (!value || value.trim().length === 0) {
8
- throw new ValidationError(`${name} is required`)
9
- }
10
- }
11
-
12
- /**
13
- * Ensures a value is neither null nor undefined.
14
- */
15
- export function ensureDefined<T>(value: T | null | undefined, name: string): asserts value is T {
16
- if (value === null || value === undefined) {
17
- throw new ValidationError(`${name} is required`)
18
- }
19
- }