@furystack/rest-service 12.0.0 โ†’ 12.1.1

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 (50) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/esm/actions/index.d.ts +1 -0
  3. package/esm/actions/index.d.ts.map +1 -1
  4. package/esm/actions/index.js +1 -0
  5. package/esm/actions/index.js.map +1 -1
  6. package/esm/actions/login.d.ts +7 -3
  7. package/esm/actions/login.d.ts.map +1 -1
  8. package/esm/actions/login.js +11 -5
  9. package/esm/actions/login.js.map +1 -1
  10. package/esm/actions/password-login-action.d.ts +24 -0
  11. package/esm/actions/password-login-action.d.ts.map +1 -0
  12. package/esm/actions/password-login-action.js +31 -0
  13. package/esm/actions/password-login-action.js.map +1 -0
  14. package/esm/actions/password-login-action.spec.d.ts +2 -0
  15. package/esm/actions/password-login-action.spec.d.ts.map +1 -0
  16. package/esm/actions/password-login-action.spec.js +105 -0
  17. package/esm/actions/password-login-action.spec.js.map +1 -0
  18. package/esm/helpers.d.ts.map +1 -1
  19. package/esm/helpers.js +0 -2
  20. package/esm/helpers.js.map +1 -1
  21. package/esm/http-authentication-settings.d.ts +3 -3
  22. package/esm/http-authentication-settings.d.ts.map +1 -1
  23. package/esm/http-authentication-settings.js +3 -2
  24. package/esm/http-authentication-settings.js.map +1 -1
  25. package/esm/http-user-context.d.ts +1 -1
  26. package/esm/http-user-context.d.ts.map +1 -1
  27. package/esm/index.d.ts +1 -0
  28. package/esm/index.d.ts.map +1 -1
  29. package/esm/index.js +1 -0
  30. package/esm/index.js.map +1 -1
  31. package/esm/login-response-strategy.d.ts +28 -0
  32. package/esm/login-response-strategy.d.ts.map +1 -0
  33. package/esm/login-response-strategy.js +28 -0
  34. package/esm/login-response-strategy.js.map +1 -0
  35. package/esm/login-response-strategy.spec.d.ts +2 -0
  36. package/esm/login-response-strategy.spec.d.ts.map +1 -0
  37. package/esm/login-response-strategy.spec.js +78 -0
  38. package/esm/login-response-strategy.spec.js.map +1 -0
  39. package/package.json +7 -7
  40. package/src/actions/index.ts +1 -0
  41. package/src/actions/login.ts +12 -6
  42. package/src/actions/password-login-action.spec.ts +122 -0
  43. package/src/actions/password-login-action.ts +35 -0
  44. package/src/helpers.ts +1 -3
  45. package/src/http-authentication-settings.ts +32 -30
  46. package/src/http-user-context.spec.ts +462 -462
  47. package/src/http-user-context.ts +164 -164
  48. package/src/index.ts +1 -0
  49. package/src/login-response-strategy.spec.ts +90 -0
  50. package/src/login-response-strategy.ts +48 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,63 @@
1
1
  # Changelog
2
2
 
3
+ ## [12.1.1] - 2026-02-27
4
+
5
+ ### ๐Ÿ› Bug Fixes
6
+
7
+ - Fixed `HttpAuthenticationSettings` not respecting its `TUser` and `TSession` generic type parameters when resolving data sets. `getUserDataSet` now uses the configurable `model` property instead of the hardcoded `User` class, and `getSessionDataSet` now uses the new `sessionModel` property instead of the hardcoded `DefaultSession` class. This allows custom user and session types to work correctly with `useHttpAuthentication`.
8
+
9
+ ## [12.1.0] - 2026-02-26
10
+
11
+ ### ๐Ÿ”ง Chores
12
+
13
+ - Normalized line endings in `http-user-context.ts`, `http-authentication-settings.ts`, and related spec files
14
+
15
+ ### โœจ Features
16
+
17
+ ### `LoginResponseStrategy<TResult>` type
18
+
19
+ New pluggable type that decouples login actions from session/token creation. A strategy turns an authenticated `User` into an `ActionResult<TResult>` โ€” the generic parameter flows through to the action's return type for full type inference.
20
+
21
+ ```typescript
22
+ import type { LoginResponseStrategy } from '@furystack/rest-service'
23
+
24
+ type LoginResponseStrategy<TResult> = {
25
+ createLoginResponse: (user: User, injector: Injector) => Promise<ActionResult<TResult>>
26
+ }
27
+ ```
28
+
29
+ ### `createCookieLoginStrategy(injector)`
30
+
31
+ Factory that creates a cookie-based `LoginResponseStrategy<User>`. On login it generates a random session ID, persists it in the session DataSet, and returns the user with a `Set-Cookie` header.
32
+
33
+ ```typescript
34
+ import { createCookieLoginStrategy } from '@furystack/rest-service'
35
+
36
+ const cookieStrategy = createCookieLoginStrategy(injector)
37
+ // cookieStrategy.createLoginResponse(user, injector) โ†’ ActionResult<User> with Set-Cookie header
38
+ ```
39
+
40
+ ### `createPasswordLoginAction(strategy)`
41
+
42
+ Factory that creates a password-based login `RequestAction`. Authenticates via `HttpUserContext.authenticateUser()` then delegates session/token creation to the provided strategy. Includes timing-attack mitigation on failure.
43
+
44
+ ```typescript
45
+ import { createPasswordLoginAction, createCookieLoginStrategy } from '@furystack/rest-service'
46
+
47
+ const cookieStrategy = createCookieLoginStrategy(injector)
48
+ const loginAction = createPasswordLoginAction(cookieStrategy)
49
+ // loginAction: RequestAction<{ result: User; body: { username: string; password: string } }>
50
+ ```
51
+
52
+ ### ๐Ÿงช Tests
53
+
54
+ - Added `login-response-strategy.spec.ts` โ€” tests cookie strategy session creation, Set-Cookie headers, session persistence, and session ID uniqueness
55
+ - Added `password-login-action.spec.ts` โ€” tests strategy delegation, user forwarding, auth failure handling, and custom strategy result types
56
+
57
+ ### โฌ†๏ธ Dependencies
58
+
59
+ - Bumped `@types/node` from ^25.3.0 to ^25.3.1
60
+
3
61
  ## [12.0.0] - 2026-02-26
4
62
 
5
63
  ### โœจ Features
@@ -4,4 +4,5 @@ export * from './is-authenticated.js';
4
4
  export * from './login.js';
5
5
  export * from './logout.js';
6
6
  export * from './not-found-action.js';
7
+ export * from './password-login-action.js';
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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"}
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;AACrC,cAAc,4BAA4B,CAAA"}
@@ -4,4 +4,5 @@ export * from './is-authenticated.js';
4
4
  export * from './login.js';
5
5
  export * from './logout.js';
6
6
  export * from './not-found-action.js';
7
+ export * from './password-login-action.js';
7
8
  //# sourceMappingURL=index.js.map
@@ -1 +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
+ {"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;AACrC,cAAc,4BAA4B,CAAA"}
@@ -1,9 +1,13 @@
1
1
  import type { User } from '@furystack/core';
2
2
  import type { RequestAction } from '../request-action-implementation.js';
3
3
  /**
4
- * Action that logs in the current user
5
- * Should be called with a JSON Post body with ``username`` and ``password`` fields.
6
- * Returns the current user instance
4
+ * Action that logs in the current user.
5
+ * Should be called with a JSON POST body with `username` and `password` fields.
6
+ * Returns the current user instance.
7
+ *
8
+ * @deprecated Use `createPasswordLoginAction(createCookieLoginStrategy(injector))` instead.
9
+ * This static action resolves services from the request-scoped injector on
10
+ * every call; the factory approach captures them once at setup time.
7
11
  */
8
12
  export declare const LoginAction: RequestAction<{
9
13
  result: User;
@@ -1 +1 @@
1
- {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/actions/login.ts"],"names":[],"mappings":"AACA,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"}
1
+ {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/actions/login.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAK3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAGxE;;;;;;;;GAQG;AACH,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,CAWA,CAAA"}
@@ -1,10 +1,15 @@
1
- import { HttpUserContext } from '../http-user-context.js';
2
1
  import { RequestError } from '@furystack/rest';
2
+ import { sleepAsync } from '@furystack/utils';
3
+ import { HttpUserContext } from '../http-user-context.js';
3
4
  import { JsonResult } from '../request-action-implementation.js';
4
5
  /**
5
- * Action that logs in the current user
6
- * Should be called with a JSON Post body with ``username`` and ``password`` fields.
7
- * Returns the current user instance
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
+ * @deprecated Use `createPasswordLoginAction(createCookieLoginStrategy(injector))` instead.
11
+ * This static action resolves services from the request-scoped injector on
12
+ * every call; the factory approach captures them once at setup time.
8
13
  */
9
14
  export const LoginAction = async ({ injector, getBody, response }) => {
10
15
  const userContext = injector.getInstance(HttpUserContext);
@@ -14,7 +19,8 @@ export const LoginAction = async ({ injector, getBody, response }) => {
14
19
  await userContext.cookieLogin(user, response);
15
20
  return JsonResult(user, 200);
16
21
  }
17
- catch (error) {
22
+ catch {
23
+ await sleepAsync(Math.random() * 1000);
18
24
  throw new RequestError('Login Failed', 400);
19
25
  }
20
26
  };
@@ -1 +1 @@
1
- {"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/actions/login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAEzD,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,CAAC;QACH,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;IAC9B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,YAAY,CAAC,cAAc,EAAE,GAAG,CAAC,CAAA;IAC7C,CAAC;AACH,CAAC,CAAA"}
1
+ {"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/actions/login.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAEzD,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAA;AAEhE;;;;;;;;GAQG;AACH,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,CAAC;QACH,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;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAA;QACtC,MAAM,IAAI,YAAY,CAAC,cAAc,EAAE,GAAG,CAAC,CAAA;IAC7C,CAAC;AACH,CAAC,CAAA"}
@@ -0,0 +1,24 @@
1
+ import type { LoginResponseStrategy } from '../login-response-strategy.js';
2
+ import type { RequestAction } from '../request-action-implementation.js';
3
+ /**
4
+ * Creates a login {@link RequestAction} that authenticates a user by
5
+ * username + password, then delegates session/token creation to the
6
+ * provided {@link LoginResponseStrategy}.
7
+ *
8
+ * The return type is inferred from the strategy:
9
+ * - Cookie strategy -> `ActionResult<User>`
10
+ * - JWT strategy -> `ActionResult<{ accessToken: string; refreshToken: string }>`
11
+ *
12
+ * A random delay (0-1 s) is added on failure to mitigate timing attacks.
13
+ *
14
+ * @param strategy The login response strategy that produces the session/token result
15
+ * @returns A `RequestAction` that can be wired into a REST API route
16
+ */
17
+ export declare const createPasswordLoginAction: <TResult>(strategy: LoginResponseStrategy<TResult>) => RequestAction<{
18
+ result: TResult;
19
+ body: {
20
+ username: string;
21
+ password: string;
22
+ };
23
+ }>;
24
+ //# sourceMappingURL=password-login-action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password-login-action.d.ts","sourceRoot":"","sources":["../../src/actions/password-login-action.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAExE;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,yBAAyB,GAAI,OAAO,EAC/C,UAAU,qBAAqB,CAAC,OAAO,CAAC,KACvC,aAAa,CAAC;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAWjF,CAAA"}
@@ -0,0 +1,31 @@
1
+ import { RequestError } from '@furystack/rest';
2
+ import { sleepAsync } from '@furystack/utils';
3
+ import { HttpUserContext } from '../http-user-context.js';
4
+ /**
5
+ * Creates a login {@link RequestAction} that authenticates a user by
6
+ * username + password, then delegates session/token creation to the
7
+ * provided {@link LoginResponseStrategy}.
8
+ *
9
+ * The return type is inferred from the strategy:
10
+ * - Cookie strategy -> `ActionResult<User>`
11
+ * - JWT strategy -> `ActionResult<{ accessToken: string; refreshToken: string }>`
12
+ *
13
+ * A random delay (0-1 s) is added on failure to mitigate timing attacks.
14
+ *
15
+ * @param strategy The login response strategy that produces the session/token result
16
+ * @returns A `RequestAction` that can be wired into a REST API route
17
+ */
18
+ export const createPasswordLoginAction = (strategy) => {
19
+ return async ({ injector, getBody }) => {
20
+ const body = await getBody();
21
+ try {
22
+ const user = await injector.getInstance(HttpUserContext).authenticateUser(body.username, body.password);
23
+ return strategy.createLoginResponse(user, injector);
24
+ }
25
+ catch {
26
+ await sleepAsync(Math.random() * 1000);
27
+ throw new RequestError('Login Failed', 400);
28
+ }
29
+ };
30
+ };
31
+ //# sourceMappingURL=password-login-action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password-login-action.js","sourceRoot":"","sources":["../../src/actions/password-login-action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAIzD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,QAAwC,EAC0C,EAAE;IACpF,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE;QACrC,MAAM,IAAI,GAAG,MAAM,OAAO,EAAE,CAAA;QAC5B,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;YACvG,OAAO,QAAQ,CAAC,mBAAmB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;QACrD,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAA;YACtC,MAAM,IAAI,YAAY,CAAC,cAAc,EAAE,GAAG,CAAC,CAAA;QAC7C,CAAC;IACH,CAAC,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=password-login-action.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password-login-action.spec.d.ts","sourceRoot":"","sources":["../../src/actions/password-login-action.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,105 @@
1
+ import { InMemoryStore, StoreManager, User, addStore } from '@furystack/core';
2
+ import { Injector } from '@furystack/inject';
3
+ import { getRepository } from '@furystack/repository';
4
+ import { PasswordAuthenticator, PasswordCredential, PasswordResetToken, usePasswordPolicy } from '@furystack/security';
5
+ import { usingAsync } from '@furystack/utils';
6
+ import { describe, expect, it, vi } from 'vitest';
7
+ import { useHttpAuthentication } from '../helpers.js';
8
+ import { DefaultSession } from '../models/default-session.js';
9
+ import { JsonResult } from '../request-action-implementation.js';
10
+ import { createPasswordLoginAction } from './password-login-action.js';
11
+ const setupInjector = async (i, username, password) => {
12
+ addStore(i, new InMemoryStore({ model: User, primaryKey: 'username' }))
13
+ .addStore(new InMemoryStore({ model: DefaultSession, primaryKey: 'sessionId' }))
14
+ .addStore(new InMemoryStore({ model: PasswordCredential, primaryKey: 'userName' }))
15
+ .addStore(new InMemoryStore({ model: PasswordResetToken, primaryKey: 'token' }));
16
+ const repo = getRepository(i);
17
+ repo.createDataSet(User, 'username');
18
+ repo.createDataSet(DefaultSession, 'sessionId');
19
+ repo.createDataSet(PasswordCredential, 'userName');
20
+ repo.createDataSet(PasswordResetToken, 'token');
21
+ usePasswordPolicy(i);
22
+ useHttpAuthentication(i);
23
+ const sm = i.getInstance(StoreManager);
24
+ const pw = i.getInstance(PasswordAuthenticator);
25
+ const cred = await pw.hasher.createCredential(username, password);
26
+ await sm.getStoreFor(PasswordCredential, 'userName').add(cred);
27
+ await sm.getStoreFor(User, 'username').add({ username, roles: ['admin'] });
28
+ };
29
+ const mockStrategy = {
30
+ createLoginResponse: vi.fn(async (user) => JsonResult(user, 200)),
31
+ };
32
+ describe('createPasswordLoginAction', () => {
33
+ const request = {};
34
+ const response = {};
35
+ it('Should delegate to the strategy on successful authentication', async () => {
36
+ await usingAsync(new Injector(), async (i) => {
37
+ await setupInjector(i, 'testuser', 'testpass');
38
+ const action = createPasswordLoginAction(mockStrategy);
39
+ const result = await action({
40
+ injector: i,
41
+ request,
42
+ response,
43
+ getBody: () => Promise.resolve({ username: 'testuser', password: 'testpass' }),
44
+ });
45
+ expect(mockStrategy.createLoginResponse).toHaveBeenCalled();
46
+ expect(result.chunk.username).toBe('testuser');
47
+ });
48
+ });
49
+ it('Should pass the correct user to the strategy', async () => {
50
+ await usingAsync(new Injector(), async (i) => {
51
+ await setupInjector(i, 'testuser', 'testpass');
52
+ const strategyFn = vi.fn(async (user) => JsonResult(user, 200));
53
+ const strategy = { createLoginResponse: strategyFn };
54
+ const action = createPasswordLoginAction(strategy);
55
+ await action({
56
+ injector: i,
57
+ request,
58
+ response,
59
+ getBody: () => Promise.resolve({ username: 'testuser', password: 'testpass' }),
60
+ });
61
+ expect(strategyFn).toHaveBeenCalledWith(expect.objectContaining({ username: 'testuser', roles: ['admin'] }), i);
62
+ });
63
+ });
64
+ it('Should throw RequestError on invalid credentials', async () => {
65
+ await usingAsync(new Injector(), async (i) => {
66
+ await setupInjector(i, 'testuser', 'testpass');
67
+ const action = createPasswordLoginAction(mockStrategy);
68
+ await expect(action({
69
+ injector: i,
70
+ request,
71
+ response,
72
+ getBody: () => Promise.resolve({ username: 'testuser', password: 'wrongpass' }),
73
+ })).rejects.toThrow('Login Failed');
74
+ });
75
+ });
76
+ it('Should throw RequestError for nonexistent user', async () => {
77
+ await usingAsync(new Injector(), async (i) => {
78
+ await setupInjector(i, 'testuser', 'testpass');
79
+ const action = createPasswordLoginAction(mockStrategy);
80
+ await expect(action({
81
+ injector: i,
82
+ request,
83
+ response,
84
+ getBody: () => Promise.resolve({ username: 'nobody', password: 'nopass' }),
85
+ })).rejects.toThrow('Login Failed');
86
+ });
87
+ });
88
+ it('Should work with a custom result type from strategy', async () => {
89
+ await usingAsync(new Injector(), async (i) => {
90
+ await setupInjector(i, 'testuser', 'testpass');
91
+ const tokenStrategy = {
92
+ createLoginResponse: async () => JsonResult({ accessToken: 'tok123' }, 200),
93
+ };
94
+ const action = createPasswordLoginAction(tokenStrategy);
95
+ const result = await action({
96
+ injector: i,
97
+ request,
98
+ response,
99
+ getBody: () => Promise.resolve({ username: 'testuser', password: 'testpass' }),
100
+ });
101
+ expect(result.chunk.accessToken).toBe('tok123');
102
+ });
103
+ });
104
+ });
105
+ //# sourceMappingURL=password-login-action.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password-login-action.spec.js","sourceRoot":"","sources":["../../src/actions/password-login-action.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC7E,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACtH,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAEjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAErD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAA;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAA;AAEtE,MAAM,aAAa,GAAG,KAAK,EAAE,CAAW,EAAE,QAAgB,EAAE,QAAgB,EAAE,EAAE;IAC9E,QAAQ,CAAC,CAAC,EAAE,IAAI,aAAa,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC;SACpE,QAAQ,CAAC,IAAI,aAAa,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;SAC/E,QAAQ,CAAC,IAAI,aAAa,CAAC,EAAE,KAAK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MAAM,iBAAiB,CAAA;AAE3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAI9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAM3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAA;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAGrE;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAU,CAAC,SAAS,OAAO,EAAE,KAAK,mBAAmB,CAAC,CAAC,CAAC;;;EACpB,CAAA;AAE/D;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,GAAI,KAAK,SAAS,IAAI,EAAE,QAAQ,SAAS,cAAc,EACvF,UAAU,QAAQ,EAClB,WAAW,OAAO,CAAC,0BAA0B,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,SAiChE,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,GAAG,mBAAmB,kBAGnF,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,eAAO,MAAM,QAAQ,GAAI,SAAS;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,GAAG,YAAY,kBAGtE,CAAA"}
package/esm/helpers.js CHANGED
@@ -27,8 +27,6 @@ export const useHttpAuthentication = (injector, settings) => {
27
27
  const systemInjector = useSystemIdentityContext({ injector, username: 'useHttpAuthentication' });
28
28
  const passwordAuthenticator = injector.getInstance(PasswordAuthenticator);
29
29
  const userDataSet = mergedSettings.getUserDataSet(systemInjector);
30
- // Narrow from DataSet<TSession, keyof TSession> to DataSet<DefaultSession, 'sessionId'>
31
- // because the built-in providers operate on DefaultSession with the concrete 'sessionId' key
32
30
  const sessionDataSet = mergedSettings.getSessionDataSet(systemInjector);
33
31
  const providers = [];
34
32
  if (mergedSettings.enableBasicAuth) {
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAI1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAG3D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,OAAO,EAAE,uBAAuB,EAAE,MAAM,mDAAmD,CAAA;AAC3F,OAAO,EAAE,wBAAwB,EAAE,MAAM,oDAAoD,CAAA;AAC7F,OAAO,EAAE,2BAA2B,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AACpH,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAA;AAG9E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAEhE;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EAAqB,GAA2B,EAAE,EAAE,CACrF,MAAM,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,GAAG,EAAE,CAAC,CAAA;AAE/D;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,QAAkB,EAClB,QAA+D,EAC/D,EAAE;IACF,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,0BAA0B,EAAmB,EAAE,QAAQ,CAAC,CAAA;IACjG,MAAM,cAAc,GAAG,wBAAwB,CAAC,EAAE,QAAQ,E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AAE,EAAE;IACtF,MAAM,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,GAAG,OAAO,CAAA;IACzC,OAAO,QAAQ,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;AAC1E,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,OAA8C,EAAE,EAAE;IACzE,MAAM,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,GAAG,OAAO,CAAA;IACzC,OAAO,QAAQ,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;AAC9D,CAAC,CAAA"}
@@ -1,6 +1,5 @@
1
1
  import { User } from '@furystack/core';
2
2
  import type { Constructable, Injector } from '@furystack/inject';
3
- import type { DataSet } from '@furystack/repository';
4
3
  import type { AuthenticationProvider } from './authentication-providers/authentication-provider.js';
5
4
  import { DefaultSession } from './models/default-session.js';
6
5
  /**
@@ -8,8 +7,9 @@ import { DefaultSession } from './models/default-session.js';
8
7
  */
9
8
  export declare class HttpAuthenticationSettings<TUser extends User, TSession extends DefaultSession> {
10
9
  model: Constructable<TUser>;
11
- getUserDataSet: (injector: Injector) => DataSet<User, "username", import("@furystack/core").WithOptionalId<User, "username">>;
12
- getSessionDataSet: (injector: Injector) => DataSet<TSession, keyof TSession>;
10
+ getUserDataSet: (injector: Injector) => import("@furystack/repository").DataSet<TUser, "username" & keyof TUser, import("@furystack/core").WithOptionalId<TUser, "username" & keyof TUser>>;
11
+ sessionModel: Constructable<TSession>;
12
+ getSessionDataSet: (injector: Injector) => import("@furystack/repository").DataSet<TSession, "sessionId" & keyof TSession, import("@furystack/core").WithOptionalId<TSession, "sessionId" & keyof TSession>>;
13
13
  cookieName: string;
14
14
  enableBasicAuth: boolean;
15
15
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"http-authentication-settings.d.ts","sourceRoot":"","sources":["../src/http-authentication-settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEhE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAEpD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uDAAuD,CAAA;AACnG,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAE5D;;GAEG;AACH,qBACa,0BAA0B,CAAC,KAAK,SAAS,IAAI,EAAE,QAAQ,SAAS,cAAc;IAClF,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,CAA+B;IAE1D,cAAc,GAAI,UAAU,QAAQ,2FAA8C;IAElF,iBAAiB,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,QAAQ,EAAE,MAAM,QAAQ,CAAC,CACmB;IAE/F,UAAU,SAAQ;IAClB,eAAe,UAAO;IAE7B;;;;OAIG;IACI,uBAAuB,EAAE,sBAAsB,EAAE,CAAK;CAC9D"}
1
+ {"version":3,"file":"http-authentication-settings.d.ts","sourceRoot":"","sources":["../src/http-authentication-settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAGhE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uDAAuD,CAAA;AACnG,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAE5D;;GAEG;AACH,qBACa,0BAA0B,CAAC,KAAK,SAAS,IAAI,EAAE,QAAQ,SAAS,cAAc;IAClF,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,CAA+B;IAE1D,cAAc,GAAI,UAAU,QAAQ,yJACkC;IAEtE,YAAY,EAAE,aAAa,CAAC,QAAQ,CAAC,CAA4C;IAEjF,iBAAiB,GAAI,UAAU,QAAQ,uKAC2C;IAElF,UAAU,SAAQ;IAClB,eAAe,UAAO;IAE7B;;;;OAIG;IACI,uBAAuB,EAAE,sBAAsB,EAAE,CAAK;CAC9D"}
@@ -13,8 +13,9 @@ import { DefaultSession } from './models/default-session.js';
13
13
  */
14
14
  let HttpAuthenticationSettings = class HttpAuthenticationSettings {
15
15
  model = User;
16
- getUserDataSet = (injector) => getDataSetFor(injector, User, 'username');
17
- getSessionDataSet = (injector) => getDataSetFor(injector, DefaultSession, 'sessionId');
16
+ getUserDataSet = (injector) => getDataSetFor(injector, this.model, 'username');
17
+ sessionModel = DefaultSession;
18
+ getSessionDataSet = (injector) => getDataSetFor(injector, this.sessionModel, 'sessionId');
18
19
  cookieName = 'fss';
19
20
  enableBasicAuth = true;
20
21
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"http-authentication-settings.js","sourceRoot":"","sources":["../src/http-authentication-settings.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAErD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAE5D;;GAEG;AAEI,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IAC9B,KAAK,GAAyB,IAA4B,CAAA;IAE1D,cAAc,GAAG,CAAC,QAAkB,EAAE,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,EAAE,UAAU,CAAC,CAAA;IAElF,iBAAiB,GAA8D,CAAC,QAAQ,EAAE,EAAE,CACjG,aAAa,CAAC,QAAQ,EAAE,cAAc,EAAE,WAAW,CAAiD,CAAA;IAE/F,UAAU,GAAG,KAAK,CAAA;IAClB,eAAe,GAAG,IAAI,CAAA;IAE7B;;;;OAIG;IACI,uBAAuB,GAA6B,EAAE,CAAA;CAC9D,CAAA;AAjBY,0BAA0B;IADtC,UAAU,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;GACzB,0BAA0B,CAiBtC"}
1
+ {"version":3,"file":"http-authentication-settings.js","sourceRoot":"","sources":["../src/http-authentication-settings.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAErD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAE5D;;GAEG;AAEI,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IAC9B,KAAK,GAAyB,IAA4B,CAAA;IAE1D,cAAc,GAAG,CAAC,QAAkB,EAAE,EAAE,CAC7C,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,EAAE,UAAsC,CAAC,CAAA;IAEtE,YAAY,GAA4B,cAAyC,CAAA;IAEjF,iBAAiB,GAAG,CAAC,QAAkB,EAAE,EAAE,CAChD,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,YAAY,EAAE,WAA2C,CAAC,CAAA;IAElF,UAAU,GAAG,KAAK,CAAA;IAClB,eAAe,GAAG,IAAI,CAAA;IAE7B;;;;OAIG;IACI,uBAAuB,GAA6B,EAAE,CAAA;CAC9D,CAAA;AApBY,0BAA0B;IADtC,UAAU,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;GACzB,0BAA0B,CAoBtC"}
@@ -7,7 +7,7 @@ import type { DefaultSession } from './models/default-session.js';
7
7
  */
8
8
  export declare class HttpUserContext {
9
9
  getUserDataSet: () => import("@furystack/repository").DataSet<User, "username", import("@furystack/core").WithOptionalId<User, "username">>;
10
- getSessionDataSet: () => import("@furystack/repository").DataSet<DefaultSession, keyof DefaultSession, import("@furystack/core").WithOptionalId<DefaultSession, keyof DefaultSession>>;
10
+ getSessionDataSet: () => import("@furystack/repository").DataSet<DefaultSession, "sessionId", import("@furystack/core").WithOptionalId<DefaultSession, "sessionId">>;
11
11
  private getUserByName;
12
12
  private user?;
13
13
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"http-user-context.d.ts","sourceRoot":"","sources":["../src/http-user-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAM3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;AAE3C,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAA;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAEjE;;GAEG;AACH,qBACa,eAAe;IACnB,cAAc,8HAAgE;IAE9E,iBAAiB,sKAAmE;IAE3F,OAAO,CAAC,aAAa,CAOpB;IAED,OAAO,CAAC,IAAI,CAAC,CAAM;IAEnB;;;OAGG;IACU,eAAe,CAAC,OAAO,EAAE,eAAe;IASrD;;;;;OAKG;IACU,YAAY,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAUzF;;;;;OAKG;IACU,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAanD,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC;IAQ9D,uBAAuB,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC,GAAG,MAAM,GAAG,IAAI;IAIxF;;;;;OAKG;IACU,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ1F;;;;;OAKG;IACU,WAAW,CACtB,IAAI,EAAE,IAAI,EACV,c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,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC,GAAG,MAAM,GAAG,IAAI;IAIxF;;;;;OAKG;IACU,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ1F;;;;;OAKG;IACU,WAAW,CACtB,IAAI,EAAE,IAAI,EACV,cAAc,EAAE;QAAE,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE,GACrE,OAAO,CAAC,IAAI,CAAC;IAQH,YAAY,CACvB,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC,EACzC,QAAQ,EAAE;QAAE,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE;IAalE,SACwB,cAAc,EAAE,0BAA0B,CAAC,IAAI,EAAE,cAAc,CAAC,CAAA;IAExF,iBACyB,cAAc,CAAU;IAEjD,iBACyB,aAAa,CAAuB;IAEtD,IAAI;CAiBZ"}
package/esm/index.d.ts CHANGED
@@ -9,6 +9,7 @@ export * from './get-schema-from-api.js';
9
9
  export * from './helpers.js';
10
10
  export * from './http-authentication-settings.js';
11
11
  export * from './http-user-context.js';
12
+ export * from './login-response-strategy.js';
12
13
  export * from './mime-types.js';
13
14
  export * from './models/index.js';
14
15
  export * from './proxy-manager.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,qCAAqC,CAAA;AACnD,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gCAAgC,CAAA;AAC9C,cAAc,0BAA0B,CAAA;AACxC,cAAc,cAAc,CAAA;AAC5B,cAAc,mCAAmC,CAAA;AACjD,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oCAAoC,CAAA;AAClD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qBAAqB,CAAA;AACnC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,eAAe,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,qCAAqC,CAAA;AACnD,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gCAAgC,CAAA;AAC9C,cAAc,0BAA0B,CAAA;AACxC,cAAc,cAAc,CAAA;AAC5B,cAAc,mCAAmC,CAAA;AACjD,cAAc,wBAAwB,CAAA;AACtC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oCAAoC,CAAA;AAClD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qBAAqB,CAAA;AACnC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,eAAe,CAAA"}
package/esm/index.js CHANGED
@@ -9,6 +9,7 @@ export * from './get-schema-from-api.js';
9
9
  export * from './helpers.js';
10
10
  export * from './http-authentication-settings.js';
11
11
  export * from './http-user-context.js';
12
+ export * from './login-response-strategy.js';
12
13
  export * from './mime-types.js';
13
14
  export * from './models/index.js';
14
15
  export * from './proxy-manager.js';
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,qCAAqC,CAAA;AACnD,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gCAAgC,CAAA;AAC9C,cAAc,0BAA0B,CAAA;AACxC,cAAc,cAAc,CAAA;AAC5B,cAAc,mCAAmC,CAAA;AACjD,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oCAAoC,CAAA;AAClD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qBAAqB,CAAA;AACnC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,eAAe,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,qCAAqC,CAAA;AACnD,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gCAAgC,CAAA;AAC9C,cAAc,0BAA0B,CAAA;AACxC,cAAc,cAAc,CAAA;AAC5B,cAAc,mCAAmC,CAAA;AACjD,cAAc,wBAAwB,CAAA;AACtC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oCAAoC,CAAA;AAClD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qBAAqB,CAAA;AACnC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,eAAe,CAAA"}
@@ -0,0 +1,28 @@
1
+ import type { User } from '@furystack/core';
2
+ import type { Injector } from '@furystack/inject';
3
+ import type { ActionResult } from './request-action-implementation.js';
4
+ /**
5
+ * A pluggable strategy that turns an authenticated {@link User} into an
6
+ * {@link ActionResult} containing the session/token data for the client.
7
+ *
8
+ * Pass a concrete strategy to action factories like
9
+ * {@link createPasswordLoginAction} or `createGoogleLoginAction` to
10
+ * decouple the authentication mechanism from the session/token mechanism.
11
+ *
12
+ * @typeParam TResult The shape of the response body (e.g. `User` for cookies,
13
+ * `{ accessToken: string; refreshToken: string }` for JWT)
14
+ */
15
+ export type LoginResponseStrategy<TResult> = {
16
+ createLoginResponse: (user: User, injector: Injector) => Promise<ActionResult<TResult>>;
17
+ };
18
+ /**
19
+ * Creates a cookie-based {@link LoginResponseStrategy}.
20
+ *
21
+ * On each login it generates a random session ID, persists it in the session
22
+ * DataSet, and returns the user with a `Set-Cookie` header.
23
+ *
24
+ * @param injector The root injector (must have {@link HttpAuthenticationSettings} configured)
25
+ * @returns A strategy that returns `ActionResult<User>`
26
+ */
27
+ export declare const createCookieLoginStrategy: (injector: Injector) => LoginResponseStrategy<User>;
28
+ //# sourceMappingURL=login-response-strategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login-response-strategy.d.ts","sourceRoot":"","sources":["../src/login-response-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAIjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAA;AAGtE;;;;;;;;;;GAUG;AACH,MAAM,MAAM,qBAAqB,CAAC,OAAO,IAAI;IAC3C,mBAAmB,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAA;CACxF,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,GAAI,UAAU,QAAQ,KAAG,qBAAqB,CAAC,IAAI,CAcxF,CAAA"}
@@ -0,0 +1,28 @@
1
+ import { useSystemIdentityContext } from '@furystack/core';
2
+ import { randomBytes } from 'crypto';
3
+ import { HttpAuthenticationSettings } from './http-authentication-settings.js';
4
+ import { JsonResult } from './request-action-implementation.js';
5
+ /**
6
+ * Creates a cookie-based {@link LoginResponseStrategy}.
7
+ *
8
+ * On each login it generates a random session ID, persists it in the session
9
+ * DataSet, and returns the user with a `Set-Cookie` header.
10
+ *
11
+ * @param injector The root injector (must have {@link HttpAuthenticationSettings} configured)
12
+ * @returns A strategy that returns `ActionResult<User>`
13
+ */
14
+ export const createCookieLoginStrategy = (injector) => {
15
+ const settings = injector.getInstance(HttpAuthenticationSettings);
16
+ const systemInjector = useSystemIdentityContext({ injector, username: 'CookieLoginStrategy' });
17
+ return {
18
+ createLoginResponse: async (user) => {
19
+ const sessionDataSet = settings.getSessionDataSet(systemInjector);
20
+ const sessionId = randomBytes(32).toString('hex');
21
+ await sessionDataSet.add(systemInjector, { sessionId, username: user.username });
22
+ return JsonResult(user, 200, {
23
+ 'Set-Cookie': `${settings.cookieName}=${sessionId}; Path=/; HttpOnly`,
24
+ });
25
+ },
26
+ };
27
+ };
28
+ //# sourceMappingURL=login-response-strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login-response-strategy.js","sourceRoot":"","sources":["../src/login-response-strategy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAEpC,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAA;AAE9E,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAA;AAiB/D;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,QAAkB,EAA+B,EAAE;IAC3F,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC,0BAA0B,CAAC,CAAA;IACjE,MAAM,cAAc,GAAG,wBAAwB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,qBAAqB,EAAE,CAAC,CAAA;IAE9F,OAAO;QACL,mBAAmB,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YAClC,MAAM,cAAc,GAAG,QAAQ,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAA;YACjE,MAAM,SAAS,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;YACjD,MAAM,cAAc,CAAC,GAAG,CAAC,cAAc,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;YAChF,OAAO,UAAU,CAAC,IAAI,EAAE,GAAG,EAAE;gBAC3B,YAAY,EAAE,GAAG,QAAQ,CAAC,UAAU,IAAI,SAAS,oBAAoB;aACtE,CAAC,CAAA;QACJ,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=login-response-strategy.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login-response-strategy.spec.d.ts","sourceRoot":"","sources":["../src/login-response-strategy.spec.ts"],"names":[],"mappings":""}