@xeplr/cli 0.3.0 → 0.3.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xeplr/cli",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Creates a working xeplr application — API, sign-in and UI — from a few answers.",
5
5
  "license": "MIT",
6
6
  "author": "xeppie <admin@xeplr.com>",
@@ -38,4 +38,5 @@ The API (`@xeplr/base-apis`) and the sign-in service (`@xeplr/auth`), with this
38
38
  | `__PREFIX___CONNECTION`, `AUTH_DB_CONNECTION_INFO_ENCRYPTED` | the database, encrypted — `npm run db:encrypt` |
39
39
  | `DB_API`, `AUTH_DB_NAME` | the two database names — never guessed |
40
40
  | `AUTH_SUPER_ADMIN_EMAIL` / `_PASSWORD` | the first account — created once, when the sign-in database is first set up |
41
+ | `AUTH_TENANT_HEADER` | `none`: one set of roles for everyone. A multi-tenant app names its company header (e.g. `x-company-id`), so a role made inside a company belongs to it |
41
42
  | `EMAIL_PROVIDER` and its settings | optional; without them sign-in works, but activation and reset links cannot be sent |
@@ -50,6 +50,12 @@ XEPLR_AUTH_MIGRATIONS=./node_modules/@xeplr/factory/migrations-auth,./migrations
50
50
  AUTH_SUPER_ADMIN_EMAIL=__ADMIN_EMAIL__
51
51
  AUTH_SUPER_ADMIN_PASSWORD=__ADMIN_PASSWORD__
52
52
 
53
+ # ── Which company a role belongs to ──
54
+ # none: this app has one set of roles for everyone. A multi-tenant app names
55
+ # the header that carries the company id instead (e.g. x-company-id), so a
56
+ # role made inside a company belongs to that company.
57
+ AUTH_TENANT_HEADER=none
58
+
53
59
  # ── Links that go out in emails ──
54
60
  # FULLY QUALIFIED, and they point at UI pages rather than at the API. The
55
61
  # sign-in service builds these links and appends the token as ?token=... — an
@@ -30,6 +30,8 @@ AUTH_URL=http://127.0.0.1:__AUTH_PORT__
30
30
  XEPLR_AUTH_MIGRATIONS=./node_modules/@xeplr/factory/migrations-auth,./migrations-auth,./node_modules/@xeplr/workflow/migrations-auth
31
31
  AUTH_SUPER_ADMIN_EMAIL=
32
32
  AUTH_SUPER_ADMIN_PASSWORD=
33
+ # none for one set of roles; a multi-tenant app names its company header, e.g. x-company-id
34
+ AUTH_TENANT_HEADER=none
33
35
 
34
36
  # ── Public addresses (what people's browsers open) ──
35
37
  AUTH_ACTIVATION_URL=https://app.example.com/auth/activate
@@ -2,6 +2,9 @@
2
2
  //
3
3
  // Forms every UI in the app: make one, design it, publish it, open it, add it
4
4
  // to the side rail
5
+ // Masters the lists the rest of the app points at — departments, statuses,
6
+ // countries. Ordinary forms with a flag, gathered in one place because
7
+ // that is what they are: reference data, not daily work
5
8
  // Menu the side rail's items: rename, reorder, hide
6
9
  // Flows forms one after another — what is filled in decides the next; run by
7
10
  // Xeplr Workflow, and says how to connect it until it is
@@ -10,11 +13,13 @@
10
13
  // people use.
11
14
  import { useSearchParams } from 'react-router-dom'
12
15
  import Forms from './Forms.jsx'
16
+ import Masters from './Masters.jsx'
13
17
  import MenuSettings from './MenuSettings.jsx'
14
18
  import Flows from './Flows.jsx'
15
19
 
16
20
  const TABS = [
17
21
  { id: 'forms', label: 'Forms', Page: Forms },
22
+ { id: 'masters', label: 'Masters', Page: Masters },
18
23
  { id: 'flows', label: 'Flows', Page: Flows },
19
24
  { id: 'menu', label: 'Menu', Page: MenuSettings }
20
25
  ]
@@ -9,27 +9,56 @@
9
9
  // Claude can make forms too — see "Create a new UI" in CLAUDE.md.
10
10
  import { useCallback, useEffect, useState } from 'react'
11
11
  import { useNavigate } from 'react-router-dom'
12
- import { listMenuItems, addMenuItem, removeMenuItem, useAccess } from '@xeplr/ui-account'
12
+ import { listMenuItems, addMenuItem, removeMenuItem, useAccess, getUsers } from '@xeplr/ui-account'
13
+ import { deleteForm } from '@xeplr/ui-factory'
14
+ // THE APP'S OWN DIALOGS. window.confirm cannot say which button is the
15
+ // dangerous one and looks like a different piece of software appearing over
16
+ // this one; a red box pinned to the page stays there until something else
17
+ // replaces it, long after it has been read.
18
+ import { raiseConfirm, raiseSnackbar } from '@xeplr/ui-utils'
13
19
  import { factory } from '../api/factory.js'
14
20
  import { FORM_MENU_PREFIX } from '../menu.js'
15
21
 
16
- /** listScreens rows → one entry per form: { key, name, source, list, edit }. */
22
+ /**
23
+ * listScreens rows → one entry per form.
24
+ *
25
+ * `description` and `createdBy` travel with it because of the thing that
26
+ * happens once more than a handful of people can make forms: three of them
27
+ * are called "Inspection", and the fields say what each HOLDS, never what it
28
+ * was for or whose it is. Deciding which to keep is otherwise guesswork.
29
+ */
17
30
  function groupForms(rows) {
18
31
  const byKey = new Map()
19
32
  rows.forEach((row) => {
20
33
  const m = /^(.*)_(list|edit)$/.exec(row.screenKey)
21
34
  const key = m ? m[1] : row.screenKey
22
- const entry = byKey.get(key) || { key, name: null, source: null, list: null, edit: null }
35
+ const entry = byKey.get(key) || {
36
+ key, name: null, source: null, list: null, edit: null,
37
+ description: null, createdBy: null, createdDate: null
38
+ }
23
39
  if (m) entry[m[2]] = row
24
40
  else entry.edit = row
25
41
  if (m && m[2] === 'list') entry.name = row.name
26
42
  entry.name = entry.name || row.name
27
43
  entry.source = entry.source || row.source
44
+ entry.description = entry.description || row.description
45
+ // The form's own half is the one that speaks for it; a list screen is
46
+ // only consulted when there is no other answer.
47
+ if (m && m[2] === 'edit') { entry.createdBy = row.createdBy; entry.createdDate = row.createdDate }
48
+ entry.createdBy = entry.createdBy || row.createdBy
49
+ entry.createdDate = entry.createdDate || row.createdDate
28
50
  byKey.set(key, entry)
29
51
  })
30
52
  return [...byKey.values()].sort((a, b) => String(a.name).localeCompare(String(b.name)))
31
53
  }
32
54
 
55
+ /** "3 Feb 2026" — enough to tell two forms apart, no more. */
56
+ function madeOn(when) {
57
+ if (!when) return null
58
+ const d = new Date(when)
59
+ return isNaN(d) ? null : d.toLocaleDateString(undefined, { day: 'numeric', month: 'short', year: 'numeric' })
60
+ }
61
+
33
62
  function state(screen) {
34
63
  if (!screen) return { label: '—', unpublished: false }
35
64
  if (screen.version === null) return { label: 'Not published yet', unpublished: true }
@@ -50,16 +79,19 @@ export default function Forms() {
50
79
  const navigate = useNavigate()
51
80
  const { refreshAccess } = useAccess()
52
81
  const [forms, setForms] = useState(null)
82
+ // WHO MADE EACH ONE. The screens table keeps the maker's id; the names live
83
+ // in the sign-in service, so they are fetched once here and matched up.
84
+ // Failing to get them is not an error worth showing — the date alone still
85
+ // tells two forms of the same name apart.
86
+ const [people, setPeople] = useState({})
53
87
  const [inMenu, setInMenu] = useState(new Set())
54
- const [error, setError] = useState(null)
55
- const [notice, setNotice] = useState(null)
56
88
  const [label, setLabel] = useState('')
57
89
  const [key, setKey] = useState('')
58
90
  const [keyEdited, setKeyEdited] = useState(false)
59
91
  const [busy, setBusy] = useState(null)
60
92
 
61
93
  const load = useCallback(() => {
62
- factory.listScreens().then((rows) => { setForms(groupForms(rows)); setError(null) }, (e) => setError(e.message))
94
+ factory.listScreens().then((rows) => setForms(groupForms(rows)), (e) => raiseSnackbar(e.message, { design: 'error' }))
63
95
  listMenuItems().then(
64
96
  (items) => setInMenu(new Set(items.filter((m) => m.name.startsWith(FORM_MENU_PREFIX) && !m.isHidden).map((m) => m.name.slice(FORM_MENU_PREFIX.length)))),
65
97
  () => {}
@@ -67,6 +99,21 @@ export default function Forms() {
67
99
  }, [])
68
100
  useEffect(load, [load])
69
101
 
102
+ // Once. A name per row would be one request per form, and these change far
103
+ // more slowly than the page is opened.
104
+ useEffect(() => {
105
+ let cancelled = false
106
+ getUsers()
107
+ .then((rows) => {
108
+ if (cancelled) return
109
+ const by = {}
110
+ ;(rows || []).forEach((u) => { by[u.id] = u.name || u.email || u.id })
111
+ setPeople(by)
112
+ })
113
+ .catch(() => {})
114
+ return () => { cancelled = true }
115
+ }, [])
116
+
70
117
  const onLabel = (value) => {
71
118
  setLabel(value)
72
119
  if (!keyEdited) setKey(suggestKey(value))
@@ -79,28 +126,63 @@ export default function Forms() {
79
126
  const made = await factory.createEntity({ key: key.trim(), label: label.trim() })
80
127
  navigate('/configure/forms/' + made.key + '/design/form')
81
128
  } catch (err) {
82
- setError(err.message)
129
+ raiseSnackbar(err.message, { design: 'error' })
83
130
  setBusy(null)
84
131
  }
85
132
  }
86
133
 
87
134
  // The form first — publishing it creates or changes the table — then the list.
135
+ /**
136
+ * Delete a form. Asked first, in the words of what will actually happen
137
+ * rather than "are you sure": the design goes, and the records do not
138
+ * unless there are none.
139
+ */
140
+ const remove = async (form) => {
141
+ const ok = await raiseConfirm(
142
+ 'Its design goes. Its table and any records in it are kept unless the table is empty.',
143
+ {
144
+ title: 'Delete "' + (form.name || form.key) + '"?',
145
+ confirmLabel: 'Delete',
146
+ // Red, because it cannot be undone from here.
147
+ danger: true
148
+ }
149
+ )
150
+ if (!ok) return
151
+ setBusy(form.key)
152
+ try {
153
+ const out = await deleteForm(factory, form)
154
+ // Said plainly: somebody deleting a form expects all of it to go, and a
155
+ // table left behind is worth knowing about rather than discovering.
156
+ if (out && out.records > 0) {
157
+ raiseSnackbar('"' + (form.name || form.key) + '" is gone. Its table "' + out.table + '" was kept — it still holds ' +
158
+ out.records + ' record' + (out.records === 1 ? '' : 's') + '.', { design: 'info' })
159
+ } else if (out && out.tableDropped) {
160
+ raiseSnackbar('"' + (form.name || form.key) + '" and its empty table are gone.', { design: 'success' })
161
+ } else {
162
+ raiseSnackbar('"' + (form.name || form.key) + '" is gone.', { design: 'success' })
163
+ }
164
+ load()
165
+ } catch (err) {
166
+ raiseSnackbar(err.message, { design: 'error' })
167
+ } finally {
168
+ setBusy(null)
169
+ }
170
+ }
171
+
88
172
  const publish = async (form) => {
89
173
  setBusy(form.key)
90
- setNotice(null)
91
174
  try {
92
175
  for (const screen of [form.edit, form.list]) {
93
176
  if (!screen || (screen.version !== null && !screen.hasDraft)) continue
94
177
  const row = await factory.loadDraft(screen.screenKey)
95
178
  await factory.publish(row.document)
96
179
  }
97
- setNotice('Published "' + form.name + '"')
98
- setError(null)
180
+ raiseSnackbar('Published "' + form.name + '"', { design: 'success' })
99
181
  load()
100
182
  } catch (err) {
101
- setError(err.confirm
183
+ raiseSnackbar(err.confirm
102
184
  ? 'Publishing "' + form.name + '" would remove columns and their data — open Design form and publish there to see what, and confirm.'
103
- : err.message)
185
+ : err.message, { design: 'error' })
104
186
  } finally {
105
187
  setBusy(null)
106
188
  }
@@ -112,10 +194,10 @@ export default function Forms() {
112
194
  if (inMenu.has(form.key)) await removeMenuItem(FORM_MENU_PREFIX + form.key)
113
195
  else await addMenuItem({ name: FORM_MENU_PREFIX + form.key, label: form.name })
114
196
  await refreshAccess()
115
- setNotice(inMenu.has(form.key) ? 'Removed "' + form.name + '" from the menu' : 'Added "' + form.name + '" to the menu — rename or move it in the Menu tab')
197
+ raiseSnackbar(inMenu.has(form.key) ? 'Removed "' + form.name + '" from the menu' : 'Added "' + form.name + '" to the menu — rename or move it in the Menu tab', { design: 'success' })
116
198
  load()
117
199
  } catch (err) {
118
- setError(err.message)
200
+ raiseSnackbar(err.message, { design: 'error' })
119
201
  } finally {
120
202
  setBusy(null)
121
203
  }
@@ -141,8 +223,6 @@ export default function Forms() {
141
223
  </button>
142
224
  </form>
143
225
 
144
- {error && <div className="app-error">{error}</div>}
145
- {notice && <div className="app-notice">{notice}</div>}
146
226
 
147
227
  {forms && forms.length === 0 && <p className="app-sub">No forms yet.</p>}
148
228
  {forms && forms.length > 0 && (
@@ -157,7 +237,19 @@ export default function Forms() {
157
237
  const canOpen = form.list && form.list.version !== null
158
238
  return (
159
239
  <tr key={form.key}>
160
- <td><strong>{form.name || form.key}</strong><div className="app-sub">{form.key}</div></td>
240
+ <td>
241
+ <strong>{form.name || form.key}</strong>
242
+ <div className="app-sub">{form.key}</div>
243
+ {/* WHAT IT IS FOR, and whose it is — the two things that
244
+ tell three forms of the same name apart. The date
245
+ stands alone when the names cannot be fetched. */}
246
+ {form.description && <div className="app-sub">{form.description}</div>}
247
+ {(form.createdBy || form.createdDate) && (
248
+ <div className="app-sub">
249
+ {[people[form.createdBy], madeOn(form.createdDate)].filter(Boolean).join(' · ')}
250
+ </div>
251
+ )}
252
+ </td>
161
253
  <td><code>{form.source || '—'}</code></td>
162
254
  <td className={edit.unpublished ? 'app-forms-pending' : undefined}>{edit.label}</td>
163
255
  <td className={list.unpublished ? 'app-forms-pending' : undefined}>{list.label}</td>
@@ -173,6 +265,17 @@ export default function Forms() {
173
265
  {busy === form.key ? 'Publishing…' : 'Publish'}
174
266
  </button>
175
267
  )}
268
+ {/* The design always goes; the TABLE only when it is empty
269
+ and nothing else describes it. Records are never lost
270
+ to a click — @xeplr/factory refuses to drop a table
271
+ with rows in it and says how many kept it. */}
272
+ <button
273
+ className="app-btn app-btn-quiet app-btn-danger"
274
+ disabled={busy === form.key}
275
+ onClick={() => remove(form)}
276
+ >
277
+ Delete
278
+ </button>
176
279
  </td>
177
280
  </tr>
178
281
  )
@@ -0,0 +1,114 @@
1
+ // CONFIGURE UI → MASTERS — the lists the rest of the app points at.
2
+ //
3
+ // Departments, statuses, countries, categories: small tables that other forms
4
+ // choose from. They are ordinary forms with a flag (Design → This is a
5
+ // master), so they have a table, a list, an edit screen and permissions like
6
+ // anything else — a master is a fact about a form, not a kind of form.
7
+ //
8
+ // They are gathered HERE rather than scattered through the side rail because
9
+ // that is what they are: reference data somebody maintains occasionally, not
10
+ // pages people work in daily. The rail stays for the work.
11
+ //
12
+ // Which forms are masters is @xeplr/ui-factory's answer (`useScreenSource`),
13
+ // not this app's — grouping two screens into a form and reading the flag is
14
+ // the same code in every app, and a copy here could never be fixed centrally.
15
+ import { useState } from 'react'
16
+ import { Link } from 'react-router-dom'
17
+ import { useScreenSource, createMaster, possibleParents, FactoryBuilder } from '@xeplr/ui-factory'
18
+ import { factory } from '../api/factory.js'
19
+
20
+ export default function Masters() {
21
+ const { masters, loading, reload } = useScreenSource(factory, { Builder: FactoryBuilder })
22
+ const [name, setName] = useState('')
23
+ const [parent, setParent] = useState('')
24
+ const [busy, setBusy] = useState(false)
25
+ const [error, setError] = useState(null)
26
+
27
+ // MADE, NOT DESIGNED. A master is a name, an order and what it belongs to —
28
+ // the same three things every time — so it is created outright and the
29
+ // builder is for the day one needs a fourth field.
30
+ const create = async (e) => {
31
+ e.preventDefault()
32
+ if (!name.trim() || busy) return
33
+ setBusy(true)
34
+ try {
35
+ const owner = masters.find((m) => m.key === parent)
36
+ await createMaster(factory, {
37
+ name: name.trim(),
38
+ parent: owner ? { table: owner.source, label: owner.name } : null
39
+ })
40
+ setName('')
41
+ setParent('')
42
+ setError(null)
43
+ reload()
44
+ } catch (err) {
45
+ setError(err.message)
46
+ } finally {
47
+ setBusy(false)
48
+ }
49
+ }
50
+
51
+ if (loading) return <p className="app-sub">Loading…</p>
52
+
53
+ return (
54
+ <div className="app-forms">
55
+ <p className="app-page-lead">
56
+ The lists the rest of the app chooses from. A master is a name, an order of your own,
57
+ and — when it belongs to one — the master above it.
58
+ </p>
59
+
60
+ {error && <div className="app-error">{error}</div>}
61
+
62
+ <form className="app-forms-new" onSubmit={create}>
63
+ <label className="app-forms-field">
64
+ <span>New master</span>
65
+ <input value={name} onChange={(e) => setName(e.target.value)} placeholder="Departments" />
66
+ </label>
67
+ {/* Only worth asking once there is something to belong to. */}
68
+ {masters.length > 0 && (
69
+ <label className="app-forms-field">
70
+ <span>Belongs to</span>
71
+ <select value={parent} onChange={(e) => setParent(e.target.value)}>
72
+ <option value="">— nothing —</option>
73
+ {possibleParents(masters).map((m) => (
74
+ <option key={m.key} value={m.key}>{m.name}</option>
75
+ ))}
76
+ </select>
77
+ </label>
78
+ )}
79
+ <button type="submit" className="app-btn" disabled={!name.trim() || busy}>
80
+ {busy ? 'Making it…' : 'Make the master'}
81
+ </button>
82
+ </form>
83
+
84
+ {masters.length === 0 && (
85
+ <p className="app-sub">
86
+ No masters yet. Departments, statuses, countries — anything other forms point at.
87
+ </p>
88
+ )}
89
+
90
+ {masters.length > 0 && (
91
+ <table className="app-table">
92
+ <thead><tr><th>Master</th><th>Shown as</th><th>Table</th><th /></tr></thead>
93
+ <tbody>
94
+ {masters.map((m) => (
95
+ <tr key={m.key}>
96
+ <td><strong>{m.name}</strong></td>
97
+ {/* What a picker shows for one of its records — said once on
98
+ the master, not again on every dropdown pointing at it. */}
99
+ <td className="app-sub">{m.labelField || '—'}</td>
100
+ <td className="app-sub">{m.source || '—'}</td>
101
+ <td className="app-row-actions">
102
+ {/* Its records: the list screen is what looking at a master
103
+ means. Its design is where the flag was set. */}
104
+ <Link to={`/forms/${m.key}`}>Open</Link>
105
+ <Link to={`/configure/forms/${m.key}/design/form`}>Design</Link>
106
+ </td>
107
+ </tr>
108
+ ))}
109
+ </tbody>
110
+ </table>
111
+ )}
112
+ </div>
113
+ )
114
+ }