jazz-tools 0.10.14 → 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 +8 -0
- package/dist/{chunk-5YDDEUNX.js → chunk-5USJBXLW.js} +41 -13
- package/dist/{chunk-5YDDEUNX.js.map → chunk-5USJBXLW.js.map} +1 -1
- 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/implementation/ContextManager.ts +63 -15
- package/src/testing.ts +10 -16
- package/src/tests/ContextManager.test.ts +27 -14
- package/src/tests/PassphraseAuth.test.ts +4 -0
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,13 @@
|
|
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
|
+
|
3
11
|
## 0.10.14
|
4
12
|
|
5
13
|
### Patch Changes
|
@@ -3591,7 +3591,7 @@ import { cojsonInternals as cojsonInternals4 } from "cojson";
|
|
3591
3591
|
var JazzContextManager = class {
|
3592
3592
|
constructor() {
|
3593
3593
|
this.authSecretStorage = new AuthSecretStorage();
|
3594
|
-
this.
|
3594
|
+
this.keepContextOpen = false;
|
3595
3595
|
this.logOut = async () => {
|
3596
3596
|
if (!this.context || !this.props) {
|
3597
3597
|
return;
|
@@ -3606,6 +3606,14 @@ var JazzContextManager = class {
|
|
3606
3606
|
}
|
3607
3607
|
this.context.done();
|
3608
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
|
+
};
|
3609
3617
|
/**
|
3610
3618
|
* Authenticates the user with the given credentials
|
3611
3619
|
*/
|
@@ -3614,13 +3622,12 @@ var JazzContextManager = class {
|
|
3614
3622
|
throw new Error("Props required");
|
3615
3623
|
}
|
3616
3624
|
const prevContext = this.context;
|
3617
|
-
const
|
3618
|
-
|
3619
|
-
this.authenticating = true;
|
3625
|
+
const migratingAnonymousAccount = await this.shouldMigrateAnonymousAccount();
|
3626
|
+
this.keepContextOpen = migratingAnonymousAccount;
|
3620
3627
|
await this.createContext(this.props, { credentials }).finally(() => {
|
3621
|
-
this.
|
3628
|
+
this.keepContextOpen = false;
|
3622
3629
|
});
|
3623
|
-
if (
|
3630
|
+
if (migratingAnonymousAccount) {
|
3624
3631
|
await this.handleAnonymousAccountMigration(prevContext);
|
3625
3632
|
}
|
3626
3633
|
};
|
@@ -3629,18 +3636,17 @@ var JazzContextManager = class {
|
|
3629
3636
|
throw new Error("Props required");
|
3630
3637
|
}
|
3631
3638
|
const prevContext = this.context;
|
3632
|
-
const
|
3633
|
-
|
3634
|
-
this.authenticating = true;
|
3639
|
+
const migratingAnonymousAccount = await this.shouldMigrateAnonymousAccount();
|
3640
|
+
this.keepContextOpen = migratingAnonymousAccount;
|
3635
3641
|
await this.createContext(this.props, {
|
3636
3642
|
newAccountProps: {
|
3637
3643
|
secret: accountSecret,
|
3638
3644
|
creationProps
|
3639
3645
|
}
|
3640
3646
|
}).finally(() => {
|
3641
|
-
this.
|
3647
|
+
this.keepContextOpen = false;
|
3642
3648
|
});
|
3643
|
-
if (
|
3649
|
+
if (migratingAnonymousAccount) {
|
3644
3650
|
await this.handleAnonymousAccountMigration(prevContext);
|
3645
3651
|
}
|
3646
3652
|
if (this.context && "me" in this.context) {
|
@@ -3661,12 +3667,27 @@ var JazzContextManager = class {
|
|
3661
3667
|
return new InMemoryKVStore();
|
3662
3668
|
}
|
3663
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) {
|
3664
3685
|
props;
|
3665
3686
|
authProps;
|
3666
3687
|
throw new Error("Not implemented");
|
3667
3688
|
}
|
3668
3689
|
async updateContext(props, context, authProps) {
|
3669
|
-
if (!this.
|
3690
|
+
if (!this.keepContextOpen) {
|
3670
3691
|
this.context?.done();
|
3671
3692
|
}
|
3672
3693
|
this.context = context;
|
@@ -3728,6 +3749,13 @@ var JazzContextManager = class {
|
|
3728
3749
|
}
|
3729
3750
|
}
|
3730
3751
|
};
|
3752
|
+
function createResolvablePromise() {
|
3753
|
+
let resolve;
|
3754
|
+
const promise = new Promise((res) => {
|
3755
|
+
resolve = res;
|
3756
|
+
});
|
3757
|
+
return { promise, resolve };
|
3758
|
+
}
|
3731
3759
|
|
3732
3760
|
// src/auth/DemoAuth.ts
|
3733
3761
|
var DemoAuth = class {
|
@@ -4045,4 +4073,4 @@ export {
|
|
4045
4073
|
consumeInviteLink
|
4046
4074
|
};
|
4047
4075
|
/* istanbul ignore file -- @preserve */
|
4048
|
-
//# sourceMappingURL=chunk-
|
4076
|
+
//# sourceMappingURL=chunk-5USJBXLW.js.map
|