-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathorganization.zod.ts
More file actions
161 lines (132 loc) · 4.1 KB
/
organization.zod.ts
File metadata and controls
161 lines (132 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { z } from 'zod';
/**
* Organization Schema (Multi-Tenant Architecture)
*
* Defines the standard organization/workspace model for ObjectStack.
* Supports B2B SaaS scenarios where users belong to multiple teams/workspaces.
*
* This aligns with better-auth's organization plugin capabilities.
*/
/**
* Organization Schema
* Represents a team, workspace, or tenant in a multi-tenant application
*/
import { lazySchema } from '../shared/lazy-schema';
export const OrganizationSchema = lazySchema(() => z.object({
/**
* Unique organization identifier
*/
id: z.string().describe('Unique organization identifier'),
/**
* Organization name (display name)
*/
name: z.string().describe('Organization display name'),
/**
* Organization slug (URL-friendly identifier)
* Must be unique across all organizations
*/
slug: z.string()
.regex(/^[a-z0-9_-]+$/)
.describe('Unique URL-friendly slug (lowercase alphanumeric, hyphens, underscores)'),
/**
* Organization logo URL
*/
logo: z.string().url().optional().describe('Organization logo URL'),
/**
* Custom metadata for the organization
* Can store additional configuration, settings, or custom fields
*/
metadata: z.record(z.string(), z.unknown()).optional().describe('Custom metadata'),
/**
* Organization creation timestamp
*/
createdAt: z.string().datetime().describe('Organization creation timestamp'),
/**
* Last update timestamp
*/
updatedAt: z.string().datetime().describe('Last update timestamp'),
}));
export type Organization = z.infer<typeof OrganizationSchema>;
/**
* Organization Member Schema
* Links users to organizations with specific roles
*/
export const MemberSchema = lazySchema(() => z.object({
/**
* Unique member identifier
*/
id: z.string().describe('Unique member identifier'),
/**
* Organization ID this membership belongs to
*/
organizationId: z.string().describe('Organization ID'),
/**
* User ID of the member
*/
userId: z.string().describe('User ID'),
/**
* Member's role within the organization
* Common roles: 'owner', 'admin', 'member', 'guest'
* Can be customized per application
*/
role: z.string().describe('Member role (e.g., owner, admin, member, guest)'),
/**
* Member creation timestamp
*/
createdAt: z.string().datetime().describe('Member creation timestamp'),
/**
* Last update timestamp
*/
updatedAt: z.string().datetime().describe('Last update timestamp'),
}));
export type Member = z.infer<typeof MemberSchema>;
/**
* Invitation Status Enum
*/
export const InvitationStatus = z.enum(['pending', 'accepted', 'rejected', 'expired']);
export type InvitationStatus = z.infer<typeof InvitationStatus>;
/**
* Organization Invitation Schema
* Represents an invitation to join an organization
*/
export const InvitationSchema = lazySchema(() => z.object({
/**
* Unique invitation identifier
*/
id: z.string().describe('Unique invitation identifier'),
/**
* Organization ID the invitation is for
*/
organizationId: z.string().describe('Organization ID'),
/**
* Email address of the invitee
*/
email: z.string().email().describe('Invitee email address'),
/**
* Role the invitee will receive upon accepting
* Common roles: 'admin', 'member', 'guest'
*/
role: z.string().describe('Role to assign upon acceptance'),
/**
* Invitation status
*/
status: InvitationStatus.default('pending').describe('Invitation status'),
/**
* Invitation expiration timestamp
*/
expiresAt: z.string().datetime().describe('Invitation expiry timestamp'),
/**
* User ID of the person who sent the invitation
*/
inviterId: z.string().describe('User ID of the inviter'),
/**
* Invitation creation timestamp
*/
createdAt: z.string().datetime().describe('Invitation creation timestamp'),
/**
* Last update timestamp
*/
updatedAt: z.string().datetime().describe('Last update timestamp'),
}));
export type Invitation = z.infer<typeof InvitationSchema>;