lupine.api 1.1.58 → 1.1.59

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 (137) hide show
  1. package/README.md +3 -3
  2. package/admin/admin-about.tsx +12 -16
  3. package/admin/admin-config.tsx +47 -44
  4. package/admin/admin-css.tsx +3 -3
  5. package/admin/admin-db.tsx +75 -75
  6. package/admin/admin-frame-helper.tsx +364 -364
  7. package/admin/admin-frame.tsx +164 -164
  8. package/admin/admin-index.tsx +65 -65
  9. package/admin/admin-login.tsx +111 -111
  10. package/admin/admin-menu-edit.tsx +637 -637
  11. package/admin/admin-menu-list.tsx +87 -87
  12. package/admin/admin-page-edit.tsx +564 -564
  13. package/admin/admin-page-list.tsx +83 -83
  14. package/admin/admin-performance.tsx +28 -28
  15. package/admin/admin-release.tsx +427 -426
  16. package/admin/admin-resources.tsx +382 -382
  17. package/admin/admin-shell.tsx +89 -89
  18. package/admin/admin-table-data.tsx +146 -146
  19. package/admin/admin-table-list.tsx +230 -230
  20. package/admin/admin-test-animations.tsx +395 -395
  21. package/admin/admin-test-component.tsx +823 -808
  22. package/admin/admin-test-edit.tsx +319 -319
  23. package/admin/admin-test-themes.tsx +56 -56
  24. package/admin/admin-tokens.tsx +338 -338
  25. package/admin/design/admin-design.tsx +174 -174
  26. package/admin/design/block-grid.tsx +36 -36
  27. package/admin/design/block-grid1.tsx +21 -21
  28. package/admin/design/block-paragraph.tsx +19 -19
  29. package/admin/design/block-title.tsx +19 -19
  30. package/admin/design/design-block-box.tsx +140 -140
  31. package/admin/design/drag-data.tsx +24 -24
  32. package/admin/index.ts +9 -9
  33. package/admin/package.json +15 -15
  34. package/admin/tsconfig.json +127 -127
  35. package/dev/copy-folder.js +32 -32
  36. package/dev/cp-index-html.js +69 -69
  37. package/dev/file-utils.js +12 -12
  38. package/dev/index.js +18 -19
  39. package/dev/package.json +12 -12
  40. package/dev/plugin-ifelse.js +168 -168
  41. package/dev/plugin-ifelse.test.js +37 -37
  42. package/dev/run-cmd.js +14 -14
  43. package/dev/send-request.js +12 -12
  44. package/package.json +55 -55
  45. package/src/admin-api/admin-api-helper.ts +210 -205
  46. package/src/admin-api/admin-api.ts +65 -65
  47. package/src/admin-api/admin-auth.ts +152 -146
  48. package/src/admin-api/admin-config.ts +94 -84
  49. package/src/admin-api/admin-csv.ts +94 -94
  50. package/src/admin-api/admin-db.ts +269 -269
  51. package/src/admin-api/admin-menu.ts +135 -135
  52. package/src/admin-api/admin-page.ts +135 -135
  53. package/src/admin-api/admin-performance.ts +128 -128
  54. package/src/admin-api/admin-release.ts +703 -700
  55. package/src/admin-api/admin-resources.ts +318 -318
  56. package/src/admin-api/admin-token-helper.ts +82 -79
  57. package/src/admin-api/admin-tokens.ts +90 -90
  58. package/src/admin-api/index.ts +2 -2
  59. package/src/admin-api/web-config-api.ts +19 -19
  60. package/src/api/api-cache.ts +103 -103
  61. package/src/api/api-helper.ts +44 -44
  62. package/src/api/api-module.ts +67 -60
  63. package/src/api/api-router.ts +177 -177
  64. package/src/api/api-shared-storage.ts +64 -64
  65. package/src/api/async-storage.ts +5 -5
  66. package/src/api/debug-service.ts +56 -56
  67. package/src/api/encode-html.ts +27 -27
  68. package/src/api/handle-status.ts +75 -75
  69. package/src/api/index.ts +15 -16
  70. package/src/api/mini-web-socket.ts +270 -270
  71. package/src/api/server-content-type.ts +82 -82
  72. package/src/api/server-render.ts +235 -215
  73. package/src/api/shell-service.ts +74 -74
  74. package/src/api/simple-storage.ts +80 -80
  75. package/src/api/static-server.ts +128 -125
  76. package/src/api/to-client-delivery.ts +26 -26
  77. package/src/app/app-cache.ts +55 -55
  78. package/src/app/app-helper.ts +62 -62
  79. package/src/app/app-message.ts +109 -109
  80. package/src/app/app-shared-storage.ts +363 -363
  81. package/src/app/app-start.ts +136 -136
  82. package/src/app/cleanup-exit.ts +16 -16
  83. package/src/app/host-to-path.ts +38 -38
  84. package/src/app/index.ts +11 -11
  85. package/src/app/process-dev-requests.ts +130 -130
  86. package/src/app/web-listener.ts +294 -294
  87. package/src/app/web-processor.ts +47 -42
  88. package/src/app/web-server.ts +100 -100
  89. package/src/common-js/web-env.js +104 -104
  90. package/src/index.ts +7 -7
  91. package/src/lang/api-lang-en.ts +26 -26
  92. package/src/lang/api-lang-zh-cn.ts +27 -27
  93. package/src/lang/index.ts +2 -2
  94. package/src/lang/lang-helper.ts +76 -76
  95. package/src/lang/lang-props.ts +6 -6
  96. package/src/lib/db/db-helper.ts +23 -23
  97. package/src/lib/db/db-mysql.ts +249 -250
  98. package/src/lib/db/db-sqlite.ts +101 -101
  99. package/src/lib/db/db.spec.ts +28 -28
  100. package/src/lib/db/db.ts +325 -325
  101. package/src/lib/db/index.ts +5 -5
  102. package/src/lib/index.ts +3 -3
  103. package/src/lib/logger.spec.ts +214 -214
  104. package/src/lib/logger.ts +281 -281
  105. package/src/lib/runtime-require.ts +37 -37
  106. package/src/lib/utils/cookie-util.ts +34 -34
  107. package/src/lib/utils/crypto.ts +58 -58
  108. package/src/lib/utils/date-utils.ts +317 -317
  109. package/src/lib/utils/deep-merge.ts +37 -37
  110. package/src/lib/utils/delay.ts +12 -12
  111. package/src/lib/utils/file-setting.ts +55 -55
  112. package/src/lib/utils/format-bytes.ts +11 -11
  113. package/src/lib/utils/fs-utils.ts +158 -158
  114. package/src/lib/utils/get-env.ts +27 -27
  115. package/src/lib/utils/index.ts +12 -12
  116. package/src/lib/utils/is-type.ts +48 -48
  117. package/src/lib/utils/load-env.ts +14 -14
  118. package/src/lib/utils/pad.ts +6 -6
  119. package/src/models/api-base.ts +5 -5
  120. package/src/models/api-module-props.ts +10 -11
  121. package/src/models/api-router-props.ts +26 -26
  122. package/src/models/app-cache-props.ts +33 -33
  123. package/src/models/app-data-props.ts +10 -10
  124. package/src/models/app-helper-props.ts +6 -6
  125. package/src/models/app-shared-storage-props.ts +38 -38
  126. package/src/models/app-start-props.ts +18 -18
  127. package/src/models/async-storage-props.ts +13 -13
  128. package/src/models/db-config.ts +30 -30
  129. package/src/models/host-to-path-props.ts +12 -12
  130. package/src/models/index.ts +16 -16
  131. package/src/models/json-object.ts +8 -8
  132. package/src/models/locals-props.ts +36 -36
  133. package/src/models/logger-props.ts +84 -84
  134. package/src/models/simple-storage-props.ts +13 -14
  135. package/src/models/to-client-delivery-props.ts +6 -6
  136. package/tsconfig.json +115 -115
  137. package/dev/plugin-gen-versions.js +0 -20
@@ -1,205 +1,210 @@
1
- import { ServerResponse } from 'http';
2
- import { ApiHelper } from '../api';
3
- import { CryptoUtils, Logger } from '../lib';
4
- import { ServerRequest } from '../models';
5
-
6
- /*
7
- dev-admin uses different authentication method from frontend.
8
- dev-admin only provides fixed username and password authentication, no user maintenance.
9
- saved cookie name: _token_dev
10
- */
11
-
12
- // DEFAULT_ADMIN_PASS is DEFAULT_ADMIN_NAME + ':' + login password hash.
13
- // Use below command to generate hash:
14
- // node -e "console.log(require('crypto').createHash('md5').update('admin:F4AZ5O@2fPUjw%f$LmhZpJTQ^DoXnWPkH#hqE', 'utf8').digest('hex'))"
15
- export type DevAdminSessionProps = {
16
- u: string; // username
17
- t: string; // type: admin, user
18
- ip: string;
19
- h: string; // md5 of name+pass
20
- };
21
-
22
- /*
23
- dev admin has more permissions than app admin, and the dashboard also supports for app admin only users.
24
- app admin is supposed to manage the application, not the site, and may have different fields in cookie.
25
- This is a sample how to set login process for app admin.
26
-
27
- export const appAdminHookSetCookie: AppAdminHookSetCookieProps = async (
28
- req: ServerRequest,
29
- res: ServerResponse,
30
- username: string
31
- ) => {
32
- const cryptoKey = process.env['CRYPTO_KEY'];
33
- const u = process.env['ADMIN_USER'];
34
- const p = process.env['ADMIN_PASS'];
35
- if (!cryptoKey || !u || !p) {
36
- return {};
37
- }
38
-
39
- const specialToken = CryptoUtils.hash((u + ':' + p) as string);
40
- const loginJson: LoginJsonProps = {
41
- ip: '',
42
- id: 0,
43
- u: u,
44
- t: 'admin',
45
- h: specialToken,
46
- };
47
-
48
- const token = JSON.stringify(loginJson);
49
- const tokenCookie = CryptoUtils.encrypt(token, cryptoKey);
50
- const response = {
51
- status: 'ok',
52
- message: langHelper.getLang('shared:login_success'),
53
- result: tokenCookie,
54
- user: {
55
- u: loginJson.u,
56
- t: loginJson.t,
57
- },
58
- };
59
-
60
- // sameSite: 'none' needs secure=true
61
- req.locals.setCookie('_token', tokenCookie, {
62
- expireDays: 360,
63
- path: '/',
64
- httpOnly: false,
65
- secure: true,
66
- sameSite: 'none',
67
- });
68
- return response;
69
- };
70
-
71
- export const appAdminHookCheckLogin: AppAdminHookCheckLoginProps = async (
72
- req: ServerRequest,
73
- res: ServerResponse,
74
- username: string,
75
- password: string
76
- ) => {
77
- if (process.env['ADMIN_PASS'] && username === process.env['ADMIN_USER'] && password === process.env['ADMIN_PASS']) {
78
- const appAdminResponse = await appAdminHookSetCookie(req, res, username);
79
- ApiHelper.sendJson(req, res, appAdminResponse);
80
- return true;
81
- }
82
- return false;
83
- };
84
-
85
- adminHelper.setAppAdminHookSetCookie(appAdminHookSetCookie);
86
- adminHelper.setAppAdminHookCheckLogin(appAdminHookCheckLogin);
87
- */
88
- export type AppAdminHookSetCookieProps = (req: ServerRequest, res: ServerResponse, username: string) => Promise<any>;
89
- export type AppAdminHookCheckLoginProps = (req: ServerRequest, res: ServerResponse, username: string, password: string) => Promise<boolean>;
90
- export type AppAdminHookLogoutProps = (req: ServerRequest, res: ServerResponse) => Promise<void>;
91
-
92
- export const DEV_ADMIN_TYPE = 'dev-admin';
93
- export const DEV_ADMIN_CRYPTO_KEY_NAME = 'DEV_CRYPTO_KEY';
94
- export const DEV_ADMIN_SESSION_NAME = '_token_dev';
95
- export class AdminApiHelper {
96
- private static instance: AdminApiHelper;
97
- private logger = new Logger('admin-api');
98
-
99
- private constructor() {}
100
-
101
- public static getInstance(): AdminApiHelper {
102
- if (!AdminApiHelper.instance) {
103
- AdminApiHelper.instance = new AdminApiHelper();
104
- }
105
- return AdminApiHelper.instance;
106
- }
107
-
108
- private AppAdminHookSetCookie?: AppAdminHookSetCookieProps;
109
- setAppAdminHookSetCookie(hook: AppAdminHookSetCookieProps) {
110
- this.AppAdminHookSetCookie = hook;
111
- }
112
- getAppAdminHookSetCookie() {
113
- return this.AppAdminHookSetCookie;
114
- }
115
-
116
- private AppAdminHookCheckLogin?: AppAdminHookCheckLoginProps;
117
- setAppAdminHookCheckLogin(hook: AppAdminHookCheckLoginProps) {
118
- this.AppAdminHookCheckLogin = hook;
119
- }
120
- getAppAdminHookCheckLogin() {
121
- return this.AppAdminHookCheckLogin;
122
- }
123
-
124
- private AppAdminHookLogout?: AppAdminHookLogoutProps;
125
- setAppAdminHookLogout(hook: AppAdminHookLogoutProps) {
126
- this.AppAdminHookLogout = hook;
127
- }
128
- getAppAdminHookLogout() {
129
- return this.AppAdminHookLogout;
130
- }
131
-
132
- decryptJson(text: string) {
133
- const cryptoKey = process.env[DEV_ADMIN_CRYPTO_KEY_NAME];
134
- if (cryptoKey && text) {
135
- try {
136
- const deCrypto = CryptoUtils.decrypt(text, cryptoKey);
137
- const json = JSON.parse(deCrypto);
138
- return json;
139
- } catch (error: any) {
140
- this.logger.error(error.message);
141
- }
142
- }
143
- return false;
144
- }
145
-
146
- encryptJson(jsonOrText: string | object) {
147
- const cryptoKey = process.env[DEV_ADMIN_CRYPTO_KEY_NAME];
148
- if (cryptoKey && jsonOrText) {
149
- try {
150
- const text = typeof jsonOrText === 'string' ? jsonOrText : JSON.stringify(jsonOrText);
151
- const encryptText = CryptoUtils.encrypt(text, cryptoKey);
152
- return encryptText;
153
- } catch (error: any) {
154
- this.logger.error(error.message);
155
- }
156
- }
157
- return false;
158
- }
159
-
160
- async getDevAdminFromCookie(
161
- req: ServerRequest,
162
- res: ServerResponse,
163
- sendResponseWhenError = true
164
- ): Promise<DevAdminSessionProps | false> {
165
- try {
166
- const cookies = req.locals.cookies();
167
- const token = cookies.get(DEV_ADMIN_SESSION_NAME, '');
168
- if (token) {
169
- const json = this.decryptJson(token) as DevAdminSessionProps;
170
- if (!json || json.t !== DEV_ADMIN_TYPE) {
171
- if (sendResponseWhenError) {
172
- const response = {
173
- status: 'error',
174
- message: 'Wrong session data, contact site admin please.',
175
- };
176
- ApiHelper.sendJson(req, res, response);
177
- }
178
- return false;
179
- }
180
-
181
- // if it's special admin
182
- if (json.h && json.u === process.env['DEV_ADMIN_USER']) {
183
- const hash = CryptoUtils.hash(process.env['DEV_ADMIN_USER'] + ':' + process.env['DEV_ADMIN_PASS']);
184
- if (json.h === hash) {
185
- return json;
186
- }
187
- }
188
- return false;
189
- }
190
- } catch (error: any) {
191
- this.logger.error(error.message);
192
- }
193
- if (sendResponseWhenError) {
194
- const response = {
195
- status: 'error',
196
- message: 'Please login to use this system.',
197
- };
198
- ApiHelper.sendJson(req, res, response);
199
- }
200
- return false;
201
- }
202
- }
203
-
204
- // add comment for tree shaking
205
- export const adminApiHelper = /* @__PURE__ */ AdminApiHelper.getInstance();
1
+ import { ServerResponse } from 'http';
2
+ import { ApiHelper } from '../api';
3
+ import { CryptoUtils, Logger } from '../lib';
4
+ import { ServerRequest } from '../models';
5
+
6
+ /*
7
+ dev-admin uses different authentication method from frontend.
8
+ dev-admin only provides fixed username and password authentication, no user maintenance.
9
+ saved cookie name: _token_dev
10
+ */
11
+
12
+ // DEFAULT_ADMIN_PASS is DEFAULT_ADMIN_NAME + ':' + login password hash.
13
+ // Use below command to generate hash:
14
+ // node -e "console.log(require('crypto').createHash('md5').update('admin:F4AZ5O@2fPUjw%f$LmhZpJTQ^DoXnWPkH#hqE', 'utf8').digest('hex'))"
15
+ export type DevAdminSessionProps = {
16
+ u: string; // username
17
+ t: string; // type: admin, user
18
+ ip: string;
19
+ h: string; // md5 of name+pass
20
+ };
21
+
22
+ /*
23
+ dev admin has more permissions than app admin, and the dashboard also supports for app admin only users.
24
+ app admin is supposed to manage the application, not the site, and may have different fields in cookie.
25
+ This is a sample how to set login process for app admin.
26
+
27
+ export const appAdminHookSetCookie: AppAdminHookSetCookieProps = async (
28
+ req: ServerRequest,
29
+ res: ServerResponse,
30
+ username: string
31
+ ) => {
32
+ const cryptoKey = process.env['CRYPTO_KEY'];
33
+ const u = process.env['ADMIN_USER'];
34
+ const p = process.env['ADMIN_PASS'];
35
+ if (!cryptoKey || !u || !p) {
36
+ return {};
37
+ }
38
+
39
+ const specialToken = CryptoUtils.hash((u + ':' + p) as string);
40
+ const loginJson: LoginJsonProps = {
41
+ ip: '',
42
+ id: 0,
43
+ u: u,
44
+ t: 'admin',
45
+ h: specialToken,
46
+ };
47
+
48
+ const token = JSON.stringify(loginJson);
49
+ const tokenCookie = CryptoUtils.encrypt(token, cryptoKey);
50
+ const response = {
51
+ status: 'ok',
52
+ message: langHelper.getLang('shared:login_success'),
53
+ result: tokenCookie,
54
+ user: {
55
+ u: loginJson.u,
56
+ t: loginJson.t,
57
+ },
58
+ };
59
+
60
+ // sameSite: 'none' needs secure=true
61
+ req.locals.setCookie('_token', tokenCookie, {
62
+ expireDays: 360,
63
+ path: '/',
64
+ httpOnly: false,
65
+ secure: true,
66
+ sameSite: 'none',
67
+ });
68
+ return response;
69
+ };
70
+
71
+ export const appAdminHookCheckLogin: AppAdminHookCheckLoginProps = async (
72
+ req: ServerRequest,
73
+ res: ServerResponse,
74
+ username: string,
75
+ password: string
76
+ ) => {
77
+ if (process.env['ADMIN_PASS'] && username === process.env['ADMIN_USER'] && password === process.env['ADMIN_PASS']) {
78
+ const appAdminResponse = await appAdminHookSetCookie(req, res, username);
79
+ ApiHelper.sendJson(req, res, appAdminResponse);
80
+ return true;
81
+ }
82
+ return false;
83
+ };
84
+
85
+ adminHelper.setAppAdminHookSetCookie(appAdminHookSetCookie);
86
+ adminHelper.setAppAdminHookCheckLogin(appAdminHookCheckLogin);
87
+ */
88
+ export type AppAdminHookSetCookieProps = (req: ServerRequest, res: ServerResponse, username: string) => Promise<any>;
89
+ export type AppAdminHookCheckLoginProps = (
90
+ req: ServerRequest,
91
+ res: ServerResponse,
92
+ username: string,
93
+ password: string
94
+ ) => Promise<boolean>;
95
+ export type AppAdminHookLogoutProps = (req: ServerRequest, res: ServerResponse) => Promise<void>;
96
+
97
+ export const DEV_ADMIN_TYPE = 'dev-admin';
98
+ export const DEV_ADMIN_CRYPTO_KEY_NAME = 'DEV_CRYPTO_KEY';
99
+ export const DEV_ADMIN_SESSION_NAME = '_token_dev';
100
+ export class AdminApiHelper {
101
+ private static instance: AdminApiHelper;
102
+ private logger = new Logger('admin-api');
103
+
104
+ private constructor() {}
105
+
106
+ public static getInstance(): AdminApiHelper {
107
+ if (!AdminApiHelper.instance) {
108
+ AdminApiHelper.instance = new AdminApiHelper();
109
+ }
110
+ return AdminApiHelper.instance;
111
+ }
112
+
113
+ private AppAdminHookSetCookie?: AppAdminHookSetCookieProps;
114
+ setAppAdminHookSetCookie(hook: AppAdminHookSetCookieProps) {
115
+ this.AppAdminHookSetCookie = hook;
116
+ }
117
+ getAppAdminHookSetCookie() {
118
+ return this.AppAdminHookSetCookie;
119
+ }
120
+
121
+ private AppAdminHookCheckLogin?: AppAdminHookCheckLoginProps;
122
+ setAppAdminHookCheckLogin(hook: AppAdminHookCheckLoginProps) {
123
+ this.AppAdminHookCheckLogin = hook;
124
+ }
125
+ getAppAdminHookCheckLogin() {
126
+ return this.AppAdminHookCheckLogin;
127
+ }
128
+
129
+ private AppAdminHookLogout?: AppAdminHookLogoutProps;
130
+ setAppAdminHookLogout(hook: AppAdminHookLogoutProps) {
131
+ this.AppAdminHookLogout = hook;
132
+ }
133
+ getAppAdminHookLogout() {
134
+ return this.AppAdminHookLogout;
135
+ }
136
+
137
+ decryptJson(text: string) {
138
+ const cryptoKey = process.env[DEV_ADMIN_CRYPTO_KEY_NAME];
139
+ if (cryptoKey && text) {
140
+ try {
141
+ const deCrypto = CryptoUtils.decrypt(text, cryptoKey);
142
+ const json = JSON.parse(deCrypto);
143
+ return json;
144
+ } catch (error: any) {
145
+ this.logger.error(error.message);
146
+ }
147
+ }
148
+ return false;
149
+ }
150
+
151
+ encryptJson(jsonOrText: string | object) {
152
+ const cryptoKey = process.env[DEV_ADMIN_CRYPTO_KEY_NAME];
153
+ if (cryptoKey && jsonOrText) {
154
+ try {
155
+ const text = typeof jsonOrText === 'string' ? jsonOrText : JSON.stringify(jsonOrText);
156
+ const encryptText = CryptoUtils.encrypt(text, cryptoKey);
157
+ return encryptText;
158
+ } catch (error: any) {
159
+ this.logger.error(error.message);
160
+ }
161
+ }
162
+ return false;
163
+ }
164
+
165
+ async getDevAdminFromCookie(
166
+ req: ServerRequest,
167
+ res: ServerResponse,
168
+ sendResponseWhenError = true
169
+ ): Promise<DevAdminSessionProps | false> {
170
+ try {
171
+ const cookies = req.locals.cookies();
172
+ const token = cookies.get(DEV_ADMIN_SESSION_NAME, '');
173
+ if (token) {
174
+ const json = this.decryptJson(token) as DevAdminSessionProps;
175
+ if (!json || json.t !== DEV_ADMIN_TYPE) {
176
+ if (sendResponseWhenError) {
177
+ const response = {
178
+ status: 'error',
179
+ message: 'Wrong session data, contact site admin please.',
180
+ };
181
+ ApiHelper.sendJson(req, res, response);
182
+ }
183
+ return false;
184
+ }
185
+
186
+ // if it's special admin
187
+ if (json.h && json.u === process.env['DEV_ADMIN_USER']) {
188
+ const hash = CryptoUtils.hash(process.env['DEV_ADMIN_USER'] + ':' + process.env['DEV_ADMIN_PASS']);
189
+ if (json.h === hash) {
190
+ return json;
191
+ }
192
+ }
193
+ return false;
194
+ }
195
+ } catch (error: any) {
196
+ this.logger.error(error.message);
197
+ }
198
+ if (sendResponseWhenError) {
199
+ const response = {
200
+ status: 'error',
201
+ message: 'Please login to use this system.',
202
+ };
203
+ ApiHelper.sendJson(req, res, response);
204
+ }
205
+ return false;
206
+ }
207
+ }
208
+
209
+ // add comment for tree shaking
210
+ export const adminApiHelper = /* @__PURE__ */ AdminApiHelper.getInstance();
@@ -1,65 +1,65 @@
1
- import { ServerResponse } from 'http';
2
- // import { AdminUser } from './admin-user';
3
- import { AdminDb } from './admin-db';
4
- import { AdminMenu } from './admin-menu';
5
- import { devAdminAuth, devAdminLogout, needDevAdminSession } from './admin-auth';
6
- import { AdminPerformance } from './admin-performance';
7
- import { AdminRelease } from './admin-release';
8
- import { AdminResources } from './admin-resources';
9
- import { AdminTokens } from './admin-tokens';
10
- import { AdminConfig } from './admin-config';
11
- import { Logger } from '../lib';
12
- import { IApiBase, ServerRequest } from '../models';
13
- import { ApiRouter } from '../api';
14
- import { readWebConfig } from './web-config-api';
15
-
16
- const logger = new Logger('admin-api');
17
-
18
- export class AdminApi implements IApiBase {
19
- protected router = new ApiRouter();
20
- adminUser: any;
21
-
22
- constructor() {
23
- this.mountDashboard();
24
- }
25
-
26
- public getRouter(): ApiRouter {
27
- return this.router;
28
- }
29
-
30
- protected mountDashboard() {
31
- this.router.use('/web-config', readWebConfig);
32
-
33
- const adminDb = new AdminDb();
34
- this.router.use('/db', needDevAdminSession, adminDb.getRouter());
35
-
36
- // const adminUsers = new AdminUser();
37
- // this.router.use('/user', needDevAdminSession, adminUsers.getRouter());
38
-
39
- const adminMenus = new AdminMenu();
40
- this.router.use('/menu', needDevAdminSession, adminMenus.getRouter());
41
-
42
- const adminPerformance = new AdminPerformance();
43
- this.router.use('/performance', needDevAdminSession, adminPerformance.getRouter());
44
-
45
- const adminRelease = new AdminRelease();
46
- // as some endpoints check the token, so add needDevAdminSession inside
47
- this.router.use('/release', adminRelease.getRouter());
48
-
49
- const adminResources = new AdminResources();
50
- this.router.use('/resources', needDevAdminSession, adminResources.getRouter());
51
-
52
- const adminConfig = new AdminConfig();
53
- this.router.use('/config', needDevAdminSession, adminConfig.getRouter());
54
-
55
- const adminTokens = new AdminTokens();
56
- this.router.use('/tokens', needDevAdminSession, adminTokens.getRouter());
57
-
58
- this.router.use('/auth', async (req: ServerRequest, res: ServerResponse) => {
59
- return devAdminAuth(req, res);
60
- });
61
- this.router.use('/logout', async (req: ServerRequest, res: ServerResponse) => {
62
- return devAdminLogout(req, res);
63
- });
64
- }
65
- }
1
+ import { ServerResponse } from 'http';
2
+ // import { AdminUser } from './admin-user';
3
+ import { AdminDb } from './admin-db';
4
+ import { AdminMenu } from './admin-menu';
5
+ import { devAdminAuth, devAdminLogout, needDevAdminSession } from './admin-auth';
6
+ import { AdminPerformance } from './admin-performance';
7
+ import { AdminRelease } from './admin-release';
8
+ import { AdminResources } from './admin-resources';
9
+ import { AdminTokens } from './admin-tokens';
10
+ import { AdminConfig } from './admin-config';
11
+ import { Logger } from '../lib';
12
+ import { IApiBase, ServerRequest } from '../models';
13
+ import { ApiRouter } from '../api';
14
+ import { readWebConfig } from './web-config-api';
15
+
16
+ const logger = new Logger('admin-api');
17
+
18
+ export class AdminApi implements IApiBase {
19
+ protected router = new ApiRouter();
20
+ adminUser: any;
21
+
22
+ constructor() {
23
+ this.mountDashboard();
24
+ }
25
+
26
+ public getRouter(): ApiRouter {
27
+ return this.router;
28
+ }
29
+
30
+ protected mountDashboard() {
31
+ this.router.use('/web-config', readWebConfig);
32
+
33
+ const adminDb = new AdminDb();
34
+ this.router.use('/db', needDevAdminSession, adminDb.getRouter());
35
+
36
+ // const adminUsers = new AdminUser();
37
+ // this.router.use('/user', needDevAdminSession, adminUsers.getRouter());
38
+
39
+ const adminMenus = new AdminMenu();
40
+ this.router.use('/menu', needDevAdminSession, adminMenus.getRouter());
41
+
42
+ const adminPerformance = new AdminPerformance();
43
+ this.router.use('/performance', needDevAdminSession, adminPerformance.getRouter());
44
+
45
+ const adminRelease = new AdminRelease();
46
+ // as some endpoints check the token, so add needDevAdminSession inside
47
+ this.router.use('/release', adminRelease.getRouter());
48
+
49
+ const adminResources = new AdminResources();
50
+ this.router.use('/resources', needDevAdminSession, adminResources.getRouter());
51
+
52
+ const adminConfig = new AdminConfig();
53
+ this.router.use('/config', needDevAdminSession, adminConfig.getRouter());
54
+
55
+ const adminTokens = new AdminTokens();
56
+ this.router.use('/tokens', needDevAdminSession, adminTokens.getRouter());
57
+
58
+ this.router.use('/auth', async (req: ServerRequest, res: ServerResponse) => {
59
+ return devAdminAuth(req, res);
60
+ });
61
+ this.router.use('/logout', async (req: ServerRequest, res: ServerResponse) => {
62
+ return devAdminLogout(req, res);
63
+ });
64
+ }
65
+ }