@reventlessdev/reventless-registration 1.0.0-alpha.4 → 1.0.0-alpha.40
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/README.md +10 -0
- package/i18n/en.json +8 -0
- package/package.json +7 -6
- package/src/Registration/ContactAddressId.res +27 -3
- package/src/Registration/ContactAddressId.res.mjs +26 -2
- package/src/Registration/InboundTranslation/CompleteRegistration.res +2 -2
- package/src/Registration/InboundTranslation/CompleteRegistration.res.mjs +3 -3
- package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res +9 -6
- package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res.mjs +16 -9
- package/src/Registration/InboundTranslation/SignUp.res +19 -8
- package/src/Registration/InboundTranslation/SignUp.res.mjs +15 -6
- package/src/Registration/InboundTranslation/SignUp_Translation.res +51 -15
- package/src/Registration/InboundTranslation/SignUp_Translation.res.mjs +50 -8
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res +9 -3
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res.mjs +7 -3
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res +10 -7
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res.mjs +17 -8
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res +39 -7
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res.mjs +27 -11
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res +115 -44
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res.mjs +203 -61
- package/src/Registration/StateChange/RegistrationPolicy.res +3 -0
- package/src/Registration/StateChange/RegistrationPolicy.res.mjs +3 -0
- package/src/Registration/StateChange/RegistrationPolicy_Decision.res +6 -5
- package/src/Registration/StateChange/RegistrationPolicy_Decision.res.mjs +22 -15
- package/src/Registration/StateChange/Registrations.res +79 -27
- package/src/Registration/StateChange/Registrations.res.mjs +85 -39
- package/src/Registration/StateChange/Registrations_Decision.res +96 -36
- package/src/Registration/StateChange/Registrations_Decision.res.mjs +119 -52
- package/src/Registration/StateViewStream/RegistrationWindows.res.mjs +1 -1
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as Sury from "sury";
|
|
4
|
+
import * as Pii$Reventless from "@reventlessdev/reventless-spec/src/components/Pii.res.mjs";
|
|
4
5
|
import * as Role$Reventless from "@reventlessdev/reventless-spec/src/types/Role.res.mjs";
|
|
6
|
+
import * as Email$Reventless from "@reventlessdev/reventless-spec/src/semantic/Email.res.mjs";
|
|
5
7
|
import * as DcbTag$Reventless from "@reventlessdev/reventless-spec/src/components/DcbTag.res.mjs";
|
|
6
8
|
import * as Api$ReventlessInfra from "@reventlessdev/reventless-infra/src/components/Api.res.mjs";
|
|
7
9
|
import * as DateTime$Reventless from "@reventlessdev/reventless-spec/src/semantic/DateTime.res.mjs";
|
|
10
|
+
import * as Admission$Reventless from "@reventlessdev/reventless-spec/src/types/Admission.res.mjs";
|
|
8
11
|
import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
|
|
9
12
|
|
|
10
13
|
let consumedEventSchema = Sury.union([
|
|
@@ -19,99 +22,126 @@ let consumedEventSchema = Sury.union([
|
|
|
19
22
|
})),
|
|
20
23
|
Sury.$schema(s => ({
|
|
21
24
|
TAG: "RegistrationRequested",
|
|
22
|
-
|
|
25
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
26
|
+
email: s.m(Pii$Reventless.marked("emailId", undefined, Email$Reventless.schema)),
|
|
23
27
|
roles: s.m(Sury.array(Sury.string)),
|
|
24
|
-
requestedAt: s.m(DateTime$Reventless.schema)
|
|
28
|
+
requestedAt: s.m(DateTime$Reventless.schema),
|
|
29
|
+
language: s.m(Sury.$option(Sury.string))
|
|
25
30
|
})),
|
|
26
31
|
Sury.$schema(s => ({
|
|
27
32
|
TAG: "RegistrationExpired",
|
|
28
|
-
|
|
33
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema))
|
|
29
34
|
})),
|
|
30
35
|
Sury.$schema(s => ({
|
|
31
36
|
TAG: "RegistrationInvited",
|
|
32
|
-
|
|
37
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
38
|
+
email: s.m(Pii$Reventless.marked("emailId", undefined, Email$Reventless.schema)),
|
|
33
39
|
roles: s.m(Sury.array(Sury.string)),
|
|
34
40
|
invitedBy: s.m(Sury.string),
|
|
35
|
-
invitedAt: s.m(DateTime$Reventless.schema)
|
|
41
|
+
invitedAt: s.m(DateTime$Reventless.schema),
|
|
42
|
+
language: s.m(Sury.$option(Sury.string))
|
|
36
43
|
})),
|
|
37
44
|
Sury.$schema(s => ({
|
|
38
45
|
TAG: "RegistrationChallengeReissued",
|
|
39
|
-
|
|
46
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
47
|
+
email: s.m(Pii$Reventless.marked("emailId", undefined, Email$Reventless.schema)),
|
|
40
48
|
reissuedAt: s.m(DateTime$Reventless.schema),
|
|
41
|
-
invitedBy: s.m(Sury.$option(Sury.string))
|
|
49
|
+
invitedBy: s.m(Sury.$option(Sury.string)),
|
|
50
|
+
language: s.m(Sury.$option(Sury.string))
|
|
42
51
|
})),
|
|
43
52
|
Sury.$schema(s => ({
|
|
44
53
|
TAG: "RegistrationWithdrawn",
|
|
45
|
-
|
|
54
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
46
55
|
withdrawnAt: s.m(DateTime$Reventless.schema)
|
|
47
56
|
})),
|
|
48
57
|
Sury.$schema(s => ({
|
|
49
58
|
TAG: "RegistrationAttemptedOnTakenAddress",
|
|
50
|
-
|
|
59
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
60
|
+
email: s.m(Pii$Reventless.marked("emailId", undefined, Email$Reventless.schema)),
|
|
51
61
|
attemptedAt: s.m(DateTime$Reventless.schema)
|
|
52
62
|
})),
|
|
53
63
|
Sury.$schema(s => ({
|
|
54
64
|
TAG: "RegistrationChallengeIssued",
|
|
55
|
-
|
|
65
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
56
66
|
proofHash: s.m(Sury.string),
|
|
57
|
-
issuedAt: s.m(DateTime$Reventless.schema)
|
|
67
|
+
issuedAt: s.m(DateTime$Reventless.schema),
|
|
68
|
+
language: s.m(Sury.$option(Sury.string)),
|
|
69
|
+
messageKey: s.m(Sury.$option(Sury.string))
|
|
58
70
|
})),
|
|
59
71
|
Sury.$schema(s => ({
|
|
60
72
|
TAG: "RegistrationProofAccepted",
|
|
61
|
-
|
|
73
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
74
|
+
email: s.m(Pii$Reventless.marked("emailId", undefined, Email$Reventless.schema)),
|
|
62
75
|
roles: s.m(Sury.array(Sury.string)),
|
|
63
76
|
proofHash: s.m(Sury.string)
|
|
64
77
|
})),
|
|
65
78
|
Sury.$schema(s => ({
|
|
66
79
|
TAG: "RegistrationProofRefused",
|
|
67
|
-
|
|
80
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
68
81
|
reason: s.m(Sury.string)
|
|
69
82
|
})),
|
|
70
83
|
Sury.$schema(s => ({
|
|
71
84
|
TAG: "RegistrationCompleted",
|
|
72
|
-
|
|
85
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema))
|
|
86
|
+
})),
|
|
87
|
+
Sury.$schema(s => ({
|
|
88
|
+
TAG: "RegistrationReleased",
|
|
89
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
90
|
+
releasedAt: s.m(DateTime$Reventless.schema)
|
|
73
91
|
}))
|
|
74
92
|
]);
|
|
75
93
|
|
|
76
94
|
let commandSchema = Sury.union([
|
|
77
95
|
Sury.$schema(s => ({
|
|
78
96
|
TAG: "Register",
|
|
79
|
-
|
|
97
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
98
|
+
email: s.m(Pii$Reventless.mark("emailId", undefined, Email$Reventless.schema)),
|
|
80
99
|
role: s.m(DcbTag$Reventless.mark(Role$Reventless.nameSchema)),
|
|
81
|
-
requestedAt: s.m(DateTime$Reventless.schema)
|
|
100
|
+
requestedAt: s.m(DateTime$Reventless.schema),
|
|
101
|
+
language: s.m(Sury.$option(Sury.string)),
|
|
102
|
+
initially: s.m(Sury.$option(Admission$Reventless.initiallySchema))
|
|
82
103
|
})),
|
|
83
104
|
Sury.$schema(s => ({
|
|
84
105
|
TAG: "IssueRegistrationChallenge",
|
|
85
|
-
|
|
106
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
86
107
|
proofHash: s.m(Sury.string),
|
|
87
|
-
issuedAt: s.m(DateTime$Reventless.schema)
|
|
108
|
+
issuedAt: s.m(DateTime$Reventless.schema),
|
|
109
|
+
language: s.m(Sury.$option(Sury.string)),
|
|
110
|
+
messageKey: s.m(Sury.$option(Sury.string))
|
|
88
111
|
})),
|
|
89
112
|
Sury.$schema(s => ({
|
|
90
113
|
TAG: "SubmitRegistrationProof",
|
|
91
|
-
|
|
114
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
92
115
|
proofHash: s.m(Sury.string),
|
|
93
116
|
presentedAt: s.m(DateTime$Reventless.schema)
|
|
94
117
|
})),
|
|
95
118
|
Sury.$schema(s => ({
|
|
96
119
|
TAG: "RecordRegistrationCompleted",
|
|
97
|
-
|
|
120
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema))
|
|
98
121
|
})),
|
|
99
122
|
Sury.$schema(s => ({
|
|
100
123
|
TAG: "Invite",
|
|
101
|
-
|
|
124
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
125
|
+
email: s.m(Pii$Reventless.mark("emailId", undefined, Email$Reventless.schema)),
|
|
102
126
|
roles: s.m(Sury.array(Role$Reventless.nameSchema)),
|
|
103
127
|
invitedBy: s.m(Sury.string),
|
|
104
|
-
requestedAt: s.m(DateTime$Reventless.schema)
|
|
128
|
+
requestedAt: s.m(DateTime$Reventless.schema),
|
|
129
|
+
language: s.m(Sury.$option(Sury.string))
|
|
105
130
|
})),
|
|
106
131
|
Sury.$schema(s => ({
|
|
107
132
|
TAG: "ReissueRegistrationChallenge",
|
|
108
|
-
|
|
133
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
109
134
|
requestedAt: s.m(DateTime$Reventless.schema)
|
|
110
135
|
})),
|
|
111
136
|
Sury.$schema(s => ({
|
|
112
137
|
TAG: "WithdrawRegistration",
|
|
113
|
-
|
|
138
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
114
139
|
withdrawnAt: s.m(DateTime$Reventless.schema)
|
|
140
|
+
})),
|
|
141
|
+
Sury.$schema(s => ({
|
|
142
|
+
TAG: "ReleaseRegistration",
|
|
143
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
144
|
+
releasedAt: s.m(DateTime$Reventless.schema)
|
|
115
145
|
}))
|
|
116
146
|
]);
|
|
117
147
|
|
|
@@ -126,57 +156,72 @@ let errorSchema = Sury.union([
|
|
|
126
156
|
let eventSchema = Sury.union([
|
|
127
157
|
Sury.$schema(s => ({
|
|
128
158
|
TAG: "RegistrationRequested",
|
|
129
|
-
|
|
159
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
160
|
+
email: s.m(Pii$Reventless.marked("emailId", undefined, Email$Reventless.schema)),
|
|
130
161
|
roles: s.m(Sury.array(Sury.string)),
|
|
131
|
-
requestedAt: s.m(DateTime$Reventless.schema)
|
|
162
|
+
requestedAt: s.m(DateTime$Reventless.schema),
|
|
163
|
+
language: s.m(Sury.$option(Sury.string))
|
|
132
164
|
})),
|
|
133
165
|
Sury.$schema(s => ({
|
|
134
166
|
TAG: "RegistrationExpired",
|
|
135
|
-
|
|
167
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema))
|
|
136
168
|
})),
|
|
137
169
|
Sury.$schema(s => ({
|
|
138
170
|
TAG: "RegistrationInvited",
|
|
139
|
-
|
|
171
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
172
|
+
email: s.m(Pii$Reventless.marked("emailId", undefined, Email$Reventless.schema)),
|
|
140
173
|
roles: s.m(Sury.array(Sury.string)),
|
|
141
174
|
invitedBy: s.m(Sury.string),
|
|
142
|
-
invitedAt: s.m(DateTime$Reventless.schema)
|
|
175
|
+
invitedAt: s.m(DateTime$Reventless.schema),
|
|
176
|
+
language: s.m(Sury.$option(Sury.string))
|
|
143
177
|
})),
|
|
144
178
|
Sury.$schema(s => ({
|
|
145
179
|
TAG: "RegistrationChallengeReissued",
|
|
146
|
-
|
|
180
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
181
|
+
email: s.m(Pii$Reventless.marked("emailId", undefined, Email$Reventless.schema)),
|
|
147
182
|
reissuedAt: s.m(DateTime$Reventless.schema),
|
|
148
|
-
invitedBy: s.m(Sury.$option(Sury.string))
|
|
183
|
+
invitedBy: s.m(Sury.$option(Sury.string)),
|
|
184
|
+
language: s.m(Sury.$option(Sury.string))
|
|
149
185
|
})),
|
|
150
186
|
Sury.$schema(s => ({
|
|
151
187
|
TAG: "RegistrationWithdrawn",
|
|
152
|
-
|
|
188
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
153
189
|
withdrawnAt: s.m(DateTime$Reventless.schema)
|
|
154
190
|
})),
|
|
155
191
|
Sury.$schema(s => ({
|
|
156
192
|
TAG: "RegistrationAttemptedOnTakenAddress",
|
|
157
|
-
|
|
193
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
194
|
+
email: s.m(Pii$Reventless.marked("emailId", undefined, Email$Reventless.schema)),
|
|
158
195
|
attemptedAt: s.m(DateTime$Reventless.schema)
|
|
159
196
|
})),
|
|
160
197
|
Sury.$schema(s => ({
|
|
161
198
|
TAG: "RegistrationChallengeIssued",
|
|
162
|
-
|
|
199
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
163
200
|
proofHash: s.m(Sury.string),
|
|
164
|
-
issuedAt: s.m(DateTime$Reventless.schema)
|
|
201
|
+
issuedAt: s.m(DateTime$Reventless.schema),
|
|
202
|
+
language: s.m(Sury.$option(Sury.string)),
|
|
203
|
+
messageKey: s.m(Sury.$option(Sury.string))
|
|
165
204
|
})),
|
|
166
205
|
Sury.$schema(s => ({
|
|
167
206
|
TAG: "RegistrationProofAccepted",
|
|
168
|
-
|
|
207
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
208
|
+
email: s.m(Pii$Reventless.marked("emailId", undefined, Email$Reventless.schema)),
|
|
169
209
|
roles: s.m(Sury.array(Sury.string)),
|
|
170
210
|
proofHash: s.m(Sury.string)
|
|
171
211
|
})),
|
|
172
212
|
Sury.$schema(s => ({
|
|
173
213
|
TAG: "RegistrationProofRefused",
|
|
174
|
-
|
|
214
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
175
215
|
reason: s.m(Sury.string)
|
|
176
216
|
})),
|
|
177
217
|
Sury.$schema(s => ({
|
|
178
218
|
TAG: "RegistrationCompleted",
|
|
179
|
-
|
|
219
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema))
|
|
220
|
+
})),
|
|
221
|
+
Sury.$schema(s => ({
|
|
222
|
+
TAG: "RegistrationReleased",
|
|
223
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
224
|
+
releasedAt: s.m(DateTime$Reventless.schema)
|
|
180
225
|
}))
|
|
181
226
|
]);
|
|
182
227
|
|
|
@@ -187,7 +232,8 @@ let commandSchema$1 = Api$ReventlessInfra.markNoApiVariants(commandSchema, [
|
|
|
187
232
|
"RecordRegistrationCompleted",
|
|
188
233
|
"Invite",
|
|
189
234
|
"ReissueRegistrationChallenge",
|
|
190
|
-
"WithdrawRegistration"
|
|
235
|
+
"WithdrawRegistration",
|
|
236
|
+
"ReleaseRegistration"
|
|
191
237
|
]);
|
|
192
238
|
|
|
193
239
|
function authorizationOf(param) {
|
|
@@ -10,13 +10,16 @@ module V = ContactVerification
|
|
|
10
10
|
module Guards = ContactVerification_Guards
|
|
11
11
|
|
|
12
12
|
type policyState =
|
|
13
|
-
/** Nothing recorded about the role:
|
|
14
|
-
self-service, closed otherwise. */
|
|
13
|
+
/** Nothing recorded about the role: the deployment's starting state if the app
|
|
14
|
+
declares it self-service, closed otherwise. */
|
|
15
15
|
| Unset
|
|
16
16
|
| Closed
|
|
17
17
|
| Open(option<Reventless.DateTime.t>)
|
|
18
18
|
|
|
19
19
|
type pending = {
|
|
20
|
+
/** The address the claim was made for: where its code goes, and what an
|
|
21
|
+
accepted proof makes an account for. */
|
|
22
|
+
email: Reventless.Pii.t<Reventless.Email.t>,
|
|
20
23
|
/** When the claim was made, or its code last reissued: what a claim with no
|
|
21
24
|
challenge out lapses from. */
|
|
22
25
|
requestedAt: Reventless.DateTime.t,
|
|
@@ -24,6 +27,9 @@ type pending = {
|
|
|
24
27
|
roles: array<string>,
|
|
25
28
|
/** Who invited, for a claim an inviter made. */
|
|
26
29
|
invitedBy?: string,
|
|
30
|
+
/** The language the claim was made in: what its codes are written in for a person with no
|
|
31
|
+
account to say. */
|
|
32
|
+
language?: string,
|
|
27
33
|
challenge: option<Guards.challenge>,
|
|
28
34
|
proofHash: option<string>,
|
|
29
35
|
}
|
|
@@ -50,6 +56,12 @@ let initialState = {admission: Unset, stage: Unclaimed, lastNoticeAt: None}
|
|
|
50
56
|
so the door cannot be used to flood a registered person's inbox. */
|
|
51
57
|
let noticeCooldown = 3600
|
|
52
58
|
|
|
59
|
+
/** The contact a challenge is held against. The guards only compare it, so the
|
|
60
|
+
ledger's id for the address serves, and no address is needed to decide. */
|
|
61
|
+
let contactOf = (emailId: ContactAddressId.t): ContactVerification.contact => ByEmail(
|
|
62
|
+
Reventless.Email.unsafe(emailId->ContactAddressId.toString),
|
|
63
|
+
)
|
|
64
|
+
|
|
53
65
|
let purposeOf = (p: pending) => RegistrationChallenge.purposeOf(~invitedBy=p.invitedBy)
|
|
54
66
|
|
|
55
67
|
/** The challenge rules a pending registration is held to: an invitation's code
|
|
@@ -60,27 +72,35 @@ let evolve = (state, event) =>
|
|
|
60
72
|
switch event {
|
|
61
73
|
| RegistrationOpened({?until}) => {...state, admission: Open(until)}
|
|
62
74
|
| RegistrationClosed(_) => {...state, admission: Closed}
|
|
63
|
-
| RegistrationRequested({roles, requestedAt}) => {
|
|
75
|
+
| RegistrationRequested({email, roles, requestedAt, ?language}) => {
|
|
64
76
|
...state,
|
|
65
|
-
stage: Pending({requestedAt, roles, challenge: None, proofHash: None}),
|
|
77
|
+
stage: Pending({email, requestedAt, roles, ?language, challenge: None, proofHash: None}),
|
|
66
78
|
}
|
|
67
|
-
| RegistrationInvited({roles, invitedBy, invitedAt}) => {
|
|
79
|
+
| RegistrationInvited({email, roles, invitedBy, invitedAt, ?language}) => {
|
|
68
80
|
...state,
|
|
69
|
-
stage: Pending({
|
|
81
|
+
stage: Pending({
|
|
82
|
+
email,
|
|
83
|
+
requestedAt: invitedAt,
|
|
84
|
+
roles,
|
|
85
|
+
invitedBy,
|
|
86
|
+
?language,
|
|
87
|
+
challenge: None,
|
|
88
|
+
proofHash: None,
|
|
89
|
+
}),
|
|
70
90
|
}
|
|
71
91
|
| RegistrationExpired(_) | RegistrationWithdrawn(_) => {...state, stage: Unclaimed}
|
|
72
92
|
| RegistrationAttemptedOnTakenAddress({attemptedAt}) => {
|
|
73
93
|
...state,
|
|
74
94
|
lastNoticeAt: Some(attemptedAt),
|
|
75
95
|
}
|
|
76
|
-
| RegistrationChallengeIssued({
|
|
96
|
+
| RegistrationChallengeIssued({emailId, proofHash, issuedAt}) =>
|
|
77
97
|
switch state.stage {
|
|
78
98
|
| Pending(p) => {
|
|
79
99
|
...state,
|
|
80
100
|
stage: Pending({
|
|
81
101
|
...p,
|
|
82
102
|
challenge: Some({
|
|
83
|
-
contact:
|
|
103
|
+
contact: contactOf(emailId),
|
|
84
104
|
purpose: purposeOf(p),
|
|
85
105
|
issuedAt,
|
|
86
106
|
attempts: 0,
|
|
@@ -112,19 +132,34 @@ let evolve = (state, event) =>
|
|
|
112
132
|
}
|
|
113
133
|
| RegistrationProofAccepted(_) => {...state, stage: Verified}
|
|
114
134
|
| RegistrationCompleted(_) => {...state, stage: Completed}
|
|
135
|
+
// The account was erased: the address is nobody's, and nobody was told of an
|
|
136
|
+
// attempt on it.
|
|
137
|
+
| RegistrationReleased(_) => {...state, stage: Unclaimed, lastNoticeAt: None}
|
|
115
138
|
}
|
|
116
139
|
|
|
117
|
-
/** Whether the policy admits a registration for `role` that arrived at `at
|
|
118
|
-
A role nobody has recorded anything
|
|
119
|
-
|
|
120
|
-
with no event to close it.
|
|
121
|
-
|
|
140
|
+
/** Whether the policy admits a registration for `role` that arrived at `at`,
|
|
141
|
+
on a deployment that starts `initially`. A role nobody has recorded anything
|
|
142
|
+
about reads as the starting state, if it is declared self-service; so does one
|
|
143
|
+
past an open window's end, with no event to close it. A request stamped with no
|
|
144
|
+
starting state was made when every role started open. */
|
|
145
|
+
let admits = (
|
|
146
|
+
admission,
|
|
147
|
+
~table,
|
|
148
|
+
~role,
|
|
149
|
+
~at,
|
|
150
|
+
~initially: option<Reventless.Admission.initially>,
|
|
151
|
+
) => {
|
|
152
|
+
let starting = () =>
|
|
153
|
+
table->Reventless.Admission.isSelfService(role) &&
|
|
154
|
+
initially->Option.getOr(Reventless.Admission.InitiallyOpen) ==
|
|
155
|
+
Reventless.Admission.InitiallyOpen
|
|
122
156
|
switch admission {
|
|
123
|
-
| Unset =>
|
|
157
|
+
| Unset => starting()
|
|
124
158
|
| Closed => false
|
|
125
159
|
| Open(None) => true
|
|
126
|
-
| Open(Some(until)) => Reventless.DateTime.isBefore(at, until)
|
|
160
|
+
| Open(Some(until)) => Reventless.DateTime.isBefore(at, until) || starting()
|
|
127
161
|
}
|
|
162
|
+
}
|
|
128
163
|
|
|
129
164
|
/** Whether the app declares `role` as one a person is invited to. */
|
|
130
165
|
let isByInvitation = (table, role) =>
|
|
@@ -166,8 +201,8 @@ module Make = (App: Reventless.Admission.Declaration) => {
|
|
|
166
201
|
// decision: the policy is consulted before the address, so a closed
|
|
167
202
|
// deployment sends nothing — not even the notice to an address that is
|
|
168
203
|
// already registered.
|
|
169
|
-
| Register({email, role, requestedAt}) =>
|
|
170
|
-
if !admits(state.admission, ~table=App.table, ~role, ~at=requestedAt) {
|
|
204
|
+
| Register({emailId, email, role, requestedAt, ?language, ?initially}) =>
|
|
205
|
+
if !admits(state.admission, ~table=App.table, ~role, ~at=requestedAt, ~initially) {
|
|
171
206
|
Ok([])
|
|
172
207
|
} else {
|
|
173
208
|
let roles = [(role :> string)]
|
|
@@ -177,54 +212,65 @@ module Make = (App: Reventless.Admission.Declaration) => {
|
|
|
177
212
|
switch state.lastNoticeAt {
|
|
178
213
|
| Some(last) if Guards.elapsedSeconds(~from=last, ~to_=requestedAt) < noticeCooldown =>
|
|
179
214
|
Ok([])
|
|
180
|
-
| _ =>
|
|
215
|
+
| _ =>
|
|
216
|
+
Ok([
|
|
217
|
+
RegistrationAttemptedOnTakenAddress({
|
|
218
|
+
emailId,
|
|
219
|
+
email: Value(email),
|
|
220
|
+
attemptedAt: requestedAt,
|
|
221
|
+
}),
|
|
222
|
+
])
|
|
181
223
|
}
|
|
182
224
|
| Verified => Ok([])
|
|
183
225
|
// A visitor cannot take over a claim, an inviter's included, while it holds.
|
|
184
226
|
| Pending(p) if !hasLapsed(p, ~now=requestedAt) => Ok([])
|
|
185
227
|
| Pending(_) =>
|
|
186
228
|
Ok([
|
|
187
|
-
RegistrationExpired({
|
|
188
|
-
RegistrationRequested({email, roles, requestedAt}),
|
|
229
|
+
RegistrationExpired({emailId: emailId}),
|
|
230
|
+
RegistrationRequested({emailId, email: Value(email), roles, requestedAt, ?language}),
|
|
189
231
|
])
|
|
190
|
-
| Unclaimed =>
|
|
232
|
+
| Unclaimed =>
|
|
233
|
+
Ok([RegistrationRequested({emailId, email: Value(email), roles, requestedAt, ?language})])
|
|
191
234
|
}
|
|
192
235
|
}
|
|
193
236
|
|
|
194
237
|
// The policy is not consulted: it says whether visitors may sign themselves
|
|
195
238
|
// up, and an invitation is not that. The table is, because it is the hard
|
|
196
239
|
// cap on how each role is admitted.
|
|
197
|
-
| Invite({email, roles, invitedBy, requestedAt}) =>
|
|
240
|
+
| Invite({emailId, email, roles, invitedBy, requestedAt, ?language}) =>
|
|
198
241
|
switch roles->Array.find(r => !isByInvitation(App.table, r)) {
|
|
199
242
|
| Some(role) => Error(NotByInvitation({role: (role :> string)}))
|
|
200
243
|
| None if roles == [] => Error(NoRoleToGrant)
|
|
201
244
|
| None =>
|
|
202
245
|
let invited = RegistrationInvited({
|
|
203
|
-
|
|
246
|
+
emailId,
|
|
247
|
+
email: Value(email),
|
|
204
248
|
roles: roles->Array.map(r => (r :> string)),
|
|
205
249
|
invitedBy,
|
|
206
250
|
invitedAt: requestedAt,
|
|
251
|
+
?language,
|
|
207
252
|
})
|
|
208
253
|
switch state.stage {
|
|
209
254
|
// An address that holds an account, or is about to, is not registered
|
|
210
255
|
// twice; granting it roles is not registration.
|
|
211
256
|
| Completed | Verified => Ok([])
|
|
212
257
|
| Pending(p) if !hasLapsed(p, ~now=requestedAt) => Ok([])
|
|
213
|
-
| Pending(_) => Ok([RegistrationExpired({
|
|
258
|
+
| Pending(_) => Ok([RegistrationExpired({emailId: emailId}), invited])
|
|
214
259
|
| Unclaimed => Ok([invited])
|
|
215
260
|
}
|
|
216
261
|
}
|
|
217
262
|
|
|
218
|
-
| IssueRegistrationChallenge({
|
|
263
|
+
| IssueRegistrationChallenge({emailId, proofHash, issuedAt, ?language, ?messageKey}) =>
|
|
219
264
|
switch state.stage {
|
|
220
265
|
| Pending(p) =>
|
|
221
266
|
switch Guards.onIssueRequested(
|
|
222
|
-
~contact=
|
|
267
|
+
~contact=contactOf(emailId),
|
|
223
268
|
~existing=p.challenge,
|
|
224
269
|
~now=issuedAt,
|
|
225
270
|
~policy=policyOf(p),
|
|
226
271
|
) {
|
|
227
|
-
| Issue =>
|
|
272
|
+
| Issue =>
|
|
273
|
+
Ok([RegistrationChallengeIssued({emailId, proofHash, issuedAt, ?language, ?messageKey})])
|
|
228
274
|
// A redelivered request mints nothing, and because nothing is emitted,
|
|
229
275
|
// sends nothing either.
|
|
230
276
|
| AlreadyOpen => Ok([])
|
|
@@ -236,18 +282,24 @@ module Make = (App: Reventless.Admission.Declaration) => {
|
|
|
236
282
|
// replaced by a second in flight, and the first to arrive would be the one
|
|
237
283
|
// recorded. And not twice within the resend cooldown, so a door that
|
|
238
284
|
// reaches this cannot be used to flood an inbox.
|
|
239
|
-
| ReissueRegistrationChallenge({
|
|
285
|
+
| ReissueRegistrationChallenge({emailId, requestedAt}) =>
|
|
240
286
|
switch state.stage {
|
|
241
287
|
| Pending({challenge: Some(c)} as p)
|
|
242
288
|
if Guards.elapsedSeconds(~from=c.issuedAt, ~to_=requestedAt) >=
|
|
243
289
|
policyOf(p).resendCooldown =>
|
|
244
290
|
Ok([
|
|
245
|
-
RegistrationChallengeReissued({
|
|
291
|
+
RegistrationChallengeReissued({
|
|
292
|
+
emailId,
|
|
293
|
+
email: p.email,
|
|
294
|
+
reissuedAt: requestedAt,
|
|
295
|
+
invitedBy: ?p.invitedBy,
|
|
296
|
+
language: ?p.language,
|
|
297
|
+
}),
|
|
246
298
|
])
|
|
247
299
|
| _ => Ok([])
|
|
248
300
|
}
|
|
249
301
|
|
|
250
|
-
| SubmitRegistrationProof({
|
|
302
|
+
| SubmitRegistrationProof({emailId, proofHash, presentedAt}) =>
|
|
251
303
|
switch state.stage {
|
|
252
304
|
| Pending({challenge: Some(c), proofHash: Some(held), roles} as p) =>
|
|
253
305
|
switch Guards.onProofPresented(
|
|
@@ -257,8 +309,8 @@ module Make = (App: Reventless.Admission.Declaration) => {
|
|
|
257
309
|
~now=presentedAt,
|
|
258
310
|
~policy=policyOf(p),
|
|
259
311
|
) {
|
|
260
|
-
| Settle => Ok([RegistrationProofAccepted({email, roles, proofHash})])
|
|
261
|
-
| Refuse(reason) => Ok([RegistrationProofRefused({
|
|
312
|
+
| Settle => Ok([RegistrationProofAccepted({emailId, email: p.email, roles, proofHash})])
|
|
313
|
+
| Refuse(reason) => Ok([RegistrationProofRefused({emailId, reason: refusalReason(reason)})])
|
|
262
314
|
}
|
|
263
315
|
// No challenge to answer: nothing to count it against, and nothing to say.
|
|
264
316
|
| _ => Ok([])
|
|
@@ -266,15 +318,23 @@ module Make = (App: Reventless.Admission.Declaration) => {
|
|
|
266
318
|
|
|
267
319
|
// Only a claim nobody has proved: once a proof settled, an account is on
|
|
268
320
|
// its way, and withdrawing the claim would not stop it.
|
|
269
|
-
| WithdrawRegistration({
|
|
321
|
+
| WithdrawRegistration({emailId, withdrawnAt}) =>
|
|
270
322
|
switch state.stage {
|
|
271
|
-
| Pending(_) => Ok([RegistrationWithdrawn({
|
|
323
|
+
| Pending(_) => Ok([RegistrationWithdrawn({emailId, withdrawnAt})])
|
|
272
324
|
| Unclaimed | Verified | Completed => Ok([])
|
|
273
325
|
}
|
|
274
326
|
|
|
275
|
-
|
|
327
|
+
// Only an account: a claim nobody proved is withdrawn, and one being turned
|
|
328
|
+
// into an account is released once the account exists and is erased.
|
|
329
|
+
| ReleaseRegistration({emailId, releasedAt}) =>
|
|
330
|
+
switch state.stage {
|
|
331
|
+
| Completed => Ok([RegistrationReleased({emailId, releasedAt})])
|
|
332
|
+
| Unclaimed | Pending(_) | Verified => Ok([])
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
| RecordRegistrationCompleted({emailId}) =>
|
|
276
336
|
switch state.stage {
|
|
277
|
-
| Verified => Ok([RegistrationCompleted({
|
|
337
|
+
| Verified => Ok([RegistrationCompleted({emailId: emailId})])
|
|
278
338
|
| _ => Ok([])
|
|
279
339
|
}
|
|
280
340
|
}
|