@madauth/server 0.3.0-beta.2 → 0.5.0-beta.1

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 (37) hide show
  1. package/README.md +3 -2
  2. package/dist/bin.js +202 -50
  3. package/dist/chunk-7DHKDRGY.js +1706 -0
  4. package/dist/{chunk-DCDTO5LG.js → chunk-A7UYZRBL.js} +1 -0
  5. package/dist/chunk-NP75Y3IV.js +107 -0
  6. package/dist/chunk-NYIEFI4B.js +1040 -0
  7. package/dist/{chunk-56MOVFO4.js → chunk-O2URPWA6.js} +37 -4
  8. package/dist/{chunk-3QRKWLR7.js → chunk-SISM7YUZ.js} +15 -10
  9. package/dist/{config-Dg2fZuWR.d.ts → config-CcGlHVAN.d.ts} +19 -8
  10. package/dist/dynamodb.js +1 -1
  11. package/dist/entry/azure.d.ts +3 -3
  12. package/dist/entry/azure.js +4 -4
  13. package/dist/entry/lambda.d.ts +3 -3
  14. package/dist/entry/lambda.js +4 -4
  15. package/dist/entry/node.d.ts +3 -3
  16. package/dist/entry/node.js +4 -4
  17. package/dist/index.d.ts +37 -15
  18. package/dist/index.js +12 -6
  19. package/dist/{schema-3yhCc2jH.d.ts → schema-BTgDj1Xn.d.ts} +79 -3
  20. package/dist/sqlite.js +2 -2
  21. package/dist/standalone/azure.mjs +5511 -922
  22. package/dist/standalone/lambda.mjs +5461 -872
  23. package/dist/standalone/main.mjs +5487 -898
  24. package/dist/store/dynamodb.d.ts +1 -1
  25. package/dist/store/sqlite.d.ts +1 -1
  26. package/dist/testing.d.ts +1 -1
  27. package/dist/testing.js +21 -0
  28. package/dist/{user-BMWEWREH.d.ts → user-yoGjrw4k.d.ts} +5 -0
  29. package/dist/verify.d.ts +1 -1
  30. package/dist/verify.js +1 -1
  31. package/dist/{webhook-j5u9Kv9l.d.ts → webhook-DlmfG_kS.d.ts} +5 -2
  32. package/dist/webhook.d.ts +1 -1
  33. package/dist/webhook.js +1 -1
  34. package/package.json +4 -2
  35. package/dist/chunk-CD7Y4T66.js +0 -62
  36. package/dist/chunk-DVVBIFIV.js +0 -718
  37. package/dist/chunk-TI35AZ2U.js +0 -660
@@ -57,6 +57,7 @@ function userFromClaims(claims) {
57
57
  if (claims.name) user.name = claims.name;
58
58
  if (claims.picture) user.picture = claims.picture;
59
59
  if (claims.claims && typeof claims.claims === "object" && Object.keys(claims.claims).length) user.claims = claims.claims;
60
+ if (Array.isArray(claims.amr)) user.amr = claims.amr.filter((value) => typeof value === "string");
60
61
  return user;
61
62
  }
62
63
 
@@ -0,0 +1,107 @@
1
+ // src/store/schema.ts
2
+ var madauthSchema = {
3
+ version: 7,
4
+ models: {
5
+ /** Someone who signed in, whichever way: the e-mail address is the identity shared by the sign-in methods. */
6
+ user: {
7
+ fields: {
8
+ id: { type: "string", primaryKey: true },
9
+ email: { type: "string" },
10
+ emailNormalized: { type: "string", unique: true },
11
+ emailVerified: { type: "boolean" },
12
+ name: { type: "string", nullable: true },
13
+ sessionVersion: { type: "number" },
14
+ /** When the last e-mail was sent to the user: at most one per minute. */
15
+ lastMailAt: { type: "number" },
16
+ /** When the last SMS was sent to the user: at most one per minute, counted apart from the e-mails (since version 6). */
17
+ lastSmsAt: { type: "number", nullable: true },
18
+ /** Wrong e-mail codes in a row, counted across e-mails (since version 2). */
19
+ wrongCodes: { type: "number" },
20
+ /** What admins attached to the user, as JSON, e.g. `{"roles":["admin"]}` (since version 4). */
21
+ claims: { type: "string", nullable: true },
22
+ /**
23
+ * When the user's first session started: the sign-up was complete, with every second factor the
24
+ * policy asked for. 0 until then. Empty in records from before version 7, whose sign-up counts as
25
+ * complete (since version 7).
26
+ */
27
+ signedUpAt: { type: "number", nullable: true },
28
+ createdAt: { type: "number" }
29
+ }
30
+ },
31
+ /**
32
+ * How a user signs in. `key` is `password:<userId>`, `google:<sub>`, `totp:<userId>` (the authenticator
33
+ * app, whose `secret` is encrypted), `email-link:<userId>` or `sms:<userId>` (the phone that gets the
34
+ * codes of the second factor).
35
+ */
36
+ account: {
37
+ fields: {
38
+ id: { type: "string", primaryKey: true },
39
+ userId: { type: "string", index: true },
40
+ key: { type: "string", unique: true },
41
+ secret: { type: "string", nullable: true },
42
+ failedAttempts: { type: "number" },
43
+ lockedUntil: { type: "number" },
44
+ /** The address the provider reported at the last sign-in, e.g. Google's current primary address (since version 4). */
45
+ email: { type: "string", nullable: true },
46
+ /** The time step of the last authenticator code that was accepted, so a code works once; 0 before (since version 5). */
47
+ lastUsedStep: { type: "number" },
48
+ /**
49
+ * The setup an authenticator secret came from; its recovery codes carry the same id, so the app and
50
+ * its codes always belong together. Empty for other accounts (since version 5).
51
+ */
52
+ setupId: { type: "string", nullable: true },
53
+ /** The phone number of an `sms:` account, in E.164 form (`+41791234567`). Empty for other accounts (since version 6). */
54
+ phone: { type: "string", nullable: true },
55
+ /**
56
+ * The user's id when the account is how they sign in (their one primary method), empty for a second
57
+ * factor. Unique, so a user has one primary method at most (since version 7; empty in older records).
58
+ */
59
+ primaryUserId: { type: "string", nullable: true, unique: true },
60
+ /**
61
+ * Whether the account is a second factor (an authenticator app that is a step of the user's sign-in
62
+ * method, or a phone for SMS codes) rather than a sign-in method. Empty in records from before version 7,
63
+ * which madAuth tells apart by their key (since version 7).
64
+ */
65
+ secondFactor: { type: "boolean", nullable: true },
66
+ createdAt: { type: "number" }
67
+ }
68
+ },
69
+ /**
70
+ * A recovery code of a user's authenticator app (since version 5). `id` is the code's keyed hash; the
71
+ * record goes when the code is used. It works only while the account's `setupId` is its own.
72
+ */
73
+ recoveryCode: {
74
+ fields: {
75
+ id: { type: "string", primaryKey: true },
76
+ userId: { type: "string", index: true },
77
+ setupId: { type: "string" },
78
+ createdAt: { type: "number" }
79
+ }
80
+ },
81
+ /** A pending e-mail verification, password reset, sign-in link or SMS code. `id` is the SHA-256 of the link token. */
82
+ verification: {
83
+ fields: {
84
+ id: { type: "string", primaryKey: true },
85
+ userId: { type: "string", index: true },
86
+ purpose: { type: "string" },
87
+ codeHash: { type: "string" },
88
+ attempts: { type: "number" },
89
+ expiresAt: { type: "number" }
90
+ }
91
+ },
92
+ /** A setting admins change at runtime, as JSON (since version 4), e.g. `methods`: which sign-in methods are on. */
93
+ setting: {
94
+ fields: {
95
+ id: { type: "string", primaryKey: true },
96
+ value: { type: "string" },
97
+ updatedAt: { type: "number" },
98
+ /** The address of the admin who set it; empty when set from the command line. */
99
+ updatedBy: { type: "string", nullable: true }
100
+ }
101
+ }
102
+ }
103
+ };
104
+
105
+ export {
106
+ madauthSchema
107
+ };