jazz-tools 0.10.5 → 0.10.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
 
2
- > jazz-tools@0.10.5 build /home/runner/_work/jazz/jazz/packages/jazz-tools
2
+ > jazz-tools@0.10.7 build /home/runner/_work/jazz/jazz/packages/jazz-tools
3
3
  > tsup
4
4
 
5
5
  CLI Building entry: {"index":"src/index.ts","testing":"src/testing.ts"}
@@ -10,9 +10,9 @@
10
10
  CLI Cleaning output folder
11
11
  ESM Build start
12
12
  ESM dist/index.js 1.50 KB
13
- ESM dist/testing.js 6.18 KB
14
- ESM dist/chunk-DXCQRDRG.js 111.89 KB
13
+ ESM dist/testing.js 6.28 KB
14
+ ESM dist/chunk-TSEO4KAO.js 113.17 KB
15
15
  ESM dist/index.js.map 259.00 B
16
- ESM dist/testing.js.map 12.19 KB
17
- ESM dist/chunk-DXCQRDRG.js.map 269.43 KB
18
- ESM ⚡️ Build success in 82ms
16
+ ESM dist/testing.js.map 12.41 KB
17
+ ESM dist/chunk-TSEO4KAO.js.map 271.81 KB
18
+ ESM ⚡️ Build success in 42ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # jazz-tools
2
2
 
3
+ ## 0.10.7
4
+
5
+ ### Patch Changes
6
+
7
+ - 1136d9b: Fixed isAuthenticated out-of-sync with the account state during the logOut and authenticate flows
8
+ - 0eed228: Fixes clerk auth flow
9
+ - Updated dependencies [0f83320]
10
+ - Updated dependencies [012022d]
11
+ - cojson@0.10.7
12
+
13
+ ## 0.10.6
14
+
15
+ ### Patch Changes
16
+
17
+ - ada802b: Fix Clerk credentials migration
18
+ - Updated dependencies [5c76e37]
19
+ - cojson@0.10.6
20
+
3
21
  ## 0.10.5
4
22
 
5
23
  ### Patch Changes
@@ -528,7 +528,6 @@ async function createJazzContext(options) {
528
528
  authSecretStorage.clear();
529
529
  }
530
530
  });
531
- authSecretStorage.emitUpdate(credentials);
532
531
  } else {
533
532
  const secretSeed = options.crypto.newRandomSecretSeed();
534
533
  const initialAgentSecret = options.newAccountProps?.secret ?? crypto.agentSecretFromSecretSeed(secretSeed);
@@ -3437,6 +3436,7 @@ var KvStoreContext_default = KvStoreContext;
3437
3436
  var STORAGE_KEY = "jazz-logged-in-secret";
3438
3437
  var AuthSecretStorage = class {
3439
3438
  constructor() {
3439
+ this.notify = false;
3440
3440
  this.listeners = /* @__PURE__ */ new Set();
3441
3441
  this.isAuthenticated = false;
3442
3442
  }
@@ -3445,15 +3445,46 @@ var AuthSecretStorage = class {
3445
3445
  if (!await kvStore.get(STORAGE_KEY)) {
3446
3446
  const demoAuthSecret = await kvStore.get("demo-auth-logged-in-secret");
3447
3447
  if (demoAuthSecret) {
3448
- await kvStore.set(STORAGE_KEY, demoAuthSecret);
3448
+ const parsed = JSON.parse(demoAuthSecret);
3449
+ await kvStore.set(
3450
+ STORAGE_KEY,
3451
+ JSON.stringify({
3452
+ accountID: parsed.accountID,
3453
+ accountSecret: parsed.accountSecret,
3454
+ provider: "demo"
3455
+ })
3456
+ );
3449
3457
  await kvStore.delete("demo-auth-logged-in-secret");
3450
3458
  }
3451
3459
  const clerkAuthSecret = await kvStore.get("jazz-clerk-auth");
3452
3460
  if (clerkAuthSecret) {
3453
- await kvStore.set(STORAGE_KEY, clerkAuthSecret);
3461
+ const parsed = JSON.parse(clerkAuthSecret);
3462
+ await kvStore.set(
3463
+ STORAGE_KEY,
3464
+ JSON.stringify({
3465
+ accountID: parsed.accountID,
3466
+ accountSecret: parsed.secret,
3467
+ provider: "clerk"
3468
+ })
3469
+ );
3454
3470
  await kvStore.delete("jazz-clerk-auth");
3455
3471
  }
3456
3472
  }
3473
+ const value = await kvStore.get(STORAGE_KEY);
3474
+ if (value) {
3475
+ const parsed = JSON.parse(value);
3476
+ if ("secret" in parsed) {
3477
+ await kvStore.set(
3478
+ STORAGE_KEY,
3479
+ JSON.stringify({
3480
+ accountID: parsed.accountID,
3481
+ secretSeed: parsed.secretSeed,
3482
+ accountSecret: parsed.secret,
3483
+ provider: parsed.provider
3484
+ })
3485
+ );
3486
+ }
3487
+ }
3457
3488
  }
3458
3489
  async get() {
3459
3490
  const kvStore = KvStoreContext_default.getInstance().getStorage();
@@ -3481,7 +3512,9 @@ var AuthSecretStorage = class {
3481
3512
  provider: payload.provider
3482
3513
  })
3483
3514
  );
3484
- this.emitUpdate(payload);
3515
+ if (this.notify) {
3516
+ this.emitUpdate(payload);
3517
+ }
3485
3518
  }
3486
3519
  getIsAuthenticated(data) {
3487
3520
  if (!data) return false;
@@ -3504,7 +3537,9 @@ var AuthSecretStorage = class {
3504
3537
  async clear() {
3505
3538
  const kvStore = KvStoreContext_default.getInstance().getStorage();
3506
3539
  await kvStore.delete(STORAGE_KEY);
3507
- this.emitUpdate(null);
3540
+ if (this.notify) {
3541
+ this.emitUpdate(null);
3542
+ }
3508
3543
  }
3509
3544
  };
3510
3545
 
@@ -3534,13 +3569,17 @@ import { cojsonInternals as cojsonInternals4 } from "cojson";
3534
3569
  var JazzContextManager = class {
3535
3570
  constructor() {
3536
3571
  this.authSecretStorage = new AuthSecretStorage();
3572
+ this.authSecretStorageWithNotify = Object.assign(
3573
+ Object.create(this.authSecretStorage),
3574
+ { notify: true }
3575
+ );
3537
3576
  this.authenticating = false;
3538
3577
  this.logOut = async () => {
3539
3578
  if (!this.context || !this.props) {
3540
3579
  return;
3541
3580
  }
3581
+ await this.props.onLogOut?.();
3542
3582
  await this.context.logOut();
3543
- this.props.onLogOut?.();
3544
3583
  return this.createContext(this.props);
3545
3584
  };
3546
3585
  this.done = () => {
@@ -3549,6 +3588,9 @@ var JazzContextManager = class {
3549
3588
  }
3550
3589
  this.context.done();
3551
3590
  };
3591
+ /**
3592
+ * Authenticates the user with the given credentials
3593
+ */
3552
3594
  this.authenticate = async (credentials) => {
3553
3595
  if (!this.props) {
3554
3596
  throw new Error("Props required");
@@ -3600,7 +3642,7 @@ var JazzContextManager = class {
3600
3642
  authProps;
3601
3643
  throw new Error("Not implemented");
3602
3644
  }
3603
- updateContext(props, context) {
3645
+ async updateContext(props, context, authProps) {
3604
3646
  if (!this.authenticating) {
3605
3647
  this.context?.done();
3606
3648
  }
@@ -3612,6 +3654,11 @@ var JazzContextManager = class {
3612
3654
  authenticate: this.authenticate,
3613
3655
  logOut: this.logOut
3614
3656
  };
3657
+ if (authProps?.credentials) {
3658
+ this.authSecretStorage.emitUpdate(authProps.credentials);
3659
+ } else {
3660
+ this.authSecretStorage.emitUpdate(await this.authSecretStorage.get());
3661
+ }
3615
3662
  this.notify();
3616
3663
  }
3617
3664
  propsChanged(props) {
@@ -3622,7 +3669,7 @@ var JazzContextManager = class {
3622
3669
  return this.value;
3623
3670
  }
3624
3671
  getAuthSecretStorage() {
3625
- return this.authSecretStorage;
3672
+ return this.authSecretStorageWithNotify;
3626
3673
  }
3627
3674
  notify() {
3628
3675
  for (const listener of this.listeners) {
@@ -3925,4 +3972,4 @@ export {
3925
3972
  consumeInviteLink
3926
3973
  };
3927
3974
  /* istanbul ignore file -- @preserve */
3928
- //# sourceMappingURL=chunk-DXCQRDRG.js.map
3975
+ //# sourceMappingURL=chunk-TSEO4KAO.js.map