@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,4 +1,4 @@
1
- import type { RequestAction } from '../request-action-implementation';
1
+ import type { RequestAction } from '../request-action-implementation.js';
2
2
  /**
3
3
  * Action for unhandled (500) errors
4
4
  * Returns a serialized error instance in JSON format.
@@ -1 +1 @@
1
- {"version":3,"file":"error-action.d.ts","sourceRoot":"","sources":["../../src/actions/error-action.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAIrE;;;GAGG;AAEH,eAAO,MAAM,WAAW,EAAE,aAAa,CAAC;IACtC,IAAI,EAAE,OAAO,CAAA;IACb,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;CAC5B,CAoBA,CAAA"}
1
+ {"version":3,"file":"error-action.d.ts","sourceRoot":"","sources":["../../src/actions/error-action.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAIxE;;;GAGG;AAEH,eAAO,MAAM,WAAW,EAAE,aAAa,CAAC;IACtC,IAAI,EAAE,OAAO,CAAA;IACb,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;CAC5B,CAoBA,CAAA"}
@@ -0,0 +1,25 @@
1
+ import { RequestError } from '@furystack/rest';
2
+ import { AuthorizationError } from '@furystack/core';
3
+ import { JsonResult } from '../request-action-implementation.js';
4
+ import { SchemaValidationError } from '../schema-validator/schema-validation-error.js';
5
+ /**
6
+ * Action for unhandled (500) errors
7
+ * Returns a serialized error instance in JSON format.
8
+ */
9
+ export const ErrorAction = async ({ getBody }) => {
10
+ const body = await getBody();
11
+ if (body instanceof SchemaValidationError) {
12
+ return JsonResult({ message: body.message, errors: body.errors }, 400);
13
+ }
14
+ if (body instanceof RequestError) {
15
+ return JsonResult({ message: body.message }, body.responseCode);
16
+ }
17
+ if (body instanceof AuthorizationError) {
18
+ return JsonResult({ message: body.message }, 403);
19
+ }
20
+ if (body instanceof Error) {
21
+ return JsonResult({ message: body.message }, 500);
22
+ }
23
+ return JsonResult({ message: 'An unexpected error happened' }, 500);
24
+ };
25
+ //# sourceMappingURL=error-action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-action.js","sourceRoot":"","sources":["../../src/actions/error-action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEpD,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAA;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gDAAgD,CAAA;AAEtF;;;GAGG;AAEH,MAAM,CAAC,MAAM,WAAW,GAGnB,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;IACzB,MAAM,IAAI,GAAG,MAAM,OAAO,EAAE,CAAA;IAE5B,IAAI,IAAI,YAAY,qBAAqB,EAAE;QACzC,OAAO,UAAU,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,GAAG,CAAC,CAAA;KACvE;IAED,IAAI,IAAI,YAAY,YAAY,EAAE;QAChC,OAAO,UAAU,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;KAChE;IAED,IAAI,IAAI,YAAY,kBAAkB,EAAE;QACtC,OAAO,UAAU,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,GAAG,CAAC,CAAA;KAClD;IAED,IAAI,IAAI,YAAY,KAAK,EAAE;QACzB,OAAO,UAAU,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,GAAG,CAAC,CAAA;KAClD;IAED,OAAO,UAAU,CAAC,EAAE,OAAO,EAAE,8BAA8B,EAAE,EAAE,GAAG,CAAC,CAAA;AACrE,CAAC,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import type { User } from '@furystack/core';
2
- import type { RequestAction } from '../request-action-implementation';
2
+ import type { RequestAction } from '../request-action-implementation.js';
3
3
  /**
4
4
  * Action that returns the current authenticated user
5
5
  * @param injector The injector from the current stack
@@ -1 +1 @@
1
- {"version":3,"file":"get-current-user.d.ts","sourceRoot":"","sources":["../../src/actions/get-current-user.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAG3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAGrE;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,aAAa,CAAC;IACzC,MAAM,EAAE,IAAI,CAAA;CACb,CAGC,CAAA"}
1
+ {"version":3,"file":"get-current-user.d.ts","sourceRoot":"","sources":["../../src/actions/get-current-user.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAG3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAGxE;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,aAAa,CAAC;IACzC,MAAM,EAAE,IAAI,CAAA;CACb,CAGC,CAAA"}
@@ -0,0 +1,12 @@
1
+ import { getCurrentUser } from '@furystack/core';
2
+ import { Authenticate } from '../authenticate.js';
3
+ import { JsonResult } from '../request-action-implementation.js';
4
+ /**
5
+ * Action that returns the current authenticated user
6
+ * @param injector The injector from the current stack
7
+ */
8
+ export const GetCurrentUser = Authenticate()(async ({ injector }) => {
9
+ const user = await getCurrentUser(injector);
10
+ return JsonResult(user);
11
+ });
12
+ //# sourceMappingURL=get-current-user.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-current-user.js","sourceRoot":"","sources":["../../src/actions/get-current-user.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAA;AAEhE;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAEtB,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;IACzC,MAAM,IAAI,GAAG,MAAM,cAAc,CAAC,QAAQ,CAAC,CAAA;IAC3C,OAAO,UAAU,CAAC,IAAI,CAAC,CAAA;AACzB,CAAC,CAAC,CAAA"}
@@ -0,0 +1,7 @@
1
+ export * from './error-action.js';
2
+ export * from './get-current-user.js';
3
+ export * from './is-authenticated.js';
4
+ export * from './login.js';
5
+ export * from './logout.js';
6
+ export * from './not-found-action.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AACrC,cAAc,uBAAuB,CAAA;AACrC,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,uBAAuB,CAAA"}
@@ -0,0 +1,7 @@
1
+ export * from './error-action.js';
2
+ export * from './get-current-user.js';
3
+ export * from './is-authenticated.js';
4
+ export * from './login.js';
5
+ export * from './logout.js';
6
+ export * from './not-found-action.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AACrC,cAAc,uBAAuB,CAAA;AACrC,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,uBAAuB,CAAA"}
@@ -1,4 +1,4 @@
1
- import type { RequestAction } from '../request-action-implementation';
1
+ import type { RequestAction } from '../request-action-implementation.js';
2
2
  /**
3
3
  * Action that returns if the current user is authenticated
4
4
  * @param options The options for the Custom Action
@@ -1 +1 @@
1
- {"version":3,"file":"is-authenticated.d.ts","sourceRoot":"","sources":["../../src/actions/is-authenticated.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAGrE;;;;;GAKG;AACH,eAAO,MAAM,eAAe,EAAE,aAAa,CAAC;IAAE,MAAM,EAAE;QAAE,eAAe,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,CAGnF,CAAA"}
1
+ {"version":3,"file":"is-authenticated.d.ts","sourceRoot":"","sources":["../../src/actions/is-authenticated.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAGxE;;;;;GAKG;AACH,eAAO,MAAM,eAAe,EAAE,aAAa,CAAC;IAAE,MAAM,EAAE;QAAE,eAAe,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,CAGnF,CAAA"}
@@ -0,0 +1,13 @@
1
+ import { isAuthenticated } from '@furystack/core';
2
+ import { JsonResult } from '../request-action-implementation.js';
3
+ /**
4
+ * Action that returns if the current user is authenticated
5
+ * @param options The options for the Custom Action
6
+ * @param options.injector The Injector from the current context
7
+ * @returns A standard authentication result
8
+ */
9
+ export const IsAuthenticated = async ({ injector }) => {
10
+ const isAuthenticatedResult = await isAuthenticated(injector);
11
+ return JsonResult({ isAuthenticated: isAuthenticatedResult });
12
+ };
13
+ //# sourceMappingURL=is-authenticated.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-authenticated.js","sourceRoot":"","sources":["../../src/actions/is-authenticated.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAA;AAEhE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAA4D,KAAK,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC7G,MAAM,qBAAqB,GAAG,MAAM,eAAe,CAAC,QAAQ,CAAC,CAAA;IAC7D,OAAO,UAAU,CAAC,EAAE,eAAe,EAAE,qBAAqB,EAAE,CAAC,CAAA;AAC/D,CAAC,CAAA"}
@@ -1,6 +1,6 @@
1
- import '../helpers';
1
+ import '../helpers.js';
2
2
  import type { User } from '@furystack/core';
3
- import type { RequestAction } from '../request-action-implementation';
3
+ import type { RequestAction } from '../request-action-implementation.js';
4
4
  /**
5
5
  * Action that logs in the current user
6
6
  * Should be called with a JSON Post body with ``username`` and ``password`` fields.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/actions/login.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAGxE;;;;GAIG;AAEH,eAAO,MAAM,WAAW,EAAE,aAAa,CAAC;IACtC,MAAM,EAAE,IAAI,CAAA;IACZ,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAA;CAC7C,CAUA,CAAA"}
@@ -0,0 +1,22 @@
1
+ import { HttpUserContext } from '../http-user-context.js';
2
+ import '../helpers.js';
3
+ import { RequestError } from '@furystack/rest';
4
+ import { JsonResult } from '../request-action-implementation.js';
5
+ /**
6
+ * Action that logs in the current user
7
+ * Should be called with a JSON Post body with ``username`` and ``password`` fields.
8
+ * Returns the current user instance
9
+ */
10
+ export const LoginAction = async ({ injector, getBody, response }) => {
11
+ const userContext = injector.getInstance(HttpUserContext);
12
+ const body = await getBody();
13
+ try {
14
+ const user = await userContext.authenticateUser(body.username, body.password);
15
+ await userContext.cookieLogin(user, response);
16
+ return JsonResult(user, 200);
17
+ }
18
+ catch (error) {
19
+ throw new RequestError('Login Failed', 400);
20
+ }
21
+ };
22
+ //# sourceMappingURL=login.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/actions/login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,eAAe,CAAA;AAEtB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAA;AAEhE;;;;GAIG;AAEH,MAAM,CAAC,MAAM,WAAW,GAGnB,KAAK,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC7C,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC,eAAe,CAAC,CAAA;IACzD,MAAM,IAAI,GAAG,MAAM,OAAO,EAAE,CAAA;IAC5B,IAAI;QACF,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,gBAAgB,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC7E,MAAM,WAAW,CAAC,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;QAC7C,OAAO,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;KAC7B;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,YAAY,CAAC,cAAc,EAAE,GAAG,CAAC,CAAA;KAC5C;AACH,CAAC,CAAA"}
@@ -1,4 +1,4 @@
1
- import type { RequestAction } from '../request-action-implementation';
1
+ import type { RequestAction } from '../request-action-implementation.js';
2
2
  /**
3
3
  * Action that logs out the current user
4
4
  * @param root0 The Options object
@@ -1 +1 @@
1
- {"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../src/actions/logout.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAGrE;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,EAAE,aAAa,CAAC;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,CAG3D,CAAA"}
1
+ {"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../src/actions/logout.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAGxE;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,EAAE,aAAa,CAAC;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,CAG3D,CAAA"}
@@ -0,0 +1,15 @@
1
+ import { HttpUserContext } from '../http-user-context.js';
2
+ import { EmptyResult } from '../request-action-implementation.js';
3
+ /**
4
+ * Action that logs out the current user
5
+ * @param root0 The Options object
6
+ * @param root0.injector The injector from the context
7
+ * @param root0.request The current Request object
8
+ * @param root0.response The Response object
9
+ * @returns An empty result that indicates the success
10
+ */
11
+ export const LogoutAction = async ({ injector, request, response }) => {
12
+ await injector.getInstance(HttpUserContext).cookieLogout(request, response);
13
+ return EmptyResult();
14
+ };
15
+ //# sourceMappingURL=logout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logout.js","sourceRoot":"","sources":["../../src/actions/logout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAEzD,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAA;AAEjE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAuC,KAAK,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE;IACxG,MAAM,QAAQ,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;IAC3E,OAAO,WAAW,EAAE,CAAA;AACtB,CAAC,CAAA"}
@@ -1,4 +1,4 @@
1
- import type { RequestAction } from '../request-action-implementation';
1
+ import type { RequestAction } from '../request-action-implementation.js';
2
2
  /**
3
3
  * @returns The standard Not Found action result
4
4
  */
@@ -1 +1 @@
1
- {"version":3,"file":"not-found-action.d.ts","sourceRoot":"","sources":["../../src/actions/not-found-action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAGrE;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,aAAa,CAAC;IAAE,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAOvE,CAAA"}
1
+ {"version":3,"file":"not-found-action.d.ts","sourceRoot":"","sources":["../../src/actions/not-found-action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAGxE;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,aAAa,CAAC;IAAE,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAOvE,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { JsonResult } from '../request-action-implementation.js';
2
+ /**
3
+ * @returns The standard Not Found action result
4
+ */
5
+ export const NotFoundAction = async () => {
6
+ return JsonResult({
7
+ error: 'Content not found',
8
+ }, 404);
9
+ };
10
+ //# sourceMappingURL=not-found-action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"not-found-action.js","sourceRoot":"","sources":["../../src/actions/not-found-action.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAA;AAEhE;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAiD,KAAK,IAAI,EAAE;IACrF,OAAO,UAAU,CACf;QACE,KAAK,EAAE,mBAAmB;KAC3B,EACD,GAAG,CACJ,CAAA;AACH,CAAC,CAAA"}
@@ -1,11 +1,11 @@
1
1
  import type { Disposable } from '@furystack/utils';
2
2
  import type { Method, RestApi } from '@furystack/rest';
3
3
  import type { Injector } from '@furystack/inject';
4
- import type { OnRequest } from './server-manager';
5
4
  import type { MatchFunction } from 'path-to-regexp';
6
- import type { CorsOptions } from './models/cors-options';
7
- import './server-response-extensions';
8
- import type { RequestAction } from './request-action-implementation';
5
+ import type { OnRequest } from './server-manager.js';
6
+ import type { CorsOptions } from './models/cors-options.js';
7
+ import './server-response-extensions.js';
8
+ import type { RequestAction } from './request-action-implementation.js';
9
9
  export type RestApiImplementation<T extends RestApi> = {
10
10
  [TMethod in keyof T]: {
11
11
  [TUrl in keyof T[TMethod]]: T[TMethod][TUrl] extends {
@@ -1 +1 @@
1
- {"version":3,"file":"api-manager.d.ts","sourceRoot":"","sources":["../src/api-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAElD,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAEtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAEjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAGnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAGxD,OAAO,8BAA8B,CAAA;AAIrC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAA;AAEpE,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,OAAO,IAAI;KACpD,OAAO,IAAI,MAAM,CAAC,GAAG;SACnB,IAAI,IAAI,MAAM,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS;YAAE,MAAM,EAAE,OAAO,CAAA;SAAE,GAAG,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK;KACnH;CACF,CAAA;AAED,MAAM,WAAW,mBAAmB,CAAC,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,iBAAiB,CAAC,OAAO,EAAE;QAChC,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,GAAG,CAAC,EAAE,MAAM,CAAA;QACZ,WAAW,EAAE,MAAM,CAAA;QACnB,gBAAgB,EAAE,MAAM,EAAE,CAAA;KAC3B,GAAG,OAAO;IASX,OAAO,CAAC,qBAAqB;YAiBf,aAAa;YAmDb,SAAS;IA2BvB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;CAC/C"}
@@ -0,0 +1,153 @@
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 { PathHelper, usingAsync } from '@furystack/utils';
11
+ import { deserializeQueryString } from '@furystack/rest';
12
+ import { Injectable, Injected } from '@furystack/inject';
13
+ import { match } from 'path-to-regexp';
14
+ import { IdentityContext } from '@furystack/core';
15
+ import { ServerManager } from './server-manager.js';
16
+ import { NotFoundAction } from './actions/not-found-action.js';
17
+ import { Utils } from './utils.js';
18
+ import { ErrorAction } from './actions/error-action.js';
19
+ import './server-response-extensions.js';
20
+ import { HttpUserContext } from './http-user-context.js';
21
+ let ApiManager = class ApiManager {
22
+ constructor() {
23
+ this.apis = new Map();
24
+ }
25
+ dispose() {
26
+ this.apis.clear();
27
+ }
28
+ getSuportedMethods(api) {
29
+ return Object.keys(api);
30
+ }
31
+ compileApi(api, root) {
32
+ const supportedMethods = this.getSuportedMethods(api);
33
+ const compiledApi = {};
34
+ supportedMethods.forEach((method) => {
35
+ compiledApi[method] = [
36
+ ...Object.entries(api[method]).map(([path, action]) => {
37
+ const fullPath = `/${PathHelper.normalize(PathHelper.joinPaths(root, path))}`;
38
+ const matcher = match(fullPath, { decode: decodeURIComponent });
39
+ return { method, fullPath, matcher, action: action };
40
+ }),
41
+ ];
42
+ });
43
+ return compiledApi;
44
+ }
45
+ async addApi({ api, hostName, port, root, cors, injector, deserializeQueryParams, }) {
46
+ const supportedMethods = this.getSuportedMethods(api);
47
+ const rootApiPath = PathHelper.normalize(root);
48
+ const server = await this.serverManager.getOrCreate({ hostName, port });
49
+ const compiledApi = this.compileApi(api, root);
50
+ server.apis.push({
51
+ shouldExec: (msg) => this.shouldExecRequest({
52
+ ...msg,
53
+ method: msg.req.method?.toUpperCase(),
54
+ rootApiPath,
55
+ supportedMethods,
56
+ url: PathHelper.normalize(msg.req.url || ''),
57
+ }),
58
+ onRequest: (msg) => this.onMessage({
59
+ ...msg,
60
+ compiledApi,
61
+ rootApiPath,
62
+ port,
63
+ supportedMethods,
64
+ cors,
65
+ injector,
66
+ hostName,
67
+ deserializeQueryParams,
68
+ }),
69
+ });
70
+ }
71
+ shouldExecRequest(options) {
72
+ return options.method &&
73
+ options.url &&
74
+ (options.supportedMethods.includes(options.method) || options.method === 'OPTIONS') &&
75
+ PathHelper.normalize(options.url).startsWith(options.rootApiPath)
76
+ ? true
77
+ : false;
78
+ }
79
+ getActionFromEndpoint(compiledEndpoint, fullUrl, method) {
80
+ let resolvedParams;
81
+ const action = compiledEndpoint[method]?.find((route) => {
82
+ const result = route.matcher(fullUrl.pathname);
83
+ if (result) {
84
+ resolvedParams = result.params;
85
+ }
86
+ return result;
87
+ });
88
+ return (action && {
89
+ ...action,
90
+ params: resolvedParams,
91
+ });
92
+ }
93
+ async executeAction({ injector, req, res, fullUrl, action, deserializeQueryParams, params, }) {
94
+ await usingAsync(injector.createChild(), async (i) => {
95
+ const utils = i.getInstance(Utils);
96
+ const httpUserContext = i.getInstance(HttpUserContext);
97
+ i.setExplicitInstance({
98
+ getCurrentUser: () => httpUserContext.getCurrentUser(req),
99
+ isAuthorized: (...roles) => httpUserContext.isAuthorized(req, ...roles),
100
+ isAuthenticated: () => httpUserContext.isAuthenticated(req),
101
+ }, IdentityContext);
102
+ try {
103
+ const actionResult = await action({
104
+ request: req,
105
+ response: res,
106
+ injector: i,
107
+ getBody: () => utils.readPostBody(req),
108
+ headers: req.headers,
109
+ getQuery: () => deserializeQueryParams ? deserializeQueryParams(fullUrl.search) : deserializeQueryString(fullUrl.search),
110
+ getUrlParams: () => {
111
+ return params;
112
+ },
113
+ });
114
+ res.sendActionResult(actionResult);
115
+ }
116
+ catch (error) {
117
+ const errorActionResult = await ErrorAction({
118
+ request: req,
119
+ response: res,
120
+ injector: i,
121
+ getBody: async () => error,
122
+ });
123
+ res.sendActionResult(errorActionResult);
124
+ }
125
+ return;
126
+ });
127
+ }
128
+ async onMessage(options) {
129
+ const fullUrl = new URL(PathHelper.joinPaths('http://', `${options.hostName || ServerManager.DEFAULT_HOST}:${options.port}`, options.req.url));
130
+ options.cors && options.injector.getInstance(Utils).addCorsHeaders(options.cors, options.req, options.res);
131
+ if (options.req.method === 'OPTIONS') {
132
+ options.res.writeHead(200);
133
+ options.res.end();
134
+ return;
135
+ }
136
+ const action = this.getActionFromEndpoint(options.compiledApi, fullUrl, options.req.method?.toUpperCase());
137
+ if (action) {
138
+ await this.executeAction({ ...options, ...action, fullUrl });
139
+ }
140
+ else {
141
+ options.res.sendActionResult(await NotFoundAction({ injector: options.injector, request: options.req, response: options.res }));
142
+ }
143
+ }
144
+ };
145
+ __decorate([
146
+ Injected(ServerManager),
147
+ __metadata("design:type", ServerManager)
148
+ ], ApiManager.prototype, "serverManager", void 0);
149
+ ApiManager = __decorate([
150
+ Injectable({ lifetime: 'singleton' })
151
+ ], ApiManager);
152
+ export { ApiManager };
153
+ //# sourceMappingURL=api-manager.js.map
@@ -0,0 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H,CAAC;CAIF,CAAA;AADkB;IADhB,QAAQ,CAAC,aAAa,CAAC;8BACS,aAAa;iDAAA;AA7KnC,UAAU;IADtB,UAAU,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;GACzB,UAAU,CA8KtB;SA9KY,UAAU"}
@@ -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 Authenticate: () => <T extends {
3
3
  result: unknown;
4
4
  }>(action: RequestAction<T>) => RequestAction<T>;
@@ -1 +1 @@
1
- {"version":3,"file":"authenticate.d.ts","sourceRoot":"","sources":["../src/authenticate.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAgB,aAAa,EAAwB,MAAM,iCAAiC,CAAA;AAGxG,eAAO,MAAM,YAAY;YAEF,OAAO;gDAc3B,CAAA"}
1
+ {"version":3,"file":"authenticate.d.ts","sourceRoot":"","sources":["../src/authenticate.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAgB,aAAa,EAAwB,MAAM,oCAAoC,CAAA;AAG3G,eAAO,MAAM,YAAY;YAEF,OAAO;gDAc3B,CAAA"}
@@ -0,0 +1,16 @@
1
+ import { isAuthenticated } from '@furystack/core';
2
+ import { sleepAsync } from '@furystack/utils';
3
+ import { HttpUserContext } from './http-user-context.js';
4
+ import { JsonResult } from './request-action-implementation.js';
5
+ export const Authenticate = () => (action) => {
6
+ return async (args) => {
7
+ const { injector } = args;
8
+ const authenticated = await isAuthenticated(injector);
9
+ if (!authenticated) {
10
+ await sleepAsync(Math.random() * 1000);
11
+ return JsonResult({ error: 'unauthorized' }, 401, injector.getInstance(HttpUserContext).authentication.enableBasicAuth ? { 'WWW-Authenticate': 'Basic' } : {});
12
+ }
13
+ return (await action(args));
14
+ };
15
+ };
16
+ //# sourceMappingURL=authenticate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authenticate.js","sourceRoot":"","sources":["../src/authenticate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAExD,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAA;AAE/D,MAAM,CAAC,MAAM,YAAY,GACvB,GAAG,EAAE,CACL,CAAgC,MAAwB,EAAoB,EAAE;IAC5E,OAAO,KAAK,EAAE,IAA6B,EAA4B,EAAE;QACvE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAA;QACzB,MAAM,aAAa,GAAG,MAAM,eAAe,CAAC,QAAQ,CAAC,CAAA;QACrD,IAAI,CAAC,aAAa,EAAE;YAClB,MAAM,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAA;YACtC,OAAO,UAAU,CACf,EAAE,KAAK,EAAE,cAAc,EAAE,EACzB,GAAG,EACH,QAAQ,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAC9E,CAAA;SAChC;QACD,OAAO,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,CAAQ,CAAA;IACpC,CAAC,CAAA;AACH,CAAC,CAAA"}
@@ -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 Authorize: (...roles: string[]) => <T extends {
3
3
  result: unknown;
4
4
  }>(action: RequestAction<T>) => RequestAction<T>;
@@ -1 +1 @@
1
- {"version":3,"file":"authorize.d.ts","sourceRoot":"","sources":["../src/authorize.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAgB,aAAa,EAAwB,MAAM,iCAAiC,CAAA;AAGxG,eAAO,MAAM,SAAS,aACT,MAAM,EAAE;YACE,OAAO;gDAa3B,CAAA"}
1
+ {"version":3,"file":"authorize.d.ts","sourceRoot":"","sources":["../src/authorize.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAgB,aAAa,EAAwB,MAAM,oCAAoC,CAAA;AAG3G,eAAO,MAAM,SAAS,aACT,MAAM,EAAE;YACE,OAAO;gDAa3B,CAAA"}
@@ -0,0 +1,19 @@
1
+ import { isAuthorized } from '@furystack/core';
2
+ import { sleepAsync } from '@furystack/utils';
3
+ import { JsonResult } from './request-action-implementation.js';
4
+ export const Authorize = (...roles) => (action) => {
5
+ return async (options) => {
6
+ try {
7
+ const authorized = await isAuthorized(options.injector, ...roles);
8
+ if (!authorized) {
9
+ await sleepAsync(Math.random() * 1000);
10
+ return JsonResult({ error: 'forbidden' }, 403);
11
+ }
12
+ }
13
+ catch (error) {
14
+ return JsonResult({ error: 'forbidden' }, 403);
15
+ }
16
+ return (await action(options));
17
+ };
18
+ };
19
+ //# sourceMappingURL=authorize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorize.js","sourceRoot":"","sources":["../src/authorize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAA;AAE/D,MAAM,CAAC,MAAM,SAAS,GACpB,CAAC,GAAG,KAAe,EAAE,EAAE,CACvB,CAAgC,MAAwB,EAAoB,EAAE;IAC5E,OAAO,KAAK,EAAE,OAAgC,EAA4B,EAAE;QAC1E,IAAI;YACF,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,KAAK,CAAC,CAAA;YACjE,IAAI,CAAC,UAAU,EAAE;gBACf,MAAM,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAA;gBACtC,OAAO,UAAU,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,GAAG,CAAQ,CAAA;aACtD;SACF;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,UAAU,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,GAAG,CAAQ,CAAA;SACtD;QACD,OAAO,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,CAAQ,CAAA;IACvC,CAAC,CAAA;AACH,CAAC,CAAA"}
@@ -1,7 +1,7 @@
1
1
  import type { Constructable } from '@furystack/inject';
2
2
  import type { DeleteEndpoint } from '@furystack/rest';
3
3
  import '@furystack/repository';
4
- import type { RequestAction } from '../request-action-implementation';
4
+ import type { RequestAction } from '../request-action-implementation.js';
5
5
  /**
6
6
  * Creates a DELETE endpoint for removing entities
7
7
  * @param options The options for endpoint creation
@@ -1 +1 @@
1
- {"version":3,"file":"create-delete-endpoint.d.ts","sourceRoot":"","sources":["../../src/endpoint-generators/create-delete-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAIrE;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB;;;mDAWhC,CAAA"}
1
+ {"version":3,"file":"create-delete-endpoint.d.ts","sourceRoot":"","sources":["../../src/endpoint-generators/create-delete-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAIxE;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB;;;mDAWhC,CAAA"}
@@ -0,0 +1,20 @@
1
+ import '@furystack/repository';
2
+ import { JsonResult } from '../request-action-implementation.js';
3
+ import { getRepository } from '@furystack/repository';
4
+ /**
5
+ * Creates a DELETE endpoint for removing entities
6
+ * @param options The options for endpoint creation
7
+ * @param options.model The Model class
8
+ * @param options.primaryKey The field used as primary key on the model
9
+ * @returns a boolean that indicates the success
10
+ */
11
+ export const createDeleteEndpoint = (options) => {
12
+ const endpoint = async ({ injector, getUrlParams }) => {
13
+ const { id } = getUrlParams();
14
+ const dataSet = getRepository(injector).getDataSetFor(options.model, options.primaryKey);
15
+ await dataSet.remove(injector, id);
16
+ return JsonResult({}, 204);
17
+ };
18
+ return endpoint;
19
+ };
20
+ //# sourceMappingURL=create-delete-endpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-delete-endpoint.js","sourceRoot":"","sources":["../../src/endpoint-generators/create-delete-endpoint.ts"],"names":[],"mappings":"AAEA,OAAO,uBAAuB,CAAA;AAE9B,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAErD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAgD,OAGnF,EAAE,EAAE;IACH,MAAM,QAAQ,GAAkD,KAAK,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,EAAE;QACnG,MAAM,EAAE,EAAE,EAAE,GAAG,YAAY,EAAE,CAAA;QAC7B,MAAM,OAAO,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,CAAA;QACxF,MAAM,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;QAClC,OAAO,UAAU,CAAC,EAAE,EAAE,GAAG,CAAC,CAAA;IAC5B,CAAC,CAAA;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA"}
@@ -1,7 +1,7 @@
1
1
  import type { Constructable } from '@furystack/inject';
2
2
  import type { GetCollectionEndpoint } from '@furystack/rest';
3
3
  import '@furystack/repository';
4
- import type { RequestAction } from '../request-action-implementation';
4
+ import type { RequestAction } from '../request-action-implementation.js';
5
5
  /**
6
6
  * Creates a GetCollection endpoint for the given model. The model should have a Repository DataSet
7
7
  * @param options The options for endpoint creation
@@ -1 +1 @@
1
- {"version":3,"file":"create-get-collection-endpoint.d.ts","sourceRoot":"","sources":["../../src/endpoint-generators/create-get-collection-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAC5D,OAAO,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAIrE;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B;;;6CAcvC,CAAA"}
1
+ {"version":3,"file":"create-get-collection-endpoint.d.ts","sourceRoot":"","sources":["../../src/endpoint-generators/create-get-collection-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAC5D,OAAO,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAIxE;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B;;;6CAcvC,CAAA"}
@@ -0,0 +1,22 @@
1
+ import '@furystack/repository';
2
+ import { JsonResult } from '../request-action-implementation.js';
3
+ import { getRepository } from '@furystack/repository';
4
+ /**
5
+ * Creates a GetCollection endpoint for the given model. The model should have a Repository DataSet
6
+ * @param options The options for endpoint creation
7
+ * @param options.model The Model class
8
+ * @param options.primaryKey The field used as primary key on the model
9
+ * @returns The created endpoint
10
+ */
11
+ export const createGetCollectionEndpoint = (options) => {
12
+ const endpoint = async ({ injector, getQuery }) => {
13
+ const { findOptions } = getQuery();
14
+ const dataSet = getRepository(injector).getDataSetFor(options.model, options.primaryKey);
15
+ const entriesPromise = dataSet.find(injector, findOptions || {});
16
+ const countPromise = dataSet.count(injector, findOptions?.filter);
17
+ const [entries, count] = await Promise.all([entriesPromise, countPromise]);
18
+ return JsonResult({ entries, count });
19
+ };
20
+ return endpoint;
21
+ };
22
+ //# sourceMappingURL=create-get-collection-endpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-get-collection-endpoint.js","sourceRoot":"","sources":["../../src/endpoint-generators/create-get-collection-endpoint.ts"],"names":[],"mappings":"AAEA,OAAO,uBAAuB,CAAA;AAE9B,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAErD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAiC,OAG3E,EAAE,EAAE;IACH,MAAM,QAAQ,GAA4C,KAAK,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,EAAE;QACzF,MAAM,EAAE,WAAW,EAAE,GAAG,QAAQ,EAAE,CAAA;QAClC,MAAM,OAAO,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,CAAA;QACxF,MAAM,cAAc,GAAG,OAAO,CAAC,IAAI,CAAM,QAAQ,EAAE,WAAW,IAAI,EAAE,CAAC,CAAA;QACrE,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,CAAC,CAAA;QACjE,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC,CAAA;QAE1E,OAAO,UAAU,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAA;IACvC,CAAC,CAAA;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA"}
@@ -1,7 +1,7 @@
1
1
  import type { Constructable } from '@furystack/inject';
2
2
  import type { GetEntityEndpoint } from '@furystack/rest';
3
3
  import '@furystack/repository';
4
- import type { RequestAction } from '../request-action-implementation';
4
+ import type { RequestAction } from '../request-action-implementation.js';
5
5
  /**
6
6
  * Creates a simple Get Entity endpoint for a specified model.
7
7
  * @param options The options for endpoint creation
@@ -1 +1 @@
1
- {"version":3,"file":"create-get-entity-endpoint.d.ts","sourceRoot":"","sources":["../../src/endpoint-generators/create-get-entity-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAExD,OAAO,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAIrE;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB;;;sDAenC,CAAA"}
1
+ {"version":3,"file":"create-get-entity-endpoint.d.ts","sourceRoot":"","sources":["../../src/endpoint-generators/create-get-entity-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAExD,OAAO,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAIxE;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB;;;sDAenC,CAAA"}