@reventlessdev/reventless-registration 1.0.0-alpha.3 → 1.0.0-alpha.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/i18n/en.json +8 -0
- package/package.json +7 -6
- package/src/Registration/ContactAddressId.res +27 -3
- package/src/Registration/ContactAddressId.res.mjs +26 -2
- package/src/Registration/InboundTranslation/CompleteRegistration.res +2 -2
- package/src/Registration/InboundTranslation/CompleteRegistration.res.mjs +3 -3
- package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res +9 -6
- package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res.mjs +16 -9
- package/src/Registration/InboundTranslation/SignUp.res +6 -3
- package/src/Registration/InboundTranslation/SignUp.res.mjs +11 -5
- package/src/Registration/InboundTranslation/SignUp_Translation.res +34 -13
- package/src/Registration/InboundTranslation/SignUp_Translation.res.mjs +26 -5
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res +9 -3
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res.mjs +7 -3
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res +10 -7
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res.mjs +17 -8
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res +36 -7
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res.mjs +24 -11
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res +115 -44
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res.mjs +203 -61
- package/src/Registration/StateChange/Registrations.res +76 -27
- package/src/Registration/StateChange/Registrations.res.mjs +83 -39
- package/src/Registration/StateChange/Registrations_Decision.res +74 -26
- package/src/Registration/StateChange/Registrations_Decision.res.mjs +106 -47
- package/src/Registration/StateViewStream/RegistrationWindows.res.mjs +1 -1
|
@@ -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({
|
|
19
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 = {
|
|
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
|
-
|
|
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
|
|
@@ -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
|
-
|
|
12
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 = [];
|
|
@@ -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
|
-
(
|
|
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
|
-
`${
|
|
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({
|
|
19
|
+
| RegistrationChallengeReissued({
|
|
20
|
+
emailId,
|
|
21
|
+
email: Value(email),
|
|
22
|
+
reissuedAt,
|
|
23
|
+
?invitedBy,
|
|
24
|
+
?language,
|
|
25
|
+
}) => [
|
|
17
26
|
(
|
|
18
|
-
`${
|
|
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
|
-
`${
|
|
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
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
42
|
-
let
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
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 =
|
|
100
|
+
let noticeBody = Messages.takenBody->Reventless.Text.inSource
|
|
56
101
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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=
|
|
73
|
-
~body=
|
|
137
|
+
~subject=Messages.takenSubject,
|
|
138
|
+
~body=Messages.takenBody,
|
|
139
|
+
~values=Dict.make(),
|
|
74
140
|
) {
|
|
75
141
|
| Ok(_) => Ok(None)
|
|
76
|
-
| Error(
|
|
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
|
-
~
|
|
94
|
-
~
|
|
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.
|
|
168
|
+
item.emailId,
|
|
100
169
|
IssueRegistrationChallenge({
|
|
101
|
-
|
|
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(
|
|
178
|
+
| Error(reason) => Error(reason)
|
|
108
179
|
}
|
|
109
180
|
}
|
|
110
181
|
}
|