@reventlessdev/reventless-registration 1.0.0-alpha.4 → 1.0.0-alpha.41

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
@@ -9,26 +9,35 @@ function groupsOf(roles) {
9
9
  }
10
10
 
11
11
  function collect(event, param) {
12
- let proofHash = event.proofHash;
13
12
  let email = event.email;
13
+ let emailId = event.emailId;
14
+ if (typeof email !== "object") {
15
+ if (email === "Erased") {
16
+ return [];
17
+ } else {
18
+ return [];
19
+ }
20
+ }
21
+ let proofHash = event.proofHash;
14
22
  return [[
15
- email + `:` + proofHash,
23
+ emailId + `:` + proofHash,
16
24
  {
17
- email: email,
25
+ emailId: emailId,
26
+ email: email._0,
18
27
  roles: event.roles,
19
28
  proofHash: proofHash
20
29
  }
21
30
  ]];
22
31
  }
23
32
 
24
- function completed(email) {
33
+ function completed(emailId) {
25
34
  return {
26
35
  TAG: "Ok",
27
36
  _0: [
28
- email,
37
+ emailId,
29
38
  {
30
39
  TAG: "RecordRegistrationCompleted",
31
- email: ContactAddressId$ReventlessRegistration.makeFromString(email)
40
+ emailId: ContactAddressId$ReventlessRegistration.makeFromString(emailId)
32
41
  }
33
42
  ]
34
43
  };
@@ -57,11 +66,11 @@ async function translate(_id, item, capabilities) {
57
66
  _0: password
58
67
  }, item.roles.map(Role$Reventless.groupOf));
59
68
  if (match.TAG === "Ok") {
60
- return completed(item.email);
69
+ return completed(item.emailId);
61
70
  }
62
71
  let why = match._0;
63
72
  if (typeof why !== "object") {
64
- return completed(item.email);
73
+ return completed(item.emailId);
65
74
  }
66
75
  if (why.TAG !== "Unavailable") {
67
76
  return {
@@ -1,5 +1,8 @@
1
1
  // SendRegistrationChallenge OutboundTranslationSlice.
2
2
  //
3
+ // Writes to the address a registration names. Work is keyed by the ledger's id
4
+ // for the address, its fingerprint, never by the address.
5
+ //
3
6
  // Writes to the address a registration names. A fresh registration gets a
4
7
  // secret to prove control of the address, and the ledger records its hash; an
5
8
  // invitation gets one too, worded as an invitation and holding for a week; a
@@ -15,32 +18,58 @@
15
18
 
16
19
  @schema
17
20
  type consumedEvent =
18
- | RegistrationRequested({email: string, requestedAt: Reventless.DateTime.t})
19
- | RegistrationAttemptedOnTakenAddress({email: string, attemptedAt: Reventless.DateTime.t})
21
+ | RegistrationRequested({
22
+ emailId: string,
23
+ @pii({subject: "emailId"}) email: Reventless.Email.t,
24
+ requestedAt: Reventless.DateTime.t,
25
+ language?: string,
26
+ })
27
+ | RegistrationAttemptedOnTakenAddress({
28
+ emailId: string,
29
+ @pii({subject: "emailId"}) email: Reventless.Email.t,
30
+ attemptedAt: Reventless.DateTime.t,
31
+ })
20
32
  | RegistrationInvited({
21
- email: string,
33
+ emailId: string,
34
+ @pii({subject: "emailId"}) email: Reventless.Email.t,
22
35
  roles: array<string>,
23
36
  invitedBy: string,
24
37
  invitedAt: Reventless.DateTime.t,
38
+ language?: string,
25
39
  })
26
40
  | RegistrationChallengeReissued({
27
- email: string,
41
+ emailId: string,
42
+ @pii({subject: "emailId"}) email: Reventless.Email.t,
28
43
  reissuedAt: Reventless.DateTime.t,
29
44
  invitedBy?: string,
45
+ language?: string,
30
46
  })
31
47
 
48
+ // `emailId` is the ledger's id for the address, `email` the address the mail goes to.
49
+
32
50
  /** `invited` words the secret as an invitation; it is left out for a sign-up
33
51
  and for the notice. `roles` names what the invitation grants, where the
34
- event said: a reissued code does not. */
52
+ event said: a reissued code does not. `language` is the one the claim was made
53
+ in, for a person with no account to say; the notice to a taken address has none,
54
+ since its owner's account does. */
35
55
  @schema
36
- type outboundItem = {email: string, alreadyRegistered: bool, invited?: bool, roles?: array<string>}
56
+ type outboundItem = {
57
+ emailId: string,
58
+ @pii({subject: "emailId"}) email: Reventless.Email.t,
59
+ alreadyRegistered: bool,
60
+ invited?: bool,
61
+ roles?: array<string>,
62
+ language?: string,
63
+ }
37
64
 
38
65
  @schema
39
66
  type inboundCommand =
40
67
  | IssueRegistrationChallenge({
41
- email: ContactAddressId.t,
68
+ emailId: ContactAddressId.t,
42
69
  proofHash: string,
43
70
  issuedAt: Reventless.DateTime.t,
71
+ language?: string,
72
+ messageKey?: string,
44
73
  })
45
74
 
46
75
  // For a mail transport that is down. Exhausting them opens no challenge, which
@@ -49,3 +78,6 @@ let maxRetries = 3
49
78
  let targetName = Some("Registrations")
50
79
  let sourceNames: array<string> = []
51
80
  let capabilityNeeds = [Reventless.CapabilityNeed.Messaging]
81
+
82
+ /** This slice writes to the addresses visitors name; a deployment caps its mail per day. */
83
+ let admissionDoor = Reventless.Admission.Mail
@@ -1,6 +1,8 @@
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";
5
+ import * as Email$Reventless from "@reventlessdev/reventless-spec/src/semantic/Email.res.mjs";
4
6
  import * as DcbTag$Reventless from "@reventlessdev/reventless-spec/src/components/DcbTag.res.mjs";
5
7
  import * as DateTime$Reventless from "@reventlessdev/reventless-spec/src/semantic/DateTime.res.mjs";
6
8
  import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
@@ -8,41 +10,52 @@ import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.re
8
10
  let consumedEventSchema = Sury.union([
9
11
  Sury.$schema(s => ({
10
12
  TAG: "RegistrationRequested",
11
- email: s.m(Sury.string),
12
- requestedAt: s.m(DateTime$Reventless.schema)
13
+ emailId: s.m(DcbTag$Reventless.string),
14
+ email: s.m(Pii$Reventless.marked("emailId", undefined, Email$Reventless.schema)),
15
+ requestedAt: s.m(DateTime$Reventless.schema),
16
+ language: s.m(Sury.$option(Sury.string))
13
17
  })),
14
18
  Sury.$schema(s => ({
15
19
  TAG: "RegistrationAttemptedOnTakenAddress",
16
- email: s.m(Sury.string),
20
+ emailId: s.m(DcbTag$Reventless.string),
21
+ email: s.m(Pii$Reventless.marked("emailId", undefined, Email$Reventless.schema)),
17
22
  attemptedAt: s.m(DateTime$Reventless.schema)
18
23
  })),
19
24
  Sury.$schema(s => ({
20
25
  TAG: "RegistrationInvited",
21
- email: s.m(Sury.string),
26
+ emailId: s.m(DcbTag$Reventless.string),
27
+ email: s.m(Pii$Reventless.marked("emailId", undefined, Email$Reventless.schema)),
22
28
  roles: s.m(Sury.array(Sury.string)),
23
29
  invitedBy: s.m(Sury.string),
24
- invitedAt: s.m(DateTime$Reventless.schema)
30
+ invitedAt: s.m(DateTime$Reventless.schema),
31
+ language: s.m(Sury.$option(Sury.string))
25
32
  })),
26
33
  Sury.$schema(s => ({
27
34
  TAG: "RegistrationChallengeReissued",
28
- email: s.m(Sury.string),
35
+ emailId: s.m(DcbTag$Reventless.string),
36
+ email: s.m(Pii$Reventless.marked("emailId", undefined, Email$Reventless.schema)),
29
37
  reissuedAt: s.m(DateTime$Reventless.schema),
30
- invitedBy: s.m(Sury.$option(Sury.string))
38
+ invitedBy: s.m(Sury.$option(Sury.string)),
39
+ language: s.m(Sury.$option(Sury.string))
31
40
  }))
32
41
  ]);
33
42
 
34
43
  let outboundItemSchema = Sury.$schema(s => ({
35
- email: s.m(Sury.string),
44
+ emailId: s.m(Sury.string),
45
+ email: s.m(Pii$Reventless.mark("emailId", undefined, Email$Reventless.schema)),
36
46
  alreadyRegistered: s.m(Sury.boolean),
37
47
  invited: s.m(Sury.$option(Sury.boolean)),
38
- roles: s.m(Sury.$option(Sury.array(Sury.string)))
48
+ roles: s.m(Sury.$option(Sury.array(Sury.string))),
49
+ language: s.m(Sury.$option(Sury.string))
39
50
  }));
40
51
 
41
52
  let inboundCommandSchema = Sury.$schema(s => ({
42
53
  TAG: "IssueRegistrationChallenge",
43
- email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
54
+ emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
44
55
  proofHash: s.m(Sury.string),
45
- issuedAt: s.m(DateTime$Reventless.schema)
56
+ issuedAt: s.m(DateTime$Reventless.schema),
57
+ language: s.m(Sury.$option(Sury.string)),
58
+ messageKey: s.m(Sury.$option(Sury.string))
46
59
  }));
47
60
 
48
61
  let sourceNames = [];
@@ -59,6 +72,8 @@ let maxRetries = 3;
59
72
 
60
73
  let targetName = "Registrations";
61
74
 
75
+ let admissionDoor = "mail";
76
+
62
77
  let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/OutboundTranslation/SendRegistrationChallenge.res.mjs";
63
78
 
64
79
  let externalSystem;
@@ -73,6 +88,7 @@ export {
73
88
  targetName,
74
89
  sourceNames,
75
90
  capabilityNeeds,
91
+ admissionDoor,
76
92
  moduleUrl,
77
93
  externalSystem,
78
94
  traits,
@@ -4,61 +4,126 @@
4
4
  // or a code reissued, is new work rather than work already done.
5
5
  let collect = (event, ~sourceId as _) =>
6
6
  switch event {
7
- | RegistrationRequested({email, requestedAt}) => [
8
- (`${email}:${requestedAt->Reventless.DateTime.toString}`, {email, alreadyRegistered: false}),
7
+ | RegistrationRequested({emailId, email: Value(email), requestedAt, ?language}) => [
8
+ (
9
+ `${emailId}:${requestedAt->Reventless.DateTime.toString}`,
10
+ {emailId, email, alreadyRegistered: false, ?language},
11
+ ),
9
12
  ]
10
- | RegistrationInvited({email, roles, invitedAt}) => [
13
+ | RegistrationInvited({emailId, email: Value(email), roles, invitedAt, ?language}) => [
11
14
  (
12
- `${email}:invited:${invitedAt->Reventless.DateTime.toString}`,
13
- {email, alreadyRegistered: false, invited: true, roles},
15
+ `${emailId}:invited:${invitedAt->Reventless.DateTime.toString}`,
16
+ {emailId, email, alreadyRegistered: false, invited: true, roles, ?language},
14
17
  ),
15
18
  ]
16
- | RegistrationChallengeReissued({email, reissuedAt, ?invitedBy}) => [
19
+ | RegistrationChallengeReissued({
20
+ emailId,
21
+ email: Value(email),
22
+ reissuedAt,
23
+ ?invitedBy,
24
+ ?language,
25
+ }) => [
17
26
  (
18
- `${email}:reissued:${reissuedAt->Reventless.DateTime.toString}`,
19
- {email, alreadyRegistered: false, invited: invitedBy->Option.isSome},
27
+ `${emailId}:reissued:${reissuedAt->Reventless.DateTime.toString}`,
28
+ {emailId, email, alreadyRegistered: false, invited: invitedBy->Option.isSome, ?language},
20
29
  ),
21
30
  ]
22
- | RegistrationAttemptedOnTakenAddress({email, attemptedAt}) => [
31
+ | RegistrationAttemptedOnTakenAddress({emailId, email: Value(email), attemptedAt}) => [
23
32
  (
24
- `${email}:taken:${attemptedAt->Reventless.DateTime.toString}`,
25
- {email, alreadyRegistered: true},
33
+ `${emailId}:taken:${attemptedAt->Reventless.DateTime.toString}`,
34
+ {emailId, email, alreadyRegistered: true},
26
35
  ),
27
36
  ]
37
+ // An address that was erased or forgotten has nobody left to write to.
38
+ | _ => []
39
+ }
40
+
41
+ // The mails' words, by key, in the English a deployment with no catalogue sends. A translation
42
+ // is a catalogue's `registration.*` keys; `pnpm run check:server-catalogues` keeps
43
+ // `i18n/en.json` the same as these.
44
+ module Messages = {
45
+ let challengeSubject: Reventless.Text.message = {
46
+ key: "registration.challenge.subject",
47
+ source: "Finish your registration",
48
+ }
49
+ let challengeBody: Reventless.Text.message = {
50
+ key: "registration.challenge.body",
51
+ source: "Your registration code is {token}. Enter it with a password of your choice to finish. It expires in {expiresIn}.",
52
+ }
53
+ let invitedSubject: Reventless.Text.message = {
54
+ key: "registration.invited.subject",
55
+ source: "You are invited to create an account",
56
+ }
57
+ let invitedBody: Reventless.Text.message = {
58
+ key: "registration.invited.body",
59
+ source: "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}.",
60
+ }
61
+ let takenSubject: Reventless.Text.message = {
62
+ key: "registration.taken.subject",
63
+ source: "Someone tried to register with your address",
64
+ }
65
+ let takenBody: Reventless.Text.message = {
66
+ key: "registration.taken.body",
67
+ source: "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.",
28
68
  }
69
+ let all = [challengeSubject, challengeBody, invitedSubject, invitedBody, takenSubject, takenBody]
70
+ }
29
71
 
30
72
  let expiresIn = (~invited) =>
31
- RegistrationChallenge.policyFor(
32
- RegistrationChallenge.purposeFor(~invited),
33
- ).tokenTtl->Reventless.Duration.format
73
+ RegistrationChallenge.policyFor(RegistrationChallenge.purposeFor(~invited)).tokenTtl
34
74
 
35
- let challengeBody = (~token) =>
36
- `Your registration code is ${token}. Enter it with a password of your choice to finish. It expires in ${expiresIn(
37
- ~invited=false,
38
- )}.`
75
+ let challengeValues = (~token) =>
76
+ dict{
77
+ "token": Reventless.MessageFormat.Text(token),
78
+ "expiresIn": Duration(expiresIn(~invited=false)),
79
+ }
39
80
 
40
- /** What the invitation grants, as the mail says it: "as Merchandiser", or
41
- nothing where the event did not say. */
42
- let asRoles = (roles: option<array<string>>) =>
43
- switch roles {
44
- | Some([]) | None => ""
45
- | Some(roles) => ` as ${roles->Array.join(" and ")}`
81
+ /** What the invitation grants, as the mail says it: "as Merchandiser", or nothing where the
82
+ event did not say. */
83
+ let invitationValues = (~token, ~roles: option<array<string>>=?) => {
84
+ let roles = roles->Option.getOr([])
85
+ dict{
86
+ "token": Reventless.MessageFormat.Text(token),
87
+ "expiresIn": Duration(expiresIn(~invited=true)),
88
+ "hasRoles": Text(roles == [] ? "no" : "yes"),
89
+ "roles": List(roles),
46
90
  }
91
+ }
92
+
93
+ /** The mails in English, as a deployment with no catalogue sends them. */
94
+ let challengeBody = (~token) =>
95
+ Messages.challengeBody->Reventless.Text.inSource(~values=challengeValues(~token))
47
96
 
48
97
  let invitationBody = (~token, ~roles=?) =>
49
- `You have been invited to create an account${asRoles(
50
- roles,
51
- )}. Your code is ${token}. Enter it with this address and a password of your choice to accept. It expires in ${expiresIn(
52
- ~invited=true,
53
- )}.`
98
+ Messages.invitedBody->Reventless.Text.inSource(~values=invitationValues(~token, ~roles?))
54
99
 
55
- let noticeBody = "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."
100
+ let noticeBody = Messages.takenBody->Reventless.Text.inSource
56
101
 
57
- let send = (capabilities: Reventless.Capabilities.t, ~email, ~subject, ~body) =>
58
- capabilities.messaging.send(
59
- ~recipient=ToEmail(Reventless.Email.unsafe(email)),
60
- ~message={subject, body},
61
- )
102
+ /** Write and send one mail; what it answers is the language it went out in. */
103
+ let send = async (
104
+ capabilities: Reventless.Capabilities.t,
105
+ ~email,
106
+ ~requested=?,
107
+ ~subject,
108
+ ~body,
109
+ ~values,
110
+ ) => {
111
+ let recipient: Reventless.Messaging.recipient = ToEmail(email)
112
+ switch await capabilities.text->Reventless.Text.compose(
113
+ ~recipient,
114
+ ~requested?,
115
+ ~subject,
116
+ ~body,
117
+ ~values,
118
+ ) {
119
+ | Error(reason) => Error(reason)
120
+ | Ok(message) =>
121
+ switch await capabilities.messaging.send(~recipient, ~message) {
122
+ | Ok(_) => Ok(message.language)
123
+ | Error(failure) => Error(Reventless.Messaging.failureReason(failure))
124
+ }
125
+ }
126
+ }
62
127
 
63
128
  /**
64
129
  Draw a secret, send it, and open a challenge against its hash — sending first,
@@ -69,11 +134,12 @@ let translate = async (_id, item: outboundItem, ~capabilities: Reventless.Capabi
69
134
  switch await send(
70
135
  capabilities,
71
136
  ~email=item.email,
72
- ~subject="Someone tried to register with your address",
73
- ~body=noticeBody,
137
+ ~subject=Messages.takenSubject,
138
+ ~body=Messages.takenBody,
139
+ ~values=Dict.make(),
74
140
  ) {
75
141
  | Ok(_) => Ok(None)
76
- | Error(failure) => Error(Reventless.Messaging.failureReason(failure))
142
+ | Error(reason) => Error(reason)
77
143
  }
78
144
  } else {
79
145
  let invited = item.invited->Option.getOr(false)
@@ -87,24 +153,29 @@ let translate = async (_id, item: outboundItem, ~capabilities: Reventless.Capabi
87
153
  switch capabilities.secrets.hash(token) {
88
154
  | Error(Unavailable(why)) => Error(`cannot hash a secret: ${why}`)
89
155
  | Ok(proofHash) =>
156
+ let body = invited ? Messages.invitedBody : Messages.challengeBody
90
157
  switch await send(
91
158
  capabilities,
92
159
  ~email=item.email,
93
- ~subject=invited ? "You are invited to create an account" : "Finish your registration",
94
- ~body=invited ? invitationBody(~token, ~roles=?item.roles) : challengeBody(~token),
160
+ ~requested=?item.language,
161
+ ~subject=invited ? Messages.invitedSubject : Messages.challengeSubject,
162
+ ~body,
163
+ ~values=invited ? invitationValues(~token, ~roles=?item.roles) : challengeValues(~token),
95
164
  ) {
96
- | Ok(_) =>
165
+ | Ok(language) =>
97
166
  Ok(
98
167
  Some((
99
- item.email,
168
+ item.emailId,
100
169
  IssueRegistrationChallenge({
101
- email: ContactAddressId.makeFromString(item.email),
170
+ emailId: ContactAddressId.makeFromString(item.emailId),
102
171
  proofHash,
103
172
  issuedAt: Date.make()->Date.toISOString->Reventless.DateTime.unsafe,
173
+ ?language,
174
+ messageKey: body.key,
104
175
  }),
105
176
  )),
106
177
  )
107
- | Error(failure) => Error(Reventless.Messaging.failureReason(failure))
178
+ | Error(reason) => Error(reason)
108
179
  }
109
180
  }
110
181
  }