@zautha/react 0.10.0 → 0.11.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/dist/index.cjs +196 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +88 -2
- package/dist/index.d.mts +88 -2
- package/dist/index.mjs +193 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -68,6 +68,105 @@ function useZauthaState() {
|
|
|
68
68
|
return (0, react.useSyncExternalStore)(zautha?.subscribe ?? noop, () => zautha?.getSnapshot() ?? pending, () => pending);
|
|
69
69
|
}
|
|
70
70
|
//#endregion
|
|
71
|
+
//#region src/pagination.ts
|
|
72
|
+
/**
|
|
73
|
+
* The pages of one list. Without a source nothing is read and the list is empty; a source with a new key starts again on
|
|
74
|
+
* the initial page. A response to an older request (another page, key or revalidation) is dropped, so it never
|
|
75
|
+
* overwrites a newer one.
|
|
76
|
+
*/
|
|
77
|
+
function usePages(source, params) {
|
|
78
|
+
const key = source?.key ?? null;
|
|
79
|
+
const { pageSize = 10, initialPage = 1 } = params === true || params === void 0 ? {} : params;
|
|
80
|
+
const [at, setAt] = (0, react.useState)({
|
|
81
|
+
key,
|
|
82
|
+
page: initialPage,
|
|
83
|
+
version: 0
|
|
84
|
+
});
|
|
85
|
+
const [settled, setSettled] = (0, react.useState)(null);
|
|
86
|
+
const latest = (0, react.useRef)(0);
|
|
87
|
+
const waiting = (0, react.useRef)([]);
|
|
88
|
+
if (at.key !== key) {
|
|
89
|
+
setAt({
|
|
90
|
+
key,
|
|
91
|
+
page: initialPage,
|
|
92
|
+
version: 0
|
|
93
|
+
});
|
|
94
|
+
setSettled(null);
|
|
95
|
+
}
|
|
96
|
+
const { page, version } = at.key === key ? at : {
|
|
97
|
+
page: initialPage,
|
|
98
|
+
version: 0
|
|
99
|
+
};
|
|
100
|
+
const request = JSON.stringify([
|
|
101
|
+
key,
|
|
102
|
+
page,
|
|
103
|
+
pageSize,
|
|
104
|
+
version
|
|
105
|
+
]);
|
|
106
|
+
const loader = (0, react.useRef)(source?.load);
|
|
107
|
+
(0, react.useEffect)(() => {
|
|
108
|
+
loader.current = source?.load;
|
|
109
|
+
});
|
|
110
|
+
(0, react.useEffect)(() => {
|
|
111
|
+
const id = ++latest.current;
|
|
112
|
+
const settle = (data, count, error) => {
|
|
113
|
+
if (latest.current !== id) return;
|
|
114
|
+
if (key !== null) setSettled({
|
|
115
|
+
request,
|
|
116
|
+
key,
|
|
117
|
+
page,
|
|
118
|
+
data,
|
|
119
|
+
count,
|
|
120
|
+
error
|
|
121
|
+
});
|
|
122
|
+
for (const resolve of waiting.current.splice(0)) resolve();
|
|
123
|
+
};
|
|
124
|
+
if (key === null || loader.current === void 0) return settle([], 0, null);
|
|
125
|
+
loader.current({
|
|
126
|
+
limit: pageSize,
|
|
127
|
+
offset: (page - 1) * pageSize
|
|
128
|
+
}).then((r) => settle(r.data, r.totalCount, null), (error) => settle([], 0, error instanceof Error ? error : new Error(String(error))));
|
|
129
|
+
}, [request]);
|
|
130
|
+
const shown = settled !== null && settled.key === key && settled.page === page ? settled : null;
|
|
131
|
+
const isFetching = key !== null && settled?.request !== request;
|
|
132
|
+
const count = shown?.count ?? 0;
|
|
133
|
+
const pageCount = Math.ceil(count / pageSize);
|
|
134
|
+
const go = (0, react.useCallback)((to) => setAt((a) => {
|
|
135
|
+
const from = a.key === key ? a.page : initialPage;
|
|
136
|
+
return {
|
|
137
|
+
key,
|
|
138
|
+
page: Math.max(1, to(from)),
|
|
139
|
+
version: a.key === key ? a.version : 0
|
|
140
|
+
};
|
|
141
|
+
}), [key, initialPage]);
|
|
142
|
+
const revalidate = (0, react.useCallback)(() => new Promise((resolve) => {
|
|
143
|
+
waiting.current.push(resolve);
|
|
144
|
+
setAt((a) => a.key === key ? {
|
|
145
|
+
...a,
|
|
146
|
+
version: a.version + 1
|
|
147
|
+
} : {
|
|
148
|
+
key,
|
|
149
|
+
page: initialPage,
|
|
150
|
+
version: 1
|
|
151
|
+
});
|
|
152
|
+
}), [key, initialPage]);
|
|
153
|
+
return {
|
|
154
|
+
data: shown?.data ?? [],
|
|
155
|
+
count,
|
|
156
|
+
page,
|
|
157
|
+
pageCount,
|
|
158
|
+
isLoading: isFetching && shown === null,
|
|
159
|
+
isFetching,
|
|
160
|
+
error: shown?.error ?? null,
|
|
161
|
+
hasNextPage: page < pageCount,
|
|
162
|
+
hasPreviousPage: page > 1,
|
|
163
|
+
fetchNext: (0, react.useCallback)(() => go((p) => p + 1), [go]),
|
|
164
|
+
fetchPrevious: (0, react.useCallback)(() => go((p) => p - 1), [go]),
|
|
165
|
+
fetchPage: (0, react.useCallback)((n) => go(() => n), [go]),
|
|
166
|
+
revalidate
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
//#endregion
|
|
71
170
|
//#region src/hooks.ts
|
|
72
171
|
const isLoadedStatus = (status) => status === "ready" || status === "degraded";
|
|
73
172
|
/** The signed-in session: a pending one (tasks left, e.g. setting up two-step verification) counts as signed out. */
|
|
@@ -169,6 +268,80 @@ function useSignUp() {
|
|
|
169
268
|
fetchStatus: snapshot?.fetchStatus ?? "idle"
|
|
170
269
|
};
|
|
171
270
|
}
|
|
271
|
+
/** A list's filters: its params without the page size and the first page. */
|
|
272
|
+
function filtersOf(params) {
|
|
273
|
+
const filters = { ...params === true ? {} : params };
|
|
274
|
+
delete filters.pageSize;
|
|
275
|
+
delete filters.initialPage;
|
|
276
|
+
return filters;
|
|
277
|
+
}
|
|
278
|
+
/** A list of `owner` read with `load`: its key (`owner` and the params, so new filters start the list again). */
|
|
279
|
+
const list = (owner, params, load) => ({
|
|
280
|
+
key: `${owner}:${JSON.stringify(params)}`,
|
|
281
|
+
load
|
|
282
|
+
});
|
|
283
|
+
/** The signed-in user (an active session's) and whether hooks that read it are loaded. */
|
|
284
|
+
function useSignedInUser() {
|
|
285
|
+
const zautha = useZautha();
|
|
286
|
+
const state = useZauthaState();
|
|
287
|
+
const user = activeSession(state) === null ? null : zautha?.user ?? null;
|
|
288
|
+
return {
|
|
289
|
+
isLoaded: isLoadedStatus(state.status) && (activeSession(state) === null || user !== null),
|
|
290
|
+
state,
|
|
291
|
+
user
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* The session's active organization and the user's membership of it, from the session token and the user (no request of
|
|
296
|
+
* its own), and on request its members and invitations, page by page. The lists start again on their first page when
|
|
297
|
+
* the active organization changes.
|
|
298
|
+
*/
|
|
299
|
+
function useOrganization(params = {}) {
|
|
300
|
+
const { isLoaded, state, user } = useSignedInUser();
|
|
301
|
+
const id = state.organization?.id;
|
|
302
|
+
const membership = user?.organizationMemberships.find((m) => m.organization.id === id) ?? null;
|
|
303
|
+
const organization = membership?.organization ?? null;
|
|
304
|
+
const owner = membership === null ? "" : `${membership.publicUserData.userId}:${membership.organization.id}`;
|
|
305
|
+
const { memberships, invitations } = params;
|
|
306
|
+
const manages = membership?.permissions.includes("org:sys_memberships:manage") === true;
|
|
307
|
+
const members = usePages(organization === null || memberships === void 0 ? null : list(owner, memberships, (page) => organization.getMemberships({
|
|
308
|
+
...filtersOf(memberships),
|
|
309
|
+
...page
|
|
310
|
+
})), memberships);
|
|
311
|
+
const invited = usePages(organization === null || invitations === void 0 || !manages ? null : list(owner, invitations, (page) => organization.getInvitations({
|
|
312
|
+
...filtersOf(invitations),
|
|
313
|
+
...page
|
|
314
|
+
})), invitations);
|
|
315
|
+
return {
|
|
316
|
+
isLoaded,
|
|
317
|
+
organization,
|
|
318
|
+
membership,
|
|
319
|
+
...memberships === void 0 ? {} : { memberships: members },
|
|
320
|
+
...invitations === void 0 ? {} : { invitations: invited }
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Creating an organization and choosing the active one, and on request the user's memberships and the invitations to
|
|
325
|
+
* the user, page by page.
|
|
326
|
+
*/
|
|
327
|
+
function useOrganizationList(params = {}) {
|
|
328
|
+
const zautha = useZautha();
|
|
329
|
+
const { isLoaded, user } = useSignedInUser();
|
|
330
|
+
const { userMemberships, userInvitations } = params;
|
|
331
|
+
const memberships = usePages(user === null || userMemberships === void 0 ? null : list(user.id, userMemberships, (page) => user.getOrganizationMemberships(page)), userMemberships);
|
|
332
|
+
const invitations = usePages(user === null || userInvitations === void 0 ? null : list(user.id, userInvitations, (page) => user.getOrganizationInvitations({
|
|
333
|
+
...filtersOf(userInvitations),
|
|
334
|
+
...page
|
|
335
|
+
})), userInvitations);
|
|
336
|
+
return {
|
|
337
|
+
isLoaded,
|
|
338
|
+
createOrganization: (0, react.useCallback)((p) => zautha?.createOrganization(p) ?? notLoaded(), [zautha]),
|
|
339
|
+
setActive: (0, react.useCallback)((p) => zautha?.setActive(p) ?? notLoaded(), [zautha]),
|
|
340
|
+
...userMemberships === void 0 ? {} : { userMemberships: memberships },
|
|
341
|
+
...userInvitations === void 0 ? {} : { userInvitations: invitations }
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
const notLoaded = () => Promise.reject(new _zautha_js.ZauthaError("Zautha is not loaded yet."));
|
|
172
345
|
//#endregion
|
|
173
346
|
//#region src/control.tsx
|
|
174
347
|
/**
|
|
@@ -334,9 +507,30 @@ function OAuthConsent(props) {
|
|
|
334
507
|
componentProps: props
|
|
335
508
|
});
|
|
336
509
|
}
|
|
510
|
+
function CreateOrganization(props) {
|
|
511
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Mounted, {
|
|
512
|
+
name: "CreateOrganization",
|
|
513
|
+
componentProps: props
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
function OrganizationProfile(props) {
|
|
517
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Mounted, {
|
|
518
|
+
name: "OrganizationProfile",
|
|
519
|
+
componentProps: props
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
function OrganizationSwitcher(props) {
|
|
523
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Mounted, {
|
|
524
|
+
name: "OrganizationSwitcher",
|
|
525
|
+
componentProps: props
|
|
526
|
+
});
|
|
527
|
+
}
|
|
337
528
|
//#endregion
|
|
338
529
|
exports.AuthenticateWithRedirectCallback = AuthenticateWithRedirectCallback;
|
|
530
|
+
exports.CreateOrganization = CreateOrganization;
|
|
339
531
|
exports.OAuthConsent = OAuthConsent;
|
|
532
|
+
exports.OrganizationProfile = OrganizationProfile;
|
|
533
|
+
exports.OrganizationSwitcher = OrganizationSwitcher;
|
|
340
534
|
exports.RedirectToSignIn = RedirectToSignIn;
|
|
341
535
|
exports.RedirectToSignUp = RedirectToSignUp;
|
|
342
536
|
Object.defineProperty(exports, "ReverificationCancelledError", {
|
|
@@ -449,6 +643,8 @@ Object.defineProperty(exports, "isZauthaPasskeyError", {
|
|
|
449
643
|
}
|
|
450
644
|
});
|
|
451
645
|
exports.useAuth = useAuth;
|
|
646
|
+
exports.useOrganization = useOrganization;
|
|
647
|
+
exports.useOrganizationList = useOrganizationList;
|
|
452
648
|
exports.useReverification = useReverification;
|
|
453
649
|
exports.useSession = useSession;
|
|
454
650
|
exports.useSignIn = useSignIn;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["createContext","useState","Zautha","useMemo","useContext","useSyncExternalStore","useCallback","checkAuthorization","useRef","withReverification","useSyncExternalStore","Children","isValidElement","cloneElement","useRef"],"sources":["../src/provider.tsx","../src/hooks.ts","../src/control.tsx","../src/buttons.tsx","../src/prebuilt.tsx"],"sourcesContent":["import { Zautha, type ZauthaOptions, type ZauthaState } from \"@zautha/js\";\nimport { createContext, useContext, useEffect, useMemo, useState, useSyncExternalStore, type ReactNode } from \"react\";\n\ninterface ZauthaContextValue {\n readonly zautha: Zautha | null;\n /** The snapshot before the instance exists and during server rendering (carries `initialState`). */\n readonly pending: ZauthaState;\n}\n\nconst ZauthaContext = createContext<ZauthaContextValue | undefined>(undefined);\n\nexport interface ZauthaProviderProps extends Omit<ZauthaOptions, \"fetch\"> {\n publishableKey: string;\n children?: ReactNode;\n}\n\n/**\n * Creates the Zautha instance after mount (never during render, so StrictMode's double mount and SSR\n * create no timers or channels), loads it, and disposes it on unmount. Until then hooks report\n * `isLoaded: false`, unless `initialState` (the server's view, e.g. from @zautha/nextjs) says who is signed in.\n */\nexport function ZauthaProvider({ publishableKey, children, ...options }: ZauthaProviderProps): ReactNode {\n const [zautha, setZautha] = useState<Zautha | null>(null);\n const { ui, appearance, localization, signInUrl, signUpUrl, navigate, initialState } = options;\n const [pending] = useState<ZauthaState>(() => ({ ...NO_STATE, initialState: initialState ?? null }));\n\n useEffect(() => {\n const instance = new Zautha(publishableKey, {\n ...(ui === undefined ? {} : { ui }),\n ...(appearance === undefined ? {} : { appearance }),\n ...(localization === undefined ? {} : { localization }),\n ...(signInUrl === undefined ? {} : { signInUrl }),\n ...(signUpUrl === undefined ? {} : { signUpUrl }),\n ...(navigate === undefined ? {} : { navigate }),\n ...(initialState === undefined ? {} : { initialState }),\n });\n // The instance is an external system: it is created here, never during render, and published through state.\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setZautha(instance);\n void instance.load();\n return () => {\n instance.dispose();\n setZautha(null);\n };\n // Appearance/localization objects are read at mount; changing the key re-creates the instance.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [publishableKey]);\n\n const value = useMemo(() => ({ zautha, pending }), [zautha, pending]);\n return <ZauthaContext.Provider value={value}>{children}</ZauthaContext.Provider>;\n}\n\n/** The Zautha instance, or null before the provider has created it. */\nexport function useZautha(): Zautha | null {\n return useZauthaContext().zautha;\n}\n\nfunction useZauthaContext(): ZauthaContextValue {\n const value = useContext(ZauthaContext);\n if (value === undefined) throw new Error(\"Zautha hooks and components must be used inside <ZauthaProvider>.\");\n return value;\n}\n\nconst NO_STATE: ZauthaState = {\n status: \"loading\",\n environment: null,\n client: null,\n session: null,\n user: null,\n organization: null,\n initialState: null,\n};\nconst noop = (): (() => void) => () => undefined;\n\n/** Reactive snapshot of the instance state (the loading state, with any initial state, before the instance exists). */\nexport function useZauthaState(): ZauthaState {\n const { zautha, pending } = useZauthaContext();\n return useSyncExternalStore(\n zautha?.subscribe ?? noop,\n () => zautha?.getSnapshot() ?? pending,\n () => pending,\n );\n}\n","import {\n checkAuthorization,\n withReverification,\n type AttemptErrors,\n type FetchStatus,\n type Session,\n type SignInResource,\n type SignUpResource,\n type UserResource,\n type ZauthaState,\n} from \"@zautha/js\";\nimport { useCallback, useLayoutEffect, useRef, useSyncExternalStore } from \"react\";\nimport { useZautha, useZauthaState } from \"./provider\";\n\n/**\n * What `has` checks in the session's active organization: full keys (`org:admin`, `org:invoices:read`). Every condition\n * given must hold; with none, false.\n */\nexport type HasParams = { role?: string; permission?: string };\nexport type Has = (params: HasParams) => boolean;\n\nexport interface UseAuthResult {\n isLoaded: boolean;\n isSignedIn: boolean;\n userId: string | null;\n sessionId: string | null;\n /** The active organization (`org_…`); null without one, and while signed out. */\n orgId: string | null;\n /** The user's role in it, a full key such as `org:admin`. */\n orgRole: string | null;\n /** Its slug; null without one or while the instance has slugs off. */\n orgSlug: string | null;\n /** The role's custom permissions, full keys such as `org:invoices:read`. */\n orgPermissions: readonly string[] | null;\n getToken: (options?: { skipCache?: boolean }) => Promise<string | null>;\n signOut: (options?: { redirectUrl?: string }) => Promise<void>;\n /**\n * From the session token alone, the same rule as every Zautha SDK and your server: false without an active\n * organization, and always false for a system permission (`org:sys_…`, never in the token).\n */\n has: Has;\n}\n\nconst isLoadedStatus = (status: string): boolean => status === \"ready\" || status === \"degraded\";\n\n/** The signed-in session: a pending one (tasks left, e.g. setting up two-step verification) counts as signed out. */\nconst activeSession = (state: ZauthaState): Session | null =>\n state.session?.status === \"active\" ? state.session : null;\n\nexport function useAuth(): UseAuthResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const getToken = useCallback(\n (options?: { skipCache?: boolean }) => zautha?.getToken(options) ?? Promise.resolve(null),\n [zautha],\n );\n const signOut = useCallback(\n (options?: { redirectUrl?: string }) => zautha?.signOut(options) ?? Promise.resolve(),\n [zautha],\n );\n // Until the first load settles, the server's initial state (if any) answers, so nothing flickers.\n const initial = state.status === \"loading\" ? state.initialState : null;\n const session = activeSession(state);\n const userId = initial === null ? (session?.userId ?? null) : initial.userId;\n const sessionId = initial === null ? (session?.id ?? null) : initial.sessionId;\n const signedIn = userId !== null;\n const organization = initial === null ? (session === null ? null : state.organization) : initial.organization;\n const has = useCallback<Has>((params) => checkAuthorization(organization, params), [organization]);\n return {\n isLoaded: isLoadedStatus(state.status) || initial !== null,\n isSignedIn: signedIn,\n userId,\n sessionId,\n orgId: organization?.id ?? null,\n orgRole: organization?.role ?? null,\n orgSlug: organization?.slug ?? null,\n orgPermissions: organization?.permissions ?? null,\n getToken,\n signOut,\n has,\n };\n}\n\n/** The signed-in user with its self-service actions (`user.update`, `user.createEmailAddress`, …). */\nexport function useUser(): { isLoaded: boolean; isSignedIn: boolean; user: UserResource | null } {\n const zautha = useZautha();\n const state = useZauthaState();\n const signedIn = activeSession(state) !== null;\n // zautha.user is rebuilt only when state.user changes, so the resource is stable between renders.\n const user = !signedIn || state.user === null ? null : (zautha?.user ?? null);\n return { isLoaded: isLoadedStatus(state.status), isSignedIn: signedIn, user };\n}\n\n/**\n * Wraps a sensitive action so that it completes after an identity check when it needs one: when `fetcher` throws\n * `ReverificationRequiredError` (e.g. `user.updatePassword`) or resolves to a `Response` with the `403\n * reverification_required` body (your backend with @zautha/backend, @zautha/nextjs or Zautha.AspNetCore), the\n * reverification modal opens and, once the user has verified, `fetcher` runs once more with the same arguments (its\n * token is fresh by then). Closing the modal rejects with `ReverificationCancelledError`. Needs `ui` from @zautha/ui on\n * the provider. The returned function is stable; it always calls the latest `fetcher`.\n */\nexport function useReverification<Args extends unknown[], Result>(\n fetcher: (...args: Args) => Promise<Result>,\n): (...args: Args) => Promise<Result> {\n const zautha = useZautha();\n const latest = useRef(fetcher);\n useLayoutEffect(() => {\n latest.current = fetcher;\n });\n return useCallback(\n (...args: Args) => {\n const call = (...callArgs: Args): Promise<Result> => latest.current(...callArgs);\n // Before the provider has created the instance no modal can open: the action runs as it is.\n return zautha === null ? call(...args) : withReverification(zautha, call)(...args);\n },\n [zautha],\n );\n}\n\n/** The signed-in session; null while signed out or while the session is pending (tasks left). */\nexport function useSession(): { isLoaded: boolean; isSignedIn: boolean; session: Session | null } {\n const state = useZauthaState();\n const session = activeSession(state);\n return { isLoaded: isLoadedStatus(state.status), isSignedIn: session !== null, session };\n}\n\nconst noopSubscribe = (): (() => void) => () => undefined;\n\nfunction useResource<T extends SignInResource | SignUpResource>(resource: T | null) {\n const snapshot = useSyncExternalStore(\n resource?.subscribe ?? noopSubscribe,\n () => resource?.snapshot ?? null,\n () => null,\n );\n return snapshot;\n}\n\nexport interface UseSignInResult {\n isLoaded: boolean;\n /** The sign-in resource; null until the provider has created the instance. */\n signIn: SignInResource | null;\n errors: AttemptErrors;\n fetchStatus: FetchStatus;\n}\n\nconst NO_ERRORS: AttemptErrors = { fields: {}, global: [] };\n\nexport function useSignIn(): UseSignInResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const snapshot = useResource(zautha?.signIn ?? null);\n return {\n isLoaded: isLoadedStatus(state.status),\n signIn: zautha?.signIn ?? null,\n errors: snapshot?.errors ?? NO_ERRORS,\n fetchStatus: snapshot?.fetchStatus ?? \"idle\",\n };\n}\n\nexport interface UseSignUpResult {\n isLoaded: boolean;\n signUp: SignUpResource | null;\n errors: AttemptErrors;\n fetchStatus: FetchStatus;\n}\n\nexport function useSignUp(): UseSignUpResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const snapshot = useResource(zautha?.signUp ?? null);\n return {\n isLoaded: isLoadedStatus(state.status),\n signUp: zautha?.signUp ?? null,\n errors: snapshot?.errors ?? NO_ERRORS,\n fetchStatus: snapshot?.fetchStatus ?? \"idle\",\n };\n}\n","import { useEffect, type ReactNode } from \"react\";\nimport { useAuth, type Has, type HasParams } from \"./hooks\";\nimport { useZautha, useZauthaState } from \"./provider\";\n\nexport type ShowWhen = \"signed-in\" | \"signed-out\" | HasParams | ((has: Has) => boolean);\n\n/**\n * Renders `children` when the condition holds, else `fallback`. Renders nothing until Zautha has\n * loaded, so a signed-in user never sees a signed-out flash.\n */\nexport function Show(props: { when: ShowWhen; fallback?: ReactNode; children?: ReactNode }): ReactNode {\n const { isLoaded, isSignedIn, has } = useAuth();\n if (!isLoaded) return null;\n const { when } = props;\n const pass =\n when === \"signed-in\"\n ? isSignedIn\n : when === \"signed-out\"\n ? !isSignedIn\n : typeof when === \"function\"\n ? when(has)\n : has(when);\n return pass ? props.children : (props.fallback ?? null);\n}\n\nexport function ZauthaLoading(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"loading\" ? props.children : null;\n}\n\n/** Loaded, including degraded (network trouble after load: last known state is shown). */\nexport function ZauthaLoaded(props: { children?: ReactNode }): ReactNode {\n const { status } = useZauthaState();\n return status === \"ready\" || status === \"degraded\" ? props.children : null;\n}\n\nexport function ZauthaDegraded(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"degraded\" ? props.children : null;\n}\n\nexport function ZauthaFailed(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"failed\" ? props.children : null;\n}\n\n/** Sends a signed-out visitor to sign-in once loaded; renders nothing. */\nexport function RedirectToSignIn(props: { redirectUrl?: string }): ReactNode {\n const zautha = useZautha();\n const { isLoaded, isSignedIn } = useAuth();\n const { redirectUrl } = props;\n useEffect(() => {\n if (zautha !== null && isLoaded && !isSignedIn)\n zautha.redirectToSignIn(redirectUrl === undefined ? {} : { redirectUrl });\n }, [zautha, isLoaded, isSignedIn, redirectUrl]);\n return null;\n}\n\nexport function RedirectToSignUp(props: { redirectUrl?: string }): ReactNode {\n const zautha = useZautha();\n const { isLoaded, isSignedIn } = useAuth();\n const { redirectUrl } = props;\n useEffect(() => {\n if (zautha !== null && isLoaded && !isSignedIn)\n zautha.redirectToSignUp(redirectUrl === undefined ? {} : { redirectUrl });\n }, [zautha, isLoaded, isSignedIn, redirectUrl]);\n return null;\n}\n","import { Children, cloneElement, isValidElement, type MouseEvent, type ReactElement, type ReactNode } from \"react\";\nimport { useZautha } from \"./provider\";\n\ninterface ButtonProps {\n /** `redirect` (default) goes to the sign-in page; `modal` opens the prebuilt component (needs `ui`). */\n mode?: \"redirect\" | \"modal\";\n redirectUrl?: string;\n children?: ReactNode;\n}\n\n/** Wraps its single child (or renders a plain button) and wires the click. Unstyled by design. */\nfunction Trigger(props: { children: ReactNode; label: string; onClick: () => void }): ReactNode {\n const child = Children.count(props.children) === 1 ? Children.only(props.children) : null;\n if (isValidElement<{ onClick?: (event: MouseEvent) => void }>(child)) {\n const original = child.props.onClick;\n return cloneElement(child as ReactElement<{ onClick?: (event: MouseEvent) => void }>, {\n onClick: (event: MouseEvent) => {\n original?.(event);\n if (!event.defaultPrevented) props.onClick();\n },\n });\n }\n return (\n <button type=\"button\" onClick={props.onClick}>\n {props.children ?? props.label}\n </button>\n );\n}\n\nexport function SignInButton(props: ButtonProps): ReactNode {\n const zautha = useZautha();\n const options = props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl };\n return (\n <Trigger\n label=\"Sign in\"\n onClick={() => (props.mode === \"modal\" ? zautha?.openSignIn(options) : zautha?.redirectToSignIn(options))}\n >\n {props.children}\n </Trigger>\n );\n}\n\nexport function SignUpButton(props: ButtonProps): ReactNode {\n const zautha = useZautha();\n const options = props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl };\n return (\n <Trigger\n label=\"Sign up\"\n onClick={() => (props.mode === \"modal\" ? zautha?.openSignUp(options) : zautha?.redirectToSignUp(options))}\n >\n {props.children}\n </Trigger>\n );\n}\n\nexport function SignOutButton(props: { redirectUrl?: string; children?: ReactNode }): ReactNode {\n const zautha = useZautha();\n return (\n <Trigger\n label=\"Sign out\"\n onClick={() => void zautha?.signOut(props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl })}\n >\n {props.children}\n </Trigger>\n );\n}\n","import type { UiComponentName } from \"@zautha/js\";\nimport { useEffect, useRef, type ReactNode } from \"react\";\nimport { useZautha } from \"./provider\";\n\n/**\n * Mounts a @zautha/ui component into a div once the instance exists; later prop changes update it in\n * place. SSR renders only the empty div.\n */\nfunction Mounted(props: { name: UiComponentName; componentProps: object }): ReactNode {\n const zautha = useZautha();\n const ref = useRef<HTMLDivElement>(null);\n const mountedWith = useRef<object | null>(null);\n const { name, componentProps } = props;\n\n useEffect(() => {\n const element = ref.current;\n if (zautha === null || element === null) return;\n zautha.mount(name, element, componentProps);\n mountedWith.current = componentProps;\n return () => {\n mountedWith.current = null;\n zautha.unmount(element);\n };\n // componentProps changes are applied by the effect below without remounting.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [zautha, name]);\n\n useEffect(() => {\n const element = ref.current;\n if (zautha === null || element === null || mountedWith.current === null || mountedWith.current === componentProps)\n return;\n mountedWith.current = componentProps;\n zautha.updateMounted(element, componentProps);\n }, [zautha, componentProps]);\n\n return <div ref={ref} />;\n}\n\n// Prop types live in @zautha/ui; they are structural here so @zautha/react has no runtime dependency on it.\nexport function SignIn(props: import(\"@zautha/ui\").SignInProps): ReactNode {\n return <Mounted name=\"SignIn\" componentProps={props} />;\n}\n\nexport function SignUp(props: import(\"@zautha/ui\").SignUpProps): ReactNode {\n return <Mounted name=\"SignUp\" componentProps={props} />;\n}\n\n/** The page a provider sends the user back to: finishes the social sign-in or sign-up (see @zautha/ui). */\nexport function AuthenticateWithRedirectCallback(\n props: import(\"@zautha/ui\").AuthenticateWithRedirectCallbackProps,\n): ReactNode {\n return <Mounted name=\"AuthenticateWithRedirectCallback\" componentProps={props} />;\n}\n\nexport function UserButton(props: import(\"@zautha/ui\").UserButtonProps): ReactNode {\n return <Mounted name=\"UserButton\" componentProps={props} />;\n}\n\nexport function UserProfile(props: import(\"@zautha/ui\").UserProfileProps): ReactNode {\n return <Mounted name=\"UserProfile\" componentProps={props} />;\n}\n\nexport function OAuthConsent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xB;CAGF,GAAG,CAAC,QAAQ,IAAI,CAAC;CAEjB,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,MAAM,UAAU,IAAI;EACpB,IAAI,WAAW,QAAQ,YAAY,QAAQ,YAAY,YAAY,QAAQ,YAAY,YAAY,gBACjG;EACF,YAAY,UAAU;EACtB,OAAO,cAAc,SAAS,cAAc;CAC9C,GAAG,CAAC,QAAQ,cAAc,CAAC;CAE3B,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD,EAAU,IAAM,CAAA;AACzB;AAGA,SAAgB,OAAO,OAAoD;CACzE,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,SAAD;EAAS,MAAK;EAAS,gBAAgB;CAAQ,CAAA;AACxD;AAEA,SAAgB,OAAO,OAAoD;CACzE,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,SAAD;EAAS,MAAK;EAAS,gBAAgB;CAAQ,CAAA;AACxD;;AAGA,SAAgB,iCACd,OACW;CACX,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,SAAD;EAAS,MAAK;EAAmC,gBAAgB;CAAQ,CAAA;AAClF;AAEA,SAAgB,WAAW,OAAwD;CACjF,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,SAAD;EAAS,MAAK;EAAa,gBAAgB;CAAQ,CAAA;AAC5D;AAEA,SAAgB,YAAY,OAAyD;CACnF,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,SAAD;EAAS,MAAK;EAAc,gBAAgB;CAAQ,CAAA;AAC7D;AAEA,SAAgB,aAAa,OAA0D;CACrF,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,SAAD;EAAS,MAAK;EAAe,gBAAgB;CAAQ,CAAA;AAC9D"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["createContext","useState","Zautha","useMemo","useContext","useSyncExternalStore","useState","useRef","useCallback","useCallback","checkAuthorization","useRef","withReverification","useSyncExternalStore","ZauthaError","Children","isValidElement","cloneElement","useRef"],"sources":["../src/provider.tsx","../src/pagination.ts","../src/hooks.ts","../src/control.tsx","../src/buttons.tsx","../src/prebuilt.tsx"],"sourcesContent":["import { Zautha, type ZauthaOptions, type ZauthaState } from \"@zautha/js\";\nimport { createContext, useContext, useEffect, useMemo, useState, useSyncExternalStore, type ReactNode } from \"react\";\n\ninterface ZauthaContextValue {\n readonly zautha: Zautha | null;\n /** The snapshot before the instance exists and during server rendering (carries `initialState`). */\n readonly pending: ZauthaState;\n}\n\nconst ZauthaContext = createContext<ZauthaContextValue | undefined>(undefined);\n\nexport interface ZauthaProviderProps extends Omit<ZauthaOptions, \"fetch\"> {\n publishableKey: string;\n children?: ReactNode;\n}\n\n/**\n * Creates the Zautha instance after mount (never during render, so StrictMode's double mount and SSR\n * create no timers or channels), loads it, and disposes it on unmount. Until then hooks report\n * `isLoaded: false`, unless `initialState` (the server's view, e.g. from @zautha/nextjs) says who is signed in.\n */\nexport function ZauthaProvider({ publishableKey, children, ...options }: ZauthaProviderProps): ReactNode {\n const [zautha, setZautha] = useState<Zautha | null>(null);\n const { ui, appearance, localization, signInUrl, signUpUrl, navigate, initialState } = options;\n const [pending] = useState<ZauthaState>(() => ({ ...NO_STATE, initialState: initialState ?? null }));\n\n useEffect(() => {\n const instance = new Zautha(publishableKey, {\n ...(ui === undefined ? {} : { ui }),\n ...(appearance === undefined ? {} : { appearance }),\n ...(localization === undefined ? {} : { localization }),\n ...(signInUrl === undefined ? {} : { signInUrl }),\n ...(signUpUrl === undefined ? {} : { signUpUrl }),\n ...(navigate === undefined ? {} : { navigate }),\n ...(initialState === undefined ? {} : { initialState }),\n });\n // The instance is an external system: it is created here, never during render, and published through state.\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setZautha(instance);\n void instance.load();\n return () => {\n instance.dispose();\n setZautha(null);\n };\n // Appearance/localization objects are read at mount; changing the key re-creates the instance.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [publishableKey]);\n\n const value = useMemo(() => ({ zautha, pending }), [zautha, pending]);\n return <ZauthaContext.Provider value={value}>{children}</ZauthaContext.Provider>;\n}\n\n/** The Zautha instance, or null before the provider has created it. */\nexport function useZautha(): Zautha | null {\n return useZauthaContext().zautha;\n}\n\nfunction useZauthaContext(): ZauthaContextValue {\n const value = useContext(ZauthaContext);\n if (value === undefined) throw new Error(\"Zautha hooks and components must be used inside <ZauthaProvider>.\");\n return value;\n}\n\nconst NO_STATE: ZauthaState = {\n status: \"loading\",\n environment: null,\n client: null,\n session: null,\n user: null,\n organization: null,\n initialState: null,\n};\nconst noop = (): (() => void) => () => undefined;\n\n/** Reactive snapshot of the instance state (the loading state, with any initial state, before the instance exists). */\nexport function useZauthaState(): ZauthaState {\n const { zautha, pending } = useZauthaContext();\n return useSyncExternalStore(\n zautha?.subscribe ?? noop,\n () => zautha?.getSnapshot() ?? pending,\n () => pending,\n );\n}\n","import type { Paginated } from \"@zautha/js\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\n\n/** A list's page size (default 10, the API's) and the page to start on (default 1). */\nexport interface PaginationParams {\n pageSize?: number;\n initialPage?: number;\n}\n\n/**\n * One page of a list and how to move through it. `isLoading`: the page has no data yet; `isFetching`: a request for it\n * is in flight (also while `revalidate()` reads it again). A failed read leaves `data` empty and sets `error`.\n */\nexport interface PaginatedResult<T> {\n data: T[];\n /** How many there are in all. */\n count: number;\n page: number;\n pageCount: number;\n isLoading: boolean;\n isFetching: boolean;\n error: Error | null;\n hasNextPage: boolean;\n hasPreviousPage: boolean;\n fetchNext: () => void;\n fetchPrevious: () => void;\n fetchPage: (page: number) => void;\n /** Reads the current page again; resolves once it has been read. */\n revalidate: () => Promise<void>;\n}\n\n/** What a page read gets: 1–100 items after `offset`. */\nexport type PageLoader<T> = (page: { limit: number; offset: number }) => Promise<Paginated<T>>;\n\n/** A list to read: `key` names what is listed (the user, the organization, the filters); `load` reads one page. */\nexport interface PageSource<T> {\n readonly key: string;\n readonly load: PageLoader<T>;\n}\n\ninterface Settled<T> {\n readonly request: string;\n readonly key: string;\n readonly page: number;\n readonly data: T[];\n readonly count: number;\n readonly error: Error | null;\n}\n\n/**\n * The pages of one list. Without a source nothing is read and the list is empty; a source with a new key starts again on\n * the initial page. A response to an older request (another page, key or revalidation) is dropped, so it never\n * overwrites a newer one.\n */\nexport function usePages<T>(\n source: PageSource<T> | null,\n params: PaginationParams | true | undefined,\n): PaginatedResult<T> {\n const key = source?.key ?? null;\n const { pageSize = 10, initialPage = 1 } = params === true || params === undefined ? {} : params;\n const [at, setAt] = useState({ key, page: initialPage, version: 0 });\n const [settled, setSettled] = useState<Settled<T> | null>(null);\n const latest = useRef(0);\n const waiting = useRef<(() => void)[]>([]);\n if (at.key !== key) {\n // Another list (also an earlier one again): start on its initial page with a fresh read, whatever was shown before.\n setAt({ key, page: initialPage, version: 0 });\n setSettled(null);\n }\n const { page, version } = at.key === key ? at : { page: initialPage, version: 0 };\n const request = JSON.stringify([key, page, pageSize, version]);\n const loader = useRef(source?.load);\n useEffect(() => {\n loader.current = source?.load;\n });\n\n useEffect(() => {\n const id = ++latest.current;\n const settle = (data: T[], count: number, error: Error | null): void => {\n if (latest.current !== id) return;\n if (key !== null) setSettled({ request, key, page, data, count, error });\n for (const resolve of waiting.current.splice(0)) resolve();\n };\n if (key === null || loader.current === undefined) return settle([], 0, null);\n loader.current({ limit: pageSize, offset: (page - 1) * pageSize }).then(\n (r) => settle(r.data, r.totalCount, null),\n (error: unknown) => settle([], 0, error instanceof Error ? error : new Error(String(error))),\n );\n // `request` covers key, page, pageSize and version.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [request]);\n\n const shown = settled !== null && settled.key === key && settled.page === page ? settled : null;\n const isFetching = key !== null && settled?.request !== request;\n const count = shown?.count ?? 0;\n const pageCount = Math.ceil(count / pageSize);\n const go = useCallback(\n (to: (page: number) => number) =>\n setAt((a) => {\n const from = a.key === key ? a.page : initialPage;\n return { key, page: Math.max(1, to(from)), version: a.key === key ? a.version : 0 };\n }),\n [key, initialPage],\n );\n const revalidate = useCallback(\n () =>\n new Promise<void>((resolve) => {\n waiting.current.push(resolve);\n setAt((a) => (a.key === key ? { ...a, version: a.version + 1 } : { key, page: initialPage, version: 1 }));\n }),\n [key, initialPage],\n );\n return {\n data: shown?.data ?? [],\n count,\n page,\n pageCount,\n isLoading: isFetching && shown === null,\n isFetching,\n error: shown?.error ?? null,\n hasNextPage: page < pageCount,\n hasPreviousPage: page > 1,\n fetchNext: useCallback(() => go((p) => p + 1), [go]),\n fetchPrevious: useCallback(() => go((p) => p - 1), [go]),\n fetchPage: useCallback((n: number) => go(() => n), [go]),\n revalidate,\n };\n}\n","import {\n checkAuthorization,\n withReverification,\n ZauthaError,\n type AttemptErrors,\n type FetchStatus,\n type OrganizationInvitationResource,\n type OrganizationInvitationStatus,\n type OrganizationMembership,\n type OrganizationMembershipResource,\n type OrganizationResource,\n type Session,\n type SignInResource,\n type SignUpResource,\n type UserOrganizationInvitationResource,\n type UserResource,\n type ZauthaState,\n} from \"@zautha/js\";\nimport { useCallback, useLayoutEffect, useRef, useSyncExternalStore } from \"react\";\nimport { usePages, type PageLoader, type PageSource, type PaginatedResult, type PaginationParams } from \"./pagination\";\nimport { useZautha, useZauthaState } from \"./provider\";\n\n/**\n * What `has` checks in the session's active organization: full keys (`org:admin`, `org:invoices:read`). Every condition\n * given must hold; with none, false.\n */\nexport type HasParams = { role?: string; permission?: string };\nexport type Has = (params: HasParams) => boolean;\n\nexport interface UseAuthResult {\n isLoaded: boolean;\n isSignedIn: boolean;\n userId: string | null;\n sessionId: string | null;\n /** The active organization (`org_…`); null without one, and while signed out. */\n orgId: string | null;\n /** The user's role in it, a full key such as `org:admin`. */\n orgRole: string | null;\n /** Its slug; null without one or while the instance has slugs off. */\n orgSlug: string | null;\n /** The role's custom permissions, full keys such as `org:invoices:read`. */\n orgPermissions: readonly string[] | null;\n getToken: (options?: { skipCache?: boolean }) => Promise<string | null>;\n signOut: (options?: { redirectUrl?: string }) => Promise<void>;\n /**\n * From the session token alone, the same rule as every Zautha SDK and your server: false without an active\n * organization, and always false for a system permission (`org:sys_…`, never in the token).\n */\n has: Has;\n}\n\nconst isLoadedStatus = (status: string): boolean => status === \"ready\" || status === \"degraded\";\n\n/** The signed-in session: a pending one (tasks left, e.g. setting up two-step verification) counts as signed out. */\nconst activeSession = (state: ZauthaState): Session | null =>\n state.session?.status === \"active\" ? state.session : null;\n\nexport function useAuth(): UseAuthResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const getToken = useCallback(\n (options?: { skipCache?: boolean }) => zautha?.getToken(options) ?? Promise.resolve(null),\n [zautha],\n );\n const signOut = useCallback(\n (options?: { redirectUrl?: string }) => zautha?.signOut(options) ?? Promise.resolve(),\n [zautha],\n );\n // Until the first load settles, the server's initial state (if any) answers, so nothing flickers.\n const initial = state.status === \"loading\" ? state.initialState : null;\n const session = activeSession(state);\n const userId = initial === null ? (session?.userId ?? null) : initial.userId;\n const sessionId = initial === null ? (session?.id ?? null) : initial.sessionId;\n const signedIn = userId !== null;\n const organization = initial === null ? (session === null ? null : state.organization) : initial.organization;\n const has = useCallback<Has>((params) => checkAuthorization(organization, params), [organization]);\n return {\n isLoaded: isLoadedStatus(state.status) || initial !== null,\n isSignedIn: signedIn,\n userId,\n sessionId,\n orgId: organization?.id ?? null,\n orgRole: organization?.role ?? null,\n orgSlug: organization?.slug ?? null,\n orgPermissions: organization?.permissions ?? null,\n getToken,\n signOut,\n has,\n };\n}\n\n/** The signed-in user with its self-service actions (`user.update`, `user.createEmailAddress`, …). */\nexport function useUser(): { isLoaded: boolean; isSignedIn: boolean; user: UserResource | null } {\n const zautha = useZautha();\n const state = useZauthaState();\n const signedIn = activeSession(state) !== null;\n // zautha.user is rebuilt only when state.user changes, so the resource is stable between renders.\n const user = !signedIn || state.user === null ? null : (zautha?.user ?? null);\n return { isLoaded: isLoadedStatus(state.status), isSignedIn: signedIn, user };\n}\n\n/**\n * Wraps a sensitive action so that it completes after an identity check when it needs one: when `fetcher` throws\n * `ReverificationRequiredError` (e.g. `user.updatePassword`) or resolves to a `Response` with the `403\n * reverification_required` body (your backend with @zautha/backend, @zautha/nextjs or Zautha.AspNetCore), the\n * reverification modal opens and, once the user has verified, `fetcher` runs once more with the same arguments (its\n * token is fresh by then). Closing the modal rejects with `ReverificationCancelledError`. Needs `ui` from @zautha/ui on\n * the provider. The returned function is stable; it always calls the latest `fetcher`.\n */\nexport function useReverification<Args extends unknown[], Result>(\n fetcher: (...args: Args) => Promise<Result>,\n): (...args: Args) => Promise<Result> {\n const zautha = useZautha();\n const latest = useRef(fetcher);\n useLayoutEffect(() => {\n latest.current = fetcher;\n });\n return useCallback(\n (...args: Args) => {\n const call = (...callArgs: Args): Promise<Result> => latest.current(...callArgs);\n // Before the provider has created the instance no modal can open: the action runs as it is.\n return zautha === null ? call(...args) : withReverification(zautha, call)(...args);\n },\n [zautha],\n );\n}\n\n/** The signed-in session; null while signed out or while the session is pending (tasks left). */\nexport function useSession(): { isLoaded: boolean; isSignedIn: boolean; session: Session | null } {\n const state = useZauthaState();\n const session = activeSession(state);\n return { isLoaded: isLoadedStatus(state.status), isSignedIn: session !== null, session };\n}\n\nconst noopSubscribe = (): (() => void) => () => undefined;\n\nfunction useResource<T extends SignInResource | SignUpResource>(resource: T | null) {\n const snapshot = useSyncExternalStore(\n resource?.subscribe ?? noopSubscribe,\n () => resource?.snapshot ?? null,\n () => null,\n );\n return snapshot;\n}\n\nexport interface UseSignInResult {\n isLoaded: boolean;\n /** The sign-in resource; null until the provider has created the instance. */\n signIn: SignInResource | null;\n errors: AttemptErrors;\n fetchStatus: FetchStatus;\n}\n\nconst NO_ERRORS: AttemptErrors = { fields: {}, global: [] };\n\nexport function useSignIn(): UseSignInResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const snapshot = useResource(zautha?.signIn ?? null);\n return {\n isLoaded: isLoadedStatus(state.status),\n signIn: zautha?.signIn ?? null,\n errors: snapshot?.errors ?? NO_ERRORS,\n fetchStatus: snapshot?.fetchStatus ?? \"idle\",\n };\n}\n\nexport interface UseSignUpResult {\n isLoaded: boolean;\n signUp: SignUpResource | null;\n errors: AttemptErrors;\n fetchStatus: FetchStatus;\n}\n\nexport function useSignUp(): UseSignUpResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const snapshot = useResource(zautha?.signUp ?? null);\n return {\n isLoaded: isLoadedStatus(state.status),\n signUp: zautha?.signUp ?? null,\n errors: snapshot?.errors ?? NO_ERRORS,\n fetchStatus: snapshot?.fetchStatus ?? \"idle\",\n };\n}\n\n/** A list a hook reads only when asked: `true` for the defaults, or the page size, the first page and the filters. */\nexport type ListParams<Filters = object> = true | (PaginationParams & Filters);\n\nexport interface UseOrganizationParams {\n /** The active organization's members (needs `org:sys_memberships:read`), filtered by a role key. */\n memberships?: ListParams<{ role?: string }>;\n /** Its invitations, filtered by status; read only for a member with `org:sys_memberships:manage` (else empty). */\n invitations?: ListParams<{ status?: OrganizationInvitationStatus[] }>;\n}\n\nexport interface UseOrganizationResult {\n isLoaded: boolean;\n /** The session's active organization with the member's actions; null without one, while signed out or pending. */\n organization: OrganizationResource | null;\n /** The user's membership of it: role and every permission of the role, system ones included (to show buttons). */\n membership: OrganizationMembershipResource | null;\n /** Only when asked for in the params. */\n memberships?: PaginatedResult<OrganizationMembership>;\n invitations?: PaginatedResult<OrganizationInvitationResource>;\n}\n\nexport interface UseOrganizationListParams {\n /** The user's memberships, newest first. */\n userMemberships?: ListParams;\n /** The invitations to the user's verified addresses; by default the pending ones. */\n userInvitations?: ListParams<{ status?: OrganizationInvitationStatus[] }>;\n}\n\nexport interface UseOrganizationListResult {\n isLoaded: boolean;\n /** Creates an organization with the user in it; it is not made active (`setActive` does that). */\n createOrganization: (params: { name: string; slug?: string }) => Promise<OrganizationResource>;\n /** Makes an organization (id or slug) the session's active one; null is the personal account. */\n setActive: (params: { organization: string | null }) => Promise<void>;\n userMemberships?: PaginatedResult<OrganizationMembershipResource>;\n userInvitations?: PaginatedResult<UserOrganizationInvitationResource>;\n}\n\n/** A list's filters: its params without the page size and the first page. */\nfunction filtersOf<F extends object>(params: ListParams<F>): F {\n const filters = { ...(params === true ? {} : params) } as PaginationParams & F;\n delete filters.pageSize;\n delete filters.initialPage;\n return filters;\n}\n\n/** A list of `owner` read with `load`: its key (`owner` and the params, so new filters start the list again). */\nconst list = <T>(owner: string, params: ListParams<object>, load: PageLoader<T>): PageSource<T> => ({\n key: `${owner}:${JSON.stringify(params)}`,\n load,\n});\n\n/** The signed-in user (an active session's) and whether hooks that read it are loaded. */\nfunction useSignedInUser(): { isLoaded: boolean; state: ZauthaState; user: UserResource | null } {\n const zautha = useZautha();\n const state = useZauthaState();\n const user = activeSession(state) === null ? null : (zautha?.user ?? null);\n // An active session is loaded once its user is.\n return { isLoaded: isLoadedStatus(state.status) && (activeSession(state) === null || user !== null), state, user };\n}\n\n/**\n * The session's active organization and the user's membership of it, from the session token and the user (no request of\n * its own), and on request its members and invitations, page by page. The lists start again on their first page when\n * the active organization changes.\n */\nexport function useOrganization(params: UseOrganizationParams = {}): UseOrganizationResult {\n const { isLoaded, state, user } = useSignedInUser();\n const id = state.organization?.id;\n const membership = user?.organizationMemberships.find((m) => m.organization.id === id) ?? null;\n const organization = membership?.organization ?? null;\n // The user's own membership: its user is the signed-in one.\n const owner = membership === null ? \"\" : `${membership.publicUserData.userId}:${membership.organization.id}`;\n const { memberships, invitations } = params;\n const manages = membership?.permissions.includes(\"org:sys_memberships:manage\") === true;\n const members = usePages(\n organization === null || memberships === undefined\n ? null\n : list(owner, memberships, (page) => organization.getMemberships({ ...filtersOf(memberships), ...page })),\n memberships,\n );\n const invited = usePages(\n organization === null || invitations === undefined || !manages\n ? null\n : list(owner, invitations, (page) => organization.getInvitations({ ...filtersOf(invitations), ...page })),\n invitations,\n );\n return {\n isLoaded,\n organization,\n membership,\n ...(memberships === undefined ? {} : { memberships: members }),\n ...(invitations === undefined ? {} : { invitations: invited }),\n };\n}\n\n/**\n * Creating an organization and choosing the active one, and on request the user's memberships and the invitations to\n * the user, page by page.\n */\nexport function useOrganizationList(params: UseOrganizationListParams = {}): UseOrganizationListResult {\n const zautha = useZautha();\n const { isLoaded, user } = useSignedInUser();\n const { userMemberships, userInvitations } = params;\n const memberships = usePages(\n user === null || userMemberships === undefined\n ? null\n : list(user.id, userMemberships, (page) => user.getOrganizationMemberships(page)),\n userMemberships,\n );\n const invitations = usePages(\n user === null || userInvitations === undefined\n ? null\n : list(user.id, userInvitations, (page) =>\n user.getOrganizationInvitations({ ...filtersOf(userInvitations), ...page }),\n ),\n userInvitations,\n );\n const createOrganization = useCallback(\n (p: { name: string; slug?: string }) => zautha?.createOrganization(p) ?? notLoaded(),\n [zautha],\n );\n const setActive = useCallback((p: { organization: string | null }) => zautha?.setActive(p) ?? notLoaded(), [zautha]);\n return {\n isLoaded,\n createOrganization,\n setActive,\n ...(userMemberships === undefined ? {} : { userMemberships: memberships }),\n ...(userInvitations === undefined ? {} : { userInvitations: invitations }),\n };\n}\n\nconst notLoaded = (): Promise<never> => Promise.reject(new ZauthaError(\"Zautha is not loaded yet.\"));\n","import { useEffect, type ReactNode } from \"react\";\nimport { useAuth, type Has, type HasParams } from \"./hooks\";\nimport { useZautha, useZauthaState } from \"./provider\";\n\nexport type ShowWhen = \"signed-in\" | \"signed-out\" | HasParams | ((has: Has) => boolean);\n\n/**\n * Renders `children` when the condition holds, else `fallback`. Renders nothing until Zautha has\n * loaded, so a signed-in user never sees a signed-out flash.\n */\nexport function Show(props: { when: ShowWhen; fallback?: ReactNode; children?: ReactNode }): ReactNode {\n const { isLoaded, isSignedIn, has } = useAuth();\n if (!isLoaded) return null;\n const { when } = props;\n const pass =\n when === \"signed-in\"\n ? isSignedIn\n : when === \"signed-out\"\n ? !isSignedIn\n : typeof when === \"function\"\n ? when(has)\n : has(when);\n return pass ? props.children : (props.fallback ?? null);\n}\n\nexport function ZauthaLoading(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"loading\" ? props.children : null;\n}\n\n/** Loaded, including degraded (network trouble after load: last known state is shown). */\nexport function ZauthaLoaded(props: { children?: ReactNode }): ReactNode {\n const { status } = useZauthaState();\n return status === \"ready\" || status === \"degraded\" ? props.children : null;\n}\n\nexport function ZauthaDegraded(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"degraded\" ? props.children : null;\n}\n\nexport function ZauthaFailed(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"failed\" ? props.children : null;\n}\n\n/** Sends a signed-out visitor to sign-in once loaded; renders nothing. */\nexport function RedirectToSignIn(props: { redirectUrl?: string }): ReactNode {\n const zautha = useZautha();\n const { isLoaded, isSignedIn } = useAuth();\n const { redirectUrl } = props;\n useEffect(() => {\n if (zautha !== null && isLoaded && !isSignedIn)\n zautha.redirectToSignIn(redirectUrl === undefined ? {} : { redirectUrl });\n }, [zautha, isLoaded, isSignedIn, redirectUrl]);\n return null;\n}\n\nexport function RedirectToSignUp(props: { redirectUrl?: string }): ReactNode {\n const zautha = useZautha();\n const { isLoaded, isSignedIn } = useAuth();\n const { redirectUrl } = props;\n useEffect(() => {\n if (zautha !== null && isLoaded && !isSignedIn)\n zautha.redirectToSignUp(redirectUrl === undefined ? {} : { redirectUrl });\n }, [zautha, isLoaded, isSignedIn, redirectUrl]);\n return null;\n}\n","import { Children, cloneElement, isValidElement, type MouseEvent, type ReactElement, type ReactNode } from \"react\";\nimport { useZautha } from \"./provider\";\n\ninterface ButtonProps {\n /** `redirect` (default) goes to the sign-in page; `modal` opens the prebuilt component (needs `ui`). */\n mode?: \"redirect\" | \"modal\";\n redirectUrl?: string;\n children?: ReactNode;\n}\n\n/** Wraps its single child (or renders a plain button) and wires the click. Unstyled by design. */\nfunction Trigger(props: { children: ReactNode; label: string; onClick: () => void }): ReactNode {\n const child = Children.count(props.children) === 1 ? Children.only(props.children) : null;\n if (isValidElement<{ onClick?: (event: MouseEvent) => void }>(child)) {\n const original = child.props.onClick;\n return cloneElement(child as ReactElement<{ onClick?: (event: MouseEvent) => void }>, {\n onClick: (event: MouseEvent) => {\n original?.(event);\n if (!event.defaultPrevented) props.onClick();\n },\n });\n }\n return (\n <button type=\"button\" onClick={props.onClick}>\n {props.children ?? props.label}\n </button>\n );\n}\n\nexport function SignInButton(props: ButtonProps): ReactNode {\n const zautha = useZautha();\n const options = props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl };\n return (\n <Trigger\n label=\"Sign in\"\n onClick={() => (props.mode === \"modal\" ? zautha?.openSignIn(options) : zautha?.redirectToSignIn(options))}\n >\n {props.children}\n </Trigger>\n );\n}\n\nexport function SignUpButton(props: ButtonProps): ReactNode {\n const zautha = useZautha();\n const options = props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl };\n return (\n <Trigger\n label=\"Sign up\"\n onClick={() => (props.mode === \"modal\" ? zautha?.openSignUp(options) : zautha?.redirectToSignUp(options))}\n >\n {props.children}\n </Trigger>\n );\n}\n\nexport function SignOutButton(props: { redirectUrl?: string; children?: ReactNode }): ReactNode {\n const zautha = useZautha();\n return (\n <Trigger\n label=\"Sign out\"\n onClick={() => void zautha?.signOut(props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl })}\n >\n {props.children}\n </Trigger>\n );\n}\n","import type { UiComponentName } from \"@zautha/js\";\nimport { useEffect, useRef, type ReactNode } from \"react\";\nimport { useZautha } from \"./provider\";\n\n/**\n * Mounts a @zautha/ui component into a div once the instance exists; later prop changes update it in\n * place. SSR renders only the empty div.\n */\nfunction Mounted(props: { name: UiComponentName; componentProps: object }): ReactNode {\n const zautha = useZautha();\n const ref = useRef<HTMLDivElement>(null);\n const mountedWith = useRef<object | null>(null);\n const { name, componentProps } = props;\n\n useEffect(() => {\n const element = ref.current;\n if (zautha === null || element === null) return;\n zautha.mount(name, element, componentProps);\n mountedWith.current = componentProps;\n return () => {\n mountedWith.current = null;\n zautha.unmount(element);\n };\n // componentProps changes are applied by the effect below without remounting.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [zautha, name]);\n\n useEffect(() => {\n const element = ref.current;\n if (zautha === null || element === null || mountedWith.current === null || mountedWith.current === componentProps)\n return;\n mountedWith.current = componentProps;\n zautha.updateMounted(element, componentProps);\n }, [zautha, componentProps]);\n\n return <div ref={ref} />;\n}\n\n// Prop types live in @zautha/ui; they are structural here so @zautha/react has no runtime dependency on it.\nexport function SignIn(props: import(\"@zautha/ui\").SignInProps): ReactNode {\n return <Mounted name=\"SignIn\" componentProps={props} />;\n}\n\nexport function SignUp(props: import(\"@zautha/ui\").SignUpProps): ReactNode {\n return <Mounted name=\"SignUp\" componentProps={props} />;\n}\n\n/** The page a provider sends the user back to: finishes the social sign-in or sign-up (see @zautha/ui). */\nexport function AuthenticateWithRedirectCallback(\n props: import(\"@zautha/ui\").AuthenticateWithRedirectCallbackProps,\n): ReactNode {\n return <Mounted name=\"AuthenticateWithRedirectCallback\" componentProps={props} />;\n}\n\nexport function UserButton(props: import(\"@zautha/ui\").UserButtonProps): ReactNode {\n return <Mounted name=\"UserButton\" componentProps={props} />;\n}\n\nexport function UserProfile(props: import(\"@zautha/ui\").UserProfileProps): ReactNode {\n return <Mounted name=\"UserProfile\" componentProps={props} />;\n}\n\nexport function OAuthConsent(props: import(\"@zautha/ui\").OAuthConsentProps): ReactNode {\n return <Mounted name=\"OAuthConsent\" componentProps={props} />;\n}\n\nexport function CreateOrganization(props: import(\"@zautha/ui\").CreateOrganizationProps): ReactNode {\n return <Mounted name=\"CreateOrganization\" componentProps={props} />;\n}\n\nexport function OrganizationProfile(props: import(\"@zautha/ui\").OrganizationProfileProps): ReactNode {\n return <Mounted name=\"OrganizationProfile\" componentProps={props} />;\n}\n\nexport function OrganizationSwitcher(props: import(\"@zautha/ui\").OrganizationSwitcherProps): ReactNode {\n return <Mounted name=\"OrganizationSwitcher\" componentProps={props} />;\n}\n"],"mappings":";;;;;;AASA,MAAM,iBAAA,GAAgBA,MAAAA,cAAAA,CAA8C,KAAA,CAAS;;;;;;AAY7E,SAAgB,eAAe,EAAE,gBAAgB,UAAU,GAAG,WA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.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { AttemptErrors, EmailAddress, Environment, ExternalAccount, ExternalAccountResource, FetchStatus, OAuthStrategy, Passkey, PasskeyCreation, RedirectCallbackResult, ReverificationCancelledError, ReverificationRequiredError, ReverificationRequirement, Session, Session as Session$1, SessionWithActivity, SignInResource, SignInResource as SignInResource$1, SignUpResource, SignUpResource as SignUpResource$1, SocialProvider, User, UserResource, UserResource as UserResource$1, Zautha, ZauthaApiError, ZauthaCaptchaError, ZauthaError, ZauthaErrorCode, ZauthaNetworkError, ZauthaOfflineError, ZauthaOptions, ZauthaPasskeyError, isReverificationCancelledError, isReverificationRequiredError, isZauthaApiError, isZauthaCaptchaError, isZauthaError, isZauthaNetworkError, isZauthaOfflineError, isZauthaPasskeyError } from "@zautha/js";
|
|
2
|
+
import { AttemptErrors, EmailAddress, Environment, ExternalAccount, ExternalAccountResource, FetchStatus, OAuthStrategy, Organization, OrganizationInvitation, OrganizationInvitationResource, OrganizationInvitationResource as OrganizationInvitationResource$1, OrganizationInvitationStatus, OrganizationInvitationStatus as OrganizationInvitationStatus$1, OrganizationMembership, OrganizationMembership as OrganizationMembership$1, OrganizationMembershipResource, OrganizationMembershipResource as OrganizationMembershipResource$1, OrganizationResource, OrganizationResource as OrganizationResource$1, OrganizationRole, Passkey, PasskeyCreation, RedirectCallbackResult, ReverificationCancelledError, ReverificationRequiredError, ReverificationRequirement, Session, Session as Session$1, SessionWithActivity, SignInResource, SignInResource as SignInResource$1, SignUpResource, SignUpResource as SignUpResource$1, SocialProvider, User, UserOrganizationInvitationResource, UserOrganizationInvitationResource as UserOrganizationInvitationResource$1, UserResource, UserResource as UserResource$1, Zautha, ZauthaApiError, ZauthaCaptchaError, ZauthaError, ZauthaErrorCode, ZauthaNetworkError, ZauthaOfflineError, ZauthaOptions, ZauthaPasskeyError, isReverificationCancelledError, isReverificationRequiredError, isZauthaApiError, isZauthaCaptchaError, isZauthaError, isZauthaNetworkError, isZauthaOfflineError, isZauthaPasskeyError } from "@zautha/js";
|
|
3
3
|
import { ReactNode } from "react";
|
|
4
4
|
//#region src/provider.d.ts
|
|
5
5
|
interface ZauthaProviderProps extends Omit<ZauthaOptions, "fetch"> {
|
|
@@ -15,6 +15,34 @@ export declare function ZauthaProvider({ publishableKey, children, ...options }:
|
|
|
15
15
|
/** The Zautha instance, or null before the provider has created it. */
|
|
16
16
|
export declare function useZautha(): Zautha | null;
|
|
17
17
|
//#endregion
|
|
18
|
+
//#region src/pagination.d.ts
|
|
19
|
+
/** A list's page size (default 10, the API's) and the page to start on (default 1). */
|
|
20
|
+
interface PaginationParams {
|
|
21
|
+
pageSize?: number;
|
|
22
|
+
initialPage?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* One page of a list and how to move through it. `isLoading`: the page has no data yet; `isFetching`: a request for it
|
|
26
|
+
* is in flight (also while `revalidate()` reads it again). A failed read leaves `data` empty and sets `error`.
|
|
27
|
+
*/
|
|
28
|
+
interface PaginatedResult<T> {
|
|
29
|
+
data: T[];
|
|
30
|
+
/** How many there are in all. */
|
|
31
|
+
count: number;
|
|
32
|
+
page: number;
|
|
33
|
+
pageCount: number;
|
|
34
|
+
isLoading: boolean;
|
|
35
|
+
isFetching: boolean;
|
|
36
|
+
error: Error | null;
|
|
37
|
+
hasNextPage: boolean;
|
|
38
|
+
hasPreviousPage: boolean;
|
|
39
|
+
fetchNext: () => void;
|
|
40
|
+
fetchPrevious: () => void;
|
|
41
|
+
fetchPage: (page: number) => void;
|
|
42
|
+
/** Reads the current page again; resolves once it has been read. */
|
|
43
|
+
revalidate: () => Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
18
46
|
//#region src/hooks.d.ts
|
|
19
47
|
/**
|
|
20
48
|
* What `has` checks in the session's active organization: full keys (`org:admin`, `org:invoices:read`). Every condition
|
|
@@ -87,6 +115,61 @@ interface UseSignUpResult {
|
|
|
87
115
|
fetchStatus: FetchStatus;
|
|
88
116
|
}
|
|
89
117
|
export declare function useSignUp(): UseSignUpResult;
|
|
118
|
+
/** A list a hook reads only when asked: `true` for the defaults, or the page size, the first page and the filters. */
|
|
119
|
+
type ListParams<Filters = object> = true | (PaginationParams & Filters);
|
|
120
|
+
interface UseOrganizationParams {
|
|
121
|
+
/** The active organization's members (needs `org:sys_memberships:read`), filtered by a role key. */
|
|
122
|
+
memberships?: ListParams<{
|
|
123
|
+
role?: string;
|
|
124
|
+
}>;
|
|
125
|
+
/** Its invitations, filtered by status; read only for a member with `org:sys_memberships:manage` (else empty). */
|
|
126
|
+
invitations?: ListParams<{
|
|
127
|
+
status?: OrganizationInvitationStatus$1[];
|
|
128
|
+
}>;
|
|
129
|
+
}
|
|
130
|
+
interface UseOrganizationResult {
|
|
131
|
+
isLoaded: boolean;
|
|
132
|
+
/** The session's active organization with the member's actions; null without one, while signed out or pending. */
|
|
133
|
+
organization: OrganizationResource$1 | null;
|
|
134
|
+
/** The user's membership of it: role and every permission of the role, system ones included (to show buttons). */
|
|
135
|
+
membership: OrganizationMembershipResource$1 | null;
|
|
136
|
+
/** Only when asked for in the params. */
|
|
137
|
+
memberships?: PaginatedResult<OrganizationMembership$1>;
|
|
138
|
+
invitations?: PaginatedResult<OrganizationInvitationResource$1>;
|
|
139
|
+
}
|
|
140
|
+
interface UseOrganizationListParams {
|
|
141
|
+
/** The user's memberships, newest first. */
|
|
142
|
+
userMemberships?: ListParams;
|
|
143
|
+
/** The invitations to the user's verified addresses; by default the pending ones. */
|
|
144
|
+
userInvitations?: ListParams<{
|
|
145
|
+
status?: OrganizationInvitationStatus$1[];
|
|
146
|
+
}>;
|
|
147
|
+
}
|
|
148
|
+
interface UseOrganizationListResult {
|
|
149
|
+
isLoaded: boolean;
|
|
150
|
+
/** Creates an organization with the user in it; it is not made active (`setActive` does that). */
|
|
151
|
+
createOrganization: (params: {
|
|
152
|
+
name: string;
|
|
153
|
+
slug?: string;
|
|
154
|
+
}) => Promise<OrganizationResource$1>;
|
|
155
|
+
/** Makes an organization (id or slug) the session's active one; null is the personal account. */
|
|
156
|
+
setActive: (params: {
|
|
157
|
+
organization: string | null;
|
|
158
|
+
}) => Promise<void>;
|
|
159
|
+
userMemberships?: PaginatedResult<OrganizationMembershipResource$1>;
|
|
160
|
+
userInvitations?: PaginatedResult<UserOrganizationInvitationResource$1>;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* The session's active organization and the user's membership of it, from the session token and the user (no request of
|
|
164
|
+
* its own), and on request its members and invitations, page by page. The lists start again on their first page when
|
|
165
|
+
* the active organization changes.
|
|
166
|
+
*/
|
|
167
|
+
export declare function useOrganization(params?: UseOrganizationParams): UseOrganizationResult;
|
|
168
|
+
/**
|
|
169
|
+
* Creating an organization and choosing the active one, and on request the user's memberships and the invitations to
|
|
170
|
+
* the user, page by page.
|
|
171
|
+
*/
|
|
172
|
+
export declare function useOrganizationList(params?: UseOrganizationListParams): UseOrganizationListResult;
|
|
90
173
|
//#endregion
|
|
91
174
|
//#region src/control.d.ts
|
|
92
175
|
type ShowWhen = "signed-in" | "signed-out" | HasParams | ((has: Has) => boolean);
|
|
@@ -142,6 +225,9 @@ export declare function AuthenticateWithRedirectCallback(props: import("@zautha/
|
|
|
142
225
|
export declare function UserButton(props: import("@zautha/ui").UserButtonProps): ReactNode;
|
|
143
226
|
export declare function UserProfile(props: import("@zautha/ui").UserProfileProps): ReactNode;
|
|
144
227
|
export declare function OAuthConsent(props: import("@zautha/ui").OAuthConsentProps): ReactNode;
|
|
228
|
+
export declare function CreateOrganization(props: import("@zautha/ui").CreateOrganizationProps): ReactNode;
|
|
229
|
+
export declare function OrganizationProfile(props: import("@zautha/ui").OrganizationProfileProps): ReactNode;
|
|
230
|
+
export declare function OrganizationSwitcher(props: import("@zautha/ui").OrganizationSwitcherProps): ReactNode;
|
|
145
231
|
//#endregion
|
|
146
|
-
export { type EmailAddress, type Environment, type ExternalAccount, type ExternalAccountResource, type Has, type HasParams, type OAuthStrategy, type Passkey, type PasskeyCreation, type RedirectCallbackResult, ReverificationCancelledError, ReverificationRequiredError, type ReverificationRequirement, type Session, type SessionWithActivity, type ShowWhen, type SignInResource, type SignUpResource, type SocialProvider, type UseAuthResult, type UseSignInResult, type UseSignUpResult, type User, type UserResource, ZauthaApiError, ZauthaCaptchaError, ZauthaError, type ZauthaErrorCode, ZauthaNetworkError, ZauthaOfflineError, ZauthaPasskeyError, type ZauthaProviderProps, isReverificationCancelledError, isReverificationRequiredError, isZauthaApiError, isZauthaCaptchaError, isZauthaError, isZauthaNetworkError, isZauthaOfflineError, isZauthaPasskeyError };
|
|
232
|
+
export { type EmailAddress, type Environment, type ExternalAccount, type ExternalAccountResource, type Has, type HasParams, type ListParams, type OAuthStrategy, type Organization, type OrganizationInvitation, type OrganizationInvitationResource, type OrganizationInvitationStatus, type OrganizationMembership, type OrganizationMembershipResource, type OrganizationResource, type OrganizationRole, type PaginatedResult, type PaginationParams, type Passkey, type PasskeyCreation, type RedirectCallbackResult, ReverificationCancelledError, ReverificationRequiredError, type ReverificationRequirement, type Session, type SessionWithActivity, type ShowWhen, type SignInResource, type SignUpResource, type SocialProvider, type UseAuthResult, type UseOrganizationListParams, type UseOrganizationListResult, type UseOrganizationParams, type UseOrganizationResult, type UseSignInResult, type UseSignUpResult, type User, type UserOrganizationInvitationResource, type UserResource, ZauthaApiError, ZauthaCaptchaError, ZauthaError, type ZauthaErrorCode, ZauthaNetworkError, ZauthaOfflineError, ZauthaPasskeyError, type ZauthaProviderProps, isReverificationCancelledError, isReverificationRequiredError, isZauthaApiError, isZauthaCaptchaError, isZauthaError, isZauthaNetworkError, isZauthaOfflineError, isZauthaPasskeyError };
|
|
147
233
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { AttemptErrors, EmailAddress, Environment, ExternalAccount, ExternalAccountResource, FetchStatus, OAuthStrategy, Passkey, PasskeyCreation, RedirectCallbackResult, ReverificationCancelledError, ReverificationRequiredError, ReverificationRequirement, Session, Session as Session$1, SessionWithActivity, SignInResource, SignInResource as SignInResource$1, SignUpResource, SignUpResource as SignUpResource$1, SocialProvider, User, UserResource, UserResource as UserResource$1, Zautha, ZauthaApiError, ZauthaCaptchaError, ZauthaError, ZauthaErrorCode, ZauthaNetworkError, ZauthaOfflineError, ZauthaOptions, ZauthaPasskeyError, isReverificationCancelledError, isReverificationRequiredError, isZauthaApiError, isZauthaCaptchaError, isZauthaError, isZauthaNetworkError, isZauthaOfflineError, isZauthaPasskeyError } from "@zautha/js";
|
|
2
|
+
import { AttemptErrors, EmailAddress, Environment, ExternalAccount, ExternalAccountResource, FetchStatus, OAuthStrategy, Organization, OrganizationInvitation, OrganizationInvitationResource, OrganizationInvitationResource as OrganizationInvitationResource$1, OrganizationInvitationStatus, OrganizationInvitationStatus as OrganizationInvitationStatus$1, OrganizationMembership, OrganizationMembership as OrganizationMembership$1, OrganizationMembershipResource, OrganizationMembershipResource as OrganizationMembershipResource$1, OrganizationResource, OrganizationResource as OrganizationResource$1, OrganizationRole, Passkey, PasskeyCreation, RedirectCallbackResult, ReverificationCancelledError, ReverificationRequiredError, ReverificationRequirement, Session, Session as Session$1, SessionWithActivity, SignInResource, SignInResource as SignInResource$1, SignUpResource, SignUpResource as SignUpResource$1, SocialProvider, User, UserOrganizationInvitationResource, UserOrganizationInvitationResource as UserOrganizationInvitationResource$1, UserResource, UserResource as UserResource$1, Zautha, ZauthaApiError, ZauthaCaptchaError, ZauthaError, ZauthaErrorCode, ZauthaNetworkError, ZauthaOfflineError, ZauthaOptions, ZauthaPasskeyError, isReverificationCancelledError, isReverificationRequiredError, isZauthaApiError, isZauthaCaptchaError, isZauthaError, isZauthaNetworkError, isZauthaOfflineError, isZauthaPasskeyError } from "@zautha/js";
|
|
3
3
|
import { ReactNode } from "react";
|
|
4
4
|
//#region src/provider.d.ts
|
|
5
5
|
interface ZauthaProviderProps extends Omit<ZauthaOptions, "fetch"> {
|
|
@@ -15,6 +15,34 @@ export declare function ZauthaProvider({ publishableKey, children, ...options }:
|
|
|
15
15
|
/** The Zautha instance, or null before the provider has created it. */
|
|
16
16
|
export declare function useZautha(): Zautha | null;
|
|
17
17
|
//#endregion
|
|
18
|
+
//#region src/pagination.d.ts
|
|
19
|
+
/** A list's page size (default 10, the API's) and the page to start on (default 1). */
|
|
20
|
+
interface PaginationParams {
|
|
21
|
+
pageSize?: number;
|
|
22
|
+
initialPage?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* One page of a list and how to move through it. `isLoading`: the page has no data yet; `isFetching`: a request for it
|
|
26
|
+
* is in flight (also while `revalidate()` reads it again). A failed read leaves `data` empty and sets `error`.
|
|
27
|
+
*/
|
|
28
|
+
interface PaginatedResult<T> {
|
|
29
|
+
data: T[];
|
|
30
|
+
/** How many there are in all. */
|
|
31
|
+
count: number;
|
|
32
|
+
page: number;
|
|
33
|
+
pageCount: number;
|
|
34
|
+
isLoading: boolean;
|
|
35
|
+
isFetching: boolean;
|
|
36
|
+
error: Error | null;
|
|
37
|
+
hasNextPage: boolean;
|
|
38
|
+
hasPreviousPage: boolean;
|
|
39
|
+
fetchNext: () => void;
|
|
40
|
+
fetchPrevious: () => void;
|
|
41
|
+
fetchPage: (page: number) => void;
|
|
42
|
+
/** Reads the current page again; resolves once it has been read. */
|
|
43
|
+
revalidate: () => Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
18
46
|
//#region src/hooks.d.ts
|
|
19
47
|
/**
|
|
20
48
|
* What `has` checks in the session's active organization: full keys (`org:admin`, `org:invoices:read`). Every condition
|
|
@@ -87,6 +115,61 @@ interface UseSignUpResult {
|
|
|
87
115
|
fetchStatus: FetchStatus;
|
|
88
116
|
}
|
|
89
117
|
export declare function useSignUp(): UseSignUpResult;
|
|
118
|
+
/** A list a hook reads only when asked: `true` for the defaults, or the page size, the first page and the filters. */
|
|
119
|
+
type ListParams<Filters = object> = true | (PaginationParams & Filters);
|
|
120
|
+
interface UseOrganizationParams {
|
|
121
|
+
/** The active organization's members (needs `org:sys_memberships:read`), filtered by a role key. */
|
|
122
|
+
memberships?: ListParams<{
|
|
123
|
+
role?: string;
|
|
124
|
+
}>;
|
|
125
|
+
/** Its invitations, filtered by status; read only for a member with `org:sys_memberships:manage` (else empty). */
|
|
126
|
+
invitations?: ListParams<{
|
|
127
|
+
status?: OrganizationInvitationStatus$1[];
|
|
128
|
+
}>;
|
|
129
|
+
}
|
|
130
|
+
interface UseOrganizationResult {
|
|
131
|
+
isLoaded: boolean;
|
|
132
|
+
/** The session's active organization with the member's actions; null without one, while signed out or pending. */
|
|
133
|
+
organization: OrganizationResource$1 | null;
|
|
134
|
+
/** The user's membership of it: role and every permission of the role, system ones included (to show buttons). */
|
|
135
|
+
membership: OrganizationMembershipResource$1 | null;
|
|
136
|
+
/** Only when asked for in the params. */
|
|
137
|
+
memberships?: PaginatedResult<OrganizationMembership$1>;
|
|
138
|
+
invitations?: PaginatedResult<OrganizationInvitationResource$1>;
|
|
139
|
+
}
|
|
140
|
+
interface UseOrganizationListParams {
|
|
141
|
+
/** The user's memberships, newest first. */
|
|
142
|
+
userMemberships?: ListParams;
|
|
143
|
+
/** The invitations to the user's verified addresses; by default the pending ones. */
|
|
144
|
+
userInvitations?: ListParams<{
|
|
145
|
+
status?: OrganizationInvitationStatus$1[];
|
|
146
|
+
}>;
|
|
147
|
+
}
|
|
148
|
+
interface UseOrganizationListResult {
|
|
149
|
+
isLoaded: boolean;
|
|
150
|
+
/** Creates an organization with the user in it; it is not made active (`setActive` does that). */
|
|
151
|
+
createOrganization: (params: {
|
|
152
|
+
name: string;
|
|
153
|
+
slug?: string;
|
|
154
|
+
}) => Promise<OrganizationResource$1>;
|
|
155
|
+
/** Makes an organization (id or slug) the session's active one; null is the personal account. */
|
|
156
|
+
setActive: (params: {
|
|
157
|
+
organization: string | null;
|
|
158
|
+
}) => Promise<void>;
|
|
159
|
+
userMemberships?: PaginatedResult<OrganizationMembershipResource$1>;
|
|
160
|
+
userInvitations?: PaginatedResult<UserOrganizationInvitationResource$1>;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* The session's active organization and the user's membership of it, from the session token and the user (no request of
|
|
164
|
+
* its own), and on request its members and invitations, page by page. The lists start again on their first page when
|
|
165
|
+
* the active organization changes.
|
|
166
|
+
*/
|
|
167
|
+
export declare function useOrganization(params?: UseOrganizationParams): UseOrganizationResult;
|
|
168
|
+
/**
|
|
169
|
+
* Creating an organization and choosing the active one, and on request the user's memberships and the invitations to
|
|
170
|
+
* the user, page by page.
|
|
171
|
+
*/
|
|
172
|
+
export declare function useOrganizationList(params?: UseOrganizationListParams): UseOrganizationListResult;
|
|
90
173
|
//#endregion
|
|
91
174
|
//#region src/control.d.ts
|
|
92
175
|
type ShowWhen = "signed-in" | "signed-out" | HasParams | ((has: Has) => boolean);
|
|
@@ -142,6 +225,9 @@ export declare function AuthenticateWithRedirectCallback(props: import("@zautha/
|
|
|
142
225
|
export declare function UserButton(props: import("@zautha/ui").UserButtonProps): ReactNode;
|
|
143
226
|
export declare function UserProfile(props: import("@zautha/ui").UserProfileProps): ReactNode;
|
|
144
227
|
export declare function OAuthConsent(props: import("@zautha/ui").OAuthConsentProps): ReactNode;
|
|
228
|
+
export declare function CreateOrganization(props: import("@zautha/ui").CreateOrganizationProps): ReactNode;
|
|
229
|
+
export declare function OrganizationProfile(props: import("@zautha/ui").OrganizationProfileProps): ReactNode;
|
|
230
|
+
export declare function OrganizationSwitcher(props: import("@zautha/ui").OrganizationSwitcherProps): ReactNode;
|
|
145
231
|
//#endregion
|
|
146
|
-
export { type EmailAddress, type Environment, type ExternalAccount, type ExternalAccountResource, type Has, type HasParams, type OAuthStrategy, type Passkey, type PasskeyCreation, type RedirectCallbackResult, ReverificationCancelledError, ReverificationRequiredError, type ReverificationRequirement, type Session, type SessionWithActivity, type ShowWhen, type SignInResource, type SignUpResource, type SocialProvider, type UseAuthResult, type UseSignInResult, type UseSignUpResult, type User, type UserResource, ZauthaApiError, ZauthaCaptchaError, ZauthaError, type ZauthaErrorCode, ZauthaNetworkError, ZauthaOfflineError, ZauthaPasskeyError, type ZauthaProviderProps, isReverificationCancelledError, isReverificationRequiredError, isZauthaApiError, isZauthaCaptchaError, isZauthaError, isZauthaNetworkError, isZauthaOfflineError, isZauthaPasskeyError };
|
|
232
|
+
export { type EmailAddress, type Environment, type ExternalAccount, type ExternalAccountResource, type Has, type HasParams, type ListParams, type OAuthStrategy, type Organization, type OrganizationInvitation, type OrganizationInvitationResource, type OrganizationInvitationStatus, type OrganizationMembership, type OrganizationMembershipResource, type OrganizationResource, type OrganizationRole, type PaginatedResult, type PaginationParams, type Passkey, type PasskeyCreation, type RedirectCallbackResult, ReverificationCancelledError, ReverificationRequiredError, type ReverificationRequirement, type Session, type SessionWithActivity, type ShowWhen, type SignInResource, type SignUpResource, type SocialProvider, type UseAuthResult, type UseOrganizationListParams, type UseOrganizationListResult, type UseOrganizationParams, type UseOrganizationResult, type UseSignInResult, type UseSignUpResult, type User, type UserOrganizationInvitationResource, type UserResource, ZauthaApiError, ZauthaCaptchaError, ZauthaError, type ZauthaErrorCode, ZauthaNetworkError, ZauthaOfflineError, ZauthaPasskeyError, type ZauthaProviderProps, isReverificationCancelledError, isReverificationRequiredError, isZauthaApiError, isZauthaCaptchaError, isZauthaError, isZauthaNetworkError, isZauthaOfflineError, isZauthaPasskeyError };
|
|
147
233
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { ReverificationCancelledError, ReverificationRequiredError, Zautha, ZauthaApiError, ZauthaCaptchaError, ZauthaError, ZauthaNetworkError, ZauthaOfflineError, ZauthaPasskeyError, checkAuthorization, isReverificationCancelledError, isReverificationRequiredError, isZauthaApiError, isZauthaCaptchaError, isZauthaError, isZauthaNetworkError, isZauthaOfflineError, isZauthaPasskeyError, withReverification } from "@zautha/js";
|
|
2
|
+
import { ReverificationCancelledError, ReverificationRequiredError, Zautha, ZauthaApiError, ZauthaCaptchaError, ZauthaError, ZauthaError as ZauthaError$1, ZauthaNetworkError, ZauthaOfflineError, ZauthaPasskeyError, checkAuthorization, isReverificationCancelledError, isReverificationRequiredError, isZauthaApiError, isZauthaCaptchaError, isZauthaError, isZauthaNetworkError, isZauthaOfflineError, isZauthaPasskeyError, withReverification } from "@zautha/js";
|
|
3
3
|
import { Children, cloneElement, createContext, isValidElement, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
//#region src/provider.tsx
|
|
@@ -67,6 +67,105 @@ function useZauthaState() {
|
|
|
67
67
|
return useSyncExternalStore(zautha?.subscribe ?? noop, () => zautha?.getSnapshot() ?? pending, () => pending);
|
|
68
68
|
}
|
|
69
69
|
//#endregion
|
|
70
|
+
//#region src/pagination.ts
|
|
71
|
+
/**
|
|
72
|
+
* The pages of one list. Without a source nothing is read and the list is empty; a source with a new key starts again on
|
|
73
|
+
* the initial page. A response to an older request (another page, key or revalidation) is dropped, so it never
|
|
74
|
+
* overwrites a newer one.
|
|
75
|
+
*/
|
|
76
|
+
function usePages(source, params) {
|
|
77
|
+
const key = source?.key ?? null;
|
|
78
|
+
const { pageSize = 10, initialPage = 1 } = params === true || params === void 0 ? {} : params;
|
|
79
|
+
const [at, setAt] = useState({
|
|
80
|
+
key,
|
|
81
|
+
page: initialPage,
|
|
82
|
+
version: 0
|
|
83
|
+
});
|
|
84
|
+
const [settled, setSettled] = useState(null);
|
|
85
|
+
const latest = useRef(0);
|
|
86
|
+
const waiting = useRef([]);
|
|
87
|
+
if (at.key !== key) {
|
|
88
|
+
setAt({
|
|
89
|
+
key,
|
|
90
|
+
page: initialPage,
|
|
91
|
+
version: 0
|
|
92
|
+
});
|
|
93
|
+
setSettled(null);
|
|
94
|
+
}
|
|
95
|
+
const { page, version } = at.key === key ? at : {
|
|
96
|
+
page: initialPage,
|
|
97
|
+
version: 0
|
|
98
|
+
};
|
|
99
|
+
const request = JSON.stringify([
|
|
100
|
+
key,
|
|
101
|
+
page,
|
|
102
|
+
pageSize,
|
|
103
|
+
version
|
|
104
|
+
]);
|
|
105
|
+
const loader = useRef(source?.load);
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
loader.current = source?.load;
|
|
108
|
+
});
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
const id = ++latest.current;
|
|
111
|
+
const settle = (data, count, error) => {
|
|
112
|
+
if (latest.current !== id) return;
|
|
113
|
+
if (key !== null) setSettled({
|
|
114
|
+
request,
|
|
115
|
+
key,
|
|
116
|
+
page,
|
|
117
|
+
data,
|
|
118
|
+
count,
|
|
119
|
+
error
|
|
120
|
+
});
|
|
121
|
+
for (const resolve of waiting.current.splice(0)) resolve();
|
|
122
|
+
};
|
|
123
|
+
if (key === null || loader.current === void 0) return settle([], 0, null);
|
|
124
|
+
loader.current({
|
|
125
|
+
limit: pageSize,
|
|
126
|
+
offset: (page - 1) * pageSize
|
|
127
|
+
}).then((r) => settle(r.data, r.totalCount, null), (error) => settle([], 0, error instanceof Error ? error : new Error(String(error))));
|
|
128
|
+
}, [request]);
|
|
129
|
+
const shown = settled !== null && settled.key === key && settled.page === page ? settled : null;
|
|
130
|
+
const isFetching = key !== null && settled?.request !== request;
|
|
131
|
+
const count = shown?.count ?? 0;
|
|
132
|
+
const pageCount = Math.ceil(count / pageSize);
|
|
133
|
+
const go = useCallback((to) => setAt((a) => {
|
|
134
|
+
const from = a.key === key ? a.page : initialPage;
|
|
135
|
+
return {
|
|
136
|
+
key,
|
|
137
|
+
page: Math.max(1, to(from)),
|
|
138
|
+
version: a.key === key ? a.version : 0
|
|
139
|
+
};
|
|
140
|
+
}), [key, initialPage]);
|
|
141
|
+
const revalidate = useCallback(() => new Promise((resolve) => {
|
|
142
|
+
waiting.current.push(resolve);
|
|
143
|
+
setAt((a) => a.key === key ? {
|
|
144
|
+
...a,
|
|
145
|
+
version: a.version + 1
|
|
146
|
+
} : {
|
|
147
|
+
key,
|
|
148
|
+
page: initialPage,
|
|
149
|
+
version: 1
|
|
150
|
+
});
|
|
151
|
+
}), [key, initialPage]);
|
|
152
|
+
return {
|
|
153
|
+
data: shown?.data ?? [],
|
|
154
|
+
count,
|
|
155
|
+
page,
|
|
156
|
+
pageCount,
|
|
157
|
+
isLoading: isFetching && shown === null,
|
|
158
|
+
isFetching,
|
|
159
|
+
error: shown?.error ?? null,
|
|
160
|
+
hasNextPage: page < pageCount,
|
|
161
|
+
hasPreviousPage: page > 1,
|
|
162
|
+
fetchNext: useCallback(() => go((p) => p + 1), [go]),
|
|
163
|
+
fetchPrevious: useCallback(() => go((p) => p - 1), [go]),
|
|
164
|
+
fetchPage: useCallback((n) => go(() => n), [go]),
|
|
165
|
+
revalidate
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
//#endregion
|
|
70
169
|
//#region src/hooks.ts
|
|
71
170
|
const isLoadedStatus = (status) => status === "ready" || status === "degraded";
|
|
72
171
|
/** The signed-in session: a pending one (tasks left, e.g. setting up two-step verification) counts as signed out. */
|
|
@@ -168,6 +267,80 @@ function useSignUp() {
|
|
|
168
267
|
fetchStatus: snapshot?.fetchStatus ?? "idle"
|
|
169
268
|
};
|
|
170
269
|
}
|
|
270
|
+
/** A list's filters: its params without the page size and the first page. */
|
|
271
|
+
function filtersOf(params) {
|
|
272
|
+
const filters = { ...params === true ? {} : params };
|
|
273
|
+
delete filters.pageSize;
|
|
274
|
+
delete filters.initialPage;
|
|
275
|
+
return filters;
|
|
276
|
+
}
|
|
277
|
+
/** A list of `owner` read with `load`: its key (`owner` and the params, so new filters start the list again). */
|
|
278
|
+
const list = (owner, params, load) => ({
|
|
279
|
+
key: `${owner}:${JSON.stringify(params)}`,
|
|
280
|
+
load
|
|
281
|
+
});
|
|
282
|
+
/** The signed-in user (an active session's) and whether hooks that read it are loaded. */
|
|
283
|
+
function useSignedInUser() {
|
|
284
|
+
const zautha = useZautha();
|
|
285
|
+
const state = useZauthaState();
|
|
286
|
+
const user = activeSession(state) === null ? null : zautha?.user ?? null;
|
|
287
|
+
return {
|
|
288
|
+
isLoaded: isLoadedStatus(state.status) && (activeSession(state) === null || user !== null),
|
|
289
|
+
state,
|
|
290
|
+
user
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* The session's active organization and the user's membership of it, from the session token and the user (no request of
|
|
295
|
+
* its own), and on request its members and invitations, page by page. The lists start again on their first page when
|
|
296
|
+
* the active organization changes.
|
|
297
|
+
*/
|
|
298
|
+
function useOrganization(params = {}) {
|
|
299
|
+
const { isLoaded, state, user } = useSignedInUser();
|
|
300
|
+
const id = state.organization?.id;
|
|
301
|
+
const membership = user?.organizationMemberships.find((m) => m.organization.id === id) ?? null;
|
|
302
|
+
const organization = membership?.organization ?? null;
|
|
303
|
+
const owner = membership === null ? "" : `${membership.publicUserData.userId}:${membership.organization.id}`;
|
|
304
|
+
const { memberships, invitations } = params;
|
|
305
|
+
const manages = membership?.permissions.includes("org:sys_memberships:manage") === true;
|
|
306
|
+
const members = usePages(organization === null || memberships === void 0 ? null : list(owner, memberships, (page) => organization.getMemberships({
|
|
307
|
+
...filtersOf(memberships),
|
|
308
|
+
...page
|
|
309
|
+
})), memberships);
|
|
310
|
+
const invited = usePages(organization === null || invitations === void 0 || !manages ? null : list(owner, invitations, (page) => organization.getInvitations({
|
|
311
|
+
...filtersOf(invitations),
|
|
312
|
+
...page
|
|
313
|
+
})), invitations);
|
|
314
|
+
return {
|
|
315
|
+
isLoaded,
|
|
316
|
+
organization,
|
|
317
|
+
membership,
|
|
318
|
+
...memberships === void 0 ? {} : { memberships: members },
|
|
319
|
+
...invitations === void 0 ? {} : { invitations: invited }
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Creating an organization and choosing the active one, and on request the user's memberships and the invitations to
|
|
324
|
+
* the user, page by page.
|
|
325
|
+
*/
|
|
326
|
+
function useOrganizationList(params = {}) {
|
|
327
|
+
const zautha = useZautha();
|
|
328
|
+
const { isLoaded, user } = useSignedInUser();
|
|
329
|
+
const { userMemberships, userInvitations } = params;
|
|
330
|
+
const memberships = usePages(user === null || userMemberships === void 0 ? null : list(user.id, userMemberships, (page) => user.getOrganizationMemberships(page)), userMemberships);
|
|
331
|
+
const invitations = usePages(user === null || userInvitations === void 0 ? null : list(user.id, userInvitations, (page) => user.getOrganizationInvitations({
|
|
332
|
+
...filtersOf(userInvitations),
|
|
333
|
+
...page
|
|
334
|
+
})), userInvitations);
|
|
335
|
+
return {
|
|
336
|
+
isLoaded,
|
|
337
|
+
createOrganization: useCallback((p) => zautha?.createOrganization(p) ?? notLoaded(), [zautha]),
|
|
338
|
+
setActive: useCallback((p) => zautha?.setActive(p) ?? notLoaded(), [zautha]),
|
|
339
|
+
...userMemberships === void 0 ? {} : { userMemberships: memberships },
|
|
340
|
+
...userInvitations === void 0 ? {} : { userInvitations: invitations }
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
const notLoaded = () => Promise.reject(new ZauthaError$1("Zautha is not loaded yet."));
|
|
171
344
|
//#endregion
|
|
172
345
|
//#region src/control.tsx
|
|
173
346
|
/**
|
|
@@ -333,7 +506,25 @@ function OAuthConsent(props) {
|
|
|
333
506
|
componentProps: props
|
|
334
507
|
});
|
|
335
508
|
}
|
|
509
|
+
function CreateOrganization(props) {
|
|
510
|
+
return /* @__PURE__ */ jsx(Mounted, {
|
|
511
|
+
name: "CreateOrganization",
|
|
512
|
+
componentProps: props
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
function OrganizationProfile(props) {
|
|
516
|
+
return /* @__PURE__ */ jsx(Mounted, {
|
|
517
|
+
name: "OrganizationProfile",
|
|
518
|
+
componentProps: props
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
function OrganizationSwitcher(props) {
|
|
522
|
+
return /* @__PURE__ */ jsx(Mounted, {
|
|
523
|
+
name: "OrganizationSwitcher",
|
|
524
|
+
componentProps: props
|
|
525
|
+
});
|
|
526
|
+
}
|
|
336
527
|
//#endregion
|
|
337
|
-
export { AuthenticateWithRedirectCallback, OAuthConsent, RedirectToSignIn, RedirectToSignUp, ReverificationCancelledError, ReverificationRequiredError, Show, SignIn, SignInButton, SignOutButton, SignUp, SignUpButton, UserButton, UserProfile, ZauthaApiError, ZauthaCaptchaError, ZauthaDegraded, ZauthaError, ZauthaFailed, ZauthaLoaded, ZauthaLoading, ZauthaNetworkError, ZauthaOfflineError, ZauthaPasskeyError, ZauthaProvider, isReverificationCancelledError, isReverificationRequiredError, isZauthaApiError, isZauthaCaptchaError, isZauthaError, isZauthaNetworkError, isZauthaOfflineError, isZauthaPasskeyError, useAuth, useReverification, useSession, useSignIn, useSignUp, useUser, useZautha };
|
|
528
|
+
export { AuthenticateWithRedirectCallback, CreateOrganization, OAuthConsent, OrganizationProfile, OrganizationSwitcher, RedirectToSignIn, RedirectToSignUp, ReverificationCancelledError, ReverificationRequiredError, Show, SignIn, SignInButton, SignOutButton, SignUp, SignUpButton, UserButton, UserProfile, ZauthaApiError, ZauthaCaptchaError, ZauthaDegraded, ZauthaError, ZauthaFailed, ZauthaLoaded, ZauthaLoading, ZauthaNetworkError, ZauthaOfflineError, ZauthaPasskeyError, ZauthaProvider, isReverificationCancelledError, isReverificationRequiredError, isZauthaApiError, isZauthaCaptchaError, isZauthaError, isZauthaNetworkError, isZauthaOfflineError, isZauthaPasskeyError, useAuth, useOrganization, useOrganizationList, useReverification, useSession, useSignIn, useSignUp, useUser, useZautha };
|
|
338
529
|
|
|
339
530
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/provider.tsx","../src/hooks.ts","../src/control.tsx","../src/buttons.tsx","../src/prebuilt.tsx"],"sourcesContent":["import { Zautha, type ZauthaOptions, type ZauthaState } from \"@zautha/js\";\nimport { createContext, useContext, useEffect, useMemo, useState, useSyncExternalStore, type ReactNode } from \"react\";\n\ninterface ZauthaContextValue {\n readonly zautha: Zautha | null;\n /** The snapshot before the instance exists and during server rendering (carries `initialState`). */\n readonly pending: ZauthaState;\n}\n\nconst ZauthaContext = createContext<ZauthaContextValue | undefined>(undefined);\n\nexport interface ZauthaProviderProps extends Omit<ZauthaOptions, \"fetch\"> {\n publishableKey: string;\n children?: ReactNode;\n}\n\n/**\n * Creates the Zautha instance after mount (never during render, so StrictMode's double mount and SSR\n * create no timers or channels), loads it, and disposes it on unmount. Until then hooks report\n * `isLoaded: false`, unless `initialState` (the server's view, e.g. from @zautha/nextjs) says who is signed in.\n */\nexport function ZauthaProvider({ publishableKey, children, ...options }: ZauthaProviderProps): ReactNode {\n const [zautha, setZautha] = useState<Zautha | null>(null);\n const { ui, appearance, localization, signInUrl, signUpUrl, navigate, initialState } = options;\n const [pending] = useState<ZauthaState>(() => ({ ...NO_STATE, initialState: initialState ?? null }));\n\n useEffect(() => {\n const instance = new Zautha(publishableKey, {\n ...(ui === undefined ? {} : { ui }),\n ...(appearance === undefined ? {} : { appearance }),\n ...(localization === undefined ? {} : { localization }),\n ...(signInUrl === undefined ? {} : { signInUrl }),\n ...(signUpUrl === undefined ? {} : { signUpUrl }),\n ...(navigate === undefined ? {} : { navigate }),\n ...(initialState === undefined ? {} : { initialState }),\n });\n // The instance is an external system: it is created here, never during render, and published through state.\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setZautha(instance);\n void instance.load();\n return () => {\n instance.dispose();\n setZautha(null);\n };\n // Appearance/localization objects are read at mount; changing the key re-creates the instance.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [publishableKey]);\n\n const value = useMemo(() => ({ zautha, pending }), [zautha, pending]);\n return <ZauthaContext.Provider value={value}>{children}</ZauthaContext.Provider>;\n}\n\n/** The Zautha instance, or null before the provider has created it. */\nexport function useZautha(): Zautha | null {\n return useZauthaContext().zautha;\n}\n\nfunction useZauthaContext(): ZauthaContextValue {\n const value = useContext(ZauthaContext);\n if (value === undefined) throw new Error(\"Zautha hooks and components must be used inside <ZauthaProvider>.\");\n return value;\n}\n\nconst NO_STATE: ZauthaState = {\n status: \"loading\",\n environment: null,\n client: null,\n session: null,\n user: null,\n organization: null,\n initialState: null,\n};\nconst noop = (): (() => void) => () => undefined;\n\n/** Reactive snapshot of the instance state (the loading state, with any initial state, before the instance exists). */\nexport function useZauthaState(): ZauthaState {\n const { zautha, pending } = useZauthaContext();\n return useSyncExternalStore(\n zautha?.subscribe ?? noop,\n () => zautha?.getSnapshot() ?? pending,\n () => pending,\n );\n}\n","import {\n checkAuthorization,\n withReverification,\n type AttemptErrors,\n type FetchStatus,\n type Session,\n type SignInResource,\n type SignUpResource,\n type UserResource,\n type ZauthaState,\n} from \"@zautha/js\";\nimport { useCallback, useLayoutEffect, useRef, useSyncExternalStore } from \"react\";\nimport { useZautha, useZauthaState } from \"./provider\";\n\n/**\n * What `has` checks in the session's active organization: full keys (`org:admin`, `org:invoices:read`). Every condition\n * given must hold; with none, false.\n */\nexport type HasParams = { role?: string; permission?: string };\nexport type Has = (params: HasParams) => boolean;\n\nexport interface UseAuthResult {\n isLoaded: boolean;\n isSignedIn: boolean;\n userId: string | null;\n sessionId: string | null;\n /** The active organization (`org_…`); null without one, and while signed out. */\n orgId: string | null;\n /** The user's role in it, a full key such as `org:admin`. */\n orgRole: string | null;\n /** Its slug; null without one or while the instance has slugs off. */\n orgSlug: string | null;\n /** The role's custom permissions, full keys such as `org:invoices:read`. */\n orgPermissions: readonly string[] | null;\n getToken: (options?: { skipCache?: boolean }) => Promise<string | null>;\n signOut: (options?: { redirectUrl?: string }) => Promise<void>;\n /**\n * From the session token alone, the same rule as every Zautha SDK and your server: false without an active\n * organization, and always false for a system permission (`org:sys_…`, never in the token).\n */\n has: Has;\n}\n\nconst isLoadedStatus = (status: string): boolean => status === \"ready\" || status === \"degraded\";\n\n/** The signed-in session: a pending one (tasks left, e.g. setting up two-step verification) counts as signed out. */\nconst activeSession = (state: ZauthaState): Session | null =>\n state.session?.status === \"active\" ? state.session : null;\n\nexport function useAuth(): UseAuthResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const getToken = useCallback(\n (options?: { skipCache?: boolean }) => zautha?.getToken(options) ?? Promise.resolve(null),\n [zautha],\n );\n const signOut = useCallback(\n (options?: { redirectUrl?: string }) => zautha?.signOut(options) ?? Promise.resolve(),\n [zautha],\n );\n // Until the first load settles, the server's initial state (if any) answers, so nothing flickers.\n const initial = state.status === \"loading\" ? state.initialState : null;\n const session = activeSession(state);\n const userId = initial === null ? (session?.userId ?? null) : initial.userId;\n const sessionId = initial === null ? (session?.id ?? null) : initial.sessionId;\n const signedIn = userId !== null;\n const organization = initial === null ? (session === null ? null : state.organization) : initial.organization;\n const has = useCallback<Has>((params) => checkAuthorization(organization, params), [organization]);\n return {\n isLoaded: isLoadedStatus(state.status) || initial !== null,\n isSignedIn: signedIn,\n userId,\n sessionId,\n orgId: organization?.id ?? null,\n orgRole: organization?.role ?? null,\n orgSlug: organization?.slug ?? null,\n orgPermissions: organization?.permissions ?? null,\n getToken,\n signOut,\n has,\n };\n}\n\n/** The signed-in user with its self-service actions (`user.update`, `user.createEmailAddress`, …). */\nexport function useUser(): { isLoaded: boolean; isSignedIn: boolean; user: UserResource | null } {\n const zautha = useZautha();\n const state = useZauthaState();\n const signedIn = activeSession(state) !== null;\n // zautha.user is rebuilt only when state.user changes, so the resource is stable between renders.\n const user = !signedIn || state.user === null ? null : (zautha?.user ?? null);\n return { isLoaded: isLoadedStatus(state.status), isSignedIn: signedIn, user };\n}\n\n/**\n * Wraps a sensitive action so that it completes after an identity check when it needs one: when `fetcher` throws\n * `ReverificationRequiredError` (e.g. `user.updatePassword`) or resolves to a `Response` with the `403\n * reverification_required` body (your backend with @zautha/backend, @zautha/nextjs or Zautha.AspNetCore), the\n * reverification modal opens and, once the user has verified, `fetcher` runs once more with the same arguments (its\n * token is fresh by then). Closing the modal rejects with `ReverificationCancelledError`. Needs `ui` from @zautha/ui on\n * the provider. The returned function is stable; it always calls the latest `fetcher`.\n */\nexport function useReverification<Args extends unknown[], Result>(\n fetcher: (...args: Args) => Promise<Result>,\n): (...args: Args) => Promise<Result> {\n const zautha = useZautha();\n const latest = useRef(fetcher);\n useLayoutEffect(() => {\n latest.current = fetcher;\n });\n return useCallback(\n (...args: Args) => {\n const call = (...callArgs: Args): Promise<Result> => latest.current(...callArgs);\n // Before the provider has created the instance no modal can open: the action runs as it is.\n return zautha === null ? call(...args) : withReverification(zautha, call)(...args);\n },\n [zautha],\n );\n}\n\n/** The signed-in session; null while signed out or while the session is pending (tasks left). */\nexport function useSession(): { isLoaded: boolean; isSignedIn: boolean; session: Session | null } {\n const state = useZauthaState();\n const session = activeSession(state);\n return { isLoaded: isLoadedStatus(state.status), isSignedIn: session !== null, session };\n}\n\nconst noopSubscribe = (): (() => void) => () => undefined;\n\nfunction useResource<T extends SignInResource | SignUpResource>(resource: T | null) {\n const snapshot = useSyncExternalStore(\n resource?.subscribe ?? noopSubscribe,\n () => resource?.snapshot ?? null,\n () => null,\n );\n return snapshot;\n}\n\nexport interface UseSignInResult {\n isLoaded: boolean;\n /** The sign-in resource; null until the provider has created the instance. */\n signIn: SignInResource | null;\n errors: AttemptErrors;\n fetchStatus: FetchStatus;\n}\n\nconst NO_ERRORS: AttemptErrors = { fields: {}, global: [] };\n\nexport function useSignIn(): UseSignInResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const snapshot = useResource(zautha?.signIn ?? null);\n return {\n isLoaded: isLoadedStatus(state.status),\n signIn: zautha?.signIn ?? null,\n errors: snapshot?.errors ?? NO_ERRORS,\n fetchStatus: snapshot?.fetchStatus ?? \"idle\",\n };\n}\n\nexport interface UseSignUpResult {\n isLoaded: boolean;\n signUp: SignUpResource | null;\n errors: AttemptErrors;\n fetchStatus: FetchStatus;\n}\n\nexport function useSignUp(): UseSignUpResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const snapshot = useResource(zautha?.signUp ?? null);\n return {\n isLoaded: isLoadedStatus(state.status),\n signUp: zautha?.signUp ?? null,\n errors: snapshot?.errors ?? NO_ERRORS,\n fetchStatus: snapshot?.fetchStatus ?? \"idle\",\n };\n}\n","import { useEffect, type ReactNode } from \"react\";\nimport { useAuth, type Has, type HasParams } from \"./hooks\";\nimport { useZautha, useZauthaState } from \"./provider\";\n\nexport type ShowWhen = \"signed-in\" | \"signed-out\" | HasParams | ((has: Has) => boolean);\n\n/**\n * Renders `children` when the condition holds, else `fallback`. Renders nothing until Zautha has\n * loaded, so a signed-in user never sees a signed-out flash.\n */\nexport function Show(props: { when: ShowWhen; fallback?: ReactNode; children?: ReactNode }): ReactNode {\n const { isLoaded, isSignedIn, has } = useAuth();\n if (!isLoaded) return null;\n const { when } = props;\n const pass =\n when === \"signed-in\"\n ? isSignedIn\n : when === \"signed-out\"\n ? !isSignedIn\n : typeof when === \"function\"\n ? when(has)\n : has(when);\n return pass ? props.children : (props.fallback ?? null);\n}\n\nexport function ZauthaLoading(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"loading\" ? props.children : null;\n}\n\n/** Loaded, including degraded (network trouble after load: last known state is shown). */\nexport function ZauthaLoaded(props: { children?: ReactNode }): ReactNode {\n const { status } = useZauthaState();\n return status === \"ready\" || status === \"degraded\" ? props.children : null;\n}\n\nexport function ZauthaDegraded(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"degraded\" ? props.children : null;\n}\n\nexport function ZauthaFailed(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"failed\" ? props.children : null;\n}\n\n/** Sends a signed-out visitor to sign-in once loaded; renders nothing. */\nexport function RedirectToSignIn(props: { redirectUrl?: string }): ReactNode {\n const zautha = useZautha();\n const { isLoaded, isSignedIn } = useAuth();\n const { redirectUrl } = props;\n useEffect(() => {\n if (zautha !== null && isLoaded && !isSignedIn)\n zautha.redirectToSignIn(redirectUrl === undefined ? {} : { redirectUrl });\n }, [zautha, isLoaded, isSignedIn, redirectUrl]);\n return null;\n}\n\nexport function RedirectToSignUp(props: { redirectUrl?: string }): ReactNode {\n const zautha = useZautha();\n const { isLoaded, isSignedIn } = useAuth();\n const { redirectUrl } = props;\n useEffect(() => {\n if (zautha !== null && isLoaded && !isSignedIn)\n zautha.redirectToSignUp(redirectUrl === undefined ? {} : { redirectUrl });\n }, [zautha, isLoaded, isSignedIn, redirectUrl]);\n return null;\n}\n","import { Children, cloneElement, isValidElement, type MouseEvent, type ReactElement, type ReactNode } from \"react\";\nimport { useZautha } from \"./provider\";\n\ninterface ButtonProps {\n /** `redirect` (default) goes to the sign-in page; `modal` opens the prebuilt component (needs `ui`). */\n mode?: \"redirect\" | \"modal\";\n redirectUrl?: string;\n children?: ReactNode;\n}\n\n/** Wraps its single child (or renders a plain button) and wires the click. Unstyled by design. */\nfunction Trigger(props: { children: ReactNode; label: string; onClick: () => void }): ReactNode {\n const child = Children.count(props.children) === 1 ? Children.only(props.children) : null;\n if (isValidElement<{ onClick?: (event: MouseEvent) => void }>(child)) {\n const original = child.props.onClick;\n return cloneElement(child as ReactElement<{ onClick?: (event: MouseEvent) => void }>, {\n onClick: (event: MouseEvent) => {\n original?.(event);\n if (!event.defaultPrevented) props.onClick();\n },\n });\n }\n return (\n <button type=\"button\" onClick={props.onClick}>\n {props.children ?? props.label}\n </button>\n );\n}\n\nexport function SignInButton(props: ButtonProps): ReactNode {\n const zautha = useZautha();\n const options = props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl };\n return (\n <Trigger\n label=\"Sign in\"\n onClick={() => (props.mode === \"modal\" ? zautha?.openSignIn(options) : zautha?.redirectToSignIn(options))}\n >\n {props.children}\n </Trigger>\n );\n}\n\nexport function SignUpButton(props: ButtonProps): ReactNode {\n const zautha = useZautha();\n const options = props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl };\n return (\n <Trigger\n label=\"Sign up\"\n onClick={() => (props.mode === \"modal\" ? zautha?.openSignUp(options) : zautha?.redirectToSignUp(options))}\n >\n {props.children}\n </Trigger>\n );\n}\n\nexport function SignOutButton(props: { redirectUrl?: string; children?: ReactNode }): ReactNode {\n const zautha = useZautha();\n return (\n <Trigger\n label=\"Sign out\"\n onClick={() => void zautha?.signOut(props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl })}\n >\n {props.children}\n </Trigger>\n );\n}\n","import type { UiComponentName } from \"@zautha/js\";\nimport { useEffect, useRef, type ReactNode } from \"react\";\nimport { useZautha } from \"./provider\";\n\n/**\n * Mounts a @zautha/ui component into a div once the instance exists; later prop changes update it in\n * place. SSR renders only the empty div.\n */\nfunction Mounted(props: { name: UiComponentName; componentProps: object }): ReactNode {\n const zautha = useZautha();\n const ref = useRef<HTMLDivElement>(null);\n const mountedWith = useRef<object | null>(null);\n const { name, componentProps } = props;\n\n useEffect(() => {\n const element = ref.current;\n if (zautha === null || element === null) return;\n zautha.mount(name, element, componentProps);\n mountedWith.current = componentProps;\n return () => {\n mountedWith.current = null;\n zautha.unmount(element);\n };\n // componentProps changes are applied by the effect below without remounting.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [zautha, name]);\n\n useEffect(() => {\n const element = ref.current;\n if (zautha === null || element === null || mountedWith.current === null || mountedWith.current === componentProps)\n return;\n mountedWith.current = componentProps;\n zautha.updateMounted(element, componentProps);\n }, [zautha, componentProps]);\n\n return <div ref={ref} />;\n}\n\n// Prop types live in @zautha/ui; they are structural here so @zautha/react has no runtime dependency on it.\nexport function SignIn(props: import(\"@zautha/ui\").SignInProps): ReactNode {\n return <Mounted name=\"SignIn\" componentProps={props} />;\n}\n\nexport function SignUp(props: import(\"@zautha/ui\").SignUpProps): ReactNode {\n return <Mounted name=\"SignUp\" componentProps={props} />;\n}\n\n/** The page a provider sends the user back to: finishes the social sign-in or sign-up (see @zautha/ui). */\nexport function AuthenticateWithRedirectCallback(\n props: import(\"@zautha/ui\").AuthenticateWithRedirectCallbackProps,\n): ReactNode {\n return <Mounted name=\"AuthenticateWithRedirectCallback\" componentProps={props} />;\n}\n\nexport function UserButton(props: import(\"@zautha/ui\").UserButtonProps): ReactNode {\n return <Mounted name=\"UserButton\" componentProps={props} />;\n}\n\nexport function UserProfile(props: import(\"@zautha/ui\").UserProfileProps): ReactNode {\n return <Mounted name=\"UserProfile\" componentProps={props} />;\n}\n\nexport function OAuthConsent(props: import(\"@zautha/ui\").OAuthConsentProps): ReactNode {\n return <Mounted name=\"OAuthConsent\" componentProps={props} />;\n}\n"],"mappings":";;;;;AASA,MAAM,gBAAgB,cAA8C,KAAA,CAAS;;;;;;AAY7E,SAAgB,eAAe,EAAE,gBAAgB,UAAU,GAAG,WAA2C;CACvG,MAAM,CAAC,QAAQ,aAAa,SAAwB,IAAI;CACxD,MAAM,EAAE,IAAI,YAAY,cAAc,WAAW,WAAW,UAAU,iBAAiB;CACvF,MAAM,CAAC,WAAW,gBAA6B;EAAE,GAAG;EAAU,cAAc,gBAAgB;CAAK,EAAE;CAEnG,gBAAgB;EACd,MAAM,WAAW,IAAI,OAAO,gBAAgB;GAC1C,GAAI,OAAO,KAAA,IAAY,CAAC,IAAI,EAAE,GAAG;GACjC,GAAI,eAAe,KAAA,IAAY,CAAC,IAAI,EAAE,WAAW;GACjD,GAAI,iBAAiB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa;GACrD,GAAI,cAAc,KAAA,IAAY,CAAC,IAAI,EAAE,UAAU;GAC/C,GAAI,cAAc,KAAA,IAAY,CAAC,IAAI,EAAE,UAAU;GAC/C,GAAI,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS;GAC7C,GAAI,iBAAiB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa;EACvD,CAAC;EAGD,UAAU,QAAQ;EAClB,SAAc,KAAK;EACnB,aAAa;GACX,SAAS,QAAQ;GACjB,UAAU,IAAI;EAChB;CAGF,GAAG,CAAC,cAAc,CAAC;CAEnB,MAAM,QAAQ,eAAe;EAAE;EAAQ;C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D;CACzE,OAAO,oBAAC,SAAD;EAAS,MAAK;EAAS,gBAAgB;CAAQ,CAAA;AACxD;;AAGA,SAAgB,iCACd,OACW;CACX,OAAO,oBAAC,SAAD;EAAS,MAAK;EAAmC,gBAAgB;CAAQ,CAAA;AAClF;AAEA,SAAgB,WAAW,OAAwD;CACjF,OAAO,oBAAC,SAAD;EAAS,MAAK;EAAa,gBAAgB;CAAQ,CAAA;AAC5D;AAEA,SAAgB,YAAY,OAAyD;CACnF,OAAO,oBAAC,SAAD;EAAS,MAAK;EAAc,gBAAgB;CAAQ,CAAA;AAC7D;AAEA,SAAgB,aAAa,OAA0D;CACrF,OAAO,oBAAC,SAAD;EAAS,MAAK;EAAe,gBAAgB;CAAQ,CAAA;AAC9D"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["ZauthaError"],"sources":["../src/provider.tsx","../src/pagination.ts","../src/hooks.ts","../src/control.tsx","../src/buttons.tsx","../src/prebuilt.tsx"],"sourcesContent":["import { Zautha, type ZauthaOptions, type ZauthaState } from \"@zautha/js\";\nimport { createContext, useContext, useEffect, useMemo, useState, useSyncExternalStore, type ReactNode } from \"react\";\n\ninterface ZauthaContextValue {\n readonly zautha: Zautha | null;\n /** The snapshot before the instance exists and during server rendering (carries `initialState`). */\n readonly pending: ZauthaState;\n}\n\nconst ZauthaContext = createContext<ZauthaContextValue | undefined>(undefined);\n\nexport interface ZauthaProviderProps extends Omit<ZauthaOptions, \"fetch\"> {\n publishableKey: string;\n children?: ReactNode;\n}\n\n/**\n * Creates the Zautha instance after mount (never during render, so StrictMode's double mount and SSR\n * create no timers or channels), loads it, and disposes it on unmount. Until then hooks report\n * `isLoaded: false`, unless `initialState` (the server's view, e.g. from @zautha/nextjs) says who is signed in.\n */\nexport function ZauthaProvider({ publishableKey, children, ...options }: ZauthaProviderProps): ReactNode {\n const [zautha, setZautha] = useState<Zautha | null>(null);\n const { ui, appearance, localization, signInUrl, signUpUrl, navigate, initialState } = options;\n const [pending] = useState<ZauthaState>(() => ({ ...NO_STATE, initialState: initialState ?? null }));\n\n useEffect(() => {\n const instance = new Zautha(publishableKey, {\n ...(ui === undefined ? {} : { ui }),\n ...(appearance === undefined ? {} : { appearance }),\n ...(localization === undefined ? {} : { localization }),\n ...(signInUrl === undefined ? {} : { signInUrl }),\n ...(signUpUrl === undefined ? {} : { signUpUrl }),\n ...(navigate === undefined ? {} : { navigate }),\n ...(initialState === undefined ? {} : { initialState }),\n });\n // The instance is an external system: it is created here, never during render, and published through state.\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setZautha(instance);\n void instance.load();\n return () => {\n instance.dispose();\n setZautha(null);\n };\n // Appearance/localization objects are read at mount; changing the key re-creates the instance.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [publishableKey]);\n\n const value = useMemo(() => ({ zautha, pending }), [zautha, pending]);\n return <ZauthaContext.Provider value={value}>{children}</ZauthaContext.Provider>;\n}\n\n/** The Zautha instance, or null before the provider has created it. */\nexport function useZautha(): Zautha | null {\n return useZauthaContext().zautha;\n}\n\nfunction useZauthaContext(): ZauthaContextValue {\n const value = useContext(ZauthaContext);\n if (value === undefined) throw new Error(\"Zautha hooks and components must be used inside <ZauthaProvider>.\");\n return value;\n}\n\nconst NO_STATE: ZauthaState = {\n status: \"loading\",\n environment: null,\n client: null,\n session: null,\n user: null,\n organization: null,\n initialState: null,\n};\nconst noop = (): (() => void) => () => undefined;\n\n/** Reactive snapshot of the instance state (the loading state, with any initial state, before the instance exists). */\nexport function useZauthaState(): ZauthaState {\n const { zautha, pending } = useZauthaContext();\n return useSyncExternalStore(\n zautha?.subscribe ?? noop,\n () => zautha?.getSnapshot() ?? pending,\n () => pending,\n );\n}\n","import type { Paginated } from \"@zautha/js\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\n\n/** A list's page size (default 10, the API's) and the page to start on (default 1). */\nexport interface PaginationParams {\n pageSize?: number;\n initialPage?: number;\n}\n\n/**\n * One page of a list and how to move through it. `isLoading`: the page has no data yet; `isFetching`: a request for it\n * is in flight (also while `revalidate()` reads it again). A failed read leaves `data` empty and sets `error`.\n */\nexport interface PaginatedResult<T> {\n data: T[];\n /** How many there are in all. */\n count: number;\n page: number;\n pageCount: number;\n isLoading: boolean;\n isFetching: boolean;\n error: Error | null;\n hasNextPage: boolean;\n hasPreviousPage: boolean;\n fetchNext: () => void;\n fetchPrevious: () => void;\n fetchPage: (page: number) => void;\n /** Reads the current page again; resolves once it has been read. */\n revalidate: () => Promise<void>;\n}\n\n/** What a page read gets: 1–100 items after `offset`. */\nexport type PageLoader<T> = (page: { limit: number; offset: number }) => Promise<Paginated<T>>;\n\n/** A list to read: `key` names what is listed (the user, the organization, the filters); `load` reads one page. */\nexport interface PageSource<T> {\n readonly key: string;\n readonly load: PageLoader<T>;\n}\n\ninterface Settled<T> {\n readonly request: string;\n readonly key: string;\n readonly page: number;\n readonly data: T[];\n readonly count: number;\n readonly error: Error | null;\n}\n\n/**\n * The pages of one list. Without a source nothing is read and the list is empty; a source with a new key starts again on\n * the initial page. A response to an older request (another page, key or revalidation) is dropped, so it never\n * overwrites a newer one.\n */\nexport function usePages<T>(\n source: PageSource<T> | null,\n params: PaginationParams | true | undefined,\n): PaginatedResult<T> {\n const key = source?.key ?? null;\n const { pageSize = 10, initialPage = 1 } = params === true || params === undefined ? {} : params;\n const [at, setAt] = useState({ key, page: initialPage, version: 0 });\n const [settled, setSettled] = useState<Settled<T> | null>(null);\n const latest = useRef(0);\n const waiting = useRef<(() => void)[]>([]);\n if (at.key !== key) {\n // Another list (also an earlier one again): start on its initial page with a fresh read, whatever was shown before.\n setAt({ key, page: initialPage, version: 0 });\n setSettled(null);\n }\n const { page, version } = at.key === key ? at : { page: initialPage, version: 0 };\n const request = JSON.stringify([key, page, pageSize, version]);\n const loader = useRef(source?.load);\n useEffect(() => {\n loader.current = source?.load;\n });\n\n useEffect(() => {\n const id = ++latest.current;\n const settle = (data: T[], count: number, error: Error | null): void => {\n if (latest.current !== id) return;\n if (key !== null) setSettled({ request, key, page, data, count, error });\n for (const resolve of waiting.current.splice(0)) resolve();\n };\n if (key === null || loader.current === undefined) return settle([], 0, null);\n loader.current({ limit: pageSize, offset: (page - 1) * pageSize }).then(\n (r) => settle(r.data, r.totalCount, null),\n (error: unknown) => settle([], 0, error instanceof Error ? error : new Error(String(error))),\n );\n // `request` covers key, page, pageSize and version.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [request]);\n\n const shown = settled !== null && settled.key === key && settled.page === page ? settled : null;\n const isFetching = key !== null && settled?.request !== request;\n const count = shown?.count ?? 0;\n const pageCount = Math.ceil(count / pageSize);\n const go = useCallback(\n (to: (page: number) => number) =>\n setAt((a) => {\n const from = a.key === key ? a.page : initialPage;\n return { key, page: Math.max(1, to(from)), version: a.key === key ? a.version : 0 };\n }),\n [key, initialPage],\n );\n const revalidate = useCallback(\n () =>\n new Promise<void>((resolve) => {\n waiting.current.push(resolve);\n setAt((a) => (a.key === key ? { ...a, version: a.version + 1 } : { key, page: initialPage, version: 1 }));\n }),\n [key, initialPage],\n );\n return {\n data: shown?.data ?? [],\n count,\n page,\n pageCount,\n isLoading: isFetching && shown === null,\n isFetching,\n error: shown?.error ?? null,\n hasNextPage: page < pageCount,\n hasPreviousPage: page > 1,\n fetchNext: useCallback(() => go((p) => p + 1), [go]),\n fetchPrevious: useCallback(() => go((p) => p - 1), [go]),\n fetchPage: useCallback((n: number) => go(() => n), [go]),\n revalidate,\n };\n}\n","import {\n checkAuthorization,\n withReverification,\n ZauthaError,\n type AttemptErrors,\n type FetchStatus,\n type OrganizationInvitationResource,\n type OrganizationInvitationStatus,\n type OrganizationMembership,\n type OrganizationMembershipResource,\n type OrganizationResource,\n type Session,\n type SignInResource,\n type SignUpResource,\n type UserOrganizationInvitationResource,\n type UserResource,\n type ZauthaState,\n} from \"@zautha/js\";\nimport { useCallback, useLayoutEffect, useRef, useSyncExternalStore } from \"react\";\nimport { usePages, type PageLoader, type PageSource, type PaginatedResult, type PaginationParams } from \"./pagination\";\nimport { useZautha, useZauthaState } from \"./provider\";\n\n/**\n * What `has` checks in the session's active organization: full keys (`org:admin`, `org:invoices:read`). Every condition\n * given must hold; with none, false.\n */\nexport type HasParams = { role?: string; permission?: string };\nexport type Has = (params: HasParams) => boolean;\n\nexport interface UseAuthResult {\n isLoaded: boolean;\n isSignedIn: boolean;\n userId: string | null;\n sessionId: string | null;\n /** The active organization (`org_…`); null without one, and while signed out. */\n orgId: string | null;\n /** The user's role in it, a full key such as `org:admin`. */\n orgRole: string | null;\n /** Its slug; null without one or while the instance has slugs off. */\n orgSlug: string | null;\n /** The role's custom permissions, full keys such as `org:invoices:read`. */\n orgPermissions: readonly string[] | null;\n getToken: (options?: { skipCache?: boolean }) => Promise<string | null>;\n signOut: (options?: { redirectUrl?: string }) => Promise<void>;\n /**\n * From the session token alone, the same rule as every Zautha SDK and your server: false without an active\n * organization, and always false for a system permission (`org:sys_…`, never in the token).\n */\n has: Has;\n}\n\nconst isLoadedStatus = (status: string): boolean => status === \"ready\" || status === \"degraded\";\n\n/** The signed-in session: a pending one (tasks left, e.g. setting up two-step verification) counts as signed out. */\nconst activeSession = (state: ZauthaState): Session | null =>\n state.session?.status === \"active\" ? state.session : null;\n\nexport function useAuth(): UseAuthResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const getToken = useCallback(\n (options?: { skipCache?: boolean }) => zautha?.getToken(options) ?? Promise.resolve(null),\n [zautha],\n );\n const signOut = useCallback(\n (options?: { redirectUrl?: string }) => zautha?.signOut(options) ?? Promise.resolve(),\n [zautha],\n );\n // Until the first load settles, the server's initial state (if any) answers, so nothing flickers.\n const initial = state.status === \"loading\" ? state.initialState : null;\n const session = activeSession(state);\n const userId = initial === null ? (session?.userId ?? null) : initial.userId;\n const sessionId = initial === null ? (session?.id ?? null) : initial.sessionId;\n const signedIn = userId !== null;\n const organization = initial === null ? (session === null ? null : state.organization) : initial.organization;\n const has = useCallback<Has>((params) => checkAuthorization(organization, params), [organization]);\n return {\n isLoaded: isLoadedStatus(state.status) || initial !== null,\n isSignedIn: signedIn,\n userId,\n sessionId,\n orgId: organization?.id ?? null,\n orgRole: organization?.role ?? null,\n orgSlug: organization?.slug ?? null,\n orgPermissions: organization?.permissions ?? null,\n getToken,\n signOut,\n has,\n };\n}\n\n/** The signed-in user with its self-service actions (`user.update`, `user.createEmailAddress`, …). */\nexport function useUser(): { isLoaded: boolean; isSignedIn: boolean; user: UserResource | null } {\n const zautha = useZautha();\n const state = useZauthaState();\n const signedIn = activeSession(state) !== null;\n // zautha.user is rebuilt only when state.user changes, so the resource is stable between renders.\n const user = !signedIn || state.user === null ? null : (zautha?.user ?? null);\n return { isLoaded: isLoadedStatus(state.status), isSignedIn: signedIn, user };\n}\n\n/**\n * Wraps a sensitive action so that it completes after an identity check when it needs one: when `fetcher` throws\n * `ReverificationRequiredError` (e.g. `user.updatePassword`) or resolves to a `Response` with the `403\n * reverification_required` body (your backend with @zautha/backend, @zautha/nextjs or Zautha.AspNetCore), the\n * reverification modal opens and, once the user has verified, `fetcher` runs once more with the same arguments (its\n * token is fresh by then). Closing the modal rejects with `ReverificationCancelledError`. Needs `ui` from @zautha/ui on\n * the provider. The returned function is stable; it always calls the latest `fetcher`.\n */\nexport function useReverification<Args extends unknown[], Result>(\n fetcher: (...args: Args) => Promise<Result>,\n): (...args: Args) => Promise<Result> {\n const zautha = useZautha();\n const latest = useRef(fetcher);\n useLayoutEffect(() => {\n latest.current = fetcher;\n });\n return useCallback(\n (...args: Args) => {\n const call = (...callArgs: Args): Promise<Result> => latest.current(...callArgs);\n // Before the provider has created the instance no modal can open: the action runs as it is.\n return zautha === null ? call(...args) : withReverification(zautha, call)(...args);\n },\n [zautha],\n );\n}\n\n/** The signed-in session; null while signed out or while the session is pending (tasks left). */\nexport function useSession(): { isLoaded: boolean; isSignedIn: boolean; session: Session | null } {\n const state = useZauthaState();\n const session = activeSession(state);\n return { isLoaded: isLoadedStatus(state.status), isSignedIn: session !== null, session };\n}\n\nconst noopSubscribe = (): (() => void) => () => undefined;\n\nfunction useResource<T extends SignInResource | SignUpResource>(resource: T | null) {\n const snapshot = useSyncExternalStore(\n resource?.subscribe ?? noopSubscribe,\n () => resource?.snapshot ?? null,\n () => null,\n );\n return snapshot;\n}\n\nexport interface UseSignInResult {\n isLoaded: boolean;\n /** The sign-in resource; null until the provider has created the instance. */\n signIn: SignInResource | null;\n errors: AttemptErrors;\n fetchStatus: FetchStatus;\n}\n\nconst NO_ERRORS: AttemptErrors = { fields: {}, global: [] };\n\nexport function useSignIn(): UseSignInResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const snapshot = useResource(zautha?.signIn ?? null);\n return {\n isLoaded: isLoadedStatus(state.status),\n signIn: zautha?.signIn ?? null,\n errors: snapshot?.errors ?? NO_ERRORS,\n fetchStatus: snapshot?.fetchStatus ?? \"idle\",\n };\n}\n\nexport interface UseSignUpResult {\n isLoaded: boolean;\n signUp: SignUpResource | null;\n errors: AttemptErrors;\n fetchStatus: FetchStatus;\n}\n\nexport function useSignUp(): UseSignUpResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const snapshot = useResource(zautha?.signUp ?? null);\n return {\n isLoaded: isLoadedStatus(state.status),\n signUp: zautha?.signUp ?? null,\n errors: snapshot?.errors ?? NO_ERRORS,\n fetchStatus: snapshot?.fetchStatus ?? \"idle\",\n };\n}\n\n/** A list a hook reads only when asked: `true` for the defaults, or the page size, the first page and the filters. */\nexport type ListParams<Filters = object> = true | (PaginationParams & Filters);\n\nexport interface UseOrganizationParams {\n /** The active organization's members (needs `org:sys_memberships:read`), filtered by a role key. */\n memberships?: ListParams<{ role?: string }>;\n /** Its invitations, filtered by status; read only for a member with `org:sys_memberships:manage` (else empty). */\n invitations?: ListParams<{ status?: OrganizationInvitationStatus[] }>;\n}\n\nexport interface UseOrganizationResult {\n isLoaded: boolean;\n /** The session's active organization with the member's actions; null without one, while signed out or pending. */\n organization: OrganizationResource | null;\n /** The user's membership of it: role and every permission of the role, system ones included (to show buttons). */\n membership: OrganizationMembershipResource | null;\n /** Only when asked for in the params. */\n memberships?: PaginatedResult<OrganizationMembership>;\n invitations?: PaginatedResult<OrganizationInvitationResource>;\n}\n\nexport interface UseOrganizationListParams {\n /** The user's memberships, newest first. */\n userMemberships?: ListParams;\n /** The invitations to the user's verified addresses; by default the pending ones. */\n userInvitations?: ListParams<{ status?: OrganizationInvitationStatus[] }>;\n}\n\nexport interface UseOrganizationListResult {\n isLoaded: boolean;\n /** Creates an organization with the user in it; it is not made active (`setActive` does that). */\n createOrganization: (params: { name: string; slug?: string }) => Promise<OrganizationResource>;\n /** Makes an organization (id or slug) the session's active one; null is the personal account. */\n setActive: (params: { organization: string | null }) => Promise<void>;\n userMemberships?: PaginatedResult<OrganizationMembershipResource>;\n userInvitations?: PaginatedResult<UserOrganizationInvitationResource>;\n}\n\n/** A list's filters: its params without the page size and the first page. */\nfunction filtersOf<F extends object>(params: ListParams<F>): F {\n const filters = { ...(params === true ? {} : params) } as PaginationParams & F;\n delete filters.pageSize;\n delete filters.initialPage;\n return filters;\n}\n\n/** A list of `owner` read with `load`: its key (`owner` and the params, so new filters start the list again). */\nconst list = <T>(owner: string, params: ListParams<object>, load: PageLoader<T>): PageSource<T> => ({\n key: `${owner}:${JSON.stringify(params)}`,\n load,\n});\n\n/** The signed-in user (an active session's) and whether hooks that read it are loaded. */\nfunction useSignedInUser(): { isLoaded: boolean; state: ZauthaState; user: UserResource | null } {\n const zautha = useZautha();\n const state = useZauthaState();\n const user = activeSession(state) === null ? null : (zautha?.user ?? null);\n // An active session is loaded once its user is.\n return { isLoaded: isLoadedStatus(state.status) && (activeSession(state) === null || user !== null), state, user };\n}\n\n/**\n * The session's active organization and the user's membership of it, from the session token and the user (no request of\n * its own), and on request its members and invitations, page by page. The lists start again on their first page when\n * the active organization changes.\n */\nexport function useOrganization(params: UseOrganizationParams = {}): UseOrganizationResult {\n const { isLoaded, state, user } = useSignedInUser();\n const id = state.organization?.id;\n const membership = user?.organizationMemberships.find((m) => m.organization.id === id) ?? null;\n const organization = membership?.organization ?? null;\n // The user's own membership: its user is the signed-in one.\n const owner = membership === null ? \"\" : `${membership.publicUserData.userId}:${membership.organization.id}`;\n const { memberships, invitations } = params;\n const manages = membership?.permissions.includes(\"org:sys_memberships:manage\") === true;\n const members = usePages(\n organization === null || memberships === undefined\n ? null\n : list(owner, memberships, (page) => organization.getMemberships({ ...filtersOf(memberships), ...page })),\n memberships,\n );\n const invited = usePages(\n organization === null || invitations === undefined || !manages\n ? null\n : list(owner, invitations, (page) => organization.getInvitations({ ...filtersOf(invitations), ...page })),\n invitations,\n );\n return {\n isLoaded,\n organization,\n membership,\n ...(memberships === undefined ? {} : { memberships: members }),\n ...(invitations === undefined ? {} : { invitations: invited }),\n };\n}\n\n/**\n * Creating an organization and choosing the active one, and on request the user's memberships and the invitations to\n * the user, page by page.\n */\nexport function useOrganizationList(params: UseOrganizationListParams = {}): UseOrganizationListResult {\n const zautha = useZautha();\n const { isLoaded, user } = useSignedInUser();\n const { userMemberships, userInvitations } = params;\n const memberships = usePages(\n user === null || userMemberships === undefined\n ? null\n : list(user.id, userMemberships, (page) => user.getOrganizationMemberships(page)),\n userMemberships,\n );\n const invitations = usePages(\n user === null || userInvitations === undefined\n ? null\n : list(user.id, userInvitations, (page) =>\n user.getOrganizationInvitations({ ...filtersOf(userInvitations), ...page }),\n ),\n userInvitations,\n );\n const createOrganization = useCallback(\n (p: { name: string; slug?: string }) => zautha?.createOrganization(p) ?? notLoaded(),\n [zautha],\n );\n const setActive = useCallback((p: { organization: string | null }) => zautha?.setActive(p) ?? notLoaded(), [zautha]);\n return {\n isLoaded,\n createOrganization,\n setActive,\n ...(userMemberships === undefined ? {} : { userMemberships: memberships }),\n ...(userInvitations === undefined ? {} : { userInvitations: invitations }),\n };\n}\n\nconst notLoaded = (): Promise<never> => Promise.reject(new ZauthaError(\"Zautha is not loaded yet.\"));\n","import { useEffect, type ReactNode } from \"react\";\nimport { useAuth, type Has, type HasParams } from \"./hooks\";\nimport { useZautha, useZauthaState } from \"./provider\";\n\nexport type ShowWhen = \"signed-in\" | \"signed-out\" | HasParams | ((has: Has) => boolean);\n\n/**\n * Renders `children` when the condition holds, else `fallback`. Renders nothing until Zautha has\n * loaded, so a signed-in user never sees a signed-out flash.\n */\nexport function Show(props: { when: ShowWhen; fallback?: ReactNode; children?: ReactNode }): ReactNode {\n const { isLoaded, isSignedIn, has } = useAuth();\n if (!isLoaded) return null;\n const { when } = props;\n const pass =\n when === \"signed-in\"\n ? isSignedIn\n : when === \"signed-out\"\n ? !isSignedIn\n : typeof when === \"function\"\n ? when(has)\n : has(when);\n return pass ? props.children : (props.fallback ?? null);\n}\n\nexport function ZauthaLoading(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"loading\" ? props.children : null;\n}\n\n/** Loaded, including degraded (network trouble after load: last known state is shown). */\nexport function ZauthaLoaded(props: { children?: ReactNode }): ReactNode {\n const { status } = useZauthaState();\n return status === \"ready\" || status === \"degraded\" ? props.children : null;\n}\n\nexport function ZauthaDegraded(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"degraded\" ? props.children : null;\n}\n\nexport function ZauthaFailed(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"failed\" ? props.children : null;\n}\n\n/** Sends a signed-out visitor to sign-in once loaded; renders nothing. */\nexport function RedirectToSignIn(props: { redirectUrl?: string }): ReactNode {\n const zautha = useZautha();\n const { isLoaded, isSignedIn } = useAuth();\n const { redirectUrl } = props;\n useEffect(() => {\n if (zautha !== null && isLoaded && !isSignedIn)\n zautha.redirectToSignIn(redirectUrl === undefined ? {} : { redirectUrl });\n }, [zautha, isLoaded, isSignedIn, redirectUrl]);\n return null;\n}\n\nexport function RedirectToSignUp(props: { redirectUrl?: string }): ReactNode {\n const zautha = useZautha();\n const { isLoaded, isSignedIn } = useAuth();\n const { redirectUrl } = props;\n useEffect(() => {\n if (zautha !== null && isLoaded && !isSignedIn)\n zautha.redirectToSignUp(redirectUrl === undefined ? {} : { redirectUrl });\n }, [zautha, isLoaded, isSignedIn, redirectUrl]);\n return null;\n}\n","import { Children, cloneElement, isValidElement, type MouseEvent, type ReactElement, type ReactNode } from \"react\";\nimport { useZautha } from \"./provider\";\n\ninterface ButtonProps {\n /** `redirect` (default) goes to the sign-in page; `modal` opens the prebuilt component (needs `ui`). */\n mode?: \"redirect\" | \"modal\";\n redirectUrl?: string;\n children?: ReactNode;\n}\n\n/** Wraps its single child (or renders a plain button) and wires the click. Unstyled by design. */\nfunction Trigger(props: { children: ReactNode; label: string; onClick: () => void }): ReactNode {\n const child = Children.count(props.children) === 1 ? Children.only(props.children) : null;\n if (isValidElement<{ onClick?: (event: MouseEvent) => void }>(child)) {\n const original = child.props.onClick;\n return cloneElement(child as ReactElement<{ onClick?: (event: MouseEvent) => void }>, {\n onClick: (event: MouseEvent) => {\n original?.(event);\n if (!event.defaultPrevented) props.onClick();\n },\n });\n }\n return (\n <button type=\"button\" onClick={props.onClick}>\n {props.children ?? props.label}\n </button>\n );\n}\n\nexport function SignInButton(props: ButtonProps): ReactNode {\n const zautha = useZautha();\n const options = props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl };\n return (\n <Trigger\n label=\"Sign in\"\n onClick={() => (props.mode === \"modal\" ? zautha?.openSignIn(options) : zautha?.redirectToSignIn(options))}\n >\n {props.children}\n </Trigger>\n );\n}\n\nexport function SignUpButton(props: ButtonProps): ReactNode {\n const zautha = useZautha();\n const options = props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl };\n return (\n <Trigger\n label=\"Sign up\"\n onClick={() => (props.mode === \"modal\" ? zautha?.openSignUp(options) : zautha?.redirectToSignUp(options))}\n >\n {props.children}\n </Trigger>\n );\n}\n\nexport function SignOutButton(props: { redirectUrl?: string; children?: ReactNode }): ReactNode {\n const zautha = useZautha();\n return (\n <Trigger\n label=\"Sign out\"\n onClick={() => void zautha?.signOut(props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl })}\n >\n {props.children}\n </Trigger>\n );\n}\n","import type { UiComponentName } from \"@zautha/js\";\nimport { useEffect, useRef, type ReactNode } from \"react\";\nimport { useZautha } from \"./provider\";\n\n/**\n * Mounts a @zautha/ui component into a div once the instance exists; later prop changes update it in\n * place. SSR renders only the empty div.\n */\nfunction Mounted(props: { name: UiComponentName; componentProps: object }): ReactNode {\n const zautha = useZautha();\n const ref = useRef<HTMLDivElement>(null);\n const mountedWith = useRef<object | null>(null);\n const { name, componentProps } = props;\n\n useEffect(() => {\n const element = ref.current;\n if (zautha === null || element === null) return;\n zautha.mount(name, element, componentProps);\n mountedWith.current = componentProps;\n return () => {\n mountedWith.current = null;\n zautha.unmount(element);\n };\n // componentProps changes are applied by the effect below without remounting.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [zautha, name]);\n\n useEffect(() => {\n const element = ref.current;\n if (zautha === null || element === null || mountedWith.current === null || mountedWith.current === componentProps)\n return;\n mountedWith.current = componentProps;\n zautha.updateMounted(element, componentProps);\n }, [zautha, componentProps]);\n\n return <div ref={ref} />;\n}\n\n// Prop types live in @zautha/ui; they are structural here so @zautha/react has no runtime dependency on it.\nexport function SignIn(props: import(\"@zautha/ui\").SignInProps): ReactNode {\n return <Mounted name=\"SignIn\" componentProps={props} />;\n}\n\nexport function SignUp(props: import(\"@zautha/ui\").SignUpProps): ReactNode {\n return <Mounted name=\"SignUp\" componentProps={props} />;\n}\n\n/** The page a provider sends the user back to: finishes the social sign-in or sign-up (see @zautha/ui). */\nexport function AuthenticateWithRedirectCallback(\n props: import(\"@zautha/ui\").AuthenticateWithRedirectCallbackProps,\n): ReactNode {\n return <Mounted name=\"AuthenticateWithRedirectCallback\" componentProps={props} />;\n}\n\nexport function UserButton(props: import(\"@zautha/ui\").UserButtonProps): ReactNode {\n return <Mounted name=\"UserButton\" componentProps={props} />;\n}\n\nexport function UserProfile(props: import(\"@zautha/ui\").UserProfileProps): ReactNode {\n return <Mounted name=\"UserProfile\" componentProps={props} />;\n}\n\nexport function OAuthConsent(props: import(\"@zautha/ui\").OAuthConsentProps): ReactNode {\n return <Mounted name=\"OAuthConsent\" componentProps={props} />;\n}\n\nexport function CreateOrganization(props: import(\"@zautha/ui\").CreateOrganizationProps): ReactNode {\n return <Mounted name=\"CreateOrganization\" componentProps={props} />;\n}\n\nexport function OrganizationProfile(props: import(\"@zautha/ui\").OrganizationProfileProps): ReactNode {\n return <Mounted name=\"OrganizationProfile\" componentProps={props} />;\n}\n\nexport function OrganizationSwitcher(props: import(\"@zautha/ui\").OrganizationSwitcherProps): ReactNode {\n return <Mounted name=\"OrganizationSwitcher\" componentProps={props} />;\n}\n"],"mappings":";;;;;AASA,MAAM,gBAAgB,cAA8C,KAAA,CAAS;;;;;;AAY7E,SAAgB,eAAe,EAAE,gBAAgB,UAAU,GAAG,WAA2C;CACvG,MAAM,CAAC,QAAQ,aAAa,SAAwB,IAAI;CACxD,MAAM,EAAE,IAAI,YAAY,cAAc,WAAW,WAAW,UAAU,iBAAiB;CACvF,MAAM,CAAC,WAAW,gBAA6B;EAAE,GAAG;EAAU,cAAc,gBAAgB;CAAK,EAAE;CAEnG,gBAAgB;EACd,MAAM,WAAW,IAAI,OAAO,gBAAgB;GAC1C,GAAI,OAAO,KAAA,IAAY,CAAC,IAAI,EAAE,GAAG;GACjC,GAAI,eAAe,KAAA,IAAY,CAAC,IAAI,EAAE,WAAW;GACjD,GAAI,iBAAiB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa;GACrD,GAAI,cAAc,KAAA,IAAY,CAAC,IAAI,EAAE,UAAU;GAC/C,GAAI,cAAc,KAAA,IAAY,CAAC,IAAI,EAAE,UAAU;GAC/C,GAAI,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS;GAC7C,GAAI,iBAAiB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa;EACvD,CAAC;EAGD,UAAU,QAAQ;EAClB,SAAc,KAAK;EACnB,aAAa;GACX,SAAS,QAAQ;GACjB,UAAU,IAAI;EAChB;CAGF,GAAG,CAA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YAAY,OAAyD;CACnF,OAAO,oBAAC,SAAD;EAAS,MAAK;EAAc,gBAAgB;CAAQ,CAAA;AAC7D;AAEA,SAAgB,aAAa,OAA0D;CACrF,OAAO,oBAAC,SAAD;EAAS,MAAK;EAAe,gBAAgB;CAAQ,CAAA;AAC9D;AAEA,SAAgB,mBAAmB,OAAgE;CACjG,OAAO,oBAAC,SAAD;EAAS,MAAK;EAAqB,gBAAgB;CAAQ,CAAA;AACpE;AAEA,SAAgB,oBAAoB,OAAiE;CACnG,OAAO,oBAAC,SAAD;EAAS,MAAK;EAAsB,gBAAgB;CAAQ,CAAA;AACrE;AAEA,SAAgB,qBAAqB,OAAkE;CACrG,OAAO,oBAAC,SAAD;EAAS,MAAK;EAAuB,gBAAgB;CAAQ,CAAA;AACtE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zautha/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "React bindings for Zautha: provider, hooks, <Show>, buttons and prebuilt components.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"LICENSE"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@zautha/js": "^0.
|
|
34
|
+
"@zautha/js": "^0.11.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"react": "^19.0.0",
|
|
38
38
|
"react-dom": "^19.0.0",
|
|
39
|
-
"@zautha/ui": "^0.
|
|
39
|
+
"@zautha/ui": "^0.11.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@size-limit/preset-small-lib": "14.0.1",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@testing-library/user-event": "14.6.7",
|
|
45
45
|
"@types/react": "19.3.0",
|
|
46
46
|
"@types/react-dom": "19.3.0",
|
|
47
|
-
"@zautha/ui": "0.
|
|
47
|
+
"@zautha/ui": "0.11.0",
|
|
48
48
|
"happy-dom": "20.14.5",
|
|
49
49
|
"msw": "2.15.0",
|
|
50
50
|
"react": "19.3.0",
|