@tsed/formio 8.11.0 → 8.11.2-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/lib/esm/FormioModule.js +0 -1
  2. package/lib/esm/builder/FormioMapper.js +0 -1
  3. package/lib/esm/components/AlterActions.js +0 -1
  4. package/lib/esm/components/AlterAudit.js +0 -1
  5. package/lib/esm/components/AlterHost.js +0 -1
  6. package/lib/esm/components/AlterLog.js +0 -1
  7. package/lib/esm/components/AlterSkip.js +0 -1
  8. package/lib/esm/components/AlterTemplateExportSteps.js +0 -1
  9. package/lib/esm/components/AlterTemplateImportSteps.js +0 -1
  10. package/lib/esm/decorators/action.js +0 -1
  11. package/lib/esm/decorators/actionCtx.js +0 -1
  12. package/lib/esm/decorators/alter.js +0 -1
  13. package/lib/esm/decorators/on.js +0 -1
  14. package/lib/esm/decorators/useFormioAuth.js +0 -1
  15. package/lib/esm/domain/AlterHook.js +0 -1
  16. package/lib/esm/domain/Formio.js +0 -1
  17. package/lib/esm/domain/FormioAction.js +0 -1
  18. package/lib/esm/domain/FormioActionsIndex.js +0 -1
  19. package/lib/esm/domain/FormioAuth.js +0 -1
  20. package/lib/esm/domain/FormioBaseModel.js +0 -1
  21. package/lib/esm/domain/FormioConfig.js +0 -1
  22. package/lib/esm/domain/FormioCtxMapper.js +0 -1
  23. package/lib/esm/domain/FormioDecodedToken.js +0 -1
  24. package/lib/esm/domain/FormioErrors.js +0 -1
  25. package/lib/esm/domain/FormioHooks.js +0 -1
  26. package/lib/esm/domain/FormioJs.js +0 -1
  27. package/lib/esm/domain/FormioModels.js +0 -1
  28. package/lib/esm/domain/FormioRouter.js +0 -1
  29. package/lib/esm/domain/FormioSettings.js +0 -1
  30. package/lib/esm/domain/FormioTemplate.js +0 -1
  31. package/lib/esm/domain/FormioTemplateUtil.js +0 -1
  32. package/lib/esm/domain/FormioUpdate.js +0 -1
  33. package/lib/esm/domain/FormioUtils.js +0 -1
  34. package/lib/esm/domain/OnHook.js +0 -1
  35. package/lib/esm/domain/Resource.js +0 -1
  36. package/lib/esm/index.js +0 -1
  37. package/lib/esm/middlewares/FormioAuthMiddleware.js +0 -1
  38. package/lib/esm/services/FormioAuthService.js +0 -1
  39. package/lib/esm/services/FormioDatabase.js +0 -1
  40. package/lib/esm/services/FormioHooksService.js +0 -1
  41. package/lib/esm/services/FormioInstaller.js +0 -1
  42. package/lib/esm/services/FormioRepository.js +0 -1
  43. package/lib/esm/services/FormioService.js +0 -1
  44. package/lib/esm/utils/isMongoId.js +0 -1
  45. package/package.json +13 -10
  46. package/lib/esm/FormioModule.js.map +0 -1
  47. package/lib/esm/builder/FormioMapper.js.map +0 -1
  48. package/lib/esm/components/AlterActions.js.map +0 -1
  49. package/lib/esm/components/AlterAudit.js.map +0 -1
  50. package/lib/esm/components/AlterHost.js.map +0 -1
  51. package/lib/esm/components/AlterLog.js.map +0 -1
  52. package/lib/esm/components/AlterSkip.js.map +0 -1
  53. package/lib/esm/components/AlterTemplateExportSteps.js.map +0 -1
  54. package/lib/esm/components/AlterTemplateImportSteps.js.map +0 -1
  55. package/lib/esm/decorators/action.js.map +0 -1
  56. package/lib/esm/decorators/actionCtx.js.map +0 -1
  57. package/lib/esm/decorators/alter.js.map +0 -1
  58. package/lib/esm/decorators/on.js.map +0 -1
  59. package/lib/esm/decorators/useFormioAuth.js.map +0 -1
  60. package/lib/esm/domain/AlterHook.js.map +0 -1
  61. package/lib/esm/domain/Formio.js.map +0 -1
  62. package/lib/esm/domain/FormioAction.js.map +0 -1
  63. package/lib/esm/domain/FormioActionsIndex.js.map +0 -1
  64. package/lib/esm/domain/FormioAuth.js.map +0 -1
  65. package/lib/esm/domain/FormioBaseModel.js.map +0 -1
  66. package/lib/esm/domain/FormioConfig.js.map +0 -1
  67. package/lib/esm/domain/FormioCtxMapper.js.map +0 -1
  68. package/lib/esm/domain/FormioDecodedToken.js.map +0 -1
  69. package/lib/esm/domain/FormioErrors.js.map +0 -1
  70. package/lib/esm/domain/FormioHooks.js.map +0 -1
  71. package/lib/esm/domain/FormioJs.js.map +0 -1
  72. package/lib/esm/domain/FormioModels.js.map +0 -1
  73. package/lib/esm/domain/FormioRouter.js.map +0 -1
  74. package/lib/esm/domain/FormioSettings.js.map +0 -1
  75. package/lib/esm/domain/FormioTemplate.js.map +0 -1
  76. package/lib/esm/domain/FormioTemplateUtil.js.map +0 -1
  77. package/lib/esm/domain/FormioUpdate.js.map +0 -1
  78. package/lib/esm/domain/FormioUtils.js.map +0 -1
  79. package/lib/esm/domain/OnHook.js.map +0 -1
  80. package/lib/esm/domain/Resource.js.map +0 -1
  81. package/lib/esm/index.js.map +0 -1
  82. package/lib/esm/middlewares/FormioAuthMiddleware.js.map +0 -1
  83. package/lib/esm/services/FormioAuthService.js.map +0 -1
  84. package/lib/esm/services/FormioDatabase.js.map +0 -1
  85. package/lib/esm/services/FormioHooksService.js.map +0 -1
  86. package/lib/esm/services/FormioInstaller.js.map +0 -1
  87. package/lib/esm/services/FormioRepository.js.map +0 -1
  88. package/lib/esm/services/FormioService.js.map +0 -1
  89. package/lib/esm/utils/isMongoId.js.map +0 -1
  90. package/src/FormioModule.spec.ts +0 -113
  91. package/src/FormioModule.ts +0 -130
  92. package/src/builder/FormioMapper.spec.ts +0 -93
  93. package/src/builder/FormioMapper.ts +0 -71
  94. package/src/components/AlterActions.spec.ts +0 -376
  95. package/src/components/AlterActions.ts +0 -136
  96. package/src/components/AlterAudit.spec.ts +0 -19
  97. package/src/components/AlterAudit.ts +0 -12
  98. package/src/components/AlterHost.spec.ts +0 -20
  99. package/src/components/AlterHost.ts +0 -11
  100. package/src/components/AlterLog.spec.ts +0 -19
  101. package/src/components/AlterLog.ts +0 -12
  102. package/src/components/AlterSkip.spec.ts +0 -44
  103. package/src/components/AlterSkip.ts +0 -28
  104. package/src/components/AlterTemplateExportSteps.spec.ts +0 -99
  105. package/src/components/AlterTemplateExportSteps.ts +0 -58
  106. package/src/components/AlterTemplateImportSteps.spec.ts +0 -70
  107. package/src/components/AlterTemplateImportSteps.ts +0 -50
  108. package/src/decorators/action.ts +0 -20
  109. package/src/decorators/actionCtx.spec.ts +0 -25
  110. package/src/decorators/actionCtx.ts +0 -29
  111. package/src/decorators/alter.spec.ts +0 -16
  112. package/src/decorators/alter.ts +0 -19
  113. package/src/decorators/on.spec.ts +0 -16
  114. package/src/decorators/on.ts +0 -19
  115. package/src/decorators/useFormioAuth.spec.ts +0 -15
  116. package/src/decorators/useFormioAuth.ts +0 -12
  117. package/src/domain/AlterHook.ts +0 -3
  118. package/src/domain/Formio.ts +0 -122
  119. package/src/domain/FormioAction.ts +0 -30
  120. package/src/domain/FormioActionsIndex.ts +0 -19
  121. package/src/domain/FormioAuth.ts +0 -83
  122. package/src/domain/FormioBaseModel.ts +0 -14
  123. package/src/domain/FormioConfig.ts +0 -63
  124. package/src/domain/FormioCtxMapper.ts +0 -8
  125. package/src/domain/FormioDecodedToken.ts +0 -13
  126. package/src/domain/FormioErrors.ts +0 -53
  127. package/src/domain/FormioHooks.ts +0 -207
  128. package/src/domain/FormioJs.ts +0 -18
  129. package/src/domain/FormioModels.ts +0 -48
  130. package/src/domain/FormioRouter.ts +0 -10
  131. package/src/domain/FormioSettings.ts +0 -61
  132. package/src/domain/FormioTemplate.ts +0 -9
  133. package/src/domain/FormioTemplateUtil.ts +0 -15
  134. package/src/domain/FormioUpdate.ts +0 -23
  135. package/src/domain/FormioUtils.ts +0 -331
  136. package/src/domain/OnHook.ts +0 -3
  137. package/src/domain/Resource.ts +0 -21
  138. package/src/index.ts +0 -46
  139. package/src/middlewares/FormioAuthMiddleware.spec.ts +0 -61
  140. package/src/middlewares/FormioAuthMiddleware.ts +0 -34
  141. package/src/services/FormioAuthService.spec.ts +0 -396
  142. package/src/services/FormioAuthService.ts +0 -228
  143. package/src/services/FormioDatabase.spec.ts +0 -326
  144. package/src/services/FormioDatabase.ts +0 -165
  145. package/src/services/FormioHooksService.spec.ts +0 -156
  146. package/src/services/FormioHooksService.ts +0 -92
  147. package/src/services/FormioInstaller.spec.ts +0 -146
  148. package/src/services/FormioInstaller.ts +0 -46
  149. package/src/services/FormioRepository.spec.ts +0 -114
  150. package/src/services/FormioRepository.ts +0 -49
  151. package/src/services/FormioService.spec.ts +0 -368
  152. package/src/services/FormioService.ts +0 -134
  153. package/src/utils/isMongoId.ts +0 -3
  154. package/vitest.config.mts +0 -21
@@ -1,331 +0,0 @@
1
- import {Request, Response} from "express";
2
-
3
- import {FormioErrors} from "./FormioErrors.js";
4
- import {FormioJs} from "./FormioJs.js";
5
-
6
- export interface FormioUtil {
7
- Formio: FormioJs;
8
- /**
9
- * Iterate through each component within a form.
10
- *
11
- * @param {Object} components
12
- * The components to iterate.
13
- * @param {Function} fn
14
- * The iteration function to invoke for each component.
15
- * @param {Boolean} includeAll
16
- * Whether or not to include layout components.
17
- * @param {String} path
18
- */
19
- eachComponent: Function;
20
- /**
21
- * Get a component by its key
22
- *
23
- * @param {Object} components
24
- * The components to iterate.
25
- * @param {String} key
26
- * The key of the component to get.
27
- *
28
- * @returns {Object}
29
- * The component that matches the given key, or undefined if not found.
30
- */
31
- getComponent: Function;
32
- /**
33
- * Define if component should be considered input component
34
- *
35
- * @param {Object} componentJson
36
- * JSON of component to check
37
- *
38
- * @returns {Boolean}
39
- * If component is input or not
40
- */
41
- isInputComponent: Function;
42
- /**
43
- * Flatten the form components for data manipulation.
44
- *
45
- * @param {Object} components
46
- * The components to iterate.
47
- * @param {Boolean} includeAll
48
- * Whether or not to include layout components.
49
- *
50
- * @returns {Object}
51
- * The flattened components map.
52
- */
53
- flattenComponents: Function;
54
- /**
55
- * Get the value for a component key, in the given submission.
56
- *
57
- * @param {Object} submission
58
- * A submission object to search.
59
- * @param {String} key
60
- * A for components API key to search for.
61
- */
62
- getValue: Function;
63
- /**
64
- * Determine if a component is a layout component or not.
65
- *
66
- * @param {Object} component
67
- * The component to check.
68
- *
69
- * @returns {Boolean}
70
- * Whether or not the component is a layout component.
71
- */
72
- isLayoutComponent: Function;
73
- /**
74
- * Apply JSON logic functionality.
75
- *
76
- * @param component
77
- * @param row
78
- * @param data
79
- */
80
- jsonLogic: Function;
81
- /**
82
- * Check if the condition for a component is true or not.
83
- *
84
- * @param component
85
- * @param row
86
- * @param data
87
- */
88
- checkCondition: Function;
89
- flattenComponentsForRender: Function;
90
- renderFormSubmission: Function;
91
- renderComponentValue: Function;
92
- /**
93
- * A node-fetch shim adding support for http(s) proxy and allowing
94
- * invalid tls certificates (to be used with self signed certificates).
95
- *
96
- * @param {any} url The request url string or url like object.
97
- * @param {any} options The request options object.
98
- * @returns {Promise<Response>} The promise with the node-fetch response object.
99
- */
100
- fetch: any;
101
-
102
- base64: {
103
- /**
104
- * Base64 encode the given data.
105
- *
106
- * @param {String} decoded
107
- * The decoded data to encode.
108
- *
109
- * @return {String}
110
- * The base64 representation of the given data.
111
- */
112
- encode(decoded: string): string;
113
- /**
114
- * Base64 decode the given data.
115
- *
116
- * @param {String} encoded
117
- * The encoded data to decode.
118
- *
119
- * @return {String}
120
- * The ascii representation of the given encoded data.
121
- */
122
- decode(encoded: string): string;
123
- };
124
- /**
125
- * Application error codes.
126
- */
127
- errorCodes: FormioErrors;
128
-
129
- layoutComponents: ("panel" | "table" | "well" | "columns" | "fieldset" | "tabs" | string)[];
130
-
131
- deleteProp(target: any, propertyKey: any): any;
132
-
133
- /**
134
- * A wrapper around console.log that gets ignored by eslint.
135
- *
136
- * @param {*} content
137
- * The content to pass to console.log.
138
- */
139
- log(content: string): void;
140
-
141
- /**
142
- * Determine if a value is a boolean representation.
143
- * @param value
144
- * @return {boolean}
145
- */
146
- isBoolean(value: any): boolean;
147
-
148
- /**
149
- * Quick boolean coercer.
150
- * @param value
151
- * @return {boolean}
152
- */
153
- boolean(value: any): boolean;
154
-
155
- /**
156
- * A wrapper around console.error that gets ignored by eslint.
157
- *
158
- * @param {*} content
159
- * The content to pass to console.error.
160
- */
161
- error(content: any): void;
162
-
163
- /**
164
- * Returns the URL alias for a form provided the url.
165
- */
166
- getAlias(req: Request, reservedForms: string[]): {alias: string; additional: string};
167
-
168
- /**
169
- * Escape a string for use in regex.
170
- *
171
- * @param str
172
- * @returns {*}
173
- */
174
- escapeRegExp(str: string): string;
175
-
176
- /**
177
- * Create a sub response object that only handles errors.
178
- *
179
- * @param res
180
- * @return {{send: function(), sendStatus: function(*=), status: function(*=)}}
181
- */
182
- createSubResponse(res: Response): Response;
183
-
184
- /**
185
- * Create a sub-request object from the original request.
186
- *
187
- * @param req
188
- */
189
- createSubRequest(req: Request): Request;
190
-
191
- /**
192
- * Return the objectId.
193
- *
194
- * @param id
195
- * @returns {*}
196
- * @constructor
197
- */
198
- ObjectId(id: string): any;
199
-
200
- /**
201
- * Search the request headers for the given key.
202
- *
203
- * @param req
204
- * The Express request object.
205
- * @param key
206
- * The key to search for in the headers.
207
- *
208
- * @return
209
- * The header value if found or false.
210
- */
211
- getHeader(req: Request, key: string): string | false;
212
-
213
- /**
214
- * Search the request query for the given key.
215
- *
216
- * @param req
217
- * The Express request object.
218
- * @param key
219
- * The key to search for in the query.
220
- *
221
- * @return
222
- * The query value if found or false.
223
- */
224
- getQuery(req: Request, key: string): any | false;
225
-
226
- /**
227
- * Search the request parameters for the given key.
228
- *
229
- * @param req
230
- * The Express request object.
231
- * @param key
232
- * The key to search for in the parameters.
233
- *
234
- * @return
235
- * The parameter value if found or false.
236
- */
237
- getParameter(req: Request, key: string): any | false;
238
-
239
- /**
240
- * Determine if the request has the given key set as a header or url parameter.
241
- *
242
- * @param req
243
- * The Express request object.
244
- * @param key
245
- * The key to search for.
246
- *
247
- * @return
248
- * Return the value of the key or false if not found.
249
- */
250
- getRequestValue(req: Request, key: string): any | false;
251
-
252
- /**
253
- * Split the given URL into its key/value pairs.
254
- *
255
- * @param url
256
- * The request url to split, typically req.url.
257
- *
258
- * @returns {{}}
259
- * The key/value pairs of the request url.
260
- */
261
- getUrlParams(url: string): Record<string, any>;
262
-
263
- /**
264
- * Converts a form component key into a submission key
265
- * by putting .data. between each nested component
266
- * (ex: `user.name` becomes `user.data.name` in a submission)
267
- * @param key
268
- * The key to convert
269
- * @return
270
- * The submission key
271
- */
272
- getSubmissionKey(key: string): string;
273
-
274
- /**
275
- * Converts a submission key into a form component key
276
- * by replacing .data. with .
277
- * (ex: `user.data.name` becomes `user.name` in a submission)
278
- * @param key
279
- * The key to convert
280
- * @return
281
- * The form component key
282
- */
283
- getFormComponentKey(key: string): string;
284
-
285
- /**
286
- * Utility function to ensure the given id is always a BSON object.
287
- *
288
- * @param _id {String|Object}
289
- * A mongo id as a string or object.
290
- *
291
- * @returns {Object}
292
- * The mongo BSON id.
293
- */
294
- idToBson(_id: string | any): any;
295
-
296
- /**
297
- * Utility function to ensure the given id is always a string object.
298
- *
299
- * @param _id {String|Object}
300
- * A mongo id as a string or object.
301
- *
302
- * @returns {String}
303
- * The mongo string id.
304
- */
305
- idToString(_id: string | any): string;
306
-
307
- /**
308
- * Ensures that a submission data has MongoDB ObjectID's for all "id" fields.
309
- * @param data
310
- * @return {boolean}
311
- */
312
- ensureIds(data: any[]): any;
313
-
314
- removeProtectedFields(form: string, action: string, submissions: any): void;
315
-
316
- /**
317
- * Retrieve a unique machine name
318
- *
319
- * @param document
320
- * @param model
321
- * @param next
322
- * @return {*}
323
- */
324
- uniqueMachineName(document: {machineName: string}, model: any, next: (err?: Error) => void): void;
325
-
326
- castValue<T = any>(valueType: "string" | "number" | "boolean" | "[number]" | "[string]", value: any): T;
327
-
328
- valuePath(prefix: string, key: string): string;
329
-
330
- eachValue(components: any, data: any, fn: Function, context: any, path?: string): void;
331
- }
@@ -1,3 +0,0 @@
1
- export interface OnHook<T = any> {
2
- on(...args: any[]): boolean | void;
3
- }
@@ -1,21 +0,0 @@
1
- import {NextFunction, Request, Response} from "express";
2
-
3
- export type ResourceHttpHandler = (req: Request, res: Response, next: NextFunction) => void;
4
-
5
- export interface ResourceHttpMethodOptions {
6
- before?: ResourceHttpHandler;
7
- after?: ResourceHttpHandler;
8
- }
9
-
10
- export interface ResourceRestOptions extends ResourceHttpMethodOptions {
11
- beforePut?: ResourceHttpHandler;
12
- beforePatch?: ResourceHttpHandler;
13
- beforePost?: ResourceHttpHandler;
14
- beforeIndex?: ResourceHttpHandler;
15
- beforeGet?: ResourceHttpHandler;
16
- afterPut?: ResourceHttpHandler;
17
- afterPatch?: ResourceHttpHandler;
18
- afterPost?: ResourceHttpHandler;
19
- afterIndex?: ResourceHttpHandler;
20
- afterGet?: ResourceHttpHandler;
21
- }
package/src/index.ts DELETED
@@ -1,46 +0,0 @@
1
- /**
2
- * @file Automatically generated by @tsed/barrels.
3
- */
4
- export * from "./builder/FormioMapper.js";
5
- export * from "./components/AlterActions.js";
6
- export * from "./components/AlterAudit.js";
7
- export * from "./components/AlterHost.js";
8
- export * from "./components/AlterLog.js";
9
- export * from "./components/AlterSkip.js";
10
- export * from "./components/AlterTemplateExportSteps.js";
11
- export * from "./components/AlterTemplateImportSteps.js";
12
- export * from "./decorators/action.js";
13
- export * from "./decorators/actionCtx.js";
14
- export * from "./decorators/alter.js";
15
- export * from "./decorators/on.js";
16
- export * from "./decorators/useFormioAuth.js";
17
- export * from "./domain/AlterHook.js";
18
- export * from "./domain/Formio.js";
19
- export * from "./domain/FormioAction.js";
20
- export * from "./domain/FormioActionsIndex.js";
21
- export * from "./domain/FormioAuth.js";
22
- export * from "./domain/FormioBaseModel.js";
23
- export * from "./domain/FormioConfig.js";
24
- export * from "./domain/FormioCtxMapper.js";
25
- export * from "./domain/FormioDecodedToken.js";
26
- export * from "./domain/FormioErrors.js";
27
- export * from "./domain/FormioHooks.js";
28
- export * from "./domain/FormioJs.js";
29
- export * from "./domain/FormioModels.js";
30
- export * from "./domain/FormioRouter.js";
31
- export * from "./domain/FormioSettings.js";
32
- export * from "./domain/FormioTemplate.js";
33
- export * from "./domain/FormioTemplateUtil.js";
34
- export * from "./domain/FormioUpdate.js";
35
- export * from "./domain/FormioUtils.js";
36
- export * from "./domain/OnHook.js";
37
- export * from "./domain/Resource.js";
38
- export * from "./FormioModule.js";
39
- export * from "./middlewares/FormioAuthMiddleware.js";
40
- export * from "./services/FormioAuthService.js";
41
- export * from "./services/FormioDatabase.js";
42
- export * from "./services/FormioHooksService.js";
43
- export * from "./services/FormioInstaller.js";
44
- export * from "./services/FormioRepository.js";
45
- export * from "./services/FormioService.js";
46
- export * from "./utils/isMongoId.js";
@@ -1,61 +0,0 @@
1
- import {catchAsyncError} from "@tsed/core";
2
- import {Unauthorized} from "@tsed/exceptions";
3
- import {PlatformTest} from "@tsed/platform-http/testing";
4
-
5
- import {FormioService} from "../services/FormioService.js";
6
- import {FormioAuthMiddleware} from "./FormioAuthMiddleware.js";
7
-
8
- describe("FormioAuthMiddleware", () => {
9
- beforeEach(() => PlatformTest.create());
10
- afterEach(() => PlatformTest.reset());
11
-
12
- it("should authorize user", async () => {
13
- const formio = {
14
- middleware: {
15
- tokenHandler: vi.fn().mockImplementation((request: any, response: any, next: any) => {
16
- request.token = {
17
- user: {
18
- _id: "id"
19
- }
20
- };
21
- next();
22
- })
23
- }
24
- };
25
-
26
- const middleware = await PlatformTest.invoke<FormioAuthMiddleware>(FormioAuthMiddleware, [
27
- {
28
- token: FormioService,
29
- use: formio
30
- }
31
- ]);
32
-
33
- const ctx = PlatformTest.createRequestContext();
34
-
35
- await middleware.use(ctx);
36
-
37
- expect(formio.middleware.tokenHandler).toHaveBeenCalledWith(ctx.getRequest(), ctx.getResponse(), expect.any(Function));
38
- });
39
- it("should throw error", async () => {
40
- const formio = {
41
- middleware: {
42
- tokenHandler: vi.fn().mockImplementation((request: any, response: any, next: any) => {
43
- next();
44
- })
45
- }
46
- };
47
-
48
- const middleware = await PlatformTest.invoke<FormioAuthMiddleware>(FormioAuthMiddleware, [
49
- {
50
- token: FormioService,
51
- use: formio
52
- }
53
- ]);
54
-
55
- const ctx = PlatformTest.createRequestContext();
56
-
57
- const error = await catchAsyncError(() => middleware.use(ctx));
58
-
59
- expect(error).toBeInstanceOf(Unauthorized);
60
- });
61
- });
@@ -1,34 +0,0 @@
1
- import {promisify} from "node:util";
2
-
3
- import {getValue} from "@tsed/core";
4
- import {Inject} from "@tsed/di";
5
- import {Unauthorized} from "@tsed/exceptions";
6
- import {Middleware} from "@tsed/platform-middlewares";
7
- import {Context} from "@tsed/platform-params";
8
-
9
- import {FormioService} from "../services/FormioService.js";
10
-
11
- /**
12
- * @middleware
13
- * @formio
14
- */
15
- @Middleware()
16
- export class FormioAuthMiddleware {
17
- @Inject()
18
- protected formio: FormioService;
19
-
20
- get tokenHandler(): any {
21
- return promisify(this.formio.middleware.tokenHandler);
22
- }
23
-
24
- async use(@Context() ctx: Context) {
25
- const req = ctx.getRequest();
26
- const res = ctx.getResponse();
27
-
28
- await this.tokenHandler(req, res);
29
-
30
- if (!getValue(req, "token.user._id")) {
31
- throw new Unauthorized("User unauthorized");
32
- }
33
- }
34
- }