w-web-task 1.0.31 → 1.0.33
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.tmp +1 -1
- package/dist/js/app-legacy.c161c06f.js +1 -0
- package/dist/js/app.c161c06f.js +1 -0
- package/dist/js/{chunk-vendors-legacy.03f6ffe7.js → chunk-vendors-legacy.59fd6af8.js} +3 -3
- package/dist/js/{chunk-vendors.03f6ffe7.js → chunk-vendors.59fd6af8.js} +3 -3
- package/dist/w-web-task.umd.js +2 -2
- package/dist/w-web-task.umd.js.map +1 -1
- package/docs/WWebTask.html +447 -6
- package/docs/global.html +240 -2
- package/docs/index.html +2 -2
- package/docs/server_WWebTask.mjs.html +61 -46
- package/docs/server_authorizeExec.mjs.html +129 -0
- package/docs/server_lockSave.mjs.html +2 -2
- package/docs/server_maskLog.mjs.html +2 -2
- package/docs/server_wrapInjected.mjs.html +2 -2
- package/docs/src_plugins_submitGuard.mjs.html +2 -2
- package/g.mOrm.mjs +2 -7
- package/package.json +12 -12
- package/server/WWebTask.mjs +59 -44
- package/server/authorizeExec.mjs +57 -0
- package/srv.mjs +11 -8
- package/dist/js/app-legacy.1c14647d.js +0 -1
- package/dist/js/app.1c14647d.js +0 -1
package/docs/global.html
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
<nav >
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="WWebTask.html">WWebTask</a></li></ul><h3>Global</h3><ul><li><a href="global.html#createLockSave">createLockSave</a></li><li><a href="global.html#describeUpstream">describeUpstream</a></li><li><a href="global.html#maskQuery">maskQuery</a></li><li><a href="global.html#maskTok">maskTok</a></li><li><a href="global.html#maskUrl">maskUrl</a></li><li><a href="global.html#submitGuard">submitGuard</a></li><li><a href="global.html#wrapInjected">wrapInjected</a></li></ul>
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="WWebTask.html">WWebTask</a></li></ul><h3>Global</h3><ul><li><a href="global.html#createAuthorizeExec">createAuthorizeExec</a></li><li><a href="global.html#createLockSave">createLockSave</a></li><li><a href="global.html#describeUpstream">describeUpstream</a></li><li><a href="global.html#maskQuery">maskQuery</a></li><li><a href="global.html#maskTok">maskTok</a></li><li><a href="global.html#maskUrl">maskUrl</a></li><li><a href="global.html#submitGuard">submitGuard</a></li><li><a href="global.html#wrapInjected">wrapInjected</a></li></ul>
|
|
33
33
|
|
|
34
34
|
</nav>
|
|
35
35
|
|
|
@@ -130,6 +130,244 @@
|
|
|
130
130
|
|
|
131
131
|
|
|
132
132
|
|
|
133
|
+
<h4 class="name" id="createAuthorizeExec"><span class="type-signature"></span>createAuthorizeExec<span class="signature">(opt)</span><span class="type-signature"> → {function}</span></h4>
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
<dl class="details">
|
|
141
|
+
|
|
142
|
+
<dt class="tag-description">Description:</dt>
|
|
143
|
+
<dd class="tag-description"><ul class="dummy"><li><p>資料通道表操作之授權函數(交 w-serv-hapi / w-serv-webdata 之 opt.authorizeExec; spec D17 決策 2)</p>
|
|
144
|
+
<p>w-serv-webdata 1.1.7 起 useDbOrm=true 時必填, 前端呼叫表操作(如同步之 channels.select)時於 operOrm 之前呼叫,
|
|
145
|
+
回傳嚴格等於 true 才放行, 其他值一律回應 'permission denied' 且不呼叫 operOrm.
|
|
146
|
+
本套件之資料通道只開放 methodsExec 所列方法(['select'], 供前端同步); 寫入一律經 kpFunExt(D16 lockSave、確保成員列 kmx、D7 游標身分皆在其內).
|
|
147
|
+
放行: userId 為非空字串, 且 methodName 屬 methodsExec; 回傳一律為布林.
|
|
148
|
+
拒絕: 回 false 並記 srLog.error({ event: 'authorizeExec', err, tableName, methodName }), userId 缺為 'errUserIdMissing', 方法不在清單為 'errUserNoPermission'.
|
|
149
|
+
getUserIdByToken 已 fail-closed 且 w-serv-webdata 只綁定 methodsExec 之方法, 故兩個拒絕分支於正常呼叫不會發生, 屬縱深防護.</p></li></ul></dd>
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
<dt class="tag-source">Source:</dt>
|
|
154
|
+
<dd class="tag-source"><ul class="dummy"><li>
|
|
155
|
+
<a href="server_authorizeExec.mjs.html">server/authorizeExec.mjs</a>, <a href="server_authorizeExec.mjs.html#line22">line 22</a>
|
|
156
|
+
</li></ul></dd>
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
</dl>
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
<h5 class="h5-parameters">Parameters:</h5>
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
<table class="params">
|
|
206
|
+
<thead>
|
|
207
|
+
<tr>
|
|
208
|
+
|
|
209
|
+
<th>Name</th>
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
<th>Type</th>
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
<th class="last">Description</th>
|
|
219
|
+
</tr>
|
|
220
|
+
</thead>
|
|
221
|
+
|
|
222
|
+
<tbody>
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
<tr>
|
|
226
|
+
|
|
227
|
+
<td class="name"><code>opt</code></td>
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
<td class="type">
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
<span class="param-type">Object</span>
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
</td>
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
<td class="description last"><p>輸入設定物件</p>
|
|
245
|
+
<h6>Properties</h6>
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
<table class="params">
|
|
249
|
+
<thead>
|
|
250
|
+
<tr>
|
|
251
|
+
|
|
252
|
+
<th>Name</th>
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
<th>Type</th>
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
<th class="last">Description</th>
|
|
262
|
+
</tr>
|
|
263
|
+
</thead>
|
|
264
|
+
|
|
265
|
+
<tbody>
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
<tr>
|
|
269
|
+
|
|
270
|
+
<td class="name"><code>methodsExec</code></td>
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
<td class="type">
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
<span class="param-type">Array</span>
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
</td>
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
<td class="description last"><p>輸入允許之表操作方法陣列(須與交 w-serv-hapi 之 methodsExec 為同一陣列), 須為非空陣列</p></td>
|
|
288
|
+
</tr>
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
<tr>
|
|
293
|
+
|
|
294
|
+
<td class="name"><code>srLog</code></td>
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
<td class="type">
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
<span class="param-type">Object</span>
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
</td>
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
<td class="description last"><p>輸入後端 log 物件, 須具 error 函數</p></td>
|
|
312
|
+
</tr>
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
</tbody>
|
|
316
|
+
</table>
|
|
317
|
+
|
|
318
|
+
</td>
|
|
319
|
+
</tr>
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
</tbody>
|
|
323
|
+
</table>
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
<h5 class="h5-returns">Returns:</h5>
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
<div class="param-desc">
|
|
344
|
+
<p>回傳 ({ userId, tableName, methodName }) => Boolean</p>
|
|
345
|
+
</div>
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
<dl class="param-type">
|
|
350
|
+
<dt>
|
|
351
|
+
Type
|
|
352
|
+
</dt>
|
|
353
|
+
<dd>
|
|
354
|
+
|
|
355
|
+
<span class="param-type">function</span>
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
</dd>
|
|
360
|
+
</dl>
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
133
371
|
<h4 class="name" id="createLockSave"><span class="type-signature"></span>createLockSave<span class="signature">(cst)</span><span class="type-signature"> → {function}</span></h4>
|
|
134
372
|
|
|
135
373
|
|
|
@@ -1421,7 +1659,7 @@ opt.hold 為函數, 輸入流程結果, 回傳 true 時保持占位與按鈕鎖(
|
|
|
1421
1659
|
<br class="clear">
|
|
1422
1660
|
|
|
1423
1661
|
<footer>
|
|
1424
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on
|
|
1662
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Oct 14 2026 08:01:17 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
1425
1663
|
</footer>
|
|
1426
1664
|
|
|
1427
1665
|
<script>prettyPrint();</script>
|
package/docs/index.html
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
<nav >
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="WWebTask.html">WWebTask</a></li></ul><h3>Global</h3><ul><li><a href="global.html#createLockSave">createLockSave</a></li><li><a href="global.html#describeUpstream">describeUpstream</a></li><li><a href="global.html#maskQuery">maskQuery</a></li><li><a href="global.html#maskTok">maskTok</a></li><li><a href="global.html#maskUrl">maskUrl</a></li><li><a href="global.html#submitGuard">submitGuard</a></li><li><a href="global.html#wrapInjected">wrapInjected</a></li></ul>
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="WWebTask.html">WWebTask</a></li></ul><h3>Global</h3><ul><li><a href="global.html#createAuthorizeExec">createAuthorizeExec</a></li><li><a href="global.html#createLockSave">createLockSave</a></li><li><a href="global.html#describeUpstream">describeUpstream</a></li><li><a href="global.html#maskQuery">maskQuery</a></li><li><a href="global.html#maskTok">maskTok</a></li><li><a href="global.html#maskUrl">maskUrl</a></li><li><a href="global.html#submitGuard">submitGuard</a></li><li><a href="global.html#wrapInjected">wrapInjected</a></li></ul>
|
|
33
33
|
|
|
34
34
|
</nav>
|
|
35
35
|
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
<br class="clear">
|
|
72
72
|
|
|
73
73
|
<footer>
|
|
74
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on
|
|
74
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Oct 14 2026 08:01:17 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
75
75
|
</footer>
|
|
76
76
|
|
|
77
77
|
<script>prettyPrint();</script>
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
<nav >
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="WWebTask.html">WWebTask</a></li></ul><h3>Global</h3><ul><li><a href="global.html#createLockSave">createLockSave</a></li><li><a href="global.html#describeUpstream">describeUpstream</a></li><li><a href="global.html#maskQuery">maskQuery</a></li><li><a href="global.html#maskTok">maskTok</a></li><li><a href="global.html#maskUrl">maskUrl</a></li><li><a href="global.html#submitGuard">submitGuard</a></li><li><a href="global.html#wrapInjected">wrapInjected</a></li></ul>
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="WWebTask.html">WWebTask</a></li></ul><h3>Global</h3><ul><li><a href="global.html#createAuthorizeExec">createAuthorizeExec</a></li><li><a href="global.html#createLockSave">createLockSave</a></li><li><a href="global.html#describeUpstream">describeUpstream</a></li><li><a href="global.html#maskQuery">maskQuery</a></li><li><a href="global.html#maskTok">maskTok</a></li><li><a href="global.html#maskUrl">maskUrl</a></li><li><a href="global.html#submitGuard">submitGuard</a></li><li><a href="global.html#wrapInjected">wrapInjected</a></li></ul>
|
|
33
33
|
|
|
34
34
|
</nav>
|
|
35
35
|
|
|
@@ -69,9 +69,11 @@ import fsIsFile from 'wsemi/src/fsIsFile.mjs'
|
|
|
69
69
|
import replace from 'wsemi/src/replace.mjs'
|
|
70
70
|
import WServHapiServer from 'w-serv-hapi/src/WServHapiServer.mjs'
|
|
71
71
|
import WServOrm from 'w-serv-orm/src/WServOrm.mjs'
|
|
72
|
+
import checkOptRemoved from 'w-serv-orm/src/checkOptRemoved.mjs'
|
|
72
73
|
import procLang from './procLang.mjs'
|
|
73
74
|
import procCore from './procCore.mjs'
|
|
74
75
|
import createLockSave from './lockSave.mjs'
|
|
76
|
+
import createAuthorizeExec from './authorizeExec.mjs'
|
|
75
77
|
import srLogInit from './srLog.mjs'
|
|
76
78
|
import { maskTok, maskQuery } from './maskLog.mjs'
|
|
77
79
|
import { wrapInjected } from './wrapInjected.mjs'
|
|
@@ -86,11 +88,23 @@ import ds from '../src/schema/index.mjs'
|
|
|
86
88
|
* @param {String} url 輸入資料庫連線字串,例如w-orm-lmdb為'./db'
|
|
87
89
|
* @param {String} db 輸入資料庫名稱字串
|
|
88
90
|
* @param {Function} getUserByToken 輸入處理函數,函數會傳入使用者token,通過此函數處理後並回傳使用者資訊物件,並至少須提供'id'、'email'、'name'、'isAdmin'欄位,且'isAdmin'限輸入'y'或'n'
|
|
89
|
-
* @param {Function} verifyClientUser
|
|
90
|
-
* @param {Function} verifyAppUser
|
|
91
|
+
* @param {Function} verifyClientUser 輸入驗證瀏覽使用者身份之處理函數,函數會傳入使用者資訊物件與來源字串(from),通過此函數識別後回傳布林值,允許使用者回傳true,反之回傳false。作用於登入檢查(/api/getUserByToken,from為'getUserByToken')與前端資料通道之每次請求(連線閘,from為w-converhp之apiType如'main'),兩者同一判定;拋錯或reject視同不允許
|
|
92
|
+
* @param {Function} verifyAppUser 輸入驗證應用程序使用者身份之處理函數,函數會傳入使用者資訊物件與來源字串(from,為API名稱),通過此函數識別後回傳布林值,允許使用者回傳true,反之回傳false。作用於對外HTTP REST API(agent面);拋錯或reject視同不允許
|
|
91
93
|
* @param {Object} [opt={}] 輸入設定物件,預設{}
|
|
92
94
|
* @param {Integer} [opt.serverPort=11008] 輸入伺服器通訊port,預設11008
|
|
93
|
-
* @
|
|
95
|
+
* @param {String} [opt.subfolder=''] 輸入網站子目錄字串,例如'mtask',預設''
|
|
96
|
+
* @param {String} [opt.urlRedirect=''] 輸入未登入時導向之網址字串(例如SSO登入頁),預設''
|
|
97
|
+
* @param {String} [opt.showLanguage='y'] 輸入是否顯示語系選單字串,可選'y'、'n',預設'y'
|
|
98
|
+
* @param {String} [opt.language='eng'] 輸入初始語系字串,可選'eng'、'cht',預設'eng'
|
|
99
|
+
* @param {Object} [opt.webName={}] 輸入網站名稱物件,key為語系而值為字串,預設{}
|
|
100
|
+
* @param {Object} [opt.webDescription={}] 輸入網站說明物件,key為語系而值為字串,預設{}
|
|
101
|
+
* @param {String} [opt.webLogo=''] 輸入網站logo字串,預設''
|
|
102
|
+
* @param {Object} [opt.kpLangExt={}] 輸入擴充語系物件,預設{}
|
|
103
|
+
* @param {String} [opt.logFd='./logs'] 輸入後端log資料夾字串,相對路徑以建構時之工作目錄解析,資料夾不可建立時(例如上層為檔案)於建構時拋錯(w-syslog 1.0.33起;於資料庫建立之前),預設'./logs'
|
|
104
|
+
* @param {String} [opt.logInterval='hr'] 輸入後端log分檔模式字串,可選'day'、'hr',預設'hr'
|
|
105
|
+
* @param {Integer} [opt.archiveAfterDays=30] 輸入終態任務與舊訊息逾此天數搬至冷表之天數,小於等於0為停用,預設30
|
|
106
|
+
* 已移除之設定:useCheckUser、getUserById、useExcludeWhenNotAdmin(w-serv-orm已移除),給予undefined、null、false以外之值即於建構時拋錯(於任何副作用之前)
|
|
107
|
+
* @returns {Object} 回傳w-serv-hapi之伺服器事件物件,可監聽error事件;w-serv-hapi 1.1.6起另帶ready與stop,惟stop只停止伺服器與其下游,不釋放本套件之計時器(封存掃描、雙擊防護占位)與資料庫連線,本套件以結束行程收尾
|
|
94
108
|
*/
|
|
95
109
|
function WWebTask(WOrm, url, db, getUserByToken, verifyClientUser, verifyAppUser, opt = {}) {
|
|
96
110
|
let instWServHapiServer = null
|
|
@@ -138,6 +152,11 @@ function WWebTask(WOrm, url, db, getUserByToken, verifyClientUser, verifyAppUser
|
|
|
138
152
|
}
|
|
139
153
|
|
|
140
154
|
|
|
155
|
+
//checkOptRemoved: w-serv-orm 已移除之 useCheckUser / getUserById / useExcludeWhenNotAdmin(spec D17), 本套件不讀不轉交;
|
|
156
|
+
//給予 undefined / null / false 以外之值即同步拋 w-serv-orm 之原文訊息. 置於任何副作用(srLog 之 log 目錄、資料庫)之前; 規則與訊息由 w-serv-orm 單一擁有
|
|
157
|
+
checkOptRemoved(opt)
|
|
158
|
+
|
|
159
|
+
|
|
141
160
|
//serverPort
|
|
142
161
|
let serverPort = get(opt, 'serverPort')
|
|
143
162
|
if (!ispint(serverPort)) {
|
|
@@ -146,18 +165,6 @@ function WWebTask(WOrm, url, db, getUserByToken, verifyClientUser, verifyAppUser
|
|
|
146
165
|
serverPort = cint(serverPort)
|
|
147
166
|
|
|
148
167
|
|
|
149
|
-
//useCheckUser
|
|
150
|
-
let useCheckUser = get(opt, 'useCheckUser', false)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
//getUserById
|
|
154
|
-
let getUserById = get(opt, 'getUserById', null)
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
//useExcludeWhenNotAdmin
|
|
158
|
-
let useExcludeWhenNotAdmin = get(opt, 'useExcludeWhenNotAdmin', false)
|
|
159
|
-
|
|
160
|
-
|
|
161
168
|
//webName
|
|
162
169
|
let webName = get(opt, 'webName', {})
|
|
163
170
|
|
|
@@ -200,14 +207,13 @@ function WWebTask(WOrm, url, db, getUserByToken, verifyClientUser, verifyAppUser
|
|
|
200
207
|
let kpLang = procLang({ kpLangExt, webName, webDescription })
|
|
201
208
|
|
|
202
209
|
|
|
203
|
-
//srLog(後端 log;錯誤一律 log err-key
|
|
210
|
+
//srLog(後端 log;錯誤一律 log err-key 供識別)
|
|
204
211
|
let srLog = srLogInit(opt)
|
|
205
212
|
|
|
206
213
|
//注入函數一律經 wrapInjected 包裝後使用(W 契約,spec/設計要點與取捨.md D15):
|
|
207
|
-
//部署方注入之 getUserByToken / verifyClientUser / verifyAppUser
|
|
214
|
+
//部署方注入之 getUserByToken / verifyClientUser / verifyAppUser 同步拋錯或 reject 時,視同否定結果(查無 → null、無權限 → false),
|
|
208
215
|
//走各呼叫點既有分支回自家 key;失敗原文(舊版 sso helper 為已代入權杖之完整網址)不上拋、不入 log,只記 describeUpstream 之 key 或型別。
|
|
209
216
|
//以包裝版取代參數本身 → 其後所有呼叫點(含日後新增者)結構上只可能用到包裝版;包裝處記 warn(因),呼叫點記 error(果)。
|
|
210
|
-
//getUserById 選填(useCheckUser=true 時由 WServOrm 呼叫;原 reject 原文經 execute 之 pm2resolve 回前端),有給才包裝,查無由 WServOrm 既有分支拒絕。
|
|
211
217
|
let onInjectFail = (name) => {
|
|
212
218
|
return (d) => {
|
|
213
219
|
srLog.warn({ event: `inject-${name}-fail`, ...d })
|
|
@@ -216,20 +222,12 @@ function WWebTask(WOrm, url, db, getUserByToken, verifyClientUser, verifyAppUser
|
|
|
216
222
|
getUserByToken = wrapInjected(getUserByToken, { failValue: null, onFail: onInjectFail('getUserByToken') })
|
|
217
223
|
verifyClientUser = wrapInjected(verifyClientUser, { failValue: false, onFail: onInjectFail('verifyClientUser') })
|
|
218
224
|
verifyAppUser = wrapInjected(verifyAppUser, { failValue: false, onFail: onInjectFail('verifyAppUser') })
|
|
219
|
-
if (isfun(getUserById)) {
|
|
220
|
-
getUserById = wrapInjected(getUserById, { failValue: null, onFail: onInjectFail('getUserById') })
|
|
221
|
-
}
|
|
222
225
|
|
|
223
226
|
|
|
224
227
|
//WServOrm
|
|
225
|
-
let optWServOrm = {
|
|
226
|
-
useCheckUser,
|
|
227
|
-
getUserById,
|
|
228
|
-
useExcludeWhenNotAdmin,
|
|
229
|
-
}
|
|
230
228
|
let wp = {}
|
|
231
229
|
try {
|
|
232
|
-
wp = WServOrm(ds, WOrm, url, db
|
|
230
|
+
wp = WServOrm(ds, WOrm, url, db)
|
|
233
231
|
}
|
|
234
232
|
catch (err) {
|
|
235
233
|
//ORM 為必要依賴:初始化失敗即 fail-fast,不以 wp={} 帶 undefined woItems/procOrm 殘缺啟動
|
|
@@ -392,12 +390,21 @@ function WWebTask(WOrm, url, db, getUserByToken, verifyClientUser, verifyAppUser
|
|
|
392
390
|
|
|
393
391
|
//p
|
|
394
392
|
let p = {
|
|
395
|
-
checkToken
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
393
|
+
//checkToken:資料通道之連線閘(verifyConn 用),回傳是否放行(spec D17 決策 3)。
|
|
394
|
+
//認證:getTokenUser,與 HTTP 路徑同一出口(S8);失敗 reject 自家 key(w-converhp 回 permission denied、不寫 srLog,D15)。
|
|
395
|
+
//授權:已包裝之 verifyClientUser(拋錯或 reject 視同 false 並記 inject warn),與登入檢查 getAndVerifyClientUser 同一判定;from 為 w-converhp 之 apiType。
|
|
396
|
+
checkToken: async(token, from = '') => {
|
|
397
|
+
|
|
398
|
+
//getTokenUser
|
|
399
|
+
let user = await getTokenUser(token)
|
|
400
|
+
|
|
401
|
+
//verifyClientUser
|
|
402
|
+
let b = verifyClientUser(user, from)
|
|
403
|
+
if (ispm(b)) {
|
|
404
|
+
b = await b
|
|
405
|
+
}
|
|
399
406
|
|
|
400
|
-
return
|
|
407
|
+
return !!b
|
|
401
408
|
},
|
|
402
409
|
}
|
|
403
410
|
|
|
@@ -997,15 +1004,16 @@ function WWebTask(WOrm, url, db, getUserByToken, verifyClientUser, verifyAppUser
|
|
|
997
1004
|
]
|
|
998
1005
|
|
|
999
1006
|
|
|
1000
|
-
//tableNamesExec, tableNamesSync
|
|
1001
|
-
|
|
1002
|
-
//(
|
|
1003
|
-
//
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
+
//tableNamesExec, tableNamesSync, methodsExec
|
|
1008
|
+
//資料通道之表操作只開 select, 供前端同步 channels/channelMembers (spec D17 決策 2); 寫入一律走 kpFunExt 業務函式
|
|
1009
|
+
//(D16 lockSave、確保成員列 kmx、D7 游標身分皆在其內), 避免前端或直打 /api/main 之 ORM 直寫繞過之 (2026-10-14 前曾開 insert/save/del).
|
|
1010
|
+
//tasks/messages 之生命週期/原子寫入亦一律走 kpFunExt (對應 spec 設計總覽 §6.2 註 與 設計要點與取捨 D2).
|
|
1011
|
+
//tableNamesSync 須與 tableNamesExec 對齊且 methodsExec 須含 select: 同步引擎收到某表 tag 變更時會呼叫 kpExec[table].select() 去重抓
|
|
1012
|
+
//(w-serv-webdata 1.1.12 於建構時檢核). messages/tasks 前端一律走 $fapi getMessages/getTasks 按需拉取 (非 ORM change 推送), 故不放進 sync.
|
|
1013
|
+
//methodsExec 為單一定義: 同時交 w-serv-hapi 綁定與 authorizeExec 判斷
|
|
1007
1014
|
let tableNamesExec = ['channels', 'channelMembers']
|
|
1008
1015
|
let tableNamesSync = tableNamesExec
|
|
1016
|
+
let methodsExec = ['select']
|
|
1009
1017
|
|
|
1010
1018
|
|
|
1011
1019
|
//WServHapiServer
|
|
@@ -1029,11 +1037,17 @@ function WWebTask(WOrm, url, db, getUserByToken, verifyClientUser, verifyAppUser
|
|
|
1029
1037
|
return false
|
|
1030
1038
|
}
|
|
1031
1039
|
|
|
1032
|
-
//checkToken
|
|
1033
|
-
let b = await p.checkToken(token)
|
|
1040
|
+
//checkToken:token 認證(解析 user + 驗欄位齊備; 失敗 reject 自家 key)+ 瀏覽使用者授權(部署方之 verifyClientUser, 與登入檢查同一強度; spec D17 決策 3)
|
|
1041
|
+
let b = await p.checkToken(token, apiType)
|
|
1034
1042
|
|
|
1035
|
-
|
|
1036
|
-
|
|
1043
|
+
//check
|
|
1044
|
+
if (!b) {
|
|
1045
|
+
srLog.error({ event: 'verifyConn', err: 'errUserNoPermission', apiType }) //授權不通過須入 log 供稽核/統計; 只記 key 與 apiType, 不記權杖與使用者物件
|
|
1046
|
+
return false
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
srLog.info({ event: 'verifyConn', apiType }) //連線之認證與授權通過
|
|
1050
|
+
return true
|
|
1037
1051
|
},
|
|
1038
1052
|
getUserIdByToken: async (token) => { //可使用async或sync函數
|
|
1039
1053
|
//fail-closed(S9,對齊 perm):token 非字串或查無 userId(含上游失敗經 wrapInjected 視同查無)一律 reject,
|
|
@@ -1055,7 +1069,8 @@ function WWebTask(WOrm, url, db, getUserByToken, verifyClientUser, verifyAppUser
|
|
|
1055
1069
|
kpOrm: woItems,
|
|
1056
1070
|
operOrm: procOrm, //procOrm的輸入為: userId, tableName, methodName, input
|
|
1057
1071
|
tableNamesExec,
|
|
1058
|
-
methodsExec
|
|
1072
|
+
methodsExec,
|
|
1073
|
+
authorizeExec: createAuthorizeExec({ methodsExec, srLog }), //w-serv-webdata 1.1.7 起 useDbOrm=true 時必填; 只放行已識別使用者之 select, 拒絕記 srLog (spec D17)
|
|
1059
1074
|
tableNamesSync,
|
|
1060
1075
|
kpFunExt: { //接收參數第1個為userId, 之後才是前端給予參數 (皆經 wrapErrLog)
|
|
1061
1076
|
|
|
@@ -1109,7 +1124,7 @@ export default WWebTask
|
|
|
1109
1124
|
<br class="clear">
|
|
1110
1125
|
|
|
1111
1126
|
<footer>
|
|
1112
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on
|
|
1127
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Oct 14 2026 08:01:17 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
1113
1128
|
</footer>
|
|
1114
1129
|
|
|
1115
1130
|
<script>prettyPrint();</script>
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>server/authorizeExec.mjs - Documentation</title>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
10
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
11
|
+
<!--[if lt IE 9]>
|
|
12
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
13
|
+
<![endif]-->
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
15
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
16
|
+
<script src="scripts/nav.js" defer></script>
|
|
17
|
+
|
|
18
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
|
|
22
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
23
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
24
|
+
<div class="navicon"></div>
|
|
25
|
+
</label>
|
|
26
|
+
|
|
27
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
28
|
+
|
|
29
|
+
<nav >
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="WWebTask.html">WWebTask</a></li></ul><h3>Global</h3><ul><li><a href="global.html#createAuthorizeExec">createAuthorizeExec</a></li><li><a href="global.html#createLockSave">createLockSave</a></li><li><a href="global.html#describeUpstream">describeUpstream</a></li><li><a href="global.html#maskQuery">maskQuery</a></li><li><a href="global.html#maskTok">maskTok</a></li><li><a href="global.html#maskUrl">maskUrl</a></li><li><a href="global.html#submitGuard">submitGuard</a></li><li><a href="global.html#wrapInjected">wrapInjected</a></li></ul>
|
|
33
|
+
|
|
34
|
+
</nav>
|
|
35
|
+
|
|
36
|
+
<div id="main">
|
|
37
|
+
|
|
38
|
+
<h1 class="page-title">server/authorizeExec.mjs</h1>
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<section>
|
|
47
|
+
<article>
|
|
48
|
+
<pre class="prettyprint source linenums"><code>import get from 'lodash-es/get.js'
|
|
49
|
+
import isestr from 'wsemi/src/isestr.mjs'
|
|
50
|
+
import isearr from 'wsemi/src/isearr.mjs'
|
|
51
|
+
import isfun from 'wsemi/src/isfun.mjs'
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 資料通道表操作之授權函數(交 w-serv-hapi / w-serv-webdata 之 opt.authorizeExec; spec D17 決策 2)
|
|
56
|
+
*
|
|
57
|
+
* w-serv-webdata 1.1.7 起 useDbOrm=true 時必填, 前端呼叫表操作(如同步之 channels.select)時於 operOrm 之前呼叫,
|
|
58
|
+
* 回傳嚴格等於 true 才放行, 其他值一律回應 'permission denied' 且不呼叫 operOrm.
|
|
59
|
+
* 本套件之資料通道只開放 methodsExec 所列方法(['select'], 供前端同步); 寫入一律經 kpFunExt(D16 lockSave、確保成員列 kmx、D7 游標身分皆在其內).
|
|
60
|
+
* 放行: userId 為非空字串, 且 methodName 屬 methodsExec; 回傳一律為布林.
|
|
61
|
+
* 拒絕: 回 false 並記 srLog.error({ event: 'authorizeExec', err, tableName, methodName }), userId 缺為 'errUserIdMissing', 方法不在清單為 'errUserNoPermission'.
|
|
62
|
+
* getUserIdByToken 已 fail-closed 且 w-serv-webdata 只綁定 methodsExec 之方法, 故兩個拒絕分支於正常呼叫不會發生, 屬縱深防護.
|
|
63
|
+
*
|
|
64
|
+
* @param {Object} opt 輸入設定物件
|
|
65
|
+
* @param {Array} opt.methodsExec 輸入允許之表操作方法陣列(須與交 w-serv-hapi 之 methodsExec 為同一陣列), 須為非空陣列
|
|
66
|
+
* @param {Object} opt.srLog 輸入後端 log 物件, 須具 error 函數
|
|
67
|
+
* @returns {Function} 回傳 ({ userId, tableName, methodName }) => Boolean
|
|
68
|
+
*/
|
|
69
|
+
function createAuthorizeExec(opt = {}) {
|
|
70
|
+
|
|
71
|
+
//methodsExec
|
|
72
|
+
let methodsExec = get(opt, 'methodsExec')
|
|
73
|
+
if (!isearr(methodsExec)) {
|
|
74
|
+
throw new Error('invalid opt.methodsExec')
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//srLog
|
|
78
|
+
let srLog = get(opt, 'srLog')
|
|
79
|
+
if (!isfun(get(srLog, 'error'))) {
|
|
80
|
+
throw new Error('invalid opt.srLog')
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
let authorizeExec = ({ userId, tableName, methodName } = {}) => {
|
|
84
|
+
|
|
85
|
+
//check userId
|
|
86
|
+
if (!isestr(userId)) {
|
|
87
|
+
srLog.error({ event: 'authorizeExec', err: 'errUserIdMissing', tableName, methodName })
|
|
88
|
+
return false
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
//check methodName
|
|
92
|
+
if (!methodsExec.includes(methodName)) {
|
|
93
|
+
srLog.error({ event: 'authorizeExec', err: 'errUserNoPermission', tableName, methodName })
|
|
94
|
+
return false
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return true
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return authorizeExec
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
export default createAuthorizeExec
|
|
105
|
+
</code></pre>
|
|
106
|
+
</article>
|
|
107
|
+
</section>
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
</div>
|
|
115
|
+
|
|
116
|
+
<br class="clear">
|
|
117
|
+
|
|
118
|
+
<footer>
|
|
119
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Oct 14 2026 08:01:17 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
120
|
+
</footer>
|
|
121
|
+
|
|
122
|
+
<script>prettyPrint();</script>
|
|
123
|
+
<script src="scripts/polyfill.js"></script>
|
|
124
|
+
<script src="scripts/linenumber.js"></script>
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
</body>
|
|
129
|
+
</html>
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
<nav >
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="WWebTask.html">WWebTask</a></li></ul><h3>Global</h3><ul><li><a href="global.html#createLockSave">createLockSave</a></li><li><a href="global.html#describeUpstream">describeUpstream</a></li><li><a href="global.html#maskQuery">maskQuery</a></li><li><a href="global.html#maskTok">maskTok</a></li><li><a href="global.html#maskUrl">maskUrl</a></li><li><a href="global.html#submitGuard">submitGuard</a></li><li><a href="global.html#wrapInjected">wrapInjected</a></li></ul>
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="WWebTask.html">WWebTask</a></li></ul><h3>Global</h3><ul><li><a href="global.html#createAuthorizeExec">createAuthorizeExec</a></li><li><a href="global.html#createLockSave">createLockSave</a></li><li><a href="global.html#describeUpstream">describeUpstream</a></li><li><a href="global.html#maskQuery">maskQuery</a></li><li><a href="global.html#maskTok">maskTok</a></li><li><a href="global.html#maskUrl">maskUrl</a></li><li><a href="global.html#submitGuard">submitGuard</a></li><li><a href="global.html#wrapInjected">wrapInjected</a></li></ul>
|
|
33
33
|
|
|
34
34
|
</nav>
|
|
35
35
|
|
|
@@ -102,7 +102,7 @@ export default createLockSave
|
|
|
102
102
|
<br class="clear">
|
|
103
103
|
|
|
104
104
|
<footer>
|
|
105
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on
|
|
105
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Oct 14 2026 08:01:17 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
106
106
|
</footer>
|
|
107
107
|
|
|
108
108
|
<script>prettyPrint();</script>
|