@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.
Files changed (94) hide show
  1. package/README.md +75 -3
  2. package/distribution/account-database/type.d.ts +73 -0
  3. package/distribution/account-database/type.d.ts.map +1 -0
  4. package/distribution/account-database/type.js +2 -0
  5. package/distribution/account-database/type.js.map +1 -0
  6. package/distribution/account-migration/index.d.ts +18 -0
  7. package/distribution/account-migration/index.d.ts.map +1 -0
  8. package/distribution/account-migration/index.js +122 -0
  9. package/distribution/account-migration/index.js.map +1 -0
  10. package/distribution/audit-event/index.d.ts +12 -0
  11. package/distribution/audit-event/index.d.ts.map +1 -0
  12. package/distribution/audit-event/index.js +25 -0
  13. package/distribution/audit-event/index.js.map +1 -0
  14. package/distribution/audit-event/type.d.ts +15 -0
  15. package/distribution/audit-event/type.d.ts.map +1 -0
  16. package/distribution/audit-event/type.js +2 -0
  17. package/distribution/audit-event/type.js.map +1 -0
  18. package/distribution/code-request/index.d.ts +16 -0
  19. package/distribution/code-request/index.d.ts.map +1 -0
  20. package/distribution/code-request/index.js +52 -0
  21. package/distribution/code-request/index.js.map +1 -0
  22. package/distribution/code-request/type.d.ts +25 -0
  23. package/distribution/code-request/type.d.ts.map +1 -0
  24. package/distribution/code-request/type.js +2 -0
  25. package/distribution/code-request/type.js.map +1 -0
  26. package/distribution/code-request-prune/index.d.ts +13 -0
  27. package/distribution/code-request-prune/index.d.ts.map +1 -0
  28. package/distribution/code-request-prune/index.js +12 -0
  29. package/distribution/code-request-prune/index.js.map +1 -0
  30. package/distribution/code-verification/index.d.ts +14 -0
  31. package/distribution/code-verification/index.d.ts.map +1 -0
  32. package/distribution/code-verification/index.js +43 -0
  33. package/distribution/code-verification/index.js.map +1 -0
  34. package/distribution/code-verification/type.d.ts +22 -0
  35. package/distribution/code-verification/type.d.ts.map +1 -0
  36. package/distribution/code-verification/type.js +2 -0
  37. package/distribution/code-verification/type.js.map +1 -0
  38. package/distribution/contact-addition/index.d.ts +13 -0
  39. package/distribution/contact-addition/index.d.ts.map +1 -0
  40. package/distribution/contact-addition/index.js +48 -0
  41. package/distribution/contact-addition/index.js.map +1 -0
  42. package/distribution/contact-addition/type.d.ts +15 -0
  43. package/distribution/contact-addition/type.d.ts.map +1 -0
  44. package/distribution/contact-addition/type.js +2 -0
  45. package/distribution/contact-addition/type.js.map +1 -0
  46. package/distribution/contact-kind/index.d.ts +12 -0
  47. package/distribution/contact-kind/index.d.ts.map +1 -0
  48. package/distribution/contact-kind/index.js +18 -0
  49. package/distribution/contact-kind/index.js.map +1 -0
  50. package/distribution/contact-kind/type.d.ts +6 -0
  51. package/distribution/contact-kind/type.d.ts.map +1 -0
  52. package/distribution/contact-kind/type.js +2 -0
  53. package/distribution/contact-kind/type.js.map +1 -0
  54. package/distribution/contact-lookup/index.d.ts +16 -0
  55. package/distribution/contact-lookup/index.d.ts.map +1 -0
  56. package/distribution/contact-lookup/index.js +20 -0
  57. package/distribution/contact-lookup/index.js.map +1 -0
  58. package/distribution/contact-removal/index.d.ts +19 -0
  59. package/distribution/contact-removal/index.d.ts.map +1 -0
  60. package/distribution/contact-removal/index.js +35 -0
  61. package/distribution/contact-removal/index.js.map +1 -0
  62. package/distribution/contact-verification/index.d.ts +20 -0
  63. package/distribution/contact-verification/index.d.ts.map +1 -0
  64. package/distribution/contact-verification/index.js +37 -0
  65. package/distribution/contact-verification/index.js.map +1 -0
  66. package/distribution/database-error/index.d.ts +12 -0
  67. package/distribution/database-error/index.d.ts.map +1 -0
  68. package/distribution/database-error/index.js +14 -0
  69. package/distribution/database-error/index.js.map +1 -0
  70. package/distribution/person-account/index.d.ts +14 -0
  71. package/distribution/person-account/index.d.ts.map +1 -0
  72. package/distribution/person-account/index.js +45 -0
  73. package/distribution/person-account/index.js.map +1 -0
  74. package/distribution/person-account/type.d.ts +17 -0
  75. package/distribution/person-account/type.d.ts.map +1 -0
  76. package/distribution/person-account/type.js +2 -0
  77. package/distribution/person-account/type.js.map +1 -0
  78. package/distribution/test-database/index.d.ts +13 -0
  79. package/distribution/test-database/index.d.ts.map +1 -0
  80. package/distribution/test-database/index.js +17 -0
  81. package/distribution/test-database/index.js.map +1 -0
  82. package/distribution/username-availability/index.d.ts +11 -0
  83. package/distribution/username-availability/index.d.ts.map +1 -0
  84. package/distribution/username-availability/index.js +21 -0
  85. package/distribution/username-availability/index.js.map +1 -0
  86. package/distribution/username-change/index.d.ts +15 -0
  87. package/distribution/username-change/index.d.ts.map +1 -0
  88. package/distribution/username-change/index.js +39 -0
  89. package/distribution/username-change/index.js.map +1 -0
  90. package/distribution/username-change/type.d.ts +7 -0
  91. package/distribution/username-change/type.d.ts.map +1 -0
  92. package/distribution/username-change/type.js +2 -0
  93. package/distribution/username-change/type.js.map +1 -0
  94. 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
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/username-change/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAC7E,OAAO,EAAE,a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C,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,7 @@
1
+ export type UsernameChangeResult = {
2
+ changed: true;
3
+ } | {
4
+ changed: false;
5
+ reason: "username-invalid" | "username-taken" | "no-account";
6
+ };
7
+ //# sourceMappingURL=type.d.ts.map
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -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",
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": "^0.11.1"
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",