@madauth/server 0.2.0-beta.2 → 0.3.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.
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  createApp
3
- } from "../chunk-YALS7OMV.js";
4
- import "../chunk-7CTAB3QV.js";
3
+ } from "../chunk-ZSBKNV5W.js";
4
+ import "../chunk-DCDTO5LG.js";
5
5
  import {
6
6
  loadConfig,
7
7
  resolveEnv
8
- } from "../chunk-5CKEMC6M.js";
8
+ } from "../chunk-ODITZLMM.js";
9
9
  import "../chunk-JDQLSL36.js";
10
- import "../chunk-6EJDVZCD.js";
10
+ import "../chunk-NPNM26J3.js";
11
11
 
12
12
  // src/entry/node.ts
13
13
  import { serve } from "@hono/node-server";
package/dist/index.d.ts CHANGED
@@ -1,15 +1,21 @@
1
1
  import { Hono } from 'hono';
2
- import { M as MadauthConfig } from './config-BkxADgtp.js';
3
- export { C as ConfigError, a as ConfigOverrides, E as EntryOptions, e as envVars, l as loadConfig } from './config-BkxADgtp.js';
2
+ import { M as MadauthConfig } from './config-DEBYi8hb.js';
3
+ export { C as ConfigError, a as ConfigOverrides, E as EntryOptions, e as envVars, l as loadConfig } from './config-DEBYi8hb.js';
4
4
  import { JWK } from 'jose';
5
- import { a as Schema } from './schema-BSgYVRpd.js';
6
- export { F as FieldDef, b as FieldType, R as Row, S as StoreAdapter, V as Value, W as Where, m as madauthSchema } from './schema-BSgYVRpd.js';
7
- export { M as MadauthUser } from './user-C1A3BfOo.js';
8
- import './webhook-ltwulgcB.js';
5
+ import { a as Schema } from './schema-3yhCc2jH.js';
6
+ export { F as FieldDef, b as FieldType, R as Row, S as StoreAdapter, V as Value, W as Where, m as madauthSchema } from './schema-3yhCc2jH.js';
7
+ export { M as MadauthUser } from './user-BMWEWREH.js';
8
+ import './webhook-DCDP6SaE.js';
9
9
 
10
10
  /** Creates a new private ES256 JWK for MADAUTH_SIGNING_KEY. */
11
11
  declare function generateSigningKey(): Promise<JWK>;
12
12
 
13
+ /** The sign-in methods madAuth has. */
14
+ declare const SIGN_IN_METHODS: readonly ["google", "password"];
15
+ type SignInMethod = (typeof SIGN_IN_METHODS)[number];
16
+ /** Which sign-in methods are on. A method that is not mentioned is on. */
17
+ type MethodSettings = Partial<Record<SignInMethod, boolean>>;
18
+
13
19
  /** Hash parameter that carries a sign-in error back to the app after the code flow. */
14
20
  declare const REDIRECT_ERROR_PARAM = "madauth_error";
15
21
 
@@ -32,4 +38,21 @@ declare function upgradeTablesSql(dialect: SqlDialect, fromVersion: number): str
32
38
  /** The SQL that creates madAuth's tables and indexes in an empty database. */
33
39
  declare function createTablesSql(dialect: SqlDialect, schema?: Schema): string;
34
40
 
35
- export { MadauthConfig, REDIRECT_ERROR_PARAM, Schema, type SqlDialect, columnName, createApp, createTablesSql, generateSigningKey, tableName, upgradeTablesSql };
41
+ /** A user's claims: a JSON object. */
42
+ type Claims = Record<string, unknown>;
43
+ /** The role that may manage claims and settings through the HTTP API. */
44
+ declare const ADMIN_ROLE = "admin";
45
+ /**
46
+ * Checks role names and returns them sorted and without duplicates, or null if `input` is not a list of
47
+ * valid names: lower-case letters, digits, `-` and `_`, starting with a letter, at most 32 characters.
48
+ */
49
+ declare function parseRoles(input: unknown): string[] | null;
50
+ /**
51
+ * Checks a claims object and returns it in canonical form (keys sorted, `roles` sorted and without
52
+ * duplicates), or null if `input` is not one: a JSON object whose keys are names (letters, digits and `_`,
53
+ * starting with a letter, at most 64 characters), whose `roles`, if any, is a valid list of role names,
54
+ * and which is at most {@link MAX_CLAIMS_LENGTH} characters as JSON.
55
+ */
56
+ declare function parseClaims(input: unknown): Claims | null;
57
+
58
+ export { ADMIN_ROLE, type Claims, MadauthConfig, type MethodSettings, REDIRECT_ERROR_PARAM, SIGN_IN_METHODS, Schema, type SignInMethod, type SqlDialect, columnName, createApp, createTablesSql, generateSigningKey, parseClaims, parseRoles, tableName, upgradeTablesSql };
package/dist/index.js CHANGED
@@ -3,27 +3,33 @@ import {
3
3
  createTablesSql,
4
4
  tableName,
5
5
  upgradeTablesSql
6
- } from "./chunk-CNL562LZ.js";
6
+ } from "./chunk-56MOVFO4.js";
7
7
  import {
8
8
  madauthSchema
9
- } from "./chunk-XNBWZZHT.js";
9
+ } from "./chunk-CD7Y4T66.js";
10
10
  import {
11
11
  REDIRECT_ERROR_PARAM,
12
12
  createApp
13
- } from "./chunk-YALS7OMV.js";
14
- import "./chunk-7CTAB3QV.js";
13
+ } from "./chunk-ZSBKNV5W.js";
14
+ import "./chunk-DCDTO5LG.js";
15
15
  import {
16
+ ADMIN_ROLE,
16
17
  ConfigError,
18
+ SIGN_IN_METHODS,
17
19
  envVars,
18
- loadConfig
19
- } from "./chunk-5CKEMC6M.js";
20
+ loadConfig,
21
+ parseClaims,
22
+ parseRoles
23
+ } from "./chunk-ODITZLMM.js";
20
24
  import {
21
25
  generateSigningKey
22
26
  } from "./chunk-JDQLSL36.js";
23
- import "./chunk-6EJDVZCD.js";
27
+ import "./chunk-NPNM26J3.js";
24
28
  export {
29
+ ADMIN_ROLE,
25
30
  ConfigError,
26
31
  REDIRECT_ERROR_PARAM,
32
+ SIGN_IN_METHODS,
27
33
  columnName,
28
34
  createApp,
29
35
  createTablesSql,
@@ -31,6 +37,8 @@ export {
31
37
  generateSigningKey,
32
38
  loadConfig,
33
39
  madauthSchema,
40
+ parseClaims,
41
+ parseRoles,
34
42
  tableName,
35
43
  upgradeTablesSql
36
44
  };
@@ -43,8 +43,9 @@ interface Schema {
43
43
  }
44
44
  /** The records madAuth stores. Timestamps are milliseconds since 1970. */
45
45
  declare const madauthSchema: {
46
- readonly version: 3;
46
+ readonly version: 4;
47
47
  readonly models: {
48
+ /** Someone who signed in, whichever way: the e-mail address is the identity shared by the sign-in methods. */
48
49
  readonly user: {
49
50
  readonly fields: {
50
51
  readonly id: {
@@ -75,12 +76,17 @@ declare const madauthSchema: {
75
76
  readonly wrongCodes: {
76
77
  readonly type: "number";
77
78
  };
79
+ /** What admins attached to the user, as JSON, e.g. `{"roles":["admin"]}` (since version 4). */
80
+ readonly claims: {
81
+ readonly type: "string";
82
+ readonly nullable: true;
83
+ };
78
84
  readonly createdAt: {
79
85
  readonly type: "number";
80
86
  };
81
87
  };
82
88
  };
83
- /** How a user signs in. `key` is e.g. `password:<userId>`; later `google:<sub>` or `totp:<userId>`. */
89
+ /** How a user signs in. `key` is `password:<userId>` or `google:<sub>`; later e.g. `totp:<userId>`. */
84
90
  readonly account: {
85
91
  readonly fields: {
86
92
  readonly id: {
@@ -105,6 +111,11 @@ declare const madauthSchema: {
105
111
  readonly lockedUntil: {
106
112
  readonly type: "number";
107
113
  };
114
+ /** The address the provider reported at the last sign-in, e.g. Google's current primary address (since version 4). */
115
+ readonly email: {
116
+ readonly type: "string";
117
+ readonly nullable: true;
118
+ };
108
119
  readonly createdAt: {
109
120
  readonly type: "number";
110
121
  };
@@ -135,23 +146,20 @@ declare const madauthSchema: {
135
146
  };
136
147
  };
137
148
  };
138
- /**
139
- * The roles of an e-mail address (since version 3). `id` is the normalized address, so the roles
140
- * apply whichever way its owner signs in. `roles` holds the names separated by spaces.
141
- */
142
- readonly role: {
149
+ /** A setting admins change at runtime, as JSON (since version 4), e.g. `methods`: which sign-in methods are on. */
150
+ readonly setting: {
143
151
  readonly fields: {
144
152
  readonly id: {
145
153
  readonly type: "string";
146
154
  readonly primaryKey: true;
147
155
  };
148
- readonly roles: {
156
+ readonly value: {
149
157
  readonly type: "string";
150
158
  };
151
159
  readonly updatedAt: {
152
160
  readonly type: "number";
153
161
  };
154
- /** The address of the admin who set them; empty when set from the command line. */
162
+ /** The address of the admin who set it; empty when set from the command line. */
155
163
  readonly updatedBy: {
156
164
  readonly type: "string";
157
165
  readonly nullable: true;
package/dist/sqlite.js CHANGED
@@ -3,10 +3,10 @@ import {
3
3
  createTablesSql,
4
4
  tableName,
5
5
  upgradeTablesSql
6
- } from "./chunk-CNL562LZ.js";
6
+ } from "./chunk-56MOVFO4.js";
7
7
  import {
8
8
  madauthSchema
9
- } from "./chunk-XNBWZZHT.js";
9
+ } from "./chunk-CD7Y4T66.js";
10
10
 
11
11
  // src/store/sqlite.ts
12
12
  function createSqliteAdapter(path) {