@observa/sdk 2.2.1 → 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/README.md +12 -0
- package/dist/apis/ingestApi.d.ts +12 -1
- package/dist/apis/ingestApi.d.ts.map +1 -1
- package/dist/apis/ingestApi.js +136 -3
- package/dist/apis/ingestApi.js.map +1 -1
- package/dist/domain/ingest.d.ts +15 -1
- package/dist/domain/ingest.d.ts.map +1 -1
- package/dist/index.d.ts +494 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +568 -18
- package/dist/index.js.map +1 -1
- package/dist/sdk.d.ts +2 -1
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +1 -1
- package/dist/sdk.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 +11 -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/sdk.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IngestApi } from './apis/ingestApi';
|
|
1
|
+
import { IngestApi, type IngestNormalizationOptions } from './apis/ingestApi';
|
|
2
2
|
import { UptimeApi } from './apis/uptimeApi';
|
|
3
3
|
import { type RetryPolicy } from './http/httpClient';
|
|
4
4
|
import { type ProcessContext, type ProcessContextDynamic, type ProcessContextDynamicOptions, type ProcessContextOptions, type ProcessContextStatic, type ProcessContextStaticOptions } from './utils/processContext';
|
|
@@ -27,6 +27,7 @@ export type ObservaSDKOptions = {
|
|
|
27
27
|
* Additional headers sent with every request.
|
|
28
28
|
*/
|
|
29
29
|
headers?: Record<string, string>;
|
|
30
|
+
ingest?: IngestNormalizationOptions;
|
|
30
31
|
};
|
|
31
32
|
/**
|
|
32
33
|
* Main SDK for error ingestion and uptime heartbeats.
|
package/dist/sdk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,0BAA0B,EAAE,MAAM,kBAAkB,CAAA;AAC7E,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,EAIH,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,4BAA4B,EACjC,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,2BAA2B,EACnC,MAAM,wBAAwB,CAAA;AAE/B;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC5B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,KAAK,CAAC,EAAE,WAAW,CAAA;IACnB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,MAAM,CAAC,EAAE,0BAA0B,CAAA;CACtC,CAAA;AAOD;;GAEG;AACH,qBAAa,UAAU;IACnB;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAA;IAC1B;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAA;IAE1B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAY;IAEjC;;OAEG;gBACS,OAAO,EAAE,iBAAiB;IAkBtC;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM;IAIxB,iBAAiB,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,cAAc;IAIlE,uBAAuB,CAAC,OAAO,CAAC,EAAE,2BAA2B,GAAG,oBAAoB;IAIpF,wBAAwB,CAAC,OAAO,CAAC,EAAE,4BAA4B,GAAG,qBAAqB;CAG1F"}
|
package/dist/sdk.js
CHANGED
|
@@ -35,7 +35,7 @@ export class ObservaSDK {
|
|
|
35
35
|
retry: options.retry,
|
|
36
36
|
headers: options.headers,
|
|
37
37
|
});
|
|
38
|
-
this.ingest = new IngestApi(this.http, options.dsnKey);
|
|
38
|
+
this.ingest = new IngestApi(this.http, options.dsnKey, options.ingest);
|
|
39
39
|
this.uptime = new UptimeApi(this.http, options.dsnKey);
|
|
40
40
|
this.http.startHealthCheck(() => this.ingest.health(options.dsnKey));
|
|
41
41
|
}
|
package/dist/sdk.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.js","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"sdk.js","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAmC,MAAM,kBAAkB,CAAA;AAC7E,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAoB,MAAM,mBAAmB,CAAA;AAChE,OAAO,EACH,iBAAiB,EACjB,wBAAwB,EACxB,uBAAuB,GAO1B,MAAM,wBAAwB,CAAA;AA8B/B;;GAEG;AACH,MAAM,gBAAgB,GAAG,sDAAsD,CAAA;AAE/E;;GAEG;AACH,MAAM,OAAO,UAAU;IACnB;;OAEG;IACM,MAAM,CAAW;IAC1B;;OAEG;IACM,MAAM,CAAW;IAET,IAAI,CAAY;IAEjC;;OAEG;I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ED,uBAAuB,CAAC,OAAqC;QACzD,OAAO,uBAAuB,CAAC,OAAO,CAAC,CAAA;IAC3C,CAAC;IAED,wBAAwB,CAAC,OAAsC;QAC3D,OAAO,wBAAwB,CAAC,OAAO,CAAC,CAAA;IAC5C,CAAC;CACJ"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { IngestRequest, IngestResponse } from '../domain/ingest';
|
|
2
|
+
import type { HttpClient } from '../http/httpClient';
|
|
3
|
+
export type IngestNormalizationOptions = {
|
|
4
|
+
schemaVersion?: number;
|
|
5
|
+
includeContext?: boolean;
|
|
6
|
+
includeSystemContext?: boolean;
|
|
7
|
+
includeRuntimeContext?: boolean;
|
|
8
|
+
maxEventBytes?: number;
|
|
9
|
+
maxFrames?: number;
|
|
10
|
+
maxMessageLength?: number;
|
|
11
|
+
maxExceptionValueLength?: number;
|
|
12
|
+
};
|
|
13
|
+
export declare class IngestApi {
|
|
14
|
+
private readonly http;
|
|
15
|
+
private readonly defaultDsnKey?;
|
|
16
|
+
private readonly normalization?;
|
|
17
|
+
constructor(http: HttpClient, defaultDsnKey?: string | undefined, normalization?: IngestNormalizationOptions | undefined);
|
|
18
|
+
event(input: IngestRequest): Promise<IngestResponse>;
|
|
19
|
+
health(dsnKey?: string): Promise<{
|
|
20
|
+
ok: boolean;
|
|
21
|
+
}>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { randomUUID } from 'crypto';
|
|
2
|
+
import { ValidationError } from '../http/errors.js';
|
|
3
|
+
import { getProcessContextDynamic, getProcessContextStatic } from '../utils/processContext.js';
|
|
4
|
+
import { ensureDefined, ensureNonEmpty } from '../utils/validate.js';
|
|
5
|
+
const DEFAULT_NORMALIZATION = {
|
|
6
|
+
schemaVersion: 1,
|
|
7
|
+
includeContext: true,
|
|
8
|
+
includeSystemContext: true,
|
|
9
|
+
includeRuntimeContext: true,
|
|
10
|
+
maxEventBytes: 64 * 1024,
|
|
11
|
+
maxFrames: 60,
|
|
12
|
+
maxMessageLength: 4000,
|
|
13
|
+
maxExceptionValueLength: 4000,
|
|
14
|
+
};
|
|
15
|
+
export class IngestApi {
|
|
16
|
+
http;
|
|
17
|
+
defaultDsnKey;
|
|
18
|
+
normalization;
|
|
19
|
+
constructor(http, defaultDsnKey, normalization) {
|
|
20
|
+
this.http = http;
|
|
21
|
+
this.defaultDsnKey = defaultDsnKey;
|
|
22
|
+
this.normalization = normalization;
|
|
23
|
+
}
|
|
24
|
+
async event(input) {
|
|
25
|
+
ensureDefined(input, 'input');
|
|
26
|
+
const dsnKey = input.dsnKey ?? this.defaultDsnKey;
|
|
27
|
+
ensureDefined(dsnKey, 'dsnKey');
|
|
28
|
+
ensureNonEmpty(dsnKey, 'dsnKey');
|
|
29
|
+
ensureDefined(input.event, 'event');
|
|
30
|
+
if (input.idempotencyKey && input.idempotencyKey.length > 128) {
|
|
31
|
+
throw new ValidationError('idempotencyKey must be at most 128 characters');
|
|
32
|
+
}
|
|
33
|
+
const headers = {};
|
|
34
|
+
if (input.idempotencyKey)
|
|
35
|
+
headers['x-idempotency-key'] = input.idempotencyKey;
|
|
36
|
+
if (input.sdkVersion)
|
|
37
|
+
headers['x-sdk-version'] = input.sdkVersion;
|
|
38
|
+
const { idempotencyKey, sdkVersion, event, ...body } = input;
|
|
39
|
+
const normalizedEvent = normalizeEvent(event, this.normalization);
|
|
40
|
+
return this.http.post('/ingest/events', { ...body, dsnKey, event: normalizedEvent }, { auth: 'apiKey', headers });
|
|
41
|
+
}
|
|
42
|
+
async health(dsnKey) {
|
|
43
|
+
const resolvedDsnKey = dsnKey ?? this.defaultDsnKey;
|
|
44
|
+
ensureDefined(resolvedDsnKey, 'dsnKey');
|
|
45
|
+
ensureNonEmpty(resolvedDsnKey, 'dsnKey');
|
|
46
|
+
return this.http.post('/ingest/health', { dsnKey: resolvedDsnKey }, { auth: 'apiKey' });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function normalizeEvent(event, options) {
|
|
50
|
+
const config = { ...DEFAULT_NORMALIZATION, ...options };
|
|
51
|
+
const normalizedTimestamp = normalizeTimestamp(event.timestamp);
|
|
52
|
+
const normalizedLevel = event.level ? event.level.toLowerCase() : undefined;
|
|
53
|
+
const normalizedMessage = event.message ? truncate(event.message, config.maxMessageLength) : undefined;
|
|
54
|
+
const normalizedException = normalizeException(event.exception, config);
|
|
55
|
+
if (!normalizedMessage && !normalizedException) {
|
|
56
|
+
throw new ValidationError('event message or exception is required');
|
|
57
|
+
}
|
|
58
|
+
const normalizedContext = normalizeContext(event.context, config);
|
|
59
|
+
const normalizedEvent = {
|
|
60
|
+
...event,
|
|
61
|
+
event_id: event.event_id ?? randomUUID(),
|
|
62
|
+
timestamp: normalizedTimestamp,
|
|
63
|
+
schema_version: event.schema_version ?? config.schemaVersion,
|
|
64
|
+
level: normalizedLevel,
|
|
65
|
+
message: normalizedMessage,
|
|
66
|
+
exception: normalizedException,
|
|
67
|
+
context: normalizedContext,
|
|
68
|
+
};
|
|
69
|
+
return enforceSizeLimit(normalizedEvent, config);
|
|
70
|
+
}
|
|
71
|
+
function normalizeTimestamp(timestamp) {
|
|
72
|
+
if (!timestamp)
|
|
73
|
+
return new Date().toISOString();
|
|
74
|
+
const parsed = new Date(timestamp);
|
|
75
|
+
if (Number.isNaN(parsed.getTime())) {
|
|
76
|
+
throw new ValidationError('timestamp must be a valid ISO date');
|
|
77
|
+
}
|
|
78
|
+
return parsed.toISOString();
|
|
79
|
+
}
|
|
80
|
+
function normalizeException(exception, config) {
|
|
81
|
+
if (!exception)
|
|
82
|
+
return undefined;
|
|
83
|
+
if (!exception.type || !exception.value) {
|
|
84
|
+
throw new ValidationError('exception.type and exception.value are required');
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
...exception,
|
|
88
|
+
value: truncate(exception.value, config.maxExceptionValueLength),
|
|
89
|
+
stacktrace: normalizeStacktrace(exception.stacktrace, config.maxFrames),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function normalizeStacktrace(stacktrace, maxFrames) {
|
|
93
|
+
if (!stacktrace || !Array.isArray(stacktrace.frames))
|
|
94
|
+
return undefined;
|
|
95
|
+
const frames = stacktrace.frames;
|
|
96
|
+
const normalizedFrames = frames.slice(0, maxFrames).map((frame) => {
|
|
97
|
+
const filename = typeof frame?.filename === 'string' ? frame.filename : undefined;
|
|
98
|
+
const functionName = typeof frame?.function === 'string' ? frame.function : undefined;
|
|
99
|
+
const lineno = typeof frame?.lineno === 'number' ? frame.lineno : undefined;
|
|
100
|
+
const colno = typeof frame?.colno === 'number' ? frame.colno : undefined;
|
|
101
|
+
const inferredInApp = filename ? !filename.includes('node_modules') : false;
|
|
102
|
+
return {
|
|
103
|
+
filename,
|
|
104
|
+
function: functionName,
|
|
105
|
+
lineno,
|
|
106
|
+
colno,
|
|
107
|
+
in_app: typeof frame?.in_app === 'boolean' ? frame.in_app : inferredInApp,
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
return { frames: normalizedFrames };
|
|
111
|
+
}
|
|
112
|
+
function normalizeContext(context, config) {
|
|
113
|
+
if (!config.includeContext)
|
|
114
|
+
return context;
|
|
115
|
+
const systemContext = config.includeSystemContext ? getProcessContextDynamic() : undefined;
|
|
116
|
+
const runtimeContext = config.includeRuntimeContext ? getProcessContextStatic({ includeVersions: false }) : undefined;
|
|
117
|
+
const mergedContext = {
|
|
118
|
+
...context,
|
|
119
|
+
system: context?.system ?? systemContext,
|
|
120
|
+
runtime: context?.runtime ?? runtimeContext,
|
|
121
|
+
};
|
|
122
|
+
return mergedContext;
|
|
123
|
+
}
|
|
124
|
+
function enforceSizeLimit(event, config) {
|
|
125
|
+
let normalized = event;
|
|
126
|
+
if (getSize(normalized) <= config.maxEventBytes)
|
|
127
|
+
return normalized;
|
|
128
|
+
if (normalized.extra) {
|
|
129
|
+
normalized = { ...normalized, extra: undefined };
|
|
130
|
+
}
|
|
131
|
+
if (getSize(normalized) <= config.maxEventBytes)
|
|
132
|
+
return normalized;
|
|
133
|
+
if (normalized.tags) {
|
|
134
|
+
normalized = { ...normalized, tags: undefined };
|
|
135
|
+
}
|
|
136
|
+
if (getSize(normalized) <= config.maxEventBytes)
|
|
137
|
+
return normalized;
|
|
138
|
+
if (normalized.exception?.stacktrace) {
|
|
139
|
+
normalized = {
|
|
140
|
+
...normalized,
|
|
141
|
+
exception: { ...normalized.exception, stacktrace: undefined },
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
if (getSize(normalized) <= config.maxEventBytes)
|
|
145
|
+
return normalized;
|
|
146
|
+
if (normalized.message) {
|
|
147
|
+
normalized = { ...normalized, message: truncate(normalized.message, config.maxMessageLength) };
|
|
148
|
+
}
|
|
149
|
+
if (normalized.exception?.value) {
|
|
150
|
+
normalized = {
|
|
151
|
+
...normalized,
|
|
152
|
+
exception: { ...normalized.exception, value: truncate(normalized.exception.value, config.maxExceptionValueLength) },
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
if (getSize(normalized) <= config.maxEventBytes)
|
|
156
|
+
return normalized;
|
|
157
|
+
throw new ValidationError('event payload exceeds size limit');
|
|
158
|
+
}
|
|
159
|
+
function getSize(value) {
|
|
160
|
+
return Buffer.byteLength(JSON.stringify(value), 'utf8');
|
|
161
|
+
}
|
|
162
|
+
function truncate(value, maxLength) {
|
|
163
|
+
if (value.length <= maxLength)
|
|
164
|
+
return value;
|
|
165
|
+
return value.slice(0, maxLength);
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=ingestApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ingestApi.js","sourceRoot":"","sources":["../../../src/apis/ingestApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAEnC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAA;AAC3F,OAAO,EA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CAAC,CAAC,EAAE,SAAS,CAAC,CAAA;AACpC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { UptimeEvent, UptimeHeartbeatInput, UptimeSummary } from '../domain/uptime';
|
|
2
|
+
import type { HttpClient } from '../http/httpClient';
|
|
3
|
+
export declare class UptimeApi {
|
|
4
|
+
private readonly http;
|
|
5
|
+
private readonly defaultDsnKey?;
|
|
6
|
+
constructor(http: HttpClient, defaultDsnKey?: string | undefined);
|
|
7
|
+
recordHeartbeat(input: UptimeHeartbeatInput): Promise<UptimeEvent>;
|
|
8
|
+
history(projectId: string, date: string): Promise<UptimeEvent[]>;
|
|
9
|
+
latest(projectId: string): Promise<UptimeEvent | null>;
|
|
10
|
+
summary(projectId: string, days?: number, delayThresholdMinutes?: number): Promise<UptimeSummary[]>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ensureDefined, ensureNonEmpty } from '../utils/validate.js';
|
|
2
|
+
export class UptimeApi {
|
|
3
|
+
http;
|
|
4
|
+
defaultDsnKey;
|
|
5
|
+
constructor(http, defaultDsnKey) {
|
|
6
|
+
this.http = http;
|
|
7
|
+
this.defaultDsnKey = defaultDsnKey;
|
|
8
|
+
}
|
|
9
|
+
async recordHeartbeat(input) {
|
|
10
|
+
ensureDefined(input, 'input');
|
|
11
|
+
const dsnKey = input.dsnKey ?? this.defaultDsnKey;
|
|
12
|
+
ensureDefined(dsnKey, 'dsnKey');
|
|
13
|
+
ensureNonEmpty(dsnKey, 'dsnKey');
|
|
14
|
+
ensureNonEmpty(input.status, 'status');
|
|
15
|
+
return this.http.post('/uptime/heartbeats', { ...input, dsnKey }, { auth: 'apiKey' });
|
|
16
|
+
}
|
|
17
|
+
async history(projectId, date) {
|
|
18
|
+
ensureNonEmpty(projectId, 'projectId');
|
|
19
|
+
ensureNonEmpty(date, 'date');
|
|
20
|
+
return this.http.get(`/projects/${encodeURIComponent(projectId)}/uptime/history`, {
|
|
21
|
+
query: { date },
|
|
22
|
+
auth: 'none',
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async latest(projectId) {
|
|
26
|
+
ensureNonEmpty(projectId, 'projectId');
|
|
27
|
+
return this.http.get(`/projects/${encodeURIComponent(projectId)}/uptime/latest`, {
|
|
28
|
+
auth: 'none',
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async summary(projectId, days, delayThresholdMinutes) {
|
|
32
|
+
ensureNonEmpty(projectId, 'projectId');
|
|
33
|
+
return this.http.get(`/projects/${encodeURIComponent(projectId)}/uptime/summary`, {
|
|
34
|
+
query: { days, delayThresholdMinutes },
|
|
35
|
+
auth: 'none',
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=uptimeApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uptimeApi.js","sourceRoot":"","sources":["../../../src/apis/uptimeApi.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAMjE,MAAM,OAAO,SAAS;IAIW;IAAmC;IAAhE,YAA6B,IAAgB,EAAmB,aAAsB;QAAzD,SAAI,GAAJ,IAAI,CAAY;QAAmB,kBAAa,GAAb,aAAa,CAAS;IAAI,CAAC;IAK3F,KAAK,CAAC,eAAe,CAAC,KAA2B;QAC7C,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAC7B,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,aAAa,CAAA;QACjD,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;QAC/B,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;QAChC,cAAc,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;QACtC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAc,oBAAoB,EAAE,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;IACtG,CAAC;IAKD,KAAK,CAAC,OAAO,CAAC,SAAiB,EAAE,IAAY;QACzC,cAAc,CAAC,SAAS,EAAE,WAAW,CAAC,CAAA;QACtC,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QAC5B,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAgB,aAAa,kBAAkB,CAAC,SAAS,CAAC,iBAAiB,EAAE;YAC7F,KAAK,EAAE,EAAE,IAAI,EAAE;YACf,IAAI,EAAE,MAAM;SACf,CAAC,CAAA;IACN,CAAC;IAKD,KAAK,CAAC,MAAM,CAAC,SAAiB;QAC1B,cAAc,CAAC,SAAS,EAAE,WAAW,CAAC,CAAA;QACtC,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAqB,aAAa,kBAAkB,CAAC,SAAS,CAAC,gBAAgB,EAAE;YACjG,IAAI,EAAE,MAAM;SACf,CAAC,CAAA;IACN,CAAC;IAKD,KAAK,CAAC,OAAO,CAAC,SAAiB,EAAE,IAAa,EAAE,qBAA8B;QAC1E,cAAc,CAAC,SAAS,EAAE,WAAW,CAAC,CAAA;QACtC,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAkB,aAAa,kBAAkB,CAAC,SAAS,CAAC,iBAAiB,EAAE;YAC/F,KAAK,EAAE,EAAE,IAAI,EAAE,qBAAqB,EAAE;YACtC,IAAI,EAAE,MAAM;SACf,CAAC,CAAA;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ProcessContextDynamic, ProcessContextStatic } from '../utils/processContext';
|
|
2
|
+
export type IngestLevel = 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
|
3
|
+
export type StacktraceFrame = {
|
|
4
|
+
filename?: string;
|
|
5
|
+
function?: string;
|
|
6
|
+
lineno?: number;
|
|
7
|
+
colno?: number;
|
|
8
|
+
in_app?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type Stacktrace = {
|
|
11
|
+
frames: StacktraceFrame[];
|
|
12
|
+
};
|
|
13
|
+
export type IngestException = {
|
|
14
|
+
type: string;
|
|
15
|
+
value: string;
|
|
16
|
+
stacktrace?: Stacktrace;
|
|
17
|
+
};
|
|
18
|
+
export type RequestContext = {
|
|
19
|
+
requestId?: string;
|
|
20
|
+
userId?: string;
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
};
|
|
23
|
+
export type IngestEventContext = {
|
|
24
|
+
system?: ProcessContextDynamic;
|
|
25
|
+
runtime?: ProcessContextStatic;
|
|
26
|
+
request?: RequestContext;
|
|
27
|
+
};
|
|
28
|
+
export type IngestEvent = {
|
|
29
|
+
event_id?: string;
|
|
30
|
+
timestamp?: string;
|
|
31
|
+
schema_version?: number;
|
|
32
|
+
level?: IngestLevel;
|
|
33
|
+
message?: string;
|
|
34
|
+
exception?: IngestException;
|
|
35
|
+
context?: IngestEventContext;
|
|
36
|
+
tags?: Record<string, string>;
|
|
37
|
+
extra?: Record<string, unknown>;
|
|
38
|
+
};
|
|
39
|
+
export type IngestRequest = {
|
|
40
|
+
dsnKey?: string;
|
|
41
|
+
event: IngestEvent;
|
|
42
|
+
idempotencyKey?: string;
|
|
43
|
+
sdkVersion?: string;
|
|
44
|
+
};
|
|
45
|
+
export type IngestResponse = {
|
|
46
|
+
event_id: string;
|
|
47
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ingest.js","sourceRoot":"","sources":["../../../src/domain/ingest.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type UptimeStatus = 'up' | 'down' | 'degraded';
|
|
2
|
+
export type UptimeEvent = {
|
|
3
|
+
id: string;
|
|
4
|
+
projectId: string;
|
|
5
|
+
status: UptimeStatus;
|
|
6
|
+
message?: string;
|
|
7
|
+
responseTimeMs?: number;
|
|
8
|
+
checkedAt?: string;
|
|
9
|
+
createdAt?: string;
|
|
10
|
+
};
|
|
11
|
+
export type UptimeHeartbeatInput = {
|
|
12
|
+
dsnKey?: string;
|
|
13
|
+
status: UptimeStatus;
|
|
14
|
+
responseTimeMs?: number;
|
|
15
|
+
checkedAt?: string;
|
|
16
|
+
message?: string;
|
|
17
|
+
};
|
|
18
|
+
export type UptimeSummary = {
|
|
19
|
+
date: string;
|
|
20
|
+
missingHours?: number;
|
|
21
|
+
delayMinutes?: number;
|
|
22
|
+
delayedCount?: number;
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uptime.js","sourceRoot":"","sources":["../../../src/domain/uptime.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type ErrorDetails = {
|
|
2
|
+
status?: number;
|
|
3
|
+
code?: string;
|
|
4
|
+
details?: unknown;
|
|
5
|
+
retryAfter?: number;
|
|
6
|
+
};
|
|
7
|
+
export declare class SdkError extends Error {
|
|
8
|
+
readonly status?: number;
|
|
9
|
+
readonly code?: string;
|
|
10
|
+
readonly details?: unknown;
|
|
11
|
+
constructor(message: string, details?: ErrorDetails);
|
|
12
|
+
}
|
|
13
|
+
export declare class ValidationError extends SdkError {
|
|
14
|
+
}
|
|
15
|
+
export declare class AuthError extends SdkError {
|
|
16
|
+
}
|
|
17
|
+
export declare class ForbiddenError extends SdkError {
|
|
18
|
+
}
|
|
19
|
+
export declare class NotFoundError extends SdkError {
|
|
20
|
+
}
|
|
21
|
+
export declare class ConflictError extends SdkError {
|
|
22
|
+
}
|
|
23
|
+
export declare class RateLimitError extends SdkError {
|
|
24
|
+
readonly retryAfter?: number;
|
|
25
|
+
constructor(message: string, details?: ErrorDetails);
|
|
26
|
+
}
|
|
27
|
+
export declare class ServerError extends SdkError {
|
|
28
|
+
}
|
|
29
|
+
export declare class NetworkError extends SdkError {
|
|
30
|
+
}
|
|
31
|
+
export declare class TimeoutError extends SdkError {
|
|
32
|
+
}
|
|
33
|
+
export declare function mapHttpError(status: number, details?: unknown, retryAfter?: number): SdkError;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export class SdkError extends Error {
|
|
2
|
+
status;
|
|
3
|
+
code;
|
|
4
|
+
details;
|
|
5
|
+
constructor(message, details) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = new.target.name;
|
|
8
|
+
this.status = details?.status;
|
|
9
|
+
this.code = details?.code;
|
|
10
|
+
this.details = details?.details;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class ValidationError extends SdkError {
|
|
14
|
+
}
|
|
15
|
+
export class AuthError extends SdkError {
|
|
16
|
+
}
|
|
17
|
+
export class ForbiddenError extends SdkError {
|
|
18
|
+
}
|
|
19
|
+
export class NotFoundError extends SdkError {
|
|
20
|
+
}
|
|
21
|
+
export class ConflictError extends SdkError {
|
|
22
|
+
}
|
|
23
|
+
export class RateLimitError extends SdkError {
|
|
24
|
+
retryAfter;
|
|
25
|
+
constructor(message, details) {
|
|
26
|
+
super(message, details);
|
|
27
|
+
this.retryAfter = details?.retryAfter;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export class ServerError extends SdkError {
|
|
31
|
+
}
|
|
32
|
+
export class NetworkError extends SdkError {
|
|
33
|
+
}
|
|
34
|
+
export class TimeoutError extends SdkError {
|
|
35
|
+
}
|
|
36
|
+
export function mapHttpError(status, details, retryAfter) {
|
|
37
|
+
const info = { status, details, retryAfter };
|
|
38
|
+
if (status === 400)
|
|
39
|
+
return new ValidationError('Invalid request', info);
|
|
40
|
+
if (status === 401)
|
|
41
|
+
return new AuthError('Unauthorized', info);
|
|
42
|
+
if (status === 403)
|
|
43
|
+
return new ForbiddenError('Forbidden', info);
|
|
44
|
+
if (status === 404)
|
|
45
|
+
return new NotFoundError('Resource not found', info);
|
|
46
|
+
if (status === 409)
|
|
47
|
+
return new ConflictError('Conflict', info);
|
|
48
|
+
if (status === 429)
|
|
49
|
+
return new RateLimitError('Rate limit exceeded', info);
|
|
50
|
+
if (status >= 500)
|
|
51
|
+
return new ServerError('Server error', info);
|
|
52
|
+
return new SdkError('HTTP error', info);
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/http/errors.ts"],"names":[],"mappings":"AAaA,MAAM,OAAO,QAAS,SAAQ,KAAK;IACtB,MAAM,CAAS;IACf,IAAI,CAAS;IACb,OAAO,CAAU;IAK1B,YAAY,OAAe,EAAE,OAAsB;QAC/C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAA;QAC3B,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,CAAA;QAC7B,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,IAAI,CAAA;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,EAAE,OAAO,CAAA;IACnC,CAAC;CACJ;AAKD,MAAM,OAAO,eAAgB,SAAQ,QAAQ;CAAI;AAIjD,MAAM,OAAO,SAAU,SAAQ,QAAQ;CAAI;AAI3C,MAAM,OAAO,cAAe,SAAQ,QAAQ;CAAI;AAIhD,MAAM,OAAO,aAAc,SAAQ,QAAQ;CAAI;AAI/C,MAAM,OAAO,aAAc,SAAQ,QAAQ;CAAI;AAI/C,MAAM,OAAO,cAAe,SAAQ,QAAQ;IAC/B,UAAU,CAAS;IAE5B,YAAY,OAAe,EAAE,OAAsB;QAC/C,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACvB,IAAI,CAAC,UAAU,GAAG,OAAO,EAAE,UAAU,CAAA;IACzC,CAAC;CACJ;AAID,MAAM,OAAO,WAAY,SAAQ,QAAQ;CAAI;AAI7C,MAAM,OAAO,YAAa,SAAQ,QAAQ;CAAI;AAI9C,MAAM,OAAO,YAAa,SAAQ,QAAQ;CAAI;AAK9C,MAAM,UAAU,YAAY,CAAC,MAAc,EAAE,OAAiB,EAAE,UAAmB;IAC/E,MAAM,IAAI,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,CAAA;IAC5C,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,IAAI,eAAe,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAA;IACvE,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,IAAI,SAAS,CAAC,cAAc,EAAE,IAAI,CAAC,CAAA;IAC9D,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,IAAI,cAAc,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;IAChE,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,IAAI,aAAa,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAA;IACxE,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,IAAI,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;IAC9D,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,IAAI,cAAc,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAA;IAC1E,IAAI,MAAM,IAAI,GAAG;QAAE,OAAO,IAAI,WAAW,CAAC,cAAc,EAAE,IAAI,CAAC,CAAA;IAC/D,OAAO,IAAI,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;AAC3C,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export type AuthMode = 'apiKey' | 'none';
|
|
2
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
3
|
+
export type QueryParams = Record<string, string | number | boolean | undefined>;
|
|
4
|
+
export type RetryPolicy = {
|
|
5
|
+
retries: number;
|
|
6
|
+
retryDelayMs?: (attempt: number, response?: Response, error?: unknown) => number;
|
|
7
|
+
retryOn?: (response?: Response, error?: unknown) => boolean;
|
|
8
|
+
};
|
|
9
|
+
export type HttpClientOptions = {
|
|
10
|
+
baseUrl: string;
|
|
11
|
+
apiKey?: string;
|
|
12
|
+
timeoutMs?: number;
|
|
13
|
+
headers?: Record<string, string>;
|
|
14
|
+
retry?: RetryPolicy;
|
|
15
|
+
};
|
|
16
|
+
export type RequestOptions = {
|
|
17
|
+
method: HttpMethod;
|
|
18
|
+
path: string;
|
|
19
|
+
query?: QueryParams;
|
|
20
|
+
body?: unknown;
|
|
21
|
+
headers?: Record<string, string>;
|
|
22
|
+
auth?: AuthMode;
|
|
23
|
+
};
|
|
24
|
+
export declare class HttpClient {
|
|
25
|
+
private apiKey?;
|
|
26
|
+
private readonly baseUrl;
|
|
27
|
+
private readonly timeoutMs;
|
|
28
|
+
private readonly headers;
|
|
29
|
+
private readonly retry?;
|
|
30
|
+
private healthCheckPromise?;
|
|
31
|
+
constructor(options: HttpClientOptions);
|
|
32
|
+
setApiKey(apiKey?: string): void;
|
|
33
|
+
startHealthCheck(healthCheck: () => Promise<unknown>): void;
|
|
34
|
+
get<T>(path: string, options?: Omit<RequestOptions, 'method' | 'path'>): Promise<T>;
|
|
35
|
+
post<T>(path: string, body?: unknown, options?: Omit<RequestOptions, 'method' | 'path' | 'body'>): Promise<T>;
|
|
36
|
+
put<T>(path: string, body?: unknown, options?: Omit<RequestOptions, 'method' | 'path' | 'body'>): Promise<T>;
|
|
37
|
+
patch<T>(path: string, body?: unknown, options?: Omit<RequestOptions, 'method' | 'path' | 'body'>): Promise<T>;
|
|
38
|
+
delete<T>(path: string, options?: Omit<RequestOptions, 'method' | 'path'>): Promise<T>;
|
|
39
|
+
request<T>(options: RequestOptions): Promise<T>;
|
|
40
|
+
private execute;
|
|
41
|
+
private buildUrl;
|
|
42
|
+
private readBody;
|
|
43
|
+
private parseRetryAfter;
|
|
44
|
+
private delay;
|
|
45
|
+
}
|