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

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 +113 -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 +182 -0
  99. package/resources/templates/default/admin/lib/tenant/dict.ts +453 -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
@@ -1,23 +1,87 @@
1
- import * as ProgressPrimitive from '@radix-ui/react-progress'
1
+ import { Slot } from '@radix-ui/react-slot'
2
2
  import * as React from 'react'
3
+ import { ComponentPropsWithoutRef, createContext, forwardRef, useContext } from 'react'
3
4
  import { uic } from '../utils/index.js'
4
5
 
5
- const ProgressRoot = uic(ProgressPrimitive.Root, {
6
+ const DEFAULT_MAX = 100
7
+
8
+ type ProgressState = 'indeterminate' | 'complete' | 'loading'
9
+
10
+ const ProgressContext = createContext<{ value: number | null; max: number }>({ value: null, max: DEFAULT_MAX })
11
+
12
+ const getProgressState = (value: number | null, max: number): ProgressState =>
13
+ value === null ? 'indeterminate' : value === max ? 'complete' : 'loading'
14
+
15
+ const isValidMax = (max: number | undefined): max is number => typeof max === 'number' && !Number.isNaN(max) && max > 0
16
+
17
+ const isValidValue = (value: number | null, max: number): value is number =>
18
+ typeof value === 'number' && !Number.isNaN(value) && value <= max && value >= 0
19
+
20
+ const defaultGetValueLabel = (value: number, max: number) => `${Math.round((value / max) * 100)}%`
21
+
22
+ export type ProgressRootProps = ComponentPropsWithoutRef<'div'> & {
23
+ /** `null` or `undefined` means indeterminate. */
24
+ value?: number | null
25
+ max?: number
26
+ getValueLabel?: (value: number, max: number) => string
27
+ asChild?: boolean
28
+ }
29
+
30
+ const ProgressRootBase = forwardRef<HTMLDivElement, ProgressRootProps>(
31
+ ({ asChild, value: valueProp = null, max: maxProp, getValueLabel = defaultGetValueLabel, ...props }, ref) => {
32
+ const Comp = asChild ? Slot : 'div'
33
+ if ((maxProp || maxProp === 0) && !isValidMax(maxProp)) {
34
+ console.error(
35
+ `Invalid prop \`max\` of value \`${maxProp}\` supplied to \`Progress\`. Only numbers greater than 0 are valid. Defaulting to \`${DEFAULT_MAX}\`.`,
36
+ )
37
+ }
38
+ const max = isValidMax(maxProp) ? maxProp : DEFAULT_MAX
39
+ if (valueProp !== null && !isValidValue(valueProp, max)) {
40
+ console.error(
41
+ `Invalid prop \`value\` of value \`${valueProp}\` supplied to \`Progress\`. It must be between 0 and \`max\` (${max}), or null. Defaulting to \`null\`.`,
42
+ )
43
+ }
44
+ const value = isValidValue(valueProp, max) ? valueProp : null
45
+ return (
46
+ <ProgressContext.Provider value={{ value, max }}>
47
+ <Comp
48
+ aria-valuemax={max}
49
+ aria-valuemin={0}
50
+ aria-valuenow={value ?? undefined}
51
+ aria-valuetext={value !== null ? getValueLabel(value, max) : undefined}
52
+ role="progressbar"
53
+ data-state={getProgressState(value, max)}
54
+ data-value={value ?? undefined}
55
+ data-max={max}
56
+ {...props}
57
+ ref={ref}
58
+ />
59
+ </ProgressContext.Provider>
60
+ )
61
+ },
62
+ )
63
+ ProgressRootBase.displayName = 'Progress'
64
+
65
+ const ProgressIndicatorBase = forwardRef<HTMLDivElement, ComponentPropsWithoutRef<'div'> & { asChild?: boolean }>(({ asChild, ...props }, ref) => {
66
+ const Comp = asChild ? Slot : 'div'
67
+ const { value, max } = useContext(ProgressContext)
68
+ return <Comp data-state={getProgressState(value, max)} data-value={value ?? undefined} data-max={max} {...props} ref={ref} />
69
+ })
70
+ ProgressIndicatorBase.displayName = 'ProgressIndicator'
71
+
72
+ const ProgressRoot = uic(ProgressRootBase, {
6
73
  baseClass: 'relative h-1.5 w-full overflow-hidden rounded-full bg-primary/20',
7
- displayName: ProgressPrimitive.Root.displayName,
74
+ displayName: 'Progress',
8
75
  })
9
76
 
10
- const ProgressIndicator = uic(ProgressPrimitive.Indicator, {
77
+ const ProgressIndicator = uic(ProgressIndicatorBase, {
11
78
  baseClass: 'h-full w-full flex-1 transition-all bg-gradient-to-b from-blue-500 to-blue-400',
12
- displayName: ProgressPrimitive.Indicator.displayName,
79
+ displayName: 'ProgressIndicator',
13
80
  })
14
81
 
15
- export const Progress = React.forwardRef<
16
- React.ElementRef<typeof ProgressPrimitive.Root>,
17
- React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root>
18
- >(({ className, value, ...props }, ref) => (
19
- <ProgressRoot ref={ref} {...props}>
82
+ export const Progress = React.forwardRef<HTMLDivElement, ProgressRootProps>(({ className, value, ...props }, ref) => (
83
+ <ProgressRoot ref={ref} value={value} {...props}>
20
84
  <ProgressIndicator style={{ transform: `translateX(-${100 - (value || 0)}%)` }} />
21
85
  </ProgressRoot>
22
86
  ))
23
- Progress.displayName = ProgressPrimitive.Root.displayName
87
+ Progress.displayName = 'Progress'
@@ -1,7 +1,30 @@
1
- import * as SeparatorPrimitive from '@radix-ui/react-separator'
1
+ import { Slot } from '@radix-ui/react-slot'
2
+ import { ComponentPropsWithoutRef, forwardRef } from 'react'
2
3
  import { uic } from '../utils/index.js'
3
4
 
4
- export const Separator = uic(SeparatorPrimitive.Root, {
5
+ type SeparatorBaseProps = ComponentPropsWithoutRef<'div'> & {
6
+ orientation?: 'horizontal' | 'vertical'
7
+ /** A purely visual separator, hidden from assistive technology. */
8
+ decorative?: boolean
9
+ asChild?: boolean
10
+ }
11
+
12
+ const SeparatorBase = forwardRef<HTMLDivElement, SeparatorBaseProps>(({ asChild, decorative, orientation: orientationProp, ...props }, ref) => {
13
+ const Comp = asChild ? Slot : 'div'
14
+ const orientation = orientationProp === 'vertical' ? 'vertical' : 'horizontal'
15
+ return (
16
+ <Comp
17
+ data-orientation={orientation}
18
+ role={decorative ? 'none' : 'separator'}
19
+ aria-orientation={!decorative && orientation === 'vertical' ? orientation : undefined}
20
+ {...props}
21
+ ref={ref}
22
+ />
23
+ )
24
+ })
25
+ SeparatorBase.displayName = 'Separator'
26
+
27
+ export const Separator = uic(SeparatorBase, {
5
28
  baseClass: 'shrink-0 bg-border',
6
29
  variants: {
7
30
  orientation: {
@@ -9,5 +32,6 @@ export const Separator = uic(SeparatorPrimitive.Root, {
9
32
  vertical: 'h-full w-[1px]',
10
33
  },
11
34
  },
12
- displayName: SeparatorPrimitive.Root.displayName,
35
+ passVariantProps: ['orientation'],
36
+ displayName: 'Separator',
13
37
  })
@@ -1,7 +1,7 @@
1
1
  import { createRequiredContext } from '@contember/react-utils'
2
2
  import { dataAttribute } from '@contember/utilities'
3
3
  import { Slot } from '@radix-ui/react-slot'
4
- import { cva, VariantProps } from 'class-variance-authority'
4
+ import { cva, VariantProps } from '../utils/classNames.js'
5
5
  import { PanelLeft } from 'lucide-react'
6
6
  import { ComponentProps, CSSProperties, ElementRef, forwardRef, PropsWithChildren, ReactNode, useCallback, useEffect, useMemo, useState } from 'react'
7
7
  import { cn, uic } from '../utils/index.js'
@@ -1,4 +1,6 @@
1
- import * as TogglePrimitive from '@radix-ui/react-toggle'
1
+ import { composeEventHandlers } from '@contember/utilities'
2
+ import { Slot } from '@radix-ui/react-slot'
3
+ import { ComponentPropsWithoutRef, forwardRef, useState } from 'react'
2
4
  import { ConfigVariants, uic, uiconfig } from '../utils/index.js'
3
5
 
4
6
  export const toggleConfig = uiconfig({
@@ -23,4 +25,41 @@ export const toggleConfig = uiconfig({
23
25
 
24
26
  export type ToggleProps = ConfigVariants<Exclude<typeof toggleConfig.variants, undefined>>
25
27
 
26
- export const Toggle = uic(TogglePrimitive.Root, toggleConfig)
28
+ type ToggleBaseProps = ComponentPropsWithoutRef<'button'> & {
29
+ /** Controlled pressed state. */
30
+ pressed?: boolean
31
+ defaultPressed?: boolean
32
+ onPressedChange?: (pressed: boolean) => void
33
+ asChild?: boolean
34
+ }
35
+
36
+ const ToggleBase = forwardRef<HTMLButtonElement, ToggleBaseProps>(
37
+ ({ asChild, pressed: pressedProp, defaultPressed, onPressedChange, ...props }, ref) => {
38
+ const Comp = asChild ? Slot : 'button'
39
+ const [uncontrolledPressed, setUncontrolledPressed] = useState(defaultPressed ?? false)
40
+ const isControlled = pressedProp !== undefined
41
+ const pressed = isControlled ? pressedProp : uncontrolledPressed
42
+ return (
43
+ <Comp
44
+ type="button"
45
+ aria-pressed={pressed}
46
+ data-state={pressed ? 'on' : 'off'}
47
+ data-disabled={props.disabled ? '' : undefined}
48
+ {...props}
49
+ ref={ref}
50
+ onClick={composeEventHandlers(props.onClick, () => {
51
+ if (props.disabled) {
52
+ return
53
+ }
54
+ if (!isControlled) {
55
+ setUncontrolledPressed(!pressed)
56
+ }
57
+ onPressedChange?.(!pressed)
58
+ })}
59
+ />
60
+ )
61
+ },
62
+ )
63
+ ToggleBase.displayName = 'Toggle'
64
+
65
+ export const Toggle = uic(ToggleBase, toggleConfig)
@@ -0,0 +1,107 @@
1
+ export type ClassDictionary = Record<string, unknown>
2
+ export type ClassArray = ClassValue[]
3
+ export type ClassValue = ClassArray | ClassDictionary | string | number | bigint | null | boolean | undefined
4
+
5
+ const toClassString = (value: ClassValue): string => {
6
+ if (typeof value === 'string' || typeof value === 'number') {
7
+ return String(value)
8
+ }
9
+ if (typeof value !== 'object' || value === null) {
10
+ return ''
11
+ }
12
+ let result = ''
13
+ if (Array.isArray(value)) {
14
+ for (const item of value) {
15
+ const itemString = item ? toClassString(item) : ''
16
+ if (itemString) {
17
+ result += (result ? ' ' : '') + itemString
18
+ }
19
+ }
20
+ return result
21
+ }
22
+ for (const key in value) {
23
+ if (value[key]) {
24
+ result += (result ? ' ' : '') + key
25
+ }
26
+ }
27
+ return result
28
+ }
29
+
30
+ /**
31
+ * Joins class names; same semantics as `clsx`: strings and numbers are kept, arrays are flattened,
32
+ * objects contribute their keys with truthy values, everything else is dropped.
33
+ */
34
+ export const cx = (...inputs: ClassValue[]): string => toClassString(inputs)
35
+
36
+ type ConfigSchema = Record<string, Record<string, ClassValue>>
37
+
38
+ type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T
39
+
40
+ type ClassProp =
41
+ | { class: ClassValue; className?: never }
42
+ | { class?: never; className: ClassValue }
43
+ | { class?: never; className?: never }
44
+
45
+ type CvaVariants<T extends ConfigSchema> = {
46
+ [Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | null | undefined
47
+ }
48
+
49
+ type CvaVariantsMulti<T extends ConfigSchema> = {
50
+ [Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | StringToBoolean<keyof T[Variant]>[] | undefined
51
+ }
52
+
53
+ type CvaConfig<T> = T extends ConfigSchema ? {
54
+ variants?: T
55
+ defaultVariants?: CvaVariants<T>
56
+ compoundVariants?: ((CvaVariants<T> | CvaVariantsMulti<T>) & ClassProp)[]
57
+ }
58
+ : never
59
+
60
+ type CvaProps<T> = T extends ConfigSchema ? CvaVariants<T> & ClassProp : ClassProp
61
+
62
+ export type VariantProps<Component extends (props?: never) => string> = Omit<Exclude<Parameters<Component>[0], undefined>, 'class' | 'className'>
63
+
64
+ const variantKey = (value: unknown): unknown => typeof value === 'boolean' ? `${value}` : value === 0 ? '0' : value
65
+
66
+ /**
67
+ * Builds a class name from a base, variant classes, compound variant classes and `class` / `className`;
68
+ * same semantics as `cva` from `class-variance-authority` 0.7.
69
+ */
70
+ export const cva = <T>(base?: ClassValue, config?: CvaConfig<T>) => (props?: CvaProps<T>): string => {
71
+ const propsRecord: Record<string, unknown> = { ...props }
72
+ const variants: ConfigSchema | undefined = config?.variants
73
+ if (variants == null) {
74
+ return cx(base, props?.class, props?.className)
75
+ }
76
+ const defaultVariants: Record<string, unknown> = { ...config?.defaultVariants }
77
+
78
+ const variantClassNames = Object.keys(variants).map(variant => {
79
+ const variantProp = propsRecord[variant]
80
+ if (variantProp === null) {
81
+ return null
82
+ }
83
+ const key = variantKey(variantProp) || variantKey(defaultVariants[variant])
84
+ // Property access converts the key with String(), like cva's `variants[variant][key]`.
85
+ return variants[variant][String(key)]
86
+ })
87
+
88
+ const resolvedVariants: Record<string, unknown> = { ...defaultVariants }
89
+ for (const [key, value] of Object.entries(propsRecord)) {
90
+ if (value !== undefined) {
91
+ resolvedVariants[key] = value
92
+ }
93
+ }
94
+
95
+ const compoundClassNames: ClassValue[] = []
96
+ for (const compoundVariant of config?.compoundVariants ?? []) {
97
+ const { class: cvClass, className: cvClassName, ...conditions } = compoundVariant
98
+ const matches = Object.entries(conditions).every(([key, value]) =>
99
+ Array.isArray(value) ? value.includes(resolvedVariants[key]) : resolvedVariants[key] === value
100
+ )
101
+ if (matches) {
102
+ compoundClassNames.push(cvClass, cvClassName)
103
+ }
104
+ }
105
+
106
+ return cx(base, variantClassNames, compoundClassNames, props?.class, props?.className)
107
+ }
@@ -1,8 +1,8 @@
1
- import { ClassValue, clsx } from 'clsx'
1
+ import { ClassValue, cx } from './classNames.js'
2
2
  import { twMerge } from 'tailwind-merge'
3
3
 
4
4
  /**
5
- * `cn` is a utility function that combines Tailwind CSS class names using `clsx`
5
+ * `cn` is a utility function that combines Tailwind CSS class names using `cx` (`clsx` semantics)
6
6
  * and merges conflicting classes with `twMerge`.
7
7
  *
8
8
  * Useful for composing conditional and dynamic className values in React components
@@ -19,4 +19,4 @@ import { twMerge } from 'tailwind-merge'
19
19
  * }
20
20
  * ```
21
21
  */
22
- export const cn = (...inputs: ClassValue[]) => twMerge(clsx(...inputs))
22
+ export const cn = (...inputs: ClassValue[]) => twMerge(cx(...inputs))
@@ -1,2 +1,3 @@
1
+ export * from './classNames.js'
1
2
  export * from './cn.js'
2
3
  export * from './uic.js'
@@ -1,7 +1,6 @@
1
1
  import { dataAttribute } from '@contember/utilities'
2
2
  import { Slot } from '@radix-ui/react-slot'
3
- import { cva } from 'class-variance-authority'
4
- import { ClassValue, clsx } from 'clsx'
3
+ import { ClassValue, cva, cx } from './classNames.js'
5
4
  import { ComponentType, createElement, forwardRef, ReactNode, useMemo } from 'react'
6
5
  import { twMerge } from 'tailwind-merge'
7
6
  import { useObjectMemo } from '@contember/react-utils'
@@ -148,7 +147,7 @@ export const uic = <El extends React.ElementType, Variants extends ConfigSchema
148
147
  }
149
148
  }
150
149
  const style = useMemo(() => config?.style ? { ...config.style, ...(rest.style || {}) } : rest.style, [rest.style])
151
- const finalClassName = useMemo(() => twMerge(clsx(cls(variantsMemoized), classNameProp)), [variantsMemoized, classNameProp])
150
+ const finalClassName = useMemo(() => twMerge(cx(cls(variantsMemoized), classNameProp)), [variantsMemoized, classNameProp])
152
151
 
153
152
  let FinalComponent: React.ElementType = Component
154
153
  if (props.asChild && typeof Component === 'string') {
@@ -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}",
@@ -39,22 +40,15 @@
39
40
  "@radix-ui/react-avatar": "^1.1.3",
40
41
  "@radix-ui/react-dialog": "^1.1.2",
41
42
  "@radix-ui/react-dropdown-menu": "^2.1.2",
42
- "@radix-ui/react-label": "^2.1.0",
43
43
  "@radix-ui/react-popover": "^1.1.2",
44
- "@radix-ui/react-portal": "^1.1.2",
45
- "@radix-ui/react-progress": "^1.1.0",
46
44
  "@radix-ui/react-scroll-area": "^1.2.0",
47
45
  "@radix-ui/react-select": "^2.1.2",
48
- "@radix-ui/react-separator": "^1.1.2",
49
46
  "@radix-ui/react-slot": "^1.1.0",
50
47
  "@radix-ui/react-switch": "^1.1.1",
51
48
  "@radix-ui/react-toast": "^1.2.2",
52
- "@radix-ui/react-toggle": "^1.1.0",
53
49
  "@radix-ui/react-toggle-group": "^1.1.0",
54
50
  "@radix-ui/react-tooltip": "^1.1.3",
55
51
  "@sentry/react": "^8.47.0",
56
- "class-variance-authority": "^0.7.0",
57
- "clsx": "^2.1.1",
58
52
  "lucide-react": "^0.451.0",
59
53
  "qrcode-generator": "^1.4.4",
60
54
  "react": "^18.3.1",
@@ -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
- minio:
85
- image: bitnami/minio
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
- MINIO_ROOT_USER: 'contember'
89
- MINIO_ROOT_PASSWORD: 'contember'
90
- MINIO_DEFAULT_BUCKETS: 'contember:download'
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
- - minio-data:/bitnami/minio/data
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
- minio-data: ~
146
+ object-storage-data: ~
@@ -1,6 +1,5 @@
1
- import { Command, CommandConfiguration, Input } from '@contember/cli-common'
1
+ import { Command, CommandConfiguration, escapeTerminalText, Input, Output, style } from '@contember/cli-common'
2
2
  import { join } from 'node:path'
3
- import chalk from 'chalk'
4
3
  import { TemplateInstaller } from '../lib/TemplateInstaller.js'
5
4
  import { getPackageVersion } from '../lib/version.js'
6
5
  import { detectPackageManager } from '../lib/packageManagerDetector.js'
@@ -13,9 +12,29 @@ type Options = {
13
12
  template: string
14
13
  }
15
14
 
15
+ export interface WorkspaceCreateResult {
16
+ projectName: string
17
+ projectDirectory: string
18
+ template: string
19
+ packageManager: string
20
+ }
21
+
22
+ export interface WorkspaceCreateRuntime {
23
+ cwd(): string
24
+ getPackageVersion(): Promise<string>
25
+ detectPackageManager(): string
26
+ }
27
+
28
+ const defaultRuntime: WorkspaceCreateRuntime = {
29
+ cwd: () => process.cwd(),
30
+ getPackageVersion,
31
+ detectPackageManager,
32
+ }
33
+
16
34
  export class WorkspaceCreateCommand extends Command<Args, Options> {
17
35
  constructor(
18
- private readonly templateInstaller: TemplateInstaller,
36
+ private readonly templateInstaller: Pick<TemplateInstaller, 'installTemplate'>,
37
+ private readonly runtime: WorkspaceCreateRuntime = defaultRuntime,
19
38
  ) {
20
39
  super()
21
40
  }
@@ -26,51 +45,59 @@ export class WorkspaceCreateCommand extends Command<Args, Options> {
26
45
  configuration.option('template').shortcut('t').valueRequired().description('Template name or remote source')
27
46
  }
28
47
 
29
- protected async execute(input: Input<Args, Options>): Promise<void> {
48
+ protected async execute(input: Input<Args, Options>, output: Output): Promise<void> {
30
49
  const projectName = input.getArgument('projectName')
31
- const projectDirectory = join(process.cwd(), projectName)
32
- const packageManager = detectPackageManager()
50
+ const projectDirectory = join(this.runtime.cwd(), projectName)
51
+ const packageManager = this.runtime.detectPackageManager()
33
52
  const template = input.getOption('template') ?? 'default'
34
53
 
35
54
  await this.templateInstaller.installTemplate(template, projectDirectory, {
36
- version: await getPackageVersion(),
55
+ version: await this.runtime.getPackageVersion(),
37
56
  projectName: projectName,
38
57
  packageManager: packageManager,
39
58
  })
40
59
 
41
- console.log(createDocs(projectDirectory, projectName, packageManager))
60
+ const result: WorkspaceCreateResult = { projectName, projectDirectory, template, packageManager }
61
+ output.data(result, {
62
+ human: value => createDocs(value),
63
+ quiet: value => value.projectDirectory,
64
+ })
42
65
  }
43
66
  }
44
67
 
45
- const createDocs = (projectDirectory: string, projectName: string, packageManager: string) => `
46
- Contember project successfully created in ${projectDirectory}
68
+ const createDocs = ({ projectDirectory, projectName, packageManager }: WorkspaceCreateResult) => {
69
+ const safeProjectDirectory = escapeTerminalText(projectDirectory)
70
+ const safeProjectName = escapeTerminalText(projectName)
71
+ const safePackageManager = escapeTerminalText(packageManager)
72
+ return `
73
+ Contember project successfully created in ${safeProjectDirectory}
47
74
 
48
75
  Next steps:
49
76
 
50
77
  1. Navigate to the project directory:
51
- $ ${chalk.green(`cd ${projectName}`)}
78
+ $ ${style('green', `cd ${safeProjectName}`)}
52
79
 
53
80
  2. Install dependencies:
54
- $ ${chalk.green(`${packageManager} install`)}
81
+ $ ${style('green', `${safePackageManager} install`)}
55
82
 
56
83
  3. Start the Contember stack:
57
- $ ${chalk.green(`${packageManager} start`)}
84
+ $ ${style('green', `${safePackageManager} start`)}
58
85
 
59
86
  Available services:
60
87
 
61
- ${chalk.bold('UI & Admin')}
62
- - Contember Admin ${chalk.blue('http://localhost:1480')}
88
+ ${style('bold', 'UI & Admin')}
89
+ - Contember Admin ${style('blue', 'http://localhost:1480')}
63
90
 
64
- ${chalk.bold('API & Backend')}
65
- - Contember Engine API ${chalk.blue('http://localhost:1481')}
91
+ ${style('bold', 'API & Backend')}
92
+ - Contember Engine API ${style('blue', 'http://localhost:1481')}
66
93
  Auth token: 0000000000000000000000000000000000000000
67
94
 
68
- ${chalk.bold('Development Tools')}
69
- - PostgreSQL database ${chalk.blue('http://localhost:1482')} ${chalk.grey('credentials: contember / contember')}
70
- - Minio S3 storage ${chalk.blue('http://localhost:1483')}
71
- - Mailpit SMTP testing ${chalk.blue('http://localhost:1484')}
72
- - Adminer DB manager ${chalk.blue('http://localhost:1485')}
73
- - Minio Dashboard ${chalk.blue('http://localhost:1486')} ${chalk.grey('credentials: contember / contember')}
95
+ ${style('bold', 'Development Tools')}
96
+ - PostgreSQL database ${style('blue', 'http://localhost:1482')} ${style('grey', 'credentials: contember / contember')}
97
+ - S3 object storage ${style('blue', 'http://localhost:1483')} ${style('grey', 'credentials: contember / contember')}
98
+ - Mailpit SMTP testing ${style('blue', 'http://localhost:1484')}
99
+ - Adminer DB manager ${style('blue', 'http://localhost:1485')}
74
100
 
75
- ${chalk.bold('Need help?')} Ask the community: https://github.com/orgs/contember/discussions
101
+ ${style('bold', 'Need help?')} Ask the community: https://github.com/orgs/contember/discussions
76
102
  `
103
+ }
@@ -1,14 +1,18 @@
1
1
  import * as fs from 'node:fs/promises'
2
2
  import { access } from 'node:fs/promises'
3
3
  import { tmpdir } from 'node:os'
4
+ import { join } from 'node:path'
4
5
 
5
6
  export class FileSystem {
6
7
  readFile = fs.readFile
7
8
  writeFile = fs.writeFile
8
9
  rename = fs.rename
10
+ realPath = fs.realpath
11
+ lstat = fs.lstat
9
12
  readDir = fs.readdir
10
13
  copy = (source: string, destination: string, options?: { filter?: (source: string, destination: string) => boolean }) =>
11
- fs.cp(source, destination, { recursive: true, ...options })
14
+ // verbatimSymlinks: by default fs.cp rewrites relative links into absolute paths into the source tree
15
+ fs.cp(source, destination, { recursive: true, verbatimSymlinks: true, ...options })
12
16
  unlink = fs.unlink
13
17
  remove = fs.rm
14
18
  pathExists = async (path: string) => {
@@ -20,6 +24,7 @@ export class FileSystem {
20
24
  }
21
25
  }
22
26
  createTempDir = async () => {
23
- return await fs.mkdtemp(tmpdir())
27
+ // mkdtemp appends random characters to the prefix, so without a separator it would create `/tmpXXXXXX`
28
+ return await fs.mkdtemp(join(tmpdir(), 'contember-template-'))
24
29
  }
25
30
  }