@contember/create 2.2.0-alpha.1 → 2.2.0-alpha.10
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 +27 -13
- package/dist/development/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
- package/dist/development/src/commands/WorkspaceCreateCommand.js +28 -14
- package/dist/development/src/commands/WorkspaceCreateCommand.js.map +1 -1
- package/dist/development/src/lib/TemplateInstaller.cjs +72 -60
- package/dist/development/src/lib/TemplateInstaller.cjs.map +1 -1
- package/dist/development/src/lib/TemplateInstaller.js +72 -60
- package/dist/development/src/lib/TemplateInstaller.js.map +1 -1
- 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 +27 -13
- package/dist/production/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
- package/dist/production/src/commands/WorkspaceCreateCommand.js +28 -14
- package/dist/production/src/commands/WorkspaceCreateCommand.js.map +1 -1
- package/dist/production/src/lib/TemplateInstaller.cjs +72 -60
- package/dist/production/src/lib/TemplateInstaller.cjs.map +1 -1
- package/dist/production/src/lib/TemplateInstaller.js +72 -60
- package/dist/production/src/lib/TemplateInstaller.js.map +1 -1
- 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.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/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- 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/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 +113 -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 +182 -0
- package/resources/templates/default/admin/lib/tenant/dict.ts +450 -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/package.json +1 -0
- 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 +42 -14
- package/src/lib/TemplateInstaller.ts +87 -69
- package/src/run.ts +8 -7
- package/tests/cases/unit/create-process.test.ts +66 -0
- package/tests/cases/unit/template-installer-cleanup.test.ts +150 -0
- package/tests/cases/unit/workspace-create.test.ts +81 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { useMemo, useState } from 'react'
|
|
3
|
+
import { Button, Input, Loader, Table, TableCell, TableHead, TableHeader, TableRow } from '~/lib'
|
|
4
|
+
import { ChevronLeftIcon, ChevronRightIcon, RefreshCwIcon } from 'lucide-react'
|
|
5
|
+
import { usePersonsQuery, useTenantQueryLoader } from '@contember/react-client-tenant'
|
|
6
|
+
import { dict } from '../dict.js'
|
|
7
|
+
import { MfaBadges } from './mfa.js'
|
|
8
|
+
import { DisablePersonAction, EnablePersonAction, ForceSignOutPersonAction, ResetPersonMfaAction } from './person-actions.js'
|
|
9
|
+
|
|
10
|
+
const perPage = 20
|
|
11
|
+
|
|
12
|
+
export interface PersonsListController {
|
|
13
|
+
refresh: () => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface PersonsListProps {
|
|
17
|
+
controller?: { current?: PersonsListController }
|
|
18
|
+
/** When set, the e-mail cell becomes a button — a host app typically opens `PersonDetail` from it. */
|
|
19
|
+
onSelectPerson?: (personId: string) => void
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const PersonsList = ({ controller, onSelectPerson }: PersonsListProps) => {
|
|
23
|
+
const [page, setPage] = useState(0)
|
|
24
|
+
const [email, setEmail] = useState('')
|
|
25
|
+
|
|
26
|
+
// useTenantQueryLoader compares its variables one level deep, so an inline filter object would refetch on every render
|
|
27
|
+
const filter = useMemo(() => email ? { email } : undefined, [email])
|
|
28
|
+
|
|
29
|
+
const [query, { refresh }] = useTenantQueryLoader(usePersonsQuery(), {
|
|
30
|
+
filter,
|
|
31
|
+
offset: page * perPage,
|
|
32
|
+
limit: perPage + 1,
|
|
33
|
+
})
|
|
34
|
+
if (controller) {
|
|
35
|
+
controller.current = { refresh }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<div className="relative flex flex-col gap-4">
|
|
40
|
+
<Input
|
|
41
|
+
type="text"
|
|
42
|
+
value={email}
|
|
43
|
+
placeholder={dict.tenant.personsList.filterEmailPlaceholder}
|
|
44
|
+
onChange={e => {
|
|
45
|
+
setPage(0)
|
|
46
|
+
setEmail(e.target.value)
|
|
47
|
+
}}
|
|
48
|
+
/>
|
|
49
|
+
{query.state === 'error'
|
|
50
|
+
? <div className="text-destructive italic">{dict.tenant.personsList.failedToLoadData}</div>
|
|
51
|
+
: (
|
|
52
|
+
<div className="relative">
|
|
53
|
+
{query.state !== 'success' && <Loader position="absolute" />}
|
|
54
|
+
<Table>
|
|
55
|
+
<TableHeader>
|
|
56
|
+
<TableRow>
|
|
57
|
+
<TableHead>{dict.tenant.personsList.email}</TableHead>
|
|
58
|
+
<TableHead>{dict.tenant.personsList.name}</TableHead>
|
|
59
|
+
<TableHead>{dict.tenant.personsList.roles}</TableHead>
|
|
60
|
+
<TableHead>{dict.tenant.personsList.status}</TableHead>
|
|
61
|
+
<TableHead>{dict.tenant.personsList.mfa}</TableHead>
|
|
62
|
+
<TableHead className="w-40">
|
|
63
|
+
<div className="flex gap-2 items-center">
|
|
64
|
+
<span>{dict.tenant.personsList.actions}</span>
|
|
65
|
+
<Button variant="outline" onClick={refresh} className="ml-auto" size="sm">
|
|
66
|
+
<RefreshCwIcon className="w-3 h-3" />
|
|
67
|
+
</Button>
|
|
68
|
+
</div>
|
|
69
|
+
</TableHead>
|
|
70
|
+
</TableRow>
|
|
71
|
+
</TableHeader>
|
|
72
|
+
{'data' in query && query.data.length === 0 && (
|
|
73
|
+
<TableRow>
|
|
74
|
+
<TableCell colSpan={6}>{dict.tenant.personsList.noResults}</TableCell>
|
|
75
|
+
</TableRow>
|
|
76
|
+
)}
|
|
77
|
+
{'data' in query && query.data.slice(0, perPage).map(person => (
|
|
78
|
+
<TableRow key={person.id}>
|
|
79
|
+
<TableCell>
|
|
80
|
+
{onSelectPerson
|
|
81
|
+
? (
|
|
82
|
+
<Button variant="link" size="sm" className="px-0" onClick={() => onSelectPerson(person.id)}>
|
|
83
|
+
{person.email ?? dict.tenant.personsList.noEmail}
|
|
84
|
+
</Button>
|
|
85
|
+
)
|
|
86
|
+
: person.email ?? dict.tenant.personsList.noEmail}
|
|
87
|
+
</TableCell>
|
|
88
|
+
<TableCell>{person.name ?? dict.tenant.personsList.noName}</TableCell>
|
|
89
|
+
<TableCell>
|
|
90
|
+
{person.identity.roles?.length ? person.identity.roles.join(', ') : dict.tenant.personsList.noRoles}
|
|
91
|
+
</TableCell>
|
|
92
|
+
<TableCell className="whitespace-nowrap">
|
|
93
|
+
{person.disabledAt
|
|
94
|
+
? (
|
|
95
|
+
<span className="text-destructive">
|
|
96
|
+
{dict.tenant.personsList.disabled} ({new Date(person.disabledAt).toLocaleString()})
|
|
97
|
+
</span>
|
|
98
|
+
)
|
|
99
|
+
: dict.tenant.personsList.active}
|
|
100
|
+
</TableCell>
|
|
101
|
+
<TableCell>
|
|
102
|
+
<MfaBadges otpEnabled={person.otpEnabled} emailOtpEnabled={person.emailOtpEnabled} />
|
|
103
|
+
</TableCell>
|
|
104
|
+
<TableCell className="space-x-2 whitespace-nowrap">
|
|
105
|
+
{person.disabledAt
|
|
106
|
+
? <EnablePersonAction personId={person.id} onSuccess={refresh} />
|
|
107
|
+
: <DisablePersonAction personId={person.id} onSuccess={refresh} />}
|
|
108
|
+
<ForceSignOutPersonAction personId={person.id} onSuccess={refresh} />
|
|
109
|
+
<ResetPersonMfaAction personId={person.id} onSuccess={refresh} />
|
|
110
|
+
</TableCell>
|
|
111
|
+
</TableRow>
|
|
112
|
+
))}
|
|
113
|
+
</Table>
|
|
114
|
+
<div className="flex gap-2 mt-4 justify-between">
|
|
115
|
+
<Button variant="outline" disabled={page === 0} onClick={() => setPage(page - 1)}>
|
|
116
|
+
<ChevronLeftIcon className="w-4 h-4" />
|
|
117
|
+
<span className="sr-only">{dict.tenant.personsList.previous}</span>
|
|
118
|
+
</Button>
|
|
119
|
+
<Button variant="outline" disabled={'data' in query && query.data.length <= perPage} onClick={() => setPage(page + 1)}>
|
|
120
|
+
<ChevronRightIcon className="w-4 h-4" />
|
|
121
|
+
<span className="sr-only">{dict.tenant.personsList.next}</span>
|
|
122
|
+
</Button>
|
|
123
|
+
</div>
|
|
124
|
+
</div>
|
|
125
|
+
)}
|
|
126
|
+
</div>
|
|
127
|
+
)
|
|
128
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { Button, Loader, Table, TableCell, TableHead, TableHeader, TableRow } from '~/lib'
|
|
3
|
+
import { RefreshCwIcon } from 'lucide-react'
|
|
4
|
+
import { useProjectSecretsQuery, useTenantQueryLoader } from '@contember/react-client-tenant'
|
|
5
|
+
import { useProjectSlug } from '@contember/react-client'
|
|
6
|
+
import { dict } from '../dict.js'
|
|
7
|
+
|
|
8
|
+
export interface ProjectSecretListController {
|
|
9
|
+
refresh: () => void
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ProjectSecretListProps {
|
|
13
|
+
controller?: { current?: ProjectSecretListController }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* `ProjectSecretList` lists the project secret keys and their timestamps; values are never returned by the API.
|
|
18
|
+
*
|
|
19
|
+
* The listing does not embed the editing form — a host app renders `SetProjectSecretForm` next to it and reloads
|
|
20
|
+
* the listing through the controller.
|
|
21
|
+
*
|
|
22
|
+
* ## Example
|
|
23
|
+
* ```tsx
|
|
24
|
+
* const controller = useRef<ProjectSecretListController>(undefined)
|
|
25
|
+
* return (
|
|
26
|
+
* <>
|
|
27
|
+
* <ProjectSecretList controller={controller} />
|
|
28
|
+
* <SetProjectSecretForm projectSlug={projectSlug} onSuccess={() => controller.current?.refresh()}>
|
|
29
|
+
* <form className="grid gap-4">
|
|
30
|
+
* <SetProjectSecretFormFields />
|
|
31
|
+
* </form>
|
|
32
|
+
* </SetProjectSecretForm>
|
|
33
|
+
* </>
|
|
34
|
+
* )
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export const ProjectSecretList = ({ controller }: ProjectSecretListProps) => {
|
|
38
|
+
const projectSlug = useProjectSlug()!
|
|
39
|
+
const [query, { refresh }] = useTenantQueryLoader(useProjectSecretsQuery(), {
|
|
40
|
+
projectSlug,
|
|
41
|
+
})
|
|
42
|
+
if (controller) {
|
|
43
|
+
controller.current = { refresh }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (query.state === 'error') {
|
|
47
|
+
return <div className="text-destructive italic">{dict.tenant.projectSecretList.failedToLoadData}</div>
|
|
48
|
+
}
|
|
49
|
+
return (
|
|
50
|
+
<div className="relative">
|
|
51
|
+
{query.state !== 'success' && <Loader position="absolute" />}
|
|
52
|
+
<Table>
|
|
53
|
+
<TableHeader>
|
|
54
|
+
<TableRow>
|
|
55
|
+
<TableHead>{dict.tenant.projectSecretList.key}</TableHead>
|
|
56
|
+
<TableHead>{dict.tenant.projectSecretList.created}</TableHead>
|
|
57
|
+
<TableHead className="w-32">
|
|
58
|
+
<div className="flex gap-2 items-center">
|
|
59
|
+
<span>{dict.tenant.projectSecretList.updated}</span>
|
|
60
|
+
<Button variant="outline" onClick={refresh} className="ml-auto" size="sm">
|
|
61
|
+
<RefreshCwIcon className="w-3 h-3" />
|
|
62
|
+
</Button>
|
|
63
|
+
</div>
|
|
64
|
+
</TableHead>
|
|
65
|
+
</TableRow>
|
|
66
|
+
</TableHeader>
|
|
67
|
+
{'data' in query && query.data.length === 0 && (
|
|
68
|
+
<TableRow>
|
|
69
|
+
<TableCell colSpan={3}>{dict.tenant.projectSecretList.noResults}</TableCell>
|
|
70
|
+
</TableRow>
|
|
71
|
+
)}
|
|
72
|
+
{'data' in query && query.data.map(secret => (
|
|
73
|
+
<TableRow key={secret.key}>
|
|
74
|
+
<TableCell className="font-mono">{secret.key}</TableCell>
|
|
75
|
+
<TableCell className="whitespace-nowrap">{new Date(secret.createdAt).toLocaleString()}</TableCell>
|
|
76
|
+
<TableCell className="whitespace-nowrap">{new Date(secret.updatedAt).toLocaleString()}</TableCell>
|
|
77
|
+
</TableRow>
|
|
78
|
+
))}
|
|
79
|
+
</Table>
|
|
80
|
+
</div>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import { RegenerateBackupCodesTrigger, useIdentity } from '@contember/interface'
|
|
3
|
+
import { Button } from '~/lib'
|
|
4
|
+
import {
|
|
5
|
+
AlertDialog,
|
|
6
|
+
AlertDialogAction,
|
|
7
|
+
AlertDialogCancel,
|
|
8
|
+
AlertDialogContent,
|
|
9
|
+
AlertDialogDescription,
|
|
10
|
+
AlertDialogFooter,
|
|
11
|
+
AlertDialogHeader,
|
|
12
|
+
AlertDialogTitle,
|
|
13
|
+
AlertDialogTrigger,
|
|
14
|
+
ToastContent,
|
|
15
|
+
useShowToast,
|
|
16
|
+
} from '~/lib'
|
|
17
|
+
import { dict } from '../dict.js'
|
|
18
|
+
import { actionErrorMessage } from '../errors.js'
|
|
19
|
+
|
|
20
|
+
export interface BackupCodesDisplayProps {
|
|
21
|
+
codes: readonly string[]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const BackupCodesDisplay = ({ codes }: BackupCodesDisplayProps) => (
|
|
25
|
+
<div className="flex flex-col gap-2">
|
|
26
|
+
<div className="grid grid-cols-2 gap-x-4 gap-y-1 rounded-sm border bg-background-upper p-4 font-mono text-sm">
|
|
27
|
+
{codes.map(code => <div key={code}>{code}</div>)}
|
|
28
|
+
</div>
|
|
29
|
+
<p className="text-sm text-gray-500">{dict.tenant.backupCodes.writeDownNote}</p>
|
|
30
|
+
</div>
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
export const BackupCodes = () => {
|
|
34
|
+
const identity = useIdentity()
|
|
35
|
+
const showToast = useShowToast()
|
|
36
|
+
const [codes, setCodes] = useState<readonly string[]>()
|
|
37
|
+
|
|
38
|
+
const person = identity?.person
|
|
39
|
+
if (!person) {
|
|
40
|
+
return null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (codes) {
|
|
44
|
+
return <BackupCodesDisplay codes={codes} />
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!(person.otpEnabled || person.emailOtpEnabled)) {
|
|
48
|
+
return <p>{dict.tenant.backupCodes.noMfaActive}</p>
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<>
|
|
53
|
+
<p>{dict.tenant.backupCodes.description}</p>
|
|
54
|
+
<AlertDialog>
|
|
55
|
+
<AlertDialogTrigger asChild>
|
|
56
|
+
<Button variant="destructive">{dict.tenant.backupCodes.regenerate}</Button>
|
|
57
|
+
</AlertDialogTrigger>
|
|
58
|
+
<AlertDialogContent>
|
|
59
|
+
<AlertDialogHeader>
|
|
60
|
+
<AlertDialogTitle>{dict.tenant.backupCodes.regenerate}</AlertDialogTitle>
|
|
61
|
+
<AlertDialogDescription>{dict.tenant.backupCodes.regenerateConfirm}</AlertDialogDescription>
|
|
62
|
+
</AlertDialogHeader>
|
|
63
|
+
<AlertDialogFooter>
|
|
64
|
+
<AlertDialogCancel>{dict.tenant.backupCodes.cancel}</AlertDialogCancel>
|
|
65
|
+
<RegenerateBackupCodesTrigger
|
|
66
|
+
onSuccess={({ result: { backupCodes } }) => {
|
|
67
|
+
setCodes(backupCodes)
|
|
68
|
+
showToast(<ToastContent>{dict.tenant.backupCodes.regenerateSuccess}</ToastContent>, { type: 'success' })
|
|
69
|
+
}}
|
|
70
|
+
onError={({ code }) => {
|
|
71
|
+
showToast(<ToastContent>{actionErrorMessage(code, dict.tenant.backupCodes.regenerateFailed)}</ToastContent>, { type: 'error' })
|
|
72
|
+
}}
|
|
73
|
+
>
|
|
74
|
+
<AlertDialogAction variant="destructive">{dict.tenant.backupCodes.regenerate}</AlertDialogAction>
|
|
75
|
+
</RegenerateBackupCodesTrigger>
|
|
76
|
+
</AlertDialogFooter>
|
|
77
|
+
</AlertDialogContent>
|
|
78
|
+
</AlertDialog>
|
|
79
|
+
</>
|
|
80
|
+
)
|
|
81
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import { DisableEmailOtpTrigger, EmailOtpConfirmForm, InitEmailOtpTrigger, useEmailOtpConfirmForm, useIdentity } from '@contember/interface'
|
|
3
|
+
import { Loader } from '~/lib'
|
|
4
|
+
import { Button } from '~/lib'
|
|
5
|
+
import {
|
|
6
|
+
AlertDialog,
|
|
7
|
+
AlertDialogAction,
|
|
8
|
+
AlertDialogCancel,
|
|
9
|
+
AlertDialogContent,
|
|
10
|
+
AlertDialogDescription,
|
|
11
|
+
AlertDialogFooter,
|
|
12
|
+
AlertDialogHeader,
|
|
13
|
+
AlertDialogTitle,
|
|
14
|
+
AlertDialogTrigger,
|
|
15
|
+
} from '~/lib'
|
|
16
|
+
import { TenantFormError, TenantFormField } from '../forms/common.js'
|
|
17
|
+
import { ToastContent, useShowToast } from '~/lib'
|
|
18
|
+
import { BackupCodesDisplay } from './backup-codes.js'
|
|
19
|
+
import { dict } from '../dict.js'
|
|
20
|
+
|
|
21
|
+
export const EmailOtpSetup = () => {
|
|
22
|
+
const identity = useIdentity()
|
|
23
|
+
const showToast = useShowToast()
|
|
24
|
+
const [confirming, setConfirming] = useState(false)
|
|
25
|
+
const [backupCodes, setBackupCodes] = useState<readonly string[]>()
|
|
26
|
+
|
|
27
|
+
const person = identity?.person
|
|
28
|
+
|
|
29
|
+
if (!person) {
|
|
30
|
+
return null
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const onInitSuccess = () => {
|
|
34
|
+
setConfirming(true)
|
|
35
|
+
showToast(<ToastContent>{dict.tenant.emailOtpSetup.codeSent}</ToastContent>, { type: 'success' })
|
|
36
|
+
}
|
|
37
|
+
const onInitError = () => {
|
|
38
|
+
showToast(<ToastContent>{dict.tenant.emailOtpSetup.initFailed}</ToastContent>, { type: 'error' })
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (confirming) {
|
|
42
|
+
return (
|
|
43
|
+
<EmailOtpConfirmForm
|
|
44
|
+
onSuccess={({ result: { backupCodes } }) => {
|
|
45
|
+
setConfirming(false)
|
|
46
|
+
setBackupCodes(backupCodes)
|
|
47
|
+
showToast(<ToastContent>{dict.tenant.emailOtpSetup.enabledSuccess}</ToastContent>, { type: 'success' })
|
|
48
|
+
}}
|
|
49
|
+
>
|
|
50
|
+
<form>
|
|
51
|
+
<EmailOtpConfirmFormFields />
|
|
52
|
+
</form>
|
|
53
|
+
</EmailOtpConfirmForm>
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (backupCodes) {
|
|
58
|
+
return <BackupCodesDisplay codes={backupCodes} />
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (person.emailOtpEnabled) {
|
|
62
|
+
return (
|
|
63
|
+
<>
|
|
64
|
+
<p>{dict.tenant.emailOtpSetup.emailOtpEnabled}</p>
|
|
65
|
+
<AlertDialog>
|
|
66
|
+
<AlertDialogTrigger asChild>
|
|
67
|
+
<Button variant="destructive">{dict.tenant.emailOtpSetup.disableEmailOtp}</Button>
|
|
68
|
+
</AlertDialogTrigger>
|
|
69
|
+
<AlertDialogContent>
|
|
70
|
+
<AlertDialogHeader>
|
|
71
|
+
<AlertDialogTitle>{dict.tenant.emailOtpSetup.disableEmailOtp}</AlertDialogTitle>
|
|
72
|
+
<AlertDialogDescription>{dict.tenant.emailOtpSetup.disableEmailOtpConfirm}</AlertDialogDescription>
|
|
73
|
+
</AlertDialogHeader>
|
|
74
|
+
<AlertDialogFooter>
|
|
75
|
+
<AlertDialogCancel>
|
|
76
|
+
{dict.tenant.emailOtpSetup.cancel}
|
|
77
|
+
</AlertDialogCancel>
|
|
78
|
+
<DisableEmailOtpTrigger
|
|
79
|
+
onSuccess={() => {
|
|
80
|
+
showToast(<ToastContent>{dict.tenant.emailOtpSetup.disabledSuccess}</ToastContent>, { type: 'success' })
|
|
81
|
+
}}
|
|
82
|
+
onError={() => {
|
|
83
|
+
showToast(<ToastContent>{dict.tenant.emailOtpSetup.disableFailed}</ToastContent>, { type: 'error' })
|
|
84
|
+
}}
|
|
85
|
+
>
|
|
86
|
+
<AlertDialogAction variant="destructive">
|
|
87
|
+
{dict.tenant.emailOtpSetup.disable}
|
|
88
|
+
</AlertDialogAction>
|
|
89
|
+
</DisableEmailOtpTrigger>
|
|
90
|
+
</AlertDialogFooter>
|
|
91
|
+
</AlertDialogContent>
|
|
92
|
+
</AlertDialog>
|
|
93
|
+
<InitEmailOtpTrigger onSuccess={onInitSuccess} onError={onInitError}>
|
|
94
|
+
<Button>{dict.tenant.emailOtpSetup.setupAgain}</Button>
|
|
95
|
+
</InitEmailOtpTrigger>
|
|
96
|
+
</>
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
return (
|
|
100
|
+
<>
|
|
101
|
+
<p>
|
|
102
|
+
{dict.tenant.emailOtpSetup.description}
|
|
103
|
+
</p>
|
|
104
|
+
<InitEmailOtpTrigger onSuccess={onInitSuccess} onError={onInitError}>
|
|
105
|
+
<Button>{dict.tenant.emailOtpSetup.sendCode}</Button>
|
|
106
|
+
</InitEmailOtpTrigger>
|
|
107
|
+
</>
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export const EmailOtpConfirmFormFields = () => {
|
|
112
|
+
const form = useEmailOtpConfirmForm()
|
|
113
|
+
return (
|
|
114
|
+
<div className="relative flex flex-col gap-2">
|
|
115
|
+
{form.state === 'success' || form.state === 'submitting' ? <Loader position="absolute" /> : null}
|
|
116
|
+
<TenantFormError form={form} messages={dict.tenant.emailOtpSetup.emailOtpConfirmFormErrorMessages} />
|
|
117
|
+
<TenantFormField
|
|
118
|
+
form={form}
|
|
119
|
+
messages={dict.tenant.emailOtpSetup.emailOtpConfirmFormErrorMessages}
|
|
120
|
+
field="otpToken"
|
|
121
|
+
type="text"
|
|
122
|
+
required
|
|
123
|
+
maxLength={6}
|
|
124
|
+
autoComplete="one-time-code"
|
|
125
|
+
>
|
|
126
|
+
{dict.tenant.emailOtpSetup.otpToken}
|
|
127
|
+
</TenantFormField>
|
|
128
|
+
<Button type="submit" className="w-full" disabled={form.state === 'submitting'}>
|
|
129
|
+
{dict.tenant.emailOtpSetup.confirm}
|
|
130
|
+
</Button>
|
|
131
|
+
</div>
|
|
132
|
+
)
|
|
133
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { DisableMyPasswordlessTrigger, EnableMyPasswordlessTrigger, useIdentity } from '@contember/interface'
|
|
2
|
+
import { Button } from '~/lib'
|
|
3
|
+
import { ToastContent, useShowToast } from '~/lib'
|
|
4
|
+
import { dict } from '../dict.js'
|
|
5
|
+
import { actionErrorMessage } from '../errors.js'
|
|
6
|
+
|
|
7
|
+
export const PasswordlessToggle = () => {
|
|
8
|
+
const identity = useIdentity()
|
|
9
|
+
const showToast = useShowToast()
|
|
10
|
+
|
|
11
|
+
const onError = ({ code }: { code: string }) => {
|
|
12
|
+
showToast(<ToastContent>{actionErrorMessage(code, dict.tenant.passwordlessToggle.toggleFailed)}</ToastContent>, { type: 'error' })
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const person = identity?.person
|
|
16
|
+
if (!person) {
|
|
17
|
+
return null
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Both flags come from the server, because the decision needs the tenant policy and reading the
|
|
21
|
+
// configuration is an admin permission. `passwordlessAvailable` is the effective state — the raw
|
|
22
|
+
// opt-in says nothing under an `always`/`never` policy — and `passwordlessSelfManaged` is whether
|
|
23
|
+
// the opt-in decides anything at all, so the toggle is not offered where it would change nothing.
|
|
24
|
+
if (!person.passwordlessSelfManaged) {
|
|
25
|
+
return (
|
|
26
|
+
<p>
|
|
27
|
+
{person.passwordlessAvailable
|
|
28
|
+
? dict.tenant.passwordlessToggle.enforcedEnabled
|
|
29
|
+
: dict.tenant.passwordlessToggle.enforcedDisabled}
|
|
30
|
+
</p>
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (person.passwordlessAvailable) {
|
|
35
|
+
return (
|
|
36
|
+
<>
|
|
37
|
+
<p>{dict.tenant.passwordlessToggle.descriptionEnabled}</p>
|
|
38
|
+
<DisableMyPasswordlessTrigger
|
|
39
|
+
onSuccess={() => {
|
|
40
|
+
showToast(<ToastContent>{dict.tenant.passwordlessToggle.disabledSuccess}</ToastContent>, { type: 'success' })
|
|
41
|
+
}}
|
|
42
|
+
onError={onError}
|
|
43
|
+
>
|
|
44
|
+
<Button variant="destructive">{dict.tenant.passwordlessToggle.disable}</Button>
|
|
45
|
+
</DisableMyPasswordlessTrigger>
|
|
46
|
+
</>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<>
|
|
52
|
+
<p>{dict.tenant.passwordlessToggle.descriptionDisabled}</p>
|
|
53
|
+
<EnableMyPasswordlessTrigger
|
|
54
|
+
onSuccess={() => {
|
|
55
|
+
showToast(<ToastContent>{dict.tenant.passwordlessToggle.enabledSuccess}</ToastContent>, { type: 'success' })
|
|
56
|
+
}}
|
|
57
|
+
onError={onError}
|
|
58
|
+
>
|
|
59
|
+
<Button>{dict.tenant.passwordlessToggle.enable}</Button>
|
|
60
|
+
</EnableMyPasswordlessTrigger>
|
|
61
|
+
</>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { ReactNode, useCallback } 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 { useMySessionsQuery, usePersonSessionsQuery, useTenantQueryLoader } from '@contember/react-client-tenant'
|
|
24
|
+
import { RevokeSessionTrigger } from '@contember/interface'
|
|
25
|
+
import { dict } from '../dict.js'
|
|
26
|
+
import { actionErrorMessage } from '../errors.js'
|
|
27
|
+
|
|
28
|
+
const formatDateTime = (value?: string | null): ReactNode => {
|
|
29
|
+
if (!value) {
|
|
30
|
+
return <span className="text-gray-400 italic">{dict.tenant.sessionList.never}</span>
|
|
31
|
+
}
|
|
32
|
+
return new Date(value).toLocaleString()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface SessionListController {
|
|
36
|
+
refresh: () => void
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface SessionListProps {
|
|
40
|
+
personId?: string
|
|
41
|
+
controller?: { current?: SessionListController }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const SessionList = ({ personId, controller }: SessionListProps) => {
|
|
45
|
+
const mySessionsQuery = useMySessionsQuery()
|
|
46
|
+
const personSessionsQuery = usePersonSessionsQuery()
|
|
47
|
+
const fetcher = useCallback((variables: { personId?: string }) => (
|
|
48
|
+
variables.personId ? personSessionsQuery({ personId: variables.personId }) : mySessionsQuery({})
|
|
49
|
+
), [mySessionsQuery, personSessionsQuery])
|
|
50
|
+
|
|
51
|
+
const [query, { refresh }] = useTenantQueryLoader(fetcher, { personId })
|
|
52
|
+
if (controller) {
|
|
53
|
+
controller.current = { refresh }
|
|
54
|
+
}
|
|
55
|
+
const showToast = useShowToast()
|
|
56
|
+
|
|
57
|
+
const onRevoked = () => {
|
|
58
|
+
refresh()
|
|
59
|
+
showToast(<ToastContent>{dict.tenant.sessionList.revokeSuccess}</ToastContent>, { type: 'success' })
|
|
60
|
+
}
|
|
61
|
+
const onRevokeError = ({ code }: { code: string }) => {
|
|
62
|
+
showToast(<ToastContent>{actionErrorMessage(code, dict.tenant.sessionList.revokeFailed)}</ToastContent>, { type: 'error' })
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Revoking is self-service only: `revokeSession` refuses a session that is not the caller's own, so
|
|
66
|
+
// in the admin view the button would be one that always fails. `ForceSignOutPersonAction` is the
|
|
67
|
+
// admin equivalent, and `PersonDetail` already offers it.
|
|
68
|
+
const canRevoke = personId === undefined
|
|
69
|
+
|
|
70
|
+
if (query.state === 'error') {
|
|
71
|
+
return <div className="text-destructive italic">{dict.tenant.sessionList.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.sessionList.created}</TableHead>
|
|
80
|
+
<TableHead>{dict.tenant.sessionList.lastUsed}</TableHead>
|
|
81
|
+
<TableHead>{dict.tenant.sessionList.ip}</TableHead>
|
|
82
|
+
<TableHead>{dict.tenant.sessionList.userAgent}</TableHead>
|
|
83
|
+
<TableHead>{dict.tenant.sessionList.expires}</TableHead>
|
|
84
|
+
<TableHead className="w-24">
|
|
85
|
+
<div className="flex gap-2 items-center">
|
|
86
|
+
{canRevoke && <span>{dict.tenant.sessionList.action}</span>}
|
|
87
|
+
<Button variant="outline" onClick={refresh} className="ml-auto" size="sm">
|
|
88
|
+
<RefreshCwIcon className="w-3 h-3" />
|
|
89
|
+
</Button>
|
|
90
|
+
</div>
|
|
91
|
+
</TableHead>
|
|
92
|
+
</TableRow>
|
|
93
|
+
</TableHeader>
|
|
94
|
+
{'data' in query && query.data.length === 0 && (
|
|
95
|
+
<TableRow>
|
|
96
|
+
<TableCell colSpan={6}>{dict.tenant.sessionList.noResults}</TableCell>
|
|
97
|
+
</TableRow>
|
|
98
|
+
)}
|
|
99
|
+
{'data' in query && query.data.map(session => (
|
|
100
|
+
<TableRow key={session.id}>
|
|
101
|
+
<TableCell className="whitespace-nowrap">{formatDateTime(session.createdAt)}</TableCell>
|
|
102
|
+
<TableCell className="whitespace-nowrap">{formatDateTime(session.lastUsedAt)}</TableCell>
|
|
103
|
+
<TableCell className="whitespace-nowrap">{session.lastIp ?? session.createdIp}</TableCell>
|
|
104
|
+
<TableCell className="max-w-xs truncate" title={session.lastUserAgent ?? session.createdUserAgent ?? ''}>
|
|
105
|
+
{session.lastUserAgent ?? session.createdUserAgent}
|
|
106
|
+
</TableCell>
|
|
107
|
+
<TableCell className="whitespace-nowrap">{formatDateTime(session.expiresAt)}</TableCell>
|
|
108
|
+
<TableCell className="whitespace-nowrap">
|
|
109
|
+
{canRevoke && (session.isCurrent
|
|
110
|
+
? <span className="text-gray-500 italic">{dict.tenant.sessionList.thisDevice}</span>
|
|
111
|
+
: <RevokeSessionDialog sessionId={session.id} onSuccess={onRevoked} onError={onRevokeError} />)}
|
|
112
|
+
</TableCell>
|
|
113
|
+
</TableRow>
|
|
114
|
+
))}
|
|
115
|
+
</Table>
|
|
116
|
+
</div>
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const RevokeSessionDialog = (
|
|
121
|
+
{ sessionId, onSuccess, onError }: { sessionId: string; onSuccess: () => void; onError: (args: { code: string }) => void },
|
|
122
|
+
) => {
|
|
123
|
+
return (
|
|
124
|
+
<AlertDialog>
|
|
125
|
+
<AlertDialogTrigger asChild>
|
|
126
|
+
<Button variant="destructive">
|
|
127
|
+
<BanIcon className="w-3 h-3" />
|
|
128
|
+
</Button>
|
|
129
|
+
</AlertDialogTrigger>
|
|
130
|
+
<AlertDialogContent>
|
|
131
|
+
<AlertDialogHeader>
|
|
132
|
+
<AlertDialogTitle>{dict.tenant.sessionList.revokeConfirmation}</AlertDialogTitle>
|
|
133
|
+
</AlertDialogHeader>
|
|
134
|
+
<AlertDialogFooter>
|
|
135
|
+
<AlertDialogCancel>{dict.tenant.sessionList.cancel}</AlertDialogCancel>
|
|
136
|
+
<RevokeSessionTrigger sessionId={sessionId} onSuccess={onSuccess} onError={onError}>
|
|
137
|
+
<AlertDialogAction variant="destructive">{dict.tenant.sessionList.revoke}</AlertDialogAction>
|
|
138
|
+
</RevokeSessionTrigger>
|
|
139
|
+
</AlertDialogFooter>
|
|
140
|
+
</AlertDialogContent>
|
|
141
|
+
</AlertDialog>
|
|
142
|
+
)
|
|
143
|
+
}
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"@contember/react-block-repeater": "{version}",
|
|
26
26
|
"@contember/react-board": "{version}",
|
|
27
27
|
"@contember/react-board-dnd-kit": "{version}",
|
|
28
|
+
"@contember/react-client": "{version}",
|
|
28
29
|
"@contember/react-dataview": "{version}",
|
|
29
30
|
"@contember/react-form": "{version}",
|
|
30
31
|
"@contember/react-repeater": "{version}",
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Local object storage (SeaweedFS)
|
|
2
|
+
|
|
3
|
+
`identities.json` is the `-s3.config` file for the `object-storage` service in
|
|
4
|
+
`docker-compose.yaml`. JSON carries no comments, so the two identities are explained here.
|
|
5
|
+
|
|
6
|
+
- **`anonymous`** — the unauthenticated caller. `Read:contember` makes exactly one bucket publicly
|
|
7
|
+
readable, which is what the Contember engine's asset bucket needs: `generateUploadUrl` hands the
|
|
8
|
+
browser a `publicUrl` with no credentials on it. Any other bucket added to `S3_BUCKET` stays
|
|
9
|
+
private until it is listed here as well.
|
|
10
|
+
- **`contember`** — the credentials the engine signs upload and read URLs with
|
|
11
|
+
(`DEFAULT_S3_KEY` / `DEFAULT_S3_SECRET`). Local dev only; a deployed environment holds its own.
|
|
12
|
+
|
|
13
|
+
Buckets are not declared here; the service creates them from `S3_BUCKET` on start.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"identities": [
|
|
3
|
+
{
|
|
4
|
+
"name": "anonymous",
|
|
5
|
+
"actions": ["Read:contember"]
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
"name": "contember",
|
|
9
|
+
"credentials": [{ "accessKey": "contember", "secretKey": "contember" }],
|
|
10
|
+
"actions": ["Admin", "Read", "Write", "List", "Tagging"]
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
}
|