@lark-apaas/nestjs-capability 0.0.1-alpha.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/LICENSE +13 -0
- package/README.md +307 -0
- package/dist/index.cjs +658 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +156 -0
- package/dist/index.d.ts +156 -0
- package/dist/index.js +620 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,658 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/index.ts
|
|
32
|
+
var index_exports = {};
|
|
33
|
+
__export(index_exports, {
|
|
34
|
+
ActionNotFoundError: () => ActionNotFoundError,
|
|
35
|
+
CapabilityModule: () => CapabilityModule,
|
|
36
|
+
CapabilityNotFoundError: () => CapabilityNotFoundError,
|
|
37
|
+
CapabilityService: () => CapabilityService,
|
|
38
|
+
DebugController: () => DebugController,
|
|
39
|
+
PluginLoadError: () => PluginLoadError,
|
|
40
|
+
PluginLoaderService: () => PluginLoaderService,
|
|
41
|
+
PluginNotFoundError: () => PluginNotFoundError,
|
|
42
|
+
TemplateEngineService: () => TemplateEngineService,
|
|
43
|
+
WebhookController: () => WebhookController
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(index_exports);
|
|
46
|
+
|
|
47
|
+
// src/services/template-engine.service.ts
|
|
48
|
+
var import_common = require("@nestjs/common");
|
|
49
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
50
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
51
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
52
|
+
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;
|
|
53
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
54
|
+
}
|
|
55
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
56
|
+
var TemplateEngineService = class {
|
|
57
|
+
static {
|
|
58
|
+
__name(this, "TemplateEngineService");
|
|
59
|
+
}
|
|
60
|
+
TEMPLATE_REGEX = /^\{\{input\.(.+)\}\}$/;
|
|
61
|
+
resolve(template, input) {
|
|
62
|
+
if (typeof template === "string") {
|
|
63
|
+
return this.resolveString(template, input);
|
|
64
|
+
}
|
|
65
|
+
if (Array.isArray(template)) {
|
|
66
|
+
return template.map((item) => this.resolve(item, input));
|
|
67
|
+
}
|
|
68
|
+
if (template !== null && typeof template === "object") {
|
|
69
|
+
return this.resolveObject(template, input);
|
|
70
|
+
}
|
|
71
|
+
return template;
|
|
72
|
+
}
|
|
73
|
+
resolveString(template, input) {
|
|
74
|
+
const match = template.match(this.TEMPLATE_REGEX);
|
|
75
|
+
if (!match) {
|
|
76
|
+
return template;
|
|
77
|
+
}
|
|
78
|
+
const path2 = match[1];
|
|
79
|
+
return this.getValueByPath(input, path2);
|
|
80
|
+
}
|
|
81
|
+
resolveObject(template, input) {
|
|
82
|
+
const result = {};
|
|
83
|
+
for (const [key, value] of Object.entries(template)) {
|
|
84
|
+
result[key] = this.resolve(value, input);
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
getValueByPath(obj, path2) {
|
|
89
|
+
const keys = path2.split(".");
|
|
90
|
+
let current = obj;
|
|
91
|
+
for (const key of keys) {
|
|
92
|
+
if (current === null || current === void 0) {
|
|
93
|
+
return void 0;
|
|
94
|
+
}
|
|
95
|
+
current = current[key];
|
|
96
|
+
}
|
|
97
|
+
return current;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
TemplateEngineService = _ts_decorate([
|
|
101
|
+
(0, import_common.Injectable)()
|
|
102
|
+
], TemplateEngineService);
|
|
103
|
+
|
|
104
|
+
// src/services/plugin-loader.service.ts
|
|
105
|
+
var import_common2 = require("@nestjs/common");
|
|
106
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
107
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
108
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
109
|
+
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;
|
|
110
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
111
|
+
}
|
|
112
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
113
|
+
var PluginNotFoundError = class extends Error {
|
|
114
|
+
static {
|
|
115
|
+
__name(this, "PluginNotFoundError");
|
|
116
|
+
}
|
|
117
|
+
constructor(pluginID) {
|
|
118
|
+
super(`Plugin not found: ${pluginID}`);
|
|
119
|
+
this.name = "PluginNotFoundError";
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
var PluginLoadError = class extends Error {
|
|
123
|
+
static {
|
|
124
|
+
__name(this, "PluginLoadError");
|
|
125
|
+
}
|
|
126
|
+
constructor(pluginID, reason) {
|
|
127
|
+
super(`Failed to load plugin ${pluginID}: ${reason}`);
|
|
128
|
+
this.name = "PluginLoadError";
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
var PluginLoaderService = class _PluginLoaderService {
|
|
132
|
+
static {
|
|
133
|
+
__name(this, "PluginLoaderService");
|
|
134
|
+
}
|
|
135
|
+
logger = new import_common2.Logger(_PluginLoaderService.name);
|
|
136
|
+
pluginInstances = /* @__PURE__ */ new Map();
|
|
137
|
+
loadPlugin(pluginID) {
|
|
138
|
+
const cached = this.pluginInstances.get(pluginID);
|
|
139
|
+
if (cached) {
|
|
140
|
+
this.logger.debug(`Using cached plugin instance: ${pluginID}`);
|
|
141
|
+
return cached;
|
|
142
|
+
}
|
|
143
|
+
this.logger.log(`Loading plugin: ${pluginID}`);
|
|
144
|
+
try {
|
|
145
|
+
const pluginPackage = require(pluginID);
|
|
146
|
+
if (typeof pluginPackage.create !== "function") {
|
|
147
|
+
throw new PluginLoadError(pluginID, "Plugin does not export create() function");
|
|
148
|
+
}
|
|
149
|
+
const instance = pluginPackage.create();
|
|
150
|
+
this.pluginInstances.set(pluginID, instance);
|
|
151
|
+
this.logger.log(`Plugin loaded successfully: ${pluginID}`);
|
|
152
|
+
return instance;
|
|
153
|
+
} catch (error) {
|
|
154
|
+
if (error.code === "MODULE_NOT_FOUND") {
|
|
155
|
+
throw new PluginNotFoundError(pluginID);
|
|
156
|
+
}
|
|
157
|
+
throw new PluginLoadError(pluginID, error instanceof Error ? error.message : String(error));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
isPluginInstalled(pluginID) {
|
|
161
|
+
try {
|
|
162
|
+
require.resolve(pluginID);
|
|
163
|
+
return true;
|
|
164
|
+
} catch {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
clearCache(pluginID) {
|
|
169
|
+
if (pluginID) {
|
|
170
|
+
this.pluginInstances.delete(pluginID);
|
|
171
|
+
this.logger.log(`Cleared cache for plugin: ${pluginID}`);
|
|
172
|
+
} else {
|
|
173
|
+
this.pluginInstances.clear();
|
|
174
|
+
this.logger.log("Cleared all plugin caches");
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
PluginLoaderService = _ts_decorate2([
|
|
179
|
+
(0, import_common2.Injectable)()
|
|
180
|
+
], PluginLoaderService);
|
|
181
|
+
|
|
182
|
+
// src/services/capability.service.ts
|
|
183
|
+
var import_common3 = require("@nestjs/common");
|
|
184
|
+
var import_nestjs_common = require("@lark-apaas/nestjs-common");
|
|
185
|
+
var fs = __toESM(require("fs"), 1);
|
|
186
|
+
var path = __toESM(require("path"), 1);
|
|
187
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
188
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
189
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
190
|
+
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;
|
|
191
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
192
|
+
}
|
|
193
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
194
|
+
function _ts_metadata(k, v) {
|
|
195
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
196
|
+
}
|
|
197
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
198
|
+
function _ts_param(paramIndex, decorator) {
|
|
199
|
+
return function(target, key) {
|
|
200
|
+
decorator(target, key, paramIndex);
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
__name(_ts_param, "_ts_param");
|
|
204
|
+
var CapabilityNotFoundError = class extends Error {
|
|
205
|
+
static {
|
|
206
|
+
__name(this, "CapabilityNotFoundError");
|
|
207
|
+
}
|
|
208
|
+
constructor(capabilityId) {
|
|
209
|
+
super(`Capability not found: ${capabilityId}`);
|
|
210
|
+
this.name = "CapabilityNotFoundError";
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
var ActionNotFoundError = class extends Error {
|
|
214
|
+
static {
|
|
215
|
+
__name(this, "ActionNotFoundError");
|
|
216
|
+
}
|
|
217
|
+
constructor(pluginID, actionName) {
|
|
218
|
+
super(`Action '${actionName}' not found in plugin ${pluginID}`);
|
|
219
|
+
this.name = "ActionNotFoundError";
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
var CapabilityService = class _CapabilityService {
|
|
223
|
+
static {
|
|
224
|
+
__name(this, "CapabilityService");
|
|
225
|
+
}
|
|
226
|
+
requestContextService;
|
|
227
|
+
httpClient;
|
|
228
|
+
pluginLoaderService;
|
|
229
|
+
templateEngineService;
|
|
230
|
+
logger = new import_common3.Logger(_CapabilityService.name);
|
|
231
|
+
capabilities = /* @__PURE__ */ new Map();
|
|
232
|
+
capabilitiesDir;
|
|
233
|
+
constructor(requestContextService, httpClient, pluginLoaderService, templateEngineService) {
|
|
234
|
+
this.requestContextService = requestContextService;
|
|
235
|
+
this.httpClient = httpClient;
|
|
236
|
+
this.pluginLoaderService = pluginLoaderService;
|
|
237
|
+
this.templateEngineService = templateEngineService;
|
|
238
|
+
this.capabilitiesDir = path.join(process.cwd(), "server/capabilities");
|
|
239
|
+
}
|
|
240
|
+
setCapabilitiesDir(dir) {
|
|
241
|
+
this.capabilitiesDir = dir;
|
|
242
|
+
}
|
|
243
|
+
async onModuleInit() {
|
|
244
|
+
await this.loadCapabilities();
|
|
245
|
+
}
|
|
246
|
+
async loadCapabilities() {
|
|
247
|
+
this.logger.log(`Loading capabilities from ${this.capabilitiesDir}`);
|
|
248
|
+
if (!fs.existsSync(this.capabilitiesDir)) {
|
|
249
|
+
this.logger.warn(`Capabilities directory not found: ${this.capabilitiesDir}`);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const files = fs.readdirSync(this.capabilitiesDir).filter((f) => f.endsWith(".json"));
|
|
253
|
+
for (const file of files) {
|
|
254
|
+
try {
|
|
255
|
+
const filePath = path.join(this.capabilitiesDir, file);
|
|
256
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
257
|
+
const config = JSON.parse(content);
|
|
258
|
+
if (!config.id) {
|
|
259
|
+
this.logger.warn(`Skipping capability without id: ${file}`);
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
this.capabilities.set(config.id, config);
|
|
263
|
+
this.logger.log(`Loaded capability: ${config.id} (${config.name})`);
|
|
264
|
+
} catch (error) {
|
|
265
|
+
this.logger.error(`Failed to load capability from ${file}:`, error);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
this.logger.log(`Loaded ${this.capabilities.size} capabilities`);
|
|
269
|
+
}
|
|
270
|
+
listCapabilities() {
|
|
271
|
+
return Array.from(this.capabilities.values());
|
|
272
|
+
}
|
|
273
|
+
getCapability(capabilityId) {
|
|
274
|
+
return this.capabilities.get(capabilityId) ?? null;
|
|
275
|
+
}
|
|
276
|
+
load(capabilityId) {
|
|
277
|
+
const config = this.capabilities.get(capabilityId);
|
|
278
|
+
if (!config) {
|
|
279
|
+
throw new CapabilityNotFoundError(capabilityId);
|
|
280
|
+
}
|
|
281
|
+
return {
|
|
282
|
+
call: /* @__PURE__ */ __name(async (actionName, input, contextOverride) => {
|
|
283
|
+
return this.execute(config, actionName, input, contextOverride);
|
|
284
|
+
}, "call")
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
async execute(config, actionName, input, contextOverride) {
|
|
288
|
+
const startTime = Date.now();
|
|
289
|
+
try {
|
|
290
|
+
const pluginInstance = this.pluginLoaderService.loadPlugin(config.pluginID);
|
|
291
|
+
if (!pluginInstance.hasAction(actionName)) {
|
|
292
|
+
throw new ActionNotFoundError(config.pluginID, actionName);
|
|
293
|
+
}
|
|
294
|
+
const resolvedParams = this.templateEngineService.resolve(config.formValue, input);
|
|
295
|
+
const context = this.buildActionContext(contextOverride);
|
|
296
|
+
this.logger.log({
|
|
297
|
+
message: "Executing capability",
|
|
298
|
+
capabilityId: config.id,
|
|
299
|
+
action: actionName,
|
|
300
|
+
pluginID: config.pluginID
|
|
301
|
+
});
|
|
302
|
+
const result = await pluginInstance.run(actionName, context, resolvedParams);
|
|
303
|
+
this.logger.log({
|
|
304
|
+
message: "Capability executed successfully",
|
|
305
|
+
capabilityId: config.id,
|
|
306
|
+
action: actionName,
|
|
307
|
+
duration: Date.now() - startTime
|
|
308
|
+
});
|
|
309
|
+
return result;
|
|
310
|
+
} catch (error) {
|
|
311
|
+
this.logger.error({
|
|
312
|
+
message: "Capability execution failed",
|
|
313
|
+
capabilityId: config.id,
|
|
314
|
+
action: actionName,
|
|
315
|
+
error: error instanceof Error ? error.message : String(error),
|
|
316
|
+
duration: Date.now() - startTime
|
|
317
|
+
});
|
|
318
|
+
throw error;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
buildActionContext(override) {
|
|
322
|
+
return {
|
|
323
|
+
logger: this.logger,
|
|
324
|
+
httpClient: this.httpClient,
|
|
325
|
+
userContext: override?.userContext ?? this.getUserContext()
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
getUserContext() {
|
|
329
|
+
const ctx = this.requestContextService.getContext();
|
|
330
|
+
return {
|
|
331
|
+
userId: ctx?.userId ?? "",
|
|
332
|
+
tenantId: ctx?.tenantId ?? ""
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
CapabilityService = _ts_decorate3([
|
|
337
|
+
(0, import_common3.Injectable)(),
|
|
338
|
+
_ts_param(1, (0, import_common3.Inject)(import_nestjs_common.PLATFORM_HTTP_CLIENT)),
|
|
339
|
+
_ts_metadata("design:type", Function),
|
|
340
|
+
_ts_metadata("design:paramtypes", [
|
|
341
|
+
typeof import_nestjs_common.RequestContextService === "undefined" ? Object : import_nestjs_common.RequestContextService,
|
|
342
|
+
typeof PlatformHttpClient === "undefined" ? Object : PlatformHttpClient,
|
|
343
|
+
typeof PluginLoaderService === "undefined" ? Object : PluginLoaderService,
|
|
344
|
+
typeof TemplateEngineService === "undefined" ? Object : TemplateEngineService
|
|
345
|
+
])
|
|
346
|
+
], CapabilityService);
|
|
347
|
+
|
|
348
|
+
// src/controllers/debug.controller.ts
|
|
349
|
+
var import_common4 = require("@nestjs/common");
|
|
350
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
351
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
352
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
353
|
+
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;
|
|
354
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
355
|
+
}
|
|
356
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
357
|
+
function _ts_metadata2(k, v) {
|
|
358
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
359
|
+
}
|
|
360
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
361
|
+
function _ts_param2(paramIndex, decorator) {
|
|
362
|
+
return function(target, key) {
|
|
363
|
+
decorator(target, key, paramIndex);
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
__name(_ts_param2, "_ts_param");
|
|
367
|
+
var DebugController = class {
|
|
368
|
+
static {
|
|
369
|
+
__name(this, "DebugController");
|
|
370
|
+
}
|
|
371
|
+
capabilityService;
|
|
372
|
+
templateEngineService;
|
|
373
|
+
constructor(capabilityService, templateEngineService) {
|
|
374
|
+
this.capabilityService = capabilityService;
|
|
375
|
+
this.templateEngineService = templateEngineService;
|
|
376
|
+
}
|
|
377
|
+
list() {
|
|
378
|
+
const capabilities = this.capabilityService.listCapabilities();
|
|
379
|
+
return {
|
|
380
|
+
code: 0,
|
|
381
|
+
message: "success",
|
|
382
|
+
data: capabilities.map((c) => ({
|
|
383
|
+
id: c.id,
|
|
384
|
+
name: c.name,
|
|
385
|
+
pluginID: c.pluginID,
|
|
386
|
+
pluginVersion: c.pluginVersion
|
|
387
|
+
}))
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
async debug(capabilityId, body) {
|
|
391
|
+
const startTime = Date.now();
|
|
392
|
+
const config = this.capabilityService.getCapability(capabilityId);
|
|
393
|
+
if (!config) {
|
|
394
|
+
throw new import_common4.HttpException({
|
|
395
|
+
code: 1,
|
|
396
|
+
message: `Capability not found: ${capabilityId}`,
|
|
397
|
+
error: "CAPABILITY_NOT_FOUND"
|
|
398
|
+
}, import_common4.HttpStatus.NOT_FOUND);
|
|
399
|
+
}
|
|
400
|
+
const resolvedParams = this.templateEngineService.resolve(config.formValue, body.params);
|
|
401
|
+
try {
|
|
402
|
+
const result = await this.capabilityService.load(capabilityId).call(body.action, body.params);
|
|
403
|
+
return {
|
|
404
|
+
code: 0,
|
|
405
|
+
message: "success",
|
|
406
|
+
data: result,
|
|
407
|
+
debug: {
|
|
408
|
+
capabilityConfig: config,
|
|
409
|
+
resolvedParams,
|
|
410
|
+
duration: Date.now() - startTime,
|
|
411
|
+
pluginID: config.pluginID
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
} catch (error) {
|
|
415
|
+
const duration = Date.now() - startTime;
|
|
416
|
+
if (error instanceof CapabilityNotFoundError) {
|
|
417
|
+
throw new import_common4.HttpException({
|
|
418
|
+
code: 1,
|
|
419
|
+
message: error.message,
|
|
420
|
+
error: "CAPABILITY_NOT_FOUND",
|
|
421
|
+
debug: {
|
|
422
|
+
duration
|
|
423
|
+
}
|
|
424
|
+
}, import_common4.HttpStatus.NOT_FOUND);
|
|
425
|
+
}
|
|
426
|
+
if (error instanceof PluginNotFoundError) {
|
|
427
|
+
throw new import_common4.HttpException({
|
|
428
|
+
code: 1,
|
|
429
|
+
message: error.message,
|
|
430
|
+
error: "PLUGIN_NOT_FOUND",
|
|
431
|
+
debug: {
|
|
432
|
+
duration,
|
|
433
|
+
pluginID: config.pluginID
|
|
434
|
+
}
|
|
435
|
+
}, import_common4.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
436
|
+
}
|
|
437
|
+
if (error instanceof ActionNotFoundError) {
|
|
438
|
+
throw new import_common4.HttpException({
|
|
439
|
+
code: 1,
|
|
440
|
+
message: error.message,
|
|
441
|
+
error: "ACTION_NOT_FOUND",
|
|
442
|
+
debug: {
|
|
443
|
+
duration,
|
|
444
|
+
pluginID: config.pluginID
|
|
445
|
+
}
|
|
446
|
+
}, import_common4.HttpStatus.BAD_REQUEST);
|
|
447
|
+
}
|
|
448
|
+
throw new import_common4.HttpException({
|
|
449
|
+
code: 1,
|
|
450
|
+
message: error instanceof Error ? error.message : String(error),
|
|
451
|
+
error: "EXECUTION_ERROR",
|
|
452
|
+
debug: {
|
|
453
|
+
duration,
|
|
454
|
+
pluginID: config.pluginID,
|
|
455
|
+
resolvedParams
|
|
456
|
+
}
|
|
457
|
+
}, import_common4.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
_ts_decorate4([
|
|
462
|
+
(0, import_common4.Get)("list"),
|
|
463
|
+
_ts_metadata2("design:type", Function),
|
|
464
|
+
_ts_metadata2("design:paramtypes", []),
|
|
465
|
+
_ts_metadata2("design:returntype", typeof ListResponse === "undefined" ? Object : ListResponse)
|
|
466
|
+
], DebugController.prototype, "list", null);
|
|
467
|
+
_ts_decorate4([
|
|
468
|
+
(0, import_common4.Post)("debug/:capability_id"),
|
|
469
|
+
_ts_param2(0, (0, import_common4.Param)("capability_id")),
|
|
470
|
+
_ts_param2(1, (0, import_common4.Body)()),
|
|
471
|
+
_ts_metadata2("design:type", Function),
|
|
472
|
+
_ts_metadata2("design:paramtypes", [
|
|
473
|
+
String,
|
|
474
|
+
typeof ExecuteRequestBody === "undefined" ? Object : ExecuteRequestBody
|
|
475
|
+
]),
|
|
476
|
+
_ts_metadata2("design:returntype", Promise)
|
|
477
|
+
], DebugController.prototype, "debug", null);
|
|
478
|
+
DebugController = _ts_decorate4([
|
|
479
|
+
(0, import_common4.Controller)("__innerapi__/capability"),
|
|
480
|
+
_ts_metadata2("design:type", Function),
|
|
481
|
+
_ts_metadata2("design:paramtypes", [
|
|
482
|
+
typeof CapabilityService === "undefined" ? Object : CapabilityService,
|
|
483
|
+
typeof TemplateEngineService === "undefined" ? Object : TemplateEngineService
|
|
484
|
+
])
|
|
485
|
+
], DebugController);
|
|
486
|
+
|
|
487
|
+
// src/controllers/webhook.controller.ts
|
|
488
|
+
var import_common5 = require("@nestjs/common");
|
|
489
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
490
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
491
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
492
|
+
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;
|
|
493
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
494
|
+
}
|
|
495
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
496
|
+
function _ts_metadata3(k, v) {
|
|
497
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
498
|
+
}
|
|
499
|
+
__name(_ts_metadata3, "_ts_metadata");
|
|
500
|
+
function _ts_param3(paramIndex, decorator) {
|
|
501
|
+
return function(target, key) {
|
|
502
|
+
decorator(target, key, paramIndex);
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
__name(_ts_param3, "_ts_param");
|
|
506
|
+
var WebhookController = class {
|
|
507
|
+
static {
|
|
508
|
+
__name(this, "WebhookController");
|
|
509
|
+
}
|
|
510
|
+
capabilityService;
|
|
511
|
+
constructor(capabilityService) {
|
|
512
|
+
this.capabilityService = capabilityService;
|
|
513
|
+
}
|
|
514
|
+
async execute(capabilityId, body) {
|
|
515
|
+
try {
|
|
516
|
+
const result = await this.capabilityService.load(capabilityId).call(body.action, body.params);
|
|
517
|
+
return {
|
|
518
|
+
code: 0,
|
|
519
|
+
message: "success",
|
|
520
|
+
data: result
|
|
521
|
+
};
|
|
522
|
+
} catch (error) {
|
|
523
|
+
if (error instanceof CapabilityNotFoundError) {
|
|
524
|
+
throw new import_common5.HttpException({
|
|
525
|
+
code: 1,
|
|
526
|
+
message: error.message,
|
|
527
|
+
error: "CAPABILITY_NOT_FOUND"
|
|
528
|
+
}, import_common5.HttpStatus.NOT_FOUND);
|
|
529
|
+
}
|
|
530
|
+
if (error instanceof PluginNotFoundError) {
|
|
531
|
+
throw new import_common5.HttpException({
|
|
532
|
+
code: 1,
|
|
533
|
+
message: error.message,
|
|
534
|
+
error: "PLUGIN_NOT_FOUND"
|
|
535
|
+
}, import_common5.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
536
|
+
}
|
|
537
|
+
if (error instanceof ActionNotFoundError) {
|
|
538
|
+
throw new import_common5.HttpException({
|
|
539
|
+
code: 1,
|
|
540
|
+
message: error.message,
|
|
541
|
+
error: "ACTION_NOT_FOUND"
|
|
542
|
+
}, import_common5.HttpStatus.BAD_REQUEST);
|
|
543
|
+
}
|
|
544
|
+
throw new import_common5.HttpException({
|
|
545
|
+
code: 1,
|
|
546
|
+
message: error instanceof Error ? error.message : String(error),
|
|
547
|
+
error: "EXECUTION_ERROR"
|
|
548
|
+
}, import_common5.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
_ts_decorate5([
|
|
553
|
+
(0, import_common5.Post)(":capability_id"),
|
|
554
|
+
_ts_param3(0, (0, import_common5.Param)("capability_id")),
|
|
555
|
+
_ts_param3(1, (0, import_common5.Body)()),
|
|
556
|
+
_ts_metadata3("design:type", Function),
|
|
557
|
+
_ts_metadata3("design:paramtypes", [
|
|
558
|
+
String,
|
|
559
|
+
typeof ExecuteRequestBody === "undefined" ? Object : ExecuteRequestBody
|
|
560
|
+
]),
|
|
561
|
+
_ts_metadata3("design:returntype", Promise)
|
|
562
|
+
], WebhookController.prototype, "execute", null);
|
|
563
|
+
WebhookController = _ts_decorate5([
|
|
564
|
+
(0, import_common5.Controller)("api/capability"),
|
|
565
|
+
_ts_metadata3("design:type", Function),
|
|
566
|
+
_ts_metadata3("design:paramtypes", [
|
|
567
|
+
typeof CapabilityService === "undefined" ? Object : CapabilityService
|
|
568
|
+
])
|
|
569
|
+
], WebhookController);
|
|
570
|
+
|
|
571
|
+
// src/capability.module.ts
|
|
572
|
+
var import_common6 = require("@nestjs/common");
|
|
573
|
+
var import_nestjs_common2 = require("@lark-apaas/nestjs-common");
|
|
574
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
575
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
576
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
577
|
+
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;
|
|
578
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
579
|
+
}
|
|
580
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
581
|
+
var CAPABILITY_OPTIONS = /* @__PURE__ */ Symbol("CAPABILITY_OPTIONS");
|
|
582
|
+
var isDevelopment = process.env.NODE_ENV === "development";
|
|
583
|
+
function getControllers() {
|
|
584
|
+
const controllers = [
|
|
585
|
+
WebhookController
|
|
586
|
+
];
|
|
587
|
+
if (isDevelopment) {
|
|
588
|
+
controllers.push(DebugController);
|
|
589
|
+
}
|
|
590
|
+
return controllers;
|
|
591
|
+
}
|
|
592
|
+
__name(getControllers, "getControllers");
|
|
593
|
+
var CapabilityModule = class _CapabilityModule {
|
|
594
|
+
static {
|
|
595
|
+
__name(this, "CapabilityModule");
|
|
596
|
+
}
|
|
597
|
+
static forRoot(options) {
|
|
598
|
+
return {
|
|
599
|
+
module: _CapabilityModule,
|
|
600
|
+
controllers: getControllers(),
|
|
601
|
+
providers: [
|
|
602
|
+
{
|
|
603
|
+
provide: CAPABILITY_OPTIONS,
|
|
604
|
+
useValue: options ?? {}
|
|
605
|
+
},
|
|
606
|
+
{
|
|
607
|
+
provide: CapabilityService,
|
|
608
|
+
useFactory: /* @__PURE__ */ __name((requestContextService, httpClient, pluginLoader, templateEngine, moduleOptions) => {
|
|
609
|
+
const service = new CapabilityService(requestContextService, httpClient, pluginLoader, templateEngine);
|
|
610
|
+
if (moduleOptions?.capabilitiesDir) {
|
|
611
|
+
service.setCapabilitiesDir(moduleOptions.capabilitiesDir);
|
|
612
|
+
}
|
|
613
|
+
return service;
|
|
614
|
+
}, "useFactory"),
|
|
615
|
+
inject: [
|
|
616
|
+
import_nestjs_common2.RequestContextService,
|
|
617
|
+
import_nestjs_common2.PLATFORM_HTTP_CLIENT,
|
|
618
|
+
PluginLoaderService,
|
|
619
|
+
TemplateEngineService,
|
|
620
|
+
CAPABILITY_OPTIONS
|
|
621
|
+
]
|
|
622
|
+
},
|
|
623
|
+
PluginLoaderService,
|
|
624
|
+
TemplateEngineService
|
|
625
|
+
],
|
|
626
|
+
exports: [
|
|
627
|
+
CapabilityService
|
|
628
|
+
]
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
CapabilityModule = _ts_decorate6([
|
|
633
|
+
(0, import_common6.Module)({
|
|
634
|
+
controllers: getControllers(),
|
|
635
|
+
providers: [
|
|
636
|
+
CapabilityService,
|
|
637
|
+
PluginLoaderService,
|
|
638
|
+
TemplateEngineService
|
|
639
|
+
],
|
|
640
|
+
exports: [
|
|
641
|
+
CapabilityService
|
|
642
|
+
]
|
|
643
|
+
})
|
|
644
|
+
], CapabilityModule);
|
|
645
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
646
|
+
0 && (module.exports = {
|
|
647
|
+
ActionNotFoundError,
|
|
648
|
+
CapabilityModule,
|
|
649
|
+
CapabilityNotFoundError,
|
|
650
|
+
CapabilityService,
|
|
651
|
+
DebugController,
|
|
652
|
+
PluginLoadError,
|
|
653
|
+
PluginLoaderService,
|
|
654
|
+
PluginNotFoundError,
|
|
655
|
+
TemplateEngineService,
|
|
656
|
+
WebhookController
|
|
657
|
+
});
|
|
658
|
+
//# sourceMappingURL=index.cjs.map
|