@lark-apaas/fullstack-nestjs-core 1.1.18-alpha.1 → 1.1.19-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1887 -79
- package/dist/index.d.cts +37 -3
- package/dist/index.d.ts +37 -3
- package/dist/index.js +1876 -71
- package/package.json +8 -7
package/dist/index.cjs
CHANGED
|
@@ -32,11 +32,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
32
32
|
// src/index.ts
|
|
33
33
|
var index_exports = {};
|
|
34
34
|
__export(index_exports, {
|
|
35
|
-
AutoTrace: () =>
|
|
35
|
+
AutoTrace: () => import_nestjs_common10.AutoTrace,
|
|
36
|
+
CanRole: () => CanRole,
|
|
36
37
|
CsrfMiddleware: () => CsrfMiddleware,
|
|
37
38
|
CsrfTokenMiddleware: () => CsrfTokenMiddleware,
|
|
38
39
|
DevToolsModule: () => import_nestjs_openapi_devtools2.DevToolsModule,
|
|
39
40
|
DevToolsV2Module: () => import_nestjs_openapi_devtools2.DevToolsV2Module,
|
|
41
|
+
FileService: () => FileService,
|
|
40
42
|
PlatformModule: () => PlatformModule,
|
|
41
43
|
UserContextMiddleware: () => UserContextMiddleware,
|
|
42
44
|
ViewContextMiddleware: () => ViewContextMiddleware,
|
|
@@ -45,9 +47,9 @@ __export(index_exports, {
|
|
|
45
47
|
module.exports = __toCommonJS(index_exports);
|
|
46
48
|
|
|
47
49
|
// src/modules/platform/module.ts
|
|
48
|
-
var
|
|
49
|
-
var
|
|
50
|
-
var
|
|
50
|
+
var import_common20 = require("@nestjs/common");
|
|
51
|
+
var import_core10 = require("@nestjs/core");
|
|
52
|
+
var import_nestjs_common8 = require("@lark-apaas/nestjs-common");
|
|
51
53
|
var import_config2 = require("@nestjs/config");
|
|
52
54
|
var import_nestjs_observable = require("@lark-apaas/nestjs-observable");
|
|
53
55
|
var import_axios2 = require("@nestjs/axios");
|
|
@@ -55,7 +57,7 @@ var import_nestjs_logger2 = require("@lark-apaas/nestjs-logger");
|
|
|
55
57
|
var import_nestjs_datapaas = require("@lark-apaas/nestjs-datapaas");
|
|
56
58
|
var import_nestjs_authnpaas = require("@lark-apaas/nestjs-authnpaas");
|
|
57
59
|
var import_nestjs_trigger = require("@lark-apaas/nestjs-trigger");
|
|
58
|
-
var
|
|
60
|
+
var import_nestjs_common9 = require("@lark-apaas/nestjs-common");
|
|
59
61
|
var import_nestjs_capability = require("@lark-apaas/nestjs-capability");
|
|
60
62
|
|
|
61
63
|
// src/middlewares/user-context/index.ts
|
|
@@ -82,10 +84,10 @@ __name(getWebUserFromHeader, "getWebUserFromHeader");
|
|
|
82
84
|
|
|
83
85
|
// src/middlewares/user-context/index.ts
|
|
84
86
|
function _ts_decorate(decorators, target, key, desc) {
|
|
85
|
-
var
|
|
86
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
87
|
-
else for (var
|
|
88
|
-
return
|
|
87
|
+
var c4 = arguments.length, r2 = c4 < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d4;
|
|
88
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r2 = Reflect.decorate(decorators, target, key, desc);
|
|
89
|
+
else for (var i4 = decorators.length - 1; i4 >= 0; i4--) if (d4 = decorators[i4]) r2 = (c4 < 3 ? d4(r2) : c4 > 3 ? d4(target, key, r2) : d4(target, key)) || r2;
|
|
90
|
+
return c4 > 3 && r2 && Object.defineProperty(target, key, r2), r2;
|
|
89
91
|
}
|
|
90
92
|
__name(_ts_decorate, "_ts_decorate");
|
|
91
93
|
var UserContextMiddleware = class {
|
|
@@ -104,7 +106,8 @@ var UserContextMiddleware = class {
|
|
|
104
106
|
userName: webUser?.user_name?.zh_cn ?? "",
|
|
105
107
|
userNameEn: webUser?.user_name?.en_us ?? "",
|
|
106
108
|
userNameI18n: webUser?.user_name ?? {},
|
|
107
|
-
isSystemAccount: webUser?.is_system_account ?? false
|
|
109
|
+
isSystemAccount: webUser?.is_system_account ?? false,
|
|
110
|
+
roles: webUser?.roles ?? []
|
|
108
111
|
};
|
|
109
112
|
next();
|
|
110
113
|
}
|
|
@@ -132,10 +135,10 @@ __name(sendForbidden, "sendForbidden");
|
|
|
132
135
|
|
|
133
136
|
// src/middlewares/csrf/index.ts
|
|
134
137
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
135
|
-
var
|
|
136
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
137
|
-
else for (var
|
|
138
|
-
return
|
|
138
|
+
var c4 = arguments.length, r2 = c4 < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d4;
|
|
139
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r2 = Reflect.decorate(decorators, target, key, desc);
|
|
140
|
+
else for (var i4 = decorators.length - 1; i4 >= 0; i4--) if (d4 = decorators[i4]) r2 = (c4 < 3 ? d4(r2) : c4 > 3 ? d4(target, key, r2) : d4(target, key)) || r2;
|
|
141
|
+
return c4 > 3 && r2 && Object.defineProperty(target, key, r2), r2;
|
|
139
142
|
}
|
|
140
143
|
__name(_ts_decorate2, "_ts_decorate");
|
|
141
144
|
var CsrfMiddleware = class _CsrfMiddleware {
|
|
@@ -174,9 +177,9 @@ var import_common3 = require("@nestjs/common");
|
|
|
174
177
|
var import_nestjs_common = require("@lark-apaas/nestjs-common");
|
|
175
178
|
|
|
176
179
|
// src/utils/safe-stringify.ts
|
|
177
|
-
function safeEscape(
|
|
178
|
-
return
|
|
179
|
-
switch (
|
|
180
|
+
function safeEscape(s3) {
|
|
181
|
+
return s3.replace(/[<>&='"\n\r\u2028\u2029]/g, function(c4) {
|
|
182
|
+
switch (c4.charCodeAt(0)) {
|
|
180
183
|
case 60:
|
|
181
184
|
return "\\u003c";
|
|
182
185
|
// <
|
|
@@ -210,7 +213,7 @@ function safeEscape(s) {
|
|
|
210
213
|
return "\\u2029";
|
|
211
214
|
// 段落分隔符
|
|
212
215
|
default:
|
|
213
|
-
return
|
|
216
|
+
return c4;
|
|
214
217
|
}
|
|
215
218
|
});
|
|
216
219
|
}
|
|
@@ -218,14 +221,14 @@ __name(safeEscape, "safeEscape");
|
|
|
218
221
|
|
|
219
222
|
// src/middlewares/view-context/index.ts
|
|
220
223
|
function _ts_decorate3(decorators, target, key, desc) {
|
|
221
|
-
var
|
|
222
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
223
|
-
else for (var
|
|
224
|
-
return
|
|
224
|
+
var c4 = arguments.length, r2 = c4 < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d4;
|
|
225
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r2 = Reflect.decorate(decorators, target, key, desc);
|
|
226
|
+
else for (var i4 = decorators.length - 1; i4 >= 0; i4--) if (d4 = decorators[i4]) r2 = (c4 < 3 ? d4(r2) : c4 > 3 ? d4(target, key, r2) : d4(target, key)) || r2;
|
|
227
|
+
return c4 > 3 && r2 && Object.defineProperty(target, key, r2), r2;
|
|
225
228
|
}
|
|
226
229
|
__name(_ts_decorate3, "_ts_decorate");
|
|
227
|
-
function _ts_metadata(k,
|
|
228
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k,
|
|
230
|
+
function _ts_metadata(k, v4) {
|
|
231
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v4);
|
|
229
232
|
}
|
|
230
233
|
__name(_ts_metadata, "_ts_metadata");
|
|
231
234
|
function _ts_param(paramIndex, decorator) {
|
|
@@ -264,7 +267,7 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
|
|
|
264
267
|
}
|
|
265
268
|
}
|
|
266
269
|
async use(req, res, next) {
|
|
267
|
-
const { userId, tenantId, appId } = req.userContext;
|
|
270
|
+
const { userId, tenantId, appId, loginUrl, userType } = req.userContext;
|
|
268
271
|
const csrfToken = req.csrfToken;
|
|
269
272
|
const appInfo = await this.getAppInfo(appId);
|
|
270
273
|
const environment = mapToWindowEnvironment(process.env.FORCE_FRAMEWORK_ENVIRONMENT);
|
|
@@ -275,6 +278,8 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
|
|
|
275
278
|
appName: safeEscape(appInfo?.app_name ?? "\u5999\u642D\u5E94\u7528"),
|
|
276
279
|
appAvatar: appInfo?.app_avatar ?? "",
|
|
277
280
|
appDescription: safeEscape(appInfo?.app_description ?? ""),
|
|
281
|
+
loginUrl: loginUrl ?? "",
|
|
282
|
+
userType: userType ?? "",
|
|
278
283
|
tenantId,
|
|
279
284
|
environment
|
|
280
285
|
};
|
|
@@ -283,6 +288,8 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
|
|
|
283
288
|
csrfToken: csrfToken ?? "",
|
|
284
289
|
userId: userId ?? "",
|
|
285
290
|
tenantId: tenantId ?? "",
|
|
291
|
+
loginUrl: loginUrl ?? "",
|
|
292
|
+
userType: userType ?? "",
|
|
286
293
|
appId: appId ?? "",
|
|
287
294
|
appName: safeEscape(appInfo?.app_name ?? "\u5999\u642D\u5E94\u7528"),
|
|
288
295
|
appAvatar: appInfo?.app_avatar ?? "",
|
|
@@ -326,19 +333,19 @@ __name(resolveCsrfTokenOptions, "resolveCsrfTokenOptions");
|
|
|
326
333
|
function genToken() {
|
|
327
334
|
const ts = Math.floor(Date.now() / 1e3);
|
|
328
335
|
const randInt64 = BigInt("0x" + import_crypto.default.randomBytes(8).toString("hex")).toString();
|
|
329
|
-
const
|
|
336
|
+
const s3 = `${randInt64}.${ts}`;
|
|
330
337
|
const sha1 = import_crypto.default.createHash("sha1");
|
|
331
|
-
sha1.update(
|
|
338
|
+
sha1.update(s3);
|
|
332
339
|
return `${sha1.digest("hex")}-${ts}`;
|
|
333
340
|
}
|
|
334
341
|
__name(genToken, "genToken");
|
|
335
342
|
|
|
336
343
|
// src/middlewares/csrf_token/index.ts
|
|
337
344
|
function _ts_decorate4(decorators, target, key, desc) {
|
|
338
|
-
var
|
|
339
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
340
|
-
else for (var
|
|
341
|
-
return
|
|
345
|
+
var c4 = arguments.length, r2 = c4 < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d4;
|
|
346
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r2 = Reflect.decorate(decorators, target, key, desc);
|
|
347
|
+
else for (var i4 = decorators.length - 1; i4 >= 0; i4--) if (d4 = decorators[i4]) r2 = (c4 < 3 ? d4(r2) : c4 > 3 ? d4(target, key, r2) : d4(target, key)) || r2;
|
|
348
|
+
return c4 > 3 && r2 && Object.defineProperty(target, key, r2), r2;
|
|
342
349
|
}
|
|
343
350
|
__name(_ts_decorate4, "_ts_decorate");
|
|
344
351
|
var CsrfTokenMiddleware = class _CsrfTokenMiddleware {
|
|
@@ -410,14 +417,14 @@ __name(apiResponseInterceptor, "apiResponseInterceptor");
|
|
|
410
417
|
var import_common5 = require("@nestjs/common");
|
|
411
418
|
var import_nestjs_common2 = require("@lark-apaas/nestjs-common");
|
|
412
419
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
413
|
-
var
|
|
414
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
415
|
-
else for (var
|
|
416
|
-
return
|
|
420
|
+
var c4 = arguments.length, r2 = c4 < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d4;
|
|
421
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r2 = Reflect.decorate(decorators, target, key, desc);
|
|
422
|
+
else for (var i4 = decorators.length - 1; i4 >= 0; i4--) if (d4 = decorators[i4]) r2 = (c4 < 3 ? d4(r2) : c4 > 3 ? d4(target, key, r2) : d4(target, key)) || r2;
|
|
423
|
+
return c4 > 3 && r2 && Object.defineProperty(target, key, r2), r2;
|
|
417
424
|
}
|
|
418
425
|
__name(_ts_decorate5, "_ts_decorate");
|
|
419
|
-
function _ts_metadata2(k,
|
|
420
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k,
|
|
426
|
+
function _ts_metadata2(k, v4) {
|
|
427
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v4);
|
|
421
428
|
}
|
|
422
429
|
__name(_ts_metadata2, "_ts_metadata");
|
|
423
430
|
var RequestContextMiddleware = class {
|
|
@@ -431,12 +438,14 @@ var RequestContextMiddleware = class {
|
|
|
431
438
|
use(req, _res, next) {
|
|
432
439
|
const path = req.originalUrl ?? req.url;
|
|
433
440
|
const userContext = req.userContext ?? {};
|
|
441
|
+
const ttEnv = req.headers["x-tt-env"];
|
|
434
442
|
this.requestContext.run({
|
|
435
443
|
path,
|
|
436
444
|
method: req.method,
|
|
437
445
|
userId: userContext.userId,
|
|
438
446
|
tenantId: userContext.tenantId,
|
|
439
|
-
appId: userContext.appId
|
|
447
|
+
appId: userContext.appId,
|
|
448
|
+
ttEnv
|
|
440
449
|
}, () => next());
|
|
441
450
|
}
|
|
442
451
|
};
|
|
@@ -453,14 +462,14 @@ var import_common6 = require("@nestjs/common");
|
|
|
453
462
|
var import_axios = require("@nestjs/axios");
|
|
454
463
|
var import_nestjs_logger = require("@lark-apaas/nestjs-logger");
|
|
455
464
|
function _ts_decorate6(decorators, target, key, desc) {
|
|
456
|
-
var
|
|
457
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
458
|
-
else for (var
|
|
459
|
-
return
|
|
465
|
+
var c4 = arguments.length, r2 = c4 < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d4;
|
|
466
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r2 = Reflect.decorate(decorators, target, key, desc);
|
|
467
|
+
else for (var i4 = decorators.length - 1; i4 >= 0; i4--) if (d4 = decorators[i4]) r2 = (c4 < 3 ? d4(r2) : c4 > 3 ? d4(target, key, r2) : d4(target, key)) || r2;
|
|
468
|
+
return c4 > 3 && r2 && Object.defineProperty(target, key, r2), r2;
|
|
460
469
|
}
|
|
461
470
|
__name(_ts_decorate6, "_ts_decorate");
|
|
462
|
-
function _ts_metadata3(k,
|
|
463
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k,
|
|
471
|
+
function _ts_metadata3(k, v4) {
|
|
472
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v4);
|
|
464
473
|
}
|
|
465
474
|
__name(_ts_metadata3, "_ts_metadata");
|
|
466
475
|
var HttpInterceptorService = class {
|
|
@@ -548,14 +557,14 @@ var app_config_default = (0, import_config.registerAs)(NAMESPACE, () => {
|
|
|
548
557
|
var import_common7 = require("@nestjs/common");
|
|
549
558
|
var import_core = require("@nestjs/core");
|
|
550
559
|
function _ts_decorate7(decorators, target, key, desc) {
|
|
551
|
-
var
|
|
552
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
553
|
-
else for (var
|
|
554
|
-
return
|
|
560
|
+
var c4 = arguments.length, r2 = c4 < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d4;
|
|
561
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r2 = Reflect.decorate(decorators, target, key, desc);
|
|
562
|
+
else for (var i4 = decorators.length - 1; i4 >= 0; i4--) if (d4 = decorators[i4]) r2 = (c4 < 3 ? d4(r2) : c4 > 3 ? d4(target, key, r2) : d4(target, key)) || r2;
|
|
563
|
+
return c4 > 3 && r2 && Object.defineProperty(target, key, r2), r2;
|
|
555
564
|
}
|
|
556
565
|
__name(_ts_decorate7, "_ts_decorate");
|
|
557
|
-
function _ts_metadata4(k,
|
|
558
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k,
|
|
566
|
+
function _ts_metadata4(k, v4) {
|
|
567
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v4);
|
|
559
568
|
}
|
|
560
569
|
__name(_ts_metadata4, "_ts_metadata");
|
|
561
570
|
var processStartTimestamp = Date.now();
|
|
@@ -616,15 +625,16 @@ FrameworkDebugMiddleware = _ts_decorate7([
|
|
|
616
625
|
// src/services/platform-http-client.service.ts
|
|
617
626
|
var import_common8 = require("@nestjs/common");
|
|
618
627
|
var import_http_client = require("@lark-apaas/http-client");
|
|
628
|
+
var import_nestjs_common3 = require("@lark-apaas/nestjs-common");
|
|
619
629
|
function _ts_decorate8(decorators, target, key, desc) {
|
|
620
|
-
var
|
|
621
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
622
|
-
else for (var
|
|
623
|
-
return
|
|
630
|
+
var c4 = arguments.length, r2 = c4 < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d4;
|
|
631
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r2 = Reflect.decorate(decorators, target, key, desc);
|
|
632
|
+
else for (var i4 = decorators.length - 1; i4 >= 0; i4--) if (d4 = decorators[i4]) r2 = (c4 < 3 ? d4(r2) : c4 > 3 ? d4(target, key, r2) : d4(target, key)) || r2;
|
|
633
|
+
return c4 > 3 && r2 && Object.defineProperty(target, key, r2), r2;
|
|
624
634
|
}
|
|
625
635
|
__name(_ts_decorate8, "_ts_decorate");
|
|
626
|
-
function _ts_metadata5(k,
|
|
627
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k,
|
|
636
|
+
function _ts_metadata5(k, v4) {
|
|
637
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v4);
|
|
628
638
|
}
|
|
629
639
|
__name(_ts_metadata5, "_ts_metadata");
|
|
630
640
|
var ProtectedHttpClient = class ProtectedHttpClient2 {
|
|
@@ -658,10 +668,12 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
|
|
|
658
668
|
static {
|
|
659
669
|
__name(this, "PlatformHttpClientService");
|
|
660
670
|
}
|
|
671
|
+
requestContext;
|
|
661
672
|
client;
|
|
662
673
|
protectedClient;
|
|
663
674
|
logger = new import_common8.Logger(_PlatformHttpClientService.name);
|
|
664
|
-
constructor() {
|
|
675
|
+
constructor(requestContext) {
|
|
676
|
+
this.requestContext = requestContext;
|
|
665
677
|
const baseConfig = {
|
|
666
678
|
timeout: 5e3
|
|
667
679
|
};
|
|
@@ -752,6 +764,13 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
|
|
|
752
764
|
registerGlobalInterceptors() {
|
|
753
765
|
this.client.interceptors.request.use((config) => {
|
|
754
766
|
this.logger.debug(`Server SDK HTTP Request: ${config.method?.toUpperCase()} ${config.url}`);
|
|
767
|
+
const ttEnv = this.requestContext.get("ttEnv");
|
|
768
|
+
if (ttEnv) {
|
|
769
|
+
config.headers = {
|
|
770
|
+
...config.headers,
|
|
771
|
+
"x-tt-env": ttEnv
|
|
772
|
+
};
|
|
773
|
+
}
|
|
755
774
|
return config;
|
|
756
775
|
}, (error) => {
|
|
757
776
|
this.logger.error("Server SDK HTTP Request Error", error, "HttpService");
|
|
@@ -774,20 +793,1802 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
|
|
|
774
793
|
PlatformHttpClientService = _ts_decorate8([
|
|
775
794
|
(0, import_common8.Injectable)(),
|
|
776
795
|
_ts_metadata5("design:type", Function),
|
|
777
|
-
_ts_metadata5("design:paramtypes", [
|
|
796
|
+
_ts_metadata5("design:paramtypes", [
|
|
797
|
+
typeof import_nestjs_common3.RequestContextService === "undefined" ? Object : import_nestjs_common3.RequestContextService
|
|
798
|
+
])
|
|
778
799
|
], PlatformHttpClientService);
|
|
779
800
|
|
|
780
801
|
// src/modules/platform/config/feature-switch.ts
|
|
781
802
|
var DISABLE_DATAPASS = process.env.FORCE_FRAMEWORK_DISABLE_DATAPASS === "true";
|
|
782
803
|
|
|
783
|
-
// src/
|
|
804
|
+
// src/services/file.service.ts
|
|
805
|
+
var import_common9 = require("@nestjs/common");
|
|
806
|
+
var import_nestjs_common4 = require("@lark-apaas/nestjs-common");
|
|
807
|
+
var import_file_service = require("@lark-apaas/file-service");
|
|
784
808
|
function _ts_decorate9(decorators, target, key, desc) {
|
|
785
|
-
var
|
|
786
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
787
|
-
else for (var
|
|
788
|
-
return
|
|
809
|
+
var c4 = arguments.length, r2 = c4 < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d4;
|
|
810
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r2 = Reflect.decorate(decorators, target, key, desc);
|
|
811
|
+
else for (var i4 = decorators.length - 1; i4 >= 0; i4--) if (d4 = decorators[i4]) r2 = (c4 < 3 ? d4(r2) : c4 > 3 ? d4(target, key, r2) : d4(target, key)) || r2;
|
|
812
|
+
return c4 > 3 && r2 && Object.defineProperty(target, key, r2), r2;
|
|
789
813
|
}
|
|
790
814
|
__name(_ts_decorate9, "_ts_decorate");
|
|
815
|
+
function _ts_metadata6(k, v4) {
|
|
816
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v4);
|
|
817
|
+
}
|
|
818
|
+
__name(_ts_metadata6, "_ts_metadata");
|
|
819
|
+
function _ts_param2(paramIndex, decorator) {
|
|
820
|
+
return function(target, key) {
|
|
821
|
+
decorator(target, key, paramIndex);
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
__name(_ts_param2, "_ts_param");
|
|
825
|
+
var FileService = class {
|
|
826
|
+
static {
|
|
827
|
+
__name(this, "FileService");
|
|
828
|
+
}
|
|
829
|
+
requestContextService;
|
|
830
|
+
httpClient;
|
|
831
|
+
observable;
|
|
832
|
+
fileServiceCore;
|
|
833
|
+
nestLogger;
|
|
834
|
+
constructor(requestContextService, httpClient, observable) {
|
|
835
|
+
this.requestContextService = requestContextService;
|
|
836
|
+
this.httpClient = httpClient;
|
|
837
|
+
this.observable = observable;
|
|
838
|
+
this.fileServiceCore = new import_file_service.FileService(this.httpClient);
|
|
839
|
+
this.nestLogger = new import_common9.Logger("file");
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* 返回一个绑定了指定 bucket 的代理对象
|
|
843
|
+
* 不会修改 context,避免副作用
|
|
844
|
+
*/
|
|
845
|
+
from(bucket) {
|
|
846
|
+
return {
|
|
847
|
+
upload: /* @__PURE__ */ __name((file, options) => this._upload(bucket, file, options), "upload"),
|
|
848
|
+
download: /* @__PURE__ */ __name((path) => this._download(bucket, path), "download"),
|
|
849
|
+
list: /* @__PURE__ */ __name((prefix, searchOptions) => this._list(bucket, prefix, searchOptions), "list"),
|
|
850
|
+
remove: /* @__PURE__ */ __name((filePaths) => this._remove(bucket, filePaths), "remove"),
|
|
851
|
+
createSignedUrl: /* @__PURE__ */ __name((path, expiresIn) => this._createSignedUrl(bucket, path, expiresIn), "createSignedUrl"),
|
|
852
|
+
getFileMetadata: /* @__PURE__ */ __name((filePath) => this._getFileMetadata(bucket, filePath), "getFileMetadata")
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
// ============ 公开方法(使用默认 bucket)============
|
|
856
|
+
async upload(file, options) {
|
|
857
|
+
return this._upload(await this.getDefaultBucket(), file, options);
|
|
858
|
+
}
|
|
859
|
+
download(path) {
|
|
860
|
+
const capturedBucketPromise = this.getDefaultBucket();
|
|
861
|
+
return this._download(capturedBucketPromise, path);
|
|
862
|
+
}
|
|
863
|
+
async list(prefix, searchOptions) {
|
|
864
|
+
return this._list(await this.getDefaultBucket(), prefix, searchOptions);
|
|
865
|
+
}
|
|
866
|
+
async remove(filePaths) {
|
|
867
|
+
return this._remove(await this.getDefaultBucket(), filePaths);
|
|
868
|
+
}
|
|
869
|
+
async createSignedUrl(path, expiresIn) {
|
|
870
|
+
return this._createSignedUrl(await this.getDefaultBucket(), path, expiresIn);
|
|
871
|
+
}
|
|
872
|
+
async getFileMetadata(filePath) {
|
|
873
|
+
return this._getFileMetadata(await this.getDefaultBucket(), filePath);
|
|
874
|
+
}
|
|
875
|
+
async getDefaultBucket() {
|
|
876
|
+
const reqContext = this.requestContextService.getContext();
|
|
877
|
+
const bucketFromContext = reqContext?.bucket;
|
|
878
|
+
if (bucketFromContext) {
|
|
879
|
+
return bucketFromContext;
|
|
880
|
+
}
|
|
881
|
+
const appId = this.getAppId();
|
|
882
|
+
const bucket = await this.fileServiceCore.getDefaultBucket(appId);
|
|
883
|
+
return bucket;
|
|
884
|
+
}
|
|
885
|
+
getAppId() {
|
|
886
|
+
const requestCtx = this.requestContextService.getContext();
|
|
887
|
+
return requestCtx?.appId ?? "";
|
|
888
|
+
}
|
|
889
|
+
// ============ 核心实现方法(接受 bucket 参数)============
|
|
890
|
+
async _upload(bucket, file, options) {
|
|
891
|
+
const span = this.observable.startTrace("\u6587\u4EF6: upload", this.requestContextService.getContext()?.requestRootSpan);
|
|
892
|
+
span.setAttribute("module", "file");
|
|
893
|
+
span.setAttribute("source_type", "platform");
|
|
894
|
+
const spanContext = {
|
|
895
|
+
traceId: span.spanContext().traceId,
|
|
896
|
+
spanId: span.spanContext().spanId
|
|
897
|
+
};
|
|
898
|
+
const logContext = {
|
|
899
|
+
source_type: "platform",
|
|
900
|
+
paas_attributes_module: "file",
|
|
901
|
+
paas_parent_span_context: spanContext
|
|
902
|
+
};
|
|
903
|
+
const baseParams = {
|
|
904
|
+
method: "upload",
|
|
905
|
+
source_type: "server",
|
|
906
|
+
request: {
|
|
907
|
+
options
|
|
908
|
+
}
|
|
909
|
+
};
|
|
910
|
+
const startTime = Date.now();
|
|
911
|
+
try {
|
|
912
|
+
const res = await this.fileServiceCore.upload({
|
|
913
|
+
appId: this.getAppId(),
|
|
914
|
+
bucketId: await bucket,
|
|
915
|
+
fileBody: file,
|
|
916
|
+
options
|
|
917
|
+
});
|
|
918
|
+
this.nestLogger.log(JSON.stringify({
|
|
919
|
+
...baseParams,
|
|
920
|
+
response: res,
|
|
921
|
+
status: "succeed",
|
|
922
|
+
duration_ms: Date.now() - startTime
|
|
923
|
+
}), logContext);
|
|
924
|
+
return res;
|
|
925
|
+
} catch (e3) {
|
|
926
|
+
this.nestLogger.error(JSON.stringify({
|
|
927
|
+
...baseParams,
|
|
928
|
+
error_message: e3 instanceof Error ? e3.message : String(e3),
|
|
929
|
+
status: "failed",
|
|
930
|
+
duration_ms: Date.now() - startTime
|
|
931
|
+
}), logContext);
|
|
932
|
+
throw e3;
|
|
933
|
+
} finally {
|
|
934
|
+
span.end();
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
_download(bucket, path) {
|
|
938
|
+
const capturedAppId = this.getAppId();
|
|
939
|
+
const capturedRootSpan = this.requestContextService.getContext()?.requestRootSpan;
|
|
940
|
+
const downloadFn = /* @__PURE__ */ __name(async () => {
|
|
941
|
+
const span = this.observable.startTrace("\u6587\u4EF6: download", capturedRootSpan);
|
|
942
|
+
span.setAttribute("module", "file");
|
|
943
|
+
span.setAttribute("source_type", "platform");
|
|
944
|
+
const spanContext = {
|
|
945
|
+
traceId: span.spanContext().traceId,
|
|
946
|
+
spanId: span.spanContext().spanId
|
|
947
|
+
};
|
|
948
|
+
const logContext = {
|
|
949
|
+
source_type: "platform",
|
|
950
|
+
paas_attributes_module: "file",
|
|
951
|
+
paas_parent_span_context: spanContext
|
|
952
|
+
};
|
|
953
|
+
const baseParams = {
|
|
954
|
+
method: "download",
|
|
955
|
+
source_type: "server",
|
|
956
|
+
request: {
|
|
957
|
+
path
|
|
958
|
+
}
|
|
959
|
+
};
|
|
960
|
+
const startTime = Date.now();
|
|
961
|
+
try {
|
|
962
|
+
const res = await this.fileServiceCore.downloadInner({
|
|
963
|
+
appId: capturedAppId,
|
|
964
|
+
bucketId: await bucket,
|
|
965
|
+
filePath: path
|
|
966
|
+
});
|
|
967
|
+
this.nestLogger.log(JSON.stringify({
|
|
968
|
+
...baseParams,
|
|
969
|
+
response: {
|
|
970
|
+
metadata: res.metadata
|
|
971
|
+
},
|
|
972
|
+
status: "succeed",
|
|
973
|
+
duration_ms: Date.now() - startTime
|
|
974
|
+
}), logContext);
|
|
975
|
+
return res;
|
|
976
|
+
} catch (e3) {
|
|
977
|
+
this.nestLogger.error(JSON.stringify({
|
|
978
|
+
...baseParams,
|
|
979
|
+
error_message: e3 instanceof Error ? e3.message : String(e3),
|
|
980
|
+
status: "failed",
|
|
981
|
+
duration_ms: Date.now() - startTime
|
|
982
|
+
}), logContext);
|
|
983
|
+
throw e3;
|
|
984
|
+
} finally {
|
|
985
|
+
span.end();
|
|
986
|
+
}
|
|
987
|
+
}, "downloadFn");
|
|
988
|
+
return new import_file_service.FileDownloadBuilder(downloadFn);
|
|
989
|
+
}
|
|
990
|
+
async _list(bucket, prefix, searchOptions) {
|
|
991
|
+
const span = this.observable.startTrace("\u6587\u4EF6: list", this.requestContextService.getContext()?.requestRootSpan);
|
|
992
|
+
span.setAttribute("module", "file");
|
|
993
|
+
span.setAttribute("source_type", "platform");
|
|
994
|
+
const spanContext = {
|
|
995
|
+
traceId: span.spanContext().traceId,
|
|
996
|
+
spanId: span.spanContext().spanId
|
|
997
|
+
};
|
|
998
|
+
const logContext = {
|
|
999
|
+
source_type: "platform",
|
|
1000
|
+
paas_attributes_module: "file",
|
|
1001
|
+
paas_parent_span_context: spanContext
|
|
1002
|
+
};
|
|
1003
|
+
const baseParams = {
|
|
1004
|
+
method: "list",
|
|
1005
|
+
source_type: "server",
|
|
1006
|
+
request: {
|
|
1007
|
+
prefix,
|
|
1008
|
+
searchOptions
|
|
1009
|
+
}
|
|
1010
|
+
};
|
|
1011
|
+
const startTime = Date.now();
|
|
1012
|
+
try {
|
|
1013
|
+
const res = await this.fileServiceCore.list({
|
|
1014
|
+
appId: this.getAppId(),
|
|
1015
|
+
bucketId: await bucket,
|
|
1016
|
+
prefix,
|
|
1017
|
+
searchOptions
|
|
1018
|
+
});
|
|
1019
|
+
this.nestLogger.log(JSON.stringify({
|
|
1020
|
+
...baseParams,
|
|
1021
|
+
response: res,
|
|
1022
|
+
status: "succeed",
|
|
1023
|
+
duration_ms: Date.now() - startTime
|
|
1024
|
+
}), logContext);
|
|
1025
|
+
return res;
|
|
1026
|
+
} catch (e3) {
|
|
1027
|
+
this.nestLogger.error(JSON.stringify({
|
|
1028
|
+
...baseParams,
|
|
1029
|
+
error_message: e3 instanceof Error ? e3.message : String(e3),
|
|
1030
|
+
status: "failed",
|
|
1031
|
+
duration_ms: Date.now() - startTime
|
|
1032
|
+
}), logContext);
|
|
1033
|
+
throw e3;
|
|
1034
|
+
} finally {
|
|
1035
|
+
span.end();
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
async _remove(bucket, filePaths) {
|
|
1039
|
+
const span = this.observable.startTrace("\u6587\u4EF6: remove", this.requestContextService.getContext()?.requestRootSpan);
|
|
1040
|
+
span.setAttribute("module", "file");
|
|
1041
|
+
span.setAttribute("source_type", "platform");
|
|
1042
|
+
const spanContext = {
|
|
1043
|
+
traceId: span.spanContext().traceId,
|
|
1044
|
+
spanId: span.spanContext().spanId
|
|
1045
|
+
};
|
|
1046
|
+
const logContext = {
|
|
1047
|
+
source_type: "platform",
|
|
1048
|
+
paas_attributes_module: "file",
|
|
1049
|
+
paas_parent_span_context: spanContext
|
|
1050
|
+
};
|
|
1051
|
+
const baseParams = {
|
|
1052
|
+
method: "remove",
|
|
1053
|
+
source_type: "server",
|
|
1054
|
+
request: {
|
|
1055
|
+
filePaths
|
|
1056
|
+
}
|
|
1057
|
+
};
|
|
1058
|
+
const startTime = Date.now();
|
|
1059
|
+
try {
|
|
1060
|
+
const res = await this.fileServiceCore.remove({
|
|
1061
|
+
appId: this.getAppId(),
|
|
1062
|
+
bucketId: await bucket,
|
|
1063
|
+
filePaths
|
|
1064
|
+
});
|
|
1065
|
+
this.nestLogger.log(JSON.stringify({
|
|
1066
|
+
...baseParams,
|
|
1067
|
+
response: res,
|
|
1068
|
+
status: "succeed",
|
|
1069
|
+
duration_ms: Date.now() - startTime
|
|
1070
|
+
}), logContext);
|
|
1071
|
+
return res;
|
|
1072
|
+
} catch (e3) {
|
|
1073
|
+
this.nestLogger.error(JSON.stringify({
|
|
1074
|
+
...baseParams,
|
|
1075
|
+
error_message: e3 instanceof Error ? e3.message : String(e3),
|
|
1076
|
+
status: "failed",
|
|
1077
|
+
duration_ms: Date.now() - startTime
|
|
1078
|
+
}), logContext);
|
|
1079
|
+
throw e3;
|
|
1080
|
+
} finally {
|
|
1081
|
+
span.end();
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
async _createSignedUrl(bucket, path, expiresIn) {
|
|
1085
|
+
const span = this.observable.startTrace("\u6587\u4EF6: createSignedUrl", this.requestContextService.getContext()?.requestRootSpan);
|
|
1086
|
+
span.setAttribute("module", "file");
|
|
1087
|
+
span.setAttribute("source_type", "platform");
|
|
1088
|
+
const spanContext = {
|
|
1089
|
+
traceId: span.spanContext().traceId,
|
|
1090
|
+
spanId: span.spanContext().spanId
|
|
1091
|
+
};
|
|
1092
|
+
const logContext = {
|
|
1093
|
+
source_type: "platform",
|
|
1094
|
+
paas_attributes_module: "file",
|
|
1095
|
+
paas_parent_span_context: spanContext
|
|
1096
|
+
};
|
|
1097
|
+
const baseParams = {
|
|
1098
|
+
method: "createSignedUrl",
|
|
1099
|
+
source_type: "server",
|
|
1100
|
+
request: {
|
|
1101
|
+
path,
|
|
1102
|
+
expiresIn
|
|
1103
|
+
}
|
|
1104
|
+
};
|
|
1105
|
+
const startTime = Date.now();
|
|
1106
|
+
try {
|
|
1107
|
+
const res = await this.fileServiceCore.createSignedUrl({
|
|
1108
|
+
appId: this.getAppId(),
|
|
1109
|
+
bucketId: await bucket,
|
|
1110
|
+
filePath: path,
|
|
1111
|
+
expiresIn
|
|
1112
|
+
});
|
|
1113
|
+
this.nestLogger.log(JSON.stringify({
|
|
1114
|
+
...baseParams,
|
|
1115
|
+
response: res,
|
|
1116
|
+
status: "succeed",
|
|
1117
|
+
duration_ms: Date.now() - startTime
|
|
1118
|
+
}), logContext);
|
|
1119
|
+
return res;
|
|
1120
|
+
} catch (e3) {
|
|
1121
|
+
this.nestLogger.error(JSON.stringify({
|
|
1122
|
+
...baseParams,
|
|
1123
|
+
error_message: e3 instanceof Error ? e3.message : String(e3),
|
|
1124
|
+
status: "failed",
|
|
1125
|
+
duration_ms: Date.now() - startTime
|
|
1126
|
+
}), logContext);
|
|
1127
|
+
throw e3;
|
|
1128
|
+
} finally {
|
|
1129
|
+
span.end();
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
async _getFileMetadata(bucket, filePath) {
|
|
1133
|
+
const span = this.observable.startTrace("\u6587\u4EF6: getFileMetadata", this.requestContextService.getContext()?.requestRootSpan);
|
|
1134
|
+
span.setAttribute("module", "file");
|
|
1135
|
+
span.setAttribute("source_type", "platform");
|
|
1136
|
+
const spanContext = {
|
|
1137
|
+
traceId: span.spanContext().traceId,
|
|
1138
|
+
spanId: span.spanContext().spanId
|
|
1139
|
+
};
|
|
1140
|
+
const logContext = {
|
|
1141
|
+
source_type: "platform",
|
|
1142
|
+
paas_attributes_module: "file",
|
|
1143
|
+
paas_parent_span_context: spanContext
|
|
1144
|
+
};
|
|
1145
|
+
const baseParams = {
|
|
1146
|
+
method: "getFileMetadata",
|
|
1147
|
+
source_type: "server",
|
|
1148
|
+
request: {
|
|
1149
|
+
filePath
|
|
1150
|
+
}
|
|
1151
|
+
};
|
|
1152
|
+
const startTime = Date.now();
|
|
1153
|
+
try {
|
|
1154
|
+
const res = await this.fileServiceCore.getFileMetadata({
|
|
1155
|
+
appId: this.getAppId(),
|
|
1156
|
+
bucketId: await bucket,
|
|
1157
|
+
filePath
|
|
1158
|
+
});
|
|
1159
|
+
this.nestLogger.log(JSON.stringify({
|
|
1160
|
+
...baseParams,
|
|
1161
|
+
response: res,
|
|
1162
|
+
status: "succeed",
|
|
1163
|
+
duration_ms: Date.now() - startTime
|
|
1164
|
+
}), logContext);
|
|
1165
|
+
return res;
|
|
1166
|
+
} catch (e3) {
|
|
1167
|
+
this.nestLogger.error(JSON.stringify({
|
|
1168
|
+
...baseParams,
|
|
1169
|
+
error_message: e3 instanceof Error ? e3.message : String(e3),
|
|
1170
|
+
status: "failed",
|
|
1171
|
+
duration_ms: Date.now() - startTime
|
|
1172
|
+
}), logContext);
|
|
1173
|
+
throw e3;
|
|
1174
|
+
} finally {
|
|
1175
|
+
span.end();
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
};
|
|
1179
|
+
FileService = _ts_decorate9([
|
|
1180
|
+
(0, import_common9.Injectable)(),
|
|
1181
|
+
_ts_param2(1, (0, import_common9.Inject)(import_nestjs_common4.PLATFORM_HTTP_CLIENT)),
|
|
1182
|
+
_ts_param2(2, (0, import_common9.Inject)(import_nestjs_common4.OBSERVABLE_SERVICE)),
|
|
1183
|
+
_ts_metadata6("design:type", Function),
|
|
1184
|
+
_ts_metadata6("design:paramtypes", [
|
|
1185
|
+
typeof import_nestjs_common4.RequestContextService === "undefined" ? Object : import_nestjs_common4.RequestContextService,
|
|
1186
|
+
typeof PlatformHttpClient === "undefined" ? Object : PlatformHttpClient,
|
|
1187
|
+
typeof import_nestjs_common4.ObservableService === "undefined" ? Object : import_nestjs_common4.ObservableService
|
|
1188
|
+
])
|
|
1189
|
+
], FileService);
|
|
1190
|
+
|
|
1191
|
+
// ../nestjs-authzpaas/dist/index.js
|
|
1192
|
+
var import_common10 = require("@nestjs/common");
|
|
1193
|
+
var import_core6 = require("@nestjs/core");
|
|
1194
|
+
var import_common11 = require("@nestjs/common");
|
|
1195
|
+
var import_common12 = require("@nestjs/common");
|
|
1196
|
+
var import_core7 = require("@nestjs/core");
|
|
1197
|
+
var import_common13 = require("@nestjs/common");
|
|
1198
|
+
var import_core8 = require("@nestjs/core");
|
|
1199
|
+
var import_common14 = require("@nestjs/common");
|
|
1200
|
+
var import_common15 = require("@nestjs/common");
|
|
1201
|
+
var import_common16 = require("@nestjs/common");
|
|
1202
|
+
|
|
1203
|
+
// ../../../node_modules/@ucast/core/dist/es6m/index.mjs
|
|
1204
|
+
var t = class {
|
|
1205
|
+
static {
|
|
1206
|
+
__name(this, "t");
|
|
1207
|
+
}
|
|
1208
|
+
constructor(t3, e3) {
|
|
1209
|
+
this.operator = t3, this.value = e3, Object.defineProperty(this, "t", { writable: true });
|
|
1210
|
+
}
|
|
1211
|
+
get notes() {
|
|
1212
|
+
return this.t;
|
|
1213
|
+
}
|
|
1214
|
+
addNote(t3) {
|
|
1215
|
+
this.t = this.t || [], this.t.push(t3);
|
|
1216
|
+
}
|
|
1217
|
+
};
|
|
1218
|
+
var e = class extends t {
|
|
1219
|
+
static {
|
|
1220
|
+
__name(this, "e");
|
|
1221
|
+
}
|
|
1222
|
+
};
|
|
1223
|
+
var r = class extends e {
|
|
1224
|
+
static {
|
|
1225
|
+
__name(this, "r");
|
|
1226
|
+
}
|
|
1227
|
+
constructor(t3, e3) {
|
|
1228
|
+
if (!Array.isArray(e3)) throw new Error(`"${t3}" operator expects to receive an array of conditions`);
|
|
1229
|
+
super(t3, e3);
|
|
1230
|
+
}
|
|
1231
|
+
};
|
|
1232
|
+
var n = "__itself__";
|
|
1233
|
+
var o = class extends t {
|
|
1234
|
+
static {
|
|
1235
|
+
__name(this, "o");
|
|
1236
|
+
}
|
|
1237
|
+
constructor(t3, e3, r2) {
|
|
1238
|
+
super(t3, r2), this.field = e3;
|
|
1239
|
+
}
|
|
1240
|
+
};
|
|
1241
|
+
var s = new e("__null__", null);
|
|
1242
|
+
var i = Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty);
|
|
1243
|
+
function c(t3, e3) {
|
|
1244
|
+
return e3 instanceof r && e3.operator === t3;
|
|
1245
|
+
}
|
|
1246
|
+
__name(c, "c");
|
|
1247
|
+
function u(t3, e3) {
|
|
1248
|
+
return 1 === e3.length ? e3[0] : new r(t3, (/* @__PURE__ */ __name(function t4(e4, r2, n3) {
|
|
1249
|
+
const o3 = n3 || [];
|
|
1250
|
+
for (let n4 = 0, s3 = r2.length; n4 < s3; n4++) {
|
|
1251
|
+
const s4 = r2[n4];
|
|
1252
|
+
c(e4, s4) ? t4(e4, s4.value, o3) : o3.push(s4);
|
|
1253
|
+
}
|
|
1254
|
+
return o3;
|
|
1255
|
+
}, "t"))(t3, e3));
|
|
1256
|
+
}
|
|
1257
|
+
__name(u, "u");
|
|
1258
|
+
var a = /* @__PURE__ */ __name((t3) => t3, "a");
|
|
1259
|
+
var h = /* @__PURE__ */ __name(() => /* @__PURE__ */ Object.create(null), "h");
|
|
1260
|
+
var f = Object.defineProperty(h(), "__@type@__", { value: "ignore value" });
|
|
1261
|
+
function l(t3, e3, r2 = false) {
|
|
1262
|
+
if (!t3 || t3 && t3.constructor !== Object) return false;
|
|
1263
|
+
for (const n3 in t3) {
|
|
1264
|
+
if (i(t3, n3) && i(e3, n3) && (!r2 || t3[n3] !== f)) return true;
|
|
1265
|
+
}
|
|
1266
|
+
return false;
|
|
1267
|
+
}
|
|
1268
|
+
__name(l, "l");
|
|
1269
|
+
function d(t3) {
|
|
1270
|
+
const e3 = [];
|
|
1271
|
+
for (const r2 in t3) i(t3, r2) && t3[r2] !== f && e3.push(r2);
|
|
1272
|
+
return e3;
|
|
1273
|
+
}
|
|
1274
|
+
__name(d, "d");
|
|
1275
|
+
function p(t3, e3) {
|
|
1276
|
+
e3 !== s && t3.push(e3);
|
|
1277
|
+
}
|
|
1278
|
+
__name(p, "p");
|
|
1279
|
+
var w = /* @__PURE__ */ __name((t3) => u("and", t3), "w");
|
|
1280
|
+
var O = { compound(t3, e3, n3) {
|
|
1281
|
+
const o3 = (Array.isArray(e3) ? e3 : [e3]).map((t4) => n3.parse(t4));
|
|
1282
|
+
return new r(t3.name, o3);
|
|
1283
|
+
}, field: /* @__PURE__ */ __name((t3, e3, r2) => new o(t3.name, r2.field, e3), "field"), document: /* @__PURE__ */ __name((t3, r2) => new e(t3.name, r2), "document") };
|
|
1284
|
+
var j = class {
|
|
1285
|
+
static {
|
|
1286
|
+
__name(this, "j");
|
|
1287
|
+
}
|
|
1288
|
+
constructor(t3, e3 = h()) {
|
|
1289
|
+
this.o = void 0, this.s = void 0, this.i = void 0, this.u = void 0, this.h = void 0, this.parse = this.parse.bind(this), this.u = { operatorToConditionName: e3.operatorToConditionName || a, defaultOperatorName: e3.defaultOperatorName || "eq", mergeFinalConditions: e3.mergeFinalConditions || w }, this.o = Object.keys(t3).reduce((e4, r2) => (e4[r2] = Object.assign({ name: this.u.operatorToConditionName(r2) }, t3[r2]), e4), {}), this.s = Object.assign({}, e3.fieldContext, { field: "", query: {}, parse: this.parse, hasOperators: /* @__PURE__ */ __name((t4) => l(t4, this.o, e3.useIgnoreValue), "hasOperators") }), this.i = Object.assign({}, e3.documentContext, { parse: this.parse, query: {} }), this.h = e3.useIgnoreValue ? d : Object.keys;
|
|
1290
|
+
}
|
|
1291
|
+
setParse(t3) {
|
|
1292
|
+
this.parse = t3, this.s.parse = t3, this.i.parse = t3;
|
|
1293
|
+
}
|
|
1294
|
+
parseField(t3, e3, r2, n3) {
|
|
1295
|
+
const o3 = this.o[e3];
|
|
1296
|
+
if (!o3) throw new Error(`Unsupported operator "${e3}"`);
|
|
1297
|
+
if ("field" !== o3.type) throw new Error(`Unexpected ${o3.type} operator "${e3}" at field level`);
|
|
1298
|
+
return this.s.field = t3, this.s.query = n3, this.parseInstruction(o3, r2, this.s);
|
|
1299
|
+
}
|
|
1300
|
+
parseInstruction(t3, e3, r2) {
|
|
1301
|
+
"function" == typeof t3.validate && t3.validate(t3, e3);
|
|
1302
|
+
return (t3.parse || O[t3.type])(t3, e3, r2);
|
|
1303
|
+
}
|
|
1304
|
+
parseFieldOperators(t3, e3) {
|
|
1305
|
+
const r2 = [], n3 = this.h(e3);
|
|
1306
|
+
for (let o3 = 0, s3 = n3.length; o3 < s3; o3++) {
|
|
1307
|
+
const s4 = n3[o3];
|
|
1308
|
+
if (!this.o[s4]) throw new Error(`Field query for "${t3}" may contain only operators or a plain object as a value`);
|
|
1309
|
+
p(r2, this.parseField(t3, s4, e3[s4], e3));
|
|
1310
|
+
}
|
|
1311
|
+
return r2;
|
|
1312
|
+
}
|
|
1313
|
+
parse(t3) {
|
|
1314
|
+
const e3 = [], r2 = this.h(t3);
|
|
1315
|
+
this.i.query = t3;
|
|
1316
|
+
for (let n3 = 0, o3 = r2.length; n3 < o3; n3++) {
|
|
1317
|
+
const o4 = r2[n3], s3 = t3[o4], i4 = this.o[o4];
|
|
1318
|
+
if (i4) {
|
|
1319
|
+
if ("document" !== i4.type && "compound" !== i4.type) throw new Error(`Cannot use parsing instruction for operator "${o4}" in "document" context as it is supposed to be used in "${i4.type}" context`);
|
|
1320
|
+
p(e3, this.parseInstruction(i4, s3, this.i));
|
|
1321
|
+
} else this.s.hasOperators(s3) ? e3.push(...this.parseFieldOperators(o4, s3)) : p(e3, this.parseField(o4, this.u.defaultOperatorName, s3, t3));
|
|
1322
|
+
}
|
|
1323
|
+
return this.u.mergeFinalConditions(e3);
|
|
1324
|
+
}
|
|
1325
|
+
};
|
|
1326
|
+
function _(t3, e3) {
|
|
1327
|
+
const r2 = t3[e3];
|
|
1328
|
+
if ("function" != typeof r2) throw new Error(`Unable to interpret "${e3}" condition. Did you forget to register interpreter for it?`);
|
|
1329
|
+
return r2;
|
|
1330
|
+
}
|
|
1331
|
+
__name(_, "_");
|
|
1332
|
+
function y(t3) {
|
|
1333
|
+
return t3.operator;
|
|
1334
|
+
}
|
|
1335
|
+
__name(y, "y");
|
|
1336
|
+
function m(t3, e3) {
|
|
1337
|
+
const r2 = e3, n3 = r2 && r2.getInterpreterName || y;
|
|
1338
|
+
let o3;
|
|
1339
|
+
switch (r2 ? r2.numberOfArguments : 0) {
|
|
1340
|
+
case 1:
|
|
1341
|
+
o3 = /* @__PURE__ */ __name((e4) => {
|
|
1342
|
+
const o4 = n3(e4, r2);
|
|
1343
|
+
return _(t3, o4)(e4, s3);
|
|
1344
|
+
}, "o");
|
|
1345
|
+
break;
|
|
1346
|
+
case 3:
|
|
1347
|
+
o3 = /* @__PURE__ */ __name((e4, o4, i4) => {
|
|
1348
|
+
const c4 = n3(e4, r2);
|
|
1349
|
+
return _(t3, c4)(e4, o4, i4, s3);
|
|
1350
|
+
}, "o");
|
|
1351
|
+
break;
|
|
1352
|
+
default:
|
|
1353
|
+
o3 = /* @__PURE__ */ __name((e4, o4) => {
|
|
1354
|
+
const i4 = n3(e4, r2);
|
|
1355
|
+
return _(t3, i4)(e4, o4, s3);
|
|
1356
|
+
}, "o");
|
|
1357
|
+
}
|
|
1358
|
+
const s3 = Object.assign({}, r2, { interpret: o3 });
|
|
1359
|
+
return s3.interpret;
|
|
1360
|
+
}
|
|
1361
|
+
__name(m, "m");
|
|
1362
|
+
function v(t3, e3) {
|
|
1363
|
+
return (r2, ...n3) => {
|
|
1364
|
+
const o3 = t3(r2, ...n3), s3 = e3.bind(null, o3);
|
|
1365
|
+
return s3.ast = o3, s3;
|
|
1366
|
+
};
|
|
1367
|
+
}
|
|
1368
|
+
__name(v, "v");
|
|
1369
|
+
var x = j.prototype.parseInstruction;
|
|
1370
|
+
|
|
1371
|
+
// ../../../node_modules/@ucast/mongo/dist/es6m/index.mjs
|
|
1372
|
+
function s2(e3, t3) {
|
|
1373
|
+
if (!Array.isArray(t3)) throw new Error(`"${e3.name}" expects value to be an array`);
|
|
1374
|
+
}
|
|
1375
|
+
__name(s2, "s");
|
|
1376
|
+
function p2(e3, t3) {
|
|
1377
|
+
if (s2(e3, t3), !t3.length) throw new Error(`"${e3.name}" expects to have at least one element in array`);
|
|
1378
|
+
}
|
|
1379
|
+
__name(p2, "p");
|
|
1380
|
+
var l2 = /* @__PURE__ */ __name((e3) => (t3, r2) => {
|
|
1381
|
+
if (typeof r2 !== e3) throw new Error(`"${t3.name}" expects value to be a "${e3}"`);
|
|
1382
|
+
}, "l");
|
|
1383
|
+
var c2 = { type: "compound", validate: p2, parse(t3, r2, { parse: o3 }) {
|
|
1384
|
+
const a4 = r2.map((e3) => o3(e3));
|
|
1385
|
+
return u(t3.name, a4);
|
|
1386
|
+
} };
|
|
1387
|
+
var f2 = c2;
|
|
1388
|
+
var d2 = { type: "compound", validate: p2 };
|
|
1389
|
+
var u2 = { type: "field", validate(e3, t3) {
|
|
1390
|
+
if (!(t3 && (t3 instanceof RegExp || t3.constructor === Object))) throw new Error(`"${e3.name}" expects to receive either regular expression or object of field operators`);
|
|
1391
|
+
}, parse(e3, o3, a4) {
|
|
1392
|
+
const n3 = o3 instanceof RegExp ? new o("regex", a4.field, o3) : a4.parse(o3, a4);
|
|
1393
|
+
return new r(e3.name, [n3]);
|
|
1394
|
+
} };
|
|
1395
|
+
var $ = { type: "field", validate(e3, t3) {
|
|
1396
|
+
if (!t3 || t3.constructor !== Object) throw new Error(`"${e3.name}" expects to receive an object with nested query or field level operators`);
|
|
1397
|
+
}, parse(e3, r2, { parse: a4, field: n3, hasOperators: i4 }) {
|
|
1398
|
+
const s3 = i4(r2) ? a4(r2, { field: n }) : a4(r2);
|
|
1399
|
+
return new o(e3.name, n3, s3);
|
|
1400
|
+
} };
|
|
1401
|
+
var w2 = { type: "field", validate: l2("number") };
|
|
1402
|
+
var y2 = { type: "field", validate: s2 };
|
|
1403
|
+
var x2 = y2;
|
|
1404
|
+
var v2 = y2;
|
|
1405
|
+
var h2 = { type: "field", validate(e3, t3) {
|
|
1406
|
+
if (!Array.isArray(t3) || 2 !== t3.length) throw new Error(`"${e3.name}" expects an array with 2 numeric elements`);
|
|
1407
|
+
} };
|
|
1408
|
+
var m2 = { type: "field", validate: l2("boolean") };
|
|
1409
|
+
var g = { type: "field", validate: /* @__PURE__ */ __name(function(e3, t3) {
|
|
1410
|
+
if (!("string" == typeof t3 || "number" == typeof t3 || t3 instanceof Date)) throw new Error(`"${e3.name}" expects value to be comparable (i.e., string, number or date)`);
|
|
1411
|
+
}, "validate") };
|
|
1412
|
+
var b = g;
|
|
1413
|
+
var E = b;
|
|
1414
|
+
var j2 = b;
|
|
1415
|
+
var O2 = { type: "field" };
|
|
1416
|
+
var R = O2;
|
|
1417
|
+
var _2 = { type: "field", validate(e3, t3) {
|
|
1418
|
+
if (!(t3 instanceof RegExp) && "string" != typeof t3) throw new Error(`"${e3.name}" expects value to be a regular expression or a string that represents regular expression`);
|
|
1419
|
+
}, parse(e3, r2, o3) {
|
|
1420
|
+
const a4 = "string" == typeof r2 ? new RegExp(r2, o3.query.$options || "") : r2;
|
|
1421
|
+
return new o(e3.name, o3.field, a4);
|
|
1422
|
+
} };
|
|
1423
|
+
var q = { type: "field", parse: /* @__PURE__ */ __name(() => s, "parse") };
|
|
1424
|
+
var A = { type: "document", validate: l2("function") };
|
|
1425
|
+
var N = Object.freeze({ __proto__: null, $and: c2, $or: f2, $nor: d2, $not: u2, $elemMatch: $, $size: w2, $in: y2, $nin: x2, $all: v2, $mod: h2, $exists: m2, $gte: g, $gt: b, $lt: E, $lte: j2, $eq: O2, $ne: R, $regex: _2, $options: q, $where: A });
|
|
1426
|
+
var P = class extends j {
|
|
1427
|
+
static {
|
|
1428
|
+
__name(this, "P");
|
|
1429
|
+
}
|
|
1430
|
+
constructor(e3) {
|
|
1431
|
+
super(e3, { defaultOperatorName: "$eq", operatorToConditionName: /* @__PURE__ */ __name((e4) => e4.slice(1), "operatorToConditionName") });
|
|
1432
|
+
}
|
|
1433
|
+
parse(e3, t3) {
|
|
1434
|
+
return t3 && t3.field ? w(this.parseFieldOperators(t3.field, e3)) : super.parse(e3);
|
|
1435
|
+
}
|
|
1436
|
+
};
|
|
1437
|
+
var z = N;
|
|
1438
|
+
|
|
1439
|
+
// ../../../node_modules/@ucast/js/dist/es6m/index.mjs
|
|
1440
|
+
function n2(r2, t3, n3) {
|
|
1441
|
+
for (let e3 = 0, o3 = r2.length; e3 < o3; e3++) if (0 === n3(r2[e3], t3)) return true;
|
|
1442
|
+
return false;
|
|
1443
|
+
}
|
|
1444
|
+
__name(n2, "n");
|
|
1445
|
+
function e2(r2, t3) {
|
|
1446
|
+
return Array.isArray(r2) && Number.isNaN(Number(t3));
|
|
1447
|
+
}
|
|
1448
|
+
__name(e2, "e");
|
|
1449
|
+
function o2(r2, t3, n3) {
|
|
1450
|
+
if (!e2(r2, t3)) return n3(r2, t3);
|
|
1451
|
+
let o3 = [];
|
|
1452
|
+
for (let e3 = 0; e3 < r2.length; e3++) {
|
|
1453
|
+
const u5 = n3(r2[e3], t3);
|
|
1454
|
+
void 0 !== u5 && (o3 = o3.concat(u5));
|
|
1455
|
+
}
|
|
1456
|
+
return o3;
|
|
1457
|
+
}
|
|
1458
|
+
__name(o2, "o");
|
|
1459
|
+
function u3(r2) {
|
|
1460
|
+
return (t3, n3, e3) => {
|
|
1461
|
+
const o3 = e3.get(n3, t3.field);
|
|
1462
|
+
return Array.isArray(o3) ? o3.some((n4) => r2(t3, n4, e3)) : r2(t3, o3, e3);
|
|
1463
|
+
};
|
|
1464
|
+
}
|
|
1465
|
+
__name(u3, "u");
|
|
1466
|
+
var c3 = /* @__PURE__ */ __name((r2, t3) => r2[t3], "c");
|
|
1467
|
+
function i2(r2, t3, n3) {
|
|
1468
|
+
const e3 = t3.lastIndexOf(".");
|
|
1469
|
+
return -1 === e3 ? [r2, t3] : [n3(r2, t3.slice(0, e3)), t3.slice(e3 + 1)];
|
|
1470
|
+
}
|
|
1471
|
+
__name(i2, "i");
|
|
1472
|
+
function f3(t3, n3, e3 = c3) {
|
|
1473
|
+
if (n3 === n) return t3;
|
|
1474
|
+
if (!t3) throw new Error(`Unable to get field "${n3}" out of ${String(t3)}.`);
|
|
1475
|
+
return (function(r2, t4, n4) {
|
|
1476
|
+
if (-1 === t4.indexOf(".")) return o2(r2, t4, n4);
|
|
1477
|
+
const e4 = t4.split(".");
|
|
1478
|
+
let u5 = r2;
|
|
1479
|
+
for (let r3 = 0, t5 = e4.length; r3 < t5; r3++) if (u5 = o2(u5, e4[r3], n4), !u5 || "object" != typeof u5) return u5;
|
|
1480
|
+
return u5;
|
|
1481
|
+
})(t3, n3, e3);
|
|
1482
|
+
}
|
|
1483
|
+
__name(f3, "f");
|
|
1484
|
+
function a2(r2, t3) {
|
|
1485
|
+
return r2 === t3 ? 0 : r2 > t3 ? 1 : -1;
|
|
1486
|
+
}
|
|
1487
|
+
__name(a2, "a");
|
|
1488
|
+
function l3(r2, n3 = {}) {
|
|
1489
|
+
return m(r2, Object.assign({ get: f3, compare: a2 }, n3));
|
|
1490
|
+
}
|
|
1491
|
+
__name(l3, "l");
|
|
1492
|
+
var p3 = /* @__PURE__ */ __name((r2, t3, { interpret: n3 }) => r2.value.some((r3) => n3(r3, t3)), "p");
|
|
1493
|
+
var g2 = /* @__PURE__ */ __name((r2, t3, n3) => !p3(r2, t3, n3), "g");
|
|
1494
|
+
var m3 = /* @__PURE__ */ __name((r2, t3, { interpret: n3 }) => r2.value.every((r3) => n3(r3, t3)), "m");
|
|
1495
|
+
var y3 = /* @__PURE__ */ __name((r2, t3, { interpret: n3 }) => !n3(r2.value[0], t3), "y");
|
|
1496
|
+
var b2 = /* @__PURE__ */ __name((r2, t3, { compare: e3, get: o3 }) => {
|
|
1497
|
+
const u5 = o3(t3, r2.field);
|
|
1498
|
+
return Array.isArray(u5) && !Array.isArray(r2.value) ? n2(u5, r2.value, e3) : 0 === e3(u5, r2.value);
|
|
1499
|
+
}, "b");
|
|
1500
|
+
var A2 = /* @__PURE__ */ __name((r2, t3, n3) => !b2(r2, t3, n3), "A");
|
|
1501
|
+
var d3 = u3((r2, t3, n3) => {
|
|
1502
|
+
const e3 = n3.compare(t3, r2.value);
|
|
1503
|
+
return 0 === e3 || -1 === e3;
|
|
1504
|
+
});
|
|
1505
|
+
var h3 = u3((r2, t3, n3) => -1 === n3.compare(t3, r2.value));
|
|
1506
|
+
var j3 = u3((r2, t3, n3) => 1 === n3.compare(t3, r2.value));
|
|
1507
|
+
var w3 = u3((r2, t3, n3) => {
|
|
1508
|
+
const e3 = n3.compare(t3, r2.value);
|
|
1509
|
+
return 0 === e3 || 1 === e3;
|
|
1510
|
+
});
|
|
1511
|
+
var _3 = /* @__PURE__ */ __name((t3, n3, { get: o3 }) => {
|
|
1512
|
+
if (t3.field === n) return void 0 !== n3;
|
|
1513
|
+
const [u5, c4] = i2(n3, t3.field, o3), f4 = /* @__PURE__ */ __name((r2) => null == r2 ? Boolean(r2) === t3.value : r2.hasOwnProperty(c4) === t3.value, "f");
|
|
1514
|
+
return e2(u5, c4) ? u5.some(f4) : f4(u5);
|
|
1515
|
+
}, "_");
|
|
1516
|
+
var v3 = u3((r2, t3) => "number" == typeof t3 && t3 % r2.value[0] === r2.value[1]);
|
|
1517
|
+
var x3 = /* @__PURE__ */ __name((t3, n3, { get: o3 }) => {
|
|
1518
|
+
const [u5, c4] = i2(n3, t3.field, o3), f4 = /* @__PURE__ */ __name((r2) => {
|
|
1519
|
+
const n4 = o3(r2, c4);
|
|
1520
|
+
return Array.isArray(n4) && n4.length === t3.value;
|
|
1521
|
+
}, "f");
|
|
1522
|
+
return t3.field !== n && e2(u5, c4) ? u5.some(f4) : f4(u5);
|
|
1523
|
+
}, "x");
|
|
1524
|
+
var O3 = u3((r2, t3) => "string" == typeof t3 && r2.value.test(t3));
|
|
1525
|
+
var N2 = u3((r2, t3, { compare: e3 }) => n2(r2.value, t3, e3));
|
|
1526
|
+
var $2 = /* @__PURE__ */ __name((r2, t3, n3) => !N2(r2, t3, n3), "$");
|
|
1527
|
+
var q2 = /* @__PURE__ */ __name((r2, t3, { compare: e3, get: o3 }) => {
|
|
1528
|
+
const u5 = o3(t3, r2.field);
|
|
1529
|
+
return Array.isArray(u5) && r2.value.every((r3) => n2(u5, r3, e3));
|
|
1530
|
+
}, "q");
|
|
1531
|
+
var z2 = /* @__PURE__ */ __name((r2, t3, { interpret: n3, get: e3 }) => {
|
|
1532
|
+
const o3 = e3(t3, r2.field);
|
|
1533
|
+
return Array.isArray(o3) && o3.some((t4) => n3(r2.value, t4));
|
|
1534
|
+
}, "z");
|
|
1535
|
+
var B = /* @__PURE__ */ __name((r2, t3) => r2.value.call(t3), "B");
|
|
1536
|
+
var E2 = Object.freeze({ __proto__: null, or: p3, nor: g2, and: m3, not: y3, eq: b2, ne: A2, lte: d3, lt: h3, gt: j3, gte: w3, exists: _3, mod: v3, size: x3, regex: O3, within: N2, nin: $2, all: q2, elemMatch: z2, where: B });
|
|
1537
|
+
var M = Object.assign({}, E2, { in: N2 });
|
|
1538
|
+
var S = l3(M);
|
|
1539
|
+
|
|
1540
|
+
// ../../../node_modules/@ucast/mongo2js/dist/es6m/index.mjs
|
|
1541
|
+
function i3(o3) {
|
|
1542
|
+
return null === o3 || "object" != typeof o3 ? o3 : o3 instanceof Date ? o3.getTime() : o3 && "function" == typeof o3.toJSON ? o3.toJSON() : o3;
|
|
1543
|
+
}
|
|
1544
|
+
__name(i3, "i");
|
|
1545
|
+
var m4 = /* @__PURE__ */ __name((o3, t3) => a2(i3(o3), i3(t3)), "m");
|
|
1546
|
+
function p4(r2, c4, f4) {
|
|
1547
|
+
const s3 = new P(r2), i4 = l3(c4, Object.assign({ compare: m4 }, f4));
|
|
1548
|
+
if (f4 && f4.forPrimitives) {
|
|
1549
|
+
const o3 = { field: n }, e3 = s3.parse;
|
|
1550
|
+
s3.setParse((t3) => e3(t3, o3));
|
|
1551
|
+
}
|
|
1552
|
+
return v(s3.parse, i4);
|
|
1553
|
+
}
|
|
1554
|
+
__name(p4, "p");
|
|
1555
|
+
var u4 = p4(z, M);
|
|
1556
|
+
var a3 = p4(["$and", "$or"].reduce((o3, t3) => (o3[t3] = Object.assign({}, o3[t3], { type: "field" }), o3), Object.assign({}, z, { $nor: Object.assign({}, z.$nor, { type: "field", parse: O.compound }) })), M, { forPrimitives: true });
|
|
1557
|
+
|
|
1558
|
+
// ../../../node_modules/@casl/ability/dist/es6m/index.mjs
|
|
1559
|
+
var O4 = Object.hasOwn || ((t3, i4) => Object.prototype.hasOwnProperty.call(t3, i4));
|
|
1560
|
+
function C(t3) {
|
|
1561
|
+
return Array.isArray(t3) ? t3 : [t3];
|
|
1562
|
+
}
|
|
1563
|
+
__name(C, "C");
|
|
1564
|
+
var R2 = "__caslSubjectType__";
|
|
1565
|
+
var S2 = /* @__PURE__ */ __name((t3) => {
|
|
1566
|
+
const i4 = typeof t3;
|
|
1567
|
+
return i4 === "string" || i4 === "function";
|
|
1568
|
+
}, "S");
|
|
1569
|
+
var T = /* @__PURE__ */ __name((t3) => t3.modelName || t3.name, "T");
|
|
1570
|
+
function z3(t3) {
|
|
1571
|
+
return typeof t3 === "string" ? t3 : T(t3);
|
|
1572
|
+
}
|
|
1573
|
+
__name(z3, "z");
|
|
1574
|
+
function B2(t3) {
|
|
1575
|
+
if (O4(t3, R2)) return t3[R2];
|
|
1576
|
+
return T(t3.constructor);
|
|
1577
|
+
}
|
|
1578
|
+
__name(B2, "B");
|
|
1579
|
+
var q3 = { function: /* @__PURE__ */ __name((t3) => t3.constructor, "function"), string: B2 };
|
|
1580
|
+
function G(t3, i4, e3) {
|
|
1581
|
+
for (let s3 = e3; s3 < i4.length; s3++) t3.push(i4[s3]);
|
|
1582
|
+
}
|
|
1583
|
+
__name(G, "G");
|
|
1584
|
+
function H(t3, i4) {
|
|
1585
|
+
if (!t3 || !t3.length) return i4 || [];
|
|
1586
|
+
if (!i4 || !i4.length) return t3 || [];
|
|
1587
|
+
let e3 = 0;
|
|
1588
|
+
let s3 = 0;
|
|
1589
|
+
const n3 = [];
|
|
1590
|
+
while (e3 < t3.length && s3 < i4.length) if (t3[e3].priority < i4[s3].priority) {
|
|
1591
|
+
n3.push(t3[e3]);
|
|
1592
|
+
e3++;
|
|
1593
|
+
} else {
|
|
1594
|
+
n3.push(i4[s3]);
|
|
1595
|
+
s3++;
|
|
1596
|
+
}
|
|
1597
|
+
G(n3, t3, e3);
|
|
1598
|
+
G(n3, i4, s3);
|
|
1599
|
+
return n3;
|
|
1600
|
+
}
|
|
1601
|
+
__name(H, "H");
|
|
1602
|
+
function I(t3, i4, e3) {
|
|
1603
|
+
let s3 = t3.get(i4);
|
|
1604
|
+
if (!s3) {
|
|
1605
|
+
s3 = e3();
|
|
1606
|
+
t3.set(i4, s3);
|
|
1607
|
+
}
|
|
1608
|
+
return s3;
|
|
1609
|
+
}
|
|
1610
|
+
__name(I, "I");
|
|
1611
|
+
var J = /* @__PURE__ */ __name((t3) => t3, "J");
|
|
1612
|
+
function K(t3, i4) {
|
|
1613
|
+
if (Array.isArray(t3.fields) && !t3.fields.length) throw new Error("`rawRule.fields` cannot be an empty array. https://bit.ly/390miLa");
|
|
1614
|
+
if (t3.fields && !i4.fieldMatcher) throw new Error('You need to pass "fieldMatcher" option in order to restrict access by fields');
|
|
1615
|
+
if (t3.conditions && !i4.conditionsMatcher) throw new Error('You need to pass "conditionsMatcher" option in order to restrict access by conditions');
|
|
1616
|
+
}
|
|
1617
|
+
__name(K, "K");
|
|
1618
|
+
var N3 = class {
|
|
1619
|
+
static {
|
|
1620
|
+
__name(this, "N");
|
|
1621
|
+
}
|
|
1622
|
+
constructor(t3, i4, e3 = 0) {
|
|
1623
|
+
K(t3, i4);
|
|
1624
|
+
this.action = i4.resolveAction(t3.action);
|
|
1625
|
+
this.subject = t3.subject;
|
|
1626
|
+
this.inverted = !!t3.inverted;
|
|
1627
|
+
this.conditions = t3.conditions;
|
|
1628
|
+
this.reason = t3.reason;
|
|
1629
|
+
this.origin = t3;
|
|
1630
|
+
this.fields = t3.fields ? C(t3.fields) : void 0;
|
|
1631
|
+
this.priority = e3;
|
|
1632
|
+
this.t = i4;
|
|
1633
|
+
}
|
|
1634
|
+
i() {
|
|
1635
|
+
if (this.conditions && !this.o) this.o = this.t.conditionsMatcher(this.conditions);
|
|
1636
|
+
return this.o;
|
|
1637
|
+
}
|
|
1638
|
+
get ast() {
|
|
1639
|
+
const t3 = this.i();
|
|
1640
|
+
return t3 ? t3.ast : void 0;
|
|
1641
|
+
}
|
|
1642
|
+
matchesConditions(t3) {
|
|
1643
|
+
if (!this.conditions) return true;
|
|
1644
|
+
if (!t3 || S2(t3)) return !this.inverted;
|
|
1645
|
+
const i4 = this.i();
|
|
1646
|
+
return i4(t3);
|
|
1647
|
+
}
|
|
1648
|
+
matchesField(t3) {
|
|
1649
|
+
if (!this.fields) return true;
|
|
1650
|
+
if (!t3) return !this.inverted;
|
|
1651
|
+
if (!this.u) this.u = this.t.fieldMatcher(this.fields);
|
|
1652
|
+
return this.u(t3);
|
|
1653
|
+
}
|
|
1654
|
+
};
|
|
1655
|
+
function Q(t3, i4) {
|
|
1656
|
+
const e3 = { value: t3, prev: i4, next: null };
|
|
1657
|
+
if (i4) i4.next = e3;
|
|
1658
|
+
return e3;
|
|
1659
|
+
}
|
|
1660
|
+
__name(Q, "Q");
|
|
1661
|
+
function V(t3) {
|
|
1662
|
+
if (t3.next) t3.next.prev = t3.prev;
|
|
1663
|
+
if (t3.prev) t3.prev.next = t3.next;
|
|
1664
|
+
t3.next = t3.prev = null;
|
|
1665
|
+
}
|
|
1666
|
+
__name(V, "V");
|
|
1667
|
+
var W = /* @__PURE__ */ __name((t3) => ({ value: t3.value, prev: t3.prev, next: t3.next }), "W");
|
|
1668
|
+
var X = /* @__PURE__ */ __name(() => ({ rules: [], merged: false }), "X");
|
|
1669
|
+
var Z = /* @__PURE__ */ __name(() => /* @__PURE__ */ new Map(), "Z");
|
|
1670
|
+
var tt = class {
|
|
1671
|
+
static {
|
|
1672
|
+
__name(this, "tt");
|
|
1673
|
+
}
|
|
1674
|
+
constructor(t3 = [], i4 = {}) {
|
|
1675
|
+
this.h = false;
|
|
1676
|
+
this.l = /* @__PURE__ */ new Map();
|
|
1677
|
+
this.p = { conditionsMatcher: i4.conditionsMatcher, fieldMatcher: i4.fieldMatcher, resolveAction: i4.resolveAction || J };
|
|
1678
|
+
this.$ = i4.anyAction || "manage";
|
|
1679
|
+
this.A = i4.anySubjectType || "all";
|
|
1680
|
+
this.m = t3;
|
|
1681
|
+
this.M = !!i4.detectSubjectType;
|
|
1682
|
+
this.j = i4.detectSubjectType || B2;
|
|
1683
|
+
this.v(t3);
|
|
1684
|
+
}
|
|
1685
|
+
get rules() {
|
|
1686
|
+
return this.m;
|
|
1687
|
+
}
|
|
1688
|
+
detectSubjectType(t3) {
|
|
1689
|
+
if (S2(t3)) return t3;
|
|
1690
|
+
if (!t3) return this.A;
|
|
1691
|
+
return this.j(t3);
|
|
1692
|
+
}
|
|
1693
|
+
update(t3) {
|
|
1694
|
+
const i4 = { rules: t3, ability: this, target: this };
|
|
1695
|
+
this._("update", i4);
|
|
1696
|
+
this.m = t3;
|
|
1697
|
+
this.v(t3);
|
|
1698
|
+
this._("updated", i4);
|
|
1699
|
+
return this;
|
|
1700
|
+
}
|
|
1701
|
+
v(t3) {
|
|
1702
|
+
const i4 = /* @__PURE__ */ new Map();
|
|
1703
|
+
let e3;
|
|
1704
|
+
for (let s3 = t3.length - 1; s3 >= 0; s3--) {
|
|
1705
|
+
const n3 = t3.length - s3 - 1;
|
|
1706
|
+
const r2 = new N3(t3[s3], this.p, n3);
|
|
1707
|
+
const o3 = C(r2.action);
|
|
1708
|
+
const c4 = C(r2.subject || this.A);
|
|
1709
|
+
if (!this.h && r2.fields) this.h = true;
|
|
1710
|
+
for (let t4 = 0; t4 < c4.length; t4++) {
|
|
1711
|
+
const s4 = I(i4, c4[t4], Z);
|
|
1712
|
+
if (e3 === void 0) e3 = typeof c4[t4];
|
|
1713
|
+
if (typeof c4[t4] !== e3 && e3 !== "mixed") e3 = "mixed";
|
|
1714
|
+
for (let t5 = 0; t5 < o3.length; t5++) I(s4, o3[t5], X).rules.push(r2);
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
this.l = i4;
|
|
1718
|
+
if (e3 !== "mixed" && !this.M) {
|
|
1719
|
+
const t4 = q3[e3] || q3.string;
|
|
1720
|
+
this.j = t4;
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
possibleRulesFor(t3, i4 = this.A) {
|
|
1724
|
+
if (!S2(i4)) throw new Error('"possibleRulesFor" accepts only subject types (i.e., string or class) as the 2nd parameter');
|
|
1725
|
+
const e3 = I(this.l, i4, Z);
|
|
1726
|
+
const s3 = I(e3, t3, X);
|
|
1727
|
+
if (s3.merged) return s3.rules;
|
|
1728
|
+
const n3 = t3 !== this.$ && e3.has(this.$) ? e3.get(this.$).rules : void 0;
|
|
1729
|
+
let r2 = H(s3.rules, n3);
|
|
1730
|
+
if (i4 !== this.A) r2 = H(r2, this.possibleRulesFor(t3, this.A));
|
|
1731
|
+
s3.rules = r2;
|
|
1732
|
+
s3.merged = true;
|
|
1733
|
+
return r2;
|
|
1734
|
+
}
|
|
1735
|
+
rulesFor(t3, i4, e3) {
|
|
1736
|
+
const s3 = this.possibleRulesFor(t3, i4);
|
|
1737
|
+
if (e3 && typeof e3 !== "string") throw new Error("The 3rd, `field` parameter is expected to be a string. See https://stalniy.github.io/casl/en/api/casl-ability#can-of-pure-ability for details");
|
|
1738
|
+
if (!this.h) return s3;
|
|
1739
|
+
return s3.filter((t4) => t4.matchesField(e3));
|
|
1740
|
+
}
|
|
1741
|
+
actionsFor(t3) {
|
|
1742
|
+
if (!S2(t3)) throw new Error('"actionsFor" accepts only subject types (i.e., string or class) as a parameter');
|
|
1743
|
+
const i4 = /* @__PURE__ */ new Set();
|
|
1744
|
+
const e3 = this.l.get(t3);
|
|
1745
|
+
if (e3) Array.from(e3.keys()).forEach((t4) => i4.add(t4));
|
|
1746
|
+
const s3 = t3 !== this.A ? this.l.get(this.A) : void 0;
|
|
1747
|
+
if (s3) Array.from(s3.keys()).forEach((t4) => i4.add(t4));
|
|
1748
|
+
return Array.from(i4);
|
|
1749
|
+
}
|
|
1750
|
+
on(t3, i4) {
|
|
1751
|
+
this.F = this.F || /* @__PURE__ */ new Map();
|
|
1752
|
+
const e3 = this.F;
|
|
1753
|
+
const s3 = e3.get(t3) || null;
|
|
1754
|
+
const n3 = Q(i4, s3);
|
|
1755
|
+
e3.set(t3, n3);
|
|
1756
|
+
return () => {
|
|
1757
|
+
const i5 = e3.get(t3);
|
|
1758
|
+
if (!n3.next && !n3.prev && i5 === n3) e3.delete(t3);
|
|
1759
|
+
else if (n3 === i5) e3.set(t3, n3.prev);
|
|
1760
|
+
V(n3);
|
|
1761
|
+
};
|
|
1762
|
+
}
|
|
1763
|
+
_(t3, i4) {
|
|
1764
|
+
if (!this.F) return;
|
|
1765
|
+
let e3 = this.F.get(t3) || null;
|
|
1766
|
+
while (e3 !== null) {
|
|
1767
|
+
const t4 = e3.prev ? W(e3.prev) : null;
|
|
1768
|
+
e3.value(i4);
|
|
1769
|
+
e3 = t4;
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
};
|
|
1773
|
+
var PureAbility = class extends tt {
|
|
1774
|
+
static {
|
|
1775
|
+
__name(this, "PureAbility");
|
|
1776
|
+
}
|
|
1777
|
+
can(t3, i4, e3) {
|
|
1778
|
+
const s3 = this.relevantRuleFor(t3, i4, e3);
|
|
1779
|
+
return !!s3 && !s3.inverted;
|
|
1780
|
+
}
|
|
1781
|
+
relevantRuleFor(t3, i4, e3) {
|
|
1782
|
+
const s3 = this.detectSubjectType(i4);
|
|
1783
|
+
const n3 = this.rulesFor(t3, s3, e3);
|
|
1784
|
+
for (let t4 = 0, e4 = n3.length; t4 < e4; t4++) if (n3[t4].matchesConditions(i4)) return n3[t4];
|
|
1785
|
+
return null;
|
|
1786
|
+
}
|
|
1787
|
+
cannot(t3, i4, e3) {
|
|
1788
|
+
return !this.can(t3, i4, e3);
|
|
1789
|
+
}
|
|
1790
|
+
};
|
|
1791
|
+
var it = { $eq: O2, $ne: R, $lt: E, $lte: j2, $gt: b, $gte: g, $in: y2, $nin: x2, $all: v2, $size: w2, $regex: _2, $options: q, $elemMatch: $, $exists: m2 };
|
|
1792
|
+
var et = { eq: b2, ne: A2, lt: h3, lte: d3, gt: j3, gte: w3, in: N2, nin: $2, all: q2, size: x3, regex: O3, elemMatch: z2, exists: _3, and: m3 };
|
|
1793
|
+
var nt = p4(it, et);
|
|
1794
|
+
function isAbilityClass(t3) {
|
|
1795
|
+
return t3.prototype !== void 0 && typeof t3.prototype.possibleRulesFor === "function";
|
|
1796
|
+
}
|
|
1797
|
+
__name(isAbilityClass, "isAbilityClass");
|
|
1798
|
+
var dt = class {
|
|
1799
|
+
static {
|
|
1800
|
+
__name(this, "dt");
|
|
1801
|
+
}
|
|
1802
|
+
constructor(t3) {
|
|
1803
|
+
this.O = t3;
|
|
1804
|
+
}
|
|
1805
|
+
because(t3) {
|
|
1806
|
+
this.O.reason = t3;
|
|
1807
|
+
return this;
|
|
1808
|
+
}
|
|
1809
|
+
};
|
|
1810
|
+
var AbilityBuilder = class {
|
|
1811
|
+
static {
|
|
1812
|
+
__name(this, "AbilityBuilder");
|
|
1813
|
+
}
|
|
1814
|
+
constructor(t3) {
|
|
1815
|
+
this.rules = [];
|
|
1816
|
+
this.C = t3;
|
|
1817
|
+
this.can = (t4, i4, e3, s3) => this.R(t4, i4, e3, s3, false);
|
|
1818
|
+
this.cannot = (t4, i4, e3, s3) => this.R(t4, i4, e3, s3, true);
|
|
1819
|
+
this.build = (t4) => isAbilityClass(this.C) ? new this.C(this.rules, t4) : this.C(this.rules, t4);
|
|
1820
|
+
}
|
|
1821
|
+
R(t3, i4, e3, s3, n3) {
|
|
1822
|
+
const r2 = { action: t3 };
|
|
1823
|
+
if (n3) r2.inverted = n3;
|
|
1824
|
+
if (i4) {
|
|
1825
|
+
r2.subject = i4;
|
|
1826
|
+
if (Array.isArray(e3) || typeof e3 === "string") r2.fields = e3;
|
|
1827
|
+
else if (typeof e3 !== "undefined") r2.conditions = e3;
|
|
1828
|
+
if (typeof s3 !== "undefined") r2.conditions = s3;
|
|
1829
|
+
}
|
|
1830
|
+
this.rules.push(r2);
|
|
1831
|
+
return new dt(r2);
|
|
1832
|
+
}
|
|
1833
|
+
};
|
|
1834
|
+
var yt = /* @__PURE__ */ __name((t3) => `Cannot execute "${t3.action}" on "${t3.subjectType}"`, "yt");
|
|
1835
|
+
var pt = /* @__PURE__ */ __name(function t2(i4) {
|
|
1836
|
+
this.message = i4;
|
|
1837
|
+
}, "t");
|
|
1838
|
+
pt.prototype = Object.create(Error.prototype);
|
|
1839
|
+
var ForbiddenError = class extends pt {
|
|
1840
|
+
static {
|
|
1841
|
+
__name(this, "ForbiddenError");
|
|
1842
|
+
}
|
|
1843
|
+
static setDefaultMessage(t3) {
|
|
1844
|
+
this.P = typeof t3 === "string" ? () => t3 : t3;
|
|
1845
|
+
}
|
|
1846
|
+
static from(t3) {
|
|
1847
|
+
return new this(t3);
|
|
1848
|
+
}
|
|
1849
|
+
constructor(t3) {
|
|
1850
|
+
super("");
|
|
1851
|
+
this.ability = t3;
|
|
1852
|
+
if (typeof Error.captureStackTrace === "function") {
|
|
1853
|
+
this.name = "ForbiddenError";
|
|
1854
|
+
Error.captureStackTrace(this, this.constructor);
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
setMessage(t3) {
|
|
1858
|
+
this.message = t3;
|
|
1859
|
+
return this;
|
|
1860
|
+
}
|
|
1861
|
+
throwUnlessCan(t3, i4, e3) {
|
|
1862
|
+
const s3 = this.unlessCan(t3, i4, e3);
|
|
1863
|
+
if (s3) throw s3;
|
|
1864
|
+
}
|
|
1865
|
+
unlessCan(t3, i4, e3) {
|
|
1866
|
+
const s3 = this.ability.relevantRuleFor(t3, i4, e3);
|
|
1867
|
+
if (s3 && !s3.inverted) return;
|
|
1868
|
+
this.action = t3;
|
|
1869
|
+
this.subject = i4;
|
|
1870
|
+
this.subjectType = z3(this.ability.detectSubjectType(i4));
|
|
1871
|
+
this.field = e3;
|
|
1872
|
+
const n3 = s3 ? s3.reason : "";
|
|
1873
|
+
this.message = this.message || n3 || this.constructor.P(this);
|
|
1874
|
+
return this;
|
|
1875
|
+
}
|
|
1876
|
+
};
|
|
1877
|
+
ForbiddenError.P = yt;
|
|
1878
|
+
var bt = Object.freeze({ __proto__: null });
|
|
1879
|
+
|
|
1880
|
+
// ../nestjs-authzpaas/dist/index.js
|
|
1881
|
+
var import_common17 = require("@nestjs/common");
|
|
1882
|
+
var import_nestjs_common5 = require("@lark-apaas/nestjs-common");
|
|
1883
|
+
var import_nestjs_common6 = require("@lark-apaas/nestjs-common");
|
|
1884
|
+
var import_common18 = require("@nestjs/common");
|
|
1885
|
+
var import_core9 = require("@nestjs/core");
|
|
1886
|
+
var import_nestjs_common7 = require("@lark-apaas/nestjs-common");
|
|
1887
|
+
var import_common19 = require("@nestjs/common");
|
|
1888
|
+
var __defProp2 = Object.defineProperty;
|
|
1889
|
+
var __name2 = /* @__PURE__ */ __name((target, value) => __defProp2(target, "name", {
|
|
1890
|
+
value,
|
|
1891
|
+
configurable: true
|
|
1892
|
+
}), "__name");
|
|
1893
|
+
var __defProp22 = Object.defineProperty;
|
|
1894
|
+
var __name22 = /* @__PURE__ */ __name2((target, value) => __defProp22(target, "name", {
|
|
1895
|
+
value,
|
|
1896
|
+
configurable: true
|
|
1897
|
+
}), "__name");
|
|
1898
|
+
var AUTHNPAAS_MODULE_OPTIONS = /* @__PURE__ */ Symbol("AUTHNPAAS_MODULE_OPTIONS");
|
|
1899
|
+
var NEED_LOGIN_KEY = "authnpaas:needLogin";
|
|
1900
|
+
function _ts_decorate10(decorators, target, key, desc) {
|
|
1901
|
+
var c4 = arguments.length, r2 = c4 < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d4;
|
|
1902
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r2 = Reflect.decorate(decorators, target, key, desc);
|
|
1903
|
+
else for (var i4 = decorators.length - 1; i4 >= 0; i4--) if (d4 = decorators[i4]) r2 = (c4 < 3 ? d4(r2) : c4 > 3 ? d4(target, key, r2) : d4(target, key)) || r2;
|
|
1904
|
+
return c4 > 3 && r2 && Object.defineProperty(target, key, r2), r2;
|
|
1905
|
+
}
|
|
1906
|
+
__name(_ts_decorate10, "_ts_decorate");
|
|
1907
|
+
__name2(_ts_decorate10, "_ts_decorate");
|
|
1908
|
+
__name22(_ts_decorate10, "_ts_decorate");
|
|
1909
|
+
function _ts_metadata7(k, v4) {
|
|
1910
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v4);
|
|
1911
|
+
}
|
|
1912
|
+
__name(_ts_metadata7, "_ts_metadata");
|
|
1913
|
+
__name2(_ts_metadata7, "_ts_metadata");
|
|
1914
|
+
__name22(_ts_metadata7, "_ts_metadata");
|
|
1915
|
+
var AuthNPaasGuard = class {
|
|
1916
|
+
static {
|
|
1917
|
+
__name(this, "AuthNPaasGuard");
|
|
1918
|
+
}
|
|
1919
|
+
static {
|
|
1920
|
+
__name2(this, "AuthNPaasGuard");
|
|
1921
|
+
}
|
|
1922
|
+
static {
|
|
1923
|
+
__name22(this, "AuthNPaasGuard");
|
|
1924
|
+
}
|
|
1925
|
+
reflector;
|
|
1926
|
+
constructor(reflector) {
|
|
1927
|
+
this.reflector = reflector;
|
|
1928
|
+
}
|
|
1929
|
+
async canActivate(context) {
|
|
1930
|
+
const http = context.switchToHttp();
|
|
1931
|
+
const request = http.getRequest();
|
|
1932
|
+
const response = http.getResponse();
|
|
1933
|
+
const { userId, loginUrl } = request.userContext || {};
|
|
1934
|
+
const needLoginMeta = this.reflector.getAllAndOverride(NEED_LOGIN_KEY, [
|
|
1935
|
+
context.getHandler(),
|
|
1936
|
+
context.getClass()
|
|
1937
|
+
]);
|
|
1938
|
+
if (needLoginMeta && !userId && loginUrl) {
|
|
1939
|
+
response.setHeader("x-login-url", loginUrl);
|
|
1940
|
+
throw new import_common13.UnauthorizedException("\u672A\u767B\u5F55");
|
|
1941
|
+
}
|
|
1942
|
+
return true;
|
|
1943
|
+
}
|
|
1944
|
+
};
|
|
1945
|
+
AuthNPaasGuard = _ts_decorate10([
|
|
1946
|
+
(0, import_common13.Injectable)(),
|
|
1947
|
+
_ts_metadata7("design:type", Function),
|
|
1948
|
+
_ts_metadata7("design:paramtypes", [
|
|
1949
|
+
typeof import_core8.Reflector === "undefined" ? Object : import_core8.Reflector
|
|
1950
|
+
])
|
|
1951
|
+
], AuthNPaasGuard);
|
|
1952
|
+
function _ts_decorate22(decorators, target, key, desc) {
|
|
1953
|
+
var c4 = arguments.length, r2 = c4 < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d4;
|
|
1954
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r2 = Reflect.decorate(decorators, target, key, desc);
|
|
1955
|
+
else for (var i4 = decorators.length - 1; i4 >= 0; i4--) if (d4 = decorators[i4]) r2 = (c4 < 3 ? d4(r2) : c4 > 3 ? d4(target, key, r2) : d4(target, key)) || r2;
|
|
1956
|
+
return c4 > 3 && r2 && Object.defineProperty(target, key, r2), r2;
|
|
1957
|
+
}
|
|
1958
|
+
__name(_ts_decorate22, "_ts_decorate2");
|
|
1959
|
+
__name2(_ts_decorate22, "_ts_decorate2");
|
|
1960
|
+
__name22(_ts_decorate22, "_ts_decorate");
|
|
1961
|
+
var AuthNPaasModule = class _AuthNPaasModule {
|
|
1962
|
+
static {
|
|
1963
|
+
__name(this, "_AuthNPaasModule");
|
|
1964
|
+
}
|
|
1965
|
+
static {
|
|
1966
|
+
__name2(this, "_AuthNPaasModule");
|
|
1967
|
+
}
|
|
1968
|
+
static {
|
|
1969
|
+
__name22(this, "AuthNPaasModule");
|
|
1970
|
+
}
|
|
1971
|
+
static forRoot(options) {
|
|
1972
|
+
return {
|
|
1973
|
+
module: _AuthNPaasModule,
|
|
1974
|
+
global: true,
|
|
1975
|
+
controllers: [],
|
|
1976
|
+
providers: [
|
|
1977
|
+
// 配置提供者
|
|
1978
|
+
{
|
|
1979
|
+
provide: AUTHNPAAS_MODULE_OPTIONS,
|
|
1980
|
+
useValue: {
|
|
1981
|
+
...options || {}
|
|
1982
|
+
}
|
|
1983
|
+
},
|
|
1984
|
+
// 核心服务
|
|
1985
|
+
import_core7.Reflector,
|
|
1986
|
+
// 服务提供者
|
|
1987
|
+
AuthNPaasGuard,
|
|
1988
|
+
// 守卫提供者
|
|
1989
|
+
{
|
|
1990
|
+
provide: import_core7.APP_GUARD,
|
|
1991
|
+
useClass: AuthNPaasGuard
|
|
1992
|
+
}
|
|
1993
|
+
],
|
|
1994
|
+
exports: []
|
|
1995
|
+
};
|
|
1996
|
+
}
|
|
1997
|
+
};
|
|
1998
|
+
AuthNPaasModule = _ts_decorate22([
|
|
1999
|
+
(0, import_common12.Module)({})
|
|
2000
|
+
], AuthNPaasModule);
|
|
2001
|
+
var IS_PUBLIC_KEY = "isPublic";
|
|
2002
|
+
var Public = /* @__PURE__ */ __name22(() => (0, import_common14.SetMetadata)(IS_PUBLIC_KEY, true), "Public");
|
|
2003
|
+
var PERMISSION_API_CONFIG_TOKEN = /* @__PURE__ */ Symbol("PERMISSION_API_CONFIG");
|
|
2004
|
+
var AUTHZPAAS_MODULE_OPTIONS = /* @__PURE__ */ Symbol("AUTHZPAAS_MODULE_OPTIONS");
|
|
2005
|
+
var ROLES_KEY = "authzpaas:roles";
|
|
2006
|
+
function _ts_decorate32(decorators, target, key, desc) {
|
|
2007
|
+
var c4 = arguments.length, r2 = c4 < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d4;
|
|
2008
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r2 = Reflect.decorate(decorators, target, key, desc);
|
|
2009
|
+
else for (var i4 = decorators.length - 1; i4 >= 0; i4--) if (d4 = decorators[i4]) r2 = (c4 < 3 ? d4(r2) : c4 > 3 ? d4(target, key, r2) : d4(target, key)) || r2;
|
|
2010
|
+
return c4 > 3 && r2 && Object.defineProperty(target, key, r2), r2;
|
|
2011
|
+
}
|
|
2012
|
+
__name(_ts_decorate32, "_ts_decorate3");
|
|
2013
|
+
__name2(_ts_decorate32, "_ts_decorate");
|
|
2014
|
+
var ROLE_SUBJECT = "@role";
|
|
2015
|
+
var AbilityFactory = class {
|
|
2016
|
+
static {
|
|
2017
|
+
__name(this, "AbilityFactory");
|
|
2018
|
+
}
|
|
2019
|
+
static {
|
|
2020
|
+
__name2(this, "AbilityFactory");
|
|
2021
|
+
}
|
|
2022
|
+
/**
|
|
2023
|
+
* 为用户创建 Ability
|
|
2024
|
+
*/
|
|
2025
|
+
createForUser(permissionData) {
|
|
2026
|
+
const { can, build } = new AbilityBuilder(PureAbility);
|
|
2027
|
+
for (const role of permissionData.roles) {
|
|
2028
|
+
can(role, ROLE_SUBJECT);
|
|
2029
|
+
}
|
|
2030
|
+
return build();
|
|
2031
|
+
}
|
|
2032
|
+
};
|
|
2033
|
+
AbilityFactory = _ts_decorate32([
|
|
2034
|
+
(0, import_common16.Injectable)()
|
|
2035
|
+
], AbilityFactory);
|
|
2036
|
+
var PermissionDeniedType = /* @__PURE__ */ (function(PermissionDeniedType2) {
|
|
2037
|
+
PermissionDeniedType2["UNAUTHENTICATED"] = "UNAUTHENTICATED";
|
|
2038
|
+
PermissionDeniedType2["ROLE_REQUIRED"] = "ROLE_REQUIRED";
|
|
2039
|
+
PermissionDeniedType2["PERMISSION_REQUIRED"] = "PERMISSION_REQUIRED";
|
|
2040
|
+
PermissionDeniedType2["PERMISSION_CONFIG_QUERY_FAILED"] = "PERMISSION_CONFIG_QUERY_FAILED";
|
|
2041
|
+
return PermissionDeniedType2;
|
|
2042
|
+
})({});
|
|
2043
|
+
var PermissionDeniedException = class _PermissionDeniedException extends import_common17.HttpException {
|
|
2044
|
+
static {
|
|
2045
|
+
__name(this, "_PermissionDeniedException");
|
|
2046
|
+
}
|
|
2047
|
+
static {
|
|
2048
|
+
__name2(this, "PermissionDeniedException");
|
|
2049
|
+
}
|
|
2050
|
+
type;
|
|
2051
|
+
details;
|
|
2052
|
+
constructor(details, httpStatusCode = 403) {
|
|
2053
|
+
super({
|
|
2054
|
+
statusCode: httpStatusCode,
|
|
2055
|
+
cause: details.cause,
|
|
2056
|
+
type: details.type,
|
|
2057
|
+
message: details.message,
|
|
2058
|
+
...details.requiredRoles && {
|
|
2059
|
+
requiredRoles: details.requiredRoles
|
|
2060
|
+
},
|
|
2061
|
+
...details.requiredPermissions && {
|
|
2062
|
+
requiredPermissions: details.requiredPermissions
|
|
2063
|
+
},
|
|
2064
|
+
...details.environmentRequirement && {
|
|
2065
|
+
environmentRequirement: details.environmentRequirement
|
|
2066
|
+
},
|
|
2067
|
+
...details.metadata && {
|
|
2068
|
+
metadata: details.metadata
|
|
2069
|
+
}
|
|
2070
|
+
}, httpStatusCode);
|
|
2071
|
+
this.type = details.type;
|
|
2072
|
+
this.details = details;
|
|
2073
|
+
this.name = "PermissionDeniedException";
|
|
2074
|
+
}
|
|
2075
|
+
/**
|
|
2076
|
+
* 创建用户未认证异常
|
|
2077
|
+
*/
|
|
2078
|
+
static unauthenticated(message = "\u7528\u6237\u672A\u8BA4\u8BC1") {
|
|
2079
|
+
return new _PermissionDeniedException({
|
|
2080
|
+
type: "UNAUTHENTICATED",
|
|
2081
|
+
message
|
|
2082
|
+
});
|
|
2083
|
+
}
|
|
2084
|
+
/**
|
|
2085
|
+
* 创建角色不足异常
|
|
2086
|
+
*/
|
|
2087
|
+
static roleRequired(requiredRoles) {
|
|
2088
|
+
const message = `\u9700\u8981\u4EE5\u4E0B\u4EFB\u4E00\u89D2\u8272: ${requiredRoles.join(", ")}`;
|
|
2089
|
+
return new _PermissionDeniedException({
|
|
2090
|
+
type: "ROLE_REQUIRED",
|
|
2091
|
+
message,
|
|
2092
|
+
requiredRoles
|
|
2093
|
+
});
|
|
2094
|
+
}
|
|
2095
|
+
/**
|
|
2096
|
+
* 创建权限不足异常
|
|
2097
|
+
*/
|
|
2098
|
+
static permissionRequired(requiredPermissions, or = false, customMessage) {
|
|
2099
|
+
let message;
|
|
2100
|
+
if (customMessage) {
|
|
2101
|
+
message = customMessage;
|
|
2102
|
+
} else if (requiredPermissions.length === 1) {
|
|
2103
|
+
const perm = requiredPermissions[0];
|
|
2104
|
+
message = or ? `\u7F3A\u5C11\u6743\u9650: \u9700\u8981\u5BF9 ${perm.subject} \u6267\u884C\u4EE5\u4E0B\u4EFB\u4E00\u64CD\u4F5C [${perm.actions.join(", ")}]` : `\u7F3A\u5C11\u6743\u9650: \u9700\u8981\u5BF9 ${perm.subject} \u6267\u884C\u6240\u6709\u64CD\u4F5C [${perm.actions.join(", ")}]`;
|
|
2105
|
+
} else {
|
|
2106
|
+
message = or ? `\u7F3A\u5C11\u6743\u9650: \u9700\u8981\u6EE1\u8DB3\u4EE5\u4E0B\u4EFB\u4E00\u6743\u9650\u8981\u6C42: ${requiredPermissions.map(({ actions, subject }) => `\u5BF9 ${subject} \u6267\u884C\u4EE5\u4E0B\u4EFB\u4E00\u64CD\u4F5C [${actions.join(", ")}]`).join(", ")}` : `\u7F3A\u5C11\u6743\u9650: \u9700\u8981\u6EE1\u8DB3\u4EE5\u4E0B\u6240\u6709\u6743\u9650\u8981\u6C42: ${requiredPermissions.map(({ actions, subject }) => `\u5BF9 ${subject} \u6267\u884C\u6240\u6709\u64CD\u4F5C [${actions.join(", ")}]`).join(", ")}`;
|
|
2107
|
+
}
|
|
2108
|
+
return new _PermissionDeniedException({
|
|
2109
|
+
type: "PERMISSION_REQUIRED",
|
|
2110
|
+
message,
|
|
2111
|
+
requiredPermissions,
|
|
2112
|
+
metadata: {
|
|
2113
|
+
or
|
|
2114
|
+
}
|
|
2115
|
+
});
|
|
2116
|
+
}
|
|
2117
|
+
};
|
|
2118
|
+
function _ts_decorate42(decorators, target, key, desc) {
|
|
2119
|
+
var c4 = arguments.length, r2 = c4 < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d4;
|
|
2120
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r2 = Reflect.decorate(decorators, target, key, desc);
|
|
2121
|
+
else for (var i4 = decorators.length - 1; i4 >= 0; i4--) if (d4 = decorators[i4]) r2 = (c4 < 3 ? d4(r2) : c4 > 3 ? d4(target, key, r2) : d4(target, key)) || r2;
|
|
2122
|
+
return c4 > 3 && r2 && Object.defineProperty(target, key, r2), r2;
|
|
2123
|
+
}
|
|
2124
|
+
__name(_ts_decorate42, "_ts_decorate4");
|
|
2125
|
+
__name2(_ts_decorate42, "_ts_decorate");
|
|
2126
|
+
function _ts_metadata22(k, v4) {
|
|
2127
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v4);
|
|
2128
|
+
}
|
|
2129
|
+
__name(_ts_metadata22, "_ts_metadata2");
|
|
2130
|
+
__name2(_ts_metadata22, "_ts_metadata");
|
|
2131
|
+
function _ts_param3(paramIndex, decorator) {
|
|
2132
|
+
return function(target, key) {
|
|
2133
|
+
decorator(target, key, paramIndex);
|
|
2134
|
+
};
|
|
2135
|
+
}
|
|
2136
|
+
__name(_ts_param3, "_ts_param");
|
|
2137
|
+
__name2(_ts_param3, "_ts_param");
|
|
2138
|
+
var PermissionService = class {
|
|
2139
|
+
static {
|
|
2140
|
+
__name(this, "PermissionService");
|
|
2141
|
+
}
|
|
2142
|
+
static {
|
|
2143
|
+
__name2(this, "PermissionService");
|
|
2144
|
+
}
|
|
2145
|
+
apiConfig;
|
|
2146
|
+
abilityFactory;
|
|
2147
|
+
client;
|
|
2148
|
+
requestContextService;
|
|
2149
|
+
constructor(apiConfig, abilityFactory, client, requestContextService) {
|
|
2150
|
+
this.apiConfig = apiConfig;
|
|
2151
|
+
this.abilityFactory = abilityFactory;
|
|
2152
|
+
this.client = client;
|
|
2153
|
+
this.requestContextService = requestContextService;
|
|
2154
|
+
}
|
|
2155
|
+
/**
|
|
2156
|
+
* 获取用户权限数据
|
|
2157
|
+
*/
|
|
2158
|
+
async getUserPermissions({ laneId }) {
|
|
2159
|
+
const permissionData = await this.fetchFromApi({
|
|
2160
|
+
laneId
|
|
2161
|
+
});
|
|
2162
|
+
const dataWithTimestamp = {
|
|
2163
|
+
...permissionData,
|
|
2164
|
+
fetchedAt: /* @__PURE__ */ new Date()
|
|
2165
|
+
};
|
|
2166
|
+
return dataWithTimestamp;
|
|
2167
|
+
}
|
|
2168
|
+
/**
|
|
2169
|
+
* 从 API 获取权限数据
|
|
2170
|
+
* 内置实现,用户无需配置
|
|
2171
|
+
*/
|
|
2172
|
+
async fetchFromApi({ laneId }) {
|
|
2173
|
+
const { timeout = 5e3 } = this.apiConfig || {};
|
|
2174
|
+
const { appId = "", userId = "" } = this.requestContextService.getContext() || {};
|
|
2175
|
+
if (!appId) {
|
|
2176
|
+
throw new PermissionDeniedException({
|
|
2177
|
+
type: PermissionDeniedType.PERMISSION_CONFIG_QUERY_FAILED,
|
|
2178
|
+
message: "appId is empty"
|
|
2179
|
+
}, import_common11.HttpStatus.BAD_REQUEST);
|
|
2180
|
+
}
|
|
2181
|
+
const url = `/app/${appId}/inner/api/v1/permissions/roles`;
|
|
2182
|
+
const requestHeaders = {
|
|
2183
|
+
"Content-Type": "application/json",
|
|
2184
|
+
// 透传 laneId 到权限服务
|
|
2185
|
+
...laneId ? {
|
|
2186
|
+
"x-tt-env": laneId || ""
|
|
2187
|
+
} : {}
|
|
2188
|
+
};
|
|
2189
|
+
const controller = new AbortController();
|
|
2190
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
2191
|
+
try {
|
|
2192
|
+
const response = await this.client.post(url, {
|
|
2193
|
+
userID: userId || ""
|
|
2194
|
+
}, {
|
|
2195
|
+
credentials: "include",
|
|
2196
|
+
headers: requestHeaders,
|
|
2197
|
+
signal: controller.signal
|
|
2198
|
+
});
|
|
2199
|
+
clearTimeout(timeoutId);
|
|
2200
|
+
if (!response.ok) {
|
|
2201
|
+
const error = new Error(`Permission API returned ${response.status}: ${response.statusText}`);
|
|
2202
|
+
throw new PermissionDeniedException({
|
|
2203
|
+
cause: error,
|
|
2204
|
+
type: PermissionDeniedType.PERMISSION_CONFIG_QUERY_FAILED,
|
|
2205
|
+
message: error.message
|
|
2206
|
+
}, import_common11.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
2207
|
+
}
|
|
2208
|
+
let data;
|
|
2209
|
+
let responseText = "";
|
|
2210
|
+
try {
|
|
2211
|
+
responseText = await response.text();
|
|
2212
|
+
data = JSON.parse(responseText);
|
|
2213
|
+
} catch (jsonError) {
|
|
2214
|
+
const error = new Error(`Permission API returned invalid JSON: ${responseText}`);
|
|
2215
|
+
throw new PermissionDeniedException({
|
|
2216
|
+
cause: error,
|
|
2217
|
+
type: PermissionDeniedType.PERMISSION_CONFIG_QUERY_FAILED,
|
|
2218
|
+
message: error.message
|
|
2219
|
+
}, import_common11.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
2220
|
+
}
|
|
2221
|
+
return {
|
|
2222
|
+
userId,
|
|
2223
|
+
roles: data.data?.roleList || [],
|
|
2224
|
+
// TODO: 基于权限点位设置能力
|
|
2225
|
+
// permissions: data.permissions || [],
|
|
2226
|
+
fetchedAt: /* @__PURE__ */ new Date()
|
|
2227
|
+
};
|
|
2228
|
+
} catch (error) {
|
|
2229
|
+
clearTimeout(timeoutId);
|
|
2230
|
+
let err = error;
|
|
2231
|
+
if (error.name === "AbortError") {
|
|
2232
|
+
err = new Error(`Permission API request timeout after ${timeout}ms`);
|
|
2233
|
+
}
|
|
2234
|
+
throw new PermissionDeniedException({
|
|
2235
|
+
cause: err,
|
|
2236
|
+
type: PermissionDeniedType.PERMISSION_CONFIG_QUERY_FAILED,
|
|
2237
|
+
message: err.message
|
|
2238
|
+
}, import_common11.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
// /**
|
|
2242
|
+
// * 获取用户的 Ability 实例(带缓存)
|
|
2243
|
+
// * @param userId 用户ID
|
|
2244
|
+
// * @returns CASL Ability 实例
|
|
2245
|
+
// */
|
|
2246
|
+
// private async getUserAbility(
|
|
2247
|
+
// userId?: string,
|
|
2248
|
+
// mockRoles?: string[]
|
|
2249
|
+
// ): Promise<AppAbility> {
|
|
2250
|
+
// // 计算缓存 key
|
|
2251
|
+
// const key = this.buildCacheKey(userId, mockRoles);
|
|
2252
|
+
// // 尝试从缓存获取
|
|
2253
|
+
// const cached = this.cache.get(key);
|
|
2254
|
+
// if (cached) {
|
|
2255
|
+
// return cached.ability;
|
|
2256
|
+
// }
|
|
2257
|
+
// // 缓存未命中,调用 getUserPermissions 会创建并缓存
|
|
2258
|
+
// await this.getUserPermissions(userId, mockRoles);
|
|
2259
|
+
// // 再次从缓存获取(此时一定存在)
|
|
2260
|
+
// const newCached = this.cache.get(key);
|
|
2261
|
+
// return newCached!.ability;
|
|
2262
|
+
// }
|
|
2263
|
+
/**
|
|
2264
|
+
* 检查角色要求
|
|
2265
|
+
* 使用 CASL Ability 统一鉴权方式
|
|
2266
|
+
* @param requirement 角色要求
|
|
2267
|
+
* @param laneId 环境ID
|
|
2268
|
+
* @returns 用户权限检查结果,包含结果和详细信息
|
|
2269
|
+
* @throws PermissionDeniedException 当权限数据获取失败时
|
|
2270
|
+
*/
|
|
2271
|
+
async checkRoles(requirement, laneId, userContext) {
|
|
2272
|
+
const { userId = "" } = this.requestContextService.getContext() || {};
|
|
2273
|
+
let permissionData = null;
|
|
2274
|
+
if (!userContext || !("roles" in userContext)) {
|
|
2275
|
+
permissionData = await this.getUserPermissions({
|
|
2276
|
+
laneId
|
|
2277
|
+
});
|
|
2278
|
+
} else {
|
|
2279
|
+
permissionData = {
|
|
2280
|
+
userId,
|
|
2281
|
+
roles: userContext.roles || [],
|
|
2282
|
+
fetchedAt: /* @__PURE__ */ new Date()
|
|
2283
|
+
};
|
|
2284
|
+
}
|
|
2285
|
+
if (!permissionData) {
|
|
2286
|
+
throw new PermissionDeniedException({
|
|
2287
|
+
cause: new Error("Permission data fetch api is not configured"),
|
|
2288
|
+
type: PermissionDeniedType.PERMISSION_CONFIG_QUERY_FAILED,
|
|
2289
|
+
message: "Permission data fetch api is not configured"
|
|
2290
|
+
}, import_common11.HttpStatus.BAD_REQUEST);
|
|
2291
|
+
}
|
|
2292
|
+
const ability = this.abilityFactory.createForUser(permissionData);
|
|
2293
|
+
const { roles } = requirement;
|
|
2294
|
+
if (!roles || roles.length === 0) {
|
|
2295
|
+
return {
|
|
2296
|
+
result: true
|
|
2297
|
+
};
|
|
2298
|
+
}
|
|
2299
|
+
const hasRole = roles.some((role) => ability.can(role, ROLE_SUBJECT));
|
|
2300
|
+
if (!hasRole) {
|
|
2301
|
+
const userRoles = permissionData.roles;
|
|
2302
|
+
return {
|
|
2303
|
+
result: false,
|
|
2304
|
+
details: `\u7528\u6237 ${userId}, \u7528\u6237\u89D2\u8272 [${userRoles.join(", ")}], \u9700\u8981 [${roles.join(", ")}]`
|
|
2305
|
+
};
|
|
2306
|
+
}
|
|
2307
|
+
return {
|
|
2308
|
+
result: true
|
|
2309
|
+
};
|
|
2310
|
+
}
|
|
2311
|
+
};
|
|
2312
|
+
PermissionService = _ts_decorate42([
|
|
2313
|
+
(0, import_common11.Injectable)(),
|
|
2314
|
+
Public(),
|
|
2315
|
+
_ts_param3(0, (0, import_common11.Inject)(PERMISSION_API_CONFIG_TOKEN)),
|
|
2316
|
+
_ts_param3(2, (0, import_common11.Inject)(import_nestjs_common5.PLATFORM_HTTP_CLIENT)),
|
|
2317
|
+
_ts_metadata22("design:type", Function),
|
|
2318
|
+
_ts_metadata22("design:paramtypes", [
|
|
2319
|
+
typeof PermissionApiConfig === "undefined" ? Object : PermissionApiConfig,
|
|
2320
|
+
typeof AbilityFactory === "undefined" ? Object : AbilityFactory,
|
|
2321
|
+
typeof import_nestjs_common5.PlatformHttpClient === "undefined" ? Object : import_nestjs_common5.PlatformHttpClient,
|
|
2322
|
+
typeof import_nestjs_common6.RequestContextService === "undefined" ? Object : import_nestjs_common6.RequestContextService
|
|
2323
|
+
])
|
|
2324
|
+
], PermissionService);
|
|
2325
|
+
function _ts_decorate52(decorators, target, key, desc) {
|
|
2326
|
+
var c4 = arguments.length, r2 = c4 < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d4;
|
|
2327
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r2 = Reflect.decorate(decorators, target, key, desc);
|
|
2328
|
+
else for (var i4 = decorators.length - 1; i4 >= 0; i4--) if (d4 = decorators[i4]) r2 = (c4 < 3 ? d4(r2) : c4 > 3 ? d4(target, key, r2) : d4(target, key)) || r2;
|
|
2329
|
+
return c4 > 3 && r2 && Object.defineProperty(target, key, r2), r2;
|
|
2330
|
+
}
|
|
2331
|
+
__name(_ts_decorate52, "_ts_decorate5");
|
|
2332
|
+
__name2(_ts_decorate52, "_ts_decorate");
|
|
2333
|
+
function _ts_metadata32(k, v4) {
|
|
2334
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v4);
|
|
2335
|
+
}
|
|
2336
|
+
__name(_ts_metadata32, "_ts_metadata3");
|
|
2337
|
+
__name2(_ts_metadata32, "_ts_metadata");
|
|
2338
|
+
function _ts_param22(paramIndex, decorator) {
|
|
2339
|
+
return function(target, key) {
|
|
2340
|
+
decorator(target, key, paramIndex);
|
|
2341
|
+
};
|
|
2342
|
+
}
|
|
2343
|
+
__name(_ts_param22, "_ts_param2");
|
|
2344
|
+
__name2(_ts_param22, "_ts_param");
|
|
2345
|
+
var AuthZPaasGuard = class _AuthZPaasGuard {
|
|
2346
|
+
static {
|
|
2347
|
+
__name(this, "_AuthZPaasGuard");
|
|
2348
|
+
}
|
|
2349
|
+
static {
|
|
2350
|
+
__name2(this, "AuthZPaasGuard");
|
|
2351
|
+
}
|
|
2352
|
+
reflector;
|
|
2353
|
+
permissionService;
|
|
2354
|
+
obs;
|
|
2355
|
+
constructor(reflector, permissionService, obs) {
|
|
2356
|
+
this.reflector = reflector;
|
|
2357
|
+
this.permissionService = permissionService;
|
|
2358
|
+
this.obs = obs;
|
|
2359
|
+
}
|
|
2360
|
+
logger = new import_common18.Logger(_AuthZPaasGuard.name);
|
|
2361
|
+
/**
|
|
2362
|
+
* 验证角色要求是否有效
|
|
2363
|
+
* @param requirements 角色要求
|
|
2364
|
+
* @returns 是否有效
|
|
2365
|
+
*/
|
|
2366
|
+
isValidRoleRequirement(requirements) {
|
|
2367
|
+
return Boolean(requirements && requirements.roles && requirements.roles.length > 0);
|
|
2368
|
+
}
|
|
2369
|
+
async canActivate(context) {
|
|
2370
|
+
const http = context.switchToHttp();
|
|
2371
|
+
const request = http.getRequest();
|
|
2372
|
+
const laneId = request.headers["x-tt-env"];
|
|
2373
|
+
const baseUrl = `${request.protocol}://${request.get("host")}`;
|
|
2374
|
+
const userContext = request.userContext;
|
|
2375
|
+
userContext.baseUrl = baseUrl;
|
|
2376
|
+
const checkRoleRequirement = this.reflector.getAllAndOverride(ROLES_KEY, [
|
|
2377
|
+
context.getHandler(),
|
|
2378
|
+
context.getClass()
|
|
2379
|
+
]);
|
|
2380
|
+
if (this.isValidRoleRequirement(checkRoleRequirement)) {
|
|
2381
|
+
const spanName = checkRoleRequirement.roles.join(" or ");
|
|
2382
|
+
return this.obs.trace(spanName, async (span) => {
|
|
2383
|
+
span.setAttributes({
|
|
2384
|
+
module: "permission"
|
|
2385
|
+
});
|
|
2386
|
+
const startTime = Date.now();
|
|
2387
|
+
try {
|
|
2388
|
+
const checkResult = await this.permissionService.checkRoles(checkRoleRequirement, laneId, userContext);
|
|
2389
|
+
const endTime = Date.now();
|
|
2390
|
+
if (!checkResult.result) {
|
|
2391
|
+
this.logger.warn(JSON.stringify({
|
|
2392
|
+
role: spanName,
|
|
2393
|
+
duration_ms: endTime - startTime,
|
|
2394
|
+
result: checkResult.result ? "has_auth" : "no_auth",
|
|
2395
|
+
result_detail: checkResult.details
|
|
2396
|
+
}), {
|
|
2397
|
+
source_type: "platform",
|
|
2398
|
+
paas_attributes_module: "permission"
|
|
2399
|
+
});
|
|
2400
|
+
} else {
|
|
2401
|
+
this.logger.log(JSON.stringify({
|
|
2402
|
+
role: spanName,
|
|
2403
|
+
duration_ms: endTime - startTime,
|
|
2404
|
+
result: checkResult.result ? "has_auth" : "no_auth"
|
|
2405
|
+
}), {
|
|
2406
|
+
source_type: "platform",
|
|
2407
|
+
paas_attributes_module: "permission"
|
|
2408
|
+
});
|
|
2409
|
+
}
|
|
2410
|
+
return checkResult.result;
|
|
2411
|
+
} catch (error) {
|
|
2412
|
+
const endTime = Date.now();
|
|
2413
|
+
this.logger.error(JSON.stringify({
|
|
2414
|
+
role: spanName,
|
|
2415
|
+
duration_ms: endTime - startTime,
|
|
2416
|
+
result: "",
|
|
2417
|
+
error_message: error.message
|
|
2418
|
+
}), {
|
|
2419
|
+
source_type: "platform",
|
|
2420
|
+
paas_attributes_module: "permission"
|
|
2421
|
+
});
|
|
2422
|
+
throw error;
|
|
2423
|
+
}
|
|
2424
|
+
});
|
|
2425
|
+
}
|
|
2426
|
+
return true;
|
|
2427
|
+
}
|
|
2428
|
+
};
|
|
2429
|
+
AuthZPaasGuard = _ts_decorate52([
|
|
2430
|
+
(0, import_common18.Injectable)(),
|
|
2431
|
+
_ts_param22(2, (0, import_common18.Inject)(import_nestjs_common7.OBSERVABLE_SERVICE)),
|
|
2432
|
+
_ts_metadata32("design:type", Function),
|
|
2433
|
+
_ts_metadata32("design:paramtypes", [
|
|
2434
|
+
typeof import_core9.Reflector === "undefined" ? Object : import_core9.Reflector,
|
|
2435
|
+
typeof PermissionService === "undefined" ? Object : PermissionService,
|
|
2436
|
+
typeof import_nestjs_common7.ObservableService === "undefined" ? Object : import_nestjs_common7.ObservableService
|
|
2437
|
+
])
|
|
2438
|
+
], AuthZPaasGuard);
|
|
2439
|
+
function _ts_decorate62(decorators, target, key, desc) {
|
|
2440
|
+
var c4 = arguments.length, r2 = c4 < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d4;
|
|
2441
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r2 = Reflect.decorate(decorators, target, key, desc);
|
|
2442
|
+
else for (var i4 = decorators.length - 1; i4 >= 0; i4--) if (d4 = decorators[i4]) r2 = (c4 < 3 ? d4(r2) : c4 > 3 ? d4(target, key, r2) : d4(target, key)) || r2;
|
|
2443
|
+
return c4 > 3 && r2 && Object.defineProperty(target, key, r2), r2;
|
|
2444
|
+
}
|
|
2445
|
+
__name(_ts_decorate62, "_ts_decorate6");
|
|
2446
|
+
__name2(_ts_decorate62, "_ts_decorate");
|
|
2447
|
+
var AuthZPaasModule = class _AuthZPaasModule {
|
|
2448
|
+
static {
|
|
2449
|
+
__name(this, "_AuthZPaasModule");
|
|
2450
|
+
}
|
|
2451
|
+
static {
|
|
2452
|
+
__name2(this, "AuthZPaasModule");
|
|
2453
|
+
}
|
|
2454
|
+
static forRoot(options) {
|
|
2455
|
+
const { permissionApi = {} } = options || {};
|
|
2456
|
+
return {
|
|
2457
|
+
module: _AuthZPaasModule,
|
|
2458
|
+
global: true,
|
|
2459
|
+
controllers: [],
|
|
2460
|
+
providers: [
|
|
2461
|
+
// 配置提供者
|
|
2462
|
+
{
|
|
2463
|
+
provide: AUTHZPAAS_MODULE_OPTIONS,
|
|
2464
|
+
useValue: {
|
|
2465
|
+
...options
|
|
2466
|
+
}
|
|
2467
|
+
},
|
|
2468
|
+
{
|
|
2469
|
+
provide: PERMISSION_API_CONFIG_TOKEN,
|
|
2470
|
+
useValue: permissionApi
|
|
2471
|
+
},
|
|
2472
|
+
// 核心服务
|
|
2473
|
+
import_core6.Reflector,
|
|
2474
|
+
// 服务提供者
|
|
2475
|
+
PermissionService,
|
|
2476
|
+
AbilityFactory,
|
|
2477
|
+
AuthZPaasGuard,
|
|
2478
|
+
// 守卫提供者
|
|
2479
|
+
{
|
|
2480
|
+
provide: import_core6.APP_GUARD,
|
|
2481
|
+
useClass: AuthZPaasGuard
|
|
2482
|
+
}
|
|
2483
|
+
],
|
|
2484
|
+
exports: [
|
|
2485
|
+
PermissionService,
|
|
2486
|
+
AbilityFactory
|
|
2487
|
+
]
|
|
2488
|
+
};
|
|
2489
|
+
}
|
|
2490
|
+
/**
|
|
2491
|
+
* 异步注册 AuthZPaas 模块(根模块)
|
|
2492
|
+
* 用于需要从配置服务获取设置的场景
|
|
2493
|
+
*
|
|
2494
|
+
* @param options 异步配置选项
|
|
2495
|
+
* @returns 动态模块
|
|
2496
|
+
*
|
|
2497
|
+
* @example
|
|
2498
|
+
* ```typescript
|
|
2499
|
+
* @Module({
|
|
2500
|
+
* imports: [
|
|
2501
|
+
* AuthZPaasModule.forRootAsync({
|
|
2502
|
+
* imports: [ConfigModule],
|
|
2503
|
+
* inject: [ConfigService],
|
|
2504
|
+
* useFactory: async (configService: ConfigService) => ({
|
|
2505
|
+
* permissionApi: {
|
|
2506
|
+
* baseUrl: configService.get('PERMISSION_API_URL'),
|
|
2507
|
+
* apiToken: configService.get('PERMISSION_API_TOKEN'),
|
|
2508
|
+
* },
|
|
2509
|
+
* cache: {
|
|
2510
|
+
* ttl: configService.get('CACHE_TTL', 300),
|
|
2511
|
+
* max: configService.get('CACHE_MAX', 1000),
|
|
2512
|
+
* },
|
|
2513
|
+
* }),
|
|
2514
|
+
* }),
|
|
2515
|
+
* ],
|
|
2516
|
+
* })
|
|
2517
|
+
* export class AppModule {}
|
|
2518
|
+
* ```
|
|
2519
|
+
*/
|
|
2520
|
+
static forRootAsync(options) {
|
|
2521
|
+
const { imports = [], inject = [], useFactory } = options;
|
|
2522
|
+
return {
|
|
2523
|
+
module: _AuthZPaasModule,
|
|
2524
|
+
global: true,
|
|
2525
|
+
imports,
|
|
2526
|
+
controllers: [],
|
|
2527
|
+
providers: [
|
|
2528
|
+
// 异步配置提供者
|
|
2529
|
+
{
|
|
2530
|
+
provide: AUTHZPAAS_MODULE_OPTIONS,
|
|
2531
|
+
useFactory,
|
|
2532
|
+
inject
|
|
2533
|
+
},
|
|
2534
|
+
// 权限 API 配置提供者
|
|
2535
|
+
{
|
|
2536
|
+
provide: PERMISSION_API_CONFIG_TOKEN,
|
|
2537
|
+
useFactory: /* @__PURE__ */ __name2((moduleOptions) => {
|
|
2538
|
+
return moduleOptions.permissionApi;
|
|
2539
|
+
}, "useFactory"),
|
|
2540
|
+
inject: [
|
|
2541
|
+
AUTHZPAAS_MODULE_OPTIONS
|
|
2542
|
+
]
|
|
2543
|
+
},
|
|
2544
|
+
// 核心服务
|
|
2545
|
+
import_core6.Reflector,
|
|
2546
|
+
// 服务提供者
|
|
2547
|
+
PermissionService,
|
|
2548
|
+
AbilityFactory,
|
|
2549
|
+
AuthZPaasGuard,
|
|
2550
|
+
// 守卫提供者
|
|
2551
|
+
{
|
|
2552
|
+
provide: import_core6.APP_GUARD,
|
|
2553
|
+
useClass: AuthZPaasGuard
|
|
2554
|
+
}
|
|
2555
|
+
],
|
|
2556
|
+
exports: [
|
|
2557
|
+
PermissionService,
|
|
2558
|
+
AbilityFactory
|
|
2559
|
+
]
|
|
2560
|
+
};
|
|
2561
|
+
}
|
|
2562
|
+
};
|
|
2563
|
+
AuthZPaasModule = _ts_decorate62([
|
|
2564
|
+
(0, import_common10.Module)({})
|
|
2565
|
+
], AuthZPaasModule);
|
|
2566
|
+
var CanRole = /* @__PURE__ */ __name2((role) => {
|
|
2567
|
+
let requirement;
|
|
2568
|
+
if (!Array.isArray(role) && typeof role === "string") {
|
|
2569
|
+
requirement = {
|
|
2570
|
+
roles: [
|
|
2571
|
+
role
|
|
2572
|
+
]
|
|
2573
|
+
};
|
|
2574
|
+
} else if (Array.isArray(role) && role.every((role2) => typeof role2 === "string")) {
|
|
2575
|
+
requirement = {
|
|
2576
|
+
roles: role
|
|
2577
|
+
};
|
|
2578
|
+
} else {
|
|
2579
|
+
throw new Error("Invalid CanRole parameter: " + JSON.stringify(role));
|
|
2580
|
+
}
|
|
2581
|
+
return (0, import_common19.SetMetadata)(ROLES_KEY, requirement);
|
|
2582
|
+
}, "CanRole");
|
|
2583
|
+
|
|
2584
|
+
// src/modules/platform/module.ts
|
|
2585
|
+
function _ts_decorate11(decorators, target, key, desc) {
|
|
2586
|
+
var c4 = arguments.length, r2 = c4 < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d4;
|
|
2587
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r2 = Reflect.decorate(decorators, target, key, desc);
|
|
2588
|
+
else for (var i4 = decorators.length - 1; i4 >= 0; i4--) if (d4 = decorators[i4]) r2 = (c4 < 3 ? d4(r2) : c4 > 3 ? d4(target, key, r2) : d4(target, key)) || r2;
|
|
2589
|
+
return c4 > 3 && r2 && Object.defineProperty(target, key, r2), r2;
|
|
2590
|
+
}
|
|
2591
|
+
__name(_ts_decorate11, "_ts_decorate");
|
|
791
2592
|
var PLATFORM_MODULE_OPTIONS = /* @__PURE__ */ Symbol("PLATFORM_MODULE_OPTIONS");
|
|
792
2593
|
var PlatformModule = class _PlatformModule {
|
|
793
2594
|
static {
|
|
@@ -809,7 +2610,7 @@ var PlatformModule = class _PlatformModule {
|
|
|
809
2610
|
app_config_default
|
|
810
2611
|
]
|
|
811
2612
|
}),
|
|
812
|
-
|
|
2613
|
+
import_nestjs_common8.CommonModule,
|
|
813
2614
|
import_nestjs_observable.NestjsObservableModule,
|
|
814
2615
|
import_nestjs_logger2.LoggerModule,
|
|
815
2616
|
import_axios2.HttpModule.register({
|
|
@@ -848,6 +2649,7 @@ var PlatformModule = class _PlatformModule {
|
|
|
848
2649
|
})
|
|
849
2650
|
],
|
|
850
2651
|
import_nestjs_authnpaas.AuthNPaasModule.forRoot(),
|
|
2652
|
+
AuthZPaasModule.forRoot(),
|
|
851
2653
|
import_nestjs_trigger.AutomationModule.forRoot(),
|
|
852
2654
|
import_nestjs_capability.CapabilityModule.forRoot({
|
|
853
2655
|
capabilitiesDir: options.capabilitiesDir,
|
|
@@ -860,8 +2662,8 @@ var PlatformModule = class _PlatformModule {
|
|
|
860
2662
|
useValue: options
|
|
861
2663
|
},
|
|
862
2664
|
{
|
|
863
|
-
provide:
|
|
864
|
-
useValue: new
|
|
2665
|
+
provide: import_core10.APP_PIPE,
|
|
2666
|
+
useValue: new import_common20.ValidationPipe({
|
|
865
2667
|
transform: true,
|
|
866
2668
|
transformOptions: {
|
|
867
2669
|
enableImplicitConversion: true
|
|
@@ -869,12 +2671,12 @@ var PlatformModule = class _PlatformModule {
|
|
|
869
2671
|
})
|
|
870
2672
|
},
|
|
871
2673
|
{
|
|
872
|
-
provide:
|
|
2674
|
+
provide: import_nestjs_common8.OBSERVABLE_SERVICE,
|
|
873
2675
|
useClass: import_nestjs_observable.Observable
|
|
874
2676
|
},
|
|
875
2677
|
PlatformHttpClientService,
|
|
876
2678
|
{
|
|
877
|
-
provide:
|
|
2679
|
+
provide: import_nestjs_common9.PLATFORM_HTTP_CLIENT,
|
|
878
2680
|
useFactory: /* @__PURE__ */ __name((svc) => svc.instance, "useFactory"),
|
|
879
2681
|
inject: [
|
|
880
2682
|
PlatformHttpClientService
|
|
@@ -882,17 +2684,19 @@ var PlatformModule = class _PlatformModule {
|
|
|
882
2684
|
},
|
|
883
2685
|
HttpInterceptorService,
|
|
884
2686
|
{
|
|
885
|
-
provide:
|
|
2687
|
+
provide: import_core10.APP_INTERCEPTOR,
|
|
886
2688
|
useClass: import_nestjs_observable.TraceInterceptor
|
|
887
|
-
}
|
|
2689
|
+
},
|
|
2690
|
+
FileService
|
|
888
2691
|
],
|
|
889
2692
|
exports: [
|
|
890
2693
|
import_config2.ConfigModule,
|
|
891
2694
|
import_nestjs_logger2.LoggerModule,
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
import_nestjs_capability.CapabilityModule
|
|
2695
|
+
import_nestjs_common8.CommonModule,
|
|
2696
|
+
import_nestjs_common8.OBSERVABLE_SERVICE,
|
|
2697
|
+
import_nestjs_common9.PLATFORM_HTTP_CLIENT,
|
|
2698
|
+
import_nestjs_capability.CapabilityModule,
|
|
2699
|
+
FileService
|
|
896
2700
|
]
|
|
897
2701
|
};
|
|
898
2702
|
}
|
|
@@ -921,9 +2725,9 @@ var PlatformModule = class _PlatformModule {
|
|
|
921
2725
|
}
|
|
922
2726
|
}
|
|
923
2727
|
};
|
|
924
|
-
PlatformModule =
|
|
925
|
-
(0,
|
|
926
|
-
(0,
|
|
2728
|
+
PlatformModule = _ts_decorate11([
|
|
2729
|
+
(0, import_common20.Global)(),
|
|
2730
|
+
(0, import_common20.Module)({})
|
|
927
2731
|
], PlatformModule);
|
|
928
2732
|
|
|
929
2733
|
// src/setup.ts
|
|
@@ -962,14 +2766,17 @@ __reExport(index_exports, require("@lark-apaas/nestjs-capability"), module.expor
|
|
|
962
2766
|
__reExport(index_exports, require("@lark-apaas/nestjs-datapaas"), module.exports);
|
|
963
2767
|
__reExport(index_exports, require("@lark-apaas/nestjs-observable"), module.exports);
|
|
964
2768
|
__reExport(index_exports, require("@lark-apaas/nestjs-trigger"), module.exports);
|
|
965
|
-
|
|
2769
|
+
__reExport(index_exports, require("@lark-apaas/file-service"), module.exports);
|
|
2770
|
+
var import_nestjs_common10 = require("@lark-apaas/nestjs-common");
|
|
966
2771
|
// Annotate the CommonJS export names for ESM import in node:
|
|
967
2772
|
0 && (module.exports = {
|
|
968
2773
|
AutoTrace,
|
|
2774
|
+
CanRole,
|
|
969
2775
|
CsrfMiddleware,
|
|
970
2776
|
CsrfTokenMiddleware,
|
|
971
2777
|
DevToolsModule,
|
|
972
2778
|
DevToolsV2Module,
|
|
2779
|
+
FileService,
|
|
973
2780
|
PlatformModule,
|
|
974
2781
|
UserContextMiddleware,
|
|
975
2782
|
ViewContextMiddleware,
|
|
@@ -978,5 +2785,6 @@ var import_nestjs_common5 = require("@lark-apaas/nestjs-common");
|
|
|
978
2785
|
...require("@lark-apaas/nestjs-capability"),
|
|
979
2786
|
...require("@lark-apaas/nestjs-datapaas"),
|
|
980
2787
|
...require("@lark-apaas/nestjs-observable"),
|
|
981
|
-
...require("@lark-apaas/nestjs-trigger")
|
|
2788
|
+
...require("@lark-apaas/nestjs-trigger"),
|
|
2789
|
+
...require("@lark-apaas/file-service")
|
|
982
2790
|
});
|