@reventlessdev/reventless-registration 1.0.0-alpha.38 → 1.0.0-alpha.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/Registration/InboundTranslation/SignUp.res +15 -7
- package/src/Registration/InboundTranslation/SignUp.res.mjs +6 -3
- package/src/Registration/InboundTranslation/SignUp_Translation.res +18 -3
- package/src/Registration/InboundTranslation/SignUp_Translation.res.mjs +26 -5
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res +3 -0
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res.mjs +3 -0
- package/src/Registration/StateChange/RegistrationPolicy.res +3 -0
- package/src/Registration/StateChange/RegistrationPolicy.res.mjs +3 -0
- package/src/Registration/StateChange/RegistrationPolicy_Decision.res +6 -5
- package/src/Registration/StateChange/RegistrationPolicy_Decision.res.mjs +22 -15
- package/src/Registration/StateChange/Registrations.res +3 -0
- package/src/Registration/StateChange/Registrations.res.mjs +3 -1
- package/src/Registration/StateChange/Registrations_Decision.res +23 -11
- package/src/Registration/StateChange/Registrations_Decision.res.mjs +13 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reventlessdev/reventless-registration",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.39",
|
|
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": [
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"sury": "11.1.0",
|
|
16
16
|
"sury-ppx": "11.1.0",
|
|
17
|
-
"@reventlessdev/reventless-
|
|
18
|
-
"@reventlessdev/reventless-
|
|
19
|
-
"@reventlessdev/reventless-spec": "3.0.0-alpha.
|
|
17
|
+
"@reventlessdev/reventless-infra": "3.0.0-alpha.240",
|
|
18
|
+
"@reventlessdev/reventless-ppx": "^1.0.0-alpha.118",
|
|
19
|
+
"@reventlessdev/reventless-spec": "3.0.0-alpha.209"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"rescript": "12.3.1"
|
|
@@ -7,19 +7,26 @@
|
|
|
7
7
|
// learns none of it: a closed role, a role no visitor may have, a taken address
|
|
8
8
|
// and a fresh one all answer alike.
|
|
9
9
|
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
10
|
+
// First it asks the person check whether a person sent the request; a missing,
|
|
11
|
+
// failed or unanswerable check relays nothing and says so, which names no address.
|
|
12
|
+
//
|
|
13
|
+
// Anonymous because the caller is trying to become someone. A deployed platform
|
|
14
|
+
// hosts it on a door for visitors, with its guards.
|
|
14
15
|
|
|
15
16
|
@@reventless.spec
|
|
16
17
|
@@reventless.authorize(AllowAnonymous)
|
|
17
18
|
|
|
18
19
|
/** `role` may be left out where exactly one role is open to visitors; with
|
|
19
20
|
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.
|
|
21
|
+
shell in, which their mails are written in where the deployment offers it.
|
|
22
|
+
`personCheck` is the token of the widget the deployment names, if it names one. */
|
|
21
23
|
@schema
|
|
22
|
-
type externalInput = {
|
|
24
|
+
type externalInput = {
|
|
25
|
+
@sensitive email: string,
|
|
26
|
+
role?: string,
|
|
27
|
+
language?: string,
|
|
28
|
+
@sensitive personCheck?: string,
|
|
29
|
+
}
|
|
23
30
|
|
|
24
31
|
@schema
|
|
25
32
|
type command =
|
|
@@ -29,10 +36,11 @@ type command =
|
|
|
29
36
|
role: Reventless.Role.name,
|
|
30
37
|
requestedAt: Reventless.DateTime.t,
|
|
31
38
|
language?: string,
|
|
39
|
+
initially?: @s.matches(Reventless.Admission.initiallySchema) Reventless.Admission.initially,
|
|
32
40
|
})
|
|
33
41
|
|
|
34
42
|
let targetName = "Registrations"
|
|
35
|
-
let capabilityNeeds
|
|
43
|
+
let capabilityNeeds = [Reventless.CapabilityNeed.PersonCheck]
|
|
36
44
|
|
|
37
45
|
/** This door starts a registration; the platform tells the shell so. */
|
|
38
46
|
let admissionDoor = Reventless.Admission.Start
|
|
@@ -6,13 +6,15 @@ import * as Role$Reventless from "@reventlessdev/reventless-spec/src/types/Role.
|
|
|
6
6
|
import * as Email$Reventless from "@reventlessdev/reventless-spec/src/semantic/Email.res.mjs";
|
|
7
7
|
import * as DcbTag$Reventless from "@reventlessdev/reventless-spec/src/components/DcbTag.res.mjs";
|
|
8
8
|
import * as DateTime$Reventless from "@reventlessdev/reventless-spec/src/semantic/DateTime.res.mjs";
|
|
9
|
+
import * as Admission$Reventless from "@reventlessdev/reventless-spec/src/types/Admission.res.mjs";
|
|
9
10
|
import * as Sensitive$Reventless from "@reventlessdev/reventless-spec/src/components/Sensitive.res.mjs";
|
|
10
11
|
import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
|
|
11
12
|
|
|
12
13
|
let externalInputSchema = Sury.$schema(s => ({
|
|
13
14
|
email: s.m(Sensitive$Reventless.string),
|
|
14
15
|
role: s.m(Sury.$option(Sury.string)),
|
|
15
|
-
language: s.m(Sury.$option(Sury.string))
|
|
16
|
+
language: s.m(Sury.$option(Sury.string)),
|
|
17
|
+
personCheck: s.m(Sury.$option(Sensitive$Reventless.string))
|
|
16
18
|
}));
|
|
17
19
|
|
|
18
20
|
let commandSchema = Sury.$schema(s => ({
|
|
@@ -21,10 +23,11 @@ let commandSchema = Sury.$schema(s => ({
|
|
|
21
23
|
email: s.m(Pii$Reventless.mark("emailId", undefined, Email$Reventless.schema)),
|
|
22
24
|
role: s.m(Role$Reventless.nameSchema),
|
|
23
25
|
requestedAt: s.m(DateTime$Reventless.schema),
|
|
24
|
-
language: s.m(Sury.$option(Sury.string))
|
|
26
|
+
language: s.m(Sury.$option(Sury.string)),
|
|
27
|
+
initially: s.m(Sury.$option(Admission$Reventless.initiallySchema))
|
|
25
28
|
}));
|
|
26
29
|
|
|
27
|
-
let capabilityNeeds = [];
|
|
30
|
+
let capabilityNeeds = ["PersonCheck"];
|
|
28
31
|
|
|
29
32
|
function authorizationOf(param) {
|
|
30
33
|
return "AllowAnonymous";
|
|
@@ -17,6 +17,14 @@ let languageOf = (raw: option<string>): option<string> =>
|
|
|
17
17
|
String.length(tag) <= 35 && /^[A-Za-z]{2,3}(-[A-Za-z0-9]{1,8})*$/->RegExp.test(tag)
|
|
18
18
|
)
|
|
19
19
|
|
|
20
|
+
/** What a sign-up is told when the check says no: the same whatever the address,
|
|
21
|
+
so it says nothing of one. */
|
|
22
|
+
let personCheckRejected = "the check that a person is signing up did not pass; try it again"
|
|
23
|
+
|
|
24
|
+
/** What it is told when the check cannot be asked. Refused rather than let through,
|
|
25
|
+
so a check that is down never opens the door to scripts. */
|
|
26
|
+
let personCheckUnavailable = "the check that a person is signing up cannot be reached; try again later"
|
|
27
|
+
|
|
20
28
|
/** The door over the app's table, which picks the role a sign-up may leave out. */
|
|
21
29
|
module Make = (App: Reventless.Admission.Declaration) => {
|
|
22
30
|
module Spec = Spec
|
|
@@ -27,9 +35,15 @@ module Make = (App: Reventless.Admission.Declaration) => {
|
|
|
27
35
|
~capabilities: Reventless.Capabilities.t,
|
|
28
36
|
~caller as _,
|
|
29
37
|
) =>
|
|
30
|
-
switch (
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
switch (
|
|
39
|
+
await capabilities.personCheck.verify(~token=input.personCheck->Option.getOr("")),
|
|
40
|
+
Reventless.Email.fromString(input.email->String.trim),
|
|
41
|
+
input.role,
|
|
42
|
+
) {
|
|
43
|
+
| (Error(Rejected(_)), _, _) => Error(personCheckRejected)
|
|
44
|
+
| (Error(Unavailable(_)), _, _) => Error(personCheckUnavailable)
|
|
45
|
+
| (Ok(), Error(_), _) => Error("not an email address")
|
|
46
|
+
| (Ok(), Ok(typed), role) =>
|
|
33
47
|
switch role
|
|
34
48
|
->Option.map(String.trim)
|
|
35
49
|
->Option.filter(r => r != "")
|
|
@@ -52,6 +66,7 @@ module Make = (App: Reventless.Admission.Declaration) => {
|
|
|
52
66
|
role,
|
|
53
67
|
requestedAt: Date.make()->Date.toISOString->Reventless.DateTime.unsafe,
|
|
54
68
|
language: ?languageOf(input.language),
|
|
69
|
+
initially: capabilities.selfRegistrationInitially,
|
|
55
70
|
}),
|
|
56
71
|
),
|
|
57
72
|
])
|
|
@@ -25,24 +25,42 @@ function languageOf(raw) {
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
let personCheckRejected = "the check that a person is signing up did not pass; try it again";
|
|
29
|
+
|
|
30
|
+
let personCheckUnavailable = "the check that a person is signing up cannot be reached; try again later";
|
|
31
|
+
|
|
28
32
|
function Make(App) {
|
|
29
33
|
let translate = async (input, capabilities, param) => {
|
|
30
|
-
let match =
|
|
31
|
-
let match$1 = input.
|
|
34
|
+
let match = await capabilities.personCheck.verify(Stdlib_Option.getOr(input.personCheck, ""));
|
|
35
|
+
let match$1 = Email$Reventless.fromString(input.email.trim());
|
|
36
|
+
let match$2 = input.role;
|
|
32
37
|
if (match.TAG !== "Ok") {
|
|
38
|
+
if (match._0.TAG === "Rejected") {
|
|
39
|
+
return {
|
|
40
|
+
TAG: "Error",
|
|
41
|
+
_0: personCheckRejected
|
|
42
|
+
};
|
|
43
|
+
} else {
|
|
44
|
+
return {
|
|
45
|
+
TAG: "Error",
|
|
46
|
+
_0: personCheckUnavailable
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (match$1.TAG !== "Ok") {
|
|
33
51
|
return {
|
|
34
52
|
TAG: "Error",
|
|
35
53
|
_0: "not an email address"
|
|
36
54
|
};
|
|
37
55
|
}
|
|
38
|
-
let role = Stdlib_Option.orElse(Stdlib_Option.map(Stdlib_Option.filter(Stdlib_Option.map(match$
|
|
56
|
+
let role = Stdlib_Option.orElse(Stdlib_Option.map(Stdlib_Option.filter(Stdlib_Option.map(match$2, prim => prim.trim()), r => r !== ""), prim => prim), defaultRole(App.table));
|
|
39
57
|
if (role === undefined) {
|
|
40
58
|
return {
|
|
41
59
|
TAG: "Error",
|
|
42
60
|
_0: "say which role to sign up for"
|
|
43
61
|
};
|
|
44
62
|
}
|
|
45
|
-
let email = ContactAddressId$ReventlessRegistration.normalize(match._0);
|
|
63
|
+
let email = ContactAddressId$ReventlessRegistration.normalize(match$1._0);
|
|
46
64
|
let why = ContactAddressId$ReventlessRegistration.fingerprint(capabilities.secrets, email);
|
|
47
65
|
if (why.TAG !== "Ok") {
|
|
48
66
|
return {
|
|
@@ -61,7 +79,8 @@ function Make(App) {
|
|
|
61
79
|
email: email,
|
|
62
80
|
role: role,
|
|
63
81
|
requestedAt: new Date().toISOString(),
|
|
64
|
-
language: languageOf(input.language)
|
|
82
|
+
language: languageOf(input.language),
|
|
83
|
+
initially: capabilities.selfRegistrationInitially
|
|
65
84
|
}
|
|
66
85
|
]]
|
|
67
86
|
};
|
|
@@ -81,6 +100,8 @@ export {
|
|
|
81
100
|
Spec,
|
|
82
101
|
defaultRole,
|
|
83
102
|
languageOf,
|
|
103
|
+
personCheckRejected,
|
|
104
|
+
personCheckUnavailable,
|
|
84
105
|
Make,
|
|
85
106
|
moduleUrl,
|
|
86
107
|
}
|
|
@@ -78,3 +78,6 @@ let maxRetries = 3
|
|
|
78
78
|
let targetName = Some("Registrations")
|
|
79
79
|
let sourceNames: array<string> = []
|
|
80
80
|
let capabilityNeeds = [Reventless.CapabilityNeed.Messaging]
|
|
81
|
+
|
|
82
|
+
/** This slice writes to the addresses visitors name; a deployment caps its mail per day. */
|
|
83
|
+
let admissionDoor = Reventless.Admission.Mail
|
|
@@ -72,6 +72,8 @@ let maxRetries = 3;
|
|
|
72
72
|
|
|
73
73
|
let targetName = "Registrations";
|
|
74
74
|
|
|
75
|
+
let admissionDoor = "mail";
|
|
76
|
+
|
|
75
77
|
let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/OutboundTranslation/SendRegistrationChallenge.res.mjs";
|
|
76
78
|
|
|
77
79
|
let externalSystem;
|
|
@@ -86,6 +88,7 @@ export {
|
|
|
86
88
|
targetName,
|
|
87
89
|
sourceNames,
|
|
88
90
|
capabilityNeeds,
|
|
91
|
+
admissionDoor,
|
|
89
92
|
moduleUrl,
|
|
90
93
|
externalSystem,
|
|
91
94
|
traits,
|
|
@@ -56,3 +56,6 @@ type event =
|
|
|
56
56
|
| RegistrationClosed({
|
|
57
57
|
role: @s.matches(Reventless.DcbTag.mark(Reventless.Role.nameSchema)) Reventless.Role.name,
|
|
58
58
|
})
|
|
59
|
+
|
|
60
|
+
/** This decision opens and closes a role; the platform tells the shell so. */
|
|
61
|
+
let admissionDoor = Reventless.Admission.Policy
|
|
@@ -65,6 +65,8 @@ let name = "RegistrationPolicy";
|
|
|
65
65
|
|
|
66
66
|
let Id;
|
|
67
67
|
|
|
68
|
+
let admissionDoor = "policy";
|
|
69
|
+
|
|
68
70
|
let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/StateChange/RegistrationPolicy.res.mjs";
|
|
69
71
|
|
|
70
72
|
let readConsistency = "EscalateOnRetry";
|
|
@@ -77,6 +79,7 @@ export {
|
|
|
77
79
|
commandSchema,
|
|
78
80
|
errorSchema,
|
|
79
81
|
eventSchema,
|
|
82
|
+
admissionDoor,
|
|
80
83
|
moduleUrl,
|
|
81
84
|
authorizationOf,
|
|
82
85
|
readConsistency,
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
@@reventless.decision
|
|
2
2
|
|
|
3
|
-
// Nothing recorded is
|
|
4
|
-
// it
|
|
5
|
-
// one, changes nothing and records nothing.
|
|
3
|
+
// Nothing recorded is the deployment's starting state, which this slice does not
|
|
4
|
+
// know: from it, opening and closing both record. Opening an open role with the
|
|
5
|
+
// same end, or closing a closed one, changes nothing and records nothing.
|
|
6
6
|
|
|
7
7
|
type state =
|
|
8
|
+
| Unset
|
|
8
9
|
| Closed
|
|
9
10
|
| Open(option<Reventless.DateTime.t>)
|
|
10
11
|
|
|
11
|
-
let initialState =
|
|
12
|
+
let initialState = Unset
|
|
12
13
|
|
|
13
14
|
let evolve = (_state, event) =>
|
|
14
15
|
switch event {
|
|
@@ -36,7 +37,7 @@ module Make = (App: Reventless.Admission.Declaration) => {
|
|
|
36
37
|
| (Open(current), OpenRegistration({?until})) if current == until => Ok([])
|
|
37
38
|
| (_, OpenRegistration({role, ?until})) => Ok([RegistrationOpened({role, ?until})])
|
|
38
39
|
| (Closed, CloseRegistration(_)) => Ok([])
|
|
39
|
-
| (Open(_), CloseRegistration({role})) => Ok([RegistrationClosed({role: role})])
|
|
40
|
+
| (Open(_) | Unset, CloseRegistration({role})) => Ok([RegistrationClosed({role: role})])
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
}
|
|
@@ -4,11 +4,6 @@ import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js
|
|
|
4
4
|
import * as Admission$Reventless from "@reventlessdev/reventless-spec/src/types/Admission.res.mjs";
|
|
5
5
|
import * as RegistrationPolicy$ReventlessRegistration from "./RegistrationPolicy.res.mjs";
|
|
6
6
|
|
|
7
|
-
let initialState = {
|
|
8
|
-
TAG: "Open",
|
|
9
|
-
_0: undefined
|
|
10
|
-
};
|
|
11
|
-
|
|
12
7
|
function evolve(_state, event) {
|
|
13
8
|
if (event.TAG === "RegistrationOpened") {
|
|
14
9
|
return {
|
|
@@ -33,7 +28,7 @@ function Make(App) {
|
|
|
33
28
|
};
|
|
34
29
|
}
|
|
35
30
|
if (typeof state !== "object") {
|
|
36
|
-
if (command.TAG !== "OpenRegistration") {
|
|
31
|
+
if (state !== "Unset" && command.TAG !== "OpenRegistration") {
|
|
37
32
|
return {
|
|
38
33
|
TAG: "Ok",
|
|
39
34
|
_0: []
|
|
@@ -56,19 +51,29 @@ function Make(App) {
|
|
|
56
51
|
};
|
|
57
52
|
}
|
|
58
53
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
54
|
+
if (command.TAG === "OpenRegistration") {
|
|
55
|
+
return {
|
|
56
|
+
TAG: "Ok",
|
|
57
|
+
_0: [{
|
|
58
|
+
TAG: "RegistrationOpened",
|
|
59
|
+
role: command.role,
|
|
60
|
+
until: command.until
|
|
61
|
+
}]
|
|
62
|
+
};
|
|
63
|
+
} else {
|
|
64
|
+
return {
|
|
65
|
+
TAG: "Ok",
|
|
66
|
+
_0: [{
|
|
67
|
+
TAG: "RegistrationClosed",
|
|
68
|
+
role: command.role
|
|
69
|
+
}]
|
|
70
|
+
};
|
|
71
|
+
}
|
|
67
72
|
};
|
|
68
73
|
return {
|
|
69
74
|
Spec: undefined,
|
|
70
75
|
moduleUrl: RegistrationPolicy$ReventlessRegistration.moduleUrl,
|
|
71
|
-
initialState:
|
|
76
|
+
initialState: "Unset",
|
|
72
77
|
evolve: evolve,
|
|
73
78
|
decide: decide
|
|
74
79
|
};
|
|
@@ -76,6 +81,8 @@ function Make(App) {
|
|
|
76
81
|
|
|
77
82
|
let Spec;
|
|
78
83
|
|
|
84
|
+
let initialState = "Unset";
|
|
85
|
+
|
|
79
86
|
let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/StateChange/RegistrationPolicy_Decision.res.mjs";
|
|
80
87
|
|
|
81
88
|
export {
|
|
@@ -105,6 +105,9 @@ type command =
|
|
|
105
105
|
role: @s.matches(Reventless.DcbTag.mark(Reventless.Role.nameSchema)) Reventless.Role.name,
|
|
106
106
|
requestedAt: Reventless.DateTime.t,
|
|
107
107
|
language?: string,
|
|
108
|
+
/** The deployment's starting state, stamped by the door: what the role is
|
|
109
|
+
while nobody has opened or closed it. */
|
|
110
|
+
initially?: @s.matches(Reventless.Admission.initiallySchema) Reventless.Admission.initially,
|
|
108
111
|
})
|
|
109
112
|
| @noApi
|
|
110
113
|
IssueRegistrationChallenge({
|
|
@@ -7,6 +7,7 @@ import * as Email$Reventless from "@reventlessdev/reventless-spec/src/semantic/E
|
|
|
7
7
|
import * as DcbTag$Reventless from "@reventlessdev/reventless-spec/src/components/DcbTag.res.mjs";
|
|
8
8
|
import * as Api$ReventlessInfra from "@reventlessdev/reventless-infra/src/components/Api.res.mjs";
|
|
9
9
|
import * as DateTime$Reventless from "@reventlessdev/reventless-spec/src/semantic/DateTime.res.mjs";
|
|
10
|
+
import * as Admission$Reventless from "@reventlessdev/reventless-spec/src/types/Admission.res.mjs";
|
|
10
11
|
import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
|
|
11
12
|
|
|
12
13
|
let consumedEventSchema = Sury.union([
|
|
@@ -97,7 +98,8 @@ let commandSchema = Sury.union([
|
|
|
97
98
|
email: s.m(Pii$Reventless.mark("emailId", undefined, Email$Reventless.schema)),
|
|
98
99
|
role: s.m(DcbTag$Reventless.mark(Role$Reventless.nameSchema)),
|
|
99
100
|
requestedAt: s.m(DateTime$Reventless.schema),
|
|
100
|
-
language: s.m(Sury.$option(Sury.string))
|
|
101
|
+
language: s.m(Sury.$option(Sury.string)),
|
|
102
|
+
initially: s.m(Sury.$option(Admission$Reventless.initiallySchema))
|
|
101
103
|
})),
|
|
102
104
|
Sury.$schema(s => ({
|
|
103
105
|
TAG: "IssueRegistrationChallenge",
|
|
@@ -10,8 +10,8 @@ module V = ContactVerification
|
|
|
10
10
|
module Guards = ContactVerification_Guards
|
|
11
11
|
|
|
12
12
|
type policyState =
|
|
13
|
-
/** Nothing recorded about the role:
|
|
14
|
-
self-service, closed otherwise. */
|
|
13
|
+
/** Nothing recorded about the role: the deployment's starting state if the app
|
|
14
|
+
declares it self-service, closed otherwise. */
|
|
15
15
|
| Unset
|
|
16
16
|
| Closed
|
|
17
17
|
| Open(option<Reventless.DateTime.t>)
|
|
@@ -137,17 +137,29 @@ let evolve = (state, event) =>
|
|
|
137
137
|
| RegistrationReleased(_) => {...state, stage: Unclaimed, lastNoticeAt: None}
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
/** Whether the policy admits a registration for `role` that arrived at `at
|
|
141
|
-
A role nobody has recorded anything
|
|
142
|
-
|
|
143
|
-
with no event to close it.
|
|
144
|
-
|
|
140
|
+
/** Whether the policy admits a registration for `role` that arrived at `at`,
|
|
141
|
+
on a deployment that starts `initially`. A role nobody has recorded anything
|
|
142
|
+
about reads as the starting state, if it is declared self-service; so does one
|
|
143
|
+
past an open window's end, with no event to close it. A request stamped with no
|
|
144
|
+
starting state was made when every role started open. */
|
|
145
|
+
let admits = (
|
|
146
|
+
admission,
|
|
147
|
+
~table,
|
|
148
|
+
~role,
|
|
149
|
+
~at,
|
|
150
|
+
~initially: option<Reventless.Admission.initially>,
|
|
151
|
+
) => {
|
|
152
|
+
let starting = () =>
|
|
153
|
+
table->Reventless.Admission.isSelfService(role) &&
|
|
154
|
+
initially->Option.getOr(Reventless.Admission.InitiallyOpen) ==
|
|
155
|
+
Reventless.Admission.InitiallyOpen
|
|
145
156
|
switch admission {
|
|
146
|
-
| Unset =>
|
|
157
|
+
| Unset => starting()
|
|
147
158
|
| Closed => false
|
|
148
159
|
| Open(None) => true
|
|
149
|
-
| Open(Some(until)) => Reventless.DateTime.isBefore(at, until)
|
|
160
|
+
| Open(Some(until)) => Reventless.DateTime.isBefore(at, until) || starting()
|
|
150
161
|
}
|
|
162
|
+
}
|
|
151
163
|
|
|
152
164
|
/** Whether the app declares `role` as one a person is invited to. */
|
|
153
165
|
let isByInvitation = (table, role) =>
|
|
@@ -189,8 +201,8 @@ module Make = (App: Reventless.Admission.Declaration) => {
|
|
|
189
201
|
// decision: the policy is consulted before the address, so a closed
|
|
190
202
|
// deployment sends nothing — not even the notice to an address that is
|
|
191
203
|
// already registered.
|
|
192
|
-
| Register({emailId, email, role, requestedAt, ?language}) =>
|
|
193
|
-
if !admits(state.admission, ~table=App.table, ~role, ~at=requestedAt) {
|
|
204
|
+
| Register({emailId, email, role, requestedAt, ?language, ?initially}) =>
|
|
205
|
+
if !admits(state.admission, ~table=App.table, ~role, ~at=requestedAt, ~initially) {
|
|
194
206
|
Ok([])
|
|
195
207
|
} else {
|
|
196
208
|
let roles = [(role :> string)]
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
3
4
|
import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js";
|
|
4
5
|
import * as DateTime$Reventless from "@reventlessdev/reventless-spec/src/semantic/DateTime.res.mjs";
|
|
5
6
|
import * as Admission$Reventless from "@reventlessdev/reventless-spec/src/types/Admission.res.mjs";
|
|
@@ -176,17 +177,24 @@ function evolve(state, event) {
|
|
|
176
177
|
}
|
|
177
178
|
}
|
|
178
179
|
|
|
179
|
-
function admits(admission, table, role, at) {
|
|
180
|
+
function admits(admission, table, role, at, initially) {
|
|
181
|
+
let starting = () => {
|
|
182
|
+
if (Admission$Reventless.isSelfService(table, role)) {
|
|
183
|
+
return Stdlib_Option.getOr(initially, "open") === "open";
|
|
184
|
+
} else {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
};
|
|
180
188
|
if (typeof admission !== "object") {
|
|
181
189
|
if (admission === "Unset") {
|
|
182
|
-
return
|
|
190
|
+
return starting();
|
|
183
191
|
} else {
|
|
184
192
|
return false;
|
|
185
193
|
}
|
|
186
194
|
}
|
|
187
195
|
let until = admission._0;
|
|
188
|
-
if (until !== undefined) {
|
|
189
|
-
return
|
|
196
|
+
if (until !== undefined && !DateTime$Reventless.isBefore(at, until)) {
|
|
197
|
+
return starting();
|
|
190
198
|
} else {
|
|
191
199
|
return true;
|
|
192
200
|
}
|
|
@@ -230,7 +238,7 @@ function Make(App) {
|
|
|
230
238
|
let role = command.role;
|
|
231
239
|
let email = command.email;
|
|
232
240
|
let emailId = command.emailId;
|
|
233
|
-
if (!admits(state.admission, App.table, role, requestedAt)) {
|
|
241
|
+
if (!admits(state.admission, App.table, role, requestedAt, command.initially)) {
|
|
234
242
|
return {
|
|
235
243
|
TAG: "Ok",
|
|
236
244
|
_0: []
|