@reventlessdev/reventless-registration 1.0.0-alpha.5 → 1.0.0-alpha.50

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 (48) hide show
  1. package/README.md +87 -2
  2. package/conformance/Registration/InboundTranslation/CompleteRegistration_Conformance_GWT.res +65 -0
  3. package/conformance/Registration/InboundTranslation/CompleteRegistration_Conformance_GWT.res.mjs +123 -0
  4. package/conformance/Registration/InboundTranslation/SignUp_Conformance_GWT.res +136 -0
  5. package/conformance/Registration/InboundTranslation/SignUp_Conformance_GWT.res.mjs +212 -0
  6. package/conformance/Registration/OutboundTranslation/CreateRegisteredPrincipal_Conformance_GWT.res +102 -0
  7. package/conformance/Registration/OutboundTranslation/CreateRegisteredPrincipal_Conformance_GWT.res.mjs +179 -0
  8. package/conformance/Registration/OutboundTranslation/SendRegistrationChallenge_Conformance_GWT.res +312 -0
  9. package/conformance/Registration/OutboundTranslation/SendRegistrationChallenge_Conformance_GWT.res.mjs +360 -0
  10. package/conformance/Registration/Registration_Conformance_Examples.res +58 -0
  11. package/conformance/Registration/Registration_Conformance_Examples.res.mjs +106 -0
  12. package/conformance/Registration/StateChange/RegistrationPolicy_Conformance_GWT.res +108 -0
  13. package/conformance/Registration/StateChange/RegistrationPolicy_Conformance_GWT.res.mjs +161 -0
  14. package/conformance/Registration/StateChange/RegistrationsByInvitation_Conformance_GWT.res +155 -0
  15. package/conformance/Registration/StateChange/RegistrationsByInvitation_Conformance_GWT.res.mjs +216 -0
  16. package/conformance/Registration/StateChange/Registrations_Conformance_GWT.res +469 -0
  17. package/conformance/Registration/StateChange/Registrations_Conformance_GWT.res.mjs +512 -0
  18. package/conformance/Registration/StateViewStream/RegistrationWindows_Conformance_GWT.res +33 -0
  19. package/conformance/Registration/StateViewStream/RegistrationWindows_Conformance_GWT.res.mjs +87 -0
  20. package/i18n/en.json +8 -0
  21. package/package.json +10 -6
  22. package/rescript.json +6 -1
  23. package/src/Registration/InboundTranslation/CompleteRegistration.res +2 -2
  24. package/src/Registration/InboundTranslation/CompleteRegistration.res.mjs +3 -3
  25. package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res +1 -1
  26. package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res.mjs +1 -1
  27. package/src/Registration/InboundTranslation/SignUp.res +19 -9
  28. package/src/Registration/InboundTranslation/SignUp.res.mjs +14 -7
  29. package/src/Registration/InboundTranslation/SignUp_Translation.res +32 -7
  30. package/src/Registration/InboundTranslation/SignUp_Translation.res.mjs +41 -8
  31. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res +5 -5
  32. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res.mjs +6 -5
  33. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res +10 -8
  34. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res.mjs +18 -10
  35. package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res +24 -13
  36. package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res.mjs +26 -16
  37. package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res +115 -44
  38. package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res.mjs +204 -66
  39. package/src/Registration/StateChange/RegistrationPolicy.res +3 -0
  40. package/src/Registration/StateChange/RegistrationPolicy.res.mjs +3 -0
  41. package/src/Registration/StateChange/RegistrationPolicy_Decision.res +6 -5
  42. package/src/Registration/StateChange/RegistrationPolicy_Decision.res.mjs +22 -15
  43. package/src/Registration/StateChange/Registrations.res +67 -41
  44. package/src/Registration/StateChange/Registrations.res.mjs +84 -51
  45. package/src/Registration/StateChange/Registrations_Decision.res +82 -39
  46. package/src/Registration/StateChange/Registrations_Decision.res.mjs +116 -58
  47. package/src/Registration/StateViewStream/RegistrationWindows.res +4 -0
  48. package/src/Registration/StateViewStream/RegistrationWindows.res.mjs +3 -3
@@ -1,6 +1,7 @@
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 Email$Reventless from "@reventlessdev/reventless-spec/src/semantic/Email.res.mjs";
5
6
  import * as DcbTag$Reventless from "@reventlessdev/reventless-spec/src/components/DcbTag.res.mjs";
6
7
  import * as DateTime$Reventless from "@reventlessdev/reventless-spec/src/semantic/DateTime.res.mjs";
@@ -9,46 +10,52 @@ import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.re
9
10
  let consumedEventSchema = Sury.union([
10
11
  Sury.$schema(s => ({
11
12
  TAG: "RegistrationRequested",
12
- email: s.m(Sury.string),
13
- address: s.m(Email$Reventless.schema),
14
- 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))
15
17
  })),
16
18
  Sury.$schema(s => ({
17
19
  TAG: "RegistrationAttemptedOnTakenAddress",
18
- email: s.m(Sury.string),
19
- address: s.m(Email$Reventless.schema),
20
+ emailId: s.m(DcbTag$Reventless.string),
21
+ email: s.m(Pii$Reventless.marked("emailId", undefined, Email$Reventless.schema)),
20
22
  attemptedAt: s.m(DateTime$Reventless.schema)
21
23
  })),
22
24
  Sury.$schema(s => ({
23
25
  TAG: "RegistrationInvited",
24
- email: s.m(Sury.string),
25
- address: s.m(Email$Reventless.schema),
26
+ emailId: s.m(DcbTag$Reventless.string),
27
+ email: s.m(Pii$Reventless.marked("emailId", undefined, Email$Reventless.schema)),
26
28
  roles: s.m(Sury.array(Sury.string)),
27
29
  invitedBy: s.m(Sury.string),
28
- invitedAt: s.m(DateTime$Reventless.schema)
30
+ invitedAt: s.m(DateTime$Reventless.schema),
31
+ language: s.m(Sury.$option(Sury.string))
29
32
  })),
30
33
  Sury.$schema(s => ({
31
34
  TAG: "RegistrationChallengeReissued",
32
- email: s.m(Sury.string),
33
- address: s.m(Email$Reventless.schema),
35
+ emailId: s.m(DcbTag$Reventless.string),
36
+ email: s.m(Pii$Reventless.marked("emailId", undefined, Email$Reventless.schema)),
34
37
  reissuedAt: s.m(DateTime$Reventless.schema),
35
- invitedBy: s.m(Sury.$option(Sury.string))
38
+ invitedBy: s.m(Sury.$option(Sury.string)),
39
+ language: s.m(Sury.$option(Sury.string))
36
40
  }))
37
41
  ]);
38
42
 
39
43
  let outboundItemSchema = Sury.$schema(s => ({
40
- email: s.m(Sury.string),
41
- address: s.m(Email$Reventless.schema),
44
+ emailId: s.m(Sury.string),
45
+ email: s.m(Pii$Reventless.mark("emailId", undefined, Email$Reventless.schema)),
42
46
  alreadyRegistered: s.m(Sury.boolean),
43
47
  invited: s.m(Sury.$option(Sury.boolean)),
44
- 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))
45
50
  }));
46
51
 
47
52
  let inboundCommandSchema = Sury.$schema(s => ({
48
53
  TAG: "IssueRegistrationChallenge",
49
- email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
54
+ emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
50
55
  proofHash: s.m(Sury.string),
51
- 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))
52
59
  }));
53
60
 
54
61
  let sourceNames = [];
@@ -65,6 +72,8 @@ let maxRetries = 3;
65
72
 
66
73
  let targetName = "Registrations";
67
74
 
75
+ let admissionDoor = "mail";
76
+
68
77
  let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/OutboundTranslation/SendRegistrationChallenge.res.mjs";
69
78
 
70
79
  let externalSystem;
@@ -79,6 +88,7 @@ export {
79
88
  targetName,
80
89
  sourceNames,
81
90
  capabilityNeeds,
91
+ admissionDoor,
82
92
  moduleUrl,
83
93
  externalSystem,
84
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, address, requestedAt}) => [
7
+ | RegistrationRequested({emailId, email: Value(email), requestedAt, ?language}) => [
8
8
  (
9
- `${email}:${requestedAt->Reventless.DateTime.toString}`,
10
- {email, address, alreadyRegistered: false},
9
+ `${emailId}:${requestedAt->Reventless.DateTime.toString}`,
10
+ {emailId, email, alreadyRegistered: false, ?language},
11
11
  ),
12
12
  ]
13
- | RegistrationInvited({email, address, roles, invitedAt}) => [
13
+ | RegistrationInvited({emailId, email: Value(email), roles, invitedAt, ?language}) => [
14
14
  (
15
- `${email}:invited:${invitedAt->Reventless.DateTime.toString}`,
16
- {email, address, alreadyRegistered: false, invited: true, roles},
15
+ `${emailId}:invited:${invitedAt->Reventless.DateTime.toString}`,
16
+ {emailId, email, alreadyRegistered: false, invited: true, roles, ?language},
17
17
  ),
18
18
  ]
19
- | RegistrationChallengeReissued({email, address, reissuedAt, ?invitedBy}) => [
19
+ | RegistrationChallengeReissued({
20
+ emailId,
21
+ email: Value(email),
22
+ reissuedAt,
23
+ ?invitedBy,
24
+ ?language,
25
+ }) => [
20
26
  (
21
- `${email}:reissued:${reissuedAt->Reventless.DateTime.toString}`,
22
- {email, address, alreadyRegistered: false, invited: invitedBy->Option.isSome},
27
+ `${emailId}:reissued:${reissuedAt->Reventless.DateTime.toString}`,
28
+ {emailId, email, alreadyRegistered: false, invited: invitedBy->Option.isSome, ?language},
23
29
  ),
24
30
  ]
25
- | RegistrationAttemptedOnTakenAddress({email, address, attemptedAt}) => [
31
+ | RegistrationAttemptedOnTakenAddress({emailId, email: Value(email), attemptedAt}) => [
26
32
  (
27
- `${email}:taken:${attemptedAt->Reventless.DateTime.toString}`,
28
- {email, address, alreadyRegistered: true},
33
+ `${emailId}:taken:${attemptedAt->Reventless.DateTime.toString}`,
34
+ {emailId, email, alreadyRegistered: true},
29
35
  ),
30
36
  ]
37
+ // An address that was erased or forgotten has nobody left to write to.
38
+ | _ => []
31
39
  }
32
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.",
68
+ }
69
+ let all = [challengeSubject, challengeBody, invitedSubject, invitedBody, takenSubject, takenBody]
70
+ }
71
+
33
72
  let expiresIn = (~invited) =>
34
- RegistrationChallenge.policyFor(
35
- RegistrationChallenge.purposeFor(~invited),
36
- ).tokenTtl->Reventless.Duration.format
73
+ RegistrationChallenge.policyFor(RegistrationChallenge.purposeFor(~invited)).tokenTtl
37
74
 
38
- let challengeBody = (~token) =>
39
- `Your registration code is ${token}. Enter it with a password of your choice to finish. It expires in ${expiresIn(
40
- ~invited=false,
41
- )}.`
75
+ let challengeValues = (~token) =>
76
+ dict{
77
+ "token": Reventless.MessageFormat.Text(token),
78
+ "expiresIn": Duration(expiresIn(~invited=false)),
79
+ }
42
80
 
43
- /** What the invitation grants, as the mail says it: "as Merchandiser", or
44
- nothing where the event did not say. */
45
- let asRoles = (roles: option<array<string>>) =>
46
- switch roles {
47
- | Some([]) | None => ""
48
- | 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),
49
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))
50
96
 
51
97
  let invitationBody = (~token, ~roles=?) =>
52
- `You have been invited to create an account${asRoles(
53
- roles,
54
- )}. Your code is ${token}. Enter it with this address and a password of your choice to accept. It expires in ${expiresIn(
55
- ~invited=true,
56
- )}.`
98
+ Messages.invitedBody->Reventless.Text.inSource(~values=invitationValues(~token, ~roles?))
57
99
 
58
- 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
59
101
 
60
- let send = (capabilities: Reventless.Capabilities.t, ~address, ~subject, ~body) =>
61
- capabilities.messaging.send(~recipient=ToEmail(address), ~message={subject, body})
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,
@@ -68,12 +133,13 @@ let translate = async (_id, item: outboundItem, ~capabilities: Reventless.Capabi
68
133
  if item.alreadyRegistered {
69
134
  switch await send(
70
135
  capabilities,
71
- ~address=item.address,
72
- ~subject="Someone tried to register with your address",
73
- ~body=noticeBody,
136
+ ~email=item.email,
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
- ~address=item.address,
93
- ~subject=invited ? "You are invited to create an account" : "Finish your registration",
94
- ~body=invited ? invitationBody(~token, ~roles=?item.roles) : challengeBody(~token),
159
+ ~email=item.email,
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
  }
@@ -1,7 +1,8 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
3
  import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
4
- import * as Duration$Reventless from "@reventlessdev/reventless-spec/src/semantic/Duration.res.mjs";
4
+ import * as Text$Reventless from "@reventlessdev/reventless-spec/src/i18n/Text.res.mjs";
5
+ import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js";
5
6
  import * as Messaging$Reventless from "@reventlessdev/reventless-spec/src/semantic/Messaging.res.mjs";
6
7
  import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
7
8
  import * as RegistrationChallenge$ReventlessRegistration from "../../RegistrationChallenge.res.mjs";
@@ -10,86 +11,218 @@ function collect(event, param) {
10
11
  switch (event.TAG) {
11
12
  case "RegistrationRequested" :
12
13
  let email = event.email;
13
- return [[
14
- email + `:` + event.requestedAt,
15
- {
16
- email: email,
17
- address: event.address,
18
- alreadyRegistered: false
19
- }
20
- ]];
14
+ let emailId = event.emailId;
15
+ if (typeof email !== "object") {
16
+ if (email === "Erased") {
17
+ return [];
18
+ } else {
19
+ return [];
20
+ }
21
+ } else {
22
+ return [[
23
+ emailId + `:` + event.requestedAt,
24
+ {
25
+ emailId: emailId,
26
+ email: email._0,
27
+ alreadyRegistered: false,
28
+ language: event.language
29
+ }
30
+ ]];
31
+ }
21
32
  case "RegistrationAttemptedOnTakenAddress" :
22
33
  let email$1 = event.email;
23
- return [[
24
- email$1 + `:taken:` + event.attemptedAt,
25
- {
26
- email: email$1,
27
- address: event.address,
28
- alreadyRegistered: true
29
- }
30
- ]];
34
+ let emailId$1 = event.emailId;
35
+ if (typeof email$1 !== "object") {
36
+ if (email$1 === "Erased") {
37
+ return [];
38
+ } else {
39
+ return [];
40
+ }
41
+ } else {
42
+ return [[
43
+ emailId$1 + `:taken:` + event.attemptedAt,
44
+ {
45
+ emailId: emailId$1,
46
+ email: email$1._0,
47
+ alreadyRegistered: true
48
+ }
49
+ ]];
50
+ }
31
51
  case "RegistrationInvited" :
32
52
  let email$2 = event.email;
33
- return [[
34
- email$2 + `:invited:` + event.invitedAt,
35
- {
36
- email: email$2,
37
- address: event.address,
38
- alreadyRegistered: false,
39
- invited: true,
40
- roles: event.roles
41
- }
42
- ]];
53
+ let emailId$2 = event.emailId;
54
+ if (typeof email$2 !== "object") {
55
+ if (email$2 === "Erased") {
56
+ return [];
57
+ } else {
58
+ return [];
59
+ }
60
+ } else {
61
+ return [[
62
+ emailId$2 + `:invited:` + event.invitedAt,
63
+ {
64
+ emailId: emailId$2,
65
+ email: email$2._0,
66
+ alreadyRegistered: false,
67
+ invited: true,
68
+ roles: event.roles,
69
+ language: event.language
70
+ }
71
+ ]];
72
+ }
43
73
  case "RegistrationChallengeReissued" :
44
74
  let email$3 = event.email;
45
- return [[
46
- email$3 + `:reissued:` + event.reissuedAt,
47
- {
48
- email: email$3,
49
- address: event.address,
50
- alreadyRegistered: false,
51
- invited: Stdlib_Option.isSome(event.invitedBy)
52
- }
53
- ]];
75
+ let emailId$3 = event.emailId;
76
+ if (typeof email$3 !== "object") {
77
+ if (email$3 === "Erased") {
78
+ return [];
79
+ } else {
80
+ return [];
81
+ }
82
+ } else {
83
+ return [[
84
+ emailId$3 + `:reissued:` + event.reissuedAt,
85
+ {
86
+ emailId: emailId$3,
87
+ email: email$3._0,
88
+ alreadyRegistered: false,
89
+ invited: Stdlib_Option.isSome(event.invitedBy),
90
+ language: event.language
91
+ }
92
+ ]];
93
+ }
54
94
  }
55
95
  }
56
96
 
97
+ let challengeSubject = {
98
+ key: "registration.challenge.subject",
99
+ source: "Finish your registration"
100
+ };
101
+
102
+ let challengeBody = {
103
+ key: "registration.challenge.body",
104
+ source: "Your registration code is {token}. Enter it with a password of your choice to finish. It expires in {expiresIn}."
105
+ };
106
+
107
+ let invitedSubject = {
108
+ key: "registration.invited.subject",
109
+ source: "You are invited to create an account"
110
+ };
111
+
112
+ let invitedBody = {
113
+ key: "registration.invited.body",
114
+ 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}."
115
+ };
116
+
117
+ let takenSubject = {
118
+ key: "registration.taken.subject",
119
+ source: "Someone tried to register with your address"
120
+ };
121
+
122
+ let takenBody = {
123
+ key: "registration.taken.body",
124
+ 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."
125
+ };
126
+
127
+ let all = [
128
+ challengeSubject,
129
+ challengeBody,
130
+ invitedSubject,
131
+ invitedBody,
132
+ takenSubject,
133
+ takenBody
134
+ ];
135
+
136
+ let Messages = {
137
+ challengeSubject: challengeSubject,
138
+ challengeBody: challengeBody,
139
+ invitedSubject: invitedSubject,
140
+ invitedBody: invitedBody,
141
+ takenSubject: takenSubject,
142
+ takenBody: takenBody,
143
+ all: all
144
+ };
145
+
57
146
  function expiresIn(invited) {
58
- return Duration$Reventless.format(RegistrationChallenge$ReventlessRegistration.policyFor(RegistrationChallenge$ReventlessRegistration.purposeFor(invited)).tokenTtl);
147
+ return RegistrationChallenge$ReventlessRegistration.policyFor(RegistrationChallenge$ReventlessRegistration.purposeFor(invited)).tokenTtl;
59
148
  }
60
149
 
61
- function challengeBody(token) {
62
- return `Your registration code is ` + token + `. Enter it with a password of your choice to finish. It expires in ` + expiresIn(false) + `.`;
150
+ function challengeValues(token) {
151
+ return {
152
+ token: {
153
+ TAG: "Text",
154
+ _0: token
155
+ },
156
+ expiresIn: {
157
+ TAG: "Duration",
158
+ _0: RegistrationChallenge$ReventlessRegistration.policyFor(RegistrationChallenge$ReventlessRegistration.purposeFor(false)).tokenTtl
159
+ }
160
+ };
63
161
  }
64
162
 
65
- function asRoles(roles) {
66
- if (roles !== undefined && roles.length !== 0) {
67
- return ` as ` + roles.join(" and ");
68
- } else {
69
- return "";
70
- }
163
+ function invitationValues(token, roles) {
164
+ let roles$1 = Stdlib_Option.getOr(roles, []);
165
+ return {
166
+ token: {
167
+ TAG: "Text",
168
+ _0: token
169
+ },
170
+ expiresIn: {
171
+ TAG: "Duration",
172
+ _0: RegistrationChallenge$ReventlessRegistration.policyFor(RegistrationChallenge$ReventlessRegistration.purposeFor(true)).tokenTtl
173
+ },
174
+ hasRoles: {
175
+ TAG: "Text",
176
+ _0: Primitive_object.equal(roles$1, []) ? "no" : "yes"
177
+ },
178
+ roles: {
179
+ TAG: "List",
180
+ _0: roles$1
181
+ }
182
+ };
183
+ }
184
+
185
+ function challengeBody$1(token) {
186
+ return Text$Reventless.inSource(challengeBody, challengeValues(token));
71
187
  }
72
188
 
73
189
  function invitationBody(token, roles) {
74
- return `You have been invited to create an account` + asRoles(roles) + `. Your code is ` + token + `. Enter it with this address and a password of your choice to accept. It expires in ` + expiresIn(true) + `.`;
190
+ return Text$Reventless.inSource(invitedBody, invitationValues(token, roles));
75
191
  }
76
192
 
77
- 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.";
193
+ let noticeBody = Text$Reventless.inSource(takenBody, undefined);
78
194
 
79
- function send(capabilities, address, subject, body) {
80
- return capabilities.messaging.send({
195
+ async function send(capabilities, email, requested, subject, body, values) {
196
+ let recipient = {
81
197
  TAG: "ToEmail",
82
- _0: address
83
- }, {
84
- subject: subject,
85
- body: body
86
- });
198
+ _0: email
199
+ };
200
+ let reason = await Text$Reventless.compose(capabilities.text, recipient, requested, subject, body, values);
201
+ if (reason.TAG !== "Ok") {
202
+ return {
203
+ TAG: "Error",
204
+ _0: reason._0
205
+ };
206
+ }
207
+ let message = reason._0;
208
+ let failure = await capabilities.messaging.send(recipient, message);
209
+ if (failure.TAG === "Ok") {
210
+ return {
211
+ TAG: "Ok",
212
+ _0: message.language
213
+ };
214
+ } else {
215
+ return {
216
+ TAG: "Error",
217
+ _0: Messaging$Reventless.failureReason(failure._0)
218
+ };
219
+ }
87
220
  }
88
221
 
89
222
  async function translate(_id, item, capabilities) {
90
223
  if (item.alreadyRegistered) {
91
- let failure = await send(capabilities, item.address, "Someone tried to register with your address", noticeBody);
92
- if (failure.TAG === "Ok") {
224
+ let reason = await send(capabilities, item.email, undefined, takenSubject, takenBody, {});
225
+ if (reason.TAG === "Ok") {
93
226
  return {
94
227
  TAG: "Ok",
95
228
  _0: undefined
@@ -97,7 +230,7 @@ async function translate(_id, item, capabilities) {
97
230
  } else {
98
231
  return {
99
232
  TAG: "Error",
100
- _0: Messaging$Reventless.failureReason(failure._0)
233
+ _0: reason._0
101
234
  };
102
235
  }
103
236
  }
@@ -118,24 +251,27 @@ async function translate(_id, item, capabilities) {
118
251
  _0: `cannot hash a secret: ` + proofHash._0._0
119
252
  };
120
253
  }
121
- let failure$1 = await send(capabilities, item.address, invited ? "You are invited to create an account" : "Finish your registration", invited ? invitationBody(token$1, item.roles) : challengeBody(token$1));
122
- if (failure$1.TAG === "Ok") {
254
+ let body = invited ? invitedBody : challengeBody;
255
+ let language = await send(capabilities, item.email, item.language, invited ? invitedSubject : challengeSubject, body, invited ? invitationValues(token$1, item.roles) : challengeValues(token$1));
256
+ if (language.TAG === "Ok") {
123
257
  return {
124
258
  TAG: "Ok",
125
259
  _0: [
126
- item.email,
260
+ item.emailId,
127
261
  {
128
262
  TAG: "IssueRegistrationChallenge",
129
- email: ContactAddressId$ReventlessRegistration.makeFromString(item.email),
263
+ emailId: ContactAddressId$ReventlessRegistration.makeFromString(item.emailId),
130
264
  proofHash: proofHash._0,
131
- issuedAt: new Date().toISOString()
265
+ issuedAt: new Date().toISOString(),
266
+ language: language._0,
267
+ messageKey: body.key
132
268
  }
133
269
  ]
134
270
  };
135
271
  } else {
136
272
  return {
137
273
  TAG: "Error",
138
- _0: Messaging$Reventless.failureReason(failure$1._0)
274
+ _0: language._0
139
275
  };
140
276
  }
141
277
  }
@@ -151,9 +287,11 @@ let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/Outboun
151
287
  export {
152
288
  Spec,
153
289
  collect,
290
+ Messages,
154
291
  expiresIn,
155
- challengeBody,
156
- asRoles,
292
+ challengeValues,
293
+ invitationValues,
294
+ challengeBody$1 as challengeBody,
157
295
  invitationBody,
158
296
  noticeBody,
159
297
  send,
@@ -161,4 +299,4 @@ export {
161
299
  onExhausted,
162
300
  moduleUrl,
163
301
  }
164
- /* Duration-Reventless Not a pure module */
302
+ /* noticeBody Not a pure module */
@@ -56,3 +56,6 @@ type event =
56
56
  | RegistrationClosed({
57
57
  role: @s.matches(Reventless.DcbTag.mark(Reventless.Role.nameSchema)) Reventless.Role.name,
58
58
  })
59
+
60
+ /** This decision opens and closes a role; the platform tells the shell so. */
61
+ let admissionDoor = Reventless.Admission.Policy
@@ -65,6 +65,8 @@ let name = "RegistrationPolicy";
65
65
 
66
66
  let Id;
67
67
 
68
+ let admissionDoor = "policy";
69
+
68
70
  let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/StateChange/RegistrationPolicy.res.mjs";
69
71
 
70
72
  let readConsistency = "EscalateOnRetry";
@@ -77,6 +79,7 @@ export {
77
79
  commandSchema,
78
80
  errorSchema,
79
81
  eventSchema,
82
+ admissionDoor,
80
83
  moduleUrl,
81
84
  authorizationOf,
82
85
  readConsistency,