@sonatel-os/openapi-runtime 0.1.1 → 0.2.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 +458 -170
- package/dist/errors.cjs +154 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.esm.js +154 -0
- package/dist/errors.esm.js.map +1 -0
- package/dist/index.cjs +557 -5453
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -74
- package/dist/index.esm.js +560 -5455
- package/dist/index.esm.js.map +1 -1
- package/dist/react/index.cjs +129 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.esm.js +129 -0
- package/dist/react/index.esm.js.map +1 -0
- package/dist/src/auth/config.d.ts +170 -0
- package/dist/src/auth/index.d.ts +3 -0
- package/dist/src/auth/manager.d.ts +51 -0
- package/dist/src/auth/providers.d.ts +178 -0
- package/dist/src/constants.d.ts +30 -0
- package/dist/src/core/client.d.ts +83 -0
- package/dist/src/core/registry.d.ts +116 -0
- package/dist/src/errors.d.ts +126 -0
- package/dist/src/index.d.ts +230 -0
- package/dist/src/mocking/index.d.ts +1 -0
- package/dist/src/mocking/sampler.d.ts +87 -0
- package/dist/src/react/useOpenAPI.d.ts +127 -3
- package/dist/src/utils.d.ts +103 -0
- package/dist/src/validation/index.d.ts +1 -0
- package/dist/src/validation/validator.d.ts +117 -0
- package/package.json +25 -8
- package/dist/src/auth.d.ts +0 -33
- package/dist/src/client.d.ts +0 -20
- package/dist/src/config.d.ts +0 -10
- package/dist/src/http.d.ts +0 -0
- package/dist/src/registry.d.ts +0 -28
- package/dist/src/sampler.d.ts +0 -2
- package/dist/src/validate.d.ts +0 -17
package/dist/errors.cjs
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
class OpenAPIRuntimeError extends Error {
|
|
4
|
+
/**
|
|
5
|
+
* @param {string} message - Error message
|
|
6
|
+
* @param {string} code - Error code for programmatic handling
|
|
7
|
+
* @param {object} [details] - Additional error context
|
|
8
|
+
*/
|
|
9
|
+
constructor(message, code, details = {}) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "OpenAPIRuntimeError";
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.details = details;
|
|
14
|
+
Error.captureStackTrace?.(this, this.constructor);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Convert error to JSON for logging/serialization.
|
|
18
|
+
* @returns {{ name: string, code: string, message: string, details: object }}
|
|
19
|
+
*/
|
|
20
|
+
toJSON() {
|
|
21
|
+
return {
|
|
22
|
+
name: this.name,
|
|
23
|
+
code: this.code,
|
|
24
|
+
message: this.message,
|
|
25
|
+
details: this.details
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
class SpecNotFoundError extends OpenAPIRuntimeError {
|
|
30
|
+
/**
|
|
31
|
+
* @param {string} specName - Name of the spec that wasn't found
|
|
32
|
+
*/
|
|
33
|
+
constructor(specName) {
|
|
34
|
+
super(
|
|
35
|
+
`Spec not registered: "${specName}"`,
|
|
36
|
+
"SPEC_NOT_FOUND",
|
|
37
|
+
{ specName }
|
|
38
|
+
);
|
|
39
|
+
this.name = "SpecNotFoundError";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
class OperationNotFoundError extends OpenAPIRuntimeError {
|
|
43
|
+
/**
|
|
44
|
+
* @param {string} operationId - The operation ID that wasn't found
|
|
45
|
+
* @param {string} [specName] - Optional spec name for context
|
|
46
|
+
*/
|
|
47
|
+
constructor(operationId, specName) {
|
|
48
|
+
super(
|
|
49
|
+
`Operation not found: "${operationId}"${specName ? ` in spec "${specName}"` : ""}`,
|
|
50
|
+
"OPERATION_NOT_FOUND",
|
|
51
|
+
{ operationId, specName }
|
|
52
|
+
);
|
|
53
|
+
this.name = "OperationNotFoundError";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
class AuthenticationError extends OpenAPIRuntimeError {
|
|
57
|
+
/**
|
|
58
|
+
* @param {string} message - Error description
|
|
59
|
+
* @param {Array<{ scheme: string, error: string }>} [failures] - List of auth failures
|
|
60
|
+
*/
|
|
61
|
+
constructor(message, failures = []) {
|
|
62
|
+
super(
|
|
63
|
+
message,
|
|
64
|
+
"AUTHENTICATION_FAILED",
|
|
65
|
+
{ failures }
|
|
66
|
+
);
|
|
67
|
+
this.name = "AuthenticationError";
|
|
68
|
+
this.failures = failures;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
class SecurityError extends OpenAPIRuntimeError {
|
|
72
|
+
/**
|
|
73
|
+
* @param {string} message - Security violation description
|
|
74
|
+
* @param {string} [violation] - Type of security violation
|
|
75
|
+
*/
|
|
76
|
+
constructor(message, violation) {
|
|
77
|
+
super(
|
|
78
|
+
message,
|
|
79
|
+
"SECURITY_VIOLATION",
|
|
80
|
+
{ violation }
|
|
81
|
+
);
|
|
82
|
+
this.name = "SecurityError";
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
class ValidationError extends OpenAPIRuntimeError {
|
|
86
|
+
/**
|
|
87
|
+
* @param {string} message - Validation error description
|
|
88
|
+
* @param {Array<object>} errors - AJV validation errors
|
|
89
|
+
* @param {'request' | 'response'} type - Whether request or response failed
|
|
90
|
+
*/
|
|
91
|
+
constructor(message, errors = [], type = "response") {
|
|
92
|
+
super(
|
|
93
|
+
message,
|
|
94
|
+
"VALIDATION_FAILED",
|
|
95
|
+
{ errors, type }
|
|
96
|
+
);
|
|
97
|
+
this.name = "ValidationError";
|
|
98
|
+
this.errors = errors;
|
|
99
|
+
this.validationType = type;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
class SpecLoadError extends OpenAPIRuntimeError {
|
|
103
|
+
/**
|
|
104
|
+
* @param {string} specName - Name/path of the spec that failed to load
|
|
105
|
+
* @param {string} reason - Why loading failed
|
|
106
|
+
*/
|
|
107
|
+
constructor(specName, reason) {
|
|
108
|
+
super(
|
|
109
|
+
`Failed to load spec "${specName}": ${reason}`,
|
|
110
|
+
"SPEC_LOAD_FAILED",
|
|
111
|
+
{ specName, reason }
|
|
112
|
+
);
|
|
113
|
+
this.name = "SpecLoadError";
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
class ConfigurationError extends OpenAPIRuntimeError {
|
|
117
|
+
/**
|
|
118
|
+
* @param {string} message - What's wrong with the configuration
|
|
119
|
+
* @param {string} [configKey] - Which config key is problematic
|
|
120
|
+
*/
|
|
121
|
+
constructor(message, configKey) {
|
|
122
|
+
super(
|
|
123
|
+
message,
|
|
124
|
+
"CONFIGURATION_INVALID",
|
|
125
|
+
{ configKey }
|
|
126
|
+
);
|
|
127
|
+
this.name = "ConfigurationError";
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
class InvalidInputError extends OpenAPIRuntimeError {
|
|
131
|
+
/**
|
|
132
|
+
* @param {string} message - What input is invalid
|
|
133
|
+
* @param {string} [field] - Which field is invalid
|
|
134
|
+
* @param {*} [value] - The invalid value (sanitized)
|
|
135
|
+
*/
|
|
136
|
+
constructor(message, field, value) {
|
|
137
|
+
super(
|
|
138
|
+
message,
|
|
139
|
+
"INVALID_INPUT",
|
|
140
|
+
{ field, value: typeof value === "string" ? value.slice(0, 100) : typeof value }
|
|
141
|
+
);
|
|
142
|
+
this.name = "InvalidInputError";
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.AuthenticationError = AuthenticationError;
|
|
146
|
+
exports.ConfigurationError = ConfigurationError;
|
|
147
|
+
exports.InvalidInputError = InvalidInputError;
|
|
148
|
+
exports.OpenAPIRuntimeError = OpenAPIRuntimeError;
|
|
149
|
+
exports.OperationNotFoundError = OperationNotFoundError;
|
|
150
|
+
exports.SecurityError = SecurityError;
|
|
151
|
+
exports.SpecLoadError = SpecLoadError;
|
|
152
|
+
exports.SpecNotFoundError = SpecNotFoundError;
|
|
153
|
+
exports.ValidationError = ValidationError;
|
|
154
|
+
//# sourceMappingURL=errors.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.cjs","sources":["../src/errors.js"],"sourcesContent":["/**\n * @module errors\n * @description Custom error types for precise error handling and debugging.\n */\n\n/**\n * Base error class for all OpenAPI Runtime errors.\n * @extends Error\n */\nexport class OpenAPIRuntimeError extends Error {\n /**\n * @param {string} message - Error message\n * @param {string} code - Error code for programmatic handling\n * @param {object} [details] - Additional error context\n */\n constructor(message, code, details = {}) {\n super(message)\n this.name = 'OpenAPIRuntimeError'\n this.code = code\n this.details = details\n Error.captureStackTrace?.(this, this.constructor)\n }\n\n /**\n * Convert error to JSON for logging/serialization.\n * @returns {{ name: string, code: string, message: string, details: object }}\n */\n toJSON() {\n return {\n name: this.name,\n code: this.code,\n message: this.message,\n details: this.details\n }\n }\n}\n\n/**\n * Thrown when a requested spec is not found in the registry.\n * @extends OpenAPIRuntimeError\n */\nexport class SpecNotFoundError extends OpenAPIRuntimeError {\n /**\n * @param {string} specName - Name of the spec that wasn't found\n */\n constructor(specName) {\n super(\n `Spec not registered: \"${specName}\"`,\n 'SPEC_NOT_FOUND',\n { specName }\n )\n this.name = 'SpecNotFoundError'\n }\n}\n\n/**\n * Thrown when a requested operation is not found in a spec.\n * @extends OpenAPIRuntimeError\n */\nexport class OperationNotFoundError extends OpenAPIRuntimeError {\n /**\n * @param {string} operationId - The operation ID that wasn't found\n * @param {string} [specName] - Optional spec name for context\n */\n constructor(operationId, specName) {\n super(\n `Operation not found: \"${operationId}\"${specName ? ` in spec \"${specName}\"` : ''}`,\n 'OPERATION_NOT_FOUND',\n { operationId, specName }\n )\n this.name = 'OperationNotFoundError'\n }\n}\n\n/**\n * Thrown when authentication fails or is misconfigured.\n * @extends OpenAPIRuntimeError\n */\nexport class AuthenticationError extends OpenAPIRuntimeError {\n /**\n * @param {string} message - Error description\n * @param {Array<{ scheme: string, error: string }>} [failures] - List of auth failures\n */\n constructor(message, failures = []) {\n super(\n message,\n 'AUTHENTICATION_FAILED',\n { failures }\n )\n this.name = 'AuthenticationError'\n this.failures = failures\n }\n}\n\n/**\n * Thrown when security requirements are violated.\n * @extends OpenAPIRuntimeError\n */\nexport class SecurityError extends OpenAPIRuntimeError {\n /**\n * @param {string} message - Security violation description\n * @param {string} [violation] - Type of security violation\n */\n constructor(message, violation) {\n super(\n message,\n 'SECURITY_VIOLATION',\n { violation }\n )\n this.name = 'SecurityError'\n }\n}\n\n/**\n * Thrown when validation fails (request or response).\n * @extends OpenAPIRuntimeError\n */\nexport class ValidationError extends OpenAPIRuntimeError {\n /**\n * @param {string} message - Validation error description\n * @param {Array<object>} errors - AJV validation errors\n * @param {'request' | 'response'} type - Whether request or response failed\n */\n constructor(message, errors = [], type = 'response') {\n super(\n message,\n 'VALIDATION_FAILED',\n { errors, type }\n )\n this.name = 'ValidationError'\n this.errors = errors\n this.validationType = type\n }\n}\n\n/**\n * Thrown when spec loading or parsing fails.\n * @extends OpenAPIRuntimeError\n */\nexport class SpecLoadError extends OpenAPIRuntimeError {\n /**\n * @param {string} specName - Name/path of the spec that failed to load\n * @param {string} reason - Why loading failed\n */\n constructor(specName, reason) {\n super(\n `Failed to load spec \"${specName}\": ${reason}`,\n 'SPEC_LOAD_FAILED',\n { specName, reason }\n )\n this.name = 'SpecLoadError'\n }\n}\n\n/**\n * Thrown when configuration is invalid.\n * @extends OpenAPIRuntimeError\n */\nexport class ConfigurationError extends OpenAPIRuntimeError {\n /**\n * @param {string} message - What's wrong with the configuration\n * @param {string} [configKey] - Which config key is problematic\n */\n constructor(message, configKey) {\n super(\n message,\n 'CONFIGURATION_INVALID',\n { configKey }\n )\n this.name = 'ConfigurationError'\n }\n}\n\n/**\n * Thrown when input parameters are invalid.\n * @extends OpenAPIRuntimeError\n */\nexport class InvalidInputError extends OpenAPIRuntimeError {\n /**\n * @param {string} message - What input is invalid\n * @param {string} [field] - Which field is invalid\n * @param {*} [value] - The invalid value (sanitized)\n */\n constructor(message, field, value) {\n super(\n message,\n 'INVALID_INPUT',\n { field, value: typeof value === 'string' ? value.slice(0, 100) : typeof value }\n )\n this.name = 'InvalidInputError'\n }\n}\n"],"names":[],"mappings":";;AASO,MAAM,4BAA4B,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM7C,YAAY,SAAS,MAAM,UAAU,CAAA,GAAI;AACvC,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,UAAU;AACf,UAAM,oBAAoB,MAAM,KAAK,WAAW;AAAA,EAClD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAS;AACP,WAAO;AAAA,MACL,MAAM,KAAK;AAAA,MACX,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,SAAS,KAAK;AAAA,IACpB;AAAA,EACE;AACF;AAMO,MAAM,0BAA0B,oBAAoB;AAAA;AAAA;AAAA;AAAA,EAIzD,YAAY,UAAU;AACpB;AAAA,MACE,yBAAyB,QAAQ;AAAA,MACjC;AAAA,MACA,EAAE,SAAQ;AAAA,IAChB;AACI,SAAK,OAAO;AAAA,EACd;AACF;AAMO,MAAM,+BAA+B,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA,EAK9D,YAAY,aAAa,UAAU;AACjC;AAAA,MACE,yBAAyB,WAAW,IAAI,WAAW,aAAa,QAAQ,MAAM,EAAE;AAAA,MAChF;AAAA,MACA,EAAE,aAAa,SAAQ;AAAA,IAC7B;AACI,SAAK,OAAO;AAAA,EACd;AACF;AAMO,MAAM,4BAA4B,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA,EAK3D,YAAY,SAAS,WAAW,IAAI;AAClC;AAAA,MACE;AAAA,MACA;AAAA,MACA,EAAE,SAAQ;AAAA,IAChB;AACI,SAAK,OAAO;AACZ,SAAK,WAAW;AAAA,EAClB;AACF;AAMO,MAAM,sBAAsB,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA,EAKrD,YAAY,SAAS,WAAW;AAC9B;AAAA,MACE;AAAA,MACA;AAAA,MACA,EAAE,UAAS;AAAA,IACjB;AACI,SAAK,OAAO;AAAA,EACd;AACF;AAMO,MAAM,wBAAwB,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMvD,YAAY,SAAS,SAAS,CAAA,GAAI,OAAO,YAAY;AACnD;AAAA,MACE;AAAA,MACA;AAAA,MACA,EAAE,QAAQ,KAAI;AAAA,IACpB;AACI,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,iBAAiB;AAAA,EACxB;AACF;AAMO,MAAM,sBAAsB,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA,EAKrD,YAAY,UAAU,QAAQ;AAC5B;AAAA,MACE,wBAAwB,QAAQ,MAAM,MAAM;AAAA,MAC5C;AAAA,MACA,EAAE,UAAU,OAAM;AAAA,IACxB;AACI,SAAK,OAAO;AAAA,EACd;AACF;AAMO,MAAM,2BAA2B,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA,EAK1D,YAAY,SAAS,WAAW;AAC9B;AAAA,MACE;AAAA,MACA;AAAA,MACA,EAAE,UAAS;AAAA,IACjB;AACI,SAAK,OAAO;AAAA,EACd;AACF;AAMO,MAAM,0BAA0B,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMzD,YAAY,SAAS,OAAO,OAAO;AACjC;AAAA,MACE;AAAA,MACA;AAAA,MACA,EAAE,OAAO,OAAO,OAAO,UAAU,WAAW,MAAM,MAAM,GAAG,GAAG,IAAI,OAAO,MAAK;AAAA,IACpF;AACI,SAAK,OAAO;AAAA,EACd;AACF;;;;;;;;;;"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
class OpenAPIRuntimeError extends Error {
|
|
2
|
+
/**
|
|
3
|
+
* @param {string} message - Error message
|
|
4
|
+
* @param {string} code - Error code for programmatic handling
|
|
5
|
+
* @param {object} [details] - Additional error context
|
|
6
|
+
*/
|
|
7
|
+
constructor(message, code, details = {}) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "OpenAPIRuntimeError";
|
|
10
|
+
this.code = code;
|
|
11
|
+
this.details = details;
|
|
12
|
+
Error.captureStackTrace?.(this, this.constructor);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Convert error to JSON for logging/serialization.
|
|
16
|
+
* @returns {{ name: string, code: string, message: string, details: object }}
|
|
17
|
+
*/
|
|
18
|
+
toJSON() {
|
|
19
|
+
return {
|
|
20
|
+
name: this.name,
|
|
21
|
+
code: this.code,
|
|
22
|
+
message: this.message,
|
|
23
|
+
details: this.details
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
class SpecNotFoundError extends OpenAPIRuntimeError {
|
|
28
|
+
/**
|
|
29
|
+
* @param {string} specName - Name of the spec that wasn't found
|
|
30
|
+
*/
|
|
31
|
+
constructor(specName) {
|
|
32
|
+
super(
|
|
33
|
+
`Spec not registered: "${specName}"`,
|
|
34
|
+
"SPEC_NOT_FOUND",
|
|
35
|
+
{ specName }
|
|
36
|
+
);
|
|
37
|
+
this.name = "SpecNotFoundError";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
class OperationNotFoundError extends OpenAPIRuntimeError {
|
|
41
|
+
/**
|
|
42
|
+
* @param {string} operationId - The operation ID that wasn't found
|
|
43
|
+
* @param {string} [specName] - Optional spec name for context
|
|
44
|
+
*/
|
|
45
|
+
constructor(operationId, specName) {
|
|
46
|
+
super(
|
|
47
|
+
`Operation not found: "${operationId}"${specName ? ` in spec "${specName}"` : ""}`,
|
|
48
|
+
"OPERATION_NOT_FOUND",
|
|
49
|
+
{ operationId, specName }
|
|
50
|
+
);
|
|
51
|
+
this.name = "OperationNotFoundError";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
class AuthenticationError extends OpenAPIRuntimeError {
|
|
55
|
+
/**
|
|
56
|
+
* @param {string} message - Error description
|
|
57
|
+
* @param {Array<{ scheme: string, error: string }>} [failures] - List of auth failures
|
|
58
|
+
*/
|
|
59
|
+
constructor(message, failures = []) {
|
|
60
|
+
super(
|
|
61
|
+
message,
|
|
62
|
+
"AUTHENTICATION_FAILED",
|
|
63
|
+
{ failures }
|
|
64
|
+
);
|
|
65
|
+
this.name = "AuthenticationError";
|
|
66
|
+
this.failures = failures;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
class SecurityError extends OpenAPIRuntimeError {
|
|
70
|
+
/**
|
|
71
|
+
* @param {string} message - Security violation description
|
|
72
|
+
* @param {string} [violation] - Type of security violation
|
|
73
|
+
*/
|
|
74
|
+
constructor(message, violation) {
|
|
75
|
+
super(
|
|
76
|
+
message,
|
|
77
|
+
"SECURITY_VIOLATION",
|
|
78
|
+
{ violation }
|
|
79
|
+
);
|
|
80
|
+
this.name = "SecurityError";
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
class ValidationError extends OpenAPIRuntimeError {
|
|
84
|
+
/**
|
|
85
|
+
* @param {string} message - Validation error description
|
|
86
|
+
* @param {Array<object>} errors - AJV validation errors
|
|
87
|
+
* @param {'request' | 'response'} type - Whether request or response failed
|
|
88
|
+
*/
|
|
89
|
+
constructor(message, errors = [], type = "response") {
|
|
90
|
+
super(
|
|
91
|
+
message,
|
|
92
|
+
"VALIDATION_FAILED",
|
|
93
|
+
{ errors, type }
|
|
94
|
+
);
|
|
95
|
+
this.name = "ValidationError";
|
|
96
|
+
this.errors = errors;
|
|
97
|
+
this.validationType = type;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
class SpecLoadError extends OpenAPIRuntimeError {
|
|
101
|
+
/**
|
|
102
|
+
* @param {string} specName - Name/path of the spec that failed to load
|
|
103
|
+
* @param {string} reason - Why loading failed
|
|
104
|
+
*/
|
|
105
|
+
constructor(specName, reason) {
|
|
106
|
+
super(
|
|
107
|
+
`Failed to load spec "${specName}": ${reason}`,
|
|
108
|
+
"SPEC_LOAD_FAILED",
|
|
109
|
+
{ specName, reason }
|
|
110
|
+
);
|
|
111
|
+
this.name = "SpecLoadError";
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
class ConfigurationError extends OpenAPIRuntimeError {
|
|
115
|
+
/**
|
|
116
|
+
* @param {string} message - What's wrong with the configuration
|
|
117
|
+
* @param {string} [configKey] - Which config key is problematic
|
|
118
|
+
*/
|
|
119
|
+
constructor(message, configKey) {
|
|
120
|
+
super(
|
|
121
|
+
message,
|
|
122
|
+
"CONFIGURATION_INVALID",
|
|
123
|
+
{ configKey }
|
|
124
|
+
);
|
|
125
|
+
this.name = "ConfigurationError";
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
class InvalidInputError extends OpenAPIRuntimeError {
|
|
129
|
+
/**
|
|
130
|
+
* @param {string} message - What input is invalid
|
|
131
|
+
* @param {string} [field] - Which field is invalid
|
|
132
|
+
* @param {*} [value] - The invalid value (sanitized)
|
|
133
|
+
*/
|
|
134
|
+
constructor(message, field, value) {
|
|
135
|
+
super(
|
|
136
|
+
message,
|
|
137
|
+
"INVALID_INPUT",
|
|
138
|
+
{ field, value: typeof value === "string" ? value.slice(0, 100) : typeof value }
|
|
139
|
+
);
|
|
140
|
+
this.name = "InvalidInputError";
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
export {
|
|
144
|
+
AuthenticationError,
|
|
145
|
+
ConfigurationError,
|
|
146
|
+
InvalidInputError,
|
|
147
|
+
OpenAPIRuntimeError,
|
|
148
|
+
OperationNotFoundError,
|
|
149
|
+
SecurityError,
|
|
150
|
+
SpecLoadError,
|
|
151
|
+
SpecNotFoundError,
|
|
152
|
+
ValidationError
|
|
153
|
+
};
|
|
154
|
+
//# sourceMappingURL=errors.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.esm.js","sources":["../src/errors.js"],"sourcesContent":["/**\n * @module errors\n * @description Custom error types for precise error handling and debugging.\n */\n\n/**\n * Base error class for all OpenAPI Runtime errors.\n * @extends Error\n */\nexport class OpenAPIRuntimeError extends Error {\n /**\n * @param {string} message - Error message\n * @param {string} code - Error code for programmatic handling\n * @param {object} [details] - Additional error context\n */\n constructor(message, code, details = {}) {\n super(message)\n this.name = 'OpenAPIRuntimeError'\n this.code = code\n this.details = details\n Error.captureStackTrace?.(this, this.constructor)\n }\n\n /**\n * Convert error to JSON for logging/serialization.\n * @returns {{ name: string, code: string, message: string, details: object }}\n */\n toJSON() {\n return {\n name: this.name,\n code: this.code,\n message: this.message,\n details: this.details\n }\n }\n}\n\n/**\n * Thrown when a requested spec is not found in the registry.\n * @extends OpenAPIRuntimeError\n */\nexport class SpecNotFoundError extends OpenAPIRuntimeError {\n /**\n * @param {string} specName - Name of the spec that wasn't found\n */\n constructor(specName) {\n super(\n `Spec not registered: \"${specName}\"`,\n 'SPEC_NOT_FOUND',\n { specName }\n )\n this.name = 'SpecNotFoundError'\n }\n}\n\n/**\n * Thrown when a requested operation is not found in a spec.\n * @extends OpenAPIRuntimeError\n */\nexport class OperationNotFoundError extends OpenAPIRuntimeError {\n /**\n * @param {string} operationId - The operation ID that wasn't found\n * @param {string} [specName] - Optional spec name for context\n */\n constructor(operationId, specName) {\n super(\n `Operation not found: \"${operationId}\"${specName ? ` in spec \"${specName}\"` : ''}`,\n 'OPERATION_NOT_FOUND',\n { operationId, specName }\n )\n this.name = 'OperationNotFoundError'\n }\n}\n\n/**\n * Thrown when authentication fails or is misconfigured.\n * @extends OpenAPIRuntimeError\n */\nexport class AuthenticationError extends OpenAPIRuntimeError {\n /**\n * @param {string} message - Error description\n * @param {Array<{ scheme: string, error: string }>} [failures] - List of auth failures\n */\n constructor(message, failures = []) {\n super(\n message,\n 'AUTHENTICATION_FAILED',\n { failures }\n )\n this.name = 'AuthenticationError'\n this.failures = failures\n }\n}\n\n/**\n * Thrown when security requirements are violated.\n * @extends OpenAPIRuntimeError\n */\nexport class SecurityError extends OpenAPIRuntimeError {\n /**\n * @param {string} message - Security violation description\n * @param {string} [violation] - Type of security violation\n */\n constructor(message, violation) {\n super(\n message,\n 'SECURITY_VIOLATION',\n { violation }\n )\n this.name = 'SecurityError'\n }\n}\n\n/**\n * Thrown when validation fails (request or response).\n * @extends OpenAPIRuntimeError\n */\nexport class ValidationError extends OpenAPIRuntimeError {\n /**\n * @param {string} message - Validation error description\n * @param {Array<object>} errors - AJV validation errors\n * @param {'request' | 'response'} type - Whether request or response failed\n */\n constructor(message, errors = [], type = 'response') {\n super(\n message,\n 'VALIDATION_FAILED',\n { errors, type }\n )\n this.name = 'ValidationError'\n this.errors = errors\n this.validationType = type\n }\n}\n\n/**\n * Thrown when spec loading or parsing fails.\n * @extends OpenAPIRuntimeError\n */\nexport class SpecLoadError extends OpenAPIRuntimeError {\n /**\n * @param {string} specName - Name/path of the spec that failed to load\n * @param {string} reason - Why loading failed\n */\n constructor(specName, reason) {\n super(\n `Failed to load spec \"${specName}\": ${reason}`,\n 'SPEC_LOAD_FAILED',\n { specName, reason }\n )\n this.name = 'SpecLoadError'\n }\n}\n\n/**\n * Thrown when configuration is invalid.\n * @extends OpenAPIRuntimeError\n */\nexport class ConfigurationError extends OpenAPIRuntimeError {\n /**\n * @param {string} message - What's wrong with the configuration\n * @param {string} [configKey] - Which config key is problematic\n */\n constructor(message, configKey) {\n super(\n message,\n 'CONFIGURATION_INVALID',\n { configKey }\n )\n this.name = 'ConfigurationError'\n }\n}\n\n/**\n * Thrown when input parameters are invalid.\n * @extends OpenAPIRuntimeError\n */\nexport class InvalidInputError extends OpenAPIRuntimeError {\n /**\n * @param {string} message - What input is invalid\n * @param {string} [field] - Which field is invalid\n * @param {*} [value] - The invalid value (sanitized)\n */\n constructor(message, field, value) {\n super(\n message,\n 'INVALID_INPUT',\n { field, value: typeof value === 'string' ? value.slice(0, 100) : typeof value }\n )\n this.name = 'InvalidInputError'\n }\n}\n"],"names":[],"mappings":"AASO,MAAM,4BAA4B,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM7C,YAAY,SAAS,MAAM,UAAU,CAAA,GAAI;AAC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