@riffdb/better-auth 0.0.0-stage → 0.2.1

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.
Files changed (226) hide show
  1. package/DESIGN.md +273 -0
  2. package/LICENSE-APACHE +201 -0
  3. package/LICENSE-MIT +27 -0
  4. package/README.md +323 -2
  5. package/dist/adapter.d.ts +34 -0
  6. package/dist/adapter.d.ts.map +1 -0
  7. package/dist/adapter.js +1600 -0
  8. package/dist/adapter.js.map +1 -0
  9. package/dist/generated/client.d.ts +2166 -0
  10. package/dist/generated/client.d.ts.map +1 -0
  11. package/dist/generated/client.js +2454 -0
  12. package/dist/generated/client.js.map +1 -0
  13. package/dist/index.d.ts +7 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +7 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/plugin-dispatch.d.ts +37 -0
  18. package/dist/plugin-dispatch.d.ts.map +1 -0
  19. package/dist/plugin-dispatch.js +293 -0
  20. package/dist/plugin-dispatch.js.map +1 -0
  21. package/dist/profile-contract.d.ts +63 -0
  22. package/dist/profile-contract.d.ts.map +1 -0
  23. package/dist/profile-contract.js +543 -0
  24. package/dist/profile-contract.js.map +1 -0
  25. package/dist/profile-plan.d.ts +69 -0
  26. package/dist/profile-plan.d.ts.map +1 -0
  27. package/dist/profile-plan.js +180 -0
  28. package/dist/profile-plan.js.map +1 -0
  29. package/dist/profile.d.ts +48 -0
  30. package/dist/profile.d.ts.map +1 -0
  31. package/dist/profile.js +132 -0
  32. package/dist/profile.js.map +1 -0
  33. package/dist/profiles/custom-fields/profile.d.ts +3 -0
  34. package/dist/profiles/custom-fields/profile.d.ts.map +1 -0
  35. package/dist/profiles/custom-fields/profile.js +475 -0
  36. package/dist/profiles/custom-fields/profile.js.map +1 -0
  37. package/dist/profiles/custom-fields/src/generated/client.d.ts +2710 -0
  38. package/dist/profiles/custom-fields/src/generated/client.d.ts.map +1 -0
  39. package/dist/profiles/custom-fields/src/generated/client.js +2663 -0
  40. package/dist/profiles/custom-fields/src/generated/client.js.map +1 -0
  41. package/dist/profiles/runtime/profile.d.ts +3 -0
  42. package/dist/profiles/runtime/profile.d.ts.map +1 -0
  43. package/dist/profiles/runtime/profile.js +1065 -0
  44. package/dist/profiles/runtime/profile.js.map +1 -0
  45. package/dist/profiles/runtime/src/generated/client.d.ts +4274 -0
  46. package/dist/profiles/runtime/src/generated/client.d.ts.map +1 -0
  47. package/dist/profiles/runtime/src/generated/client.js +4607 -0
  48. package/dist/profiles/runtime/src/generated/client.js.map +1 -0
  49. package/dist/runtime-materialize.d.ts +10 -0
  50. package/dist/runtime-materialize.d.ts.map +1 -0
  51. package/dist/runtime-materialize.js +344 -0
  52. package/dist/runtime-materialize.js.map +1 -0
  53. package/dist/runtime-profile.d.ts +34 -0
  54. package/dist/runtime-profile.d.ts.map +1 -0
  55. package/dist/runtime-profile.js +203 -0
  56. package/dist/runtime-profile.js.map +1 -0
  57. package/dist/testing.d.ts +11 -0
  58. package/dist/testing.d.ts.map +1 -0
  59. package/dist/testing.js +12 -0
  60. package/dist/testing.js.map +1 -0
  61. package/generated/go/client.go +2250 -0
  62. package/generated/mcp/tools.json +13922 -0
  63. package/generated/python/client.py +4454 -0
  64. package/generated/riffdb.application.exact.json +1 -0
  65. package/generated/riffdb.contract.bundle +0 -0
  66. package/generated/rust/client.rs +6524 -0
  67. package/package.json +83 -4
  68. package/profiles/custom-fields/generated/go/client.go +2578 -0
  69. package/profiles/custom-fields/generated/mcp/tools.json +15998 -0
  70. package/profiles/custom-fields/generated/python/client.py +5141 -0
  71. package/profiles/custom-fields/generated/riffdb.application.exact.json +1 -0
  72. package/profiles/custom-fields/generated/riffdb.contract.bundle +0 -0
  73. package/profiles/custom-fields/generated/rust/client.rs +7980 -0
  74. package/profiles/custom-fields/profile.ts +474 -0
  75. package/profiles/custom-fields/riffdb/contract.riff +568 -0
  76. package/profiles/custom-fields/riffdb/queries/admin_users_all_email_asc.riffq +24 -0
  77. package/profiles/custom-fields/riffdb/queries/admin_users_contains_asc.riffq +24 -0
  78. package/profiles/custom-fields/riffdb/queries/admin_users_contains_desc.riffq +24 -0
  79. package/profiles/custom-fields/riffdb/queries/admin_users_email_contains_created_desc.riffq +24 -0
  80. package/profiles/custom-fields/riffdb/queries/admin_users_email_contains_image_asc.riffq +24 -0
  81. package/profiles/custom-fields/riffdb/queries/admin_users_ends_with_asc.riffq +24 -0
  82. package/profiles/custom-fields/riffdb/queries/admin_users_ends_with_desc.riffq +24 -0
  83. package/profiles/custom-fields/riffdb/queries/admin_users_starts_with_asc.riffq +24 -0
  84. package/profiles/custom-fields/riffdb/queries/admin_users_starts_with_desc.riffq +24 -0
  85. package/profiles/custom-fields/riffdb/queries/find_account_by_id.riffq +24 -0
  86. package/profiles/custom-fields/riffdb/queries/find_account_by_provider.riffq +26 -0
  87. package/profiles/custom-fields/riffdb/queries/find_accounts_by_user_id.riffq +25 -0
  88. package/profiles/custom-fields/riffdb/queries/find_accounts_by_user_provider.riffq +27 -0
  89. package/profiles/custom-fields/riffdb/queries/find_active_sessions_by_user_id.riffq +23 -0
  90. package/profiles/custom-fields/riffdb/queries/find_credential_account.riffq +25 -0
  91. package/profiles/custom-fields/riffdb/queries/find_expired_verification_ids.riffq +17 -0
  92. package/profiles/custom-fields/riffdb/queries/find_latest_verification.riffq +20 -0
  93. package/profiles/custom-fields/riffdb/queries/find_session_by_id.riffq +20 -0
  94. package/profiles/custom-fields/riffdb/queries/find_session_by_token.riffq +20 -0
  95. package/profiles/custom-fields/riffdb/queries/find_sessions_by_token_set.riffq +20 -0
  96. package/profiles/custom-fields/riffdb/queries/find_sessions_by_user_id.riffq +21 -0
  97. package/profiles/custom-fields/riffdb/queries/find_user_by_email.riffq +16 -0
  98. package/profiles/custom-fields/riffdb/queries/find_user_by_id.riffq +15 -0
  99. package/profiles/custom-fields/riffdb/queries/find_verification_by_id.riffq +19 -0
  100. package/profiles/custom-fields/riffdb/queries/find_verifications_by_identifier.riffq +21 -0
  101. package/profiles/custom-fields/riffdb/queries/profile_account_with_user_by_provider.riffq +31 -0
  102. package/profiles/custom-fields/riffdb/queries/profile_session_with_user_by_id.riffq +14 -0
  103. package/profiles/custom-fields/riffdb/queries/profile_session_with_user_by_token.riffq +14 -0
  104. package/profiles/custom-fields/riffdb/queries/profile_sessions_with_users_by_token_set.riffq +25 -0
  105. package/profiles/custom-fields/riffdb/queries/profile_user_with_accounts_by_email.riffq +19 -0
  106. package/profiles/custom-fields/riffdb/queries/profile_user_with_accounts_by_id.riffq +19 -0
  107. package/profiles/custom-fields/riffdb.application.json +217 -0
  108. package/profiles/custom-fields/riffdb.application.lock.json +1 -0
  109. package/profiles/custom-fields/riffdb.toml +3 -0
  110. package/profiles/custom-fields/src/generated/client.ts +3096 -0
  111. package/profiles/organization-security/materialization.json +51 -0
  112. package/profiles/organization-security/riffdb/contract.riff +778 -0
  113. package/profiles/organization-security/riffdb/queries/find_account_by_id.riffq +18 -0
  114. package/profiles/organization-security/riffdb/queries/find_invitation_by_email.riffq +17 -0
  115. package/profiles/organization-security/riffdb/queries/find_invitation_by_id.riffq +18 -0
  116. package/profiles/organization-security/riffdb/queries/find_invitation_by_organization_id.riffq +17 -0
  117. package/profiles/organization-security/riffdb/queries/find_member_by_id.riffq +18 -0
  118. package/profiles/organization-security/riffdb/queries/find_member_by_user_id.riffq +17 -0
  119. package/profiles/organization-security/riffdb/queries/find_organization_by_id.riffq +16 -0
  120. package/profiles/organization-security/riffdb/queries/find_organization_by_slug.riffq +16 -0
  121. package/profiles/organization-security/riffdb/queries/find_session_by_id.riffq +18 -0
  122. package/profiles/organization-security/riffdb/queries/find_session_by_token.riffq +16 -0
  123. package/profiles/organization-security/riffdb/queries/find_team_by_id.riffq +18 -0
  124. package/profiles/organization-security/riffdb/queries/find_team_member_by_id.riffq +18 -0
  125. package/profiles/organization-security/riffdb/queries/find_team_member_by_membership_key.riffq +16 -0
  126. package/profiles/organization-security/riffdb/queries/find_team_member_by_team_id.riffq +17 -0
  127. package/profiles/organization-security/riffdb/queries/find_two_factor_by_id.riffq +18 -0
  128. package/profiles/organization-security/riffdb/queries/find_two_factor_by_secret.riffq +17 -0
  129. package/profiles/organization-security/riffdb/queries/find_user_by_email.riffq +16 -0
  130. package/profiles/organization-security/riffdb/queries/find_user_by_id.riffq +16 -0
  131. package/profiles/organization-security/riffdb/queries/find_verification_by_id.riffq +16 -0
  132. package/profiles/organization-security/riffdb/queries/find_verification_by_identifier.riffq +17 -0
  133. package/profiles/organization-security/riffdb.application.json +172 -0
  134. package/profiles/organization-security/riffdb.toml +7 -0
  135. package/profiles/organization-security.profile.json +980 -0
  136. package/profiles/runtime/generated/go/client.go +4511 -0
  137. package/profiles/runtime/generated/mcp/tools.json +30004 -0
  138. package/profiles/runtime/generated/python/client.py +9337 -0
  139. package/profiles/runtime/generated/riffdb.application.exact.json +1 -0
  140. package/profiles/runtime/generated/riffdb.contract.bundle +0 -0
  141. package/profiles/runtime/generated/rust/client.rs +13297 -0
  142. package/profiles/runtime/profile.ts +1064 -0
  143. package/profiles/runtime/riffdb/contract.riff +1053 -0
  144. package/profiles/runtime/riffdb/queries/admin_users_all_email_asc.riffq +24 -0
  145. package/profiles/runtime/riffdb/queries/admin_users_contains_asc.riffq +24 -0
  146. package/profiles/runtime/riffdb/queries/admin_users_contains_desc.riffq +24 -0
  147. package/profiles/runtime/riffdb/queries/admin_users_email_contains_created_desc.riffq +24 -0
  148. package/profiles/runtime/riffdb/queries/admin_users_email_contains_image_asc.riffq +24 -0
  149. package/profiles/runtime/riffdb/queries/admin_users_ends_with_asc.riffq +24 -0
  150. package/profiles/runtime/riffdb/queries/admin_users_ends_with_desc.riffq +24 -0
  151. package/profiles/runtime/riffdb/queries/admin_users_starts_with_asc.riffq +24 -0
  152. package/profiles/runtime/riffdb/queries/admin_users_starts_with_desc.riffq +24 -0
  153. package/profiles/runtime/riffdb/queries/find_account_by_id.riffq +24 -0
  154. package/profiles/runtime/riffdb/queries/find_account_by_provider.riffq +26 -0
  155. package/profiles/runtime/riffdb/queries/find_accounts_by_user_id.riffq +25 -0
  156. package/profiles/runtime/riffdb/queries/find_accounts_by_user_provider.riffq +27 -0
  157. package/profiles/runtime/riffdb/queries/find_active_sessions_by_user_id.riffq +23 -0
  158. package/profiles/runtime/riffdb/queries/find_credential_account.riffq +25 -0
  159. package/profiles/runtime/riffdb/queries/find_expired_verification_ids.riffq +17 -0
  160. package/profiles/runtime/riffdb/queries/find_latest_verification.riffq +20 -0
  161. package/profiles/runtime/riffdb/queries/find_session_by_id.riffq +20 -0
  162. package/profiles/runtime/riffdb/queries/find_session_by_token.riffq +20 -0
  163. package/profiles/runtime/riffdb/queries/find_sessions_by_token_set.riffq +20 -0
  164. package/profiles/runtime/riffdb/queries/find_sessions_by_user_id.riffq +21 -0
  165. package/profiles/runtime/riffdb/queries/find_user_by_email.riffq +16 -0
  166. package/profiles/runtime/riffdb/queries/find_user_by_id.riffq +15 -0
  167. package/profiles/runtime/riffdb/queries/find_verification_by_id.riffq +19 -0
  168. package/profiles/runtime/riffdb/queries/find_verifications_by_identifier.riffq +21 -0
  169. package/profiles/runtime/riffdb/queries/profile_account_with_user_by_provider.riffq +31 -0
  170. package/profiles/runtime/riffdb/queries/profile_invitation_by_email.riffq +17 -0
  171. package/profiles/runtime/riffdb/queries/profile_invitation_by_id.riffq +17 -0
  172. package/profiles/runtime/riffdb/queries/profile_invitation_by_organization_email_status.riffq +19 -0
  173. package/profiles/runtime/riffdb/queries/profile_invitation_by_organization_id.riffq +17 -0
  174. package/profiles/runtime/riffdb/queries/profile_invitation_by_organization_status.riffq +18 -0
  175. package/profiles/runtime/riffdb/queries/profile_member_by_id.riffq +27 -0
  176. package/profiles/runtime/riffdb/queries/profile_member_by_organization.riffq +20 -0
  177. package/profiles/runtime/riffdb/queries/profile_member_by_organization_created_at_asc.riffq +20 -0
  178. package/profiles/runtime/riffdb/queries/profile_member_by_organization_created_at_desc.riffq +20 -0
  179. package/profiles/runtime/riffdb/queries/profile_member_by_organization_role_asc.riffq +20 -0
  180. package/profiles/runtime/riffdb/queries/profile_member_by_organization_role_desc.riffq +20 -0
  181. package/profiles/runtime/riffdb/queries/profile_member_by_organization_user.riffq +28 -0
  182. package/profiles/runtime/riffdb/queries/profile_member_by_user.riffq +27 -0
  183. package/profiles/runtime/riffdb/queries/profile_organization_by_id.riffq +27 -0
  184. package/profiles/runtime/riffdb/queries/profile_organization_by_slug.riffq +27 -0
  185. package/profiles/runtime/riffdb/queries/profile_session_with_user_by_id.riffq +14 -0
  186. package/profiles/runtime/riffdb/queries/profile_session_with_user_by_token.riffq +14 -0
  187. package/profiles/runtime/riffdb/queries/profile_sessions_with_users_by_token_set.riffq +25 -0
  188. package/profiles/runtime/riffdb/queries/profile_two_factor_by_id.riffq +17 -0
  189. package/profiles/runtime/riffdb/queries/profile_two_factor_by_user.riffq +17 -0
  190. package/profiles/runtime/riffdb/queries/profile_user_with_accounts_by_email.riffq +19 -0
  191. package/profiles/runtime/riffdb/queries/profile_user_with_accounts_by_id.riffq +19 -0
  192. package/profiles/runtime/riffdb/queries/profile_users_by_id_set.riffq +8 -0
  193. package/profiles/runtime/riffdb.application.json +324 -0
  194. package/profiles/runtime/riffdb.application.lock.json +1 -0
  195. package/profiles/runtime/riffdb.toml +3 -0
  196. package/profiles/runtime/src/generated/client.ts +5186 -0
  197. package/riffdb/contract.riff +547 -0
  198. package/riffdb/queries/admin_users_all_email_asc.riffq +24 -0
  199. package/riffdb/queries/admin_users_contains_asc.riffq +24 -0
  200. package/riffdb/queries/admin_users_contains_desc.riffq +24 -0
  201. package/riffdb/queries/admin_users_email_contains_created_desc.riffq +24 -0
  202. package/riffdb/queries/admin_users_email_contains_image_asc.riffq +24 -0
  203. package/riffdb/queries/admin_users_ends_with_asc.riffq +24 -0
  204. package/riffdb/queries/admin_users_ends_with_desc.riffq +24 -0
  205. package/riffdb/queries/admin_users_starts_with_asc.riffq +24 -0
  206. package/riffdb/queries/admin_users_starts_with_desc.riffq +24 -0
  207. package/riffdb/queries/find_account_by_id.riffq +24 -0
  208. package/riffdb/queries/find_account_by_provider.riffq +26 -0
  209. package/riffdb/queries/find_accounts_by_user_id.riffq +25 -0
  210. package/riffdb/queries/find_accounts_by_user_provider.riffq +27 -0
  211. package/riffdb/queries/find_active_sessions_by_user_id.riffq +23 -0
  212. package/riffdb/queries/find_credential_account.riffq +25 -0
  213. package/riffdb/queries/find_expired_verification_ids.riffq +17 -0
  214. package/riffdb/queries/find_latest_verification.riffq +20 -0
  215. package/riffdb/queries/find_session_by_id.riffq +20 -0
  216. package/riffdb/queries/find_session_by_token.riffq +20 -0
  217. package/riffdb/queries/find_sessions_by_token_set.riffq +20 -0
  218. package/riffdb/queries/find_sessions_by_user_id.riffq +21 -0
  219. package/riffdb/queries/find_user_by_email.riffq +16 -0
  220. package/riffdb/queries/find_user_by_id.riffq +15 -0
  221. package/riffdb/queries/find_verification_by_id.riffq +19 -0
  222. package/riffdb/queries/find_verifications_by_identifier.riffq +21 -0
  223. package/riffdb.application.json +187 -0
  224. package/riffdb.application.lock.json +1 -0
  225. package/scripts/real-riffdb-runner.mjs +333 -0
  226. package/src/generated/client.ts +2746 -0
@@ -0,0 +1,568 @@
1
+ contract BetterAuthCustomFields version 1 {
2
+
3
+ entity User {
4
+ key (organization_id: uuid, user_id: uuid)
5
+ field name: string<256>
6
+ field email: string<320>
7
+ field email_verified: bool
8
+ field image: optional<string<2048>>
9
+ field created_at: timestamp
10
+ field updated_at: timestamp
11
+ field revision: u64
12
+ field date_field: optional<timestamp>
13
+ field locale: optional<string<2048>>
14
+ index by_id (organization_id, user_id)
15
+ unique user_email (organization_id, email)
16
+ index by_email (organization_id, email, user_id) cover(name, email_verified, image, created_at, updated_at, revision, date_field, locale)
17
+ index search_email (organization_id, email, user_id) text_key(email, binary_utf8_v1) cover(name, email_verified, image, created_at, updated_at, revision, date_field, locale)
18
+ index by_created_at (organization_id, created_at, user_id) cover(name, email, email_verified, image, updated_at, revision, date_field, locale)
19
+ index by_image (organization_id, image, user_id) presence(image) cover(name, email, email_verified, created_at, updated_at, revision, date_field, locale)
20
+ delete_policy cascade {
21
+ relationship Account.account_user using Account.by_user maximum 32
22
+ relationship Session.session_user using Session.by_user maximum 32
23
+ }
24
+ }
25
+
26
+ entity Account {
27
+ key (organization_id: uuid, user_id: uuid, id: uuid)
28
+ field account_id: string<256>
29
+ field provider_id: string<64>
30
+ field secret access_token: optional<string<4096>>
31
+ field secret refresh_token: optional<string<4096>>
32
+ field access_token_expires_at: optional<timestamp>
33
+ field refresh_token_expires_at: optional<timestamp>
34
+ field scope: optional<string<2048>>
35
+ field secret id_token: optional<string<8192>>
36
+ field secret password: optional<string<1024>>
37
+ field created_at: timestamp
38
+ field updated_at: timestamp
39
+ field revision: u64
40
+ unique account_row_id (organization_id, id)
41
+ unique provider_identity (organization_id, provider_id, account_id)
42
+ index by_id (organization_id, id, user_id)
43
+ index by_provider (organization_id, provider_id, account_id, user_id, id)
44
+ index by_user (organization_id, user_id, id)
45
+ index by_user_provider (organization_id, user_id, provider_id, id)
46
+ reference account_user (organization_id, user_id) -> User(organization_id, user_id)
47
+ delete_policy no_inbound
48
+ }
49
+
50
+ entity Session {
51
+ key (organization_id: uuid, user_id: uuid, id: uuid)
52
+ field secret token: string<512>
53
+ field expires_at: timestamp
54
+ field ip_address: optional<string<128>>
55
+ field user_agent: optional<string<2048>>
56
+ field created_at: timestamp
57
+ field updated_at: timestamp
58
+ field revision: u64
59
+ unique session_token (organization_id, token)
60
+ unique session_id (organization_id, id)
61
+ index by_token (organization_id, token, user_id, id)
62
+ index by_id (organization_id, id, user_id)
63
+ index by_user (organization_id, user_id, id)
64
+ index by_user_expiry (organization_id, user_id, expires_at, id)
65
+ reference session_user (organization_id, user_id) -> User(organization_id, user_id)
66
+ delete_policy no_inbound
67
+ }
68
+
69
+ entity Verification {
70
+ key (organization_id: uuid, verification_id: uuid)
71
+ field identifier: string<1024>
72
+ field secret value: string<4096>
73
+ field expires_at: timestamp
74
+ field created_at: timestamp
75
+ field updated_at: timestamp
76
+ field revision: u64
77
+ index by_identifier_created (organization_id, identifier, created_at, verification_id)
78
+ index by_expiry (organization_id, expires_at, verification_id)
79
+ delete_policy no_inbound
80
+ }
81
+
82
+ entity AccountPasswordUpdate {
83
+ key (organization_id: uuid, user_id: uuid, account_id: uuid)
84
+ field provider_id: string<64>
85
+ field secret password: optional<string<1024>>
86
+ field updated_at: timestamp
87
+ field expected_revision: u64
88
+ }
89
+
90
+ entity Tenant {
91
+ key (organization_id: uuid)
92
+ delete_policy no_inbound
93
+ }
94
+
95
+ aggregate TenantData {
96
+ root Tenant
97
+ child User
98
+ child Account
99
+ child Session
100
+ child Verification
101
+ child AccountPasswordUpdate
102
+ partition_by organization_id
103
+ conflict_key (organization_id)
104
+ }
105
+
106
+ command CreateUser {
107
+ input request_id: uuid
108
+ input organization_id: uuid
109
+ input id: uuid
110
+ input name: string<256>
111
+ input email: string<320>
112
+ input email_verified: bool
113
+ input image: optional<string<2048>>
114
+ input created_at: timestamp
115
+ input updated_at: timestamp
116
+ input date_field: optional<timestamp>
117
+ input locale: optional<string<2048>>
118
+ idempotency_key request_id
119
+ create User(organization_id, id) as user else UserAlreadyExists {}
120
+ set user.name = name
121
+ set user.email = email
122
+ set user.email_verified = email_verified
123
+ set user.image = image
124
+ set user.created_at = created_at
125
+ set user.updated_at = updated_at
126
+ set user.date_field = date_field
127
+ set user.locale = locale
128
+ set user.revision = 1
129
+ return UserCreated {}
130
+ }
131
+
132
+ command CreateAccount {
133
+ input request_id: uuid
134
+ input organization_id: uuid
135
+ input user_id: uuid
136
+ input id: uuid
137
+ input account_id: string<256>
138
+ input provider_id: string<64>
139
+ input access_token: optional<string<4096>>
140
+ input refresh_token: optional<string<4096>>
141
+ input access_token_expires_at: optional<timestamp>
142
+ input refresh_token_expires_at: optional<timestamp>
143
+ input scope: optional<string<2048>>
144
+ input id_token: optional<string<8192>>
145
+ input password: optional<string<1024>>
146
+ input created_at: timestamp
147
+ input updated_at: timestamp
148
+ idempotency_key request_id
149
+ read User(organization_id, user_id) as owner else AccountUserMissing {}
150
+ create Account(organization_id, user_id, id) as account else AccountAlreadyExists {}
151
+ set account.account_id = account_id
152
+ set account.provider_id = provider_id
153
+ set account.access_token = access_token
154
+ set account.refresh_token = refresh_token
155
+ set account.access_token_expires_at = access_token_expires_at
156
+ set account.refresh_token_expires_at = refresh_token_expires_at
157
+ set account.scope = scope
158
+ set account.id_token = id_token
159
+ set account.password = password
160
+ set account.created_at = created_at
161
+ set account.updated_at = updated_at
162
+ set account.revision = 1
163
+ return AccountCreated {}
164
+ }
165
+
166
+ command CreateSession {
167
+ input request_id: uuid
168
+ input organization_id: uuid
169
+ input user_id: uuid
170
+ input id: uuid
171
+ input token: string<512>
172
+ input expires_at: timestamp
173
+ input ip_address: optional<string<128>>
174
+ input user_agent: optional<string<2048>>
175
+ input created_at: timestamp
176
+ input updated_at: timestamp
177
+ idempotency_key request_id
178
+ read User(organization_id, user_id) as owner else SessionUserMissing {}
179
+ create Session(organization_id, user_id, id) as session else SessionAlreadyExists {}
180
+ set session.token = token
181
+ set session.expires_at = expires_at
182
+ set session.ip_address = ip_address
183
+ set session.user_agent = user_agent
184
+ set session.created_at = created_at
185
+ set session.updated_at = updated_at
186
+ set session.revision = 1
187
+ return SessionCreated {}
188
+ }
189
+
190
+ command CreateVerification {
191
+ input request_id: uuid
192
+ input organization_id: uuid
193
+ input id: uuid
194
+ input identifier: string<1024>
195
+ input value: string<4096>
196
+ input expires_at: timestamp
197
+ input created_at: timestamp
198
+ input updated_at: timestamp
199
+ idempotency_key request_id
200
+ create Verification(organization_id, id) as verification else VerificationAlreadyExists {}
201
+ set verification.identifier = identifier
202
+ set verification.value = value
203
+ set verification.expires_at = expires_at
204
+ set verification.created_at = created_at
205
+ set verification.updated_at = updated_at
206
+ set verification.revision = 1
207
+ return VerificationCreated {}
208
+ }
209
+
210
+ command CreateSignupGraph {
211
+ input request_id: uuid
212
+ input organization_id: uuid
213
+ input user_id: uuid
214
+ input user_name: string<256>
215
+ input user_email: string<320>
216
+ input user_email_verified: bool
217
+ input user_image: optional<string<2048>>
218
+ input user_created_at: timestamp
219
+ input user_updated_at: timestamp
220
+ input account_id: uuid
221
+ input external_account_id: string<256>
222
+ input provider_id: string<64>
223
+ input account_password: optional<string<1024>>
224
+ input account_created_at: timestamp
225
+ input account_updated_at: timestamp
226
+ input session_id: uuid
227
+ input session_token: string<512>
228
+ input session_expires_at: timestamp
229
+ input session_ip_address: optional<string<128>>
230
+ input session_user_agent: optional<string<2048>>
231
+ input session_created_at: timestamp
232
+ input session_updated_at: timestamp
233
+ input user_date_field: optional<timestamp>
234
+ input user_locale: optional<string<2048>>
235
+ idempotency_key request_id
236
+ create User(organization_id, user_id) as user else SignupUserExists {}
237
+ create Account(organization_id, user_id, account_id) as account else SignupAccountExists {}
238
+ create Session(organization_id, user_id, session_id) as session else SignupSessionExists {}
239
+ set user.name = user_name
240
+ set user.email = user_email
241
+ set user.email_verified = user_email_verified
242
+ set user.image = user_image
243
+ set user.created_at = user_created_at
244
+ set user.updated_at = user_updated_at
245
+ set user.date_field = user_date_field
246
+ set user.locale = user_locale
247
+ set user.revision = 1
248
+ set account.account_id = external_account_id
249
+ set account.provider_id = provider_id
250
+ set account.access_token = null
251
+ set account.refresh_token = null
252
+ set account.access_token_expires_at = null
253
+ set account.refresh_token_expires_at = null
254
+ set account.scope = null
255
+ set account.id_token = null
256
+ set account.password = account_password
257
+ set account.created_at = account_created_at
258
+ set account.updated_at = account_updated_at
259
+ set account.revision = 1
260
+ set session.token = session_token
261
+ set session.expires_at = session_expires_at
262
+ set session.ip_address = session_ip_address
263
+ set session.user_agent = session_user_agent
264
+ set session.created_at = session_created_at
265
+ set session.updated_at = session_updated_at
266
+ set session.revision = 1
267
+ return SignupGraphCreated {}
268
+ }
269
+
270
+ command CreateOAuthUserGraph {
271
+ input request_id: uuid
272
+ input organization_id: uuid
273
+ input user_id: uuid
274
+ input user_name: string<256>
275
+ input user_email: string<320>
276
+ input user_email_verified: bool
277
+ input user_image: optional<string<2048>>
278
+ input user_created_at: timestamp
279
+ input user_updated_at: timestamp
280
+ input account_id: uuid
281
+ input external_account_id: string<256>
282
+ input provider_id: string<64>
283
+ input access_token: optional<string<4096>>
284
+ input refresh_token: optional<string<4096>>
285
+ input access_token_expires_at: optional<timestamp>
286
+ input refresh_token_expires_at: optional<timestamp>
287
+ input scope: optional<string<2048>>
288
+ input id_token: optional<string<8192>>
289
+ input password: optional<string<1024>>
290
+ input account_created_at: timestamp
291
+ input account_updated_at: timestamp
292
+ input user_date_field: optional<timestamp>
293
+ input user_locale: optional<string<2048>>
294
+ idempotency_key request_id
295
+ create User(organization_id, user_id) as user else OAuthUserExists {}
296
+ create Account(organization_id, user_id, account_id) as account else OAuthAccountExists {}
297
+ set user.name = user_name
298
+ set user.email = user_email
299
+ set user.email_verified = user_email_verified
300
+ set user.image = user_image
301
+ set user.created_at = user_created_at
302
+ set user.updated_at = user_updated_at
303
+ set user.date_field = user_date_field
304
+ set user.locale = user_locale
305
+ set user.revision = 1
306
+ set account.account_id = external_account_id
307
+ set account.provider_id = provider_id
308
+ set account.access_token = access_token
309
+ set account.refresh_token = refresh_token
310
+ set account.access_token_expires_at = access_token_expires_at
311
+ set account.refresh_token_expires_at = refresh_token_expires_at
312
+ set account.scope = scope
313
+ set account.id_token = id_token
314
+ set account.password = password
315
+ set account.created_at = account_created_at
316
+ set account.updated_at = account_updated_at
317
+ set account.revision = 1
318
+ return OAuthUserGraphCreated {}
319
+ }
320
+
321
+ command UpdateUser {
322
+ input request_id: uuid
323
+ input organization_id: uuid
324
+ input user_id: uuid
325
+ input expected_revision: u64
326
+ input name: string<256>
327
+ input email: string<320>
328
+ input email_verified: bool
329
+ input image: optional<string<2048>>
330
+ input updated_at: timestamp
331
+ input date_field: optional<timestamp>
332
+ input locale: optional<string<2048>>
333
+ idempotency_key request_id
334
+ mutate User(organization_id, user_id) as user else UserUpdateMissing {}
335
+ require current_revision: user.revision == expected_revision else UserUpdateStale {}
336
+ set user.name = name checked_by current_revision
337
+ set user.email = email checked_by current_revision
338
+ set user.email_verified = email_verified checked_by current_revision
339
+ set user.image = image checked_by current_revision
340
+ set user.updated_at = updated_at checked_by current_revision
341
+ set user.date_field = date_field checked_by current_revision
342
+ set user.locale = locale checked_by current_revision
343
+ set user.revision = user.revision + 1
344
+ return UserUpdated {}
345
+ }
346
+
347
+ command UpdateSession {
348
+ input request_id: uuid
349
+ input organization_id: uuid
350
+ input user_id: uuid
351
+ input session_id: uuid
352
+ input expected_revision: u64
353
+ input expires_at: timestamp
354
+ input ip_address: optional<string<128>>
355
+ input user_agent: optional<string<2048>>
356
+ input updated_at: timestamp
357
+ idempotency_key request_id
358
+ mutate Session(organization_id, user_id, session_id) as session else SessionUpdateMissing {}
359
+ require current_revision: session.revision == expected_revision else SessionUpdateStale {}
360
+ set session.expires_at = expires_at checked_by current_revision
361
+ set session.ip_address = ip_address checked_by current_revision
362
+ set session.user_agent = user_agent checked_by current_revision
363
+ set session.updated_at = updated_at checked_by current_revision
364
+ set session.revision = session.revision + 1
365
+ return SessionUpdated {}
366
+ }
367
+
368
+ command UpdateAccount {
369
+ input request_id: uuid
370
+ input organization_id: uuid
371
+ input user_id: uuid
372
+ input account_id: uuid
373
+ input expected_revision: u64
374
+ input external_account_id: string<256>
375
+ input provider_id: string<64>
376
+ input access_token: optional<string<4096>>
377
+ input refresh_token: optional<string<4096>>
378
+ input access_token_expires_at: optional<timestamp>
379
+ input refresh_token_expires_at: optional<timestamp>
380
+ input scope: optional<string<2048>>
381
+ input id_token: optional<string<8192>>
382
+ input password: optional<string<1024>>
383
+ input updated_at: timestamp
384
+ idempotency_key request_id
385
+ mutate Account(organization_id, user_id, account_id) as account else AccountUpdateMissing {}
386
+ require current_revision: account.revision == expected_revision else AccountUpdateStale {}
387
+ set account.account_id = external_account_id checked_by current_revision
388
+ set account.provider_id = provider_id checked_by current_revision
389
+ set account.access_token = access_token checked_by current_revision
390
+ set account.refresh_token = refresh_token checked_by current_revision
391
+ set account.access_token_expires_at = access_token_expires_at checked_by current_revision
392
+ set account.refresh_token_expires_at = refresh_token_expires_at checked_by current_revision
393
+ set account.scope = scope checked_by current_revision
394
+ set account.id_token = id_token checked_by current_revision
395
+ set account.password = password checked_by current_revision
396
+ set account.updated_at = updated_at checked_by current_revision
397
+ set account.revision = account.revision + 1
398
+ return AccountUpdated {}
399
+ }
400
+
401
+ command UpdateVerification {
402
+ input request_id: uuid
403
+ input organization_id: uuid
404
+ input verification_id: uuid
405
+ input expected_revision: u64
406
+ input value: string<4096>
407
+ input expires_at: timestamp
408
+ input updated_at: timestamp
409
+ idempotency_key request_id
410
+ mutate Verification(organization_id, verification_id) as verification else VerificationUpdateMissing {}
411
+ require current_revision: verification.revision == expected_revision else VerificationUpdateStale {}
412
+ set verification.value = value checked_by current_revision
413
+ set verification.expires_at = expires_at checked_by current_revision
414
+ set verification.updated_at = updated_at checked_by current_revision
415
+ set verification.revision = verification.revision + 1
416
+ return VerificationUpdated {}
417
+ }
418
+
419
+ bulk command DeleteSession {
420
+ input request_id: uuid
421
+ input organization_id: uuid
422
+ input user_id: uuid
423
+ input session_ids: list<uuid, 1..32>
424
+ idempotency_key request_id
425
+ for session_id in session_ids {
426
+ delete Session(organization_id, user_id, session_id) as session else SessionMissing {}
427
+ }
428
+ return SessionDeleted {}
429
+ }
430
+
431
+ bulk command DeleteAccount {
432
+ input request_id: uuid
433
+ input organization_id: uuid
434
+ input user_id: uuid
435
+ input account_ids: list<uuid, 1..32>
436
+ idempotency_key request_id
437
+ for account_id in account_ids {
438
+ delete Account(organization_id, user_id, account_id) as account else AccountMissing {}
439
+ }
440
+ return AccountDeleted {}
441
+ }
442
+
443
+ bulk command DeleteVerification {
444
+ input request_id: uuid
445
+ input organization_id: uuid
446
+ input verification_ids: list<uuid, 1..32>
447
+ idempotency_key request_id
448
+ for verification_id in verification_ids {
449
+ delete Verification(organization_id, verification_id) as verification else VerificationMissing {}
450
+ }
451
+ return VerificationDeleted {}
452
+ }
453
+
454
+ bulk command DeleteUser {
455
+ input request_id: uuid
456
+ input organization_id: uuid
457
+ input user_ids: list<uuid, 1..1>
458
+ idempotency_key request_id
459
+ for user_id in user_ids {
460
+ delete User(organization_id, user_id) as user else DeleteUserMissing {}
461
+ cascade DeleteUserCascadeLimitExceeded {}
462
+ }
463
+ return UserDeleted {}
464
+ }
465
+
466
+ bulk command ConsumeVerificationSet {
467
+ input request_id: uuid
468
+ input organization_id: uuid
469
+ input verification_ids: list<uuid, 1..32>
470
+ idempotency_key request_id
471
+ for verification_id in verification_ids {
472
+ delete Verification(organization_id, verification_id) as verification else VerificationConsumeMissing {}
473
+ }
474
+ return VerificationSetConsumed {}
475
+ }
476
+
477
+ command ConsumeVerification {
478
+ input request_id: uuid
479
+ input organization_id: uuid
480
+ input verification_id: uuid
481
+ idempotency_key request_id
482
+ delete Verification(organization_id, verification_id) as verification else VerificationConsumeMissing {}
483
+ return VerificationConsumed {
484
+ verification_id: verification.verification_id,
485
+ identifier: verification.identifier,
486
+ value: verification.value reveals verification.value,
487
+ expires_at: verification.expires_at,
488
+ created_at: verification.created_at,
489
+ updated_at: verification.updated_at,
490
+ revision: verification.revision
491
+ }
492
+ }
493
+
494
+ bulk command UpdateAccountPasswords {
495
+ input request_id: uuid
496
+ input organization_id: uuid
497
+ input user_id: uuid
498
+ input updates: list<AccountPasswordUpdate, 1..8>
499
+ idempotency_key request_id
500
+ for update in updates {
501
+ mutate Account(organization_id, user_id, update.account_id) as account else PasswordAccountMissing {}
502
+ require provider_matches: account.provider_id == update.provider_id else PasswordProviderMismatch {}
503
+ require current_revision: account.revision == update.expected_revision else PasswordAccountStale {}
504
+ set account.password = update.password checked_by current_revision
505
+ set account.updated_at = update.updated_at checked_by current_revision
506
+ set account.revision = account.revision + 1
507
+ }
508
+ return AccountPasswordsUpdated {}
509
+ }
510
+
511
+ command ConsumeVerificationSnapshot {
512
+ input request_id: uuid
513
+ input organization_id: uuid
514
+ input verification_id: uuid
515
+ input expected_revision: u64
516
+ idempotency_key request_id
517
+ delete Verification(organization_id, verification_id) as verification else VerificationConsumeMissing {}
518
+ require snapshot: verification.revision == expected_revision else VerificationConsumeStale {}
519
+ return VerificationConsumed {}
520
+ }
521
+
522
+ bulk command ResetCredentialPassword {
523
+ input request_id: uuid
524
+ input organization_id: uuid
525
+ input verification_ids: list<uuid, 1..1>
526
+ input verification_revision: u64
527
+ input user_id: uuid
528
+ input external_account_id: string<256>
529
+ input account_id: uuid
530
+ input account_revision: u64
531
+ input password: string<1024>
532
+ input updated_at: timestamp
533
+ idempotency_key request_id
534
+ mutate Account(organization_id, user_id, account_id) as account else PasswordAccountMissing {}
535
+ for verification_id in verification_ids {
536
+ delete Verification(organization_id, verification_id) as verification else VerificationConsumeMissing {}
537
+ require verification_snapshot: verification.revision == verification_revision else VerificationConsumeStale {}
538
+ }
539
+ require credential_provider: account.provider_id == "credential" else PasswordProviderMismatch {}
540
+ require credential_identity: account.account_id == external_account_id else PasswordProviderMismatch {}
541
+ require account_snapshot: account.revision == account_revision else PasswordAccountStale {}
542
+ set account.password = password checked_by account_snapshot
543
+ set account.updated_at = updated_at checked_by account_snapshot
544
+ set account.revision = account.revision + 1
545
+ return CredentialPasswordReset {}
546
+ }
547
+
548
+ command UpdateCredentialPassword {
549
+ input request_id: uuid
550
+ input organization_id: uuid
551
+ input user_id: uuid
552
+ input account_id: uuid
553
+ input external_account_id: string<256>
554
+ input expected_revision: u64
555
+ input password: string<1024>
556
+ input updated_at: timestamp
557
+ idempotency_key request_id
558
+ mutate Account(organization_id, user_id, account_id) as account else PasswordAccountMissing {}
559
+ require credential_provider: account.provider_id == "credential" else PasswordProviderMismatch {}
560
+ require credential_identity: account.account_id == external_account_id else PasswordProviderMismatch {}
561
+ require account_snapshot: account.revision == expected_revision else PasswordAccountStale {}
562
+ set account.password = password checked_by account_snapshot
563
+ set account.updated_at = updated_at checked_by account_snapshot
564
+ set account.revision = account.revision + 1
565
+ return CredentialPasswordUpdated {}
566
+ }
567
+
568
+ }
@@ -0,0 +1,24 @@
1
+ query AdminUsersAllEmailAsc(
2
+ $organization_id: User.organization_id,
3
+ $minimum_email: User.email,
4
+ $user_id: User.user_id?,
5
+ $limit: Limit<100> = 50,
6
+ $offset: u64 = 0
7
+ ) {
8
+ many users from User
9
+ where organization_id == $organization_id
10
+ && email >= $minimum_email
11
+ && when $user_id { user_id == $user_id }
12
+ order by email asc, user_id asc
13
+ take $limit offset $offset
14
+
15
+ aggregate total from users { exact_count() as value }
16
+
17
+ return Found {
18
+ users: users {
19
+ organization_id user_id name email email_verified image created_at updated_at revision
20
+ date_field locale }
21
+ total: total { value }
22
+ }
23
+ outcomes Found
24
+ }
@@ -0,0 +1,24 @@
1
+ query AdminUsersContainsAsc(
2
+ $organization_id: User.organization_id,
3
+ $needle: User.email,
4
+ $user_id: User.user_id?,
5
+ $limit: Limit<100> = 50,
6
+ $offset: u64 = 0
7
+ ) {
8
+ many users from User
9
+ where organization_id == $organization_id
10
+ && when $user_id { user_id == $user_id }
11
+ && email contains $needle
12
+ order by email asc, user_id asc
13
+ take $limit offset $offset
14
+
15
+ aggregate total from users { exact_count() as value }
16
+
17
+ return Found {
18
+ users: users {
19
+ organization_id user_id name email email_verified image created_at updated_at revision
20
+ date_field locale }
21
+ total: total { value }
22
+ }
23
+ outcomes Found
24
+ }
@@ -0,0 +1,24 @@
1
+ query AdminUsersContainsDesc(
2
+ $organization_id: User.organization_id,
3
+ $needle: User.email,
4
+ $user_id: User.user_id?,
5
+ $limit: Limit<100> = 50,
6
+ $offset: u64 = 0
7
+ ) {
8
+ many users from User
9
+ where organization_id == $organization_id
10
+ && when $user_id { user_id == $user_id }
11
+ && email contains $needle
12
+ order by email desc, user_id asc
13
+ take $limit offset $offset
14
+
15
+ aggregate total from users { exact_count() as value }
16
+
17
+ return Found {
18
+ users: users {
19
+ organization_id user_id name email email_verified image created_at updated_at revision
20
+ date_field locale }
21
+ total: total { value }
22
+ }
23
+ outcomes Found
24
+ }
@@ -0,0 +1,24 @@
1
+ query AdminUsersEmailContainsCreatedDesc(
2
+ $organization_id: User.organization_id,
3
+ $needle: User.email,
4
+ $user_id: User.user_id?,
5
+ $limit: Limit<100> = 50,
6
+ $offset: u64 = 0
7
+ ) {
8
+ many users from User
9
+ where organization_id == $organization_id
10
+ && when $user_id { user_id == $user_id }
11
+ && email contains $needle
12
+ order by created_at desc, user_id asc
13
+ take $limit offset $offset
14
+
15
+ aggregate total from users { exact_count() as value }
16
+
17
+ return Found {
18
+ users: users {
19
+ organization_id user_id name email email_verified image created_at updated_at revision
20
+ date_field locale }
21
+ total: total { value }
22
+ }
23
+ outcomes Found
24
+ }
@@ -0,0 +1,24 @@
1
+ query AdminUsersEmailContainsImageAsc(
2
+ $organization_id: User.organization_id,
3
+ $needle: User.email,
4
+ $user_id: User.user_id?,
5
+ $limit: Limit<100> = 50,
6
+ $offset: u64 = 0
7
+ ) {
8
+ many users from User
9
+ where organization_id == $organization_id
10
+ && when $user_id { user_id == $user_id }
11
+ && email contains $needle
12
+ order by image asc nulls last, user_id asc
13
+ take $limit offset $offset
14
+
15
+ aggregate total from users { exact_count() as value }
16
+
17
+ return Found {
18
+ users: users {
19
+ organization_id user_id name email email_verified image created_at updated_at revision
20
+ date_field locale }
21
+ total: total { value }
22
+ }
23
+ outcomes Found
24
+ }