@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
@@ -1,5 +1,5 @@
1
1
  import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
2
- import { S as StoreAdapter } from '../schema-3yhCc2jH.js';
2
+ import { S as StoreAdapter } from '../schema-BTgDj1Xn.js';
3
3
 
4
4
  interface DynamoDbAdapterOptions {
5
5
  /** The table, with the partition key `pk` and the sort key `sk` (both strings). */
@@ -1,4 +1,4 @@
1
- import { S as StoreAdapter } from '../schema-3yhCc2jH.js';
1
+ import { S as StoreAdapter } from '../schema-BTgDj1Xn.js';
2
2
 
3
3
  /**
4
4
  * Stores madAuth's records in a SQLite file using Node's built-in `node:sqlite` (Node 22.13 or newer).
package/dist/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { S as StoreAdapter } from './schema-3yhCc2jH.js';
1
+ import { S as StoreAdapter } from './schema-BTgDj1Xn.js';
2
2
 
3
3
  /** The parts of a test runner the contract needs; Vitest, Jest and node:test with `expect` all fit. */
4
4
  interface ContractRunner {
package/dist/testing.js CHANGED
@@ -13,8 +13,10 @@ function testUser(overrides = {}) {
13
13
  name: null,
14
14
  sessionVersion: 0,
15
15
  lastMailAt: 0,
16
+ lastSmsAt: null,
16
17
  wrongCodes: 0,
17
18
  claims: null,
19
+ signedUpAt: null,
18
20
  createdAt: 17e11,
19
21
  ...overrides
20
22
  };
@@ -29,6 +31,11 @@ function testAccount(overrides = {}) {
29
31
  failedAttempts: 0,
30
32
  lockedUntil: 0,
31
33
  email: null,
34
+ lastUsedStep: 0,
35
+ setupId: null,
36
+ phone: null,
37
+ primaryUserId: null,
38
+ secondFactor: null,
32
39
  createdAt: 17e11,
33
40
  ...overrides
34
41
  };
@@ -115,6 +122,20 @@ function storeAdapterContract(t, createAdapter) {
115
122
  expect(await store.findOne("account", { key: account.key })).toEqual(account);
116
123
  expect(await store.findOne("account", { key: unique("password:missing") })).toBe(null);
117
124
  });
125
+ it("lets many records leave a unique field empty, but refuses a value that is taken", async () => {
126
+ const store = await createAdapter();
127
+ const userId = unique("usr_contract");
128
+ const first = testAccount({ userId, key: unique("totp:contract") });
129
+ const second = testAccount({ userId, key: unique("sms:contract") });
130
+ const primary = testAccount({ userId, primaryUserId: userId });
131
+ const another = testAccount({ userId, primaryUserId: userId });
132
+ expect(await store.create("account", first)).toBe(true);
133
+ expect(await store.create("account", second)).toBe(true);
134
+ expect(await store.create("account", primary)).toBe(true);
135
+ expect(await store.create("account", another)).toBe(false);
136
+ expect(await store.findOne("account", { primaryUserId: userId })).toEqual(primary);
137
+ expect(await store.findOne("account", { id: another.id })).toBe(null);
138
+ });
118
139
  it("sets a field to a value and to null", async () => {
119
140
  const store = await createAdapter();
120
141
  const user = testUser({ name: "Ada" });
@@ -7,6 +7,11 @@ interface MadauthUser {
7
7
  picture?: string;
8
8
  /** What admins attached to the user, e.g. `{ roles: ['admin'] }`. Absent without claims. */
9
9
  claims?: Record<string, unknown>;
10
+ /**
11
+ * How this session was authenticated (RFC 8176): `pwd` (password), `google`, `github`, `otp` (the
12
+ * authenticator app, on its own or as the second factor), e.g. `['pwd', 'otp']`. Present on a user that comes with a session.
13
+ */
14
+ amr?: string[];
10
15
  }
11
16
 
12
17
  export type { MadauthUser as M };
package/dist/verify.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { JWTVerifyGetKey } from 'jose';
2
- import { M as MadauthUser } from './user-BMWEWREH.js';
2
+ import { M as MadauthUser } from './user-yoGjrw4k.js';
3
3
 
4
4
  interface SessionVerifierOptions {
5
5
  /** The madAuth server's public base URL (its MADAUTH_ISSUER). */
package/dist/verify.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  SESSION_COOKIE,
3
3
  SESSION_TYP,
4
4
  userFromClaims
5
- } from "./chunk-DCDTO5LG.js";
5
+ } from "./chunk-A7UYZRBL.js";
6
6
  import {
7
7
  SIGNING_ALG
8
8
  } from "./chunk-JDQLSL36.js";
@@ -1,5 +1,8 @@
1
- /** Every `type` madAuth sends. */
2
- declare const WEBHOOK_TYPES: readonly ["email.verify", "email.reset", "email.already_registered", "email.no_password", "signup.before", "user.created", "email.verified", "email.password_reset", "user.signed_in", "user.deleted", "user.claims_changed"];
1
+ /**
2
+ * Every `type` madAuth sends: `email.send_*` and `sms.send_*` hand over a message to send, `user.signing_up`
3
+ * asks whether someone may sign up, and the other `user.*` types tell what happened.
4
+ */
5
+ declare const WEBHOOK_TYPES: readonly ["email.send_verification", "email.send_password_reset", "email.send_signin_link", "email.send_already_registered", "email.send_password_reset_no_password", "sms.send_code", "user.signing_up", "user.signed_up", "user.email_verified", "user.password_reset", "user.signed_in", "user.deleted", "user.claims_changed", "user.second_factor_enabled", "user.second_factor_disabled", "user.recovery_code_used"];
3
6
  type WebhookType = (typeof WEBHOOK_TYPES)[number];
4
7
  /** How old a call may be before receivers reject it, so a captured call can't be replayed. */
5
8
  declare const WEBHOOK_TOLERANCE_SECONDS: number;
package/dist/webhook.d.ts CHANGED
@@ -1 +1 @@
1
- export { a as WEBHOOK_TOLERANCE_SECONDS, b as WEBHOOK_TYPES, c as WebhookType, g as generateWebhookSecret, s as signWebhook, v as verifyWebhook } from './webhook-j5u9Kv9l.js';
1
+ export { a as WEBHOOK_TOLERANCE_SECONDS, b as WEBHOOK_TYPES, c as WebhookType, g as generateWebhookSecret, s as signWebhook, v as verifyWebhook } from './webhook-DlmfG_kS.js';
package/dist/webhook.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  generateWebhookSecret,
5
5
  signWebhook,
6
6
  verifyWebhook
7
- } from "./chunk-3QRKWLR7.js";
7
+ } from "./chunk-SISM7YUZ.js";
8
8
  export {
9
9
  WEBHOOK_TOLERANCE_SECONDS,
10
10
  WEBHOOK_TYPES,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@madauth/server",
3
- "version": "0.3.0-beta.2",
4
- "description": "madAuth server: Google and e-mail & password sign-in with madAuth sessions, for Docker, AWS Lambda and Azure Functions.",
3
+ "version": "0.5.0-beta.1",
4
+ "description": "madAuth server: Google, e-mail & password and authenticator-app sign-in with madAuth sessions, for Docker, AWS Lambda and Azure Functions.",
5
5
  "license": "MIT",
6
6
  "author": "David Neuy",
7
7
  "homepage": "https://github.com/inouiw/madAuth#readme",
@@ -88,6 +88,8 @@
88
88
  },
89
89
  "dependencies": {
90
90
  "@hono/node-server": "^2.1.3",
91
+ "@zxcvbn-ts/core": "4.2.0",
92
+ "@zxcvbn-ts/language-common": "4.1.3",
91
93
  "hono": "^4.13.12",
92
94
  "jose": "^6.2.12"
93
95
  },
@@ -1,62 +0,0 @@
1
- // src/store/schema.ts
2
- var madauthSchema = {
3
- version: 4,
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
- lastMailAt: { type: "number" },
15
- /** Wrong e-mail codes in a row, counted across e-mails (since version 2). */
16
- wrongCodes: { type: "number" },
17
- /** What admins attached to the user, as JSON, e.g. `{"roles":["admin"]}` (since version 4). */
18
- claims: { type: "string", nullable: true },
19
- createdAt: { type: "number" }
20
- }
21
- },
22
- /** How a user signs in. `key` is `password:<userId>` or `google:<sub>`; later e.g. `totp:<userId>`. */
23
- account: {
24
- fields: {
25
- id: { type: "string", primaryKey: true },
26
- userId: { type: "string", index: true },
27
- key: { type: "string", unique: true },
28
- secret: { type: "string", nullable: true },
29
- failedAttempts: { type: "number" },
30
- lockedUntil: { type: "number" },
31
- /** The address the provider reported at the last sign-in, e.g. Google's current primary address (since version 4). */
32
- email: { type: "string", nullable: true },
33
- createdAt: { type: "number" }
34
- }
35
- },
36
- /** A pending e-mail verification or password reset. `id` is the SHA-256 of the link token. */
37
- verification: {
38
- fields: {
39
- id: { type: "string", primaryKey: true },
40
- userId: { type: "string", index: true },
41
- purpose: { type: "string" },
42
- codeHash: { type: "string" },
43
- attempts: { type: "number" },
44
- expiresAt: { type: "number" }
45
- }
46
- },
47
- /** A setting admins change at runtime, as JSON (since version 4), e.g. `methods`: which sign-in methods are on. */
48
- setting: {
49
- fields: {
50
- id: { type: "string", primaryKey: true },
51
- value: { type: "string" },
52
- updatedAt: { type: "number" },
53
- /** The address of the admin who set it; empty when set from the command line. */
54
- updatedBy: { type: "string", nullable: true }
55
- }
56
- }
57
- }
58
- };
59
-
60
- export {
61
- madauthSchema
62
- };