@server/next 0.27.11 → 0.27.13

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 (3) hide show
  1. package/index.d.ts +4 -3
  2. package/index.js +9 -4
  3. package/package.json +2 -2
package/index.d.ts CHANGED
@@ -46,9 +46,7 @@ type KVStore = {
46
46
  name?: string;
47
47
  prefix: (key: string) => KVStore;
48
48
  get: <T = SerializableValue>(key: string) => Promise<T>;
49
- set: <T = SerializableValue>(key: string, value: T, options?: {
50
- expires: string | number;
51
- }) => Promise<void | string>;
49
+ set: <T = SerializableValue>(key: string, value: T, expires?: string | number) => Promise<void | string>;
52
50
  has: (key: string) => Promise<boolean>;
53
51
  del: (key: string) => Promise<void | string>;
54
52
  keys: () => Promise<string[]>;
@@ -84,6 +82,7 @@ type AuthSettings = {
84
82
  cleanUser: <T = AuthUser>(user: T) => T | Promise<T>;
85
83
  redirect: string;
86
84
  };
85
+ type OnError = (error: Error, ctx: Context) => Response | Promise<Response>;
87
86
  type Options = {
88
87
  port?: number;
89
88
  secret?: string;
@@ -98,6 +97,7 @@ type Options = {
98
97
  cors?: CorsOptions;
99
98
  auth?: AuthOption;
100
99
  openapi?: any;
100
+ onError?: OnError;
101
101
  };
102
102
  type Settings = {
103
103
  port: number;
@@ -113,6 +113,7 @@ type Settings = {
113
113
  cors?: CorsSettings;
114
114
  auth?: AuthSettings;
115
115
  openapi?: any;
116
+ onError?: OnError;
116
117
  };
117
118
  type Time = {
118
119
  (name: string): void;
package/index.js CHANGED
@@ -101,7 +101,7 @@ var createSession = async (user, ctx) => {
101
101
  await session2.set(
102
102
  id,
103
103
  { id, strategy, provider, user: user.email },
104
- { expires: "1w" }
104
+ "1w"
105
105
  );
106
106
  if (!strategy) throw new Error(`Invalid strategy "${strategy}"`);
107
107
  if (strategy.includes("token")) {
@@ -343,7 +343,7 @@ var callback = async (ctx) => {
343
343
  created: profile.created_at
344
344
  });
345
345
  await store.set(auth2.user, user);
346
- await session2.set(auth2.id, auth2, { expires: "1w" });
346
+ await session2.set(auth2.id, auth2, "1w");
347
347
  if (auth2.strategy.includes("token")) {
348
348
  return status(201).json({ ...user, token: auth2.id });
349
349
  }
@@ -662,6 +662,11 @@ function config(options = {}) {
662
662
  settings.openapi = {};
663
663
  }
664
664
  }
665
+ settings.onError = options.onError || ((error) => {
666
+ return new Response(error.message || "Server Error", {
667
+ status: error.status || 500
668
+ });
669
+ });
665
670
  return settings;
666
671
  }
667
672
 
@@ -973,9 +978,9 @@ async function handleRequest(handlers, ctx) {
973
978
  if (method !== "*") break;
974
979
  }
975
980
  if (ctx.platform.provider === "netlify") return;
976
- return new Response("Not Found", { status: 404 });
981
+ throw new ServerError_default("NOT_FOUND", 404, "Not Found");
977
982
  } catch (error) {
978
- return new Response(error.message || "", { status: error.status || 500 });
983
+ return ctx.options.onError(error, ctx);
979
984
  }
980
985
  }
981
986
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@server/next",
3
- "version": "0.27.11",
3
+ "version": "0.27.13",
4
4
  "description": "A fully-fledged web server with routing, file uploads, sessions, static files, schema validation, websockets, testing, etc.",
5
5
  "homepage": "https://server-js.com/",
6
6
  "repository": "https://github.com/franciscop/server-next.git",
@@ -49,7 +49,7 @@
49
49
  "@types/node": "^24.10.0",
50
50
  "check-dts": "^0.8.2",
51
51
  "jest": "^29.7.0",
52
- "polystore": "^0.14.1",
52
+ "polystore": "^0.18.0",
53
53
  "tsup": "^8.5.1",
54
54
  "typescript": "^5.9.3"
55
55
  },