@ruiapp/rapid-core 0.1.4 → 0.1.6
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/bootstrapApplicationConfig.d.ts +1 -1
- package/dist/core/actionHandler.d.ts +17 -0
- package/dist/core/pluginManager.d.ts +31 -26
- package/dist/core/server.d.ts +24 -24
- package/dist/helpers/runCollectionEntityActionHandler.d.ts +5 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +3335 -3279
- package/dist/plugins/auth/actionHandlers/createSession.d.ts +8 -0
- package/dist/plugins/auth/actionHandlers/deleteSession.d.ts +4 -0
- package/dist/plugins/auth/actionHandlers/getMyProfile.d.ts +4 -0
- package/dist/plugins/auth/mod.d.ts +25 -0
- package/dist/plugins/{authManager → auth}/routes/getMyProfile.d.ts +1 -1
- package/dist/plugins/{authManager → auth}/routes/signin.d.ts +1 -1
- package/dist/plugins/{authManager → auth}/routes/signout.d.ts +1 -1
- package/dist/plugins/dataManage/actionHandlers/addEntityRelations.d.ts +5 -0
- package/dist/plugins/dataManage/actionHandlers/countCollectionEntities.d.ts +5 -0
- package/dist/plugins/dataManage/actionHandlers/createCollectionEntitiesBatch.d.ts +5 -0
- package/dist/plugins/dataManage/actionHandlers/createCollectionEntity.d.ts +5 -0
- package/dist/plugins/dataManage/actionHandlers/deleteCollectionEntityById.d.ts +5 -0
- package/dist/plugins/dataManage/actionHandlers/findCollectionEntities.d.ts +5 -0
- package/dist/plugins/dataManage/actionHandlers/findCollectionEntityById.d.ts +5 -0
- package/dist/plugins/dataManage/actionHandlers/queryDatabase.d.ts +5 -0
- package/dist/plugins/dataManage/actionHandlers/removeEntityRelations.d.ts +5 -0
- package/dist/plugins/dataManage/actionHandlers/updateCollectionEntityById.d.ts +5 -0
- package/dist/plugins/dataManage/mod.d.ts +27 -0
- package/dist/plugins/fileManage/actionHandlers/downloadDocument.d.ts +4 -0
- package/dist/plugins/fileManage/actionHandlers/downloadFile.d.ts +4 -0
- package/dist/plugins/fileManage/actionHandlers/uploadFile.d.ts +4 -0
- package/dist/plugins/fileManage/mod.d.ts +25 -0
- package/dist/plugins/metaManage/actionHandlers/getMetaModelDetail.d.ts +4 -0
- package/dist/plugins/metaManage/actionHandlers/listMetaModels.d.ts +4 -0
- package/dist/plugins/metaManage/actionHandlers/listMetaRoutes.d.ts +4 -0
- package/dist/plugins/metaManage/mod.d.ts +25 -0
- package/dist/plugins/routeManage/actionHandlers/httpProxy.d.ts +5 -0
- package/dist/plugins/routeManage/mod.d.ts +25 -0
- package/dist/plugins/webhooks/mod.d.ts +25 -11
- package/dist/server.d.ts +7 -6
- package/dist/types.d.ts +10 -12
- package/package.json +1 -1
- package/src/bootstrapApplicationConfig.ts +6 -6
- package/src/core/actionHandler.ts +23 -0
- package/src/core/pluginManager.ts +107 -108
- package/src/core/routesBuilder.ts +4 -4
- package/src/core/server.ts +26 -44
- package/src/dataAccess/dataAccessor.ts +1 -1
- package/src/helpers/{runCollectionEntityHttpHandler.ts → runCollectionEntityActionHandler.ts} +5 -5
- package/src/index.ts +9 -0
- package/src/plugins/{authManager/httpHandlers → auth/actionHandlers}/createSession.ts +4 -4
- package/src/plugins/{authManager/httpHandlers → auth/actionHandlers}/deleteSession.ts +4 -4
- package/src/plugins/{authManager/httpHandlers → auth/actionHandlers}/getMyProfile.ts +4 -4
- package/src/plugins/{authManager/httpHandlers → auth/actionHandlers}/index.ts +2 -2
- package/src/plugins/auth/mod.ts +80 -0
- package/src/plugins/{authManager → auth}/routes/getMyProfile.ts +1 -1
- package/src/plugins/{authManager → auth}/routes/signin.ts +1 -1
- package/src/plugins/{authManager → auth}/routes/signout.ts +1 -1
- package/src/plugins/{dataManager/httpHandlers → dataManage/actionHandlers}/addEntityRelations.ts +6 -5
- package/src/plugins/dataManage/actionHandlers/countCollectionEntities.ts +23 -0
- package/src/plugins/{dataManager/httpHandlers → dataManage/actionHandlers}/createCollectionEntitiesBatch.ts +6 -5
- package/src/plugins/{dataManager/httpHandlers → dataManage/actionHandlers}/createCollectionEntity.ts +6 -5
- package/src/plugins/{dataManager/httpHandlers → dataManage/actionHandlers}/deleteCollectionEntityById.ts +8 -7
- package/src/plugins/{dataManager/httpHandlers → dataManage/actionHandlers}/findCollectionEntities.ts +8 -7
- package/src/plugins/{dataManager/httpHandlers → dataManage/actionHandlers}/findCollectionEntityById.ts +6 -5
- package/src/plugins/{dataManager/httpHandlers → dataManage/actionHandlers}/queryDatabase.ts +5 -4
- package/src/plugins/{dataManager/httpHandlers → dataManage/actionHandlers}/removeEntityRelations.ts +6 -5
- package/src/plugins/{dataManager/httpHandlers → dataManage/actionHandlers}/updateCollectionEntityById.ts +6 -5
- package/src/plugins/dataManage/mod.ts +187 -0
- package/src/plugins/{fileManager/httpHandlers → fileManage/actionHandlers}/downloadDocument.ts +4 -4
- package/src/plugins/{fileManager/httpHandlers → fileManage/actionHandlers}/downloadFile.ts +4 -4
- package/src/plugins/{fileManager/httpHandlers → fileManage/actionHandlers}/uploadFile.ts +5 -5
- package/src/plugins/fileManage/mod.ts +77 -0
- package/src/plugins/{metaManager/httpHandlers → metaManage/actionHandlers}/getMetaModelDetail.ts +4 -4
- package/src/plugins/{metaManager/httpHandlers → metaManage/actionHandlers}/listMetaModels.ts +4 -4
- package/src/plugins/{routeManager/httpHandlers → metaManage/actionHandlers}/listMetaRoutes.ts +4 -4
- package/src/plugins/{metaManager → metaManage}/mod.ts +88 -55
- package/src/plugins/{routeManager/httpHandlers → routeManage/actionHandlers}/httpProxy.ts +5 -4
- package/src/plugins/routeManage/mod.ts +92 -0
- package/src/plugins/webhooks/mod.ts +134 -94
- package/src/server.ts +28 -21
- package/src/types.ts +11 -14
- package/dist/core/httpHandler.d.ts +0 -18
- package/dist/core/plugin.d.ts +0 -6
- package/dist/helpers/runCollectionEntityHttpHandler.d.ts +0 -5
- package/dist/plugins/authManager/httpHandlers/createSession.d.ts +0 -8
- package/dist/plugins/authManager/httpHandlers/deleteSession.d.ts +0 -4
- package/dist/plugins/authManager/httpHandlers/getMyProfile.d.ts +0 -4
- package/dist/plugins/authManager/mod.d.ts +0 -16
- package/dist/plugins/dataManager/httpHandlers/addEntityRelations.d.ts +0 -4
- package/dist/plugins/dataManager/httpHandlers/countCollectionEntities.d.ts +0 -4
- package/dist/plugins/dataManager/httpHandlers/createCollectionEntitiesBatch.d.ts +0 -4
- package/dist/plugins/dataManager/httpHandlers/createCollectionEntity.d.ts +0 -4
- package/dist/plugins/dataManager/httpHandlers/deleteCollectionEntityById.d.ts +0 -4
- package/dist/plugins/dataManager/httpHandlers/findCollectionEntities.d.ts +0 -4
- package/dist/plugins/dataManager/httpHandlers/findCollectionEntityById.d.ts +0 -4
- package/dist/plugins/dataManager/httpHandlers/queryDatabase.d.ts +0 -4
- package/dist/plugins/dataManager/httpHandlers/removeEntityRelations.d.ts +0 -4
- package/dist/plugins/dataManager/httpHandlers/updateCollectionEntityById.d.ts +0 -4
- package/dist/plugins/dataManager/mod.d.ts +0 -16
- package/dist/plugins/fileManager/httpHandlers/downloadDocument.d.ts +0 -4
- package/dist/plugins/fileManager/httpHandlers/downloadFile.d.ts +0 -4
- package/dist/plugins/fileManager/httpHandlers/uploadFile.d.ts +0 -4
- package/dist/plugins/fileManager/mod.d.ts +0 -15
- package/dist/plugins/metaManager/httpHandlers/getMetaModelDetail.d.ts +0 -4
- package/dist/plugins/metaManager/httpHandlers/listMetaModels.d.ts +0 -4
- package/dist/plugins/metaManager/mod.d.ts +0 -15
- package/dist/plugins/routeManager/httpHandlers/httpProxy.d.ts +0 -4
- package/dist/plugins/routeManager/httpHandlers/listMetaRoutes.d.ts +0 -4
- package/dist/plugins/routeManager/mod.d.ts +0 -15
- package/src/core/httpHandler.ts +0 -29
- package/src/core/plugin.ts +0 -13
- package/src/plugins/authManager/mod.ts +0 -56
- package/src/plugins/dataManager/httpHandlers/countCollectionEntities.ts +0 -22
- package/src/plugins/dataManager/mod.ts +0 -154
- package/src/plugins/fileManager/mod.ts +0 -48
- package/src/plugins/routeManager/mod.ts +0 -97
- /package/dist/plugins/{authManager/httpHandlers → auth/actionHandlers}/index.d.ts +0 -0
- /package/dist/plugins/{authManager → auth}/models/AccessToken.d.ts +0 -0
- /package/dist/plugins/{authManager → auth}/models/index.d.ts +0 -0
- /package/dist/plugins/{authManager → auth}/routes/index.d.ts +0 -0
- /package/src/plugins/{authManager → auth}/models/AccessToken.ts +0 -0
- /package/src/plugins/{authManager → auth}/models/index.ts +0 -0
- /package/src/plugins/{authManager → auth}/routes/index.ts +0 -0
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
import * as _ from "lodash";
|
|
6
6
|
import { findEntities } from "~/dataAccess/entityManager";
|
|
7
7
|
import {
|
|
8
|
-
IPluginInstance,
|
|
9
8
|
IQueryBuilder,
|
|
10
9
|
QuoteTableOptions,
|
|
11
10
|
RpdApplicationConfig,
|
|
@@ -16,50 +15,103 @@ import {
|
|
|
16
15
|
RpdEntityDeleteEventPayload,
|
|
17
16
|
RpdEntityUpdateEventPayload,
|
|
18
17
|
} from "~/types";
|
|
19
|
-
import { IRpdServer, RpdConfigurationItemOptions, RpdServerPluginConfigurableTargetOptions, RpdServerPluginExtendingAbilities } from "~/core/server";
|
|
18
|
+
import { IRpdServer, RapidPlugin, RpdConfigurationItemOptions, RpdServerPluginConfigurableTargetOptions, RpdServerPluginExtendingAbilities } from "~/core/server";
|
|
20
19
|
|
|
21
|
-
import * as listMetaModels from "./
|
|
22
|
-
import * as
|
|
20
|
+
import * as listMetaModels from "./actionHandlers/listMetaModels";
|
|
21
|
+
import * as listMetaRoutes from "./actionHandlers/listMetaRoutes";
|
|
22
|
+
import * as getMetaModelDetail from "./actionHandlers/getMetaModelDetail";
|
|
23
23
|
import { isRelationProperty } from "~/utilities/rapidUtility";
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
export const configurations: RpdConfigurationItemOptions[] = [];
|
|
25
|
+
class MetaManager implements RapidPlugin {
|
|
26
|
+
get code(): string {
|
|
27
|
+
return "metaManager";
|
|
28
|
+
}
|
|
30
29
|
|
|
31
|
-
|
|
30
|
+
get description(): string {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
34
|
+
get extendingAbilities(): RpdServerPluginExtendingAbilities[] {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
get configurableTargets(): RpdServerPluginConfigurableTargetOptions[] {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get configurations(): RpdConfigurationItemOptions[] {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async initPlugin(server: IRpdServer): Promise<any> {
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async registerMiddlewares(server: IRpdServer): Promise<any> {
|
|
50
|
+
}
|
|
41
51
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
async registerActionHandlers(server: IRpdServer): Promise<any> {
|
|
53
|
+
server.registerActionHandler(this, listMetaModels);
|
|
54
|
+
server.registerActionHandler(this, listMetaRoutes);
|
|
55
|
+
server.registerActionHandler(this, getMetaModelDetail);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async registerEventHandlers(server: IRpdServer): Promise<any> {
|
|
59
|
+
server.registerEventHandler(
|
|
60
|
+
"entity.create",
|
|
61
|
+
handleEntityCreateEvent.bind(this, server),
|
|
62
|
+
);
|
|
63
|
+
server.registerEventHandler(
|
|
64
|
+
"entity.update",
|
|
65
|
+
handleEntityUpdateEvent.bind(this, server),
|
|
66
|
+
);
|
|
67
|
+
server.registerEventHandler(
|
|
68
|
+
"entity.delete",
|
|
69
|
+
handleEntityDeleteEvent.bind(this, server),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async registerMessageHandlers(server: IRpdServer): Promise<any> {
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async registerTaskProcessors(server: IRpdServer): Promise<any> {
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async onLoadingApplication(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
83
|
+
try {
|
|
84
|
+
const models: RpdDataModel[] = await listCollections(server, applicationConfig);
|
|
85
|
+
server.appendApplicationConfig({ models });
|
|
86
|
+
} catch (ex) {
|
|
87
|
+
console.warn("Failed to loading existing meta of models.", ex);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async configureModelProperties(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
98
|
+
console.log("metaManager.onApplicationLoaded");
|
|
99
|
+
await syncDatabaseSchema(server, applicationConfig);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async onApplicationReady(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
103
|
+
}
|
|
55
104
|
}
|
|
56
105
|
|
|
106
|
+
export default MetaManager;
|
|
107
|
+
|
|
108
|
+
|
|
57
109
|
async function handleEntityCreateEvent(
|
|
58
110
|
server: IRpdServer,
|
|
59
|
-
sender:
|
|
111
|
+
sender: RapidPlugin,
|
|
60
112
|
payload: RpdEntityCreateEventPayload,
|
|
61
113
|
) {
|
|
62
|
-
if (sender ===
|
|
114
|
+
if (sender === this) {
|
|
63
115
|
return;
|
|
64
116
|
}
|
|
65
117
|
|
|
@@ -79,10 +131,10 @@ async function handleEntityCreateEvent(
|
|
|
79
131
|
|
|
80
132
|
async function handleEntityUpdateEvent(
|
|
81
133
|
server: IRpdServer,
|
|
82
|
-
sender:
|
|
134
|
+
sender: RapidPlugin,
|
|
83
135
|
payload: RpdEntityUpdateEventPayload,
|
|
84
136
|
) {
|
|
85
|
-
if (sender ===
|
|
137
|
+
if (sender === this) {
|
|
86
138
|
return;
|
|
87
139
|
}
|
|
88
140
|
|
|
@@ -102,10 +154,10 @@ async function handleEntityUpdateEvent(
|
|
|
102
154
|
|
|
103
155
|
async function handleEntityDeleteEvent(
|
|
104
156
|
server: IRpdServer,
|
|
105
|
-
sender:
|
|
157
|
+
sender: RapidPlugin,
|
|
106
158
|
payload: RpdEntityDeleteEventPayload,
|
|
107
159
|
) {
|
|
108
|
-
if (sender ===
|
|
160
|
+
if (sender === this) {
|
|
109
161
|
return;
|
|
110
162
|
}
|
|
111
163
|
|
|
@@ -150,18 +202,6 @@ async function handleEntityDeleteEvent(
|
|
|
150
202
|
}
|
|
151
203
|
}
|
|
152
204
|
|
|
153
|
-
export async function configureModels(
|
|
154
|
-
server: IRpdServer,
|
|
155
|
-
applicationConfig: RpdApplicationConfig,
|
|
156
|
-
) {
|
|
157
|
-
try {
|
|
158
|
-
const models: RpdDataModel[] = await listCollections(server, applicationConfig);
|
|
159
|
-
server.appendApplicationConfig({ models });
|
|
160
|
-
} catch (ex) {
|
|
161
|
-
console.warn("Failed to loading existing meta of models.", ex);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
205
|
function listCollections(
|
|
166
206
|
server: IRpdServer,
|
|
167
207
|
applicationConfig: RpdApplicationConfig,
|
|
@@ -177,13 +217,6 @@ function listCollections(
|
|
|
177
217
|
});
|
|
178
218
|
}
|
|
179
219
|
|
|
180
|
-
export async function onApplicationLoaded(
|
|
181
|
-
server: IRpdServer,
|
|
182
|
-
applicationConfig: RpdApplicationConfig,
|
|
183
|
-
) {
|
|
184
|
-
console.log("metaManager.onApplicationLoaded");
|
|
185
|
-
await syncDatabaseSchema(server, applicationConfig);
|
|
186
|
-
}
|
|
187
220
|
|
|
188
221
|
type TableInformation = {
|
|
189
222
|
table_schema: string;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RunProxyHandlerOptions } from "~/types";
|
|
2
2
|
import { doProxy } from "~/proxy/mod";
|
|
3
|
-
import {
|
|
3
|
+
import { ActionHandlerContext } from "~/core/actionHandler";
|
|
4
|
+
import { RapidPlugin } from "~/core/server";
|
|
4
5
|
|
|
5
6
|
export const code = "httpProxy";
|
|
6
7
|
|
|
7
8
|
export async function handler(
|
|
8
|
-
plugin:
|
|
9
|
-
ctx:
|
|
9
|
+
plugin: RapidPlugin,
|
|
10
|
+
ctx: ActionHandlerContext,
|
|
10
11
|
options: RunProxyHandlerOptions,
|
|
11
12
|
) {
|
|
12
13
|
console.debug(`Running ${code} handler...`);
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route manager plugin
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
RpdApplicationConfig,
|
|
7
|
+
} from "~/types";
|
|
8
|
+
import { RpdServerPluginExtendingAbilities, RpdServerPluginConfigurableTargetOptions, RpdConfigurationItemOptions, IRpdServer, RapidPlugin } from "~/core/server";
|
|
9
|
+
import { findEntities } from "../../dataAccess/entityManager";
|
|
10
|
+
import * as httpProxy from "./actionHandlers/httpProxy";
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class RouteManager implements RapidPlugin {
|
|
14
|
+
get code(): string {
|
|
15
|
+
return "routeManager";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get description(): string {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get extendingAbilities(): RpdServerPluginExtendingAbilities[] {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get configurableTargets(): RpdServerPluginConfigurableTargetOptions[] {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get configurations(): RpdConfigurationItemOptions[] {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async initPlugin(server: IRpdServer): Promise<any> {
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async registerMiddlewares(server: IRpdServer): Promise<any> {
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async registerActionHandlers(server: IRpdServer): Promise<any> {
|
|
41
|
+
server.registerActionHandler(this, httpProxy);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async registerEventHandlers(server: IRpdServer): Promise<any> {
|
|
45
|
+
// TODO: Should rebuild routes after route configurations changed.
|
|
46
|
+
// server.registerEventHandler("entity.create", handleEntityEvent.bind(null, server))
|
|
47
|
+
// server.registerEventHandler("entity.update", handleEntityEvent.bind(null, server))
|
|
48
|
+
// server.registerEventHandler("entity.delete", handleEntityEvent.bind(null, server))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async registerMessageHandlers(server: IRpdServer): Promise<any> {
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async registerTaskProcessors(server: IRpdServer): Promise<any> {
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async onLoadingApplication(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async configureModelProperties(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
67
|
+
try {
|
|
68
|
+
const dataAccessor = server.getDataAccessor({
|
|
69
|
+
namespace: "meta",
|
|
70
|
+
singularCode: "route",
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const routes = await findEntities(server, dataAccessor, {
|
|
74
|
+
orderBy: [
|
|
75
|
+
{ field: "endpoint" },
|
|
76
|
+
],
|
|
77
|
+
});
|
|
78
|
+
applicationConfig.routes.push(...routes);
|
|
79
|
+
} catch (ex) {
|
|
80
|
+
console.warn("Failed to loading existing meta of routes.", ex.message);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
85
|
+
console.log("[routeManager.onApplicationLoaded] onApplicationLoaded");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async onApplicationReady(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export default RouteManager;
|
|
@@ -4,23 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
import * as _ from "lodash";
|
|
6
6
|
import {
|
|
7
|
-
IPluginInstance,
|
|
8
7
|
RpdApplicationConfig,
|
|
9
8
|
RpdEntityCreateEventPayload,
|
|
10
9
|
RpdEntityDeleteEventPayload,
|
|
11
10
|
RpdEntityUpdateEventPayload,
|
|
12
11
|
RpdServerEventTypes,
|
|
13
12
|
} from "~/types";
|
|
14
|
-
import { RpdServerPluginExtendingAbilities, RpdServerPluginConfigurableTargetOptions, RpdConfigurationItemOptions, IRpdServer } from "~/core/server";
|
|
13
|
+
import { RpdServerPluginExtendingAbilities, RpdServerPluginConfigurableTargetOptions, RpdConfigurationItemOptions, IRpdServer, RapidPlugin } from "~/core/server";
|
|
15
14
|
import { fetchWithTimeout } from "~/utilities/httpUtility";
|
|
16
15
|
import { findEntities } from "~/dataAccess/entityManager";
|
|
17
16
|
import pluginConfig from "./pluginConfig";
|
|
18
17
|
|
|
19
|
-
export const code = "webhooks";
|
|
20
|
-
export const description = "webhooks";
|
|
21
|
-
export const extendingAbilities: RpdServerPluginExtendingAbilities[] = [];
|
|
22
|
-
export const configurableTargets: RpdServerPluginConfigurableTargetOptions[] = [];
|
|
23
|
-
export const configurations: RpdConfigurationItemOptions[] = [];
|
|
24
18
|
|
|
25
19
|
export interface Webhook {
|
|
26
20
|
name: string;
|
|
@@ -33,112 +27,158 @@ export interface Webhook {
|
|
|
33
27
|
enabled: boolean;
|
|
34
28
|
}
|
|
35
29
|
|
|
36
|
-
let _plugin: IPluginInstance;
|
|
37
|
-
let webhooks: Webhook[];
|
|
38
30
|
|
|
39
|
-
|
|
40
|
-
_plugin = plugin;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export async function configureModels(
|
|
31
|
+
function listWebhooks(
|
|
44
32
|
server: IRpdServer,
|
|
45
|
-
applicationConfig: RpdApplicationConfig,
|
|
46
33
|
) {
|
|
47
|
-
server.
|
|
48
|
-
|
|
34
|
+
const dataAccessor = server.getDataAccessor({
|
|
35
|
+
namespace: "sys",
|
|
36
|
+
singularCode: "webhook",
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return findEntities(server, dataAccessor, {
|
|
40
|
+
filters: [
|
|
41
|
+
{
|
|
42
|
+
field: "enabled",
|
|
43
|
+
operator: "eq",
|
|
44
|
+
value: true,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
49
47
|
});
|
|
50
48
|
}
|
|
51
49
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
for (const event of events) {
|
|
59
|
-
server.registerEventHandler(
|
|
60
|
-
event,
|
|
61
|
-
handleEntityEvent.bind(null, server, event),
|
|
62
|
-
);
|
|
50
|
+
|
|
51
|
+
class WebhooksPlugin implements RapidPlugin {
|
|
52
|
+
#webhooks: Webhook[];
|
|
53
|
+
|
|
54
|
+
constructor() {
|
|
55
|
+
this.#webhooks = [];
|
|
63
56
|
}
|
|
64
|
-
}
|
|
65
57
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
event: keyof RpdServerEventTypes,
|
|
69
|
-
sender: IPluginInstance,
|
|
70
|
-
payload:
|
|
71
|
-
| RpdEntityCreateEventPayload
|
|
72
|
-
| RpdEntityUpdateEventPayload
|
|
73
|
-
| RpdEntityDeleteEventPayload,
|
|
74
|
-
) {
|
|
75
|
-
if (sender === _plugin) {
|
|
76
|
-
return;
|
|
58
|
+
get code(): string {
|
|
59
|
+
return "webhooks";
|
|
77
60
|
}
|
|
78
61
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return;
|
|
62
|
+
get description(): string {
|
|
63
|
+
return null;
|
|
82
64
|
}
|
|
83
65
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return;
|
|
66
|
+
get extendingAbilities(): RpdServerPluginExtendingAbilities[] {
|
|
67
|
+
return [];
|
|
87
68
|
}
|
|
88
69
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
70
|
+
get configurableTargets(): RpdServerPluginConfigurableTargetOptions[] {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
93
73
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
74
|
+
get configurations(): RpdConfigurationItemOptions[] {
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async initPlugin(server: IRpdServer): Promise<any> {
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async registerMiddlewares(server: IRpdServer): Promise<any> {
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async registerActionHandlers(server: IRpdServer): Promise<any> {
|
|
85
|
+
}
|
|
100
86
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
} catch (err) {
|
|
113
|
-
console.warn(new Error("Failed to call webhook. " + err.message));
|
|
114
|
-
console.warn(err);
|
|
87
|
+
async registerEventHandlers(server: IRpdServer): Promise<any> {
|
|
88
|
+
const events: (keyof RpdServerEventTypes)[] = [
|
|
89
|
+
"entity.create",
|
|
90
|
+
"entity.update",
|
|
91
|
+
"entity.delete",
|
|
92
|
+
];
|
|
93
|
+
for (const event of events) {
|
|
94
|
+
server.registerEventHandler(
|
|
95
|
+
event,
|
|
96
|
+
this.handleEntityEvent.bind(this, server, event),
|
|
97
|
+
);
|
|
115
98
|
}
|
|
116
99
|
}
|
|
117
|
-
}
|
|
118
100
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
applicationConfig: RpdApplicationConfig,
|
|
122
|
-
) {
|
|
123
|
-
console.log("[webhooks.onApplicationLoaded] loading webhooks");
|
|
124
|
-
webhooks = await listWebhooks(server);
|
|
125
|
-
}
|
|
101
|
+
async registerMessageHandlers(server: IRpdServer): Promise<any> {
|
|
102
|
+
}
|
|
126
103
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
) {
|
|
130
|
-
const dataAccessor = server.getDataAccessor({
|
|
131
|
-
namespace: "sys",
|
|
132
|
-
singularCode: "webhook",
|
|
133
|
-
});
|
|
104
|
+
async registerTaskProcessors(server: IRpdServer): Promise<any> {
|
|
105
|
+
}
|
|
134
106
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
107
|
+
async onLoadingApplication(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
111
|
+
server.appendApplicationConfig({
|
|
112
|
+
models: pluginConfig.models,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async configureModelProperties(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
123
|
+
console.log("[webhooks.onApplicationLoaded] loading webhooks");
|
|
124
|
+
this.#webhooks = await listWebhooks(server);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async onApplicationReady(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async handleEntityEvent(
|
|
131
|
+
server: IRpdServer,
|
|
132
|
+
event: keyof RpdServerEventTypes,
|
|
133
|
+
sender: RapidPlugin,
|
|
134
|
+
payload:
|
|
135
|
+
| RpdEntityCreateEventPayload
|
|
136
|
+
| RpdEntityUpdateEventPayload
|
|
137
|
+
| RpdEntityDeleteEventPayload,
|
|
138
|
+
) {
|
|
139
|
+
if (sender === this) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (payload.namespace === "sys" && payload.modelSingularCode === "webhook") {
|
|
144
|
+
this.#webhooks = await listWebhooks(server);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// We will not trigger webhooks if entity changed is in "meta" or "sys" namespaces.
|
|
149
|
+
if (payload.namespace === "meta" || payload.namespace === "sys") {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
for (const webhook of this.#webhooks) {
|
|
154
|
+
if (_.indexOf(webhook.events, event) === -1) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (
|
|
159
|
+
webhook.namespace != payload.namespace ||
|
|
160
|
+
webhook.modelSingularCode !== payload.modelSingularCode
|
|
161
|
+
) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
console.debug(`Triggering webhook. ${webhook.url}`);
|
|
166
|
+
// TODO: It's better to trigger webhook through message queue.
|
|
167
|
+
try {
|
|
168
|
+
await fetchWithTimeout(webhook.url, {
|
|
169
|
+
method: "post",
|
|
170
|
+
headers: {
|
|
171
|
+
"Content-Type": "application/json",
|
|
172
|
+
"x-webhook-secret": webhook.secret || "",
|
|
173
|
+
},
|
|
174
|
+
body: JSON.stringify({ event, payload }),
|
|
175
|
+
});
|
|
176
|
+
} catch (err) {
|
|
177
|
+
console.warn(new Error("Failed to call webhook. " + err.message));
|
|
178
|
+
console.warn(err);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
144
182
|
}
|
|
183
|
+
|
|
184
|
+
export default WebhooksPlugin;
|