@shipfox/client-auth 4.0.0 → 6.0.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 (141) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +56 -0
  3. package/dist/components/auth-guard.d.ts.map +1 -1
  4. package/dist/components/auth-guard.js +4 -4
  5. package/dist/components/auth-guard.js.map +1 -1
  6. package/dist/components/email-code-verification.d.ts.map +1 -1
  7. package/dist/components/email-code-verification.js +1 -1
  8. package/dist/components/email-code-verification.js.map +1 -1
  9. package/dist/components/redirect-target.d.ts +7 -0
  10. package/dist/components/redirect-target.d.ts.map +1 -1
  11. package/dist/components/redirect-target.js +35 -4
  12. package/dist/components/redirect-target.js.map +1 -1
  13. package/dist/components/workspace-switcher.stories.d.ts +1 -1
  14. package/dist/continuation.d.ts +1 -1
  15. package/dist/continuation.d.ts.map +1 -1
  16. package/dist/continuation.js +1 -1
  17. package/dist/continuation.js.map +1 -1
  18. package/dist/core/auth.d.ts +57 -0
  19. package/dist/core/auth.d.ts.map +1 -0
  20. package/dist/core/auth.js +3 -0
  21. package/dist/core/auth.js.map +1 -0
  22. package/dist/hooks/api/auth-mapper.d.ts +6 -0
  23. package/dist/hooks/api/auth-mapper.d.ts.map +1 -0
  24. package/dist/hooks/api/auth-mapper.js +25 -0
  25. package/dist/hooks/api/auth-mapper.js.map +1 -0
  26. package/dist/hooks/api/login-auth.d.ts +3 -28
  27. package/dist/hooks/api/login-auth.d.ts.map +1 -1
  28. package/dist/hooks/api/login-auth.js +7 -4
  29. package/dist/hooks/api/login-auth.js.map +1 -1
  30. package/dist/hooks/api/logout-auth.js +2 -2
  31. package/dist/hooks/api/logout-auth.js.map +1 -1
  32. package/dist/hooks/api/password-reset-auth.d.ts +5 -32
  33. package/dist/hooks/api/password-reset-auth.d.ts.map +1 -1
  34. package/dist/hooks/api/password-reset-auth.js +13 -7
  35. package/dist/hooks/api/password-reset-auth.js.map +1 -1
  36. package/dist/hooks/api/refresh-auth.d.ts +1 -1
  37. package/dist/hooks/api/refresh-auth.d.ts.map +1 -1
  38. package/dist/hooks/api/refresh-auth.js +1 -1
  39. package/dist/hooks/api/refresh-auth.js.map +1 -1
  40. package/dist/hooks/api/signup-auth.d.ts +2 -30
  41. package/dist/hooks/api/signup-auth.d.ts.map +1 -1
  42. package/dist/hooks/api/signup-auth.js +14 -4
  43. package/dist/hooks/api/signup-auth.js.map +1 -1
  44. package/dist/hooks/api/verify-email-auth.d.ts +4 -21
  45. package/dist/hooks/api/verify-email-auth.d.ts.map +1 -1
  46. package/dist/hooks/api/verify-email-auth.js +20 -7
  47. package/dist/hooks/api/verify-email-auth.js.map +1 -1
  48. package/dist/hooks/api/workspace-auth.d.ts +5 -21
  49. package/dist/hooks/api/workspace-auth.d.ts.map +1 -1
  50. package/dist/hooks/api/workspace-auth.js +11 -6
  51. package/dist/hooks/api/workspace-auth.js.map +1 -1
  52. package/dist/hooks/api/workspace-mapper.d.ts +4 -0
  53. package/dist/hooks/api/workspace-mapper.d.ts.map +1 -0
  54. package/dist/hooks/api/workspace-mapper.js +9 -0
  55. package/dist/hooks/api/workspace-mapper.js.map +1 -0
  56. package/dist/index.d.ts +0 -1
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +0 -1
  59. package/dist/index.js.map +1 -1
  60. package/dist/pages/invitation-context.d.ts +9 -14
  61. package/dist/pages/invitation-context.d.ts.map +1 -1
  62. package/dist/pages/invitation-context.js +4 -27
  63. package/dist/pages/invitation-context.js.map +1 -1
  64. package/dist/pages/login-page.d.ts.map +1 -1
  65. package/dist/pages/login-page.js +5 -6
  66. package/dist/pages/login-page.js.map +1 -1
  67. package/dist/pages/logout-page.d.ts.map +1 -1
  68. package/dist/pages/logout-page.js +8 -18
  69. package/dist/pages/logout-page.js.map +1 -1
  70. package/dist/pages/password-reset-page.d.ts.map +1 -1
  71. package/dist/pages/password-reset-page.js +8 -10
  72. package/dist/pages/password-reset-page.js.map +1 -1
  73. package/dist/pages/signup-page.d.ts.map +1 -1
  74. package/dist/pages/signup-page.js +24 -18
  75. package/dist/pages/signup-page.js.map +1 -1
  76. package/dist/pages/workspace-onboarding-page.js +2 -2
  77. package/dist/pages/workspace-onboarding-page.js.map +1 -1
  78. package/dist/routes/inputs.d.ts +9 -0
  79. package/dist/routes/inputs.d.ts.map +1 -0
  80. package/dist/routes/inputs.js +17 -0
  81. package/dist/routes/inputs.js.map +1 -0
  82. package/dist/routes/login.d.ts +2 -0
  83. package/dist/routes/login.d.ts.map +1 -1
  84. package/dist/routes/login.js +2 -0
  85. package/dist/routes/login.js.map +1 -1
  86. package/dist/routes/logout.d.ts +2 -0
  87. package/dist/routes/logout.d.ts.map +1 -1
  88. package/dist/routes/logout.js +2 -0
  89. package/dist/routes/logout.js.map +1 -1
  90. package/dist/routes/reset.d.ts +2 -0
  91. package/dist/routes/reset.d.ts.map +1 -1
  92. package/dist/routes/reset.js +2 -0
  93. package/dist/routes/reset.js.map +1 -1
  94. package/dist/routes/signup.d.ts +2 -0
  95. package/dist/routes/signup.d.ts.map +1 -1
  96. package/dist/routes/signup.js +2 -0
  97. package/dist/routes/signup.js.map +1 -1
  98. package/dist/tsconfig.test.tsbuildinfo +1 -1
  99. package/package.json +11 -11
  100. package/src/components/auth-guard.tsx +4 -2
  101. package/src/components/email-code-verification.tsx +1 -1
  102. package/src/components/redirect-target.test.ts +32 -1
  103. package/src/components/redirect-target.ts +41 -4
  104. package/src/continuation.ts +1 -1
  105. package/src/core/auth.ts +55 -0
  106. package/src/hooks/api/auth-mapper.test.ts +77 -0
  107. package/src/hooks/api/auth-mapper.ts +29 -0
  108. package/src/hooks/api/login-auth.test.ts +1 -1
  109. package/src/hooks/api/login-auth.ts +10 -4
  110. package/src/hooks/api/logout-auth.ts +2 -2
  111. package/src/hooks/api/password-reset-auth.test.ts +3 -3
  112. package/src/hooks/api/password-reset-auth.ts +19 -13
  113. package/src/hooks/api/refresh-auth.ts +1 -0
  114. package/src/hooks/api/signup-auth.ts +15 -4
  115. package/src/hooks/api/verify-email-auth.ts +32 -16
  116. package/src/hooks/api/workspace-auth.ts +16 -6
  117. package/src/hooks/api/workspace-mapper.test.ts +21 -0
  118. package/src/hooks/api/workspace-mapper.ts +6 -0
  119. package/src/index.ts +0 -1
  120. package/src/pages/invitation-context.ts +8 -31
  121. package/src/pages/login-page.test.tsx +1 -1
  122. package/src/pages/login-page.tsx +5 -4
  123. package/src/pages/logout-page.test.tsx +75 -0
  124. package/src/pages/logout-page.tsx +9 -13
  125. package/src/pages/password-reset-page.tsx +5 -8
  126. package/src/pages/signup-page.test.tsx +1 -1
  127. package/src/pages/signup-page.tsx +22 -16
  128. package/src/pages/workspace-onboarding-page.tsx +2 -2
  129. package/src/routes/inputs.test.ts +17 -0
  130. package/src/routes/inputs.ts +21 -0
  131. package/src/routes/login.tsx +2 -0
  132. package/src/routes/logout.tsx +2 -1
  133. package/src/routes/reset.tsx +2 -0
  134. package/src/routes/signup.tsx +2 -0
  135. package/tsconfig.build.tsbuildinfo +1 -1
  136. package/vercel.json +5 -0
  137. package/dist/components/auth-shell.d.ts +0 -13
  138. package/dist/components/auth-shell.d.ts.map +0 -1
  139. package/dist/components/auth-shell.js +0 -68
  140. package/dist/components/auth-shell.js.map +0 -1
  141. package/src/components/auth-shell.tsx +0 -68
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shipfox/client-auth",
3
3
  "license": "MIT",
4
- "version": "4.0.0",
4
+ "version": "6.0.1",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/ShipfoxHQ/shipfox.git",
@@ -10,10 +10,6 @@
10
10
  "type": "module",
11
11
  "main": "dist/index.js",
12
12
  "types": "dist/index.d.ts",
13
- "imports": {
14
- "#*": "./dist/*",
15
- "#test/*": "./test/*"
16
- },
17
13
  "exports": {
18
14
  ".": {
19
15
  "types": "./dist/index.d.ts",
@@ -35,12 +31,13 @@
35
31
  "dependencies": {
36
32
  "@swc/helpers": "^0.5.17",
37
33
  "@tanstack/react-form": "^1.32.0",
38
- "@shipfox/api-auth-dto": "7.1.0",
39
- "@shipfox/api-workspaces-dto": "6.0.0",
40
- "@shipfox/client-api": "4.0.0",
41
- "@shipfox/client-shell": "4.0.0",
42
- "@shipfox/client-ui": "4.0.0",
43
- "@shipfox/react-ui": "0.3.5"
34
+ "@shipfox/api-auth-dto": "9.0.1",
35
+ "@shipfox/api-workspaces-dto": "9.0.1",
36
+ "@shipfox/client-api": "6.0.1",
37
+ "@shipfox/client-invitations": "6.0.1",
38
+ "@shipfox/client-shell": "6.0.1",
39
+ "@shipfox/client-ui": "6.0.1",
40
+ "@shipfox/react-ui": "0.3.6"
44
41
  },
45
42
  "peerDependencies": {
46
43
  "@tanstack/react-query": "^5.101.0",
@@ -49,6 +46,9 @@
49
46
  "react": "^19.0.0",
50
47
  "react-dom": "^19.0.0"
51
48
  },
49
+ "imports": {
50
+ "#*": "./dist/*"
51
+ },
52
52
  "scripts": {
53
53
  "build": "shipfox-swc",
54
54
  "check": "shipfox-biome-check",
@@ -1,8 +1,10 @@
1
+ import {useRouteSearch} from '@shipfox/client-shell/runtime';
1
2
  import {FullPageLoader} from '@shipfox/react-ui/loader';
2
- import {Navigate, useRouter, useSearch} from '@tanstack/react-router';
3
+ import {Navigate, useRouter} from '@tanstack/react-router';
3
4
  import {type PropsWithChildren, useEffect} from 'react';
4
5
  import {useAuthState} from '#hooks/use-auth-state.js';
5
6
  import {WorkspaceOnboardingPage} from '#pages/workspace-onboarding-page.js';
7
+ import {validateRedirectSearch} from '../routes/inputs.js';
6
8
  import {sanitizeRedirectPath} from './redirect-target.js';
7
9
 
8
10
  export function AuthGuard({children}: PropsWithChildren) {
@@ -21,7 +23,7 @@ export function AuthGuard({children}: PropsWithChildren) {
21
23
 
22
24
  export function GuestGuard({children}: PropsWithChildren) {
23
25
  const auth = useAuthState();
24
- const search = useSearch({strict: false}) as {redirect?: unknown};
26
+ const search = useRouteSearch(validateRedirectSearch);
25
27
  const router = useRouter();
26
28
  const target = sanitizeRedirectPath(search.redirect);
27
29
 
@@ -1,10 +1,10 @@
1
+ import {AuthShell} from '@shipfox/client-shell/runtime';
1
2
  import {Button} from '@shipfox/react-ui/button';
2
3
  import {Callout} from '@shipfox/react-ui/callout';
3
4
  import {FormField, FormFieldInput} from '@shipfox/react-ui/form-field';
4
5
  import type {HeaderProps} from '@shipfox/react-ui/typography';
5
6
  import type {FormEvent, ReactNode, Ref} from 'react';
6
7
  import {useCallback, useEffect, useRef, useState} from 'react';
7
- import {AuthShell} from './auth-shell.js';
8
8
 
9
9
  const EIGHT_DIGIT_CODE_RE = /^\d{8}$/u;
10
10
 
@@ -1,4 +1,4 @@
1
- import {sanitizeRedirectPath} from './redirect-target.js';
1
+ import {sanitizeLogoutRedirectPath, sanitizeRedirectPath} from './redirect-target.js';
2
2
 
3
3
  describe('sanitizeRedirectPath', () => {
4
4
  describe.each([
@@ -66,3 +66,34 @@ describe('sanitizeRedirectPath', () => {
66
66
  });
67
67
  });
68
68
  });
69
+
70
+ describe('sanitizeLogoutRedirectPath', () => {
71
+ describe.each([
72
+ ['explicit login fallback', '/auth/login', '/auth/login'],
73
+ ['same-origin workspace path', '/workspaces/abc', '/workspaces/abc'],
74
+ [
75
+ 'same-origin path with search and hash',
76
+ '/workspaces/abc?tab=runs#header',
77
+ '/workspaces/abc?tab=runs#header',
78
+ ],
79
+ ])('accepts %s', (_label, input, expected) => {
80
+ test('returns the safe destination', () => {
81
+ expect(sanitizeLogoutRedirectPath(input)).toBe(expected);
82
+ });
83
+ });
84
+
85
+ describe.each([
86
+ ['missing redirect', undefined],
87
+ ['external URL', 'https://attacker.example'],
88
+ ['protocol-relative URL', '//attacker.example'],
89
+ ['auth route other than login', '/auth/reset'],
90
+ ['login route with a query', '/auth/login?redirect=/workspaces/abc'],
91
+ ['raw invitation token', '/invitations/accept?token=sf_i_raw-token'],
92
+ ['raw invitation token with trailing slash', '/invitations/accept/?token=sf_i_raw-token'],
93
+ ['malformed percent encoding', '/%E0%80%80'],
94
+ ])('falls back for %s', (_label, input) => {
95
+ test('returns login without forwarding unsafe state', () => {
96
+ expect(sanitizeLogoutRedirectPath(input)).toBe('/auth/login');
97
+ });
98
+ });
99
+ });
@@ -1,8 +1,10 @@
1
1
  const REDIRECT_ORIGIN = 'https://shipfox-redirect.invalid';
2
+ const LOGIN_PATH = '/auth/login';
3
+ const INVITATION_ACCEPT_PATH = '/invitations/accept';
4
+ const DEFAULT_LOGOUT_REDIRECT = LOGIN_PATH;
5
+ const TRAILING_SLASHES = /\/+$/;
2
6
 
3
- // Resolves and canonicalizes an internal path before returning it, so browser URL
4
- // parsing cannot turn a seemingly safe path into an external or auth route.
5
- export function sanitizeRedirectPath(value: unknown): string | undefined {
7
+ function resolveRedirectPath(value: unknown): URL | undefined {
6
8
  if (typeof value !== 'string' || !value.startsWith('/')) return undefined;
7
9
  let decoded: string;
8
10
  try {
@@ -17,6 +19,41 @@ export function sanitizeRedirectPath(value: unknown): string | undefined {
17
19
  return undefined;
18
20
  }
19
21
  if (target.origin !== REDIRECT_ORIGIN) return undefined;
20
- if (target.pathname === '/auth' || target.pathname.startsWith('/auth/')) return undefined;
22
+ return target;
23
+ }
24
+
25
+ function formatRedirectPath(target: URL): string {
21
26
  return `${target.pathname}${target.search}${target.hash}`;
22
27
  }
28
+
29
+ function isAuthPath(pathname: string): boolean {
30
+ return pathname === '/auth' || pathname.startsWith('/auth/');
31
+ }
32
+
33
+ // Resolves and canonicalizes an internal path before returning it, so browser URL
34
+ // parsing cannot turn a seemingly safe path into an external or auth route.
35
+ export function sanitizeRedirectPath(value: unknown): string | undefined {
36
+ const target = resolveRedirectPath(value);
37
+ if (!target || isAuthPath(target.pathname)) return undefined;
38
+ return formatRedirectPath(target);
39
+ }
40
+
41
+ function containsInvitationToken(target: URL): boolean {
42
+ const normalizedPathname = target.pathname.replace(TRAILING_SLASHES, '') || '/';
43
+ return normalizedPathname === INVITATION_ACCEPT_PATH && target.searchParams.has('token');
44
+ }
45
+
46
+ /**
47
+ * Returns the destination used by the shared logout route.
48
+ *
49
+ * Login is the only auth destination allowed, and invitation tokens never
50
+ * survive this boundary. Invalid values fail closed to login.
51
+ */
52
+ export function sanitizeLogoutRedirectPath(value: unknown): string {
53
+ const target = resolveRedirectPath(value);
54
+ if (!target) return DEFAULT_LOGOUT_REDIRECT;
55
+ if (isAuthPath(target.pathname) || containsInvitationToken(target)) {
56
+ return DEFAULT_LOGOUT_REDIRECT;
57
+ }
58
+ return formatRedirectPath(target);
59
+ }
@@ -1,4 +1,4 @@
1
- export {AuthActions, AuthShell, type AuthShellProps} from './components/auth-shell.js';
1
+ export {AuthActions, AuthShell, type AuthShellProps} from '@shipfox/client-shell/runtime';
2
2
  export {
3
3
  EmailCodeVerification,
4
4
  type EmailCodeVerificationProps,
@@ -0,0 +1,55 @@
1
+ export interface LoginCommand {
2
+ email: string;
3
+ password: string;
4
+ }
5
+
6
+ export interface SignupCommand extends LoginCommand {
7
+ name: string;
8
+ invitationToken?: string;
9
+ }
10
+
11
+ export interface PasswordResetRequestCommand {
12
+ email: string;
13
+ }
14
+
15
+ export interface PasswordResetConfirmCommand {
16
+ token: string;
17
+ newPassword: string;
18
+ }
19
+
20
+ export interface VerifyEmailCommand {
21
+ email: string;
22
+ challengeId: string;
23
+ code: string;
24
+ }
25
+
26
+ export interface ResendEmailVerificationCommand {
27
+ email: string;
28
+ challengeId: string;
29
+ }
30
+
31
+ export interface WorkspaceCreateCommand {
32
+ name: string;
33
+ }
34
+
35
+ export interface Workspace {
36
+ id: string;
37
+ name: string;
38
+ status: 'active' | 'suspended' | 'deleted';
39
+ }
40
+
41
+ export interface SignupResult {
42
+ user: {
43
+ id: string;
44
+ email: string;
45
+ name?: string;
46
+ emailVerifiedAt?: string;
47
+ };
48
+ emailChallenge?: {id: string; nextResendAvailableAt: string};
49
+ membership?: {id: string; userId: string; workspaceId: string};
50
+ acceptError?: {code: string; message: string};
51
+ }
52
+
53
+ export interface EmailVerificationResendResult {
54
+ nextResendAvailableAt: string;
55
+ }
@@ -0,0 +1,77 @@
1
+ import type {SignupResponseDto} from '@shipfox/api-auth-dto';
2
+ import {toSignupResult} from './auth-mapper.js';
3
+
4
+ const baseUser: SignupResponseDto['user'] = {
5
+ id: '11111111-1111-4111-8111-111111111111',
6
+ email: 'signup@example.com',
7
+ name: null,
8
+ email_verified_at: null,
9
+ status: 'active',
10
+ created_at: '2026-04-27T00:00:00.000Z',
11
+ updated_at: '2026-04-27T00:00:00.000Z',
12
+ };
13
+
14
+ describe('toSignupResult', () => {
15
+ test('maps only the user when no challenge, membership, or accept error is present', () => {
16
+ const result = toSignupResult({user: baseUser});
17
+
18
+ expect(result).toEqual({user: {id: baseUser.id, email: baseUser.email}});
19
+ });
20
+
21
+ test('maps the user name and email verification when present', () => {
22
+ const result = toSignupResult({
23
+ user: {...baseUser, name: 'Ada', email_verified_at: '2026-04-27T00:00:00.000Z'},
24
+ });
25
+
26
+ expect(result.user).toEqual({
27
+ id: baseUser.id,
28
+ email: baseUser.email,
29
+ name: 'Ada',
30
+ emailVerifiedAt: '2026-04-27T00:00:00.000Z',
31
+ });
32
+ });
33
+
34
+ test('maps the email challenge into camelCase fields', () => {
35
+ const result = toSignupResult({
36
+ user: baseUser,
37
+ email_challenge: {
38
+ id: '22222222-2222-4222-8222-222222222222',
39
+ next_resend_available_at: '2026-04-27T00:01:00.000Z',
40
+ },
41
+ });
42
+
43
+ expect(result.emailChallenge).toEqual({
44
+ id: '22222222-2222-4222-8222-222222222222',
45
+ nextResendAvailableAt: '2026-04-27T00:01:00.000Z',
46
+ });
47
+ });
48
+
49
+ test('maps the invitation membership into camelCase fields', () => {
50
+ const result = toSignupResult({
51
+ user: baseUser,
52
+ membership: {
53
+ id: '33333333-3333-4333-8333-333333333333',
54
+ user_id: baseUser.id,
55
+ workspace_id: '44444444-4444-4444-8444-444444444444',
56
+ },
57
+ });
58
+
59
+ expect(result.membership).toEqual({
60
+ id: '33333333-3333-4333-8333-333333333333',
61
+ userId: baseUser.id,
62
+ workspaceId: '44444444-4444-4444-8444-444444444444',
63
+ });
64
+ });
65
+
66
+ test('maps the invitation accept error as-is', () => {
67
+ const result = toSignupResult({
68
+ user: baseUser,
69
+ accept_error: {code: 'invitation-expired', message: 'This invitation has expired.'},
70
+ });
71
+
72
+ expect(result.acceptError).toEqual({
73
+ code: 'invitation-expired',
74
+ message: 'This invitation has expired.',
75
+ });
76
+ });
77
+ });
@@ -0,0 +1,29 @@
1
+ import type {SignupResponseDto} from '@shipfox/api-auth-dto';
2
+ import {toAuthenticatedSession, toUserIdentity} from '@shipfox/client-shell/runtime';
3
+ import type {SignupResult} from '#core/auth.js';
4
+
5
+ export {toAuthenticatedSession};
6
+
7
+ export function toSignupResult(dto: SignupResponseDto): SignupResult {
8
+ return {
9
+ user: toUserIdentity(dto.user),
10
+ ...(dto.email_challenge
11
+ ? {
12
+ emailChallenge: {
13
+ id: dto.email_challenge.id,
14
+ nextResendAvailableAt: dto.email_challenge.next_resend_available_at,
15
+ },
16
+ }
17
+ : {}),
18
+ ...(dto.membership
19
+ ? {
20
+ membership: {
21
+ id: dto.membership.id,
22
+ userId: dto.membership.user_id,
23
+ workspaceId: dto.membership.workspace_id,
24
+ },
25
+ }
26
+ : {}),
27
+ ...(dto.accept_error ? {acceptError: dto.accept_error} : {}),
28
+ };
29
+ }
@@ -37,7 +37,7 @@ describe('loginAuth', () => {
37
37
  const result = await loginAuth(body);
38
38
 
39
39
  const request = fetchImpl.mock.calls[0]?.[0] as Request;
40
- expect(result.token).toBe('access-token');
40
+ expect(result.accessToken).toBe('access-token');
41
41
  expect(request.url).toBe('https://api.example.test/auth/login');
42
42
  expect(request.method).toBe('POST');
43
43
  expect(requestBody).toEqual(body);
@@ -1,10 +1,16 @@
1
- import type {LoginBodyDto, LoginResponseDto} from '@shipfox/api-auth-dto';
2
- import {apiRequest} from '@shipfox/client-api';
1
+ import {loginResponseSchema} from '@shipfox/api-auth-dto';
2
+ import {checkedApiRequest} from '@shipfox/client-api';
3
3
  import {useMutation} from '@tanstack/react-query';
4
+ import type {LoginCommand} from '#core/auth.js';
4
5
  import {useAuthTransition} from '#state/auth.js';
6
+ import {toAuthenticatedSession} from './auth-mapper.js';
5
7
 
6
- export async function loginAuth(body: LoginBodyDto) {
7
- return await apiRequest<LoginResponseDto>('/auth/login', {method: 'POST', body});
8
+ export async function loginAuth(command: LoginCommand) {
9
+ const response = await checkedApiRequest(loginResponseSchema, '/auth/login', {
10
+ method: 'POST',
11
+ body: command,
12
+ });
13
+ return toAuthenticatedSession(response);
8
14
  }
9
15
 
10
16
  export function useLoginAuth() {
@@ -1,10 +1,10 @@
1
- import {apiRequest} from '@shipfox/client-api';
1
+ import {checkedApiRequest, emptyResponseSchema} from '@shipfox/client-api';
2
2
  import {useMutation} from '@tanstack/react-query';
3
3
  import {useAuthTransition} from '#state/auth.js';
4
4
 
5
5
  async function logoutAuth() {
6
6
  try {
7
- await apiRequest<void>('/auth/logout', {method: 'POST', body: {}});
7
+ await checkedApiRequest(emptyResponseSchema, '/auth/logout', {method: 'POST', body: {}});
8
8
  } catch {
9
9
  // Logout is best-effort: local session state must clear even if the API is offline.
10
10
  }
@@ -55,14 +55,14 @@ describe('confirmPasswordReset', () => {
55
55
  });
56
56
  });
57
57
  configureApiClient({fetchImpl});
58
- const body = {token: 'reset-token', new_password: 'new password is long'};
58
+ const body = {token: 'reset-token', newPassword: 'new password is long'};
59
59
 
60
60
  const result = await confirmPasswordReset(body);
61
61
 
62
62
  const request = fetchImpl.mock.calls[0]?.[0] as Request;
63
- expect(result.token).toBe('reset-access-token');
63
+ expect(result.accessToken).toBe('reset-access-token');
64
64
  expect(request.url).toBe('https://api.example.test/auth/password-reset/confirm');
65
65
  expect(request.method).toBe('POST');
66
- expect(requestBody).toEqual(body);
66
+ expect(requestBody).toEqual({token: body.token, new_password: body.newPassword});
67
67
  });
68
68
  });
@@ -1,23 +1,29 @@
1
- import type {
2
- PasswordResetConfirmBodyDto,
3
- PasswordResetConfirmResponseDto,
4
- PasswordResetRequestBodyDto,
5
- } from '@shipfox/api-auth-dto';
6
- import {apiRequest} from '@shipfox/client-api';
1
+ import {passwordResetConfirmResponseSchema} from '@shipfox/api-auth-dto';
2
+ import {checkedApiRequest, emptyResponseSchema} from '@shipfox/client-api';
7
3
  import {useMutation} from '@tanstack/react-query';
4
+ import type {PasswordResetConfirmCommand, PasswordResetRequestCommand} from '#core/auth.js';
8
5
  import {useAuthTransition} from '#state/auth.js';
6
+ import {toAuthenticatedSession} from './auth-mapper.js';
9
7
 
10
- export async function requestPasswordReset(body: PasswordResetRequestBodyDto) {
11
- await apiRequest<void>('/auth/password-reset', {method: 'POST', body});
12
- }
13
-
14
- export async function confirmPasswordReset(body: PasswordResetConfirmBodyDto) {
15
- return await apiRequest<PasswordResetConfirmResponseDto>('/auth/password-reset/confirm', {
8
+ export async function requestPasswordReset(command: PasswordResetRequestCommand) {
9
+ await checkedApiRequest(emptyResponseSchema, '/auth/password-reset', {
16
10
  method: 'POST',
17
- body,
11
+ body: command,
18
12
  });
19
13
  }
20
14
 
15
+ export async function confirmPasswordReset(command: PasswordResetConfirmCommand) {
16
+ const response = await checkedApiRequest(
17
+ passwordResetConfirmResponseSchema,
18
+ '/auth/password-reset/confirm',
19
+ {
20
+ method: 'POST',
21
+ body: {token: command.token, new_password: command.newPassword},
22
+ },
23
+ );
24
+ return toAuthenticatedSession(response);
25
+ }
26
+
21
27
  export function useRequestPasswordResetAuth() {
22
28
  return useMutation({mutationFn: requestPasswordReset});
23
29
  }
@@ -1,5 +1,6 @@
1
1
  export {
2
2
  authRefreshQueryKey,
3
+ authRefreshQueryOptions,
3
4
  getAuthRefreshDelayMs,
4
5
  useRefreshAuth,
5
6
  } from '@shipfox/client-shell/runtime';
@@ -1,9 +1,20 @@
1
- import type {SignupBodyDto, SignupResponseDto} from '@shipfox/api-auth-dto';
2
- import {apiRequest} from '@shipfox/client-api';
1
+ import {signupResponseSchema} from '@shipfox/api-auth-dto';
2
+ import {checkedApiRequest} from '@shipfox/client-api';
3
3
  import {useMutation} from '@tanstack/react-query';
4
+ import type {SignupCommand} from '#core/auth.js';
5
+ import {toSignupResult} from './auth-mapper.js';
4
6
 
5
- async function signupAuth(body: SignupBodyDto) {
6
- return await apiRequest<SignupResponseDto>('/auth/signup', {method: 'POST', body});
7
+ async function signupAuth(command: SignupCommand) {
8
+ const response = await checkedApiRequest(signupResponseSchema, '/auth/signup', {
9
+ method: 'POST',
10
+ body: {
11
+ email: command.email,
12
+ password: command.password,
13
+ name: command.name,
14
+ ...(command.invitationToken ? {invitation_token: command.invitationToken} : {}),
15
+ },
16
+ });
17
+ return toSignupResult(response);
7
18
  }
8
19
 
9
20
  export function useSignupAuth() {
@@ -1,25 +1,41 @@
1
- import type {
2
- VerifyEmailConfirmBodyDto,
3
- VerifyEmailConfirmResponseDto,
4
- VerifyEmailResendBodyDto,
5
- VerifyEmailResendResponseDto,
1
+ import {
2
+ verifyEmailConfirmResponseSchema,
3
+ verifyEmailResendResponseSchema,
6
4
  } from '@shipfox/api-auth-dto';
7
- import {apiRequest} from '@shipfox/client-api';
5
+ import {checkedApiRequest} from '@shipfox/client-api';
8
6
  import {useMutation} from '@tanstack/react-query';
7
+ import type {
8
+ EmailVerificationResendResult,
9
+ ResendEmailVerificationCommand,
10
+ VerifyEmailCommand,
11
+ } from '#core/auth.js';
9
12
  import {useAuthTransition} from '#state/auth.js';
13
+ import {toAuthenticatedSession} from './auth-mapper.js';
10
14
 
11
- async function verifyEmailAuth(body: VerifyEmailConfirmBodyDto) {
12
- return await apiRequest<VerifyEmailConfirmResponseDto>('/auth/verify-email/confirm', {
13
- method: 'POST',
14
- body,
15
- });
15
+ async function verifyEmailAuth(command: VerifyEmailCommand) {
16
+ const response = await checkedApiRequest(
17
+ verifyEmailConfirmResponseSchema,
18
+ '/auth/verify-email/confirm',
19
+ {
20
+ method: 'POST',
21
+ body: {email: command.email, challenge_id: command.challengeId, code: command.code},
22
+ },
23
+ );
24
+ return toAuthenticatedSession(response);
16
25
  }
17
26
 
18
- async function resendEmailVerificationAuth(body: VerifyEmailResendBodyDto) {
19
- return await apiRequest<VerifyEmailResendResponseDto>('/auth/verify-email/resend', {
20
- method: 'POST',
21
- body,
22
- });
27
+ async function resendEmailVerificationAuth(command: ResendEmailVerificationCommand) {
28
+ const response = await checkedApiRequest(
29
+ verifyEmailResendResponseSchema,
30
+ '/auth/verify-email/resend',
31
+ {
32
+ method: 'POST',
33
+ body: {email: command.email, challenge_id: command.challengeId},
34
+ },
35
+ );
36
+ return {
37
+ nextResendAvailableAt: response.next_resend_available_at,
38
+ } satisfies EmailVerificationResendResult;
23
39
  }
24
40
 
25
41
  export function useResendEmailVerificationAuth() {
@@ -1,14 +1,24 @@
1
- import type {CreateWorkspaceBodyDto, WorkspaceResponseDto} from '@shipfox/api-workspaces-dto';
2
- import {apiRequest} from '@shipfox/client-api';
3
- import {listUserWorkspaces, userWorkspacesQueryKey} from '@shipfox/client-shell/runtime';
1
+ import {workspaceResponseSchema} from '@shipfox/api-workspaces-dto';
2
+ import {checkedApiRequest} from '@shipfox/client-api';
3
+ import {
4
+ listUserWorkspaces,
5
+ userWorkspacesQueryKey,
6
+ userWorkspacesQueryOptions,
7
+ } from '@shipfox/client-shell/runtime';
4
8
  import {useMutation} from '@tanstack/react-query';
9
+ import type {WorkspaceCreateCommand} from '#core/auth.js';
5
10
  import {useRefreshAuth} from './refresh-auth.js';
11
+ import {toWorkspace} from './workspace-mapper.js';
6
12
 
7
- export async function createWorkspace(body: CreateWorkspaceBodyDto) {
8
- return await apiRequest<WorkspaceResponseDto>('/workspaces', {method: 'POST', body});
13
+ export async function createWorkspace(command: WorkspaceCreateCommand) {
14
+ const response = await checkedApiRequest(workspaceResponseSchema, '/workspaces', {
15
+ method: 'POST',
16
+ body: {name: command.name},
17
+ });
18
+ return toWorkspace(response);
9
19
  }
10
20
 
11
- export {listUserWorkspaces, userWorkspacesQueryKey};
21
+ export {listUserWorkspaces, userWorkspacesQueryKey, userWorkspacesQueryOptions};
12
22
 
13
23
  export function useCreateWorkspaceAuth() {
14
24
  const refreshAuth = useRefreshAuth();
@@ -0,0 +1,21 @@
1
+ import type {WorkspaceResponseDto} from '@shipfox/api-workspaces-dto';
2
+ import {toWorkspace} from './workspace-mapper.js';
3
+
4
+ describe('toWorkspace', () => {
5
+ test.each([
6
+ 'active',
7
+ 'suspended',
8
+ 'deleted',
9
+ ] as const)('maps a %s workspace to its domain shape', (status) => {
10
+ const dto: WorkspaceResponseDto = {
11
+ id: '11111111-1111-4111-8111-111111111111',
12
+ name: 'Acme',
13
+ status,
14
+ settings: {},
15
+ created_at: '2026-04-27T00:00:00.000Z',
16
+ updated_at: '2026-04-27T00:00:00.000Z',
17
+ };
18
+
19
+ expect(toWorkspace(dto)).toEqual({id: dto.id, name: dto.name, status});
20
+ });
21
+ });
@@ -0,0 +1,6 @@
1
+ import type {WorkspaceResponseDto} from '@shipfox/api-workspaces-dto';
2
+ import type {Workspace} from '#core/auth.js';
3
+
4
+ export function toWorkspace(dto: WorkspaceResponseDto): Workspace {
5
+ return {id: dto.id, name: dto.name, status: dto.status};
6
+ }
package/src/index.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from './components/auth-guard.js';
2
2
  export * from './components/auth-provider.js';
3
- export * from './components/auth-shell.js';
4
3
  export {WorkspaceCrumb, type WorkspaceCrumbProps} from './components/workspace-crumb.js';
5
4
  export {WorkspaceSwitcher, type WorkspaceSwitcherProps} from './components/workspace-switcher.js';
6
5
  export * from './hooks/index.js';