forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {type AtpSessionData, type AtpSessionEvent} from '@atproto/api'
2
3import {type Schema} from '../persisted'
4import {type Action, type State} from './reducer'
5import {type SessionAccount} from './types'
6
7type Reducer = (state: State, action: Action) => State
8
9type Log =
10 | {
11 type: 'reducer:init'
12 state: State
13 }
14 | {
15 type: 'reducer:call'
16 action: Action
17 prevState: State
18 nextState: State
19 }
20 | {
21 type: 'method:start'
22 method:
23 | 'createAccount'
24 | 'login'
25 | 'logout'
26 | 'resumeSession'
27 | 'removeAccount'
28 account?: SessionAccount
29 }
30 | {
31 type: 'method:end'
32 method:
33 | 'createAccount'
34 | 'login'
35 | 'logout'
36 | 'resumeSession'
37 | 'removeAccount'
38 account?: SessionAccount
39 }
40 | {
41 type: 'persisted:broadcast'
42 data: Schema['session']
43 }
44 | {
45 type: 'persisted:receive'
46 data: Schema['session']
47 }
48 | {
49 type: 'agent:switch'
50 prevAgent: object
51 nextAgent: object
52 }
53 | {
54 type: 'agent:patch'
55 agent: object
56 prevSession: AtpSessionData | undefined
57 nextSession: AtpSessionData | undefined
58 }
59
60export function wrapSessionReducerForLogging(reducer: Reducer): Reducer {
61 return function loggingWrapper(prevState: State, action: Action): State {
62 const nextState = reducer(prevState, action)
63 addSessionDebugLog({type: 'reducer:call', prevState, action, nextState})
64 return nextState
65 }
66}
67
68/**
69 * Stubs, previously used to log session errors to Statsig. We may revive this
70 * using Sentry or Bitdrift in the future.
71 */
72export function addSessionErrorLog(_did: string, _event: AtpSessionEvent) {}
73export function addSessionDebugLog(_log: Log) {}