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

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 +6 -0
  10. package/src/Registration/ContactAddressId.res.mjs +29 -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 +40 -0
  14. package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res.mjs +67 -0
  15. package/src/Registration/InboundTranslation/SignUp.res +35 -0
  16. package/src/Registration/InboundTranslation/SignUp.res.mjs +57 -0
  17. package/src/Registration/InboundTranslation/SignUp_Translation.res +40 -0
  18. package/src/Registration/InboundTranslation/SignUp_Translation.res.mjs +66 -0
  19. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res +34 -0
  20. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res.mjs +61 -0
  21. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res +46 -0
  22. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res.mjs +99 -0
  23. package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res +45 -0
  24. package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res.mjs +78 -0
  25. package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res +103 -0
  26. package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res.mjs +150 -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 +157 -0
  32. package/src/Registration/StateChange/Registrations.res.mjs +224 -0
  33. package/src/Registration/StateChange/Registrations_Decision.res +281 -0
  34. package/src/Registration/StateChange/Registrations_Decision.res.mjs +541 -0
  35. package/src/Registration/StateViewStream/RegistrationWindows.res +27 -0
  36. package/src/Registration/StateViewStream/RegistrationWindows.res.mjs +77 -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,99 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Role$Reventless from "@reventlessdev/reventless-spec/src/types/Role.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
+ function groupsOf(roles) {
8
+ return roles.map(Role$Reventless.groupOf);
9
+ }
10
+
11
+ function collect(event, param) {
12
+ let proofHash = event.proofHash;
13
+ let email = event.email;
14
+ return [[
15
+ email + `:` + proofHash,
16
+ {
17
+ email: email,
18
+ roles: event.roles,
19
+ proofHash: proofHash
20
+ }
21
+ ]];
22
+ }
23
+
24
+ function completed(email) {
25
+ return {
26
+ TAG: "Ok",
27
+ _0: [
28
+ email,
29
+ {
30
+ TAG: "RecordRegistrationCompleted",
31
+ email: ContactAddressId$ReventlessRegistration.makeFromString(email)
32
+ }
33
+ ]
34
+ };
35
+ }
36
+
37
+ async function translate(_id, item, capabilities) {
38
+ let failure = await capabilities.stash.take(item.proofHash);
39
+ if (failure.TAG !== "Ok") {
40
+ return {
41
+ TAG: "Error",
42
+ _0: Stash$Reventless.failureReason(failure._0)
43
+ };
44
+ }
45
+ let password = failure._0;
46
+ if (password === undefined) {
47
+ return {
48
+ TAG: "Error",
49
+ _0: "the password expired before the account was made"
50
+ };
51
+ }
52
+ let match = await capabilities.identityProvider.createPrincipal({
53
+ TAG: "ToEmail",
54
+ _0: item.email
55
+ }, {
56
+ TAG: "Password",
57
+ _0: password
58
+ }, item.roles.map(Role$Reventless.groupOf));
59
+ if (match.TAG === "Ok") {
60
+ return completed(item.email);
61
+ }
62
+ let why = match._0;
63
+ if (typeof why !== "object") {
64
+ return completed(item.email);
65
+ }
66
+ if (why.TAG !== "Unavailable") {
67
+ return {
68
+ TAG: "Error",
69
+ _0: why._0
70
+ };
71
+ }
72
+ await capabilities.stash.put(item.proofHash, password, 600);
73
+ return {
74
+ TAG: "Error",
75
+ _0: why._0
76
+ };
77
+ }
78
+
79
+ function onExhausted(_id, _item, param) {
80
+
81
+ }
82
+
83
+ let Spec;
84
+
85
+ let retryTtl = 600;
86
+
87
+ let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res.mjs";
88
+
89
+ export {
90
+ Spec,
91
+ groupsOf,
92
+ retryTtl,
93
+ collect,
94
+ completed,
95
+ translate,
96
+ onExhausted,
97
+ moduleUrl,
98
+ }
99
+ /* Role-Reventless Not a pure module */
@@ -0,0 +1,45 @@
1
+ // SendRegistrationChallenge OutboundTranslationSlice.
2
+ //
3
+ // Writes to the address a registration names. A fresh registration gets a
4
+ // secret to prove control of the address, and the ledger records its hash; an
5
+ // invitation gets one too, worded as an invitation and holding for a week; a
6
+ // reissued code is a fresh secret worded as its claim was. An address that is
7
+ // already registered gets a notice instead, saying someone tried. The caller who started either sees the same answer — the difference
8
+ // arrives at the address, where only its owner reads it.
9
+ //
10
+ // The plaintext goes to the address and never into the log. On the local
11
+ // platform the log transport prints the message, which is how a developer reads
12
+ // the secret and finishes a registration with no mailbox at all.
13
+
14
+ @@reventless.spec
15
+
16
+ @schema
17
+ type consumedEvent =
18
+ | RegistrationRequested({email: string, requestedAt: Reventless.DateTime.t})
19
+ | RegistrationAttemptedOnTakenAddress({email: string, attemptedAt: Reventless.DateTime.t})
20
+ | RegistrationInvited({email: string, invitedBy: string, invitedAt: Reventless.DateTime.t})
21
+ | RegistrationChallengeReissued({
22
+ email: string,
23
+ reissuedAt: Reventless.DateTime.t,
24
+ invitedBy?: string,
25
+ })
26
+
27
+ /** `invited` words the secret as an invitation; it is left out for a sign-up
28
+ and for the notice. */
29
+ @schema
30
+ type outboundItem = {email: string, alreadyRegistered: bool, invited?: bool}
31
+
32
+ @schema
33
+ type inboundCommand =
34
+ | IssueRegistrationChallenge({
35
+ email: ContactAddressId.t,
36
+ proofHash: string,
37
+ issuedAt: Reventless.DateTime.t,
38
+ })
39
+
40
+ // For a mail transport that is down. Exhausting them opens no challenge, which
41
+ // leaves the registration to lapse and the address free to try again.
42
+ let maxRetries = 3
43
+ let targetName = Some("Registrations")
44
+ let sourceNames: array<string> = []
45
+ let capabilityNeeds = [Reventless.CapabilityNeed.Messaging]
@@ -0,0 +1,78 @@
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 ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
7
+
8
+ let consumedEventSchema = Sury.union([
9
+ Sury.$schema(s => ({
10
+ TAG: "RegistrationRequested",
11
+ email: s.m(Sury.string),
12
+ requestedAt: s.m(DateTime$Reventless.schema)
13
+ })),
14
+ Sury.$schema(s => ({
15
+ TAG: "RegistrationAttemptedOnTakenAddress",
16
+ email: s.m(Sury.string),
17
+ attemptedAt: s.m(DateTime$Reventless.schema)
18
+ })),
19
+ Sury.$schema(s => ({
20
+ TAG: "RegistrationInvited",
21
+ email: s.m(Sury.string),
22
+ invitedBy: s.m(Sury.string),
23
+ invitedAt: s.m(DateTime$Reventless.schema)
24
+ })),
25
+ Sury.$schema(s => ({
26
+ TAG: "RegistrationChallengeReissued",
27
+ email: s.m(Sury.string),
28
+ reissuedAt: s.m(DateTime$Reventless.schema),
29
+ invitedBy: s.m(Sury.$option(Sury.string))
30
+ }))
31
+ ]);
32
+
33
+ let outboundItemSchema = Sury.$schema(s => ({
34
+ email: s.m(Sury.string),
35
+ alreadyRegistered: s.m(Sury.boolean),
36
+ invited: s.m(Sury.$option(Sury.boolean))
37
+ }));
38
+
39
+ let inboundCommandSchema = Sury.$schema(s => ({
40
+ TAG: "IssueRegistrationChallenge",
41
+ email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
42
+ proofHash: s.m(Sury.string),
43
+ issuedAt: s.m(DateTime$Reventless.schema)
44
+ }));
45
+
46
+ let sourceNames = [];
47
+
48
+ let capabilityNeeds = ["Messaging"];
49
+
50
+ let traits = [];
51
+
52
+ let name = "SendRegistrationChallenge";
53
+
54
+ let Id;
55
+
56
+ let maxRetries = 3;
57
+
58
+ let targetName = "Registrations";
59
+
60
+ let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/OutboundTranslation/SendRegistrationChallenge.res.mjs";
61
+
62
+ let externalSystem;
63
+
64
+ export {
65
+ name,
66
+ Id,
67
+ consumedEventSchema,
68
+ outboundItemSchema,
69
+ inboundCommandSchema,
70
+ maxRetries,
71
+ targetName,
72
+ sourceNames,
73
+ capabilityNeeds,
74
+ moduleUrl,
75
+ externalSystem,
76
+ traits,
77
+ }
78
+ /* consumedEventSchema Not a pure module */
@@ -0,0 +1,103 @@
1
+ @@reventless.translation
2
+
3
+ // Keyed by address, arm and time, so a registration made again after one lapsed,
4
+ // or a code reissued, is new work rather than work already done.
5
+ let collect = (event, ~sourceId as _) =>
6
+ switch event {
7
+ | RegistrationRequested({email, requestedAt}) => [
8
+ (`${email}:${requestedAt->Reventless.DateTime.toString}`, {email, alreadyRegistered: false}),
9
+ ]
10
+ | RegistrationInvited({email, invitedAt}) => [
11
+ (
12
+ `${email}:invited:${invitedAt->Reventless.DateTime.toString}`,
13
+ {email, alreadyRegistered: false, invited: true},
14
+ ),
15
+ ]
16
+ | RegistrationChallengeReissued({email, reissuedAt, ?invitedBy}) => [
17
+ (
18
+ `${email}:reissued:${reissuedAt->Reventless.DateTime.toString}`,
19
+ {email, alreadyRegistered: false, invited: invitedBy->Option.isSome},
20
+ ),
21
+ ]
22
+ | RegistrationAttemptedOnTakenAddress({email, attemptedAt}) => [
23
+ (
24
+ `${email}:taken:${attemptedAt->Reventless.DateTime.toString}`,
25
+ {email, alreadyRegistered: true},
26
+ ),
27
+ ]
28
+ }
29
+
30
+ let expiresIn = (~invited) =>
31
+ RegistrationChallenge.policyFor(
32
+ RegistrationChallenge.purposeFor(~invited),
33
+ ).tokenTtl->Reventless.Duration.format
34
+
35
+ let challengeBody = (~token) =>
36
+ `Your registration code is ${token}. Enter it with a password of your choice to finish. It expires in ${expiresIn(
37
+ ~invited=false,
38
+ )}.`
39
+
40
+ let invitationBody = (~token) =>
41
+ `You have been invited to create an account. Your code is ${token}. Enter it with this address and a password of your choice to accept. It expires in ${expiresIn(
42
+ ~invited=true,
43
+ )}.`
44
+
45
+ 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."
46
+
47
+ let send = (capabilities: Reventless.Capabilities.t, ~email, ~subject, ~body) =>
48
+ capabilities.messaging.send(
49
+ ~recipient=ToEmail(Reventless.Email.unsafe(email)),
50
+ ~message={subject, body},
51
+ )
52
+
53
+ /**
54
+ Draw a secret, send it, and open a challenge against its hash — sending first,
55
+ so the hash that is recorded is always the one that was delivered.
56
+ */
57
+ let translate = async (_id, item: outboundItem, ~capabilities: Reventless.Capabilities.t) =>
58
+ if item.alreadyRegistered {
59
+ switch await send(
60
+ capabilities,
61
+ ~email=item.email,
62
+ ~subject="Someone tried to register with your address",
63
+ ~body=noticeBody,
64
+ ) {
65
+ | Ok(_) => Ok(None)
66
+ | Error(failure) => Error(Reventless.Messaging.failureReason(failure))
67
+ }
68
+ } else {
69
+ let invited = item.invited->Option.getOr(false)
70
+ let policy = RegistrationChallenge.policyFor(RegistrationChallenge.purposeFor(~invited))
71
+ switch capabilities.secrets.randomToken(
72
+ ~length=policy.proofLength,
73
+ ~alphabet=policy.proofAlphabet,
74
+ ) {
75
+ | Error(Unavailable(why)) => Error(`no secret source: ${why}`)
76
+ | Ok(token) =>
77
+ switch capabilities.secrets.hash(token) {
78
+ | Error(Unavailable(why)) => Error(`cannot hash a secret: ${why}`)
79
+ | Ok(proofHash) =>
80
+ switch await send(
81
+ capabilities,
82
+ ~email=item.email,
83
+ ~subject=invited ? "You are invited to create an account" : "Finish your registration",
84
+ ~body=invited ? invitationBody(~token) : challengeBody(~token),
85
+ ) {
86
+ | Ok(_) =>
87
+ Ok(
88
+ Some((
89
+ item.email,
90
+ IssueRegistrationChallenge({
91
+ email: ContactAddressId.makeFromString(item.email),
92
+ proofHash,
93
+ issuedAt: Date.make()->Date.toISOString->Reventless.DateTime.unsafe,
94
+ }),
95
+ )),
96
+ )
97
+ | Error(failure) => Error(Reventless.Messaging.failureReason(failure))
98
+ }
99
+ }
100
+ }
101
+ }
102
+
103
+ let onExhausted = (_id, _item: outboundItem, ~lastError as _) => None
@@ -0,0 +1,150 @@
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 Duration$Reventless from "@reventlessdev/reventless-spec/src/semantic/Duration.res.mjs";
5
+ import * as Messaging$Reventless from "@reventlessdev/reventless-spec/src/semantic/Messaging.res.mjs";
6
+ import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
7
+ import * as RegistrationChallenge$ReventlessRegistration from "../../RegistrationChallenge.res.mjs";
8
+
9
+ function collect(event, param) {
10
+ switch (event.TAG) {
11
+ case "RegistrationRequested" :
12
+ let email = event.email;
13
+ return [[
14
+ email + `:` + event.requestedAt,
15
+ {
16
+ email: email,
17
+ alreadyRegistered: false
18
+ }
19
+ ]];
20
+ case "RegistrationAttemptedOnTakenAddress" :
21
+ let email$1 = event.email;
22
+ return [[
23
+ email$1 + `:taken:` + event.attemptedAt,
24
+ {
25
+ email: email$1,
26
+ alreadyRegistered: true
27
+ }
28
+ ]];
29
+ case "RegistrationInvited" :
30
+ let email$2 = event.email;
31
+ return [[
32
+ email$2 + `:invited:` + event.invitedAt,
33
+ {
34
+ email: email$2,
35
+ alreadyRegistered: false,
36
+ invited: true
37
+ }
38
+ ]];
39
+ case "RegistrationChallengeReissued" :
40
+ let email$3 = event.email;
41
+ return [[
42
+ email$3 + `:reissued:` + event.reissuedAt,
43
+ {
44
+ email: email$3,
45
+ alreadyRegistered: false,
46
+ invited: Stdlib_Option.isSome(event.invitedBy)
47
+ }
48
+ ]];
49
+ }
50
+ }
51
+
52
+ function expiresIn(invited) {
53
+ return Duration$Reventless.format(RegistrationChallenge$ReventlessRegistration.policyFor(RegistrationChallenge$ReventlessRegistration.purposeFor(invited)).tokenTtl);
54
+ }
55
+
56
+ function challengeBody(token) {
57
+ return `Your registration code is ` + token + `. Enter it with a password of your choice to finish. It expires in ` + expiresIn(false) + `.`;
58
+ }
59
+
60
+ function invitationBody(token) {
61
+ return `You have been invited to create an account. Your code is ` + token + `. Enter it with this address and a password of your choice to accept. It expires in ` + expiresIn(true) + `.`;
62
+ }
63
+
64
+ 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.";
65
+
66
+ function send(capabilities, email, subject, body) {
67
+ return capabilities.messaging.send({
68
+ TAG: "ToEmail",
69
+ _0: email
70
+ }, {
71
+ subject: subject,
72
+ body: body
73
+ });
74
+ }
75
+
76
+ async function translate(_id, item, capabilities) {
77
+ if (item.alreadyRegistered) {
78
+ let failure = await send(capabilities, item.email, "Someone tried to register with your address", noticeBody);
79
+ if (failure.TAG === "Ok") {
80
+ return {
81
+ TAG: "Ok",
82
+ _0: undefined
83
+ };
84
+ } else {
85
+ return {
86
+ TAG: "Error",
87
+ _0: Messaging$Reventless.failureReason(failure._0)
88
+ };
89
+ }
90
+ }
91
+ let invited = Stdlib_Option.getOr(item.invited, false);
92
+ let policy = RegistrationChallenge$ReventlessRegistration.policyFor(RegistrationChallenge$ReventlessRegistration.purposeFor(invited));
93
+ let token = capabilities.secrets.randomToken(policy.proofLength, policy.proofAlphabet);
94
+ if (token.TAG !== "Ok") {
95
+ return {
96
+ TAG: "Error",
97
+ _0: `no secret source: ` + token._0._0
98
+ };
99
+ }
100
+ let token$1 = token._0;
101
+ let proofHash = capabilities.secrets.hash(token$1);
102
+ if (proofHash.TAG !== "Ok") {
103
+ return {
104
+ TAG: "Error",
105
+ _0: `cannot hash a secret: ` + proofHash._0._0
106
+ };
107
+ }
108
+ let failure$1 = await send(capabilities, item.email, invited ? "You are invited to create an account" : "Finish your registration", invited ? invitationBody(token$1) : challengeBody(token$1));
109
+ if (failure$1.TAG === "Ok") {
110
+ return {
111
+ TAG: "Ok",
112
+ _0: [
113
+ item.email,
114
+ {
115
+ TAG: "IssueRegistrationChallenge",
116
+ email: ContactAddressId$ReventlessRegistration.makeFromString(item.email),
117
+ proofHash: proofHash._0,
118
+ issuedAt: new Date().toISOString()
119
+ }
120
+ ]
121
+ };
122
+ } else {
123
+ return {
124
+ TAG: "Error",
125
+ _0: Messaging$Reventless.failureReason(failure$1._0)
126
+ };
127
+ }
128
+ }
129
+
130
+ function onExhausted(_id, _item, param) {
131
+
132
+ }
133
+
134
+ let Spec;
135
+
136
+ let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res.mjs";
137
+
138
+ export {
139
+ Spec,
140
+ collect,
141
+ expiresIn,
142
+ challengeBody,
143
+ invitationBody,
144
+ noticeBody,
145
+ send,
146
+ translate,
147
+ onExhausted,
148
+ moduleUrl,
149
+ }
150
+ /* Duration-Reventless Not a pure module */
@@ -0,0 +1,58 @@
1
+ // RegistrationPolicy StateChangeSlice.
2
+ //
3
+ // Whether visitors may sign themselves up for a role right now, as domain state
4
+ // an administrator changes with a command rather than a deploy. Kept per role:
5
+ // only a role the app declares self-service has a policy at all, and
6
+ // such a role is open until an administrator closes it — the declaration is the
7
+ // deployer's opt-in, so needing a second command to make it do anything would be
8
+ // a trap.
9
+ //
10
+ // An open window may carry an end, checked against the time the registration
11
+ // arrived, so a test window someone forgets to close closes itself.
12
+
13
+ @@reventless.spec
14
+ @@reventless.authorize(AllowRoles([Admin]))
15
+
16
+ // The one role this slice's rule names: the framework's administrator, whose
17
+ // group the deployment provides. Declared here rather than in a `Roles.res`, so
18
+ // the package has no `Roles` of its own beside the app's.
19
+ module Roles = {
20
+ type t = Admin
21
+ }
22
+
23
+ // The role is this slice's partition, tagged by its type: a role is an identity
24
+ // the framework declares, not an id the plugin names.
25
+ @schema
26
+ type consumedEvent =
27
+ | RegistrationOpened({
28
+ role: @s.matches(Reventless.DcbTag.mark(Reventless.Role.nameSchema)) Reventless.Role.name,
29
+ until?: Reventless.DateTime.t,
30
+ })
31
+ | RegistrationClosed({
32
+ role: @s.matches(Reventless.DcbTag.mark(Reventless.Role.nameSchema)) Reventless.Role.name,
33
+ })
34
+
35
+ @schema
36
+ type command =
37
+ | OpenRegistration({
38
+ role: @s.matches(Reventless.DcbTag.mark(Reventless.Role.nameSchema)) Reventless.Role.name,
39
+ until?: Reventless.DateTime.t,
40
+ })
41
+ | CloseRegistration({
42
+ role: @s.matches(Reventless.DcbTag.mark(Reventless.Role.nameSchema)) Reventless.Role.name,
43
+ })
44
+
45
+ // Told to an administrator, never to a visitor: this slice's commands are an
46
+ // administrator's.
47
+ @schema
48
+ type error = NotSelfService({role: Reventless.Role.name})
49
+
50
+ @schema
51
+ type event =
52
+ | RegistrationOpened({
53
+ role: @s.matches(Reventless.DcbTag.mark(Reventless.Role.nameSchema)) Reventless.Role.name,
54
+ until?: Reventless.DateTime.t,
55
+ })
56
+ | RegistrationClosed({
57
+ role: @s.matches(Reventless.DcbTag.mark(Reventless.Role.nameSchema)) Reventless.Role.name,
58
+ })
@@ -0,0 +1,86 @@
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
+
8
+ let Roles = {};
9
+
10
+ let consumedEventSchema = Sury.union([
11
+ Sury.$schema(s => ({
12
+ TAG: "RegistrationOpened",
13
+ role: s.m(DcbTag$Reventless.mark(Role$Reventless.nameSchema)),
14
+ until: s.m(Sury.$option(DateTime$Reventless.schema))
15
+ })),
16
+ Sury.$schema(s => ({
17
+ TAG: "RegistrationClosed",
18
+ role: s.m(DcbTag$Reventless.mark(Role$Reventless.nameSchema))
19
+ }))
20
+ ]);
21
+
22
+ let commandSchema = Sury.union([
23
+ Sury.$schema(s => ({
24
+ TAG: "OpenRegistration",
25
+ role: s.m(DcbTag$Reventless.mark(Role$Reventless.nameSchema)),
26
+ until: s.m(Sury.$option(DateTime$Reventless.schema))
27
+ })),
28
+ Sury.$schema(s => ({
29
+ TAG: "CloseRegistration",
30
+ role: s.m(DcbTag$Reventless.mark(Role$Reventless.nameSchema))
31
+ }))
32
+ ]);
33
+
34
+ let errorSchema = Sury.$schema(s => ({
35
+ TAG: "NotSelfService",
36
+ role: s.m(Role$Reventless.nameSchema)
37
+ }));
38
+
39
+ let eventSchema = Sury.union([
40
+ Sury.$schema(s => ({
41
+ TAG: "RegistrationOpened",
42
+ role: s.m(DcbTag$Reventless.mark(Role$Reventless.nameSchema)),
43
+ until: s.m(Sury.$option(DateTime$Reventless.schema))
44
+ })),
45
+ Sury.$schema(s => ({
46
+ TAG: "RegistrationClosed",
47
+ role: s.m(DcbTag$Reventless.mark(Role$Reventless.nameSchema))
48
+ }))
49
+ ]);
50
+
51
+ function authorizationOf(param) {
52
+ return {
53
+ TAG: "AllowRoles",
54
+ _0: ["Admin"]
55
+ };
56
+ }
57
+
58
+ function commandTransition(param) {
59
+ return "Undeclared";
60
+ }
61
+
62
+ let traits = [];
63
+
64
+ let name = "RegistrationPolicy";
65
+
66
+ let Id;
67
+
68
+ let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/StateChange/RegistrationPolicy.res.mjs";
69
+
70
+ let readConsistency = "EscalateOnRetry";
71
+
72
+ export {
73
+ name,
74
+ Id,
75
+ Roles,
76
+ consumedEventSchema,
77
+ commandSchema,
78
+ errorSchema,
79
+ eventSchema,
80
+ moduleUrl,
81
+ authorizationOf,
82
+ readConsistency,
83
+ commandTransition,
84
+ traits,
85
+ }
86
+ /* consumedEventSchema Not a pure module */
@@ -0,0 +1,43 @@
1
+ @@reventless.decision
2
+
3
+ // Nothing recorded is open: a role reaches this slice only if the app declares
4
+ // it self-service. Opening an open role with the same end, or closing a closed
5
+ // one, changes nothing and records nothing.
6
+
7
+ type state =
8
+ | Closed
9
+ | Open(option<Reventless.DateTime.t>)
10
+
11
+ let initialState = Open(None)
12
+
13
+ let evolve = (_state, event) =>
14
+ switch event {
15
+ | RegistrationOpened({?until}) => Open(until)
16
+ | RegistrationClosed(_) => Closed
17
+ }
18
+
19
+ /** The decision over the app's table, which says which roles are self-service. */
20
+ module Make = (App: Reventless.Admission.Declaration) => {
21
+ module Spec = Spec
22
+ let moduleUrl = moduleUrl
23
+
24
+ type state = state
25
+ let initialState = initialState
26
+ let evolve = evolve
27
+
28
+ let decide = (state, command) => {
29
+ let role = switch command {
30
+ | OpenRegistration({role}) | CloseRegistration({role}) => role
31
+ }
32
+ if !(App.table->Reventless.Admission.isSelfService(role)) {
33
+ Error(NotSelfService({role: role}))
34
+ } else {
35
+ switch (state, command) {
36
+ | (Open(current), OpenRegistration({?until})) if current == until => Ok([])
37
+ | (_, OpenRegistration({role, ?until})) => Ok([RegistrationOpened({role, ?until})])
38
+ | (Closed, CloseRegistration(_)) => Ok([])
39
+ | (Open(_), CloseRegistration({role})) => Ok([RegistrationClosed({role: role})])
40
+ }
41
+ }
42
+ }
43
+ }