community-jazz-vue 0.15.4

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 (56) hide show
  1. package/.turbo/turbo-build.log +21 -0
  2. package/CHANGELOG.md +2201 -0
  3. package/LICENSE.txt +19 -0
  4. package/README.md +26 -0
  5. package/dist/Image.vue.d.ts +26 -0
  6. package/dist/auth/JazzVueProviderWithClerk.d.ts +83 -0
  7. package/dist/auth/PasskeyAuthBasicUI.vue.d.ts +21 -0
  8. package/dist/auth/useClerkAuth.d.ts +2 -0
  9. package/dist/auth/useIsAuthenticated.d.ts +1 -0
  10. package/dist/auth/usePasskeyAuth.d.ts +18 -0
  11. package/dist/auth/usePassphraseAuth.d.ts +20 -0
  12. package/dist/composables.d.ts +22 -0
  13. package/dist/index.d.ts +11 -0
  14. package/dist/index.js +667 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/provider-CCZVJj45.js +143 -0
  17. package/dist/provider-CCZVJj45.js.map +1 -0
  18. package/dist/provider.d.ts +172 -0
  19. package/dist/testing.d.ts +30 -0
  20. package/dist/testing.js +41 -0
  21. package/dist/testing.js.map +1 -0
  22. package/dist/tests/fixtures.d.ts +1 -0
  23. package/dist/tests/proxyBehavior.test.d.ts +1 -0
  24. package/dist/tests/testUtils.d.ts +9 -0
  25. package/dist/tests/useAcceptInvite.test.d.ts +1 -0
  26. package/dist/tests/useAccount.test.d.ts +1 -0
  27. package/dist/tests/useCoState.test.d.ts +1 -0
  28. package/dist/tests/useInboxSender.test.d.ts +1 -0
  29. package/dist/tests/useIsAuthenticated.test.d.ts +1 -0
  30. package/dist/tests/usePassphraseAuth.test.d.ts +1 -0
  31. package/dist/utils/contextManager.d.ts +3 -0
  32. package/package.json +53 -0
  33. package/src/Image.vue +151 -0
  34. package/src/auth/JazzVueProviderWithClerk.ts +123 -0
  35. package/src/auth/PasskeyAuthBasicUI.vue +153 -0
  36. package/src/auth/useClerkAuth.ts +35 -0
  37. package/src/auth/useIsAuthenticated.ts +21 -0
  38. package/src/auth/usePasskeyAuth.ts +48 -0
  39. package/src/auth/usePassphraseAuth.ts +57 -0
  40. package/src/composables.ts +323 -0
  41. package/src/index.ts +14 -0
  42. package/src/provider.ts +192 -0
  43. package/src/testing.ts +45 -0
  44. package/src/tests/fixtures.ts +2050 -0
  45. package/src/tests/proxyBehavior.test.ts +267 -0
  46. package/src/tests/testUtils.ts +75 -0
  47. package/src/tests/useAcceptInvite.test.ts +55 -0
  48. package/src/tests/useAccount.test.ts +59 -0
  49. package/src/tests/useCoState.test.ts +175 -0
  50. package/src/tests/useInboxSender.test.ts +58 -0
  51. package/src/tests/useIsAuthenticated.test.ts +35 -0
  52. package/src/tests/usePassphraseAuth.test.ts +95 -0
  53. package/src/utils/contextManager.ts +31 -0
  54. package/src/vite-env.d.ts +7 -0
  55. package/tsconfig.json +20 -0
  56. package/vite.config.ts +31 -0
@@ -0,0 +1,35 @@
1
+ // @vitest-environment happy-dom
2
+
3
+ import { AuthSecretStorage, InMemoryKVStore, KvStoreContext } from "jazz-tools";
4
+ import { createJazzTestAccount } from "jazz-tools/testing";
5
+ import { beforeEach, describe, expect, it } from "vitest";
6
+ import { useIsAuthenticated } from "../auth/useIsAuthenticated.js";
7
+ import { withJazzTestSetup } from "./testUtils.js";
8
+
9
+ // Initialize KV store for tests
10
+ KvStoreContext.getInstance().initialize(new InMemoryKVStore());
11
+
12
+ describe("useIsAuthenticated", () => {
13
+ let authSecretStorage: AuthSecretStorage;
14
+
15
+ beforeEach(async () => {
16
+ // Clear storage and create new instance for each test
17
+ KvStoreContext.getInstance().getStorage().clearAll();
18
+ authSecretStorage = new AuthSecretStorage();
19
+ await createJazzTestAccount({
20
+ isCurrentActiveAccount: true,
21
+ });
22
+ });
23
+
24
+ it("should return false when no credentials exist", () => {
25
+ const [result] = withJazzTestSetup(() => useIsAuthenticated());
26
+ expect(result.value).toBe(false);
27
+ });
28
+
29
+ it("should return true when valid credentials exist", async () => {
30
+ const [result] = withJazzTestSetup(() => useIsAuthenticated(), {
31
+ isAuthenticated: true,
32
+ });
33
+ expect(result.value).toBe(true);
34
+ });
35
+ });
@@ -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
+ });
@@ -0,0 +1,31 @@
1
+ import type { Account, JazzContextManager } from "jazz-tools";
2
+
3
+ // This was copied from react-core/utils.ts, so the changes from one does not impact the changes in another
4
+ // But this is sub-par and should be merged since it's portable for now.
5
+
6
+ export function getCurrentAccountFromContextManager<Acc extends Account>(
7
+ contextManager: JazzContextManager<Acc, any>,
8
+ ) {
9
+ const context = contextManager.getCurrentValue();
10
+
11
+ if (!context) {
12
+ throw new Error("No context found");
13
+ }
14
+
15
+ return "me" in context ? context.me : context.guest;
16
+ }
17
+
18
+ export function subscribeToContextManager<Acc extends Account>(
19
+ contextManager: JazzContextManager<Acc, any>,
20
+ callback: () => () => void,
21
+ ) {
22
+ let unsub = () => {};
23
+
24
+ const handler = () => {
25
+ unsub();
26
+ unsub = callback();
27
+ };
28
+
29
+ handler();
30
+ return contextManager.subscribe(handler);
31
+ }
@@ -0,0 +1,7 @@
1
+ /// <reference types="vite/client" />
2
+
3
+ declare module "*.vue" {
4
+ import type { DefineComponent } from "vue";
5
+ const component: DefineComponent<{}, {}, any>;
6
+ export default component;
7
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "lib": ["ESNext", "DOM"],
6
+ "skipLibCheck": true,
7
+ "moduleResolution": "bundler",
8
+ "moduleDetection": "force",
9
+ "jsx": "preserve",
10
+ "jsxImportSource": "vue",
11
+ "strict": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "noUncheckedIndexedAccess": true,
14
+ "esModuleInterop": true,
15
+ "declaration": true,
16
+ "isolatedModules": true
17
+ },
18
+ "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"],
19
+ "exclude": ["node_modules", "dist", "vite.config.ts"]
20
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,31 @@
1
+ import path from "node:path";
2
+ import vue from "@vitejs/plugin-vue";
3
+ import vueJsx from "@vitejs/plugin-vue-jsx";
4
+ import depsExternal from "rollup-plugin-node-externals";
5
+ import { defineConfig } from "vite";
6
+ import dts from "vite-plugin-dts";
7
+
8
+ export default defineConfig({
9
+ plugins: [
10
+ vue(),
11
+ vueJsx(),
12
+ dts({ include: ["src/**/*.ts", "src/**/*.vue"], outDir: "dist" }),
13
+ depsExternal(),
14
+ ],
15
+ build: {
16
+ lib: {
17
+ entry: {
18
+ index: path.resolve(__dirname, "src/index.ts"),
19
+ testing: path.resolve(__dirname, "src/testing.ts"),
20
+ },
21
+ name: "JazzVue",
22
+ formats: ["es"],
23
+ fileName: (_, entryName) => `${entryName}.js`,
24
+ },
25
+ rollupOptions: {
26
+ external: ["vue"],
27
+ },
28
+ sourcemap: true,
29
+ minify: false,
30
+ },
31
+ });