@flusys/nestjs-form-builder 7.1.0 → 8.0.0

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 (118) hide show
  1. package/config/index.d.ts +3 -3
  2. package/controllers/form-result.controller.d.ts +3 -3
  3. package/controllers/form.controller.d.ts +3 -3
  4. package/controllers/index.d.ts +2 -2
  5. package/docs/form-builder-swagger.config.d.ts +2 -2
  6. package/docs/index.d.ts +1 -1
  7. package/dtos/form.dto.d.ts +1 -1
  8. package/dtos/index.d.ts +2 -2
  9. package/entities/form-with-company.entity.d.ts +1 -1
  10. package/entities/form.entity.d.ts +1 -1
  11. package/entities/index.d.ts +7 -7
  12. package/enums/index.d.ts +1 -1
  13. package/fesm/262.js +1841 -0
  14. package/fesm/98.js +807 -0
  15. package/fesm/config/index.js +98 -3
  16. package/fesm/controllers/index.js +14 -2
  17. package/fesm/docs/index.js +171 -1
  18. package/fesm/dtos/index.js +571 -2
  19. package/fesm/entities/index.js +342 -10
  20. package/fesm/enums/index.js +38 -1
  21. package/fesm/index.js +482 -10
  22. package/fesm/interfaces/index.js +17 -3
  23. package/fesm/modules/index.js +178 -1
  24. package/fesm/runtime.js +85 -0
  25. package/fesm/services/index.js +35 -4
  26. package/index.d.ts +10 -10
  27. package/interfaces/form-builder-module.interface.d.ts +3 -3
  28. package/interfaces/form-result.interface.d.ts +1 -1
  29. package/interfaces/form.interface.d.ts +2 -2
  30. package/interfaces/index.d.ts +3 -3
  31. package/modules/form-builder.module.d.ts +2 -2
  32. package/modules/index.d.ts +1 -1
  33. package/package.json +26 -36
  34. package/services/form-builder-config.service.d.ts +4 -4
  35. package/services/form-builder-datasource.provider.d.ts +3 -3
  36. package/services/form-result.service.d.ts +6 -6
  37. package/services/form.service.d.ts +7 -7
  38. package/services/index.d.ts +4 -4
  39. package/utils/index.d.ts +2 -2
  40. package/utils/permission.utils.d.ts +1 -1
  41. package/cjs/config/event-actions.js +0 -33
  42. package/cjs/config/form-builder.constants.js +0 -13
  43. package/cjs/config/index.js +0 -20
  44. package/cjs/config/message-keys.js +0 -38
  45. package/cjs/controllers/form-result.controller.js +0 -281
  46. package/cjs/controllers/form-result.controller.spec.js +0 -257
  47. package/cjs/controllers/form.controller.js +0 -231
  48. package/cjs/controllers/form.controller.spec.js +0 -212
  49. package/cjs/controllers/index.js +0 -19
  50. package/cjs/docs/form-builder-swagger.config.js +0 -150
  51. package/cjs/docs/form-builder-swagger.config.spec.js +0 -75
  52. package/cjs/docs/index.js +0 -11
  53. package/cjs/dtos/form-result.dto.js +0 -248
  54. package/cjs/dtos/form.dto.js +0 -270
  55. package/cjs/dtos/index.js +0 -19
  56. package/cjs/entities/form-result.entity.js +0 -100
  57. package/cjs/entities/form-with-company.entity.js +0 -65
  58. package/cjs/entities/form.entity.js +0 -127
  59. package/cjs/entities/index.js +0 -52
  60. package/cjs/entities/index.spec.js +0 -18
  61. package/cjs/enums/form-access-type.enum.js +0 -19
  62. package/cjs/enums/index.js +0 -18
  63. package/cjs/index.js +0 -28
  64. package/cjs/interfaces/form-builder-module.interface.js +0 -4
  65. package/cjs/interfaces/form-result.interface.js +0 -4
  66. package/cjs/interfaces/form.interface.js +0 -4
  67. package/cjs/interfaces/index.js +0 -20
  68. package/cjs/modules/form-builder.module.js +0 -136
  69. package/cjs/modules/form-builder.module.spec.js +0 -133
  70. package/cjs/modules/index.js +0 -18
  71. package/cjs/services/form-builder-config.service.js +0 -69
  72. package/cjs/services/form-builder-config.service.spec.js +0 -121
  73. package/cjs/services/form-builder-datasource.provider.js +0 -125
  74. package/cjs/services/form-builder-datasource.provider.spec.js +0 -147
  75. package/cjs/services/form-result.service.js +0 -366
  76. package/cjs/services/form-result.service.spec.js +0 -823
  77. package/cjs/services/form.service.js +0 -341
  78. package/cjs/services/form.service.spec.js +0 -746
  79. package/cjs/services/index.js +0 -21
  80. package/cjs/utils/computed-field.utils.js +0 -199
  81. package/cjs/utils/computed-field.utils.spec.js +0 -1205
  82. package/cjs/utils/index.js +0 -19
  83. package/cjs/utils/permission.utils.js +0 -44
  84. package/cjs/utils/permission.utils.spec.js +0 -118
  85. package/fesm/config/event-actions.js +0 -12
  86. package/fesm/config/form-builder.constants.js +0 -3
  87. package/fesm/config/message-keys.js +0 -20
  88. package/fesm/controllers/form-result.controller.js +0 -271
  89. package/fesm/controllers/form-result.controller.spec.js +0 -253
  90. package/fesm/controllers/form.controller.js +0 -221
  91. package/fesm/controllers/form.controller.spec.js +0 -208
  92. package/fesm/docs/form-builder-swagger.config.js +0 -146
  93. package/fesm/docs/form-builder-swagger.config.spec.js +0 -71
  94. package/fesm/dtos/form-result.dto.js +0 -215
  95. package/fesm/dtos/form.dto.js +0 -243
  96. package/fesm/entities/form-result.entity.js +0 -90
  97. package/fesm/entities/form-with-company.entity.js +0 -55
  98. package/fesm/entities/form.entity.js +0 -117
  99. package/fesm/entities/index.spec.js +0 -14
  100. package/fesm/enums/form-access-type.enum.js +0 -9
  101. package/fesm/interfaces/form-builder-module.interface.js +0 -3
  102. package/fesm/interfaces/form-result.interface.js +0 -6
  103. package/fesm/interfaces/form.interface.js +0 -3
  104. package/fesm/modules/form-builder.module.js +0 -126
  105. package/fesm/modules/form-builder.module.spec.js +0 -129
  106. package/fesm/services/form-builder-config.service.js +0 -59
  107. package/fesm/services/form-builder-config.service.spec.js +0 -117
  108. package/fesm/services/form-builder-datasource.provider.js +0 -74
  109. package/fesm/services/form-builder-datasource.provider.spec.js +0 -143
  110. package/fesm/services/form-result.service.js +0 -356
  111. package/fesm/services/form-result.service.spec.js +0 -778
  112. package/fesm/services/form.service.js +0 -331
  113. package/fesm/services/form.service.spec.js +0 -701
  114. package/fesm/utils/computed-field.utils.js +0 -195
  115. package/fesm/utils/computed-field.utils.spec.js +0 -1201
  116. package/fesm/utils/index.js +0 -2
  117. package/fesm/utils/permission.utils.js +0 -42
  118. package/fesm/utils/permission.utils.spec.js +0 -114
package/fesm/262.js ADDED
@@ -0,0 +1,1841 @@
1
+ import { Identity, getJsonColumnType } from "@flusys/nestjs-shared";
2
+ import { Identity as entities_Identity } from "@flusys/nestjs-shared/entities";
3
+ import * as __rspack_external__flusys_nestjs_shared_classes_6076a329 from "@flusys/nestjs-shared/classes";
4
+ import * as __rspack_external__flusys_nestjs_shared_decorators_c129b601 from "@flusys/nestjs-shared/decorators";
5
+ import * as __rspack_external__flusys_nestjs_shared_dtos_c4585026 from "@flusys/nestjs-shared/dtos";
6
+ import * as __rspack_external__flusys_nestjs_shared_modules_24702bee from "@flusys/nestjs-shared/modules";
7
+ import * as __rspack_external__nestjs_common_a04939da from "@nestjs/common";
8
+ import * as __rspack_external__nestjs_swagger_7cd450b5 from "@nestjs/swagger";
9
+ import * as __rspack_external_class_transformer_c5a479fb from "class-transformer";
10
+ import * as __rspack_external_class_validator_7b99ef4d from "class-validator";
11
+ import * as __rspack_external_typeorm from "typeorm";
12
+ import * as __rspack_external__flusys_nestjs_core_ff4ca4e2 from "@flusys/nestjs-core";
13
+ import * as __rspack_external__flusys_nestjs_shared_utils_9125c1f1 from "@flusys/nestjs-shared/utils";
14
+ import * as __rspack_external__nestjs_core_d7b00a1a from "@nestjs/core";
15
+ export const __rspack_esm_id = 262;
16
+ export const __rspack_esm_ids = [262];
17
+ export const __webpack_modules__ = {
18
+ 769(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
19
+ /**
20
+ * Domain event actions published by the form builder module, alongside the
21
+ * CRUD lifecycle actions every ApiService emits.
22
+ */ const FORM_BUILDER_EVENT_ACTIONS = {
23
+ SUBMITTED: 'submitted',
24
+ DRAFT_SAVED: 'draft-saved'
25
+ };
26
+ /** Every entity the form builder module publishes under */ const FORM_BUILDER_EVENT_ENTITIES = {
27
+ FORM: 'form',
28
+ FORM_RESULT: 'form_result'
29
+ };
30
+ const FORM_BUILDER_EVENT_MODULE = 'form-builder';
31
+
32
+ __webpack_require__.d(__webpack_exports__, {
33
+ }, {
34
+ T$: FORM_BUILDER_EVENT_MODULE,
35
+ eF: FORM_BUILDER_EVENT_ENTITIES,
36
+ ov: FORM_BUILDER_EVENT_ACTIONS
37
+ });
38
+
39
+
40
+ },
41
+ 512(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
42
+ const FORM_BUILDER_MODULE_OPTIONS = 'FORM_BUILDER_MODULE_OPTIONS';
43
+
44
+ __webpack_require__.d(__webpack_exports__, {
45
+ }, {
46
+ v: FORM_BUILDER_MODULE_OPTIONS
47
+ });
48
+
49
+
50
+ },
51
+ 137(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
52
+ // ==================== FORM BUILDER MODULE MESSAGE KEYS ====================
53
+ const FORM_MESSAGES = {
54
+ NOT_FOUND: 'form.not.found',
55
+ NOT_PUBLIC: 'form.not.public',
56
+ AUTH_REQUIRED: 'form.auth.required',
57
+ ACCESS_DENIED: 'form.access.denied',
58
+ INVALID_ACCESS_TYPE: 'form.invalid.access.type',
59
+ PERMISSION_CHECK_FAILED: 'form.permission.check.failed',
60
+ GET_SUCCESS: 'form.get.success',
61
+ GET_ACCESS_INFO_SUCCESS: 'form.get.access.info.success'
62
+ };
63
+ const FORM_RESULT_MESSAGES = {
64
+ GET_ALL_SUCCESS: 'form.result.get.all.success',
65
+ NOT_FOUND: 'form.result.not.found',
66
+ HAS_SUBMITTED_SUCCESS: 'form.result.has.submitted.success',
67
+ HAS_NOT_SUBMITTED_SUCCESS: 'form.result.has.not.submitted.success',
68
+ SUBMIT_SUCCESS: 'form.result.submit.success',
69
+ DRAFT_GET_SUCCESS: 'form.result.draft.get.success',
70
+ DRAFT_UPDATE_SUCCESS: 'form.result.draft.update.success'
71
+ };
72
+
73
+ __webpack_require__.d(__webpack_exports__, {
74
+ }, {
75
+ Q: FORM_MESSAGES,
76
+ y: FORM_RESULT_MESSAGES
77
+ });
78
+
79
+
80
+ },
81
+ 788(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
82
+ /* import */ var _flusys_nestjs_shared_dtos__rspack_import_0 = __webpack_require__(873);
83
+ /* import */ var _nestjs_swagger__rspack_import_1 = __webpack_require__(176);
84
+ /* import */ var class_transformer__rspack_import_2 = __webpack_require__(812);
85
+ /* import */ var class_validator__rspack_import_3 = __webpack_require__(421);
86
+ function _ts_decorate(decorators, target, key, desc) {
87
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
88
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
89
+ r = Reflect.decorate(decorators, target, key, desc);
90
+ } else {
91
+ for(var i = decorators.length - 1; i >= 0; i--){
92
+ if (d = decorators[i]) {
93
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
94
+ }
95
+ }
96
+ }
97
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
98
+ }
99
+ function _ts_metadata(metadataKey, metadataValue) {
100
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
101
+ return Reflect.metadata(metadataKey, metadataValue);
102
+ }
103
+ }
104
+
105
+
106
+
107
+
108
+ class SubmitFormDto {
109
+ formId;
110
+ data;
111
+ isDraft;
112
+ }
113
+ _ts_decorate([
114
+ (0,_nestjs_swagger__rspack_import_1.ApiProperty)({
115
+ description: 'Form ID to submit',
116
+ example: '123e4567-e89b-12d3-a456-426614174000'
117
+ }),
118
+ (0,class_validator__rspack_import_3.IsUUID)(),
119
+ (0,class_validator__rspack_import_3.IsNotEmpty)(),
120
+ _ts_metadata("design:type", String)
121
+ ], SubmitFormDto.prototype, "formId", void 0);
122
+ _ts_decorate([
123
+ (0,_nestjs_swagger__rspack_import_1.ApiProperty)({
124
+ description: 'Submitted form data (field values)',
125
+ example: {
126
+ field1: 'value1',
127
+ field2: 123
128
+ }
129
+ }),
130
+ (0,class_validator__rspack_import_3.IsObject)(),
131
+ (0,class_validator__rspack_import_3.IsNotEmpty)(),
132
+ _ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
133
+ ], SubmitFormDto.prototype, "data", void 0);
134
+ _ts_decorate([
135
+ (0,_nestjs_swagger__rspack_import_1.ApiProperty)({
136
+ description: 'Save as draft instead of final submission',
137
+ default: false,
138
+ required: false
139
+ }),
140
+ (0,class_validator__rspack_import_3.IsBoolean)(),
141
+ (0,class_validator__rspack_import_3.IsOptional)(),
142
+ _ts_metadata("design:type", Boolean)
143
+ ], SubmitFormDto.prototype, "isDraft", void 0);
144
+ class CreateFormResultDto extends SubmitFormDto {
145
+ schemaVersionSnapshot;
146
+ schemaVersion;
147
+ submittedById;
148
+ }
149
+ _ts_decorate([
150
+ (0,_nestjs_swagger__rspack_import_1.ApiProperty)({
151
+ description: 'Schema snapshot at submission time',
152
+ required: false
153
+ }),
154
+ (0,class_validator__rspack_import_3.IsObject)(),
155
+ (0,class_validator__rspack_import_3.IsOptional)(),
156
+ _ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
157
+ ], CreateFormResultDto.prototype, "schemaVersionSnapshot", void 0);
158
+ _ts_decorate([
159
+ (0,_nestjs_swagger__rspack_import_1.ApiProperty)({
160
+ description: 'Schema version at submission time',
161
+ required: false
162
+ }),
163
+ (0,class_validator__rspack_import_3.IsOptional)(),
164
+ _ts_metadata("design:type", Number)
165
+ ], CreateFormResultDto.prototype, "schemaVersion", void 0);
166
+ _ts_decorate([
167
+ (0,_nestjs_swagger__rspack_import_1.ApiProperty)({
168
+ description: 'User who submitted (null for public)',
169
+ required: false
170
+ }),
171
+ (0,class_validator__rspack_import_3.IsUUID)(),
172
+ (0,class_validator__rspack_import_3.IsOptional)(),
173
+ _ts_metadata("design:type", Object)
174
+ ], CreateFormResultDto.prototype, "submittedById", void 0);
175
+ class UpdateFormResultDto extends (0,_nestjs_swagger__rspack_import_1.PartialType)(CreateFormResultDto) {
176
+ id;
177
+ }
178
+ _ts_decorate([
179
+ (0,_nestjs_swagger__rspack_import_1.ApiProperty)({
180
+ description: 'Form Result ID',
181
+ example: '123e4567-e89b-12d3-a456-426614174000'
182
+ }),
183
+ (0,class_validator__rspack_import_3.IsUUID)(),
184
+ (0,class_validator__rspack_import_3.IsNotEmpty)(),
185
+ _ts_metadata("design:type", String)
186
+ ], UpdateFormResultDto.prototype, "id", void 0);
187
+ class GetMyDraftDto {
188
+ formId;
189
+ }
190
+ _ts_decorate([
191
+ (0,_nestjs_swagger__rspack_import_1.ApiProperty)({
192
+ description: 'Form ID to get draft for',
193
+ example: '123e4567-e89b-12d3-a456-426614174000'
194
+ }),
195
+ (0,class_validator__rspack_import_3.IsUUID)(),
196
+ (0,class_validator__rspack_import_3.IsNotEmpty)(),
197
+ _ts_metadata("design:type", String)
198
+ ], GetMyDraftDto.prototype, "formId", void 0);
199
+ class UpdateDraftDto extends SubmitFormDto {
200
+ draftId;
201
+ }
202
+ _ts_decorate([
203
+ (0,_nestjs_swagger__rspack_import_1.ApiProperty)({
204
+ description: 'Draft ID to update',
205
+ example: '123e4567-e89b-12d3-a456-426614174000'
206
+ }),
207
+ (0,class_validator__rspack_import_3.IsUUID)(),
208
+ (0,class_validator__rspack_import_3.IsNotEmpty)(),
209
+ _ts_metadata("design:type", String)
210
+ ], UpdateDraftDto.prototype, "draftId", void 0);
211
+ class GetResultsByFormDto {
212
+ formId;
213
+ page;
214
+ pageSize;
215
+ }
216
+ _ts_decorate([
217
+ (0,_nestjs_swagger__rspack_import_1.ApiProperty)({
218
+ description: 'Form ID to filter results',
219
+ example: '123e4567-e89b-12d3-a456-426614174000'
220
+ }),
221
+ (0,class_validator__rspack_import_3.IsUUID)(),
222
+ (0,class_validator__rspack_import_3.IsNotEmpty)(),
223
+ _ts_metadata("design:type", String)
224
+ ], GetResultsByFormDto.prototype, "formId", void 0);
225
+ _ts_decorate([
226
+ (0,_nestjs_swagger__rspack_import_1.ApiProperty)({
227
+ description: 'Page number (0-based)',
228
+ default: 0,
229
+ required: false
230
+ }),
231
+ (0,class_validator__rspack_import_3.IsInt)(),
232
+ (0,class_validator__rspack_import_3.Min)(0),
233
+ (0,class_validator__rspack_import_3.IsOptional)(),
234
+ _ts_metadata("design:type", Number)
235
+ ], GetResultsByFormDto.prototype, "page", void 0);
236
+ _ts_decorate([
237
+ (0,_nestjs_swagger__rspack_import_1.ApiProperty)({
238
+ description: 'Page size',
239
+ default: 10,
240
+ required: false
241
+ }),
242
+ (0,class_validator__rspack_import_3.IsInt)(),
243
+ (0,class_validator__rspack_import_3.Min)(1),
244
+ (0,class_validator__rspack_import_3.IsOptional)(),
245
+ _ts_metadata("design:type", Number)
246
+ ], GetResultsByFormDto.prototype, "pageSize", void 0);
247
+ class FormResultResponseDto extends _flusys_nestjs_shared_dtos__rspack_import_0.IdentityResponseDto {
248
+ formId;
249
+ schemaVersionSnapshot;
250
+ schemaVersion;
251
+ data;
252
+ submittedById;
253
+ submittedAt;
254
+ isDraft;
255
+ }
256
+ _ts_decorate([
257
+ (0,class_transformer__rspack_import_2.Expose)(),
258
+ (0,_nestjs_swagger__rspack_import_1.ApiProperty)(),
259
+ _ts_metadata("design:type", String)
260
+ ], FormResultResponseDto.prototype, "formId", void 0);
261
+ _ts_decorate([
262
+ (0,class_transformer__rspack_import_2.Expose)(),
263
+ (0,_nestjs_swagger__rspack_import_1.ApiProperty)(),
264
+ _ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
265
+ ], FormResultResponseDto.prototype, "schemaVersionSnapshot", void 0);
266
+ _ts_decorate([
267
+ (0,class_transformer__rspack_import_2.Expose)(),
268
+ (0,_nestjs_swagger__rspack_import_1.ApiProperty)(),
269
+ _ts_metadata("design:type", Number)
270
+ ], FormResultResponseDto.prototype, "schemaVersion", void 0);
271
+ _ts_decorate([
272
+ (0,class_transformer__rspack_import_2.Expose)(),
273
+ (0,_nestjs_swagger__rspack_import_1.ApiProperty)(),
274
+ _ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
275
+ ], FormResultResponseDto.prototype, "data", void 0);
276
+ _ts_decorate([
277
+ (0,class_transformer__rspack_import_2.Expose)(),
278
+ (0,_nestjs_swagger__rspack_import_1.ApiProperty)(),
279
+ _ts_metadata("design:type", Object)
280
+ ], FormResultResponseDto.prototype, "submittedById", void 0);
281
+ _ts_decorate([
282
+ (0,class_transformer__rspack_import_2.Expose)(),
283
+ (0,_nestjs_swagger__rspack_import_1.ApiProperty)(),
284
+ _ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
285
+ ], FormResultResponseDto.prototype, "submittedAt", void 0);
286
+ _ts_decorate([
287
+ (0,class_transformer__rspack_import_2.Expose)(),
288
+ (0,_nestjs_swagger__rspack_import_1.ApiProperty)(),
289
+ _ts_metadata("design:type", Boolean)
290
+ ], FormResultResponseDto.prototype, "isDraft", void 0);
291
+
292
+ __webpack_require__.d(__webpack_exports__, {
293
+ CQ: () => (UpdateDraftDto),
294
+ D5: () => (GetMyDraftDto),
295
+ Uj: () => (UpdateFormResultDto),
296
+ _$: () => (FormResultResponseDto),
297
+ pZ: () => (CreateFormResultDto),
298
+ rp: () => (GetResultsByFormDto),
299
+ sH: () => (SubmitFormDto)
300
+ });
301
+
302
+
303
+ },
304
+ 532(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
305
+
306
+ // EXPORTS
307
+ __webpack_require__.d(__webpack_exports__, {
308
+ lV: () => (/* reexport */ Form),
309
+ C7: () => (/* reexport */ Form),
310
+ Xl: () => (/* binding */ FormCompanyEntities),
311
+ t$: () => (/* binding */ FormCoreEntities),
312
+ ez: () => (/* reexport */ FormResult),
313
+ Wl: () => (/* reexport */ FormWithCompany),
314
+ getFormBuilderEntitiesByConfig: () => (/* binding */ getFormBuilderEntitiesByConfig)
315
+ });
316
+
317
+ ;// CONCATENATED MODULE: external "@flusys/nestjs-shared"
318
+
319
+ ;// CONCATENATED MODULE: external "@flusys/nestjs-shared/entities"
320
+
321
+ // EXTERNAL MODULE: external "typeorm"
322
+ var external_typeorm_ = __webpack_require__(158);
323
+ // EXTERNAL MODULE: ./projects/nestjs-form-builder/src/enums/form-access-type.enum.ts
324
+ var form_access_type_enum = __webpack_require__(376);
325
+ ;// CONCATENATED MODULE: ./projects/nestjs-form-builder/src/entities/form.entity.ts
326
+ function _ts_decorate(decorators, target, key, desc) {
327
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
328
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
329
+ r = Reflect.decorate(decorators, target, key, desc);
330
+ } else {
331
+ for(var i = decorators.length - 1; i >= 0; i--){
332
+ if (d = decorators[i]) {
333
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
334
+ }
335
+ }
336
+ }
337
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
338
+ }
339
+ function _ts_metadata(metadataKey, metadataValue) {
340
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
341
+ return Reflect.metadata(metadataKey, metadataValue);
342
+ }
343
+ }
344
+
345
+
346
+
347
+
348
+ class Form extends entities_Identity {
349
+ name;
350
+ description;
351
+ slug;
352
+ schema;
353
+ schemaVersion;
354
+ accessType;
355
+ actionGroups;
356
+ tags;
357
+ isActive;
358
+ }
359
+ _ts_decorate([
360
+ (0,external_typeorm_.Column)({
361
+ type: 'varchar',
362
+ length: 255,
363
+ nullable: false
364
+ }),
365
+ _ts_metadata("design:type", String)
366
+ ], Form.prototype, "name", void 0);
367
+ _ts_decorate([
368
+ (0,external_typeorm_.Column)({
369
+ type: 'varchar',
370
+ length: 500,
371
+ nullable: true
372
+ }),
373
+ _ts_metadata("design:type", Object)
374
+ ], Form.prototype, "description", void 0);
375
+ _ts_decorate([
376
+ (0,external_typeorm_.Column)({
377
+ type: 'varchar',
378
+ length: 255,
379
+ nullable: true
380
+ }),
381
+ _ts_metadata("design:type", Object)
382
+ ], Form.prototype, "slug", void 0);
383
+ _ts_decorate([
384
+ (0,external_typeorm_.Column)({
385
+ type: getJsonColumnType(),
386
+ nullable: false
387
+ }),
388
+ _ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
389
+ ], Form.prototype, "schema", void 0);
390
+ _ts_decorate([
391
+ (0,external_typeorm_.Column)({
392
+ type: 'int',
393
+ nullable: false,
394
+ default: 1,
395
+ name: 'schema_version'
396
+ }),
397
+ _ts_metadata("design:type", Number)
398
+ ], Form.prototype, "schemaVersion", void 0);
399
+ _ts_decorate([
400
+ (0,external_typeorm_.Column)({
401
+ type: 'varchar',
402
+ length: 50,
403
+ default: 'AUTHENTICATED',
404
+ name: 'access_type'
405
+ }),
406
+ _ts_metadata("design:type", typeof form_access_type_enum/* .FormAccessType */.h === "undefined" ? Object : form_access_type_enum/* .FormAccessType */.h)
407
+ ], Form.prototype, "accessType", void 0);
408
+ _ts_decorate([
409
+ (0,external_typeorm_.Column)({
410
+ type: getJsonColumnType(),
411
+ nullable: true,
412
+ name: 'action_groups'
413
+ }),
414
+ _ts_metadata("design:type", Object)
415
+ ], Form.prototype, "actionGroups", void 0);
416
+ _ts_decorate([
417
+ (0,external_typeorm_.Column)({
418
+ type: getJsonColumnType(),
419
+ nullable: true
420
+ }),
421
+ _ts_metadata("design:type", Object)
422
+ ], Form.prototype, "tags", void 0);
423
+ _ts_decorate([
424
+ (0,external_typeorm_.Column)({
425
+ type: 'boolean',
426
+ nullable: false,
427
+ default: true,
428
+ name: 'is_active'
429
+ }),
430
+ _ts_metadata("design:type", Boolean)
431
+ ], Form.prototype, "isActive", void 0);
432
+ Form = _ts_decorate([
433
+ (0,external_typeorm_.Entity)({
434
+ name: 'form'
435
+ }),
436
+ (0,external_typeorm_.Index)([
437
+ 'slug'
438
+ ], {
439
+ unique: true
440
+ }),
441
+ (0,external_typeorm_.Index)([
442
+ 'isActive'
443
+ ])
444
+ ], Form);
445
+
446
+ ;// CONCATENATED MODULE: ./projects/nestjs-form-builder/src/entities/form-result.entity.ts
447
+ function form_result_entity_ts_decorate(decorators, target, key, desc) {
448
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
449
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
450
+ r = Reflect.decorate(decorators, target, key, desc);
451
+ } else {
452
+ for(var i = decorators.length - 1; i >= 0; i--){
453
+ if (d = decorators[i]) {
454
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
455
+ }
456
+ }
457
+ }
458
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
459
+ }
460
+ function form_result_entity_ts_metadata(metadataKey, metadataValue) {
461
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
462
+ return Reflect.metadata(metadataKey, metadataValue);
463
+ }
464
+ }
465
+
466
+
467
+ class FormResult extends Identity {
468
+ formId;
469
+ schemaVersionSnapshot;
470
+ schemaVersion;
471
+ data;
472
+ submittedById;
473
+ submittedAt;
474
+ isDraft;
475
+ }
476
+ form_result_entity_ts_decorate([
477
+ (0,external_typeorm_.Index)(),
478
+ (0,external_typeorm_.Column)({
479
+ type: 'uuid',
480
+ nullable: false,
481
+ name: 'form_id'
482
+ }),
483
+ form_result_entity_ts_metadata("design:type", String)
484
+ ], FormResult.prototype, "formId", void 0);
485
+ form_result_entity_ts_decorate([
486
+ (0,external_typeorm_.Column)({
487
+ type: getJsonColumnType(),
488
+ nullable: false,
489
+ name: 'schema_version_snapshot'
490
+ }),
491
+ form_result_entity_ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
492
+ ], FormResult.prototype, "schemaVersionSnapshot", void 0);
493
+ form_result_entity_ts_decorate([
494
+ (0,external_typeorm_.Column)({
495
+ type: 'int',
496
+ nullable: false,
497
+ name: 'schema_version'
498
+ }),
499
+ form_result_entity_ts_metadata("design:type", Number)
500
+ ], FormResult.prototype, "schemaVersion", void 0);
501
+ form_result_entity_ts_decorate([
502
+ (0,external_typeorm_.Column)({
503
+ type: getJsonColumnType(),
504
+ nullable: false
505
+ }),
506
+ form_result_entity_ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
507
+ ], FormResult.prototype, "data", void 0);
508
+ form_result_entity_ts_decorate([
509
+ (0,external_typeorm_.Column)({
510
+ type: 'uuid',
511
+ nullable: true,
512
+ name: 'submitted_by_id'
513
+ }),
514
+ form_result_entity_ts_metadata("design:type", Object)
515
+ ], FormResult.prototype, "submittedById", void 0);
516
+ form_result_entity_ts_decorate([
517
+ (0,external_typeorm_.Column)({
518
+ type: 'timestamp',
519
+ nullable: false,
520
+ name: 'submitted_at'
521
+ }),
522
+ form_result_entity_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
523
+ ], FormResult.prototype, "submittedAt", void 0);
524
+ form_result_entity_ts_decorate([
525
+ (0,external_typeorm_.Column)({
526
+ type: 'boolean',
527
+ default: false,
528
+ name: 'is_draft'
529
+ }),
530
+ form_result_entity_ts_metadata("design:type", Boolean)
531
+ ], FormResult.prototype, "isDraft", void 0);
532
+ FormResult = form_result_entity_ts_decorate([
533
+ (0,external_typeorm_.Entity)({
534
+ name: 'form_result'
535
+ })
536
+ ], FormResult);
537
+
538
+ ;// CONCATENATED MODULE: ./projects/nestjs-form-builder/src/entities/form-with-company.entity.ts
539
+ function form_with_company_entity_ts_decorate(decorators, target, key, desc) {
540
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
541
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
542
+ r = Reflect.decorate(decorators, target, key, desc);
543
+ } else {
544
+ for(var i = decorators.length - 1; i >= 0; i--){
545
+ if (d = decorators[i]) {
546
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
547
+ }
548
+ }
549
+ }
550
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
551
+ }
552
+ function form_with_company_entity_ts_metadata(metadataKey, metadataValue) {
553
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
554
+ return Reflect.metadata(metadataKey, metadataValue);
555
+ }
556
+ }
557
+
558
+
559
+ class FormWithCompany extends Form {
560
+ companyId;
561
+ }
562
+ form_with_company_entity_ts_decorate([
563
+ (0,external_typeorm_.Column)({
564
+ type: 'uuid',
565
+ nullable: true,
566
+ name: 'company_id'
567
+ }),
568
+ form_with_company_entity_ts_metadata("design:type", Object)
569
+ ], FormWithCompany.prototype, "companyId", void 0);
570
+ FormWithCompany = form_with_company_entity_ts_decorate([
571
+ (0,external_typeorm_.Entity)({
572
+ name: 'form'
573
+ }),
574
+ (0,external_typeorm_.Index)([
575
+ 'companyId'
576
+ ]),
577
+ (0,external_typeorm_.Index)([
578
+ 'companyId',
579
+ 'slug'
580
+ ], {
581
+ unique: true
582
+ }),
583
+ (0,external_typeorm_.Index)([
584
+ 'companyId',
585
+ 'isActive'
586
+ ])
587
+ ], FormWithCompany);
588
+
589
+ ;// CONCATENATED MODULE: ./projects/nestjs-form-builder/src/entities/index.ts
590
+ // Entities without company feature
591
+
592
+
593
+ // Entities with company feature
594
+
595
+
596
+
597
+
598
+ // Core entities (no company feature)
599
+ const FormCoreEntities = [
600
+ Form,
601
+ FormResult
602
+ ];
603
+ // Company-specific entities
604
+ const FormCompanyEntities = [
605
+ FormWithCompany,
606
+ FormResult
607
+ ];
608
+ function getFormBuilderEntitiesByConfig(enableCompanyFeature) {
609
+ return enableCompanyFeature ? FormCompanyEntities : FormCoreEntities;
610
+ }
611
+ // Base type aliases for backwards compatibility with services
612
+
613
+
614
+
615
+ },
616
+ 376(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
617
+ /**
618
+ * Form Access Type Enum
619
+ * Defines who can submit the form
620
+ */ var FormAccessType = /*#__PURE__*/ function(FormAccessType) {
621
+ /** No authentication required - anyone can submit */ FormAccessType["PUBLIC"] = "public";
622
+ /** Any authenticated user can submit */ FormAccessType["AUTHENTICATED"] = "authenticated";
623
+ /** Only users with specific action permissions can submit */ FormAccessType["ACTION_GROUP"] = "action_group";
624
+ return FormAccessType;
625
+ }({});
626
+
627
+ __webpack_require__.d(__webpack_exports__, {
628
+ h: () => (FormAccessType)
629
+ });
630
+
631
+
632
+ },
633
+ 781(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
634
+ /* import */ var _nestjs_common__rspack_import_0 = __webpack_require__(157);
635
+ /* import */ var _config_form_builder_constants_js__rspack_import_1 = __webpack_require__(512);
636
+ function _ts_decorate(decorators, target, key, desc) {
637
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
638
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
639
+ r = Reflect.decorate(decorators, target, key, desc);
640
+ } else {
641
+ for(var i = decorators.length - 1; i >= 0; i--){
642
+ if (d = decorators[i]) {
643
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
644
+ }
645
+ }
646
+ }
647
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
648
+ }
649
+ function _ts_metadata(metadataKey, metadataValue) {
650
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
651
+ return Reflect.metadata(metadataKey, metadataValue);
652
+ }
653
+ }
654
+ function _ts_param(paramIndex, decorator) {
655
+ return function(target, key) {
656
+ decorator(target, key, paramIndex);
657
+ };
658
+ }
659
+
660
+
661
+ class FormBuilderConfigService {
662
+ options;
663
+ constructor(options){
664
+ this.options = options;
665
+ }
666
+ isCompanyFeatureEnabled(tenant) {
667
+ return tenant?.enableCompanyFeature ?? this.options.bootstrapAppConfig?.enableCompanyFeature ?? false;
668
+ }
669
+ getDatabaseMode() {
670
+ return this.options.bootstrapAppConfig?.databaseMode ?? 'single';
671
+ }
672
+ isMultiTenant() {
673
+ return this.getDatabaseMode() === 'multi-tenant';
674
+ }
675
+ getOptions() {
676
+ return this.options;
677
+ }
678
+ getConfig() {
679
+ return this.options.config;
680
+ }
681
+ }
682
+ FormBuilderConfigService = _ts_decorate([
683
+ (0,_nestjs_common__rspack_import_0.Injectable)(),
684
+ _ts_param(0, (0,_nestjs_common__rspack_import_0.Inject)(_config_form_builder_constants_js__rspack_import_1/* .FORM_BUILDER_MODULE_OPTIONS */.v)),
685
+ _ts_metadata("design:type", Function),
686
+ _ts_metadata("design:paramtypes", [
687
+ typeof FormBuilderModuleOptions === "undefined" ? Object : FormBuilderModuleOptions
688
+ ])
689
+ ], FormBuilderConfigService);
690
+
691
+ __webpack_require__.d(__webpack_exports__, {
692
+ j: () => (FormBuilderConfigService)
693
+ });
694
+
695
+
696
+ },
697
+ 593(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
698
+
699
+ // EXPORTS
700
+ __webpack_require__.d(__webpack_exports__, {
701
+ _: () => (/* binding */ FormBuilderDataSourceProvider)
702
+ });
703
+
704
+ // EXTERNAL MODULE: external "@flusys/nestjs-shared/modules"
705
+ var modules_ = __webpack_require__(236);
706
+ // EXTERNAL MODULE: external "@nestjs/common"
707
+ var common_ = __webpack_require__(157);
708
+ ;// CONCATENATED MODULE: external "@nestjs/core"
709
+
710
+ // EXTERNAL MODULE: ./projects/nestjs-form-builder/src/services/form-builder-config.service.ts
711
+ var form_builder_config_service = __webpack_require__(781);
712
+ ;// CONCATENATED MODULE: ./projects/nestjs-form-builder/src/services/form-builder-datasource.provider.ts
713
+ function _ts_decorate(decorators, target, key, desc) {
714
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
715
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
716
+ r = Reflect.decorate(decorators, target, key, desc);
717
+ } else {
718
+ for(var i = decorators.length - 1; i >= 0; i--){
719
+ if (d = decorators[i]) {
720
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
721
+ }
722
+ }
723
+ }
724
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
725
+ }
726
+ function _ts_metadata(metadataKey, metadataValue) {
727
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
728
+ return Reflect.metadata(metadataKey, metadataValue);
729
+ }
730
+ }
731
+ function _ts_param(paramIndex, decorator) {
732
+ return function(target, key) {
733
+ decorator(target, key, paramIndex);
734
+ };
735
+ }
736
+
737
+
738
+
739
+
740
+ class FormBuilderDataSourceProvider extends modules_.MultiTenantDataSourceService {
741
+ configService;
742
+ static tenantConnections = new Map();
743
+ static singleDataSource = null;
744
+ static tenantsRegistry = new Map();
745
+ static initialized = false;
746
+ static connectionLocks = new Map();
747
+ static singleConnectionLock = null;
748
+ constructor(configService, request){
749
+ super(FormBuilderDataSourceProvider.buildParentOptions(configService.getOptions()), request), this.configService = configService;
750
+ }
751
+ static buildParentOptions(options) {
752
+ return {
753
+ bootstrapAppConfig: options.bootstrapAppConfig,
754
+ defaultDatabaseConfig: options.config?.defaultDatabaseConfig,
755
+ tenantDefaultDatabaseConfig: options.config?.tenantDefaultDatabaseConfig,
756
+ tenants: options.config?.tenants
757
+ };
758
+ }
759
+ async getFormBuilderEntities(enableCompanyFeature) {
760
+ const enable = enableCompanyFeature ?? this.configService.isCompanyFeatureEnabled();
761
+ const { getFormBuilderEntitiesByConfig } = await Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, 532));
762
+ return getFormBuilderEntitiesByConfig(enable);
763
+ }
764
+ async createDataSourceFromConfig(config) {
765
+ const enableCompanyFeature = this.configService.isCompanyFeatureEnabled(this.getCurrentTenant() ?? undefined);
766
+ const entities = await this.getFormBuilderEntities(enableCompanyFeature);
767
+ return super.createDataSourceFromConfig(config, entities);
768
+ }
769
+ }
770
+ FormBuilderDataSourceProvider = _ts_decorate([
771
+ (0,common_.Injectable)({
772
+ scope: common_.Scope.REQUEST
773
+ }),
774
+ _ts_param(0, (0,common_.Inject)(form_builder_config_service/* .FormBuilderConfigService */.j)),
775
+ _ts_param(1, (0,common_.Optional)()),
776
+ _ts_param(1, (0,common_.Inject)(__rspack_external__nestjs_core_d7b00a1a.REQUEST)),
777
+ _ts_metadata("design:type", Function),
778
+ _ts_metadata("design:paramtypes", [
779
+ typeof form_builder_config_service/* .FormBuilderConfigService */.j === "undefined" ? Object : form_builder_config_service/* .FormBuilderConfigService */.j,
780
+ typeof Request === "undefined" ? Object : Request
781
+ ])
782
+ ], FormBuilderDataSourceProvider);
783
+
784
+
785
+ },
786
+ 160(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
787
+ /* import */ var _flusys_nestjs_shared_classes__rspack_import_0 = __webpack_require__(937);
788
+ /* import */ var _flusys_nestjs_shared_decorators__rspack_import_1 = __webpack_require__(265);
789
+ /* import */ var _flusys_nestjs_shared_modules__rspack_import_2 = __webpack_require__(236);
790
+ /* import */ var _nestjs_common__rspack_import_3 = __webpack_require__(157);
791
+ /* import */ var typeorm__rspack_import_4 = __webpack_require__(158);
792
+ /* import */ var _config_index_js__rspack_import_10 = __webpack_require__(769);
793
+ /* import */ var _config_index_js__rspack_import_11 = __webpack_require__(137);
794
+ /* import */ var _dtos_form_result_dto_js__rspack_import_5 = __webpack_require__(788);
795
+ /* import */ var _entities_index_js__rspack_import_6 = __webpack_require__(532);
796
+ /* import */ var _enums_form_access_type_enum_js__rspack_import_12 = __webpack_require__(376);
797
+ /* import */ var _utils_computed_field_utils_js__rspack_import_13 = __webpack_require__(801);
798
+ /* import */ var _utils_permission_utils_js__rspack_import_7 = __webpack_require__(988);
799
+ /* import */ var _form_builder_config_service_js__rspack_import_8 = __webpack_require__(781);
800
+ /* import */ var _form_builder_datasource_provider_js__rspack_import_9 = __webpack_require__(593);
801
+ function _ts_decorate(decorators, target, key, desc) {
802
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
803
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
804
+ r = Reflect.decorate(decorators, target, key, desc);
805
+ } else {
806
+ for(var i = decorators.length - 1; i >= 0; i--){
807
+ if (d = decorators[i]) {
808
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
809
+ }
810
+ }
811
+ }
812
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
813
+ }
814
+ function _ts_metadata(metadataKey, metadataValue) {
815
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
816
+ return Reflect.metadata(metadataKey, metadataValue);
817
+ }
818
+ }
819
+ function _ts_param(paramIndex, decorator) {
820
+ return function(target, key) {
821
+ decorator(target, key, paramIndex);
822
+ };
823
+ }
824
+
825
+
826
+
827
+
828
+
829
+
830
+
831
+
832
+
833
+
834
+
835
+
836
+
837
+ class FormResultService extends _flusys_nestjs_shared_classes__rspack_import_0.ApiService {
838
+ cacheManager;
839
+ utilsService;
840
+ formBuilderConfig;
841
+ dataSourceProvider;
842
+ formRepository = null;
843
+ constructor(cacheManager, utilsService, formBuilderConfig, dataSourceProvider){
844
+ super(_config_index_js__rspack_import_10/* .FORM_BUILDER_EVENT_ENTITIES.FORM_RESULT */.eF.FORM_RESULT, cacheManager, utilsService, FormResultService.name, true, _config_index_js__rspack_import_10/* .FORM_BUILDER_EVENT_MODULE */.T$, dataSourceProvider, _entities_index_js__rspack_import_6/* .FormResult */.ez), this.cacheManager = cacheManager, this.utilsService = utilsService, this.formBuilderConfig = formBuilderConfig, this.dataSourceProvider = dataSourceProvider;
845
+ }
846
+ async ensureFormRepositoryInitialized() {
847
+ if (!this.formRepository) {
848
+ const enableCompanyFeature = this.formBuilderConfig.isCompanyFeatureEnabled();
849
+ const formEntity = enableCompanyFeature ? _entities_index_js__rspack_import_6/* .FormWithCompany */.Wl : _entities_index_js__rspack_import_6/* .Form */.lV;
850
+ this.formRepository = await this.dataSourceProvider.getRepository(formEntity);
851
+ }
852
+ }
853
+ async getActiveForm(formId) {
854
+ await this.ensureFormRepositoryInitialized();
855
+ const form = await this.formRepository.findOne({
856
+ where: {
857
+ id: formId,
858
+ isActive: true,
859
+ deletedAt: (0,typeorm__rspack_import_4.IsNull)()
860
+ }
861
+ });
862
+ if (!form) {
863
+ throw new _nestjs_common__rspack_import_3.NotFoundException({
864
+ message: 'Form not found or inactive',
865
+ messageKey: _config_index_js__rspack_import_11/* .FORM_MESSAGES.NOT_FOUND */.Q.NOT_FOUND
866
+ });
867
+ }
868
+ return form;
869
+ }
870
+ applyCompanyFilterToQuery(query, user) {
871
+ if (this.formBuilderConfig.isCompanyFeatureEnabled() && user?.companyId) {
872
+ query.innerJoin('form', 'f', 'f.id = form_result.formId').andWhere('f.company_id = :companyId', {
873
+ companyId: user.companyId
874
+ });
875
+ }
876
+ }
877
+ async validateSubmissionAccess(form, user, isPublic) {
878
+ if (isPublic) {
879
+ if (form.accessType !== _enums_form_access_type_enum_js__rspack_import_12/* .FormAccessType.PUBLIC */.h.PUBLIC) {
880
+ throw new _nestjs_common__rspack_import_3.UnauthorizedException({
881
+ message: 'This form is not available for public submission',
882
+ messageKey: _config_index_js__rspack_import_11/* .FORM_MESSAGES.NOT_PUBLIC */.Q.NOT_PUBLIC
883
+ });
884
+ }
885
+ return;
886
+ }
887
+ if (form.accessType === _enums_form_access_type_enum_js__rspack_import_12/* .FormAccessType.PUBLIC */.h.PUBLIC) return;
888
+ if (!user) {
889
+ throw new _nestjs_common__rspack_import_3.UnauthorizedException({
890
+ message: 'Authentication required to submit this form',
891
+ messageKey: _config_index_js__rspack_import_11/* .FORM_MESSAGES.AUTH_REQUIRED */.Q.AUTH_REQUIRED
892
+ });
893
+ }
894
+ if (form.accessType === _enums_form_access_type_enum_js__rspack_import_12/* .FormAccessType.ACTION_GROUP */.h.ACTION_GROUP && form.actionGroups?.length) {
895
+ const hasPermission = await (0,_utils_permission_utils_js__rspack_import_7/* .validateUserPermissions */.i)(user, form.actionGroups, this.cacheManager, this.formBuilderConfig.isCompanyFeatureEnabled());
896
+ if (!hasPermission) {
897
+ throw new _nestjs_common__rspack_import_3.ForbiddenException({
898
+ message: 'You do not have permission to submit this form',
899
+ messageKey: _config_index_js__rspack_import_11/* .FORM_MESSAGES.ACCESS_DENIED */.Q.ACCESS_DENIED
900
+ });
901
+ }
902
+ } else if (form.accessType !== _enums_form_access_type_enum_js__rspack_import_12/* .FormAccessType.AUTHENTICATED */.h.AUTHENTICATED) {
903
+ throw new _nestjs_common__rspack_import_3.BadRequestException({
904
+ message: 'Invalid form access type',
905
+ messageKey: _config_index_js__rspack_import_11/* .FORM_MESSAGES.INVALID_ACCESS_TYPE */.Q.INVALID_ACCESS_TYPE
906
+ });
907
+ }
908
+ }
909
+ buildUserDraftWhere(formId, userId) {
910
+ return {
911
+ formId,
912
+ submittedById: userId,
913
+ isDraft: true,
914
+ deletedAt: (0,typeorm__rspack_import_4.IsNull)()
915
+ };
916
+ }
917
+ // Query Customization
918
+ async getSelectQuery(query, _user, select) {
919
+ if (!select || !select.length) {
920
+ select = [
921
+ 'id',
922
+ 'formId',
923
+ 'schemaVersionSnapshot',
924
+ 'schemaVersion',
925
+ 'data',
926
+ 'submittedById',
927
+ 'submittedAt',
928
+ 'isDraft',
929
+ 'createdAt',
930
+ 'updatedAt'
931
+ ];
932
+ }
933
+ const selectFields = select.map((field)=>`${this.entityName}.${field}`);
934
+ query.select(selectFields);
935
+ return {
936
+ query,
937
+ isRaw: false
938
+ };
939
+ }
940
+ async getExtraManipulateQuery(query, filterDto, user) {
941
+ const result = await super.getExtraManipulateQuery(query, filterDto, user);
942
+ this.applyCompanyFilterToQuery(query, user);
943
+ return result;
944
+ }
945
+ applyComputedFields(data, form, isDraft) {
946
+ if (isDraft) {
947
+ return data;
948
+ }
949
+ const schema = form.schema;
950
+ const settings = schema?.settings;
951
+ const computedFields = settings?.computedFields;
952
+ if (!computedFields || computedFields.length === 0) {
953
+ return data;
954
+ }
955
+ const computedValues = (0,_utils_computed_field_utils_js__rspack_import_13/* .calculateComputedFields */.X)(data, computedFields);
956
+ return {
957
+ ...data,
958
+ _computed: computedValues
959
+ };
960
+ }
961
+ convertEntityToResponseDto(entity, _isRaw) {
962
+ return {
963
+ id: entity.id,
964
+ formId: entity.formId,
965
+ schemaVersionSnapshot: entity.schemaVersionSnapshot,
966
+ schemaVersion: entity.schemaVersion,
967
+ data: entity.data,
968
+ submittedById: entity.submittedById,
969
+ submittedAt: entity.submittedAt,
970
+ isDraft: entity.isDraft,
971
+ createdAt: entity.createdAt,
972
+ updatedAt: entity.updatedAt,
973
+ deletedAt: entity.deletedAt,
974
+ createdById: entity.createdById,
975
+ updatedById: entity.updatedById,
976
+ deletedById: entity.deletedById
977
+ };
978
+ }
979
+ // Form Submission
980
+ async submitForm(dto, user, isPublic = false) {
981
+ await this.ensureDataSourceRepository();
982
+ const form = await this.getActiveForm(dto.formId);
983
+ await this.validateSubmissionAccess(form, user, isPublic);
984
+ const isDraft = dto.isDraft ?? false;
985
+ const staleResults = [];
986
+ // Handle existing draft for authenticated users
987
+ if (user?.id) {
988
+ const existingDraft = await this.repository.findOne({
989
+ where: this.buildUserDraftWhere(dto.formId, user.id)
990
+ });
991
+ if (existingDraft) {
992
+ if (isDraft) {
993
+ Object.assign(existingDraft, {
994
+ data: dto.data,
995
+ schemaVersionSnapshot: form.schema,
996
+ schemaVersion: form.schemaVersion,
997
+ submittedAt: new Date()
998
+ });
999
+ const saved = await this.repository.save(existingDraft);
1000
+ await this.invalidateResultCache([
1001
+ saved
1002
+ ]);
1003
+ await this.publishSubmissionEvent(saved, dto.formId, true, user);
1004
+ return this.convertEntityToResponseDto(saved, false);
1005
+ }
1006
+ await this.repository.softRemove(existingDraft);
1007
+ staleResults.push(existingDraft);
1008
+ }
1009
+ }
1010
+ const saved = await this.repository.save({
1011
+ formId: dto.formId,
1012
+ schemaVersionSnapshot: form.schema,
1013
+ schemaVersion: form.schemaVersion,
1014
+ data: this.applyComputedFields(dto.data, form, isDraft),
1015
+ submittedById: user?.id ?? null,
1016
+ submittedAt: new Date(),
1017
+ isDraft
1018
+ });
1019
+ await this.invalidateResultCache([
1020
+ ...staleResults,
1021
+ saved
1022
+ ]);
1023
+ await this.publishSubmissionEvent(saved, dto.formId, isDraft, user);
1024
+ return this.convertEntityToResponseDto(saved, false);
1025
+ }
1026
+ async getMyDraft(formId, user) {
1027
+ await this.ensureDataSourceRepository();
1028
+ const draft = await this.repository.findOne({
1029
+ where: this.buildUserDraftWhere(formId, user.id),
1030
+ order: {
1031
+ updatedAt: 'DESC'
1032
+ }
1033
+ });
1034
+ return draft ? this.convertEntityToResponseDto(draft, false) : null;
1035
+ }
1036
+ async updateDraft(draftId, dto, user) {
1037
+ await this.ensureDataSourceRepository();
1038
+ const draft = await this.repository.findOne({
1039
+ where: {
1040
+ id: draftId,
1041
+ submittedById: user.id,
1042
+ deletedAt: (0,typeorm__rspack_import_4.IsNull)()
1043
+ }
1044
+ });
1045
+ if (!draft) {
1046
+ throw new _nestjs_common__rspack_import_3.NotFoundException({
1047
+ message: 'Draft not found',
1048
+ messageKey: _config_index_js__rspack_import_11/* .FORM_RESULT_MESSAGES.NOT_FOUND */.y.NOT_FOUND
1049
+ });
1050
+ }
1051
+ const form = await this.getActiveForm(dto.formId);
1052
+ const isDraft = dto.isDraft ?? false;
1053
+ Object.assign(draft, {
1054
+ data: this.applyComputedFields(dto.data, form, isDraft),
1055
+ schemaVersionSnapshot: form.schema,
1056
+ schemaVersion: form.schemaVersion,
1057
+ submittedAt: new Date(),
1058
+ isDraft
1059
+ });
1060
+ const saved = await this.repository.save(draft);
1061
+ await this.invalidateResultCache([
1062
+ saved
1063
+ ]);
1064
+ await this.publishSubmissionEvent(saved, dto.formId, isDraft, user);
1065
+ return this.convertEntityToResponseDto(saved, false);
1066
+ }
1067
+ async publishSubmissionEvent(result, formId, isDraft, user) {
1068
+ await this.publishDomainAction(isDraft ? _config_index_js__rspack_import_10/* .FORM_BUILDER_EVENT_ACTIONS.DRAFT_SAVED */.ov.DRAFT_SAVED : _config_index_js__rspack_import_10/* .FORM_BUILDER_EVENT_ACTIONS.SUBMITTED */.ov.SUBMITTED, {
1069
+ ids: [
1070
+ result.id
1071
+ ],
1072
+ data: result,
1073
+ metadata: {
1074
+ formId,
1075
+ isDraft,
1076
+ schemaVersion: result.schemaVersion
1077
+ },
1078
+ user
1079
+ });
1080
+ }
1081
+ async invalidateResultCache(results) {
1082
+ await Promise.all([
1083
+ this.clearCacheForAll(),
1084
+ this.clearCacheForId(results)
1085
+ ]);
1086
+ }
1087
+ async getByFormId(formId, user, pagination) {
1088
+ await this.ensureDataSourceRepository();
1089
+ const query = this.repository.createQueryBuilder(this.entityName).where('form_result.formId = :formId', {
1090
+ formId
1091
+ }).andWhere('form_result.deletedAt IS NULL');
1092
+ this.applyCompanyFilterToQuery(query, user);
1093
+ const page = pagination?.page ?? 0;
1094
+ const pageSize = pagination?.pageSize ?? 10;
1095
+ query.skip(page * pageSize).take(pageSize).orderBy('form_result.submittedAt', 'DESC');
1096
+ const [entities, total] = await query.getManyAndCount();
1097
+ return {
1098
+ data: entities.map((e)=>this.convertEntityToResponseDto(e, false)),
1099
+ total
1100
+ };
1101
+ }
1102
+ async hasUserSubmitted(formId, user) {
1103
+ await this.ensureDataSourceRepository();
1104
+ const count = await this.repository.count({
1105
+ where: {
1106
+ formId,
1107
+ submittedById: user.id,
1108
+ isDraft: false,
1109
+ deletedAt: (0,typeorm__rspack_import_4.IsNull)()
1110
+ }
1111
+ });
1112
+ return count > 0;
1113
+ }
1114
+ }
1115
+ _ts_decorate([
1116
+ (0,_flusys_nestjs_shared_decorators__rspack_import_1.LogAction)({
1117
+ action: 'formResult.submit',
1118
+ module: 'form-builder'
1119
+ }),
1120
+ _ts_metadata("design:type", Function),
1121
+ _ts_metadata("design:paramtypes", [
1122
+ typeof _dtos_form_result_dto_js__rspack_import_5/* .SubmitFormDto */.sH === "undefined" ? Object : _dtos_form_result_dto_js__rspack_import_5/* .SubmitFormDto */.sH,
1123
+ Object,
1124
+ void 0
1125
+ ]),
1126
+ _ts_metadata("design:returntype", Promise)
1127
+ ], FormResultService.prototype, "submitForm", null);
1128
+ _ts_decorate([
1129
+ (0,_flusys_nestjs_shared_decorators__rspack_import_1.LogAction)({
1130
+ action: 'formResult.updateDraft',
1131
+ module: 'form-builder'
1132
+ }),
1133
+ _ts_metadata("design:type", Function),
1134
+ _ts_metadata("design:paramtypes", [
1135
+ String,
1136
+ typeof _dtos_form_result_dto_js__rspack_import_5/* .SubmitFormDto */.sH === "undefined" ? Object : _dtos_form_result_dto_js__rspack_import_5/* .SubmitFormDto */.sH,
1137
+ typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
1138
+ ]),
1139
+ _ts_metadata("design:returntype", Promise)
1140
+ ], FormResultService.prototype, "updateDraft", null);
1141
+ FormResultService = _ts_decorate([
1142
+ (0,_nestjs_common__rspack_import_3.Injectable)({
1143
+ scope: _nestjs_common__rspack_import_3.Scope.REQUEST
1144
+ }),
1145
+ _ts_param(0, (0,_nestjs_common__rspack_import_3.Inject)('CACHE_INSTANCE')),
1146
+ _ts_param(1, (0,_nestjs_common__rspack_import_3.Inject)(_flusys_nestjs_shared_modules__rspack_import_2.UtilsService)),
1147
+ _ts_param(2, (0,_nestjs_common__rspack_import_3.Inject)(_form_builder_config_service_js__rspack_import_8/* .FormBuilderConfigService */.j)),
1148
+ _ts_param(3, (0,_nestjs_common__rspack_import_3.Inject)(_form_builder_datasource_provider_js__rspack_import_9/* .FormBuilderDataSourceProvider */._)),
1149
+ _ts_metadata("design:type", Function),
1150
+ _ts_metadata("design:paramtypes", [
1151
+ typeof _flusys_nestjs_shared_classes__rspack_import_0.HybridCache === "undefined" ? Object : _flusys_nestjs_shared_classes__rspack_import_0.HybridCache,
1152
+ typeof _flusys_nestjs_shared_modules__rspack_import_2.UtilsService === "undefined" ? Object : _flusys_nestjs_shared_modules__rspack_import_2.UtilsService,
1153
+ typeof _form_builder_config_service_js__rspack_import_8/* .FormBuilderConfigService */.j === "undefined" ? Object : _form_builder_config_service_js__rspack_import_8/* .FormBuilderConfigService */.j,
1154
+ typeof _form_builder_datasource_provider_js__rspack_import_9/* .FormBuilderDataSourceProvider */._ === "undefined" ? Object : _form_builder_datasource_provider_js__rspack_import_9/* .FormBuilderDataSourceProvider */._
1155
+ ])
1156
+ ], FormResultService);
1157
+
1158
+ __webpack_require__.d(__webpack_exports__, {
1159
+ v: () => (FormResultService)
1160
+ });
1161
+
1162
+
1163
+ },
1164
+ 148(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
1165
+
1166
+ // EXPORTS
1167
+ __webpack_require__.d(__webpack_exports__, {
1168
+ u: () => (/* binding */ FormService)
1169
+ });
1170
+
1171
+ ;// CONCATENATED MODULE: external "@flusys/nestjs-core"
1172
+
1173
+ // EXTERNAL MODULE: external "@flusys/nestjs-shared/classes"
1174
+ var classes_ = __webpack_require__(937);
1175
+ // EXTERNAL MODULE: external "@flusys/nestjs-shared/modules"
1176
+ var modules_ = __webpack_require__(236);
1177
+ ;// CONCATENATED MODULE: external "@flusys/nestjs-shared/utils"
1178
+
1179
+ // EXTERNAL MODULE: external "@nestjs/common"
1180
+ var common_ = __webpack_require__(157);
1181
+ // EXTERNAL MODULE: external "typeorm"
1182
+ var external_typeorm_ = __webpack_require__(158);
1183
+ // EXTERNAL MODULE: ./projects/nestjs-form-builder/src/config/event-actions.ts
1184
+ var event_actions = __webpack_require__(769);
1185
+ // EXTERNAL MODULE: ./projects/nestjs-form-builder/src/config/message-keys.ts
1186
+ var message_keys = __webpack_require__(137);
1187
+ // EXTERNAL MODULE: ./projects/nestjs-form-builder/src/entities/index.ts + 5 modules
1188
+ var entities = __webpack_require__(532);
1189
+ // EXTERNAL MODULE: ./projects/nestjs-form-builder/src/enums/form-access-type.enum.ts
1190
+ var form_access_type_enum = __webpack_require__(376);
1191
+ // EXTERNAL MODULE: ./projects/nestjs-form-builder/src/utils/permission.utils.ts
1192
+ var permission_utils = __webpack_require__(988);
1193
+ // EXTERNAL MODULE: ./projects/nestjs-form-builder/src/services/form-builder-config.service.ts
1194
+ var form_builder_config_service = __webpack_require__(781);
1195
+ // EXTERNAL MODULE: ./projects/nestjs-form-builder/src/services/form-builder-datasource.provider.ts + 1 modules
1196
+ var form_builder_datasource_provider = __webpack_require__(593);
1197
+ ;// CONCATENATED MODULE: ./projects/nestjs-form-builder/src/services/form.service.ts
1198
+ function _ts_decorate(decorators, target, key, desc) {
1199
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1200
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1201
+ r = Reflect.decorate(decorators, target, key, desc);
1202
+ } else {
1203
+ for(var i = decorators.length - 1; i >= 0; i--){
1204
+ if (d = decorators[i]) {
1205
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1206
+ }
1207
+ }
1208
+ }
1209
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1210
+ }
1211
+ function _ts_metadata(metadataKey, metadataValue) {
1212
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1213
+ return Reflect.metadata(metadataKey, metadataValue);
1214
+ }
1215
+ }
1216
+ function _ts_param(paramIndex, decorator) {
1217
+ return function(target, key) {
1218
+ decorator(target, key, paramIndex);
1219
+ };
1220
+ }
1221
+
1222
+
1223
+
1224
+
1225
+
1226
+
1227
+
1228
+
1229
+
1230
+
1231
+
1232
+
1233
+ class FormService extends classes_.ApiService {
1234
+ cacheManager;
1235
+ utilsService;
1236
+ formBuilderConfig;
1237
+ constructor(cacheManager, utilsService, formBuilderConfig, dataSourceProvider){
1238
+ super(event_actions/* .FORM_BUILDER_EVENT_ENTITIES.FORM */.eF.FORM, cacheManager, utilsService, FormService.name, true, event_actions/* .FORM_BUILDER_EVENT_MODULE */.T$, dataSourceProvider, formBuilderConfig.isCompanyFeatureEnabled() ? entities/* .FormWithCompany */.Wl : entities/* .Form */.lV), this.cacheManager = cacheManager, this.utilsService = utilsService, this.formBuilderConfig = formBuilderConfig;
1239
+ }
1240
+ // Entity Conversion
1241
+ async convertSingleDtoToEntity(dto, user) {
1242
+ let form = {};
1243
+ let isUpdate = false;
1244
+ // NOTE: Using 'id' in dto check instead of instanceof - instanceof may not work after esbuild bundling
1245
+ if ('id' in dto && dto.id && typeof dto.id === 'string') {
1246
+ const dbData = await this.repository.findOne({
1247
+ where: {
1248
+ id: dto.id
1249
+ }
1250
+ });
1251
+ if (!dbData) {
1252
+ throw new common_.NotFoundException({
1253
+ message: 'Form not found',
1254
+ messageKey: message_keys/* .FORM_MESSAGES.NOT_FOUND */.Q.NOT_FOUND
1255
+ });
1256
+ }
1257
+ form = dbData;
1258
+ isUpdate = true;
1259
+ // Auto-increment schema version if schema changed
1260
+ if (dto.schema && JSON.stringify(dto.schema) !== JSON.stringify(form.schema)) {
1261
+ dto.schemaVersion = form.schemaVersion + 1;
1262
+ }
1263
+ }
1264
+ // Merge DTO into form
1265
+ form = {
1266
+ ...form,
1267
+ ...dto
1268
+ };
1269
+ // Set company context if enabled
1270
+ const enableCompanyFeature = this.formBuilderConfig.isCompanyFeatureEnabled();
1271
+ if (enableCompanyFeature) {
1272
+ if (isUpdate) {
1273
+ // During update: Only set companyId if explicitly provided
1274
+ if (dto.companyId !== undefined) {
1275
+ form.companyId = dto.companyId;
1276
+ }
1277
+ // If companyId is not in form at all, set from user
1278
+ if (form.companyId === undefined) {
1279
+ form.companyId = user?.companyId ?? null;
1280
+ }
1281
+ } else {
1282
+ // During creation: Use DTO's companyId if provided, otherwise use user's
1283
+ form.companyId = dto.companyId ?? user?.companyId ?? null;
1284
+ }
1285
+ }
1286
+ return form;
1287
+ }
1288
+ async getSelectQuery(query, _user, select) {
1289
+ if (!select || !select.length) {
1290
+ select = [
1291
+ 'id',
1292
+ 'name',
1293
+ 'description',
1294
+ 'slug',
1295
+ 'schema',
1296
+ 'schemaVersion',
1297
+ 'accessType',
1298
+ 'actionGroups',
1299
+ 'tags',
1300
+ 'isActive',
1301
+ 'createdAt',
1302
+ 'updatedAt'
1303
+ ];
1304
+ }
1305
+ const selectFields = select.map((field)=>`${this.entityName}.${field}`);
1306
+ // Add company context fields if company feature is enabled
1307
+ if (this.formBuilderConfig.isCompanyFeatureEnabled()) {
1308
+ selectFields.push('form.companyId');
1309
+ }
1310
+ query.select(selectFields);
1311
+ return {
1312
+ query,
1313
+ isRaw: false
1314
+ };
1315
+ }
1316
+ // Supports filtering by one or more tags (array-contains-all) via the generic get-all filter,
1317
+ // e.g. { filter: { tags: ['survey', 'review'] } }, since tags is a JSON array column.
1318
+ async getFilterQuery(query, filter, user) {
1319
+ const { tags, ...rest } = filter;
1320
+ if (tags !== undefined && tags !== null) {
1321
+ const tagList = (Array.isArray(tags) ? tags : [
1322
+ tags
1323
+ ]).map(String);
1324
+ if (tagList.length > 0) {
1325
+ this.applyTagFilter(query, tagList);
1326
+ }
1327
+ }
1328
+ return super.getFilterQuery(query, rest, user);
1329
+ }
1330
+ applyTagFilter(query, tags) {
1331
+ const driver = __rspack_external__flusys_nestjs_core_ff4ca4e2.envConfig.getTypeOrmConfig().type;
1332
+ if (driver === 'postgres') {
1333
+ query.andWhere(`${this.entityName}.tags @> :tagValues::jsonb`, {
1334
+ tagValues: JSON.stringify(tags)
1335
+ });
1336
+ } else if (driver === 'mysql') {
1337
+ query.andWhere(`JSON_CONTAINS(${this.entityName}.tags, :tagValues)`, {
1338
+ tagValues: JSON.stringify(tags)
1339
+ });
1340
+ } else {
1341
+ tags.forEach((tag, index)=>{
1342
+ query.andWhere(`${this.entityName}.tags LIKE :tagValue${index}`, {
1343
+ [`tagValue${index}`]: `%"${tag}"%`
1344
+ });
1345
+ });
1346
+ }
1347
+ }
1348
+ async getExtraManipulateQuery(query, filterDto, user) {
1349
+ const result = await super.getExtraManipulateQuery(query, filterDto, user);
1350
+ // Apply company filter using shared utility
1351
+ (0,__rspack_external__flusys_nestjs_shared_utils_9125c1f1.applyCompanyFilter)(query, {
1352
+ isCompanyFeatureEnabled: this.formBuilderConfig.isCompanyFeatureEnabled(),
1353
+ entityAlias: 'form'
1354
+ }, user);
1355
+ return result;
1356
+ }
1357
+ convertEntityToResponseDto(entity, _isRaw) {
1358
+ // Type guard for company-enabled entity
1359
+ const entityWithCompany = entity;
1360
+ return {
1361
+ id: entity.id,
1362
+ name: entity.name,
1363
+ description: entity.description,
1364
+ slug: entity.slug,
1365
+ schema: entity.schema,
1366
+ schemaVersion: entity.schemaVersion,
1367
+ accessType: entity.accessType,
1368
+ actionGroups: entity.actionGroups,
1369
+ tags: entity.tags,
1370
+ isActive: entity.isActive,
1371
+ companyId: entityWithCompany.companyId ?? null,
1372
+ createdAt: entity.createdAt,
1373
+ updatedAt: entity.updatedAt,
1374
+ deletedAt: entity.deletedAt,
1375
+ createdById: entity.createdById,
1376
+ updatedById: entity.updatedById,
1377
+ deletedById: entity.deletedById
1378
+ };
1379
+ }
1380
+ toPublicForm(form) {
1381
+ return {
1382
+ id: form.id,
1383
+ name: form.name,
1384
+ description: form.description,
1385
+ schema: form.schema,
1386
+ schemaVersion: form.schemaVersion
1387
+ };
1388
+ }
1389
+ async findPublicActiveForm(where) {
1390
+ await this.ensureDataSourceRepository();
1391
+ return await this.repository.findOne({
1392
+ where: {
1393
+ ...where,
1394
+ accessType: form_access_type_enum/* .FormAccessType.PUBLIC */.h.PUBLIC,
1395
+ isActive: true,
1396
+ deletedAt: (0,external_typeorm_.IsNull)()
1397
+ }
1398
+ });
1399
+ }
1400
+ // Public Form Access
1401
+ async getPublicForm(formId) {
1402
+ const form = await this.findPublicActiveForm({
1403
+ id: formId
1404
+ });
1405
+ if (!form) {
1406
+ throw new common_.NotFoundException({
1407
+ message: 'Form not found or not available for public access',
1408
+ messageKey: message_keys/* .FORM_MESSAGES.NOT_PUBLIC */.Q.NOT_PUBLIC
1409
+ });
1410
+ }
1411
+ return this.toPublicForm(form);
1412
+ }
1413
+ async getFormForSubmission(formId, user) {
1414
+ await this.ensureDataSourceRepository();
1415
+ const form = await this.repository.findOne({
1416
+ where: {
1417
+ id: formId,
1418
+ isActive: true,
1419
+ deletedAt: (0,external_typeorm_.IsNull)()
1420
+ }
1421
+ });
1422
+ if (!form) {
1423
+ throw new common_.NotFoundException({
1424
+ message: 'Form not found or inactive',
1425
+ messageKey: message_keys/* .FORM_MESSAGES.NOT_FOUND */.Q.NOT_FOUND
1426
+ });
1427
+ }
1428
+ // Access validation based on accessType
1429
+ if (form.accessType === form_access_type_enum/* .FormAccessType.PUBLIC */.h.PUBLIC) {
1430
+ return form; // Anyone can access
1431
+ }
1432
+ // All non-public forms require authentication
1433
+ if (!user) {
1434
+ throw new common_.UnauthorizedException({
1435
+ message: 'Authentication required to submit this form',
1436
+ messageKey: message_keys/* .FORM_MESSAGES.AUTH_REQUIRED */.Q.AUTH_REQUIRED
1437
+ });
1438
+ }
1439
+ if (form.accessType === form_access_type_enum/* .FormAccessType.AUTHENTICATED */.h.AUTHENTICATED || form.accessType === form_access_type_enum/* .FormAccessType.ACTION_GROUP */.h.ACTION_GROUP) {
1440
+ return form; // Permission check for ACTION_GROUP is handled by the controller/guard
1441
+ }
1442
+ throw new common_.BadRequestException({
1443
+ message: 'Invalid access type',
1444
+ messageKey: message_keys/* .FORM_MESSAGES.INVALID_ACCESS_TYPE */.Q.INVALID_ACCESS_TYPE
1445
+ });
1446
+ }
1447
+ async getBySlug(slug) {
1448
+ await this.ensureDataSourceRepository();
1449
+ const form = await this.repository.findOne({
1450
+ where: {
1451
+ slug,
1452
+ deletedAt: (0,external_typeorm_.IsNull)()
1453
+ }
1454
+ });
1455
+ return form ? this.convertEntityToResponseDto(form, false) : null;
1456
+ }
1457
+ /**
1458
+ * Get public form by slug (no authentication required)
1459
+ * Returns null if form doesn't exist, is not public, or is inactive
1460
+ */ async getPublicFormBySlug(slug) {
1461
+ const form = await this.findPublicActiveForm({
1462
+ slug
1463
+ });
1464
+ return form ? this.toPublicForm(form) : null;
1465
+ }
1466
+ async getFormAccessInfo(formId) {
1467
+ await this.ensureDataSourceRepository();
1468
+ const form = await this.repository.findOne({
1469
+ where: {
1470
+ id: formId,
1471
+ deletedAt: (0,external_typeorm_.IsNull)()
1472
+ },
1473
+ select: [
1474
+ 'id',
1475
+ 'name',
1476
+ 'description',
1477
+ 'accessType',
1478
+ 'actionGroups',
1479
+ 'isActive'
1480
+ ]
1481
+ });
1482
+ if (!form) {
1483
+ throw new common_.NotFoundException({
1484
+ message: 'Form not found',
1485
+ messageKey: message_keys/* .FORM_MESSAGES.NOT_FOUND */.Q.NOT_FOUND
1486
+ });
1487
+ }
1488
+ return {
1489
+ id: form.id,
1490
+ name: form.name,
1491
+ description: form.description,
1492
+ accessType: form.accessType,
1493
+ actionGroups: form.actionGroups,
1494
+ isActive: form.isActive
1495
+ };
1496
+ }
1497
+ async getAuthenticatedForm(formId, user) {
1498
+ const form = await this.getFormForSubmission(formId, user);
1499
+ // For action_group access, check permissions from cache
1500
+ if (form.accessType === form_access_type_enum/* .FormAccessType.ACTION_GROUP */.h.ACTION_GROUP && form.actionGroups?.length) {
1501
+ const hasPermission = await (0,permission_utils/* .validateUserPermissions */.i)(user, form.actionGroups, this.cacheManager, this.formBuilderConfig.isCompanyFeatureEnabled());
1502
+ if (!hasPermission) {
1503
+ throw new common_.ForbiddenException({
1504
+ message: 'You do not have permission to access this form',
1505
+ messageKey: message_keys/* .FORM_MESSAGES.ACCESS_DENIED */.Q.ACCESS_DENIED
1506
+ });
1507
+ }
1508
+ }
1509
+ return this.toPublicForm(form);
1510
+ }
1511
+ }
1512
+ FormService = _ts_decorate([
1513
+ (0,common_.Injectable)({
1514
+ scope: common_.Scope.REQUEST
1515
+ }),
1516
+ _ts_param(0, (0,common_.Inject)('CACHE_INSTANCE')),
1517
+ _ts_param(1, (0,common_.Inject)(modules_.UtilsService)),
1518
+ _ts_param(2, (0,common_.Inject)(form_builder_config_service/* .FormBuilderConfigService */.j)),
1519
+ _ts_param(3, (0,common_.Inject)(form_builder_datasource_provider/* .FormBuilderDataSourceProvider */._)),
1520
+ _ts_metadata("design:type", Function),
1521
+ _ts_metadata("design:paramtypes", [
1522
+ typeof classes_.HybridCache === "undefined" ? Object : classes_.HybridCache,
1523
+ typeof modules_.UtilsService === "undefined" ? Object : modules_.UtilsService,
1524
+ typeof form_builder_config_service/* .FormBuilderConfigService */.j === "undefined" ? Object : form_builder_config_service/* .FormBuilderConfigService */.j,
1525
+ typeof form_builder_datasource_provider/* .FormBuilderDataSourceProvider */._ === "undefined" ? Object : form_builder_datasource_provider/* .FormBuilderDataSourceProvider */._
1526
+ ])
1527
+ ], FormService);
1528
+
1529
+
1530
+ },
1531
+ 801(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
1532
+ /**
1533
+ * Computed Field Calculation Utilities
1534
+ *
1535
+ * This module provides functions to calculate computed field values
1536
+ * based on form submission data and computed field definitions.
1537
+ *
1538
+ * NOTE: Interface definitions here mirror @flusys/ng-form-builder interfaces
1539
+ * but are defined separately to avoid cross-package dependencies.
1540
+ * Both use compatible JSON structures for form schema serialization.
1541
+ *
1542
+ * @see FLUSYS_NG/projects/ng-form-builder/interfaces/computed-field.interface.ts
1543
+ */ // ============================================================================
1544
+ // Type Definitions
1545
+ // ============================================================================
1546
+ // ============================================================================
1547
+ // Type Guards & Helpers
1548
+ // ============================================================================
1549
+ function isObject(value) {
1550
+ return typeof value === 'object' && value !== null;
1551
+ }
1552
+ function isDirectValueConfig(config) {
1553
+ return isObject(config) && config.type === 'direct' && 'value' in config;
1554
+ }
1555
+ function isFieldReferenceConfig(config) {
1556
+ return isObject(config) && config.type === 'field_reference' && 'fieldId' in config;
1557
+ }
1558
+ function isArithmeticConfig(config) {
1559
+ return isObject(config) && config.type === 'arithmetic' && 'operation' in config && 'operands' in config && Array.isArray(config.operands);
1560
+ }
1561
+ function isEmptyValue(value) {
1562
+ return value === null || value === undefined || value === '' || Array.isArray(value) && value.length === 0;
1563
+ }
1564
+ /**
1565
+ * Normalize operator to uppercase string (handles both enum and string values)
1566
+ */ function normalizeOperator(op) {
1567
+ const strOp = String(op).toUpperCase();
1568
+ return strOp === 'OR' ? 'OR' : 'AND';
1569
+ }
1570
+ /**
1571
+ * Calculate all computed fields for a form submission
1572
+ *
1573
+ * @param formData - The submitted form data (field values by field ID)
1574
+ * @param computedFields - Array of computed field definitions from form settings
1575
+ * @returns Object containing computed field values keyed by their key property
1576
+ */ function calculateComputedFields(formData, computedFields) {
1577
+ if (!computedFields || computedFields.length === 0) {
1578
+ return {};
1579
+ }
1580
+ const result = {};
1581
+ for (const field of computedFields){
1582
+ try {
1583
+ const value = calculateComputedField(formData, field);
1584
+ result[field.key] = value;
1585
+ } catch (error) {
1586
+ // If calculation fails, use default value or null
1587
+ result[field.key] = field.defaultValue ?? null;
1588
+ }
1589
+ }
1590
+ return result;
1591
+ }
1592
+ /**
1593
+ * Calculate a single computed field value
1594
+ */ function calculateComputedField(formData, field) {
1595
+ // Evaluate rules in order, first matching rule wins
1596
+ for (const rule of field.rules){
1597
+ if (evaluateCondition(formData, rule.condition)) {
1598
+ return executeComputation(formData, rule.computation, field.valueType);
1599
+ }
1600
+ }
1601
+ // No rule matched, return default
1602
+ return field.defaultValue ?? null;
1603
+ }
1604
+ /**
1605
+ * Evaluate a condition group
1606
+ */ function evaluateCondition(formData, conditionGroup) {
1607
+ // No condition = always true
1608
+ if (!conditionGroup || !conditionGroup.conditions || conditionGroup.conditions.length === 0) {
1609
+ return true;
1610
+ }
1611
+ const results = conditionGroup.conditions.map((condition)=>evaluateSingleCondition(formData, condition));
1612
+ // Normalize operator to handle both string and enum values
1613
+ const operator = normalizeOperator(conditionGroup.operator);
1614
+ if (operator === 'AND') {
1615
+ return results.every((r)=>r);
1616
+ } else {
1617
+ return results.some((r)=>r);
1618
+ }
1619
+ }
1620
+ /**
1621
+ * Evaluate a single condition
1622
+ */ function evaluateSingleCondition(formData, condition) {
1623
+ const fieldValue = formData[condition.fieldId];
1624
+ const compareValue = condition.value;
1625
+ switch(condition.comparison){
1626
+ case 'equals':
1627
+ return fieldValue === compareValue || String(fieldValue) === String(compareValue);
1628
+ case 'not_equals':
1629
+ return fieldValue !== compareValue && String(fieldValue) !== String(compareValue);
1630
+ case 'is_empty':
1631
+ return isEmptyValue(fieldValue);
1632
+ case 'is_not_empty':
1633
+ return !isEmptyValue(fieldValue);
1634
+ case 'contains':
1635
+ return String(fieldValue).includes(String(compareValue));
1636
+ case 'not_contains':
1637
+ return !String(fieldValue).includes(String(compareValue));
1638
+ case 'starts_with':
1639
+ return String(fieldValue).startsWith(String(compareValue));
1640
+ case 'ends_with':
1641
+ return String(fieldValue).endsWith(String(compareValue));
1642
+ case 'greater_than':
1643
+ return Number(fieldValue) > Number(compareValue);
1644
+ case 'less_than':
1645
+ return Number(fieldValue) < Number(compareValue);
1646
+ case 'greater_or_equal':
1647
+ return Number(fieldValue) >= Number(compareValue);
1648
+ case 'less_or_equal':
1649
+ return Number(fieldValue) <= Number(compareValue);
1650
+ case 'is_before':
1651
+ return new Date(String(fieldValue)) < new Date(String(compareValue));
1652
+ case 'is_after':
1653
+ return new Date(String(fieldValue)) > new Date(String(compareValue));
1654
+ case 'is_checked':
1655
+ return fieldValue === true || fieldValue === 'true' || fieldValue === 1;
1656
+ case 'is_not_checked':
1657
+ return fieldValue === false || fieldValue === 'false' || fieldValue === 0 || !fieldValue;
1658
+ case 'is_any_of':
1659
+ case 'in':
1660
+ return Array.isArray(compareValue) && compareValue.includes(fieldValue);
1661
+ case 'is_none_of':
1662
+ case 'not_in':
1663
+ return !Array.isArray(compareValue) || !compareValue.includes(fieldValue);
1664
+ default:
1665
+ return false;
1666
+ }
1667
+ }
1668
+ /**
1669
+ * Execute a computation and return the result
1670
+ */ function executeComputation(formData, computation, valueType) {
1671
+ const { config } = computation;
1672
+ // Use type guards for safe access
1673
+ if (computation.type === 'direct' && isDirectValueConfig(config)) {
1674
+ return valueType === 'number' ? Number(config.value) : String(config.value);
1675
+ }
1676
+ if (computation.type === 'field_reference' && isFieldReferenceConfig(config)) {
1677
+ const value = formData[config.fieldId];
1678
+ if (value === null || value === undefined) {
1679
+ return null;
1680
+ }
1681
+ return valueType === 'number' ? Number(value) : String(value);
1682
+ }
1683
+ if (computation.type === 'arithmetic' && isArithmeticConfig(config)) {
1684
+ return calculateArithmetic(formData, config);
1685
+ }
1686
+ // Unknown computation type
1687
+ return null;
1688
+ }
1689
+ /**
1690
+ * Perform arithmetic calculation
1691
+ */ function calculateArithmetic(formData, config) {
1692
+ const values = config.operands.map((operand)=>{
1693
+ if (operand.type === 'constant') {
1694
+ return operand.value ?? 0;
1695
+ } else {
1696
+ const fieldValue = formData[operand.fieldId ?? ''];
1697
+ return fieldValue !== null && fieldValue !== undefined ? Number(fieldValue) : 0;
1698
+ }
1699
+ });
1700
+ if (values.length === 0) {
1701
+ return null;
1702
+ }
1703
+ switch(config.operation){
1704
+ case 'sum':
1705
+ case 'increment':
1706
+ return values.reduce((acc, val)=>acc + val, 0);
1707
+ case 'subtract':
1708
+ case 'decrement':
1709
+ return values.reduce((acc, val, idx)=>idx === 0 ? val : acc - val, 0);
1710
+ case 'multiply':
1711
+ return values.reduce((acc, val)=>acc * val, 1);
1712
+ case 'divide':
1713
+ {
1714
+ const [first, ...rest] = values;
1715
+ return rest.reduce((acc, val)=>val !== 0 ? acc / val : acc, first);
1716
+ }
1717
+ case 'average':
1718
+ return values.reduce((acc, val)=>acc + val, 0) / values.length;
1719
+ case 'min':
1720
+ return Math.min(...values);
1721
+ case 'max':
1722
+ return Math.max(...values);
1723
+ default:
1724
+ return null;
1725
+ }
1726
+ }
1727
+
1728
+ __webpack_require__.d(__webpack_exports__, {
1729
+ X: () => (calculateComputedFields)
1730
+ });
1731
+
1732
+
1733
+ },
1734
+ 988(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
1735
+ /* import */ var _config_index_js__rspack_import_1 = __webpack_require__(137);
1736
+ /* import */ var _nestjs_common__rspack_import_0 = __webpack_require__(157);
1737
+
1738
+
1739
+ const CACHE_PREFIX = 'permissions';
1740
+ /**
1741
+ * Build permission cache key for a user
1742
+ * Uses same cache key format as PermissionGuard in nestjs-shared
1743
+ */ function buildPermissionCacheKey(user, enableCompanyFeature) {
1744
+ if (enableCompanyFeature && user.companyId) {
1745
+ return `${CACHE_PREFIX}:company:${user.companyId}:branch:${user.branchId || 'null'}:user:${user.id}`;
1746
+ }
1747
+ return `${CACHE_PREFIX}:user:${user.id}`;
1748
+ }
1749
+ /**
1750
+ * Get user permissions from cache
1751
+ * Fail-closed: if cache fails, deny access rather than allowing potentially unauthorized access
1752
+ */ async function getUserPermissionsFromCache(user, cacheManager, enableCompanyFeature) {
1753
+ const cacheKey = buildPermissionCacheKey(user, enableCompanyFeature);
1754
+ try {
1755
+ const permissions = await cacheManager.get(cacheKey);
1756
+ return permissions ?? [];
1757
+ } catch {
1758
+ throw new _nestjs_common__rspack_import_0.ForbiddenException({
1759
+ message: 'Unable to verify permissions. Please try again.',
1760
+ messageKey: _config_index_js__rspack_import_1/* .FORM_MESSAGES.PERMISSION_CHECK_FAILED */.Q.PERMISSION_CHECK_FAILED
1761
+ });
1762
+ }
1763
+ }
1764
+ /**
1765
+ * Validate user has at least one of the required permissions
1766
+ *
1767
+ * @param user - The logged-in user
1768
+ * @param requiredPermissions - Array of required permission strings (user needs at least one)
1769
+ * @param cacheManager - Cache manager instance
1770
+ * @param enableCompanyFeature - Whether company feature is enabled
1771
+ * @returns true if user has permission, false otherwise
1772
+ */ async function validateUserPermissions(user, requiredPermissions, cacheManager, enableCompanyFeature) {
1773
+ if (!requiredPermissions.length) {
1774
+ return true;
1775
+ }
1776
+ const userPermissions = await getUserPermissionsFromCache(user, cacheManager, enableCompanyFeature);
1777
+ return requiredPermissions.some((perm)=>userPermissions.includes(perm));
1778
+ }
1779
+
1780
+ __webpack_require__.d(__webpack_exports__, {
1781
+ i: () => (validateUserPermissions)
1782
+ });
1783
+
1784
+
1785
+ },
1786
+ 937(module) {
1787
+
1788
+ module.exports = __rspack_external__flusys_nestjs_shared_classes_6076a329;
1789
+
1790
+
1791
+ },
1792
+ 265(module) {
1793
+
1794
+ module.exports = __rspack_external__flusys_nestjs_shared_decorators_c129b601;
1795
+
1796
+
1797
+ },
1798
+ 873(module) {
1799
+
1800
+ module.exports = __rspack_external__flusys_nestjs_shared_dtos_c4585026;
1801
+
1802
+
1803
+ },
1804
+ 236(module) {
1805
+
1806
+ module.exports = __rspack_external__flusys_nestjs_shared_modules_24702bee;
1807
+
1808
+
1809
+ },
1810
+ 157(module) {
1811
+
1812
+ module.exports = __rspack_external__nestjs_common_a04939da;
1813
+
1814
+
1815
+ },
1816
+ 176(module) {
1817
+
1818
+ module.exports = __rspack_external__nestjs_swagger_7cd450b5;
1819
+
1820
+
1821
+ },
1822
+ 812(module) {
1823
+
1824
+ module.exports = __rspack_external_class_transformer_c5a479fb;
1825
+
1826
+
1827
+ },
1828
+ 421(module) {
1829
+
1830
+ module.exports = __rspack_external_class_validator_7b99ef4d;
1831
+
1832
+
1833
+ },
1834
+ 158(module) {
1835
+
1836
+ module.exports = __rspack_external_typeorm;
1837
+
1838
+
1839
+ },
1840
+
1841
+ };