@tsed/formio 8.11.1 → 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,99 +0,0 @@
|
|
|
1
|
-
import {PlatformTest} from "@tsed/platform-http/testing";
|
|
2
|
-
|
|
3
|
-
import {FormioDatabase} from "../services/FormioDatabase.js";
|
|
4
|
-
import {AlterTemplateExportSteps} from "./AlterTemplateExportSteps.js";
|
|
5
|
-
|
|
6
|
-
async function createServiceFixture() {
|
|
7
|
-
const mapper = {
|
|
8
|
-
mapToExport: vi.fn().mockImplementation((data) => {
|
|
9
|
-
if (data === "form_id") {
|
|
10
|
-
return "machineName";
|
|
11
|
-
}
|
|
12
|
-
return data;
|
|
13
|
-
})
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const database = {
|
|
17
|
-
submissionModel: {
|
|
18
|
-
deleteMany: vi.fn(),
|
|
19
|
-
create: vi.fn(),
|
|
20
|
-
find: vi.fn()
|
|
21
|
-
},
|
|
22
|
-
getFormioMapper: vi.fn().mockResolvedValue(mapper)
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const service = await PlatformTest.invoke<AlterTemplateExportSteps>(AlterTemplateExportSteps, [
|
|
26
|
-
{
|
|
27
|
-
token: FormioDatabase,
|
|
28
|
-
use: database
|
|
29
|
-
}
|
|
30
|
-
]);
|
|
31
|
-
|
|
32
|
-
return {service, mapper, database};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
describe("AlterTemplateExportSteps", () => {
|
|
36
|
-
beforeEach(() => PlatformTest.create());
|
|
37
|
-
afterEach(PlatformTest.reset);
|
|
38
|
-
|
|
39
|
-
it("should export submission", async () => {
|
|
40
|
-
const {service, database} = await createServiceFixture();
|
|
41
|
-
let queue: any[] = [];
|
|
42
|
-
const map = {};
|
|
43
|
-
const options = {};
|
|
44
|
-
const template: any = {
|
|
45
|
-
submissions: {
|
|
46
|
-
admin: [
|
|
47
|
-
{
|
|
48
|
-
form: "$machineName:admin",
|
|
49
|
-
data: {},
|
|
50
|
-
roles: ["admin", "admin"]
|
|
51
|
-
}
|
|
52
|
-
]
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
database.submissionModel.find.mockResolvedValue([
|
|
57
|
-
{
|
|
58
|
-
toObject() {
|
|
59
|
-
return {
|
|
60
|
-
_id: "_id",
|
|
61
|
-
created: "created",
|
|
62
|
-
updated: "updated",
|
|
63
|
-
deleted: "deleted",
|
|
64
|
-
modified: "modified",
|
|
65
|
-
__v: "__v",
|
|
66
|
-
owner: "owner",
|
|
67
|
-
roles: ["roles"],
|
|
68
|
-
form: "form_id",
|
|
69
|
-
metadata: "metadata",
|
|
70
|
-
data: {}
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
]);
|
|
75
|
-
|
|
76
|
-
queue = service.transform(queue, template, map, options);
|
|
77
|
-
|
|
78
|
-
expect(queue.length).toEqual(1);
|
|
79
|
-
|
|
80
|
-
const result = await new Promise((resolve) => queue[0]((err: any, template: any) => resolve(template)));
|
|
81
|
-
|
|
82
|
-
expect(result).toEqual({
|
|
83
|
-
submissions: {
|
|
84
|
-
machineName: [
|
|
85
|
-
{
|
|
86
|
-
created: "created",
|
|
87
|
-
data: {},
|
|
88
|
-
deleted: "deleted",
|
|
89
|
-
form: "machineName",
|
|
90
|
-
modified: "modified",
|
|
91
|
-
roles: ["roles"]
|
|
92
|
-
}
|
|
93
|
-
]
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
expect(database.getFormioMapper).toHaveBeenCalledWith();
|
|
97
|
-
expect(database.submissionModel.find).toHaveBeenCalledWith({deleted: {$eq: null}});
|
|
98
|
-
});
|
|
99
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import {getValue} from "@tsed/core";
|
|
2
|
-
import {Inject} from "@tsed/di";
|
|
3
|
-
import {MongooseDocument} from "@tsed/mongoose";
|
|
4
|
-
import async from "async";
|
|
5
|
-
|
|
6
|
-
import {FormioMapper} from "../builder/FormioMapper.js";
|
|
7
|
-
import {Alter} from "../decorators/alter.js";
|
|
8
|
-
import {AlterHook} from "../domain/AlterHook.js";
|
|
9
|
-
import {FormioSubmission} from "../domain/FormioModels.js";
|
|
10
|
-
import {FormioTemplate} from "../domain/FormioTemplate.js";
|
|
11
|
-
import {FormioDatabase} from "../services/FormioDatabase.js";
|
|
12
|
-
|
|
13
|
-
@Alter("templateExportSteps")
|
|
14
|
-
export class AlterTemplateExportSteps implements AlterHook {
|
|
15
|
-
@Inject()
|
|
16
|
-
protected database: FormioDatabase;
|
|
17
|
-
|
|
18
|
-
transform(queue: any[], template: FormioTemplate, map: any, options: any): any {
|
|
19
|
-
queue.push(async.apply(this.exportSubmissions.bind(this), template, map, options));
|
|
20
|
-
|
|
21
|
-
return queue;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
protected async exportSubmissions(template: FormioTemplate, map: any, options: any, next: any) {
|
|
25
|
-
const [mapper, submissions] = await Promise.all([
|
|
26
|
-
this.database.getFormioMapper(),
|
|
27
|
-
this.database.submissionModel.find({
|
|
28
|
-
deleted: {$eq: null}
|
|
29
|
-
})
|
|
30
|
-
]);
|
|
31
|
-
|
|
32
|
-
template.submissions = await this.mapSubmissions(submissions, mapper);
|
|
33
|
-
|
|
34
|
-
next(null, template);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
protected mapSubmissions(submissions: MongooseDocument<FormioSubmission>[], mapper: FormioMapper) {
|
|
38
|
-
return submissions
|
|
39
|
-
.map((submission) => submission.toObject())
|
|
40
|
-
.reduce((acc: any, {_id, created, updated, modified, __v, owner, roles, form, metadata, ...submission}) => {
|
|
41
|
-
const machineName = mapper.mapToExport(form.toString());
|
|
42
|
-
const key = machineName.replace("$machineName:", "");
|
|
43
|
-
|
|
44
|
-
acc[key] = getValue(acc, key, []);
|
|
45
|
-
|
|
46
|
-
acc[key].push({
|
|
47
|
-
...submission,
|
|
48
|
-
created: created && created.toString(),
|
|
49
|
-
modified: modified && modified.toString(),
|
|
50
|
-
data: mapper.mapToExport(submission.data),
|
|
51
|
-
roles: mapper.mapToExport(roles).filter(Boolean),
|
|
52
|
-
form: mapper.mapToExport(form)
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
return acc;
|
|
56
|
-
}, {});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import {PlatformTest} from "@tsed/platform-http/testing";
|
|
2
|
-
|
|
3
|
-
import {FormioDatabase} from "../services/FormioDatabase.js";
|
|
4
|
-
import {AlterTemplateImportSteps} from "./AlterTemplateImportSteps.js";
|
|
5
|
-
|
|
6
|
-
async function createServiceFixture() {
|
|
7
|
-
const mapper = {
|
|
8
|
-
mapToImport: vi.fn().mockImplementation((data) => {
|
|
9
|
-
if (data && data.data) {
|
|
10
|
-
return {
|
|
11
|
-
form: "form_id",
|
|
12
|
-
data: {},
|
|
13
|
-
roles: []
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
return data;
|
|
17
|
-
})
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const database = {
|
|
21
|
-
submissionModel: {
|
|
22
|
-
deleteMany: vi.fn(),
|
|
23
|
-
create: vi.fn()
|
|
24
|
-
},
|
|
25
|
-
getFormioMapper: vi.fn().mockResolvedValue(mapper)
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const service = await PlatformTest.invoke<AlterTemplateImportSteps>(AlterTemplateImportSteps, [
|
|
29
|
-
{
|
|
30
|
-
token: FormioDatabase,
|
|
31
|
-
use: database
|
|
32
|
-
}
|
|
33
|
-
]);
|
|
34
|
-
|
|
35
|
-
return {service, mapper, database};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
describe("AlterTemplateImportSteps", () => {
|
|
39
|
-
beforeEach(() => PlatformTest.create());
|
|
40
|
-
afterEach(PlatformTest.reset);
|
|
41
|
-
|
|
42
|
-
it("should import submission", async () => {
|
|
43
|
-
const {service, database} = await createServiceFixture();
|
|
44
|
-
let queue: any[] = [];
|
|
45
|
-
const template: any = {
|
|
46
|
-
submissions: {
|
|
47
|
-
admin: [
|
|
48
|
-
{
|
|
49
|
-
form: "$machineName:admin",
|
|
50
|
-
data: {},
|
|
51
|
-
roles: ["admin", "admin"]
|
|
52
|
-
}
|
|
53
|
-
]
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
queue = service.transform(queue, vi.fn(), template);
|
|
58
|
-
|
|
59
|
-
expect(queue.length).toEqual(1);
|
|
60
|
-
|
|
61
|
-
await new Promise((resolve) => queue[0](resolve));
|
|
62
|
-
|
|
63
|
-
expect(database.submissionModel.deleteMany).toHaveBeenCalledWith({});
|
|
64
|
-
expect(database.submissionModel.create).toHaveBeenCalledWith({
|
|
65
|
-
form: "form_id",
|
|
66
|
-
data: {},
|
|
67
|
-
roles: ["admin"]
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
});
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import {Inject} from "@tsed/di";
|
|
2
|
-
import async from "async";
|
|
3
|
-
|
|
4
|
-
import {FormioMapper} from "../builder/FormioMapper.js";
|
|
5
|
-
import {Alter} from "../decorators/alter.js";
|
|
6
|
-
import {AlterHook} from "../domain/AlterHook.js";
|
|
7
|
-
import {FormioSubmission} from "../domain/FormioModels.js";
|
|
8
|
-
import {FormioTemplate} from "../domain/FormioTemplate.js";
|
|
9
|
-
import {FormioDatabase} from "../services/FormioDatabase.js";
|
|
10
|
-
|
|
11
|
-
@Alter("templateImportSteps")
|
|
12
|
-
export class AlterTemplateImportSteps implements AlterHook {
|
|
13
|
-
@Inject()
|
|
14
|
-
protected database: FormioDatabase;
|
|
15
|
-
|
|
16
|
-
transform(queue: any[], install: Function, template: Partial<FormioTemplate>): any {
|
|
17
|
-
queue.push(async.apply(this.importSubmissions.bind(this), template));
|
|
18
|
-
|
|
19
|
-
return queue;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
protected async importSubmissions(template: Partial<FormioTemplate>, done: any) {
|
|
23
|
-
if (template && template.submissions) {
|
|
24
|
-
// clean all submissions
|
|
25
|
-
await this.database.submissionModel.deleteMany({});
|
|
26
|
-
|
|
27
|
-
const ctxData = await this.database.getFormioMapper();
|
|
28
|
-
const entries = Object.entries(template.submissions);
|
|
29
|
-
|
|
30
|
-
for (const entry of entries) {
|
|
31
|
-
for (const submission of entry[1]) {
|
|
32
|
-
await this.importSubmission({...submission, form: submission.form || entry[0]}, ctxData);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
done();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
protected async importSubmission(submission: Partial<FormioSubmission>, mapper: FormioMapper) {
|
|
41
|
-
const value = {
|
|
42
|
-
...mapper.mapToImport(submission),
|
|
43
|
-
roles: [...new Set(mapper.mapToImport(submission.roles || []))].filter(Boolean)
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
await this.database.submissionModel.create(value);
|
|
47
|
-
|
|
48
|
-
return value;
|
|
49
|
-
}
|
|
50
|
-
}
|
package/src/decorators/action.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {StoreSet, useDecorators} from "@tsed/core";
|
|
2
|
-
import {registerProvider} from "@tsed/di";
|
|
3
|
-
import {FormioActionInfo} from "@tsed/formio-types";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Create a new FormIO Action.
|
|
7
|
-
* @param options
|
|
8
|
-
* @decorator
|
|
9
|
-
*/
|
|
10
|
-
export function Action(options: FormioActionInfo): ClassDecorator {
|
|
11
|
-
return useDecorators(
|
|
12
|
-
(target: any) => {
|
|
13
|
-
registerProvider({
|
|
14
|
-
token: target,
|
|
15
|
-
type: "formio:action"
|
|
16
|
-
});
|
|
17
|
-
},
|
|
18
|
-
StoreSet("formio:action", options)
|
|
19
|
-
);
|
|
20
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {JsonParameterStore} from "@tsed/schema";
|
|
2
|
-
|
|
3
|
-
import {ActionCtx} from "./actionCtx.js";
|
|
4
|
-
|
|
5
|
-
describe("@ActionCtx", () => {
|
|
6
|
-
it("should inject ActionCtx", () => {
|
|
7
|
-
class CustomAction {
|
|
8
|
-
resolve(@ActionCtx() actionCtx: ActionCtx) {}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const param = JsonParameterStore.get(CustomAction, "resolve", 0);
|
|
12
|
-
|
|
13
|
-
expect(param.expression).toEqual("ACTION_CTX");
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it("should inject ActionCtx (with expression)", () => {
|
|
17
|
-
class CustomAction {
|
|
18
|
-
resolve(@ActionCtx("handler") actionCtx: ActionCtx) {}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const param = JsonParameterStore.get(CustomAction, "resolve", 0);
|
|
22
|
-
|
|
23
|
-
expect(param.expression).toEqual("ACTION_CTX.handler");
|
|
24
|
-
});
|
|
25
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {FormioAction} from "@tsed/formio-types";
|
|
2
|
-
import {Context} from "@tsed/platform-params";
|
|
3
|
-
|
|
4
|
-
import {SetActionItemMessage} from "../domain/FormioAction.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Return the current action context with the following data:
|
|
8
|
-
*
|
|
9
|
-
* ```typescript
|
|
10
|
-
* export type ActionCtx = {
|
|
11
|
-
* handler: string;
|
|
12
|
-
* method: string;
|
|
13
|
-
* setActionItemMessage: SetActionItemMessage;
|
|
14
|
-
* action: FormioAction;
|
|
15
|
-
* };
|
|
16
|
-
* ```
|
|
17
|
-
* @param expression
|
|
18
|
-
* @constructor
|
|
19
|
-
*/
|
|
20
|
-
export function ActionCtx(expression?: string): ParameterDecorator {
|
|
21
|
-
return Context(["ACTION_CTX", expression].filter(Boolean).join("."));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export type ActionCtx = {
|
|
25
|
-
handler: string;
|
|
26
|
-
method: string;
|
|
27
|
-
setActionItemMessage: SetActionItemMessage;
|
|
28
|
-
action: FormioAction;
|
|
29
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {Store} from "@tsed/core";
|
|
2
|
-
|
|
3
|
-
import {AlterHook} from "../domain/AlterHook.js";
|
|
4
|
-
import {Alter} from "./alter.js";
|
|
5
|
-
|
|
6
|
-
describe("@Alter", () => {
|
|
7
|
-
it("should register a hook listener", () => {
|
|
8
|
-
@Alter("custom")
|
|
9
|
-
class AlterCustom implements AlterHook {
|
|
10
|
-
transform() {}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const store = Store.from(AlterCustom);
|
|
14
|
-
expect(store.get("formio:alter:name")).toEqual("custom");
|
|
15
|
-
});
|
|
16
|
-
});
|
package/src/decorators/alter.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {StoreSet, useDecorators} from "@tsed/core";
|
|
2
|
-
import {registerProvider} from "@tsed/di";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
6
|
-
* @param name
|
|
7
|
-
* @constructor
|
|
8
|
-
*/
|
|
9
|
-
export function Alter(name: string): ClassDecorator {
|
|
10
|
-
return useDecorators(
|
|
11
|
-
(target: any) => {
|
|
12
|
-
registerProvider({
|
|
13
|
-
token: target,
|
|
14
|
-
type: "formio:alter"
|
|
15
|
-
});
|
|
16
|
-
},
|
|
17
|
-
StoreSet("formio:alter:name", name)
|
|
18
|
-
);
|
|
19
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {Store} from "@tsed/core";
|
|
2
|
-
|
|
3
|
-
import {OnHook} from "../domain/OnHook.js";
|
|
4
|
-
import {On} from "./on.js";
|
|
5
|
-
|
|
6
|
-
describe("@On", () => {
|
|
7
|
-
it("should register a hook listener", () => {
|
|
8
|
-
@On("custom")
|
|
9
|
-
class CustomEvent implements OnHook {
|
|
10
|
-
on() {}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const store = Store.from(CustomEvent);
|
|
14
|
-
expect(store.get("formio:on:name")).toEqual("custom");
|
|
15
|
-
});
|
|
16
|
-
});
|
package/src/decorators/on.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {StoreSet, useDecorators} from "@tsed/core";
|
|
2
|
-
import {registerProvider} from "@tsed/di";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Create a Form io hook event listener
|
|
6
|
-
* @param name
|
|
7
|
-
* @constructor
|
|
8
|
-
*/
|
|
9
|
-
export function On(name: string): ClassDecorator {
|
|
10
|
-
return useDecorators(
|
|
11
|
-
(target: any) => {
|
|
12
|
-
registerProvider({
|
|
13
|
-
token: target,
|
|
14
|
-
type: "formio:on"
|
|
15
|
-
});
|
|
16
|
-
},
|
|
17
|
-
StoreSet("formio:on:name", name)
|
|
18
|
-
);
|
|
19
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import {EndpointMetadata} from "@tsed/schema";
|
|
2
|
-
|
|
3
|
-
import {FormioAuthMiddleware} from "../middlewares/FormioAuthMiddleware.js";
|
|
4
|
-
import {UseFormioAuth} from "./useFormioAuth.js";
|
|
5
|
-
|
|
6
|
-
describe("UseFormioAuth", () => {
|
|
7
|
-
it("should add auth on method", () => {
|
|
8
|
-
class MyClass {
|
|
9
|
-
@UseFormioAuth()
|
|
10
|
-
get() {}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
expect(EndpointMetadata.get(MyClass, "get").beforeMiddlewares[0]).toEqual(FormioAuthMiddleware);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import {UseAuth} from "@tsed/platform-middlewares";
|
|
2
|
-
|
|
3
|
-
import {FormioAuthMiddleware} from "../middlewares/FormioAuthMiddleware.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Check if a user is connected by using the Formio Auth middleware
|
|
7
|
-
* @decorator
|
|
8
|
-
* @formio
|
|
9
|
-
*/
|
|
10
|
-
export function UseFormioAuth(): Function {
|
|
11
|
-
return UseAuth(FormioAuthMiddleware);
|
|
12
|
-
}
|
package/src/domain/AlterHook.ts
DELETED
package/src/domain/Formio.ts
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import {EventEmitter} from "events";
|
|
2
|
-
import {NextFunction, Request, Response} from "express";
|
|
3
|
-
import {Db} from "mongodb";
|
|
4
|
-
import {Mongoose, Schema} from "mongoose";
|
|
5
|
-
|
|
6
|
-
import {FormioActionModelCtor} from "./FormioAction.js";
|
|
7
|
-
import {FormioActionsIndex} from "./FormioActionsIndex.js";
|
|
8
|
-
import {FormioAuth} from "./FormioAuth.js";
|
|
9
|
-
import {FormioBaseModel} from "./FormioBaseModel.js";
|
|
10
|
-
import {FormioConfig} from "./FormioConfig.js";
|
|
11
|
-
import {FormioHook, FormioHooks} from "./FormioHooks.js";
|
|
12
|
-
import {FormioModels, FormioSchemas} from "./FormioModels.js";
|
|
13
|
-
import {FormioTemplateUtil} from "./FormioTemplateUtil.js";
|
|
14
|
-
import {FormioUpdate} from "./FormioUpdate.js";
|
|
15
|
-
import {FormioUtil} from "./FormioUtils.js";
|
|
16
|
-
|
|
17
|
-
export interface FormioBase {
|
|
18
|
-
/**
|
|
19
|
-
* Auth
|
|
20
|
-
*/
|
|
21
|
-
auth: FormioAuth;
|
|
22
|
-
/**
|
|
23
|
-
* Event emitter
|
|
24
|
-
*/
|
|
25
|
-
events: EventEmitter;
|
|
26
|
-
/**
|
|
27
|
-
* Formio configuration
|
|
28
|
-
*/
|
|
29
|
-
config: FormioConfig & {schema: string};
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Emit alter `log` event. Return false to disable event logging.
|
|
33
|
-
* @param event
|
|
34
|
-
* @param req
|
|
35
|
-
* @param info
|
|
36
|
-
*/
|
|
37
|
-
log(event: string, req: Request, ...info: any[]): void;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Emit alter `audit` event if `config.audit` is enabled. Return false to disable event logging.
|
|
41
|
-
* Use `console.log`.
|
|
42
|
-
* @param event
|
|
43
|
-
* @param req
|
|
44
|
-
* @param info
|
|
45
|
-
*/
|
|
46
|
-
audit(event: string, req: Request, ...info: any[]): void;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface FormioMiddlewares {
|
|
50
|
-
alias(req: Request, res: Response, next: NextFunction): void;
|
|
51
|
-
|
|
52
|
-
params(req: Request, res: Response, next: NextFunction): void;
|
|
53
|
-
|
|
54
|
-
accessHandler(req: Request, res: Response, next: NextFunction): void;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Authorize all urls based on roles and permissions.
|
|
58
|
-
* @param req
|
|
59
|
-
* @param res
|
|
60
|
-
* @param next
|
|
61
|
-
*/
|
|
62
|
-
permissionHandler(req: Request, res: Response, next: NextFunction): void;
|
|
63
|
-
|
|
64
|
-
restrictRequestTypes(req: Request, res: Response, next: NextFunction): void;
|
|
65
|
-
tokenHandler(req: Request, res: Response, next: NextFunction): void;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export interface Formio extends FormioBase {
|
|
69
|
-
Action: FormioActionModelCtor;
|
|
70
|
-
BaseModel: FormioBaseModel;
|
|
71
|
-
actions: FormioActionsIndex;
|
|
72
|
-
resources: any;
|
|
73
|
-
/**
|
|
74
|
-
* Database connection
|
|
75
|
-
*/
|
|
76
|
-
db: Db;
|
|
77
|
-
|
|
78
|
-
schemas: FormioSchemas & {
|
|
79
|
-
AccessSchema: Schema;
|
|
80
|
-
PermissionSchema: Schema;
|
|
81
|
-
FieldMatchAccessPermissionSchema: Schema;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
models: FormioModels;
|
|
85
|
-
/**
|
|
86
|
-
* Mongoose lib.
|
|
87
|
-
*/
|
|
88
|
-
mongoose: Mongoose;
|
|
89
|
-
/**
|
|
90
|
-
* Exported formio middlewares
|
|
91
|
-
*/
|
|
92
|
-
readonly middleware: FormioMiddlewares;
|
|
93
|
-
/**
|
|
94
|
-
* Hooks.
|
|
95
|
-
*/
|
|
96
|
-
hooks: FormioHooks;
|
|
97
|
-
/**
|
|
98
|
-
* Plugins.
|
|
99
|
-
*/
|
|
100
|
-
plugins: any;
|
|
101
|
-
/**
|
|
102
|
-
* Formio hook util.
|
|
103
|
-
*/
|
|
104
|
-
readonly hook: FormioHook;
|
|
105
|
-
/**
|
|
106
|
-
* The formio utils.
|
|
107
|
-
*/
|
|
108
|
-
readonly util: FormioUtil;
|
|
109
|
-
/**
|
|
110
|
-
* Update system.
|
|
111
|
-
*/
|
|
112
|
-
readonly update: FormioUpdate;
|
|
113
|
-
/**
|
|
114
|
-
* Template export/import
|
|
115
|
-
*/
|
|
116
|
-
readonly template: FormioTemplateUtil;
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Encryption system.
|
|
120
|
-
*/
|
|
121
|
-
encrypt(text: string, next: (err: null | Error, hash: string) => void): void;
|
|
122
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import {FormioAction, FormioActionInfo} from "@tsed/formio-types";
|
|
2
|
-
import {Request, Response} from "express";
|
|
3
|
-
|
|
4
|
-
import {FormioMongooseSchema} from "./FormioBaseModel.js";
|
|
5
|
-
import {FormioComponent} from "./FormioModels.js";
|
|
6
|
-
|
|
7
|
-
export interface FormioActionModel extends FormioAction {
|
|
8
|
-
resolve(handler: string, method: string, req: Request, res: Response, next: Function, setActionItemMessage: SetActionItemMessage): void;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type FormioActionMongooseSchema = FormioMongooseSchema<FormioAction>;
|
|
12
|
-
export type SetActionItemMessage = (message: string, data?: any, state?: any) => void;
|
|
13
|
-
|
|
14
|
-
export interface FormioActionModelCtor {
|
|
15
|
-
schema?: FormioActionMongooseSchema;
|
|
16
|
-
|
|
17
|
-
info(req: Request, response: Response, next: (err: any, info: FormioActionInfo) => void): void;
|
|
18
|
-
|
|
19
|
-
settingsForm(req: Request, response: Response, next: (err: any, info: FormioComponent[]) => void): void;
|
|
20
|
-
|
|
21
|
-
new (data: FormioAction, req: Request, res: Response): FormioActionModel;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface ActionMethods {
|
|
25
|
-
info?(req: Request, response: Response): Promise<FormioAction>;
|
|
26
|
-
|
|
27
|
-
settingsForm(req: Request, response: Response): Promise<FormioComponent[]>;
|
|
28
|
-
|
|
29
|
-
resolve(...args: any[]): Promise<any>;
|
|
30
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {Type} from "@tsed/core";
|
|
2
|
-
|
|
3
|
-
import {FormioActionModelCtor} from "./FormioAction.js";
|
|
4
|
-
|
|
5
|
-
export interface FormioActions {
|
|
6
|
-
email: FormioActionModelCtor;
|
|
7
|
-
login: FormioActionModelCtor;
|
|
8
|
-
resetpass: FormioActionModelCtor;
|
|
9
|
-
role: FormioActionModelCtor;
|
|
10
|
-
save: FormioActionModelCtor;
|
|
11
|
-
sql: FormioActionModelCtor;
|
|
12
|
-
webhook: FormioActionModelCtor;
|
|
13
|
-
|
|
14
|
-
[key: string]: FormioActionModelCtor;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface FormioActionsIndex {
|
|
18
|
-
actions: FormioActions & Record<string, Type<FormioActionModelCtor>>;
|
|
19
|
-
}
|