@gen-epix/oidc-mock-server 0.2.0 → 0.3.0

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.
@@ -4,7 +4,6 @@ import { existsSync, readFileSync } from 'fs';
4
4
  import { OAuth2Server } from 'oauth2-mock-server';
5
5
  import basicAuth from 'basic-auth';
6
6
  import { findGitRootPath } from '@gen-epix/tools-lib';
7
- import { json, urlencoded } from 'express';
8
7
 
9
8
  const DEFAULT_PORT = 5443;
10
9
  const DEFAULT_TOKEN_TIME_OUT_SECONDS = 3600;
@@ -92,62 +91,68 @@ const start = async () => {
92
91
  scope: "openid profile email offline_access"
93
92
  };
94
93
  });
95
- const requestHandler = server.service.requestHandler;
96
- requestHandler.use(json());
97
- requestHandler.use(urlencoded({ extended: true }));
98
- requestHandler.post("/set-user", (req, res) => {
94
+ server.service.addRoute("POST", "/set-user", (req, res) => {
95
+ const jsonResponse = (statusCode, body) => {
96
+ res.writeHead(statusCode, { "Content-Type": "application/json" });
97
+ res.end(JSON.stringify(body));
98
+ };
99
99
  try {
100
100
  const updatedUser = req.body;
101
101
  if (!updatedUser || Object.keys(updatedUser).length === 0) {
102
- return res.status(400).json({
102
+ jsonResponse(400, {
103
103
  error: "Bad Request",
104
104
  message: "Request body must contain at least one user field to update"
105
105
  });
106
+ return;
106
107
  }
107
108
  if (updatedUser.email !== void 0) {
108
109
  if (typeof updatedUser.email !== "string" || !updatedUser.email.trim()) {
109
- return res.status(400).json({
110
+ jsonResponse(400, {
110
111
  error: "Bad Request",
111
112
  message: "Email must be a non-empty string"
112
113
  });
114
+ return;
113
115
  }
114
116
  user.email = updatedUser.email.trim();
115
117
  }
116
118
  if (updatedUser.sub !== void 0) {
117
119
  if (typeof updatedUser.sub !== "string" || !updatedUser.sub.trim()) {
118
- return res.status(400).json({
120
+ jsonResponse(400, {
119
121
  error: "Bad Request",
120
122
  message: "Sub must be a non-empty string"
121
123
  });
124
+ return;
122
125
  }
123
126
  user.sub = updatedUser.sub.trim();
124
127
  }
125
128
  if (updatedUser.first_name !== void 0) {
126
129
  if (typeof updatedUser.first_name !== "string" || !updatedUser.first_name.trim()) {
127
- return res.status(400).json({
130
+ jsonResponse(400, {
128
131
  error: "Bad Request",
129
132
  message: "First name must be a non-empty string"
130
133
  });
134
+ return;
131
135
  }
132
136
  user.first_name = updatedUser.first_name.trim();
133
137
  }
134
138
  if (updatedUser.last_name !== void 0) {
135
139
  if (typeof updatedUser.last_name !== "string" || !updatedUser.last_name.trim()) {
136
- return res.status(400).json({
140
+ jsonResponse(400, {
137
141
  error: "Bad Request",
138
142
  message: "Last name must be a non-empty string"
139
143
  });
144
+ return;
140
145
  }
141
146
  user.last_name = updatedUser.last_name.trim();
142
147
  }
143
148
  console.log("User updated:", user);
144
- res.status(200).json({
149
+ jsonResponse(200, {
145
150
  message: "User updated successfully",
146
151
  user: { ...user }
147
152
  });
148
153
  } catch (error) {
149
154
  console.error("Error updating user:", error);
150
- res.status(500).json({
155
+ jsonResponse(500, {
151
156
  error: "Internal Server Error",
152
157
  message: "Failed to update user"
153
158
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gen-epix/oidc-mock-server",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "license": "EUPL-1.2",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -28,7 +28,6 @@
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/basic-auth": "1.1.8",
31
- "@types/express": "5.0.6",
32
31
  "@types/node": "25.9.3",
33
32
  "eslint": "10.4.1",
34
33
  "nodemon": "3.1.14",