@rexezuge/web 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/LICENSE +21 -0
  2. package/dist/Badge.d.ts +42 -0
  3. package/dist/Badge.d.ts.map +1 -0
  4. package/dist/Badge.js +25 -0
  5. package/dist/Badge.js.map +1 -0
  6. package/dist/Button.d.ts +69 -0
  7. package/dist/Button.d.ts.map +1 -0
  8. package/dist/Button.js +39 -0
  9. package/dist/Button.js.map +1 -0
  10. package/dist/Card.d.ts +42 -0
  11. package/dist/Card.d.ts.map +1 -0
  12. package/dist/Card.js +42 -0
  13. package/dist/Card.js.map +1 -0
  14. package/dist/FocusInput.d.ts +32 -0
  15. package/dist/FocusInput.d.ts.map +1 -0
  16. package/dist/FocusInput.js +19 -0
  17. package/dist/FocusInput.js.map +1 -0
  18. package/dist/Input.d.ts +52 -0
  19. package/dist/Input.d.ts.map +1 -0
  20. package/dist/Input.js +49 -0
  21. package/dist/Input.js.map +1 -0
  22. package/dist/LoadingButton.d.ts +46 -0
  23. package/dist/LoadingButton.d.ts.map +1 -0
  24. package/dist/LoadingButton.js +30 -0
  25. package/dist/LoadingButton.js.map +1 -0
  26. package/dist/Pagination.d.ts +63 -0
  27. package/dist/Pagination.d.ts.map +1 -0
  28. package/dist/Pagination.js +75 -0
  29. package/dist/Pagination.js.map +1 -0
  30. package/dist/Spinner.d.ts +31 -0
  31. package/dist/Spinner.d.ts.map +1 -0
  32. package/dist/Spinner.js +14 -0
  33. package/dist/Spinner.js.map +1 -0
  34. package/dist/api.d.ts +132 -0
  35. package/dist/api.d.ts.map +1 -0
  36. package/dist/api.js +258 -0
  37. package/dist/api.js.map +1 -0
  38. package/dist/constants.d.ts +49 -0
  39. package/dist/constants.d.ts.map +1 -0
  40. package/dist/constants.js +49 -0
  41. package/dist/constants.js.map +1 -0
  42. package/dist/index.d.ts +62 -0
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +49 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/theme.d.ts +79 -0
  47. package/dist/theme.d.ts.map +1 -0
  48. package/dist/theme.js +134 -0
  49. package/dist/theme.js.map +1 -0
  50. package/dist/useCurrentUser.d.ts +67 -0
  51. package/dist/useCurrentUser.d.ts.map +1 -0
  52. package/dist/useCurrentUser.js +49 -0
  53. package/dist/useCurrentUser.js.map +1 -0
  54. package/dist/useNotice.d.ts +60 -0
  55. package/dist/useNotice.d.ts.map +1 -0
  56. package/dist/useNotice.js +34 -0
  57. package/dist/useNotice.js.map +1 -0
  58. package/dist/useSpaLanguage.d.ts +81 -0
  59. package/dist/useSpaLanguage.d.ts.map +1 -0
  60. package/dist/useSpaLanguage.js +149 -0
  61. package/dist/useSpaLanguage.js.map +1 -0
  62. package/dist/utils.d.ts +53 -0
  63. package/dist/utils.d.ts.map +1 -0
  64. package/dist/utils.js +346 -0
  65. package/dist/utils.js.map +1 -0
  66. package/package.json +51 -3
  67. package/README.md +0 -3
@@ -0,0 +1,63 @@
1
+ import type { ReactElement } from 'react';
2
+ /**
3
+ * Pager controls.
4
+ *
5
+ * ## Provenance
6
+ *
7
+ * `components/ui/Pagination.tsx` in **AWS-AccessBridge**, with the arithmetic
8
+ * (`totalPages`, `clampPage`, `pageNumbers`) that this component reached for
9
+ * across `lib/pagination.ts` and `lib/presentation.ts` inlined, because a
10
+ * consumer importing the pager should not have to import two more modules to
11
+ * understand it. The DAV repos' `VolumeFilePager` (Durable-DAV and
12
+ * Durable-DAV-Router) is the family's other pager and informs two decisions: it
13
+ * gates on the rows actually being present, and it renders nothing at all when
14
+ * the collection fits on one page.
15
+ *
16
+ * The API is normalized away from the AWS names (`currentPage`, `totalPages`,
17
+ * `onPageChange`) to `page`, `pageCount`, `onChange`. `pageCount` may be
18
+ * derived instead of passed: give `total` and `pageSize` and the pager does the
19
+ * arithmetic, which is what the DAV pager did by hand at its call site.
20
+ *
21
+ * `full` shows a window of page numbers (AWS's default); `compact` shows
22
+ * "Page X of Y" (AWS's other variant, and what the DAV pager renders). Both
23
+ * render `null` for a single page.
24
+ */
25
+ /** How many pages `total` items occupy. A non-positive page size yields 1, never `Infinity`/`NaN`. */
26
+ declare function pageCountFor(total: number, pageSize: number): number;
27
+ /** Pins `page` into `[1, pageCount]`, rounding to the first page when it cannot be read. */
28
+ declare function clampPage(page: number, pageCount: number): number;
29
+ /**
30
+ * The 1-based page numbers to show, keeping the current page as close to the
31
+ * middle of the window as the ends allow. The window is clamped against
32
+ * `windowSize` rather than a fixed `pageCount - 2`, so a non-default window
33
+ * cannot emit page numbers past the last page.
34
+ */
35
+ declare function pageWindow(currentPage: number, pageCount: number, windowSize?: number): number[];
36
+ /** Overridable text, so an i18next app is not stuck with the English defaults. */
37
+ interface PaginationLabels {
38
+ /** Prev-button accessible name / label. */
39
+ previous?: string;
40
+ /** Next-button accessible name / label. */
41
+ next?: string;
42
+ /** The "Page X of Y" summary in `compact` (and as the pager's `aria-label` in `full`). */
43
+ summary?: (page: number, pageCount: number) => string;
44
+ }
45
+ interface PaginationProps {
46
+ /** The page being displayed, 1-based. Clamped into range for rendering. */
47
+ page: number;
48
+ /** Total pages. Omit to derive it from `total` and `pageSize`. */
49
+ pageCount?: number;
50
+ /** Total item count across every page. */
51
+ total?: number;
52
+ /** Items per page. */
53
+ pageSize?: number;
54
+ /** Called with the 1-based page to move to; already clamped into range. */
55
+ onChange: (page: number) => void;
56
+ /** `full` shows page numbers, `compact` shows a summary. */
57
+ variant?: 'full' | 'compact';
58
+ labels?: PaginationLabels;
59
+ }
60
+ declare function Pagination({ page, pageCount, total, pageSize, onChange, variant, labels, }: Readonly<PaginationProps>): ReactElement | null;
61
+ export { Pagination, clampPage, pageCountFor, pageWindow };
62
+ export type { PaginationLabels, PaginationProps };
63
+ //# sourceMappingURL=Pagination.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Pagination.d.ts","sourceRoot":"","sources":["../src/Pagination.tsx"],"names":[],"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AY,GAAG,IAAI,CAqDjD;AAED,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC;AAC3D,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAAC"}
@@ -0,0 +1,75 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Button } from './Button';
3
+ import { cn } from './utils';
4
+ /**
5
+ * Pager controls.
6
+ *
7
+ * ## Provenance
8
+ *
9
+ * `components/ui/Pagination.tsx` in **AWS-AccessBridge**, with the arithmetic
10
+ * (`totalPages`, `clampPage`, `pageNumbers`) that this component reached for
11
+ * across `lib/pagination.ts` and `lib/presentation.ts` inlined, because a
12
+ * consumer importing the pager should not have to import two more modules to
13
+ * understand it. The DAV repos' `VolumeFilePager` (Durable-DAV and
14
+ * Durable-DAV-Router) is the family's other pager and informs two decisions: it
15
+ * gates on the rows actually being present, and it renders nothing at all when
16
+ * the collection fits on one page.
17
+ *
18
+ * The API is normalized away from the AWS names (`currentPage`, `totalPages`,
19
+ * `onPageChange`) to `page`, `pageCount`, `onChange`. `pageCount` may be
20
+ * derived instead of passed: give `total` and `pageSize` and the pager does the
21
+ * arithmetic, which is what the DAV pager did by hand at its call site.
22
+ *
23
+ * `full` shows a window of page numbers (AWS's default); `compact` shows
24
+ * "Page X of Y" (AWS's other variant, and what the DAV pager renders). Both
25
+ * render `null` for a single page.
26
+ */
27
+ /** How many pages `total` items occupy. A non-positive page size yields 1, never `Infinity`/`NaN`. */
28
+ function pageCountFor(total, pageSize) {
29
+ if (!Number.isFinite(total) || !Number.isFinite(pageSize) || pageSize <= 0 || total <= 0) {
30
+ return 1;
31
+ }
32
+ return Math.ceil(total / pageSize);
33
+ }
34
+ /** Pins `page` into `[1, pageCount]`, rounding to the first page when it cannot be read. */
35
+ function clampPage(page, pageCount) {
36
+ const upper = Math.max(1, Math.trunc(Number.isFinite(pageCount) ? pageCount : 1));
37
+ const wanted = Number.isFinite(page) ? Math.trunc(page) : 1;
38
+ return Math.min(upper, Math.max(1, wanted));
39
+ }
40
+ /**
41
+ * The 1-based page numbers to show, keeping the current page as close to the
42
+ * middle of the window as the ends allow. The window is clamped against
43
+ * `windowSize` rather than a fixed `pageCount - 2`, so a non-default window
44
+ * cannot emit page numbers past the last page.
45
+ */
46
+ function pageWindow(currentPage, pageCount, windowSize = 5) {
47
+ const count = Math.min(windowSize, pageCount);
48
+ if (count <= 0) {
49
+ return [];
50
+ }
51
+ const start = Math.max(1, Math.min(currentPage - Math.floor(windowSize / 2), pageCount - count + 1));
52
+ return Array.from({ length: count }, (_, index) => start + index);
53
+ }
54
+ function Pagination({ page, pageCount, total, pageSize, onChange, variant = 'full', labels = {}, }) {
55
+ const derivedPageCount = pageCount ?? (total !== undefined && pageSize !== undefined ? pageCountFor(total, pageSize) : 1);
56
+ const pages = Math.max(1, Math.trunc(Number.isFinite(derivedPageCount) ? derivedPageCount : 1));
57
+ const current = clampPage(page, pages);
58
+ const previousLabel = labels.previous ?? 'Previous';
59
+ const nextLabel = labels.next ?? 'Next';
60
+ const summaryLabel = labels.summary ?? ((page, count) => `Page ${page} of ${count}`);
61
+ // Nothing to page: a single-page list shows no pager rather than a disabled one.
62
+ if (pages <= 1) {
63
+ return null;
64
+ }
65
+ const step = (next) => {
66
+ const target = clampPage(next, pages);
67
+ if (target !== current) {
68
+ onChange(target);
69
+ }
70
+ };
71
+ const summary = (_jsx("span", { className: "text-xs text-[var(--color-text-muted)] tabular-nums", children: summaryLabel(current, pages) }));
72
+ return (_jsxs("nav", { className: "flex flex-wrap items-center gap-2", "aria-label": summaryLabel(current, pages), children: [_jsx(Button, { variant: "secondary", size: "sm", disabled: current <= 1, onClick: () => step(current - 1), "aria-label": previousLabel, children: previousLabel }), variant === 'compact' ? (summary) : (_jsx("div", { className: "flex items-center gap-1", children: pageWindow(current, pages).map((pageNumber) => (_jsx(Button, { variant: "secondary", size: "sm", className: cn(pageNumber === current && 'bg-[var(--color-accent)] text-[#0d1008]'), "aria-current": pageNumber === current ? 'page' : undefined, onClick: () => step(pageNumber), children: pageNumber }, pageNumber))) })), _jsx(Button, { variant: "secondary", size: "sm", disabled: current >= pages, onClick: () => step(current + 1), "aria-label": nextLabel, children: nextLabel })] }));
73
+ }
74
+ export { Pagination, clampPage, pageCountFor, pageWindow };
75
+ //# sourceMappingURL=Pagination.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Pagination.js","sourceRoot":"","sources":["../src/Pagination.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,sGAAsG;AACtG,SAAS,YAAY,CAAC,KAAa,EAAE,QAAgB;IACnD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,QAAQ,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QACzF,OAAO,CAAC,CAAC;IACX,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,CAAC;AACrC,CAAC;AAED,4FAA4F;AAC5F,SAAS,SAAS,CAAC,IAAY,EAAE,SAAiB;IAChD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClF,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5D,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IA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EACnB,IAAI,EAAC,IAAI,EACT,SAAS,EAAE,EAAE,CAAC,UAAU,KAAK,OAAO,IAAI,yCAAyC,CAAC,kBACpE,UAAU,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,EACzD,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,YAE9B,UAAU,IAPN,UAAU,CAQR,CACV,CAAC,GACE,CACP,EACD,KAAC,MAAM,IAAC,OAAO,EAAC,WAAW,EAAC,IAAI,EAAC,IAAI,EAAC,QAAQ,EAAE,OAAO,IAAI,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,gBAAc,SAAS,YACtH,SAAS,GACH,IACL,CACP,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { CSSProperties } from 'react';
2
+ /**
3
+ * The loading ring.
4
+ *
5
+ * ## Provenance
6
+ *
7
+ * `components/ui/Spinner.tsx` in **AWS-AccessBridge** — the only named spinner
8
+ * in the family. The other repos inline the same ring into their buttons as a
9
+ * `Loader2` icon from `lucide-react`, which the kit does not depend on, so this
10
+ * component *is* the kit's spinner vocabulary: `Button` and `LoadingButton`
11
+ * render it while busy.
12
+ *
13
+ * The ring is a bordered circle with one transparent edge, animated by
14
+ * Tailwind's `animate-spin` (present in every consuming app's stylesheet).
15
+ */
16
+ interface SpinnerProps {
17
+ /** Diameter in pixels. */
18
+ size?: number;
19
+ /** Border colour; `currentColor` inherits from the surrounding text. */
20
+ color?: string;
21
+ /** Optional caption under the ring. */
22
+ label?: string;
23
+ /** Padding around the whole block, as a CSS shorthand. */
24
+ padding?: string;
25
+ /** Extra styles for the outer wrapper. */
26
+ style?: CSSProperties;
27
+ }
28
+ declare function Spinner({ size, color, label, padding, style, }: Readonly<SpinnerProps>): React.JSX.Element;
29
+ export { Spinner };
30
+ export type { SpinnerProps };
31
+ //# sourceMappingURL=Spinner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Spinner.d.ts","sourceRoot":"","sources":["../src/Spinner.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAG3C;;;;;;;;;;;;;GAaG;AAEH,UAAU,YAAY;IACpB,0BAA0B;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uCAAuC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0CAA0C;IAC1C,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB;AAED,iBAAS,OAAO,CAAC,EACf,IAAS,EACT,KAAyB,EACzB,KAAK,EACL,OAAkB,EAClB,KAAK,GACN,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAkB5C;AAED,OAAO,EAAE,OAAO,EAAE,CAAC;AACnB,YAAY,EAAE,YAAY,EAAE,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { theme } from './theme';
3
+ function Spinner({ size = 24, color = theme.spinnerBlue, label, padding = '16px 0', style, }) {
4
+ return (_jsxs("div", { style: { textAlign: 'center', padding, ...style }, children: [_jsx("div", { className: "animate-spin", "aria-hidden": "true", style: {
5
+ width: `${size}px`,
6
+ height: `${size}px`,
7
+ borderRadius: '50%',
8
+ border: `2px solid ${color}`,
9
+ borderTopColor: 'transparent',
10
+ margin: '0 auto',
11
+ } }), label ? _jsx("p", { style: { color: '#9ca3af', marginTop: '12px' }, children: label }) : null] }));
12
+ }
13
+ export { Spinner };
14
+ //# sourceMappingURL=Spinner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Spinner.js","sourceRoot":"","sources":["../src/Spinner.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AA8BhC,SAAS,OAAO,CAAC,EACf,IAAI,GAAG,EAAE,EACT,KAAK,GAAG,KAAK,CAAC,WAAW,EACzB,KAAK,EACL,OAAO,GAAG,QAAQ,EAClB,KAAK,GACkB;IACvB,OAAO,CACL,eAAK,KAAK,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,aACpD,cACE,SAAS,EAAC,cAAc,iBACZ,MAAM,EAClB,KAAK,EAAE;oBACL,KAAK,EAAE,GAAG,IAAI,IAAI;oBAClB,MAAM,EAAE,GAAG,IAAI,IAAI;oBACnB,YAAY,EAAE,KAAK;oBACnB,MAAM,EAAE,aAAa,KAAK,EAAE;oBAC5B,cAAc,EAAE,aAAa;oBAC7B,MAAM,EAAE,QAAQ;iBACjB,GACD,EACD,KAAK,CAAC,CAAC,CAAC,YAAG,KAAK,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,YAAG,KAAK,GAAK,CAAC,CAAC,CAAC,IAAI,IAC1E,CACP,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
package/dist/api.d.ts ADDED
@@ -0,0 +1,132 @@
1
+ import { ServiceError } from '@rexezuge/errors';
2
+ /**
3
+ * The SPA's request path.
4
+ *
5
+ * ## Provenance
6
+ *
7
+ * `lib/api.ts` in **CalDAV-Bridge**, **Durable-DAV**, **Durable-DAV-Router**,
8
+ * **Edge-Git**, **Edge-Sonic**, **Mail-Otter** and **AWS-AccessBridge** — seven
9
+ * copies that all drift on the same three decisions, settled here as follows.
10
+ *
11
+ * **1. Error model.** Six of the seven define a private `BackendError`
12
+ * (`{ message, errorType, status }`) and hand-roll the status→branch mapping at
13
+ * every call site; AWS defines `ApiError` (`{ status, message }`) plus an
14
+ * `ApiResult{ok,status,data,error}` shape that its own guide records as
15
+ * abandoned — every admin tab bypassed it, which is how nine of its seventeen
16
+ * functions ended up with no caller. The kit replaces both with the family
17
+ * taxonomy: every rejection is a `ServiceError`, so `error.status`,
18
+ * `error.type`, `error.retryable` and `instanceof ServiceError` are available
19
+ * without a per-repo error class, and `ServiceError.from` covers the
20
+ * transport-level failures the private classes swallowed.
21
+ *
22
+ * **2. Error body decoding.** Converged from the three variants that exist:
23
+ *
24
+ * - The **AWS envelope** `{ Exception: { Type, Message } }`, read first in all
25
+ * copies.
26
+ * - The **legacy** `{ error, message }` shape, where Durable-DAV also reads a
27
+ * string `error` as the *type* — otherwise a legacy body produced a correct
28
+ * message and a `null` type, which sent it through the generic fallback and
29
+ * lost the specific wording.
30
+ * - **Edge-Sonic's prose test** for a non-JSON body: an Access login page or a
31
+ * proxy's HTML error page is not a message an operator can act on, so markup
32
+ * is reported as absent rather than quoted into a notice bar. Short,
33
+ * single-line, tag-free text *is* surfaced, truncated.
34
+ * - **Truncation** at 500 characters, from every copy that has one: an
35
+ * unbounded error string from a proxy page is a rendering hazard.
36
+ * - **`text()` then `JSON.parse`, never `json()` with a `text()` fallback** —
37
+ * Edge-Sonic's comment records why the old shape cannot work: `json()`
38
+ * consumes the body stream before it fails to parse, so the second read
39
+ * returned `''` and the "not JSON" branch was unreachable.
40
+ *
41
+ * **3. Empty bodies.** Durable-DAV's fix is the one kept: a `204`, and an empty
42
+ * body from an edge error page, resolve to `undefined` rather than throwing a
43
+ * `SyntaxError` — which used to report a generic failure for an operation that
44
+ * had actually succeeded (credential revoke). AWS-AccessBridge resolved the same
45
+ * case to `{}`; `undefined` is the honest answer for "there is no body".
46
+ *
47
+ * ## What is deliberately not here
48
+ *
49
+ * - **The D1 session bookmark** (`x-d1-bookmark`, CalDAV-Bridge and
50
+ * Mail-Otter). It is module state threading a D1 replica pin through every
51
+ * `/user/*` request; the kit has no D1 client, so the header policy stays
52
+ * with the repos that own the binding.
53
+ * - **`apiAuthedFirst`** (Edge-Git) — a public-fallback policy with
54
+ * fail-closed 401/403/404 handling, specific to that app's two-surface API.
55
+ * - **WebDAV `readDav`** (Durable-DAV, Durable-DAV-Router) — it accepts `207
56
+ * Multi-Status` as success, which is a WebDAV rule, not an HTTP rule. A
57
+ * consumer needing XML calls `client.request` and reads `response.text()`
58
+ * itself.
59
+ * - **The `/user` base path.** Edge-Sonic bakes it in; the others pass full
60
+ * paths. `baseUrl` is an option here, defaulting to empty, so the caller
61
+ * decides.
62
+ */
63
+ /** The `fetch` shape a client is built on: same-origin by default, no token in JavaScript. */
64
+ type FetchFn = (input: string, init?: RequestInit) => Promise<Response>;
65
+ /** A query-string value. `null`/`undefined`/`''` are omitted, as in every copy. */
66
+ type QueryValue = string | number | boolean | null | undefined;
67
+ type QueryParams = Record<string, QueryValue | readonly QueryValue[]>;
68
+ interface ApiRequestInit {
69
+ method?: string;
70
+ /** Serialized as JSON with a matching `Content-Type`. */
71
+ body?: unknown;
72
+ headers?: HeadersInit;
73
+ signal?: AbortSignal | null;
74
+ }
75
+ interface CreateApiClientOptions {
76
+ /** Prepended to every path; `''` (the default) sends the path as given. */
77
+ baseUrl?: string;
78
+ /** Headers merged into every request; a per-request header wins over these. */
79
+ headers?: HeadersInit;
80
+ /** Passed through to `fetch`; omitted leaves the browser default. */
81
+ credentials?: RequestCredentials;
82
+ /** Truncation limit for a server-provided error message. Defaults to 500. */
83
+ maxErrorMessageLength?: number;
84
+ }
85
+ interface ApiClient {
86
+ /** One request. Throws a `ServiceError`; resolves to the parsed JSON body. */
87
+ request<T>(path: string, init?: ApiRequestInit): Promise<T>;
88
+ get<T>(path: string, params?: QueryParams): Promise<T>;
89
+ post<T>(path: string, body?: unknown): Promise<T>;
90
+ put<T>(path: string, body?: unknown): Promise<T>;
91
+ patch<T>(path: string, body?: unknown): Promise<T>;
92
+ delete<T>(path: string, body?: unknown): Promise<T>;
93
+ }
94
+ /** Default truncation for a server-provided message. */
95
+ declare const MAX_ERROR_MESSAGE_LENGTH = 500;
96
+ /**
97
+ * A failure whose only fact is its HTTP status: a status the catalog has no
98
+ * class for (451, 418, a proxy's own 5xx), or a 2xx body that is not JSON.
99
+ *
100
+ * It exists so the thrown value is *always* a `ServiceError` — a caller
101
+ * branching on `instanceof ServiceError` does not have to know which statuses
102
+ * the catalog happens to cover.
103
+ */
104
+ declare class HttpStatusError extends ServiceError {
105
+ constructor(status: number, message: string, type: string | null);
106
+ }
107
+ /**
108
+ * Builds a query string, with the leading `?` and without it when empty.
109
+ *
110
+ * `null`, `undefined` and `''` are dropped rather than sent as empty
111
+ * parameters, and an array value repeats the key — both as in the copies this
112
+ * replaces.
113
+ */
114
+ declare function buildQuery(params: QueryParams): string;
115
+ /**
116
+ * Builds a client over a `fetch` implementation.
117
+ *
118
+ * ```ts
119
+ * const api = createApiClient(fetch, { baseUrl: '/user' });
120
+ * const me = await api.get<CurrentUser>('/me');
121
+ * ```
122
+ *
123
+ * The `fetchFn` parameter is what makes this testable without a network and
124
+ * swappable for an instrumented wrapper; in a browser it is the global `fetch`.
125
+ * Memoize the client (a module constant, or `useMemo`) — `useCurrentUser`
126
+ * deliberately does not re-fetch when a new client instance appears, but a new
127
+ * instance per render still churns.
128
+ */
129
+ declare function createApiClient(fetchFn: FetchFn, options?: CreateApiClientOptions): ApiClient;
130
+ export { buildQuery, createApiClient, HttpStatusError, MAX_ERROR_MESSAGE_LENGTH };
131
+ export type { ApiClient, ApiRequestInit, CreateApiClientOptions, FetchFn, QueryParams, QueryValue };
132
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +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,8FAA8F;AAC9F,KAAK,OAAO,GAAG,CAAC,KAAK,EAAE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AAM,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,wDAAwD;AACxD,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;AAqGD;;;;;;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 ADDED
@@ -0,0 +1,258 @@
1
+ import { BadGatewayError, BadRequestError, ConflictError, ForbiddenError, InternalServerError, MethodNotAllowedError, NotFoundError, NotImplementedError, PayloadTooLargeError, PreconditionFailedError, RateLimitedError, ServiceError, ServiceUnavailableError, UnauthorizedError, UnsupportedMediaTypeError, } from '@rexezuge/errors';
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
@@ -0,0 +1 @@
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;;;;;;;GAOG;AACH,MAAM,eAAgB,SAAQ,YAAY;IACxC,YAAY,MAAc,EAAE,OAAe,EAAE,IAAmB;QAC9D,KAAK,CAAC,MAAM,EAAE,IAAI,IAAI,aAAa,MAAM,EAAE,EAAE,OAA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