@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,547 @@
1
+ contract RiffDBBetterAuthCore version 1 {
2
+ entity User {
3
+ key (organization_id: uuid, user_id: uuid)
4
+ field name: string<256>
5
+ field email: string<320>
6
+ field email_verified: bool
7
+ field image: optional<string<2048>>
8
+ field created_at: timestamp
9
+ field updated_at: timestamp
10
+ field revision: u64
11
+ unique user_email (organization_id, email)
12
+ index by_email (organization_id, email, user_id) cover(name, email_verified, image, created_at, updated_at, revision)
13
+ index search_email (organization_id, email, user_id) text_key(email, binary_utf8_v1) cover(name, email_verified, image, created_at, updated_at, revision)
14
+ index by_created_at (organization_id, created_at, user_id) cover(name, email, email_verified, image, updated_at, revision)
15
+ index by_image (organization_id, image, user_id) presence(image) cover(name, email, email_verified, created_at, updated_at, revision)
16
+ delete_policy cascade {
17
+ relationship Account.account_user using Account.by_user maximum 32
18
+ relationship Session.session_user using Session.by_user maximum 32
19
+ }
20
+ }
21
+
22
+ entity Account {
23
+ key (organization_id: uuid, user_id: uuid, id: uuid)
24
+ field account_id: string<256>
25
+ field provider_id: string<64>
26
+ field secret access_token: optional<string<4096>>
27
+ field secret refresh_token: optional<string<4096>>
28
+ field access_token_expires_at: optional<timestamp>
29
+ field refresh_token_expires_at: optional<timestamp>
30
+ field scope: optional<string<2048>>
31
+ field secret id_token: optional<string<8192>>
32
+ field secret password: optional<string<1024>>
33
+ field created_at: timestamp
34
+ field updated_at: timestamp
35
+ field revision: u64
36
+ unique account_row_id (organization_id, id)
37
+ unique provider_identity (organization_id, provider_id, account_id)
38
+ index by_id (organization_id, id, user_id)
39
+ index by_provider (organization_id, provider_id, account_id, user_id, id)
40
+ index by_user (organization_id, user_id, id)
41
+ index by_user_provider (organization_id, user_id, provider_id, id)
42
+ reference account_user (organization_id, user_id) -> User(organization_id, user_id)
43
+ delete_policy no_inbound
44
+ }
45
+
46
+ entity Session {
47
+ key (organization_id: uuid, user_id: uuid, id: uuid)
48
+ field secret token: string<512>
49
+ field expires_at: timestamp
50
+ field ip_address: optional<string<128>>
51
+ field user_agent: optional<string<2048>>
52
+ field created_at: timestamp
53
+ field updated_at: timestamp
54
+ field revision: u64
55
+ unique session_token (organization_id, token)
56
+ unique session_id (organization_id, id)
57
+ index by_token (organization_id, token, user_id, id)
58
+ index by_id (organization_id, id, user_id)
59
+ index by_user (organization_id, user_id, id)
60
+ index by_user_expiry (organization_id, user_id, expires_at, id)
61
+ reference session_user (organization_id, user_id) -> User(organization_id, user_id)
62
+ delete_policy no_inbound
63
+ }
64
+
65
+ entity Verification {
66
+ key (organization_id: uuid, verification_id: uuid)
67
+ field identifier: string<1024>
68
+ field secret value: string<4096>
69
+ field expires_at: timestamp
70
+ field created_at: timestamp
71
+ field updated_at: timestamp
72
+ field revision: u64
73
+ index by_identifier_created (organization_id, identifier, created_at, verification_id)
74
+ index by_expiry (organization_id, expires_at, verification_id)
75
+ delete_policy no_inbound
76
+ }
77
+
78
+ entity AccountPasswordUpdate {
79
+ key (organization_id: uuid, user_id: uuid, account_id: uuid)
80
+ field provider_id: string<64>
81
+ field secret password: optional<string<1024>>
82
+ field updated_at: timestamp
83
+ field expected_revision: u64
84
+ }
85
+
86
+ aggregate UserAuthData {
87
+ root User
88
+ child Account
89
+ child Session
90
+ child AccountPasswordUpdate
91
+ partition_by organization_id
92
+ conflict_key (organization_id, user_id)
93
+ }
94
+
95
+ aggregate VerificationData {
96
+ root Verification
97
+ partition_by organization_id
98
+ conflict_key (organization_id, verification_id)
99
+ }
100
+
101
+ command CreateUser {
102
+ input request_id: uuid
103
+ input organization_id: uuid
104
+ input id: uuid
105
+ input name: string<256>
106
+ input email: string<320>
107
+ input email_verified: bool
108
+ input image: optional<string<2048>>
109
+ input created_at: timestamp
110
+ input updated_at: timestamp
111
+ idempotency_key request_id
112
+ create User(organization_id, id) as user else UserAlreadyExists {}
113
+ set user.name = name
114
+ set user.email = email
115
+ set user.email_verified = email_verified
116
+ set user.image = image
117
+ set user.created_at = created_at
118
+ set user.updated_at = updated_at
119
+ set user.revision = 1
120
+ return UserCreated {}
121
+ }
122
+
123
+ command CreateAccount {
124
+ input request_id: uuid
125
+ input organization_id: uuid
126
+ input user_id: uuid
127
+ input id: uuid
128
+ input account_id: string<256>
129
+ input provider_id: string<64>
130
+ input access_token: optional<string<4096>>
131
+ input refresh_token: optional<string<4096>>
132
+ input access_token_expires_at: optional<timestamp>
133
+ input refresh_token_expires_at: optional<timestamp>
134
+ input scope: optional<string<2048>>
135
+ input id_token: optional<string<8192>>
136
+ input password: optional<string<1024>>
137
+ input created_at: timestamp
138
+ input updated_at: timestamp
139
+ idempotency_key request_id
140
+ read User(organization_id, user_id) as owner else AccountUserMissing {}
141
+ create Account(organization_id, user_id, id) as account else AccountAlreadyExists {}
142
+ set account.account_id = account_id
143
+ set account.provider_id = provider_id
144
+ set account.access_token = access_token
145
+ set account.refresh_token = refresh_token
146
+ set account.access_token_expires_at = access_token_expires_at
147
+ set account.refresh_token_expires_at = refresh_token_expires_at
148
+ set account.scope = scope
149
+ set account.id_token = id_token
150
+ set account.password = password
151
+ set account.created_at = created_at
152
+ set account.updated_at = updated_at
153
+ set account.revision = 1
154
+ return AccountCreated {}
155
+ }
156
+
157
+ command CreateSession {
158
+ input request_id: uuid
159
+ input organization_id: uuid
160
+ input user_id: uuid
161
+ input id: uuid
162
+ input token: string<512>
163
+ input expires_at: timestamp
164
+ input ip_address: optional<string<128>>
165
+ input user_agent: optional<string<2048>>
166
+ input created_at: timestamp
167
+ input updated_at: timestamp
168
+ idempotency_key request_id
169
+ read User(organization_id, user_id) as owner else SessionUserMissing {}
170
+ create Session(organization_id, user_id, id) as session else SessionAlreadyExists {}
171
+ set session.token = token
172
+ set session.expires_at = expires_at
173
+ set session.ip_address = ip_address
174
+ set session.user_agent = user_agent
175
+ set session.created_at = created_at
176
+ set session.updated_at = updated_at
177
+ set session.revision = 1
178
+ return SessionCreated {}
179
+ }
180
+
181
+ command CreateVerification {
182
+ input request_id: uuid
183
+ input organization_id: uuid
184
+ input id: uuid
185
+ input identifier: string<1024>
186
+ input value: string<4096>
187
+ input expires_at: timestamp
188
+ input created_at: timestamp
189
+ input updated_at: timestamp
190
+ idempotency_key request_id
191
+ create Verification(organization_id, id) as verification else VerificationAlreadyExists {}
192
+ set verification.identifier = identifier
193
+ set verification.value = value
194
+ set verification.expires_at = expires_at
195
+ set verification.created_at = created_at
196
+ set verification.updated_at = updated_at
197
+ set verification.revision = 1
198
+ return VerificationCreated {}
199
+ }
200
+
201
+ command CreateSignupGraph {
202
+ input request_id: uuid
203
+ input organization_id: uuid
204
+ input user_id: uuid
205
+ input user_name: string<256>
206
+ input user_email: string<320>
207
+ input user_email_verified: bool
208
+ input user_image: optional<string<2048>>
209
+ input user_created_at: timestamp
210
+ input user_updated_at: timestamp
211
+ input account_id: uuid
212
+ input external_account_id: string<256>
213
+ input provider_id: string<64>
214
+ input account_password: optional<string<1024>>
215
+ input account_created_at: timestamp
216
+ input account_updated_at: timestamp
217
+ input session_id: uuid
218
+ input session_token: string<512>
219
+ input session_expires_at: timestamp
220
+ input session_ip_address: optional<string<128>>
221
+ input session_user_agent: optional<string<2048>>
222
+ input session_created_at: timestamp
223
+ input session_updated_at: timestamp
224
+ idempotency_key request_id
225
+ create User(organization_id, user_id) as user else SignupUserExists {}
226
+ create Account(organization_id, user_id, account_id) as account else SignupAccountExists {}
227
+ create Session(organization_id, user_id, session_id) as session else SignupSessionExists {}
228
+ set user.name = user_name
229
+ set user.email = user_email
230
+ set user.email_verified = user_email_verified
231
+ set user.image = user_image
232
+ set user.created_at = user_created_at
233
+ set user.updated_at = user_updated_at
234
+ set user.revision = 1
235
+ set account.account_id = external_account_id
236
+ set account.provider_id = provider_id
237
+ set account.access_token = null
238
+ set account.refresh_token = null
239
+ set account.access_token_expires_at = null
240
+ set account.refresh_token_expires_at = null
241
+ set account.scope = null
242
+ set account.id_token = null
243
+ set account.password = account_password
244
+ set account.created_at = account_created_at
245
+ set account.updated_at = account_updated_at
246
+ set account.revision = 1
247
+ set session.token = session_token
248
+ set session.expires_at = session_expires_at
249
+ set session.ip_address = session_ip_address
250
+ set session.user_agent = session_user_agent
251
+ set session.created_at = session_created_at
252
+ set session.updated_at = session_updated_at
253
+ set session.revision = 1
254
+ return SignupGraphCreated {}
255
+ }
256
+
257
+ command CreateOAuthUserGraph {
258
+ input request_id: uuid
259
+ input organization_id: uuid
260
+ input user_id: uuid
261
+ input user_name: string<256>
262
+ input user_email: string<320>
263
+ input user_email_verified: bool
264
+ input user_image: optional<string<2048>>
265
+ input user_created_at: timestamp
266
+ input user_updated_at: timestamp
267
+ input account_id: uuid
268
+ input external_account_id: string<256>
269
+ input provider_id: string<64>
270
+ input access_token: optional<string<4096>>
271
+ input refresh_token: optional<string<4096>>
272
+ input access_token_expires_at: optional<timestamp>
273
+ input refresh_token_expires_at: optional<timestamp>
274
+ input scope: optional<string<2048>>
275
+ input id_token: optional<string<8192>>
276
+ input password: optional<string<1024>>
277
+ input account_created_at: timestamp
278
+ input account_updated_at: timestamp
279
+ idempotency_key request_id
280
+ create User(organization_id, user_id) as user else OAuthUserExists {}
281
+ create Account(organization_id, user_id, account_id) as account else OAuthAccountExists {}
282
+ set user.name = user_name
283
+ set user.email = user_email
284
+ set user.email_verified = user_email_verified
285
+ set user.image = user_image
286
+ set user.created_at = user_created_at
287
+ set user.updated_at = user_updated_at
288
+ set user.revision = 1
289
+ set account.account_id = external_account_id
290
+ set account.provider_id = provider_id
291
+ set account.access_token = access_token
292
+ set account.refresh_token = refresh_token
293
+ set account.access_token_expires_at = access_token_expires_at
294
+ set account.refresh_token_expires_at = refresh_token_expires_at
295
+ set account.scope = scope
296
+ set account.id_token = id_token
297
+ set account.password = password
298
+ set account.created_at = account_created_at
299
+ set account.updated_at = account_updated_at
300
+ set account.revision = 1
301
+ return OAuthUserGraphCreated {}
302
+ }
303
+
304
+ command UpdateUser {
305
+ input request_id: uuid
306
+ input organization_id: uuid
307
+ input user_id: uuid
308
+ input expected_revision: u64
309
+ input name: string<256>
310
+ input email: string<320>
311
+ input email_verified: bool
312
+ input image: optional<string<2048>>
313
+ input updated_at: timestamp
314
+ idempotency_key request_id
315
+ mutate User(organization_id, user_id) as user else UserUpdateMissing {}
316
+ require current_revision: user.revision == expected_revision else UserUpdateStale {}
317
+ set user.name = name
318
+ set user.email = email
319
+ set user.email_verified = email_verified
320
+ set user.image = image
321
+ set user.updated_at = updated_at
322
+ set user.revision = user.revision + 1
323
+ return UserUpdated {}
324
+ }
325
+
326
+ command UpdateSession {
327
+ input request_id: uuid
328
+ input organization_id: uuid
329
+ input user_id: uuid
330
+ input session_id: uuid
331
+ input expected_revision: u64
332
+ input expires_at: timestamp
333
+ input ip_address: optional<string<128>>
334
+ input user_agent: optional<string<2048>>
335
+ input updated_at: timestamp
336
+ idempotency_key request_id
337
+ mutate Session(organization_id, user_id, session_id) as session else SessionUpdateMissing {}
338
+ require current_revision: session.revision == expected_revision else SessionUpdateStale {}
339
+ set session.expires_at = expires_at checked_by current_revision
340
+ set session.ip_address = ip_address checked_by current_revision
341
+ set session.user_agent = user_agent checked_by current_revision
342
+ set session.updated_at = updated_at checked_by current_revision
343
+ set session.revision = session.revision + 1
344
+ return SessionUpdated {}
345
+ }
346
+
347
+ command UpdateAccount {
348
+ input request_id: uuid
349
+ input organization_id: uuid
350
+ input user_id: uuid
351
+ input account_id: uuid
352
+ input expected_revision: u64
353
+ input external_account_id: string<256>
354
+ input provider_id: string<64>
355
+ input access_token: optional<string<4096>>
356
+ input refresh_token: optional<string<4096>>
357
+ input access_token_expires_at: optional<timestamp>
358
+ input refresh_token_expires_at: optional<timestamp>
359
+ input scope: optional<string<2048>>
360
+ input id_token: optional<string<8192>>
361
+ input password: optional<string<1024>>
362
+ input updated_at: timestamp
363
+ idempotency_key request_id
364
+ mutate Account(organization_id, user_id, account_id) as account else AccountUpdateMissing {}
365
+ require current_revision: account.revision == expected_revision else AccountUpdateStale {}
366
+ set account.account_id = external_account_id checked_by current_revision
367
+ set account.provider_id = provider_id checked_by current_revision
368
+ set account.access_token = access_token checked_by current_revision
369
+ set account.refresh_token = refresh_token checked_by current_revision
370
+ set account.access_token_expires_at = access_token_expires_at checked_by current_revision
371
+ set account.refresh_token_expires_at = refresh_token_expires_at checked_by current_revision
372
+ set account.scope = scope checked_by current_revision
373
+ set account.id_token = id_token checked_by current_revision
374
+ set account.password = password checked_by current_revision
375
+ set account.updated_at = updated_at checked_by current_revision
376
+ set account.revision = account.revision + 1
377
+ return AccountUpdated {}
378
+ }
379
+
380
+ command UpdateVerification {
381
+ input request_id: uuid
382
+ input organization_id: uuid
383
+ input verification_id: uuid
384
+ input expected_revision: u64
385
+ input value: string<4096>
386
+ input expires_at: timestamp
387
+ input updated_at: timestamp
388
+ idempotency_key request_id
389
+ mutate Verification(organization_id, verification_id) as verification else VerificationUpdateMissing {}
390
+ require current_revision: verification.revision == expected_revision else VerificationUpdateStale {}
391
+ set verification.value = value
392
+ set verification.expires_at = expires_at
393
+ set verification.updated_at = updated_at
394
+ set verification.revision = verification.revision + 1
395
+ return VerificationUpdated {}
396
+ }
397
+
398
+ bulk command DeleteSession {
399
+ input request_id: uuid
400
+ input organization_id: uuid
401
+ input user_id: uuid
402
+ input session_ids: list<uuid, 1..32>
403
+ idempotency_key request_id
404
+ for session_id in session_ids {
405
+ delete Session(organization_id, user_id, session_id) as session else SessionMissing {}
406
+ }
407
+ return SessionDeleted {}
408
+ }
409
+
410
+ bulk command DeleteAccount {
411
+ input request_id: uuid
412
+ input organization_id: uuid
413
+ input user_id: uuid
414
+ input account_ids: list<uuid, 1..32>
415
+ idempotency_key request_id
416
+ for account_id in account_ids {
417
+ delete Account(organization_id, user_id, account_id) as account else AccountMissing {}
418
+ }
419
+ return AccountDeleted {}
420
+ }
421
+
422
+ bulk command DeleteVerification {
423
+ input request_id: uuid
424
+ input organization_id: uuid
425
+ input verification_ids: list<uuid, 1..32>
426
+ idempotency_key request_id
427
+ for verification_id in verification_ids {
428
+ delete Verification(organization_id, verification_id) as verification else VerificationMissing {}
429
+ }
430
+ return VerificationDeleted {}
431
+ }
432
+
433
+ bulk command DeleteUser {
434
+ input request_id: uuid
435
+ input organization_id: uuid
436
+ input user_ids: list<uuid, 1..1>
437
+ idempotency_key request_id
438
+ for user_id in user_ids {
439
+ delete User(organization_id, user_id) as user else DeleteUserMissing {}
440
+ cascade DeleteUserCascadeLimitExceeded {}
441
+ }
442
+ return UserDeleted {}
443
+ }
444
+
445
+ bulk command ConsumeVerificationSet {
446
+ input request_id: uuid
447
+ input organization_id: uuid
448
+ input verification_ids: list<uuid, 1..32>
449
+ idempotency_key request_id
450
+ for verification_id in verification_ids {
451
+ delete Verification(organization_id, verification_id) as verification else VerificationConsumeMissing {}
452
+ }
453
+ return VerificationSetConsumed {}
454
+ }
455
+
456
+ command ConsumeVerification {
457
+ input request_id: uuid
458
+ input organization_id: uuid
459
+ input verification_id: uuid
460
+ idempotency_key request_id
461
+ delete Verification(organization_id, verification_id) as verification else VerificationConsumeMissing {}
462
+ return VerificationConsumed {
463
+ verification_id: verification.verification_id,
464
+ identifier: verification.identifier,
465
+ value: verification.value reveals verification.value,
466
+ expires_at: verification.expires_at,
467
+ created_at: verification.created_at,
468
+ updated_at: verification.updated_at,
469
+ revision: verification.revision
470
+ }
471
+ }
472
+
473
+ bulk command UpdateAccountPasswords {
474
+ input request_id: uuid
475
+ input organization_id: uuid
476
+ input user_id: uuid
477
+ input updates: list<AccountPasswordUpdate, 1..8>
478
+ idempotency_key request_id
479
+ for update in updates {
480
+ mutate Account(organization_id, user_id, update.account_id) as account else PasswordAccountMissing {}
481
+ require provider_matches: account.provider_id == update.provider_id else PasswordProviderMismatch {}
482
+ require current_revision: account.revision == update.expected_revision else PasswordAccountStale {}
483
+ set account.password = update.password checked_by current_revision
484
+ set account.updated_at = update.updated_at checked_by current_revision
485
+ set account.revision = account.revision + 1
486
+ }
487
+ return AccountPasswordsUpdated {}
488
+ }
489
+
490
+ command ConsumeVerificationSnapshot {
491
+ input request_id: uuid
492
+ input organization_id: uuid
493
+ input verification_id: uuid
494
+ input expected_revision: u64
495
+ idempotency_key request_id
496
+ delete Verification(organization_id, verification_id) as verification else VerificationConsumeMissing {}
497
+ require snapshot: verification.revision == expected_revision else VerificationConsumeStale {}
498
+ return VerificationConsumed {}
499
+ }
500
+
501
+ bulk command ResetCredentialPassword {
502
+ input request_id: uuid
503
+ input organization_id: uuid
504
+ input verification_ids: list<uuid, 1..1>
505
+ input verification_revision: u64
506
+ input user_id: uuid
507
+ input external_account_id: string<256>
508
+ input account_id: uuid
509
+ input account_revision: u64
510
+ input password: string<1024>
511
+ input updated_at: timestamp
512
+ idempotency_key request_id
513
+ mutate Account(organization_id, user_id, account_id) as account else PasswordAccountMissing {}
514
+ for verification_id in verification_ids {
515
+ delete Verification(organization_id, verification_id) as verification else VerificationConsumeMissing {}
516
+ require verification_snapshot: verification.revision == verification_revision else VerificationConsumeStale {}
517
+ }
518
+ require credential_provider: account.provider_id == "credential" else PasswordProviderMismatch {}
519
+ require credential_identity: account.account_id == external_account_id else PasswordProviderMismatch {}
520
+ require account_snapshot: account.revision == account_revision else PasswordAccountStale {}
521
+ set account.password = password checked_by account_snapshot
522
+ set account.updated_at = updated_at checked_by account_snapshot
523
+ set account.revision = account.revision + 1
524
+ return CredentialPasswordReset {}
525
+ }
526
+
527
+ command UpdateCredentialPassword {
528
+ input request_id: uuid
529
+ input organization_id: uuid
530
+ input user_id: uuid
531
+ input account_id: uuid
532
+ input external_account_id: string<256>
533
+ input expected_revision: u64
534
+ input password: string<1024>
535
+ input updated_at: timestamp
536
+ idempotency_key request_id
537
+ mutate Account(organization_id, user_id, account_id) as account else PasswordAccountMissing {}
538
+ require credential_provider: account.provider_id == "credential" else PasswordProviderMismatch {}
539
+ require credential_identity: account.account_id == external_account_id else PasswordProviderMismatch {}
540
+ require account_snapshot: account.revision == expected_revision else PasswordAccountStale {}
541
+ set account.password = password checked_by account_snapshot
542
+ set account.updated_at = updated_at checked_by account_snapshot
543
+ set account.revision = account.revision + 1
544
+ return CredentialPasswordUpdated {}
545
+ }
546
+
547
+ }
@@ -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
+ }
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
+ }
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
+ }
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
+ }
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
+ }
21
+ total: total { value }
22
+ }
23
+ outcomes Found
24
+ }
@@ -0,0 +1,24 @@
1
+ query AdminUsersEndsWithAsc(
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 ends_with $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
+ }
21
+ total: total { value }
22
+ }
23
+ outcomes Found
24
+ }