feat(www): Finish up on the onboarding (#210)

Merging this prematurely to make sure the team is on the same boat... like dang! We need to find a better way to do this. 

Plus it has become too big
This commit is contained in:
Wanjohi
2025-03-26 02:21:53 +03:00
committed by GitHub
parent 957eca7794
commit f62fc1fb4b
106 changed files with 6329 additions and 866 deletions

1
packages/zero/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
sync-replica*

View File

@@ -0,0 +1 @@
UPDATE zero.permissions SET permissions = '{"tables":{"member":{"row":{"select":[["allow",{"type":"correlatedSubquery","related":{"system":"permissions","correlation":{"parentField":["team_id"],"childField":["team_id"]},"subquery":{"table":"member","alias":"zsubq_members","where":{"type":"simple","left":{"type":"column","name":"email"},"right":{"type":"static","anchor":"authData","field":"sub"},"op":"="},"orderBy":[["team_id","asc"],["id","asc"]]}},"op":"EXISTS"}]],"update":{}}},"team":{"row":{"select":[["allow",{"type":"correlatedSubquery","related":{"system":"permissions","correlation":{"parentField":["id"],"childField":["team_id"]},"subquery":{"table":"member","alias":"zsubq_members","where":{"type":"simple","left":{"type":"column","name":"email"},"right":{"type":"static","anchor":"authData","field":"sub"},"op":"="},"orderBy":[["team_id","asc"],["id","asc"]]}},"op":"EXISTS"}]],"update":{}}}}}';

View File

@@ -0,0 +1,12 @@
{
"name": "@nestri/zero",
"version": "0.0.0",
"type": "module",
"dependencies": {
"@rocicorp/zero": "*",
"@nestri/core": "*"
},
"scripts": {
"dev": "zero-deploy-permissions --output-format=sql --output-file=.permissions.sql && zero-deploy-permissions && zero-cache"
}
}

90
packages/zero/schema.ts Normal file
View File

@@ -0,0 +1,90 @@
import {
table,
string,
number,
createSchema,
relationships,
definePermissions,
} from "@rocicorp/zero";
// TODO: Add Steam, and Machines here
const timestamps = {
time_created: number(),
time_deleted: number().optional(),
} as const;
const team = table("team")
.columns({
id: string(),
name: string(),
slug: string(),
plan_type: string<"Hosted" | "BYOG">(),
...timestamps,
})
.primaryKey("id");
const member = table("member")
.columns({
id: string(),
email: string(),
team_id: string(),
time_created: number(),
time_seen: number().optional(),
time_deleted: number().optional(),
})
.primaryKey("team_id", "id");
export const schema = createSchema(1, {
tables: [team, member],
relationships: [
relationships(member, (r) => ({
team: r.one({
sourceField: ["team_id"],
destSchema: team,
destField: ["id"],
}),
members: r.many({
sourceField: ["team_id"],
destSchema: member,
destField: ["team_id"],
}),
})),
relationships(team, (r) => ({
members: r.many({
sourceField: ["id"],
destSchema: member,
destField: ["team_id"],
}),
})),
],
});
export type Schema = typeof schema;
type Auth = {
sub: string;
properties: {
userID: string;
email: string;
};
};
export const permissions = definePermissions<Auth, Schema>(schema, () => {
return {
member: {
row: {
select: [
(auth, q) => q.exists("members", (u) => u.where("email", auth.sub)),
],
},
},
team: {
row: {
select: [
(auth, q) => q.exists("members", (u) => u.where("email", auth.sub)),
],
},
},
};
});

9
packages/zero/sst-env.d.ts vendored Normal file
View File

@@ -0,0 +1,9 @@
/* This file is auto-generated by SST. Do not edit. */
/* tslint:disable */
/* eslint-disable */
/* deno-fmt-ignore-file */
/// <reference path="../../sst-env.d.ts" />
import "sst"
export {}