@tsed/formio 7.0.0-beta.9 → 7.0.0-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/jest.config.js +14 -0
- package/lib/cjs/FormioModule.js +18 -14
- package/lib/cjs/FormioModule.js.map +1 -1
- package/lib/cjs/builder/FormioMapper.js +2 -1
- package/lib/cjs/builder/FormioMapper.js.map +1 -1
- package/lib/cjs/components/AlterActions.js +47 -41
- package/lib/cjs/components/AlterActions.js.map +1 -1
- package/lib/cjs/components/AlterSkip.js +2 -0
- package/lib/cjs/components/AlterSkip.js.map +1 -1
- package/lib/cjs/components/AlterTemplateExportSteps.js +1 -0
- package/lib/cjs/components/AlterTemplateExportSteps.js.map +1 -1
- package/lib/cjs/components/AlterTemplateImportSteps.js +1 -0
- package/lib/cjs/components/AlterTemplateImportSteps.js.map +1 -1
- package/lib/cjs/middlewares/FormioAuthMiddleware.js +1 -0
- package/lib/cjs/middlewares/FormioAuthMiddleware.js.map +1 -1
- package/lib/cjs/services/FormioAuthService.js +4 -1
- package/lib/cjs/services/FormioAuthService.js.map +1 -1
- package/lib/cjs/services/FormioDatabase.js +1 -0
- package/lib/cjs/services/FormioDatabase.js.map +1 -1
- package/lib/cjs/services/FormioHooksService.js +2 -0
- package/lib/cjs/services/FormioHooksService.js.map +1 -1
- package/lib/cjs/services/FormioInstaller.js +2 -7
- package/lib/cjs/services/FormioInstaller.js.map +1 -1
- package/lib/cjs/services/FormioRepository.js +2 -0
- package/lib/cjs/services/FormioRepository.js.map +1 -1
- package/lib/cjs/services/FormioService.js +2 -0
- package/lib/cjs/services/FormioService.js.map +1 -1
- package/lib/esm/FormioModule.js +18 -14
- package/lib/esm/FormioModule.js.map +1 -1
- package/lib/esm/builder/FormioMapper.js +2 -1
- package/lib/esm/builder/FormioMapper.js.map +1 -1
- package/lib/esm/components/AlterActions.js +47 -41
- package/lib/esm/components/AlterActions.js.map +1 -1
- package/lib/esm/components/AlterSkip.js +2 -0
- package/lib/esm/components/AlterSkip.js.map +1 -1
- package/lib/esm/components/AlterTemplateExportSteps.js +1 -0
- package/lib/esm/components/AlterTemplateExportSteps.js.map +1 -1
- package/lib/esm/components/AlterTemplateImportSteps.js +1 -0
- package/lib/esm/components/AlterTemplateImportSteps.js.map +1 -1
- package/lib/esm/middlewares/FormioAuthMiddleware.js +1 -0
- package/lib/esm/middlewares/FormioAuthMiddleware.js.map +1 -1
- package/lib/esm/services/FormioAuthService.js +4 -1
- package/lib/esm/services/FormioAuthService.js.map +1 -1
- package/lib/esm/services/FormioDatabase.js +1 -0
- package/lib/esm/services/FormioDatabase.js.map +1 -1
- package/lib/esm/services/FormioHooksService.js +2 -0
- package/lib/esm/services/FormioHooksService.js.map +1 -1
- package/lib/esm/services/FormioInstaller.js +2 -7
- package/lib/esm/services/FormioInstaller.js.map +1 -1
- package/lib/esm/services/FormioRepository.js +2 -0
- package/lib/esm/services/FormioRepository.js.map +1 -1
- package/lib/esm/services/FormioService.js +2 -0
- package/lib/esm/services/FormioService.js.map +1 -1
- package/lib/types/components/AlterActions.d.ts +2 -4
- package/lib/types/services/FormioAuthService.d.ts +23 -4
- package/lib/types/services/FormioDatabase.d.ts +24 -7
- package/lib/types/services/FormioInstaller.d.ts +0 -2
- package/lib/types/services/FormioRepository.d.ts +19 -2
- package/package.json +14 -11
- package/readme.md +3 -2
- package/.mocharc.js +0 -5
- package/.nycrc +0 -27
|
@@ -5,8 +5,8 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const di_1 = require("@tsed/di");
|
|
6
6
|
const logger_1 = require("@tsed/logger");
|
|
7
7
|
const FormioDatabase_1 = require("./FormioDatabase");
|
|
8
|
-
const FormioService_1 = require("./FormioService");
|
|
9
8
|
let FormioInstaller = class FormioInstaller extends FormioDatabase_1.FormioDatabase {
|
|
9
|
+
logger;
|
|
10
10
|
async install(template, root) {
|
|
11
11
|
this.logger.info("Install formio template...");
|
|
12
12
|
template = await this.formio.importTemplate(template);
|
|
@@ -18,14 +18,13 @@ let FormioInstaller = class FormioInstaller extends FormioDatabase_1.FormioDatab
|
|
|
18
18
|
async createRootUser(user, template) {
|
|
19
19
|
const hash = await this.formio.encrypt(user.password);
|
|
20
20
|
return new Promise((resolve, reject) => {
|
|
21
|
-
var _a;
|
|
22
21
|
this.formio.resources.submission.model.create({
|
|
23
22
|
form: template.resources.admin._id,
|
|
24
23
|
data: {
|
|
25
24
|
email: user.email,
|
|
26
25
|
password: hash
|
|
27
26
|
},
|
|
28
|
-
roles: [
|
|
27
|
+
roles: [template.roles?.administrator._id].filter(Boolean)
|
|
29
28
|
}, (err, item) => {
|
|
30
29
|
if (err) {
|
|
31
30
|
return reject(err);
|
|
@@ -35,10 +34,6 @@ let FormioInstaller = class FormioInstaller extends FormioDatabase_1.FormioDatab
|
|
|
35
34
|
});
|
|
36
35
|
}
|
|
37
36
|
};
|
|
38
|
-
tslib_1.__decorate([
|
|
39
|
-
(0, di_1.Inject)(),
|
|
40
|
-
tslib_1.__metadata("design:type", FormioService_1.FormioService)
|
|
41
|
-
], FormioInstaller.prototype, "formio", void 0);
|
|
42
37
|
tslib_1.__decorate([
|
|
43
38
|
(0, di_1.Inject)(),
|
|
44
39
|
tslib_1.__metadata("design:type", logger_1.Logger)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormioInstaller.js","sourceRoot":"","sources":["../../../src/services/FormioInstaller.ts"],"names":[],"mappings":";;;;AAAA,iCAA4C;AAC5C,yCAAoC;AAGpC,qDAAgD;
|
|
1
|
+
{"version":3,"file":"FormioInstaller.js","sourceRoot":"","sources":["../../../src/services/FormioInstaller.ts"],"names":[],"mappings":";;;;AAAA,iCAA4C;AAC5C,yCAAoC;AAGpC,qDAAgD;AAGhD,IAAa,eAAe,GAA5B,MAAa,eAAgB,SAAQ,+BAAc;IAEvC,MAAM,CAAS;IAEzB,KAAK,CAAC,OAAO,CAAC,QAAwB,EAAE,IAAS;QAC/C,IAAI,CAAC,MAAM,CA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} from \"@tsed/logger\";\nimport {FormioSubmission} from \"../domain/FormioModels\";\nimport {FormioTemplate} from \"../domain/FormioTemplate\";\nimport {FormioDatabase} from \"./FormioDatabase\";\n\n@Injectable()\nexport class FormioInstaller extends FormioDatabase {\n @Inject()\n protected logger: Logger;\n\n async install(template: FormioTemplate, root: any) {\n this.logger.info(\"Install formio template...\");\n template = await this.formio.importTemplate(template);\n\n if (root) {\n this.logger.info(\"Create root user...\");\n await this.createRootUser(root, template);\n }\n }\n\n async createRootUser<User = unknown>(user: {email: string; password: string}, template: FormioTemplate): Promise<FormioSubmission<User>> {\n const hash = await this.formio.encrypt(user.password);\n\n return new Promise((resolve, reject) => {\n this.formio.resources.submission.model.create(\n {\n form: template.resources.admin._id,\n data: {\n email: user.email,\n password: hash\n },\n roles: [template.roles?.administrator._id].filter(Boolean)\n },\n (err: unknown, item: any) => {\n if (err) {\n return reject(err);\n }\n\n resolve(item);\n }\n );\n });\n }\n}\n"]}
|
|
@@ -5,6 +5,8 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const di_1 = require("@tsed/di");
|
|
6
6
|
const FormioDatabase_1 = require("./FormioDatabase");
|
|
7
7
|
class FormioRepository {
|
|
8
|
+
formioDatabase;
|
|
9
|
+
formId;
|
|
8
10
|
async getFormId() {
|
|
9
11
|
if (!this.formId) {
|
|
10
12
|
const form = await this.formioDatabase.formModel.findOne({ name: { $eq: this.formName } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormioRepository.js","sourceRoot":"","sources":["../../../src/services/FormioRepository.ts"],"names":[],"mappings":";;;;AACA,iCAAgC;AAGhC,qDAAgD;AAEhD,MAAsB,gBAAgB;
|
|
1
|
+
{"version":3,"file":"FormioRepository.js","sourceRoot":"","sources":["../../../src/services/FormioRepository.ts"],"names":[],"mappings":";;;;AACA,iCAAgC;AAGhC,qDAAgD;AAEhD,MAAsB,gBAAgB;IAE1B,cAAc,CAAiB;IAIjC,MAAM,CAAS;IAEvB,KAAK,CAAC,SAAS;QACb,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YAChB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,OAAO,CAAC,EAAC,IAAI,EAAE,EAAC,GAAG,EAAE,IAAI,CAAC,QAAQ,EAAC,EAAC,CAAC,CAAC;YAEvF,IAAI,IAAI,EAAE;gBACR,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC;aACxB;SACF;QAED,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,UAAkF;QACrG,OAAO,IAAI,CAAC,cAAc,CAAC,cAAc,CAAiB;YACxD,GAAG,UAAU;YACb,IAAI,EAAE,UAAU,CAAC,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;SAClD,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,QAAsE,EAAE;QAC3F,OAAO,IAAI,CAAC,cAAc,CAAC,cAAc,CAAiB;YACxD,GAAG,KAAK;YACR,IAAI,EAAE,MAAM,IAAI,CAAC,SAAS,EAAE;SAC7B,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,KAAU;QAChC,OAAO,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,OAAO,CAAC;YACjD,IAAI,EAAE,MAAM,IAAI,CAAC,SAAS,EAAE;YAC5B,OAAO,EAAE,IAAI;YACb,GAAG,KAAK;SACT,CAAQ,CAAC;IACZ,CAAC;CACF;AAvCC;IADC,IAAA,WAAM,GAAE;sCACiB,+BAAc;wDAAC;AAF3C,4CAyCC","sourcesContent":["import type {FilterQuery} from \"mongoose\";\nimport {Inject} from \"@tsed/di\";\nimport {MongooseDocument, MongooseModel} from \"@tsed/mongoose\";\nimport {FormioSubmission} from \"../domain/FormioModels\";\nimport {FormioDatabase} from \"./FormioDatabase\";\n\nexport abstract class FormioRepository<SubmissionData = any> {\n @Inject()\n protected formioDatabase: FormioDatabase;\n\n protected abstract formName: string;\n\n private formId: string;\n\n async getFormId() {\n if (!this.formId) {\n const form = await this.formioDatabase.formModel.findOne({name: {$eq: this.formName}});\n\n if (form) {\n this.formId = form._id;\n }\n }\n\n return this.formId;\n }\n\n async saveSubmission(submission: Omit<Partial<FormioSubmission<SubmissionData>>, \"form\"> & {form?: any}) {\n return this.formioDatabase.saveSubmission<SubmissionData>({\n ...submission,\n form: submission.form || (await this.getFormId())\n });\n }\n\n async getSubmissions(query: FilterQuery<MongooseModel<FormioSubmission<SubmissionData>>> = {}) {\n return this.formioDatabase.getSubmissions<SubmissionData>({\n ...query,\n form: await this.getFormId()\n });\n }\n\n async findOneSubmission(query: any): Promise<MongooseDocument<FormioSubmission<SubmissionData>> | undefined> {\n return this.formioDatabase.submissionModel.findOne({\n form: await this.getFormId(),\n deleted: null,\n ...query\n }) as any;\n }\n}\n"]}
|
|
@@ -11,6 +11,8 @@ const swagger_js_1 = tslib_1.__importDefault(require("formio/src/util/swagger.js
|
|
|
11
11
|
// @ts-ignore
|
|
12
12
|
const util_js_1 = tslib_1.__importDefault(require("formio/src/util/util.js"));
|
|
13
13
|
let FormioService = class FormioService {
|
|
14
|
+
router;
|
|
15
|
+
injector;
|
|
14
16
|
get audit() {
|
|
15
17
|
return this.formio.audit || (() => { });
|
|
16
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormioService.js","sourceRoot":"","sources":["../../../src/services/FormioService.ts"],"names":[],"mappings":";;;;AAAA,yCAAiE;AAIjE,+BAA+B;AAQ/B,aAAa;AACb,4DAAkC;AAClC,aAAa;AACb,oFAAiD;AACjD,aAAa;AACb,8EAA2C;AAG3C,IAAa,aAAa,GAA1B,MAAa,aAAa;
|
|
1
|
+
{"version":3,"file":"FormioService.js","sourceRoot":"","sources":["../../../src/services/FormioService.ts"],"names":[],"mappings":";;;;AAAA,yCAAiE;AAIjE,+BAA+B;AAQ/B,aA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B,GAAG,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAA4B,YAAY,CAAC,CAAC;QAExF,IAAI,gBAAgB,EAAE;YACpB,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,gBAAgB,CAAC,GAAG,CAAC;YACtD,OAAO,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;SACjG;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAES,UAAU;QAClB,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC;QAExB,iBAAI,CAAC,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACtD,iBAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3D,CAAC;CACF,CAAA;AA3GC;IADC,IAAA,eAAM,GAAE;sCACW,wBAAe;+CAAC;AAJzB,aAAa;IADzB,IAAA,mBAAU,GAAE;GACA,aAAa,CA+GzB;AA/GY,sCAAa","sourcesContent":["import {Inject, Injectable, InjectorService} from \"@tsed/common\";\nimport {MongooseConnectionOptions} from \"@tsed/mongoose\";\nimport {Db} from \"mongodb\";\nimport {Mongoose} from \"mongoose\";\nimport {promisify} from \"util\";\nimport {Formio} from \"../domain/Formio\";\nimport {FormioConfig} from \"../domain/FormioConfig\";\nimport {FormioHook, FormioHooks} from \"../domain/FormioHooks\";\nimport {FormioSchemas} from \"../domain/FormioModels\";\nimport {FormioRouter} from \"../domain/FormioRouter\";\nimport {FormioTemplate} from \"../domain/FormioTemplate\";\nimport {FormioExportOptions} from \"../domain/FormioTemplateUtil\";\n// @ts-ignore\nimport createRouter from \"formio\";\n// @ts-ignore\nimport swagger from \"formio/src/util/swagger.js\";\n// @ts-ignore\nimport util from \"formio/src/util/util.js\";\n\n@Injectable()\nexport class FormioService {\n router: FormioRouter;\n\n @Inject()\n protected injector: InjectorService;\n\n get audit(): Function {\n return this.formio.audit || (() => {});\n }\n\n get auth() {\n return this.formio.auth;\n }\n\n // istanbul ignore next\n get swagger() {\n return (...args: any[]) => new Promise((resolve) => swagger(...args, resolve));\n }\n\n get config(): FormioConfig {\n return this.formio.config;\n }\n\n get db(): Db {\n return this.formio.db;\n }\n\n get resources() {\n return this.formio.resources;\n }\n\n get mongoose(): Mongoose {\n return this.formio.mongoose;\n }\n\n get middleware() {\n return this.formio.middleware;\n }\n\n get schemas(): FormioSchemas {\n return this.formio.schemas;\n }\n\n get formio(): Formio {\n return this.router.formio as Formio;\n }\n\n get hook(): FormioHook {\n return this.formio.hook;\n }\n\n get util() {\n return this.formio.util;\n }\n\n get template() {\n return this.formio.template;\n }\n\n get Action() {\n return this.formio.Action;\n }\n\n async exportTemplate(options: Partial<FormioExportOptions> = {}): Promise<FormioTemplate> {\n return promisify(this.formio.template.export)(options);\n }\n\n async importTemplate(template: FormioTemplate): Promise<FormioTemplate> {\n return promisify(this.formio.template.import.template)(template);\n }\n\n encrypt(text: string) {\n return promisify(this.formio.encrypt)(text);\n }\n\n isInit() {\n return !!this.router;\n }\n\n // istanbul ignore next\n public createRouter(options: FormioConfig) {\n return createRouter(options);\n }\n\n public init(options: FormioConfig, hooks: FormioHooks = {}) {\n if (options && Object.keys(options).length) {\n this.router = this.createRouter(this.mapConfiguration(options));\n this.bindLogger();\n\n return this.router.init(hooks);\n }\n }\n\n protected mapConfiguration(options: FormioConfig) {\n const {injector} = this;\n const mongooseSettings = injector.settings.get<MongooseConnectionOptions>(\"mongoose.0\");\n\n if (mongooseSettings) {\n options.mongo = options.mongo || mongooseSettings.url;\n options.mongoConfig = options.mongoConfig || JSON.stringify(mongooseSettings.connectionOptions);\n }\n\n return options;\n }\n\n protected bindLogger() {\n const {injector} = this;\n\n util.log = injector.logger.info.bind(injector.logger);\n util.error = injector.logger.error.bind(injector.logger);\n }\n}\n"]}
|
package/lib/esm/FormioModule.js
CHANGED
|
@@ -14,6 +14,16 @@ import { FormioHooksService } from "./services/FormioHooksService.js";
|
|
|
14
14
|
import { FormioInstaller } from "./services/FormioInstaller.js";
|
|
15
15
|
import { FormioService } from "./services/FormioService.js";
|
|
16
16
|
let FormioModule = class FormioModule {
|
|
17
|
+
formio;
|
|
18
|
+
hooks;
|
|
19
|
+
installer;
|
|
20
|
+
app;
|
|
21
|
+
injector;
|
|
22
|
+
settings;
|
|
23
|
+
baseUrl;
|
|
24
|
+
skipInstall;
|
|
25
|
+
template;
|
|
26
|
+
root;
|
|
17
27
|
$onInit() {
|
|
18
28
|
return this.init(deepClone(this.settings));
|
|
19
29
|
}
|
|
@@ -22,8 +32,7 @@ let FormioModule = class FormioModule {
|
|
|
22
32
|
}
|
|
23
33
|
async $onRoutesInit() {
|
|
24
34
|
if (this.formio.isInit()) {
|
|
25
|
-
|
|
26
|
-
router.use(this.baseUrl, this.formio.middleware.restrictRequestTypes, this.formio.router);
|
|
35
|
+
this.app.use(this.baseUrl, this.formio.middleware.restrictRequestTypes, this.formio.router);
|
|
27
36
|
if (await this.shouldInstall()) {
|
|
28
37
|
await this.installer.install(this.template, this.root);
|
|
29
38
|
}
|
|
@@ -43,17 +52,11 @@ let FormioModule = class FormioModule {
|
|
|
43
52
|
Object.entries(spec.paths).forEach(([path, methods]) => {
|
|
44
53
|
Object.entries(methods).forEach(([method, operation]) => {
|
|
45
54
|
routes.push({
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
className: "formio",
|
|
52
|
-
methodClassName: operation.operationId,
|
|
53
|
-
parameters: [],
|
|
54
|
-
rawBody: false
|
|
55
|
-
};
|
|
56
|
-
}
|
|
55
|
+
method,
|
|
56
|
+
name: operation.operationId,
|
|
57
|
+
url: normalizePath(baseUrl, path.replace(/\/{(.*)}/gi, "/:$1")),
|
|
58
|
+
className: "formio",
|
|
59
|
+
methodClassName: operation.operationId
|
|
57
60
|
});
|
|
58
61
|
});
|
|
59
62
|
});
|
|
@@ -62,8 +65,9 @@ let FormioModule = class FormioModule {
|
|
|
62
65
|
}
|
|
63
66
|
// istanbul ignore next
|
|
64
67
|
async $onReady() {
|
|
65
|
-
if (this.formio.isInit() && this.injector.settings
|
|
68
|
+
if (this.formio.isInit() && "getBestHost" in this.injector.settings) {
|
|
66
69
|
const { injector } = this;
|
|
70
|
+
// @ts-ignore
|
|
67
71
|
const host = injector.settings.getBestHost();
|
|
68
72
|
const url = host.toString();
|
|
69
73
|
injector.logger.info(`Form.io API is available on ${url}${this.baseUrl || "/"}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormioModule.js","sourceRoot":"","sources":["../../src/FormioModule.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,QAAQ,EACR,MAAM,EACN,eAAe,EACf,aAAa,EAGb,mBAAmB,EAEpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,SAAS,EAAC,MAAM,YAAY,CAAC;AACrC,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,YAAY,EAAC,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAC,SAAS,EAAC,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAC,QAAQ,EAAC,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAC,SAAS,EAAC,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAC,wBAAwB,EAAC,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAC,wBAAwB,EAAC,MAAM,uCAAuC,CAAC;AAG/E,OAAO,EAAC,iBAAiB,EAAC,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAC,kBAAkB,EAAC,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAC,eAAe,EAAC,MAAM,4BAA4B,CAAC;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,eAAe;8CAAC;AAGpC;IADC,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC;;8CACU;AAGjC;IADC,QAAQ,CAAC,gBAAgB,EAAE,GAAG,CAAC;;6CACN;AAG1B;IADC,QAAQ,CAAC,oBAAoB,EAAE,KAAK,CAAC;;iDACP;AAG/B;IADC,QAAQ,CAAC,iBAAiB,CAAC;;8CACQ;AAGpC;IADC,QAAQ,CAAC,aAAa,CAAC;;0CACH;AA7BV,YAAY;IAdxB,MAAM,CAAC;QACN,OAAO,EAAE;YACP,aAAa;YACb,kBAAkB;YAClB,iBAAiB;YACjB,YAAY;YACZ,SAAS;YACT,UAAU;YACV,QAAQ;YACR,SAAS;YACT,wBAAwB;YACxB,wBAAwB;SACzB;KACF,CAAC;GACW,YAAY,CAgGxB;SAhGY,YAAY","sourcesContent":["import {\n Constant,\n Inject,\n InjectorService,\n normalizePath,\n OnReady,\n OnRoutesInit,\n PlatformApplication,\n PlatformRouteDetails\n} from \"@tsed/common\";\nimport {deepClone} from \"@tsed/core\";\nimport {Module} from \"@tsed/di\";\nimport {AlterActions} from \"./components/AlterActions\";\nimport {AlterAudit} from \"./components/AlterAudit\";\nimport {AlterHost} from \"./components/AlterHost\";\nimport {AlterLog} from \"./components/AlterLog\";\nimport {AlterSkip} from \"./components/AlterSkip\";\nimport {AlterTemplateExportSteps} from \"./components/AlterTemplateExportSteps\";\nimport {AlterTemplateImportSteps} from \"./components/AlterTemplateImportSteps\";\nimport {FormioConfig} from \"./domain/FormioConfig\";\nimport {FormioTemplate} from \"./domain/FormioTemplate\";\nimport {FormioAuthService} from \"./services/FormioAuthService\";\nimport {FormioHooksService} from \"./services/FormioHooksService\";\nimport {FormioInstaller} from \"./services/FormioInstaller\";\nimport {FormioService} from \"./services/FormioService\";\n\n@Module({\n imports: [\n FormioService,\n FormioHooksService,\n FormioAuthService,\n AlterActions,\n AlterHost,\n AlterAudit,\n AlterLog,\n AlterSkip,\n AlterTemplateImportSteps,\n AlterTemplateExportSteps\n ]\n})\nexport class FormioModule implements OnRoutesInit, OnReady {\n @Inject()\n protected formio: FormioService;\n\n @Inject()\n protected hooks: FormioHooksService;\n\n @Inject()\n protected installer: FormioInstaller;\n\n @Inject()\n protected app: PlatformApplication;\n\n @Inject()\n protected injector: InjectorService;\n\n @Constant(\"formio\", {})\n protected settings: FormioConfig;\n\n @Constant(\"formio.baseUrl\", \"/\")\n protected baseUrl: string;\n\n @Constant(\"formio.skipInstall\", false)\n protected skipInstall: boolean;\n\n @Constant(\"formio.template\")\n protected template?: FormioTemplate;\n\n @Constant(\"formio.root\")\n protected root?: any;\n\n $onInit() {\n return this.init(deepClone(this.settings));\n }\n\n async init(options: FormioConfig) {\n return this.formio.init(options, this.hooks.getHooks());\n }\n\n async $onRoutesInit() {\n if (this.formio.isInit()) {\n this.app.use(this.baseUrl, this.formio.middleware.restrictRequestTypes, this.formio.router);\n\n if (await this.shouldInstall()) {\n await this.installer.install(this.template!, this.root);\n }\n }\n }\n\n async $logRoutes(routes: PlatformRouteDetails[]): Promise<PlatformRouteDetails[]> {\n if (this.formio.isInit()) {\n const spec = (await this.formio.swagger(\n {\n $ctx: {\n request: {\n protocol: \"http\",\n host: \"localhost\"\n }\n }\n },\n this.formio.router\n )) as any;\n const {baseUrl} = this;\n\n Object.entries(spec.paths).forEach(([path, methods]: [string, any]) => {\n Object.entries(methods).forEach(([method, operation]: [string, any]) => {\n routes.push({\n method,\n name: operation.operationId,\n url: normalizePath(baseUrl, path.replace(/\\/{(.*)}/gi, \"/:$1\")),\n className: \"formio\",\n methodClassName: operation.operationId\n });\n });\n });\n }\n\n return routes;\n }\n\n // istanbul ignore next\n async $onReady(): Promise<void> {\n if (this.formio.isInit() && \"getBestHost\" in this.injector.settings) {\n const {injector} = this;\n // @ts-ignore\n const host = injector.settings.getBestHost();\n const url = host.toString();\n\n injector.logger.info(`Form.io API is available on ${url}${this.baseUrl || \"/\"}`);\n }\n }\n\n protected async shouldInstall() {\n const hasForms = await this.installer.hasForms();\n return this.template && !(hasForms || this.skipInstall);\n }\n}\n"]}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export class FormioMapper {
|
|
2
|
+
ctxData;
|
|
2
3
|
constructor(ctxData) {
|
|
3
4
|
this.ctxData = ctxData;
|
|
4
5
|
}
|
|
5
6
|
find(key) {
|
|
6
7
|
const store = Object.values(this.ctxData).find((store) => store.get(key));
|
|
7
|
-
return store
|
|
8
|
+
return store?.get(key);
|
|
8
9
|
}
|
|
9
10
|
findId(data) {
|
|
10
11
|
const key = String(data).startsWith("$machineName:") ? String(data) : `$machineName:${String(data)}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormioMapper.js","sourceRoot":"","sources":["../../../src/builder/FormioMapper.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,YAAY;
|
|
1
|
+
{"version":3,"file":"FormioMapper.js","sourceRoot":"","sources":["../../../src/builder/FormioMapper.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,YAAY;IACF;IAArB,YAAqB,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;IAAG,CAAC;IAEjD,IAAI,CAAC,GAAW;QACd,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QAE1E,OAAO,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IAED,MAAM,CAAC,IAAY;QACjB,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,gBAAgB,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QACrG,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAE5B,OA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,MAAM,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC;YACtC,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;gBAC/D,OAAO;oBACL,GAAG,GAAG;oBACN,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC;iBACrC,CAAC;YACJ,CAAC,EAAE,EAAE,CAAC,CAAC;YAEP,OAAO,MAAM;gBACX,CAAC,CAAC;oBACE,GAAG,MAAM;oBACT,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,IAAI;iBAC3C;gBACH,CAAC,CAAC,MAAM,CAAC;SACZ;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import {FormioCtxMapper} from \"../domain/FormioCtxMapper\";\n\nexport class FormioMapper {\n constructor(readonly ctxData: FormioCtxMapper) {}\n\n find(key: string) {\n const store = Object.values(this.ctxData).find((store) => store.get(key));\n\n return store?.get(key);\n }\n\n findId(data: string) {\n const key = String(data).startsWith(\"$machineName:\") ? String(data) : `$machineName:${String(data)}`;\n const item = this.find(key);\n\n return item ? item._id : undefined;\n }\n\n findMachineName(data: any) {\n const key = String(data);\n const item: any = this.find(key);\n\n return item ? `$machineName:${item.name || item.machineName}` : undefined;\n }\n\n mapToExport(data: any) {\n return this.mapData(data, this.findMachineName.bind(this));\n }\n\n mapToImport(data: any) {\n return this.mapData(data, this.findId.bind(this));\n }\n\n mapData(data: any, resolver: any): any {\n if (!data) {\n return data;\n }\n\n if (Array.isArray(data)) {\n return data.map((item) => {\n return this.mapData(item, resolver);\n });\n }\n\n const key = resolver(data, this.ctxData);\n\n if (key) {\n return key;\n }\n\n if (typeof data === \"object\" && !(\"_bsontype\" in data) && !(data instanceof Date)) {\n const isForm = data.path && data.type;\n const mapped = Object.entries(data).reduce((obj, [key, value]) => {\n return {\n ...obj,\n [key]: this.mapData(value, resolver)\n };\n }, {});\n\n return isForm\n ? {\n ...mapped,\n name: data.name,\n machineName: data.machineName || data.name\n }\n : mapped;\n }\n\n return data;\n }\n}\n"]}
|
|
@@ -1,39 +1,41 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { setResponseHeaders } from "@tsed/common";
|
|
3
|
+
import { AnyToPromise, AnyToPromiseStatus } from "@tsed/core";
|
|
2
4
|
import { Inject, InjectorService } from "@tsed/di";
|
|
3
|
-
import { EndpointMetadata } from "@tsed/schema";
|
|
4
5
|
import { PlatformParams } from "@tsed/platform-params";
|
|
5
6
|
import { PlatformResponseFilter } from "@tsed/platform-response-filter";
|
|
6
|
-
import {
|
|
7
|
-
import { setResponseHeaders } from "@tsed/common";
|
|
7
|
+
import { EndpointMetadata } from "@tsed/schema";
|
|
8
8
|
import { Alter } from "../decorators/alter.js";
|
|
9
9
|
import { FormioService } from "../services/FormioService.js";
|
|
10
10
|
let AlterActions = class AlterActions {
|
|
11
|
+
injector;
|
|
12
|
+
formio;
|
|
13
|
+
params;
|
|
14
|
+
responseFilter;
|
|
11
15
|
transform(actions) {
|
|
12
16
|
const { Action } = this.formio;
|
|
13
17
|
return this.getActions().reduce((actions, provider) => {
|
|
14
|
-
var _a;
|
|
15
18
|
const instance = this.injector.invoke(provider.token);
|
|
16
19
|
const options = provider.store.get("formio:action");
|
|
17
20
|
const resolveHandler = this.createHandler(provider, "resolve");
|
|
18
21
|
return {
|
|
19
22
|
...actions,
|
|
20
|
-
[options.name]:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
next(null, opts);
|
|
27
|
-
}
|
|
28
|
-
static async settingsForm(req, res, next) {
|
|
29
|
-
next(null, await instance.settingsForm(req, res));
|
|
23
|
+
[options.name]: class extends Action {
|
|
24
|
+
static access = options.access;
|
|
25
|
+
static async info(req, res, next) {
|
|
26
|
+
let opts = { ...options };
|
|
27
|
+
if (instance.info) {
|
|
28
|
+
opts = await instance.info(opts, req, res);
|
|
30
29
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
next(null, opts);
|
|
31
|
+
}
|
|
32
|
+
static async settingsForm(req, res, next) {
|
|
33
|
+
next(null, await instance.settingsForm(req, res));
|
|
34
|
+
}
|
|
35
|
+
resolve(handler, method, req, res, next, setActionItemMessage) {
|
|
36
|
+
resolveHandler(this, handler, method, req, res, next, setActionItemMessage);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
37
39
|
};
|
|
38
40
|
}, actions);
|
|
39
41
|
}
|
|
@@ -41,42 +43,46 @@ let AlterActions = class AlterActions {
|
|
|
41
43
|
return this.injector.getProviders("formio:action");
|
|
42
44
|
}
|
|
43
45
|
createHandler(provider, propertyKey) {
|
|
44
|
-
const
|
|
46
|
+
const compiledHandler = this.params.compileHandler({
|
|
45
47
|
token: provider.token,
|
|
46
48
|
propertyKey
|
|
47
49
|
});
|
|
48
50
|
return async (action, handler, method, req, res, next, setActionItemMessage) => {
|
|
49
|
-
const $ctx = req
|
|
50
|
-
$ctx
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
const { $ctx } = req;
|
|
52
|
+
if ($ctx) {
|
|
53
|
+
$ctx.set("ACTION_CTX", { handler, method, setActionItemMessage, action });
|
|
54
|
+
$ctx.endpoint = EndpointMetadata.get(provider.useClass, "resolve");
|
|
53
55
|
try {
|
|
54
|
-
|
|
55
|
-
const handler = await promisedHandler;
|
|
56
|
-
const { state, data, status, headers } = await resolver.call(() => handler({ $ctx }));
|
|
57
|
-
if (state === AnyToPromiseStatus.RESOLVED) {
|
|
58
|
-
if (status) {
|
|
59
|
-
$ctx.response.status(status);
|
|
60
|
-
}
|
|
61
|
-
if (headers) {
|
|
62
|
-
$ctx.response.setHeaders(headers);
|
|
63
|
-
}
|
|
64
|
-
if (data !== undefined) {
|
|
65
|
-
$ctx.data = data;
|
|
66
|
-
return await this.flush($ctx.data, $ctx);
|
|
67
|
-
}
|
|
56
|
+
if (await this.onRequest(compiledHandler, $ctx)) {
|
|
68
57
|
next();
|
|
69
58
|
}
|
|
70
59
|
}
|
|
71
60
|
catch (er) {
|
|
72
61
|
next(er);
|
|
73
62
|
}
|
|
74
|
-
}
|
|
63
|
+
}
|
|
75
64
|
};
|
|
76
65
|
}
|
|
66
|
+
async onRequest(handler, $ctx) {
|
|
67
|
+
const resolver = new AnyToPromise();
|
|
68
|
+
const { state, data, status, headers } = await resolver.call(() => handler({ $ctx }));
|
|
69
|
+
if (state === AnyToPromiseStatus.RESOLVED) {
|
|
70
|
+
if (status) {
|
|
71
|
+
$ctx.response.status(status);
|
|
72
|
+
}
|
|
73
|
+
if (headers) {
|
|
74
|
+
$ctx.response.setHeaders(headers);
|
|
75
|
+
}
|
|
76
|
+
if (data !== undefined) {
|
|
77
|
+
$ctx.data = data;
|
|
78
|
+
return await this.flush($ctx.data, $ctx);
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
77
83
|
async flush(data, $ctx) {
|
|
78
84
|
const { response } = $ctx;
|
|
79
|
-
if (
|
|
85
|
+
if (!$ctx.isDone()) {
|
|
80
86
|
setResponseHeaders($ctx);
|
|
81
87
|
data = await this.responseFilter.serialize(data, $ctx);
|
|
82
88
|
data = await this.responseFilter.transform(data, $ctx);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AlterActions.js","sourceRoot":"","sources":["../../../src/components/AlterActions.ts"],"names":[],"mappings":";AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"AlterActions.js","sourceRoot":"","sources":["../../../src/components/AlterActions.ts"],"names":[],"mappings":";AAAA,OAAO,EAAkB,kBAAkB,EAAC,MAAM,cAAc,CAAC;AACjE,OAAO,EAAC,YAAY,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CAAC,IAAI,EAAE,IAAW,CAAC,CAAC;YAC9D,IAAI,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,IAAI,EAAE,IAAW,CAAC,CAAC;YAE9D,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACrB;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAA;AAvHC;IADC,MAAM,EAAE;8BACW,eAAe;8CAAC;AAGpC;IADC,MAAM,EAAE;8BACS,aAAa;4CAAC;AAGhC;IADC,MAAM,EAAE;8BACS,cAAc;4CAAC;AAGjC;IADC,MAAM,EAAE;8BACiB,sBAAsB;oDAAC;AAXtC,YAAY;IADxB,KAAK,CAAC,SAAS,CAAC;GACJ,YAAY,CAyHxB;SAzHY,YAAY","sourcesContent":["import {PlatformContext, setResponseHeaders} from \"@tsed/common\";\nimport {AnyToPromise, AnyToPromiseStatus} from \"@tsed/core\";\nimport {Inject, InjectorService, Provider} from \"@tsed/di\";\nimport {FormioActionInfo} from \"@tsed/formio-types\";\nimport {PlatformParams} from \"@tsed/platform-params\";\nimport {PlatformResponseFilter} from \"@tsed/platform-response-filter\";\nimport {EndpointMetadata} from \"@tsed/schema\";\nimport {Alter} from \"../decorators/alter\";\nimport {AlterHook} from \"../domain/AlterHook\";\nimport {SetActionItemMessage} from \"../domain/FormioAction\";\nimport {FormioActions} from \"../domain/FormioActionsIndex\";\nimport {FormioService} from \"../services/FormioService\";\n\n@Alter(\"actions\")\nexport class AlterActions implements AlterHook {\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected formio: FormioService;\n\n @Inject()\n protected params: PlatformParams;\n\n @Inject()\n protected responseFilter: PlatformResponseFilter;\n\n transform(actions: FormioActions): FormioActions {\n const {Action} = this.formio;\n\n return this.getActions().reduce((actions, provider) => {\n const instance = this.injector.invoke<any>(provider.token);\n const options = provider.store.get<FormioActionInfo>(\"formio:action\");\n const resolveHandler = this.createHandler(provider, \"resolve\");\n\n return {\n ...actions,\n [options.name]: class extends Action {\n static access = options.access;\n\n static async info(req: any, res: any, next: Function) {\n let opts = {...options};\n\n if (instance.info) {\n opts = await instance.info(opts, req, res);\n }\n\n next(null, opts);\n }\n\n static async settingsForm(req: any, res: any, next: Function) {\n next(null, await instance.settingsForm(req, res));\n }\n\n resolve(handler: string, method: string, req: any, res: any, next: Function, setActionItemMessage: SetActionItemMessage): void {\n resolveHandler(this, handler, method, req, res, next, setActionItemMessage);\n }\n }\n };\n }, actions);\n }\n\n protected getActions() {\n return this.injector.getProviders(\"formio:action\");\n }\n\n protected createHandler(provider: Provider, propertyKey: string | symbol) {\n const compiledHandler = this.params.compileHandler({\n token: provider.token,\n propertyKey\n });\n\n return async (\n action: any,\n handler: string,\n method: string,\n req: any,\n res: any,\n next: any,\n setActionItemMessage: SetActionItemMessage\n ) => {\n const {$ctx} = req;\n\n if ($ctx) {\n $ctx.set(\"ACTION_CTX\", {handler, method, setActionItemMessage, action});\n $ctx.endpoint = EndpointMetadata.get(provider.useClass, \"resolve\");\n\n try {\n if (await this.onRequest(compiledHandler, $ctx)) {\n next();\n }\n } catch (er) {\n next(er);\n }\n }\n };\n }\n\n private async onRequest(handler: any, $ctx: PlatformContext) {\n const resolver = new AnyToPromise();\n const {state, data, status, headers} = await resolver.call(() => handler({$ctx}));\n\n if (state === AnyToPromiseStatus.RESOLVED) {\n if (status) {\n $ctx.response.status(status);\n }\n\n if (headers) {\n $ctx.response.setHeaders(headers);\n }\n\n if (data !== undefined) {\n $ctx.data = data;\n\n return await this.flush($ctx.data, $ctx);\n }\n\n return true;\n }\n }\n\n private async flush(data: any, $ctx: PlatformContext) {\n const {response} = $ctx;\n\n if (!$ctx.isDone()) {\n setResponseHeaders($ctx);\n\n data = await this.responseFilter.serialize(data, $ctx as any);\n data = await this.responseFilter.transform(data, $ctx as any);\n\n response.body(data);\n }\n\n return response;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AlterSkip.js","sourceRoot":"","sources":["../../../src/components/AlterSkip.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,QAAQ,EAAkB,MAAM,cAAc,CAAC;AACvD,OAAO,EAAC,aAAa,EAAC,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAC,KAAK,EAAC,MAAM,qBAAqB,CAAC;AAI1C,IAAa,SAAS,GAAtB,MAAa,SAAS;
|
|
1
|
+
{"version":3,"file":"AlterSkip.js","sourceRoot":"","sources":["../../../src/components/AlterSkip.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,QAAQ,EAAkB,MAAM,cAAc,CAAC;AACvD,OAAO,EAAC,aAAa,EAAC,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAC,KAAK,EAAC,MAAM,qBAAqB,CAAC;AAI1C,IAAa,SAAS,GAAtB,MAAa,SAAS;IAEpB,OAAO,CAAS;IAGhB,SAAS,CAAW;IAEpB,SAAS,CAAC,KAAU,EAAE,GAAoB;QACxC,IAAI,KAAK,EAAE;YACT,OAAO,IAAI,CAAC;SACb;QAED,MAAM,EAAC,OAAO,EAAC,GAAG,GAAG,CAAC;QACtB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAEtC,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;YACrC,OAAO,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,GAAG,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAjBC;IADC,QAAQ,CAAC,gBAAgB,EAAE,GAAG,CAAC;;0CAChB;AAGhB;IADC,QAAQ,CAAC,kBAAkB,EAAE,CAAC,YAAY,CAAC,CAAC;;4CACzB;AALT,SAAS;IADrB,KAAK,CAAC,MAAM,CAAC;GACD,SAAS,CAmBrB;SAnBY,SAAS","sourcesContent":["import {Constant, PlatformContext} from \"@tsed/common\";\nimport {normalizePath} from \"@tsed/common\";\nimport {Alter} from \"../decorators/alter\";\nimport {AlterHook} from \"../domain/AlterHook\";\n\n@Alter(\"skip\")\nexport class AlterSkip implements AlterHook {\n @Constant(\"formio.baseUrl\", \"/\")\n baseUrl: string;\n\n @Constant(\"formio.whiteList\", [\"/spec.json\"])\n whiteList: string[];\n\n transform(value: any, ctx: PlatformContext): any {\n if (value) {\n return true;\n }\n\n const {request} = ctx;\n const url = request.url.split(\"?\")[0];\n\n return !!this.whiteList.find((entry) => {\n return normalizePath(this.baseUrl, entry) === url;\n });\n }\n}\n"]}
|
|
@@ -5,6 +5,7 @@ import { Alter } from "../decorators/alter.js";
|
|
|
5
5
|
import { FormioDatabase } from "../services/FormioDatabase.js";
|
|
6
6
|
import async from "async";
|
|
7
7
|
let AlterTemplateExportSteps = class AlterTemplateExportSteps {
|
|
8
|
+
database;
|
|
8
9
|
transform(queue, template, map, options) {
|
|
9
10
|
queue.push(async.apply(this.exportSubmissions.bind(this), template, map, options));
|
|
10
11
|
return queue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AlterTemplateExportSteps.js","sourceRoot":"","sources":["../../../src/components/AlterTemplateExportSteps.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAGhC,OAAO,EAAC,KAAK,EAAC,MAAM,qBAAqB,CAAC;AAI1C,OAAO,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,IAAa,wBAAwB,GAArC,MAAa,wBAAwB;
|
|
1
|
+
{"version":3,"file":"AlterTemplateExportSteps.js","sourceRoot":"","sources":["../../../src/components/AlterTemplateExportSteps.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,EAAC,MAAM,EAAC,MAAM,UAA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EAAE,QAAQ,EAAE,GAAG,UAAU,EAAC,EAAE,EAAE;YACxG,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;YACxD,MAAM,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;YAErD,GAAG,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;YAElC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACZ,GAAG,UAAU;gBACb,OAAO,EAAE,OAAO,IAAI,OAAO,CAAC,QAAQ,EAAE;gBACtC,QAAQ,EAAE,QAAQ,IAAI,QAAQ,CAAC,QAAQ,EAAE;gBACzC,IAAI,EAAE,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC;gBACzC,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;gBAChD,IAAI,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC;aAC/B,CAAC,CAAC;YAEH,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;IACX,CAAC;CACF,CAAA;AA1CC;IADC,MAAM,EAAE;8BACW,cAAc;0DAAC;AAFxB,wBAAwB;IADpC,KAAK,CAAC,qBAAqB,CAAC;GAChB,wBAAwB,CA4CpC;SA5CY,wBAAwB","sourcesContent":["import {getValue} from \"@tsed/core\";\nimport {Inject} from \"@tsed/di\";\nimport {MongooseDocument} from \"@tsed/mongoose\";\nimport {FormioMapper} from \"../builder/FormioMapper\";\nimport {Alter} from \"../decorators/alter\";\nimport {AlterHook} from \"../domain/AlterHook\";\nimport {FormioSubmission} from \"../domain/FormioModels\";\nimport {FormioTemplate} from \"../domain/FormioTemplate\";\nimport {FormioDatabase} from \"../services/FormioDatabase\";\nimport async from \"async\";\n\n@Alter(\"templateExportSteps\")\nexport class AlterTemplateExportSteps implements AlterHook {\n @Inject()\n protected database: FormioDatabase;\n\n transform(queue: any[], template: FormioTemplate, map: any, options: any): any {\n queue.push(async.apply(this.exportSubmissions.bind(this), template, map, options));\n\n return queue;\n }\n\n protected async exportSubmissions(template: FormioTemplate, map: any, options: any, next: any) {\n const [mapper, submissions] = await Promise.all([\n this.database.getFormioMapper(),\n this.database.submissionModel.find({\n deleted: {$eq: null}\n })\n ]);\n\n template.submissions = await this.mapSubmissions(submissions, mapper);\n\n next(null, template);\n }\n\n protected mapSubmissions(submissions: MongooseDocument<FormioSubmission>[], mapper: FormioMapper) {\n return submissions\n .map((submission) => submission.toObject())\n .reduce((acc: any, {_id, created, updated, modified, __v, owner, roles, form, metadata, ...submission}) => {\n const machineName = mapper.mapToExport(form.toString());\n const key = machineName.replace(\"$machineName:\", \"\");\n\n acc[key] = getValue(acc, key, []);\n\n acc[key].push({\n ...submission,\n created: created && created.toString(),\n modified: modified && modified.toString(),\n data: mapper.mapToExport(submission.data),\n roles: mapper.mapToExport(roles).filter(Boolean),\n form: mapper.mapToExport(form)\n });\n\n return acc;\n }, {});\n }\n}\n"]}
|
|
@@ -4,6 +4,7 @@ import { Alter } from "../decorators/alter.js";
|
|
|
4
4
|
import { FormioDatabase } from "../services/FormioDatabase.js";
|
|
5
5
|
import async from "async";
|
|
6
6
|
let AlterTemplateImportSteps = class AlterTemplateImportSteps {
|
|
7
|
+
database;
|
|
7
8
|
transform(queue, install, template) {
|
|
8
9
|
queue.push(async.apply(this.importSubmissions.bind(this), template));
|
|
9
10
|
return queue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AlterTemplateImportSteps.js","sourceRoot":"","sources":["../../../src/components/AlterTemplateImportSteps.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAC,KAAK,EAAC,MAAM,qBAAqB,CAAC;AAI1C,OAAO,EAAC,cAAc,E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AAI,KAAK,CAAC,CAAC,CAAC,EAAC,EAAE,OAAO,CAAC,CAAC;iBAC1F;aACF;SACF;QAED,IAAI,EAAE,CAAC;IACT,CAAC;IAES,KAAK,CAAC,gBAAgB,CAAC,UAAqC,EAAE,MAAoB;QAC1F,MAAM,KAAK,GAAG;YACZ,GAAG,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC;YACjC,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;SAChF,CAAC;QAEF,MAAM,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAElD,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAA;AApCC;IADC,MAAM,EAAE;8BACW,cAAc;0DAAC;AAFxB,wBAAwB;IADpC,KAAK,CAAC,qBAAqB,CAAC;GAChB,wBAAwB,CAsCpC;SAtCY,wBAAwB","sourcesContent":["import {Inject} from \"@tsed/di\";\nimport {FormioMapper} from \"../builder/FormioMapper\";\nimport {Alter} from \"../decorators/alter\";\nimport {AlterHook} from \"../domain/AlterHook\";\nimport {FormioSubmission} from \"../domain/FormioModels\";\nimport {FormioTemplate} from \"../domain/FormioTemplate\";\nimport {FormioDatabase} from \"../services/FormioDatabase\";\nimport async from \"async\";\n\n@Alter(\"templateImportSteps\")\nexport class AlterTemplateImportSteps implements AlterHook {\n @Inject()\n protected database: FormioDatabase;\n\n transform(queue: any[], install: Function, template: Partial<FormioTemplate>): any {\n queue.push(async.apply(this.importSubmissions.bind(this), template));\n\n return queue;\n }\n\n protected async importSubmissions(template: Partial<FormioTemplate>, done: any) {\n if (template && template.submissions) {\n // clean all submissions\n await this.database.submissionModel.deleteMany({});\n\n const ctxData = await this.database.getFormioMapper();\n const entries = Object.entries(template.submissions);\n\n for (const entry of entries) {\n for (const submission of entry[1]) {\n await this.importSubmission({...submission, form: submission.form || entry[0]}, ctxData);\n }\n }\n }\n\n done();\n }\n\n protected async importSubmission(submission: Partial<FormioSubmission>, mapper: FormioMapper) {\n const value = {\n ...mapper.mapToImport(submission),\n roles: [...new Set(mapper.mapToImport(submission.roles || []))].filter(Boolean)\n };\n\n await this.database.submissionModel.create(value);\n\n return value;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormioAuthMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/FormioAuthMiddleware.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAC,MAAM,cAAc,CAAC;AACzD,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAC,SAAS,EAAC,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAC;AAExD;;;GAGG;AAEH,IAAa,oBAAoB,GAAjC,MAAa,oBAAoB;
|
|
1
|
+
{"version":3,"file":"FormioAuthMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/FormioAuthMiddleware.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAC,MAAM,cAAc,CAAC;AACzD,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAC,SAAS,EAAC,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAC;AAExD;;;GAGG;AAEH,IAAa,oBAAoB,GAAjC,MAAa,oBAAoB;IAErB,MAAM,CAAgB;IAEhC,IAAI,YAAY;QACd,OAAO,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IACxD,CAAC;IAED,KAAK,CAAC,GAAG,CAAY,GAAY;QAC/B,MAAM,GAAG,GAAG,GAAG,CAAC,UAAU,EAAE,CAAC;QAC7B,MAAM,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QAE9B,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAElC,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,gBAAgB,CAAC,EAAE;YACpC,MAAM,IAAI,YAAY,CAAC,mBAAmB,CAAC,CAAC;SAC7C;IACH,CAAC;CACF,CAAA;AAhBC;IADC,MAAM,EAAE;8BACS,aAAa;oDAAC;AAMhC;IAAW,WAAA,OAAO,EAAE,CAAA;;;;+CASnB;AAjBU,oBAAoB;IADhC,UAAU,EAAE;GACA,oBAAoB,CAkBhC;SAlBY,oBAAoB","sourcesContent":["import {Context, Inject, Middleware} from \"@tsed/common\";\nimport {getValue} from \"@tsed/core\";\nimport {Unauthorized} from \"@tsed/exceptions\";\nimport {promisify} from \"util\";\nimport {FormioService} from \"../services/FormioService\";\n\n/**\n * @middleware\n * @formio\n */\n@Middleware()\nexport class FormioAuthMiddleware {\n @Inject()\n protected formio: FormioService;\n\n get tokenHandler(): any {\n return promisify(this.formio.middleware.tokenHandler);\n }\n\n async use(@Context() ctx: Context) {\n const req = ctx.getRequest();\n const res = ctx.getResponse();\n\n await this.tokenHandler(req, res);\n\n if (!getValue(req, \"token.user._id\")) {\n throw new Unauthorized(\"User unauthorized\");\n }\n }\n}\n"]}
|
|
@@ -7,6 +7,9 @@ import { FormioDatabase } from "./FormioDatabase.js";
|
|
|
7
7
|
import { FormioHooksService } from "./FormioHooksService.js";
|
|
8
8
|
import { FormioService } from "./FormioService.js";
|
|
9
9
|
let FormioAuthService = class FormioAuthService {
|
|
10
|
+
formio;
|
|
11
|
+
hooks;
|
|
12
|
+
db;
|
|
10
13
|
get currentUser() {
|
|
11
14
|
return promisify(this.formio.auth.currentUser);
|
|
12
15
|
}
|
|
@@ -69,7 +72,7 @@ let FormioAuthService = class FormioAuthService {
|
|
|
69
72
|
_id: user._id
|
|
70
73
|
},
|
|
71
74
|
form: {
|
|
72
|
-
_id: form
|
|
75
|
+
_id: form?._id
|
|
73
76
|
}
|
|
74
77
|
}, form, req);
|
|
75
78
|
const decoded = this.hooks.alter("tokenDecode", token, req);
|