@lark-apaas/nestjs-capability 0.1.5 → 0.1.7
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/README.md +2 -0
- package/dist/index.cjs +262 -122
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +65 -2
- package/dist/index.d.ts +65 -2
- package/dist/index.js +236 -97
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -381,12 +381,100 @@ PluginLoaderService = _ts_decorate2([
|
|
|
381
381
|
], PluginLoaderService);
|
|
382
382
|
|
|
383
383
|
// src/services/capability.service.ts
|
|
384
|
-
import { Injectable as
|
|
384
|
+
import { Injectable as Injectable4, Logger as Logger3, Inject as Inject2 } from "@nestjs/common";
|
|
385
385
|
import { RequestContextService, HTTP_CLIENT_FACTORY } from "@lark-apaas/nestjs-common";
|
|
386
386
|
import * as fs2 from "fs";
|
|
387
387
|
import * as path2 from "path";
|
|
388
388
|
import * as chokidar from "chokidar";
|
|
389
389
|
|
|
390
|
+
// src/services/telemetry.service.ts
|
|
391
|
+
import { Injectable as Injectable3, Inject, Logger as Logger2 } from "@nestjs/common";
|
|
392
|
+
import { PLATFORM_HTTP_CLIENT } from "@lark-apaas/nestjs-common";
|
|
393
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
394
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
395
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
396
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
397
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
398
|
+
}
|
|
399
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
400
|
+
function _ts_metadata(k, v) {
|
|
401
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
402
|
+
}
|
|
403
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
404
|
+
function _ts_param(paramIndex, decorator) {
|
|
405
|
+
return function(target, key) {
|
|
406
|
+
decorator(target, key, paramIndex);
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
__name(_ts_param, "_ts_param");
|
|
410
|
+
var TELEMETRY_PATH = "/api/v1/studio/innerapi/resource_events";
|
|
411
|
+
var TelemetryService = class _TelemetryService {
|
|
412
|
+
static {
|
|
413
|
+
__name(this, "TelemetryService");
|
|
414
|
+
}
|
|
415
|
+
client;
|
|
416
|
+
logger = new Logger2(_TelemetryService.name);
|
|
417
|
+
constructor(client) {
|
|
418
|
+
this.client = client;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* 上报事件到平台
|
|
422
|
+
*
|
|
423
|
+
* @param events - 事件列表
|
|
424
|
+
* @returns 是否上报成功
|
|
425
|
+
*/
|
|
426
|
+
async reportEvents(events) {
|
|
427
|
+
if (events.length === 0) {
|
|
428
|
+
return true;
|
|
429
|
+
}
|
|
430
|
+
try {
|
|
431
|
+
const response = await this.client.post(TELEMETRY_PATH, {
|
|
432
|
+
events
|
|
433
|
+
});
|
|
434
|
+
if (!response.ok) {
|
|
435
|
+
this.logger.warn(`Failed to report events: ${response.status} ${response.statusText}`);
|
|
436
|
+
return false;
|
|
437
|
+
}
|
|
438
|
+
const result = await response.json();
|
|
439
|
+
if (result.status_code !== "0") {
|
|
440
|
+
this.logger.warn(`API error: ${result.message}`);
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
443
|
+
this.logger.debug(`Reported ${events.length} event(s) successfully`);
|
|
444
|
+
return true;
|
|
445
|
+
} catch (error) {
|
|
446
|
+
this.logger.warn(`Failed to report events: ${error instanceof Error ? error.message : error}`);
|
|
447
|
+
return false;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* 上报插件调用事件
|
|
452
|
+
*
|
|
453
|
+
* @param pluginKey - 插件标识
|
|
454
|
+
* @param details - 调用详情
|
|
455
|
+
*/
|
|
456
|
+
async reportCall(pluginKey, details) {
|
|
457
|
+
await this.reportEvents([
|
|
458
|
+
{
|
|
459
|
+
resourceType: "plugin",
|
|
460
|
+
resourceKey: pluginKey,
|
|
461
|
+
eventType: "call",
|
|
462
|
+
details: {
|
|
463
|
+
...details
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
]);
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
TelemetryService = _ts_decorate3([
|
|
470
|
+
Injectable3(),
|
|
471
|
+
_ts_param(0, Inject(PLATFORM_HTTP_CLIENT)),
|
|
472
|
+
_ts_metadata("design:type", Function),
|
|
473
|
+
_ts_metadata("design:paramtypes", [
|
|
474
|
+
typeof PlatformHttpClient === "undefined" ? Object : PlatformHttpClient
|
|
475
|
+
])
|
|
476
|
+
], TelemetryService);
|
|
477
|
+
|
|
390
478
|
// src/utils/log-utils.ts
|
|
391
479
|
var DEFAULT_MAX_LENGTH = 1e3;
|
|
392
480
|
function truncateString(str, maxLength) {
|
|
@@ -445,23 +533,23 @@ async function migrationAdaptor(promise) {
|
|
|
445
533
|
__name(migrationAdaptor, "migrationAdaptor");
|
|
446
534
|
|
|
447
535
|
// src/services/capability.service.ts
|
|
448
|
-
function
|
|
536
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
449
537
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
450
538
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
451
539
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
452
540
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
453
541
|
}
|
|
454
|
-
__name(
|
|
455
|
-
function
|
|
542
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
543
|
+
function _ts_metadata2(k, v) {
|
|
456
544
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
457
545
|
}
|
|
458
|
-
__name(
|
|
459
|
-
function
|
|
546
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
547
|
+
function _ts_param2(paramIndex, decorator) {
|
|
460
548
|
return function(target, key) {
|
|
461
549
|
decorator(target, key, paramIndex);
|
|
462
550
|
};
|
|
463
551
|
}
|
|
464
|
-
__name(
|
|
552
|
+
__name(_ts_param2, "_ts_param");
|
|
465
553
|
var CapabilityNotFoundError = class extends Error {
|
|
466
554
|
static {
|
|
467
555
|
__name(this, "CapabilityNotFoundError");
|
|
@@ -494,18 +582,20 @@ var CapabilityService = class _CapabilityService {
|
|
|
494
582
|
httpClientFactory;
|
|
495
583
|
pluginLoaderService;
|
|
496
584
|
templateEngineService;
|
|
497
|
-
|
|
585
|
+
telemetryService;
|
|
586
|
+
logger = new Logger3(_CapabilityService.name);
|
|
498
587
|
capabilities = /* @__PURE__ */ new Map();
|
|
499
588
|
/** 文件路径到 capability id 的映射,用于文件删除时查找 */
|
|
500
589
|
filePathToId = /* @__PURE__ */ new Map();
|
|
501
590
|
capabilitiesDir;
|
|
502
591
|
fileWatcher = null;
|
|
503
592
|
options = {};
|
|
504
|
-
constructor(requestContextService, httpClientFactory, pluginLoaderService, templateEngineService) {
|
|
593
|
+
constructor(requestContextService, httpClientFactory, pluginLoaderService, templateEngineService, telemetryService) {
|
|
505
594
|
this.requestContextService = requestContextService;
|
|
506
595
|
this.httpClientFactory = httpClientFactory;
|
|
507
596
|
this.pluginLoaderService = pluginLoaderService;
|
|
508
597
|
this.templateEngineService = templateEngineService;
|
|
598
|
+
this.telemetryService = telemetryService;
|
|
509
599
|
const isDev = process.env.NODE_ENV === "development";
|
|
510
600
|
this.capabilitiesDir = path2.join(process.cwd(), isDev ? "server/capabilities" : "capabilities");
|
|
511
601
|
}
|
|
@@ -738,13 +828,14 @@ var CapabilityService = class _CapabilityService {
|
|
|
738
828
|
plugin_key: config.pluginKey,
|
|
739
829
|
action: actionName
|
|
740
830
|
};
|
|
831
|
+
let isStream = false;
|
|
741
832
|
try {
|
|
742
833
|
const { pluginInstance, resolvedParams } = await this.loadPluginAndResolveParams(config, input);
|
|
743
834
|
if (!pluginInstance.hasAction(actionName)) {
|
|
744
835
|
throw new ActionNotFoundError(config.pluginKey, actionName);
|
|
745
836
|
}
|
|
746
837
|
const context = this.buildActionContext(config.pluginKey, contextOverride);
|
|
747
|
-
|
|
838
|
+
isStream = pluginInstance.isStreamAction?.(actionName) ?? false;
|
|
748
839
|
this.logger.log("Executing capability (call)", {
|
|
749
840
|
...loggerContext,
|
|
750
841
|
is_stream: isStream,
|
|
@@ -760,18 +851,23 @@ var CapabilityService = class _CapabilityService {
|
|
|
760
851
|
} else {
|
|
761
852
|
result = await pluginInstance.run(actionName, context, resolvedParams);
|
|
762
853
|
}
|
|
854
|
+
const durationMs = Date.now() - startTime;
|
|
763
855
|
this.logger.log("Capability (call) executed successfully", {
|
|
764
856
|
...loggerContext,
|
|
765
|
-
duration_ms:
|
|
857
|
+
duration_ms: durationMs,
|
|
766
858
|
output: stringifyForLog(result)
|
|
767
859
|
});
|
|
860
|
+
this.reportCallEvent(config.pluginKey, true, durationMs, isStream, contextOverride);
|
|
768
861
|
return result;
|
|
769
862
|
} catch (error) {
|
|
863
|
+
const durationMs = Date.now() - startTime;
|
|
770
864
|
this.logger.error("Capability (call) execution failed", {
|
|
771
865
|
...loggerContext,
|
|
772
|
-
duration_ms:
|
|
866
|
+
duration_ms: durationMs,
|
|
773
867
|
error: error instanceof Error ? error.message : String(error)
|
|
774
868
|
});
|
|
869
|
+
const errorCode = String(error?.code ?? "EXECUTION_ERROR");
|
|
870
|
+
this.reportCallEvent(config.pluginKey, false, durationMs, isStream, contextOverride, errorCode);
|
|
775
871
|
throw error;
|
|
776
872
|
}
|
|
777
873
|
}
|
|
@@ -810,18 +906,23 @@ var CapabilityService = class _CapabilityService {
|
|
|
810
906
|
chunks.push(result);
|
|
811
907
|
yield result;
|
|
812
908
|
}
|
|
909
|
+
const durationMs = Date.now() - startTime;
|
|
813
910
|
const aggregatedResult = pluginInstance.aggregate ? pluginInstance.aggregate(actionName, chunks) : chunks;
|
|
814
911
|
this.logger.log("Capability (stream) executed successfully", {
|
|
815
912
|
...loggerContext,
|
|
816
|
-
duration_ms:
|
|
913
|
+
duration_ms: durationMs,
|
|
817
914
|
output: stringifyForLog(aggregatedResult)
|
|
818
915
|
});
|
|
916
|
+
this.reportCallEvent(config.pluginKey, true, durationMs, isStream, contextOverride);
|
|
819
917
|
} catch (error) {
|
|
918
|
+
const durationMs = Date.now() - startTime;
|
|
820
919
|
this.logger.error("Capability (stream) execution failed", {
|
|
821
920
|
...loggerContext,
|
|
822
|
-
duration_ms:
|
|
921
|
+
duration_ms: durationMs,
|
|
823
922
|
error: error instanceof Error ? error.message : String(error)
|
|
824
923
|
});
|
|
924
|
+
const errorCode = String(error?.code ?? "EXECUTION_ERROR");
|
|
925
|
+
this.reportCallEvent(config.pluginKey, false, durationMs, true, contextOverride, errorCode);
|
|
825
926
|
throw error;
|
|
826
927
|
}
|
|
827
928
|
}
|
|
@@ -857,6 +958,8 @@ var CapabilityService = class _CapabilityService {
|
|
|
857
958
|
yield event;
|
|
858
959
|
} else if (event.type === "done") {
|
|
859
960
|
const aggregatedResult2 = pluginInstance.aggregate ? pluginInstance.aggregate(actionName, chunks) : chunks;
|
|
961
|
+
const durationMs = Date.now() - startTime;
|
|
962
|
+
this.reportCallEvent(config.pluginKey, true, durationMs, isStream, contextOverride);
|
|
860
963
|
yield {
|
|
861
964
|
type: "done",
|
|
862
965
|
metadata: {
|
|
@@ -886,11 +989,13 @@ var CapabilityService = class _CapabilityService {
|
|
|
886
989
|
};
|
|
887
990
|
}
|
|
888
991
|
const aggregatedResult2 = pluginInstance.aggregate ? pluginInstance.aggregate(actionName, chunks) : chunks;
|
|
992
|
+
const durationMs = Date.now() - startTime;
|
|
993
|
+
this.reportCallEvent(config.pluginKey, true, durationMs, isStream, contextOverride);
|
|
889
994
|
yield {
|
|
890
995
|
type: "done",
|
|
891
996
|
metadata: {
|
|
892
997
|
chunks: chunks.length,
|
|
893
|
-
duration:
|
|
998
|
+
duration: durationMs,
|
|
894
999
|
aggregated: aggregatedResult2
|
|
895
1000
|
}
|
|
896
1001
|
};
|
|
@@ -902,11 +1007,14 @@ var CapabilityService = class _CapabilityService {
|
|
|
902
1007
|
output: stringifyForLog(aggregatedResult)
|
|
903
1008
|
});
|
|
904
1009
|
} catch (error) {
|
|
1010
|
+
const durationMs = Date.now() - startTime;
|
|
905
1011
|
this.logger.error("Capability (streamWithEvents) execution failed", {
|
|
906
1012
|
...loggerContext,
|
|
907
|
-
duration_ms:
|
|
1013
|
+
duration_ms: durationMs,
|
|
908
1014
|
error: error instanceof Error ? error.message : String(error)
|
|
909
1015
|
});
|
|
1016
|
+
const errorCode = String(error?.code ?? "EXECUTION_ERROR");
|
|
1017
|
+
this.reportCallEvent(config.pluginKey, false, durationMs, true, contextOverride, errorCode);
|
|
910
1018
|
yield {
|
|
911
1019
|
type: "error",
|
|
912
1020
|
error: this.extractErrorInfo(error)
|
|
@@ -914,6 +1022,22 @@ var CapabilityService = class _CapabilityService {
|
|
|
914
1022
|
}
|
|
915
1023
|
}
|
|
916
1024
|
/**
|
|
1025
|
+
* 上报调用事件(fire-and-forget)
|
|
1026
|
+
*/
|
|
1027
|
+
reportCallEvent(pluginKey, success, durationMs, isStream, contextOverride, statusCode = "0") {
|
|
1028
|
+
const callerType = contextOverride?.caller ?? (contextOverride?.isDebug ? "debug" : "server");
|
|
1029
|
+
const manifest = this.pluginLoaderService.getManifest(pluginKey);
|
|
1030
|
+
this.telemetryService.reportCall(pluginKey, {
|
|
1031
|
+
version: manifest?.version ?? "",
|
|
1032
|
+
success: String(success),
|
|
1033
|
+
duration: String(durationMs),
|
|
1034
|
+
is_stream: String(isStream),
|
|
1035
|
+
caller_type: String(callerType),
|
|
1036
|
+
status_code: statusCode
|
|
1037
|
+
}).catch(() => {
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
/**
|
|
917
1041
|
* 从错误对象提取错误信息
|
|
918
1042
|
* 支持 PluginError 和 RateLimitError
|
|
919
1043
|
*/
|
|
@@ -940,7 +1064,8 @@ var CapabilityService = class _CapabilityService {
|
|
|
940
1064
|
logger: this.logger,
|
|
941
1065
|
platformHttpClient: this.createPluginHttpClient(pluginKey),
|
|
942
1066
|
userContext: override?.userContext ?? this.getUserContext(),
|
|
943
|
-
isDebug: override?.isDebug ?? false
|
|
1067
|
+
isDebug: override?.isDebug ?? false,
|
|
1068
|
+
caller: override?.caller
|
|
944
1069
|
};
|
|
945
1070
|
}
|
|
946
1071
|
/**
|
|
@@ -977,42 +1102,44 @@ var CapabilityService = class _CapabilityService {
|
|
|
977
1102
|
return {
|
|
978
1103
|
appId: ctx?.appId ?? "",
|
|
979
1104
|
userId: ctx?.userId ?? "",
|
|
980
|
-
tenantId: ctx?.tenantId ?? ""
|
|
1105
|
+
tenantId: ctx?.tenantId ?? "",
|
|
1106
|
+
isSystemAccount: ctx?.isSystemAccount ?? false
|
|
981
1107
|
};
|
|
982
1108
|
}
|
|
983
1109
|
};
|
|
984
|
-
CapabilityService =
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
1110
|
+
CapabilityService = _ts_decorate4([
|
|
1111
|
+
Injectable4(),
|
|
1112
|
+
_ts_param2(1, Inject2(HTTP_CLIENT_FACTORY)),
|
|
1113
|
+
_ts_metadata2("design:type", Function),
|
|
1114
|
+
_ts_metadata2("design:paramtypes", [
|
|
989
1115
|
typeof RequestContextService === "undefined" ? Object : RequestContextService,
|
|
990
1116
|
typeof HttpClientFactory === "undefined" ? Object : HttpClientFactory,
|
|
991
1117
|
typeof PluginLoaderService === "undefined" ? Object : PluginLoaderService,
|
|
992
|
-
typeof TemplateEngineService === "undefined" ? Object : TemplateEngineService
|
|
1118
|
+
typeof TemplateEngineService === "undefined" ? Object : TemplateEngineService,
|
|
1119
|
+
typeof TelemetryService === "undefined" ? Object : TelemetryService
|
|
993
1120
|
])
|
|
994
1121
|
], CapabilityService);
|
|
995
1122
|
|
|
996
1123
|
// src/controllers/debug.controller.ts
|
|
997
|
-
import { Controller, Post, Get, Param, Body, Res, HttpStatus, Logger as
|
|
1124
|
+
import { Controller, Post, Get, Param, Body, Res, HttpStatus, Logger as Logger4 } from "@nestjs/common";
|
|
998
1125
|
import { ApiExcludeController } from "@nestjs/swagger";
|
|
999
|
-
function
|
|
1126
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
1000
1127
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1001
1128
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1002
1129
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1003
1130
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1004
1131
|
}
|
|
1005
|
-
__name(
|
|
1006
|
-
function
|
|
1132
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
1133
|
+
function _ts_metadata3(k, v) {
|
|
1007
1134
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1008
1135
|
}
|
|
1009
|
-
__name(
|
|
1010
|
-
function
|
|
1136
|
+
__name(_ts_metadata3, "_ts_metadata");
|
|
1137
|
+
function _ts_param3(paramIndex, decorator) {
|
|
1011
1138
|
return function(target, key) {
|
|
1012
1139
|
decorator(target, key, paramIndex);
|
|
1013
1140
|
};
|
|
1014
1141
|
}
|
|
1015
|
-
__name(
|
|
1142
|
+
__name(_ts_param3, "_ts_param");
|
|
1016
1143
|
var DebugController = class _DebugController {
|
|
1017
1144
|
static {
|
|
1018
1145
|
__name(this, "DebugController");
|
|
@@ -1020,7 +1147,7 @@ var DebugController = class _DebugController {
|
|
|
1020
1147
|
capabilityService;
|
|
1021
1148
|
pluginLoaderService;
|
|
1022
1149
|
templateEngineService;
|
|
1023
|
-
logger = new
|
|
1150
|
+
logger = new Logger4(_DebugController.name);
|
|
1024
1151
|
constructor(capabilityService, pluginLoaderService, templateEngineService) {
|
|
1025
1152
|
this.capabilityService = capabilityService;
|
|
1026
1153
|
this.pluginLoaderService = pluginLoaderService;
|
|
@@ -1086,7 +1213,8 @@ var DebugController = class _DebugController {
|
|
|
1086
1213
|
const action = await this.getActionName(config.pluginKey, config.formValue, body.action);
|
|
1087
1214
|
const resolvedParams = this.templateEngineService.resolve(config.formValue, params, config.paramsSchema);
|
|
1088
1215
|
const result = await this.capabilityService.loadWithConfig(config).call(action, params, {
|
|
1089
|
-
isDebug: true
|
|
1216
|
+
isDebug: true,
|
|
1217
|
+
caller: "debug"
|
|
1090
1218
|
});
|
|
1091
1219
|
res.status(HttpStatus.OK).json({
|
|
1092
1220
|
status_code: ErrorCodes.SUCCESS,
|
|
@@ -1160,7 +1288,8 @@ var DebugController = class _DebugController {
|
|
|
1160
1288
|
});
|
|
1161
1289
|
const capability = this.capabilityService.loadWithConfig(config);
|
|
1162
1290
|
const eventStream = capability.callStreamWithEvents(action, params, {
|
|
1163
|
-
isDebug: true
|
|
1291
|
+
isDebug: true,
|
|
1292
|
+
caller: "debug"
|
|
1164
1293
|
});
|
|
1165
1294
|
let pendingChunk = null;
|
|
1166
1295
|
for await (const event of eventStream) {
|
|
@@ -1259,46 +1388,46 @@ var DebugController = class _DebugController {
|
|
|
1259
1388
|
}
|
|
1260
1389
|
}
|
|
1261
1390
|
};
|
|
1262
|
-
|
|
1391
|
+
_ts_decorate5([
|
|
1263
1392
|
Get("list"),
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1393
|
+
_ts_param3(0, Res()),
|
|
1394
|
+
_ts_metadata3("design:type", Function),
|
|
1395
|
+
_ts_metadata3("design:paramtypes", [
|
|
1267
1396
|
typeof Response === "undefined" ? Object : Response
|
|
1268
1397
|
]),
|
|
1269
|
-
|
|
1398
|
+
_ts_metadata3("design:returntype", void 0)
|
|
1270
1399
|
], DebugController.prototype, "list", null);
|
|
1271
|
-
|
|
1400
|
+
_ts_decorate5([
|
|
1272
1401
|
Post("debug/:capability_id"),
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1402
|
+
_ts_param3(0, Param("capability_id")),
|
|
1403
|
+
_ts_param3(1, Body()),
|
|
1404
|
+
_ts_param3(2, Res()),
|
|
1405
|
+
_ts_metadata3("design:type", Function),
|
|
1406
|
+
_ts_metadata3("design:paramtypes", [
|
|
1278
1407
|
String,
|
|
1279
1408
|
typeof DebugRequestBody === "undefined" ? Object : DebugRequestBody,
|
|
1280
1409
|
typeof Response === "undefined" ? Object : Response
|
|
1281
1410
|
]),
|
|
1282
|
-
|
|
1411
|
+
_ts_metadata3("design:returntype", Promise)
|
|
1283
1412
|
], DebugController.prototype, "debug", null);
|
|
1284
|
-
|
|
1413
|
+
_ts_decorate5([
|
|
1285
1414
|
Post("debug/:capability_id/stream"),
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1415
|
+
_ts_param3(0, Param("capability_id")),
|
|
1416
|
+
_ts_param3(1, Body()),
|
|
1417
|
+
_ts_param3(2, Res()),
|
|
1418
|
+
_ts_metadata3("design:type", Function),
|
|
1419
|
+
_ts_metadata3("design:paramtypes", [
|
|
1291
1420
|
String,
|
|
1292
1421
|
typeof DebugRequestBody === "undefined" ? Object : DebugRequestBody,
|
|
1293
1422
|
typeof Response === "undefined" ? Object : Response
|
|
1294
1423
|
]),
|
|
1295
|
-
|
|
1424
|
+
_ts_metadata3("design:returntype", Promise)
|
|
1296
1425
|
], DebugController.prototype, "debugStream", null);
|
|
1297
|
-
DebugController =
|
|
1426
|
+
DebugController = _ts_decorate5([
|
|
1298
1427
|
ApiExcludeController(),
|
|
1299
1428
|
Controller("__innerapi__/capability"),
|
|
1300
|
-
|
|
1301
|
-
|
|
1429
|
+
_ts_metadata3("design:type", Function),
|
|
1430
|
+
_ts_metadata3("design:paramtypes", [
|
|
1302
1431
|
typeof CapabilityService === "undefined" ? Object : CapabilityService,
|
|
1303
1432
|
typeof PluginLoaderService === "undefined" ? Object : PluginLoaderService,
|
|
1304
1433
|
typeof TemplateEngineService === "undefined" ? Object : TemplateEngineService
|
|
@@ -1306,31 +1435,31 @@ DebugController = _ts_decorate4([
|
|
|
1306
1435
|
], DebugController);
|
|
1307
1436
|
|
|
1308
1437
|
// src/controllers/webhook.controller.ts
|
|
1309
|
-
import { Controller as Controller2, Get as Get2, Post as Post2, Param as Param2, Body as Body2, Res as Res2, HttpStatus as HttpStatus2, Logger as
|
|
1438
|
+
import { Controller as Controller2, Get as Get2, Post as Post2, Param as Param2, Body as Body2, Res as Res2, HttpStatus as HttpStatus2, Logger as Logger5 } from "@nestjs/common";
|
|
1310
1439
|
import { ApiExcludeController as ApiExcludeController2 } from "@nestjs/swagger";
|
|
1311
|
-
function
|
|
1440
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
1312
1441
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1313
1442
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1314
1443
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1315
1444
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1316
1445
|
}
|
|
1317
|
-
__name(
|
|
1318
|
-
function
|
|
1446
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
1447
|
+
function _ts_metadata4(k, v) {
|
|
1319
1448
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1320
1449
|
}
|
|
1321
|
-
__name(
|
|
1322
|
-
function
|
|
1450
|
+
__name(_ts_metadata4, "_ts_metadata");
|
|
1451
|
+
function _ts_param4(paramIndex, decorator) {
|
|
1323
1452
|
return function(target, key) {
|
|
1324
1453
|
decorator(target, key, paramIndex);
|
|
1325
1454
|
};
|
|
1326
1455
|
}
|
|
1327
|
-
__name(
|
|
1456
|
+
__name(_ts_param4, "_ts_param");
|
|
1328
1457
|
var WebhookController = class _WebhookController {
|
|
1329
1458
|
static {
|
|
1330
1459
|
__name(this, "WebhookController");
|
|
1331
1460
|
}
|
|
1332
1461
|
capabilityService;
|
|
1333
|
-
logger = new
|
|
1462
|
+
logger = new Logger5(_WebhookController.name);
|
|
1334
1463
|
constructor(capabilityService) {
|
|
1335
1464
|
this.capabilityService = capabilityService;
|
|
1336
1465
|
}
|
|
@@ -1358,7 +1487,9 @@ var WebhookController = class _WebhookController {
|
|
|
1358
1487
|
}
|
|
1359
1488
|
async execute(capabilityId, body, res) {
|
|
1360
1489
|
try {
|
|
1361
|
-
const result = await this.capabilityService.load(capabilityId).call(body.action, body.params
|
|
1490
|
+
const result = await this.capabilityService.load(capabilityId).call(body.action, body.params, {
|
|
1491
|
+
caller: "client"
|
|
1492
|
+
});
|
|
1362
1493
|
res.status(HttpStatus2.OK).json({
|
|
1363
1494
|
status_code: ErrorCodes.SUCCESS,
|
|
1364
1495
|
data: {
|
|
@@ -1419,7 +1550,9 @@ var WebhookController = class _WebhookController {
|
|
|
1419
1550
|
input: stringifyForLog(body.params)
|
|
1420
1551
|
});
|
|
1421
1552
|
const capability = this.capabilityService.load(capabilityId);
|
|
1422
|
-
const eventStream = capability.callStreamWithEvents(body.action, body.params
|
|
1553
|
+
const eventStream = capability.callStreamWithEvents(body.action, body.params, {
|
|
1554
|
+
caller: "client"
|
|
1555
|
+
});
|
|
1423
1556
|
let pendingChunk = null;
|
|
1424
1557
|
for await (const event of eventStream) {
|
|
1425
1558
|
switch (event.type) {
|
|
@@ -1517,46 +1650,46 @@ var WebhookController = class _WebhookController {
|
|
|
1517
1650
|
}
|
|
1518
1651
|
}
|
|
1519
1652
|
};
|
|
1520
|
-
|
|
1653
|
+
_ts_decorate6([
|
|
1521
1654
|
Get2("list"),
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1655
|
+
_ts_param4(0, Res2()),
|
|
1656
|
+
_ts_metadata4("design:type", Function),
|
|
1657
|
+
_ts_metadata4("design:paramtypes", [
|
|
1525
1658
|
typeof Response === "undefined" ? Object : Response
|
|
1526
1659
|
]),
|
|
1527
|
-
|
|
1660
|
+
_ts_metadata4("design:returntype", void 0)
|
|
1528
1661
|
], WebhookController.prototype, "list", null);
|
|
1529
|
-
|
|
1662
|
+
_ts_decorate6([
|
|
1530
1663
|
Post2(":capability_id"),
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1664
|
+
_ts_param4(0, Param2("capability_id")),
|
|
1665
|
+
_ts_param4(1, Body2()),
|
|
1666
|
+
_ts_param4(2, Res2()),
|
|
1667
|
+
_ts_metadata4("design:type", Function),
|
|
1668
|
+
_ts_metadata4("design:paramtypes", [
|
|
1536
1669
|
String,
|
|
1537
1670
|
typeof ExecuteRequestBody === "undefined" ? Object : ExecuteRequestBody,
|
|
1538
1671
|
typeof Response === "undefined" ? Object : Response
|
|
1539
1672
|
]),
|
|
1540
|
-
|
|
1673
|
+
_ts_metadata4("design:returntype", Promise)
|
|
1541
1674
|
], WebhookController.prototype, "execute", null);
|
|
1542
|
-
|
|
1675
|
+
_ts_decorate6([
|
|
1543
1676
|
Post2(":capability_id/stream"),
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1677
|
+
_ts_param4(0, Param2("capability_id")),
|
|
1678
|
+
_ts_param4(1, Body2()),
|
|
1679
|
+
_ts_param4(2, Res2()),
|
|
1680
|
+
_ts_metadata4("design:type", Function),
|
|
1681
|
+
_ts_metadata4("design:paramtypes", [
|
|
1549
1682
|
String,
|
|
1550
1683
|
typeof ExecuteRequestBody === "undefined" ? Object : ExecuteRequestBody,
|
|
1551
1684
|
typeof Response === "undefined" ? Object : Response
|
|
1552
1685
|
]),
|
|
1553
|
-
|
|
1686
|
+
_ts_metadata4("design:returntype", Promise)
|
|
1554
1687
|
], WebhookController.prototype, "executeStream", null);
|
|
1555
|
-
WebhookController =
|
|
1688
|
+
WebhookController = _ts_decorate6([
|
|
1556
1689
|
ApiExcludeController2(),
|
|
1557
1690
|
Controller2("api/capability"),
|
|
1558
|
-
|
|
1559
|
-
|
|
1691
|
+
_ts_metadata4("design:type", Function),
|
|
1692
|
+
_ts_metadata4("design:paramtypes", [
|
|
1560
1693
|
typeof CapabilityService === "undefined" ? Object : CapabilityService
|
|
1561
1694
|
])
|
|
1562
1695
|
], WebhookController);
|
|
@@ -1564,13 +1697,13 @@ WebhookController = _ts_decorate5([
|
|
|
1564
1697
|
// src/capability.module.ts
|
|
1565
1698
|
import { Module } from "@nestjs/common";
|
|
1566
1699
|
import { CommonModule, RequestContextService as RequestContextService2, HTTP_CLIENT_FACTORY as HTTP_CLIENT_FACTORY2 } from "@lark-apaas/nestjs-common";
|
|
1567
|
-
function
|
|
1700
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
1568
1701
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1569
1702
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1570
1703
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1571
1704
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1572
1705
|
}
|
|
1573
|
-
__name(
|
|
1706
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
1574
1707
|
var CAPABILITY_OPTIONS = /* @__PURE__ */ Symbol("CAPABILITY_OPTIONS");
|
|
1575
1708
|
var isDevelopment = process.env.NODE_ENV === "development";
|
|
1576
1709
|
function getControllers() {
|
|
@@ -1601,8 +1734,8 @@ var CapabilityModule = class _CapabilityModule {
|
|
|
1601
1734
|
},
|
|
1602
1735
|
{
|
|
1603
1736
|
provide: CapabilityService,
|
|
1604
|
-
useFactory: /* @__PURE__ */ __name((requestContextService, httpClientFactory, pluginLoader, templateEngine, moduleOptions) => {
|
|
1605
|
-
const service = new CapabilityService(requestContextService, httpClientFactory, pluginLoader, templateEngine);
|
|
1737
|
+
useFactory: /* @__PURE__ */ __name((requestContextService, httpClientFactory, pluginLoader, templateEngine, telemetryService, moduleOptions) => {
|
|
1738
|
+
const service = new CapabilityService(requestContextService, httpClientFactory, pluginLoader, templateEngine, telemetryService);
|
|
1606
1739
|
if (moduleOptions) {
|
|
1607
1740
|
service.setOptions(moduleOptions);
|
|
1608
1741
|
}
|
|
@@ -1613,19 +1746,22 @@ var CapabilityModule = class _CapabilityModule {
|
|
|
1613
1746
|
HTTP_CLIENT_FACTORY2,
|
|
1614
1747
|
PluginLoaderService,
|
|
1615
1748
|
TemplateEngineService,
|
|
1749
|
+
TelemetryService,
|
|
1616
1750
|
CAPABILITY_OPTIONS
|
|
1617
1751
|
]
|
|
1618
1752
|
},
|
|
1619
1753
|
PluginLoaderService,
|
|
1620
|
-
TemplateEngineService
|
|
1754
|
+
TemplateEngineService,
|
|
1755
|
+
TelemetryService
|
|
1621
1756
|
],
|
|
1622
1757
|
exports: [
|
|
1623
|
-
CapabilityService
|
|
1758
|
+
CapabilityService,
|
|
1759
|
+
TelemetryService
|
|
1624
1760
|
]
|
|
1625
1761
|
};
|
|
1626
1762
|
}
|
|
1627
1763
|
};
|
|
1628
|
-
CapabilityModule =
|
|
1764
|
+
CapabilityModule = _ts_decorate7([
|
|
1629
1765
|
Module({
|
|
1630
1766
|
imports: [
|
|
1631
1767
|
CommonModule
|
|
@@ -1634,10 +1770,12 @@ CapabilityModule = _ts_decorate6([
|
|
|
1634
1770
|
providers: [
|
|
1635
1771
|
CapabilityService,
|
|
1636
1772
|
PluginLoaderService,
|
|
1637
|
-
TemplateEngineService
|
|
1773
|
+
TemplateEngineService,
|
|
1774
|
+
TelemetryService
|
|
1638
1775
|
],
|
|
1639
1776
|
exports: [
|
|
1640
|
-
CapabilityService
|
|
1777
|
+
CapabilityService,
|
|
1778
|
+
TelemetryService
|
|
1641
1779
|
]
|
|
1642
1780
|
})
|
|
1643
1781
|
], CapabilityModule);
|
|
@@ -1651,6 +1789,7 @@ export {
|
|
|
1651
1789
|
PluginLoadError,
|
|
1652
1790
|
PluginLoaderService,
|
|
1653
1791
|
PluginNotFoundError,
|
|
1792
|
+
TelemetryService,
|
|
1654
1793
|
TemplateEngineService,
|
|
1655
1794
|
WebhookController,
|
|
1656
1795
|
migrationAdaptor
|