@contember/create 2.2.0-alpha.3 → 2.2.0-alpha.5
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 +443 -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,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
|
+
}
|
|
@@ -18,11 +18,15 @@ services:
|
|
|
18
18
|
DEFAULT_DB_USER: 'contember'
|
|
19
19
|
DEFAULT_DB_PASSWORD: 'contember'
|
|
20
20
|
|
|
21
|
+
# The host port, not the service name: the engine only signs URLs here and hands them to the
|
|
22
|
+
# browser, which resolves them itself.
|
|
21
23
|
DEFAULT_S3_ENDPOINT: 'http://localhost:1483'
|
|
22
24
|
DEFAULT_S3_BUCKET: 'contember'
|
|
23
25
|
DEFAULT_S3_REGION: ''
|
|
24
26
|
DEFAULT_S3_KEY: 'contember'
|
|
25
27
|
DEFAULT_S3_SECRET: 'contember'
|
|
28
|
+
# A Contember provider name, not the image behind `object-storage`: it selects path-style
|
|
29
|
+
# addressing and no object ACL (public read comes from the store's own config instead).
|
|
26
30
|
DEFAULT_S3_PROVIDER: 'minio'
|
|
27
31
|
|
|
28
32
|
TENANT_MAILER_HOST: 'mailhog'
|
|
@@ -81,19 +85,37 @@ services:
|
|
|
81
85
|
timeout: 5s
|
|
82
86
|
retries: 10
|
|
83
87
|
|
|
84
|
-
|
|
85
|
-
image:
|
|
88
|
+
object-storage:
|
|
89
|
+
image: chrislusf/seaweedfs:4.42
|
|
90
|
+
|
|
91
|
+
# `mini` runs master + volume + filer + S3 in a single process. Both flags override a default
|
|
92
|
+
# that would bite you: `autoCreateBucket` is on by default and silently creates a bucket on the
|
|
93
|
+
# first write, so a typo would look like a working upload, and telemetry is on by default and
|
|
94
|
+
# reports to telemetry.seaweedfs.com every 24 h.
|
|
95
|
+
command: >
|
|
96
|
+
mini -dir=/data -s3.port=9000 -s3.config=/etc/seaweedfs/identities.json
|
|
97
|
+
-s3.autoCreateBucket=false -master.telemetry=false
|
|
86
98
|
|
|
87
99
|
environment:
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
100
|
+
# Created on start, an existing one left alone. Public read and the signing credentials live
|
|
101
|
+
# in the identities file — see docker/object-storage/README.md.
|
|
102
|
+
S3_BUCKET: 'contember'
|
|
91
103
|
|
|
92
104
|
ports:
|
|
93
105
|
- '1483:9000'
|
|
94
106
|
|
|
95
107
|
volumes:
|
|
96
|
-
-
|
|
108
|
+
- object-storage-data:/data
|
|
109
|
+
- ./docker/object-storage/identities.json:/etc/seaweedfs/identities.json:ro
|
|
110
|
+
|
|
111
|
+
# The S3 port starts answering ~0.5 s before the bucket exists, so probing it (or `/healthz`)
|
|
112
|
+
# would report ready while an upload still fails with `NoSuchBucket`. The filer 404s on a bucket
|
|
113
|
+
# that isn't there yet, so ask it instead.
|
|
114
|
+
healthcheck:
|
|
115
|
+
test: [ 'CMD-SHELL', 'curl -fsS -o /dev/null "http://127.0.0.1:8888/buckets/contember/?limit=1"' ]
|
|
116
|
+
interval: 2s
|
|
117
|
+
timeout: 3s
|
|
118
|
+
retries: 30
|
|
97
119
|
|
|
98
120
|
mailhog:
|
|
99
121
|
image: mailhog/mailhog
|
|
@@ -121,4 +143,4 @@ services:
|
|
|
121
143
|
|
|
122
144
|
volumes:
|
|
123
145
|
pgsql-data: ~
|
|
124
|
-
|
|
146
|
+
object-storage-data: ~
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Command, CommandConfiguration, Input } from '@contember/cli-common'
|
|
1
|
+
import { Command, CommandConfiguration, escapeTerminalText, Input, Output } from '@contember/cli-common'
|
|
2
2
|
import { join } from 'node:path'
|
|
3
3
|
import chalk from 'chalk'
|
|
4
4
|
import { TemplateInstaller } from '../lib/TemplateInstaller.js'
|
|
@@ -13,9 +13,29 @@ type Options = {
|
|
|
13
13
|
template: string
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
export interface WorkspaceCreateResult {
|
|
17
|
+
projectName: string
|
|
18
|
+
projectDirectory: string
|
|
19
|
+
template: string
|
|
20
|
+
packageManager: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface WorkspaceCreateRuntime {
|
|
24
|
+
cwd(): string
|
|
25
|
+
getPackageVersion(): Promise<string>
|
|
26
|
+
detectPackageManager(): string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const defaultRuntime: WorkspaceCreateRuntime = {
|
|
30
|
+
cwd: () => process.cwd(),
|
|
31
|
+
getPackageVersion,
|
|
32
|
+
detectPackageManager,
|
|
33
|
+
}
|
|
34
|
+
|
|
16
35
|
export class WorkspaceCreateCommand extends Command<Args, Options> {
|
|
17
36
|
constructor(
|
|
18
|
-
private readonly templateInstaller: TemplateInstaller,
|
|
37
|
+
private readonly templateInstaller: Pick<TemplateInstaller, 'installTemplate'>,
|
|
38
|
+
private readonly runtime: WorkspaceCreateRuntime = defaultRuntime,
|
|
19
39
|
) {
|
|
20
40
|
super()
|
|
21
41
|
}
|
|
@@ -26,35 +46,43 @@ export class WorkspaceCreateCommand extends Command<Args, Options> {
|
|
|
26
46
|
configuration.option('template').shortcut('t').valueRequired().description('Template name or remote source')
|
|
27
47
|
}
|
|
28
48
|
|
|
29
|
-
protected async execute(input: Input<Args, Options
|
|
49
|
+
protected async execute(input: Input<Args, Options>, output: Output): Promise<void> {
|
|
30
50
|
const projectName = input.getArgument('projectName')
|
|
31
|
-
const projectDirectory = join(
|
|
32
|
-
const packageManager = detectPackageManager()
|
|
51
|
+
const projectDirectory = join(this.runtime.cwd(), projectName)
|
|
52
|
+
const packageManager = this.runtime.detectPackageManager()
|
|
33
53
|
const template = input.getOption('template') ?? 'default'
|
|
34
54
|
|
|
35
55
|
await this.templateInstaller.installTemplate(template, projectDirectory, {
|
|
36
|
-
version: await getPackageVersion(),
|
|
56
|
+
version: await this.runtime.getPackageVersion(),
|
|
37
57
|
projectName: projectName,
|
|
38
58
|
packageManager: packageManager,
|
|
39
59
|
})
|
|
40
60
|
|
|
41
|
-
|
|
61
|
+
const result: WorkspaceCreateResult = { projectName, projectDirectory, template, packageManager }
|
|
62
|
+
output.data(result, {
|
|
63
|
+
human: value => createDocs(value),
|
|
64
|
+
quiet: value => value.projectDirectory,
|
|
65
|
+
})
|
|
42
66
|
}
|
|
43
67
|
}
|
|
44
68
|
|
|
45
|
-
const createDocs = (projectDirectory
|
|
46
|
-
|
|
69
|
+
const createDocs = ({ projectDirectory, projectName, packageManager }: WorkspaceCreateResult) => {
|
|
70
|
+
const safeProjectDirectory = escapeTerminalText(projectDirectory)
|
|
71
|
+
const safeProjectName = escapeTerminalText(projectName)
|
|
72
|
+
const safePackageManager = escapeTerminalText(packageManager)
|
|
73
|
+
return `
|
|
74
|
+
Contember project successfully created in ${safeProjectDirectory}
|
|
47
75
|
|
|
48
76
|
Next steps:
|
|
49
77
|
|
|
50
78
|
1. Navigate to the project directory:
|
|
51
|
-
$ ${chalk.green(`cd ${
|
|
79
|
+
$ ${chalk.green(`cd ${safeProjectName}`)}
|
|
52
80
|
|
|
53
81
|
2. Install dependencies:
|
|
54
|
-
$ ${chalk.green(`${
|
|
82
|
+
$ ${chalk.green(`${safePackageManager} install`)}
|
|
55
83
|
|
|
56
84
|
3. Start the Contember stack:
|
|
57
|
-
$ ${chalk.green(`${
|
|
85
|
+
$ ${chalk.green(`${safePackageManager} start`)}
|
|
58
86
|
|
|
59
87
|
Available services:
|
|
60
88
|
|
|
@@ -67,10 +95,10 @@ ${chalk.bold('API & Backend')}
|
|
|
67
95
|
|
|
68
96
|
${chalk.bold('Development Tools')}
|
|
69
97
|
- PostgreSQL database ${chalk.blue('http://localhost:1482')} ${chalk.grey('credentials: contember / contember')}
|
|
70
|
-
-
|
|
98
|
+
- S3 object storage ${chalk.blue('http://localhost:1483')} ${chalk.grey('credentials: contember / contember')}
|
|
71
99
|
- Mailpit SMTP testing ${chalk.blue('http://localhost:1484')}
|
|
72
100
|
- Adminer DB manager ${chalk.blue('http://localhost:1485')}
|
|
73
|
-
- Minio Dashboard ${chalk.blue('http://localhost:1486')} ${chalk.grey('credentials: contember / contember')}
|
|
74
101
|
|
|
75
102
|
${chalk.bold('Need help?')} Ask the community: https://github.com/orgs/contember/discussions
|
|
76
103
|
`
|
|
104
|
+
}
|