jazz-vue 0.9.22 → 0.10.0

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.
@@ -4,7 +4,13 @@ import { JazzTestProvider } from "../testing";
4
4
 
5
5
  export const withJazzTestSetup = <C extends (...args: any[]) => any>(
6
6
  composable: C,
7
- { account }: { account: Account | { guest: AnonymousJazzAgent } },
7
+ {
8
+ account,
9
+ isAuthenticated,
10
+ }: {
11
+ account?: Account | { guest: AnonymousJazzAgent };
12
+ isAuthenticated?: boolean;
13
+ } = {},
8
14
  ) => {
9
15
  let result;
10
16
 
@@ -23,6 +29,7 @@ export const withJazzTestSetup = <C extends (...args: any[]) => any>(
23
29
  JazzTestProvider,
24
30
  {
25
31
  account,
32
+ isAuthenticated,
26
33
  },
27
34
  {
28
35
  default: () => h(wrapper),
@@ -1,10 +1,19 @@
1
1
  // @vitest-environment happy-dom
2
2
 
3
- import { CoMap, co } from "jazz-tools";
4
- import { createJazzTestAccount } from "jazz-tools/testing";
5
- import { describe, expect, it } from "vitest";
3
+ import { CoMap, ID, co, cojsonInternals } from "jazz-tools";
4
+ import { createJazzTestAccount, setupJazzTestSync } from "jazz-tools/testing";
5
+ import { beforeEach, describe, expect, it } from "vitest";
6
6
  import { useCoState } from "../index.js";
7
- import { withJazzTestSetup } from "./testUtils.js";
7
+ import { waitFor, withJazzTestSetup } from "./testUtils.js";
8
+
9
+ beforeEach(async () => {
10
+ await setupJazzTestSync();
11
+ });
12
+
13
+ beforeEach(() => {
14
+ cojsonInternals.CO_VALUE_LOADING_CONFIG.MAX_RETRIES = 1;
15
+ cojsonInternals.CO_VALUE_LOADING_CONFIG.TIMEOUT = 1;
16
+ });
8
17
 
9
18
  describe("useCoState", () => {
10
19
  it("should return the correct value", async () => {
@@ -124,4 +133,24 @@ describe("useCoState", () => {
124
133
  expect(result.value?.content).toBe("123");
125
134
  expect(result.value?.nested?.content).toBe("456");
126
135
  });
136
+
137
+ it("should return null if the coValue is not found", async () => {
138
+ class TestMap extends CoMap {
139
+ content = co.string;
140
+ }
141
+
142
+ await createJazzTestAccount({
143
+ isCurrentActiveAccount: true,
144
+ });
145
+
146
+ const [result] = withJazzTestSetup(() =>
147
+ useCoState(TestMap, "co_z123" as ID<TestMap>, {}),
148
+ );
149
+
150
+ expect(result.value).toBeUndefined();
151
+
152
+ await waitFor(() => {
153
+ expect(result.value).toBeNull();
154
+ });
155
+ });
127
156
  });
@@ -0,0 +1,95 @@
1
+ // @vitest-environment happy-dom
2
+
3
+ import { mnemonicToEntropy } from "@scure/bip39";
4
+ import { AuthSecretStorage, KvStoreContext } from "jazz-tools";
5
+ import { createJazzTestAccount, setupJazzTestSync } from "jazz-tools/testing";
6
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
7
+ import { usePassphraseAuth } from "../index.js";
8
+ import { testWordlist } from "./fixtures.js";
9
+ import { waitFor, withJazzTestSetup } from "./testUtils.js";
10
+
11
+ describe("usePassphraseAuth", () => {
12
+ beforeEach(async () => {
13
+ await setupJazzTestSync();
14
+ await createJazzTestAccount({
15
+ isCurrentActiveAccount: true,
16
+ });
17
+ });
18
+
19
+ afterEach(() => {
20
+ KvStoreContext.getInstance().getStorage().clearAll();
21
+ });
22
+
23
+ it("should show anonymous in state with non-authenticated account", async () => {
24
+ const [result] = withJazzTestSetup(
25
+ () => usePassphraseAuth({ wordlist: testWordlist }),
26
+ {
27
+ isAuthenticated: false,
28
+ },
29
+ );
30
+
31
+ expect(result.value.state).toBe("anonymous");
32
+ });
33
+
34
+ it("should show signed in state with authenticated account", async () => {
35
+ const [result] = withJazzTestSetup(
36
+ () => usePassphraseAuth({ wordlist: testWordlist }),
37
+ {
38
+ isAuthenticated: true,
39
+ },
40
+ );
41
+
42
+ expect(result.value.state).toBe("signedIn");
43
+ });
44
+
45
+ it("should sign up with the current credentials", async () => {
46
+ const [result] = withJazzTestSetup(() =>
47
+ usePassphraseAuth({ wordlist: testWordlist }),
48
+ );
49
+
50
+ const authSecretStorage = new AuthSecretStorage();
51
+ const credentialsBefore = await authSecretStorage.get();
52
+
53
+ const passphrase = await result.value.signUp();
54
+
55
+ expect(result.value.state).toBe("signedIn");
56
+ expect(await authSecretStorage.get()).toEqual({
57
+ ...credentialsBefore,
58
+ provider: "passphrase",
59
+ });
60
+ expect(mnemonicToEntropy(passphrase, testWordlist)).toEqual(
61
+ credentialsBefore?.secretSeed,
62
+ );
63
+ });
64
+
65
+ it("should log in with the previous passphrase", async () => {
66
+ const [result] = withJazzTestSetup(() =>
67
+ usePassphraseAuth({ wordlist: testWordlist }),
68
+ );
69
+
70
+ const authSecretStorage = new AuthSecretStorage();
71
+ const credentialsBefore = await authSecretStorage.get();
72
+
73
+ const passphrase = await result.value.signUp();
74
+
75
+ await result.value.logIn(passphrase);
76
+
77
+ expect(result.value.state).toBe("signedIn");
78
+ expect(await authSecretStorage.get()).toMatchObject({
79
+ ...credentialsBefore,
80
+ provider: "passphrase",
81
+ });
82
+ });
83
+
84
+ it("should return the current account passphrase", async () => {
85
+ const [result] = withJazzTestSetup(() =>
86
+ usePassphraseAuth({ wordlist: testWordlist }),
87
+ );
88
+
89
+ await waitFor(() => result.value.passphrase !== "");
90
+
91
+ const passphrase = result.value.passphrase;
92
+
93
+ expect(await result.value.signUp()).toBe(passphrase);
94
+ });
95
+ });
package/vite.config.ts CHANGED
@@ -23,5 +23,7 @@ export default defineConfig({
23
23
  rollupOptions: {
24
24
  external: ["vue"],
25
25
  },
26
+ sourcemap: true,
27
+ minify: false,
26
28
  },
27
29
  });
@@ -1,69 +0,0 @@
1
- import { createJazzBrowserContext as l } from "jazz-browser";
2
- import { ref as c, defineComponent as z, provide as m, onMounted as g, watch as s, onUnmounted as y } from "vue";
3
- const u = c(), f = Symbol("JazzContext"), S = z({
4
- name: "JazzProvider",
5
- props: {
6
- auth: {
7
- type: [String, Object],
8
- required: !0
9
- },
10
- AccountSchema: {
11
- type: Object,
12
- required: !1
13
- },
14
- peer: {
15
- type: String,
16
- required: !0
17
- },
18
- storage: {
19
- type: String,
20
- default: void 0
21
- }
22
- },
23
- setup(a, { slots: o }) {
24
- const e = c(void 0), i = c(0);
25
- m(f, e);
26
- const v = async () => {
27
- var t, r;
28
- e.value && ((r = (t = e.value).done) == null || r.call(t), e.value = void 0);
29
- try {
30
- const n = await l(
31
- a.auth === "guest" ? { peer: a.peer, storage: a.storage } : {
32
- AccountSchema: a.AccountSchema,
33
- auth: a.auth,
34
- peer: a.peer,
35
- storage: a.storage
36
- }
37
- );
38
- e.value = {
39
- ...n,
40
- logOut: () => {
41
- var d;
42
- (d = u.value) == null || d.call(u), i.value += 1;
43
- }
44
- };
45
- } catch (n) {
46
- console.error("Error creating Jazz browser context:", n);
47
- }
48
- };
49
- return g(() => {
50
- v();
51
- }), s(
52
- () => i.value,
53
- async () => {
54
- await v();
55
- }
56
- ), y(() => {
57
- var t, r;
58
- e.value && ((r = (t = e.value).done) == null || r.call(t));
59
- }), () => {
60
- var t;
61
- return e.value ? (t = o.default) == null ? void 0 : t.call(o) : null;
62
- };
63
- }
64
- });
65
- export {
66
- f as J,
67
- S as a,
68
- u as l
69
- };