@reventlessdev/reventless-registration 1.0.0-alpha.5 → 1.0.0-alpha.50

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 (48) hide show
  1. package/README.md +87 -2
  2. package/conformance/Registration/InboundTranslation/CompleteRegistration_Conformance_GWT.res +65 -0
  3. package/conformance/Registration/InboundTranslation/CompleteRegistration_Conformance_GWT.res.mjs +123 -0
  4. package/conformance/Registration/InboundTranslation/SignUp_Conformance_GWT.res +136 -0
  5. package/conformance/Registration/InboundTranslation/SignUp_Conformance_GWT.res.mjs +212 -0
  6. package/conformance/Registration/OutboundTranslation/CreateRegisteredPrincipal_Conformance_GWT.res +102 -0
  7. package/conformance/Registration/OutboundTranslation/CreateRegisteredPrincipal_Conformance_GWT.res.mjs +179 -0
  8. package/conformance/Registration/OutboundTranslation/SendRegistrationChallenge_Conformance_GWT.res +312 -0
  9. package/conformance/Registration/OutboundTranslation/SendRegistrationChallenge_Conformance_GWT.res.mjs +360 -0
  10. package/conformance/Registration/Registration_Conformance_Examples.res +58 -0
  11. package/conformance/Registration/Registration_Conformance_Examples.res.mjs +106 -0
  12. package/conformance/Registration/StateChange/RegistrationPolicy_Conformance_GWT.res +108 -0
  13. package/conformance/Registration/StateChange/RegistrationPolicy_Conformance_GWT.res.mjs +161 -0
  14. package/conformance/Registration/StateChange/RegistrationsByInvitation_Conformance_GWT.res +155 -0
  15. package/conformance/Registration/StateChange/RegistrationsByInvitation_Conformance_GWT.res.mjs +216 -0
  16. package/conformance/Registration/StateChange/Registrations_Conformance_GWT.res +469 -0
  17. package/conformance/Registration/StateChange/Registrations_Conformance_GWT.res.mjs +512 -0
  18. package/conformance/Registration/StateViewStream/RegistrationWindows_Conformance_GWT.res +33 -0
  19. package/conformance/Registration/StateViewStream/RegistrationWindows_Conformance_GWT.res.mjs +87 -0
  20. package/i18n/en.json +8 -0
  21. package/package.json +10 -6
  22. package/rescript.json +6 -1
  23. package/src/Registration/InboundTranslation/CompleteRegistration.res +2 -2
  24. package/src/Registration/InboundTranslation/CompleteRegistration.res.mjs +3 -3
  25. package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res +1 -1
  26. package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res.mjs +1 -1
  27. package/src/Registration/InboundTranslation/SignUp.res +19 -9
  28. package/src/Registration/InboundTranslation/SignUp.res.mjs +14 -7
  29. package/src/Registration/InboundTranslation/SignUp_Translation.res +32 -7
  30. package/src/Registration/InboundTranslation/SignUp_Translation.res.mjs +41 -8
  31. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res +5 -5
  32. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res.mjs +6 -5
  33. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res +10 -8
  34. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res.mjs +18 -10
  35. package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res +24 -13
  36. package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res.mjs +26 -16
  37. package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res +115 -44
  38. package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res.mjs +204 -66
  39. package/src/Registration/StateChange/RegistrationPolicy.res +3 -0
  40. package/src/Registration/StateChange/RegistrationPolicy.res.mjs +3 -0
  41. package/src/Registration/StateChange/RegistrationPolicy_Decision.res +6 -5
  42. package/src/Registration/StateChange/RegistrationPolicy_Decision.res.mjs +22 -15
  43. package/src/Registration/StateChange/Registrations.res +67 -41
  44. package/src/Registration/StateChange/Registrations.res.mjs +84 -51
  45. package/src/Registration/StateChange/Registrations_Decision.res +82 -39
  46. package/src/Registration/StateChange/Registrations_Decision.res.mjs +116 -58
  47. package/src/Registration/StateViewStream/RegistrationWindows.res +4 -0
  48. package/src/Registration/StateViewStream/RegistrationWindows.res.mjs +3 -3
@@ -0,0 +1,102 @@
1
+ // Turning an accepted proof into an account. The password is taken from the stash the door put
2
+ // it in, once, and handed to the identity provider. It reads no table: the roles are the ones
3
+ // the accepted proof carries.
4
+
5
+ module Make = (App: Reventless.Admission.Declaration) => {
6
+ open CreateRegisteredPrincipal
7
+ open CreateRegisteredPrincipal_Translation
8
+ include ReventlessGwt.OutboundTranslation_GWT.FromSlice(
9
+ CreateRegisteredPrincipal,
10
+ CreateRegisteredPrincipal_Translation,
11
+ )
12
+ open Registration_Conformance_Examples
13
+
14
+ let member = Reventless.Role.make("Member")
15
+ let editor = Reventless.Role.make("Editor")
16
+ let item: outboundItem = {emailId: aliceId, email: aliceMail, roles: [member], proofHash: "h"}
17
+ let held = () => fakes(~stashed=[("h", goodPassword)], ())
18
+
19
+ let created: ReventlessGwt.Capabilities_Fake.call = PrincipalCreated({
20
+ contact: ToEmail(Reventless.Email.unsafe(aliceAddress)),
21
+ credential: Password(goodPassword),
22
+ groups: [nameOf(member)],
23
+ })
24
+
25
+ describe("CreateRegisteredPrincipal OutboundTranslationSlice", () => {
26
+ // scenario-id: 7c6dbee1-2a04-4eac-be89-24679ab14423
27
+ test("an accepted proof becomes an account with the password typed beside it", () =>
28
+ givenTodo("t1", item)
29
+ ->givenCapabilities(held())
30
+ ->whenTranslated
31
+ ->thenSent([Taken({key: "h"}), created])
32
+ )
33
+
34
+ // A registration granting several roles makes one account in all their groups.
35
+ // scenario-id: 1c7e9a3b-5d2f-4b8a-9e6c-0f3a5b7d9e1c
36
+ test("several roles land in all their groups", () =>
37
+ givenTodo("t1", {...item, roles: [member, editor]})
38
+ ->givenCapabilities(held())
39
+ ->whenTranslated
40
+ ->thenSent([
41
+ Taken({key: "h"}),
42
+ PrincipalCreated({
43
+ contact: ToEmail(Reventless.Email.unsafe(aliceAddress)),
44
+ credential: Password(goodPassword),
45
+ groups: [nameOf(member), nameOf(editor)],
46
+ }),
47
+ ])
48
+ )
49
+
50
+ // scenario-id: ef686ab8-6e38-467c-a77c-c4e951e41d83
51
+ test("the ledger is told the registration completed", () =>
52
+ givenTodo("t1", item)
53
+ ->givenCapabilities(held())
54
+ ->whenTranslated
55
+ ->thenCommand(aliceId, RecordRegistrationCompleted({emailId: alice}))
56
+ )
57
+
58
+ // An address the provider already holds is as registered as one made here.
59
+ // scenario-id: 7e33f9db-891d-4134-8ea2-c442a3a30f4b
60
+ test("an existing account still completes the registration", () =>
61
+ givenTodo("t1", item)
62
+ ->givenCapabilities(
63
+ fakes(
64
+ ~stashed=[("h", goodPassword)],
65
+ ~createPrincipal=async (~contact as _, ~credential as _, ~groups as _) => Error(Conflict),
66
+ (),
67
+ ),
68
+ )
69
+ ->whenTranslated
70
+ ->thenCommand(aliceId, RecordRegistrationCompleted({emailId: alice}))
71
+ )
72
+
73
+ // scenario-id: 00c97b0d-231a-420e-8570-665945551631
74
+ test("a password that has expired makes no account", () =>
75
+ givenTodo("t1", item)
76
+ ->givenCapabilities(fakes())
77
+ ->whenTranslated
78
+ ->thenSent([Taken({key: "h"})])
79
+ )
80
+
81
+ // The retry must find the password again, or it reports it gone.
82
+ // scenario-id: 2bf8593b-fcfa-4e51-a02d-29af156f8e07
83
+ test("a provider that is down gets the password back for the retry", () =>
84
+ givenTodo("t1", item)
85
+ ->givenCapabilities(
86
+ fakes(
87
+ ~stashed=[("h", goodPassword)],
88
+ ~createPrincipal=async (~contact as _, ~credential as _, ~groups as _) => Error(
89
+ Unavailable("down"),
90
+ ),
91
+ (),
92
+ ),
93
+ )
94
+ ->whenTranslated
95
+ ->thenSent([
96
+ Taken({key: "h"}),
97
+ created,
98
+ Stashed({key: "h", value: goodPassword, ttl: retryTtl}),
99
+ ])
100
+ )
101
+ })
102
+ }
@@ -0,0 +1,179 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as OutboundTranslation_GWT$ReventlessGwt from "@reventlessdev/reventless-gwt/src/OutboundTranslation_GWT.res.mjs";
4
+ import * as CreateRegisteredPrincipal$ReventlessRegistration from "../../../src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res.mjs";
5
+ import * as Registration_Conformance_Examples$ReventlessRegistration from "../Registration_Conformance_Examples.res.mjs";
6
+ import * as CreateRegisteredPrincipal_Translation$ReventlessRegistration from "../../../src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res.mjs";
7
+
8
+ function Make(App) {
9
+ let include = OutboundTranslation_GWT$ReventlessGwt.FromSlice({
10
+ name: CreateRegisteredPrincipal$ReventlessRegistration.name,
11
+ moduleUrl: CreateRegisteredPrincipal$ReventlessRegistration.moduleUrl,
12
+ consumedEventSchema: CreateRegisteredPrincipal$ReventlessRegistration.consumedEventSchema,
13
+ outboundItemSchema: CreateRegisteredPrincipal$ReventlessRegistration.outboundItemSchema,
14
+ inboundCommandSchema: CreateRegisteredPrincipal$ReventlessRegistration.inboundCommandSchema,
15
+ maxRetries: CreateRegisteredPrincipal$ReventlessRegistration.maxRetries,
16
+ targetName: CreateRegisteredPrincipal$ReventlessRegistration.targetName,
17
+ sourceNames: CreateRegisteredPrincipal$ReventlessRegistration.sourceNames,
18
+ externalSystem: undefined,
19
+ capabilityNeeds: CreateRegisteredPrincipal$ReventlessRegistration.capabilityNeeds,
20
+ traits: CreateRegisteredPrincipal$ReventlessRegistration.traits
21
+ })({
22
+ collect: CreateRegisteredPrincipal_Translation$ReventlessRegistration.collect,
23
+ translate: CreateRegisteredPrincipal_Translation$ReventlessRegistration.translate,
24
+ onExhausted: CreateRegisteredPrincipal_Translation$ReventlessRegistration.onExhausted,
25
+ moduleUrl: CreateRegisteredPrincipal_Translation$ReventlessRegistration.moduleUrl
26
+ });
27
+ let describe = include.describe;
28
+ let test = include.test;
29
+ let givenTodo = include.givenTodo;
30
+ let fakes = include.fakes;
31
+ let givenCapabilities = include.givenCapabilities;
32
+ let whenTranslated = include.whenTranslated;
33
+ let thenCommand = include.thenCommand;
34
+ let thenSent = include.thenSent;
35
+ let member = "Member";
36
+ let editor = "Editor";
37
+ let item_roles = [member];
38
+ let item = {
39
+ emailId: Registration_Conformance_Examples$ReventlessRegistration.aliceId,
40
+ email: Registration_Conformance_Examples$ReventlessRegistration.aliceMail,
41
+ roles: item_roles,
42
+ proofHash: "h"
43
+ };
44
+ let held = () => fakes(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, [[
45
+ "h",
46
+ Registration_Conformance_Examples$ReventlessRegistration.goodPassword
47
+ ]], undefined, undefined, undefined, undefined, undefined, undefined);
48
+ let created_0 = {
49
+ TAG: "ToEmail",
50
+ _0: Registration_Conformance_Examples$ReventlessRegistration.aliceAddress
51
+ };
52
+ let created_1 = {
53
+ TAG: "Password",
54
+ _0: Registration_Conformance_Examples$ReventlessRegistration.goodPassword
55
+ };
56
+ let created_2 = [Registration_Conformance_Examples$ReventlessRegistration.nameOf(member)];
57
+ let created = {
58
+ TAG: "PrincipalCreated",
59
+ contact: created_0,
60
+ credential: created_1,
61
+ groups: created_2
62
+ };
63
+ describe("CreateRegisteredPrincipal OutboundTranslationSlice", () => {
64
+ test("an accepted proof becomes an account with the password typed beside it", undefined, () => thenSent(whenTranslated(givenCapabilities(givenTodo("t1", item), held())), [
65
+ {
66
+ TAG: "Taken",
67
+ key: "h"
68
+ },
69
+ created
70
+ ]));
71
+ test("several roles land in all their groups", undefined, () => thenSent(whenTranslated(givenCapabilities(givenTodo("t1", {
72
+ emailId: Registration_Conformance_Examples$ReventlessRegistration.aliceId,
73
+ email: Registration_Conformance_Examples$ReventlessRegistration.aliceMail,
74
+ roles: [
75
+ member,
76
+ editor
77
+ ],
78
+ proofHash: "h"
79
+ }), held())), [
80
+ {
81
+ TAG: "Taken",
82
+ key: "h"
83
+ },
84
+ {
85
+ TAG: "PrincipalCreated",
86
+ contact: {
87
+ TAG: "ToEmail",
88
+ _0: Registration_Conformance_Examples$ReventlessRegistration.aliceAddress
89
+ },
90
+ credential: {
91
+ TAG: "Password",
92
+ _0: Registration_Conformance_Examples$ReventlessRegistration.goodPassword
93
+ },
94
+ groups: [
95
+ Registration_Conformance_Examples$ReventlessRegistration.nameOf(member),
96
+ Registration_Conformance_Examples$ReventlessRegistration.nameOf(editor)
97
+ ]
98
+ }
99
+ ]));
100
+ test("the ledger is told the registration completed", undefined, () => thenCommand(whenTranslated(givenCapabilities(givenTodo("t1", item), held())), Registration_Conformance_Examples$ReventlessRegistration.aliceId, {
101
+ TAG: "RecordRegistrationCompleted",
102
+ emailId: Registration_Conformance_Examples$ReventlessRegistration.alice
103
+ }));
104
+ test("an existing account still completes the registration", undefined, () => thenCommand(whenTranslated(givenCapabilities(givenTodo("t1", item), fakes(undefined, undefined, undefined, undefined, async (param, param$1, param$2) => ({
105
+ TAG: "Error",
106
+ _0: "Conflict"
107
+ }), undefined, undefined, undefined, [[
108
+ "h",
109
+ Registration_Conformance_Examples$ReventlessRegistration.goodPassword
110
+ ]], undefined, undefined, undefined, undefined, undefined, undefined))), Registration_Conformance_Examples$ReventlessRegistration.aliceId, {
111
+ TAG: "RecordRegistrationCompleted",
112
+ emailId: Registration_Conformance_Examples$ReventlessRegistration.alice
113
+ }));
114
+ test("a password that has expired makes no account", undefined, () => thenSent(whenTranslated(givenCapabilities(givenTodo("t1", item), fakes(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined))), [{
115
+ TAG: "Taken",
116
+ key: "h"
117
+ }]));
118
+ test("a provider that is down gets the password back for the retry", undefined, () => thenSent(whenTranslated(givenCapabilities(givenTodo("t1", item), fakes(undefined, undefined, undefined, undefined, async (param, param$1, param$2) => ({
119
+ TAG: "Error",
120
+ _0: {
121
+ TAG: "Unavailable",
122
+ _0: "down"
123
+ }
124
+ }), undefined, undefined, undefined, [[
125
+ "h",
126
+ Registration_Conformance_Examples$ReventlessRegistration.goodPassword
127
+ ]], undefined, undefined, undefined, undefined, undefined, undefined))), [
128
+ {
129
+ TAG: "Taken",
130
+ key: "h"
131
+ },
132
+ created,
133
+ {
134
+ TAG: "Stashed",
135
+ key: "h",
136
+ value: Registration_Conformance_Examples$ReventlessRegistration.goodPassword,
137
+ ttl: CreateRegisteredPrincipal_Translation$ReventlessRegistration.retryTtl
138
+ }
139
+ ]));
140
+ });
141
+ return {
142
+ describe: describe,
143
+ test: test,
144
+ testSync: include.testSync,
145
+ encItems: include.encItems,
146
+ commandPairJson: include.commandPairJson,
147
+ errorOf: include.errorOf,
148
+ givenEvent: include.givenEvent,
149
+ whenCollect: include.whenCollect,
150
+ thenTodos: include.thenTodos,
151
+ givenTodo: givenTodo,
152
+ fakes: fakes,
153
+ givenCapabilities: givenCapabilities,
154
+ attemptWith: include.attemptWith,
155
+ attempts: include.attempts,
156
+ whenTranslated: whenTranslated,
157
+ whenTranslateMocked: include.whenTranslateMocked,
158
+ whenTranslateRetrying: include.whenTranslateRetrying,
159
+ whenExhausted: include.whenExhausted,
160
+ thenCommand: thenCommand,
161
+ thenNoCommand: include.thenNoCommand,
162
+ thenSent: thenSent,
163
+ thenNothingSent: include.thenNothingSent,
164
+ thenRetryRecorded: include.thenRetryRecorded,
165
+ current: include.current,
166
+ statusName: include.statusName,
167
+ thenTodoStatus: include.thenTodoStatus,
168
+ member: member,
169
+ editor: editor,
170
+ item: item,
171
+ held: held,
172
+ created: created
173
+ };
174
+ }
175
+
176
+ export {
177
+ Make,
178
+ }
179
+ /* OutboundTranslation_GWT-ReventlessGwt Not a pure module */
@@ -0,0 +1,312 @@
1
+ // What arrives at the address. A fresh registration gets the secret; a taken address gets a
2
+ // notice and nothing else — the difference the caller who started it never sees. It reads no
3
+ // table: the roles an invitation names are the ones its event carries.
4
+
5
+ module Make = (App: Reventless.Admission.Declaration) => {
6
+ open SendRegistrationChallenge
7
+ open SendRegistrationChallenge_Translation
8
+ include ReventlessGwt.OutboundTranslation_GWT.FromSlice(
9
+ SendRegistrationChallenge,
10
+ SendRegistrationChallenge_Translation,
11
+ )
12
+ open Registration_Conformance_Examples
13
+
14
+ module Outcome = ReventlessGwt.Outcome
15
+
16
+ let staffName = "Merchandiser"
17
+ let fresh: outboundItem = {emailId: aliceId, email: aliceMail, alreadyRegistered: false}
18
+ let taken: outboundItem = {emailId: aliceId, email: aliceMail, alreadyRegistered: true}
19
+ let invitation: outboundItem = {
20
+ emailId: aliceId,
21
+ email: aliceMail,
22
+ alreadyRegistered: false,
23
+ invited: true,
24
+ roles: [staffName],
25
+ }
26
+ /** A reissued invitation's code: worded as an invitation, but the event does not say as
27
+ what. */
28
+ let reissuedInvitation: outboundItem = {
29
+ emailId: aliceId,
30
+ email: aliceMail,
31
+ alreadyRegistered: false,
32
+ invited: true,
33
+ }
34
+
35
+ let policy = ContactVerification.emailPolicy
36
+
37
+ let withSecrets = () =>
38
+ fakes(~token="known-secret", ~hash=t => `hashed:${t}`, ~channels=[Email], ())
39
+
40
+ let thenLedgerTold = async (pending, expected) =>
41
+ switch (await pending).result {
42
+ | Ok(Some((_, IssueRegistrationChallenge({emailId, proofHash, _})))) =>
43
+ let actual = `${emailId->ContactAddressId.toString}|${proofHash}`
44
+ actual == expected
45
+ ? Outcome.pass
46
+ : Outcome.fail(TranslateError({expected, actual: Some(actual)}))
47
+ | _ => Outcome.fail(TranslateError({expected, actual: None}))
48
+ }
49
+
50
+ /** What the ledger is told of the mail that carried the code: its language and key. */
51
+ let thenMailRecorded = async (pending, expected) =>
52
+ switch (await pending).result {
53
+ | Ok(Some((_, IssueRegistrationChallenge({?language, ?messageKey})))) =>
54
+ let actual = `${language->Option.getOr("")}|${messageKey->Option.getOr("")}`
55
+ actual == expected
56
+ ? Outcome.pass
57
+ : Outcome.fail(TranslateError({expected, actual: Some(actual)}))
58
+ | _ => Outcome.fail(TranslateError({expected, actual: None}))
59
+ }
60
+
61
+ let mail = (~subject, ~body, ~language="en"): ReventlessGwt.Capabilities_Fake.call => Sent({
62
+ recipient: ToEmail(Reventless.Email.unsafe(aliceAddress)),
63
+ message: {subject, body, language},
64
+ })
65
+
66
+ // A deployment that writes German sends the mail in German where its catalogue has the words,
67
+ // labeled as such, and the code's English where it has not.
68
+ let german = Reventless.Text.fromCatalogues(
69
+ ~default="de",
70
+ dict{
71
+ "de": dict{
72
+ "registration.challenge.subject": "Registrierung abschließen",
73
+ "registration.challenge.body": "Ihr Code lautet {token}. Er läuft in {expiresIn} ab.",
74
+ "registration.invited.body": "Sie sind eingeladen{hasRoles, select, yes {, als {roles}} other {}}. Ihr Code lautet {token}.",
75
+ },
76
+ },
77
+ )
78
+
79
+ // A deployment writing English that also offers German: a visitor who asked in German gets
80
+ // German, and the ledger is told which mail in which language carried the code.
81
+ let offersGerman = Reventless.Text.fromCatalogues(
82
+ ~default="en",
83
+ dict{
84
+ "de": dict{
85
+ "registration.challenge.subject": "Registrierung abschließen",
86
+ "registration.challenge.body": "Ihr Code lautet {token}. Er läuft in {expiresIn} ab.",
87
+ },
88
+ },
89
+ )
90
+
91
+ describe("SendRegistrationChallenge OutboundTranslationSlice", () => {
92
+ // scenario-id: 4095f5ec-db7f-40f7-a851-a268a5a779df
93
+ testSync("a request is collected once per address and time", () =>
94
+ givenEvent(
95
+ RegistrationRequested({
96
+ emailId: aliceId,
97
+ email: personal,
98
+ requestedAt: "2026-10-24T09:00:00.000Z",
99
+ }),
100
+ )
101
+ ->whenCollect
102
+ ->thenTodos([("fp:contactAddress:alice@example.com:2026-10-24T09:00:00.000Z", fresh)])
103
+ )
104
+
105
+ testSync("an erased address is not written to", () =>
106
+ givenEvent(
107
+ RegistrationRequested({
108
+ emailId: aliceId,
109
+ email: Reventless.Pii.Erased,
110
+ requestedAt: "2026-10-24T09:00:00.000Z",
111
+ }),
112
+ )
113
+ ->whenCollect
114
+ ->thenTodos([])
115
+ )
116
+
117
+ // scenario-id: 6102d230-f0c8-46c1-967f-d82fb1f97226
118
+ testSync("an invitation is collected as one, apart from a sign-up at the same time", () =>
119
+ givenEvent(
120
+ RegistrationInvited({
121
+ emailId: aliceId,
122
+ email: personal,
123
+ roles: [staffName],
124
+ invitedBy: "u_inviter",
125
+ invitedAt: "2026-10-24T09:00:00.000Z",
126
+ }),
127
+ )
128
+ ->whenCollect
129
+ ->thenTodos([
130
+ ("fp:contactAddress:alice@example.com:invited:2026-10-24T09:00:00.000Z", invitation),
131
+ ])
132
+ )
133
+
134
+ // A reissued code is worded as its claim was.
135
+ // scenario-id: 5dd47462-a2f8-4594-a9da-4b668a42a662
136
+ testSync("a reissued invitation's code is collected as an invitation", () =>
137
+ givenEvent(
138
+ RegistrationChallengeReissued({
139
+ emailId: aliceId,
140
+ email: personal,
141
+ reissuedAt: "2026-10-25T09:00:00.000Z",
142
+ invitedBy: "u_inviter",
143
+ }),
144
+ )
145
+ ->whenCollect
146
+ ->thenTodos([
147
+ (
148
+ "fp:contactAddress:alice@example.com:reissued:2026-10-25T09:00:00.000Z",
149
+ reissuedInvitation,
150
+ ),
151
+ ])
152
+ )
153
+
154
+ // scenario-id: 90b3573e-65c5-48c5-935a-3bcfa702d8b5
155
+ testSync("a reissued sign-up's code is collected as a sign-up", () =>
156
+ givenEvent(
157
+ RegistrationChallengeReissued({
158
+ emailId: aliceId,
159
+ email: personal,
160
+ reissuedAt: "2026-10-25T09:00:00.000Z",
161
+ }),
162
+ )
163
+ ->whenCollect
164
+ ->thenTodos([
165
+ (
166
+ "fp:contactAddress:alice@example.com:reissued:2026-10-25T09:00:00.000Z",
167
+ {emailId: aliceId, email: aliceMail, alreadyRegistered: false, invited: false},
168
+ ),
169
+ ])
170
+ )
171
+
172
+ // scenario-id: 102e1331-79c0-4fa9-973c-4d07609b34df
173
+ test("a challenge is opened against the hash, never the secret", () =>
174
+ givenTodo("t1", fresh)
175
+ ->givenCapabilities(withSecrets())
176
+ ->whenTranslated
177
+ ->thenLedgerTold("fp:contactAddress:alice@example.com|hashed:known-secret")
178
+ )
179
+
180
+ // scenario-id: 4e43e47e-e5b1-4c5a-9619-a83ec78a9fb8
181
+ test("the secret itself is what goes to the address", () =>
182
+ givenTodo("t1", fresh)
183
+ ->givenCapabilities(withSecrets())
184
+ ->whenTranslated
185
+ ->thenSent([
186
+ TokenDrawn({length: policy.proofLength, alphabet: policy.proofAlphabet}),
187
+ Hashed({input: "known-secret"}),
188
+ mail(~subject="Finish your registration", ~body=challengeBody(~token="known-secret")),
189
+ ])
190
+ )
191
+
192
+ // The invitation holds a week, which its wording says, and it names what it grants.
193
+ // scenario-id: 913f90ca-b8a9-4716-a03f-e2e86a073be3
194
+ test("an invitation's secret goes out worded as an invitation, naming the roles", () =>
195
+ givenTodo("t3", invitation)
196
+ ->givenCapabilities(withSecrets())
197
+ ->whenTranslated
198
+ ->thenSent([
199
+ TokenDrawn({length: policy.proofLength, alphabet: policy.proofAlphabet}),
200
+ Hashed({input: "known-secret"}),
201
+ mail(
202
+ ~subject="You are invited to create an account",
203
+ ~body=invitationBody(~token="known-secret", ~roles=[staffName]),
204
+ ),
205
+ ])
206
+ )
207
+
208
+ // scenario-id: 6b1d2f8a-4c3e-4a9b-8d7f-2e5c1a9b3d40
209
+ test("a reissued invitation's secret is worded as an invitation, with no role to name", () =>
210
+ givenTodo("t4", reissuedInvitation)
211
+ ->givenCapabilities(withSecrets())
212
+ ->whenTranslated
213
+ ->thenSent([
214
+ TokenDrawn({length: policy.proofLength, alphabet: policy.proofAlphabet}),
215
+ Hashed({input: "known-secret"}),
216
+ mail(
217
+ ~subject="You are invited to create an account",
218
+ ~body=invitationBody(~token="known-secret"),
219
+ ),
220
+ ])
221
+ )
222
+
223
+ // scenario-id: 18ffc082-763e-415b-a1b3-61d5c788cb19
224
+ test("a taken address is told someone tried, and no challenge opens", () =>
225
+ givenTodo("t2", taken)
226
+ ->givenCapabilities(withSecrets())
227
+ ->whenTranslated
228
+ ->thenSent([mail(~subject="Someone tried to register with your address", ~body=noticeBody)])
229
+ )
230
+
231
+ test("a deployment writing German sends the challenge in German", () =>
232
+ givenTodo("t1", fresh)
233
+ ->givenCapabilities(fakes(~token="known-secret", ~channels=[Email], ~text=german, ()))
234
+ ->whenTranslated
235
+ ->thenSent([
236
+ TokenDrawn({length: policy.proofLength, alphabet: policy.proofAlphabet}),
237
+ Hashed({input: "known-secret"}),
238
+ mail(
239
+ ~subject="Registrierung abschließen",
240
+ ~body="Ihr Code lautet known-secret. Er läuft in 1 Tag ab.",
241
+ ~language="de",
242
+ ),
243
+ ])
244
+ )
245
+
246
+ test("a key the catalogue lacks is sent in the code's English, labeled so", () =>
247
+ givenTodo("t3", invitation)
248
+ ->givenCapabilities(fakes(~token="known-secret", ~channels=[Email], ~text=german, ()))
249
+ ->whenTranslated
250
+ ->thenSent([
251
+ TokenDrawn({length: policy.proofLength, alphabet: policy.proofAlphabet}),
252
+ Hashed({input: "known-secret"}),
253
+ Sent({
254
+ recipient: ToEmail(Reventless.Email.unsafe(aliceAddress)),
255
+ message: {
256
+ subject: "You are invited to create an account",
257
+ body: `Sie sind eingeladen, als ${staffName}. Ihr Code lautet known-secret.`,
258
+ language: "de",
259
+ },
260
+ }),
261
+ ])
262
+ )
263
+
264
+ test("a visitor's language writes the code, and the ledger is told so", () =>
265
+ givenTodo("t1", {...fresh, language: "de-AT"})
266
+ ->givenCapabilities(fakes(~token="known-secret", ~channels=[Email], ~text=offersGerman, ()))
267
+ ->whenTranslated
268
+ ->thenMailRecorded("de|registration.challenge.body")
269
+ )
270
+
271
+ // The owner of a taken address has an account, and it says what they read; the visitor's
272
+ // request does not get to choose the language of a mail to someone else.
273
+ test("an account's own language wins over the request's", () =>
274
+ givenTodo("t2", {...taken, language: "de"})
275
+ ->givenCapabilities(
276
+ fakes(
277
+ ~channels=[Email],
278
+ ~text=Reventless.Text.fromCatalogues(
279
+ ~default="en",
280
+ ~localeOf=async _ => Some("en"),
281
+ dict{"de": dict{"registration.taken.subject": "Jemand wollte sich registrieren"}},
282
+ ),
283
+ (),
284
+ ),
285
+ )
286
+ ->whenTranslated
287
+ ->thenSent([mail(~subject="Someone tried to register with your address", ~body=noticeBody)])
288
+ )
289
+
290
+ test("a catalogue that cannot be read sends nothing, so the mail is tried again", () =>
291
+ givenTodo("t1", fresh)
292
+ ->givenCapabilities(
293
+ fakes(
294
+ ~token="known-secret",
295
+ ~channels=[Email],
296
+ ~text={...german, catalogue: async _ => Error("the catalogue did not load")},
297
+ (),
298
+ ),
299
+ )
300
+ ->whenTranslated
301
+ ->thenSent([
302
+ TokenDrawn({length: policy.proofLength, alphabet: policy.proofAlphabet}),
303
+ Hashed({input: "known-secret"}),
304
+ ])
305
+ )
306
+
307
+ // scenario-id: 72e8341c-1289-48bd-b8f0-c09202bccba5
308
+ test("a notice sends nothing back to the ledger", () =>
309
+ givenTodo("t2", taken)->givenCapabilities(withSecrets())->whenTranslated->thenNoCommand
310
+ )
311
+ })
312
+ }