@nexussdk/contracts 0.0.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/.turbo/turbo-build.log +52 -0
- package/dist/auth.cjs +4 -0
- package/dist/auth.cjs.map +1 -0
- package/dist/auth.d.mts +215 -0
- package/dist/auth.d.ts +215 -0
- package/dist/auth.mjs +3 -0
- package/dist/auth.mjs.map +1 -0
- package/dist/flags.cjs +4 -0
- package/dist/flags.cjs.map +1 -0
- package/dist/flags.d.mts +235 -0
- package/dist/flags.d.ts +235 -0
- package/dist/flags.mjs +3 -0
- package/dist/flags.mjs.map +1 -0
- package/dist/index.cjs +8 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.mjs +6 -0
- package/dist/index.mjs.map +1 -0
- package/dist/rfc7807.cjs +8 -0
- package/dist/rfc7807.cjs.map +1 -0
- package/dist/rfc7807.d.mts +76 -0
- package/dist/rfc7807.d.ts +76 -0
- package/dist/rfc7807.mjs +6 -0
- package/dist/rfc7807.mjs.map +1 -0
- package/dist/tracker.cjs +4 -0
- package/dist/tracker.cjs.map +1 -0
- package/dist/tracker.d.mts +197 -0
- package/dist/tracker.d.ts +197 -0
- package/dist/tracker.mjs +3 -0
- package/dist/tracker.mjs.map +1 -0
- package/package.json +50 -0
- package/src/auth.ts +224 -0
- package/src/flags.ts +255 -0
- package/src/index.ts +12 -0
- package/src/rfc7807.ts +76 -0
- package/src/tracker.ts +205 -0
- package/tsconfig.json +8 -0
- package/tsup.config.ts +17 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Problem Details for HTTP APIs Specification (RFC 7807).
|
|
3
|
+
* Standardized error format across Go-Gin and NestJS error responses.
|
|
4
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc7807}
|
|
5
|
+
* @module @nexus/contracts/rfc7807
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* RFC 7807 Compliant Error Schema.
|
|
9
|
+
* Ensures consistent machine-readable error diagnostics across all Nexus services.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const problem: ProblemDetails = {
|
|
13
|
+
* type: 'https://nexus.dev/errors/quota-exceeded',
|
|
14
|
+
* title: 'Monthly Quota Exceeded',
|
|
15
|
+
* status: 429,
|
|
16
|
+
* detail: "API Key 'pk_live_...' has exhausted its limit of 50,000 monthly events.",
|
|
17
|
+
* instance: '/api/v1/telemetry/errors',
|
|
18
|
+
* timestamp: '2024-06-01T12:00:00Z',
|
|
19
|
+
* };
|
|
20
|
+
*/
|
|
21
|
+
interface ProblemDetails {
|
|
22
|
+
/**
|
|
23
|
+
* URI reference identifying the problem type.
|
|
24
|
+
* Should be a stable, documented URI that clients can bookmark.
|
|
25
|
+
* @example 'https://nexus.dev/errors/rate-limit-exceeded'
|
|
26
|
+
*/
|
|
27
|
+
type: string;
|
|
28
|
+
/**
|
|
29
|
+
* Short, human-readable summary of problem type.
|
|
30
|
+
* Must be invariant across occurrences of the same problem type.
|
|
31
|
+
* @example 'Too Many Requests'
|
|
32
|
+
*/
|
|
33
|
+
title: string;
|
|
34
|
+
/**
|
|
35
|
+
* HTTP status code generated by origin server.
|
|
36
|
+
* @example 429
|
|
37
|
+
*/
|
|
38
|
+
status: number;
|
|
39
|
+
/**
|
|
40
|
+
* Human-readable explanation specific to this occurrence of the problem.
|
|
41
|
+
* May differ across occurrences of the same problem type.
|
|
42
|
+
* @example "API Key 'pk_live_a1b2...' has exhausted its monthly event limit."
|
|
43
|
+
*/
|
|
44
|
+
detail: string;
|
|
45
|
+
/**
|
|
46
|
+
* URI reference identifying specific occurrence of problem.
|
|
47
|
+
* Typically the request path that triggered the error.
|
|
48
|
+
* @example '/api/v1/telemetry/errors'
|
|
49
|
+
*/
|
|
50
|
+
instance?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Additional diagnostic error parameters for validation failures.
|
|
53
|
+
* @example [{ name: 'email', reason: 'Must be a valid email address.' }]
|
|
54
|
+
*/
|
|
55
|
+
invalidParams?: Array<{
|
|
56
|
+
/** Field name that caused the validation error. */
|
|
57
|
+
name: string;
|
|
58
|
+
/** Human-readable reason for the validation failure. */
|
|
59
|
+
reason: string;
|
|
60
|
+
}>;
|
|
61
|
+
/**
|
|
62
|
+
* ISO 8601 timestamp when error was produced.
|
|
63
|
+
* @example '2024-06-01T12:00:00.000Z'
|
|
64
|
+
*/
|
|
65
|
+
timestamp?: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Standard Nexus error type URI prefix.
|
|
69
|
+
* All RFC 7807 type values should use this base to ensure namespacing consistency.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* const type = `${NEXUS_ERROR_BASE}/rate-limit-exceeded`;
|
|
73
|
+
*/
|
|
74
|
+
declare const NEXUS_ERROR_BASE: "https://nexus.dev/errors";
|
|
75
|
+
|
|
76
|
+
export { NEXUS_ERROR_BASE, type ProblemDetails };
|
package/dist/rfc7807.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/rfc7807.ts"],"names":[],"mappings":";AA2EO,IAAM,gBAAA,GAAmB","file":"rfc7807.mjs","sourcesContent":["/**\n * @fileoverview Problem Details for HTTP APIs Specification (RFC 7807).\n * Standardized error format across Go-Gin and NestJS error responses.\n * @see {@link https://www.rfc-editor.org/rfc/rfc7807}\n * @module @nexus/contracts/rfc7807\n */\n\n/**\n * RFC 7807 Compliant Error Schema.\n * Ensures consistent machine-readable error diagnostics across all Nexus services.\n *\n * @example\n * const problem: ProblemDetails = {\n * type: 'https://nexus.dev/errors/quota-exceeded',\n * title: 'Monthly Quota Exceeded',\n * status: 429,\n * detail: \"API Key 'pk_live_...' has exhausted its limit of 50,000 monthly events.\",\n * instance: '/api/v1/telemetry/errors',\n * timestamp: '2024-06-01T12:00:00Z',\n * };\n */\nexport interface ProblemDetails {\n /**\n * URI reference identifying the problem type.\n * Should be a stable, documented URI that clients can bookmark.\n * @example 'https://nexus.dev/errors/rate-limit-exceeded'\n */\n type: string;\n /**\n * Short, human-readable summary of problem type.\n * Must be invariant across occurrences of the same problem type.\n * @example 'Too Many Requests'\n */\n title: string;\n /**\n * HTTP status code generated by origin server.\n * @example 429\n */\n status: number;\n /**\n * Human-readable explanation specific to this occurrence of the problem.\n * May differ across occurrences of the same problem type.\n * @example \"API Key 'pk_live_a1b2...' has exhausted its monthly event limit.\"\n */\n detail: string;\n /**\n * URI reference identifying specific occurrence of problem.\n * Typically the request path that triggered the error.\n * @example '/api/v1/telemetry/errors'\n */\n instance?: string;\n /**\n * Additional diagnostic error parameters for validation failures.\n * @example [{ name: 'email', reason: 'Must be a valid email address.' }]\n */\n invalidParams?: Array<{\n /** Field name that caused the validation error. */\n name: string;\n /** Human-readable reason for the validation failure. */\n reason: string;\n }>;\n /**\n * ISO 8601 timestamp when error was produced.\n * @example '2024-06-01T12:00:00.000Z'\n */\n timestamp?: string;\n}\n\n/**\n * Standard Nexus error type URI prefix.\n * All RFC 7807 type values should use this base to ensure namespacing consistency.\n *\n * @example\n * const type = `${NEXUS_ERROR_BASE}/rate-limit-exceeded`;\n */\nexport const NEXUS_ERROR_BASE = 'https://nexus.dev/errors' as const;\n"]}
|
package/dist/tracker.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"tracker.cjs"}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { Environment } from './auth.mjs';
|
|
2
|
+
import { UserContext } from './flags.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview Telemetry, Breadcrumb Tracing, and Error Ingestion contracts.
|
|
6
|
+
* @module @nexus/contracts/tracker
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Severity level of captured telemetry events.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const level: SeverityLevel = 'error';
|
|
14
|
+
*/
|
|
15
|
+
type SeverityLevel = 'debug' | 'info' | 'warning' | 'error' | 'fatal';
|
|
16
|
+
/**
|
|
17
|
+
* Categorization of user action trails leading to a crash.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const category: BreadcrumbCategory = 'ui.click';
|
|
21
|
+
*/
|
|
22
|
+
type BreadcrumbCategory = 'ui.click' | 'navigation' | 'http' | 'console' | 'custom';
|
|
23
|
+
/**
|
|
24
|
+
* Recorded trail of user activity captured before an exception.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const breadcrumb: Breadcrumb = {
|
|
28
|
+
* timestamp: 1704067200000,
|
|
29
|
+
* category: 'ui.click',
|
|
30
|
+
* message: 'Clicked button #checkout-btn',
|
|
31
|
+
* level: 'info',
|
|
32
|
+
* data: { elementId: 'checkout-btn', page: '/checkout' },
|
|
33
|
+
* };
|
|
34
|
+
*/
|
|
35
|
+
interface Breadcrumb {
|
|
36
|
+
/** Milliseconds epoch timestamp when event occurred. */
|
|
37
|
+
timestamp: number;
|
|
38
|
+
/** Categorical discriminator. */
|
|
39
|
+
category: BreadcrumbCategory;
|
|
40
|
+
/** Human-readable event description (e.g. "Clicked button #checkout-btn"). */
|
|
41
|
+
message: string;
|
|
42
|
+
/** Severity level of the action. */
|
|
43
|
+
level?: SeverityLevel;
|
|
44
|
+
/** Sanitized event payload (e.g. HTTP status, target route). */
|
|
45
|
+
data?: Record<string, unknown>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Parsed and structured stack frame information.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* const frame: StackFrame = {
|
|
52
|
+
* functionName: 'processPayment',
|
|
53
|
+
* fileName: 'https://app.example.com/chunk.abc123.js',
|
|
54
|
+
* lineNumber: 1,
|
|
55
|
+
* columnNumber: 45231,
|
|
56
|
+
* };
|
|
57
|
+
*/
|
|
58
|
+
interface StackFrame {
|
|
59
|
+
/** Name of the executing function or scope. */
|
|
60
|
+
functionName: string;
|
|
61
|
+
/** URL or relative path of the script file. */
|
|
62
|
+
fileName: string;
|
|
63
|
+
/** 1-based source line number. */
|
|
64
|
+
lineNumber: number;
|
|
65
|
+
/** 1-based source column number. */
|
|
66
|
+
columnNumber: number;
|
|
67
|
+
/** Extracted source context lines if available (after source map resolution). */
|
|
68
|
+
contextLines?: string[];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Ambient client execution device and browser context.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* const ctx: DeviceContext = {
|
|
75
|
+
* userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ...',
|
|
76
|
+
* currentUrl: 'https://app.example.com/checkout',
|
|
77
|
+
* viewport: '1920x1080',
|
|
78
|
+
* networkStatus: '4g',
|
|
79
|
+
* timezone: 'Asia/Ho_Chi_Minh',
|
|
80
|
+
* };
|
|
81
|
+
*/
|
|
82
|
+
interface DeviceContext {
|
|
83
|
+
/** Browser User-Agent string. */
|
|
84
|
+
userAgent: string;
|
|
85
|
+
/** Client operating system name and version. */
|
|
86
|
+
os?: string;
|
|
87
|
+
/** Browser name and version. */
|
|
88
|
+
browser?: string;
|
|
89
|
+
/** Viewport dimensions (e.g. "1920x1080"). */
|
|
90
|
+
viewport?: string;
|
|
91
|
+
/** Current browser window URL where error occurred. */
|
|
92
|
+
currentUrl: string;
|
|
93
|
+
/** Network connectivity condition (e.g. "4g", "wifi", "online"). */
|
|
94
|
+
networkStatus?: string;
|
|
95
|
+
/** Client timezone (e.g. "Asia/Ho_Chi_Minh"). */
|
|
96
|
+
timezone?: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Ingestion payload dispatched from @nexus/tracker to Go-Gin edge.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* const payload: ErrorEventPayload = {
|
|
103
|
+
* fingerprint: 'sha256hex...',
|
|
104
|
+
* errorType: 'TypeError',
|
|
105
|
+
* errorMessage: "Cannot read properties of undefined (reading 'map')",
|
|
106
|
+
* stackTrace: [{ functionName: 'ProductList', fileName: 'chunk.js', lineNumber: 1, columnNumber: 400 }],
|
|
107
|
+
* breadcrumbs: [],
|
|
108
|
+
* deviceContext: { userAgent: 'Mozilla/5.0...', currentUrl: '/products' },
|
|
109
|
+
* occurrenceCount: 1,
|
|
110
|
+
* clientTimestamp: 1704067200000,
|
|
111
|
+
* };
|
|
112
|
+
*/
|
|
113
|
+
interface ErrorEventPayload {
|
|
114
|
+
/**
|
|
115
|
+
* Deterministic hash representing this specific class of crash.
|
|
116
|
+
* Format: sha256(errorType + ":" + errorMessage + ":" + topFrameFile + ":" + topFrameLine)
|
|
117
|
+
*/
|
|
118
|
+
fingerprint: string;
|
|
119
|
+
/** JavaScript error type (e.g. "TypeError", "ReferenceError", "UnhandledRejection"). */
|
|
120
|
+
errorType: string;
|
|
121
|
+
/** Primary error message string. */
|
|
122
|
+
errorMessage: string;
|
|
123
|
+
/** Parsed stack trace frames from innermost to outermost. */
|
|
124
|
+
stackTrace: StackFrame[];
|
|
125
|
+
/** Chronological ring-buffer trail of events prior to crash (max 20). */
|
|
126
|
+
breadcrumbs: Breadcrumb[];
|
|
127
|
+
/** End-user context at time of crash (sanitized before transmission). */
|
|
128
|
+
userContext?: UserContext;
|
|
129
|
+
/** Client environment context. */
|
|
130
|
+
deviceContext: DeviceContext;
|
|
131
|
+
/** Key-value metadata tags for search aggregation. */
|
|
132
|
+
tags?: Record<string, string>;
|
|
133
|
+
/**
|
|
134
|
+
* Counter tracking consecutive duplicate occurrences aggregated by client.
|
|
135
|
+
* Prevents infinite loop crash cascades from overwhelming ingestion.
|
|
136
|
+
*/
|
|
137
|
+
occurrenceCount: number;
|
|
138
|
+
/** Client-side epoch timestamp in milliseconds when error was captured. */
|
|
139
|
+
clientTimestamp: number;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Persistent error event record stored in PostgreSQL and returned to Shell UI.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* const entity: ErrorEventEntity = {
|
|
146
|
+
* ...payload,
|
|
147
|
+
* id: 'uuid-v4',
|
|
148
|
+
* projectId: 'project-uuid',
|
|
149
|
+
* environment: 'production',
|
|
150
|
+
* serverReceivedAt: '2024-01-01T00:00:05Z',
|
|
151
|
+
* };
|
|
152
|
+
*/
|
|
153
|
+
interface ErrorEventEntity extends ErrorEventPayload {
|
|
154
|
+
/** Unique UUID v4 identifier. */
|
|
155
|
+
id: string;
|
|
156
|
+
/** Project UUID v4 identifier. */
|
|
157
|
+
projectId: string;
|
|
158
|
+
/** Target deployment environment. */
|
|
159
|
+
environment: Environment;
|
|
160
|
+
/** Timestamp when Go-Gin successfully processed and recorded the event. */
|
|
161
|
+
serverReceivedAt: string;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Aggregated error group item displayed on the Console Dashboard.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* const group: ErrorGroupSummary = {
|
|
168
|
+
* fingerprint: 'sha256hex...',
|
|
169
|
+
* errorType: 'TypeError',
|
|
170
|
+
* errorMessage: "Cannot read properties of undefined (reading 'map')",
|
|
171
|
+
* environment: 'production',
|
|
172
|
+
* totalCount: 1547,
|
|
173
|
+
* affectedUsersCount: 234,
|
|
174
|
+
* firstSeenAt: '2024-01-01T10:00:00Z',
|
|
175
|
+
* lastSeenAt: '2024-06-15T14:32:01Z',
|
|
176
|
+
* };
|
|
177
|
+
*/
|
|
178
|
+
interface ErrorGroupSummary {
|
|
179
|
+
/** Fingerprint common to all events in this group. */
|
|
180
|
+
fingerprint: string;
|
|
181
|
+
/** Error type classification. */
|
|
182
|
+
errorType: string;
|
|
183
|
+
/** Primary error message. */
|
|
184
|
+
errorMessage: string;
|
|
185
|
+
/** Environment where errors occurred. */
|
|
186
|
+
environment: Environment;
|
|
187
|
+
/** Total sum of crash occurrences across all end-users. */
|
|
188
|
+
totalCount: number;
|
|
189
|
+
/** Count of unique users impacted by this crash group. */
|
|
190
|
+
affectedUsersCount: number;
|
|
191
|
+
/** Timestamp of the first time this crash was ever seen. */
|
|
192
|
+
firstSeenAt: string;
|
|
193
|
+
/** Timestamp of the latest crash occurrence. */
|
|
194
|
+
lastSeenAt: string;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export { type Breadcrumb, type BreadcrumbCategory, type DeviceContext, type ErrorEventEntity, type ErrorEventPayload, type ErrorGroupSummary, type SeverityLevel, type StackFrame, UserContext };
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { Environment } from './auth.js';
|
|
2
|
+
import { UserContext } from './flags.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview Telemetry, Breadcrumb Tracing, and Error Ingestion contracts.
|
|
6
|
+
* @module @nexus/contracts/tracker
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Severity level of captured telemetry events.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const level: SeverityLevel = 'error';
|
|
14
|
+
*/
|
|
15
|
+
type SeverityLevel = 'debug' | 'info' | 'warning' | 'error' | 'fatal';
|
|
16
|
+
/**
|
|
17
|
+
* Categorization of user action trails leading to a crash.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const category: BreadcrumbCategory = 'ui.click';
|
|
21
|
+
*/
|
|
22
|
+
type BreadcrumbCategory = 'ui.click' | 'navigation' | 'http' | 'console' | 'custom';
|
|
23
|
+
/**
|
|
24
|
+
* Recorded trail of user activity captured before an exception.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const breadcrumb: Breadcrumb = {
|
|
28
|
+
* timestamp: 1704067200000,
|
|
29
|
+
* category: 'ui.click',
|
|
30
|
+
* message: 'Clicked button #checkout-btn',
|
|
31
|
+
* level: 'info',
|
|
32
|
+
* data: { elementId: 'checkout-btn', page: '/checkout' },
|
|
33
|
+
* };
|
|
34
|
+
*/
|
|
35
|
+
interface Breadcrumb {
|
|
36
|
+
/** Milliseconds epoch timestamp when event occurred. */
|
|
37
|
+
timestamp: number;
|
|
38
|
+
/** Categorical discriminator. */
|
|
39
|
+
category: BreadcrumbCategory;
|
|
40
|
+
/** Human-readable event description (e.g. "Clicked button #checkout-btn"). */
|
|
41
|
+
message: string;
|
|
42
|
+
/** Severity level of the action. */
|
|
43
|
+
level?: SeverityLevel;
|
|
44
|
+
/** Sanitized event payload (e.g. HTTP status, target route). */
|
|
45
|
+
data?: Record<string, unknown>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Parsed and structured stack frame information.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* const frame: StackFrame = {
|
|
52
|
+
* functionName: 'processPayment',
|
|
53
|
+
* fileName: 'https://app.example.com/chunk.abc123.js',
|
|
54
|
+
* lineNumber: 1,
|
|
55
|
+
* columnNumber: 45231,
|
|
56
|
+
* };
|
|
57
|
+
*/
|
|
58
|
+
interface StackFrame {
|
|
59
|
+
/** Name of the executing function or scope. */
|
|
60
|
+
functionName: string;
|
|
61
|
+
/** URL or relative path of the script file. */
|
|
62
|
+
fileName: string;
|
|
63
|
+
/** 1-based source line number. */
|
|
64
|
+
lineNumber: number;
|
|
65
|
+
/** 1-based source column number. */
|
|
66
|
+
columnNumber: number;
|
|
67
|
+
/** Extracted source context lines if available (after source map resolution). */
|
|
68
|
+
contextLines?: string[];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Ambient client execution device and browser context.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* const ctx: DeviceContext = {
|
|
75
|
+
* userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ...',
|
|
76
|
+
* currentUrl: 'https://app.example.com/checkout',
|
|
77
|
+
* viewport: '1920x1080',
|
|
78
|
+
* networkStatus: '4g',
|
|
79
|
+
* timezone: 'Asia/Ho_Chi_Minh',
|
|
80
|
+
* };
|
|
81
|
+
*/
|
|
82
|
+
interface DeviceContext {
|
|
83
|
+
/** Browser User-Agent string. */
|
|
84
|
+
userAgent: string;
|
|
85
|
+
/** Client operating system name and version. */
|
|
86
|
+
os?: string;
|
|
87
|
+
/** Browser name and version. */
|
|
88
|
+
browser?: string;
|
|
89
|
+
/** Viewport dimensions (e.g. "1920x1080"). */
|
|
90
|
+
viewport?: string;
|
|
91
|
+
/** Current browser window URL where error occurred. */
|
|
92
|
+
currentUrl: string;
|
|
93
|
+
/** Network connectivity condition (e.g. "4g", "wifi", "online"). */
|
|
94
|
+
networkStatus?: string;
|
|
95
|
+
/** Client timezone (e.g. "Asia/Ho_Chi_Minh"). */
|
|
96
|
+
timezone?: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Ingestion payload dispatched from @nexus/tracker to Go-Gin edge.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* const payload: ErrorEventPayload = {
|
|
103
|
+
* fingerprint: 'sha256hex...',
|
|
104
|
+
* errorType: 'TypeError',
|
|
105
|
+
* errorMessage: "Cannot read properties of undefined (reading 'map')",
|
|
106
|
+
* stackTrace: [{ functionName: 'ProductList', fileName: 'chunk.js', lineNumber: 1, columnNumber: 400 }],
|
|
107
|
+
* breadcrumbs: [],
|
|
108
|
+
* deviceContext: { userAgent: 'Mozilla/5.0...', currentUrl: '/products' },
|
|
109
|
+
* occurrenceCount: 1,
|
|
110
|
+
* clientTimestamp: 1704067200000,
|
|
111
|
+
* };
|
|
112
|
+
*/
|
|
113
|
+
interface ErrorEventPayload {
|
|
114
|
+
/**
|
|
115
|
+
* Deterministic hash representing this specific class of crash.
|
|
116
|
+
* Format: sha256(errorType + ":" + errorMessage + ":" + topFrameFile + ":" + topFrameLine)
|
|
117
|
+
*/
|
|
118
|
+
fingerprint: string;
|
|
119
|
+
/** JavaScript error type (e.g. "TypeError", "ReferenceError", "UnhandledRejection"). */
|
|
120
|
+
errorType: string;
|
|
121
|
+
/** Primary error message string. */
|
|
122
|
+
errorMessage: string;
|
|
123
|
+
/** Parsed stack trace frames from innermost to outermost. */
|
|
124
|
+
stackTrace: StackFrame[];
|
|
125
|
+
/** Chronological ring-buffer trail of events prior to crash (max 20). */
|
|
126
|
+
breadcrumbs: Breadcrumb[];
|
|
127
|
+
/** End-user context at time of crash (sanitized before transmission). */
|
|
128
|
+
userContext?: UserContext;
|
|
129
|
+
/** Client environment context. */
|
|
130
|
+
deviceContext: DeviceContext;
|
|
131
|
+
/** Key-value metadata tags for search aggregation. */
|
|
132
|
+
tags?: Record<string, string>;
|
|
133
|
+
/**
|
|
134
|
+
* Counter tracking consecutive duplicate occurrences aggregated by client.
|
|
135
|
+
* Prevents infinite loop crash cascades from overwhelming ingestion.
|
|
136
|
+
*/
|
|
137
|
+
occurrenceCount: number;
|
|
138
|
+
/** Client-side epoch timestamp in milliseconds when error was captured. */
|
|
139
|
+
clientTimestamp: number;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Persistent error event record stored in PostgreSQL and returned to Shell UI.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* const entity: ErrorEventEntity = {
|
|
146
|
+
* ...payload,
|
|
147
|
+
* id: 'uuid-v4',
|
|
148
|
+
* projectId: 'project-uuid',
|
|
149
|
+
* environment: 'production',
|
|
150
|
+
* serverReceivedAt: '2024-01-01T00:00:05Z',
|
|
151
|
+
* };
|
|
152
|
+
*/
|
|
153
|
+
interface ErrorEventEntity extends ErrorEventPayload {
|
|
154
|
+
/** Unique UUID v4 identifier. */
|
|
155
|
+
id: string;
|
|
156
|
+
/** Project UUID v4 identifier. */
|
|
157
|
+
projectId: string;
|
|
158
|
+
/** Target deployment environment. */
|
|
159
|
+
environment: Environment;
|
|
160
|
+
/** Timestamp when Go-Gin successfully processed and recorded the event. */
|
|
161
|
+
serverReceivedAt: string;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Aggregated error group item displayed on the Console Dashboard.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* const group: ErrorGroupSummary = {
|
|
168
|
+
* fingerprint: 'sha256hex...',
|
|
169
|
+
* errorType: 'TypeError',
|
|
170
|
+
* errorMessage: "Cannot read properties of undefined (reading 'map')",
|
|
171
|
+
* environment: 'production',
|
|
172
|
+
* totalCount: 1547,
|
|
173
|
+
* affectedUsersCount: 234,
|
|
174
|
+
* firstSeenAt: '2024-01-01T10:00:00Z',
|
|
175
|
+
* lastSeenAt: '2024-06-15T14:32:01Z',
|
|
176
|
+
* };
|
|
177
|
+
*/
|
|
178
|
+
interface ErrorGroupSummary {
|
|
179
|
+
/** Fingerprint common to all events in this group. */
|
|
180
|
+
fingerprint: string;
|
|
181
|
+
/** Error type classification. */
|
|
182
|
+
errorType: string;
|
|
183
|
+
/** Primary error message. */
|
|
184
|
+
errorMessage: string;
|
|
185
|
+
/** Environment where errors occurred. */
|
|
186
|
+
environment: Environment;
|
|
187
|
+
/** Total sum of crash occurrences across all end-users. */
|
|
188
|
+
totalCount: number;
|
|
189
|
+
/** Count of unique users impacted by this crash group. */
|
|
190
|
+
affectedUsersCount: number;
|
|
191
|
+
/** Timestamp of the first time this crash was ever seen. */
|
|
192
|
+
firstSeenAt: string;
|
|
193
|
+
/** Timestamp of the latest crash occurrence. */
|
|
194
|
+
lastSeenAt: string;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export { type Breadcrumb, type BreadcrumbCategory, type DeviceContext, type ErrorEventEntity, type ErrorEventPayload, type ErrorGroupSummary, type SeverityLevel, type StackFrame, UserContext };
|
package/dist/tracker.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"tracker.mjs"}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nexussdk/contracts",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"description": "Single Source of Truth (SSOT) data contracts for the Nexus Platform ecosystem",
|
|
9
|
+
"main": "./dist/index.cjs",
|
|
10
|
+
"module": "./dist/index.mjs",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.mjs",
|
|
16
|
+
"require": "./dist/index.cjs"
|
|
17
|
+
},
|
|
18
|
+
"./flags": {
|
|
19
|
+
"types": "./dist/flags.d.ts",
|
|
20
|
+
"import": "./dist/flags.mjs",
|
|
21
|
+
"require": "./dist/flags.cjs"
|
|
22
|
+
},
|
|
23
|
+
"./tracker": {
|
|
24
|
+
"types": "./dist/tracker.d.ts",
|
|
25
|
+
"import": "./dist/tracker.mjs",
|
|
26
|
+
"require": "./dist/tracker.cjs"
|
|
27
|
+
},
|
|
28
|
+
"./auth": {
|
|
29
|
+
"types": "./dist/auth.d.ts",
|
|
30
|
+
"import": "./dist/auth.mjs",
|
|
31
|
+
"require": "./dist/auth.cjs"
|
|
32
|
+
},
|
|
33
|
+
"./rfc7807": {
|
|
34
|
+
"types": "./dist/rfc7807.d.ts",
|
|
35
|
+
"import": "./dist/rfc7807.mjs",
|
|
36
|
+
"require": "./dist/rfc7807.cjs"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"tsup": "^8.0.2",
|
|
41
|
+
"typescript": "^5.4.5",
|
|
42
|
+
"rimraf": "^5.0.5"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup",
|
|
46
|
+
"dev": "tsup --watch",
|
|
47
|
+
"lint": "tsc --noEmit",
|
|
48
|
+
"clean": "rimraf dist"
|
|
49
|
+
}
|
|
50
|
+
}
|