@vereign/core 1.6.1 → 1.7.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.
- package/dist/{index.mjs → index.cjs} +92 -25
- package/dist/{index.d.mts → index.d.cts} +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +67 -57
- package/package.json +7 -6
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
1
3
|
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
6
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
3
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
9
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
10
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -14,6 +19,27 @@ var __spreadValues = (a, b) => {
|
|
|
14
19
|
}
|
|
15
20
|
return a;
|
|
16
21
|
};
|
|
22
|
+
var __export = (target, all) => {
|
|
23
|
+
for (var name in all)
|
|
24
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
25
|
+
};
|
|
26
|
+
var __copyProps = (to, from, except, desc) => {
|
|
27
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
28
|
+
for (let key of __getOwnPropNames(from))
|
|
29
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
30
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
31
|
+
}
|
|
32
|
+
return to;
|
|
33
|
+
};
|
|
34
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
35
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
36
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
37
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
38
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
39
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
40
|
+
mod
|
|
41
|
+
));
|
|
42
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
17
43
|
var __async = (__this, __arguments, generator) => {
|
|
18
44
|
return new Promise((resolve, reject) => {
|
|
19
45
|
var fulfilled = (value) => {
|
|
@@ -36,10 +62,15 @@ var __async = (__this, __arguments, generator) => {
|
|
|
36
62
|
};
|
|
37
63
|
|
|
38
64
|
// src/index.ts
|
|
39
|
-
|
|
65
|
+
var index_exports = {};
|
|
66
|
+
__export(index_exports, {
|
|
67
|
+
App: () => App
|
|
68
|
+
});
|
|
69
|
+
module.exports = __toCommonJS(index_exports);
|
|
70
|
+
var import_express3 = __toESM(require("express"), 1);
|
|
40
71
|
|
|
41
72
|
// src/health/router.ts
|
|
42
|
-
|
|
73
|
+
var import_express = __toESM(require("express"), 1);
|
|
43
74
|
|
|
44
75
|
// src/health/controller.ts
|
|
45
76
|
var HealthController = class {
|
|
@@ -56,7 +87,7 @@ var HealthController = class {
|
|
|
56
87
|
// src/health/router.ts
|
|
57
88
|
var HealthRouter = class {
|
|
58
89
|
static getRouter(logger, appVersion) {
|
|
59
|
-
const router =
|
|
90
|
+
const router = import_express.default.Router();
|
|
60
91
|
const controller = new HealthController(logger, appVersion);
|
|
61
92
|
router.get("/health", controller.check);
|
|
62
93
|
return router;
|
|
@@ -64,14 +95,14 @@ var HealthRouter = class {
|
|
|
64
95
|
};
|
|
65
96
|
|
|
66
97
|
// src/chmed16/router.ts
|
|
67
|
-
|
|
98
|
+
var import_express2 = __toESM(require("express"), 1);
|
|
68
99
|
|
|
69
100
|
// src/chmed16/controller.ts
|
|
70
|
-
|
|
71
|
-
|
|
101
|
+
var import_chmed_parser = require("@vereign/chmed-parser");
|
|
102
|
+
var import_pdf_generator = require("@vereign/pdf-generator");
|
|
72
103
|
|
|
73
104
|
// src/app-error.ts
|
|
74
|
-
|
|
105
|
+
var z = __toESM(require("zod/v4"), 1);
|
|
75
106
|
var AppError = class extends Error {
|
|
76
107
|
constructor(status, message, code, details) {
|
|
77
108
|
super(message);
|
|
@@ -102,7 +133,7 @@ var appErrorSchema = z.object({
|
|
|
102
133
|
|
|
103
134
|
// src/chmed16/controller.ts
|
|
104
135
|
var CHMED16AController = class {
|
|
105
|
-
constructor(logger) {
|
|
136
|
+
constructor(logger, appVersion, clientId) {
|
|
106
137
|
this.process = (req, res, next) => __async(this, null, function* () {
|
|
107
138
|
const { chmed, lang } = req.body;
|
|
108
139
|
const token = req.token;
|
|
@@ -117,8 +148,13 @@ var CHMED16AController = class {
|
|
|
117
148
|
}
|
|
118
149
|
});
|
|
119
150
|
this.logger = logger;
|
|
120
|
-
this.sds = new SDS(
|
|
121
|
-
|
|
151
|
+
this.sds = new import_chmed_parser.SDS(
|
|
152
|
+
"https://oauth2.sds.hin.ch",
|
|
153
|
+
logger,
|
|
154
|
+
appVersion,
|
|
155
|
+
clientId
|
|
156
|
+
);
|
|
157
|
+
this.parser = new import_chmed_parser.CHMEDParser(logger);
|
|
122
158
|
}
|
|
123
159
|
parseChmedData(chmed, token, lang) {
|
|
124
160
|
return __async(this, null, function* () {
|
|
@@ -130,7 +166,7 @@ var CHMED16AController = class {
|
|
|
130
166
|
return json;
|
|
131
167
|
} catch (error) {
|
|
132
168
|
this.logger.error("Parsing failed:", error);
|
|
133
|
-
if (error instanceof ConformanceError) {
|
|
169
|
+
if (error instanceof import_chmed_parser.ConformanceError) {
|
|
134
170
|
throw new AppError(
|
|
135
171
|
400,
|
|
136
172
|
"CHMED data does not conform to required standards.",
|
|
@@ -138,6 +174,32 @@ var CHMED16AController = class {
|
|
|
138
174
|
error.validationErrors
|
|
139
175
|
);
|
|
140
176
|
}
|
|
177
|
+
if (error instanceof import_chmed_parser.UpgradeError) {
|
|
178
|
+
throw new AppError(426, "Upgrade required.", "UPGRADE_ERROR");
|
|
179
|
+
}
|
|
180
|
+
if (error instanceof import_chmed_parser.DoctorNotFoundError) {
|
|
181
|
+
throw new AppError(400, "Failed to fetch doctor by gln", "NOT_FOUND", [
|
|
182
|
+
{
|
|
183
|
+
path: "chmed",
|
|
184
|
+
message: error.message,
|
|
185
|
+
code: "doctor_not_found"
|
|
186
|
+
}
|
|
187
|
+
]);
|
|
188
|
+
}
|
|
189
|
+
if (error instanceof import_chmed_parser.UnauthorizedError) {
|
|
190
|
+
throw new AppError(
|
|
191
|
+
401,
|
|
192
|
+
"Unauthorized access. Check the bearer token.",
|
|
193
|
+
"UNAUTHORIZED_ERROR",
|
|
194
|
+
[
|
|
195
|
+
{
|
|
196
|
+
path: "chmed",
|
|
197
|
+
message: error.message,
|
|
198
|
+
code: "unauthorized_access"
|
|
199
|
+
}
|
|
200
|
+
]
|
|
201
|
+
);
|
|
202
|
+
}
|
|
141
203
|
throw new AppError(
|
|
142
204
|
400,
|
|
143
205
|
"Failed to parse CHMED data. Please check the input format.",
|
|
@@ -157,7 +219,7 @@ var CHMED16AController = class {
|
|
|
157
219
|
return __async(this, null, function* () {
|
|
158
220
|
const pdfStart = Date.now();
|
|
159
221
|
try {
|
|
160
|
-
const pdf = new PDFLib(this.logger);
|
|
222
|
+
const pdf = new import_pdf_generator.PDFLib(this.logger);
|
|
161
223
|
const pdfBuffer = yield pdf.generateBuffer(json);
|
|
162
224
|
res.setHeader("Content-Type", "application/pdf");
|
|
163
225
|
res.setHeader("Content-Disposition", 'inline; filename="chmed16a.pdf"');
|
|
@@ -183,10 +245,10 @@ var CHMED16AController = class {
|
|
|
183
245
|
};
|
|
184
246
|
|
|
185
247
|
// src/chmed16/middleware.ts
|
|
186
|
-
|
|
248
|
+
var import_zod = require("zod");
|
|
187
249
|
|
|
188
250
|
// src/chmed16/request.ts
|
|
189
|
-
|
|
251
|
+
var z2 = __toESM(require("zod/v4"), 1);
|
|
190
252
|
var chmedPattern = /^CHMED[0-9A-Za-z]+/;
|
|
191
253
|
var bodySchema = z2.object({
|
|
192
254
|
chmed: z2.string().min(5, "string is required").refine(
|
|
@@ -217,7 +279,7 @@ var validateBody = (logger) => {
|
|
|
217
279
|
next();
|
|
218
280
|
} catch (e) {
|
|
219
281
|
logger.debug("Body validation failed", { error: e });
|
|
220
|
-
if (e instanceof ZodError) {
|
|
282
|
+
if (e instanceof import_zod.ZodError) {
|
|
221
283
|
const details = e.issues.map((err) => ({
|
|
222
284
|
path: err.path.join("."),
|
|
223
285
|
message: err.message,
|
|
@@ -278,9 +340,9 @@ var validateBearerToken = (logger) => {
|
|
|
278
340
|
|
|
279
341
|
// src/chmed16/router.ts
|
|
280
342
|
var CHMED16ARouter = class {
|
|
281
|
-
static getRouter(logger) {
|
|
282
|
-
const router =
|
|
283
|
-
const controller = new CHMED16AController(logger);
|
|
343
|
+
static getRouter(logger, appVersion, clientId) {
|
|
344
|
+
const router = import_express2.default.Router();
|
|
345
|
+
const controller = new CHMED16AController(logger, appVersion, clientId);
|
|
284
346
|
router.post(
|
|
285
347
|
"/chmed",
|
|
286
348
|
validateBearerToken(logger),
|
|
@@ -292,18 +354,19 @@ var CHMED16ARouter = class {
|
|
|
292
354
|
};
|
|
293
355
|
|
|
294
356
|
// src/index.ts
|
|
295
|
-
|
|
357
|
+
var import_zod2 = require("zod");
|
|
296
358
|
var App = class {
|
|
297
359
|
constructor(logger, appVersion) {
|
|
298
360
|
this.logger = logger;
|
|
299
361
|
this.appVersion = appVersion;
|
|
300
|
-
this.
|
|
362
|
+
this.clientId = crypto.randomUUID();
|
|
363
|
+
this.app = (0, import_express3.default)();
|
|
301
364
|
this.initializeMiddlewares();
|
|
302
365
|
this.initializeRoutes();
|
|
303
366
|
this.initializeErrorHandling();
|
|
304
367
|
}
|
|
305
368
|
initializeMiddlewares() {
|
|
306
|
-
this.app.use(
|
|
369
|
+
this.app.use(import_express3.default.json());
|
|
307
370
|
this.app.use((req, res, next) => {
|
|
308
371
|
this.logger.info(`${req.method} ${req.url}`);
|
|
309
372
|
next();
|
|
@@ -311,7 +374,10 @@ var App = class {
|
|
|
311
374
|
}
|
|
312
375
|
initializeRoutes() {
|
|
313
376
|
this.app.use("/", HealthRouter.getRouter(this.logger, this.appVersion));
|
|
314
|
-
this.app.use(
|
|
377
|
+
this.app.use(
|
|
378
|
+
"/v1",
|
|
379
|
+
CHMED16ARouter.getRouter(this.logger, this.appVersion, this.clientId)
|
|
380
|
+
);
|
|
315
381
|
}
|
|
316
382
|
/**
|
|
317
383
|
* General error handler for all errors, so we can throw from anywhere in the project
|
|
@@ -322,7 +388,7 @@ var App = class {
|
|
|
322
388
|
(e, req, res, next) => {
|
|
323
389
|
this.logger.debug("General Error Handler");
|
|
324
390
|
this.logger.debug(e);
|
|
325
|
-
if (e instanceof
|
|
391
|
+
if (e instanceof import_zod2.ZodError) {
|
|
326
392
|
const details = e.issues.map((err) => ({
|
|
327
393
|
path: err.path.join("."),
|
|
328
394
|
message: err.message,
|
|
@@ -366,6 +432,7 @@ var App = class {
|
|
|
366
432
|
});
|
|
367
433
|
}
|
|
368
434
|
};
|
|
369
|
-
export
|
|
435
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
436
|
+
0 && (module.exports = {
|
|
370
437
|
App
|
|
371
|
-
};
|
|
438
|
+
});
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
1
|
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
2
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
3
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
4
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
5
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -19,27 +14,6 @@ var __spreadValues = (a, b) => {
|
|
|
19
14
|
}
|
|
20
15
|
return a;
|
|
21
16
|
};
|
|
22
|
-
var __export = (target, all) => {
|
|
23
|
-
for (var name in all)
|
|
24
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
25
|
-
};
|
|
26
|
-
var __copyProps = (to, from, except, desc) => {
|
|
27
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
28
|
-
for (let key of __getOwnPropNames(from))
|
|
29
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
30
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
31
|
-
}
|
|
32
|
-
return to;
|
|
33
|
-
};
|
|
34
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
35
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
36
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
37
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
38
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
39
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
40
|
-
mod
|
|
41
|
-
));
|
|
42
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
43
17
|
var __async = (__this, __arguments, generator) => {
|
|
44
18
|
return new Promise((resolve, reject) => {
|
|
45
19
|
var fulfilled = (value) => {
|
|
@@ -62,15 +36,10 @@ var __async = (__this, __arguments, generator) => {
|
|
|
62
36
|
};
|
|
63
37
|
|
|
64
38
|
// src/index.ts
|
|
65
|
-
|
|
66
|
-
__export(index_exports, {
|
|
67
|
-
App: () => App
|
|
68
|
-
});
|
|
69
|
-
module.exports = __toCommonJS(index_exports);
|
|
70
|
-
var import_express3 = __toESM(require("express"));
|
|
39
|
+
import express3 from "express";
|
|
71
40
|
|
|
72
41
|
// src/health/router.ts
|
|
73
|
-
|
|
42
|
+
import express from "express";
|
|
74
43
|
|
|
75
44
|
// src/health/controller.ts
|
|
76
45
|
var HealthController = class {
|
|
@@ -87,7 +56,7 @@ var HealthController = class {
|
|
|
87
56
|
// src/health/router.ts
|
|
88
57
|
var HealthRouter = class {
|
|
89
58
|
static getRouter(logger, appVersion) {
|
|
90
|
-
const router =
|
|
59
|
+
const router = express.Router();
|
|
91
60
|
const controller = new HealthController(logger, appVersion);
|
|
92
61
|
router.get("/health", controller.check);
|
|
93
62
|
return router;
|
|
@@ -95,14 +64,21 @@ var HealthRouter = class {
|
|
|
95
64
|
};
|
|
96
65
|
|
|
97
66
|
// src/chmed16/router.ts
|
|
98
|
-
|
|
67
|
+
import express2 from "express";
|
|
99
68
|
|
|
100
69
|
// src/chmed16/controller.ts
|
|
101
|
-
|
|
102
|
-
|
|
70
|
+
import {
|
|
71
|
+
CHMEDParser,
|
|
72
|
+
SDS,
|
|
73
|
+
ConformanceError,
|
|
74
|
+
UpgradeError,
|
|
75
|
+
DoctorNotFoundError,
|
|
76
|
+
UnauthorizedError
|
|
77
|
+
} from "@vereign/chmed-parser";
|
|
78
|
+
import { PDFLib } from "@vereign/pdf-generator";
|
|
103
79
|
|
|
104
80
|
// src/app-error.ts
|
|
105
|
-
|
|
81
|
+
import * as z from "zod/v4";
|
|
106
82
|
var AppError = class extends Error {
|
|
107
83
|
constructor(status, message, code, details) {
|
|
108
84
|
super(message);
|
|
@@ -133,7 +109,7 @@ var appErrorSchema = z.object({
|
|
|
133
109
|
|
|
134
110
|
// src/chmed16/controller.ts
|
|
135
111
|
var CHMED16AController = class {
|
|
136
|
-
constructor(logger) {
|
|
112
|
+
constructor(logger, appVersion, clientId) {
|
|
137
113
|
this.process = (req, res, next) => __async(this, null, function* () {
|
|
138
114
|
const { chmed, lang } = req.body;
|
|
139
115
|
const token = req.token;
|
|
@@ -148,8 +124,13 @@ var CHMED16AController = class {
|
|
|
148
124
|
}
|
|
149
125
|
});
|
|
150
126
|
this.logger = logger;
|
|
151
|
-
this.sds = new
|
|
152
|
-
|
|
127
|
+
this.sds = new SDS(
|
|
128
|
+
"https://oauth2.sds.hin.ch",
|
|
129
|
+
logger,
|
|
130
|
+
appVersion,
|
|
131
|
+
clientId
|
|
132
|
+
);
|
|
133
|
+
this.parser = new CHMEDParser(logger);
|
|
153
134
|
}
|
|
154
135
|
parseChmedData(chmed, token, lang) {
|
|
155
136
|
return __async(this, null, function* () {
|
|
@@ -161,7 +142,7 @@ var CHMED16AController = class {
|
|
|
161
142
|
return json;
|
|
162
143
|
} catch (error) {
|
|
163
144
|
this.logger.error("Parsing failed:", error);
|
|
164
|
-
if (error instanceof
|
|
145
|
+
if (error instanceof ConformanceError) {
|
|
165
146
|
throw new AppError(
|
|
166
147
|
400,
|
|
167
148
|
"CHMED data does not conform to required standards.",
|
|
@@ -169,6 +150,32 @@ var CHMED16AController = class {
|
|
|
169
150
|
error.validationErrors
|
|
170
151
|
);
|
|
171
152
|
}
|
|
153
|
+
if (error instanceof UpgradeError) {
|
|
154
|
+
throw new AppError(426, "Upgrade required.", "UPGRADE_ERROR");
|
|
155
|
+
}
|
|
156
|
+
if (error instanceof DoctorNotFoundError) {
|
|
157
|
+
throw new AppError(400, "Failed to fetch doctor by gln", "NOT_FOUND", [
|
|
158
|
+
{
|
|
159
|
+
path: "chmed",
|
|
160
|
+
message: error.message,
|
|
161
|
+
code: "doctor_not_found"
|
|
162
|
+
}
|
|
163
|
+
]);
|
|
164
|
+
}
|
|
165
|
+
if (error instanceof UnauthorizedError) {
|
|
166
|
+
throw new AppError(
|
|
167
|
+
401,
|
|
168
|
+
"Unauthorized access. Check the bearer token.",
|
|
169
|
+
"UNAUTHORIZED_ERROR",
|
|
170
|
+
[
|
|
171
|
+
{
|
|
172
|
+
path: "chmed",
|
|
173
|
+
message: error.message,
|
|
174
|
+
code: "unauthorized_access"
|
|
175
|
+
}
|
|
176
|
+
]
|
|
177
|
+
);
|
|
178
|
+
}
|
|
172
179
|
throw new AppError(
|
|
173
180
|
400,
|
|
174
181
|
"Failed to parse CHMED data. Please check the input format.",
|
|
@@ -188,7 +195,7 @@ var CHMED16AController = class {
|
|
|
188
195
|
return __async(this, null, function* () {
|
|
189
196
|
const pdfStart = Date.now();
|
|
190
197
|
try {
|
|
191
|
-
const pdf = new
|
|
198
|
+
const pdf = new PDFLib(this.logger);
|
|
192
199
|
const pdfBuffer = yield pdf.generateBuffer(json);
|
|
193
200
|
res.setHeader("Content-Type", "application/pdf");
|
|
194
201
|
res.setHeader("Content-Disposition", 'inline; filename="chmed16a.pdf"');
|
|
@@ -214,10 +221,10 @@ var CHMED16AController = class {
|
|
|
214
221
|
};
|
|
215
222
|
|
|
216
223
|
// src/chmed16/middleware.ts
|
|
217
|
-
|
|
224
|
+
import { ZodError } from "zod";
|
|
218
225
|
|
|
219
226
|
// src/chmed16/request.ts
|
|
220
|
-
|
|
227
|
+
import * as z2 from "zod/v4";
|
|
221
228
|
var chmedPattern = /^CHMED[0-9A-Za-z]+/;
|
|
222
229
|
var bodySchema = z2.object({
|
|
223
230
|
chmed: z2.string().min(5, "string is required").refine(
|
|
@@ -248,7 +255,7 @@ var validateBody = (logger) => {
|
|
|
248
255
|
next();
|
|
249
256
|
} catch (e) {
|
|
250
257
|
logger.debug("Body validation failed", { error: e });
|
|
251
|
-
if (e instanceof
|
|
258
|
+
if (e instanceof ZodError) {
|
|
252
259
|
const details = e.issues.map((err) => ({
|
|
253
260
|
path: err.path.join("."),
|
|
254
261
|
message: err.message,
|
|
@@ -309,9 +316,9 @@ var validateBearerToken = (logger) => {
|
|
|
309
316
|
|
|
310
317
|
// src/chmed16/router.ts
|
|
311
318
|
var CHMED16ARouter = class {
|
|
312
|
-
static getRouter(logger) {
|
|
313
|
-
const router =
|
|
314
|
-
const controller = new CHMED16AController(logger);
|
|
319
|
+
static getRouter(logger, appVersion, clientId) {
|
|
320
|
+
const router = express2.Router();
|
|
321
|
+
const controller = new CHMED16AController(logger, appVersion, clientId);
|
|
315
322
|
router.post(
|
|
316
323
|
"/chmed",
|
|
317
324
|
validateBearerToken(logger),
|
|
@@ -323,18 +330,19 @@ var CHMED16ARouter = class {
|
|
|
323
330
|
};
|
|
324
331
|
|
|
325
332
|
// src/index.ts
|
|
326
|
-
|
|
333
|
+
import { ZodError as ZodError2 } from "zod";
|
|
327
334
|
var App = class {
|
|
328
335
|
constructor(logger, appVersion) {
|
|
329
336
|
this.logger = logger;
|
|
330
337
|
this.appVersion = appVersion;
|
|
331
|
-
this.
|
|
338
|
+
this.clientId = crypto.randomUUID();
|
|
339
|
+
this.app = express3();
|
|
332
340
|
this.initializeMiddlewares();
|
|
333
341
|
this.initializeRoutes();
|
|
334
342
|
this.initializeErrorHandling();
|
|
335
343
|
}
|
|
336
344
|
initializeMiddlewares() {
|
|
337
|
-
this.app.use(
|
|
345
|
+
this.app.use(express3.json());
|
|
338
346
|
this.app.use((req, res, next) => {
|
|
339
347
|
this.logger.info(`${req.method} ${req.url}`);
|
|
340
348
|
next();
|
|
@@ -342,7 +350,10 @@ var App = class {
|
|
|
342
350
|
}
|
|
343
351
|
initializeRoutes() {
|
|
344
352
|
this.app.use("/", HealthRouter.getRouter(this.logger, this.appVersion));
|
|
345
|
-
this.app.use(
|
|
353
|
+
this.app.use(
|
|
354
|
+
"/v1",
|
|
355
|
+
CHMED16ARouter.getRouter(this.logger, this.appVersion, this.clientId)
|
|
356
|
+
);
|
|
346
357
|
}
|
|
347
358
|
/**
|
|
348
359
|
* General error handler for all errors, so we can throw from anywhere in the project
|
|
@@ -353,7 +364,7 @@ var App = class {
|
|
|
353
364
|
(e, req, res, next) => {
|
|
354
365
|
this.logger.debug("General Error Handler");
|
|
355
366
|
this.logger.debug(e);
|
|
356
|
-
if (e instanceof
|
|
367
|
+
if (e instanceof ZodError2) {
|
|
357
368
|
const details = e.issues.map((err) => ({
|
|
358
369
|
path: err.path.join("."),
|
|
359
370
|
message: err.message,
|
|
@@ -397,7 +408,6 @@ var App = class {
|
|
|
397
408
|
});
|
|
398
409
|
}
|
|
399
410
|
};
|
|
400
|
-
|
|
401
|
-
0 && (module.exports = {
|
|
411
|
+
export {
|
|
402
412
|
App
|
|
403
|
-
}
|
|
413
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vereign/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "core api library for e prescription project",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"license": "AGPL-3.0-only",
|
|
10
10
|
"author": "Vereign Team",
|
|
11
11
|
"main": "dist/index.js",
|
|
12
|
+
"type": "module",
|
|
12
13
|
"module": "dist/index.mjs",
|
|
13
14
|
"types": "dist/index.d.ts",
|
|
14
15
|
"publishConfig": {
|
|
@@ -26,8 +27,8 @@
|
|
|
26
27
|
"test": "vitest run --coverage",
|
|
27
28
|
"test:watch": "vitest --coverage",
|
|
28
29
|
"semantic-release": "semantic-release",
|
|
29
|
-
"dev": "
|
|
30
|
-
"generate:swagger": "
|
|
30
|
+
"dev": "tsx watch ./src/dev-server.ts",
|
|
31
|
+
"generate:swagger": "tsx ./src/generate-swagger.ts"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
34
|
"@commitlint/cli": "^19.8.1",
|
|
@@ -52,16 +53,16 @@
|
|
|
52
53
|
"prettier": "^3.6.2",
|
|
53
54
|
"semantic-release": "^24.2.7",
|
|
54
55
|
"supertest": "^7.1.4",
|
|
55
|
-
"ts-node-dev": "^2.0.0",
|
|
56
56
|
"tsup": "^8.5.0",
|
|
57
|
+
"tsx": "^4.20.6",
|
|
57
58
|
"typescript": "^5.8.3",
|
|
58
59
|
"typescript-eslint": "^8.37.0",
|
|
59
60
|
"vitest": "^3.2.4",
|
|
60
61
|
"zod-openapi": "^5.3.1"
|
|
61
62
|
},
|
|
62
63
|
"dependencies": {
|
|
63
|
-
"@vereign/chmed-parser": "^1.
|
|
64
|
-
"@vereign/pdf-generator": "^1.
|
|
64
|
+
"@vereign/chmed-parser": "^1.10.3",
|
|
65
|
+
"@vereign/pdf-generator": "^1.6.5",
|
|
65
66
|
"express": "^5.1.0",
|
|
66
67
|
"pdfkit": "^0.17.1",
|
|
67
68
|
"winston": "^3.17.0",
|