@contember/create 2.2.0-alpha.2 → 2.2.0-alpha.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/CLAUDE.md +22 -0
  2. package/dist/development/run.cjs +7 -7
  3. package/dist/development/run.cjs.map +1 -1
  4. package/dist/development/run.js +8 -8
  5. package/dist/development/run.js.map +1 -1
  6. package/dist/development/src/commands/WorkspaceCreateCommand.cjs +36 -23
  7. package/dist/development/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
  8. package/dist/development/src/commands/WorkspaceCreateCommand.js +37 -24
  9. package/dist/development/src/commands/WorkspaceCreateCommand.js.map +1 -1
  10. package/dist/development/src/lib/FileSystem.cjs +10 -4
  11. package/dist/development/src/lib/FileSystem.cjs.map +1 -1
  12. package/dist/development/src/lib/FileSystem.js +8 -2
  13. package/dist/development/src/lib/FileSystem.js.map +1 -1
  14. package/dist/development/src/lib/TemplateInstaller.cjs +71 -60
  15. package/dist/development/src/lib/TemplateInstaller.cjs.map +1 -1
  16. package/dist/development/src/lib/TemplateInstaller.js +71 -60
  17. package/dist/development/src/lib/TemplateInstaller.js.map +1 -1
  18. package/dist/development/src/lib/fsErrors.cjs +7 -0
  19. package/dist/development/src/lib/fsErrors.cjs.map +1 -0
  20. package/dist/development/src/lib/fsErrors.js +7 -0
  21. package/dist/development/src/lib/fsErrors.js.map +1 -0
  22. package/dist/development/src/lib/projectPath.cjs +66 -0
  23. package/dist/development/src/lib/projectPath.cjs.map +1 -0
  24. package/dist/development/src/lib/projectPath.js +66 -0
  25. package/dist/development/src/lib/projectPath.js.map +1 -0
  26. package/dist/development/src/lib/remoteTemplate.cjs +108 -0
  27. package/dist/development/src/lib/remoteTemplate.cjs.map +1 -0
  28. package/dist/development/src/lib/remoteTemplate.js +108 -0
  29. package/dist/development/src/lib/remoteTemplate.js.map +1 -0
  30. package/dist/development/src/lib/tar.cjs +243 -0
  31. package/dist/development/src/lib/tar.cjs.map +1 -0
  32. package/dist/development/src/lib/tar.js +243 -0
  33. package/dist/development/src/lib/tar.js.map +1 -0
  34. package/dist/production/run.cjs +7 -7
  35. package/dist/production/run.cjs.map +1 -1
  36. package/dist/production/run.js +8 -8
  37. package/dist/production/run.js.map +1 -1
  38. package/dist/production/src/commands/WorkspaceCreateCommand.cjs +36 -23
  39. package/dist/production/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
  40. package/dist/production/src/commands/WorkspaceCreateCommand.js +37 -24
  41. package/dist/production/src/commands/WorkspaceCreateCommand.js.map +1 -1
  42. package/dist/production/src/lib/FileSystem.cjs +10 -4
  43. package/dist/production/src/lib/FileSystem.cjs.map +1 -1
  44. package/dist/production/src/lib/FileSystem.js +8 -2
  45. package/dist/production/src/lib/FileSystem.js.map +1 -1
  46. package/dist/production/src/lib/TemplateInstaller.cjs +71 -60
  47. package/dist/production/src/lib/TemplateInstaller.cjs.map +1 -1
  48. package/dist/production/src/lib/TemplateInstaller.js +71 -60
  49. package/dist/production/src/lib/TemplateInstaller.js.map +1 -1
  50. package/dist/production/src/lib/fsErrors.cjs +7 -0
  51. package/dist/production/src/lib/fsErrors.cjs.map +1 -0
  52. package/dist/production/src/lib/fsErrors.js +7 -0
  53. package/dist/production/src/lib/fsErrors.js.map +1 -0
  54. package/dist/production/src/lib/projectPath.cjs +66 -0
  55. package/dist/production/src/lib/projectPath.cjs.map +1 -0
  56. package/dist/production/src/lib/projectPath.js +66 -0
  57. package/dist/production/src/lib/projectPath.js.map +1 -0
  58. package/dist/production/src/lib/remoteTemplate.cjs +108 -0
  59. package/dist/production/src/lib/remoteTemplate.cjs.map +1 -0
  60. package/dist/production/src/lib/remoteTemplate.js +108 -0
  61. package/dist/production/src/lib/remoteTemplate.js.map +1 -0
  62. package/dist/production/src/lib/tar.cjs +243 -0
  63. package/dist/production/src/lib/tar.cjs.map +1 -0
  64. package/dist/production/src/lib/tar.js +243 -0
  65. package/dist/production/src/lib/tar.js.map +1 -0
  66. package/dist/types/commands/WorkspaceCreateCommand.d.ts +15 -3
  67. package/dist/types/commands/WorkspaceCreateCommand.d.ts.map +1 -1
  68. package/dist/types/lib/FileSystem.d.ts +2 -0
  69. package/dist/types/lib/FileSystem.d.ts.map +1 -1
  70. package/dist/types/lib/TemplateInstaller.d.ts +9 -1
  71. package/dist/types/lib/TemplateInstaller.d.ts.map +1 -1
  72. package/dist/types/lib/fsErrors.d.ts +3 -0
  73. package/dist/types/lib/fsErrors.d.ts.map +1 -0
  74. package/dist/types/lib/projectPath.d.ts +12 -0
  75. package/dist/types/lib/projectPath.d.ts.map +1 -0
  76. package/dist/types/lib/remoteTemplate.d.ts +15 -0
  77. package/dist/types/lib/remoteTemplate.d.ts.map +1 -0
  78. package/dist/types/lib/tar.d.ts +28 -0
  79. package/dist/types/lib/tar.d.ts.map +1 -0
  80. package/dist/types/tsconfig.tsbuildinfo +1 -1
  81. package/package.json +5 -7
  82. package/resources/templates/default/README.md +3 -1
  83. package/resources/templates/default/admin/app/components/navigation.tsx +95 -8
  84. package/resources/templates/default/admin/app/pages/tenant.tsx +328 -77
  85. package/resources/templates/default/admin/entrypoint/components/login.tsx +1 -1
  86. package/resources/templates/default/admin/entrypoint/pages/magicLink.tsx +1 -1
  87. package/resources/templates/default/admin/entrypoint/pages/magicLinkSent.tsx +1 -1
  88. package/resources/templates/default/admin/entrypoint/pages/passwordReset.tsx +1 -1
  89. package/resources/templates/default/admin/entrypoint/pages/resetRequest.tsx +1 -1
  90. package/resources/templates/default/admin/entrypoint/pages/resetRequestSuccess.tsx +1 -1
  91. package/resources/templates/default/admin/lib/editor/common/editor-inline-toolbar.tsx +3 -0
  92. package/resources/templates/default/admin/lib/editor/sortable-block.tsx +5 -4
  93. package/resources/templates/default/admin/lib/tenant/config/auth-policy-list.tsx +86 -0
  94. package/resources/templates/default/admin/lib/tenant/config/common.tsx +71 -0
  95. package/resources/templates/default/admin/lib/tenant/config/identity-provider-list.tsx +131 -0
  96. package/resources/templates/default/admin/lib/tenant/config/index.ts +5 -0
  97. package/resources/templates/default/admin/lib/tenant/config/mail-template-list.tsx +108 -0
  98. package/resources/templates/default/admin/lib/tenant/config/tenant-config-view.tsx +195 -0
  99. package/resources/templates/default/admin/lib/tenant/dict.ts +456 -4
  100. package/resources/templates/default/admin/lib/tenant/errors.ts +10 -0
  101. package/resources/templates/default/admin/lib/tenant/forms/add-project-member.tsx +57 -0
  102. package/resources/templates/default/admin/lib/tenant/forms/change-my-profile.tsx +40 -0
  103. package/resources/templates/default/admin/lib/tenant/forms/change-profile.tsx +55 -0
  104. package/resources/templates/default/admin/lib/tenant/forms/common.tsx +9 -2
  105. package/resources/templates/default/admin/lib/tenant/forms/create-global-api-key.tsx +69 -0
  106. package/resources/templates/default/admin/lib/tenant/forms/global-roles-control.tsx +113 -0
  107. package/resources/templates/default/admin/lib/tenant/forms/index.ts +11 -0
  108. package/resources/templates/default/admin/lib/tenant/forms/invite.tsx +42 -4
  109. package/resources/templates/default/admin/lib/tenant/forms/login.tsx +4 -10
  110. package/resources/templates/default/admin/lib/tenant/forms/memberships-control.tsx +3 -1
  111. package/resources/templates/default/admin/lib/tenant/forms/mfa-code-fields.tsx +81 -0
  112. package/resources/templates/default/admin/lib/tenant/forms/passwordless-signin.tsx +4 -10
  113. package/resources/templates/default/admin/lib/tenant/forms/set-person-password.tsx +58 -0
  114. package/resources/templates/default/admin/lib/tenant/forms/set-project-secret.tsx +59 -0
  115. package/resources/templates/default/admin/lib/tenant/forms/sign-up.tsx +73 -0
  116. package/resources/templates/default/admin/lib/tenant/hooks/index.ts +2 -0
  117. package/resources/templates/default/admin/lib/tenant/idp/identity-provider-connections.tsx +124 -0
  118. package/resources/templates/default/admin/lib/tenant/idp/index.ts +1 -0
  119. package/resources/templates/default/admin/lib/tenant/index.ts +7 -0
  120. package/resources/templates/default/admin/lib/tenant/listing/api-key-list.tsx +160 -22
  121. package/resources/templates/default/admin/lib/tenant/listing/auth-log-list.tsx +179 -0
  122. package/resources/templates/default/admin/lib/tenant/listing/global-api-key-list.tsx +149 -0
  123. package/resources/templates/default/admin/lib/tenant/listing/index.ts +7 -0
  124. package/resources/templates/default/admin/lib/tenant/listing/member-delete-dialog.tsx +1 -1
  125. package/resources/templates/default/admin/lib/tenant/listing/member-list.tsx +20 -11
  126. package/resources/templates/default/admin/lib/tenant/listing/mfa.tsx +29 -0
  127. package/resources/templates/default/admin/lib/tenant/listing/person-actions.tsx +179 -0
  128. package/resources/templates/default/admin/lib/tenant/listing/person-detail.tsx +141 -0
  129. package/resources/templates/default/admin/lib/tenant/listing/person-list.tsx +13 -2
  130. package/resources/templates/default/admin/lib/tenant/listing/persons-list.tsx +128 -0
  131. package/resources/templates/default/admin/lib/tenant/listing/project-secret-list.tsx +82 -0
  132. package/resources/templates/default/admin/lib/tenant/otp/backup-codes.tsx +81 -0
  133. package/resources/templates/default/admin/lib/tenant/otp/email-otp-setup.tsx +133 -0
  134. package/resources/templates/default/admin/lib/tenant/otp/index.ts +2 -0
  135. package/resources/templates/default/admin/lib/tenant/security/index.ts +2 -0
  136. package/resources/templates/default/admin/lib/tenant/security/passwordless-toggle.tsx +63 -0
  137. package/resources/templates/default/admin/lib/tenant/security/session-list.tsx +143 -0
  138. package/resources/templates/default/admin/lib/ui/label.tsx +25 -2
  139. package/resources/templates/default/admin/lib/ui/menu.tsx +1 -1
  140. package/resources/templates/default/admin/lib/ui/progress.tsx +75 -11
  141. package/resources/templates/default/admin/lib/ui/separator.tsx +27 -3
  142. package/resources/templates/default/admin/lib/ui/sidebar.tsx +1 -1
  143. package/resources/templates/default/admin/lib/ui/toggle.tsx +41 -2
  144. package/resources/templates/default/admin/lib/utils/classNames.ts +107 -0
  145. package/resources/templates/default/admin/lib/utils/cn.ts +3 -3
  146. package/resources/templates/default/admin/lib/utils/index.ts +1 -0
  147. package/resources/templates/default/admin/lib/utils/uic.tsx +2 -3
  148. package/resources/templates/default/admin/package.json +1 -7
  149. package/resources/templates/default/docker/object-storage/README.md +13 -0
  150. package/resources/templates/default/docker/object-storage/identities.json +13 -0
  151. package/resources/templates/default/docker-compose.yaml +29 -7
  152. package/src/commands/WorkspaceCreateCommand.ts +51 -24
  153. package/src/lib/FileSystem.ts +7 -2
  154. package/src/lib/TemplateInstaller.ts +87 -69
  155. package/src/lib/fsErrors.ts +2 -0
  156. package/src/lib/projectPath.ts +79 -0
  157. package/src/lib/remoteTemplate.ts +130 -0
  158. package/src/lib/tar.ts +283 -0
  159. package/src/run.ts +8 -7
  160. package/tests/cases/unit/create-process.test.ts +66 -0
  161. package/tests/cases/unit/fileSystem.test.ts +14 -0
  162. package/tests/cases/unit/fixtures/template.tar.gz +0 -0
  163. package/tests/cases/unit/remoteTemplate.test.ts +277 -0
  164. package/tests/cases/unit/template-installer-cleanup.test.ts +150 -0
  165. package/tests/cases/unit/template-installer-containment.test.ts +133 -0
  166. package/tests/cases/unit/template-installer-symlinks.test.ts +37 -0
  167. package/tests/cases/unit/workspace-create.test.ts +81 -0
@@ -0,0 +1,71 @@
1
+ import * as React from 'react'
2
+ import { ReactNode } from 'react'
3
+ import { Loader } from '~/lib'
4
+ import { isForbiddenError, TenantQueryLoaderState } from '@contember/react-client-tenant'
5
+ import { TerminalIcon } from 'lucide-react'
6
+ import { dict } from '../dict.js'
7
+
8
+ export interface ConfigQueryStateProps {
9
+ forbiddenMessage: string
10
+ failedMessage: string
11
+ }
12
+
13
+ /**
14
+ * Renders the non-data states of a configuration query, or `null` once data is
15
+ * available — a plain helper, not a component, so the caller can `return` it and
16
+ * then narrow on `'data' in query`.
17
+ *
18
+ * The read-only configuration views all share one shape: a permission-gated
19
+ * query that throws rather than returning an empty result, so "you may not see
20
+ * this" has to be rendered as an ordinary state instead of a failure.
21
+ */
22
+ export const renderConfigQueryState = <Result,>(
23
+ { query, forbiddenMessage, failedMessage }: ConfigQueryStateProps & { query: TenantQueryLoaderState<Result> },
24
+ ): ReactNode => {
25
+ if (query.state === 'error') {
26
+ return isForbiddenError(query.error)
27
+ ? <div className="text-gray-500 italic">{forbiddenMessage}</div>
28
+ : <div className="text-destructive italic">{failedMessage}</div>
29
+ }
30
+ if (!('data' in query)) {
31
+ return (
32
+ <div className="relative min-h-24">
33
+ <Loader position="absolute" />
34
+ </div>
35
+ )
36
+ }
37
+ return null
38
+ }
39
+
40
+ /** Points at the write path these views deliberately do not offer. */
41
+ export const ManagedByCliNote = () => (
42
+ <p className="flex items-center gap-2 text-sm text-gray-500">
43
+ <TerminalIcon className="w-3.5 h-3.5 shrink-0" />
44
+ <span>
45
+ {dict.tenant.configView.managedByCli} <code className="font-mono">{dict.tenant.configView.managedByCliCommand}</code>
46
+ </span>
47
+ </p>
48
+ )
49
+
50
+ export const ConfigSection = ({ title, children }: { title: string; children: ReactNode }) => (
51
+ <div className="flex flex-col gap-2">
52
+ <h3 className="text-sm font-semibold text-gray-700">{title}</h3>
53
+ {children}
54
+ </div>
55
+ )
56
+
57
+ /** Formats a config leaf value for display; `null`/`undefined` read as "not set". */
58
+ export const formatConfigValue = (value: unknown): string => {
59
+ if (value === null || value === undefined) {
60
+ return dict.tenant.configView.notSet
61
+ }
62
+ if (typeof value === 'boolean') {
63
+ return value ? dict.tenant.configView.enabled : dict.tenant.configView.disabled
64
+ }
65
+ if (Array.isArray(value)) {
66
+ // An empty list is a meaningful setting, not a missing one — for the panel policy it means
67
+ // nobody may enter — so it must not fall through to `String([])` and render as a blank cell.
68
+ return value.length === 0 ? dict.tenant.configView.emptyList : value.join(', ')
69
+ }
70
+ return String(value)
71
+ }
@@ -0,0 +1,131 @@
1
+ import * as React from 'react'
2
+ import { useState } from 'react'
3
+ import { Button, Loader, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, TableWrapper } from '~/lib'
4
+ import { useIdentityProvidersQuery, useTenantQueryLoader } from '@contember/react-client-tenant'
5
+ import { dict } from '../dict.js'
6
+ import { formatConfigValue, ManagedByCliNote, renderConfigQueryState } from './common.js'
7
+
8
+ export interface IdentityProviderListController {
9
+ refresh: () => void
10
+ }
11
+
12
+ export interface IdentityProviderListProps {
13
+ controller?: { current?: IdentityProviderListController }
14
+ }
15
+
16
+ /** Only the built-in `oidc` handler acts on `strictResponseType` (apple and facebook accept and ignore it); absent means off. */
17
+ const formatStrictResponseType = (type: string, configuration: unknown): string => {
18
+ if (type !== 'oidc') {
19
+ return dict.tenant.identityProviderList.notApplicable
20
+ }
21
+ const value = typeof configuration === 'object' && configuration !== null && 'strictResponseType' in configuration
22
+ ? configuration.strictResponseType
23
+ : undefined
24
+ return formatConfigValue(value === true)
25
+ }
26
+
27
+ /**
28
+ * `IdentityProviderList` shows the identity providers configured on the tenant, read-only.
29
+ *
30
+ * This is an administration view (`idp:list`), not a source for login-screen
31
+ * buttons — an unauthenticated visitor cannot run the query. Providers are
32
+ * written with `contember tenant:apply`.
33
+ *
34
+ * The configuration blob is collapsed by default and comes from
35
+ * `getPublicConfiguration`, which strips the client secret for the built-in
36
+ * handlers. A custom handler that does not implement it returns the raw stored
37
+ * configuration, hence the note under the table.
38
+ *
39
+ * ## Example
40
+ * ```tsx
41
+ * <IdentityProviderList />
42
+ * ```
43
+ */
44
+ export const IdentityProviderList = ({ controller }: IdentityProviderListProps) => {
45
+ const [query, { refresh }] = useTenantQueryLoader(useIdentityProvidersQuery(), {})
46
+ const [expanded, setExpanded] = useState<string | null>(null)
47
+ if (controller) {
48
+ controller.current = { refresh }
49
+ }
50
+
51
+ const nonData = renderConfigQueryState({
52
+ query,
53
+ forbiddenMessage: dict.tenant.identityProviderList.forbidden,
54
+ failedMessage: dict.tenant.identityProviderList.failedToLoadData,
55
+ })
56
+ if (nonData !== null) {
57
+ return nonData
58
+ }
59
+ if (!('data' in query)) {
60
+ return null
61
+ }
62
+ const providers = query.data
63
+
64
+ return (
65
+ <div className="relative flex flex-col gap-3">
66
+ {query.state !== 'success' && <Loader position="absolute" />}
67
+ <ManagedByCliNote />
68
+
69
+ <TableWrapper>
70
+ {/* Seven columns: the default cell padding would push the table past the card at desktop widths. */}
71
+ <Table className="[&_td]:px-3 [&_th]:px-3">
72
+ <TableHeader>
73
+ <TableRow>
74
+ <TableHead>{dict.tenant.identityProviderList.slug}</TableHead>
75
+ <TableHead>{dict.tenant.identityProviderList.type}</TableHead>
76
+ <TableHead>{dict.tenant.identityProviderList.status}</TableHead>
77
+ <TableHead>{dict.tenant.identityProviderList.autoSignUp}</TableHead>
78
+ <TableHead>{dict.tenant.identityProviderList.exclusive}</TableHead>
79
+ <TableHead>{dict.tenant.identityProviderList.strictResponseType}</TableHead>
80
+ <TableHead>{dict.tenant.identityProviderList.configuration}</TableHead>
81
+ </TableRow>
82
+ </TableHeader>
83
+ <TableBody>
84
+ {providers.length === 0 && (
85
+ <TableRow>
86
+ <TableCell colSpan={7}>{dict.tenant.identityProviderList.noResults}</TableCell>
87
+ </TableRow>
88
+ )}
89
+ {providers.map(provider => (
90
+ <React.Fragment key={provider.slug}>
91
+ <TableRow>
92
+ <TableCell className="font-medium">{provider.slug}</TableCell>
93
+ <TableCell className="font-mono text-xs">{provider.type}</TableCell>
94
+ <TableCell>
95
+ {provider.disabledAt
96
+ ? <span className="text-destructive">{dict.tenant.configView.disabled}</span>
97
+ : <span>{dict.tenant.configView.enabled}</span>}
98
+ </TableCell>
99
+ <TableCell>{formatConfigValue(provider.options.autoSignUp)}</TableCell>
100
+ <TableCell>{formatConfigValue(provider.options.exclusive)}</TableCell>
101
+ <TableCell>{formatStrictResponseType(provider.type, provider.configuration)}</TableCell>
102
+ <TableCell>
103
+ <Button
104
+ variant="outline"
105
+ size="sm"
106
+ onClick={() => setExpanded(expanded === provider.slug ? null : provider.slug)}
107
+ >
108
+ {expanded === provider.slug
109
+ ? dict.tenant.identityProviderList.hideConfiguration
110
+ : dict.tenant.identityProviderList.showConfiguration}
111
+ </Button>
112
+ </TableCell>
113
+ </TableRow>
114
+ {expanded === provider.slug && (
115
+ <TableRow>
116
+ <TableCell colSpan={7}>
117
+ <pre className="overflow-x-auto text-xs bg-gray-50 p-3 rounded">
118
+ {JSON.stringify(provider.configuration, null, 2)}
119
+ </pre>
120
+ </TableCell>
121
+ </TableRow>
122
+ )}
123
+ </React.Fragment>
124
+ ))}
125
+ </TableBody>
126
+ </Table>
127
+ </TableWrapper>
128
+ <p className="text-sm text-gray-500">{dict.tenant.identityProviderList.secretsNote}</p>
129
+ </div>
130
+ )
131
+ }
@@ -0,0 +1,5 @@
1
+ export * from './auth-policy-list.js'
2
+ export * from './common.js'
3
+ export * from './identity-provider-list.js'
4
+ export * from './mail-template-list.js'
5
+ export * from './tenant-config-view.js'
@@ -0,0 +1,108 @@
1
+ import * as React from 'react'
2
+ import { useState } from 'react'
3
+ import { Button, Loader, Table, TableCell, TableHead, TableHeader, TableRow } from '~/lib'
4
+ import { useMailTemplatesQuery, useTenantQueryLoader } from '@contember/react-client-tenant'
5
+ import { dict } from '../dict.js'
6
+ import { formatConfigValue, ManagedByCliNote, renderConfigQueryState } from './common.js'
7
+
8
+ export interface MailTemplateListController {
9
+ refresh: () => void
10
+ }
11
+
12
+ export interface MailTemplateListProps {
13
+ controller?: { current?: MailTemplateListController }
14
+ }
15
+
16
+ /** Templates have no id; type + variant + project is what identifies one server-side. */
17
+ const templateKey = (template: { type: string; variant?: string | null; projectSlug?: string | null }) =>
18
+ `${template.projectSlug ?? ''}/${template.type}/${template.variant ?? ''}`
19
+
20
+ /**
21
+ * `MailTemplateList` shows the configured mail templates read-only, with the body
22
+ * collapsed behind a toggle.
23
+ *
24
+ * Templates are written with `contember tenant:apply`; reading them requires
25
+ * `mailTemplate:list`. A type missing from this list is not broken — it means the
26
+ * built-in default is in use.
27
+ *
28
+ * ## Example
29
+ * ```tsx
30
+ * <MailTemplateList />
31
+ * ```
32
+ */
33
+ export const MailTemplateList = ({ controller }: MailTemplateListProps) => {
34
+ const [query, { refresh }] = useTenantQueryLoader(useMailTemplatesQuery(), {})
35
+ const [expanded, setExpanded] = useState<string | null>(null)
36
+ if (controller) {
37
+ controller.current = { refresh }
38
+ }
39
+
40
+ const nonData = renderConfigQueryState({
41
+ query,
42
+ forbiddenMessage: dict.tenant.mailTemplateList.forbidden,
43
+ failedMessage: dict.tenant.mailTemplateList.failedToLoadData,
44
+ })
45
+ if (nonData !== null) {
46
+ return nonData
47
+ }
48
+ if (!('data' in query)) {
49
+ return null
50
+ }
51
+ const templates = query.data
52
+
53
+ return (
54
+ <div className="relative flex flex-col gap-3">
55
+ {query.state !== 'success' && <Loader position="absolute" />}
56
+ <ManagedByCliNote />
57
+
58
+ {templates.length === 0
59
+ ? <div className="text-gray-500 italic">{dict.tenant.mailTemplateList.noResults}</div>
60
+ : (
61
+ <Table>
62
+ <TableHeader>
63
+ <TableRow>
64
+ <TableHead>{dict.tenant.mailTemplateList.type}</TableHead>
65
+ <TableHead>{dict.tenant.mailTemplateList.variant}</TableHead>
66
+ <TableHead>{dict.tenant.mailTemplateList.project}</TableHead>
67
+ <TableHead>{dict.tenant.mailTemplateList.subject}</TableHead>
68
+ <TableHead>{dict.tenant.mailTemplateList.replyTo}</TableHead>
69
+ <TableHead>{dict.tenant.mailTemplateList.useLayout}</TableHead>
70
+ <TableHead />
71
+ </TableRow>
72
+ </TableHeader>
73
+ {templates.map(template => {
74
+ const key = templateKey(template)
75
+ return (
76
+ <React.Fragment key={key}>
77
+ <TableRow>
78
+ <TableCell className="font-mono text-xs">{template.type}</TableCell>
79
+ <TableCell>{template.variant || '—'}</TableCell>
80
+ <TableCell>{template.projectSlug ?? '—'}</TableCell>
81
+ <TableCell className="font-medium">{template.subject}</TableCell>
82
+ <TableCell>{template.replyTo ?? '—'}</TableCell>
83
+ <TableCell>{formatConfigValue(template.useLayout)}</TableCell>
84
+ <TableCell>
85
+ <Button variant="outline" size="sm" onClick={() => setExpanded(expanded === key ? null : key)}>
86
+ {expanded === key
87
+ ? dict.tenant.mailTemplateList.hideContent
88
+ : dict.tenant.mailTemplateList.showContent}
89
+ </Button>
90
+ </TableCell>
91
+ </TableRow>
92
+ {expanded === key && (
93
+ <TableRow>
94
+ <TableCell colSpan={7}>
95
+ <pre className="overflow-x-auto whitespace-pre-wrap text-xs bg-gray-50 p-3 rounded">
96
+ {template.content}
97
+ </pre>
98
+ </TableCell>
99
+ </TableRow>
100
+ )}
101
+ </React.Fragment>
102
+ )
103
+ })}
104
+ </Table>
105
+ )}
106
+ </div>
107
+ )
108
+ }
@@ -0,0 +1,195 @@
1
+ import * as React from 'react'
2
+ import { ReactNode } from 'react'
3
+ import { Loader, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '~/lib'
4
+ import { useConfigurationQuery, useTenantQueryLoader } from '@contember/react-client-tenant'
5
+ import { dict } from '../dict.js'
6
+ import { ConfigSection, formatConfigValue, ManagedByCliNote, renderConfigQueryState } from './common.js'
7
+
8
+ export interface TenantConfigViewController {
9
+ refresh: () => void
10
+ }
11
+
12
+ export interface TenantConfigViewProps {
13
+ controller?: { current?: TenantConfigViewController }
14
+ }
15
+
16
+ // Listed explicitly rather than via Object.entries so the order is stable and a
17
+ // non-window field added to ConfigRateLimits cannot leak into the table.
18
+ const rateLimitKeys = [
19
+ 'signUpPerIp',
20
+ 'loginPerIp',
21
+ 'passwordResetPerIp',
22
+ 'passwordlessInitPerIp',
23
+ 'emailOtpPerPerson',
24
+ 'emailVerificationPerIp',
25
+ ] as const
26
+
27
+ const SettingsTable = ({ rows }: { rows: readonly (readonly [string, ReactNode])[] }) => (
28
+ <Table>
29
+ <TableHeader>
30
+ <TableRow>
31
+ <TableHead className="w-1/2">{dict.tenant.configView.setting}</TableHead>
32
+ <TableHead>{dict.tenant.configView.value}</TableHead>
33
+ </TableRow>
34
+ </TableHeader>
35
+ <TableBody>
36
+ {rows.map(([label, value]) => (
37
+ <TableRow key={label}>
38
+ <TableCell className="font-medium">{label}</TableCell>
39
+ <TableCell>{value}</TableCell>
40
+ </TableRow>
41
+ ))}
42
+ </TableBody>
43
+ </Table>
44
+ )
45
+
46
+ /**
47
+ * `TenantConfigView` shows the tenant-wide configuration read-only. There is no
48
+ * editing counterpart on purpose — the write path is `contember tenant:apply`.
49
+ *
50
+ * Requires `system:viewConfig` (the read counterpart of `system:configure`). A
51
+ * caller without it gets a "no permission" message rather than an error, because
52
+ * the resolver rejects instead of returning defaults.
53
+ *
54
+ * ## Example
55
+ * ```tsx
56
+ * <TenantConfigView />
57
+ * ```
58
+ */
59
+ export const TenantConfigView = ({ controller }: TenantConfigViewProps) => {
60
+ const [query, { refresh }] = useTenantQueryLoader(useConfigurationQuery(), {})
61
+ if (controller) {
62
+ controller.current = { refresh }
63
+ }
64
+
65
+ const nonData = renderConfigQueryState({
66
+ query,
67
+ forbiddenMessage: dict.tenant.configView.forbidden,
68
+ failedMessage: dict.tenant.configView.failedToLoadData,
69
+ })
70
+ if (nonData !== null) {
71
+ return nonData
72
+ }
73
+ if (!('data' in query)) {
74
+ return null
75
+ }
76
+ const config = query.data
77
+
78
+ return (
79
+ <div className="relative flex flex-col gap-6">
80
+ {query.state !== 'success' && <Loader position="absolute" />}
81
+ <ManagedByCliNote />
82
+
83
+ <ConfigSection title={dict.tenant.configView.panelAccess}>
84
+ <SettingsTable
85
+ rows={[
86
+ ['globalRoles', formatConfigValue(config.panel.globalRoles)],
87
+ ['projectRoles', formatConfigValue(config.panel.projectRoles)],
88
+ ]}
89
+ />
90
+ </ConfigSection>
91
+
92
+ <ConfigSection title={dict.tenant.configView.signup}>
93
+ <SettingsTable rows={[['requireEmailVerification', formatConfigValue(config.signup.requireEmailVerification)]]} />
94
+ </ConfigSection>
95
+
96
+ <ConfigSection title={dict.tenant.configView.emailChange}>
97
+ <SettingsTable
98
+ rows={[
99
+ ['requireVerification', formatConfigValue(config.emailChange.requireVerification)],
100
+ ['requireReauthentication', formatConfigValue(config.emailChange.requireReauthentication)],
101
+ ]}
102
+ />
103
+ </ConfigSection>
104
+
105
+ <ConfigSection title={dict.tenant.configView.password}>
106
+ <SettingsTable
107
+ rows={[
108
+ ['minLength', formatConfigValue(config.password.minLength)],
109
+ ['requireUppercase', formatConfigValue(config.password.requireUppercase)],
110
+ ['requireLowercase', formatConfigValue(config.password.requireLowercase)],
111
+ ['requireDigit', formatConfigValue(config.password.requireDigit)],
112
+ ['requireSpecial', formatConfigValue(config.password.requireSpecial)],
113
+ ['pattern', formatConfigValue(config.password.pattern)],
114
+ ['checkBlacklist', formatConfigValue(config.password.checkBlacklist)],
115
+ ['checkHibp', formatConfigValue(config.password.checkHibp)],
116
+ ['revokeSessionsOnChange', formatConfigValue(config.password.revokeSessionsOnChange)],
117
+ ]}
118
+ />
119
+ </ConfigSection>
120
+
121
+ <ConfigSection title={dict.tenant.configView.passwordless}>
122
+ <SettingsTable
123
+ rows={[
124
+ ['enabled', formatConfigValue(config.passwordless.enabled)],
125
+ ['url', formatConfigValue(config.passwordless.url)],
126
+ ['expiration', formatConfigValue(config.passwordless.expiration)],
127
+ ['uniformResponse', formatConfigValue(config.passwordless.uniformResponse)],
128
+ ]}
129
+ />
130
+ </ConfigSection>
131
+
132
+ <ConfigSection title={dict.tenant.configView.login}>
133
+ <SettingsTable
134
+ rows={[
135
+ ['baseBackoff', formatConfigValue(config.login.baseBackoff)],
136
+ ['maxBackoff', formatConfigValue(config.login.maxBackoff)],
137
+ ['attemptWindow', formatConfigValue(config.login.attemptWindow)],
138
+ ['revealUserExists', formatConfigValue(config.login.revealUserExists)],
139
+ ['revealLoginMethod', formatConfigValue(config.login.revealLoginMethod)],
140
+ ['defaultTokenExpiration', formatConfigValue(config.login.defaultTokenExpiration)],
141
+ ['maxTokenExpiration', formatConfigValue(config.login.maxTokenExpiration)],
142
+ ['mfaGraceDuration', formatConfigValue(config.login.mfaGraceDuration)],
143
+ ['mfaChangeRequiresReauthentication', formatConfigValue(config.login.mfaChangeRequiresReauthentication)],
144
+ ]}
145
+ />
146
+ </ConfigSection>
147
+
148
+ <ConfigSection title={dict.tenant.configView.anomalyDetection}>
149
+ <SettingsTable
150
+ rows={[
151
+ ['enabled', formatConfigValue(config.login.anomalyDetection.enabled)],
152
+ ['historySize', formatConfigValue(config.login.anomalyDetection.historySize)],
153
+ ['emailThreshold', formatConfigValue(config.login.anomalyDetection.emailThreshold)],
154
+ ['stepUpThreshold', formatConfigValue(config.login.anomalyDetection.stepUpThreshold)],
155
+ ['missingSignalIsNew', formatConfigValue(config.login.anomalyDetection.missingSignalIsNew)],
156
+ ]}
157
+ />
158
+ </ConfigSection>
159
+
160
+ <ConfigSection title={dict.tenant.configView.captcha}>
161
+ <SettingsTable
162
+ rows={[
163
+ ['provider', formatConfigValue(config.captcha.provider)],
164
+ ['threshold', formatConfigValue(config.captcha.threshold)],
165
+ ['protect.signUp', formatConfigValue(config.captcha.protect.signUp)],
166
+ ['protect.passwordReset', formatConfigValue(config.captcha.protect.passwordReset)],
167
+ ['protect.passwordlessInit', formatConfigValue(config.captcha.protect.passwordlessInit)],
168
+ ['protect.emailVerification', formatConfigValue(config.captcha.protect.emailVerification)],
169
+ ]}
170
+ />
171
+ </ConfigSection>
172
+
173
+ <ConfigSection title={dict.tenant.configView.rateLimits}>
174
+ <Table>
175
+ <TableHeader>
176
+ <TableRow>
177
+ <TableHead className="w-1/2">{dict.tenant.configView.setting}</TableHead>
178
+ <TableHead>{dict.tenant.configView.limit}</TableHead>
179
+ <TableHead>{dict.tenant.configView.window}</TableHead>
180
+ </TableRow>
181
+ </TableHeader>
182
+ <TableBody>
183
+ {rateLimitKeys.map(key => (
184
+ <TableRow key={key}>
185
+ <TableCell className="font-medium">{key}</TableCell>
186
+ <TableCell>{formatConfigValue(config.rateLimits[key].limit)}</TableCell>
187
+ <TableCell>{formatConfigValue(config.rateLimits[key].window)}</TableCell>
188
+ </TableRow>
189
+ ))}
190
+ </TableBody>
191
+ </Table>
192
+ </ConfigSection>
193
+ </div>
194
+ )
195
+ }