@lunora/client 1.0.0-alpha.29 → 1.0.0-alpha.291
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/LICENSE.md +201 -104
- package/README.md +22 -7
- package/dist/admin/index.d.mts +689 -0
- package/dist/admin/index.d.ts +689 -0
- package/dist/admin/index.mjs +1 -0
- package/dist/auth/index.d.mts +166 -5
- package/dist/auth/index.d.ts +166 -5
- package/dist/auth/index.mjs +1 -1
- package/dist/index.d.mts +757 -187
- package/dist/index.d.ts +757 -187
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/ADMIN_AUTH_DEFAULT_PAGE_SIZE-aKbm8N1z.mjs +1 -0
- package/dist/packem_shared/CONFLICT_ERROR_CODE-B7qNZMMk.mjs +1 -0
- package/dist/packem_shared/DEFAULT_MAX_BUFFER-Bd-_iyiV.mjs +1 -0
- package/dist/packem_shared/LunoraAdminClient-BkGFB5ra.mjs +1 -0
- package/dist/packem_shared/LunoraClient--R-NfrXm.mjs +1 -0
- package/dist/packem_shared/OfflineQueue-Ba2qgZK1.mjs +1 -0
- package/dist/packem_shared/RETIRE_AFTER_DURABLE_SEQ_ADVANCE-DoEHtuR8.mjs +1 -0
- package/dist/packem_shared/SKIP-d7LeP-sY.mjs +1 -0
- package/dist/packem_shared/SubscriptionRegistry-_FfLskdB.mjs +1 -0
- package/dist/packem_shared/TabCoordinator-IUCwjnqX.mjs +1 -0
- package/dist/packem_shared/applyDelta-CaudNj2C.mjs +1 -0
- package/dist/packem_shared/base64-849R7V-V.mjs +1 -0
- package/dist/packem_shared/client-tuning-C10B2KCO.mjs +1 -0
- package/dist/packem_shared/client-urls-BHLUjjcG.mjs +1 -0
- package/dist/packem_shared/connectLiveStream-BdjsWP1-.mjs +1 -0
- package/dist/packem_shared/createAsyncStoragePersistence-BgfdvLwe.mjs +1 -0
- package/dist/packem_shared/createAsyncStorageQueryCache-6Y94ocbQ.mjs +1 -0
- package/dist/packem_shared/createCallRunner-Bwcrfh76.mjs +1 -0
- package/dist/packem_shared/createClientQuery-B8Nfj-7o.mjs +1 -0
- package/dist/packem_shared/createInMemoryBookmarkStorage-BooZhW0n.mjs +1 -0
- package/dist/packem_shared/createInMemoryPersistence-C-IzNVbg.mjs +1 -0
- package/dist/packem_shared/createInMemoryQueryCache-DR6AorA2.mjs +1 -0
- package/dist/packem_shared/createLocalStore-CDCtdy5O.mjs +1 -0
- package/dist/packem_shared/createMutatorRunner-CuMRJpUx.mjs +1 -0
- package/dist/packem_shared/createReconnect-CjTmjJDH.mjs +1 -0
- package/dist/packem_shared/createServerClient-DEvfqFbl.mjs +1 -0
- package/dist/packem_shared/createSnapshotPrecondition-BXP1NPBW.mjs +1 -0
- package/dist/packem_shared/delta-merge-C6OqMEPH.mjs +1 -0
- package/dist/packem_shared/deserializePreloaded-DxozvweR.mjs +1 -0
- package/dist/packem_shared/frame-hint-D-NK691z.mjs +1 -0
- package/dist/packem_shared/function-reference.d-Br_hsKje.d.mts +45 -0
- package/dist/packem_shared/function-reference.d-Br_hsKje.d.ts +45 -0
- package/dist/packem_shared/getServerSession-BaOoo1p6.mjs +1 -0
- package/dist/packem_shared/httpStream-DN3D9WqW.mjs +7 -0
- package/dist/packem_shared/idb-utility-BS7xvou1.mjs +1 -0
- package/dist/packem_shared/live-stream-DBKgZlnb.mjs +10 -0
- package/dist/packem_shared/liveTopicSubscription-DQtKMFKw.mjs +1 -0
- package/dist/packem_shared/lunora-client-joBzs47U.mjs +1 -0
- package/dist/packem_shared/lunora-client.d-DKfDdnjJ.d.ts +4999 -0
- package/dist/packem_shared/lunora-client.d-Ezp1eG81.d.mts +4999 -0
- package/dist/packem_shared/lunoraQueryKey-CucWmxnx.mjs +1 -0
- package/dist/packem_shared/offline-queue-BEqCPDmw.mjs +1 -0
- package/dist/packem_shared/optimistic-layers-D-7D3yeJ.mjs +1 -0
- package/dist/packem_shared/{preload.d-DGGRMWB5.d.ts → preload.d-qnL9TXVr.d.mts} +2 -1
- package/dist/packem_shared/{preload.d-BmztUzzG.d.mts → preload.d-wJ_ggZsg.d.ts} +2 -1
- package/dist/packem_shared/preloadQuery-uFy24PCR.mjs +1 -0
- package/dist/packem_shared/setAuthTokenProvider-DhBppDiZ.mjs +1 -0
- package/dist/packem_shared/single-blob-store-DeaYPBSS.mjs +1 -0
- package/dist/packem_shared/snapshot-precondition-BEtcSbWr.mjs +1 -0
- package/dist/packem_shared/stream-idle-C7CsIT_m.mjs +1 -0
- package/dist/packem_shared/wire-errors-BDckSTKZ.mjs +1 -0
- package/dist/pagination/index.d.mts +30 -1
- package/dist/pagination/index.d.ts +30 -1
- package/dist/pagination/index.mjs +1 -1
- package/dist/query/index.d.mts +143 -4
- package/dist/query/index.d.ts +143 -4
- package/dist/query/index.mjs +1 -1
- package/dist/service.d.mts +49 -0
- package/dist/service.d.ts +49 -0
- package/dist/service.mjs +1 -0
- package/dist/ssr/index.d.mts +45 -16
- package/dist/ssr/index.d.ts +45 -16
- package/dist/ssr/index.mjs +1 -1
- package/dist/upload.d.mts +14 -0
- package/dist/upload.d.ts +14 -0
- package/dist/upload.mjs +1 -1
- package/package.json +16 -4
- package/dist/packem_shared/CONFLICT_ERROR_CODE-B2SU0CaJ.mjs +0 -1
- package/dist/packem_shared/ClientServiceWorker-CRQ5yl7-.mjs +0 -1
- package/dist/packem_shared/DEFAULT_MAX_BUFFER-TBn2s7Rz.mjs +0 -1
- package/dist/packem_shared/LunoraClient-DDEoZdgP.mjs +0 -1
- package/dist/packem_shared/OfflineQueue-B603_q8m.mjs +0 -1
- package/dist/packem_shared/SKIP-CArzT3Vl.mjs +0 -1
- package/dist/packem_shared/SubscriptionRegistry-CdrOD7sZ.mjs +0 -1
- package/dist/packem_shared/TabCoordinator-ijLic02x.mjs +0 -1
- package/dist/packem_shared/applyDelta-DXqQORbM.mjs +0 -1
- package/dist/packem_shared/createAsyncStoragePersistence-BRLqeXsC.mjs +0 -1
- package/dist/packem_shared/createClientQuery-CrdRoicO.mjs +0 -1
- package/dist/packem_shared/createInMemoryBookmarkStorage-DCd5Ej-t.mjs +0 -1
- package/dist/packem_shared/createInMemoryPersistence-CQYXy8UP.mjs +0 -1
- package/dist/packem_shared/createInMemoryQueryCache-DjCKrLjk.mjs +0 -1
- package/dist/packem_shared/createLocalStore-B3Tw_Tw1.mjs +0 -1
- package/dist/packem_shared/createMutationRunner-lQXH8Amk.mjs +0 -1
- package/dist/packem_shared/createMutatorRunner-BVzo0FBZ.mjs +0 -1
- package/dist/packem_shared/createReconnect-CFT7YRSR.mjs +0 -1
- package/dist/packem_shared/createReply-DF0jRsv-.mjs +0 -1
- package/dist/packem_shared/createServerClient-B7KqO8tv.mjs +0 -1
- package/dist/packem_shared/createSnapshotPrecondition-DOKRAJ4b.mjs +0 -1
- package/dist/packem_shared/deserializePreloaded-CHfOFpka.mjs +0 -1
- package/dist/packem_shared/getServerSession-CGjgRBAE.mjs +0 -1
- package/dist/packem_shared/httpStream-Cz4_QyjV.mjs +0 -11
- package/dist/packem_shared/idb-utility-C-DR8nG1.mjs +0 -1
- package/dist/packem_shared/local-store-C53xDvEr.mjs +0 -1
- package/dist/packem_shared/lunora-client.d-Bt65hm_E.d.mts +0 -2979
- package/dist/packem_shared/lunora-client.d-Bt65hm_E.d.ts +0 -2979
- package/dist/packem_shared/offline-queue-D73Dq95V.mjs +0 -1
- package/dist/packem_shared/preloadQuery-DjwSjFwt.mjs +0 -1
- package/dist/packem_shared/wire-key-D_zOxXK4.mjs +0 -1
package/dist/auth/index.d.mts
CHANGED
|
@@ -1,11 +1,172 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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-Ezp1eG81.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
|
-
/**
|
|
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
168
|
* Subscribe to identity changes. `onChange` is called whenever the user or
|
|
8
|
-
*
|
|
169
|
+
* the status changes. Returns an unsubscribe handle.
|
|
9
170
|
*/
|
|
10
171
|
subscribe: (onChange: () => void) => () => void;
|
|
11
172
|
}
|
|
@@ -17,4 +178,4 @@ interface IdentityStore {
|
|
|
17
178
|
* returns the same store, keeping the single-fetch / fan-out invariant.
|
|
18
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 };
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,11 +1,172 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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-DKfDdnjJ.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
|
-
/**
|
|
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
168
|
* Subscribe to identity changes. `onChange` is called whenever the user or
|
|
8
|
-
*
|
|
169
|
+
* the status changes. Returns an unsubscribe handle.
|
|
9
170
|
*/
|
|
10
171
|
subscribe: (onChange: () => void) => () => void;
|
|
11
172
|
}
|
|
@@ -17,4 +178,4 @@ interface IdentityStore {
|
|
|
17
178
|
* returns the same store, keeping the single-fetch / fan-out invariant.
|
|
18
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 };
|
package/dist/auth/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
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};
|