jazz-tools 0.10.13 → 0.10.15
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.
- package/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +14 -0
- package/dist/{chunk-GSIV52ZH.js → chunk-5USJBXLW.js} +55 -30
- package/dist/chunk-5USJBXLW.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/testing.js +11 -16
- package/dist/testing.js.map +1 -1
- package/package.json +2 -2
- package/src/auth/AuthSecretStorage.ts +10 -9
- package/src/implementation/ContextManager.ts +64 -22
- package/src/implementation/createContext.ts +3 -3
- package/src/testing.ts +10 -16
- package/src/tests/AuthSecretStorage.test.ts +8 -9
- package/src/tests/ContextManager.test.ts +27 -14
- package/src/tests/PassphraseAuth.test.ts +5 -2
- package/tsconfig.json +1 -1
- package/dist/chunk-GSIV52ZH.js.map +0 -1
package/.turbo/turbo-build.log
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
> jazz-tools@0.10.
|
2
|
+
> jazz-tools@0.10.15 build /home/runner/_work/jazz/jazz/packages/jazz-tools
|
3
3
|
> tsup
|
4
4
|
|
5
5
|
[34mCLI[39m Building entry: {"index":"src/index.ts","testing":"src/testing.ts"}
|
@@ -10,9 +10,9 @@
|
|
10
10
|
[34mCLI[39m Cleaning output folder
|
11
11
|
[34mESM[39m Build start
|
12
12
|
[32mESM[39m [1mdist/index.js [22m[32m1.50 KB[39m
|
13
|
-
[32mESM[39m [1mdist/testing.js [22m[32m6.
|
14
|
-
[32mESM[39m [1mdist/chunk-
|
13
|
+
[32mESM[39m [1mdist/testing.js [22m[32m6.18 KB[39m
|
14
|
+
[32mESM[39m [1mdist/chunk-5USJBXLW.js [22m[32m116.50 KB[39m
|
15
15
|
[32mESM[39m [1mdist/index.js.map [22m[32m259.00 B[39m
|
16
|
-
[32mESM[39m [1mdist/testing.js.map [22m[32m12.
|
17
|
-
[32mESM[39m [1mdist/chunk-
|
18
|
-
[32mESM[39m ⚡️ Build success in
|
16
|
+
[32mESM[39m [1mdist/testing.js.map [22m[32m12.24 KB[39m
|
17
|
+
[32mESM[39m [1mdist/chunk-5USJBXLW.js.map [22m[32m277.65 KB[39m
|
18
|
+
[32mESM[39m ⚡️ Build success in 59ms
|
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# jazz-tools
|
2
2
|
|
3
|
+
## 0.10.15
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 2f99de0: Avoid race conditions on context creation and run the anonymous migration only when the hook is provided
|
8
|
+
- Updated dependencies [f86e278]
|
9
|
+
- cojson@0.10.15
|
10
|
+
|
11
|
+
## 0.10.14
|
12
|
+
|
13
|
+
### Patch Changes
|
14
|
+
|
15
|
+
- 75211e3: Fixes invalid authentication state when logging out after signUp
|
16
|
+
|
3
17
|
## 0.10.13
|
4
18
|
|
5
19
|
### Patch Changes
|
@@ -545,7 +545,7 @@ async function createJazzContext(options) {
|
|
545
545
|
AccountSchema: options.AccountSchema,
|
546
546
|
sessionProvider: options.sessionProvider,
|
547
547
|
onLogOut: () => {
|
548
|
-
authSecretStorage.
|
548
|
+
authSecretStorage.clearWithoutNotify();
|
549
549
|
}
|
550
550
|
});
|
551
551
|
} else {
|
@@ -561,11 +561,11 @@ async function createJazzContext(options) {
|
|
561
561
|
crypto,
|
562
562
|
AccountSchema: options.AccountSchema,
|
563
563
|
onLogOut: async () => {
|
564
|
-
await authSecretStorage.
|
564
|
+
await authSecretStorage.clearWithoutNotify();
|
565
565
|
}
|
566
566
|
});
|
567
567
|
if (!options.newAccountProps) {
|
568
|
-
await authSecretStorage.
|
568
|
+
await authSecretStorage.setWithoutNotify({
|
569
569
|
accountID: context.account.id,
|
570
570
|
secretSeed,
|
571
571
|
accountSecret: context.node.account.agentSecret,
|
@@ -3457,7 +3457,6 @@ var KvStoreContext_default = KvStoreContext;
|
|
3457
3457
|
var STORAGE_KEY = "jazz-logged-in-secret";
|
3458
3458
|
var AuthSecretStorage = class {
|
3459
3459
|
constructor() {
|
3460
|
-
this.notify = false;
|
3461
3460
|
this.listeners = /* @__PURE__ */ new Set();
|
3462
3461
|
this.isAuthenticated = false;
|
3463
3462
|
}
|
@@ -3522,7 +3521,7 @@ var AuthSecretStorage = class {
|
|
3522
3521
|
provider: parsed.provider
|
3523
3522
|
};
|
3524
3523
|
}
|
3525
|
-
async
|
3524
|
+
async setWithoutNotify(payload) {
|
3526
3525
|
const kvStore = KvStoreContext_default.getInstance().getStorage();
|
3527
3526
|
await kvStore.set(
|
3528
3527
|
STORAGE_KEY,
|
@@ -3533,9 +3532,10 @@ var AuthSecretStorage = class {
|
|
3533
3532
|
provider: payload.provider
|
3534
3533
|
})
|
3535
3534
|
);
|
3536
|
-
|
3537
|
-
|
3538
|
-
|
3535
|
+
}
|
3536
|
+
async set(payload) {
|
3537
|
+
this.setWithoutNotify(payload);
|
3538
|
+
this.emitUpdate(payload);
|
3539
3539
|
}
|
3540
3540
|
getIsAuthenticated(data) {
|
3541
3541
|
if (!data) return false;
|
@@ -3555,12 +3555,13 @@ var AuthSecretStorage = class {
|
|
3555
3555
|
listener(this.isAuthenticated);
|
3556
3556
|
}
|
3557
3557
|
}
|
3558
|
-
async
|
3558
|
+
async clearWithoutNotify() {
|
3559
3559
|
const kvStore = KvStoreContext_default.getInstance().getStorage();
|
3560
3560
|
await kvStore.delete(STORAGE_KEY);
|
3561
|
-
|
3562
|
-
|
3563
|
-
|
3561
|
+
}
|
3562
|
+
async clear() {
|
3563
|
+
await this.clearWithoutNotify();
|
3564
|
+
this.emitUpdate(null);
|
3564
3565
|
}
|
3565
3566
|
};
|
3566
3567
|
|
@@ -3590,11 +3591,7 @@ import { cojsonInternals as cojsonInternals4 } from "cojson";
|
|
3590
3591
|
var JazzContextManager = class {
|
3591
3592
|
constructor() {
|
3592
3593
|
this.authSecretStorage = new AuthSecretStorage();
|
3593
|
-
this.
|
3594
|
-
Object.create(this.authSecretStorage),
|
3595
|
-
{ notify: true }
|
3596
|
-
);
|
3597
|
-
this.authenticating = false;
|
3594
|
+
this.keepContextOpen = false;
|
3598
3595
|
this.logOut = async () => {
|
3599
3596
|
if (!this.context || !this.props) {
|
3600
3597
|
return;
|
@@ -3609,6 +3606,14 @@ var JazzContextManager = class {
|
|
3609
3606
|
}
|
3610
3607
|
this.context.done();
|
3611
3608
|
};
|
3609
|
+
this.shouldMigrateAnonymousAccount = async () => {
|
3610
|
+
if (!this.props?.onAnonymousAccountDiscarded) {
|
3611
|
+
return false;
|
3612
|
+
}
|
3613
|
+
const prevCredentials = await this.authSecretStorage.get();
|
3614
|
+
const wasAnonymous = this.authSecretStorage.getIsAuthenticated(prevCredentials) === false;
|
3615
|
+
return wasAnonymous;
|
3616
|
+
};
|
3612
3617
|
/**
|
3613
3618
|
* Authenticates the user with the given credentials
|
3614
3619
|
*/
|
@@ -3617,13 +3622,12 @@ var JazzContextManager = class {
|
|
3617
3622
|
throw new Error("Props required");
|
3618
3623
|
}
|
3619
3624
|
const prevContext = this.context;
|
3620
|
-
const
|
3621
|
-
|
3622
|
-
this.authenticating = true;
|
3625
|
+
const migratingAnonymousAccount = await this.shouldMigrateAnonymousAccount();
|
3626
|
+
this.keepContextOpen = migratingAnonymousAccount;
|
3623
3627
|
await this.createContext(this.props, { credentials }).finally(() => {
|
3624
|
-
this.
|
3628
|
+
this.keepContextOpen = false;
|
3625
3629
|
});
|
3626
|
-
if (
|
3630
|
+
if (migratingAnonymousAccount) {
|
3627
3631
|
await this.handleAnonymousAccountMigration(prevContext);
|
3628
3632
|
}
|
3629
3633
|
};
|
@@ -3632,18 +3636,17 @@ var JazzContextManager = class {
|
|
3632
3636
|
throw new Error("Props required");
|
3633
3637
|
}
|
3634
3638
|
const prevContext = this.context;
|
3635
|
-
const
|
3636
|
-
|
3637
|
-
this.authenticating = true;
|
3639
|
+
const migratingAnonymousAccount = await this.shouldMigrateAnonymousAccount();
|
3640
|
+
this.keepContextOpen = migratingAnonymousAccount;
|
3638
3641
|
await this.createContext(this.props, {
|
3639
3642
|
newAccountProps: {
|
3640
3643
|
secret: accountSecret,
|
3641
3644
|
creationProps
|
3642
3645
|
}
|
3643
3646
|
}).finally(() => {
|
3644
|
-
this.
|
3647
|
+
this.keepContextOpen = false;
|
3645
3648
|
});
|
3646
|
-
if (
|
3649
|
+
if (migratingAnonymousAccount) {
|
3647
3650
|
await this.handleAnonymousAccountMigration(prevContext);
|
3648
3651
|
}
|
3649
3652
|
if (this.context && "me" in this.context) {
|
@@ -3664,12 +3667,27 @@ var JazzContextManager = class {
|
|
3664
3667
|
return new InMemoryKVStore();
|
3665
3668
|
}
|
3666
3669
|
async createContext(props, authProps) {
|
3670
|
+
this.props = props;
|
3671
|
+
const { promise, resolve } = createResolvablePromise();
|
3672
|
+
const prevPromise = this.contextPromise;
|
3673
|
+
this.contextPromise = promise;
|
3674
|
+
await prevPromise;
|
3675
|
+
try {
|
3676
|
+
const result = await this.getNewContext(props, authProps);
|
3677
|
+
await this.updateContext(props, result, authProps);
|
3678
|
+
resolve();
|
3679
|
+
} catch (error) {
|
3680
|
+
resolve();
|
3681
|
+
throw error;
|
3682
|
+
}
|
3683
|
+
}
|
3684
|
+
async getNewContext(props, authProps) {
|
3667
3685
|
props;
|
3668
3686
|
authProps;
|
3669
3687
|
throw new Error("Not implemented");
|
3670
3688
|
}
|
3671
3689
|
async updateContext(props, context, authProps) {
|
3672
|
-
if (!this.
|
3690
|
+
if (!this.keepContextOpen) {
|
3673
3691
|
this.context?.done();
|
3674
3692
|
}
|
3675
3693
|
this.context = context;
|
@@ -3696,7 +3714,7 @@ var JazzContextManager = class {
|
|
3696
3714
|
return this.value;
|
3697
3715
|
}
|
3698
3716
|
getAuthSecretStorage() {
|
3699
|
-
return this.
|
3717
|
+
return this.authSecretStorage;
|
3700
3718
|
}
|
3701
3719
|
async handleAnonymousAccountMigration(prevContext) {
|
3702
3720
|
if (!this.props) {
|
@@ -3731,6 +3749,13 @@ var JazzContextManager = class {
|
|
3731
3749
|
}
|
3732
3750
|
}
|
3733
3751
|
};
|
3752
|
+
function createResolvablePromise() {
|
3753
|
+
let resolve;
|
3754
|
+
const promise = new Promise((res) => {
|
3755
|
+
resolve = res;
|
3756
|
+
});
|
3757
|
+
return { promise, resolve };
|
3758
|
+
}
|
3734
3759
|
|
3735
3760
|
// src/auth/DemoAuth.ts
|
3736
3761
|
var DemoAuth = class {
|
@@ -4048,4 +4073,4 @@ export {
|
|
4048
4073
|
consumeInviteLink
|
4049
4074
|
};
|
4050
4075
|
/* istanbul ignore file -- @preserve */
|
4051
|
-
//# sourceMappingURL=chunk-
|
4076
|
+
//# sourceMappingURL=chunk-5USJBXLW.js.map
|