@reventlessdev/reventless-registration 1.0.0-alpha.3 → 1.0.0-alpha.31
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
package/README.md
CHANGED
|
@@ -44,6 +44,16 @@ Reventless.Admission.Invite`, checks the inviter's roles, and relays `Invite` to
|
|
|
44
44
|
ledger. The ledger refuses any role the app's table does not declare by invitation.
|
|
45
45
|
An invitation's code holds a week; a sign-up's holds a day.
|
|
46
46
|
|
|
47
|
+
The mails are written in the recipient's language where the deployment has the words:
|
|
48
|
+
their keys are `registration.*`, and `i18n/en.json` holds their English. A deployment
|
|
49
|
+
lists `node_modules/@reventlessdev/reventless-registration/i18n` among its catalogue
|
|
50
|
+
sources, before its own, and translates the keys there. Without a translation the
|
|
51
|
+
mails go out in that English. A sign-up may say which language the visitor reads
|
|
52
|
+
(`language`, a tag such as `de`); the codes for that registration are written in it
|
|
53
|
+
where the deployment offers it, unless the address already holds an account, whose
|
|
54
|
+
own language wins. The ledger records the language and the key of the mail each code
|
|
55
|
+
went out in.
|
|
56
|
+
|
|
47
57
|
The scenarios that pin these slices run in the plugins that list them, against that
|
|
48
58
|
plugin's own table: in this repository, `examples/online-shop-hybrid/registration`.
|
|
49
59
|
|
package/i18n/en.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"registration.challenge.body": "Your registration code is {token}. Enter it with a password of your choice to finish. It expires in {expiresIn}.",
|
|
3
|
+
"registration.challenge.subject": "Finish your registration",
|
|
4
|
+
"registration.invited.body": "You have been invited to create an account{hasRoles, select, yes { as {roles}} other {}}. Your code is {token}. Enter it with this address and a password of your choice to accept. It expires in {expiresIn}.",
|
|
5
|
+
"registration.invited.subject": "You are invited to create an account",
|
|
6
|
+
"registration.taken.body": "Someone asked to register an account with this address, which already has one. If it was you, sign in instead. If it was not, there is nothing to do: no account was changed.",
|
|
7
|
+
"registration.taken.subject": "Someone tried to register with your address"
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reventlessdev/reventless-registration",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.31",
|
|
4
4
|
"description": "Self-registration as a library of slices: a person with no account proves control of an address and ends up with one, admitted per role as the app declares",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"files": [
|
|
7
7
|
"src/**/*.res",
|
|
8
8
|
"src/**/*.resi",
|
|
9
9
|
"src/**/*.res.mjs",
|
|
10
|
+
"i18n/*.json",
|
|
10
11
|
"rescript.json",
|
|
11
12
|
"README.md"
|
|
12
13
|
],
|
|
13
14
|
"dependencies": {
|
|
14
|
-
"sury": "11.
|
|
15
|
-
"sury-ppx": "11.
|
|
16
|
-
"@reventlessdev/reventless-infra": "3.0.0-alpha.
|
|
17
|
-
"@reventlessdev/reventless-ppx": "1.0.0-alpha.
|
|
18
|
-
"@reventlessdev/reventless-spec": "3.0.0-alpha.
|
|
15
|
+
"sury": "11.1.0",
|
|
16
|
+
"sury-ppx": "11.1.0",
|
|
17
|
+
"@reventlessdev/reventless-infra": "3.0.0-alpha.233",
|
|
18
|
+
"@reventlessdev/reventless-ppx": "1.0.0-alpha.114",
|
|
19
|
+
"@reventlessdev/reventless-spec": "3.0.0-alpha.202"
|
|
19
20
|
},
|
|
20
21
|
"devDependencies": {
|
|
21
22
|
"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 */
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
@schema
|
|
17
17
|
type externalInput = {
|
|
18
|
-
email: string,
|
|
18
|
+
@sensitive email: string,
|
|
19
19
|
@sensitive proof: string,
|
|
20
20
|
@sensitive password: string,
|
|
21
21
|
}
|
|
@@ -23,7 +23,7 @@ type externalInput = {
|
|
|
23
23
|
@schema
|
|
24
24
|
type command =
|
|
25
25
|
| SubmitRegistrationProof({
|
|
26
|
-
|
|
26
|
+
emailId: ContactAddressId.t,
|
|
27
27
|
proofHash: string,
|
|
28
28
|
presentedAt: Reventless.DateTime.t,
|
|
29
29
|
})
|
|
@@ -7,14 +7,14 @@ import * as Sensitive$Reventless from "@reventlessdev/reventless-spec/src/compon
|
|
|
7
7
|
import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
|
|
8
8
|
|
|
9
9
|
let externalInputSchema = Sury.$schema(s => ({
|
|
10
|
-
email: s.m(
|
|
10
|
+
email: s.m(Sensitive$Reventless.string),
|
|
11
11
|
proof: s.m(Sensitive$Reventless.string),
|
|
12
12
|
password: s.m(Sensitive$Reventless.string)
|
|
13
13
|
}));
|
|
14
14
|
|
|
15
15
|
let commandSchema = Sury.$schema(s => ({
|
|
16
16
|
TAG: "SubmitRegistrationProof",
|
|
17
|
-
|
|
17
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
18
18
|
proofHash: s.m(Sury.string),
|
|
19
19
|
presentedAt: s.m(DateTime$Reventless.schema)
|
|
20
20
|
}));
|
|
@@ -33,7 +33,7 @@ let Id;
|
|
|
33
33
|
|
|
34
34
|
let targetName = "Registrations";
|
|
35
35
|
|
|
36
|
-
let admissionDoor = "
|
|
36
|
+
let admissionDoor = "complete";
|
|
37
37
|
|
|
38
38
|
let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/InboundTranslation/CompleteRegistration.res.mjs";
|
|
39
39
|
|
|
@@ -17,19 +17,22 @@ let translate = async (
|
|
|
17
17
|
| Ok(_) if input.password->String.length < minimumPasswordLength =>
|
|
18
18
|
Error(`a password needs at least ${minimumPasswordLength->Int.toString} characters`)
|
|
19
19
|
| Ok(email) =>
|
|
20
|
-
|
|
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
|
-
|
|
35
|
+
emailId: id,
|
|
33
36
|
proofHash,
|
|
34
37
|
presentedAt: Date.make()->Date.toISOString->Reventless.DateTime.unsafe,
|
|
35
38
|
}),
|
|
@@ -18,25 +18,32 @@ async function translate(input, capabilities, param) {
|
|
|
18
18
|
_0: `a password needs at least ` + (12).toString() + ` characters`
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
-
let
|
|
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
|
-
|
|
39
|
-
proofHash: proofHash
|
|
45
|
+
emailId: id,
|
|
46
|
+
proofHash: proofHash,
|
|
40
47
|
presentedAt: new Date().toISOString()
|
|
41
48
|
}
|
|
42
49
|
]]
|
|
@@ -16,16 +16,19 @@
|
|
|
16
16
|
@@reventless.authorize(AllowAnonymous)
|
|
17
17
|
|
|
18
18
|
/** `role` may be left out where exactly one role is open to visitors; with
|
|
19
|
-
several, a sign-up has to say which.
|
|
19
|
+
several, a sign-up has to say which. `language` is the one the visitor reads the
|
|
20
|
+
shell in, which their mails are written in where the deployment offers it. */
|
|
20
21
|
@schema
|
|
21
|
-
type externalInput = {email: string, role?: string}
|
|
22
|
+
type externalInput = {@sensitive email: string, role?: string, language?: string}
|
|
22
23
|
|
|
23
24
|
@schema
|
|
24
25
|
type command =
|
|
25
26
|
| Register({
|
|
26
|
-
|
|
27
|
+
emailId: ContactAddressId.t,
|
|
28
|
+
@pii({subject: "emailId"}) email: Reventless.Email.t,
|
|
27
29
|
role: Reventless.Role.name,
|
|
28
30
|
requestedAt: Reventless.DateTime.t,
|
|
31
|
+
language?: string,
|
|
29
32
|
})
|
|
30
33
|
|
|
31
34
|
let targetName = "Registrations"
|
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as Sury from "sury";
|
|
4
|
+
import * as Pii$Reventless from "@reventlessdev/reventless-spec/src/components/Pii.res.mjs";
|
|
4
5
|
import * as Role$Reventless from "@reventlessdev/reventless-spec/src/types/Role.res.mjs";
|
|
6
|
+
import * as Email$Reventless from "@reventlessdev/reventless-spec/src/semantic/Email.res.mjs";
|
|
5
7
|
import * as DcbTag$Reventless from "@reventlessdev/reventless-spec/src/components/DcbTag.res.mjs";
|
|
6
8
|
import * as DateTime$Reventless from "@reventlessdev/reventless-spec/src/semantic/DateTime.res.mjs";
|
|
9
|
+
import * as Sensitive$Reventless from "@reventlessdev/reventless-spec/src/components/Sensitive.res.mjs";
|
|
7
10
|
import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
|
|
8
11
|
|
|
9
12
|
let externalInputSchema = Sury.$schema(s => ({
|
|
10
|
-
email: s.m(
|
|
11
|
-
role: s.m(Sury.$option(Sury.string))
|
|
13
|
+
email: s.m(Sensitive$Reventless.string),
|
|
14
|
+
role: s.m(Sury.$option(Sury.string)),
|
|
15
|
+
language: s.m(Sury.$option(Sury.string))
|
|
12
16
|
}));
|
|
13
17
|
|
|
14
18
|
let commandSchema = Sury.$schema(s => ({
|
|
15
19
|
TAG: "Register",
|
|
16
|
-
|
|
20
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
21
|
+
email: s.m(Pii$Reventless.mark("emailId", undefined, Email$Reventless.schema)),
|
|
17
22
|
role: s.m(Role$Reventless.nameSchema),
|
|
18
|
-
requestedAt: s.m(DateTime$Reventless.schema)
|
|
23
|
+
requestedAt: s.m(DateTime$Reventless.schema),
|
|
24
|
+
language: s.m(Sury.$option(Sury.string))
|
|
19
25
|
}));
|
|
20
26
|
|
|
21
27
|
let capabilityNeeds = [];
|
|
@@ -32,7 +38,7 @@ let Id;
|
|
|
32
38
|
|
|
33
39
|
let targetName = "Registrations";
|
|
34
40
|
|
|
35
|
-
let admissionDoor = "
|
|
41
|
+
let admissionDoor = "start";
|
|
36
42
|
|
|
37
43
|
let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/InboundTranslation/SignUp.res.mjs";
|
|
38
44
|
|
|
@@ -8,15 +8,28 @@ let defaultRole = (table: Reventless.Admission.t): option<Reventless.Role.name>
|
|
|
8
8
|
| _ => None
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
/** A language tag as a request gave it, or none where it does not look like one: it only
|
|
12
|
+
picks the words of a mail, so a malformed one is dropped rather than refused. */
|
|
13
|
+
let languageOf = (raw: option<string>): option<string> =>
|
|
14
|
+
raw
|
|
15
|
+
->Option.map(String.trim)
|
|
16
|
+
->Option.filter(tag =>
|
|
17
|
+
String.length(tag) <= 35 && /^[A-Za-z]{2,3}(-[A-Za-z0-9]{1,8})*$/->RegExp.test(tag)
|
|
18
|
+
)
|
|
19
|
+
|
|
11
20
|
/** The door over the app's table, which picks the role a sign-up may leave out. */
|
|
12
21
|
module Make = (App: Reventless.Admission.Declaration) => {
|
|
13
22
|
module Spec = Spec
|
|
14
23
|
let moduleUrl = moduleUrl
|
|
15
24
|
|
|
16
|
-
let translate = async (
|
|
25
|
+
let translate = async (
|
|
26
|
+
input: externalInput,
|
|
27
|
+
~capabilities: Reventless.Capabilities.t,
|
|
28
|
+
~caller as _,
|
|
29
|
+
) =>
|
|
17
30
|
switch (Reventless.Email.fromString(input.email->String.trim), input.role) {
|
|
18
31
|
| (Error(_), _) => Error("not an email address")
|
|
19
|
-
| (Ok(
|
|
32
|
+
| (Ok(typed), role) =>
|
|
20
33
|
switch role
|
|
21
34
|
->Option.map(String.trim)
|
|
22
35
|
->Option.filter(r => r != "")
|
|
@@ -24,17 +37,25 @@ module Make = (App: Reventless.Admission.Declaration) => {
|
|
|
24
37
|
->Option.orElse(defaultRole(App.table)) {
|
|
25
38
|
| None => Error("say which role to sign up for")
|
|
26
39
|
| Some(role) =>
|
|
27
|
-
let email =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
let email = typed->ContactAddressId.normalize
|
|
41
|
+
switch ContactAddressId.fingerprint(capabilities.secrets, email) {
|
|
42
|
+
| Error(why) => Error(why)
|
|
43
|
+
| Ok(id) =>
|
|
44
|
+
// The envelope id is the fingerprint too: an id is stored beside the
|
|
45
|
+
// event, where the address must not be.
|
|
46
|
+
Ok([
|
|
47
|
+
(
|
|
48
|
+
id->ContactAddressId.toString,
|
|
49
|
+
Register({
|
|
50
|
+
emailId: id,
|
|
51
|
+
email,
|
|
52
|
+
role,
|
|
53
|
+
requestedAt: Date.make()->Date.toISOString->Reventless.DateTime.unsafe,
|
|
54
|
+
language: ?languageOf(input.language),
|
|
55
|
+
}),
|
|
56
|
+
),
|
|
57
|
+
])
|
|
58
|
+
}
|
|
38
59
|
}
|
|
39
60
|
}
|
|
40
61
|
}
|
|
@@ -15,8 +15,18 @@ function defaultRole(table) {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
function languageOf(raw) {
|
|
19
|
+
return Stdlib_Option.filter(Stdlib_Option.map(raw, prim => prim.trim()), tag => {
|
|
20
|
+
if (tag.length <= 35) {
|
|
21
|
+
return /^[A-Za-z]{2,3}(-[A-Za-z0-9]{1,8})*$/.test(tag);
|
|
22
|
+
} else {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
18
28
|
function Make(App) {
|
|
19
|
-
let translate = async (input,
|
|
29
|
+
let translate = async (input, capabilities, param) => {
|
|
20
30
|
let match = Email$Reventless.fromString(input.email.trim());
|
|
21
31
|
let match$1 = input.role;
|
|
22
32
|
if (match.TAG !== "Ok") {
|
|
@@ -32,16 +42,26 @@ function Make(App) {
|
|
|
32
42
|
_0: "say which role to sign up for"
|
|
33
43
|
};
|
|
34
44
|
}
|
|
35
|
-
let email = match._0
|
|
45
|
+
let email = ContactAddressId$ReventlessRegistration.normalize(match._0);
|
|
46
|
+
let why = ContactAddressId$ReventlessRegistration.fingerprint(capabilities.secrets, email);
|
|
47
|
+
if (why.TAG !== "Ok") {
|
|
48
|
+
return {
|
|
49
|
+
TAG: "Error",
|
|
50
|
+
_0: why._0
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
let id = why._0;
|
|
36
54
|
return {
|
|
37
55
|
TAG: "Ok",
|
|
38
56
|
_0: [[
|
|
39
|
-
|
|
57
|
+
ContactAddressId$ReventlessRegistration.toString(id),
|
|
40
58
|
{
|
|
41
59
|
TAG: "Register",
|
|
42
|
-
|
|
60
|
+
emailId: id,
|
|
61
|
+
email: email,
|
|
43
62
|
role: role,
|
|
44
|
-
requestedAt: new Date().toISOString()
|
|
63
|
+
requestedAt: new Date().toISOString(),
|
|
64
|
+
language: languageOf(input.language)
|
|
45
65
|
}
|
|
46
66
|
]]
|
|
47
67
|
};
|
|
@@ -60,6 +80,7 @@ let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/Inbound
|
|
|
60
80
|
export {
|
|
61
81
|
Spec,
|
|
62
82
|
defaultRole,
|
|
83
|
+
languageOf,
|
|
63
84
|
Make,
|
|
64
85
|
moduleUrl,
|
|
65
86
|
}
|
|
@@ -15,16 +15,22 @@
|
|
|
15
15
|
@schema
|
|
16
16
|
type consumedEvent =
|
|
17
17
|
| RegistrationProofAccepted({
|
|
18
|
-
|
|
18
|
+
emailId: string,
|
|
19
|
+
@pii({subject: "emailId"}) email: Reventless.Email.t,
|
|
19
20
|
roles: array<Reventless.Role.name>,
|
|
20
21
|
proofHash: string,
|
|
21
22
|
})
|
|
22
23
|
|
|
23
24
|
@schema
|
|
24
|
-
type outboundItem = {
|
|
25
|
+
type outboundItem = {
|
|
26
|
+
emailId: string,
|
|
27
|
+
@pii({subject: "emailId"}) email: Reventless.Email.t,
|
|
28
|
+
roles: array<Reventless.Role.name>,
|
|
29
|
+
proofHash: string,
|
|
30
|
+
}
|
|
25
31
|
|
|
26
32
|
@schema
|
|
27
|
-
type inboundCommand = RecordRegistrationCompleted({
|
|
33
|
+
type inboundCommand = RecordRegistrationCompleted({emailId: ContactAddressId.t})
|
|
28
34
|
|
|
29
35
|
// For a provider that is down. The password is put back before each retry, so a
|
|
30
36
|
// retry finds it; once the budget is spent, it expires.
|
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as Sury from "sury";
|
|
4
|
+
import * as Pii$Reventless from "@reventlessdev/reventless-spec/src/components/Pii.res.mjs";
|
|
4
5
|
import * as Role$Reventless from "@reventlessdev/reventless-spec/src/types/Role.res.mjs";
|
|
6
|
+
import * as Email$Reventless from "@reventlessdev/reventless-spec/src/semantic/Email.res.mjs";
|
|
5
7
|
import * as DcbTag$Reventless from "@reventlessdev/reventless-spec/src/components/DcbTag.res.mjs";
|
|
6
8
|
import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
|
|
7
9
|
|
|
8
10
|
let consumedEventSchema = Sury.$schema(s => ({
|
|
9
11
|
TAG: "RegistrationProofAccepted",
|
|
10
|
-
|
|
12
|
+
emailId: s.m(DcbTag$Reventless.string),
|
|
13
|
+
email: s.m(Pii$Reventless.marked("emailId", undefined, Email$Reventless.schema)),
|
|
11
14
|
roles: s.m(Sury.array(Role$Reventless.nameSchema)),
|
|
12
15
|
proofHash: s.m(Sury.string)
|
|
13
16
|
}));
|
|
14
17
|
|
|
15
18
|
let outboundItemSchema = Sury.$schema(s => ({
|
|
16
|
-
|
|
19
|
+
emailId: s.m(Sury.string),
|
|
20
|
+
email: s.m(Pii$Reventless.mark("emailId", undefined, Email$Reventless.schema)),
|
|
17
21
|
roles: s.m(Sury.array(Role$Reventless.nameSchema)),
|
|
18
22
|
proofHash: s.m(Sury.string)
|
|
19
23
|
}));
|
|
20
24
|
|
|
21
25
|
let inboundCommandSchema = Sury.$schema(s => ({
|
|
22
26
|
TAG: "RecordRegistrationCompleted",
|
|
23
|
-
|
|
27
|
+
emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema))
|
|
24
28
|
}));
|
|
25
29
|
|
|
26
30
|
let sourceNames = [];
|
|
@@ -9,13 +9,16 @@ let retryTtl = 600
|
|
|
9
9
|
|
|
10
10
|
let collect = (event, ~sourceId as _) =>
|
|
11
11
|
switch event {
|
|
12
|
-
| RegistrationProofAccepted({email, roles, proofHash}) => [
|
|
13
|
-
(`${
|
|
12
|
+
| RegistrationProofAccepted({emailId, email: Value(email), roles, proofHash}) => [
|
|
13
|
+
(`${emailId}:${proofHash}`, {emailId, email, roles, proofHash}),
|
|
14
14
|
]
|
|
15
|
+
// An address that was erased or forgotten has nobody left to write to.
|
|
16
|
+
| _ => []
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
// `emailId` is already the ledger's id for the address: no key is needed to say so.
|
|
20
|
+
let completed = (emailId: string) => Ok(
|
|
21
|
+
Some((emailId, RecordRegistrationCompleted({emailId: ContactAddressId.makeFromString(emailId)}))),
|
|
19
22
|
)
|
|
20
23
|
|
|
21
24
|
let translate = async (_id, item: outboundItem, ~capabilities: Reventless.Capabilities.t) =>
|
|
@@ -26,14 +29,14 @@ let translate = async (_id, item: outboundItem, ~capabilities: Reventless.Capabi
|
|
|
26
29
|
| Ok(None) => Error("the password expired before the account was made")
|
|
27
30
|
| Ok(Some(password)) =>
|
|
28
31
|
switch await capabilities.identityProvider.createPrincipal(
|
|
29
|
-
~contact=ToEmail(
|
|
32
|
+
~contact=ToEmail(item.email),
|
|
30
33
|
~credential=Password(password),
|
|
31
34
|
~groups=groupsOf(item.roles),
|
|
32
35
|
) {
|
|
33
|
-
| Ok(_) => completed(item.
|
|
36
|
+
| Ok(_) => completed(item.emailId)
|
|
34
37
|
// The provider already holds this address — an account declared before
|
|
35
38
|
// registration existed, say. It is as registered as one made here.
|
|
36
|
-
| Error(Conflict) => completed(item.
|
|
39
|
+
| Error(Conflict) => completed(item.emailId)
|
|
37
40
|
| Error(Unavailable(why)) =>
|
|
38
41
|
// Put back so the retry finds it. Failing that, the retry reports the
|
|
39
42
|
// password gone, which is true.
|
|
@@ -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
|
-
|
|
23
|
+
emailId + `:` + proofHash,
|
|
16
24
|
{
|
|
17
|
-
|
|
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(
|
|
33
|
+
function completed(emailId) {
|
|
25
34
|
return {
|
|
26
35
|
TAG: "Ok",
|
|
27
36
|
_0: [
|
|
28
|
-
|
|
37
|
+
emailId,
|
|
29
38
|
{
|
|
30
39
|
TAG: "RecordRegistrationCompleted",
|
|
31
|
-
|
|
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.
|
|
69
|
+
return completed(item.emailId);
|
|
61
70
|
}
|
|
62
71
|
let why = match._0;
|
|
63
72
|
if (typeof why !== "object") {
|
|
64
|
-
return completed(item.
|
|
73
|
+
return completed(item.emailId);
|
|
65
74
|
}
|
|
66
75
|
if (why.TAG !== "Unavailable") {
|
|
67
76
|
return {
|