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