@lunora/client 1.0.0-alpha.3 → 1.0.0-alpha.300

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 (100) hide show
  1. package/LICENSE.md +207 -104
  2. package/README.md +24 -7
  3. package/dist/admin/index.d.mts +689 -0
  4. package/dist/admin/index.d.ts +689 -0
  5. package/dist/admin/index.mjs +1 -0
  6. package/dist/auth/index.d.mts +174 -13
  7. package/dist/auth/index.d.ts +174 -13
  8. package/dist/auth/index.mjs +1 -60
  9. package/dist/index.d.mts +1121 -190
  10. package/dist/index.d.ts +1121 -190
  11. package/dist/index.mjs +1 -14
  12. package/dist/packem_shared/ADMIN_AUTH_DEFAULT_PAGE_SIZE-aKbm8N1z.mjs +1 -0
  13. package/dist/packem_shared/CONFLICT_ERROR_CODE-B7qNZMMk.mjs +1 -0
  14. package/dist/packem_shared/DEFAULT_MAX_BUFFER-Bd-_iyiV.mjs +1 -0
  15. package/dist/packem_shared/LunoraAdminClient-ClQxFDiy.mjs +1 -0
  16. package/dist/packem_shared/LunoraClient-D8eDGCKr.mjs +1 -0
  17. package/dist/packem_shared/OfflineQueue-BGkx7pBL.mjs +1 -0
  18. package/dist/packem_shared/RETIRE_AFTER_DURABLE_SEQ_ADVANCE-DoEHtuR8.mjs +1 -0
  19. package/dist/packem_shared/SKIP-d7LeP-sY.mjs +1 -0
  20. package/dist/packem_shared/SubscriptionRegistry-DjFfxba2.mjs +1 -0
  21. package/dist/packem_shared/TabCoordinator-DIySdaRV.mjs +1 -0
  22. package/dist/packem_shared/applyDelta-CaudNj2C.mjs +1 -0
  23. package/dist/packem_shared/base64-849R7V-V.mjs +1 -0
  24. package/dist/packem_shared/client-tuning-C10B2KCO.mjs +1 -0
  25. package/dist/packem_shared/client-urls-BHLUjjcG.mjs +1 -0
  26. package/dist/packem_shared/connectLiveStream-BdjsWP1-.mjs +1 -0
  27. package/dist/packem_shared/createAsyncStoragePersistence-BgfdvLwe.mjs +1 -0
  28. package/dist/packem_shared/createAsyncStorageQueryCache-6Y94ocbQ.mjs +1 -0
  29. package/dist/packem_shared/createCallRunner-Bwcrfh76.mjs +1 -0
  30. package/dist/packem_shared/createClientQuery-B8Nfj-7o.mjs +1 -0
  31. package/dist/packem_shared/createInMemoryBookmarkStorage-BooZhW0n.mjs +1 -0
  32. package/dist/packem_shared/createInMemoryPersistence-C-IzNVbg.mjs +1 -0
  33. package/dist/packem_shared/createInMemoryQueryCache-DR6AorA2.mjs +1 -0
  34. package/dist/packem_shared/createLocalStore-WKNHD1ca.mjs +1 -0
  35. package/dist/packem_shared/createMutatorRunner-CuMRJpUx.mjs +1 -0
  36. package/dist/packem_shared/createReconnect-CjTmjJDH.mjs +1 -0
  37. package/dist/packem_shared/createServerClient-CcH_sS6i.mjs +1 -0
  38. package/dist/packem_shared/createSnapshotPrecondition-BXP1NPBW.mjs +1 -0
  39. package/dist/packem_shared/delta-merge-C6OqMEPH.mjs +1 -0
  40. package/dist/packem_shared/deserializePreloaded-DxozvweR.mjs +1 -0
  41. package/dist/packem_shared/frame-hint-D-NK691z.mjs +1 -0
  42. package/dist/packem_shared/function-reference.d-Br_hsKje.d.mts +45 -0
  43. package/dist/packem_shared/function-reference.d-Br_hsKje.d.ts +45 -0
  44. package/dist/packem_shared/getServerSession-BaOoo1p6.mjs +1 -0
  45. package/dist/packem_shared/httpStream-DN3D9WqW.mjs +7 -0
  46. package/dist/packem_shared/idb-utility-BS7xvou1.mjs +1 -0
  47. package/dist/packem_shared/live-stream-DBKgZlnb.mjs +10 -0
  48. package/dist/packem_shared/liveTopicSubscription-DQtKMFKw.mjs +1 -0
  49. package/dist/packem_shared/lunora-client-BC2DJGwq.mjs +1 -0
  50. package/dist/packem_shared/lunora-client.d-BswMNnv7.d.mts +5060 -0
  51. package/dist/packem_shared/lunora-client.d-TchceUzJ.d.ts +5060 -0
  52. package/dist/packem_shared/lunoraQueryKey-CucWmxnx.mjs +1 -0
  53. package/dist/packem_shared/offline-queue-HwrYARIL.mjs +1 -0
  54. package/dist/packem_shared/optimistic-layers-BI61YTO3.mjs +1 -0
  55. package/dist/packem_shared/preload.d-BKdXfr3n.d.ts +21 -0
  56. package/dist/packem_shared/preload.d-qY64gg1w.d.mts +21 -0
  57. package/dist/packem_shared/preloadQuery-uFy24PCR.mjs +1 -0
  58. package/dist/packem_shared/setAuthTokenProvider-DhBppDiZ.mjs +1 -0
  59. package/dist/packem_shared/single-blob-store-DeaYPBSS.mjs +1 -0
  60. package/dist/packem_shared/snapshot-precondition-BEtcSbWr.mjs +1 -0
  61. package/dist/packem_shared/stream-idle-C7CsIT_m.mjs +1 -0
  62. package/dist/packem_shared/wire-errors-BDckSTKZ.mjs +1 -0
  63. package/dist/pagination/index.d.mts +72 -43
  64. package/dist/pagination/index.d.ts +72 -43
  65. package/dist/pagination/index.mjs +1 -61
  66. package/dist/query/index.d.mts +183 -44
  67. package/dist/query/index.d.ts +183 -44
  68. package/dist/query/index.mjs +1 -1
  69. package/dist/service.d.mts +49 -0
  70. package/dist/service.d.ts +49 -0
  71. package/dist/service.mjs +1 -0
  72. package/dist/ssr/index.d.mts +109 -80
  73. package/dist/ssr/index.d.ts +109 -80
  74. package/dist/ssr/index.mjs +1 -4
  75. package/dist/upload.d.mts +49 -0
  76. package/dist/upload.d.ts +49 -0
  77. package/dist/upload.mjs +1 -0
  78. package/package.json +22 -2
  79. package/dist/packem_shared/CONFLICT_ERROR_CODE-aUdVbEDw.mjs +0 -4
  80. package/dist/packem_shared/DEFAULT_MAX_BUFFER-BDkqO5PW.mjs +0 -107
  81. package/dist/packem_shared/LunoraClient-UiULzH_1.mjs +0 -2165
  82. package/dist/packem_shared/OfflineQueue-D5p_QgF_.mjs +0 -127
  83. package/dist/packem_shared/SKIP-vItZChkw.mjs +0 -50
  84. package/dist/packem_shared/SubscriptionRegistry-B-Qx_Gux.mjs +0 -26
  85. package/dist/packem_shared/applyDelta-4jFGTPA3.mjs +0 -61
  86. package/dist/packem_shared/createAsyncStoragePersistence-1Z5BZ8RC.mjs +0 -45
  87. package/dist/packem_shared/createInMemoryBookmarkStorage-BoN7a7TH.mjs +0 -11
  88. package/dist/packem_shared/createInMemoryPersistence-CW82inU5.mjs +0 -105
  89. package/dist/packem_shared/createInMemoryQueryCache-B1PQ9Twl.mjs +0 -138
  90. package/dist/packem_shared/createLocalStore-DSUfoLqY.mjs +0 -36
  91. package/dist/packem_shared/createMutationRunner-BqsavzvG.mjs +0 -21
  92. package/dist/packem_shared/createReconnect-Di_-oHH7.mjs +0 -22
  93. package/dist/packem_shared/createServerClient-BjZc3gD8.mjs +0 -11
  94. package/dist/packem_shared/deserializePreloaded-C0eJTY_W.mjs +0 -4
  95. package/dist/packem_shared/getServerSession-8jXewqxd.mjs +0 -13
  96. package/dist/packem_shared/lunora-client.d-DGvyuJ_p.d.mts +0 -1597
  97. package/dist/packem_shared/lunora-client.d-DGvyuJ_p.d.ts +0 -1597
  98. package/dist/packem_shared/preload.d-BoDmFqSG.d.ts +0 -20
  99. package/dist/packem_shared/preload.d-dSaRMuhL.d.mts +0 -20
  100. package/dist/packem_shared/preloadQuery-lobFkD2Z.mjs +0 -13
@@ -1,20 +1,181 @@
1
- import { U as User, L as LunoraClient } from "../packem_shared/lunora-client.d-DGvyuJ_p.mjs";
2
- import '@lunora/runtime';
1
+ /**
2
+ * `@lunora/client/auth` — framework-agnostic identity store, and the auth-gate
3
+ * contract every UI adapter implements.
4
+ *
5
+ * The `LunoraClient` is framework-neutral and exposes auth through an async
6
+ * `getCurrentUser()` plus `onAuthTokenChange`. This module lifts the per-client
7
+ * identity caching and listener-fan-out into a shared store that every UI
8
+ * adapter (React, Vue, Solid, Svelte, Angular) consumes, so only one fetch runs
9
+ * at a time and all mounted hooks re-render together when identity resolves or
10
+ * the token changes.
11
+ *
12
+ * ## The auth-gate contract
13
+ *
14
+ * **Read this before adding or changing a gate in any adapter.** Five adapters
15
+ * expose the same three-state gate, and they must agree on what each state
16
+ * means; deriving a gate from `user !== null` (or from the token alone) is how
17
+ * they last disagreed. The single source of truth is {@link AuthStatus}, and the
18
+ * two predicates {@link isAuthenticatedStatus} / {@link isLoadingStatus} — an
19
+ * adapter maps its reactive primitive onto those and adds nothing of its own.
20
+ *
21
+ * | status | meaning | gate |
22
+ * | ------------------ | ---------------------------------------------------------------- | --------------- |
23
+ * | `unauthenticated` | the server answered that there is no session | signed out |
24
+ * | `loading` | the first identity resolve is in flight | loading |
25
+ * | `authenticated` | the server returned a user | authenticated |
26
+ * | `unreachable` | a credential is held but the identity endpoint could not be reached | authenticated |
27
+ *
28
+ * No row says "no bearer token". A **cookie session carries no token here** —
29
+ * it is better-auth's default, what `@lunora/auth-ui` is built on, and what
30
+ * `examples/auth-playground` ships (`createAuthClient` plus
31
+ * `new LunoraClient({ url })`, never `setAuthToken`). Answering
32
+ * `unauthenticated` off a null token alone declared every user of every such
33
+ * app signed out without asking the server, which also left
34
+ * `LunoraClient`'s identity fingerprint `null` for all of them — and a
35
+ * fingerprint that is `null` for everyone is what turns the offline-queue,
36
+ * read-cache and socket identity gates into `null === null`. The first resolve
37
+ * therefore ALWAYS asks; only after an answer does a cleared token
38
+ * short-circuit.
39
+ *
40
+ * `unreachable` counts as authenticated because the **credential** is what
41
+ * authorises requests; a failed identity round-trip is a fact about the network,
42
+ * not about the session. Treating it as signed out turns every offline reload
43
+ * into a sign-out, and treating it as loading spins a fallback for the whole
44
+ * offline period — both of which shipped.
45
+ *
46
+ * The consequence a UI has to respect: `user` may be `null` while the gate says
47
+ * authenticated. Branch on `status`, never on `user === null`, to tell "signed
48
+ * out" from "signed in, identity not resolved yet".
49
+ */
50
+ import { L as LunoraClient, U as User } from "../packem_shared/lunora-client.d-BswMNnv7.mjs";
51
+ import { LunoraAdminClient } from "../admin/index.mjs";
52
+ import { AuthPage, AuthImpersonation, AuthSession, AuthUser } from '@lunora/runtime';
53
+ import '@lunora/errors';
54
+ import "../packem_shared/function-reference.d-Br_hsKje.mjs";
55
+ /** Default page size for the first read; a "load more" grows the requested window by the page size. */
56
+ declare const ADMIN_AUTH_DEFAULT_PAGE_SIZE = 50;
57
+ /** One paged admin-auth collection: the key that identifies its inputs, and how to read a `{ limit }` window from the top. */
58
+ interface AdminAuthList<T> {
59
+ /** Read the first `limit` rows. `AuthPage` is offset/limit-based, so a larger window re-reads from the top rather than appending. */
60
+ readonly fetchPage: (limit: number) => Promise<AuthPage<T>>;
61
+ /** Every input that should invalidate the cache — not `fetchPage`, which is a fresh closure per call. */
62
+ readonly key: ReadonlyArray<unknown>;
63
+ }
64
+ /** Search / filter / sort inputs for {@link authUsersList}. */
65
+ interface AuthUsersListFilter {
66
+ filterField?: string;
67
+ filterValue?: string;
68
+ search?: string;
69
+ searchField?: string;
70
+ sortBy?: string;
71
+ sortDirection?: "asc" | "desc";
72
+ }
73
+ /** Users, via the admin-gated `GET /_lunora/admin/auth/users` (`client.listAuthUsers`). */
74
+ declare const authUsersList: (client: LunoraAdminClient, filter?: AuthUsersListFilter) => AdminAuthList<AuthUser>;
75
+ /** Organizations (better-auth `organization` plugin), via `client.listAuthOrganizations`. */
76
+ declare const authOrganizationsList: (client: LunoraAdminClient) => AdminAuthList<Record<string, unknown>>;
77
+ /** Sign-up invitations (`inviteOnly` plugin), via `client.listAuthSignUpInvitations`. Rows are unfiltered and newest-first. */
78
+ declare const authSignUpInvitationsList: (client: LunoraAdminClient) => AdminAuthList<Record<string, unknown>>;
79
+ /** Auth sessions, optionally scoped to one user, via `client.listAuthSessions`. */
80
+ declare const authSessionsList: (client: LunoraAdminClient, options?: {
81
+ userId?: string;
82
+ }) => AdminAuthList<AuthSession>;
83
+ /**
84
+ * The cache key for one window of an admin list: `[namespace, identity, ...list.key, limit]`.
85
+ *
86
+ * The acting identity (slot 1) partitions the cache, or a credential swap on the
87
+ * same client (admin A → admin B) would serve A's cached rows to B until the
88
+ * refetch lands. It is `client.currentIdentity()` — a `subj:` label or a
89
+ * non-reversible token hash — never the bearer token: query keys are not
90
+ * private (persisters write them to `localStorage`, devtools render them,
91
+ * telemetry logs them), and a same-user token refresh keeps the same key.
92
+ *
93
+ * An adapter that keeps the previous window visible while a larger one loads
94
+ * must only do so when slot 1 is unchanged, so one identity's rows never stand
95
+ * in for another's.
96
+ */
97
+ declare const adminAuthListQueryKey: (identity: string | null, list: AdminAuthList<unknown>, limit: number) => ReadonlyArray<unknown>;
98
+ /**
99
+ * Subscribe to every change of `client.currentIdentity()`. Both signals are
100
+ * needed: a bearer swap fires `onAuthTokenChange`, while a cookie session's
101
+ * user switch or sign-out fires only `onIdentityChange` (no token changes
102
+ * hands) — subscribing to one leaves the other's previous rows on screen.
103
+ */
104
+ declare const subscribeAdminAuthIdentity: (client: LunoraClient, onChange: () => void) => (() => void);
105
+ /** `true` when the server reports rows beyond the loaded window; `false` before the first page resolves, so "load more" past the end is a no-op. */
106
+ declare const adminAuthListHasMore: (page: AuthPage<unknown> | undefined) => boolean;
107
+ /** Query options for one window of an admin list, spread into a TanStack hook (the `lunoraQueryOptions` pattern). */
108
+ interface AdminAuthListQueryOptions<T> {
109
+ readonly queryFn: () => Promise<AuthPage<T>>;
110
+ readonly queryKey: ReadonlyArray<unknown>;
111
+ readonly staleTime: number;
112
+ }
113
+ /**
114
+ * Options for one `{ limit }` window of an admin list. `staleTime` is `0`, not the
115
+ * provider's `Infinity`: this is a one-shot HTTP read, so a remount or a window
116
+ * refocus should re-fetch rather than serve the cached page indefinitely.
117
+ */
118
+ declare const adminAuthListQueryOptions: <T>(list: AdminAuthList<T>, identity: string | null, limit: number) => AdminAuthListQueryOptions<T>;
119
+ /**
120
+ * The page to show while a larger window of the same list loads. Only the previous
121
+ * window from the same identity may stand in: another identity's rows must never be
122
+ * shown while its first read is in flight.
123
+ */
124
+ declare const adminAuthListPlaceholder: <T>(previous: AuthPage<T> | undefined, previousKey: ReadonlyArray<unknown> | undefined, queryKey: ReadonlyArray<unknown>) => AuthPage<T> | undefined;
125
+ /** The `limit` after a "load more": one page larger, and unchanged past the end of the collection. */
126
+ declare const nextAdminAuthLimit: (current: number, pageSize: number, hasMore: boolean) => number;
127
+ /**
128
+ * Mutation options for minting an impersonation session. It deliberately does not call
129
+ * `client.setAuthToken`: swapping the acting client's own token would sign the admin out
130
+ * of their admin session without a visible transition.
131
+ */
132
+ declare const adminAuthImpersonateMutation: (client: LunoraAdminClient) => {
133
+ readonly mutationFn: (userId: string) => Promise<AuthImpersonation>;
134
+ };
135
+ /**
136
+ * Every {@link AuthStatus}, as a value — the contract table in this module's
137
+ * header, and the `@lunora/client` docs table that restates it for consumers,
138
+ * are both asserted against this list (`auth-status-docs.test.ts`), so a new
139
+ * state cannot ship undocumented.
140
+ */
141
+ declare const AUTH_STATUSES: readonly ["authenticated", "loading", "unauthenticated", "unreachable"];
142
+ /**
143
+ * Resolved authentication state. See the contract table in this module's header
144
+ * — the states are not interchangeable, and `unreachable` is the one that exists
145
+ * only so "the server said no session" and "we could not ask" stop colliding.
146
+ */
147
+ type AuthStatus = (typeof AUTH_STATUSES)[number];
148
+ /**
149
+ * Whether a gate should render its authenticated branch.
150
+ *
151
+ * Both `authenticated` and `unreachable` qualify: the credential is held in
152
+ * either case, and only the identity round-trip differs.
153
+ */
154
+ declare const isAuthenticatedStatus: (status: AuthStatus) => boolean;
155
+ /** Whether a gate should render its loading branch — the first resolve only. */
156
+ declare const isLoadingStatus: (status: AuthStatus) => boolean;
3
157
  interface IdentityStore {
4
- /** Read the current resolved user, or `null` when signed out / not yet resolved. */
158
+ /** The current {@link AuthStatus} — what a gate branches on. */
159
+ getStatus: () => AuthStatus;
160
+ /**
161
+ * The last resolved user, or `null`. `null` does NOT mean signed out on its
162
+ * own: read `getStatus` for that. A user resolved before the endpoint
163
+ * went unreachable is retained, so the UI keeps rendering the identity it
164
+ * last knew instead of blanking.
165
+ */
5
166
  getUser: () => User | null;
6
167
  /**
7
- * Subscribe to identity changes. `onChange` is called whenever the user or
8
- * token changes. Returns an unsubscribe handle.
9
- */
168
+ * Subscribe to identity changes. `onChange` is called whenever the user or
169
+ * the status changes. Returns an unsubscribe handle.
170
+ */
10
171
  subscribe: (onChange: () => void) => () => void;
11
172
  }
12
173
  /**
13
- * Return the per-client identity store, creating it on first access.
14
- *
15
- * The store is cached via a `WeakMap` so it is GC'd when the client is dropped,
16
- * and creation is idempotent — calling this multiple times with the same client
17
- * returns the same store, keeping the single-fetch / fan-out invariant.
18
- */
174
+ * Return the per-client identity store, creating it on first access.
175
+ *
176
+ * The store is cached via a `WeakMap` so it is GC'd when the client is dropped,
177
+ * and creation is idempotent — calling this multiple times with the same client
178
+ * returns the same store, keeping the single-fetch / fan-out invariant.
179
+ */
19
180
  declare const getIdentityStore: (client: LunoraClient) => IdentityStore;
20
- export { type IdentityStore, getIdentityStore };
181
+ export { ADMIN_AUTH_DEFAULT_PAGE_SIZE, AUTH_STATUSES, type AdminAuthList, type AdminAuthListQueryOptions, type AuthStatus, type AuthUsersListFilter, type IdentityStore, adminAuthImpersonateMutation, adminAuthListHasMore, adminAuthListPlaceholder, adminAuthListQueryKey, adminAuthListQueryOptions, authOrganizationsList, authSessionsList, authSignUpInvitationsList, authUsersList, getIdentityStore, isAuthenticatedStatus, isLoadingStatus, nextAdminAuthLimit, subscribeAdminAuthIdentity };
@@ -1,20 +1,181 @@
1
- import { U as User, L as LunoraClient } from "../packem_shared/lunora-client.d-DGvyuJ_p.js";
2
- import '@lunora/runtime';
1
+ /**
2
+ * `@lunora/client/auth` — framework-agnostic identity store, and the auth-gate
3
+ * contract every UI adapter implements.
4
+ *
5
+ * The `LunoraClient` is framework-neutral and exposes auth through an async
6
+ * `getCurrentUser()` plus `onAuthTokenChange`. This module lifts the per-client
7
+ * identity caching and listener-fan-out into a shared store that every UI
8
+ * adapter (React, Vue, Solid, Svelte, Angular) consumes, so only one fetch runs
9
+ * at a time and all mounted hooks re-render together when identity resolves or
10
+ * the token changes.
11
+ *
12
+ * ## The auth-gate contract
13
+ *
14
+ * **Read this before adding or changing a gate in any adapter.** Five adapters
15
+ * expose the same three-state gate, and they must agree on what each state
16
+ * means; deriving a gate from `user !== null` (or from the token alone) is how
17
+ * they last disagreed. The single source of truth is {@link AuthStatus}, and the
18
+ * two predicates {@link isAuthenticatedStatus} / {@link isLoadingStatus} — an
19
+ * adapter maps its reactive primitive onto those and adds nothing of its own.
20
+ *
21
+ * | status | meaning | gate |
22
+ * | ------------------ | ---------------------------------------------------------------- | --------------- |
23
+ * | `unauthenticated` | the server answered that there is no session | signed out |
24
+ * | `loading` | the first identity resolve is in flight | loading |
25
+ * | `authenticated` | the server returned a user | authenticated |
26
+ * | `unreachable` | a credential is held but the identity endpoint could not be reached | authenticated |
27
+ *
28
+ * No row says "no bearer token". A **cookie session carries no token here** —
29
+ * it is better-auth's default, what `@lunora/auth-ui` is built on, and what
30
+ * `examples/auth-playground` ships (`createAuthClient` plus
31
+ * `new LunoraClient({ url })`, never `setAuthToken`). Answering
32
+ * `unauthenticated` off a null token alone declared every user of every such
33
+ * app signed out without asking the server, which also left
34
+ * `LunoraClient`'s identity fingerprint `null` for all of them — and a
35
+ * fingerprint that is `null` for everyone is what turns the offline-queue,
36
+ * read-cache and socket identity gates into `null === null`. The first resolve
37
+ * therefore ALWAYS asks; only after an answer does a cleared token
38
+ * short-circuit.
39
+ *
40
+ * `unreachable` counts as authenticated because the **credential** is what
41
+ * authorises requests; a failed identity round-trip is a fact about the network,
42
+ * not about the session. Treating it as signed out turns every offline reload
43
+ * into a sign-out, and treating it as loading spins a fallback for the whole
44
+ * offline period — both of which shipped.
45
+ *
46
+ * The consequence a UI has to respect: `user` may be `null` while the gate says
47
+ * authenticated. Branch on `status`, never on `user === null`, to tell "signed
48
+ * out" from "signed in, identity not resolved yet".
49
+ */
50
+ import { L as LunoraClient, U as User } from "../packem_shared/lunora-client.d-TchceUzJ.js";
51
+ import { LunoraAdminClient } from "../admin/index.js";
52
+ import { AuthPage, AuthImpersonation, AuthSession, AuthUser } from '@lunora/runtime';
53
+ import '@lunora/errors';
54
+ import "../packem_shared/function-reference.d-Br_hsKje.js";
55
+ /** Default page size for the first read; a "load more" grows the requested window by the page size. */
56
+ declare const ADMIN_AUTH_DEFAULT_PAGE_SIZE = 50;
57
+ /** One paged admin-auth collection: the key that identifies its inputs, and how to read a `{ limit }` window from the top. */
58
+ interface AdminAuthList<T> {
59
+ /** Read the first `limit` rows. `AuthPage` is offset/limit-based, so a larger window re-reads from the top rather than appending. */
60
+ readonly fetchPage: (limit: number) => Promise<AuthPage<T>>;
61
+ /** Every input that should invalidate the cache — not `fetchPage`, which is a fresh closure per call. */
62
+ readonly key: ReadonlyArray<unknown>;
63
+ }
64
+ /** Search / filter / sort inputs for {@link authUsersList}. */
65
+ interface AuthUsersListFilter {
66
+ filterField?: string;
67
+ filterValue?: string;
68
+ search?: string;
69
+ searchField?: string;
70
+ sortBy?: string;
71
+ sortDirection?: "asc" | "desc";
72
+ }
73
+ /** Users, via the admin-gated `GET /_lunora/admin/auth/users` (`client.listAuthUsers`). */
74
+ declare const authUsersList: (client: LunoraAdminClient, filter?: AuthUsersListFilter) => AdminAuthList<AuthUser>;
75
+ /** Organizations (better-auth `organization` plugin), via `client.listAuthOrganizations`. */
76
+ declare const authOrganizationsList: (client: LunoraAdminClient) => AdminAuthList<Record<string, unknown>>;
77
+ /** Sign-up invitations (`inviteOnly` plugin), via `client.listAuthSignUpInvitations`. Rows are unfiltered and newest-first. */
78
+ declare const authSignUpInvitationsList: (client: LunoraAdminClient) => AdminAuthList<Record<string, unknown>>;
79
+ /** Auth sessions, optionally scoped to one user, via `client.listAuthSessions`. */
80
+ declare const authSessionsList: (client: LunoraAdminClient, options?: {
81
+ userId?: string;
82
+ }) => AdminAuthList<AuthSession>;
83
+ /**
84
+ * The cache key for one window of an admin list: `[namespace, identity, ...list.key, limit]`.
85
+ *
86
+ * The acting identity (slot 1) partitions the cache, or a credential swap on the
87
+ * same client (admin A → admin B) would serve A's cached rows to B until the
88
+ * refetch lands. It is `client.currentIdentity()` — a `subj:` label or a
89
+ * non-reversible token hash — never the bearer token: query keys are not
90
+ * private (persisters write them to `localStorage`, devtools render them,
91
+ * telemetry logs them), and a same-user token refresh keeps the same key.
92
+ *
93
+ * An adapter that keeps the previous window visible while a larger one loads
94
+ * must only do so when slot 1 is unchanged, so one identity's rows never stand
95
+ * in for another's.
96
+ */
97
+ declare const adminAuthListQueryKey: (identity: string | null, list: AdminAuthList<unknown>, limit: number) => ReadonlyArray<unknown>;
98
+ /**
99
+ * Subscribe to every change of `client.currentIdentity()`. Both signals are
100
+ * needed: a bearer swap fires `onAuthTokenChange`, while a cookie session's
101
+ * user switch or sign-out fires only `onIdentityChange` (no token changes
102
+ * hands) — subscribing to one leaves the other's previous rows on screen.
103
+ */
104
+ declare const subscribeAdminAuthIdentity: (client: LunoraClient, onChange: () => void) => (() => void);
105
+ /** `true` when the server reports rows beyond the loaded window; `false` before the first page resolves, so "load more" past the end is a no-op. */
106
+ declare const adminAuthListHasMore: (page: AuthPage<unknown> | undefined) => boolean;
107
+ /** Query options for one window of an admin list, spread into a TanStack hook (the `lunoraQueryOptions` pattern). */
108
+ interface AdminAuthListQueryOptions<T> {
109
+ readonly queryFn: () => Promise<AuthPage<T>>;
110
+ readonly queryKey: ReadonlyArray<unknown>;
111
+ readonly staleTime: number;
112
+ }
113
+ /**
114
+ * Options for one `{ limit }` window of an admin list. `staleTime` is `0`, not the
115
+ * provider's `Infinity`: this is a one-shot HTTP read, so a remount or a window
116
+ * refocus should re-fetch rather than serve the cached page indefinitely.
117
+ */
118
+ declare const adminAuthListQueryOptions: <T>(list: AdminAuthList<T>, identity: string | null, limit: number) => AdminAuthListQueryOptions<T>;
119
+ /**
120
+ * The page to show while a larger window of the same list loads. Only the previous
121
+ * window from the same identity may stand in: another identity's rows must never be
122
+ * shown while its first read is in flight.
123
+ */
124
+ declare const adminAuthListPlaceholder: <T>(previous: AuthPage<T> | undefined, previousKey: ReadonlyArray<unknown> | undefined, queryKey: ReadonlyArray<unknown>) => AuthPage<T> | undefined;
125
+ /** The `limit` after a "load more": one page larger, and unchanged past the end of the collection. */
126
+ declare const nextAdminAuthLimit: (current: number, pageSize: number, hasMore: boolean) => number;
127
+ /**
128
+ * Mutation options for minting an impersonation session. It deliberately does not call
129
+ * `client.setAuthToken`: swapping the acting client's own token would sign the admin out
130
+ * of their admin session without a visible transition.
131
+ */
132
+ declare const adminAuthImpersonateMutation: (client: LunoraAdminClient) => {
133
+ readonly mutationFn: (userId: string) => Promise<AuthImpersonation>;
134
+ };
135
+ /**
136
+ * Every {@link AuthStatus}, as a value — the contract table in this module's
137
+ * header, and the `@lunora/client` docs table that restates it for consumers,
138
+ * are both asserted against this list (`auth-status-docs.test.ts`), so a new
139
+ * state cannot ship undocumented.
140
+ */
141
+ declare const AUTH_STATUSES: readonly ["authenticated", "loading", "unauthenticated", "unreachable"];
142
+ /**
143
+ * Resolved authentication state. See the contract table in this module's header
144
+ * — the states are not interchangeable, and `unreachable` is the one that exists
145
+ * only so "the server said no session" and "we could not ask" stop colliding.
146
+ */
147
+ type AuthStatus = (typeof AUTH_STATUSES)[number];
148
+ /**
149
+ * Whether a gate should render its authenticated branch.
150
+ *
151
+ * Both `authenticated` and `unreachable` qualify: the credential is held in
152
+ * either case, and only the identity round-trip differs.
153
+ */
154
+ declare const isAuthenticatedStatus: (status: AuthStatus) => boolean;
155
+ /** Whether a gate should render its loading branch — the first resolve only. */
156
+ declare const isLoadingStatus: (status: AuthStatus) => boolean;
3
157
  interface IdentityStore {
4
- /** Read the current resolved user, or `null` when signed out / not yet resolved. */
158
+ /** The current {@link AuthStatus} — what a gate branches on. */
159
+ getStatus: () => AuthStatus;
160
+ /**
161
+ * The last resolved user, or `null`. `null` does NOT mean signed out on its
162
+ * own: read `getStatus` for that. A user resolved before the endpoint
163
+ * went unreachable is retained, so the UI keeps rendering the identity it
164
+ * last knew instead of blanking.
165
+ */
5
166
  getUser: () => User | null;
6
167
  /**
7
- * Subscribe to identity changes. `onChange` is called whenever the user or
8
- * token changes. Returns an unsubscribe handle.
9
- */
168
+ * Subscribe to identity changes. `onChange` is called whenever the user or
169
+ * the status changes. Returns an unsubscribe handle.
170
+ */
10
171
  subscribe: (onChange: () => void) => () => void;
11
172
  }
12
173
  /**
13
- * Return the per-client identity store, creating it on first access.
14
- *
15
- * The store is cached via a `WeakMap` so it is GC'd when the client is dropped,
16
- * and creation is idempotent — calling this multiple times with the same client
17
- * returns the same store, keeping the single-fetch / fan-out invariant.
18
- */
174
+ * Return the per-client identity store, creating it on first access.
175
+ *
176
+ * The store is cached via a `WeakMap` so it is GC'd when the client is dropped,
177
+ * and creation is idempotent — calling this multiple times with the same client
178
+ * returns the same store, keeping the single-fetch / fan-out invariant.
179
+ */
19
180
  declare const getIdentityStore: (client: LunoraClient) => IdentityStore;
20
- export { type IdentityStore, getIdentityStore };
181
+ export { ADMIN_AUTH_DEFAULT_PAGE_SIZE, AUTH_STATUSES, type AdminAuthList, type AdminAuthListQueryOptions, type AuthStatus, type AuthUsersListFilter, type IdentityStore, adminAuthImpersonateMutation, adminAuthListHasMore, adminAuthListPlaceholder, adminAuthListQueryKey, adminAuthListQueryOptions, authOrganizationsList, authSessionsList, authSignUpInvitationsList, authUsersList, getIdentityStore, isAuthenticatedStatus, isLoadingStatus, nextAdminAuthLimit, subscribeAdminAuthIdentity };
@@ -1,60 +1 @@
1
- const stores = /* @__PURE__ */ new WeakMap();
2
- const createIdentityStore = (client) => {
3
- const listeners = /* @__PURE__ */ new Set();
4
- let user = null;
5
- let started = false;
6
- const notify = () => {
7
- for (const listener of listeners) {
8
- listener();
9
- }
10
- };
11
- let generation = 0;
12
- const setUser = (next) => {
13
- if (user !== next) {
14
- user = next;
15
- notify();
16
- }
17
- };
18
- const refresh = () => {
19
- generation += 1;
20
- const current = generation;
21
- if (client.getAuthToken() === null) {
22
- setUser(null);
23
- return;
24
- }
25
- client.getCurrentUser().then((next) => {
26
- if (current === generation) {
27
- setUser(next);
28
- }
29
- return void 0;
30
- }).catch(() => {
31
- if (current === generation) {
32
- setUser(null);
33
- }
34
- });
35
- };
36
- client.onAuthTokenChange(refresh);
37
- return {
38
- getUser: () => user,
39
- subscribe: (onChange) => {
40
- listeners.add(onChange);
41
- if (!started) {
42
- started = true;
43
- refresh();
44
- }
45
- return () => {
46
- listeners.delete(onChange);
47
- };
48
- }
49
- };
50
- };
51
- const getIdentityStore = (client) => {
52
- let store = stores.get(client);
53
- if (!store) {
54
- store = createIdentityStore(client);
55
- stores.set(client, store);
56
- }
57
- return store;
58
- };
59
-
60
- export { getIdentityStore };
1
+ import{ADMIN_AUTH_DEFAULT_PAGE_SIZE as T,adminAuthImpersonateMutation as p,adminAuthListHasMore as U,adminAuthListPlaceholder as k,adminAuthListQueryKey as _,adminAuthListQueryOptions as v,authOrganizationsList as E,authSessionsList as M,authSignUpInvitationsList as w,authUsersList as C,nextAdminAuthLimit as H,subscribeAdminAuthIdentity as D}from"../packem_shared/ADMIN_AUTH_DEFAULT_PAGE_SIZE-aKbm8N1z.mjs";const S=["authenticated","loading","unauthenticated","unreachable"],y=t=>t==="authenticated"||t==="unreachable",L=t=>t==="loading",f=new WeakMap,g=t=>{const n=new Set;let u=null,r="loading",h=!1,c=!1,a;const A=()=>{for(const e of n)e()};let o=0;const i=(e,s)=>{(r!==e||u!==s)&&(r=e,u=s,A())},d=(e=!1)=>{o+=1;const s=o;if(!e&&t.getAuthToken()===null&&c){i("unauthenticated",null);return}i(u===null?"loading":"authenticated",u),t.getCurrentUser().then(l=>{s===o&&(c=!0,i(l===null?"unauthenticated":"authenticated",l),l!==null&&a===`subj:${l.id}`&&(a=void 0))}).catch(()=>{a=void 0,s===o&&i("unreachable",u)})};return t.expectIdentityResolution(),t.onAuthTokenChange(()=>{d()}),t.onIdentityChange(()=>{if(!h||t.getAuthToken()!==null)return;const e=t.currentIdentity();e===null?i("unauthenticated",null):e!==a&&(a=e,d(!0))}),t.onConnectionStatus(e=>{e==="connected"&&r==="unreachable"&&d(!0)}),{getStatus:()=>r,getUser:()=>u,subscribe:e=>(n.add(e),h||(h=!0,d()),()=>{n.delete(e)})}},m=t=>{let n=f.get(t);return n||(n=g(t),f.set(t,n)),n};export{T as ADMIN_AUTH_DEFAULT_PAGE_SIZE,S as AUTH_STATUSES,p as adminAuthImpersonateMutation,U as adminAuthListHasMore,k as adminAuthListPlaceholder,_ as adminAuthListQueryKey,v as adminAuthListQueryOptions,E as authOrganizationsList,M as authSessionsList,w as authSignUpInvitationsList,C as authUsersList,m as getIdentityStore,y as isAuthenticatedStatus,L as isLoadingStatus,H as nextAdminAuthLimit,D as subscribeAdminAuthIdentity};