@objectstack/spec 0.8.2 → 0.9.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.
Files changed (190) hide show
  1. package/README.md +58 -4
  2. package/dist/ai/devops-agent.zod.d.ts +1 -1
  3. package/dist/ai/feedback-loop.zod.d.ts +4293 -0
  4. package/dist/ai/feedback-loop.zod.d.ts.map +1 -0
  5. package/dist/ai/feedback-loop.zod.js +53 -0
  6. package/dist/ai/index.d.ts +1 -0
  7. package/dist/ai/index.d.ts.map +1 -1
  8. package/dist/ai/index.js +1 -0
  9. package/dist/api/documentation.zod.d.ts +1073 -0
  10. package/dist/api/documentation.zod.d.ts.map +1 -0
  11. package/dist/api/documentation.zod.js +487 -0
  12. package/dist/api/errors.zod.d.ts +6 -6
  13. package/dist/api/graphql.zod.d.ts +3 -3
  14. package/dist/api/hub.zod.d.ts +5239 -0
  15. package/dist/api/hub.zod.d.ts.map +1 -0
  16. package/dist/api/hub.zod.js +784 -0
  17. package/dist/api/index.d.ts +4 -0
  18. package/dist/api/index.d.ts.map +1 -1
  19. package/dist/api/index.js +4 -0
  20. package/dist/api/odata.zod.d.ts +1 -1
  21. package/dist/api/registry.example.d.ts +411 -0
  22. package/dist/api/registry.example.d.ts.map +1 -0
  23. package/dist/api/registry.example.js +470 -0
  24. package/dist/api/registry.zod.d.ts +2095 -0
  25. package/dist/api/registry.zod.d.ts.map +1 -0
  26. package/dist/api/registry.zod.js +755 -0
  27. package/dist/api/websocket.zod.d.ts +8 -8
  28. package/dist/auth/scim.zod.d.ts +3 -3
  29. package/dist/automation/flow.zod.d.ts +3 -3
  30. package/dist/contracts/index.d.ts +1 -0
  31. package/dist/contracts/index.d.ts.map +1 -1
  32. package/dist/contracts/index.js +1 -0
  33. package/dist/contracts/schema-driver.d.ts +21 -0
  34. package/dist/contracts/schema-driver.d.ts.map +1 -0
  35. package/dist/contracts/schema-driver.js +2 -0
  36. package/dist/hub/composer.zod.d.ts +226 -0
  37. package/dist/hub/composer.zod.d.ts.map +1 -1
  38. package/dist/hub/hub-federation.zod.d.ts +764 -0
  39. package/dist/hub/hub-federation.zod.d.ts.map +1 -0
  40. package/dist/hub/hub-federation.zod.js +441 -0
  41. package/dist/hub/index.d.ts +2 -0
  42. package/dist/hub/index.d.ts.map +1 -1
  43. package/dist/hub/index.js +3 -0
  44. package/dist/hub/plugin-security.zod.d.ts +1029 -0
  45. package/dist/hub/plugin-security.zod.d.ts.map +1 -0
  46. package/dist/hub/plugin-security.zod.js +637 -0
  47. package/dist/index.d.ts +1 -0
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +2 -1
  50. package/dist/integration/connector/vercel.zod.d.ts +2 -2
  51. package/dist/qa/index.d.ts +11 -0
  52. package/dist/qa/index.d.ts.map +1 -0
  53. package/dist/qa/index.js +26 -0
  54. package/dist/qa/testing.zod.d.ts +345 -0
  55. package/dist/qa/testing.zod.d.ts.map +1 -0
  56. package/dist/qa/testing.zod.js +69 -0
  57. package/dist/stack.zod.d.ts +3395 -596
  58. package/dist/stack.zod.d.ts.map +1 -1
  59. package/dist/stack.zod.js +20 -2
  60. package/dist/system/index.d.ts +2 -0
  61. package/dist/system/index.d.ts.map +1 -1
  62. package/dist/system/index.js +2 -0
  63. package/dist/system/manifest.zod.d.ts +226 -0
  64. package/dist/system/manifest.zod.d.ts.map +1 -1
  65. package/dist/system/manifest.zod.js +8 -0
  66. package/dist/system/message-queue.zod.d.ts +2 -2
  67. package/dist/system/metadata-loader.zod.d.ts +1 -1
  68. package/dist/system/migration.zod.d.ts +4205 -0
  69. package/dist/system/migration.zod.d.ts.map +1 -0
  70. package/dist/system/migration.zod.js +70 -0
  71. package/dist/system/plugin-loading.zod.d.ts +575 -0
  72. package/dist/system/plugin-loading.zod.d.ts.map +1 -0
  73. package/dist/system/plugin-loading.zod.js +612 -0
  74. package/json-schema/ai/FeedbackLoop.json +7 -0
  75. package/json-schema/ai/Issue.json +7 -0
  76. package/json-schema/ai/MetadataSource.json +7 -0
  77. package/json-schema/ai/Resolution.json +7 -0
  78. package/json-schema/api/ApiChangelogEntry.json +7 -0
  79. package/json-schema/api/ApiDiscoveryQuery.json +7 -0
  80. package/json-schema/api/ApiDiscoveryResponse.json +7 -0
  81. package/json-schema/api/ApiDocumentationConfig.json +7 -0
  82. package/json-schema/api/ApiEndpointRegistration.json +7 -0
  83. package/json-schema/api/ApiMetadata.json +7 -0
  84. package/json-schema/api/ApiParameter.json +7 -0
  85. package/json-schema/api/ApiProtocolType.json +7 -0
  86. package/json-schema/api/ApiRegistry.json +7 -0
  87. package/json-schema/api/ApiRegistryEntry.json +7 -0
  88. package/json-schema/api/ApiResponse.json +7 -0
  89. package/json-schema/api/ApiTestCollection.json +7 -0
  90. package/json-schema/api/ApiTestRequest.json +7 -0
  91. package/json-schema/api/ApiTestingUiConfig.json +7 -0
  92. package/json-schema/api/ApiTestingUiType.json +7 -0
  93. package/json-schema/api/BuildStatusResponse.json +7 -0
  94. package/json-schema/api/CodeGenerationTemplate.json +7 -0
  95. package/json-schema/api/CompileManifestRequest.json +7 -0
  96. package/json-schema/api/CompileManifestResponse.json +7 -0
  97. package/json-schema/api/ConflictResolutionStrategy.json +7 -0
  98. package/json-schema/api/CreateSpaceRequest.json +7 -0
  99. package/json-schema/api/CreateTenantRequest.json +7 -0
  100. package/json-schema/api/GeneratedApiDocumentation.json +7 -0
  101. package/json-schema/api/GetBuildStatusRequest.json +7 -0
  102. package/json-schema/api/GetMarketplacePluginRequest.json +7 -0
  103. package/json-schema/api/GetPluginVersionsRequest.json +7 -0
  104. package/json-schema/api/GetPluginVersionsResponse.json +7 -0
  105. package/json-schema/api/HttpStatusCode.json +7 -0
  106. package/json-schema/api/HubHealthResponse.json +7 -0
  107. package/json-schema/api/HubMetricsResponse.json +7 -0
  108. package/json-schema/api/IssueLicenseRequest.json +7 -0
  109. package/json-schema/api/LicenseResponse.json +7 -0
  110. package/json-schema/api/ListLicensesRequest.json +7 -0
  111. package/json-schema/api/ListLicensesResponse.json +7 -0
  112. package/json-schema/api/ListMarketplaceRequest.json +7 -0
  113. package/json-schema/api/ListMarketplaceResponse.json +7 -0
  114. package/json-schema/api/ListSpacesRequest.json +7 -0
  115. package/json-schema/api/ListSpacesResponse.json +7 -0
  116. package/json-schema/api/ListTenantsRequest.json +7 -0
  117. package/json-schema/api/ListTenantsResponse.json +7 -0
  118. package/json-schema/api/MarketplacePluginResponse.json +7 -0
  119. package/json-schema/api/ObjectQLReference.json +7 -0
  120. package/json-schema/api/OpenApiSecurityScheme.json +7 -0
  121. package/json-schema/api/OpenApiServer.json +7 -0
  122. package/json-schema/api/OpenApiSpec.json +7 -0
  123. package/json-schema/api/PaginationRequest.json +7 -0
  124. package/json-schema/api/PaginationResponse.json +7 -0
  125. package/json-schema/api/PluginResponse.json +7 -0
  126. package/json-schema/api/PluginVersionInfo.json +7 -0
  127. package/json-schema/api/PublishPluginRequest.json +7 -0
  128. package/json-schema/api/RevokeLicenseRequest.json +7 -0
  129. package/json-schema/api/SchemaDefinition.json +7 -0
  130. package/json-schema/api/SearchPluginsRequest.json +7 -0
  131. package/json-schema/api/SearchPluginsResponse.json +7 -0
  132. package/json-schema/api/SpaceResponse.json +7 -0
  133. package/json-schema/api/TenantResponse.json +7 -0
  134. package/json-schema/api/UpdatePluginRequest.json +7 -0
  135. package/json-schema/api/UpdateSpaceRequest.json +7 -0
  136. package/json-schema/api/UpdateTenantRequest.json +7 -0
  137. package/json-schema/api/ValidateLicenseRequest.json +7 -0
  138. package/json-schema/api/ValidateLicenseResponse.json +7 -0
  139. package/json-schema/hub/DependencyConflict.json +7 -0
  140. package/json-schema/hub/DependencyGraph.json +7 -0
  141. package/json-schema/hub/DependencyGraphNode.json +7 -0
  142. package/json-schema/hub/DependencyResolutionResult.json +7 -0
  143. package/json-schema/hub/EdgeLocation.json +7 -0
  144. package/json-schema/hub/FederationTopology.json +7 -0
  145. package/json-schema/hub/GlobalRegistryEntry.json +7 -0
  146. package/json-schema/hub/HubInstance.json +7 -0
  147. package/json-schema/hub/PackageDependency.json +7 -0
  148. package/json-schema/hub/PluginProvenance.json +7 -0
  149. package/json-schema/hub/PluginTrustScore.json +7 -0
  150. package/json-schema/hub/Region.json +7 -0
  151. package/json-schema/hub/ReplicationJob.json +7 -0
  152. package/json-schema/hub/SBOM.json +7 -0
  153. package/json-schema/hub/SBOMEntry.json +7 -0
  154. package/json-schema/hub/SecurityPolicy.json +7 -0
  155. package/json-schema/hub/SecurityScanResult.json +7 -0
  156. package/json-schema/hub/SecurityVulnerability.json +7 -0
  157. package/json-schema/hub/TenantPlacementPolicy.json +7 -0
  158. package/json-schema/hub/VulnerabilitySeverity.json +7 -0
  159. package/json-schema/qa/TestAction.json +7 -0
  160. package/json-schema/qa/TestActionType.json +7 -0
  161. package/json-schema/qa/TestAssertion.json +7 -0
  162. package/json-schema/qa/TestAssertionType.json +7 -0
  163. package/json-schema/qa/TestContext.json +7 -0
  164. package/json-schema/qa/TestScenario.json +7 -0
  165. package/json-schema/qa/TestStep.json +7 -0
  166. package/json-schema/qa/TestSuite.json +7 -0
  167. package/json-schema/system/AddFieldOperation.json +7 -0
  168. package/json-schema/system/ChangeSet.json +7 -0
  169. package/json-schema/system/CreateObjectOperation.json +7 -0
  170. package/json-schema/system/DeleteObjectOperation.json +7 -0
  171. package/json-schema/system/ExecuteSqlOperation.json +7 -0
  172. package/json-schema/system/MigrationDependency.json +7 -0
  173. package/json-schema/system/MigrationOperation.json +7 -0
  174. package/json-schema/system/ModifyFieldOperation.json +7 -0
  175. package/json-schema/system/PluginCaching.json +7 -0
  176. package/json-schema/system/PluginCodeSplitting.json +7 -0
  177. package/json-schema/system/PluginDependencyResolution.json +7 -0
  178. package/json-schema/system/PluginDynamicImport.json +7 -0
  179. package/json-schema/system/PluginHotReload.json +7 -0
  180. package/json-schema/system/PluginInitialization.json +7 -0
  181. package/json-schema/system/PluginLoadingConfig.json +7 -0
  182. package/json-schema/system/PluginLoadingEvent.json +7 -0
  183. package/json-schema/system/PluginLoadingState.json +7 -0
  184. package/json-schema/system/PluginLoadingStrategy.json +7 -0
  185. package/json-schema/system/PluginPerformanceMonitoring.json +7 -0
  186. package/json-schema/system/PluginPreloadConfig.json +7 -0
  187. package/json-schema/system/PluginSandboxing.json +7 -0
  188. package/json-schema/system/RemoveFieldOperation.json +7 -0
  189. package/json-schema/system/RenameObjectOperation.json +7 -0
  190. package/package.json +1 -1
@@ -0,0 +1,755 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiRegistry = exports.ApiRegistryEntry = exports.ApiEndpointRegistration = exports.ApiDiscoveryResponseSchema = exports.ApiDiscoveryQuerySchema = exports.ApiRegistrySchema = exports.ConflictResolutionStrategy = exports.ApiRegistryEntrySchema = exports.ApiMetadataSchema = exports.ApiEndpointRegistrationSchema = exports.ApiResponseSchema = exports.ApiParameterSchema = exports.SchemaDefinition = exports.ObjectQLReferenceSchema = exports.HttpStatusCode = exports.ApiProtocolType = void 0;
4
+ const zod_1 = require("zod");
5
+ const http_zod_1 = require("../shared/http.zod");
6
+ const identifiers_zod_1 = require("../shared/identifiers.zod");
7
+ /**
8
+ * Unified API Registry Protocol
9
+ *
10
+ * Provides a centralized registry for managing all API endpoints across different
11
+ * API types (REST, GraphQL, OData, WebSocket, Auth, File, Plugin-registered).
12
+ *
13
+ * This enables:
14
+ * - Unified API discovery and documentation (similar to Swagger/OpenAPI)
15
+ * - API testing interfaces
16
+ * - API governance and monitoring
17
+ * - Plugin API registration
18
+ * - Multi-protocol support
19
+ *
20
+ * Architecture Alignment:
21
+ * - Kubernetes: Service Discovery & API Server
22
+ * - AWS API Gateway: Unified API Management
23
+ * - Kong Gateway: Plugin-based API Management
24
+ *
25
+ * @example API Registry Entry
26
+ * ```typescript
27
+ * const apiEntry: ApiRegistryEntry = {
28
+ * id: 'customer_crud',
29
+ * name: 'Customer CRUD API',
30
+ * type: 'rest',
31
+ * version: 'v1',
32
+ * basePath: '/api/v1/data/customer',
33
+ * endpoints: [...],
34
+ * metadata: {
35
+ * owner: 'sales_team',
36
+ * tags: ['customer', 'crm']
37
+ * }
38
+ * }
39
+ * ```
40
+ */
41
+ // ==========================================
42
+ // API Type Enumeration
43
+ // ==========================================
44
+ /**
45
+ * API Protocol Type
46
+ *
47
+ * Defines the different types of APIs supported by ObjectStack.
48
+ */
49
+ exports.ApiProtocolType = zod_1.z.enum([
50
+ 'rest', // RESTful API (CRUD operations)
51
+ 'graphql', // GraphQL API (flexible queries)
52
+ 'odata', // OData v4 API (enterprise integration)
53
+ 'websocket', // WebSocket API (real-time)
54
+ 'file', // File/Storage API (uploads/downloads)
55
+ 'auth', // Authentication/Authorization API
56
+ 'metadata', // Metadata/Schema API
57
+ 'plugin', // Plugin-registered custom API
58
+ 'webhook', // Webhook endpoints
59
+ 'rpc', // JSON-RPC or similar
60
+ ]);
61
+ // ==========================================
62
+ // API Endpoint Registration
63
+ // ==========================================
64
+ /**
65
+ * HTTP Status Code
66
+ */
67
+ exports.HttpStatusCode = zod_1.z.union([
68
+ zod_1.z.number().int().min(100).max(599),
69
+ zod_1.z.enum(['2xx', '3xx', '4xx', '5xx']), // Pattern matching
70
+ ]);
71
+ // ==========================================
72
+ // Schema Reference Types
73
+ // ==========================================
74
+ /**
75
+ * ObjectQL Reference Schema
76
+ *
77
+ * Allows referencing ObjectStack data objects instead of static JSON schemas.
78
+ * When an API parameter or response references an ObjectQL object, the schema
79
+ * is dynamically derived from the object definition, enabling automatic updates
80
+ * when the object schema changes.
81
+ *
82
+ * **IMPORTANT - Schema Resolution Responsibility:**
83
+ * The API Registry STORES these references as metadata but does NOT resolve them.
84
+ * Schema resolution (expanding references into actual JSON Schema) is performed by:
85
+ * - **API Gateway**: For runtime request/response validation
86
+ * - **OpenAPI Generator**: For Swagger/OpenAPI documentation
87
+ * - **GraphQL Schema Builder**: For GraphQL type generation
88
+ * - **Documentation Tools**: For developer documentation
89
+ *
90
+ * This separation allows the Registry to remain lightweight and focused on
91
+ * registration/discovery, while specialized tools handle schema transformation.
92
+ *
93
+ * **Benefits:**
94
+ * - Auto-updating API documentation when object schemas change
95
+ * - Consistent type definitions across API and database
96
+ * - Reduced duplication and maintenance
97
+ * - Registry remains protocol-agnostic and lightweight
98
+ *
99
+ * @example Reference Customer object
100
+ * ```json
101
+ * {
102
+ * "objectId": "customer",
103
+ * "includeFields": ["id", "name", "email"],
104
+ * "excludeFields": ["internal_notes"]
105
+ * }
106
+ * ```
107
+ */
108
+ exports.ObjectQLReferenceSchema = zod_1.z.object({
109
+ /** Referenced object name (snake_case) */
110
+ objectId: identifiers_zod_1.SnakeCaseIdentifierSchema.describe('Object name to reference'),
111
+ /** Include only specific fields (optional) */
112
+ includeFields: zod_1.z.array(zod_1.z.string()).optional()
113
+ .describe('Include only these fields in the schema'),
114
+ /** Exclude specific fields (optional) */
115
+ excludeFields: zod_1.z.array(zod_1.z.string()).optional()
116
+ .describe('Exclude these fields from the schema'),
117
+ /** Include related objects via lookup fields */
118
+ includeRelated: zod_1.z.array(zod_1.z.string()).optional()
119
+ .describe('Include related objects via lookup fields'),
120
+ });
121
+ /**
122
+ * Schema Definition
123
+ *
124
+ * Unified schema definition that supports both:
125
+ * 1. Static JSON Schema (traditional approach)
126
+ * 2. Dynamic ObjectQL reference (linked to object definitions)
127
+ *
128
+ * When using ObjectQL references, the API documentation and validation
129
+ * automatically update when object schemas change, eliminating the need
130
+ * to manually sync API schemas with data models.
131
+ */
132
+ exports.SchemaDefinition = zod_1.z.union([
133
+ zod_1.z.any().describe('Static JSON Schema definition'),
134
+ zod_1.z.object({
135
+ $ref: exports.ObjectQLReferenceSchema.describe('Dynamic reference to ObjectQL object'),
136
+ }).describe('Dynamic ObjectQL reference'),
137
+ ]);
138
+ // ==========================================
139
+ // API Parameter & Response Schemas
140
+ // ==========================================
141
+ /**
142
+ * API Parameter Schema
143
+ *
144
+ * Defines a single API parameter (path, query, header, or body).
145
+ *
146
+ * **Enhancement: Dynamic Schema Linking**
147
+ * - Supports both static JSON Schema and dynamic ObjectQL references
148
+ * - When using ObjectQL references, parameter validation automatically updates
149
+ * when the referenced object schema changes
150
+ *
151
+ * @example Static schema
152
+ * ```json
153
+ * {
154
+ * "name": "customer_id",
155
+ * "in": "path",
156
+ * "schema": {
157
+ * "type": "string",
158
+ * "format": "uuid"
159
+ * }
160
+ * }
161
+ * ```
162
+ *
163
+ * @example Dynamic ObjectQL reference
164
+ * ```json
165
+ * {
166
+ * "name": "customer",
167
+ * "in": "body",
168
+ * "schema": {
169
+ * "$ref": {
170
+ * "objectId": "customer",
171
+ * "excludeFields": ["internal_notes"]
172
+ * }
173
+ * }
174
+ * }
175
+ * ```
176
+ */
177
+ exports.ApiParameterSchema = zod_1.z.object({
178
+ /** Parameter name */
179
+ name: zod_1.z.string().describe('Parameter name'),
180
+ /** Parameter location */
181
+ in: zod_1.z.enum(['path', 'query', 'header', 'body', 'cookie']).describe('Parameter location'),
182
+ /** Parameter description */
183
+ description: zod_1.z.string().optional().describe('Parameter description'),
184
+ /** Required flag */
185
+ required: zod_1.z.boolean().default(false).describe('Whether parameter is required'),
186
+ /** Parameter type/schema - supports static or dynamic (ObjectQL) schemas */
187
+ schema: zod_1.z.union([
188
+ zod_1.z.object({
189
+ type: zod_1.z.enum(['string', 'number', 'integer', 'boolean', 'array', 'object']).describe('Parameter type'),
190
+ format: zod_1.z.string().optional().describe('Format (e.g., date-time, email, uuid)'),
191
+ enum: zod_1.z.array(zod_1.z.any()).optional().describe('Allowed values'),
192
+ default: zod_1.z.any().optional().describe('Default value'),
193
+ items: zod_1.z.any().optional().describe('Array item schema'),
194
+ properties: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional().describe('Object properties'),
195
+ }).describe('Static JSON Schema'),
196
+ zod_1.z.object({
197
+ $ref: exports.ObjectQLReferenceSchema,
198
+ }).describe('Dynamic ObjectQL reference'),
199
+ ]).describe('Parameter schema definition'),
200
+ /** Example value */
201
+ example: zod_1.z.any().optional().describe('Example value'),
202
+ });
203
+ /**
204
+ * API Response Schema
205
+ *
206
+ * Defines an API response for a specific status code.
207
+ *
208
+ * **Enhancement: Dynamic Schema Linking**
209
+ * - Response schema can reference ObjectQL objects
210
+ * - When object definitions change, response documentation auto-updates
211
+ *
212
+ * @example Response with ObjectQL reference
213
+ * ```json
214
+ * {
215
+ * "statusCode": 200,
216
+ * "description": "Customer retrieved successfully",
217
+ * "schema": {
218
+ * "$ref": {
219
+ * "objectId": "customer",
220
+ * "excludeFields": ["password_hash"]
221
+ * }
222
+ * }
223
+ * }
224
+ * ```
225
+ */
226
+ exports.ApiResponseSchema = zod_1.z.object({
227
+ /** HTTP status code */
228
+ statusCode: exports.HttpStatusCode.describe('HTTP status code'),
229
+ /** Response description */
230
+ description: zod_1.z.string().describe('Response description'),
231
+ /** Response content type */
232
+ contentType: zod_1.z.string().default('application/json').describe('Response content type'),
233
+ /** Response schema - supports static or dynamic (ObjectQL) schemas */
234
+ schema: zod_1.z.union([
235
+ zod_1.z.any().describe('Static JSON Schema'),
236
+ zod_1.z.object({
237
+ $ref: exports.ObjectQLReferenceSchema,
238
+ }).describe('Dynamic ObjectQL reference'),
239
+ ]).optional().describe('Response body schema'),
240
+ /** Response headers */
241
+ headers: zod_1.z.record(zod_1.z.string(), zod_1.z.object({
242
+ description: zod_1.z.string().optional(),
243
+ schema: zod_1.z.any(),
244
+ })).optional().describe('Response headers'),
245
+ /** Example response */
246
+ example: zod_1.z.any().optional().describe('Example response'),
247
+ });
248
+ /**
249
+ * API Endpoint Registration Schema
250
+ *
251
+ * Represents a single API endpoint registration with complete metadata.
252
+ *
253
+ * **Enhancements:**
254
+ * 1. **RBAC Integration**: `requiredPermissions` field for automatic permission checking
255
+ * 2. **Dynamic Schema Linking**: Parameters and responses can reference ObjectQL objects
256
+ * 3. **Route Priority**: `priority` field for conflict resolution
257
+ * 4. **Protocol Config**: `protocolConfig` for protocol-specific extensions
258
+ *
259
+ * @example REST Endpoint with RBAC
260
+ * ```json
261
+ * {
262
+ * "id": "get_customer_by_id",
263
+ * "method": "GET",
264
+ * "path": "/api/v1/data/customer/:id",
265
+ * "summary": "Get customer by ID",
266
+ * "requiredPermissions": ["customer.read"],
267
+ * "parameters": [
268
+ * {
269
+ * "name": "id",
270
+ * "in": "path",
271
+ * "required": true,
272
+ * "schema": { "type": "string" }
273
+ * }
274
+ * ],
275
+ * "responses": [
276
+ * {
277
+ * "statusCode": 200,
278
+ * "description": "Customer found",
279
+ * "schema": {
280
+ * "$ref": {
281
+ * "objectId": "customer"
282
+ * }
283
+ * }
284
+ * }
285
+ * ],
286
+ * "priority": 100
287
+ * }
288
+ * ```
289
+ *
290
+ * @example Plugin Endpoint with Protocol Config
291
+ * ```json
292
+ * {
293
+ * "id": "grpc_service_method",
294
+ * "path": "/grpc/ServiceName/MethodName",
295
+ * "summary": "gRPC service method",
296
+ * "protocolConfig": {
297
+ * "subProtocol": "grpc",
298
+ * "serviceName": "CustomerService",
299
+ * "methodName": "GetCustomer"
300
+ * },
301
+ * "priority": 50
302
+ * }
303
+ * ```
304
+ */
305
+ exports.ApiEndpointRegistrationSchema = zod_1.z.object({
306
+ /** Unique endpoint identifier */
307
+ id: zod_1.z.string().describe('Unique endpoint identifier'),
308
+ /** HTTP method (for HTTP-based APIs) */
309
+ method: http_zod_1.HttpMethod.optional().describe('HTTP method'),
310
+ /** URL path pattern */
311
+ path: zod_1.z.string().describe('URL path pattern'),
312
+ /** Short summary */
313
+ summary: zod_1.z.string().optional().describe('Short endpoint summary'),
314
+ /** Detailed description */
315
+ description: zod_1.z.string().optional().describe('Detailed endpoint description'),
316
+ /** Operation ID (OpenAPI) */
317
+ operationId: zod_1.z.string().optional().describe('Unique operation identifier'),
318
+ /** Tags for grouping */
319
+ tags: zod_1.z.array(zod_1.z.string()).optional().default([]).describe('Tags for categorization'),
320
+ /** Parameters */
321
+ parameters: zod_1.z.array(exports.ApiParameterSchema).optional().default([]).describe('Endpoint parameters'),
322
+ /** Request body schema */
323
+ requestBody: zod_1.z.object({
324
+ description: zod_1.z.string().optional(),
325
+ required: zod_1.z.boolean().default(false),
326
+ contentType: zod_1.z.string().default('application/json'),
327
+ schema: zod_1.z.any().optional(),
328
+ example: zod_1.z.any().optional(),
329
+ }).optional().describe('Request body specification'),
330
+ /** Response definitions */
331
+ responses: zod_1.z.array(exports.ApiResponseSchema).optional().default([]).describe('Possible responses'),
332
+ /**
333
+ * Required Permissions (RBAC Integration)
334
+ *
335
+ * Array of permission names required to access this endpoint.
336
+ * The gateway layer automatically validates these permissions before
337
+ * allowing the request to proceed, eliminating the need for permission
338
+ * checks in individual API handlers.
339
+ *
340
+ * **Format:** `<object>.<operation>` or system permission name
341
+ *
342
+ * **Object Permissions:**
343
+ * - `customer.read` - Read customer records
344
+ * - `customer.create` - Create customer records
345
+ * - `customer.edit` - Update customer records
346
+ * - `customer.delete` - Delete customer records
347
+ * - `customer.viewAll` - View all customer records (bypass sharing)
348
+ * - `customer.modifyAll` - Modify all customer records (bypass sharing)
349
+ *
350
+ * **System Permissions:**
351
+ * - `manage_users` - User management
352
+ * - `view_setup` - Access to system setup
353
+ * - `customize_application` - Modify metadata
354
+ * - `api_enabled` - API access
355
+ *
356
+ * @example Object-level permissions
357
+ * ```json
358
+ * {
359
+ * "requiredPermissions": ["customer.read"]
360
+ * }
361
+ * ```
362
+ *
363
+ * @example Multiple permissions (ALL required)
364
+ * ```json
365
+ * {
366
+ * "requiredPermissions": ["customer.read", "account.read"]
367
+ * }
368
+ * ```
369
+ *
370
+ * @example System permission
371
+ * ```json
372
+ * {
373
+ * "requiredPermissions": ["manage_users"]
374
+ * }
375
+ * ```
376
+ *
377
+ * @see {@link file://../../permission/permission.zod.ts} for permission definitions
378
+ */
379
+ requiredPermissions: zod_1.z.array(zod_1.z.string()).optional().default([])
380
+ .describe('Required RBAC permissions (e.g., "customer.read", "manage_users")'),
381
+ /** Security requirements */
382
+ security: zod_1.z.array(zod_1.z.object({
383
+ type: zod_1.z.enum(['apiKey', 'http', 'oauth2', 'openIdConnect']),
384
+ scheme: zod_1.z.string().optional(), // bearer, basic, etc.
385
+ name: zod_1.z.string().optional(), // for apiKey
386
+ in: zod_1.z.enum(['header', 'query', 'cookie']).optional(),
387
+ })).optional().describe('Security requirements'),
388
+ /**
389
+ * Route Priority
390
+ *
391
+ * Priority level for route conflict resolution. Higher priority routes
392
+ * are registered first and take precedence when multiple routes match
393
+ * the same path pattern.
394
+ *
395
+ * **Default:** 100 (medium priority)
396
+ * **Range:** 0-1000 (higher = more important)
397
+ *
398
+ * **Use Cases:**
399
+ * - Core system APIs: 900-1000
400
+ * - Plugin APIs: 100-500
401
+ * - Custom/override APIs: 500-900
402
+ * - Fallback routes: 0-100
403
+ *
404
+ * @example High priority core endpoint
405
+ * ```json
406
+ * {
407
+ * "path": "/api/v1/data/:object/:id",
408
+ * "priority": 950
409
+ * }
410
+ * ```
411
+ *
412
+ * @example Medium priority plugin endpoint
413
+ * ```json
414
+ * {
415
+ * "path": "/api/v1/custom/action",
416
+ * "priority": 300
417
+ * }
418
+ * ```
419
+ */
420
+ priority: zod_1.z.number().int().min(0).max(1000).optional().default(100)
421
+ .describe('Route priority for conflict resolution (0-1000, higher = more important)'),
422
+ /**
423
+ * Protocol-Specific Configuration
424
+ *
425
+ * Allows plugins and custom APIs to define protocol-specific metadata
426
+ * that can be used for specialized handling or documentation generation.
427
+ *
428
+ * **Examples:**
429
+ * - gRPC: Service and method names
430
+ * - tRPC: Procedure type (query/mutation)
431
+ * - WebSocket: Event names and handlers
432
+ * - Custom protocols: Any metadata needed
433
+ *
434
+ * @example gRPC configuration
435
+ * ```json
436
+ * {
437
+ * "protocolConfig": {
438
+ * "subProtocol": "grpc",
439
+ * "serviceName": "CustomerService",
440
+ * "methodName": "GetCustomer",
441
+ * "streaming": false
442
+ * }
443
+ * }
444
+ * ```
445
+ *
446
+ * @example tRPC configuration
447
+ * ```json
448
+ * {
449
+ * "protocolConfig": {
450
+ * "subProtocol": "trpc",
451
+ * "procedureType": "query",
452
+ * "router": "customer"
453
+ * }
454
+ * }
455
+ * ```
456
+ *
457
+ * @example WebSocket configuration
458
+ * ```json
459
+ * {
460
+ * "protocolConfig": {
461
+ * "subProtocol": "websocket",
462
+ * "eventName": "customer.updated",
463
+ * "direction": "server-to-client"
464
+ * }
465
+ * }
466
+ * ```
467
+ */
468
+ protocolConfig: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional()
469
+ .describe('Protocol-specific configuration for custom protocols (gRPC, tRPC, etc.)'),
470
+ /** Deprecation flag */
471
+ deprecated: zod_1.z.boolean().default(false).describe('Whether endpoint is deprecated'),
472
+ /** External documentation */
473
+ externalDocs: zod_1.z.object({
474
+ description: zod_1.z.string().optional(),
475
+ url: zod_1.z.string().url(),
476
+ }).optional().describe('External documentation link'),
477
+ });
478
+ // ==========================================
479
+ // API Registry Entry
480
+ // ==========================================
481
+ /**
482
+ * API Metadata Schema
483
+ *
484
+ * Additional metadata for an API registration.
485
+ */
486
+ exports.ApiMetadataSchema = zod_1.z.object({
487
+ /** API owner/team */
488
+ owner: zod_1.z.string().optional().describe('Owner team or person'),
489
+ /** API status */
490
+ status: zod_1.z.enum(['active', 'deprecated', 'experimental', 'beta']).default('active')
491
+ .describe('API lifecycle status'),
492
+ /** Categorization tags */
493
+ tags: zod_1.z.array(zod_1.z.string()).optional().default([]).describe('Classification tags'),
494
+ /** Plugin source (if plugin-registered) */
495
+ pluginSource: zod_1.z.string().optional().describe('Source plugin name'),
496
+ /** Custom metadata */
497
+ custom: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional().describe('Custom metadata fields'),
498
+ });
499
+ /**
500
+ * API Registry Entry Schema
501
+ *
502
+ * Complete registration entry for an API in the unified registry.
503
+ *
504
+ * @example REST API Entry
505
+ * ```json
506
+ * {
507
+ * "id": "customer_api",
508
+ * "name": "Customer Management API",
509
+ * "type": "rest",
510
+ * "version": "v1",
511
+ * "basePath": "/api/v1/data/customer",
512
+ * "description": "CRUD operations for customer records",
513
+ * "endpoints": [...],
514
+ * "metadata": {
515
+ * "owner": "sales_team",
516
+ * "status": "active",
517
+ * "tags": ["customer", "crm"]
518
+ * }
519
+ * }
520
+ * ```
521
+ *
522
+ * @example Plugin API Entry
523
+ * ```json
524
+ * {
525
+ * "id": "payment_webhook",
526
+ * "name": "Payment Webhook API",
527
+ * "type": "plugin",
528
+ * "version": "1.0.0",
529
+ * "basePath": "/plugins/payment/webhook",
530
+ * "endpoints": [...],
531
+ * "metadata": {
532
+ * "pluginSource": "payment_gateway_plugin",
533
+ * "status": "active"
534
+ * }
535
+ * }
536
+ * ```
537
+ */
538
+ exports.ApiRegistryEntrySchema = zod_1.z.object({
539
+ /** Unique API identifier */
540
+ id: zod_1.z.string().regex(/^[a-z_][a-z0-9_]*$/).describe('Unique API identifier (snake_case)'),
541
+ /** Human-readable name */
542
+ name: zod_1.z.string().describe('API display name'),
543
+ /** API protocol type */
544
+ type: exports.ApiProtocolType.describe('API protocol type'),
545
+ /** API version */
546
+ version: zod_1.z.string().describe('API version (e.g., v1, 2024-01)'),
547
+ /** Base URL path */
548
+ basePath: zod_1.z.string().describe('Base URL path for this API'),
549
+ /** API description */
550
+ description: zod_1.z.string().optional().describe('API description'),
551
+ /** Endpoints in this API */
552
+ endpoints: zod_1.z.array(exports.ApiEndpointRegistrationSchema).describe('Registered endpoints'),
553
+ /** OpenAPI/GraphQL/OData specific configuration */
554
+ config: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional().describe('Protocol-specific configuration'),
555
+ /** API metadata */
556
+ metadata: exports.ApiMetadataSchema.optional().describe('Additional metadata'),
557
+ /** Terms of service URL */
558
+ termsOfService: zod_1.z.string().url().optional().describe('Terms of service URL'),
559
+ /** Contact information */
560
+ contact: zod_1.z.object({
561
+ name: zod_1.z.string().optional(),
562
+ url: zod_1.z.string().url().optional(),
563
+ email: zod_1.z.string().email().optional(),
564
+ }).optional().describe('Contact information'),
565
+ /** License information */
566
+ license: zod_1.z.object({
567
+ name: zod_1.z.string(),
568
+ url: zod_1.z.string().url().optional(),
569
+ }).optional().describe('License information'),
570
+ });
571
+ // ==========================================
572
+ // API Registry
573
+ // ==========================================
574
+ /**
575
+ * Route Conflict Resolution Strategy
576
+ *
577
+ * Defines how to handle conflicts when multiple endpoints register
578
+ * the same or overlapping URL patterns.
579
+ */
580
+ exports.ConflictResolutionStrategy = zod_1.z.enum([
581
+ 'error', // Throw error on conflict (safest, default)
582
+ 'priority', // Use priority field to resolve (highest priority wins)
583
+ 'first-wins', // First registered endpoint wins
584
+ 'last-wins', // Last registered endpoint wins (override mode)
585
+ ]);
586
+ /**
587
+ * API Registry Schema
588
+ *
589
+ * Central registry containing all registered APIs.
590
+ *
591
+ * **Enhancement: Route Conflict Detection**
592
+ * - `conflictResolution`: Strategy for handling route conflicts
593
+ * - Prevents silent overwrites and unexpected routing behavior
594
+ *
595
+ * @example
596
+ * ```json
597
+ * {
598
+ * "version": "1.0.0",
599
+ * "conflictResolution": "priority",
600
+ * "apis": [
601
+ * { "id": "customer_api", "type": "rest", ... },
602
+ * { "id": "graphql_api", "type": "graphql", ... },
603
+ * { "id": "file_upload_api", "type": "file", ... }
604
+ * ],
605
+ * "totalApis": 3,
606
+ * "totalEndpoints": 47
607
+ * }
608
+ * ```
609
+ *
610
+ * @example Priority-based conflict resolution
611
+ * ```json
612
+ * {
613
+ * "conflictResolution": "priority",
614
+ * "apis": [
615
+ * {
616
+ * "id": "core_api",
617
+ * "endpoints": [
618
+ * {
619
+ * "path": "/api/v1/data/:object",
620
+ * "priority": 950
621
+ * }
622
+ * ]
623
+ * },
624
+ * {
625
+ * "id": "plugin_api",
626
+ * "endpoints": [
627
+ * {
628
+ * "path": "/api/v1/data/custom",
629
+ * "priority": 300
630
+ * }
631
+ * ]
632
+ * }
633
+ * ]
634
+ * }
635
+ * ```
636
+ */
637
+ exports.ApiRegistrySchema = zod_1.z.object({
638
+ /** Registry version */
639
+ version: zod_1.z.string().describe('Registry version'),
640
+ /**
641
+ * Conflict Resolution Strategy
642
+ *
643
+ * Defines how to handle route conflicts when multiple endpoints
644
+ * register the same or overlapping URL patterns.
645
+ *
646
+ * **Strategies:**
647
+ * - `error`: Throw error on conflict (safest, prevents silent overwrites)
648
+ * - `priority`: Use endpoint priority field (highest priority wins)
649
+ * - `first-wins`: First registered endpoint wins (stable, predictable)
650
+ * - `last-wins`: Last registered endpoint wins (allows overrides)
651
+ *
652
+ * **Default:** `error`
653
+ *
654
+ * **Best Practices:**
655
+ * - Use `error` in production to catch configuration issues
656
+ * - Use `priority` when mixing core and plugin APIs
657
+ * - Use `last-wins` for development/testing overrides
658
+ *
659
+ * @example Prevent accidental conflicts
660
+ * ```json
661
+ * {
662
+ * "conflictResolution": "error"
663
+ * }
664
+ * ```
665
+ *
666
+ * @example Allow plugin overrides with priority
667
+ * ```json
668
+ * {
669
+ * "conflictResolution": "priority"
670
+ * }
671
+ * ```
672
+ */
673
+ conflictResolution: exports.ConflictResolutionStrategy.optional().default('error')
674
+ .describe('Strategy for handling route conflicts'),
675
+ /** Registered APIs */
676
+ apis: zod_1.z.array(exports.ApiRegistryEntrySchema).describe('All registered APIs'),
677
+ /** Total API count */
678
+ totalApis: zod_1.z.number().int().describe('Total number of registered APIs'),
679
+ /** Total endpoint count across all APIs */
680
+ totalEndpoints: zod_1.z.number().int().describe('Total number of endpoints'),
681
+ /** APIs grouped by type */
682
+ byType: zod_1.z.record(exports.ApiProtocolType, zod_1.z.array(exports.ApiRegistryEntrySchema)).optional()
683
+ .describe('APIs grouped by protocol type'),
684
+ /** APIs grouped by status */
685
+ byStatus: zod_1.z.record(zod_1.z.string(), zod_1.z.array(exports.ApiRegistryEntrySchema)).optional()
686
+ .describe('APIs grouped by status'),
687
+ /** Last updated timestamp */
688
+ updatedAt: zod_1.z.string().datetime().optional().describe('Last registry update time'),
689
+ });
690
+ // ==========================================
691
+ // API Discovery & Query
692
+ // ==========================================
693
+ /**
694
+ * API Discovery Query Schema
695
+ *
696
+ * Query parameters for discovering/filtering APIs in the registry.
697
+ *
698
+ * @example
699
+ * ```json
700
+ * {
701
+ * "type": "rest",
702
+ * "tags": ["customer"],
703
+ * "status": "active"
704
+ * }
705
+ * ```
706
+ */
707
+ exports.ApiDiscoveryQuerySchema = zod_1.z.object({
708
+ /** Filter by API type */
709
+ type: exports.ApiProtocolType.optional().describe('Filter by API protocol type'),
710
+ /** Filter by tags */
711
+ tags: zod_1.z.array(zod_1.z.string()).optional().describe('Filter by tags (ANY match)'),
712
+ /** Filter by status */
713
+ status: zod_1.z.enum(['active', 'deprecated', 'experimental', 'beta']).optional()
714
+ .describe('Filter by lifecycle status'),
715
+ /** Filter by plugin source */
716
+ pluginSource: zod_1.z.string().optional().describe('Filter by plugin name'),
717
+ /** Search in name/description */
718
+ search: zod_1.z.string().optional().describe('Full-text search in name/description'),
719
+ /** Filter by version */
720
+ version: zod_1.z.string().optional().describe('Filter by specific version'),
721
+ });
722
+ /**
723
+ * API Discovery Response Schema
724
+ *
725
+ * Response for API discovery queries.
726
+ */
727
+ exports.ApiDiscoveryResponseSchema = zod_1.z.object({
728
+ /** Matching APIs */
729
+ apis: zod_1.z.array(exports.ApiRegistryEntrySchema).describe('Matching API entries'),
730
+ /** Total matches */
731
+ total: zod_1.z.number().int().describe('Total matching APIs'),
732
+ /** Applied filters */
733
+ filters: exports.ApiDiscoveryQuerySchema.optional().describe('Applied query filters'),
734
+ });
735
+ // ==========================================
736
+ // Helper Functions
737
+ // ==========================================
738
+ /**
739
+ * Helper to create API endpoint registration
740
+ */
741
+ exports.ApiEndpointRegistration = Object.assign(exports.ApiEndpointRegistrationSchema, {
742
+ create: (config) => config,
743
+ });
744
+ /**
745
+ * Helper to create API registry entry
746
+ */
747
+ exports.ApiRegistryEntry = Object.assign(exports.ApiRegistryEntrySchema, {
748
+ create: (config) => config,
749
+ });
750
+ /**
751
+ * Helper to create API registry
752
+ */
753
+ exports.ApiRegistry = Object.assign(exports.ApiRegistrySchema, {
754
+ create: (config) => config,
755
+ });