@reventlessdev/reventless-registration 1.0.0-alpha.1 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reventlessdev/reventless-registration",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.2",
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": [
@@ -13,9 +13,9 @@
13
13
  "dependencies": {
14
14
  "sury": "11.0.0",
15
15
  "sury-ppx": "11.0.0",
16
- "@reventlessdev/reventless-spec": "3.0.0-alpha.176",
17
- "@reventlessdev/reventless-ppx": "1.0.0-alpha.107",
18
- "@reventlessdev/reventless-infra": "3.0.0-alpha.205"
16
+ "@reventlessdev/reventless-infra": "3.0.0-alpha.206",
17
+ "@reventlessdev/reventless-ppx": "1.0.0-alpha.108",
18
+ "@reventlessdev/reventless-spec": "3.0.0-alpha.177"
19
19
  },
20
20
  "devDependencies": {
21
21
  "rescript": "12.3.1"
@@ -17,7 +17,12 @@
17
17
  type consumedEvent =
18
18
  | RegistrationRequested({email: string, requestedAt: Reventless.DateTime.t})
19
19
  | RegistrationAttemptedOnTakenAddress({email: string, attemptedAt: Reventless.DateTime.t})
20
- | RegistrationInvited({email: string, invitedBy: string, invitedAt: Reventless.DateTime.t})
20
+ | RegistrationInvited({
21
+ email: string,
22
+ roles: array<string>,
23
+ invitedBy: string,
24
+ invitedAt: Reventless.DateTime.t,
25
+ })
21
26
  | RegistrationChallengeReissued({
22
27
  email: string,
23
28
  reissuedAt: Reventless.DateTime.t,
@@ -25,9 +30,10 @@ type consumedEvent =
25
30
  })
26
31
 
27
32
  /** `invited` words the secret as an invitation; it is left out for a sign-up
28
- and for the notice. */
33
+ and for the notice. `roles` names what the invitation grants, where the
34
+ event said: a reissued code does not. */
29
35
  @schema
30
- type outboundItem = {email: string, alreadyRegistered: bool, invited?: bool}
36
+ type outboundItem = {email: string, alreadyRegistered: bool, invited?: bool, roles?: array<string>}
31
37
 
32
38
  @schema
33
39
  type inboundCommand =
@@ -19,6 +19,7 @@ let consumedEventSchema = Sury.union([
19
19
  Sury.$schema(s => ({
20
20
  TAG: "RegistrationInvited",
21
21
  email: s.m(Sury.string),
22
+ roles: s.m(Sury.array(Sury.string)),
22
23
  invitedBy: s.m(Sury.string),
23
24
  invitedAt: s.m(DateTime$Reventless.schema)
24
25
  })),
@@ -33,7 +34,8 @@ let consumedEventSchema = Sury.union([
33
34
  let outboundItemSchema = Sury.$schema(s => ({
34
35
  email: s.m(Sury.string),
35
36
  alreadyRegistered: s.m(Sury.boolean),
36
- invited: s.m(Sury.$option(Sury.boolean))
37
+ invited: s.m(Sury.$option(Sury.boolean)),
38
+ roles: s.m(Sury.$option(Sury.array(Sury.string)))
37
39
  }));
38
40
 
39
41
  let inboundCommandSchema = Sury.$schema(s => ({
@@ -7,10 +7,10 @@ let collect = (event, ~sourceId as _) =>
7
7
  | RegistrationRequested({email, requestedAt}) => [
8
8
  (`${email}:${requestedAt->Reventless.DateTime.toString}`, {email, alreadyRegistered: false}),
9
9
  ]
10
- | RegistrationInvited({email, invitedAt}) => [
10
+ | RegistrationInvited({email, roles, invitedAt}) => [
11
11
  (
12
12
  `${email}:invited:${invitedAt->Reventless.DateTime.toString}`,
13
- {email, alreadyRegistered: false, invited: true},
13
+ {email, alreadyRegistered: false, invited: true, roles},
14
14
  ),
15
15
  ]
16
16
  | RegistrationChallengeReissued({email, reissuedAt, ?invitedBy}) => [
@@ -37,8 +37,18 @@ let challengeBody = (~token) =>
37
37
  ~invited=false,
38
38
  )}.`
39
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(
40
+ /** What the invitation grants, as the mail says it: "as Merchandiser", or
41
+ nothing where the event did not say. */
42
+ let asRoles = (roles: option<array<string>>) =>
43
+ switch roles {
44
+ | Some([]) | None => ""
45
+ | Some(roles) => ` as ${roles->Array.join(" and ")}`
46
+ }
47
+
48
+ let invitationBody = (~token, ~roles=?) =>
49
+ `You have been invited to create an account${asRoles(
50
+ roles,
51
+ )}. Your code is ${token}. Enter it with this address and a password of your choice to accept. It expires in ${expiresIn(
42
52
  ~invited=true,
43
53
  )}.`
44
54
 
@@ -81,7 +91,7 @@ let translate = async (_id, item: outboundItem, ~capabilities: Reventless.Capabi
81
91
  capabilities,
82
92
  ~email=item.email,
83
93
  ~subject=invited ? "You are invited to create an account" : "Finish your registration",
84
- ~body=invited ? invitationBody(~token) : challengeBody(~token),
94
+ ~body=invited ? invitationBody(~token, ~roles=?item.roles) : challengeBody(~token),
85
95
  ) {
86
96
  | Ok(_) =>
87
97
  Ok(
@@ -33,7 +33,8 @@ function collect(event, param) {
33
33
  {
34
34
  email: email$2,
35
35
  alreadyRegistered: false,
36
- invited: true
36
+ invited: true,
37
+ roles: event.roles
37
38
  }
38
39
  ]];
39
40
  case "RegistrationChallengeReissued" :
@@ -57,8 +58,16 @@ function challengeBody(token) {
57
58
  return `Your registration code is ` + token + `. Enter it with a password of your choice to finish. It expires in ` + expiresIn(false) + `.`;
58
59
  }
59
60
 
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) + `.`;
61
+ function asRoles(roles) {
62
+ if (roles !== undefined && roles.length !== 0) {
63
+ return ` as ` + roles.join(" and ");
64
+ } else {
65
+ return "";
66
+ }
67
+ }
68
+
69
+ function invitationBody(token, roles) {
70
+ return `You have been invited to create an account` + asRoles(roles) + `. Your code is ` + token + `. Enter it with this address and a password of your choice to accept. It expires in ` + expiresIn(true) + `.`;
62
71
  }
63
72
 
64
73
  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.";
@@ -105,7 +114,7 @@ async function translate(_id, item, capabilities) {
105
114
  _0: `cannot hash a secret: ` + proofHash._0._0
106
115
  };
107
116
  }
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));
117
+ let failure$1 = await send(capabilities, item.email, invited ? "You are invited to create an account" : "Finish your registration", invited ? invitationBody(token$1, item.roles) : challengeBody(token$1));
109
118
  if (failure$1.TAG === "Ok") {
110
119
  return {
111
120
  TAG: "Ok",
@@ -140,6 +149,7 @@ export {
140
149
  collect,
141
150
  expiresIn,
142
151
  challengeBody,
152
+ asRoles,
143
153
  invitationBody,
144
154
  noticeBody,
145
155
  send,
@@ -25,3 +25,6 @@ type state = {
25
25
  type consumedEvent =
26
26
  | RegistrationOpened({role: string, until?: Reventless.DateTime.t})
27
27
  | RegistrationClosed({role: string})
28
+
29
+ /** This view says which roles are open; the platform tells the shell where to read it. */
30
+ let admissionDoor = Reventless.Admission.OpenRoles
@@ -52,6 +52,8 @@ let stateSchema$1 = Sury.$Metadata_set(stateSchema, StateAnnotations$Reventless.
52
52
 
53
53
  let name = "RegistrationWindows";
54
54
 
55
+ let admissionDoor = "OpenRoles";
56
+
55
57
  let Id;
56
58
 
57
59
  let subIdConfig;
@@ -65,6 +67,7 @@ let visibility = "Public";
65
67
  export {
66
68
  name,
67
69
  consumedEventSchema,
70
+ admissionDoor,
68
71
  config,
69
72
  Id,
70
73
  subIdConfig,