@reventlessdev/reventless-registration 0.0.0-stage → 1.0.0-alpha.2
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/LICENSE +202 -0
- package/README.md +50 -2
- package/package.json +38 -3
- package/rescript.json +28 -0
- package/src/ContactVerification.res +106 -0
- package/src/ContactVerification.res.mjs +60 -0
- package/src/ContactVerification_Guards.res +180 -0
- package/src/ContactVerification_Guards.res.mjs +97 -0
- package/src/Registration/ContactAddressId.res +6 -0
- package/src/Registration/ContactAddressId.res.mjs +29 -0
- package/src/Registration/InboundTranslation/CompleteRegistration.res +35 -0
- package/src/Registration/InboundTranslation/CompleteRegistration.res.mjs +58 -0
- package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res +40 -0
- package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res.mjs +67 -0
- package/src/Registration/InboundTranslation/SignUp.res +35 -0
- package/src/Registration/InboundTranslation/SignUp.res.mjs +57 -0
- package/src/Registration/InboundTranslation/SignUp_Translation.res +40 -0
- package/src/Registration/InboundTranslation/SignUp_Translation.res.mjs +66 -0
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res +34 -0
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res.mjs +61 -0
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res +46 -0
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res.mjs +99 -0
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res +51 -0
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res.mjs +80 -0
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res +113 -0
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res.mjs +160 -0
- package/src/Registration/StateChange/RegistrationPolicy.res +58 -0
- package/src/Registration/StateChange/RegistrationPolicy.res.mjs +86 -0
- package/src/Registration/StateChange/RegistrationPolicy_Decision.res +43 -0
- package/src/Registration/StateChange/RegistrationPolicy_Decision.res.mjs +88 -0
- package/src/Registration/StateChange/Registrations.res +157 -0
- package/src/Registration/StateChange/Registrations.res.mjs +224 -0
- package/src/Registration/StateChange/Registrations_Decision.res +281 -0
- package/src/Registration/StateChange/Registrations_Decision.res.mjs +541 -0
- package/src/Registration/StateViewStream/RegistrationWindows.res +30 -0
- package/src/Registration/StateViewStream/RegistrationWindows.res.mjs +80 -0
- package/src/Registration/StateViewStream/RegistrationWindows_Projection.res +7 -0
- package/src/Registration/StateViewStream/RegistrationWindows_Projection.res.mjs +38 -0
- package/src/RegistrationChallenge.res +20 -0
- package/src/RegistrationChallenge.res.mjs +45 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
4
|
+
import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js";
|
|
5
|
+
import * as DateTime$Reventless from "@reventlessdev/reventless-spec/src/semantic/DateTime.res.mjs";
|
|
6
|
+
|
|
7
|
+
function contactToVerify(v) {
|
|
8
|
+
if (Primitive_object.equal(v.verifiedAddress, v.contact)) {
|
|
9
|
+
return;
|
|
10
|
+
} else {
|
|
11
|
+
return v.contact;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function elapsedSeconds(from, to_) {
|
|
16
|
+
return (DateTime$Reventless.millis(to_) - DateTime$Reventless.millis(from)) / 1000 | 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function hasExpired(c, now, policy) {
|
|
20
|
+
return elapsedSeconds(c.issuedAt, now) >= policy.tokenTtl;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function onProofPresented(c, hostContact, proofMatches, now, policy) {
|
|
24
|
+
if (Stdlib_Option.mapOr(hostContact, false, held => Primitive_object.notequal(c.contact, held))) {
|
|
25
|
+
return {
|
|
26
|
+
TAG: "Refuse",
|
|
27
|
+
_0: "AddressSuperseded"
|
|
28
|
+
};
|
|
29
|
+
} else if (c.settled) {
|
|
30
|
+
return {
|
|
31
|
+
TAG: "Refuse",
|
|
32
|
+
_0: "AlreadySettled"
|
|
33
|
+
};
|
|
34
|
+
} else if (hasExpired(c, now, policy)) {
|
|
35
|
+
return {
|
|
36
|
+
TAG: "Refuse",
|
|
37
|
+
_0: "ChallengeExpired"
|
|
38
|
+
};
|
|
39
|
+
} else if (c.attempts >= policy.maxAttempts) {
|
|
40
|
+
return {
|
|
41
|
+
TAG: "Refuse",
|
|
42
|
+
_0: "AttemptsExhausted"
|
|
43
|
+
};
|
|
44
|
+
} else if (proofMatches) {
|
|
45
|
+
return "Settle";
|
|
46
|
+
} else {
|
|
47
|
+
return {
|
|
48
|
+
TAG: "Refuse",
|
|
49
|
+
_0: "ProofMismatch"
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function onVerifiedReport(v, contact) {
|
|
55
|
+
if (Primitive_object.notequal(contact, v.contact) || Primitive_object.equal(v.verifiedAddress, contact)) {
|
|
56
|
+
return "Ignore";
|
|
57
|
+
} else {
|
|
58
|
+
return "Append";
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function onIssueRequested(contact, existing, now, policy) {
|
|
63
|
+
if (existing !== undefined && Primitive_object.equal(existing.contact, contact) && !existing.settled && !hasExpired(existing, now, policy)) {
|
|
64
|
+
return "AlreadyOpen";
|
|
65
|
+
} else {
|
|
66
|
+
return "Issue";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function onResendRequested(contact, existing, now, policy) {
|
|
71
|
+
if (existing === undefined) {
|
|
72
|
+
return "NothingOpen";
|
|
73
|
+
}
|
|
74
|
+
if (Primitive_object.notequal(existing.contact, contact) || existing.settled || hasExpired(existing, now, policy)) {
|
|
75
|
+
return "NothingOpen";
|
|
76
|
+
}
|
|
77
|
+
let waited = elapsedSeconds(existing.issuedAt, now);
|
|
78
|
+
if (waited >= policy.resendCooldown) {
|
|
79
|
+
return "Send";
|
|
80
|
+
} else {
|
|
81
|
+
return {
|
|
82
|
+
TAG: "TooSoon",
|
|
83
|
+
_0: policy.resendCooldown - waited | 0
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export {
|
|
89
|
+
contactToVerify,
|
|
90
|
+
elapsedSeconds,
|
|
91
|
+
hasExpired,
|
|
92
|
+
onProofPresented,
|
|
93
|
+
onVerifiedReport,
|
|
94
|
+
onIssueRequested,
|
|
95
|
+
onResendRequested,
|
|
96
|
+
}
|
|
97
|
+
/* DateTime-Reventless Not a pure module */
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// The address a registration claims: the partition the registration ledger
|
|
2
|
+
// decides about, and the tag that makes "this address is taken" one fact on
|
|
3
|
+
// every platform. Its value is the address itself, lower-cased.
|
|
4
|
+
include Reventless.Id.Make({
|
|
5
|
+
let key = "contactAddress"
|
|
6
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Id$Reventless from "@reventlessdev/reventless-spec/src/types/Id.res.mjs";
|
|
4
|
+
|
|
5
|
+
let include = Id$Reventless.Make({
|
|
6
|
+
key: "contactAddress"
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
let schema = include.schema;
|
|
10
|
+
|
|
11
|
+
let make = include.make;
|
|
12
|
+
|
|
13
|
+
let makeFromString = include.makeFromString;
|
|
14
|
+
|
|
15
|
+
let toString = include.toString;
|
|
16
|
+
|
|
17
|
+
let cmp = include.cmp;
|
|
18
|
+
|
|
19
|
+
let key = include.key;
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
schema,
|
|
23
|
+
make,
|
|
24
|
+
makeFromString,
|
|
25
|
+
toString,
|
|
26
|
+
cmp,
|
|
27
|
+
key,
|
|
28
|
+
}
|
|
29
|
+
/* include Not a pure module */
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// CompleteRegistration InboundTranslationSlice.
|
|
2
|
+
//
|
|
3
|
+
// The anonymous door a registration ends at: the proof that arrived at the
|
|
4
|
+
// address, and the password the person chose. The password must reach the
|
|
5
|
+
// identity provider and must never reach the log, and whether it may reach the
|
|
6
|
+
// provider at all is decided by the ledger, which this door cannot read. So the
|
|
7
|
+
// door hashes the proof, puts the password in the stash under that hash, and
|
|
8
|
+
// relays only the hash. If the ledger accepts the proof, the slice that reacts
|
|
9
|
+
// takes the password and makes the account; if not, the password expires.
|
|
10
|
+
//
|
|
11
|
+
// Both secrets are `@sensitive`, which keeps them out of this slice's audit rows.
|
|
12
|
+
|
|
13
|
+
@@reventless.spec
|
|
14
|
+
@@reventless.authorize(AllowAnonymous)
|
|
15
|
+
|
|
16
|
+
@schema
|
|
17
|
+
type externalInput = {
|
|
18
|
+
email: string,
|
|
19
|
+
@sensitive proof: string,
|
|
20
|
+
@sensitive password: string,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@schema
|
|
24
|
+
type command =
|
|
25
|
+
| SubmitRegistrationProof({
|
|
26
|
+
email: ContactAddressId.t,
|
|
27
|
+
proofHash: string,
|
|
28
|
+
presentedAt: Reventless.DateTime.t,
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
let targetName = "Registrations"
|
|
32
|
+
let capabilityNeeds = [Reventless.CapabilityNeed.Stash]
|
|
33
|
+
|
|
34
|
+
/** This door completes a registration; the platform tells the shell so. */
|
|
35
|
+
let admissionDoor = Reventless.Admission.Complete
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Sury from "sury";
|
|
4
|
+
import * as DcbTag$Reventless from "@reventlessdev/reventless-spec/src/components/DcbTag.res.mjs";
|
|
5
|
+
import * as DateTime$Reventless from "@reventlessdev/reventless-spec/src/semantic/DateTime.res.mjs";
|
|
6
|
+
import * as Sensitive$Reventless from "@reventlessdev/reventless-spec/src/components/Sensitive.res.mjs";
|
|
7
|
+
import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
|
|
8
|
+
|
|
9
|
+
let externalInputSchema = Sury.$schema(s => ({
|
|
10
|
+
email: s.m(Sury.string),
|
|
11
|
+
proof: s.m(Sensitive$Reventless.string),
|
|
12
|
+
password: s.m(Sensitive$Reventless.string)
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
let commandSchema = Sury.$schema(s => ({
|
|
16
|
+
TAG: "SubmitRegistrationProof",
|
|
17
|
+
email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
18
|
+
proofHash: s.m(Sury.string),
|
|
19
|
+
presentedAt: s.m(DateTime$Reventless.schema)
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
let capabilityNeeds = ["Stash"];
|
|
23
|
+
|
|
24
|
+
function authorizationOf(param) {
|
|
25
|
+
return "AllowAnonymous";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let traits = [];
|
|
29
|
+
|
|
30
|
+
let name = "CompleteRegistration";
|
|
31
|
+
|
|
32
|
+
let Id;
|
|
33
|
+
|
|
34
|
+
let targetName = "Registrations";
|
|
35
|
+
|
|
36
|
+
let admissionDoor = "Complete";
|
|
37
|
+
|
|
38
|
+
let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/InboundTranslation/CompleteRegistration.res.mjs";
|
|
39
|
+
|
|
40
|
+
let externalSystem;
|
|
41
|
+
|
|
42
|
+
let endpoint;
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
name,
|
|
46
|
+
Id,
|
|
47
|
+
externalInputSchema,
|
|
48
|
+
commandSchema,
|
|
49
|
+
targetName,
|
|
50
|
+
capabilityNeeds,
|
|
51
|
+
admissionDoor,
|
|
52
|
+
moduleUrl,
|
|
53
|
+
authorizationOf,
|
|
54
|
+
externalSystem,
|
|
55
|
+
traits,
|
|
56
|
+
endpoint,
|
|
57
|
+
}
|
|
58
|
+
/* externalInputSchema Not a pure module */
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
@@reventless.translation
|
|
2
|
+
|
|
3
|
+
/** How long a password waits for the ledger to accept the proof it came with. */
|
|
4
|
+
let passwordTtl = 600
|
|
5
|
+
|
|
6
|
+
/** The shortest password accepted here. Checked at the door so a pool's policy
|
|
7
|
+
does not refuse it after the proof has been spent. */
|
|
8
|
+
let minimumPasswordLength = 12
|
|
9
|
+
|
|
10
|
+
let translate = async (
|
|
11
|
+
input: externalInput,
|
|
12
|
+
~capabilities: Reventless.Capabilities.t,
|
|
13
|
+
~caller as _: option<Reventless.Identity.t>,
|
|
14
|
+
) =>
|
|
15
|
+
switch Reventless.Email.fromString(input.email->String.trim) {
|
|
16
|
+
| Error(_) => Error("not an email address")
|
|
17
|
+
| Ok(_) if input.password->String.length < minimumPasswordLength =>
|
|
18
|
+
Error(`a password needs at least ${minimumPasswordLength->Int.toString} characters`)
|
|
19
|
+
| Ok(email) =>
|
|
20
|
+
let email = email->Reventless.Email.toString->String.toLowerCase
|
|
21
|
+
switch capabilities.secrets.hash(input.proof->String.trim) {
|
|
22
|
+
| Error(Unavailable(why)) => Error(`cannot hash the proof: ${why}`)
|
|
23
|
+
| Ok(proofHash) =>
|
|
24
|
+
switch await capabilities.stash.put(~key=proofHash, ~value=input.password, ~ttl=passwordTtl) {
|
|
25
|
+
| Error(failure) =>
|
|
26
|
+
Error(`cannot hold the password: ${failure->Reventless.Stash.failureReason}`)
|
|
27
|
+
| Ok() =>
|
|
28
|
+
Ok([
|
|
29
|
+
(
|
|
30
|
+
email,
|
|
31
|
+
SubmitRegistrationProof({
|
|
32
|
+
email: ContactAddressId.makeFromString(email),
|
|
33
|
+
proofHash,
|
|
34
|
+
presentedAt: Date.make()->Date.toISOString->Reventless.DateTime.unsafe,
|
|
35
|
+
}),
|
|
36
|
+
),
|
|
37
|
+
])
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Email$Reventless from "@reventlessdev/reventless-spec/src/semantic/Email.res.mjs";
|
|
4
|
+
import * as Stash$Reventless from "@reventlessdev/reventless-spec/src/semantic/Stash.res.mjs";
|
|
5
|
+
import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
|
|
6
|
+
|
|
7
|
+
async function translate(input, capabilities, param) {
|
|
8
|
+
let email = Email$Reventless.fromString(input.email.trim());
|
|
9
|
+
if (email.TAG !== "Ok") {
|
|
10
|
+
return {
|
|
11
|
+
TAG: "Error",
|
|
12
|
+
_0: "not an email address"
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
if (input.password.length < 12) {
|
|
16
|
+
return {
|
|
17
|
+
TAG: "Error",
|
|
18
|
+
_0: `a password needs at least ` + (12).toString() + ` characters`
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
let email$1 = email._0.toLowerCase();
|
|
22
|
+
let proofHash = capabilities.secrets.hash(input.proof.trim());
|
|
23
|
+
if (proofHash.TAG !== "Ok") {
|
|
24
|
+
return {
|
|
25
|
+
TAG: "Error",
|
|
26
|
+
_0: `cannot hash the proof: ` + proofHash._0._0
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
let proofHash$1 = proofHash._0;
|
|
30
|
+
let failure = await capabilities.stash.put(proofHash$1, input.password, 600);
|
|
31
|
+
if (failure.TAG === "Ok") {
|
|
32
|
+
return {
|
|
33
|
+
TAG: "Ok",
|
|
34
|
+
_0: [[
|
|
35
|
+
email$1,
|
|
36
|
+
{
|
|
37
|
+
TAG: "SubmitRegistrationProof",
|
|
38
|
+
email: ContactAddressId$ReventlessRegistration.makeFromString(email$1),
|
|
39
|
+
proofHash: proofHash$1,
|
|
40
|
+
presentedAt: new Date().toISOString()
|
|
41
|
+
}
|
|
42
|
+
]]
|
|
43
|
+
};
|
|
44
|
+
} else {
|
|
45
|
+
return {
|
|
46
|
+
TAG: "Error",
|
|
47
|
+
_0: `cannot hold the password: ` + Stash$Reventless.failureReason(failure._0)
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let Spec;
|
|
53
|
+
|
|
54
|
+
let passwordTtl = 600;
|
|
55
|
+
|
|
56
|
+
let minimumPasswordLength = 12;
|
|
57
|
+
|
|
58
|
+
let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/InboundTranslation/CompleteRegistration_Translation.res.mjs";
|
|
59
|
+
|
|
60
|
+
export {
|
|
61
|
+
Spec,
|
|
62
|
+
passwordTtl,
|
|
63
|
+
minimumPasswordLength,
|
|
64
|
+
translate,
|
|
65
|
+
moduleUrl,
|
|
66
|
+
}
|
|
67
|
+
/* Email-Reventless Not a pure module */
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// SignUp InboundTranslationSlice.
|
|
2
|
+
//
|
|
3
|
+
// The anonymous door a registration starts at. It reads the address and the role
|
|
4
|
+
// asked for, stamps the moment the request arrived — the time the policy's open
|
|
5
|
+
// window is measured against, so a caller cannot choose it — and relays a
|
|
6
|
+
// `Register` to the ledger. What happens next is the ledger's, and the caller
|
|
7
|
+
// learns none of it: a closed role, a role no visitor may have, a taken address
|
|
8
|
+
// and a fresh one all answer alike.
|
|
9
|
+
//
|
|
10
|
+
// Anonymous because the caller is trying to become someone. The local platform
|
|
11
|
+
// honors that; a deployed one refuses the rule until it has a door of its own,
|
|
12
|
+
// which is why a plugin listing these slices is hosted by the local platform
|
|
13
|
+
// only.
|
|
14
|
+
|
|
15
|
+
@@reventless.spec
|
|
16
|
+
@@reventless.authorize(AllowAnonymous)
|
|
17
|
+
|
|
18
|
+
/** `role` may be left out where exactly one role is open to visitors; with
|
|
19
|
+
several, a sign-up has to say which. */
|
|
20
|
+
@schema
|
|
21
|
+
type externalInput = {email: string, role?: string}
|
|
22
|
+
|
|
23
|
+
@schema
|
|
24
|
+
type command =
|
|
25
|
+
| Register({
|
|
26
|
+
email: ContactAddressId.t,
|
|
27
|
+
role: Reventless.Role.name,
|
|
28
|
+
requestedAt: Reventless.DateTime.t,
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
let targetName = "Registrations"
|
|
32
|
+
let capabilityNeeds: array<Reventless.CapabilityNeed.t> = []
|
|
33
|
+
|
|
34
|
+
/** This door starts a registration; the platform tells the shell so. */
|
|
35
|
+
let admissionDoor = Reventless.Admission.Start
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Sury from "sury";
|
|
4
|
+
import * as Role$Reventless from "@reventlessdev/reventless-spec/src/types/Role.res.mjs";
|
|
5
|
+
import * as DcbTag$Reventless from "@reventlessdev/reventless-spec/src/components/DcbTag.res.mjs";
|
|
6
|
+
import * as DateTime$Reventless from "@reventlessdev/reventless-spec/src/semantic/DateTime.res.mjs";
|
|
7
|
+
import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
|
|
8
|
+
|
|
9
|
+
let externalInputSchema = Sury.$schema(s => ({
|
|
10
|
+
email: s.m(Sury.string),
|
|
11
|
+
role: s.m(Sury.$option(Sury.string))
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
let commandSchema = Sury.$schema(s => ({
|
|
15
|
+
TAG: "Register",
|
|
16
|
+
email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
17
|
+
role: s.m(Role$Reventless.nameSchema),
|
|
18
|
+
requestedAt: s.m(DateTime$Reventless.schema)
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
let capabilityNeeds = [];
|
|
22
|
+
|
|
23
|
+
function authorizationOf(param) {
|
|
24
|
+
return "AllowAnonymous";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let traits = [];
|
|
28
|
+
|
|
29
|
+
let name = "SignUp";
|
|
30
|
+
|
|
31
|
+
let Id;
|
|
32
|
+
|
|
33
|
+
let targetName = "Registrations";
|
|
34
|
+
|
|
35
|
+
let admissionDoor = "Start";
|
|
36
|
+
|
|
37
|
+
let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/InboundTranslation/SignUp.res.mjs";
|
|
38
|
+
|
|
39
|
+
let externalSystem;
|
|
40
|
+
|
|
41
|
+
let endpoint;
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
name,
|
|
45
|
+
Id,
|
|
46
|
+
externalInputSchema,
|
|
47
|
+
commandSchema,
|
|
48
|
+
targetName,
|
|
49
|
+
capabilityNeeds,
|
|
50
|
+
admissionDoor,
|
|
51
|
+
moduleUrl,
|
|
52
|
+
authorizationOf,
|
|
53
|
+
externalSystem,
|
|
54
|
+
traits,
|
|
55
|
+
endpoint,
|
|
56
|
+
}
|
|
57
|
+
/* externalInputSchema Not a pure module */
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
@@reventless.translation
|
|
2
|
+
|
|
3
|
+
/** The role a sign-up that names none asks for: the one self-service role, where
|
|
4
|
+
the table has exactly one. With none or several, the caller has to say. */
|
|
5
|
+
let defaultRole = (table: Reventless.Admission.t): option<Reventless.Role.name> =>
|
|
6
|
+
switch table->Reventless.Admission.selfService {
|
|
7
|
+
| [only] => Some(only)
|
|
8
|
+
| _ => None
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** The door over the app's table, which picks the role a sign-up may leave out. */
|
|
12
|
+
module Make = (App: Reventless.Admission.Declaration) => {
|
|
13
|
+
module Spec = Spec
|
|
14
|
+
let moduleUrl = moduleUrl
|
|
15
|
+
|
|
16
|
+
let translate = async (input: externalInput, ~capabilities as _, ~caller as _) =>
|
|
17
|
+
switch (Reventless.Email.fromString(input.email->String.trim), input.role) {
|
|
18
|
+
| (Error(_), _) => Error("not an email address")
|
|
19
|
+
| (Ok(email), role) =>
|
|
20
|
+
switch role
|
|
21
|
+
->Option.map(String.trim)
|
|
22
|
+
->Option.filter(r => r != "")
|
|
23
|
+
->Option.map(Reventless.Role.make)
|
|
24
|
+
->Option.orElse(defaultRole(App.table)) {
|
|
25
|
+
| None => Error("say which role to sign up for")
|
|
26
|
+
| Some(role) =>
|
|
27
|
+
let email = email->Reventless.Email.toString->String.toLowerCase
|
|
28
|
+
Ok([
|
|
29
|
+
(
|
|
30
|
+
email,
|
|
31
|
+
Register({
|
|
32
|
+
email: ContactAddressId.makeFromString(email),
|
|
33
|
+
role,
|
|
34
|
+
requestedAt: Date.make()->Date.toISOString->Reventless.DateTime.unsafe,
|
|
35
|
+
}),
|
|
36
|
+
),
|
|
37
|
+
])
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
4
|
+
import * as Email$Reventless from "@reventlessdev/reventless-spec/src/semantic/Email.res.mjs";
|
|
5
|
+
import * as Admission$Reventless from "@reventlessdev/reventless-spec/src/types/Admission.res.mjs";
|
|
6
|
+
import * as SignUp$ReventlessRegistration from "./SignUp.res.mjs";
|
|
7
|
+
import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
|
|
8
|
+
|
|
9
|
+
function defaultRole(table) {
|
|
10
|
+
let match = Admission$Reventless.selfService(table);
|
|
11
|
+
if (match.length !== 1) {
|
|
12
|
+
return;
|
|
13
|
+
} else {
|
|
14
|
+
return match[0];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function Make(App) {
|
|
19
|
+
let translate = async (input, param, param$1) => {
|
|
20
|
+
let match = Email$Reventless.fromString(input.email.trim());
|
|
21
|
+
let match$1 = input.role;
|
|
22
|
+
if (match.TAG !== "Ok") {
|
|
23
|
+
return {
|
|
24
|
+
TAG: "Error",
|
|
25
|
+
_0: "not an email address"
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
let role = Stdlib_Option.orElse(Stdlib_Option.map(Stdlib_Option.filter(Stdlib_Option.map(match$1, prim => prim.trim()), r => r !== ""), prim => prim), defaultRole(App.table));
|
|
29
|
+
if (role === undefined) {
|
|
30
|
+
return {
|
|
31
|
+
TAG: "Error",
|
|
32
|
+
_0: "say which role to sign up for"
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
let email = match._0.toLowerCase();
|
|
36
|
+
return {
|
|
37
|
+
TAG: "Ok",
|
|
38
|
+
_0: [[
|
|
39
|
+
email,
|
|
40
|
+
{
|
|
41
|
+
TAG: "Register",
|
|
42
|
+
email: ContactAddressId$ReventlessRegistration.makeFromString(email),
|
|
43
|
+
role: role,
|
|
44
|
+
requestedAt: new Date().toISOString()
|
|
45
|
+
}
|
|
46
|
+
]]
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
Spec: undefined,
|
|
51
|
+
moduleUrl: SignUp$ReventlessRegistration.moduleUrl,
|
|
52
|
+
translate: translate
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let Spec;
|
|
57
|
+
|
|
58
|
+
let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/InboundTranslation/SignUp_Translation.res.mjs";
|
|
59
|
+
|
|
60
|
+
export {
|
|
61
|
+
Spec,
|
|
62
|
+
defaultRole,
|
|
63
|
+
Make,
|
|
64
|
+
moduleUrl,
|
|
65
|
+
}
|
|
66
|
+
/* Email-Reventless Not a pure module */
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// CreateRegisteredPrincipal OutboundTranslationSlice.
|
|
2
|
+
//
|
|
3
|
+
// Turns an accepted proof into an account. The password is the one the person
|
|
4
|
+
// typed beside the proof: the door held it in the stash under the proof's hash,
|
|
5
|
+
// because it could not know whether the proof would be accepted, and this slice
|
|
6
|
+
// takes it now that the ledger has said yes.
|
|
7
|
+
//
|
|
8
|
+
// The account is made in the deployment's identity provider — on the local
|
|
9
|
+
// platform, the accounts file its login reads — in the groups that stand for the
|
|
10
|
+
// roles the registration grants, and the ledger is told the registration
|
|
11
|
+
// completed.
|
|
12
|
+
|
|
13
|
+
@@reventless.spec
|
|
14
|
+
|
|
15
|
+
@schema
|
|
16
|
+
type consumedEvent =
|
|
17
|
+
| RegistrationProofAccepted({
|
|
18
|
+
email: string,
|
|
19
|
+
roles: array<Reventless.Role.name>,
|
|
20
|
+
proofHash: string,
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
@schema
|
|
24
|
+
type outboundItem = {email: string, roles: array<Reventless.Role.name>, proofHash: string}
|
|
25
|
+
|
|
26
|
+
@schema
|
|
27
|
+
type inboundCommand = RecordRegistrationCompleted({email: ContactAddressId.t})
|
|
28
|
+
|
|
29
|
+
// For a provider that is down. The password is put back before each retry, so a
|
|
30
|
+
// retry finds it; once the budget is spent, it expires.
|
|
31
|
+
let maxRetries = 3
|
|
32
|
+
let targetName = Some("Registrations")
|
|
33
|
+
let sourceNames: array<string> = []
|
|
34
|
+
let capabilityNeeds = [Reventless.CapabilityNeed.Stash, Reventless.CapabilityNeed.IdentityProvider]
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Sury from "sury";
|
|
4
|
+
import * as Role$Reventless from "@reventlessdev/reventless-spec/src/types/Role.res.mjs";
|
|
5
|
+
import * as DcbTag$Reventless from "@reventlessdev/reventless-spec/src/components/DcbTag.res.mjs";
|
|
6
|
+
import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
|
|
7
|
+
|
|
8
|
+
let consumedEventSchema = Sury.$schema(s => ({
|
|
9
|
+
TAG: "RegistrationProofAccepted",
|
|
10
|
+
email: s.m(Sury.string),
|
|
11
|
+
roles: s.m(Sury.array(Role$Reventless.nameSchema)),
|
|
12
|
+
proofHash: s.m(Sury.string)
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
let outboundItemSchema = Sury.$schema(s => ({
|
|
16
|
+
email: s.m(Sury.string),
|
|
17
|
+
roles: s.m(Sury.array(Role$Reventless.nameSchema)),
|
|
18
|
+
proofHash: s.m(Sury.string)
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
let inboundCommandSchema = Sury.$schema(s => ({
|
|
22
|
+
TAG: "RecordRegistrationCompleted",
|
|
23
|
+
email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema))
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
let sourceNames = [];
|
|
27
|
+
|
|
28
|
+
let capabilityNeeds = [
|
|
29
|
+
"Stash",
|
|
30
|
+
"IdentityProvider"
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
let traits = [];
|
|
34
|
+
|
|
35
|
+
let name = "CreateRegisteredPrincipal";
|
|
36
|
+
|
|
37
|
+
let Id;
|
|
38
|
+
|
|
39
|
+
let maxRetries = 3;
|
|
40
|
+
|
|
41
|
+
let targetName = "Registrations";
|
|
42
|
+
|
|
43
|
+
let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res.mjs";
|
|
44
|
+
|
|
45
|
+
let externalSystem;
|
|
46
|
+
|
|
47
|
+
export {
|
|
48
|
+
name,
|
|
49
|
+
Id,
|
|
50
|
+
consumedEventSchema,
|
|
51
|
+
outboundItemSchema,
|
|
52
|
+
inboundCommandSchema,
|
|
53
|
+
maxRetries,
|
|
54
|
+
targetName,
|
|
55
|
+
sourceNames,
|
|
56
|
+
capabilityNeeds,
|
|
57
|
+
moduleUrl,
|
|
58
|
+
externalSystem,
|
|
59
|
+
traits,
|
|
60
|
+
}
|
|
61
|
+
/* consumedEventSchema Not a pure module */
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
@@reventless.translation
|
|
2
|
+
|
|
3
|
+
/** The groups that stand for the roles a registration grants, as this
|
|
4
|
+
deployment maps them. */
|
|
5
|
+
let groupsOf = (roles: array<Reventless.Role.name>) => roles->Array.map(Reventless.Role.groupOf)
|
|
6
|
+
|
|
7
|
+
/** How long a password put back for a retry waits again. */
|
|
8
|
+
let retryTtl = 600
|
|
9
|
+
|
|
10
|
+
let collect = (event, ~sourceId as _) =>
|
|
11
|
+
switch event {
|
|
12
|
+
| RegistrationProofAccepted({email, roles, proofHash}) => [
|
|
13
|
+
(`${email}:${proofHash}`, {email, roles, proofHash}),
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let completed = (email: string) => Ok(
|
|
18
|
+
Some((email, RecordRegistrationCompleted({email: ContactAddressId.makeFromString(email)}))),
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
let translate = async (_id, item: outboundItem, ~capabilities: Reventless.Capabilities.t) =>
|
|
22
|
+
switch await capabilities.stash.take(~key=item.proofHash) {
|
|
23
|
+
| Error(failure) => Error(failure->Reventless.Stash.failureReason)
|
|
24
|
+
// Gone: the person took longer than the stash holds a password, or a restart
|
|
25
|
+
// emptied it. Retrying cannot bring it back; they register again.
|
|
26
|
+
| Ok(None) => Error("the password expired before the account was made")
|
|
27
|
+
| Ok(Some(password)) =>
|
|
28
|
+
switch await capabilities.identityProvider.createPrincipal(
|
|
29
|
+
~contact=ToEmail(Reventless.Email.unsafe(item.email)),
|
|
30
|
+
~credential=Password(password),
|
|
31
|
+
~groups=groupsOf(item.roles),
|
|
32
|
+
) {
|
|
33
|
+
| Ok(_) => completed(item.email)
|
|
34
|
+
// The provider already holds this address — an account declared before
|
|
35
|
+
// registration existed, say. It is as registered as one made here.
|
|
36
|
+
| Error(Conflict) => completed(item.email)
|
|
37
|
+
| Error(Unavailable(why)) =>
|
|
38
|
+
// Put back so the retry finds it. Failing that, the retry reports the
|
|
39
|
+
// password gone, which is true.
|
|
40
|
+
let _ = await capabilities.stash.put(~key=item.proofHash, ~value=password, ~ttl=retryTtl)
|
|
41
|
+
Error(why)
|
|
42
|
+
| Error(Refused(why)) => Error(why)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let onExhausted = (_id, _item: outboundItem, ~lastError as _) => None
|