@observa/sdk 2.3.0 → 2.3.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.ts +494 -21
- package/dist/index.js +568 -18
- package/dist/index.js.map +1 -1
- package/dist/src/apis/ingestApi.d.ts +22 -0
- package/dist/src/apis/ingestApi.js +167 -0
- package/dist/src/apis/ingestApi.js.map +1 -0
- package/dist/src/apis/uptimeApi.d.ts +11 -0
- package/dist/src/apis/uptimeApi.js +39 -0
- package/dist/src/apis/uptimeApi.js.map +1 -0
- package/dist/src/domain/ingest.d.ts +47 -0
- package/dist/src/domain/ingest.js +2 -0
- package/dist/src/domain/ingest.js.map +1 -0
- package/dist/src/domain/uptime.d.ts +23 -0
- package/dist/src/domain/uptime.js +2 -0
- package/dist/src/domain/uptime.js.map +1 -0
- package/dist/src/http/errors.d.ts +33 -0
- package/dist/src/http/errors.js +54 -0
- package/dist/src/http/errors.js.map +1 -0
- package/dist/src/http/httpClient.d.ts +45 -0
- package/dist/src/http/httpClient.js +165 -0
- package/dist/src/http/httpClient.js.map +1 -0
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.js +7 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/sdk.d.ts +23 -0
- package/dist/src/sdk.js +40 -0
- package/dist/src/sdk.js.map +1 -0
- package/dist/src/utils/processContext.d.ts +34 -0
- package/dist/src/utils/processContext.js +47 -0
- package/dist/src/utils/processContext.js.map +1 -0
- package/dist/src/utils/validate.d.ts +2 -0
- package/dist/src/utils/validate.js +12 -0
- package/dist/src/utils/validate.js.map +1 -0
- package/dist/tests/httpClient.test.d.ts +1 -0
- package/dist/tests/httpClient.test.js +47 -0
- package/dist/tests/httpClient.test.js.map +1 -0
- package/dist/tests/ingestApi.test.d.ts +1 -0
- package/dist/tests/ingestApi.test.js +65 -0
- package/dist/tests/ingestApi.test.js.map +1 -0
- package/dist/tests/observaSdk.integration.test.d.ts +1 -0
- package/dist/tests/observaSdk.integration.test.js +51 -0
- package/dist/tests/observaSdk.integration.test.js.map +1 -0
- package/dist/tests/sdk.test.d.ts +1 -0
- package/dist/tests/sdk.test.js +104 -0
- package/dist/tests/sdk.test.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +5 -3
- package/src/apis/ingestApi.ts +185 -0
- package/src/apis/uptimeApi.ts +58 -0
- package/src/domain/ingest.ts +89 -0
- package/src/domain/uptime.ts +86 -0
- package/src/http/errors.ts +88 -0
- package/src/http/httpClient.ts +277 -0
- package/src/index.ts +68 -0
- package/src/sdk.ts +103 -0
- package/src/utils/processContext.ts +84 -0
- package/src/utils/validate.ts +19 -0
package/dist/index.js
CHANGED
|
@@ -1,19 +1,569 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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.
|
|
125
|
+
*/
|
|
126
|
+
constructor(http, defaultDsnKey, normalization) {
|
|
127
|
+
this.http = http;
|
|
128
|
+
this.defaultDsnKey = defaultDsnKey;
|
|
129
|
+
this.normalization = normalization;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Sends an event to the ingestion backend.
|
|
133
|
+
*/
|
|
134
|
+
async event(input) {
|
|
135
|
+
ensureDefined(input, "input");
|
|
136
|
+
const dsnKey = input.dsnKey ?? this.defaultDsnKey;
|
|
137
|
+
ensureDefined(dsnKey, "dsnKey");
|
|
138
|
+
ensureNonEmpty(dsnKey, "dsnKey");
|
|
139
|
+
ensureDefined(input.event, "event");
|
|
140
|
+
if (input.idempotencyKey && input.idempotencyKey.length > 128) {
|
|
141
|
+
throw new ValidationError("idempotencyKey must be at most 128 characters");
|
|
142
|
+
}
|
|
143
|
+
const headers = {};
|
|
144
|
+
if (input.idempotencyKey) headers["x-idempotency-key"] = input.idempotencyKey;
|
|
145
|
+
if (input.sdkVersion) headers["x-sdk-version"] = input.sdkVersion;
|
|
146
|
+
const { idempotencyKey, sdkVersion, event, ...body } = input;
|
|
147
|
+
const normalizedEvent = normalizeEvent(event, this.normalization);
|
|
148
|
+
return this.http.post("/ingest/events", { ...body, dsnKey, event: normalizedEvent }, { auth: "apiKey", headers });
|
|
149
|
+
}
|
|
150
|
+
async health(dsnKey) {
|
|
151
|
+
const resolvedDsnKey = dsnKey ?? this.defaultDsnKey;
|
|
152
|
+
ensureDefined(resolvedDsnKey, "dsnKey");
|
|
153
|
+
ensureNonEmpty(resolvedDsnKey, "dsnKey");
|
|
154
|
+
return this.http.post("/ingest/health", { dsnKey: resolvedDsnKey }, { auth: "apiKey" });
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
function normalizeEvent(event, options) {
|
|
158
|
+
const config = { ...DEFAULT_NORMALIZATION, ...options };
|
|
159
|
+
const normalizedTimestamp = normalizeTimestamp(event.timestamp);
|
|
160
|
+
const normalizedLevel = event.level ? event.level.toLowerCase() : void 0;
|
|
161
|
+
const normalizedMessage = event.message ? truncate(event.message, config.maxMessageLength) : void 0;
|
|
162
|
+
const normalizedException = normalizeException(event.exception, config);
|
|
163
|
+
if (!normalizedMessage && !normalizedException) {
|
|
164
|
+
throw new ValidationError("event message or exception is required");
|
|
165
|
+
}
|
|
166
|
+
const normalizedContext = normalizeContext(event.context, config);
|
|
167
|
+
const normalizedEvent = {
|
|
168
|
+
...event,
|
|
169
|
+
event_id: event.event_id ?? randomUUID(),
|
|
170
|
+
timestamp: normalizedTimestamp,
|
|
171
|
+
schema_version: event.schema_version ?? config.schemaVersion,
|
|
172
|
+
level: normalizedLevel,
|
|
173
|
+
message: normalizedMessage,
|
|
174
|
+
exception: normalizedException,
|
|
175
|
+
context: normalizedContext
|
|
176
|
+
};
|
|
177
|
+
return enforceSizeLimit(normalizedEvent, config);
|
|
178
|
+
}
|
|
179
|
+
function normalizeTimestamp(timestamp) {
|
|
180
|
+
if (!timestamp) return (/* @__PURE__ */ new Date()).toISOString();
|
|
181
|
+
const parsed = new Date(timestamp);
|
|
182
|
+
if (Number.isNaN(parsed.getTime())) {
|
|
183
|
+
throw new ValidationError("timestamp must be a valid ISO date");
|
|
184
|
+
}
|
|
185
|
+
return parsed.toISOString();
|
|
186
|
+
}
|
|
187
|
+
function normalizeException(exception, config) {
|
|
188
|
+
if (!exception) return void 0;
|
|
189
|
+
if (!exception.type || !exception.value) {
|
|
190
|
+
throw new ValidationError("exception.type and exception.value are required");
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
...exception,
|
|
194
|
+
value: truncate(exception.value, config.maxExceptionValueLength),
|
|
195
|
+
stacktrace: normalizeStacktrace(exception.stacktrace, config.maxFrames)
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function normalizeStacktrace(stacktrace, maxFrames) {
|
|
199
|
+
if (!stacktrace || !Array.isArray(stacktrace.frames)) return void 0;
|
|
200
|
+
const frames = stacktrace.frames;
|
|
201
|
+
const normalizedFrames = frames.slice(0, maxFrames).map((frame) => {
|
|
202
|
+
const filename = typeof frame?.filename === "string" ? frame.filename : void 0;
|
|
203
|
+
const functionName = typeof frame?.function === "string" ? frame.function : void 0;
|
|
204
|
+
const lineno = typeof frame?.lineno === "number" ? frame.lineno : void 0;
|
|
205
|
+
const colno = typeof frame?.colno === "number" ? frame.colno : void 0;
|
|
206
|
+
const inferredInApp = filename ? !filename.includes("node_modules") : false;
|
|
207
|
+
return {
|
|
208
|
+
filename,
|
|
209
|
+
function: functionName,
|
|
210
|
+
lineno,
|
|
211
|
+
colno,
|
|
212
|
+
in_app: typeof frame?.in_app === "boolean" ? frame.in_app : inferredInApp
|
|
213
|
+
};
|
|
214
|
+
});
|
|
215
|
+
return { frames: normalizedFrames };
|
|
216
|
+
}
|
|
217
|
+
function normalizeContext(context, config) {
|
|
218
|
+
if (!config.includeContext) return context;
|
|
219
|
+
const systemContext = config.includeSystemContext ? getProcessContextDynamic() : void 0;
|
|
220
|
+
const runtimeContext = config.includeRuntimeContext ? getProcessContextStatic({ includeVersions: false }) : void 0;
|
|
221
|
+
const mergedContext = {
|
|
222
|
+
...context,
|
|
223
|
+
system: context?.system ?? systemContext,
|
|
224
|
+
runtime: context?.runtime ?? runtimeContext
|
|
225
|
+
};
|
|
226
|
+
return mergedContext;
|
|
227
|
+
}
|
|
228
|
+
function enforceSizeLimit(event, config) {
|
|
229
|
+
let normalized = event;
|
|
230
|
+
if (getSize(normalized) <= config.maxEventBytes) return normalized;
|
|
231
|
+
if (normalized.extra) {
|
|
232
|
+
normalized = { ...normalized, extra: void 0 };
|
|
233
|
+
}
|
|
234
|
+
if (getSize(normalized) <= config.maxEventBytes) return normalized;
|
|
235
|
+
if (normalized.tags) {
|
|
236
|
+
normalized = { ...normalized, tags: void 0 };
|
|
237
|
+
}
|
|
238
|
+
if (getSize(normalized) <= config.maxEventBytes) return normalized;
|
|
239
|
+
if (normalized.exception?.stacktrace) {
|
|
240
|
+
normalized = {
|
|
241
|
+
...normalized,
|
|
242
|
+
exception: { ...normalized.exception, stacktrace: void 0 }
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
if (getSize(normalized) <= config.maxEventBytes) return normalized;
|
|
246
|
+
if (normalized.message) {
|
|
247
|
+
normalized = { ...normalized, message: truncate(normalized.message, config.maxMessageLength) };
|
|
248
|
+
}
|
|
249
|
+
if (normalized.exception?.value) {
|
|
250
|
+
normalized = {
|
|
251
|
+
...normalized,
|
|
252
|
+
exception: { ...normalized.exception, value: truncate(normalized.exception.value, config.maxExceptionValueLength) }
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
if (getSize(normalized) <= config.maxEventBytes) return normalized;
|
|
256
|
+
throw new ValidationError("event payload exceeds size limit");
|
|
257
|
+
}
|
|
258
|
+
function getSize(value) {
|
|
259
|
+
return Buffer.byteLength(JSON.stringify(value), "utf8");
|
|
260
|
+
}
|
|
261
|
+
function truncate(value, maxLength) {
|
|
262
|
+
if (value.length <= maxLength) return value;
|
|
263
|
+
return value.slice(0, maxLength);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// src/apis/uptimeApi.ts
|
|
267
|
+
var UptimeApi = class {
|
|
268
|
+
/**
|
|
269
|
+
* Creates the uptime client with an optional default DSN.
|
|
270
|
+
*/
|
|
271
|
+
constructor(http, defaultDsnKey) {
|
|
272
|
+
this.http = http;
|
|
273
|
+
this.defaultDsnKey = defaultDsnKey;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Records an uptime heartbeat.
|
|
277
|
+
*/
|
|
278
|
+
async recordHeartbeat(input) {
|
|
279
|
+
ensureDefined(input, "input");
|
|
280
|
+
const dsnKey = input.dsnKey ?? this.defaultDsnKey;
|
|
281
|
+
ensureDefined(dsnKey, "dsnKey");
|
|
282
|
+
ensureNonEmpty(dsnKey, "dsnKey");
|
|
283
|
+
ensureNonEmpty(input.status, "status");
|
|
284
|
+
return this.http.post("/uptime/heartbeats", { ...input, dsnKey }, { auth: "apiKey" });
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Lists a project's daily uptime history.
|
|
288
|
+
*/
|
|
289
|
+
async history(projectId, date) {
|
|
290
|
+
ensureNonEmpty(projectId, "projectId");
|
|
291
|
+
ensureNonEmpty(date, "date");
|
|
292
|
+
return this.http.get(`/projects/${encodeURIComponent(projectId)}/uptime/history`, {
|
|
293
|
+
query: { date },
|
|
294
|
+
auth: "none"
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Gets the latest uptime event for a project.
|
|
299
|
+
*/
|
|
300
|
+
async latest(projectId) {
|
|
301
|
+
ensureNonEmpty(projectId, "projectId");
|
|
302
|
+
return this.http.get(`/projects/${encodeURIComponent(projectId)}/uptime/latest`, {
|
|
303
|
+
auth: "none"
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Summarizes daily uptime.
|
|
308
|
+
*/
|
|
309
|
+
async summary(projectId, days, delayThresholdMinutes) {
|
|
310
|
+
ensureNonEmpty(projectId, "projectId");
|
|
311
|
+
return this.http.get(`/projects/${encodeURIComponent(projectId)}/uptime/summary`, {
|
|
312
|
+
query: { days, delayThresholdMinutes },
|
|
313
|
+
auth: "none"
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
// src/http/httpClient.ts
|
|
319
|
+
var HttpClient = class {
|
|
320
|
+
apiKey;
|
|
321
|
+
baseUrl;
|
|
322
|
+
timeoutMs;
|
|
323
|
+
headers;
|
|
324
|
+
retry;
|
|
325
|
+
healthCheckPromise;
|
|
326
|
+
/**
|
|
327
|
+
* Creates an HTTP client with baseUrl and optional apiKey.
|
|
328
|
+
*/
|
|
329
|
+
constructor(options) {
|
|
330
|
+
this.baseUrl = options.baseUrl.replace(/\/+$/, "");
|
|
331
|
+
this.apiKey = options.apiKey;
|
|
332
|
+
this.timeoutMs = options.timeoutMs ?? 5e3;
|
|
333
|
+
this.headers = options.headers ?? {};
|
|
334
|
+
this.retry = options.retry;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Updates the API key at runtime.
|
|
338
|
+
*/
|
|
339
|
+
setApiKey(apiKey) {
|
|
340
|
+
this.apiKey = apiKey;
|
|
341
|
+
}
|
|
342
|
+
startHealthCheck(healthCheck) {
|
|
343
|
+
if (!this.healthCheckPromise) {
|
|
344
|
+
const promise = healthCheck();
|
|
345
|
+
this.healthCheckPromise = promise;
|
|
346
|
+
promise.catch(() => void 0);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* GET request.
|
|
351
|
+
*/
|
|
352
|
+
async get(path, options) {
|
|
353
|
+
return this.request({ method: "GET", path, ...options });
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* POST request.
|
|
357
|
+
*/
|
|
358
|
+
async post(path, body, options) {
|
|
359
|
+
return this.request({ method: "POST", path, body, ...options });
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* PUT request.
|
|
363
|
+
*/
|
|
364
|
+
async put(path, body, options) {
|
|
365
|
+
return this.request({ method: "PUT", path, body, ...options });
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* PATCH request.
|
|
369
|
+
*/
|
|
370
|
+
async patch(path, body, options) {
|
|
371
|
+
return this.request({ method: "PATCH", path, body, ...options });
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* DELETE request.
|
|
375
|
+
*/
|
|
376
|
+
async delete(path, options) {
|
|
377
|
+
return this.request({ method: "DELETE", path, ...options });
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Executes a request with retry logic.
|
|
381
|
+
*/
|
|
382
|
+
async request(options) {
|
|
383
|
+
if (this.healthCheckPromise) {
|
|
384
|
+
await this.healthCheckPromise;
|
|
385
|
+
}
|
|
386
|
+
const retry = this.retry ?? { retries: 0 };
|
|
387
|
+
const retryOn = retry.retryOn ?? ((response, error) => {
|
|
388
|
+
if (response) return response.status === 429 || response.status >= 500;
|
|
389
|
+
return error instanceof NetworkError || error instanceof TimeoutError || error instanceof TypeError;
|
|
390
|
+
});
|
|
391
|
+
const retryDelayMs = retry.retryDelayMs ?? ((attempt) => Math.min(1e3 * 2 ** (attempt - 1), 8e3));
|
|
392
|
+
let lastError;
|
|
393
|
+
for (let attempt = 0; attempt <= retry.retries; attempt += 1) {
|
|
394
|
+
try {
|
|
395
|
+
const { response, data } = await this.execute(options);
|
|
396
|
+
if (!response.ok) {
|
|
397
|
+
const retryAfter = this.parseRetryAfter(response.headers.get("retry-after"));
|
|
398
|
+
const error = mapHttpError(response.status, data, retryAfter);
|
|
399
|
+
if (retryOn(response, error) && attempt < retry.retries) {
|
|
400
|
+
await this.delay(retryDelayMs(attempt + 1, response, error));
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
throw error;
|
|
404
|
+
}
|
|
405
|
+
return data;
|
|
406
|
+
} catch (error) {
|
|
407
|
+
lastError = error;
|
|
408
|
+
if (retryOn(void 0, error) && attempt < retry.retries) {
|
|
409
|
+
await this.delay(retryDelayMs(attempt + 1, void 0, error));
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
throw error;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
throw lastError;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Executes a request without retry and returns response + data.
|
|
419
|
+
*/
|
|
420
|
+
async execute(options) {
|
|
421
|
+
const url = this.buildUrl(options.path, options.query);
|
|
422
|
+
const headers = { ...this.headers, ...options.headers };
|
|
423
|
+
if (options.body !== void 0) headers["content-type"] = "application/json";
|
|
424
|
+
const authMode = options.auth ?? "none";
|
|
425
|
+
if (authMode === "apiKey") {
|
|
426
|
+
if (!this.apiKey) throw new AuthError("API key is required");
|
|
427
|
+
headers["x-api-key"] = this.apiKey;
|
|
428
|
+
}
|
|
429
|
+
const controller = new AbortController();
|
|
430
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
431
|
+
try {
|
|
432
|
+
const response = await fetch(url, {
|
|
433
|
+
method: options.method,
|
|
434
|
+
headers,
|
|
435
|
+
body: options.body === void 0 ? void 0 : JSON.stringify(options.body),
|
|
436
|
+
signal: controller.signal
|
|
437
|
+
});
|
|
438
|
+
const data = await this.readBody(response);
|
|
439
|
+
return { response, data };
|
|
440
|
+
} catch (error) {
|
|
441
|
+
if (error?.name === "AbortError") {
|
|
442
|
+
throw new TimeoutError("Request timeout");
|
|
443
|
+
}
|
|
444
|
+
if (error instanceof NetworkError || error instanceof TimeoutError) throw error;
|
|
445
|
+
if (error instanceof Error) {
|
|
446
|
+
if (error instanceof AuthError) throw error;
|
|
447
|
+
}
|
|
448
|
+
if (error instanceof Error && "status" in error) throw error;
|
|
449
|
+
throw new NetworkError("Network error", { details: error });
|
|
450
|
+
} finally {
|
|
451
|
+
clearTimeout(timer);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Builds the final URL with query params.
|
|
456
|
+
*/
|
|
457
|
+
buildUrl(path, query) {
|
|
458
|
+
const base = this.baseUrl;
|
|
459
|
+
const fullPath = path.startsWith("http") ? path : `${base}${path.startsWith("/") ? "" : "/"}${path}`;
|
|
460
|
+
if (!query) return fullPath;
|
|
461
|
+
const params = new URLSearchParams();
|
|
462
|
+
for (const [key, value] of Object.entries(query)) {
|
|
463
|
+
if (value === void 0) continue;
|
|
464
|
+
params.set(key, String(value));
|
|
465
|
+
}
|
|
466
|
+
const suffix = params.toString();
|
|
467
|
+
return suffix ? `${fullPath}?${suffix}` : fullPath;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Parses the body as JSON when possible.
|
|
471
|
+
*/
|
|
472
|
+
async readBody(response) {
|
|
473
|
+
if (response.status === 204) return void 0;
|
|
474
|
+
const text = await response.text();
|
|
475
|
+
if (!text) return void 0;
|
|
476
|
+
try {
|
|
477
|
+
return JSON.parse(text);
|
|
478
|
+
} catch {
|
|
479
|
+
return text;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
parseRetryAfter(value) {
|
|
483
|
+
if (!value) return void 0;
|
|
484
|
+
const seconds = Number(value);
|
|
485
|
+
if (!Number.isNaN(seconds) && Number.isFinite(seconds)) {
|
|
486
|
+
return Math.max(0, seconds);
|
|
487
|
+
}
|
|
488
|
+
const parsedDate = Date.parse(value);
|
|
489
|
+
if (Number.isNaN(parsedDate)) return void 0;
|
|
490
|
+
const diffMs = parsedDate - Date.now();
|
|
491
|
+
if (diffMs <= 0) return 0;
|
|
492
|
+
return Math.ceil(diffMs / 1e3);
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Simple delay for retries.
|
|
496
|
+
*/
|
|
497
|
+
async delay(ms) {
|
|
498
|
+
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
// src/sdk.ts
|
|
503
|
+
var DEFAULT_BASE_URL = "https://backend-observa-production.up.railway.app/v1";
|
|
504
|
+
var ObservaSDK = class {
|
|
505
|
+
/**
|
|
506
|
+
* Uptime API (heartbeats and public reads).
|
|
507
|
+
*/
|
|
508
|
+
uptime;
|
|
509
|
+
/**
|
|
510
|
+
* Event ingestion API.
|
|
511
|
+
*/
|
|
512
|
+
ingest;
|
|
513
|
+
http;
|
|
514
|
+
/**
|
|
515
|
+
* Creates an SDK instance with required apiKey and dsnKey.
|
|
516
|
+
*/
|
|
517
|
+
constructor(options) {
|
|
518
|
+
if (!options || !options.apiKey || !options.dsnKey) {
|
|
519
|
+
throw new Error("ObservaSDK requires both apiKey and dsnKey");
|
|
520
|
+
}
|
|
521
|
+
const baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
522
|
+
const normalizedBaseUrl = baseUrl.endsWith("/v1") ? baseUrl : `${baseUrl}/v1`;
|
|
523
|
+
this.http = new HttpClient({
|
|
524
|
+
baseUrl: normalizedBaseUrl,
|
|
525
|
+
apiKey: options.apiKey,
|
|
526
|
+
timeoutMs: options.timeoutMs,
|
|
527
|
+
retry: options.retry,
|
|
528
|
+
headers: options.headers
|
|
529
|
+
});
|
|
530
|
+
this.ingest = new IngestApi(this.http, options.dsnKey, options.ingest);
|
|
531
|
+
this.uptime = new UptimeApi(this.http, options.dsnKey);
|
|
532
|
+
this.http.startHealthCheck(() => this.ingest.health(options.dsnKey));
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Updates the API key used by the SDK at runtime.
|
|
536
|
+
*/
|
|
537
|
+
setApiKey(apiKey) {
|
|
538
|
+
this.http.setApiKey(apiKey);
|
|
539
|
+
}
|
|
540
|
+
getProcessContext(options) {
|
|
541
|
+
return getProcessContext(options);
|
|
542
|
+
}
|
|
543
|
+
getProcessContextStatic(options) {
|
|
544
|
+
return getProcessContextStatic(options);
|
|
545
|
+
}
|
|
546
|
+
getProcessContextDynamic(options) {
|
|
547
|
+
return getProcessContextDynamic(options);
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
export {
|
|
551
|
+
AuthError,
|
|
552
|
+
ConflictError,
|
|
553
|
+
ForbiddenError,
|
|
554
|
+
HttpClient,
|
|
555
|
+
IngestApi,
|
|
556
|
+
NetworkError,
|
|
557
|
+
NotFoundError,
|
|
558
|
+
ObservaSDK,
|
|
559
|
+
RateLimitError,
|
|
560
|
+
SdkError,
|
|
561
|
+
ServerError,
|
|
562
|
+
TimeoutError,
|
|
563
|
+
UptimeApi,
|
|
564
|
+
ValidationError,
|
|
565
|
+
getProcessContext,
|
|
566
|
+
getProcessContextDynamic,
|
|
567
|
+
getProcessContextStatic
|
|
568
|
+
};
|
|
19
569
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAMlC;;GAEG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAM9C;;GAEG;AACH,OAAO,EACL,QAAQ,EACR,eAAe,EACf,SAAS,EACT,cAAc,EACd,aAAa,EACb,aAAa,EACb,cAAc,EACd,WAAW,EACX,YAAY,EACZ,YAAY,GACb,MAAM,eAAe,CAAA;AAEtB;;GAEG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AA6B5C,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAA"}
|
|
1
|
+
{"version":3,"sources":["../src/apis/ingestApi.ts","../src/http/errors.ts","../src/utils/processContext.ts","../src/utils/validate.ts","../src/apis/uptimeApi.ts","../src/http/httpClient.ts","../src/sdk.ts"],"sourcesContent":["import { randomUUID } from 'crypto'\nimport type { IngestEvent, IngestRequest, IngestResponse, StacktraceFrame } from '../domain/ingest'\nimport { ValidationError } from '../http/errors'\nimport { getProcessContextDynamic, getProcessContextStatic } from '../utils/processContext'\nimport { ensureDefined, ensureNonEmpty } from '../utils/validate'\nimport type { HttpClient } from '../http/httpClient'\n\nexport type IngestNormalizationOptions = {\n schemaVersion?: number\n includeContext?: boolean\n includeSystemContext?: boolean\n includeRuntimeContext?: boolean\n maxEventBytes?: number\n maxFrames?: number\n maxMessageLength?: number\n maxExceptionValueLength?: number\n}\n\nconst DEFAULT_NORMALIZATION: Required<IngestNormalizationOptions> = {\n schemaVersion: 1,\n includeContext: true,\n includeSystemContext: true,\n includeRuntimeContext: true,\n maxEventBytes: 64 * 1024,\n maxFrames: 60,\n maxMessageLength: 4000,\n maxExceptionValueLength: 4000,\n}\n\n/**\n * Event ingestion API.\n */\nexport class IngestApi {\n /**\n * Creates the ingestion client with an optional default DSN.\n */\n constructor(\n private readonly http: HttpClient,\n private readonly defaultDsnKey?: string,\n private readonly normalization?: IngestNormalizationOptions\n ) { }\n\n /**\n * Sends an event to the ingestion backend.\n */\n async event(input: IngestRequest): Promise<IngestResponse> {\n ensureDefined(input, 'input')\n const dsnKey = input.dsnKey ?? this.defaultDsnKey\n ensureDefined(dsnKey, 'dsnKey')\n ensureNonEmpty(dsnKey, 'dsnKey')\n ensureDefined(input.event, 'event')\n if (input.idempotencyKey && input.idempotencyKey.length > 128) {\n throw new ValidationError('idempotencyKey must be at most 128 characters')\n }\n const headers: Record<string, string> = {}\n if (input.idempotencyKey) headers['x-idempotency-key'] = input.idempotencyKey\n if (input.sdkVersion) headers['x-sdk-version'] = input.sdkVersion\n const { idempotencyKey, sdkVersion, event, ...body } = input\n const normalizedEvent = normalizeEvent(event, this.normalization)\n return this.http.post<IngestResponse>('/ingest/events', { ...body, dsnKey, event: normalizedEvent }, { auth: 'apiKey', headers })\n }\n\n async health(dsnKey?: string): Promise<{ ok: boolean }> {\n const resolvedDsnKey = dsnKey ?? this.defaultDsnKey\n ensureDefined(resolvedDsnKey, 'dsnKey')\n ensureNonEmpty(resolvedDsnKey, 'dsnKey')\n return this.http.post<{ ok: boolean }>('/ingest/health', { dsnKey: resolvedDsnKey }, { auth: 'apiKey' })\n }\n}\n\nfunction normalizeEvent(event: IngestEvent, options?: IngestNormalizationOptions): IngestEvent {\n const config = { ...DEFAULT_NORMALIZATION, ...options }\n const normalizedTimestamp = normalizeTimestamp(event.timestamp)\n const normalizedLevel = event.level ? event.level.toLowerCase() : undefined\n const normalizedMessage = event.message ? truncate(event.message, config.maxMessageLength) : undefined\n const normalizedException = normalizeException(event.exception, config)\n if (!normalizedMessage && !normalizedException) {\n throw new ValidationError('event message or exception is required')\n }\n const normalizedContext = normalizeContext(event.context, config)\n const normalizedEvent: IngestEvent = {\n ...event,\n event_id: event.event_id ?? randomUUID(),\n timestamp: normalizedTimestamp,\n schema_version: event.schema_version ?? config.schemaVersion,\n level: normalizedLevel as IngestEvent['level'],\n message: normalizedMessage,\n exception: normalizedException,\n context: normalizedContext,\n }\n return enforceSizeLimit(normalizedEvent, config)\n}\n\nfunction normalizeTimestamp(timestamp?: string) {\n if (!timestamp) return new Date().toISOString()\n const parsed = new Date(timestamp)\n if (Number.isNaN(parsed.getTime())) {\n throw new ValidationError('timestamp must be a valid ISO date')\n }\n return parsed.toISOString()\n}\n\nfunction normalizeException(exception: IngestEvent['exception'], config: Required<IngestNormalizationOptions>) {\n if (!exception) return undefined\n if (!exception.type || !exception.value) {\n throw new ValidationError('exception.type and exception.value are required')\n }\n return {\n ...exception,\n value: truncate(exception.value, config.maxExceptionValueLength),\n stacktrace: normalizeStacktrace(exception.stacktrace, config.maxFrames),\n }\n}\n\nfunction normalizeStacktrace(stacktrace: { frames?: StacktraceFrame[] } | undefined, maxFrames: number) {\n if (!stacktrace || !Array.isArray(stacktrace.frames)) return undefined\n const frames = stacktrace.frames\n const normalizedFrames = frames.slice(0, maxFrames).map((frame) => {\n const filename = typeof frame?.filename === 'string' ? frame.filename : undefined\n const functionName = typeof frame?.function === 'string' ? frame.function : undefined\n const lineno = typeof frame?.lineno === 'number' ? frame.lineno : undefined\n const colno = typeof frame?.colno === 'number' ? frame.colno : undefined\n const inferredInApp = filename ? !filename.includes('node_modules') : false\n return {\n filename,\n function: functionName,\n lineno,\n colno,\n in_app: typeof frame?.in_app === 'boolean' ? frame.in_app : inferredInApp,\n }\n })\n return { frames: normalizedFrames }\n}\n\nfunction normalizeContext(context: IngestEvent['context'] | undefined, config: Required<IngestNormalizationOptions>) {\n if (!config.includeContext) return context\n const systemContext = config.includeSystemContext ? getProcessContextDynamic() : undefined\n const runtimeContext = config.includeRuntimeContext ? getProcessContextStatic({ includeVersions: false }) : undefined\n const mergedContext = {\n ...context,\n system: context?.system ?? systemContext,\n runtime: context?.runtime ?? runtimeContext,\n }\n return mergedContext\n}\n\nfunction enforceSizeLimit(event: IngestEvent, config: Required<IngestNormalizationOptions>) {\n let normalized = event\n if (getSize(normalized) <= config.maxEventBytes) return normalized\n if (normalized.extra) {\n normalized = { ...normalized, extra: undefined }\n }\n if (getSize(normalized) <= config.maxEventBytes) return normalized\n if (normalized.tags) {\n normalized = { ...normalized, tags: undefined }\n }\n if (getSize(normalized) <= config.maxEventBytes) return normalized\n if (normalized.exception?.stacktrace) {\n normalized = {\n ...normalized,\n exception: { ...normalized.exception, stacktrace: undefined },\n }\n }\n if (getSize(normalized) <= config.maxEventBytes) return normalized\n if (normalized.message) {\n normalized = { ...normalized, message: truncate(normalized.message, config.maxMessageLength) }\n }\n if (normalized.exception?.value) {\n normalized = {\n ...normalized,\n exception: { ...normalized.exception, value: truncate(normalized.exception.value, config.maxExceptionValueLength) },\n }\n }\n if (getSize(normalized) <= config.maxEventBytes) return normalized\n throw new ValidationError('event payload exceeds size limit')\n}\n\nfunction getSize(value: unknown) {\n return Buffer.byteLength(JSON.stringify(value), 'utf8')\n}\n\nfunction truncate(value: string, maxLength: number) {\n if (value.length <= maxLength) return value\n return value.slice(0, maxLength)\n}\n","/**\r\n * Additional data to enrich SDK errors.\r\n */\r\nexport type ErrorDetails = {\r\n status?: number\r\n code?: string\r\n details?: unknown\r\n retryAfter?: number\r\n}\r\n\r\n/**\r\n * Base SDK error.\r\n */\r\nexport class SdkError extends Error {\r\n readonly status?: number\r\n readonly code?: string\r\n readonly details?: unknown\r\n\r\n /**\r\n * Creates an error with optional metadata.\r\n */\r\n constructor(message: string, details?: ErrorDetails) {\r\n super(message)\r\n this.name = new.target.name\r\n this.status = details?.status\r\n this.code = details?.code\r\n this.details = details?.details\r\n }\r\n}\r\n\r\n/**\r\n * Input validation error.\r\n */\r\nexport class ValidationError extends SdkError { }\r\n/**\r\n * Authentication error.\r\n */\r\nexport class AuthError extends SdkError { }\r\n/**\r\n * Error caused by insufficient permissions.\r\n */\r\nexport class ForbiddenError extends SdkError { }\r\n/**\r\n * Error when a resource does not exist.\r\n */\r\nexport class NotFoundError extends SdkError { }\r\n/**\r\n * Error caused by a state conflict.\r\n */\r\nexport class ConflictError extends SdkError { }\r\n/**\r\n * Error caused by rate limiting.\r\n */\r\nexport class RateLimitError extends SdkError {\r\n readonly retryAfter?: number\r\n\r\n constructor(message: string, details?: ErrorDetails) {\r\n super(message, details)\r\n this.retryAfter = details?.retryAfter\r\n }\r\n}\r\n/**\r\n * Server-side error.\r\n */\r\nexport class ServerError extends SdkError { }\r\n/**\r\n * Network error.\r\n */\r\nexport class NetworkError extends SdkError { }\r\n/**\r\n * Request timeout error.\r\n */\r\nexport class TimeoutError extends SdkError { }\r\n\r\n/**\r\n * Maps HTTP status codes to typed SDK errors.\r\n */\r\nexport function mapHttpError(status: number, details?: unknown, retryAfter?: number): SdkError {\r\n const info = { status, details, retryAfter }\r\n if (status === 400) return new ValidationError('Invalid request', info)\r\n if (status === 401) return new AuthError('Unauthorized', info)\r\n if (status === 403) return new ForbiddenError('Forbidden', info)\r\n if (status === 404) return new NotFoundError('Resource not found', info)\r\n if (status === 409) return new ConflictError('Conflict', info)\r\n if (status === 429) return new RateLimitError('Rate limit exceeded', info)\r\n if (status >= 500) return new ServerError('Server error', info)\r\n return new SdkError('HTTP error', info)\r\n}\r\n","export type ProcessContextStatic = {\r\n versions?: NodeJS.ProcessVersions\r\n node?: string\r\n platform?: NodeJS.Platform\r\n arch?: string\r\n releaseName?: string\r\n}\r\n\r\nexport type ProcessContextDynamic = {\r\n pid?: number\r\n uptimeSeconds?: number\r\n memory?: NodeJS.MemoryUsage\r\n}\r\n\r\nexport type ProcessContext = ProcessContextStatic & ProcessContextDynamic\r\n\r\nexport type ProcessContextOptions = {\r\n includeStatic?: boolean\r\n includeDynamic?: boolean\r\n includeVersions?: boolean\r\n includeRuntime?: boolean\r\n includePid?: boolean\r\n includeUptime?: boolean\r\n includeMemory?: boolean\r\n}\r\n\r\nexport type ProcessContextStaticOptions = {\r\n includeVersions?: boolean\r\n includeRuntime?: boolean\r\n}\r\n\r\nexport type ProcessContextDynamicOptions = {\r\n includePid?: boolean\r\n includeUptime?: boolean\r\n includeMemory?: boolean\r\n}\r\n\r\nexport function getProcessContext(options?: ProcessContextOptions): ProcessContext {\r\n const includeStatic = options?.includeStatic ?? true\r\n const includeDynamic = options?.includeDynamic ?? true\r\n const includeVersions = options?.includeVersions ?? true\r\n const includeRuntime = options?.includeRuntime ?? true\r\n const includePid = options?.includePid ?? true\r\n const includeUptime = options?.includeUptime ?? true\r\n const includeMemory = options?.includeMemory ?? true\r\n const context: ProcessContext = {}\r\n\r\n if (includeDynamic) {\r\n if (includePid) context.pid = process.pid\r\n if (includeUptime) context.uptimeSeconds = Math.round(process.uptime())\r\n if (includeMemory) context.memory = process.memoryUsage()\r\n }\r\n\r\n if (includeStatic) {\r\n if (includeVersions) context.versions = process.versions\r\n if (includeRuntime) {\r\n context.node = process.versions.node\r\n context.platform = process.platform\r\n context.arch = process.arch\r\n context.releaseName = process.release?.name\r\n }\r\n }\r\n\r\n return context\r\n}\r\n\r\nexport function getProcessContextStatic(options?: ProcessContextStaticOptions): ProcessContextStatic {\r\n return getProcessContext({\r\n includeDynamic: false,\r\n includeStatic: true,\r\n includeVersions: options?.includeVersions,\r\n includeRuntime: options?.includeRuntime,\r\n })\r\n}\r\n\r\nexport function getProcessContextDynamic(options?: ProcessContextDynamicOptions): ProcessContextDynamic {\r\n return getProcessContext({\r\n includeStatic: false,\r\n includeDynamic: true,\r\n includePid: options?.includePid,\r\n includeUptime: options?.includeUptime,\r\n includeMemory: options?.includeMemory,\r\n })\r\n}\r\n","import { ValidationError } from '../http/errors'\n\n/**\n * Ensures a string is present and non-empty.\n */\nexport function ensureNonEmpty(value: string, name: string) {\n if (!value || value.trim().length === 0) {\n throw new ValidationError(`${name} is required`)\n }\n}\n\n/**\n * Ensures a value is neither null nor undefined.\n */\nexport function ensureDefined<T>(value: T | null | undefined, name: string): asserts value is T {\n if (value === null || value === undefined) {\n throw new ValidationError(`${name} is required`)\n }\n}\n","import type { UptimeEvent, UptimeHeartbeatInput, UptimeSummary } from '../domain/uptime'\nimport { ensureDefined, ensureNonEmpty } from '../utils/validate'\nimport type { HttpClient } from '../http/httpClient'\n\n/**\n * Uptime API for heartbeats and public reads.\n */\nexport class UptimeApi {\n /**\n * Creates the uptime client with an optional default DSN.\n */\n constructor(private readonly http: HttpClient, private readonly defaultDsnKey?: string) { }\n\n /**\n * Records an uptime heartbeat.\n */\n async recordHeartbeat(input: UptimeHeartbeatInput): Promise<UptimeEvent> {\n ensureDefined(input, 'input')\n const dsnKey = input.dsnKey ?? this.defaultDsnKey\n ensureDefined(dsnKey, 'dsnKey')\n ensureNonEmpty(dsnKey, 'dsnKey')\n ensureNonEmpty(input.status, 'status')\n return this.http.post<UptimeEvent>('/uptime/heartbeats', { ...input, dsnKey }, { auth: 'apiKey' })\n }\n\n /**\n * Lists a project's daily uptime history.\n */\n async history(projectId: string, date: string): Promise<UptimeEvent[]> {\n ensureNonEmpty(projectId, 'projectId')\n ensureNonEmpty(date, 'date')\n return this.http.get<UptimeEvent[]>(`/projects/${encodeURIComponent(projectId)}/uptime/history`, {\n query: { date },\n auth: 'none',\n })\n }\n\n /**\n * Gets the latest uptime event for a project.\n */\n async latest(projectId: string): Promise<UptimeEvent | null> {\n ensureNonEmpty(projectId, 'projectId')\n return this.http.get<UptimeEvent | null>(`/projects/${encodeURIComponent(projectId)}/uptime/latest`, {\n auth: 'none',\n })\n }\n\n /**\n * Summarizes daily uptime.\n */\n async summary(projectId: string, days?: number, delayThresholdMinutes?: number): Promise<UptimeSummary[]> {\n ensureNonEmpty(projectId, 'projectId')\n return this.http.get<UptimeSummary[]>(`/projects/${encodeURIComponent(projectId)}/uptime/summary`, {\n query: { days, delayThresholdMinutes },\n auth: 'none',\n })\n }\n}\n","import { AuthError, NetworkError, TimeoutError, mapHttpError } from './errors'\n\n/**\n * Authentication mode per request.\n */\nexport type AuthMode = 'apiKey' | 'none'\n/**\n * Supported HTTP methods.\n */\nexport type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'\n/**\n * Serializable query parameters.\n */\nexport type QueryParams = Record<string, string | number | boolean | undefined>\n\n/**\n * Retry policy for transient errors.\n */\nexport type RetryPolicy = {\n /**\n * Number of additional retries.\n */\n retries: number\n /**\n * Computes the delay between retries.\n */\n retryDelayMs?: (attempt: number, response?: Response, error?: unknown) => number\n /**\n * Determines whether a response or error should be retried.\n */\n retryOn?: (response?: Response, error?: unknown) => boolean\n}\n\n/**\n * Base HTTP client configuration.\n */\nexport type HttpClientOptions = {\n /**\n * Backend base URL.\n */\n baseUrl: string\n /**\n * API key used for SDK authentication.\n */\n apiKey?: string\n /**\n * Request timeout in milliseconds.\n */\n timeoutMs?: number\n /**\n * Global headers.\n */\n headers?: Record<string, string>\n /**\n * Retry policy.\n */\n retry?: RetryPolicy\n}\n\n/**\n * Per-request options.\n */\nexport type RequestOptions = {\n method: HttpMethod\n path: string\n query?: QueryParams\n body?: unknown\n headers?: Record<string, string>\n /**\n * Defines whether the request requires an apiKey or is public.\n */\n auth?: AuthMode\n}\n\n/**\n * Base HTTP client for the SDK.\n */\nexport class HttpClient {\n private apiKey?: string\n private readonly baseUrl: string\n private readonly timeoutMs: number\n private readonly headers: Record<string, string>\n private readonly retry?: RetryPolicy\n private healthCheckPromise?: Promise<unknown>\n\n /**\n * Creates an HTTP client with baseUrl and optional apiKey.\n */\n constructor(options: HttpClientOptions) {\n this.baseUrl = options.baseUrl.replace(/\\/+$/, '')\n this.apiKey = options.apiKey\n this.timeoutMs = options.timeoutMs ?? 5000\n this.headers = options.headers ?? {}\n this.retry = options.retry\n }\n\n /**\n * Updates the API key at runtime.\n */\n setApiKey(apiKey?: string) {\n this.apiKey = apiKey\n }\n\n startHealthCheck(healthCheck: () => Promise<unknown>) {\n if (!this.healthCheckPromise) {\n const promise = healthCheck()\n this.healthCheckPromise = promise\n promise.catch(() => undefined)\n }\n }\n\n /**\n * GET request.\n */\n async get<T>(path: string, options?: Omit<RequestOptions, 'method' | 'path'>): Promise<T> {\n return this.request<T>({ method: 'GET', path, ...options })\n }\n\n /**\n * POST request.\n */\n async post<T>(path: string, body?: unknown, options?: Omit<RequestOptions, 'method' | 'path' | 'body'>): Promise<T> {\n return this.request<T>({ method: 'POST', path, body, ...options })\n }\n\n /**\n * PUT request.\n */\n async put<T>(path: string, body?: unknown, options?: Omit<RequestOptions, 'method' | 'path' | 'body'>): Promise<T> {\n return this.request<T>({ method: 'PUT', path, body, ...options })\n }\n\n /**\n * PATCH request.\n */\n async patch<T>(path: string, body?: unknown, options?: Omit<RequestOptions, 'method' | 'path' | 'body'>): Promise<T> {\n return this.request<T>({ method: 'PATCH', path, body, ...options })\n }\n\n /**\n * DELETE request.\n */\n async delete<T>(path: string, options?: Omit<RequestOptions, 'method' | 'path'>): Promise<T> {\n return this.request<T>({ method: 'DELETE', path, ...options })\n }\n\n /**\n * Executes a request with retry logic.\n */\n async request<T>(options: RequestOptions): Promise<T> {\n if (this.healthCheckPromise) {\n await this.healthCheckPromise\n }\n const retry = this.retry ?? { retries: 0 }\n const retryOn = retry.retryOn ?? ((response?: Response, error?: unknown) => {\n if (response) return response.status === 429 || response.status >= 500\n return error instanceof NetworkError || error instanceof TimeoutError || error instanceof TypeError\n })\n const retryDelayMs = retry.retryDelayMs ?? ((attempt: number) => Math.min(1000 * 2 ** (attempt - 1), 8000))\n let lastError: unknown\n\n for (let attempt = 0; attempt <= retry.retries; attempt += 1) {\n try {\n const { response, data } = await this.execute(options)\n if (!response.ok) {\n const retryAfter = this.parseRetryAfter(response.headers.get('retry-after'))\n const error = mapHttpError(response.status, data, retryAfter)\n if (retryOn(response, error) && attempt < retry.retries) {\n await this.delay(retryDelayMs(attempt + 1, response, error))\n continue\n }\n throw error\n }\n return data as T\n } catch (error) {\n lastError = error\n if (retryOn(undefined, error) && attempt < retry.retries) {\n await this.delay(retryDelayMs(attempt + 1, undefined, error))\n continue\n }\n throw error\n }\n }\n\n throw lastError\n }\n\n /**\n * Executes a request without retry and returns response + data.\n */\n private async execute(options: RequestOptions): Promise<{ response: Response; data: unknown }> {\n const url = this.buildUrl(options.path, options.query)\n const headers: Record<string, string> = { ...this.headers, ...options.headers }\n if (options.body !== undefined) headers['content-type'] = 'application/json'\n const authMode = options.auth ?? 'none'\n if (authMode === 'apiKey') {\n if (!this.apiKey) throw new AuthError('API key is required')\n headers['x-api-key'] = this.apiKey\n }\n\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), this.timeoutMs)\n\n try {\n const response = await fetch(url, {\n method: options.method,\n headers,\n body: options.body === undefined ? undefined : JSON.stringify(options.body),\n signal: controller.signal,\n })\n const data = await this.readBody(response)\n return { response, data }\n } catch (error: any) {\n if (error?.name === 'AbortError') {\n throw new TimeoutError('Request timeout')\n }\n if (error instanceof NetworkError || error instanceof TimeoutError) throw error\n if (error instanceof Error) {\n if (error instanceof AuthError) throw error\n }\n if (error instanceof Error && 'status' in error) throw error\n throw new NetworkError('Network error', { details: error })\n } finally {\n clearTimeout(timer)\n }\n }\n\n /**\n * Builds the final URL with query params.\n */\n private buildUrl(path: string, query?: QueryParams): string {\n const base = this.baseUrl\n const fullPath = path.startsWith('http') ? path : `${base}${path.startsWith('/') ? '' : '/'}${path}`\n if (!query) return fullPath\n const params = new URLSearchParams()\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined) continue\n params.set(key, String(value))\n }\n const suffix = params.toString()\n return suffix ? `${fullPath}?${suffix}` : fullPath\n }\n\n /**\n * Parses the body as JSON when possible.\n */\n private async readBody(response: Response): Promise<unknown> {\n if (response.status === 204) return undefined\n const text = await response.text()\n if (!text) return undefined\n try {\n return JSON.parse(text)\n } catch {\n return text\n }\n }\n\n private parseRetryAfter(value: string | null): number | undefined {\n if (!value) return undefined\n const seconds = Number(value)\n if (!Number.isNaN(seconds) && Number.isFinite(seconds)) {\n return Math.max(0, seconds)\n }\n const parsedDate = Date.parse(value)\n if (Number.isNaN(parsedDate)) return undefined\n const diffMs = parsedDate - Date.now()\n if (diffMs <= 0) return 0\n return Math.ceil(diffMs / 1000)\n }\n\n /**\n * Simple delay for retries.\n */\n private async delay(ms: number): Promise<void> {\n await new Promise(resolve => setTimeout(resolve, ms))\n }\n}\n","import { IngestApi, type IngestNormalizationOptions } from './apis/ingestApi'\nimport { UptimeApi } from './apis/uptimeApi'\nimport { HttpClient, type RetryPolicy } from './http/httpClient'\nimport {\n getProcessContext,\n getProcessContextDynamic,\n getProcessContextStatic,\n type ProcessContext,\n type ProcessContextDynamic,\n type ProcessContextDynamicOptions,\n type ProcessContextOptions,\n type ProcessContextStatic,\n type ProcessContextStaticOptions,\n} from './utils/processContext'\n\n/**\n * SDK configuration options.\n */\nexport type ObservaSDKOptions = {\n /**\n * Organization API key used to authenticate SDK requests.\n */\n apiKey: string\n /**\n * Project DSN used to identify the destination of events and heartbeats.\n */\n dsnKey: string\n baseUrl?: string\n /**\n * HTTP request timeout in milliseconds.\n */\n timeoutMs?: number\n /**\n * Retry policy for transient errors.\n */\n retry?: RetryPolicy\n /**\n * Additional headers sent with every request.\n */\n headers?: Record<string, string>\n ingest?: IngestNormalizationOptions\n}\n\n/**\n * Fixed backend target for the SDK.\n */\nconst DEFAULT_BASE_URL = 'https://backend-observa-production.up.railway.app/v1'\n\n/**\n * Main SDK for error ingestion and uptime heartbeats.\n */\nexport class ObservaSDK {\n /**\n * Uptime API (heartbeats and public reads).\n */\n readonly uptime: UptimeApi\n /**\n * Event ingestion API.\n */\n readonly ingest: IngestApi\n\n private readonly http: HttpClient\n\n /**\n * Creates an SDK instance with required apiKey and dsnKey.\n */\n constructor(options: ObservaSDKOptions) {\n if (!options || !options.apiKey || !options.dsnKey) {\n throw new Error('ObservaSDK requires both apiKey and dsnKey')\n }\n const baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, '')\n const normalizedBaseUrl = baseUrl.endsWith('/v1') ? baseUrl : `${baseUrl}/v1`\n this.http = new HttpClient({\n baseUrl: normalizedBaseUrl,\n apiKey: options.apiKey,\n timeoutMs: options.timeoutMs,\n retry: options.retry,\n headers: options.headers,\n })\n this.ingest = new IngestApi(this.http, options.dsnKey, options.ingest)\n this.uptime = new UptimeApi(this.http, options.dsnKey)\n this.http.startHealthCheck(() => this.ingest.health(options.dsnKey))\n }\n\n /**\n * Updates the API key used by the SDK at runtime.\n */\n setApiKey(apiKey: string) {\n this.http.setApiKey(apiKey)\n }\n\n getProcessContext(options?: ProcessContextOptions): ProcessContext {\n return getProcessContext(options)\n }\n\n getProcessContextStatic(options?: ProcessContextStaticOptions): ProcessContextStatic {\n return getProcessContextStatic(options)\n }\n\n getProcessContextDynamic(options?: ProcessContextDynamicOptions): ProcessContextDynamic {\n return getProcessContextDynamic(options)\n }\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;;;ACapB,IAAM,WAAN,cAAuB,MAAM;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA,EAKT,YAAY,SAAiB,SAAwB;AACjD,UAAM,OAAO;AACb,SAAK,OAAO,WAAW;AACvB,SAAK,SAAS,SAAS;AACvB,SAAK,OAAO,SAAS;AACrB,SAAK,UAAU,SAAS;AAAA,EAC5B;AACJ;AAKO,IAAM,kBAAN,cAA8B,SAAS;AAAE;AAIzC,IAAM,YAAN,cAAwB,SAAS;AAAE;AAInC,IAAM,iBAAN,cAA6B,SAAS;AAAE;AAIxC,IAAM,gBAAN,cAA4B,SAAS;AAAE;AAIvC,IAAM,gBAAN,cAA4B,SAAS;AAAE;AAIvC,IAAM,iBAAN,cAA6B,SAAS;AAAA,EAChC;AAAA,EAET,YAAY,SAAiB,SAAwB;AACjD,UAAM,SAAS,OAAO;AACtB,SAAK,aAAa,SAAS;AAAA,EAC/B;AACJ;AAIO,IAAM,cAAN,cAA0B,SAAS;AAAE;AAIrC,IAAM,eAAN,cAA2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