@madauth/server 0.1.0 → 0.2.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,16 +1,16 @@
1
1
  import { LambdaEvent, LambdaContext, handle } from 'hono/aws-lambda';
2
- import { C as ConfigOverrides } from '../config-KQvE2imU.js';
2
+ import { E as EntryOptions } from '../config-BkxADgtp.js';
3
3
  import 'jose';
4
- import '../schema-Dotc6LU7.js';
5
- import '../webhook-CT80emTQ.js';
4
+ import '../schema-BSgYVRpd.js';
5
+ import '../webhook-ltwulgcB.js';
6
6
 
7
7
  type LambdaHandler = (event: LambdaEvent, context: LambdaContext) => ReturnType<ReturnType<typeof handle>>;
8
8
  /**
9
9
  * Creates an AWS Lambda handler (Function URL, API Gateway v1/v2 or ALB). It reads the configuration from
10
10
  * the function's environment variables on the first invocation. Pass `store` to use your own store
11
- * adapter.
11
+ * adapter, and `env` to load settings from elsewhere, e.g. secrets from the Parameter Store.
12
12
  */
13
- declare function createHandler(overrides?: ConfigOverrides): LambdaHandler;
13
+ declare function createHandler(options?: EntryOptions): LambdaHandler;
14
14
  /** The handler configured only by environment variables (`lambda.handler` in the standalone bundle). */
15
15
  declare const handler: LambdaHandler;
16
16
 
@@ -1,19 +1,21 @@
1
1
  import {
2
2
  createApp
3
- } from "../chunk-TEMZRMFF.js";
4
- import "../chunk-PRRKLEW7.js";
3
+ } from "../chunk-YALS7OMV.js";
4
+ import "../chunk-7CTAB3QV.js";
5
5
  import {
6
- loadConfig
7
- } from "../chunk-V2XKGETK.js";
6
+ loadConfig,
7
+ resolveEnv
8
+ } from "../chunk-5CKEMC6M.js";
8
9
  import "../chunk-JDQLSL36.js";
9
- import "../chunk-AVZE6FFR.js";
10
+ import "../chunk-6EJDVZCD.js";
10
11
 
11
12
  // src/entry/lambda.ts
12
13
  import { handle } from "hono/aws-lambda";
13
- function createHandler(overrides = {}) {
14
+ function createHandler(options = {}) {
15
+ const { env, ...overrides } = options;
14
16
  let handlerPromise;
15
17
  return async (event, context) => {
16
- handlerPromise ??= loadConfig(process.env, overrides).then((config) => handle(createApp(config)));
18
+ handlerPromise ??= resolveEnv(env).then((loaded) => loadConfig(loaded, overrides)).then((config) => handle(createApp(config)));
17
19
  handlerPromise.catch(() => handlerPromise = void 0);
18
20
  return (await handlerPromise)(event, context);
19
21
  };
@@ -1,15 +1,12 @@
1
- import { C as ConfigOverrides } from '../config-KQvE2imU.js';
1
+ import { E as EntryOptions } from '../config-BkxADgtp.js';
2
2
  import 'jose';
3
- import '../schema-Dotc6LU7.js';
4
- import '../webhook-CT80emTQ.js';
3
+ import '../schema-BSgYVRpd.js';
4
+ import '../webhook-ltwulgcB.js';
5
5
 
6
- interface StartOptions extends ConfigOverrides {
7
- /** Environment variables to read. Default: `process.env`. */
8
- env?: Record<string, string | undefined>;
9
- }
6
+ type StartOptions = EntryOptions;
10
7
  /**
11
8
  * Starts the madAuth server on Node, listening on PORT (default 8787). Used by the Docker image.
12
- * Pass `store` to use your own store adapter.
9
+ * Pass `store` to use your own store adapter, and `env` to load settings from elsewhere than `process.env`.
13
10
  */
14
11
  declare function start(opts?: StartOptions): Promise<void>;
15
12
 
@@ -1,17 +1,19 @@
1
1
  import {
2
2
  createApp
3
- } from "../chunk-TEMZRMFF.js";
4
- import "../chunk-PRRKLEW7.js";
3
+ } from "../chunk-YALS7OMV.js";
4
+ import "../chunk-7CTAB3QV.js";
5
5
  import {
6
- loadConfig
7
- } from "../chunk-V2XKGETK.js";
6
+ loadConfig,
7
+ resolveEnv
8
+ } from "../chunk-5CKEMC6M.js";
8
9
  import "../chunk-JDQLSL36.js";
9
- import "../chunk-AVZE6FFR.js";
10
+ import "../chunk-6EJDVZCD.js";
10
11
 
11
12
  // src/entry/node.ts
12
13
  import { serve } from "@hono/node-server";
13
14
  async function start(opts = {}) {
14
- const { env = process.env, ...overrides } = opts;
15
+ const { env: source, ...overrides } = opts;
16
+ const env = await resolveEnv(source);
15
17
  const config = await loadConfig(env, overrides);
16
18
  const port = Number(env.PORT?.trim() || 8787);
17
19
  serve({ fetch: createApp(config).fetch, port });
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { Hono } from 'hono';
2
- import { M as MadauthConfig } from './config-KQvE2imU.js';
3
- export { a as ConfigError, C as ConfigOverrides, e as envVars, l as loadConfig } from './config-KQvE2imU.js';
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';
4
4
  import { JWK } from 'jose';
5
- import { a as Schema } from './schema-Dotc6LU7.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-Dotc6LU7.js';
7
- export { M as MadauthUser } from './user-3DDyggFV.js';
8
- import './webhook-CT80emTQ.js';
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';
9
9
 
10
10
  /** Creates a new private ES256 JWK for MADAUTH_SIGNING_KEY. */
11
11
  declare function generateSigningKey(): Promise<JWK>;
@@ -24,7 +24,12 @@ declare function tableName(model: string): string;
24
24
  /** The SQL column that holds a field, e.g. `email_normalized` for `emailNormalized`. */
25
25
  declare function columnName(field: string): string;
26
26
  type SqlDialect = 'sqlite' | 'postgres' | 'mysql';
27
+ /**
28
+ * The SQL that brings tables created for schema version `fromVersion` up to date. Empty if they are.
29
+ * Run it before you start the madAuth version that needs it; older madAuth versions ignore the additions.
30
+ */
31
+ declare function upgradeTablesSql(dialect: SqlDialect, fromVersion: number): string;
27
32
  /** The SQL that creates madAuth's tables and indexes in an empty database. */
28
33
  declare function createTablesSql(dialect: SqlDialect, schema?: Schema): string;
29
34
 
30
- export { MadauthConfig, REDIRECT_ERROR_PARAM, Schema, type SqlDialect, columnName, createApp, createTablesSql, generateSigningKey, tableName };
35
+ export { MadauthConfig, REDIRECT_ERROR_PARAM, Schema, type SqlDialect, columnName, createApp, createTablesSql, generateSigningKey, tableName, upgradeTablesSql };
package/dist/index.js CHANGED
@@ -1,23 +1,26 @@
1
1
  import {
2
2
  columnName,
3
3
  createTablesSql,
4
- madauthSchema,
5
- tableName
6
- } from "./chunk-3WIWWKRI.js";
4
+ tableName,
5
+ upgradeTablesSql
6
+ } from "./chunk-CNL562LZ.js";
7
+ import {
8
+ madauthSchema
9
+ } from "./chunk-XNBWZZHT.js";
7
10
  import {
8
11
  REDIRECT_ERROR_PARAM,
9
12
  createApp
10
- } from "./chunk-TEMZRMFF.js";
11
- import "./chunk-PRRKLEW7.js";
13
+ } from "./chunk-YALS7OMV.js";
14
+ import "./chunk-7CTAB3QV.js";
12
15
  import {
13
16
  ConfigError,
14
17
  envVars,
15
18
  loadConfig
16
- } from "./chunk-V2XKGETK.js";
19
+ } from "./chunk-5CKEMC6M.js";
17
20
  import {
18
21
  generateSigningKey
19
22
  } from "./chunk-JDQLSL36.js";
20
- import "./chunk-AVZE6FFR.js";
23
+ import "./chunk-6EJDVZCD.js";
21
24
  export {
22
25
  ConfigError,
23
26
  REDIRECT_ERROR_PARAM,
@@ -28,5 +31,6 @@ export {
28
31
  generateSigningKey,
29
32
  loadConfig,
30
33
  madauthSchema,
31
- tableName
34
+ tableName,
35
+ upgradeTablesSql
32
36
  };
@@ -43,7 +43,7 @@ interface Schema {
43
43
  }
44
44
  /** The records madAuth stores. Timestamps are milliseconds since 1970. */
45
45
  declare const madauthSchema: {
46
- readonly version: 1;
46
+ readonly version: 3;
47
47
  readonly models: {
48
48
  readonly user: {
49
49
  readonly fields: {
@@ -71,6 +71,10 @@ declare const madauthSchema: {
71
71
  readonly lastMailAt: {
72
72
  readonly type: "number";
73
73
  };
74
+ /** Wrong e-mail codes in a row, counted across e-mails (since version 2). */
75
+ readonly wrongCodes: {
76
+ readonly type: "number";
77
+ };
74
78
  readonly createdAt: {
75
79
  readonly type: "number";
76
80
  };
@@ -131,6 +135,29 @@ declare const madauthSchema: {
131
135
  };
132
136
  };
133
137
  };
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: {
143
+ readonly fields: {
144
+ readonly id: {
145
+ readonly type: "string";
146
+ readonly primaryKey: true;
147
+ };
148
+ readonly roles: {
149
+ readonly type: "string";
150
+ };
151
+ readonly updatedAt: {
152
+ readonly type: "number";
153
+ };
154
+ /** The address of the admin who set them; empty when set from the command line. */
155
+ readonly updatedBy: {
156
+ readonly type: "string";
157
+ readonly nullable: true;
158
+ };
159
+ };
160
+ };
134
161
  };
135
162
  };
136
163
 
package/dist/sqlite.js CHANGED
@@ -1,9 +1,12 @@
1
1
  import {
2
2
  columnName,
3
3
  createTablesSql,
4
- madauthSchema,
5
- tableName
6
- } from "./chunk-3WIWWKRI.js";
4
+ tableName,
5
+ upgradeTablesSql
6
+ } from "./chunk-CNL562LZ.js";
7
+ import {
8
+ madauthSchema
9
+ } from "./chunk-XNBWZZHT.js";
7
10
 
8
11
  // src/store/sqlite.ts
9
12
  function createSqliteAdapter(path) {
@@ -87,7 +90,7 @@ function migrate(db) {
87
90
  if (version === madauthSchema.version) return;
88
91
  db.exec("BEGIN");
89
92
  try {
90
- db.exec(createTablesSql("sqlite"));
93
+ db.exec(version === 0 ? createTablesSql("sqlite") : upgradeTablesSql("sqlite", version));
91
94
  db.exec(`PRAGMA user_version = ${madauthSchema.version}`);
92
95
  db.exec("COMMIT");
93
96
  } catch (e) {