@forklaunch/core 0.2.36 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. package/lib/{src/database/mikro/models/entities/base.entity.d.ts → base.entity-DNfmMOgd.d.mts} +3 -2
  2. package/lib/base.entity-DNfmMOgd.d.ts +27 -0
  3. package/lib/{src/cache/redisTtlCache.d.ts → cache/index.d.mts} +67 -4
  4. package/lib/cache/index.d.ts +130 -0
  5. package/lib/cache/index.js +133 -0
  6. package/lib/cache/index.mjs +105 -0
  7. package/lib/controllers/index.d.mts +5 -0
  8. package/lib/controllers/index.d.ts +5 -0
  9. package/lib/controllers/index.js +18 -0
  10. package/lib/controllers/index.mjs +0 -0
  11. package/lib/database/index.d.mts +37 -0
  12. package/lib/{src/database/mikro/models/entities/mongo.base.entity.d.ts → database/index.d.ts} +5 -2
  13. package/lib/database/index.js +78 -0
  14. package/lib/database/index.mjs +53 -0
  15. package/lib/dtoMapper/index.d.mts +215 -0
  16. package/lib/dtoMapper/index.d.ts +215 -0
  17. package/lib/dtoMapper/index.js +230 -0
  18. package/lib/dtoMapper/index.mjs +202 -0
  19. package/lib/http/index.d.mts +910 -0
  20. package/lib/http/index.d.ts +910 -0
  21. package/lib/http/index.js +2181 -0
  22. package/lib/http/index.mjs +2122 -0
  23. package/lib/services/index.d.mts +64 -0
  24. package/lib/services/index.d.ts +64 -0
  25. package/lib/services/index.js +159 -0
  26. package/lib/services/index.mjs +131 -0
  27. package/package.json +39 -26
  28. package/lib/src/cache/index.d.ts +0 -5
  29. package/lib/src/cache/index.d.ts.map +0 -1
  30. package/lib/src/cache/index.js +0 -4
  31. package/lib/src/cache/interfaces/ttlCache.interface.d.ts +0 -48
  32. package/lib/src/cache/interfaces/ttlCache.interface.d.ts.map +0 -1
  33. package/lib/src/cache/interfaces/ttlCache.interface.js +0 -1
  34. package/lib/src/cache/redisTtlCache.d.ts.map +0 -1
  35. package/lib/src/cache/redisTtlCache.js +0 -98
  36. package/lib/src/cache/types/ttlCacheRecord.types.d.ts +0 -14
  37. package/lib/src/cache/types/ttlCacheRecord.types.d.ts.map +0 -1
  38. package/lib/src/cache/types/ttlCacheRecord.types.js +0 -1
  39. package/lib/src/cache/utils/cacheKey.d.ts +0 -2
  40. package/lib/src/cache/utils/cacheKey.d.ts.map +0 -1
  41. package/lib/src/cache/utils/cacheKey.js +0 -3
  42. package/lib/src/controllers/index.d.ts +0 -2
  43. package/lib/src/controllers/index.d.ts.map +0 -1
  44. package/lib/src/controllers/index.js +0 -1
  45. package/lib/src/controllers/interfaces/controller.interface.d.ts +0 -4
  46. package/lib/src/controllers/interfaces/controller.interface.d.ts.map +0 -1
  47. package/lib/src/controllers/interfaces/controller.interface.js +0 -1
  48. package/lib/src/database/index.d.ts +0 -3
  49. package/lib/src/database/index.d.ts.map +0 -1
  50. package/lib/src/database/index.js +0 -2
  51. package/lib/src/database/mikro/models/entities/base.entity.d.ts.map +0 -1
  52. package/lib/src/database/mikro/models/entities/base.entity.js +0 -42
  53. package/lib/src/database/mikro/models/entities/mongo.base.entity.d.ts.map +0 -1
  54. package/lib/src/database/mikro/models/entities/mongo.base.entity.js +0 -51
  55. package/lib/src/dtoMapper/index.d.ts +0 -3
  56. package/lib/src/dtoMapper/index.d.ts.map +0 -1
  57. package/lib/src/dtoMapper/index.js +0 -2
  58. package/lib/src/dtoMapper/interfaces/dtoMapper.interface.d.ts +0 -18
  59. package/lib/src/dtoMapper/interfaces/dtoMapper.interface.d.ts.map +0 -1
  60. package/lib/src/dtoMapper/interfaces/dtoMapper.interface.js +0 -1
  61. package/lib/src/dtoMapper/models/baseDtoMapper.model.d.ts +0 -72
  62. package/lib/src/dtoMapper/models/baseDtoMapper.model.d.ts.map +0 -1
  63. package/lib/src/dtoMapper/models/baseDtoMapper.model.js +0 -76
  64. package/lib/src/dtoMapper/models/requestDtoMapper.model.d.ts +0 -68
  65. package/lib/src/dtoMapper/models/requestDtoMapper.model.d.ts.map +0 -1
  66. package/lib/src/dtoMapper/models/requestDtoMapper.model.js +0 -71
  67. package/lib/src/dtoMapper/models/responseDtoMapper.model.d.ts +0 -67
  68. package/lib/src/dtoMapper/models/responseDtoMapper.model.d.ts.map +0 -1
  69. package/lib/src/dtoMapper/models/responseDtoMapper.model.js +0 -68
  70. package/lib/src/dtoMapper/types/dtoMapper.types.d.ts +0 -9
  71. package/lib/src/dtoMapper/types/dtoMapper.types.d.ts.map +0 -1
  72. package/lib/src/dtoMapper/types/dtoMapper.types.js +0 -1
  73. package/lib/src/http/application/expressLikeApplication.d.ts +0 -21
  74. package/lib/src/http/application/expressLikeApplication.d.ts.map +0 -1
  75. package/lib/src/http/application/expressLikeApplication.js +0 -21
  76. package/lib/src/http/guards/isConstrainedForklaunchRouter.d.ts +0 -4
  77. package/lib/src/http/guards/isConstrainedForklaunchRouter.d.ts.map +0 -1
  78. package/lib/src/http/guards/isConstrainedForklaunchRouter.js +0 -5
  79. package/lib/src/http/guards/isExpressLikeSchemaHandler.d.ts +0 -5
  80. package/lib/src/http/guards/isExpressLikeSchemaHandler.d.ts.map +0 -1
  81. package/lib/src/http/guards/isExpressLikeSchemaHandler.js +0 -6
  82. package/lib/src/http/guards/isForklaunchExpressLikeRouter.d.ts +0 -5
  83. package/lib/src/http/guards/isForklaunchExpressLikeRouter.d.ts.map +0 -1
  84. package/lib/src/http/guards/isForklaunchExpressLikeRouter.js +0 -6
  85. package/lib/src/http/guards/isForklaunchRouter.d.ts +0 -4
  86. package/lib/src/http/guards/isForklaunchRouter.d.ts.map +0 -1
  87. package/lib/src/http/guards/isForklaunchRouter.js +0 -7
  88. package/lib/src/http/guards/isHttpContractDetails.d.ts +0 -7
  89. package/lib/src/http/guards/isHttpContractDetails.d.ts.map +0 -1
  90. package/lib/src/http/guards/isHttpContractDetails.js +0 -9
  91. package/lib/src/http/guards/isPathParamContractDetails.d.ts +0 -4
  92. package/lib/src/http/guards/isPathParamContractDetails.d.ts.map +0 -1
  93. package/lib/src/http/guards/isPathParamContractDetails.js +0 -10
  94. package/lib/src/http/guards/isResponseShape.d.ts +0 -3
  95. package/lib/src/http/guards/isResponseShape.d.ts.map +0 -1
  96. package/lib/src/http/guards/isResponseShape.js +0 -7
  97. package/lib/src/http/guards/isTypedHandler.d.ts +0 -5
  98. package/lib/src/http/guards/isTypedHandler.d.ts.map +0 -1
  99. package/lib/src/http/guards/isTypedHandler.js +0 -6
  100. package/lib/src/http/handlers/delete.d.ts +0 -9
  101. package/lib/src/http/handlers/delete.d.ts.map +0 -1
  102. package/lib/src/http/handlers/delete.js +0 -4
  103. package/lib/src/http/handlers/get.d.ts +0 -9
  104. package/lib/src/http/handlers/get.d.ts.map +0 -1
  105. package/lib/src/http/handlers/get.js +0 -4
  106. package/lib/src/http/handlers/head.d.ts +0 -9
  107. package/lib/src/http/handlers/head.d.ts.map +0 -1
  108. package/lib/src/http/handlers/head.js +0 -4
  109. package/lib/src/http/handlers/middleware.d.ts +0 -9
  110. package/lib/src/http/handlers/middleware.d.ts.map +0 -1
  111. package/lib/src/http/handlers/middleware.js +0 -4
  112. package/lib/src/http/handlers/options.d.ts +0 -9
  113. package/lib/src/http/handlers/options.d.ts.map +0 -1
  114. package/lib/src/http/handlers/options.js +0 -4
  115. package/lib/src/http/handlers/patch.d.ts +0 -9
  116. package/lib/src/http/handlers/patch.d.ts.map +0 -1
  117. package/lib/src/http/handlers/patch.js +0 -4
  118. package/lib/src/http/handlers/post.d.ts +0 -9
  119. package/lib/src/http/handlers/post.d.ts.map +0 -1
  120. package/lib/src/http/handlers/post.js +0 -4
  121. package/lib/src/http/handlers/put.d.ts +0 -9
  122. package/lib/src/http/handlers/put.d.ts.map +0 -1
  123. package/lib/src/http/handlers/put.js +0 -4
  124. package/lib/src/http/handlers/trace.d.ts +0 -9
  125. package/lib/src/http/handlers/trace.d.ts.map +0 -1
  126. package/lib/src/http/handlers/trace.js +0 -4
  127. package/lib/src/http/handlers/typedAuthHandler.d.ts +0 -5
  128. package/lib/src/http/handlers/typedAuthHandler.d.ts.map +0 -1
  129. package/lib/src/http/handlers/typedAuthHandler.js +0 -3
  130. package/lib/src/http/handlers/typedHandler.d.ts +0 -21
  131. package/lib/src/http/handlers/typedHandler.d.ts.map +0 -1
  132. package/lib/src/http/handlers/typedHandler.js +0 -30
  133. package/lib/src/http/index.d.ts +0 -23
  134. package/lib/src/http/index.d.ts.map +0 -1
  135. package/lib/src/http/index.js +0 -22
  136. package/lib/src/http/interfaces/expressLikeRouter.interface.d.ts +0 -24
  137. package/lib/src/http/interfaces/expressLikeRouter.interface.d.ts.map +0 -1
  138. package/lib/src/http/interfaces/expressLikeRouter.interface.js +0 -1
  139. package/lib/src/http/middleware/request/auth.middleware.d.ts +0 -16
  140. package/lib/src/http/middleware/request/auth.middleware.d.ts.map +0 -1
  141. package/lib/src/http/middleware/request/auth.middleware.js +0 -143
  142. package/lib/src/http/middleware/request/cors.middleware.d.ts +0 -13
  143. package/lib/src/http/middleware/request/cors.middleware.d.ts.map +0 -1
  144. package/lib/src/http/middleware/request/cors.middleware.js +0 -15
  145. package/lib/src/http/middleware/request/createContext.middleware.d.ts +0 -15
  146. package/lib/src/http/middleware/request/createContext.middleware.d.ts.map +0 -1
  147. package/lib/src/http/middleware/request/createContext.middleware.js +0 -26
  148. package/lib/src/http/middleware/request/enrichDetails.middleware.d.ts +0 -15
  149. package/lib/src/http/middleware/request/enrichDetails.middleware.d.ts.map +0 -1
  150. package/lib/src/http/middleware/request/enrichDetails.middleware.js +0 -19
  151. package/lib/src/http/middleware/request/parse.middleware.d.ts +0 -17
  152. package/lib/src/http/middleware/request/parse.middleware.d.ts.map +0 -1
  153. package/lib/src/http/middleware/request/parse.middleware.js +0 -43
  154. package/lib/src/http/middleware/response/parse.middleware.d.ts +0 -31
  155. package/lib/src/http/middleware/response/parse.middleware.d.ts.map +0 -1
  156. package/lib/src/http/middleware/response/parse.middleware.js +0 -52
  157. package/lib/src/http/openApiV3Generator/openApiV3Generator.d.ts +0 -14
  158. package/lib/src/http/openApiV3Generator/openApiV3Generator.d.ts.map +0 -1
  159. package/lib/src/http/openApiV3Generator/openApiV3Generator.js +0 -169
  160. package/lib/src/http/router/expressLikeRouter.d.ts +0 -138
  161. package/lib/src/http/router/expressLikeRouter.d.ts.map +0 -1
  162. package/lib/src/http/router/expressLikeRouter.js +0 -483
  163. package/lib/src/http/types/apiDefinition.types.d.ts +0 -260
  164. package/lib/src/http/types/apiDefinition.types.d.ts.map +0 -1
  165. package/lib/src/http/types/apiDefinition.types.js +0 -1
  166. package/lib/src/http/types/contractDetails.types.d.ts +0 -211
  167. package/lib/src/http/types/contractDetails.types.d.ts.map +0 -1
  168. package/lib/src/http/types/contractDetails.types.js +0 -1
  169. package/lib/src/http/types/expressLikeRouter.types.d.ts +0 -51
  170. package/lib/src/http/types/expressLikeRouter.types.d.ts.map +0 -1
  171. package/lib/src/http/types/expressLikeRouter.types.js +0 -1
  172. package/lib/src/http/types/router.types.d.ts +0 -32
  173. package/lib/src/http/types/router.types.d.ts.map +0 -1
  174. package/lib/src/http/types/router.types.js +0 -1
  175. package/lib/src/http/types/typedHandler.types.d.ts +0 -10
  176. package/lib/src/http/types/typedHandler.types.d.ts.map +0 -1
  177. package/lib/src/http/types/typedHandler.types.js +0 -1
  178. package/lib/src/http/utils/enrichExpressLikeSend.d.ts +0 -32
  179. package/lib/src/http/utils/enrichExpressLikeSend.d.ts.map +0 -1
  180. package/lib/src/http/utils/enrichExpressLikeSend.js +0 -50
  181. package/lib/src/http/utils/httpStatusCodes.d.ts +0 -75
  182. package/lib/src/http/utils/httpStatusCodes.d.ts.map +0 -1
  183. package/lib/src/http/utils/httpStatusCodes.js +0 -1039
  184. package/lib/src/services/configInjector.d.ts +0 -21
  185. package/lib/src/services/configInjector.d.ts.map +0 -1
  186. package/lib/src/services/configInjector.js +0 -90
  187. package/lib/src/services/index.d.ts +0 -5
  188. package/lib/src/services/index.d.ts.map +0 -1
  189. package/lib/src/services/index.js +0 -4
  190. package/lib/src/services/interfaces/baseService.d.ts +0 -15
  191. package/lib/src/services/interfaces/baseService.d.ts.map +0 -1
  192. package/lib/src/services/interfaces/baseService.js +0 -1
  193. package/lib/src/services/types/configInjector.types.d.ts +0 -25
  194. package/lib/src/services/types/configInjector.types.d.ts.map +0 -1
  195. package/lib/src/services/types/configInjector.types.js +0 -6
  196. package/lib/src/services/types/entityManager.types.d.ts +0 -4
  197. package/lib/src/services/types/entityManager.types.d.ts.map +0 -1
  198. package/lib/src/services/types/entityManager.types.js +0 -1
  199. package/lib/tests/configInjector.test.d.ts +0 -2
  200. package/lib/tests/configInjector.test.d.ts.map +0 -1
  201. package/lib/tests/configInjector.test.js +0 -105
  202. package/lib/tests/dtoMapper.test.d.ts +0 -2
  203. package/lib/tests/dtoMapper.test.d.ts.map +0 -1
  204. package/lib/tests/dtoMapper.test.js +0 -170
  205. package/lib/tests/expressLikeRouterInstantiation.test.d.ts +0 -2
  206. package/lib/tests/expressLikeRouterInstantiation.test.d.ts.map +0 -1
  207. package/lib/tests/expressLikeRouterInstantiation.test.js +0 -118
  208. package/lib/tests/http.middleware.test.d.ts +0 -2
  209. package/lib/tests/http.middleware.test.d.ts.map +0 -1
  210. package/lib/tests/http.middleware.test.js +0 -102
  211. package/lib/tests/openApiV3Generator.test.d.ts +0 -2
  212. package/lib/tests/openApiV3Generator.test.d.ts.map +0 -1
  213. package/lib/tests/openApiV3Generator.test.js +0 -66
  214. package/lib/tests/redisTtlCache.test.d.ts +0 -2
  215. package/lib/tests/redisTtlCache.test.d.ts.map +0 -1
  216. package/lib/tests/redisTtlCache.test.js +0 -49
  217. package/lib/tests/typedHandler.test.d.ts +0 -2
  218. package/lib/tests/typedHandler.test.d.ts.map +0 -1
  219. package/lib/tests/typedHandler.test.js +0 -3
  220. package/lib/vitest.config.d.ts +0 -3
  221. package/lib/vitest.config.d.ts.map +0 -1
  222. package/lib/vitest.config.js +0 -7
@@ -0,0 +1,2181 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/http/index.ts
31
+ var http_exports = {};
32
+ __export(http_exports, {
33
+ ForklaunchExpressLikeApplication: () => ForklaunchExpressLikeApplication,
34
+ ForklaunchExpressLikeRouter: () => ForklaunchExpressLikeRouter,
35
+ HTTPStatuses: () => HTTPStatuses,
36
+ delete_: () => delete_,
37
+ enrichExpressLikeSend: () => enrichExpressLikeSend,
38
+ generateSwaggerDocument: () => generateSwaggerDocument,
39
+ get: () => get,
40
+ getCodeForStatus: () => getCodeForStatus,
41
+ head: () => head,
42
+ isClientError: () => isClientError,
43
+ isForklaunchRouter: () => isForklaunchRouter,
44
+ isInformational: () => isInformational,
45
+ isRedirection: () => isRedirection,
46
+ isServerError: () => isServerError,
47
+ isSuccessful: () => isSuccessful,
48
+ isValidStatusCode: () => isValidStatusCode,
49
+ middleware: () => middleware,
50
+ options: () => options,
51
+ patch: () => patch,
52
+ post: () => post,
53
+ put: () => put,
54
+ trace: () => trace,
55
+ typedHandler: () => typedHandler
56
+ });
57
+ module.exports = __toCommonJS(http_exports);
58
+
59
+ // src/http/guards/isForklaunchRouter.ts
60
+ function isForklaunchRouter(maybeForklaunchRouter) {
61
+ return maybeForklaunchRouter != null && typeof maybeForklaunchRouter === "object" && "basePath" in maybeForklaunchRouter && "routes" in maybeForklaunchRouter && Array.isArray(maybeForklaunchRouter.routes);
62
+ }
63
+
64
+ // src/http/guards/isConstrainedForklaunchRouter.ts
65
+ function isConstrainedForklaunchRouter(maybeForklaunchExpressLikeRouter) {
66
+ return isForklaunchRouter(maybeForklaunchExpressLikeRouter) && "requestHandler" in maybeForklaunchExpressLikeRouter;
67
+ }
68
+
69
+ // src/http/guards/isExpressLikeSchemaHandler.ts
70
+ var import_common = require("@forklaunch/common");
71
+ function isExpressLikeSchemaHandler(middleware2) {
72
+ const extractedArgumentNames = typeof middleware2 === "function" && new Set(
73
+ (0, import_common.extractArgumentNames)(middleware2).map(
74
+ (argumentName) => argumentName.toLowerCase()
75
+ )
76
+ );
77
+ return extractedArgumentNames && extractedArgumentNames.size <= 3;
78
+ }
79
+
80
+ // src/http/guards/isForklaunchExpressLikeRouter.ts
81
+ function isForklaunchExpressLikeRouter(maybeForklaunchExpressLikeRouter) {
82
+ return isConstrainedForklaunchRouter(
83
+ maybeForklaunchExpressLikeRouter
84
+ ) && "basePath" in maybeForklaunchExpressLikeRouter && "internal" in maybeForklaunchExpressLikeRouter;
85
+ }
86
+
87
+ // src/http/guards/isPathParamContractDetails.ts
88
+ function isPathParamHttpContractDetails(maybePathParamHttpContractDetails) {
89
+ return maybePathParamHttpContractDetails != null && typeof maybePathParamHttpContractDetails === "object" && "name" in maybePathParamHttpContractDetails && "summary" in maybePathParamHttpContractDetails && "responses" in maybePathParamHttpContractDetails && maybePathParamHttpContractDetails.name != null && maybePathParamHttpContractDetails.summary != null && maybePathParamHttpContractDetails.responses != null;
90
+ }
91
+
92
+ // src/http/guards/isHttpContractDetails.ts
93
+ function isHttpContractDetails(maybeContractDetails) {
94
+ return isPathParamHttpContractDetails(maybeContractDetails) && "body" in maybeContractDetails && maybeContractDetails.body != null;
95
+ }
96
+
97
+ // src/http/guards/isTypedHandler.ts
98
+ function isTypedHandler(maybeTypedHandler) {
99
+ return maybeTypedHandler != null && typeof maybeTypedHandler === "object" && "_typedHandler" in maybeTypedHandler && maybeTypedHandler._typedHandler === true;
100
+ }
101
+
102
+ // src/http/middleware/request/auth.middleware.ts
103
+ var import_jose = require("jose");
104
+ var invalidAuthorizationTokenFormat = [
105
+ 401,
106
+ "Invalid Authorization token format."
107
+ ];
108
+ var invalidAuthorizationSubject = [
109
+ 403,
110
+ "Invalid Authorization subject."
111
+ ];
112
+ var invalidAuthorizationTokenPermissions = [
113
+ 403,
114
+ "Invalid Authorization permissions."
115
+ ];
116
+ var invalidAuthorizationTokenRoles = [
117
+ 403,
118
+ "Invalid Authorization roles."
119
+ ];
120
+ var invalidAuthorizationToken = [
121
+ 403,
122
+ "Invalid Authorization token."
123
+ ];
124
+ var invalidAuthorizationLogin = [
125
+ 403,
126
+ "Invalid Authorization login."
127
+ ];
128
+ async function checkAuthorizationToken(authorizationMethod, authorizationToken, req) {
129
+ if (authorizationToken == null) {
130
+ return [401, "No Authorization token provided."];
131
+ }
132
+ const [tokenPrefix, token] = authorizationToken.split(" ");
133
+ let resourceId;
134
+ switch (authorizationMethod.method) {
135
+ case "jwt": {
136
+ if (tokenPrefix !== "Bearer") {
137
+ return invalidAuthorizationTokenFormat;
138
+ }
139
+ try {
140
+ const decodedJwt = await (0, import_jose.jwtVerify)(
141
+ token,
142
+ new TextEncoder().encode(
143
+ // TODO: Check this at application startup if there is any route with jwt checking
144
+ process.env.JWT_SECRET
145
+ )
146
+ );
147
+ if (!decodedJwt.payload.sub) {
148
+ return invalidAuthorizationSubject;
149
+ }
150
+ resourceId = decodedJwt.payload.sub;
151
+ } catch (error) {
152
+ console.error(error);
153
+ return invalidAuthorizationToken;
154
+ }
155
+ break;
156
+ }
157
+ case "basic": {
158
+ if (authorizationToken !== "Basic") {
159
+ return invalidAuthorizationTokenFormat;
160
+ }
161
+ const [username, password] = Buffer.from(token, "base64").toString("utf-8").split(":");
162
+ if (!username || !password) {
163
+ return invalidAuthorizationTokenFormat;
164
+ }
165
+ if (!authorizationMethod.login(username, password)) {
166
+ return invalidAuthorizationLogin;
167
+ }
168
+ resourceId = username;
169
+ break;
170
+ }
171
+ case "other":
172
+ if (tokenPrefix !== authorizationMethod.tokenPrefix) {
173
+ return invalidAuthorizationTokenFormat;
174
+ }
175
+ resourceId = authorizationMethod.decodeResource(token);
176
+ break;
177
+ }
178
+ if (authorizationMethod.allowedPermissions || authorizationMethod.forbiddenPermissions) {
179
+ if (!authorizationMethod.mapPermissions) {
180
+ return [500, "No permission mapping function provided."];
181
+ }
182
+ const resourcePermissions = await authorizationMethod.mapPermissions(
183
+ resourceId,
184
+ req
185
+ );
186
+ if (authorizationMethod.allowedPermissions) {
187
+ if (resourcePermissions.intersection(authorizationMethod.allowedPermissions).size === 0) {
188
+ return invalidAuthorizationTokenPermissions;
189
+ }
190
+ }
191
+ if (authorizationMethod.forbiddenPermissions) {
192
+ if (resourcePermissions.intersection(
193
+ authorizationMethod.forbiddenPermissions
194
+ ).size !== 0) {
195
+ return invalidAuthorizationTokenPermissions;
196
+ }
197
+ }
198
+ }
199
+ if (authorizationMethod.allowedRoles || authorizationMethod.forbiddenRoles) {
200
+ if (!authorizationMethod.mapRoles) {
201
+ return [500, "No role mapping function provided."];
202
+ }
203
+ const resourceRoles = await authorizationMethod.mapRoles(resourceId, req);
204
+ if (authorizationMethod.allowedRoles) {
205
+ if (resourceRoles.intersection(authorizationMethod.allowedRoles).size === 0) {
206
+ return invalidAuthorizationTokenRoles;
207
+ }
208
+ }
209
+ if (authorizationMethod.forbiddenRoles) {
210
+ if (resourceRoles.intersection(authorizationMethod.forbiddenRoles).size !== 0) {
211
+ return invalidAuthorizationTokenRoles;
212
+ }
213
+ }
214
+ }
215
+ return [401, "Invalid Authorization method."];
216
+ }
217
+ async function parseRequestAuth(req, res, next) {
218
+ console.debug("[MIDDLEWARE] parseRequest started");
219
+ const auth = req.contractDetails.auth;
220
+ if (auth) {
221
+ const errorAndMessage = await checkAuthorizationToken(
222
+ auth,
223
+ req.headers[(auth.method === "other" ? auth.headerName : void 0) ?? "Authorization"],
224
+ req
225
+ );
226
+ if (Array.isArray(errorAndMessage)) {
227
+ res.status(errorAndMessage[0]).send(errorAndMessage[1]);
228
+ next?.(new Error(errorAndMessage[1]));
229
+ }
230
+ }
231
+ next?.();
232
+ }
233
+
234
+ // src/http/middleware/request/cors.middleware.ts
235
+ var import_cors = __toESM(require("cors"));
236
+ function cors(req, res, next) {
237
+ console.debug("[MIDDLEWARE] cors started");
238
+ if (req.method === "OPTIONS") {
239
+ res.cors = true;
240
+ }
241
+ (0, import_cors.default)()(req, res, next ?? (() => {
242
+ }));
243
+ }
244
+
245
+ // src/http/middleware/request/createContext.middleware.ts
246
+ var import_uuid = require("uuid");
247
+ function createContext(schemaValidator) {
248
+ return (req, res, next) => {
249
+ console.debug("[MIDDLEWARE] createRequestContext started");
250
+ req.schemaValidator = schemaValidator;
251
+ let correlationId = (0, import_uuid.v4)();
252
+ if (req.headers["x-correlation-id"]) {
253
+ correlationId = req.headers["x-correlation-id"];
254
+ }
255
+ res.setHeader("x-correlation-id", correlationId);
256
+ req.context = {
257
+ correlationId
258
+ };
259
+ next?.();
260
+ };
261
+ }
262
+
263
+ // src/http/middleware/request/enrichDetails.middleware.ts
264
+ function enrichDetails(contractDetails, requestSchema, responseSchemas) {
265
+ return (req, res, next) => {
266
+ console.debug("[MIDDLEWARE] enrichRequestDetails started");
267
+ req.contractDetails = contractDetails;
268
+ req.requestSchema = requestSchema;
269
+ res.responseSchemas = responseSchemas;
270
+ next?.();
271
+ };
272
+ }
273
+
274
+ // src/http/guards/isResponseShape.ts
275
+ function isResponseShape(maybeResponseShape) {
276
+ return maybeResponseShape != null && "body" in maybeResponseShape && "query" in maybeResponseShape && "params" in maybeResponseShape && "headers" in maybeResponseShape;
277
+ }
278
+
279
+ // src/http/middleware/request/parse.middleware.ts
280
+ function parse(req, _res, next) {
281
+ console.debug("[MIDDLEWARE] parseRequest started");
282
+ const request = {
283
+ params: req.params,
284
+ query: req.query,
285
+ headers: req.headers,
286
+ body: req.body
287
+ };
288
+ const parsedRequest = req.schemaValidator.parse(req.requestSchema, request);
289
+ if (parsedRequest.ok && isResponseShape(parsedRequest.value)) {
290
+ req.body = parsedRequest.value.body;
291
+ req.params = parsedRequest.value.params;
292
+ req.query = parsedRequest.value.query;
293
+ req.headers = parsedRequest.value.headers;
294
+ }
295
+ if (!parsedRequest.ok) {
296
+ switch (req.contractDetails.options?.requestValidation) {
297
+ default:
298
+ case "error":
299
+ next?.(new Error(`Invalid request: ${parsedRequest.error}`));
300
+ break;
301
+ case "warning":
302
+ console.warn(`Invalid request: ${parsedRequest.error}`);
303
+ break;
304
+ case "none":
305
+ break;
306
+ }
307
+ }
308
+ next?.();
309
+ }
310
+
311
+ // src/http/router/expressLikeRouter.ts
312
+ var ForklaunchExpressLikeRouter = class {
313
+ constructor(basePath, schemaValidator, internal) {
314
+ this.schemaValidator = schemaValidator;
315
+ this.internal = internal;
316
+ this.basePath = basePath;
317
+ this.internal.use(createContext(this.schemaValidator));
318
+ this.internal.use(cors);
319
+ }
320
+ requestHandler;
321
+ routers = [];
322
+ routes = [];
323
+ basePath;
324
+ /**
325
+ * Resolves middlewares based on the contract details.
326
+ *
327
+ * @param {PathParamHttpContractDetails<SV> | HttpContractDetails<SV>} contractDetails - The contract details.
328
+ * @returns {MiddlewareHandler<SV>[]} - The resolved middlewares.
329
+ */
330
+ #resolveMiddlewares(contractDetails, requestSchema, responseSchemas) {
331
+ return [
332
+ enrichDetails(contractDetails, requestSchema, responseSchemas),
333
+ parse,
334
+ parseRequestAuth
335
+ ];
336
+ }
337
+ /**
338
+ * Parses and runs the controller handler with error handling.
339
+ *
340
+ * @template P - The type of request parameters.
341
+ * @template ResBodyMap - The type of response body.
342
+ * @template ReqBody - The type of request body.
343
+ * @template ReqQuery - The type of request query.
344
+ * @template LocalsObj - The type of local variables.
345
+ * @template StatusCode - The type of status code.
346
+ * @param {MiddlewareHandler<SV, P, ResBodyMap | string, ReqBody, ReqQuery, LocalsObj, StatusCode>} requestHandler - The request handler.
347
+ * @returns {ExpressMiddlewareHandler} - The Express request handler.
348
+ */
349
+ #parseAndRunControllerHandler(requestHandler) {
350
+ return async (req, res, next) => {
351
+ if (!requestHandler) {
352
+ throw new Error("Controller handler is not defined");
353
+ }
354
+ try {
355
+ await requestHandler(req, res, next);
356
+ } catch (error) {
357
+ next?.(error);
358
+ console.error(error);
359
+ if (!res.headersSent) {
360
+ res.status(500).send("Internal Server Error");
361
+ }
362
+ }
363
+ };
364
+ }
365
+ /**
366
+ * Extracts the controller handler from the provided handlers.
367
+ *
368
+ * @template P - The type of request parameters.
369
+ * @template ResBodyMap - The type of response body.
370
+ * @template ReqBody - The type of request body.
371
+ * @template ReqQuery - The type of request query.
372
+ * @template LocalsObj - The type of local variables.
373
+ * @param {MiddlewareHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>[]} handlers - The provided handlers.
374
+ * @returns {MiddlewareHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>} - The extracted controller handler.
375
+ * @throws {Error} - Throws an error if the last argument is not a handler.
376
+ */
377
+ #extractControllerHandler(handlers) {
378
+ const controllerHandler = handlers.pop();
379
+ if (typeof controllerHandler !== "function") {
380
+ throw new Error(
381
+ `Last argument must be a handler, received: ${controllerHandler}`
382
+ );
383
+ }
384
+ return controllerHandler;
385
+ }
386
+ #compile(contractDetails) {
387
+ const schemaValidator = this.schemaValidator;
388
+ const requestSchema = schemaValidator.compile(
389
+ schemaValidator.schemify({
390
+ ...contractDetails.params ? { params: contractDetails.params } : {},
391
+ ...contractDetails.requestHeaders ? { headers: contractDetails.requestHeaders } : {},
392
+ ...contractDetails.query ? { query: contractDetails.query } : {},
393
+ ...isHttpContractDetails(contractDetails) && contractDetails.body ? { body: contractDetails.body } : {}
394
+ })
395
+ );
396
+ const responseEntries = {
397
+ 400: schemaValidator.string,
398
+ 401: schemaValidator.string,
399
+ 403: schemaValidator.string,
400
+ 404: schemaValidator.string,
401
+ 500: schemaValidator.string,
402
+ ...isPathParamHttpContractDetails(contractDetails) || isHttpContractDetails(contractDetails) ? { ...contractDetails.responses } : {}
403
+ };
404
+ const responseSchemas = {
405
+ responses: {},
406
+ ...contractDetails.responseHeaders ? {
407
+ headers: schemaValidator.compile(
408
+ schemaValidator.schemify(contractDetails.responseHeaders)
409
+ )
410
+ } : {}
411
+ };
412
+ Object.entries(responseEntries).forEach(([code, responseShape]) => {
413
+ responseSchemas.responses[Number(code)] = schemaValidator.compile(
414
+ schemaValidator.schemify(responseShape)
415
+ );
416
+ });
417
+ return {
418
+ requestSchema,
419
+ responseSchemas
420
+ };
421
+ }
422
+ /**
423
+ * Executes request locally, applying parameters
424
+ *
425
+ * @param handlers {ExpressLikeHandler<SV>}
426
+ * @param controllerHandler
427
+ * @returns
428
+ */
429
+ #localParamRequest(handlers, controllerHandler) {
430
+ return async (route, request) => {
431
+ let statusCode;
432
+ let responseMessage;
433
+ const responseHeaders = {};
434
+ const req = {
435
+ params: request?.params ?? {},
436
+ query: request?.query ?? {},
437
+ headers: request?.headers ?? {},
438
+ body: request?.body ?? {},
439
+ path: route
440
+ };
441
+ const res = {
442
+ status: (code) => {
443
+ statusCode = code;
444
+ return res;
445
+ },
446
+ send: (message) => {
447
+ responseMessage = message;
448
+ },
449
+ json: (body) => {
450
+ responseMessage = body;
451
+ },
452
+ jsonp: (body) => {
453
+ responseMessage = body;
454
+ },
455
+ setHeader: (key, value) => {
456
+ responseHeaders[key] = value;
457
+ }
458
+ };
459
+ let cursor = handlers.shift();
460
+ if (cursor) {
461
+ for (const fn of handlers) {
462
+ await cursor(req, res, (err) => {
463
+ if (err) {
464
+ throw err;
465
+ }
466
+ cursor = fn;
467
+ });
468
+ }
469
+ await cursor(req, res, async (err) => {
470
+ if (err) {
471
+ throw err;
472
+ }
473
+ });
474
+ }
475
+ const cHandler = controllerHandler;
476
+ await cHandler(req, res, (err) => {
477
+ if (err) {
478
+ throw err;
479
+ }
480
+ });
481
+ return {
482
+ code: statusCode,
483
+ response: responseMessage,
484
+ headers: responseHeaders
485
+ };
486
+ };
487
+ }
488
+ registerRoute(method, path, registrationMethod, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareAndTypedHandler) {
489
+ if (isTypedHandler(contractDetailsOrMiddlewareOrTypedHandler)) {
490
+ const { contractDetails, handlers } = contractDetailsOrMiddlewareOrTypedHandler;
491
+ return this.registerRoute(
492
+ method,
493
+ path,
494
+ registrationMethod,
495
+ contractDetails,
496
+ ...handlers
497
+ );
498
+ } else {
499
+ const maybeTypedHandler = middlewareOrMiddlewareAndTypedHandler[middlewareOrMiddlewareAndTypedHandler.length - 1];
500
+ if (isTypedHandler(maybeTypedHandler)) {
501
+ const { contractDetails, handlers } = maybeTypedHandler;
502
+ return this.registerRoute(
503
+ method,
504
+ path,
505
+ registrationMethod,
506
+ contractDetails,
507
+ ...middlewareOrMiddlewareAndTypedHandler.concat(handlers)
508
+ );
509
+ } else {
510
+ if (isExpressLikeSchemaHandler(contractDetailsOrMiddlewareOrTypedHandler) || isTypedHandler(contractDetailsOrMiddlewareOrTypedHandler)) {
511
+ throw new Error("Contract details are not defined");
512
+ }
513
+ const contractDetails = contractDetailsOrMiddlewareOrTypedHandler;
514
+ const handlers = middlewareOrMiddlewareAndTypedHandler.filter(
515
+ (handler) => isExpressLikeSchemaHandler(handler)
516
+ );
517
+ if (!isHttpContractDetails(contractDetails) && !isPathParamHttpContractDetails(contractDetails)) {
518
+ throw new Error(
519
+ "Contract details are malformed for route definition"
520
+ );
521
+ }
522
+ this.routes.push({
523
+ basePath: this.basePath,
524
+ path,
525
+ method,
526
+ contractDetails
527
+ });
528
+ const { requestSchema, responseSchemas } = this.#compile(contractDetails);
529
+ const controllerHandler = this.#extractControllerHandler(handlers);
530
+ registrationMethod.bind(this.internal)(
531
+ path,
532
+ ...this.#resolveMiddlewares(contractDetails, requestSchema, responseSchemas).concat(
533
+ handlers
534
+ ),
535
+ this.#parseAndRunControllerHandler(controllerHandler)
536
+ );
537
+ return this.#localParamRequest(
538
+ handlers,
539
+ controllerHandler
540
+ );
541
+ }
542
+ }
543
+ }
544
+ #extractHandlers(handlers, processMiddleware) {
545
+ const last = handlers.pop();
546
+ let finalHandlers = last ? [last] : [];
547
+ if (isTypedHandler(last)) {
548
+ finalHandlers = last.handlers;
549
+ }
550
+ handlers.forEach((handler) => {
551
+ if (isTypedHandler(handler)) {
552
+ throw new Error(
553
+ "Only the last argument supplied to this function can be a typed handler. Please use only middleware."
554
+ );
555
+ }
556
+ });
557
+ const middleware2 = processMiddleware ? handlers.map(processMiddleware) : handlers;
558
+ return [...middleware2, ...finalHandlers];
559
+ }
560
+ #extractMiddlewareFromEnrichedTypedHandlerArray(handlers) {
561
+ return this.#extractHandlers(handlers);
562
+ }
563
+ #extractNestableMiddlewareFromEnrichedTypedHandlerArray(handlers) {
564
+ return this.#extractHandlers(
565
+ handlers,
566
+ (handler) => isForklaunchExpressLikeRouter(handler) ? handler.internal : handler
567
+ );
568
+ }
569
+ #processTypedHandlerOrMiddleware(handler, middleware2) {
570
+ if (isTypedHandler(handler)) {
571
+ middleware2.push(...handler.handlers);
572
+ } else if (isExpressLikeSchemaHandler(handler)) {
573
+ middleware2.push(handler);
574
+ }
575
+ }
576
+ #extractMiddlewareAsRouterHandlers(contractDetailsOrMiddlewareOrTypedHandler, middlewareOrMiddlewareWithTypedHandler) {
577
+ const middleware2 = [];
578
+ this.#processTypedHandlerOrMiddleware(contractDetailsOrMiddlewareOrTypedHandler, middleware2);
579
+ middleware2.push(
580
+ ...this.#extractMiddlewareFromEnrichedTypedHandlerArray(middlewareOrMiddlewareWithTypedHandler)
581
+ );
582
+ return middleware2;
583
+ }
584
+ #extractNestableMiddlewareAsRouterHandlers(contractDetailsOrMiddlewareOrTypedHandler, middlewareOrMiddlewareWithTypedHandler) {
585
+ const middleware2 = [];
586
+ this.#processTypedHandlerOrMiddleware(
587
+ contractDetailsOrMiddlewareOrTypedHandler,
588
+ middleware2
589
+ );
590
+ if (isForklaunchExpressLikeRouter(
591
+ contractDetailsOrMiddlewareOrTypedHandler
592
+ )) {
593
+ middleware2.push(contractDetailsOrMiddlewareOrTypedHandler.internal);
594
+ }
595
+ middleware2.push(
596
+ ...this.#extractNestableMiddlewareFromEnrichedTypedHandlerArray(middlewareOrMiddlewareWithTypedHandler)
597
+ );
598
+ return middleware2;
599
+ }
600
+ registerMiddlewareHandler(registrationMethod, pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) {
601
+ const middleware2 = [];
602
+ if (typeof pathOrContractDetailsOrMiddlewareOrTypedHandler === "string") {
603
+ middleware2.push(
604
+ ...this.#extractMiddlewareAsRouterHandlers(
605
+ contractDetailsOrMiddlewareOrTypedHandler,
606
+ middlewareOrMiddlewareWithTypedHandler
607
+ )
608
+ );
609
+ const path = pathOrContractDetailsOrMiddlewareOrTypedHandler;
610
+ registrationMethod.bind(this.internal)(path, ...middleware2);
611
+ } else {
612
+ middleware2.push(
613
+ ...this.#extractMiddlewareAsRouterHandlers(
614
+ pathOrContractDetailsOrMiddlewareOrTypedHandler,
615
+ (isExpressLikeSchemaHandler(contractDetailsOrMiddlewareOrTypedHandler) || isTypedHandler(contractDetailsOrMiddlewareOrTypedHandler) ? [contractDetailsOrMiddlewareOrTypedHandler] : []).concat(middlewareOrMiddlewareWithTypedHandler)
616
+ )
617
+ );
618
+ registrationMethod.bind(this.internal)(...middleware2);
619
+ }
620
+ return this;
621
+ }
622
+ registerNestableMiddlewareHandler(registrationMethod, pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) {
623
+ const middleware2 = [];
624
+ let path;
625
+ if (typeof pathOrContractDetailsOrMiddlewareOrTypedHandler === "string") {
626
+ middleware2.push(
627
+ ...this.#extractNestableMiddlewareAsRouterHandlers(
628
+ contractDetailsOrMiddlewareOrTypedHandler,
629
+ middlewareOrMiddlewareWithTypedHandler
630
+ )
631
+ );
632
+ path = pathOrContractDetailsOrMiddlewareOrTypedHandler;
633
+ } else {
634
+ if (isConstrainedForklaunchRouter(
635
+ pathOrContractDetailsOrMiddlewareOrTypedHandler
636
+ )) {
637
+ path = pathOrContractDetailsOrMiddlewareOrTypedHandler.basePath;
638
+ }
639
+ middleware2.push(
640
+ ...this.#extractNestableMiddlewareAsRouterHandlers(
641
+ pathOrContractDetailsOrMiddlewareOrTypedHandler,
642
+ (isExpressLikeSchemaHandler(contractDetailsOrMiddlewareOrTypedHandler) || isTypedHandler(contractDetailsOrMiddlewareOrTypedHandler) || isConstrainedForklaunchRouter(
643
+ contractDetailsOrMiddlewareOrTypedHandler
644
+ ) ? [contractDetailsOrMiddlewareOrTypedHandler] : []).concat(middlewareOrMiddlewareWithTypedHandler)
645
+ )
646
+ );
647
+ }
648
+ if (path) {
649
+ registrationMethod.bind(this.internal)(path, ...middleware2);
650
+ } else {
651
+ registrationMethod.bind(this.internal)(...middleware2);
652
+ }
653
+ return this;
654
+ }
655
+ use = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
656
+ [
657
+ pathOrContractDetailsOrMiddlewareOrTypedHandler,
658
+ contractDetailsOrMiddlewareOrTypedHandler,
659
+ ...middlewareOrMiddlewareWithTypedHandler
660
+ ].forEach((arg) => {
661
+ if (isForklaunchRouter(arg)) {
662
+ this.routers.push(arg);
663
+ }
664
+ });
665
+ return this.registerNestableMiddlewareHandler(
666
+ this.internal.use,
667
+ pathOrContractDetailsOrMiddlewareOrTypedHandler,
668
+ contractDetailsOrMiddlewareOrTypedHandler,
669
+ ...middlewareOrMiddlewareWithTypedHandler
670
+ );
671
+ };
672
+ all = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
673
+ return this.registerMiddlewareHandler(
674
+ this.internal.all,
675
+ pathOrContractDetailsOrMiddlewareOrTypedHandler,
676
+ contractDetailsOrMiddlewareOrTypedHandler,
677
+ ...middlewareOrMiddlewareWithTypedHandler
678
+ );
679
+ };
680
+ connect = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
681
+ return this.registerMiddlewareHandler(
682
+ this.internal.connect,
683
+ pathOrContractDetailsOrMiddlewareOrTypedHandler,
684
+ contractDetailsOrMiddlewareOrTypedHandler,
685
+ ...middlewareOrMiddlewareWithTypedHandler
686
+ );
687
+ };
688
+ /**
689
+ * Registers a GET route with the specified contract details and handler handlers.
690
+ *
691
+ * @template P - The type of request parameters.
692
+ * @template ResBodyMap - The type of response body.
693
+ * @template ReqBody - The type of request body.
694
+ * @template ReqQuery - The type of request query.
695
+ * @template LocalsObj - The type of local variables.
696
+ * @param {string} path - The path for the route.
697
+ * @param {PathParamHttpContractDetails<SV, P, ResBodyMap, ReqQuery>} contractDetails - The contract details.
698
+ * @param {...SchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>[]} handlers - The handler handlers.
699
+ * @returns {ExpressRouter} - The Express router.
700
+ */
701
+ get = (path, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
702
+ return {
703
+ get: this.registerRoute(
704
+ "get",
705
+ path,
706
+ this.internal.get,
707
+ contractDetailsOrMiddlewareOrTypedHandler,
708
+ ...middlewareOrMiddlewareWithTypedHandler
709
+ )
710
+ };
711
+ };
712
+ /**
713
+ * Registers a POST route with the specified contract details and handler handlers.
714
+ *
715
+ * @template P - The type of request parameters.
716
+ * @template ResBodyMap - The type of response body.
717
+ * @template ReqBody - The type of request body.
718
+ * @template ReqQuery - The type of request query.
719
+ * @template LocalsObj - The type of local variables.
720
+ * @param {string} path - The path for the route.
721
+ * @param {HttpContractDetails<SV, P, ResBodyMap, ReqBody, ReqQuery>} contractDetails - The contract details.
722
+ * @param {...SchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>[]} handlers - The handler handlers.
723
+ * @returns {ExpressRouter} - The Expxwress router.
724
+ */
725
+ post = (path, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
726
+ return {
727
+ post: this.registerRoute(
728
+ "post",
729
+ path,
730
+ this.internal.post,
731
+ contractDetailsOrMiddlewareOrTypedHandler,
732
+ ...middlewareOrMiddlewareWithTypedHandler
733
+ )
734
+ };
735
+ };
736
+ /**
737
+ * Registers a PUT route with the specified contract details and handler handlers.
738
+ *
739
+ * @template P - The type of request parameters.
740
+ * @template ResBodyMap - The type of response body.
741
+ * @template ReqBody - The type of request body.
742
+ * @template ReqQuery - The type of request query.
743
+ * @template LocalsObj - The type of local variables.
744
+ * @param {string} path - The path for the route.
745
+ * @param {HttpContractDetails<SV, P, ResBodyMap, ReqBody, ReqQuery>} contractDetails - The contract details.
746
+ * @param {...SchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>[]} handlers - The handler handlers.
747
+ * @returns {ExpressRouter} - The Express router.
748
+ */
749
+ put = (path, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
750
+ return {
751
+ put: this.registerRoute(
752
+ "put",
753
+ path,
754
+ this.internal.put,
755
+ contractDetailsOrMiddlewareOrTypedHandler,
756
+ ...middlewareOrMiddlewareWithTypedHandler
757
+ )
758
+ };
759
+ };
760
+ /**
761
+ * Registers a PATCH route with the specified contract details and handler handlers.
762
+ *
763
+ * @template P - The type of request parameters.
764
+ * @template ResBodyMap - The type of response body.
765
+ * @template ReqBody - The type of request body.
766
+ * @template ReqQuery - The type of request query.
767
+ * @template LocalsObj - The type of local variables.
768
+ * @param {string} path - The path for the route.
769
+ * @param {HttpContractDetails<SV, P, ResBodyMap, ReqBody, ReqQuery>} contractDetails - The contract details.
770
+ * @param {...SchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>[]} handlers - The handler handlers.
771
+ * @returns {ExpressRouter} - The Express router.
772
+ */
773
+ patch = (path, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
774
+ return {
775
+ patch: this.registerRoute(
776
+ "patch",
777
+ path,
778
+ this.internal.patch,
779
+ contractDetailsOrMiddlewareOrTypedHandler,
780
+ ...middlewareOrMiddlewareWithTypedHandler
781
+ )
782
+ };
783
+ };
784
+ /**
785
+ * Registers a DELETE route with the specified contract details and handler handlers.
786
+ *
787
+ * @template P - The type of request parameters.
788
+ * @template ResBodyMap - The type of response body.
789
+ * @template ReqBody - The type of request body.
790
+ * @template ReqQuery - The type of request query.
791
+ * @template LocalsObj - The type of local variables.
792
+ * @param {string} path - The path for the route.
793
+ * @param {PathParamHttpContractDetails<SV, P, ResBodyMap, ReqQuery>} contractDetails - The contract details.
794
+ * @param {...SchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>[]} handlers - The handler handlers.
795
+ * @returns {ExpressRouter} - The Express router.
796
+ */
797
+ delete = (path, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
798
+ return {
799
+ delete: this.registerRoute(
800
+ "delete",
801
+ path,
802
+ this.internal.delete,
803
+ contractDetailsOrMiddlewareOrTypedHandler,
804
+ ...middlewareOrMiddlewareWithTypedHandler
805
+ )
806
+ };
807
+ };
808
+ /**
809
+ * Registers a OPTIONS route with the specified contract details and handler handlers.
810
+ *
811
+ * @template P - The type of request parameters.
812
+ * @template ResBodyMap - The type of response body.
813
+ * @template ReqBody - The type of request body.
814
+ * @template ReqQuery - The type of request query.
815
+ * @template LocalsObj - The type of local variables.
816
+ * @param {string} path - The path for the route.
817
+ * @param {PathParamHttpContractDetails<SV, P, ResBodyMap, ReqQuery>} contractDetails - The contract details.
818
+ * @param {...SchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>[]} handlers - The handler handlers.
819
+ * @returns {ExpressRouter} - The Express router.
820
+ */
821
+ options = (path, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
822
+ return {
823
+ options: this.registerRoute(
824
+ "options",
825
+ path,
826
+ this.internal.options,
827
+ contractDetailsOrMiddlewareOrTypedHandler,
828
+ ...middlewareOrMiddlewareWithTypedHandler
829
+ )
830
+ };
831
+ };
832
+ /**
833
+ * Registers a HEAD route with the specified contract details and handler handlers.
834
+ *
835
+ * @template P - The type of request parameters.
836
+ * @template ResBodyMap - The type of response body.
837
+ * @template ReqBody - The type of request body.
838
+ * @template ReqQuery - The type of request query.
839
+ * @template LocalsObj - The type of local variables.
840
+ * @param {string} path - The path for the route.
841
+ * @param {PathParamHttpContractDetails<SV, P, ResBodyMap, ReqQuery>} contractDetails - The contract details.
842
+ * @param {...SchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>[]} handlers - The handler handlers.
843
+ * @returns {ExpressRouter} - The Express router.
844
+ */
845
+ head = (path, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
846
+ return {
847
+ head: this.registerRoute(
848
+ "head",
849
+ path,
850
+ this.internal.head,
851
+ contractDetailsOrMiddlewareOrTypedHandler,
852
+ ...middlewareOrMiddlewareWithTypedHandler
853
+ )
854
+ };
855
+ };
856
+ /**
857
+ * Registers a TRACE route with the specified contract details and handler handlers.
858
+ *
859
+ * @template P - The type of request parameters.
860
+ * @template ResBodyMap - The type of response body.
861
+ * @template ReqBody - The type of request body.
862
+ * @template ReqQuery - The type of request query.
863
+ * @template LocalsObj - The type of local variables.
864
+ * @param {string} path - The path for the route.
865
+ * @param {PathParamHttpContractDetails<SV, P, ResBodyMap, ReqQuery>} contractDetails - The contract details.
866
+ * @param {...SchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>[]} handlers - The handler handlers.
867
+ * @returns {ExpressRouter} - The Express router.
868
+ */
869
+ trace = (path, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
870
+ return {
871
+ trace: this.registerRoute(
872
+ "trace",
873
+ path,
874
+ this.internal.trace,
875
+ contractDetailsOrMiddlewareOrTypedHandler,
876
+ ...middlewareOrMiddlewareWithTypedHandler
877
+ )
878
+ };
879
+ };
880
+ };
881
+
882
+ // src/http/application/expressLikeApplication.ts
883
+ var ForklaunchExpressLikeApplication = class extends ForklaunchExpressLikeRouter {
884
+ /**
885
+ * Creates an instance of the Application class.
886
+ *
887
+ * @param {SV} schemaValidator - The schema validator.
888
+ */
889
+ constructor(schemaValidator, internal) {
890
+ super("/", schemaValidator, internal);
891
+ this.schemaValidator = schemaValidator;
892
+ this.internal = internal;
893
+ }
894
+ };
895
+
896
+ // src/http/handlers/typedHandler.ts
897
+ function typedHandler(_schemaValidator, _pathOrContractDetails, contractMethodOrContractDetails, contractDetailsOrHandler, ...handlerArray) {
898
+ let contractDetails;
899
+ let handlers;
900
+ if (typeof contractMethodOrContractDetails === "string") {
901
+ if (typeof contractDetailsOrHandler !== "function") {
902
+ contractDetails = contractDetailsOrHandler;
903
+ } else {
904
+ throw new Error("Invalid definition for contract details");
905
+ }
906
+ handlers = handlerArray;
907
+ } else {
908
+ contractDetails = contractMethodOrContractDetails;
909
+ if (typeof contractDetailsOrHandler === "function") {
910
+ handlers = [contractDetailsOrHandler, ...handlerArray];
911
+ } else {
912
+ throw new Error("Invalid definition for handler");
913
+ }
914
+ }
915
+ return {
916
+ _typedHandler: true,
917
+ contractDetails,
918
+ handlers
919
+ };
920
+ }
921
+
922
+ // src/http/handlers/delete.ts
923
+ var delete_ = (_schemaValidator, path, contractDetails, ...handlers) => {
924
+ return typedHandler(_schemaValidator, path, "delete", contractDetails, ...handlers);
925
+ };
926
+
927
+ // src/http/handlers/get.ts
928
+ var get = (_schemaValidator, path, contractDetails, ...handlers) => {
929
+ return typedHandler(_schemaValidator, path, "get", contractDetails, ...handlers);
930
+ };
931
+
932
+ // src/http/handlers/head.ts
933
+ var head = (_schemaValidator, path, contractDetails, ...handlers) => {
934
+ return typedHandler(_schemaValidator, path, "head", contractDetails, ...handlers);
935
+ };
936
+
937
+ // src/http/handlers/middleware.ts
938
+ var middleware = (_schemaValidator, path, contractDetails, ...handlers) => {
939
+ return typedHandler(_schemaValidator, path, "middleware", contractDetails, ...handlers);
940
+ };
941
+
942
+ // src/http/handlers/options.ts
943
+ var options = (_schemaValidator, path, contractDetails, ...handlers) => {
944
+ return typedHandler(_schemaValidator, path, "options", contractDetails, ...handlers);
945
+ };
946
+
947
+ // src/http/handlers/patch.ts
948
+ var patch = (_schemaValidator, path, contractDetails, ...handlers) => {
949
+ return typedHandler(_schemaValidator, path, "patch", contractDetails, ...handlers);
950
+ };
951
+
952
+ // src/http/handlers/post.ts
953
+ var post = (_schemaValidator, path, contractDetails, ...handlers) => {
954
+ return typedHandler(_schemaValidator, path, "post", contractDetails, ...handlers);
955
+ };
956
+
957
+ // src/http/handlers/put.ts
958
+ var put = (_schemaValidator, path, contractDetails, ...handlers) => {
959
+ return typedHandler(_schemaValidator, path, "put", contractDetails, ...handlers);
960
+ };
961
+
962
+ // src/http/handlers/trace.ts
963
+ var trace = (_schemaValidator, path, contractDetails, ...handlers) => {
964
+ return typedHandler(_schemaValidator, path, "trace", contractDetails, ...handlers);
965
+ };
966
+
967
+ // src/http/utils/httpStatusCodes.ts
968
+ var HTTPStatuses = {
969
+ /**
970
+ * The initial part of a request has been received and has not yet been
971
+ * rejected by the server. The server intends to send a final response after
972
+ * the request has been fully received and acted upon.
973
+ *
974
+ * When the request contains an Expect header field that includes a
975
+ * 100-continue expectation, the 100 response indicates that the server
976
+ * wishes to receive the request payload body. The client ought to continue
977
+ * sending the request and discard the 100 response.
978
+ *
979
+ * If the request did not contain an Expect header field containing the
980
+ * 100-continue expectation, the client can simply discard this interim
981
+ * response.
982
+ */
983
+ 100: "Continue",
984
+ /**
985
+ * The server understands and is willing to comply with the client's request,
986
+ * via the Upgrade header field, for a change in the application protocol
987
+ * being used on this connection.
988
+ *
989
+ * The server MUST generate an Upgrade header field in the response that
990
+ * indicates which protocol(s) will be switched to immediately after the
991
+ * empty line that terminates the 101 response.
992
+ *
993
+ * It is assumed that the server will only agree to switch protocols when it
994
+ * is advantageous to do so. For example, switching to a newer version of
995
+ * HTTP might be advantageous over older versions, and switching to a
996
+ * real-time, synchronous protocol might be advantageous when delivering
997
+ * resources that use such features.
998
+ */
999
+ 101: "Switching Protocols",
1000
+ /**
1001
+ * An interim response used to inform the client that the server has accepted
1002
+ * the complete request, but has not yet completed it.
1003
+ *
1004
+ * This status code SHOULD only be sent when the server has a reasonable
1005
+ * expectation that the request will take significant time to complete. As
1006
+ * guidance, if a method is taking longer than 20 seconds (a reasonable, but
1007
+ * arbitrary value) to process the server SHOULD return a 102 (Processing)
1008
+ * response. The server MUST send a final response after the request has been
1009
+ * completed.
1010
+ *
1011
+ * Methods can potentially take a long period of time to process, especially
1012
+ * methods that support the Depth header. In such cases the client may
1013
+ * time-out the connection while waiting for a response. To prevent this the
1014
+ * server may return a 102 Processing status code to indicate to the client
1015
+ * that the server is still processing the method.
1016
+ */
1017
+ 102: "Processing",
1018
+ /**
1019
+ * The request has succeeded.
1020
+ *
1021
+ * Aside from responses to CONNECT, a 200 response always has a payload,
1022
+ * though an origin server MAY generate a payload body of zero length. If no
1023
+ * payload is desired, an origin server ought to send 204 No Content instead.
1024
+ * For CONNECT, no payload is allowed because the successful result is a
1025
+ * tunnel, which begins immediately after the 200 response header section.
1026
+ *
1027
+ * A 200 response is cacheable by default; i.e., unless otherwise indicated
1028
+ * by the method definition or explicit cache controls.
1029
+ */
1030
+ 200: "OK",
1031
+ /**
1032
+ * The request has been fulfilled and has resulted in one or more new
1033
+ * resources being created.
1034
+ *
1035
+ * The primary resource created by the request is identified by either a
1036
+ * Location header field in the response or, if no Location field is
1037
+ * received, by the effective request URI.
1038
+ *
1039
+ * The 201 response payload typically describes and links to the resource(s)
1040
+ * created. See Section 7.2 of RFC7231 for a discussion of the meaning and
1041
+ * purpose of validator header fields, such as ETag and Last-Modified, in a
1042
+ * 201 response.
1043
+ */
1044
+ 201: "Created",
1045
+ /**
1046
+ * The request has been accepted for processing, but the processing has not
1047
+ * been completed. The request might or might not eventually be acted upon,
1048
+ * as it might be disallowed when processing actually takes place.
1049
+ *
1050
+ * There is no facility in HTTP for re-sending a status code from an
1051
+ * asynchronous operation.
1052
+ *
1053
+ * The 202 response is intentionally noncommittal. Its purpose is to allow a
1054
+ * server to accept a request for some other process (perhaps a
1055
+ * batch-oriented process that is only run once per day) without requiring
1056
+ * that the user agent's connection to the server persist until the process
1057
+ * is completed. The representation sent with this response ought to describe
1058
+ * the request's current status and point to (or embed) a status monitor that
1059
+ * can provide the user with an estimate of when the request will be
1060
+ * fulfilled.
1061
+ */
1062
+ 202: "Accepted",
1063
+ /**
1064
+ * The request was successful but the enclosed payload has been modified from
1065
+ * that of the origin server's 200 OK response by a transforming proxy.
1066
+ *
1067
+ * This status code allows the proxy to notify recipients when a
1068
+ * transformation has been applied, since that knowledge might impact later
1069
+ * decisions regarding the content. For example, future cache validation
1070
+ * requests for the content might only be applicable along the same request
1071
+ * path (through the same proxies).
1072
+ *
1073
+ * The 203 response is similar to the Warning code of 214 Transformation
1074
+ * Applied, which has the advantage of being applicable to responses with any
1075
+ * status code.
1076
+ *
1077
+ * A 203 response is cacheable by default; i.e., unless otherwise indicated
1078
+ * by the method definition or explicit cache controls.
1079
+ */
1080
+ 203: "Non-authoritative Information",
1081
+ /**
1082
+ * The server has successfully fulfilled the request and that there is no
1083
+ * additional content to send in the response payload body.
1084
+ *
1085
+ * Metadata in the response header fields refer to the target resource and
1086
+ * its selected representation after the requested action was applied.
1087
+ *
1088
+ * A 204 response is terminated by the first empty line after the header
1089
+ * fields because it cannot contain a message body.
1090
+ *
1091
+ * A 204 response is cacheable by default; i.e., unless otherwise indicated
1092
+ * by the method definition or explicit cache controls.
1093
+ */
1094
+ 204: "No Content",
1095
+ /**
1096
+ * He server has fulfilled the request and desires that the user agent reset
1097
+ * the "document view", which caused the request to be sent, to its original
1098
+ * state as received from the origin server.
1099
+ *
1100
+ * This response is intended to support a common data entry use case where
1101
+ * the user receives content that supports data entry (a form, notepad,
1102
+ * canvas, etc.), enters or manipulates data in that space, causes the
1103
+ * entered data to be submitted in a request, and then the data entry
1104
+ * mechanism is reset for the next entry so that the user can easily
1105
+ * initiate another input action.
1106
+ *
1107
+ * Since the 205 status code implies that no additional content will be
1108
+ * provided, a server MUST NOT generate a payload in a 205 response. In
1109
+ * other words, a server MUST do one of the following for a 205 response: a)
1110
+ * indicate a zero-length body for the response by including a
1111
+ * Content-Length header field with a value of 0; b) indicate a zero-length
1112
+ * payload for the response by including a Transfer-Encoding header field
1113
+ * with a value of chunked and a message body consisting of a single chunk
1114
+ * of zero-length; or, c) close the connection immediately after sending the
1115
+ * blank line terminating the header section.
1116
+ */
1117
+ 205: "Reset Content",
1118
+ /**
1119
+ * The server is successfully fulfilling a range request for the target
1120
+ * resource by transferring one or more parts of the selected representation
1121
+ * that correspond to the satisfiable ranges found in the request's Range
1122
+ * header field.
1123
+ *
1124
+ * If a single part is being transferred, the server generating the 206
1125
+ * response MUST generate a Content-Range header field, describing what range
1126
+ * of the selected representation is enclosed, and a payload consisting of
1127
+ * the range.
1128
+ *
1129
+ * If multiple parts are being transferred, the server generating the 206
1130
+ * response MUST generate a "multipart/byteranges" payload2, and a
1131
+ * Content-Type header field containing the multipart/byteranges media type
1132
+ * and its required boundary parameter. To avoid confusion with single-part
1133
+ * responses, a server MUST NOT generate a Content-Range header field in the
1134
+ * HTTP header section of a multiple part response (this field will be sent
1135
+ * in each part instead).
1136
+ *
1137
+ * Within the header area of each body part in the multipart payload, the
1138
+ * server MUST generate a Content-Range header field corresponding to the
1139
+ * range being enclosed in that body part. If the selected representation
1140
+ * would have had a Content-Type header field in a 200 OK response, the
1141
+ * server SHOULD generate that same Content-Type field in the header area of
1142
+ * each body part.
1143
+ *
1144
+ * When multiple ranges are requested, a server MAY coalesce any of the
1145
+ * ranges that overlap, or that are separated by a gap that is smaller than
1146
+ * the overhead of sending multiple parts, regardless of the order in which
1147
+ * the corresponding byte-range-spec appeared in the received Range header
1148
+ * field. Since the typical overhead between parts of a multipart/byteranges
1149
+ * payload is around 80 bytes, depending on the selected representation's
1150
+ * media type and the chosen boundary parameter length, it can be less
1151
+ * efficient to transfer many small disjoint parts than it is to transfer the
1152
+ * entire selected representation.
1153
+ *
1154
+ * A server MUST NOT generate a multipart response to a request for a single
1155
+ * range, since a client that does not request multiple parts might not
1156
+ * support multipart responses. However, a server MAY generate a
1157
+ * multipart/byteranges payload with only a single body part if multiple
1158
+ * ranges were requested and only one range was found to be satisfiable or
1159
+ * only one range remained after coalescing. A client that cannot process a
1160
+ * multipart/byteranges response MUST NOT generate a request that asks for
1161
+ * multiple ranges.
1162
+ *
1163
+ * When a multipart response payload is generated, the server SHOULD send the
1164
+ * parts in the same order that the corresponding byte-range-spec appeared in
1165
+ * the received Range header field, excluding those ranges that were deemed
1166
+ * unsatisfiable or that were coalesced into other ranges. A client that
1167
+ * receives a multipart response MUST inspect the Content-Range header field
1168
+ * present in each body part in order to determine which range is contained
1169
+ * in that body part; a client cannot rely on receiving the same ranges that
1170
+ * it requested, nor the same order that it requested.
1171
+ *
1172
+ * When a 206 response is generated, the server MUST generate the following
1173
+ * header fields, in addition to those required above, if the field would
1174
+ * have been sent in a 200 OK response to the same request: Date,
1175
+ * Cache-Control, ETag, Expires, Content-Location, and Vary.
1176
+ *
1177
+ * If a 206 is generated in response to a request with an If-Range header
1178
+ * field, the sender SHOULD NOT generate other representation header fields
1179
+ * beyond those required above, because the client is understood to already
1180
+ * have a prior response containing those header fields. Otherwise, the
1181
+ * sender MUST generate all of the representation header fields that would
1182
+ * have been sent in a 200 OK response to the same request.
1183
+ *
1184
+ * A 206 response is cacheable by default; i.e., unless otherwise indicated
1185
+ * by explicit cache controls.
1186
+ */
1187
+ 206: "Partial Content",
1188
+ /**
1189
+ * A Multi-Status response conveys information about multiple resources in
1190
+ * situations where multiple status codes might be appropriate.
1191
+ *
1192
+ * The default Multi-Status response body is a text/xml or application/xml
1193
+ * HTTP entity with a 'multistatus' root element. Further elements contain
1194
+ * 200, 300, 400, and 500 series status codes generated during the method
1195
+ * invocation. 100 series status codes SHOULD NOT be recorded in a 'response'
1196
+ * XML element.
1197
+ *
1198
+ * Although '207' is used as the overall response status code, the recipient
1199
+ * needs to consult the contents of the multistatus response body for further
1200
+ * information about the success or failure of the method execution. The
1201
+ * response MAY be used in success, partial success and also in failure
1202
+ * situations.
1203
+ *
1204
+ * The 'multistatus' root element holds zero or more 'response' elements in
1205
+ * any order, each with information about an individual resource. Each
1206
+ * 'response' element MUST have an 'href' element to identify the resource.
1207
+ *
1208
+ * A Multi-Status response uses one out of two distinct formats for
1209
+ * representing the status:
1210
+ *
1211
+ * 1. A 'status' element as child of the 'response' element indicates the
1212
+ * status of the message execution for the identified resource as a whole.
1213
+ * Some method definitions provide information about specific status codes
1214
+ * clients should be prepared to see in a response. However, clients MUST be
1215
+ * able to handle other status codes, using the generic rules defined in
1216
+ * RFC2616 Section 10.
1217
+ *
1218
+ * 2. For PROPFIND and PROPPATCH, the format has been extended using the
1219
+ * 'propstat' element instead of 'status', providing information about
1220
+ * individual properties of a resource. This format is specific to PROPFIND
1221
+ * and PROPPATCH, and is described in detail in RFC4918 Section 9.1 and
1222
+ * RFC4918 Section 9.2.
1223
+ */
1224
+ 207: "Multi-Status",
1225
+ /**
1226
+ * Used inside a DAV: propstat response element to avoid enumerating the
1227
+ * internal members of multiple bindings to the same collection repeatedly.
1228
+ *
1229
+ * For each binding to a collection inside the request's scope, only one will
1230
+ * be reported with a 200 status, while subsequent DAV:response elements for
1231
+ * all other bindings will use the 208 status, and no DAV:response elements
1232
+ * for their descendants are included.
1233
+ *
1234
+ * Note that the 208 status will only occur for "Depth: infinity" requests,
1235
+ * and that it is of particular importance when the multiple collection
1236
+ * bindings cause a bind loop.
1237
+ *
1238
+ * A client can request the DAV:resource-id property in a PROPFIND request to
1239
+ * guarantee that they can accurately reconstruct the binding structure of a
1240
+ * collection with multiple bindings to a single resource.
1241
+ *
1242
+ * For backward compatibility with clients not aware of the 208 status code
1243
+ * appearing in multistatus response bodies, it SHOULD NOT be used unless the
1244
+ * client has signaled support for this specification using the "DAV" request
1245
+ * header. Instead, a 508 Loop Detected status should be returned when a
1246
+ * binding loop is discovered. This allows the server to return the 508 as
1247
+ * the top-level return status, if it discovers it before it started the
1248
+ * response, or in the middle of a multistatus, if it discovers it in the
1249
+ * middle of streaming out a multistatus response.
1250
+ */
1251
+ 208: "Already Reported",
1252
+ /**
1253
+ * The server has fulfilled a GET request for the resource, and the response
1254
+ * is a representation of the result of one or more instance-manipulations
1255
+ * applied to the current instance.
1256
+ *
1257
+ * The actual current instance might not be available except by combining
1258
+ * this response with other previous or future responses, as appropriate for
1259
+ * the specific instance-manipulation(s). If so, the headers of the resulting
1260
+ * instance are the result of combining the headers from the 226 response and
1261
+ * the other instances, following the rules in section 13.5.3 of the HTTP/1.1
1262
+ * specification.
1263
+ *
1264
+ * The request MUST have included an A-IM header field listing at least one
1265
+ * instance-manipulation. The response MUST include an Etag header field
1266
+ * giving the entity tag of the current instance.
1267
+ *
1268
+ * A response received with a status code of 226 MAY be stored by a cache and
1269
+ * used in reply to a subsequent request, subject to the HTTP expiration
1270
+ * mechanism and any Cache-Control headers, and to the requirements in
1271
+ * section 10.6.
1272
+ *
1273
+ * A response received with a status code of 226 MAY be used by a cache, in
1274
+ * conjunction with a cache entry for the base instance, to create a cache
1275
+ * entry for the current instance.
1276
+ */
1277
+ 226: "IM Used",
1278
+ /**
1279
+ * The target resource has more than one representation, each with its own
1280
+ * more specific identifier, and information about the alternatives is being
1281
+ * provided so that the user (or user agent) can select a preferred
1282
+ * representation by redirecting its request to one or more of those
1283
+ * identifiers.
1284
+ *
1285
+ * In other words, the server desires that the user agent engage in reactive
1286
+ * negotiation to select the most appropriate representation(s) for its
1287
+ * needs.
1288
+ *
1289
+ * If the server has a preferred choice, the server SHOULD generate a
1290
+ * Location header field containing a preferred choice's URI reference. The
1291
+ * user agent MAY use the Location field value for automatic redirection.
1292
+ *
1293
+ * For request methods other than HEAD, the server SHOULD generate a payload
1294
+ * in the 300 response containing a list of representation metadata and URI
1295
+ * reference(s) from which the user or user agent can choose the one most
1296
+ * preferred. The user agent MAY make a selection from that list
1297
+ * automatically if it understands the provided media type. A specific format
1298
+ * for automatic selection is not defined by this specification because HTTP
1299
+ * tries to remain orthogonal to the definition of its payloads. In practice,
1300
+ * the representation is provided in some easily parsed format believed to be
1301
+ * acceptable to the user agent, as determined by shared design or content
1302
+ * negotiation, or in some commonly accepted hypertext format.
1303
+ *
1304
+ * A 300 response is cacheable by default; i.e., unless otherwise indicated
1305
+ * by the method definition or explicit cache controls.
1306
+ *
1307
+ * Note: The original proposal for the 300 status code defined the URI header
1308
+ * field as providing a list of alternative representations, such that it
1309
+ * would be usable for 200, 300, and 406 responses and be transferred in
1310
+ * responses to the HEAD method. However, lack of deployment and disagreement
1311
+ * over syntax led to both URI and Alternates (a subsequent proposal) being
1312
+ * dropped from this specification. It is possible to communicate the list
1313
+ * using a set of Link header fields3, each with a relationship of
1314
+ * "alternate", though deployment is a chicken-and-egg problem.
1315
+ */
1316
+ 300: "Multiple Choices",
1317
+ /**
1318
+ * The target resource has been assigned a new permanent URI and any future
1319
+ * references to this resource ought to use one of the enclosed URIs.
1320
+ *
1321
+ * Clients with link-editing capabilities ought to automatically re-link
1322
+ * references to the effective request URI to one or more of the new
1323
+ * references sent by the server, where possible.
1324
+ *
1325
+ * The server SHOULD generate a Location header field in the response
1326
+ * containing a preferred URI reference for the new permanent URI. The user
1327
+ * agent MAY use the Location field value for automatic redirection. The
1328
+ * server's response payload usually contains a short hypertext note with a
1329
+ * hyperlink to the new URI(s).
1330
+ *
1331
+ * Note: For historical reasons, a user agent MAY change the request method
1332
+ * from POST to GET for the subsequent request. If this behavior is
1333
+ * undesired, the 307 Temporary Redirect status code can be used instead.
1334
+ *
1335
+ * A 301 response is cacheable by default; i.e., unless otherwise indicated
1336
+ * by the method definition or explicit cache controls.
1337
+ */
1338
+ 301: "Moved Permanently",
1339
+ /**
1340
+ * The target resource resides temporarily under a different URI. Since the
1341
+ * redirection might be altered on occasion, the client ought to continue to
1342
+ * use the effective request URI for future requests.
1343
+ *
1344
+ * The server SHOULD generate a Location header field in the response
1345
+ * containing a URI reference for the different URI. The user agent MAY use
1346
+ * the Location field value for automatic redirection. The server's response
1347
+ * payload usually contains a short hypertext note with a hyperlink to the
1348
+ * different URI(s).
1349
+ *
1350
+ * Note: For historical reasons, a user agent MAY change the request method
1351
+ * from POST to GET for the subsequent request. If this behavior is
1352
+ * undesired, the 307 Temporary Redirect status code can be used instead.
1353
+ */
1354
+ 302: "Found",
1355
+ /**
1356
+ * The server is redirecting the user agent to a different resource, as
1357
+ * indicated by a URI in the Location header field, which is intended to
1358
+ * provide an indirect response to the original request.
1359
+ *
1360
+ * A user agent can perform a retrieval request targeting that URI (a GET or
1361
+ * HEAD request if using HTTP), which might also be redirected, and present
1362
+ * the eventual result as an answer to the original request. Note that the
1363
+ * new URI in the Location header field is not considered equivalent to the
1364
+ * effective request URI.
1365
+ *
1366
+ * This status code is applicable to any HTTP method. It is primarily used
1367
+ * to allow the output of a POST action to redirect the user agent to a
1368
+ * selected resource, since doing so provides the information corresponding
1369
+ * to the POST response in a form that can be separately identified,
1370
+ * bookmarked, and cached, independent of the original request.
1371
+ *
1372
+ * A 303 response to a GET request indicates that the origin server does not
1373
+ * have a representation of the target resource that can be transferred by
1374
+ * the server over HTTP. However, the Location field value refers to a
1375
+ * resource that is descriptive of the target resource, such that making a
1376
+ * retrieval request on that other resource might result in a representation
1377
+ * that is useful to recipients without implying that it represents the
1378
+ * original target resource. Note that answers to the questions of what can
1379
+ * be represented, what representations are adequate, and what might be a
1380
+ * useful description are outside the scope of HTTP.
1381
+ *
1382
+ * Except for responses to a HEAD request, the representation of a 303
1383
+ * response ought to contain a short hypertext note with a hyperlink to the
1384
+ * same URI reference provided in the Location header field.
1385
+ */
1386
+ 303: "See Other",
1387
+ /**
1388
+ * A conditional GET or HEAD request has been received and would have
1389
+ * resulted in a 200 OK response if it were not for the fact that the
1390
+ * condition evaluated to false.
1391
+ *
1392
+ * In other words, there is no need for the server to transfer a
1393
+ * representation of the target resource because the request indicates that
1394
+ * the client, which made the request conditional, already has a valid
1395
+ * representation; the server is therefore redirecting the client to make
1396
+ * use of that stored representation as if it were the payload of a 200 OK
1397
+ * response.
1398
+ *
1399
+ * The server generating a 304 response MUST generate any of the following
1400
+ * header fields that would have been sent in a 200 OK response to the same
1401
+ * request: Cache-Control, Content-Location, Date, ETag, Expires, and Vary.
1402
+ *
1403
+ * Since the goal of a 304 response is to minimize information transfer when
1404
+ * the recipient already has one or more cached representations, a sender
1405
+ * SHOULD NOT generate representation metadata other than the above listed
1406
+ * fields unless said metadata exists for the purpose of guiding cache
1407
+ * updates (e.g., Last-Modified might be useful if the response does not have
1408
+ * an ETag field).
1409
+ *
1410
+ * Requirements on a cache that receives a 304 response are defined in
1411
+ * Section 4.3.4 of RFC7234. If the conditional request originated with an
1412
+ * outbound client, such as a user agent with its own cache sending a
1413
+ * conditional GET to a shared proxy, then the proxy SHOULD forward the
1414
+ * 304 response to that client.
1415
+ *
1416
+ * A 304 response cannot contain a message-body; it is always terminated by
1417
+ * the first empty line after the header fields.
1418
+ */
1419
+ 304: "Not Modified",
1420
+ /**
1421
+ * Defined in a previous version of this specification and is now deprecated,
1422
+ * due to security concerns regarding in-band configuration of a proxy.
1423
+ */
1424
+ 305: "Use Proxy",
1425
+ /**
1426
+ * The target resource resides temporarily under a different URI and the user
1427
+ * agent MUST NOT change the request method if it performs an automatic
1428
+ * redirection to that URI.
1429
+ *
1430
+ * Since the redirection can change over time, the client ought to continue
1431
+ * using the original effective request URI for future requests.
1432
+ *
1433
+ * The server SHOULD generate a Location header field in the response
1434
+ * containing a URI reference for the different URI. The user agent MAY use
1435
+ * the Location field value for automatic redirection. The server's response
1436
+ * payload usually contains a short hypertext note with a hyperlink to the
1437
+ * different URI(s).
1438
+ *
1439
+ * Note: This status code is similar to 302 Found, except that it does not
1440
+ * allow changing the request method from POST to GET. This specification
1441
+ * defines no equivalent counterpart for 301 Moved Permanently (RFC7238,
1442
+ * however, proposes defining the status code 308 Permanent Redirect for
1443
+ * this purpose).
1444
+ */
1445
+ 307: "Temporary Redirect",
1446
+ /**
1447
+ * The target resource has been assigned a new permanent URI and any future
1448
+ * references to this resource ought to use one of the enclosed URIs.
1449
+ *
1450
+ * Clients with link editing capabilities ought to automatically re-link
1451
+ * references to the effective request URI to one or more of the new
1452
+ * references sent by the server, where possible.
1453
+ *
1454
+ * The server SHOULD generate a Location header field in the response
1455
+ * containing a preferred URI reference for the new permanent URI. The user
1456
+ * agent MAY use the Location field value for automatic redirection. The
1457
+ * server's response payload usually contains a short hypertext note with a
1458
+ * hyperlink to the new URI(s).
1459
+ *
1460
+ * A 308 response is cacheable by default; i.e., unless otherwise indicated
1461
+ * by the method definition or explicit cache controls.
1462
+ *
1463
+ * Note: This status code is similar to 301 Moved Permanently, except that it
1464
+ * does not allow changing the request method from POST to GET.
1465
+ */
1466
+ 308: "Permanent Redirect",
1467
+ /**
1468
+ * The 400 (Bad Request) status code indicates that the server cannot or
1469
+ * will not process the request due to something that is perceived to be
1470
+ * a client error (e.g., malformed request syntax, invalid request
1471
+ * message framing, or deceptive request routing).
1472
+ */
1473
+ 400: "Bad Request",
1474
+ /**
1475
+ * The request has not been applied because it lacks valid authentication
1476
+ * credentials for the target resource.
1477
+ *
1478
+ * The server generating a 401 response MUST send a WWW-Authenticate header
1479
+ * field containing at least one challenge applicable to the target resource.
1480
+ *
1481
+ * If the request included authentication credentials, then the 401 response
1482
+ * indicates that authorization has been refused for those credentials. The
1483
+ * user agent MAY repeat the request with a new or replaced Authorization
1484
+ * header field. If the 401 response contains the same challenge as the
1485
+ * prior response, and the user agent has already attempted authentication at
1486
+ * least once, then the user agent SHOULD present the enclosed representation
1487
+ * to the user, since it usually contains relevant diagnostic information.
1488
+ */
1489
+ 401: "Unauthorized",
1490
+ /**
1491
+ * The 402 (Payment Required) status code is reserved for future use.
1492
+ */
1493
+ 402: "Payment Required",
1494
+ /**
1495
+ * The 403 (Forbidden) status code indicates that the server understood
1496
+ * the request but refuses to authorize it. A server that wishes to
1497
+ * make public why the request has been forbidden can describe that
1498
+ * reason in the response payload (if any).
1499
+ *
1500
+ * If authentication credentials were provided in the request, the
1501
+ * server considers them insufficient to grant access. The client
1502
+ * SHOULD NOT automatically repeat the request with the same
1503
+ * credentials. The client MAY repeat the request with new or different
1504
+ * credentials. However, a request might be forbidden for reasons
1505
+ * unrelated to the credentials.
1506
+ *
1507
+ * An origin server that wishes to "hide" the current existence of a
1508
+ * forbidden target resource MAY instead respond with a status code of
1509
+ * 404 (Not Found).
1510
+ */
1511
+ 403: "Forbidden",
1512
+ /**
1513
+ * The 404 (Not Found) status code indicates that the origin server did
1514
+ * not find a current representation for the target resource or is not
1515
+ * willing to disclose that one exists. A 404 status code does not
1516
+ * indicate whether this lack of representation is temporary or
1517
+ * permanent; the 410 (Gone) status code is preferred over 404 if the
1518
+ * origin server knows, presumably through some configurable means, that
1519
+ * the condition is likely to be permanent.
1520
+ *
1521
+ * A 404 response is cacheable by default; i.e., unless otherwise
1522
+ * indicated by the method definition or explicit cache controls (see
1523
+ * Section 4.2.2 of [RFC7234]).
1524
+ */
1525
+ 404: "Not Found",
1526
+ /**
1527
+ * The 405 (Method Not Allowed) status code indicates that the method
1528
+ * received in the request-line is known by the origin server but not
1529
+ * supported by the target resource. The origin server MUST generate an
1530
+ * Allow header field in a 405 response containing a list of the target
1531
+ * resource's currently supported methods.
1532
+ *
1533
+ * A 405 response is cacheable by default; i.e., unless otherwise
1534
+ * indicated by the method definition or explicit cache controls (see
1535
+ * Section 4.2.2 of [RFC7234]).
1536
+ */
1537
+ 405: "Method Not Allowed",
1538
+ /**
1539
+ * The 406 (Not Acceptable) status code indicates that the target
1540
+ * resource does not have a current representation that would be
1541
+ * acceptable to the user agent, according to the proactive negotiation
1542
+ * header fields received in the request (Section 5.3), and the server
1543
+ * is unwilling to supply a default representation.
1544
+ *
1545
+ * The server SHOULD generate a payload containing a list of available
1546
+ * representation characteristics and corresponding resource identifiers
1547
+ * from which the user or user agent can choose the one most
1548
+ * appropriate. A user agent MAY automatically select the most
1549
+ * appropriate choice from that list. However, this specification does
1550
+ * not define any standard for such automatic selection, as described in
1551
+ * Section 6.4.1 of [RFC7231]
1552
+ */
1553
+ 406: "Not Acceptable",
1554
+ /**
1555
+ * Similar to 401 Unauthorized, but it indicates that the client needs to
1556
+ * authenticate itself in order to use a proxy.
1557
+ *
1558
+ * The proxy MUST send a Proxy-Authenticate header field containing a
1559
+ * challenge applicable to that proxy for the target resource. The client MAY
1560
+ * repeat the request with a new or replaced Proxy-Authorization header field.
1561
+ */
1562
+ 407: "Proxy Authentication Required",
1563
+ /**
1564
+ * The 408 (Request Timeout) status code indicates that the server did
1565
+ * not receive a complete request message within the time that it was
1566
+ * prepared to wait. A server SHOULD send the "close" connection option
1567
+ * (Section 6.1 of [RFC7230]) in the response, since 408 implies that
1568
+ * the server has decided to close the connection rather than continue
1569
+ * waiting. If the client has an outstanding request in transit, the
1570
+ * client MAY repeat that request on a new connection.
1571
+ */
1572
+ 408: "Request Timeout",
1573
+ /**
1574
+ * The 409 (Conflict) status code indicates that the request could not
1575
+ * be completed due to a conflict with the current state of the target
1576
+ * resource. This code is used in situations where the user might be
1577
+ * able to resolve the conflict and resubmit the request. The server
1578
+ * SHOULD generate a payload that includes enough information for a user
1579
+ * to recognize the source of the conflict.
1580
+ *
1581
+ * Conflicts are most likely to occur in response to a PUT request. For
1582
+ * example, if versioning were being used and the representation being
1583
+ * PUT included changes to a resource that conflict with those made by
1584
+ * an earlier (third-party) request, the origin server might use a 409
1585
+ * response to indicate that it can't complete the request. In this
1586
+ * case, the response representation would likely contain information
1587
+ * useful for merging the differences based on the revision history.
1588
+ */
1589
+ 409: "Conflict",
1590
+ /**
1591
+ * The 410 (Gone) status code indicates that access to the target
1592
+ * resource is no longer available at the origin server and that this
1593
+ * condition is likely to be permanent. If the origin server does not
1594
+ * know, or has no facility to determine, whether or not the condition
1595
+ * is permanent, the status code 404 (Not Found) ought to be used
1596
+ * instead.
1597
+ *
1598
+ * The 410 response is primarily intended to assist the task of web
1599
+ * maintenance by notifying the recipient that the resource is
1600
+ * intentionally unavailable and that the server owners desire that
1601
+ * remote links to that resource be removed. Such an event is common
1602
+ * for limited-time, promotional services and for resources belonging to
1603
+ * individuals no longer associated with the origin server's site. It
1604
+ * is not necessary to mark all permanently unavailable resources as
1605
+ * "gone" or to keep the mark for any length of time -- that is left to
1606
+ * the discretion of the server owner.
1607
+ *
1608
+ * A 410 response is cacheable by default; i.e., unless otherwise
1609
+ * indicated by the method definition or explicit cache controls (see
1610
+ * Section 4.2.2 of [RFC7234]).
1611
+ */
1612
+ 410: "Gone",
1613
+ /**
1614
+ * The 411 (Length Required) status code indicates that the server
1615
+ * refuses to accept the request without a defined Content-Length
1616
+ * (Section 3.3.2 of [RFC7230]). The client MAY repeat the request if
1617
+ * it adds a valid Content-Length header field containing the length of
1618
+ * the message body in the request message.
1619
+ */
1620
+ 411: "Length Required",
1621
+ /**
1622
+ * One or more conditions given in the request header fields evaluated to
1623
+ * false when tested on the server.
1624
+ *
1625
+ * This response code allows the client to place preconditions on the current
1626
+ * resource state (its current representations and metadata) and, thus,
1627
+ * prevent the request method from being applied if the target resource is in
1628
+ * an unexpected state.
1629
+ */
1630
+ 412: "Precondition Failed",
1631
+ /**
1632
+ * The 413 (Payload Too Large) status code indicates that the server is
1633
+ * refusing to process a request because the request payload is larger
1634
+ * than the server is willing or able to process. The server MAY close
1635
+ * the connection to prevent the client from continuing the request.
1636
+ *
1637
+ * If the condition is temporary, the server SHOULD generate a
1638
+ * Retry-After header field to indicate that it is temporary and after
1639
+ * what time the client MAY try again.
1640
+ */
1641
+ 413: "Payload Too Large",
1642
+ /**
1643
+ * The 414 (URI Too Long) status code indicates that the server is
1644
+ * refusing to service the request because the request-target (Section
1645
+ * 5.3 of [RFC7230]) is longer than the server is willing to interpret.
1646
+ * This rare condition is only likely to occur when a client has
1647
+ * improperly converted a POST request to a GET request with long query
1648
+ * information, when the client has descended into a "black hole" of
1649
+ * redirection (e.g., a redirected URI prefix that points to a suffix of
1650
+ * itself) or when the server is under attack by a client attempting to
1651
+ * exploit potential security holes.
1652
+ *
1653
+ * A 414 response is cacheable by default; i.e., unless otherwise
1654
+ * indicated by the method definition or explicit cache controls (see
1655
+ * Section 4.2.2 of [RFC7234]).
1656
+ */
1657
+ 414: "Request-URI Too Long",
1658
+ /**
1659
+ * The 415 (Unsupported Media Type) status code indicates that the
1660
+ * origin server is refusing to service the request because the payload
1661
+ * is in a format not supported by this method on the target resource.
1662
+ * The format problem might be due to the request's indicated
1663
+ * Content-Type or Content-Encoding, or as a result of inspecting the
1664
+ * data directly.
1665
+ */
1666
+ 415: "Unsupported Media Type",
1667
+ /**
1668
+ * None of the ranges in the request's Range header field overlap the
1669
+ * current extent of the selected resource or that the set of ranges
1670
+ * requested has been rejected due to invalid ranges or an excessive request
1671
+ * of small or overlapping ranges.
1672
+ *
1673
+ * For byte ranges, failing to overlap the current extent means that the
1674
+ * first-byte-pos of all of the byte-range-spec values were greater than the
1675
+ * current length of the selected representation. When this status code is
1676
+ * generated in response to a byte-range request, the sender SHOULD generate
1677
+ * a Content-Range header field specifying the current length of the selected
1678
+ * representation
1679
+ */
1680
+ 416: "Requested Range Not Satisfiable",
1681
+ /**
1682
+ * The 417 (Expectation Failed) status code indicates that the
1683
+ * expectation given in the request's Expect header field
1684
+ * (Section 5.1.1 of [RFC7231]) could not be met by at least one of the
1685
+ * inbound servers.
1686
+ */
1687
+ 417: "Expectation Failed",
1688
+ /**
1689
+ * Any attempt to brew coffee with a teapot should result in the error code
1690
+ * "418 I'm a teapot". The resulting entity body MAY be short and stout.
1691
+ */
1692
+ 418: "I'm a Teapot",
1693
+ /**
1694
+ * The request was directed at a server that is not able to produce a
1695
+ * response. This can be sent by a server that is not configured to produce
1696
+ * responses for the combination of scheme and authority that are included
1697
+ * in the request URI.
1698
+ *
1699
+ * Clients receiving a 421 Misdirected Request response from a server MAY
1700
+ * retry the request -- whether the request method is idempotent or
1701
+ * not -- over a different connection. This is possible if a connection is
1702
+ * reused or if an alternative service is selected ALT-SVC.
1703
+ *
1704
+ * This status code MUST NOT be generated by proxies.
1705
+ *
1706
+ * A 421 response is cacheable by default, i.e., unless otherwise indicated by
1707
+ * the method definition or explicit cache controls
1708
+ */
1709
+ 421: "Misdirected Request",
1710
+ /**
1711
+ * The server understands the content type of the request entity (hence a
1712
+ * 415 Unsupported Media Type status code is inappropriate), and the syntax
1713
+ * of the request entity is correct (thus a 400 Bad Request status code is
1714
+ * inappropriate) but was unable to process the contained instructions.
1715
+ *
1716
+ * For example, this error condition may occur if an XML request body contains
1717
+ * well-formed (i.e., syntactically correct), but semantically erroneous, XML
1718
+ * instructions.
1719
+ */
1720
+ 422: "Unprocessable Entity",
1721
+ /**
1722
+ * The source or destination resource of a method is locked.
1723
+ *
1724
+ * This response SHOULD contain an appropriate precondition or postcondition
1725
+ * code, such as 'lock-token-submitted' or 'no-conflicting-lock'.
1726
+ */
1727
+ 423: "Locked",
1728
+ /**
1729
+ * The method could not be performed on the resource because the requested
1730
+ * action depended on another action and that action failed.
1731
+ *
1732
+ * For example, if a command in a PROPPATCH method fails, then, at minimum,
1733
+ * the rest of the commands will also fail with 424 Failed Dependency.
1734
+ */
1735
+ 424: "Failed Dependency",
1736
+ /**
1737
+ * The 426 (Upgrade Required) status code indicates that the server
1738
+ * refuses to perform the request using the current protocol but might
1739
+ * be willing to do so after the client upgrades to a different
1740
+ * protocol. The server MUST send an Upgrade header field in a 426
1741
+ * response to indicate the required protocol(s) (Section 6.7 of
1742
+ * [RFC7230]).
1743
+ */
1744
+ 426: "Upgrade Required",
1745
+ /**
1746
+ * The origin server requires the request to be conditional.
1747
+ *
1748
+ * Its typical use is to avoid the "lost update" problem, where a client GETs
1749
+ * a resource's state, modifies it, and PUTs it back to the server, when
1750
+ * meanwhile a third party has modified the state on the server, leading
1751
+ * to a conflict. By requiring requests to be conditional, the server can
1752
+ * assure that clients are working with the correct copies.
1753
+ *
1754
+ * Responses using this status code SHOULD explain how to resubmit the request
1755
+ * successfully.
1756
+ *
1757
+ * Responses with the 428 status code MUST NOT be stored by a cache.
1758
+ */
1759
+ 428: "Precondition Required",
1760
+ /**
1761
+ * The user has sent too many requests in a given amount of time
1762
+ * ("rate limiting").
1763
+ *
1764
+ * The response representations SHOULD include details explaining the
1765
+ * condition, and MAY include a Retry-After header indicating how long to
1766
+ * wait before making a new request.
1767
+ *
1768
+ * Responses with the 429 status code MUST NOT be stored by a cache.
1769
+ */
1770
+ 429: "Too Many Requests",
1771
+ /**
1772
+ * The server is unwilling to process the request because its header fields
1773
+ * are too large. The request MAY be resubmitted after reducing the size of
1774
+ * the request header fields.
1775
+ *
1776
+ * It can be used both when the set of request header fields in total is too
1777
+ * large, and when a single header field is at fault. In the latter case, the
1778
+ * response representation SHOULD specify which header field was too large.
1779
+ */
1780
+ 431: "Request Header Fields Too Large",
1781
+ /**
1782
+ * A non-standard status code used to instruct nginx to close the connection
1783
+ * without sending a response to the client, most commonly used to deny
1784
+ * malicious or malformed requests.
1785
+ *
1786
+ * This status code is not seen by the client, it only appears in nginx log
1787
+ * files.
1788
+ */
1789
+ 444: "Connection Closed Without Response",
1790
+ /**
1791
+ * The server is denying access to the resource as a consequence of a legal
1792
+ * demand.
1793
+ *
1794
+ * The server in question might not be an origin server. This type of legal
1795
+ * demand typically most directly affects the operations of ISPs and search
1796
+ * engines.
1797
+ *
1798
+ * Responses using this status code SHOULD include an explanation, in the
1799
+ * response body, of the details of the legal demand: the party making it,
1800
+ * the applicable legislation or regulation, and what classes of person and
1801
+ * resource it applies to.
1802
+ *
1803
+ * The use of the 451 status code implies neither the existence nor
1804
+ * non-existence of the resource named in the request. That is to say, it is
1805
+ * possible that if the legal demands were removed, a request for the
1806
+ * resource still might not succeed.
1807
+ *
1808
+ * Note that in many cases clients can still access the denied resource by
1809
+ * using technical countermeasures such as a VPN or the Tor network.
1810
+ *
1811
+ * A 451 response is cacheable by default; i.e., unless otherwise indicated
1812
+ * by the method definition or explicit cache controls; see RFC7234.
1813
+ */
1814
+ 451: "Unavailable For Legal Reasons",
1815
+ /**
1816
+ * A non-standard status code introduced by nginx for the case when a client
1817
+ * closes the connection while nginx is processing the request.
1818
+ */
1819
+ 499: "Client Closed Request",
1820
+ /**
1821
+ * The 500 (Internal Server Error) status code indicates that the server
1822
+ * encountered an unexpected condition that prevented it from fulfilling
1823
+ * the request.
1824
+ */
1825
+ 500: "Internal Server Error",
1826
+ /**
1827
+ * The 501 (Not Implemented) status code indicates that the server does
1828
+ * not support the functionality required to fulfill the request. This
1829
+ * is the appropriate response when the server does not recognize the
1830
+ * request method and is not capable of supporting it for any resource.
1831
+ *
1832
+ * A 501 response is cacheable by default; i.e., unless otherwise
1833
+ * indicated by the method definition or explicit cache controls (see
1834
+ * Section 4.2.2 of [RFC7234]).
1835
+ */
1836
+ 501: "Not Implemented",
1837
+ /**
1838
+ * The 502 (Bad Gateway) status code indicates that the server, while
1839
+ * acting as a gateway or proxy, received an invalid response from an
1840
+ * inbound server it accessed while attempting to fulfill the request.
1841
+ */
1842
+ 502: "Bad Gateway",
1843
+ /**
1844
+ * The 503 (Service Unavailable) status code indicates that the server
1845
+ * is currently unable to handle the request due to a temporary overload
1846
+ * or scheduled maintenance, which will likely be alleviated after some
1847
+ * delay. The server MAY send a Retry-After header field
1848
+ * (Section 7.1.3 of [RFC7231]) to suggest an appropriate amount of time for
1849
+ * the client to wait before retrying the request.
1850
+ */
1851
+ 503: "Service Unavailable",
1852
+ /**
1853
+ * The 504 (Gateway Timeout) status code indicates that the server,
1854
+ *while acting as a gateway or proxy, did not receive a timely response
1855
+ *from an upstream server it needed to access in order to complete the
1856
+ *request.
1857
+ */
1858
+ 504: "Gateway Timeout",
1859
+ /**
1860
+ * The 505 (HTTP Version Not Supported) status code indicates that the
1861
+ *server does not support, or refuses to support, the major version of
1862
+ *HTTP that was used in the request message. The server is indicating
1863
+ *that it is unable or unwilling to complete the request using the same
1864
+ *major version as the client, as described in Section 2.6 of
1865
+ *[RFC7230], other than with this error message. The server SHOULD
1866
+ *generate a representation for the 505 response that describes why
1867
+ *that version is not supported and what other protocols are supported
1868
+ *by that server.
1869
+ */
1870
+ 505: "HTTP Version Not Supported",
1871
+ /**
1872
+ * The server has an internal configuration error: the chosen variant
1873
+ * resource is configured to engage in transparent content negotiation
1874
+ * itself, and is therefore not a proper end point in the negotiation
1875
+ * process.
1876
+ */
1877
+ 506: "Variant Also Negotiates",
1878
+ /**
1879
+ * The method could not be performed on the resource because the server is
1880
+ * unable to store the representation needed to successfully complete the
1881
+ * request.
1882
+ *
1883
+ * This condition is considered to be temporary. If the request that received
1884
+ * this status code was the result of a user action, the request MUST NOT be
1885
+ * repeated until it is requested by a separate user action.
1886
+ */
1887
+ 507: "Insufficient Storage",
1888
+ /**
1889
+ * The server terminated an operation because it encountered an infinite loop
1890
+ * while processing a request with "Depth: infinity". This status indicates
1891
+ * that the entire operation failed.
1892
+ */
1893
+ 508: "Loop Detected",
1894
+ /**
1895
+ * The policy for accessing the resource has not been met in the request. The
1896
+ * server should send back all the information necessary for the client to
1897
+ * issue an extended request.
1898
+ *
1899
+ * It is outside the scope of this specification to specify how the
1900
+ * extensions inform the client.
1901
+ *
1902
+ * If the 510 response contains information about extensions that were not
1903
+ * present in the initial request then the client MAY repeat the request if
1904
+ * it has reason to believe it can fulfill the extension policy by modifying
1905
+ * the request according to the information provided in the 510 response.
1906
+ * Otherwise the client MAY present any entity included in the 510 response
1907
+ * to the user, since that entity may include relevant diagnostic information.
1908
+ */
1909
+ 510: "Not Extended",
1910
+ /**
1911
+ * The client needs to authenticate to gain network access.
1912
+ *
1913
+ * The response representation SHOULD contain a link to a resource that
1914
+ * allows the user to submit credentials (e.g., with an HTML form).
1915
+ *
1916
+ * Note that the 511 response SHOULD NOT contain a challenge or the login
1917
+ * interface itself, because browsers would show the login interface as being
1918
+ * associated with the originally requested URL, which may cause confusion.
1919
+ *
1920
+ * The 511 status SHOULD NOT be generated by origin servers; it is intended
1921
+ * for use by intercepting proxies that are interposed as a means of
1922
+ * controlling access to the network.
1923
+ *
1924
+ * Responses with the 511 status code MUST NOT be stored by a cache.
1925
+ */
1926
+ 511: "Network Authentication Required",
1927
+ /**
1928
+ * This status code is not specified in any RFCs, but is used by some HTTP
1929
+ * proxies to signal a network connect timeout behind the proxy to a client
1930
+ * in front of the proxy.
1931
+ */
1932
+ 599: "Network Connect Timeout Error"
1933
+ };
1934
+ var isValidStatusCode = (code) => !!HTTPStatuses[code];
1935
+ var isInformational = (code) => code >= 100 && code < 200;
1936
+ var isSuccessful = (code) => code >= 200 && code < 300;
1937
+ var isRedirection = (code) => code >= 300 && code < 400;
1938
+ var isClientError = (code) => code >= 400 && code < 500;
1939
+ var isServerError = (code) => code >= 500;
1940
+ var getCodeForStatus = (status) => {
1941
+ const clnStr = status.toLocaleLowerCase().trim();
1942
+ const entry = Object.entries(HTTPStatuses).find(
1943
+ (ent) => ent[1].toLowerCase() === clnStr
1944
+ );
1945
+ if (entry) return parseInt(entry[0]);
1946
+ return null;
1947
+ };
1948
+ var httpStatusCodes_default = HTTPStatuses;
1949
+
1950
+ // src/http/openApiV3Generator/openApiV3Generator.ts
1951
+ function toUpperCase(str) {
1952
+ return str.charAt(0).toUpperCase() + str.slice(1);
1953
+ }
1954
+ function transformBasePath(basePath) {
1955
+ if (basePath.startsWith("/")) {
1956
+ return toUpperCase(basePath.slice(1));
1957
+ }
1958
+ return `/${basePath}`;
1959
+ }
1960
+ function swaggerDocument(port, tags, paths) {
1961
+ return {
1962
+ openapi: "3.1.0",
1963
+ info: {
1964
+ title: process.env.API_TITLE || "",
1965
+ version: process.env.VERSION || "1.0.0"
1966
+ },
1967
+ components: {
1968
+ securitySchemes: {
1969
+ bearer: {
1970
+ type: "http",
1971
+ scheme: "bearer",
1972
+ bearerFormat: "JWT"
1973
+ }
1974
+ }
1975
+ },
1976
+ tags,
1977
+ servers: [
1978
+ {
1979
+ url: `http://localhost:${port}`
1980
+ }
1981
+ ],
1982
+ paths
1983
+ };
1984
+ }
1985
+ function contentResolver(schemaValidator, body) {
1986
+ const bodySpec = schemaValidator.openapi(body);
1987
+ return body === schemaValidator.string ? {
1988
+ "plain/text": {
1989
+ schema: bodySpec
1990
+ }
1991
+ } : {
1992
+ "application/json": {
1993
+ schema: bodySpec
1994
+ }
1995
+ };
1996
+ }
1997
+ function generateSwaggerDocument(schemaValidator, port, routers) {
1998
+ const tags = [];
1999
+ const paths = {};
2000
+ routers.flat(Infinity).forEach((router) => {
2001
+ const controllerName = transformBasePath(router.basePath);
2002
+ tags.push({
2003
+ name: controllerName,
2004
+ description: `${controllerName} Operations`
2005
+ });
2006
+ router.routes.forEach((route) => {
2007
+ const fullPath = `${router.basePath}${route.path === "/" ? "" : route.path}`.replace(
2008
+ /:(\w+)/g,
2009
+ "{$1}"
2010
+ );
2011
+ if (!paths[fullPath]) {
2012
+ paths[fullPath] = {};
2013
+ }
2014
+ const { name, summary, query, requestHeaders } = route.contractDetails;
2015
+ const responses = {};
2016
+ for (const key in route.contractDetails.responses) {
2017
+ responses[key] = {
2018
+ description: httpStatusCodes_default[key],
2019
+ content: contentResolver(
2020
+ schemaValidator,
2021
+ route.contractDetails.responses[key]
2022
+ )
2023
+ };
2024
+ }
2025
+ const pathItemObject = {
2026
+ tags: [controllerName],
2027
+ summary: `${name}: ${summary}`,
2028
+ parameters: [],
2029
+ responses
2030
+ };
2031
+ if (route.contractDetails.params) {
2032
+ for (const key in route.contractDetails.params) {
2033
+ pathItemObject.parameters?.push({
2034
+ name: key,
2035
+ in: "path"
2036
+ });
2037
+ }
2038
+ }
2039
+ const body = route.contractDetails.body;
2040
+ if (body) {
2041
+ pathItemObject.requestBody = {
2042
+ required: true,
2043
+ content: contentResolver(schemaValidator, body)
2044
+ };
2045
+ }
2046
+ if (requestHeaders) {
2047
+ for (const key in requestHeaders) {
2048
+ pathItemObject.parameters?.push({
2049
+ name: key,
2050
+ in: "header"
2051
+ });
2052
+ }
2053
+ }
2054
+ if (query) {
2055
+ for (const key in query) {
2056
+ pathItemObject.parameters?.push({
2057
+ name: key,
2058
+ in: "query"
2059
+ });
2060
+ }
2061
+ }
2062
+ if (route.contractDetails.auth) {
2063
+ responses[401] = {
2064
+ description: httpStatusCodes_default[401],
2065
+ content: contentResolver(schemaValidator, schemaValidator.string)
2066
+ };
2067
+ responses[403] = {
2068
+ description: httpStatusCodes_default[403],
2069
+ content: contentResolver(schemaValidator, schemaValidator.string)
2070
+ };
2071
+ if (route.contractDetails.auth.method === "jwt") {
2072
+ pathItemObject.security = [
2073
+ {
2074
+ bearer: Array.from(
2075
+ route.contractDetails.auth.allowedPermissions?.values() || []
2076
+ )
2077
+ }
2078
+ ];
2079
+ }
2080
+ }
2081
+ if (route.method !== "middleware") {
2082
+ paths[fullPath][route.method] = pathItemObject;
2083
+ }
2084
+ });
2085
+ });
2086
+ return swaggerDocument(port, tags, paths);
2087
+ }
2088
+
2089
+ // src/http/middleware/response/parse.middleware.ts
2090
+ function parse2(req, res, next) {
2091
+ console.debug("[MIDDLEWARE] parseResponse started");
2092
+ const { headers, responses } = res.responseSchemas;
2093
+ const parsedResponse = req.schemaValidator.parse(
2094
+ responses?.[res.statusCode],
2095
+ res.bodyData
2096
+ );
2097
+ const parsedHeaders = req.schemaValidator.parse(
2098
+ headers ?? req.schemaValidator.unknown,
2099
+ res.getHeaders()
2100
+ );
2101
+ const parseErrors = [];
2102
+ if (!parsedHeaders.ok) {
2103
+ parseErrors.push(
2104
+ `${parsedHeaders.error ? `Header ${parsedHeaders.error}` : ""}`
2105
+ );
2106
+ }
2107
+ if (!parsedResponse.ok) {
2108
+ parseErrors.push(
2109
+ `${parsedResponse.error ? `Response ${parsedResponse.error}` : ""}`
2110
+ );
2111
+ }
2112
+ if (parseErrors.length > 0) {
2113
+ switch (req.contractDetails.options?.responseValidation) {
2114
+ default:
2115
+ case "error":
2116
+ next?.(new Error(`Invalid response:
2117
+ ${parseErrors.join("\n\n")}`));
2118
+ break;
2119
+ case "warning":
2120
+ console.warn(`Invalid response:
2121
+ ${parseErrors.join("\n\n")}`);
2122
+ break;
2123
+ case "none":
2124
+ break;
2125
+ }
2126
+ }
2127
+ next?.();
2128
+ }
2129
+
2130
+ // src/http/utils/enrichExpressLikeSend.ts
2131
+ function enrichExpressLikeSend(instance, req, res, originalSend, data, shouldEnrich) {
2132
+ let parseErrorSent;
2133
+ if (shouldEnrich) {
2134
+ if (res.statusCode === 404) {
2135
+ res.status(404);
2136
+ originalSend.call(instance, "Not Found");
2137
+ }
2138
+ parse2(req, res, (err) => {
2139
+ if (err) {
2140
+ let errorString = err.message;
2141
+ if (res.locals.errorMessage) {
2142
+ errorString += `
2143
+ ------------------
2144
+ ${res.locals.errorMessage}`;
2145
+ }
2146
+ res.status(500);
2147
+ originalSend.call(instance, errorString);
2148
+ parseErrorSent = true;
2149
+ }
2150
+ });
2151
+ }
2152
+ if (!parseErrorSent) {
2153
+ originalSend.call(instance, data);
2154
+ }
2155
+ }
2156
+ // Annotate the CommonJS export names for ESM import in node:
2157
+ 0 && (module.exports = {
2158
+ ForklaunchExpressLikeApplication,
2159
+ ForklaunchExpressLikeRouter,
2160
+ HTTPStatuses,
2161
+ delete_,
2162
+ enrichExpressLikeSend,
2163
+ generateSwaggerDocument,
2164
+ get,
2165
+ getCodeForStatus,
2166
+ head,
2167
+ isClientError,
2168
+ isForklaunchRouter,
2169
+ isInformational,
2170
+ isRedirection,
2171
+ isServerError,
2172
+ isSuccessful,
2173
+ isValidStatusCode,
2174
+ middleware,
2175
+ options,
2176
+ patch,
2177
+ post,
2178
+ put,
2179
+ trace,
2180
+ typedHandler
2181
+ });