@thatopen/services 0.34.5 → 0.35.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/README.md +66 -66
- package/dist/cli.js +54 -12
- package/dist/cli.js.map +1 -1
- package/dist/core/app-cache.d.ts +32 -0
- package/dist/core/app-cache.test.d.ts +1 -0
- package/dist/core/client.d.ts +9 -1
- package/dist/index.cjs.js +5 -5
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +974 -917
- package/dist/index.es.js.map +1 -1
- package/dist/types/context.d.ts +6 -0
- package/dist/vite-env.d.ts +1 -1
- package/docs/ai-quickstart.md +548 -548
- package/docs/builtin/paths.json +130 -130
- package/docs/cli/create.md +29 -29
- package/docs/cli/local-server.md +38 -38
- package/docs/cli/login.md +32 -32
- package/docs/cli/mcp.md +46 -46
- package/docs/cli/publish.md +31 -31
- package/docs/cli/run.md +26 -26
- package/docs/cli/serve.md +43 -43
- package/docs/cli/swap.md +30 -30
- package/docs/cloud/GaussianSplatConverter.md +43 -43
- package/docs/cloud/PointCloudConverter.md +53 -53
- package/docs/flow-architecture.md +393 -393
- package/docs/flow-plugin-guide.md +354 -354
- package/docs/platform-token.md +81 -81
- package/docs/rate-limits.md +133 -133
- package/docs/recipes-guide.md +243 -243
- package/docs/revit-collab-quickstart.md +445 -445
- package/docs/rhino-interop-quickstart.md +387 -387
- package/docs/sheet-sets-guide.md +69 -69
- package/package.json +4 -4
- package/resources/AGENTS.md +57 -57
- package/src/built-in/CDEManager/example.ts +214 -214
- package/src/built-in/CDEManager/examples/FileEditing/example.ts +226 -226
- package/src/built-in/CDEManager/examples/FileMoves/example.ts +186 -186
- package/src/built-in/CDEManager/examples/FileOperations/example.ts +295 -295
- package/src/built-in/CDEManager/examples/FileTransfers/example.ts +210 -210
- package/src/built-in/CDEManager/examples/FolderManagement/example.ts +230 -230
- package/src/built-in/CDEManager/examples/MetadataSchema/example.ts +230 -230
- package/src/built-in/CDEManager/examples/MetadataViews/example.ts +166 -166
- package/src/built-in/CDEManager/examples/ProjectConfig/example.ts +177 -177
- package/src/built-in/ClashesManager/example.ts +283 -283
- package/src/built-in/GISManager/example.ts +355 -355
- package/src/built-in/ProjectManager/example.ts +124 -124
- package/src/built-in/UIManager/src/app/example.ts +97 -97
- package/src/built-in/UIManager/src/app/examples/AppState/example.ts +140 -140
- package/src/built-in/UIManager/src/app/examples/Banner/example.ts +159 -159
- package/src/built-in/UIManager/src/app/examples/Contexts/example.ts +123 -123
- package/src/built-in/UIManager/src/app/examples/FileDrop/example.ts +124 -124
- package/src/built-in/UIManager/src/app/examples/FloatingLayout/example.ts +90 -90
- package/src/built-in/UIManager/src/app/examples/Modal/example.ts +163 -163
- package/src/built-in/UIManager/src/app/examples/Notifications/example.ts +133 -133
- package/src/built-in/UIManager/src/app/examples/ProjectFileStorage/example.ts +150 -150
- package/src/built-in/UIManager/src/app/examples/Sidebar/example.ts +105 -105
- package/src/built-in/UIManager/src/clashes-panel/example.ts +183 -183
- package/src/built-in/UIManager/src/gis-panel/example.ts +163 -163
- package/src/built-in/UIManager/src/gis-properties-panel/example.ts +168 -168
- package/src/built-in/UIManager/src/git-history-panel/example.ts +70 -70
- package/src/built-in/UIManager/src/map-panel/example.ts +189 -189
- package/src/built-in/UIManager/src/models-list/example.ts +181 -181
- package/src/built-in/UIManager/src/settings-panel/example.ts +303 -303
- package/src/built-in/UIManager/src/topics-panel/example.ts +170 -170
- package/src/built-in/UIManager/src/viewer/example.ts +182 -182
- package/src/built-in/UIManager/src/viewer-toolbar/example.ts +376 -376
- package/src/built-in/index.ts +2995 -2995
- package/src/cli/templates/app/README.md +250 -250
- package/src/cli/templates/app/index.html +35 -35
- package/src/cli/templates/app/package.json +32 -32
- package/src/cli/templates/app/src/app.ts +37 -37
- package/src/cli/templates/app/src/assets/tool-placeholder.ts +50 -50
- package/src/cli/templates/app/src/bim-components/CloudRunner/index.ts +95 -95
- package/src/cli/templates/app/src/bim-components/CloudRunner/src/index.ts +1 -1
- package/src/cli/templates/app/src/bim-components/CloudRunner/src/types.ts +5 -5
- package/src/cli/templates/app/src/bim-components/index.ts +1 -1
- package/src/cli/templates/app/src/globals.ts +1 -1
- package/src/cli/templates/app/src/main.history.ts +191 -191
- package/src/cli/templates/app/src/main.ts +226 -226
- package/src/cli/templates/app/src/setups/channel.ts +76 -76
- package/src/cli/templates/app/src/setups/reality-capture/lib/hidden-tiles-plugin.ts +88 -88
- package/src/cli/templates/app/src/setups/reality-capture/lib/point-tile-plugin.ts +166 -166
- package/src/cli/templates/app/src/setups/reality-capture/lib/render-frame.ts +31 -31
- package/src/cli/templates/app/src/setups/reality-capture/lib/splat-tile-plugin.ts +51 -51
- package/src/cli/templates/app/src/setups/reality-capture-viewer.ts +1383 -1383
- package/src/cli/templates/app/src/ui-components/app-info-section/index.ts +26 -26
- package/src/cli/templates/app/src/ui-components/app-info-section/src/index.ts +1 -1
- package/src/cli/templates/app/src/ui-components/app-info-section/src/types.ts +15 -15
- package/src/cli/templates/app/src/ui-components/cloud-runner-section/index.ts +37 -37
- package/src/cli/templates/app/src/ui-components/cloud-runner-section/src/index.ts +1 -1
- package/src/cli/templates/app/src/ui-components/cloud-runner-section/src/types.ts +14 -14
- package/src/cli/templates/app/src/ui-components/index.ts +2 -2
- package/src/cli/templates/app/tsconfig.json +16 -16
- package/src/cli/templates/app/vite.config.js +57 -57
- package/src/cli/templates/cloud-component/README.md +205 -205
- package/src/cli/templates/cloud-component/_thatopen +5 -5
- package/src/cli/templates/cloud-component/declarations.json +4 -4
- package/src/cli/templates/cloud-component/package.json +21 -21
- package/src/cli/templates/cloud-component/src/main.ts +70 -70
- package/src/cli/templates/cloud-component/tsconfig.json +16 -16
- package/src/cli/templates/cloud-component/vite.config.js +46 -46
- package/src/cli/templates/shared/AGENTS.md +8 -8
- package/src/cli/templates/shared/CLAUDE.md +1 -1
- package/src/cli/templates/shared/_gitignore +5 -5
- package/src/core/examples/.env.example +7 -7
- package/src/core/examples/apps.ts +67 -67
- package/src/core/examples/batch-reads.ts +99 -99
- package/src/core/examples/channel.ts +65 -65
- package/src/core/examples/components.ts +91 -91
- package/src/core/examples/execution.ts +75 -75
- package/src/core/examples/file-metadata.ts +94 -94
- package/src/core/examples/files.ts +81 -81
- package/src/core/examples/folders.ts +82 -82
- package/src/core/examples/hidden-files.ts +88 -88
- package/src/core/examples/history.ts +103 -103
- package/src/core/examples/icons.ts +68 -68
- package/src/core/examples/permissions.ts +87 -87
package/docs/platform-token.md
CHANGED
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
# Logging in to That Open Platform
|
|
2
|
-
|
|
3
|
-
Everything else in these guides needs this, and it is the same three lines every time, so it lives
|
|
4
|
-
here rather than in each of them.
|
|
5
|
-
|
|
6
|
-
## Get the token
|
|
7
|
-
|
|
8
|
-
Say this to the user, and wait:
|
|
9
|
-
|
|
10
|
-
> "To log in I need a That Open Platform **access token**. You create it yourself:
|
|
11
|
-
> **https://platform.thatopen.com/dashboard/data → API Tokens → Add → copy** (Account Settings shows the same card), then paste it
|
|
12
|
-
> here."
|
|
13
|
-
|
|
14
|
-
**Never print it back, never write it into a file, never commit it.** Not into a script, not into a
|
|
15
|
-
`.env` you are about to show, not into a chat message quoting the command you ran.
|
|
16
|
-
|
|
17
|
-
## Log in
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
thatopen login --token <TOKEN>
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
Credentials go to `~/.thatopen/config.json`, as `accessToken` and `apiUrl`. `--local` writes them to
|
|
24
|
-
a `.thatopen` file in the project instead, which is what a scaffolded project uses.
|
|
25
|
-
|
|
26
|
-
You do not need an npm account or an npm token for the private packages. The CLI derives access to
|
|
27
|
-
them from this one.
|
|
28
|
-
|
|
29
|
-
## Everyone is on production
|
|
30
|
-
|
|
31
|
-
**Do not ask the user which environment they want.** Production is the answer, it is the default,
|
|
32
|
-
and the plain command above is already correct. Asking turns a decision nobody has into a question
|
|
33
|
-
they cannot answer, at the worst possible moment — the first thing you say to them.
|
|
34
|
-
|
|
35
|
-
There is a `dev` platform, and it exists for the people building That Open Platform itself. If the
|
|
36
|
-
user is one of them they already know, and they will tell you without being asked.
|
|
37
|
-
|
|
38
|
-
Everything below this line is for that case only. If nothing has mentioned dev, skip it.
|
|
39
|
-
|
|
40
|
-
<details>
|
|
41
|
-
<summary>Dev, for the platform team</summary>
|
|
42
|
-
|
|
43
|
-
Two platforms, not two views of one. Separate accounts, separate tokens, separate projects. A token
|
|
44
|
-
from one is refused by the other, and a model published to the wrong one lands somewhere the user's
|
|
45
|
-
team cannot see — while every command reports success.
|
|
46
|
-
|
|
47
|
-
```bash
|
|
48
|
-
thatopen login --token <TOKEN> --api-url https://dev.platform.thatopen.com
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
Its dashboard is the same page on that host: `https://dev.platform.thatopen.com/dashboard/data`.
|
|
52
|
-
|
|
53
|
-
</details>
|
|
54
|
-
|
|
55
|
-
## Check, do not ask
|
|
56
|
-
|
|
57
|
-
**`login` prints "Logged in successfully" and does not name the environment**, so nothing on screen
|
|
58
|
-
would contradict a wrong assumption. Read `apiUrl` from `~/.thatopen/config.json` yourself.
|
|
59
|
-
|
|
60
|
-
If it says production — which it will — say nothing about it and carry on. There is no decision to
|
|
61
|
-
report.
|
|
62
|
-
|
|
63
|
-
**Only if it says dev**, and the user has not told you they work there, is there anything to say:
|
|
64
|
-
|
|
65
|
-
> "This machine is pointed at the dev platform, which is the one the That Open team builds on. I'll
|
|
66
|
-
> move it to production — that will need a token from **https://platform.thatopen.com/dashboard/data**,
|
|
67
|
-
> since dev tokens are not accepted there."
|
|
68
|
-
|
|
69
|
-
Check this **even when the machine is already logged in**, and especially then. A saved login is
|
|
70
|
-
whoever used this machine last, not an answer to a question you have asked.
|
|
71
|
-
|
|
72
|
-
## When it fails
|
|
73
|
-
|
|
74
|
-
- **`Unauthorized`** — the token is invalid, expired, or from the other environment. Production
|
|
75
|
-
tokens use no `--api-url`; dev tokens need it. Ask for a fresh one from the same environment as
|
|
76
|
-
the URL you are using.
|
|
77
|
-
- **HTTP 403 on `item/folder?projectId=…`** — login worked. The account simply has no access to that
|
|
78
|
-
project, or the project is in the other environment. Confirm the project id with the user before
|
|
79
|
-
assuming anything is broken.
|
|
80
|
-
- **A private package fails to install** — you are not logged in, or logged in to the environment
|
|
81
|
-
that does not have it. Log in again and retry; there is no separate npm login to do.
|
|
1
|
+
# Logging in to That Open Platform
|
|
2
|
+
|
|
3
|
+
Everything else in these guides needs this, and it is the same three lines every time, so it lives
|
|
4
|
+
here rather than in each of them.
|
|
5
|
+
|
|
6
|
+
## Get the token
|
|
7
|
+
|
|
8
|
+
Say this to the user, and wait:
|
|
9
|
+
|
|
10
|
+
> "To log in I need a That Open Platform **access token**. You create it yourself:
|
|
11
|
+
> **https://platform.thatopen.com/dashboard/data → API Tokens → Add → copy** (Account Settings shows the same card), then paste it
|
|
12
|
+
> here."
|
|
13
|
+
|
|
14
|
+
**Never print it back, never write it into a file, never commit it.** Not into a script, not into a
|
|
15
|
+
`.env` you are about to show, not into a chat message quoting the command you ran.
|
|
16
|
+
|
|
17
|
+
## Log in
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
thatopen login --token <TOKEN>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Credentials go to `~/.thatopen/config.json`, as `accessToken` and `apiUrl`. `--local` writes them to
|
|
24
|
+
a `.thatopen` file in the project instead, which is what a scaffolded project uses.
|
|
25
|
+
|
|
26
|
+
You do not need an npm account or an npm token for the private packages. The CLI derives access to
|
|
27
|
+
them from this one.
|
|
28
|
+
|
|
29
|
+
## Everyone is on production
|
|
30
|
+
|
|
31
|
+
**Do not ask the user which environment they want.** Production is the answer, it is the default,
|
|
32
|
+
and the plain command above is already correct. Asking turns a decision nobody has into a question
|
|
33
|
+
they cannot answer, at the worst possible moment — the first thing you say to them.
|
|
34
|
+
|
|
35
|
+
There is a `dev` platform, and it exists for the people building That Open Platform itself. If the
|
|
36
|
+
user is one of them they already know, and they will tell you without being asked.
|
|
37
|
+
|
|
38
|
+
Everything below this line is for that case only. If nothing has mentioned dev, skip it.
|
|
39
|
+
|
|
40
|
+
<details>
|
|
41
|
+
<summary>Dev, for the platform team</summary>
|
|
42
|
+
|
|
43
|
+
Two platforms, not two views of one. Separate accounts, separate tokens, separate projects. A token
|
|
44
|
+
from one is refused by the other, and a model published to the wrong one lands somewhere the user's
|
|
45
|
+
team cannot see — while every command reports success.
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
thatopen login --token <TOKEN> --api-url https://dev.platform.thatopen.com
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Its dashboard is the same page on that host: `https://dev.platform.thatopen.com/dashboard/data`.
|
|
52
|
+
|
|
53
|
+
</details>
|
|
54
|
+
|
|
55
|
+
## Check, do not ask
|
|
56
|
+
|
|
57
|
+
**`login` prints "Logged in successfully" and does not name the environment**, so nothing on screen
|
|
58
|
+
would contradict a wrong assumption. Read `apiUrl` from `~/.thatopen/config.json` yourself.
|
|
59
|
+
|
|
60
|
+
If it says production — which it will — say nothing about it and carry on. There is no decision to
|
|
61
|
+
report.
|
|
62
|
+
|
|
63
|
+
**Only if it says dev**, and the user has not told you they work there, is there anything to say:
|
|
64
|
+
|
|
65
|
+
> "This machine is pointed at the dev platform, which is the one the That Open team builds on. I'll
|
|
66
|
+
> move it to production — that will need a token from **https://platform.thatopen.com/dashboard/data**,
|
|
67
|
+
> since dev tokens are not accepted there."
|
|
68
|
+
|
|
69
|
+
Check this **even when the machine is already logged in**, and especially then. A saved login is
|
|
70
|
+
whoever used this machine last, not an answer to a question you have asked.
|
|
71
|
+
|
|
72
|
+
## When it fails
|
|
73
|
+
|
|
74
|
+
- **`Unauthorized`** — the token is invalid, expired, or from the other environment. Production
|
|
75
|
+
tokens use no `--api-url`; dev tokens need it. Ask for a fresh one from the same environment as
|
|
76
|
+
the URL you are using.
|
|
77
|
+
- **HTTP 403 on `item/folder?projectId=…`** — login worked. The account simply has no access to that
|
|
78
|
+
project, or the project is in the other environment. Confirm the project id with the user before
|
|
79
|
+
assuming anything is broken.
|
|
80
|
+
- **A private package fails to install** — you are not logged in, or logged in to the environment
|
|
81
|
+
that does not have it. Log in again and retry; there is no separate npm login to do.
|
package/docs/rate-limits.md
CHANGED
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
# Rate limits, and how to save data without hitting them
|
|
2
|
-
|
|
3
|
-
The platform API is rate limited. Every app and cloud component shares the same
|
|
4
|
-
budget, so **how often you write decides whether your app works**. This page has
|
|
5
|
-
the numbers, the failure mode, and the pattern to use instead.
|
|
6
|
-
|
|
7
|
-
> **The one rule:** never send a request on every change the user makes. No
|
|
8
|
-
> autosave-per-keystroke, no write inside a render loop, no polling loop that
|
|
9
|
-
> hammers a list endpoint. Keep work-in-progress in the browser and talk to the
|
|
10
|
-
> server on an explicit save.
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
## The numbers
|
|
15
|
-
|
|
16
|
-
Limits are per **rolling 60-second window**, counted per user (JWT), or per API
|
|
17
|
-
token owner, or per IP — whichever identifies the caller.
|
|
18
|
-
|
|
19
|
-
| Endpoint | Client method | Limit |
|
|
20
|
-
|---|---|---|
|
|
21
|
-
| `POST /api/item` | `createFile`, `createComponent`, `createApp` | **30 / min** |
|
|
22
|
-
| `POST /api/item/:id/version` | `updateFile` / `updateComponent` **with a `file`** | **30 / min** |
|
|
23
|
-
| `PUT /api/item/:id/version/:tag/metadata` | `updateFileVersionMetadata` | 30 / min |
|
|
24
|
-
| `DELETE /api/item/:id/version/:tag/metadata` | `deleteFileVersionMetadata` | 30 / min |
|
|
25
|
-
| `PUT /api/item/:id/version/:tag/archive` \| `/recover` | `archiveVersion`, `recoverVersion` | 30 / min |
|
|
26
|
-
| `POST /api/item/hidden` \| `/hidden/batch` | `createHiddenFile`, `createHiddenFilesBatch` | 30 / min |
|
|
27
|
-
| `POST /api/processor/:id/execute` | `executeComponent` | 20 / min |
|
|
28
|
-
| `GET /api/item/folder/:id/download`, `POST /api/item/batch/download` | `downloadFolder` | 10 / min |
|
|
29
|
-
| `POST /api/item/batch/versions` \| `/batch/version-metadata` \| `/batch/folders` | `listVersionsBatch`, `getFileVersionMetadataBatch`, `getFoldersBatch` | 60 / min |
|
|
30
|
-
| `POST /api/item/hidden/signed-url/batch` | `getHiddenFileSignedUrlsBatch` | 100 / min |
|
|
31
|
-
| `GET /api/item/hidden/:id/download` | `downloadHiddenFile` | 3000 / min |
|
|
32
|
-
| Everything else | — | 100 / min |
|
|
33
|
-
|
|
34
|
-
Two things follow from the table:
|
|
35
|
-
|
|
36
|
-
- **30 writes per minute is one write every two seconds.** An autosave tied to
|
|
37
|
-
user input passes that in a few seconds of typing or dragging.
|
|
38
|
-
- **Reads are cheap, but not free.** A viewer that mints one signed URL per tile
|
|
39
|
-
will exhaust 100/min quickly — use `getHiddenFileSignedUrlsBatch`, which signs
|
|
40
|
-
up to `STORAGE_BATCH_MAX` files per request.
|
|
41
|
-
|
|
42
|
-
## What a rate-limited response looks like
|
|
43
|
-
|
|
44
|
-
Status `429`, with a `Retry-After` header (seconds) and this body:
|
|
45
|
-
|
|
46
|
-
```json
|
|
47
|
-
{
|
|
48
|
-
"statusCode": 429,
|
|
49
|
-
"message": "Rate limit exceeded: max 30 requests per 60s for this endpoint. Retry after 12s.",
|
|
50
|
-
"code": "RATE_LIMITED",
|
|
51
|
-
"details": { "limit": 30, "windowSeconds": 60, "retryAfter": 12, "scope": "user" }
|
|
52
|
-
}
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
The client surfaces it as a `RequestError`:
|
|
56
|
-
|
|
57
|
-
```ts
|
|
58
|
-
import { RequestError } from '@thatopen/services';
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
await client.updateFile(fileId, { file: blob, versionTag: tag });
|
|
62
|
-
} catch (err) {
|
|
63
|
-
if (err instanceof RequestError && err.status === 429) {
|
|
64
|
-
// err.code === 'RATE_LIMITED'
|
|
65
|
-
// err.retryAfter — seconds to wait, from Retry-After or details.retryAfter
|
|
66
|
-
showToast(`Saving is paused for ${err.retryAfter}s — your work is kept locally.`);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
throw err;
|
|
70
|
-
}
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
**A 429 means the write did not happen.** Nothing was saved. If the user's only
|
|
74
|
-
copy of the change was in that request, it is gone — which is the real reason
|
|
75
|
-
the local-draft pattern below matters.
|
|
76
|
-
|
|
77
|
-
## The pattern: drafts in memory, explicit saves
|
|
78
|
-
|
|
79
|
-
Keep every intermediate state in memory. Write to the platform only when the
|
|
80
|
-
user asks for it, or on a slow timer.
|
|
81
|
-
|
|
82
|
-
> **Why not `localStorage`?** Platform apps run in a sandboxed iframe on an
|
|
83
|
-
> **opaque origin**, where `localStorage`, `sessionStorage`, IndexedDB and
|
|
84
|
-
> cookies don't return empty — they **throw, on the property access itself**.
|
|
85
|
-
> Dev mode grants `allow-same-origin`, so origin storage works on the machine
|
|
86
|
-
> of whoever writes the app and fails for every user. This has shipped broken
|
|
87
|
-
> at least once. Inside a platform app there are exactly two stores: memory,
|
|
88
|
-
> and the platform through the client API.
|
|
89
|
-
|
|
90
|
-
```ts
|
|
91
|
-
const drafts = new Map<string, { state: unknown; at: number }>();
|
|
92
|
-
|
|
93
|
-
function onChange(fileId: string, state: unknown) {
|
|
94
|
-
drafts.set(fileId, { state, at: Date.now() });
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
async function onSave(fileId: string, state: unknown) {
|
|
98
|
-
const blob = new Blob([JSON.stringify(state)], { type: 'application/json' });
|
|
99
|
-
await client.updateFile(fileId, { file: blob, versionTag: `v${Date.now()}` });
|
|
100
|
-
drafts.delete(fileId);
|
|
101
|
-
}
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
A draft in memory does not survive a reload. If surviving one matters, the
|
|
105
|
-
draft itself has to go to the platform — on the explicit save, or on the slow
|
|
106
|
-
timer below — because there is nowhere else to put it.
|
|
107
|
-
|
|
108
|
-
Rules of thumb:
|
|
109
|
-
|
|
110
|
-
- **Explicit save**, or a timer no faster than **once every 30 seconds**, and
|
|
111
|
-
only when something actually changed.
|
|
112
|
-
- **One request per save**, not one per changed object. Batch the whole document.
|
|
113
|
-
- **Never save while a save is in flight.** Keep a flag per file, and drop or
|
|
114
|
-
queue the second save. Overlapping writes also create versions that are hard
|
|
115
|
-
to reconcile.
|
|
116
|
-
- **Big or binary work-in-progress** stays in memory too — there is no
|
|
117
|
-
IndexedDB fallback in the sandbox, so size is bounded by RAM, which is fine:
|
|
118
|
-
it is the same object the app is already editing.
|
|
119
|
-
- There is **no draft-write method in the client on purpose.** Memory is the
|
|
120
|
-
draft store; the platform stores versions the user chose to keep.
|
|
121
|
-
|
|
122
|
-
## Retries
|
|
123
|
-
|
|
124
|
-
The client does not retry by default. When you turn retries on, it backs off
|
|
125
|
-
exponentially, adds jitter, and honours `Retry-After`:
|
|
126
|
-
|
|
127
|
-
```ts
|
|
128
|
-
const client = new EngineServicesClient(token, apiUrl, { retries: 3 });
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
Only network failures, `429` and `5xx` are retried. Other `4xx` fail straight
|
|
132
|
-
away, because repeating them cannot help. Never write your own immediate retry
|
|
133
|
-
loop around a 429 — that is what turns a throttled request into an outage.
|
|
1
|
+
# Rate limits, and how to save data without hitting them
|
|
2
|
+
|
|
3
|
+
The platform API is rate limited. Every app and cloud component shares the same
|
|
4
|
+
budget, so **how often you write decides whether your app works**. This page has
|
|
5
|
+
the numbers, the failure mode, and the pattern to use instead.
|
|
6
|
+
|
|
7
|
+
> **The one rule:** never send a request on every change the user makes. No
|
|
8
|
+
> autosave-per-keystroke, no write inside a render loop, no polling loop that
|
|
9
|
+
> hammers a list endpoint. Keep work-in-progress in the browser and talk to the
|
|
10
|
+
> server on an explicit save.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## The numbers
|
|
15
|
+
|
|
16
|
+
Limits are per **rolling 60-second window**, counted per user (JWT), or per API
|
|
17
|
+
token owner, or per IP — whichever identifies the caller.
|
|
18
|
+
|
|
19
|
+
| Endpoint | Client method | Limit |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| `POST /api/item` | `createFile`, `createComponent`, `createApp` | **30 / min** |
|
|
22
|
+
| `POST /api/item/:id/version` | `updateFile` / `updateComponent` **with a `file`** | **30 / min** |
|
|
23
|
+
| `PUT /api/item/:id/version/:tag/metadata` | `updateFileVersionMetadata` | 30 / min |
|
|
24
|
+
| `DELETE /api/item/:id/version/:tag/metadata` | `deleteFileVersionMetadata` | 30 / min |
|
|
25
|
+
| `PUT /api/item/:id/version/:tag/archive` \| `/recover` | `archiveVersion`, `recoverVersion` | 30 / min |
|
|
26
|
+
| `POST /api/item/hidden` \| `/hidden/batch` | `createHiddenFile`, `createHiddenFilesBatch` | 30 / min |
|
|
27
|
+
| `POST /api/processor/:id/execute` | `executeComponent` | 20 / min |
|
|
28
|
+
| `GET /api/item/folder/:id/download`, `POST /api/item/batch/download` | `downloadFolder` | 10 / min |
|
|
29
|
+
| `POST /api/item/batch/versions` \| `/batch/version-metadata` \| `/batch/folders` | `listVersionsBatch`, `getFileVersionMetadataBatch`, `getFoldersBatch` | 60 / min |
|
|
30
|
+
| `POST /api/item/hidden/signed-url/batch` | `getHiddenFileSignedUrlsBatch` | 100 / min |
|
|
31
|
+
| `GET /api/item/hidden/:id/download` | `downloadHiddenFile` | 3000 / min |
|
|
32
|
+
| Everything else | — | 100 / min |
|
|
33
|
+
|
|
34
|
+
Two things follow from the table:
|
|
35
|
+
|
|
36
|
+
- **30 writes per minute is one write every two seconds.** An autosave tied to
|
|
37
|
+
user input passes that in a few seconds of typing or dragging.
|
|
38
|
+
- **Reads are cheap, but not free.** A viewer that mints one signed URL per tile
|
|
39
|
+
will exhaust 100/min quickly — use `getHiddenFileSignedUrlsBatch`, which signs
|
|
40
|
+
up to `STORAGE_BATCH_MAX` files per request.
|
|
41
|
+
|
|
42
|
+
## What a rate-limited response looks like
|
|
43
|
+
|
|
44
|
+
Status `429`, with a `Retry-After` header (seconds) and this body:
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"statusCode": 429,
|
|
49
|
+
"message": "Rate limit exceeded: max 30 requests per 60s for this endpoint. Retry after 12s.",
|
|
50
|
+
"code": "RATE_LIMITED",
|
|
51
|
+
"details": { "limit": 30, "windowSeconds": 60, "retryAfter": 12, "scope": "user" }
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The client surfaces it as a `RequestError`:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { RequestError } from '@thatopen/services';
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
await client.updateFile(fileId, { file: blob, versionTag: tag });
|
|
62
|
+
} catch (err) {
|
|
63
|
+
if (err instanceof RequestError && err.status === 429) {
|
|
64
|
+
// err.code === 'RATE_LIMITED'
|
|
65
|
+
// err.retryAfter — seconds to wait, from Retry-After or details.retryAfter
|
|
66
|
+
showToast(`Saving is paused for ${err.retryAfter}s — your work is kept locally.`);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**A 429 means the write did not happen.** Nothing was saved. If the user's only
|
|
74
|
+
copy of the change was in that request, it is gone — which is the real reason
|
|
75
|
+
the local-draft pattern below matters.
|
|
76
|
+
|
|
77
|
+
## The pattern: drafts in memory, explicit saves
|
|
78
|
+
|
|
79
|
+
Keep every intermediate state in memory. Write to the platform only when the
|
|
80
|
+
user asks for it, or on a slow timer.
|
|
81
|
+
|
|
82
|
+
> **Why not `localStorage`?** Platform apps run in a sandboxed iframe on an
|
|
83
|
+
> **opaque origin**, where `localStorage`, `sessionStorage`, IndexedDB and
|
|
84
|
+
> cookies don't return empty — they **throw, on the property access itself**.
|
|
85
|
+
> Dev mode grants `allow-same-origin`, so origin storage works on the machine
|
|
86
|
+
> of whoever writes the app and fails for every user. This has shipped broken
|
|
87
|
+
> at least once. Inside a platform app there are exactly two stores: memory,
|
|
88
|
+
> and the platform through the client API.
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
const drafts = new Map<string, { state: unknown; at: number }>();
|
|
92
|
+
|
|
93
|
+
function onChange(fileId: string, state: unknown) {
|
|
94
|
+
drafts.set(fileId, { state, at: Date.now() });
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function onSave(fileId: string, state: unknown) {
|
|
98
|
+
const blob = new Blob([JSON.stringify(state)], { type: 'application/json' });
|
|
99
|
+
await client.updateFile(fileId, { file: blob, versionTag: `v${Date.now()}` });
|
|
100
|
+
drafts.delete(fileId);
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
A draft in memory does not survive a reload. If surviving one matters, the
|
|
105
|
+
draft itself has to go to the platform — on the explicit save, or on the slow
|
|
106
|
+
timer below — because there is nowhere else to put it.
|
|
107
|
+
|
|
108
|
+
Rules of thumb:
|
|
109
|
+
|
|
110
|
+
- **Explicit save**, or a timer no faster than **once every 30 seconds**, and
|
|
111
|
+
only when something actually changed.
|
|
112
|
+
- **One request per save**, not one per changed object. Batch the whole document.
|
|
113
|
+
- **Never save while a save is in flight.** Keep a flag per file, and drop or
|
|
114
|
+
queue the second save. Overlapping writes also create versions that are hard
|
|
115
|
+
to reconcile.
|
|
116
|
+
- **Big or binary work-in-progress** stays in memory too — there is no
|
|
117
|
+
IndexedDB fallback in the sandbox, so size is bounded by RAM, which is fine:
|
|
118
|
+
it is the same object the app is already editing.
|
|
119
|
+
- There is **no draft-write method in the client on purpose.** Memory is the
|
|
120
|
+
draft store; the platform stores versions the user chose to keep.
|
|
121
|
+
|
|
122
|
+
## Retries
|
|
123
|
+
|
|
124
|
+
The client does not retry by default. When you turn retries on, it backs off
|
|
125
|
+
exponentially, adds jitter, and honours `Retry-After`:
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
const client = new EngineServicesClient(token, apiUrl, { retries: 3 });
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Only network failures, `429` and `5xx` are retried. Other `4xx` fail straight
|
|
132
|
+
away, because repeating them cannot help. Never write your own immediate retry
|
|
133
|
+
loop around a 429 — that is what turns a throttled request into an outage.
|