@proveanything/smartlinks 2.1.17 → 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.
Files changed (80) hide show
  1. package/dist/adminViews.d.ts +104 -0
  2. package/dist/adminViews.js +275 -0
  3. package/dist/api/ai.d.ts +15 -5
  4. package/dist/api/ai.js +15 -9
  5. package/dist/api/aiGuide.d.ts +108 -0
  6. package/dist/api/aiGuide.js +161 -0
  7. package/dist/api/appObjects.d.ts +21 -0
  8. package/dist/api/appObjects.js +33 -1
  9. package/dist/api/authKit.d.ts +37 -1
  10. package/dist/api/authKit.js +51 -0
  11. package/dist/api/index.d.ts +2 -0
  12. package/dist/api/index.js +2 -0
  13. package/dist/api/operations.d.ts +36 -0
  14. package/dist/api/operations.js +56 -0
  15. package/dist/api/order.d.ts +12 -1
  16. package/dist/api/order.js +15 -0
  17. package/dist/api/userGroups.d.ts +78 -0
  18. package/dist/api/userGroups.js +124 -0
  19. package/dist/docs/API_SUMMARY.md +1111 -80
  20. package/dist/docs/admin-lists-and-pickers.md +140 -0
  21. package/dist/docs/admin-views.md +147 -0
  22. package/dist/docs/app-data-storage.md +277 -276
  23. package/dist/docs/app-manifest.md +2 -0
  24. package/dist/docs/auth-kit.md +872 -741
  25. package/dist/docs/comms.md +686 -644
  26. package/dist/docs/customer-guide.md +70 -0
  27. package/dist/docs/headless-providers.md +112 -112
  28. package/dist/docs/operations.md +281 -0
  29. package/dist/docs/overview.md +3 -0
  30. package/dist/docs/server-functions.md +87 -1
  31. package/dist/docs/ui-utils.md +123 -121
  32. package/dist/docs/user-groups.md +175 -0
  33. package/dist/docs/utils.md +17 -0
  34. package/dist/headless.js +38 -2
  35. package/dist/http.js +8 -0
  36. package/dist/iframeResponder.d.ts +15 -0
  37. package/dist/iframeResponder.js +39 -1
  38. package/dist/index.d.ts +3 -1
  39. package/dist/index.js +2 -0
  40. package/dist/live.d.ts +80 -0
  41. package/dist/live.js +315 -0
  42. package/dist/openapi.yaml +1864 -48
  43. package/dist/testing/index.d.ts +35 -0
  44. package/dist/testing/index.js +86 -0
  45. package/dist/types/appManifest.d.ts +297 -1
  46. package/dist/types/appOptions.d.ts +32 -0
  47. package/dist/types/appOptions.js +3 -0
  48. package/dist/types/authKit.d.ts +193 -4
  49. package/dist/types/comms.d.ts +41 -2
  50. package/dist/types/containers.d.ts +8 -0
  51. package/dist/types/headless.d.ts +49 -1
  52. package/dist/types/iframeResponder.d.ts +16 -1
  53. package/dist/types/index.d.ts +3 -0
  54. package/dist/types/index.js +3 -0
  55. package/dist/types/operations.d.ts +598 -0
  56. package/dist/types/operations.js +8 -0
  57. package/dist/types/order.d.ts +35 -6
  58. package/dist/types/userGroups.d.ts +103 -0
  59. package/dist/types/userGroups.js +5 -0
  60. package/dist/utils/conditions.d.ts +7 -0
  61. package/dist/utils/conditions.js +16 -9
  62. package/docs/API_SUMMARY.md +1111 -80
  63. package/docs/admin-lists-and-pickers.md +140 -0
  64. package/docs/admin-views.md +147 -0
  65. package/docs/app-data-storage.md +277 -276
  66. package/docs/app-manifest.md +2 -0
  67. package/docs/auth-kit.md +872 -741
  68. package/docs/comms.md +686 -644
  69. package/docs/customer-guide.md +70 -0
  70. package/docs/headless-providers.md +112 -112
  71. package/docs/operations.md +281 -0
  72. package/docs/overview.md +3 -0
  73. package/docs/server-functions.md +87 -1
  74. package/docs/ui-utils.md +123 -121
  75. package/docs/user-groups.md +175 -0
  76. package/docs/utils.md +17 -0
  77. package/openapi.yaml +1864 -48
  78. package/package.json +1 -1
  79. package/scripts/doctor.mjs +454 -428
  80. 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
+ ```
@@ -0,0 +1,147 @@
1
+ # Admin views
2
+
3
+ An app's **admin views** are its admin screens by name: "the campaigns list", "one campaign", "bookings
4
+ for a day". The app declares them once, in `app.manifest.json#adminViews`, and three things read the same
5
+ list:
6
+
7
+ | Reader | What it does with the views |
8
+ |---|---|
9
+ | **The app's own side menu** | areas (`main`) in order, Settings (`settings`) at the bottom; opening a record swaps in that record's views |
10
+ | **Studio's workspace menu** (coming) | lifts an app's areas into the business's own menu, then opens the app with `chrome=none` |
11
+ | **The Studio assistant** | opens a view while it talks: "here are Saturday's bookings" |
12
+
13
+ Admin views are not portal pages (`linkable`, see [deep-link-discovery.md](deep-link-discovery.md)) and
14
+ not standalone screens (`publicViews`). They are the admin side only.
15
+
16
+ Core apps with three or more areas follow prove `server/docs/design/core-app-layout.md`. Their side menu
17
+ is built from these views.
18
+
19
+ ---
20
+
21
+ ## Declaring views
22
+
23
+ ```json
24
+ "adminViews": [
25
+ { "id": "campaigns", "title": "Campaigns", "path": "/campaigns", "icon": "megaphone",
26
+ "description": "Campaigns: drafts, scheduled and sent, with their results.",
27
+ "params": { "status": "draft | scheduled | sent" } },
28
+ { "id": "campaign", "title": "Campaign", "path": "/campaigns/{campaignId}", "group": "record",
29
+ "within": "campaigns", "params": { "campaignId": "a campaign's id" },
30
+ "description": "One campaign: its message, who it goes to, and how it landed." },
31
+ { "id": "log", "title": "Message log", "path": "/log", "icon": "scroll-text" },
32
+ { "id": "settings", "title": "Settings", "path": "/settings", "icon": "settings", "group": "settings" }
33
+ ]
34
+ ```
35
+
36
+ | Field | Meaning |
37
+ |---|---|
38
+ | `id` | Stable, unique in the app. Hosts and the assistant keep it, so never reuse one for another screen. |
39
+ | `title` | The menu label, in the business's words. |
40
+ | `path` | Hash route in the admin page. `{name}` marks a required param. |
41
+ | `group` | `main` (default), an area in the menu. `settings`, pinned at the bottom. `record`, a screen inside one record, never in the main menu. |
42
+ | `within` | The view this one sits in. A record's first view names its area. The record's other views name the record's first view. |
43
+ | `icon` | A [Lucide](https://lucide.dev/icons) name, kebab-case. |
44
+ | `description` | One line on what the screen shows. The assistant reads it to choose a view. |
45
+ | `params` | Each param, with a few words on what it is. `{name}` params are required; the rest are optional query params. Never list platform context (`collectionId`, `appId`, …). |
46
+
47
+ **A record with several screens** (a product with details, proofs and variants):
48
+
49
+ ```json
50
+ { "id": "product", "title": "Details", "path": "/products/{productId}", "group": "record", "within": "products" },
51
+ { "id": "product.proofs", "title": "Proofs", "path": "/products/{productId}/proofs", "group": "record", "within": "product" },
52
+ { "id": "product.variants", "title": "Variants", "path": "/products/{productId}/variants", "group": "record", "within": "product" }
53
+ ```
54
+
55
+ While a product is open, the menu reads "← Products", then Details, Proofs, Variants.
56
+
57
+ Declare only screens worth opening by name. A dialog, a step inside a form or a filter state is not a
58
+ view; it is a param of one (`status`, `tab`).
59
+
60
+ ---
61
+
62
+ ## Building the menu from them
63
+
64
+ Import the manifest so there is one list, and use the helpers:
65
+
66
+ ```ts
67
+ import * as SL from '@proveanything/smartlinks'
68
+ import manifest from '../public/app.manifest.json'
69
+
70
+ const views = manifest.adminViews as SL.AdminView[]
71
+
72
+ SL.adminViews.menu(views) // { main: [...areas], settings: [...] }
73
+ SL.adminViews.match(views, location.pathname) // { view, params } | null — what screen this is
74
+ SL.adminViews.trail(views, 'campaign') // [campaigns, campaign] — campaigns is the current menu item
75
+ SL.adminViews.recordMenu(views, 'campaign') // { back: campaigns, record, items } — the swapped menu
76
+ SL.adminViews.pathFor(views[1], { campaignId }) // '/campaigns/c_1'
77
+ ```
78
+
79
+ Route the app by these paths, not by a `?tab=` param. The host keeps the path in its own address
80
+ (`?path=`), so a screen survives a reload and can be shared.
81
+
82
+ ---
83
+
84
+ ## Following the host: `smartlinks:navigate`
85
+
86
+ The host (Studio, the assistant) asks the app to open a screen without reloading it:
87
+
88
+ ```
89
+ host → app { type: 'smartlinks:navigate', view?: 'campaign', params?: { campaignId: 'c_1' }, path?: '/log', highlight?: 'row-id' }
90
+ ```
91
+
92
+ Register once, near the router:
93
+
94
+ ```ts
95
+ const navigate = useNavigate()
96
+ useEffect(() => SL.adminViews.onNavigate(views, (to) => navigate(to.path)), [navigate])
97
+ ```
98
+
99
+ - Registering posts `smartlinks:navigable` to the host. A host that never hears it (an older build)
100
+ reloads the frame at the new path instead.
101
+ - Only messages from the parent window are taken. A `view` is resolved to its path, and a raw `path`
102
+ must be a hash route of this app.
103
+ - After each request the app posts `smartlinks:navigate-result` `{ ok, view, path, reason? }`, so the
104
+ assistant can say when a screen couldn't be opened.
105
+ - `highlight` is optional. It is an id the app understands, such as a row to point at; ignore it if you
106
+ have nothing to point at.
107
+
108
+ Hosts on the SDK use `IframeResponder.navigate(req)`, which returns `false` when the app isn't
109
+ navigable. Hosts with their own frame code use `SL.adminViews.postNavigate(frame.contentWindow, req)`.
110
+
111
+ ---
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
+
135
+ ## `chrome=none`: the host carries the menu
136
+
137
+ When a host's own menu already lists an app's views, it opens the app with `chrome=none`. The app then
138
+ hides its side menu and the bar holding its toggle, and shows only the content. The page header
139
+ (`AdminPageHeader`) stays: it is content.
140
+
141
+ ```ts
142
+ const bare = SL.adminViews.hostChrome() === 'none'
143
+ ```
144
+
145
+ `hostChrome()` reads the address the page was first opened at, so the app's own navigation can't lose it.
146
+ With `chrome=none` the app moves between areas only when the host says so (`smartlinks:navigate`).
147
+ Links inside the content, such as opening a campaign from the list, still work as normal.