@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.
Files changed (30) hide show
  1. package/README.md +10 -0
  2. package/i18n/en.json +8 -0
  3. package/package.json +7 -6
  4. package/src/Registration/ContactAddressId.res +27 -3
  5. package/src/Registration/ContactAddressId.res.mjs +26 -2
  6. package/src/Registration/InboundTranslation/CompleteRegistration.res +2 -2
  7. package/src/Registration/InboundTranslation/CompleteRegistration.res.mjs +3 -3
  8. package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res +9 -6
  9. package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res.mjs +16 -9
  10. package/src/Registration/InboundTranslation/SignUp.res +19 -8
  11. package/src/Registration/InboundTranslation/SignUp.res.mjs +15 -6
  12. package/src/Registration/InboundTranslation/SignUp_Translation.res +51 -15
  13. package/src/Registration/InboundTranslation/SignUp_Translation.res.mjs +50 -8
  14. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res +9 -3
  15. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res.mjs +7 -3
  16. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res +10 -7
  17. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res.mjs +17 -8
  18. package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res +39 -7
  19. package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res.mjs +27 -11
  20. package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res +115 -44
  21. package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res.mjs +203 -61
  22. package/src/Registration/StateChange/RegistrationPolicy.res +3 -0
  23. package/src/Registration/StateChange/RegistrationPolicy.res.mjs +3 -0
  24. package/src/Registration/StateChange/RegistrationPolicy_Decision.res +6 -5
  25. package/src/Registration/StateChange/RegistrationPolicy_Decision.res.mjs +22 -15
  26. package/src/Registration/StateChange/Registrations.res +79 -27
  27. package/src/Registration/StateChange/Registrations.res.mjs +85 -39
  28. package/src/Registration/StateChange/Registrations_Decision.res +96 -36
  29. package/src/Registration/StateChange/Registrations_Decision.res.mjs +119 -52
  30. package/src/Registration/StateViewStream/RegistrationWindows.res.mjs +1 -1
package/README.md CHANGED
@@ -44,6 +44,16 @@ Reventless.Admission.Invite`, checks the inviter's roles, and relays `Invite` to
44
44
  ledger. The ledger refuses any role the app's table does not declare by invitation.
45
45
  An invitation's code holds a week; a sign-up's holds a day.
46
46
 
47
+ The mails are written in the recipient's language where the deployment has the words:
48
+ their keys are `registration.*`, and `i18n/en.json` holds their English. A deployment
49
+ lists `node_modules/@reventlessdev/reventless-registration/i18n` among its catalogue
50
+ sources, before its own, and translates the keys there. Without a translation the
51
+ mails go out in that English. A sign-up may say which language the visitor reads
52
+ (`language`, a tag such as `de`); the codes for that registration are written in it
53
+ where the deployment offers it, unless the address already holds an account, whose
54
+ own language wins. The ledger records the language and the key of the mail each code
55
+ went out in.
56
+
47
57
  The scenarios that pin these slices run in the plugins that list them, against that
48
58
  plugin's own table: in this repository, `examples/online-shop-hybrid/registration`.
49
59
 
package/i18n/en.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "registration.challenge.body": "Your registration code is {token}. Enter it with a password of your choice to finish. It expires in {expiresIn}.",
3
+ "registration.challenge.subject": "Finish your registration",
4
+ "registration.invited.body": "You have been invited to create an account{hasRoles, select, yes { as {roles}} other {}}. Your code is {token}. Enter it with this address and a password of your choice to accept. It expires in {expiresIn}.",
5
+ "registration.invited.subject": "You are invited to create an account",
6
+ "registration.taken.body": "Someone asked to register an account with this address, which already has one. If it was you, sign in instead. If it was not, there is nothing to do: no account was changed.",
7
+ "registration.taken.subject": "Someone tried to register with your address"
8
+ }
package/package.json CHANGED
@@ -1,21 +1,22 @@
1
1
  {
2
2
  "name": "@reventlessdev/reventless-registration",
3
- "version": "1.0.0-alpha.4",
3
+ "version": "1.0.0-alpha.40",
4
4
  "description": "Self-registration as a library of slices: a person with no account proves control of an address and ends up with one, admitted per role as the app declares",
5
5
  "license": "Apache-2.0",
6
6
  "files": [
7
7
  "src/**/*.res",
8
8
  "src/**/*.resi",
9
9
  "src/**/*.res.mjs",
10
+ "i18n/*.json",
10
11
  "rescript.json",
11
12
  "README.md"
12
13
  ],
13
14
  "dependencies": {
14
- "sury": "11.0.0",
15
- "sury-ppx": "11.0.0",
16
- "@reventlessdev/reventless-infra": "3.0.0-alpha.208",
17
- "@reventlessdev/reventless-spec": "3.0.0-alpha.179",
18
- "@reventlessdev/reventless-ppx": "1.0.0-alpha.108"
15
+ "sury": "11.1.0",
16
+ "sury-ppx": "11.1.0",
17
+ "@reventlessdev/reventless-infra": "3.0.0-alpha.241",
18
+ "@reventlessdev/reventless-ppx": "^1.0.0-alpha.118",
19
+ "@reventlessdev/reventless-spec": "3.0.0-alpha.210"
19
20
  },
20
21
  "devDependencies": {
21
22
  "rescript": "12.3.1"
@@ -1,6 +1,30 @@
1
- // The address a registration claims: the partition the registration ledger
2
- // decides about, and the tag that makes "this address is taken" one fact on
3
- // every platform. Its value is the address itself, lower-cased.
1
+ // The address a registration claims, as the ledger knows it: the partition it
2
+ // decides about, and the tag that makes "this address is taken" one fact on every
3
+ // platform.
4
+ //
5
+ // Its value is a keyed fingerprint of the lower-cased address, never the address.
6
+ // A tag is an index key, and an index key cannot be encrypted or erased, so the
7
+ // address itself is carried beside it in a field of its own on the events that
8
+ // must reach the person. The key is the deployment's (`secrets.fingerprint`) and
9
+ // is never rotated: rotating it would orphan every registration recorded under
10
+ // the old one.
4
11
  include Reventless.Id.Make({
5
12
  let key = "contactAddress"
6
13
  })
14
+
15
+ /** What the fingerprint is taken under, so no other use of the deployment's key
16
+ can produce the same value for an address. */
17
+ let purpose = "contactAddress"
18
+
19
+ /** The form every door takes the fingerprint of: an address differing only in
20
+ case or surrounding spaces is the same registration. */
21
+ let normalize = (address: Reventless.Email.t): Reventless.Email.t =>
22
+ address->Reventless.Email.toString->String.trim->String.toLowerCase->Reventless.Email.unsafe
23
+
24
+ /** The ledger's id for an address. Refused, never degraded to the address, when
25
+ the deployment holds no key. */
26
+ let fingerprint = (secrets: Reventless.Secrets.t, address: Reventless.Email.t): result<t, string> =>
27
+ switch secrets.fingerprint(~purpose, address->normalize->Reventless.Email.toString) {
28
+ | Ok(value) => Ok(makeFromString(value))
29
+ | Error(Unavailable(why)) => Error(`cannot fingerprint the address: ${why}`)
30
+ }
@@ -6,12 +6,33 @@ let include = Id$Reventless.Make({
6
6
  key: "contactAddress"
7
7
  });
8
8
 
9
+ let makeFromString = include.makeFromString;
10
+
11
+ let purpose = "contactAddress";
12
+
13
+ function normalize(address) {
14
+ return address.trim().toLowerCase();
15
+ }
16
+
17
+ function fingerprint(secrets, address) {
18
+ let value = secrets.fingerprint(purpose, address.trim().toLowerCase());
19
+ if (value.TAG === "Ok") {
20
+ return {
21
+ TAG: "Ok",
22
+ _0: makeFromString(value._0)
23
+ };
24
+ } else {
25
+ return {
26
+ TAG: "Error",
27
+ _0: `cannot fingerprint the address: ` + value._0._0
28
+ };
29
+ }
30
+ }
31
+
9
32
  let schema = include.schema;
10
33
 
11
34
  let make = include.make;
12
35
 
13
- let makeFromString = include.makeFromString;
14
-
15
36
  let toString = include.toString;
16
37
 
17
38
  let cmp = include.cmp;
@@ -25,5 +46,8 @@ export {
25
46
  toString,
26
47
  cmp,
27
48
  key,
49
+ purpose,
50
+ normalize,
51
+ fingerprint,
28
52
  }
29
53
  /* include Not a pure module */
@@ -15,7 +15,7 @@
15
15
 
16
16
  @schema
17
17
  type externalInput = {
18
- email: string,
18
+ @sensitive email: string,
19
19
  @sensitive proof: string,
20
20
  @sensitive password: string,
21
21
  }
@@ -23,7 +23,7 @@ type externalInput = {
23
23
  @schema
24
24
  type command =
25
25
  | SubmitRegistrationProof({
26
- email: ContactAddressId.t,
26
+ emailId: ContactAddressId.t,
27
27
  proofHash: string,
28
28
  presentedAt: Reventless.DateTime.t,
29
29
  })
@@ -7,14 +7,14 @@ import * as Sensitive$Reventless from "@reventlessdev/reventless-spec/src/compon
7
7
  import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
8
8
 
9
9
  let externalInputSchema = Sury.$schema(s => ({
10
- email: s.m(Sury.string),
10
+ email: s.m(Sensitive$Reventless.string),
11
11
  proof: s.m(Sensitive$Reventless.string),
12
12
  password: s.m(Sensitive$Reventless.string)
13
13
  }));
14
14
 
15
15
  let commandSchema = Sury.$schema(s => ({
16
16
  TAG: "SubmitRegistrationProof",
17
- email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
17
+ emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
18
18
  proofHash: s.m(Sury.string),
19
19
  presentedAt: s.m(DateTime$Reventless.schema)
20
20
  }));
@@ -33,7 +33,7 @@ let Id;
33
33
 
34
34
  let targetName = "Registrations";
35
35
 
36
- let admissionDoor = "Complete";
36
+ let admissionDoor = "complete";
37
37
 
38
38
  let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/InboundTranslation/CompleteRegistration.res.mjs";
39
39
 
@@ -17,19 +17,22 @@ let translate = async (
17
17
  | Ok(_) if input.password->String.length < minimumPasswordLength =>
18
18
  Error(`a password needs at least ${minimumPasswordLength->Int.toString} characters`)
19
19
  | Ok(email) =>
20
- let email = email->Reventless.Email.toString->String.toLowerCase
21
- switch capabilities.secrets.hash(input.proof->String.trim) {
22
- | Error(Unavailable(why)) => Error(`cannot hash the proof: ${why}`)
23
- | Ok(proofHash) =>
20
+ switch (
21
+ ContactAddressId.fingerprint(capabilities.secrets, email),
22
+ capabilities.secrets.hash(input.proof->String.trim),
23
+ ) {
24
+ | (Error(why), _) => Error(why)
25
+ | (_, Error(Unavailable(why))) => Error(`cannot hash the proof: ${why}`)
26
+ | (Ok(id), Ok(proofHash)) =>
24
27
  switch await capabilities.stash.put(~key=proofHash, ~value=input.password, ~ttl=passwordTtl) {
25
28
  | Error(failure) =>
26
29
  Error(`cannot hold the password: ${failure->Reventless.Stash.failureReason}`)
27
30
  | Ok() =>
28
31
  Ok([
29
32
  (
30
- email,
33
+ id->ContactAddressId.toString,
31
34
  SubmitRegistrationProof({
32
- email: ContactAddressId.makeFromString(email),
35
+ emailId: id,
33
36
  proofHash,
34
37
  presentedAt: Date.make()->Date.toISOString->Reventless.DateTime.unsafe,
35
38
  }),
@@ -18,25 +18,32 @@ async function translate(input, capabilities, param) {
18
18
  _0: `a password needs at least ` + (12).toString() + ` characters`
19
19
  };
20
20
  }
21
- let email$1 = email._0.toLowerCase();
22
- let proofHash = capabilities.secrets.hash(input.proof.trim());
23
- if (proofHash.TAG !== "Ok") {
21
+ let match = ContactAddressId$ReventlessRegistration.fingerprint(capabilities.secrets, email._0);
22
+ let match$1 = capabilities.secrets.hash(input.proof.trim());
23
+ if (match.TAG !== "Ok") {
24
24
  return {
25
25
  TAG: "Error",
26
- _0: `cannot hash the proof: ` + proofHash._0._0
26
+ _0: match._0
27
27
  };
28
28
  }
29
- let proofHash$1 = proofHash._0;
30
- let failure = await capabilities.stash.put(proofHash$1, input.password, 600);
29
+ let id = match._0;
30
+ if (match$1.TAG !== "Ok") {
31
+ return {
32
+ TAG: "Error",
33
+ _0: `cannot hash the proof: ` + match$1._0._0
34
+ };
35
+ }
36
+ let proofHash = match$1._0;
37
+ let failure = await capabilities.stash.put(proofHash, input.password, 600);
31
38
  if (failure.TAG === "Ok") {
32
39
  return {
33
40
  TAG: "Ok",
34
41
  _0: [[
35
- email$1,
42
+ ContactAddressId$ReventlessRegistration.toString(id),
36
43
  {
37
44
  TAG: "SubmitRegistrationProof",
38
- email: ContactAddressId$ReventlessRegistration.makeFromString(email$1),
39
- proofHash: proofHash$1,
45
+ emailId: id,
46
+ proofHash: proofHash,
40
47
  presentedAt: new Date().toISOString()
41
48
  }
42
49
  ]]
@@ -7,29 +7,40 @@
7
7
  // learns none of it: a closed role, a role no visitor may have, a taken address
8
8
  // and a fresh one all answer alike.
9
9
  //
10
- // Anonymous because the caller is trying to become someone. The local platform
11
- // honors that; a deployed one refuses the rule until it has a door of its own,
12
- // which is why a plugin listing these slices is hosted by the local platform
13
- // only.
10
+ // First it asks the person check whether a person sent the request; a missing,
11
+ // failed or unanswerable check relays nothing and says so, which names no address.
12
+ //
13
+ // Anonymous because the caller is trying to become someone. A deployed platform
14
+ // hosts it on a door for visitors, with its guards.
14
15
 
15
16
  @@reventless.spec
16
17
  @@reventless.authorize(AllowAnonymous)
17
18
 
18
19
  /** `role` may be left out where exactly one role is open to visitors; with
19
- several, a sign-up has to say which. */
20
+ several, a sign-up has to say which. `language` is the one the visitor reads the
21
+ shell in, which their mails are written in where the deployment offers it.
22
+ `personCheck` is the token of the widget the deployment names, if it names one. */
20
23
  @schema
21
- type externalInput = {email: string, role?: string}
24
+ type externalInput = {
25
+ @sensitive email: string,
26
+ role?: string,
27
+ language?: string,
28
+ @sensitive personCheck?: string,
29
+ }
22
30
 
23
31
  @schema
24
32
  type command =
25
33
  | Register({
26
- email: ContactAddressId.t,
34
+ emailId: ContactAddressId.t,
35
+ @pii({subject: "emailId"}) email: Reventless.Email.t,
27
36
  role: Reventless.Role.name,
28
37
  requestedAt: Reventless.DateTime.t,
38
+ language?: string,
39
+ initially?: @s.matches(Reventless.Admission.initiallySchema) Reventless.Admission.initially,
29
40
  })
30
41
 
31
42
  let targetName = "Registrations"
32
- let capabilityNeeds: array<Reventless.CapabilityNeed.t> = []
43
+ let capabilityNeeds = [Reventless.CapabilityNeed.PersonCheck]
33
44
 
34
45
  /** This door starts a registration; the platform tells the shell so. */
35
46
  let admissionDoor = Reventless.Admission.Start
@@ -1,24 +1,33 @@
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 DateTime$Reventless from "@reventlessdev/reventless-spec/src/semantic/DateTime.res.mjs";
9
+ import * as Admission$Reventless from "@reventlessdev/reventless-spec/src/types/Admission.res.mjs";
10
+ import * as Sensitive$Reventless from "@reventlessdev/reventless-spec/src/components/Sensitive.res.mjs";
7
11
  import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
8
12
 
9
13
  let externalInputSchema = Sury.$schema(s => ({
10
- email: s.m(Sury.string),
11
- role: s.m(Sury.$option(Sury.string))
14
+ email: s.m(Sensitive$Reventless.string),
15
+ role: s.m(Sury.$option(Sury.string)),
16
+ language: s.m(Sury.$option(Sury.string)),
17
+ personCheck: s.m(Sury.$option(Sensitive$Reventless.string))
12
18
  }));
13
19
 
14
20
  let commandSchema = Sury.$schema(s => ({
15
21
  TAG: "Register",
16
- email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
22
+ emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
23
+ email: s.m(Pii$Reventless.mark("emailId", undefined, Email$Reventless.schema)),
17
24
  role: s.m(Role$Reventless.nameSchema),
18
- requestedAt: s.m(DateTime$Reventless.schema)
25
+ requestedAt: s.m(DateTime$Reventless.schema),
26
+ language: s.m(Sury.$option(Sury.string)),
27
+ initially: s.m(Sury.$option(Admission$Reventless.initiallySchema))
19
28
  }));
20
29
 
21
- let capabilityNeeds = [];
30
+ let capabilityNeeds = ["PersonCheck"];
22
31
 
23
32
  function authorizationOf(param) {
24
33
  return "AllowAnonymous";
@@ -32,7 +41,7 @@ let Id;
32
41
 
33
42
  let targetName = "Registrations";
34
43
 
35
- let admissionDoor = "Start";
44
+ let admissionDoor = "start";
36
45
 
37
46
  let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/InboundTranslation/SignUp.res.mjs";
38
47
 
@@ -8,15 +8,42 @@ let defaultRole = (table: Reventless.Admission.t): option<Reventless.Role.name>
8
8
  | _ => None
9
9
  }
10
10
 
11
+ /** A language tag as a request gave it, or none where it does not look like one: it only
12
+ picks the words of a mail, so a malformed one is dropped rather than refused. */
13
+ let languageOf = (raw: option<string>): option<string> =>
14
+ raw
15
+ ->Option.map(String.trim)
16
+ ->Option.filter(tag =>
17
+ String.length(tag) <= 35 && /^[A-Za-z]{2,3}(-[A-Za-z0-9]{1,8})*$/->RegExp.test(tag)
18
+ )
19
+
20
+ /** What a sign-up is told when the check says no: the same whatever the address,
21
+ so it says nothing of one. */
22
+ let personCheckRejected = "the check that a person is signing up did not pass; try it again"
23
+
24
+ /** What it is told when the check cannot be asked. Refused rather than let through,
25
+ so a check that is down never opens the door to scripts. */
26
+ let personCheckUnavailable = "the check that a person is signing up cannot be reached; try again later"
27
+
11
28
  /** The door over the app's table, which picks the role a sign-up may leave out. */
12
29
  module Make = (App: Reventless.Admission.Declaration) => {
13
30
  module Spec = Spec
14
31
  let moduleUrl = moduleUrl
15
32
 
16
- let translate = async (input: externalInput, ~capabilities as _, ~caller as _) =>
17
- switch (Reventless.Email.fromString(input.email->String.trim), input.role) {
18
- | (Error(_), _) => Error("not an email address")
19
- | (Ok(email), role) =>
33
+ let translate = async (
34
+ input: externalInput,
35
+ ~capabilities: Reventless.Capabilities.t,
36
+ ~caller as _,
37
+ ) =>
38
+ switch (
39
+ await capabilities.personCheck.verify(~token=input.personCheck->Option.getOr("")),
40
+ Reventless.Email.fromString(input.email->String.trim),
41
+ input.role,
42
+ ) {
43
+ | (Error(Rejected(_)), _, _) => Error(personCheckRejected)
44
+ | (Error(Unavailable(_)), _, _) => Error(personCheckUnavailable)
45
+ | (Ok(), Error(_), _) => Error("not an email address")
46
+ | (Ok(), Ok(typed), role) =>
20
47
  switch role
21
48
  ->Option.map(String.trim)
22
49
  ->Option.filter(r => r != "")
@@ -24,17 +51,26 @@ module Make = (App: Reventless.Admission.Declaration) => {
24
51
  ->Option.orElse(defaultRole(App.table)) {
25
52
  | None => Error("say which role to sign up for")
26
53
  | Some(role) =>
27
- let email = email->Reventless.Email.toString->String.toLowerCase
28
- Ok([
29
- (
30
- email,
31
- Register({
32
- email: ContactAddressId.makeFromString(email),
33
- role,
34
- requestedAt: Date.make()->Date.toISOString->Reventless.DateTime.unsafe,
35
- }),
36
- ),
37
- ])
54
+ let email = typed->ContactAddressId.normalize
55
+ switch ContactAddressId.fingerprint(capabilities.secrets, email) {
56
+ | Error(why) => Error(why)
57
+ | Ok(id) =>
58
+ // The envelope id is the fingerprint too: an id is stored beside the
59
+ // event, where the address must not be.
60
+ Ok([
61
+ (
62
+ id->ContactAddressId.toString,
63
+ Register({
64
+ emailId: id,
65
+ email,
66
+ role,
67
+ requestedAt: Date.make()->Date.toISOString->Reventless.DateTime.unsafe,
68
+ language: ?languageOf(input.language),
69
+ initially: capabilities.selfRegistrationInitially,
70
+ }),
71
+ ),
72
+ ])
73
+ }
38
74
  }
39
75
  }
40
76
  }
@@ -15,33 +15,72 @@ function defaultRole(table) {
15
15
  }
16
16
  }
17
17
 
18
+ function languageOf(raw) {
19
+ return Stdlib_Option.filter(Stdlib_Option.map(raw, prim => prim.trim()), tag => {
20
+ if (tag.length <= 35) {
21
+ return /^[A-Za-z]{2,3}(-[A-Za-z0-9]{1,8})*$/.test(tag);
22
+ } else {
23
+ return false;
24
+ }
25
+ });
26
+ }
27
+
28
+ let personCheckRejected = "the check that a person is signing up did not pass; try it again";
29
+
30
+ let personCheckUnavailable = "the check that a person is signing up cannot be reached; try again later";
31
+
18
32
  function Make(App) {
19
- let translate = async (input, param, param$1) => {
20
- let match = Email$Reventless.fromString(input.email.trim());
21
- let match$1 = input.role;
33
+ let translate = async (input, capabilities, param) => {
34
+ let match = await capabilities.personCheck.verify(Stdlib_Option.getOr(input.personCheck, ""));
35
+ let match$1 = Email$Reventless.fromString(input.email.trim());
36
+ let match$2 = input.role;
22
37
  if (match.TAG !== "Ok") {
38
+ if (match._0.TAG === "Rejected") {
39
+ return {
40
+ TAG: "Error",
41
+ _0: personCheckRejected
42
+ };
43
+ } else {
44
+ return {
45
+ TAG: "Error",
46
+ _0: personCheckUnavailable
47
+ };
48
+ }
49
+ }
50
+ if (match$1.TAG !== "Ok") {
23
51
  return {
24
52
  TAG: "Error",
25
53
  _0: "not an email address"
26
54
  };
27
55
  }
28
- let role = Stdlib_Option.orElse(Stdlib_Option.map(Stdlib_Option.filter(Stdlib_Option.map(match$1, prim => prim.trim()), r => r !== ""), prim => prim), defaultRole(App.table));
56
+ let role = Stdlib_Option.orElse(Stdlib_Option.map(Stdlib_Option.filter(Stdlib_Option.map(match$2, prim => prim.trim()), r => r !== ""), prim => prim), defaultRole(App.table));
29
57
  if (role === undefined) {
30
58
  return {
31
59
  TAG: "Error",
32
60
  _0: "say which role to sign up for"
33
61
  };
34
62
  }
35
- let email = match._0.toLowerCase();
63
+ let email = ContactAddressId$ReventlessRegistration.normalize(match$1._0);
64
+ let why = ContactAddressId$ReventlessRegistration.fingerprint(capabilities.secrets, email);
65
+ if (why.TAG !== "Ok") {
66
+ return {
67
+ TAG: "Error",
68
+ _0: why._0
69
+ };
70
+ }
71
+ let id = why._0;
36
72
  return {
37
73
  TAG: "Ok",
38
74
  _0: [[
39
- email,
75
+ ContactAddressId$ReventlessRegistration.toString(id),
40
76
  {
41
77
  TAG: "Register",
42
- email: ContactAddressId$ReventlessRegistration.makeFromString(email),
78
+ emailId: id,
79
+ email: email,
43
80
  role: role,
44
- requestedAt: new Date().toISOString()
81
+ requestedAt: new Date().toISOString(),
82
+ language: languageOf(input.language),
83
+ initially: capabilities.selfRegistrationInitially
45
84
  }
46
85
  ]]
47
86
  };
@@ -60,6 +99,9 @@ let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/Inbound
60
99
  export {
61
100
  Spec,
62
101
  defaultRole,
102
+ languageOf,
103
+ personCheckRejected,
104
+ personCheckUnavailable,
63
105
  Make,
64
106
  moduleUrl,
65
107
  }
@@ -15,16 +15,22 @@
15
15
  @schema
16
16
  type consumedEvent =
17
17
  | RegistrationProofAccepted({
18
- email: string,
18
+ emailId: string,
19
+ @pii({subject: "emailId"}) email: Reventless.Email.t,
19
20
  roles: array<Reventless.Role.name>,
20
21
  proofHash: string,
21
22
  })
22
23
 
23
24
  @schema
24
- type outboundItem = {email: string, roles: array<Reventless.Role.name>, proofHash: string}
25
+ type outboundItem = {
26
+ emailId: string,
27
+ @pii({subject: "emailId"}) email: Reventless.Email.t,
28
+ roles: array<Reventless.Role.name>,
29
+ proofHash: string,
30
+ }
25
31
 
26
32
  @schema
27
- type inboundCommand = RecordRegistrationCompleted({email: ContactAddressId.t})
33
+ type inboundCommand = RecordRegistrationCompleted({emailId: ContactAddressId.t})
28
34
 
29
35
  // For a provider that is down. The password is put back before each retry, so a
30
36
  // retry finds it; once the budget is spent, it expires.
@@ -1,26 +1,30 @@
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 ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
7
9
 
8
10
  let consumedEventSchema = Sury.$schema(s => ({
9
11
  TAG: "RegistrationProofAccepted",
10
- email: s.m(Sury.string),
12
+ emailId: s.m(DcbTag$Reventless.string),
13
+ email: s.m(Pii$Reventless.marked("emailId", undefined, Email$Reventless.schema)),
11
14
  roles: s.m(Sury.array(Role$Reventless.nameSchema)),
12
15
  proofHash: s.m(Sury.string)
13
16
  }));
14
17
 
15
18
  let outboundItemSchema = Sury.$schema(s => ({
16
- email: s.m(Sury.string),
19
+ emailId: s.m(Sury.string),
20
+ email: s.m(Pii$Reventless.mark("emailId", undefined, Email$Reventless.schema)),
17
21
  roles: s.m(Sury.array(Role$Reventless.nameSchema)),
18
22
  proofHash: s.m(Sury.string)
19
23
  }));
20
24
 
21
25
  let inboundCommandSchema = Sury.$schema(s => ({
22
26
  TAG: "RecordRegistrationCompleted",
23
- email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema))
27
+ emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema))
24
28
  }));
25
29
 
26
30
  let sourceNames = [];
@@ -9,13 +9,16 @@ let retryTtl = 600
9
9
 
10
10
  let collect = (event, ~sourceId as _) =>
11
11
  switch event {
12
- | RegistrationProofAccepted({email, roles, proofHash}) => [
13
- (`${email}:${proofHash}`, {email, roles, proofHash}),
12
+ | RegistrationProofAccepted({emailId, email: Value(email), roles, proofHash}) => [
13
+ (`${emailId}:${proofHash}`, {emailId, email, roles, proofHash}),
14
14
  ]
15
+ // An address that was erased or forgotten has nobody left to write to.
16
+ | _ => []
15
17
  }
16
18
 
17
- let completed = (email: string) => Ok(
18
- Some((email, RecordRegistrationCompleted({email: ContactAddressId.makeFromString(email)}))),
19
+ // `emailId` is already the ledger's id for the address: no key is needed to say so.
20
+ let completed = (emailId: string) => Ok(
21
+ Some((emailId, RecordRegistrationCompleted({emailId: ContactAddressId.makeFromString(emailId)}))),
19
22
  )
20
23
 
21
24
  let translate = async (_id, item: outboundItem, ~capabilities: Reventless.Capabilities.t) =>
@@ -26,14 +29,14 @@ let translate = async (_id, item: outboundItem, ~capabilities: Reventless.Capabi
26
29
  | Ok(None) => Error("the password expired before the account was made")
27
30
  | Ok(Some(password)) =>
28
31
  switch await capabilities.identityProvider.createPrincipal(
29
- ~contact=ToEmail(Reventless.Email.unsafe(item.email)),
32
+ ~contact=ToEmail(item.email),
30
33
  ~credential=Password(password),
31
34
  ~groups=groupsOf(item.roles),
32
35
  ) {
33
- | Ok(_) => completed(item.email)
36
+ | Ok(_) => completed(item.emailId)
34
37
  // The provider already holds this address — an account declared before
35
38
  // registration existed, say. It is as registered as one made here.
36
- | Error(Conflict) => completed(item.email)
39
+ | Error(Conflict) => completed(item.emailId)
37
40
  | Error(Unavailable(why)) =>
38
41
  // Put back so the retry finds it. Failing that, the retry reports the
39
42
  // password gone, which is true.