@reventlessdev/reventless-registration 1.0.0-alpha.53 → 1.0.0-alpha.54

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/README.md CHANGED
@@ -28,9 +28,10 @@ dependencies. The generator composes the slices as the plugin's own, under the
28
28
  | Slice | Kind | What it does |
29
29
  |---|---|---|
30
30
  | `RegistrationPolicy` | StateChange, administrators only | Opens and closes a self-service role, optionally until a time |
31
- | `Registrations` | StateChange, relayed commands only | The ledger, partitioned by address. Besides a sign-up's arms, it takes an invitation (`Invite`), a reissued code and a withdrawal, which no door here reaches |
31
+ | `Registrations` | StateChange, relayed commands only | The ledger, partitioned by address. Besides a sign-up's arms, it takes an invitation, a reissued code and a withdrawal; no door here reaches the last two |
32
32
  | `RegistrationWindows` | StateViewStream, anonymous | Which self-service roles are open now |
33
33
  | `SignUp` | Inbound, anonymous | Starts a registration for a role |
34
+ | `Invite` | Inbound, signed in | Starts an invitation for the roles the table lets the inviter grant ([Inviting someone](#inviting-someone)) |
34
35
  | `CompleteRegistration` | Inbound, anonymous | Takes the proof and the password; the password goes to the stash, never to the log |
35
36
  | `SendRegistrationChallenge` | Outbound, `Messaging` | Sends the code, or tells a registered address someone tried |
36
37
  | `CreateRegisteredPrincipal` | Outbound, `Stash` + `IdentityProvider` | Makes the account once the proof is accepted |
@@ -72,7 +73,7 @@ whether an address is registered.
72
73
  | `Register` | `SignUp` | `RegistrationRequested` | Unclaimed, and the policy admits the role |
73
74
  | | | `RegistrationExpired`, `RegistrationRequested` | Pending, but the claim has lapsed |
74
75
  | | | `RegistrationAttemptedOnTakenAddress` | Completed, at most once an hour |
75
- | `Invite` | an invitation door the app provides | `RegistrationInvited` | Unclaimed |
76
+ | `Invite` | `Invite` | `RegistrationInvited` | Unclaimed |
76
77
  | | | `RegistrationExpired`, `RegistrationInvited` | Pending, but the claim has lapsed |
77
78
  | | | error `NotByInvitation` or `NoRoleToGrant` | a role not declared by invitation, or no role |
78
79
  | `IssueRegistrationChallenge` | `SendRegistrationChallenge` | `RegistrationChallengeIssued` | Pending, with no code out |
@@ -105,12 +106,6 @@ names the scenario of `conformance/…/Registrations_Conformance_GWT.res` that p
105
106
  `RecordRegistrationCompleted`. The ledger records `RegistrationCompleted`. *"an account
106
107
  made for a settled proof completes the registration"*
107
108
 
108
- The package ships the doors a visitor uses and no invitation door. A plugin that
109
- provides one lists it beside these slices, marks it `let admissionDoor =
110
- Reventless.Admission.Invite`, checks the inviter's roles, and relays `Invite` to the
111
- ledger. The ledger refuses any role the app's table does not declare by invitation.
112
- An invitation's code holds a week; a sign-up's holds a day.
113
-
114
109
  The mails are written in the recipient's language where the deployment has the words:
115
110
  their keys are `registration.*`, and `i18n/en.json` holds their English. A deployment
116
111
  lists `node_modules/@reventlessdev/reventless-registration/i18n` among its catalogue
@@ -121,6 +116,35 @@ where the deployment offers it, unless the address already holds an account, who
121
116
  own language wins. The ledger records the language and the key of the mail each code
122
117
  went out in.
123
118
 
119
+ ## Inviting someone
120
+
121
+ `Invite` is the door for a person someone else lets in. A signed-in inviter names an
122
+ address and the roles to grant it, and the person invited finishes at
123
+ `CompleteRegistration`, as a visitor does. An invitation's code holds a week; a sign-up's
124
+ holds a day.
125
+
126
+ The table says who may invite as what:
127
+
128
+ ```rescript
129
+ // src/Admission.res
130
+ let table = Reventless.Admission.declare([
131
+ (Roles.Shopper, SelfService),
132
+ (Merchandiser, Invitation({by: [Admin]})),
133
+ (Admin, Provisioned),
134
+ ])
135
+ ```
136
+
137
+ The door relays `Invite` to the ledger only when every role named is declared by
138
+ invitation and the inviter is in the group of one of the roles that may invite to it.
139
+ Otherwise it answers with the reason, naming the role: unlike a visitor, an inviter is
140
+ signed in and is owed it. The ledger checks the table again (`NotByInvitation`,
141
+ `NoRoleToGrant`), records nothing for an address that already holds an account, and does
142
+ not take over a claim that still holds.
143
+
144
+ A table that declares no role by invitation leaves the door in place with nothing it may
145
+ grant: every invitation is refused. Resending a code (`ReissueRegistrationChallenge`) and
146
+ taking an invitation back (`WithdrawRegistration`) are ledger commands with no door yet.
147
+
124
148
  ## Testing the slices against your table
125
149
 
126
150
  The package ships its scenarios as suites under `conformance/`, one per component, each a
@@ -134,6 +158,7 @@ module Policy = RegistrationPolicy_Conformance_GWT.Make(Admission)
134
158
  module Windows = RegistrationWindows_Conformance_GWT.Make(Admission)
135
159
  module SignUpDoor = SignUp_Conformance_GWT.Make(Admission)
136
160
  module CompletionDoor = CompleteRegistration_Conformance_GWT.Make(Admission)
161
+ module InvitationDoor = Invite_Conformance_GWT.Make(Admission)
137
162
  module Mail = SendRegistrationChallenge_Conformance_GWT.Make(Admission)
138
163
  module Account = CreateRegisteredPrincipal_Conformance_GWT.Make(Admission)
139
164
  ```
@@ -146,5 +171,5 @@ commands take part in your plugin's lifecycle model. The example host in this re
146
171
  `examples/online-shop-hybrid/registration`, runs them under its own table and under one that
147
172
  admits staff by invitation.
148
173
 
149
- The doors admit anonymous callers, which only the local platform does today, so a
174
+ The visitors' doors admit anonymous callers, which only the local platform does today, so a
150
175
  plugin listing these slices is hosted by the local platform only.
@@ -0,0 +1,123 @@
1
+ // The door an invitation starts at, for any admission table. Who may invite as what is the
2
+ // table's; the time on the command is read at the edge, so it is not compared whole.
3
+
4
+ module Make = (App: Reventless.Admission.Declaration) => {
5
+ module AppInvite = Invite_Translation.Make(App)
6
+ open Invite
7
+ include ReventlessGwt.InboundTranslation_GWT.FromSlice(Invite, AppInvite)
8
+ open Registration_Conformance_Examples
9
+
10
+ module Outcome = ReventlessGwt.Outcome
11
+
12
+ let needing = needs =>
13
+ (name, body) =>
14
+ switch unmet(needs) {
15
+ | None => test(name, body)
16
+ | Some(why) => ReventlessGwt.JestBind.todo(`${name} (${why})`)
17
+ }
18
+
19
+ let invitedRoles = byInvitation(App.table)
20
+ let invitedRole = first(invitedRoles)
21
+ let roleName = nameOf(invitedRole)
22
+
23
+ /** A signed-in caller in the groups of `roles`. */
24
+ let signedIn = (~userId="u_inviter", roles: array<Reventless.Role.name>) => Some({
25
+ ...Reventless.Identity.anonymous,
26
+ userId,
27
+ username: userId,
28
+ groups: roles->Array.map(Reventless.Role.groupOf),
29
+ })
30
+
31
+ /** Someone the table lets invite to `role`. */
32
+ let inviterFor = role =>
33
+ switch App.table->Reventless.Admission.strategyOf(role) {
34
+ | Invitation({by}) => signedIn(by)
35
+ | SelfService | Provisioned => signedIn([])
36
+ }
37
+
38
+ let thenInvites = async (pending, expected) =>
39
+ switch (await pending).outcome {
40
+ | Translated([(id, Invite({emailId, roles, invitedBy, _}))]) =>
41
+ let actual = `${id}|${emailId->ContactAddressId.toString}|${roles
42
+ ->Array.map(nameOf)
43
+ ->Array.join(",")}|${invitedBy}`
44
+ actual == expected
45
+ ? Outcome.pass
46
+ : Outcome.fail(TranslateError({expected, actual: Some(actual)}))
47
+ | _ => Outcome.fail(TranslateError({expected, actual: None}))
48
+ }
49
+
50
+ let thenLanguage = async (pending, expected) =>
51
+ switch (await pending).outcome {
52
+ | Translated([(_, Invite({?language}))]) if language == expected => Outcome.pass
53
+ | Translated([(_, Invite({?language}))]) =>
54
+ Outcome.fail(
55
+ TranslateError({
56
+ expected: expected->Option.getOr("(none)"),
57
+ actual: Some(language->Option.getOr("(none)")),
58
+ }),
59
+ )
60
+ | _ => Outcome.fail(TranslateError({expected: "an Invite", actual: None}))
61
+ }
62
+
63
+ describe("Invite InboundTranslationSlice", () => {
64
+ // Refused before the table is read: an invitation says who sent it.
65
+ test("an invitation nobody signed in sent is refused", () =>
66
+ whenInput({email: aliceAddress, roles: [roleName]})->thenNotUnderstood(
67
+ Invite_Translation.noInviter,
68
+ )
69
+ )
70
+
71
+ test("something that is not an address is not understood", () =>
72
+ whenInput(
73
+ {email: "alice", roles: [roleName]},
74
+ ~caller=?inviterFor(invitedRole),
75
+ )->thenNotUnderstood("not an email address")
76
+ )
77
+
78
+ test("an invitation to no role is refused", () =>
79
+ whenInput(
80
+ {email: aliceAddress, roles: [" "]},
81
+ ~caller=?inviterFor(invitedRole),
82
+ )->thenNotUnderstood(Invite_Translation.noRole)
83
+ )
84
+
85
+ // The table is the cap: no inviter grants a role it does not declare by invitation.
86
+ test("a role the table does not declare by invitation is refused, naming it", () => {
87
+ let stranger = App.table->unknownRole
88
+ whenInput(
89
+ {email: aliceAddress, roles: [nameOf(stranger)]},
90
+ ~caller=?signedIn(App.table->Array.map(e => e.role)),
91
+ )->thenNotUnderstood(Invite_Translation.mayNotGrant(stranger))
92
+ })
93
+
94
+ let test = needing([has(invitedRoles, ~kind="by-invitation")])
95
+
96
+ test("an inviter the table names invites an address, as one spelling", () =>
97
+ whenInput(
98
+ {email: " Alice@Example.com ", roles: [roleName]},
99
+ ~caller=?inviterFor(invitedRole),
100
+ )->thenInvites(`${aliceId}|${aliceId}|${roleName}|u_inviter`)
101
+ )
102
+
103
+ test("a signed-in caller the table does not name may not invite", () =>
104
+ whenInput({email: aliceAddress, roles: [roleName]}, ~caller=?signedIn([]))->thenNotUnderstood(
105
+ Invite_Translation.mayNotGrant(invitedRole),
106
+ )
107
+ )
108
+
109
+ test("the language the person invited reads travels with the invitation", () =>
110
+ whenInput(
111
+ {email: aliceAddress, roles: [roleName], language: " de-AT "},
112
+ ~caller=?inviterFor(invitedRole),
113
+ )->thenLanguage(Some("de-AT"))
114
+ )
115
+
116
+ test("starting an invitation reaches no capability", () =>
117
+ whenInput(
118
+ {email: aliceAddress, roles: [roleName]},
119
+ ~caller=?inviterFor(invitedRole),
120
+ )->thenNothingSent
121
+ )
122
+ })
123
+ }
@@ -0,0 +1,200 @@
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 Role$Reventless from "@reventlessdev/reventless-spec/src/types/Role.res.mjs";
5
+ import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js";
6
+ import * as Identity$Reventless from "@reventlessdev/reventless-spec/src/types/Identity.res.mjs";
7
+ import * as Admission$Reventless from "@reventlessdev/reventless-spec/src/types/Admission.res.mjs";
8
+ import * as Outcome$ReventlessGwt from "@reventlessdev/reventless-gwt/src/Outcome.res.mjs";
9
+ import * as JestBind$ReventlessGwt from "@reventlessdev/reventless-gwt/src/JestBind.res.mjs";
10
+ import * as Invite$ReventlessRegistration from "../../../src/Registration/InboundTranslation/Invite.res.mjs";
11
+ import * as InboundTranslation_GWT$ReventlessGwt from "@reventlessdev/reventless-gwt/src/InboundTranslation_GWT.res.mjs";
12
+ import * as ContactAddressId$ReventlessRegistration from "../../../src/Registration/ContactAddressId.res.mjs";
13
+ import * as Invite_Translation$ReventlessRegistration from "../../../src/Registration/InboundTranslation/Invite_Translation.res.mjs";
14
+ import * as Registration_Conformance_Examples$ReventlessRegistration from "../Registration_Conformance_Examples.res.mjs";
15
+
16
+ function Make(App) {
17
+ let AppInvite = Invite_Translation$ReventlessRegistration.Make(App);
18
+ let include = InboundTranslation_GWT$ReventlessGwt.FromSlice({
19
+ name: Invite$ReventlessRegistration.name,
20
+ moduleUrl: Invite$ReventlessRegistration.moduleUrl,
21
+ externalInputSchema: Invite$ReventlessRegistration.externalInputSchema,
22
+ commandSchema: Invite$ReventlessRegistration.commandSchema,
23
+ targetName: Invite$ReventlessRegistration.targetName,
24
+ externalSystem: Invite$ReventlessRegistration.externalSystem,
25
+ authorizationOf: Invite$ReventlessRegistration.authorizationOf,
26
+ endpoint: undefined,
27
+ capabilityNeeds: Invite$ReventlessRegistration.capabilityNeeds
28
+ })({
29
+ translate: AppInvite.translate,
30
+ moduleUrl: AppInvite.moduleUrl
31
+ });
32
+ let describe = include.describe;
33
+ let test = include.test;
34
+ let whenInput = include.whenInput;
35
+ let thenNotUnderstood = include.thenNotUnderstood;
36
+ let thenNothingSent = include.thenNothingSent;
37
+ let needing = needs => ((name, body) => {
38
+ let why = Registration_Conformance_Examples$ReventlessRegistration.unmet(needs);
39
+ if (why !== undefined) {
40
+ return JestBind$ReventlessGwt.todo(name + ` (` + why + `)`);
41
+ } else {
42
+ return test(name, undefined, body);
43
+ }
44
+ });
45
+ let invitedRoles = Registration_Conformance_Examples$ReventlessRegistration.byInvitation(App.table);
46
+ let invitedRole = Registration_Conformance_Examples$ReventlessRegistration.first(invitedRoles);
47
+ let roleName = Registration_Conformance_Examples$ReventlessRegistration.nameOf(invitedRole);
48
+ let signedIn = (userIdOpt, roles) => {
49
+ let userId = userIdOpt !== undefined ? userIdOpt : "u_inviter";
50
+ let newrecord = {...Identity$Reventless.anonymous};
51
+ return newrecord.groups = roles.map(Role$Reventless.groupOf), newrecord.username = userId, newrecord.userId = userId, newrecord;
52
+ };
53
+ let inviterFor = role => {
54
+ let match = Admission$Reventless.strategyOf(App.table, role);
55
+ if (typeof match !== "object") {
56
+ if (match === "SelfService") {
57
+ return signedIn(undefined, []);
58
+ } else {
59
+ return signedIn(undefined, []);
60
+ }
61
+ } else {
62
+ return signedIn(undefined, match.by);
63
+ }
64
+ };
65
+ let thenInvites = async (pending, expected) => {
66
+ let match = (await pending).outcome;
67
+ switch (match.TAG) {
68
+ case "Translated" :
69
+ let match$1 = match._0;
70
+ if (match$1.length === 1) {
71
+ let match$2 = match$1[0];
72
+ let match$3 = match$2[1];
73
+ let actual = match$2[0] + `|` + ContactAddressId$ReventlessRegistration.toString(match$3.emailId) + `|` + match$3.roles.map(Registration_Conformance_Examples$ReventlessRegistration.nameOf).join(",") + `|` + match$3.invitedBy;
74
+ if (actual === expected) {
75
+ return Outcome$ReventlessGwt.pass;
76
+ } else {
77
+ return Outcome$ReventlessGwt.fail({
78
+ TAG: "TranslateError",
79
+ expected: expected,
80
+ actual: actual
81
+ });
82
+ }
83
+ }
84
+ break;
85
+ case "NotUnderstood" :
86
+ case "InputRefused" :
87
+ break;
88
+ }
89
+ return Outcome$ReventlessGwt.fail({
90
+ TAG: "TranslateError",
91
+ expected: expected,
92
+ actual: undefined
93
+ });
94
+ };
95
+ let thenLanguage = async (pending, expected) => {
96
+ let match = (await pending).outcome;
97
+ switch (match.TAG) {
98
+ case "Translated" :
99
+ let match$1 = match._0;
100
+ if (match$1.length !== 1) {
101
+ return Outcome$ReventlessGwt.fail({
102
+ TAG: "TranslateError",
103
+ expected: "an Invite",
104
+ actual: undefined
105
+ });
106
+ }
107
+ let match$2 = match$1[0];
108
+ let language = match$2[1].language;
109
+ if (Primitive_object.equal(language, expected)) {
110
+ return Outcome$ReventlessGwt.pass;
111
+ } else {
112
+ return Outcome$ReventlessGwt.fail({
113
+ TAG: "TranslateError",
114
+ expected: Stdlib_Option.getOr(expected, "(none)"),
115
+ actual: Stdlib_Option.getOr(language, "(none)")
116
+ });
117
+ }
118
+ case "NotUnderstood" :
119
+ case "InputRefused" :
120
+ return Outcome$ReventlessGwt.fail({
121
+ TAG: "TranslateError",
122
+ expected: "an Invite",
123
+ actual: undefined
124
+ });
125
+ }
126
+ };
127
+ describe("Invite InboundTranslationSlice", () => {
128
+ test("an invitation nobody signed in sent is refused", undefined, () => thenNotUnderstood(whenInput({
129
+ email: Registration_Conformance_Examples$ReventlessRegistration.aliceAddress,
130
+ roles: [roleName]
131
+ }, undefined, undefined), Invite_Translation$ReventlessRegistration.noInviter));
132
+ test("something that is not an address is not understood", undefined, () => thenNotUnderstood(whenInput({
133
+ email: "alice",
134
+ roles: [roleName]
135
+ }, undefined, inviterFor(invitedRole)), "not an email address"));
136
+ test("an invitation to no role is refused", undefined, () => thenNotUnderstood(whenInput({
137
+ email: Registration_Conformance_Examples$ReventlessRegistration.aliceAddress,
138
+ roles: [" "]
139
+ }, undefined, inviterFor(invitedRole)), Invite_Translation$ReventlessRegistration.noRole));
140
+ test("a role the table does not declare by invitation is refused, naming it", undefined, () => {
141
+ let stranger = Registration_Conformance_Examples$ReventlessRegistration.unknownRole(App.table);
142
+ return thenNotUnderstood(whenInput({
143
+ email: Registration_Conformance_Examples$ReventlessRegistration.aliceAddress,
144
+ roles: [Registration_Conformance_Examples$ReventlessRegistration.nameOf(stranger)]
145
+ }, undefined, signedIn(undefined, App.table.map(e => e.role))), Invite_Translation$ReventlessRegistration.mayNotGrant(stranger));
146
+ });
147
+ let test$1 = needing([Registration_Conformance_Examples$ReventlessRegistration.has(invitedRoles, "by-invitation")]);
148
+ test$1("an inviter the table names invites an address, as one spelling", () => thenInvites(whenInput({
149
+ email: " Alice@Example.com ",
150
+ roles: [roleName]
151
+ }, undefined, inviterFor(invitedRole)), Registration_Conformance_Examples$ReventlessRegistration.aliceId + `|` + Registration_Conformance_Examples$ReventlessRegistration.aliceId + `|` + roleName + `|u_inviter`));
152
+ test$1("a signed-in caller the table does not name may not invite", () => thenNotUnderstood(whenInput({
153
+ email: Registration_Conformance_Examples$ReventlessRegistration.aliceAddress,
154
+ roles: [roleName]
155
+ }, undefined, signedIn(undefined, [])), Invite_Translation$ReventlessRegistration.mayNotGrant(invitedRole)));
156
+ test$1("the language the person invited reads travels with the invitation", () => thenLanguage(whenInput({
157
+ email: Registration_Conformance_Examples$ReventlessRegistration.aliceAddress,
158
+ roles: [roleName],
159
+ language: " de-AT "
160
+ }, undefined, inviterFor(invitedRole)), "de-AT"));
161
+ test$1("starting an invitation reaches no capability", () => thenNothingSent(whenInput({
162
+ email: Registration_Conformance_Examples$ReventlessRegistration.aliceAddress,
163
+ roles: [roleName]
164
+ }, undefined, inviterFor(invitedRole))));
165
+ });
166
+ return {
167
+ AppInvite: AppInvite,
168
+ describe: describe,
169
+ test: test,
170
+ fakes: include.fakes,
171
+ encPairs: include.encPairs,
172
+ errorOf: include.errorOf,
173
+ whenInput: whenInput,
174
+ whenReceived: include.whenReceived,
175
+ describeOther: include.describeOther,
176
+ roundTrips: include.roundTrips,
177
+ thenCommands: include.thenCommands,
178
+ thenCommand: include.thenCommand,
179
+ thenNoCommand: include.thenNoCommand,
180
+ thenNotUnderstood: thenNotUnderstood,
181
+ thenTranslateError: include.thenTranslateError,
182
+ thenRefusedInput: include.thenRefusedInput,
183
+ thenSent: include.thenSent,
184
+ thenNothingSent: thenNothingSent,
185
+ Outcome: undefined,
186
+ needing: needing,
187
+ invitedRoles: invitedRoles,
188
+ invitedRole: invitedRole,
189
+ roleName: roleName,
190
+ signedIn: signedIn,
191
+ inviterFor: inviterFor,
192
+ thenInvites: thenInvites,
193
+ thenLanguage: thenLanguage
194
+ };
195
+ }
196
+
197
+ export {
198
+ Make,
199
+ }
200
+ /* Role-Reventless Not a pure module */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reventlessdev/reventless-registration",
3
- "version": "1.0.0-alpha.53",
3
+ "version": "1.0.0-alpha.54",
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": [
@@ -17,16 +17,16 @@
17
17
  "rescript": "12.3.1",
18
18
  "sury": "11.1.0",
19
19
  "sury-ppx": "11.1.0",
20
- "@reventlessdev/reventless-gwt": "1.0.0-alpha.310",
21
20
  "@reventlessdev/reventless-infra": "3.0.0-alpha.254",
22
- "@reventlessdev/reventless-spec": "3.0.0-alpha.223",
23
- "@reventlessdev/reventless-ppx": "1.0.0-alpha.125"
21
+ "@reventlessdev/reventless-ppx": "1.0.0-alpha.125",
22
+ "@reventlessdev/reventless-gwt": "1.0.0-alpha.311",
23
+ "@reventlessdev/reventless-spec": "3.0.0-alpha.223"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "rescript": "^12.3.1",
27
27
  "sury": "^11.1.0",
28
28
  "sury-ppx": "^11.1.0",
29
- "@reventlessdev/reventless-gwt": "^1.0.0-alpha.310",
29
+ "@reventlessdev/reventless-gwt": "^1.0.0-alpha.311",
30
30
  "@reventlessdev/reventless-infra": "^3.0.0-alpha.254",
31
31
  "@reventlessdev/reventless-ppx": "^1.0.0-alpha.125",
32
32
  "@reventlessdev/reventless-spec": "^3.0.0-alpha.223"
@@ -0,0 +1,41 @@
1
+ // Invite InboundTranslationSlice.
2
+ //
3
+ // The door an invitation starts at. A signed-in inviter names an address and the
4
+ // roles to grant it; the door relays `Invite` to the ledger only when the app's
5
+ // table lets this inviter grant every one of them, and stamps the moment the
6
+ // request arrived. The person invited finishes at `CompleteRegistration`.
7
+ //
8
+ // Unlike the visitors' doors it answers with a reason: its caller is signed in,
9
+ // and is owed why an invitation was not sent.
10
+
11
+ @@reventless.spec
12
+
13
+ /** `roles` are the roles the invitation grants, by name. `language` is the one
14
+ the person invited reads, which their mail is written in where the deployment
15
+ offers it. */
16
+ @schema
17
+ type externalInput = {
18
+ @sensitive email: string,
19
+ roles: array<string>,
20
+ language?: string,
21
+ }
22
+
23
+ @schema
24
+ type command =
25
+ | Invite({
26
+ emailId: ContactAddressId.t,
27
+ @pii({subject: "emailId"}) email: Reventless.Email.t,
28
+ roles: array<Reventless.Role.name>,
29
+ invitedBy: string,
30
+ requestedAt: Reventless.DateTime.t,
31
+ language?: string,
32
+ })
33
+
34
+ let targetName = "Registrations"
35
+ // The other party, who invites: a signed-in person, through the app's own screens. An app names its own in
36
+ // plugin.json's `slicesFrom` entry (`externalSystems`), which takes this one's place.
37
+ let externalSystem = Some("Person inviting")
38
+ let capabilityNeeds: array<Reventless.CapabilityNeed.t> = []
39
+
40
+ /** This door starts an invitation; the platform's admission check looks for it. */
41
+ let admissionDoor = Reventless.Admission.Invite
@@ -0,0 +1,64 @@
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 Sensitive$Reventless from "@reventlessdev/reventless-spec/src/components/Sensitive.res.mjs";
10
+ import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
11
+
12
+ let externalInputSchema = Sury.$schema(s => ({
13
+ email: s.m(Sensitive$Reventless.string),
14
+ roles: s.m(Sury.array(Sury.string)),
15
+ language: s.m(Sury.$option(Sury.string))
16
+ }));
17
+
18
+ let commandSchema = Sury.$schema(s => ({
19
+ TAG: "Invite",
20
+ emailId: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
21
+ email: s.m(Pii$Reventless.mark("emailId", undefined, Email$Reventless.schema)),
22
+ roles: s.m(Sury.array(Role$Reventless.nameSchema)),
23
+ invitedBy: s.m(Sury.string),
24
+ requestedAt: s.m(DateTime$Reventless.schema),
25
+ language: s.m(Sury.$option(Sury.string))
26
+ }));
27
+
28
+ let capabilityNeeds = [];
29
+
30
+ function authorizationOf(param) {
31
+ return "AllowAuthenticated";
32
+ }
33
+
34
+ let traits = [];
35
+
36
+ let name = "Invite";
37
+
38
+ let Id;
39
+
40
+ let targetName = "Registrations";
41
+
42
+ let externalSystem = "Person inviting";
43
+
44
+ let admissionDoor = "invite";
45
+
46
+ let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/InboundTranslation/Invite.res.mjs";
47
+
48
+ let endpoint;
49
+
50
+ export {
51
+ name,
52
+ Id,
53
+ externalInputSchema,
54
+ commandSchema,
55
+ targetName,
56
+ externalSystem,
57
+ capabilityNeeds,
58
+ admissionDoor,
59
+ moduleUrl,
60
+ authorizationOf,
61
+ traits,
62
+ endpoint,
63
+ }
64
+ /* externalInputSchema Not a pure module */
@@ -0,0 +1,65 @@
1
+ @@reventless.translation
2
+
3
+ let noInviter = "an invitation needs someone signed in to send it"
4
+ let noRole = "say which roles to invite to"
5
+
6
+ /** What an inviter is told for a role they may not grant, naming it. */
7
+ let mayNotGrant = (role: Reventless.Role.name) =>
8
+ `you may not invite someone as ${(role :> string)}`
9
+
10
+ /** Whether the table lets `inviter` grant `role`: the role is declared by invitation, and
11
+ the inviter is in the group of one of the roles that may invite to it. */
12
+ let mayInvite = (table, inviter: Reventless.Identity.t, role) =>
13
+ switch table->Reventless.Admission.strategyOf(role) {
14
+ | Invitation({by}) =>
15
+ by->Array.some(r => inviter->Reventless.Identity.hasGroup(Reventless.Role.groupOf(r)))
16
+ | SelfService | Provisioned => false
17
+ }
18
+
19
+ /** The door over the app's table, which says who may invite as what. */
20
+ module Make = (App: Reventless.Admission.Declaration) => {
21
+ module Spec = Spec
22
+ let moduleUrl = moduleUrl
23
+
24
+ let translate = async (
25
+ input: externalInput,
26
+ ~capabilities: Reventless.Capabilities.t,
27
+ ~caller: option<Reventless.Identity.t>,
28
+ ) => {
29
+ let roles =
30
+ input.roles
31
+ ->Array.map(String.trim)
32
+ ->Array.filter(r => r != "")
33
+ ->Array.map(Reventless.Role.make)
34
+ switch (caller, Reventless.Email.fromString(input.email->String.trim)) {
35
+ | (None, _) => Error(noInviter)
36
+ | (Some(_), Error(_)) => Error("not an email address")
37
+ | (Some(_), Ok(_)) if roles == [] => Error(noRole)
38
+ | (Some(inviter), Ok(typed)) =>
39
+ switch roles->Array.find(r => !mayInvite(App.table, inviter, r)) {
40
+ | Some(role) => Error(mayNotGrant(role))
41
+ | None =>
42
+ let email = typed->ContactAddressId.normalize
43
+ switch ContactAddressId.fingerprint(capabilities.secrets, email) {
44
+ | Error(why) => Error(why)
45
+ | Ok(id) =>
46
+ // The envelope id is the fingerprint, as on a sign-up: the address must not be
47
+ // stored beside the event.
48
+ Ok([
49
+ (
50
+ id->ContactAddressId.toString,
51
+ Invite({
52
+ emailId: id,
53
+ email,
54
+ roles,
55
+ invitedBy: inviter.userId,
56
+ requestedAt: Date.make()->Date.toISOString->Reventless.DateTime.unsafe,
57
+ language: ?SignUp_Translation.languageOf(input.language),
58
+ }),
59
+ ),
60
+ ])
61
+ }
62
+ }
63
+ }
64
+ }
65
+ }
@@ -0,0 +1,103 @@
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 Email$Reventless from "@reventlessdev/reventless-spec/src/semantic/Email.res.mjs";
5
+ import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js";
6
+ import * as Identity$Reventless from "@reventlessdev/reventless-spec/src/types/Identity.res.mjs";
7
+ import * as Admission$Reventless from "@reventlessdev/reventless-spec/src/types/Admission.res.mjs";
8
+ import * as Invite$ReventlessRegistration from "./Invite.res.mjs";
9
+ import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
10
+ import * as SignUp_Translation$ReventlessRegistration from "./SignUp_Translation.res.mjs";
11
+
12
+ let noInviter = "an invitation needs someone signed in to send it";
13
+
14
+ let noRole = "say which roles to invite to";
15
+
16
+ function mayNotGrant(role) {
17
+ return `you may not invite someone as ` + role;
18
+ }
19
+
20
+ function mayInvite(table, inviter, role) {
21
+ let match = Admission$Reventless.strategyOf(table, role);
22
+ if (typeof match !== "object") {
23
+ return false;
24
+ } else {
25
+ return match.by.some(r => Identity$Reventless.hasGroup(inviter, Role$Reventless.groupOf(r)));
26
+ }
27
+ }
28
+
29
+ function Make(App) {
30
+ let translate = async (input, capabilities, caller) => {
31
+ let roles = input.roles.map(prim => prim.trim()).filter(r => r !== "").map(prim => prim);
32
+ let match = Email$Reventless.fromString(input.email.trim());
33
+ if (caller === undefined) {
34
+ return {
35
+ TAG: "Error",
36
+ _0: noInviter
37
+ };
38
+ }
39
+ if (match.TAG !== "Ok") {
40
+ return {
41
+ TAG: "Error",
42
+ _0: "not an email address"
43
+ };
44
+ }
45
+ if (Primitive_object.equal(roles, [])) {
46
+ return {
47
+ TAG: "Error",
48
+ _0: noRole
49
+ };
50
+ }
51
+ let role = roles.find(r => !mayInvite(App.table, caller, r));
52
+ if (role !== undefined) {
53
+ return {
54
+ TAG: "Error",
55
+ _0: mayNotGrant(role)
56
+ };
57
+ }
58
+ let email = ContactAddressId$ReventlessRegistration.normalize(match._0);
59
+ let why = ContactAddressId$ReventlessRegistration.fingerprint(capabilities.secrets, email);
60
+ if (why.TAG !== "Ok") {
61
+ return {
62
+ TAG: "Error",
63
+ _0: why._0
64
+ };
65
+ }
66
+ let id = why._0;
67
+ return {
68
+ TAG: "Ok",
69
+ _0: [[
70
+ ContactAddressId$ReventlessRegistration.toString(id),
71
+ {
72
+ TAG: "Invite",
73
+ emailId: id,
74
+ email: email,
75
+ roles: roles,
76
+ invitedBy: caller.userId,
77
+ requestedAt: new Date().toISOString(),
78
+ language: SignUp_Translation$ReventlessRegistration.languageOf(input.language)
79
+ }
80
+ ]]
81
+ };
82
+ };
83
+ return {
84
+ Spec: undefined,
85
+ moduleUrl: Invite$ReventlessRegistration.moduleUrl,
86
+ translate: translate
87
+ };
88
+ }
89
+
90
+ let Spec;
91
+
92
+ let moduleUrl = "@reventlessdev/reventless-registration/src/Registration/InboundTranslation/Invite_Translation.res.mjs";
93
+
94
+ export {
95
+ Spec,
96
+ noInviter,
97
+ noRole,
98
+ mayNotGrant,
99
+ mayInvite,
100
+ Make,
101
+ moduleUrl,
102
+ }
103
+ /* Role-Reventless Not a pure module */