@contember/create 2.2.0-alpha.3 → 2.2.0-alpha.4
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
|
@@ -4,12 +4,16 @@ import { Input } from '~/lib'
|
|
|
4
4
|
import { HTMLInputTypeAttribute, useState } from 'react'
|
|
5
5
|
import { dataAttribute } from '@contember/utilities'
|
|
6
6
|
import { Label } from '~/lib'
|
|
7
|
+
import { dict } from '../dict.js'
|
|
7
8
|
|
|
8
|
-
type FormErrorMessages<CtxValue extends FormContextValue<any, any, any>> = Record<
|
|
9
|
+
export type FormErrorMessages<CtxValue extends FormContextValue<any, any, any>> = Record<
|
|
9
10
|
(CtxValue extends FormContextValue<any, infer E> ? E : never) & string,
|
|
10
11
|
string | undefined
|
|
11
12
|
>
|
|
12
13
|
|
|
14
|
+
/** Codes any form can raise, so a per-form dict does not have to carry them. It still wins if it does. */
|
|
15
|
+
const commonErrorMessages: Partial<Record<string, string>> = dict.tenant.commonErrorMessages
|
|
16
|
+
|
|
13
17
|
export interface TenantFormErrorsProps<CtxValue extends FormContextValue<any, any, any>> {
|
|
14
18
|
form: CtxValue
|
|
15
19
|
field?: keyof CtxValue['values']
|
|
@@ -22,7 +26,10 @@ export const TenantFormError = <CtxValue extends FormContextValue<any, any, any>
|
|
|
22
26
|
{form.errors
|
|
23
27
|
.filter(error => error.field === field)
|
|
24
28
|
.filter(it => !(it.code in messages && ((messages as any)[it.code] === undefined)))
|
|
25
|
-
.map(error => [error.code, {
|
|
29
|
+
.map(error => [error.code, {
|
|
30
|
+
error: (messages as any)[error.code] || commonErrorMessages[error.code] || 'Unknown error',
|
|
31
|
+
developerMessage: error.developerMessage,
|
|
32
|
+
}])
|
|
26
33
|
.map(([code, error]) => {
|
|
27
34
|
return <TenantFormSingleError key={code} {...error} />
|
|
28
35
|
})}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { useCreateGlobalApiKeyForm } from '@contember/react-identity'
|
|
2
|
+
import { Button, Input, Loader } from '~/lib'
|
|
3
|
+
import { PlusIcon, XIcon } from 'lucide-react'
|
|
4
|
+
import { TenantFormError, TenantFormField, TenantFormLabel } from './common.js'
|
|
5
|
+
import { dict } from '../dict.js'
|
|
6
|
+
|
|
7
|
+
export const CreateGlobalApiKeyFormFields = () => {
|
|
8
|
+
const form = useCreateGlobalApiKeyForm()
|
|
9
|
+
const roles = form.values.roles
|
|
10
|
+
return (
|
|
11
|
+
<div className="relative flex flex-col gap-2">
|
|
12
|
+
{form.state === 'submitting' ? <Loader position="absolute" /> : null}
|
|
13
|
+
|
|
14
|
+
<TenantFormError
|
|
15
|
+
form={form}
|
|
16
|
+
messages={dict.tenant.createGlobalApiKey.errorMessages}
|
|
17
|
+
/>
|
|
18
|
+
|
|
19
|
+
<TenantFormField
|
|
20
|
+
form={form}
|
|
21
|
+
messages={dict.tenant.createGlobalApiKey.errorMessages}
|
|
22
|
+
field="description"
|
|
23
|
+
type="text"
|
|
24
|
+
required
|
|
25
|
+
autoFocus
|
|
26
|
+
>
|
|
27
|
+
{dict.tenant.createGlobalApiKey.description}
|
|
28
|
+
</TenantFormField>
|
|
29
|
+
|
|
30
|
+
<TenantFormLabel form={form} field="roles">{dict.tenant.createGlobalApiKey.roles}</TenantFormLabel>
|
|
31
|
+
<div className="flex flex-col gap-2">
|
|
32
|
+
{roles.map((role, index) => (
|
|
33
|
+
<div key={index} className="flex gap-2 items-center">
|
|
34
|
+
<Input
|
|
35
|
+
type="text"
|
|
36
|
+
value={role}
|
|
37
|
+
placeholder={dict.tenant.createGlobalApiKey.rolePlaceholder}
|
|
38
|
+
onChange={e => form.setValue('roles', roles.map((it, i) => i === index ? e.target.value : it))}
|
|
39
|
+
/>
|
|
40
|
+
<Button
|
|
41
|
+
type="button"
|
|
42
|
+
variant="outline"
|
|
43
|
+
onClick={() => form.setValue('roles', roles.filter((_, i) => i !== index))}
|
|
44
|
+
>
|
|
45
|
+
<XIcon className="w-4 h-4" />
|
|
46
|
+
<span className="sr-only">{dict.tenant.createGlobalApiKey.removeRole}</span>
|
|
47
|
+
</Button>
|
|
48
|
+
</div>
|
|
49
|
+
))}
|
|
50
|
+
<div>
|
|
51
|
+
<Button
|
|
52
|
+
type="button"
|
|
53
|
+
variant="outline"
|
|
54
|
+
className="flex gap-2"
|
|
55
|
+
onClick={() => form.setValue('roles', [...roles, ''])}
|
|
56
|
+
>
|
|
57
|
+
<PlusIcon className="w-4 h-4" />
|
|
58
|
+
{dict.tenant.createGlobalApiKey.addRole}
|
|
59
|
+
</Button>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
<TenantFormError form={form} messages={dict.tenant.createGlobalApiKey.errorMessages} field="roles" />
|
|
63
|
+
|
|
64
|
+
<Button type="submit" className="w-full" disabled={form.state === 'submitting'}>
|
|
65
|
+
{dict.tenant.createGlobalApiKey.submit}
|
|
66
|
+
</Button>
|
|
67
|
+
</div>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
import { Button, Input, ToastContent, useShowToast } from '~/lib'
|
|
4
|
+
import { PlusIcon, XIcon } from 'lucide-react'
|
|
5
|
+
import { toFormErrorCode, useAddGlobalIdentityRolesMutation, useRemoveGlobalIdentityRolesMutation } from '@contember/react-client-tenant'
|
|
6
|
+
import { AddGlobalIdentityRolesErrorCode, RemoveGlobalIdentityRolesErrorCode } from '@contember/graphql-client-tenant'
|
|
7
|
+
import { dict } from '../dict.js'
|
|
8
|
+
import { actionErrorMessage } from '../errors.js'
|
|
9
|
+
|
|
10
|
+
export interface GlobalRolesControlProps {
|
|
11
|
+
identityId: string
|
|
12
|
+
roles: readonly string[]
|
|
13
|
+
onChange?: () => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* `GlobalRolesControl` manages the global (tenant-wide) roles of an identity.
|
|
18
|
+
*
|
|
19
|
+
* ## Example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* <GlobalRolesControl identityId={person.identity.id} roles={person.identity.roles ?? []} onChange={refresh} />
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export const GlobalRolesControl = ({ identityId, roles, onChange }: GlobalRolesControlProps) => {
|
|
25
|
+
const addRoles = useAddGlobalIdentityRolesMutation()
|
|
26
|
+
const removeRoles = useRemoveGlobalIdentityRolesMutation()
|
|
27
|
+
const showToast = useShowToast()
|
|
28
|
+
const [newRole, setNewRole] = useState('')
|
|
29
|
+
const [submitting, setSubmitting] = useState(false)
|
|
30
|
+
|
|
31
|
+
const onError = (code: AddGlobalIdentityRolesErrorCode | RemoveGlobalIdentityRolesErrorCode | undefined) => {
|
|
32
|
+
const message = (code && dict.tenant.globalRoles.errorMessages[code]) ?? dict.tenant.globalRoles.errorMessages.UNKNOWN_ERROR
|
|
33
|
+
showToast(<ToastContent>{message}</ToastContent>, { type: 'error' })
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const onThrown = (error: unknown) => {
|
|
37
|
+
const message = actionErrorMessage(toFormErrorCode(error), dict.tenant.globalRoles.errorMessages.UNKNOWN_ERROR)
|
|
38
|
+
showToast(<ToastContent>{message}</ToastContent>, { type: 'error' })
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const onAdd = async () => {
|
|
42
|
+
const role = newRole.trim()
|
|
43
|
+
if (!role) {
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
setSubmitting(true)
|
|
47
|
+
try {
|
|
48
|
+
const result = await addRoles({ identityId, roles: [role] })
|
|
49
|
+
if (result.ok) {
|
|
50
|
+
setNewRole('')
|
|
51
|
+
showToast(<ToastContent>{dict.tenant.globalRoles.addSuccess}</ToastContent>, { type: 'success' })
|
|
52
|
+
} else {
|
|
53
|
+
onError(result.error)
|
|
54
|
+
}
|
|
55
|
+
} catch (error) {
|
|
56
|
+
// A denied mutation throws rather than answering `ok: false` — without this the control
|
|
57
|
+
// would stay disabled forever with nothing said. Reachable: a project admin cannot grant
|
|
58
|
+
// a global role, and `PersonDetail` renders this for them.
|
|
59
|
+
onThrown(error)
|
|
60
|
+
} finally {
|
|
61
|
+
setSubmitting(false)
|
|
62
|
+
}
|
|
63
|
+
onChange?.()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const onRemove = async (role: string) => {
|
|
67
|
+
setSubmitting(true)
|
|
68
|
+
try {
|
|
69
|
+
const result = await removeRoles({ identityId, roles: [role] })
|
|
70
|
+
if (result.ok) {
|
|
71
|
+
showToast(<ToastContent>{dict.tenant.globalRoles.removeSuccess}</ToastContent>, { type: 'success' })
|
|
72
|
+
} else {
|
|
73
|
+
onError(result.error)
|
|
74
|
+
}
|
|
75
|
+
} catch (error) {
|
|
76
|
+
onThrown(error)
|
|
77
|
+
} finally {
|
|
78
|
+
setSubmitting(false)
|
|
79
|
+
}
|
|
80
|
+
onChange?.()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<div className="flex flex-col gap-2">
|
|
85
|
+
<div className="flex gap-2 flex-wrap items-center">
|
|
86
|
+
{roles.length === 0 && <span className="text-gray-400 italic">{dict.tenant.globalRoles.noRoles}</span>}
|
|
87
|
+
{roles.map(role => (
|
|
88
|
+
<span key={role} className="inline-flex items-center gap-1 border border-gray-200 rounded-sm pl-2 py-0.5 text-sm">
|
|
89
|
+
{role}
|
|
90
|
+
<Button type="button" variant="ghost" size="xs" disabled={submitting} onClick={() => onRemove(role)}>
|
|
91
|
+
<XIcon className="w-3 h-3" />
|
|
92
|
+
<span className="sr-only">{dict.tenant.globalRoles.removeRole}</span>
|
|
93
|
+
</Button>
|
|
94
|
+
</span>
|
|
95
|
+
))}
|
|
96
|
+
</div>
|
|
97
|
+
<div className="flex gap-2 items-center">
|
|
98
|
+
{/* The tenant API cannot enumerate the roles defined in the config, so a new role is entered as free text. */}
|
|
99
|
+
<Input
|
|
100
|
+
type="text"
|
|
101
|
+
value={newRole}
|
|
102
|
+
placeholder={dict.tenant.globalRoles.rolePlaceholder}
|
|
103
|
+
disabled={submitting}
|
|
104
|
+
onChange={e => setNewRole(e.target.value)}
|
|
105
|
+
/>
|
|
106
|
+
<Button type="button" variant="outline" className="flex gap-2" disabled={submitting || !newRole.trim()} onClick={onAdd}>
|
|
107
|
+
<PlusIcon className="w-4 h-4" />
|
|
108
|
+
{dict.tenant.globalRoles.addRole}
|
|
109
|
+
</Button>
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
112
|
+
)
|
|
113
|
+
}
|
|
@@ -1,12 +1,23 @@
|
|
|
1
|
+
export * from './add-project-member.js'
|
|
1
2
|
export * from './change-my-password.js'
|
|
3
|
+
export * from './change-my-profile.js'
|
|
4
|
+
export * from './change-profile.js'
|
|
2
5
|
export * from './common.js'
|
|
3
6
|
export * from './confirm-email-change.js'
|
|
4
7
|
export * from './create-api-key.js'
|
|
8
|
+
export * from './create-global-api-key.js'
|
|
9
|
+
export * from './global-roles-control.js'
|
|
5
10
|
export * from './invite.js'
|
|
6
11
|
export * from './login.js'
|
|
7
12
|
export * from './memberships-control.js'
|
|
13
|
+
export * from './mfa-code-fields.js'
|
|
8
14
|
export * from './password-reset.js'
|
|
9
15
|
export * from './password-reset-request.js'
|
|
16
|
+
export * from './passwordless-signin.js'
|
|
17
|
+
export * from './passwordless-signin-init.js'
|
|
10
18
|
export * from './request-email-verification.js'
|
|
19
|
+
export * from './set-person-password.js'
|
|
20
|
+
export * from './set-project-secret.js'
|
|
21
|
+
export * from './sign-up.js'
|
|
11
22
|
export * from './update-project-member.js'
|
|
12
23
|
export * from './verify-email.js'
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
import { InviteFormErrorCode, useInviteForm } from '@contember/react-identity'
|
|
2
|
-
import { Button } from '~/lib'
|
|
2
|
+
import { Button, CheckboxInput } from '~/lib'
|
|
3
3
|
import { Loader } from '~/lib'
|
|
4
4
|
import { TenantFormError, TenantFormField, TenantFormLabel } from './common.js'
|
|
5
5
|
import { MembershipsControl, RolesConfig, useIntrospectionRolesConfig } from './memberships-control.js'
|
|
6
6
|
import { dict } from '../dict.js'
|
|
7
7
|
|
|
8
|
-
export
|
|
8
|
+
export interface InviteFormFieldsProps {
|
|
9
|
+
projectSlug: string
|
|
10
|
+
roles?: RolesConfig
|
|
11
|
+
/**
|
|
12
|
+
* Offers the "do not send an invitation e-mail" checkbox and the password
|
|
13
|
+
* field it reveals. Must be paired with `allowUnmanaged` on `InviteForm`;
|
|
14
|
+
* without it the form still mails.
|
|
15
|
+
*/
|
|
16
|
+
allowUnmanaged?: boolean
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const InviteFormFields = ({ projectSlug, roles, allowUnmanaged }: InviteFormFieldsProps) => {
|
|
9
20
|
const form = useInviteForm()
|
|
10
|
-
|
|
21
|
+
// See `add-project-member.tsx`: the hook must not sit behind `??`.
|
|
22
|
+
const introspectedRoles = useIntrospectionRolesConfig(projectSlug)
|
|
23
|
+
const rolesResolved = roles ?? introspectedRoles
|
|
11
24
|
return (
|
|
12
25
|
<div className="relative flex flex-col gap-2">
|
|
13
26
|
{form.state === 'submitting' ? <Loader position="absolute" /> : null}
|
|
@@ -45,8 +58,33 @@ export const InviteFormFields = ({ projectSlug, roles }: { projectSlug: string;
|
|
|
45
58
|
roles={rolesResolved}
|
|
46
59
|
/>
|
|
47
60
|
|
|
61
|
+
{allowUnmanaged && (
|
|
62
|
+
<>
|
|
63
|
+
<label className="flex items-center gap-2 mt-2">
|
|
64
|
+
<CheckboxInput
|
|
65
|
+
checked={form.values.unmanaged}
|
|
66
|
+
onChange={e => form.setValue('unmanaged', e.target.checked)}
|
|
67
|
+
/>
|
|
68
|
+
<span className="text-sm">{dict.tenant.invite.unmanaged}</span>
|
|
69
|
+
</label>
|
|
70
|
+
<p className="text-sm text-gray-500">{dict.tenant.invite.unmanagedDescription}</p>
|
|
71
|
+
|
|
72
|
+
{form.values.unmanaged && (
|
|
73
|
+
<TenantFormField
|
|
74
|
+
form={form}
|
|
75
|
+
messages={dict.tenant.invite.errorMessages}
|
|
76
|
+
field="password"
|
|
77
|
+
type="password"
|
|
78
|
+
autoComplete="new-password"
|
|
79
|
+
>
|
|
80
|
+
{dict.tenant.invite.password}
|
|
81
|
+
</TenantFormField>
|
|
82
|
+
)}
|
|
83
|
+
</>
|
|
84
|
+
)}
|
|
85
|
+
|
|
48
86
|
<Button type="submit" className="w-full" disabled={form.state === 'submitting'}>
|
|
49
|
-
{dict.tenant.invite.submit}
|
|
87
|
+
{allowUnmanaged && form.values.unmanaged ? dict.tenant.invite.submitUnmanaged : dict.tenant.invite.submit}
|
|
50
88
|
</Button>
|
|
51
89
|
</div>
|
|
52
90
|
)
|
|
@@ -4,6 +4,7 @@ import { Loader } from '~/lib'
|
|
|
4
4
|
import { TenantFormError, TenantFormField } from './common.js'
|
|
5
5
|
import { dict } from '../dict.js'
|
|
6
6
|
import { Link } from '@contember/interface'
|
|
7
|
+
import { MfaCodeFields } from './mfa-code-fields.js'
|
|
7
8
|
|
|
8
9
|
export const LoginFormFields = () => {
|
|
9
10
|
const form = useLoginForm()
|
|
@@ -49,18 +50,11 @@ export const LoginFormFields = () => {
|
|
|
49
50
|
</TenantFormField>
|
|
50
51
|
|
|
51
52
|
{(form.state === 'otp-required' || fieldErrors.includes('otpToken')) && (
|
|
52
|
-
<
|
|
53
|
+
<MfaCodeFields
|
|
53
54
|
form={form}
|
|
54
55
|
messages={dict.tenant.login.errorMessages}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
type="text"
|
|
58
|
-
required
|
|
59
|
-
autoFocus
|
|
60
|
-
maxLength={6}
|
|
61
|
-
>
|
|
62
|
-
{dict.tenant.login.otpToken}
|
|
63
|
-
</TenantFormField>
|
|
56
|
+
labels={dict.tenant.login.mfa}
|
|
57
|
+
/>
|
|
64
58
|
)}
|
|
65
59
|
|
|
66
60
|
<Button type="submit" className="w-full" disabled={form.state === 'submitting'}>
|
|
@@ -130,7 +130,9 @@ export const useIntrospectionRolesConfig = (projectSlug: string): RolesConfig |
|
|
|
130
130
|
for (const role of roles) {
|
|
131
131
|
const variables: RolesConfig[string]['variables'] = {}
|
|
132
132
|
for (const variable of role.variables) {
|
|
133
|
-
|
|
133
|
+
// `__typename` is not selectable through the generated fetchers, so it is always undefined here;
|
|
134
|
+
// `value` is what only a predefined variable carries, and those the user cannot set.
|
|
135
|
+
if ('value' in variable) {
|
|
134
136
|
continue
|
|
135
137
|
}
|
|
136
138
|
variables[variable.name] = {
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { FormContextValue } from '@contember/react-identity'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
import { FormErrorMessages, TenantFormField } from './common.js'
|
|
4
|
+
|
|
5
|
+
export interface MfaCodeFieldsLabels {
|
|
6
|
+
otpToken: string
|
|
7
|
+
backupCode: string
|
|
8
|
+
/** Link out of the authenticator step, for someone who lost their device. */
|
|
9
|
+
useBackupCode: string
|
|
10
|
+
/** Link back to the authenticator step. */
|
|
11
|
+
useOtpToken: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface MfaCodeValues extends Record<string, unknown> {
|
|
15
|
+
otpToken: string
|
|
16
|
+
backupCode: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface MfaCodeFieldsProps<Value extends MfaCodeValues, ErrorCode extends string, State extends string = never> {
|
|
20
|
+
form: FormContextValue<Value, ErrorCode, State>
|
|
21
|
+
messages: FormErrorMessages<FormContextValue<Value, ErrorCode, State>>
|
|
22
|
+
labels: MfaCodeFieldsLabels
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The second sign-in step: an authenticator code, or a backup code for whoever lost their
|
|
27
|
+
* authenticator. Only one input is mounted at a time — with both on screen the native `required` on
|
|
28
|
+
* the OTP field blocks submitting a backup code, which left account recovery unreachable.
|
|
29
|
+
*/
|
|
30
|
+
export const MfaCodeFields = <Value extends MfaCodeValues, ErrorCode extends string, State extends string = never>(
|
|
31
|
+
{ form, messages, labels }: MfaCodeFieldsProps<Value, ErrorCode, State>,
|
|
32
|
+
) => {
|
|
33
|
+
const [useBackupCode, setUseBackupCode] = useState(false)
|
|
34
|
+
|
|
35
|
+
const switchTo = (backupCode: boolean) => {
|
|
36
|
+
// Clear whichever field is being left behind: both are submitted, and a stale OTP value would
|
|
37
|
+
// fail the six-digit check before the backup code is ever looked at.
|
|
38
|
+
form.setValue(backupCode ? 'otpToken' : 'backupCode', '')
|
|
39
|
+
setUseBackupCode(backupCode)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<>
|
|
44
|
+
{useBackupCode
|
|
45
|
+
? (
|
|
46
|
+
<TenantFormField
|
|
47
|
+
form={form}
|
|
48
|
+
messages={messages}
|
|
49
|
+
field="backupCode"
|
|
50
|
+
autoComplete="one-time-code"
|
|
51
|
+
type="text"
|
|
52
|
+
required
|
|
53
|
+
autoFocus
|
|
54
|
+
>
|
|
55
|
+
{labels.backupCode}
|
|
56
|
+
</TenantFormField>
|
|
57
|
+
)
|
|
58
|
+
: (
|
|
59
|
+
<TenantFormField
|
|
60
|
+
form={form}
|
|
61
|
+
messages={messages}
|
|
62
|
+
field="otpToken"
|
|
63
|
+
autoComplete="one-time-code"
|
|
64
|
+
type="text"
|
|
65
|
+
required
|
|
66
|
+
autoFocus
|
|
67
|
+
maxLength={6}
|
|
68
|
+
>
|
|
69
|
+
{labels.otpToken}
|
|
70
|
+
</TenantFormField>
|
|
71
|
+
)}
|
|
72
|
+
<button
|
|
73
|
+
type="button"
|
|
74
|
+
className="self-start text-sm text-gray-500 underline"
|
|
75
|
+
onClick={() => switchTo(!useBackupCode)}
|
|
76
|
+
>
|
|
77
|
+
{useBackupCode ? labels.useOtpToken : labels.useBackupCode}
|
|
78
|
+
</button>
|
|
79
|
+
</>
|
|
80
|
+
)
|
|
81
|
+
}
|
|
@@ -4,6 +4,7 @@ import { Loader } from '~/lib'
|
|
|
4
4
|
import { TenantFormError, TenantFormField } from './common.js'
|
|
5
5
|
import { dict } from '../dict.js'
|
|
6
6
|
import { useEffect, useRef, useState } from 'react'
|
|
7
|
+
import { MfaCodeFields } from './mfa-code-fields.js'
|
|
7
8
|
|
|
8
9
|
export const PasswordlessSignInFormFields = ({ type, email }: { type: 'token' | 'otp'; email?: string }) => {
|
|
9
10
|
const form = usePasswordlessSignInForm()
|
|
@@ -50,18 +51,11 @@ export const PasswordlessSignInFormFields = ({ type, email }: { type: 'token' |
|
|
|
50
51
|
)}
|
|
51
52
|
|
|
52
53
|
{(form.state === 'otp-required' || fieldErrors.includes('otpToken')) && (
|
|
53
|
-
<
|
|
54
|
+
<MfaCodeFields
|
|
54
55
|
form={form}
|
|
55
56
|
messages={dict.tenant.passwordlessSignIn.errorMessages}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
type="text"
|
|
59
|
-
required
|
|
60
|
-
autoFocus
|
|
61
|
-
maxLength={6}
|
|
62
|
-
>
|
|
63
|
-
{dict.tenant.passwordlessSignIn.otpToken}
|
|
64
|
-
</TenantFormField>
|
|
57
|
+
labels={dict.tenant.passwordlessSignIn.mfa}
|
|
58
|
+
/>
|
|
65
59
|
)}
|
|
66
60
|
|
|
67
61
|
<Button type="submit" className="w-full" disabled={form.state === 'submitting'} ref={buttonRef}>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { useChangePasswordForm } 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
|
+
* `SetPersonPasswordFormFields` renders the fields of the admin `ChangePasswordForm` provider — an administrator
|
|
9
|
+
* sets a password for another person, so no current password is asked for.
|
|
10
|
+
*
|
|
11
|
+
* ## Example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* <ChangePasswordForm personId={personId}>
|
|
14
|
+
* <form className="grid gap-4">
|
|
15
|
+
* <SetPersonPasswordFormFields />
|
|
16
|
+
* </form>
|
|
17
|
+
* </ChangePasswordForm>
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export const SetPersonPasswordFormFields = () => {
|
|
21
|
+
const form = useChangePasswordForm()
|
|
22
|
+
return (
|
|
23
|
+
<div className="relative flex flex-col gap-2">
|
|
24
|
+
{form.state === 'submitting' ? <Loader position="absolute" /> : null}
|
|
25
|
+
|
|
26
|
+
<TenantFormError
|
|
27
|
+
form={form}
|
|
28
|
+
messages={dict.tenant.setPersonPassword.errorMessages}
|
|
29
|
+
/>
|
|
30
|
+
|
|
31
|
+
<TenantFormField
|
|
32
|
+
form={form}
|
|
33
|
+
messages={dict.tenant.setPersonPassword.errorMessages}
|
|
34
|
+
field="password"
|
|
35
|
+
type="password"
|
|
36
|
+
required
|
|
37
|
+
autoComplete="new-password"
|
|
38
|
+
>
|
|
39
|
+
{dict.tenant.setPersonPassword.password}
|
|
40
|
+
</TenantFormField>
|
|
41
|
+
|
|
42
|
+
<TenantFormField
|
|
43
|
+
form={form}
|
|
44
|
+
messages={dict.tenant.setPersonPassword.errorMessages}
|
|
45
|
+
field="passwordConfirmation"
|
|
46
|
+
type="password"
|
|
47
|
+
required
|
|
48
|
+
autoComplete="new-password"
|
|
49
|
+
>
|
|
50
|
+
{dict.tenant.setPersonPassword.passwordConfirmation}
|
|
51
|
+
</TenantFormField>
|
|
52
|
+
|
|
53
|
+
<Button type="submit" className="w-full" disabled={form.state === 'submitting'}>
|
|
54
|
+
{dict.tenant.setPersonPassword.submit}
|
|
55
|
+
</Button>
|
|
56
|
+
</div>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useSetProjectSecretForm } 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
|
+
* `SetProjectSecretFormFields` renders the fields of the `SetProjectSecretForm` provider.
|
|
9
|
+
*
|
|
10
|
+
* ## Example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <SetProjectSecretForm projectSlug={projectSlug} onSuccess={() => controller.current?.refresh()}>
|
|
13
|
+
* <form className="grid gap-4">
|
|
14
|
+
* <SetProjectSecretFormFields />
|
|
15
|
+
* </form>
|
|
16
|
+
* </SetProjectSecretForm>
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export const SetProjectSecretFormFields = () => {
|
|
20
|
+
const form = useSetProjectSecretForm()
|
|
21
|
+
return (
|
|
22
|
+
<div className="relative flex flex-col gap-2">
|
|
23
|
+
{form.state === 'submitting' ? <Loader position="absolute" /> : null}
|
|
24
|
+
|
|
25
|
+
<TenantFormError
|
|
26
|
+
form={form}
|
|
27
|
+
messages={dict.tenant.setProjectSecret.errorMessages}
|
|
28
|
+
/>
|
|
29
|
+
|
|
30
|
+
<TenantFormField
|
|
31
|
+
form={form}
|
|
32
|
+
messages={dict.tenant.setProjectSecret.errorMessages}
|
|
33
|
+
field="key"
|
|
34
|
+
type="text"
|
|
35
|
+
required
|
|
36
|
+
autoFocus
|
|
37
|
+
autoComplete="off"
|
|
38
|
+
>
|
|
39
|
+
{dict.tenant.setProjectSecret.key}
|
|
40
|
+
</TenantFormField>
|
|
41
|
+
|
|
42
|
+
{/* A secret value must not be readable over the shoulder of whoever enters it. */}
|
|
43
|
+
<TenantFormField
|
|
44
|
+
form={form}
|
|
45
|
+
messages={dict.tenant.setProjectSecret.errorMessages}
|
|
46
|
+
field="value"
|
|
47
|
+
type="password"
|
|
48
|
+
required
|
|
49
|
+
autoComplete="off"
|
|
50
|
+
>
|
|
51
|
+
{dict.tenant.setProjectSecret.value}
|
|
52
|
+
</TenantFormField>
|
|
53
|
+
|
|
54
|
+
<Button type="submit" className="w-full" disabled={form.state === 'submitting'}>
|
|
55
|
+
{dict.tenant.setProjectSecret.submit}
|
|
56
|
+
</Button>
|
|
57
|
+
</div>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
@@ -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
|
+
}
|