speedly 1.2.48 → 2.0.5

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 (67) hide show
  1. package/dist/cjs/auth/auth2.d.ts +18 -0
  2. package/dist/cjs/auth/auth2.js +93 -0
  3. package/dist/cjs/config/init.d.ts +15 -0
  4. package/dist/cjs/config/init.js +58 -0
  5. package/dist/cjs/db/db.d.ts +65 -66
  6. package/dist/cjs/db/db.js +15 -22
  7. package/dist/cjs/document/index.d.ts +2 -0
  8. package/dist/cjs/document/index.js +7 -0
  9. package/dist/cjs/index.d.ts +3 -53
  10. package/dist/cjs/index.js +7 -22
  11. package/dist/cjs/kit/auth/auth.d.ts +3 -0
  12. package/dist/cjs/kit/auth/auth.js +38 -0
  13. package/dist/cjs/kit/auth/types.d.ts +19 -0
  14. package/dist/cjs/kit/auth/types.js +2 -0
  15. package/dist/cjs/kit/db/db.d.ts +182 -0
  16. package/dist/cjs/kit/db/db.js +594 -0
  17. package/dist/cjs/kit/db/utils.d.ts +3 -0
  18. package/dist/cjs/kit/db/utils.js +15 -0
  19. package/dist/cjs/kit/index.d.ts +5 -0
  20. package/dist/cjs/kit/index.js +14 -0
  21. package/dist/cjs/kit/uploader/uploader.d.ts +24 -0
  22. package/dist/cjs/kit/uploader/uploader.js +148 -0
  23. package/dist/cjs/kit/validator/validator.d.ts +9 -0
  24. package/dist/cjs/kit/validator/validator.js +36 -0
  25. package/dist/cjs/model/index.d.ts +2 -0
  26. package/dist/cjs/model/index.js +8 -0
  27. package/dist/cjs/model/translation.d.ts +24 -6
  28. package/dist/cjs/modules/index.d.ts +2 -0
  29. package/dist/cjs/modules/index.js +8 -0
  30. package/dist/cjs/modules/translation/translation.routes.js +12 -8
  31. package/dist/cjs/util/index.d.ts +2 -0
  32. package/dist/cjs/util/index.js +8 -0
  33. package/dist/cjs/util/makeOptional.js +17 -7
  34. package/dist/cjs/yup.config.d.ts +2 -0
  35. package/dist/cjs/yup.config.js +24 -0
  36. package/dist/esm/config/init.d.ts +15 -0
  37. package/dist/esm/config/init.js +58 -0
  38. package/dist/esm/db/db.d.ts +65 -66
  39. package/dist/esm/db/db.js +15 -22
  40. package/dist/esm/document/index.d.ts +2 -0
  41. package/dist/esm/document/index.js +7 -0
  42. package/dist/esm/index.d.ts +3 -53
  43. package/dist/esm/index.js +7 -22
  44. package/dist/esm/kit/auth/auth.d.ts +3 -0
  45. package/dist/esm/kit/auth/auth.js +38 -0
  46. package/dist/esm/kit/auth/types.d.ts +19 -0
  47. package/dist/esm/kit/auth/types.js +2 -0
  48. package/dist/esm/kit/db/db.d.ts +182 -0
  49. package/dist/esm/kit/db/db.js +594 -0
  50. package/dist/esm/kit/db/utils.d.ts +3 -0
  51. package/dist/esm/kit/db/utils.js +15 -0
  52. package/dist/esm/kit/index.d.ts +5 -0
  53. package/dist/esm/kit/index.js +14 -0
  54. package/dist/esm/kit/uploader/uploader.d.ts +24 -0
  55. package/dist/esm/kit/uploader/uploader.js +148 -0
  56. package/dist/esm/kit/validator/validator.d.ts +9 -0
  57. package/dist/esm/kit/validator/validator.js +36 -0
  58. package/dist/esm/model/index.d.ts +2 -0
  59. package/dist/esm/model/index.js +8 -0
  60. package/dist/esm/model/translation.d.ts +24 -6
  61. package/dist/esm/modules/index.d.ts +2 -0
  62. package/dist/esm/modules/index.js +8 -0
  63. package/dist/esm/modules/translation/translation.routes.js +12 -8
  64. package/dist/esm/util/index.d.ts +2 -0
  65. package/dist/esm/util/index.js +8 -0
  66. package/dist/esm/util/makeOptional.js +17 -7
  67. package/package.json +1 -1
@@ -0,0 +1,18 @@
1
+ import { Request, Response, NextFunction } from "express";
2
+ type Handler = (req: Request, res: Response, next: (errorMessage?: string) => unknown) => unknown;
3
+ type UseAuth = (req: Request, res: Response, next: NextFunction) => UseAuth | {
4
+ user?: (...handlers: Handler[]) => unknown;
5
+ admin?: (...handlers: [{
6
+ permission: string;
7
+ }, ...Handler[]] | Handler[]) => unknown;
8
+ any?: (...handlers: Handler[]) => unknown;
9
+ };
10
+ declare const auth: (config?: {
11
+ admin: {
12
+ role: string;
13
+ model: string;
14
+ };
15
+ jwtSecretEnv: string;
16
+ customValidator: (req: Request, key: string) => boolean;
17
+ }) => UseAuth;
18
+ export default auth;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const getConfig_1 = __importDefault(require("../util/getConfig"));
7
+ const gConfig = {
8
+ admin: { role: "ADMIN", model: "../models/admin" },
9
+ jwtSecretEnv: "JWT_KEY",
10
+ customValidator: (req, key) => {
11
+ return true;
12
+ },
13
+ ...(0, getConfig_1.default)("auth"),
14
+ };
15
+ const holders = {};
16
+ const auth = (config = gConfig) => {
17
+ // const adminModel = require('../models/admin')
18
+ let handlerState = {};
19
+ let useAuth = async (req, res, next) => {
20
+ try {
21
+ const nextFunc = (handlers, index = 0) => (errorMessage = "") => {
22
+ if (errorMessage)
23
+ return next(errorMessage);
24
+ if (!handlers.length || !handlers[index + 1])
25
+ return next();
26
+ handlers[index + 1](req, res, nextFunc(handlers, index + 1));
27
+ };
28
+ const keys = Object.keys(handlerState);
29
+ for (let i = 0; i < keys.length; i++) {
30
+ const key = keys[i];
31
+ if (!handlerState[key]?.handlers?.length)
32
+ continue;
33
+ if (await gConfig?.customValidator?.(req, key)) {
34
+ return await handlerState[key].handlers[0](req, res, nextFunc(handlerState[key].handlers));
35
+ }
36
+ else if ((await gConfig?.customValidator?.(req, key)) == null) {
37
+ return next({ status: 401, json: { message: "unauthorized" } });
38
+ }
39
+ else if (i === keys.length - 1) {
40
+ next({
41
+ status: 405,
42
+ json: { message: "you don't have access to this section" },
43
+ });
44
+ }
45
+ else
46
+ continue;
47
+ }
48
+ }
49
+ catch (error) {
50
+ console.log("auth", 42, error);
51
+ next({
52
+ status: 403,
53
+ json: {
54
+ message: error instanceof Error
55
+ ? error.message
56
+ : "error on authentication please login again",
57
+ },
58
+ });
59
+ }
60
+ };
61
+ holders.admin = (...handlers) => {
62
+ if (!Array.isArray(handlers))
63
+ throw new Error("handlers must be an array");
64
+ const hasConfig = typeof handlers[0] === "object" && "permission" in handlers[0];
65
+ const configObj = hasConfig
66
+ ? handlers[0]
67
+ : undefined;
68
+ const handlerFns = hasConfig
69
+ ? handlers.slice(1)
70
+ : handlers;
71
+ handlerState[`admin${configObj?.permission ? `:${configObj.permission}` : ""}`] = {
72
+ ...(configObj ? { config: configObj } : {}),
73
+ handlers: handlerFns,
74
+ };
75
+ return useAuth;
76
+ };
77
+ holders.user = (...handlers) => {
78
+ if (!Array.isArray(handlers))
79
+ throw new Error("handlers must be an array");
80
+ handlerState.user = { handlers };
81
+ return useAuth;
82
+ };
83
+ holders.any = (...handlers) => {
84
+ if (!Array.isArray(handlers))
85
+ throw new Error("handlers must be an array");
86
+ handlerState.any = { handlers };
87
+ return useAuth;
88
+ };
89
+ useAuth = Object.assign(useAuth, holders);
90
+ return useAuth;
91
+ };
92
+ console.log("auth", 81, typeof auth);
93
+ exports.default = auth;
@@ -0,0 +1,15 @@
1
+ import express from "express";
2
+ type InitConfig = {
3
+ notFoundHandler?: boolean;
4
+ errorHandler?: boolean;
5
+ jsonParser?: boolean;
6
+ urlEncodedParser?: boolean;
7
+ cookieParser?: boolean;
8
+ staticFiles?: boolean;
9
+ [key: string]: any;
10
+ };
11
+ export default function speedly(config?: InitConfig): express.Express & {
12
+ speedlyConfig: InitConfig;
13
+ registerFallbacks: () => void;
14
+ };
15
+ export {};
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = speedly;
7
+ const express_1 = __importDefault(require("express"));
8
+ const defaultConfig = {
9
+ notFoundHandler: true,
10
+ errorHandler: true,
11
+ jsonParser: true,
12
+ urlEncodedParser: true,
13
+ cookieParser: true,
14
+ staticFiles: true,
15
+ };
16
+ function speedly(config = {}) {
17
+ const finalConfig = { ...defaultConfig, ...config };
18
+ const app = (0, express_1.default)();
19
+ if (finalConfig.jsonParser)
20
+ app.use(express_1.default.json());
21
+ if (finalConfig.urlEncodedParser)
22
+ app.use(express_1.default.urlencoded({ extended: true }));
23
+ if (finalConfig.cookieParser) {
24
+ try {
25
+ const cookieParser = require("cookie-parser");
26
+ app.use(cookieParser());
27
+ }
28
+ catch (error) {
29
+ if (error.code === "MODULE_NOT_FOUND") {
30
+ console.warn("cookie-parser module not found. Please install it to use cookieParser middleware.");
31
+ }
32
+ }
33
+ }
34
+ if (finalConfig.staticFiles)
35
+ app.use("/static", express_1.default.static("public"));
36
+ // user can call this manually if needed
37
+ const registerFallbacks = () => {
38
+ if (finalConfig.notFoundHandler) {
39
+ app.use((req, res) => res.status(404).json({ message: "Not Found" }));
40
+ }
41
+ if (finalConfig.errorHandler) {
42
+ app.use((error, req, res, next) => {
43
+ console.error("Speedly Error:", error);
44
+ res.status(500).json({ message: "Internal Server Error" });
45
+ });
46
+ }
47
+ };
48
+ // ⛔ we intercept listen, add fallback before server starts
49
+ const originalListen = app.listen.bind(app);
50
+ app.listen = (...args) => {
51
+ registerFallbacks();
52
+ return originalListen(...args);
53
+ };
54
+ // 🔓 expose config + extend points for override
55
+ app.speedlyConfig = finalConfig;
56
+ app.registerFallbacks = registerFallbacks;
57
+ return app;
58
+ }
@@ -13,7 +13,6 @@ type ConfigsType = {
13
13
  dbType?: string;
14
14
  path?: string;
15
15
  dbEnv?: string;
16
- response?: boolean;
17
16
  type: "internal" | "external";
18
17
  pagination?: {
19
18
  quantity?: number;
@@ -27,157 +26,157 @@ declare const db: (collectionName: string, config?: ConfigsType) => {
27
26
  (req: Request, res: Response, next: NextFunction): Promise<void>;
28
27
  select(value: string | {
29
28
  [key: string]: -1 | 1;
30
- }): any;
29
+ }): /*elided*/ any;
31
30
  sort(value: string | {
32
31
  [key: string]: -1 | 1;
33
- }): any;
34
- skip(value: number): any;
35
- limit(value: number): any;
36
- populate(value: string | object | (string | object)[]): any;
32
+ }): /*elided*/ any;
33
+ skip(value: number): /*elided*/ any;
34
+ limit(value: number): /*elided*/ any;
35
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
37
36
  };
38
37
  create: (body?: {}) => {
39
38
  (req: Request, res: Response, next: NextFunction): Promise<void>;
40
39
  select(value: string | {
41
40
  [key: string]: -1 | 1;
42
- }): any;
41
+ }): /*elided*/ any;
43
42
  sort(value: string | {
44
43
  [key: string]: -1 | 1;
45
- }): any;
46
- skip(value: number): any;
47
- limit(value: number): any;
48
- populate(value: string | object | (string | object)[]): any;
44
+ }): /*elided*/ any;
45
+ skip(value: number): /*elided*/ any;
46
+ limit(value: number): /*elided*/ any;
47
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
49
48
  };
50
49
  updateOne: (match?: {}, body?: {}) => {
51
50
  (req: Request, res: Response, next: NextFunction): Promise<void>;
52
51
  select(value: string | {
53
52
  [key: string]: -1 | 1;
54
- }): any;
53
+ }): /*elided*/ any;
55
54
  sort(value: string | {
56
55
  [key: string]: -1 | 1;
57
- }): any;
58
- skip(value: number): any;
59
- limit(value: number): any;
60
- populate(value: string | object | (string | object)[]): any;
56
+ }): /*elided*/ any;
57
+ skip(value: number): /*elided*/ any;
58
+ limit(value: number): /*elided*/ any;
59
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
61
60
  };
62
61
  updateMany: (match?: {}, body?: {}) => {
63
62
  (req: Request, res: Response, next: NextFunction): Promise<void>;
64
63
  select(value: string | {
65
64
  [key: string]: -1 | 1;
66
- }): any;
65
+ }): /*elided*/ any;
67
66
  sort(value: string | {
68
67
  [key: string]: -1 | 1;
69
- }): any;
70
- skip(value: number): any;
71
- limit(value: number): any;
72
- populate(value: string | object | (string | object)[]): any;
68
+ }): /*elided*/ any;
69
+ skip(value: number): /*elided*/ any;
70
+ limit(value: number): /*elided*/ any;
71
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
73
72
  };
74
73
  deleteOne: (match?: {}) => {
75
74
  (req: Request, res: Response, next: NextFunction): Promise<void>;
76
75
  select(value: string | {
77
76
  [key: string]: -1 | 1;
78
- }): any;
77
+ }): /*elided*/ any;
79
78
  sort(value: string | {
80
79
  [key: string]: -1 | 1;
81
- }): any;
82
- skip(value: number): any;
83
- limit(value: number): any;
84
- populate(value: string | object | (string | object)[]): any;
80
+ }): /*elided*/ any;
81
+ skip(value: number): /*elided*/ any;
82
+ limit(value: number): /*elided*/ any;
83
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
85
84
  };
86
85
  deleteMany: (match?: {}) => {
87
86
  (req: Request, res: Response, next: NextFunction): Promise<void>;
88
87
  select(value: string | {
89
88
  [key: string]: -1 | 1;
90
- }): any;
89
+ }): /*elided*/ any;
91
90
  sort(value: string | {
92
91
  [key: string]: -1 | 1;
93
- }): any;
94
- skip(value: number): any;
95
- limit(value: number): any;
96
- populate(value: string | object | (string | object)[]): any;
92
+ }): /*elided*/ any;
93
+ skip(value: number): /*elided*/ any;
94
+ limit(value: number): /*elided*/ any;
95
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
97
96
  };
98
97
  findOne: (match?: {}) => {
99
98
  (req: Request, res: Response, next: NextFunction): Promise<void>;
100
99
  select(value: string | {
101
100
  [key: string]: -1 | 1;
102
- }): any;
101
+ }): /*elided*/ any;
103
102
  sort(value: string | {
104
103
  [key: string]: -1 | 1;
105
- }): any;
106
- skip(value: number): any;
107
- limit(value: number): any;
108
- populate(value: string | object | (string | object)[]): any;
104
+ }): /*elided*/ any;
105
+ skip(value: number): /*elided*/ any;
106
+ limit(value: number): /*elided*/ any;
107
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
109
108
  };
110
109
  findOneAndUpdate: (match?: {}, body?: {}) => {
111
110
  (req: Request, res: Response, next: NextFunction): Promise<void>;
112
111
  select(value: string | {
113
112
  [key: string]: -1 | 1;
114
- }): any;
113
+ }): /*elided*/ any;
115
114
  sort(value: string | {
116
115
  [key: string]: -1 | 1;
117
- }): any;
118
- skip(value: number): any;
119
- limit(value: number): any;
120
- populate(value: string | object | (string | object)[]): any;
116
+ }): /*elided*/ any;
117
+ skip(value: number): /*elided*/ any;
118
+ limit(value: number): /*elided*/ any;
119
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
121
120
  };
122
121
  aggregate: (pipeline?: never[]) => {
123
122
  (req: Request, res: Response, next: NextFunction): Promise<void>;
124
123
  select(value: string | {
125
124
  [key: string]: -1 | 1;
126
- }): any;
125
+ }): /*elided*/ any;
127
126
  sort(value: string | {
128
127
  [key: string]: -1 | 1;
129
- }): any;
130
- skip(value: number): any;
131
- limit(value: number): any;
132
- populate(value: string | object | (string | object)[]): any;
128
+ }): /*elided*/ any;
129
+ skip(value: number): /*elided*/ any;
130
+ limit(value: number): /*elided*/ any;
131
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
133
132
  };
134
133
  findOneAndDelete: (match?: {}) => {
135
134
  (req: Request, res: Response, next: NextFunction): Promise<void>;
136
135
  select(value: string | {
137
136
  [key: string]: -1 | 1;
138
- }): any;
137
+ }): /*elided*/ any;
139
138
  sort(value: string | {
140
139
  [key: string]: -1 | 1;
141
- }): any;
142
- skip(value: number): any;
143
- limit(value: number): any;
144
- populate(value: string | object | (string | object)[]): any;
140
+ }): /*elided*/ any;
141
+ skip(value: number): /*elided*/ any;
142
+ limit(value: number): /*elided*/ any;
143
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
145
144
  };
146
145
  findById: (id?: string) => {
147
146
  (req: Request, res: Response, next: NextFunction): Promise<void>;
148
147
  select(value: string | {
149
148
  [key: string]: -1 | 1;
150
- }): any;
149
+ }): /*elided*/ any;
151
150
  sort(value: string | {
152
151
  [key: string]: -1 | 1;
153
- }): any;
154
- skip(value: number): any;
155
- limit(value: number): any;
156
- populate(value: string | object | (string | object)[]): any;
152
+ }): /*elided*/ any;
153
+ skip(value: number): /*elided*/ any;
154
+ limit(value: number): /*elided*/ any;
155
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
157
156
  };
158
157
  findByIdAndUpdate: (id?: string, body?: {}) => {
159
158
  (req: Request, res: Response, next: NextFunction): Promise<void>;
160
159
  select(value: string | {
161
160
  [key: string]: -1 | 1;
162
- }): any;
161
+ }): /*elided*/ any;
163
162
  sort(value: string | {
164
163
  [key: string]: -1 | 1;
165
- }): any;
166
- skip(value: number): any;
167
- limit(value: number): any;
168
- populate(value: string | object | (string | object)[]): any;
164
+ }): /*elided*/ any;
165
+ skip(value: number): /*elided*/ any;
166
+ limit(value: number): /*elided*/ any;
167
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
169
168
  };
170
169
  findByIdAndDelete: (id?: string) => {
171
170
  (req: Request, res: Response, next: NextFunction): Promise<void>;
172
171
  select(value: string | {
173
172
  [key: string]: -1 | 1;
174
- }): any;
173
+ }): /*elided*/ any;
175
174
  sort(value: string | {
176
175
  [key: string]: -1 | 1;
177
- }): any;
178
- skip(value: number): any;
179
- limit(value: number): any;
180
- populate(value: string | object | (string | object)[]): any;
176
+ }): /*elided*/ any;
177
+ skip(value: number): /*elided*/ any;
178
+ limit(value: number): /*elided*/ any;
179
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
181
180
  };
182
181
  } | undefined;
183
182
  export default db;
package/dist/cjs/db/db.js CHANGED
@@ -14,7 +14,6 @@ let configs = {
14
14
  path: "../models",
15
15
  type: "external",
16
16
  dbEnv: "DB_URL",
17
- response: true,
18
17
  ...(0, getConfig_1.default)("db"),
19
18
  };
20
19
  const usingMongoDb = (collectionName, config = { type: "external" }) => {
@@ -486,26 +485,21 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
486
485
  : []);
487
486
  }
488
487
  }
489
- if (config?.response) {
490
- const action = queryState.action?.match(/create|update|delet/i)?.[0] || "find";
491
- const resBody = queryState.action == "aggregate"
492
- ? {
493
- message: config?.message ||
494
- `the ${collectionName} was found successfully`,
495
- content: [],
496
- ...data[0],
497
- }
498
- : {
499
- content: data,
500
- ...{ detail: Object.keys(detail).length ? detail : undefined },
501
- message: config?.message ||
502
- `the ${collectionName} was ${action == "find" ? "found" : action + "ed"}`,
503
- };
504
- res.success ? res.success(200, resBody) : res.status(200).json(resBody);
505
- }
506
- else {
507
- next();
508
- }
488
+ const action = queryState.action?.match(/create|update|delet/i)?.[0] || "find";
489
+ const resBody = queryState.action == "aggregate"
490
+ ? {
491
+ message: config?.message ||
492
+ `the ${collectionName} was found successfully`,
493
+ content: [],
494
+ ...data[0],
495
+ }
496
+ : {
497
+ content: data,
498
+ ...{ detail: Object.keys(detail).length ? detail : undefined },
499
+ message: config?.message ||
500
+ `the ${collectionName} was ${action == "find" ? "found" : action + "ed"}`,
501
+ };
502
+ res.success ? res.success(200, resBody) : res.status(200).json(resBody);
509
503
  }
510
504
  }
511
505
  catch (err) {
@@ -585,7 +579,6 @@ const db = (collectionName, config = configs) => {
585
579
  path: "../models",
586
580
  dbEnv: "DB_URL",
587
581
  type: "external",
588
- response: true,
589
582
  ...(0, getConfig_1.default)("db"),
590
583
  };
591
584
  Object.entries(config).forEach(([key, value]) => {
@@ -0,0 +1,2 @@
1
+ import document from "./document";
2
+ export default document;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const document_1 = __importDefault(require("./document"));
7
+ exports.default = document_1.default;
@@ -1,53 +1,3 @@
1
- import auth from "./auth/auth";
2
- import db from "./db/db";
3
- import uploader from "./uploader/uploader";
4
- import validator from "./validator/validator";
5
- import document from "./document/document";
6
- declare const utils: {
7
- translator: (text?: string, lang?: string) => Promise<unknown>;
8
- };
9
- declare const models: {
10
- translation: import("mongoose").Model<{
11
- text: string;
12
- lang: string;
13
- translatedText: string;
14
- } & import("mongoose").DefaultTimestampProps, {}, {}, {}, import("mongoose").Document<unknown, {}, {
15
- text: string;
16
- lang: string;
17
- translatedText: string;
18
- } & import("mongoose").DefaultTimestampProps, {}, {
19
- timestamps: true;
20
- }> & {
21
- text: string;
22
- lang: string;
23
- translatedText: string;
24
- } & import("mongoose").DefaultTimestampProps & {
25
- _id: import("mongoose").Types.ObjectId;
26
- } & {
27
- __v: number;
28
- }, import("mongoose").Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
29
- timestamps: true;
30
- }, {
31
- text: string;
32
- lang: string;
33
- translatedText: string;
34
- } & import("mongoose").DefaultTimestampProps, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
35
- text: string;
36
- lang: string;
37
- translatedText: string;
38
- } & import("mongoose").DefaultTimestampProps>, {}, import("mongoose").ResolveSchemaOptions<{
39
- timestamps: true;
40
- }>> & import("mongoose").FlatRecord<{
41
- text: string;
42
- lang: string;
43
- translatedText: string;
44
- } & import("mongoose").DefaultTimestampProps> & {
45
- _id: import("mongoose").Types.ObjectId;
46
- } & {
47
- __v: number;
48
- }>>;
49
- };
50
- declare const modules: {
51
- translation: import("express-serve-static-core").Router;
52
- };
53
- export { auth, db, uploader, validator, models, modules, utils, document };
1
+ import speedly from "./config/init";
2
+ export { Request, Response, NextFunction, Application, Router, RequestHandler, ErrorRequestHandler, } from "express";
3
+ export default speedly;
package/dist/cjs/index.js CHANGED
@@ -3,25 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.document = exports.utils = exports.modules = exports.models = exports.validator = exports.uploader = exports.db = exports.auth = void 0;
7
- const auth_1 = __importDefault(require("./auth/auth"));
8
- exports.auth = auth_1.default;
9
- const db_1 = __importDefault(require("./db/db"));
10
- exports.db = db_1.default;
11
- const uploader_1 = __importDefault(require("./uploader/uploader"));
12
- exports.uploader = uploader_1.default;
13
- const validator_1 = __importDefault(require("./validator/validator"));
14
- exports.validator = validator_1.default;
15
- const translation_1 = __importDefault(require("./model/translation"));
16
- const translation_routes_1 = __importDefault(require("./modules/translation/translation.routes"));
17
- const document_1 = __importDefault(require("./document/document"));
18
- exports.document = document_1.default;
19
- const translator_1 = __importDefault(require("./util/translator"));
20
- const utils = {
21
- translator: translator_1.default,
22
- };
23
- exports.utils = utils;
24
- const models = { translation: translation_1.default };
25
- exports.models = models;
26
- const modules = { translation: translation_routes_1.default };
27
- exports.modules = modules;
6
+ exports.Router = void 0;
7
+ const init_1 = __importDefault(require("./config/init"));
8
+ // Export express types and classes
9
+ var express_1 = require("express");
10
+ Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return express_1.Router; } });
11
+ // Override the default express() with our speedly`s functions
12
+ exports.default = init_1.default;
@@ -0,0 +1,3 @@
1
+ import * as Types from "./types";
2
+ declare const auth: Types.Auth;
3
+ export default auth;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const getConfig_1 = __importDefault(require("../../util/getConfig"));
7
+ const gConfig = {
8
+ admin: { role: "ADMIN", model: "../models/admin" },
9
+ jwtSecretEnv: "JWT_KEY",
10
+ customValidator: (req, key) => {
11
+ return true;
12
+ },
13
+ ...(0, getConfig_1.default)("auth"),
14
+ };
15
+ const executer = (authType) => {
16
+ const mw = async (req, res, next) => {
17
+ const accessResult = await gConfig?.customValidator?.(req, authType);
18
+ if (accessResult == null)
19
+ return next({ status: 401, json: { message: "Unauthorized" } });
20
+ if (!accessResult)
21
+ return next({ status: 403, json: { message: "Forbidden" } });
22
+ return next();
23
+ };
24
+ Object.defineProperty(mw, "name", { value: `auth:${authType}` });
25
+ return mw;
26
+ };
27
+ const auth = {
28
+ user: () => {
29
+ return executer("user");
30
+ },
31
+ admin: (config) => {
32
+ return executer(`admin${config?.permission ? `:${config.permission}` : ""}`);
33
+ },
34
+ any: () => {
35
+ return executer("any");
36
+ },
37
+ };
38
+ exports.default = auth;
@@ -0,0 +1,19 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ type Handler = (req: Request, res: Response, next: (errorMessage?: string) => unknown) => unknown;
3
+ type Executer = (authField: string) => (req: Request, res: Response, next: NextFunction) => unknown;
4
+ type Auth = {
5
+ user: () => Handler;
6
+ admin: (config?: {
7
+ permission: string;
8
+ }) => Handler;
9
+ any: () => Handler;
10
+ };
11
+ type ConfigType = {
12
+ customValidator?: (req: Request, key: string) => Promise<boolean | null>;
13
+ jwtSecretEnv?: string;
14
+ admin?: {
15
+ role: string;
16
+ model: string;
17
+ };
18
+ };
19
+ export { Handler, Executer, Auth, ConfigType };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });