@tsed/formio 7.0.0-beta.2 → 7.0.0-beta.5
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/.mocharc.js +2 -2
- package/.nycrc +6 -5
- package/lib/cjs/FormioModule.js +21 -21
- package/lib/cjs/FormioModule.js.map +1 -1
- package/lib/cjs/builder/FormioMapper.js +11 -3
- package/lib/cjs/builder/FormioMapper.js.map +1 -1
- package/lib/cjs/components/AlterActions.js +61 -16
- package/lib/cjs/components/AlterActions.js.map +1 -1
- package/lib/cjs/components/AlterAudit.js +1 -1
- package/lib/cjs/components/AlterAudit.js.map +1 -1
- package/lib/cjs/components/AlterHost.js +1 -1
- package/lib/cjs/components/AlterLog.js +1 -1
- package/lib/cjs/components/AlterSkip.js +5 -5
- package/lib/cjs/components/AlterTemplateExportSteps.js +5 -5
- package/lib/cjs/components/AlterTemplateExportSteps.js.map +1 -1
- package/lib/cjs/components/AlterTemplateImportSteps.js +5 -5
- package/lib/cjs/components/AlterTemplateImportSteps.js.map +1 -1
- package/lib/cjs/domain/FormioHooks.js.map +1 -1
- package/lib/cjs/domain/FormioModels.js +1 -1
- package/lib/cjs/domain/FormioModels.js.map +1 -1
- package/lib/cjs/domain/Resource.js.map +1 -1
- package/lib/cjs/index.js +46 -42
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/middlewares/FormioAuthMiddleware.js +8 -8
- package/lib/cjs/middlewares/FormioAuthMiddleware.js.map +1 -1
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/services/FormioAuthService.js +7 -7
- package/lib/cjs/services/FormioAuthService.js.map +1 -1
- package/lib/cjs/services/FormioDatabase.js +47 -10
- package/lib/cjs/services/FormioDatabase.js.map +1 -1
- package/lib/cjs/services/FormioHooksService.js +5 -5
- package/lib/cjs/services/FormioHooksService.js.map +1 -1
- package/lib/cjs/services/FormioInstaller.js +5 -5
- package/lib/cjs/services/FormioInstaller.js.map +1 -1
- package/lib/cjs/services/FormioRepository.js +42 -0
- package/lib/cjs/services/FormioRepository.js.map +1 -0
- package/lib/cjs/services/FormioService.js +13 -10
- package/lib/cjs/services/FormioService.js.map +1 -1
- package/lib/esm/FormioModule.js +11 -11
- package/lib/esm/builder/FormioMapper.js +11 -3
- package/lib/esm/builder/FormioMapper.js.map +1 -1
- package/lib/esm/components/AlterActions.js +58 -13
- package/lib/esm/components/AlterActions.js.map +1 -1
- package/lib/esm/components/AlterAudit.js +1 -1
- package/lib/esm/components/AlterAudit.js.map +1 -1
- package/lib/esm/components/AlterHost.js +1 -1
- package/lib/esm/components/AlterLog.js +1 -1
- package/lib/esm/components/AlterSkip.js +1 -1
- package/lib/esm/components/AlterTemplateExportSteps.js +3 -3
- package/lib/esm/components/AlterTemplateExportSteps.js.map +1 -1
- package/lib/esm/components/AlterTemplateImportSteps.js +3 -3
- package/lib/esm/components/AlterTemplateImportSteps.js.map +1 -1
- package/lib/esm/decorators/useFormioAuth.js +1 -1
- package/lib/esm/domain/FormioHooks.js.map +1 -1
- package/lib/esm/domain/Resource.js.map +1 -1
- package/lib/esm/index.js +46 -42
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/middlewares/FormioAuthMiddleware.js +1 -1
- package/lib/esm/package.json +3 -0
- package/lib/esm/services/FormioAuthService.js +3 -3
- package/lib/esm/services/FormioAuthService.js.map +1 -1
- package/lib/esm/services/FormioDatabase.js +47 -10
- package/lib/esm/services/FormioDatabase.js.map +1 -1
- package/lib/esm/services/FormioHooksService.js +1 -1
- package/lib/esm/services/FormioInstaller.js +2 -2
- package/lib/esm/services/FormioRepository.js +38 -0
- package/lib/esm/services/FormioRepository.js.map +1 -0
- package/lib/esm/services/FormioService.js +6 -3
- package/lib/esm/services/FormioService.js.map +1 -1
- package/lib/types/components/AlterActions.d.ts +8 -3
- package/lib/types/components/AlterAudit.d.ts +2 -2
- package/lib/types/domain/FormioHooks.d.ts +1 -1
- package/lib/types/domain/Resource.d.ts +2 -2
- package/lib/types/index.d.ts +22 -14
- package/lib/types/services/FormioAuthService.d.ts +14 -3
- package/lib/types/services/FormioDatabase.d.ts +47 -8
- package/lib/types/services/FormioRepository.d.ts +24 -0
- package/package.json +21 -15
- package/readme.md +5 -9
- package/tsconfig.compile.esm.json +1 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormioAuthService.js","sourceRoot":"","sources":["../../../src/services/FormioAuthService.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAC;AACtC,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAC,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAC,SAAS,EAAC,MAAM,MAAM,CAAC;AAG/B,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAG9C,IAAa,iBAAiB,GAA9B,MAAa,iBAAiB;IAU5B,IAAI,WAAW;QACb,OAAO,SAAS,CAAC,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;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I,CAAC,EAAE;YACzB,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;SACnB;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAU,CAAa,IAAqC;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;AApNC;IADC,MAAM,EAAE;8BACD,aAAa;iDAAC;AAGtB;IADC,MAAM,EAAE;8BACF,kBAAkB;gDAAC;AAG1B;IADC,MAAM,EAAE;8BACL,cAAc;6CAAC;AARR,iBAAiB;IAD7B,UAAU,EAAE;GACA,iBAAiB,CAsN7B;SAtNY,iBAAiB","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,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAC;AACtC,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAC,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAC,SAAS,EAAC,MAAM,MAAM,CAAC;AAG/B,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAG9C,IAAa,iBAAiB,GAA9B,MAAa,iBAAiB;IAU5B,IAAI,WAAW;QACb,OAAO,SAAS,CAAC,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,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EAAE,CAAC;SACnB;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAU,CAAa,IAAqC;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,MAAM,EAAE;8BACD,aAAa;iDAAC;AAGtB;IADC,MAAM,EAAE;8BACF,kBAAkB;gDAAC;AAG1B;IADC,MAAM,EAAE;8BACL,cAAc;6CAAC;AARR,iBAAiB;IAD7B,UAAU,EAAE;GACA,iBAAiB,CAqN7B;SArNY,iBAAiB","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"]}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { isArray, isObject, isString, toMap as tMap } from "@tsed/core";
|
|
3
3
|
import { Inject, Injectable } from "@tsed/di";
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import omit from "lodash/omit";
|
|
5
|
+
import { FormioMapper } from "../builder/FormioMapper.js";
|
|
6
|
+
import { isMongoId } from "../utils/isMongoId.js";
|
|
7
|
+
import { FormioService } from "./FormioService.js";
|
|
7
8
|
function toMap(list) {
|
|
8
|
-
return tMap(list, (o) => [o._id.toString(), `$machineName:${o.machineName}`]);
|
|
9
|
+
return tMap(list, (o) => [o._id.toString(), `$machineName:${o.name || o.machineName}`]);
|
|
9
10
|
}
|
|
10
11
|
let FormioDatabase = class FormioDatabase {
|
|
11
12
|
get models() {
|
|
@@ -51,7 +52,7 @@ let FormioDatabase = class FormioDatabase {
|
|
|
51
52
|
return (await this.formModel.countDocuments()) > 0;
|
|
52
53
|
}
|
|
53
54
|
async hasForm(name) {
|
|
54
|
-
return !!(await this.formModel.countDocuments({
|
|
55
|
+
return !!(await this.formModel.countDocuments({ name: { $eq: name } }));
|
|
55
56
|
}
|
|
56
57
|
async getForm(nameOrId) {
|
|
57
58
|
return this.formModel
|
|
@@ -61,21 +62,57 @@ let FormioDatabase = class FormioDatabase {
|
|
|
61
62
|
? {
|
|
62
63
|
_id: nameOrId
|
|
63
64
|
}
|
|
64
|
-
: {
|
|
65
|
+
: { name: { $eq: nameOrId } })
|
|
65
66
|
})
|
|
66
67
|
.lean()
|
|
67
68
|
.exec();
|
|
68
69
|
}
|
|
69
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Import form previously exported by export tool.
|
|
72
|
+
* This method transform alias to a real mongoose _id
|
|
73
|
+
* @param form
|
|
74
|
+
* @param onCreate
|
|
75
|
+
*/
|
|
76
|
+
async importFormIfNotExists(form, onCreate) {
|
|
70
77
|
if (!(await this.hasForm(form.name))) {
|
|
71
|
-
const createForm = await this.
|
|
78
|
+
const createForm = await this.importForm(form);
|
|
72
79
|
onCreate && (await onCreate(createForm));
|
|
73
80
|
}
|
|
74
81
|
return this.getForm(form.name);
|
|
75
82
|
}
|
|
76
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Import form previously exported by export tool.
|
|
85
|
+
* This method transform alias to a real mongoose _id
|
|
86
|
+
* @param form
|
|
87
|
+
*/
|
|
88
|
+
async importForm(form) {
|
|
77
89
|
const mapper = await this.getFormioMapper();
|
|
78
|
-
return
|
|
90
|
+
return this.saveForm(mapper.mapToImport(form));
|
|
91
|
+
}
|
|
92
|
+
async saveForm(form) {
|
|
93
|
+
form = omit(form, ["__v"]);
|
|
94
|
+
return this.formModel.findOneAndUpdate({ _id: form._id }, form, { upsert: true, new: true });
|
|
95
|
+
}
|
|
96
|
+
async getSubmissions(query = {}) {
|
|
97
|
+
return this.submissionModel.find({
|
|
98
|
+
...query,
|
|
99
|
+
deleted: { $eq: null }
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Import submission previously exported by export tool.
|
|
104
|
+
* This method transform alias to a real mongoose _id
|
|
105
|
+
* @param submission
|
|
106
|
+
*/
|
|
107
|
+
async importSubmission(submission) {
|
|
108
|
+
const mapper = await this.getFormioMapper();
|
|
109
|
+
return this.saveSubmission(mapper.mapToImport(submission));
|
|
110
|
+
}
|
|
111
|
+
async saveSubmission(submission) {
|
|
112
|
+
submission = omit(submission, ["__v"]);
|
|
113
|
+
return this.submissionModel.findOneAndUpdate({
|
|
114
|
+
_id: submission._id
|
|
115
|
+
}, submission, { new: true, upsert: true });
|
|
79
116
|
}
|
|
80
117
|
idToBson(form) {
|
|
81
118
|
if (isArray(form)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormioDatabase.js","sourceRoot":"","sources":["../../../src/services/FormioDatabase.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,IAAI,IAAI,EAAC,MAAM,YAAY,CAAC;AACtE,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAG5C,OAAO,EAAC,YAAY,EAAC,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAE9C,SAAS,KAAK,CAAI,IAAW;IAC3B,OAAO,IAAI,CAA8B,IAAI,EAAE,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,gBAAgB,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"FormioDatabase.js","sourceRoot":"","sources":["../../../src/services/FormioDatabase.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,IAAI,IAAI,EAAC,MAAM,YAAY,CAAC;AACtE,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAG5C,OAAO,IAAI,MAAM,aAAa,CAAC;AAE/B,OAAO,EAAC,YAAY,EAAC,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAE9C,SAAS,KAAK,CAAI,IAAW;IAC3B,OAAO,IAAI,CAA8B,IAAI,EAAE,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,gBAAgB,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,C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nD;aAAM,IAAI,QAAQ,CAAC,IAAI,CAAC,EAAE;YACzB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAE,IAAY,CAAC,GAAG,CAAC,CAAC;SACrD;aAAM,IAAI,QAAQ,CAAC,IAAI,CAAC,EAAE;YACzB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;SACxC;IACH,CAAC;CACF,CAAA;AAlJC;IADC,MAAM,EAAE;8BACS,aAAa;8CAAC;AAFrB,cAAc;IAD1B,UAAU,EAAE;GACA,cAAc,CAoJ1B;SApJY,cAAc","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"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { Inject, Injectable, InjectorService } from "@tsed/common";
|
|
3
3
|
import { promisify } from "util";
|
|
4
|
-
import { FormioService } from "./FormioService";
|
|
4
|
+
import { FormioService } from "./FormioService.js";
|
|
5
5
|
let FormioHooksService = class FormioHooksService {
|
|
6
6
|
get settings() {
|
|
7
7
|
return this.formio.hook.settings;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { Inject, Injectable } from "@tsed/di";
|
|
3
3
|
import { Logger } from "@tsed/logger";
|
|
4
|
-
import { FormioDatabase } from "./FormioDatabase";
|
|
5
|
-
import { FormioService } from "./FormioService";
|
|
4
|
+
import { FormioDatabase } from "./FormioDatabase.js";
|
|
5
|
+
import { FormioService } from "./FormioService.js";
|
|
6
6
|
let FormioInstaller = class FormioInstaller extends FormioDatabase {
|
|
7
7
|
async install(template, root) {
|
|
8
8
|
this.logger.info("Install formio template...");
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Inject } from "@tsed/di";
|
|
3
|
+
import { FormioDatabase } from "./FormioDatabase.js";
|
|
4
|
+
export class FormioRepository {
|
|
5
|
+
async getFormId() {
|
|
6
|
+
if (!this.formId) {
|
|
7
|
+
const form = await this.formioDatabase.formModel.findOne({ name: { $eq: this.formName } });
|
|
8
|
+
if (form) {
|
|
9
|
+
this.formId = form._id;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return this.formId;
|
|
13
|
+
}
|
|
14
|
+
async saveSubmission(submission) {
|
|
15
|
+
return this.formioDatabase.saveSubmission({
|
|
16
|
+
...submission,
|
|
17
|
+
form: submission.form || (await this.getFormId())
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async getSubmissions(query = {}) {
|
|
21
|
+
return this.formioDatabase.getSubmissions({
|
|
22
|
+
...query,
|
|
23
|
+
form: await this.getFormId()
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async findOneSubmission(query) {
|
|
27
|
+
return this.formioDatabase.submissionModel.findOne({
|
|
28
|
+
form: await this.getFormId(),
|
|
29
|
+
deleted: null,
|
|
30
|
+
...query
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
__decorate([
|
|
35
|
+
Inject(),
|
|
36
|
+
__metadata("design:type", FormioDatabase)
|
|
37
|
+
], FormioRepository.prototype, "formioDatabase", void 0);
|
|
38
|
+
//# sourceMappingURL=FormioRepository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormioRepository.js","sourceRoot":"","sources":["../../../src/services/FormioRepository.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAGhC,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD,MAAM,OAAgB,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,MAAM,EAAE;8BACiB,cAAc;wDAAC","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"]}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { Inject, Injectable, InjectorService } from "@tsed/common";
|
|
3
3
|
import { promisify } from "util";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
import createRouter from "formio";
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
import swagger from "formio/src/util/swagger.js";
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
import util from "formio/src/util/util.js";
|
|
7
10
|
let FormioService = class FormioService {
|
|
8
11
|
get audit() {
|
|
9
12
|
return this.formio.audit || (() => { });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormioService.js","sourceRoot":"","sources":["../../../src/services/FormioService.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAE,UAAU,EAAE,eAAe,EAAC,MAAM,cAAc,CAAC;AAIjE,OAAO,EAAC,SAAS,EAAC,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"FormioService.js","sourceRoot":"","sources":["../../../src/services/FormioService.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAE,UAAU,EAAE,eAAe,EAAC,MAAM,cAAc,CAAC;AAIjE,OAAO,EAAC,SAAS,EAAC,MAAM,MAAM,CAAC;AAQ/B,aAAa;AACb,OAAO,YAAY,MAAM,QAAQ,CAAC;AAClC,aAAa;AACb,OAAO,OAAO,MAAM,4BAA4B,CAAC;AACjD,aAAa;AACb,OAAO,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,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,IAAI,CAAC,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACtD,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3D,CAAC;CACF,CAAA;AA3GC;IADC,MAAM,EAAE;8BACW,eAAe;+CAAC;AAJzB,aAAa;IADzB,UAAU,EAAE;GACA,aAAa,CA+GzB;SA/GY,aAAa","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"]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { PlatformContext } from "@tsed/common";
|
|
2
1
|
import { InjectorService, Provider } from "@tsed/di";
|
|
2
|
+
import { PlatformParams } from "@tsed/platform-params";
|
|
3
|
+
import { PlatformResponseFilter } from "@tsed/platform-response-filter";
|
|
4
|
+
import { PlatformContext } from "@tsed/common";
|
|
3
5
|
import { AlterHook } from "../domain/AlterHook";
|
|
4
6
|
import { SetActionItemMessage } from "../domain/FormioAction";
|
|
5
7
|
import { FormioActions } from "../domain/FormioActionsIndex";
|
|
@@ -7,9 +9,12 @@ import { FormioService } from "../services/FormioService";
|
|
|
7
9
|
export declare class AlterActions implements AlterHook {
|
|
8
10
|
protected injector: InjectorService;
|
|
9
11
|
protected formio: FormioService;
|
|
12
|
+
protected params: PlatformParams;
|
|
13
|
+
protected responseFilter: PlatformResponseFilter;
|
|
10
14
|
transform(actions: FormioActions): FormioActions;
|
|
11
15
|
protected getActions(): Provider<any>[];
|
|
12
|
-
protected
|
|
16
|
+
protected createHandler(provider: Provider, propertyKey: string | symbol): (action: any, handler: string, method: string, req: {
|
|
13
17
|
$ctx: PlatformContext;
|
|
14
|
-
}, res:
|
|
18
|
+
}, res: any, next: any, setActionItemMessage: SetActionItemMessage) => Promise<void>;
|
|
19
|
+
private flush;
|
|
15
20
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DIContext } from "@tsed/di";
|
|
2
2
|
import { AlterHook } from "../domain/AlterHook";
|
|
3
3
|
export declare class AlterAudit implements AlterHook {
|
|
4
|
-
transform(info: any[], event: string, ctx:
|
|
4
|
+
transform(info: any[], event: string, ctx: DIContext): boolean;
|
|
5
5
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MongooseDocument } from "@tsed/mongoose";
|
|
2
|
-
import { Request } from "express";
|
|
2
|
+
import { Request, Response } from "express";
|
|
3
3
|
import { FilterQuery, Schema, SchemaDefinition } from "mongoose";
|
|
4
4
|
import { Formio } from "./Formio";
|
|
5
5
|
import { FormioActions } from "./FormioActionsIndex";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare type ResourceHttpHandler = (req: Request, res: Response, next:
|
|
1
|
+
import { Request, Response, NextFunction } from "express";
|
|
2
|
+
export declare type ResourceHttpHandler = (req: Request, res: Response, next: NextFunction) => void;
|
|
3
3
|
export interface ResourceHttpMethodOptions {
|
|
4
4
|
before?: ResourceHttpHandler;
|
|
5
5
|
after?: ResourceHttpHandler;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,38 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./FormioModule";
|
|
5
|
+
export * from "./builder/FormioMapper";
|
|
6
|
+
export * from "./components/AlterActions";
|
|
7
|
+
export * from "./components/AlterAudit";
|
|
8
|
+
export * from "./components/AlterHost";
|
|
9
|
+
export * from "./components/AlterLog";
|
|
10
|
+
export * from "./components/AlterSkip";
|
|
11
|
+
export * from "./components/AlterTemplateExportSteps";
|
|
12
|
+
export * from "./components/AlterTemplateImportSteps";
|
|
1
13
|
export * from "./decorators/action";
|
|
2
14
|
export * from "./decorators/actionCtx";
|
|
3
15
|
export * from "./decorators/alter";
|
|
4
16
|
export * from "./decorators/on";
|
|
5
17
|
export * from "./decorators/useFormioAuth";
|
|
6
|
-
export * from "./middlewares/FormioAuthMiddleware";
|
|
7
18
|
export * from "./domain/AlterHook";
|
|
8
19
|
export * from "./domain/Formio";
|
|
9
|
-
export * from "./domain/FormioDecodedToken";
|
|
10
20
|
export * from "./domain/FormioAction";
|
|
11
21
|
export * from "./domain/FormioActionsIndex";
|
|
12
22
|
export * from "./domain/FormioAuth";
|
|
13
23
|
export * from "./domain/FormioBaseModel";
|
|
14
24
|
export * from "./domain/FormioConfig";
|
|
15
25
|
export * from "./domain/FormioCtxMapper";
|
|
26
|
+
export * from "./domain/FormioDecodedToken";
|
|
16
27
|
export * from "./domain/FormioErrors";
|
|
17
28
|
export * from "./domain/FormioHooks";
|
|
18
29
|
export * from "./domain/FormioJs";
|
|
19
30
|
export * from "./domain/FormioModels";
|
|
20
31
|
export * from "./domain/FormioRouter";
|
|
21
32
|
export * from "./domain/FormioSettings";
|
|
22
|
-
export * from "./domain/FormioUpdate";
|
|
23
|
-
export * from "./domain/FormioUtils";
|
|
24
33
|
export * from "./domain/FormioTemplate";
|
|
25
34
|
export * from "./domain/FormioTemplateUtil";
|
|
35
|
+
export * from "./domain/FormioUpdate";
|
|
36
|
+
export * from "./domain/FormioUtils";
|
|
26
37
|
export * from "./domain/OnHook";
|
|
27
|
-
export * from "./
|
|
28
|
-
export * from "./
|
|
29
|
-
export * from "./services/FormioService";
|
|
30
|
-
export * from "./services/FormioDatabase";
|
|
31
|
-
export * from "./services/FormioDatabase";
|
|
38
|
+
export * from "./domain/Resource";
|
|
39
|
+
export * from "./middlewares/FormioAuthMiddleware";
|
|
32
40
|
export * from "./services/FormioAuthService";
|
|
41
|
+
export * from "./services/FormioDatabase";
|
|
33
42
|
export * from "./services/FormioHooksService";
|
|
34
|
-
export * from "./
|
|
35
|
-
export * from "./
|
|
36
|
-
export * from "./
|
|
37
|
-
export * from "./
|
|
38
|
-
export * from "./components/AlterSkip";
|
|
43
|
+
export * from "./services/FormioInstaller";
|
|
44
|
+
export * from "./services/FormioRepository";
|
|
45
|
+
export * from "./services/FormioService";
|
|
46
|
+
export * from "./utils/isMongoId";
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/// <reference types="mongoose/types/pipelinestage" />
|
|
2
|
+
/// <reference types="mongoose/types/connection" />
|
|
3
|
+
/// <reference types="mongoose/types/cursor" />
|
|
4
|
+
/// <reference types="mongoose/types/document" />
|
|
5
|
+
/// <reference types="mongoose/types/error" />
|
|
6
|
+
/// <reference types="mongoose/types/mongooseoptions" />
|
|
7
|
+
/// <reference types="mongoose/types/schemaoptions" />
|
|
1
8
|
/// <reference types="mongoose" />
|
|
2
9
|
import { PlatformContext, Req } from "@tsed/common";
|
|
3
10
|
import { FormioPayloadToken } from "../domain/FormioDecodedToken";
|
|
@@ -33,19 +40,23 @@ export declare class FormioAuthService {
|
|
|
33
40
|
* Retrieve roles
|
|
34
41
|
* @param req
|
|
35
42
|
*/
|
|
36
|
-
getRoles(req?: Req): Promise<import("mongoose").LeanDocument<import("@tsed/mongoose").MongooseMergedDocument<import("mongoose").Document<any,
|
|
43
|
+
getRoles(req?: Req): Promise<import("mongoose").LeanDocument<import("@tsed/mongoose").MongooseMergedDocument<import("mongoose").Document<any, any, any> & import("@tsed/formio-types/lib/types/domain/FormioRole").FormioRole & import("@tsed/mongoose").MongooseDocumentMethods<import("@tsed/formio-types/lib/types/domain/FormioRole").FormioRole>> & {
|
|
44
|
+
_id: any;
|
|
45
|
+
}>[]>;
|
|
37
46
|
/**
|
|
38
47
|
* Update the role of the current user submission
|
|
39
48
|
* @param _id
|
|
40
49
|
* @param role
|
|
41
50
|
* @param req
|
|
42
51
|
*/
|
|
43
|
-
updateUserRole(_id: string | any, role: string, req?: Req): Promise<import("@tsed/mongoose").MongooseMergedDocument<import("mongoose").Document<any,
|
|
52
|
+
updateUserRole(_id: string | any, role: string, req?: Req): Promise<import("@tsed/mongoose").MongooseMergedDocument<import("mongoose").Document<any, any, any> & FormioSubmission<any> & import("@tsed/mongoose").MongooseDocumentMethods<FormioSubmission<any>>> & {
|
|
53
|
+
_id: any;
|
|
54
|
+
}>;
|
|
44
55
|
/**
|
|
45
56
|
* Create a user submission in formio
|
|
46
57
|
* @param user
|
|
47
58
|
*/
|
|
48
|
-
createUser<User = any>(user: Partial<FormioSubmission<User>>): Promise<import("mongoose").LeanDocument<import("mongoose").Document<any,
|
|
59
|
+
createUser<User = any>(user: Partial<FormioSubmission<User>>): Promise<import("mongoose").LeanDocument<import("mongoose").Document<any, any, any> & FormioSubmission<any> & import("@tsed/mongoose").MongooseDocumentMethods<FormioSubmission<any>>>>;
|
|
49
60
|
/**
|
|
50
61
|
* Update user submission in formio
|
|
51
62
|
* @param user
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
/// <reference types="mongoose" />
|
|
2
|
-
|
|
1
|
+
/// <reference types="mongoose/types/pipelinestage" />
|
|
2
|
+
/// <reference types="mongoose/types/connection" />
|
|
3
|
+
/// <reference types="mongoose/types/cursor" />
|
|
4
|
+
/// <reference types="mongoose/types/document" />
|
|
5
|
+
/// <reference types="mongoose/types/error" />
|
|
6
|
+
/// <reference types="mongoose/types/mongooseoptions" />
|
|
7
|
+
/// <reference types="mongoose/types/schemaoptions" />
|
|
8
|
+
import { MongooseDocument, MongooseModel } from "@tsed/mongoose";
|
|
9
|
+
import type { FilterQuery } from "mongoose";
|
|
3
10
|
import { FormioAction, FormioActionItem, FormioForm, FormioRole, FormioSubmission, FormioToken } from "@tsed/formio-types";
|
|
4
11
|
import { FormioMapper } from "../builder/FormioMapper";
|
|
5
12
|
import { FormioService } from "./FormioService";
|
|
6
13
|
export declare class FormioDatabase {
|
|
7
14
|
protected formio: FormioService;
|
|
8
|
-
get models():
|
|
9
|
-
[index: string]: import("mongoose").Model<any, {}>;
|
|
10
|
-
};
|
|
15
|
+
get models(): import("mongoose").Models;
|
|
11
16
|
get roleModel(): MongooseModel<FormioRole>;
|
|
12
17
|
get formModel(): MongooseModel<FormioForm>;
|
|
13
18
|
get actionModel(): MongooseModel<FormioAction>;
|
|
@@ -17,8 +22,42 @@ export declare class FormioDatabase {
|
|
|
17
22
|
getFormioMapper(): Promise<FormioMapper>;
|
|
18
23
|
hasForms(): Promise<boolean>;
|
|
19
24
|
hasForm(name: string): Promise<boolean>;
|
|
20
|
-
getForm(nameOrId: string): Promise<import("mongoose").LeanDocument<import("@tsed/mongoose").MongooseMergedDocument<import("mongoose").Document<any,
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
getForm(nameOrId: string): Promise<import("mongoose").LeanDocument<import("@tsed/mongoose").MongooseMergedDocument<import("mongoose").Document<any, any, any> & FormioForm & import("@tsed/mongoose").MongooseDocumentMethods<FormioForm>> & {
|
|
26
|
+
_id: any;
|
|
27
|
+
}> | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Import form previously exported by export tool.
|
|
30
|
+
* This method transform alias to a real mongoose _id
|
|
31
|
+
* @param form
|
|
32
|
+
* @param onCreate
|
|
33
|
+
*/
|
|
34
|
+
importFormIfNotExists(form: FormioForm, onCreate?: (form: FormioForm) => any): Promise<import("mongoose").LeanDocument<import("@tsed/mongoose").MongooseMergedDocument<import("mongoose").Document<any, any, any> & FormioForm & import("@tsed/mongoose").MongooseDocumentMethods<FormioForm>> & {
|
|
35
|
+
_id: any;
|
|
36
|
+
}> | null>;
|
|
37
|
+
/**
|
|
38
|
+
* Import form previously exported by export tool.
|
|
39
|
+
* This method transform alias to a real mongoose _id
|
|
40
|
+
* @param form
|
|
41
|
+
*/
|
|
42
|
+
importForm(form: FormioForm): Promise<import("@tsed/mongoose").MongooseMergedDocument<import("mongoose").Document<any, any, any> & FormioForm & import("@tsed/mongoose").MongooseDocumentMethods<FormioForm>> & {
|
|
43
|
+
_id: any;
|
|
44
|
+
}>;
|
|
45
|
+
saveForm(form: FormioForm): Promise<import("@tsed/mongoose").MongooseMergedDocument<import("mongoose").Document<any, any, any> & FormioForm & import("@tsed/mongoose").MongooseDocumentMethods<FormioForm>> & {
|
|
46
|
+
_id: any;
|
|
47
|
+
}>;
|
|
48
|
+
getSubmissions<Data>(query?: FilterQuery<MongooseModel<FormioSubmission<Data>>>): Promise<MongooseDocument<FormioSubmission<Data>>[]>;
|
|
49
|
+
/**
|
|
50
|
+
* Import submission previously exported by export tool.
|
|
51
|
+
* This method transform alias to a real mongoose _id
|
|
52
|
+
* @param submission
|
|
53
|
+
*/
|
|
54
|
+
importSubmission<Data = any>(submission: Omit<Partial<FormioSubmission<Data>>, "form"> & {
|
|
55
|
+
form?: any;
|
|
56
|
+
}): Promise<import("@tsed/mongoose").MongooseMergedDocument<import("mongoose").Document<any, any, any> & FormioSubmission<any> & import("@tsed/mongoose").MongooseDocumentMethods<FormioSubmission<any>>> & {
|
|
57
|
+
_id: any;
|
|
58
|
+
}>;
|
|
59
|
+
saveSubmission<Data = any>(submission: Partial<FormioSubmission<Data>>): Promise<import("@tsed/mongoose").MongooseMergedDocument<import("mongoose").Document<any, any, any> & FormioSubmission<any> & import("@tsed/mongoose").MongooseDocumentMethods<FormioSubmission<any>>> & {
|
|
60
|
+
_id: any;
|
|
61
|
+
}>;
|
|
23
62
|
idToBson(form?: any): any;
|
|
24
63
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="mongoose/types/pipelinestage" />
|
|
2
|
+
/// <reference types="mongoose/types/connection" />
|
|
3
|
+
/// <reference types="mongoose/types/cursor" />
|
|
4
|
+
/// <reference types="mongoose/types/document" />
|
|
5
|
+
/// <reference types="mongoose/types/error" />
|
|
6
|
+
/// <reference types="mongoose/types/mongooseoptions" />
|
|
7
|
+
/// <reference types="mongoose/types/schemaoptions" />
|
|
8
|
+
import type { FilterQuery } from "mongoose";
|
|
9
|
+
import { MongooseDocument, MongooseModel } from "@tsed/mongoose";
|
|
10
|
+
import { FormioSubmission } from "../domain/FormioModels";
|
|
11
|
+
import { FormioDatabase } from "./FormioDatabase";
|
|
12
|
+
export declare abstract class FormioRepository<SubmissionData = any> {
|
|
13
|
+
protected formioDatabase: FormioDatabase;
|
|
14
|
+
protected abstract formName: string;
|
|
15
|
+
private formId;
|
|
16
|
+
getFormId(): Promise<string>;
|
|
17
|
+
saveSubmission(submission: Omit<Partial<FormioSubmission<SubmissionData>>, "form"> & {
|
|
18
|
+
form?: any;
|
|
19
|
+
}): Promise<import("@tsed/mongoose").MongooseMergedDocument<import("mongoose").Document<any, any, any> & FormioSubmission<any> & import("@tsed/mongoose").MongooseDocumentMethods<FormioSubmission<any>>> & {
|
|
20
|
+
_id: any;
|
|
21
|
+
}>;
|
|
22
|
+
getSubmissions(query?: FilterQuery<MongooseModel<FormioSubmission<SubmissionData>>>): Promise<MongooseDocument<FormioSubmission<SubmissionData>>[]>;
|
|
23
|
+
findOneSubmission(query: any): Promise<MongooseDocument<FormioSubmission<SubmissionData>> | undefined>;
|
|
24
|
+
}
|