@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,22 @@
1
+ import type { CodePurpose } from "@sharadox/account-web-library/code-request/type";
2
+ import type { Contact } from "@sharadox/account-web-library/contact-kind/type";
3
+ export interface CodeVerificationOptions {
4
+ requestId: string;
5
+ /** As typed: spaces are ignored. */
6
+ code: string;
7
+ purpose: CodePurpose;
8
+ pepper: string;
9
+ /** Wrong codes allowed before the request is dead (5 by default). */
10
+ maximumAttempts?: number;
11
+ /** Milliseconds since 1970 (now by default). */
12
+ now?: number;
13
+ }
14
+ export type CodeVerificationResult = {
15
+ valid: true;
16
+ contact: Contact;
17
+ accountId: string | null;
18
+ } | {
19
+ valid: false;
20
+ reason: "unknown" | "used" | "replaced" | "expired" | "attempts" | "wrong";
21
+ };
22
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/code-verification/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iDAAiD,CAAC;AACnF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iDAAiD,CAAC;AAE/E,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,oCAAoC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,WAAW,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,sBAAsB,GAC9B;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAC3D;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,SAAS,GAAG,MAAM,GAAG,UAAU,GAAG,SAAS,GAAG,UAAU,GAAG,OAAO,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/code-verification/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ import type { Kysely } from "kysely";
2
+ import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
3
+ import type { ContactAdditionRequest, ContactAdditionResult } from "@sharadox/account-web-library/contact-addition/type";
4
+ /**
5
+ * Adds a contact to an account, unverified until a one-time code sent to it comes back (`verifyContact`). Refuses
6
+ * one the account already has, or one another account has verified. Ask for a fresh code first (step-up) and tell
7
+ * the other contacts.
8
+ *
9
+ * @example
10
+ * const result = await addContact(database, { accountId, contact: { kind: "email", value } });
11
+ */
12
+ export declare function addContact(database: Kysely<AccountDatabase>, { accountId, contact, now }: ContactAdditionRequest): Promise<ContactAdditionResult>;
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/contact-addition/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAE3F,OAAO,KAAK,EACV,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,qDAAqD,CAAC;AAI7D;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,SAAS,EAAE,OAAO,EAAE,GAAgB,EAAE,EAAE,sBAAsB,GAC/D,OAAO,CAAC,qBAAqB,CAAC,CA8BhC"}
@@ -0,0 +1,48 @@
1
+ import { uuidVersion7 } from "@sharadox/web-library/identifier/uuid-version-7";
2
+ import { recordAuditEvent } from "@sharadox/account-web-library/audit-event";
3
+ import { normalizeContact } from "@sharadox/account-web-library/contact-kind";
4
+ import { databaseError } from "@sharadox/account-web-library/database-error";
5
+ /**
6
+ * Adds a contact to an account, unverified until a one-time code sent to it comes back (`verifyContact`). Refuses
7
+ * one the account already has, or one another account has verified. Ask for a fresh code first (step-up) and tell
8
+ * the other contacts.
9
+ *
10
+ * @example
11
+ * const result = await addContact(database, { accountId, contact: { kind: "email", value } });
12
+ */
13
+ export async function addContact(database, { accountId, contact, now = Date.now() }) {
14
+ const { kind, value } = normalizeContact(contact);
15
+ const contactId = uuidVersion7({ now });
16
+ try {
17
+ return await database.transaction().execute(async (transaction) => {
18
+ const account = await transaction
19
+ .selectFrom("account")
20
+ .select("id")
21
+ .where("id", "=", accountId)
22
+ .executeTakeFirst();
23
+ if (!account)
24
+ return { added: false, reason: "no-account" };
25
+ const owner = await transaction
26
+ .selectFrom("contact")
27
+ .select("account_id")
28
+ .where("kind", "=", kind)
29
+ .where("value", "=", value)
30
+ .where("verified_at", "is not", null)
31
+ .executeTakeFirst();
32
+ if (owner && owner.account_id !== accountId)
33
+ return { added: false, reason: "contact-taken" };
34
+ await transaction
35
+ .insertInto("contact")
36
+ .values({ id: contactId, account_id: accountId, kind, value, verified_at: null, created_at: new Date(now) })
37
+ .execute();
38
+ await recordAuditEvent(transaction, { accountId, action: "contact.added", detail: { contactId, kind }, now });
39
+ return { added: true, contactId };
40
+ });
41
+ }
42
+ catch (error) {
43
+ if (databaseError(error)?.constraint === "contact_per_account")
44
+ return { added: false, reason: "already-added" };
45
+ throw error;
46
+ }
47
+ }
48
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/contact-addition/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAE/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAK7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAC;AAE7E;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,QAAiC,EACjC,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,EAA0B;IAEhE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAClD,MAAM,SAAS,GAAG,YAAY,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACxC,IAAI,CAAC;QACH,OAAO,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,WAAW,EAAkC,EAAE;YAChG,MAAM,OAAO,GAAG,MAAM,WAAW;iBAC9B,UAAU,CAAC,SAAS,CAAC;iBACrB,MAAM,CAAC,IAAI,CAAC;iBACZ,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,CAAC;iBAC3B,gBAAgB,EAAE,CAAC;YACtB,IAAI,CAAC,OAAO;gBAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;YAC5D,MAAM,KAAK,GAAG,MAAM,WAAW;iBAC5B,UAAU,CAAC,SAAS,CAAC;iBACrB,MAAM,CAAC,YAAY,CAAC;iBACpB,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC;iBACxB,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,CAAC;iBAC1B,KAAK,CAAC,aAAa,EAAE,QAAQ,EAAE,IAAI,CAAC;iBACpC,gBAAgB,EAAE,CAAC;YACtB,IAAI,KAAK,IAAI,KAAK,CAAC,UAAU,KAAK,SAAS;gBAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC;YAC9F,MAAM,WAAW;iBACd,UAAU,CAAC,SAAS,CAAC;iBACrB,MAAM,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;iBAC3G,OAAO,EAAE,CAAC;YACb,MAAM,gBAAgB,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;YAC9G,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QACpC,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,UAAU,KAAK,qBAAqB;YAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC;QACjH,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { Contact } from "@sharadox/account-web-library/contact-kind/type";
2
+ export interface ContactAdditionRequest {
3
+ accountId: string;
4
+ contact: Contact;
5
+ /** Milliseconds since 1970 (now by default). */
6
+ now?: number;
7
+ }
8
+ export type ContactAdditionResult = {
9
+ added: true;
10
+ contactId: string;
11
+ } | {
12
+ added: false;
13
+ reason: "already-added" | "contact-taken" | "no-account";
14
+ };
15
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/contact-addition/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iDAAiD,CAAC;AAE/E,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,qBAAqB,GAC/B;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,eAAe,GAAG,eAAe,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/contact-addition/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ import type { Contact } from "@sharadox/account-web-library/contact-kind/type";
2
+ /** The kinds of contact this version can store and send codes to. */
3
+ export declare const CONTACT_KINDS: string[];
4
+ /**
5
+ * A contact in the one form it is stored and compared in (an email trimmed and lowercase…). Throws for a kind this
6
+ * version doesn't know, or a value that isn't valid for its kind.
7
+ *
8
+ * @example
9
+ * normalizeContact({ kind: "email", value: " Luis@Example.com " }); // { kind: "email", value: "luis@example.com" }
10
+ */
11
+ export declare function normalizeContact({ kind, value }: Contact): Contact;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/contact-kind/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iDAAiD,CAAC;AAI/E,qEAAqE;AACrE,eAAO,MAAM,aAAa,UAA2B,CAAC;AAEtD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,OAAO,GAAG,OAAO,CAIlE"}
@@ -0,0 +1,18 @@
1
+ import { normalizeEmail } from "@sharadox/account-web-library/email-contact";
2
+ const NORMALIZERS = { email: normalizeEmail };
3
+ /** The kinds of contact this version can store and send codes to. */
4
+ export const CONTACT_KINDS = Object.keys(NORMALIZERS);
5
+ /**
6
+ * A contact in the one form it is stored and compared in (an email trimmed and lowercase…). Throws for a kind this
7
+ * version doesn't know, or a value that isn't valid for its kind.
8
+ *
9
+ * @example
10
+ * normalizeContact({ kind: "email", value: " Luis@Example.com " }); // { kind: "email", value: "luis@example.com" }
11
+ */
12
+ export function normalizeContact({ kind, value }) {
13
+ const normalize = NORMALIZERS[kind];
14
+ if (!normalize)
15
+ throw new Error(`unknown contact kind "${kind}"`);
16
+ return { kind, value: normalize(value) };
17
+ }
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/contact-kind/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAG7E,MAAM,WAAW,GAA8C,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC;AAEzF,qEAAqE;AACrE,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAEtD;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAW;IACvD,MAAM,SAAS,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IACpC,IAAI,CAAC,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,GAAG,CAAC,CAAC;IAClE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,6 @@
1
+ /** A contact as given or stored: its kind (`email`…) and value. */
2
+ export interface Contact {
3
+ kind: string;
4
+ value: string;
5
+ }
6
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/contact-kind/type.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/contact-kind/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,16 @@
1
+ import type { Kysely } from "kysely";
2
+ import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
3
+ import type { Contact } from "@sharadox/account-web-library/contact-kind/type";
4
+ /**
5
+ * The account a verified contact belongs to (written any way: it is normalized first), or undefined. Unverified
6
+ * contacts never count, so claiming someone's address proves nothing.
7
+ *
8
+ * @example
9
+ * const found = await findAccountByContact(database, { kind: "email", value: typed });
10
+ */
11
+ export declare function findAccountByContact(database: Kysely<AccountDatabase>, contact: Contact): Promise<{
12
+ accountId: string;
13
+ contactId: string;
14
+ signIn: boolean;
15
+ } | undefined>;
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/contact-lookup/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAE3F,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iDAAiD,CAAC;AAE/E;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,OAAO,EAAE,OAAO,GACf,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GAAG,SAAS,CAAC,CAUhF"}
@@ -0,0 +1,20 @@
1
+ import { normalizeContact } from "@sharadox/account-web-library/contact-kind";
2
+ /**
3
+ * The account a verified contact belongs to (written any way: it is normalized first), or undefined. Unverified
4
+ * contacts never count, so claiming someone's address proves nothing.
5
+ *
6
+ * @example
7
+ * const found = await findAccountByContact(database, { kind: "email", value: typed });
8
+ */
9
+ export async function findAccountByContact(database, contact) {
10
+ const { kind, value } = normalizeContact(contact);
11
+ const row = await database
12
+ .selectFrom("contact")
13
+ .select(["id", "account_id", "sign_in"])
14
+ .where("kind", "=", kind)
15
+ .where("value", "=", value)
16
+ .where("verified_at", "is not", null)
17
+ .executeTakeFirst();
18
+ return row && { accountId: row.account_id, contactId: row.id, signIn: row.sign_in };
19
+ }
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/contact-lookup/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAG9E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,QAAiC,EACjC,OAAgB;IAEhB,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAClD,MAAM,GAAG,GAAG,MAAM,QAAQ;SACvB,UAAU,CAAC,SAAS,CAAC;SACrB,MAAM,CAAC,CAAC,IAAI,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC;SACvC,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC;SACxB,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,CAAC;SAC1B,KAAK,CAAC,aAAa,EAAE,QAAQ,EAAE,IAAI,CAAC;SACpC,gBAAgB,EAAE,CAAC;IACtB,OAAO,GAAG,IAAI,EAAE,SAAS,EAAE,GAAG,CAAC,UAAU,EAAE,SAAS,EAAE,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;AACtF,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { Kysely } from "kysely";
2
+ import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
3
+ /**
4
+ * Removes a contact from an account. Refuses to remove the last verified sign-in contact of a person (the database
5
+ * checks it when the change commits). Ask for a fresh code first (step-up) and tell the other contacts.
6
+ *
7
+ * @example
8
+ * const result = await removeContact(database, { accountId, contactId });
9
+ */
10
+ export declare function removeContact(database: Kysely<AccountDatabase>, { accountId, contactId }: {
11
+ accountId: string;
12
+ contactId: string;
13
+ }): Promise<{
14
+ removed: true;
15
+ } | {
16
+ removed: false;
17
+ reason: "no-contact" | "last-sign-in-contact";
18
+ }>;
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/contact-removal/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAI3F;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GACjE,OAAO,CAAC;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,YAAY,GAAG,sBAAsB,CAAA;CAAE,CAAC,CAqBhG"}
@@ -0,0 +1,35 @@
1
+ import { recordAuditEvent } from "@sharadox/account-web-library/audit-event";
2
+ import { databaseError } from "@sharadox/account-web-library/database-error";
3
+ /**
4
+ * Removes a contact from an account. Refuses to remove the last verified sign-in contact of a person (the database
5
+ * checks it when the change commits). Ask for a fresh code first (step-up) and tell the other contacts.
6
+ *
7
+ * @example
8
+ * const result = await removeContact(database, { accountId, contactId });
9
+ */
10
+ export async function removeContact(database, { accountId, contactId }) {
11
+ try {
12
+ return await database.transaction().execute(async (transaction) => {
13
+ const removed = await transaction
14
+ .deleteFrom("contact")
15
+ .where("id", "=", contactId)
16
+ .where("account_id", "=", accountId)
17
+ .returning("kind")
18
+ .executeTakeFirst();
19
+ if (!removed)
20
+ return { removed: false, reason: "no-contact" };
21
+ await recordAuditEvent(transaction, {
22
+ accountId,
23
+ action: "contact.removed",
24
+ detail: { contactId, kind: removed.kind },
25
+ });
26
+ return { removed: true };
27
+ });
28
+ }
29
+ catch (error) {
30
+ if (databaseError(error)?.code === "23514")
31
+ return { removed: false, reason: "last-sign-in-contact" };
32
+ throw error;
33
+ }
34
+ }
35
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/contact-removal/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAC;AAE7E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,QAAiC,EACjC,EAAE,SAAS,EAAE,SAAS,EAA4C;IAElE,IAAI,CAAC;QACH,OAAO,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;YAChE,MAAM,OAAO,GAAG,MAAM,WAAW;iBAC9B,UAAU,CAAC,SAAS,CAAC;iBACrB,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,CAAC;iBAC3B,KAAK,CAAC,YAAY,EAAE,GAAG,EAAE,SAAS,CAAC;iBACnC,SAAS,CAAC,MAAM,CAAC;iBACjB,gBAAgB,EAAE,CAAC;YACtB,IAAI,CAAC,OAAO;gBAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAW,CAAC;YACvE,MAAM,gBAAgB,CAAC,WAAW,EAAE;gBAClC,SAAS;gBACT,MAAM,EAAE,iBAAiB;gBACzB,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE;aAC1C,CAAC,CAAC;YACH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAW,CAAC;QACpC,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,IAAI,KAAK,OAAO;YAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,sBAAsB,EAAE,CAAC;QACtG,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { Kysely } from "kysely";
2
+ import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
3
+ /**
4
+ * Marks an account's contact verified, once the one-time code sent to it came back. Refuses when another account
5
+ * verified the same contact first (a verified contact belongs to one account only).
6
+ *
7
+ * @example
8
+ * await verifyContact(database, { accountId, contactId }); // { verified: true }
9
+ */
10
+ export declare function verifyContact(database: Kysely<AccountDatabase>, { accountId, contactId, now }: {
11
+ accountId: string;
12
+ contactId: string;
13
+ now?: number;
14
+ }): Promise<{
15
+ verified: true;
16
+ } | {
17
+ verified: false;
18
+ reason: "no-contact" | "contact-taken";
19
+ }>;
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/contact-verification/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAI3F;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,SAAS,EAAE,SAAS,EAAE,GAAgB,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GACjG,OAAO,CAAC;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,QAAQ,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,YAAY,GAAG,eAAe,CAAA;CAAE,CAAC,CAuB3F"}
@@ -0,0 +1,37 @@
1
+ import { recordAuditEvent } from "@sharadox/account-web-library/audit-event";
2
+ import { databaseError } from "@sharadox/account-web-library/database-error";
3
+ /**
4
+ * Marks an account's contact verified, once the one-time code sent to it came back. Refuses when another account
5
+ * verified the same contact first (a verified contact belongs to one account only).
6
+ *
7
+ * @example
8
+ * await verifyContact(database, { accountId, contactId }); // { verified: true }
9
+ */
10
+ export async function verifyContact(database, { accountId, contactId, now = Date.now() }) {
11
+ try {
12
+ return await database.transaction().execute(async (transaction) => {
13
+ const updated = await transaction
14
+ .updateTable("contact")
15
+ .set({ verified_at: new Date(now) })
16
+ .where("id", "=", contactId)
17
+ .where("account_id", "=", accountId)
18
+ .returning("kind")
19
+ .executeTakeFirst();
20
+ if (!updated)
21
+ return { verified: false, reason: "no-contact" };
22
+ await recordAuditEvent(transaction, {
23
+ accountId,
24
+ action: "contact.verified",
25
+ detail: { contactId, kind: updated.kind },
26
+ now,
27
+ });
28
+ return { verified: true };
29
+ });
30
+ }
31
+ catch (error) {
32
+ if (databaseError(error)?.constraint === "contact_verified")
33
+ return { verified: false, reason: "contact-taken" };
34
+ throw error;
35
+ }
36
+ }
37
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/contact-verification/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAC;AAE7E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,QAAiC,EACjC,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,EAA0D;IAElG,IAAI,CAAC;QACH,OAAO,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;YAChE,MAAM,OAAO,GAAG,MAAM,WAAW;iBAC9B,WAAW,CAAC,SAAS,CAAC;iBACtB,GAAG,CAAC,EAAE,WAAW,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;iBACnC,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,CAAC;iBAC3B,KAAK,CAAC,YAAY,EAAE,GAAG,EAAE,SAAS,CAAC;iBACnC,SAAS,CAAC,MAAM,CAAC;iBACjB,gBAAgB,EAAE,CAAC;YACtB,IAAI,CAAC,OAAO;gBAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAW,CAAC;YACxE,MAAM,gBAAgB,CAAC,WAAW,EAAE;gBAClC,SAAS;gBACT,MAAM,EAAE,kBAAkB;gBAC1B,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE;gBACzC,GAAG;aACJ,CAAC,CAAC;YACH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAW,CAAC;QACrC,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,UAAU,KAAK,kBAAkB;YAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC;QACjH,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Postgres's error code (`23505` unique, `23514` check…) and the constraint that failed, from an error thrown by the
3
+ * driver (Neon's or PGlite's); undefined for any other error.
4
+ *
5
+ * @example
6
+ * if (databaseError(error)?.constraint === "account_username_key") return { reason: "username-taken" };
7
+ */
8
+ export declare function databaseError(error: unknown): {
9
+ code: string;
10
+ constraint: string | undefined;
11
+ } | undefined;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/database-error/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAAG,SAAS,CAK1G"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Postgres's error code (`23505` unique, `23514` check…) and the constraint that failed, from an error thrown by the
3
+ * driver (Neon's or PGlite's); undefined for any other error.
4
+ *
5
+ * @example
6
+ * if (databaseError(error)?.constraint === "account_username_key") return { reason: "username-taken" };
7
+ */
8
+ export function databaseError(error) {
9
+ if (typeof error !== "object" || error === null || typeof error.code !== "string")
10
+ return undefined;
11
+ const { code, constraint } = error;
12
+ return { code, constraint };
13
+ }
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/database-error/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,OAAQ,KAA4B,CAAC,IAAI,KAAK,QAAQ;QACvG,OAAO,SAAS,CAAC;IACnB,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,KAA8C,CAAC;IAC5E,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { Kysely } from "kysely";
2
+ import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
3
+ import type { PersonAccountRequest, PersonAccountResult } from "@sharadox/account-web-library/person-account/type";
4
+ /**
5
+ * Creates a person's account with the contact their one-time code just proved, as its verified sign-in contact, and
6
+ * records it — all or nothing. Refuses a username outside the rules or taken in any case, and a contact another
7
+ * account has verified.
8
+ *
9
+ * @example
10
+ * const result = await createPersonAccount(database, { username: "Luis-Pires", contact: { kind: "email", value } });
11
+ * if (!result.created) return explain(result.reason);
12
+ */
13
+ export declare function createPersonAccount(database: Kysely<AccountDatabase>, { username, contact, now }: PersonAccountRequest): Promise<PersonAccountResult>;
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/person-account/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,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,mDAAmD,CAAC;AAGnH;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAgB,EAAE,EAAE,oBAAoB,GAC5D,OAAO,CAAC,mBAAmB,CAAC,CAyB9B"}
@@ -0,0 +1,45 @@
1
+ import { uuidVersion7 } from "@sharadox/web-library/identifier/uuid-version-7";
2
+ import { recordAuditEvent } from "@sharadox/account-web-library/audit-event";
3
+ import { normalizeContact } from "@sharadox/account-web-library/contact-kind";
4
+ import { databaseError } from "@sharadox/account-web-library/database-error";
5
+ import { checkUsername } from "@sharadox/account-web-library/username";
6
+ /**
7
+ * Creates a person's account with the contact their one-time code just proved, as its verified sign-in contact, and
8
+ * records it — all or nothing. Refuses a username outside the rules or taken in any case, and a contact another
9
+ * account has verified.
10
+ *
11
+ * @example
12
+ * const result = await createPersonAccount(database, { username: "Luis-Pires", contact: { kind: "email", value } });
13
+ * if (!result.created) return explain(result.reason);
14
+ */
15
+ export async function createPersonAccount(database, { username, contact, now = Date.now() }) {
16
+ if (!checkUsername(username).valid)
17
+ return { created: false, reason: "username-invalid" };
18
+ const { kind, value } = normalizeContact(contact);
19
+ const at = new Date(now);
20
+ const accountId = uuidVersion7({ now });
21
+ const contactId = uuidVersion7({ now });
22
+ try {
23
+ await database.transaction().execute(async (transaction) => {
24
+ await transaction
25
+ .insertInto("account")
26
+ .values({ id: accountId, kind: "person", username, owner_id: null, created_at: at, last_active_at: at })
27
+ .execute();
28
+ await transaction
29
+ .insertInto("contact")
30
+ .values({ id: contactId, account_id: accountId, kind, value, verified_at: at, created_at: at })
31
+ .execute();
32
+ await recordAuditEvent(transaction, { accountId, action: "account.created", detail: { contactId }, now });
33
+ });
34
+ }
35
+ catch (error) {
36
+ const constraint = databaseError(error)?.constraint;
37
+ if (constraint === "account_username_key")
38
+ return { created: false, reason: "username-taken" };
39
+ if (constraint === "contact_verified")
40
+ return { created: false, reason: "contact-taken" };
41
+ throw error;
42
+ }
43
+ return { created: true, accountId, contactId };
44
+ }
45
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/person-account/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAE/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAC;AAE7E,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAEvE;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,QAAiC,EACjC,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,EAAwB;IAE7D,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,KAAK;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC;IAC1F,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAClD,MAAM,EAAE,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,MAAM,SAAS,GAAG,YAAY,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACxC,MAAM,SAAS,GAAG,YAAY,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACxC,IAAI,CAAC;QACH,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;YACzD,MAAM,WAAW;iBACd,UAAU,CAAC,SAAS,CAAC;iBACrB,MAAM,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,CAAC;iBACvG,OAAO,EAAE,CAAC;YACb,MAAM,WAAW;iBACd,UAAU,CAAC,SAAS,CAAC;iBACrB,MAAM,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC;iBAC9F,OAAO,EAAE,CAAC;YACb,MAAM,gBAAgB,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;QAC5G,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,UAAU,GAAG,aAAa,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC;QACpD,IAAI,UAAU,KAAK,sBAAsB;YAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;QAC/F,IAAI,UAAU,KAAK,kBAAkB;YAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC;QAC1F,MAAM,KAAK,CAAC;IACd,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;AACjD,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { Contact } from "@sharadox/account-web-library/contact-kind/type";
2
+ export interface PersonAccountRequest {
3
+ username: string;
4
+ /** Already proved by a one-time code: it is stored verified. */
5
+ contact: Contact;
6
+ /** Milliseconds since 1970 (now by default). */
7
+ now?: number;
8
+ }
9
+ export type PersonAccountResult = {
10
+ created: true;
11
+ accountId: string;
12
+ contactId: string;
13
+ } | {
14
+ created: false;
15
+ reason: "username-invalid" | "username-taken" | "contact-taken";
16
+ };
17
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/person-account/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iDAAiD,CAAC;AAE/E,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,OAAO,EAAE,OAAO,CAAC;IACjB,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,mBAAmB,GAC3B;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GACvD;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,kBAAkB,GAAG,gBAAgB,GAAG,eAAe,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/person-account/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ import type { MemoryDatabase } from "@sharadox/database-web-library/memory-database/type";
2
+ import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
3
+ /**
4
+ * A migrated account database in memory, for this library's tests (and applications' own): Postgres 18 through
5
+ * PGlite, so every constraint and trigger runs as in production.
6
+ *
7
+ * @example
8
+ * const memory = await createTestAccountDatabase();
9
+ * // … test …
10
+ * await memory.close();
11
+ */
12
+ export declare function createTestAccountDatabase(): Promise<MemoryDatabase<AccountDatabase>>;
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/test-database/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qDAAqD,CAAC;AAC1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAG3F;;;;;;;;GAQG;AACH,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC,CAI1F"}
@@ -0,0 +1,17 @@
1
+ import { createMemoryDatabase } from "@sharadox/database-web-library/memory-database";
2
+ import { migrateAccount } from "@sharadox/account-web-library/account-migration";
3
+ /**
4
+ * A migrated account database in memory, for this library's tests (and applications' own): Postgres 18 through
5
+ * PGlite, so every constraint and trigger runs as in production.
6
+ *
7
+ * @example
8
+ * const memory = await createTestAccountDatabase();
9
+ * // … test …
10
+ * await memory.close();
11
+ */
12
+ export async function createTestAccountDatabase() {
13
+ const memory = await createMemoryDatabase();
14
+ await migrateAccount(memory.database);
15
+ return memory;
16
+ }
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/test-database/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gDAAgD,CAAC;AAGtF,OAAO,EAAE,cAAc,EAAE,MAAM,iDAAiD,CAAC;AAEjF;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB;IAC7C,MAAM,MAAM,GAAG,MAAM,oBAAoB,EAAmB,CAAC;IAC7D,MAAM,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACtC,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { type Kysely } from "kysely";
2
+ import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
3
+ /**
4
+ * Whether a username can be taken: `available`, `taken` (in any case: `aBc` is taken when `abc` exists) or `invalid`
5
+ * (outside the rules). Rate limit callers: it tells whether an account exists.
6
+ *
7
+ * @example
8
+ * await usernameAvailability(database, "Luis-Pires"); // "available"
9
+ */
10
+ export declare function usernameAvailability(database: Kysely<AccountDatabase>, username: string): Promise<"available" | "taken" | "invalid">;
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/username-availability/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAG3F;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,WAAW,GAAG,OAAO,GAAG,SAAS,CAAC,CAS5C"}
@@ -0,0 +1,21 @@
1
+ import { sql } from "kysely";
2
+ import { checkUsername } from "@sharadox/account-web-library/username";
3
+ /**
4
+ * Whether a username can be taken: `available`, `taken` (in any case: `aBc` is taken when `abc` exists) or `invalid`
5
+ * (outside the rules). Rate limit callers: it tells whether an account exists.
6
+ *
7
+ * @example
8
+ * await usernameAvailability(database, "Luis-Pires"); // "available"
9
+ */
10
+ export async function usernameAvailability(database, username) {
11
+ const check = checkUsername(username);
12
+ if (!check.valid)
13
+ return "invalid";
14
+ const found = await database
15
+ .selectFrom("account")
16
+ .select("id")
17
+ .where(sql `lower(username)`, "=", check.key)
18
+ .executeTakeFirst();
19
+ return found ? "taken" : "available";
20
+ }
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/username-availability/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAe,MAAM,QAAQ,CAAC;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAEvE;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,QAAiC,EACjC,QAAgB;IAEhB,MAAM,KAAK,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;IACtC,IAAI,CAAC,KAAK,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IACnC,MAAM,KAAK,GAAG,MAAM,QAAQ;SACzB,UAAU,CAAC,SAAS,CAAC;SACrB,MAAM,CAAC,IAAI,CAAC;SACZ,KAAK,CAAC,GAAG,CAAQ,iBAAiB,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC;SACnD,gBAAgB,EAAE,CAAC;IACtB,OAAO,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC;AACvC,CAAC"}