cursedauth 0.13.0 → 0.14.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
@@ -48,6 +48,7 @@ logins and nothing else. The provider is a separate service reached over HTTPS a
48
48
  | `cursedauth/sso` | both | the grant: its wire shape, its claims, its verification |
49
49
  | `cursedauth/session-claims` | server | the bearer-token half: `SESSION_CLAIMS_KEY`, `SessionClaims`, `createRequireSession`. **Worker-safe** — reaches no `bun:sqlite` |
50
50
  | `cursedauth/constant-time` | both | `constantTimeEqual` — compare two secrets without leaking where they differ |
51
+ | `cursedauth/fleet-call` | both | `parseFleetUser`, `fleetBearerMatches`, `fleetCallHeaders` — one fleet app asking another over a Service Binding as the signed-in account (`x-fleet-user`) |
51
52
  | `cursedauth/secure-request` | both | `isSecureRequest` — whether a request arrived over HTTPS (reading `x-forwarded-proto` behind the tunnel), the one question the cookie `Secure` attribute turns on. Published 0.9.3 because `patterns` and `auth` each carried a copy (task 2106) |
52
53
  | `cursedauth/offline-grant` | both | the bounded offline window: how long a device with no network may keep using cached content |
53
54
  | `cursedauth/relay-door` | server | a relay app's door on its Worker (`cursedops/relay`): the SSO consumer over D1, the account signed into `<app>_as` for the Mac, the browser's session cookies stripped, the door's schema and the cutover's session import. Lifted from `apps/roms` in 0.10.0. **Worker-safe** |
@@ -0,0 +1,16 @@
1
+ /** The asking account, JSON — `{ id, email, isOwner?, isAdmin? }`. */
2
+ export declare const FLEET_USER_HEADER = "x-fleet-user";
3
+ /** The account a fleet call names. `email` is lowercased; the flags are `true` or `false`, never absent. */
4
+ export interface FleetUser {
5
+ id: string;
6
+ email: string;
7
+ isOwner: boolean;
8
+ isAdmin: boolean;
9
+ }
10
+ /** The `x-fleet-user` value as an account, or null for anything that is not one — never throws. */
11
+ export declare function parseFleetUser(header: string | null | undefined): FleetUser | null;
12
+ /** Whether the request's `authorization: Bearer …` is `token` — false when either is empty. Constant time. */
13
+ export declare function fleetBearerMatches(authorization: string | null | undefined, token: string | null | undefined): boolean;
14
+ /** The caller's headers: the bearer, the asking account, and JSON wanted back. */
15
+ export declare function fleetCallHeaders(token: string, user: FleetUser): Record<string, string>;
16
+ //# sourceMappingURL=fleetCall.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fleetCall.d.ts","sourceRoot":"","sources":["../src/fleetCall.ts"],"names":[],"mappings":"AAqBA,sEAAsE;AACtE,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAEhD,4GAA4G;AAC5G,MAAM,WAAW,SAAS;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;CACjB;AAED,mGAAmG;AACnG,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,SAAS,GAAG,IAAI,CASlF;AAED,8GAA8G;AAC9G,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAGtH;AAED,kFAAkF;AAClF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAEvF"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * One fleet app asking another, over a Service Binding, AS the signed-in account —
3
+ * `cursedauth/fleet-call`.
4
+ *
5
+ * The caller proves itself with a bearer the two apps share (a secret per route, put from each
6
+ * app's own secrets file) and names whose eyes the read uses in `x-fleet-user`, JSON
7
+ * `{ id, email, isOwner?, isAdmin? }`. The callee checks the bearer in constant time, parses the
8
+ * account, and answers through its OWN visibility rules for that account — a relative who cannot
9
+ * see a private branch in one app cannot find it from the other.
10
+ *
11
+ * ## Why it is here (2026-10-27, forge task cursedforge-tasks-todo)
12
+ *
13
+ * family↔photos is the first pair to call each other both ways (photos' tree picker reads
14
+ * family's people; family's dossier reads photos' pictures of a person), and the second direction
15
+ * had begun as a copy of the first's header name and parser — `tools/check-copies.ts` caught the
16
+ * constant. The parser is the part that matters: it decides who the reader is, so two copies
17
+ * that drift is a read made with the wrong eyes. Pure functions, no node builtin: a Worker and a
18
+ * Mac host both import it.
19
+ */
20
+ import { constantTimeEqual } from "./constantTime.js";
21
+ /** The asking account, JSON — `{ id, email, isOwner?, isAdmin? }`. */
22
+ export const FLEET_USER_HEADER = "x-fleet-user";
23
+ /** The `x-fleet-user` value as an account, or null for anything that is not one — never throws. */
24
+ export function parseFleetUser(header) {
25
+ if (!header)
26
+ return null;
27
+ try {
28
+ const v = JSON.parse(header);
29
+ if (!v || typeof v.id !== "string" || !v.id.trim() || typeof v.email !== "string")
30
+ return null;
31
+ return { id: v.id.trim(), email: v.email.trim().toLowerCase(), isOwner: v.isOwner === true, isAdmin: v.isAdmin === true };
32
+ }
33
+ catch {
34
+ return null;
35
+ }
36
+ }
37
+ /** Whether the request's `authorization: Bearer …` is `token` — false when either is empty. Constant time. */
38
+ export function fleetBearerMatches(authorization, token) {
39
+ const presented = (authorization ?? "").replace(/^Bearer\s+/i, "").trim();
40
+ return Boolean(presented && token) && constantTimeEqual(presented, token);
41
+ }
42
+ /** The caller's headers: the bearer, the asking account, and JSON wanted back. */
43
+ export function fleetCallHeaders(token, user) {
44
+ return { authorization: `Bearer ${token}`, [FLEET_USER_HEADER]: JSON.stringify(user), accept: "application/json" };
45
+ }
46
+ //# sourceMappingURL=fleetCall.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fleetCall.js","sourceRoot":"","sources":["../src/fleetCall.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,sEAAsE;AACtE,MAAM,CAAC,MAAM,iBAAiB,GAAG,cAAc,CAAC;AAUhD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HANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cursedauth",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "The app side of fleet SSO — sign in through the accounts service, keep a local snapshot of who signed in, and gate the app on it. Bun + Hono + React, one SQLite file per app.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -101,6 +101,12 @@
101
101
  "source": "./src/constantTime.ts",
102
102
  "import": "./dist/constantTime.js"
103
103
  },
104
+ "./fleet-call": {
105
+ "types": "./dist/fleetCall.d.ts",
106
+ "bun": "./src/fleetCall.ts",
107
+ "source": "./src/fleetCall.ts",
108
+ "import": "./dist/fleetCall.js"
109
+ },
104
110
  "./secure-request": {
105
111
  "types": "./dist/secureRequest.d.ts",
106
112
  "bun": "./src/secureRequest.ts",
@@ -0,0 +1,54 @@
1
+ /**
2
+ * One fleet app asking another, over a Service Binding, AS the signed-in account —
3
+ * `cursedauth/fleet-call`.
4
+ *
5
+ * The caller proves itself with a bearer the two apps share (a secret per route, put from each
6
+ * app's own secrets file) and names whose eyes the read uses in `x-fleet-user`, JSON
7
+ * `{ id, email, isOwner?, isAdmin? }`. The callee checks the bearer in constant time, parses the
8
+ * account, and answers through its OWN visibility rules for that account — a relative who cannot
9
+ * see a private branch in one app cannot find it from the other.
10
+ *
11
+ * ## Why it is here (2026-10-27, forge task cursedforge-tasks-todo)
12
+ *
13
+ * family↔photos is the first pair to call each other both ways (photos' tree picker reads
14
+ * family's people; family's dossier reads photos' pictures of a person), and the second direction
15
+ * had begun as a copy of the first's header name and parser — `tools/check-copies.ts` caught the
16
+ * constant. The parser is the part that matters: it decides who the reader is, so two copies
17
+ * that drift is a read made with the wrong eyes. Pure functions, no node builtin: a Worker and a
18
+ * Mac host both import it.
19
+ */
20
+ import { constantTimeEqual } from "./constantTime.js";
21
+
22
+ /** The asking account, JSON — `{ id, email, isOwner?, isAdmin? }`. */
23
+ export const FLEET_USER_HEADER = "x-fleet-user";
24
+
25
+ /** The account a fleet call names. `email` is lowercased; the flags are `true` or `false`, never absent. */
26
+ export interface FleetUser {
27
+ id: string;
28
+ email: string;
29
+ isOwner: boolean;
30
+ isAdmin: boolean;
31
+ }
32
+
33
+ /** The `x-fleet-user` value as an account, or null for anything that is not one — never throws. */
34
+ export function parseFleetUser(header: string | null | undefined): FleetUser | null {
35
+ if (!header) return null;
36
+ try {
37
+ const v = JSON.parse(header) as Partial<FleetUser> | null;
38
+ if (!v || typeof v.id !== "string" || !v.id.trim() || typeof v.email !== "string") return null;
39
+ return { id: v.id.trim(), email: v.email.trim().toLowerCase(), isOwner: v.isOwner === true, isAdmin: v.isAdmin === true };
40
+ } catch {
41
+ return null;
42
+ }
43
+ }
44
+
45
+ /** Whether the request's `authorization: Bearer …` is `token` — false when either is empty. Constant time. */
46
+ export function fleetBearerMatches(authorization: string | null | undefined, token: string | null | undefined): boolean {
47
+ const presented = (authorization ?? "").replace(/^Bearer\s+/i, "").trim();
48
+ return Boolean(presented && token) && constantTimeEqual(presented, token as string);
49
+ }
50
+
51
+ /** The caller's headers: the bearer, the asking account, and JSON wanted back. */
52
+ export function fleetCallHeaders(token: string, user: FleetUser): Record<string, string> {
53
+ return { authorization: `Bearer ${token}`, [FLEET_USER_HEADER]: JSON.stringify(user), accept: "application/json" };
54
+ }