@sharadox/account-web-library 0.1.0-development.33 → 0.1.0-development.36

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
@@ -326,6 +326,11 @@ revokedBy? })` ends it now (history kept); `listGrants(database, { accountId })`
326
326
  permissions now: the default role plus active grants (an active exclusive one wins), limited to `scope`, and for an
327
327
  agent to what its owner may do right now. Built on `effectivePermissions`.
328
328
 
329
+ The account system's own application is `ACCOUNT_APPLICATION` (`account-application`): permissions to see the
330
+ administration, read and give roles, ban and decide appeals; roles `administrator`, `moderator` and the ban.
331
+ `setUpAccountSystem(database, { administrators })` (`account-setup`) syncs it and makes the identifiers listed
332
+ (`ACCOUNT_ADMINISTRATORS`) administrators when they aren't: run it at start and after sign-ins.
333
+
329
334
  In the database (migration `0005-role`): `permission`, `role`, `role_permission`, `role_grant`. A role still
330
335
  granted can't be deleted (`RESTRICT`); a grant outlives the account that gave it (`granted_by` becomes null).
331
336
 
@@ -0,0 +1,8 @@
1
+ import type { ApplicationDeclaration } from "@sharadox/account-web-library/application-sync/type";
2
+ /**
3
+ * The account system's own application: what its administration needs, synced at every start. The roles: the
4
+ * administrator (everything), the moderator (bans and appeals), and the ban on the account site itself, which leaves
5
+ * only what the law and the account's owner need (seeing the ban, appealing, the data download, deletion).
6
+ */
7
+ export declare const ACCOUNT_APPLICATION: ApplicationDeclaration;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/account-application/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qDAAqD,CAAC;AAElG;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,sBA6BjC,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The account system's own application: what its administration needs, synced at every start. The roles: the
3
+ * administrator (everything), the moderator (bans and appeals), and the ban on the account site itself, which leaves
4
+ * only what the law and the account's owner need (seeing the ban, appealing, the data download, deletion).
5
+ */
6
+ export const ACCOUNT_APPLICATION = {
7
+ key: "account",
8
+ name: "Account",
9
+ permissions: [
10
+ { key: "account.administration.read", description: "See the administration" },
11
+ { key: "account.role.read", description: "See any account's roles and bans" },
12
+ { key: "account.role.assign", description: "Give and take back roles (only those whose permissions one holds)" },
13
+ { key: "account.ban.create", description: "Ban an account, citing the rules it broke" },
14
+ { key: "account.appeal.decide", description: "Decide appeals" },
15
+ ],
16
+ roles: [
17
+ {
18
+ key: "administrator",
19
+ name: "Administrator",
20
+ permissions: [
21
+ "account.administration.read",
22
+ "account.role.read",
23
+ "account.role.assign",
24
+ "account.ban.create",
25
+ "account.appeal.decide",
26
+ ],
27
+ },
28
+ {
29
+ key: "moderator",
30
+ name: "Moderator",
31
+ permissions: ["account.administration.read", "account.role.read", "account.ban.create", "account.appeal.decide"],
32
+ },
33
+ { key: "banned", name: "Banned", permissions: [], exclusive: true },
34
+ ],
35
+ };
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/account-application/index.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAA2B;IACzD,GAAG,EAAE,SAAS;IACd,IAAI,EAAE,SAAS;IACf,WAAW,EAAE;QACX,EAAE,GAAG,EAAE,6BAA6B,EAAE,WAAW,EAAE,wBAAwB,EAAE;QAC7E,EAAE,GAAG,EAAE,mBAAmB,EAAE,WAAW,EAAE,kCAAkC,EAAE;QAC7E,EAAE,GAAG,EAAE,qBAAqB,EAAE,WAAW,EAAE,mEAAmE,EAAE;QAChH,EAAE,GAAG,EAAE,oBAAoB,EAAE,WAAW,EAAE,2CAA2C,EAAE;QACvF,EAAE,GAAG,EAAE,uBAAuB,EAAE,WAAW,EAAE,gBAAgB,EAAE;KAChE;IACD,KAAK,EAAE;QACL;YACE,GAAG,EAAE,eAAe;YACpB,IAAI,EAAE,eAAe;YACrB,WAAW,EAAE;gBACX,6BAA6B;gBAC7B,mBAAmB;gBACnB,qBAAqB;gBACrB,oBAAoB;gBACpB,uBAAuB;aACxB;SACF;QACD;YACE,GAAG,EAAE,WAAW;YAChB,IAAI,EAAE,WAAW;YACjB,WAAW,EAAE,CAAC,6BAA6B,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,uBAAuB,CAAC;SACjH;QACD,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE;KACpE;CACF,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { type Kysely } from "kysely";
2
+ import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
3
+ /**
4
+ * Brings the account system's own application up to date (its permissions and roles) and makes the identifiers in
5
+ * `ACCOUNT_ADMINISTRATORS` administrators, when they aren't already: the first administrator has to come from
6
+ * somewhere. Runs at every start; safe to run again.
7
+ *
8
+ * @example
9
+ * await setUpAccountSystem(database, { administrators: ["luis-pires"] });
10
+ */
11
+ export declare function setUpAccountSystem(database: Kysely<AccountDatabase>, { administrators }: {
12
+ administrators: string[];
13
+ }): Promise<void>;
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/account-setup/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAK3F;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,cAAc,EAAE,EAAE;IAAE,cAAc,EAAE,MAAM,EAAE,CAAA;CAAE,GAC/C,OAAO,CAAC,IAAI,CAAC,CA4Bf"}
@@ -0,0 +1,42 @@
1
+ import { sql } from "kysely";
2
+ import { syncApplication } from "@sharadox/account-web-library/application-sync";
3
+ import { grantRole } from "@sharadox/account-web-library/role-grant";
4
+ import { ACCOUNT_APPLICATION } from "@sharadox/account-web-library/account-application";
5
+ /**
6
+ * Brings the account system's own application up to date (its permissions and roles) and makes the identifiers in
7
+ * `ACCOUNT_ADMINISTRATORS` administrators, when they aren't already: the first administrator has to come from
8
+ * somewhere. Runs at every start; safe to run again.
9
+ *
10
+ * @example
11
+ * await setUpAccountSystem(database, { administrators: ["luis-pires"] });
12
+ */
13
+ export async function setUpAccountSystem(database, { administrators }) {
14
+ await syncApplication(database, ACCOUNT_APPLICATION);
15
+ for (const identifier of administrators) {
16
+ const account = await database
17
+ .selectFrom("identifier")
18
+ .select("account_id")
19
+ .where(sql `lower(value)`, "=", identifier.toLowerCase())
20
+ .executeTakeFirst();
21
+ if (!account?.account_id)
22
+ continue;
23
+ const held = await database
24
+ .selectFrom("role_grant")
25
+ .innerJoin("role", "role.id", "role_grant.role_id")
26
+ .select("role_grant.id")
27
+ .where("role_grant.account_id", "=", account.account_id)
28
+ .where("role.key", "=", "administrator")
29
+ .where((where) => where.or([where("role_grant.ends_at", "is", null), where("role_grant.ends_at", ">", new Date())]))
30
+ .executeTakeFirst();
31
+ if (held)
32
+ continue;
33
+ await grantRole(database, {
34
+ accountId: account.account_id,
35
+ application: "account",
36
+ role: "administrator",
37
+ source: "system",
38
+ reason: "ACCOUNT_ADMINISTRATORS",
39
+ });
40
+ }
41
+ }
42
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/account-setup/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAe,MAAM,QAAQ,CAAC;AAE1C,OAAO,EAAE,eAAe,EAAE,MAAM,gDAAgD,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mDAAmD,CAAC;AA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GED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sharadox/account-web-library",
3
- "version": "0.1.0-development.33",
3
+ "version": "0.1.0-development.36",
4
4
  "description": "Passwordless accounts for web applications: one-time codes, two-factor, roles, bans and OpenID Connect for people and agents.",
5
5
  "private": false,
6
6
  "license": "SEE LICENSE IN LICENCA.md",