@furystack/rest-service 6.2.23 → 7.0.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 (231) hide show
  1. package/package.json +29 -12
  2. package/src/actions/error-action.spec.ts +1 -0
  3. package/src/actions/get-current-user.spec.ts +1 -0
  4. package/src/actions/get-current-user.ts +0 -1
  5. package/src/actions/is-authenticated.spec.ts +1 -0
  6. package/src/actions/is-authenticated.ts +0 -1
  7. package/src/actions/login-action.spec.ts +3 -2
  8. package/src/actions/logout-action.spec.ts +2 -1
  9. package/src/actions/logout.ts +0 -1
  10. package/src/actions/not-found-action.spec.ts +1 -0
  11. package/src/add-cors-header.spec.ts +7 -6
  12. package/src/authenticate.spec.ts +7 -6
  13. package/src/authorize.spec.ts +7 -6
  14. package/src/endpoint-generators/create-delete-endpoint.spec.ts +1 -0
  15. package/src/endpoint-generators/create-delete-endpoint.ts +0 -1
  16. package/src/endpoint-generators/create-get-collection-endpoint.spec.ts +1 -0
  17. package/src/endpoint-generators/create-get-collection-endpoint.ts +0 -1
  18. package/src/endpoint-generators/create-get-entity-endpoint.spec.ts +1 -0
  19. package/src/endpoint-generators/create-get-entity-endpoint.ts +0 -1
  20. package/src/endpoint-generators/create-patch-endpoint.spec.ts +1 -0
  21. package/src/endpoint-generators/create-patch-endpoint.ts +0 -1
  22. package/src/endpoint-generators/create-post-endpoint.spec.ts +1 -0
  23. package/src/endpoint-generators/create-post-endpoint.ts +0 -1
  24. package/src/helpers.spec.ts +1 -0
  25. package/src/helpers.ts +2 -6
  26. package/src/http-user-context.spec.ts +15 -14
  27. package/src/http-user-context.ts +0 -3
  28. package/src/incoming-message-extensions.spec.ts +1 -0
  29. package/src/mime-types.spec.ts +1 -0
  30. package/src/rest-service.integration.spec.ts +1 -0
  31. package/src/rest.integration.test.ts +1 -0
  32. package/src/schema-validator/schema-validator.test.ts +1 -0
  33. package/src/server-manager.ts +2 -2
  34. package/src/server-response-extensions.spec.ts +23 -18
  35. package/src/static-server-manager.spec.ts +2 -2
  36. package/src/utils.ts +0 -2
  37. package/src/validate.integration.spec.ts +1 -0
  38. package/types/actions/get-current-user.d.ts +0 -1
  39. package/types/actions/get-current-user.d.ts.map +1 -1
  40. package/types/actions/is-authenticated.d.ts +0 -1
  41. package/types/actions/is-authenticated.d.ts.map +1 -1
  42. package/types/actions/logout.d.ts +0 -1
  43. package/types/actions/logout.d.ts.map +1 -1
  44. package/types/endpoint-generators/create-delete-endpoint.d.ts +0 -1
  45. package/types/endpoint-generators/create-delete-endpoint.d.ts.map +1 -1
  46. package/types/endpoint-generators/create-get-collection-endpoint.d.ts +0 -1
  47. package/types/endpoint-generators/create-get-collection-endpoint.d.ts.map +1 -1
  48. package/types/endpoint-generators/create-get-entity-endpoint.d.ts +0 -1
  49. package/types/endpoint-generators/create-get-entity-endpoint.d.ts.map +1 -1
  50. package/types/endpoint-generators/create-patch-endpoint.d.ts +0 -1
  51. package/types/endpoint-generators/create-patch-endpoint.d.ts.map +1 -1
  52. package/types/endpoint-generators/create-post-endpoint.d.ts +0 -1
  53. package/types/endpoint-generators/create-post-endpoint.d.ts.map +1 -1
  54. package/types/helpers.d.ts +2 -4
  55. package/types/helpers.d.ts.map +1 -1
  56. package/types/http-user-context.d.ts +0 -3
  57. package/types/http-user-context.d.ts.map +1 -1
  58. package/types/server-manager.d.ts.map +1 -1
  59. package/types/utils.d.ts +0 -2
  60. package/types/utils.d.ts.map +1 -1
  61. package/dist/actions/error-action.js +0 -29
  62. package/dist/actions/error-action.js.map +0 -1
  63. package/dist/actions/error-action.spec.js +0 -48
  64. package/dist/actions/error-action.spec.js.map +0 -1
  65. package/dist/actions/get-current-user.js +0 -16
  66. package/dist/actions/get-current-user.js.map +0 -1
  67. package/dist/actions/get-current-user.spec.js +0 -20
  68. package/dist/actions/get-current-user.spec.js.map +0 -1
  69. package/dist/actions/index.js +0 -23
  70. package/dist/actions/index.js.map +0 -1
  71. package/dist/actions/is-authenticated.js +0 -18
  72. package/dist/actions/is-authenticated.js.map +0 -1
  73. package/dist/actions/is-authenticated.spec.js +0 -19
  74. package/dist/actions/is-authenticated.spec.js.map +0 -1
  75. package/dist/actions/login-action.spec.js +0 -35
  76. package/dist/actions/login-action.spec.js.map +0 -1
  77. package/dist/actions/login.js +0 -26
  78. package/dist/actions/login.js.map +0 -1
  79. package/dist/actions/logout-action.spec.js +0 -23
  80. package/dist/actions/logout-action.spec.js.map +0 -1
  81. package/dist/actions/logout.js +0 -20
  82. package/dist/actions/logout.js.map +0 -1
  83. package/dist/actions/not-found-action.js +0 -14
  84. package/dist/actions/not-found-action.js.map +0 -1
  85. package/dist/actions/not-found-action.spec.js +0 -17
  86. package/dist/actions/not-found-action.spec.js.map +0 -1
  87. package/dist/add-cors-header.spec.js +0 -99
  88. package/dist/add-cors-header.spec.js.map +0 -1
  89. package/dist/api-manager.js +0 -156
  90. package/dist/api-manager.js.map +0 -1
  91. package/dist/authenticate.js +0 -20
  92. package/dist/authenticate.js.map +0 -1
  93. package/dist/authenticate.spec.js +0 -59
  94. package/dist/authenticate.spec.js.map +0 -1
  95. package/dist/authorize.js +0 -23
  96. package/dist/authorize.js.map +0 -1
  97. package/dist/authorize.spec.js +0 -55
  98. package/dist/authorize.spec.js.map +0 -1
  99. package/dist/endpoint-generators/create-delete-endpoint.js +0 -25
  100. package/dist/endpoint-generators/create-delete-endpoint.js.map +0 -1
  101. package/dist/endpoint-generators/create-delete-endpoint.spec.js +0 -35
  102. package/dist/endpoint-generators/create-delete-endpoint.spec.js.map +0 -1
  103. package/dist/endpoint-generators/create-get-collection-endpoint.js +0 -27
  104. package/dist/endpoint-generators/create-get-collection-endpoint.js.map +0 -1
  105. package/dist/endpoint-generators/create-get-collection-endpoint.spec.js +0 -157
  106. package/dist/endpoint-generators/create-get-collection-endpoint.spec.js.map +0 -1
  107. package/dist/endpoint-generators/create-get-entity-endpoint.js +0 -30
  108. package/dist/endpoint-generators/create-get-entity-endpoint.js.map +0 -1
  109. package/dist/endpoint-generators/create-get-entity-endpoint.spec.js +0 -75
  110. package/dist/endpoint-generators/create-get-entity-endpoint.spec.js.map +0 -1
  111. package/dist/endpoint-generators/create-patch-endpoint.js +0 -27
  112. package/dist/endpoint-generators/create-patch-endpoint.js.map +0 -1
  113. package/dist/endpoint-generators/create-patch-endpoint.spec.js +0 -38
  114. package/dist/endpoint-generators/create-patch-endpoint.spec.js.map +0 -1
  115. package/dist/endpoint-generators/create-post-endpoint.js +0 -30
  116. package/dist/endpoint-generators/create-post-endpoint.js.map +0 -1
  117. package/dist/endpoint-generators/create-post-endpoint.spec.js +0 -36
  118. package/dist/endpoint-generators/create-post-endpoint.spec.js.map +0 -1
  119. package/dist/endpoint-generators/index.js +0 -22
  120. package/dist/endpoint-generators/index.js.map +0 -1
  121. package/dist/endpoint-generators/utils.js +0 -28
  122. package/dist/endpoint-generators/utils.js.map +0 -1
  123. package/dist/helpers.js +0 -39
  124. package/dist/helpers.js.map +0 -1
  125. package/dist/helpers.spec.js +0 -35
  126. package/dist/helpers.spec.js.map +0 -1
  127. package/dist/http-authentication-settings.js +0 -29
  128. package/dist/http-authentication-settings.js.map +0 -1
  129. package/dist/http-user-context.js +0 -174
  130. package/dist/http-user-context.js.map +0 -1
  131. package/dist/http-user-context.spec.js +0 -272
  132. package/dist/http-user-context.spec.js.map +0 -1
  133. package/dist/incoming-message-extensions.js +0 -16
  134. package/dist/incoming-message-extensions.js.map +0 -1
  135. package/dist/incoming-message-extensions.spec.js +0 -39
  136. package/dist/incoming-message-extensions.spec.js.map +0 -1
  137. package/dist/index.js +0 -35
  138. package/dist/index.js.map +0 -1
  139. package/dist/mime-types.js +0 -340
  140. package/dist/mime-types.js.map +0 -1
  141. package/dist/mime-types.spec.js +0 -15
  142. package/dist/mime-types.spec.js.map +0 -1
  143. package/dist/models/cors-options.js +0 -3
  144. package/dist/models/cors-options.js.map +0 -1
  145. package/dist/models/default-session.js +0 -10
  146. package/dist/models/default-session.js.map +0 -1
  147. package/dist/models/index.js +0 -19
  148. package/dist/models/index.js.map +0 -1
  149. package/dist/request-action-implementation.js +0 -42
  150. package/dist/request-action-implementation.js.map +0 -1
  151. package/dist/rest-service.integration.spec.js +0 -143
  152. package/dist/rest-service.integration.spec.js.map +0 -1
  153. package/dist/rest.integration.test.js +0 -156
  154. package/dist/rest.integration.test.js.map +0 -1
  155. package/dist/schema-validator/index.js +0 -19
  156. package/dist/schema-validator/index.js.map +0 -1
  157. package/dist/schema-validator/schema-validation-error.js +0 -15
  158. package/dist/schema-validator/schema-validation-error.js.map +0 -1
  159. package/dist/schema-validator/schema-validator.js +0 -38
  160. package/dist/schema-validator/schema-validator.js.map +0 -1
  161. package/dist/schema-validator/schema-validator.test.js +0 -62
  162. package/dist/schema-validator/schema-validator.test.js.map +0 -1
  163. package/dist/schema-validator/validate-examples.js +0 -29
  164. package/dist/schema-validator/validate-examples.js.map +0 -1
  165. package/dist/server-manager.js +0 -79
  166. package/dist/server-manager.js.map +0 -1
  167. package/dist/server-response-extensions.js +0 -17
  168. package/dist/server-response-extensions.js.map +0 -1
  169. package/dist/server-response-extensions.spec.js +0 -49
  170. package/dist/server-response-extensions.spec.js.map +0 -1
  171. package/dist/static-server-manager.js +0 -71
  172. package/dist/static-server-manager.js.map +0 -1
  173. package/dist/static-server-manager.spec.js +0 -218
  174. package/dist/static-server-manager.spec.js.map +0 -1
  175. package/dist/utils.js +0 -75
  176. package/dist/utils.js.map +0 -1
  177. package/dist/validate.integration.schema.js +0 -3
  178. package/dist/validate.integration.schema.js.map +0 -1
  179. package/dist/validate.integration.spec.js +0 -216
  180. package/dist/validate.integration.spec.js.map +0 -1
  181. package/dist/validate.integration.spec.schema.json +0 -903
  182. package/dist/validate.js +0 -47
  183. package/dist/validate.js.map +0 -1
  184. package/types/actions/error-action.spec.d.ts +0 -2
  185. package/types/actions/error-action.spec.d.ts.map +0 -1
  186. package/types/actions/get-current-user.spec.d.ts +0 -2
  187. package/types/actions/get-current-user.spec.d.ts.map +0 -1
  188. package/types/actions/is-authenticated.spec.d.ts +0 -2
  189. package/types/actions/is-authenticated.spec.d.ts.map +0 -1
  190. package/types/actions/login-action.spec.d.ts +0 -2
  191. package/types/actions/login-action.spec.d.ts.map +0 -1
  192. package/types/actions/logout-action.spec.d.ts +0 -2
  193. package/types/actions/logout-action.spec.d.ts.map +0 -1
  194. package/types/actions/not-found-action.spec.d.ts +0 -2
  195. package/types/actions/not-found-action.spec.d.ts.map +0 -1
  196. package/types/add-cors-header.spec.d.ts +0 -2
  197. package/types/add-cors-header.spec.d.ts.map +0 -1
  198. package/types/authenticate.spec.d.ts +0 -2
  199. package/types/authenticate.spec.d.ts.map +0 -1
  200. package/types/authorize.spec.d.ts +0 -2
  201. package/types/authorize.spec.d.ts.map +0 -1
  202. package/types/endpoint-generators/create-delete-endpoint.spec.d.ts +0 -2
  203. package/types/endpoint-generators/create-delete-endpoint.spec.d.ts.map +0 -1
  204. package/types/endpoint-generators/create-get-collection-endpoint.spec.d.ts +0 -2
  205. package/types/endpoint-generators/create-get-collection-endpoint.spec.d.ts.map +0 -1
  206. package/types/endpoint-generators/create-get-entity-endpoint.spec.d.ts +0 -2
  207. package/types/endpoint-generators/create-get-entity-endpoint.spec.d.ts.map +0 -1
  208. package/types/endpoint-generators/create-patch-endpoint.spec.d.ts +0 -2
  209. package/types/endpoint-generators/create-patch-endpoint.spec.d.ts.map +0 -1
  210. package/types/endpoint-generators/create-post-endpoint.spec.d.ts +0 -2
  211. package/types/endpoint-generators/create-post-endpoint.spec.d.ts.map +0 -1
  212. package/types/helpers.spec.d.ts +0 -2
  213. package/types/helpers.spec.d.ts.map +0 -1
  214. package/types/http-user-context.spec.d.ts +0 -3
  215. package/types/http-user-context.spec.d.ts.map +0 -1
  216. package/types/incoming-message-extensions.spec.d.ts +0 -2
  217. package/types/incoming-message-extensions.spec.d.ts.map +0 -1
  218. package/types/mime-types.spec.d.ts +0 -2
  219. package/types/mime-types.spec.d.ts.map +0 -1
  220. package/types/rest-service.integration.spec.d.ts +0 -2
  221. package/types/rest-service.integration.spec.d.ts.map +0 -1
  222. package/types/rest.integration.test.d.ts +0 -90
  223. package/types/rest.integration.test.d.ts.map +0 -1
  224. package/types/schema-validator/schema-validator.test.d.ts +0 -2
  225. package/types/schema-validator/schema-validator.test.d.ts.map +0 -1
  226. package/types/server-response-extensions.spec.d.ts +0 -2
  227. package/types/server-response-extensions.spec.d.ts.map +0 -1
  228. package/types/static-server-manager.spec.d.ts +0 -2
  229. package/types/static-server-manager.spec.d.ts.map +0 -1
  230. package/types/validate.integration.spec.d.ts +0 -2
  231. package/types/validate.integration.spec.d.ts.map +0 -1
package/package.json CHANGED
@@ -1,8 +1,25 @@
1
1
  {
2
2
  "name": "@furystack/rest-service",
3
- "version": "6.2.23",
3
+ "version": "7.0.0",
4
4
  "description": "Repository implementation for FuryStack",
5
- "main": "dist/index.js",
5
+ "type": "module",
6
+ "scripts": {
7
+ "build:es6": "tsc --outDir ./esm"
8
+ },
9
+ "exports": {
10
+ ".": {
11
+ "import": "./esm/index.js",
12
+ "types": "./types/index.d.ts"
13
+ },
14
+ "./package.json": "./package.json"
15
+ },
16
+ "typesVersions": {
17
+ "*": {
18
+ "*": [
19
+ "types/*"
20
+ ]
21
+ }
22
+ },
6
23
  "files": [
7
24
  "dist",
8
25
  "types",
@@ -29,22 +46,22 @@
29
46
  },
30
47
  "homepage": "https://github.com/furystack/furystack",
31
48
  "dependencies": {
32
- "@furystack/core": "^11.3.1",
33
- "@furystack/inject": "^7.1.9",
34
- "@furystack/repository": "^6.1.17",
35
- "@furystack/rest": "^4.2.1",
36
- "@furystack/security": "^2.1.16",
37
- "@furystack/utils": "^3.1.8",
49
+ "@furystack/core": "^12.0.0",
50
+ "@furystack/inject": "^8.0.0",
51
+ "@furystack/repository": "^7.0.0",
52
+ "@furystack/rest": "^5.0.0",
53
+ "@furystack/security": "^3.0.0",
54
+ "@furystack/utils": "^4.0.0",
38
55
  "ajv": "^8.12.0",
39
56
  "ajv-formats": "^2.1.1",
40
57
  "path-to-regexp": "^6.2.1",
41
58
  "semaphore-async-await": "^1.5.1"
42
59
  },
43
60
  "devDependencies": {
44
- "@furystack/rest-client-fetch": "^4.1.19",
45
- "@types/jest": "^29.5.0",
46
- "@types/node": "^18.15.11"
61
+ "@furystack/rest-client-fetch": "^5.0.0",
62
+ "@types/node": "^18.15.11",
63
+ "typescript": "^5.0.4",
64
+ "vitest": "^0.30.1"
47
65
  },
48
- "typings": "./types/index.d.ts",
49
66
  "gitHead": "1045d854bfd8c475b7035471d130d401417a2321"
50
67
  }
@@ -5,6 +5,7 @@ import type { IncomingMessage } from 'http'
5
5
  import { RequestError } from '@furystack/rest'
6
6
  import { AuthorizationError } from '@furystack/core'
7
7
  import type { ServerResponse } from 'http'
8
+ import { describe, it, expect } from 'vitest'
8
9
 
9
10
  describe('ErrorAction tests', () => {
10
11
  const request = { url: 'https://google.com' } as IncomingMessage
@@ -3,6 +3,7 @@ import { usingAsync } from '@furystack/utils'
3
3
  import { GetCurrentUser } from './get-current-user'
4
4
  import type { IncomingMessage, ServerResponse } from 'http'
5
5
  import { IdentityContext } from '@furystack/core'
6
+ import { describe, it, expect } from 'vitest'
6
7
 
7
8
  describe('getCurrentUser', () => {
8
9
  const request = { url: 'https://google.com' } as IncomingMessage
@@ -6,7 +6,6 @@ import { JsonResult } from '../request-action-implementation'
6
6
 
7
7
  /**
8
8
  * Action that returns the current authenticated user
9
- *
10
9
  * @param injector The injector from the current stack
11
10
  */
12
11
  export const GetCurrentUser: RequestAction<{
@@ -3,6 +3,7 @@ import { usingAsync } from '@furystack/utils'
3
3
  import { IsAuthenticated } from './is-authenticated'
4
4
  import type { IncomingMessage, ServerResponse } from 'http'
5
5
  import { IdentityContext } from '@furystack/core'
6
+ import { describe, it, expect } from 'vitest'
6
7
 
7
8
  describe('isAuthenticated', () => {
8
9
  const request = { url: 'https://google.com' } as IncomingMessage
@@ -4,7 +4,6 @@ import { JsonResult } from '../request-action-implementation'
4
4
 
5
5
  /**
6
6
  * Action that returns if the current user is authenticated
7
- *
8
7
  * @param options The options for the Custom Action
9
8
  * @param options.injector The Injector from the current context
10
9
  * @returns A standard authentication result
@@ -3,6 +3,7 @@ import { Injector } from '@furystack/inject'
3
3
  import { usingAsync } from '@furystack/utils'
4
4
  import { LoginAction } from './login'
5
5
  import { HttpUserContext } from '../http-user-context'
6
+ import { describe, it, expect, vi } from 'vitest'
6
7
 
7
8
  describe('LoginAction', () => {
8
9
  const request = { url: 'https://google.com' } as IncomingMessage
@@ -13,8 +14,8 @@ describe('LoginAction', () => {
13
14
  await usingAsync(new Injector(), async (i) => {
14
15
  i.setExplicitInstance(
15
16
  {
16
- authenticateUser: jest.fn(async () => testUser),
17
- cookieLogin: jest.fn(async () => testUser),
17
+ authenticateUser: vi.fn(async () => testUser),
18
+ cookieLogin: vi.fn(async () => testUser),
18
19
  authentication: {},
19
20
  },
20
21
  HttpUserContext,
@@ -3,6 +3,7 @@ import { usingAsync } from '@furystack/utils'
3
3
  import { HttpUserContext } from '../http-user-context'
4
4
  import { LogoutAction } from './logout'
5
5
  import type { IncomingMessage, ServerResponse } from 'http'
6
+ import { describe, it, expect, vi } from 'vitest'
6
7
 
7
8
  describe('LogoutAction', () => {
8
9
  const request = { url: 'https://google.com' } as IncomingMessage
@@ -10,7 +11,7 @@ describe('LogoutAction', () => {
10
11
 
11
12
  it('exec', async () => {
12
13
  await usingAsync(new Injector(), async (i) => {
13
- const cookieLogout = jest.fn(async () => true)
14
+ const cookieLogout = vi.fn(async () => true)
14
15
  i.setExplicitInstance(
15
16
  {
16
17
  cookieLogout,
@@ -4,7 +4,6 @@ import { EmptyResult } from '../request-action-implementation'
4
4
 
5
5
  /**
6
6
  * Action that logs out the current user
7
- *
8
7
  * @param root0 The Options object
9
8
  * @param root0.injector The injector from the context
10
9
  * @param root0.request The current Request object
@@ -2,6 +2,7 @@ import { Injector } from '@furystack/inject'
2
2
  import { usingAsync } from '@furystack/utils'
3
3
  import { NotFoundAction } from './not-found-action'
4
4
  import type { IncomingMessage, ServerResponse } from 'http'
5
+ import { describe, it, expect } from 'vitest'
5
6
 
6
7
  describe('NotFoundAction tests', () => {
7
8
  const request = { url: 'https://google.com' } as IncomingMessage
@@ -1,5 +1,6 @@
1
1
  import type { IncomingMessage, ServerResponse } from 'http'
2
2
  import { Utils } from './utils'
3
+ import { describe, it, expect, vi } from 'vitest'
3
4
 
4
5
  describe('AddCorsHeaders', () => {
5
6
  const utils = new Utils()
@@ -8,7 +9,7 @@ describe('AddCorsHeaders', () => {
8
9
  headers: { origin: 'http://localhost/', host: 'http://localhost' },
9
10
  } as any as IncomingMessage
10
11
  const resp: ServerResponse = {
11
- setHeader: jest.fn(),
12
+ setHeader: vi.fn(),
12
13
  } as unknown as ServerResponse
13
14
 
14
15
  utils.addCorsHeaders(
@@ -28,7 +29,7 @@ describe('AddCorsHeaders', () => {
28
29
  headers: { origin: 'http://localhost/', host: 'http://google.com' },
29
30
  } as any as IncomingMessage
30
31
  const resp: ServerResponse = {
31
- setHeader: jest.fn(),
32
+ setHeader: vi.fn(),
32
33
  } as unknown as ServerResponse
33
34
 
34
35
  utils.addCorsHeaders(
@@ -48,7 +49,7 @@ describe('AddCorsHeaders', () => {
48
49
  headers: { origin: 'http://localhost/', host: 'http://github.com' },
49
50
  } as any as IncomingMessage
50
51
  const resp: ServerResponse = {
51
- setHeader: jest.fn(),
52
+ setHeader: vi.fn(),
52
53
  } as unknown as ServerResponse
53
54
 
54
55
  utils.addCorsHeaders(
@@ -67,7 +68,7 @@ describe('AddCorsHeaders', () => {
67
68
  headers: { origin: 'http://localhost/', host: 'http://github.com' },
68
69
  } as any as IncomingMessage
69
70
  const resp: ServerResponse = {
70
- setHeader: jest.fn(),
71
+ setHeader: vi.fn(),
71
72
  } as unknown as ServerResponse
72
73
 
73
74
  utils.addCorsHeaders(
@@ -92,7 +93,7 @@ describe('AddCorsHeaders', () => {
92
93
  headers: { origin: 'http://localhost/', host: 'http://github.com' },
93
94
  } as any as IncomingMessage
94
95
  const resp: ServerResponse = {
95
- setHeader: jest.fn(),
96
+ setHeader: vi.fn(),
96
97
  } as unknown as ServerResponse
97
98
 
98
99
  utils.addCorsHeaders(
@@ -115,7 +116,7 @@ describe('AddCorsHeaders', () => {
115
116
  headers: { origin: 'http://localhost/', host: 'http://github.com' },
116
117
  } as any as IncomingMessage
117
118
  const resp: ServerResponse = {
118
- setHeader: jest.fn(),
119
+ setHeader: vi.fn(),
119
120
  } as unknown as ServerResponse
120
121
 
121
122
  utils.addCorsHeaders(
@@ -6,6 +6,7 @@ import { Authenticate } from './authenticate'
6
6
  import type { ServerResponse } from 'http'
7
7
  import { IdentityContext } from '@furystack/core'
8
8
  import { EmptyResult } from './request-action-implementation'
9
+ import { describe, it, expect, vi } from 'vitest'
9
10
 
10
11
  describe('Authenticate', () => {
11
12
  const response = {} as any as ServerResponse
@@ -13,7 +14,7 @@ describe('Authenticate', () => {
13
14
 
14
15
  it('Should return 403 w/o basic auth header, when unauthorized and basic auth is disabled', async () => {
15
16
  await usingAsync(new Injector(), async (i) => {
16
- const isAuthenticatedAction = jest.fn(async () => false)
17
+ const isAuthenticatedAction = vi.fn(async () => false)
17
18
 
18
19
  i.setExplicitInstance(
19
20
  { isAuthenticated: isAuthenticatedAction, getCurrentUser: async () => Promise.reject(':(') },
@@ -26,7 +27,7 @@ describe('Authenticate', () => {
26
27
  },
27
28
  HttpUserContext,
28
29
  )
29
- const exampleAuthenticatedAction = jest.fn(async () => EmptyResult())
30
+ const exampleAuthenticatedAction = vi.fn(async () => EmptyResult())
30
31
  const authorized = Authenticate()(exampleAuthenticatedAction)
31
32
 
32
33
  const result = await authorized({ injector: i, request, response })
@@ -39,7 +40,7 @@ describe('Authenticate', () => {
39
40
 
40
41
  it('Should return 403 with basic auth headers when unauthorized and basic auth is enabled', async () => {
41
42
  await usingAsync(new Injector(), async (i) => {
42
- const isAuthenticatedAction = jest.fn(async () => false)
43
+ const isAuthenticatedAction = vi.fn(async () => false)
43
44
  i.setExplicitInstance(
44
45
  {
45
46
  isAuthenticated: isAuthenticatedAction,
@@ -48,7 +49,7 @@ describe('Authenticate', () => {
48
49
  },
49
50
  HttpUserContext,
50
51
  )
51
- const exampleAuthenticatedAction = jest.fn(async () => EmptyResult())
52
+ const exampleAuthenticatedAction = vi.fn(async () => EmptyResult())
52
53
  const authorized = Authenticate()(exampleAuthenticatedAction)
53
54
 
54
55
  const result = await authorized({ injector: i, request, response })
@@ -61,12 +62,12 @@ describe('Authenticate', () => {
61
62
 
62
63
  it('Should exec the original action if authorized', async () => {
63
64
  await usingAsync(new Injector(), async (i) => {
64
- const isAuthenticatedAction = jest.fn(async () => true)
65
+ const isAuthenticatedAction = vi.fn(async () => true)
65
66
  i.setExplicitInstance(
66
67
  { isAuthenticated: isAuthenticatedAction, getCurrentUser: async () => Promise.reject(':(') },
67
68
  IdentityContext,
68
69
  )
69
- const exampleAuthenticatedAction = jest.fn(async () => EmptyResult())
70
+ const exampleAuthenticatedAction = vi.fn(async () => EmptyResult())
70
71
  const authorized = Authenticate()(exampleAuthenticatedAction)
71
72
  const params = { injector: i, body: undefined, query: undefined, request, response }
72
73
  const result = await authorized(params)
@@ -6,6 +6,7 @@ import { IdentityContext } from '@furystack/core'
6
6
  import { Authorize } from './authorize'
7
7
  import type { ServerResponse } from 'http'
8
8
  import { EmptyResult } from './request-action-implementation'
9
+ import { describe, it, expect, vi } from 'vitest'
9
10
 
10
11
  describe('Authorize', () => {
11
12
  const response = {} as any as ServerResponse
@@ -13,12 +14,12 @@ describe('Authorize', () => {
13
14
 
14
15
  it('Should return 403 when failed to get current user', async () => {
15
16
  await usingAsync(new Injector(), async (i) => {
16
- const isAuthorizedAction = jest.fn(async () => false)
17
+ const isAuthorizedAction = vi.fn(async () => false)
17
18
  i.setExplicitInstance(
18
19
  { isAuthorized: isAuthorizedAction, getCurrentUser: () => Promise.reject(':(') },
19
20
  IdentityContext,
20
21
  )
21
- const exampleAuthorizedAction = jest.fn(async () => EmptyResult())
22
+ const exampleAuthorizedAction = vi.fn(async () => EmptyResult())
22
23
  const authorized = Authorize('Role1')(exampleAuthorizedAction)
23
24
 
24
25
  const result = await authorized({ injector: i, request, response })
@@ -30,7 +31,7 @@ describe('Authorize', () => {
30
31
 
31
32
  it('Should return 403 if the current user does not have the role', async () => {
32
33
  await usingAsync(new Injector(), async (i) => {
33
- const isAuthorizedAction = jest.fn(async () => false)
34
+ const isAuthorizedAction = vi.fn(async () => false)
34
35
  i.setExplicitInstance(
35
36
  {
36
37
  isAuthorized: isAuthorizedAction,
@@ -38,7 +39,7 @@ describe('Authorize', () => {
38
39
  },
39
40
  IdentityContext,
40
41
  )
41
- const exampleAuthorizedAction = jest.fn(async () => EmptyResult())
42
+ const exampleAuthorizedAction = vi.fn(async () => EmptyResult())
42
43
  const authorized = Authorize('Role2')(exampleAuthorizedAction)
43
44
 
44
45
  const result = await authorized({ injector: i, request, response })
@@ -50,7 +51,7 @@ describe('Authorize', () => {
50
51
 
51
52
  it('Should exec the original action if authorized', async () => {
52
53
  await usingAsync(new Injector(), async (i) => {
53
- const isAuthorizedAction = jest.fn(async () => true)
54
+ const isAuthorizedAction = vi.fn(async () => true)
54
55
  i.setExplicitInstance(
55
56
  {
56
57
  isAuthorized: isAuthorizedAction,
@@ -58,7 +59,7 @@ describe('Authorize', () => {
58
59
  },
59
60
  IdentityContext,
60
61
  )
61
- const exampleAuthorizedAction = jest.fn(async () => EmptyResult())
62
+ const exampleAuthorizedAction = vi.fn(async () => EmptyResult())
62
63
  const authorized = Authorize('Role1')(exampleAuthorizedAction)
63
64
  const params = { injector: i, body: undefined, query: undefined, request, response }
64
65
  const result = await authorized(params)
@@ -5,6 +5,7 @@ import { createDeleteEndpoint } from './create-delete-endpoint'
5
5
  import { MockClass, setupContext } from './utils'
6
6
  import { useRestService } from '../helpers'
7
7
  import { getDataSetFor } from '@furystack/repository'
8
+ import { describe, it, expect } from 'vitest'
8
9
 
9
10
  describe('createDeleteEndpoint', () => {
10
11
  it('Should delete the entity and report the success', async () => {
@@ -7,7 +7,6 @@ import { getRepository } from '@furystack/repository'
7
7
 
8
8
  /**
9
9
  * Creates a DELETE endpoint for removing entities
10
- *
11
10
  * @param options The options for endpoint creation
12
11
  * @param options.model The Model class
13
12
  * @param options.primaryKey The field used as primary key on the model
@@ -7,6 +7,7 @@ import { serializeToQueryString } from '@furystack/rest'
7
7
  import type { FindOptions } from '@furystack/core'
8
8
  import { getDataSetFor, getRepository } from '@furystack/repository'
9
9
  import { useRestService } from '../helpers'
10
+ import { describe, it, expect } from 'vitest'
10
11
 
11
12
  const addMockEntities = async (i: Injector) =>
12
13
  await getRepository(i)
@@ -7,7 +7,6 @@ import { getRepository } from '@furystack/repository'
7
7
 
8
8
  /**
9
9
  * Creates a GetCollection endpoint for the given model. The model should have a Repository DataSet
10
- *
11
10
  * @param options The options for endpoint creation
12
11
  * @param options.model The Model class
13
12
  * @param options.primaryKey The field used as primary key on the model
@@ -6,6 +6,7 @@ import { MockClass, setupContext } from './utils'
6
6
  import { createGetEntityEndpoint } from './create-get-entity-endpoint'
7
7
  import { getDataSetFor } from '@furystack/repository'
8
8
  import { useRestService } from '../helpers'
9
+ import { describe, it, expect } from 'vitest'
9
10
 
10
11
  describe('createGetEntityEndpoint', () => {
11
12
  it('Should return the entity', async () => {
@@ -8,7 +8,6 @@ import { getRepository } from '@furystack/repository'
8
8
 
9
9
  /**
10
10
  * Creates a simple Get Entity endpoint for a specified model.
11
- *
12
11
  * @param options The options for endpoint creation
13
12
  * @param options.model The entity model, should have a Repository DataSet
14
13
  * @param options.primaryKey The field name used as primary key on the model
@@ -5,6 +5,7 @@ import { createPatchEndpoint } from './create-patch-endpoint'
5
5
  import { MockClass, setupContext } from './utils'
6
6
  import { getDataSetFor } from '@furystack/repository'
7
7
  import { useRestService } from '../helpers'
8
+ import { describe, it, expect } from 'vitest'
8
9
 
9
10
  describe('createPatchEndpoint', () => {
10
11
  it('Should update the entity and report the success', async () => {
@@ -9,7 +9,6 @@ import type { WithOptionalId } from '@furystack/core'
9
9
 
10
10
  /**
11
11
  * Creates a PATCH endpoint for updating entities
12
- *
13
12
  * @param options The options for endpoint creation
14
13
  * @param options.model The Model class
15
14
  * @param options.primaryKey The field name that is used as primary key on the model
@@ -5,6 +5,7 @@ import { createPostEndpoint } from './create-post-endpoint'
5
5
  import { MockClass, setupContext } from './utils'
6
6
  import { useRestService } from '../helpers'
7
7
  import { getDataSetFor } from '@furystack/repository'
8
+ import { describe, it, expect } from 'vitest'
8
9
 
9
10
  describe('createPostEndpoint', () => {
10
11
  it('Should create the entity and report the success', async () => {
@@ -9,7 +9,6 @@ import type { WithOptionalId } from '@furystack/core'
9
9
  import { getRepository } from '@furystack/repository'
10
10
  /**
11
11
  * Creates a POST endpoint for updating entities
12
- *
13
12
  * @param options The options for endpoint creation
14
13
  * @param options.model The Model class
15
14
  * @param options.primaryKey The field name used as primary key
@@ -4,6 +4,7 @@ import { ApiManager } from './api-manager'
4
4
  import { HttpAuthenticationSettings } from './http-authentication-settings'
5
5
  import { useHttpAuthentication, useRestService, useStaticFiles } from './helpers'
6
6
  import { StaticServerManager } from './static-server-manager'
7
+ import { describe, it, expect } from 'vitest'
7
8
 
8
9
  describe('Injector extensions', () => {
9
10
  describe('useHttpAuthentication', () => {
package/src/helpers.ts CHANGED
@@ -10,17 +10,14 @@ import { StaticServerManager } from './static-server-manager'
10
10
 
11
11
  /**
12
12
  * Sets up the @furystack/rest-service with the provided settings
13
- *
14
13
  * @param api The API implementation details
14
+ * @returns a promise that resolves when the API is added to the server
15
15
  */
16
- export const useRestService = async <T extends RestApi>(api: ImplementApiOptions<T>) => {
16
+ export const useRestService = async <T extends RestApi>(api: ImplementApiOptions<T>) =>
17
17
  await api.injector.getInstance(ApiManager).addApi({ ...api })
18
- return this
19
- }
20
18
 
21
19
  /**
22
20
  * Sets up the HTTP Authentication
23
- *
24
21
  * @param injector The Injector instance
25
22
  * @param settings Settings for HTTP Authentication
26
23
  * @returns void
@@ -32,7 +29,6 @@ export const useHttpAuthentication = <TUser extends User, TSession extends Defau
32
29
 
33
30
  /**
34
31
  * Sets up a static file server
35
- *
36
32
  * @param options The settings for the static file server
37
33
  * @param options.injector The Injector instance
38
34
  * @param options.settings Settings for the static file server
@@ -6,6 +6,7 @@ import { DefaultSession } from './models/default-session'
6
6
  import { HttpUserContext } from './http-user-context'
7
7
  import { PasswordAuthenticator, PasswordCredential, UnauthenticatedError } from '@furystack/security'
8
8
  import { useHttpAuthentication } from './helpers'
9
+ import { describe, it, expect, vi } from 'vitest'
9
10
 
10
11
  export const prepareInjector = async (i: Injector) => {
11
12
  addStore(i, new InMemoryStore({ model: User, primaryKey: 'username' }))
@@ -43,7 +44,7 @@ describe('HttpUserContext', () => {
43
44
  await usingAsync(new Injector(), async (i) => {
44
45
  await prepareInjector(i)
45
46
  const ctx = i.getInstance(HttpUserContext)
46
- ctx.getCurrentUser = jest.fn(async () => testUser)
47
+ ctx.getCurrentUser = vi.fn(async () => testUser)
47
48
  const value = await ctx.isAuthenticated(request)
48
49
  expect(value).toBe(true)
49
50
  expect(ctx.getCurrentUser).toBeCalled()
@@ -54,7 +55,7 @@ describe('HttpUserContext', () => {
54
55
  await usingAsync(new Injector(), async (i) => {
55
56
  await prepareInjector(i)
56
57
  const ctx = i.getInstance(HttpUserContext)
57
- ctx.getCurrentUser = jest.fn(async () => {
58
+ ctx.getCurrentUser = vi.fn(async () => {
58
59
  throw Error(':(')
59
60
  })
60
61
  await expect(ctx.isAuthenticated(request)).resolves.toEqual(false)
@@ -68,7 +69,7 @@ describe('HttpUserContext', () => {
68
69
  await usingAsync(new Injector(), async (i) => {
69
70
  await prepareInjector(i)
70
71
  const ctx = i.getInstance(HttpUserContext)
71
- ctx.getCurrentUser = jest.fn(async () => testUser)
72
+ ctx.getCurrentUser = vi.fn(async () => testUser)
72
73
  const value = await ctx.isAuthorized(request, 'grantedRole1', 'grantedRole2')
73
74
  expect(value).toBe(true)
74
75
  expect(ctx.getCurrentUser).toBeCalled()
@@ -79,7 +80,7 @@ describe('HttpUserContext', () => {
79
80
  await usingAsync(new Injector(), async (i) => {
80
81
  await prepareInjector(i)
81
82
  const ctx = i.getInstance(HttpUserContext)
82
- ctx.getCurrentUser = jest.fn(async () => testUser)
83
+ ctx.getCurrentUser = vi.fn(async () => testUser)
83
84
  const value = await ctx.isAuthorized(request, 'grantedRole1', 'nonGrantedRole2')
84
85
  expect(value).toBe(false)
85
86
  expect(ctx.getCurrentUser).toBeCalled()
@@ -187,7 +188,7 @@ describe('HttpUserContext', () => {
187
188
  await usingAsync(new Injector(), async (i) => {
188
189
  await prepareInjector(i)
189
190
  const ctx = i.getInstance(HttpUserContext)
190
- ctx.authenticateUser = jest.fn(async () => testUser)
191
+ ctx.authenticateUser = vi.fn(async () => testUser)
191
192
  const result = await ctx.authenticateRequest({
192
193
  headers: { authorization: `Basic dGVzdHVzZXI6cGFzc3dvcmQ=` },
193
194
  } as IncomingMessage)
@@ -201,7 +202,7 @@ describe('HttpUserContext', () => {
201
202
  await prepareInjector(i)
202
203
  const ctx = i.getInstance(HttpUserContext)
203
204
  ctx.authentication.enableBasicAuth = false
204
- ctx.authenticateUser = jest.fn(async () => testUser)
205
+ ctx.authenticateUser = vi.fn(async () => testUser)
205
206
  await expect(
206
207
  ctx.authenticateRequest({
207
208
  headers: { authorization: `Basic dGVzdHVzZXI6cGFzc3dvcmQ=` },
@@ -263,7 +264,7 @@ describe('HttpUserContext', () => {
263
264
  await usingAsync(new Injector(), async (i) => {
264
265
  await prepareInjector(i)
265
266
  const ctx = i.getInstance(HttpUserContext)
266
- ctx.authenticateRequest = jest.fn(async () => testUser)
267
+ ctx.authenticateRequest = vi.fn(async () => testUser)
267
268
  const result = await ctx.getCurrentUser(request)
268
269
  const result2 = await ctx.getCurrentUser(request)
269
270
  expect(ctx.authenticateRequest).toBeCalledTimes(1)
@@ -278,8 +279,8 @@ describe('HttpUserContext', () => {
278
279
  await usingAsync(new Injector(), async (i) => {
279
280
  await prepareInjector(i)
280
281
  const ctx = i.getInstance(HttpUserContext)
281
- const setHeader = jest.fn()
282
- ctx.getSessionStore().add = jest.fn(async () => {
282
+ const setHeader = vi.fn()
283
+ ctx.getSessionStore().add = vi.fn(async () => {
283
284
  return {} as any
284
285
  })
285
286
  const authResult = await ctx.cookieLogin(testUser, { setHeader } as any)
@@ -295,14 +296,14 @@ describe('HttpUserContext', () => {
295
296
  await usingAsync(new Injector(), async (i) => {
296
297
  await prepareInjector(i)
297
298
  const ctx = i.getInstance(HttpUserContext)
298
- const setHeader = jest.fn()
299
- ctx.getSessionStore().add = jest.fn(async () => {
299
+ const setHeader = vi.fn()
300
+ ctx.getSessionStore().add = vi.fn(async () => {
300
301
  return {} as any
301
302
  })
302
- ctx.authenticateRequest = jest.fn(async () => testUser)
303
- ctx.getSessionStore().remove = jest.fn(async () => undefined)
303
+ ctx.authenticateRequest = vi.fn(async () => testUser)
304
+ ctx.getSessionStore().remove = vi.fn(async () => undefined)
304
305
  ctx.getSessionIdFromRequest = () => 'example-session-id'
305
- response.setHeader = jest.fn(() => response)
306
+ response.setHeader = vi.fn(() => response)
306
307
  await ctx.cookieLogin(testUser, { setHeader } as any)
307
308
  await ctx.cookieLogout(request, response)
308
309
  expect(response.setHeader).toBeCalledWith('Set-Cookie', 'fss=; Path=/; HttpOnly')
@@ -51,7 +51,6 @@ export class HttpUserContext {
51
51
 
52
52
  /**
53
53
  * Returns if the current user can be authorized with ALL of the specified roles
54
- *
55
54
  * @param request The request to be authenticated
56
55
  * @param roles The list of roles to authorize
57
56
  * @returns a boolean value that indicates if the user is authenticated
@@ -68,7 +67,6 @@ export class HttpUserContext {
68
67
 
69
68
  /**
70
69
  * Checks if the system contains a user with the provided name and password, throws an error otherwise
71
- *
72
70
  * @param userName The username
73
71
  * @param password The password
74
72
  * @returns the authenticated User
@@ -137,7 +135,6 @@ export class HttpUserContext {
137
135
 
138
136
  /**
139
137
  * Creates and sets up a cookie-based session for the provided user
140
- *
141
138
  * @param user The user to create a session for
142
139
  * @param serverResponse A serverResponse to set the cookie
143
140
  * @returns the current User
@@ -1,6 +1,7 @@
1
1
  import { IncomingMessage } from 'http'
2
2
  import './incoming-message-extensions'
3
3
  import { Socket } from 'net'
4
+ import { describe, it, expect } from 'vitest'
4
5
 
5
6
  describe('IncomingMessage extensions', () => {
6
7
  describe('readPostBody', () => {
@@ -1,4 +1,5 @@
1
1
  import { getMimeForFile } from './mime-types'
2
+ import { describe, it, expect } from 'vitest'
2
3
  describe('MIME Types', () => {
3
4
  it('Should return a default fallback', () => {
4
5
  expect(getMimeForFile('test.alma')).toBe('application/octet-stream')
@@ -7,6 +7,7 @@ import { User, InMemoryStore, addStore } from '@furystack/core'
7
7
  import { DefaultSession } from './models/default-session'
8
8
  import { JsonResult } from './request-action-implementation'
9
9
  import { useHttpAuthentication, useRestService } from './helpers'
10
+ import { describe, it, expect } from 'vitest'
10
11
 
11
12
  class UserWithPassword extends User {
12
13
  password!: string
@@ -5,6 +5,7 @@ import { usingAsync } from '@furystack/utils'
5
5
  import { JsonResult } from './request-action-implementation'
6
6
  import './helpers'
7
7
  import { useRestService } from './helpers'
8
+ import { describe, it, expect } from 'vitest'
8
9
 
9
10
  export interface EchoApi extends RestApi {
10
11
  GET: {
@@ -2,6 +2,7 @@ import { SchemaValidator } from './schema-validator'
2
2
  import type { BodyParameters, Language } from './validate-examples'
3
3
  import { exampleSchema } from './validate-examples'
4
4
  import { SchemaValidationError } from './schema-validation-error'
5
+ import { describe, it, expect } from 'vitest'
5
6
 
6
7
  describe('ValidateSchema', () => {
7
8
  describe('String Literal checks', () => {