@tsed/formio 8.11.0 → 8.11.2-rc.1
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/lib/esm/FormioModule.js +0 -1
- package/lib/esm/builder/FormioMapper.js +0 -1
- package/lib/esm/components/AlterActions.js +0 -1
- package/lib/esm/components/AlterAudit.js +0 -1
- package/lib/esm/components/AlterHost.js +0 -1
- package/lib/esm/components/AlterLog.js +0 -1
- package/lib/esm/components/AlterSkip.js +0 -1
- package/lib/esm/components/AlterTemplateExportSteps.js +0 -1
- package/lib/esm/components/AlterTemplateImportSteps.js +0 -1
- package/lib/esm/decorators/action.js +0 -1
- package/lib/esm/decorators/actionCtx.js +0 -1
- package/lib/esm/decorators/alter.js +0 -1
- package/lib/esm/decorators/on.js +0 -1
- package/lib/esm/decorators/useFormioAuth.js +0 -1
- package/lib/esm/domain/AlterHook.js +0 -1
- package/lib/esm/domain/Formio.js +0 -1
- package/lib/esm/domain/FormioAction.js +0 -1
- package/lib/esm/domain/FormioActionsIndex.js +0 -1
- package/lib/esm/domain/FormioAuth.js +0 -1
- package/lib/esm/domain/FormioBaseModel.js +0 -1
- package/lib/esm/domain/FormioConfig.js +0 -1
- package/lib/esm/domain/FormioCtxMapper.js +0 -1
- package/lib/esm/domain/FormioDecodedToken.js +0 -1
- package/lib/esm/domain/FormioErrors.js +0 -1
- package/lib/esm/domain/FormioHooks.js +0 -1
- package/lib/esm/domain/FormioJs.js +0 -1
- package/lib/esm/domain/FormioModels.js +0 -1
- package/lib/esm/domain/FormioRouter.js +0 -1
- package/lib/esm/domain/FormioSettings.js +0 -1
- package/lib/esm/domain/FormioTemplate.js +0 -1
- package/lib/esm/domain/FormioTemplateUtil.js +0 -1
- package/lib/esm/domain/FormioUpdate.js +0 -1
- package/lib/esm/domain/FormioUtils.js +0 -1
- package/lib/esm/domain/OnHook.js +0 -1
- package/lib/esm/domain/Resource.js +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/middlewares/FormioAuthMiddleware.js +0 -1
- package/lib/esm/services/FormioAuthService.js +0 -1
- package/lib/esm/services/FormioDatabase.js +0 -1
- package/lib/esm/services/FormioHooksService.js +0 -1
- package/lib/esm/services/FormioInstaller.js +0 -1
- package/lib/esm/services/FormioRepository.js +0 -1
- package/lib/esm/services/FormioService.js +0 -1
- package/lib/esm/utils/isMongoId.js +0 -1
- package/package.json +13 -10
- package/lib/esm/FormioModule.js.map +0 -1
- package/lib/esm/builder/FormioMapper.js.map +0 -1
- package/lib/esm/components/AlterActions.js.map +0 -1
- package/lib/esm/components/AlterAudit.js.map +0 -1
- package/lib/esm/components/AlterHost.js.map +0 -1
- package/lib/esm/components/AlterLog.js.map +0 -1
- package/lib/esm/components/AlterSkip.js.map +0 -1
- package/lib/esm/components/AlterTemplateExportSteps.js.map +0 -1
- package/lib/esm/components/AlterTemplateImportSteps.js.map +0 -1
- package/lib/esm/decorators/action.js.map +0 -1
- package/lib/esm/decorators/actionCtx.js.map +0 -1
- package/lib/esm/decorators/alter.js.map +0 -1
- package/lib/esm/decorators/on.js.map +0 -1
- package/lib/esm/decorators/useFormioAuth.js.map +0 -1
- package/lib/esm/domain/AlterHook.js.map +0 -1
- package/lib/esm/domain/Formio.js.map +0 -1
- package/lib/esm/domain/FormioAction.js.map +0 -1
- package/lib/esm/domain/FormioActionsIndex.js.map +0 -1
- package/lib/esm/domain/FormioAuth.js.map +0 -1
- package/lib/esm/domain/FormioBaseModel.js.map +0 -1
- package/lib/esm/domain/FormioConfig.js.map +0 -1
- package/lib/esm/domain/FormioCtxMapper.js.map +0 -1
- package/lib/esm/domain/FormioDecodedToken.js.map +0 -1
- package/lib/esm/domain/FormioErrors.js.map +0 -1
- package/lib/esm/domain/FormioHooks.js.map +0 -1
- package/lib/esm/domain/FormioJs.js.map +0 -1
- package/lib/esm/domain/FormioModels.js.map +0 -1
- package/lib/esm/domain/FormioRouter.js.map +0 -1
- package/lib/esm/domain/FormioSettings.js.map +0 -1
- package/lib/esm/domain/FormioTemplate.js.map +0 -1
- package/lib/esm/domain/FormioTemplateUtil.js.map +0 -1
- package/lib/esm/domain/FormioUpdate.js.map +0 -1
- package/lib/esm/domain/FormioUtils.js.map +0 -1
- package/lib/esm/domain/OnHook.js.map +0 -1
- package/lib/esm/domain/Resource.js.map +0 -1
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/middlewares/FormioAuthMiddleware.js.map +0 -1
- package/lib/esm/services/FormioAuthService.js.map +0 -1
- package/lib/esm/services/FormioDatabase.js.map +0 -1
- package/lib/esm/services/FormioHooksService.js.map +0 -1
- package/lib/esm/services/FormioInstaller.js.map +0 -1
- package/lib/esm/services/FormioRepository.js.map +0 -1
- package/lib/esm/services/FormioService.js.map +0 -1
- package/lib/esm/utils/isMongoId.js.map +0 -1
- package/src/FormioModule.spec.ts +0 -113
- package/src/FormioModule.ts +0 -130
- package/src/builder/FormioMapper.spec.ts +0 -93
- package/src/builder/FormioMapper.ts +0 -71
- package/src/components/AlterActions.spec.ts +0 -376
- package/src/components/AlterActions.ts +0 -136
- package/src/components/AlterAudit.spec.ts +0 -19
- package/src/components/AlterAudit.ts +0 -12
- package/src/components/AlterHost.spec.ts +0 -20
- package/src/components/AlterHost.ts +0 -11
- package/src/components/AlterLog.spec.ts +0 -19
- package/src/components/AlterLog.ts +0 -12
- package/src/components/AlterSkip.spec.ts +0 -44
- package/src/components/AlterSkip.ts +0 -28
- package/src/components/AlterTemplateExportSteps.spec.ts +0 -99
- package/src/components/AlterTemplateExportSteps.ts +0 -58
- package/src/components/AlterTemplateImportSteps.spec.ts +0 -70
- package/src/components/AlterTemplateImportSteps.ts +0 -50
- package/src/decorators/action.ts +0 -20
- package/src/decorators/actionCtx.spec.ts +0 -25
- package/src/decorators/actionCtx.ts +0 -29
- package/src/decorators/alter.spec.ts +0 -16
- package/src/decorators/alter.ts +0 -19
- package/src/decorators/on.spec.ts +0 -16
- package/src/decorators/on.ts +0 -19
- package/src/decorators/useFormioAuth.spec.ts +0 -15
- package/src/decorators/useFormioAuth.ts +0 -12
- package/src/domain/AlterHook.ts +0 -3
- package/src/domain/Formio.ts +0 -122
- package/src/domain/FormioAction.ts +0 -30
- package/src/domain/FormioActionsIndex.ts +0 -19
- package/src/domain/FormioAuth.ts +0 -83
- package/src/domain/FormioBaseModel.ts +0 -14
- package/src/domain/FormioConfig.ts +0 -63
- package/src/domain/FormioCtxMapper.ts +0 -8
- package/src/domain/FormioDecodedToken.ts +0 -13
- package/src/domain/FormioErrors.ts +0 -53
- package/src/domain/FormioHooks.ts +0 -207
- package/src/domain/FormioJs.ts +0 -18
- package/src/domain/FormioModels.ts +0 -48
- package/src/domain/FormioRouter.ts +0 -10
- package/src/domain/FormioSettings.ts +0 -61
- package/src/domain/FormioTemplate.ts +0 -9
- package/src/domain/FormioTemplateUtil.ts +0 -15
- package/src/domain/FormioUpdate.ts +0 -23
- package/src/domain/FormioUtils.ts +0 -331
- package/src/domain/OnHook.ts +0 -3
- package/src/domain/Resource.ts +0 -21
- package/src/index.ts +0 -46
- package/src/middlewares/FormioAuthMiddleware.spec.ts +0 -61
- package/src/middlewares/FormioAuthMiddleware.ts +0 -34
- package/src/services/FormioAuthService.spec.ts +0 -396
- package/src/services/FormioAuthService.ts +0 -228
- package/src/services/FormioDatabase.spec.ts +0 -326
- package/src/services/FormioDatabase.ts +0 -165
- package/src/services/FormioHooksService.spec.ts +0 -156
- package/src/services/FormioHooksService.ts +0 -92
- package/src/services/FormioInstaller.spec.ts +0 -146
- package/src/services/FormioInstaller.ts +0 -46
- package/src/services/FormioRepository.spec.ts +0 -114
- package/src/services/FormioRepository.ts +0 -49
- package/src/services/FormioService.spec.ts +0 -368
- package/src/services/FormioService.ts +0 -134
- package/src/utils/isMongoId.ts +0 -3
- package/vitest.config.mts +0 -21
|
@@ -1,376 +0,0 @@
|
|
|
1
|
-
import {BadRequest} from "@tsed/exceptions";
|
|
2
|
-
import {FormioActionInfo, FormioComponent} from "@tsed/formio-types";
|
|
3
|
-
import {PlatformContext} from "@tsed/platform-http";
|
|
4
|
-
import {PlatformTest} from "@tsed/platform-http/testing";
|
|
5
|
-
import {Context} from "@tsed/platform-params";
|
|
6
|
-
|
|
7
|
-
import {Action} from "../decorators/action.js";
|
|
8
|
-
import {ActionCtx} from "../decorators/actionCtx.js";
|
|
9
|
-
import {ActionMethods} from "../domain/FormioAction.js";
|
|
10
|
-
import {FormioActions} from "../domain/FormioActionsIndex.js";
|
|
11
|
-
import {FormioService} from "../services/FormioService.js";
|
|
12
|
-
import {AlterActions} from "./AlterActions.js";
|
|
13
|
-
|
|
14
|
-
async function getActionsFixture(formio: any) {
|
|
15
|
-
const ctx = PlatformTest.createRequestContext();
|
|
16
|
-
|
|
17
|
-
ctx.getRequest().$ctx = ctx;
|
|
18
|
-
|
|
19
|
-
const alterActions = await PlatformTest.invoke<AlterActions>(AlterActions, [
|
|
20
|
-
{
|
|
21
|
-
token: FormioService,
|
|
22
|
-
use: formio
|
|
23
|
-
}
|
|
24
|
-
]);
|
|
25
|
-
return {ctx, alterActions};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
describe("AlterActions", () => {
|
|
29
|
-
beforeEach(() => PlatformTest.create());
|
|
30
|
-
afterEach(PlatformTest.reset);
|
|
31
|
-
|
|
32
|
-
it("should create the new actions and return response", async () => {
|
|
33
|
-
@Action({
|
|
34
|
-
name: "custom",
|
|
35
|
-
title: "My custom Action",
|
|
36
|
-
description: "Custom action description",
|
|
37
|
-
priority: 0,
|
|
38
|
-
defaults: {
|
|
39
|
-
handler: [],
|
|
40
|
-
method: []
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
class CustomAction implements ActionMethods {
|
|
44
|
-
resolve(@ActionCtx() actionCtx: ActionCtx, @Context() ctx: PlatformContext) {
|
|
45
|
-
return Promise.resolve(actionCtx);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
settingsForm() {
|
|
49
|
-
return Promise.resolve([{} as any]);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const formio = {
|
|
54
|
-
Action: class Action {}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
// PlatformTest.injector.forkProvider(CustomAction);
|
|
58
|
-
PlatformTest.injector.invoke(CustomAction);
|
|
59
|
-
|
|
60
|
-
const {ctx, alterActions} = await getActionsFixture(formio);
|
|
61
|
-
|
|
62
|
-
let actions: FormioActions = {} as any;
|
|
63
|
-
|
|
64
|
-
actions = alterActions.transform(actions);
|
|
65
|
-
|
|
66
|
-
const info: FormioActionInfo = await new Promise((resolve) => {
|
|
67
|
-
actions.custom.info(ctx.getRequest(), ctx.getResponse(), (err, info) => resolve(info));
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
const settings: FormioComponent[] = await new Promise((resolve) => {
|
|
71
|
-
actions.custom.settingsForm(ctx.getRequest(), ctx.getResponse(), (err, components) => resolve(components));
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
const instance = new actions.custom(info as any, ctx.getRequest(), ctx.getResponse());
|
|
75
|
-
|
|
76
|
-
new Promise((resolve) => {
|
|
77
|
-
instance.resolve(
|
|
78
|
-
"handler",
|
|
79
|
-
"method",
|
|
80
|
-
ctx.getRequest(),
|
|
81
|
-
ctx.getResponse(),
|
|
82
|
-
(err: any, result: any) => resolve(result),
|
|
83
|
-
"setActionItemMessage" as any
|
|
84
|
-
);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
await new Promise((r) => setTimeout(r, 200));
|
|
88
|
-
|
|
89
|
-
expect(instance).toBeInstanceOf(formio.Action);
|
|
90
|
-
expect(info).toEqual({
|
|
91
|
-
defaults: {
|
|
92
|
-
handler: [],
|
|
93
|
-
method: []
|
|
94
|
-
},
|
|
95
|
-
description: "Custom action description",
|
|
96
|
-
name: "custom",
|
|
97
|
-
priority: 0,
|
|
98
|
-
title: "My custom Action"
|
|
99
|
-
});
|
|
100
|
-
expect(settings).toEqual([{}]);
|
|
101
|
-
expect(ctx.response.raw.data).toEqual({
|
|
102
|
-
handler: "handler",
|
|
103
|
-
method: "method",
|
|
104
|
-
setActionItemMessage: "setActionItemMessage",
|
|
105
|
-
action: {}
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
it("should create the new actions and return response with customInfo", async () => {
|
|
109
|
-
@Action({
|
|
110
|
-
name: "custom",
|
|
111
|
-
title: "My custom Action",
|
|
112
|
-
description: "Custom action description",
|
|
113
|
-
priority: 0,
|
|
114
|
-
defaults: {
|
|
115
|
-
handler: [],
|
|
116
|
-
method: []
|
|
117
|
-
}
|
|
118
|
-
})
|
|
119
|
-
class CustomAction implements ActionMethods {
|
|
120
|
-
resolve(@ActionCtx() actionCtx: ActionCtx, @Context() ctx: PlatformContext) {
|
|
121
|
-
return Promise.resolve(actionCtx);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
info(opts: any) {
|
|
125
|
-
return opts;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
settingsForm() {
|
|
129
|
-
return Promise.resolve([{} as any]);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const formio = {
|
|
134
|
-
Action: class Action {}
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
// PlatformTest.injector.forkProvider(CustomAction);
|
|
138
|
-
PlatformTest.injector.invoke(CustomAction);
|
|
139
|
-
|
|
140
|
-
const {ctx, alterActions} = await getActionsFixture(formio);
|
|
141
|
-
|
|
142
|
-
let actions: FormioActions = {} as any;
|
|
143
|
-
|
|
144
|
-
actions = alterActions.transform(actions);
|
|
145
|
-
|
|
146
|
-
const info: FormioActionInfo = await new Promise((resolve) => {
|
|
147
|
-
actions.custom.info(ctx.getRequest(), ctx.getResponse(), (err, info) => resolve(info));
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
const settings: FormioComponent[] = await new Promise((resolve) => {
|
|
151
|
-
actions.custom.settingsForm(ctx.getRequest(), ctx.getResponse(), (err, components) => resolve(components));
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
const instance = new actions.custom(info as any, ctx.getRequest(), ctx.getResponse());
|
|
155
|
-
|
|
156
|
-
new Promise((resolve) => {
|
|
157
|
-
instance.resolve(
|
|
158
|
-
"handler",
|
|
159
|
-
"method",
|
|
160
|
-
ctx.getRequest(),
|
|
161
|
-
ctx.getResponse(),
|
|
162
|
-
(err: any, result: any) => resolve(result),
|
|
163
|
-
"setActionItemMessage" as any
|
|
164
|
-
);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
await new Promise((r) => setTimeout(r, 200));
|
|
168
|
-
|
|
169
|
-
expect(instance).toBeInstanceOf(formio.Action);
|
|
170
|
-
expect(info).toEqual({
|
|
171
|
-
defaults: {
|
|
172
|
-
handler: [],
|
|
173
|
-
method: []
|
|
174
|
-
},
|
|
175
|
-
description: "Custom action description",
|
|
176
|
-
name: "custom",
|
|
177
|
-
priority: 0,
|
|
178
|
-
title: "My custom Action"
|
|
179
|
-
});
|
|
180
|
-
expect(settings).toEqual([{}]);
|
|
181
|
-
expect(ctx.response.raw.data).toEqual({
|
|
182
|
-
handler: "handler",
|
|
183
|
-
method: "method",
|
|
184
|
-
setActionItemMessage: "setActionItemMessage",
|
|
185
|
-
action: {}
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
it("should create the new actions and call next", async () => {
|
|
189
|
-
@Action({
|
|
190
|
-
name: "custom",
|
|
191
|
-
title: "My custom Action",
|
|
192
|
-
description: "Custom action description",
|
|
193
|
-
priority: 0,
|
|
194
|
-
defaults: {
|
|
195
|
-
handler: [],
|
|
196
|
-
method: []
|
|
197
|
-
}
|
|
198
|
-
})
|
|
199
|
-
class CustomAction implements ActionMethods {
|
|
200
|
-
resolve(@ActionCtx() actionCtx: ActionCtx, @Context() ctx: PlatformContext) {
|
|
201
|
-
return Promise.resolve();
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
settingsForm() {
|
|
205
|
-
return Promise.resolve([{} as any]);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const formio = {
|
|
210
|
-
Action: class Action {}
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
// PlatformTest.injector.forkProvider(CustomAction);
|
|
214
|
-
PlatformTest.injector.invoke(CustomAction);
|
|
215
|
-
|
|
216
|
-
const {ctx, alterActions} = await getActionsFixture(formio);
|
|
217
|
-
|
|
218
|
-
let actions: FormioActions = {} as any;
|
|
219
|
-
|
|
220
|
-
actions = alterActions.transform(actions);
|
|
221
|
-
|
|
222
|
-
const info: FormioActionInfo = await new Promise((resolve) => {
|
|
223
|
-
actions.custom.info(ctx.getRequest(), ctx.getResponse(), (err, info) => resolve(info));
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
const instance = new actions.custom(info as any, ctx.getRequest(), ctx.getResponse());
|
|
227
|
-
|
|
228
|
-
const result = await new Promise((resolve) => {
|
|
229
|
-
instance.resolve(
|
|
230
|
-
"handler",
|
|
231
|
-
"method",
|
|
232
|
-
ctx.getRequest(),
|
|
233
|
-
ctx.getResponse(),
|
|
234
|
-
(err: any, result: any) => resolve(result),
|
|
235
|
-
"setActionItemMessage" as any
|
|
236
|
-
);
|
|
237
|
-
});
|
|
238
|
-
expect(result).toEqual(undefined);
|
|
239
|
-
});
|
|
240
|
-
it("should create the new actions and call next with error", async () => {
|
|
241
|
-
@Action({
|
|
242
|
-
name: "custom",
|
|
243
|
-
title: "My custom Action",
|
|
244
|
-
description: "Custom action description",
|
|
245
|
-
priority: 0,
|
|
246
|
-
defaults: {
|
|
247
|
-
handler: [],
|
|
248
|
-
method: []
|
|
249
|
-
}
|
|
250
|
-
})
|
|
251
|
-
class CustomAction implements ActionMethods {
|
|
252
|
-
resolve(@ActionCtx() actionCtx: ActionCtx, @Context() ctx: PlatformContext) {
|
|
253
|
-
return Promise.reject(new BadRequest("bad request"));
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
settingsForm() {
|
|
257
|
-
return Promise.resolve([{} as any]);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
const formio = {
|
|
262
|
-
Action: class Action {}
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
// PlatformTest.injector.forkProvider(CustomAction);
|
|
266
|
-
PlatformTest.injector.invoke(CustomAction);
|
|
267
|
-
|
|
268
|
-
const {ctx, alterActions} = await getActionsFixture(formio);
|
|
269
|
-
|
|
270
|
-
let actions: FormioActions = {} as any;
|
|
271
|
-
|
|
272
|
-
actions = alterActions.transform(actions);
|
|
273
|
-
|
|
274
|
-
const info: FormioActionInfo = await new Promise((resolve) => {
|
|
275
|
-
actions.custom.info(ctx.getRequest(), ctx.getResponse(), (err, info) => resolve(info));
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
const instance = new actions.custom(info as any, ctx.getRequest(), ctx.getResponse());
|
|
279
|
-
|
|
280
|
-
const result: any = await new Promise((resolve) => {
|
|
281
|
-
instance.resolve(
|
|
282
|
-
"handler",
|
|
283
|
-
"method",
|
|
284
|
-
ctx.getRequest(),
|
|
285
|
-
ctx.getResponse(),
|
|
286
|
-
(err: any, result: any) => {
|
|
287
|
-
return resolve(err);
|
|
288
|
-
},
|
|
289
|
-
"setActionItemMessage" as any
|
|
290
|
-
);
|
|
291
|
-
});
|
|
292
|
-
expect(result.message).toEqual("bad request");
|
|
293
|
-
});
|
|
294
|
-
it("should create the new actions and call next (with status and headers)", async () => {
|
|
295
|
-
@Action({
|
|
296
|
-
name: "custom",
|
|
297
|
-
title: "My custom Action",
|
|
298
|
-
description: "Custom action description",
|
|
299
|
-
priority: 0,
|
|
300
|
-
defaults: {
|
|
301
|
-
handler: [],
|
|
302
|
-
method: []
|
|
303
|
-
}
|
|
304
|
-
})
|
|
305
|
-
class CustomAction implements ActionMethods {
|
|
306
|
-
resolve(@ActionCtx() actionCtx: ActionCtx, @Context() ctx: PlatformContext) {
|
|
307
|
-
return Promise.resolve({
|
|
308
|
-
statusText: "Created",
|
|
309
|
-
status: 201,
|
|
310
|
-
headers: {
|
|
311
|
-
"x-header": "test"
|
|
312
|
-
},
|
|
313
|
-
data: {
|
|
314
|
-
hello: "world"
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
settingsForm() {
|
|
320
|
-
return Promise.resolve([{} as any]);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
const formio = {
|
|
325
|
-
Action: class Action {}
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
// PlatformTest.injector.forkProvider(CustomAction);
|
|
329
|
-
PlatformTest.injector.invoke(CustomAction);
|
|
330
|
-
|
|
331
|
-
const {ctx, alterActions} = await getActionsFixture(formio);
|
|
332
|
-
|
|
333
|
-
let actions: FormioActions = {} as any;
|
|
334
|
-
|
|
335
|
-
actions = alterActions.transform(actions);
|
|
336
|
-
|
|
337
|
-
const info: FormioActionInfo = await new Promise((resolve) => {
|
|
338
|
-
actions.custom.info(ctx.getRequest(), ctx.getResponse(), (err, info) => resolve(info));
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
const settings: FormioComponent[] = await new Promise((resolve) => {
|
|
342
|
-
actions.custom.settingsForm(ctx.getRequest(), ctx.getResponse(), (err, components) => resolve(components));
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
const instance = new actions.custom(info as any, ctx.getRequest(), ctx.getResponse());
|
|
346
|
-
|
|
347
|
-
new Promise((resolve) => {
|
|
348
|
-
instance.resolve(
|
|
349
|
-
"handler",
|
|
350
|
-
"method",
|
|
351
|
-
ctx.getRequest(),
|
|
352
|
-
ctx.getResponse(),
|
|
353
|
-
(err: any, result: any) => resolve(result),
|
|
354
|
-
"setActionItemMessage" as any
|
|
355
|
-
);
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
await new Promise((r) => setTimeout(r, 200));
|
|
359
|
-
|
|
360
|
-
expect(instance).toBeInstanceOf(formio.Action);
|
|
361
|
-
expect(info).toEqual({
|
|
362
|
-
defaults: {
|
|
363
|
-
handler: [],
|
|
364
|
-
method: []
|
|
365
|
-
},
|
|
366
|
-
description: "Custom action description",
|
|
367
|
-
name: "custom",
|
|
368
|
-
priority: 0,
|
|
369
|
-
title: "My custom Action"
|
|
370
|
-
});
|
|
371
|
-
expect(settings).toEqual([{}]);
|
|
372
|
-
expect(ctx.response.raw.data).toEqual({
|
|
373
|
-
hello: "world"
|
|
374
|
-
});
|
|
375
|
-
});
|
|
376
|
-
});
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import {AnyToPromise, AnyToPromiseStatus} from "@tsed/core";
|
|
2
|
-
import {Inject, InjectorService, Provider} from "@tsed/di";
|
|
3
|
-
import {FormioActionInfo} from "@tsed/formio-types";
|
|
4
|
-
import {PlatformContext, setResponseHeaders} from "@tsed/platform-http";
|
|
5
|
-
import {PlatformParams} from "@tsed/platform-params";
|
|
6
|
-
import {PlatformResponseFilter} from "@tsed/platform-response-filter";
|
|
7
|
-
import {EndpointMetadata} from "@tsed/schema";
|
|
8
|
-
|
|
9
|
-
import {Alter} from "../decorators/alter.js";
|
|
10
|
-
import {AlterHook} from "../domain/AlterHook.js";
|
|
11
|
-
import {SetActionItemMessage} from "../domain/FormioAction.js";
|
|
12
|
-
import {FormioActions} from "../domain/FormioActionsIndex.js";
|
|
13
|
-
import {FormioService} from "../services/FormioService.js";
|
|
14
|
-
|
|
15
|
-
@Alter("actions")
|
|
16
|
-
export class AlterActions implements AlterHook {
|
|
17
|
-
@Inject()
|
|
18
|
-
protected injector: InjectorService;
|
|
19
|
-
|
|
20
|
-
@Inject()
|
|
21
|
-
protected formio: FormioService;
|
|
22
|
-
|
|
23
|
-
@Inject()
|
|
24
|
-
protected params: PlatformParams;
|
|
25
|
-
|
|
26
|
-
@Inject()
|
|
27
|
-
protected responseFilter: PlatformResponseFilter;
|
|
28
|
-
|
|
29
|
-
transform(actions: FormioActions): FormioActions {
|
|
30
|
-
const {Action} = this.formio;
|
|
31
|
-
|
|
32
|
-
return this.getActions().reduce((actions, provider) => {
|
|
33
|
-
const instance = this.injector.invoke<any>(provider.token);
|
|
34
|
-
const options = provider.store.get<FormioActionInfo>("formio:action");
|
|
35
|
-
const resolveHandler = this.createHandler(provider, "resolve");
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
...actions,
|
|
39
|
-
[options.name]: class extends Action {
|
|
40
|
-
static access = options.access;
|
|
41
|
-
|
|
42
|
-
static async info(req: any, res: any, next: Function) {
|
|
43
|
-
let opts = {...options};
|
|
44
|
-
|
|
45
|
-
if (instance.info) {
|
|
46
|
-
opts = await instance.info(opts, req, res);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
next(null, opts);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
static async settingsForm(req: any, res: any, next: Function) {
|
|
53
|
-
next(null, await instance.settingsForm(req, res));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
resolve(handler: string, method: string, req: any, res: any, next: Function, setActionItemMessage: SetActionItemMessage): void {
|
|
57
|
-
resolveHandler(this, handler, method, req, res, next, setActionItemMessage);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
}, actions);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
protected getActions() {
|
|
65
|
-
return this.injector.getProviders("formio:action");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
protected createHandler(provider: Provider, propertyKey: string | symbol) {
|
|
69
|
-
const compiledHandler = this.params.compileHandler({
|
|
70
|
-
token: provider.token,
|
|
71
|
-
propertyKey
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
return async (
|
|
75
|
-
action: any,
|
|
76
|
-
handler: string,
|
|
77
|
-
method: string,
|
|
78
|
-
req: any,
|
|
79
|
-
res: any,
|
|
80
|
-
next: any,
|
|
81
|
-
setActionItemMessage: SetActionItemMessage
|
|
82
|
-
) => {
|
|
83
|
-
const {$ctx} = req;
|
|
84
|
-
|
|
85
|
-
if ($ctx) {
|
|
86
|
-
$ctx.set("ACTION_CTX", {handler, method, setActionItemMessage, action});
|
|
87
|
-
$ctx.endpoint = EndpointMetadata.get(provider.useClass, "resolve");
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
if (await this.onRequest(compiledHandler, $ctx)) {
|
|
91
|
-
next();
|
|
92
|
-
}
|
|
93
|
-
} catch (er) {
|
|
94
|
-
next(er);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
private async onRequest(handler: any, $ctx: PlatformContext) {
|
|
101
|
-
const resolver = new AnyToPromise();
|
|
102
|
-
const {state, data, status, headers} = await resolver.call(() => handler({$ctx}));
|
|
103
|
-
|
|
104
|
-
if (state === AnyToPromiseStatus.RESOLVED) {
|
|
105
|
-
if (status) {
|
|
106
|
-
$ctx.response.status(status);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (headers) {
|
|
110
|
-
$ctx.response.setHeaders(headers);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (data !== undefined) {
|
|
114
|
-
$ctx.data = data;
|
|
115
|
-
|
|
116
|
-
return this.flush($ctx.data, $ctx);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return true;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
private async flush(data: any, $ctx: PlatformContext) {
|
|
124
|
-
const {response} = $ctx;
|
|
125
|
-
|
|
126
|
-
if (!$ctx.isDone()) {
|
|
127
|
-
setResponseHeaders($ctx);
|
|
128
|
-
|
|
129
|
-
data = await this.responseFilter.transform(data, $ctx as any);
|
|
130
|
-
|
|
131
|
-
response.body(data);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return response;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {PlatformTest} from "@tsed/platform-http/testing";
|
|
2
|
-
|
|
3
|
-
import {AlterAudit} from "./AlterAudit.js";
|
|
4
|
-
|
|
5
|
-
describe("AlterAudit", () => {
|
|
6
|
-
beforeEach(() => PlatformTest.create());
|
|
7
|
-
afterEach(PlatformTest.reset);
|
|
8
|
-
|
|
9
|
-
it("should log data", async () => {
|
|
10
|
-
const ctx = PlatformTest.createRequestContext();
|
|
11
|
-
|
|
12
|
-
vi.spyOn(ctx.logger, "info");
|
|
13
|
-
|
|
14
|
-
const alterAudit = await PlatformTest.invoke<AlterAudit>(AlterAudit);
|
|
15
|
-
|
|
16
|
-
alterAudit.transform(["data"], "event", ctx);
|
|
17
|
-
expect(ctx.logger.info).toHaveBeenCalledWith({event: "event", info: ["data"]});
|
|
18
|
-
});
|
|
19
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import {DIContext} from "@tsed/di";
|
|
2
|
-
|
|
3
|
-
import {Alter} from "../decorators/alter.js";
|
|
4
|
-
import {AlterHook} from "../domain/AlterHook.js";
|
|
5
|
-
|
|
6
|
-
@Alter("audit")
|
|
7
|
-
export class AlterAudit implements AlterHook {
|
|
8
|
-
transform(info: any[], event: string, ctx: DIContext): boolean {
|
|
9
|
-
ctx.logger.info({event, info});
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {PlatformTest} from "@tsed/platform-http/testing";
|
|
2
|
-
|
|
3
|
-
import {AlterHost} from "./AlterHost.js";
|
|
4
|
-
|
|
5
|
-
describe("AlterHost", () => {
|
|
6
|
-
beforeEach(() => PlatformTest.create());
|
|
7
|
-
afterEach(PlatformTest.reset);
|
|
8
|
-
|
|
9
|
-
it("should transform host", async () => {
|
|
10
|
-
const ctx = PlatformTest.createRequestContext();
|
|
11
|
-
ctx.request.raw.headers["host"] = "host";
|
|
12
|
-
ctx.getRequest().protocol = "https";
|
|
13
|
-
|
|
14
|
-
const alterHost = await PlatformTest.invoke<AlterHost>(AlterHost);
|
|
15
|
-
|
|
16
|
-
const url = alterHost.transform("/projects", ctx);
|
|
17
|
-
|
|
18
|
-
expect(url).toEqual("https://host/projects");
|
|
19
|
-
});
|
|
20
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {PlatformContext} from "@tsed/platform-http";
|
|
2
|
-
|
|
3
|
-
import {Alter} from "../decorators/alter.js";
|
|
4
|
-
import {AlterHook} from "../domain/AlterHook.js";
|
|
5
|
-
|
|
6
|
-
@Alter("host")
|
|
7
|
-
export class AlterHost implements AlterHook<string> {
|
|
8
|
-
transform(baseUrl: string, ctx: PlatformContext) {
|
|
9
|
-
return `${ctx.request.protocol}://${ctx.request.host}${baseUrl}`;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {PlatformTest} from "@tsed/platform-http/testing";
|
|
2
|
-
|
|
3
|
-
import {AlterLog} from "./AlterLog.js";
|
|
4
|
-
|
|
5
|
-
describe("AlterLog", () => {
|
|
6
|
-
beforeEach(() => PlatformTest.create());
|
|
7
|
-
afterEach(PlatformTest.reset);
|
|
8
|
-
|
|
9
|
-
it("should log data", async () => {
|
|
10
|
-
const ctx = PlatformTest.createRequestContext();
|
|
11
|
-
|
|
12
|
-
vi.spyOn(ctx.logger, "debug");
|
|
13
|
-
|
|
14
|
-
const alterLog = await PlatformTest.invoke<AlterLog>(AlterLog);
|
|
15
|
-
|
|
16
|
-
alterLog.transform("event", ctx, "data");
|
|
17
|
-
expect(ctx.logger.debug).toHaveBeenCalledWith({event: "event", info: ["data"]});
|
|
18
|
-
});
|
|
19
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import {PlatformContext} from "@tsed/platform-http";
|
|
2
|
-
|
|
3
|
-
import {Alter} from "../decorators/alter.js";
|
|
4
|
-
import {AlterHook} from "../domain/AlterHook.js";
|
|
5
|
-
|
|
6
|
-
@Alter("log")
|
|
7
|
-
export class AlterLog implements AlterHook {
|
|
8
|
-
transform(event: string, ctx: PlatformContext, ...info: any[]): boolean {
|
|
9
|
-
ctx.logger.debug({event, info});
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import {PlatformTest} from "@tsed/platform-http/testing";
|
|
2
|
-
|
|
3
|
-
import {AlterSkip} from "./AlterSkip.js";
|
|
4
|
-
|
|
5
|
-
describe("AlterSkip", () => {
|
|
6
|
-
beforeEach(() => PlatformTest.create());
|
|
7
|
-
afterEach(PlatformTest.reset);
|
|
8
|
-
|
|
9
|
-
it("should transform skip", async () => {
|
|
10
|
-
const ctx = PlatformTest.createRequestContext();
|
|
11
|
-
|
|
12
|
-
const alterSkip = await PlatformTest.invoke<AlterSkip>(AlterSkip);
|
|
13
|
-
|
|
14
|
-
ctx.getRequest().originalUrl = "/spec.json";
|
|
15
|
-
|
|
16
|
-
const result = alterSkip.transform(false, ctx);
|
|
17
|
-
|
|
18
|
-
expect(result).toEqual(true);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("should transform skip and return false", async () => {
|
|
22
|
-
const ctx = PlatformTest.createRequestContext();
|
|
23
|
-
|
|
24
|
-
const alterSkip = await PlatformTest.invoke<AlterSkip>(AlterSkip);
|
|
25
|
-
|
|
26
|
-
ctx.getRequest().originalUrl = "/other";
|
|
27
|
-
|
|
28
|
-
const result = alterSkip.transform(false, ctx);
|
|
29
|
-
|
|
30
|
-
expect(result).toEqual(false);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("should not transform skip", async () => {
|
|
34
|
-
const ctx = PlatformTest.createRequestContext();
|
|
35
|
-
|
|
36
|
-
const alterSkip = await PlatformTest.invoke<AlterSkip>(AlterSkip);
|
|
37
|
-
|
|
38
|
-
ctx.getRequest().originalUrl = "/other";
|
|
39
|
-
|
|
40
|
-
const result = alterSkip.transform(true, ctx);
|
|
41
|
-
|
|
42
|
-
expect(result).toEqual(true);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {Constant} from "@tsed/di";
|
|
2
|
-
import {normalizePath} from "@tsed/normalize-path";
|
|
3
|
-
import {PlatformContext} from "@tsed/platform-http";
|
|
4
|
-
|
|
5
|
-
import {Alter} from "../decorators/alter.js";
|
|
6
|
-
import {AlterHook} from "../domain/AlterHook.js";
|
|
7
|
-
|
|
8
|
-
@Alter("skip")
|
|
9
|
-
export class AlterSkip implements AlterHook {
|
|
10
|
-
@Constant("formio.baseUrl", "/")
|
|
11
|
-
baseUrl: string;
|
|
12
|
-
|
|
13
|
-
@Constant("formio.whiteList", ["/spec.json"])
|
|
14
|
-
whiteList: string[];
|
|
15
|
-
|
|
16
|
-
transform(value: any, ctx: PlatformContext): any {
|
|
17
|
-
if (value) {
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const {request} = ctx;
|
|
22
|
-
const url = request.url.split("?")[0];
|
|
23
|
-
|
|
24
|
-
return !!this.whiteList.find((entry) => {
|
|
25
|
-
return normalizePath(this.baseUrl, entry) === url;
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
}
|