accounts 0.18.3 → 0.18.5

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 (41) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/core/Adapter.d.ts +4 -0
  3. package/dist/core/Adapter.d.ts.map +1 -1
  4. package/dist/core/Client.d.ts.map +1 -1
  5. package/dist/core/Client.js +62 -2
  6. package/dist/core/Client.js.map +1 -1
  7. package/dist/core/Provider.d.ts.map +1 -1
  8. package/dist/core/Provider.js +16 -4
  9. package/dist/core/Provider.js.map +1 -1
  10. package/dist/core/Schema.d.ts +30 -2
  11. package/dist/core/Schema.d.ts.map +1 -1
  12. package/dist/core/adapters/postMessage/mount.d.ts.map +1 -1
  13. package/dist/core/adapters/postMessage/mount.js +4 -2
  14. package/dist/core/adapters/postMessage/mount.js.map +1 -1
  15. package/dist/core/adapters/privy.d.ts.map +1 -1
  16. package/dist/core/adapters/privy.js +7 -2
  17. package/dist/core/adapters/privy.js.map +1 -1
  18. package/dist/core/zod/rpc.d.ts +18 -1
  19. package/dist/core/zod/rpc.d.ts.map +1 -1
  20. package/dist/core/zod/rpc.js +13 -1
  21. package/dist/core/zod/rpc.js.map +1 -1
  22. package/dist/react/Remote.d.ts.map +1 -1
  23. package/dist/react/Remote.js +5 -1
  24. package/dist/react/Remote.js.map +1 -1
  25. package/dist/trusted-hosts.json +1 -0
  26. package/package.json +4 -4
  27. package/src/core/Adapter.ts +4 -0
  28. package/src/core/Client.test.ts +153 -1
  29. package/src/core/Client.ts +73 -2
  30. package/src/core/Provider.localnet.test.ts +114 -0
  31. package/src/core/Provider.ts +25 -8
  32. package/src/core/Schema.test-d.ts +23 -0
  33. package/src/core/adapters/postMessage/mount.test.ts +51 -0
  34. package/src/core/adapters/postMessage/mount.ts +4 -2
  35. package/src/core/adapters/privy.test.ts +150 -8
  36. package/src/core/adapters/privy.ts +13 -5
  37. package/src/core/zod/request.test.ts +29 -1
  38. package/src/core/zod/rpc.ts +14 -3
  39. package/src/react/Remote.test.ts +153 -0
  40. package/src/react/Remote.ts +7 -1
  41. package/src/trusted-hosts.json +1 -0
@@ -0,0 +1,153 @@
1
+ import { vi } from 'vitest'
2
+ import { afterEach, describe, expect, test } from 'vp/test'
3
+
4
+ const hooks = vi.hoisted(() => ({ cleanups: [] as (() => void)[] }))
5
+
6
+ vi.mock('react', () => ({
7
+ useCallback: (fn: unknown) => fn,
8
+ useEffect: (effect: () => void | (() => void)) => {
9
+ const cleanup = effect()
10
+ if (cleanup) hooks.cleanups.push(cleanup)
11
+ },
12
+ useMemo: (fn: () => unknown) => fn(),
13
+ useRef: (current: unknown) => ({ current }),
14
+ useState: (initial: unknown) => [initial, () => {}],
15
+ }))
16
+
17
+ import { useTheme } from './Remote.js'
18
+
19
+ afterEach(() => {
20
+ hooks.cleanups.length = 0
21
+ vi.unstubAllGlobals()
22
+ })
23
+
24
+ describe('useTheme', () => {
25
+ test('behavior: applies URL theme values to the document', () => {
26
+ const root = createRoot()
27
+ stubBrowser(root, '?accent=%23b9a3ff&radius=medium&scheme=dark')
28
+
29
+ useTheme()
30
+
31
+ expect(readRoot(root)).toMatchInlineSnapshot(`
32
+ {
33
+ "attributes": {
34
+ "data-theme": "dark",
35
+ "data-theme-accent": "custom",
36
+ "data-theme-radius": "medium",
37
+ },
38
+ "colorScheme": "dark",
39
+ "properties": {
40
+ "--theme-accent": "#b9a3ff",
41
+ },
42
+ }
43
+ `)
44
+ })
45
+
46
+ test('behavior: replaces URL overrides with live theme updates', () => {
47
+ const root = createRoot()
48
+ stubBrowser(root, '?accent=purple&radius=full&scheme=dark')
49
+ let update: ((theme: { scheme?: string }) => void) | undefined
50
+ const remote = {
51
+ messenger: {
52
+ on(_topic: string, listener: typeof update) {
53
+ update = listener
54
+ return () => {}
55
+ },
56
+ },
57
+ }
58
+ useTheme(remote as never)
59
+
60
+ update?.({ scheme: 'light' })
61
+
62
+ expect(readRoot(root)).toMatchInlineSnapshot(`
63
+ {
64
+ "attributes": {
65
+ "data-theme": "light",
66
+ },
67
+ "colorScheme": "light",
68
+ "properties": {},
69
+ }
70
+ `)
71
+ })
72
+
73
+ test('behavior: restores the document theme when unmounted', () => {
74
+ const root = createRoot(
75
+ {
76
+ 'data-theme': 'light',
77
+ 'data-theme-accent': 'custom',
78
+ 'data-theme-radius': 'small',
79
+ },
80
+ 'light',
81
+ { '--theme-accent': '#ff007a' },
82
+ )
83
+ stubBrowser(root, '?accent=blue&radius=full&scheme=dark')
84
+ useTheme()
85
+
86
+ hooks.cleanups[0]?.()
87
+
88
+ expect(readRoot(root)).toMatchInlineSnapshot(`
89
+ {
90
+ "attributes": {
91
+ "data-theme": "light",
92
+ "data-theme-accent": "custom",
93
+ "data-theme-radius": "small",
94
+ },
95
+ "colorScheme": "light",
96
+ "properties": {
97
+ "--theme-accent": "#ff007a",
98
+ },
99
+ }
100
+ `)
101
+ })
102
+ })
103
+
104
+ // Helpers
105
+
106
+ function stubBrowser(root: ReturnType<typeof createRoot>, search: string) {
107
+ vi.stubGlobal('document', { documentElement: root })
108
+ vi.stubGlobal('window', { location: { search } })
109
+ }
110
+
111
+ function createRoot(
112
+ initialAttributes: Record<string, string> = {},
113
+ colorScheme = '',
114
+ initialProperties: Record<string, string> = {},
115
+ ) {
116
+ const attributes = new Map(Object.entries(initialAttributes))
117
+ const properties = new Map(Object.entries(initialProperties))
118
+ return {
119
+ attributes,
120
+ getAttribute(name: string) {
121
+ return attributes.get(name) ?? null
122
+ },
123
+ removeAttribute(name: string) {
124
+ attributes.delete(name)
125
+ },
126
+ setAttribute(name: string, value: string) {
127
+ attributes.set(name, value)
128
+ },
129
+ style: {
130
+ colorScheme,
131
+ getPropertyValue(name: string) {
132
+ return properties.get(name) ?? ''
133
+ },
134
+ removeProperty(name: string) {
135
+ const value = properties.get(name) ?? ''
136
+ properties.delete(name)
137
+ return value
138
+ },
139
+ setProperty(name: string, value: string) {
140
+ properties.set(name, value)
141
+ },
142
+ },
143
+ properties,
144
+ }
145
+ }
146
+
147
+ function readRoot(root: ReturnType<typeof createRoot>) {
148
+ return {
149
+ attributes: Object.fromEntries(root.attributes),
150
+ colorScheme: root.style.colorScheme,
151
+ properties: Object.fromEntries(root.properties),
152
+ }
153
+ }
@@ -126,7 +126,10 @@ function applyTheme(theme: {
126
126
  root.setAttribute('data-theme-accent', getAccentName(accent))
127
127
  if (!isAccentPreset(accent)) root.style.setProperty('--theme-accent', accent)
128
128
  }
129
- if (scheme) root.style.colorScheme = scheme
129
+ if (scheme) {
130
+ root.style.colorScheme = scheme
131
+ root.setAttribute('data-theme', scheme)
132
+ }
130
133
  if (radius) root.setAttribute('data-theme-radius', radius)
131
134
  }
132
135
 
@@ -137,11 +140,13 @@ function captureTheme(): ThemeSnapshot {
137
140
  accentValue: root.style.getPropertyValue('--theme-accent'),
138
141
  colorScheme: root.style.colorScheme,
139
142
  radius: root.getAttribute('data-theme-radius'),
143
+ scheme: root.getAttribute('data-theme'),
140
144
  }
141
145
  }
142
146
 
143
147
  function restoreTheme(snapshot: ThemeSnapshot) {
144
148
  const root = document.documentElement
149
+ restoreAttribute(root, 'data-theme', snapshot.scheme)
145
150
  restoreAttribute(root, 'data-theme-accent', snapshot.accentPreset)
146
151
  restoreAttribute(root, 'data-theme-radius', snapshot.radius)
147
152
  if (snapshot.accentValue) root.style.setProperty('--theme-accent', snapshot.accentValue)
@@ -175,6 +180,7 @@ type ThemeSnapshot = {
175
180
  accentValue: string
176
181
  colorScheme: string
177
182
  radius: string | null
183
+ scheme: string | null
178
184
  }
179
185
 
180
186
  export declare namespace useEnsureVisibility {
@@ -3,6 +3,7 @@
3
3
  "localhost",
4
4
  "*.localhost",
5
5
  "*.tempo.xyz",
6
+ "mercator.sh",
6
7
  "paradigm.xyz",
7
8
  "promptgolf.sh",
8
9
  "app.polyhedge.capital",