@reventlessdev/reventless-registration 1.0.0-alpha.2 → 1.0.0-alpha.20
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/package.json +4 -4
- package/src/Registration/ContactAddressId.res +27 -3
- package/src/Registration/ContactAddressId.res.mjs +26 -2
- 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 +1 -0
- package/src/Registration/InboundTranslation/SignUp.res.mjs +3 -0
- package/src/Registration/InboundTranslation/SignUp_Translation.res +23 -12
- package/src/Registration/InboundTranslation/SignUp_Translation.res.mjs +13 -4
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res +7 -1
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res.mjs +4 -0
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res +6 -3
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res.mjs +11 -2
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res +24 -3
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res.mjs +7 -0
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res +17 -15
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res.mjs +75 -35
- package/src/Registration/StateChange/Registrations.res +33 -2
- package/src/Registration/StateChange/Registrations.res.mjs +31 -1
- package/src/Registration/StateChange/Registrations_Decision.res +54 -13
- package/src/Registration/StateChange/Registrations_Decision.res.mjs +75 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reventlessdev/reventless-registration",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.20",
|
|
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": [
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"sury": "11.0.0",
|
|
15
15
|
"sury-ppx": "11.0.0",
|
|
16
|
-
"@reventlessdev/reventless-
|
|
17
|
-
"@reventlessdev/reventless-
|
|
18
|
-
"@reventlessdev/reventless-spec": "3.0.0-alpha.
|
|
16
|
+
"@reventlessdev/reventless-ppx": "1.0.0-alpha.111",
|
|
17
|
+
"@reventlessdev/reventless-infra": "3.0.0-alpha.223",
|
|
18
|
+
"@reventlessdev/reventless-spec": "3.0.0-alpha.194"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"rescript": "12.3.1"
|
|
@@ -1,6 +1,30 @@
|
|
|
1
|
-
// The address a registration claims
|
|
2
|
-
// decides about, and the tag that makes "this address is taken" one fact on
|
|
3
|
-
//
|
|
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 */
|
|
@@ -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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
33
|
+
id->ContactAddressId.toString,
|
|
31
34
|
SubmitRegistrationProof({
|
|
32
|
-
email:
|
|
35
|
+
email: 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
|
|
22
|
-
let
|
|
23
|
-
if (
|
|
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:
|
|
26
|
+
_0: match._0
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
-
let
|
|
30
|
-
|
|
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
|
-
|
|
42
|
+
ContactAddressId$ReventlessRegistration.toString(id),
|
|
36
43
|
{
|
|
37
44
|
TAG: "SubmitRegistrationProof",
|
|
38
|
-
email:
|
|
39
|
-
proofHash: proofHash
|
|
45
|
+
email: id,
|
|
46
|
+
proofHash: proofHash,
|
|
40
47
|
presentedAt: new Date().toISOString()
|
|
41
48
|
}
|
|
42
49
|
]]
|
|
@@ -1,7 +1,9 @@
|
|
|
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";
|
|
7
9
|
import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
|
|
@@ -14,6 +16,7 @@ let externalInputSchema = Sury.$schema(s => ({
|
|
|
14
16
|
let commandSchema = Sury.$schema(s => ({
|
|
15
17
|
TAG: "Register",
|
|
16
18
|
email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
19
|
+
address: s.m(Pii$Reventless.mark("email", undefined, Email$Reventless.schema)),
|
|
17
20
|
role: s.m(Role$Reventless.nameSchema),
|
|
18
21
|
requestedAt: s.m(DateTime$Reventless.schema)
|
|
19
22
|
}));
|
|
@@ -13,7 +13,11 @@ module Make = (App: Reventless.Admission.Declaration) => {
|
|
|
13
13
|
module Spec = Spec
|
|
14
14
|
let moduleUrl = moduleUrl
|
|
15
15
|
|
|
16
|
-
let translate = async (
|
|
16
|
+
let translate = async (
|
|
17
|
+
input: externalInput,
|
|
18
|
+
~capabilities: Reventless.Capabilities.t,
|
|
19
|
+
~caller as _,
|
|
20
|
+
) =>
|
|
17
21
|
switch (Reventless.Email.fromString(input.email->String.trim), input.role) {
|
|
18
22
|
| (Error(_), _) => Error("not an email address")
|
|
19
23
|
| (Ok(email), role) =>
|
|
@@ -24,17 +28,24 @@ module Make = (App: Reventless.Admission.Declaration) => {
|
|
|
24
28
|
->Option.orElse(defaultRole(App.table)) {
|
|
25
29
|
| None => Error("say which role to sign up for")
|
|
26
30
|
| Some(role) =>
|
|
27
|
-
let
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
let address = email->ContactAddressId.normalize
|
|
32
|
+
switch ContactAddressId.fingerprint(capabilities.secrets, address) {
|
|
33
|
+
| Error(why) => Error(why)
|
|
34
|
+
| Ok(id) =>
|
|
35
|
+
// The envelope id is the fingerprint too: an id is stored beside the
|
|
36
|
+
// event, where the address must not be.
|
|
37
|
+
Ok([
|
|
38
|
+
(
|
|
39
|
+
id->ContactAddressId.toString,
|
|
40
|
+
Register({
|
|
41
|
+
email: id,
|
|
42
|
+
address,
|
|
43
|
+
role,
|
|
44
|
+
requestedAt: Date.make()->Date.toISOString->Reventless.DateTime.unsafe,
|
|
45
|
+
}),
|
|
46
|
+
),
|
|
47
|
+
])
|
|
48
|
+
}
|
|
38
49
|
}
|
|
39
50
|
}
|
|
40
51
|
}
|
|
@@ -16,7 +16,7 @@ function defaultRole(table) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
function Make(App) {
|
|
19
|
-
let translate = async (input,
|
|
19
|
+
let translate = async (input, capabilities, param) => {
|
|
20
20
|
let match = Email$Reventless.fromString(input.email.trim());
|
|
21
21
|
let match$1 = input.role;
|
|
22
22
|
if (match.TAG !== "Ok") {
|
|
@@ -32,14 +32,23 @@ function Make(App) {
|
|
|
32
32
|
_0: "say which role to sign up for"
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
let
|
|
35
|
+
let address = ContactAddressId$ReventlessRegistration.normalize(match._0);
|
|
36
|
+
let why = ContactAddressId$ReventlessRegistration.fingerprint(capabilities.secrets, address);
|
|
37
|
+
if (why.TAG !== "Ok") {
|
|
38
|
+
return {
|
|
39
|
+
TAG: "Error",
|
|
40
|
+
_0: why._0
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
let id = why._0;
|
|
36
44
|
return {
|
|
37
45
|
TAG: "Ok",
|
|
38
46
|
_0: [[
|
|
39
|
-
|
|
47
|
+
ContactAddressId$ReventlessRegistration.toString(id),
|
|
40
48
|
{
|
|
41
49
|
TAG: "Register",
|
|
42
|
-
email:
|
|
50
|
+
email: id,
|
|
51
|
+
address: address,
|
|
43
52
|
role: role,
|
|
44
53
|
requestedAt: new Date().toISOString()
|
|
45
54
|
}
|
|
@@ -16,12 +16,18 @@
|
|
|
16
16
|
type consumedEvent =
|
|
17
17
|
| RegistrationProofAccepted({
|
|
18
18
|
email: string,
|
|
19
|
+
@pii({subject: "email"}) address: Reventless.Email.t,
|
|
19
20
|
roles: array<Reventless.Role.name>,
|
|
20
21
|
proofHash: string,
|
|
21
22
|
})
|
|
22
23
|
|
|
23
24
|
@schema
|
|
24
|
-
type outboundItem = {
|
|
25
|
+
type outboundItem = {
|
|
26
|
+
email: string,
|
|
27
|
+
@pii({subject: "email"}) address: Reventless.Email.t,
|
|
28
|
+
roles: array<Reventless.Role.name>,
|
|
29
|
+
proofHash: string,
|
|
30
|
+
}
|
|
25
31
|
|
|
26
32
|
@schema
|
|
27
33
|
type inboundCommand = RecordRegistrationCompleted({email: ContactAddressId.t})
|
|
@@ -1,19 +1,23 @@
|
|
|
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
12
|
email: s.m(Sury.string),
|
|
13
|
+
address: s.m(Pii$Reventless.marked("email", 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
19
|
email: s.m(Sury.string),
|
|
20
|
+
address: s.m(Pii$Reventless.mark("email", undefined, Email$Reventless.schema)),
|
|
17
21
|
roles: s.m(Sury.array(Role$Reventless.nameSchema)),
|
|
18
22
|
proofHash: s.m(Sury.string)
|
|
19
23
|
}));
|
|
@@ -9,11 +9,14 @@ 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({email, address: Value(address), roles, proofHash}) => [
|
|
13
|
+
(`${email}:${proofHash}`, {email, address, roles, proofHash}),
|
|
14
14
|
]
|
|
15
|
+
// An address that was erased or forgotten has nobody left to write to.
|
|
16
|
+
| _ => []
|
|
15
17
|
}
|
|
16
18
|
|
|
19
|
+
// `email` is already the ledger's id for the address: no key is needed to say so.
|
|
17
20
|
let completed = (email: string) => Ok(
|
|
18
21
|
Some((email, RecordRegistrationCompleted({email: ContactAddressId.makeFromString(email)}))),
|
|
19
22
|
)
|
|
@@ -26,7 +29,7 @@ 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(
|
|
32
|
+
~contact=ToEmail(item.address),
|
|
30
33
|
~credential=Password(password),
|
|
31
34
|
~groups=groupsOf(item.roles),
|
|
32
35
|
) {
|
|
@@ -9,12 +9,21 @@ function groupsOf(roles) {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
function collect(event, param) {
|
|
12
|
-
let
|
|
12
|
+
let address = event.address;
|
|
13
13
|
let email = event.email;
|
|
14
|
+
if (typeof address !== "object") {
|
|
15
|
+
if (address === "Erased") {
|
|
16
|
+
return [];
|
|
17
|
+
} else {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
let proofHash = event.proofHash;
|
|
14
22
|
return [[
|
|
15
23
|
email + `:` + proofHash,
|
|
16
24
|
{
|
|
17
25
|
email: email,
|
|
26
|
+
address: address._0,
|
|
18
27
|
roles: event.roles,
|
|
19
28
|
proofHash: proofHash
|
|
20
29
|
}
|
|
@@ -51,7 +60,7 @@ async function translate(_id, item, capabilities) {
|
|
|
51
60
|
}
|
|
52
61
|
let match = await capabilities.identityProvider.createPrincipal({
|
|
53
62
|
TAG: "ToEmail",
|
|
54
|
-
_0: item.
|
|
63
|
+
_0: item.address
|
|
55
64
|
}, {
|
|
56
65
|
TAG: "Password",
|
|
57
66
|
_0: password
|
|
@@ -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,25 +18,43 @@
|
|
|
15
18
|
|
|
16
19
|
@schema
|
|
17
20
|
type consumedEvent =
|
|
18
|
-
| RegistrationRequested({
|
|
19
|
-
|
|
21
|
+
| RegistrationRequested({
|
|
22
|
+
email: string,
|
|
23
|
+
@pii({subject: "email"}) address: Reventless.Email.t,
|
|
24
|
+
requestedAt: Reventless.DateTime.t,
|
|
25
|
+
})
|
|
26
|
+
| RegistrationAttemptedOnTakenAddress({
|
|
27
|
+
email: string,
|
|
28
|
+
@pii({subject: "email"}) address: Reventless.Email.t,
|
|
29
|
+
attemptedAt: Reventless.DateTime.t,
|
|
30
|
+
})
|
|
20
31
|
| RegistrationInvited({
|
|
21
32
|
email: string,
|
|
33
|
+
@pii({subject: "email"}) address: Reventless.Email.t,
|
|
22
34
|
roles: array<string>,
|
|
23
35
|
invitedBy: string,
|
|
24
36
|
invitedAt: Reventless.DateTime.t,
|
|
25
37
|
})
|
|
26
38
|
| RegistrationChallengeReissued({
|
|
27
39
|
email: string,
|
|
40
|
+
@pii({subject: "email"}) address: Reventless.Email.t,
|
|
28
41
|
reissuedAt: Reventless.DateTime.t,
|
|
29
42
|
invitedBy?: string,
|
|
30
43
|
})
|
|
31
44
|
|
|
45
|
+
// `email` is the ledger's id for the address, `address` the address the mail goes to.
|
|
46
|
+
|
|
32
47
|
/** `invited` words the secret as an invitation; it is left out for a sign-up
|
|
33
48
|
and for the notice. `roles` names what the invitation grants, where the
|
|
34
49
|
event said: a reissued code does not. */
|
|
35
50
|
@schema
|
|
36
|
-
type outboundItem = {
|
|
51
|
+
type outboundItem = {
|
|
52
|
+
email: string,
|
|
53
|
+
@pii({subject: "email"}) address: Reventless.Email.t,
|
|
54
|
+
alreadyRegistered: bool,
|
|
55
|
+
invited?: bool,
|
|
56
|
+
roles?: array<string>,
|
|
57
|
+
}
|
|
37
58
|
|
|
38
59
|
@schema
|
|
39
60
|
type inboundCommand =
|
|
@@ -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";
|
|
@@ -9,16 +11,19 @@ let consumedEventSchema = Sury.union([
|
|
|
9
11
|
Sury.$schema(s => ({
|
|
10
12
|
TAG: "RegistrationRequested",
|
|
11
13
|
email: s.m(Sury.string),
|
|
14
|
+
address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
|
|
12
15
|
requestedAt: s.m(DateTime$Reventless.schema)
|
|
13
16
|
})),
|
|
14
17
|
Sury.$schema(s => ({
|
|
15
18
|
TAG: "RegistrationAttemptedOnTakenAddress",
|
|
16
19
|
email: s.m(Sury.string),
|
|
20
|
+
address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
|
|
17
21
|
attemptedAt: s.m(DateTime$Reventless.schema)
|
|
18
22
|
})),
|
|
19
23
|
Sury.$schema(s => ({
|
|
20
24
|
TAG: "RegistrationInvited",
|
|
21
25
|
email: s.m(Sury.string),
|
|
26
|
+
address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
|
|
22
27
|
roles: s.m(Sury.array(Sury.string)),
|
|
23
28
|
invitedBy: s.m(Sury.string),
|
|
24
29
|
invitedAt: s.m(DateTime$Reventless.schema)
|
|
@@ -26,6 +31,7 @@ let consumedEventSchema = Sury.union([
|
|
|
26
31
|
Sury.$schema(s => ({
|
|
27
32
|
TAG: "RegistrationChallengeReissued",
|
|
28
33
|
email: s.m(Sury.string),
|
|
34
|
+
address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
|
|
29
35
|
reissuedAt: s.m(DateTime$Reventless.schema),
|
|
30
36
|
invitedBy: s.m(Sury.$option(Sury.string))
|
|
31
37
|
}))
|
|
@@ -33,6 +39,7 @@ let consumedEventSchema = Sury.union([
|
|
|
33
39
|
|
|
34
40
|
let outboundItemSchema = Sury.$schema(s => ({
|
|
35
41
|
email: s.m(Sury.string),
|
|
42
|
+
address: s.m(Pii$Reventless.mark("email", undefined, Email$Reventless.schema)),
|
|
36
43
|
alreadyRegistered: s.m(Sury.boolean),
|
|
37
44
|
invited: s.m(Sury.$option(Sury.boolean)),
|
|
38
45
|
roles: s.m(Sury.$option(Sury.array(Sury.string)))
|
|
@@ -4,27 +4,32 @@
|
|
|
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({email, address: Value(address), requestedAt}) => [
|
|
8
|
+
(
|
|
9
|
+
`${email}:${requestedAt->Reventless.DateTime.toString}`,
|
|
10
|
+
{email, address, alreadyRegistered: false},
|
|
11
|
+
),
|
|
9
12
|
]
|
|
10
|
-
| RegistrationInvited({email, roles, invitedAt}) => [
|
|
13
|
+
| RegistrationInvited({email, address: Value(address), roles, invitedAt}) => [
|
|
11
14
|
(
|
|
12
15
|
`${email}:invited:${invitedAt->Reventless.DateTime.toString}`,
|
|
13
|
-
{email, alreadyRegistered: false, invited: true, roles},
|
|
16
|
+
{email, address, alreadyRegistered: false, invited: true, roles},
|
|
14
17
|
),
|
|
15
18
|
]
|
|
16
|
-
| RegistrationChallengeReissued({email, reissuedAt, ?invitedBy}) => [
|
|
19
|
+
| RegistrationChallengeReissued({email, address: Value(address), reissuedAt, ?invitedBy}) => [
|
|
17
20
|
(
|
|
18
21
|
`${email}:reissued:${reissuedAt->Reventless.DateTime.toString}`,
|
|
19
|
-
{email, alreadyRegistered: false, invited: invitedBy->Option.isSome},
|
|
22
|
+
{email, address, alreadyRegistered: false, invited: invitedBy->Option.isSome},
|
|
20
23
|
),
|
|
21
24
|
]
|
|
22
|
-
| RegistrationAttemptedOnTakenAddress({email, attemptedAt}) => [
|
|
25
|
+
| RegistrationAttemptedOnTakenAddress({email, address: Value(address), attemptedAt}) => [
|
|
23
26
|
(
|
|
24
27
|
`${email}:taken:${attemptedAt->Reventless.DateTime.toString}`,
|
|
25
|
-
{email, alreadyRegistered: true},
|
|
28
|
+
{email, address, alreadyRegistered: true},
|
|
26
29
|
),
|
|
27
30
|
]
|
|
31
|
+
// An address that was erased or forgotten has nobody left to write to.
|
|
32
|
+
| _ => []
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
let expiresIn = (~invited) =>
|
|
@@ -54,11 +59,8 @@ let invitationBody = (~token, ~roles=?) =>
|
|
|
54
59
|
|
|
55
60
|
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."
|
|
56
61
|
|
|
57
|
-
let send = (capabilities: Reventless.Capabilities.t, ~
|
|
58
|
-
capabilities.messaging.send(
|
|
59
|
-
~recipient=ToEmail(Reventless.Email.unsafe(email)),
|
|
60
|
-
~message={subject, body},
|
|
61
|
-
)
|
|
62
|
+
let send = (capabilities: Reventless.Capabilities.t, ~address, ~subject, ~body) =>
|
|
63
|
+
capabilities.messaging.send(~recipient=ToEmail(address), ~message={subject, body})
|
|
62
64
|
|
|
63
65
|
/**
|
|
64
66
|
Draw a secret, send it, and open a challenge against its hash — sending first,
|
|
@@ -68,7 +70,7 @@ let translate = async (_id, item: outboundItem, ~capabilities: Reventless.Capabi
|
|
|
68
70
|
if item.alreadyRegistered {
|
|
69
71
|
switch await send(
|
|
70
72
|
capabilities,
|
|
71
|
-
~
|
|
73
|
+
~address=item.address,
|
|
72
74
|
~subject="Someone tried to register with your address",
|
|
73
75
|
~body=noticeBody,
|
|
74
76
|
) {
|
|
@@ -89,7 +91,7 @@ let translate = async (_id, item: outboundItem, ~capabilities: Reventless.Capabi
|
|
|
89
91
|
| Ok(proofHash) =>
|
|
90
92
|
switch await send(
|
|
91
93
|
capabilities,
|
|
92
|
-
~
|
|
94
|
+
~address=item.address,
|
|
93
95
|
~subject=invited ? "You are invited to create an account" : "Finish your registration",
|
|
94
96
|
~body=invited ? invitationBody(~token, ~roles=?item.roles) : challengeBody(~token),
|
|
95
97
|
) {
|