@proveanything/smartlinks 2.1.18 → 2.1.19
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/dist/adminViews.d.ts +19 -0
- package/dist/adminViews.js +16 -0
- package/dist/api/ai.d.ts +15 -5
- package/dist/api/ai.js +15 -9
- package/dist/api/aiGuide.d.ts +108 -0
- package/dist/api/aiGuide.js +161 -0
- package/dist/api/appObjects.d.ts +21 -0
- package/dist/api/appObjects.js +33 -1
- package/dist/api/authKit.d.ts +37 -1
- package/dist/api/authKit.js +51 -0
- package/dist/docs/API_SUMMARY.md +509 -40
- package/dist/docs/admin-lists-and-pickers.md +140 -0
- package/dist/docs/admin-views.md +22 -0
- package/dist/docs/app-data-storage.md +277 -276
- package/dist/docs/auth-kit.md +872 -741
- package/dist/docs/comms.md +686 -644
- package/dist/docs/customer-guide.md +70 -0
- package/dist/docs/headless-providers.md +112 -112
- package/dist/docs/server-functions.md +69 -1
- package/dist/docs/ui-utils.md +123 -121
- package/dist/docs/user-groups.md +175 -168
- package/dist/headless.js +38 -2
- package/dist/http.js +4 -0
- package/dist/index.d.ts +2 -2
- package/dist/live.d.ts +80 -0
- package/dist/live.js +315 -0
- package/dist/openapi.yaml +888 -34
- package/dist/testing/index.d.ts +22 -0
- package/dist/testing/index.js +31 -0
- package/dist/types/appManifest.d.ts +214 -1
- package/dist/types/appOptions.d.ts +32 -0
- package/dist/types/appOptions.js +3 -0
- package/dist/types/authKit.d.ts +193 -4
- package/dist/types/comms.d.ts +41 -2
- package/dist/types/headless.d.ts +49 -1
- package/dist/types/iframeResponder.d.ts +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/docs/API_SUMMARY.md +509 -40
- package/docs/admin-lists-and-pickers.md +140 -0
- package/docs/admin-views.md +22 -0
- package/docs/app-data-storage.md +277 -276
- package/docs/auth-kit.md +872 -741
- package/docs/comms.md +686 -644
- package/docs/customer-guide.md +70 -0
- package/docs/headless-providers.md +112 -112
- package/docs/server-functions.md +69 -1
- package/docs/ui-utils.md +123 -121
- package/docs/user-groups.md +175 -168
- package/openapi.yaml +888 -34
- package/package.json +1 -1
- package/scripts/doctor.mjs +454 -428
- package/scripts/lib/keyed-app-data.mjs +21 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# Lists an admin edits: value lists, set-up types and pickers
|
|
2
|
+
|
|
3
|
+
Most apps have lists the business keeps up to date: the machines on a floor, the desks in a room,
|
|
4
|
+
hold reasons, teams. This page says where each kind lives and how a screen picks from it quickly.
|
|
5
|
+
Design note: `prove/server/docs/design/admin-lists-and-pickers.md`.
|
|
6
|
+
|
|
7
|
+
## Which home
|
|
8
|
+
|
|
9
|
+
Ask in order; the first yes wins.
|
|
10
|
+
|
|
11
|
+
| Question | Home |
|
|
12
|
+
|---|---|
|
|
13
|
+
| Is it something SmartLinks already has (contacts, products, work orders, stock, bookings)? | That object. Don't redeclare it; point at it with a `ref` field |
|
|
14
|
+
| Is there one of it per collection (or product, variant, batch)? | **Settings**: `SL.appConfiguration.getConfig` / `setConfig` |
|
|
15
|
+
| Does your code branch on the values (`if (stage === "filling")`)? | A **fixed enum**: `"type": "enum", "options": [...]`, changed by a release |
|
|
16
|
+
| Is it just values the admin adds, renames, reorders or switches off? | A **value list**: `data.lists`, picked by `"type": "enum", "list": "<id>"` |
|
|
17
|
+
| Does each entry have its own fields or point at other things? | A **set-up type**: app records of a declared type |
|
|
18
|
+
|
|
19
|
+
Don't keep lists of things in keyed app data (`getData` / `setData`): it has no type, no search and
|
|
20
|
+
no checks, and it is being retired. Use a set-up type.
|
|
21
|
+
|
|
22
|
+
## Value lists
|
|
23
|
+
|
|
24
|
+
Declare the list and its starting values in the manifest's `data` block. An `enum` field picks from
|
|
25
|
+
it with `list` instead of `options`:
|
|
26
|
+
|
|
27
|
+
```jsonc
|
|
28
|
+
"data": {
|
|
29
|
+
"schemaVersion": "1.0.0",
|
|
30
|
+
"lists": {
|
|
31
|
+
"hold-reasons": {
|
|
32
|
+
"label": "Hold reasons",
|
|
33
|
+
"values": [
|
|
34
|
+
{ "code": "awaiting-components", "label": "Awaiting components" },
|
|
35
|
+
{ "code": "customer-query", "label": "Customer query" }
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"types": {
|
|
40
|
+
"accord.job": {
|
|
41
|
+
"fields": { "holdReason": { "type": "enum", "list": "hold-reasons", "label": "Hold reason" } }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
- A record stores the value's **code**; screens show its label. Codes never change.
|
|
48
|
+
- The manifest's values are used until the admin first saves the list. After that the list is the
|
|
49
|
+
collection's.
|
|
50
|
+
- **Values are never deleted.** A value the admin leaves out is kept, switched off, so records that
|
|
51
|
+
carry it still show its label. Saving checks that codes are unique.
|
|
52
|
+
- `"editable": false` makes a list the app's alone (changed by a release). `"public": true` lets the
|
|
53
|
+
public API read it; otherwise only admins and server code can.
|
|
54
|
+
|
|
55
|
+
Save a list (admins): `SL.app.options.saveList(collectionId, appId, 'hold-reasons', [{ code, label, active }])`.
|
|
56
|
+
|
|
57
|
+
## Set-up types
|
|
58
|
+
|
|
59
|
+
A set-up type is an ordinary declared type (`storage: { kind: 'record' }`) with a few extra keys:
|
|
60
|
+
|
|
61
|
+
| Key | Meaning |
|
|
62
|
+
|---|---|
|
|
63
|
+
| `title` | The list's name in Studio's Set-up lists, plural and short ("Machines"). Default: the description |
|
|
64
|
+
| `label` | The field pickers show. Default `label`, then `name`, then `title` |
|
|
65
|
+
| `sublabel` | A field shown as the second line (a machine's stage) |
|
|
66
|
+
| `activeField` | A boolean field; `false` switches the entry off. Default: the record's status (`inactive` / `archived` = off) |
|
|
67
|
+
| `orderField` | A number field to sort by. Default `sortOrder`, then `order`, then the label |
|
|
68
|
+
| `small` | Dozens to hundreds of entries: `ctx.sl.appRecords.all` reads them from cache |
|
|
69
|
+
| `setup` | A list the admin keeps: Studio will draw a list and form for it. Implies `checked` |
|
|
70
|
+
| `checked` | Saves are checked against the declared fields |
|
|
71
|
+
|
|
72
|
+
```jsonc
|
|
73
|
+
"accord.machine": {
|
|
74
|
+
"description": "A machine on the production floor.",
|
|
75
|
+
"storage": { "kind": "record", "recordType": "machine" },
|
|
76
|
+
"visibility": "admin",
|
|
77
|
+
"label": "name", "sublabel": "stage", "activeField": "isActive",
|
|
78
|
+
"small": true, "setup": true,
|
|
79
|
+
"fields": {
|
|
80
|
+
"name": { "type": "string", "label": "Name", "required": true },
|
|
81
|
+
"stage": { "type": "enum", "options": ["Decoration", "Filling", "Packaging", "Wrapping"] },
|
|
82
|
+
"outputPerMinute": { "type": "number", "label": "Output per minute" },
|
|
83
|
+
"isActive": { "type": "boolean" }
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**Checks on save.** For a `checked` (or `setup`) type, a create or update whose data doesn't match is
|
|
89
|
+
refused with `400 INVALID_RECORD` and a `problems` list (`{ field, message }`), all problems at once:
|
|
90
|
+
wrong value types, missing required fields, an `enum` value not in its options or list, a `ref` to one
|
|
91
|
+
of the app's own types that names no live record. Fields you don't declare are left alone. Types
|
|
92
|
+
that aren't checked are never checked.
|
|
93
|
+
|
|
94
|
+
## Pickers: one call
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
// In any screen
|
|
98
|
+
const res = await SL.app.options.get(collectionId, appId, 'type:accord.machine', { admin: true })
|
|
99
|
+
const res = await SL.app.options.get(collectionId, appId, 'list:hold-reasons', { admin: true })
|
|
100
|
+
// → { items: [{ id, label, sublabel?, active, order }], version, mode: 'all' }
|
|
101
|
+
|
|
102
|
+
// In server code (needs sl:records:read)
|
|
103
|
+
await ctx.sl.appOptions.get('list:hold-reasons')
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
- `source` is `type:<declared type id or record type>` or `list:<list id>`.
|
|
107
|
+
- Entries carry only id, label, second line, on/off and order, never the record's data. They come
|
|
108
|
+
sorted. For a list, `id` is the value's code.
|
|
109
|
+
- **Switched-off entries come back too** (`active: false`). Hide them for new choices; keep showing
|
|
110
|
+
the label on records that already carry them.
|
|
111
|
+
- **Cached.** Saved, deleted and restored records clear their type's entry at once. Hold on to
|
|
112
|
+
`version` and pass it back (`{ version }`); if nothing changed you get `{ unchanged: true, version }`.
|
|
113
|
+
- **Large types.** A type with more than 2,000 entries answers `mode: 'search'` with no items; pass
|
|
114
|
+
`q` and it answers the first 50 whose label contains it.
|
|
115
|
+
- **Who sees what.** `admin: true` (the admin API) lists everything. The public API lists public
|
|
116
|
+
records, and lists declared `public`.
|
|
117
|
+
|
|
118
|
+
## Every record of a type, with its data
|
|
119
|
+
|
|
120
|
+
Server code that needs the fields as well (the capacity check reads every machine's rate):
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
const machines = await ctx.sl.appRecords.all('machine') // or 'accord.machine'
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Up to 5,000 records, oldest first; more is refused (`TOO_MANY`), so page with `query`. Read from cache
|
|
127
|
+
for `small` types, cleared on every write. Admin authority sees every record; other callers see the
|
|
128
|
+
public ones.
|
|
129
|
+
|
|
130
|
+
## Testing
|
|
131
|
+
|
|
132
|
+
`createFunctionTestContext` has both calls in memory. Records follow the default conventions; lists
|
|
133
|
+
come from the `valueLists` option:
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
const ctx = createFunctionTestContext({
|
|
137
|
+
def,
|
|
138
|
+
valueLists: { 'hold-reasons': [{ code: 'customer-query', label: 'Customer query' }] },
|
|
139
|
+
})
|
|
140
|
+
```
|
package/docs/admin-views.md
CHANGED
|
@@ -110,6 +110,28 @@ navigable. Hosts with their own frame code use `SL.adminViews.postNavigate(frame
|
|
|
110
110
|
|
|
111
111
|
---
|
|
112
112
|
|
|
113
|
+
## Opening another app: `smartlinks:open-app`
|
|
114
|
+
|
|
115
|
+
Apps link to each other's screens. Some examples:
|
|
116
|
+
- Messages opens a person in the CRM.
|
|
117
|
+
- The CRM opens that person's messages.
|
|
118
|
+
- A message about a booking opens the booking.
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
SL.adminViews.openApp({ appId: 'crm', view: 'contact', params: { contactId } })
|
|
122
|
+
// app → host { type: 'smartlinks:open-app', payload: { appId, view?, params?, path? } }
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
- **How the host resolves it.** Studio reads that app's published manifest `adminViews`, fills the
|
|
126
|
+
view's path from `params`, and opens the app there. The other app doesn't need any particular SDK,
|
|
127
|
+
only declared views.
|
|
128
|
+
- **Fallbacks.** An unknown view, or an app without views, opens at its start. A raw `path` (a hash
|
|
129
|
+
route of that app) is used as given.
|
|
130
|
+
- **Only that collection's apps.** The host opens only apps installed in, or core to, the collection
|
|
131
|
+
it is showing.
|
|
132
|
+
- **Name the views you link to** in your docs (`crm: contact`, `messages: log` with `contact`), and
|
|
133
|
+
keep their ids stable: other apps use them.
|
|
134
|
+
|
|
113
135
|
## `chrome=none`: the host carries the menu
|
|
114
136
|
|
|
115
137
|
When a host's own menu already lists an app's views, it opens the app with `chrome=none`. The app then
|