@telecrypt-io/storage 0.2.2 → 0.2.4

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 CHANGED
@@ -8,14 +8,14 @@ Files are encrypted on the client before upload. The server stores only opaque c
8
8
  never holds the decryption keys. Shared folders let multiple people add and read files, and a
9
9
  Recovery Key restores your files on a new device — even if you lose the original.
10
10
 
11
- **Status:** library source only. `@telecrypt-io/storage@0.2.2` is the current public release,
12
- published from this repository's protected `v0.2.2` tag with NPM Trusted Publishing/OIDC
11
+ **Status:** library source only. `@telecrypt-io/storage@0.2.4` is the current public release,
12
+ published from this repository's protected `v0.2.4` tag with NPM Trusted Publishing/OIDC
13
13
  provenance. The older `0.1.3` release is the immutable legacy combined library-and-CLI package.
14
14
 
15
15
  ## Install
16
16
 
17
17
  ```bash
18
- npm install @telecrypt-io/storage@0.2.2
18
+ npm install @telecrypt-io/storage@0.2.4
19
19
  ```
20
20
 
21
21
  This gives you the `TeleCryptIOStorage` library and its browser-safe `core` API.
@@ -1,5 +1,47 @@
1
1
  import { CliError } from "./errors.js";
2
2
  import { waitForCondition } from "./poll.js";
3
+ /**
4
+ * Production Synapse enforces the built-in rc_messages budget (per-account
5
+ * burst 10, refill 1/5s) on every room/state mutation the tree operations
6
+ * issue. A delete/decline sequence (kick members + leave + forget) can
7
+ * exceed the burst within seconds, so each operation retries on 429 with the
8
+ * server-advised backoff. Mirrors the harness library suite's
9
+ * `withRateLimitRetry`; must not mask non-rate-limit failures.
10
+ */
11
+ const RATE_LIMIT_RETRIES = 6;
12
+ function isRateLimited(error) {
13
+ if (!(error instanceof Error))
14
+ return false;
15
+ if (!("isRateLimitError" in error))
16
+ return false;
17
+ const isRateLimitError = error.isRateLimitError;
18
+ return typeof isRateLimitError === "function" && isRateLimitError.call(error) === true;
19
+ }
20
+ async function withRateLimitRetry(label, operation) {
21
+ for (let attempt = 0;; attempt++) {
22
+ try {
23
+ return await operation();
24
+ }
25
+ catch (error) {
26
+ if (!isRateLimited(error) || attempt >= RATE_LIMIT_RETRIES)
27
+ throw error;
28
+ // The server's retry_after_ms only covers one token; tree operations
29
+ // need several (kick + leave + forget). Wait at least 15s so the
30
+ // burst refills.
31
+ let retryAfter = 15_000;
32
+ if (error instanceof Error && "getRetryAfterMs" in error) {
33
+ const getRetryAfterMs = error.getRetryAfterMs;
34
+ if (typeof getRetryAfterMs === "function") {
35
+ const advised = getRetryAfterMs.call(error);
36
+ if (typeof advised === "number" && Number.isFinite(advised) && advised > 0) {
37
+ retryAfter = Math.max(retryAfter, advised);
38
+ }
39
+ }
40
+ }
41
+ await new Promise((resolve) => setTimeout(resolve, retryAfter));
42
+ }
43
+ }
44
+ }
3
45
  /**
4
46
  * Resolves a folder by ID, polling briefly: a room this same account just
5
47
  * created (or was just invited to, by another process/session) can be
@@ -100,8 +142,17 @@ export async function listPendingInvites(storage) {
100
142
  }
101
143
  /** Decline a folder invite (same as leaving before join). */
102
144
  export async function declineInvite(storage, folderId) {
145
+ const client = storage.getClient();
103
146
  try {
104
- await storage.getClient().leave(folderId);
147
+ await withRateLimitRetry("declineInvite", async () => {
148
+ await client.leave(folderId);
149
+ // The server only allows forgetting a room once this account's
150
+ // membership is `leave`; forgetting removes the room from the local
151
+ // store immediately, so a declined invite stops showing up in
152
+ // listFolders/listPendingInvites without waiting for the leave event
153
+ // to round-trip through the background sync loop.
154
+ await client.forget(folderId);
155
+ });
105
156
  }
106
157
  catch (err) {
107
158
  throw new CliError(`decline failed: ${err.message}`);
@@ -167,7 +218,22 @@ export async function renameFolder(storage, folderId, name) {
167
218
  }
168
219
  export async function deleteFolder(storage, folderId) {
169
220
  const tree = await resolveTree(storage, folderId);
170
- await tree.delete();
221
+ // `tree.delete()` kicks members and leaves this room AND every
222
+ // subdirectory room, but never forgets any of them, so they all linger in
223
+ // the local store and listFolders keeps returning the deleted folder until
224
+ // the leave events round-trip through the background sync loop (30-60s
225
+ // under full-suite load). Forgetting removes each room from the local
226
+ // store immediately; the server only accepts a forget once membership is
227
+ // `leave`, which `tree.delete()` has just completed for the whole tree.
228
+ const subdirectoryIds = tree.getDirectories().map((d) => d.id);
229
+ const client = storage.getClient();
230
+ await withRateLimitRetry("deleteFolder", async () => {
231
+ await tree.delete();
232
+ await client.forget(folderId);
233
+ for (const subId of subdirectoryIds) {
234
+ await client.forget(subId);
235
+ }
236
+ });
171
237
  return { id: folderId, deleted: true };
172
238
  }
173
239
  export async function renameFile(storage, folderId, fileId, name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telecrypt-io/storage",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "license": "BUSL-1.1",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",