@proveanything/smartlinks 2.1.22 → 2.1.24
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/adminCardsView.d.ts +1 -1
- package/dist/adminCardsView.js +70 -55
- package/dist/api/appObjects.d.ts +26 -0
- package/dist/api/appObjects.js +31 -1
- package/dist/api/conditions.d.ts +51 -0
- package/dist/api/conditions.js +57 -0
- package/dist/api/contact.d.ts +23 -0
- package/dist/api/contact.js +30 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +1 -0
- package/dist/api/products.d.ts +22 -0
- package/dist/api/products.js +29 -0
- package/dist/api/proof.d.ts +30 -0
- package/dist/api/proof.js +37 -0
- package/dist/docs/API_SUMMARY.md +322 -172
- package/dist/docs/admin-cards.md +1 -1
- package/dist/docs/app-docs.md +73 -0
- package/dist/docs/app-manifest.md +20 -0
- package/dist/docs/standard-query.md +187 -0
- package/dist/docs/utils.md +22 -8
- package/dist/openapi.yaml +462 -0
- package/dist/types/adminCards.d.ts +2 -1
- package/dist/types/appManifest.d.ts +29 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/query.d.ts +121 -0
- package/dist/types/query.js +5 -0
- package/dist/utils/conditions.d.ts +1 -1
- package/dist/utils/conditions.js +21 -6
- package/docs/API_SUMMARY.md +322 -172
- package/docs/admin-cards.md +1 -1
- package/docs/app-docs.md +73 -0
- package/docs/app-manifest.md +20 -0
- package/docs/standard-query.md +187 -0
- package/docs/utils.md +22 -8
- package/openapi.yaml +462 -0
- package/package.json +1 -1
package/dist/docs/admin-cards.md
CHANGED
|
@@ -116,7 +116,7 @@ export async function cardUnanswered(ctx): Promise<AdminCardPayload> {
|
|
|
116
116
|
| `trend` | `{ direction: 'up'\|'down'\|'flat', label?, good? }` — `good` picks the colour |
|
|
117
117
|
| `status` | `{ tone: 'ok'\|'attention'\|'neutral'\|'error', text }` — `attention`/`error` also go to the To do strip |
|
|
118
118
|
| `progress` | `{ done, total, label? }` — a progress bar |
|
|
119
|
-
| `items` | Up to 5 rows `{ title, subtitle?, meta?, path? }` |
|
|
119
|
+
| `items` | Up to 5 rows `{ title, subtitle?, meta?, path?, image? }` — `image` is an https picture shown small beside the row (a product photo); an ISO-timestamp `meta` reads as a short date |
|
|
120
120
|
| `todo` | `[{ text, action? }]` — collected into the dashboard's To do strip |
|
|
121
121
|
| `actions` | Up to 2 buttons `{ label, path? \| url? }` — `path` opens your app's admin at that path |
|
|
122
122
|
| `empty` | `{ text, action? }` — shown instead of the body when there's nothing yet |
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# App docs: the manual that ships with your app
|
|
2
|
+
|
|
3
|
+
Every app can carry a manual for the people who use it: how to set it up, how to use it day to day,
|
|
4
|
+
what its settings do, what to do when something looks wrong. The manual lives in the app's own repo,
|
|
5
|
+
ships with every release, and for first-party apps is published on
|
|
6
|
+
[docs.smartlinks.app](https://docs.smartlinks.app) straight from the stable release. Nobody copies it
|
|
7
|
+
anywhere: release the app and its manual is live.
|
|
8
|
+
|
|
9
|
+
## Where it goes
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
public/
|
|
13
|
+
app.manifest.json
|
|
14
|
+
docs/
|
|
15
|
+
index.md ← front page
|
|
16
|
+
setup.md
|
|
17
|
+
settings.md
|
|
18
|
+
images/
|
|
19
|
+
inbox.png
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
`public/docs/` is copied into the build like any static file, so it reaches the CDN with the release:
|
|
23
|
+
`https://smartlinks.app/apps/<appId>/<channel>/docs/index.md`.
|
|
24
|
+
|
|
25
|
+
Keep internal notes (designs, plans, decisions) in `src/docs/` or anywhere outside `public/`.
|
|
26
|
+
Everything in `public/docs/` is public.
|
|
27
|
+
|
|
28
|
+
## Declare it in the manifest
|
|
29
|
+
|
|
30
|
+
```jsonc
|
|
31
|
+
// public/app.manifest.json
|
|
32
|
+
"docs": {
|
|
33
|
+
"pages": [
|
|
34
|
+
{ "file": "docs/index.md", "title": "Messages", "description": "Send campaigns and answer people in one inbox.", "audience": "team" },
|
|
35
|
+
{ "file": "docs/setup.md", "title": "Setting up", "description": "Senders, channels and who can reply.", "audience": "admin" },
|
|
36
|
+
{ "file": "docs/settings.md", "title": "Settings", "audience": "admin" }
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
| Field | |
|
|
42
|
+
|---|---|
|
|
43
|
+
| `pages[].file` | Path in the build, relative to `public/`. |
|
|
44
|
+
| `pages[].title` | Title in the docs menu. |
|
|
45
|
+
| `pages[].description` | One sentence: what the page helps with. Shown in listings and search. |
|
|
46
|
+
| `pages[].audience` | `team` (staff using the app, default), `admin` (setting it up), `customer` (the public), `developer` (building on it). |
|
|
47
|
+
| `listed` | `false` keeps the manual off docs.smartlinks.app. Default `true`. |
|
|
48
|
+
|
|
49
|
+
The first page is the front page. Pages appear in the order listed.
|
|
50
|
+
|
|
51
|
+
## Writing the pages
|
|
52
|
+
|
|
53
|
+
- Write for the person in front of the screen, in their words: "New campaign", not "the campaign
|
|
54
|
+
creation flow". Name buttons and screens exactly as the app shows them.
|
|
55
|
+
- One page per job: getting started, setting up, each main task, settings, troubleshooting.
|
|
56
|
+
- Short numbered steps for anything done in order.
|
|
57
|
+
- Images: put them in `public/docs/images/` and link them relatively (``).
|
|
58
|
+
Links between pages are relative too (`[Setting up](setup.md)`). The docs site rewrites both.
|
|
59
|
+
- Start each page with a `# ` heading. No frontmatter needed: the manifest carries title and order.
|
|
60
|
+
|
|
61
|
+
## Keep it current
|
|
62
|
+
|
|
63
|
+
Update the manual in the same change as the behaviour. Forge checks at release time: an app with no
|
|
64
|
+
`docs`, or a release whose code changed while `public/docs/` did not, gets a prompt to look at the
|
|
65
|
+
manual. It never blocks a release.
|
|
66
|
+
|
|
67
|
+
## Related
|
|
68
|
+
|
|
69
|
+
- [`ai-guide.md`](ai-guide-template.md) is for the AI that configures the app, not for people. Keep
|
|
70
|
+
both: the AI guide says what to set, the manual says how to use it.
|
|
71
|
+
- The manifest's `adminViews`, `functions` (with `agent` for [agent tools](agent-tools.md)) and
|
|
72
|
+
`assistant` blocks describe the app to software. The docs site lists them on a generated
|
|
73
|
+
reference page; the manual is the human-written part.
|
|
@@ -507,6 +507,26 @@ should say and how the assistant changes config with undo: **[assistant-apps.md]
|
|
|
507
507
|
|
|
508
508
|
---
|
|
509
509
|
|
|
510
|
+
#### `docs`
|
|
511
|
+
|
|
512
|
+
The app's manual, for the people who use it: Markdown pages under `public/docs/`, shipped with every
|
|
513
|
+
release. For first-party apps, docs.smartlinks.app reads the stable release's pages directly, so
|
|
514
|
+
releasing the app publishes its manual.
|
|
515
|
+
|
|
516
|
+
```jsonc
|
|
517
|
+
"docs": {
|
|
518
|
+
"pages": [
|
|
519
|
+
{ "file": "docs/index.md", "title": "Messages", "description": "Send campaigns and answer people in one inbox.", "audience": "team" },
|
|
520
|
+
{ "file": "docs/setup.md", "title": "Setting up", "audience": "admin" }
|
|
521
|
+
]
|
|
522
|
+
}
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
The first page is the front page. `audience` is `team` (default), `admin`, `customer` or `developer`.
|
|
526
|
+
`listed: false` keeps a manual off the docs site. What to write and how: **[app-docs.md](app-docs.md)**.
|
|
527
|
+
|
|
528
|
+
---
|
|
529
|
+
|
|
510
530
|
## `app.admin.json`
|
|
511
531
|
|
|
512
532
|
Fetched only by the admin UI and AI-assisted setup flows — never loaded on the public-facing page. Keep setup logic and configuration schemas here, not in the manifest.
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# The standard query
|
|
2
|
+
|
|
3
|
+
One request body to **filter, sort, page, count, total and follow links**, the same on every resource
|
|
4
|
+
that takes it. Learn it once.
|
|
5
|
+
|
|
6
|
+
| Resource | Function | Call |
|
|
7
|
+
|---|---|---|
|
|
8
|
+
| Proofs | `proof.query(collectionId, body)` | `POST /admin/collection/:id/proof/query` |
|
|
9
|
+
| Contacts | `contact.query(collectionId, body)` | `POST /admin/collection/:id/contacts/query` |
|
|
10
|
+
| Products | `products.standardQuery(collectionId, body)` | `POST /admin/collection/:id/products/standard/query` |
|
|
11
|
+
| App records | `app.records.query(collectionId, appId, body)` | `POST /admin/collection/:id/app/:appId/records/query` |
|
|
12
|
+
|
|
13
|
+
All are admin calls and read-only. Products also keep `products.query`, whose own body is unchanged;
|
|
14
|
+
`standardQuery` sits beside it.
|
|
15
|
+
|
|
16
|
+
Each resource says what its query can use: `proof.queryFields`, `contact.queryFields`,
|
|
17
|
+
`products.standardQueryFields`, `app.records.queryFields` (a `GET` on the same address). It returns the
|
|
18
|
+
fields, what each can be used for, and the links.
|
|
19
|
+
|
|
20
|
+
## The body
|
|
21
|
+
|
|
22
|
+
Everything is optional. An empty body returns the first page.
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
interface StandardQuery {
|
|
26
|
+
where?: QueryWhere
|
|
27
|
+
orderBy?: Array<Record<string, 'asc' | 'desc'>>
|
|
28
|
+
limit?: number // rows: 1–200 (default 50); groups: 1–500
|
|
29
|
+
cursor?: string | null // nextCursor from the previous page
|
|
30
|
+
select?: string[]
|
|
31
|
+
count?: boolean
|
|
32
|
+
groupBy?: string[]
|
|
33
|
+
aggregates?: Record<string, QueryAggregate>
|
|
34
|
+
expand?: string[] | Record<string, string[] | true>
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
It answers in one of two shapes:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
{ items: [...], nextCursor: string | null, count?: number } // rows
|
|
42
|
+
{ groups: [...], more: boolean } // with groupBy and/or aggregates
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Filtering: `where`
|
|
46
|
+
|
|
47
|
+
`field: value` means "equal to". `field: { op: value }` uses a comparison. Every entry must hold.
|
|
48
|
+
|
|
49
|
+
| Comparison | Meaning |
|
|
50
|
+
|---|---|
|
|
51
|
+
| `eq`, `ne` | equal, not equal |
|
|
52
|
+
| `gt`, `gte`, `lt`, `lte` | more / less than (numbers, dates, text) |
|
|
53
|
+
| `in`, `nin` | one of / none of a list (1–100 values) |
|
|
54
|
+
| `contains`, `startsWith` | text, in any letter case |
|
|
55
|
+
| `isNull` | `true`: empty; `false`: has a value |
|
|
56
|
+
| `has`, `hasAny`, `hasAll` | a list field (a contact's `tags`) holds one / any / all |
|
|
57
|
+
|
|
58
|
+
Combine with `and`, `or` and `not`, nested up to 4 levels:
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
await proof.query(collectionId, {
|
|
62
|
+
where: {
|
|
63
|
+
createdAt: { gte: '2026-01-01', lt: '2026-02-01' },
|
|
64
|
+
or: [{ productId: 'toaster' }, { and: [{ productId: 'kettle' }, { claimable: true }] }],
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Dates are ISO 8601 text (`"2026-01-31"` or `"2026-01-31T09:00:00Z"`).
|
|
70
|
+
|
|
71
|
+
### Product facets
|
|
72
|
+
|
|
73
|
+
A product's `facets` are filtered by key. Name the facet by its key or its name, and the value by its
|
|
74
|
+
key or its name, in any letter case. Every facet given must match.
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
await products.standardQuery(collectionId, {
|
|
78
|
+
where: { facets: { brand: 'Breville', category: { in: ['Toasters', 'Kettles'] } } },
|
|
79
|
+
})
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### An app's own fields: paths into a record
|
|
83
|
+
|
|
84
|
+
An app record keeps the app's own fields inside `data` (and `owner`, `admin`). Reach one by path, as a
|
|
85
|
+
field name:
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
await app.records.query(collectionId, appId, {
|
|
89
|
+
where: { recordType: 'work_order', 'data.status': 'released', 'data.qty': { gt: 10 } },
|
|
90
|
+
select: ['ref', 'data.status', 'data.line.name'],
|
|
91
|
+
})
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
- A path can be filtered, selected, grouped and totalled. It cannot be sorted on.
|
|
95
|
+
- It reads as text. Compared with a **number** (`gt`, `gte`, `lt`, `lte`), and in `sum`, `avg`, `min`
|
|
96
|
+
and `max`, it is read as a number; a value that is not a number is left out, it does not fail the
|
|
97
|
+
query.
|
|
98
|
+
- A path follows named fields, up to 4 deep. It does not reach into lists.
|
|
99
|
+
- The documents themselves (`data`, `owner`, `admin`) are returned only when selected.
|
|
100
|
+
|
|
101
|
+
## Sorting and paging
|
|
102
|
+
|
|
103
|
+
`orderBy` takes up to 3 `{ field: 'asc' | 'desc' }`. Only fields that are never empty can be sorted
|
|
104
|
+
on (ask `queryFields`). Pass the answer's `nextCursor` as `cursor` for the next page, with the **same**
|
|
105
|
+
`where` and `orderBy`; a cursor from a different query is refused.
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
let cursor: string | null = null
|
|
109
|
+
do {
|
|
110
|
+
const page = await contact.query(collectionId, { orderBy: [{ createdAt: 'asc' }], limit: 200, cursor })
|
|
111
|
+
if (!('items' in page)) break
|
|
112
|
+
// …use page.items
|
|
113
|
+
cursor = page.nextCursor
|
|
114
|
+
} while (cursor)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
`count: true` adds how many rows match `where` in all, not just on this page.
|
|
118
|
+
|
|
119
|
+
## Totals: `groupBy` and `aggregates`
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
// How many people own each product, and when the latest was registered
|
|
123
|
+
await proof.query(collectionId, {
|
|
124
|
+
where: { userId: { isNull: false } },
|
|
125
|
+
groupBy: ['productId'],
|
|
126
|
+
aggregates: { owners: { countDistinct: 'userId' }, latest: { max: 'createdAt' } },
|
|
127
|
+
})
|
|
128
|
+
// → { groups: [{ productId: 'kettle', owners: 2, latest: '2026-01-06T12:00:00.000Z' }, …], more: false }
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
- A total is one of `{ count: true }`, `{ countDistinct: field }`, `{ sum | avg | min | max: field }`.
|
|
132
|
+
- `aggregates` without `groupBy` gives one group: the totals over everything matched.
|
|
133
|
+
- Groups come ordered by the first total, largest first, unless `orderBy` names a group field or a
|
|
134
|
+
total. `more: true` means there were more groups than `limit`.
|
|
135
|
+
- A grouped query has no pages, no `select` and no `expand`.
|
|
136
|
+
|
|
137
|
+
## Following a link: `expand`
|
|
138
|
+
|
|
139
|
+
`expand` returns the thing a row points at, inside the row, under the link's name.
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
await proof.query(collectionId, {
|
|
143
|
+
where: { productId: 'toaster' },
|
|
144
|
+
select: ['id'],
|
|
145
|
+
expand: { product: ['name', 'sku'], owner: ['firstName', 'email'] },
|
|
146
|
+
})
|
|
147
|
+
// → items: [{ id: 'p1', product: { name: 'Breville Toaster', sku: '…' }, owner: { firstName: 'Ana', email: '…' } }]
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
| Resource | Links |
|
|
151
|
+
|---|---|
|
|
152
|
+
| Proofs | `product`, `owner` (the contact with the owner's login id) |
|
|
153
|
+
| App records | `product`, `contact` |
|
|
154
|
+
|
|
155
|
+
`expand: ['product']` returns the linked thing's usual fields. A link is null when there is nothing
|
|
156
|
+
linked, and also when the linked thing would not be returned by its own query (a deleted product, an
|
|
157
|
+
erased contact). Up to 3 links, one level deep, rows only.
|
|
158
|
+
|
|
159
|
+
## What is refused
|
|
160
|
+
|
|
161
|
+
A query that asks for something a resource does not offer is refused with status 400 and a plain
|
|
162
|
+
message saying what is allowed:
|
|
163
|
+
|
|
164
|
+
```json
|
|
165
|
+
{ "errorCode": "INVALID_QUERY", "errorText": "There is no field \"colour\" on proofs. Fields: id, productId, …", "at": "where.colour" }
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
That includes a field that is not offered (anywhere: filter, sort, group or select), an unknown
|
|
169
|
+
comparison, a value of the wrong type, too many rows or values, and nesting that is too deep. A query
|
|
170
|
+
that runs for more than 5 seconds is stopped with `QUERY_TOO_SLOW`: narrow `where`.
|
|
171
|
+
|
|
172
|
+
## A question across resources
|
|
173
|
+
|
|
174
|
+
"How many people own a Breville toaster, and who registered one most recently?"
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
const found = await products.standardQuery(collectionId, {
|
|
178
|
+
where: { facets: { brand: 'Breville', category: 'Toasters' } }, select: ['id'],
|
|
179
|
+
})
|
|
180
|
+
const ids = 'items' in found ? found.items.map((p) => String(p.id)) : []
|
|
181
|
+
const where = { productId: { in: ids }, userId: { isNull: false } }
|
|
182
|
+
|
|
183
|
+
const owners = await proof.query(collectionId, { where, aggregates: { owners: { countDistinct: 'userId' } } })
|
|
184
|
+
const latest = await proof.query(collectionId, {
|
|
185
|
+
where, orderBy: [{ createdAt: 'desc' }], limit: 1, expand: { owner: ['firstName', 'lastName'] },
|
|
186
|
+
})
|
|
187
|
+
```
|
package/dist/docs/utils.md
CHANGED
|
@@ -670,8 +670,24 @@ await utils.validateCondition({
|
|
|
670
670
|
})
|
|
671
671
|
```
|
|
672
672
|
|
|
673
|
-
####
|
|
674
|
-
|
|
673
|
+
#### Saved Conditions (by id)
|
|
674
|
+
A collection keeps **saved conditions**: named rule sets such as "UK only" or "In the stadium", made in Studio or with the `conditions` API. Check one by id and the SDK loads it from the collection by itself (cached for the page):
|
|
675
|
+
|
|
676
|
+
```typescript
|
|
677
|
+
import { utils, conditions } from '@proveanything/smartlinks'
|
|
678
|
+
|
|
679
|
+
const show = await utils.validateCondition({
|
|
680
|
+
conditionId: 'nfCmuWDY',
|
|
681
|
+
collection: { id: 'col1' },
|
|
682
|
+
user: { valid: true, location: { country: 'GB' } },
|
|
683
|
+
})
|
|
684
|
+
|
|
685
|
+
// Admin: list, create, change, remove
|
|
686
|
+
const all = await conditions.list('col1', true)
|
|
687
|
+
await conditions.create('col1', { title: 'UK only', type: 'and', conditions: [{ type: 'country', countries: ['GB'], contains: true }] })
|
|
688
|
+
```
|
|
689
|
+
|
|
690
|
+
A rule can also refer to another saved condition, for reuse:
|
|
675
691
|
|
|
676
692
|
```typescript
|
|
677
693
|
await utils.validateCondition({
|
|
@@ -683,15 +699,13 @@ await utils.validateCondition({
|
|
|
683
699
|
passes: true // true = must pass, false = must fail
|
|
684
700
|
}]
|
|
685
701
|
},
|
|
686
|
-
|
|
687
|
-
fetchCondition: async (collectionId, conditionId) => {
|
|
688
|
-
// Your logic to fetch condition by ID
|
|
689
|
-
return { type: 'and', conditions: [...] }
|
|
690
|
-
},
|
|
691
|
-
collection: { id: 'col1' }
|
|
702
|
+
collection: { id: 'col1' },
|
|
692
703
|
})
|
|
693
704
|
```
|
|
694
705
|
|
|
706
|
+
- A saved condition that's switched off (`disabled: true`) passes for everyone; so does one that can't be found.
|
|
707
|
+
- Pass `fetchCondition: async (collectionId, conditionId) => ConditionSet | null` to load them your own way (from data you already have, or in a test).
|
|
708
|
+
|
|
695
709
|
### Combining Conditions (AND/OR Logic)
|
|
696
710
|
|
|
697
711
|
```typescript
|