@riffdb/better-auth 0.0.0-stage → 0.2.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/DESIGN.md +197 -0
- package/LICENSE-APACHE +201 -0
- package/LICENSE-MIT +27 -0
- package/README.md +191 -2
- package/dist/adapter.d.ts +28 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +1262 -0
- package/dist/adapter.js.map +1 -0
- package/dist/generated/client.d.ts +1925 -0
- package/dist/generated/client.d.ts.map +1 -0
- package/dist/generated/client.js +2044 -0
- package/dist/generated/client.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/profile-contract.d.ts +60 -0
- package/dist/profile-contract.d.ts.map +1 -0
- package/dist/profile-contract.js +535 -0
- package/dist/profile-contract.js.map +1 -0
- package/dist/profile-plan.d.ts +69 -0
- package/dist/profile-plan.d.ts.map +1 -0
- package/dist/profile-plan.js +180 -0
- package/dist/profile-plan.js.map +1 -0
- package/dist/profile.d.ts +47 -0
- package/dist/profile.d.ts.map +1 -0
- package/dist/profile.js +131 -0
- package/dist/profile.js.map +1 -0
- package/dist/testing.d.ts +11 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +12 -0
- package/dist/testing.js.map +1 -0
- package/generated/go/client.go +1996 -0
- package/generated/mcp/tools.json +12352 -0
- package/generated/python/client.py +3877 -0
- package/generated/riffdb.application.exact.json +1 -0
- package/generated/riffdb.contract.bundle +0 -0
- package/generated/rust/client.rs +6028 -0
- package/package.json +62 -4
- package/profiles/organization-security/materialization.json +48 -0
- package/profiles/organization-security/riffdb/contract.riff +766 -0
- package/profiles/organization-security/riffdb/queries/find_account_by_id.riffq +18 -0
- package/profiles/organization-security/riffdb/queries/find_invitation_by_email.riffq +17 -0
- package/profiles/organization-security/riffdb/queries/find_invitation_by_id.riffq +18 -0
- package/profiles/organization-security/riffdb/queries/find_invitation_by_organization_id.riffq +17 -0
- package/profiles/organization-security/riffdb/queries/find_member_by_id.riffq +18 -0
- package/profiles/organization-security/riffdb/queries/find_member_by_user_id.riffq +17 -0
- package/profiles/organization-security/riffdb/queries/find_organization_by_id.riffq +16 -0
- package/profiles/organization-security/riffdb/queries/find_organization_by_slug.riffq +16 -0
- package/profiles/organization-security/riffdb/queries/find_session_by_id.riffq +18 -0
- package/profiles/organization-security/riffdb/queries/find_session_by_token.riffq +16 -0
- package/profiles/organization-security/riffdb/queries/find_team_by_id.riffq +18 -0
- package/profiles/organization-security/riffdb/queries/find_team_member_by_id.riffq +18 -0
- package/profiles/organization-security/riffdb/queries/find_team_member_by_team_id.riffq +17 -0
- package/profiles/organization-security/riffdb/queries/find_two_factor_by_id.riffq +18 -0
- package/profiles/organization-security/riffdb/queries/find_two_factor_by_secret.riffq +17 -0
- package/profiles/organization-security/riffdb/queries/find_user_by_email.riffq +16 -0
- package/profiles/organization-security/riffdb/queries/find_user_by_id.riffq +16 -0
- package/profiles/organization-security/riffdb/queries/find_verification_by_id.riffq +16 -0
- package/profiles/organization-security/riffdb/queries/find_verification_by_identifier.riffq +17 -0
- package/profiles/organization-security/riffdb.application.json +167 -0
- package/profiles/organization-security/riffdb.toml +7 -0
- package/profiles/organization-security.profile.json +954 -0
- package/riffdb/contract.riff +489 -0
- package/riffdb/queries/admin_users_all_email_asc.riffq +24 -0
- package/riffdb/queries/admin_users_contains_asc.riffq +24 -0
- package/riffdb/queries/admin_users_contains_desc.riffq +24 -0
- package/riffdb/queries/admin_users_email_contains_created_desc.riffq +24 -0
- package/riffdb/queries/admin_users_email_contains_image_asc.riffq +24 -0
- package/riffdb/queries/admin_users_ends_with_asc.riffq +24 -0
- package/riffdb/queries/admin_users_ends_with_desc.riffq +24 -0
- package/riffdb/queries/admin_users_starts_with_asc.riffq +24 -0
- package/riffdb/queries/admin_users_starts_with_desc.riffq +24 -0
- package/riffdb/queries/find_account_by_id.riffq +24 -0
- package/riffdb/queries/find_account_by_provider.riffq +26 -0
- package/riffdb/queries/find_accounts_by_user_id.riffq +25 -0
- package/riffdb/queries/find_accounts_by_user_provider.riffq +27 -0
- package/riffdb/queries/find_active_sessions_by_user_id.riffq +23 -0
- package/riffdb/queries/find_expired_verification_ids.riffq +17 -0
- package/riffdb/queries/find_latest_verification.riffq +20 -0
- package/riffdb/queries/find_session_by_id.riffq +20 -0
- package/riffdb/queries/find_session_by_token.riffq +20 -0
- package/riffdb/queries/find_sessions_by_token_set.riffq +20 -0
- package/riffdb/queries/find_sessions_by_user_id.riffq +21 -0
- package/riffdb/queries/find_user_by_email.riffq +16 -0
- package/riffdb/queries/find_user_by_id.riffq +15 -0
- package/riffdb/queries/find_verification_by_id.riffq +19 -0
- package/riffdb/queries/find_verifications_by_identifier.riffq +21 -0
- package/riffdb.application.json +107 -0
- package/riffdb.application.lock.json +1 -0
- package/scripts/real-riffdb-runner.mjs +333 -0
|
@@ -0,0 +1,766 @@
|
|
|
1
|
+
contract BetterAuthOrganizationSecurity version 1 {
|
|
2
|
+
entity Account {
|
|
3
|
+
key (tenant_id: uuid, user_id: uuid, account_row_id: uuid)
|
|
4
|
+
field secret access_token: optional<string<2048>>
|
|
5
|
+
field secret access_token_expires_at: optional<timestamp>
|
|
6
|
+
field account_id: string<2048>
|
|
7
|
+
field created_at: timestamp
|
|
8
|
+
field secret id_token: optional<string<2048>>
|
|
9
|
+
field secret password: optional<string<2048>>
|
|
10
|
+
field provider_id: string<2048>
|
|
11
|
+
field secret refresh_token: optional<string<2048>>
|
|
12
|
+
field secret refresh_token_expires_at: optional<timestamp>
|
|
13
|
+
field scope: optional<string<2048>>
|
|
14
|
+
field updated_at: timestamp
|
|
15
|
+
field revision: u64
|
|
16
|
+
index by_parent (tenant_id, user_id, account_row_id)
|
|
17
|
+
reference account_parent (tenant_id, user_id) -> User(tenant_id, user_id)
|
|
18
|
+
delete_policy no_inbound
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
entity Invitation {
|
|
22
|
+
key (tenant_id: uuid, user_id: uuid, invitation_id: uuid)
|
|
23
|
+
field created_at: timestamp
|
|
24
|
+
field email: string<2048>
|
|
25
|
+
field expires_at: timestamp
|
|
26
|
+
field organization_id: uuid
|
|
27
|
+
field role: optional<string<2048>>
|
|
28
|
+
field status: string<2048>
|
|
29
|
+
field team_id: optional<string<2048>>
|
|
30
|
+
field revision: u64
|
|
31
|
+
index by_email (tenant_id, email, user_id, invitation_id)
|
|
32
|
+
index by_organization_id (tenant_id, organization_id, user_id, invitation_id)
|
|
33
|
+
index by_parent (tenant_id, user_id, invitation_id)
|
|
34
|
+
reference invitation_parent (tenant_id, user_id) -> User(tenant_id, user_id)
|
|
35
|
+
delete_policy no_inbound
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
entity Member {
|
|
39
|
+
key (tenant_id: uuid, organization_id: uuid, member_id: uuid)
|
|
40
|
+
field created_at: timestamp
|
|
41
|
+
field role: string<2048>
|
|
42
|
+
field user_id: uuid
|
|
43
|
+
field revision: u64
|
|
44
|
+
index by_user_id (tenant_id, user_id, organization_id, member_id)
|
|
45
|
+
index by_parent (tenant_id, organization_id, member_id)
|
|
46
|
+
reference member_parent (tenant_id, organization_id) -> Organization(tenant_id, organization_id)
|
|
47
|
+
delete_policy no_inbound
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
entity Organization {
|
|
51
|
+
key (tenant_id: uuid, organization_id: uuid)
|
|
52
|
+
field created_at: timestamp
|
|
53
|
+
field logo: optional<string<2048>>
|
|
54
|
+
field metadata: optional<string<2048>>
|
|
55
|
+
field name: string<2048>
|
|
56
|
+
field slug: string<2048>
|
|
57
|
+
field revision: u64
|
|
58
|
+
unique organization_slug (tenant_id, slug)
|
|
59
|
+
index by_slug (tenant_id, slug, organization_id)
|
|
60
|
+
delete_policy cascade {
|
|
61
|
+
relationship Member.member_parent using Member.by_parent maximum 32
|
|
62
|
+
relationship Team.team_parent using Team.by_parent maximum 32
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
entity Session {
|
|
67
|
+
key (tenant_id: uuid, user_id: uuid, session_id: uuid)
|
|
68
|
+
field active_organization_id: optional<string<2048>>
|
|
69
|
+
field active_team_id: optional<string<2048>>
|
|
70
|
+
field created_at: timestamp
|
|
71
|
+
field expires_at: timestamp
|
|
72
|
+
field ip_address: optional<string<2048>>
|
|
73
|
+
field secret token: string<2048>
|
|
74
|
+
field updated_at: timestamp
|
|
75
|
+
field user_agent: optional<string<2048>>
|
|
76
|
+
field revision: u64
|
|
77
|
+
unique session_token (tenant_id, token)
|
|
78
|
+
index by_token (tenant_id, token, user_id, session_id)
|
|
79
|
+
index by_parent (tenant_id, user_id, session_id)
|
|
80
|
+
reference session_parent (tenant_id, user_id) -> User(tenant_id, user_id)
|
|
81
|
+
delete_policy no_inbound
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
entity Team {
|
|
85
|
+
key (tenant_id: uuid, organization_id: uuid, team_id: uuid)
|
|
86
|
+
field created_at: timestamp
|
|
87
|
+
field name: string<2048>
|
|
88
|
+
field updated_at: optional<timestamp>
|
|
89
|
+
field revision: u64
|
|
90
|
+
index by_parent (tenant_id, organization_id, team_id)
|
|
91
|
+
reference team_parent (tenant_id, organization_id) -> Organization(tenant_id, organization_id)
|
|
92
|
+
delete_policy no_inbound
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
entity TeamMember {
|
|
96
|
+
key (tenant_id: uuid, user_id: uuid, team_member_id: uuid)
|
|
97
|
+
field created_at: optional<timestamp>
|
|
98
|
+
field team_id: uuid
|
|
99
|
+
field revision: u64
|
|
100
|
+
index by_team_id (tenant_id, team_id, user_id, team_member_id)
|
|
101
|
+
index by_parent (tenant_id, user_id, team_member_id)
|
|
102
|
+
reference team_member_parent (tenant_id, user_id) -> User(tenant_id, user_id)
|
|
103
|
+
delete_policy no_inbound
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
entity TwoFactor {
|
|
107
|
+
key (tenant_id: uuid, user_id: uuid, two_factor_id: uuid)
|
|
108
|
+
field secret backup_codes: string<2048>
|
|
109
|
+
field secret failed_verification_count: optional<i64>
|
|
110
|
+
field secret locked_until: optional<timestamp>
|
|
111
|
+
field secret secret: string<2048>
|
|
112
|
+
field verified: optional<bool>
|
|
113
|
+
field revision: u64
|
|
114
|
+
index by_secret (tenant_id, secret, user_id, two_factor_id)
|
|
115
|
+
index by_parent (tenant_id, user_id, two_factor_id)
|
|
116
|
+
reference two_factor_parent (tenant_id, user_id) -> User(tenant_id, user_id)
|
|
117
|
+
delete_policy no_inbound
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
entity User {
|
|
121
|
+
key (tenant_id: uuid, user_id: uuid)
|
|
122
|
+
field created_at: timestamp
|
|
123
|
+
field email: string<2048>
|
|
124
|
+
field email_verified: bool
|
|
125
|
+
field image: optional<string<2048>>
|
|
126
|
+
field locale: optional<string<2048>>
|
|
127
|
+
field name: string<2048>
|
|
128
|
+
field two_factor_enabled: optional<bool>
|
|
129
|
+
field updated_at: timestamp
|
|
130
|
+
field revision: u64
|
|
131
|
+
unique user_email (tenant_id, email)
|
|
132
|
+
index by_email (tenant_id, email, user_id)
|
|
133
|
+
delete_policy cascade {
|
|
134
|
+
relationship Account.account_parent using Account.by_parent maximum 32
|
|
135
|
+
relationship Invitation.invitation_parent using Invitation.by_parent maximum 32
|
|
136
|
+
relationship Session.session_parent using Session.by_parent maximum 32
|
|
137
|
+
relationship TeamMember.team_member_parent using TeamMember.by_parent maximum 32
|
|
138
|
+
relationship TwoFactor.two_factor_parent using TwoFactor.by_parent maximum 32
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
entity Verification {
|
|
143
|
+
key (tenant_id: uuid, verification_id: uuid)
|
|
144
|
+
field created_at: timestamp
|
|
145
|
+
field expires_at: timestamp
|
|
146
|
+
field identifier: string<2048>
|
|
147
|
+
field updated_at: timestamp
|
|
148
|
+
field secret value: string<2048>
|
|
149
|
+
field revision: u64
|
|
150
|
+
index by_identifier (tenant_id, identifier, verification_id)
|
|
151
|
+
delete_policy no_inbound
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
aggregate OrganizationData {
|
|
155
|
+
root Organization
|
|
156
|
+
child Member
|
|
157
|
+
child Team
|
|
158
|
+
partition_by tenant_id
|
|
159
|
+
conflict_key (tenant_id, organization_id)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
aggregate UserData {
|
|
163
|
+
root User
|
|
164
|
+
child Account
|
|
165
|
+
child Invitation
|
|
166
|
+
child Session
|
|
167
|
+
child TeamMember
|
|
168
|
+
child TwoFactor
|
|
169
|
+
partition_by tenant_id
|
|
170
|
+
conflict_key (tenant_id, user_id)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
aggregate VerificationData {
|
|
174
|
+
root Verification
|
|
175
|
+
partition_by tenant_id
|
|
176
|
+
conflict_key (tenant_id, verification_id)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
command CreateAccount {
|
|
180
|
+
input request_id: uuid
|
|
181
|
+
input tenant_id: uuid
|
|
182
|
+
input user_id: uuid
|
|
183
|
+
input account_row_id: uuid
|
|
184
|
+
input access_token: optional<string<2048>>
|
|
185
|
+
input access_token_expires_at: optional<timestamp>
|
|
186
|
+
input account_id: string<2048>
|
|
187
|
+
input created_at: timestamp
|
|
188
|
+
input id_token: optional<string<2048>>
|
|
189
|
+
input password: optional<string<2048>>
|
|
190
|
+
input provider_id: string<2048>
|
|
191
|
+
input refresh_token: optional<string<2048>>
|
|
192
|
+
input refresh_token_expires_at: optional<timestamp>
|
|
193
|
+
input scope: optional<string<2048>>
|
|
194
|
+
input updated_at: timestamp
|
|
195
|
+
idempotency_key request_id
|
|
196
|
+
read User(tenant_id, user_id) as user else AccountParentMissing {}
|
|
197
|
+
create Account(tenant_id, user_id, account_row_id) as account else AccountAlreadyExists {}
|
|
198
|
+
set account.access_token = access_token
|
|
199
|
+
set account.access_token_expires_at = access_token_expires_at
|
|
200
|
+
set account.account_id = account_id
|
|
201
|
+
set account.created_at = created_at
|
|
202
|
+
set account.id_token = id_token
|
|
203
|
+
set account.password = password
|
|
204
|
+
set account.provider_id = provider_id
|
|
205
|
+
set account.refresh_token = refresh_token
|
|
206
|
+
set account.refresh_token_expires_at = refresh_token_expires_at
|
|
207
|
+
set account.scope = scope
|
|
208
|
+
set account.updated_at = updated_at
|
|
209
|
+
set account.revision = 1
|
|
210
|
+
return AccountCreated {}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
command UpdateAccount {
|
|
214
|
+
input request_id: uuid
|
|
215
|
+
input tenant_id: uuid
|
|
216
|
+
input user_id: uuid
|
|
217
|
+
input account_row_id: uuid
|
|
218
|
+
input expected_revision: u64
|
|
219
|
+
input access_token: optional<string<2048>>
|
|
220
|
+
input access_token_expires_at: optional<timestamp>
|
|
221
|
+
input account_id: string<2048>
|
|
222
|
+
input created_at: timestamp
|
|
223
|
+
input id_token: optional<string<2048>>
|
|
224
|
+
input password: optional<string<2048>>
|
|
225
|
+
input provider_id: string<2048>
|
|
226
|
+
input refresh_token: optional<string<2048>>
|
|
227
|
+
input refresh_token_expires_at: optional<timestamp>
|
|
228
|
+
input scope: optional<string<2048>>
|
|
229
|
+
input updated_at: timestamp
|
|
230
|
+
idempotency_key request_id
|
|
231
|
+
mutate Account(tenant_id, user_id, account_row_id) as account else AccountUpdateMissing {}
|
|
232
|
+
require current_revision: account.revision == expected_revision else AccountUpdateStale {}
|
|
233
|
+
set account.access_token = access_token checked_by current_revision
|
|
234
|
+
set account.access_token_expires_at = access_token_expires_at checked_by current_revision
|
|
235
|
+
set account.account_id = account_id checked_by current_revision
|
|
236
|
+
set account.created_at = created_at checked_by current_revision
|
|
237
|
+
set account.id_token = id_token checked_by current_revision
|
|
238
|
+
set account.password = password checked_by current_revision
|
|
239
|
+
set account.provider_id = provider_id checked_by current_revision
|
|
240
|
+
set account.refresh_token = refresh_token checked_by current_revision
|
|
241
|
+
set account.refresh_token_expires_at = refresh_token_expires_at checked_by current_revision
|
|
242
|
+
set account.scope = scope checked_by current_revision
|
|
243
|
+
set account.updated_at = updated_at checked_by current_revision
|
|
244
|
+
set account.revision = account.revision + 1
|
|
245
|
+
return AccountUpdated {}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
bulk command DeleteAccount {
|
|
249
|
+
input request_id: uuid
|
|
250
|
+
input tenant_id: uuid
|
|
251
|
+
input user_id: uuid
|
|
252
|
+
input account_row_ids: list<uuid, 1..32>
|
|
253
|
+
idempotency_key request_id
|
|
254
|
+
for account_row_id in account_row_ids {
|
|
255
|
+
delete Account(tenant_id, user_id, account_row_id) as account else AccountMissing {}
|
|
256
|
+
}
|
|
257
|
+
return AccountDeleted {}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
command CreateInvitation {
|
|
261
|
+
input request_id: uuid
|
|
262
|
+
input tenant_id: uuid
|
|
263
|
+
input user_id: uuid
|
|
264
|
+
input invitation_id: uuid
|
|
265
|
+
input created_at: timestamp
|
|
266
|
+
input email: string<2048>
|
|
267
|
+
input expires_at: timestamp
|
|
268
|
+
input organization_id: uuid
|
|
269
|
+
input role: optional<string<2048>>
|
|
270
|
+
input status: string<2048>
|
|
271
|
+
input team_id: optional<string<2048>>
|
|
272
|
+
idempotency_key request_id
|
|
273
|
+
read User(tenant_id, user_id) as user else InvitationParentMissing {}
|
|
274
|
+
create Invitation(tenant_id, user_id, invitation_id) as invitation else InvitationAlreadyExists {}
|
|
275
|
+
set invitation.created_at = created_at
|
|
276
|
+
set invitation.email = email
|
|
277
|
+
set invitation.expires_at = expires_at
|
|
278
|
+
set invitation.organization_id = organization_id
|
|
279
|
+
set invitation.role = role
|
|
280
|
+
set invitation.status = status
|
|
281
|
+
set invitation.team_id = team_id
|
|
282
|
+
set invitation.revision = 1
|
|
283
|
+
return InvitationCreated {}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
command UpdateInvitation {
|
|
287
|
+
input request_id: uuid
|
|
288
|
+
input tenant_id: uuid
|
|
289
|
+
input user_id: uuid
|
|
290
|
+
input invitation_id: uuid
|
|
291
|
+
input expected_revision: u64
|
|
292
|
+
input created_at: timestamp
|
|
293
|
+
input email: string<2048>
|
|
294
|
+
input expires_at: timestamp
|
|
295
|
+
input organization_id: uuid
|
|
296
|
+
input role: optional<string<2048>>
|
|
297
|
+
input status: string<2048>
|
|
298
|
+
input team_id: optional<string<2048>>
|
|
299
|
+
idempotency_key request_id
|
|
300
|
+
mutate Invitation(tenant_id, user_id, invitation_id) as invitation else InvitationUpdateMissing {}
|
|
301
|
+
require current_revision: invitation.revision == expected_revision else InvitationUpdateStale {}
|
|
302
|
+
set invitation.created_at = created_at checked_by current_revision
|
|
303
|
+
set invitation.email = email checked_by current_revision
|
|
304
|
+
set invitation.expires_at = expires_at checked_by current_revision
|
|
305
|
+
set invitation.organization_id = organization_id checked_by current_revision
|
|
306
|
+
set invitation.role = role checked_by current_revision
|
|
307
|
+
set invitation.status = status checked_by current_revision
|
|
308
|
+
set invitation.team_id = team_id checked_by current_revision
|
|
309
|
+
set invitation.revision = invitation.revision + 1
|
|
310
|
+
return InvitationUpdated {}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
bulk command DeleteInvitation {
|
|
314
|
+
input request_id: uuid
|
|
315
|
+
input tenant_id: uuid
|
|
316
|
+
input user_id: uuid
|
|
317
|
+
input invitation_ids: list<uuid, 1..32>
|
|
318
|
+
idempotency_key request_id
|
|
319
|
+
for invitation_id in invitation_ids {
|
|
320
|
+
delete Invitation(tenant_id, user_id, invitation_id) as invitation else InvitationMissing {}
|
|
321
|
+
}
|
|
322
|
+
return InvitationDeleted {}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
command CreateMember {
|
|
326
|
+
input request_id: uuid
|
|
327
|
+
input tenant_id: uuid
|
|
328
|
+
input organization_id: uuid
|
|
329
|
+
input member_id: uuid
|
|
330
|
+
input created_at: timestamp
|
|
331
|
+
input role: string<2048>
|
|
332
|
+
input user_id: uuid
|
|
333
|
+
idempotency_key request_id
|
|
334
|
+
read Organization(tenant_id, organization_id) as organization else MemberParentMissing {}
|
|
335
|
+
create Member(tenant_id, organization_id, member_id) as member else MemberAlreadyExists {}
|
|
336
|
+
set member.created_at = created_at
|
|
337
|
+
set member.role = role
|
|
338
|
+
set member.user_id = user_id
|
|
339
|
+
set member.revision = 1
|
|
340
|
+
return MemberCreated {}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
command UpdateMember {
|
|
344
|
+
input request_id: uuid
|
|
345
|
+
input tenant_id: uuid
|
|
346
|
+
input organization_id: uuid
|
|
347
|
+
input member_id: uuid
|
|
348
|
+
input expected_revision: u64
|
|
349
|
+
input created_at: timestamp
|
|
350
|
+
input role: string<2048>
|
|
351
|
+
input user_id: uuid
|
|
352
|
+
idempotency_key request_id
|
|
353
|
+
mutate Member(tenant_id, organization_id, member_id) as member else MemberUpdateMissing {}
|
|
354
|
+
require current_revision: member.revision == expected_revision else MemberUpdateStale {}
|
|
355
|
+
set member.created_at = created_at checked_by current_revision
|
|
356
|
+
set member.role = role checked_by current_revision
|
|
357
|
+
set member.user_id = user_id checked_by current_revision
|
|
358
|
+
set member.revision = member.revision + 1
|
|
359
|
+
return MemberUpdated {}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
bulk command DeleteMember {
|
|
363
|
+
input request_id: uuid
|
|
364
|
+
input tenant_id: uuid
|
|
365
|
+
input organization_id: uuid
|
|
366
|
+
input member_ids: list<uuid, 1..32>
|
|
367
|
+
idempotency_key request_id
|
|
368
|
+
for member_id in member_ids {
|
|
369
|
+
delete Member(tenant_id, organization_id, member_id) as member else MemberMissing {}
|
|
370
|
+
}
|
|
371
|
+
return MemberDeleted {}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
command CreateOrganization {
|
|
375
|
+
input request_id: uuid
|
|
376
|
+
input tenant_id: uuid
|
|
377
|
+
input organization_id: uuid
|
|
378
|
+
input created_at: timestamp
|
|
379
|
+
input logo: optional<string<2048>>
|
|
380
|
+
input metadata: optional<string<2048>>
|
|
381
|
+
input name: string<2048>
|
|
382
|
+
input slug: string<2048>
|
|
383
|
+
idempotency_key request_id
|
|
384
|
+
create Organization(tenant_id, organization_id) as organization else OrganizationAlreadyExists {}
|
|
385
|
+
set organization.created_at = created_at
|
|
386
|
+
set organization.logo = logo
|
|
387
|
+
set organization.metadata = metadata
|
|
388
|
+
set organization.name = name
|
|
389
|
+
set organization.slug = slug
|
|
390
|
+
set organization.revision = 1
|
|
391
|
+
return OrganizationCreated {}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
command UpdateOrganization {
|
|
395
|
+
input request_id: uuid
|
|
396
|
+
input tenant_id: uuid
|
|
397
|
+
input organization_id: uuid
|
|
398
|
+
input expected_revision: u64
|
|
399
|
+
input created_at: timestamp
|
|
400
|
+
input logo: optional<string<2048>>
|
|
401
|
+
input metadata: optional<string<2048>>
|
|
402
|
+
input name: string<2048>
|
|
403
|
+
input slug: string<2048>
|
|
404
|
+
idempotency_key request_id
|
|
405
|
+
mutate Organization(tenant_id, organization_id) as organization else OrganizationUpdateMissing {}
|
|
406
|
+
require current_revision: organization.revision == expected_revision else OrganizationUpdateStale {}
|
|
407
|
+
set organization.created_at = created_at
|
|
408
|
+
set organization.logo = logo
|
|
409
|
+
set organization.metadata = metadata
|
|
410
|
+
set organization.name = name
|
|
411
|
+
set organization.slug = slug
|
|
412
|
+
set organization.revision = organization.revision + 1
|
|
413
|
+
return OrganizationUpdated {}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
bulk command DeleteOrganization {
|
|
417
|
+
input request_id: uuid
|
|
418
|
+
input tenant_id: uuid
|
|
419
|
+
input organization_ids: list<uuid, 1..3>
|
|
420
|
+
idempotency_key request_id
|
|
421
|
+
for organization_id in organization_ids {
|
|
422
|
+
delete Organization(tenant_id, organization_id) as organization else OrganizationMissing {}
|
|
423
|
+
cascade OrganizationCascadeLimitExceeded {}
|
|
424
|
+
}
|
|
425
|
+
return OrganizationDeleted {}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
command CreateSession {
|
|
429
|
+
input request_id: uuid
|
|
430
|
+
input tenant_id: uuid
|
|
431
|
+
input user_id: uuid
|
|
432
|
+
input session_id: uuid
|
|
433
|
+
input active_organization_id: optional<string<2048>>
|
|
434
|
+
input active_team_id: optional<string<2048>>
|
|
435
|
+
input created_at: timestamp
|
|
436
|
+
input expires_at: timestamp
|
|
437
|
+
input ip_address: optional<string<2048>>
|
|
438
|
+
input token: string<2048>
|
|
439
|
+
input updated_at: timestamp
|
|
440
|
+
input user_agent: optional<string<2048>>
|
|
441
|
+
idempotency_key request_id
|
|
442
|
+
read User(tenant_id, user_id) as user else SessionParentMissing {}
|
|
443
|
+
create Session(tenant_id, user_id, session_id) as session else SessionAlreadyExists {}
|
|
444
|
+
set session.active_organization_id = active_organization_id
|
|
445
|
+
set session.active_team_id = active_team_id
|
|
446
|
+
set session.created_at = created_at
|
|
447
|
+
set session.expires_at = expires_at
|
|
448
|
+
set session.ip_address = ip_address
|
|
449
|
+
set session.token = token
|
|
450
|
+
set session.updated_at = updated_at
|
|
451
|
+
set session.user_agent = user_agent
|
|
452
|
+
set session.revision = 1
|
|
453
|
+
return SessionCreated {}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
command UpdateSession {
|
|
457
|
+
input request_id: uuid
|
|
458
|
+
input tenant_id: uuid
|
|
459
|
+
input user_id: uuid
|
|
460
|
+
input session_id: uuid
|
|
461
|
+
input expected_revision: u64
|
|
462
|
+
input active_organization_id: optional<string<2048>>
|
|
463
|
+
input active_team_id: optional<string<2048>>
|
|
464
|
+
input created_at: timestamp
|
|
465
|
+
input expires_at: timestamp
|
|
466
|
+
input ip_address: optional<string<2048>>
|
|
467
|
+
input token: string<2048>
|
|
468
|
+
input updated_at: timestamp
|
|
469
|
+
input user_agent: optional<string<2048>>
|
|
470
|
+
idempotency_key request_id
|
|
471
|
+
mutate Session(tenant_id, user_id, session_id) as session else SessionUpdateMissing {}
|
|
472
|
+
require current_revision: session.revision == expected_revision else SessionUpdateStale {}
|
|
473
|
+
set session.active_organization_id = active_organization_id checked_by current_revision
|
|
474
|
+
set session.active_team_id = active_team_id checked_by current_revision
|
|
475
|
+
set session.created_at = created_at checked_by current_revision
|
|
476
|
+
set session.expires_at = expires_at checked_by current_revision
|
|
477
|
+
set session.ip_address = ip_address checked_by current_revision
|
|
478
|
+
set session.token = token checked_by current_revision
|
|
479
|
+
set session.updated_at = updated_at checked_by current_revision
|
|
480
|
+
set session.user_agent = user_agent checked_by current_revision
|
|
481
|
+
set session.revision = session.revision + 1
|
|
482
|
+
return SessionUpdated {}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
bulk command DeleteSession {
|
|
486
|
+
input request_id: uuid
|
|
487
|
+
input tenant_id: uuid
|
|
488
|
+
input user_id: uuid
|
|
489
|
+
input session_ids: list<uuid, 1..32>
|
|
490
|
+
idempotency_key request_id
|
|
491
|
+
for session_id in session_ids {
|
|
492
|
+
delete Session(tenant_id, user_id, session_id) as session else SessionMissing {}
|
|
493
|
+
}
|
|
494
|
+
return SessionDeleted {}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
command CreateTeam {
|
|
498
|
+
input request_id: uuid
|
|
499
|
+
input tenant_id: uuid
|
|
500
|
+
input organization_id: uuid
|
|
501
|
+
input team_id: uuid
|
|
502
|
+
input created_at: timestamp
|
|
503
|
+
input name: string<2048>
|
|
504
|
+
input updated_at: optional<timestamp>
|
|
505
|
+
idempotency_key request_id
|
|
506
|
+
read Organization(tenant_id, organization_id) as organization else TeamParentMissing {}
|
|
507
|
+
create Team(tenant_id, organization_id, team_id) as team else TeamAlreadyExists {}
|
|
508
|
+
set team.created_at = created_at
|
|
509
|
+
set team.name = name
|
|
510
|
+
set team.updated_at = updated_at
|
|
511
|
+
set team.revision = 1
|
|
512
|
+
return TeamCreated {}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
command UpdateTeam {
|
|
516
|
+
input request_id: uuid
|
|
517
|
+
input tenant_id: uuid
|
|
518
|
+
input organization_id: uuid
|
|
519
|
+
input team_id: uuid
|
|
520
|
+
input expected_revision: u64
|
|
521
|
+
input created_at: timestamp
|
|
522
|
+
input name: string<2048>
|
|
523
|
+
input updated_at: optional<timestamp>
|
|
524
|
+
idempotency_key request_id
|
|
525
|
+
mutate Team(tenant_id, organization_id, team_id) as team else TeamUpdateMissing {}
|
|
526
|
+
require current_revision: team.revision == expected_revision else TeamUpdateStale {}
|
|
527
|
+
set team.created_at = created_at checked_by current_revision
|
|
528
|
+
set team.name = name checked_by current_revision
|
|
529
|
+
set team.updated_at = updated_at checked_by current_revision
|
|
530
|
+
set team.revision = team.revision + 1
|
|
531
|
+
return TeamUpdated {}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
bulk command DeleteTeam {
|
|
535
|
+
input request_id: uuid
|
|
536
|
+
input tenant_id: uuid
|
|
537
|
+
input organization_id: uuid
|
|
538
|
+
input team_ids: list<uuid, 1..32>
|
|
539
|
+
idempotency_key request_id
|
|
540
|
+
for team_id in team_ids {
|
|
541
|
+
delete Team(tenant_id, organization_id, team_id) as team else TeamMissing {}
|
|
542
|
+
}
|
|
543
|
+
return TeamDeleted {}
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
command CreateTeamMember {
|
|
547
|
+
input request_id: uuid
|
|
548
|
+
input tenant_id: uuid
|
|
549
|
+
input user_id: uuid
|
|
550
|
+
input team_member_id: uuid
|
|
551
|
+
input created_at: optional<timestamp>
|
|
552
|
+
input team_id: uuid
|
|
553
|
+
idempotency_key request_id
|
|
554
|
+
read User(tenant_id, user_id) as user else TeamMemberParentMissing {}
|
|
555
|
+
create TeamMember(tenant_id, user_id, team_member_id) as team_member else TeamMemberAlreadyExists {}
|
|
556
|
+
set team_member.created_at = created_at
|
|
557
|
+
set team_member.team_id = team_id
|
|
558
|
+
set team_member.revision = 1
|
|
559
|
+
return TeamMemberCreated {}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
command UpdateTeamMember {
|
|
563
|
+
input request_id: uuid
|
|
564
|
+
input tenant_id: uuid
|
|
565
|
+
input user_id: uuid
|
|
566
|
+
input team_member_id: uuid
|
|
567
|
+
input expected_revision: u64
|
|
568
|
+
input created_at: optional<timestamp>
|
|
569
|
+
input team_id: uuid
|
|
570
|
+
idempotency_key request_id
|
|
571
|
+
mutate TeamMember(tenant_id, user_id, team_member_id) as team_member else TeamMemberUpdateMissing {}
|
|
572
|
+
require current_revision: team_member.revision == expected_revision else TeamMemberUpdateStale {}
|
|
573
|
+
set team_member.created_at = created_at checked_by current_revision
|
|
574
|
+
set team_member.team_id = team_id checked_by current_revision
|
|
575
|
+
set team_member.revision = team_member.revision + 1
|
|
576
|
+
return TeamMemberUpdated {}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
bulk command DeleteTeamMember {
|
|
580
|
+
input request_id: uuid
|
|
581
|
+
input tenant_id: uuid
|
|
582
|
+
input user_id: uuid
|
|
583
|
+
input team_member_ids: list<uuid, 1..32>
|
|
584
|
+
idempotency_key request_id
|
|
585
|
+
for team_member_id in team_member_ids {
|
|
586
|
+
delete TeamMember(tenant_id, user_id, team_member_id) as team_member else TeamMemberMissing {}
|
|
587
|
+
}
|
|
588
|
+
return TeamMemberDeleted {}
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
command CreateTwoFactor {
|
|
592
|
+
input request_id: uuid
|
|
593
|
+
input tenant_id: uuid
|
|
594
|
+
input user_id: uuid
|
|
595
|
+
input two_factor_id: uuid
|
|
596
|
+
input backup_codes: string<2048>
|
|
597
|
+
input failed_verification_count: optional<i64>
|
|
598
|
+
input locked_until: optional<timestamp>
|
|
599
|
+
input secret: string<2048>
|
|
600
|
+
input verified: optional<bool>
|
|
601
|
+
idempotency_key request_id
|
|
602
|
+
read User(tenant_id, user_id) as user else TwoFactorParentMissing {}
|
|
603
|
+
create TwoFactor(tenant_id, user_id, two_factor_id) as two_factor else TwoFactorAlreadyExists {}
|
|
604
|
+
set two_factor.backup_codes = backup_codes
|
|
605
|
+
set two_factor.failed_verification_count = failed_verification_count
|
|
606
|
+
set two_factor.locked_until = locked_until
|
|
607
|
+
set two_factor.secret = secret
|
|
608
|
+
set two_factor.verified = verified
|
|
609
|
+
set two_factor.revision = 1
|
|
610
|
+
return TwoFactorCreated {}
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
command UpdateTwoFactor {
|
|
614
|
+
input request_id: uuid
|
|
615
|
+
input tenant_id: uuid
|
|
616
|
+
input user_id: uuid
|
|
617
|
+
input two_factor_id: uuid
|
|
618
|
+
input expected_revision: u64
|
|
619
|
+
input backup_codes: string<2048>
|
|
620
|
+
input failed_verification_count: optional<i64>
|
|
621
|
+
input locked_until: optional<timestamp>
|
|
622
|
+
input secret: string<2048>
|
|
623
|
+
input verified: optional<bool>
|
|
624
|
+
idempotency_key request_id
|
|
625
|
+
mutate TwoFactor(tenant_id, user_id, two_factor_id) as two_factor else TwoFactorUpdateMissing {}
|
|
626
|
+
require current_revision: two_factor.revision == expected_revision else TwoFactorUpdateStale {}
|
|
627
|
+
set two_factor.backup_codes = backup_codes checked_by current_revision
|
|
628
|
+
set two_factor.failed_verification_count = failed_verification_count checked_by current_revision
|
|
629
|
+
set two_factor.locked_until = locked_until checked_by current_revision
|
|
630
|
+
set two_factor.secret = secret checked_by current_revision
|
|
631
|
+
set two_factor.verified = verified checked_by current_revision
|
|
632
|
+
set two_factor.revision = two_factor.revision + 1
|
|
633
|
+
return TwoFactorUpdated {}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
bulk command DeleteTwoFactor {
|
|
637
|
+
input request_id: uuid
|
|
638
|
+
input tenant_id: uuid
|
|
639
|
+
input user_id: uuid
|
|
640
|
+
input two_factor_ids: list<uuid, 1..32>
|
|
641
|
+
idempotency_key request_id
|
|
642
|
+
for two_factor_id in two_factor_ids {
|
|
643
|
+
delete TwoFactor(tenant_id, user_id, two_factor_id) as two_factor else TwoFactorMissing {}
|
|
644
|
+
}
|
|
645
|
+
return TwoFactorDeleted {}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
command CreateUser {
|
|
649
|
+
input request_id: uuid
|
|
650
|
+
input tenant_id: uuid
|
|
651
|
+
input user_id: uuid
|
|
652
|
+
input created_at: timestamp
|
|
653
|
+
input email: string<2048>
|
|
654
|
+
input email_verified: bool
|
|
655
|
+
input image: optional<string<2048>>
|
|
656
|
+
input locale: optional<string<2048>>
|
|
657
|
+
input name: string<2048>
|
|
658
|
+
input two_factor_enabled: optional<bool>
|
|
659
|
+
input updated_at: timestamp
|
|
660
|
+
idempotency_key request_id
|
|
661
|
+
create User(tenant_id, user_id) as user else UserAlreadyExists {}
|
|
662
|
+
set user.created_at = created_at
|
|
663
|
+
set user.email = email
|
|
664
|
+
set user.email_verified = email_verified
|
|
665
|
+
set user.image = image
|
|
666
|
+
set user.locale = locale
|
|
667
|
+
set user.name = name
|
|
668
|
+
set user.two_factor_enabled = two_factor_enabled
|
|
669
|
+
set user.updated_at = updated_at
|
|
670
|
+
set user.revision = 1
|
|
671
|
+
return UserCreated {}
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
command UpdateUser {
|
|
675
|
+
input request_id: uuid
|
|
676
|
+
input tenant_id: uuid
|
|
677
|
+
input user_id: uuid
|
|
678
|
+
input expected_revision: u64
|
|
679
|
+
input created_at: timestamp
|
|
680
|
+
input email: string<2048>
|
|
681
|
+
input email_verified: bool
|
|
682
|
+
input image: optional<string<2048>>
|
|
683
|
+
input locale: optional<string<2048>>
|
|
684
|
+
input name: string<2048>
|
|
685
|
+
input two_factor_enabled: optional<bool>
|
|
686
|
+
input updated_at: timestamp
|
|
687
|
+
idempotency_key request_id
|
|
688
|
+
mutate User(tenant_id, user_id) as user else UserUpdateMissing {}
|
|
689
|
+
require current_revision: user.revision == expected_revision else UserUpdateStale {}
|
|
690
|
+
set user.created_at = created_at
|
|
691
|
+
set user.email = email
|
|
692
|
+
set user.email_verified = email_verified
|
|
693
|
+
set user.image = image
|
|
694
|
+
set user.locale = locale
|
|
695
|
+
set user.name = name
|
|
696
|
+
set user.two_factor_enabled = two_factor_enabled
|
|
697
|
+
set user.updated_at = updated_at
|
|
698
|
+
set user.revision = user.revision + 1
|
|
699
|
+
return UserUpdated {}
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
bulk command DeleteUser {
|
|
703
|
+
input request_id: uuid
|
|
704
|
+
input tenant_id: uuid
|
|
705
|
+
input user_ids: list<uuid, 1..1>
|
|
706
|
+
idempotency_key request_id
|
|
707
|
+
for user_id in user_ids {
|
|
708
|
+
delete User(tenant_id, user_id) as user else UserMissing {}
|
|
709
|
+
cascade UserCascadeLimitExceeded {}
|
|
710
|
+
}
|
|
711
|
+
return UserDeleted {}
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
command CreateVerification {
|
|
715
|
+
input request_id: uuid
|
|
716
|
+
input tenant_id: uuid
|
|
717
|
+
input verification_id: uuid
|
|
718
|
+
input created_at: timestamp
|
|
719
|
+
input expires_at: timestamp
|
|
720
|
+
input identifier: string<2048>
|
|
721
|
+
input updated_at: timestamp
|
|
722
|
+
input value: string<2048>
|
|
723
|
+
idempotency_key request_id
|
|
724
|
+
create Verification(tenant_id, verification_id) as verification else VerificationAlreadyExists {}
|
|
725
|
+
set verification.created_at = created_at
|
|
726
|
+
set verification.expires_at = expires_at
|
|
727
|
+
set verification.identifier = identifier
|
|
728
|
+
set verification.updated_at = updated_at
|
|
729
|
+
set verification.value = value
|
|
730
|
+
set verification.revision = 1
|
|
731
|
+
return VerificationCreated {}
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
command UpdateVerification {
|
|
735
|
+
input request_id: uuid
|
|
736
|
+
input tenant_id: uuid
|
|
737
|
+
input verification_id: uuid
|
|
738
|
+
input expected_revision: u64
|
|
739
|
+
input created_at: timestamp
|
|
740
|
+
input expires_at: timestamp
|
|
741
|
+
input identifier: string<2048>
|
|
742
|
+
input updated_at: timestamp
|
|
743
|
+
input value: string<2048>
|
|
744
|
+
idempotency_key request_id
|
|
745
|
+
mutate Verification(tenant_id, verification_id) as verification else VerificationUpdateMissing {}
|
|
746
|
+
require current_revision: verification.revision == expected_revision else VerificationUpdateStale {}
|
|
747
|
+
set verification.created_at = created_at
|
|
748
|
+
set verification.expires_at = expires_at
|
|
749
|
+
set verification.identifier = identifier
|
|
750
|
+
set verification.updated_at = updated_at
|
|
751
|
+
set verification.value = value
|
|
752
|
+
set verification.revision = verification.revision + 1
|
|
753
|
+
return VerificationUpdated {}
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
bulk command DeleteVerification {
|
|
757
|
+
input request_id: uuid
|
|
758
|
+
input tenant_id: uuid
|
|
759
|
+
input verification_ids: list<uuid, 1..32>
|
|
760
|
+
idempotency_key request_id
|
|
761
|
+
for verification_id in verification_ids {
|
|
762
|
+
delete Verification(tenant_id, verification_id) as verification else VerificationMissing {}
|
|
763
|
+
}
|
|
764
|
+
return VerificationDeleted {}
|
|
765
|
+
}
|
|
766
|
+
}
|