@shipfox/client-invitations 5.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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +35 -0
- package/dist/core/invitation-acceptance.d.ts +9 -0
- package/dist/core/invitation-acceptance.d.ts.map +1 -0
- package/dist/core/invitation-acceptance.js +3 -0
- package/dist/core/invitation-acceptance.js.map +1 -0
- package/dist/hooks/api/accept-invitation.d.ts +1 -8
- package/dist/hooks/api/accept-invitation.d.ts.map +1 -1
- package/dist/hooks/api/accept-invitation.js +7 -4
- package/dist/hooks/api/accept-invitation.js.map +1 -1
- package/dist/hooks/api/invitation-acceptance-mapper.d.ts +4 -0
- package/dist/hooks/api/invitation-acceptance-mapper.d.ts.map +1 -0
- package/dist/hooks/api/invitation-acceptance-mapper.js +12 -0
- package/dist/hooks/api/invitation-acceptance-mapper.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/pages/invitation-accept-page.d.ts.map +1 -1
- package/dist/pages/invitation-accept-page.js +5 -7
- package/dist/pages/invitation-accept-page.js.map +1 -1
- package/dist/routes/accept.d.ts +2 -0
- package/dist/routes/accept.d.ts.map +1 -1
- package/dist/routes/accept.js +2 -0
- package/dist/routes/accept.js.map +1 -1
- package/dist/routes/inputs.d.ts +5 -0
- package/dist/routes/inputs.d.ts.map +1 -0
- package/dist/routes/inputs.js +8 -0
- package/dist/routes/inputs.js.map +1 -0
- package/dist/tsconfig.test.tsbuildinfo +1 -1
- package/package.json +10 -11
- package/src/core/invitation-acceptance.ts +8 -0
- package/src/hooks/api/accept-invitation.ts +7 -8
- package/src/hooks/api/invitation-acceptance-mapper.test.ts +23 -0
- package/src/hooks/api/invitation-acceptance-mapper.ts +13 -0
- package/src/index.ts +1 -0
- package/src/pages/invitation-accept-page.tsx +10 -6
- package/src/routes/accept.tsx +5 -1
- package/src/routes/inputs.test.ts +11 -0
- package/src/routes/inputs.ts +10 -0
- package/tsconfig.build.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shipfox/client-invitations",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "
|
|
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",
|
|
@@ -31,12 +27,12 @@
|
|
|
31
27
|
"dependencies": {
|
|
32
28
|
"@swc/helpers": "^0.5.17",
|
|
33
29
|
"@tanstack/react-query": "^5.101.0",
|
|
34
|
-
"@shipfox/api-auth-dto": "
|
|
35
|
-
"@shipfox/api-workspaces-dto": "
|
|
36
|
-
"@shipfox/client-api": "
|
|
37
|
-
"@shipfox/client-
|
|
38
|
-
"@shipfox/
|
|
39
|
-
"@shipfox/
|
|
30
|
+
"@shipfox/api-auth-dto": "9.0.1",
|
|
31
|
+
"@shipfox/api-workspaces-dto": "9.0.1",
|
|
32
|
+
"@shipfox/client-api": "6.0.1",
|
|
33
|
+
"@shipfox/client-ui": "6.0.1",
|
|
34
|
+
"@shipfox/react-ui": "0.3.6",
|
|
35
|
+
"@shipfox/client-shell": "6.0.1"
|
|
40
36
|
},
|
|
41
37
|
"peerDependencies": {
|
|
42
38
|
"@tanstack/react-query": "^5.101.0",
|
|
@@ -44,6 +40,9 @@
|
|
|
44
40
|
"react": "^19.0.0",
|
|
45
41
|
"react-dom": "^19.0.0"
|
|
46
42
|
},
|
|
43
|
+
"imports": {
|
|
44
|
+
"#*": "./dist/*"
|
|
45
|
+
},
|
|
47
46
|
"scripts": {
|
|
48
47
|
"build": "shipfox-swc",
|
|
49
48
|
"check": "shipfox-biome-check",
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
AcceptInvitationResponseDto,
|
|
4
|
-
} from '@shipfox/api-workspaces-dto';
|
|
5
|
-
import {apiRequest} from '@shipfox/client-api';
|
|
1
|
+
import {acceptInvitationResponseSchema} from '@shipfox/api-workspaces-dto';
|
|
2
|
+
import {checkedApiRequest} from '@shipfox/client-api';
|
|
6
3
|
import {useMutation} from '@tanstack/react-query';
|
|
4
|
+
import {toInvitationAcceptance} from './invitation-acceptance-mapper.js';
|
|
7
5
|
|
|
8
|
-
async function acceptInvitation(
|
|
9
|
-
|
|
6
|
+
async function acceptInvitation(command: {token: string}) {
|
|
7
|
+
const response = await checkedApiRequest(acceptInvitationResponseSchema, '/invitations/accept', {
|
|
10
8
|
method: 'POST',
|
|
11
|
-
body,
|
|
9
|
+
body: command,
|
|
12
10
|
});
|
|
11
|
+
return toInvitationAcceptance(response);
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
export function useAcceptInvitation() {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {toInvitationAcceptance} from './invitation-acceptance-mapper.js';
|
|
2
|
+
|
|
3
|
+
describe('toInvitationAcceptance', () => {
|
|
4
|
+
test('maps the acceptance response into the invitation domain', () => {
|
|
5
|
+
const result = toInvitationAcceptance({
|
|
6
|
+
membership: {
|
|
7
|
+
id: '11111111-1111-4111-8111-111111111111',
|
|
8
|
+
user_id: '22222222-2222-4222-8222-222222222222',
|
|
9
|
+
workspace_id: '33333333-3333-4333-8333-333333333333',
|
|
10
|
+
},
|
|
11
|
+
already_member: true,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
expect(result).toEqual({
|
|
15
|
+
membership: {
|
|
16
|
+
id: '11111111-1111-4111-8111-111111111111',
|
|
17
|
+
userId: '22222222-2222-4222-8222-222222222222',
|
|
18
|
+
workspaceId: '33333333-3333-4333-8333-333333333333',
|
|
19
|
+
},
|
|
20
|
+
alreadyMember: true,
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type {AcceptInvitationResponseDto} from '@shipfox/api-workspaces-dto';
|
|
2
|
+
import type {InvitationAcceptance} from '#core/invitation-acceptance.js';
|
|
3
|
+
|
|
4
|
+
export function toInvitationAcceptance(dto: AcceptInvitationResponseDto): InvitationAcceptance {
|
|
5
|
+
return {
|
|
6
|
+
membership: {
|
|
7
|
+
id: dto.membership.id,
|
|
8
|
+
userId: dto.membership.user_id,
|
|
9
|
+
workspaceId: dto.membership.workspace_id,
|
|
10
|
+
},
|
|
11
|
+
alreadyMember: dto.already_member,
|
|
12
|
+
};
|
|
13
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export type {InvitationAcceptance} from '#core/invitation-acceptance.js';
|
|
1
2
|
export {type InvitationPreview, pendingInvitation} from '#core/invitation-preview.js';
|
|
2
3
|
export {completeInvitationAcceptance} from './complete-acceptance.js';
|
|
3
4
|
export {useAcceptInvitation} from './hooks/api/accept-invitation.js';
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
AuthShell,
|
|
3
|
+
useAuthState,
|
|
4
|
+
useRefreshAuth,
|
|
5
|
+
useRouteSearch,
|
|
6
|
+
} from '@shipfox/client-shell/runtime';
|
|
2
7
|
import {createSingleFlight} from '@shipfox/client-ui';
|
|
3
8
|
import {Button} from '@shipfox/react-ui/button';
|
|
4
9
|
import {Callout} from '@shipfox/react-ui/callout';
|
|
@@ -6,20 +11,19 @@ import {ShipfoxLoader} from '@shipfox/react-ui/loader';
|
|
|
6
11
|
import {toast} from '@shipfox/react-ui/toast';
|
|
7
12
|
import {Text} from '@shipfox/react-ui/typography';
|
|
8
13
|
import {formatDate} from '@shipfox/react-ui/utils';
|
|
9
|
-
import {Link, useNavigate
|
|
14
|
+
import {Link, useNavigate} from '@tanstack/react-router';
|
|
10
15
|
import {useCallback, useEffect, useRef} from 'react';
|
|
11
16
|
import {completeInvitationAcceptance} from '#complete-acceptance.js';
|
|
12
17
|
import {useAcceptInvitation} from '#hooks/api/accept-invitation.js';
|
|
13
18
|
import {usePreviewInvitation} from '#hooks/api/preview-invitation.js';
|
|
19
|
+
import {validateInvitationAcceptSearch} from '../routes/inputs.js';
|
|
14
20
|
|
|
15
21
|
const invitationAccepts = createSingleFlight<string, void>();
|
|
16
22
|
const toastedTerminals = new Set<string>();
|
|
17
23
|
const TOASTED_TERMINALS_MAX = 32;
|
|
18
24
|
|
|
19
25
|
export function InvitationAcceptPage() {
|
|
20
|
-
const
|
|
21
|
-
const token =
|
|
22
|
-
typeof search.token === 'string' && search.token.length > 0 ? search.token : undefined;
|
|
26
|
+
const {token} = useRouteSearch(validateInvitationAcceptSearch);
|
|
23
27
|
const navigate = useNavigate();
|
|
24
28
|
const auth = useAuthState();
|
|
25
29
|
const refreshAuth = useRefreshAuth();
|
|
@@ -53,7 +57,7 @@ export function InvitationAcceptPage() {
|
|
|
53
57
|
const runAccept = useCallback(
|
|
54
58
|
async (params: {token: string; workspaceName: string}) => {
|
|
55
59
|
const result = await accept.mutateAsync({token: params.token});
|
|
56
|
-
await completeAccept(result.membership.
|
|
60
|
+
await completeAccept(result.membership.workspaceId, params.workspaceName);
|
|
57
61
|
},
|
|
58
62
|
[accept, completeAccept],
|
|
59
63
|
);
|
package/src/routes/accept.tsx
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import {defineRoute} from '@shipfox/client-shell/runtime';
|
|
2
2
|
import {InvitationAcceptPage} from '#pages/invitation-accept-page.js';
|
|
3
|
+
import {validateInvitationAcceptSearch} from './inputs.js';
|
|
3
4
|
|
|
4
|
-
export default defineRoute({
|
|
5
|
+
export default defineRoute({
|
|
6
|
+
validateSearch: validateInvitationAcceptSearch,
|
|
7
|
+
component: InvitationAcceptPage,
|
|
8
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {validateInvitationAcceptSearch} from './inputs.js';
|
|
2
|
+
|
|
3
|
+
describe('invitation route inputs', () => {
|
|
4
|
+
it('accepts a token and drops missing or malformed values', () => {
|
|
5
|
+
expect(validateInvitationAcceptSearch({token: 'invite-token'})).toEqual({
|
|
6
|
+
token: 'invite-token',
|
|
7
|
+
});
|
|
8
|
+
expect(validateInvitationAcceptSearch({})).toEqual({});
|
|
9
|
+
expect(validateInvitationAcceptSearch({token: ['invite-token']})).toEqual({});
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface InvitationAcceptSearch {
|
|
2
|
+
token?: string;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function validateInvitationAcceptSearch(
|
|
6
|
+
input: Record<string, unknown>,
|
|
7
|
+
): InvitationAcceptSearch {
|
|
8
|
+
const token = typeof input.token === 'string' && input.token.length > 0 ? input.token : undefined;
|
|
9
|
+
return token ? {token} : {};
|
|
10
|
+
}
|