oneie 2.0.9 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +16 -11
- package/README.md +110 -128
- package/dist/index.js +0 -0
- package/folders.yaml +1 -1
- package/one/.obsidian/workspace.json +10 -10
- package/one/README.md +111 -31
- package/one/events/2025-10-15-unignore-public-group-docs.md +280 -0
- package/one/groups/groups.md +543 -0
- package/one/groups/one.md +599 -0
- package/one/knowledge/ontology-frontend.md +76 -46
- package/one/license.md +16 -11
- package/one/things/ONE.md +22 -21
- package/one/things/plans/5-build-frontend.md +0 -0
- package/one/things/plans/switch-off-auth.md +20 -0
- package/package.json +1 -1
- /package/one/things/{vision/elegant-interface.md → interface.md} +0 -0
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
# Groups: Multi-Tenant Platform Structure
|
|
2
|
+
|
|
3
|
+
**Groups are the hierarchical isolation boundary for multi-tenancy in the ONE Platform.**
|
|
4
|
+
|
|
5
|
+
For details on the ONE group (vision, strategy, revenue), see **[ONE Group →](./one.md)**
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
The ONE Platform operates as a multi-tenant system where:
|
|
10
|
+
- **Platform Owner (Anthony)** owns the infrastructure and smart contracts (100%)
|
|
11
|
+
- **Groups** are tenant containers for resources and users (with 6 types)
|
|
12
|
+
- **Group Owners** manage their groups and members
|
|
13
|
+
- **Group Users** have scoped access to group resources
|
|
14
|
+
|
|
15
|
+
## Table: `groups`
|
|
16
|
+
|
|
17
|
+
**Schema Structure:**
|
|
18
|
+
```typescript
|
|
19
|
+
{
|
|
20
|
+
_id: Id<"groups">,
|
|
21
|
+
name: string,
|
|
22
|
+
type: "friend_circle" | "business" | "community" | "dao" | "government" | "organization",
|
|
23
|
+
parentGroupId?: Id<"groups">, // For hierarchical nesting
|
|
24
|
+
properties: {
|
|
25
|
+
// Identity
|
|
26
|
+
slug?: string, // URL-friendly (e.g., "acme")
|
|
27
|
+
domain?: string, // Custom domain (e.g., "acme.one.ie")
|
|
28
|
+
logo?: string,
|
|
29
|
+
description?: string,
|
|
30
|
+
|
|
31
|
+
// Status & Plan (mainly for organizations)
|
|
32
|
+
plan?: "starter" | "pro" | "enterprise",
|
|
33
|
+
|
|
34
|
+
// Limits & Usage (mainly for organizations)
|
|
35
|
+
limits?: {
|
|
36
|
+
users: number,
|
|
37
|
+
storage: number, // GB
|
|
38
|
+
apiCalls: number, // Per month
|
|
39
|
+
inferences: number, // Per month
|
|
40
|
+
},
|
|
41
|
+
usage?: {
|
|
42
|
+
users: number,
|
|
43
|
+
storage: number,
|
|
44
|
+
apiCalls: number,
|
|
45
|
+
inferences: number,
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
// Billing (mainly for organizations)
|
|
49
|
+
billing?: {
|
|
50
|
+
customerId?: string, // Stripe customer ID
|
|
51
|
+
subscriptionId?: string,
|
|
52
|
+
currentPeriodEnd?: number,
|
|
53
|
+
// Blockchain billing
|
|
54
|
+
cryptoEnabled?: boolean,
|
|
55
|
+
treasuryAddress?: {
|
|
56
|
+
sui?: string,
|
|
57
|
+
solana?: string,
|
|
58
|
+
base?: string,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
// Settings
|
|
63
|
+
settings?: {
|
|
64
|
+
allowSignups?: boolean,
|
|
65
|
+
requireEmailVerification?: boolean,
|
|
66
|
+
enableTwoFactor?: boolean,
|
|
67
|
+
allowedDomains?: string[],
|
|
68
|
+
// Inference settings
|
|
69
|
+
inferenceEnabled?: boolean,
|
|
70
|
+
inferenceModels?: string[], // ["gpt-4", "claude-3.5", "llama-3"]
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
// Revenue share (if group generates platform revenue)
|
|
74
|
+
revenueShare?: number, // 0.0 to 1.0 (0 = platform keeps all)
|
|
75
|
+
|
|
76
|
+
trialEndsAt?: number,
|
|
77
|
+
},
|
|
78
|
+
status: "draft" | "active" | "archived",
|
|
79
|
+
createdAt: number,
|
|
80
|
+
updatedAt: number,
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Group Types
|
|
85
|
+
|
|
86
|
+
### 1. **friend_circle**
|
|
87
|
+
Small groups of 2-10 people who know each other personally
|
|
88
|
+
- Family groups
|
|
89
|
+
- Close friend circles
|
|
90
|
+
- Small social groups
|
|
91
|
+
|
|
92
|
+
### 2. **business**
|
|
93
|
+
Commercial entities and teams
|
|
94
|
+
- Startups
|
|
95
|
+
- Small businesses
|
|
96
|
+
- Teams and departments
|
|
97
|
+
|
|
98
|
+
### 3. **community**
|
|
99
|
+
Open membership groups around shared interests
|
|
100
|
+
- Online communities
|
|
101
|
+
- Fan clubs
|
|
102
|
+
- Special interest groups
|
|
103
|
+
|
|
104
|
+
### 4. **dao**
|
|
105
|
+
Decentralized autonomous organizations
|
|
106
|
+
- Token-gated groups
|
|
107
|
+
- On-chain governance
|
|
108
|
+
- Treasury management
|
|
109
|
+
|
|
110
|
+
### 5. **government**
|
|
111
|
+
Public sector and civic groups
|
|
112
|
+
- Municipal services
|
|
113
|
+
- Public agencies
|
|
114
|
+
- Civic organizations
|
|
115
|
+
|
|
116
|
+
### 6. **organization**
|
|
117
|
+
Large-scale multi-tenant business entities
|
|
118
|
+
- Enterprise customers
|
|
119
|
+
- SaaS tenants
|
|
120
|
+
- White-label deployments
|
|
121
|
+
|
|
122
|
+
## Core Relationships (Connections)
|
|
123
|
+
|
|
124
|
+
**Membership:** `creator` → `group` via `member_of`
|
|
125
|
+
- `metadata.role`: `"group_owner"` | `"group_user"`
|
|
126
|
+
- `metadata.permissions`: Array of permission strings
|
|
127
|
+
|
|
128
|
+
**Ownership:** `creator` → `group` via `owns`
|
|
129
|
+
- Platform owner (Anthony) owns the ONE group at 100%
|
|
130
|
+
- Group owners may own their groups
|
|
131
|
+
|
|
132
|
+
**Hierarchy:** `group` → `group` via `parentGroupId`
|
|
133
|
+
- Groups can nest within groups
|
|
134
|
+
- Parent groups can access child group data (configurable)
|
|
135
|
+
|
|
136
|
+
**Resource Ownership:** `group` → resources via `owns`
|
|
137
|
+
- Content, workflows, tokens, products, websites
|
|
138
|
+
- All group resources link back to group via ownership connection
|
|
139
|
+
|
|
140
|
+
## Core Events
|
|
141
|
+
|
|
142
|
+
**Group Lifecycle:**
|
|
143
|
+
- `group_created` - When group is created
|
|
144
|
+
- `group_updated` - Settings, plan, or limits changed
|
|
145
|
+
- `user_invited_to_group` - Invitation sent
|
|
146
|
+
- `user_joined_group` - User accepts invitation
|
|
147
|
+
- `user_removed_from_group` - User removed from group
|
|
148
|
+
|
|
149
|
+
**Billing Events (mainly for organizations):**
|
|
150
|
+
- `payment_event` - Subscription payments (Stripe or crypto)
|
|
151
|
+
- `subscription_event` - Plan changes (starter → pro → enterprise)
|
|
152
|
+
|
|
153
|
+
**Inference Events:**
|
|
154
|
+
- `inference_request` - Group member requests inference
|
|
155
|
+
- `inference_completed` - Result delivered
|
|
156
|
+
- `inference_quota_exceeded` - Monthly limit hit
|
|
157
|
+
|
|
158
|
+
**Revenue Events:**
|
|
159
|
+
- `group_revenue_generated` - When group's activity generates platform revenue
|
|
160
|
+
- `revenue_share_distributed` - If group has revenue share agreement
|
|
161
|
+
|
|
162
|
+
## Code Examples
|
|
163
|
+
|
|
164
|
+
### Create ONE Platform Group (Anthony's)
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
// Create the ONE group (owned by Anthony)
|
|
168
|
+
const oneGroupId = await db.insert("groups", {
|
|
169
|
+
name: "ONE Platform",
|
|
170
|
+
type: "organization",
|
|
171
|
+
parentGroupId: undefined, // Top-level group
|
|
172
|
+
properties: {
|
|
173
|
+
slug: "one",
|
|
174
|
+
domain: "one.ie",
|
|
175
|
+
plan: "enterprise",
|
|
176
|
+
limits: {
|
|
177
|
+
users: 1000000, // Unlimited for platform
|
|
178
|
+
storage: 1000000, // 1PB
|
|
179
|
+
apiCalls: -1, // Unlimited
|
|
180
|
+
inferences: -1, // Unlimited
|
|
181
|
+
},
|
|
182
|
+
usage: {
|
|
183
|
+
users: 0,
|
|
184
|
+
storage: 0,
|
|
185
|
+
apiCalls: 0,
|
|
186
|
+
inferences: 0,
|
|
187
|
+
},
|
|
188
|
+
billing: {
|
|
189
|
+
cryptoEnabled: true,
|
|
190
|
+
treasuryAddress: {
|
|
191
|
+
sui: process.env.PLATFORM_TREASURY_SUI,
|
|
192
|
+
solana: process.env.PLATFORM_TREASURY_SOLANA,
|
|
193
|
+
base: process.env.PLATFORM_TREASURY_BASE,
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
settings: {
|
|
197
|
+
allowSignups: true,
|
|
198
|
+
requireEmailVerification: true,
|
|
199
|
+
enableTwoFactor: true,
|
|
200
|
+
inferenceEnabled: true,
|
|
201
|
+
inferenceModels: ["gpt-4", "claude-3.5", "llama-3"],
|
|
202
|
+
},
|
|
203
|
+
revenueShare: 0, // Anthony keeps 100% of revenue
|
|
204
|
+
},
|
|
205
|
+
status: "active",
|
|
206
|
+
createdAt: Date.now(),
|
|
207
|
+
updatedAt: Date.now(),
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// Anthony owns the ONE group (100%)
|
|
211
|
+
await db.insert("connections", {
|
|
212
|
+
fromThingId: anthonyId,
|
|
213
|
+
toThingId: oneGroupId,
|
|
214
|
+
relationshipType: "owns",
|
|
215
|
+
metadata: {
|
|
216
|
+
ownershipPercentage: 100,
|
|
217
|
+
},
|
|
218
|
+
createdAt: Date.now(),
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// Anthony is also a member with group_owner role
|
|
222
|
+
await db.insert("connections", {
|
|
223
|
+
fromThingId: anthonyId,
|
|
224
|
+
toThingId: oneGroupId,
|
|
225
|
+
relationshipType: "member_of",
|
|
226
|
+
metadata: {
|
|
227
|
+
role: "group_owner",
|
|
228
|
+
permissions: ["*"], // All permissions
|
|
229
|
+
},
|
|
230
|
+
createdAt: Date.now(),
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
// Log creation event
|
|
234
|
+
await db.insert("events", {
|
|
235
|
+
groupId: oneGroupId,
|
|
236
|
+
type: "group_created",
|
|
237
|
+
actorId: anthonyId,
|
|
238
|
+
targetId: oneGroupId,
|
|
239
|
+
timestamp: Date.now(),
|
|
240
|
+
metadata: {
|
|
241
|
+
name: "ONE Platform",
|
|
242
|
+
slug: "one",
|
|
243
|
+
type: "organization",
|
|
244
|
+
plan: "enterprise",
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Create Customer Group (Multi-Tenant)
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
// Customer creates their own group
|
|
253
|
+
const customerGroupId = await db.insert("groups", {
|
|
254
|
+
name: "Acme Corp",
|
|
255
|
+
type: "organization",
|
|
256
|
+
parentGroupId: undefined, // Top-level tenant
|
|
257
|
+
properties: {
|
|
258
|
+
slug: "acme",
|
|
259
|
+
domain: "acme.one.ie",
|
|
260
|
+
plan: "pro",
|
|
261
|
+
limits: {
|
|
262
|
+
users: 50,
|
|
263
|
+
storage: 100, // GB
|
|
264
|
+
apiCalls: 100000,
|
|
265
|
+
inferences: 10000, // 10K inferences/month
|
|
266
|
+
},
|
|
267
|
+
usage: {
|
|
268
|
+
users: 0,
|
|
269
|
+
storage: 0,
|
|
270
|
+
apiCalls: 0,
|
|
271
|
+
inferences: 0,
|
|
272
|
+
},
|
|
273
|
+
billing: {
|
|
274
|
+
customerId: "cus_stripe123",
|
|
275
|
+
subscriptionId: "sub_stripe456",
|
|
276
|
+
cryptoEnabled: false,
|
|
277
|
+
},
|
|
278
|
+
settings: {
|
|
279
|
+
allowSignups: false,
|
|
280
|
+
requireEmailVerification: true,
|
|
281
|
+
enableTwoFactor: false,
|
|
282
|
+
inferenceEnabled: true,
|
|
283
|
+
inferenceModels: ["gpt-4", "claude-3.5"],
|
|
284
|
+
},
|
|
285
|
+
revenueShare: 0.1, // Customer gets 10% revenue share if they refer users
|
|
286
|
+
},
|
|
287
|
+
status: "active",
|
|
288
|
+
createdAt: Date.now(),
|
|
289
|
+
updatedAt: Date.now(),
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
// Customer is group_owner
|
|
293
|
+
await db.insert("connections", {
|
|
294
|
+
fromThingId: customerId,
|
|
295
|
+
toThingId: customerGroupId,
|
|
296
|
+
relationshipType: "member_of",
|
|
297
|
+
metadata: {
|
|
298
|
+
role: "group_owner",
|
|
299
|
+
permissions: ["read", "write", "admin", "billing"],
|
|
300
|
+
},
|
|
301
|
+
createdAt: Date.now(),
|
|
302
|
+
});
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### Create Hierarchical Groups (Department within Organization)
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
// Create parent organization
|
|
309
|
+
const orgId = await db.insert("groups", {
|
|
310
|
+
name: "Tech Corp",
|
|
311
|
+
type: "organization",
|
|
312
|
+
parentGroupId: undefined,
|
|
313
|
+
properties: {
|
|
314
|
+
slug: "techcorp",
|
|
315
|
+
plan: "enterprise",
|
|
316
|
+
},
|
|
317
|
+
status: "active",
|
|
318
|
+
createdAt: Date.now(),
|
|
319
|
+
updatedAt: Date.now(),
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
// Create child business group (department)
|
|
323
|
+
const deptId = await db.insert("groups", {
|
|
324
|
+
name: "Engineering Team",
|
|
325
|
+
type: "business",
|
|
326
|
+
parentGroupId: orgId, // Nest within parent
|
|
327
|
+
properties: {
|
|
328
|
+
description: "Product engineering department",
|
|
329
|
+
},
|
|
330
|
+
status: "active",
|
|
331
|
+
createdAt: Date.now(),
|
|
332
|
+
updatedAt: Date.now(),
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
// Create friend circle within department (squad)
|
|
336
|
+
const squadId = await db.insert("groups", {
|
|
337
|
+
name: "Backend Squad",
|
|
338
|
+
type: "friend_circle",
|
|
339
|
+
parentGroupId: deptId, // Nest within department
|
|
340
|
+
properties: {
|
|
341
|
+
description: "Backend services team",
|
|
342
|
+
},
|
|
343
|
+
status: "active",
|
|
344
|
+
createdAt: Date.now(),
|
|
345
|
+
updatedAt: Date.now(),
|
|
346
|
+
});
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
### Track Group Inference Usage
|
|
350
|
+
|
|
351
|
+
```typescript
|
|
352
|
+
// User in group requests inference
|
|
353
|
+
await db.insert("events", {
|
|
354
|
+
groupId: customerGroupId,
|
|
355
|
+
type: "inference_request",
|
|
356
|
+
actorId: userId,
|
|
357
|
+
targetId: inferenceRequestId,
|
|
358
|
+
timestamp: Date.now(),
|
|
359
|
+
metadata: {
|
|
360
|
+
model: "gpt-4",
|
|
361
|
+
cost: 0.045,
|
|
362
|
+
price: 0.10,
|
|
363
|
+
},
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
// Update group usage
|
|
367
|
+
const group = await db.get(customerGroupId);
|
|
368
|
+
await db.patch(customerGroupId, {
|
|
369
|
+
properties: {
|
|
370
|
+
...group.properties,
|
|
371
|
+
usage: {
|
|
372
|
+
...group.properties.usage,
|
|
373
|
+
inferences: group.properties.usage.inferences + 1,
|
|
374
|
+
},
|
|
375
|
+
},
|
|
376
|
+
updatedAt: Date.now(),
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
// Check if quota exceeded
|
|
380
|
+
if (group.properties.usage.inferences >= group.properties.limits.inferences) {
|
|
381
|
+
await db.insert("events", {
|
|
382
|
+
groupId: customerGroupId,
|
|
383
|
+
type: "inference_quota_exceeded",
|
|
384
|
+
actorId: "system",
|
|
385
|
+
targetId: customerGroupId,
|
|
386
|
+
timestamp: Date.now(),
|
|
387
|
+
metadata: {
|
|
388
|
+
limit: group.properties.limits.inferences,
|
|
389
|
+
usage: group.properties.usage.inferences,
|
|
390
|
+
},
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
### Revenue Share Distribution
|
|
396
|
+
|
|
397
|
+
```typescript
|
|
398
|
+
// When customer group generates platform revenue
|
|
399
|
+
await db.insert("events", {
|
|
400
|
+
groupId: customerGroupId,
|
|
401
|
+
type: "group_revenue_generated",
|
|
402
|
+
actorId: customerGroupId,
|
|
403
|
+
targetId: anthonyId, // Platform owner
|
|
404
|
+
timestamp: Date.now(),
|
|
405
|
+
metadata: {
|
|
406
|
+
totalRevenue: 1000.00, // $1K generated by group
|
|
407
|
+
groupShare: 100.00, // 10% to group
|
|
408
|
+
platformShare: 900.00, // 90% to Anthony
|
|
409
|
+
revenueSharePercentage: 0.1,
|
|
410
|
+
},
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
// Distribute revenue share (if configured)
|
|
414
|
+
if (group.properties.revenueShare > 0) {
|
|
415
|
+
await db.insert("events", {
|
|
416
|
+
groupId: customerGroupId,
|
|
417
|
+
type: "revenue_share_distributed",
|
|
418
|
+
actorId: anthonyId,
|
|
419
|
+
targetId: customerId,
|
|
420
|
+
timestamp: Date.now(),
|
|
421
|
+
metadata: {
|
|
422
|
+
amount: 100.00,
|
|
423
|
+
percentage: 0.1,
|
|
424
|
+
network: "sui",
|
|
425
|
+
txDigest: "...",
|
|
426
|
+
},
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
## Queries
|
|
432
|
+
|
|
433
|
+
**List group members:**
|
|
434
|
+
```typescript
|
|
435
|
+
const members = await db
|
|
436
|
+
.query("connections")
|
|
437
|
+
.withIndex("to_type", q =>
|
|
438
|
+
q.eq("toThingId", groupId)
|
|
439
|
+
.eq("relationshipType", "member_of")
|
|
440
|
+
)
|
|
441
|
+
.collect();
|
|
442
|
+
|
|
443
|
+
const memberEntities = await Promise.all(
|
|
444
|
+
members.map(m => db.get(m.fromThingId))
|
|
445
|
+
);
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
**List group resources:**
|
|
449
|
+
```typescript
|
|
450
|
+
const resources = await db
|
|
451
|
+
.query("connections")
|
|
452
|
+
.withIndex("from_type", q =>
|
|
453
|
+
q.eq("fromThingId", groupId)
|
|
454
|
+
.eq("relationshipType", "owns")
|
|
455
|
+
)
|
|
456
|
+
.collect();
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
**Get child groups (hierarchical query):**
|
|
460
|
+
```typescript
|
|
461
|
+
const childGroups = await db
|
|
462
|
+
.query("groups")
|
|
463
|
+
.filter(q => q.eq(q.field("parentGroupId"), groupId))
|
|
464
|
+
.collect();
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
**Get group inference usage:**
|
|
468
|
+
```typescript
|
|
469
|
+
const group = await db.get(groupId);
|
|
470
|
+
const usage = group.properties.usage?.inferences || 0;
|
|
471
|
+
const limit = group.properties.limits?.inferences || 0;
|
|
472
|
+
const percentageUsed = (usage / limit) * 100;
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
**Recent group activity:**
|
|
476
|
+
```typescript
|
|
477
|
+
const events = await db
|
|
478
|
+
.query("events")
|
|
479
|
+
.withIndex("group_time", q => q.eq("groupId", groupId))
|
|
480
|
+
.order("desc")
|
|
481
|
+
.take(100)
|
|
482
|
+
.collect();
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
**Calculate group revenue (for revenue share):**
|
|
486
|
+
```typescript
|
|
487
|
+
const revenueEvents = await db
|
|
488
|
+
.query("events")
|
|
489
|
+
.withIndex("type_time", q =>
|
|
490
|
+
q.eq("type", "group_revenue_generated")
|
|
491
|
+
)
|
|
492
|
+
.filter(q => q.eq(q.field("actorId"), groupId))
|
|
493
|
+
.collect();
|
|
494
|
+
|
|
495
|
+
const totalRevenue = revenueEvents.reduce(
|
|
496
|
+
(sum, e) => sum + e.metadata.totalRevenue,
|
|
497
|
+
0
|
|
498
|
+
);
|
|
499
|
+
const groupShare = revenueEvents.reduce(
|
|
500
|
+
(sum, e) => sum + e.metadata.groupShare,
|
|
501
|
+
0
|
|
502
|
+
);
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
## Multi-Tenant Isolation
|
|
506
|
+
|
|
507
|
+
**Access Control Pattern:**
|
|
508
|
+
```typescript
|
|
509
|
+
// Check if user can access group resource
|
|
510
|
+
export const canAccess = async (
|
|
511
|
+
userId: Id<"things">,
|
|
512
|
+
groupId: Id<"groups">,
|
|
513
|
+
requiredPermission: string
|
|
514
|
+
) => {
|
|
515
|
+
const membership = await db
|
|
516
|
+
.query("connections")
|
|
517
|
+
.withIndex("from_type", q =>
|
|
518
|
+
q.eq("fromThingId", userId)
|
|
519
|
+
.eq("toThingId", groupId)
|
|
520
|
+
.eq("relationshipType", "member_of")
|
|
521
|
+
)
|
|
522
|
+
.first();
|
|
523
|
+
|
|
524
|
+
if (!membership) return false;
|
|
525
|
+
|
|
526
|
+
const permissions = membership.metadata.permissions || [];
|
|
527
|
+
return permissions.includes("*") || permissions.includes(requiredPermission);
|
|
528
|
+
};
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
## Notes
|
|
532
|
+
|
|
533
|
+
- **Platform Owner (Anthony)** - Owns ONE group at 100%, receives all platform revenue
|
|
534
|
+
- **Multi-tenant** - Each group isolated via membership connections
|
|
535
|
+
- **Hierarchical** - Groups can nest infinitely (friend circles → businesses → organizations)
|
|
536
|
+
- **6 group types** - friend_circle, business, community, dao, government, organization
|
|
537
|
+
- **Protocol-agnostic** - Blockchain interactions via `metadata.network`
|
|
538
|
+
- **Inference quotas** - Monthly limits enforced per group (mainly organizations)
|
|
539
|
+
- **Revenue share** - Optional revenue split for referring groups (configurable 0-100%)
|
|
540
|
+
- **Blockchain billing** - Groups can pay via crypto (SUI/Solana/Base)
|
|
541
|
+
- **Usage tracking** - All inference/API usage tracked in group properties
|
|
542
|
+
- **Event history** - Complete audit trail of group activity
|
|
543
|
+
- **Flexible scale** - From friend circles (2 people) to governments (billions) without schema changes
|