@contember/create 2.2.0-alpha.2 → 2.2.0-alpha.21
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/CLAUDE.md +22 -0
- package/dist/development/run.cjs +7 -7
- package/dist/development/run.cjs.map +1 -1
- package/dist/development/run.js +8 -8
- package/dist/development/run.js.map +1 -1
- package/dist/development/src/commands/WorkspaceCreateCommand.cjs +36 -23
- package/dist/development/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
- package/dist/development/src/commands/WorkspaceCreateCommand.js +37 -24
- package/dist/development/src/commands/WorkspaceCreateCommand.js.map +1 -1
- package/dist/development/src/lib/FileSystem.cjs +10 -4
- package/dist/development/src/lib/FileSystem.cjs.map +1 -1
- package/dist/development/src/lib/FileSystem.js +8 -2
- package/dist/development/src/lib/FileSystem.js.map +1 -1
- package/dist/development/src/lib/TemplateInstaller.cjs +71 -60
- package/dist/development/src/lib/TemplateInstaller.cjs.map +1 -1
- package/dist/development/src/lib/TemplateInstaller.js +71 -60
- package/dist/development/src/lib/TemplateInstaller.js.map +1 -1
- package/dist/development/src/lib/fsErrors.cjs +7 -0
- package/dist/development/src/lib/fsErrors.cjs.map +1 -0
- package/dist/development/src/lib/fsErrors.js +7 -0
- package/dist/development/src/lib/fsErrors.js.map +1 -0
- package/dist/development/src/lib/projectPath.cjs +66 -0
- package/dist/development/src/lib/projectPath.cjs.map +1 -0
- package/dist/development/src/lib/projectPath.js +66 -0
- package/dist/development/src/lib/projectPath.js.map +1 -0
- package/dist/development/src/lib/remoteTemplate.cjs +108 -0
- package/dist/development/src/lib/remoteTemplate.cjs.map +1 -0
- package/dist/development/src/lib/remoteTemplate.js +108 -0
- package/dist/development/src/lib/remoteTemplate.js.map +1 -0
- package/dist/development/src/lib/tar.cjs +243 -0
- package/dist/development/src/lib/tar.cjs.map +1 -0
- package/dist/development/src/lib/tar.js +243 -0
- package/dist/development/src/lib/tar.js.map +1 -0
- package/dist/production/run.cjs +7 -7
- package/dist/production/run.cjs.map +1 -1
- package/dist/production/run.js +8 -8
- package/dist/production/run.js.map +1 -1
- package/dist/production/src/commands/WorkspaceCreateCommand.cjs +36 -23
- package/dist/production/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
- package/dist/production/src/commands/WorkspaceCreateCommand.js +37 -24
- package/dist/production/src/commands/WorkspaceCreateCommand.js.map +1 -1
- package/dist/production/src/lib/FileSystem.cjs +10 -4
- package/dist/production/src/lib/FileSystem.cjs.map +1 -1
- package/dist/production/src/lib/FileSystem.js +8 -2
- package/dist/production/src/lib/FileSystem.js.map +1 -1
- package/dist/production/src/lib/TemplateInstaller.cjs +71 -60
- package/dist/production/src/lib/TemplateInstaller.cjs.map +1 -1
- package/dist/production/src/lib/TemplateInstaller.js +71 -60
- package/dist/production/src/lib/TemplateInstaller.js.map +1 -1
- package/dist/production/src/lib/fsErrors.cjs +7 -0
- package/dist/production/src/lib/fsErrors.cjs.map +1 -0
- package/dist/production/src/lib/fsErrors.js +7 -0
- package/dist/production/src/lib/fsErrors.js.map +1 -0
- package/dist/production/src/lib/projectPath.cjs +66 -0
- package/dist/production/src/lib/projectPath.cjs.map +1 -0
- package/dist/production/src/lib/projectPath.js +66 -0
- package/dist/production/src/lib/projectPath.js.map +1 -0
- package/dist/production/src/lib/remoteTemplate.cjs +108 -0
- package/dist/production/src/lib/remoteTemplate.cjs.map +1 -0
- package/dist/production/src/lib/remoteTemplate.js +108 -0
- package/dist/production/src/lib/remoteTemplate.js.map +1 -0
- package/dist/production/src/lib/tar.cjs +243 -0
- package/dist/production/src/lib/tar.cjs.map +1 -0
- package/dist/production/src/lib/tar.js +243 -0
- package/dist/production/src/lib/tar.js.map +1 -0
- package/dist/types/commands/WorkspaceCreateCommand.d.ts +15 -3
- package/dist/types/commands/WorkspaceCreateCommand.d.ts.map +1 -1
- package/dist/types/lib/FileSystem.d.ts +2 -0
- package/dist/types/lib/FileSystem.d.ts.map +1 -1
- package/dist/types/lib/TemplateInstaller.d.ts +9 -1
- package/dist/types/lib/TemplateInstaller.d.ts.map +1 -1
- package/dist/types/lib/fsErrors.d.ts +3 -0
- package/dist/types/lib/fsErrors.d.ts.map +1 -0
- package/dist/types/lib/projectPath.d.ts +12 -0
- package/dist/types/lib/projectPath.d.ts.map +1 -0
- package/dist/types/lib/remoteTemplate.d.ts +15 -0
- package/dist/types/lib/remoteTemplate.d.ts.map +1 -0
- package/dist/types/lib/tar.d.ts +28 -0
- package/dist/types/lib/tar.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -7
- package/resources/templates/default/README.md +3 -1
- package/resources/templates/default/admin/app/components/navigation.tsx +95 -8
- package/resources/templates/default/admin/app/pages/tenant.tsx +328 -77
- package/resources/templates/default/admin/entrypoint/components/login.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/magicLink.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/magicLinkSent.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/passwordReset.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/resetRequest.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/resetRequestSuccess.tsx +1 -1
- package/resources/templates/default/admin/lib/editor/common/editor-inline-toolbar.tsx +3 -0
- package/resources/templates/default/admin/lib/editor/sortable-block.tsx +5 -4
- package/resources/templates/default/admin/lib/tenant/config/auth-policy-list.tsx +86 -0
- package/resources/templates/default/admin/lib/tenant/config/common.tsx +71 -0
- package/resources/templates/default/admin/lib/tenant/config/identity-provider-list.tsx +131 -0
- package/resources/templates/default/admin/lib/tenant/config/index.ts +5 -0
- package/resources/templates/default/admin/lib/tenant/config/mail-template-list.tsx +108 -0
- package/resources/templates/default/admin/lib/tenant/config/tenant-config-view.tsx +195 -0
- package/resources/templates/default/admin/lib/tenant/dict.ts +456 -4
- package/resources/templates/default/admin/lib/tenant/errors.ts +10 -0
- package/resources/templates/default/admin/lib/tenant/forms/add-project-member.tsx +57 -0
- package/resources/templates/default/admin/lib/tenant/forms/change-my-profile.tsx +40 -0
- package/resources/templates/default/admin/lib/tenant/forms/change-profile.tsx +55 -0
- package/resources/templates/default/admin/lib/tenant/forms/common.tsx +9 -2
- package/resources/templates/default/admin/lib/tenant/forms/create-global-api-key.tsx +69 -0
- package/resources/templates/default/admin/lib/tenant/forms/global-roles-control.tsx +113 -0
- package/resources/templates/default/admin/lib/tenant/forms/index.ts +11 -0
- package/resources/templates/default/admin/lib/tenant/forms/invite.tsx +42 -4
- package/resources/templates/default/admin/lib/tenant/forms/login.tsx +4 -10
- package/resources/templates/default/admin/lib/tenant/forms/memberships-control.tsx +3 -1
- package/resources/templates/default/admin/lib/tenant/forms/mfa-code-fields.tsx +81 -0
- package/resources/templates/default/admin/lib/tenant/forms/passwordless-signin.tsx +4 -10
- package/resources/templates/default/admin/lib/tenant/forms/set-person-password.tsx +58 -0
- package/resources/templates/default/admin/lib/tenant/forms/set-project-secret.tsx +59 -0
- package/resources/templates/default/admin/lib/tenant/forms/sign-up.tsx +73 -0
- package/resources/templates/default/admin/lib/tenant/hooks/index.ts +2 -0
- package/resources/templates/default/admin/lib/tenant/idp/identity-provider-connections.tsx +124 -0
- package/resources/templates/default/admin/lib/tenant/idp/index.ts +1 -0
- package/resources/templates/default/admin/lib/tenant/index.ts +7 -0
- package/resources/templates/default/admin/lib/tenant/listing/api-key-list.tsx +160 -22
- package/resources/templates/default/admin/lib/tenant/listing/auth-log-list.tsx +179 -0
- package/resources/templates/default/admin/lib/tenant/listing/global-api-key-list.tsx +149 -0
- package/resources/templates/default/admin/lib/tenant/listing/index.ts +7 -0
- package/resources/templates/default/admin/lib/tenant/listing/member-delete-dialog.tsx +1 -1
- package/resources/templates/default/admin/lib/tenant/listing/member-list.tsx +20 -11
- package/resources/templates/default/admin/lib/tenant/listing/mfa.tsx +29 -0
- package/resources/templates/default/admin/lib/tenant/listing/person-actions.tsx +179 -0
- package/resources/templates/default/admin/lib/tenant/listing/person-detail.tsx +141 -0
- package/resources/templates/default/admin/lib/tenant/listing/person-list.tsx +13 -2
- package/resources/templates/default/admin/lib/tenant/listing/persons-list.tsx +128 -0
- package/resources/templates/default/admin/lib/tenant/listing/project-secret-list.tsx +82 -0
- package/resources/templates/default/admin/lib/tenant/otp/backup-codes.tsx +81 -0
- package/resources/templates/default/admin/lib/tenant/otp/email-otp-setup.tsx +133 -0
- package/resources/templates/default/admin/lib/tenant/otp/index.ts +2 -0
- package/resources/templates/default/admin/lib/tenant/security/index.ts +2 -0
- package/resources/templates/default/admin/lib/tenant/security/passwordless-toggle.tsx +63 -0
- package/resources/templates/default/admin/lib/tenant/security/session-list.tsx +143 -0
- package/resources/templates/default/admin/lib/ui/label.tsx +25 -2
- package/resources/templates/default/admin/lib/ui/menu.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/progress.tsx +75 -11
- package/resources/templates/default/admin/lib/ui/separator.tsx +27 -3
- package/resources/templates/default/admin/lib/ui/sidebar.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/toggle.tsx +41 -2
- package/resources/templates/default/admin/lib/utils/classNames.ts +107 -0
- package/resources/templates/default/admin/lib/utils/cn.ts +3 -3
- package/resources/templates/default/admin/lib/utils/index.ts +1 -0
- package/resources/templates/default/admin/lib/utils/uic.tsx +2 -3
- package/resources/templates/default/admin/package.json +1 -7
- package/resources/templates/default/docker/object-storage/README.md +13 -0
- package/resources/templates/default/docker/object-storage/identities.json +13 -0
- package/resources/templates/default/docker-compose.yaml +29 -7
- package/src/commands/WorkspaceCreateCommand.ts +51 -24
- package/src/lib/FileSystem.ts +7 -2
- package/src/lib/TemplateInstaller.ts +87 -69
- package/src/lib/fsErrors.ts +2 -0
- package/src/lib/projectPath.ts +79 -0
- package/src/lib/remoteTemplate.ts +130 -0
- package/src/lib/tar.ts +283 -0
- package/src/run.ts +8 -7
- package/tests/cases/unit/create-process.test.ts +66 -0
- package/tests/cases/unit/fileSystem.test.ts +14 -0
- package/tests/cases/unit/fixtures/template.tar.gz +0 -0
- package/tests/cases/unit/remoteTemplate.test.ts +277 -0
- package/tests/cases/unit/template-installer-cleanup.test.ts +150 -0
- package/tests/cases/unit/template-installer-containment.test.ts +133 -0
- package/tests/cases/unit/template-installer-symlinks.test.ts +37 -0
- package/tests/cases/unit/workspace-create.test.ts +81 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { useSignUpForm } from '@contember/react-identity'
|
|
2
|
+
import { Button } from '~/lib'
|
|
3
|
+
import { Loader } from '~/lib'
|
|
4
|
+
import { TenantFormError, TenantFormField } from './common.js'
|
|
5
|
+
import { dict } from '../dict.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Fields for open registration. `signUp` creates the account but does not sign
|
|
9
|
+
* anyone in — the surrounding page decides what happens next.
|
|
10
|
+
*/
|
|
11
|
+
export const SignUpFormFields = ({ showName = true }: { showName?: boolean }) => {
|
|
12
|
+
const form = useSignUpForm()
|
|
13
|
+
return (
|
|
14
|
+
<div className="relative flex flex-col gap-2">
|
|
15
|
+
{form.state === 'success' || form.state === 'submitting' ? <Loader position="absolute" /> : null}
|
|
16
|
+
|
|
17
|
+
<TenantFormError
|
|
18
|
+
form={form}
|
|
19
|
+
messages={dict.tenant.signUp.errorMessages}
|
|
20
|
+
/>
|
|
21
|
+
|
|
22
|
+
<TenantFormField
|
|
23
|
+
form={form}
|
|
24
|
+
messages={dict.tenant.signUp.errorMessages}
|
|
25
|
+
field="email"
|
|
26
|
+
type="email"
|
|
27
|
+
required
|
|
28
|
+
autoFocus
|
|
29
|
+
autoComplete="email"
|
|
30
|
+
>
|
|
31
|
+
{dict.tenant.signUp.email}
|
|
32
|
+
</TenantFormField>
|
|
33
|
+
|
|
34
|
+
{showName && (
|
|
35
|
+
<TenantFormField
|
|
36
|
+
form={form}
|
|
37
|
+
messages={dict.tenant.signUp.errorMessages}
|
|
38
|
+
field="name"
|
|
39
|
+
type="text"
|
|
40
|
+
autoComplete="name"
|
|
41
|
+
>
|
|
42
|
+
{dict.tenant.signUp.name}
|
|
43
|
+
</TenantFormField>
|
|
44
|
+
)}
|
|
45
|
+
|
|
46
|
+
<TenantFormField
|
|
47
|
+
form={form}
|
|
48
|
+
messages={dict.tenant.signUp.errorMessages}
|
|
49
|
+
field="password"
|
|
50
|
+
type="password"
|
|
51
|
+
required
|
|
52
|
+
autoComplete="new-password"
|
|
53
|
+
>
|
|
54
|
+
{dict.tenant.signUp.password}
|
|
55
|
+
</TenantFormField>
|
|
56
|
+
|
|
57
|
+
<TenantFormField
|
|
58
|
+
form={form}
|
|
59
|
+
messages={dict.tenant.signUp.errorMessages}
|
|
60
|
+
field="passwordConfirmation"
|
|
61
|
+
type="password"
|
|
62
|
+
required
|
|
63
|
+
autoComplete="new-password"
|
|
64
|
+
>
|
|
65
|
+
{dict.tenant.signUp.passwordConfirmation}
|
|
66
|
+
</TenantFormField>
|
|
67
|
+
|
|
68
|
+
<Button type="submit" className="w-full" disabled={form.state === 'submitting'}>
|
|
69
|
+
{dict.tenant.signUp.submit}
|
|
70
|
+
</Button>
|
|
71
|
+
</div>
|
|
72
|
+
)
|
|
73
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
import {
|
|
4
|
+
AlertDialog,
|
|
5
|
+
AlertDialogAction,
|
|
6
|
+
AlertDialogCancel,
|
|
7
|
+
AlertDialogContent,
|
|
8
|
+
AlertDialogFooter,
|
|
9
|
+
AlertDialogHeader,
|
|
10
|
+
AlertDialogTitle,
|
|
11
|
+
AlertDialogTrigger,
|
|
12
|
+
Button,
|
|
13
|
+
Loader,
|
|
14
|
+
Table,
|
|
15
|
+
TableCell,
|
|
16
|
+
TableHead,
|
|
17
|
+
TableHeader,
|
|
18
|
+
TableRow,
|
|
19
|
+
ToastContent,
|
|
20
|
+
useShowToast,
|
|
21
|
+
} from '~/lib'
|
|
22
|
+
import { RefreshCwIcon, UnlinkIcon } from 'lucide-react'
|
|
23
|
+
import { useDisconnectMyIdentityProviderMutation, useMyIdentityProvidersQuery, useTenantQueryLoader } from '@contember/react-client-tenant'
|
|
24
|
+
import { dict } from '../dict.js'
|
|
25
|
+
|
|
26
|
+
export interface IdentityProviderConnectionsController {
|
|
27
|
+
refresh: () => void
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface IdentityProviderConnectionsProps {
|
|
31
|
+
controller?: { current?: IdentityProviderConnectionsController }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const IdentityProviderConnections = ({ controller }: IdentityProviderConnectionsProps) => {
|
|
35
|
+
const [query, { refresh }] = useTenantQueryLoader(useMyIdentityProvidersQuery(), {})
|
|
36
|
+
if (controller) {
|
|
37
|
+
controller.current = { refresh }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (query.state === 'error') {
|
|
41
|
+
return <div className="text-destructive italic">{dict.tenant.identityProviderConnections.failedToLoadData}</div>
|
|
42
|
+
}
|
|
43
|
+
return (
|
|
44
|
+
<div className="relative">
|
|
45
|
+
{query.state !== 'success' && <Loader position="absolute" />}
|
|
46
|
+
<Table>
|
|
47
|
+
<TableHeader>
|
|
48
|
+
<TableRow>
|
|
49
|
+
<TableHead>{dict.tenant.identityProviderConnections.provider}</TableHead>
|
|
50
|
+
<TableHead>{dict.tenant.identityProviderConnections.account}</TableHead>
|
|
51
|
+
<TableHead>{dict.tenant.identityProviderConnections.connectedAt}</TableHead>
|
|
52
|
+
<TableHead>{dict.tenant.identityProviderConnections.status}</TableHead>
|
|
53
|
+
<TableHead className="w-24">
|
|
54
|
+
<div className="flex gap-2 items-center">
|
|
55
|
+
<span>{dict.tenant.identityProviderConnections.action}</span>
|
|
56
|
+
<Button variant="outline" onClick={refresh} className="ml-auto" size="sm">
|
|
57
|
+
<RefreshCwIcon className="w-3 h-3" />
|
|
58
|
+
</Button>
|
|
59
|
+
</div>
|
|
60
|
+
</TableHead>
|
|
61
|
+
</TableRow>
|
|
62
|
+
</TableHeader>
|
|
63
|
+
{'data' in query && query.data.length === 0 && (
|
|
64
|
+
<TableRow>
|
|
65
|
+
<TableCell colSpan={5}>{dict.tenant.identityProviderConnections.noResults}</TableCell>
|
|
66
|
+
</TableRow>
|
|
67
|
+
)}
|
|
68
|
+
{'data' in query && query.data.map(connection => (
|
|
69
|
+
<TableRow key={connection.id}>
|
|
70
|
+
<TableCell className="font-medium">{connection.identityProvider.slug}</TableCell>
|
|
71
|
+
<TableCell>{connection.externalIdentifier}</TableCell>
|
|
72
|
+
<TableCell className="whitespace-nowrap">{new Date(connection.createdAt).toLocaleString()}</TableCell>
|
|
73
|
+
<TableCell>
|
|
74
|
+
{connection.identityProvider.disabledAt
|
|
75
|
+
? <span className="text-destructive">{dict.tenant.identityProviderConnections.disabled}</span>
|
|
76
|
+
: null}
|
|
77
|
+
</TableCell>
|
|
78
|
+
<TableCell className="whitespace-nowrap">
|
|
79
|
+
<DisconnectDialog connectionId={connection.id} onSuccess={refresh} />
|
|
80
|
+
</TableCell>
|
|
81
|
+
</TableRow>
|
|
82
|
+
))}
|
|
83
|
+
</Table>
|
|
84
|
+
</div>
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const DisconnectDialog = ({ connectionId, onSuccess }: { connectionId: string; onSuccess: () => void }) => {
|
|
89
|
+
const disconnect = useDisconnectMyIdentityProviderMutation()
|
|
90
|
+
const showToast = useShowToast()
|
|
91
|
+
const [open, setOpen] = useState(false)
|
|
92
|
+
const onConfirm = async () => {
|
|
93
|
+
const result = await disconnect({ id: connectionId })
|
|
94
|
+
setOpen(false)
|
|
95
|
+
if (result.ok) {
|
|
96
|
+
showToast(<ToastContent>{dict.tenant.identityProviderConnections.disconnected}</ToastContent>, { type: 'success' })
|
|
97
|
+
onSuccess()
|
|
98
|
+
} else {
|
|
99
|
+
const message = dict.tenant.identityProviderConnections.errorMessages[result.error]
|
|
100
|
+
?? dict.tenant.identityProviderConnections.errorMessages.UNKNOWN_ERROR
|
|
101
|
+
showToast(<ToastContent>{message}</ToastContent>, { type: 'error' })
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return (
|
|
105
|
+
<AlertDialog open={open} onOpenChange={setOpen}>
|
|
106
|
+
<AlertDialogTrigger asChild>
|
|
107
|
+
<Button variant="destructive">
|
|
108
|
+
<UnlinkIcon className="w-3 h-3" />
|
|
109
|
+
</Button>
|
|
110
|
+
</AlertDialogTrigger>
|
|
111
|
+
<AlertDialogContent>
|
|
112
|
+
<AlertDialogHeader>
|
|
113
|
+
<AlertDialogTitle>{dict.tenant.identityProviderConnections.disconnectConfirmation}</AlertDialogTitle>
|
|
114
|
+
</AlertDialogHeader>
|
|
115
|
+
<AlertDialogFooter>
|
|
116
|
+
<AlertDialogCancel>{dict.tenant.identityProviderConnections.cancel}</AlertDialogCancel>
|
|
117
|
+
<AlertDialogAction asChild>
|
|
118
|
+
<Button variant="destructive" onClick={onConfirm}>{dict.tenant.identityProviderConnections.disconnect}</Button>
|
|
119
|
+
</AlertDialogAction>
|
|
120
|
+
</AlertDialogFooter>
|
|
121
|
+
</AlertDialogContent>
|
|
122
|
+
</AlertDialog>
|
|
123
|
+
)
|
|
124
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './identity-provider-connections.js'
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
// re-exported under a prefixed name: `react-ui-lib-base` also exports a `dict`, and `react-ui-lib` star-exports both
|
|
2
|
+
export { dict as tenantDict } from './dict.js'
|
|
3
|
+
export * from './config/index.js'
|
|
4
|
+
export * from './errors.js'
|
|
1
5
|
export * from './forms/index.js'
|
|
6
|
+
export * from './hooks/index.js'
|
|
7
|
+
export * from './idp/index.js'
|
|
2
8
|
export * from './listing/index.js'
|
|
3
9
|
export * from './otp/index.js'
|
|
10
|
+
export * from './security/index.js'
|
|
@@ -1,27 +1,165 @@
|
|
|
1
|
-
import { ProjectMembersFilter } from '@contember/graphql-client-tenant'
|
|
2
1
|
import * as React from 'react'
|
|
3
|
-
import {
|
|
2
|
+
import { ReactNode, useState } from 'react'
|
|
3
|
+
import {
|
|
4
|
+
AlertDialog,
|
|
5
|
+
AlertDialogAction,
|
|
6
|
+
AlertDialogCancel,
|
|
7
|
+
AlertDialogContent,
|
|
8
|
+
AlertDialogFooter,
|
|
9
|
+
AlertDialogHeader,
|
|
10
|
+
AlertDialogTitle,
|
|
11
|
+
AlertDialogTrigger,
|
|
12
|
+
Button,
|
|
13
|
+
Loader,
|
|
14
|
+
Table,
|
|
15
|
+
TableCell,
|
|
16
|
+
TableHead,
|
|
17
|
+
TableHeader,
|
|
18
|
+
TableRow,
|
|
19
|
+
ToastContent,
|
|
20
|
+
useShowToast,
|
|
21
|
+
} from '~/lib'
|
|
22
|
+
import { BanIcon, RefreshCwIcon } from 'lucide-react'
|
|
23
|
+
import {
|
|
24
|
+
ProjectApiKeysQueryResult,
|
|
25
|
+
toFormErrorCode,
|
|
26
|
+
useDisableApiKeyMutation,
|
|
27
|
+
useProjectApiKeysQuery,
|
|
28
|
+
useTenantQueryLoader,
|
|
29
|
+
} from '@contember/react-client-tenant'
|
|
30
|
+
import { useProjectSlug } from '@contember/react-client'
|
|
4
31
|
import { dict } from '../dict.js'
|
|
5
|
-
import {
|
|
32
|
+
import { actionErrorMessage } from '../errors.js'
|
|
6
33
|
|
|
7
|
-
const
|
|
8
|
-
|
|
34
|
+
const formatDateTime = (value?: string | null): ReactNode => {
|
|
35
|
+
if (!value) {
|
|
36
|
+
return <span className="text-gray-400 italic">{dict.tenant.apiKeyList.never}</span>
|
|
37
|
+
}
|
|
38
|
+
return new Date(value).toLocaleString()
|
|
9
39
|
}
|
|
10
40
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
41
|
+
const projectRoles = (apiKey: ProjectApiKeysQueryResult[number], projectSlug: string): string[] =>
|
|
42
|
+
apiKey.identity.projects
|
|
43
|
+
.filter(it => it.project.slug === projectSlug)
|
|
44
|
+
.flatMap(it => it.memberships.map(membership => membership.role))
|
|
45
|
+
|
|
46
|
+
export interface ApiKeyListController {
|
|
47
|
+
refresh: () => void
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface ApiKeyListProps {
|
|
51
|
+
controller?: { current?: ApiKeyListController }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const ApiKeyList = ({ controller }: ApiKeyListProps) => {
|
|
55
|
+
const projectSlug = useProjectSlug()!
|
|
56
|
+
const [query, { refresh }] = useTenantQueryLoader(useProjectApiKeysQuery(), { projectSlug })
|
|
57
|
+
if (controller) {
|
|
58
|
+
controller.current = { refresh }
|
|
59
|
+
}
|
|
60
|
+
const showToast = useShowToast()
|
|
61
|
+
|
|
62
|
+
const onDisabled = () => {
|
|
63
|
+
refresh()
|
|
64
|
+
showToast(<ToastContent>{dict.tenant.apiKeyList.disableSuccess}</ToastContent>, { type: 'success' })
|
|
65
|
+
}
|
|
66
|
+
const onDisableError = (code: string) => {
|
|
67
|
+
showToast(<ToastContent>{actionErrorMessage(code, dict.tenant.apiKeyList.disableFailed)}</ToastContent>, { type: 'error' })
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (query.state === 'error') {
|
|
71
|
+
return <div className="text-destructive italic">{dict.tenant.apiKeyList.failedToLoadData}</div>
|
|
72
|
+
}
|
|
73
|
+
return (
|
|
74
|
+
<div className="relative">
|
|
75
|
+
{query.state !== 'success' && <Loader position="absolute" />}
|
|
76
|
+
<Table>
|
|
77
|
+
<TableHeader>
|
|
78
|
+
<TableRow>
|
|
79
|
+
<TableHead>{dict.tenant.apiKeyList.description}</TableHead>
|
|
80
|
+
<TableHead>{dict.tenant.apiKeyList.type}</TableHead>
|
|
81
|
+
<TableHead>{dict.tenant.apiKeyList.roles}</TableHead>
|
|
82
|
+
<TableHead>{dict.tenant.apiKeyList.status}</TableHead>
|
|
83
|
+
<TableHead>{dict.tenant.apiKeyList.created}</TableHead>
|
|
84
|
+
<TableHead>{dict.tenant.apiKeyList.lastUsed}</TableHead>
|
|
85
|
+
<TableHead>{dict.tenant.apiKeyList.expires}</TableHead>
|
|
86
|
+
<TableHead className="w-24">
|
|
87
|
+
<div className="flex gap-2 items-center">
|
|
88
|
+
<span>{dict.tenant.apiKeyList.action}</span>
|
|
89
|
+
<Button variant="outline" onClick={refresh} className="ml-auto" size="sm">
|
|
90
|
+
<RefreshCwIcon className="w-3 h-3" />
|
|
91
|
+
</Button>
|
|
92
|
+
</div>
|
|
93
|
+
</TableHead>
|
|
94
|
+
</TableRow>
|
|
95
|
+
</TableHeader>
|
|
96
|
+
{'data' in query && query.data.length === 0 && (
|
|
97
|
+
<TableRow>
|
|
98
|
+
<TableCell colSpan={8}>{dict.tenant.apiKeyList.noResults}</TableCell>
|
|
99
|
+
</TableRow>
|
|
100
|
+
)}
|
|
101
|
+
{'data' in query && query.data.map(apiKey => {
|
|
102
|
+
const roles = projectRoles(apiKey, projectSlug)
|
|
103
|
+
return (
|
|
104
|
+
<TableRow key={apiKey.id}>
|
|
105
|
+
<TableCell>{apiKey.description ?? apiKey.identity.description ?? dict.tenant.apiKeyList.unnamed}</TableCell>
|
|
106
|
+
<TableCell>{apiKey.type ?? dict.tenant.apiKeyList.unknownType}</TableCell>
|
|
107
|
+
<TableCell>{roles.length ? roles.join(', ') : dict.tenant.apiKeyList.noRoles}</TableCell>
|
|
108
|
+
<TableCell>
|
|
109
|
+
{apiKey.enabled === false
|
|
110
|
+
? <span className="text-destructive">{dict.tenant.apiKeyList.disabled}</span>
|
|
111
|
+
: dict.tenant.apiKeyList.enabled}
|
|
112
|
+
</TableCell>
|
|
113
|
+
<TableCell className="whitespace-nowrap">{formatDateTime(apiKey.createdAt)}</TableCell>
|
|
114
|
+
<TableCell className="whitespace-nowrap">{formatDateTime(apiKey.lastUsedAt)}</TableCell>
|
|
115
|
+
<TableCell className="whitespace-nowrap">{formatDateTime(apiKey.expiresAt)}</TableCell>
|
|
116
|
+
<TableCell className="whitespace-nowrap">
|
|
117
|
+
{apiKey.enabled !== false && <DisableApiKeyDialog apiKeyId={apiKey.id} onSuccess={onDisabled} onError={onDisableError} />}
|
|
118
|
+
</TableCell>
|
|
119
|
+
</TableRow>
|
|
120
|
+
)
|
|
121
|
+
})}
|
|
122
|
+
</Table>
|
|
123
|
+
</div>
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const DisableApiKeyDialog = ({ apiKeyId, onSuccess, onError }: { apiKeyId: string; onSuccess: () => void; onError: (code: string) => void }) => {
|
|
128
|
+
const disableApiKey = useDisableApiKeyMutation()
|
|
129
|
+
const [open, setOpen] = useState(false)
|
|
130
|
+
const onConfirm = async () => {
|
|
131
|
+
try {
|
|
132
|
+
const result = await disableApiKey({ id: apiKeyId })
|
|
133
|
+
setOpen(false)
|
|
134
|
+
if (result.ok) {
|
|
135
|
+
onSuccess()
|
|
136
|
+
} else {
|
|
137
|
+
onError('UNKNOWN_ERROR')
|
|
138
|
+
}
|
|
139
|
+
} catch (e) {
|
|
140
|
+
// A denied mutation throws; without this the dialog would just hang on an unhandled rejection.
|
|
141
|
+
setOpen(false)
|
|
142
|
+
onError(toFormErrorCode(e))
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return (
|
|
146
|
+
<AlertDialog open={open} onOpenChange={setOpen}>
|
|
147
|
+
<AlertDialogTrigger asChild>
|
|
148
|
+
<Button variant="destructive">
|
|
149
|
+
<BanIcon className="w-3 h-3" />
|
|
150
|
+
</Button>
|
|
151
|
+
</AlertDialogTrigger>
|
|
152
|
+
<AlertDialogContent>
|
|
153
|
+
<AlertDialogHeader>
|
|
154
|
+
<AlertDialogTitle>{dict.tenant.apiKeyList.disableConfirmation}</AlertDialogTitle>
|
|
155
|
+
</AlertDialogHeader>
|
|
156
|
+
<AlertDialogFooter>
|
|
157
|
+
<AlertDialogCancel>{dict.tenant.apiKeyList.cancel}</AlertDialogCancel>
|
|
158
|
+
<AlertDialogAction asChild>
|
|
159
|
+
<Button variant="destructive" onClick={onConfirm}>{dict.tenant.apiKeyList.disable}</Button>
|
|
160
|
+
</AlertDialogAction>
|
|
161
|
+
</AlertDialogFooter>
|
|
162
|
+
</AlertDialogContent>
|
|
163
|
+
</AlertDialog>
|
|
164
|
+
)
|
|
165
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { useMemo, useState } from 'react'
|
|
3
|
+
import {
|
|
4
|
+
Button,
|
|
5
|
+
Input,
|
|
6
|
+
Label,
|
|
7
|
+
Loader,
|
|
8
|
+
Select,
|
|
9
|
+
SelectContent,
|
|
10
|
+
SelectItem,
|
|
11
|
+
SelectTrigger,
|
|
12
|
+
SelectValue,
|
|
13
|
+
Table,
|
|
14
|
+
TableCell,
|
|
15
|
+
TableHead,
|
|
16
|
+
TableHeader,
|
|
17
|
+
TableRow,
|
|
18
|
+
} from '~/lib'
|
|
19
|
+
import { ChevronLeftIcon, ChevronRightIcon, RefreshCwIcon } from 'lucide-react'
|
|
20
|
+
import { AuthLogFilter } from '@contember/graphql-client-tenant'
|
|
21
|
+
import { isForbiddenError, useAuthLogQuery, useTenantQueryLoader } from '@contember/react-client-tenant'
|
|
22
|
+
import { dict } from '../dict.js'
|
|
23
|
+
|
|
24
|
+
const perPage = 20
|
|
25
|
+
|
|
26
|
+
type SuccessFilter = 'all' | 'ok' | 'failed'
|
|
27
|
+
|
|
28
|
+
export interface AuthLogListController {
|
|
29
|
+
refresh: () => void
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface AuthLogListProps {
|
|
33
|
+
controller?: { current?: AuthLogListController }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* `AuthLogList` renders the tenant authentication audit log with filtering and pagination.
|
|
38
|
+
*
|
|
39
|
+
* ## Example
|
|
40
|
+
* ```tsx
|
|
41
|
+
* <AuthLogList />
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export const AuthLogList = ({ controller }: AuthLogListProps) => {
|
|
45
|
+
const [page, setPage] = useState(0)
|
|
46
|
+
const [types, setTypes] = useState('')
|
|
47
|
+
const [success, setSuccess] = useState<SuccessFilter>('all')
|
|
48
|
+
const [person, setPerson] = useState('')
|
|
49
|
+
|
|
50
|
+
// `useTenantQueryLoader` compares its variables shallowly, so the nested filter has to keep its identity.
|
|
51
|
+
const filter = useMemo((): AuthLogFilter => {
|
|
52
|
+
// There is no enum of `auth_log_type` values in the API, so types are entered as a free-text, comma separated, OR-combined list.
|
|
53
|
+
const typeList = types.split(',').map(it => it.trim()).filter(Boolean)
|
|
54
|
+
return {
|
|
55
|
+
types: typeList.length ? typeList : undefined,
|
|
56
|
+
success: success === 'all' ? undefined : success === 'ok',
|
|
57
|
+
personInputIdentifier: person.trim() || undefined,
|
|
58
|
+
}
|
|
59
|
+
}, [types, success, person])
|
|
60
|
+
|
|
61
|
+
const [query, { refresh }] = useTenantQueryLoader(useAuthLogQuery(), {
|
|
62
|
+
filter,
|
|
63
|
+
offset: page * perPage,
|
|
64
|
+
limit: perPage,
|
|
65
|
+
})
|
|
66
|
+
if (controller) {
|
|
67
|
+
controller.current = { refresh }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<div className="relative flex flex-col gap-4">
|
|
72
|
+
<div className="flex flex-col gap-4 sm:flex-row sm:items-end">
|
|
73
|
+
<div className="flex flex-col gap-2 grow">
|
|
74
|
+
<Label htmlFor="auth-log-types">{dict.tenant.authLog.filterTypes}</Label>
|
|
75
|
+
<Input
|
|
76
|
+
id="auth-log-types"
|
|
77
|
+
type="text"
|
|
78
|
+
value={types}
|
|
79
|
+
placeholder={dict.tenant.authLog.filterTypesPlaceholder}
|
|
80
|
+
onChange={e => {
|
|
81
|
+
setPage(0)
|
|
82
|
+
setTypes(e.target.value)
|
|
83
|
+
}}
|
|
84
|
+
/>
|
|
85
|
+
</div>
|
|
86
|
+
<div className="flex flex-col gap-2 grow">
|
|
87
|
+
<Label htmlFor="auth-log-person">{dict.tenant.authLog.filterPerson}</Label>
|
|
88
|
+
<Input
|
|
89
|
+
id="auth-log-person"
|
|
90
|
+
type="text"
|
|
91
|
+
value={person}
|
|
92
|
+
placeholder={dict.tenant.authLog.filterPersonPlaceholder}
|
|
93
|
+
onChange={e => {
|
|
94
|
+
setPage(0)
|
|
95
|
+
setPerson(e.target.value)
|
|
96
|
+
}}
|
|
97
|
+
/>
|
|
98
|
+
</div>
|
|
99
|
+
<div className="flex flex-col gap-2 sm:w-48">
|
|
100
|
+
<Label htmlFor="auth-log-success">{dict.tenant.authLog.filterSuccess}</Label>
|
|
101
|
+
<Select
|
|
102
|
+
value={success}
|
|
103
|
+
onValueChange={value => {
|
|
104
|
+
setPage(0)
|
|
105
|
+
setSuccess(value === 'ok' || value === 'failed' ? value : 'all')
|
|
106
|
+
}}
|
|
107
|
+
>
|
|
108
|
+
<SelectTrigger id="auth-log-success">
|
|
109
|
+
<SelectValue />
|
|
110
|
+
</SelectTrigger>
|
|
111
|
+
<SelectContent>
|
|
112
|
+
<SelectItem value="all">{dict.tenant.authLog.filterSuccessAll}</SelectItem>
|
|
113
|
+
<SelectItem value="ok">{dict.tenant.authLog.filterSuccessOk}</SelectItem>
|
|
114
|
+
<SelectItem value="failed">{dict.tenant.authLog.filterSuccessFailed}</SelectItem>
|
|
115
|
+
</SelectContent>
|
|
116
|
+
</Select>
|
|
117
|
+
</div>
|
|
118
|
+
</div>
|
|
119
|
+
{/* `authLog` rejects rather than answering an empty page, so "not yours to see" is an ordinary state here. */}
|
|
120
|
+
{query.state === 'error'
|
|
121
|
+
? isForbiddenError(query.error)
|
|
122
|
+
? <div className="text-gray-500 italic">{dict.tenant.authLog.forbidden}</div>
|
|
123
|
+
: <div className="text-destructive italic">{dict.tenant.authLog.failedToLoadData}</div>
|
|
124
|
+
: (
|
|
125
|
+
<div className="relative">
|
|
126
|
+
{query.state !== 'success' && <Loader position="absolute" />}
|
|
127
|
+
<Table>
|
|
128
|
+
<TableHeader>
|
|
129
|
+
<TableRow>
|
|
130
|
+
<TableHead>{dict.tenant.authLog.createdAt}</TableHead>
|
|
131
|
+
<TableHead>{dict.tenant.authLog.type}</TableHead>
|
|
132
|
+
<TableHead>{dict.tenant.authLog.success}</TableHead>
|
|
133
|
+
<TableHead>{dict.tenant.authLog.person}</TableHead>
|
|
134
|
+
<TableHead>{dict.tenant.authLog.ipAddress}</TableHead>
|
|
135
|
+
<TableHead className="w-40">
|
|
136
|
+
<div className="flex gap-2 items-center">
|
|
137
|
+
<span>{dict.tenant.authLog.errorCode}</span>
|
|
138
|
+
<Button variant="outline" onClick={refresh} className="ml-auto" size="sm">
|
|
139
|
+
<RefreshCwIcon className="w-3 h-3" />
|
|
140
|
+
</Button>
|
|
141
|
+
</div>
|
|
142
|
+
</TableHead>
|
|
143
|
+
</TableRow>
|
|
144
|
+
</TableHeader>
|
|
145
|
+
{'data' in query && query.data.entries.length === 0 && (
|
|
146
|
+
<TableRow>
|
|
147
|
+
<TableCell colSpan={6}>{dict.tenant.authLog.noResults}</TableCell>
|
|
148
|
+
</TableRow>
|
|
149
|
+
)}
|
|
150
|
+
{'data' in query && query.data.entries.map(entry => (
|
|
151
|
+
<TableRow key={entry.id}>
|
|
152
|
+
<TableCell className="whitespace-nowrap">{new Date(entry.createdAt).toLocaleString()}</TableCell>
|
|
153
|
+
<TableCell className="font-mono text-xs">{entry.type}</TableCell>
|
|
154
|
+
<TableCell>
|
|
155
|
+
{entry.success
|
|
156
|
+
? dict.tenant.authLog.ok
|
|
157
|
+
: <span className="text-destructive">{dict.tenant.authLog.failed}</span>}
|
|
158
|
+
</TableCell>
|
|
159
|
+
<TableCell>{entry.personInputIdentifier}</TableCell>
|
|
160
|
+
<TableCell className="whitespace-nowrap">{entry.ipAddress}</TableCell>
|
|
161
|
+
<TableCell className="font-mono text-xs" title={entry.errorMessage}>{entry.errorCode}</TableCell>
|
|
162
|
+
</TableRow>
|
|
163
|
+
))}
|
|
164
|
+
</Table>
|
|
165
|
+
<div className="flex gap-2 mt-4 justify-between">
|
|
166
|
+
<Button variant="outline" disabled={page === 0} onClick={() => setPage(page - 1)}>
|
|
167
|
+
<ChevronLeftIcon className="w-4 h-4" />
|
|
168
|
+
<span className="sr-only">{dict.tenant.authLog.previous}</span>
|
|
169
|
+
</Button>
|
|
170
|
+
<Button variant="outline" disabled={'data' in query && !query.data.hasMore} onClick={() => setPage(page + 1)}>
|
|
171
|
+
<ChevronRightIcon className="w-4 h-4" />
|
|
172
|
+
<span className="sr-only">{dict.tenant.authLog.next}</span>
|
|
173
|
+
</Button>
|
|
174
|
+
</div>
|
|
175
|
+
</div>
|
|
176
|
+
)}
|
|
177
|
+
</div>
|
|
178
|
+
)
|
|
179
|
+
}
|