cursedauth 0.8.0 โ†’ 0.9.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 (70) hide show
  1. package/dist/_bunOnly.d.ts +2 -0
  2. package/dist/_bunOnly.d.ts.map +1 -0
  3. package/dist/_bunOnly.js +11 -0
  4. package/dist/_bunOnly.js.map +1 -0
  5. package/dist/account/AccountMenu.d.ts +2 -2
  6. package/dist/account/AccountMenu.d.ts.map +1 -1
  7. package/dist/account/AccountMenu.js +8 -8
  8. package/dist/account/AccountMenu.js.map +1 -1
  9. package/dist/account/AccountNotice.d.ts +1 -1
  10. package/dist/account/AccountNotice.d.ts.map +1 -1
  11. package/dist/account/AccountNotice.js +3 -3
  12. package/dist/account/AccountNotice.js.map +1 -1
  13. package/dist/account/accountNotice.state.d.ts +1 -1
  14. package/dist/account/accountNotice.state.d.ts.map +1 -1
  15. package/dist/account/accountNotice.state.js +2 -2
  16. package/dist/account/accountNotice.state.js.map +1 -1
  17. package/dist/accountSlot.client.d.ts +1 -1
  18. package/dist/accountSlot.client.d.ts.map +1 -1
  19. package/dist/accountSlot.client.js +1 -1
  20. package/dist/accountSlot.client.js.map +1 -1
  21. package/dist/auth.d.ts +1 -1
  22. package/dist/auth.d.ts.map +1 -1
  23. package/dist/auth.js +3 -3
  24. package/dist/auth.js.map +1 -1
  25. package/dist/auth.server.js +1 -1
  26. package/dist/auth.server.js.map +1 -1
  27. package/dist/contentCensus.d.ts +1 -1
  28. package/dist/contentCensus.d.ts.map +1 -1
  29. package/dist/d1Stores.d.ts +15 -4
  30. package/dist/d1Stores.d.ts.map +1 -1
  31. package/dist/d1Stores.js +14 -3
  32. package/dist/d1Stores.js.map +1 -1
  33. package/dist/index.d.ts +8 -8
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +7 -7
  36. package/dist/index.js.map +1 -1
  37. package/dist/ssoAutoSignIn.js +2 -2
  38. package/dist/ssoAutoSignIn.js.map +1 -1
  39. package/dist/ssoConsumer.server.d.ts +24 -4
  40. package/dist/ssoConsumer.server.d.ts.map +1 -1
  41. package/dist/ssoConsumer.server.js +55 -10
  42. package/dist/ssoConsumer.server.js.map +1 -1
  43. package/dist/ssoTestHarness.d.ts +1 -1
  44. package/dist/ssoTestHarness.d.ts.map +1 -1
  45. package/dist/ssoTestHarness.js +2 -2
  46. package/dist/ssoTestHarness.js.map +1 -1
  47. package/dist/userSessions.core.d.ts +1 -1
  48. package/dist/userSessions.core.d.ts.map +1 -1
  49. package/dist/userSessions.core.js +4 -4
  50. package/dist/userSessions.core.js.map +1 -1
  51. package/dist/userSessions.d.ts +2 -2
  52. package/dist/userSessions.d.ts.map +1 -1
  53. package/dist/userSessions.js +2 -2
  54. package/dist/userSessions.js.map +1 -1
  55. package/package.json +4 -4
  56. package/src/_bunOnly.ts +13 -0
  57. package/src/account/AccountMenu.tsx +8 -8
  58. package/src/account/AccountNotice.tsx +5 -5
  59. package/src/account/accountNotice.state.ts +3 -3
  60. package/src/accountSlot.client.ts +1 -1
  61. package/src/auth.server.ts +1 -1
  62. package/src/auth.ts +3 -3
  63. package/src/contentCensus.ts +1 -1
  64. package/src/d1Stores.ts +15 -4
  65. package/src/index.ts +8 -8
  66. package/src/ssoAutoSignIn.ts +2 -2
  67. package/src/ssoConsumer.server.ts +56 -9
  68. package/src/ssoTestHarness.ts +2 -2
  69. package/src/userSessions.core.ts +4 -4
  70. package/src/userSessions.ts +2 -2
@@ -37,11 +37,11 @@
37
37
  * capsule and ยง5 wants 44px targets; both are literals here for that reason.
38
38
  */
39
39
  import { useCallback } from "react";
40
- import { currentExpectedAccount, setExpectedAccount } from "../accountSlot.client";
41
- import type { AccountDriftBody } from "../accountSlots";
42
- import { startSsoSignIn } from "../ssoAutoSignIn";
43
- import { useHostDark, useInjectedStyles } from "../ui/popover";
44
- import type { AccountNoticeState } from "./accountNotice.state";
40
+ import { currentExpectedAccount, setExpectedAccount } from "../accountSlot.client.js";
41
+ import type { AccountDriftBody } from "../accountSlots.js";
42
+ import { startSsoSignIn } from "../ssoAutoSignIn.js";
43
+ import { useHostDark, useInjectedStyles } from "../ui/popover.js";
44
+ import type { AccountNoticeState } from "./accountNotice.state.js";
45
45
 
46
46
  const STYLE_ID = "san-style";
47
47
 
@@ -21,9 +21,9 @@
21
21
  * the banner is fetched only once there is something to say.
22
22
  */
23
23
  import { useEffect, useState } from "react";
24
- import { ACCOUNT_DRIFT_EVENT } from "../accountSlot.client";
25
- import type { AccountDriftBody } from "../accountSlots";
26
- import { takeSsoError } from "../ssoAutoSignIn";
24
+ import { ACCOUNT_DRIFT_EVENT } from "../accountSlot.client.js";
25
+ import type { AccountDriftBody } from "../accountSlots.js";
26
+ import { takeSsoError } from "../ssoAutoSignIn.js";
27
27
 
28
28
  /** What went wrong with the account, if anything. */
29
29
  export type AccountNoticeState =
@@ -51,7 +51,7 @@ import {
51
51
  normalizeSlot,
52
52
  slotFromUrl,
53
53
  withSlot,
54
- } from "./accountSlots";
54
+ } from "./accountSlots.js";
55
55
 
56
56
  /** Per-tab, like the SSO auto-sign-in guards next door and for the same
57
57
  * reason: it must never be a reason a DIFFERENT tab acts as somebody else. */
@@ -4,7 +4,7 @@
4
4
  // `auth.ts`. This file is separate for one reason: the server must not pull React into
5
5
  // its bundle. Change them together; they are one boundary.
6
6
  import type { Context, MiddlewareHandler, Next } from "hono";
7
- import { isProductionRuntime } from "./runtimeMode";
7
+ import { isProductionRuntime } from "./runtimeMode.js";
8
8
 
9
9
  export interface SessionClaims {
10
10
  userId: string;
package/src/auth.ts CHANGED
@@ -42,7 +42,7 @@ import {
42
42
  useRef,
43
43
  useState,
44
44
  } from "react";
45
- import { isProductionRuntime } from "./runtimeMode";
45
+ import { isProductionRuntime } from "./runtimeMode.js";
46
46
  import {
47
47
  clearSsoAutoState,
48
48
  decideSsoAutoSignIn,
@@ -51,7 +51,7 @@ import {
51
51
  ssoSignedOutHere,
52
52
  startSsoSignIn,
53
53
  startSsoSignOut,
54
- } from "./ssoAutoSignIn";
54
+ } from "./ssoAutoSignIn.js";
55
55
 
56
56
  // Re-exported through THIS subpath on purpose: `cursedauth/auth`
57
57
  // is already the one client-side auth import every satellite has, and a second
@@ -75,7 +75,7 @@ export {
75
75
  takeSsoError,
76
76
  useSsoAutoSignIn,
77
77
  useSsoErrorNotice,
78
- } from "./ssoAutoSignIn";
78
+ } from "./ssoAutoSignIn.js";
79
79
 
80
80
  export interface SatelliteUser {
81
81
  id: string;
@@ -21,7 +21,7 @@
21
21
  * @see `ssoConsumer.server.ts` for the route, and `sso.ts` for the ticket.
22
22
  */
23
23
  import type { Database } from "bun:sqlite";
24
- import type { ContentCensus, ContentCensusUser } from "./sso";
24
+ import type { ContentCensus, ContentCensusUser } from "./sso.js";
25
25
 
26
26
  /** One kind of thing an app keeps per account. */
27
27
  export interface CensusCounter {
package/src/d1Stores.ts CHANGED
@@ -57,11 +57,11 @@ import {
57
57
  type RawSsoUserRow,
58
58
  type SsoUserRow,
59
59
  type SsoUserStore,
60
- } from "./ssoUsers";
61
- import type { SessionRow, SessionRows } from "./userSessions.core";
60
+ } from "./ssoUsers.js";
61
+ import type { SessionRow, SessionRows } from "./userSessions.core.js";
62
62
 
63
- export { SESSIONS_DDL } from "./userSessions.core";
64
- export { SSO_USERS_DDL } from "./ssoUsers";
63
+ export { SESSIONS_DDL } from "./userSessions.core.js";
64
+ export { SSO_USERS_DDL } from "./ssoUsers.js";
65
65
 
66
66
  /**
67
67
  * The slice of a D1 handle these stores use.
@@ -113,6 +113,17 @@ export interface PendingWrites extends WriteCollector {
113
113
  settle(): Promise<void>;
114
114
  }
115
115
 
116
+ /**
117
+ * ๐Ÿ”ด The SHARED home of this primitive is `cursedbelt-server/d1` โ€” it is a D1-invocation
118
+ * concern, it sits beside `perInvocation` there, and its header carries the full argument.
119
+ * This copy stays because the dependency edge may not: every app installs `cursedauth` and
120
+ * not all of them install the belt, so a belt-less consumer needs a door here. One
121
+ * implementation's worth of BEHAVIOUR behind two doors is not two implementations โ€” but it
122
+ * is still two bodies, so **a change to either one belongs in both**, and the belt's is the
123
+ * one that decides. The contract that must not drift is `Promise.all` over `allSettled`, and
124
+ * both sides hold it under test: `d1Stores.lostWrite.test.ts:254` here, and
125
+ * `d1/invocation.spec.ts`'s "a failed write REJECTS settle()" there.
126
+ */
116
127
  export function createPendingWrites(): PendingWrites {
117
128
  const pending: Promise<unknown>[] = [];
118
129
  return {
package/src/index.ts CHANGED
@@ -30,7 +30,7 @@ export {
30
30
  type SsoConsumer,
31
31
  type SsoConsumerOptions,
32
32
  type SsoUser,
33
- } from "./ssoConsumer.server";
33
+ } from "./ssoConsumer.server.js";
34
34
  export {
35
35
  createSqliteSessionRows,
36
36
  createUserSessionStore,
@@ -45,7 +45,7 @@ export {
45
45
  type UserSessionStore,
46
46
  type UserSessionStoreCoreOptions,
47
47
  type UserSessionStoreOptions,
48
- } from "./userSessions";
48
+ } from "./userSessions.js";
49
49
  /*
50
50
  * The `sso_users` seam. ๐Ÿ”ด `cursedauth/d1-stores` is deliberately NOT re-exported from
51
51
  * this barrel: it has no reason to be here (a Worker cannot import this file at all โ€”
@@ -59,7 +59,7 @@ export {
59
59
  SSO_USERS_DDL,
60
60
  type SsoUserRow,
61
61
  type SsoUserStore,
62
- } from "./ssoUsers";
62
+ } from "./ssoUsers.js";
63
63
  export {
64
64
  DEFAULT_GATE_PATH,
65
65
  type GatedMountPlan,
@@ -67,14 +67,14 @@ export {
67
67
  type Mounter,
68
68
  mountGatedApp,
69
69
  type SessionGate,
70
- } from "./mountGatedApp";
71
- export { type CensusCounter, countingCensus, sharedCensus } from "./contentCensus";
70
+ } from "./mountGatedApp.js";
71
+ export { type CensusCounter, countingCensus, sharedCensus } from "./contentCensus.js";
72
72
  export {
73
73
  LOCAL_AUTH_URL,
74
74
  STAGE_IDENTITY_ENV,
75
75
  stageIdentityIsLocal,
76
- } from "./stageIdentity";
77
- export type { ContentCensus, ContentCensusUser } from "./sso";
76
+ } from "./stageIdentity.js";
77
+ export type { ContentCensus, ContentCensusUser } from "./sso.js";
78
78
  /*
79
79
  * The bearer-token half of the boundary. `getSessionClaims` was the only piece this
80
80
  * barrel published until 2026-09-15, because the four apps graduated before `roms`
@@ -98,4 +98,4 @@ export {
98
98
  SESSION_CLAIMS_KEY,
99
99
  type SessionClaims,
100
100
  type SessionVerifier,
101
- } from "./auth.server";
101
+ } from "./auth.server.js";
@@ -52,8 +52,8 @@
52
52
  * from `ssoConsumer.server.ts`: that module pulls in `bun:sqlite` and hono,
53
53
  * and this one runs in a browser. `ssoAutoSignIn.test.ts` pins them equal. */
54
54
  import { useEffect, useRef, useState } from "react";
55
- import { currentAccountSlot } from "./accountSlot.client";
56
- import { ACCOUNT_SLOT_PARAM } from "./accountSlots";
55
+ import { currentAccountSlot } from "./accountSlot.client.js";
56
+ import { ACCOUNT_SLOT_PARAM } from "./accountSlots.js";
57
57
 
58
58
  export const SSO_START_PATH = "/api/auth/sso/start";
59
59
  /**
@@ -31,10 +31,10 @@ import type { KeyObject } from "node:crypto";
31
31
  import { createPublicKey } from "node:crypto";
32
32
  import type { Database } from "bun:sqlite";
33
33
  import type { Context, Hono, MiddlewareHandler, Next } from "hono";
34
- import { stageIdentityIsLocal } from "./stageIdentity";
35
- import { SESSION_CLAIMS_KEY, type SessionClaims } from "./auth.server";
36
- import { isSecureRequest } from "./secureRequest";
37
- import { createSqliteSsoUserStore, type SsoUserRow, type SsoUserStore } from "./ssoUsers";
34
+ import { stageIdentityIsLocal } from "./stageIdentity.js";
35
+ import { SESSION_CLAIMS_KEY, type SessionClaims } from "./auth.server.js";
36
+ import { isSecureRequest } from "./secureRequest.js";
37
+ import { createSqliteSsoUserStore, type SsoUserRow, type SsoUserStore } from "./ssoUsers.js";
38
38
  import {
39
39
  CENSUS_MAX_SUBJECTS,
40
40
  type ContentCensus,
@@ -47,7 +47,7 @@ import {
47
47
  verifyGrant,
48
48
  verifyRevocation,
49
49
  verifySessionsRequest,
50
- } from "./sso";
50
+ } from "./sso.js";
51
51
  import {
52
52
  ACCOUNT_DRIFT_STATUS,
53
53
  accountDriftBody,
@@ -55,8 +55,8 @@ import {
55
55
  MAX_ACCOUNT_SLOTS,
56
56
  normalizeSlot,
57
57
  withSlot,
58
- } from "./accountSlots";
59
- import type { UserSessionStore } from "./userSessions";
58
+ } from "./accountSlots.js";
59
+ import type { UserSessionStore } from "./userSessions.js";
60
60
 
61
61
  export const SSO_CALLBACK_PATH = "/api/auth/sso/callback";
62
62
  export const SSO_START_PATH = "/api/auth/sso/start";
@@ -494,13 +494,59 @@ export function resolveSsoAudience(
494
494
  authUrl: string,
495
495
  env: NodeJS.ProcessEnv = process.env,
496
496
  registered: readonly string[] = [],
497
+ publicUrl = "",
497
498
  ): string {
499
+ const hosted = hostedStageAudience(appKey, authUrl, publicUrl, registered);
500
+ if (hosted) return hosted;
498
501
  if (!stageIdentityIsLocal(env)) return appKey;
499
502
  if (!isLoopbackOrigin(authUrl)) return appKey;
500
503
  const local = `${appKey}-local`;
501
504
  return registered.includes(local) ? local : appKey;
502
505
  }
503
506
 
507
+ /**
508
+ * ๐Ÿ”ด The HOSTED stage โ€” `<app>-stage.<zone>` signing in at `auth-stage.<zone>` โ€” which is
509
+ * `apps/auth` deployed a second time and mints grants for `<app>-stage` (its roster,
510
+ * `apps/auth/src/server/stageDoor.ts`). Added 2026-09-22, the day auth-stage stopped being a
511
+ * fork: until then only the LOCAL stage had a twin audience, and a hosted stage consumer asked
512
+ * for `<app>` and refused every grant the stage door minted โ€” measured on `collections-stage`,
513
+ * *"grant is for "collections-stage", not "collections""*.
514
+ *
515
+ * Three conditions, all required, the same shape as the local branch and for the same reasons:
516
+ *
517
+ * 1. **this consumer's OWN origin is `<app>-stage.<zone>`** โ€” a name in the fleet's zone that
518
+ * only a stage deploy creates. A production release cannot acquire it without the DNS record.
519
+ * 2. **the accounts door is `auth-stage.<zone>`, the same zone** โ€” a stage origin talking to the
520
+ * REAL door keeps its real audience, so a stage can never mint itself production access.
521
+ * 3. **`<app>-stage` is registered** โ€” an app that has not declared its stage twin keeps its own
522
+ * key and fails visibly at the roster rather than asking for an audience nobody knows.
523
+ *
524
+ * It moves the AUDIENCE only, exactly as the local branch does.
525
+ */
526
+ export function hostedStageAudience(
527
+ appKey: string,
528
+ authUrl: string,
529
+ publicUrl: string,
530
+ registered: readonly string[],
531
+ ): string | null {
532
+ const stage = `${appKey}-stage`;
533
+ if (!registered.includes(stage)) return null;
534
+ let app: URL;
535
+ let auth: URL;
536
+ try {
537
+ app = new URL(publicUrl);
538
+ auth = new URL(authUrl);
539
+ } catch {
540
+ return null;
541
+ }
542
+ if (app.protocol !== "https:" || auth.protocol !== "https:") return null;
543
+ const [appLabel, ...appZone] = app.hostname.split(".");
544
+ const [authLabel, ...authZone] = auth.hostname.split(".");
545
+ if (appLabel !== stage || authLabel !== "auth-stage") return null;
546
+ if (appZone.length < 2 || appZone.join(".") !== authZone.join(".")) return null;
547
+ return stage;
548
+ }
549
+
504
550
  export function createSsoConsumer(options: SsoConsumerOptions): SsoConsumer {
505
551
  const { app: appKey, sessions } = options;
506
552
  /*
@@ -531,11 +577,12 @@ export function createSsoConsumer(options: SsoConsumerOptions): SsoConsumer {
531
577
  authUrl,
532
578
  options.env ?? process.env,
533
579
  options.registeredAudiences ?? [],
580
+ options.publicUrl,
534
581
  );
535
582
  if (audience !== appKey) {
536
583
  console.log(
537
- `[${appKey}] SSO audience is "${audience}" โ€” this is a LOCAL STAGE, signing in ` +
538
- `against ${authUrl}. A grant minted here cannot open the production deployment.`,
584
+ `[${appKey}] SSO audience is "${audience}" โ€” this is a ${audience.endsWith("-stage") ? "HOSTED" : "LOCAL"} STAGE, ` +
585
+ `signing in against ${authUrl}. A grant minted here cannot open the production deployment.`,
539
586
  );
540
587
  }
541
588
  const publicUrl = options.publicUrl.replace(/\/$/, "");
@@ -14,8 +14,8 @@
14
14
  * app had copied.
15
15
  */
16
16
  import type { Hono } from "hono";
17
- import { generateSsoKeyPair, mintGrant, type SsoKeyPair } from "./sso";
18
- import { SSO_CALLBACK_PATH } from "./ssoConsumer.server";
17
+ import { generateSsoKeyPair, mintGrant, type SsoKeyPair } from "./sso.js";
18
+ import { SSO_CALLBACK_PATH } from "./ssoConsumer.server.js";
19
19
 
20
20
  /** A user as the accounts satellite would know them โ€” the shape grants are minted from. */
21
21
  export interface SeededTestUser {
@@ -65,22 +65,22 @@ import {
65
65
  normalizeSlot,
66
66
  slotCookieName,
67
67
  slotFromUrl,
68
- } from "./accountSlots";
68
+ } from "./accountSlots.js";
69
69
  import {
70
70
  clientAddressOf,
71
71
  clientFactsOf,
72
72
  clientUserAgentOf,
73
73
  describePlace,
74
74
  type PlaceLookup,
75
- } from "./clientDescription";
75
+ } from "./clientDescription.js";
76
76
  // ๐Ÿ”ด The compare, not a copy of it. This module carried its OWN `constantTimeEqual`
77
77
  // until 2026-09-17 โ€” a `node:crypto` `timingSafeEqual` with both sides padded to a
78
78
  // common length โ€” while `constantTime.ts` sat two files away with the same contract.
79
79
  // That made an eighth copy of this primitive inside the very package that publishes
80
80
  // it. Both forms were correct; neither knew about the other, which is the whole
81
81
  // failure mode.
82
- import { constantTimeEqual } from "./constantTime";
83
- import { isSecureRequest } from "./secureRequest";
82
+ import { constantTimeEqual } from "./constantTime.js";
83
+ import { isSecureRequest } from "./secureRequest.js";
84
84
 
85
85
  /**
86
86
  * One row of the `sessions` table, as both implementations hand it over.
@@ -35,7 +35,7 @@ import {
35
35
  type SessionRows,
36
36
  type UserSessionStore,
37
37
  type UserSessionStoreCoreOptions,
38
- } from "./userSessions.core";
38
+ } from "./userSessions.core.js";
39
39
 
40
40
  export {
41
41
  createUserSessionStoreOver,
@@ -48,7 +48,7 @@ export {
48
48
  type SlotOccupant,
49
49
  type UserSessionStore,
50
50
  type UserSessionStoreCoreOptions,
51
- } from "./userSessions.core";
51
+ } from "./userSessions.core.js";
52
52
 
53
53
  export interface UserSessionStoreOptions extends UserSessionStoreCoreOptions {
54
54
  dbPath: string;