jazz-tools 0.18.6 → 0.18.8

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 (91) hide show
  1. package/.turbo/turbo-build.log +55 -55
  2. package/CHANGELOG.md +28 -0
  3. package/dist/better-auth/auth/server.d.ts.map +1 -1
  4. package/dist/better-auth/auth/server.js +8 -4
  5. package/dist/better-auth/auth/server.js.map +1 -1
  6. package/dist/{chunk-45VKEOXG.js → chunk-QF3R3C4N.js} +75 -22
  7. package/dist/chunk-QF3R3C4N.js.map +1 -0
  8. package/dist/index.js +1 -1
  9. package/dist/inspector/{custom-element-IBHKHN27.js → custom-element-G6SPZEBR.js} +292 -31
  10. package/dist/inspector/custom-element-G6SPZEBR.js.map +1 -0
  11. package/dist/inspector/index.d.ts +1 -1
  12. package/dist/inspector/index.js +302 -41
  13. package/dist/inspector/index.js.map +1 -1
  14. package/dist/inspector/register-custom-element.js +1 -1
  15. package/dist/inspector/ui/button.d.ts +1 -1
  16. package/dist/inspector/ui/button.d.ts.map +1 -1
  17. package/dist/inspector/ui/heading.d.ts +2 -1
  18. package/dist/inspector/ui/heading.d.ts.map +1 -1
  19. package/dist/inspector/ui/input.d.ts.map +1 -1
  20. package/dist/inspector/ui/modal.d.ts +16 -0
  21. package/dist/inspector/ui/modal.d.ts.map +1 -0
  22. package/dist/inspector/viewer/delete-local-data.d.ts +2 -0
  23. package/dist/inspector/viewer/delete-local-data.d.ts.map +1 -0
  24. package/dist/inspector/viewer/{inpsector-button.d.ts → inspector-button.d.ts} +1 -1
  25. package/dist/inspector/viewer/{inpsector-button.d.ts.map → inspector-button.d.ts.map} +1 -1
  26. package/dist/inspector/viewer/new-app.d.ts +1 -1
  27. package/dist/inspector/viewer/new-app.d.ts.map +1 -1
  28. package/dist/react/hooks.d.ts +1 -1
  29. package/dist/react/hooks.d.ts.map +1 -1
  30. package/dist/react/index.d.ts +1 -1
  31. package/dist/react/index.d.ts.map +1 -1
  32. package/dist/react/index.js +3 -1
  33. package/dist/react/index.js.map +1 -1
  34. package/dist/react-core/hooks.d.ts +133 -0
  35. package/dist/react-core/hooks.d.ts.map +1 -1
  36. package/dist/react-core/index.js +85 -17
  37. package/dist/react-core/index.js.map +1 -1
  38. package/dist/react-core/tests/useCoStateWithSelector.test.d.ts +2 -0
  39. package/dist/react-core/tests/useCoStateWithSelector.test.d.ts.map +1 -0
  40. package/dist/react-native-core/hooks.d.ts +1 -1
  41. package/dist/react-native-core/hooks.d.ts.map +1 -1
  42. package/dist/react-native-core/index.js +3 -1
  43. package/dist/react-native-core/index.js.map +1 -1
  44. package/dist/testing.js +1 -1
  45. package/dist/tools/coValues/CoFieldInit.d.ts +5 -5
  46. package/dist/tools/coValues/CoFieldInit.d.ts.map +1 -1
  47. package/dist/tools/coValues/CoValueBase.d.ts +14 -0
  48. package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
  49. package/dist/tools/coValues/coMap.d.ts +0 -12
  50. package/dist/tools/coValues/coMap.d.ts.map +1 -1
  51. package/dist/tools/implementation/createContext.d.ts +2 -1
  52. package/dist/tools/implementation/createContext.d.ts.map +1 -1
  53. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +5 -3
  54. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
  55. package/dist/tools/tests/utils.d.ts.map +1 -1
  56. package/dist/worker/index.d.ts +4 -0
  57. package/dist/worker/index.d.ts.map +1 -1
  58. package/dist/worker/index.js +4 -2
  59. package/dist/worker/index.js.map +1 -1
  60. package/package.json +6 -4
  61. package/src/better-auth/auth/server.ts +8 -4
  62. package/src/better-auth/auth/tests/server.test.ts +2 -2
  63. package/src/inspector/index.tsx +1 -1
  64. package/src/inspector/ui/button.tsx +15 -1
  65. package/src/inspector/ui/heading.tsx +7 -2
  66. package/src/inspector/ui/input.tsx +6 -2
  67. package/src/inspector/ui/modal.tsx +158 -0
  68. package/src/inspector/viewer/delete-local-data.tsx +101 -0
  69. package/src/inspector/viewer/new-app.tsx +3 -1
  70. package/src/react/hooks.tsx +1 -0
  71. package/src/react/index.ts +1 -0
  72. package/src/react-core/hooks.ts +162 -0
  73. package/src/react-core/tests/useCoStateWithSelector.test.ts +149 -0
  74. package/src/react-native-core/hooks.tsx +1 -0
  75. package/src/tools/coValues/CoFieldInit.ts +5 -5
  76. package/src/tools/coValues/CoValueBase.ts +32 -0
  77. package/src/tools/coValues/coList.ts +35 -0
  78. package/src/tools/coValues/coMap.ts +0 -18
  79. package/src/tools/implementation/createContext.ts +9 -2
  80. package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +22 -8
  81. package/src/tools/tests/coList.test.ts +41 -0
  82. package/src/tools/tests/coMap.test.ts +37 -0
  83. package/src/tools/tests/coPlainText.test.ts +24 -0
  84. package/src/tools/tests/createContext.test.ts +24 -0
  85. package/src/tools/tests/deepLoading.test.ts +2 -0
  86. package/src/tools/tests/patterns/requestToJoin.test.ts +14 -6
  87. package/src/tools/tests/utils.ts +1 -0
  88. package/src/worker/index.ts +6 -0
  89. package/dist/chunk-45VKEOXG.js.map +0 -1
  90. package/dist/inspector/custom-element-IBHKHN27.js.map +0 -1
  91. /package/src/inspector/viewer/{inpsector-button.tsx → inspector-button.tsx} +0 -0
@@ -1,5 +1,5 @@
1
1
 
2
- > jazz-tools@0.18.6 build /home/runner/_work/jazz/jazz/packages/jazz-tools
2
+ > jazz-tools@0.18.8 build /home/runner/_work/jazz/jazz/packages/jazz-tools
3
3
  > tsup && pnpm types && pnpm build:svelte
4
4
 
5
5
  CLI Building entry: {"index":"src/index.ts","testing":"src/testing.ts"}
@@ -109,91 +109,91 @@
109
109
  ESM Build start
110
110
  ESM dist/react/ssr.js 688.00 B
111
111
  ESM dist/react/ssr.js.map 1.12 KB
112
- ESM ⚡️ Build success in 19ms
112
+ ESM ⚡️ Build success in 17ms
113
+ ESM dist/react-native/testing.js 120.00 B
114
+ ESM dist/react-native/index.js 2.53 KB
115
+ ESM dist/react-native/crypto.js 161.00 B
116
+ ESM dist/react-native/testing.js.map 176.00 B
117
+ ESM dist/react-native/index.js.map 5.68 KB
118
+ ESM dist/react-native/crypto.js.map 197.00 B
119
+ ESM ⚡️ Build success in 18ms
113
120
  ESM dist/tiptap/index.js 564.00 B
114
121
  ESM dist/tiptap/index.js.map 1.21 KB
115
- ESM ⚡️ Build success in 15ms
116
- ESM dist/worker/index.js 2.42 KB
117
- ESM dist/worker/index.js.map 5.08 KB
118
- ESM ⚡️ Build success in 15ms
119
- ESM dist/expo/index.js 4.68 KB
120
- ESM dist/expo/crypto.js 153.00 B
121
- ESM dist/expo/testing.js 112.00 B
122
- ESM dist/expo/index.js.map 10.23 KB
123
- ESM dist/expo/crypto.js.map 189.00 B
124
- ESM dist/expo/testing.js.map 168.00 B
125
- ESM ⚡️ Build success in 24ms
126
- ESM dist/better-auth/auth/client.js 4.44 KB
127
- ESM dist/better-auth/auth/server.js 8.18 KB
128
- ESM dist/better-auth/auth/react.js 799.00 B
129
- ESM dist/better-auth/auth/client.js.map 8.24 KB
130
- ESM dist/better-auth/auth/react.js.map 2.04 KB
131
- ESM dist/better-auth/auth/server.js.map 15.03 KB
132
- ESM ⚡️ Build success in 17ms
122
+ ESM ⚡️ Build success in 22ms
123
+ ESM dist/worker/index.js 2.47 KB
124
+ ESM dist/worker/index.js.map 5.26 KB
125
+ ESM ⚡️ Build success in 21ms
133
126
  ESM dist/media/index.js 236.00 B
134
127
  ESM dist/media/index.browser.js 2.79 KB
128
+ ESM dist/media/index.native.js 2.90 KB
135
129
  ESM dist/media/index.server.js 2.95 KB
136
130
  ESM dist/media/chunk-W3S526L3.js 6.47 KB
137
- ESM dist/media/index.native.js 2.90 KB
138
131
  ESM dist/media/index.js.map 71.00 B
139
132
  ESM dist/media/index.browser.js.map 6.15 KB
133
+ ESM dist/media/index.native.js.map 6.09 KB
140
134
  ESM dist/media/index.server.js.map 6.37 KB
141
135
  ESM dist/media/chunk-W3S526L3.js.map 16.57 KB
142
- ESM dist/media/index.native.js.map 6.09 KB
143
- ESM ⚡️ Build success in 36ms
136
+ ESM ⚡️ Build success in 32ms
137
+ ESM dist/better-auth/auth/client.js 4.44 KB
138
+ ESM dist/better-auth/auth/server.js 8.36 KB
139
+ ESM dist/better-auth/auth/react.js 799.00 B
140
+ ESM dist/better-auth/auth/client.js.map 8.24 KB
141
+ ESM dist/better-auth/auth/react.js.map 2.04 KB
142
+ ESM dist/better-auth/auth/server.js.map 15.29 KB
143
+ ESM ⚡️ Build success in 29ms
144
144
  ESM dist/browser/index.js 13.64 KB
145
145
  ESM dist/browser/index.js.map 29.14 KB
146
- ESM ⚡️ Build success in 37ms
147
- ESM dist/react-native/index.js 2.53 KB
148
- ESM dist/react-native/testing.js 120.00 B
149
- ESM dist/react-native/crypto.js 161.00 B
150
- ESM dist/react-native/index.js.map 5.68 KB
151
- ESM dist/react-native/testing.js.map 176.00 B
152
- ESM dist/react-native/crypto.js.map 197.00 B
153
- ESM ⚡️ Build success in 34ms
154
- ESM dist/react-native-core/index.js 17.90 KB
146
+ ESM ⚡️ Build success in 38ms
147
+ ESM dist/expo/index.js 4.68 KB
148
+ ESM dist/expo/testing.js 112.00 B
149
+ ESM dist/expo/crypto.js 153.00 B
150
+ ESM dist/expo/index.js.map 10.23 KB
151
+ ESM dist/expo/testing.js.map 168.00 B
152
+ ESM dist/expo/crypto.js.map 189.00 B
153
+ ESM ⚡️ Build success in 41ms
154
+ ESM dist/react-native-core/index.js 17.95 KB
155
155
  ESM dist/react-native-core/testing.js 119.00 B
156
156
  ESM dist/react-native-core/crypto.js 2.10 KB
157
- ESM dist/react-native-core/index.js.map 36.66 KB
158
157
  ESM dist/react-native-core/testing.js.map 175.00 B
159
158
  ESM dist/react-native-core/crypto.js.map 4.25 KB
160
- ESM ⚡️ Build success in 38ms
161
- ESM dist/prosemirror/index.js 77.63 KB
162
- ESM dist/prosemirror/index.js.map 306.98 KB
163
- ESM ⚡️ Build success in 40ms
159
+ ESM dist/react-native-core/index.js.map 36.70 KB
160
+ ESM ⚡️ Build success in 41ms
161
+ ESM dist/react/index.js 24.71 KB
164
162
  ESM dist/react/testing.js 122.00 B
165
- ESM dist/react/index.js 24.66 KB
163
+ ESM dist/react/index.js.map 53.50 KB
166
164
  ESM dist/react/testing.js.map 165.00 B
167
- ESM dist/react/index.js.map 53.43 KB
168
- ESM ⚡️ Build success in 40ms
169
- ESM dist/inspector/index.js 61.57 KB
170
- ESM dist/inspector/index.js.map 110.11 KB
171
- ESM ⚡️ Build success in 60ms
172
- ESM dist/index.js 26.13 KB
173
- ESM dist/chunk-45VKEOXG.js 167.19 KB
165
+ ESM ⚡️ Build success in 42ms
166
+ ESM dist/prosemirror/index.js 77.63 KB
167
+ ESM dist/prosemirror/index.js.map 306.98 KB
168
+ ESM ⚡️ Build success in 44ms
169
+ ESM dist/inspector/index.js 69.71 KB
170
+ ESM dist/inspector/index.js.map 121.38 KB
171
+ ESM ⚡️ Build success in 57ms
174
172
  ESM dist/testing.js 7.17 KB
173
+ ESM dist/index.js 26.13 KB
174
+ ESM dist/chunk-QF3R3C4N.js 168.58 KB
175
175
  ESM dist/testing.js.map 14.10 KB
176
176
  ESM dist/index.js.map 52.92 KB
177
- ESM dist/chunk-45VKEOXG.js.map 397.84 KB
178
- ESM ⚡️ Build success in 82ms
177
+ ESM dist/chunk-QF3R3C4N.js.map 400.77 KB
178
+ ESM ⚡️ Build success in 81ms
179
+ ESM dist/react-core/index.js 145.59 KB
179
180
  ESM dist/react-core/testing.js 1.17 KB
180
181
  ESM dist/react-core/chunk-7DYMJ74I.js 279.00 B
181
- ESM dist/react-core/index.js 143.64 KB
182
+ ESM dist/react-core/index.js.map 399.79 KB
182
183
  ESM dist/react-core/testing.js.map 1.82 KB
183
184
  ESM dist/react-core/chunk-7DYMJ74I.js.map 533.00 B
184
- ESM dist/react-core/index.js.map 391.48 KB
185
- ESM ⚡️ Build success in 79ms
185
+ ESM ⚡️ Build success in 78ms
186
186
  ESM dist/inspector/register-custom-element.js 218.00 B
187
187
  ESM dist/inspector/register-custom-element.js.map 314.00 B
188
- ESM dist/inspector/custom-element-IBHKHN27.js 1.53 MB
189
- ESM dist/inspector/custom-element-IBHKHN27.js.map 2.35 MB
190
- ESM ⚡️ Build success in 117ms
188
+ ESM dist/inspector/custom-element-G6SPZEBR.js 1.54 MB
189
+ ESM dist/inspector/custom-element-G6SPZEBR.js.map 2.36 MB
190
+ ESM ⚡️ Build success in 114ms
191
191
 
192
- > jazz-tools@0.18.6 types /home/runner/_work/jazz/jazz/packages/jazz-tools
192
+ > jazz-tools@0.18.8 types /home/runner/_work/jazz/jazz/packages/jazz-tools
193
193
  > tsc --outDir dist
194
194
 
195
195
 
196
- > jazz-tools@0.18.6 build:svelte /home/runner/_work/jazz/jazz/packages/jazz-tools
196
+ > jazz-tools@0.18.8 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,33 @@
1
1
  # jazz-tools
2
2
 
3
+ ## 0.18.8
4
+
5
+ ### Patch Changes
6
+
7
+ - 700fe46: fix: in 32d1444 was used the wrong Better Auth internal function to delete old verification codes
8
+ - aba0d55: Support the selection of a subset of keys to make optional in `co.map().partial()`
9
+ - Updated dependencies [9a4caf2]
10
+ - cojson@0.18.8
11
+ - cojson-storage-indexeddb@0.18.8
12
+ - cojson-transport-ws@0.18.8
13
+
14
+ ## 0.18.7
15
+
16
+ ### Patch Changes
17
+
18
+ - cf26739: Add `useCoStateWithSelector` for granular reactivity
19
+ - a3cd9c8: Add lastUpdatedAt & createdAt properties to $jazz in all the coValue types
20
+ - ca5cd26: Make CoLists structurally equal to arrays
21
+ - 32d1444: fix: ensure better-auth email-otp verification uniqueness
22
+ - Updated dependencies [c2d8bf7]
23
+ - Updated dependencies [dccb464]
24
+ - Updated dependencies [a3cd9c8]
25
+ - Updated dependencies [e8e7bf8]
26
+ - Updated dependencies [51d3558]
27
+ - cojson@0.18.7
28
+ - cojson-storage-indexeddb@0.18.7
29
+ - cojson-transport-ws@0.18.7
30
+
3
31
  ## 0.18.6
4
32
 
5
33
  ### 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,UAsQ9B,CAAC"}
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.deleteVerificationByIdentifier(
52
+ identifier
53
+ );
50
54
  await context.context.internalAdapter.createVerificationValue(
51
55
  {
52
56
  value: JSON.stringify({ jazzAuth: context.jazzAuth }),
53
- identifier: `${verification.identifier}-jazz-auth`,
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 = `${state}-jazz-auth`;
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}-jazz-auth`;
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: `${state}-jazz-auth`,
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;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,QAAQ,OAAO,MAAM,YAAY;AAE/B,sBAAI,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Aa,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,GAAG,KAAK;AAAA,cACpB;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":[]}
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 const identifier = `jazz-auth-${verification.identifier}`;\n await context.context.internalAdapter.deleteVerificationByIdentifier(\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,QAAQ,OAAO,MAAM,YAAY;AAE/B,sBAAI,CAAC,wBAAwB,OAAO,GAAG;AACrC,0BAAM,IAAI,SAAS,KAAK;AAAA,sBACtB,SAAS;AAAA,oBACX,CAAC;AAAA,kBACH;AAEA,yBAAO;AAAA,oBACL,MAAM;AAAA,sBACJ,WAAW,QAAQ,SAAS;AAAA,sBAC5B,sBACE,QAAQ,SAAS;AAAA,oBACrB;AAAA,kBACF;AAAA,gBACF;AAAA,cACF;AAAA,YACF;AAAA,YACA,c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AAA,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
- activeAccountContext.set(account2);
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
- activeAccountContext.set(account);
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();
@@ -4645,9 +4694,13 @@ function enrichCoMapSchema(schema, coValueClass) {
4645
4694
  }
4646
4695
  return coMapDefiner(pickedShape);
4647
4696
  },
4648
- partial: () => {
4697
+ partial: (keys) => {
4649
4698
  const partialShape = {};
4650
4699
  for (const [key, value] of Object.entries(coValueSchema.shape)) {
4700
+ if (keys && !keys[key]) {
4701
+ partialShape[key] = value;
4702
+ continue;
4703
+ }
4651
4704
  if (isAnyCoValueSchema2(value)) {
4652
4705
  partialShape[key] = coOptionalDefiner(value);
4653
4706
  } else {
@@ -5858,4 +5911,4 @@ export {
5858
5911
  JazzContextManager
5859
5912
  };
5860
5913
  /* istanbul ignore file -- @preserve */
5861
- //# sourceMappingURL=chunk-45VKEOXG.js.map
5914
+ //# sourceMappingURL=chunk-QF3R3C4N.js.map