@furystack/rest-service 7.0.0 → 7.0.2

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 (189) hide show
  1. package/{types → esm}/actions/error-action.d.ts +1 -1
  2. package/{types → esm}/actions/error-action.d.ts.map +1 -1
  3. package/esm/actions/error-action.js +25 -0
  4. package/esm/actions/error-action.js.map +1 -0
  5. package/{types → esm}/actions/get-current-user.d.ts +1 -1
  6. package/{types → esm}/actions/get-current-user.d.ts.map +1 -1
  7. package/esm/actions/get-current-user.js +12 -0
  8. package/esm/actions/get-current-user.js.map +1 -0
  9. package/esm/actions/index.d.ts +7 -0
  10. package/esm/actions/index.d.ts.map +1 -0
  11. package/esm/actions/index.js +7 -0
  12. package/esm/actions/index.js.map +1 -0
  13. package/{types → esm}/actions/is-authenticated.d.ts +1 -1
  14. package/{types → esm}/actions/is-authenticated.d.ts.map +1 -1
  15. package/esm/actions/is-authenticated.js +13 -0
  16. package/esm/actions/is-authenticated.js.map +1 -0
  17. package/{types → esm}/actions/login.d.ts +2 -2
  18. package/esm/actions/login.d.ts.map +1 -0
  19. package/esm/actions/login.js +22 -0
  20. package/esm/actions/login.js.map +1 -0
  21. package/{types → esm}/actions/logout.d.ts +1 -1
  22. package/{types → esm}/actions/logout.d.ts.map +1 -1
  23. package/esm/actions/logout.js +15 -0
  24. package/esm/actions/logout.js.map +1 -0
  25. package/{types → esm}/actions/not-found-action.d.ts +1 -1
  26. package/{types → esm}/actions/not-found-action.d.ts.map +1 -1
  27. package/esm/actions/not-found-action.js +10 -0
  28. package/esm/actions/not-found-action.js.map +1 -0
  29. package/{types → esm}/api-manager.d.ts +4 -4
  30. package/{types → esm}/api-manager.d.ts.map +1 -1
  31. package/esm/api-manager.js +153 -0
  32. package/esm/api-manager.js.map +1 -0
  33. package/{types → esm}/authenticate.d.ts +1 -1
  34. package/{types → esm}/authenticate.d.ts.map +1 -1
  35. package/esm/authenticate.js +16 -0
  36. package/esm/authenticate.js.map +1 -0
  37. package/{types → esm}/authorize.d.ts +1 -1
  38. package/{types → esm}/authorize.d.ts.map +1 -1
  39. package/esm/authorize.js +19 -0
  40. package/esm/authorize.js.map +1 -0
  41. package/{types → esm}/endpoint-generators/create-delete-endpoint.d.ts +1 -1
  42. package/{types → esm}/endpoint-generators/create-delete-endpoint.d.ts.map +1 -1
  43. package/esm/endpoint-generators/create-delete-endpoint.js +20 -0
  44. package/esm/endpoint-generators/create-delete-endpoint.js.map +1 -0
  45. package/{types → esm}/endpoint-generators/create-get-collection-endpoint.d.ts +1 -1
  46. package/{types → esm}/endpoint-generators/create-get-collection-endpoint.d.ts.map +1 -1
  47. package/esm/endpoint-generators/create-get-collection-endpoint.js +22 -0
  48. package/esm/endpoint-generators/create-get-collection-endpoint.js.map +1 -0
  49. package/{types → esm}/endpoint-generators/create-get-entity-endpoint.d.ts +1 -1
  50. package/{types → esm}/endpoint-generators/create-get-entity-endpoint.d.ts.map +1 -1
  51. package/esm/endpoint-generators/create-get-entity-endpoint.js +25 -0
  52. package/esm/endpoint-generators/create-get-entity-endpoint.js.map +1 -0
  53. package/{types → esm}/endpoint-generators/create-patch-endpoint.d.ts +1 -1
  54. package/{types → esm}/endpoint-generators/create-patch-endpoint.d.ts.map +1 -1
  55. package/esm/endpoint-generators/create-patch-endpoint.js +22 -0
  56. package/esm/endpoint-generators/create-patch-endpoint.js.map +1 -0
  57. package/{types → esm}/endpoint-generators/create-post-endpoint.d.ts +1 -1
  58. package/{types → esm}/endpoint-generators/create-post-endpoint.d.ts.map +1 -1
  59. package/esm/endpoint-generators/create-post-endpoint.js +25 -0
  60. package/esm/endpoint-generators/create-post-endpoint.js.map +1 -0
  61. package/esm/endpoint-generators/index.d.ts +6 -0
  62. package/{types → esm}/endpoint-generators/index.d.ts.map +1 -1
  63. package/esm/endpoint-generators/index.js +6 -0
  64. package/esm/endpoint-generators/index.js.map +1 -0
  65. package/esm/endpoint-generators/utils.js +23 -0
  66. package/esm/endpoint-generators/utils.js.map +1 -0
  67. package/{types → esm}/helpers.d.ts +4 -4
  68. package/esm/helpers.d.ts.map +1 -0
  69. package/esm/helpers.js +28 -0
  70. package/esm/helpers.js.map +1 -0
  71. package/{types → esm}/http-authentication-settings.d.ts +1 -1
  72. package/{types → esm}/http-authentication-settings.d.ts.map +1 -1
  73. package/esm/http-authentication-settings.js +26 -0
  74. package/esm/http-authentication-settings.js.map +1 -0
  75. package/{types → esm}/http-user-context.d.ts +2 -2
  76. package/{types → esm}/http-user-context.d.ts.map +1 -1
  77. package/esm/http-user-context.js +168 -0
  78. package/esm/http-user-context.js.map +1 -0
  79. package/esm/incoming-message-extensions.js +11 -0
  80. package/esm/incoming-message-extensions.js.map +1 -0
  81. package/esm/index.d.ts +19 -0
  82. package/esm/index.d.ts.map +1 -0
  83. package/esm/index.js +19 -0
  84. package/esm/index.js.map +1 -0
  85. package/esm/mime-types.js +333 -0
  86. package/esm/mime-types.js.map +1 -0
  87. package/esm/models/cors-options.js +2 -0
  88. package/esm/models/cors-options.js.map +1 -0
  89. package/esm/models/default-session.js +6 -0
  90. package/esm/models/default-session.js.map +1 -0
  91. package/esm/models/index.d.ts +3 -0
  92. package/esm/models/index.d.ts.map +1 -0
  93. package/esm/models/index.js +3 -0
  94. package/esm/models/index.js.map +1 -0
  95. package/esm/request-action-implementation.js +34 -0
  96. package/esm/request-action-implementation.js.map +1 -0
  97. package/esm/schema-validator/index.d.ts +3 -0
  98. package/{types → esm}/schema-validator/index.d.ts.map +1 -1
  99. package/esm/schema-validator/index.js +3 -0
  100. package/esm/schema-validator/index.js.map +1 -0
  101. package/esm/schema-validator/schema-validation-error.js +11 -0
  102. package/esm/schema-validator/schema-validation-error.js.map +1 -0
  103. package/esm/schema-validator/schema-validator.js +31 -0
  104. package/esm/schema-validator/schema-validator.js.map +1 -0
  105. package/esm/schema-validator/validate-examples.js +26 -0
  106. package/esm/schema-validator/validate-examples.js.map +1 -0
  107. package/{types → esm}/server-manager.d.ts +1 -1
  108. package/esm/server-manager.js +73 -0
  109. package/esm/server-manager.js.map +1 -0
  110. package/{types → esm}/server-response-extensions.d.ts +1 -1
  111. package/{types → esm}/server-response-extensions.d.ts.map +1 -1
  112. package/esm/server-response-extensions.js +12 -0
  113. package/esm/server-response-extensions.js.map +1 -0
  114. package/{types → esm}/static-server-manager.d.ts +1 -1
  115. package/esm/static-server-manager.js +68 -0
  116. package/esm/static-server-manager.js.map +1 -0
  117. package/{types → esm}/utils.d.ts +1 -1
  118. package/{types → esm}/utils.d.ts.map +1 -1
  119. package/esm/utils.js +70 -0
  120. package/esm/utils.js.map +1 -0
  121. package/{types → esm}/validate.d.ts +1 -1
  122. package/{types → esm}/validate.d.ts.map +1 -1
  123. package/esm/validate.integration.schema.js +2 -0
  124. package/esm/validate.integration.schema.js.map +1 -0
  125. package/esm/validate.integration.spec.schema.json +903 -0
  126. package/esm/validate.js +43 -0
  127. package/esm/validate.js.map +1 -0
  128. package/package.json +11 -20
  129. package/src/actions/error-action.ts +3 -3
  130. package/src/actions/get-current-user.ts +3 -3
  131. package/src/actions/index.ts +6 -6
  132. package/src/actions/is-authenticated.ts +2 -2
  133. package/src/actions/login.ts +4 -4
  134. package/src/actions/logout.ts +3 -3
  135. package/src/actions/not-found-action.ts +2 -2
  136. package/src/api-manager.ts +10 -9
  137. package/src/authenticate.ts +3 -3
  138. package/src/authorize.ts +2 -2
  139. package/src/endpoint-generators/create-delete-endpoint.ts +2 -2
  140. package/src/endpoint-generators/create-get-collection-endpoint.ts +2 -2
  141. package/src/endpoint-generators/create-get-entity-endpoint.ts +2 -2
  142. package/src/endpoint-generators/create-patch-endpoint.ts +2 -2
  143. package/src/endpoint-generators/create-post-endpoint.ts +2 -2
  144. package/src/endpoint-generators/index.ts +5 -5
  145. package/src/endpoint-generators/utils.ts +1 -1
  146. package/src/helpers.ts +6 -6
  147. package/src/http-authentication-settings.ts +1 -1
  148. package/src/http-user-context.ts +2 -2
  149. package/src/incoming-message-extensions.ts +1 -1
  150. package/src/index.ts +18 -18
  151. package/src/models/index.ts +2 -2
  152. package/src/schema-validator/index.ts +2 -2
  153. package/src/schema-validator/schema-validator.ts +3 -3
  154. package/src/server-response-extensions.ts +1 -1
  155. package/src/static-server-manager.ts +2 -2
  156. package/src/utils.ts +1 -1
  157. package/src/validate.ts +2 -2
  158. package/types/actions/index.d.ts +0 -7
  159. package/types/actions/index.d.ts.map +0 -1
  160. package/types/actions/login.d.ts.map +0 -1
  161. package/types/endpoint-generators/index.d.ts +0 -6
  162. package/types/helpers.d.ts.map +0 -1
  163. package/types/index.d.ts +0 -19
  164. package/types/index.d.ts.map +0 -1
  165. package/types/models/index.d.ts +0 -3
  166. package/types/models/index.d.ts.map +0 -1
  167. package/types/schema-validator/index.d.ts +0 -3
  168. /package/{types → esm}/endpoint-generators/utils.d.ts +0 -0
  169. /package/{types → esm}/endpoint-generators/utils.d.ts.map +0 -0
  170. /package/{types → esm}/incoming-message-extensions.d.ts +0 -0
  171. /package/{types → esm}/incoming-message-extensions.d.ts.map +0 -0
  172. /package/{types → esm}/mime-types.d.ts +0 -0
  173. /package/{types → esm}/mime-types.d.ts.map +0 -0
  174. /package/{types → esm}/models/cors-options.d.ts +0 -0
  175. /package/{types → esm}/models/cors-options.d.ts.map +0 -0
  176. /package/{types → esm}/models/default-session.d.ts +0 -0
  177. /package/{types → esm}/models/default-session.d.ts.map +0 -0
  178. /package/{types → esm}/request-action-implementation.d.ts +0 -0
  179. /package/{types → esm}/request-action-implementation.d.ts.map +0 -0
  180. /package/{types → esm}/schema-validator/schema-validation-error.d.ts +0 -0
  181. /package/{types → esm}/schema-validator/schema-validation-error.d.ts.map +0 -0
  182. /package/{types → esm}/schema-validator/schema-validator.d.ts +0 -0
  183. /package/{types → esm}/schema-validator/schema-validator.d.ts.map +0 -0
  184. /package/{types → esm}/schema-validator/validate-examples.d.ts +0 -0
  185. /package/{types → esm}/schema-validator/validate-examples.d.ts.map +0 -0
  186. /package/{types → esm}/server-manager.d.ts.map +0 -0
  187. /package/{types → esm}/static-server-manager.d.ts.map +0 -0
  188. /package/{types → esm}/validate.integration.schema.d.ts +0 -0
  189. /package/{types → esm}/validate.integration.schema.d.ts.map +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"server-response-extensions.d.ts","sourceRoot":"","sources":["../src/server-response-extensions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAEnE,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,CAAC,CAAA;IACP,OAAO,CAAC,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;CAClC;AACD,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;CAClC;AAED,OAAO,QAAQ,MAAM,CAAC;IACpB,UAAiB,cAAc;QAC7B,gBAAgB,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI,CAAA;KACvD;CACF"}
1
+ {"version":3,"file":"server-response-extensions.d.ts","sourceRoot":"","sources":["../src/server-response-extensions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAA;AAEtE,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,CAAC,CAAA;IACP,OAAO,CAAC,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;CAClC;AACD,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;CAClC;AAED,OAAO,QAAQ,MAAM,CAAC;IACpB,UAAiB,cAAc;QAC7B,gBAAgB,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI,CAAA;KACvD;CACF"}
@@ -0,0 +1,12 @@
1
+ import http from 'http';
2
+ http.ServerResponse.prototype.sendActionResult = function (options) {
3
+ if (typeof options.chunk === 'object') {
4
+ options.chunk = JSON.stringify(options.chunk);
5
+ }
6
+ if (typeof options.chunk === 'string' && options.chunk === 'BypassResult') {
7
+ return;
8
+ }
9
+ this.writeHead(options.statusCode, options.headers);
10
+ this.end(options.chunk);
11
+ };
12
+ //# sourceMappingURL=server-response-extensions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-response-extensions.js","sourceRoot":"","sources":["../src/server-response-extensions.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AAoBvB,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,gBAAgB,GAAG,UAAa,OAAwB;IACpF,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,EAAE;QACrC,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAQ,CAAA;KACrD;IACD,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,KAAK,cAAc,EAAE;QACzE,OAAM;KACP;IACD,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IACnD,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AACzB,CAAC,CAAA"}
@@ -1,4 +1,4 @@
1
- /// <reference types="node" />
1
+ /// <reference types="node" resolution-mode="require"/>
2
2
  import type { IncomingMessage, OutgoingHttpHeaders } from 'http';
3
3
  export interface StaticServerOptions {
4
4
  baseUrl: string;
@@ -0,0 +1,68 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Injectable, Injected } from '@furystack/inject';
11
+ import { createReadStream } from 'fs';
12
+ import { stat } from 'fs/promises';
13
+ import { getMimeForFile } from './mime-types.js';
14
+ import { join, normalize, sep } from 'path';
15
+ import { ServerManager } from './server-manager.js';
16
+ let StaticServerManager = class StaticServerManager {
17
+ constructor() {
18
+ this.shouldExec = (baseUrl) => ({ req }) => req.url &&
19
+ req.method?.toUpperCase() === 'GET' &&
20
+ (req.url === baseUrl || req.url.startsWith(baseUrl[baseUrl.length - 1] === '/' ? baseUrl : `${baseUrl}/`))
21
+ ? true
22
+ : false;
23
+ this.onRequest = ({ path, baseUrl, fallback, headers, }) => {
24
+ return async ({ req, res }) => {
25
+ const filePath = req.url.substring(baseUrl.length - 1).replaceAll('/', sep);
26
+ const fullPath = normalize(join(path, filePath));
27
+ try {
28
+ await this.sendFile({ fullPath, res, headers });
29
+ }
30
+ catch (error) {
31
+ if (fallback) {
32
+ await this.sendFile({ fullPath: join(path, fallback), res, headers });
33
+ }
34
+ else {
35
+ res.writeHead(404, { 'Content-Type': 'text/plain' });
36
+ res.end('Not found');
37
+ }
38
+ }
39
+ };
40
+ };
41
+ }
42
+ async sendFile({ fullPath, headers, res, }) {
43
+ const { size } = await stat(fullPath);
44
+ const head = {
45
+ ...headers,
46
+ 'Content-Length': size,
47
+ 'Content-Type': getMimeForFile(fullPath),
48
+ };
49
+ res.writeHead(200, head);
50
+ await new Promise((resolve, reject) => createReadStream(fullPath, { autoClose: true }).once('finish', resolve).once('error', reject).pipe(res));
51
+ }
52
+ async addStaticSite(options) {
53
+ const server = await this.serverManager.getOrCreate({ hostName: options.hostName, port: options.port });
54
+ server.apis.push({
55
+ shouldExec: this.shouldExec(options.baseUrl),
56
+ onRequest: this.onRequest({ ...options }),
57
+ });
58
+ }
59
+ };
60
+ __decorate([
61
+ Injected(ServerManager),
62
+ __metadata("design:type", ServerManager)
63
+ ], StaticServerManager.prototype, "serverManager", void 0);
64
+ StaticServerManager = __decorate([
65
+ Injectable({ lifetime: 'singleton' })
66
+ ], StaticServerManager);
67
+ export { StaticServerManager };
68
+ //# sourceMappingURL=static-server-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"static-server-manager.js","sourceRoot":"","sources":["../src/static-server-manager.ts"],"names":[],"mappings":"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"}
@@ -1,5 +1,5 @@
1
1
  import type { IncomingMessage, ServerResponse } from 'http';
2
- import type { CorsOptions } from './models/cors-options';
2
+ import type { CorsOptions } from './models/cors-options.js';
3
3
  /**
4
4
  * A collection of various HTTP API related utilities
5
5
  */
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAA;AAE3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD;;GAEG;AACH,qBACa,KAAK;IACH,eAAe,CAAC,eAAe,EAAE,eAAe;IAuB7D;;;;OAIG;IACU,YAAY,CAAC,CAAC,EAAE,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,CAAC,CAAC;IAM1E;;;;;OAKG;IACI,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,eAAe,EAAE,cAAc,EAAE,cAAc;CAkB7G"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAA;AAE3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAE3D;;GAEG;AACH,qBACa,KAAK;IACH,eAAe,CAAC,eAAe,EAAE,eAAe;IAuB7D;;;;OAIG;IACU,YAAY,CAAC,CAAC,EAAE,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,CAAC,CAAC;IAM1E;;;;;OAKG;IACI,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,eAAe,EAAE,cAAc,EAAE,cAAc;CAkB7G"}
package/esm/utils.js ADDED
@@ -0,0 +1,70 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Injectable } from '@furystack/inject';
8
+ /**
9
+ * A collection of various HTTP API related utilities
10
+ */
11
+ let Utils = class Utils {
12
+ async readPostBodyRaw(incomingMessage) {
13
+ if (!incomingMessage.readable) {
14
+ throw Error('Incoming message is not readable');
15
+ }
16
+ let body = '';
17
+ await new Promise((resolve, reject) => {
18
+ incomingMessage.on('readable', () => {
19
+ const data = incomingMessage.read();
20
+ if (data) {
21
+ body += data;
22
+ }
23
+ });
24
+ incomingMessage.on('end', () => {
25
+ resolve();
26
+ });
27
+ incomingMessage.on('error', (err) => {
28
+ reject(err);
29
+ });
30
+ });
31
+ return body;
32
+ }
33
+ /**
34
+ * Reads the post's body and returns a promise with a parsed value
35
+ * @param incomingMessage The incoming message instance
36
+ * @returns the parsed object from the post body
37
+ */
38
+ async readPostBody(incomingMessage) {
39
+ const body = incomingMessage.postBody || JSON.parse(await this.readPostBodyRaw(incomingMessage));
40
+ incomingMessage.postBody = body;
41
+ return body;
42
+ }
43
+ /**
44
+ * Adds the specified CORS headers to the response
45
+ * @param options The CORS Options object
46
+ * @param incomingMessage The incoming message instance
47
+ * @param serverResponse The outgoing response instance
48
+ */
49
+ addCorsHeaders(options, incomingMessage, serverResponse) {
50
+ if (incomingMessage.headers &&
51
+ incomingMessage.headers.origin !== incomingMessage.headers.host &&
52
+ options.origins.some((origin) => origin === incomingMessage.headers.origin)) {
53
+ serverResponse.setHeader('Access-Control-Allow-Origin', incomingMessage.headers.origin);
54
+ if (options.credentials) {
55
+ serverResponse.setHeader('Access-Control-Allow-Credentials', 'true');
56
+ }
57
+ if (options.headers && options.headers.length) {
58
+ serverResponse.setHeader('Access-Control-Allow-Headers', options.headers.join(', '));
59
+ }
60
+ if (options.methods && options.methods.length) {
61
+ serverResponse.setHeader('Access-Control-Allow-Methods', options.methods.join(', '));
62
+ }
63
+ }
64
+ }
65
+ };
66
+ Utils = __decorate([
67
+ Injectable({ lifetime: 'transient' })
68
+ ], Utils);
69
+ export { Utils };
70
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAG9C;;GAEG;AAEH,IAAa,KAAK,GAAlB,MAAa,KAAK;IACT,KAAK,CAAC,eAAe,CAAC,eAAgC;QAC3D,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE;YAC7B,MAAM,KAAK,CAAC,kCAAkC,CAAC,CAAA;SAChD;QAED,IAAI,IAAI,GAAG,EAAE,CAAA;QACb,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC1C,eAAe,CAAC,EAAE,CAAC,UAAU,EAAE,GAAG,EAAE;gBAClC,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,EAAE,CAAA;gBACnC,IAAI,IAAI,EAAE;oBACR,IAAI,IAAI,IAAI,CAAA;iBACb;YACH,CAAC,CAAC,CAAA;YACF,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;gBAC7B,OAAO,EAAE,CAAA;YACX,CAAC,CAAC,CAAA;YACF,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;gBAClC,MAAM,CAAC,GAAG,CAAC,CAAA;YACb,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,YAAY,CAAI,eAAgC;QAC3D,MAAM,IAAI,GAAG,eAAe,CAAC,QAAQ,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC,CAAA;QAChG,eAAe,CAAC,QAAQ,GAAG,IAAI,CAAA;QAC/B,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;;;OAKG;IACI,cAAc,CAAC,OAAoB,EAAE,eAAgC,EAAE,cAA8B;QAC1G,IACE,eAAe,CAAC,OAAO;YACvB,eAAe,CAAC,OAAO,CAAC,MAAM,KAAK,eAAe,CAAC,OAAO,CAAC,IAAI;YAC/D,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,EAC3E;YACA,cAAc,CAAC,SAAS,CAAC,6BAA6B,EAAE,eAAe,CAAC,OAAO,CAAC,MAAgB,CAAC,CAAA;YACjG,IAAI,OAAO,CAAC,WAAW,EAAE;gBACvB,cAAc,CAAC,SAAS,CAAC,kCAAkC,EAAE,MAAM,CAAC,CAAA;aACrE;YACD,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE;gBAC7C,cAAc,CAAC,SAAS,CAAC,8BAA8B,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;aACrF;YACD,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE;gBAC7C,cAAc,CAAC,SAAS,CAAC,8BAA8B,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;aACrF;SACF;IACH,CAAC;CACF,CAAA;AA3DY,KAAK;IADjB,UAAU,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;GACzB,KAAK,CA2DjB;SA3DY,KAAK"}
@@ -1,4 +1,4 @@
1
- import type { RequestAction } from './request-action-implementation';
1
+ import type { RequestAction } from './request-action-implementation.js';
2
2
  export declare const Validate: <TSchema extends {
3
3
  definitions: {
4
4
  [K: string]: any;
@@ -1 +1 @@
1
- {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,aAAa,EAAwB,MAAM,iCAAiC,CAAA;AAGxG,eAAO,MAAM,QAAQ;;;;;IAEjB;;OAEG;;IAEH;;OAEG;;;YAGgB,GAAG;gDA6CvB,CAAA"}
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,aAAa,EAAwB,MAAM,oCAAoC,CAAA;AAG3G,eAAO,MAAM,QAAQ;;;;;IAEjB;;OAEG;;IAEH;;OAEG;;;YAGgB,GAAG;gDA6CvB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=validate.integration.schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.integration.schema.js","sourceRoot":"","sources":["../src/validate.integration.schema.ts"],"names":[],"mappings":""}