@sourceaxis/errors 0.1.0

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 ADDED
@@ -0,0 +1,36 @@
1
+ # @sourceaxis/errors
2
+
3
+ Stable public error hierarchy for SourceAxis.
4
+
5
+ ## Responsibilities
6
+
7
+ - Provide `SourceAxisError` as the base public error type.
8
+ - Expose stable error codes, retryability, categories, severity, timestamps, diagnostics, and
9
+ serialization.
10
+ - Provide typed subclasses for authentication, authorization, configuration, provider, repository,
11
+ transport, timeout, cancellation, validation, conflict, not-found, rate-limit, unsupported
12
+ capability, and unexpected failures.
13
+
14
+ ## Install
15
+
16
+ ```sh
17
+ pnpm add @sourceaxis/errors
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```ts
23
+ import { SourceAxisError } from "@sourceaxis/errors";
24
+
25
+ try {
26
+ await operation();
27
+ } catch (error) {
28
+ if (error instanceof SourceAxisError) {
29
+ console.error(error.code, error.retryability, error.diagnostics);
30
+ } else {
31
+ throw error;
32
+ }
33
+ }
34
+ ```
35
+
36
+ Use `serialize()` or `toJSON()` for safe diagnostics and telemetry payloads.
@@ -0,0 +1,363 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnexpectedError = exports.RepositoryError = exports.NotFoundError = exports.ConflictError = exports.AuthorizationError = exports.CapabilityNotSupportedError = exports.RateLimitError = exports.ProviderError = exports.AuthenticationError = exports.CancellationError = exports.TimeoutError = exports.TransportError = exports.ConfigurationError = exports.ValidationError = exports.SourceAxisError = exports.ErrorCodes = void 0;
4
+ /**
5
+ * Stable public error codes. These codes are part of the compatibility contract.
6
+ */
7
+ exports.ErrorCodes = {
8
+ Authentication: "SOURCEAXIS_AUTHENTICATION",
9
+ Authorization: "SOURCEAXIS_PERMISSION_DENIED",
10
+ Cancellation: "SOURCEAXIS_CANCELLED",
11
+ CapabilityNotSupported: "SOURCEAXIS_CAPABILITY_NOT_SUPPORTED",
12
+ Configuration: "SOURCEAXIS_CONFIGURATION",
13
+ Conflict: "SOURCEAXIS_CONFLICT",
14
+ NotFound: "SOURCEAXIS_NOT_FOUND",
15
+ Provider: "SOURCEAXIS_PROVIDER",
16
+ RateLimit: "SOURCEAXIS_RATE_LIMITED",
17
+ Repository: "SOURCEAXIS_REPOSITORY",
18
+ Timeout: "SOURCEAXIS_TIMEOUT",
19
+ Transport: "SOURCEAXIS_TRANSPORT",
20
+ Unexpected: "SOURCEAXIS_UNEXPECTED",
21
+ Validation: "SOURCEAXIS_VALIDATION"
22
+ };
23
+ const definitions = {
24
+ AuthenticationError: {
25
+ category: "authentication",
26
+ code: exports.ErrorCodes.Authentication,
27
+ retryability: "Never",
28
+ severity: "error"
29
+ },
30
+ CancellationError: {
31
+ category: "transport",
32
+ code: exports.ErrorCodes.Cancellation,
33
+ retryability: "Never",
34
+ severity: "info"
35
+ },
36
+ CapabilityNotSupportedError: {
37
+ category: "provider",
38
+ code: exports.ErrorCodes.CapabilityNotSupported,
39
+ retryability: "Never",
40
+ severity: "warning"
41
+ },
42
+ ConfigurationError: {
43
+ category: "configuration",
44
+ code: exports.ErrorCodes.Configuration,
45
+ retryability: "Never",
46
+ severity: "error"
47
+ },
48
+ ConflictError: {
49
+ category: "provider",
50
+ code: exports.ErrorCodes.Conflict,
51
+ retryability: "Maybe",
52
+ severity: "warning"
53
+ },
54
+ SourceAxisError: {
55
+ category: "unexpected",
56
+ code: exports.ErrorCodes.Unexpected,
57
+ retryability: "Never",
58
+ severity: "error"
59
+ },
60
+ NotFoundError: {
61
+ category: "provider",
62
+ code: exports.ErrorCodes.NotFound,
63
+ retryability: "Never",
64
+ severity: "warning"
65
+ },
66
+ AuthorizationError: {
67
+ category: "provider",
68
+ code: exports.ErrorCodes.Authorization,
69
+ retryability: "Never",
70
+ severity: "error"
71
+ },
72
+ ProviderError: {
73
+ category: "provider",
74
+ code: exports.ErrorCodes.Provider,
75
+ retryability: "Maybe",
76
+ severity: "error"
77
+ },
78
+ RateLimitError: {
79
+ category: "provider",
80
+ code: exports.ErrorCodes.RateLimit,
81
+ retryability: "Always",
82
+ severity: "warning"
83
+ },
84
+ RepositoryError: {
85
+ category: "repository",
86
+ code: exports.ErrorCodes.Repository,
87
+ retryability: "Maybe",
88
+ severity: "error"
89
+ },
90
+ TimeoutError: {
91
+ category: "transport",
92
+ code: exports.ErrorCodes.Timeout,
93
+ retryability: "Maybe",
94
+ severity: "warning"
95
+ },
96
+ TransportError: {
97
+ category: "transport",
98
+ code: exports.ErrorCodes.Transport,
99
+ retryability: "Maybe",
100
+ severity: "error"
101
+ },
102
+ UnexpectedError: {
103
+ category: "unexpected",
104
+ code: exports.ErrorCodes.Unexpected,
105
+ retryability: "Never",
106
+ severity: "critical"
107
+ },
108
+ ValidationError: {
109
+ category: "validation",
110
+ code: exports.ErrorCodes.Validation,
111
+ retryability: "Never",
112
+ severity: "warning"
113
+ }
114
+ };
115
+ /**
116
+ * Base class for every public SourceAxis error.
117
+ */
118
+ class SourceAxisError extends Error {
119
+ /**
120
+ * Stable public error code.
121
+ */
122
+ code;
123
+ /**
124
+ * Retry guidance for callers and retry middleware.
125
+ */
126
+ retryability;
127
+ /**
128
+ * Provider-neutral error category.
129
+ */
130
+ category;
131
+ /**
132
+ * Diagnostic severity.
133
+ */
134
+ severity;
135
+ /**
136
+ * ISO-8601 timestamp captured when the error is created.
137
+ */
138
+ timestamp;
139
+ /**
140
+ * Safe structured diagnostic context.
141
+ */
142
+ diagnostics;
143
+ /**
144
+ * Immutable error metadata.
145
+ */
146
+ metadata;
147
+ constructor(message, options = {}) {
148
+ const definition = getDefinition(new.target.name);
149
+ super(message, createErrorOptions(options.cause));
150
+ Object.setPrototypeOf(this, new.target.prototype);
151
+ this.name = new.target.name;
152
+ this.code = definition.code;
153
+ this.retryability = options.retryability ?? definition.retryability;
154
+ this.category = definition.category;
155
+ this.severity = options.severity ?? definition.severity;
156
+ this.timestamp = normalizeTimestamp(options.timestamp);
157
+ this.diagnostics = freezeDiagnostics(options.diagnostics);
158
+ this.metadata = deepFreeze({
159
+ category: this.category,
160
+ code: this.code,
161
+ retryability: this.retryability,
162
+ severity: this.severity,
163
+ timestamp: this.timestamp
164
+ });
165
+ if (Error.captureStackTrace !== undefined) {
166
+ Error.captureStackTrace(this, new.target);
167
+ }
168
+ Object.freeze(this);
169
+ }
170
+ /**
171
+ * Returns a deterministic, safe representation suitable for diagnostics and telemetry.
172
+ */
173
+ toJSON() {
174
+ const serialized = {
175
+ category: this.category,
176
+ code: this.code,
177
+ diagnostics: this.diagnostics,
178
+ message: this.message,
179
+ name: this.name,
180
+ retryability: this.retryability,
181
+ severity: this.severity,
182
+ timestamp: this.timestamp
183
+ };
184
+ const cause = serializeCause(this.cause);
185
+ if (cause !== undefined) {
186
+ serialized.cause = cause;
187
+ }
188
+ return deepFreeze(serialized);
189
+ }
190
+ /**
191
+ * Returns the canonical serialized representation.
192
+ */
193
+ serialize() {
194
+ return this.toJSON();
195
+ }
196
+ }
197
+ exports.SourceAxisError = SourceAxisError;
198
+ /**
199
+ * Validation failure detected before an operation executes.
200
+ */
201
+ class ValidationError extends SourceAxisError {
202
+ constructor(message, options = {}) {
203
+ super(message, options);
204
+ }
205
+ }
206
+ exports.ValidationError = ValidationError;
207
+ /**
208
+ * Invalid or missing SourceAxis configuration.
209
+ */
210
+ class ConfigurationError extends SourceAxisError {
211
+ constructor(message, options = {}) {
212
+ super(message, options);
213
+ }
214
+ }
215
+ exports.ConfigurationError = ConfigurationError;
216
+ /**
217
+ * Transport-neutral execution failure.
218
+ */
219
+ class TransportError extends SourceAxisError {
220
+ constructor(message, options = {}) {
221
+ super(message, options);
222
+ }
223
+ }
224
+ exports.TransportError = TransportError;
225
+ /**
226
+ * Request execution exceeded an allowed duration.
227
+ */
228
+ class TimeoutError extends TransportError {
229
+ constructor(message, options = {}) {
230
+ super(message, options);
231
+ }
232
+ }
233
+ exports.TimeoutError = TimeoutError;
234
+ /**
235
+ * Operation was intentionally interrupted.
236
+ */
237
+ class CancellationError extends TransportError {
238
+ constructor(message, options = {}) {
239
+ super(message, options);
240
+ }
241
+ }
242
+ exports.CancellationError = CancellationError;
243
+ /**
244
+ * Authentication failure.
245
+ */
246
+ class AuthenticationError extends SourceAxisError {
247
+ constructor(message, options = {}) {
248
+ super(message, options);
249
+ }
250
+ }
251
+ exports.AuthenticationError = AuthenticationError;
252
+ /**
253
+ * Provider-neutral provider failure.
254
+ */
255
+ class ProviderError extends SourceAxisError {
256
+ constructor(message, options = {}) {
257
+ super(message, options);
258
+ }
259
+ }
260
+ exports.ProviderError = ProviderError;
261
+ /**
262
+ * Provider rate limit failure.
263
+ */
264
+ class RateLimitError extends ProviderError {
265
+ constructor(message, options = {}) {
266
+ super(message, options);
267
+ }
268
+ }
269
+ exports.RateLimitError = RateLimitError;
270
+ /**
271
+ * Requested provider capability is not supported.
272
+ */
273
+ class CapabilityNotSupportedError extends ProviderError {
274
+ constructor(message, options = {}) {
275
+ super(message, options);
276
+ }
277
+ }
278
+ exports.CapabilityNotSupportedError = CapabilityNotSupportedError;
279
+ /**
280
+ * Provider denied permission for the requested operation.
281
+ */
282
+ class AuthorizationError extends ProviderError {
283
+ constructor(message, options = {}) {
284
+ super(message, options);
285
+ }
286
+ }
287
+ exports.AuthorizationError = AuthorizationError;
288
+ /**
289
+ * Provider reported a conflict for the requested operation.
290
+ */
291
+ class ConflictError extends ProviderError {
292
+ constructor(message, options = {}) {
293
+ super(message, options);
294
+ }
295
+ }
296
+ exports.ConflictError = ConflictError;
297
+ /**
298
+ * Provider or repository resource was not found.
299
+ */
300
+ class NotFoundError extends ProviderError {
301
+ constructor(message, options = {}) {
302
+ super(message, options);
303
+ }
304
+ }
305
+ exports.NotFoundError = NotFoundError;
306
+ /**
307
+ * Repository lifecycle or repository state failure.
308
+ */
309
+ class RepositoryError extends SourceAxisError {
310
+ constructor(message, options = {}) {
311
+ super(message, options);
312
+ }
313
+ }
314
+ exports.RepositoryError = RepositoryError;
315
+ /**
316
+ * Internal defect or unforeseen runtime condition.
317
+ */
318
+ class UnexpectedError extends SourceAxisError {
319
+ constructor(message, options = {}) {
320
+ super(message, options);
321
+ }
322
+ }
323
+ exports.UnexpectedError = UnexpectedError;
324
+ function getDefinition(name) {
325
+ return definitions[name] ?? definitions.SourceAxisError;
326
+ }
327
+ function createErrorOptions(cause) {
328
+ return cause === undefined ? undefined : { cause };
329
+ }
330
+ function normalizeTimestamp(timestamp) {
331
+ if (timestamp instanceof Date) {
332
+ return timestamp.toISOString();
333
+ }
334
+ return timestamp ?? new Date().toISOString();
335
+ }
336
+ function freezeDiagnostics(diagnostics) {
337
+ return deepFreeze(diagnostics ?? {});
338
+ }
339
+ function serializeCause(cause) {
340
+ if (cause instanceof SourceAxisError) {
341
+ return cause.toJSON();
342
+ }
343
+ if (cause instanceof Error) {
344
+ return deepFreeze({ name: cause.name });
345
+ }
346
+ if (cause === undefined) {
347
+ return undefined;
348
+ }
349
+ return deepFreeze({ name: typeof cause });
350
+ }
351
+ function deepFreeze(value) {
352
+ if (value === null || (typeof value !== "object" && typeof value !== "function")) {
353
+ return value;
354
+ }
355
+ for (const key of Reflect.ownKeys(value)) {
356
+ const child = value[key];
357
+ if (child !== null && (typeof child === "object" || typeof child === "function")) {
358
+ deepFreeze(child);
359
+ }
360
+ }
361
+ return Object.freeze(value);
362
+ }
363
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAKA;;GAEG;AACU,QAAA,UAAU,GAAG;IACxB,cAAc,EAAE,2BAA2B;IAC3C,aAAa,EAAE,8BAA8B;IAC7C,YAAY,EAAE,sBAAsB;IACpC,sBAAsB,EAAE,qCAAqC;IAC7D,aAAa,EAAE,0BAA0B;IACzC,QAAQ,EAAE,qBAAqB;IAC/B,QAAQ,EAAE,sBAAsB;IAChC,QAAQ,EAAE,qBAAqB;IAC/B,SAAS,EAAE,yBAAyB;IACpC,UAAU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E,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,UAAU,CAAC,EAAE,IAAI,EAAE,OAAO,KAAK,EAAE,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,UAAU,CAAI,KAAQ;IAC7B,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,UAAU,CAAC,EAAE,CAAC;QACjF,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzC,MAAM,KAAK,GAAI,KAAsC,CAAC,GAAG,CAAC,CAAC;QAE3D,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,UAAU,CAAC,EAAE,CAAC;YACjF,UAAU,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC"}
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,262 @@
1
+ /**
2
+ * Retry guidance exposed by every public SourceAxis error.
3
+ */
4
+ export type ErrorRetryability = "Never" | "Maybe" | "Always";
5
+ /**
6
+ * Stable public error codes. These codes are part of the compatibility contract.
7
+ */
8
+ export declare const ErrorCodes: {
9
+ readonly Authentication: "SOURCEAXIS_AUTHENTICATION";
10
+ readonly Authorization: "SOURCEAXIS_PERMISSION_DENIED";
11
+ readonly Cancellation: "SOURCEAXIS_CANCELLED";
12
+ readonly CapabilityNotSupported: "SOURCEAXIS_CAPABILITY_NOT_SUPPORTED";
13
+ readonly Configuration: "SOURCEAXIS_CONFIGURATION";
14
+ readonly Conflict: "SOURCEAXIS_CONFLICT";
15
+ readonly NotFound: "SOURCEAXIS_NOT_FOUND";
16
+ readonly Provider: "SOURCEAXIS_PROVIDER";
17
+ readonly RateLimit: "SOURCEAXIS_RATE_LIMITED";
18
+ readonly Repository: "SOURCEAXIS_REPOSITORY";
19
+ readonly Timeout: "SOURCEAXIS_TIMEOUT";
20
+ readonly Transport: "SOURCEAXIS_TRANSPORT";
21
+ readonly Unexpected: "SOURCEAXIS_UNEXPECTED";
22
+ readonly Validation: "SOURCEAXIS_VALIDATION";
23
+ };
24
+ /**
25
+ * Stable public error code.
26
+ */
27
+ export type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
28
+ /**
29
+ * Public classification for SourceAxis errors.
30
+ */
31
+ export type ErrorCategory = "authentication" | "configuration" | "provider" | "repository" | "transport" | "unexpected" | "validation";
32
+ /**
33
+ * Diagnostic severity for a SourceAxis error.
34
+ */
35
+ export type ErrorSeverity = "debug" | "info" | "warning" | "error" | "critical";
36
+ /**
37
+ * JSON-safe primitive value accepted in diagnostics.
38
+ */
39
+ export type DiagnosticPrimitive = string | number | boolean | null;
40
+ /**
41
+ * JSON-safe diagnostic value accepted in public errors.
42
+ */
43
+ export type DiagnosticValue = DiagnosticPrimitive | readonly DiagnosticValue[] | {
44
+ readonly [key: string]: DiagnosticValue;
45
+ };
46
+ /**
47
+ * Operation-level diagnostic context.
48
+ */
49
+ export type OperationDiagnostics = Readonly<{
50
+ operation?: string;
51
+ capability?: string;
52
+ retryCount?: number;
53
+ elapsedMs?: number;
54
+ correlationId?: string;
55
+ }>;
56
+ /**
57
+ * Repository-level diagnostic context.
58
+ */
59
+ export type RepositoryDiagnostics = Readonly<{
60
+ provider?: string;
61
+ repository?: string;
62
+ reference?: string;
63
+ path?: string;
64
+ }>;
65
+ /**
66
+ * Provider-neutral diagnostic context.
67
+ */
68
+ export type ProviderDiagnostics = Readonly<{
69
+ provider?: string;
70
+ requestId?: string;
71
+ activityId?: string;
72
+ status?: number;
73
+ providerCode?: string;
74
+ }>;
75
+ /**
76
+ * Transport-neutral diagnostic context.
77
+ */
78
+ export type TransportDiagnostics = Readonly<{
79
+ transport?: string;
80
+ timeoutMs?: number;
81
+ cancelled?: boolean;
82
+ requestMethod?: string;
83
+ requestUrl?: string;
84
+ }>;
85
+ /**
86
+ * Safe structured diagnostic context exposed by SourceAxis errors.
87
+ */
88
+ export type ErrorDiagnostics = Readonly<{
89
+ operation?: OperationDiagnostics;
90
+ repository?: RepositoryDiagnostics;
91
+ provider?: ProviderDiagnostics;
92
+ transport?: TransportDiagnostics;
93
+ extra?: Readonly<Record<string, DiagnosticValue>>;
94
+ }>;
95
+ /**
96
+ * Immutable metadata exposed by every public SourceAxis error.
97
+ */
98
+ export type ErrorMetadata = Readonly<{
99
+ code: ErrorCode;
100
+ retryability: ErrorRetryability;
101
+ category: ErrorCategory;
102
+ severity: ErrorSeverity;
103
+ timestamp: string;
104
+ }>;
105
+ /**
106
+ * Constructor options shared by every public SourceAxis error.
107
+ */
108
+ export type SourceAxisErrorOptions = Readonly<{
109
+ cause?: unknown;
110
+ diagnostics?: ErrorDiagnostics;
111
+ retryability?: ErrorRetryability;
112
+ severity?: ErrorSeverity;
113
+ timestamp?: Date | string;
114
+ }>;
115
+ /**
116
+ * Safe serialized representation of a cause.
117
+ */
118
+ export type SerializedCause = Readonly<{
119
+ name: string;
120
+ code?: ErrorCode;
121
+ }>;
122
+ /**
123
+ * Safe serialized representation of a SourceAxis error.
124
+ */
125
+ export type SerializedSourceAxisError = Readonly<{
126
+ name: string;
127
+ message: string;
128
+ code: ErrorCode;
129
+ retryability: ErrorRetryability;
130
+ category: ErrorCategory;
131
+ severity: ErrorSeverity;
132
+ timestamp: string;
133
+ diagnostics: ErrorDiagnostics;
134
+ cause?: SerializedSourceAxisError | SerializedCause;
135
+ }>;
136
+ /**
137
+ * Base class for every public SourceAxis error.
138
+ */
139
+ export declare class SourceAxisError extends Error {
140
+ /**
141
+ * Stable public error code.
142
+ */
143
+ readonly code: ErrorCode;
144
+ /**
145
+ * Retry guidance for callers and retry middleware.
146
+ */
147
+ readonly retryability: ErrorRetryability;
148
+ /**
149
+ * Provider-neutral error category.
150
+ */
151
+ readonly category: ErrorCategory;
152
+ /**
153
+ * Diagnostic severity.
154
+ */
155
+ readonly severity: ErrorSeverity;
156
+ /**
157
+ * ISO-8601 timestamp captured when the error is created.
158
+ */
159
+ readonly timestamp: string;
160
+ /**
161
+ * Safe structured diagnostic context.
162
+ */
163
+ readonly diagnostics: ErrorDiagnostics;
164
+ /**
165
+ * Immutable error metadata.
166
+ */
167
+ readonly metadata: ErrorMetadata;
168
+ constructor(message: string, options?: SourceAxisErrorOptions);
169
+ /**
170
+ * Returns a deterministic, safe representation suitable for diagnostics and telemetry.
171
+ */
172
+ toJSON(): SerializedSourceAxisError;
173
+ /**
174
+ * Returns the canonical serialized representation.
175
+ */
176
+ serialize(): SerializedSourceAxisError;
177
+ }
178
+ /**
179
+ * Validation failure detected before an operation executes.
180
+ */
181
+ export declare class ValidationError extends SourceAxisError {
182
+ constructor(message: string, options?: SourceAxisErrorOptions);
183
+ }
184
+ /**
185
+ * Invalid or missing SourceAxis configuration.
186
+ */
187
+ export declare class ConfigurationError extends SourceAxisError {
188
+ constructor(message: string, options?: SourceAxisErrorOptions);
189
+ }
190
+ /**
191
+ * Transport-neutral execution failure.
192
+ */
193
+ export declare class TransportError extends SourceAxisError {
194
+ constructor(message: string, options?: SourceAxisErrorOptions);
195
+ }
196
+ /**
197
+ * Request execution exceeded an allowed duration.
198
+ */
199
+ export declare class TimeoutError extends TransportError {
200
+ constructor(message: string, options?: SourceAxisErrorOptions);
201
+ }
202
+ /**
203
+ * Operation was intentionally interrupted.
204
+ */
205
+ export declare class CancellationError extends TransportError {
206
+ constructor(message: string, options?: SourceAxisErrorOptions);
207
+ }
208
+ /**
209
+ * Authentication failure.
210
+ */
211
+ export declare class AuthenticationError extends SourceAxisError {
212
+ constructor(message: string, options?: SourceAxisErrorOptions);
213
+ }
214
+ /**
215
+ * Provider-neutral provider failure.
216
+ */
217
+ export declare class ProviderError extends SourceAxisError {
218
+ constructor(message: string, options?: SourceAxisErrorOptions);
219
+ }
220
+ /**
221
+ * Provider rate limit failure.
222
+ */
223
+ export declare class RateLimitError extends ProviderError {
224
+ constructor(message: string, options?: SourceAxisErrorOptions);
225
+ }
226
+ /**
227
+ * Requested provider capability is not supported.
228
+ */
229
+ export declare class CapabilityNotSupportedError extends ProviderError {
230
+ constructor(message: string, options?: SourceAxisErrorOptions);
231
+ }
232
+ /**
233
+ * Provider denied permission for the requested operation.
234
+ */
235
+ export declare class AuthorizationError extends ProviderError {
236
+ constructor(message: string, options?: SourceAxisErrorOptions);
237
+ }
238
+ /**
239
+ * Provider reported a conflict for the requested operation.
240
+ */
241
+ export declare class ConflictError extends ProviderError {
242
+ constructor(message: string, options?: SourceAxisErrorOptions);
243
+ }
244
+ /**
245
+ * Provider or repository resource was not found.
246
+ */
247
+ export declare class NotFoundError extends ProviderError {
248
+ constructor(message: string, options?: SourceAxisErrorOptions);
249
+ }
250
+ /**
251
+ * Repository lifecycle or repository state failure.
252
+ */
253
+ export declare class RepositoryError extends SourceAxisError {
254
+ constructor(message: string, options?: SourceAxisErrorOptions);
255
+ }
256
+ /**
257
+ * Internal defect or unforeseen runtime condition.
258
+ */
259
+ export declare class UnexpectedError extends SourceAxisError {
260
+ constructor(message: string, options?: SourceAxisErrorOptions);
261
+ }
262
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;CAeb,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,U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OURCEAXIS_AUTHENTICATION",
6
+ Authorization: "SOURCEAXIS_PERMISSION_DENIED",
7
+ Cancellation: "SOURCEAXIS_CANCELLED",
8
+ CapabilityNotSupported: "SOURCEAXIS_CAPABILITY_NOT_SUPPORTED",
9
+ Configuration: "SOURCEAXIS_CONFIGURATION",
10
+ Conflict: "SOURCEAXIS_CONFLICT",
11
+ NotFound: "SOURCEAXIS_NOT_FOUND",
12
+ Provider: "SOURCEAXIS_PROVIDER",
13
+ RateLimit: "SOURCEAXIS_RATE_LIMITED",
14
+ Repository: "SOURCEAXIS_REPOSITORY",
15
+ Timeout: "SOURCEAXIS_TIMEOUT",
16
+ Transport: "SOURCEAXIS_TRANSPORT",
17
+ Unexpected: "SOURCEAXIS_UNEXPECTED",
18
+ Validation: "SOURCEAXIS_VALIDATION"
19
+ };
20
+ const definitions = {
21
+ AuthenticationError: {
22
+ category: "authentication",
23
+ code: ErrorCodes.Authentication,
24
+ retryability: "Never",
25
+ severity: "error"
26
+ },
27
+ CancellationError: {
28
+ category: "transport",
29
+ code: ErrorCodes.Cancellation,
30
+ retryability: "Never",
31
+ severity: "info"
32
+ },
33
+ CapabilityNotSupportedError: {
34
+ category: "provider",
35
+ code: ErrorCodes.CapabilityNotSupported,
36
+ retryability: "Never",
37
+ severity: "warning"
38
+ },
39
+ ConfigurationError: {
40
+ category: "configuration",
41
+ code: ErrorCodes.Configuration,
42
+ retryability: "Never",
43
+ severity: "error"
44
+ },
45
+ ConflictError: {
46
+ category: "provider",
47
+ code: ErrorCodes.Conflict,
48
+ retryability: "Maybe",
49
+ severity: "warning"
50
+ },
51
+ SourceAxisError: {
52
+ category: "unexpected",
53
+ code: ErrorCodes.Unexpected,
54
+ retryability: "Never",
55
+ severity: "error"
56
+ },
57
+ NotFoundError: {
58
+ category: "provider",
59
+ code: ErrorCodes.NotFound,
60
+ retryability: "Never",
61
+ severity: "warning"
62
+ },
63
+ AuthorizationError: {
64
+ category: "provider",
65
+ code: ErrorCodes.Authorization,
66
+ retryability: "Never",
67
+ severity: "error"
68
+ },
69
+ ProviderError: {
70
+ category: "provider",
71
+ code: ErrorCodes.Provider,
72
+ retryability: "Maybe",
73
+ severity: "error"
74
+ },
75
+ RateLimitError: {
76
+ category: "provider",
77
+ code: ErrorCodes.RateLimit,
78
+ retryability: "Always",
79
+ severity: "warning"
80
+ },
81
+ RepositoryError: {
82
+ category: "repository",
83
+ code: ErrorCodes.Repository,
84
+ retryability: "Maybe",
85
+ severity: "error"
86
+ },
87
+ TimeoutError: {
88
+ category: "transport",
89
+ code: ErrorCodes.Timeout,
90
+ retryability: "Maybe",
91
+ severity: "warning"
92
+ },
93
+ TransportError: {
94
+ category: "transport",
95
+ code: ErrorCodes.Transport,
96
+ retryability: "Maybe",
97
+ severity: "error"
98
+ },
99
+ UnexpectedError: {
100
+ category: "unexpected",
101
+ code: ErrorCodes.Unexpected,
102
+ retryability: "Never",
103
+ severity: "critical"
104
+ },
105
+ ValidationError: {
106
+ category: "validation",
107
+ code: ErrorCodes.Validation,
108
+ retryability: "Never",
109
+ severity: "warning"
110
+ }
111
+ };
112
+ /**
113
+ * Base class for every public SourceAxis error.
114
+ */
115
+ export class SourceAxisError extends Error {
116
+ /**
117
+ * Stable public error code.
118
+ */
119
+ code;
120
+ /**
121
+ * Retry guidance for callers and retry middleware.
122
+ */
123
+ retryability;
124
+ /**
125
+ * Provider-neutral error category.
126
+ */
127
+ category;
128
+ /**
129
+ * Diagnostic severity.
130
+ */
131
+ severity;
132
+ /**
133
+ * ISO-8601 timestamp captured when the error is created.
134
+ */
135
+ timestamp;
136
+ /**
137
+ * Safe structured diagnostic context.
138
+ */
139
+ diagnostics;
140
+ /**
141
+ * Immutable error metadata.
142
+ */
143
+ metadata;
144
+ constructor(message, options = {}) {
145
+ const definition = getDefinition(new.target.name);
146
+ super(message, createErrorOptions(options.cause));
147
+ Object.setPrototypeOf(this, new.target.prototype);
148
+ this.name = new.target.name;
149
+ this.code = definition.code;
150
+ this.retryability = options.retryability ?? definition.retryability;
151
+ this.category = definition.category;
152
+ this.severity = options.severity ?? definition.severity;
153
+ this.timestamp = normalizeTimestamp(options.timestamp);
154
+ this.diagnostics = freezeDiagnostics(options.diagnostics);
155
+ this.metadata = deepFreeze({
156
+ category: this.category,
157
+ code: this.code,
158
+ retryability: this.retryability,
159
+ severity: this.severity,
160
+ timestamp: this.timestamp
161
+ });
162
+ if (Error.captureStackTrace !== undefined) {
163
+ Error.captureStackTrace(this, new.target);
164
+ }
165
+ Object.freeze(this);
166
+ }
167
+ /**
168
+ * Returns a deterministic, safe representation suitable for diagnostics and telemetry.
169
+ */
170
+ toJSON() {
171
+ const serialized = {
172
+ category: this.category,
173
+ code: this.code,
174
+ diagnostics: this.diagnostics,
175
+ message: this.message,
176
+ name: this.name,
177
+ retryability: this.retryability,
178
+ severity: this.severity,
179
+ timestamp: this.timestamp
180
+ };
181
+ const cause = serializeCause(this.cause);
182
+ if (cause !== undefined) {
183
+ serialized.cause = cause;
184
+ }
185
+ return deepFreeze(serialized);
186
+ }
187
+ /**
188
+ * Returns the canonical serialized representation.
189
+ */
190
+ serialize() {
191
+ return this.toJSON();
192
+ }
193
+ }
194
+ /**
195
+ * Validation failure detected before an operation executes.
196
+ */
197
+ export class ValidationError extends SourceAxisError {
198
+ constructor(message, options = {}) {
199
+ super(message, options);
200
+ }
201
+ }
202
+ /**
203
+ * Invalid or missing SourceAxis configuration.
204
+ */
205
+ export class ConfigurationError extends SourceAxisError {
206
+ constructor(message, options = {}) {
207
+ super(message, options);
208
+ }
209
+ }
210
+ /**
211
+ * Transport-neutral execution failure.
212
+ */
213
+ export class TransportError extends SourceAxisError {
214
+ constructor(message, options = {}) {
215
+ super(message, options);
216
+ }
217
+ }
218
+ /**
219
+ * Request execution exceeded an allowed duration.
220
+ */
221
+ export class TimeoutError extends TransportError {
222
+ constructor(message, options = {}) {
223
+ super(message, options);
224
+ }
225
+ }
226
+ /**
227
+ * Operation was intentionally interrupted.
228
+ */
229
+ export class CancellationError extends TransportError {
230
+ constructor(message, options = {}) {
231
+ super(message, options);
232
+ }
233
+ }
234
+ /**
235
+ * Authentication failure.
236
+ */
237
+ export class AuthenticationError extends SourceAxisError {
238
+ constructor(message, options = {}) {
239
+ super(message, options);
240
+ }
241
+ }
242
+ /**
243
+ * Provider-neutral provider failure.
244
+ */
245
+ export class ProviderError extends SourceAxisError {
246
+ constructor(message, options = {}) {
247
+ super(message, options);
248
+ }
249
+ }
250
+ /**
251
+ * Provider rate limit failure.
252
+ */
253
+ export class RateLimitError extends ProviderError {
254
+ constructor(message, options = {}) {
255
+ super(message, options);
256
+ }
257
+ }
258
+ /**
259
+ * Requested provider capability is not supported.
260
+ */
261
+ export class CapabilityNotSupportedError extends ProviderError {
262
+ constructor(message, options = {}) {
263
+ super(message, options);
264
+ }
265
+ }
266
+ /**
267
+ * Provider denied permission for the requested operation.
268
+ */
269
+ export class AuthorizationError extends ProviderError {
270
+ constructor(message, options = {}) {
271
+ super(message, options);
272
+ }
273
+ }
274
+ /**
275
+ * Provider reported a conflict for the requested operation.
276
+ */
277
+ export class ConflictError extends ProviderError {
278
+ constructor(message, options = {}) {
279
+ super(message, options);
280
+ }
281
+ }
282
+ /**
283
+ * Provider or repository resource was not found.
284
+ */
285
+ export class NotFoundError extends ProviderError {
286
+ constructor(message, options = {}) {
287
+ super(message, options);
288
+ }
289
+ }
290
+ /**
291
+ * Repository lifecycle or repository state failure.
292
+ */
293
+ export class RepositoryError extends SourceAxisError {
294
+ constructor(message, options = {}) {
295
+ super(message, options);
296
+ }
297
+ }
298
+ /**
299
+ * Internal defect or unforeseen runtime condition.
300
+ */
301
+ export class UnexpectedError extends SourceAxisError {
302
+ constructor(message, options = {}) {
303
+ super(message, options);
304
+ }
305
+ }
306
+ function getDefinition(name) {
307
+ return definitions[name] ?? definitions.SourceAxisError;
308
+ }
309
+ function createErrorOptions(cause) {
310
+ return cause === undefined ? undefined : { cause };
311
+ }
312
+ function normalizeTimestamp(timestamp) {
313
+ if (timestamp instanceof Date) {
314
+ return timestamp.toISOString();
315
+ }
316
+ return timestamp ?? new Date().toISOString();
317
+ }
318
+ function freezeDiagnostics(diagnostics) {
319
+ return deepFreeze(diagnostics ?? {});
320
+ }
321
+ function serializeCause(cause) {
322
+ if (cause instanceof SourceAxisError) {
323
+ return cause.toJSON();
324
+ }
325
+ if (cause instanceof Error) {
326
+ return deepFreeze({ name: cause.name });
327
+ }
328
+ if (cause === undefined) {
329
+ return undefined;
330
+ }
331
+ return deepFreeze({ name: typeof cause });
332
+ }
333
+ function deepFreeze(value) {
334
+ if (value === null || (typeof value !== "object" && typeof value !== "function")) {
335
+ return value;
336
+ }
337
+ for (const key of Reflect.ownKeys(value)) {
338
+ const child = value[key];
339
+ if (child !== null && (typeof child === "object" || typeof child === "function")) {
340
+ deepFreeze(child);
341
+ }
342
+ }
343
+ return Object.freeze(value);
344
+ }
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@sourceaxis/errors",
3
+ "version": "0.1.0",
4
+ "description": "Canonical SourceAxis public error hierarchy and serialization model.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "files": [
9
+ "dist",
10
+ "README.md"
11
+ ],
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/esm/index.d.ts",
15
+ "import": "./dist/esm/index.js",
16
+ "require": "./dist/cjs/index.js",
17
+ "default": "./dist/esm/index.js"
18
+ }
19
+ },
20
+ "types": "./dist/esm/index.d.ts",
21
+ "scripts": {
22
+ "build": "tsc -p tsconfig.esm.json && node ../../scripts/build/build-cjs.mjs .",
23
+ "test": "vitest run --config vitest.config.mjs",
24
+ "typecheck": "tsc -p tsconfig.json --noEmit"
25
+ },
26
+ "main": "./dist/cjs/index.js",
27
+ "module": "./dist/esm/index.js",
28
+ "engines": {
29
+ "node": ">=20.19.0"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/mriduldey/source-axis.git",
34
+ "directory": "packages/errors"
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/mriduldey/source-axis/issues"
38
+ },
39
+ "homepage": "https://github.com/mriduldey/source-axis#readme",
40
+ "keywords": [
41
+ "git",
42
+ "github",
43
+ "sdk",
44
+ "typescript",
45
+ "provider-neutral"
46
+ ],
47
+ "publishConfig": {
48
+ "access": "public",
49
+ "provenance": true
50
+ }
51
+ }