@indietabletop/appkit 6.1.6 → 7.0.0-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/AppConfig/AppConfig.d.ts +29 -0
- package/dist/AuthCard/AuthCard.d.ts +10 -0
- package/dist/AuthCard/AuthCard.stories.d.ts +34 -0
- package/dist/AuthCard/style.css.d.ts +23 -0
- package/dist/DialogTrigger/index.d.ts +13 -0
- package/dist/DocumentTitle/DocumentTitle.d.ts +3 -0
- package/dist/EnumMapper.d.ts +25 -0
- package/dist/ExternalLink.d.ts +3 -0
- package/dist/FullscreenDismissBlocker.d.ts +5 -0
- package/{lib/HistoryState.ts → dist/HistoryState.d.ts} +2 -5
- package/dist/IndieTabletopClubLogo.d.ts +7 -0
- package/dist/IndieTabletopClubSymbol.d.ts +7 -0
- package/dist/InfoPage/index.d.ts +8 -0
- package/dist/InfoPage/pages.d.ts +2 -0
- package/dist/InfoPage/style.css.d.ts +5 -0
- package/dist/Letterhead/index.d.ts +19 -0
- package/dist/Letterhead/stories.d.ts +13 -0
- package/dist/Letterhead/style.css.d.ts +46 -0
- package/dist/LetterheadForm/LetterheadReadonlyTextField.stories.d.ts +17 -0
- package/dist/LetterheadForm/LetterheadSubmitError.stories.d.ts +11 -0
- package/dist/LetterheadForm/LetterheadTextField.stories.d.ts +336 -0
- package/dist/LetterheadForm/index.d.ts +44 -0
- package/dist/LetterheadForm/style.css.d.ts +8 -0
- package/dist/LoadingIndicator.d.ts +3 -0
- package/dist/MiddotSeparated/MiddotSeparated.d.ts +8 -0
- package/dist/MiddotSeparated/MiddotSeparated.stories.d.ts +586 -0
- package/dist/MiddotSeparated/style.css.d.ts +1 -0
- package/dist/ModalDialog/index.d.ts +12 -0
- package/dist/ModalDialog/style.css.d.ts +58 -0
- package/dist/ModernIDB/Cursor.d.ts +56 -0
- package/dist/ModernIDB/ModernIDB.d.ts +66 -0
- package/dist/ModernIDB/ModernIDBError.d.ts +3 -0
- package/dist/ModernIDB/ObjectStore.d.ts +112 -0
- package/dist/ModernIDB/ObjectStoreIndex.d.ts +53 -0
- package/dist/ModernIDB/Transaction.d.ts +16 -0
- package/dist/ModernIDB/VersionChangeManager.d.ts +30 -0
- package/dist/ModernIDB/bindings/factory.d.ts +12 -0
- package/dist/ModernIDB/bindings/index.d.ts +2 -0
- package/{lib/ModernIDB/bindings/types.ts → dist/ModernIDB/bindings/types.d.ts} +13 -32
- package/dist/ModernIDB/bindings/utils.d.ts +2 -0
- package/dist/ModernIDB/index.d.ts +10 -0
- package/dist/ModernIDB/types.d.ts +88 -0
- package/dist/ModernIDB/utils.d.ts +4 -0
- package/dist/QRCode/QRCode.d.ts +7 -0
- package/dist/QRCode/QRCode.stories.d.ts +33 -0
- package/dist/QRCode/style.css.d.ts +4 -0
- package/dist/ReleaseInfo/index.d.ts +5 -0
- package/dist/RulesetResolver.d.ts +87 -0
- package/dist/SafariCheck/SafariCheck.d.ts +23 -0
- package/dist/SafariCheck/SafariCheck.stories.d.ts +73 -0
- package/dist/SafariCheck/style.css.d.ts +17 -0
- package/dist/ServiceWorkerHandler.d.ts +11 -0
- package/dist/ShareButton/ShareButton.d.ts +57 -0
- package/dist/ShareButton/ShareButton.stories.d.ts +1577 -0
- package/dist/ShareButton/test.css.d.ts +1 -0
- package/dist/SubscribeCard/LetterheadInfoCard.d.ts +2 -0
- package/dist/SubscribeCard/SubscribeByEmailCard.d.ts +24 -0
- package/dist/SubscribeCard/SubscribeByEmailCard.stories.d.ts +10 -0
- package/dist/SubscribeCard/SubscribeByPledgeCard.d.ts +36 -0
- package/dist/SubscribeCard/SubscribeByPledgeCard.stories.d.ts +65 -0
- package/dist/SubscribeCard/style.css.d.ts +4 -0
- package/dist/account/AccountIssueView.d.ts +3 -0
- package/dist/account/AlreadyLoggedInView.d.ts +5 -0
- package/dist/account/CurrentUserFetcher.d.ts +20 -0
- package/dist/account/CurrentUserFetcher.stories.d.ts +136 -0
- package/dist/account/FailureFallbackView.d.ts +1 -0
- package/dist/account/JoinCard.d.ts +14 -0
- package/dist/account/JoinCard.stories.d.ts +143 -0
- package/dist/account/LoadingView.d.ts +1 -0
- package/dist/account/LoginCard.d.ts +39 -0
- package/dist/account/LoginCard.stories.d.ts +217 -0
- package/dist/account/LoginView.d.ts +10 -0
- package/dist/account/NoConnectionView.d.ts +4 -0
- package/dist/account/PasswordResetCard.d.ts +15 -0
- package/dist/account/PasswordResetCard.stories.d.ts +128 -0
- package/dist/account/UserMismatchView.d.ts +6 -0
- package/dist/account/VerifyPage.d.ts +13 -0
- package/dist/account/style.css.d.ts +10 -0
- package/{lib/account/types.ts → dist/account/types.d.ts} +3 -6
- package/dist/account/useFetchCurrentUser.d.ts +28 -0
- package/dist/account/useRedirectPath.d.ts +6 -0
- package/dist/animations.css.d.ts +3 -0
- package/dist/append-copy-to-text.d.ts +10 -0
- package/dist/append-copy-to-text.test.d.ts +1 -0
- package/dist/appkit.css +1 -0
- package/dist/appkit.js +10692 -0
- package/dist/async-op.d.ts +101 -0
- package/dist/atomic.css.d.ts +6 -0
- package/{lib/caught-value.ts → dist/caught-value.d.ts} +1 -11
- package/{lib/class-names.ts → dist/class-names.d.ts} +6 -17
- package/dist/client.d.ts +424 -0
- package/dist/common.css.d.ts +5 -0
- package/dist/copyrightRange.d.ts +1 -0
- package/dist/copyrightRange.test.d.ts +1 -0
- package/dist/createSafeStorage.d.ts +34 -0
- package/dist/failureMessages.d.ts +20 -0
- package/dist/failureMessages.test.d.ts +1 -0
- package/dist/form/FormSubmitButton.d.ts +17 -0
- package/dist/form/SubmitErrorAlert.d.ts +5 -0
- package/dist/form/style.css.d.ts +3 -0
- package/dist/globals.css.d.ts +0 -0
- package/dist/groupBy.d.ts +1 -0
- package/dist/groupBy.test.d.ts +1 -0
- package/dist/hrefs.d.ts +32 -0
- package/dist/hrefs.test.d.ts +1 -0
- package/dist/idToDate.d.ts +5 -0
- package/dist/idToDate.test.d.ts +1 -0
- package/dist/ids.d.ts +1 -0
- package/dist/ids.test.d.ts +1 -0
- package/dist/index.d.ts +64 -0
- package/dist/internal.css.d.ts +2 -0
- package/dist/mailto.d.ts +8 -0
- package/dist/mailto.test.d.ts +1 -0
- package/dist/media.d.ts +39 -0
- package/dist/random.d.ts +3 -0
- package/dist/result/swr.d.ts +4 -0
- package/{lib/sleep.ts → dist/sleep.d.ts} +1 -3
- package/dist/store/index.d.ts +237 -0
- package/dist/store/store.d.ts +144 -0
- package/dist/store/types.d.ts +49 -0
- package/dist/store/utils.d.ts +10 -0
- package/dist/storybook/decorators.d.ts +3 -0
- package/dist/structs.d.ts +1 -0
- package/{lib/typeguards.ts → dist/typeguards.d.ts} +1 -3
- package/dist/typeguards.test.d.ts +1 -0
- package/{lib/types.ts → dist/types.d.ts} +12 -23
- package/dist/unique.d.ts +10 -0
- package/dist/unique.test.d.ts +1 -0
- package/dist/use-async-op.d.ts +6 -0
- package/dist/use-document-background-color.d.ts +4 -0
- package/dist/use-form.d.ts +29 -0
- package/dist/use-is-installed.d.ts +8 -0
- package/dist/use-media-query.d.ts +1 -0
- package/dist/use-reverting-state.d.ts +5 -0
- package/dist/use-scroll-restoration.d.ts +25 -0
- package/dist/useEnsureValue.d.ts +6 -0
- package/dist/useInvokeClient.d.ts +25 -0
- package/dist/useIsVisible.d.ts +4 -0
- package/dist/utm.d.ts +58 -0
- package/dist/utm.test.d.ts +1 -0
- package/dist/validations.d.ts +3 -0
- package/dist/vars.css.d.ts +10 -0
- package/package.json +12 -5
- package/lib/AppConfig/AppConfig.tsx +0 -61
- package/lib/AuthCard/AuthCard.stories.ts +0 -34
- package/lib/AuthCard/AuthCard.tsx +0 -64
- package/lib/AuthCard/style.css.ts +0 -49
- package/lib/DialogTrigger/index.tsx +0 -36
- package/lib/DocumentTitle/DocumentTitle.tsx +0 -10
- package/lib/EnumMapper.ts +0 -50
- package/lib/ExternalLink.tsx +0 -10
- package/lib/FullscreenDismissBlocker.tsx +0 -23
- package/lib/IndieTabletopClubLogo.tsx +0 -44
- package/lib/IndieTabletopClubSymbol.tsx +0 -37
- package/lib/InfoPage/index.tsx +0 -46
- package/lib/InfoPage/pages.tsx +0 -36
- package/lib/InfoPage/style.css.ts +0 -36
- package/lib/Letterhead/index.tsx +0 -85
- package/lib/Letterhead/stories.tsx +0 -41
- package/lib/Letterhead/style.css.ts +0 -152
- package/lib/LetterheadForm/LetterheadReadonlyTextField.stories.tsx +0 -17
- package/lib/LetterheadForm/LetterheadSubmitError.stories.tsx +0 -19
- package/lib/LetterheadForm/LetterheadTextField.stories.tsx +0 -19
- package/lib/LetterheadForm/index.tsx +0 -137
- package/lib/LetterheadForm/style.css.ts +0 -89
- package/lib/LoadingIndicator.tsx +0 -40
- package/lib/MiddotSeparated/MiddotSeparated.stories.ts +0 -26
- package/lib/MiddotSeparated/MiddotSeparated.tsx +0 -26
- package/lib/MiddotSeparated/style.css.ts +0 -10
- package/lib/ModalDialog/index.tsx +0 -28
- package/lib/ModalDialog/style.css.ts +0 -88
- package/lib/ModernIDB/Cursor.ts +0 -91
- package/lib/ModernIDB/ModernIDB.ts +0 -337
- package/lib/ModernIDB/ModernIDBError.ts +0 -9
- package/lib/ModernIDB/ObjectStore.ts +0 -195
- package/lib/ModernIDB/ObjectStoreIndex.ts +0 -102
- package/lib/ModernIDB/README.md +0 -9
- package/lib/ModernIDB/Transaction.ts +0 -40
- package/lib/ModernIDB/VersionChangeManager.ts +0 -57
- package/lib/ModernIDB/bindings/factory.tsx +0 -165
- package/lib/ModernIDB/bindings/index.ts +0 -2
- package/lib/ModernIDB/bindings/utils.tsx +0 -32
- package/lib/ModernIDB/index.ts +0 -10
- package/lib/ModernIDB/types.ts +0 -120
- package/lib/ModernIDB/utils.ts +0 -51
- package/lib/QRCode/QRCode.stories.tsx +0 -41
- package/lib/QRCode/QRCode.tsx +0 -54
- package/lib/QRCode/style.css.ts +0 -23
- package/lib/ReleaseInfo/index.tsx +0 -29
- package/lib/RulesetResolver.ts +0 -214
- package/lib/SafariCheck/SafariCheck.stories.tsx +0 -99
- package/lib/SafariCheck/SafariCheck.tsx +0 -273
- package/lib/SafariCheck/addToDock.svg +0 -13
- package/lib/SafariCheck/addToHomeScreen.svg +0 -12
- package/lib/SafariCheck/safari.svg +0 -32
- package/lib/SafariCheck/shareIcon.svg +0 -11
- package/lib/SafariCheck/style.css.ts +0 -106
- package/lib/ServiceWorkerHandler.tsx +0 -53
- package/lib/ShareButton/ShareButton.stories.tsx +0 -58
- package/lib/ShareButton/ShareButton.tsx +0 -153
- package/lib/ShareButton/test.css.ts +0 -3
- package/lib/SubscribeCard/LetterheadInfoCard.tsx +0 -23
- package/lib/SubscribeCard/SubscribeByEmailCard.stories.tsx +0 -69
- package/lib/SubscribeCard/SubscribeByEmailCard.tsx +0 -183
- package/lib/SubscribeCard/SubscribeByPledgeCard.stories.tsx +0 -133
- package/lib/SubscribeCard/SubscribeByPledgeCard.tsx +0 -127
- package/lib/SubscribeCard/style.css.ts +0 -14
- package/lib/account/AccountIssueView.tsx +0 -44
- package/lib/account/AlreadyLoggedInView.tsx +0 -47
- package/lib/account/CurrentUserFetcher.stories.tsx +0 -292
- package/lib/account/CurrentUserFetcher.tsx +0 -118
- package/lib/account/FailureFallbackView.tsx +0 -36
- package/lib/account/JoinCard.stories.tsx +0 -257
- package/lib/account/JoinCard.tsx +0 -301
- package/lib/account/LoadingView.tsx +0 -14
- package/lib/account/LoginCard.stories.tsx +0 -288
- package/lib/account/LoginCard.tsx +0 -100
- package/lib/account/LoginView.tsx +0 -151
- package/lib/account/NoConnectionView.tsx +0 -34
- package/lib/account/PasswordResetCard.stories.tsx +0 -242
- package/lib/account/PasswordResetCard.tsx +0 -296
- package/lib/account/UserMismatchView.tsx +0 -62
- package/lib/account/VerifyPage.tsx +0 -195
- package/lib/account/style.css.ts +0 -57
- package/lib/account/useFetchCurrentUser.tsx +0 -63
- package/lib/account/useRedirectPath.ts +0 -21
- package/lib/animations.css.ts +0 -17
- package/lib/append-copy-to-text.ts +0 -35
- package/lib/async-op.ts +0 -286
- package/lib/atomic.css.ts +0 -11
- package/lib/client.ts +0 -662
- package/lib/common.css.ts +0 -48
- package/lib/copyrightRange.ts +0 -10
- package/lib/createSafeStorage.ts +0 -91
- package/lib/failureMessages.ts +0 -108
- package/lib/form/FormSubmitButton.tsx +0 -58
- package/lib/form/SubmitErrorAlert.tsx +0 -21
- package/lib/form/style.css.ts +0 -9
- package/lib/globals.css.ts +0 -62
- package/lib/groupBy.ts +0 -25
- package/lib/hrefs.ts +0 -48
- package/lib/idToDate.ts +0 -8
- package/lib/ids.ts +0 -6
- package/lib/index.ts +0 -71
- package/lib/internal.css.ts +0 -10
- package/lib/mailto.ts +0 -40
- package/lib/media.ts +0 -50
- package/lib/random.ts +0 -19
- package/lib/result/swr.ts +0 -18
- package/lib/store/index.tsx +0 -241
- package/lib/store/store.ts +0 -479
- package/lib/store/types.ts +0 -45
- package/lib/store/utils.ts +0 -54
- package/lib/storybook/decorators.tsx +0 -10
- package/lib/structs.ts +0 -3
- package/lib/unique.ts +0 -24
- package/lib/use-async-op.ts +0 -16
- package/lib/use-document-background-color.ts +0 -16
- package/lib/use-form.ts +0 -78
- package/lib/use-is-installed.ts +0 -17
- package/lib/use-media-query.ts +0 -21
- package/lib/use-reverting-state.ts +0 -32
- package/lib/use-scroll-restoration.ts +0 -99
- package/lib/useEnsureValue.ts +0 -31
- package/lib/useInvokeClient.ts +0 -54
- package/lib/useIsVisible.ts +0 -27
- package/lib/utm.ts +0 -92
- package/lib/validations.ts +0 -25
- package/lib/vars.css.ts +0 -13
package/lib/store/index.tsx
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
import type { UserGameData } from "@indietabletop/types";
|
|
2
|
-
import { createActorContext } from "@xstate/react";
|
|
3
|
-
import { createContext, useContext, useMemo, type ReactNode } from "react";
|
|
4
|
-
import { fromCallback, fromPromise } from "xstate";
|
|
5
|
-
import { Failure, Success } from "../async-op.ts";
|
|
6
|
-
import type { GameCode, IndieTabletopClient } from "../client.ts";
|
|
7
|
-
import type { ModernIDB } from "../ModernIDB/ModernIDB.ts";
|
|
8
|
-
import type { ModernIDBIndexes, ModernIDBSchema } from "../ModernIDB/types.ts";
|
|
9
|
-
import type { CurrentUser } from "../types.ts";
|
|
10
|
-
import {
|
|
11
|
-
machine,
|
|
12
|
-
type PullChangesInput,
|
|
13
|
-
type PushChangesInput,
|
|
14
|
-
} from "./store.ts";
|
|
15
|
-
import type { MachineEvent, PullResult, PushResult } from "./types.ts";
|
|
16
|
-
import { toSyncedItems } from "./utils.ts";
|
|
17
|
-
|
|
18
|
-
export type AppActions = {
|
|
19
|
-
clientLogout: (params: { serverUser: CurrentUser }) => Promise<void>;
|
|
20
|
-
serverLogout: () => Promise<void>;
|
|
21
|
-
logout: () => Promise<void>;
|
|
22
|
-
push: () => void;
|
|
23
|
-
pull: () => void;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export const AppActionsContext = createContext<null | AppActions>(null);
|
|
27
|
-
|
|
28
|
-
const {
|
|
29
|
-
Provider: InternalMachineProvider,
|
|
30
|
-
useSelector,
|
|
31
|
-
useActorRef,
|
|
32
|
-
} = createActorContext(machine);
|
|
33
|
-
|
|
34
|
-
export { useActorRef, useSelector };
|
|
35
|
-
|
|
36
|
-
export function useCurrentUser() {
|
|
37
|
-
return useSelector((s) => s.context.currentUser);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function useSessionInfo() {
|
|
41
|
-
return useSelector((s) => s.context.sessionInfo);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function useAppActions() {
|
|
45
|
-
const actions = useContext(AppActionsContext);
|
|
46
|
-
|
|
47
|
-
if (!actions) {
|
|
48
|
-
throw new Error(`Missing context value for app actions.`);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return actions;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export type DatabaseAppMachineMethods = {
|
|
55
|
-
upsertGameData(data: UserGameData): Promise<Success<string[]>>;
|
|
56
|
-
|
|
57
|
-
getUpdatedGameDataSince(props: {
|
|
58
|
-
sinceTs: number | null;
|
|
59
|
-
exclude: Set<string>;
|
|
60
|
-
}): Promise<Success<UserGameData>>;
|
|
61
|
-
|
|
62
|
-
clearAll(): Promise<Success<string> | Failure<string>>;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export function createAppMachineProvider<
|
|
66
|
-
Schema extends ModernIDBSchema,
|
|
67
|
-
Indexes extends ModernIDBIndexes<Schema>,
|
|
68
|
-
>(options: {
|
|
69
|
-
database: ModernIDB<Schema, Indexes> & DatabaseAppMachineMethods;
|
|
70
|
-
client: IndieTabletopClient;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Which games should the machine pull game data for?
|
|
74
|
-
*
|
|
75
|
-
* If null is provided, no data will be pulled.
|
|
76
|
-
*
|
|
77
|
-
* @remarks Honestly this is a bit hacky and we should have a better way to
|
|
78
|
-
* disable sync entirely for apps that don't need it (e.g. the Creators App).
|
|
79
|
-
*/
|
|
80
|
-
pullGameDataFor: GameCode | GameCode[] | null;
|
|
81
|
-
}) {
|
|
82
|
-
const { client, database } = options;
|
|
83
|
-
|
|
84
|
-
// Concrete implementations of actors that our machine requires.
|
|
85
|
-
|
|
86
|
-
const auth = fromCallback<MachineEvent>(({ sendBack }) => {
|
|
87
|
-
const controller = new AbortController();
|
|
88
|
-
|
|
89
|
-
client.addEventListener(
|
|
90
|
-
"currentUser",
|
|
91
|
-
({ detail }) => void sendBack({ type: "currentUser", ...detail }),
|
|
92
|
-
controller,
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
client.addEventListener(
|
|
96
|
-
"sessionInfo",
|
|
97
|
-
({ detail }) => void sendBack({ type: "sessionInfo", ...detail }),
|
|
98
|
-
controller,
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
client.addEventListener(
|
|
102
|
-
"sessionExpired",
|
|
103
|
-
() => void sendBack({ type: "sessionExpired" }),
|
|
104
|
-
controller,
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
return () => {
|
|
108
|
-
controller.abort();
|
|
109
|
-
};
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
const sync = fromCallback<MachineEvent>(({ sendBack }) => {
|
|
113
|
-
const controller = new AbortController();
|
|
114
|
-
|
|
115
|
-
// As long as sync is active, make sure to `pull` after every window focus.
|
|
116
|
-
window.addEventListener(
|
|
117
|
-
"focus",
|
|
118
|
-
() => void sendBack({ type: "pull" }),
|
|
119
|
-
controller,
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
// If there is a `readwrite` transaction in IndexedDB trigger a `push`.
|
|
123
|
-
database.addEventListener(
|
|
124
|
-
"readwrite",
|
|
125
|
-
() => void sendBack({ type: "push" }),
|
|
126
|
-
controller,
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
return () => {
|
|
130
|
-
controller.abort();
|
|
131
|
-
};
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
const pullChanges = fromPromise<PullResult, PullChangesInput>(
|
|
135
|
-
async ({ input }) => {
|
|
136
|
-
if (!options.pullGameDataFor) {
|
|
137
|
-
return new Success({ pulled: [] });
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const result = await client.pullUserData({
|
|
141
|
-
include: options.pullGameDataFor,
|
|
142
|
-
sinceTs: input.sinceTs,
|
|
143
|
-
expectCurrentUserId: input.currentUser.id,
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
const userGameData = result.valueOrThrow();
|
|
147
|
-
await database.upsertGameData(userGameData);
|
|
148
|
-
|
|
149
|
-
return new Success({ pulled: toSyncedItems(userGameData) });
|
|
150
|
-
},
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
const pushChanges = fromPromise<PushResult, PushChangesInput>(
|
|
154
|
-
async ({ input }) => {
|
|
155
|
-
const { value: changedData } = await database.getUpdatedGameDataSince({
|
|
156
|
-
sinceTs: input.sinceTs,
|
|
157
|
-
exclude: new Set(input.ignoredItems.map((i) => i.id)),
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
const changed = toSyncedItems(changedData);
|
|
161
|
-
|
|
162
|
-
if (changed.length === 0) {
|
|
163
|
-
return new Success({ pushed: [], pulled: [] });
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const result = await client.pushUserData({
|
|
167
|
-
data: changedData,
|
|
168
|
-
pullSinceTs: input.currentSyncTs,
|
|
169
|
-
currentSyncTs: input.currentSyncTs,
|
|
170
|
-
expectCurrentUserId: input.currentUser.id,
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
const userGameData = result.valueOrThrow();
|
|
174
|
-
await database.upsertGameData(userGameData);
|
|
175
|
-
|
|
176
|
-
return new Success({
|
|
177
|
-
pushed: changed,
|
|
178
|
-
pulled: toSyncedItems(userGameData),
|
|
179
|
-
});
|
|
180
|
-
},
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
// Bound provider components
|
|
184
|
-
|
|
185
|
-
function AppActionsProvider(props: { children: ReactNode }) {
|
|
186
|
-
const { children } = props;
|
|
187
|
-
const app = useActorRef();
|
|
188
|
-
|
|
189
|
-
const actions: AppActions = useMemo(() => {
|
|
190
|
-
async function clientLogout(params: { serverUser: CurrentUser }) {
|
|
191
|
-
await database.clearAll();
|
|
192
|
-
app.send({ type: "serverUser", ...params });
|
|
193
|
-
|
|
194
|
-
// Get new session info
|
|
195
|
-
await client.refreshTokens();
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
async function serverLogout() {
|
|
199
|
-
await client.logout();
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
async function logout() {
|
|
203
|
-
await client.logout();
|
|
204
|
-
await database.clearAll();
|
|
205
|
-
app.send({ type: "reset" });
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function push() {
|
|
209
|
-
app.send({ type: "push" });
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function pull() {
|
|
213
|
-
app.send({ type: "pull" });
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return {
|
|
217
|
-
pull,
|
|
218
|
-
push,
|
|
219
|
-
logout,
|
|
220
|
-
serverLogout,
|
|
221
|
-
clientLogout,
|
|
222
|
-
};
|
|
223
|
-
}, [app]);
|
|
224
|
-
|
|
225
|
-
return <AppActionsContext value={actions}>{children}</AppActionsContext>;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return function AppMachineProvider(props: { children: ReactNode }) {
|
|
229
|
-
const { children } = props;
|
|
230
|
-
|
|
231
|
-
return (
|
|
232
|
-
<InternalMachineProvider
|
|
233
|
-
logic={machine.provide({
|
|
234
|
-
actors: { auth, sync, pullChanges, pushChanges },
|
|
235
|
-
})}
|
|
236
|
-
>
|
|
237
|
-
<AppActionsProvider>{children}</AppActionsProvider>
|
|
238
|
-
</InternalMachineProvider>
|
|
239
|
-
);
|
|
240
|
-
};
|
|
241
|
-
}
|
package/lib/store/store.ts
DELETED
|
@@ -1,479 +0,0 @@
|
|
|
1
|
-
import { number } from "superstruct";
|
|
2
|
-
import {
|
|
3
|
-
and,
|
|
4
|
-
assertEvent,
|
|
5
|
-
assign,
|
|
6
|
-
fromCallback,
|
|
7
|
-
fromPromise,
|
|
8
|
-
setup,
|
|
9
|
-
} from "xstate";
|
|
10
|
-
import {
|
|
11
|
-
createSafeStorage,
|
|
12
|
-
type SafeStorageKey,
|
|
13
|
-
} from "../createSafeStorage.ts";
|
|
14
|
-
import { currentUser, sessionInfo } from "../structs.ts";
|
|
15
|
-
import type { CurrentUser, SessionInfo } from "../types.ts";
|
|
16
|
-
import type {
|
|
17
|
-
MachineContext,
|
|
18
|
-
MachineEvent,
|
|
19
|
-
PullResult,
|
|
20
|
-
PushResult,
|
|
21
|
-
SyncedItem,
|
|
22
|
-
} from "./types.ts";
|
|
23
|
-
import { assertNonNullish, caughtToResult } from "./utils.ts";
|
|
24
|
-
|
|
25
|
-
const safeStorage = createSafeStorage({
|
|
26
|
-
currentUser: currentUser(),
|
|
27
|
-
sessionInfo: sessionInfo(),
|
|
28
|
-
lastSuccessfulSyncTs: number(),
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
function createInMemoryContext(): Omit<
|
|
32
|
-
MachineContext,
|
|
33
|
-
SafeStorageKey<typeof safeStorage>
|
|
34
|
-
> {
|
|
35
|
-
return {
|
|
36
|
-
currentSync: null,
|
|
37
|
-
pushOnceIdle: false,
|
|
38
|
-
syncLog: [],
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function createInitialContext(): MachineContext {
|
|
43
|
-
return {
|
|
44
|
-
...createInMemoryContext(),
|
|
45
|
-
currentUser: safeStorage.getItem("currentUser"),
|
|
46
|
-
sessionInfo: safeStorage.getItem("sessionInfo"),
|
|
47
|
-
lastSuccessfulSyncTs: safeStorage.getItem("lastSuccessfulSyncTs"),
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const sync = fromCallback<MachineEvent>(() => {
|
|
52
|
-
throw new Error(`Sync actor not provided.`);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const auth = fromCallback<MachineEvent>(() => {
|
|
56
|
-
throw new Error(`Auth actor not provided.`);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
export type PullChangesInput = {
|
|
60
|
-
sinceTs: number | null;
|
|
61
|
-
currentUser: CurrentUser;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const pullChanges = fromPromise<PullResult, PullChangesInput>(() => {
|
|
65
|
-
throw new Error(`Pull changes actor not provided.`);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
export type PushChangesInput = {
|
|
69
|
-
sinceTs: number | null;
|
|
70
|
-
currentSyncTs: number;
|
|
71
|
-
ignoredItems: SyncedItem[];
|
|
72
|
-
currentUser: CurrentUser;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const pushChanges = fromPromise<PushResult, PushChangesInput>(async () => {
|
|
76
|
-
throw new Error(`Push changes actor not provided.`);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const config = setup({
|
|
80
|
-
types: {
|
|
81
|
-
context: {} as MachineContext,
|
|
82
|
-
events: {} as MachineEvent,
|
|
83
|
-
children: {} as {
|
|
84
|
-
sync: "sync";
|
|
85
|
-
auth: "auth";
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
actors: {
|
|
90
|
-
auth,
|
|
91
|
-
sync,
|
|
92
|
-
pullChanges,
|
|
93
|
-
pushChanges,
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
actions: {
|
|
97
|
-
setCurrentSync: assign({
|
|
98
|
-
currentSync: () => ({ startedTs: Date.now(), pull: null, push: null }),
|
|
99
|
-
}),
|
|
100
|
-
|
|
101
|
-
flushCurrentSync: assign(({ context }) => {
|
|
102
|
-
const { currentSync, syncLog } = context;
|
|
103
|
-
|
|
104
|
-
assertNonNullish(
|
|
105
|
-
currentSync,
|
|
106
|
-
"Flushing current sync but context.currentSync is nullish.",
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
currentSync: null,
|
|
111
|
-
syncLog: [currentSync, ...syncLog],
|
|
112
|
-
};
|
|
113
|
-
}),
|
|
114
|
-
|
|
115
|
-
setLastSuccessfulSync: assign(({ context }) => {
|
|
116
|
-
assertNonNullish(
|
|
117
|
-
context.currentSync,
|
|
118
|
-
"Setting last successful sync but context.currentSync is nullish.",
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
const lastSuccessfulSyncTs = context.currentSync.startedTs;
|
|
122
|
-
safeStorage.setItem("lastSuccessfulSyncTs", lastSuccessfulSyncTs);
|
|
123
|
-
return { lastSuccessfulSyncTs };
|
|
124
|
-
}),
|
|
125
|
-
|
|
126
|
-
markSyncStepResult: assign({
|
|
127
|
-
currentSync: (
|
|
128
|
-
{ context },
|
|
129
|
-
params: { pull?: PullResult; push?: PushResult },
|
|
130
|
-
) => {
|
|
131
|
-
assertNonNullish(
|
|
132
|
-
context.currentSync,
|
|
133
|
-
"Marking sync step result but context.currentSync is nullish.",
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
return {
|
|
137
|
-
...context.currentSync,
|
|
138
|
-
...params,
|
|
139
|
-
};
|
|
140
|
-
},
|
|
141
|
-
}),
|
|
142
|
-
|
|
143
|
-
queuePush: assign({ pushOnceIdle: true }),
|
|
144
|
-
|
|
145
|
-
clearPushQueue: assign({ pushOnceIdle: false }),
|
|
146
|
-
|
|
147
|
-
setCurrentUser: assign((_, currentUser: CurrentUser) => {
|
|
148
|
-
safeStorage.setItem("currentUser", currentUser);
|
|
149
|
-
return { currentUser };
|
|
150
|
-
}),
|
|
151
|
-
|
|
152
|
-
patchSessionInfo: assign(({ context }, newSessionInfo: SessionInfo) => {
|
|
153
|
-
const sessionInfo = context.sessionInfo
|
|
154
|
-
? { ...context.sessionInfo, expiresTs: newSessionInfo.expiresTs }
|
|
155
|
-
: newSessionInfo;
|
|
156
|
-
|
|
157
|
-
safeStorage.setItem("sessionInfo", sessionInfo);
|
|
158
|
-
return { sessionInfo };
|
|
159
|
-
}),
|
|
160
|
-
|
|
161
|
-
resetContext: assign((): MachineContext => {
|
|
162
|
-
safeStorage.clear();
|
|
163
|
-
|
|
164
|
-
return {
|
|
165
|
-
...createInMemoryContext(),
|
|
166
|
-
currentUser: null,
|
|
167
|
-
sessionInfo: null,
|
|
168
|
-
lastSuccessfulSyncTs: null,
|
|
169
|
-
};
|
|
170
|
-
}),
|
|
171
|
-
|
|
172
|
-
resetWithServerUser: assign((_, serverUser: CurrentUser) => {
|
|
173
|
-
safeStorage.clear();
|
|
174
|
-
safeStorage.setItem("currentUser", serverUser);
|
|
175
|
-
|
|
176
|
-
return {
|
|
177
|
-
...createInMemoryContext(),
|
|
178
|
-
currentUser: serverUser,
|
|
179
|
-
sessionInfo: null,
|
|
180
|
-
lastSuccessfulSyncTs: null,
|
|
181
|
-
};
|
|
182
|
-
}),
|
|
183
|
-
},
|
|
184
|
-
|
|
185
|
-
guards: {
|
|
186
|
-
shouldPushOnceIdle: ({ context }) => {
|
|
187
|
-
return context.pushOnceIdle;
|
|
188
|
-
},
|
|
189
|
-
|
|
190
|
-
isEligibleForSync: and(["isUserVerified", "isNotMismatched"]),
|
|
191
|
-
|
|
192
|
-
isUserVerified: ({ event }) => {
|
|
193
|
-
assertEvent(event, "currentUser");
|
|
194
|
-
|
|
195
|
-
return event.currentUser.isVerified;
|
|
196
|
-
},
|
|
197
|
-
|
|
198
|
-
isNotMismatched: ({ event, context }) => {
|
|
199
|
-
assertEvent(event, "currentUser");
|
|
200
|
-
|
|
201
|
-
// If there is no current user, there cannot be a mismatch
|
|
202
|
-
if (!context.currentUser) {
|
|
203
|
-
return true;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// Otherwise check that user IDs match.
|
|
207
|
-
return context.currentUser.id === event.currentUser.id;
|
|
208
|
-
},
|
|
209
|
-
|
|
210
|
-
hasBecomeEligibleForSync: and(["isNotMismatched", "hasBecomeVerified"]),
|
|
211
|
-
|
|
212
|
-
hasBecomeVerified: ({ event, context }) => {
|
|
213
|
-
assertEvent(event, "currentUser");
|
|
214
|
-
|
|
215
|
-
if (!context.currentUser) {
|
|
216
|
-
return false;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// User was unverified previously, but now they are verified.
|
|
220
|
-
return (
|
|
221
|
-
context.currentUser.isVerified === false &&
|
|
222
|
-
event.currentUser.isVerified === true
|
|
223
|
-
);
|
|
224
|
-
},
|
|
225
|
-
},
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
export const machine = config.createMachine({
|
|
229
|
-
/** @xstate-layout N4IgpgJg5mDOIC5QEMAOqDEAnOYAuA2gAwC6ioqA9rAJZ42UB25IAHogLQBMRAbAHQBOQbwCMggOy8ALES7DRAGhABPTvIn8AzAA5B0rdN4BWCRKKDRvAL7XlaVPwCujZE7wALMI3oBjZHiQGL5OWDg+AKqwYFjEZEggVLT0TCzsCEZc-FyiXHqiOtJcvLwSymoI3Fqi-LkiIjkSIrIStvbozq7uXj40-oEQwaHheFExBKLxFNR0DMwJ6dJL-GJ1gkTSwubS5Yj6mjrG602F0ietdiAOnW6e3n4BQSFh92OxXFOJMynzoIs6uwQljaVw6LluPQeAww0SwADcYm84iwkrNUgtEHkiICOKI8SDrhD7n1HoNniMkaQUd85mlELkctktLxDkQdDoJFYuGVVPTREZaoZjMKdNzRFILu1HETev0nsNXrCJp9UT86QhRVkiHVjDIiHwSlxAXiBaJDEVqkRzNVpASOjKofKXpElR9qclaRiENjed67dLusS5YNorBaEwAJKMABmlGRCVVnr+9JKAkE3LyPF4zN0Sl9JoEZukwuMos5Ev9-AdJOhofDjAAoqxUDQcBB49MPejkwhDDUtERqjwDBIuMYszitOnsmaOdJcqW5zZLoTA7LSfxYCpGL5N9vfDRGFAMBAmGBN3hHlX7WvHRA9zuHwejx2vl3fmxMcVpPxjOLNgOeISAYgLcsY-DmJIxjVJYg6iBslbVsGT5Poex6oE4sAeK+ibdp+CDwdqQjSHogimPopiGICxaaAU6bchseS6IIiG3jWkAoVuO5ofwGEADZ8WhJ5nvwh5wpQADW56rnc64DJx+48fxglHggYmUP0cxxDhNJ4ekuQbPwhz6AYA6FCUWjGgIHLCLopj8tqJmsbJd4KdxR68U4AlCTEWCUFgvF8QEsZYAAtteAYuex95cbusVKV5KlQGpjDiZpTDaVSCa6R++n8j+YjmKYo7ATovDGgY2SbCY2YkUczmQtFbnPlAnlYUJp6MOe6lSRFVZschsWoR5GHtap6npYwmUqjl6pWBIOhGdq1r6pyYqAgOtR8MY2q6HkYiag1QYbkN8UjZhHg+WE-mBcF-nhTJjWDfuw2taNl3jalGkBFppA6e+c26tZpksiRFjzgCvpcFwP7QUU46CDoQH8sYR1yRxQ00BAfFgBg73-WiuX0usAh-sBghaOYZWFICUg-nR0HajDejAWjrmY9juPKQTapejkxRLbk7KDoawqAtmgi-tDxhLNBZljmzTUczjGA80m+EFGI2haDrZhyKKxZGr6SNaNrOvjkU2aiqIivPY+ADuyCzEeeMXWren0lIWRkwBFhIzyFQslkdE8DLXBTtmkqgpFT0nS9jvO8erCwJegRVtGgRYAAFKIO1EAAlBgj3HfJQ0J-QL5ZZ2hNzUUWTcrwMMSNBZEmYCpaaI3lN8PqPDAbaIKMJQEBwCwDjujXXrcDLQgiOIdNyAoOKrLUBjjloPDHFOlbggNpIT7zPa4sBEH6gObImBy+qQxUHBGDUueitmMhmufqMrjeUXBgf6vpAbTI6CIKYAC9RLK+jvlIFYa9zakUcu-KU-Uv4bkPGAQSUAaAACMcY-w9kCQy4ckZ4gUGRcQgIKbgRRpsM0RYmhR2LujGK+4cFEw1KOABQDyYRwppOZYMgtC6m1DIUUSNlwIKQnHR8Z0oDMPVOmIg7DgEU1ATicUi0+FwxkLBeCdDP6x1Li9KRnlvJHhkV6EQi0CEcJAbwbh+YCrbW1MtWQiMWIfxjiXDGBjFLnTGtI7KAMvT8jyPwIw1ReBskKFYaCFUjI6z4Pwng1DCq2wkXFbxrVYqQFMT2cQeJT4imECRIoAd6Sm34SYfUiMzDh3HDoFJ+jJHpP4NGJ2OMIDZPwokzQ9l5xHHgrnBaoEpy1DMCRGGMMRBmFEdHRBejPGPixtg-xk8ew5AKNoJmHIdDdw5LTRu2hdTimbsAsU9T5m7nLmhDp+kIbaE5Drfko4ii5D2VkcpRzhTAW5FoWwtggA */
|
|
230
|
-
id: "app",
|
|
231
|
-
context: () => createInitialContext(),
|
|
232
|
-
|
|
233
|
-
invoke: {
|
|
234
|
-
id: "auth",
|
|
235
|
-
src: "auth",
|
|
236
|
-
},
|
|
237
|
-
|
|
238
|
-
initial: "unauthenticated",
|
|
239
|
-
|
|
240
|
-
on: {
|
|
241
|
-
reset: [
|
|
242
|
-
{
|
|
243
|
-
actions: "resetContext",
|
|
244
|
-
target: ".unauthenticated",
|
|
245
|
-
},
|
|
246
|
-
],
|
|
247
|
-
},
|
|
248
|
-
|
|
249
|
-
states: {
|
|
250
|
-
unauthenticated: {
|
|
251
|
-
description:
|
|
252
|
-
"The user is either completely anonymous, authenticated via insecure means (localStorage), or in an otherwise no-correctly-authenticated state (e.g. user mismatch).",
|
|
253
|
-
|
|
254
|
-
on: {
|
|
255
|
-
currentUser: [
|
|
256
|
-
{
|
|
257
|
-
guard: "isEligibleForSync",
|
|
258
|
-
target: "authenticated",
|
|
259
|
-
|
|
260
|
-
actions: {
|
|
261
|
-
type: "setCurrentUser",
|
|
262
|
-
params: ({ event }) => event.currentUser,
|
|
263
|
-
},
|
|
264
|
-
},
|
|
265
|
-
{
|
|
266
|
-
guard: "isNotMismatched",
|
|
267
|
-
target: "authenticated.ineligible",
|
|
268
|
-
|
|
269
|
-
actions: {
|
|
270
|
-
type: "setCurrentUser",
|
|
271
|
-
params: ({ event }) => event.currentUser,
|
|
272
|
-
},
|
|
273
|
-
},
|
|
274
|
-
{ target: "unauthenticated" },
|
|
275
|
-
],
|
|
276
|
-
serverUser: {
|
|
277
|
-
target: "authenticated",
|
|
278
|
-
actions: {
|
|
279
|
-
type: "resetWithServerUser",
|
|
280
|
-
params: ({ event }) => event.serverUser,
|
|
281
|
-
},
|
|
282
|
-
},
|
|
283
|
-
},
|
|
284
|
-
},
|
|
285
|
-
|
|
286
|
-
authenticated: {
|
|
287
|
-
description: "The user has a session with ITC.",
|
|
288
|
-
|
|
289
|
-
initial: "sync",
|
|
290
|
-
|
|
291
|
-
on: {
|
|
292
|
-
currentUser: [
|
|
293
|
-
{
|
|
294
|
-
guard: "hasBecomeEligibleForSync",
|
|
295
|
-
target: "authenticated",
|
|
296
|
-
reenter: true,
|
|
297
|
-
|
|
298
|
-
actions: {
|
|
299
|
-
type: "setCurrentUser",
|
|
300
|
-
params: ({ event }) => event.currentUser,
|
|
301
|
-
},
|
|
302
|
-
},
|
|
303
|
-
{
|
|
304
|
-
guard: "isNotMismatched",
|
|
305
|
-
actions: {
|
|
306
|
-
type: "setCurrentUser",
|
|
307
|
-
params: ({ event }) => event.currentUser,
|
|
308
|
-
},
|
|
309
|
-
},
|
|
310
|
-
{
|
|
311
|
-
target: "unauthenticated",
|
|
312
|
-
},
|
|
313
|
-
],
|
|
314
|
-
|
|
315
|
-
sessionInfo: {
|
|
316
|
-
actions: {
|
|
317
|
-
type: "patchSessionInfo",
|
|
318
|
-
params: ({ event }) => event.sessionInfo,
|
|
319
|
-
},
|
|
320
|
-
},
|
|
321
|
-
|
|
322
|
-
sessionExpired: {
|
|
323
|
-
target: "unauthenticated",
|
|
324
|
-
},
|
|
325
|
-
},
|
|
326
|
-
|
|
327
|
-
states: {
|
|
328
|
-
ineligible: {
|
|
329
|
-
description: "The user is not eligible for sync (e.g. unverified)",
|
|
330
|
-
},
|
|
331
|
-
|
|
332
|
-
sync: {
|
|
333
|
-
description: "The user is eligible for the sync feature.",
|
|
334
|
-
invoke: {
|
|
335
|
-
id: "sync",
|
|
336
|
-
src: "sync",
|
|
337
|
-
},
|
|
338
|
-
|
|
339
|
-
initial: "syncing",
|
|
340
|
-
|
|
341
|
-
states: {
|
|
342
|
-
syncing: {
|
|
343
|
-
description: "The sync operation is in progress.",
|
|
344
|
-
initial: "pulling",
|
|
345
|
-
entry: "setCurrentSync",
|
|
346
|
-
exit: "flushCurrentSync",
|
|
347
|
-
|
|
348
|
-
on: {
|
|
349
|
-
push: {
|
|
350
|
-
actions: "queuePush",
|
|
351
|
-
},
|
|
352
|
-
},
|
|
353
|
-
|
|
354
|
-
states: {
|
|
355
|
-
pulling: {
|
|
356
|
-
invoke: {
|
|
357
|
-
src: "pullChanges",
|
|
358
|
-
input: ({ context }) => ({
|
|
359
|
-
sinceTs: context.lastSuccessfulSyncTs,
|
|
360
|
-
currentUser: context.currentUser!,
|
|
361
|
-
}),
|
|
362
|
-
onDone: {
|
|
363
|
-
target: "pushing",
|
|
364
|
-
actions: [
|
|
365
|
-
{
|
|
366
|
-
type: "markSyncStepResult",
|
|
367
|
-
params: ({ event }) => ({
|
|
368
|
-
pull: event.output,
|
|
369
|
-
}),
|
|
370
|
-
},
|
|
371
|
-
],
|
|
372
|
-
},
|
|
373
|
-
onError: {
|
|
374
|
-
target: "failed",
|
|
375
|
-
actions: {
|
|
376
|
-
type: "markSyncStepResult",
|
|
377
|
-
params: ({ event }) => ({
|
|
378
|
-
pull: caughtToResult(event.error),
|
|
379
|
-
}),
|
|
380
|
-
},
|
|
381
|
-
},
|
|
382
|
-
},
|
|
383
|
-
},
|
|
384
|
-
pushing: {
|
|
385
|
-
entry: "clearPushQueue",
|
|
386
|
-
|
|
387
|
-
invoke: {
|
|
388
|
-
src: "pushChanges",
|
|
389
|
-
input: ({ context }) => {
|
|
390
|
-
assertNonNullish(
|
|
391
|
-
context.currentSync,
|
|
392
|
-
"Setting pushChanges input but context.currentSync is unset.",
|
|
393
|
-
);
|
|
394
|
-
|
|
395
|
-
assertNonNullish(
|
|
396
|
-
context.currentUser,
|
|
397
|
-
"Setting pushChanges input but context.currentUser is unset.",
|
|
398
|
-
);
|
|
399
|
-
|
|
400
|
-
// This value might be unset if no push was made during
|
|
401
|
-
// this sync attempt.
|
|
402
|
-
const pulledItems =
|
|
403
|
-
context.currentSync.pull?.valueOrNull()?.pulled ?? [];
|
|
404
|
-
|
|
405
|
-
return {
|
|
406
|
-
ignoredItems: pulledItems,
|
|
407
|
-
currentSyncTs: context.currentSync.startedTs,
|
|
408
|
-
sinceTs: context.lastSuccessfulSyncTs,
|
|
409
|
-
currentUser: context.currentUser,
|
|
410
|
-
};
|
|
411
|
-
},
|
|
412
|
-
onDone: {
|
|
413
|
-
target: "synced",
|
|
414
|
-
actions: {
|
|
415
|
-
type: "markSyncStepResult",
|
|
416
|
-
params: ({ event }) => ({
|
|
417
|
-
push: event.output,
|
|
418
|
-
}),
|
|
419
|
-
},
|
|
420
|
-
},
|
|
421
|
-
onError: {
|
|
422
|
-
target: "failed",
|
|
423
|
-
actions: {
|
|
424
|
-
type: "markSyncStepResult",
|
|
425
|
-
params: ({ event }) => ({
|
|
426
|
-
push: caughtToResult(event.error),
|
|
427
|
-
}),
|
|
428
|
-
},
|
|
429
|
-
},
|
|
430
|
-
},
|
|
431
|
-
},
|
|
432
|
-
synced: {
|
|
433
|
-
type: "final",
|
|
434
|
-
entry: "setLastSuccessfulSync",
|
|
435
|
-
},
|
|
436
|
-
|
|
437
|
-
failed: {
|
|
438
|
-
type: "final",
|
|
439
|
-
},
|
|
440
|
-
},
|
|
441
|
-
|
|
442
|
-
onDone: "idle",
|
|
443
|
-
},
|
|
444
|
-
|
|
445
|
-
idle: {
|
|
446
|
-
description: "The app is listening for sync events.",
|
|
447
|
-
always: {
|
|
448
|
-
guard: "shouldPushOnceIdle",
|
|
449
|
-
target: "waiting",
|
|
450
|
-
},
|
|
451
|
-
on: {
|
|
452
|
-
push: "waiting",
|
|
453
|
-
pull: "syncing",
|
|
454
|
-
},
|
|
455
|
-
},
|
|
456
|
-
|
|
457
|
-
waiting: {
|
|
458
|
-
description:
|
|
459
|
-
"We are waiting for further push events to batch them.",
|
|
460
|
-
|
|
461
|
-
after: {
|
|
462
|
-
1500: {
|
|
463
|
-
target: "syncing.pushing",
|
|
464
|
-
},
|
|
465
|
-
},
|
|
466
|
-
|
|
467
|
-
on: {
|
|
468
|
-
push: {
|
|
469
|
-
target: "waiting",
|
|
470
|
-
reenter: true,
|
|
471
|
-
},
|
|
472
|
-
},
|
|
473
|
-
},
|
|
474
|
-
},
|
|
475
|
-
},
|
|
476
|
-
},
|
|
477
|
-
},
|
|
478
|
-
},
|
|
479
|
-
});
|