@tsed/formio 7.0.0-beta.3 → 7.0.0-beta.4

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.
Files changed (80) hide show
  1. package/.mocharc.js +2 -2
  2. package/.nycrc +6 -5
  3. package/lib/cjs/FormioModule.js +21 -21
  4. package/lib/cjs/FormioModule.js.map +1 -1
  5. package/lib/cjs/builder/FormioMapper.js +11 -3
  6. package/lib/cjs/builder/FormioMapper.js.map +1 -1
  7. package/lib/cjs/components/AlterActions.js +61 -16
  8. package/lib/cjs/components/AlterActions.js.map +1 -1
  9. package/lib/cjs/components/AlterAudit.js +1 -1
  10. package/lib/cjs/components/AlterAudit.js.map +1 -1
  11. package/lib/cjs/components/AlterHost.js +1 -1
  12. package/lib/cjs/components/AlterLog.js +1 -1
  13. package/lib/cjs/components/AlterSkip.js +5 -5
  14. package/lib/cjs/components/AlterTemplateExportSteps.js +5 -5
  15. package/lib/cjs/components/AlterTemplateExportSteps.js.map +1 -1
  16. package/lib/cjs/components/AlterTemplateImportSteps.js +5 -5
  17. package/lib/cjs/components/AlterTemplateImportSteps.js.map +1 -1
  18. package/lib/cjs/domain/FormioHooks.js.map +1 -1
  19. package/lib/cjs/domain/FormioModels.js +1 -1
  20. package/lib/cjs/domain/FormioModels.js.map +1 -1
  21. package/lib/cjs/domain/Resource.js.map +1 -1
  22. package/lib/cjs/index.js +46 -42
  23. package/lib/cjs/index.js.map +1 -1
  24. package/lib/cjs/middlewares/FormioAuthMiddleware.js +8 -8
  25. package/lib/cjs/middlewares/FormioAuthMiddleware.js.map +1 -1
  26. package/lib/cjs/package.json +3 -0
  27. package/lib/cjs/services/FormioAuthService.js +7 -7
  28. package/lib/cjs/services/FormioAuthService.js.map +1 -1
  29. package/lib/cjs/services/FormioDatabase.js +47 -10
  30. package/lib/cjs/services/FormioDatabase.js.map +1 -1
  31. package/lib/cjs/services/FormioHooksService.js +5 -5
  32. package/lib/cjs/services/FormioHooksService.js.map +1 -1
  33. package/lib/cjs/services/FormioInstaller.js +5 -5
  34. package/lib/cjs/services/FormioInstaller.js.map +1 -1
  35. package/lib/cjs/services/FormioRepository.js +42 -0
  36. package/lib/cjs/services/FormioRepository.js.map +1 -0
  37. package/lib/cjs/services/FormioService.js +13 -10
  38. package/lib/cjs/services/FormioService.js.map +1 -1
  39. package/lib/esm/FormioModule.js +11 -11
  40. package/lib/esm/builder/FormioMapper.js +11 -3
  41. package/lib/esm/builder/FormioMapper.js.map +1 -1
  42. package/lib/esm/components/AlterActions.js +58 -13
  43. package/lib/esm/components/AlterActions.js.map +1 -1
  44. package/lib/esm/components/AlterAudit.js +1 -1
  45. package/lib/esm/components/AlterAudit.js.map +1 -1
  46. package/lib/esm/components/AlterHost.js +1 -1
  47. package/lib/esm/components/AlterLog.js +1 -1
  48. package/lib/esm/components/AlterSkip.js +1 -1
  49. package/lib/esm/components/AlterTemplateExportSteps.js +3 -3
  50. package/lib/esm/components/AlterTemplateExportSteps.js.map +1 -1
  51. package/lib/esm/components/AlterTemplateImportSteps.js +3 -3
  52. package/lib/esm/components/AlterTemplateImportSteps.js.map +1 -1
  53. package/lib/esm/decorators/useFormioAuth.js +1 -1
  54. package/lib/esm/domain/FormioHooks.js.map +1 -1
  55. package/lib/esm/domain/Resource.js.map +1 -1
  56. package/lib/esm/index.js +46 -42
  57. package/lib/esm/index.js.map +1 -1
  58. package/lib/esm/middlewares/FormioAuthMiddleware.js +1 -1
  59. package/lib/esm/package.json +3 -0
  60. package/lib/esm/services/FormioAuthService.js +3 -3
  61. package/lib/esm/services/FormioAuthService.js.map +1 -1
  62. package/lib/esm/services/FormioDatabase.js +47 -10
  63. package/lib/esm/services/FormioDatabase.js.map +1 -1
  64. package/lib/esm/services/FormioHooksService.js +1 -1
  65. package/lib/esm/services/FormioInstaller.js +2 -2
  66. package/lib/esm/services/FormioRepository.js +38 -0
  67. package/lib/esm/services/FormioRepository.js.map +1 -0
  68. package/lib/esm/services/FormioService.js +6 -3
  69. package/lib/esm/services/FormioService.js.map +1 -1
  70. package/lib/types/components/AlterActions.d.ts +8 -3
  71. package/lib/types/components/AlterAudit.d.ts +2 -2
  72. package/lib/types/domain/FormioHooks.d.ts +1 -1
  73. package/lib/types/domain/Resource.d.ts +2 -2
  74. package/lib/types/index.d.ts +22 -14
  75. package/lib/types/services/FormioAuthService.d.ts +14 -3
  76. package/lib/types/services/FormioDatabase.d.ts +47 -8
  77. package/lib/types/services/FormioRepository.d.ts +24 -0
  78. package/package.json +21 -15
  79. package/readme.md +5 -9
  80. package/tsconfig.compile.esm.json +1 -12
package/lib/cjs/index.js CHANGED
@@ -1,46 +1,50 @@
1
1
  "use strict";
2
+ /**
3
+ * @file Automatically generated by barrelsby.
4
+ */
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const tslib_1 = require("tslib");
4
- // decorators
5
- (0, tslib_1.__exportStar)(require("./decorators/action"), exports);
6
- (0, tslib_1.__exportStar)(require("./decorators/actionCtx"), exports);
7
- (0, tslib_1.__exportStar)(require("./decorators/alter"), exports);
8
- (0, tslib_1.__exportStar)(require("./decorators/on"), exports);
9
- (0, tslib_1.__exportStar)(require("./decorators/useFormioAuth"), exports);
10
- // middlewares
11
- (0, tslib_1.__exportStar)(require("./middlewares/FormioAuthMiddleware"), exports);
12
- // domain
13
- (0, tslib_1.__exportStar)(require("./domain/AlterHook"), exports);
14
- (0, tslib_1.__exportStar)(require("./domain/Formio"), exports);
15
- (0, tslib_1.__exportStar)(require("./domain/FormioDecodedToken"), exports);
16
- (0, tslib_1.__exportStar)(require("./domain/FormioAction"), exports);
17
- (0, tslib_1.__exportStar)(require("./domain/FormioActionsIndex"), exports);
18
- (0, tslib_1.__exportStar)(require("./domain/FormioAuth"), exports);
19
- (0, tslib_1.__exportStar)(require("./domain/FormioBaseModel"), exports);
20
- (0, tslib_1.__exportStar)(require("./domain/FormioConfig"), exports);
21
- (0, tslib_1.__exportStar)(require("./domain/FormioCtxMapper"), exports);
22
- (0, tslib_1.__exportStar)(require("./domain/FormioErrors"), exports);
23
- (0, tslib_1.__exportStar)(require("./domain/FormioHooks"), exports);
24
- (0, tslib_1.__exportStar)(require("./domain/FormioJs"), exports);
25
- (0, tslib_1.__exportStar)(require("./domain/FormioModels"), exports);
26
- (0, tslib_1.__exportStar)(require("./domain/FormioRouter"), exports);
27
- (0, tslib_1.__exportStar)(require("./domain/FormioSettings"), exports);
28
- (0, tslib_1.__exportStar)(require("./domain/FormioUpdate"), exports);
29
- (0, tslib_1.__exportStar)(require("./domain/FormioUtils"), exports);
30
- (0, tslib_1.__exportStar)(require("./domain/FormioTemplate"), exports);
31
- (0, tslib_1.__exportStar)(require("./domain/FormioTemplateUtil"), exports);
32
- (0, tslib_1.__exportStar)(require("./domain/OnHook"), exports);
33
- // module
34
- (0, tslib_1.__exportStar)(require("./FormioModule"), exports);
35
- (0, tslib_1.__exportStar)(require("./builder/FormioMapper"), exports);
36
- (0, tslib_1.__exportStar)(require("./services/FormioService"), exports);
37
- (0, tslib_1.__exportStar)(require("./services/FormioDatabase"), exports);
38
- (0, tslib_1.__exportStar)(require("./services/FormioDatabase"), exports);
39
- (0, tslib_1.__exportStar)(require("./services/FormioAuthService"), exports);
40
- (0, tslib_1.__exportStar)(require("./services/FormioHooksService"), exports);
41
- (0, tslib_1.__exportStar)(require("./components/AlterActions"), exports);
42
- (0, tslib_1.__exportStar)(require("./components/AlterAudit"), exports);
43
- (0, tslib_1.__exportStar)(require("./components/AlterLog"), exports);
44
- (0, tslib_1.__exportStar)(require("./components/AlterHost"), exports);
45
- (0, tslib_1.__exportStar)(require("./components/AlterSkip"), exports);
7
+ tslib_1.__exportStar(require("./FormioModule"), exports);
8
+ tslib_1.__exportStar(require("./builder/FormioMapper"), exports);
9
+ tslib_1.__exportStar(require("./components/AlterActions"), exports);
10
+ tslib_1.__exportStar(require("./components/AlterAudit"), exports);
11
+ tslib_1.__exportStar(require("./components/AlterHost"), exports);
12
+ tslib_1.__exportStar(require("./components/AlterLog"), exports);
13
+ tslib_1.__exportStar(require("./components/AlterSkip"), exports);
14
+ tslib_1.__exportStar(require("./components/AlterTemplateExportSteps"), exports);
15
+ tslib_1.__exportStar(require("./components/AlterTemplateImportSteps"), exports);
16
+ tslib_1.__exportStar(require("./decorators/action"), exports);
17
+ tslib_1.__exportStar(require("./decorators/actionCtx"), exports);
18
+ tslib_1.__exportStar(require("./decorators/alter"), exports);
19
+ tslib_1.__exportStar(require("./decorators/on"), exports);
20
+ tslib_1.__exportStar(require("./decorators/useFormioAuth"), exports);
21
+ tslib_1.__exportStar(require("./domain/AlterHook"), exports);
22
+ tslib_1.__exportStar(require("./domain/Formio"), exports);
23
+ tslib_1.__exportStar(require("./domain/FormioAction"), exports);
24
+ tslib_1.__exportStar(require("./domain/FormioActionsIndex"), exports);
25
+ tslib_1.__exportStar(require("./domain/FormioAuth"), exports);
26
+ tslib_1.__exportStar(require("./domain/FormioBaseModel"), exports);
27
+ tslib_1.__exportStar(require("./domain/FormioConfig"), exports);
28
+ tslib_1.__exportStar(require("./domain/FormioCtxMapper"), exports);
29
+ tslib_1.__exportStar(require("./domain/FormioDecodedToken"), exports);
30
+ tslib_1.__exportStar(require("./domain/FormioErrors"), exports);
31
+ tslib_1.__exportStar(require("./domain/FormioHooks"), exports);
32
+ tslib_1.__exportStar(require("./domain/FormioJs"), exports);
33
+ tslib_1.__exportStar(require("./domain/FormioModels"), exports);
34
+ tslib_1.__exportStar(require("./domain/FormioRouter"), exports);
35
+ tslib_1.__exportStar(require("./domain/FormioSettings"), exports);
36
+ tslib_1.__exportStar(require("./domain/FormioTemplate"), exports);
37
+ tslib_1.__exportStar(require("./domain/FormioTemplateUtil"), exports);
38
+ tslib_1.__exportStar(require("./domain/FormioUpdate"), exports);
39
+ tslib_1.__exportStar(require("./domain/FormioUtils"), exports);
40
+ tslib_1.__exportStar(require("./domain/OnHook"), exports);
41
+ tslib_1.__exportStar(require("./domain/Resource"), exports);
42
+ tslib_1.__exportStar(require("./middlewares/FormioAuthMiddleware"), exports);
43
+ tslib_1.__exportStar(require("./services/FormioAuthService"), exports);
44
+ tslib_1.__exportStar(require("./services/FormioDatabase"), exports);
45
+ tslib_1.__exportStar(require("./services/FormioHooksService"), exports);
46
+ tslib_1.__exportStar(require("./services/FormioInstaller"), exports);
47
+ tslib_1.__exportStar(require("./services/FormioRepository"), exports);
48
+ tslib_1.__exportStar(require("./services/FormioService"), exports);
49
+ tslib_1.__exportStar(require("./utils/isMongoId"), exports);
46
50
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,aAAa;AACb,mEAAoC;AACpC,sEAAuC;AACvC,kEAAmC;AACnC,+DAAgC;AAChC,0EAA2C;AAE3C,cAAc;AACd,kFAAmD;AAEnD,SAAS;AACT,kEAAmC;AACnC,+DAAgC;AAChC,2EAA4C;AAC5C,qEAAsC;AACtC,2EAA4C;AAC5C,mEAAoC;AACpC,wEAAyC;AACzC,qEAAsC;AACtC,wEAAyC;AACzC,qEAAsC;AACtC,oEAAqC;AACrC,iEAAkC;AAClC,qEAAsC;AACtC,qEAAsC;AACtC,uEAAwC;AACxC,qEAAsC;AACtC,oEAAqC;AACrC,uEAAwC;AACxC,2EAA4C;AAC5C,+DAAgC;AAEhC,SAAS;AACT,8DAA+B;AAC/B,sEAAuC;AACvC,wEAAyC;AACzC,yEAA0C;AAC1C,yEAA0C;AAC1C,4EAA6C;AAC7C,6EAA8C;AAC9C,yEAA0C;AAC1C,uEAAwC;AACxC,qEAAsC;AACtC,sEAAuC;AACvC,sEAAuC","sourcesContent":["// decorators\nexport * from \"./decorators/action\";\nexport * from \"./decorators/actionCtx\";\nexport * from \"./decorators/alter\";\nexport * from \"./decorators/on\";\nexport * from \"./decorators/useFormioAuth\";\n\n// middlewares\nexport * from \"./middlewares/FormioAuthMiddleware\";\n\n// domain\nexport * from \"./domain/AlterHook\";\nexport * from \"./domain/Formio\";\nexport * from \"./domain/FormioDecodedToken\";\nexport * from \"./domain/FormioAction\";\nexport * from \"./domain/FormioActionsIndex\";\nexport * from \"./domain/FormioAuth\";\nexport * from \"./domain/FormioBaseModel\";\nexport * from \"./domain/FormioConfig\";\nexport * from \"./domain/FormioCtxMapper\";\nexport * from \"./domain/FormioErrors\";\nexport * from \"./domain/FormioHooks\";\nexport * from \"./domain/FormioJs\";\nexport * from \"./domain/FormioModels\";\nexport * from \"./domain/FormioRouter\";\nexport * from \"./domain/FormioSettings\";\nexport * from \"./domain/FormioUpdate\";\nexport * from \"./domain/FormioUtils\";\nexport * from \"./domain/FormioTemplate\";\nexport * from \"./domain/FormioTemplateUtil\";\nexport * from \"./domain/OnHook\";\n\n// module\nexport * from \"./FormioModule\";\nexport * from \"./builder/FormioMapper\";\nexport * from \"./services/FormioService\";\nexport * from \"./services/FormioDatabase\";\nexport * from \"./services/FormioDatabase\";\nexport * from \"./services/FormioAuthService\";\nexport * from \"./services/FormioHooksService\";\nexport * from \"./components/AlterActions\";\nexport * from \"./components/AlterAudit\";\nexport * from \"./components/AlterLog\";\nexport * from \"./components/AlterHost\";\nexport * from \"./components/AlterSkip\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,yDAA+B;AAC/B,iEAAuC;AACvC,oEAA0C;AAC1C,kEAAwC;AACxC,iEAAuC;AACvC,gEAAsC;AACtC,iEAAuC;AACvC,gFAAsD;AACtD,gFAAsD;AACtD,8DAAoC;AACpC,iEAAuC;AACvC,6DAAmC;AACnC,0DAAgC;AAChC,qEAA2C;AAC3C,6DAAmC;AACnC,0DAAgC;AAChC,gEAAsC;AACtC,sEAA4C;AAC5C,8DAAoC;AACpC,mEAAyC;AACzC,gEAAsC;AACtC,mEAAyC;AACzC,sEAA4C;AAC5C,gEAAsC;AACtC,+DAAqC;AACrC,4DAAkC;AAClC,gEAAsC;AACtC,gEAAsC;AACtC,kEAAwC;AACxC,kEAAwC;AACxC,sEAA4C;AAC5C,gEAAsC;AACtC,+DAAqC;AACrC,0DAAgC;AAChC,4DAAkC;AAClC,6EAAmD;AACnD,uEAA6C;AAC7C,oEAA0C;AAC1C,wEAA8C;AAC9C,qEAA2C;AAC3C,sEAA4C;AAC5C,mEAAyC;AACzC,4DAAkC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./FormioModule\";\nexport * from \"./builder/FormioMapper\";\nexport * from \"./components/AlterActions\";\nexport * from \"./components/AlterAudit\";\nexport * from \"./components/AlterHost\";\nexport * from \"./components/AlterLog\";\nexport * from \"./components/AlterSkip\";\nexport * from \"./components/AlterTemplateExportSteps\";\nexport * from \"./components/AlterTemplateImportSteps\";\nexport * from \"./decorators/action\";\nexport * from \"./decorators/actionCtx\";\nexport * from \"./decorators/alter\";\nexport * from \"./decorators/on\";\nexport * from \"./decorators/useFormioAuth\";\nexport * from \"./domain/AlterHook\";\nexport * from \"./domain/Formio\";\nexport * from \"./domain/FormioAction\";\nexport * from \"./domain/FormioActionsIndex\";\nexport * from \"./domain/FormioAuth\";\nexport * from \"./domain/FormioBaseModel\";\nexport * from \"./domain/FormioConfig\";\nexport * from \"./domain/FormioCtxMapper\";\nexport * from \"./domain/FormioDecodedToken\";\nexport * from \"./domain/FormioErrors\";\nexport * from \"./domain/FormioHooks\";\nexport * from \"./domain/FormioJs\";\nexport * from \"./domain/FormioModels\";\nexport * from \"./domain/FormioRouter\";\nexport * from \"./domain/FormioSettings\";\nexport * from \"./domain/FormioTemplate\";\nexport * from \"./domain/FormioTemplateUtil\";\nexport * from \"./domain/FormioUpdate\";\nexport * from \"./domain/FormioUtils\";\nexport * from \"./domain/OnHook\";\nexport * from \"./domain/Resource\";\nexport * from \"./middlewares/FormioAuthMiddleware\";\nexport * from \"./services/FormioAuthService\";\nexport * from \"./services/FormioDatabase\";\nexport * from \"./services/FormioHooksService\";\nexport * from \"./services/FormioInstaller\";\nexport * from \"./services/FormioRepository\";\nexport * from \"./services/FormioService\";\nexport * from \"./utils/isMongoId\";\n"]}
@@ -24,17 +24,17 @@ let FormioAuthMiddleware = class FormioAuthMiddleware {
24
24
  }
25
25
  }
26
26
  };
27
- (0, tslib_1.__decorate)([
27
+ tslib_1.__decorate([
28
28
  (0, common_1.Inject)(),
29
- (0, tslib_1.__metadata)("design:type", FormioService_1.FormioService)
29
+ tslib_1.__metadata("design:type", FormioService_1.FormioService)
30
30
  ], FormioAuthMiddleware.prototype, "formio", void 0);
31
- (0, tslib_1.__decorate)([
32
- (0, tslib_1.__param)(0, (0, common_1.Context)()),
33
- (0, tslib_1.__metadata)("design:type", Function),
34
- (0, tslib_1.__metadata)("design:paramtypes", [Object]),
35
- (0, tslib_1.__metadata)("design:returntype", Promise)
31
+ tslib_1.__decorate([
32
+ tslib_1.__param(0, (0, common_1.Context)()),
33
+ tslib_1.__metadata("design:type", Function),
34
+ tslib_1.__metadata("design:paramtypes", [Object]),
35
+ tslib_1.__metadata("design:returntype", Promise)
36
36
  ], FormioAuthMiddleware.prototype, "use", null);
37
- FormioAuthMiddleware = (0, tslib_1.__decorate)([
37
+ FormioAuthMiddleware = tslib_1.__decorate([
38
38
  (0, common_1.Middleware)()
39
39
  ], FormioAuthMiddleware);
40
40
  exports.FormioAuthMiddleware = FormioAuthMiddleware;
@@ -1 +1 @@
1
- {"version":3,"file":"FormioAuthMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/FormioAuthMiddleware.ts"],"names":[],"mappings":";;;;AAAA,yCAAyD;AACzD,qCAAoC;AACpC,iDAA8C;AAC9C,+BAA+B;AAC/B,6DAAwD;AAExD;;;GAGG;AAEH,IAAa,oBAAoB,GAAjC,MAAa,oBAAoB;IAI/B,IAAI,YAAY;QACd,OAAO,IAAA,gBAAS,EAAC,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,IAAA,eAAQ,EAAC,GAAG,EAAE,gBAAgB,CAAC,EAAE;YACpC,MAAM,IAAI,yBAAY,CAAC,mBAAmB,CAAC,CAAC;SAC7C;IACH,CAAC;CACF,CAAA;AAhBC;IADC,IAAA,eAAM,GAAE;2CACS,6BAAa;oDAAC;AAMhC;IAAW,wBAAA,IAAA,gBAAO,GAAE,CAAA;;;;+CASnB;AAjBU,oBAAoB;IADhC,IAAA,mBAAU,GAAE;GACA,oBAAoB,CAkBhC;AAlBY,oDAAoB","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"]}
1
+ {"version":3,"file":"FormioAuthMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/FormioAuthMiddleware.ts"],"names":[],"mappings":";;;;AAAA,yCAAyD;AACzD,qCAAoC;AACpC,iDAA8C;AAC9C,+BAA+B;AAC/B,6DAAwD;AAExD;;;GAGG;AAEH,IAAa,oBAAoB,GAAjC,MAAa,oBAAoB;IAI/B,IAAI,YAAY;QACd,OAAO,IAAA,gBAAS,EAAC,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,IAAA,eAAQ,EAAC,GAAG,EAAE,gBAAgB,CAAC,EAAE;YACpC,MAAM,IAAI,yBAAY,CAAC,mBAAmB,CAAC,CAAC;SAC7C;IACH,CAAC;CACF,CAAA;AAhBC;IADC,IAAA,eAAM,GAAE;sCACS,6BAAa;oDAAC;AAMhC;IAAW,mBAAA,IAAA,gBAAO,GAAE,CAAA;;;;+CASnB;AAjBU,oBAAoB;IADhC,IAAA,mBAAU,GAAE;GACA,oBAAoB,CAkBhC;AAlBY,oDAAoB","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"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -163,19 +163,19 @@ let FormioAuthService = class FormioAuthService {
163
163
  return user;
164
164
  }
165
165
  };
166
- (0, tslib_1.__decorate)([
166
+ tslib_1.__decorate([
167
167
  (0, di_1.Inject)(),
168
- (0, tslib_1.__metadata)("design:type", FormioService_1.FormioService)
168
+ tslib_1.__metadata("design:type", FormioService_1.FormioService)
169
169
  ], FormioAuthService.prototype, "formio", void 0);
170
- (0, tslib_1.__decorate)([
170
+ tslib_1.__decorate([
171
171
  (0, di_1.Inject)(),
172
- (0, tslib_1.__metadata)("design:type", FormioHooksService_1.FormioHooksService)
172
+ tslib_1.__metadata("design:type", FormioHooksService_1.FormioHooksService)
173
173
  ], FormioAuthService.prototype, "hooks", void 0);
174
- (0, tslib_1.__decorate)([
174
+ tslib_1.__decorate([
175
175
  (0, di_1.Inject)(),
176
- (0, tslib_1.__metadata)("design:type", FormioDatabase_1.FormioDatabase)
176
+ tslib_1.__metadata("design:type", FormioDatabase_1.FormioDatabase)
177
177
  ], FormioAuthService.prototype, "db", void 0);
178
- FormioAuthService = (0, tslib_1.__decorate)([
178
+ FormioAuthService = tslib_1.__decorate([
179
179
  (0, di_1.Injectable)()
180
180
  ], FormioAuthService);
181
181
  exports.FormioAuthService = FormioAuthService;
@@ -1 +1 @@
1
- {"version":3,"file":"FormioAuthService.js","sourceRoot":"","sources":["../../../src/services/FormioAuthService.ts"],"names":[],"mappings":";;;;AACA,qCAAsC;AACtC,iCAA4C;AAC5C,iDAAoE;AACpE,+BAA+B;AAG/B,qDAAgD;AAChD,6DAAwD;AACxD,mDAA8C;AAG9C,IAAa,iBAAiB,GAA9B,MAAa,iBAAiB;IAU5B,IAAI,WAAW;QACb,OAAO,IAAA,gBAAS,EAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACjD,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;IACnC,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;IACpC,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;IACjC,CAAC;IAED,cAAc,CAAa,IAAoC,EAAE,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;IAD7B,IAAA,eAAU,GAAE;GACA,iBAAiB,CAsN7B;AAtNY,8CAAiB","sourcesContent":["import {PlatformContext, Req} from \"@tsed/common\";\nimport {isFunction} from \"@tsed/core\";\nimport {Inject, Injectable} from \"@tsed/di\";\nimport {BadRequest, NotFound, Unauthorized} from \"@tsed/exceptions\";\nimport {promisify} from \"util\";\nimport {FormioPayloadToken} from \"../domain/FormioDecodedToken\";\nimport {FormioForm, FormioSubmission, WithID} from \"../domain/FormioModels\";\nimport {FormioDatabase} from \"./FormioDatabase\";\nimport {FormioHooksService} from \"./FormioHooksService\";\nimport {FormioService} from \"./FormioService\";\n\n@Injectable()\nexport class FormioAuthService {\n @Inject()\n formio: FormioService;\n\n @Inject()\n hooks: FormioHooksService;\n\n @Inject()\n db: FormioDatabase;\n\n get currentUser() {\n return promisify(this.formio.auth.currentUser);\n }\n\n get getToken() {\n return this.formio.auth.getToken;\n }\n\n get tempToken() {\n return this.formio.auth.tempToken;\n }\n\n get logout() {\n return this.formio.auth.logout;\n }\n\n setCurrentUser<User = any>(user: WithID<FormioSubmission<User>>, token: FormioPayloadToken, ctx: PlatformContext) {\n const request = ctx.getRequest();\n const response = ctx.getResponse();\n\n request.submission.data = user.data;\n request.user = user;\n request.token = token.decoded;\n response.token = token.token;\n request[\"x-jwt-token\"] = token.token;\n\n return this;\n }\n\n /**\n * Generate the payload token for the session\n * @param user\n * @param ctx\n */\n async generatePayloadToken<User = any>(\n user: WithID<FormioSubmission<User>>,\n ctx: PlatformContext\n ): Promise<{user: WithID<FormioSubmission<User>>; token: FormioPayloadToken}> {\n const req = ctx.getRequest();\n const audit = this.formio.audit;\n let form: FormioForm | null;\n\n try {\n form = (await this.db.getForm(user.form)) as any;\n } catch (err) {\n audit(\n \"EAUTH_USERFORM\",\n {\n ...req,\n userId: user._id\n },\n user.form,\n err\n );\n throw err;\n }\n\n if (!form) {\n audit(\n \"EAUTH_USERFORM\",\n {\n ...req,\n userId: user._id\n },\n user.form,\n {message: \"User form not found\"}\n );\n\n throw new NotFound(\"User form not found.\");\n }\n\n try {\n user = await this.hooks.alterAsync(\"user\", user);\n } catch (err) {\n // istanbul ignore next\n ctx.logger.debug(err);\n }\n\n await this.hooks.alterAsync(\"login\", user, req);\n\n // Allow anyone to hook and modify the token.\n const token = this.hooks.alter(\n \"token\",\n {\n user: {\n _id: user._id\n },\n form: {\n _id: form?._id\n }\n },\n form,\n req\n );\n\n const decoded = this.hooks.alter(\"tokenDecode\", token, req);\n\n return {\n user,\n token: {\n token: this.getToken(token) as string,\n decoded\n }\n };\n }\n\n /**\n * Generate session from the given authenticated user.\n * @param user\n * @param ctx\n */\n async generateSession<User = any>(user: WithID<FormioSubmission<User>>, ctx: PlatformContext) {\n try {\n const {user: userSession, token} = await this.generatePayloadToken(user, ctx);\n this.setCurrentUser(userSession, token, ctx);\n\n await this.currentUser(ctx.getRequest(), ctx.getResponse());\n } catch (err) {\n ctx.logger.error({event: \"Error on OAuthActions\", error: err});\n throw new Unauthorized(err.message);\n }\n }\n\n /**\n * Retrieve roles\n * @param req\n */\n async getRoles(req?: Req) {\n try {\n const query = this.hooks.alter(\"roleQuery\", {deleted: {$eq: null}}, req);\n\n return await this.db.roleModel.find(query).sort({title: 1}).lean().exec();\n } catch (err) {\n throw new BadRequest(this.formio.util.errorCodes.role.EROLESLOAD);\n }\n }\n\n /**\n * Update the role of the current user submission\n * @param _id\n * @param role\n * @param req\n */\n async updateUserRole(_id: string | any, role: string, req?: Req) {\n const query = this.hooks.alter(\n \"submissionQuery\",\n {\n _id: this.formio.util.idToBson(_id),\n deleted: {$eq: null}\n },\n req\n );\n\n const user = await this.db.submissionModel.findOne(query).exec();\n\n if (!user) {\n throw new BadRequest(\"No Submission was found with the given setting `submission`.\");\n }\n\n user.roles = [this.formio.util.idToBson(role)];\n\n if (isFunction(user.save)) {\n await user.save();\n }\n\n return user;\n }\n\n /**\n * Create a user submission in formio\n * @param user\n */\n async createUser<User = any>(user: Partial<FormioSubmission<User>>) {\n const submission = new this.db.submissionModel({\n owner: null,\n deleted: null,\n roles: [],\n externalsIds: [],\n ...user,\n created: new Date().toISOString(),\n modified: new Date().toISOString()\n });\n\n user.form && (submission.form = this.db.idToBson(user.form));\n\n await submission.save();\n\n return submission.toObject();\n }\n\n /**\n * Update user submission in formio\n * @param user\n */\n async updateUser<User = any>(user: WithID<FormioSubmission<User>>) {\n await this.db.submissionModel.updateOne(\n {\n _id: user._id\n },\n {$set: user}\n );\n\n return user;\n }\n}\n"]}
1
+ {"version":3,"file":"FormioAuthService.js","sourceRoot":"","sources":["../../../src/services/FormioAuthService.ts"],"names":[],"mappings":";;;;AACA,qCAAsC;AACtC,iCAA4C;AAC5C,iDAAoE;AACpE,+BAA+B;AAG/B,qDAAgD;AAChD,6DAAwD;AACxD,mDAA8C;AAG9C,IAAa,iBAAiB,GAA9B,MAAa,iBAAiB;IAU5B,IAAI,WAAW;QACb,OAAO,IAAA,gBAAS,EAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACjD,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;IACnC,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;IACpC,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;IACjC,CAAC;IAED,cAAc,CAAa,IAAoC,EAAE,KAAyB,EAAE,GAAoB;QAC9G,MAAM,OAAO,GAAG,GAAG,CAAC,UAAU,EAAE,CAAC;QACjC,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QAEnC,OAAO,CAAC,UAAU,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACpC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;QACpB,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC,OAA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;QAChE,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC,eAAe,CAAC;YAC7C,KAAK,EAAE,IAAI;YACX,OAAO,EAAE,IAAI;YACb,KAAK,EAAE,EAAE;YACT,YAAY,EAAE,EAAE;YAChB,GAAG,IAAI;YACP,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACjC,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACnC,CAAC,CAAC;QAEH,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAE7D,MAAM,UAAU,CAAC,IAAI,EAAE,CAAC;QAExB,OAAO,UAAU,CAAC,QAAQ,EAAE,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAU,CAAa,IAAoC;QAC/D,MAAM,IAAI,CAAC,EAAE,CAAC,eAAe,CAAC,SAAS,CACrC;YACE,GAAG,EAAE,IAAI,CAAC,GAAG;SACd,EACD,EAAC,IAAI,EAAE,IAAI,EAAC,CACb,CAAC;QAEF,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAnNC;IADC,IAAA,WAAM,GAAE;sCACD,6BAAa;iDAAC;AAGtB;IADC,IAAA,WAAM,GAAE;sCACF,uCAAkB;gDAAC;AAG1B;IADC,IAAA,WAAM,GAAE;sCACL,+BAAc;6CAAC;AARR,iBAAiB;IAD7B,IAAA,eAAU,GAAE;GACA,iBAAiB,CAqN7B;AArNY,8CAAiB","sourcesContent":["import {PlatformContext, Req} from \"@tsed/common\";\nimport {isFunction} from \"@tsed/core\";\nimport {Inject, Injectable} from \"@tsed/di\";\nimport {BadRequest, NotFound, Unauthorized} from \"@tsed/exceptions\";\nimport {promisify} from \"util\";\nimport {FormioPayloadToken} from \"../domain/FormioDecodedToken\";\nimport {FormioForm, FormioSubmission, WithID} from \"../domain/FormioModels\";\nimport {FormioDatabase} from \"./FormioDatabase\";\nimport {FormioHooksService} from \"./FormioHooksService\";\nimport {FormioService} from \"./FormioService\";\n\n@Injectable()\nexport class FormioAuthService {\n @Inject()\n formio: FormioService;\n\n @Inject()\n hooks: FormioHooksService;\n\n @Inject()\n db: FormioDatabase;\n\n get currentUser() {\n return promisify(this.formio.auth.currentUser);\n }\n\n get getToken() {\n return this.formio.auth.getToken;\n }\n\n get tempToken() {\n return this.formio.auth.tempToken;\n }\n\n get logout() {\n return this.formio.auth.logout;\n }\n\n setCurrentUser<User = any>(user: WithID<FormioSubmission<User>>, token: FormioPayloadToken, ctx: PlatformContext) {\n const request = ctx.getRequest();\n const response = ctx.getResponse();\n\n request.submission.data = user.data;\n request.user = user;\n request.token = token.decoded;\n response.token = token.token;\n request[\"x-jwt-token\"] = token.token;\n\n return this;\n }\n\n /**\n * Generate the payload token for the session\n * @param user\n * @param ctx\n */\n async generatePayloadToken<User = any>(\n user: WithID<FormioSubmission<User>>,\n ctx: PlatformContext\n ): Promise<{user: WithID<FormioSubmission<User>>; token: FormioPayloadToken}> {\n const req = ctx.getRequest();\n const audit = this.formio.audit;\n let form: FormioForm | null;\n\n try {\n form = (await this.db.getForm(user.form)) as any;\n } catch (err) {\n audit(\n \"EAUTH_USERFORM\",\n {\n ...req,\n userId: user._id\n },\n user.form,\n err\n );\n throw err;\n }\n\n if (!form) {\n audit(\n \"EAUTH_USERFORM\",\n {\n ...req,\n userId: user._id\n },\n user.form,\n {message: \"User form not found\"}\n );\n\n throw new NotFound(\"User form not found.\");\n }\n\n try {\n user = await this.hooks.alterAsync(\"user\", user);\n } catch (err) {\n // istanbul ignore next\n ctx.logger.debug(err);\n }\n\n await this.hooks.alterAsync(\"login\", user, req);\n\n // Allow anyone to hook and modify the token.\n const token = this.hooks.alter(\n \"token\",\n {\n user: {\n _id: user._id\n },\n form: {\n _id: form?._id\n }\n },\n form,\n req\n );\n\n const decoded = this.hooks.alter(\"tokenDecode\", token, req);\n\n return {\n user,\n token: {\n token: this.getToken(token) as string,\n decoded\n }\n };\n }\n\n /**\n * Generate session from the given authenticated user.\n * @param user\n * @param ctx\n */\n async generateSession<User = any>(user: WithID<FormioSubmission<User>>, ctx: PlatformContext) {\n try {\n const {user: userSession, token} = await this.generatePayloadToken(user, ctx);\n this.setCurrentUser(userSession, token, ctx);\n\n await this.currentUser(ctx.getRequest(), ctx.getResponse());\n } catch (err) {\n ctx.logger.error({event: \"Error on OAuthActions\", error: err});\n throw new Unauthorized(err.message);\n }\n }\n\n /**\n * Retrieve roles\n * @param req\n */\n async getRoles(req?: Req) {\n try {\n const query = this.hooks.alter(\"roleQuery\", {deleted: {$eq: null}}, req);\n return await this.db.roleModel.find(query).sort({title: 1}).lean().exec();\n } catch (err) {\n throw new BadRequest(this.formio.util.errorCodes.role.EROLESLOAD);\n }\n }\n\n /**\n * Update the role of the current user submission\n * @param _id\n * @param role\n * @param req\n */\n async updateUserRole(_id: string | any, role: string, req?: Req) {\n const query = this.hooks.alter(\n \"submissionQuery\",\n {\n _id: this.formio.util.idToBson(_id),\n deleted: {$eq: null}\n },\n req\n );\n\n const user = await this.db.submissionModel.findOne(query).exec();\n\n if (!user) {\n throw new BadRequest(\"No Submission was found with the given setting `submission`.\");\n }\n\n user.roles = [this.formio.util.idToBson(role)];\n\n if (isFunction(user.save)) {\n await user.save();\n }\n\n return user;\n }\n\n /**\n * Create a user submission in formio\n * @param user\n */\n async createUser<User = any>(user: Partial<FormioSubmission<User>>) {\n const submission = new this.db.submissionModel({\n owner: null,\n deleted: null,\n roles: [],\n externalsIds: [],\n ...user,\n created: new Date().toISOString(),\n modified: new Date().toISOString()\n });\n\n user.form && (submission.form = this.db.idToBson(user.form));\n\n await submission.save();\n\n return submission.toObject();\n }\n\n /**\n * Update user submission in formio\n * @param user\n */\n async updateUser<User = any>(user: WithID<FormioSubmission<User>>) {\n await this.db.submissionModel.updateOne(\n {\n _id: user._id\n },\n {$set: user}\n );\n\n return user;\n }\n}\n"]}
@@ -4,11 +4,12 @@ exports.FormioDatabase = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const core_1 = require("@tsed/core");
6
6
  const di_1 = require("@tsed/di");
7
+ const omit_1 = tslib_1.__importDefault(require("lodash/omit"));
7
8
  const FormioMapper_1 = require("../builder/FormioMapper");
8
9
  const isMongoId_1 = require("../utils/isMongoId");
9
10
  const FormioService_1 = require("./FormioService");
10
11
  function toMap(list) {
11
- return (0, core_1.toMap)(list, (o) => [o._id.toString(), `$machineName:${o.machineName}`]);
12
+ return (0, core_1.toMap)(list, (o) => [o._id.toString(), `$machineName:${o.name || o.machineName}`]);
12
13
  }
13
14
  let FormioDatabase = class FormioDatabase {
14
15
  get models() {
@@ -54,7 +55,7 @@ let FormioDatabase = class FormioDatabase {
54
55
  return (await this.formModel.countDocuments()) > 0;
55
56
  }
56
57
  async hasForm(name) {
57
- return !!(await this.formModel.countDocuments({ machineName: { $eq: name } }));
58
+ return !!(await this.formModel.countDocuments({ name: { $eq: name } }));
58
59
  }
59
60
  async getForm(nameOrId) {
60
61
  return this.formModel
@@ -64,21 +65,57 @@ let FormioDatabase = class FormioDatabase {
64
65
  ? {
65
66
  _id: nameOrId
66
67
  }
67
- : { machineName: { $eq: nameOrId } })
68
+ : { name: { $eq: nameOrId } })
68
69
  })
69
70
  .lean()
70
71
  .exec();
71
72
  }
72
- async createFormIfNotExists(form, onCreate) {
73
+ /**
74
+ * Import form previously exported by export tool.
75
+ * This method transform alias to a real mongoose _id
76
+ * @param form
77
+ * @param onCreate
78
+ */
79
+ async importFormIfNotExists(form, onCreate) {
73
80
  if (!(await this.hasForm(form.name))) {
74
- const createForm = await this.saveFormDefinition(form);
81
+ const createForm = await this.importForm(form);
75
82
  onCreate && (await onCreate(createForm));
76
83
  }
77
84
  return this.getForm(form.name);
78
85
  }
79
- async saveFormDefinition(form) {
86
+ /**
87
+ * Import form previously exported by export tool.
88
+ * This method transform alias to a real mongoose _id
89
+ * @param form
90
+ */
91
+ async importForm(form) {
80
92
  const mapper = await this.getFormioMapper();
81
- return new this.formModel(mapper.mapToImport(form)).save();
93
+ return this.saveForm(mapper.mapToImport(form));
94
+ }
95
+ async saveForm(form) {
96
+ form = (0, omit_1.default)(form, ["__v"]);
97
+ return this.formModel.findOneAndUpdate({ _id: form._id }, form, { upsert: true, new: true });
98
+ }
99
+ async getSubmissions(query = {}) {
100
+ return this.submissionModel.find({
101
+ ...query,
102
+ deleted: { $eq: null }
103
+ });
104
+ }
105
+ /**
106
+ * Import submission previously exported by export tool.
107
+ * This method transform alias to a real mongoose _id
108
+ * @param submission
109
+ */
110
+ async importSubmission(submission) {
111
+ const mapper = await this.getFormioMapper();
112
+ return this.saveSubmission(mapper.mapToImport(submission));
113
+ }
114
+ async saveSubmission(submission) {
115
+ submission = (0, omit_1.default)(submission, ["__v"]);
116
+ return this.submissionModel.findOneAndUpdate({
117
+ _id: submission._id
118
+ }, submission, { new: true, upsert: true });
82
119
  }
83
120
  idToBson(form) {
84
121
  if ((0, core_1.isArray)(form)) {
@@ -92,11 +129,11 @@ let FormioDatabase = class FormioDatabase {
92
129
  }
93
130
  }
94
131
  };
95
- (0, tslib_1.__decorate)([
132
+ tslib_1.__decorate([
96
133
  (0, di_1.Inject)(),
97
- (0, tslib_1.__metadata)("design:type", FormioService_1.FormioService)
134
+ tslib_1.__metadata("design:type", FormioService_1.FormioService)
98
135
  ], FormioDatabase.prototype, "formio", void 0);
99
- FormioDatabase = (0, tslib_1.__decorate)([
136
+ FormioDatabase = tslib_1.__decorate([
100
137
  (0, di_1.Injectable)()
101
138
  ], FormioDatabase);
102
139
  exports.FormioDatabase = FormioDatabase;
@@ -1 +1 @@
1
- {"version":3,"file":"FormioDatabase.js","sourceRoot":"","sources":["../../../src/services/FormioDatabase.ts"],"names":[],"mappings":";;;;AAAA,qCAAsE;AACtE,iCAA4C;AAG5C,0DAAqD;AACrD,kDAA6C;AAC7C,mDAA8C;AAE9C,SAAS,KAAK,CAAI,IAAW;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IAED,KAAK,CAAC,kBAAkB,CAAC,IAAgB;QACvC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAE5C,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC7D,CAAC;IAED,QAAQ,CAAC,IAAU;QACjB,IAAI,IAAA,cAAO,EAAC,IAAI,CAAC,EAAE;YACjB,OAAO,EAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAC,CAAC;SACnD;aAAM,IAAI,IAAA,eAAQ,EAAC,IAAI,CAAC,EAAE;YACzB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAE,IAAY,CAAC,GAAG,CAAC,CAAC;SACrD;aAAM,IAAI,IAAA,eAAQ,EAAC,IAAI,CAAC,EAAE;YACzB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;SACxC;IACH,CAAC;CACF,CAAA;AAjGC;IADC,IAAA,WAAM,GAAE;2CACS,6BAAa;8CAAC;AAFrB,cAAc;IAD1B,IAAA,eAAU,GAAE;GACA,cAAc,CAmG1B;AAnGY,wCAAc","sourcesContent":["import {isArray, isObject, isString, toMap as tMap} from \"@tsed/core\";\nimport {Inject, Injectable} from \"@tsed/di\";\nimport {MongooseDocument, MongooseModel} from \"@tsed/mongoose\";\nimport {FormioAction, FormioActionItem, FormioForm, FormioRole, FormioSubmission, FormioToken} from \"@tsed/formio-types\";\nimport {FormioMapper} from \"../builder/FormioMapper\";\nimport {isMongoId} from \"../utils/isMongoId\";\nimport {FormioService} from \"./FormioService\";\n\nfunction toMap<T>(list: any[]) {\n return tMap<string, MongooseDocument<T>>(list, (o: any) => [o._id.toString(), `$machineName:${o.machineName}`]);\n}\n\n@Injectable()\nexport class FormioDatabase {\n @Inject()\n protected formio: FormioService;\n\n get models() {\n return this.formio.mongoose.models;\n }\n\n get roleModel(): MongooseModel<FormioRole> {\n return this.models.role;\n }\n\n get formModel(): MongooseModel<FormioForm> {\n return this.models.form;\n }\n\n get actionModel(): MongooseModel<FormioAction> {\n return this.models.action;\n }\n\n get submissionModel(): MongooseModel<FormioSubmission> {\n return this.models.submission;\n }\n\n get tokenModel(): MongooseModel<FormioToken> {\n return this.models.token;\n }\n\n get actionItemModel(): MongooseModel<FormioActionItem> {\n return this.models.actionItem;\n }\n\n async getFormioMapper(): Promise<FormioMapper> {\n const [roles, forms, actions] = await Promise.all([\n this.roleModel.find({\n deleted: {$eq: null}\n }),\n this.formModel.find({\n deleted: {$eq: null}\n }),\n this.actionModel.find({\n deleted: {$eq: null}\n })\n ]);\n\n return new FormioMapper({\n forms: toMap<FormioForm>(forms),\n actions: toMap<FormioAction>(actions),\n roles: toMap<FormioRole>(roles)\n });\n }\n\n async hasForms(): Promise<boolean> {\n return (await this.formModel.countDocuments()) > 0;\n }\n\n async hasForm(name: string): Promise<boolean> {\n return !!(await this.formModel.countDocuments({machineName: {$eq: name}}));\n }\n\n async getForm(nameOrId: string) {\n return this.formModel\n .findOne({\n deleted: {$eq: null},\n ...(isMongoId(nameOrId)\n ? {\n _id: nameOrId\n }\n : {machineName: {$eq: nameOrId}})\n })\n .lean()\n .exec();\n }\n\n async createFormIfNotExists(form: FormioForm, onCreate?: (form: FormioForm) => any) {\n if (!(await this.hasForm(form.name))) {\n const createForm = await this.saveFormDefinition(form);\n\n onCreate && (await onCreate(createForm));\n }\n\n return this.getForm(form.name);\n }\n\n async saveFormDefinition(form: FormioForm) {\n const mapper = await this.getFormioMapper();\n\n return new this.formModel(mapper.mapToImport(form)).save();\n }\n\n idToBson(form?: any) {\n if (isArray(form)) {\n return {$in: form.map(this.formio.util.idToBson)};\n } else if (isObject(form)) {\n return this.formio.util.idToBson((form as any)._id);\n } else if (isString(form)) {\n return this.formio.util.idToB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AU,GAAG,IAAA,cAAI,EAAC,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;QAEvC,OAAO,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAC1C;YACE,GAAG,EAAE,UAAU,CAAC,GAAG;SACpB,EACD,UAAU,EACV,EAAC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAC,CAC1B,CAAC;IACJ,CAAC;IAED,QAAQ,CAAC,IAAU;QACjB,IAAI,IAAA,cAAO,EAAC,IAAI,CAAC,EAAE;YACjB,OAAO,EAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAC,CAAC;SACnD;aAAM,IAAI,IAAA,eAAQ,EAAC,IAAI,CAAC,EAAE;YACzB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAE,IAAY,CAAC,GAAG,CAAC,CAAC;SACrD;aAAM,IAAI,IAAA,eAAQ,EAAC,IAAI,CAAC,EAAE;YACzB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;SACxC;IACH,CAAC;CACF,CAAA;AAlJC;IADC,IAAA,WAAM,GAAE;sCACS,6BAAa;8CAAC;AAFrB,cAAc;IAD1B,IAAA,eAAU,GAAE;GACA,cAAc,CAoJ1B;AApJY,wCAAc","sourcesContent":["import {isArray, isObject, isString, toMap as tMap} from \"@tsed/core\";\nimport {Inject, Injectable} from \"@tsed/di\";\nimport {MongooseDocument, MongooseModel} from \"@tsed/mongoose\";\nimport type {FilterQuery} from \"mongoose\";\nimport omit from \"lodash/omit\";\nimport {FormioAction, FormioActionItem, FormioForm, FormioRole, FormioSubmission, FormioToken} from \"@tsed/formio-types\";\nimport {FormioMapper} from \"../builder/FormioMapper\";\nimport {isMongoId} from \"../utils/isMongoId\";\nimport {FormioService} from \"./FormioService\";\n\nfunction toMap<T>(list: any[]) {\n return tMap<string, MongooseDocument<T>>(list, (o: any) => [o._id.toString(), `$machineName:${o.name || o.machineName}`]);\n}\n\n@Injectable()\nexport class FormioDatabase {\n @Inject()\n protected formio: FormioService;\n\n get models() {\n return this.formio.mongoose.models;\n }\n\n get roleModel(): MongooseModel<FormioRole> {\n return this.models.role;\n }\n\n get formModel(): MongooseModel<FormioForm> {\n return this.models.form;\n }\n\n get actionModel(): MongooseModel<FormioAction> {\n return this.models.action;\n }\n\n get submissionModel(): MongooseModel<FormioSubmission> {\n return this.models.submission;\n }\n\n get tokenModel(): MongooseModel<FormioToken> {\n return this.models.token;\n }\n\n get actionItemModel(): MongooseModel<FormioActionItem> {\n return this.models.actionItem;\n }\n\n async getFormioMapper(): Promise<FormioMapper> {\n const [roles, forms, actions] = await Promise.all([\n this.roleModel.find({\n deleted: {$eq: null}\n }),\n this.formModel.find({\n deleted: {$eq: null}\n }),\n this.actionModel.find({\n deleted: {$eq: null}\n })\n ]);\n\n return new FormioMapper({\n forms: toMap<FormioForm>(forms),\n actions: toMap<FormioAction>(actions),\n roles: toMap<FormioRole>(roles)\n });\n }\n\n async hasForms(): Promise<boolean> {\n return (await this.formModel.countDocuments()) > 0;\n }\n\n async hasForm(name: string): Promise<boolean> {\n return !!(await this.formModel.countDocuments({name: {$eq: name}}));\n }\n\n async getForm(nameOrId: string) {\n return this.formModel\n .findOne({\n deleted: {$eq: null},\n ...(isMongoId(nameOrId)\n ? {\n _id: nameOrId\n }\n : {name: {$eq: nameOrId}})\n })\n .lean()\n .exec();\n }\n\n /**\n * Import form previously exported by export tool.\n * This method transform alias to a real mongoose _id\n * @param form\n * @param onCreate\n */\n async importFormIfNotExists(form: FormioForm, onCreate?: (form: FormioForm) => any) {\n if (!(await this.hasForm(form.name))) {\n const createForm = await this.importForm(form);\n\n onCreate && (await onCreate(createForm));\n }\n\n return this.getForm(form.name);\n }\n\n /**\n * Import form previously exported by export tool.\n * This method transform alias to a real mongoose _id\n * @param form\n */\n async importForm(form: FormioForm) {\n const mapper = await this.getFormioMapper();\n\n return this.saveForm(mapper.mapToImport(form));\n }\n\n async saveForm(form: FormioForm) {\n form = omit(form, [\"__v\"]) as any;\n\n return this.formModel.findOneAndUpdate({_id: form._id}, form, {upsert: true, new: true});\n }\n\n async getSubmissions<Data>(\n query: FilterQuery<MongooseModel<FormioSubmission<Data>>> = {}\n ): Promise<MongooseDocument<FormioSubmission<Data>>[]> {\n return this.submissionModel.find({\n ...query,\n deleted: {$eq: null}\n }) as any;\n }\n\n /**\n * Import submission previously exported by export tool.\n * This method transform alias to a real mongoose _id\n * @param submission\n */\n async importSubmission<Data = any>(submission: Omit<Partial<FormioSubmission<Data>>, \"form\"> & {form?: any}) {\n const mapper = await this.getFormioMapper();\n\n return this.saveSubmission(mapper.mapToImport(submission));\n }\n\n async saveSubmission<Data = any>(submission: Partial<FormioSubmission<Data>>) {\n submission = omit(submission, [\"__v\"]);\n\n return this.submissionModel.findOneAndUpdate(\n {\n _id: submission._id\n },\n submission,\n {new: true, upsert: true}\n );\n }\n\n idToBson(form?: any) {\n if (isArray(form)) {\n return {$in: form.map(this.formio.util.idToBson)};\n } else if (isObject(form)) {\n return this.formio.util.idToBson((form as any)._id);\n } else if (isString(form)) {\n return this.formio.util.idToBson(form);\n }\n }\n}\n"]}
@@ -66,15 +66,15 @@ let FormioHooksService = class FormioHooksService {
66
66
  }, {});
67
67
  }
68
68
  };
69
- (0, tslib_1.__decorate)([
69
+ tslib_1.__decorate([
70
70
  (0, common_1.Inject)(),
71
- (0, tslib_1.__metadata)("design:type", common_1.InjectorService)
71
+ tslib_1.__metadata("design:type", common_1.InjectorService)
72
72
  ], FormioHooksService.prototype, "injector", void 0);
73
- (0, tslib_1.__decorate)([
73
+ tslib_1.__decorate([
74
74
  (0, common_1.Inject)(FormioService_1.FormioService),
75
- (0, tslib_1.__metadata)("design:type", FormioService_1.FormioService)
75
+ tslib_1.__metadata("design:type", FormioService_1.FormioService)
76
76
  ], FormioHooksService.prototype, "formio", void 0);
77
- FormioHooksService = (0, tslib_1.__decorate)([
77
+ FormioHooksService = tslib_1.__decorate([
78
78
  (0, common_1.Injectable)()
79
79
  ], FormioHooksService);
80
80
  exports.FormioHooksService = FormioHooksService;
@@ -1 +1 @@
1
- {"version":3,"file":"FormioHooksService.js","sourceRoot":"","sources":["../../../src/services/FormioHooksService.ts"],"names":[],"mappings":";;;;AAAA,yCAAiE;AACjE,+BAA+B;AAE/B,mDAA8C;AAI9C,IAAa,kBAAkB,GAA/B,MAAa,kBAAkB;IAO7B,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;IACnC,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;IACjC,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;IAChC,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAA,gBAAS,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,QAAQ;QACN,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC;YACrC,EAAE,EAAE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC;SAChC,CAAC;IACJ,CAAC;IAES,YAAY,CAAC,IAAoB;QACzC,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC;IAES,gBAAgB,CAAC,IAAoB;QAC7C,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;IACtD,CAAC;IAES,SAAS,CAAC,IAAoB,EAAE,KAAiC;QACzE,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,IAA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CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;YAClD,CAAC,CAAC,CACH,CAAC;YAEJ,OAAO;gBACL,GAAG,KAAK;gBACR,CAAC,IAAI,CAAC,EAAG,EAAiB,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC;aAC9C,CAAC;QACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;CACF,CAAA;AAhFC;IADC,IAAA,eAAM,GAAE;2CACW,wBAAe;oDAAC;AAGpC;IADC,IAAA,eAAM,EAAC,6BAAa,CAAC;2CACJ,6BAAa;kDAAC;AALrB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;GACA,kBAAkB,CAkF9B;AAlFY,gDAAkB","sourcesContent":["import {Inject, Injectable, InjectorService} from \"@tsed/common\";\nimport {promisify} from \"util\";\nimport {FormioHooks} from \"../domain/FormioHooks\";\nimport {FormioService} from \"./FormioService\";\nimport {Request} from \"express\";\n\n@Injectable()\nexport class FormioHooksService {\n @Inject()\n protected injector: InjectorService;\n\n @Inject(FormioService)\n protected formio: FormioService;\n\n get settings(): (req: Request, cb: Function) => void {\n return this.formio.hook.settings;\n }\n\n get invoke() {\n return this.formio.hook.invoke;\n }\n\n get alter(): (event: string, ...args: any[]) => any {\n return this.formio.hook.alter;\n }\n\n get alterAsync(): (event: string, ...args: any[]) => Promise<any> {\n return promisify(this.alter);\n }\n\n getHooks(): FormioHooks {\n return {\n alter: this.getHooksProvider(\"alter\"),\n on: this.getHooksProvider(\"on\")\n };\n }\n\n protected getProviders(type: \"alter\" | \"on\") {\n return this.injector.getProviders(`formio:${type}`);\n }\n\n protected getHooksProvider(type: \"alter\" | \"on\") {\n return this.bindHooks(type, this.createHooks(type));\n }\n\n protected bindHooks(type: \"alter\" | \"on\", hooks: Record<string, Function[]>) {\n return Object.entries(hooks).reduce((newHooks, [key, pool]) => {\n const wrap = (input: any, ...args: any[]): any => {\n let last: any;\n\n for (const fn of pool) {\n const result = fn(input, ...args);\n\n if (type === \"alter\") {\n input = result;\n } else {\n last = result;\n }\n }\n\n return type === \"alter\" ? input : last;\n };\n\n return {\n ...newHooks,\n [key]: wrap\n };\n }, {});\n }\n\n private createHooks(type: \"alter\" | \"on\") {\n return this.getProviders(type).reduce<Record<string, Function[]>>((hooks, provider) => {\n const instance = this.injector.invoke<any>(provider.token);\n const name = provider.store.get(`formio:${type}:name`);\n const pool: Function[] = hooks[name] || [];\n\n const hook = (...args: any[]) =>\n instance[type === \"alter\" ? \"transform\" : \"on\"](\n ...args.map((input: any) => {\n return input && input.$ctx ? input.$ctx : input;\n })\n );\n\n return {\n ...hooks,\n [name]: ([] as Function[]).concat(pool, hook)\n };\n }, {});\n }\n}\n"]}
1
+ {"version":3,"file":"FormioHooksService.js","sourceRoot":"","sources":["../../../src/services/FormioHooksService.ts"],"names":[],"mappings":";;;;AAAA,yCAAiE;AACjE,+BAA+B;AAE/B,mDAA8C;AAI9C,IAAa,kBAAkB,GAA/B,MAAa,kBAAkB;IAO7B,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;IACnC,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;IACjC,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;IAChC,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAA,gBAAS,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,QAAQ;QACN,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC;YACrC,EAAE,EAAE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC;SAChC,CAAC;IACJ,CAAC;IAES,YAAY,CAAC,IAAoB;QACzC,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,UAAU,IAAI,EAAE,CA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,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YAE3C,MAAM,IAAI,GAAG,CAAC,GAAG,IAAW,EAAE,EAAE,CAC9B,QAAQ,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAC7C,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,KAAU,EAAE,EAAE;gBACzB,OAAO,KAAK,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;YAClD,CAAC,CAAC,CACH,CAAC;YAEJ,OAAO;gBACL,GAAG,KAAK;gBACR,CAAC,IAAI,CAAC,EAAG,EAAiB,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC;aAC9C,CAAC;QACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;CACF,CAAA;AAhFC;IADC,IAAA,eAAM,GAAE;sCACW,wBAAe;oDAAC;AAGpC;IADC,IAAA,eAAM,EAAC,6BAAa,CAAC;sCACJ,6BAAa;kDAAC;AALrB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;GACA,kBAAkB,CAkF9B;AAlFY,gDAAkB","sourcesContent":["import {Inject, Injectable, InjectorService} from \"@tsed/common\";\nimport {promisify} from \"util\";\nimport {FormioHooks} from \"../domain/FormioHooks\";\nimport {FormioService} from \"./FormioService\";\nimport {Request} from \"express\";\n\n@Injectable()\nexport class FormioHooksService {\n @Inject()\n protected injector: InjectorService;\n\n @Inject(FormioService)\n protected formio: FormioService;\n\n get settings(): (req: Request, cb: Function) => void {\n return this.formio.hook.settings;\n }\n\n get invoke() {\n return this.formio.hook.invoke;\n }\n\n get alter(): (event: string, ...args: any[]) => any {\n return this.formio.hook.alter;\n }\n\n get alterAsync(): (event: string, ...args: any[]) => Promise<any> {\n return promisify(this.alter);\n }\n\n getHooks(): FormioHooks {\n return {\n alter: this.getHooksProvider(\"alter\"),\n on: this.getHooksProvider(\"on\")\n };\n }\n\n protected getProviders(type: \"alter\" | \"on\") {\n return this.injector.getProviders(`formio:${type}`);\n }\n\n protected getHooksProvider(type: \"alter\" | \"on\") {\n return this.bindHooks(type, this.createHooks(type));\n }\n\n protected bindHooks(type: \"alter\" | \"on\", hooks: Record<string, Function[]>) {\n return Object.entries(hooks).reduce((newHooks, [key, pool]) => {\n const wrap = (input: any, ...args: any[]): any => {\n let last: any;\n\n for (const fn of pool) {\n const result = fn(input, ...args);\n\n if (type === \"alter\") {\n input = result;\n } else {\n last = result;\n }\n }\n\n return type === \"alter\" ? input : last;\n };\n\n return {\n ...newHooks,\n [key]: wrap\n };\n }, {});\n }\n\n private createHooks(type: \"alter\" | \"on\") {\n return this.getProviders(type).reduce<Record<string, Function[]>>((hooks, provider) => {\n const instance = this.injector.invoke<any>(provider.token);\n const name = provider.store.get(`formio:${type}:name`);\n const pool: Function[] = hooks[name] || [];\n\n const hook = (...args: any[]) =>\n instance[type === \"alter\" ? \"transform\" : \"on\"](\n ...args.map((input: any) => {\n return input && input.$ctx ? input.$ctx : input;\n })\n );\n\n return {\n ...hooks,\n [name]: ([] as Function[]).concat(pool, hook)\n };\n }, {});\n }\n}\n"]}
@@ -35,15 +35,15 @@ let FormioInstaller = class FormioInstaller extends FormioDatabase_1.FormioDatab
35
35
  });
36
36
  }
37
37
  };
38
- (0, tslib_1.__decorate)([
38
+ tslib_1.__decorate([
39
39
  (0, di_1.Inject)(),
40
- (0, tslib_1.__metadata)("design:type", FormioService_1.FormioService)
40
+ tslib_1.__metadata("design:type", FormioService_1.FormioService)
41
41
  ], FormioInstaller.prototype, "formio", void 0);
42
- (0, tslib_1.__decorate)([
42
+ tslib_1.__decorate([
43
43
  (0, di_1.Inject)(),
44
- (0, tslib_1.__metadata)("design:type", logger_1.Logger)
44
+ tslib_1.__metadata("design:type", logger_1.Logger)
45
45
  ], FormioInstaller.prototype, "logger", void 0);
46
- FormioInstaller = (0, tslib_1.__decorate)([
46
+ FormioInstaller = tslib_1.__decorate([
47
47
  (0, di_1.Injectable)()
48
48
  ], FormioInstaller);
49
49
  exports.FormioInstaller = FormioInstaller;
@@ -1 +1 @@
1
- {"version":3,"file":"FormioInstaller.js","sourceRoot":"","sources":["../../../src/services/FormioInstaller.ts"],"names":[],"mappings":";;;;AAAA,iCAA4C;AAC5C,yCAAoC;AAGpC,qDAAgD;AAChD,mDAA8C;AAG9C,IAAa,eAAe,GAA5B,MAAa,eAAgB,SAAQ,+BAAc;IAOjD,KAAK,CAAC,OAAO,CAAC,QAAwB,EAAE,IAAS;QAC/C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;QAC/C,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAEtD,IAAI,IAAI,EAAE;YACR,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;YACxC,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;SAC3C;IACH,CAAC;IAED,KAAK,CAAC,cAAc,CAAiB,IAAuC,EAAE,QAAwB;QACpG,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEtD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;;YACrC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAC3C;gBACE,IAAI,EAAE,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG;gBAClC,IAAI,EAAE;oBACJ,KAAK,EAAE,IAAI,CAAC,KAAK;oBACjB,QAAQ,EAAE,IAAI;iBACf;gBACD,KAAK,EAAE,CAAC,MAAA,QAAQ,CAAC,KAAK,0CAAE,aAAa,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;aAC3D,EACD,CAAC,GAAY,EAAE,IAAS,EAAE,EAAE;gBAC1B,IAAI,GAAG,EAAE;oBACP,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;iBACpB;gBAED,OAAO,CAAC,IAAI,CAAC,CAAC;YAChB,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAtCC;IADC,IAAA,WAAM,GAAE;2CACS,6BAAa;+CAAC;AAGhC;IADC,IAAA,WAAM,GAAE;2CACS,eAAM;+CAAC;AALd,eAAe;IAD3B,IAAA,eAAU,GAAE;GACA,eAAe,CAwC3B;AAxCY,0CAAe","sourcesContent":["import {Inject, Injectable} from \"@tsed/di\";\nimport {Logger} from \"@tsed/logger\";\nimport {FormioSubmission} from \"../domain/FormioModels\";\nimport {FormioTemplate} from \"../domain/FormioTemplate\";\nimport {FormioDatabase} from \"./FormioDatabase\";\nimport {FormioService} from \"./FormioService\";\n\n@Injectable()\nexport class FormioInstaller extends FormioDatabase {\n @Inject()\n protected formio: FormioService;\n\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"]}
1
+ {"version":3,"file":"FormioInstaller.js","sourceRoot":"","sources":["../../../src/services/FormioInstaller.ts"],"names":[],"mappings":";;;;AAAA,iCAA4C;AAC5C,yCAAoC;AAGpC,qDAAgD;AAChD,mDAA8C;A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AAE;sCACS,6BAAa;+CAAC;AAGhC;IADC,IAAA,WAAM,GAAE;sCACS,eAAM;+CAAC;AALd,eAAe;IAD3B,IAAA,eAAU,GAAE;GACA,eAAe,CAwC3B;AAxCY,0CAAe","sourcesContent":["import {Inject, Injectable} from \"@tsed/di\";\nimport {Logger} from \"@tsed/logger\";\nimport {FormioSubmission} from \"../domain/FormioModels\";\nimport {FormioTemplate} from \"../domain/FormioTemplate\";\nimport {FormioDatabase} from \"./FormioDatabase\";\nimport {FormioService} from \"./FormioService\";\n\n@Injectable()\nexport class FormioInstaller extends FormioDatabase {\n @Inject()\n protected formio: FormioService;\n\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"]}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FormioRepository = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const di_1 = require("@tsed/di");
6
+ const FormioDatabase_1 = require("./FormioDatabase");
7
+ class FormioRepository {
8
+ async getFormId() {
9
+ if (!this.formId) {
10
+ const form = await this.formioDatabase.formModel.findOne({ name: { $eq: this.formName } });
11
+ if (form) {
12
+ this.formId = form._id;
13
+ }
14
+ }
15
+ return this.formId;
16
+ }
17
+ async saveSubmission(submission) {
18
+ return this.formioDatabase.saveSubmission({
19
+ ...submission,
20
+ form: submission.form || (await this.getFormId())
21
+ });
22
+ }
23
+ async getSubmissions(query = {}) {
24
+ return this.formioDatabase.getSubmissions({
25
+ ...query,
26
+ form: await this.getFormId()
27
+ });
28
+ }
29
+ async findOneSubmission(query) {
30
+ return this.formioDatabase.submissionModel.findOne({
31
+ form: await this.getFormId(),
32
+ deleted: null,
33
+ ...query
34
+ });
35
+ }
36
+ }
37
+ tslib_1.__decorate([
38
+ (0, di_1.Inject)(),
39
+ tslib_1.__metadata("design:type", FormioDatabase_1.FormioDatabase)
40
+ ], FormioRepository.prototype, "formioDatabase", void 0);
41
+ exports.FormioRepository = FormioRepository;
42
+ //# sourceMappingURL=FormioRepository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormioRepository.js","sourceRoot":"","sources":["../../../src/services/FormioRepository.ts"],"names":[],"mappings":";;;;AACA,iCAAgC;AAGhC,qDAAgD;AAEhD,MAAsB,gBAAgB;IAQpC,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"]}
@@ -4,9 +4,12 @@ exports.FormioService = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const common_1 = require("@tsed/common");
6
6
  const util_1 = require("util");
7
- const createRouter = require("formio");
8
- const swagger = require("formio/src/util/swagger.js");
9
- const util = require("formio/src/util/util.js");
7
+ // @ts-ignore
8
+ const formio_1 = tslib_1.__importDefault(require("formio"));
9
+ // @ts-ignore
10
+ const swagger_js_1 = tslib_1.__importDefault(require("formio/src/util/swagger.js"));
11
+ // @ts-ignore
12
+ const util_js_1 = tslib_1.__importDefault(require("formio/src/util/util.js"));
10
13
  let FormioService = class FormioService {
11
14
  get audit() {
12
15
  return this.formio.audit || (() => { });
@@ -16,7 +19,7 @@ let FormioService = class FormioService {
16
19
  }
17
20
  // istanbul ignore next
18
21
  get swagger() {
19
- return (...args) => new Promise((resolve) => swagger(...args, resolve));
22
+ return (...args) => new Promise((resolve) => (0, swagger_js_1.default)(...args, resolve));
20
23
  }
21
24
  get config() {
22
25
  return this.formio.config;
@@ -65,7 +68,7 @@ let FormioService = class FormioService {
65
68
  }
66
69
  // istanbul ignore next
67
70
  createRouter(options) {
68
- return createRouter(options);
71
+ return (0, formio_1.default)(options);
69
72
  }
70
73
  init(options, hooks = {}) {
71
74
  if (options && Object.keys(options).length) {
@@ -85,15 +88,15 @@ let FormioService = class FormioService {
85
88
  }
86
89
  bindLogger() {
87
90
  const { injector } = this;
88
- util.log = injector.logger.info.bind(injector.logger);
89
- util.error = injector.logger.error.bind(injector.logger);
91
+ util_js_1.default.log = injector.logger.info.bind(injector.logger);
92
+ util_js_1.default.error = injector.logger.error.bind(injector.logger);
90
93
  }
91
94
  };
92
- (0, tslib_1.__decorate)([
95
+ tslib_1.__decorate([
93
96
  (0, common_1.Inject)(),
94
- (0, tslib_1.__metadata)("design:type", common_1.InjectorService)
97
+ tslib_1.__metadata("design:type", common_1.InjectorService)
95
98
  ], FormioService.prototype, "injector", void 0);
96
- FormioService = (0, tslib_1.__decorate)([
99
+ FormioService = tslib_1.__decorate([
97
100
  (0, common_1.Injectable)()
98
101
  ], FormioService);
99
102
  exports.FormioService = FormioService;