@indietabletop/appkit 7.1.0 → 7.2.0-rc.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.
Files changed (2) hide show
  1. package/lib/store/store.ts +36 -8
  2. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { number } from "superstruct";
1
+ import { nullable, number, object } from "superstruct";
2
2
  import {
3
3
  and,
4
4
  assertEvent,
@@ -28,10 +28,17 @@ const safeStorage = createSafeStorage({
28
28
  lastSuccessfulSyncTs: number(),
29
29
  });
30
30
 
31
- function createInMemoryContext(): Omit<
32
- MachineContext,
33
- SafeStorageKey<typeof safeStorage>
34
- > {
31
+ const legacyStorage = createSafeStorage({
32
+ store: object({
33
+ currentUser: nullable(currentUser()),
34
+ sessionInfo: nullable(sessionInfo()),
35
+ lastSuccessfulSyncTs: nullable(number()),
36
+ }),
37
+ });
38
+
39
+ type MemoryContext = Omit<MachineContext, SafeStorageKey<typeof safeStorage>>;
40
+
41
+ function createInMemoryContext(): MemoryContext {
35
42
  return {
36
43
  currentSync: null,
37
44
  pushOnceIdle: false,
@@ -39,12 +46,33 @@ function createInMemoryContext(): Omit<
39
46
  };
40
47
  }
41
48
 
49
+ type PersistedContext = Pick<
50
+ MachineContext,
51
+ SafeStorageKey<typeof safeStorage>
52
+ >;
53
+
54
+ function getPersistedContext(): PersistedContext {
55
+ // Legacy store was used in the Hobgoblin app.
56
+ const legacyStore = legacyStorage.getItem("store");
57
+
58
+ // If legacy store existed in localStorage, we make sure to clean it up.
59
+ if (legacyStore) {
60
+ legacyStorage.clear();
61
+ }
62
+
63
+ return {
64
+ currentUser: legacyStore?.currentUser ?? safeStorage.getItem("currentUser"),
65
+ sessionInfo: legacyStore?.sessionInfo ?? safeStorage.getItem("sessionInfo"),
66
+ lastSuccessfulSyncTs:
67
+ legacyStore?.lastSuccessfulSyncTs ??
68
+ safeStorage.getItem("lastSuccessfulSyncTs"),
69
+ };
70
+ }
71
+
42
72
  function createInitialContext(): MachineContext {
43
73
  return {
44
74
  ...createInMemoryContext(),
45
- currentUser: safeStorage.getItem("currentUser"),
46
- sessionInfo: safeStorage.getItem("sessionInfo"),
47
- lastSuccessfulSyncTs: safeStorage.getItem("lastSuccessfulSyncTs"),
75
+ ...getPersistedContext(),
48
76
  };
49
77
  }
50
78
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indietabletop/appkit",
3
- "version": "7.1.0",
3
+ "version": "7.2.0-rc.0",
4
4
  "description": "A collection of modules used in apps built by Indie Tabletop Club",
5
5
  "private": false,
6
6
  "type": "module",