@sharadox/account-web-library 0.1.0-development.3 → 0.1.0-development.9
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 +75 -3
- package/distribution/account-database/type.d.ts +73 -0
- package/distribution/account-database/type.d.ts.map +1 -0
- package/distribution/account-database/type.js +2 -0
- package/distribution/account-database/type.js.map +1 -0
- package/distribution/account-migration/index.d.ts +18 -0
- package/distribution/account-migration/index.d.ts.map +1 -0
- package/distribution/account-migration/index.js +122 -0
- package/distribution/account-migration/index.js.map +1 -0
- package/distribution/audit-event/index.d.ts +12 -0
- package/distribution/audit-event/index.d.ts.map +1 -0
- package/distribution/audit-event/index.js +25 -0
- package/distribution/audit-event/index.js.map +1 -0
- package/distribution/audit-event/type.d.ts +15 -0
- package/distribution/audit-event/type.d.ts.map +1 -0
- package/distribution/audit-event/type.js +2 -0
- package/distribution/audit-event/type.js.map +1 -0
- package/distribution/code-request/index.d.ts +16 -0
- package/distribution/code-request/index.d.ts.map +1 -0
- package/distribution/code-request/index.js +52 -0
- package/distribution/code-request/index.js.map +1 -0
- package/distribution/code-request/type.d.ts +25 -0
- package/distribution/code-request/type.d.ts.map +1 -0
- package/distribution/code-request/type.js +2 -0
- package/distribution/code-request/type.js.map +1 -0
- package/distribution/code-request-prune/index.d.ts +13 -0
- package/distribution/code-request-prune/index.d.ts.map +1 -0
- package/distribution/code-request-prune/index.js +12 -0
- package/distribution/code-request-prune/index.js.map +1 -0
- package/distribution/code-verification/index.d.ts +14 -0
- package/distribution/code-verification/index.d.ts.map +1 -0
- package/distribution/code-verification/index.js +43 -0
- package/distribution/code-verification/index.js.map +1 -0
- package/distribution/code-verification/type.d.ts +22 -0
- package/distribution/code-verification/type.d.ts.map +1 -0
- package/distribution/code-verification/type.js +2 -0
- package/distribution/code-verification/type.js.map +1 -0
- package/distribution/contact-addition/index.d.ts +13 -0
- package/distribution/contact-addition/index.d.ts.map +1 -0
- package/distribution/contact-addition/index.js +48 -0
- package/distribution/contact-addition/index.js.map +1 -0
- package/distribution/contact-addition/type.d.ts +15 -0
- package/distribution/contact-addition/type.d.ts.map +1 -0
- package/distribution/contact-addition/type.js +2 -0
- package/distribution/contact-addition/type.js.map +1 -0
- package/distribution/contact-kind/index.d.ts +12 -0
- package/distribution/contact-kind/index.d.ts.map +1 -0
- package/distribution/contact-kind/index.js +18 -0
- package/distribution/contact-kind/index.js.map +1 -0
- package/distribution/contact-kind/type.d.ts +6 -0
- package/distribution/contact-kind/type.d.ts.map +1 -0
- package/distribution/contact-kind/type.js +2 -0
- package/distribution/contact-kind/type.js.map +1 -0
- package/distribution/contact-lookup/index.d.ts +16 -0
- package/distribution/contact-lookup/index.d.ts.map +1 -0
- package/distribution/contact-lookup/index.js +20 -0
- package/distribution/contact-lookup/index.js.map +1 -0
- package/distribution/contact-removal/index.d.ts +19 -0
- package/distribution/contact-removal/index.d.ts.map +1 -0
- package/distribution/contact-removal/index.js +35 -0
- package/distribution/contact-removal/index.js.map +1 -0
- package/distribution/contact-verification/index.d.ts +20 -0
- package/distribution/contact-verification/index.d.ts.map +1 -0
- package/distribution/contact-verification/index.js +37 -0
- package/distribution/contact-verification/index.js.map +1 -0
- package/distribution/database-error/index.d.ts +12 -0
- package/distribution/database-error/index.d.ts.map +1 -0
- package/distribution/database-error/index.js +14 -0
- package/distribution/database-error/index.js.map +1 -0
- package/distribution/person-account/index.d.ts +14 -0
- package/distribution/person-account/index.d.ts.map +1 -0
- package/distribution/person-account/index.js +45 -0
- package/distribution/person-account/index.js.map +1 -0
- package/distribution/person-account/type.d.ts +17 -0
- package/distribution/person-account/type.d.ts.map +1 -0
- package/distribution/person-account/type.js +2 -0
- package/distribution/person-account/type.js.map +1 -0
- package/distribution/test-database/index.d.ts +13 -0
- package/distribution/test-database/index.d.ts.map +1 -0
- package/distribution/test-database/index.js +17 -0
- package/distribution/test-database/index.js.map +1 -0
- package/distribution/username-availability/index.d.ts +11 -0
- package/distribution/username-availability/index.d.ts.map +1 -0
- package/distribution/username-availability/index.js +21 -0
- package/distribution/username-availability/index.js.map +1 -0
- package/distribution/username-change/index.d.ts +15 -0
- package/distribution/username-change/index.d.ts.map +1 -0
- package/distribution/username-change/index.js +39 -0
- package/distribution/username-change/index.js.map +1 -0
- package/distribution/username-change/type.d.ts +7 -0
- package/distribution/username-change/type.d.ts.map +1 -0
- package/distribution/username-change/type.js +2 -0
- package/distribution/username-change/type.js.map +1 -0
- package/package.json +5 -2
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Kysely } from "kysely";
|
|
2
|
+
import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
|
|
3
|
+
import type { UsernameChangeResult } from "@sharadox/account-web-library/username-change/type";
|
|
4
|
+
/**
|
|
5
|
+
* Changes an account's username whenever its owner wants; the old one is free for anyone at once. Accounts are
|
|
6
|
+
* referenced by id, so nothing breaks; the audit log keeps the history. Changing only the case is allowed.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* await changeUsername(database, { accountId, username: "Luis-Pires" }); // { changed: true }
|
|
10
|
+
*/
|
|
11
|
+
export declare function changeUsername(database: Kysely<AccountDatabase>, { accountId, username }: {
|
|
12
|
+
accountId: string;
|
|
13
|
+
username: string;
|
|
14
|
+
}): Promise<UsernameChangeResult>;
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/username-change/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAI3F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oDAAoD,CAAC;AAE/F;;;;;;GAMG;AACH,wBAAsB,cAAc,CAClC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAC/D,OAAO,CAAC,oBAAoB,CAAC,CAwB/B"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { recordAuditEvent } from "@sharadox/account-web-library/audit-event";
|
|
2
|
+
import { databaseError } from "@sharadox/account-web-library/database-error";
|
|
3
|
+
import { checkUsername } from "@sharadox/account-web-library/username";
|
|
4
|
+
/**
|
|
5
|
+
* Changes an account's username whenever its owner wants; the old one is free for anyone at once. Accounts are
|
|
6
|
+
* referenced by id, so nothing breaks; the audit log keeps the history. Changing only the case is allowed.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* await changeUsername(database, { accountId, username: "Luis-Pires" }); // { changed: true }
|
|
10
|
+
*/
|
|
11
|
+
export async function changeUsername(database, { accountId, username }) {
|
|
12
|
+
if (!checkUsername(username).valid)
|
|
13
|
+
return { changed: false, reason: "username-invalid" };
|
|
14
|
+
try {
|
|
15
|
+
return await database.transaction().execute(async (transaction) => {
|
|
16
|
+
const current = await transaction
|
|
17
|
+
.selectFrom("account")
|
|
18
|
+
.select("username")
|
|
19
|
+
.where("id", "=", accountId)
|
|
20
|
+
.forUpdate()
|
|
21
|
+
.executeTakeFirst();
|
|
22
|
+
if (!current)
|
|
23
|
+
return { changed: false, reason: "no-account" };
|
|
24
|
+
await transaction.updateTable("account").set({ username }).where("id", "=", accountId).execute();
|
|
25
|
+
await recordAuditEvent(transaction, {
|
|
26
|
+
accountId,
|
|
27
|
+
action: "account.username-changed",
|
|
28
|
+
detail: { from: current.username, to: username },
|
|
29
|
+
});
|
|
30
|
+
return { changed: true };
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (databaseError(error)?.constraint === "account_username_key")
|
|
35
|
+
return { changed: false, reason: "username-taken" };
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+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AAE,EAAE,EAAE,QAAQ,EAAE;aACjD,CAAC,CAAC;YACH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC3B,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,UAAU,KAAK,sBAAsB;YAC7D,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;QACtD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/username-change/type.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAC9B;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,kBAAkB,GAAG,gBAAgB,GAAG,YAAY,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/username-change/type.ts"],"names":[],"mappings":""}
|
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.9",
|
|
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",
|
|
@@ -40,9 +40,12 @@
|
|
|
40
40
|
"*.{json,md,yml,yaml}": "prettier --write"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@sharadox/web-library": "
|
|
43
|
+
"@sharadox/database-web-library": "0.1.0-development.6",
|
|
44
|
+
"@sharadox/web-library": "^0.11.1",
|
|
45
|
+
"kysely": "^0.28.20"
|
|
44
46
|
},
|
|
45
47
|
"devDependencies": {
|
|
48
|
+
"@electric-sql/pglite": "0.5.16",
|
|
46
49
|
"@sharadox/es-lint-configuration-web-library": "^0.1.3",
|
|
47
50
|
"@sharadox/library-build-web-library": "^0.2.1",
|
|
48
51
|
"@sharadox/prettier-configuration-web-library": "^0.1.2",
|