@shivaedev/react 0.40.0 → 0.41.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +5 -3
- package/dist/client/actionCompletion.d.ts.map +1 -1
- package/dist/client/actionCompletion.js +2 -2
- package/dist/client/actionCompletion.js.map +1 -1
- package/dist/client/adapters/SessionSignOut.d.ts +9 -0
- package/dist/client/adapters/SessionSignOut.d.ts.map +1 -0
- package/dist/client/adapters/SessionSignOut.js +18 -0
- package/dist/client/adapters/SessionSignOut.js.map +1 -0
- package/dist/client/adapters/useSessionRetry.d.ts +3 -0
- package/dist/client/adapters/useSessionRetry.d.ts.map +1 -0
- package/dist/client/adapters/useSessionRetry.js +48 -0
- package/dist/client/adapters/useSessionRetry.js.map +1 -0
- package/dist/client/adapters/useSignOut.d.ts +3 -2
- package/dist/client/adapters/useSignOut.d.ts.map +1 -1
- package/dist/client/adapters/useSignOut.js +6 -1
- package/dist/client/adapters/useSignOut.js.map +1 -1
- package/dist/client/mountLive.js +1 -1
- package/dist/client/mountLive.js.map +1 -1
- package/dist/client/resultState.d.ts.map +1 -1
- package/dist/client/resultState.js +2 -2
- package/dist/client/resultState.js.map +1 -1
- package/dist/client/saveState.d.ts.map +1 -1
- package/dist/client/saveState.js +2 -2
- package/dist/client/saveState.js.map +1 -1
- package/dist/client/sessionBoundary.d.ts +6 -3
- package/dist/client/sessionBoundary.d.ts.map +1 -1
- package/dist/client/sessionBoundary.js +16 -4
- package/dist/client/sessionBoundary.js.map +1 -1
- package/dist/internal/adapters/useLatestCallback.d.ts +1 -1
- package/dist/internal/adapters/useLatestCallback.d.ts.map +1 -1
- package/dist/internal/adapters/useLatestCallback.js.map +1 -1
- package/dist/internal/sessionRecheck.d.ts +1 -2
- package/dist/internal/sessionRecheck.d.ts.map +1 -1
- package/dist/internal/sessionRecheck.js +2 -6
- package/dist/internal/sessionRecheck.js.map +1 -1
- package/package.json +22 -22
- package/src/client/actionCompletion.ts +2 -2
- package/src/client/adapters/SessionSignOut.ts +27 -0
- package/src/client/adapters/useSessionRetry.ts +54 -0
- package/src/client/adapters/useSignOut.ts +6 -1
- package/src/client/mountLive.ts +1 -1
- package/src/client/resultState.ts +2 -2
- package/src/client/saveState.ts +2 -2
- package/src/client/sessionBoundary.ts +33 -17
- package/src/internal/adapters/useLatestCallback.ts +1 -1
- package/src/internal/sessionRecheck.ts +2 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.41.1 - 2026-11-04
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Require Effect 4.0.7 and its matching companion packages. Install the 4.0.7 Effect stack together.
|
|
8
|
+
|
|
9
|
+
## 0.41.0 - 2026-11-04
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- Add `useUndoableChange` for versioned commands: capture an inverse payload, guard Undo with the returned version, keep the latest removal notice across reordered replies, preserve typed results and hold deployment updates while writes are pending.
|
|
14
|
+
- `SessionBoundary` accepts a session-check Effect, retries failed checks with exponential backoff, and retries immediately on online or foreground events. Its optional `signOut` atom holds the signed-in tree until the auth owner reports signed out.
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- Socket transport failures no longer request a session check; typed authentication refusals still do.
|
|
19
|
+
|
|
3
20
|
## 0.40.0 - 2026-11-04
|
|
4
21
|
|
|
5
22
|
### Added
|
package/README.md
CHANGED
|
@@ -84,7 +84,7 @@ export function App({ session, recheck }: { readonly session: Session | undefine
|
|
|
84
84
|
|
|
85
85
|
Pass the signed-out router as `signedOut` and the requested continuation address as `redirectTo` (for example, the sign-in route's `returnTo` search value). On successful sign-in, the auth owner supplies the new `session`; the boundary unmounts the signed-out tree before replacing the URL, then mounts the signed-in tree at that address. The sign-in screen requests a session recheck after success; it leaves navigation to the boundary. Off-site, non-HTTP and malformed targets fall back to `/`. A same-origin destination keeps its path, query and fragment. The default replacement uses browser history. Supply `navigate={(href) => history.replace(href)}` for a router history such as TanStack's memory history; the callback receives only the checked local path. Navigation happens once when entering a generation, so a same-user session rotation does not navigate again.
|
|
86
86
|
|
|
87
|
-
A query that fails with an `Unauthorized` from `@shivaedev/errors/taxonomy.ts` asks `recheck` to run and keeps its retained data. An action does the same once per failed result, retaining its last successful `data` and the typed failure in `cause`; rerendering that result does not repeat the recheck. A live
|
|
87
|
+
A query that fails with an `Unauthorized` from `@shivaedev/errors/taxonomy.ts` asks `recheck` to run and keeps its retained data. An action does the same once per failed result, retaining its last successful `data` and the typed failure in `cause`; rerendering that result does not repeat the recheck. A live reconnect requests a check only for a typed `Unauthorized` authentication refusal; dropped sockets and unreachable servers leave the session alone. Pass the auth owner’s session-refresh Effect as `recheck` (for example, `recheck={auth.session.refresh}`). The boundary shares an in-flight check, retries failures after 1, 2, 4 seconds and so on up to 30 seconds, and retries immediately on visible `online` or `visibilitychange` events while a check is pending, restarting an in-flight check too. Session replacement and unmount cancel retries. Existing void callbacks remain supported; they keep their own check and retry policy. Keep retained session data on screen when a refresh exposes a failure, and pass `session={undefined}` only after a definite signed-out answer. The auth owner decides whether the session ends. The boundary also handles React StrictMode's effect replay and preserves component state across hiding and revealing an `<Activity>` subtree, supplying a live registry when revealed.
|
|
88
88
|
|
|
89
89
|
#### Session-scoped bindings
|
|
90
90
|
|
|
@@ -941,7 +941,9 @@ The example uses `Option` from `effect` and the application's Better Auth client
|
|
|
941
941
|
|
|
942
942
|
For other Better Auth reads, `authQuery` from `@shivaedev/react/client/authQuery.ts` creates an input-keyed query atom family. Pass an input-to-Effect function, such as the result of `authQuery` from `@shivaedev/identity/client/adapters/authQuery.ts`, then render its atom with `useQuery`. Releasing a pending read interrupts its Effect and aborts the supplied signal.
|
|
943
943
|
|
|
944
|
-
|
|
944
|
+
Pass the auth owner’s sign-out atom to `SessionBoundary` as `signOut={signOut}`. The boundary mounts it in the auth owner’s registry and unmounts the signed-in tree while sign-out is pending, including the following session refetch. A successful action keeps the tree held until the session clears; a failed action releases the hold. Supply an atom for the sign-out request itself, and give `recheck` the auth owner’s session refresh. After the request succeeds, the boundary starts that check and retries failures while holding the tree. A failed session check never releases a successful sign-out’s hold.
|
|
945
|
+
|
|
946
|
+
For an explicit sign-out in a TanStack route, use `useSignOut(signOut, { signIn: "/sign-in" })` from `@shivaedev/react/client/adapters/useSignOut.ts` in place of `useAction`. It exposes the same state and a `dispatch()` handler. The hook records sign-out intent before the request and navigates to sign-in after success. A refused request clears that intent, including when the boundary remounts its route. Repeated clicks while pending share one request and follow-up. Unmounting the component or disposing its registry stops the follow-up navigation. If a session refresh replaces the component before the response, the replacement session’s route policy owns navigation to sign-in. `permissionGuard` and `signInSearch(location)` omit `returnTo` for that intent, including when the auth owner's session refresh reruns guards first. Use `signInSearch` for module sign-in links too; ordinary visits retain the full requested location. Applications do not need history markers or Better Auth completion timing hooks.
|
|
945
947
|
|
|
946
948
|
### 3. Every day
|
|
947
949
|
|
|
@@ -1188,7 +1190,7 @@ const screen = screenDriver({ act, pending, root: view.container, tell: story.te
|
|
|
1188
1190
|
|
|
1189
1191
|
`useQuery(atom, options?)` adds `refresh(): void`; `useAction` adds `dispatch(input): void`. `QueryOptions.coalesceWindow` accepts a native Duration for live changed hints on contract-bound queries; it belongs to the query atom in its registry, so readers sharing that atom share the window. Omitting it uses the session default. `QueryOptions.notice` publishes a notice descriptor for a failed result. `QueryOptions.keepPreviousData` defaults to `false` and controls retention across query atom changes. Same-identity refresh retention is always enabled. `result` and `cause` describe the current native query even when `data` displays a previous atom's success. Success, input and typed failure types are inferred from the supplied atom. The Effect overload is `useAction(runtime, run, options?)`, where `ActionOptions` supplies `concurrent`, `notices`, `onSuccess(value, input)` and `onFailure(error, input)`; its shared state also includes the native runtime's typed failure.
|
|
1190
1192
|
|
|
1191
|
-
Import the defining `.ts` module, such as `@shivaedev/react/client/editor.ts`. There is no root import. `useSessionRecheck()` from `client/sessionBoundary.ts`
|
|
1193
|
+
Import the defining `.ts` module, such as `@shivaedev/react/client/editor.ts`. There is no root import. `useSessionRecheck()` from `client/sessionBoundary.ts` requests the boundary’s shared session check.
|
|
1192
1194
|
|
|
1193
1195
|
Prefer `useEditor` and `useCreate` when binding a form to a command. The lower-level modules expose the same composition pieces: `submission` from `submission.ts` makes a form and its submission snapshot reader, `rejecting` from `@shivaedev/form/fieldRejection.ts` maps save failures through a submitter, and `useSaveState` from `client/saveState.ts` observes submission and invokes a success callback. Field-rejection mapping types and `fieldRejectionOf` also belong to `@shivaedev/form/fieldRejection.ts`; `AtomServices` belongs to `AtomServices.ts`.
|
|
1194
1196
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actionCompletion.d.ts","sourceRoot":"","sources":["../../src/client/actionCompletion.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"actionCompletion.d.ts","sourceRoot":"","sources":["../../src/client/actionCompletion.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAGpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,MAAM,WAAW,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,KAAK;IACrD,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvD,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACvD;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,aAAa,EAC7D,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,aAAa,CAAC,EAC5E,GAAG,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,EAC1E,OAAO,EAAE,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GACrC,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,CA2DjD"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { RegistryContext } from "@effect/atom-react";
|
|
2
2
|
import { Effect } from "effect";
|
|
3
3
|
import { useContext, useInsertionEffect, useMemo, useRef } from "react";
|
|
4
|
+
import { isUnauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
4
5
|
import { NoticeContext } from "#internal/NoticeContext.ts";
|
|
5
6
|
import { publishNotice } from "#internal/noticeStore.ts";
|
|
6
|
-
import { requestsRecheck } from "#internal/sessionRecheck.ts";
|
|
7
7
|
import { useSessionRecheck } from "./sessionBoundary.js";
|
|
8
8
|
export function useActionSource(source, run, options) {
|
|
9
9
|
const registry = useContext(RegistryContext);
|
|
@@ -18,7 +18,7 @@ export function useActionSource(source, run, options) {
|
|
|
18
18
|
const lifetime = { active: false, registry };
|
|
19
19
|
function rejected(error, input) {
|
|
20
20
|
return Effect.gen(function* () {
|
|
21
|
-
if (lifetime.active &&
|
|
21
|
+
if (lifetime.active && isUnauthorized(error)) {
|
|
22
22
|
yield* Effect.sync(() => latestRef.current.recheck());
|
|
23
23
|
}
|
|
24
24
|
yield* Effect.sync(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actionCompletion.js","sourceRoot":"","sources":["../../src/client/actionCompletion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"actionCompletion.js","sourceRoot":"","sources":["../../src/client/actionCompletion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AASzD,MAAM,UAAU,eAAe,CAC9B,MAA4E,EAC5E,GAA0E,EAC1E,OAAuC;IAEvC,MAAM,QAAQ,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IAC7C,MAAM,OAAO,GAAG,iBAAiB,EAAE,CAAC;IACpC,MAAM,OAAO,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;IAC1C,MAAM,SAAS,GAAG,MAAM,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CA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AAO,CAAC,CAAC,CAAC;IACjD,kBAAkB,CAAC,GAAG,EAAE;QACvB,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC;QAC7B,OAAO,GAAG,EAAE;YACX,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAG,KAAK,CAAC;QAC/B,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IACZ,OAAO,KAAK,CAAC,IAAI,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
2
|
+
import type * as Atom from "effect/reactivity/Atom";
|
|
3
|
+
import { type ReactNode } from "react";
|
|
4
|
+
export declare function SessionSignOut({ action, children, recheck, }: {
|
|
5
|
+
readonly action: Atom.Atom<AsyncResult.AsyncResult<unknown, unknown>>;
|
|
6
|
+
readonly children?: ReactNode;
|
|
7
|
+
readonly recheck: () => void;
|
|
8
|
+
}): ReactNode;
|
|
9
|
+
//# sourceMappingURL=SessionSignOut.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SessionSignOut.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/SessionSignOut.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAC7D,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAE5D,wBAAgB,cAAc,CAAC,EAC9B,MAAM,EACN,QAAQ,EACR,OAAO,GACP,EAAE;IACF,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IACtE,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;CAC7B,GAAG,SAAS,CAaZ"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useAtomValue } from "@effect/atom-react";
|
|
2
|
+
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
export function SessionSignOut({ action, children, recheck, }) {
|
|
5
|
+
const result = useAtomValue(action);
|
|
6
|
+
const [held, hold] = useState(false);
|
|
7
|
+
const blocked = result.waiting || (held && !AsyncResult.isFailure(result));
|
|
8
|
+
if (held !== blocked) {
|
|
9
|
+
hold(blocked);
|
|
10
|
+
}
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (held && AsyncResult.isSuccess(result) && !result.waiting) {
|
|
13
|
+
recheck();
|
|
14
|
+
}
|
|
15
|
+
}, [held, result, recheck]);
|
|
16
|
+
return blocked ? null : children;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=SessionSignOut.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SessionSignOut.js","sourceRoot":"","sources":["../../../src/client/adapters/SessionSignOut.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAE7D,OAAO,EAAkB,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5D,MAAM,UAAU,cAAc,CAAC,EAC9B,MAAM,EACN,QAAQ,EACR,OAAO,GAKP;IACA,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACpC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IACrC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3E,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QACtB,IAAI,CAAC,OAAO,CAAC,CAAC;IACf,CAAC;IACD,SAAS,CAAC,GAAG,EAAE;QACd,IAAI,IAAI,IAAI,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAC9D,OAAO,EAAE,CAAC;QACX,CAAC;IACF,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5B,OAAO,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSessionRetry.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/useSessionRetry.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAGvE,wBAAgB,eAAe,CAAC,OAAO,EAAE,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,IAAI,CA8CpI"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { RegistryContext } from "@effect/atom-react";
|
|
2
|
+
import { Effect, Fiber, Schedule } from "effect";
|
|
3
|
+
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
4
|
+
import { useContext, useEffect, useMemo } from "react";
|
|
5
|
+
import { useLatestCallback } from "#internal/adapters/useLatestCallback.ts";
|
|
6
|
+
export function useSessionRetry(recheck, identity) {
|
|
7
|
+
const registry = useContext(RegistryContext);
|
|
8
|
+
const latest = useLatestCallback(() => (Effect.isEffect(recheck) ? recheck : Effect.sync(recheck)));
|
|
9
|
+
const retry = useMemo(() => {
|
|
10
|
+
let running;
|
|
11
|
+
function stop() {
|
|
12
|
+
if (running) {
|
|
13
|
+
Effect.runFork(Fiber.interrupt(running));
|
|
14
|
+
running = undefined;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function start() {
|
|
18
|
+
if (running || identity === undefined) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const fiber = Effect.runFork(Effect.suspend(latest).pipe(Effect.retry(Schedule.min([Schedule.exponential("1 second"), Schedule.spaced("30 seconds")])), Effect.provideService(AtomRegistry.AtomRegistry, registry)));
|
|
22
|
+
running = fiber;
|
|
23
|
+
fiber.addObserver(() => {
|
|
24
|
+
if (running === fiber) {
|
|
25
|
+
running = undefined;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function resume() {
|
|
30
|
+
if (running && window.document.visibilityState === "visible") {
|
|
31
|
+
stop();
|
|
32
|
+
start();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return { resume, start, stop };
|
|
36
|
+
}, [latest, registry, identity]);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
window.addEventListener("online", retry.resume);
|
|
39
|
+
window.addEventListener("visibilitychange", retry.resume);
|
|
40
|
+
return () => {
|
|
41
|
+
window.removeEventListener("online", retry.resume);
|
|
42
|
+
window.removeEventListener("visibilitychange", retry.resume);
|
|
43
|
+
retry.stop();
|
|
44
|
+
};
|
|
45
|
+
}, [retry]);
|
|
46
|
+
return retry.start;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=useSessionRetry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSessionRetry.js","sourceRoot":"","sources":["../../../src/client/adapters/useSessionRetry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvD,OAAO,EAAE,iBAAi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MAAM;YACd,IAAI,OAAO,IAAI,MAAM,CAAC,QAAQ,CAAC,eAAe,KAAK,SAAS,EAAE,CAAC;gBAC9D,IAAI,EAAE,CAAC;gBACP,KAAK,EAAE,CAAC;YACT,CAAC;QACF,CAAC;QACD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAChC,CAAC,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;IACjC,SAAS,CAAC,GAAG,EAAE;QACd,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QAChD,MAAM,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QAC1D,OAAO,GAAG,EAAE;YACX,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;YACnD,MAAM,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;YAC7D,KAAK,CAAC,IAAI,EAAE,CAAC;QACd,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IACZ,OAAO,KAAK,CAAC,KAAK,CAAC;AACpB,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Option } from "effect";
|
|
1
2
|
import * as Atom from "effect/reactivity/Atom";
|
|
2
3
|
declare module "@tanstack/react-router" {
|
|
3
4
|
interface HistoryState {
|
|
@@ -7,8 +8,8 @@ declare module "@tanstack/react-router" {
|
|
|
7
8
|
export declare function useSignOut<A, E>(action: Atom.AtomResultFn<void, A, E>, options: {
|
|
8
9
|
readonly signIn: string;
|
|
9
10
|
}): {
|
|
10
|
-
cause:
|
|
11
|
-
data:
|
|
11
|
+
cause: Option.Option<import("effect/Cause").Cause<E>>;
|
|
12
|
+
data: Option.Option<A>;
|
|
12
13
|
pending: boolean;
|
|
13
14
|
refreshing: boolean;
|
|
14
15
|
result: import("effect/reactivity/AsyncResult").AsyncResult<A, E>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSignOut.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/useSignOut.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useSignOut.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/useSignOut.ts"],"names":[],"mappings":"AAEA,OAAO,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAM/C,OAAO,QAAQ,wBAAwB,CAAC;IACvC,UAAU,YAAY;QACrB,QAAQ,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;KACrC;CACD;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE;;;;;;;EAmD3G"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RegistryContext, useAtomMount } from "@effect/atom-react";
|
|
2
2
|
import { useRouter } from "@tanstack/react-router";
|
|
3
|
-
import { Effect } from "effect";
|
|
3
|
+
import { Effect, Option } from "effect";
|
|
4
4
|
import * as Atom from "effect/reactivity/Atom";
|
|
5
5
|
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
6
6
|
import { useContext, useEffect, useMemo } from "react";
|
|
@@ -30,6 +30,11 @@ export function useSignOut(action, options) {
|
|
|
30
30
|
useAtomMount(followUp);
|
|
31
31
|
useEffect(() => () => local.set(followUp, Atom.Interrupt), [local, followUp]);
|
|
32
32
|
const state = useAction(source);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (router && Option.isSome(state.cause) && !state.pending && router.history.location.state.__platformSignOut) {
|
|
35
|
+
router.history.replace(router.history.location.href, { ...router.history.location.state, __platformSignOut: false });
|
|
36
|
+
}
|
|
37
|
+
}, [router, state.cause, state.pending]);
|
|
33
38
|
return {
|
|
34
39
|
...state,
|
|
35
40
|
dispatch: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSignOut.js","sourceRoot":"","sources":["../../../src/client/adapters/useSignOut.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"useSignOut.js","sourceRoot":"","sources":["../../../src/client/adapters/useSignOut.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAQ7E,MAAM,UAAU,UAAU,CAAO,MAAqC,EAAE,OAAoC;IAC3G,MAAM,MAAM,GAAG,SAAS,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC1C,MAAM,KAAK,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IAC1C,MAAM,QAAQ,GAAG,UAAU,CAAC,sBAAsB,CAAC,IAAI,KAAK,CAAC;IAC7D,MAAM,MAAM,GAAG,OAAO,CACrB,GAAG,E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AC,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC;YACrH,CAAC;YACD,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;YAC1B,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QAChC,CAAC;KACD,CAAC;AACH,CAAC"}
|
package/dist/client/mountLive.js
CHANGED
|
@@ -8,7 +8,7 @@ import { recheckUnauthorized } from "#internal/sessionRecheck.ts";
|
|
|
8
8
|
function recheckFailure(registry, failure) {
|
|
9
9
|
const error = Option.flatMap(failure, Cause.findErrorOption);
|
|
10
10
|
if (Option.isSome(error)) {
|
|
11
|
-
void recheckUnauthorized(registry, error.value
|
|
11
|
+
void recheckUnauthorized(registry, error.value);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
export const mountLive = Effect.fn("Live.mountLive")(function* (client, coalesceWindow) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mountLive.js","sourceRoot":"","sources":["../../src/client/mountLive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAiB,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE,SAAS,cAAc,CAAC,QAAmC,EAAE,OAA4C;IACxG,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC;IAC7D,IAAI,MAAM,CAAC,MA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,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,aAAa,EACvD,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,aAAa,CAAC,EAC3C,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,EAC5D,OAAO,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GACjE,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC"}
|
|
@@ -2,12 +2,12 @@ import { RegistryContext, useAtomRefresh, useAtomSet, useAtomValue } from "@effe
|
|
|
2
2
|
import { Cause, Option, Predicate } from "effect";
|
|
3
3
|
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
4
4
|
import { useContext, useEffect, useState } from "react";
|
|
5
|
+
import { isUnauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
5
6
|
import { acceptLoaderQuery } from "#adapters/queryHandoff.ts";
|
|
6
7
|
import { useActionResult } from "#client/adapters/useActionResult.ts";
|
|
7
8
|
import { useLiveWindow } from "#client/adapters/useLiveWindow.ts";
|
|
8
9
|
import { usePermissionFailure } from "#internal/adapters/usePermissionFailure.ts";
|
|
9
10
|
import { useQueryNotice } from "#internal/adapters/useQueryNotice.ts";
|
|
10
|
-
import { requestsRecheck } from "#internal/sessionRecheck.ts";
|
|
11
11
|
import { useActionSource } from "./actionCompletion.js";
|
|
12
12
|
import { useSessionRecheck } from "./sessionBoundary.js";
|
|
13
13
|
function state(result, data = AsyncResult.value(result)) {
|
|
@@ -22,7 +22,7 @@ function state(result, data = AsyncResult.value(result)) {
|
|
|
22
22
|
function useRecheckOnUnauthorized(result, enabled = true) {
|
|
23
23
|
const recheck = useSessionRecheck();
|
|
24
24
|
useEffect(() => {
|
|
25
|
-
if (enabled && AsyncResult.isFailure(result) && Option.exists(Cause.findErrorOption(result.cause),
|
|
25
|
+
if (enabled && AsyncResult.isFailure(result) && Option.exists(Cause.findErrorOption(result.cause), isUnauthorized)) {
|
|
26
26
|
recheck();
|
|
27
27
|
}
|
|
28
28
|
}, [enabled, recheck, result]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resultState.js","sourceRoot":"","sources":["../../src/client/resultState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAE,KAAK,EAA8B,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC9E,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAG7D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"resultState.js","sourceRoot":"","sources":["../../src/client/resultState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAE,KAAK,EAA8B,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC9E,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAG7D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAClF,OAAO,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oot":"","sources":["../../src/client/saveState.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"saveState.d.ts","sourceRoot":"","sources":["../../src/client/saveState.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKvC,OAAO,EAAE,YAAY,EAAE,KAAK,MAAM,EAAE,KAAK,IAAI,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAKzF,MAAM,WAAW,SAAS,CAAC,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,YAAY,GAAG,OAAO,CAAC,CAAC,CAAC;IACvE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CACzB;AACD,wBAAgB,YAAY,CAAC,OAAO,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,aAAa,EACvE,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,GAAG,YAAY,EAAE,aAAa,CAAC,GAAG,SAAS,EACnE,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,GAC3B,SAAS,CAAC,CAAC,GAAG,aAAa,CAAC,CAgC9B"}
|
package/dist/client/saveState.js
CHANGED
|
@@ -3,8 +3,8 @@ import { Cause, Option } from "effect";
|
|
|
3
3
|
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
4
4
|
import * as Atom from "effect/reactivity/Atom";
|
|
5
5
|
import { useCallback, useContext, useEffect } from "react";
|
|
6
|
+
import { isUnauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
6
7
|
import { FieldFailure, Invalid } from "@shivaedev/form/shape.ts";
|
|
7
|
-
import { requestsRecheck } from "#internal/sessionRecheck.ts";
|
|
8
8
|
import { useSessionRecheck } from "./sessionBoundary.js";
|
|
9
9
|
const idle = Atom.make(AsyncResult.initial());
|
|
10
10
|
const clean = Atom.make(false);
|
|
@@ -14,7 +14,7 @@ export function useSaveState(form, settled) {
|
|
|
14
14
|
const result = useAtomValue(form?.submit ?? idle);
|
|
15
15
|
const dirty = useAtomValue(form?.dirty ?? clean);
|
|
16
16
|
useEffect(() => {
|
|
17
|
-
if (AsyncResult.isFailure(result) && Option.exists(Cause.findErrorOption(result.cause),
|
|
17
|
+
if (AsyncResult.isFailure(result) && Option.exists(Cause.findErrorOption(result.cause), isUnauthorized)) {
|
|
18
18
|
recheck();
|
|
19
19
|
}
|
|
20
20
|
}, [recheck, result]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"saveState.js","sourceRoot":"","sources":["../../src/client/saveState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAC7D,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"saveState.js","sourceRoot":"","sources":["../../src/client/saveState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACvC,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AI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;gBAClD,OAAO,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACvB,CAAC;QACF,CAAC,CAAC,EACH,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CACzB,CAAC;IACF,MAAM,IAAI,GAAG,WAAW,CAAC,GAAG,EAAE;QAC7B,IAAI,IAAI,KAAK,SAAS,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;YAC7D,OAAO;QACR,CAAC;QACD,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACtC,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;IACrB,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IACzD,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAC5B,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,EACzB,CAAC,KAAK,EAA8B,EAAE,CAAC,CAAC,CAAC,KAAK,YAAY,YAAY,IAAI,KAAK,YAAY,OAAO,CAAC,CACnG,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;AACnG,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { Duration } from "effect";
|
|
1
|
+
import type { Duration, Effect } from "effect";
|
|
2
|
+
import type * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
3
|
+
import type * as Atom from "effect/reactivity/Atom";
|
|
2
4
|
import type * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
3
5
|
import { type ReactNode } from "react";
|
|
4
6
|
export interface SessionBoundaryProps<TSession, TClient> {
|
|
@@ -7,11 +9,12 @@ export interface SessionBoundaryProps<TSession, TClient> {
|
|
|
7
9
|
readonly identify: (session: TSession) => string;
|
|
8
10
|
readonly liveCoalesceWindow?: Duration.Input | undefined;
|
|
9
11
|
readonly navigate?: ((href: string) => void) | undefined;
|
|
10
|
-
readonly recheck: () => void
|
|
12
|
+
readonly recheck: (() => void) | Effect.Effect<unknown, unknown, AtomRegistry.AtomRegistry>;
|
|
11
13
|
readonly redirectTo?: string | undefined;
|
|
12
14
|
readonly session: TSession | undefined;
|
|
13
15
|
readonly signedOut?: ReactNode;
|
|
16
|
+
readonly signOut?: Atom.Atom<AsyncResult.AsyncResult<unknown, unknown>> | undefined;
|
|
14
17
|
}
|
|
15
18
|
export declare function useSessionRecheck(): () => void;
|
|
16
|
-
export declare function SessionBoundary<TSession, TClient>({ session, liveCoalesceWindow, identify, connect, recheck, signedOut, redirectTo, navigate, children, }: SessionBoundaryProps<TSession, TClient>): ReactNode;
|
|
19
|
+
export declare function SessionBoundary<TSession, TClient>({ session, liveCoalesceWindow, identify, connect, recheck, signedOut, signOut, redirectTo, navigate, children, }: SessionBoundaryProps<TSession, TClient>): ReactNode;
|
|
17
20
|
//# sourceMappingURL=sessionBoundary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessionBoundary.d.ts","sourceRoot":"","sources":["../../src/client/sessionBoundary.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"sessionBoundary.d.ts","sourceRoot":"","sources":["../../src/client/sessionBoundary.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,KAAK,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,KAAK,IAAI,MAAM,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S,EACT,OAAO,EACP,UAAU,EACV,QAAQ,EACR,QAAQ,GACR,EAAE,oBAAoB,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,SAAS,CA6BrD"}
|
|
@@ -3,18 +3,30 @@ import { createElement, Fragment, useContext } from "react";
|
|
|
3
3
|
import { DraftSessionContext } from "@shivaedev/form/adapters/react.ts";
|
|
4
4
|
import { SessionGeneration } from "#client/adapters/SessionGeneration.ts";
|
|
5
5
|
import { SessionHandoff } from "#client/adapters/SessionHandoff.ts";
|
|
6
|
+
import { SessionSignOut } from "#client/adapters/SessionSignOut.ts";
|
|
7
|
+
import { useSessionRetry } from "#client/adapters/useSessionRetry.ts";
|
|
6
8
|
import { RecheckContext } from "#internal/RecheckContext.ts";
|
|
7
9
|
import { SignOutRegistryContext } from "#internal/SignOutRegistryContext.ts";
|
|
8
10
|
import { useDraftOwner } from "./useDraftOwner.js";
|
|
9
11
|
export function useSessionRecheck() {
|
|
10
12
|
return useContext(RecheckContext);
|
|
11
13
|
}
|
|
12
|
-
export function SessionBoundary({ session, liveCoalesceWindow, identify, connect, recheck, signedOut, redirectTo, navigate, children, }) {
|
|
14
|
+
export function SessionBoundary({ session, liveCoalesceWindow, identify, connect, recheck, signedOut, signOut, redirectTo, navigate, children, }) {
|
|
13
15
|
const registry = useContext(RegistryContext);
|
|
14
16
|
const id = session === undefined ? undefined : identify(session);
|
|
15
17
|
const current = useDraftOwner(id);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
const retry = useSessionRetry(recheck, id);
|
|
19
|
+
if (session === undefined) {
|
|
20
|
+
return createElement(Fragment, null, signedOut);
|
|
21
|
+
}
|
|
22
|
+
const generation = createElement(SessionGeneration, {
|
|
23
|
+
children,
|
|
24
|
+
connect,
|
|
25
|
+
identity: id,
|
|
26
|
+
liveCoalesceWindow,
|
|
27
|
+
recheck: retry,
|
|
28
|
+
session,
|
|
29
|
+
});
|
|
30
|
+
return createElement(SignOutRegistryContext.Provider, { value: registry }, createElement(DraftSessionContext.Provider, { value: current }, createElement(SessionHandoff, { key: id, navigate, redirectTo }, signOut === undefined ? generation : createElement(SessionSignOut, { action: signOut, recheck: retry }, generation))));
|
|
19
31
|
}
|
|
20
32
|
//# sourceMappingURL=sessionBoundary.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessionBoundary.js","sourceRoot":"","sources":["../../src/client/sessionBoundary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"sessionBoundary.js","sourceRoot":"","sources":["../../src/client/sessionBoundary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAKrD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAkB,UAAU,EAAE,MAAM,OAAO,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAanD,MAAM,UAAU,iBAAiB;IAChC,OAAO,UAAU,CAAC,cAAc,CAAC,CAAC;AACnC,CAAC;AACD,MAAM,UAAU,eAAe,CAAoB,EAClD,OAAO,EACP,kBAAkB,EAClB,QAAQ,EACR,OAAO,EACP,OAAO,EACP,SAAS,EACT,OAAO,EACP,UAAU,EACV,QAAQ,EACR,QAAQ,GACiC;IACzC,MAAM,QAAQ,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IAC7C,MAAM,EAAE,GAAG,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACjE,MAAM,OAAO,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC;IAClC,MAAM,KAAK,GAAG,eAAe,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC3C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,aAAa,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;IACjD,CAAC;IACD,MAAM,UAAU,GAAG,aAAa,CAAC,iBAAoC,EAAE;QACtE,QAAQ;QACR,OAAO;QACP,QAAQ,EAAE,EAAE;QACZ,kBAAkB;QAClB,OAAO,EAAE,KAAK;QACd,OAAO;KACP,CAAC,CAAC;IACH,OAAO,aAAa,CACnB,sBAAsB,CAAC,QAAQ,EAC/B,EAAE,KAAK,EAAE,QAAQ,EAAE,EACnB,aAAa,CACZ,mBAAmB,CAAC,QAAQ,EAC5B,EAAE,KAAK,EAAE,OAAO,EAAE,EAClB,aAAa,CACZ,cAAc,EACd,EAAE,GAAG,EAAE,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,EACjC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,cAAc,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,UAAU,CAAC,CACnH,CACD,CACD,CAAC;AACH,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function useLatestCallback(callback: () =>
|
|
1
|
+
export declare function useLatestCallback<A>(callback: () => A): () => A;
|
|
2
2
|
//# sourceMappingURL=useLatestCallback.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLatestCallback.d.ts","sourceRoot":"","sources":["../../../src/internal/adapters/useLatestCallback.ts"],"names":[],"mappings":"AAEA,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"useLatestCallback.d.ts","sourceRoot":"","sources":["../../../src/internal/adapters/useLatestCallback.ts"],"names":[],"mappings":"AAEA,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,CAM/D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLatestCallback.js","sourceRoot":"","sources":["../../../src/internal/adapters/useLatestCallback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE7D,MAAM,UAAU,iBAAiB,
|
|
1
|
+
{"version":3,"file":"useLatestCallback.js","sourceRoot":"","sources":["../../../src/internal/adapters/useLatestCallback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE7D,MAAM,UAAU,iBAAiB,CAAI,QAAiB;IACrD,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IACnC,eAAe,CAAC,GAAG,EAAE;QACpB,SAAS,CAAC,OAAO,GAAG,QAAQ,CAAC;IAC9B,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IACf,OAAO,WAAW,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
2
2
|
export declare function registerSessionRecheck(registry: AtomRegistry.AtomRegistry, recheck: () => void): () => void;
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function recheckUnauthorized(registry: AtomRegistry.AtomRegistry, error: unknown, connection?: boolean): Promise<void>;
|
|
3
|
+
export declare function recheckUnauthorized(registry: AtomRegistry.AtomRegistry, error: unknown): Promise<void>;
|
|
5
4
|
//# sourceMappingURL=sessionRecheck.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessionRecheck.d.ts","sourceRoot":"","sources":["../../src/internal/sessionRecheck.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,YAAY,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"sessionRecheck.d.ts","sourceRoot":"","sources":["../../src/internal/sessionRecheck.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAKpE,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,YAAY,CAAC,YAAY,EAAE,OAAO,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAK3G;AAED,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,YAAY,CAAC,YAAY,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAI5G"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { RpcClientError } from "effect/rpc/RpcClientError";
|
|
2
1
|
import { isUnauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
3
2
|
const rechecks = new WeakMap();
|
|
4
3
|
export function registerSessionRecheck(registry, recheck) {
|
|
@@ -7,11 +6,8 @@ export function registerSessionRecheck(registry, recheck) {
|
|
|
7
6
|
rechecks.delete(registry);
|
|
8
7
|
};
|
|
9
8
|
}
|
|
10
|
-
export function
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
export async function recheckUnauthorized(registry, error, connection = false) {
|
|
14
|
-
if (requestsRecheck(error, connection)) {
|
|
9
|
+
export async function recheckUnauthorized(registry, error) {
|
|
10
|
+
if (isUnauthorized(error)) {
|
|
15
11
|
await rechecks.get(registry)?.();
|
|
16
12
|
}
|
|
17
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessionRecheck.js","sourceRoot":"","sources":["../../src/internal/sessionRecheck.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM
|
|
1
|
+
{"version":3,"file":"sessionRecheck.js","sourceRoot":"","sources":["../../src/internal/sessionRecheck.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAyC,CAAC;AAEtE,MAAM,UAAU,sBAAsB,CAAC,QAAmC,EAAE,OAAmB;IAC9F,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAChC,OAAO,GAAG,EAAE;QACX,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC3B,CAAC,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,QAAmC,EAAE,KAAc;IAC5F,IAAI,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,MAAM,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;IAClC,CAAC;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.1",
|
|
4
4
|
"description": "React query, action, editor and session hooks for native Effect atoms",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -45,31 +45,31 @@
|
|
|
45
45
|
"README.md"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@shivaedev/access": "0.5.
|
|
49
|
-
"@shivaedev/contract": "0.36.
|
|
50
|
-
"@shivaedev/errors": "0.9.
|
|
51
|
-
"@shivaedev/form": "0.
|
|
52
|
-
"@shivaedev/identity": "0.
|
|
48
|
+
"@shivaedev/access": "0.5.1",
|
|
49
|
+
"@shivaedev/contract": "0.36.1",
|
|
50
|
+
"@shivaedev/errors": "0.9.1",
|
|
51
|
+
"@shivaedev/form": "0.17.1",
|
|
52
|
+
"@shivaedev/identity": "0.26.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@effect/atom-react": "4.0.
|
|
56
|
-
"@effect/platform-node": "4.0.
|
|
57
|
-
"@effect/sql-pg": "4.0.
|
|
58
|
-
"@effect/sql-sqlite-node": "4.0.
|
|
59
|
-
"@shivaedev/changes": "0.10.
|
|
60
|
-
"@shivaedev/jobs": "0.
|
|
61
|
-
"@shivaedev/quality": "0.
|
|
62
|
-
"@shivaedev/server": "0.24.
|
|
63
|
-
"@shivaedev/service": "0.7.
|
|
64
|
-
"@shivaedev/sql": "0.
|
|
65
|
-
"@shivaedev/test-kits": "0.
|
|
66
|
-
"@shivaedev/test-sql": "0.
|
|
67
|
-
"@shivaedev/test-story": "0.
|
|
55
|
+
"@effect/atom-react": "4.0.7",
|
|
56
|
+
"@effect/platform-node": "4.0.7",
|
|
57
|
+
"@effect/sql-pg": "4.0.7",
|
|
58
|
+
"@effect/sql-sqlite-node": "4.0.7",
|
|
59
|
+
"@shivaedev/changes": "0.10.1",
|
|
60
|
+
"@shivaedev/jobs": "0.36.0",
|
|
61
|
+
"@shivaedev/quality": "0.61.1",
|
|
62
|
+
"@shivaedev/server": "0.24.2",
|
|
63
|
+
"@shivaedev/service": "0.7.1",
|
|
64
|
+
"@shivaedev/sql": "0.39.0",
|
|
65
|
+
"@shivaedev/test-kits": "0.4.0",
|
|
66
|
+
"@shivaedev/test-sql": "0.21.1",
|
|
67
|
+
"@shivaedev/test-story": "0.39.1",
|
|
68
68
|
"@tanstack/react-router": "1.170.46",
|
|
69
69
|
"@types/node": "24.19.2",
|
|
70
70
|
"@types/react": "19.3.0",
|
|
71
71
|
"@types/react-dom": "19.3.0",
|
|
72
|
-
"effect": "4.0.
|
|
72
|
+
"effect": "4.0.7",
|
|
73
73
|
"happy-dom": "21.0.4",
|
|
74
74
|
"react": "19.3.1",
|
|
75
75
|
"react-dom": "19.3.1",
|
|
@@ -77,9 +77,9 @@
|
|
|
77
77
|
"vitest": "5.0.5"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
|
-
"@effect/atom-react": "4.0.
|
|
80
|
+
"@effect/atom-react": "4.0.7",
|
|
81
81
|
"@tanstack/react-router": "1.170.46",
|
|
82
|
-
"effect": "4.0.
|
|
82
|
+
"effect": "4.0.7",
|
|
83
83
|
"react": "19.3.1"
|
|
84
84
|
},
|
|
85
85
|
"peerDependenciesMeta": {
|
|
@@ -2,10 +2,10 @@ import { RegistryContext } from "@effect/atom-react";
|
|
|
2
2
|
import { Effect } from "effect";
|
|
3
3
|
import type * as Atom from "effect/reactivity/Atom";
|
|
4
4
|
import { useContext, useInsertionEffect, useMemo, useRef } from "react";
|
|
5
|
+
import { isUnauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
5
6
|
import type { AtomServices } from "#AtomServices.ts";
|
|
6
7
|
import { NoticeContext } from "#internal/NoticeContext.ts";
|
|
7
8
|
import { publishNotice } from "#internal/noticeStore.ts";
|
|
8
|
-
import { requestsRecheck } from "#internal/sessionRecheck.ts";
|
|
9
9
|
import type { NoticeFeedback } from "#notices.ts";
|
|
10
10
|
import { useSessionRecheck } from "./sessionBoundary.ts";
|
|
11
11
|
|
|
@@ -33,7 +33,7 @@ export function useActionSource<TInput, A, E, R, TRuntimeError>(
|
|
|
33
33
|
const lifetime = { active: false, registry };
|
|
34
34
|
function rejected(error: E, input: TInput) {
|
|
35
35
|
return Effect.gen(function* () {
|
|
36
|
-
if (lifetime.active &&
|
|
36
|
+
if (lifetime.active && isUnauthorized(error)) {
|
|
37
37
|
yield* Effect.sync(() => latestRef.current.recheck());
|
|
38
38
|
}
|
|
39
39
|
yield* Effect.sync(() => {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useAtomValue } from "@effect/atom-react";
|
|
2
|
+
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
3
|
+
import type * as Atom from "effect/reactivity/Atom";
|
|
4
|
+
import { type ReactNode, useEffect, useState } from "react";
|
|
5
|
+
|
|
6
|
+
export function SessionSignOut({
|
|
7
|
+
action,
|
|
8
|
+
children,
|
|
9
|
+
recheck,
|
|
10
|
+
}: {
|
|
11
|
+
readonly action: Atom.Atom<AsyncResult.AsyncResult<unknown, unknown>>;
|
|
12
|
+
readonly children?: ReactNode;
|
|
13
|
+
readonly recheck: () => void;
|
|
14
|
+
}): ReactNode {
|
|
15
|
+
const result = useAtomValue(action);
|
|
16
|
+
const [held, hold] = useState(false);
|
|
17
|
+
const blocked = result.waiting || (held && !AsyncResult.isFailure(result));
|
|
18
|
+
if (held !== blocked) {
|
|
19
|
+
hold(blocked);
|
|
20
|
+
}
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (held && AsyncResult.isSuccess(result) && !result.waiting) {
|
|
23
|
+
recheck();
|
|
24
|
+
}
|
|
25
|
+
}, [held, result, recheck]);
|
|
26
|
+
return blocked ? null : children;
|
|
27
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { RegistryContext } from "@effect/atom-react";
|
|
2
|
+
import { Effect, Fiber, Schedule } from "effect";
|
|
3
|
+
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
4
|
+
import { useContext, useEffect, useMemo } from "react";
|
|
5
|
+
import type { SessionBoundaryProps } from "#client/sessionBoundary.ts";
|
|
6
|
+
import { useLatestCallback } from "#internal/adapters/useLatestCallback.ts";
|
|
7
|
+
|
|
8
|
+
export function useSessionRetry(recheck: SessionBoundaryProps<unknown, unknown>["recheck"], identity: string | undefined): () => void {
|
|
9
|
+
const registry = useContext(RegistryContext);
|
|
10
|
+
const latest = useLatestCallback(() => (Effect.isEffect(recheck) ? recheck : Effect.sync(recheck)));
|
|
11
|
+
const retry = useMemo(() => {
|
|
12
|
+
let running: Fiber.Fiber<unknown, unknown> | undefined;
|
|
13
|
+
function stop() {
|
|
14
|
+
if (running) {
|
|
15
|
+
Effect.runFork(Fiber.interrupt(running));
|
|
16
|
+
running = undefined;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function start() {
|
|
20
|
+
if (running || identity === undefined) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const fiber = Effect.runFork(
|
|
24
|
+
Effect.suspend(latest).pipe(
|
|
25
|
+
Effect.retry(Schedule.min([Schedule.exponential("1 second"), Schedule.spaced("30 seconds")])),
|
|
26
|
+
Effect.provideService(AtomRegistry.AtomRegistry, registry),
|
|
27
|
+
),
|
|
28
|
+
);
|
|
29
|
+
running = fiber;
|
|
30
|
+
fiber.addObserver(() => {
|
|
31
|
+
if (running === fiber) {
|
|
32
|
+
running = undefined;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function resume() {
|
|
37
|
+
if (running && window.document.visibilityState === "visible") {
|
|
38
|
+
stop();
|
|
39
|
+
start();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return { resume, start, stop };
|
|
43
|
+
}, [latest, registry, identity]);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
window.addEventListener("online", retry.resume);
|
|
46
|
+
window.addEventListener("visibilitychange", retry.resume);
|
|
47
|
+
return () => {
|
|
48
|
+
window.removeEventListener("online", retry.resume);
|
|
49
|
+
window.removeEventListener("visibilitychange", retry.resume);
|
|
50
|
+
retry.stop();
|
|
51
|
+
};
|
|
52
|
+
}, [retry]);
|
|
53
|
+
return retry.start;
|
|
54
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RegistryContext, useAtomMount } from "@effect/atom-react";
|
|
2
2
|
import { useRouter } from "@tanstack/react-router";
|
|
3
|
-
import { Effect } from "effect";
|
|
3
|
+
import { Effect, Option } from "effect";
|
|
4
4
|
import * as Atom from "effect/reactivity/Atom";
|
|
5
5
|
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
6
6
|
import { useContext, useEffect, useMemo } from "react";
|
|
@@ -46,6 +46,11 @@ export function useSignOut<A, E>(action: Atom.AtomResultFn<void, A, E>, options:
|
|
|
46
46
|
useAtomMount(followUp);
|
|
47
47
|
useEffect(() => () => local.set(followUp, Atom.Interrupt), [local, followUp]);
|
|
48
48
|
const state = useAction(source);
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (router && Option.isSome(state.cause) && !state.pending && router.history.location.state.__platformSignOut) {
|
|
51
|
+
router.history.replace(router.history.location.href, { ...router.history.location.state, __platformSignOut: false });
|
|
52
|
+
}
|
|
53
|
+
}, [router, state.cause, state.pending]);
|
|
49
54
|
return {
|
|
50
55
|
...state,
|
|
51
56
|
dispatch: () => {
|
package/src/client/mountLive.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { recheckUnauthorized } from "#internal/sessionRecheck.ts";
|
|
|
9
9
|
function recheckFailure(registry: AtomRegistry.AtomRegistry, failure: Option.Option<Cause.Cause<unknown>>) {
|
|
10
10
|
const error = Option.flatMap(failure, Cause.findErrorOption);
|
|
11
11
|
if (Option.isSome(error)) {
|
|
12
|
-
void recheckUnauthorized(registry, error.value
|
|
12
|
+
void recheckUnauthorized(registry, error.value);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -4,13 +4,13 @@ import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
|
4
4
|
import type * as Atom from "effect/reactivity/Atom";
|
|
5
5
|
import type * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
6
6
|
import { useContext, useEffect, useState } from "react";
|
|
7
|
+
import { isUnauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
7
8
|
import type { AtomServices } from "#AtomServices.ts";
|
|
8
9
|
import { acceptLoaderQuery } from "#adapters/queryHandoff.ts";
|
|
9
10
|
import { useActionResult } from "#client/adapters/useActionResult.ts";
|
|
10
11
|
import { useLiveWindow } from "#client/adapters/useLiveWindow.ts";
|
|
11
12
|
import { usePermissionFailure } from "#internal/adapters/usePermissionFailure.ts";
|
|
12
13
|
import { useQueryNotice } from "#internal/adapters/useQueryNotice.ts";
|
|
13
|
-
import { requestsRecheck } from "#internal/sessionRecheck.ts";
|
|
14
14
|
import type { NoticeDescriptor } from "#notices.ts";
|
|
15
15
|
import { type ActionOptions, useActionSource } from "./actionCompletion.ts";
|
|
16
16
|
import { useSessionRecheck } from "./sessionBoundary.ts";
|
|
@@ -34,7 +34,7 @@ function state<A, E>(result: AsyncResult.AsyncResult<A, E>, data = AsyncResult.v
|
|
|
34
34
|
function useRecheckOnUnauthorized<A, E>(result: AsyncResult.AsyncResult<A, E>, enabled = true): void {
|
|
35
35
|
const recheck = useSessionRecheck();
|
|
36
36
|
useEffect(() => {
|
|
37
|
-
if (enabled && AsyncResult.isFailure(result) && Option.exists(Cause.findErrorOption(result.cause),
|
|
37
|
+
if (enabled && AsyncResult.isFailure(result) && Option.exists(Cause.findErrorOption(result.cause), isUnauthorized)) {
|
|
38
38
|
recheck();
|
|
39
39
|
}
|
|
40
40
|
}, [enabled, recheck, result]);
|
package/src/client/saveState.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { Cause, Option } from "effect";
|
|
|
3
3
|
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
4
4
|
import * as Atom from "effect/reactivity/Atom";
|
|
5
5
|
import { useCallback, useContext, useEffect } from "react";
|
|
6
|
+
import { isUnauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
6
7
|
import { FieldFailure, type Fields, type Form, Invalid } from "@shivaedev/form/shape.ts";
|
|
7
|
-
import { requestsRecheck } from "#internal/sessionRecheck.ts";
|
|
8
8
|
import { useSessionRecheck } from "./sessionBoundary.ts";
|
|
9
9
|
|
|
10
10
|
const idle = Atom.make(AsyncResult.initial());
|
|
@@ -26,7 +26,7 @@ export function useSaveState<TFields extends Fields, A, E, TRuntimeError>(
|
|
|
26
26
|
const result: AsyncResult.AsyncResult<A, E | TRuntimeError | FieldFailure | Invalid> = useAtomValue(form?.submit ?? idle);
|
|
27
27
|
const dirty = useAtomValue(form?.dirty ?? clean);
|
|
28
28
|
useEffect(() => {
|
|
29
|
-
if (AsyncResult.isFailure(result) && Option.exists(Cause.findErrorOption(result.cause),
|
|
29
|
+
if (AsyncResult.isFailure(result) && Option.exists(Cause.findErrorOption(result.cause), isUnauthorized)) {
|
|
30
30
|
recheck();
|
|
31
31
|
}
|
|
32
32
|
}, [recheck, result]);
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { RegistryContext } from "@effect/atom-react";
|
|
2
|
-
import type { Duration } from "effect";
|
|
2
|
+
import type { Duration, Effect } from "effect";
|
|
3
|
+
import type * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
4
|
+
import type * as Atom from "effect/reactivity/Atom";
|
|
3
5
|
import type * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
4
6
|
import { createElement, Fragment, type ReactNode, useContext } from "react";
|
|
5
7
|
import { DraftSessionContext } from "@shivaedev/form/adapters/react.ts";
|
|
6
8
|
import { SessionGeneration } from "#client/adapters/SessionGeneration.ts";
|
|
7
9
|
import { SessionHandoff } from "#client/adapters/SessionHandoff.ts";
|
|
10
|
+
import { SessionSignOut } from "#client/adapters/SessionSignOut.ts";
|
|
11
|
+
import { useSessionRetry } from "#client/adapters/useSessionRetry.ts";
|
|
8
12
|
import { RecheckContext } from "#internal/RecheckContext.ts";
|
|
9
13
|
import { SignOutRegistryContext } from "#internal/SignOutRegistryContext.ts";
|
|
10
14
|
import { useDraftOwner } from "./useDraftOwner.ts";
|
|
@@ -14,10 +18,11 @@ export interface SessionBoundaryProps<TSession, TClient> {
|
|
|
14
18
|
readonly identify: (session: TSession) => string;
|
|
15
19
|
readonly liveCoalesceWindow?: Duration.Input | undefined;
|
|
16
20
|
readonly navigate?: ((href: string) => void) | undefined;
|
|
17
|
-
readonly recheck: () => void
|
|
21
|
+
readonly recheck: (() => void) | Effect.Effect<unknown, unknown, AtomRegistry.AtomRegistry>;
|
|
18
22
|
readonly redirectTo?: string | undefined;
|
|
19
23
|
readonly session: TSession | undefined;
|
|
20
24
|
readonly signedOut?: ReactNode;
|
|
25
|
+
readonly signOut?: Atom.Atom<AsyncResult.AsyncResult<unknown, unknown>> | undefined;
|
|
21
26
|
}
|
|
22
27
|
export function useSessionRecheck(): () => void {
|
|
23
28
|
return useContext(RecheckContext);
|
|
@@ -29,6 +34,7 @@ export function SessionBoundary<TSession, TClient>({
|
|
|
29
34
|
connect,
|
|
30
35
|
recheck,
|
|
31
36
|
signedOut,
|
|
37
|
+
signOut,
|
|
32
38
|
redirectTo,
|
|
33
39
|
navigate,
|
|
34
40
|
children,
|
|
@@ -36,19 +42,29 @@ export function SessionBoundary<TSession, TClient>({
|
|
|
36
42
|
const registry = useContext(RegistryContext);
|
|
37
43
|
const id = session === undefined ? undefined : identify(session);
|
|
38
44
|
const current = useDraftOwner(id);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
45
|
+
const retry = useSessionRetry(recheck, id);
|
|
46
|
+
if (session === undefined) {
|
|
47
|
+
return createElement(Fragment, null, signedOut);
|
|
48
|
+
}
|
|
49
|
+
const generation = createElement(SessionGeneration<TSession, TClient>, {
|
|
50
|
+
children,
|
|
51
|
+
connect,
|
|
52
|
+
identity: id,
|
|
53
|
+
liveCoalesceWindow,
|
|
54
|
+
recheck: retry,
|
|
55
|
+
session,
|
|
56
|
+
});
|
|
57
|
+
return createElement(
|
|
58
|
+
SignOutRegistryContext.Provider,
|
|
59
|
+
{ value: registry },
|
|
60
|
+
createElement(
|
|
61
|
+
DraftSessionContext.Provider,
|
|
62
|
+
{ value: current },
|
|
63
|
+
createElement(
|
|
64
|
+
SessionHandoff,
|
|
65
|
+
{ key: id, navigate, redirectTo },
|
|
66
|
+
signOut === undefined ? generation : createElement(SessionSignOut, { action: signOut, recheck: retry }, generation),
|
|
67
|
+
),
|
|
68
|
+
),
|
|
69
|
+
);
|
|
54
70
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback, useLayoutEffect, useRef } from "react";
|
|
2
2
|
|
|
3
|
-
export function useLatestCallback(callback: () =>
|
|
3
|
+
export function useLatestCallback<A>(callback: () => A): () => A {
|
|
4
4
|
const latestRef = useRef(callback);
|
|
5
5
|
useLayoutEffect(() => {
|
|
6
6
|
latestRef.current = callback;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
2
|
-
import { RpcClientError } from "effect/rpc/RpcClientError";
|
|
3
2
|
import { isUnauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
4
3
|
|
|
5
4
|
const rechecks = new WeakMap<AtomRegistry.AtomRegistry, () => void>();
|
|
@@ -11,12 +10,8 @@ export function registerSessionRecheck(registry: AtomRegistry.AtomRegistry, rech
|
|
|
11
10
|
};
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
export function
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export async function recheckUnauthorized(registry: AtomRegistry.AtomRegistry, error: unknown, connection = false): Promise<void> {
|
|
19
|
-
if (requestsRecheck(error, connection)) {
|
|
13
|
+
export async function recheckUnauthorized(registry: AtomRegistry.AtomRegistry, error: unknown): Promise<void> {
|
|
14
|
+
if (isUnauthorized(error)) {
|
|
20
15
|
await rechecks.get(registry)?.();
|
|
21
16
|
}
|
|
22
17
|
}
|