@rexezuge/web 1.2.0 → 1.4.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/dist/AppPage.d.ts +6 -2
- package/dist/AppPage.d.ts.map +1 -1
- package/dist/AppPage.js +1 -7
- package/dist/AppPage.js.map +7 -1
- package/dist/Badge.d.ts +9 -3
- package/dist/Badge.d.ts.map +1 -1
- package/dist/Badge.js +1 -25
- package/dist/Badge.js.map +7 -1
- package/dist/Button.d.ts +6 -2
- package/dist/Button.d.ts.map +1 -1
- package/dist/Button.js +1 -39
- package/dist/Button.js.map +7 -1
- package/dist/Card.d.ts +12 -9
- package/dist/Card.d.ts.map +1 -1
- package/dist/Card.js +1 -42
- package/dist/Card.js.map +7 -1
- package/dist/ContextBar.d.ts +9 -3
- package/dist/ContextBar.d.ts.map +1 -1
- package/dist/ContextBar.js +1 -7
- package/dist/ContextBar.js.map +7 -1
- package/dist/FocusInput.d.ts +1 -2
- package/dist/FocusInput.d.ts.map +1 -1
- package/dist/FocusInput.js +1 -19
- package/dist/FocusInput.js.map +7 -1
- package/dist/Input.d.ts +9 -8
- package/dist/Input.d.ts.map +1 -1
- package/dist/Input.js +1 -49
- package/dist/Input.js.map +7 -1
- package/dist/LanguageSelector.d.ts +6 -2
- package/dist/LanguageSelector.d.ts.map +1 -1
- package/dist/LanguageSelector.js +1 -12
- package/dist/LanguageSelector.js.map +7 -1
- package/dist/LoadingButton.d.ts +19 -7
- package/dist/LoadingButton.d.ts.map +1 -1
- package/dist/LoadingButton.js +1 -30
- package/dist/LoadingButton.js.map +7 -1
- package/dist/ModalShell.d.ts +12 -4
- package/dist/ModalShell.d.ts.map +1 -1
- package/dist/ModalShell.js +1 -22
- package/dist/ModalShell.js.map +7 -1
- package/dist/NoticeBar.d.ts +7 -3
- package/dist/NoticeBar.d.ts.map +1 -1
- package/dist/NoticeBar.js +1 -12
- package/dist/NoticeBar.js.map +7 -1
- package/dist/PageHeaderCard.d.ts +6 -2
- package/dist/PageHeaderCard.d.ts.map +1 -1
- package/dist/PageHeaderCard.js +1 -7
- package/dist/PageHeaderCard.js.map +7 -1
- package/dist/PageState.d.ts +9 -3
- package/dist/PageState.d.ts.map +1 -1
- package/dist/PageState.js +1 -47
- package/dist/PageState.js.map +7 -1
- package/dist/Pagination.d.ts +36 -12
- package/dist/Pagination.d.ts.map +1 -1
- package/dist/Pagination.js +1 -75
- package/dist/Pagination.js.map +7 -1
- package/dist/ReadOnlyField.d.ts +12 -4
- package/dist/ReadOnlyField.d.ts.map +1 -1
- package/dist/ReadOnlyField.js +1 -17
- package/dist/ReadOnlyField.js.map +7 -1
- package/dist/RefreshButton.d.ts +6 -2
- package/dist/RefreshButton.d.ts.map +1 -1
- package/dist/RefreshButton.js +1 -8
- package/dist/RefreshButton.js.map +7 -1
- package/dist/Spinner.d.ts +15 -5
- package/dist/Spinner.d.ts.map +1 -1
- package/dist/Spinner.js +1 -14
- package/dist/Spinner.js.map +7 -1
- package/dist/TypeToConfirmModal.d.ts +15 -5
- package/dist/TypeToConfirmModal.d.ts.map +1 -1
- package/dist/TypeToConfirmModal.js +1 -24
- package/dist/TypeToConfirmModal.js.map +7 -1
- package/dist/Unauthorized.d.ts +6 -2
- package/dist/Unauthorized.d.ts.map +1 -1
- package/dist/Unauthorized.js +1 -11
- package/dist/Unauthorized.js.map +7 -1
- package/dist/api.d.ts +27 -9
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +1 -258
- package/dist/api.js.map +7 -1
- package/dist/constants.js +1 -49
- package/dist/constants.js.map +7 -1
- package/dist/index.d.ts +51 -51
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -89
- package/dist/index.js.map +7 -1
- package/dist/theme.d.ts +24 -8
- package/dist/theme.d.ts.map +1 -1
- package/dist/theme.js +1 -134
- package/dist/theme.js.map +7 -1
- package/dist/useCopyToClipboard.d.ts +3 -1
- package/dist/useCopyToClipboard.d.ts.map +1 -1
- package/dist/useCopyToClipboard.js +1 -40
- package/dist/useCopyToClipboard.js.map +7 -1
- package/dist/useCurrentUser.d.ts +22 -8
- package/dist/useCurrentUser.d.ts.map +1 -1
- package/dist/useCurrentUser.js +1 -49
- package/dist/useCurrentUser.js.map +7 -1
- package/dist/useNotice.d.ts +21 -7
- package/dist/useNotice.d.ts.map +1 -1
- package/dist/useNotice.js +1 -34
- package/dist/useNotice.js.map +7 -1
- package/dist/useSpaLanguage.d.ts +27 -11
- package/dist/useSpaLanguage.d.ts.map +1 -1
- package/dist/useSpaLanguage.js +1 -149
- package/dist/useSpaLanguage.js.map +7 -1
- package/dist/utils.d.ts +6 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -346
- package/dist/utils.js.map +7 -1
- package/package.json +4 -4
package/dist/Unauthorized.js
CHANGED
|
@@ -1,11 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ZERO_TRUST_AUTHENTICATION_PATH } from './constants';
|
|
3
|
-
function Unauthorized({ title, message, actionLabel, onAuthenticate }) {
|
|
4
|
-
const authenticate = onAuthenticate ??
|
|
5
|
-
(() => {
|
|
6
|
-
globalThis.location.assign(ZERO_TRUST_AUTHENTICATION_PATH);
|
|
7
|
-
});
|
|
8
|
-
return (_jsx("div", { className: "bg-[var(--color-surface-base)] text-[var(--color-text-primary)] flex items-center justify-center py-16", children: _jsxs("div", { className: "text-center px-6", children: [_jsx("h1", { className: "text-lg font-medium mt-4 mb-1", children: title }), message && _jsx("p", { className: "text-[var(--color-text-secondary)] text-sm", children: message }), _jsx("button", { type: "button", onClick: authenticate, className: "mt-6 inline-flex items-center justify-center rounded-xl bg-[var(--color-accent)] px-5 py-2.5 text-sm font-medium text-[#0d1008] transition-colors hover:bg-[var(--color-accent-dim)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--color-accent)]", children: actionLabel })] }) }));
|
|
9
|
-
}
|
|
10
|
-
export { Unauthorized };
|
|
11
|
-
//# sourceMappingURL=Unauthorized.js.map
|
|
1
|
+
import{jsx as e,jsxs as r}from"react/jsx-runtime";import{ZERO_TRUST_AUTHENTICATION_PATH as n}from"./constants.js";function l({title:o,message:t,actionLabel:c,onAuthenticate:i}){const s=i??(()=>{location.assign(n)});return e("div",{className:"bg-[var(--color-surface-base)] text-[var(--color-text-primary)] flex items-center justify-center py-16",children:r("div",{className:"text-center px-6",children:[e("h1",{className:"text-lg font-medium mt-4 mb-1",children:o}),t&&e("p",{className:"text-[var(--color-text-secondary)] text-sm",children:t}),e("button",{type:"button",onClick:s,className:"mt-6 inline-flex items-center justify-center rounded-xl bg-[var(--color-accent)] px-5 py-2.5 text-sm font-medium text-[#0d1008] transition-colors hover:bg-[var(--color-accent-dim)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--color-accent)]",children:c})]})})}export{l as Unauthorized};
|
package/dist/Unauthorized.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/Unauthorized.tsx"],
|
|
4
|
+
"sourcesContent": ["import { ZERO_TRUST_AUTHENTICATION_PATH } from './constants.ts';\n\n/**\n * The \"you are not signed in\" page.\n *\n * ## Provenance\n *\n * `components/layout/Unauthorized.tsx` in **Durable-DAV**, **Durable-DAV-Router**,\n * **Edge-Git**, **Mail-Otter** and **Edge-Sonic** — five copies, byte-identical\n * apart from the doc comment — plus `Unauthorized.tsx` at the components root\n * in **AWS-AccessBridge** and **CalDAV-Bridge**.\n *\n * ## Why `onAuthenticate` is an argument and not a fixed `location.assign`\n *\n * All seven copies hard-coded `globalThis.location.assign(ZERO_TRUST_AUTHENTICATION_PATH)`.\n * That is untestable — jsdom refuses to navigate, so the one branch that\n * matters (what happens when the operator actually clicks the button) had no\n * assertions at all — and it hard-codes a routing assumption into a component\n * that a repo may not share.\n *\n * The default keeps the original behaviour for a repo that wants it, and a\n * caller with a different sign-in route passes its own.\n */\n\ninterface UnauthorizedProps {\n /**\n The heading. Required: this is the page's only `h1`.\n */\n title: string;\n /**\n * Why they are being stopped.\n *\n * Optional, and `null`/omitted renders no paragraph rather than an empty one.\n * A blank line under the heading reads as a rendering bug.\n */\n message?: string;\n /**\n The sign-in button's label. Required.\n */\n actionLabel: string;\n /**\n * What the button does.\n *\n * Defaults to navigating to {@link ZERO_TRUST_AUTHENTICATION_PATH}, which is\n * what every copy in the family did.\n */\n onAuthenticate?: () => void;\n}\n\nfunction Unauthorized({ title, message, actionLabel, onAuthenticate }: Readonly<UnauthorizedProps>) {\n const authenticate =\n onAuthenticate ??\n ((): void => {\n location.assign(ZERO_TRUST_AUTHENTICATION_PATH);\n });\n\n return (\n <div className=\"bg-[var(--color-surface-base)] text-[var(--color-text-primary)] flex items-center justify-center py-16\">\n <div className=\"text-center px-6\">\n <h1 className=\"text-lg font-medium mt-4 mb-1\">{title}</h1>\n {message && <p className=\"text-[var(--color-text-secondary)] text-sm\">{message}</p>}\n <button\n type=\"button\"\n onClick={authenticate}\n className=\"mt-6 inline-flex items-center justify-center rounded-xl bg-[var(--color-accent)] px-5 py-2.5 text-sm font-medium text-[#0d1008] transition-colors hover:bg-[var(--color-accent-dim)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--color-accent)]\"\n >\n {actionLabel}\n </button>\n </div>\n </div>\n );\n}\n\nexport { Unauthorized };\nexport type { UnauthorizedProps };\n"],
|
|
5
|
+
"mappings": "kDAAA,OAAS,kCAAAA,MAAsC,iBAiD/C,SAASC,EAAa,CAAE,MAAAC,EAAO,QAAAC,EAAS,YAAAC,EAAa,eAAAC,CAAc,EAA+B,CAChG,MAAMC,EACJD,IACC,IAAW,CACV,SAAS,OAAOL,CAA8B,CAChD,GAEF,OACEO,EAAA,MAAA,CAAK,UAAU,yGAAwG,SACrHC,EAAA,MAAA,CAAK,UAAU,mBAAkB,SAAA,CAC/BD,EAAA,KAAA,CAAI,UAAU,gCAA+B,SAAEL,CAAK,CAAA,EACnDC,GAAWI,EAAA,IAAA,CAAG,UAAU,6CAA4C,SAAEJ,CAAO,CAAA,EAC9EI,EAAA,SAAA,CACE,KAAK,SACL,QAASD,EACT,UAAU,gTAA+S,SAExTF,CAAW,CAAA,CACL,CAAA,CAAA,CACL,CAAA,CAGZ",
|
|
6
|
+
"names": ["ZERO_TRUST_AUTHENTICATION_PATH", "Unauthorized", "title", "message", "actionLabel", "onAuthenticate", "authenticate", "_jsx", "_jsxs"]
|
|
7
|
+
}
|
package/dist/api.d.ts
CHANGED
|
@@ -60,30 +60,46 @@ import { ServiceError } from '@rexezuge/errors';
|
|
|
60
60
|
* paths. `baseUrl` is an option here, defaulting to empty, so the caller
|
|
61
61
|
* decides.
|
|
62
62
|
*/
|
|
63
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
The `fetch` shape a client is built on: same-origin by default, no token in JavaScript.
|
|
65
|
+
*/
|
|
64
66
|
type FetchFn = (input: string, init?: RequestInit) => Promise<Response>;
|
|
65
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
A query-string value. `null`/`undefined`/`''` are omitted, as in every copy.
|
|
69
|
+
*/
|
|
66
70
|
type QueryValue = string | number | boolean | null | undefined;
|
|
67
71
|
type QueryParams = Record<string, QueryValue | readonly QueryValue[]>;
|
|
68
72
|
interface ApiRequestInit {
|
|
69
73
|
method?: string;
|
|
70
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
Serialized as JSON with a matching `Content-Type`.
|
|
76
|
+
*/
|
|
71
77
|
body?: unknown;
|
|
72
78
|
headers?: HeadersInit;
|
|
73
79
|
signal?: AbortSignal | null;
|
|
74
80
|
}
|
|
75
81
|
interface CreateApiClientOptions {
|
|
76
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
Prepended to every path; `''` (the default) sends the path as given.
|
|
84
|
+
*/
|
|
77
85
|
baseUrl?: string;
|
|
78
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
Headers merged into every request; a per-request header wins over these.
|
|
88
|
+
*/
|
|
79
89
|
headers?: HeadersInit;
|
|
80
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
Passed through to `fetch`; omitted leaves the browser default.
|
|
92
|
+
*/
|
|
81
93
|
credentials?: RequestCredentials;
|
|
82
|
-
/**
|
|
94
|
+
/**
|
|
95
|
+
Truncation limit for a server-provided error message. Defaults to 500.
|
|
96
|
+
*/
|
|
83
97
|
maxErrorMessageLength?: number;
|
|
84
98
|
}
|
|
85
99
|
interface ApiClient {
|
|
86
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
One request. Throws a `ServiceError`; resolves to the parsed JSON body.
|
|
102
|
+
*/
|
|
87
103
|
request<T>(path: string, init?: ApiRequestInit): Promise<T>;
|
|
88
104
|
get<T>(path: string, params?: QueryParams): Promise<T>;
|
|
89
105
|
post<T>(path: string, body?: unknown): Promise<T>;
|
|
@@ -91,7 +107,9 @@ interface ApiClient {
|
|
|
91
107
|
patch<T>(path: string, body?: unknown): Promise<T>;
|
|
92
108
|
delete<T>(path: string, body?: unknown): Promise<T>;
|
|
93
109
|
}
|
|
94
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
Default truncation for a server-provided message.
|
|
112
|
+
*/
|
|
95
113
|
declare const MAX_ERROR_MESSAGE_LENGTH = 500;
|
|
96
114
|
/**
|
|
97
115
|
* A failure whose only fact is its HTTP status: a status the catalog has no
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAYL,YAAY,EAIb,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAEH
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAYL,YAAY,EAIb,MAAM,kBAAkB,CAA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AE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACjD,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACnD,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACrD;AAED;;EAEE;AACF,QAAA,MAAM,wBAAwB,MAAM,CAAC;AA2BrC;;;;;;;GAOG;AACH,cAAM,eAAgB,SAAQ,YAAY;gBAC5B,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;CAGjE;AA2GD;;;;;;GAMG;AACH,iBAAS,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAkB/C;AAED;;;;;;;;;;;;;GAaG;AACH,iBAAS,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,GAAE,sBAA2B,GAAG,SAAS,CAoG1F;AAED,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,eAAe,EAAE,wBAAwB,EAAE,CAAC;AAClF,YAAY,EAAE,SAAS,EAAE,cAAc,EAAE,sBAAsB,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC"}
|
package/dist/api.js
CHANGED
|
@@ -1,258 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
/** Default truncation for a server-provided message. */
|
|
3
|
-
const MAX_ERROR_MESSAGE_LENGTH = 500;
|
|
4
|
-
/**
|
|
5
|
-
* Statuses the family taxonomy has a class for, mapped to it.
|
|
6
|
-
*
|
|
7
|
-
* The map is keyed by status rather than by the server's `Exception.Type`
|
|
8
|
-
* because the status is the fact that survives a rolling deploy: a body from an
|
|
9
|
-
* older Worker build still carries today's status, while a `Type` may be
|
|
10
|
-
* spelled either way.
|
|
11
|
-
*/
|
|
12
|
-
const HTTP_ERROR_CLASSES = {
|
|
13
|
-
400: BadRequestError,
|
|
14
|
-
401: UnauthorizedError,
|
|
15
|
-
403: ForbiddenError,
|
|
16
|
-
404: NotFoundError,
|
|
17
|
-
405: MethodNotAllowedError,
|
|
18
|
-
409: ConflictError,
|
|
19
|
-
412: PreconditionFailedError,
|
|
20
|
-
413: PayloadTooLargeError,
|
|
21
|
-
415: UnsupportedMediaTypeError,
|
|
22
|
-
429: RateLimitedError,
|
|
23
|
-
500: InternalServerError,
|
|
24
|
-
501: NotImplementedError,
|
|
25
|
-
502: BadGatewayError,
|
|
26
|
-
503: ServiceUnavailableError,
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* A failure whose only fact is its HTTP status: a status the catalog has no
|
|
30
|
-
* class for (451, 418, a proxy's own 5xx), or a 2xx body that is not JSON.
|
|
31
|
-
*
|
|
32
|
-
* It exists so the thrown value is *always* a `ServiceError` — a caller
|
|
33
|
-
* branching on `instanceof ServiceError` does not have to know which statuses
|
|
34
|
-
* the catalog happens to cover.
|
|
35
|
-
*/
|
|
36
|
-
class HttpStatusError extends ServiceError {
|
|
37
|
-
constructor(status, message, type) {
|
|
38
|
-
super(status, type ?? `HttpStatus${status}`, message);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function readString(value) {
|
|
42
|
-
return typeof value === 'string' && value.trim() !== '' ? value : null;
|
|
43
|
-
}
|
|
44
|
-
function truncate(value, maxLength) {
|
|
45
|
-
return value.length > maxLength ? `${value.slice(0, maxLength)}…` : value;
|
|
46
|
-
}
|
|
47
|
-
/** Rejects control characters: that is what separates text from a binary or a document. */
|
|
48
|
-
// eslint-disable-next-line no-control-regex -- rejecting control characters IS the test
|
|
49
|
-
const CONTROL_CHARACTER = /[\u0000-\u001F\u007F]/;
|
|
50
|
-
/**
|
|
51
|
-
* Whether a non-JSON error body is text worth showing rather than markup or a
|
|
52
|
-
* blob. Deliberately conservative: the cost of wrongly refusing is the generic
|
|
53
|
-
* status sentence, and the cost of wrongly accepting is an HTML page in a
|
|
54
|
-
* notice bar.
|
|
55
|
-
*/
|
|
56
|
-
function isProbablyProse(raw, maxLength) {
|
|
57
|
-
if (raw.length === 0 || raw.length > maxLength || raw.includes('<')) {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
return !CONTROL_CHARACTER.test(raw);
|
|
61
|
-
}
|
|
62
|
-
function decodeJsonError(payload, status, maxLength) {
|
|
63
|
-
if (typeof payload === 'string') {
|
|
64
|
-
const message = payload.trim();
|
|
65
|
-
return { message: message === '' ? null : truncate(message, maxLength), type: null };
|
|
66
|
-
}
|
|
67
|
-
if (typeof payload !== 'object' || payload === null) {
|
|
68
|
-
return { message: null, type: null };
|
|
69
|
-
}
|
|
70
|
-
// Three dialects, newest first: the AWS envelope, the unified `{error:
|
|
71
|
-
// {code,message}}` object, and the legacy flat `{error, message}`.
|
|
72
|
-
const envelope = payload;
|
|
73
|
-
const nestedError = typeof envelope.error === 'object' && envelope.error !== null ? envelope.error : null;
|
|
74
|
-
const type = readString(envelope.Exception?.Type) ??
|
|
75
|
-
(typeof envelope.error === 'string' ? readString(envelope.error) : null) ??
|
|
76
|
-
readString(nestedError?.code) ??
|
|
77
|
-
readString(envelope.code) ??
|
|
78
|
-
null;
|
|
79
|
-
const message = readString(envelope.Exception?.Message) ??
|
|
80
|
-
readString(envelope.message) ??
|
|
81
|
-
(typeof envelope.error === 'string' ? readString(envelope.error) : null) ??
|
|
82
|
-
readString(nestedError?.message) ??
|
|
83
|
-
null;
|
|
84
|
-
if (message !== null) {
|
|
85
|
-
return { message: truncate(message, maxLength), type };
|
|
86
|
-
}
|
|
87
|
-
if (type !== null) {
|
|
88
|
-
// The server named the failure but gave no sentence for it.
|
|
89
|
-
return { message: `${type} (HTTP ${status})`, type };
|
|
90
|
-
}
|
|
91
|
-
return { message: null, type: null };
|
|
92
|
-
}
|
|
93
|
-
function decodeErrorBody(text, status, maxLength) {
|
|
94
|
-
const trimmed = text.trim();
|
|
95
|
-
if (trimmed === '') {
|
|
96
|
-
return { message: null, type: null };
|
|
97
|
-
}
|
|
98
|
-
try {
|
|
99
|
-
return decodeJsonError(JSON.parse(trimmed), status, maxLength);
|
|
100
|
-
}
|
|
101
|
-
catch {
|
|
102
|
-
return { message: isProbablyProse(trimmed, maxLength) ? truncate(trimmed, maxLength) : null, type: null };
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
function mergeHeaders(base, overrides) {
|
|
106
|
-
const headers = new Headers(base);
|
|
107
|
-
if (overrides === undefined) {
|
|
108
|
-
return headers;
|
|
109
|
-
}
|
|
110
|
-
for (const [name, value] of new Headers(overrides)) {
|
|
111
|
-
headers.set(name, value);
|
|
112
|
-
}
|
|
113
|
-
return headers;
|
|
114
|
-
}
|
|
115
|
-
function isQueryList(value) {
|
|
116
|
-
return Array.isArray(value);
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Builds a query string, with the leading `?` and without it when empty.
|
|
120
|
-
*
|
|
121
|
-
* `null`, `undefined` and `''` are dropped rather than sent as empty
|
|
122
|
-
* parameters, and an array value repeats the key — both as in the copies this
|
|
123
|
-
* replaces.
|
|
124
|
-
*/
|
|
125
|
-
function buildQuery(params) {
|
|
126
|
-
const search = new URLSearchParams();
|
|
127
|
-
for (const [name, value] of Object.entries(params)) {
|
|
128
|
-
if (value === undefined || value === null || value === '') {
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
if (isQueryList(value)) {
|
|
132
|
-
for (const entry of value) {
|
|
133
|
-
if (entry !== undefined && entry !== null && entry !== '') {
|
|
134
|
-
search.append(name, String(entry));
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
search.set(name, String(value));
|
|
140
|
-
}
|
|
141
|
-
const encoded = search.toString();
|
|
142
|
-
return encoded === '' ? '' : `?${encoded}`;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Builds a client over a `fetch` implementation.
|
|
146
|
-
*
|
|
147
|
-
* ```ts
|
|
148
|
-
* const api = createApiClient(fetch, { baseUrl: '/user' });
|
|
149
|
-
* const me = await api.get<CurrentUser>('/me');
|
|
150
|
-
* ```
|
|
151
|
-
*
|
|
152
|
-
* The `fetchFn` parameter is what makes this testable without a network and
|
|
153
|
-
* swappable for an instrumented wrapper; in a browser it is the global `fetch`.
|
|
154
|
-
* Memoize the client (a module constant, or `useMemo`) — `useCurrentUser`
|
|
155
|
-
* deliberately does not re-fetch when a new client instance appears, but a new
|
|
156
|
-
* instance per render still churns.
|
|
157
|
-
*/
|
|
158
|
-
function createApiClient(fetchFn, options = {}) {
|
|
159
|
-
const baseUrl = options.baseUrl ?? '';
|
|
160
|
-
const maxErrorMessageLength = options.maxErrorMessageLength ?? MAX_ERROR_MESSAGE_LENGTH;
|
|
161
|
-
async function request(path, init = {}) {
|
|
162
|
-
const method = (init.method ?? 'GET').toUpperCase();
|
|
163
|
-
const url = `${baseUrl}${path}`;
|
|
164
|
-
const hasBody = init.body !== undefined;
|
|
165
|
-
const headers = mergeHeaders(options.headers, init.headers);
|
|
166
|
-
// Same-origin only, and no token in JavaScript: the Cloudflare Access
|
|
167
|
-
// session cookie rides along under the default credentials, and there is no
|
|
168
|
-
// place for a token to leak to. Both defaults yield to an explicit header
|
|
169
|
-
// — a consumer that wants XML passes its own `Accept`.
|
|
170
|
-
if (!headers.has('Accept')) {
|
|
171
|
-
headers.set('Accept', 'application/json');
|
|
172
|
-
}
|
|
173
|
-
if (hasBody && !headers.has('Content-Type')) {
|
|
174
|
-
headers.set('Content-Type', 'application/json');
|
|
175
|
-
}
|
|
176
|
-
const requestInit = { method, headers };
|
|
177
|
-
if (options.credentials !== undefined) {
|
|
178
|
-
requestInit.credentials = options.credentials;
|
|
179
|
-
}
|
|
180
|
-
if (hasBody) {
|
|
181
|
-
requestInit.body = JSON.stringify(init.body);
|
|
182
|
-
}
|
|
183
|
-
if (init.signal !== undefined && init.signal !== null) {
|
|
184
|
-
requestInit.signal = init.signal;
|
|
185
|
-
}
|
|
186
|
-
const context = `${method} ${url}`;
|
|
187
|
-
let response;
|
|
188
|
-
try {
|
|
189
|
-
response = await fetchFn(url, requestInit);
|
|
190
|
-
}
|
|
191
|
-
catch (cause) {
|
|
192
|
-
// The transport never answered — offline, DNS, CORS, an aborted signal.
|
|
193
|
-
// There is no status to report, so the failure normalizes through
|
|
194
|
-
// `ServiceError.from` like any other unknown throw. A caller that cancels
|
|
195
|
-
// its own request therefore sees a 500-shaped error too; the taxonomy has
|
|
196
|
-
// no "aborted" class, and swallowing it here would hide real transport
|
|
197
|
-
// failures. A caller that cancels should not surface the rejection.
|
|
198
|
-
throw ServiceError.from(cause);
|
|
199
|
-
}
|
|
200
|
-
if (!response.ok) {
|
|
201
|
-
throw await toServiceError(response);
|
|
202
|
-
}
|
|
203
|
-
return readJson(response, context);
|
|
204
|
-
}
|
|
205
|
-
async function toServiceError(response) {
|
|
206
|
-
let text = '';
|
|
207
|
-
try {
|
|
208
|
-
text = await response.text();
|
|
209
|
-
}
|
|
210
|
-
catch {
|
|
211
|
-
// The body could not be read at all — a reset after the headers. The
|
|
212
|
-
// status is still the one true thing about the request, and the catalog
|
|
213
|
-
// default message says more than anything this could invent.
|
|
214
|
-
}
|
|
215
|
-
const decoded = decodeErrorBody(text, response.status, maxErrorMessageLength);
|
|
216
|
-
const ErrorClass = HTTP_ERROR_CLASSES[response.status];
|
|
217
|
-
if (ErrorClass !== undefined) {
|
|
218
|
-
// A `null` message leaves the catalog's default in place, which is a
|
|
219
|
-
// better sentence than anything the client could invent.
|
|
220
|
-
return new ErrorClass(decoded.message ?? undefined);
|
|
221
|
-
}
|
|
222
|
-
return new HttpStatusError(response.status, decoded.message ?? `Request failed with status ${response.status}.`, decoded.type);
|
|
223
|
-
}
|
|
224
|
-
async function readJson(response, context) {
|
|
225
|
-
if (response.status === 204) {
|
|
226
|
-
return undefined;
|
|
227
|
-
}
|
|
228
|
-
let text;
|
|
229
|
-
try {
|
|
230
|
-
text = await response.text();
|
|
231
|
-
}
|
|
232
|
-
catch (cause) {
|
|
233
|
-
throw ServiceError.from(cause);
|
|
234
|
-
}
|
|
235
|
-
if (text.trim() === '') {
|
|
236
|
-
return undefined;
|
|
237
|
-
}
|
|
238
|
-
try {
|
|
239
|
-
return JSON.parse(text);
|
|
240
|
-
}
|
|
241
|
-
catch {
|
|
242
|
-
// A 2xx body that is not JSON is an HTML error page from a proxy. It must
|
|
243
|
-
// surface as a ServiceError, not a SyntaxError, so the caller's error
|
|
244
|
-
// handling has one shape to recognize.
|
|
245
|
-
throw new HttpStatusError(response.status, `Malformed response body: ${context}`, null);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
return {
|
|
249
|
-
request,
|
|
250
|
-
get: async (path, params) => request(`${path}${params === undefined ? '' : buildQuery(params)}`),
|
|
251
|
-
post: async (path, body) => request(path, { method: 'POST', body }),
|
|
252
|
-
put: async (path, body) => request(path, { method: 'PUT', body }),
|
|
253
|
-
patch: async (path, body) => request(path, { method: 'PATCH', body }),
|
|
254
|
-
delete: async (path, body) => request(path, { method: 'DELETE', body }),
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
export { buildQuery, createApiClient, HttpStatusError, MAX_ERROR_MESSAGE_LENGTH };
|
|
258
|
-
//# sourceMappingURL=api.js.map
|
|
1
|
+
import{BadGatewayError as $,BadRequestError as A,ConflictError as C,ForbiddenError as O,InternalServerError as H,MethodNotAllowedError as P,NotFoundError as M,NotImplementedError as N,PayloadTooLargeError as U,PreconditionFailedError as x,RateLimitedError as j,ServiceError as m,ServiceUnavailableError as L,UnauthorizedError as _,UnsupportedMediaTypeError as F}from"@rexezuge/errors";const S=500,T={400:A,401:_,403:O,404:M,405:P,409:C,412:x,413:U,415:F,429:j,500:H,501:N,502:$,503:L};class g extends m{constructor(n,u,r){super(n,r??`HttpStatus${n}`,u)}}function i(e){return typeof e=="string"&&e.trim()!==""?e:null}function h(e,n){return e.length>n?`${e.slice(0,n)}\u2026`:e}const J=/[\u0000-\u001F\u007F]/;function q(e,n){return e.length===0||e.length>n||e.includes("<")?!1:!J.test(e)}function B(e,n,u){if(typeof e=="string"){const t=e.trim();return{message:t===""?null:h(t,u),type:null}}if(typeof e!="object"||e===null)return{message:null,type:null};const r=e,s=typeof r.error=="object"&&r.error!==null?r.error:null,c=i(r.Exception?.Type)??(typeof r.error=="string"?i(r.error):null)??i(s?.code)??i(r.code)??null,f=i(r.Exception?.Message)??i(r.message)??(typeof r.error=="string"?i(r.error):null)??i(s?.message)??null;return f!==null?{message:h(f,u),type:c}:c!==null?{message:`${c} (HTTP ${n})`,type:c}:{message:null,type:null}}function G(e,n,u){const r=e.trim();if(r==="")return{message:null,type:null};try{return B(JSON.parse(r),n,u)}catch{return{message:q(r,u)?h(r,u):null,type:null}}}function v(e,n){const u=new Headers(e);if(n===void 0)return u;for(const[r,s]of new Headers(n))u.set(r,s);return u}function I(e){return Array.isArray(e)}function b(e){const n=new URLSearchParams;for(const[r,s]of Object.entries(e))if(!(s==null||s==="")){if(I(s)){for(const c of s)c!=null&&c!==""&&n.append(r,String(c));continue}n.set(r,String(s))}const u=n.toString();return u===""?"":`?${u}`}function Q(e,n={}){const u=n.baseUrl??"",r=n.maxErrorMessageLength??S;async function s(t,o={}){const a=(o.method??"GET").toUpperCase(),l=`${u}${t}`,p=o.body!==void 0,d=v(n.headers,o.headers);d.has("Accept")||d.set("Accept","application/json"),p&&!d.has("Content-Type")&&d.set("Content-Type","application/json");const y={method:a,headers:d};n.credentials!==void 0&&(y.credentials=n.credentials),p&&(y.body=JSON.stringify(o.body)),o.signal!==void 0&&o.signal!==null&&(y.signal=o.signal);const w=`${a} ${l}`;let E;try{E=await e(l,y)}catch(R){throw m.from(R)}if(!E.ok)throw await c(E);return f(E,w)}async function c(t){let o="";try{o=await t.text()}catch{}const a=G(o,t.status,r);if(Object.hasOwn(T,t.status)){const l=T[t.status];return new l(a.message??void 0)}return new g(t.status,a.message??`Request failed with status ${t.status}.`,a.type)}async function f(t,o){if(t.status===204)return;let a;try{a=await t.text()}catch(l){throw m.from(l)}if(a.trim()!=="")try{return JSON.parse(a)}catch{throw new g(t.status,`Malformed response body: ${o}`,null)}}return{request:s,get:async(t,o)=>s(`${t}${o===void 0?"":b(o)}`),post:async(t,o)=>s(t,{method:"POST",body:o}),put:async(t,o)=>s(t,{method:"PUT",body:o}),patch:async(t,o)=>s(t,{method:"PATCH",body:o}),delete:async(t,o)=>s(t,{method:"DELETE",body:o})}}export{g as HttpStatusError,S as MAX_ERROR_MESSAGE_LENGTH,b as buildQuery,Q as createApiClient};
|
package/dist/api.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EACf,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,qBAAqB,EACrB,aAAa,EACb,mBAAmB,EACnB,oBAAoB,EACpB,uBAAuB,EACvB,gBAAgB,EAChB,YAAY,EACZ,uBAAuB,EACvB,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,kBAAkB,CAAC;AAqG1B,wDAAwD;AACxD,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAErC;;;;;;;GAOG;AACH,MAAM,kBAAkB,GAAqE;IAC3F,GAAG,EAAE,eAAe;IACpB,GAAG,EAAE,iBAAiB;IACtB,GAAG,EAAE,cAAc;IACnB,GAAG,EAAE,aAAa;IAClB,GAAG,EAAE,qBAAqB;IAC1B,GAAG,EAAE,aAAa;IAClB,GAAG,EAAE,uBAAuB;IAC5B,GAAG,EAAE,oBAAoB;IACzB,GAAG,EAAE,yBAAyB;IAC9B,GAAG,EAAE,gBAAgB;IACrB,GAAG,EAAE,mBAAmB;IACxB,GAAG,EAAE,mBAAmB;IACxB,GAAG,EAAE,eAAe;IACpB,GAAG,EAAE,uBAAuB;CAC7B,CAAC;AAEF;;;;;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AY,EAAE,IAAc,EAAc,EAAE,CAAC,OAAO,CAAI,IAAI,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;KAC5G,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,eAAe,EAAE,wBAAwB,EAAE,CAAC","sourcesContent":["import {\n BadGatewayError,\n BadRequestError,\n ConflictError,\n ForbiddenError,\n InternalServerError,\n MethodNotAllowedError,\n NotFoundError,\n NotImplementedError,\n PayloadTooLargeError,\n PreconditionFailedError,\n RateLimitedError,\n ServiceError,\n ServiceUnavailableError,\n UnauthorizedError,\n UnsupportedMediaTypeError,\n} from '@rexezuge/errors';\n\n/**\n * The SPA's request path.\n *\n * ## Provenance\n *\n * `lib/api.ts` in **CalDAV-Bridge**, **Durable-DAV**, **Durable-DAV-Router**,\n * **Edge-Git**, **Edge-Sonic**, **Mail-Otter** and **AWS-AccessBridge** — seven\n * copies that all drift on the same three decisions, settled here as follows.\n *\n * **1. Error model.** Six of the seven define a private `BackendError`\n * (`{ message, errorType, status }`) and hand-roll the status→branch mapping at\n * every call site; AWS defines `ApiError` (`{ status, message }`) plus an\n * `ApiResult{ok,status,data,error}` shape that its own guide records as\n * abandoned — every admin tab bypassed it, which is how nine of its seventeen\n * functions ended up with no caller. The kit replaces both with the family\n * taxonomy: every rejection is a `ServiceError`, so `error.status`,\n * `error.type`, `error.retryable` and `instanceof ServiceError` are available\n * without a per-repo error class, and `ServiceError.from` covers the\n * transport-level failures the private classes swallowed.\n *\n * **2. Error body decoding.** Converged from the three variants that exist:\n *\n * - The **AWS envelope** `{ Exception: { Type, Message } }`, read first in all\n * copies.\n * - The **legacy** `{ error, message }` shape, where Durable-DAV also reads a\n * string `error` as the *type* — otherwise a legacy body produced a correct\n * message and a `null` type, which sent it through the generic fallback and\n * lost the specific wording.\n * - **Edge-Sonic's prose test** for a non-JSON body: an Access login page or a\n * proxy's HTML error page is not a message an operator can act on, so markup\n * is reported as absent rather than quoted into a notice bar. Short,\n * single-line, tag-free text *is* surfaced, truncated.\n * - **Truncation** at 500 characters, from every copy that has one: an\n * unbounded error string from a proxy page is a rendering hazard.\n * - **`text()` then `JSON.parse`, never `json()` with a `text()` fallback** —\n * Edge-Sonic's comment records why the old shape cannot work: `json()`\n * consumes the body stream before it fails to parse, so the second read\n * returned `''` and the \"not JSON\" branch was unreachable.\n *\n * **3. Empty bodies.** Durable-DAV's fix is the one kept: a `204`, and an empty\n * body from an edge error page, resolve to `undefined` rather than throwing a\n * `SyntaxError` — which used to report a generic failure for an operation that\n * had actually succeeded (credential revoke). AWS-AccessBridge resolved the same\n * case to `{}`; `undefined` is the honest answer for \"there is no body\".\n *\n * ## What is deliberately not here\n *\n * - **The D1 session bookmark** (`x-d1-bookmark`, CalDAV-Bridge and\n * Mail-Otter). It is module state threading a D1 replica pin through every\n * `/user/*` request; the kit has no D1 client, so the header policy stays\n * with the repos that own the binding.\n * - **`apiAuthedFirst`** (Edge-Git) — a public-fallback policy with\n * fail-closed 401/403/404 handling, specific to that app's two-surface API.\n * - **WebDAV `readDav`** (Durable-DAV, Durable-DAV-Router) — it accepts `207\n * Multi-Status` as success, which is a WebDAV rule, not an HTTP rule. A\n * consumer needing XML calls `client.request` and reads `response.text()`\n * itself.\n * - **The `/user` base path.** Edge-Sonic bakes it in; the others pass full\n * paths. `baseUrl` is an option here, defaulting to empty, so the caller\n * decides.\n */\n\n/** The `fetch` shape a client is built on: same-origin by default, no token in JavaScript. */\ntype FetchFn = (input: string, init?: RequestInit) => Promise<Response>;\n\n/** A query-string value. `null`/`undefined`/`''` are omitted, as in every copy. */\ntype QueryValue = string | number | boolean | null | undefined;\n\ntype QueryParams = Record<string, QueryValue | readonly QueryValue[]>;\n\ninterface ApiRequestInit {\n method?: string;\n /** Serialized as JSON with a matching `Content-Type`. */\n body?: unknown;\n headers?: HeadersInit;\n signal?: AbortSignal | null;\n}\n\ninterface CreateApiClientOptions {\n /** Prepended to every path; `''` (the default) sends the path as given. */\n baseUrl?: string;\n /** Headers merged into every request; a per-request header wins over these. */\n headers?: HeadersInit;\n /** Passed through to `fetch`; omitted leaves the browser default. */\n credentials?: RequestCredentials;\n /** Truncation limit for a server-provided error message. Defaults to 500. */\n maxErrorMessageLength?: number;\n}\n\ninterface ApiClient {\n /** One request. Throws a `ServiceError`; resolves to the parsed JSON body. */\n request<T>(path: string, init?: ApiRequestInit): Promise<T>;\n get<T>(path: string, params?: QueryParams): Promise<T>;\n post<T>(path: string, body?: unknown): Promise<T>;\n put<T>(path: string, body?: unknown): Promise<T>;\n patch<T>(path: string, body?: unknown): Promise<T>;\n delete<T>(path: string, body?: unknown): Promise<T>;\n}\n\n/** Default truncation for a server-provided message. */\nconst MAX_ERROR_MESSAGE_LENGTH = 500;\n\n/**\n * Statuses the family taxonomy has a class for, mapped to it.\n *\n * The map is keyed by status rather than by the server's `Exception.Type`\n * because the status is the fact that survives a rolling deploy: a body from an\n * older Worker build still carries today's status, while a `Type` may be\n * spelled either way.\n */\nconst HTTP_ERROR_CLASSES: Readonly<Record<number, new (message?: string) => ServiceError>> = {\n 400: BadRequestError,\n 401: UnauthorizedError,\n 403: ForbiddenError,\n 404: NotFoundError,\n 405: MethodNotAllowedError,\n 409: ConflictError,\n 412: PreconditionFailedError,\n 413: PayloadTooLargeError,\n 415: UnsupportedMediaTypeError,\n 429: RateLimitedError,\n 500: InternalServerError,\n 501: NotImplementedError,\n 502: BadGatewayError,\n 503: ServiceUnavailableError,\n};\n\n/**\n * A failure whose only fact is its HTTP status: a status the catalog has no\n * class for (451, 418, a proxy's own 5xx), or a 2xx body that is not JSON.\n *\n * It exists so the thrown value is *always* a `ServiceError` — a caller\n * branching on `instanceof ServiceError` does not have to know which statuses\n * the catalog happens to cover.\n */\nclass HttpStatusError extends ServiceError {\n constructor(status: number, message: string, type: string | null) {\n super(status, type ?? `HttpStatus${status}`, message);\n }\n}\n\ninterface DecodedErrorBody {\n /** What the server said, or `null` when it said nothing usable. */\n message: string | null;\n /** The server's machine-readable code, when it sent one. */\n type: string | null;\n}\n\nfunction readString(value: unknown): string | null {\n return typeof value === 'string' && value.trim() !== '' ? value : null;\n}\n\nfunction truncate(value: string, maxLength: number): string {\n return value.length > maxLength ? `${value.slice(0, maxLength)}…` : value;\n}\n\n/** Rejects control characters: that is what separates text from a binary or a document. */\n// eslint-disable-next-line no-control-regex -- rejecting control characters IS the test\nconst CONTROL_CHARACTER = /[\\u0000-\\u001F\\u007F]/;\n\n/**\n * Whether a non-JSON error body is text worth showing rather than markup or a\n * blob. Deliberately conservative: the cost of wrongly refusing is the generic\n * status sentence, and the cost of wrongly accepting is an HTML page in a\n * notice bar.\n */\nfunction isProbablyProse(raw: string, maxLength: number): boolean {\n if (raw.length === 0 || raw.length > maxLength || raw.includes('<')) {\n return false;\n }\n return !CONTROL_CHARACTER.test(raw);\n}\n\nfunction decodeJsonError(payload: unknown, status: number, maxLength: number): DecodedErrorBody {\n if (typeof payload === 'string') {\n const message = payload.trim();\n return { message: message === '' ? null : truncate(message, maxLength), type: null };\n }\n if (typeof payload !== 'object' || payload === null) {\n return { message: null, type: null };\n }\n // Three dialects, newest first: the AWS envelope, the unified `{error:\n // {code,message}}` object, and the legacy flat `{error, message}`.\n const envelope = payload as {\n Exception?: { Type?: unknown; Message?: unknown };\n error?: unknown;\n message?: unknown;\n code?: unknown;\n };\n const nestedError =\n typeof envelope.error === 'object' && envelope.error !== null ? (envelope.error as { message?: unknown; code?: unknown }) : null;\n const type =\n readString(envelope.Exception?.Type) ??\n (typeof envelope.error === 'string' ? readString(envelope.error) : null) ??\n readString(nestedError?.code) ??\n readString(envelope.code) ??\n null;\n const message =\n readString(envelope.Exception?.Message) ??\n readString(envelope.message) ??\n (typeof envelope.error === 'string' ? readString(envelope.error) : null) ??\n readString(nestedError?.message) ??\n null;\n if (message !== null) {\n return { message: truncate(message, maxLength), type };\n }\n if (type !== null) {\n // The server named the failure but gave no sentence for it.\n return { message: `${type} (HTTP ${status})`, type };\n }\n return { message: null, type: null };\n}\n\nfunction decodeErrorBody(text: string, status: number, maxLength: number): DecodedErrorBody {\n const trimmed = text.trim();\n if (trimmed === '') {\n return { message: null, type: null };\n }\n try {\n return decodeJsonError(JSON.parse(trimmed) as unknown, status, maxLength);\n } catch {\n return { message: isProbablyProse(trimmed, maxLength) ? truncate(trimmed, maxLength) : null, type: null };\n }\n}\n\nfunction mergeHeaders(base: HeadersInit | undefined, overrides?: HeadersInit): Headers {\n const headers = new Headers(base);\n if (overrides === undefined) {\n return headers;\n }\n for (const [name, value] of new Headers(overrides)) {\n headers.set(name, value);\n }\n return headers;\n}\n\nfunction isQueryList(value: QueryValue | readonly QueryValue[]): value is readonly QueryValue[] {\n return Array.isArray(value);\n}\n\n/**\n * Builds a query string, with the leading `?` and without it when empty.\n *\n * `null`, `undefined` and `''` are dropped rather than sent as empty\n * parameters, and an array value repeats the key — both as in the copies this\n * replaces.\n */\nfunction buildQuery(params: QueryParams): string {\n const search = new URLSearchParams();\n for (const [name, value] of Object.entries(params)) {\n if (value === undefined || value === null || value === '') {\n continue;\n }\n if (isQueryList(value)) {\n for (const entry of value) {\n if (entry !== undefined && entry !== null && entry !== '') {\n search.append(name, String(entry));\n }\n }\n continue;\n }\n search.set(name, String(value));\n }\n const encoded = search.toString();\n return encoded === '' ? '' : `?${encoded}`;\n}\n\n/**\n * Builds a client over a `fetch` implementation.\n *\n * ```ts\n * const api = createApiClient(fetch, { baseUrl: '/user' });\n * const me = await api.get<CurrentUser>('/me');\n * ```\n *\n * The `fetchFn` parameter is what makes this testable without a network and\n * swappable for an instrumented wrapper; in a browser it is the global `fetch`.\n * Memoize the client (a module constant, or `useMemo`) — `useCurrentUser`\n * deliberately does not re-fetch when a new client instance appears, but a new\n * instance per render still churns.\n */\nfunction createApiClient(fetchFn: FetchFn, options: CreateApiClientOptions = {}): ApiClient {\n const baseUrl = options.baseUrl ?? '';\n const maxErrorMessageLength = options.maxErrorMessageLength ?? MAX_ERROR_MESSAGE_LENGTH;\n\n async function request<T>(path: string, init: ApiRequestInit = {}): Promise<T> {\n const method = (init.method ?? 'GET').toUpperCase();\n const url = `${baseUrl}${path}`;\n const hasBody = init.body !== undefined;\n const headers = mergeHeaders(options.headers, init.headers);\n // Same-origin only, and no token in JavaScript: the Cloudflare Access\n // session cookie rides along under the default credentials, and there is no\n // place for a token to leak to. Both defaults yield to an explicit header\n // — a consumer that wants XML passes its own `Accept`.\n if (!headers.has('Accept')) {\n headers.set('Accept', 'application/json');\n }\n if (hasBody && !headers.has('Content-Type')) {\n headers.set('Content-Type', 'application/json');\n }\n const requestInit: RequestInit = { method, headers };\n if (options.credentials !== undefined) {\n requestInit.credentials = options.credentials;\n }\n if (hasBody) {\n requestInit.body = JSON.stringify(init.body);\n }\n if (init.signal !== undefined && init.signal !== null) {\n requestInit.signal = init.signal;\n }\n\n const context = `${method} ${url}`;\n let response: Response;\n try {\n response = await fetchFn(url, requestInit);\n } catch (cause) {\n // The transport never answered — offline, DNS, CORS, an aborted signal.\n // There is no status to report, so the failure normalizes through\n // `ServiceError.from` like any other unknown throw. A caller that cancels\n // its own request therefore sees a 500-shaped error too; the taxonomy has\n // no \"aborted\" class, and swallowing it here would hide real transport\n // failures. A caller that cancels should not surface the rejection.\n throw ServiceError.from(cause);\n }\n if (!response.ok) {\n throw await toServiceError(response);\n }\n return readJson<T>(response, context);\n }\n\n async function toServiceError(response: Response): Promise<ServiceError> {\n let text = '';\n try {\n text = await response.text();\n } catch {\n // The body could not be read at all — a reset after the headers. The\n // status is still the one true thing about the request, and the catalog\n // default message says more than anything this could invent.\n }\n const decoded = decodeErrorBody(text, response.status, maxErrorMessageLength);\n const ErrorClass = HTTP_ERROR_CLASSES[response.status];\n if (ErrorClass !== undefined) {\n // A `null` message leaves the catalog's default in place, which is a\n // better sentence than anything the client could invent.\n return new ErrorClass(decoded.message ?? undefined);\n }\n return new HttpStatusError(response.status, decoded.message ?? `Request failed with status ${response.status}.`, decoded.type);\n }\n\n async function readJson<T>(response: Response, context: string): Promise<T> {\n if (response.status === 204) {\n return undefined as T;\n }\n let text: string;\n try {\n text = await response.text();\n } catch (cause) {\n throw ServiceError.from(cause);\n }\n if (text.trim() === '') {\n return undefined as T;\n }\n try {\n return JSON.parse(text) as T;\n } catch {\n // A 2xx body that is not JSON is an HTML error page from a proxy. It must\n // surface as a ServiceError, not a SyntaxError, so the caller's error\n // handling has one shape to recognize.\n throw new HttpStatusError(response.status, `Malformed response body: ${context}`, null);\n }\n }\n\n return {\n request,\n get: async <T>(path: string, params?: QueryParams): Promise<T> =>\n request<T>(`${path}${params === undefined ? '' : buildQuery(params)}`),\n post: async <T>(path: string, body?: unknown): Promise<T> => request<T>(path, { method: 'POST', body }),\n put: async <T>(path: string, body?: unknown): Promise<T> => request<T>(path, { method: 'PUT', body }),\n patch: async <T>(path: string, body?: unknown): Promise<T> => request<T>(path, { method: 'PATCH', body }),\n delete: async <T>(path: string, body?: unknown): Promise<T> => request<T>(path, { method: 'DELETE', body }),\n };\n}\n\nexport { buildQuery, createApiClient, HttpStatusError, MAX_ERROR_MESSAGE_LENGTH };\nexport type { ApiClient, ApiRequestInit, CreateApiClientOptions, FetchFn, QueryParams, QueryValue };\n"]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/api.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n BadGatewayError,\n BadRequestError,\n ConflictError,\n ForbiddenError,\n InternalServerError,\n MethodNotAllowedError,\n NotFoundError,\n NotImplementedError,\n PayloadTooLargeError,\n PreconditionFailedError,\n RateLimitedError,\n ServiceError,\n ServiceUnavailableError,\n UnauthorizedError,\n UnsupportedMediaTypeError,\n} from '@rexezuge/errors';\n\n/**\n * The SPA's request path.\n *\n * ## Provenance\n *\n * `lib/api.ts` in **CalDAV-Bridge**, **Durable-DAV**, **Durable-DAV-Router**,\n * **Edge-Git**, **Edge-Sonic**, **Mail-Otter** and **AWS-AccessBridge** — seven\n * copies that all drift on the same three decisions, settled here as follows.\n *\n * **1. Error model.** Six of the seven define a private `BackendError`\n * (`{ message, errorType, status }`) and hand-roll the status→branch mapping at\n * every call site; AWS defines `ApiError` (`{ status, message }`) plus an\n * `ApiResult{ok,status,data,error}` shape that its own guide records as\n * abandoned — every admin tab bypassed it, which is how nine of its seventeen\n * functions ended up with no caller. The kit replaces both with the family\n * taxonomy: every rejection is a `ServiceError`, so `error.status`,\n * `error.type`, `error.retryable` and `instanceof ServiceError` are available\n * without a per-repo error class, and `ServiceError.from` covers the\n * transport-level failures the private classes swallowed.\n *\n * **2. Error body decoding.** Converged from the three variants that exist:\n *\n * - The **AWS envelope** `{ Exception: { Type, Message } }`, read first in all\n * copies.\n * - The **legacy** `{ error, message }` shape, where Durable-DAV also reads a\n * string `error` as the *type* — otherwise a legacy body produced a correct\n * message and a `null` type, which sent it through the generic fallback and\n * lost the specific wording.\n * - **Edge-Sonic's prose test** for a non-JSON body: an Access login page or a\n * proxy's HTML error page is not a message an operator can act on, so markup\n * is reported as absent rather than quoted into a notice bar. Short,\n * single-line, tag-free text *is* surfaced, truncated.\n * - **Truncation** at 500 characters, from every copy that has one: an\n * unbounded error string from a proxy page is a rendering hazard.\n * - **`text()` then `JSON.parse`, never `json()` with a `text()` fallback** —\n * Edge-Sonic's comment records why the old shape cannot work: `json()`\n * consumes the body stream before it fails to parse, so the second read\n * returned `''` and the \"not JSON\" branch was unreachable.\n *\n * **3. Empty bodies.** Durable-DAV's fix is the one kept: a `204`, and an empty\n * body from an edge error page, resolve to `undefined` rather than throwing a\n * `SyntaxError` — which used to report a generic failure for an operation that\n * had actually succeeded (credential revoke). AWS-AccessBridge resolved the same\n * case to `{}`; `undefined` is the honest answer for \"there is no body\".\n *\n * ## What is deliberately not here\n *\n * - **The D1 session bookmark** (`x-d1-bookmark`, CalDAV-Bridge and\n * Mail-Otter). It is module state threading a D1 replica pin through every\n * `/user/*` request; the kit has no D1 client, so the header policy stays\n * with the repos that own the binding.\n * - **`apiAuthedFirst`** (Edge-Git) — a public-fallback policy with\n * fail-closed 401/403/404 handling, specific to that app's two-surface API.\n * - **WebDAV `readDav`** (Durable-DAV, Durable-DAV-Router) — it accepts `207\n * Multi-Status` as success, which is a WebDAV rule, not an HTTP rule. A\n * consumer needing XML calls `client.request` and reads `response.text()`\n * itself.\n * - **The `/user` base path.** Edge-Sonic bakes it in; the others pass full\n * paths. `baseUrl` is an option here, defaulting to empty, so the caller\n * decides.\n */\n\n/**\nThe `fetch` shape a client is built on: same-origin by default, no token in JavaScript.\n*/\ntype FetchFn = (input: string, init?: RequestInit) => Promise<Response>;\n\n/**\nA query-string value. `null`/`undefined`/`''` are omitted, as in every copy.\n*/\ntype QueryValue = string | number | boolean | null | undefined;\n\ntype QueryParams = Record<string, QueryValue | readonly QueryValue[]>;\n\ninterface ApiRequestInit {\n method?: string;\n /**\n Serialized as JSON with a matching `Content-Type`.\n */\n body?: unknown;\n headers?: HeadersInit;\n signal?: AbortSignal | null;\n}\n\ninterface CreateApiClientOptions {\n /**\n Prepended to every path; `''` (the default) sends the path as given.\n */\n baseUrl?: string;\n /**\n Headers merged into every request; a per-request header wins over these.\n */\n headers?: HeadersInit;\n /**\n Passed through to `fetch`; omitted leaves the browser default.\n */\n credentials?: RequestCredentials;\n /**\n Truncation limit for a server-provided error message. Defaults to 500.\n */\n maxErrorMessageLength?: number;\n}\n\ninterface ApiClient {\n /**\n One request. Throws a `ServiceError`; resolves to the parsed JSON body.\n */\n request<T>(path: string, init?: ApiRequestInit): Promise<T>;\n get<T>(path: string, params?: QueryParams): Promise<T>;\n post<T>(path: string, body?: unknown): Promise<T>;\n put<T>(path: string, body?: unknown): Promise<T>;\n patch<T>(path: string, body?: unknown): Promise<T>;\n delete<T>(path: string, body?: unknown): Promise<T>;\n}\n\n/**\nDefault truncation for a server-provided message.\n*/\nconst MAX_ERROR_MESSAGE_LENGTH = 500;\n\n/**\n * Statuses the family taxonomy has a class for, mapped to it.\n *\n * The map is keyed by status rather than by the server's `Exception.Type`\n * because the status is the fact that survives a rolling deploy: a body from an\n * older Worker build still carries today's status, while a `Type` may be\n * spelled either way.\n */\nconst HTTP_ERROR_CLASSES: Readonly<Record<number, new (message?: string) => ServiceError>> = {\n 400: BadRequestError,\n 401: UnauthorizedError,\n 403: ForbiddenError,\n 404: NotFoundError,\n 405: MethodNotAllowedError,\n 409: ConflictError,\n 412: PreconditionFailedError,\n 413: PayloadTooLargeError,\n 415: UnsupportedMediaTypeError,\n 429: RateLimitedError,\n 500: InternalServerError,\n 501: NotImplementedError,\n 502: BadGatewayError,\n 503: ServiceUnavailableError,\n};\n\n/**\n * A failure whose only fact is its HTTP status: a status the catalog has no\n * class for (451, 418, a proxy's own 5xx), or a 2xx body that is not JSON.\n *\n * It exists so the thrown value is *always* a `ServiceError` — a caller\n * branching on `instanceof ServiceError` does not have to know which statuses\n * the catalog happens to cover.\n */\nclass HttpStatusError extends ServiceError {\n constructor(status: number, message: string, type: string | null) {\n super(status, type ?? `HttpStatus${status}`, message);\n }\n}\n\ninterface DecodedErrorBody {\n /**\n What the server said, or `null` when it said nothing usable.\n */\n message: string | null;\n /**\n The server's machine-readable code, when it sent one.\n */\n type: string | null;\n}\n\nfunction readString(value: unknown): string | null {\n return typeof value === 'string' && value.trim() !== '' ? value : null;\n}\n\nfunction truncate(value: string, maxLength: number): string {\n return value.length > maxLength ? `${value.slice(0, maxLength)}…` : value;\n}\n\n/**\nRejects control characters: that is what separates text from a binary or a document.\n*/\n// eslint-disable-next-line no-control-regex -- rejecting control characters IS the test\nconst CONTROL_CHARACTER = /[\\u0000-\\u001F\\u007F]/;\n\n/**\n * Whether a non-JSON error body is text worth showing rather than markup or a\n * blob. Deliberately conservative: the cost of wrongly refusing is the generic\n * status sentence, and the cost of wrongly accepting is an HTML page in a\n * notice bar.\n */\nfunction isProbablyProse(raw: string, maxLength: number): boolean {\n if (raw.length === 0 || raw.length > maxLength || raw.includes('<')) {\n return false;\n }\n return !CONTROL_CHARACTER.test(raw);\n}\n\nfunction decodeJsonError(payload: unknown, status: number, maxLength: number): DecodedErrorBody {\n if (typeof payload === 'string') {\n const message = payload.trim();\n return { message: message === '' ? null : truncate(message, maxLength), type: null };\n }\n if (typeof payload !== 'object' || payload === null) {\n return { message: null, type: null };\n }\n // Three dialects, newest first: the AWS envelope, the unified `{error:\n // {code,message}}` object, and the legacy flat `{error, message}`.\n const envelope = payload as {\n Exception?: { Type?: unknown; Message?: unknown };\n error?: unknown;\n message?: unknown;\n code?: unknown;\n };\n const nestedError =\n typeof envelope.error === 'object' && envelope.error !== null ? (envelope.error as { message?: unknown; code?: unknown }) : null;\n const type =\n readString(envelope.Exception?.Type) ??\n (typeof envelope.error === 'string' ? readString(envelope.error) : null) ??\n readString(nestedError?.code) ??\n readString(envelope.code) ??\n null;\n const message =\n readString(envelope.Exception?.Message) ??\n readString(envelope.message) ??\n (typeof envelope.error === 'string' ? readString(envelope.error) : null) ??\n readString(nestedError?.message) ??\n null;\n if (message !== null) {\n return { message: truncate(message, maxLength), type };\n }\n if (type !== null) {\n // The server named the failure but gave no sentence for it.\n return { message: `${type} (HTTP ${status})`, type };\n }\n return { message: null, type: null };\n}\n\nfunction decodeErrorBody(text: string, status: number, maxLength: number): DecodedErrorBody {\n const trimmed = text.trim();\n if (trimmed === '') {\n return { message: null, type: null };\n }\n try {\n return decodeJsonError(JSON.parse(trimmed) as unknown, status, maxLength);\n } catch {\n return { message: isProbablyProse(trimmed, maxLength) ? truncate(trimmed, maxLength) : null, type: null };\n }\n}\n\nfunction mergeHeaders(base: HeadersInit | undefined, overrides?: HeadersInit): Headers {\n const headers = new Headers(base);\n if (overrides === undefined) {\n return headers;\n }\n for (const [name, value] of new Headers(overrides)) {\n headers.set(name, value);\n }\n return headers;\n}\n\nfunction isQueryList(value: QueryValue | readonly QueryValue[]): value is readonly QueryValue[] {\n return Array.isArray(value);\n}\n\n/**\n * Builds a query string, with the leading `?` and without it when empty.\n *\n * `null`, `undefined` and `''` are dropped rather than sent as empty\n * parameters, and an array value repeats the key — both as in the copies this\n * replaces.\n */\nfunction buildQuery(params: QueryParams): string {\n const search = new URLSearchParams();\n for (const [name, value] of Object.entries(params)) {\n if (value === undefined || value === null || value === '') {\n continue;\n }\n if (isQueryList(value)) {\n for (const entry of value) {\n if (entry !== undefined && entry !== null && entry !== '') {\n search.append(name, String(entry));\n }\n }\n continue;\n }\n search.set(name, String(value));\n }\n const encoded = search.toString();\n return encoded === '' ? '' : `?${encoded}`;\n}\n\n/**\n * Builds a client over a `fetch` implementation.\n *\n * ```ts\n * const api = createApiClient(fetch, { baseUrl: '/user' });\n * const me = await api.get<CurrentUser>('/me');\n * ```\n *\n * The `fetchFn` parameter is what makes this testable without a network and\n * swappable for an instrumented wrapper; in a browser it is the global `fetch`.\n * Memoize the client (a module constant, or `useMemo`) — `useCurrentUser`\n * deliberately does not re-fetch when a new client instance appears, but a new\n * instance per render still churns.\n */\nfunction createApiClient(fetchFn: FetchFn, options: CreateApiClientOptions = {}): ApiClient {\n const baseUrl = options.baseUrl ?? '';\n const maxErrorMessageLength = options.maxErrorMessageLength ?? MAX_ERROR_MESSAGE_LENGTH;\n\n async function request<T>(path: string, init: ApiRequestInit = {}): Promise<T> {\n const method = (init.method ?? 'GET').toUpperCase();\n const url = `${baseUrl}${path}`;\n const hasBody = init.body !== undefined;\n const headers = mergeHeaders(options.headers, init.headers);\n // Same-origin only, and no token in JavaScript: the Cloudflare Access\n // session cookie rides along under the default credentials, and there is no\n // place for a token to leak to. Both defaults yield to an explicit header\n // — a consumer that wants XML passes its own `Accept`.\n if (!headers.has('Accept')) {\n headers.set('Accept', 'application/json');\n }\n if (hasBody && !headers.has('Content-Type')) {\n headers.set('Content-Type', 'application/json');\n }\n const requestInit: RequestInit = { method, headers };\n if (options.credentials !== undefined) {\n requestInit.credentials = options.credentials;\n }\n if (hasBody) {\n requestInit.body = JSON.stringify(init.body);\n }\n if (init.signal !== undefined && init.signal !== null) {\n requestInit.signal = init.signal;\n }\n\n const context = `${method} ${url}`;\n let response: Response;\n try {\n response = await fetchFn(url, requestInit);\n } catch (cause) {\n // The transport never answered — offline, DNS, CORS, an aborted signal.\n // There is no status to report, so the failure normalizes through\n // `ServiceError.from` like any other unknown throw. A caller that cancels\n // its own request therefore sees a 500-shaped error too; the taxonomy has\n // no \"aborted\" class, and swallowing it here would hide real transport\n // failures. A caller that cancels should not surface the rejection.\n throw ServiceError.from(cause);\n }\n if (!response.ok) {\n throw await toServiceError(response);\n }\n return readJson<T>(response, context);\n }\n\n async function toServiceError(response: Response): Promise<ServiceError> {\n let text = '';\n try {\n text = await response.text();\n } catch {\n // The body could not be read at all — a reset after the headers. The\n // status is still the one true thing about the request, and the catalog\n // default message says more than anything this could invent.\n }\n const decoded = decodeErrorBody(text, response.status, maxErrorMessageLength);\n if (Object.hasOwn(HTTP_ERROR_CLASSES, response.status)) {\n const ErrorClass = HTTP_ERROR_CLASSES[response.status];\n // A `null` message leaves the catalog's default in place, which is a\n // better sentence than anything the client could invent.\n return new ErrorClass(decoded.message ?? undefined);\n }\n return new HttpStatusError(response.status, decoded.message ?? `Request failed with status ${response.status}.`, decoded.type);\n }\n\n async function readJson<T>(response: Response, context: string): Promise<T> {\n if (response.status === 204) {\n return undefined as T;\n }\n let text: string;\n try {\n text = await response.text();\n } catch (cause) {\n throw ServiceError.from(cause);\n }\n if (text.trim() === '') {\n return undefined as T;\n }\n try {\n return JSON.parse(text) as T;\n } catch {\n // A 2xx body that is not JSON is an HTML error page from a proxy. It must\n // surface as a ServiceError, not a SyntaxError, so the caller's error\n // handling has one shape to recognize.\n throw new HttpStatusError(response.status, `Malformed response body: ${context}`, null);\n }\n }\n\n return {\n request,\n get: async <T>(path: string, params?: QueryParams): Promise<T> =>\n request<T>(`${path}${params === undefined ? '' : buildQuery(params)}`),\n post: async <T>(path: string, body?: unknown): Promise<T> => request<T>(path, { method: 'POST', body }),\n put: async <T>(path: string, body?: unknown): Promise<T> => request<T>(path, { method: 'PUT', body }),\n patch: async <T>(path: string, body?: unknown): Promise<T> => request<T>(path, { method: 'PATCH', body }),\n delete: async <T>(path: string, body?: unknown): Promise<T> => request<T>(path, { method: 'DELETE', body }),\n };\n}\n\nexport { buildQuery, createApiClient, HttpStatusError, MAX_ERROR_MESSAGE_LENGTH };\nexport type { ApiClient, ApiRequestInit, CreateApiClientOptions, FetchFn, QueryParams, QueryValue };\n"],
|
|
5
|
+
"mappings": "AAAA,OACE,mBAAAA,EACA,mBAAAC,EACA,iBAAAC,EACA,kBAAAC,EACA,uBAAAC,EACA,yBAAAC,EACA,iBAAAC,EACA,uBAAAC,EACA,wBAAAC,EACA,2BAAAC,EACA,oBAAAC,EACA,gBAAAC,EACA,2BAAAC,EACA,qBAAAC,EACA,6BAAAC,MACK,mBAwHP,MAAMC,EAA2B,IAU3BC,EAAuF,CAC3F,IAAKf,EACL,IAAKY,EACL,IAAKV,EACL,IAAKG,EACL,IAAKD,EACL,IAAKH,EACL,IAAKO,EACL,IAAKD,EACL,IAAKM,EACL,IAAKJ,EACL,IAAKN,EACL,IAAKG,EACL,IAAKP,EACL,IAAKY,GAWP,MAAMK,UAAwBN,CAAY,CACxC,YAAYO,EAAgBC,EAAiBC,EAAmB,CAC9D,MAAMF,EAAQE,GAAQ,aAAaF,CAAM,GAAIC,CAAO,CACtD,EAcF,SAASE,EAAWC,EAAc,CAChC,OAAO,OAAOA,GAAU,UAAYA,EAAM,KAAI,IAAO,GAAKA,EAAQ,IACpE,CAEA,SAASC,EAASD,EAAeE,EAAiB,CAChD,OAAOF,EAAM,OAASE,EAAY,GAAGF,EAAM,MAAM,EAAGE,CAAS,CAAC,SAAMF,CACtE,CAMA,MAAMG,EAAoB,wBAQ1B,SAASC,EAAgBC,EAAaH,EAAiB,CACrD,OAAIG,EAAI,SAAW,GAAKA,EAAI,OAASH,GAAaG,EAAI,SAAS,GAAG,EACzD,GAEF,CAACF,EAAkB,KAAKE,CAAG,CACpC,CAEA,SAASC,EAAgBC,EAAkBX,EAAgBM,EAAiB,CAC1E,GAAI,OAAOK,GAAY,SAAU,CAC/B,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,GAAKD,EAAWC,CAAM,CAAC,EAAE,EACvE,KAAM,MAAUU,EAAca,IAA+Bd,EAAWC,EAAM,CAAE,OAAQ,OAAQ,KAAAa,CAAI,CAAE,EACtG,IAAK,MAAUb,EAAca,IAA+Bd,EAAWC,EAAM,CAAE,OAAQ,MAAO,KAAAa,CAAI,CAAE,EACpG,MAAO,MAAUb,EAAca,IAA+Bd,EAAWC,EAAM,CAAE,OAAQ,QAAS,KAAAa,CAAI,CAAE,EACxG,OAAQ,MAAUb,EAAca,IAA+Bd,EAAWC,EAAM,CAAE,OAAQ,SAAU,KAAAa,CAAI,CAAE,EAE9G",
|
|
6
|
+
"names": ["BadGatewayError", "BadRequestError", "ConflictError", "ForbiddenError", "InternalServerError", "MethodNotAllowedError", "NotFoundError", "NotImplementedError", "PayloadTooLargeError", "PreconditionFailedError", "RateLimitedError", "ServiceError", "ServiceUnavailableError", "UnauthorizedError", "UnsupportedMediaTypeError", "MAX_ERROR_MESSAGE_LENGTH", "HTTP_ERROR_CLASSES", "HttpStatusError", "status", "message", "type", "readString", "value", "truncate", "maxLength", "CONTROL_CHARACTER", "isProbablyProse", "raw", "decodeJsonError", "payload", "envelope", "nestedError", "decodeErrorBody", "text", "trimmed", "mergeHeaders", "base", "overrides", "headers", "name", "isQueryList", "buildQuery", "params", "search", "entry", "encoded", "createApiClient", "fetchFn", "options", "baseUrl", "maxErrorMessageLength", "request", "path", "init", "method", "url", "hasBody", "requestInit", "context", "response", "cause", "toServiceError", "readJson", "decoded", "ErrorClass", "body"]
|
|
7
|
+
}
|
package/dist/constants.js
CHANGED
|
@@ -1,49 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Timing and path constants the SPA primitives share.
|
|
3
|
-
*
|
|
4
|
-
* ## Provenance
|
|
5
|
-
*
|
|
6
|
-
* `lib/constants.ts` in **CalDAV-Bridge**, **Durable-DAV**, **Durable-DAV-Router**,
|
|
7
|
-
* **Edge-Git**, **Edge-Sonic**, **Mail-Meow**, **Mail-Otter** and
|
|
8
|
-
* **AWS-AccessBridge** — eight copies, of which only three values are shared by
|
|
9
|
-
* most:
|
|
10
|
-
*
|
|
11
|
-
* | Value | Repos |
|
|
12
|
-
* | --------------------------------- | ----- |
|
|
13
|
-
* | `NOTICE_TIMEOUT_MS = 6000` | 7 of 8 (all but AWS-AccessBridge, which has no notice bar) |
|
|
14
|
-
* | `ZERO_TRUST_AUTHENTICATION_PATH` | 7 of 8 (all but CalDAV-Bridge) |
|
|
15
|
-
* | `COPY_FEEDBACK_TIMEOUT_MS = 1500` | 5 of 8 |
|
|
16
|
-
*
|
|
17
|
-
* Everything else stayed in exactly one repo and is therefore *not* here — a
|
|
18
|
-
* constant with a single consumer is that consumer's vocabulary, not the
|
|
19
|
-
* family's. Consumers re-declaring these locally should delete them and import
|
|
20
|
-
* from `@rexezuge/web`:
|
|
21
|
-
*
|
|
22
|
-
* - `SCAN_POLL_INTERVAL_MS` (Edge-Sonic) — a library-scan poll cadence.
|
|
23
|
-
* - `FORM_HIGHLIGHT_TIMEOUT_MS` (Mail-Otter) — form highlight animation.
|
|
24
|
-
* - `OAUTH2_FEATURES` / `OAUTH2_FEATURE_SCOPES` (Mail-Otter) — provider tables.
|
|
25
|
-
* - `DEFAULT_TEAM_ID` (AWS-AccessBridge) — re-exported from its own `shared`.
|
|
26
|
-
*/
|
|
27
|
-
/**
|
|
28
|
-
* How long a notice stays on screen before it dismisses itself.
|
|
29
|
-
*
|
|
30
|
-
* Six seconds in every repo that has one: long enough to read a sentence, short
|
|
31
|
-
* enough that a stale error is not still on screen after the user has fixed it.
|
|
32
|
-
*/
|
|
33
|
-
const NOTICE_TIMEOUT_MS = 6000;
|
|
34
|
-
/**
|
|
35
|
-
* How long a "Copied" affordance stays visible after a clipboard write.
|
|
36
|
-
*/
|
|
37
|
-
const COPY_FEEDBACK_TIMEOUT_MS = 1500;
|
|
38
|
-
/**
|
|
39
|
-
* The path that is always behind Cloudflare Access.
|
|
40
|
-
*
|
|
41
|
-
* Navigating here starts the Zero Trust login flow for a caller with no valid
|
|
42
|
-
* session; after login, Access redirects back to the URL it interrupted, which
|
|
43
|
-
* is why each app also registers this path — Edge-Sonic answers it with a
|
|
44
|
-
* redirect to `/` so a returning signer-in does not land on a JSON
|
|
45
|
-
* `Exception{NotFound}` from what they were told was the app home.
|
|
46
|
-
*/
|
|
47
|
-
const ZERO_TRUST_AUTHENTICATION_PATH = '/user/';
|
|
48
|
-
export { COPY_FEEDBACK_TIMEOUT_MS, NOTICE_TIMEOUT_MS, ZERO_TRUST_AUTHENTICATION_PATH };
|
|
49
|
-
//# sourceMappingURL=constants.js.map
|
|
1
|
+
const T=6e3,_=1500,E="/user/";export{_ as COPY_FEEDBACK_TIMEOUT_MS,T as NOTICE_TIMEOUT_MS,E as ZERO_TRUST_AUTHENTICATION_PATH};
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/constants.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Timing and path constants the SPA primitives share.\n *\n * ## Provenance\n *\n * `lib/constants.ts` in **CalDAV-Bridge**, **Durable-DAV**, **Durable-DAV-Router**,\n * **Edge-Git**, **Edge-Sonic**, **Mail-Meow**, **Mail-Otter** and\n * **AWS-AccessBridge** — eight copies, of which only three values are shared by\n * most:\n *\n * | Value | Repos |\n * | --------------------------------- | ----- |\n * | `NOTICE_TIMEOUT_MS = 6000` | 7 of 8 (all but AWS-AccessBridge, which has no notice bar) |\n * | `ZERO_TRUST_AUTHENTICATION_PATH` | 7 of 8 (all but CalDAV-Bridge) |\n * | `COPY_FEEDBACK_TIMEOUT_MS = 1500` | 5 of 8 |\n *\n * Everything else stayed in exactly one repo and is therefore *not* here — a\n * constant with a single consumer is that consumer's vocabulary, not the\n * family's. Consumers re-declaring these locally should delete them and import\n * from `@rexezuge/web`:\n *\n * - `SCAN_POLL_INTERVAL_MS` (Edge-Sonic) — a library-scan poll cadence.\n * - `FORM_HIGHLIGHT_TIMEOUT_MS` (Mail-Otter) — form highlight animation.\n * - `OAUTH2_FEATURES` / `OAUTH2_FEATURE_SCOPES` (Mail-Otter) — provider tables.\n * - `DEFAULT_TEAM_ID` (AWS-AccessBridge) — re-exported from its own `shared`.\n */\n\n/**\n * How long a notice stays on screen before it dismisses itself.\n *\n * Six seconds in every repo that has one: long enough to read a sentence, short\n * enough that a stale error is not still on screen after the user has fixed it.\n */\nconst NOTICE_TIMEOUT_MS = 6000;\n\n/**\n * How long a \"Copied\" affordance stays visible after a clipboard write.\n */\nconst COPY_FEEDBACK_TIMEOUT_MS = 1500;\n\n/**\n * The path that is always behind Cloudflare Access.\n *\n * Navigating here starts the Zero Trust login flow for a caller with no valid\n * session; after login, Access redirects back to the URL it interrupted, which\n * is why each app also registers this path — Edge-Sonic answers it with a\n * redirect to `/` so a returning signer-in does not land on a JSON\n * `Exception{NotFound}` from what they were told was the app home.\n */\nconst ZERO_TRUST_AUTHENTICATION_PATH = '/user/';\n\nexport { COPY_FEEDBACK_TIMEOUT_MS, NOTICE_TIMEOUT_MS, ZERO_TRUST_AUTHENTICATION_PATH };\n"],
|
|
5
|
+
"mappings": "AAiCA,MAAMA,EAAoB,IAKpBC,EAA2B,KAW3BC,EAAiC",
|
|
6
|
+
"names": ["NOTICE_TIMEOUT_MS", "COPY_FEEDBACK_TIMEOUT_MS", "ZERO_TRUST_AUTHENTICATION_PATH"]
|
|
7
|
+
}
|