Compare commits

..

16 Commits

Author SHA1 Message Date
Guido D'Orsi
4fd1d5a3a4 crazy auth refactoring 2025-01-20 18:36:00 +01:00
Guido D'Orsi
40634c6ec1 chore: update lockfile 2025-01-20 12:41:08 +01:00
Guido D'Orsi
8bc758ce95 Merge remote-tracking branch 'origin/main' into user-onboarding-upgrade 2025-01-20 12:32:25 +01:00
Guido D'Orsi
73079ca1b7 test: update e2e tests 2025-01-17 22:57:45 +01:00
Guido D'Orsi
c36f19a97f fix: fix imports & and tests on createJazzBrowserContext 2025-01-17 19:28:38 +01:00
Guido D'Orsi
109338923a chore: update lockfile 2025-01-17 18:18:57 +01:00
Guido D'Orsi
f4c2501b06 chore: move auth hook in useInJazzAuth 2025-01-17 18:18:24 +01:00
Guido D'Orsi
9161229474 chore: revert the changes on the todo example 2025-01-17 18:17:46 +01:00
Guido D'Orsi
265f2f40bf fix: fix passkey auth cancelation and add tests 2025-01-17 17:50:35 +01:00
Guido D'Orsi
d2935ac2ae feat: make clerk auth compatible with passkeys 2025-01-17 14:49:25 +01:00
Guido D'Orsi
aaf00b8a20 feat: update starter example with anonymous auth 2025-01-17 14:49:25 +01:00
Guido D'Orsi
f9c6a49d2a feat: onboarding auth on todo example 2025-01-17 14:49:25 +01:00
Guido D'Orsi
2f54a48a3d feat: make auth code disappear from the React setup 2025-01-17 14:49:25 +01:00
Guido D'Orsi
be4dd0a787 feat: centralize auth secret management 2025-01-17 14:49:25 +01:00
Guido D'Orsi
f3f072e7cf feat: improve login/signup code and better UX on the music player auth 2025-01-17 14:49:24 +01:00
Guido D'Orsi
a6270bf552 feat: add onboarding user upgrade to Passkey and Clerk auth 2025-01-17 14:49:24 +01:00
204 changed files with 3252 additions and 5123 deletions

View File

@@ -1,82 +1,5 @@
# chat-rn-clerk
## 1.0.59
### Patch Changes
- jazz-react-native@0.9.18
- jazz-react-native-auth-clerk@0.9.18
- jazz-tools@0.9.18
- jazz-react-native-media-images@0.9.18
## 1.0.58
### Patch Changes
- Updated dependencies [c2ca1fe]
- Updated dependencies [1227047]
- jazz-tools@0.9.17
- jazz-react-native@0.9.17
- jazz-react-native-auth-clerk@0.9.17
- jazz-react-native-media-images@0.9.17
## 1.0.57
### Patch Changes
- Updated dependencies [24b3b6a]
- jazz-react-native-auth-clerk@0.9.16
- jazz-tools@0.9.16
- jazz-react-native@0.9.16
- jazz-react-native-media-images@0.9.16
## 1.0.56
### Patch Changes
- Updated dependencies [7491711]
- jazz-tools@0.9.15
- jazz-react-native@0.9.15
- jazz-react-native-auth-clerk@0.9.15
- jazz-react-native-media-images@0.9.15
## 1.0.55
### Patch Changes
- Updated dependencies [3df93cc]
- jazz-tools@0.9.14
- jazz-react-native@0.9.14
- jazz-react-native-auth-clerk@0.9.14
- jazz-react-native-media-images@0.9.14
## 1.0.54
### Patch Changes
- jazz-react-native@0.9.13
- jazz-react-native-auth-clerk@0.9.13
- jazz-tools@0.9.13
- jazz-react-native-media-images@0.9.13
## 1.0.53
### Patch Changes
- jazz-react-native@0.9.12
- jazz-react-native-auth-clerk@0.9.12
- jazz-tools@0.9.12
- jazz-react-native-media-images@0.9.12
## 1.0.52
### Patch Changes
- jazz-react-native@0.9.11
- jazz-react-native-auth-clerk@0.9.11
- jazz-tools@0.9.11
- jazz-react-native-media-images@0.9.11
## 1.0.51
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "chat-rn-clerk",
"main": "index.js",
"version": "1.0.59",
"version": "1.0.51",
"scripts": {
"build": "expo export -p ios",
"start": "expo start",

View File

@@ -1,7 +1,13 @@
import { useClerk, useUser } from "@clerk/clerk-expo";
import { JazzProvider, setupKvStore } from "jazz-react-native";
import { useJazzClerkAuth } from "jazz-react-native-auth-clerk";
import React, { createContext, PropsWithChildren, useContext } from "react";
import React, {
createContext,
PropsWithChildren,
useContext,
useEffect,
useState,
} from "react";
import { Text, View } from "react-native";
const AuthContext = createContext<{
isAuthenticated: boolean;
@@ -21,7 +27,15 @@ export function JazzAndAuth({ children }: PropsWithChildren) {
const { isSignedIn, isLoaded: isClerkLoaded } = useUser();
const clerk = useClerk();
const [auth, state] = useJazzClerkAuth(clerk, kvStore);
const isAuthenticated = Boolean(isSignedIn && isClerkLoaded && auth);
const [isAuthenticated, setIsAuthenticated] = useState(false);
useEffect(() => {
if (isSignedIn && isClerkLoaded && auth) {
setIsAuthenticated(true);
} else {
setIsAuthenticated(false);
}
}, [isSignedIn, isClerkLoaded, auth]);
return (
<AuthContext.Provider

View File

@@ -1,66 +1,5 @@
# chat-rn
## 1.0.56
### Patch Changes
- jazz-react-native@0.9.18
- jazz-tools@0.9.18
## 1.0.55
### Patch Changes
- Updated dependencies [c2ca1fe]
- Updated dependencies [1227047]
- jazz-tools@0.9.17
- jazz-react-native@0.9.17
## 1.0.54
### Patch Changes
- Updated dependencies [24b3b6a]
- jazz-tools@0.9.16
- jazz-react-native@0.9.16
## 1.0.53
### Patch Changes
- Updated dependencies [7491711]
- jazz-tools@0.9.15
- jazz-react-native@0.9.15
## 1.0.52
### Patch Changes
- Updated dependencies [3df93cc]
- jazz-tools@0.9.14
- jazz-react-native@0.9.14
## 1.0.51
### Patch Changes
- jazz-react-native@0.9.13
- jazz-tools@0.9.13
## 1.0.50
### Patch Changes
- jazz-react-native@0.9.12
- jazz-tools@0.9.12
## 1.0.49
### Patch Changes
- jazz-react-native@0.9.11
- jazz-tools@0.9.11
## 1.0.48
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "chat-rn",
"version": "1.0.56",
"version": "1.0.48",
"main": "index.js",
"scripts": {
"build": "expo export -p ios",

View File

@@ -1,74 +1,5 @@
# chat-vue
## 0.0.43
### Patch Changes
- jazz-browser@0.9.18
- jazz-tools@0.9.18
- jazz-vue@0.9.18
## 0.0.42
### Patch Changes
- Updated dependencies [c2ca1fe]
- Updated dependencies [1227047]
- jazz-tools@0.9.17
- jazz-browser@0.9.17
- jazz-vue@0.9.17
## 0.0.41
### Patch Changes
- Updated dependencies [24b3b6a]
- jazz-tools@0.9.16
- jazz-browser@0.9.16
- jazz-vue@0.9.16
## 0.0.40
### Patch Changes
- Updated dependencies [7491711]
- jazz-tools@0.9.15
- jazz-browser@0.9.15
- jazz-vue@0.9.15
## 0.0.39
### Patch Changes
- Updated dependencies [3df93cc]
- jazz-tools@0.9.14
- jazz-browser@0.9.14
- jazz-vue@0.9.14
## 0.0.38
### Patch Changes
- jazz-browser@0.9.13
- jazz-tools@0.9.13
- jazz-vue@0.9.13
## 0.0.37
### Patch Changes
- jazz-browser@0.9.12
- jazz-tools@0.9.12
- jazz-vue@0.9.12
## 0.0.36
### Patch Changes
- jazz-browser@0.9.11
- jazz-tools@0.9.11
- jazz-vue@0.9.11
## 0.0.35
### Patch Changes

View File

@@ -11,6 +11,10 @@ You can either
Create a new Jazz project, and use this example as a template.
```bash
npm create jazz-app@latest --example chat-vue --project-name chat-vue
```
or
```bash
npx create-jazz-app@latest --example chat-vue --project-name chat-vue
```

View File

@@ -1,6 +1,6 @@
{
"name": "chat-vue",
"version": "0.0.43",
"version": "0.0.35",
"private": true,
"type": "module",
"scripts": {

View File

@@ -1,74 +1,5 @@
# jazz-example-chat
## 0.0.139
### Patch Changes
- jazz-react@0.9.18
- jazz-tools@0.9.18
- jazz-browser-media-images@0.9.18
## 0.0.138
### Patch Changes
- Updated dependencies [c2ca1fe]
- Updated dependencies [1227047]
- jazz-tools@0.9.17
- jazz-browser-media-images@0.9.17
- jazz-react@0.9.17
## 0.0.137
### Patch Changes
- Updated dependencies [24b3b6a]
- jazz-tools@0.9.16
- jazz-browser-media-images@0.9.16
- jazz-react@0.9.16
## 0.0.136
### Patch Changes
- Updated dependencies [7491711]
- jazz-tools@0.9.15
- jazz-browser-media-images@0.9.15
- jazz-react@0.9.15
## 0.0.135
### Patch Changes
- Updated dependencies [3df93cc]
- jazz-tools@0.9.14
- jazz-browser-media-images@0.9.14
- jazz-react@0.9.14
## 0.0.134
### Patch Changes
- jazz-react@0.9.13
- jazz-tools@0.9.13
- jazz-browser-media-images@0.9.13
## 0.0.133
### Patch Changes
- jazz-react@0.9.12
- jazz-tools@0.9.12
- jazz-browser-media-images@0.9.12
## 0.0.132
### Patch Changes
- jazz-react@0.9.11
- jazz-tools@0.9.11
- jazz-browser-media-images@0.9.11
## 0.0.131
### Patch Changes

View File

@@ -13,6 +13,10 @@ You can either
Create a new Jazz project, and use this example as a template.
```bash
npm create jazz-app@latest --example chat --project-name chat
```
or
```bash
npx create-jazz-app@latest --example chat --project-name chat
```

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-chat",
"private": true,
"version": "0.0.139",
"version": "0.0.131",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,74 +1,5 @@
# minimal-auth-clerk
## 0.0.38
### Patch Changes
- jazz-react@0.9.18
- jazz-react-auth-clerk@0.9.18
- jazz-tools@0.9.18
## 0.0.37
### Patch Changes
- Updated dependencies [c2ca1fe]
- Updated dependencies [1227047]
- jazz-tools@0.9.17
- jazz-react@0.9.17
- jazz-react-auth-clerk@0.9.17
## 0.0.36
### Patch Changes
- Updated dependencies [24b3b6a]
- jazz-react-auth-clerk@0.9.16
- jazz-tools@0.9.16
- jazz-react@0.9.16
## 0.0.35
### Patch Changes
- Updated dependencies [7491711]
- jazz-tools@0.9.15
- jazz-react@0.9.15
- jazz-react-auth-clerk@0.9.15
## 0.0.34
### Patch Changes
- Updated dependencies [3df93cc]
- jazz-tools@0.9.14
- jazz-react@0.9.14
- jazz-react-auth-clerk@0.9.14
## 0.0.33
### Patch Changes
- jazz-react@0.9.13
- jazz-react-auth-clerk@0.9.13
- jazz-tools@0.9.13
## 0.0.32
### Patch Changes
- jazz-react@0.9.12
- jazz-react-auth-clerk@0.9.12
- jazz-tools@0.9.12
## 0.0.31
### Patch Changes
- jazz-react@0.9.11
- jazz-react-auth-clerk@0.9.11
- jazz-tools@0.9.11
## 0.0.30
### Patch Changes

View File

@@ -15,7 +15,11 @@ You can either
Create a new Jazz project, and use this example as a template.
```bash
npx create-jazz-app@latest --example clerk --project-name clerk
npm create jazz-app@latest --start clerk --project-name clerk
```
or
```bash
npx create-jazz-app@latest --start clerk --project-name clerk
```
Go to the new project directory.

View File

@@ -1,7 +1,7 @@
{
"name": "clerk",
"private": true,
"version": "0.0.38",
"version": "0.0.30",
"type": "module",
"scripts": {
"dev": "vite",
@@ -13,7 +13,7 @@
"dependencies": {
"@clerk/clerk-react": "^5.4.1",
"jazz-react": "workspace:*",
"jazz-react-auth-clerk": "workspace:0.9.18",
"jazz-react-auth-clerk": "workspace:0.9.10",
"jazz-tools": "workspace:*",
"react": "^18.3.1",
"react-dom": "^18.3.1"

View File

@@ -1,66 +1,5 @@
# file-share-svelte
## 0.0.23
### Patch Changes
- jazz-svelte@0.9.18
- jazz-tools@0.9.18
## 0.0.22
### Patch Changes
- Updated dependencies [c2ca1fe]
- Updated dependencies [1227047]
- jazz-tools@0.9.17
- jazz-svelte@0.9.17
## 0.0.21
### Patch Changes
- Updated dependencies [24b3b6a]
- jazz-tools@0.9.16
- jazz-svelte@0.9.16
## 0.0.20
### Patch Changes
- Updated dependencies [7491711]
- jazz-tools@0.9.15
- jazz-svelte@0.9.15
## 0.0.19
### Patch Changes
- Updated dependencies [3df93cc]
- jazz-tools@0.9.14
- jazz-svelte@0.9.14
## 0.0.18
### Patch Changes
- jazz-svelte@0.9.13
- jazz-tools@0.9.13
## 0.0.17
### Patch Changes
- jazz-svelte@0.9.12
- jazz-tools@0.9.12
## 0.0.16
### Patch Changes
- jazz-svelte@0.9.11
- jazz-tools@0.9.11
## 0.0.15
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "file-share-svelte",
"version": "0.0.23",
"version": "0.0.15",
"private": true,
"type": "module",
"scripts": {

View File

@@ -1,74 +1,5 @@
# form
## 0.0.34
### Patch Changes
- jazz-react@0.9.18
- jazz-tools@0.9.18
- jazz-browser-media-images@0.9.18
## 0.0.33
### Patch Changes
- Updated dependencies [c2ca1fe]
- Updated dependencies [1227047]
- jazz-tools@0.9.17
- jazz-browser-media-images@0.9.17
- jazz-react@0.9.17
## 0.0.32
### Patch Changes
- Updated dependencies [24b3b6a]
- jazz-tools@0.9.16
- jazz-browser-media-images@0.9.16
- jazz-react@0.9.16
## 0.0.31
### Patch Changes
- Updated dependencies [7491711]
- jazz-tools@0.9.15
- jazz-browser-media-images@0.9.15
- jazz-react@0.9.15
## 0.0.30
### Patch Changes
- Updated dependencies [3df93cc]
- jazz-tools@0.9.14
- jazz-browser-media-images@0.9.14
- jazz-react@0.9.14
## 0.0.29
### Patch Changes
- jazz-react@0.9.13
- jazz-tools@0.9.13
- jazz-browser-media-images@0.9.13
## 0.0.28
### Patch Changes
- jazz-react@0.9.12
- jazz-tools@0.9.12
- jazz-browser-media-images@0.9.12
## 0.0.27
### Patch Changes
- jazz-react@0.9.11
- jazz-tools@0.9.11
- jazz-browser-media-images@0.9.11
## 0.0.26
### Patch Changes

View File

@@ -28,7 +28,11 @@ You can either
Create a new Jazz project, and use this example as a template.
```bash
npx create-jazz-app@latest --example form --project-name form
npm create jazz-app@latest --start form --project-name form
```
or
```bash
npx create-jazz-app@latest --start form --project-name form
```
Go to the new project directory.

View File

@@ -1,7 +1,7 @@
{
"name": "form",
"private": true,
"version": "0.0.34",
"version": "0.0.26",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,74 +1,5 @@
# image-upload
## 0.0.36
### Patch Changes
- jazz-react@0.9.18
- jazz-tools@0.9.18
- jazz-browser-media-images@0.9.18
## 0.0.35
### Patch Changes
- Updated dependencies [c2ca1fe]
- Updated dependencies [1227047]
- jazz-tools@0.9.17
- jazz-browser-media-images@0.9.17
- jazz-react@0.9.17
## 0.0.34
### Patch Changes
- Updated dependencies [24b3b6a]
- jazz-tools@0.9.16
- jazz-browser-media-images@0.9.16
- jazz-react@0.9.16
## 0.0.33
### Patch Changes
- Updated dependencies [7491711]
- jazz-tools@0.9.15
- jazz-browser-media-images@0.9.15
- jazz-react@0.9.15
## 0.0.32
### Patch Changes
- Updated dependencies [3df93cc]
- jazz-tools@0.9.14
- jazz-browser-media-images@0.9.14
- jazz-react@0.9.14
## 0.0.31
### Patch Changes
- jazz-react@0.9.13
- jazz-tools@0.9.13
- jazz-browser-media-images@0.9.13
## 0.0.30
### Patch Changes
- jazz-react@0.9.12
- jazz-tools@0.9.12
- jazz-browser-media-images@0.9.12
## 0.0.29
### Patch Changes
- jazz-react@0.9.11
- jazz-tools@0.9.11
- jazz-browser-media-images@0.9.11
## 0.0.28
### Patch Changes

View File

@@ -15,6 +15,10 @@ You can either
Create a new Jazz project, and use this example as a template.
```bash
npm create jazz-app@latest --example image-upload --project-name image-upload
```
or
```bash
npx create-jazz-app@latest --example image-upload --project-name image-upload
```

View File

@@ -1,7 +1,7 @@
{
"name": "image-upload",
"private": true,
"version": "0.0.36",
"version": "0.0.28",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,38 +1,5 @@
# jazz-example-inspector
## 0.0.99
### Patch Changes
- Updated dependencies [8898b10]
- cojson@0.9.18
- cojson-transport-ws@0.9.18
## 0.0.98
### Patch Changes
- Updated dependencies [8d29e50]
- cojson-transport-ws@0.9.13
- cojson@0.9.13
## 0.0.97
### Patch Changes
- Updated dependencies [15d4b2a]
- cojson-transport-ws@0.9.12
- cojson@0.9.12
## 0.0.96
### Patch Changes
- Updated dependencies [efbf3d8]
- Updated dependencies [5863bad]
- cojson@0.9.11
- cojson-transport-ws@0.9.11
## 0.0.95
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-inspector-app",
"private": true,
"version": "0.0.99",
"version": "0.0.95",
"type": "module",
"scripts": {
"dev": "vite",
@@ -16,8 +16,8 @@
"@radix-ui/react-toast": "^1.1.4",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"cojson": "workspace:0.9.18",
"cojson-transport-ws": "workspace:0.9.18",
"cojson": "workspace:0.9.10",
"cojson-transport-ws": "workspace:0.9.10",
"hash-slash": "workspace:0.2.1",
"lucide-react": "^0.274.0",
"qrcode": "^1.5.3",

View File

@@ -1,74 +1,5 @@
# jazz-example-musicplayer
## 0.0.59
### Patch Changes
- jazz-inspector@0.9.18
- jazz-react@0.9.18
- jazz-tools@0.9.18
## 0.0.58
### Patch Changes
- Updated dependencies [c2ca1fe]
- Updated dependencies [1227047]
- jazz-tools@0.9.17
- jazz-inspector@0.9.17
- jazz-react@0.9.17
## 0.0.57
### Patch Changes
- Updated dependencies [24b3b6a]
- jazz-tools@0.9.16
- jazz-inspector@0.9.16
- jazz-react@0.9.16
## 0.0.56
### Patch Changes
- Updated dependencies [7491711]
- jazz-tools@0.9.15
- jazz-inspector@0.9.15
- jazz-react@0.9.15
## 0.0.55
### Patch Changes
- Updated dependencies [3df93cc]
- jazz-tools@0.9.14
- jazz-inspector@0.9.14
- jazz-react@0.9.14
## 0.0.54
### Patch Changes
- jazz-inspector@0.9.13
- jazz-react@0.9.13
- jazz-tools@0.9.13
## 0.0.53
### Patch Changes
- jazz-inspector@0.9.12
- jazz-react@0.9.12
- jazz-tools@0.9.12
## 0.0.52
### Patch Changes
- jazz-inspector@0.9.11
- jazz-react@0.9.11
- jazz-tools@0.9.11
## 0.0.51
### Patch Changes

View File

@@ -13,6 +13,10 @@ You can either
Create a new Jazz project, and use this example as a template.
```bash
npm create jazz-app@latest --example music-player --project-name music-player
```
or
```bash
npx create-jazz-app@latest --example music-player --project-name music-player
```

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-music-player",
"private": true,
"version": "0.0.59",
"version": "0.0.51",
"type": "module",
"scripts": {
"dev": "vite",
@@ -13,13 +13,16 @@
"test:ui": "playwright test --ui"
},
"dependencies": {
"@radix-ui/react-dialog": "^1.1.4",
"@radix-ui/react-dropdown-menu": "^2.1.1",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-label": "^2.1.1",
"@radix-ui/react-slot": "^1.1.1",
"@radix-ui/react-toast": "^1.1.4",
"@radix-ui/react-tooltip": "^1.1.6",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"jazz-react": "workspace:0.9.18",
"jazz-tools": "workspace:0.9.18",
"jazz-react": "workspace:0.9.10",
"jazz-tools": "workspace:0.9.10",
"jazz-inspector": "workspace:*",
"lucide-react": "^0.274.0",
"react": "^18.3.1",

View File

@@ -85,7 +85,7 @@ export class MusicaAccount extends Account {
* The account migration is run on account creation and on every log-in.
* You can use it to set up the account root and any other initial CoValues you need.
*/
migrate() {
migrate(this: MusicaAccount) {
if (!this._refs.root) {
const ownership = { owner: this };

View File

@@ -11,7 +11,7 @@ import { PlayerControls } from "./components/PlayerControls";
import "./index.css";
import { MusicaAccount } from "@/1_schema";
import { DemoAuthBasicUI, JazzProvider, useDemoAuth } from "jazz-react";
import { JazzProvider, useIsAnonymousUser } from "jazz-react";
import { useUploadExampleData } from "./lib/useUploadExampleData";
/**
@@ -55,27 +55,24 @@ function Main() {
}
function JazzAndAuth({ children }: { children: React.ReactNode }) {
const [auth, state] = useDemoAuth();
const peer =
(new URL(window.location.href).searchParams.get(
"peer",
) as `ws://${string}`) ??
"wss://cloud.jazz.tools/?key=music-player-example-jazz@garden.co";
const isAnonymous = useIsAnonymousUser();
return (
<>
<JazzProvider
storage="indexedDB"
auth={auth}
peer={peer}
AccountSchema={MusicaAccount}
>
{children}
<JazzInspector />
</JazzProvider>
<DemoAuthBasicUI appName="Jazz Music Player" state={state} />
</>
<JazzProvider
storage="indexedDB"
peer={peer}
localOnly={isAnonymous}
AccountSchema={MusicaAccount}
>
{children}
<JazzInspector />
</JazzProvider>
);
}

View File

@@ -1,12 +1,17 @@
import { useToast } from "@/hooks/use-toast";
import { createInviteLink, useAccount, useCoState } from "jazz-react";
import {
createInviteLink,
useAccount,
useCoState,
useIsAnonymousUser,
} from "jazz-react";
import { ID } from "jazz-tools";
import { useNavigate, useParams } from "react-router";
import { Playlist } from "./1_schema";
import { createNewPlaylist, uploadMusicTracks } from "./4_actions";
import { MediaPlayer } from "./5_useMediaPlayer";
import { AuthButton } from "./components/AuthButton";
import { FileUploadButton } from "./components/FileUploadButton";
import { LogoutButton } from "./components/LogoutButton";
import { MusicTrackRow } from "./components/MusicTrackRow";
import { PlaylistTitleInput } from "./components/PlaylistTitleInput";
import { SidePanel } from "./components/SidePanel";
@@ -66,6 +71,8 @@ export function HomePage({ mediaPlayer }: { mediaPlayer: MediaPlayer }) {
});
};
const isAnonymousUser = useIsAnonymousUser();
return (
<div className="flex flex-col h-screen text-gray-800 bg-blue-50">
<div className="flex flex-1 overflow-hidden">
@@ -86,12 +93,12 @@ export function HomePage({ mediaPlayer }: { mediaPlayer: MediaPlayer }) {
<Button onClick={handleCreatePlaylist}>New playlist</Button>
</>
)}
{!isRootPlaylist && (
{!isRootPlaylist && !isAnonymousUser && (
<Button onClick={handlePlaylistShareClick}>
Share playlist
</Button>
)}
<LogoutButton />
<AuthButton />
</div>
</div>
<ul className="flex flex-col">

View File

@@ -0,0 +1,40 @@
"use client";
import { Button } from "@/components/ui/button";
import { useAccount, useIsAnonymousUser } from "jazz-react";
import { useState } from "react";
import { useNavigate } from "react-router-dom";
import { AuthModal } from "./AuthModal";
export function AuthButton() {
const [open, setOpen] = useState(false);
const { logOut } = useAccount();
const navigate = useNavigate();
const isOnboarding = useIsAnonymousUser();
function handleSignOut() {
logOut();
navigate("/");
}
if (!isOnboarding) {
return (
<Button variant="outline" onClick={handleSignOut}>
Sign out
</Button>
);
}
return (
<>
<Button
onClick={() => setOpen(true)}
className="bg-white text-black hover:bg-gray-100"
>
Sign up
</Button>
<AuthModal open={open} onOpenChange={setOpen} />
</>
);
}

View File

@@ -0,0 +1,112 @@
import { Button } from "@/components/ui/button";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { useAccount, usePasskeyAuth } from "jazz-react";
import { Loader2 } from "lucide-react";
import { useState } from "react";
interface AuthModalProps {
open: boolean;
onOpenChange: (open: boolean) => void;
}
export function AuthModal({ open, onOpenChange }: AuthModalProps) {
const [username, setUsername] = useState("");
const [isSignUp, setIsSignUp] = useState(true);
const { me } = useAccount();
const [, authState] = usePasskeyAuth({
appName: "Jazz Music Player",
onAnonymousUserUpgrade: ({ username, isSignUp }) => {
if (isSignUp) {
me.profile!.name = username;
}
onOpenChange(false);
},
});
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (authState.state === "ready") {
if (isSignUp) {
authState.signUp(username);
} else {
authState.logIn();
}
}
};
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-[425px]">
<DialogHeader>
<DialogTitle className="text-2xl font-bold">
{isSignUp ? "Create account" : "Welcome back"}
</DialogTitle>
{authState.state === "ready" && (
<DialogDescription>
{isSignUp
? "Sign up to enable network sync and share your playlists with others"
: "Changes done before logging in will be lost"}
</DialogDescription>
)}
</DialogHeader>
<form onSubmit={handleSubmit} className="space-y-4">
{isSignUp && (
<div className="space-y-2">
<Label htmlFor="username">Username</Label>
<Input
id="username"
value={username}
onChange={(e) => setUsername(e.target.value)}
placeholder="Enter your username"
required
/>
</div>
)}
{authState.errors.length > 0 && (
<div className="text-sm text-red-500">
{authState.errors.map((error, i) => (
<p key={i}>{error}</p>
))}
</div>
)}
<div className="space-y-4">
<Button
type="submit"
className="w-full bg-blue-600 hover:bg-blue-700"
disabled={authState.state === "loading"}
>
{authState.state === "loading" ? (
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
) : isSignUp ? (
"Sign up with passkey"
) : (
"Login with passkey"
)}
</Button>
<div className="text-center text-sm">
{isSignUp ? "Already have an account?" : "Don't have an account?"}{" "}
<button
type="button"
onClick={() => setIsSignUp(!isSignUp)}
className="text-blue-600 hover:underline"
>
{isSignUp ? "Login" : "Sign up"}
</button>
</div>
</div>
</form>
</DialogContent>
</Dialog>
);
}

View File

@@ -0,0 +1,37 @@
import { Badge } from "@/components/ui/badge";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { useIsAnonymousUser } from "jazz-react";
import { Info } from "lucide-react";
export function LocalOnlyTag() {
const isAnonymousUser = useIsAnonymousUser();
if (!isAnonymousUser) {
return null;
}
return (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<div className="inline-flex items-center gap-1.5 cursor-help">
<Badge variant="default" className="h-5 text-xs font-normal">
Local only
</Badge>
<Info className="h-3.5 w-3.5 text-muted-foreground" />
</div>
</TooltipTrigger>
<TooltipContent className="max-w-[250px]">
<p>
Sign up to enable network sync and share your playlists with others
</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
);
}

View File

@@ -1,5 +1,6 @@
import { useAccount } from "jazz-react";
import { useNavigate, useParams } from "react-router";
import { LocalOnlyTag } from "./LocalOnlyTag";
export function SidePanel() {
const { playlistId } = useParams();
@@ -25,7 +26,7 @@ export function SidePanel() {
return (
<aside className="w-64 p-6 bg-white overflow-y-auto">
<div className="flex items-center mb-6">
<div className="flex items-center mb-1">
<svg
className="w-8 h-8 mr-2"
viewBox="0 0 24 24"
@@ -46,6 +47,9 @@ export function SidePanel() {
</svg>
<span className="text-xl font-bold text-blue-600">Music Player</span>
</div>
<div className="mb-6">
<LocalOnlyTag />
</div>
<nav>
<h2 className="mb-2 text-sm font-semibold text-gray-600">Playlists</h2>
<ul className="space-y-1">

View File

@@ -0,0 +1,36 @@
import { type VariantProps, cva } from "class-variance-authority";
import * as React from "react";
import { cn } from "@/lib/utils";
const badgeVariants = cva(
"inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
{
variants: {
variant: {
default:
"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",
secondary:
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
destructive:
"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",
outline: "text-foreground",
},
},
defaultVariants: {
variant: "default",
},
},
);
export interface BadgeProps
extends React.HTMLAttributes<HTMLDivElement>,
VariantProps<typeof badgeVariants> {}
function Badge({ className, variant, ...props }: BadgeProps) {
return (
<div className={cn(badgeVariants({ variant }), className)} {...props} />
);
}
export { Badge, badgeVariants };

View File

@@ -0,0 +1,120 @@
import * as DialogPrimitive from "@radix-ui/react-dialog";
import { X } from "lucide-react";
import * as React from "react";
import { cn } from "@/lib/utils";
const Dialog = DialogPrimitive.Root;
const DialogTrigger = DialogPrimitive.Trigger;
const DialogPortal = DialogPrimitive.Portal;
const DialogClose = DialogPrimitive.Close;
const DialogOverlay = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Overlay
ref={ref}
className={cn(
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className,
)}
{...props}
/>
));
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
const DialogContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
>(({ className, children, ...props }, ref) => (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Content
ref={ref}
className={cn(
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
className,
)}
{...props}
>
{children}
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
<X className="h-4 w-4" />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
</DialogPrimitive.Content>
</DialogPortal>
));
DialogContent.displayName = DialogPrimitive.Content.displayName;
const DialogHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col space-y-1.5 text-center sm:text-left",
className,
)}
{...props}
/>
);
DialogHeader.displayName = "DialogHeader";
const DialogFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
className,
)}
{...props}
/>
);
DialogFooter.displayName = "DialogFooter";
const DialogTitle = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Title
ref={ref}
className={cn(
"text-lg font-semibold leading-none tracking-tight",
className,
)}
{...props}
/>
));
DialogTitle.displayName = DialogPrimitive.Title.displayName;
const DialogDescription = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Description
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
));
DialogDescription.displayName = DialogPrimitive.Description.displayName;
export {
Dialog,
DialogPortal,
DialogOverlay,
DialogClose,
DialogTrigger,
DialogContent,
DialogHeader,
DialogFooter,
DialogTitle,
DialogDescription,
};

View File

@@ -0,0 +1,22 @@
import * as React from "react";
import { cn } from "@/lib/utils";
const Input = React.forwardRef<HTMLInputElement, React.ComponentProps<"input">>(
({ className, type, ...props }, ref) => {
return (
<input
type={type}
className={cn(
"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
className,
)}
ref={ref}
{...props}
/>
);
},
);
Input.displayName = "Input";
export { Input };

View File

@@ -0,0 +1,24 @@
import * as LabelPrimitive from "@radix-ui/react-label";
import { type VariantProps, cva } from "class-variance-authority";
import * as React from "react";
import { cn } from "@/lib/utils";
const labelVariants = cva(
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
);
const Label = React.forwardRef<
React.ElementRef<typeof LabelPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
VariantProps<typeof labelVariants>
>(({ className, ...props }, ref) => (
<LabelPrimitive.Root
ref={ref}
className={cn(labelVariants(), className)}
{...props}
/>
));
Label.displayName = LabelPrimitive.Root.displayName;
export { Label };

View File

@@ -0,0 +1,30 @@
"use client";
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
import * as React from "react";
import { cn } from "@/lib/utils";
const TooltipProvider = TooltipPrimitive.Provider;
const Tooltip = TooltipPrimitive.Root;
const TooltipTrigger = TooltipPrimitive.Trigger;
const TooltipContent = React.forwardRef<
React.ElementRef<typeof TooltipPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
>(({ className, sideOffset = 4, ...props }, ref) => (
<TooltipPrimitive.Content
ref={ref}
sideOffset={sideOffset}
className={cn(
"z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
className,
)}
{...props}
/>
));
TooltipContent.displayName = TooltipPrimitive.Content.displayName;
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };

View File

@@ -1,44 +1,81 @@
import { test } from "@playwright/test";
import { BrowserContext, test } from "@playwright/test";
import { HomePage } from "./pages/HomePage";
import { LoginPage } from "./pages/LoginPage";
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
test("create a new playlist and share", async ({ page }) => {
const loginPage = new LoginPage(page);
async function mockAuthenticator(context: BrowserContext) {
await context.addInitScript(() => {
Object.defineProperty(window.navigator, "credentials", {
value: {
...window.navigator.credentials,
create: async () => ({
type: "public-key",
id: new Uint8Array([1, 2, 3, 4]),
rawId: new Uint8Array([1, 2, 3, 4]),
response: {
clientDataJSON: new Uint8Array([1]),
attestationObject: new Uint8Array([2]),
},
}),
get: async () => ({
type: "public-key",
id: new Uint8Array([1, 2, 3, 4]),
rawId: new Uint8Array([1, 2, 3, 4]),
response: {
authenticatorData: new Uint8Array([1]),
clientDataJSON: new Uint8Array([2]),
signature: new Uint8Array([3]),
},
}),
},
configurable: true,
});
});
}
await loginPage.goto();
await loginPage.fillUsername("S. Mario");
await loginPage.signup();
// Configure the authenticator
test.beforeEach(async ({ context }) => {
// Enable virtual authenticator environment
await mockAuthenticator(context);
});
const homePage = new HomePage(page);
test("create a new playlist and share", async ({
page: marioPage,
browser,
}) => {
await marioPage.goto("/");
const marioHome = new HomePage(marioPage);
// The example song should be loaded
await homePage.expectMusicTrack("Example song");
await homePage.editTrackTitle("Example song", "Super Mario World");
await marioHome.expectMusicTrack("Example song");
await marioHome.editTrackTitle("Example song", "Super Mario World");
await homePage.createPlaylist();
await homePage.editPlaylistTitle("Save the princess");
await marioHome.createPlaylist();
await marioHome.editPlaylistTitle("Save the princess");
await homePage.navigateToPlaylist("All tracks");
await homePage.addTrackToPlaylist("Super Mario World", "Save the princess");
await marioHome.navigateToPlaylist("All tracks");
await marioHome.addTrackToPlaylist("Super Mario World", "Save the princess");
await homePage.navigateToPlaylist("Save the princess");
await homePage.expectMusicTrack("Super Mario World");
await marioHome.navigateToPlaylist("Save the princess");
await marioHome.expectMusicTrack("Super Mario World");
const url = await homePage.getShareLink();
await marioHome.signUp("Mario");
const url = await marioHome.getShareLink();
await sleep(4000); // Wait for the sync to complete
await homePage.logout();
const luigiPage = await (await browser.newContext()).newPage();
await luigiPage.goto("/");
await loginPage.goto();
await loginPage.fillUsername("Luigi");
await loginPage.signup();
const luigiHome = new HomePage(luigiPage);
await page.goto(url);
await luigiHome.signUp("Luigi");
await homePage.expectMusicTrack("Super Mario World");
await homePage.playMusicTrack("Super Mario World");
await homePage.expectActiveTrackPlaying();
await luigiPage.goto(url);
await luigiHome.expectMusicTrack("Super Mario World");
await luigiHome.playMusicTrack("Super Mario World");
await luigiHome.expectActiveTrackPlaying();
});

View File

@@ -95,6 +95,14 @@ export class HomePage {
.click();
}
async signUp(name: string) {
await this.page.getByRole("button", { name: "Sign up" }).click();
await this.page.getByRole("textbox", { name: "Username" }).fill(name);
await this.page
.getByRole("button", { name: "Sign up with passkey" })
.click();
}
async logout() {
await this.logoutButton.click();
}

View File

@@ -1,40 +0,0 @@
import { Locator, Page, expect } from "@playwright/test";
export class LoginPage {
readonly page: Page;
readonly usernameInput: Locator;
readonly signupButton: Locator;
constructor(page: Page) {
this.page = page;
this.usernameInput = page.getByRole("textbox");
this.signupButton = page.getByRole("button", {
name: "Sign up",
});
}
async goto() {
this.page.goto("/");
}
async fillUsername(value: string) {
await this.usernameInput.clear();
await this.usernameInput.fill(value);
}
async loginAs(value: string) {
await this.page
.getByRole("button", {
name: value,
})
.click();
}
async signup() {
await this.signupButton.click();
}
async expectLoaded() {
await expect(this.signupButton).toBeVisible();
}
}

View File

@@ -1,74 +1,5 @@
# jazz-example-onboarding
## 0.0.40
### Patch Changes
- jazz-react@0.9.18
- jazz-tools@0.9.18
- jazz-browser-media-images@0.9.18
## 0.0.39
### Patch Changes
- Updated dependencies [c2ca1fe]
- Updated dependencies [1227047]
- jazz-tools@0.9.17
- jazz-browser-media-images@0.9.17
- jazz-react@0.9.17
## 0.0.38
### Patch Changes
- Updated dependencies [24b3b6a]
- jazz-tools@0.9.16
- jazz-browser-media-images@0.9.16
- jazz-react@0.9.16
## 0.0.37
### Patch Changes
- Updated dependencies [7491711]
- jazz-tools@0.9.15
- jazz-browser-media-images@0.9.15
- jazz-react@0.9.15
## 0.0.36
### Patch Changes
- Updated dependencies [3df93cc]
- jazz-tools@0.9.14
- jazz-browser-media-images@0.9.14
- jazz-react@0.9.14
## 0.0.35
### Patch Changes
- jazz-react@0.9.13
- jazz-tools@0.9.13
- jazz-browser-media-images@0.9.13
## 0.0.34
### Patch Changes
- jazz-react@0.9.12
- jazz-tools@0.9.12
- jazz-browser-media-images@0.9.12
## 0.0.33
### Patch Changes
- jazz-react@0.9.11
- jazz-tools@0.9.11
- jazz-browser-media-images@0.9.11
## 0.0.32
### Patch Changes

View File

@@ -11,6 +11,10 @@ You can either
Create a new Jazz project, and use this example as a template.
```bash
npm create jazz-app@latest --example onboarding --project-name onboarding
```
or
```bash
npx create-jazz-app@latest --example onboarding --project-name onboarding
```

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-onboarding",
"private": true,
"version": "0.0.40",
"version": "0.0.32",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,66 +1,5 @@
# organization
## 0.0.32
### Patch Changes
- jazz-react@0.9.18
- jazz-tools@0.9.18
## 0.0.31
### Patch Changes
- Updated dependencies [c2ca1fe]
- Updated dependencies [1227047]
- jazz-tools@0.9.17
- jazz-react@0.9.17
## 0.0.30
### Patch Changes
- Updated dependencies [24b3b6a]
- jazz-tools@0.9.16
- jazz-react@0.9.16
## 0.0.29
### Patch Changes
- Updated dependencies [7491711]
- jazz-tools@0.9.15
- jazz-react@0.9.15
## 0.0.28
### Patch Changes
- Updated dependencies [3df93cc]
- jazz-tools@0.9.14
- jazz-react@0.9.14
## 0.0.27
### Patch Changes
- jazz-react@0.9.13
- jazz-tools@0.9.13
## 0.0.26
### Patch Changes
- jazz-react@0.9.12
- jazz-tools@0.9.12
## 0.0.25
### Patch Changes
- jazz-react@0.9.11
- jazz-tools@0.9.11
## 0.0.24
### Patch Changes

View File

@@ -16,6 +16,10 @@ You can either
Create a new Jazz project, and use this example as a template.
```bash
npm create jazz-app@latest --example organization --project-name organization
```
or
```bash
npx create-jazz-app@latest --example organization --project-name organization
```

View File

@@ -1,7 +1,7 @@
{
"name": "organization",
"private": true,
"version": "0.0.32",
"version": "0.0.24",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,53 +1,5 @@
# passkey-svelte
## 0.0.27
### Patch Changes
- jazz-svelte@0.9.18
## 0.0.26
### Patch Changes
- jazz-svelte@0.9.17
## 0.0.25
### Patch Changes
- jazz-svelte@0.9.16
## 0.0.24
### Patch Changes
- jazz-svelte@0.9.15
## 0.0.23
### Patch Changes
- jazz-svelte@0.9.14
## 0.0.22
### Patch Changes
- jazz-svelte@0.9.13
## 0.0.21
### Patch Changes
- jazz-svelte@0.9.12
## 0.0.20
### Patch Changes
- jazz-svelte@0.9.11
## 0.0.19
### Patch Changes

View File

@@ -21,6 +21,10 @@ You can either
Create a new Jazz project, and use this example as a template.
```bash
npm create jazz-app@latest --example passkey-svelte --project-name passkey-svelte
```
or
```bash
npx create-jazz-app@latest --example passkey-svelte --project-name passkey-svelte
```

View File

@@ -1,6 +1,6 @@
{
"name": "passkey-svelte",
"version": "0.0.27",
"version": "0.0.19",
"type": "module",
"private": true,
"scripts": {

View File

@@ -1,66 +1,5 @@
# minimal-auth-passkey
## 0.0.37
### Patch Changes
- jazz-react@0.9.18
- jazz-tools@0.9.18
## 0.0.36
### Patch Changes
- Updated dependencies [c2ca1fe]
- Updated dependencies [1227047]
- jazz-tools@0.9.17
- jazz-react@0.9.17
## 0.0.35
### Patch Changes
- Updated dependencies [24b3b6a]
- jazz-tools@0.9.16
- jazz-react@0.9.16
## 0.0.34
### Patch Changes
- Updated dependencies [7491711]
- jazz-tools@0.9.15
- jazz-react@0.9.15
## 0.0.33
### Patch Changes
- Updated dependencies [3df93cc]
- jazz-tools@0.9.14
- jazz-react@0.9.14
## 0.0.32
### Patch Changes
- jazz-react@0.9.13
- jazz-tools@0.9.13
## 0.0.31
### Patch Changes
- jazz-react@0.9.12
- jazz-tools@0.9.12
## 0.0.30
### Patch Changes
- jazz-react@0.9.11
- jazz-tools@0.9.11
## 0.0.29
### Patch Changes

View File

@@ -15,6 +15,10 @@ You can either
Create a new Jazz project, and use this example as a template.
```bash
npm create jazz-app@latest --example passkey --project-name passkey
```
or
```bash
npx create-jazz-app@latest --example passkey --project-name passkey
```

View File

@@ -1,7 +1,7 @@
{
"name": "passkey",
"private": true,
"version": "0.0.37",
"version": "0.0.29",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,66 +1,5 @@
# jazz-password-manager
## 0.0.58
### Patch Changes
- jazz-react@0.9.18
- jazz-tools@0.9.18
## 0.0.57
### Patch Changes
- Updated dependencies [c2ca1fe]
- Updated dependencies [1227047]
- jazz-tools@0.9.17
- jazz-react@0.9.17
## 0.0.56
### Patch Changes
- Updated dependencies [24b3b6a]
- jazz-tools@0.9.16
- jazz-react@0.9.16
## 0.0.55
### Patch Changes
- Updated dependencies [7491711]
- jazz-tools@0.9.15
- jazz-react@0.9.15
## 0.0.54
### Patch Changes
- Updated dependencies [3df93cc]
- jazz-tools@0.9.14
- jazz-react@0.9.14
## 0.0.53
### Patch Changes
- jazz-react@0.9.13
- jazz-tools@0.9.13
## 0.0.52
### Patch Changes
- jazz-react@0.9.12
- jazz-tools@0.9.12
## 0.0.51
### Patch Changes
- jazz-react@0.9.11
- jazz-tools@0.9.11
## 0.0.50
### Patch Changes

View File

@@ -15,6 +15,10 @@ You can either
Create a new Jazz project, and use this example as a template.
```bash
npm create jazz-app@latest --example password-manager --project-name password-manager
```
or
```bash
npx create-jazz-app@latest --example password-manager --project-name password-manager
```

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-password-manager",
"private": true,
"version": "0.0.58",
"version": "0.0.50",
"type": "module",
"scripts": {
"dev": "vite",
@@ -12,8 +12,8 @@
"clean-install": "rm -rf node_modules pnpm-lock.yaml && pnpm install"
},
"dependencies": {
"jazz-react": "workspace:0.9.18",
"jazz-tools": "workspace:0.9.18",
"jazz-react": "workspace:0.9.10",
"jazz-tools": "workspace:0.9.10",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-hook-form": "^7.41.5",

View File

@@ -1,74 +1,5 @@
# jazz-example-pets
## 0.0.156
### Patch Changes
- jazz-react@0.9.18
- jazz-tools@0.9.18
- jazz-browser-media-images@0.9.18
## 0.0.155
### Patch Changes
- Updated dependencies [c2ca1fe]
- Updated dependencies [1227047]
- jazz-tools@0.9.17
- jazz-browser-media-images@0.9.17
- jazz-react@0.9.17
## 0.0.154
### Patch Changes
- Updated dependencies [24b3b6a]
- jazz-tools@0.9.16
- jazz-browser-media-images@0.9.16
- jazz-react@0.9.16
## 0.0.153
### Patch Changes
- Updated dependencies [7491711]
- jazz-tools@0.9.15
- jazz-browser-media-images@0.9.15
- jazz-react@0.9.15
## 0.0.152
### Patch Changes
- Updated dependencies [3df93cc]
- jazz-tools@0.9.14
- jazz-browser-media-images@0.9.14
- jazz-react@0.9.14
## 0.0.151
### Patch Changes
- jazz-react@0.9.13
- jazz-tools@0.9.13
- jazz-browser-media-images@0.9.13
## 0.0.150
### Patch Changes
- jazz-react@0.9.12
- jazz-tools@0.9.12
- jazz-browser-media-images@0.9.12
## 0.0.149
### Patch Changes
- jazz-react@0.9.11
- jazz-tools@0.9.11
- jazz-browser-media-images@0.9.11
## 0.0.148
### Patch Changes

View File

@@ -13,6 +13,10 @@ You can either
Create a new Jazz project, and use this example as a template.
```bash
npm create jazz-app@latest --example pets --project-name pets
```
or
```bash
npx create-jazz-app@latest --example pets --project-name pets
```

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-pets",
"private": true,
"version": "0.0.156",
"version": "0.0.148",
"type": "module",
"scripts": {
"dev": "vite",
@@ -19,9 +19,9 @@
"@radix-ui/react-toast": "^1.1.4",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"jazz-browser-media-images": "workspace:0.9.18",
"jazz-react": "workspace:0.9.18",
"jazz-tools": "workspace:0.9.18",
"jazz-browser-media-images": "workspace:0.9.10",
"jazz-react": "workspace:0.9.10",
"jazz-tools": "workspace:0.9.10",
"lucide-react": "^0.274.0",
"qrcode": "^1.5.3",
"react": "^18.3.1",
@@ -41,7 +41,7 @@
"@vitejs/plugin-react-swc": "^3.3.2",
"autoprefixer": "^10.4.20",
"is-ci": "^3.0.1",
"jazz-run": "workspace:0.9.18",
"jazz-run": "workspace:0.9.10",
"postcss": "^8.4.27",
"tailwindcss": "^3.4.15",
"typescript": "~5.6.2",

View File

@@ -1,74 +1,5 @@
# reactions
## 0.0.36
### Patch Changes
- jazz-react@0.9.18
- jazz-tools@0.9.18
- jazz-browser-media-images@0.9.18
## 0.0.35
### Patch Changes
- Updated dependencies [c2ca1fe]
- Updated dependencies [1227047]
- jazz-tools@0.9.17
- jazz-browser-media-images@0.9.17
- jazz-react@0.9.17
## 0.0.34
### Patch Changes
- Updated dependencies [24b3b6a]
- jazz-tools@0.9.16
- jazz-browser-media-images@0.9.16
- jazz-react@0.9.16
## 0.0.33
### Patch Changes
- Updated dependencies [7491711]
- jazz-tools@0.9.15
- jazz-browser-media-images@0.9.15
- jazz-react@0.9.15
## 0.0.32
### Patch Changes
- Updated dependencies [3df93cc]
- jazz-tools@0.9.14
- jazz-browser-media-images@0.9.14
- jazz-react@0.9.14
## 0.0.31
### Patch Changes
- jazz-react@0.9.13
- jazz-tools@0.9.13
- jazz-browser-media-images@0.9.13
## 0.0.30
### Patch Changes
- jazz-react@0.9.12
- jazz-tools@0.9.12
- jazz-browser-media-images@0.9.12
## 0.0.29
### Patch Changes
- jazz-react@0.9.11
- jazz-tools@0.9.11
- jazz-browser-media-images@0.9.11
## 0.0.28
### Patch Changes

View File

@@ -13,6 +13,10 @@ You can either
Create a new Jazz project, and use this example as a template.
```bash
npm create jazz-app@latest --example reactions --project-name reactions
```
or
```bash
npx create-jazz-app@latest --example reactions --project-name reactions
```

View File

@@ -1,7 +1,7 @@
{
"name": "reactions",
"private": true,
"version": "0.0.36",
"version": "0.0.28",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,74 +1,5 @@
# todo-vue
## 0.0.41
### Patch Changes
- jazz-browser@0.9.18
- jazz-tools@0.9.18
- jazz-vue@0.9.18
## 0.0.40
### Patch Changes
- Updated dependencies [c2ca1fe]
- Updated dependencies [1227047]
- jazz-tools@0.9.17
- jazz-browser@0.9.17
- jazz-vue@0.9.17
## 0.0.39
### Patch Changes
- Updated dependencies [24b3b6a]
- jazz-tools@0.9.16
- jazz-browser@0.9.16
- jazz-vue@0.9.16
## 0.0.38
### Patch Changes
- Updated dependencies [7491711]
- jazz-tools@0.9.15
- jazz-browser@0.9.15
- jazz-vue@0.9.15
## 0.0.37
### Patch Changes
- Updated dependencies [3df93cc]
- jazz-tools@0.9.14
- jazz-browser@0.9.14
- jazz-vue@0.9.14
## 0.0.36
### Patch Changes
- jazz-browser@0.9.13
- jazz-tools@0.9.13
- jazz-vue@0.9.13
## 0.0.35
### Patch Changes
- jazz-browser@0.9.12
- jazz-tools@0.9.12
- jazz-vue@0.9.12
## 0.0.34
### Patch Changes
- jazz-browser@0.9.11
- jazz-tools@0.9.11
- jazz-vue@0.9.11
## 0.0.33
### Patch Changes

View File

@@ -11,6 +11,10 @@ You can either
Create a new Jazz project, and use this example as a template.
```bash
npm create jazz-app@latest --example todo-vue --project-name todo-vue
```
or
```bash
npx create-jazz-app@latest --example todo-vue --project-name todo-vue
```

View File

@@ -1,6 +1,6 @@
{
"name": "todo-vue",
"version": "0.0.41",
"version": "0.0.33",
"private": true,
"type": "module",
"scripts": {

View File

@@ -1,66 +1,5 @@
# jazz-example-todo
## 0.0.155
### Patch Changes
- jazz-react@0.9.18
- jazz-tools@0.9.18
## 0.0.154
### Patch Changes
- Updated dependencies [c2ca1fe]
- Updated dependencies [1227047]
- jazz-tools@0.9.17
- jazz-react@0.9.17
## 0.0.153
### Patch Changes
- Updated dependencies [24b3b6a]
- jazz-tools@0.9.16
- jazz-react@0.9.16
## 0.0.152
### Patch Changes
- Updated dependencies [7491711]
- jazz-tools@0.9.15
- jazz-react@0.9.15
## 0.0.151
### Patch Changes
- Updated dependencies [3df93cc]
- jazz-tools@0.9.14
- jazz-react@0.9.14
## 0.0.150
### Patch Changes
- jazz-react@0.9.13
- jazz-tools@0.9.13
## 0.0.149
### Patch Changes
- jazz-react@0.9.12
- jazz-tools@0.9.12
## 0.0.148
### Patch Changes
- jazz-react@0.9.11
- jazz-tools@0.9.11
## 0.0.147
### Patch Changes

View File

@@ -13,6 +13,10 @@ You can either
Create a new Jazz project, and use this example as a template.
```bash
npm create jazz-app@latest --example todo --project-name todo
```
or
```bash
npx create-jazz-app@latest --example todo --project-name todo
```

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-todo",
"private": true,
"version": "0.0.155",
"version": "0.0.147",
"type": "module",
"scripts": {
"dev": "vite",
@@ -16,8 +16,8 @@
"@radix-ui/react-toast": "^1.1.4",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"jazz-react": "workspace:0.9.18",
"jazz-tools": "workspace:0.9.18",
"jazz-react": "workspace:0.9.10",
"jazz-tools": "workspace:0.9.10",
"lucide-react": "^0.274.0",
"qrcode": "^1.5.3",
"react": "^18.3.1",

View File

@@ -1,66 +1,5 @@
# version-history
## 0.0.33
### Patch Changes
- jazz-react@0.9.18
- jazz-tools@0.9.18
## 0.0.32
### Patch Changes
- Updated dependencies [c2ca1fe]
- Updated dependencies [1227047]
- jazz-tools@0.9.17
- jazz-react@0.9.17
## 0.0.31
### Patch Changes
- Updated dependencies [24b3b6a]
- jazz-tools@0.9.16
- jazz-react@0.9.16
## 0.0.30
### Patch Changes
- Updated dependencies [7491711]
- jazz-tools@0.9.15
- jazz-react@0.9.15
## 0.0.29
### Patch Changes
- Updated dependencies [3df93cc]
- jazz-tools@0.9.14
- jazz-react@0.9.14
## 0.0.28
### Patch Changes
- jazz-react@0.9.13
- jazz-tools@0.9.13
## 0.0.27
### Patch Changes
- jazz-react@0.9.12
- jazz-tools@0.9.12
## 0.0.26
### Patch Changes
- jazz-react@0.9.11
- jazz-tools@0.9.11
## 0.0.25
### Patch Changes

View File

@@ -13,6 +13,10 @@ You can either
Create a new Jazz project, and use this example as a template.
```bash
npm create jazz-app@latest --example version-history --project-name version-history
```
or
```bash
npx create-jazz-app@latest --example version-history --project-name version-history
```

View File

@@ -1,7 +1,7 @@
{
"name": "version-history",
"private": true,
"version": "0.0.33",
"version": "0.0.25",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -132,7 +132,7 @@ As you develop your app, you'll likely want to
- initialise data in a user's `root` and `profile`
- add more data to your `root` and `profile` schemas
You can achieve both by overriding the `migrate()` method on your `Account` schema class.
You can achieve both by overriding the static `migrate()` method on your `Account` schema class.
### When migrations run

View File

@@ -1,38 +1,5 @@
# cojson-storage-indexeddb
## 0.9.18
### Patch Changes
- Updated dependencies [8898b10]
- cojson@0.9.18
- cojson-storage@0.9.18
## 0.9.13
### Patch Changes
- Updated dependencies [8d29e50]
- cojson-storage@0.9.13
- cojson@0.9.13
## 0.9.12
### Patch Changes
- Updated dependencies [15d4b2a]
- cojson-storage@0.9.12
- cojson@0.9.12
## 0.9.11
### Patch Changes
- Updated dependencies [efbf3d8]
- Updated dependencies [5863bad]
- cojson@0.9.11
- cojson-storage@0.9.11
## 0.9.10
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "cojson-storage-indexeddb",
"version": "0.9.18",
"version": "0.9.10",
"main": "dist/index.js",
"type": "module",
"types": "src/index.ts",

View File

@@ -1,38 +1,5 @@
# cojson-storage-sqlite
## 0.8.57
### Patch Changes
- Updated dependencies [8898b10]
- cojson@0.9.18
- cojson-storage@0.9.18
## 0.8.56
### Patch Changes
- Updated dependencies [8d29e50]
- cojson-storage@0.9.13
- cojson@0.9.13
## 0.8.55
### Patch Changes
- Updated dependencies [15d4b2a]
- cojson-storage@0.9.12
- cojson@0.9.12
## 0.8.54
### Patch Changes
- Updated dependencies [efbf3d8]
- Updated dependencies [5863bad]
- cojson@0.9.11
- cojson-storage@0.9.11
## 0.8.53
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "cojson-storage-rn-sqlite",
"type": "module",
"version": "0.8.57",
"version": "0.8.53",
"main": "dist/index.js",
"types": "src/index.ts",
"license": "MIT",

View File

@@ -1,41 +1,5 @@
# cojson-storage-sqlite
## 0.9.18
### Patch Changes
- Updated dependencies [8898b10]
- cojson@0.9.18
- cojson-storage@0.9.18
## 0.9.13
### Patch Changes
- 8d29e50: Restore the logger wrapper and adapt the API to pino
- Updated dependencies [8d29e50]
- cojson-storage@0.9.13
- cojson@0.9.13
## 0.9.12
### Patch Changes
- 15d4b2a: Revert the custom logger
- Updated dependencies [15d4b2a]
- cojson-storage@0.9.12
- cojson@0.9.12
## 0.9.11
### Patch Changes
- 5863bad: Wrap all the console logs with a logger class to make possible to customize the logger
- Updated dependencies [efbf3d8]
- Updated dependencies [5863bad]
- cojson@0.9.11
- cojson-storage@0.9.11
## 0.9.10
### Patch Changes

View File

@@ -1,13 +1,13 @@
{
"name": "cojson-storage-sqlite",
"type": "module",
"version": "0.9.18",
"version": "0.9.10",
"main": "dist/index.js",
"types": "src/index.ts",
"license": "MIT",
"dependencies": {
"better-sqlite3": "^11.7.0",
"cojson": "workspace:0.9.18",
"cojson": "workspace:0.9.10",
"cojson-storage": "workspace:*"
},
"devDependencies": {

View File

@@ -1,10 +1,5 @@
import { Database as DatabaseT } from "better-sqlite3";
import {
CojsonInternalTypes,
OutgoingSyncQueue,
SessionID,
logger,
} from "cojson";
import { CojsonInternalTypes, OutgoingSyncQueue, SessionID } from "cojson";
import RawCoID = CojsonInternalTypes.RawCoID;
import Signature = CojsonInternalTypes.Signature;
import Transaction = CojsonInternalTypes.Transaction;
@@ -28,10 +23,6 @@ export type RawTransactionRow = {
tx: string;
};
export function getErrorMessage(error: unknown) {
return error instanceof Error ? error.message : "Unknown error";
}
export class SQLiteClient implements DBClientInterface {
private readonly db: DatabaseT;
private readonly toLocalNode: OutgoingSyncQueue;
@@ -57,10 +48,7 @@ export class SQLiteClient implements DBClientInterface {
header: parsedHeader,
};
} catch (e) {
const headerValue = coValueRow?.header ?? "";
logger.warn("Invalid JSON in header: " + headerValue, {
id: coValueId,
});
console.warn(coValueId, "Invalid JSON in header", e, coValueRow?.header);
return;
}
}
@@ -87,7 +75,7 @@ export class SQLiteClient implements DBClientInterface {
tx: JSON.parse(transactionRow.tx) as Transaction,
}));
} catch (e) {
logger.warn("Invalid JSON in transaction");
console.warn("Invalid JSON in transaction", e);
return [];
}
}

View File

@@ -4,7 +4,6 @@ import {
OutgoingSyncQueue,
Peer,
cojsonInternals,
logger,
} from "cojson";
import { SyncManager, TransactionRow } from "cojson-storage";
import { SQLiteClient } from "./sqliteClient.js";
@@ -41,21 +40,24 @@ export class SQLiteNode {
await new Promise((resolve) => setTimeout(resolve, 0));
}
} catch (e) {
logger.error(
`Error reading from localNode, handling msg\n\n${JSON.stringify(
msg,
(k, v) =>
k === "changes" || k === "encryptedChanges"
? v.slice(0, 20) + "..."
: v,
)}`,
console.error(
new Error(
`Error reading from localNode, handling msg\n\n${JSON.stringify(
msg,
(k, v) =>
k === "changes" || k === "encryptedChanges"
? v.slice(0, 20) + "..."
: v,
)}`,
{ cause: e },
),
);
}
}
};
processMessages().catch((e) =>
logger.error("Error in processMessages in sqlite", e),
console.error("Error in processMessages in sqlite", e),
);
}
@@ -95,7 +97,10 @@ export class SQLiteNode {
db.pragma("user_version") as [{ user_version: number }]
)[0].user_version as number;
console.log("DB version", oldVersion);
if (oldVersion === 0) {
console.log("Migration 0 -> 1: Basic schema");
db.prepare(
`CREATE TABLE IF NOT EXISTS transactions (
ses INTEGER,
@@ -133,10 +138,15 @@ export class SQLiteNode {
).run();
db.pragma("user_version = 1");
console.log("Migration 0 -> 1: Basic schema - done");
}
if (oldVersion <= 1) {
// fix embarrassing off-by-one error for transaction indices
console.log(
"Migration 1 -> 2: Fix off-by-one error for transaction indices",
);
const txs = db
.prepare(`SELECT * FROM transactions`)
.all() as TransactionRow[];
@@ -153,9 +163,14 @@ export class SQLiteNode {
}
db.pragma("user_version = 2");
console.log(
"Migration 1 -> 2: Fix off-by-one error for transaction indices - done",
);
}
if (oldVersion <= 2) {
console.log("Migration 2 -> 3: Add signatureAfter");
db.prepare(
`CREATE TABLE IF NOT EXISTS signatureAfter (
ses INTEGER,
@@ -170,6 +185,7 @@ export class SQLiteNode {
).run();
db.pragma("user_version = 3");
console.log("Migration 2 -> 3: Add signatureAfter - done!!");
}
return new SQLiteNode(db, fromLocalNode, toLocalNode);

View File

@@ -1,37 +1,5 @@
# cojson-storage
## 0.9.18
### Patch Changes
- Updated dependencies [8898b10]
- cojson@0.9.18
## 0.9.13
### Patch Changes
- 8d29e50: Restore the logger wrapper and adapt the API to pino
- Updated dependencies [8d29e50]
- cojson@0.9.13
## 0.9.12
### Patch Changes
- 15d4b2a: Revert the custom logger
- Updated dependencies [15d4b2a]
- cojson@0.9.12
## 0.9.11
### Patch Changes
- 5863bad: Wrap all the console logs with a logger class to make possible to customize the logger
- Updated dependencies [efbf3d8]
- Updated dependencies [5863bad]
- cojson@0.9.11
## 0.9.10
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "cojson-storage",
"version": "0.9.18",
"version": "0.9.10",
"main": "dist/index.js",
"type": "module",
"types": "src/index.ts",

View File

@@ -6,7 +6,6 @@ import {
SyncMessage,
cojsonInternals,
emptyKnownState,
logger,
} from "cojson";
import { collectNewTxs, getDependedOnCoValues } from "./syncUtils.js";
import { DBClientInterface, StoredSessionRow } from "./types.js";
@@ -315,7 +314,7 @@ export class SyncManager {
return this.toLocalNode
.push(msg)
.catch((e) =>
logger.error(`Error sending ${msg.action} state, id ${msg.id}`, e),
console.error(`Error sending ${msg.action} state, id ${msg.id}`, e),
);
}
}

View File

@@ -1,37 +1,5 @@
# cojson-transport-nodejs-ws
## 0.9.18
### Patch Changes
- Updated dependencies [8898b10]
- cojson@0.9.18
## 0.9.13
### Patch Changes
- 8d29e50: Restore the logger wrapper and adapt the API to pino
- Updated dependencies [8d29e50]
- cojson@0.9.13
## 0.9.12
### Patch Changes
- 15d4b2a: Revert the custom logger
- Updated dependencies [15d4b2a]
- cojson@0.9.12
## 0.9.11
### Patch Changes
- 5863bad: Wrap all the console logs with a logger class to make possible to customize the logger
- Updated dependencies [efbf3d8]
- Updated dependencies [5863bad]
- cojson@0.9.11
## 0.9.10
### Patch Changes

View File

@@ -1,12 +1,12 @@
{
"name": "cojson-transport-ws",
"type": "module",
"version": "0.9.18",
"version": "0.9.10",
"main": "dist/index.js",
"types": "src/index.ts",
"license": "MIT",
"dependencies": {
"cojson": "workspace:0.9.18",
"cojson": "workspace:0.9.10",
"typescript": "~5.6.2"
},
"scripts": {

View File

@@ -4,10 +4,9 @@ import {
PingTimeoutError,
SyncMessage,
cojsonInternals,
logger,
} from "cojson";
import { BatchedOutgoingMessages } from "./BatchedOutgoingMessages.js";
import { deserializeMessages, getErrorMessage } from "./serialization.js";
import { deserializeMessages } from "./serialization.js";
import { AnyWebSocket } from "./types.js";
export const BUFFER_LIMIT = 100_000;
@@ -137,7 +136,7 @@ export function createWebSocketPeer({
function handleClose() {
incoming
.push("Disconnected")
.catch((e) => logger.error("Error while pushing disconnect msg", e));
.catch((e) => console.error("Error while pushing disconnect msg", e));
emitClosedEvent();
}
@@ -146,7 +145,7 @@ export function createWebSocketPeer({
const pingTimeout = createPingTimeoutListener(expectPings, () => {
incoming
.push("PingTimeout")
.catch((e) => logger.error("Error while pushing ping timeout", e));
.catch((e) => console.error("Error while pushing ping timeout", e));
emitClosedEvent();
});
@@ -157,14 +156,17 @@ export function createWebSocketPeer({
function handleIncomingMsg(event: { data: unknown }) {
if (event.data === "") {
console.log("client", id, "sent empty message");
return;
}
const result = deserializeMessages(event.data);
if (!result.ok) {
logger.warn(
"Error while deserializing messages: " + getErrorMessage(result.error),
console.error(
"Error while deserializing messages",
event.data,
result.error,
);
return;
}
@@ -182,7 +184,7 @@ export function createWebSocketPeer({
if (msg && "action" in msg) {
incoming
.push(msg)
.catch((e) => logger.error("Error while pushing incoming msg", e));
.catch((e) => console.error("Error while pushing incoming msg", e));
}
}
}
@@ -195,6 +197,7 @@ export function createWebSocketPeer({
outgoing: {
push: outgoingMessages.sendMessage,
close() {
console.log("Trying to close", id, websocket.readyState);
outgoingMessages.close();
websocket.removeEventListener("message", handleIncomingMsg);

View File

@@ -1,10 +1,6 @@
import { SyncMessage, logger } from "cojson";
import { SyncMessage } from "cojson";
import { PingMsg } from "./types.js";
export function getErrorMessage(error: unknown) {
return error instanceof Error ? error.message : "Unknown error";
}
export function addMessageToBacklog(backlog: string, message: SyncMessage) {
if (!backlog) {
return JSON.stringify(message);
@@ -28,7 +24,7 @@ export function deserializeMessages(messages: unknown) {
| PingMsg[],
} as const;
} catch (e) {
logger.error("Error while deserializing messages: " + getErrorMessage(e));
console.error("Error while deserializing messages", e);
return {
ok: false,
error: e,

View File

@@ -1,30 +1,5 @@
# cojson
## 0.9.18
### Patch Changes
- 8898b10: Export AccountRole type
## 0.9.13
### Patch Changes
- 8d29e50: Restore the logger wrapper and adapt the API to pino
## 0.9.12
### Patch Changes
- 15d4b2a: Revert the custom logger
## 0.9.11
### Patch Changes
- efbf3d8: Optimize queue management
- 5863bad: Wrap all the console logs with a logger class to make possible to customize the logger
## 0.9.10
### Patch Changes

View File

@@ -24,7 +24,7 @@
},
"type": "module",
"license": "MIT",
"version": "0.9.18",
"version": "0.9.10",
"devDependencies": {
"@opentelemetry/sdk-metrics": "^1.29.0",
"@types/jest": "^29.5.3",

View File

@@ -5,7 +5,6 @@ import {
} from "./PriorityBasedMessageQueue.js";
import { TryAddTransactionsError } from "./coValueCore.js";
import { RawCoID } from "./ids.js";
import { logger } from "./logger.js";
import { CO_VALUE_PRIORITY } from "./priority.js";
import { Peer, SyncMessage } from "./sync.js";
@@ -93,7 +92,7 @@ export class PeerState {
this.processing = true;
let entry: QueueEntry<SyncMessage> | undefined;
let entry: QueueEntry | undefined;
while ((entry = this.queue.pull())) {
// Awaiting the push to send one message at a time
// This way when the peer is "under pressure" we can enqueue all
@@ -130,7 +129,7 @@ export class PeerState {
}
private closeQueue() {
let entry: QueueEntry<SyncMessage> | undefined;
let entry: QueueEntry | undefined;
while ((entry = this.queue.pull())) {
// Using resolve here to avoid unnecessary noise in the logs
entry.resolve();
@@ -138,10 +137,7 @@ export class PeerState {
}
gracefulShutdown() {
logger.debug("Gracefully closing", {
peerId: this.id,
peerRole: this.role,
});
console.debug("Gracefully closing", this.id);
this.closeQueue();
this.peer.outgoing.close();
this.closed = true;

View File

@@ -18,12 +18,11 @@ function promiseWithResolvers<R>() {
};
}
export type QueueEntry<V> = {
msg: V;
export type QueueEntry = {
msg: SyncMessage;
promise: Promise<void>;
resolve: () => void;
reject: (_: unknown) => void;
next: QueueEntry<V> | undefined;
};
/**
@@ -34,68 +33,10 @@ type Tuple<T, N extends number, A extends unknown[] = []> = A extends {
}
? A
: Tuple<T, N, [...A, T]>;
type QueueTuple = Tuple<Queue<SyncMessage>, 8>;
class Queue<V> {
head: QueueEntry<V> | undefined = undefined;
tail: QueueEntry<V> | undefined = undefined;
push(msg: V) {
const { promise, resolve, reject } = promiseWithResolvers<void>();
const entry: QueueEntry<V> = {
msg,
promise,
resolve,
reject,
next: undefined,
};
if (this.head === undefined) {
this.head = entry;
} else {
if (this.tail === undefined) {
throw new Error("Tail is null but head is not");
}
this.tail.next = entry;
}
this.tail = entry;
return entry;
}
pull() {
const entry = this.head;
if (entry) {
this.head = entry.next;
}
if (this.head === undefined) {
this.tail = undefined;
}
return entry;
}
isNonEmpty() {
return this.head !== undefined;
}
}
type QueueTuple = Tuple<QueueEntry[], 8>;
export class PriorityBasedMessageQueue {
private queues: QueueTuple = [
new Queue(),
new Queue(),
new Queue(),
new Queue(),
new Queue(),
new Queue(),
new Queue(),
new Queue(),
];
private queues: QueueTuple = [[], [], [], [], [], [], [], []];
queueSizeCounter = metrics
.getMeter("cojson")
.createUpDownCounter("jazz.messagequeue.size", {
@@ -111,19 +52,22 @@ export class PriorityBasedMessageQueue {
constructor(private defaultPriority: CoValuePriority) {}
public push(msg: SyncMessage) {
const { promise, resolve, reject } = promiseWithResolvers<void>();
const entry: QueueEntry = { msg, promise, resolve, reject };
const priority = "priority" in msg ? msg.priority : this.defaultPriority;
const entry = this.getQueue(priority).push(msg);
this.getQueue(priority).push(entry);
this.queueSizeCounter.add(1, {
priority,
});
return entry.promise;
return promise;
}
public pull() {
const priority = this.queues.findIndex((queue) => queue.isNonEmpty());
const priority = this.queues.findIndex((queue) => queue.length > 0);
if (priority === -1) {
return;
@@ -133,6 +77,6 @@ export class PriorityBasedMessageQueue {
priority,
});
return this.queues[priority]?.pull();
return this.queues[priority]?.shift();
}
}

View File

@@ -43,7 +43,12 @@ export function bytesToBase64url(bytes: Uint8Array) {
let base64 = decoder.decode(new Uint8Array(encoded.buffer, 0, n));
if (k === 1) base64 += "==";
if (k === 2) base64 += "=";
// const after = performance.now();
// console.log(
// "bytesToBase64url bandwidth in MB/s for length",
// (1000 * bytes.length / (after - before)) / (1024 * 1024),
// bytes.length
// );
return base64;
}

View File

@@ -24,7 +24,6 @@ import {
import { Stringified, parseJSON, stableStringify } from "./jsonStringify.js";
import { JsonObject, JsonValue } from "./jsonValue.js";
import { LocalNode, ResolveAccountAgentError } from "./localNode.js";
import { logger } from "./logger.js";
import {
PermissionsDef as RulesetDef,
determineValidTransactions,
@@ -210,10 +209,16 @@ export class CoValueCore {
.andThen((agent) => {
const signerID = this.crypto.getAgentSignerID(agent);
// const beforeHash = performance.now();
const { expectedNewHash, newStreamingHash } = this.expectedNewHashAfter(
sessionID,
newTransactions,
);
// const afterHash = performance.now();
// console.log(
// "Hashing took",
// afterHash - beforeHash
// );
if (givenExpectedNewHash && givenExpectedNewHash !== expectedNewHash) {
return err({
@@ -386,6 +391,7 @@ export class CoValueCore {
streamingHash.update(transaction);
const after = performance.now();
if (after - before > 1) {
// console.log("Hashing blocked for", after - before);
await new Promise((resolve) => setTimeout(resolve, 0));
before = performance.now();
}
@@ -534,7 +540,7 @@ export class CoValueCore {
}
if (!decryptedChanges) {
logger.error("Failed to decrypt transaction despite having key");
console.error("Failed to decrypt transaction despite having key");
continue;
}
@@ -679,7 +685,7 @@ export class CoValueCore {
if (secret) {
return secret as KeySecret;
} else {
logger.warn(
console.error(
`Encrypting ${encryptingKeyID} key didn't decrypt ${keyID}`,
);
}
@@ -719,7 +725,7 @@ export class CoValueCore {
if (secret) {
return secret as KeySecret;
} else {
logger.warn(
console.error(
`Encrypting parent ${parentKey.id} key didn't decrypt ${keyID}`,
);
}

View File

@@ -1,7 +1,6 @@
import { PeerState } from "./PeerState.js";
import { CoValueCore } from "./coValueCore.js";
import { RawCoID } from "./ids.js";
import { logger } from "./logger.js";
import { PeerID } from "./sync.js";
export const CO_VALUE_LOADING_MAX_RETRIES = 5;
@@ -283,7 +282,7 @@ async function loadCoValueFromPeers(
...coValueEntry.state.coValue.knownState(),
})
.catch((err) => {
logger.warn(`Failed to push load message to peer ${peer.id}`, err);
console.error(`Failed to push load message to peer ${peer.id}`, err);
});
} else {
/**
@@ -297,17 +296,14 @@ async function loadCoValueFromPeers(
sessions: {},
})
.catch((err) => {
logger.warn(`Failed to push load message to peer ${peer.id}`, err);
console.error(`Failed to push load message to peer ${peer.id}`, err);
});
}
if (coValueEntry.state.type === "loading") {
const timeout = setTimeout(() => {
if (coValueEntry.state.type === "loading") {
logger.warn("Failed to load coValue from peer", {
peerId: peer.id,
peerRole: peer.role,
});
console.error("Failed to load coValue from peer", peer.id);
coValueEntry.dispatch({
type: "not-found-in-peer",
peerId: peer.id,
@@ -360,7 +356,7 @@ function sleep(ms: number) {
function getPeersWithoutErrors(peers: PeerState[], coValueId: RawCoID) {
return peers.filter((p) => {
if (p.erroredCoValues.has(coValueId)) {
logger.warn(
console.error(
`Skipping load on errored coValue ${coValueId} from peer ${p.id}`,
);
return false;

View File

@@ -16,7 +16,6 @@ import {
import { AgentID } from "../ids.js";
import { JsonObject } from "../jsonValue.js";
import { LocalNode } from "../localNode.js";
import { logger } from "../logger.js";
import type { AccountRole } from "../permissions.js";
import { RawCoMap } from "./coMap.js";
import { InviteSecret, RawGroup } from "./group.js";
@@ -60,7 +59,7 @@ export class RawAccount<
);
if (agents.length !== 1) {
logger.warn("Account has " + agents.length + " agents", { id: this.id });
console.warn("Account has " + agents.length + " agents", this.id);
}
this._cachedCurrentAgentID = agents[0];

View File

@@ -133,6 +133,10 @@ export class RawCoListView<
change.before.txIndex
]?.[change.before.changeIdx];
if (!beforeEntry) {
// console.error(
// "Insertion before missing op " +
// change.before
// );
continue;
}
beforeEntry.predecessors.splice(0, 0, {
@@ -152,6 +156,9 @@ export class RawCoListView<
change.after.txIndex
]?.[change.after.changeIdx];
if (!afterEntry) {
// console.error(
// "Insertion after missing op " + change.after
// );
continue;
}
afterEntry.successors.push({

View File

@@ -3,7 +3,6 @@ import { CoID, RawCoValue } from "../coValue.js";
import { CoValueCore } from "../coValueCore.js";
import { AgentID, SessionID, TransactionID } from "../ids.js";
import { JsonObject, JsonValue } from "../jsonValue.js";
import { logger } from "../logger.js";
import { CoValueKnownState } from "../sync.js";
import { accountOrAgentIDfromSessionID } from "../typeUtils/accountOrAgentIDfromSessionID.js";
import { isAccountID } from "../typeUtils/isAccountID.js";
@@ -310,7 +309,7 @@ export class RawBinaryCoStreamView<
const start = items[0];
if (start?.type !== "start") {
logger.error("Invalid binary stream start", start);
console.error("Invalid binary stream start", start);
return;
}
@@ -329,7 +328,7 @@ export class RawBinaryCoStreamView<
}
if (item.type !== "chunk") {
logger.error("Invalid binary stream chunk", item);
console.error("Invalid binary stream chunk", item);
return undefined;
}
@@ -383,6 +382,7 @@ export class RawBinaryCoStream<
chunk: Uint8Array,
privacy: "private" | "trusting" = "private",
): void {
// const before = performance.now();
this.push(
{
type: "chunk",
@@ -391,6 +391,11 @@ export class RawBinaryCoStream<
privacy,
false,
);
// const after = performance.now();
// console.log(
// "pushBinaryStreamChunk bandwidth in MB/s",
// (1000 * chunk.length) / (after - before) / (1024 * 1024)
// );
}
endBinaryStream(privacy: "private" | "trusting" = "private") {

View File

@@ -13,7 +13,6 @@ import {
isParentGroupReference,
} from "../ids.js";
import { JsonObject } from "../jsonValue.js";
import { logger } from "../logger.js";
import { AccountRole, Role } from "../permissions.js";
import { expectGroup } from "../typeUtils/expectGroup.js";
import {
@@ -154,7 +153,7 @@ export class RawGroup<
child.state.type === "unavailable"
) {
child.loadFromPeers(peers).catch(() => {
logger.error(`Failed to load child group ${id}`);
console.error(`Failed to load child group ${id}`);
});
}
@@ -322,7 +321,7 @@ export class RawGroup<
const secret = this.core.getReadKey(keyID);
if (!secret) {
logger.error("Can't find key " + keyID);
console.error("Can't find key", keyID);
continue;
}

View File

@@ -7,7 +7,6 @@ import { base64URLtoBytes, bytesToBase64url } from "../base64url.js";
import { RawCoID, TransactionID } from "../ids.js";
import { Stringified, stableStringify } from "../jsonStringify.js";
import { JsonValue } from "../jsonValue.js";
import { logger } from "../logger.js";
import {
CryptoProvider,
Encrypted,
@@ -193,9 +192,7 @@ export class PureJSCrypto extends CryptoProvider<Blake3State> {
try {
return JSON.parse(textDecoder.decode(plaintext));
} catch (e) {
logger.error(
"Failed to decrypt/parse sealed message: " + (e as Error)?.message,
);
console.error("Failed to decrypt/parse sealed message", e);
return undefined;
}
}

Some files were not shown because too many files have changed in this diff Show More