@estiva-app/conversation 0.32.0 → 0.33.0
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/CHANGELOG.md +24 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/refusals.d.ts +59 -0
- package/dist/refusals.d.ts.map +1 -0
- package/dist/refusals.js +168 -0
- package/dist/refusals.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +13 -1
- package/src/refusals.ts +176 -0
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,30 @@ none. A change to how an event is read is a MINOR in `0.x` even when no
|
|
|
6
6
|
signature moved, because two apps on different versions would then disagree
|
|
7
7
|
about a conversation.
|
|
8
8
|
|
|
9
|
+
## 0.33.0 — 2026-11-04
|
|
10
|
+
|
|
11
|
+
**SPEC: none — nothing read or written changes; this is the words a person
|
|
12
|
+
reads when a write is refused** (ONE-4; Miky, 4 Nov).
|
|
13
|
+
|
|
14
|
+
- `refusalReason` / `refusalCause` (new): any refusal — the relay's `invalid:`,
|
|
15
|
+
`restricted:`, `rate-limited:` or `auth-required:` reason, an HTTP body, a
|
|
16
|
+
builder's `content is N bytes, max M`, a network error, or an app's own
|
|
17
|
+
`{ cause }` — comes to one plain reason, the same in every app: "it is too
|
|
18
|
+
long", "this message was deleted, or you can no longer write here", "you can
|
|
19
|
+
no longer write here", "this team is archived", "too many at once, try again
|
|
20
|
+
in a moment", "your computer’s clock is wrong; set it and try again", "you are
|
|
21
|
+
signed out; sign in again", and "something went wrong, try again" for
|
|
22
|
+
anything else. The relay's own words are never one of them.
|
|
23
|
+
- `tooLarge` / `uploadLimit` / `UPLOAD_LIMITS` (new): the relay's size limits —
|
|
24
|
+
a GIF 10 MB, another picture 50 MB, anything else 100 MB (Cloudflare refuses
|
|
25
|
+
a larger body) — checked before a file uploads: "Too large: the most is 10
|
|
26
|
+
MB".
|
|
27
|
+
- `uploadRefusal` (new): the line on a file's card when its upload is refused,
|
|
28
|
+
from protocol's `upload failed: <status> <body>`: the limit the relay named,
|
|
29
|
+
"This type of file can’t be added", "This file could not be read", "Too many
|
|
30
|
+
at once, try again in a moment", "Sign in again", "You can no longer add
|
|
31
|
+
files here" or "Could not upload, try again".
|
|
32
|
+
|
|
9
33
|
## 0.32.0 — 2026-11-04
|
|
10
34
|
|
|
11
35
|
**SPEC: §6.4's new "Resolving a thread", §6.5's three states of a top-level
|
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* apps: it imports no app's data layer, opens no socket, and takes every
|
|
13
13
|
* environment touch — the relay read, the clock, storage — as a parameter.
|
|
14
14
|
*/
|
|
15
|
-
export declare const CONVERSATION_VERSION = "0.
|
|
15
|
+
export declare const CONVERSATION_VERSION = "0.33.0";
|
|
16
16
|
export { KIND_MESSAGE, KIND_COMMENT, KIND_EDIT, KIND_REACTION, KIND_DELETION, KIND_ASSERTION, isConversationKind, isEventId, } from './kinds.js';
|
|
17
17
|
export { trustedTs, orderingMs, byOrder } from './order.js';
|
|
18
18
|
export { namedInBody, isReply, anchorsOf, anchorIdsOf, isAbout, isCrossedComment, isCrossedCommentOn, isCommentOn, referencesAddress, strengthOn, threadStrength, referenceTagsFor, mentionTagsFor, peopleNamedInBody, MAX_MENTIONED_PEOPLE, type Strength, } from './strength.js';
|
|
@@ -37,5 +37,6 @@ export { peopleNamedInText, newlyNamedPeople, mentionAddsFor, type FileText } fr
|
|
|
37
37
|
export { KIND_MEMBERSHIP_LIST, namedProfilesOf, rosterOf, byName, mentionablePeople, type NamedProfile } from './people.js';
|
|
38
38
|
export { messageWords, openingWords, referenceWord, type OpeningWordsOptions } from './openingWords.js';
|
|
39
39
|
export { archivedLine } from './archivedLine.js';
|
|
40
|
+
export { refusalCause, refusalReason, REFUSAL_REASONS, tooLarge, uploadLimit, uploadRefusal, UPLOAD_LIMITS, type RefusalCause, type UploadCause, } from './refusals.js';
|
|
40
41
|
export { createDraftStore, draftKeys, NO_DRAFTS, DRAFT_MAX_AGE_MS, DRAFT_MAX_CHARS, type Draft, type DraftStore, type DraftStorage, } from './drafts.js';
|
|
41
42
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,oBAAoB,WAAW,CAAA;AAE5C,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,aAAa,EACb,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,SAAS,GACV,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3D,OAAO,EACL,WAAW,EACX,OAAO,EACP,SAAS,EACT,WAAW,EACX,OAAO,EACP,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,KAAK,QAAQ,GACd,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAA;AAEpE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE/G,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,QAAQ,GACd,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,aAAa,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,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AAmB,CAAA;AAE1B,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEtG,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAA;AAE3H,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAEvG,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD,OAAO,EACL,YAAY,EACZ,aAAa,EACb,eAAe,EACf,QAAQ,EACR,WAAW,EACX,aAAa,EACb,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,WAAW,GACjB,MAAM,eAAe,CAAA;AAEtB,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,YAAY,GAClB,MAAM,aAAa,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* apps: it imports no app's data layer, opens no socket, and takes every
|
|
13
13
|
* environment touch — the relay read, the clock, storage — as a parameter.
|
|
14
14
|
*/
|
|
15
|
-
export const CONVERSATION_VERSION = '0.
|
|
15
|
+
export const CONVERSATION_VERSION = '0.33.0';
|
|
16
16
|
export { KIND_MESSAGE, KIND_COMMENT, KIND_EDIT, KIND_REACTION, KIND_DELETION, KIND_ASSERTION, isConversationKind, isEventId, } from './kinds.js';
|
|
17
17
|
export { trustedTs, orderingMs, byOrder } from './order.js';
|
|
18
18
|
export { namedInBody, isReply, anchorsOf, anchorIdsOf, isAbout, isCrossedComment, isCrossedCommentOn, isCommentOn, referencesAddress, strengthOn, threadStrength, referenceTagsFor, mentionTagsFor, peopleNamedInBody, MAX_MENTIONED_PEOPLE, } from './strength.js';
|
|
@@ -37,5 +37,6 @@ export { peopleNamedInText, newlyNamedPeople, mentionAddsFor } from './textMenti
|
|
|
37
37
|
export { KIND_MEMBERSHIP_LIST, namedProfilesOf, rosterOf, byName, mentionablePeople } from './people.js';
|
|
38
38
|
export { messageWords, openingWords, referenceWord } from './openingWords.js';
|
|
39
39
|
export { archivedLine } from './archivedLine.js';
|
|
40
|
+
export { refusalCause, refusalReason, REFUSAL_REASONS, tooLarge, uploadLimit, uploadRefusal, UPLOAD_LIMITS, } from './refusals.js';
|
|
40
41
|
export { createDraftStore, draftKeys, NO_DRAFTS, DRAFT_MAX_AGE_MS, DRAFT_MAX_CHARS, } from './drafts.js';
|
|
41
42
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,QAAQ,CAAA;AAE5C,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,aAAa,EACb,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,SAAS,GACV,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3D,OAAO,EACL,WAAW,EACX,OAAO,EACP,SAAS,EACT,WAAW,EACX,OAAO,EACP,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,oBAAoB,GAErB,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAiB,MAAM,cAAc,CAAA;AAEpE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAiB,MAAM,YAAY,CAAA;AAE/G,OAAO,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3
|
+
* reaction or a file is refused (ONE-4).
|
|
4
|
+
*
|
|
5
|
+
* A refusal comes from the relay (`invalid: …`, `restricted: …`, an HTTP body),
|
|
6
|
+
* from Estiva ID, from the builders' own checks (`content is N bytes, max M`),
|
|
7
|
+
* from the network, or from the app itself. Whatever it was, a person reads
|
|
8
|
+
* one plain reason for its cause, the same in Peek, Ship and Leaf, and never
|
|
9
|
+
* the relay's words: those go to the console. The comment box and the cards
|
|
10
|
+
* put the reason in their sentence ("Not sent: <reason>. Your text is back in
|
|
11
|
+
* the box."), so a reason is lower case and ends with no full stop.
|
|
12
|
+
*
|
|
13
|
+
* An app with a cause of its own hands `{ cause }` rather than a sentence, so
|
|
14
|
+
* its words are these too. A file's own words (`uploadRefusal`) are a whole
|
|
15
|
+
* line on its card, and `tooLarge` stops a file over the relay's limit before
|
|
16
|
+
* it uploads (Miky, 4 Nov: the server's limits, checked in every app first).
|
|
17
|
+
*/
|
|
18
|
+
/** Why something was refused, as far as a person needs to know. */
|
|
19
|
+
export type RefusalCause = 'too-long' | 'gone' | 'no-access' | 'archived' | 'busy' | 'clock' | 'signed-out' | 'unknown';
|
|
20
|
+
/**
|
|
21
|
+
* Each cause's reason, put in a sentence by the box or the card. `gone` is
|
|
22
|
+
* what the relay says for an edit or a reaction on a message that was deleted
|
|
23
|
+
* or that you can no longer write beside: it does not say which.
|
|
24
|
+
*/
|
|
25
|
+
export declare const REFUSAL_REASONS: Readonly<Record<RefusalCause, string>>;
|
|
26
|
+
/** What a refusal comes to; `{ cause }` is taken as it is. */
|
|
27
|
+
export declare function refusalCause(reason: unknown): RefusalCause;
|
|
28
|
+
/** The plain reason for any refusal, to say after "Not sent:", "Not saved:" or "Not reacted:". */
|
|
29
|
+
export declare function refusalReason(reason: unknown): string;
|
|
30
|
+
/** Why a file did not upload, as far as a person needs to know. */
|
|
31
|
+
export type UploadCause = 'too-large' | 'type' | 'unreadable' | 'busy' | 'signed-out' | 'no-access' | 'unknown';
|
|
32
|
+
/**
|
|
33
|
+
* The relay's size limits (buzz `BUZZ_MAX_*_BYTES`, read back on production on
|
|
34
|
+
* 4 Nov): a GIF 10 MB, another picture 50 MB, anything else 100 MB, since
|
|
35
|
+
* Cloudflare refuses a larger body before the relay sees it (a video's 500 MB
|
|
36
|
+
* is never reached). Cloudflare's 100 MB is taken as decimal, the lower
|
|
37
|
+
* reading, so nothing that passes here is turned away there.
|
|
38
|
+
*/
|
|
39
|
+
export declare const UPLOAD_LIMITS: {
|
|
40
|
+
readonly gif: number;
|
|
41
|
+
readonly image: number;
|
|
42
|
+
readonly other: 100000000;
|
|
43
|
+
};
|
|
44
|
+
/** The most a file of this type may be, in bytes. */
|
|
45
|
+
export declare function uploadLimit(type: string | undefined): number;
|
|
46
|
+
/** The line for a file over its limit, said before it uploads; undefined when it fits. */
|
|
47
|
+
export declare function tooLarge(file: {
|
|
48
|
+
size: number;
|
|
49
|
+
type?: string;
|
|
50
|
+
}): string | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* The line on a file's card when its upload was refused: from protocol's
|
|
53
|
+
* `upload failed: <status> <body>`, any other error, or `{ cause }`. A 413
|
|
54
|
+
* names the limit the relay gave, or the type's own when Cloudflare answered.
|
|
55
|
+
*/
|
|
56
|
+
export declare function uploadRefusal(reason: unknown, file?: {
|
|
57
|
+
type?: string;
|
|
58
|
+
}): string;
|
|
59
|
+
//# sourceMappingURL=refusals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refusals.d.ts","sourceRoot":"","sources":["../src/refusals.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,mEAAmE;AACnE,MAAM,MAAM,YAAY,GACpB,UAAU,GACV,MAAM,GACN,WAAW,GACX,UAAU,GACV,MAAM,GACN,OAAO,GACP,YAAY,GACZ,SAAS,CAAA;AAEb;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CASlE,CAAA;AAmDD,8DAA8D;AAC9D,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY,CAQ1D;AAED,kGAAkG;AAClG,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAErD;AAED,mEAAmE;AACnE,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,MAAM,GAAG,YAAY,GAAG,MAAM,GAAG,YAAY,GAAG,WAAW,GAAG,SAAS,CAAA;AAI/G;;;;;;GAMG;AACH,eAAO,MAAM,aAAa;;;;CAAgE,CAAA;AAE1F,qDAAqD;AACrD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAK5D;AAKD,0FAA0F;AAC1F,wBAAgB,QAAQ,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,GAAG,SAAS,CAGlF;AAWD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAoB/E"}
|
package/dist/refusals.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* refusals, the one set of words every app says when a send, an edit, a
|
|
3
|
+
* reaction or a file is refused (ONE-4).
|
|
4
|
+
*
|
|
5
|
+
* A refusal comes from the relay (`invalid: …`, `restricted: …`, an HTTP body),
|
|
6
|
+
* from Estiva ID, from the builders' own checks (`content is N bytes, max M`),
|
|
7
|
+
* from the network, or from the app itself. Whatever it was, a person reads
|
|
8
|
+
* one plain reason for its cause, the same in Peek, Ship and Leaf, and never
|
|
9
|
+
* the relay's words: those go to the console. The comment box and the cards
|
|
10
|
+
* put the reason in their sentence ("Not sent: <reason>. Your text is back in
|
|
11
|
+
* the box."), so a reason is lower case and ends with no full stop.
|
|
12
|
+
*
|
|
13
|
+
* An app with a cause of its own hands `{ cause }` rather than a sentence, so
|
|
14
|
+
* its words are these too. A file's own words (`uploadRefusal`) are a whole
|
|
15
|
+
* line on its card, and `tooLarge` stops a file over the relay's limit before
|
|
16
|
+
* it uploads (Miky, 4 Nov: the server's limits, checked in every app first).
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Each cause's reason, put in a sentence by the box or the card. `gone` is
|
|
20
|
+
* what the relay says for an edit or a reaction on a message that was deleted
|
|
21
|
+
* or that you can no longer write beside: it does not say which.
|
|
22
|
+
*/
|
|
23
|
+
export const REFUSAL_REASONS = {
|
|
24
|
+
'too-long': 'it is too long',
|
|
25
|
+
gone: 'this message was deleted, or you can no longer write here',
|
|
26
|
+
'no-access': 'you can no longer write here',
|
|
27
|
+
archived: 'this team is archived',
|
|
28
|
+
busy: 'too many at once, try again in a moment',
|
|
29
|
+
clock: 'your computer’s clock is wrong; set it and try again',
|
|
30
|
+
'signed-out': 'you are signed out; sign in again',
|
|
31
|
+
unknown: 'something went wrong, try again',
|
|
32
|
+
};
|
|
33
|
+
/** The text a refusal carries: a string, an `Error`'s message, or `{ error }` / `{ message }` / `{ reason }`, one JSON body deep. */
|
|
34
|
+
function textOf(reason) {
|
|
35
|
+
if (reason == null)
|
|
36
|
+
return '';
|
|
37
|
+
if (typeof reason === 'string') {
|
|
38
|
+
const json = reason.trim();
|
|
39
|
+
if (json.startsWith('{')) {
|
|
40
|
+
try {
|
|
41
|
+
return textOf(JSON.parse(json)) || reason;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return reason;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return reason;
|
|
48
|
+
}
|
|
49
|
+
if (reason instanceof Error)
|
|
50
|
+
return textOf(reason.message);
|
|
51
|
+
if (typeof reason === 'object') {
|
|
52
|
+
const r = reason;
|
|
53
|
+
for (const key of ['error', 'message', 'reason']) {
|
|
54
|
+
const value = r[key];
|
|
55
|
+
if (typeof value === 'string')
|
|
56
|
+
return textOf(value);
|
|
57
|
+
if (value && typeof value === 'object')
|
|
58
|
+
return textOf(value);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return String(reason);
|
|
62
|
+
}
|
|
63
|
+
const CAUSES = new Set(Object.keys(REFUSAL_REASONS));
|
|
64
|
+
/*
|
|
65
|
+
In order: the first that matches is the cause. Scope and identity before
|
|
66
|
+
`restricted:`, which also prefixes "insufficient scope". Each reason above
|
|
67
|
+
maps back to its own cause, so a reason passed on twice stays the same.
|
|
68
|
+
|
|
69
|
+
Words, because the relay sends no reason code yet (SPEC: "until then a
|
|
70
|
+
refusal is its sentence alone"). When the TEA issue "When the server says
|
|
71
|
+
no, every app knows why" adds them, `refusalCause` reads the code first and
|
|
72
|
+
these rules stay only for a refusal that carries none.
|
|
73
|
+
why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-refusal-starts-with-a-reason-code-every-app-reads.md
|
|
74
|
+
*/
|
|
75
|
+
const RULES = [
|
|
76
|
+
[/content (is \d+ bytes, max|exceeds maximum size)|too long/i, 'too-long'],
|
|
77
|
+
[/rate-limited|quota|too many|too busy|relay is busy|admission|\b429\b|concurrency/i, 'busy'],
|
|
78
|
+
[/timestamp too far|clock/i, 'clock'],
|
|
79
|
+
[/auth-required|insufficient scope|does not match authenticated|signed out|sign in|\b401\b|token_rejected|session_expired/i, 'signed-out'],
|
|
80
|
+
[/archived/i, 'archived'],
|
|
81
|
+
[/target (event )?not found|not (editable|deletable) by you|was deleted|no longer on this page/i, 'gone'],
|
|
82
|
+
[/^(restricted|blocked):|not a (channel |relay )?member|only members|no longer (post|write)|banned|timed out until|writes are fenced|\b403\b/i, 'no-access'],
|
|
83
|
+
];
|
|
84
|
+
/** What a refusal comes to; `{ cause }` is taken as it is. */
|
|
85
|
+
export function refusalCause(reason) {
|
|
86
|
+
if (reason && typeof reason === 'object' && 'cause' in reason) {
|
|
87
|
+
const cause = reason.cause;
|
|
88
|
+
if (typeof cause === 'string' && CAUSES.has(cause))
|
|
89
|
+
return cause;
|
|
90
|
+
}
|
|
91
|
+
const text = textOf(reason);
|
|
92
|
+
for (const [rule, cause] of RULES)
|
|
93
|
+
if (rule.test(text))
|
|
94
|
+
return cause;
|
|
95
|
+
return 'unknown';
|
|
96
|
+
}
|
|
97
|
+
/** The plain reason for any refusal, to say after "Not sent:", "Not saved:" or "Not reacted:". */
|
|
98
|
+
export function refusalReason(reason) {
|
|
99
|
+
return REFUSAL_REASONS[refusalCause(reason)];
|
|
100
|
+
}
|
|
101
|
+
const MB = 1024 * 1024;
|
|
102
|
+
/**
|
|
103
|
+
* The relay's size limits (buzz `BUZZ_MAX_*_BYTES`, read back on production on
|
|
104
|
+
* 4 Nov): a GIF 10 MB, another picture 50 MB, anything else 100 MB, since
|
|
105
|
+
* Cloudflare refuses a larger body before the relay sees it (a video's 500 MB
|
|
106
|
+
* is never reached). Cloudflare's 100 MB is taken as decimal, the lower
|
|
107
|
+
* reading, so nothing that passes here is turned away there.
|
|
108
|
+
*/
|
|
109
|
+
export const UPLOAD_LIMITS = { gif: 10 * MB, image: 50 * MB, other: 100_000_000 };
|
|
110
|
+
/** The most a file of this type may be, in bytes. */
|
|
111
|
+
export function uploadLimit(type) {
|
|
112
|
+
const t = (type ?? '').toLowerCase();
|
|
113
|
+
if (t === 'image/gif')
|
|
114
|
+
return UPLOAD_LIMITS.gif;
|
|
115
|
+
if (t.startsWith('image/'))
|
|
116
|
+
return UPLOAD_LIMITS.image;
|
|
117
|
+
return UPLOAD_LIMITS.other;
|
|
118
|
+
}
|
|
119
|
+
// Whole MB either way: 10,485,760 bytes and 100,000,000 bytes both say what the limit is called.
|
|
120
|
+
const tooLargeLine = (bytes) => `Too large: the most is ${bytes % MB === 0 ? bytes / MB : Math.round(bytes / 1e6)} MB`;
|
|
121
|
+
/** The line for a file over its limit, said before it uploads; undefined when it fits. */
|
|
122
|
+
export function tooLarge(file) {
|
|
123
|
+
const limit = uploadLimit(file.type);
|
|
124
|
+
return file.size > limit ? tooLargeLine(limit) : undefined;
|
|
125
|
+
}
|
|
126
|
+
const UPLOAD_LINES = {
|
|
127
|
+
type: 'This type of file can’t be added',
|
|
128
|
+
unreadable: 'This file could not be read',
|
|
129
|
+
busy: 'Too many at once, try again in a moment',
|
|
130
|
+
'signed-out': 'Sign in again',
|
|
131
|
+
'no-access': 'You can no longer add files here',
|
|
132
|
+
unknown: 'Could not upload, try again',
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* The line on a file's card when its upload was refused: from protocol's
|
|
136
|
+
* `upload failed: <status> <body>`, any other error, or `{ cause }`. A 413
|
|
137
|
+
* names the limit the relay gave, or the type's own when Cloudflare answered.
|
|
138
|
+
*/
|
|
139
|
+
export function uploadRefusal(reason, file) {
|
|
140
|
+
if (reason && typeof reason === 'object' && 'cause' in reason) {
|
|
141
|
+
const cause = reason.cause;
|
|
142
|
+
if (cause === 'too-large')
|
|
143
|
+
return tooLargeLine(uploadLimit(file?.type));
|
|
144
|
+
if (typeof cause === 'string' && Object.hasOwn(UPLOAD_LINES, cause))
|
|
145
|
+
return UPLOAD_LINES[cause];
|
|
146
|
+
}
|
|
147
|
+
const raw = reason instanceof Error ? reason.message : typeof reason === 'string' ? reason : textOf(reason);
|
|
148
|
+
const status = Number(/upload failed:\s*(\d{3})/i.exec(raw)?.[1] ?? 0);
|
|
149
|
+
const said = textOf(raw.replace(/^.*?upload failed:\s*\d{3}\s*/is, ''));
|
|
150
|
+
if (status === 413 || /file too large/i.test(said)) {
|
|
151
|
+
const max = Number(/max (\d+)\)?/i.exec(said)?.[1] ?? 0);
|
|
152
|
+
if (/dimensions/i.test(said))
|
|
153
|
+
return UPLOAD_LINES.unreadable;
|
|
154
|
+
return tooLargeLine(max || uploadLimit(file?.type));
|
|
155
|
+
}
|
|
156
|
+
if (status === 415 || /content type|unsupported container/i.test(said))
|
|
157
|
+
return UPLOAD_LINES.type;
|
|
158
|
+
if (status === 422 || /metadata|invalid image|duration|resolution/i.test(said))
|
|
159
|
+
return UPLOAD_LINES.unreadable;
|
|
160
|
+
if (status === 429 || /rate limit|concurrency/i.test(said))
|
|
161
|
+
return UPLOAD_LINES.busy;
|
|
162
|
+
if (status === 401 || /authentication failed|signed out/i.test(said))
|
|
163
|
+
return UPLOAD_LINES['signed-out'];
|
|
164
|
+
if (status === 403)
|
|
165
|
+
return UPLOAD_LINES['no-access'];
|
|
166
|
+
return UPLOAD_LINES.unknown;
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=refusals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refusals.js","sourceRoot":"","sources":["../src/refusals.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAaH;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAA2C;IACrE,UAAU,EAAE,gBAAgB;IAC5B,IAAI,EAAE,2DAA2D;IACjE,WAAW,EAAE,8BAA8B;IAC3C,QAAQ,EAAE,uBAAuB;IACjC,IAAI,EAAE,yCAAyC;IAC/C,KAAK,EAAE,sDAAsD;IAC7D,YAAY,EAAE,mCAAmC;IACjD,OAAO,EAAE,iCAAiC;CAC3C,CAAA;AAED,qIAAqI;AACrI,SAAS,MAAM,CAAC,MAAe;IAC7B,IAAI,MAAM,IAAI,IAAI;QAAE,OAAO,EAAE,CAAA;IAC7B,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,EAAE,CAAA;QAC1B,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACzB,IAAI,CAAC;gBACH,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,MAAM,CAAA;YAC3C,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,MAAM,CAAA;YACf,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;IACD,IAAI,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AA;IACvE,IAAI,MAAM,KAAK,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACnD,MAAM,GAAG,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;QACxD,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,OAAO,YAAY,CAAC,UAAU,CAAA;QAC5D,OAAO,YAAY,CAAC,GAAG,IAAI,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;IACrD,CAAC;IACD,IAAI,MAAM,KAAK,GAAG,IAAI,qCAAqC,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,YAAY,CAAC,IAAI,CAAA;IAChG,IAAI,MAAM,KAAK,GAAG,IAAI,6CAA6C,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,YAAY,CAAC,UAAU,CAAA;IAC9G,IAAI,MAAM,KAAK,GAAG,IAAI,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,YAAY,CAAC,IAAI,CAAA;IACpF,IAAI,MAAM,KAAK,GAAG,IAAI,mCAAmC,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,YAAY,CAAC,YAAY,CAAC,CAAA;IACvG,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,YAAY,CAAC,WAAW,CAAC,CAAA;IACpD,OAAO,YAAY,CAAC,OAAO,CAAA;AAC7B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estiva-app/conversation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.0",
|
|
4
4
|
"description": "The conversation rules of the Estiva SPEC (§6.2–§6.8, §11): comment and mention strengths, threading, one shape for a message and a thread, resolving a thread, the line rule, the edit, reaction and attachment folds, NIP-22 comment and reply builders, drafts, NIP-RS read state, membership and unread. A convenience an app adopts, never a requirement.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/src/index.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* apps: it imports no app's data layer, opens no socket, and takes every
|
|
13
13
|
* environment touch — the relay read, the clock, storage — as a parameter.
|
|
14
14
|
*/
|
|
15
|
-
export const CONVERSATION_VERSION = '0.
|
|
15
|
+
export const CONVERSATION_VERSION = '0.33.0'
|
|
16
16
|
|
|
17
17
|
export {
|
|
18
18
|
KIND_MESSAGE,
|
|
@@ -255,6 +255,18 @@ export { messageWords, openingWords, referenceWord, type OpeningWordsOptions } f
|
|
|
255
255
|
|
|
256
256
|
export { archivedLine } from './archivedLine.js'
|
|
257
257
|
|
|
258
|
+
export {
|
|
259
|
+
refusalCause,
|
|
260
|
+
refusalReason,
|
|
261
|
+
REFUSAL_REASONS,
|
|
262
|
+
tooLarge,
|
|
263
|
+
uploadLimit,
|
|
264
|
+
uploadRefusal,
|
|
265
|
+
UPLOAD_LIMITS,
|
|
266
|
+
type RefusalCause,
|
|
267
|
+
type UploadCause,
|
|
268
|
+
} from './refusals.js'
|
|
269
|
+
|
|
258
270
|
export {
|
|
259
271
|
createDraftStore,
|
|
260
272
|
draftKeys,
|
package/src/refusals.ts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* refusals, the one set of words every app says when a send, an edit, a
|
|
3
|
+
* reaction or a file is refused (ONE-4).
|
|
4
|
+
*
|
|
5
|
+
* A refusal comes from the relay (`invalid: …`, `restricted: …`, an HTTP body),
|
|
6
|
+
* from Estiva ID, from the builders' own checks (`content is N bytes, max M`),
|
|
7
|
+
* from the network, or from the app itself. Whatever it was, a person reads
|
|
8
|
+
* one plain reason for its cause, the same in Peek, Ship and Leaf, and never
|
|
9
|
+
* the relay's words: those go to the console. The comment box and the cards
|
|
10
|
+
* put the reason in their sentence ("Not sent: <reason>. Your text is back in
|
|
11
|
+
* the box."), so a reason is lower case and ends with no full stop.
|
|
12
|
+
*
|
|
13
|
+
* An app with a cause of its own hands `{ cause }` rather than a sentence, so
|
|
14
|
+
* its words are these too. A file's own words (`uploadRefusal`) are a whole
|
|
15
|
+
* line on its card, and `tooLarge` stops a file over the relay's limit before
|
|
16
|
+
* it uploads (Miky, 4 Nov: the server's limits, checked in every app first).
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/** Why something was refused, as far as a person needs to know. */
|
|
20
|
+
export type RefusalCause =
|
|
21
|
+
| 'too-long'
|
|
22
|
+
| 'gone'
|
|
23
|
+
| 'no-access'
|
|
24
|
+
| 'archived'
|
|
25
|
+
| 'busy'
|
|
26
|
+
| 'clock'
|
|
27
|
+
| 'signed-out'
|
|
28
|
+
| 'unknown'
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Each cause's reason, put in a sentence by the box or the card. `gone` is
|
|
32
|
+
* what the relay says for an edit or a reaction on a message that was deleted
|
|
33
|
+
* or that you can no longer write beside: it does not say which.
|
|
34
|
+
*/
|
|
35
|
+
export const REFUSAL_REASONS: Readonly<Record<RefusalCause, string>> = {
|
|
36
|
+
'too-long': 'it is too long',
|
|
37
|
+
gone: 'this message was deleted, or you can no longer write here',
|
|
38
|
+
'no-access': 'you can no longer write here',
|
|
39
|
+
archived: 'this team is archived',
|
|
40
|
+
busy: 'too many at once, try again in a moment',
|
|
41
|
+
clock: 'your computer’s clock is wrong; set it and try again',
|
|
42
|
+
'signed-out': 'you are signed out; sign in again',
|
|
43
|
+
unknown: 'something went wrong, try again',
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The text a refusal carries: a string, an `Error`'s message, or `{ error }` / `{ message }` / `{ reason }`, one JSON body deep. */
|
|
47
|
+
function textOf(reason: unknown): string {
|
|
48
|
+
if (reason == null) return ''
|
|
49
|
+
if (typeof reason === 'string') {
|
|
50
|
+
const json = reason.trim()
|
|
51
|
+
if (json.startsWith('{')) {
|
|
52
|
+
try {
|
|
53
|
+
return textOf(JSON.parse(json)) || reason
|
|
54
|
+
} catch {
|
|
55
|
+
return reason
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return reason
|
|
59
|
+
}
|
|
60
|
+
if (reason instanceof Error) return textOf(reason.message)
|
|
61
|
+
if (typeof reason === 'object') {
|
|
62
|
+
const r = reason as Record<string, unknown>
|
|
63
|
+
for (const key of ['error', 'message', 'reason']) {
|
|
64
|
+
const value = r[key]
|
|
65
|
+
if (typeof value === 'string') return textOf(value)
|
|
66
|
+
if (value && typeof value === 'object') return textOf(value)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return String(reason)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const CAUSES = new Set<string>(Object.keys(REFUSAL_REASONS))
|
|
73
|
+
|
|
74
|
+
/*
|
|
75
|
+
In order: the first that matches is the cause. Scope and identity before
|
|
76
|
+
`restricted:`, which also prefixes "insufficient scope". Each reason above
|
|
77
|
+
maps back to its own cause, so a reason passed on twice stays the same.
|
|
78
|
+
|
|
79
|
+
Words, because the relay sends no reason code yet (SPEC: "until then a
|
|
80
|
+
refusal is its sentence alone"). When the TEA issue "When the server says
|
|
81
|
+
no, every app knows why" adds them, `refusalCause` reads the code first and
|
|
82
|
+
these rules stay only for a refusal that carries none.
|
|
83
|
+
why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-refusal-starts-with-a-reason-code-every-app-reads.md
|
|
84
|
+
*/
|
|
85
|
+
const RULES: readonly [RegExp, RefusalCause][] = [
|
|
86
|
+
[/content (is \d+ bytes, max|exceeds maximum size)|too long/i, 'too-long'],
|
|
87
|
+
[/rate-limited|quota|too many|too busy|relay is busy|admission|\b429\b|concurrency/i, 'busy'],
|
|
88
|
+
[/timestamp too far|clock/i, 'clock'],
|
|
89
|
+
[/auth-required|insufficient scope|does not match authenticated|signed out|sign in|\b401\b|token_rejected|session_expired/i, 'signed-out'],
|
|
90
|
+
[/archived/i, 'archived'],
|
|
91
|
+
[/target (event )?not found|not (editable|deletable) by you|was deleted|no longer on this page/i, 'gone'],
|
|
92
|
+
[/^(restricted|blocked):|not a (channel |relay )?member|only members|no longer (post|write)|banned|timed out until|writes are fenced|\b403\b/i, 'no-access'],
|
|
93
|
+
]
|
|
94
|
+
|
|
95
|
+
/** What a refusal comes to; `{ cause }` is taken as it is. */
|
|
96
|
+
export function refusalCause(reason: unknown): RefusalCause {
|
|
97
|
+
if (reason && typeof reason === 'object' && 'cause' in reason) {
|
|
98
|
+
const cause = (reason as { cause: unknown }).cause
|
|
99
|
+
if (typeof cause === 'string' && CAUSES.has(cause)) return cause as RefusalCause
|
|
100
|
+
}
|
|
101
|
+
const text = textOf(reason)
|
|
102
|
+
for (const [rule, cause] of RULES) if (rule.test(text)) return cause
|
|
103
|
+
return 'unknown'
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** The plain reason for any refusal, to say after "Not sent:", "Not saved:" or "Not reacted:". */
|
|
107
|
+
export function refusalReason(reason: unknown): string {
|
|
108
|
+
return REFUSAL_REASONS[refusalCause(reason)]
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Why a file did not upload, as far as a person needs to know. */
|
|
112
|
+
export type UploadCause = 'too-large' | 'type' | 'unreadable' | 'busy' | 'signed-out' | 'no-access' | 'unknown'
|
|
113
|
+
|
|
114
|
+
const MB = 1024 * 1024
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The relay's size limits (buzz `BUZZ_MAX_*_BYTES`, read back on production on
|
|
118
|
+
* 4 Nov): a GIF 10 MB, another picture 50 MB, anything else 100 MB, since
|
|
119
|
+
* Cloudflare refuses a larger body before the relay sees it (a video's 500 MB
|
|
120
|
+
* is never reached). Cloudflare's 100 MB is taken as decimal, the lower
|
|
121
|
+
* reading, so nothing that passes here is turned away there.
|
|
122
|
+
*/
|
|
123
|
+
export const UPLOAD_LIMITS = { gif: 10 * MB, image: 50 * MB, other: 100_000_000 } as const
|
|
124
|
+
|
|
125
|
+
/** The most a file of this type may be, in bytes. */
|
|
126
|
+
export function uploadLimit(type: string | undefined): number {
|
|
127
|
+
const t = (type ?? '').toLowerCase()
|
|
128
|
+
if (t === 'image/gif') return UPLOAD_LIMITS.gif
|
|
129
|
+
if (t.startsWith('image/')) return UPLOAD_LIMITS.image
|
|
130
|
+
return UPLOAD_LIMITS.other
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Whole MB either way: 10,485,760 bytes and 100,000,000 bytes both say what the limit is called.
|
|
134
|
+
const tooLargeLine = (bytes: number) => `Too large: the most is ${bytes % MB === 0 ? bytes / MB : Math.round(bytes / 1e6)} MB`
|
|
135
|
+
|
|
136
|
+
/** The line for a file over its limit, said before it uploads; undefined when it fits. */
|
|
137
|
+
export function tooLarge(file: { size: number; type?: string }): string | undefined {
|
|
138
|
+
const limit = uploadLimit(file.type)
|
|
139
|
+
return file.size > limit ? tooLargeLine(limit) : undefined
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const UPLOAD_LINES: Readonly<Record<Exclude<UploadCause, 'too-large'>, string>> = {
|
|
143
|
+
type: 'This type of file can’t be added',
|
|
144
|
+
unreadable: 'This file could not be read',
|
|
145
|
+
busy: 'Too many at once, try again in a moment',
|
|
146
|
+
'signed-out': 'Sign in again',
|
|
147
|
+
'no-access': 'You can no longer add files here',
|
|
148
|
+
unknown: 'Could not upload, try again',
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* The line on a file's card when its upload was refused: from protocol's
|
|
153
|
+
* `upload failed: <status> <body>`, any other error, or `{ cause }`. A 413
|
|
154
|
+
* names the limit the relay gave, or the type's own when Cloudflare answered.
|
|
155
|
+
*/
|
|
156
|
+
export function uploadRefusal(reason: unknown, file?: { type?: string }): string {
|
|
157
|
+
if (reason && typeof reason === 'object' && 'cause' in reason) {
|
|
158
|
+
const cause = (reason as { cause: unknown }).cause
|
|
159
|
+
if (cause === 'too-large') return tooLargeLine(uploadLimit(file?.type))
|
|
160
|
+
if (typeof cause === 'string' && Object.hasOwn(UPLOAD_LINES, cause)) return UPLOAD_LINES[cause as keyof typeof UPLOAD_LINES]
|
|
161
|
+
}
|
|
162
|
+
const raw = reason instanceof Error ? reason.message : typeof reason === 'string' ? reason : textOf(reason)
|
|
163
|
+
const status = Number(/upload failed:\s*(\d{3})/i.exec(raw)?.[1] ?? 0)
|
|
164
|
+
const said = textOf(raw.replace(/^.*?upload failed:\s*\d{3}\s*/is, ''))
|
|
165
|
+
if (status === 413 || /file too large/i.test(said)) {
|
|
166
|
+
const max = Number(/max (\d+)\)?/i.exec(said)?.[1] ?? 0)
|
|
167
|
+
if (/dimensions/i.test(said)) return UPLOAD_LINES.unreadable
|
|
168
|
+
return tooLargeLine(max || uploadLimit(file?.type))
|
|
169
|
+
}
|
|
170
|
+
if (status === 415 || /content type|unsupported container/i.test(said)) return UPLOAD_LINES.type
|
|
171
|
+
if (status === 422 || /metadata|invalid image|duration|resolution/i.test(said)) return UPLOAD_LINES.unreadable
|
|
172
|
+
if (status === 429 || /rate limit|concurrency/i.test(said)) return UPLOAD_LINES.busy
|
|
173
|
+
if (status === 401 || /authentication failed|signed out/i.test(said)) return UPLOAD_LINES['signed-out']
|
|
174
|
+
if (status === 403) return UPLOAD_LINES['no-access']
|
|
175
|
+
return UPLOAD_LINES.unknown
|
|
176
|
+
}
|