@lunora/auth 1.0.0-alpha.1 → 1.0.0-alpha.100

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 (70) hide show
  1. package/LICENSE.md +38 -0
  2. package/README.md +56 -1
  3. package/__assets__/package-og.svg +1 -1
  4. package/dist/adapter.d.mts +4 -43
  5. package/dist/adapter.d.ts +4 -43
  6. package/dist/adapter.mjs +1 -47
  7. package/dist/audit.d.mts +131 -0
  8. package/dist/audit.d.ts +131 -0
  9. package/dist/audit.mjs +12 -0
  10. package/dist/email-guard.d.mts +125 -0
  11. package/dist/email-guard.d.ts +125 -0
  12. package/dist/email-guard.mjs +1 -0
  13. package/dist/index.d.mts +713 -147
  14. package/dist/index.d.ts +713 -147
  15. package/dist/index.mjs +1 -12
  16. package/dist/middleware.d.mts +157 -156
  17. package/dist/middleware.d.ts +157 -156
  18. package/dist/middleware.mjs +1 -53
  19. package/dist/packem_shared/AUTH_DO_AUDIT_PATH-D-RB2XYs.mjs +1 -0
  20. package/dist/packem_shared/DEFAULT_AUTH_BASE_PATH-DneiLGpv.mjs +1 -0
  21. package/dist/packem_shared/LunoraAuthAdminError-DtAKa22S.mjs +1 -0
  22. package/dist/packem_shared/adapter-DA8DdALX.mjs +1 -0
  23. package/dist/packem_shared/adapter.d-2a61HAY2.d.ts +76 -0
  24. package/dist/packem_shared/adapter.d-DrD3bb1u.d.mts +76 -0
  25. package/dist/packem_shared/authAuditHook-tG8gdR77.mjs +1 -0
  26. package/dist/packem_shared/authDoColumnAdditions-BCSs7qaN.mjs +1 -0
  27. package/dist/packem_shared/compileMigrationsSql-Y1YB3maO.mjs +1 -0
  28. package/dist/packem_shared/create-auth.d-De6IOirt.d.mts +128 -0
  29. package/dist/packem_shared/create-auth.d-De6IOirt.d.ts +128 -0
  30. package/dist/packem_shared/createAuth-DYFhkI1U.mjs +1 -0
  31. package/dist/packem_shared/createDoAuthWiring-C8H_SGCq.mjs +1 -0
  32. package/dist/packem_shared/createLunoraAuthClient-DhjhCwmM.mjs +1 -0
  33. package/dist/packem_shared/emailGateDatabaseHooks-CAygR3iq.mjs +1 -0
  34. package/dist/packem_shared/sessionPresets-C867Mlo4.mjs +1 -0
  35. package/dist/packem_shared/uiConfig-B8pN6pks.mjs +1 -0
  36. package/dist/plugins-client.d.mts +165 -1
  37. package/dist/plugins-client.d.ts +165 -1
  38. package/dist/plugins-client.mjs +1 -2
  39. package/dist/plugins-enterprise-client.d.mts +15 -0
  40. package/dist/plugins-enterprise-client.d.ts +15 -0
  41. package/dist/plugins-enterprise-client.mjs +1 -0
  42. package/dist/plugins-enterprise.d.mts +1670 -0
  43. package/dist/plugins-enterprise.d.ts +1670 -0
  44. package/dist/plugins-enterprise.mjs +1 -0
  45. package/dist/plugins.d.mts +102 -2
  46. package/dist/plugins.d.ts +102 -2
  47. package/dist/plugins.mjs +1 -22
  48. package/dist/schema.d.mts +39 -39
  49. package/dist/schema.d.ts +39 -39
  50. package/dist/schema.mjs +1 -62
  51. package/dist/sql-store.d.mts +28 -28
  52. package/dist/sql-store.d.ts +28 -28
  53. package/dist/sql-store.mjs +1 -162
  54. package/dist/store.d.mts +49 -31
  55. package/dist/store.d.ts +49 -31
  56. package/dist/store.mjs +1 -170
  57. package/dist/turnstile-middleware.d.mts +55 -55
  58. package/dist/turnstile-middleware.d.ts +55 -55
  59. package/dist/turnstile-middleware.mjs +1 -45
  60. package/dist/turnstile.d.mts +42 -59
  61. package/dist/turnstile.d.ts +42 -59
  62. package/dist/turnstile.mjs +1 -61
  63. package/package.json +40 -6
  64. package/dist/packem_shared/DEFAULT_AUTH_BASE_PATH-DjcUWEQl.mjs +0 -11
  65. package/dist/packem_shared/create-auth.d-M36jwG_Y.d.mts +0 -58
  66. package/dist/packem_shared/create-auth.d-M36jwG_Y.d.ts +0 -58
  67. package/dist/packem_shared/createAuth-B-tvsvQU.mjs +0 -56
  68. package/dist/packem_shared/createAuthAdmin-BxrfEeA_.mjs +0 -249
  69. package/dist/packem_shared/ensureMigrated-wZH3oXDu.mjs +0 -28
  70. package/dist/packem_shared/sessionPresets-B95rXrd8.mjs +0 -35
package/LICENSE.md CHANGED
@@ -103,3 +103,41 @@ Unless required by applicable law or agreed to in writing, software distributed
103
103
  under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
104
  CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
105
  specific language governing permissions and limitations under the License.
106
+
107
+ <!-- DEPENDENCIES -->
108
+ <!-- /DEPENDENCIES -->
109
+
110
+ <!-- TYPE_DEPENDENCIES -->
111
+
112
+ # Licenses of bundled types
113
+ The published @lunora/auth artifact additionally contains code with the following licenses:
114
+ MIT
115
+
116
+ # Bundled types:
117
+ ## @better-auth/sso
118
+ License: MIT
119
+ By: Bereket Engida
120
+ Repository: git+https://github.com/better-auth/better-auth.git
121
+
122
+ > The MIT License (MIT)
123
+ > Copyright (c) 2024 - present, Bereket Engida
124
+ >
125
+ > Permission is hereby granted, free of charge, to any person obtaining a copy of
126
+ > this software and associated documentation files (the “Software”), to deal in
127
+ > the Software without restriction, including without limitation the rights to
128
+ > use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
129
+ > the Software, and to permit persons to whom the Software is furnished to do so,
130
+ > subject to the following conditions:
131
+ >
132
+ > The above copyright notice and this permission notice shall be included in all
133
+ > copies or substantial portions of the Software.
134
+ >
135
+ > THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
136
+ > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
137
+ > FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
138
+ > IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
139
+ > DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
140
+ > ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
141
+ > DEALINGS IN THE SOFTWARE.
142
+
143
+ <!-- /TYPE_DEPENDENCIES -->
package/README.md CHANGED
@@ -84,10 +84,65 @@ The runtime resolves the inbound session and stamps `ctx.auth` on every `query`
84
84
 
85
85
  ### Plugins & CAPTCHA
86
86
 
87
- better-auth's plugin factories are re-exported from `@lunora/auth/plugins` (so you don't need better-auth's deep import paths): `admin`, `anonymous`, `bearer`, `captcha`, `createAccessControl`, `customSession`, `deviceAuthorization`, `emailOTP`, `genericOAuth`, `haveIBeenPwned`, `jwt`, `magicLink`, `mcp`, `multiSession`, `oAuthProxy`, `oidcProvider`, `oneTimeToken`, `organization`, `passkey`, `phoneNumber`, `siwe`, `twoFactor`, `username`, and `withMcpAuth`.
87
+ better-auth's plugin factories are re-exported from `@lunora/auth/plugins` (so you don't need better-auth's deep import paths): `admin`, `anonymous`, `bearer`, `captcha`, `createAccessControl`, `createMcpProtectedRequestHandler`, `customSession`, `deviceAuthorization`, `emailOTP`, `genericOAuth`, `haveIBeenPwned`, `jwt`, `lastLoginMethod`, `magicLink`, `mcp`, `multiSession`, `oAuthProxy`, `oauthDeviceAuthorization`, `oauthProvider`, `oneTap`, `oneTimeToken`, `organization`, `passkey`, `phoneNumber`, `requireMcpAuth`, `scim`, `siwe`, `twoFactor`, and `username`. Enterprise SSO ships separately as `sso` from `@lunora/auth/plugins/enterprise` (an optional peer — see the docs).
88
88
 
89
89
  For Cloudflare Turnstile on the **auth flow**, use the `captcha` plugin (`captcha({ provider: "cloudflare-turnstile", secretKey: env.TURNSTILE_SECRET_KEY })`); it reads the token from the `x-captcha-response` header. For **non-auth** procedures, the package root also exports standalone helpers — `verifyTurnstile` (pure `siteverify`) and `verifyTurnstileMiddleware` (a `.use()` middleware that takes the token from the function args).
90
90
 
91
+ ### Disposable / free-email gating
92
+
93
+ Reject throwaway/disposable signups (and branch on free-vs-business email) by reusing the visulima email lists — pure-data and **edge-safe on the default path** (no DNS). Wire it into better-auth's native signup with `withEmailGate` (or `emailGateDatabaseHooks`):
94
+
95
+ ```ts
96
+ import { createAuth, withEmailGate, lunoraD1Adapter } from "@lunora/auth";
97
+
98
+ const auth = createAuth(
99
+ withEmailGate(
100
+ { secret: env.AUTH_SECRET, database: lunoraD1Adapter(env.DB), emailAndPassword: { enabled: true } },
101
+ {
102
+ blockDisposable: true, // default — reject disposable domains with `EMAIL_DOMAIN_BLOCKED`
103
+ allowDomains: ["your-company.com"], // never blocked; always classified `business`
104
+ denyDomains: [], // extra domains to treat as disposable
105
+ // mx: true, // OPT-IN deliverability check — needs DNS (node:dns), so keep it OFF on the edge path
106
+ onClassify: (c, user) => console.log(`signup ${user.email as string}: ${c.emailClass}`),
107
+ },
108
+ ),
109
+ );
110
+ ```
111
+
112
+ A blocked signup fails with the coded error `EMAIL_DOMAIN_BLOCKED` (HTTP 400); a business/free email passes and its `emailClass` (`disposable | free | business`) is surfaced via `onClassify`. Everything is config-gated and defaults sensibly.
113
+
114
+ - **Programmatic / non-auth use:** `classifyEmail(email, config)` (sync, pure-data) and `assertEmailAllowed(email, config)` (async; throws the coded error) come from `@lunora/auth/email-guard`, plus `emailGateMiddleware({ email: (ctx) => ctx.args.email })` for a `.use()` gate on your own signup mutations.
115
+ - **Edge-safety:** on workerd, `await loadEmailDomainLists()` once at worker init (the gate helpers do this for you). The optional `mx: true` deliverability check is loaded via a dynamic import so `node:dns` never enters the default bundle — enable it only with `nodejs_compat` (or a DNS-over-HTTPS shim).
116
+
117
+ ### Security / audit trail
118
+
119
+ Record authentication & security events (sign-in, sign-up, password change, MFA enable/disable, token refresh, session revoke, …) to a durable, queryable audit trail. Install the better-auth `hooks.after` recorder with `authAuditHook` (or compose via `withAuthAudit`), backed by the same D1 database as the auth tables:
120
+
121
+ ```ts
122
+ import { authAuditHook, createAuth, d1Executor, lunoraD1Adapter, readAuthAuditLog } from "@lunora/auth";
123
+
124
+ const executor = d1Executor(env.DB);
125
+
126
+ const auth = createAuth({
127
+ secret: env.AUTH_SECRET,
128
+ database: lunoraD1Adapter(env.DB),
129
+ hooks: {
130
+ after: authAuditHook({
131
+ executor,
132
+ // retention is CONFIGURABLE and NOT capped — omit it for an unbounded, compliance-grade trail
133
+ retention: 100_000,
134
+ // optional export tap for SIEM forwarding (receives each redacted entry)
135
+ onRecord: (entry) => forwardToSiem(entry),
136
+ }),
137
+ },
138
+ });
139
+
140
+ // Query the trail (RLS/admin-gate this in your own read):
141
+ const recent = await readAuthAuditLog(executor, { event: "sign-in", limit: 100 });
142
+ ```
143
+
144
+ The free-form `detail` payload is scrubbed with `@visulima/redact` before it is persisted, so a token/password that leaks into an event's context never reaches the durable table. Retention defaults to unbounded (set `retention` to bound it). The store lives in the reserved `__lunora_auth_audit__` table (auto-hidden from the data browser).
145
+
91
146
  > This README covers the basics. For the full API, options, and guides, see the **[documentation](https://lunora.sh/docs/packages/auth)**.
92
147
 
93
148
  ## Related