jazz-tools 0.19.20 → 0.19.22

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 (105) hide show
  1. package/.svelte-kit/__package__/server.d.ts.map +1 -1
  2. package/.svelte-kit/__package__/server.js +9 -7
  3. package/.turbo/turbo-build.log +56 -56
  4. package/CHANGELOG.md +15 -0
  5. package/dist/better-auth/auth/server.d.ts.map +1 -1
  6. package/dist/better-auth/auth/server.js +4 -4
  7. package/dist/better-auth/auth/server.js.map +1 -1
  8. package/dist/better-auth/database-adapter/index.js.map +1 -1
  9. package/dist/better-auth/database-adapter/repository/generic.d.ts +3 -3
  10. package/dist/better-auth/database-adapter/repository/session.d.ts +2 -2
  11. package/dist/better-auth/database-adapter/schema.d.ts +3 -3
  12. package/dist/better-auth/database-adapter/schema.d.ts.map +1 -1
  13. package/dist/{chunk-MI24YFCY.js → chunk-QCTQH5RS.js} +1 -1
  14. package/dist/chunk-QCTQH5RS.js.map +1 -0
  15. package/dist/index.js +36 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/media/{chunk-3LKBM3G3.js → chunk-IRL3KNPO.js} +2 -2
  18. package/dist/media/{chunk-3LKBM3G3.js.map → chunk-IRL3KNPO.js.map} +1 -1
  19. package/dist/media/create-image/react-native.d.ts +1 -1
  20. package/dist/media/create-image/react-native.d.ts.map +1 -1
  21. package/dist/media/index.browser.js +1 -1
  22. package/dist/media/index.js +1 -1
  23. package/dist/media/index.native.js +5 -5
  24. package/dist/media/index.native.js.map +1 -1
  25. package/dist/media/index.server.js +1 -1
  26. package/dist/react/hooks.d.ts +1 -2
  27. package/dist/react/hooks.d.ts.map +1 -1
  28. package/dist/react/index.js +7 -2
  29. package/dist/react/index.js.map +1 -1
  30. package/dist/react-core/hooks.d.ts +92 -1
  31. package/dist/react-core/hooks.d.ts.map +1 -1
  32. package/dist/react-core/index.js +126 -57
  33. package/dist/react-core/index.js.map +1 -1
  34. package/dist/react-core/tests/useCoStates.test.d.ts +2 -0
  35. package/dist/react-core/tests/useCoStates.test.d.ts.map +1 -0
  36. package/dist/react-native/index.js +4 -0
  37. package/dist/react-native/index.js.map +1 -1
  38. package/dist/react-native-core/hooks.d.ts +1 -1
  39. package/dist/react-native-core/hooks.d.ts.map +1 -1
  40. package/dist/react-native-core/index.js +4 -0
  41. package/dist/react-native-core/index.js.map +1 -1
  42. package/dist/svelte/auth/ClerkAuth.svelte.d.ts +38 -0
  43. package/dist/svelte/auth/ClerkAuth.svelte.d.ts.map +1 -0
  44. package/dist/svelte/auth/ClerkAuth.svelte.js +47 -0
  45. package/dist/svelte/auth/JazzSvelteProviderWithClerk.svelte +156 -0
  46. package/dist/svelte/auth/JazzSvelteProviderWithClerk.svelte.d.ts +67 -0
  47. package/dist/svelte/auth/JazzSvelteProviderWithClerk.svelte.d.ts.map +1 -0
  48. package/dist/svelte/auth/RegisterClerkAuth.svelte +27 -0
  49. package/dist/svelte/auth/RegisterClerkAuth.svelte.d.ts +17 -0
  50. package/dist/svelte/auth/RegisterClerkAuth.svelte.d.ts.map +1 -0
  51. package/dist/svelte/auth/index.d.ts +2 -0
  52. package/dist/svelte/auth/index.d.ts.map +1 -1
  53. package/dist/svelte/auth/index.js +2 -0
  54. package/dist/svelte/tests/ClerkAuth.svelte.test.d.ts +2 -0
  55. package/dist/svelte/tests/ClerkAuth.svelte.test.d.ts.map +1 -0
  56. package/dist/svelte/tests/ClerkAuth.svelte.test.js +202 -0
  57. package/dist/svelte/tests/TestClerkAuthWrapper.svelte +16 -0
  58. package/dist/svelte/tests/TestClerkAuthWrapper.svelte.d.ts +8 -0
  59. package/dist/svelte/tests/TestClerkAuthWrapper.svelte.d.ts.map +1 -0
  60. package/dist/svelte/tests/testUtils.d.ts +1 -0
  61. package/dist/svelte/tests/testUtils.d.ts.map +1 -1
  62. package/dist/svelte/tests/testUtils.js +3 -1
  63. package/dist/testing.js +1 -1
  64. package/dist/tools/auth/clerk/index.d.ts +1 -1
  65. package/dist/tools/auth/clerk/types.d.ts +1 -1
  66. package/dist/tools/auth/clerk/types.d.ts.map +1 -1
  67. package/dist/tools/exports.d.ts +1 -0
  68. package/dist/tools/exports.d.ts.map +1 -1
  69. package/dist/tools/subscribe/types.d.ts +1 -1
  70. package/dist/tools/subscribe/types.d.ts.map +1 -1
  71. package/dist/worker/JazzMessageChannel.d.ts +36 -0
  72. package/dist/worker/JazzMessageChannel.d.ts.map +1 -0
  73. package/dist/worker/index.d.ts +7 -1
  74. package/dist/worker/index.d.ts.map +1 -1
  75. package/dist/worker/index.js +28 -17
  76. package/dist/worker/index.js.map +1 -1
  77. package/package.json +4 -4
  78. package/src/better-auth/auth/server.ts +9 -7
  79. package/src/better-auth/database-adapter/repository/generic.ts +3 -3
  80. package/src/better-auth/database-adapter/repository/session.ts +2 -2
  81. package/src/better-auth/database-adapter/schema.ts +5 -5
  82. package/src/media/create-image/react-native.ts +9 -7
  83. package/src/media/create-image-factory.test.ts +1 -1
  84. package/src/media/create-image-factory.ts +1 -1
  85. package/src/react/hooks.tsx +4 -2
  86. package/src/react-core/hooks.ts +321 -76
  87. package/src/react-core/tests/testUtils.tsx +2 -2
  88. package/src/react-core/tests/useCoState.selector.test.ts +309 -22
  89. package/src/react-core/tests/useCoStates.test.tsx +414 -0
  90. package/src/react-native-core/hooks.tsx +2 -0
  91. package/src/svelte/auth/ClerkAuth.svelte.ts +67 -0
  92. package/src/svelte/auth/JazzSvelteProviderWithClerk.svelte +156 -0
  93. package/src/svelte/auth/RegisterClerkAuth.svelte +27 -0
  94. package/src/svelte/auth/index.ts +2 -0
  95. package/src/svelte/tests/ClerkAuth.svelte.test.ts +305 -0
  96. package/src/svelte/tests/TestClerkAuthWrapper.svelte +16 -0
  97. package/src/svelte/tests/testUtils.ts +4 -1
  98. package/src/tools/auth/clerk/types.ts +1 -1
  99. package/src/tools/exports.ts +5 -0
  100. package/src/tools/subscribe/types.ts +1 -1
  101. package/src/tools/tests/inbox.test.ts +7 -7
  102. package/src/tools/tests/testStorage.ts +2 -2
  103. package/src/worker/JazzMessageChannel.ts +73 -0
  104. package/src/worker/index.ts +36 -17
  105. package/dist/chunk-MI24YFCY.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/better-auth/auth/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,gBAAgB,EAGtB,MAAM,aAAa,CAAC;AASrB,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"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/better-auth/auth/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,gBAAgB,EAGtB,MAAM,aAAa,CAAC;AASrB,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,UA4Q9B,CAAC"}
@@ -123,8 +123,9 @@ export const jazzPlugin = () => {
123
123
  */
124
124
  {
125
125
  matcher: (context) => {
126
- return (context.path.startsWith("/callback") ||
127
- context.path.startsWith("/oauth2/callback"));
126
+ return (context.path?.startsWith("/callback") ||
127
+ context.path?.startsWith("/oauth2/callback") ||
128
+ false);
128
129
  },
129
130
  handler: createAuthMiddleware(async (ctx) => {
130
131
  const state = ctx.query?.state || ctx.body?.state;
@@ -159,7 +160,7 @@ export const jazzPlugin = () => {
159
160
  */
160
161
  {
161
162
  matcher: (context) => {
162
- return context.path.startsWith("/sign-in/email-otp");
163
+ return context.path?.startsWith("/sign-in/email-otp") || false;
163
164
  },
164
165
  handler: createAuthMiddleware(async (ctx) => {
165
166
  const email = ctx.body.email;
@@ -196,9 +197,10 @@ export const jazzPlugin = () => {
196
197
  */
197
198
  {
198
199
  matcher: (context) => {
199
- return (context.path.startsWith("/sign-up") ||
200
- context.path.startsWith("/sign-in") ||
201
- context.path.startsWith("/get-session"));
200
+ return (context.path?.startsWith("/sign-up") ||
201
+ context.path?.startsWith("/sign-in") ||
202
+ context.path?.startsWith("/get-session") ||
203
+ false);
202
204
  },
203
205
  handler: createAuthMiddleware({}, async (ctx) => {
204
206
  const returned = ctx.context.returned;
@@ -218,7 +220,7 @@ export const jazzPlugin = () => {
218
220
  */
219
221
  {
220
222
  matcher: (context) => {
221
- return context.path.startsWith("/sign-in/social");
223
+ return context.path?.startsWith("/sign-in/social") || false;
222
224
  },
223
225
  handler: createAuthMiddleware(async (ctx) => {
224
226
  if (!contextContainsJazzAuth(ctx)) {
@@ -1,5 +1,5 @@
1
1
 
2
- > jazz-tools@0.19.20 build /home/runner/_work/jazz/jazz/packages/jazz-tools
2
+ > jazz-tools@0.19.22 build /home/runner/_work/jazz/jazz/packages/jazz-tools
3
3
  > tsup && pnpm types && pnpm build:svelte && pnpm build:better-auth-svelte
4
4
 
5
5
  CLI Building entry: {"index":"src/index.ts","testing":"src/testing.ts","tools/ssr":"src/tools/ssr/index.ts"}
@@ -110,121 +110,121 @@
110
110
  ESM dist/tiptap/index.js 564.00 B
111
111
  ESM dist/tiptap/index.js.map 1.21 KB
112
112
  ESM ⚡️ Build success in 33ms
113
- ESM dist/worker/index.js 3.19 KB
113
+ ESM dist/worker/index.js 3.45 KB
114
114
  ESM dist/worker/napi-crypto.js 110.00 B
115
115
  ESM dist/worker/edge-wasm.js 215.00 B
116
- ESM dist/worker/index.js.map 6.26 KB
116
+ ESM dist/worker/index.js.map 6.97 KB
117
117
  ESM dist/worker/napi-crypto.js.map 162.00 B
118
118
  ESM dist/worker/edge-wasm.js.map 434.00 B
119
119
  ESM ⚡️ Build success in 32ms
120
120
  ESM dist/better-auth/auth/client.js 4.54 KB
121
- ESM dist/better-auth/auth/server.js 8.36 KB
121
+ ESM dist/better-auth/auth/server.js 8.40 KB
122
122
  ESM dist/better-auth/auth/react.js 799.00 B
123
123
  ESM dist/better-auth/auth/client.js.map 8.44 KB
124
- ESM dist/better-auth/auth/server.js.map 15.31 KB
125
124
  ESM dist/better-auth/auth/react.js.map 2.04 KB
126
- ESM ⚡️ Build success in 29ms
125
+ ESM dist/better-auth/auth/server.js.map 15.40 KB
126
+ ESM ⚡️ Build success in 30ms
127
127
  ESM dist/media/index.js 236.00 B
128
128
  ESM dist/media/index.browser.js 2.79 KB
129
- ESM dist/media/index.native.js 4.01 KB
129
+ ESM dist/media/index.native.js 4.04 KB
130
130
  ESM dist/media/index.server.js 2.95 KB
131
- ESM dist/media/chunk-3LKBM3G3.js 6.69 KB
131
+ ESM dist/media/chunk-IRL3KNPO.js 6.70 KB
132
132
  ESM dist/media/index.js.map 71.00 B
133
133
  ESM dist/media/index.browser.js.map 6.15 KB
134
- ESM dist/media/index.native.js.map 8.10 KB
135
134
  ESM dist/media/index.server.js.map 6.37 KB
136
- ESM dist/media/chunk-3LKBM3G3.js.map 16.99 KB
137
- ESM ⚡️ Build success in 37ms
138
- ESM dist/react-core/index.js 15.29 KB
139
- ESM dist/react-core/testing.js 1.22 KB
140
- ESM dist/react-core/chunk-7DYMJ74I.js 279.00 B
141
- ESM dist/react-core/index.js.map 46.65 KB
142
- ESM dist/react-core/testing.js.map 1.86 KB
143
- ESM dist/react-core/chunk-7DYMJ74I.js.map 533.00 B
144
- ESM ⚡️ Build success in 37ms
135
+ ESM dist/media/index.native.js.map 8.17 KB
136
+ ESM dist/media/chunk-IRL3KNPO.js.map 17.00 KB
137
+ ESM ⚡️ Build success in 44ms
145
138
  ESM dist/expo/index.js 4.68 KB
146
- ESM dist/expo/testing.js 112.00 B
147
139
  ESM dist/expo/crypto.js 153.00 B
148
140
  ESM dist/expo/polyfills.js 858.00 B
141
+ ESM dist/expo/testing.js 112.00 B
149
142
  ESM dist/expo/index.js.map 10.23 KB
143
+ ESM dist/expo/polyfills.js.map 1.61 KB
150
144
  ESM dist/expo/testing.js.map 168.00 B
151
145
  ESM dist/expo/crypto.js.map 189.00 B
152
- ESM dist/expo/polyfills.js.map 1.61 KB
153
- ESM ⚡️ Build success in 42ms
146
+ ESM ⚡️ Build success in 47ms
147
+ ESM dist/react-core/index.js 17.37 KB
148
+ ESM dist/react-core/testing.js 1.22 KB
149
+ ESM dist/react-core/chunk-7DYMJ74I.js 279.00 B
150
+ ESM dist/react-core/index.js.map 57.58 KB
151
+ ESM dist/react-core/testing.js.map 1.86 KB
152
+ ESM dist/react-core/chunk-7DYMJ74I.js.map 533.00 B
153
+ ESM ⚡️ Build success in 53ms
154
+ ESM dist/prosemirror/index.js 77.76 KB
155
+ ESM dist/prosemirror/index.js.map 307.20 KB
156
+ ESM ⚡️ Build success in 74ms
157
+ ESM dist/better-auth/database-adapter/index.js 26.65 KB
158
+ ESM dist/better-auth/database-adapter/index.js.map 58.27 KB
159
+ ESM ⚡️ Build success in 63ms
154
160
  ESM dist/browser/index.js 16.26 KB
155
161
  ESM dist/browser/index.js.map 34.88 KB
156
- ESM ⚡️ Build success in 60ms
157
- ESM dist/better-auth/database-adapter/index.js 26.65 KB
158
- ESM dist/better-auth/database-adapter/index.js.map 58.26 KB
159
- ESM ⚡️ Build success in 59ms
160
- ESM dist/react/index.js 25.96 KB
162
+ ESM ⚡️ Build success in 77ms
163
+ ESM dist/react/index.js 26.00 KB
161
164
  ESM dist/react/testing.js 122.00 B
162
165
  ESM dist/react/ssr.js 697.00 B
163
166
  ESM dist/react/testing.js.map 165.00 B
164
167
  ESM dist/react/ssr.js.map 1.11 KB
165
- ESM dist/react/index.js.map 55.44 KB
166
- ESM ⚡️ Build success in 62ms
167
- ESM dist/prosemirror/index.js 77.76 KB
168
- ESM dist/prosemirror/index.js.map 307.20 KB
169
- ESM ⚡️ Build success in 71ms
170
- ESM dist/react-native-core/index.js 34.07 KB
168
+ ESM dist/react/index.js.map 55.47 KB
169
+ ESM ⚡️ Build success in 65ms
170
+ ESM dist/react-native-core/index.js 34.14 KB
171
171
  ESM dist/react-native-core/testing.js 119.00 B
172
- ESM dist/react-native-core/chunk-DGUM43GV.js 432.00 B
173
172
  ESM dist/react-native-core/crypto.js 2.61 KB
173
+ ESM dist/react-native-core/chunk-DGUM43GV.js 432.00 B
174
174
  ESM dist/react-native-core/crypto/RNCrypto.js 120.00 B
175
175
  ESM dist/react-native-core/testing.js.map 175.00 B
176
- ESM dist/react-native-core/crypto/RNCrypto.js.map 178.00 B
177
176
  ESM dist/react-native-core/crypto.js.map 5.26 KB
177
+ ESM dist/react-native-core/crypto/RNCrypto.js.map 178.00 B
178
178
  ESM dist/react-native-core/chunk-DGUM43GV.js.map 71.00 B
179
- ESM dist/react-native-core/index.js.map 69.18 KB
180
- ESM ⚡️ Build success in 68ms
181
- ESM dist/react-native/chunk-DGUM43GV.js 432.00 B
179
+ ESM dist/react-native-core/index.js.map 69.24 KB
180
+ ESM ⚡️ Build success in 71ms
181
+ ESM dist/react-native/index.js 36.68 KB
182
182
  ESM dist/react-native/testing.js 120.00 B
183
183
  ESM dist/react-native/crypto.js 192.00 B
184
- ESM dist/react-native/index.js 36.61 KB
184
+ ESM dist/react-native/chunk-DGUM43GV.js 432.00 B
185
185
  ESM dist/react-native/polyfills.js 858.00 B
186
- ESM dist/react-native/testing.js.map 176.00 B
186
+ ESM dist/react-native/index.js.map 74.79 KB
187
187
  ESM dist/react-native/chunk-DGUM43GV.js.map 71.00 B
188
- ESM dist/react-native/crypto.js.map 199.00 B
189
- ESM dist/react-native/index.js.map 74.73 KB
188
+ ESM dist/react-native/testing.js.map 176.00 B
190
189
  ESM dist/react-native/polyfills.js.map 1.61 KB
191
- ESM ⚡️ Build success in 71ms
190
+ ESM dist/react-native/crypto.js.map 199.00 B
191
+ ESM ⚡️ Build success in 81ms
192
+ ESM dist/inspector/index.js 6.29 KB
192
193
  ESM dist/inspector/standalone.js 12.61 KB
193
194
  ESM dist/inspector/chunk-YQNK5Y7B.js 127.21 KB
194
- ESM dist/inspector/index.js 6.29 KB
195
- ESM dist/inspector/standalone.js.map 20.11 KB
196
195
  ESM dist/inspector/index.js.map 9.65 KB
196
+ ESM dist/inspector/standalone.js.map 20.11 KB
197
197
  ESM dist/inspector/chunk-YQNK5Y7B.js.map 221.30 KB
198
- ESM ⚡️ Build success in 88ms
199
- ESM dist/index.js 30.81 KB
198
+ ESM ⚡️ Build success in 98ms
200
199
  ESM dist/testing.js 8.56 KB
201
- ESM dist/tools/ssr.js 156.00 B
202
200
  ESM dist/chunk-M2HGBOXS.js 694.00 B
201
+ ESM dist/tools/ssr.js 156.00 B
203
202
  ESM dist/chunk-PZ5AY32C.js 233.00 B
204
- ESM dist/chunk-MI24YFCY.js 228.88 KB
205
- ESM dist/index.js.map 62.37 KB
203
+ ESM dist/index.js 32.14 KB
204
+ ESM dist/chunk-QCTQH5RS.js 228.88 KB
206
205
  ESM dist/testing.js.map 16.21 KB
207
206
  ESM dist/chunk-M2HGBOXS.js.map 1.10 KB
208
- ESM dist/tools/ssr.js.map 71.00 B
209
207
  ESM dist/chunk-PZ5AY32C.js.map 71.00 B
210
- ESM dist/chunk-MI24YFCY.js.map 536.60 KB
211
- ESM ⚡️ Build success in 104ms
208
+ ESM dist/tools/ssr.js.map 71.00 B
209
+ ESM dist/index.js.map 65.34 KB
210
+ ESM dist/chunk-QCTQH5RS.js.map 536.59 KB
211
+ ESM ⚡️ Build success in 140ms
212
212
  ESM dist/inspector/register-custom-element.js 218.00 B
213
213
  ESM dist/inspector/register-custom-element.js.map 314.00 B
214
214
  ESM dist/inspector/custom-element-KYV64IOC.js 1.60 MB
215
215
  ESM dist/inspector/custom-element-KYV64IOC.js.map 2.47 MB
216
- ESM ⚡️ Build success in 138ms
216
+ ESM ⚡️ Build success in 151ms
217
217
 
218
- > jazz-tools@0.19.20 types /home/runner/_work/jazz/jazz/packages/jazz-tools
218
+ > jazz-tools@0.19.22 types /home/runner/_work/jazz/jazz/packages/jazz-tools
219
219
  > tsc --outDir dist
220
220
 
221
221
 
222
- > jazz-tools@0.19.20 build:svelte /home/runner/_work/jazz/jazz/packages/jazz-tools
222
+ > jazz-tools@0.19.22 build:svelte /home/runner/_work/jazz/jazz/packages/jazz-tools
223
223
  > rm -rf dist/svelte && svelte-package -i src/svelte -o dist/svelte --tsconfig tsconfig.svelte.json
224
224
 
225
225
  src/svelte -> dist/svelte
226
226
 
227
- > jazz-tools@0.19.20 build:better-auth-svelte /home/runner/_work/jazz/jazz/packages/jazz-tools
227
+ > jazz-tools@0.19.22 build:better-auth-svelte /home/runner/_work/jazz/jazz/packages/jazz-tools
228
228
  > mkdir -p dist/better-auth/auth && svelte-package -i src/better-auth/auth -o dist/better-auth/auth-temp --tsconfig tsconfig.svelte.json && cp dist/better-auth/auth-temp/svelte.svelte dist/better-auth/auth/svelte.svelte && cp dist/better-auth/auth-temp/svelte.svelte.d.ts dist/better-auth/auth/svelte.d.ts && rm -rf dist/better-auth/auth-temp
229
229
 
230
230
  src/better-auth/auth -> dist/better-auth/auth-temp
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # jazz-tools
2
2
 
3
+ ## 0.19.22
4
+
5
+ ### Patch Changes
6
+
7
+ - 89d8798: Adds a 512 variant for progressive image loading.
8
+ - 30b5339: Fix an issue when generating image placeholders from clients using Expo Image Manipulator
9
+ - Updated dependencies [3b70482]
10
+ - Updated dependencies [6078ea5]
11
+ - cojson@0.19.22
12
+ - cojson-storage-indexeddb@0.19.22
13
+ - cojson-transport-ws@0.19.22
14
+
3
15
  ## 0.19.19
4
16
 
5
17
  ### Patch Changes
@@ -465,6 +477,7 @@
465
477
  ### Patch Changes
466
478
 
467
479
  - f2f478a: Add connection status API for React and Svelte
480
+
468
481
  - **React**: Added `useSyncConnectionStatus()` hook that returns the current connection status to the Jazz sync server
469
482
  - **Svelte**: Added `SyncConnectionStatus` class that provides reactive connection status monitoring
470
483
 
@@ -500,6 +513,7 @@
500
513
  ### Patch Changes
501
514
 
502
515
  - a584ab3: Add WasmCrypto support for Cloudflare Workers and edge runtimes by importing `jazz-tools/load-edge-wasm`.
516
+
503
517
  - Enable WasmCrypto functionality by initializing the WebAssembly environment with the import: `import "jazz-tools/load-edge-wasm"` in edge runtimes.
504
518
  - Guarantee compatibility across Cloudflare Workers and other edge runtime environments.
505
519
 
@@ -883,6 +897,7 @@
883
897
  - 3cd1586: Makes the key rotation not fail when child groups are unavailable or their readkey is not accessible.
884
898
 
885
899
  Also changes the Group.removeMember method to not return a Promise, because:
900
+
886
901
  - All the locally available child groups are rotated immediately
887
902
  - All the remote child groups are rotated in background, but since they are not locally available the user won't need the new key immediately
888
903
 
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/better-auth/auth/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,gBAAgB,EAGtB,MAAM,aAAa,CAAC;AASrB,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"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/better-auth/auth/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,gBAAgB,EAGtB,MAAM,aAAa,CAAC;AASrB,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,UA4Q9B,CAAC"}
@@ -109,7 +109,7 @@ var jazzPlugin = () => {
109
109
  */
110
110
  {
111
111
  matcher: (context) => {
112
- return context.path.startsWith("/callback") || context.path.startsWith("/oauth2/callback");
112
+ return context.path?.startsWith("/callback") || context.path?.startsWith("/oauth2/callback") || false;
113
113
  },
114
114
  handler: createAuthMiddleware(async (ctx) => {
115
115
  const state = ctx.query?.state || ctx.body?.state;
@@ -144,7 +144,7 @@ var jazzPlugin = () => {
144
144
  */
145
145
  {
146
146
  matcher: (context) => {
147
- return context.path.startsWith("/sign-in/email-otp");
147
+ return context.path?.startsWith("/sign-in/email-otp") || false;
148
148
  },
149
149
  handler: createAuthMiddleware(async (ctx) => {
150
150
  const email = ctx.body.email;
@@ -181,7 +181,7 @@ var jazzPlugin = () => {
181
181
  */
182
182
  {
183
183
  matcher: (context) => {
184
- return context.path.startsWith("/sign-up") || context.path.startsWith("/sign-in") || context.path.startsWith("/get-session");
184
+ return context.path?.startsWith("/sign-up") || context.path?.startsWith("/sign-in") || context.path?.startsWith("/get-session") || false;
185
185
  },
186
186
  handler: createAuthMiddleware({}, async (ctx) => {
187
187
  const returned = ctx.context.returned;
@@ -201,7 +201,7 @@ var jazzPlugin = () => {
201
201
  */
202
202
  {
203
203
  matcher: (context) => {
204
- return context.path.startsWith("/sign-in/social");
204
+ return context.path?.startsWith("/sign-in/social") || false;
205
205
  },
206
206
  handler: createAuthMiddleware(async (ctx) => {
207
207
  if (!contextContainsJazzAuth(ctx)) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/better-auth/auth/server.ts"],"sourcesContent":["import {\n AuthContext,\n type BetterAuthPlugin,\n MiddlewareContext,\n MiddlewareOptions,\n} from \"better-auth\";\nimport { APIError } from \"better-auth/api\";\nimport { symmetricDecrypt, symmetricEncrypt } from \"better-auth/crypto\";\nimport { 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":";AAMA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB,wBAAwB;AACnD,SAAS,4BAA4B;AAqC9B,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,cAAc;AAAA,cACZ,QAAQ;AAAA,gBACN,OAAO,OAAO,cAAc,YAAY;AAMtC,sBACE,wBAAwB,OAAO,KAC/B,aAAa,WAAW,WAAW,cAAc,GAC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AA,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 {\n AuthContext,\n type BetterAuthPlugin,\n MiddlewareContext,\n MiddlewareOptions,\n} from \"better-auth\";\nimport { APIError } from \"better-auth/api\";\nimport { symmetricDecrypt, symmetricEncrypt } from \"better-auth/crypto\";\nimport { 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 false\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\") || false;\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 false\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\") || false;\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":";AAMA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB,wBAAwB;AACnD,SAAS,4BAA4B;AAqC9B,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,cAAc;AAAA,cACZ,QAAQ;AAAA,gBACN,OAAO,OAAO,cAAc,YAAY;AAMtC,sBACE,wBAAwB,OAAO,KAC/B,aAAa,WAAW,WAAW,cAAc,GACjD;AACA,0BAAM,aAAa,aAAa,aAAa,UAAU;AACvD,0BAAM,QAAQ,QAAQ,gBAAgB;AAAA,sBACpC;AAAA,oBACF;AACA,0BAAM,QAAQ,QAAQ,gBAAgB;AAAA,sBACpC;AAAA,wB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