jazz-tools 0.18.24 → 0.18.25

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 (80) hide show
  1. package/.svelte-kit/__package__/Provider.svelte +2 -0
  2. package/.svelte-kit/__package__/Provider.svelte.d.ts.map +1 -1
  3. package/.turbo/turbo-build.log +53 -53
  4. package/CHANGELOG.md +14 -0
  5. package/dist/browser/index.js +9 -9
  6. package/dist/browser/index.js.map +1 -1
  7. package/dist/{chunk-W7JT3QUN.js → chunk-DOCEAUVD.js} +72 -35
  8. package/dist/chunk-DOCEAUVD.js.map +1 -0
  9. package/dist/{chunk-BOMSRY5H.js → chunk-M2HGBOXS.js} +2 -2
  10. package/dist/chunk-M2HGBOXS.js.map +1 -0
  11. package/dist/index.js +2 -2
  12. package/dist/inspector/{custom-element-XDJT5T57.js → custom-element-A7UAELEG.js} +3 -1
  13. package/dist/inspector/{custom-element-XDJT5T57.js.map → custom-element-A7UAELEG.js.map} +1 -1
  14. package/dist/inspector/index.js +2 -0
  15. package/dist/inspector/index.js.map +1 -1
  16. package/dist/inspector/register-custom-element.js +1 -1
  17. package/dist/inspector/viewer/use-open-inspector.d.ts.map +1 -1
  18. package/dist/inspector/viewer/use-page-path.d.ts.map +1 -1
  19. package/dist/react/index.js +4 -2
  20. package/dist/react/index.js.map +1 -1
  21. package/dist/react/provider.d.ts +2 -1
  22. package/dist/react/provider.d.ts.map +1 -1
  23. package/dist/react/ssr.js +1 -1
  24. package/dist/react/ssr.js.map +1 -1
  25. package/dist/react-native-core/index.js +12 -11
  26. package/dist/react-native-core/index.js.map +1 -1
  27. package/dist/react-native-core/provider.d.ts +2 -1
  28. package/dist/react-native-core/provider.d.ts.map +1 -1
  29. package/dist/svelte/Provider.svelte +2 -0
  30. package/dist/svelte/Provider.svelte.d.ts.map +1 -1
  31. package/dist/testing.js +4 -4
  32. package/dist/testing.js.map +1 -1
  33. package/dist/tools/auth/AuthSecretStorage.d.ts +3 -1
  34. package/dist/tools/auth/AuthSecretStorage.d.ts.map +1 -1
  35. package/dist/tools/coValues/account.d.ts +3 -3
  36. package/dist/tools/coValues/account.d.ts.map +1 -1
  37. package/dist/tools/coValues/group.d.ts +20 -1
  38. package/dist/tools/coValues/group.d.ts.map +1 -1
  39. package/dist/tools/coValues/interfaces.d.ts.map +1 -1
  40. package/dist/tools/implementation/ContextManager.d.ts +1 -0
  41. package/dist/tools/implementation/ContextManager.d.ts.map +1 -1
  42. package/dist/tools/implementation/createContext.d.ts +7 -7
  43. package/dist/tools/implementation/createContext.d.ts.map +1 -1
  44. package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts +5 -0
  45. package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts.map +1 -1
  46. package/dist/tools/ssr.js +1 -1
  47. package/dist/tools/testing.d.ts.map +1 -1
  48. package/dist/worker/index.js +3 -3
  49. package/dist/worker/index.js.map +1 -1
  50. package/package.json +4 -4
  51. package/src/better-auth/database-adapter/tests/sync-utils.ts +1 -1
  52. package/src/browser/createBrowserContext.ts +9 -9
  53. package/src/browser/tests/utils.ts +2 -2
  54. package/src/inspector/viewer/use-open-inspector.ts +1 -0
  55. package/src/inspector/viewer/use-page-path.ts +1 -0
  56. package/src/react/provider.tsx +3 -0
  57. package/src/react-native-core/platform.ts +9 -9
  58. package/src/react-native-core/provider.tsx +3 -1
  59. package/src/svelte/Provider.svelte +2 -0
  60. package/src/tools/auth/AuthSecretStorage.ts +16 -9
  61. package/src/tools/coValues/account.ts +5 -5
  62. package/src/tools/coValues/group.ts +33 -0
  63. package/src/tools/coValues/interfaces.ts +4 -1
  64. package/src/tools/implementation/ContextManager.ts +7 -3
  65. package/src/tools/implementation/createContext.ts +12 -12
  66. package/src/tools/implementation/zodSchema/schemaTypes/GroupSchema.ts +7 -1
  67. package/src/tools/ssr/ssr.ts +1 -1
  68. package/src/tools/testing.ts +3 -3
  69. package/src/tools/tests/AuthSecretStorage.test.ts +59 -1
  70. package/src/tools/tests/ContextManager.test.ts +11 -1
  71. package/src/tools/tests/account.test.ts +16 -0
  72. package/src/tools/tests/coPlainText.test.ts +2 -2
  73. package/src/tools/tests/createContext.test.ts +19 -19
  74. package/src/tools/tests/deepLoading.test.ts +2 -2
  75. package/src/tools/tests/group.test.ts +59 -0
  76. package/src/tools/tests/inbox.test.ts +2 -2
  77. package/src/tools/tests/utils.ts +3 -3
  78. package/src/worker/index.ts +3 -3
  79. package/dist/chunk-BOMSRY5H.js.map +0 -1
  80. package/dist/chunk-W7JT3QUN.js.map +0 -1
@@ -2164,7 +2164,7 @@ var Account = class extends CoValueBase {
2164
2164
  *
2165
2165
  * @param valueID The ID of the `CoValue` or `Group` to accept the invite to.
2166
2166
  * @param inviteSecret The secret of the invite to accept.
2167
- * @param coValueClass The class of the `CoValue` or `Group` to accept the invite to.
2167
+ * @param coValueClass [Group] The class of the `CoValue` or `Group` to accept the invite to.
2168
2168
  * @returns The loaded `CoValue` or `Group`.
2169
2169
  */
2170
2170
  async acceptInvite(valueID, inviteSecret, coValueClass) {
@@ -2176,7 +2176,7 @@ var Account = class extends CoValueBase {
2176
2176
  inviteSecret
2177
2177
  );
2178
2178
  return loadCoValue(
2179
- coValueClassFromCoValueClassOrSchema(coValueClass),
2179
+ coValueClassFromCoValueClassOrSchema(coValueClass ?? Group5),
2180
2180
  valueID,
2181
2181
  {
2182
2182
  loadAs: this
@@ -2258,7 +2258,7 @@ var Account = class extends CoValueBase {
2258
2258
  const account = await this.create({
2259
2259
  creationProps: options.creationProps,
2260
2260
  crypto: as.$jazz.localNode.crypto,
2261
- peersToLoadFrom: [connectedPeers[0]]
2261
+ peers: [connectedPeers[0]]
2262
2262
  });
2263
2263
  await account.$jazz.waitForAllCoValuesSync();
2264
2264
  return account;
@@ -2646,9 +2646,27 @@ var _Group = class _Group extends CoValueBase {
2646
2646
  const { options, listener } = parseSubscribeRestArgs(args);
2647
2647
  return subscribeToCoValueWithoutMe(this, id, options, listener);
2648
2648
  }
2649
+ /** @category Invites
2650
+ * Creates a group invite
2651
+ * @param id The ID of the group to create an invite for
2652
+ * @param options Optional configuration
2653
+ * @param options.role The role to grant to the accepter of the invite. Defaults to 'reader'
2654
+ * @param options.loadAs The account to use when loading the group. Defaults to the current account
2655
+ * @returns An invite secret, (a string starting with "inviteSecret_"). Can be
2656
+ * accepted using `Account.acceptInvite()`
2657
+ */
2658
+ static async createInvite(id, options) {
2659
+ const group = await loadCoValueWithoutMe(this, id, {
2660
+ loadAs: options?.loadAs
2661
+ });
2662
+ if (!group) {
2663
+ throw new Error(`Group with id ${id} not found`);
2664
+ }
2665
+ return group.$jazz.createInvite(options?.role ?? "reader");
2666
+ }
2649
2667
  };
2650
2668
  _Group.prototype[TypeSym] = "Group";
2651
- var Group6 = _Group;
2669
+ var Group5 = _Group;
2652
2670
  var GroupJazzApi = class extends CoValueJazzApi {
2653
2671
  constructor(group, raw) {
2654
2672
  super(group);
@@ -2676,6 +2694,14 @@ var GroupJazzApi = class extends CoValueJazzApi {
2676
2694
  const { options, listener } = parseSubscribeRestArgs(args);
2677
2695
  return subscribeToExistingCoValue(this.group, options, listener);
2678
2696
  }
2697
+ /**
2698
+ * Create an invite to this group
2699
+ *
2700
+ * @category Invites
2701
+ */
2702
+ createInvite(role = "reader") {
2703
+ return this.raw.createInvite(role);
2704
+ }
2679
2705
  /**
2680
2706
  * Wait for the `Group` to be uploaded to the other peers.
2681
2707
  *
@@ -2685,7 +2711,7 @@ var GroupJazzApi = class extends CoValueJazzApi {
2685
2711
  return this.raw.core.waitForSync(options);
2686
2712
  }
2687
2713
  };
2688
- RegisteredSchemas["Group"] = Group6;
2714
+ RegisteredSchemas["Group"] = Group5;
2689
2715
  function isAccountID(id) {
2690
2716
  return id.startsWith("co_");
2691
2717
  }
@@ -3514,7 +3540,7 @@ function instantiateRefEncodedWithInit(schema, init, parentOwner) {
3514
3540
  }
3515
3541
  const node = parentOwner.$jazz.localNode;
3516
3542
  const rawGroup = node.createGroup();
3517
- const owner = new Group6({ fromRaw: rawGroup });
3543
+ const owner = new Group5({ fromRaw: rawGroup });
3518
3544
  owner.addMember(parentOwner);
3519
3545
  return schema.ref.create(init, owner);
3520
3546
  }
@@ -4344,7 +4370,7 @@ async function randomSessionProvider(accountID, crypto) {
4344
4370
  }
4345
4371
  async function createJazzContextFromExistingCredentials({
4346
4372
  credentials,
4347
- peersToLoadFrom,
4373
+ peers,
4348
4374
  crypto,
4349
4375
  storage,
4350
4376
  AccountSchema: PropsAccountSchema,
@@ -4362,7 +4388,7 @@ async function createJazzContextFromExistingCredentials({
4362
4388
  accountID: credentials.accountID,
4363
4389
  accountSecret: credentials.secret,
4364
4390
  sessionID,
4365
- peersToLoadFrom,
4391
+ peers,
4366
4392
  crypto,
4367
4393
  storage,
4368
4394
  migration: async (rawAccount, _node, creationProps) => {
@@ -4394,7 +4420,7 @@ async function createJazzContextFromExistingCredentials({
4394
4420
  async function createJazzContextForNewAccount({
4395
4421
  creationProps,
4396
4422
  initialAgentSecret,
4397
- peersToLoadFrom,
4423
+ peers,
4398
4424
  crypto,
4399
4425
  AccountSchema: PropsAccountSchema,
4400
4426
  onLogOut,
@@ -4404,7 +4430,7 @@ async function createJazzContextForNewAccount({
4404
4430
  const AccountClass = coValueClassFromCoValueClassOrSchema(CurrentAccountSchema);
4405
4431
  const { node } = await LocalNode4.withNewlyCreatedAccount({
4406
4432
  creationProps,
4407
- peersToLoadFrom,
4433
+ peers,
4408
4434
  crypto,
4409
4435
  initialAgentSecret,
4410
4436
  storage,
@@ -4440,7 +4466,7 @@ async function createJazzContext(options) {
4440
4466
  accountID: credentials.accountID,
4441
4467
  secret: credentials.accountSecret
4442
4468
  },
4443
- peersToLoadFrom: options.peersToLoadFrom,
4469
+ peers: options.peers,
4444
4470
  crypto,
4445
4471
  AccountSchema: options.AccountSchema,
4446
4472
  sessionProvider: options.sessionProvider,
@@ -4459,7 +4485,7 @@ async function createJazzContext(options) {
4459
4485
  context = await createJazzContextForNewAccount({
4460
4486
  creationProps,
4461
4487
  initialAgentSecret,
4462
- peersToLoadFrom: options.peersToLoadFrom,
4488
+ peers: options.peers,
4463
4489
  crypto,
4464
4490
  AccountSchema: options.AccountSchema,
4465
4491
  onLogOut: async () => {
@@ -4482,7 +4508,7 @@ async function createJazzContext(options) {
4482
4508
  };
4483
4509
  }
4484
4510
  function createAnonymousJazzContext({
4485
- peersToLoadFrom,
4511
+ peers,
4486
4512
  crypto,
4487
4513
  storage
4488
4514
  }) {
@@ -4492,7 +4518,7 @@ function createAnonymousJazzContext({
4492
4518
  crypto.newRandomSessionID(crypto.getAgentID(agentSecret)),
4493
4519
  crypto
4494
4520
  );
4495
- for (const peer of peersToLoadFrom) {
4521
+ for (const peer of peers) {
4496
4522
  node.syncManager.addPeer(peer);
4497
4523
  }
4498
4524
  if (storage) {
@@ -4620,19 +4646,22 @@ var GroupSchema = class {
4620
4646
  this.builtin = "Group";
4621
4647
  }
4622
4648
  getCoValueClass() {
4623
- return Group6;
4649
+ return Group5;
4624
4650
  }
4625
4651
  optional() {
4626
4652
  return coOptionalDefiner(this);
4627
4653
  }
4628
4654
  create(options) {
4629
- return Group6.create(options);
4655
+ return Group5.create(options);
4630
4656
  }
4631
4657
  load(id, options) {
4632
- return Group6.load(id, options);
4658
+ return Group5.load(id, options);
4659
+ }
4660
+ createInvite(id, options) {
4661
+ return Group5.createInvite(id, options);
4633
4662
  }
4634
4663
  subscribe(id, ...args) {
4635
- return Group6.subscribe(id, ...args);
4664
+ return Group5.subscribe(id, ...args);
4636
4665
  }
4637
4666
  };
4638
4667
 
@@ -5407,20 +5436,26 @@ var KvStoreContext = class _KvStoreContext {
5407
5436
  var KvStoreContext_default = KvStoreContext;
5408
5437
 
5409
5438
  // src/tools/auth/AuthSecretStorage.ts
5439
+ import { z as z2 } from "zod/v4";
5410
5440
  var STORAGE_KEY = "jazz-logged-in-secret";
5411
5441
  var AuthSecretStorage = class {
5412
- constructor() {
5442
+ constructor(storageKey = STORAGE_KEY) {
5443
+ this.storageKey = storageKey;
5444
+ z2.string().nonempty().parse(storageKey);
5413
5445
  this.listeners = /* @__PURE__ */ new Set();
5414
5446
  this.isAuthenticated = false;
5415
5447
  }
5448
+ getStorageKey() {
5449
+ return this.storageKey;
5450
+ }
5416
5451
  async migrate() {
5417
5452
  const kvStore = KvStoreContext_default.getInstance().getStorage();
5418
- if (!await kvStore.get(STORAGE_KEY)) {
5453
+ if (!await kvStore.get(this.storageKey)) {
5419
5454
  const demoAuthSecret = await kvStore.get("demo-auth-logged-in-secret");
5420
5455
  if (demoAuthSecret) {
5421
5456
  const parsed = JSON.parse(demoAuthSecret);
5422
5457
  await kvStore.set(
5423
- STORAGE_KEY,
5458
+ this.storageKey,
5424
5459
  JSON.stringify({
5425
5460
  accountID: parsed.accountID,
5426
5461
  accountSecret: parsed.accountSecret,
@@ -5433,7 +5468,7 @@ var AuthSecretStorage = class {
5433
5468
  if (clerkAuthSecret) {
5434
5469
  const parsed = JSON.parse(clerkAuthSecret);
5435
5470
  await kvStore.set(
5436
- STORAGE_KEY,
5471
+ this.storageKey,
5437
5472
  JSON.stringify({
5438
5473
  accountID: parsed.accountID,
5439
5474
  accountSecret: parsed.secret,
@@ -5443,12 +5478,12 @@ var AuthSecretStorage = class {
5443
5478
  await kvStore.delete("jazz-clerk-auth");
5444
5479
  }
5445
5480
  }
5446
- const value = await kvStore.get(STORAGE_KEY);
5481
+ const value = await kvStore.get(this.storageKey);
5447
5482
  if (value) {
5448
5483
  const parsed = JSON.parse(value);
5449
5484
  if ("secret" in parsed) {
5450
5485
  await kvStore.set(
5451
- STORAGE_KEY,
5486
+ this.storageKey,
5452
5487
  JSON.stringify({
5453
5488
  accountID: parsed.accountID,
5454
5489
  secretSeed: parsed.secretSeed,
@@ -5461,7 +5496,7 @@ var AuthSecretStorage = class {
5461
5496
  }
5462
5497
  async get() {
5463
5498
  const kvStore = KvStoreContext_default.getInstance().getStorage();
5464
- const data = await kvStore.get(STORAGE_KEY);
5499
+ const data = await kvStore.get(this.storageKey);
5465
5500
  if (!data) return null;
5466
5501
  const parsed = JSON.parse(data);
5467
5502
  if (!parsed.accountID || !parsed.accountSecret) {
@@ -5477,7 +5512,7 @@ var AuthSecretStorage = class {
5477
5512
  async setWithoutNotify(payload) {
5478
5513
  const kvStore = KvStoreContext_default.getInstance().getStorage();
5479
5514
  await kvStore.set(
5480
- STORAGE_KEY,
5515
+ this.storageKey,
5481
5516
  JSON.stringify({
5482
5517
  accountID: payload.accountID,
5483
5518
  secretSeed: payload.secretSeed ? Array.from(payload.secretSeed) : void 0,
@@ -5510,7 +5545,7 @@ var AuthSecretStorage = class {
5510
5545
  }
5511
5546
  async clearWithoutNotify() {
5512
5547
  const kvStore = KvStoreContext_default.getInstance().getStorage();
5513
- await kvStore.delete(STORAGE_KEY);
5548
+ await kvStore.delete(this.storageKey);
5514
5549
  }
5515
5550
  async clear() {
5516
5551
  await this.clearWithoutNotify();
@@ -5542,7 +5577,7 @@ var InMemoryKVStore = class {
5542
5577
  // src/tools/implementation/ContextManager.ts
5543
5578
  function getAnonymousFallback() {
5544
5579
  const context = createAnonymousJazzContext({
5545
- peersToLoadFrom: [],
5580
+ peers: [],
5546
5581
  crypto: new PureJSCrypto()
5547
5582
  });
5548
5583
  return {
@@ -5565,7 +5600,6 @@ function getAnonymousFallback() {
5565
5600
  }
5566
5601
  var JazzContextManager = class {
5567
5602
  constructor(opts) {
5568
- this.authSecretStorage = new AuthSecretStorage();
5569
5603
  this.keepContextOpen = false;
5570
5604
  this.authenticatingAccountID = null;
5571
5605
  this.logOut = async () => {
@@ -5669,6 +5703,7 @@ var JazzContextManager = class {
5669
5703
  };
5670
5704
  };
5671
5705
  KvStoreContext.getInstance().initialize(this.getKvStore());
5706
+ this.authSecretStorage = new AuthSecretStorage(opts?.authSecretStorageKey);
5672
5707
  if (opts?.useAnonymousFallback) {
5673
5708
  this.value = getAnonymousFallback();
5674
5709
  }
@@ -5960,7 +5995,9 @@ function subscribeToCoValue(cls, id, options, listener) {
5960
5995
  if (unsubscribed) return;
5961
5996
  if (value.type === "unavailable") {
5962
5997
  options.onUnavailable?.();
5963
- console.error(value.toString());
5998
+ if (!options.skipRetry) {
5999
+ console.error(value.toString());
6000
+ }
5964
6001
  } else if (value.type === "unauthorized") {
5965
6002
  options.onUnauthorized?.();
5966
6003
  console.error(value.toString());
@@ -6006,9 +6043,9 @@ function isAccountInstance(instance) {
6006
6043
  return TypeSym in instance && instance[TypeSym] === "Account";
6007
6044
  }
6008
6045
  function parseCoValueCreateOptions(options) {
6009
- const Group17 = RegisteredSchemas["Group"];
6046
+ const Group16 = RegisteredSchemas["Group"];
6010
6047
  if (!options) {
6011
- return { owner: Group17.create(), uniqueness: void 0 };
6048
+ return { owner: Group16.create(), uniqueness: void 0 };
6012
6049
  }
6013
6050
  if (TypeSym in options) {
6014
6051
  if (options[TypeSym] === "Account") {
@@ -6019,7 +6056,7 @@ function parseCoValueCreateOptions(options) {
6019
6056
  }
6020
6057
  const uniqueness = options.unique ? { uniqueness: options.unique } : void 0;
6021
6058
  const opts = {
6022
- owner: options.owner ? accountOrGroupToGroup(options.owner) : Group17.create(),
6059
+ owner: options.owner ? accountOrGroupToGroup(options.owner) : Group16.create(),
6023
6060
  uniqueness
6024
6061
  };
6025
6062
  return opts;
@@ -6168,7 +6205,7 @@ export {
6168
6205
  FileStream,
6169
6206
  Account,
6170
6207
  isControlledAccount,
6171
- Group6 as Group,
6208
+ Group5 as Group,
6172
6209
  Profile,
6173
6210
  isCoValueId,
6174
6211
  Inbox,
@@ -6197,4 +6234,4 @@ export {
6197
6234
  JazzContextManager
6198
6235
  };
6199
6236
  /* istanbul ignore file -- @preserve */
6200
- //# sourceMappingURL=chunk-W7JT3QUN.js.map
6237
+ //# sourceMappingURL=chunk-DOCEAUVD.js.map