Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit 03f0e47

Browse files
committed
chore: fix type errors in examples
1 parent 62502ec commit 03f0e47

File tree

8 files changed

+77
-527
lines changed

8 files changed

+77
-527
lines changed

examples/game/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
"tsx": "^4.0.0",
2525
"typescript": "^5.0.0",
2626
"vite": "^5.0.0",
27-
"vitest": "^1.0.0"
27+
"vitest": "^3.1.1"
2828
}
2929
}

examples/game/tests/game.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ global.setInterval = vi.fn((fn: () => void, delay: number) => {
99
const id = originalSetInterval(fn, delay);
1010
mockIntervals.push(id);
1111
return id;
12-
});
12+
}) as any;
1313

1414
// Cleanup function for intervals
1515
const clearTestIntervals = () => {

examples/stream/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
"tsx": "^4.0.0",
2525
"typescript": "^5.0.0",
2626
"vite": "^5.0.0",
27-
"vitest": "^1.0.0"
27+
"vitest": "^3.1.1"
2828
}
2929
}

examples/sync/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
"tsx": "^4.0.0",
2525
"typescript": "^5.0.0",
2626
"vite": "^5.0.0",
27-
"vitest": "^1.0.0"
27+
"vitest": "^3.1.1"
2828
}
2929
}

examples/tenant/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
"tsx": "^4.0.0",
2525
"typescript": "^5.0.0",
2626
"vite": "^5.0.0",
27-
"vitest": "^1.0.0"
27+
"vitest": "^3.1.1"
2828
}
2929
}

examples/tenant/src/backend/registry.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { actor, setup } from "@rivetkit/actor";
2-
import { UserError } from "@rivetkit/actor/errors";
32

43
export type Member = {
54
id: string;
@@ -21,32 +20,6 @@ export type ConnState = {
2120
role: "admin" | "member";
2221
};
2322

24-
// Simple authentication function
25-
async function authenticate(
26-
token: string,
27-
): Promise<{ userId: string; role: "admin" | "member" }> {
28-
// Simple token parsing - in production, verify JWT or session
29-
if (token.startsWith("auth:")) {
30-
const userId = token.split(":")[1];
31-
32-
// Hardcoded user roles for demo
33-
const userRoles: Record<string, "admin" | "member"> = {
34-
"user-1": "admin", // Alice
35-
"user-2": "member", // Bob
36-
"user-3": "member", // Charlie
37-
};
38-
39-
const role = userRoles[userId];
40-
if (!role) {
41-
throw new UserError("Invalid authentication token");
42-
}
43-
44-
return { userId, role };
45-
}
46-
47-
throw new UserError("Invalid authentication token format");
48-
}
49-
5023
const tenant = actor({
5124
onAuth: () => {},
5225
// Persistent state that survives restarts: https://rivet.gg/docs/actors/state
Lines changed: 9 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createClient, createRivetKit } from "@rivetkit/react";
22
import { useEffect, useState } from "react";
3-
import type { Member, Invoice, registry } from "../backend/registry";
3+
import type { Member, registry } from "../backend/registry";
44

55
const client = createClient<typeof registry>("http://localhost:8080");
66
const { useActor } = createRivetKit(client);
@@ -10,12 +10,10 @@ const ORG_ID = "org-1";
1010
export function App() {
1111
// Authentication state
1212
const [token, setToken] = useState<string>("");
13-
const [currentUser, setCurrentUser] = useState<Member | null>(null);
1413

1514
// Data state
1615
const [organization, setOrganization] = useState<any>(null);
1716
const [members, setMembers] = useState<Member[]>([]);
18-
const [invoices, setInvoices] = useState<Invoice[]>([]);
1917
const [dashboardStats, setDashboardStats] = useState<any>(null);
2018
const [error, setError] = useState<string>("");
2119
const [loading, setLoading] = useState(false);
@@ -45,10 +43,8 @@ export function App() {
4543

4644
const logout = () => {
4745
setToken("");
48-
setCurrentUser(null);
4946
setOrganization(null);
5047
setMembers([]);
51-
setInvoices([]);
5248
setDashboardStats(null);
5349
setError("");
5450
};
@@ -60,10 +56,6 @@ export function App() {
6056
const loadData = async () => {
6157
setLoading(true);
6258
try {
63-
// Get current user info
64-
const user = await tenant.connection!.getCurrentUser();
65-
setCurrentUser(user);
66-
6759
// Get organization info
6860
const org = await tenant.connection!.getOrganization();
6961
setOrganization(org);
@@ -75,16 +67,6 @@ export function App() {
7567
// Get dashboard stats
7668
const stats = await tenant.connection!.getDashboardStats();
7769
setDashboardStats(stats);
78-
79-
// Try to get invoices (only available to admins)
80-
try {
81-
const invoicesList = await tenant.connection!.getInvoices();
82-
setInvoices(invoicesList);
83-
setError("");
84-
} catch (err: any) {
85-
setError(err.message || "Failed to load invoices");
86-
setInvoices([]);
87-
}
8870
} catch (err: any) {
8971
setError(err.message || "Failed to load data");
9072
} finally {
@@ -104,54 +86,7 @@ export function App() {
10486
setMembers(prev => prev.map(m => m.id === member.id ? member : m));
10587
});
10688

107-
tenant.useEvent("invoiceUpdated", ({ invoice }: { invoice: Invoice }) => {
108-
setInvoices(prev => prev.map(inv => inv.id === invoice.id ? invoice : inv));
109-
});
11089

111-
// Admin functions
112-
const markInvoicePaid = async (invoiceId: string) => {
113-
if (!tenant.connection) return;
114-
115-
try {
116-
await tenant.connection.markInvoicePaid(invoiceId);
117-
setError("");
118-
} catch (err: any) {
119-
setError(err.message || "Failed to mark invoice as paid");
120-
}
121-
};
122-
123-
const addMember = async () => {
124-
if (!tenant.connection) return;
125-
126-
const name = prompt("Enter member name:");
127-
const email = prompt("Enter member email:");
128-
129-
if (!name || !email) return;
130-
131-
try {
132-
await tenant.connection.addMember({
133-
name,
134-
email,
135-
role: "member",
136-
});
137-
setError("");
138-
} catch (err: any) {
139-
setError(err.message || "Failed to add member");
140-
}
141-
};
142-
143-
const updateMemberRole = async (memberId: string, currentRole: string) => {
144-
if (!tenant.connection) return;
145-
146-
const newRole = currentRole === "admin" ? "member" : "admin";
147-
148-
try {
149-
await tenant.connection.updateMemberRole(memberId, newRole);
150-
setError("");
151-
} catch (err: any) {
152-
setError(err.message || "Failed to update member role");
153-
}
154-
};
15590

15691
// Login screen when not authenticated
15792
if (!token) {
@@ -198,19 +133,14 @@ export function App() {
198133
</div>
199134

200135
{/* User Info */}
201-
{currentUser && (
202-
<div className="user-info">
203-
<div className="user-details">
204-
<span>Logged in as: <strong>{currentUser.name}</strong></span>
205-
<span className={`user-badge ${currentUser.role}`}>
206-
{currentUser.role}
207-
</span>
208-
</div>
209-
<button className="logout-button" onClick={logout}>
210-
Logout
211-
</button>
136+
<div className="user-info">
137+
<div className="user-details">
138+
<span>Logged in</span>
212139
</div>
213-
)}
140+
<button className="logout-button" onClick={logout}>
141+
Logout
142+
</button>
143+
</div>
214144

215145
{/* Organization Header */}
216146
{organization && (
@@ -254,14 +184,6 @@ export function App() {
254184
</div>
255185
<div style={{ color: "#6c757d" }}>Members</div>
256186
</div>
257-
{dashboardStats.totalRevenue !== undefined && (
258-
<div style={{ padding: "20px", backgroundColor: "#f8f9fa", borderRadius: "6px", textAlign: "center" }}>
259-
<div style={{ fontSize: "24px", fontWeight: "bold", color: "#6f42c1" }}>
260-
${dashboardStats.totalRevenue.toFixed(2)}
261-
</div>
262-
<div style={{ color: "#6c757d" }}>Total Revenue</div>
263-
</div>
264-
)}
265187
</div>
266188
</div>
267189
)}
@@ -270,21 +192,6 @@ export function App() {
270192
<div className="section">
271193
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: "15px" }}>
272194
<h3>Team Members</h3>
273-
{currentUser?.role === "admin" && (
274-
<button
275-
onClick={addMember}
276-
style={{
277-
padding: "8px 16px",
278-
backgroundColor: "#28a745",
279-
color: "white",
280-
border: "none",
281-
borderRadius: "4px",
282-
cursor: "pointer"
283-
}}
284-
>
285-
Add Member
286-
</button>
287-
)}
288195
</div>
289196

290197
{members.length === 0 ? (
@@ -296,7 +203,6 @@ export function App() {
296203
<th>Name</th>
297204
<th>Email</th>
298205
<th>Role</th>
299-
{currentUser?.role === "admin" && <th>Actions</th>}
300206
</tr>
301207
</thead>
302208
<tbody>
@@ -309,86 +215,13 @@ export function App() {
309215
{member.role}
310216
</span>
311217
</td>
312-
{currentUser?.role === "admin" && (
313-
<td>
314-
<button
315-
onClick={() => updateMemberRole(member.id, member.role)}
316-
style={{
317-
padding: "4px 8px",
318-
backgroundColor: "#6c757d",
319-
color: "white",
320-
border: "none",
321-
borderRadius: "4px",
322-
cursor: "pointer",
323-
fontSize: "12px"
324-
}}
325-
>
326-
Toggle Role
327-
</button>
328-
</td>
329-
)}
330218
</tr>
331219
))}
332220
</tbody>
333221
</table>
334222
)}
335223
</div>
336224

337-
{/* Invoices Section - only displayed to admins */}
338-
{currentUser?.role === "admin" && (
339-
<div className="section">
340-
<h3>Invoices (Admin Only)</h3>
341-
{invoices.length === 0 ? (
342-
<div className="empty-state">No invoices found</div>
343-
) : (
344-
<table className="data-table">
345-
<thead>
346-
<tr>
347-
<th>Invoice #</th>
348-
<th>Description</th>
349-
<th>Date</th>
350-
<th>Amount</th>
351-
<th>Status</th>
352-
<th>Actions</th>
353-
</tr>
354-
</thead>
355-
<tbody>
356-
{invoices.map((invoice) => (
357-
<tr key={invoice.id}>
358-
<td>{invoice.id}</td>
359-
<td>{invoice.description}</td>
360-
<td>{new Date(invoice.date).toLocaleDateString()}</td>
361-
<td>${invoice.amount.toFixed(2)}</td>
362-
<td>
363-
<span className={`status-badge ${invoice.paid ? 'paid' : 'unpaid'}`}>
364-
{invoice.paid ? "Paid" : "Unpaid"}
365-
</span>
366-
</td>
367-
<td>
368-
{!invoice.paid && (
369-
<button
370-
onClick={() => markInvoicePaid(invoice.id)}
371-
style={{
372-
padding: "4px 8px",
373-
backgroundColor: "#28a745",
374-
color: "white",
375-
border: "none",
376-
borderRadius: "4px",
377-
cursor: "pointer",
378-
fontSize: "12px"
379-
}}
380-
>
381-
Mark Paid
382-
</button>
383-
)}
384-
</td>
385-
</tr>
386-
))}
387-
</tbody>
388-
</table>
389-
)}
390-
</div>
391-
)}
392225
</div>
393226
);
394-
}
227+
}

0 commit comments

Comments
 (0)