@flink-app/flink 0.14.3 → 2.0.0-alpha.100
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/CHANGELOG.md +1051 -0
- package/SCHEMA_EXTRACTION_ANALYSIS.md +494 -0
- package/SIMPLE_AST_FEASIBILITY.md +570 -0
- package/bin/flink.ts +13 -2
- package/cli/build.ts +24 -44
- package/cli/clean.ts +13 -25
- package/cli/cli-utils.ts +190 -17
- package/cli/dev.ts +252 -0
- package/cli/loadEnvFiles.ts +116 -0
- package/cli/run.ts +45 -62
- package/dist/bin/flink.js +61 -2
- package/dist/cli/build.js +20 -25
- package/dist/cli/clean.js +12 -10
- package/dist/cli/cli-utils.d.ts +34 -3
- package/dist/cli/cli-utils.js +193 -12
- package/dist/cli/dev.d.ts +2 -0
- package/dist/cli/dev.js +279 -0
- package/dist/cli/loadEnvFiles.d.ts +30 -0
- package/dist/cli/loadEnvFiles.js +113 -0
- package/dist/cli/run.js +47 -46
- package/dist/src/DependencyTracker.d.ts +44 -0
- package/dist/src/DependencyTracker.js +239 -0
- package/dist/src/FlinkApp.d.ts +163 -10
- package/dist/src/FlinkApp.js +847 -184
- package/dist/src/FlinkContext.d.ts +41 -0
- package/dist/src/FlinkErrors.d.ts +19 -6
- package/dist/src/FlinkErrors.js +36 -42
- package/dist/src/FlinkHttpHandler.d.ts +219 -26
- package/dist/src/FlinkHttpHandler.js +37 -1
- package/dist/src/FlinkJob.d.ts +10 -0
- package/dist/src/FlinkLog.d.ts +82 -18
- package/dist/src/FlinkLog.js +165 -13
- package/dist/src/FlinkLogFactory.d.ts +288 -0
- package/dist/src/FlinkLogFactory.js +619 -0
- package/dist/src/FlinkRepo.d.ts +10 -2
- package/dist/src/FlinkRepo.js +11 -1
- package/dist/src/FlinkRequestContext.d.ts +63 -0
- package/dist/src/FlinkRequestContext.js +74 -0
- package/dist/src/FlinkResponse.d.ts +6 -0
- package/dist/src/FlinkService.d.ts +38 -0
- package/dist/src/FlinkService.js +46 -0
- package/dist/src/LeaderElection.d.ts +45 -0
- package/dist/src/LeaderElection.js +269 -0
- package/dist/src/SchemaCache.d.ts +84 -0
- package/dist/src/SchemaCache.js +289 -0
- package/dist/src/TypeScriptCompiler.d.ts +161 -51
- package/dist/src/TypeScriptCompiler.js +1253 -617
- package/dist/src/TypeScriptUtils.js +4 -0
- package/dist/src/ai/AgentRunner.d.ts +39 -0
- package/dist/src/ai/AgentRunner.js +760 -0
- package/dist/src/ai/ConversationAgent.d.ts +279 -0
- package/dist/src/ai/ConversationAgent.js +404 -0
- package/dist/src/ai/ConversationFlinkAgent.d.ts +278 -0
- package/dist/src/ai/ConversationFlinkAgent.js +404 -0
- package/dist/src/ai/FlinkAgent.d.ts +690 -0
- package/dist/src/ai/FlinkAgent.js +729 -0
- package/dist/src/ai/FlinkTool.d.ts +135 -0
- package/dist/src/ai/FlinkTool.js +2 -0
- package/dist/src/ai/InMemoryConversationAgent.d.ts +121 -0
- package/dist/src/ai/InMemoryConversationAgent.js +209 -0
- package/dist/src/ai/LLMAdapter.d.ts +148 -0
- package/dist/src/ai/LLMAdapter.js +2 -0
- package/dist/src/ai/PersistentFlinkAgent.d.ts +278 -0
- package/dist/src/ai/PersistentFlinkAgent.js +403 -0
- package/dist/src/ai/SubAgentExecutor.d.ts +38 -0
- package/dist/src/ai/SubAgentExecutor.js +223 -0
- package/dist/src/ai/ToolExecutor.d.ts +64 -0
- package/dist/src/ai/ToolExecutor.js +497 -0
- package/dist/src/ai/agentInstructions.d.ts +68 -0
- package/dist/src/ai/agentInstructions.js +286 -0
- package/dist/src/ai/index.d.ts +8 -0
- package/dist/src/ai/index.js +26 -0
- package/dist/src/ai/instructionFileLoader.d.ts +44 -0
- package/dist/src/ai/instructionFileLoader.js +179 -0
- package/dist/src/auth/FlinkAuthPlugin.d.ts +1 -1
- package/dist/src/handlers/StreamWriterFactory.d.ts +20 -0
- package/dist/src/handlers/StreamWriterFactory.js +83 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/index.js +17 -0
- package/dist/src/loadPluginSchemas.d.ts +45 -0
- package/dist/src/loadPluginSchemas.js +143 -0
- package/dist/src/schema-extraction/ComplexTypeDetection.d.ts +40 -0
- package/dist/src/schema-extraction/ComplexTypeDetection.js +75 -0
- package/dist/src/schema-extraction/TypeScriptSourceParser.d.ts +321 -0
- package/dist/src/schema-extraction/TypeScriptSourceParser.js +925 -0
- package/dist/src/schema-extraction/TypeScriptSourceParser.spec.d.ts +1 -0
- package/dist/src/schema-extraction/TypeScriptSourceParser.spec.js +233 -0
- package/dist/src/schema-extraction/TypeScriptTokenizer.d.ts +57 -0
- package/dist/src/schema-extraction/TypeScriptTokenizer.js +177 -0
- package/dist/src/schema-extraction/index.d.ts +2 -0
- package/dist/src/schema-extraction/index.js +20 -0
- package/dist/src/schema-extraction/types.d.ts +31 -0
- package/dist/src/schema-extraction/types.js +2 -0
- package/dist/src/utils/loadFlinkConfig.d.ts +53 -0
- package/dist/src/utils/loadFlinkConfig.js +77 -0
- package/dist/src/utils.d.ts +30 -0
- package/dist/src/utils.js +52 -0
- package/dist/src/workers/SchemaGeneratorWorker.d.ts +1 -0
- package/dist/src/workers/SchemaGeneratorWorker.js +49 -0
- package/dist/src/workers/WorkerPool.d.ts +60 -0
- package/dist/src/workers/WorkerPool.js +306 -0
- package/examples/logging-hierarchical-example.ts +125 -0
- package/package.json +29 -4
- package/readme.md +499 -0
- package/spec/AgentDescendantDetection.spec.ts +335 -0
- package/spec/AgentDuplicateDetection.spec.ts +112 -0
- package/spec/AgentObserver.spec.ts +266 -0
- package/spec/AgentRunner.spec.ts +1062 -0
- package/spec/AsyncLocalStorageContext.spec.ts +223 -0
- package/spec/ConversationHooks.spec.ts +257 -0
- package/spec/FlinkAgent.spec.ts +681 -0
- package/spec/FlinkApp.htmlResponse.spec.ts +260 -0
- package/spec/FlinkApp.onError.invocation.spec.ts +151 -0
- package/spec/FlinkApp.onError.spec.ts +1 -2
- package/spec/FlinkApp.query.spec.ts +107 -0
- package/spec/FlinkApp.routeOrdering.spec.ts +61 -0
- package/spec/FlinkApp.undefinedResponse.spec.ts +123 -0
- package/spec/FlinkApp.validationMode.spec.ts +155 -0
- package/spec/FlinkJob.spec.ts +171 -0
- package/spec/FlinkLogFactory.spec.ts +337 -0
- package/spec/FlinkRepo.spec.ts +1 -1
- package/spec/LeaderElection.spec.ts +174 -0
- package/spec/StreamingIntegration.spec.ts +139 -0
- package/spec/ToolExecutor.spec.ts +465 -0
- package/spec/TypeScriptCompiler.spec.ts +1 -1
- package/spec/TypeScriptSourceParser.spec.ts +1215 -0
- package/spec/TypeScriptTokenizer.spec.ts +366 -0
- package/spec/ai/ContextCompaction.spec.ts +405 -0
- package/spec/ai/ConversationAgent.spec.ts +520 -0
- package/spec/ai/InMemoryConversationAgent.spec.ts +144 -0
- package/spec/ai/agentInstructions.spec.ts +358 -0
- package/spec/fixtures/agent-instructions/TestAgent.ts +24 -0
- package/spec/fixtures/agent-instructions/simple.md +3 -0
- package/spec/fixtures/agent-instructions/template.md +18 -0
- package/spec/fixtures/agent-instructions/yaml-format.yaml +9 -0
- package/spec/mock-project/dist/.tsbuildinfo +1 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCar.js +56 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCar2.js +58 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithArraySchema.js +52 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithArraySchema2.js +52 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithArraySchema3.js +52 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithLiteralSchema.js +54 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithLiteralSchema2.js +54 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithSchemaInFile.js +57 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithSchemaInFile2.js +57 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/ManuallyAddedHandler.js +53 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/ManuallyAddedHandler2.js +55 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchCar.js +57 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchOnboardingSession.js +75 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchOrderWithComplexTypes.js +57 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchProductWithIntersection.js +58 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchUserWithUnion.js +58 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PostCar.js +54 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PostLogin.js +55 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PostLogout.js +54 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PutCar.js +54 -0
- package/spec/mock-project/dist/spec/mock-project/src/index.js +83 -0
- package/spec/mock-project/dist/spec/mock-project/src/repos/CarRepo.js +26 -0
- package/spec/mock-project/dist/spec/mock-project/src/schemas/Car.js +2 -0
- package/spec/mock-project/dist/spec/mock-project/src/schemas/DefaultExportSchema.js +2 -0
- package/spec/mock-project/dist/spec/mock-project/src/schemas/FileWithTwoSchemas.js +2 -0
- package/spec/mock-project/dist/src/FlinkApp.js +1000 -0
- package/spec/mock-project/dist/src/FlinkContext.js +2 -0
- package/spec/mock-project/dist/src/FlinkErrors.js +143 -0
- package/spec/mock-project/dist/src/FlinkHttpHandler.js +47 -0
- package/spec/mock-project/dist/src/FlinkJob.js +2 -0
- package/spec/mock-project/dist/src/FlinkLog.js +119 -0
- package/spec/mock-project/dist/src/FlinkLogFactory.js +617 -0
- package/spec/mock-project/dist/src/FlinkPlugin.js +2 -0
- package/spec/mock-project/dist/src/FlinkRepo.js +224 -0
- package/spec/mock-project/dist/src/FlinkRequestContext.js +74 -0
- package/spec/mock-project/dist/src/FlinkResponse.js +2 -0
- package/spec/mock-project/dist/src/ai/AgentExecutor.js +279 -0
- package/spec/mock-project/dist/src/ai/AgentRunner.js +632 -0
- package/spec/mock-project/dist/src/ai/ConversationAgent.js +402 -0
- package/spec/mock-project/dist/src/ai/ConversationFlinkAgent.js +422 -0
- package/spec/mock-project/dist/src/ai/FlinkAgent.js +699 -0
- package/spec/mock-project/dist/src/ai/FlinkTool.js +2 -0
- package/spec/mock-project/dist/src/ai/InMemoryConversationAgent.js +209 -0
- package/spec/mock-project/dist/src/ai/LLMAdapter.js +2 -0
- package/spec/mock-project/dist/src/ai/SubAgentExecutor.js +223 -0
- package/spec/mock-project/dist/src/ai/ToolExecutor.js +412 -0
- package/spec/mock-project/dist/src/ai/agentInstructions.js +246 -0
- package/spec/mock-project/dist/src/auth/FlinkAuthPlugin.js +2 -0
- package/spec/mock-project/dist/src/auth/FlinkAuthUser.js +2 -0
- package/spec/mock-project/dist/src/handlers/GetCar.js +26 -52
- package/spec/mock-project/dist/src/handlers/GetCar.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCar2.js +32 -54
- package/spec/mock-project/dist/src/handlers/GetCar2.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema.js +26 -48
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema2.js +28 -48
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema2.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema3.js +29 -48
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema3.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema.js +26 -50
- package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema2.js +28 -50
- package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema2.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile.js +27 -53
- package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile2.js +29 -53
- package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile2.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler.js +16 -49
- package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler2.js +25 -50
- package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler2.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PatchCar.js +27 -53
- package/spec/mock-project/dist/src/handlers/PatchCar.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PatchOnboardingSession.js +44 -70
- package/spec/mock-project/dist/src/handlers/PatchOnboardingSession.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PatchOrderWithComplexTypes.js +27 -53
- package/spec/mock-project/dist/src/handlers/PatchOrderWithComplexTypes.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PatchProductWithIntersection.js +28 -54
- package/spec/mock-project/dist/src/handlers/PatchProductWithIntersection.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PatchUserWithUnion.js +28 -54
- package/spec/mock-project/dist/src/handlers/PatchUserWithUnion.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PostCar.js +24 -50
- package/spec/mock-project/dist/src/handlers/PostCar.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PostLogin.js +25 -51
- package/spec/mock-project/dist/src/handlers/PostLogin.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PostLogout.js +24 -50
- package/spec/mock-project/dist/src/handlers/PostLogout.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PutCar.js +24 -50
- package/spec/mock-project/dist/src/handlers/PutCar.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/StreamWriterFactory.js +83 -0
- package/spec/mock-project/dist/src/index.js +52 -76
- package/spec/mock-project/dist/src/index.js.map +1 -0
- package/spec/mock-project/dist/src/mock-data-generator.js +9 -0
- package/spec/mock-project/dist/src/repos/CarRepo.js +12 -24
- package/spec/mock-project/dist/src/repos/CarRepo.js.map +1 -0
- package/spec/mock-project/dist/src/schemas/Car.js +3 -1
- package/spec/mock-project/dist/src/schemas/Car.js.map +1 -0
- package/spec/mock-project/dist/src/schemas/DefaultExportSchema.js +3 -1
- package/spec/mock-project/dist/src/schemas/DefaultExportSchema.js.map +1 -0
- package/spec/mock-project/dist/src/schemas/FileWithTwoSchemas.js +3 -1
- package/spec/mock-project/dist/src/schemas/FileWithTwoSchemas.js.map +1 -0
- package/spec/mock-project/dist/src/utils.js +290 -0
- package/spec/mock-project/tsconfig.json +6 -1
- package/spec/schema-generation-nested-objects.spec.ts +97 -0
- package/spec/testHelpers.ts +49 -0
- package/spec/utils.caseConversion.spec.ts +78 -0
- package/spec/utils.spec.ts +13 -13
- package/src/DependencyTracker.ts +166 -0
- package/src/FlinkApp.ts +919 -155
- package/src/FlinkContext.ts +43 -0
- package/src/FlinkErrors.ts +32 -12
- package/src/FlinkHttpHandler.ts +246 -28
- package/src/FlinkJob.ts +11 -0
- package/src/FlinkLog.ts +119 -12
- package/src/FlinkLogFactory.ts +699 -0
- package/src/FlinkRepo.ts +10 -3
- package/src/FlinkRequestContext.ts +95 -0
- package/src/FlinkResponse.ts +6 -0
- package/src/FlinkService.ts +49 -0
- package/src/LeaderElection.ts +203 -0
- package/src/SchemaCache.ts +232 -0
- package/src/TypeScriptCompiler.ts +1347 -610
- package/src/TypeScriptUtils.ts +5 -0
- package/src/ai/AgentRunner.ts +646 -0
- package/src/ai/ConversationAgent.ts +413 -0
- package/src/ai/FlinkAgent.ts +1069 -0
- package/src/ai/FlinkTool.ts +165 -0
- package/src/ai/InMemoryConversationAgent.ts +149 -0
- package/src/ai/LLMAdapter.ts +126 -0
- package/src/ai/ToolExecutor.ts +485 -0
- package/src/ai/agentInstructions.ts +245 -0
- package/src/ai/index.ts +8 -0
- package/src/ai/instructionFileLoader.ts +156 -0
- package/src/auth/FlinkAuthPlugin.ts +2 -1
- package/src/handlers/StreamWriterFactory.ts +84 -0
- package/src/index.ts +14 -0
- package/src/loadPluginSchemas.ts +141 -0
- package/src/schema-extraction/TypeScriptSourceParser.ts +1058 -0
- package/src/schema-extraction/TypeScriptTokenizer.ts +205 -0
- package/src/schema-extraction/index.ts +2 -0
- package/src/schema-extraction/types.ts +34 -0
- package/src/utils/loadFlinkConfig.ts +89 -0
- package/src/utils.ts +52 -0
- package/tsconfig.json +6 -1
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.notFound = notFound;
|
|
4
|
+
exports.conflict = conflict;
|
|
5
|
+
exports.badRequest = badRequest;
|
|
6
|
+
exports.unauthorized = unauthorized;
|
|
7
|
+
exports.forbidden = forbidden;
|
|
8
|
+
exports.internalServerError = internalServerError;
|
|
9
|
+
var uuid_1 = require("uuid");
|
|
10
|
+
/**
|
|
11
|
+
* Returns a 404 Not Found error response.
|
|
12
|
+
* Use when a requested resource doesn't exist (e.g., invalid ID, missing entity).
|
|
13
|
+
*
|
|
14
|
+
* @param detail - Optional custom error message
|
|
15
|
+
* @param code - Optional custom error code
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* if (!user) return notFound("User not found");
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
function notFound(detail, code) {
|
|
22
|
+
return {
|
|
23
|
+
status: 404,
|
|
24
|
+
error: {
|
|
25
|
+
id: (0, uuid_1.v4)(),
|
|
26
|
+
title: "Not Found",
|
|
27
|
+
detail: detail || "The requested resource does not exist",
|
|
28
|
+
code: code || "notFound"
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Returns a 409 Conflict error response.
|
|
34
|
+
* Use when a request conflicts with existing data (e.g., duplicate username/email).
|
|
35
|
+
*
|
|
36
|
+
* @param detail - Optional custom error message
|
|
37
|
+
* @param code - Optional custom error code
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* if (existingUser) return conflict("Email already registered");
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
function conflict(detail, code) {
|
|
44
|
+
return {
|
|
45
|
+
status: 409,
|
|
46
|
+
error: {
|
|
47
|
+
id: (0, uuid_1.v4)(),
|
|
48
|
+
title: "Conflict",
|
|
49
|
+
detail: detail || "An identical entity exits",
|
|
50
|
+
code: code || "conflict"
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Returns a 400 Bad Request error response.
|
|
56
|
+
* Use when the request is malformed or contains invalid data (e.g., validation errors).
|
|
57
|
+
*
|
|
58
|
+
* @param detail - Optional custom error message
|
|
59
|
+
* @param code - Optional custom error code
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* if (!email || !password) return badRequest("Email and password are required");
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
function badRequest(detail, code) {
|
|
66
|
+
return {
|
|
67
|
+
status: 400,
|
|
68
|
+
error: {
|
|
69
|
+
id: (0, uuid_1.v4)(),
|
|
70
|
+
title: "Bad Request",
|
|
71
|
+
detail: detail || "Invalid request",
|
|
72
|
+
code: code || "badRequest"
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Returns a 401 Unauthorized error response.
|
|
78
|
+
* Use when authentication is required but missing or invalid (e.g., no token, expired token).
|
|
79
|
+
* This means "who are you?" - the user needs to identify themselves first.
|
|
80
|
+
*
|
|
81
|
+
* @param detail - Optional custom error message
|
|
82
|
+
* @param code - Optional custom error code
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* if (!ctx.auth?.user) return unauthorized("Authentication required");
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
function unauthorized(detail, code) {
|
|
89
|
+
return {
|
|
90
|
+
status: 401,
|
|
91
|
+
error: {
|
|
92
|
+
id: (0, uuid_1.v4)(),
|
|
93
|
+
title: "Unauthorized",
|
|
94
|
+
detail: detail || "Authentication required",
|
|
95
|
+
code: code || "unauthorized"
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Returns a 403 Forbidden error response.
|
|
101
|
+
* Use when the user is authenticated but lacks permission to access the resource.
|
|
102
|
+
* This means "I know who you are, but you're not allowed to do this."
|
|
103
|
+
*
|
|
104
|
+
* @param detail - Optional custom error message
|
|
105
|
+
* @param code - Optional custom error code
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* if (ctx.auth?.user?.role !== "admin") return forbidden("Admin access required");
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
function forbidden(detail, code) {
|
|
112
|
+
return {
|
|
113
|
+
status: 403,
|
|
114
|
+
error: {
|
|
115
|
+
id: (0, uuid_1.v4)(),
|
|
116
|
+
title: "Forbidden",
|
|
117
|
+
detail: detail || "You do not have permission to access this resource",
|
|
118
|
+
code: code || "forbidden"
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Returns a 500 Internal Server Error response.
|
|
124
|
+
* Use when an unexpected error occurs on the server side.
|
|
125
|
+
*
|
|
126
|
+
* @param detail - Optional custom error message
|
|
127
|
+
* @param code - Optional custom error code
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* try { ... } catch (error) { return internalServerError("Failed to process request"); }
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
function internalServerError(detail, code) {
|
|
134
|
+
return {
|
|
135
|
+
status: 500,
|
|
136
|
+
error: {
|
|
137
|
+
id: (0, uuid_1.v4)(),
|
|
138
|
+
title: "Internal Server Error",
|
|
139
|
+
detail: detail || "Something unexpected went wrong",
|
|
140
|
+
code: code || "internalServerError"
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidationMode = exports.HttpMethod = void 0;
|
|
4
|
+
var HttpMethod;
|
|
5
|
+
(function (HttpMethod) {
|
|
6
|
+
HttpMethod["get"] = "get";
|
|
7
|
+
HttpMethod["post"] = "post";
|
|
8
|
+
HttpMethod["put"] = "put";
|
|
9
|
+
HttpMethod["delete"] = "delete";
|
|
10
|
+
HttpMethod["patch"] = "patch";
|
|
11
|
+
})(HttpMethod || (exports.HttpMethod = HttpMethod = {}));
|
|
12
|
+
/**
|
|
13
|
+
* Validation mode for handler request and response schemas.
|
|
14
|
+
*
|
|
15
|
+
* Controls whether request and/or response data is validated against JSON schemas.
|
|
16
|
+
*
|
|
17
|
+
* **Security Note:** Skipping validation can introduce security risks. Only use
|
|
18
|
+
* SkipValidation or ValidateResponse when you have implemented custom validation
|
|
19
|
+
* or the endpoint is internal/trusted.
|
|
20
|
+
*
|
|
21
|
+
* - Validate: Validate both request and response (default behavior)
|
|
22
|
+
* - SkipValidation: Skip both request and response validation
|
|
23
|
+
* - ValidateRequest: Validate only request, skip response validation
|
|
24
|
+
* - ValidateResponse: Validate only response, skip request validation
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* // Skip validation for webhook with custom signature verification
|
|
29
|
+
* export const Route: RouteProps = {
|
|
30
|
+
* path: "/webhook",
|
|
31
|
+
* validation: ValidationMode.SkipValidation
|
|
32
|
+
* };
|
|
33
|
+
*
|
|
34
|
+
* // Validate request but allow flexible response during development
|
|
35
|
+
* export const Route: RouteProps = {
|
|
36
|
+
* path: "/api/data",
|
|
37
|
+
* validation: ValidationMode.ValidateRequest
|
|
38
|
+
* };
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
var ValidationMode;
|
|
42
|
+
(function (ValidationMode) {
|
|
43
|
+
ValidationMode["Validate"] = "Validate";
|
|
44
|
+
ValidationMode["SkipValidation"] = "SkipValidation";
|
|
45
|
+
ValidationMode["ValidateRequest"] = "ValidateRequest";
|
|
46
|
+
ValidationMode["ValidateResponse"] = "ValidateResponse";
|
|
47
|
+
})(ValidationMode || (exports.ValidationMode = ValidationMode = {}));
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.log = void 0;
|
|
16
|
+
var node_color_log_1 = __importDefault(require("node-color-log"));
|
|
17
|
+
var LOG_LEVELS = {
|
|
18
|
+
trace: 0,
|
|
19
|
+
debug: 1,
|
|
20
|
+
info: 2,
|
|
21
|
+
warn: 3,
|
|
22
|
+
error: 4,
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Current global log level for trace filtering
|
|
26
|
+
*/
|
|
27
|
+
var currentLogLevel = "info";
|
|
28
|
+
/**
|
|
29
|
+
* Check if a message should be logged based on current level
|
|
30
|
+
*/
|
|
31
|
+
function shouldLog(messageLevel) {
|
|
32
|
+
return LOG_LEVELS[messageLevel] >= LOG_LEVELS[currentLogLevel];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Flink logging utility with proper stdout/stderr separation
|
|
36
|
+
*
|
|
37
|
+
* Following Unix/POSIX best practices:
|
|
38
|
+
* - trace, debug, info → stdout (normal output)
|
|
39
|
+
* - warn, error → stderr (diagnostic output)
|
|
40
|
+
*
|
|
41
|
+
* Benefits:
|
|
42
|
+
* - Container orchestration can capture streams separately
|
|
43
|
+
* - Shell redirection works correctly (command > out.log 2> err.log)
|
|
44
|
+
* - Log aggregation tools can route differently
|
|
45
|
+
* - Monitoring systems can alert on stderr only
|
|
46
|
+
*
|
|
47
|
+
* Note: console.warn() and console.error() automatically write to stderr in Node.js
|
|
48
|
+
*/
|
|
49
|
+
exports.log = {
|
|
50
|
+
/**
|
|
51
|
+
* Trace logs (stdout)
|
|
52
|
+
* Use for extremely detailed diagnostic information (most verbose level)
|
|
53
|
+
*/
|
|
54
|
+
trace: function () {
|
|
55
|
+
var args = [];
|
|
56
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
57
|
+
args[_i] = arguments[_i];
|
|
58
|
+
}
|
|
59
|
+
if (shouldLog("trace")) {
|
|
60
|
+
var timestamp = new Date().toISOString();
|
|
61
|
+
console.log.apply(console, __spreadArray(["".concat(timestamp, " [TRACE]")], args, false));
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
/**
|
|
65
|
+
* Debug logs (stdout)
|
|
66
|
+
* Use for detailed diagnostic information during development
|
|
67
|
+
*/
|
|
68
|
+
debug: node_color_log_1.default.debug.bind(node_color_log_1.default),
|
|
69
|
+
/**
|
|
70
|
+
* Info logs (stdout)
|
|
71
|
+
* Use for general informational messages about application state
|
|
72
|
+
*/
|
|
73
|
+
info: node_color_log_1.default.info.bind(node_color_log_1.default),
|
|
74
|
+
/**
|
|
75
|
+
* Warning logs (stderr)
|
|
76
|
+
* Use for potentially harmful situations that aren't errors
|
|
77
|
+
* Writes to stderr following Unix/POSIX best practices
|
|
78
|
+
*/
|
|
79
|
+
warn: node_color_log_1.default.warn.bind(node_color_log_1.default),
|
|
80
|
+
/**
|
|
81
|
+
* Error logs (stderr)
|
|
82
|
+
* Use for error events that might still allow the app to continue
|
|
83
|
+
* Writes to stderr following Unix/POSIX best practices
|
|
84
|
+
*/
|
|
85
|
+
error: node_color_log_1.default.error.bind(node_color_log_1.default),
|
|
86
|
+
/**
|
|
87
|
+
* JSON output (stdout)
|
|
88
|
+
* Use for structured data output
|
|
89
|
+
*/
|
|
90
|
+
json: function () {
|
|
91
|
+
var args = [];
|
|
92
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
93
|
+
args[_i] = arguments[_i];
|
|
94
|
+
}
|
|
95
|
+
for (var _a = 0, args_1 = args; _a < args_1.length; _a++) {
|
|
96
|
+
var o = args_1[_a];
|
|
97
|
+
console.log(JSON.stringify(o, null, 2));
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
/**
|
|
101
|
+
* Colored background log (stdout)
|
|
102
|
+
* Use for highlighted messages during development
|
|
103
|
+
*/
|
|
104
|
+
bgColorLog: node_color_log_1.default.bgColorLog.bind(node_color_log_1.default),
|
|
105
|
+
/**
|
|
106
|
+
* Colored font log (stdout)
|
|
107
|
+
* Use for colored messages during development
|
|
108
|
+
*/
|
|
109
|
+
fontColorLog: node_color_log_1.default.fontColorLog.bind(node_color_log_1.default),
|
|
110
|
+
/**
|
|
111
|
+
* Set global log level
|
|
112
|
+
*/
|
|
113
|
+
setLevel: function (level) {
|
|
114
|
+
currentLogLevel = level;
|
|
115
|
+
// node-color-log doesn't support trace, so use debug as the effective level
|
|
116
|
+
var effectiveLevel = level === "trace" ? "debug" : level;
|
|
117
|
+
node_color_log_1.default.setLevel(effectiveLevel);
|
|
118
|
+
},
|
|
119
|
+
};
|