singularity-core 0.15.3 → 0.17.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/README.md CHANGED
@@ -15,73 +15,4 @@ export const { login, logout, getValidSession, hasUserPermission } =
15
15
  createCookieSession({ client: fetchAuthServerClient, cookiePrefix: "filion" });
16
16
  ```
17
17
 
18
- See [AGENTS.md](./AGENTS.md) for the subpaths and the rules for adding code.
19
-
20
- ## TODO
21
-
22
- Fix on `main` and release as 0.9.0 (the `feature/fragments` tarballs already use
23
- up to 0.8.7), then rebase `feature/fragments`.
24
-
25
- ### High value
26
-
27
- - [x] Logout can end the user's sessions on every device. `endApiSession`
28
- (`src/auth/server.ts:156`) sends `refreshToken: null` when the refresh cookie
29
- is missing, and `?? refreshToken` (`:241`) keeps an `EMPTY_GUID` from a
30
- refresh. Treat `EMPTY_GUID` as no token everywhere and skip the API logout
31
- when there is no real refresh token.
32
- - [x] Temporary API errors sign users out. A refresh that returns 429 or 5xx
33
- clears the cookies (`src/auth/server.ts:232-235`), and the `catch` (`:243`)
34
- returns null even while the access token is still valid. Clear only on
35
- 400/401/403 and keep the current token while `secondsUntilExpiry > 0`. Add
36
- tests for both.
37
- - [x] Cookie roles are decoded, not verified (`src/auth/server.ts:70-93`). Keep it
38
- decode-only, but document here and in `docs/projects/core.md` that roles are
39
- a UI hint and the API is the real gate. Audit that every admin and blog
40
- server function behind `requirePermission` calls the API with the bearer
41
- token.
42
- - [x] CSP (`src/security/index.ts:59-76`) lacks `base-uri 'self'`,
43
- `object-src 'none'` and `form-action 'self'`. Widen `CspDirective` to allow
44
- `frame-src` and `worker-src`. In the dev policy, browsers ignore
45
- `'unsafe-inline'` next to a nonce or `'strict-dynamic'`.
46
- - [x] `useListSearch` (`src/paging/react.ts:14-26`) reapplies the old text after
47
- Back or a link clears the search. Re-sync `text` when `current` changes from
48
- outside (track the last applied value in a ref).
49
- - [x] `build` doesn't clean `dist/`, so `dist/fragments` from the other branch
50
- would ship in the next pack. Delete `dist` before `tsc`.
51
- - [x] `formatDate` (`src/format/index.ts:1-14`) uses local getters, so server
52
- (UTC) and browser (Stockholm) disagree near midnight, and invalid input gives
53
- `NaN-NaN-NaN`. Use `Intl.DateTimeFormat` with a `timeZone` and return `""`
54
- for invalid dates.
55
-
56
- ### Nice to have
57
-
58
- - [x] `formatTimeSpan` drops days (`src/format/index.ts:32-34`), and the "days
59
- included" test expects the wrong value.
60
- - [x] The theme client hint `Sec-CH-Prefers-Color-Scheme` (`src/theme/server.ts:22`)
61
- is never requested with `Accept-CH`. The server renders "system" as light
62
- while `ThemeProvider` treats it as dark before mount
63
- (`src/theme/react.tsx:89`). Make the two defaults agree.
64
- - [x] `ThemeProvider` reads and writes `localStorage` without a guard
65
- (`src/theme/react.tsx:98,128`). `buildThemeBootstrapScript`
66
- (`src/theme/index.ts:63`) puts keys into a JS string and a RegExp unescaped;
67
- use `JSON.stringify` and escape the regex.
68
- - [x] `proxyEventStream` (`src/api/server.ts:89-94`) doesn't catch a failed fetch.
69
- Return 502 with `failureMessage`.
70
- - [x] Small fixes: `pageSearchSchema` throws on `?page=abc` (add
71
- `.catch(undefined)`); `parsePage` accepts `take: 0` (use
72
- `.int().positive()`); `na` returns one shared fallback array; `IMAGE_WIDTHS`
73
- is mutable; `new URL(src)` throws on relative `/i/` URLs
74
- (`src/images/index.ts:57,82`); `slugify` drops ø/æ/ß/ł.
75
- - [x] `getValidSession` isn't cached per request, so beforeLoad, middleware and a
76
- loader can each refresh. Make cookie `secure` an option instead of reading
77
- `NODE_ENV`.
78
- - [x] `engines` pins Node 25, which reached end of life in June 2026. Allow 24 LTS
79
- and 26.
80
- - [x] Add `.gitattributes` (`* text=auto eol=lf`). CRLF in `package.json` is why
81
- `biome check` fails.
82
- - [x] Add a `check` script that only reports and a `verify` script (typecheck,
83
- check, test). Add `"./package.json"` to `exports`.
84
- - [x] No tests for `http` or `router/react`.
85
- - [x] Docs drift: `AGENTS.md` mentions `pnpm openapi-types`, which isn't in
86
- `package.json`; it describes both tarballs and publishing without saying
87
- which is current. This README names 5 of the 13 areas.
18
+ See [AGENTS.md](./AGENTS.md) for the subpaths and the rules for adding code. Open fixes are in [IMPROVEMENTS.md](./IMPROVEMENTS.md).
@@ -30,6 +30,14 @@ export declare function filionTransformer(src: string | URL, operations: {
30
30
  * constrained one only those up to twice its display width.
31
31
  */
32
32
  export declare function getImageBreakpoints(width: number | undefined, layout: string): number[];
33
+ /**
34
+ * Starts loading a full-width Filion image, so the page about to show it finds
35
+ * it ready. The srcset and sizes are those of a `fullWidth` image, which makes
36
+ * the browser pick the same file. Resolves once the image is decoded, when it
37
+ * fails, or after `timeoutMs`, whichever comes first. Does nothing on the
38
+ * server or for any other URL.
39
+ */
40
+ export declare function preloadFullWidthImage(src: string, timeoutMs?: number): Promise<void>;
33
41
  /** A focal point as fractions of the image, 0..1 from the top left. */
34
42
  export type ImageFocus = {
35
43
  x: number;
@@ -94,6 +94,25 @@ export function getImageBreakpoints(width, layout) {
94
94
  const max = snapWidth(width * 2);
95
95
  return IMAGE_WIDTHS.filter((candidate) => candidate <= max);
96
96
  }
97
+ /**
98
+ * Starts loading a full-width Filion image, so the page about to show it finds
99
+ * it ready. The srcset and sizes are those of a `fullWidth` image, which makes
100
+ * the browser pick the same file. Resolves once the image is decoded, when it
101
+ * fails, or after `timeoutMs`, whichever comes first. Does nothing on the
102
+ * server or for any other URL.
103
+ */
104
+ export async function preloadFullWidthImage(src, timeoutMs = 300) {
105
+ if (typeof document === "undefined" || !isFilionImage(src))
106
+ return;
107
+ const image = new Image();
108
+ image.sizes = "100vw";
109
+ image.srcset = IMAGE_WIDTHS.map((width) => `${withImageSize(src, width)} ${width}w`).join(", ");
110
+ image.src = src;
111
+ await Promise.race([
112
+ image.decode().catch(() => undefined),
113
+ new Promise((resolve) => setTimeout(resolve, timeoutMs)),
114
+ ]);
115
+ }
97
116
  /** Converts a normalized focal point to a CSS object-position value. */
98
117
  export function getObjectPosition(focus) {
99
118
  return `${focus.x * 100}% ${focus.y * 100}%`;
@@ -1,4 +1,5 @@
1
1
  import { type StaticDataRouteOption } from "@tanstack/react-router";
2
+ export { pageViewTransition } from "./view-transition.js";
2
3
  /**
3
4
  * `staticData[key]` of the deepest matched route that sets it, so a layout
4
5
  * route can act on what the page under it declares. The apps use it for the
@@ -1,5 +1,6 @@
1
1
  import { useMatches } from "@tanstack/react-router";
2
2
  import { deepestStaticData } from "./static-data.js";
3
+ export { pageViewTransition } from "./view-transition.js";
3
4
  /**
4
5
  * `staticData[key]` of the deepest matched route that sets it, so a layout
5
6
  * route can act on what the page under it declares. The apps use it for the
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The apps' `defaultViewTransition`: a change of path animates, a change of
3
+ * only the search or hash does not, so filters, search and paging stay still.
4
+ * The router default also covers back and forward, which a `Link` prop cannot.
5
+ *
6
+ * A browser that has `startViewTransition` but no transition types never
7
+ * calls `types`, so there a filter change fades too.
8
+ */
9
+ export declare const pageViewTransition: {
10
+ types: ({ pathChanged }: {
11
+ pathChanged: boolean;
12
+ }) => string[] | false;
13
+ };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The apps' `defaultViewTransition`: a change of path animates, a change of
3
+ * only the search or hash does not, so filters, search and paging stay still.
4
+ * The router default also covers back and forward, which a `Link` prop cannot.
5
+ *
6
+ * A browser that has `startViewTransition` but no transition types never
7
+ * calls `types`, so there a filter change fades too.
8
+ */
9
+ export const pageViewTransition = {
10
+ types: ({ pathChanged }) => pathChanged ? [] : false,
11
+ };
package/package.json CHANGED
@@ -1,154 +1,157 @@
1
1
  {
2
- "name": "singularity-core",
3
- "version": "0.15.3",
4
- "description": "Shared non-UI code for Singularity TanStack Start apps: auth sessions, API client middleware, API schemas, paging, route data, images, formatting, HTTP helpers, theme, cookie notice, SEO, security headers and telemetry.",
5
- "type": "module",
6
- "author": "Filip",
7
- "license": "MIT",
8
- "files": [
9
- "dist",
10
- "config"
11
- ],
12
- "sideEffects": [
13
- "./dist/security/zod-jitless.js"
14
- ],
15
- "engines": {
16
- "node": ">=26.0.0 <27.0.0",
17
- "pnpm": ">=12.0.0 <13.0.0"
18
- },
19
- "exports": {
20
- "./auth": {
21
- "types": "./dist/auth/index.d.ts",
22
- "import": "./dist/auth/index.js"
23
- },
24
- "./auth/server": {
25
- "types": "./dist/auth/server.d.ts",
26
- "import": "./dist/auth/server.js"
27
- },
28
- "./api": {
29
- "types": "./dist/api/index.d.ts",
30
- "import": "./dist/api/index.js"
31
- },
32
- "./api/server": {
33
- "types": "./dist/api/server.d.ts",
34
- "import": "./dist/api/server.js"
35
- },
36
- "./paging": {
37
- "types": "./dist/paging/index.d.ts",
38
- "import": "./dist/paging/index.js"
39
- },
40
- "./paging/react": {
41
- "types": "./dist/paging/react.d.ts",
42
- "import": "./dist/paging/react.js"
43
- },
44
- "./router/react": {
45
- "types": "./dist/router/react.d.ts",
46
- "import": "./dist/router/react.js"
47
- },
48
- "./cookie-notice/server": {
49
- "types": "./dist/cookie-notice/server.d.ts",
50
- "import": "./dist/cookie-notice/server.js"
51
- },
52
- "./theme": {
53
- "types": "./dist/theme/index.d.ts",
54
- "import": "./dist/theme/index.js"
55
- },
56
- "./theme/server": {
57
- "types": "./dist/theme/server.d.ts",
58
- "import": "./dist/theme/server.js"
59
- },
60
- "./theme/react": {
61
- "types": "./dist/theme/react.d.ts",
62
- "import": "./dist/theme/react.js"
63
- },
64
- "./schema": {
65
- "types": "./dist/schema/index.d.ts",
66
- "import": "./dist/schema/index.js"
67
- },
68
- "./seo": {
69
- "types": "./dist/seo/index.d.ts",
70
- "import": "./dist/seo/index.js"
71
- },
72
- "./security": {
73
- "types": "./dist/security/index.d.ts",
74
- "import": "./dist/security/index.js"
75
- },
76
- "./security/zod-jitless": {
77
- "types": "./dist/security/zod-jitless.d.ts",
78
- "import": "./dist/security/zod-jitless.js"
79
- },
80
- "./telemetry": {
81
- "types": "./dist/telemetry/index.d.ts",
82
- "import": "./dist/telemetry/index.js"
83
- },
84
- "./images": {
85
- "types": "./dist/images/index.d.ts",
86
- "import": "./dist/images/index.js"
87
- },
88
- "./format": {
89
- "types": "./dist/format/index.d.ts",
90
- "import": "./dist/format/index.js"
91
- },
92
- "./http": {
93
- "types": "./dist/http/index.d.ts",
94
- "import": "./dist/http/index.js"
95
- },
96
- "./biome": "./config/biome-app.json",
97
- "./package.json": "./package.json"
98
- },
99
- "peerDependencies": {
100
- "@tanstack/react-router": "^1.170.0",
101
- "@tanstack/react-start": "^1.168.0",
102
- "jose": "^6.0.0",
103
- "openapi-fetch": "^0.17.0",
104
- "react": "^19.0.0",
105
- "zod": "^4.0.0"
106
- },
107
- "peerDependenciesMeta": {
108
- "@tanstack/react-router": {
109
- "optional": true
110
- },
111
- "@tanstack/react-start": {
112
- "optional": true
113
- },
114
- "jose": {
115
- "optional": true
116
- },
117
- "openapi-fetch": {
118
- "optional": true
119
- },
120
- "react": {
121
- "optional": true
122
- }
123
- },
124
- "devDependencies": {
125
- "@biomejs/biome": "2.5.15",
126
- "@tanstack/react-router": "1.170.46",
127
- "@tanstack/react-start": "1.169.4",
128
- "@types/node": "26.6.6",
129
- "@types/react": "19.3.0",
130
- "@types/react-dom": "19.3.0",
131
- "happy-dom": "20.14.6",
132
- "jose": "6.2.13",
133
- "openapi-fetch": "0.17.0",
134
- "openapi-typescript": "7.13.0",
135
- "react": "19.3.1",
136
- "react-dom": "19.3.1",
137
- "typescript": "6.0.3",
138
- "vitest": "5.0.5",
139
- "zod": "4.6.7"
140
- },
141
- "scripts": {
142
- "build": "node -e \"fs.rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.build.json",
143
- "typecheck": "tsc --noEmit",
144
- "test": "vitest run",
145
- "test:watch": "vitest",
146
- "openapi-dev-types": "openapi-typescript http://localhost:5268/swagger/v1/swagger.json -o ./src/api/v1.ts --alphabetize --default-non-nullable --enum-values",
147
- "openapi-types": "openapi-typescript https://api.filion.se/swagger/v1/swagger.json -o ./src/api/v1.ts --alphabetize --default-non-nullable --enum-values",
148
- "check": "biome check",
149
- "verify": "pnpm run typecheck && pnpm run check && pnpm run test",
150
- "biome:check": "biome check --write",
151
- "biome:lint": "biome lint --fix",
152
- "biome:format": "biome format --write"
153
- }
154
- }
2
+ "name": "singularity-core",
3
+ "version": "0.17.0",
4
+ "description": "Shared non-UI code for Singularity TanStack Start apps: auth sessions, API client middleware, API schemas, paging, route data, images, formatting, HTTP helpers, theme, cookie notice, SEO, security headers and telemetry.",
5
+ "type": "module",
6
+ "author": "Filip",
7
+ "license": "MIT",
8
+ "files": [
9
+ "dist",
10
+ "config"
11
+ ],
12
+ "sideEffects": [
13
+ "./dist/security/zod-jitless.js"
14
+ ],
15
+ "packageManager": "pnpm@12.3.4",
16
+ "engines": {
17
+ "node": ">=26.0.0 <27.0.0",
18
+ "pnpm": ">=12.0.0 <13.0.0"
19
+ },
20
+ "exports": {
21
+ "./auth": {
22
+ "types": "./dist/auth/index.d.ts",
23
+ "import": "./dist/auth/index.js"
24
+ },
25
+ "./auth/server": {
26
+ "types": "./dist/auth/server.d.ts",
27
+ "import": "./dist/auth/server.js"
28
+ },
29
+ "./api": {
30
+ "types": "./dist/api/index.d.ts",
31
+ "import": "./dist/api/index.js"
32
+ },
33
+ "./api/server": {
34
+ "types": "./dist/api/server.d.ts",
35
+ "import": "./dist/api/server.js"
36
+ },
37
+ "./paging": {
38
+ "types": "./dist/paging/index.d.ts",
39
+ "import": "./dist/paging/index.js"
40
+ },
41
+ "./paging/react": {
42
+ "types": "./dist/paging/react.d.ts",
43
+ "import": "./dist/paging/react.js"
44
+ },
45
+ "./router/react": {
46
+ "types": "./dist/router/react.d.ts",
47
+ "import": "./dist/router/react.js"
48
+ },
49
+ "./cookie-notice/server": {
50
+ "types": "./dist/cookie-notice/server.d.ts",
51
+ "import": "./dist/cookie-notice/server.js"
52
+ },
53
+ "./theme": {
54
+ "types": "./dist/theme/index.d.ts",
55
+ "import": "./dist/theme/index.js"
56
+ },
57
+ "./theme/server": {
58
+ "types": "./dist/theme/server.d.ts",
59
+ "import": "./dist/theme/server.js"
60
+ },
61
+ "./theme/react": {
62
+ "types": "./dist/theme/react.d.ts",
63
+ "import": "./dist/theme/react.js"
64
+ },
65
+ "./schema": {
66
+ "types": "./dist/schema/index.d.ts",
67
+ "import": "./dist/schema/index.js"
68
+ },
69
+ "./seo": {
70
+ "types": "./dist/seo/index.d.ts",
71
+ "import": "./dist/seo/index.js"
72
+ },
73
+ "./security": {
74
+ "types": "./dist/security/index.d.ts",
75
+ "import": "./dist/security/index.js"
76
+ },
77
+ "./security/zod-jitless": {
78
+ "types": "./dist/security/zod-jitless.d.ts",
79
+ "import": "./dist/security/zod-jitless.js"
80
+ },
81
+ "./telemetry": {
82
+ "types": "./dist/telemetry/index.d.ts",
83
+ "import": "./dist/telemetry/index.js"
84
+ },
85
+ "./images": {
86
+ "types": "./dist/images/index.d.ts",
87
+ "import": "./dist/images/index.js"
88
+ },
89
+ "./format": {
90
+ "types": "./dist/format/index.d.ts",
91
+ "import": "./dist/format/index.js"
92
+ },
93
+ "./http": {
94
+ "types": "./dist/http/index.d.ts",
95
+ "import": "./dist/http/index.js"
96
+ },
97
+ "./biome": "./config/biome-app.json",
98
+ "./package.json": "./package.json"
99
+ },
100
+ "scripts": {
101
+ "build": "node -e \"fs.rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.build.json",
102
+ "typecheck": "tsc --noEmit",
103
+ "test": "vitest run",
104
+ "test:watch": "vitest",
105
+ "openapi-dev-types": "openapi-typescript http://localhost:5268/swagger/v1/swagger.json -o ./src/api/v1.ts --alphabetize --default-non-nullable --enum-values",
106
+ "openapi-types": "openapi-typescript https://api.filion.se/swagger/v1/swagger.json -o ./src/api/v1.ts --alphabetize --default-non-nullable --enum-values",
107
+ "prepack": "pnpm build",
108
+ "prepublishOnly": "pnpm verify",
109
+ "check": "biome check",
110
+ "verify": "pnpm run typecheck && pnpm run check && pnpm run test",
111
+ "biome:check": "biome check --write",
112
+ "biome:lint": "biome lint --fix",
113
+ "biome:format": "biome format --write"
114
+ },
115
+ "peerDependencies": {
116
+ "@tanstack/react-router": "^1.170.0",
117
+ "@tanstack/react-start": "^1.168.0",
118
+ "jose": "^6.0.0",
119
+ "openapi-fetch": "^0.17.0",
120
+ "react": "^19.0.0",
121
+ "zod": "^4.0.0"
122
+ },
123
+ "peerDependenciesMeta": {
124
+ "@tanstack/react-router": {
125
+ "optional": true
126
+ },
127
+ "@tanstack/react-start": {
128
+ "optional": true
129
+ },
130
+ "jose": {
131
+ "optional": true
132
+ },
133
+ "openapi-fetch": {
134
+ "optional": true
135
+ },
136
+ "react": {
137
+ "optional": true
138
+ }
139
+ },
140
+ "devDependencies": {
141
+ "@biomejs/biome": "2.5.15",
142
+ "@tanstack/react-router": "1.170.46",
143
+ "@tanstack/react-start": "1.169.4",
144
+ "@types/node": "26.6.6",
145
+ "@types/react": "19.3.0",
146
+ "@types/react-dom": "19.3.0",
147
+ "happy-dom": "20.14.6",
148
+ "jose": "6.2.13",
149
+ "openapi-fetch": "0.17.0",
150
+ "openapi-typescript": "7.13.0",
151
+ "react": "19.3.1",
152
+ "react-dom": "19.3.1",
153
+ "typescript": "6.0.3",
154
+ "vitest": "5.0.5",
155
+ "zod": "4.6.7"
156
+ }
157
+ }