@lunora/auth 1.0.0-alpha.14 → 1.0.0-alpha.16

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.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { lunoraAuthAdapter, lunoraD1Adapter } from "./adapter.mjs";
2
+ import { LunoraError } from '@lunora/errors';
2
3
  import { L as LunoraAuth, a as LunoraAuthOptions } from "./packem_shared/create-auth.d-Mwhb4gSc.mjs";
3
4
  export { c as createAuth, r as resolveAuthOptions } from "./packem_shared/create-auth.d-Mwhb4gSc.mjs";
4
5
  export { type LunoraAuthApiContext, LunoraAuthHeadersError, type WithAuthPluginsMiddleware, type WithAuthPluginsOptions, withAuthPlugins } from "./middleware.mjs";
@@ -271,8 +272,7 @@ interface CreateAuthAdminOptions {
271
272
  * surface that `code` so the runtime can map it onto an HTTP status and the
272
273
  * studio can show a meaningful message instead of a generic 500.
273
274
  */
274
- declare class LunoraAuthAdminError extends Error {
275
- readonly code: string;
275
+ declare class LunoraAuthAdminError extends LunoraError {
276
276
  constructor(message: string, code: string);
277
277
  }
278
278
  /**
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { lunoraAuthAdapter, lunoraD1Adapter } from "./adapter.js";
2
+ import { LunoraError } from '@lunora/errors';
2
3
  import { L as LunoraAuth, a as LunoraAuthOptions } from "./packem_shared/create-auth.d-Mwhb4gSc.js";
3
4
  export { c as createAuth, r as resolveAuthOptions } from "./packem_shared/create-auth.d-Mwhb4gSc.js";
4
5
  export { type LunoraAuthApiContext, LunoraAuthHeadersError, type WithAuthPluginsMiddleware, type WithAuthPluginsOptions, withAuthPlugins } from "./middleware.js";
@@ -271,8 +272,7 @@ interface CreateAuthAdminOptions {
271
272
  * surface that `code` so the runtime can map it onto an HTTP status and the
272
273
  * studio can show a meaningful message instead of a generic 500.
273
274
  */
274
- declare class LunoraAuthAdminError extends Error {
275
- readonly code: string;
275
+ declare class LunoraAuthAdminError extends LunoraError {
276
276
  constructor(message: string, code: string);
277
277
  }
278
278
  /**
package/dist/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  export { lunoraAuthAdapter, lunoraD1Adapter } from './adapter.mjs';
2
- export { LunoraAuthAdminError, createAuthAdmin } from './packem_shared/LunoraAuthAdminError-BxrfEeA_.mjs';
3
- export { createAuth, resolveAuthOptions } from './packem_shared/createAuth-hRGxUJ9w.mjs';
2
+ export { LunoraAuthAdminError, createAuthAdmin } from './packem_shared/LunoraAuthAdminError-BpVImgEy.mjs';
3
+ export { createAuth, resolveAuthOptions } from './packem_shared/createAuth-BVMMllTm.mjs';
4
4
  export { DEFAULT_AUTH_BASE_PATH, handleAuthRequest } from './packem_shared/DEFAULT_AUTH_BASE_PATH-DjcUWEQl.mjs';
5
5
  export { LunoraAuthHeadersError, withAuthPlugins } from './middleware.mjs';
6
- export { compileMigrationsSql, ensureMigrated } from './packem_shared/compileMigrationsSql-cyE5U18R.mjs';
6
+ export { compileMigrationsSql, ensureMigrated } from './packem_shared/compileMigrationsSql-B9bj-mJv.mjs';
7
7
  export { default as authTables } from './schema.mjs';
8
8
  export { sessionPresets, validateSessionPolicy } from './packem_shared/sessionPresets-Dwwd74_J.mjs';
9
9
  export { createSqlAuthStore, d1Executor } from './sql-store.mjs';
@@ -1,3 +1,4 @@
1
+ import { LunoraError } from '@lunora/errors';
1
2
  import { L as LunoraAuth } from "./packem_shared/create-auth.d-Mwhb4gSc.mjs";
2
3
  import 'better-auth';
3
4
  /**
@@ -22,7 +23,7 @@ interface MiddlewareNext<ContextIn> {
22
23
  * advisor lint — both treat a header-less `ctx.authApi.*` call as an
23
24
  * authorization bypass, so a call that trips the lint also trips this guard.
24
25
  */
25
- declare class LunoraAuthHeadersError extends Error {
26
+ declare class LunoraAuthHeadersError extends LunoraError {
26
27
  /** The `ctx.authApi.&lt;method>` that was called without `headers`. */
27
28
  readonly method: string;
28
29
  constructor(method: string);
@@ -1,3 +1,4 @@
1
+ import { LunoraError } from '@lunora/errors';
1
2
  import { L as LunoraAuth } from "./packem_shared/create-auth.d-Mwhb4gSc.js";
2
3
  import 'better-auth';
3
4
  /**
@@ -22,7 +23,7 @@ interface MiddlewareNext<ContextIn> {
22
23
  * advisor lint — both treat a header-less `ctx.authApi.*` call as an
23
24
  * authorization bypass, so a call that trips the lint also trips this guard.
24
25
  */
25
- declare class LunoraAuthHeadersError extends Error {
26
+ declare class LunoraAuthHeadersError extends LunoraError {
26
27
  /** The `ctx.authApi.&lt;method>` that was called without `headers`. */
27
28
  readonly method: string;
28
29
  constructor(method: string);
@@ -1,3 +1,5 @@
1
+ import { LunoraError } from '@lunora/errors';
2
+
1
3
  const callHasHeaders = (argument) => {
2
4
  if (argument === void 0) {
3
5
  return false;
@@ -30,14 +32,15 @@ const guardAuthApi = (api) => {
30
32
  }
31
33
  });
32
34
  };
33
- class LunoraAuthHeadersError extends Error {
35
+ class LunoraAuthHeadersError extends LunoraError {
34
36
  /** The `ctx.authApi.&lt;method>` that was called without `headers`. */
35
37
  method;
36
38
  constructor(method) {
37
39
  super(
38
- `@lunora/auth: ctx.authApi.${method}(…) was called without \`headers\`. better-auth treats a header-less call as a trusted server-to-server invocation and skips session authorization entirely — an authorization bypass. Pass the inbound request headers: ctx.authApi.${method}({ body, headers: request.headers }). If you genuinely intend an unauthenticated server-to-server call, opt out explicitly via ctx.authApi.withoutHeaders().<method>(…), or disable the guard for the whole middleware with withAuthPlugins(auth, { enforceHeaders: false }).`
40
+ "AUTH_HEADERS_MISSING",
41
+ `@lunora/auth: ctx.authApi.${method}(…) was called without \`headers\`. better-auth treats a header-less call as a trusted server-to-server invocation and skips session authorization entirely — an authorization bypass. Pass the inbound request headers: ctx.authApi.${method}({ body, headers: request.headers }). If you genuinely intend an unauthenticated server-to-server call, opt out explicitly via ctx.authApi.withoutHeaders().<method>(…), or disable the guard for the whole middleware with withAuthPlugins(auth, { enforceHeaders: false }).`,
42
+ { name: "LunoraAuthHeadersError" }
39
43
  );
40
- this.name = "LunoraAuthHeadersError";
41
44
  this.method = method;
42
45
  }
43
46
  }
@@ -1,9 +1,8 @@
1
- class LunoraAuthAdminError extends Error {
2
- code;
1
+ import { LunoraError } from '@lunora/errors';
2
+
3
+ class LunoraAuthAdminError extends LunoraError {
3
4
  constructor(message, code) {
4
- super(message);
5
- this.name = "LunoraAuthAdminError";
6
- this.code = code;
5
+ super(code, message, { name: "LunoraAuthAdminError" });
7
6
  }
8
7
  }
9
8
  const DEFAULT_LIMIT = 50;
@@ -1,5 +1,5 @@
1
1
  import { getMigrations } from 'better-auth/db/migration';
2
- import { resolveAuthOptions } from './createAuth-hRGxUJ9w.mjs';
2
+ import { resolveAuthOptions } from './createAuth-BVMMllTm.mjs';
3
3
 
4
4
  const migrating = /* @__PURE__ */ new WeakMap();
5
5
  const ensureMigrated = async (auth) => {
@@ -1,3 +1,4 @@
1
+ import { LunoraError } from '@lunora/errors';
1
2
  import { betterAuth } from 'better-auth';
2
3
  import { validateSessionPolicy } from './sessionPresets-Dwwd74_J.mjs';
3
4
 
@@ -23,7 +24,7 @@ const isHttpsBaseUrl = (baseURL) => {
23
24
  };
24
25
  const isExplicitHttpBaseUrl = (baseURL) => {
25
26
  if (typeof baseURL === "string") {
26
- return baseURL.startsWith("http://");
27
+ return baseURL.toLowerCase().startsWith("http://");
27
28
  }
28
29
  if (baseURL && typeof baseURL === "object") {
29
30
  if (baseURL.protocol === "http") {
@@ -32,7 +33,7 @@ const isExplicitHttpBaseUrl = (baseURL) => {
32
33
  if (baseURL.protocol === "https") {
33
34
  return false;
34
35
  }
35
- return typeof baseURL.fallback === "string" && baseURL.fallback.startsWith("http://");
36
+ return typeof baseURL.fallback === "string" && baseURL.fallback.toLowerCase().startsWith("http://");
36
37
  }
37
38
  return false;
38
39
  };
@@ -40,7 +41,7 @@ const hardenAuthOptions = (options) => {
40
41
  if (isWeakSecret(options.secret)) {
41
42
  const message = `@lunora/auth: AUTH_SECRET is only ${String(options.secret?.trim().length)} characters. Use at least ${String(MIN_SECRET_LENGTH)} for a brute-force-resistant secret — generate one with \`openssl rand -hex 32\`.`;
42
43
  if (isHttpsBaseUrl(options.baseURL)) {
43
- throw new Error(message);
44
+ throw new LunoraError("INTERNAL", message);
44
45
  }
45
46
  console.warn(message);
46
47
  }
@@ -72,7 +73,8 @@ const resolveAuthOptions = (options) => {
72
73
  };
73
74
  const createAuth = (options) => {
74
75
  if (!options.secret || options.secret.trim() === "") {
75
- throw new Error(
76
+ throw new LunoraError(
77
+ "INTERNAL",
76
78
  '@lunora/auth: `secret` is required. Set AUTH_SECRET locally in .dev.vars (`lunora env set AUTH_SECRET "$(openssl rand -hex 32)"`), and in production with `wrangler secret put AUTH_SECRET`.'
77
79
  );
78
80
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/auth",
3
- "version": "1.0.0-alpha.14",
3
+ "version": "1.0.0-alpha.16",
4
4
  "description": "Auth for Lunora — a thin better-auth wrapper: email/password, OAuth, plugins, D1-backed",
5
5
  "keywords": [
6
6
  "auth",
@@ -83,8 +83,9 @@
83
83
  },
84
84
  "dependencies": {
85
85
  "@better-auth/passkey": "^1.6.22",
86
- "@lunora/server": "1.0.0-alpha.13",
87
- "@lunora/values": "1.0.0-alpha.3",
86
+ "@lunora/errors": "1.0.0-alpha.1",
87
+ "@lunora/server": "1.0.0-alpha.14",
88
+ "@lunora/values": "1.0.0-alpha.4",
88
89
  "better-auth": "^1.6.22"
89
90
  },
90
91
  "engines": {