@reventlessdev/reventless-registration 1.0.0-alpha.2 → 1.0.0-alpha.21

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 (23) hide show
  1. package/package.json +4 -4
  2. package/src/Registration/ContactAddressId.res +27 -3
  3. package/src/Registration/ContactAddressId.res.mjs +26 -2
  4. package/src/Registration/InboundTranslation/CompleteRegistration.res +2 -2
  5. package/src/Registration/InboundTranslation/CompleteRegistration.res.mjs +2 -2
  6. package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res +9 -6
  7. package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res.mjs +16 -9
  8. package/src/Registration/InboundTranslation/SignUp.res +3 -2
  9. package/src/Registration/InboundTranslation/SignUp.res.mjs +6 -2
  10. package/src/Registration/InboundTranslation/SignUp_Translation.res +24 -13
  11. package/src/Registration/InboundTranslation/SignUp_Translation.res.mjs +13 -4
  12. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res +9 -3
  13. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res.mjs +7 -3
  14. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res +10 -7
  15. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res.mjs +17 -8
  16. package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res +27 -6
  17. package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res.mjs +13 -6
  18. package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res +19 -17
  19. package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res.mjs +73 -33
  20. package/src/Registration/StateChange/Registrations.res +58 -27
  21. package/src/Registration/StateChange/Registrations.res.mjs +58 -28
  22. package/src/Registration/StateChange/Registrations_Decision.res +67 -26
  23. package/src/Registration/StateChange/Registrations_Decision.res.mjs +91 -42
@@ -17,6 +17,9 @@ type policyState =
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,
@@ -50,6 +53,12 @@ let initialState = {admission: Unset, stage: Unclaimed, lastNoticeAt: None}
50
53
  so the door cannot be used to flood a registered person's inbox. */
51
54
  let noticeCooldown = 3600
52
55
 
56
+ /** The contact a challenge is held against. The guards only compare it, so the
57
+ ledger's id for the address serves, and no address is needed to decide. */
58
+ let contactOf = (emailId: ContactAddressId.t): ContactVerification.contact => ByEmail(
59
+ Reventless.Email.unsafe(emailId->ContactAddressId.toString),
60
+ )
61
+
53
62
  let purposeOf = (p: pending) => RegistrationChallenge.purposeOf(~invitedBy=p.invitedBy)
54
63
 
55
64
  /** The challenge rules a pending registration is held to: an invitation's code
@@ -60,27 +69,34 @@ let evolve = (state, event) =>
60
69
  switch event {
61
70
  | RegistrationOpened({?until}) => {...state, admission: Open(until)}
62
71
  | RegistrationClosed(_) => {...state, admission: Closed}
63
- | RegistrationRequested({roles, requestedAt}) => {
72
+ | RegistrationRequested({email, roles, requestedAt}) => {
64
73
  ...state,
65
- stage: Pending({requestedAt, roles, challenge: None, proofHash: None}),
74
+ stage: Pending({email, requestedAt, roles, challenge: None, proofHash: None}),
66
75
  }
67
- | RegistrationInvited({roles, invitedBy, invitedAt}) => {
76
+ | RegistrationInvited({email, roles, invitedBy, invitedAt}) => {
68
77
  ...state,
69
- stage: Pending({requestedAt: invitedAt, roles, invitedBy, challenge: None, proofHash: None}),
78
+ stage: Pending({
79
+ email,
80
+ requestedAt: invitedAt,
81
+ roles,
82
+ invitedBy,
83
+ challenge: None,
84
+ proofHash: None,
85
+ }),
70
86
  }
71
87
  | RegistrationExpired(_) | RegistrationWithdrawn(_) => {...state, stage: Unclaimed}
72
88
  | RegistrationAttemptedOnTakenAddress({attemptedAt}) => {
73
89
  ...state,
74
90
  lastNoticeAt: Some(attemptedAt),
75
91
  }
76
- | RegistrationChallengeIssued({email, proofHash, issuedAt}) =>
92
+ | RegistrationChallengeIssued({emailId, proofHash, issuedAt}) =>
77
93
  switch state.stage {
78
94
  | Pending(p) => {
79
95
  ...state,
80
96
  stage: Pending({
81
97
  ...p,
82
98
  challenge: Some({
83
- contact: ByEmail(Reventless.Email.unsafe(email->ContactAddressId.toString)),
99
+ contact: contactOf(emailId),
84
100
  purpose: purposeOf(p),
85
101
  issuedAt,
86
102
  attempts: 0,
@@ -112,6 +128,9 @@ let evolve = (state, event) =>
112
128
  }
113
129
  | RegistrationProofAccepted(_) => {...state, stage: Verified}
114
130
  | RegistrationCompleted(_) => {...state, stage: Completed}
131
+ // The account was erased: the address is nobody's, and nobody was told of an
132
+ // attempt on it.
133
+ | RegistrationReleased(_) => {...state, stage: Unclaimed, lastNoticeAt: None}
115
134
  }
116
135
 
117
136
  /** Whether the policy admits a registration for `role` that arrived at `at`.
@@ -166,7 +185,7 @@ module Make = (App: Reventless.Admission.Declaration) => {
166
185
  // decision: the policy is consulted before the address, so a closed
167
186
  // deployment sends nothing — not even the notice to an address that is
168
187
  // already registered.
169
- | Register({email, role, requestedAt}) =>
188
+ | Register({emailId, email, role, requestedAt}) =>
170
189
  if !admits(state.admission, ~table=App.table, ~role, ~at=requestedAt) {
171
190
  Ok([])
172
191
  } else {
@@ -177,30 +196,39 @@ module Make = (App: Reventless.Admission.Declaration) => {
177
196
  switch state.lastNoticeAt {
178
197
  | Some(last) if Guards.elapsedSeconds(~from=last, ~to_=requestedAt) < noticeCooldown =>
179
198
  Ok([])
180
- | _ => Ok([RegistrationAttemptedOnTakenAddress({email, attemptedAt: requestedAt})])
199
+ | _ =>
200
+ Ok([
201
+ RegistrationAttemptedOnTakenAddress({
202
+ emailId,
203
+ email: Value(email),
204
+ attemptedAt: requestedAt,
205
+ }),
206
+ ])
181
207
  }
182
208
  | Verified => Ok([])
183
209
  // A visitor cannot take over a claim, an inviter's included, while it holds.
184
210
  | Pending(p) if !hasLapsed(p, ~now=requestedAt) => Ok([])
185
211
  | Pending(_) =>
186
212
  Ok([
187
- RegistrationExpired({email: email}),
188
- RegistrationRequested({email, roles, requestedAt}),
213
+ RegistrationExpired({emailId: emailId}),
214
+ RegistrationRequested({emailId, email: Value(email), roles, requestedAt}),
189
215
  ])
190
- | Unclaimed => Ok([RegistrationRequested({email, roles, requestedAt})])
216
+ | Unclaimed =>
217
+ Ok([RegistrationRequested({emailId, email: Value(email), roles, requestedAt})])
191
218
  }
192
219
  }
193
220
 
194
221
  // The policy is not consulted: it says whether visitors may sign themselves
195
222
  // up, and an invitation is not that. The table is, because it is the hard
196
223
  // cap on how each role is admitted.
197
- | Invite({email, roles, invitedBy, requestedAt}) =>
224
+ | Invite({emailId, email, roles, invitedBy, requestedAt}) =>
198
225
  switch roles->Array.find(r => !isByInvitation(App.table, r)) {
199
226
  | Some(role) => Error(NotByInvitation({role: (role :> string)}))
200
227
  | None if roles == [] => Error(NoRoleToGrant)
201
228
  | None =>
202
229
  let invited = RegistrationInvited({
203
- email,
230
+ emailId,
231
+ email: Value(email),
204
232
  roles: roles->Array.map(r => (r :> string)),
205
233
  invitedBy,
206
234
  invitedAt: requestedAt,
@@ -210,21 +238,21 @@ module Make = (App: Reventless.Admission.Declaration) => {
210
238
  // twice; granting it roles is not registration.
211
239
  | Completed | Verified => Ok([])
212
240
  | Pending(p) if !hasLapsed(p, ~now=requestedAt) => Ok([])
213
- | Pending(_) => Ok([RegistrationExpired({email: email}), invited])
241
+ | Pending(_) => Ok([RegistrationExpired({emailId: emailId}), invited])
214
242
  | Unclaimed => Ok([invited])
215
243
  }
216
244
  }
217
245
 
218
- | IssueRegistrationChallenge({email, proofHash, issuedAt}) =>
246
+ | IssueRegistrationChallenge({emailId, proofHash, issuedAt}) =>
219
247
  switch state.stage {
220
248
  | Pending(p) =>
221
249
  switch Guards.onIssueRequested(
222
- ~contact=ByEmail(Reventless.Email.unsafe(email->ContactAddressId.toString)),
250
+ ~contact=contactOf(emailId),
223
251
  ~existing=p.challenge,
224
252
  ~now=issuedAt,
225
253
  ~policy=policyOf(p),
226
254
  ) {
227
- | Issue => Ok([RegistrationChallengeIssued({email, proofHash, issuedAt})])
255
+ | Issue => Ok([RegistrationChallengeIssued({emailId, proofHash, issuedAt})])
228
256
  // A redelivered request mints nothing, and because nothing is emitted,
229
257
  // sends nothing either.
230
258
  | AlreadyOpen => Ok([])
@@ -236,18 +264,23 @@ module Make = (App: Reventless.Admission.Declaration) => {
236
264
  // replaced by a second in flight, and the first to arrive would be the one
237
265
  // recorded. And not twice within the resend cooldown, so a door that
238
266
  // reaches this cannot be used to flood an inbox.
239
- | ReissueRegistrationChallenge({email, requestedAt}) =>
267
+ | ReissueRegistrationChallenge({emailId, requestedAt}) =>
240
268
  switch state.stage {
241
269
  | Pending({challenge: Some(c)} as p)
242
270
  if Guards.elapsedSeconds(~from=c.issuedAt, ~to_=requestedAt) >=
243
271
  policyOf(p).resendCooldown =>
244
272
  Ok([
245
- RegistrationChallengeReissued({email, reissuedAt: requestedAt, invitedBy: ?p.invitedBy}),
273
+ RegistrationChallengeReissued({
274
+ emailId,
275
+ email: p.email,
276
+ reissuedAt: requestedAt,
277
+ invitedBy: ?p.invitedBy,
278
+ }),
246
279
  ])
247
280
  | _ => Ok([])
248
281
  }
249
282
 
250
- | SubmitRegistrationProof({email, proofHash, presentedAt}) =>
283
+ | SubmitRegistrationProof({emailId, proofHash, presentedAt}) =>
251
284
  switch state.stage {
252
285
  | Pending({challenge: Some(c), proofHash: Some(held), roles} as p) =>
253
286
  switch Guards.onProofPresented(
@@ -257,8 +290,8 @@ module Make = (App: Reventless.Admission.Declaration) => {
257
290
  ~now=presentedAt,
258
291
  ~policy=policyOf(p),
259
292
  ) {
260
- | Settle => Ok([RegistrationProofAccepted({email, roles, proofHash})])
261
- | Refuse(reason) => Ok([RegistrationProofRefused({email, reason: refusalReason(reason)})])
293
+ | Settle => Ok([RegistrationProofAccepted({emailId, email: p.email, roles, proofHash})])
294
+ | Refuse(reason) => Ok([RegistrationProofRefused({emailId, reason: refusalReason(reason)})])
262
295
  }
263
296
  // No challenge to answer: nothing to count it against, and nothing to say.
264
297
  | _ => Ok([])
@@ -266,15 +299,23 @@ module Make = (App: Reventless.Admission.Declaration) => {
266
299
 
267
300
  // Only a claim nobody has proved: once a proof settled, an account is on
268
301
  // its way, and withdrawing the claim would not stop it.
269
- | WithdrawRegistration({email, withdrawnAt}) =>
302
+ | WithdrawRegistration({emailId, withdrawnAt}) =>
270
303
  switch state.stage {
271
- | Pending(_) => Ok([RegistrationWithdrawn({email, withdrawnAt})])
304
+ | Pending(_) => Ok([RegistrationWithdrawn({emailId, withdrawnAt})])
272
305
  | Unclaimed | Verified | Completed => Ok([])
273
306
  }
274
307
 
275
- | RecordRegistrationCompleted({email}) =>
308
+ // Only an account: a claim nobody proved is withdrawn, and one being turned
309
+ // into an account is released once the account exists and is erased.
310
+ | ReleaseRegistration({emailId, releasedAt}) =>
311
+ switch state.stage {
312
+ | Completed => Ok([RegistrationReleased({emailId, releasedAt})])
313
+ | Unclaimed | Pending(_) | Verified => Ok([])
314
+ }
315
+
316
+ | RecordRegistrationCompleted({emailId}) =>
276
317
  switch state.stage {
277
- | Verified => Ok([RegistrationCompleted({email: email})])
318
+ | Verified => Ok([RegistrationCompleted({emailId: emailId})])
278
319
  | _ => Ok([])
279
320
  }
280
321
  }
@@ -14,6 +14,13 @@ let initialState = {
14
14
  lastNoticeAt: undefined
15
15
  };
16
16
 
17
+ function contactOf(emailId) {
18
+ return {
19
+ TAG: "ByEmail",
20
+ _0: ContactAddressId$ReventlessRegistration.toString(emailId)
21
+ };
22
+ }
23
+
17
24
  function purposeOf(p) {
18
25
  return RegistrationChallenge$ReventlessRegistration.purposeOf(p.invitedBy);
19
26
  }
@@ -45,6 +52,7 @@ function evolve(state, event) {
45
52
  stage: {
46
53
  TAG: "Pending",
47
54
  _0: {
55
+ email: event.email,
48
56
  requestedAt: event.requestedAt,
49
57
  roles: event.roles,
50
58
  challenge: undefined,
@@ -59,6 +67,7 @@ function evolve(state, event) {
59
67
  stage: {
60
68
  TAG: "Pending",
61
69
  _0: {
70
+ email: event.email,
62
71
  requestedAt: event.invitedAt,
63
72
  roles: event.roles,
64
73
  invitedBy: event.invitedBy,
@@ -109,7 +118,7 @@ function evolve(state, event) {
109
118
  _0: (newrecord$1.proofHash = event.proofHash, newrecord$1.challenge = {
110
119
  contact: {
111
120
  TAG: "ByEmail",
112
- _0: ContactAddressId$ReventlessRegistration.toString(event.email)
121
+ _0: ContactAddressId$ReventlessRegistration.toString(event.emailId)
113
122
  },
114
123
  purpose: RegistrationChallenge$ReventlessRegistration.purposeOf(p$2.invitedBy),
115
124
  issuedAt: event.issuedAt,
@@ -156,6 +165,12 @@ function evolve(state, event) {
156
165
  stage: "Completed",
157
166
  lastNoticeAt: state.lastNoticeAt
158
167
  };
168
+ case "RegistrationReleased" :
169
+ return {
170
+ admission: state.admission,
171
+ stage: "Unclaimed",
172
+ lastNoticeAt: undefined
173
+ };
159
174
  }
160
175
  }
161
176
 
@@ -211,6 +226,7 @@ function Make(App) {
211
226
  let requestedAt = command.requestedAt;
212
227
  let role = command.role;
213
228
  let email = command.email;
229
+ let emailId = command.emailId;
214
230
  if (!admits(state.admission, App.table, role, requestedAt)) {
215
231
  return {
216
232
  TAG: "Ok",
@@ -226,11 +242,15 @@ function Make(App) {
226
242
  _0: [
227
243
  {
228
244
  TAG: "RegistrationExpired",
229
- email: email
245
+ emailId: emailId
230
246
  },
231
247
  {
232
248
  TAG: "RegistrationRequested",
233
- email: email,
249
+ emailId: emailId,
250
+ email: {
251
+ TAG: "Value",
252
+ _0: email
253
+ },
234
254
  roles: roles,
235
255
  requestedAt: requestedAt
236
256
  }
@@ -249,7 +269,11 @@ function Make(App) {
249
269
  TAG: "Ok",
250
270
  _0: [{
251
271
  TAG: "RegistrationRequested",
252
- email: email,
272
+ emailId: emailId,
273
+ email: {
274
+ TAG: "Value",
275
+ _0: email
276
+ },
253
277
  roles: roles,
254
278
  requestedAt: requestedAt
255
279
  }]
@@ -261,36 +285,29 @@ function Make(App) {
261
285
  };
262
286
  case "Completed" :
263
287
  let last = state.lastNoticeAt;
264
- if (last !== undefined) {
265
- if (ContactVerification_Guards$ReventlessRegistration.elapsedSeconds(last, requestedAt) < 3600) {
266
- return {
267
- TAG: "Ok",
268
- _0: []
269
- };
270
- } else {
271
- return {
272
- TAG: "Ok",
273
- _0: [{
274
- TAG: "RegistrationAttemptedOnTakenAddress",
275
- email: email,
276
- attemptedAt: requestedAt
277
- }]
278
- };
279
- }
280
- } else {
288
+ if (last !== undefined && ContactVerification_Guards$ReventlessRegistration.elapsedSeconds(last, requestedAt) < 3600) {
281
289
  return {
282
290
  TAG: "Ok",
283
- _0: [{
284
- TAG: "RegistrationAttemptedOnTakenAddress",
285
- email: email,
286
- attemptedAt: requestedAt
287
- }]
291
+ _0: []
288
292
  };
289
293
  }
294
+ return {
295
+ TAG: "Ok",
296
+ _0: [{
297
+ TAG: "RegistrationAttemptedOnTakenAddress",
298
+ emailId: emailId,
299
+ email: {
300
+ TAG: "Value",
301
+ _0: email
302
+ },
303
+ attemptedAt: requestedAt
304
+ }]
305
+ };
290
306
  }
307
+ break;
291
308
  case "IssueRegistrationChallenge" :
292
309
  let issuedAt = command.issuedAt;
293
- let email$1 = command.email;
310
+ let emailId$1 = command.emailId;
294
311
  let p$1 = state.stage;
295
312
  if (typeof p$1 !== "object") {
296
313
  return {
@@ -301,14 +318,14 @@ function Make(App) {
301
318
  let p$2 = p$1._0;
302
319
  let match = ContactVerification_Guards$ReventlessRegistration.onIssueRequested({
303
320
  TAG: "ByEmail",
304
- _0: ContactAddressId$ReventlessRegistration.toString(email$1)
321
+ _0: ContactAddressId$ReventlessRegistration.toString(emailId$1)
305
322
  }, p$2.challenge, issuedAt, RegistrationChallenge$ReventlessRegistration.policyFor(RegistrationChallenge$ReventlessRegistration.purposeOf(p$2.invitedBy)));
306
323
  if (match === "Issue") {
307
324
  return {
308
325
  TAG: "Ok",
309
326
  _0: [{
310
327
  TAG: "RegistrationChallengeIssued",
311
- email: email$1,
328
+ emailId: emailId$1,
312
329
  proofHash: command.proofHash,
313
330
  issuedAt: issuedAt
314
331
  }]
@@ -321,7 +338,7 @@ function Make(App) {
321
338
  }
322
339
  case "SubmitRegistrationProof" :
323
340
  let proofHash = command.proofHash;
324
- let email$2 = command.email;
341
+ let emailId$2 = command.emailId;
325
342
  let p$3 = state.stage;
326
343
  if (typeof p$3 !== "object") {
327
344
  return {
@@ -350,7 +367,8 @@ function Make(App) {
350
367
  TAG: "Ok",
351
368
  _0: [{
352
369
  TAG: "RegistrationProofAccepted",
353
- email: email$2,
370
+ emailId: emailId$2,
371
+ email: p$4.email,
354
372
  roles: p$4.roles,
355
373
  proofHash: proofHash
356
374
  }]
@@ -360,7 +378,7 @@ function Make(App) {
360
378
  TAG: "Ok",
361
379
  _0: [{
362
380
  TAG: "RegistrationProofRefused",
363
- email: email$2,
381
+ emailId: emailId$2,
364
382
  reason: refusalReason(reason._0)
365
383
  }]
366
384
  };
@@ -373,7 +391,7 @@ function Make(App) {
373
391
  TAG: "Ok",
374
392
  _0: [{
375
393
  TAG: "RegistrationCompleted",
376
- email: command.email
394
+ emailId: command.emailId
377
395
  }]
378
396
  };
379
397
  } else {
@@ -391,7 +409,7 @@ function Make(App) {
391
409
  case "Invite" :
392
410
  let requestedAt$1 = command.requestedAt;
393
411
  let roles$1 = command.roles;
394
- let email$3 = command.email;
412
+ let emailId$3 = command.emailId;
395
413
  let role$1 = roles$1.find(r => !isByInvitation(App.table, r));
396
414
  if (role$1 !== undefined) {
397
415
  return {
@@ -408,13 +426,18 @@ function Make(App) {
408
426
  _0: "NoRoleToGrant"
409
427
  };
410
428
  }
411
- let invited_1 = roles$1.map(r => r);
412
- let invited_2 = command.invitedBy;
429
+ let invited_1 = {
430
+ TAG: "Value",
431
+ _0: command.email
432
+ };
433
+ let invited_2 = roles$1.map(r => r);
434
+ let invited_3 = command.invitedBy;
413
435
  let invited = {
414
436
  TAG: "RegistrationInvited",
415
- email: email$3,
416
- roles: invited_1,
417
- invitedBy: invited_2,
437
+ emailId: emailId$3,
438
+ email: invited_1,
439
+ roles: invited_2,
440
+ invitedBy: invited_3,
418
441
  invitedAt: requestedAt$1
419
442
  };
420
443
  let p$5 = state.stage;
@@ -425,7 +448,7 @@ function Make(App) {
425
448
  _0: [
426
449
  {
427
450
  TAG: "RegistrationExpired",
428
- email: email$3
451
+ emailId: emailId$3
429
452
  },
430
453
  invited
431
454
  ]
@@ -467,7 +490,8 @@ function Make(App) {
467
490
  TAG: "Ok",
468
491
  _0: [{
469
492
  TAG: "RegistrationChallengeReissued",
470
- email: command.email,
493
+ emailId: command.emailId,
494
+ email: p$7.email,
471
495
  reissuedAt: requestedAt$2,
472
496
  invitedBy: p$7.invitedBy
473
497
  }]
@@ -496,11 +520,35 @@ function Make(App) {
496
520
  TAG: "Ok",
497
521
  _0: [{
498
522
  TAG: "RegistrationWithdrawn",
499
- email: command.email,
523
+ emailId: command.emailId,
500
524
  withdrawnAt: command.withdrawnAt
501
525
  }]
502
526
  };
503
527
  }
528
+ case "ReleaseRegistration" :
529
+ let match$3 = state.stage;
530
+ if (typeof match$3 !== "object") {
531
+ if (match$3 === "Completed") {
532
+ return {
533
+ TAG: "Ok",
534
+ _0: [{
535
+ TAG: "RegistrationReleased",
536
+ emailId: command.emailId,
537
+ releasedAt: command.releasedAt
538
+ }]
539
+ };
540
+ } else {
541
+ return {
542
+ TAG: "Ok",
543
+ _0: []
544
+ };
545
+ }
546
+ } else {
547
+ return {
548
+ TAG: "Ok",
549
+ _0: []
550
+ };
551
+ }
504
552
  }
505
553
  };
506
554
  return {
@@ -528,6 +576,7 @@ export {
528
576
  Guards,
529
577
  initialState,
530
578
  noticeCooldown,
579
+ contactOf,
531
580
  purposeOf,
532
581
  policyOf,
533
582
  evolve,