@sharadox/account-web-library 0.1.0-development.27 → 0.1.0-development.30
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 +44 -0
- package/distribution/account-ban/index.d.ts +67 -0
- package/distribution/account-ban/index.d.ts.map +1 -0
- package/distribution/account-ban/index.js +233 -0
- package/distribution/account-ban/index.js.map +1 -0
- package/distribution/account-ban/type.d.ts +44 -0
- package/distribution/account-ban/type.d.ts.map +1 -0
- package/distribution/account-ban/type.js +2 -0
- package/distribution/account-ban/type.js.map +1 -0
- package/distribution/account-database/type.d.ts +114 -0
- package/distribution/account-database/type.d.ts.map +1 -1
- package/distribution/account-deletion/index.d.ts +7 -4
- package/distribution/account-deletion/index.d.ts.map +1 -1
- package/distribution/account-deletion/index.js +43 -5
- package/distribution/account-deletion/index.js.map +1 -1
- package/distribution/account-inactivity/index.d.ts +25 -0
- package/distribution/account-inactivity/index.d.ts.map +1 -0
- package/distribution/account-inactivity/index.js +100 -0
- package/distribution/account-inactivity/index.js.map +1 -0
- package/distribution/account-migration/index.d.ts.map +1 -1
- package/distribution/account-migration/index.js +120 -0
- package/distribution/account-migration/index.js.map +1 -1
- package/distribution/account-notice/index.d.ts +15 -0
- package/distribution/account-notice/index.d.ts.map +1 -0
- package/distribution/account-notice/index.js +41 -0
- package/distribution/account-notice/index.js.map +1 -0
- package/distribution/account-permission/index.d.ts +14 -0
- package/distribution/account-permission/index.d.ts.map +1 -0
- package/distribution/account-permission/index.js +91 -0
- package/distribution/account-permission/index.js.map +1 -0
- package/distribution/account-permission/type.d.ts +12 -0
- package/distribution/account-permission/type.d.ts.map +1 -0
- package/distribution/account-permission/type.js +2 -0
- package/distribution/account-permission/type.js.map +1 -0
- package/distribution/application-sync/index.d.ts +14 -0
- package/distribution/application-sync/index.d.ts.map +1 -0
- package/distribution/application-sync/index.js +96 -0
- package/distribution/application-sync/index.js.map +1 -0
- package/distribution/application-sync/type.d.ts +29 -0
- package/distribution/application-sync/type.d.ts.map +1 -0
- package/distribution/application-sync/type.js +2 -0
- package/distribution/application-sync/type.js.map +1 -0
- package/distribution/banned-contact/index.d.ts +34 -0
- package/distribution/banned-contact/index.d.ts.map +1 -0
- package/distribution/banned-contact/index.js +52 -0
- package/distribution/banned-contact/index.js.map +1 -0
- package/distribution/contact-addition-flow/index.d.ts +2 -1
- package/distribution/contact-addition-flow/index.d.ts.map +1 -1
- package/distribution/contact-addition-flow/index.js +15 -4
- package/distribution/contact-addition-flow/index.js.map +1 -1
- package/distribution/contact-addition-flow/type.d.ts +5 -2
- package/distribution/contact-addition-flow/type.d.ts.map +1 -1
- package/distribution/contact-channel/type.d.ts +24 -0
- package/distribution/contact-channel/type.d.ts.map +1 -1
- package/distribution/email-channel/index.d.ts.map +1 -1
- package/distribution/email-channel/index.js +78 -0
- package/distribution/email-channel/index.js.map +1 -1
- package/distribution/person-account/index.d.ts +1 -1
- package/distribution/person-account/index.d.ts.map +1 -1
- package/distribution/person-account/index.js +10 -2
- package/distribution/person-account/index.js.map +1 -1
- package/distribution/person-account/type.d.ts +2 -0
- package/distribution/person-account/type.d.ts.map +1 -1
- package/distribution/role-grant/index.d.ts +38 -0
- package/distribution/role-grant/index.d.ts.map +1 -0
- package/distribution/role-grant/index.js +142 -0
- package/distribution/role-grant/index.js.map +1 -0
- package/distribution/role-grant/type.d.ts +40 -0
- package/distribution/role-grant/type.d.ts.map +1 -0
- package/distribution/role-grant/type.js +2 -0
- package/distribution/role-grant/type.js.map +1 -0
- package/distribution/rule-sync/index.d.ts +28 -0
- package/distribution/rule-sync/index.d.ts.map +1 -0
- package/distribution/rule-sync/index.js +80 -0
- package/distribution/rule-sync/index.js.map +1 -0
- package/distribution/rule-sync/type.d.ts +17 -0
- package/distribution/rule-sync/type.d.ts.map +1 -0
- package/distribution/rule-sync/type.js +2 -0
- package/distribution/rule-sync/type.js.map +1 -0
- package/distribution/second-factor-finish/index.d.ts +2 -1
- package/distribution/second-factor-finish/index.d.ts.map +1 -1
- package/distribution/second-factor-finish/index.js +12 -7
- package/distribution/second-factor-finish/index.js.map +1 -1
- package/distribution/second-factor-finish/type.d.ts +4 -1
- package/distribution/second-factor-finish/type.d.ts.map +1 -1
- package/distribution/sign-up-finish/index.d.ts +3 -2
- package/distribution/sign-up-finish/index.d.ts.map +1 -1
- package/distribution/sign-up-finish/index.js +8 -2
- package/distribution/sign-up-finish/index.js.map +1 -1
- package/distribution/sign-up-finish/type.d.ts +3 -1
- package/distribution/sign-up-finish/type.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -304,6 +304,50 @@ Removing one is `removeContact` (the last sign-in contact can't go).
|
|
|
304
304
|
|
|
305
305
|
Tests: `createTestPerson(database, identifier)` (`test-person`).
|
|
306
306
|
|
|
307
|
+
## Roles and permissions
|
|
308
|
+
|
|
309
|
+
Every application declares its permissions and roles in code, and the account system answers what an account may
|
|
310
|
+
do there.
|
|
311
|
+
|
|
312
|
+
- `syncApplication(database, { key, name, permissions, roles })` (`application-sync`): run at every deploy. Each
|
|
313
|
+
permission starts with the application's key (`platform.job.read`); a role lists permissions, and may be the
|
|
314
|
+
application's `default` (every account holds it, with no grant) or `exclusive` (while granted, only its
|
|
315
|
+
permissions count: a ban). Undeclared permissions and roles go, except a role still granted. Refusals:
|
|
316
|
+
`foreign-permission`, `unknown-permission`, `defaults` (more than one).
|
|
317
|
+
- `grantRole(database, { accountId, application, role, resource?, startsAt?, endsAt?, source?, grantedBy?, reason? })`
|
|
318
|
+
(`role-grant`) → `{ granted: true, grantId }` or a reason (`no-role`, `no-account`, `not-allowed`, `escalation`).
|
|
319
|
+
Given by someone, it needs their `account.role.assign` (`ROLE_ASSIGN_PERMISSION`, in the `account` application)
|
|
320
|
+
and every permission of the role: nobody hands out more than they hold. `revokeGrant(database, { grantId,
|
|
321
|
+
revokedBy? })` ends it now (history kept); `listGrants(database, { accountId })` lists them with `active`.
|
|
322
|
+
- `accountPermissions(database, { accountId, application, resource?, scope? })` (`account-permission`) → the set of
|
|
323
|
+
permissions now: the default role plus active grants (an active exclusive one wins), limited to `scope`, and for an
|
|
324
|
+
agent to what its owner may do right now. Built on `effectivePermissions`.
|
|
325
|
+
|
|
326
|
+
In the database (migration `0005-role`): `permission`, `role`, `role_permission`, `role_grant`. A role still
|
|
327
|
+
granted can't be deleted (`RESTRICT`); a grant outlives the account that gave it (`granted_by` becomes null).
|
|
328
|
+
|
|
329
|
+
## Rules, bans and appeals
|
|
330
|
+
|
|
331
|
+
- `syncRules(database, { application, rules })` (`rule-sync`): public rules, the application's own or global
|
|
332
|
+
(`application: null`), each with its words per language and its penalty schedule (seconds or `"permanent"` for the
|
|
333
|
+
1st, 2nd… offense; the last repeats). A changed rule gets a new version; bans keep the version they cited.
|
|
334
|
+
`listRules(database, { application })` gives the newest versions, for the public rules page.
|
|
335
|
+
- `banAccount(database, { accountId, application, rules, statement, evidence?, by? })` (`account-ban`): the length
|
|
336
|
+
comes from the rules (this offense for each, per account, rule and application; the longest wins), so equal
|
|
337
|
+
offenses get equal penalties. The ban is the application's exclusive role, granted until then or for good. `by`
|
|
338
|
+
needs `account.ban.create` (`BAN_PERMISSION`). Refusals: `not-allowed`, `no-rule`, `no-ban-role`.
|
|
339
|
+
- `appealBan(database, { banId, accountId, text })`: one appeal per ban, by the banned account.
|
|
340
|
+
`decideAppeal(database, { appealId, by, decision, reasons, endsAt? })`: `upheld`, `shortened` (to `endsAt`) or
|
|
341
|
+
`lifted`, once, by someone with `account.appeal.decide` (`APPEAL_PERMISSION`). `listBans(database, { accountId })`.
|
|
342
|
+
- The banned-contact ledger (`banned-contact`): deleting a banned account (`deleteAccount` now takes
|
|
343
|
+
`ledgerPepper`, `deriveSecret(ACCOUNT_SECRET, "banned-contact")`) keeps each verified contact's HMAC (emails
|
|
344
|
+
without `+tags`) until the ban ends. `finishSignUp` and `startContactAddition` refuse such a contact
|
|
345
|
+
(`contact-banned`); `contactBanned(database, { contact, pepper, application })` asks directly;
|
|
346
|
+
`pruneBannedContacts(database)` forgets ended ones (a daily job).
|
|
347
|
+
|
|
348
|
+
In the database (migration `0006-rule-ban`): `rule`, `ban`, `ban_rule` (a cited rule version can't be deleted),
|
|
349
|
+
`appeal` (one per ban), `banned_contact` (no link to any account).
|
|
350
|
+
|
|
307
351
|
## License
|
|
308
352
|
|
|
309
353
|
Sharadox Open Source License 0.1.0 (see `LICENSE.md`).
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Kysely } from "kysely";
|
|
2
|
+
import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
|
|
3
|
+
import type { BanRequest, BanResult, BanView } from "@sharadox/account-web-library/account-ban/type";
|
|
4
|
+
/** Banning, in the account system's own application. */
|
|
5
|
+
export declare const BAN_PERMISSION = "account.ban.create";
|
|
6
|
+
/** Deciding appeals, in the account system's own application. */
|
|
7
|
+
export declare const APPEAL_PERMISSION = "account.appeal.decide";
|
|
8
|
+
/**
|
|
9
|
+
* Bans an account in an application for breaking rules: the length comes from the rules' penalty schedules (this
|
|
10
|
+
* offense for each, counted per account, rule and application; the longest wins), so equal offenses get equal
|
|
11
|
+
* penalties. The ban is the application's exclusive role, granted until then (or for good), with a record of the
|
|
12
|
+
* rule versions broken and the statement of reasons. Recorded in the audit log.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* await banAccount(database, { accountId, application: "platform", rules: ["spam"], statement, by: moderator });
|
|
16
|
+
*/
|
|
17
|
+
export declare function banAccount(database: Kysely<AccountDatabase>, { accountId, application, rules, statement, evidence, by, now }: BanRequest): Promise<BanResult>;
|
|
18
|
+
/**
|
|
19
|
+
* The one appeal a ban may have, written by the banned account.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* await appealBan(database, { banId, accountId, text });
|
|
23
|
+
*/
|
|
24
|
+
export declare function appealBan(database: Kysely<AccountDatabase>, { banId, accountId, text, now }: {
|
|
25
|
+
banId: string;
|
|
26
|
+
accountId: string;
|
|
27
|
+
text: string;
|
|
28
|
+
now?: number;
|
|
29
|
+
}): Promise<{
|
|
30
|
+
appealed: true;
|
|
31
|
+
appealId: string;
|
|
32
|
+
} | {
|
|
33
|
+
appealed: false;
|
|
34
|
+
reason: "no-ban" | "already-appealed";
|
|
35
|
+
}>;
|
|
36
|
+
/**
|
|
37
|
+
* A moderator's decision on an appeal, with its reasons: `upheld` keeps the ban, `shortened` moves its end to
|
|
38
|
+
* `endsAt`, `lifted` ends it now. Decided once.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* await decideAppeal(database, { appealId, by: moderator, decision: "lifted", reasons });
|
|
42
|
+
*/
|
|
43
|
+
export declare function decideAppeal(database: Kysely<AccountDatabase>, { appealId, by, decision, reasons, endsAt, now, }: {
|
|
44
|
+
appealId: string;
|
|
45
|
+
by: string;
|
|
46
|
+
decision: "upheld" | "shortened" | "lifted";
|
|
47
|
+
reasons: string;
|
|
48
|
+
endsAt?: number;
|
|
49
|
+
now?: number;
|
|
50
|
+
}): Promise<{
|
|
51
|
+
decided: true;
|
|
52
|
+
} | {
|
|
53
|
+
decided: false;
|
|
54
|
+
reason: "not-allowed" | "no-appeal" | "already-decided";
|
|
55
|
+
}>;
|
|
56
|
+
/**
|
|
57
|
+
* An account's bans, newest first: the rules cited, the statement, the penalty, when it ends, whether it is active,
|
|
58
|
+
* and its appeal.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* const bans = await listBans(database, { accountId });
|
|
62
|
+
*/
|
|
63
|
+
export declare function listBans(database: Kysely<AccountDatabase>, { accountId, now }: {
|
|
64
|
+
accountId: string;
|
|
65
|
+
now?: number;
|
|
66
|
+
}): Promise<BanView[]>;
|
|
67
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/account-ban/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAA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CAAC;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,GACA,OAAO,CAAC;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,aAAa,GAAG,WAAW,GAAG,iBAAiB,CAAA;CAAE,CAAC,CA8B1G;AAED;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAC5B,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,SAAS,EAAE,GAAgB,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GACnE,OAAO,CAAC,OAAO,EAAE,CAAC,CA8CpB"}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { uuidVersion7 } from "@sharadox/web-library/identifier/uuid-version-7";
|
|
2
|
+
import { accountPermissions } from "@sharadox/account-web-library/account-permission";
|
|
3
|
+
import { recordAuditEvent } from "@sharadox/account-web-library/audit-event";
|
|
4
|
+
import { banLength } from "@sharadox/account-web-library/ban-length";
|
|
5
|
+
import { revokeGrant } from "@sharadox/account-web-library/role-grant";
|
|
6
|
+
/** Banning, in the account system's own application. */
|
|
7
|
+
export const BAN_PERMISSION = "account.ban.create";
|
|
8
|
+
/** Deciding appeals, in the account system's own application. */
|
|
9
|
+
export const APPEAL_PERMISSION = "account.appeal.decide";
|
|
10
|
+
const allowed = async (database, accountId, permission) => (await accountPermissions(database, { accountId, application: "account" })).has(permission);
|
|
11
|
+
/**
|
|
12
|
+
* Bans an account in an application for breaking rules: the length comes from the rules' penalty schedules (this
|
|
13
|
+
* offense for each, counted per account, rule and application; the longest wins), so equal offenses get equal
|
|
14
|
+
* penalties. The ban is the application's exclusive role, granted until then (or for good), with a record of the
|
|
15
|
+
* rule versions broken and the statement of reasons. Recorded in the audit log.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* await banAccount(database, { accountId, application: "platform", rules: ["spam"], statement, by: moderator });
|
|
19
|
+
*/
|
|
20
|
+
export async function banAccount(database, { accountId, application, rules, statement, evidence, by, now = Date.now() }) {
|
|
21
|
+
if (by && !(await allowed(database, by, BAN_PERMISSION)))
|
|
22
|
+
return { banned: false, reason: "not-allowed" };
|
|
23
|
+
const app = await database
|
|
24
|
+
.selectFrom("application")
|
|
25
|
+
.select("id")
|
|
26
|
+
.where("key", "=", application)
|
|
27
|
+
.executeTakeFirstOrThrow();
|
|
28
|
+
if (rules.length === 0)
|
|
29
|
+
return { banned: false, reason: "no-rule", detail: "" };
|
|
30
|
+
const cited = [];
|
|
31
|
+
for (const code of rules) {
|
|
32
|
+
const rule = await database
|
|
33
|
+
.selectFrom("rule")
|
|
34
|
+
.select(["id", "code", "schedule"])
|
|
35
|
+
.where("code", "=", code)
|
|
36
|
+
.where((where) => where.or([where("application_id", "=", app.id), where("application_id", "is", null)]))
|
|
37
|
+
.orderBy("version", "desc")
|
|
38
|
+
.executeTakeFirst();
|
|
39
|
+
if (!rule)
|
|
40
|
+
return { banned: false, reason: "no-rule", detail: code };
|
|
41
|
+
cited.push(rule);
|
|
42
|
+
}
|
|
43
|
+
const role = await database
|
|
44
|
+
.selectFrom("role")
|
|
45
|
+
.select("id")
|
|
46
|
+
.where("application_id", "=", app.id)
|
|
47
|
+
.where("exclusive", "=", true)
|
|
48
|
+
.orderBy("key")
|
|
49
|
+
.executeTakeFirst();
|
|
50
|
+
if (!role)
|
|
51
|
+
return { banned: false, reason: "no-ban-role" };
|
|
52
|
+
const broken = [];
|
|
53
|
+
for (const rule of cited) {
|
|
54
|
+
const previous = await database
|
|
55
|
+
.selectFrom("ban_rule")
|
|
56
|
+
.innerJoin("rule", "rule.id", "ban_rule.rule_id")
|
|
57
|
+
.innerJoin("ban", "ban.id", "ban_rule.ban_id")
|
|
58
|
+
.select((select) => select.fn.countAll().as("count"))
|
|
59
|
+
.where("ban.account_id", "=", accountId)
|
|
60
|
+
.where("rule.code", "=", rule.code)
|
|
61
|
+
.where("rule.application_id", "is not distinct from", app.id)
|
|
62
|
+
.executeTakeFirstOrThrow();
|
|
63
|
+
broken.push({ schedule: rule.schedule, previousOffenses: Number(previous.count) });
|
|
64
|
+
}
|
|
65
|
+
const penalty = banLength(broken);
|
|
66
|
+
const endsAt = penalty === "permanent" ? null : new Date(now + penalty * 1000);
|
|
67
|
+
const banId = uuidVersion7({ now });
|
|
68
|
+
await database.transaction().execute(async (transaction) => {
|
|
69
|
+
const grantId = uuidVersion7({ now });
|
|
70
|
+
await transaction
|
|
71
|
+
.insertInto("role_grant")
|
|
72
|
+
.values({
|
|
73
|
+
id: grantId,
|
|
74
|
+
account_id: accountId,
|
|
75
|
+
role_id: role.id,
|
|
76
|
+
starts_at: new Date(now),
|
|
77
|
+
ends_at: endsAt,
|
|
78
|
+
source: "ban",
|
|
79
|
+
granted_by: by ?? null,
|
|
80
|
+
reason: statement,
|
|
81
|
+
})
|
|
82
|
+
.execute();
|
|
83
|
+
await transaction
|
|
84
|
+
.insertInto("ban")
|
|
85
|
+
.values({
|
|
86
|
+
id: banId,
|
|
87
|
+
grant_id: grantId,
|
|
88
|
+
account_id: accountId,
|
|
89
|
+
statement,
|
|
90
|
+
evidence: evidence ?? null,
|
|
91
|
+
penalty: String(penalty),
|
|
92
|
+
created_by: by ?? null,
|
|
93
|
+
})
|
|
94
|
+
.execute();
|
|
95
|
+
await transaction
|
|
96
|
+
.insertInto("ban_rule")
|
|
97
|
+
.values(cited.map((rule) => ({ id: uuidVersion7({ now }), ban_id: banId, rule_id: rule.id })))
|
|
98
|
+
.execute();
|
|
99
|
+
await recordAuditEvent(transaction, {
|
|
100
|
+
accountId,
|
|
101
|
+
actorAccountId: by ?? null,
|
|
102
|
+
application,
|
|
103
|
+
action: "ban.created",
|
|
104
|
+
detail: { banId, rules, penalty },
|
|
105
|
+
now,
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
return { banned: true, banId, endsAt };
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The one appeal a ban may have, written by the banned account.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* await appealBan(database, { banId, accountId, text });
|
|
115
|
+
*/
|
|
116
|
+
export async function appealBan(database, { banId, accountId, text, now = Date.now() }) {
|
|
117
|
+
const ban = await database
|
|
118
|
+
.selectFrom("ban")
|
|
119
|
+
.select("id")
|
|
120
|
+
.where("id", "=", banId)
|
|
121
|
+
.where("account_id", "=", accountId)
|
|
122
|
+
.executeTakeFirst();
|
|
123
|
+
if (!ban)
|
|
124
|
+
return { appealed: false, reason: "no-ban" };
|
|
125
|
+
const existing = await database.selectFrom("appeal").select("id").where("ban_id", "=", banId).executeTakeFirst();
|
|
126
|
+
if (existing)
|
|
127
|
+
return { appealed: false, reason: "already-appealed" };
|
|
128
|
+
// The database still refuses a second one sent at the same moment (unique ban_id).
|
|
129
|
+
const appealId = uuidVersion7({ now });
|
|
130
|
+
await database
|
|
131
|
+
.insertInto("appeal")
|
|
132
|
+
.values({ id: appealId, ban_id: banId, text, created_at: new Date(now) })
|
|
133
|
+
.execute();
|
|
134
|
+
await recordAuditEvent(database, { accountId, action: "ban.appealed", detail: { banId, appealId }, now });
|
|
135
|
+
return { appealed: true, appealId };
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* A moderator's decision on an appeal, with its reasons: `upheld` keeps the ban, `shortened` moves its end to
|
|
139
|
+
* `endsAt`, `lifted` ends it now. Decided once.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* await decideAppeal(database, { appealId, by: moderator, decision: "lifted", reasons });
|
|
143
|
+
*/
|
|
144
|
+
export async function decideAppeal(database, { appealId, by, decision, reasons, endsAt, now = Date.now(), }) {
|
|
145
|
+
if (!(await allowed(database, by, APPEAL_PERMISSION)))
|
|
146
|
+
return { decided: false, reason: "not-allowed" };
|
|
147
|
+
const appeal = await database
|
|
148
|
+
.selectFrom("appeal")
|
|
149
|
+
.innerJoin("ban", "ban.id", "appeal.ban_id")
|
|
150
|
+
.select(["appeal.decision", "ban.grant_id", "ban.account_id", "ban.id as banId"])
|
|
151
|
+
.where("appeal.id", "=", appealId)
|
|
152
|
+
.executeTakeFirst();
|
|
153
|
+
if (!appeal)
|
|
154
|
+
return { decided: false, reason: "no-appeal" };
|
|
155
|
+
if (appeal.decision)
|
|
156
|
+
return { decided: false, reason: "already-decided" };
|
|
157
|
+
if (decision === "lifted")
|
|
158
|
+
await revokeGrant(database, { grantId: appeal.grant_id, revokedBy: by, now });
|
|
159
|
+
if (decision === "shortened" && endsAt !== undefined)
|
|
160
|
+
await database
|
|
161
|
+
.updateTable("role_grant")
|
|
162
|
+
.set({ ends_at: new Date(endsAt) })
|
|
163
|
+
.where("id", "=", appeal.grant_id)
|
|
164
|
+
.execute();
|
|
165
|
+
await database
|
|
166
|
+
.updateTable("appeal")
|
|
167
|
+
.set({ decision, reasons, decided_by: by, decided_at: new Date(now) })
|
|
168
|
+
.where("id", "=", appealId)
|
|
169
|
+
.execute();
|
|
170
|
+
await recordAuditEvent(database, {
|
|
171
|
+
accountId: appeal.account_id,
|
|
172
|
+
actorAccountId: by,
|
|
173
|
+
action: "ban.appeal-decided",
|
|
174
|
+
detail: { banId: appeal.banId, appealId, decision },
|
|
175
|
+
now,
|
|
176
|
+
});
|
|
177
|
+
return { decided: true };
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* An account's bans, newest first: the rules cited, the statement, the penalty, when it ends, whether it is active,
|
|
181
|
+
* and its appeal.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* const bans = await listBans(database, { accountId });
|
|
185
|
+
*/
|
|
186
|
+
export async function listBans(database, { accountId, now = Date.now() }) {
|
|
187
|
+
const bans = await database
|
|
188
|
+
.selectFrom("ban")
|
|
189
|
+
.innerJoin("role_grant", "role_grant.id", "ban.grant_id")
|
|
190
|
+
.innerJoin("role", "role.id", "role_grant.role_id")
|
|
191
|
+
.leftJoin("application", "application.id", "role.application_id")
|
|
192
|
+
.leftJoin("appeal", "appeal.ban_id", "ban.id")
|
|
193
|
+
.select([
|
|
194
|
+
"ban.id as banId",
|
|
195
|
+
"application.key as application",
|
|
196
|
+
"ban.statement",
|
|
197
|
+
"ban.penalty",
|
|
198
|
+
"role_grant.starts_at as startsAt",
|
|
199
|
+
"role_grant.ends_at as endsAt",
|
|
200
|
+
"appeal.id as appealId",
|
|
201
|
+
"appeal.text as appealText",
|
|
202
|
+
"appeal.decision",
|
|
203
|
+
"appeal.reasons",
|
|
204
|
+
])
|
|
205
|
+
.where("ban.account_id", "=", accountId)
|
|
206
|
+
.orderBy("ban.id", "desc")
|
|
207
|
+
.execute();
|
|
208
|
+
const views = [];
|
|
209
|
+
for (const ban of bans) {
|
|
210
|
+
const rules = await database
|
|
211
|
+
.selectFrom("ban_rule")
|
|
212
|
+
.innerJoin("rule", "rule.id", "ban_rule.rule_id")
|
|
213
|
+
.select("rule.code")
|
|
214
|
+
.where("ban_rule.ban_id", "=", ban.banId)
|
|
215
|
+
.orderBy("rule.code")
|
|
216
|
+
.execute();
|
|
217
|
+
views.push({
|
|
218
|
+
banId: ban.banId,
|
|
219
|
+
application: ban.application,
|
|
220
|
+
rules: rules.map(({ code }) => code),
|
|
221
|
+
statement: ban.statement,
|
|
222
|
+
penalty: ban.penalty,
|
|
223
|
+
startsAt: ban.startsAt,
|
|
224
|
+
endsAt: ban.endsAt,
|
|
225
|
+
active: ban.startsAt.getTime() <= now && (ban.endsAt === null || now < ban.endsAt.getTime()),
|
|
226
|
+
appeal: ban.appealId
|
|
227
|
+
? { appealId: ban.appealId, text: ban.appealText, decision: ban.decision, reasons: ban.reasons }
|
|
228
|
+
: null,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
return views;
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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SACT,CAAC,CAAC;IACL,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export interface BanRequest {
|
|
2
|
+
accountId: string;
|
|
3
|
+
/** The application's key (`platform`): its exclusive role is the ban. */
|
|
4
|
+
application: string;
|
|
5
|
+
/** The codes of the rules broken (newest versions), the application's own or global. */
|
|
6
|
+
rules: string[];
|
|
7
|
+
/** The statement of reasons the account is shown. */
|
|
8
|
+
statement: string;
|
|
9
|
+
evidence?: string;
|
|
10
|
+
/** The moderator: needs `account.ban.create`. The system without it. */
|
|
11
|
+
by?: string;
|
|
12
|
+
now?: number;
|
|
13
|
+
}
|
|
14
|
+
export type BanResult = {
|
|
15
|
+
banned: true;
|
|
16
|
+
banId: string;
|
|
17
|
+
endsAt: Date | null;
|
|
18
|
+
} | {
|
|
19
|
+
banned: false;
|
|
20
|
+
reason: "not-allowed" | "no-ban-role";
|
|
21
|
+
} | {
|
|
22
|
+
banned: false;
|
|
23
|
+
reason: "no-rule";
|
|
24
|
+
detail: string;
|
|
25
|
+
};
|
|
26
|
+
/** A ban as the banned account, or a moderator, sees it. */
|
|
27
|
+
export interface BanView {
|
|
28
|
+
banId: string;
|
|
29
|
+
application: string | null;
|
|
30
|
+
rules: string[];
|
|
31
|
+
statement: string;
|
|
32
|
+
/** Seconds, or "permanent". */
|
|
33
|
+
penalty: string;
|
|
34
|
+
startsAt: Date;
|
|
35
|
+
endsAt: Date | null;
|
|
36
|
+
active: boolean;
|
|
37
|
+
appeal: {
|
|
38
|
+
appealId: string;
|
|
39
|
+
text: string;
|
|
40
|
+
decision: string | null;
|
|
41
|
+
reasons: string | null;
|
|
42
|
+
} | null;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/account-ban/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,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account-ban/type.ts"],"names":[],"mappings":""}
|
|
@@ -21,6 +21,8 @@ export interface AccountTable {
|
|
|
21
21
|
owner_id: string | null;
|
|
22
22
|
created_at: DefaultTime;
|
|
23
23
|
last_active_at: DefaultTime;
|
|
24
|
+
/** The language its notices are written in (`pt-PT`); English when null. */
|
|
25
|
+
language: ColumnType<string | null, string | null | undefined, string | null>;
|
|
24
26
|
}
|
|
25
27
|
/** A way to reach an account (email now; phone and messaging later). */
|
|
26
28
|
export interface ContactTable {
|
|
@@ -130,6 +132,108 @@ export interface AccountSessionTable {
|
|
|
130
132
|
/** When a fresh code last confirmed it is really them, for sensitive changes (`step-up`). */
|
|
131
133
|
step_up_at: ColumnType<Date | null, Date | null | undefined, Date | null>;
|
|
132
134
|
}
|
|
135
|
+
/** Something an account may do in one application (`platform.job.read`); declared by the application. */
|
|
136
|
+
export interface PermissionTable {
|
|
137
|
+
id: string;
|
|
138
|
+
application_id: string;
|
|
139
|
+
/** Starts with the application's key. */
|
|
140
|
+
key: string;
|
|
141
|
+
description: Generated<string>;
|
|
142
|
+
created_at: DefaultTime;
|
|
143
|
+
}
|
|
144
|
+
/** A set of permissions in one application (or every one: `application_id` null). */
|
|
145
|
+
export interface RoleTable {
|
|
146
|
+
id: string;
|
|
147
|
+
application_id: string | null;
|
|
148
|
+
key: string;
|
|
149
|
+
name: string;
|
|
150
|
+
/** While granted, the account has only this role's permissions there (how bans work). */
|
|
151
|
+
exclusive: Generated<boolean>;
|
|
152
|
+
/** Every account holds its application's default role, without a grant. */
|
|
153
|
+
is_default: Generated<boolean>;
|
|
154
|
+
created_at: DefaultTime;
|
|
155
|
+
}
|
|
156
|
+
export interface RolePermissionTable {
|
|
157
|
+
id: string;
|
|
158
|
+
role_id: string;
|
|
159
|
+
permission_id: string;
|
|
160
|
+
}
|
|
161
|
+
/** A role given to an account, maybe for one resource, from a moment until another (or for good). */
|
|
162
|
+
export interface RoleGrantTable {
|
|
163
|
+
id: string;
|
|
164
|
+
account_id: string;
|
|
165
|
+
role_id: string;
|
|
166
|
+
/** `platform:project:42`; null for the whole application. */
|
|
167
|
+
resource: string | null;
|
|
168
|
+
starts_at: DefaultTime;
|
|
169
|
+
ends_at: Date | null;
|
|
170
|
+
source: "manual" | "membership" | "ban" | "system";
|
|
171
|
+
/** Who gave it; null for the system, or once that account is gone. */
|
|
172
|
+
granted_by: string | null;
|
|
173
|
+
reason: string | null;
|
|
174
|
+
created_at: DefaultTime;
|
|
175
|
+
}
|
|
176
|
+
/** Words in each language (`{ en, pt }`). */
|
|
177
|
+
type Words = Record<string, string>;
|
|
178
|
+
/** One version of a public rule, with its penalties for the 1st, 2nd… offense (seconds, or "permanent"). */
|
|
179
|
+
export interface RuleTable {
|
|
180
|
+
id: string;
|
|
181
|
+
/** Null for every application. */
|
|
182
|
+
application_id: string | null;
|
|
183
|
+
code: string;
|
|
184
|
+
version: number;
|
|
185
|
+
title: ColumnType<Words, Words | string, Words | string>;
|
|
186
|
+
description: ColumnType<Words, Words | string, Words | string>;
|
|
187
|
+
schedule: ColumnType<(number | "permanent")[], (number | "permanent")[] | string, (number | "permanent")[] | string>;
|
|
188
|
+
created_at: DefaultTime;
|
|
189
|
+
}
|
|
190
|
+
/** A ban: the exclusive grant it made, its statement of reasons, and how its length was reached. */
|
|
191
|
+
export interface BanTable {
|
|
192
|
+
id: string;
|
|
193
|
+
grant_id: string;
|
|
194
|
+
account_id: string;
|
|
195
|
+
statement: string;
|
|
196
|
+
evidence: string | null;
|
|
197
|
+
/** Seconds, or "permanent". */
|
|
198
|
+
penalty: string;
|
|
199
|
+
created_by: string | null;
|
|
200
|
+
created_at: DefaultTime;
|
|
201
|
+
}
|
|
202
|
+
/** A rule version a ban cites. */
|
|
203
|
+
export interface BanRuleTable {
|
|
204
|
+
id: string;
|
|
205
|
+
ban_id: string;
|
|
206
|
+
rule_id: string;
|
|
207
|
+
}
|
|
208
|
+
/** The one appeal a ban may have, and its decision. */
|
|
209
|
+
export interface AppealTable {
|
|
210
|
+
id: string;
|
|
211
|
+
ban_id: string;
|
|
212
|
+
text: string;
|
|
213
|
+
created_at: DefaultTime;
|
|
214
|
+
decision: "upheld" | "shortened" | "lifted" | null;
|
|
215
|
+
reasons: string | null;
|
|
216
|
+
decided_by: string | null;
|
|
217
|
+
decided_at: Date | null;
|
|
218
|
+
}
|
|
219
|
+
/** A banned account's contact, kept (as an HMAC only) after the account is deleted, until the ban ends. */
|
|
220
|
+
export interface BannedContactTable {
|
|
221
|
+
id: string;
|
|
222
|
+
contact_hash: string;
|
|
223
|
+
application_id: string | null;
|
|
224
|
+
ends_at: Date | null;
|
|
225
|
+
rule_codes: string[];
|
|
226
|
+
created_at: DefaultTime;
|
|
227
|
+
}
|
|
228
|
+
/** An inactivity warning sent, for one period of inactivity (from `active_at`). */
|
|
229
|
+
export interface InactivityWarningTable {
|
|
230
|
+
id: string;
|
|
231
|
+
account_id: string;
|
|
232
|
+
stage: "6-months" | "3-months" | "1-month" | "1-week" | "1-day";
|
|
233
|
+
/** The `last_active_at` it counted from: signing in starts a new period. */
|
|
234
|
+
active_at: Date;
|
|
235
|
+
sent_at: DefaultTime;
|
|
236
|
+
}
|
|
133
237
|
/** The tables `migrateAccount` creates, for typing a Kysely instance. */
|
|
134
238
|
export interface AccountDatabase {
|
|
135
239
|
application: ApplicationTable;
|
|
@@ -143,6 +247,16 @@ export interface AccountDatabase {
|
|
|
143
247
|
account_picture: AccountPictureTable;
|
|
144
248
|
totp_credential: TotpCredentialTable;
|
|
145
249
|
recovery_code: RecoveryCodeTable;
|
|
250
|
+
permission: PermissionTable;
|
|
251
|
+
role: RoleTable;
|
|
252
|
+
role_permission: RolePermissionTable;
|
|
253
|
+
role_grant: RoleGrantTable;
|
|
254
|
+
rule: RuleTable;
|
|
255
|
+
ban: BanTable;
|
|
256
|
+
ban_rule: BanRuleTable;
|
|
257
|
+
appeal: AppealTable;
|
|
258
|
+
banned_contact: BannedContactTable;
|
|
259
|
+
inactivity_warning: InactivityWarningTable;
|
|
146
260
|
}
|
|
147
261
|
/** The account tables and the protection tables (rate limits, spending caps, used challenges) the server needs. */
|
|
148
262
|
export type AccountServerDatabase = AccountDatabase & ProtectionDatabase;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/account-database/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2DAA2D,CAAC;AACpG,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEpD,wDAAwD;AACxD,KAAK,WAAW,GAAG,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,EAAE,IAAI,CAAC,CAAC;AAE5D,sFAAsF;AACtF,MAAM,WAAW,gBAAgB;IAC/B,cAAc;IACd,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACtB,uFAAuF;IACvF,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,WAAW,CAAC;CACzB;AAED,+CAA+C;AAC/C,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC;IACzB,wDAAwD;IACxD,IAAI,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,WAAW,CAAC;IACxB,cAAc,EAAE,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/account-database/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2DAA2D,CAAC;AACpG,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEpD,wDAAwD;AACxD,KAAK,WAAW,GAAG,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,EAAE,IAAI,CAAC,C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IAChB,eAAe,EAAE,mBAAmB,CAAC;IACrC,UAAU,EAAE,cAAc,CAAC;IAC3B,IAAI,EAAE,SAAS,CAAC;IAChB,GAAG,EAAE,QAAQ,CAAC;IACd,QAAQ,EAAE,YAAY,CAAC;IACvB,MAAM,EAAE,WAAW,CAAC;IACpB,cAAc,EAAE,kBAAkB,CAAC;IACnC,kBAAkB,EAAE,sBAAsB,CAAC;CAC5C;AAED,mHAAmH;AACnH,MAAM,MAAM,qBAAqB,GAAG,eAAe,GAAG,kBAAkB,CAAC"}
|
|
@@ -4,14 +4,17 @@ import type { PictureStorage } from "@sharadox/account-web-library/picture-stora
|
|
|
4
4
|
/**
|
|
5
5
|
* Deletes an account for good: its picture file, then the account with everything that belongs to it (identifier,
|
|
6
6
|
* contacts, sessions, two-factor, agents), in one transaction. Its identifier is free at once. The audit log keeps
|
|
7
|
-
* `account.deleted` and earlier events under the bare id, with no personal data.
|
|
8
|
-
* (
|
|
7
|
+
* `account.deleted` and earlier events under the bare id, with no personal data. An account banned somewhere leaves
|
|
8
|
+
* its contacts in the banned-contact ledger (HMACs under `ledgerPepper`) until the ban ends. Ask for a fresh code
|
|
9
|
+
* first (step-up).
|
|
9
10
|
*
|
|
10
11
|
* @example
|
|
11
|
-
* await deleteAccount(database, storage, { accountId }); // { deleted: true }
|
|
12
|
+
* await deleteAccount(database, storage, { accountId, ledgerPepper }); // { deleted: true }
|
|
12
13
|
*/
|
|
13
|
-
export declare function deleteAccount(database: Kysely<AccountDatabase>, storage: PictureStorage, { accountId }: {
|
|
14
|
+
export declare function deleteAccount(database: Kysely<AccountDatabase>, storage: PictureStorage, { accountId, ledgerPepper, now }: {
|
|
14
15
|
accountId: string;
|
|
16
|
+
ledgerPepper: string;
|
|
17
|
+
now?: number;
|
|
15
18
|
}): Promise<{
|
|
16
19
|
deleted: boolean;
|
|
17
20
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/account-deletion/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/account-deletion/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAK3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oDAAoD,CAAC;AAEzF;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,OAAO,EAAE,cAAc,EACvB,EAAE,SAAS,EAAE,YAAY,EAAE,GAAgB,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GACvG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAoD/B"}
|