@reventlessdev/reventless-registration 0.0.0-stage → 1.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +50 -2
  3. package/package.json +38 -3
  4. package/rescript.json +28 -0
  5. package/src/ContactVerification.res +106 -0
  6. package/src/ContactVerification.res.mjs +60 -0
  7. package/src/ContactVerification_Guards.res +180 -0
  8. package/src/ContactVerification_Guards.res.mjs +97 -0
  9. package/src/Registration/ContactAddressId.res +30 -0
  10. package/src/Registration/ContactAddressId.res.mjs +53 -0
  11. package/src/Registration/InboundTranslation/CompleteRegistration.res +35 -0
  12. package/src/Registration/InboundTranslation/CompleteRegistration.res.mjs +58 -0
  13. package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res +43 -0
  14. package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res.mjs +74 -0
  15. package/src/Registration/InboundTranslation/SignUp.res +36 -0
  16. package/src/Registration/InboundTranslation/SignUp.res.mjs +60 -0
  17. package/src/Registration/InboundTranslation/SignUp_Translation.res +51 -0
  18. package/src/Registration/InboundTranslation/SignUp_Translation.res.mjs +75 -0
  19. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res +40 -0
  20. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res.mjs +65 -0
  21. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res +49 -0
  22. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res.mjs +108 -0
  23. package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res +72 -0
  24. package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res.mjs +87 -0
  25. package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res +115 -0
  26. package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res.mjs +200 -0
  27. package/src/Registration/StateChange/RegistrationPolicy.res +58 -0
  28. package/src/Registration/StateChange/RegistrationPolicy.res.mjs +86 -0
  29. package/src/Registration/StateChange/RegistrationPolicy_Decision.res +43 -0
  30. package/src/Registration/StateChange/RegistrationPolicy_Decision.res.mjs +88 -0
  31. package/src/Registration/StateChange/Registrations.res +183 -0
  32. package/src/Registration/StateChange/Registrations.res.mjs +238 -0
  33. package/src/Registration/StateChange/Registrations_Decision.res +311 -0
  34. package/src/Registration/StateChange/Registrations_Decision.res.mjs +560 -0
  35. package/src/Registration/StateViewStream/RegistrationWindows.res +30 -0
  36. package/src/Registration/StateViewStream/RegistrationWindows.res.mjs +80 -0
  37. package/src/Registration/StateViewStream/RegistrationWindows_Projection.res +7 -0
  38. package/src/Registration/StateViewStream/RegistrationWindows_Projection.res.mjs +38 -0
  39. package/src/RegistrationChallenge.res +20 -0
  40. 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,30 @@
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.
11
+ include Reventless.Id.Make({
12
+ let key = "contactAddress"
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
+ }
@@ -0,0 +1,53 @@
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 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
+
32
+ let schema = include.schema;
33
+
34
+ let make = include.make;
35
+
36
+ let toString = include.toString;
37
+
38
+ let cmp = include.cmp;
39
+
40
+ let key = include.key;
41
+
42
+ export {
43
+ schema,
44
+ make,
45
+ makeFromString,
46
+ toString,
47
+ cmp,
48
+ key,
49
+ purpose,
50
+ normalize,
51
+ fingerprint,
52
+ }
53
+ /* 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,43 @@
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
+ 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)) =>
27
+ switch await capabilities.stash.put(~key=proofHash, ~value=input.password, ~ttl=passwordTtl) {
28
+ | Error(failure) =>
29
+ Error(`cannot hold the password: ${failure->Reventless.Stash.failureReason}`)
30
+ | Ok() =>
31
+ Ok([
32
+ (
33
+ id->ContactAddressId.toString,
34
+ SubmitRegistrationProof({
35
+ email: id,
36
+ proofHash,
37
+ presentedAt: Date.make()->Date.toISOString->Reventless.DateTime.unsafe,
38
+ }),
39
+ ),
40
+ ])
41
+ }
42
+ }
43
+ }
@@ -0,0 +1,74 @@
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 match = ContactAddressId$ReventlessRegistration.fingerprint(capabilities.secrets, email._0);
22
+ let match$1 = capabilities.secrets.hash(input.proof.trim());
23
+ if (match.TAG !== "Ok") {
24
+ return {
25
+ TAG: "Error",
26
+ _0: match._0
27
+ };
28
+ }
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);
38
+ if (failure.TAG === "Ok") {
39
+ return {
40
+ TAG: "Ok",
41
+ _0: [[
42
+ ContactAddressId$ReventlessRegistration.toString(id),
43
+ {
44
+ TAG: "SubmitRegistrationProof",
45
+ email: id,
46
+ proofHash: proofHash,
47
+ presentedAt: new Date().toISOString()
48
+ }
49
+ ]]
50
+ };
51
+ } else {
52
+ return {
53
+ TAG: "Error",
54
+ _0: `cannot hold the password: ` + Stash$Reventless.failureReason(failure._0)
55
+ };
56
+ }
57
+ }
58
+
59
+ let Spec;
60
+
61
+ let passwordTtl = 600;
62
+
63
+ let minimumPasswordLength = 12;
64
+
65
+ let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/InboundTranslation/CompleteRegistration_Translation.res.mjs";
66
+
67
+ export {
68
+ Spec,
69
+ passwordTtl,
70
+ minimumPasswordLength,
71
+ translate,
72
+ moduleUrl,
73
+ }
74
+ /* Email-Reventless Not a pure module */
@@ -0,0 +1,36 @@
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
+ @pii({subject: "email"}) address: Reventless.Email.t,
28
+ role: Reventless.Role.name,
29
+ requestedAt: Reventless.DateTime.t,
30
+ })
31
+
32
+ let targetName = "Registrations"
33
+ let capabilityNeeds: array<Reventless.CapabilityNeed.t> = []
34
+
35
+ /** This door starts a registration; the platform tells the shell so. */
36
+ let admissionDoor = Reventless.Admission.Start
@@ -0,0 +1,60 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Sury from "sury";
4
+ import * as Pii$Reventless from "@reventlessdev/reventless-spec/src/components/Pii.res.mjs";
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";
7
+ import * as DcbTag$Reventless from "@reventlessdev/reventless-spec/src/components/DcbTag.res.mjs";
8
+ import * as DateTime$Reventless from "@reventlessdev/reventless-spec/src/semantic/DateTime.res.mjs";
9
+ import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
10
+
11
+ let externalInputSchema = Sury.$schema(s => ({
12
+ email: s.m(Sury.string),
13
+ role: s.m(Sury.$option(Sury.string))
14
+ }));
15
+
16
+ let commandSchema = Sury.$schema(s => ({
17
+ TAG: "Register",
18
+ email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
19
+ address: s.m(Pii$Reventless.mark("email", undefined, Email$Reventless.schema)),
20
+ role: s.m(Role$Reventless.nameSchema),
21
+ requestedAt: s.m(DateTime$Reventless.schema)
22
+ }));
23
+
24
+ let capabilityNeeds = [];
25
+
26
+ function authorizationOf(param) {
27
+ return "AllowAnonymous";
28
+ }
29
+
30
+ let traits = [];
31
+
32
+ let name = "SignUp";
33
+
34
+ let Id;
35
+
36
+ let targetName = "Registrations";
37
+
38
+ let admissionDoor = "Start";
39
+
40
+ let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/InboundTranslation/SignUp.res.mjs";
41
+
42
+ let externalSystem;
43
+
44
+ let endpoint;
45
+
46
+ export {
47
+ name,
48
+ Id,
49
+ externalInputSchema,
50
+ commandSchema,
51
+ targetName,
52
+ capabilityNeeds,
53
+ admissionDoor,
54
+ moduleUrl,
55
+ authorizationOf,
56
+ externalSystem,
57
+ traits,
58
+ endpoint,
59
+ }
60
+ /* externalInputSchema Not a pure module */
@@ -0,0 +1,51 @@
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 (
17
+ input: externalInput,
18
+ ~capabilities: Reventless.Capabilities.t,
19
+ ~caller as _,
20
+ ) =>
21
+ switch (Reventless.Email.fromString(input.email->String.trim), input.role) {
22
+ | (Error(_), _) => Error("not an email address")
23
+ | (Ok(email), role) =>
24
+ switch role
25
+ ->Option.map(String.trim)
26
+ ->Option.filter(r => r != "")
27
+ ->Option.map(Reventless.Role.make)
28
+ ->Option.orElse(defaultRole(App.table)) {
29
+ | None => Error("say which role to sign up for")
30
+ | Some(role) =>
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
+ }
49
+ }
50
+ }
51
+ }
@@ -0,0 +1,75 @@
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, capabilities, param) => {
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 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;
44
+ return {
45
+ TAG: "Ok",
46
+ _0: [[
47
+ ContactAddressId$ReventlessRegistration.toString(id),
48
+ {
49
+ TAG: "Register",
50
+ email: id,
51
+ address: address,
52
+ role: role,
53
+ requestedAt: new Date().toISOString()
54
+ }
55
+ ]]
56
+ };
57
+ };
58
+ return {
59
+ Spec: undefined,
60
+ moduleUrl: SignUp$ReventlessRegistration.moduleUrl,
61
+ translate: translate
62
+ };
63
+ }
64
+
65
+ let Spec;
66
+
67
+ let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/InboundTranslation/SignUp_Translation.res.mjs";
68
+
69
+ export {
70
+ Spec,
71
+ defaultRole,
72
+ Make,
73
+ moduleUrl,
74
+ }
75
+ /* Email-Reventless Not a pure module */
@@ -0,0 +1,40 @@
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
+ @pii({subject: "email"}) address: Reventless.Email.t,
20
+ roles: array<Reventless.Role.name>,
21
+ proofHash: string,
22
+ })
23
+
24
+ @schema
25
+ type outboundItem = {
26
+ email: string,
27
+ @pii({subject: "email"}) address: Reventless.Email.t,
28
+ roles: array<Reventless.Role.name>,
29
+ proofHash: string,
30
+ }
31
+
32
+ @schema
33
+ type inboundCommand = RecordRegistrationCompleted({email: ContactAddressId.t})
34
+
35
+ // For a provider that is down. The password is put back before each retry, so a
36
+ // retry finds it; once the budget is spent, it expires.
37
+ let maxRetries = 3
38
+ let targetName = Some("Registrations")
39
+ let sourceNames: array<string> = []
40
+ let capabilityNeeds = [Reventless.CapabilityNeed.Stash, Reventless.CapabilityNeed.IdentityProvider]