frontend-hamroun 1.2.5 → 1.2.6
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/context.d.ts +3 -4
- package/dist/context.js +6 -8
- package/dist/frontend-hamroun.es.js +331 -301
- package/dist/frontend-hamroun.umd.js +13 -13
- package/dist/index.d.ts +58 -14
- package/dist/index.js +26 -13
- package/package.json +1 -1
- package/src/context.ts +11 -14
- package/src/index.ts +72 -43
- package/templates/basic-app/src/App.tsx +53 -1
- package/templates/basic-app/src/main.tsx +18 -1
@@ -1,19 +1,18 @@
|
|
1
|
-
import
|
2
|
-
import { Router as Et } from "express";
|
1
|
+
import O, { Router as ye } from "express";
|
3
2
|
import de from "path";
|
4
|
-
import
|
5
|
-
import
|
6
|
-
import
|
3
|
+
import Ne from "compression";
|
4
|
+
import Oe from "helmet";
|
5
|
+
import Pe from "morgan";
|
7
6
|
import $ from "mongoose";
|
8
|
-
import
|
7
|
+
import De from "fs";
|
9
8
|
import z from "jsonwebtoken";
|
10
9
|
import * as fe from "bcrypt";
|
11
|
-
import
|
10
|
+
import Me from "crypto";
|
12
11
|
const he = globalThis || void 0 || self;
|
13
|
-
function
|
12
|
+
function Fe(r) {
|
14
13
|
return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r;
|
15
14
|
}
|
16
|
-
var
|
15
|
+
var ge = { exports: {} }, m = ge.exports = {}, k, v;
|
17
16
|
function te() {
|
18
17
|
throw new Error("setTimeout has not been defined");
|
19
18
|
}
|
@@ -32,7 +31,7 @@ function re() {
|
|
32
31
|
v = re;
|
33
32
|
}
|
34
33
|
})();
|
35
|
-
function
|
34
|
+
function we(r) {
|
36
35
|
if (k === setTimeout)
|
37
36
|
return setTimeout(r, 0);
|
38
37
|
if ((k === te || !k) && setTimeout)
|
@@ -47,7 +46,7 @@ function ge(r) {
|
|
47
46
|
}
|
48
47
|
}
|
49
48
|
}
|
50
|
-
function
|
49
|
+
function Le(r) {
|
51
50
|
if (v === clearTimeout)
|
52
51
|
return clearTimeout(r);
|
53
52
|
if ((v === re || !v) && clearTimeout)
|
@@ -62,20 +61,20 @@ function Pe(r) {
|
|
62
61
|
}
|
63
62
|
}
|
64
63
|
}
|
65
|
-
var A = [],
|
66
|
-
function
|
67
|
-
!
|
64
|
+
var A = [], D = !1, _, B = -1;
|
65
|
+
function Ve() {
|
66
|
+
!D || !_ || (D = !1, _.length ? A = _.concat(A) : B = -1, A.length && Ee());
|
68
67
|
}
|
69
|
-
function
|
70
|
-
if (!
|
71
|
-
var r =
|
72
|
-
|
68
|
+
function Ee() {
|
69
|
+
if (!D) {
|
70
|
+
var r = we(Ve);
|
71
|
+
D = !0;
|
73
72
|
for (var t = A.length; t; ) {
|
74
|
-
for (_ = A, A = []; ++
|
75
|
-
_ && _[
|
76
|
-
|
73
|
+
for (_ = A, A = []; ++B < t; )
|
74
|
+
_ && _[B].run();
|
75
|
+
B = -1, t = A.length;
|
77
76
|
}
|
78
|
-
_ = null,
|
77
|
+
_ = null, D = !1, Le(r);
|
79
78
|
}
|
80
79
|
}
|
81
80
|
m.nextTick = function(r) {
|
@@ -83,12 +82,12 @@ m.nextTick = function(r) {
|
|
83
82
|
if (arguments.length > 1)
|
84
83
|
for (var e = 1; e < arguments.length; e++)
|
85
84
|
t[e - 1] = arguments[e];
|
86
|
-
A.push(new
|
85
|
+
A.push(new be(r, t)), A.length === 1 && !D && we(Ee);
|
87
86
|
};
|
88
|
-
function
|
87
|
+
function be(r, t) {
|
89
88
|
this.fun = r, this.array = t;
|
90
89
|
}
|
91
|
-
|
90
|
+
be.prototype.run = function() {
|
92
91
|
this.fun.apply(null, this.array);
|
93
92
|
};
|
94
93
|
m.title = "browser";
|
@@ -123,17 +122,17 @@ m.chdir = function(r) {
|
|
123
122
|
m.umask = function() {
|
124
123
|
return 0;
|
125
124
|
};
|
126
|
-
var
|
127
|
-
const w = /* @__PURE__ */
|
128
|
-
function
|
125
|
+
var Be = ge.exports;
|
126
|
+
const w = /* @__PURE__ */ Fe(Be), j = typeof window < "u" ? window : typeof he < "u" ? he : {};
|
127
|
+
function ae(r, t, e) {
|
129
128
|
return {
|
130
129
|
type: r,
|
131
130
|
props: t || {},
|
132
131
|
key: e
|
133
132
|
};
|
134
133
|
}
|
135
|
-
function
|
136
|
-
return
|
134
|
+
function Te(r, t, e) {
|
135
|
+
return ae(r, t, e);
|
137
136
|
}
|
138
137
|
function se(r) {
|
139
138
|
if (typeof r == "string" || typeof r == "number")
|
@@ -171,12 +170,12 @@ function se(r) {
|
|
171
170
|
}) : t.setAttribute(e, s);
|
172
171
|
}), t;
|
173
172
|
}
|
174
|
-
const
|
175
|
-
typeof window < "u" && (window.jsx =
|
176
|
-
const
|
173
|
+
const ke = Symbol("Fragment");
|
174
|
+
typeof window < "u" && (window.jsx = ae, window.jsxs = Te, window.Fragment = ke);
|
175
|
+
const He = typeof window < "u" && typeof document < "u";
|
177
176
|
async function C(r) {
|
178
177
|
var t;
|
179
|
-
if (console.log("Creating element from:", r), !
|
178
|
+
if (console.log("Creating element from:", r), !He) {
|
180
179
|
if (r == null)
|
181
180
|
return { nodeType: 3, textContent: "" };
|
182
181
|
if (typeof r == "boolean")
|
@@ -271,7 +270,7 @@ async function C(r) {
|
|
271
270
|
}
|
272
271
|
return document.createTextNode(String(r));
|
273
272
|
}
|
274
|
-
class
|
273
|
+
class We {
|
275
274
|
constructor(t = {}) {
|
276
275
|
this.state = {}, this.element = null, this._mounted = !1, this.props = t;
|
277
276
|
}
|
@@ -315,40 +314,40 @@ class Be {
|
|
315
314
|
throw new Error("Component must implement render() method");
|
316
315
|
}
|
317
316
|
}
|
318
|
-
let
|
317
|
+
let H = !1;
|
319
318
|
const X = [];
|
320
|
-
function
|
321
|
-
if (
|
319
|
+
function ce(r) {
|
320
|
+
if (H) {
|
322
321
|
X.push(r);
|
323
322
|
return;
|
324
323
|
}
|
325
|
-
|
324
|
+
H = !0;
|
326
325
|
try {
|
327
326
|
for (r(); X.length > 0; ) {
|
328
327
|
const t = X.shift();
|
329
328
|
t == null || t();
|
330
329
|
}
|
331
330
|
} finally {
|
332
|
-
|
331
|
+
H = !1;
|
333
332
|
}
|
334
333
|
}
|
335
334
|
let u = 0;
|
336
|
-
const Z = /* @__PURE__ */ new Map(), b = /* @__PURE__ */ new Map(),
|
335
|
+
const Z = /* @__PURE__ */ new Map(), b = /* @__PURE__ */ new Map(), L = /* @__PURE__ */ new Map(), K = /* @__PURE__ */ new Map(), ee = /* @__PURE__ */ new Map();
|
337
336
|
let ne = null, oe = null, ie = null;
|
338
|
-
const
|
339
|
-
function
|
337
|
+
const ve = typeof window > "u", W = /* @__PURE__ */ new Map();
|
338
|
+
function Se(r, t, e) {
|
340
339
|
ne = r, oe = e, ie = t;
|
341
340
|
}
|
342
341
|
function U() {
|
343
342
|
return u++, b.set(u, 0), u;
|
344
343
|
}
|
345
344
|
function q() {
|
346
|
-
|
345
|
+
ve && W.delete(u), u = 0;
|
347
346
|
}
|
348
|
-
function
|
347
|
+
function Ae(r) {
|
349
348
|
if (!u)
|
350
349
|
throw new Error("useState must be called within a render");
|
351
|
-
if (
|
350
|
+
if (ve) {
|
352
351
|
W.has(u) || W.set(u, /* @__PURE__ */ new Map());
|
353
352
|
const i = W.get(u), o = b.get(u) || 0;
|
354
353
|
i.has(o) || i.set(o, r);
|
@@ -361,21 +360,21 @@ function Se(r) {
|
|
361
360
|
e >= t.length && t.push(r);
|
362
361
|
const s = t[e], n = (i) => {
|
363
362
|
const o = typeof i == "function" ? i(t[e]) : i;
|
364
|
-
t[e] !== o && (t[e] = o,
|
363
|
+
t[e] !== o && (t[e] = o, H ? ce(() => pe(u)) : pe(u));
|
365
364
|
};
|
366
365
|
return b.set(u, e + 1), [s, n];
|
367
366
|
}
|
368
|
-
function
|
367
|
+
function Ue(r, t) {
|
369
368
|
if (!u) throw new Error("useEffect must be called within a render");
|
370
369
|
const e = b.get(u);
|
371
|
-
|
372
|
-
const s =
|
370
|
+
L.has(u) || L.set(u, []);
|
371
|
+
const s = L.get(u), n = s[e];
|
373
372
|
(!n || !t || !n.deps || t.some((i, o) => i !== n.deps[o])) && (n != null && n.cleanup && n.cleanup(), queueMicrotask(() => {
|
374
373
|
const i = r() || void 0;
|
375
374
|
s[e] = { cleanup: i, deps: t };
|
376
375
|
})), b.set(u, e + 1);
|
377
376
|
}
|
378
|
-
function
|
377
|
+
function qe(r, t) {
|
379
378
|
if (!u) throw new Error("useMemo must be called within a render");
|
380
379
|
const e = b.get(u);
|
381
380
|
K.has(u) || K.set(u, []);
|
@@ -386,7 +385,7 @@ function Ve(r, t) {
|
|
386
385
|
}
|
387
386
|
return b.set(u, e + 1), n.value;
|
388
387
|
}
|
389
|
-
function
|
388
|
+
function Ge(r) {
|
390
389
|
if (!u) throw new Error("useRef must be called within a render");
|
391
390
|
const t = b.get(u);
|
392
391
|
ee.has(u) || ee.set(u, []);
|
@@ -400,32 +399,32 @@ function We(r) {
|
|
400
399
|
}
|
401
400
|
async function pe(r) {
|
402
401
|
try {
|
403
|
-
const t =
|
402
|
+
const t = L.get(r);
|
404
403
|
t && (t.forEach((e) => {
|
405
404
|
e.cleanup && e.cleanup();
|
406
|
-
}),
|
405
|
+
}), L.set(r, [])), ne && oe && ie && await ne(ie, oe);
|
407
406
|
} catch (t) {
|
408
407
|
console.error("Error during rerender:", t);
|
409
408
|
}
|
410
409
|
}
|
411
|
-
function
|
412
|
-
const [r, t] =
|
410
|
+
function Je() {
|
411
|
+
const [r, t] = Ae(null);
|
413
412
|
return [r, () => t(null)];
|
414
413
|
}
|
415
414
|
let G = !1;
|
416
|
-
async function
|
415
|
+
async function Qe(r, t) {
|
417
416
|
G = !0;
|
418
417
|
try {
|
419
|
-
await
|
418
|
+
await ue(r, t);
|
420
419
|
} finally {
|
421
420
|
G = !1;
|
422
421
|
}
|
423
422
|
}
|
424
|
-
async function
|
425
|
-
console.log("Rendering to:", t.id || "unnamed-container"),
|
423
|
+
async function ue(r, t) {
|
424
|
+
console.log("Rendering to:", t.id || "unnamed-container"), ce(async () => {
|
426
425
|
const e = U();
|
427
426
|
try {
|
428
|
-
|
427
|
+
Se(ue, r, t);
|
429
428
|
const s = await C(r);
|
430
429
|
G || (t.innerHTML = ""), G && t.firstChild ? console.log("Hydrating existing DOM") : t.appendChild(s);
|
431
430
|
} finally {
|
@@ -433,21 +432,21 @@ async function le(r, t) {
|
|
433
432
|
}
|
434
433
|
});
|
435
434
|
}
|
436
|
-
async function
|
437
|
-
U(),
|
435
|
+
async function P(r) {
|
436
|
+
U(), Se(() => {
|
438
437
|
}, r, null);
|
439
438
|
try {
|
440
439
|
if (r == null || typeof r == "boolean") return "";
|
441
440
|
if (typeof r == "number" || typeof r == "string")
|
442
|
-
return
|
441
|
+
return V(String(r));
|
443
442
|
if (Array.isArray(r))
|
444
|
-
return (await Promise.all(r.map(
|
443
|
+
return (await Promise.all(r.map(P))).join("");
|
445
444
|
if ("type" in r && r.props !== void 0) {
|
446
445
|
const { type: t, props: e } = r;
|
447
446
|
if (typeof t == "function")
|
448
447
|
try {
|
449
448
|
U();
|
450
|
-
const i = await t(e || {}), o = await
|
449
|
+
const i = await t(e || {}), o = await P(i);
|
451
450
|
return q(), o;
|
452
451
|
} catch (i) {
|
453
452
|
return console.error("Error rendering component:", i), "";
|
@@ -455,13 +454,13 @@ async function N(r) {
|
|
455
454
|
if (t === Symbol.for("react.fragment") || t.name === "Fragment") {
|
456
455
|
if (e.children) {
|
457
456
|
const i = Array.isArray(e.children) ? e.children : [e.children];
|
458
|
-
return (await Promise.all(i.map(
|
457
|
+
return (await Promise.all(i.map(P))).join("");
|
459
458
|
}
|
460
459
|
return "";
|
461
460
|
}
|
462
461
|
let s = `<${t}`;
|
463
462
|
for (const [i, o] of Object.entries(e || {}))
|
464
|
-
i === "children" || i === "key" || (i === "className" ? s += ` class="${
|
463
|
+
i === "children" || i === "key" || (i === "className" ? s += ` class="${V(String(o))}"` : i === "style" && typeof o == "object" ? s += ` style="${Ye(o || {})}"` : i.startsWith("on") || (s += ` ${i}="${V(String(o))}"`));
|
465
464
|
if ((/* @__PURE__ */ new Set([
|
466
465
|
"area",
|
467
466
|
"base",
|
@@ -482,25 +481,40 @@ async function N(r) {
|
|
482
481
|
if (s += ">", e != null && e.children) {
|
483
482
|
const i = Array.isArray(e.children) ? e.children : [e.children];
|
484
483
|
for (const o of i)
|
485
|
-
s += await
|
484
|
+
s += await P(o);
|
486
485
|
}
|
487
486
|
return s + `</${t}>`;
|
488
487
|
}
|
489
|
-
return
|
488
|
+
return V(String(r));
|
490
489
|
} finally {
|
491
490
|
q();
|
492
491
|
}
|
493
492
|
}
|
494
|
-
function
|
493
|
+
function V(r) {
|
495
494
|
return r.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
496
495
|
}
|
497
|
-
function
|
498
|
-
return Object.entries(r).map(([t, e]) => `${
|
496
|
+
function Ye(r) {
|
497
|
+
return Object.entries(r).map(([t, e]) => `${ze(t)}:${e}`).join(";");
|
499
498
|
}
|
500
|
-
function
|
499
|
+
function ze(r) {
|
501
500
|
return r.replace(/[A-Z]/g, (t) => "-" + t.toLowerCase());
|
502
501
|
}
|
503
|
-
|
502
|
+
function Xe(r) {
|
503
|
+
const t = {
|
504
|
+
_currentValue: r,
|
505
|
+
Provider: function({ value: s, children: n }) {
|
506
|
+
return t._currentValue = s, n;
|
507
|
+
},
|
508
|
+
Consumer: function({ children: s }) {
|
509
|
+
return s(t._currentValue);
|
510
|
+
}
|
511
|
+
};
|
512
|
+
return t;
|
513
|
+
}
|
514
|
+
function Ze(r) {
|
515
|
+
return r._currentValue;
|
516
|
+
}
|
517
|
+
class xe {
|
504
518
|
// Renamed from isConnected to _connected
|
505
519
|
constructor(t) {
|
506
520
|
this.connection = null, this._connected = !1, this.options = {
|
@@ -562,8 +576,8 @@ class Qe {
|
|
562
576
|
return this.connection;
|
563
577
|
}
|
564
578
|
}
|
565
|
-
function
|
566
|
-
const t =
|
579
|
+
function Ke(r = {}) {
|
580
|
+
const t = O(), {
|
567
581
|
port: e = 3e3,
|
568
582
|
staticDir: s = "public",
|
569
583
|
enableCors: n = !0,
|
@@ -576,15 +590,15 @@ function Ye(r = {}) {
|
|
576
590
|
trustProxy: E = !1,
|
577
591
|
showErrorDetails: S = w.env.NODE_ENV !== "production"
|
578
592
|
} = r;
|
579
|
-
if (E && t.set("trust proxy", E), t.use(
|
593
|
+
if (E && t.set("trust proxy", E), t.use(O.json()), t.use(O.urlencoded({ extended: !0 })), c && t.use(Ne()), d && t.use(Oe({
|
580
594
|
contentSecurityPolicy: r.disableCSP ? !1 : void 0
|
581
|
-
})), h && t.use(
|
595
|
+
})), h && t.use(Pe(h)), n && t.use((l, p, f) => {
|
582
596
|
if (p.header("Access-Control-Allow-Origin", "*"), p.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS"), p.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization"), l.method === "OPTIONS")
|
583
597
|
return p.sendStatus(200);
|
584
598
|
f();
|
585
599
|
}), a.forEach((l) => t.use(l)), s) {
|
586
600
|
const l = de.resolve(w.cwd(), s);
|
587
|
-
|
601
|
+
De.existsSync(l) ? (t.use(O.static(l, {
|
588
602
|
maxAge: r.staticCacheAge || "1d",
|
589
603
|
etag: !0
|
590
604
|
})), console.log(`📂 Serving static files from: ${l}`)) : console.warn(`⚠️ Static directory not found: ${l}`);
|
@@ -592,7 +606,7 @@ function Ye(r = {}) {
|
|
592
606
|
let y = null;
|
593
607
|
t.connectToDatabase = async (l) => {
|
594
608
|
try {
|
595
|
-
return y && y.isConnected() ? (console.log("✅ Using existing database connection"), y) : (y = new
|
609
|
+
return y && y.isConnected() ? (console.log("✅ Using existing database connection"), y) : (y = new xe(l), await y.connect(), console.log("✅ Database connected successfully"), w.on("SIGTERM", async () => {
|
596
610
|
y && y.isConnected() && (await y.disconnect(), console.log("Database connection closed"));
|
597
611
|
}), y);
|
598
612
|
} catch (p) {
|
@@ -619,7 +633,7 @@ function Ye(r = {}) {
|
|
619
633
|
query: g.query,
|
620
634
|
user: g.user,
|
621
635
|
...f.props
|
622
|
-
},
|
636
|
+
}, _e = await P(p(Y));
|
623
637
|
T.send(`
|
624
638
|
<!DOCTYPE html>
|
625
639
|
<html lang="${f.lang || "en"}">
|
@@ -627,19 +641,19 @@ function Ye(r = {}) {
|
|
627
641
|
<meta charset="UTF-8">
|
628
642
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
629
643
|
<title>${f.title || "Frontend Hamroun App"}</title>
|
630
|
-
${f.meta ? f.meta.map((
|
644
|
+
${f.meta ? f.meta.map((F) => `<meta ${Object.entries(F).map(([Ie, Re]) => `${Ie}="${Re}"`).join(" ")}>`).join(`
|
631
645
|
`) : ""}
|
632
646
|
${f.head || ""}
|
633
647
|
${f.styles ? `<style>${f.styles}</style>` : ""}
|
634
|
-
${f.styleSheets ? f.styleSheets.map((
|
648
|
+
${f.styleSheets ? f.styleSheets.map((F) => `<link rel="stylesheet" href="${F}">`).join(`
|
635
649
|
`) : ""}
|
636
650
|
</head>
|
637
651
|
<body ${f.bodyAttributes || ""}>
|
638
|
-
<div id="${f.rootId || "root"}">${
|
652
|
+
<div id="${f.rootId || "root"}">${_e}</div>
|
639
653
|
<script>
|
640
654
|
window.__INITIAL_DATA__ = ${JSON.stringify(f.initialData || {})};
|
641
655
|
<\/script>
|
642
|
-
${f.scripts ? f.scripts.map((
|
656
|
+
${f.scripts ? f.scripts.map((F) => `<script src="${F}"><\/script>`).join(`
|
643
657
|
`) : ""}
|
644
658
|
</body>
|
645
659
|
</html>
|
@@ -714,169 +728,8 @@ ${Object.keys(J).map((g) => ` ${g}`).join(`
|
|
714
728
|
return w.on("SIGTERM", () => f("SIGTERM")), w.on("SIGINT", () => f("SIGINT")), p;
|
715
729
|
}, t;
|
716
730
|
}
|
717
|
-
const Ae = (r, { res: t }) => {
|
718
|
-
console.error("API Error:", r);
|
719
|
-
const e = r.status || r.statusCode || 500, s = r.message || "Internal server error";
|
720
|
-
t.status(e).json({
|
721
|
-
success: !1,
|
722
|
-
error: s,
|
723
|
-
stack: w.env.NODE_ENV !== "production" ? r.stack : void 0
|
724
|
-
});
|
725
|
-
};
|
726
|
-
function ut(r, t = {}) {
|
727
|
-
const e = R.Router(), { middleware: s = [], errorHandler: n = Ae } = t;
|
728
|
-
s.forEach((o) => e.use(o));
|
729
|
-
const i = (o) => async (a, c, d) => {
|
730
|
-
try {
|
731
|
-
const h = { req: a, res: c, next: d, params: a.params, query: a.query, body: a.body };
|
732
|
-
return await o(h);
|
733
|
-
} catch (h) {
|
734
|
-
const E = { req: a, res: c, next: d, params: a.params, query: a.query, body: a.body };
|
735
|
-
return n(h, E);
|
736
|
-
}
|
737
|
-
};
|
738
|
-
return e.get("/", i(async ({ req: o, res: a }) => {
|
739
|
-
const c = o.pagination || { page: 1, limit: 10 }, d = await r.getAll(c);
|
740
|
-
a.json({
|
741
|
-
success: !0,
|
742
|
-
...d
|
743
|
-
});
|
744
|
-
})), e.get("/:id", i(async ({ params: o, res: a }) => {
|
745
|
-
const c = await r.getById(o.id);
|
746
|
-
if (!c) {
|
747
|
-
a.status(404).json({
|
748
|
-
success: !1,
|
749
|
-
error: "Item not found"
|
750
|
-
});
|
751
|
-
return;
|
752
|
-
}
|
753
|
-
a.json({
|
754
|
-
success: !0,
|
755
|
-
data: c
|
756
|
-
});
|
757
|
-
})), e.post("/", i(async ({ body: o, res: a }) => {
|
758
|
-
const c = await r.create(o);
|
759
|
-
a.status(201).json({
|
760
|
-
success: !0,
|
761
|
-
data: c,
|
762
|
-
message: "Item created successfully"
|
763
|
-
});
|
764
|
-
})), e.put("/:id", i(async ({ params: o, body: a, res: c }) => {
|
765
|
-
const d = await r.update(o.id, a);
|
766
|
-
if (!d) {
|
767
|
-
c.status(404).json({
|
768
|
-
success: !1,
|
769
|
-
error: "Item not found"
|
770
|
-
});
|
771
|
-
return;
|
772
|
-
}
|
773
|
-
c.json({
|
774
|
-
success: !0,
|
775
|
-
data: d,
|
776
|
-
message: "Item updated successfully"
|
777
|
-
});
|
778
|
-
})), e.delete("/:id", i(async ({ params: o, res: a }) => {
|
779
|
-
if (!await r.delete(o.id)) {
|
780
|
-
a.status(404).json({
|
781
|
-
success: !1,
|
782
|
-
error: "Item not found"
|
783
|
-
});
|
784
|
-
return;
|
785
|
-
}
|
786
|
-
a.json({
|
787
|
-
success: !0,
|
788
|
-
message: "Item deleted successfully"
|
789
|
-
});
|
790
|
-
})), e;
|
791
|
-
}
|
792
|
-
function lt(r, t = {}) {
|
793
|
-
const e = R.Router(), { middleware: s = [], errorHandler: n = Ae } = t;
|
794
|
-
s.forEach((o) => e.use(o));
|
795
|
-
const i = (o) => async (a, c, d) => {
|
796
|
-
try {
|
797
|
-
const h = { req: a, res: c, next: d, params: a.params, query: a.query, body: a.body };
|
798
|
-
return c.headersSent ? void 0 : await o(h);
|
799
|
-
} catch (h) {
|
800
|
-
if (c.headersSent) {
|
801
|
-
console.error("Error occurred after response was sent:", h);
|
802
|
-
return;
|
803
|
-
}
|
804
|
-
const E = { req: a, res: c, next: d, params: a.params, query: a.query, body: a.body };
|
805
|
-
return n(h, E);
|
806
|
-
}
|
807
|
-
};
|
808
|
-
return Object.entries(r).forEach(([o, a]) => {
|
809
|
-
const { method: c, handler: d } = a;
|
810
|
-
e[c](o, i(d));
|
811
|
-
}), e;
|
812
|
-
}
|
813
|
-
function xe(r, t, e, s, n) {
|
814
|
-
const i = { success: r };
|
815
|
-
return t !== void 0 && (i.data = t), e && (i.message = e), s && (i.error = s), n && (i.meta = n), i;
|
816
|
-
}
|
817
|
-
function P(r, t, e, s = 200, n) {
|
818
|
-
r.status(s).json(xe(!0, t, e, void 0, n));
|
819
|
-
}
|
820
|
-
function L(r, t, e = 400, s) {
|
821
|
-
const n = t instanceof Error ? t.message : t;
|
822
|
-
r.status(e).json(xe(!1, void 0, void 0, n, s));
|
823
|
-
}
|
824
|
-
function ze(r) {
|
825
|
-
const t = parseInt(r.query.page) || 1, e = parseInt(r.query.limit) || 10, s = r.query.sort || "createdAt", n = r.query.order === "asc" ? "asc" : "desc";
|
826
|
-
return { page: t, limit: e, sort: s, order: n };
|
827
|
-
}
|
828
|
-
function Xe(r, t, e) {
|
829
|
-
r.pagination = ze(r), e();
|
830
|
-
}
|
831
|
-
function dt(r) {
|
832
|
-
return (t, e, s) => {
|
833
|
-
try {
|
834
|
-
const { error: n, value: i } = r.validate(t.body);
|
835
|
-
if (n) {
|
836
|
-
L(e, `Validation error: ${n.message}`, 400);
|
837
|
-
return;
|
838
|
-
}
|
839
|
-
t.body = i, s();
|
840
|
-
} catch {
|
841
|
-
L(e, "Validation error", 400);
|
842
|
-
}
|
843
|
-
};
|
844
|
-
}
|
845
|
-
function Ze(r = {}, t) {
|
846
|
-
const e = ae();
|
847
|
-
return r.requireAuth && t && (e.use(t.authenticate), r.requiredRole && e.use(t.hasRole(r.requiredRole))), r.rateLimit && console.warn("Rate limiting is disabled: express-rate-limit dependency is not installed"), e;
|
848
|
-
}
|
849
|
-
function M(r) {
|
850
|
-
return (t, e, s) => {
|
851
|
-
r(t, e, s).catch(s);
|
852
|
-
};
|
853
|
-
}
|
854
|
-
function ft(r) {
|
855
|
-
const t = ae();
|
856
|
-
return t.get("/", Xe, M(async (e, s) => {
|
857
|
-
const n = await r.getAll(e.pagination);
|
858
|
-
P(s, n);
|
859
|
-
})), t.get("/:id", M(async (e, s) => {
|
860
|
-
const n = await r.getById(e.params.id);
|
861
|
-
if (!n)
|
862
|
-
return L(s, "Item not found", 404);
|
863
|
-
P(s, n);
|
864
|
-
})), t.post("/", M(async (e, s) => {
|
865
|
-
const n = await r.create(e.body);
|
866
|
-
P(s, n, "Item created successfully", 201);
|
867
|
-
})), t.put("/:id", M(async (e, s) => {
|
868
|
-
const n = await r.update(e.params.id, e.body);
|
869
|
-
if (!n)
|
870
|
-
return L(s, "Item not found", 404);
|
871
|
-
P(s, n, "Item updated successfully");
|
872
|
-
})), t.delete("/:id", M(async (e, s) => {
|
873
|
-
if (!await r.delete(e.params.id))
|
874
|
-
return L(s, "Item not found", 404);
|
875
|
-
P(s, null, "Item deleted successfully");
|
876
|
-
})), t;
|
877
|
-
}
|
878
731
|
const me = fe.default || fe;
|
879
|
-
class
|
732
|
+
class et {
|
880
733
|
constructor(t) {
|
881
734
|
if (this.loginAttempts = /* @__PURE__ */ new Map(), this.login = async (e, s) => {
|
882
735
|
try {
|
@@ -1073,7 +926,7 @@ class Ke {
|
|
1073
926
|
* Generate a cryptographically secure random token
|
1074
927
|
*/
|
1075
928
|
generateSecureToken(t = 32) {
|
1076
|
-
return
|
929
|
+
return Me.randomBytes(t).toString("hex");
|
1077
930
|
}
|
1078
931
|
/**
|
1079
932
|
* Generate token pair (access token + refresh token)
|
@@ -1164,10 +1017,10 @@ class Ke {
|
|
1164
1017
|
return s ? e > s.resetTime ? (this.loginAttempts.set(t, { count: 1, resetTime: e + 36e5 }), !0) : s.count >= 5 ? !1 : (s.count++, this.loginAttempts.set(t, s), !0) : (this.loginAttempts.set(t, { count: 1, resetTime: e + 36e5 }), !0);
|
1165
1018
|
}
|
1166
1019
|
}
|
1167
|
-
function
|
1168
|
-
return new
|
1020
|
+
function tt(r) {
|
1021
|
+
return new et(r);
|
1169
1022
|
}
|
1170
|
-
function
|
1023
|
+
function rt(r, t) {
|
1171
1024
|
const e = $.model(r, t);
|
1172
1025
|
return {
|
1173
1026
|
getAll: async (s) => {
|
@@ -1267,7 +1120,7 @@ function pt(r, t) {
|
|
1267
1120
|
}
|
1268
1121
|
};
|
1269
1122
|
}
|
1270
|
-
const
|
1123
|
+
const st = {
|
1271
1124
|
String: { type: String },
|
1272
1125
|
Number: { type: Number },
|
1273
1126
|
Boolean: { type: Boolean },
|
@@ -1286,62 +1139,239 @@ const mt = {
|
|
1286
1139
|
Default: (r, t) => ({ ...r, default: t }),
|
1287
1140
|
// Array field type
|
1288
1141
|
Array: (r) => ({ type: [r] })
|
1289
|
-
},
|
1142
|
+
}, Ce = (r, { res: t }) => {
|
1143
|
+
console.error("API Error:", r);
|
1144
|
+
const e = r.status || r.statusCode || 500, s = r.message || "Internal server error";
|
1145
|
+
t.status(e).json({
|
1146
|
+
success: !1,
|
1147
|
+
error: s,
|
1148
|
+
stack: w.env.NODE_ENV !== "production" ? r.stack : void 0
|
1149
|
+
});
|
1150
|
+
};
|
1151
|
+
function nt(r, t = {}) {
|
1152
|
+
const e = O.Router(), { middleware: s = [], errorHandler: n = Ce } = t;
|
1153
|
+
s.forEach((o) => e.use(o));
|
1154
|
+
const i = (o) => async (a, c, d) => {
|
1155
|
+
try {
|
1156
|
+
const h = { req: a, res: c, next: d, params: a.params, query: a.query, body: a.body };
|
1157
|
+
return await o(h);
|
1158
|
+
} catch (h) {
|
1159
|
+
const E = { req: a, res: c, next: d, params: a.params, query: a.query, body: a.body };
|
1160
|
+
return n(h, E);
|
1161
|
+
}
|
1162
|
+
};
|
1163
|
+
return e.get("/", i(async ({ req: o, res: a }) => {
|
1164
|
+
const c = o.pagination || { page: 1, limit: 10 }, d = await r.getAll(c);
|
1165
|
+
a.json({
|
1166
|
+
success: !0,
|
1167
|
+
...d
|
1168
|
+
});
|
1169
|
+
})), e.get("/:id", i(async ({ params: o, res: a }) => {
|
1170
|
+
const c = await r.getById(o.id);
|
1171
|
+
if (!c) {
|
1172
|
+
a.status(404).json({
|
1173
|
+
success: !1,
|
1174
|
+
error: "Item not found"
|
1175
|
+
});
|
1176
|
+
return;
|
1177
|
+
}
|
1178
|
+
a.json({
|
1179
|
+
success: !0,
|
1180
|
+
data: c
|
1181
|
+
});
|
1182
|
+
})), e.post("/", i(async ({ body: o, res: a }) => {
|
1183
|
+
const c = await r.create(o);
|
1184
|
+
a.status(201).json({
|
1185
|
+
success: !0,
|
1186
|
+
data: c,
|
1187
|
+
message: "Item created successfully"
|
1188
|
+
});
|
1189
|
+
})), e.put("/:id", i(async ({ params: o, body: a, res: c }) => {
|
1190
|
+
const d = await r.update(o.id, a);
|
1191
|
+
if (!d) {
|
1192
|
+
c.status(404).json({
|
1193
|
+
success: !1,
|
1194
|
+
error: "Item not found"
|
1195
|
+
});
|
1196
|
+
return;
|
1197
|
+
}
|
1198
|
+
c.json({
|
1199
|
+
success: !0,
|
1200
|
+
data: d,
|
1201
|
+
message: "Item updated successfully"
|
1202
|
+
});
|
1203
|
+
})), e.delete("/:id", i(async ({ params: o, res: a }) => {
|
1204
|
+
if (!await r.delete(o.id)) {
|
1205
|
+
a.status(404).json({
|
1206
|
+
success: !1,
|
1207
|
+
error: "Item not found"
|
1208
|
+
});
|
1209
|
+
return;
|
1210
|
+
}
|
1211
|
+
a.json({
|
1212
|
+
success: !0,
|
1213
|
+
message: "Item deleted successfully"
|
1214
|
+
});
|
1215
|
+
})), e;
|
1216
|
+
}
|
1217
|
+
function ot(r, t = {}) {
|
1218
|
+
const e = O.Router(), { middleware: s = [], errorHandler: n = Ce } = t;
|
1219
|
+
s.forEach((o) => e.use(o));
|
1220
|
+
const i = (o) => async (a, c, d) => {
|
1221
|
+
try {
|
1222
|
+
const h = { req: a, res: c, next: d, params: a.params, query: a.query, body: a.body };
|
1223
|
+
return c.headersSent ? void 0 : await o(h);
|
1224
|
+
} catch (h) {
|
1225
|
+
if (c.headersSent) {
|
1226
|
+
console.error("Error occurred after response was sent:", h);
|
1227
|
+
return;
|
1228
|
+
}
|
1229
|
+
const E = { req: a, res: c, next: d, params: a.params, query: a.query, body: a.body };
|
1230
|
+
return n(h, E);
|
1231
|
+
}
|
1232
|
+
};
|
1233
|
+
return Object.entries(r).forEach(([o, a]) => {
|
1234
|
+
const { method: c, handler: d } = a;
|
1235
|
+
e[c](o, i(d));
|
1236
|
+
}), e;
|
1237
|
+
}
|
1238
|
+
function le(r, t, e, s, n) {
|
1239
|
+
const i = { success: r };
|
1240
|
+
return t !== void 0 && (i.data = t), e && (i.message = e), s && (i.error = s), n && (i.meta = n), i;
|
1241
|
+
}
|
1242
|
+
function R(r, t, e, s = 200, n) {
|
1243
|
+
r.status(s).json(le(!0, t, e, void 0, n));
|
1244
|
+
}
|
1245
|
+
function M(r, t, e = 400, s) {
|
1246
|
+
const n = t instanceof Error ? t.message : t;
|
1247
|
+
r.status(e).json(le(!1, void 0, void 0, n, s));
|
1248
|
+
}
|
1249
|
+
function $e(r) {
|
1250
|
+
const t = parseInt(r.query.page) || 1, e = parseInt(r.query.limit) || 10, s = r.query.sort || "createdAt", n = r.query.order === "asc" ? "asc" : "desc";
|
1251
|
+
return { page: t, limit: e, sort: s, order: n };
|
1252
|
+
}
|
1253
|
+
function je(r, t, e) {
|
1254
|
+
r.pagination = $e(r), e();
|
1255
|
+
}
|
1256
|
+
function it(r) {
|
1257
|
+
return (t, e, s) => {
|
1258
|
+
try {
|
1259
|
+
const { error: n, value: i } = r.validate(t.body);
|
1260
|
+
if (n) {
|
1261
|
+
M(e, `Validation error: ${n.message}`, 400);
|
1262
|
+
return;
|
1263
|
+
}
|
1264
|
+
t.body = i, s();
|
1265
|
+
} catch {
|
1266
|
+
M(e, "Validation error", 400);
|
1267
|
+
}
|
1268
|
+
};
|
1269
|
+
}
|
1270
|
+
function at(r = {}, t) {
|
1271
|
+
const e = ye();
|
1272
|
+
return r.requireAuth && t && (e.use(t.authenticate), r.requiredRole && e.use(t.hasRole(r.requiredRole))), r.rateLimit && console.warn("Rate limiting is disabled: express-rate-limit dependency is not installed"), e;
|
1273
|
+
}
|
1274
|
+
function N(r) {
|
1275
|
+
return (t, e, s) => {
|
1276
|
+
r(t, e, s).catch(s);
|
1277
|
+
};
|
1278
|
+
}
|
1279
|
+
function ct(r) {
|
1280
|
+
const t = ye();
|
1281
|
+
return t.get("/", je, N(async (e, s) => {
|
1282
|
+
const n = await r.getAll(e.pagination);
|
1283
|
+
R(s, n);
|
1284
|
+
})), t.get("/:id", N(async (e, s) => {
|
1285
|
+
const n = await r.getById(e.params.id);
|
1286
|
+
if (!n)
|
1287
|
+
return M(s, "Item not found", 404);
|
1288
|
+
R(s, n);
|
1289
|
+
})), t.post("/", N(async (e, s) => {
|
1290
|
+
const n = await r.create(e.body);
|
1291
|
+
R(s, n, "Item created successfully", 201);
|
1292
|
+
})), t.put("/:id", N(async (e, s) => {
|
1293
|
+
const n = await r.update(e.params.id, e.body);
|
1294
|
+
if (!n)
|
1295
|
+
return M(s, "Item not found", 404);
|
1296
|
+
R(s, n, "Item updated successfully");
|
1297
|
+
})), t.delete("/:id", N(async (e, s) => {
|
1298
|
+
if (!await r.delete(e.params.id))
|
1299
|
+
return M(s, "Item not found", 404);
|
1300
|
+
R(s, null, "Item deleted successfully");
|
1301
|
+
})), t;
|
1302
|
+
}
|
1303
|
+
const wt = {
|
1290
1304
|
// Frontend
|
1291
|
-
jsx:
|
1292
|
-
jsxs:
|
1305
|
+
jsx: ae,
|
1306
|
+
jsxs: Te,
|
1293
1307
|
createElement: se,
|
1294
|
-
Fragment:
|
1295
|
-
Component:
|
1296
|
-
useState:
|
1297
|
-
useEffect:
|
1298
|
-
useRef:
|
1299
|
-
useMemo:
|
1300
|
-
useErrorBoundary:
|
1301
|
-
render:
|
1302
|
-
hydrate:
|
1303
|
-
renderToString:
|
1308
|
+
Fragment: ke,
|
1309
|
+
Component: We,
|
1310
|
+
useState: Ae,
|
1311
|
+
useEffect: Ue,
|
1312
|
+
useRef: Ge,
|
1313
|
+
useMemo: qe,
|
1314
|
+
useErrorBoundary: Je,
|
1315
|
+
render: ue,
|
1316
|
+
hydrate: Qe,
|
1317
|
+
renderToString: P,
|
1304
1318
|
prepareRender: U,
|
1305
1319
|
finishRender: q,
|
1306
|
-
batchUpdates:
|
1320
|
+
batchUpdates: ce,
|
1321
|
+
createContext: Xe,
|
1322
|
+
useContext: Ze,
|
1307
1323
|
// Backend
|
1308
|
-
createServer:
|
1309
|
-
|
1310
|
-
|
1324
|
+
createServer: Ke,
|
1325
|
+
createAuth: tt,
|
1326
|
+
createModel: rt,
|
1327
|
+
FieldTypes: st,
|
1328
|
+
createModelRouter: nt,
|
1329
|
+
createCustomRouter: ot,
|
1330
|
+
createApiRouter: at,
|
1331
|
+
sendSuccess: R,
|
1332
|
+
sendError: M,
|
1333
|
+
apiResponse: le,
|
1334
|
+
getPaginationParams: $e,
|
1335
|
+
paginationMiddleware: je,
|
1336
|
+
validateRequest: it,
|
1337
|
+
asyncHandler: N,
|
1338
|
+
createRestEndpoints: ct,
|
1339
|
+
DatabaseConnector: xe
|
1311
1340
|
};
|
1312
1341
|
export {
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1342
|
+
We as Component,
|
1343
|
+
xe as DatabaseConnector,
|
1344
|
+
st as FieldTypes,
|
1345
|
+
ke as Fragment,
|
1346
|
+
le as apiResponse,
|
1347
|
+
N as asyncHandler,
|
1348
|
+
ce as batchUpdates,
|
1349
|
+
at as createApiRouter,
|
1350
|
+
tt as createAuth,
|
1351
|
+
Xe as createContext,
|
1352
|
+
ot as createCustomRouter,
|
1324
1353
|
se as createElement,
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1354
|
+
rt as createModel,
|
1355
|
+
nt as createModelRouter,
|
1356
|
+
ct as createRestEndpoints,
|
1357
|
+
Ke as createServer,
|
1358
|
+
wt as default,
|
1330
1359
|
q as finishRender,
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1360
|
+
$e as getPaginationParams,
|
1361
|
+
Qe as hydrate,
|
1362
|
+
ae as jsx,
|
1363
|
+
Te as jsxs,
|
1364
|
+
je as paginationMiddleware,
|
1336
1365
|
U as prepareRender,
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
Ue as
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1366
|
+
ue as render,
|
1367
|
+
P as renderToString,
|
1368
|
+
M as sendError,
|
1369
|
+
R as sendSuccess,
|
1370
|
+
Ze as useContext,
|
1371
|
+
Ue as useEffect,
|
1372
|
+
Je as useErrorBoundary,
|
1373
|
+
qe as useMemo,
|
1374
|
+
Ge as useRef,
|
1375
|
+
Ae as useState,
|
1376
|
+
it as validateRequest
|
1347
1377
|
};
|