@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
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Kysely } from "kysely";
|
|
2
|
+
import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
|
|
3
|
+
import type { GrantView, RoleGrantRequest, RoleGrantResult } from "@sharadox/account-web-library/role-grant/type";
|
|
4
|
+
/** The permission that lets an account give roles, in the account system's own application. */
|
|
5
|
+
export declare const ROLE_ASSIGN_PERMISSION = "account.role.assign";
|
|
6
|
+
/**
|
|
7
|
+
* Gives an account a role in an application, maybe for one resource and a time. Given by someone (`grantedBy`), it
|
|
8
|
+
* needs their `account.role.assign` and every permission the role has, there: nobody hands out more than they hold.
|
|
9
|
+
* Recorded in the audit log.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* await grantRole(database, { accountId, application: "platform", role: "manager", grantedBy: admin });
|
|
13
|
+
*/
|
|
14
|
+
export declare function grantRole(database: Kysely<AccountDatabase>, { accountId, application, role, resource, startsAt, endsAt, source, grantedBy, reason, now, }: RoleGrantRequest): Promise<RoleGrantResult>;
|
|
15
|
+
/**
|
|
16
|
+
* Ends a grant now (a grant not started yet goes), keeping its history. Recorded in the audit log.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* await revokeGrant(database, { grantId, revokedBy: admin }); // { revoked: true }
|
|
20
|
+
*/
|
|
21
|
+
export declare function revokeGrant(database: Kysely<AccountDatabase>, { grantId, revokedBy, now }: {
|
|
22
|
+
grantId: string;
|
|
23
|
+
revokedBy?: string;
|
|
24
|
+
now?: number;
|
|
25
|
+
}): Promise<{
|
|
26
|
+
revoked: boolean;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* An account's grants, newest first, each with its role and whether it is active now.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const grants = await listGrants(database, { accountId });
|
|
33
|
+
*/
|
|
34
|
+
export declare function listGrants(database: Kysely<AccountDatabase>, { accountId, now }: {
|
|
35
|
+
accountId: string;
|
|
36
|
+
now?: number;
|
|
37
|
+
}): Promise<GrantView[]>;
|
|
38
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/role-grant/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAI3F,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,+CAA+C,CAAC;AAElH,+FAA+F;AAC/F,eAAO,MAAM,sBAAsB,wBAAwB,CAAC;AAE5D;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EACE,SAAS,EACT,WAAW,EACX,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,MAAiB,EACjB,SAAS,EACT,MAAM,EACN,GAAgB,GACjB,EAAE,gBAAgB,GAClB,OAAO,CAAC,eAAe,CAAC,CAuD1B;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,OAAO,EAAE,SAAS,EAAE,GAAgB,EAAE,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAC9F,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CA8B/B;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,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,SAAS,EAAE,CAAC,CAuBtB"}
|
|
@@ -0,0 +1,142 @@
|
|
|
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 { databaseError } from "@sharadox/account-web-library/database-error";
|
|
5
|
+
/** The permission that lets an account give roles, in the account system's own application. */
|
|
6
|
+
export const ROLE_ASSIGN_PERMISSION = "account.role.assign";
|
|
7
|
+
/**
|
|
8
|
+
* Gives an account a role in an application, maybe for one resource and a time. Given by someone (`grantedBy`), it
|
|
9
|
+
* needs their `account.role.assign` and every permission the role has, there: nobody hands out more than they hold.
|
|
10
|
+
* Recorded in the audit log.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* await grantRole(database, { accountId, application: "platform", role: "manager", grantedBy: admin });
|
|
14
|
+
*/
|
|
15
|
+
export async function grantRole(database, { accountId, application, role, resource, startsAt, endsAt, source = "manual", grantedBy, reason, now = Date.now(), }) {
|
|
16
|
+
const found = await database
|
|
17
|
+
.selectFrom("role")
|
|
18
|
+
.innerJoin("application", "application.id", "role.application_id")
|
|
19
|
+
.leftJoin("role_permission", "role_permission.role_id", "role.id")
|
|
20
|
+
.leftJoin("permission", "permission.id", "role_permission.permission_id")
|
|
21
|
+
.select(["role.id", "permission.key as permission"])
|
|
22
|
+
.where("application.key", "=", application)
|
|
23
|
+
.where("role.key", "=", role)
|
|
24
|
+
.execute();
|
|
25
|
+
if (found.length === 0)
|
|
26
|
+
return { granted: false, reason: "no-role" };
|
|
27
|
+
if (grantedBy) {
|
|
28
|
+
const assigning = await accountPermissions(database, { accountId: grantedBy, application: "account", now });
|
|
29
|
+
if (!assigning.has(ROLE_ASSIGN_PERMISSION))
|
|
30
|
+
return { granted: false, reason: "not-allowed" };
|
|
31
|
+
const held = await accountPermissions(database, {
|
|
32
|
+
accountId: grantedBy,
|
|
33
|
+
application,
|
|
34
|
+
now,
|
|
35
|
+
...(resource ? { resource } : {}),
|
|
36
|
+
});
|
|
37
|
+
if (found.some(({ permission }) => permission && !held.has(permission)))
|
|
38
|
+
return { granted: false, reason: "escalation" };
|
|
39
|
+
}
|
|
40
|
+
const grantId = uuidVersion7({ now });
|
|
41
|
+
try {
|
|
42
|
+
await database.transaction().execute(async (transaction) => {
|
|
43
|
+
await transaction
|
|
44
|
+
.insertInto("role_grant")
|
|
45
|
+
.values({
|
|
46
|
+
id: grantId,
|
|
47
|
+
account_id: accountId,
|
|
48
|
+
role_id: found[0].id,
|
|
49
|
+
resource: resource ?? null,
|
|
50
|
+
starts_at: new Date(startsAt ?? now),
|
|
51
|
+
ends_at: endsAt === undefined ? null : new Date(endsAt),
|
|
52
|
+
source,
|
|
53
|
+
granted_by: grantedBy ?? null,
|
|
54
|
+
reason: reason ?? null,
|
|
55
|
+
})
|
|
56
|
+
.execute();
|
|
57
|
+
await recordAuditEvent(transaction, {
|
|
58
|
+
accountId,
|
|
59
|
+
actorAccountId: grantedBy ?? null,
|
|
60
|
+
application,
|
|
61
|
+
action: "role.granted",
|
|
62
|
+
detail: { grantId, role, source },
|
|
63
|
+
now,
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
if (databaseError(error)?.constraint === "role_grant_account_id_fkey")
|
|
69
|
+
return { granted: false, reason: "no-account" };
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
return { granted: true, grantId };
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Ends a grant now (a grant not started yet goes), keeping its history. Recorded in the audit log.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* await revokeGrant(database, { grantId, revokedBy: admin }); // { revoked: true }
|
|
79
|
+
*/
|
|
80
|
+
export async function revokeGrant(database, { grantId, revokedBy, now = Date.now() }) {
|
|
81
|
+
const at = new Date(now);
|
|
82
|
+
return database.transaction().execute(async (transaction) => {
|
|
83
|
+
const ended = await transaction
|
|
84
|
+
.updateTable("role_grant")
|
|
85
|
+
.set({ ends_at: at })
|
|
86
|
+
.where("id", "=", grantId)
|
|
87
|
+
.where("starts_at", "<", at)
|
|
88
|
+
.where((where) => where.or([where("ends_at", "is", null), where("ends_at", ">", at)]))
|
|
89
|
+
.returning("account_id")
|
|
90
|
+
.executeTakeFirst();
|
|
91
|
+
const gone = ended
|
|
92
|
+
? undefined
|
|
93
|
+
: await transaction
|
|
94
|
+
.deleteFrom("role_grant")
|
|
95
|
+
.where("id", "=", grantId)
|
|
96
|
+
.where("starts_at", ">=", at)
|
|
97
|
+
.returning("account_id")
|
|
98
|
+
.executeTakeFirst();
|
|
99
|
+
const accountId = ended?.account_id ?? gone?.account_id;
|
|
100
|
+
if (!accountId)
|
|
101
|
+
return { revoked: false };
|
|
102
|
+
await recordAuditEvent(transaction, {
|
|
103
|
+
accountId,
|
|
104
|
+
actorAccountId: revokedBy ?? null,
|
|
105
|
+
action: "role.revoked",
|
|
106
|
+
detail: { grantId },
|
|
107
|
+
now,
|
|
108
|
+
});
|
|
109
|
+
return { revoked: true };
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* An account's grants, newest first, each with its role and whether it is active now.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* const grants = await listGrants(database, { accountId });
|
|
117
|
+
*/
|
|
118
|
+
export async function listGrants(database, { accountId, now = Date.now() }) {
|
|
119
|
+
const rows = await database
|
|
120
|
+
.selectFrom("role_grant")
|
|
121
|
+
.innerJoin("role", "role.id", "role_grant.role_id")
|
|
122
|
+
.leftJoin("application", "application.id", "role.application_id")
|
|
123
|
+
.select([
|
|
124
|
+
"role_grant.id as grantId",
|
|
125
|
+
"application.key as application",
|
|
126
|
+
"role.key as role",
|
|
127
|
+
"role.name as roleName",
|
|
128
|
+
"role_grant.resource",
|
|
129
|
+
"role_grant.starts_at as startsAt",
|
|
130
|
+
"role_grant.ends_at as endsAt",
|
|
131
|
+
"role_grant.source",
|
|
132
|
+
"role_grant.reason",
|
|
133
|
+
])
|
|
134
|
+
.where("role_grant.account_id", "=", accountId)
|
|
135
|
+
.orderBy("role_grant.id", "desc")
|
|
136
|
+
.execute();
|
|
137
|
+
return rows.map((row) => ({
|
|
138
|
+
...row,
|
|
139
|
+
active: row.startsAt.getTime() <= now && (row.endsAt === null || now < row.endsAt.getTime()),
|
|
140
|
+
}));
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/role-grant/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAE/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,kDAAkD,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAC;AAG7E,+FAA+F;AAC/F,MAAM,CAAC,MAAM,sBAAsB,GAAG,qBAAqB,CAAC;AAE5D;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,QAAiC,EACjC,EACE,SAAS,EACT,WAAW,EACX,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,MAAM,GAAG,QAAQ,EACjB,SA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
|
|
|
1
|
+
export interface RoleGrantRequest {
|
|
2
|
+
accountId: string;
|
|
3
|
+
/** The role's application key (`platform`). */
|
|
4
|
+
application: string;
|
|
5
|
+
/** The role's key (`manager`). */
|
|
6
|
+
role: string;
|
|
7
|
+
/** `platform:project:42`; the whole application without it. */
|
|
8
|
+
resource?: string;
|
|
9
|
+
/** Milliseconds since 1970 (now by default). */
|
|
10
|
+
startsAt?: number;
|
|
11
|
+
/** Milliseconds since 1970; for good without it. */
|
|
12
|
+
endsAt?: number;
|
|
13
|
+
source?: "manual" | "membership" | "ban" | "system";
|
|
14
|
+
/** Who gives it: they need `account.role.assign` and every permission of the role. The system without it. */
|
|
15
|
+
grantedBy?: string;
|
|
16
|
+
reason?: string;
|
|
17
|
+
now?: number;
|
|
18
|
+
}
|
|
19
|
+
export type RoleGrantResult = {
|
|
20
|
+
granted: true;
|
|
21
|
+
grantId: string;
|
|
22
|
+
} | {
|
|
23
|
+
granted: false;
|
|
24
|
+
reason: "no-role" | "no-account" | "not-allowed" | "escalation";
|
|
25
|
+
};
|
|
26
|
+
/** A grant as an account's page or an administrator sees it. */
|
|
27
|
+
export interface GrantView {
|
|
28
|
+
grantId: string;
|
|
29
|
+
application: string | null;
|
|
30
|
+
role: string;
|
|
31
|
+
roleName: string;
|
|
32
|
+
resource: string | null;
|
|
33
|
+
startsAt: Date;
|
|
34
|
+
endsAt: Date | null;
|
|
35
|
+
source: string;
|
|
36
|
+
reason: string | null;
|
|
37
|
+
/** Started and not ended. */
|
|
38
|
+
active: boolean;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/role-grant/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,WAAW,EAAE,MAAM,CAAC;IACpB,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gDAAgD;IAChD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,QAAQ,GAAG,YAAY,GAAG,KAAK,GAAG,QAAQ,CAAC;IACpD,6GAA6G;IAC7G,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,eAAe,GACvB;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,SAAS,GAAG,YAAY,GAAG,aAAa,GAAG,YAAY,CAAA;CAAE,CAAC;AAExF,gEAAgE;AAChE,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,IAAI,CAAC;IACf,MAAM,EAAE,IAAI,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,6BAA6B;IAC7B,MAAM,EAAE,OAAO,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/role-grant/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Kysely } from "kysely";
|
|
2
|
+
import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
|
|
3
|
+
import type { PublishedRule, RuleDeclaration } from "@sharadox/account-web-library/rule-sync/type";
|
|
4
|
+
/**
|
|
5
|
+
* Publishes an application's rules (or global ones, `application: null`). A rule whose words or penalties changed gets
|
|
6
|
+
* a new version, and earlier bans keep citing the version they broke. Returns the codes given a new version.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* await syncRules(database, { application: "platform", rules: [{ code: "spam", title, description, schedule }] });
|
|
10
|
+
*/
|
|
11
|
+
export declare function syncRules(database: Kysely<AccountDatabase>, { application, rules }: {
|
|
12
|
+
application: string | null;
|
|
13
|
+
rules: RuleDeclaration[];
|
|
14
|
+
}): Promise<{
|
|
15
|
+
versioned: string[];
|
|
16
|
+
unknownApplication?: true;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* The rules in force for an application, newest versions, global ones first then its own, by code: what the public
|
|
20
|
+
* rules page and `GET /api/rules` show.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const rules = await listRules(database, { application: "platform" });
|
|
24
|
+
*/
|
|
25
|
+
export declare function listRules(database: Kysely<AccountDatabase>, { application }: {
|
|
26
|
+
application: string;
|
|
27
|
+
}): Promise<PublishedRule[]>;
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/rule-sync/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAC3F,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,8CAA8C,CAAC;AAUnG;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE;IAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,eAAe,EAAE,CAAA;CAAE,GAC/E,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,EAAE,CAAC;IAAC,kBAAkB,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC,CA8B7D;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,WAAW,EAAE,EAAE;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,GACvC,OAAO,CAAC,aAAa,EAAE,CAAC,CA2B1B"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { uuidVersion7 } from "@sharadox/web-library/identifier/uuid-version-7";
|
|
2
|
+
const same = (first, second) => JSON.stringify(first) === JSON.stringify(second);
|
|
3
|
+
/** The application's id; null for global rules; undefined when it doesn't exist. */
|
|
4
|
+
async function applicationId(database, key) {
|
|
5
|
+
if (key === null)
|
|
6
|
+
return null;
|
|
7
|
+
return (await database.selectFrom("application").select("id").where("key", "=", key).executeTakeFirst())?.id;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Publishes an application's rules (or global ones, `application: null`). A rule whose words or penalties changed gets
|
|
11
|
+
* a new version, and earlier bans keep citing the version they broke. Returns the codes given a new version.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* await syncRules(database, { application: "platform", rules: [{ code: "spam", title, description, schedule }] });
|
|
15
|
+
*/
|
|
16
|
+
export async function syncRules(database, { application, rules }) {
|
|
17
|
+
const id = await applicationId(database, application);
|
|
18
|
+
if (id === undefined)
|
|
19
|
+
return { versioned: [], unknownApplication: true };
|
|
20
|
+
const versioned = [];
|
|
21
|
+
for (const rule of rules) {
|
|
22
|
+
let latest = database.selectFrom("rule").selectAll().where("code", "=", rule.code);
|
|
23
|
+
latest = id === null ? latest.where("application_id", "is", null) : latest.where("application_id", "=", id);
|
|
24
|
+
const current = await latest.orderBy("version", "desc").executeTakeFirst();
|
|
25
|
+
if (current &&
|
|
26
|
+
same(current.title, rule.title) &&
|
|
27
|
+
same(current.description, rule.description) &&
|
|
28
|
+
same(current.schedule, rule.schedule))
|
|
29
|
+
continue;
|
|
30
|
+
await database
|
|
31
|
+
.insertInto("rule")
|
|
32
|
+
.values({
|
|
33
|
+
id: uuidVersion7(),
|
|
34
|
+
application_id: id,
|
|
35
|
+
code: rule.code,
|
|
36
|
+
version: (current?.version ?? 0) + 1,
|
|
37
|
+
title: JSON.stringify(rule.title),
|
|
38
|
+
description: JSON.stringify(rule.description),
|
|
39
|
+
schedule: JSON.stringify(rule.schedule),
|
|
40
|
+
})
|
|
41
|
+
.execute();
|
|
42
|
+
versioned.push(rule.code);
|
|
43
|
+
}
|
|
44
|
+
return { versioned };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The rules in force for an application, newest versions, global ones first then its own, by code: what the public
|
|
48
|
+
* rules page and `GET /api/rules` show.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* const rules = await listRules(database, { application: "platform" });
|
|
52
|
+
*/
|
|
53
|
+
export async function listRules(database, { application }) {
|
|
54
|
+
const id = await applicationId(database, application);
|
|
55
|
+
const rows = await database
|
|
56
|
+
.selectFrom("rule")
|
|
57
|
+
.selectAll()
|
|
58
|
+
.where((where) => id
|
|
59
|
+
? where.or([where("application_id", "is", null), where("application_id", "=", id)])
|
|
60
|
+
: where("application_id", "is", null))
|
|
61
|
+
.orderBy("version", "desc")
|
|
62
|
+
.execute();
|
|
63
|
+
const newest = new Map();
|
|
64
|
+
for (const row of rows) {
|
|
65
|
+
const key = `${row.application_id === null ? "0" : "1"}:${row.code}`;
|
|
66
|
+
if (!newest.has(key))
|
|
67
|
+
newest.set(key, row);
|
|
68
|
+
}
|
|
69
|
+
return [...newest.entries()]
|
|
70
|
+
.sort(([first], [second]) => first.localeCompare(second))
|
|
71
|
+
.map(([, row]) => ({
|
|
72
|
+
code: row.code,
|
|
73
|
+
version: row.version,
|
|
74
|
+
title: row.title,
|
|
75
|
+
description: row.description,
|
|
76
|
+
schedule: row.schedule,
|
|
77
|
+
global: row.application_id === null,
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/rule-sync/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAI/E,MAAM,IAAI,GAAG,CAAC,KAAc,EAAE,MAAe,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAEnG,oFAAoF;AACpF,KAAK,UAAU,aAAa,CAAC,QAAiC,EAAE,GAAkB;IAChF,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAC9B,OAAO,CAAC,MAAM,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,gBAAgB,EAAE,CAAC,EAAE,EAAE,CAAC;AAC/G,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,QAAiC,EACjC,EAAE,WAAW,EAAE,KAAK,EAA4D;IAEhF,MAAM,EAAE,GAAG,MAAM,aAAa,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;IACtD,IAAI,EAAE,KAAK,SAAS;QAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAC;IACzE,MAAM,SAAS,GAAa,EAAE,CAAC;IAC/B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,MAAM,GAAG,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,MAAM,E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AAO;QACpB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,MAAM,EAAE,GAAG,CAAC,cAAc,KAAK,IAAI;KACpC,CAAC,CAAC,CAAC;AACR,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PenaltySchedule } from "@sharadox/account-web-library/ban-length/type";
|
|
2
|
+
/** A public rule as an application declares it. */
|
|
3
|
+
export interface RuleDeclaration {
|
|
4
|
+
code: string;
|
|
5
|
+
/** In each language: `{ en, pt }`. */
|
|
6
|
+
title: Record<string, string>;
|
|
7
|
+
description: Record<string, string>;
|
|
8
|
+
/** Penalties for the 1st, 2nd… offense: seconds, or "permanent"; the last repeats. */
|
|
9
|
+
schedule: PenaltySchedule;
|
|
10
|
+
}
|
|
11
|
+
/** A rule's newest version, as `/rules` shows it. */
|
|
12
|
+
export interface PublishedRule extends RuleDeclaration {
|
|
13
|
+
version: number;
|
|
14
|
+
/** For every application. */
|
|
15
|
+
global: boolean;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/rule-sync/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+CAA+C,CAAC;AAErF,mDAAmD;AACnD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,sFAAsF;IACtF,QAAQ,EAAE,eAAe,CAAC;CAC3B;AAED,qDAAqD;AACrD,MAAM,WAAW,aAAc,SAAQ,eAAe;IACpD,OAAO,EAAE,MAAM,CAAC;IAChB,6BAA6B;IAC7B,MAAM,EAAE,OAAO,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/rule-sync/type.ts"],"names":[],"mappings":""}
|
|
@@ -3,7 +3,8 @@ import type { SecondFactorFinish, SecondFactorFinishResult } from "@sharadox/acc
|
|
|
3
3
|
/**
|
|
4
4
|
* The two-factor step of signing in: the authenticator app's code (never the same step twice) or a single-use
|
|
5
5
|
* recovery code, after the emailed code passed (`finishSignIn` gave the ticket). Guesses are limited per account and
|
|
6
|
-
* per address group. The session is marked as having passed two-factor.
|
|
6
|
+
* per address group. The session is marked as having passed two-factor. After a recovery code, call `notify` after
|
|
7
|
+
* answering, to tell every contact.
|
|
7
8
|
*
|
|
8
9
|
* @example
|
|
9
10
|
* const result = await finishSecondFactor(server, { ticket, code, address, token: cookie });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/second-factor-finish/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/second-factor-finish/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAC;AAOvF,OAAO,KAAK,EACV,kBAAkB,EAClB,wBAAwB,EACzB,MAAM,yDAAyD,CAAC;AAIjE;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,aAAa,EACrB,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,SAAgB,EAAE,GAAgB,EAAE,EAAE,kBAAkB,GACvF,OAAO,CAAC,wBAAwB,CAAC,CA+DnC"}
|
|
@@ -2,6 +2,7 @@ import { addressGroup } from "@sharadox/protection-web-library/address-group";
|
|
|
2
2
|
import { limitRate } from "@sharadox/protection-web-library/rate-limit";
|
|
3
3
|
import { accountTables, signInLimits } from "@sharadox/account-web-library/account-server";
|
|
4
4
|
import { signIn } from "@sharadox/account-web-library/account-sign-in";
|
|
5
|
+
import { notifyAccount } from "@sharadox/account-web-library/account-notice";
|
|
5
6
|
import { recordAuditEvent } from "@sharadox/account-web-library/audit-event";
|
|
6
7
|
import { recoveryCodeHash } from "@sharadox/account-web-library/recovery-code-store";
|
|
7
8
|
import { decryptSecret } from "@sharadox/account-web-library/secret-encryption";
|
|
@@ -11,7 +12,8 @@ import { verifyTotp } from "@sharadox/account-web-library/totp";
|
|
|
11
12
|
/**
|
|
12
13
|
* The two-factor step of signing in: the authenticator app's code (never the same step twice) or a single-use
|
|
13
14
|
* recovery code, after the emailed code passed (`finishSignIn` gave the ticket). Guesses are limited per account and
|
|
14
|
-
* per address group. The session is marked as having passed two-factor.
|
|
15
|
+
* per address group. The session is marked as having passed two-factor. After a recovery code, call `notify` after
|
|
16
|
+
* answering, to tell every contact.
|
|
15
17
|
*
|
|
16
18
|
* @example
|
|
17
19
|
* const result = await finishSecondFactor(server, { ticket, code, address, token: cookie });
|
|
@@ -44,7 +46,7 @@ export async function finishSecondFactor(server, { ticket, code, address, token,
|
|
|
44
46
|
.executeTakeFirst();
|
|
45
47
|
// Two-factor was turned off since the emailed code passed: that code is the proof.
|
|
46
48
|
if (!credential)
|
|
47
|
-
return
|
|
49
|
+
return "passed";
|
|
48
50
|
const typed = code.replace(/\s/g, "");
|
|
49
51
|
const secret = decryptSecret(credential.secret_ciphertext, deriveSecret(server.secret, "totp-encryption"));
|
|
50
52
|
// Confirming the setup stored a step, so a confirmed credential always has one.
|
|
@@ -56,7 +58,7 @@ export async function finishSecondFactor(server, { ticket, code, address, token,
|
|
|
56
58
|
.set({ last_used_step: verification.step })
|
|
57
59
|
.where("id", "=", credential.id)
|
|
58
60
|
.execute();
|
|
59
|
-
return
|
|
61
|
+
return "passed";
|
|
60
62
|
}
|
|
61
63
|
const used = await transaction
|
|
62
64
|
.updateTable("recovery_code")
|
|
@@ -66,13 +68,16 @@ export async function finishSecondFactor(server, { ticket, code, address, token,
|
|
|
66
68
|
.where("used_at", "is", null)
|
|
67
69
|
.executeTakeFirst();
|
|
68
70
|
if (used.numUpdatedRows === 0n)
|
|
69
|
-
return
|
|
71
|
+
return "wrong";
|
|
70
72
|
await recordAuditEvent(transaction, { accountId, action: "second-factor.recovery-code-used", now });
|
|
71
|
-
return
|
|
73
|
+
return "recovery";
|
|
72
74
|
});
|
|
73
|
-
if (
|
|
75
|
+
if (passed === "wrong")
|
|
74
76
|
return { status: "refused", reason: "wrong" };
|
|
75
77
|
const session = await signIn(server.database, { accountId, token, secondFactor: true, userAgent, now });
|
|
76
|
-
|
|
78
|
+
if (passed === "passed")
|
|
79
|
+
return { status: "signed-in", accountId, token: session.token };
|
|
80
|
+
const notify = () => notifyAccount(server, { accountId, notice: { kind: "recovery-code-used" } });
|
|
81
|
+
return { status: "signed-in", accountId, token: session.token, notify };
|
|
77
82
|
}
|
|
78
83
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/second-factor-finish/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,6CAA6C,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,8CAA8C,CAAC;AAE3F,OAAO,EAAE,MAAM,EAAE,MAAM,+CAA+C,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,mDAAmD,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,MAAM,iDAAiD,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAK/E,OAAO,EAAE,UAAU,EAAE,MAAM,6CAA6C,CAAC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O,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;IACtE,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC;IACxG,IAAI,MAAM,KAAK,QAAQ;QAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;IACzF,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,EAAE,CAAC,CAAC;IAClG,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;AAC1E,CAAC"}
|
|
@@ -12,10 +12,13 @@ export interface SecondFactorFinish {
|
|
|
12
12
|
/** Milliseconds since 1970 (now by default). */
|
|
13
13
|
now?: number;
|
|
14
14
|
}
|
|
15
|
-
export type SecondFactorFinishResult =
|
|
15
|
+
export type SecondFactorFinishResult =
|
|
16
|
+
/** `notify`, after a recovery code: tells every contact (call it after answering). */
|
|
17
|
+
{
|
|
16
18
|
status: "signed-in";
|
|
17
19
|
accountId: string;
|
|
18
20
|
token: string;
|
|
21
|
+
notify?: () => Promise<void>;
|
|
19
22
|
} | {
|
|
20
23
|
status: "refused";
|
|
21
24
|
reason: "ticket" | "wrong";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/second-factor-finish/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,wBAAwB,
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/second-factor-finish/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,wBAAwB;AAClC,sFAAsF;AACpF;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,GACvF;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAA;CAAE,GACjD;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,YAAY,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
|
@@ -3,10 +3,11 @@ import type { SignUpFinish, SignUpFinishResult } from "@sharadox/account-web-lib
|
|
|
3
3
|
/**
|
|
4
4
|
* The last step for a new person: the name and identifier they chose, with the ticket proving their contact. Creates the
|
|
5
5
|
* account with that contact verified and signs it in. A refused name or identifier can be tried again with the same
|
|
6
|
-
* ticket while it lasts; a ticket can't make two accounts (the contact is then taken).
|
|
6
|
+
* ticket while it lasts; a ticket can't make two accounts (the contact is then taken). A contact of a deleted account
|
|
7
|
+
* banned from the account system (or everywhere) can't sign up again while that ban lasts.
|
|
7
8
|
*
|
|
8
9
|
* @example
|
|
9
10
|
* const result = await finishSignUp(server, { ticket, name, identifier, token: cookie });
|
|
10
11
|
*/
|
|
11
|
-
export declare function finishSignUp(server: AccountServer, { ticket, name, identifier, token, userAgent, now }: SignUpFinish): Promise<SignUpFinishResult>;
|
|
12
|
+
export declare function finishSignUp(server: AccountServer, { ticket, name, identifier, token, userAgent, language, now }: SignUpFinish): Promise<SignUpFinishResult>;
|
|
12
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/sign-up-finish/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/sign-up-finish/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAC;AAKvF,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,mDAAmD,CAAC;AAE1G;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,aAAa,EACrB,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,SAAgB,EAAE,QAAQ,EAAE,GAAgB,EAAE,EAAE,YAAY,GAC9F,OAAO,CAAC,kBAAkB,CAAC,CAoB7B"}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { signIn } from "@sharadox/account-web-library/account-sign-in";
|
|
2
|
+
import { contactBanned } from "@sharadox/account-web-library/banned-contact";
|
|
2
3
|
import { createPersonAccount } from "@sharadox/account-web-library/person-account";
|
|
3
4
|
import { deriveSecret } from "@sharadox/account-web-library/secret-derivation";
|
|
4
5
|
import { readTicket } from "@sharadox/account-web-library/signed-ticket";
|
|
5
6
|
/**
|
|
6
7
|
* The last step for a new person: the name and identifier they chose, with the ticket proving their contact. Creates the
|
|
7
8
|
* account with that contact verified and signs it in. A refused name or identifier can be tried again with the same
|
|
8
|
-
* ticket while it lasts; a ticket can't make two accounts (the contact is then taken).
|
|
9
|
+
* ticket while it lasts; a ticket can't make two accounts (the contact is then taken). A contact of a deleted account
|
|
10
|
+
* banned from the account system (or everywhere) can't sign up again while that ban lasts.
|
|
9
11
|
*
|
|
10
12
|
* @example
|
|
11
13
|
* const result = await finishSignUp(server, { ticket, name, identifier, token: cookie });
|
|
12
14
|
*/
|
|
13
|
-
export async function finishSignUp(server, { ticket, name, identifier, token, userAgent = null, now = Date.now() }) {
|
|
15
|
+
export async function finishSignUp(server, { ticket, name, identifier, token, userAgent = null, language, now = Date.now() }) {
|
|
14
16
|
const reading = readTicket(ticket, {
|
|
15
17
|
secret: deriveSecret(server.secret, "sign-up-ticket"),
|
|
16
18
|
purpose: "sign-up",
|
|
@@ -18,10 +20,14 @@ export async function finishSignUp(server, { ticket, name, identifier, token, us
|
|
|
18
20
|
});
|
|
19
21
|
if (!reading.valid)
|
|
20
22
|
return { status: "refused", reason: "ticket" };
|
|
23
|
+
const pepper = deriveSecret(server.secret, "banned-contact");
|
|
24
|
+
if (await contactBanned(server.database, { contact: reading.data.contact, pepper, application: "account", now }))
|
|
25
|
+
return { status: "refused", reason: "contact-banned" };
|
|
21
26
|
const created = await createPersonAccount(server.database, {
|
|
22
27
|
name,
|
|
23
28
|
identifier,
|
|
24
29
|
contact: reading.data.contact,
|
|
30
|
+
...(language ? { language } : {}),
|
|
25
31
|
now,
|
|
26
32
|
});
|
|
27
33
|
if (!created.created)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/sign-up-finish/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA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AAQ,EAAE;QACzD,IAAI;QACJ,UAAU;QACV,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO;QAC7B,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjC,GAAG;KACJ,CAAC,CAAC;IACH,IAAI,CAAC,OAAO,CAAC,OAAO;QAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;IAC3E,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC;IACvG,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;AACrF,CAAC"}
|
|
@@ -8,6 +8,8 @@ export interface SignUpFinish {
|
|
|
8
8
|
identifier: string;
|
|
9
9
|
/** The browser's current session cookie, if any. */
|
|
10
10
|
token: string | undefined;
|
|
11
|
+
/** The person's language (`pt-PT`), for the notices the account will get. */
|
|
12
|
+
language?: string;
|
|
11
13
|
/** The browser's User-Agent, for the list of devices. */
|
|
12
14
|
userAgent?: string | null;
|
|
13
15
|
/** Milliseconds since 1970 (now by default). */
|
|
@@ -19,7 +21,7 @@ export type SignUpFinishResult = {
|
|
|
19
21
|
token: string;
|
|
20
22
|
} | {
|
|
21
23
|
status: "refused";
|
|
22
|
-
reason: "ticket" | Extract<PersonAccountResult, {
|
|
24
|
+
reason: "ticket" | "contact-banned" | Extract<PersonAccountResult, {
|
|
23
25
|
created: false;
|
|
24
26
|
}>["reason"];
|
|
25
27
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/sign-up-finish/type.ts"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,CAAC;IAClB,MAAM,EAAE,QAAQ,GAAG,gBAAgB,GAAG,OAAO,CAAC,mBAAmB,EAAE;QAAE,OAAO,EAAE,KAAK,CAAA;KAAE,CAAC,CAAC,QAAQ,CAAC,CAAC;CAClG,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sharadox/account-web-library",
|
|
3
|
-
"version": "0.1.0-development.
|
|
3
|
+
"version": "0.1.0-development.30",
|
|
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",
|