jazz-tools 0.19.6 → 0.19.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 (111) hide show
  1. package/.turbo/turbo-build.log +51 -47
  2. package/CHANGELOG.md +24 -0
  3. package/dist/{chunk-GCBXV2KC.js → chunk-2S3Z2CN6.js} +122 -53
  4. package/dist/chunk-2S3Z2CN6.js.map +1 -0
  5. package/dist/expo/polyfills.js +22 -0
  6. package/dist/expo/polyfills.js.map +1 -0
  7. package/dist/index.js +26 -6
  8. package/dist/index.js.map +1 -1
  9. package/dist/react-core/hooks.d.ts.map +1 -1
  10. package/dist/react-core/index.js +17 -6
  11. package/dist/react-core/index.js.map +1 -1
  12. package/dist/react-native/index.d.ts +1 -1
  13. package/dist/react-native/index.d.ts.map +1 -1
  14. package/dist/react-native/index.js +713 -9
  15. package/dist/react-native/index.js.map +1 -1
  16. package/dist/react-native/polyfills.js +22 -0
  17. package/dist/react-native/polyfills.js.map +1 -0
  18. package/dist/react-native-core/index.d.ts.map +1 -1
  19. package/dist/react-native-core/index.js.map +1 -1
  20. package/dist/testing.js +1 -1
  21. package/dist/tools/coValues/account.d.ts +3 -3
  22. package/dist/tools/coValues/account.d.ts.map +1 -1
  23. package/dist/tools/coValues/coFeed.d.ts +3 -3
  24. package/dist/tools/coValues/coFeed.d.ts.map +1 -1
  25. package/dist/tools/coValues/coList.d.ts +4 -4
  26. package/dist/tools/coValues/coList.d.ts.map +1 -1
  27. package/dist/tools/coValues/coMap.d.ts +7 -7
  28. package/dist/tools/coValues/coMap.d.ts.map +1 -1
  29. package/dist/tools/coValues/coPlainText.d.ts +2 -2
  30. package/dist/tools/coValues/coPlainText.d.ts.map +1 -1
  31. package/dist/tools/coValues/coVector.d.ts +2 -2
  32. package/dist/tools/coValues/coVector.d.ts.map +1 -1
  33. package/dist/tools/coValues/deepLoading.d.ts +24 -0
  34. package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
  35. package/dist/tools/coValues/group.d.ts +2 -2
  36. package/dist/tools/coValues/group.d.ts.map +1 -1
  37. package/dist/tools/coValues/interfaces.d.ts +6 -6
  38. package/dist/tools/coValues/interfaces.d.ts.map +1 -1
  39. package/dist/tools/coValues/schemaUnion.d.ts +2 -2
  40. package/dist/tools/coValues/schemaUnion.d.ts.map +1 -1
  41. package/dist/tools/config.d.ts +3 -0
  42. package/dist/tools/config.d.ts.map +1 -0
  43. package/dist/tools/exports.d.ts +2 -0
  44. package/dist/tools/exports.d.ts.map +1 -1
  45. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +2 -2
  46. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
  47. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts +2 -2
  48. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts.map +1 -1
  49. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +2 -2
  50. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
  51. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +4 -4
  52. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
  53. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +4 -4
  54. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
  55. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +4 -4
  56. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
  57. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +2 -2
  58. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
  59. package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts +2 -2
  60. package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts.map +1 -1
  61. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +2 -2
  62. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
  63. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +2 -2
  64. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
  65. package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
  66. package/dist/tools/subscribe/JazzError.d.ts.map +1 -1
  67. package/dist/tools/subscribe/SubscriptionScope.d.ts +10 -1
  68. package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
  69. package/dist/tools/subscribe/errorReporting.d.ts +31 -0
  70. package/dist/tools/subscribe/errorReporting.d.ts.map +1 -0
  71. package/dist/tools/testing.d.ts.map +1 -1
  72. package/dist/tools/tests/errorReporting.test.d.ts +2 -0
  73. package/dist/tools/tests/errorReporting.test.d.ts.map +1 -0
  74. package/package.json +13 -5
  75. package/src/react-core/hooks.ts +16 -0
  76. package/src/react-native/index.ts +1 -1
  77. package/src/react-native-core/index.ts +2 -0
  78. package/src/react-native-core/polyfills/index.js +28 -0
  79. package/src/tools/coValues/account.ts +3 -4
  80. package/src/tools/coValues/coFeed.ts +3 -2
  81. package/src/tools/coValues/coList.ts +4 -4
  82. package/src/tools/coValues/coMap.ts +4 -4
  83. package/src/tools/coValues/coPlainText.ts +2 -2
  84. package/src/tools/coValues/coVector.ts +2 -2
  85. package/src/tools/coValues/deepLoading.ts +31 -0
  86. package/src/tools/coValues/group.ts +2 -2
  87. package/src/tools/coValues/interfaces.ts +19 -23
  88. package/src/tools/coValues/schemaUnion.ts +2 -2
  89. package/src/tools/config.ts +9 -0
  90. package/src/tools/exports.ts +4 -0
  91. package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +2 -2
  92. package/src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts +2 -2
  93. package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +2 -2
  94. package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +4 -4
  95. package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +4 -4
  96. package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +4 -10
  97. package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +2 -2
  98. package/src/tools/implementation/zodSchema/schemaTypes/GroupSchema.ts +2 -2
  99. package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +2 -2
  100. package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +2 -2
  101. package/src/tools/subscribe/JazzError.ts +9 -6
  102. package/src/tools/subscribe/SubscriptionScope.ts +126 -36
  103. package/src/tools/subscribe/errorReporting.ts +67 -0
  104. package/src/tools/tests/coDiscriminatedUnion.test.ts +69 -2
  105. package/src/tools/tests/deepLoading.test.ts +47 -47
  106. package/src/tools/tests/errorReporting.test.ts +103 -0
  107. package/src/tools/tests/load.test.ts +21 -1
  108. package/src/tools/tests/request.test.ts +2 -1
  109. package/src/tools/tests/subscribe.test.ts +44 -0
  110. package/tsup.config.ts +16 -0
  111. package/dist/chunk-GCBXV2KC.js.map +0 -1
@@ -1,11 +1,688 @@
1
- // src/react-native/index.ts
2
- export * from "jazz-tools/react-native-core";
1
+ // src/react-native-core/storage/kv-store-context.ts
2
+ var KvStoreContext = class _KvStoreContext {
3
+ constructor() {
4
+ this.storageInstance = null;
5
+ }
6
+ static getInstance() {
7
+ if (!_KvStoreContext.instance) {
8
+ _KvStoreContext.instance = new _KvStoreContext();
9
+ }
10
+ return _KvStoreContext.instance;
11
+ }
12
+ isInitialized() {
13
+ return this.storageInstance !== null;
14
+ }
15
+ initialize(store) {
16
+ if (!this.storageInstance) {
17
+ this.storageInstance = store;
18
+ }
19
+ }
20
+ getStorage() {
21
+ if (!this.storageInstance) {
22
+ throw new Error("Storage instance is not initialized.");
23
+ }
24
+ return this.storageInstance;
25
+ }
26
+ };
27
+
28
+ // src/react-native-core/auth/DemoAuthUI.tsx
29
+ import { useState } from "react";
30
+ import {
31
+ StyleSheet,
32
+ Text,
33
+ TextInput,
34
+ TouchableOpacity,
35
+ View,
36
+ useColorScheme
37
+ } from "react-native";
38
+ import { jsx, jsxs } from "react/jsx-runtime";
39
+ var DemoAuthBasicUI = ({
40
+ appName,
41
+ auth,
42
+ children
43
+ }) => {
44
+ const colorScheme = useColorScheme();
45
+ const darkMode = colorScheme === "dark";
46
+ const [username, setUsername] = useState("");
47
+ const [errorMessage, setErrorMessage] = useState(null);
48
+ const handleSignUp = () => {
49
+ setErrorMessage(null);
50
+ auth.signUp(username).catch((error) => {
51
+ setErrorMessage(error.message);
52
+ });
53
+ };
54
+ const handleLogIn = (username2) => {
55
+ setErrorMessage(null);
56
+ auth.logIn(username2).catch((error) => {
57
+ setErrorMessage(error.message);
58
+ });
59
+ };
60
+ if (auth.state === "signedIn") {
61
+ return children;
62
+ }
63
+ return /* @__PURE__ */ jsx(
64
+ View,
65
+ {
66
+ style: [
67
+ styles.container,
68
+ darkMode ? styles.darkBackground : styles.lightBackground
69
+ ],
70
+ children: /* @__PURE__ */ jsxs(View, { style: styles.formContainer, children: [
71
+ /* @__PURE__ */ jsx(
72
+ Text,
73
+ {
74
+ style: [
75
+ styles.headerText,
76
+ darkMode ? styles.darkText : styles.lightText
77
+ ],
78
+ children: appName
79
+ }
80
+ ),
81
+ errorMessage && /* @__PURE__ */ jsx(Text, { style: styles.errorText, children: errorMessage }),
82
+ /* @__PURE__ */ jsx(
83
+ TextInput,
84
+ {
85
+ placeholder: "Display name",
86
+ value: username,
87
+ onChangeText: setUsername,
88
+ placeholderTextColor: darkMode ? "#fff" : "#000",
89
+ style: [
90
+ styles.textInput,
91
+ darkMode ? styles.darkInput : styles.lightInput
92
+ ]
93
+ }
94
+ ),
95
+ /* @__PURE__ */ jsx(
96
+ TouchableOpacity,
97
+ {
98
+ onPress: handleSignUp,
99
+ style: [
100
+ styles.button,
101
+ darkMode ? styles.darkButton : styles.lightButton
102
+ ],
103
+ children: /* @__PURE__ */ jsx(
104
+ Text,
105
+ {
106
+ style: darkMode ? styles.darkButtonText : styles.lightButtonText,
107
+ children: "Sign Up as new account"
108
+ }
109
+ )
110
+ }
111
+ ),
112
+ /* @__PURE__ */ jsx(View, { style: styles.existingUsersContainer, children: auth.existingUsers.map((user) => /* @__PURE__ */ jsx(
113
+ TouchableOpacity,
114
+ {
115
+ onPress: () => handleLogIn(user),
116
+ style: [
117
+ styles.existingUserButton,
118
+ darkMode ? styles.darkUserButton : styles.lightUserButton
119
+ ],
120
+ children: /* @__PURE__ */ jsxs(Text, { style: darkMode ? styles.darkText : styles.lightText, children: [
121
+ 'Log In as "',
122
+ user,
123
+ '"'
124
+ ] })
125
+ },
126
+ user
127
+ )) })
128
+ ] })
129
+ }
130
+ );
131
+ };
132
+ var styles = StyleSheet.create({
133
+ container: {
134
+ flex: 1,
135
+ justifyContent: "center",
136
+ alignItems: "center",
137
+ padding: 20
138
+ },
139
+ formContainer: {
140
+ width: "80%",
141
+ alignItems: "center",
142
+ justifyContent: "center"
143
+ },
144
+ headerText: {
145
+ fontSize: 24,
146
+ marginBottom: 20
147
+ },
148
+ errorText: {
149
+ color: "red",
150
+ marginVertical: 5,
151
+ textAlign: "center"
152
+ },
153
+ textInput: {
154
+ borderWidth: 1,
155
+ padding: 10,
156
+ marginVertical: 10,
157
+ width: "100%",
158
+ borderRadius: 6
159
+ },
160
+ darkInput: {
161
+ borderColor: "#444",
162
+ backgroundColor: "#000",
163
+ color: "#fff"
164
+ },
165
+ lightInput: {
166
+ borderColor: "#ddd",
167
+ backgroundColor: "#fff",
168
+ color: "#000"
169
+ },
170
+ button: {
171
+ paddingVertical: 15,
172
+ paddingHorizontal: 10,
173
+ borderRadius: 6,
174
+ width: "100%",
175
+ marginVertical: 10
176
+ },
177
+ darkButton: {
178
+ backgroundColor: "#444"
179
+ },
180
+ lightButton: {
181
+ backgroundColor: "#ddd"
182
+ },
183
+ darkButtonText: {
184
+ color: "#fff",
185
+ textAlign: "center"
186
+ },
187
+ lightButtonText: {
188
+ color: "#000",
189
+ textAlign: "center"
190
+ },
191
+ existingUsersContainer: {
192
+ width: "100%",
193
+ marginTop: 20
194
+ },
195
+ existingUserButton: {
196
+ paddingVertical: 15,
197
+ paddingHorizontal: 10,
198
+ borderRadius: 6,
199
+ marginVertical: 5
200
+ },
201
+ darkUserButton: {
202
+ backgroundColor: "#222"
203
+ },
204
+ lightUserButton: {
205
+ backgroundColor: "#eee"
206
+ },
207
+ loadingText: {
208
+ fontSize: 18,
209
+ color: "#888"
210
+ },
211
+ darkText: {
212
+ color: "#fff"
213
+ },
214
+ lightText: {
215
+ color: "#000"
216
+ },
217
+ darkBackground: {
218
+ backgroundColor: "#000"
219
+ },
220
+ lightBackground: {
221
+ backgroundColor: "#fff"
222
+ }
223
+ });
224
+
225
+ // src/react-native-core/auth/auth.ts
226
+ function clearUserCredentials() {
227
+ const kvStore = KvStoreContext.getInstance().getStorage();
228
+ return Promise.all([
229
+ kvStore.delete("demo-auth-logged-in-secret"),
230
+ kvStore.delete("jazz-clerk-auth"),
231
+ kvStore.delete("jazz-logged-in-secret")
232
+ ]);
233
+ }
234
+
235
+ // src/react-native-core/hooks.tsx
236
+ import { useEffect } from "react";
237
+ import { parseInviteLink } from "jazz-tools";
238
+ import { useJazzContext } from "jazz-tools/react-core";
239
+ import { Linking } from "react-native";
240
+ import {
241
+ useCoState,
242
+ experimental_useInboxSender,
243
+ useDemoAuth,
244
+ usePassphraseAuth,
245
+ useJazzContext as useJazzContext2,
246
+ useAuthSecretStorage,
247
+ useIsAuthenticated,
248
+ useAccount,
249
+ useAgent,
250
+ useLogOut,
251
+ useSyncConnectionStatus,
252
+ useCoValueSubscription,
253
+ useAccountSubscription,
254
+ useSubscriptionSelector
255
+ } from "jazz-tools/react-core";
256
+ function useAcceptInviteNative({
257
+ invitedObjectSchema,
258
+ onAccept,
259
+ forValueHint
260
+ }) {
261
+ const context = useJazzContext();
262
+ if (!("me" in context)) {
263
+ throw new Error(
264
+ "useAcceptInviteNative can't be used in a JazzProvider with auth === 'guest'."
265
+ );
266
+ }
267
+ useEffect(() => {
268
+ const handleDeepLink = ({ url }) => {
269
+ const result = parseInviteLink(url);
270
+ if (result && result.valueHint === forValueHint) {
271
+ context.me.acceptInvite(
272
+ result.valueID,
273
+ result.inviteSecret,
274
+ invitedObjectSchema
275
+ ).then(() => {
276
+ onAccept(result.valueID);
277
+ }).catch((e) => {
278
+ console.error("Failed to accept invite", e);
279
+ });
280
+ }
281
+ };
282
+ const linkingListener = Linking.addEventListener("url", handleDeepLink);
283
+ void Linking.getInitialURL().then((url) => {
284
+ if (url) handleDeepLink({ url });
285
+ });
286
+ return () => {
287
+ linkingListener.remove();
288
+ };
289
+ }, [context, onAccept, invitedObjectSchema, forValueHint]);
290
+ }
291
+
292
+ // src/react-native-core/provider.tsx
293
+ import { JazzContext, JazzContextManagerContext } from "jazz-tools/react-core";
294
+ import React2, { useEffect as useEffect2, useRef } from "react";
295
+
296
+ // src/react-native-core/ReactNativeContextManager.ts
297
+ import {
298
+ JazzContextManager
299
+ } from "jazz-tools";
300
+
301
+ // src/react-native-core/platform.ts
302
+ import NetInfo from "@react-native-community/netinfo";
303
+ import { getSqliteStorageAsync } from "cojson";
304
+ import { PureJSCrypto } from "cojson/dist/crypto/PureJSCrypto";
305
+ import {
306
+ createInviteLink as baseCreateInviteLink,
307
+ createAnonymousJazzContext,
308
+ createJazzContext
309
+ } from "jazz-tools";
310
+ import { WebSocketPeerWithReconnection } from "cojson-transport-ws";
311
+ var ReactNativeWebSocketPeerWithReconnection = class extends WebSocketPeerWithReconnection {
312
+ onNetworkChange(callback) {
313
+ return NetInfo.addEventListener(
314
+ (state) => callback(state.isConnected ?? false)
315
+ );
316
+ }
317
+ };
318
+ async function setupPeers(options) {
319
+ const CryptoProvider2 = options.CryptoProvider || PureJSCrypto;
320
+ const crypto = await CryptoProvider2.create();
321
+ let node = void 0;
322
+ const peers = [];
323
+ const storage2 = options.storage && options.storage !== "disabled" ? await getSqliteStorageAsync(options.storage) : void 0;
324
+ if (options.sync.when === "never") {
325
+ return {
326
+ toggleNetwork: () => {
327
+ },
328
+ addConnectionListener: () => () => {
329
+ },
330
+ connected: () => false,
331
+ peers,
332
+ setNode: () => {
333
+ },
334
+ crypto,
335
+ storage: storage2
336
+ };
337
+ }
338
+ const wsPeer = new ReactNativeWebSocketPeerWithReconnection({
339
+ peer: options.sync.peer,
340
+ reconnectionTimeout: options.reconnectionTimeout,
341
+ addPeer: (peer) => {
342
+ if (node) {
343
+ node.syncManager.addPeer(peer);
344
+ } else {
345
+ peers.push(peer);
346
+ }
347
+ },
348
+ removePeer: (peer) => {
349
+ peers.splice(peers.indexOf(peer), 1);
350
+ }
351
+ });
352
+ function toggleNetwork(enabled) {
353
+ if (enabled) {
354
+ wsPeer.enable();
355
+ } else {
356
+ wsPeer.disable();
357
+ }
358
+ }
359
+ function setNode(value) {
360
+ node = value;
361
+ }
362
+ if (options.sync.when === "always" || !options.sync.when) {
363
+ toggleNetwork(true);
364
+ }
365
+ return {
366
+ toggleNetwork,
367
+ addConnectionListener(listener) {
368
+ wsPeer.subscribe(listener);
369
+ return () => {
370
+ wsPeer.unsubscribe(listener);
371
+ };
372
+ },
373
+ connected: () => wsPeer.connected,
374
+ peers,
375
+ setNode,
376
+ crypto,
377
+ storage: storage2
378
+ };
379
+ }
380
+ async function createJazzReactNativeGuestContext(options) {
381
+ const {
382
+ toggleNetwork,
383
+ peers,
384
+ setNode,
385
+ crypto,
386
+ storage: storage2,
387
+ addConnectionListener,
388
+ connected
389
+ } = await setupPeers(options);
390
+ const context = createAnonymousJazzContext({
391
+ crypto,
392
+ peers,
393
+ storage: storage2
394
+ });
395
+ setNode(context.agent.node);
396
+ options.authSecretStorage.emitUpdate(null);
397
+ return {
398
+ guest: context.agent,
399
+ node: context.agent.node,
400
+ done: () => {
401
+ toggleNetwork(false);
402
+ context.done();
403
+ },
404
+ logOut: () => {
405
+ return context.logOut();
406
+ },
407
+ addConnectionListener,
408
+ connected
409
+ };
410
+ }
411
+ async function createJazzReactNativeContext(options) {
412
+ const {
413
+ toggleNetwork,
414
+ peers,
415
+ setNode,
416
+ crypto,
417
+ storage: storage2,
418
+ addConnectionListener,
419
+ connected
420
+ } = await setupPeers(options);
421
+ let unsubscribeAuthUpdate = () => {
422
+ };
423
+ if (options.sync.when === "signedUp") {
424
+ let handleAuthUpdate2 = function(isAuthenticated) {
425
+ if (isAuthenticated) {
426
+ toggleNetwork(true);
427
+ } else {
428
+ toggleNetwork(false);
429
+ }
430
+ };
431
+ var handleAuthUpdate = handleAuthUpdate2;
432
+ const authSecretStorage = options.authSecretStorage;
433
+ const credentials = options.credentials ?? await authSecretStorage.get();
434
+ authSecretStorage.emitUpdate(credentials);
435
+ unsubscribeAuthUpdate = authSecretStorage.onUpdate(handleAuthUpdate2);
436
+ handleAuthUpdate2(authSecretStorage.isAuthenticated);
437
+ }
438
+ const context = await createJazzContext({
439
+ credentials: options.credentials,
440
+ newAccountProps: options.newAccountProps,
441
+ peers,
442
+ crypto,
443
+ defaultProfileName: options.defaultProfileName,
444
+ AccountSchema: options.AccountSchema,
445
+ sessionProvider: provideLockSession,
446
+ authSecretStorage: options.authSecretStorage,
447
+ storage: storage2
448
+ });
449
+ setNode(context.node);
450
+ return {
451
+ me: context.account,
452
+ node: context.node,
453
+ authSecretStorage: context.authSecretStorage,
454
+ done: () => {
455
+ toggleNetwork(false);
456
+ unsubscribeAuthUpdate();
457
+ context.done();
458
+ },
459
+ logOut: () => {
460
+ unsubscribeAuthUpdate();
461
+ return context.logOut();
462
+ },
463
+ addConnectionListener,
464
+ connected
465
+ };
466
+ }
467
+ async function provideLockSession(accountID, crypto) {
468
+ const sessionDone = () => {
469
+ };
470
+ const kvStore = KvStoreContext.getInstance().getStorage();
471
+ const sessionID = await kvStore.get(accountID) || crypto.newRandomSessionID(accountID);
472
+ await kvStore.set(accountID, sessionID);
473
+ return Promise.resolve({
474
+ sessionID,
475
+ sessionDone
476
+ });
477
+ }
478
+ function createInviteLink(value, role, { baseURL, valueHint } = {}) {
479
+ return baseCreateInviteLink(value, role, baseURL ?? "", valueHint);
480
+ }
481
+ function setupKvStore(kvStore) {
482
+ if (!kvStore) {
483
+ return void 0;
484
+ }
485
+ KvStoreContext.getInstance().initialize(kvStore);
486
+ return kvStore;
487
+ }
488
+
489
+ // src/react-native-core/ReactNativeContextManager.ts
490
+ var ReactNativeContextManager = class extends JazzContextManager {
491
+ async getNewContext(props, authProps) {
492
+ if (props.guestMode) {
493
+ return createJazzReactNativeGuestContext({
494
+ sync: props.sync,
495
+ storage: props.storage,
496
+ authSecretStorage: this.authSecretStorage,
497
+ CryptoProvider: props.CryptoProvider
498
+ });
499
+ } else {
500
+ return createJazzReactNativeContext({
501
+ sync: props.sync,
502
+ storage: props.storage,
503
+ AccountSchema: props.AccountSchema,
504
+ credentials: authProps?.credentials,
505
+ newAccountProps: authProps?.newAccountProps,
506
+ defaultProfileName: props.defaultProfileName,
507
+ authSecretStorage: this.authSecretStorage,
508
+ CryptoProvider: props.CryptoProvider
509
+ });
510
+ }
511
+ }
512
+ getKvStore() {
513
+ return KvStoreContext.getInstance().getStorage();
514
+ }
515
+ propsChanged(props) {
516
+ if (!this.props) {
517
+ return true;
518
+ }
519
+ return this.props.sync.when !== props.sync.when || this.props.sync.peer !== props.sync.peer || this.props.guestMode !== props.guestMode;
520
+ }
521
+ };
522
+
523
+ // src/react-native-core/provider.tsx
524
+ import { jsx as jsx2 } from "react/jsx-runtime";
525
+ function JazzProviderCore({
526
+ children,
527
+ guestMode,
528
+ sync,
529
+ storage: storage2,
530
+ AccountSchema,
531
+ defaultProfileName,
532
+ onLogOut,
533
+ logOutReplacement,
534
+ onAnonymousAccountDiscarded,
535
+ kvStore,
536
+ CryptoProvider: CryptoProvider2,
537
+ authSecretStorageKey
538
+ }) {
539
+ setupKvStore(kvStore);
540
+ const [contextManager] = React2.useState(
541
+ () => new ReactNativeContextManager({ authSecretStorageKey })
542
+ );
543
+ const onLogOutRefCallback = useRefCallback(onLogOut);
544
+ const logOutReplacementRefCallback = useRefCallback(logOutReplacement);
545
+ const onAnonymousAccountDiscardedRefCallback = useRefCallback(
546
+ onAnonymousAccountDiscarded
547
+ );
548
+ const logoutReplacementActiveRef = useRef(false);
549
+ logoutReplacementActiveRef.current = Boolean(logOutReplacement);
550
+ const value = React2.useSyncExternalStore(
551
+ React2.useCallback(
552
+ (callback) => {
553
+ const props = {
554
+ AccountSchema,
555
+ guestMode,
556
+ sync,
557
+ storage: storage2,
558
+ defaultProfileName,
559
+ onLogOut: onLogOutRefCallback,
560
+ logOutReplacement: logoutReplacementActiveRef.current ? logOutReplacementRefCallback : void 0,
561
+ onAnonymousAccountDiscarded: onAnonymousAccountDiscardedRefCallback,
562
+ CryptoProvider: CryptoProvider2
563
+ };
564
+ if (contextManager.propsChanged(props)) {
565
+ contextManager.createContext(props).catch((error) => {
566
+ console.log(error.stack);
567
+ console.error("Error creating Jazz React Native context:", error);
568
+ });
569
+ }
570
+ return contextManager.subscribe(callback);
571
+ },
572
+ [sync, guestMode].concat(storage2)
573
+ ),
574
+ () => contextManager.getCurrentValue(),
575
+ () => contextManager.getCurrentValue()
576
+ );
577
+ useEffect2(() => {
578
+ if (process.env.NODE_ENV === "development") return;
579
+ return () => {
580
+ contextManager.done();
581
+ };
582
+ }, []);
583
+ return /* @__PURE__ */ jsx2(JazzContext.Provider, { value, children: /* @__PURE__ */ jsx2(JazzContextManagerContext.Provider, { value: contextManager, children: value && children }) });
584
+ }
585
+ function useRefCallback(callback) {
586
+ const callbackRef = React2.useRef(callback);
587
+ callbackRef.current = callback;
588
+ return useRef(
589
+ (...args) => callbackRef.current?.(...args)
590
+ ).current;
591
+ }
592
+
593
+ // src/react-native-core/media/image.tsx
594
+ import { ImageDefinition } from "jazz-tools";
595
+ import { highestResAvailable } from "jazz-tools/media";
596
+ import { forwardRef, useEffect as useEffect3, useMemo, useState as useState2 } from "react";
597
+ import { Image as RNImage } from "react-native";
598
+ import { jsx as jsx3 } from "react/jsx-runtime";
599
+ var Image = forwardRef(function Image2({ imageId, width, height, placeholder, ...props }, ref) {
600
+ const image = useCoState(ImageDefinition, imageId, {
601
+ select: (image2) => image2.$isLoaded ? image2 : null
602
+ });
603
+ const [src, setSrc] = useState2(
604
+ image?.placeholderDataURL ?? "data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="
605
+ );
606
+ const dimensions = useMemo(() => {
607
+ const originalWidth = image?.originalSize?.[0];
608
+ const originalHeight = image?.originalSize?.[1];
609
+ if (width === "original" && height === "original") {
610
+ return { width: originalWidth, height: originalHeight };
611
+ }
612
+ if (width === "original" && typeof height === "number") {
613
+ if (originalWidth && originalHeight) {
614
+ return {
615
+ width: Math.round(height * originalWidth / originalHeight),
616
+ height
617
+ };
618
+ }
619
+ return { width: void 0, height };
620
+ }
621
+ if (height === "original" && typeof width === "number") {
622
+ if (originalWidth && originalHeight) {
623
+ return {
624
+ width,
625
+ height: Math.round(width * originalHeight / originalWidth)
626
+ };
627
+ }
628
+ return { width, height: void 0 };
629
+ }
630
+ return {
631
+ width: width === "original" ? originalWidth : width,
632
+ height: height === "original" ? originalHeight : height
633
+ };
634
+ }, [image?.originalSize, width, height]);
635
+ useEffect3(() => {
636
+ if (!image) return;
637
+ let lastBestImage = image?.placeholderDataURL ?? placeholder;
638
+ const unsub = image.$jazz.subscribe({}, (update) => {
639
+ if (lastBestImage === void 0 && update.placeholderDataURL) {
640
+ setSrc(update.placeholderDataURL);
641
+ lastBestImage = update.placeholderDataURL;
642
+ }
643
+ const bestImage = highestResAvailable(
644
+ update,
645
+ dimensions.width || dimensions.height || 9999,
646
+ dimensions.height || dimensions.width || 9999
647
+ );
648
+ if (!bestImage) return;
649
+ if (lastBestImage === bestImage.image) return;
650
+ const url = bestImage.image.asBase64({ dataURL: true });
651
+ if (url) {
652
+ setSrc(url);
653
+ lastBestImage = bestImage.image;
654
+ }
655
+ });
656
+ return unsub;
657
+ }, [image]);
658
+ if (!src) {
659
+ return null;
660
+ }
661
+ return /* @__PURE__ */ jsx3(
662
+ RNImage,
663
+ {
664
+ ref,
665
+ source: { uri: src },
666
+ width: dimensions.width,
667
+ height: dimensions.height,
668
+ ...props
669
+ }
670
+ );
671
+ });
672
+
673
+ // src/react-native-core/index.ts
674
+ import {
675
+ createCoValueSubscriptionContext,
676
+ createAccountSubscriptionContext
677
+ } from "jazz-tools/react-core";
678
+ import { SQLiteDatabaseDriverAsync } from "cojson";
679
+ import { parseInviteLink as parseInviteLink2 } from "jazz-tools";
3
680
 
4
681
  // src/react-native/provider.tsx
5
682
  import {
6
- JazzProviderCore
683
+ JazzProviderCore as JazzProviderCore2
7
684
  } from "jazz-tools/react-native-core";
8
- import { useMemo } from "react";
685
+ import { useMemo as useMemo2 } from "react";
9
686
 
10
687
  // src/react-native/storage/mmkv-store-adapter.ts
11
688
  import { MMKV } from "react-native-mmkv";
@@ -85,19 +762,46 @@ var OPSQLiteAdapter = class {
85
762
  };
86
763
 
87
764
  // src/react-native/provider.tsx
88
- import { jsx } from "react/jsx-runtime";
765
+ import { jsx as jsx4 } from "react/jsx-runtime";
89
766
  function JazzReactNativeProvider(props) {
90
- const storage2 = useMemo(() => {
767
+ const storage2 = useMemo2(() => {
91
768
  return props.storage ?? new OPSQLiteAdapter();
92
769
  }, [props.storage]);
93
- const kvStore = useMemo(() => {
770
+ const kvStore = useMemo2(() => {
94
771
  return props.kvStore ?? new MMKVStore();
95
772
  }, [props.kvStore]);
96
- return /* @__PURE__ */ jsx(JazzProviderCore, { ...props, storage: storage2, kvStore });
773
+ return /* @__PURE__ */ jsx4(JazzProviderCore2, { ...props, storage: storage2, kvStore });
97
774
  }
98
775
  export {
776
+ DemoAuthBasicUI,
777
+ Image,
778
+ JazzProviderCore,
99
779
  JazzReactNativeProvider,
780
+ KvStoreContext,
100
781
  MMKVStore,
101
- OPSQLiteAdapter
782
+ OPSQLiteAdapter,
783
+ ReactNativeContextManager,
784
+ SQLiteDatabaseDriverAsync,
785
+ clearUserCredentials,
786
+ createAccountSubscriptionContext,
787
+ createCoValueSubscriptionContext,
788
+ createInviteLink,
789
+ experimental_useInboxSender,
790
+ parseInviteLink2 as parseInviteLink,
791
+ setupKvStore,
792
+ useAcceptInviteNative,
793
+ useAccount,
794
+ useAccountSubscription,
795
+ useAgent,
796
+ useAuthSecretStorage,
797
+ useCoState,
798
+ useCoValueSubscription,
799
+ useDemoAuth,
800
+ useIsAuthenticated,
801
+ useJazzContext2 as useJazzContext,
802
+ useLogOut,
803
+ usePassphraseAuth,
804
+ useSubscriptionSelector,
805
+ useSyncConnectionStatus
102
806
  };
103
807
  //# sourceMappingURL=index.js.map