jazz-tools 0.18.6 → 0.18.7
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/.turbo/turbo-build.log +49 -49
- package/CHANGELOG.md +17 -0
- package/dist/better-auth/auth/server.d.ts.map +1 -1
- package/dist/better-auth/auth/server.js +8 -4
- package/dist/better-auth/auth/server.js.map +1 -1
- package/dist/{chunk-45VKEOXG.js → chunk-CFAY3FMQ.js} +70 -21
- package/dist/chunk-CFAY3FMQ.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/inspector/{custom-element-IBHKHN27.js → custom-element-G6SPZEBR.js} +292 -31
- package/dist/inspector/custom-element-G6SPZEBR.js.map +1 -0
- package/dist/inspector/index.d.ts +1 -1
- package/dist/inspector/index.js +302 -41
- package/dist/inspector/index.js.map +1 -1
- package/dist/inspector/register-custom-element.js +1 -1
- package/dist/inspector/ui/button.d.ts +1 -1
- package/dist/inspector/ui/button.d.ts.map +1 -1
- package/dist/inspector/ui/heading.d.ts +2 -1
- package/dist/inspector/ui/heading.d.ts.map +1 -1
- package/dist/inspector/ui/input.d.ts.map +1 -1
- package/dist/inspector/ui/modal.d.ts +16 -0
- package/dist/inspector/ui/modal.d.ts.map +1 -0
- package/dist/inspector/viewer/delete-local-data.d.ts +2 -0
- package/dist/inspector/viewer/delete-local-data.d.ts.map +1 -0
- package/dist/inspector/viewer/{inpsector-button.d.ts → inspector-button.d.ts} +1 -1
- package/dist/inspector/viewer/{inpsector-button.d.ts.map → inspector-button.d.ts.map} +1 -1
- package/dist/inspector/viewer/new-app.d.ts +1 -1
- package/dist/inspector/viewer/new-app.d.ts.map +1 -1
- package/dist/react/hooks.d.ts +1 -1
- package/dist/react/hooks.d.ts.map +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +3 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-core/hooks.d.ts +133 -0
- package/dist/react-core/hooks.d.ts.map +1 -1
- package/dist/react-core/index.js +80 -16
- package/dist/react-core/index.js.map +1 -1
- package/dist/react-core/tests/useCoStateWithSelector.test.d.ts +2 -0
- package/dist/react-core/tests/useCoStateWithSelector.test.d.ts.map +1 -0
- package/dist/react-native-core/hooks.d.ts +1 -1
- package/dist/react-native-core/hooks.d.ts.map +1 -1
- package/dist/react-native-core/index.js +3 -1
- package/dist/react-native-core/index.js.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/tools/coValues/CoValueBase.d.ts +14 -0
- package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
- package/dist/tools/coValues/coMap.d.ts +0 -12
- package/dist/tools/coValues/coMap.d.ts.map +1 -1
- package/dist/tools/implementation/createContext.d.ts +2 -1
- package/dist/tools/implementation/createContext.d.ts.map +1 -1
- package/dist/tools/tests/utils.d.ts.map +1 -1
- package/dist/worker/index.d.ts +4 -0
- package/dist/worker/index.d.ts.map +1 -1
- package/dist/worker/index.js +4 -2
- package/dist/worker/index.js.map +1 -1
- package/package.json +6 -4
- package/src/better-auth/auth/server.ts +8 -4
- package/src/better-auth/auth/tests/server.test.ts +2 -2
- package/src/inspector/index.tsx +1 -1
- package/src/inspector/ui/button.tsx +15 -1
- package/src/inspector/ui/heading.tsx +7 -2
- package/src/inspector/ui/input.tsx +6 -2
- package/src/inspector/ui/modal.tsx +158 -0
- package/src/inspector/viewer/delete-local-data.tsx +101 -0
- package/src/inspector/viewer/new-app.tsx +3 -1
- package/src/react/hooks.tsx +1 -0
- package/src/react/index.ts +1 -0
- package/src/react-core/hooks.ts +162 -0
- package/src/react-core/tests/useCoStateWithSelector.test.ts +149 -0
- package/src/react-native-core/hooks.tsx +1 -0
- package/src/tools/coValues/CoValueBase.ts +32 -0
- package/src/tools/coValues/coList.ts +35 -0
- package/src/tools/coValues/coMap.ts +0 -18
- package/src/tools/implementation/createContext.ts +9 -2
- package/src/tools/tests/coList.test.ts +41 -0
- package/src/tools/tests/coPlainText.test.ts +24 -0
- package/src/tools/tests/createContext.test.ts +24 -0
- package/src/tools/tests/deepLoading.test.ts +2 -0
- package/src/tools/tests/patterns/requestToJoin.test.ts +14 -6
- package/src/tools/tests/utils.ts +1 -0
- package/src/worker/index.ts +6 -0
- package/dist/chunk-45VKEOXG.js.map +0 -1
- package/dist/inspector/custom-element-IBHKHN27.js.map +0 -1
- /package/src/inspector/viewer/{inpsector-button.tsx → inspector-button.tsx} +0 -0
package/.turbo/turbo-build.log
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
> jazz-tools@0.18.
|
2
|
+
> jazz-tools@0.18.7 build /home/runner/_work/jazz/jazz/packages/jazz-tools
|
3
3
|
> tsup && pnpm types && pnpm build:svelte
|
4
4
|
|
5
5
|
[34mCLI[39m Building entry: {"index":"src/index.ts","testing":"src/testing.ts"}
|
@@ -109,91 +109,91 @@
|
|
109
109
|
[34mESM[39m Build start
|
110
110
|
[32mESM[39m [1mdist/react/ssr.js [22m[32m688.00 B[39m
|
111
111
|
[32mESM[39m [1mdist/react/ssr.js.map [22m[32m1.12 KB[39m
|
112
|
-
[32mESM[39m ⚡️ Build success in
|
112
|
+
[32mESM[39m ⚡️ Build success in 21ms
|
113
|
+
[32mESM[39m [1mdist/worker/index.js [22m[32m2.47 KB[39m
|
114
|
+
[32mESM[39m [1mdist/worker/index.js.map [22m[32m5.26 KB[39m
|
115
|
+
[32mESM[39m ⚡️ Build success in 18ms
|
113
116
|
[32mESM[39m [1mdist/tiptap/index.js [22m[32m564.00 B[39m
|
114
117
|
[32mESM[39m [1mdist/tiptap/index.js.map [22m[32m1.21 KB[39m
|
115
|
-
[32mESM[39m ⚡️ Build success in
|
116
|
-
[32mESM[39m [1mdist/worker/index.js [22m[32m2.42 KB[39m
|
117
|
-
[32mESM[39m [1mdist/worker/index.js.map [22m[32m5.08 KB[39m
|
118
|
-
[32mESM[39m ⚡️ Build success in 15ms
|
119
|
-
[32mESM[39m [1mdist/expo/index.js [22m[32m4.68 KB[39m
|
120
|
-
[32mESM[39m [1mdist/expo/crypto.js [22m[32m153.00 B[39m
|
121
|
-
[32mESM[39m [1mdist/expo/testing.js [22m[32m112.00 B[39m
|
122
|
-
[32mESM[39m [1mdist/expo/index.js.map [22m[32m10.23 KB[39m
|
123
|
-
[32mESM[39m [1mdist/expo/crypto.js.map [22m[32m189.00 B[39m
|
124
|
-
[32mESM[39m [1mdist/expo/testing.js.map [22m[32m168.00 B[39m
|
125
|
-
[32mESM[39m ⚡️ Build success in 24ms
|
118
|
+
[32mESM[39m ⚡️ Build success in 20ms
|
126
119
|
[32mESM[39m [1mdist/better-auth/auth/client.js [22m[32m4.44 KB[39m
|
127
|
-
[32mESM[39m [1mdist/better-auth/auth/server.js [22m[32m8.18 KB[39m
|
128
120
|
[32mESM[39m [1mdist/better-auth/auth/react.js [22m[32m799.00 B[39m
|
121
|
+
[32mESM[39m [1mdist/better-auth/auth/server.js [22m[32m8.35 KB[39m
|
129
122
|
[32mESM[39m [1mdist/better-auth/auth/client.js.map [22m[32m8.24 KB[39m
|
130
123
|
[32mESM[39m [1mdist/better-auth/auth/react.js.map [22m[32m2.04 KB[39m
|
131
|
-
[32mESM[39m [1mdist/better-auth/auth/server.js.map [22m[32m15.
|
132
|
-
[32mESM[39m ⚡️ Build success in
|
124
|
+
[32mESM[39m [1mdist/better-auth/auth/server.js.map [22m[32m15.28 KB[39m
|
125
|
+
[32mESM[39m ⚡️ Build success in 23ms
|
126
|
+
[32mESM[39m [1mdist/browser/index.js [22m[32m13.64 KB[39m
|
127
|
+
[32mESM[39m [1mdist/browser/index.js.map [22m[32m29.14 KB[39m
|
128
|
+
[32mESM[39m ⚡️ Build success in 37ms
|
133
129
|
[32mESM[39m [1mdist/media/index.js [22m[32m236.00 B[39m
|
134
130
|
[32mESM[39m [1mdist/media/index.browser.js [22m[32m2.79 KB[39m
|
131
|
+
[32mESM[39m [1mdist/media/index.native.js [22m[32m2.90 KB[39m
|
135
132
|
[32mESM[39m [1mdist/media/index.server.js [22m[32m2.95 KB[39m
|
136
133
|
[32mESM[39m [1mdist/media/chunk-W3S526L3.js [22m[32m6.47 KB[39m
|
137
|
-
[32mESM[39m [1mdist/media/index.native.js [22m[32m2.90 KB[39m
|
138
134
|
[32mESM[39m [1mdist/media/index.js.map [22m[32m71.00 B[39m
|
139
135
|
[32mESM[39m [1mdist/media/index.browser.js.map [22m[32m6.15 KB[39m
|
136
|
+
[32mESM[39m [1mdist/media/index.native.js.map [22m[32m6.09 KB[39m
|
140
137
|
[32mESM[39m [1mdist/media/index.server.js.map [22m[32m6.37 KB[39m
|
141
138
|
[32mESM[39m [1mdist/media/chunk-W3S526L3.js.map [22m[32m16.57 KB[39m
|
142
|
-
[32mESM[39m
|
143
|
-
[32mESM[39m
|
144
|
-
[32mESM[39m [1mdist/
|
145
|
-
[32mESM[39m [1mdist/
|
139
|
+
[32mESM[39m ⚡️ Build success in 37ms
|
140
|
+
[32mESM[39m [1mdist/expo/index.js [22m[32m4.68 KB[39m
|
141
|
+
[32mESM[39m [1mdist/expo/testing.js [22m[32m112.00 B[39m
|
142
|
+
[32mESM[39m [1mdist/expo/crypto.js [22m[32m153.00 B[39m
|
143
|
+
[32mESM[39m [1mdist/expo/index.js.map [22m[32m10.23 KB[39m
|
144
|
+
[32mESM[39m [1mdist/expo/testing.js.map [22m[32m168.00 B[39m
|
145
|
+
[32mESM[39m [1mdist/expo/crypto.js.map [22m[32m189.00 B[39m
|
146
146
|
[32mESM[39m ⚡️ Build success in 37ms
|
147
147
|
[32mESM[39m [1mdist/react-native/index.js [22m[32m2.53 KB[39m
|
148
148
|
[32mESM[39m [1mdist/react-native/testing.js [22m[32m120.00 B[39m
|
149
149
|
[32mESM[39m [1mdist/react-native/crypto.js [22m[32m161.00 B[39m
|
150
|
-
[32mESM[39m [1mdist/react-native/index.js.map [22m[32m5.68 KB[39m
|
151
150
|
[32mESM[39m [1mdist/react-native/testing.js.map [22m[32m176.00 B[39m
|
151
|
+
[32mESM[39m [1mdist/react-native/index.js.map [22m[32m5.68 KB[39m
|
152
152
|
[32mESM[39m [1mdist/react-native/crypto.js.map [22m[32m197.00 B[39m
|
153
|
-
[32mESM[39m ⚡️ Build success in
|
154
|
-
[32mESM[39m [1mdist/react-native-core/index.js [22m[32m17.90 KB[39m
|
155
|
-
[32mESM[39m [1mdist/react-native-core/testing.js [22m[32m119.00 B[39m
|
156
|
-
[32mESM[39m [1mdist/react-native-core/crypto.js [22m[32m2.10 KB[39m
|
157
|
-
[32mESM[39m [1mdist/react-native-core/index.js.map [22m[32m36.66 KB[39m
|
158
|
-
[32mESM[39m [1mdist/react-native-core/testing.js.map [22m[32m175.00 B[39m
|
159
|
-
[32mESM[39m [1mdist/react-native-core/crypto.js.map [22m[32m4.25 KB[39m
|
160
|
-
[32mESM[39m ⚡️ Build success in 38ms
|
153
|
+
[32mESM[39m ⚡️ Build success in 44ms
|
161
154
|
[32mESM[39m [1mdist/prosemirror/index.js [22m[32m77.63 KB[39m
|
162
155
|
[32mESM[39m [1mdist/prosemirror/index.js.map [22m[32m306.98 KB[39m
|
163
|
-
[32mESM[39m ⚡️ Build success in
|
156
|
+
[32mESM[39m ⚡️ Build success in 50ms
|
164
157
|
[32mESM[39m [1mdist/react/testing.js [22m[32m122.00 B[39m
|
165
|
-
[32mESM[39m [1mdist/react/index.js [22m[32m24.
|
158
|
+
[32mESM[39m [1mdist/react/index.js [22m[32m24.71 KB[39m
|
166
159
|
[32mESM[39m [1mdist/react/testing.js.map [22m[32m165.00 B[39m
|
167
|
-
[32mESM[39m [1mdist/react/index.js.map [22m[32m53.
|
168
|
-
[32mESM[39m ⚡️ Build success in
|
169
|
-
[32mESM[39m [1mdist/
|
170
|
-
[32mESM[39m [1mdist/
|
171
|
-
[32mESM[39m
|
172
|
-
[32mESM[39m [1mdist/index.js
|
173
|
-
[32mESM[39m [1mdist/
|
160
|
+
[32mESM[39m [1mdist/react/index.js.map [22m[32m53.50 KB[39m
|
161
|
+
[32mESM[39m ⚡️ Build success in 51ms
|
162
|
+
[32mESM[39m [1mdist/react-native-core/index.js [22m[32m17.95 KB[39m
|
163
|
+
[32mESM[39m [1mdist/react-native-core/crypto.js [22m[32m2.10 KB[39m
|
164
|
+
[32mESM[39m [1mdist/react-native-core/testing.js [22m[32m119.00 B[39m
|
165
|
+
[32mESM[39m [1mdist/react-native-core/index.js.map [22m[32m36.70 KB[39m
|
166
|
+
[32mESM[39m [1mdist/react-native-core/crypto.js.map [22m[32m4.25 KB[39m
|
167
|
+
[32mESM[39m [1mdist/react-native-core/testing.js.map [22m[32m175.00 B[39m
|
168
|
+
[32mESM[39m ⚡️ Build success in 53ms
|
169
|
+
[32mESM[39m [1mdist/inspector/index.js [22m[32m69.71 KB[39m
|
170
|
+
[32mESM[39m [1mdist/inspector/index.js.map [22m[32m121.38 KB[39m
|
171
|
+
[32mESM[39m ⚡️ Build success in 72ms
|
174
172
|
[32mESM[39m [1mdist/testing.js [22m[32m7.17 KB[39m
|
173
|
+
[32mESM[39m [1mdist/index.js [22m[32m26.13 KB[39m
|
174
|
+
[32mESM[39m [1mdist/chunk-CFAY3FMQ.js [22m[32m168.48 KB[39m
|
175
175
|
[32mESM[39m [1mdist/testing.js.map [22m[32m14.10 KB[39m
|
176
176
|
[32mESM[39m [1mdist/index.js.map [22m[32m52.92 KB[39m
|
177
|
-
[32mESM[39m [1mdist/chunk-
|
178
|
-
[32mESM[39m ⚡️ Build success in
|
177
|
+
[32mESM[39m [1mdist/chunk-CFAY3FMQ.js.map [22m[32m400.30 KB[39m
|
178
|
+
[32mESM[39m ⚡️ Build success in 105ms
|
179
179
|
[32mESM[39m [1mdist/react-core/testing.js [22m[32m1.17 KB[39m
|
180
180
|
[32mESM[39m [1mdist/react-core/chunk-7DYMJ74I.js [22m[32m279.00 B[39m
|
181
|
-
[32mESM[39m [1mdist/react-core/index.js [22m[
|
181
|
+
[32mESM[39m [1mdist/react-core/index.js [22m[32m145.49 KB[39m
|
182
182
|
[32mESM[39m [1mdist/react-core/testing.js.map [22m[32m1.82 KB[39m
|
183
183
|
[32mESM[39m [1mdist/react-core/chunk-7DYMJ74I.js.map [22m[32m533.00 B[39m
|
184
|
-
[32mESM[39m [1mdist/react-core/index.js.map [22m[
|
185
|
-
[32mESM[39m ⚡️ Build success in
|
184
|
+
[32mESM[39m [1mdist/react-core/index.js.map [22m[32m399.32 KB[39m
|
185
|
+
[32mESM[39m ⚡️ Build success in 106ms
|
186
186
|
[32mESM[39m [1mdist/inspector/register-custom-element.js [22m[32m218.00 B[39m
|
187
187
|
[32mESM[39m [1mdist/inspector/register-custom-element.js.map [22m[32m314.00 B[39m
|
188
|
-
[32mESM[39m [1mdist/inspector/custom-element-
|
189
|
-
[32mESM[39m [1mdist/inspector/custom-element-
|
190
|
-
[32mESM[39m ⚡️ Build success in
|
188
|
+
[32mESM[39m [1mdist/inspector/custom-element-G6SPZEBR.js [22m[32m1.54 MB[39m
|
189
|
+
[32mESM[39m [1mdist/inspector/custom-element-G6SPZEBR.js.map [22m[32m2.36 MB[39m
|
190
|
+
[32mESM[39m ⚡️ Build success in 148ms
|
191
191
|
|
192
|
-
> jazz-tools@0.18.
|
192
|
+
> jazz-tools@0.18.7 types /home/runner/_work/jazz/jazz/packages/jazz-tools
|
193
193
|
> tsc --outDir dist
|
194
194
|
|
195
195
|
|
196
|
-
> jazz-tools@0.18.
|
196
|
+
> jazz-tools@0.18.7 build:svelte /home/runner/_work/jazz/jazz/packages/jazz-tools
|
197
197
|
> rm -rf dist/svelte && svelte-package -i src/svelte -o dist/svelte --tsconfig tsconfig.svelte.json
|
198
198
|
|
199
199
|
src/svelte -> dist/svelte
|
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
# jazz-tools
|
2
2
|
|
3
|
+
## 0.18.7
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- cf26739: Add `useCoStateWithSelector` for granular reactivity
|
8
|
+
- a3cd9c8: Add lastUpdatedAt & createdAt properties to $jazz in all the coValue types
|
9
|
+
- ca5cd26: Make CoLists structurally equal to arrays
|
10
|
+
- 32d1444: fix: ensure better-auth email-otp verification uniqueness
|
11
|
+
- Updated dependencies [c2d8bf7]
|
12
|
+
- Updated dependencies [dccb464]
|
13
|
+
- Updated dependencies [a3cd9c8]
|
14
|
+
- Updated dependencies [e8e7bf8]
|
15
|
+
- Updated dependencies [51d3558]
|
16
|
+
- cojson@0.18.7
|
17
|
+
- cojson-storage-indexeddb@0.18.7
|
18
|
+
- cojson-transport-ws@0.18.7
|
19
|
+
|
3
20
|
## 0.18.6
|
4
21
|
|
5
22
|
### Patch Changes
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/better-auth/auth/server.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAwB,MAAM,qBAAqB,CAAC;AAM7E,KAAK,UAAU,GAAG,gBAAgB,GAAG;IACnC,MAAM,EAAE;QACN,IAAI,EAAE;YACJ,MAAM,EAAE;gBACN,SAAS,EAAE;oBACT,IAAI,EAAE,QAAQ,CAAC;oBACf,QAAQ,EAAE,KAAK,CAAC;oBAChB,KAAK,EAAE,KAAK,CAAC;iBACd,CAAC;gBACF,oBAAoB,EAAE;oBACpB,IAAI,EAAE,QAAQ,CAAC;oBACf,QAAQ,EAAE,KAAK,CAAC;oBAChB,KAAK,EAAE,KAAK,CAAC;oBACb,QAAQ,EAAE,KAAK,CAAC;iBACjB,CAAC;aACH,CAAC;SACH,CAAC;KACH,CAAC;CACH,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/better-auth/auth/server.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAwB,MAAM,qBAAqB,CAAC;AAM7E,KAAK,UAAU,GAAG,gBAAgB,GAAG;IACnC,MAAM,EAAE;QACN,IAAI,EAAE;YACJ,MAAM,EAAE;gBACN,SAAS,EAAE;oBACT,IAAI,EAAE,QAAQ,CAAC;oBACf,QAAQ,EAAE,KAAK,CAAC;oBAChB,KAAK,EAAE,KAAK,CAAC;iBACd,CAAC;gBACF,oBAAoB,EAAE;oBACpB,IAAI,EAAE,QAAQ,CAAC;oBACf,QAAQ,EAAE,KAAK,CAAC;oBAChB,KAAK,EAAE,KAAK,CAAC;oBACb,QAAQ,EAAE,KAAK,CAAC;iBACjB,CAAC;aACH,CAAC;SACH,CAAC;KACH,CAAC;CACH,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,EAAE,MAAM,UA0Q9B,CAAC"}
|
@@ -47,10 +47,14 @@ var jazzPlugin = () => {
|
|
47
47
|
create: {
|
48
48
|
after: async (verification, context) => {
|
49
49
|
if (contextContainsJazzAuth(context) && verification.identifier.startsWith("sign-in-otp-")) {
|
50
|
+
const identifier = `jazz-auth-${verification.identifier}`;
|
51
|
+
await context.context.internalAdapter.deleteVerificationValue(
|
52
|
+
identifier
|
53
|
+
);
|
50
54
|
await context.context.internalAdapter.createVerificationValue(
|
51
55
|
{
|
52
56
|
value: JSON.stringify({ jazzAuth: context.jazzAuth }),
|
53
|
-
identifier
|
57
|
+
identifier,
|
54
58
|
expiresAt: verification.expiresAt
|
55
59
|
}
|
56
60
|
);
|
@@ -109,7 +113,7 @@ var jazzPlugin = () => {
|
|
109
113
|
},
|
110
114
|
handler: createAuthMiddleware(async (ctx) => {
|
111
115
|
const state = ctx.query?.state || ctx.body?.state;
|
112
|
-
const identifier =
|
116
|
+
const identifier = `jazz-auth-${state}`;
|
113
117
|
const data = await ctx.context.internalAdapter.findVerificationValue(
|
114
118
|
identifier
|
115
119
|
);
|
@@ -144,7 +148,7 @@ var jazzPlugin = () => {
|
|
144
148
|
},
|
145
149
|
handler: createAuthMiddleware(async (ctx) => {
|
146
150
|
const email = ctx.body.email;
|
147
|
-
const identifier = `sign-in-otp-${email}
|
151
|
+
const identifier = `jazz-auth-sign-in-otp-${email}`;
|
148
152
|
const data = await ctx.context.internalAdapter.findVerificationValue(
|
149
153
|
identifier
|
150
154
|
);
|
@@ -213,7 +217,7 @@ var jazzPlugin = () => {
|
|
213
217
|
expiresAt.setMinutes(expiresAt.getMinutes() + 10);
|
214
218
|
await ctx.context.internalAdapter.createVerificationValue({
|
215
219
|
value,
|
216
|
-
identifier:
|
220
|
+
identifier: `jazz-auth-${state}`,
|
217
221
|
expiresAt
|
218
222
|
});
|
219
223
|
})
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/better-auth/auth/server.ts"],"sourcesContent":["import { AuthContext, MiddlewareContext, MiddlewareOptions } from \"better-auth\";\nimport { APIError } from \"better-auth/api\";\nimport { symmetricDecrypt, symmetricEncrypt } from \"better-auth/crypto\";\nimport { BetterAuthPlugin, createAuthMiddleware } from \"better-auth/plugins\";\nimport type { Account, AuthCredentials, ID } from \"jazz-tools\";\n\n// Define a type to have user fields mapped in the better-auth instance\n// It should be automatic, but it needs an hard reference to BetterAuthPlugin type\n// in order to be exported as library.\ntype JazzPlugin = BetterAuthPlugin & {\n schema: {\n user: {\n fields: {\n accountID: {\n type: \"string\";\n required: false;\n input: false;\n };\n encryptedCredentials: {\n type: \"string\";\n required: false;\n input: false;\n returned: false;\n };\n };\n };\n };\n};\n\n/**\n * @returns The BetterAuth server plugin.\n *\n * @example\n * ```ts\n * const auth = betterAuth({\n * plugins: [jazzPlugin()],\n * // ... other BetterAuth options\n * });\n * ```\n */\nexport const jazzPlugin: () => JazzPlugin = () => {\n return {\n id: \"jazz-plugin\",\n schema: {\n user: {\n fields: {\n accountID: {\n type: \"string\",\n required: false,\n input: false,\n },\n encryptedCredentials: {\n type: \"string\",\n required: false,\n input: false,\n returned: false,\n },\n },\n },\n },\n\n init() {\n return {\n options: {\n databaseHooks: {\n user: {\n create: {\n before: async (user, context) => {\n // If the user is created without a jazzAuth, it will throw an error.\n if (!contextContainsJazzAuth(context)) {\n throw new APIError(422, {\n message: \"JazzAuth is required on user creation\",\n });\n }\n // Decorate the user with the jazz's credentials.\n return {\n data: {\n accountID: context.jazzAuth.accountID,\n encryptedCredentials:\n context.jazzAuth.encryptedCredentials,\n },\n };\n },\n },\n },\n verification: {\n create: {\n after: async (verification, context) => {\n /**\n * For: Email OTP plugin\n * After a verification is created, if it is from the EmailOTP plugin,\n * create a new verification value with the jazzAuth with the same expiration.\n */\n if (\n contextContainsJazzAuth(context) &&\n verification.identifier.startsWith(\"sign-in-otp-\")\n ) {\n await context.context.internalAdapter.createVerificationValue(\n {\n value: JSON.stringify({ jazzAuth: context.jazzAuth }),\n identifier: `${verification.identifier}-jazz-auth`,\n expiresAt: verification.expiresAt,\n },\n );\n }\n },\n },\n },\n },\n },\n };\n },\n\n hooks: {\n before: [\n /**\n * If the client sends a x-jazz-auth header,\n * we encrypt the credentials and inject them into the context.\n */\n {\n matcher: (context) => {\n return !!context.headers?.get(\"x-jazz-auth\");\n },\n handler: createAuthMiddleware(async (ctx) => {\n const jazzAuth = JSON.parse(ctx.headers?.get(\"x-jazz-auth\")!);\n\n const credentials: AuthCredentials = {\n accountID: jazzAuth.accountID as ID<Account>,\n secretSeed: jazzAuth.secretSeed,\n accountSecret: jazzAuth.accountSecret as any,\n // If the provider remains 'anonymous', Jazz will not consider us authenticated later.\n provider: \"better-auth\",\n };\n\n const encryptedCredentials = await symmetricEncrypt({\n key: ctx.context.secret,\n data: JSON.stringify(credentials),\n });\n\n return {\n context: {\n ...ctx,\n jazzAuth: {\n accountID: jazzAuth.accountID,\n encryptedCredentials: encryptedCredentials,\n },\n },\n };\n }),\n },\n\n /**\n * For: Social / OAuth2 plugin\n * /callback is the endpoint that BetterAuth uses to authenticate the user coming from a social provider.\n * 1. Catch the state\n * 2. Find the verification value\n * 3. If the verification value contains a jazzAuth, inject into the context to have it in case of registration.\n */\n {\n matcher: (context) => {\n return (\n context.path.startsWith(\"/callback\") ||\n context.path.startsWith(\"/oauth2/callback\")\n );\n },\n handler: createAuthMiddleware(async (ctx) => {\n const state = ctx.query?.state || ctx.body?.state;\n\n const identifier = `${state}-jazz-auth`;\n\n const data =\n await ctx.context.internalAdapter.findVerificationValue(\n identifier,\n );\n\n // if not found, the social plugin will throw later anyway\n if (!data) {\n throw new APIError(404, {\n message: \"Verification not found\",\n });\n }\n\n const parsed = JSON.parse(data.value);\n\n if (parsed && \"jazzAuth\" in parsed) {\n return {\n context: {\n ...ctx,\n jazzAuth: parsed.jazzAuth,\n },\n };\n } else {\n throw new APIError(404, {\n message: \"JazzAuth not found in verification value\",\n });\n }\n }),\n },\n /**\n * For: Email OTP plugin\n * When the user sends an OTP, we try to find the jazzAuth.\n * If it isn't a sign-up, we expect to not find a verification value.\n */\n {\n matcher: (context) => {\n return context.path.startsWith(\"/sign-in/email-otp\");\n },\n handler: createAuthMiddleware(async (ctx) => {\n const email = ctx.body.email;\n const identifier = `sign-in-otp-${email}-jazz-auth`;\n\n const data =\n await ctx.context.internalAdapter.findVerificationValue(\n identifier,\n );\n\n // if not found, it isn't a sign-up\n if (!data || data.expiresAt < new Date()) {\n return;\n }\n\n const parsed = JSON.parse(data.value);\n\n if (parsed && \"jazzAuth\" in parsed) {\n return {\n context: {\n ...ctx,\n jazzAuth: parsed.jazzAuth,\n },\n };\n } else {\n throw new APIError(500, {\n message: \"JazzAuth not found in verification value\",\n });\n }\n }),\n },\n ],\n after: [\n /**\n * This middleware is used to extract the jazzAuth from the user and return it in the response.\n * It is used in the following endpoints that return the user:\n * - /sign-up/email\n * - /sign-in/email\n * - /get-session\n */\n {\n matcher: (context) => {\n return (\n context.path.startsWith(\"/sign-up\") ||\n context.path.startsWith(\"/sign-in\") ||\n context.path.startsWith(\"/get-session\")\n );\n },\n handler: createAuthMiddleware({}, async (ctx) => {\n const returned = ctx.context.returned as any;\n if (!returned?.user?.id) {\n return;\n }\n const jazzAuth = await extractJazzAuth(returned.user.id, ctx);\n\n return ctx.json({\n ...returned,\n jazzAuth: jazzAuth,\n });\n }),\n },\n\n /**\n * For: Social / OAuth2 plugin\n * When the user sign-in via social, we create a verification value with the jazzAuth.\n */\n {\n matcher: (context) => {\n return context.path.startsWith(\"/sign-in/social\");\n },\n handler: createAuthMiddleware(async (ctx) => {\n if (!contextContainsJazzAuth(ctx)) {\n throw new APIError(500, {\n message: \"JazzAuth not found in context\",\n });\n }\n\n const returned = ctx.context.returned as { url: string };\n\n const url = new URL(returned.url);\n const state = url.searchParams.get(\"state\");\n\n const value = JSON.stringify({ jazzAuth: ctx.jazzAuth });\n const expiresAt = new Date();\n expiresAt.setMinutes(expiresAt.getMinutes() + 10);\n\n await ctx.context.internalAdapter.createVerificationValue({\n value,\n identifier: `${state}-jazz-auth`,\n expiresAt,\n });\n }),\n },\n ],\n },\n } satisfies JazzPlugin;\n};\n\nfunction contextContainsJazzAuth(ctx: unknown): ctx is {\n jazzAuth: {\n accountID: string;\n encryptedCredentials: string;\n };\n} {\n return !!ctx && typeof ctx === \"object\" && \"jazzAuth\" in ctx;\n}\n\nasync function extractJazzAuth(\n userId: string,\n ctx: MiddlewareContext<\n MiddlewareOptions,\n AuthContext & {\n returned?: unknown;\n responseHeaders?: Headers;\n }\n >,\n) {\n const user = await ctx.context.adapter.findOne<{\n accountID: string;\n encryptedCredentials: string;\n }>({\n model: ctx.context.tables.user!.modelName,\n where: [\n {\n field: \"id\",\n operator: \"eq\",\n value: userId,\n },\n ],\n select: [\"accountID\", \"encryptedCredentials\"],\n });\n\n if (!user) {\n return;\n }\n\n const jazzAuth = JSON.parse(\n await symmetricDecrypt({\n key: ctx.context.secret,\n data: user.encryptedCredentials,\n }),\n );\n\n return jazzAuth;\n}\n"],"mappings":";AACA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB,wBAAwB;AACnD,SAA2B,4BAA4B;AAqChD,IAAM,aAA+B,MAAM;AAChD,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,QAAQ;AAAA,MACN,MAAM;AAAA,QACJ,QAAQ;AAAA,UACN,WAAW;AAAA,YACT,MAAM;AAAA,YACN,UAAU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sources":["../../../src/better-auth/auth/server.ts"],"sourcesContent":["import { AuthContext, MiddlewareContext, MiddlewareOptions } from \"better-auth\";\nimport { APIError } from \"better-auth/api\";\nimport { symmetricDecrypt, symmetricEncrypt } from \"better-auth/crypto\";\nimport { BetterAuthPlugin, createAuthMiddleware } from \"better-auth/plugins\";\nimport type { Account, AuthCredentials, ID } from \"jazz-tools\";\n\n// Define a type to have user fields mapped in the better-auth instance\n// It should be automatic, but it needs an hard reference to BetterAuthPlugin type\n// in order to be exported as library.\ntype JazzPlugin = BetterAuthPlugin & {\n schema: {\n user: {\n fields: {\n accountID: {\n type: \"string\";\n required: false;\n input: false;\n };\n encryptedCredentials: {\n type: \"string\";\n required: false;\n input: false;\n returned: false;\n };\n };\n };\n };\n};\n\n/**\n * @returns The BetterAuth server plugin.\n *\n * @example\n * ```ts\n * const auth = betterAuth({\n * plugins: [jazzPlugin()],\n * // ... other BetterAuth options\n * });\n * ```\n */\nexport const jazzPlugin: () => JazzPlugin = () => {\n return {\n id: \"jazz-plugin\",\n schema: {\n user: {\n fields: {\n accountID: {\n type: \"string\",\n required: false,\n input: false,\n },\n encryptedCredentials: {\n type: \"string\",\n required: false,\n input: false,\n returned: false,\n },\n },\n },\n },\n\n init() {\n return {\n options: {\n databaseHooks: {\n user: {\n create: {\n before: async (user, context) => {\n // If the user is created without a jazzAuth, it will throw an error.\n if (!contextContainsJazzAuth(context)) {\n throw new APIError(422, {\n message: \"JazzAuth is required on user creation\",\n });\n }\n // Decorate the user with the jazz's credentials.\n return {\n data: {\n accountID: context.jazzAuth.accountID,\n encryptedCredentials:\n context.jazzAuth.encryptedCredentials,\n },\n };\n },\n },\n },\n verification: {\n create: {\n after: async (verification, context) => {\n /**\n * For: Email OTP plugin\n * After a verification is created, if it is from the EmailOTP plugin,\n * create a new verification value with the jazzAuth with the same expiration.\n */\n if (\n contextContainsJazzAuth(context) &&\n verification.identifier.startsWith(\"sign-in-otp-\")\n ) {\n const identifier = `jazz-auth-${verification.identifier}`;\n await context.context.internalAdapter.deleteVerificationValue(\n identifier,\n );\n await context.context.internalAdapter.createVerificationValue(\n {\n value: JSON.stringify({ jazzAuth: context.jazzAuth }),\n identifier: identifier,\n expiresAt: verification.expiresAt,\n },\n );\n }\n },\n },\n },\n },\n },\n };\n },\n\n hooks: {\n before: [\n /**\n * If the client sends a x-jazz-auth header,\n * we encrypt the credentials and inject them into the context.\n */\n {\n matcher: (context) => {\n return !!context.headers?.get(\"x-jazz-auth\");\n },\n handler: createAuthMiddleware(async (ctx) => {\n const jazzAuth = JSON.parse(ctx.headers?.get(\"x-jazz-auth\")!);\n\n const credentials: AuthCredentials = {\n accountID: jazzAuth.accountID as ID<Account>,\n secretSeed: jazzAuth.secretSeed,\n accountSecret: jazzAuth.accountSecret as any,\n // If the provider remains 'anonymous', Jazz will not consider us authenticated later.\n provider: \"better-auth\",\n };\n\n const encryptedCredentials = await symmetricEncrypt({\n key: ctx.context.secret,\n data: JSON.stringify(credentials),\n });\n\n return {\n context: {\n ...ctx,\n jazzAuth: {\n accountID: jazzAuth.accountID,\n encryptedCredentials: encryptedCredentials,\n },\n },\n };\n }),\n },\n\n /**\n * For: Social / OAuth2 plugin\n * /callback is the endpoint that BetterAuth uses to authenticate the user coming from a social provider.\n * 1. Catch the state\n * 2. Find the verification value\n * 3. If the verification value contains a jazzAuth, inject into the context to have it in case of registration.\n */\n {\n matcher: (context) => {\n return (\n context.path.startsWith(\"/callback\") ||\n context.path.startsWith(\"/oauth2/callback\")\n );\n },\n handler: createAuthMiddleware(async (ctx) => {\n const state = ctx.query?.state || ctx.body?.state;\n\n const identifier = `jazz-auth-${state}`;\n\n const data =\n await ctx.context.internalAdapter.findVerificationValue(\n identifier,\n );\n\n // if not found, the social plugin will throw later anyway\n if (!data) {\n throw new APIError(404, {\n message: \"Verification not found\",\n });\n }\n\n const parsed = JSON.parse(data.value);\n\n if (parsed && \"jazzAuth\" in parsed) {\n return {\n context: {\n ...ctx,\n jazzAuth: parsed.jazzAuth,\n },\n };\n } else {\n throw new APIError(404, {\n message: \"JazzAuth not found in verification value\",\n });\n }\n }),\n },\n /**\n * For: Email OTP plugin\n * When the user sends an OTP, we try to find the jazzAuth.\n * If it isn't a sign-up, we expect to not find a verification value.\n */\n {\n matcher: (context) => {\n return context.path.startsWith(\"/sign-in/email-otp\");\n },\n handler: createAuthMiddleware(async (ctx) => {\n const email = ctx.body.email;\n const identifier = `jazz-auth-sign-in-otp-${email}`;\n\n const data =\n await ctx.context.internalAdapter.findVerificationValue(\n identifier,\n );\n\n // if not found, it isn't a sign-up\n if (!data || data.expiresAt < new Date()) {\n return;\n }\n\n const parsed = JSON.parse(data.value);\n\n if (parsed && \"jazzAuth\" in parsed) {\n return {\n context: {\n ...ctx,\n jazzAuth: parsed.jazzAuth,\n },\n };\n } else {\n throw new APIError(500, {\n message: \"JazzAuth not found in verification value\",\n });\n }\n }),\n },\n ],\n after: [\n /**\n * This middleware is used to extract the jazzAuth from the user and return it in the response.\n * It is used in the following endpoints that return the user:\n * - /sign-up/email\n * - /sign-in/email\n * - /get-session\n */\n {\n matcher: (context) => {\n return (\n context.path.startsWith(\"/sign-up\") ||\n context.path.startsWith(\"/sign-in\") ||\n context.path.startsWith(\"/get-session\")\n );\n },\n handler: createAuthMiddleware({}, async (ctx) => {\n const returned = ctx.context.returned as any;\n if (!returned?.user?.id) {\n return;\n }\n const jazzAuth = await extractJazzAuth(returned.user.id, ctx);\n\n return ctx.json({\n ...returned,\n jazzAuth: jazzAuth,\n });\n }),\n },\n\n /**\n * For: Social / OAuth2 plugin\n * When the user sign-in via social, we create a verification value with the jazzAuth.\n */\n {\n matcher: (context) => {\n return context.path.startsWith(\"/sign-in/social\");\n },\n handler: createAuthMiddleware(async (ctx) => {\n if (!contextContainsJazzAuth(ctx)) {\n throw new APIError(500, {\n message: \"JazzAuth not found in context\",\n });\n }\n\n const returned = ctx.context.returned as { url: string };\n\n const url = new URL(returned.url);\n const state = url.searchParams.get(\"state\");\n\n const value = JSON.stringify({ jazzAuth: ctx.jazzAuth });\n const expiresAt = new Date();\n expiresAt.setMinutes(expiresAt.getMinutes() + 10);\n\n await ctx.context.internalAdapter.createVerificationValue({\n value,\n identifier: `jazz-auth-${state}`,\n expiresAt,\n });\n }),\n },\n ],\n },\n } satisfies JazzPlugin;\n};\n\nfunction contextContainsJazzAuth(ctx: unknown): ctx is {\n jazzAuth: {\n accountID: string;\n encryptedCredentials: string;\n };\n} {\n return !!ctx && typeof ctx === \"object\" && \"jazzAuth\" in ctx;\n}\n\nasync function extractJazzAuth(\n userId: string,\n ctx: MiddlewareContext<\n MiddlewareOptions,\n AuthContext & {\n returned?: unknown;\n responseHeaders?: Headers;\n }\n >,\n) {\n const user = await ctx.context.adapter.findOne<{\n accountID: string;\n encryptedCredentials: string;\n }>({\n model: ctx.context.tables.user!.modelName,\n where: [\n {\n field: \"id\",\n operator: \"eq\",\n value: userId,\n },\n ],\n select: [\"accountID\", \"encryptedCredentials\"],\n });\n\n if (!user) {\n return;\n }\n\n const jazzAuth = JSON.parse(\n await symmetricDecrypt({\n key: ctx.context.secret,\n data: user.encryptedCredentials,\n }),\n );\n\n return jazzAuth;\n}\n"],"mappings":";AACA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB,wBAAwB;AACnD,SAA2B,4BAA4B;AAqChD,IAAM,aAA+B,MAAM;AAChD,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,QAAQ;AAAA,MACN,MAAM;AAAA,QACJ,QAAQ;AAAA,UACN,WAAW;AAAA,YACT,MAAM;AAAA,YACN,UAAU;AAAA,YACV,OAAO;AAAA,UACT;AAAA,UACA,sBAAsB;AAAA,YACpB,MAAM;AAAA,YACN,UAAU;AAAA,YACV,OAAO;AAAA,YACP,UAAU;AAAA,UACZ;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IAEA,OAAO;AACL,aAAO;AAAA,QACL,SAAS;AAAA,UACP,eAAe;AAAA,YACb,MAAM;AAAA,cACJ,QAAQ;AAAA,gBACN,QAA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ACH;AAEA,kBAAM,WAAW,IAAI,QAAQ;AAE7B,kBAAM,MAAM,IAAI,IAAI,SAAS,GAAG;AAChC,kBAAM,QAAQ,IAAI,aAAa,IAAI,OAAO;AAE1C,kBAAM,QAAQ,KAAK,UAAU,EAAE,UAAU,IAAI,SAAS,CAAC;AACvD,kBAAM,YAAY,oBAAI,KAAK;AAC3B,sBAAU,WAAW,UAAU,WAAW,IAAI,EAAE;AAEhD,kBAAM,IAAI,QAAQ,gBAAgB,wBAAwB;AAAA,cACxD;AAAA,cACA,YAAY,aAAa,KAAK;AAAA,cAC9B;AAAA,YACF,CAAC;AAAA,UACH,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,wBAAwB,KAK/B;AACA,SAAO,CAAC,CAAC,OAAO,OAAO,QAAQ,YAAY,cAAc;AAC3D;AAEA,eAAe,gBACb,QACA,KAOA;AACA,QAAM,OAAO,MAAM,IAAI,QAAQ,QAAQ,QAGpC;AAAA,IACD,OAAO,IAAI,QAAQ,OAAO,KAAM;AAAA,IAChC,OAAO;AAAA,MACL;AAAA,QACE,OAAO;AAAA,QACP,UAAU;AAAA,QACV,OAAO;AAAA,MACT;AAAA,IACF;AAAA,IACA,QAAQ,CAAC,aAAa,sBAAsB;AAAA,EAC9C,CAAC;AAED,MAAI,CAAC,MAAM;AACT;AAAA,EACF;AAEA,QAAM,WAAW,KAAK;AAAA,IACpB,MAAM,iBAAiB;AAAA,MACrB,KAAK,IAAI,QAAQ;AAAA,MACjB,MAAM,KAAK;AAAA,IACb,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":[]}
|
@@ -162,6 +162,32 @@ var CoValueJazzApi = class {
|
|
162
162
|
}
|
163
163
|
return new AnonymousJazzAgent(this.localNode);
|
164
164
|
}
|
165
|
+
/**
|
166
|
+
* The timestamp of the creation time of the CoValue
|
167
|
+
*
|
168
|
+
* @category Content
|
169
|
+
*/
|
170
|
+
get createdAt() {
|
171
|
+
const createdAt = this.raw.core.verified.header.meta?.createdAt;
|
172
|
+
if (typeof createdAt === "string") {
|
173
|
+
return new Date(createdAt).getTime();
|
174
|
+
}
|
175
|
+
return this.raw.core.earliestTxMadeAt;
|
176
|
+
}
|
177
|
+
/**
|
178
|
+
* The timestamp of the last updated time of the CoValue
|
179
|
+
*
|
180
|
+
* Returns the creation time if there are no updates.
|
181
|
+
*
|
182
|
+
* @category Content
|
183
|
+
*/
|
184
|
+
get lastUpdatedAt() {
|
185
|
+
const value = this.raw.core.latestTxMadeAt;
|
186
|
+
if (value === 0) {
|
187
|
+
return this.createdAt;
|
188
|
+
}
|
189
|
+
return value;
|
190
|
+
}
|
165
191
|
};
|
166
192
|
|
167
193
|
// src/tools/implementation/inspect.ts
|
@@ -679,22 +705,6 @@ var CoMapJazzApi = class extends CoValueJazzApi {
|
|
679
705
|
get raw() {
|
680
706
|
return this.getRaw();
|
681
707
|
}
|
682
|
-
/**
|
683
|
-
* The timestamp of the creation time of the CoMap
|
684
|
-
*
|
685
|
-
* @category Content
|
686
|
-
*/
|
687
|
-
get createdAt() {
|
688
|
-
return this.raw.earliestTxMadeAt ?? Number.MAX_SAFE_INTEGER;
|
689
|
-
}
|
690
|
-
/**
|
691
|
-
* The timestamp of the last updated time of the CoMap
|
692
|
-
*
|
693
|
-
* @category Content
|
694
|
-
*/
|
695
|
-
get lastUpdatedAt() {
|
696
|
-
return this.raw.latestTxMadeAt;
|
697
|
-
}
|
698
708
|
/** @internal */
|
699
709
|
get schema() {
|
700
710
|
return this.coMap.constructor._schema;
|
@@ -1437,6 +1447,39 @@ var CoListProxyHandler = {
|
|
1437
1447
|
} else {
|
1438
1448
|
return Reflect.has(target, key);
|
1439
1449
|
}
|
1450
|
+
},
|
1451
|
+
ownKeys(target) {
|
1452
|
+
const keys = Reflect.ownKeys(target);
|
1453
|
+
const indexKeys = target.$jazz.raw.entries().map((_entry, i) => String(i));
|
1454
|
+
keys.push(...indexKeys);
|
1455
|
+
return keys;
|
1456
|
+
},
|
1457
|
+
getOwnPropertyDescriptor(target, key) {
|
1458
|
+
if (key === TypeSym) {
|
1459
|
+
return {
|
1460
|
+
enumerable: false,
|
1461
|
+
configurable: true,
|
1462
|
+
writable: false,
|
1463
|
+
value: target[TypeSym]
|
1464
|
+
};
|
1465
|
+
} else if (key in target) {
|
1466
|
+
return Reflect.getOwnPropertyDescriptor(target, key);
|
1467
|
+
} else if (typeof key === "string" && !isNaN(+key)) {
|
1468
|
+
const index = Number(key);
|
1469
|
+
if (index >= 0 && index < target.$jazz.raw.entries().length) {
|
1470
|
+
return {
|
1471
|
+
enumerable: true,
|
1472
|
+
configurable: true,
|
1473
|
+
writable: true
|
1474
|
+
};
|
1475
|
+
}
|
1476
|
+
} else if (key === "length") {
|
1477
|
+
return {
|
1478
|
+
enumerable: false,
|
1479
|
+
configurable: false,
|
1480
|
+
writable: false
|
1481
|
+
};
|
1482
|
+
}
|
1440
1483
|
}
|
1441
1484
|
};
|
1442
1485
|
|
@@ -4201,7 +4244,8 @@ async function createJazzContextFromExistingCredentials({
|
|
4201
4244
|
storage,
|
4202
4245
|
AccountSchema: PropsAccountSchema,
|
4203
4246
|
sessionProvider,
|
4204
|
-
onLogOut
|
4247
|
+
onLogOut,
|
4248
|
+
asActiveAccount
|
4205
4249
|
}) {
|
4206
4250
|
const { sessionID, sessionDone } = await sessionProvider(
|
4207
4251
|
credentials.accountID,
|
@@ -4218,12 +4262,16 @@ async function createJazzContextFromExistingCredentials({
|
|
4218
4262
|
storage,
|
4219
4263
|
migration: async (rawAccount, _node, creationProps) => {
|
4220
4264
|
const account2 = AccountClass.fromRaw(rawAccount);
|
4221
|
-
|
4265
|
+
if (asActiveAccount) {
|
4266
|
+
activeAccountContext.set(account2);
|
4267
|
+
}
|
4222
4268
|
await account2.applyMigration(creationProps);
|
4223
4269
|
}
|
4224
4270
|
});
|
4225
4271
|
const account = AccountClass.fromNode(node);
|
4226
|
-
|
4272
|
+
if (asActiveAccount) {
|
4273
|
+
activeAccountContext.set(account);
|
4274
|
+
}
|
4227
4275
|
return {
|
4228
4276
|
node,
|
4229
4277
|
account,
|
@@ -4294,7 +4342,8 @@ async function createJazzContext(options) {
|
|
4294
4342
|
onLogOut: () => {
|
4295
4343
|
authSecretStorage.clearWithoutNotify();
|
4296
4344
|
},
|
4297
|
-
storage: options.storage
|
4345
|
+
storage: options.storage,
|
4346
|
+
asActiveAccount: true
|
4298
4347
|
});
|
4299
4348
|
} else {
|
4300
4349
|
const secretSeed = options.crypto.newRandomSecretSeed();
|
@@ -5858,4 +5907,4 @@ export {
|
|
5858
5907
|
JazzContextManager
|
5859
5908
|
};
|
5860
5909
|
/* istanbul ignore file -- @preserve */
|
5861
|
-
//# sourceMappingURL=chunk-
|
5910
|
+
//# sourceMappingURL=chunk-CFAY3FMQ.js.map
|