@thecms/cli 0.0.0-stage → 0.20.1-dev.122
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/chunk-VVIH7QDO.js +13506 -0
- package/dist/cli.js +11 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.js +9 -0
- package/dist/method/capabilities.md +358 -0
- package/dist/method/method.md +292 -0
- package/dist/method/standard/app.md +127 -0
- package/dist/method/standard/brand.md +160 -0
- package/dist/method/standard/components.md +183 -0
- package/dist/method/standard/mobile.md +144 -0
- package/package.json +50 -4
- package/README.md +0 -3
package/dist/cli.js
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** What `thecms login` keeps: the token and what is needed to revoke it (`thecms logout`). */
|
|
2
|
+
interface Credential {
|
|
3
|
+
token: string;
|
|
4
|
+
/** the token's id (`DELETE /_auth/tokens/{id}`) */
|
|
5
|
+
id: string;
|
|
6
|
+
expiresAt: string;
|
|
7
|
+
email?: string;
|
|
8
|
+
}
|
|
9
|
+
interface CredentialStore {
|
|
10
|
+
/** where it was kept: "the system's keychain" or the file's path */
|
|
11
|
+
save(api: string, credential: Credential): string;
|
|
12
|
+
load(api: string): Credential | null;
|
|
13
|
+
remove(api: string): void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Everything a command touches outside itself: the folder, the platform, the
|
|
18
|
+
* terminal, the computer's keychain, the programs it runs. `cli.ts` builds the
|
|
19
|
+
* real one (real.ts); the tests give their own (the API in process, a temporary folder).
|
|
20
|
+
*/
|
|
21
|
+
interface Ctx {
|
|
22
|
+
/** the folder the command runs in (the site's app: package.json, app/, components/, lib/) */
|
|
23
|
+
cwd: string;
|
|
24
|
+
/** the platform's API and dashboard (THECMS_API / THECMS_DASHBOARD only for the platform's own development) */
|
|
25
|
+
api: string;
|
|
26
|
+
dashboard: string;
|
|
27
|
+
/** D629: this CLI's release channel (its build's: `latest` = production, `dev` = the dev); `latest` when absent */
|
|
28
|
+
channel?: "latest" | "dev";
|
|
29
|
+
fetch: typeof fetch;
|
|
30
|
+
out: (line: string) => void;
|
|
31
|
+
err: (line: string) => void;
|
|
32
|
+
store: CredentialStore;
|
|
33
|
+
/** open an address in the browser */
|
|
34
|
+
open: (url: string) => Promise<void>;
|
|
35
|
+
/** ask a question in the terminal (null: nobody to ask) */
|
|
36
|
+
ask: (question: string) => Promise<string | null>;
|
|
37
|
+
/** run a program, its output on the terminal; its exit code (`env`: variables added for it alone — AGENT D497: a token never in its arguments) */
|
|
38
|
+
run: (command: string, args: string[], cwd: string, env?: Record<string, string>) => Promise<number>;
|
|
39
|
+
/** the API key for CI (`--key`, else THECMS_KEY: read by the CLI only, never by the site — D374) */
|
|
40
|
+
key?: string;
|
|
41
|
+
/** wait (CAPTURE D517: the pace between two requests to an old site); a timer when absent */
|
|
42
|
+
sleep?: (ms: number) => Promise<void>;
|
|
43
|
+
/** CAPTURE D515: start `thecms <args>` on its own, detached from this process (no shell): the MCP never waits for it */
|
|
44
|
+
detach?: (args: string[], cwd: string) => Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* CLI D392 — `thecms <argv…>` from another program (`create-thecms-app` is
|
|
49
|
+
* `run(["create", …])`): this process's folder, terminal and environment; the exit code.
|
|
50
|
+
*/
|
|
51
|
+
declare function run(argv: string[]): Promise<number>;
|
|
52
|
+
/**
|
|
53
|
+
* AGENT D461 — the personal token of `thecms login`, for a script of the
|
|
54
|
+
* project: `createSdk({ publicKey, personalToken: personalToken() })`. Read
|
|
55
|
+
* from this computer's keychain at each run, never written in a file; the
|
|
56
|
+
* script acts as the person, with their role. Without a sign-in it throws.
|
|
57
|
+
*/
|
|
58
|
+
declare function personalToken(ctx?: Pick<Ctx, "api" | "store">): string;
|
|
59
|
+
|
|
60
|
+
export { personalToken, run };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
# Capabilities: what the platform does, and the nearest way when it does not {#capabilities}
|
|
2
|
+
|
|
3
|
+
For whoever builds a site or an app on theCMS.: how the platform **behaves**, pattern by pattern, with the exact inputs of the MCP's tools or the HTTP call. Read it before asking the person or the platform's people how to do something. Where something does not exist, the last part says the nearest way inside the platform and what is lost.
|
|
4
|
+
|
|
5
|
+
Conventions:
|
|
6
|
+
- **HTTP**: every address below starts with `https://<the platform>/v1`; `{workspace}` is the workspace's address. A user of an app calls with `Authorization: Bearer <access token>` ([`standard/mobile.md`](standard/mobile.md)).
|
|
7
|
+
- **MCP**: `apply_*` answers the plan first; it writes only with `confirm: true`, after the person's ok.
|
|
8
|
+
- **Users** are the workspace's readers: the people who sign in to a site or an app. **Members** are the people of the dashboard.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 1. The users of an app and their role {#cap-reader-role}
|
|
13
|
+
|
|
14
|
+
A user writes **only** through the role the workspace gives to the **application** they signed in from — never a role per user, never an anonymous write. The role may hold only:
|
|
15
|
+
- `records/<schema>`: `read`, `create`, `update`, `delete`; `update` and `delete` only of their own (`own: true`); reading others' only under a condition (`own` or `where`);
|
|
16
|
+
- `assets`: their own files.
|
|
17
|
+
|
|
18
|
+
Never `publish`, a wildcard, another area, the owner's role: the platform refuses it in words (422). The **readers** feature must be on: only the platform's administrator turns it on (`set_feature { workspace, feature: "readers", enabled: true }`).
|
|
19
|
+
<!-- src: docs/internal/invariants/end-users.md (readerRoleRules, D559–D562); docs/internal/invariants/features.md; packages/cli/src/mcp/server.ts set_feature -->
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
apply_role {
|
|
23
|
+
"name": "Users",
|
|
24
|
+
"permissions": [
|
|
25
|
+
{ "resource": "records/program", "actions": ["create", "read", "update", "delete"], "own": true },
|
|
26
|
+
{ "resource": "assets", "actions": ["create", "read", "update", "delete"] }
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
apply_application { "name": "Example app", "siteUrl": "https://example.com/app", "readerRole": "Users" }
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
A permission on records takes:
|
|
33
|
+
- `own: true` — the records whose `_createdBy` is the caller (`enduser:<id>` for a user);
|
|
34
|
+
- `where: [{ field, op, value }]` — a filterable field, a relation, `_id` or `_status`, with `eq`, `neq`, `in`, `nin`;
|
|
35
|
+
- `fields: { read: [...], write: [...] }` — only those fields.
|
|
36
|
+
<!-- src: docs/internal/invariants/records-access.md (Grants); packages/api/tests/integration/reader-writes/unique-reader.test.ts (fields: { read }) -->
|
|
37
|
+
- a `where` value `{ "assigned": "<schema>", "via": "<field>" }` — the records of `<schema>` whose relation `<field>` to `_reader` names the user (a team's `staff`, a club's `owner`, a league's `members`), read at each request; with it a user may also `update` and `delete` those records (only the `fields` it writes): `{ "resource": "records/callup", "actions": ["create", "read"], "where": [{ "field": "team", "op": "in", "value": { "assigned": "team", "via": "staff" } }] }`.
|
|
38
|
+
<!-- src: docs/internal/invariants/records-access.md (D597); packages/api/tests/integration/reader-writes/spot-groups.test.ts -->
|
|
39
|
+
|
|
40
|
+
Taking the role away (`readerRole: null`) stops every user of the app at once, renewals included.
|
|
41
|
+
<!-- src: docs/internal/invariants/end-users.md (closeReaderSessions); reader-writes/records-files.test.ts "the role taken away" -->
|
|
42
|
+
|
|
43
|
+
### A user's own data {#cap-own-data}
|
|
44
|
+
|
|
45
|
+
Example: each user's training programs, sessions and sets.
|
|
46
|
+
|
|
47
|
+
- Every schema of the user's data gets `own: true` with the four actions (above).
|
|
48
|
+
- What a user creates carries them as author (`_createdBy`) and is a **draft**: a user never publishes, and nobody else reads it unless a condition says so.
|
|
49
|
+
- `GET /{workspace}/records/{schema}` gives a user only the records their role reads: there is no need to filter by author (and `?where[_createdBy]…` is refused, 422).
|
|
50
|
+
<!-- src: records-access.md (`_createdBy` filterable only via anyOf / mine); proved 13/11/2026 by a throwaway test (METHOD ME4): where[_createdBy] → 422 -->
|
|
51
|
+
|
|
52
|
+
### A shared library plus each user's own entries {#cap-library-and-own}
|
|
53
|
+
|
|
54
|
+
Example: exercises curated by the editors, plus each user's own exercises, in ONE schema `exercise`.
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{ "resource": "records/exercise", "actions": ["create", "read", "update", "delete"], "own": true },
|
|
58
|
+
{ "resource": "records/exercise", "actions": ["read"], "where": [{ "field": "_status", "op": "eq", "value": "published" }] }
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
- Several permissions on one schema **add up** (OR), record by record: a user reads the published exercises and their own; another user's own exercises and the editors' drafts do not exist for them (404).
|
|
62
|
+
- A user's own exercises stay drafts read by them only: a user never publishes. To share one, a member publishes it (`publish`, or the dashboard; it is then the library's).
|
|
63
|
+
- Something a user chooses to show to everyone is a field of theirs and a condition: `visibility` (`private` / `public`) and `where: [{ field: "visibility", op: "eq", value: "public" }]`.
|
|
64
|
+
<!-- src: records-access.md ("several grants = OR, per record", 404 D14); end-users.md (never publish); proved 13/11/2026: published + own listed, another user's own and the editor's draft not; reader-writes/records-files.test.ts (visibility = public) -->
|
|
65
|
+
|
|
66
|
+
### One per user {#cap-one-per-user}
|
|
67
|
+
|
|
68
|
+
Example: one profile per user, one XP record per user and week.
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
apply_schema { "schema": "profile", "fields": [{ "name": "nickname", "type": "string" }], "unique": [["_createdBy"]] }
|
|
72
|
+
apply_schema { "schema": "weekly_xp", "fields": [{ "name": "week", "type": "string", "filterable": true }, { "name": "xp", "type": "number" }], "unique": [["_createdBy", "week"]] }
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
A second one is refused (409, see [uniqueness](#cap-unique)).
|
|
76
|
+
<!-- src: docs/internal/invariants/schema.md (Uniqueness, D564); docs/internal/dossier/READER-WRITES.md D564 -->
|
|
77
|
+
|
|
78
|
+
### Linking: only what the writer reads {#cap-links}
|
|
79
|
+
|
|
80
|
+
Every **new** link a write adds must point to a record the writer can read — for every relation, without declaring it. Otherwise 403 `You cannot link a record you cannot read (<schema>/<id>)`. A user links their own records and the library's published ones; never another user's private record nor an editor's draft.
|
|
81
|
+
<!-- src: records-access.md ("a NEW link must point to a record the writer can read (D26)"); packages/records/src/access/gate.ts assertLinks; proved 13/11/2026: link to another user's exercise and to an editor's draft → 403 -->
|
|
82
|
+
|
|
83
|
+
Interacting with someone else's content is a record of one's own linked to theirs (a like, a comment, a follow), never a write on their record.
|
|
84
|
+
<!-- src: end-users.md (D563) -->
|
|
85
|
+
|
|
86
|
+
### People and profiles {#cap-people}
|
|
87
|
+
|
|
88
|
+
A person is a relation to `_reader`; declare at creation the schema of their profile, and every linked person comes out as `{ id, profile }` — the profile as the caller may read it, never an email.
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
apply_schema { "schema": "follow", "fields": [{ "name": "following", "type": "relation", "relatedEntity": "_reader", "readerProfile": "profile" }], "unique": [["_createdBy", "following"]] }
|
|
92
|
+
```
|
|
93
|
+
<!-- src: docs/internal/invariants/relations.md (D565, D573); packages/cli/src/mcp/server.ts field.readerProfile -->
|
|
94
|
+
|
|
95
|
+
A relation to many takes `maxLinks` (1–1000): at most that many links, for every writer — over it, 422 `A team holds at most 3 staff (4 given)`, `details: { reason: "maxLinks" }`: `{ "name": "staff", "type": "relation", "relatedEntity": "_reader", "cardinality": "many", "maxLinks": 3 }`.
|
|
96
|
+
<!-- src: docs/internal/invariants/relations.md (D598); packages/cli/src/mcp/server.ts field.maxLinks; spot-groups.test.ts -->
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## 2. Writing well {#cap-writes}
|
|
101
|
+
|
|
102
|
+
### Uniqueness {#cap-unique}
|
|
103
|
+
|
|
104
|
+
`unique` lists combinations of fields that never repeat (at most 5, each of 1–3 fields): `_createdBy`, fields of type string, number, boolean, datetime, enum, url, uuid, or a relation to one — never a translated field, a `json`, a relation to many.
|
|
105
|
+
|
|
106
|
+
- Checked on every create and update, for every writer (members, keys, users), on the **published** schema: `apply_schema` publishes a new schema with it at once; on an existing one it goes to the draft — `publish` makes it hold.
|
|
107
|
+
- **A combination with an empty value (missing, null or `""`) is not checked**: it behaves like a unique index `where <field> is not null`.
|
|
108
|
+
- A repeat → **409** `CONFLICT`, `details: { reason: "unique", fields: [...] }`, words such as `A Profile with the same nickname already exists: there is one only`. The 409 tells the caller the value exists: a nickname unique across users is, by nature, a value anyone can test.
|
|
109
|
+
<!-- src: schema.md (Uniqueness); packages/core/src/types.ts canBeUnique; proved 13/11/2026: missing / "" not checked, same key → 409 with details { reason: "unique", fields } -->
|
|
110
|
+
|
|
111
|
+
Example: a nickname unique among all users, 3–20 characters:
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
apply_schema { "schema": "profile", "fields": [{ "name": "nickname", "type": "string", "pattern": "^[a-z0-9_]{3,20}$", "patternMessage": "3–20 letters, digits or _" }], "unique": [["_createdBy"], ["nickname"]] }
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
A value outside the pattern → 422 with the `patternMessage`.
|
|
118
|
+
<!-- src: docs/internal/invariants/field-formats.md (pattern); proved 13/11/2026: "Fr" → 422 'Field "nickname": 3–20 letters, digits or _' -->
|
|
119
|
+
|
|
120
|
+
### Idempotent writes and offline sync {#cap-offline-sync}
|
|
121
|
+
|
|
122
|
+
The platform makes every record's id: an `_id` sent on a create is ignored, and there is no upsert. The idempotent write is a **client id with a uniqueness**:
|
|
123
|
+
|
|
124
|
+
```json
|
|
125
|
+
apply_schema { "schema": "set_log", "fields": [{ "name": "client_id", "type": "uuid", "filterable": true }, { "name": "kg", "type": "number" }], "unique": [["_createdBy", "client_id"]] }
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
1. The app makes the uuid on the phone and sends `POST /{workspace}/records/set_log { client_id, … }`.
|
|
129
|
+
2. A retry of a write already saved → **409** `details.reason: "unique"`: it means "already saved".
|
|
130
|
+
3. To change it, find its id — `GET /{workspace}/records/set_log?where[client_id][eq]=<uuid>` — then `PUT` it ([conflicts](#cap-conflicts)).
|
|
131
|
+
<!-- src: packages/records/src/record/engine.ts create ("The id is generated inside"); proved 13/11/2026: client _id ignored, retry → 409, another user with the same client_id → 201, where[client_id] finds 1 -->
|
|
132
|
+
|
|
133
|
+
`[["_createdBy", "client_id"]]` keeps each user's ids apart; `[["client_id"]]` would make them unique across all users.
|
|
134
|
+
|
|
135
|
+
### Conflicts between devices {#cap-conflicts}
|
|
136
|
+
|
|
137
|
+
`GET /{workspace}/records/{schema}/{id}` answers an `ETag`. `PUT` with `If-Match: <ETag>` refuses a save on top of a newer one: **409** `details: { reason: "stale", etag, fields, theirs }` (their version as the caller may read it). Without `If-Match` the last save wins. Every answer to a `PUT` carries the new `ETag`.
|
|
138
|
+
<!-- src: packages/api/src/routes/records.ts PUT (DESIGN R2); proved 13/11/2026: second save with the old ETag → 409 reason "stale" -->
|
|
139
|
+
|
|
140
|
+
### A shape that writes {#cap-shape-writes}
|
|
141
|
+
|
|
142
|
+
- A shape may write: the site's server creates records with a key that only creates; the platform limits writes per visitor and per schema.
|
|
143
|
+
<!-- src: docs/internal/dossier/BFF.md (D658–D664); packages/api/tests/integration/bff/site-writes.test.ts -->
|
|
144
|
+
|
|
145
|
+
### Limits {#cap-limits}
|
|
146
|
+
|
|
147
|
+
| What | Limit | Over it |
|
|
148
|
+
|---|---|---|
|
|
149
|
+
| A user's writes | 60 a minute | 429 `RATE_LIMITED` + `Retry-After` |
|
|
150
|
+
| A user's requests to the management routes | 600 a minute | 429 `RATE_LIMITED` + `Retry-After` |
|
|
151
|
+
| A JSON body | 2 MB | 413 |
|
|
152
|
+
| A page of a list | `?limit` 1–200, then `cursor` | 422 |
|
|
153
|
+
| A user's files | 1,000 files, 1 GB | 403 `QUOTA_EXCEEDED` |
|
|
154
|
+
| One upload | 100 MB whole, 1 GB in pieces (tus) | 413; a tus upload is refused at its opening |
|
|
155
|
+
| Sign-ins started from one address | 20 a minute | 429 |
|
|
156
|
+
|
|
157
|
+
Counted per instance of the platform: the numbers are the order of magnitude, not a contract. A user has **no batch and no import**: one record per call (`/batch` → 403; `/import` answers every row refused).
|
|
158
|
+
<!-- src: packages/api/src/traffic/rate-limit.ts RATE_RULES (readerLogin 20, management 600, readerWrites 60); docs/internal/invariants/traffic.md (2 MB, per instance); relations.md (?limit 1..200); fuses.md (D572); assets.md (UPLOAD_MAX_BYTES 100 MB, tus 1 GB); end-users.md (READER_ROUTES); reader-writes/records-files.test.ts (batch 403); proved 13/11/2026: import preview by a user → every row "Missing permission" -->
|
|
159
|
+
|
|
160
|
+
### Cascades {#cap-cascades}
|
|
161
|
+
|
|
162
|
+
A relation field says what happens to its record when the record it points to is deleted: `onDelete: "detach"` (default: the link goes), `"cascade"` (the record goes too), `"restrict"` (the target cannot be deleted while it is linked: 409 with `details.impact.blocking`).
|
|
163
|
+
|
|
164
|
+
- A cascade runs inside the delete, whoever deletes: a user deleting their program deletes its days and slots **without** a `delete` permission on them. Deleted records go to the trash for 30 days.
|
|
165
|
+
- The cascade takes every linked record, whoever created it: a library record must never be the target of a `cascade` from users' records — an editor deleting an exercise would delete the users' slots. Use `restrict` (the editor is told who uses it) or `detach`.
|
|
166
|
+
<!-- src: relations.md (onDelete); docs/internal/invariants/deletes.md (planned, trash 30 days); packages/records/CLAUDE.md (planDelete: closure of the cascade sources); packages/api/src/routes/records.ts DELETE (gate.load of the target only); proved 13/11/2026: a user without delete on program_day deletes the program → 200, day and slot gone; editor deleting a restricted exercise → 409 blocking -->
|
|
167
|
+
|
|
168
|
+
```json
|
|
169
|
+
{ "name": "program", "type": "relation", "relatedEntity": "program", "onDelete": "cascade" }
|
|
170
|
+
{ "name": "exercise", "type": "relation", "relatedEntity": "exercise", "onDelete": "restrict" }
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### JSON fields {#cap-json}
|
|
174
|
+
|
|
175
|
+
A `json` field holds any JSON value, unchecked: no shape, no validation, not filterable (`?where` on it → 422), not sortable, never in a uniqueness; its size is bounded by the 2 MB body. Keep in JSON what the app reads whole (a prescription, a warm-up, a setup); make a schema of what you filter, link, count or keep unique.
|
|
176
|
+
<!-- src: packages/core/src/types.ts (FILTERABLE_TYPES, canBeUnique without json); packages/schema/src/engine.ts validate (no json rule); traffic.md (2 MB); proved 13/11/2026: nested object saved, where on json → 422 -->
|
|
177
|
+
|
|
178
|
+
### Field rules {#cap-field-rules}
|
|
179
|
+
|
|
180
|
+
The server checks on every write: `required`, `enum` values, a string's `pattern` (the whole value), a relation's cardinality and that its targets exist (422), an `asset` field's types and size. A schema is append-only: no rename, no type change — a new field instead.
|
|
181
|
+
<!-- src: schema.md; field-formats.md; relations.md (Cardinality); assets.md (asset field rule) -->
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## 2b. What a block can read {#cap-block-reads}
|
|
186
|
+
|
|
187
|
+
A page's block reads the workspace as its set, shape and settings say; the model has the schema each reading needs, nothing more. The block is an entry of `apply_page`'s `blocks` (or a set's `presets`, `apply_set`).
|
|
188
|
+
|
|
189
|
+
| The block shows | The schema it needs | Its reading |
|
|
190
|
+
|---|---|---|
|
|
191
|
+
| "See also" on a record's page | a category schema shared by the records (`service_category`) and a field on the record that points at it (`service.service_category`, one, filterable) — never a relation of the schema with itself | a filter on the open record's category, without the open record |
|
|
192
|
+
| A menu, breadcrumbs | a tree: `menu` + `menu_item`, `menu_item`'s relation to itself (sub-entries in the plural, `menu_items`; the mother in the singular, `menu_item.menu_item`, made by the platform) | the menu's `menu_items`, then each item's |
|
|
193
|
+
| The archive of a tag | a tag schema, a relation to many on the record (`tags`) | a filter on the tag |
|
|
194
|
+
| A list in the editor's order | a number field `position` | `sort` on `position` |
|
|
195
|
+
| The sub-pages of a section | a tree of one schema (`page` and its `pages`) | `descendantsOf` on the section |
|
|
196
|
+
|
|
197
|
+
```json
|
|
198
|
+
{ "set": "service", "shape": "related", "title": "See also", "limit": 3, "filters": [
|
|
199
|
+
{ "field": "service_category", "op": "eq", "value": "{context.service_category}" },
|
|
200
|
+
{ "field": "_id", "op": "neq", "value": "{context._id}" } ] }
|
|
201
|
+
```
|
|
202
|
+
```json
|
|
203
|
+
{ "set": "post", "shape": "card", "filters": [{ "field": "tags", "op": "eq", "value": "{context._id}" }] }
|
|
204
|
+
```
|
|
205
|
+
```json
|
|
206
|
+
{ "set": "menu_item", "shape": "list", "sort": { "field": "position", "direction": "asc" } }
|
|
207
|
+
```
|
|
208
|
+
```json
|
|
209
|
+
{ "set": "page", "shape": "sub_pages", "filters": [{ "field": "section", "op": "descendantsOf", "value": "{context._id}" }] }
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
- `{context.<field>}` is the open record's value (a link → its id; a link to many → `in`); `{context._id}` is the open record itself: with `neq` it never lists itself. They hold only on a template page (a page of a record).
|
|
213
|
+
- A relation of a schema with itself is **only** a tree. A "related" relation of a schema to itself (`related_services`) is a mistake the plan of `apply_schema` points at (structures: `related`).
|
|
214
|
+
- Repeated items (cards, steps, numbers, logos) are records of a schema, in the editor's order (`position`); a block's shape holds only what holds in that place of the page.
|
|
215
|
+
<!-- src: packages/presentation/src/resolver/widget-resolver.ts resolveQueryPlaceholders (`{context.<field>}`, `_id` included; eq/neq on a list → in/nin); packages/api/tests/integration/presentation/context-id-neq.test.ts; docs/internal/invariants/relations.md (MODEL-FOR-PRESENTATION, D496 descendantsOf); packages/cli/src/mcp/structures.ts (related, menu, categories); packages/core/src/shape-values.ts (a shape's list field); docs/internal/invariants/field-formats.md -->
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## 3. Files of an app's users {#cap-files}
|
|
220
|
+
|
|
221
|
+
Example: a photo of a user's own exercise.
|
|
222
|
+
|
|
223
|
+
- Upload with `POST /{workspace}/assets` (a form: `file`, `for` = `{ "schema": "exercise", "field": "photo" }`), or in pieces with tus at `/{workspace}/assets/uploads`. `for` is required for a user, and must be a file field their role writes (none → 422 `reason: for_required`; not theirs → 403); the field's types and size apply.
|
|
224
|
+
- A user sees and changes only their own files; another's is a 404.
|
|
225
|
+
- A file's address never changes content (a replaced file gets a new address).
|
|
226
|
+
<!-- src: docs/internal/invariants/assets.md (READER-WRITES D566, D572; immutable) -->
|
|
227
|
+
|
|
228
|
+
### Private until published {#cap-private-files}
|
|
229
|
+
|
|
230
|
+
Example: the photo of a post that a member has not published yet.
|
|
231
|
+
|
|
232
|
+
- A file a user uploads is **private** (`public: false` in its answer): its public address answers 404, and the public answers show it without an address.
|
|
233
|
+
- Its author, and the members who read files, open it from the `publicUrl` of their own answers (`GET /{workspace}/assets/{id}`, the list, the upload's answer). That address is signed and lasts 15 minutes; size variants (`&w=640`) work on it too. It is never cached by a browser or a CDN: read it again when it expires.
|
|
234
|
+
- The file becomes public (`public: true`, the plain address) when a **published** record links it in a file field. It goes back to private when no published record links it any more (unpublished, deleted, or the field changed).
|
|
235
|
+
- A file inside a block is not counted: only file fields are.
|
|
236
|
+
- Members' uploads stay public as before.
|
|
237
|
+
- A video refused as too long for its field (`stream.status: refused`) is closed the same way. Its record does not change.
|
|
238
|
+
<!-- src: docs/internal/invariants/assets.md (READER-WRITES B3 D602, D607); packages/api/src/utils/file-publicity.ts; packages/api/src/queue/file-publicity.ts; packages/assets/src/video.ts MEMBER_FILE_MS -->
|
|
239
|
+
|
|
240
|
+
### The place a photo was taken {#cap-photo-place}
|
|
241
|
+
|
|
242
|
+
At every upload of a photo (JPEG, PNG, WebP, HEIC / HEIF / AVIF), by anyone, the platform removes from the stored original:
|
|
243
|
+
- the place: EXIF GPS, and the XMP and IPTC that repeat it;
|
|
244
|
+
- the device's personal metadata: make, model, serial numbers, owner, software, maker notes, comments.
|
|
245
|
+
|
|
246
|
+
The image is not encoded again and the orientation stays. The app does not need to strip anything before uploading.
|
|
247
|
+
<!-- src: docs/internal/invariants/assets.md (READER-WRITES B3 D603); packages/assets/src/transform/strip-metadata.ts; tests/integration/assets/photo-place.test.ts -->
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
## 4. Sign-in {#cap-sign-in}
|
|
252
|
+
|
|
253
|
+
### Methods {#cap-sign-in-methods}
|
|
254
|
+
|
|
255
|
+
Users sign in only with the workspace's own methods: templates `google`, `github`, `microsoft`, `apple`, or any OpenID Connect provider by its issuer, or a manual OAuth 2 one. There is no password and no email code of the platform.
|
|
256
|
+
|
|
257
|
+
```json
|
|
258
|
+
apply_sign_in_method { "key": "google", "template": "google", "label": "Google", "clientId": "…", "enabled": true }
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
The Client secret (Apple: the `.p8` key) is typed by the person in the dashboard; Apple's team id and key id are not secrets: `apply_sign_in_method { teamId, keyId }`. Then `test_sign_in { key }`: a real sign-in that makes no user.
|
|
262
|
+
<!-- src: docs/internal/invariants/sign-in.md; packages/integrations/src/signin/model.ts SIGNIN_TEMPLATES; packages/cli/src/mcp/server.ts apply_sign_in_method, test_sign_in -->
|
|
263
|
+
|
|
264
|
+
### The return on iOS and Android {#cap-sign-in-return}
|
|
265
|
+
|
|
266
|
+
The flow is in [`standard/mobile.md`](standard/mobile.md) §5. What the platform does:
|
|
267
|
+
- the return goes **only** to the asking application's Site URL: `<Site URL>/api/cms/signed-in?code=…&to=<path>` (a code, 60 s, once); a refusal to `<Site URL><path>?signin=closed|domain|unverified|revoked|failed`;
|
|
268
|
+
- a Site URL is `http://` or `https://`, without query or fragment: a custom scheme (`example://`) is refused (422);
|
|
269
|
+
- with PKCE the code is worth nothing without the app's verifier;
|
|
270
|
+
- the session: an hour, renewed with a refresh token valid 60 days from its last use.
|
|
271
|
+
<!-- src: sign-in.md (return ONLY to the Site URL); packages/presentation/src/application/engine.ts checkSiteUrl; end-users.md (PKCE D569, D571) -->
|
|
272
|
+
|
|
273
|
+
### Closed beta {#cap-closed-beta}
|
|
274
|
+
|
|
275
|
+
`apply_sign_in_policy { mode }`:
|
|
276
|
+
- `open` — anyone;
|
|
277
|
+
- `closed` — **nobody new**: only users who already signed in once (a new one comes back with `?signin=closed`);
|
|
278
|
+
- `domains` — only VERIFIED addresses of the listed domains.
|
|
279
|
+
|
|
280
|
+
Users already there always come in, unless revoked. No route creates a user in advance and there are no invitations ([nearest way](#cap-not-yet)).
|
|
281
|
+
<!-- src: packages/integrations/src/signin/model.ts admitsNewReader; docs/internal/dossier/SIGN-IN.md D342; packages/api/src/routes/readers.ts (list, read, purchases, revoke, restore, forget only) -->
|
|
282
|
+
|
|
283
|
+
### A site and its app {#cap-site-and-app}
|
|
284
|
+
|
|
285
|
+
Two applications ([`standard/mobile.md`](standard/mobile.md) §3): the site without `readerRole`, the app with it and Site URL = the site's address + `/app`.
|
|
286
|
+
|
|
287
|
+
- The readers feature is the **workspace's**: on, the site's answer lists the sign-in methods for every application; the site simply shows none, and its users write nothing (no role).
|
|
288
|
+
- A Site URL can change at any time (`apply_application { siteUrl }`): a sign-in under way (10 minutes) returns to the new one, because the return is read when the provider comes back; sessions and refresh tokens are tied to the application, not to the address, and stay valid; the site's origins allowed to call the public API follow it.
|
|
289
|
+
- What the platform does not move: the `/.well-known` files are served by the site at its own domain, and the app names that domain in its build — a new domain is a new build of the app.
|
|
290
|
+
<!-- src: docs/internal/invariants/features.md (FE3: readers off → signIn []); packages/api/src/routes/views.ts (signIn from the workspace's methods); packages/api/src/routes/reader-sign-in.ts callback (siteUrlOf at return); refresh (siteOfKey, no Site URL); packages/api/src/middleware/cors.ts (60 s); packages/cli/src/native-app.ts (APP_LINK_PATHS /app/*) -->
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## 5. A user leaves {#cap-forget}
|
|
295
|
+
|
|
296
|
+
- **Revoke** (reversible): `DELETE /{workspace}/readers/{id}`; they cannot sign in again until a member restores them (`POST /{workspace}/readers/{id}/restore`).
|
|
297
|
+
- **Forget** (irreversible): `forget_reader { reader }` or `POST /{workspace}/readers/{id}/forget`. Goes: the identity and its sign-in links, every record they created (live and in the trash, every version, their links both ways), every file they uploaded and their uploads under way, the links of others' records to them (`_reader`), their purchases, visits, the addresses in the activity, their sessions. Stays: orders under an opaque id, the events with ids only.
|
|
298
|
+
- Both are a **member's** action (permission `readers`): a user cannot forget themselves from the app ([nearest way](#cap-not-yet)).
|
|
299
|
+
<!-- src: docs/internal/invariants/personal-data.md (forget, D570); end-users.md (revoke, restore); packages/api/src/routes/readers.ts forget requirePermission("readers", "delete") -->
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## 5b. Notices from other systems {#cap-inbound-notices}
|
|
304
|
+
|
|
305
|
+
Example: an identity provider tells the workspace that a user has been verified. The app started the verification and passed its own user id as the reference.
|
|
306
|
+
|
|
307
|
+
A notice is declared with `apply_hook` (plan first) or `PUT /{workspace}/hooks/{name}` (permission `connection`). It belongs to the workspace's Webhooks feature: with the feature off, its management is refused and every notice is a 404.
|
|
308
|
+
|
|
309
|
+
```json
|
|
310
|
+
apply_hook { "name": "identity", "signature": { "header": "X-Signature", "prefix": "sha256=" }, "eventId": "id", "rules": [
|
|
311
|
+
{ "when": [{ "path": "type", "equals": "verification.approved" }], "schema": "profile",
|
|
312
|
+
"match": { "field": "reader", "value": { "from": "data.reference" } }, "set": { "verified": true }, "publish": false },
|
|
313
|
+
{ "when": [{ "path": "type", "equals": "verification.approved" }], "schema": "club",
|
|
314
|
+
"match": { "field": "_id", "value": { "from": "data.club" } }, "set": { "owner": { "from": "data.reference" } },
|
|
315
|
+
"onlyIf": [{ "field": "owner", "empty": true }], "publish": true }
|
|
316
|
+
] }
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
- **The secret** the other system signs with is typed by the person in the dashboard, never by an agent. It is stored encrypted and never shown again. Until it is typed, every notice is refused.
|
|
320
|
+
- **The signature** is HMAC-SHA256 of the raw body, in the header you declare (`hex` or `base64`, with an optional prefix). A wrong signature is a 401 and changes nothing.
|
|
321
|
+
- **What a rule does:**
|
|
322
|
+
- it finds exactly one record: a field (`_id` for its id) equal to a value of the notice (`{ "from": "<dotted path>" }`) or to a constant;
|
|
323
|
+
- it sets the fields listed;
|
|
324
|
+
- `when` and `onlyIf` are its conditions.
|
|
325
|
+
- **The writes:** each rule says whether the record it writes is published (`"publish": true`, e.g. the club's new owner works at once) or stays a draft (`false`). Each write emits `record.updated`, and a published one also `record.published`, with the actor `system:hook:<name>`, so they show in the Activity.
|
|
326
|
+
- **The same notice twice** (the same event id, within 30 days) is processed once.
|
|
327
|
+
- **The log**, `GET /{workspace}/hooks/{name}`, keeps every call for 30 days: its outcome, its status and the ids written, never the body.
|
|
328
|
+
- No verification provider is built in: any system that signs its notices works.
|
|
329
|
+
<!-- src: docs/internal/invariants/webhooks.md (READER-WRITES B7 D605, D606); packages/api/src/routes/hooks.ts; packages/webhooks/src/inbound.ts; packages/cli/src/mcp/server.ts apply_hook; tests/integration/reader-writes/inbound-hooks.test.ts -->
|
|
330
|
+
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
## 6. Importing a prototype's data {#cap-import}
|
|
334
|
+
|
|
335
|
+
A prototype's users and their data do not move to the workspace: the model, the roles and the app move ([method](method.md), Reading the prototype). Whatever a member imports (`POST /{workspace}/records/{schema}/import`, `apply_records`) is the member's, not a user's: it would not be "theirs" for the role.
|
|
336
|
+
`apply_records` also writes a tree in one call: a record carries the records of its relation to many as objects (a menu with its entries, each with its sub-entries); each is found again among the links of its own parent, so entries with the same label under different parents stay different records. A match may be a list of fields whose combination is unique.
|
|
337
|
+
<!-- src: packages/cli/src/mcp/server.ts instructions ("never its users nor their data"); records-access.md (import = create through the gate, _createdBy = the caller) -->
|
|
338
|
+
|
|
339
|
+
The nearest way: the user, signed in to the new app, brings their own history — the app reads what the user exported from the old system and writes it as them, one record per call, within 60 writes a minute, with a client id so a retry never duplicates ([offline sync](#cap-offline-sync)).
|
|
340
|
+
|
|
341
|
+
---
|
|
342
|
+
|
|
343
|
+
## 7. Not possible today, and the nearest way {#cap-not-yet}
|
|
344
|
+
|
|
345
|
+
| Need | Nearest way today | What is lost | Where it would come from |
|
|
346
|
+
|---|---|---|---|
|
|
347
|
+
| **Joining with a code** without listing the groups | The group is readable by a condition (`open = true`); the user links themselves to it with a record of their own (`member` → `group`, `unique: [["_createdBy"]]` for one group per user) | Anyone can list the open groups and their codes | READER-WRITES step 2 (privileged operations) |
|
|
348
|
+
| **Values computed by the platform** (counters, XP, streaks, totals) and checks the client cannot fake | The app computes them from the user's own records and writes them as theirs | A user can inflate their own values | READER-WRITES step 2 (derived counters) |
|
|
349
|
+
| **Work at the end of a period** (awards, rankings) | A member writes and publishes them (dashboard, `apply_records` + `publish`), readable by `where _status = published` | Not automatic; someone does it each period | READER-WRITES step 2 (scheduled work) |
|
|
350
|
+
| **Domain logic once, on the platform** | Written in the app (Swift and Kotlin) | Two implementations | None: code of the client on the platform is excluded |
|
|
351
|
+
| **Push notifications, scheduled jobs** | Local notifications of the phone | No reminder decided by the server | None |
|
|
352
|
+
| **Sign-in with an email code, no password** | Apple / Google, or an OpenID Connect provider that offers it (by its issuer) | — | None |
|
|
353
|
+
| **Invitations to a closed beta** | `open` while the invited people sign in for the first time, then `closed`; anyone else who came in meanwhile revoked | A window in which anyone can enter | None |
|
|
354
|
+
| **A custom URL scheme as the sign-in return** | The Site URL with the app's links (`/.well-known`). In development, without them: the site's own route at `<Site URL>/api/cms/signed-in` may hand the code on to the app's scheme — the code is worthless without the app's verifier (PKCE) | That route is the site's code, outside the standard and `thecms verify` | None |
|
|
355
|
+
| **A user deletes their own account from the app** | The user deletes their own records; a member forgets them on request | Not self-service | None |
|
|
356
|
+
| **A client-chosen id, an upsert** | A client id with a uniqueness ([offline sync](#cap-offline-sync)) | A second call to change a record already saved | None |
|
|
357
|
+
| **Several records in one call** by a user | One call per record within 60 a minute | Speed of a large sync | None |
|
|
358
|
+
<!-- src: docs/internal/dossier/READER-WRITES.md ("Passo 2": contatori derivati, operazioni privilegiate, ambiti fra utenti, lavori pianificati, file privati; "Scartate": funzioni server ospitate); sign-in.md (methods); end-users.md (D562 no batch); assets.md (immutable public URL); grep of docs/internal/dossier for push, email code, invitations, custom scheme: no step, 13/11/2026 -->
|