@tstdl/base 0.92.141 → 0.92.143

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 (224) hide show
  1. package/ai/ai-file.service.js +1 -1
  2. package/ai/ai.service.js +3 -3
  3. package/ai/types.d.ts +1 -1
  4. package/api/client/client.d.ts +1 -1
  5. package/api/client/client.js +10 -4
  6. package/api/server/middlewares/content-type.middleware.js +8 -7
  7. package/api/types.js +1 -1
  8. package/authentication/client/authentication.service.js +3 -3
  9. package/authentication/server/authentication-ancillary.service.d.ts +11 -1
  10. package/authentication/server/authentication-ancillary.service.js +1 -1
  11. package/authentication/server/authentication-secret-requirements.validator.js +1 -1
  12. package/authentication/server/authentication.api-controller.js +22 -10
  13. package/authentication/server/authentication.service.d.ts +11 -5
  14. package/authentication/server/authentication.service.js +97 -49
  15. package/authentication/server/drizzle.config.js +2 -2
  16. package/authentication/server/module.js +1 -1
  17. package/cancellation/token.d.ts +2 -2
  18. package/cancellation/token.js +4 -4
  19. package/cookie/cookie.js +2 -2
  20. package/css/css-variables.js +1 -1
  21. package/document-management/api/document-management.api.d.ts +122 -24
  22. package/document-management/api/document-management.api.js +17 -0
  23. package/document-management/{server/services → authorization}/document-management-authorization.service.d.ts +7 -7
  24. package/document-management/authorization/document-management-authorization.service.js +2 -0
  25. package/document-management/authorization/index.d.ts +2 -0
  26. package/document-management/authorization/index.js +2 -0
  27. package/document-management/authorization/policies.d.ts +38 -0
  28. package/document-management/authorization/policies.js +2 -0
  29. package/document-management/index.d.ts +1 -0
  30. package/document-management/index.js +1 -0
  31. package/document-management/models/document-assignment-scope.model.d.ts +1 -0
  32. package/document-management/models/document-assignment-scope.model.js +10 -3
  33. package/document-management/models/document-assignment-task.model.d.ts +1 -0
  34. package/document-management/models/document-assignment-task.model.js +8 -2
  35. package/document-management/models/document-category.model.d.ts +1 -0
  36. package/document-management/models/document-category.model.js +7 -1
  37. package/document-management/models/document-collection-assignment.model.d.ts +1 -0
  38. package/document-management/models/document-collection-assignment.model.js +12 -4
  39. package/document-management/models/document-collection.model.d.ts +2 -0
  40. package/document-management/models/document-collection.model.js +8 -2
  41. package/document-management/models/document-management-table.d.ts +3 -1
  42. package/document-management/models/document-management-table.js +2 -2
  43. package/document-management/models/document-property-value.model.d.ts +1 -0
  44. package/document-management/models/document-property-value.model.js +9 -3
  45. package/document-management/models/document-property.model.d.ts +1 -0
  46. package/document-management/models/document-property.model.js +8 -2
  47. package/document-management/models/document-request-collection-assignment.model.d.ts +1 -0
  48. package/document-management/models/document-request-collection-assignment.model.js +12 -4
  49. package/document-management/models/document-request-template.d.ts +1 -0
  50. package/document-management/models/document-request-template.js +6 -1
  51. package/document-management/models/document-request.model.d.ts +1 -0
  52. package/document-management/models/document-request.model.js +10 -1
  53. package/document-management/models/document-requests-template.d.ts +1 -0
  54. package/document-management/models/document-requests-template.js +7 -3
  55. package/document-management/models/document-tag-assignment.model.d.ts +8 -0
  56. package/document-management/models/document-tag-assignment.model.js +40 -0
  57. package/document-management/models/document-tag.model.d.ts +6 -0
  58. package/document-management/models/{document-request-submission.model.js → document-tag.model.js} +14 -18
  59. package/document-management/models/document-type-property.model.d.ts +1 -0
  60. package/document-management/models/document-type-property.model.js +7 -2
  61. package/document-management/models/document-type-validation.model.d.ts +1 -0
  62. package/document-management/models/document-type-validation.model.js +8 -2
  63. package/document-management/models/document-type.model.d.ts +1 -0
  64. package/document-management/models/document-type.model.js +7 -2
  65. package/document-management/models/document-validation-definition.model.d.ts +1 -0
  66. package/document-management/models/document-validation-definition.model.js +7 -2
  67. package/document-management/models/document-validation-execution-related-document.model.d.ts +1 -0
  68. package/document-management/models/document-validation-execution-related-document.model.js +10 -3
  69. package/document-management/models/document-validation-execution.model.d.ts +1 -0
  70. package/document-management/models/document-validation-execution.model.js +9 -3
  71. package/document-management/models/document-workflow.model.d.ts +4 -1
  72. package/document-management/models/document-workflow.model.js +16 -4
  73. package/document-management/models/document.model.d.ts +2 -2
  74. package/document-management/models/document.model.js +9 -8
  75. package/document-management/models/index.d.ts +2 -1
  76. package/document-management/models/index.js +2 -1
  77. package/document-management/server/api/document-management.api.d.ts +4 -1
  78. package/document-management/server/api/document-management.api.js +113 -22
  79. package/document-management/server/configure.d.ts +2 -2
  80. package/document-management/server/configure.js +7 -7
  81. package/document-management/server/drizzle/0000_parallel_mantis.sql +359 -0
  82. package/document-management/server/drizzle/meta/0000_snapshot.json +784 -260
  83. package/document-management/server/drizzle/meta/_journal.json +2 -2
  84. package/document-management/server/module.d.ts +2 -2
  85. package/document-management/server/module.js +2 -2
  86. package/document-management/server/schemas.d.ts +6 -5
  87. package/document-management/server/schemas.js +12 -11
  88. package/document-management/server/services/document-category-type.service.d.ts +19 -10
  89. package/document-management/server/services/document-category-type.service.js +34 -27
  90. package/document-management/server/services/document-collection.service.d.ts +13 -6
  91. package/document-management/server/services/document-collection.service.js +36 -12
  92. package/document-management/server/services/document-file.service.d.ts +8 -7
  93. package/document-management/server/services/document-file.service.js +28 -33
  94. package/document-management/server/services/document-management-ai.service.d.ts +5 -4
  95. package/document-management/server/services/document-management-ai.service.js +51 -28
  96. package/document-management/server/services/document-management-ancillary.service.d.ts +3 -21
  97. package/document-management/server/services/document-management-ancillary.service.js +0 -24
  98. package/document-management/server/services/document-management-observation.service.d.ts +15 -0
  99. package/document-management/server/services/document-management-observation.service.js +160 -0
  100. package/document-management/server/services/document-management.service.d.ts +6 -5
  101. package/document-management/server/services/document-management.service.js +112 -86
  102. package/document-management/server/services/document-property.service.d.ts +15 -7
  103. package/document-management/server/services/document-property.service.js +52 -20
  104. package/document-management/server/services/document-request.service.d.ts +13 -24
  105. package/document-management/server/services/document-request.service.js +39 -62
  106. package/document-management/server/services/document-tag.service.d.ts +10 -0
  107. package/document-management/server/services/document-tag.service.js +59 -0
  108. package/document-management/server/services/document-validation.service.d.ts +8 -8
  109. package/document-management/server/services/document-validation.service.js +41 -40
  110. package/document-management/server/services/document-workflow.service.d.ts +6 -5
  111. package/document-management/server/services/document-workflow.service.js +54 -43
  112. package/document-management/server/services/document.service.d.ts +12 -11
  113. package/document-management/server/services/document.service.js +64 -40
  114. package/document-management/server/services/index.d.ts +2 -1
  115. package/document-management/server/services/index.js +2 -1
  116. package/document-management/server/services/singleton.js +2 -2
  117. package/document-management/server/validators/ai-validation-executor.js +4 -4
  118. package/document-management/service-models/document-collection-metadata.service-model.d.ts +14 -0
  119. package/document-management/service-models/document-collection-metadata.service-model.js +1 -0
  120. package/document-management/service-models/document-folders.view-model.d.ts +1 -7
  121. package/document-management/service-models/document-folders.view-model.js +3 -15
  122. package/document-management/service-models/document-management.view-model.d.ts +20 -6
  123. package/document-management/service-models/document-management.view-model.js +62 -8
  124. package/document-management/service-models/document.service-model.d.ts +14 -11
  125. package/document-management/service-models/document.service-model.js +11 -2
  126. package/document-management/service-models/enriched/enriched-document-assignment.view.d.ts +1 -1
  127. package/document-management/service-models/enriched/enriched-document-assignment.view.js +0 -2
  128. package/document-management/service-models/enriched/enriched-document-category.view.d.ts +11 -1
  129. package/document-management/service-models/enriched/enriched-document-category.view.js +44 -1
  130. package/document-management/service-models/enriched/enriched-document-collection.view.d.ts +4 -2
  131. package/document-management/service-models/enriched/enriched-document-collection.view.js +13 -3
  132. package/document-management/service-models/enriched/enriched-document-management-data.view.d.ts +2 -0
  133. package/document-management/service-models/enriched/enriched-document-management-data.view.js +4 -2
  134. package/document-management/service-models/enriched/enriched-document-request.view.d.ts +1 -0
  135. package/document-management/service-models/enriched/enriched-document-request.view.js +2 -0
  136. package/document-management/service-models/enriched/enriched-document-type.view.d.ts +9 -1
  137. package/document-management/service-models/enriched/enriched-document-type.view.js +28 -1
  138. package/document-management/service-models/enriched/enriched-document.view.d.ts +7 -6
  139. package/document-management/service-models/enriched/enriched-document.view.js +29 -6
  140. package/document-management/service-models/{normalized-requests-template-data.model.d.ts → enriched/enriched-requests-template-data.model.d.ts} +6 -6
  141. package/document-management/service-models/{normalized-requests-template-data.model.js → enriched/enriched-requests-template-data.model.js} +1 -1
  142. package/document-management/service-models/enriched/index.d.ts +1 -0
  143. package/document-management/service-models/enriched/index.js +1 -0
  144. package/document-management/service-models/index.d.ts +2 -2
  145. package/document-management/service-models/index.js +2 -2
  146. package/examples/document-management/categories-and-types.d.ts +33 -31
  147. package/examples/document-management/categories-and-types.js +33 -0
  148. package/examples/document-management/main.d.ts +5 -4
  149. package/examples/document-management/main.js +13 -7
  150. package/function/log.js +2 -2
  151. package/http/server/node/module.d.ts +4 -1
  152. package/http/server/node/module.js +10 -1
  153. package/http/server/node/node-http-server.d.ts +3 -6
  154. package/http/server/node/node-http-server.js +68 -67
  155. package/injector/inject.js +6 -6
  156. package/injector/injector.js +3 -3
  157. package/jsx/is-component-class.js +1 -1
  158. package/key-value-store/key-value.store.d.ts +38 -7
  159. package/key-value-store/key-value.store.js +2 -1
  160. package/key-value-store/mongo/mongo-key-value.store.d.ts +1 -0
  161. package/key-value-store/mongo/mongo-key-value.store.js +14 -5
  162. package/key-value-store/postgres/drizzle/0000_shocking_slipstream.sql +12 -0
  163. package/key-value-store/postgres/drizzle/meta/0000_snapshot.json +97 -0
  164. package/key-value-store/postgres/drizzle/meta/_journal.json +13 -0
  165. package/key-value-store/postgres/drizzle.config.d.ts +2 -0
  166. package/key-value-store/postgres/drizzle.config.js +11 -0
  167. package/key-value-store/postgres/index.d.ts +2 -0
  168. package/key-value-store/postgres/index.js +2 -0
  169. package/key-value-store/postgres/key-value-store.service.d.ts +17 -0
  170. package/key-value-store/postgres/key-value-store.service.js +65 -0
  171. package/key-value-store/postgres/models/index.d.ts +2 -0
  172. package/key-value-store/postgres/models/index.js +2 -0
  173. package/key-value-store/postgres/models/key-value.model.d.ts +7 -0
  174. package/key-value-store/postgres/models/key-value.model.js +35 -0
  175. package/key-value-store/postgres/models/schemas.d.ts +3 -0
  176. package/key-value-store/postgres/models/schemas.js +4 -0
  177. package/key-value-store/postgres/module.d.ts +6 -0
  178. package/key-value-store/postgres/module.js +23 -0
  179. package/lock/web/web-lock.d.ts +0 -1
  180. package/lock/web/web-lock.js +6 -13
  181. package/orm/data-types/timestamp.js +1 -1
  182. package/orm/decorators.d.ts +37 -29
  183. package/orm/decorators.js +44 -24
  184. package/orm/entity.d.ts +1 -0
  185. package/orm/query.d.ts +10 -2
  186. package/orm/repository.types.d.ts +2 -1
  187. package/orm/schemas/json.d.ts +12 -6
  188. package/orm/schemas/json.js +12 -5
  189. package/orm/server/database.js +5 -2
  190. package/orm/server/drizzle/schema-converter.js +40 -11
  191. package/orm/server/query-converter.d.ts +2 -1
  192. package/orm/server/query-converter.js +57 -34
  193. package/orm/server/repository.d.ts +26 -43
  194. package/orm/server/repository.js +106 -39
  195. package/orm/server/transaction.d.ts +2 -1
  196. package/orm/server/transaction.js +3 -0
  197. package/orm/server/transactional.d.ts +5 -1
  198. package/orm/server/transactional.js +34 -4
  199. package/package.json +14 -11
  200. package/process/spawn.js +0 -1
  201. package/promise/deferred-promise.d.ts +4 -3
  202. package/promise/deferred-promise.js +13 -5
  203. package/queue/postgres/queue.js +8 -8
  204. package/reflection/utils.js +3 -3
  205. package/schema/decorators/class.js +0 -1
  206. package/schema/decorators/schema.js +1 -1
  207. package/schema/schemas/boolean.d.ts +1 -1
  208. package/schema/schemas/boolean.js +2 -2
  209. package/schema/schemas/number.js +3 -3
  210. package/schema/schemas/object.js +5 -6
  211. package/sse/server-sent-events-source.js +4 -1
  212. package/utils/compression.js +9 -9
  213. package/utils/date-time.d.ts +1 -0
  214. package/utils/date-time.js +18 -4
  215. package/utils/equals.d.ts +7 -0
  216. package/utils/equals.js +17 -2
  217. package/utils/function/memoize.js +10 -2
  218. package/utils/jwt.js +3 -3
  219. package/utils/object/property-name.d.ts +2 -2
  220. package/utils/timing.d.ts +2 -2
  221. package/utils/timing.js +12 -12
  222. package/document-management/models/document-request-submission.model.d.ts +0 -7
  223. package/document-management/server/drizzle/0000_moaning_luckman.sql +0 -305
  224. package/document-management/server/services/document-management-authorization.service.js +0 -28
@@ -7,16 +7,21 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- import { References } from '../../orm/decorators.js';
10
+ import { ForeignKey, References } from '../../orm/decorators.js';
11
11
  import { Entity } from '../../orm/entity.js';
12
12
  import { Unique, Uuid } from '../../orm/types.js';
13
13
  import { DocumentManagementTable } from './document-management-table.js';
14
14
  import { DocumentValidationExecution } from './document-validation-execution.model.js';
15
15
  import { Document } from './document.model.js';
16
16
  let DocumentValidationExecutionRelatedDocument = class DocumentValidationExecutionRelatedDocument extends Entity {
17
+ tenantId;
17
18
  executionId;
18
19
  documentId;
19
20
  };
21
+ __decorate([
22
+ Uuid(),
23
+ __metadata("design:type", String)
24
+ ], DocumentValidationExecutionRelatedDocument.prototype, "tenantId", void 0);
20
25
  __decorate([
21
26
  Uuid(),
22
27
  References(() => DocumentValidationExecution),
@@ -28,7 +33,9 @@ __decorate([
28
33
  __metadata("design:type", String)
29
34
  ], DocumentValidationExecutionRelatedDocument.prototype, "documentId", void 0);
30
35
  DocumentValidationExecutionRelatedDocument = __decorate([
31
- DocumentManagementTable(),
32
- Unique(['executionId', 'documentId'], { naming: 'abbreviated-table' })
36
+ DocumentManagementTable({ name: 'validation_execution_related_document' }),
37
+ Unique(['tenantId', 'executionId', 'documentId']),
38
+ ForeignKey(() => DocumentValidationExecution, ['tenantId', 'executionId'], ['tenantId', 'id']),
39
+ ForeignKey(() => Document, ['tenantId', 'documentId'], ['tenantId', 'id'])
33
40
  ], DocumentValidationExecutionRelatedDocument);
34
41
  export { DocumentValidationExecutionRelatedDocument };
@@ -16,6 +16,7 @@ export declare const DocumentValidationResultStatus: {
16
16
  export type DocumentValidationResultStatus = EnumType<typeof DocumentValidationResultStatus>;
17
17
  export declare class DocumentValidationExecution extends Entity {
18
18
  static readonly entityName: 'DocumentValidationExecution';
19
+ tenantId: Uuid;
19
20
  workflowId: Uuid;
20
21
  definitionId: Uuid;
21
22
  state: DocumentValidationExecutionState;
@@ -8,7 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
10
  import { defineEnum } from '../../enumeration/enumeration.js';
11
- import { References } from '../../orm/decorators.js';
11
+ import { ForeignKey, References } from '../../orm/decorators.js';
12
12
  import { Entity } from '../../orm/entity.js';
13
13
  import { Timestamp, Unique, Uuid } from '../../orm/types.js';
14
14
  import { Enumeration, StringProperty } from '../../schema/index.js';
@@ -27,6 +27,7 @@ export const DocumentValidationResultStatus = defineEnum('DocumentValidationResu
27
27
  Warning: 'warning',
28
28
  });
29
29
  let DocumentValidationExecution = class DocumentValidationExecution extends Entity {
30
+ tenantId;
30
31
  workflowId;
31
32
  definitionId;
32
33
  state;
@@ -35,6 +36,10 @@ let DocumentValidationExecution = class DocumentValidationExecution extends Enti
35
36
  startedAt;
36
37
  completedAt;
37
38
  };
39
+ __decorate([
40
+ Uuid(),
41
+ __metadata("design:type", String)
42
+ ], DocumentValidationExecution.prototype, "tenantId", void 0);
38
43
  __decorate([
39
44
  Uuid(),
40
45
  References(() => DocumentWorkflow),
@@ -66,7 +71,8 @@ __decorate([
66
71
  __metadata("design:type", Object)
67
72
  ], DocumentValidationExecution.prototype, "completedAt", void 0);
68
73
  DocumentValidationExecution = __decorate([
69
- DocumentManagementTable(),
70
- Unique(['workflowId', 'definitionId'])
74
+ DocumentManagementTable({ name: 'validation_execution' }),
75
+ Unique(['tenantId', 'workflowId', 'definitionId']),
76
+ ForeignKey(() => DocumentWorkflow, ['tenantId', 'workflowId'], ['tenantId', 'id'])
71
77
  ], DocumentValidationExecution);
72
78
  export { DocumentValidationExecution };
@@ -1,6 +1,6 @@
1
1
  import { type EnumType } from '../../enumeration/enumeration.js';
2
2
  import { Entity } from '../../orm/entity.js';
3
- import { Uuid } from '../../orm/types.js';
3
+ import { Timestamp, Uuid } from '../../orm/types.js';
4
4
  export declare const DocumentWorkflowStep: {
5
5
  readonly Classification: "classification";
6
6
  readonly Extraction: "extraction";
@@ -11,6 +11,7 @@ export type DocumentWorkflowStep = EnumType<typeof DocumentWorkflowStep>;
11
11
  export declare const DocumentWorkflowState: {
12
12
  readonly Pending: "pending";
13
13
  readonly Running: "running";
14
+ readonly Review: "review";
14
15
  readonly Completed: "completed";
15
16
  /** Unexpected error happened */
16
17
  readonly Error: "error";
@@ -27,9 +28,11 @@ export declare const DocumentWorkflowFailReason: {
27
28
  export type DocumentWorkflowFailReason = EnumType<typeof DocumentWorkflowFailReason>;
28
29
  export declare class DocumentWorkflow extends Entity {
29
30
  static readonly entityName: 'DocumentWorkflow';
31
+ tenantId: Uuid;
30
32
  documentId: Uuid;
31
33
  step: DocumentWorkflowStep;
32
34
  state: DocumentWorkflowState;
33
35
  failReason: DocumentWorkflowFailReason | null;
36
+ completeTimestamp: Timestamp | null;
34
37
  completeUserId: Uuid | null;
35
38
  }
@@ -8,9 +8,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
10
  import { defineEnum } from '../../enumeration/enumeration.js';
11
- import { References } from '../../orm/decorators.js';
11
+ import { ForeignKey, References } from '../../orm/decorators.js';
12
12
  import { Entity } from '../../orm/entity.js';
13
- import { Index, Uuid } from '../../orm/types.js';
13
+ import { Index, Timestamp, Uuid } from '../../orm/types.js';
14
14
  import { Enumeration } from '../../schema/index.js';
15
15
  import { DocumentManagementTable } from './document-management-table.js';
16
16
  import { Document } from './document.model.js';
@@ -23,6 +23,7 @@ export const DocumentWorkflowStep = defineEnum('DocumentWorkflowStep', {
23
23
  export const DocumentWorkflowState = defineEnum('DocumentWorkflowState', {
24
24
  Pending: 'pending',
25
25
  Running: 'running',
26
+ Review: 'review',
26
27
  Completed: 'completed',
27
28
  /** Unexpected error happened */
28
29
  Error: 'error',
@@ -36,12 +37,18 @@ export const DocumentWorkflowFailReason = defineEnum('DocumentWorkflowFailReason
36
37
  NoSuitableRequest: 'no-suitable-request',
37
38
  });
38
39
  let DocumentWorkflow = class DocumentWorkflow extends Entity {
40
+ tenantId;
39
41
  documentId;
40
42
  step;
41
43
  state;
42
44
  failReason;
45
+ completeTimestamp;
43
46
  completeUserId;
44
47
  };
48
+ __decorate([
49
+ Uuid(),
50
+ __metadata("design:type", String)
51
+ ], DocumentWorkflow.prototype, "tenantId", void 0);
45
52
  __decorate([
46
53
  Uuid(),
47
54
  References(() => Document),
@@ -59,12 +66,17 @@ __decorate([
59
66
  Enumeration(DocumentWorkflowFailReason, { nullable: true }),
60
67
  __metadata("design:type", Object)
61
68
  ], DocumentWorkflow.prototype, "failReason", void 0);
69
+ __decorate([
70
+ Timestamp({ nullable: true }),
71
+ __metadata("design:type", Object)
72
+ ], DocumentWorkflow.prototype, "completeTimestamp", void 0);
62
73
  __decorate([
63
74
  Uuid({ nullable: true }),
64
75
  __metadata("design:type", Object)
65
76
  ], DocumentWorkflow.prototype, "completeUserId", void 0);
66
77
  DocumentWorkflow = __decorate([
67
- DocumentManagementTable(),
68
- Index(['documentId'], { unique: true, where: () => ({ state: { $neq: DocumentWorkflowState.Completed } }) })
78
+ DocumentManagementTable({ name: 'workflow' }),
79
+ Index(['documentId'], { unique: true, where: () => ({ state: { $neq: DocumentWorkflowState.Completed } }) }),
80
+ ForeignKey(() => Document, ['tenantId', 'documentId'], ['tenantId', 'id'])
69
81
  ], DocumentWorkflow);
70
82
  export { DocumentWorkflow };
@@ -7,16 +7,16 @@ export declare const DocumentApproval: {
7
7
  readonly Rejected: "rejected";
8
8
  };
9
9
  export type DocumentApproval = EnumType<typeof DocumentApproval>;
10
- export type UpdatableDocumentProperties = keyof Pick<Document, 'typeId' | 'title' | 'subtitle' | 'date' | 'summary' | 'tags' | 'comment'>;
10
+ export type UpdatableDocumentProperties = keyof Pick<Document, 'typeId' | 'title' | 'subtitle' | 'date' | 'summary' | 'comment'>;
11
11
  export declare class Document extends Entity {
12
12
  static readonly entityName: 'Document';
13
+ tenantId: Uuid;
13
14
  typeId: Uuid | null;
14
15
  title: string | null;
15
16
  subtitle: string | null;
16
17
  pages: number | null;
17
18
  date: NumericDate | null;
18
19
  summary: string | null;
19
- tags: string[] | null;
20
20
  approval: DocumentApproval;
21
21
  comment: string | null;
22
22
  originalFileName: string | null;
@@ -10,8 +10,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  import { defineEnum } from '../../enumeration/enumeration.js';
11
11
  import { References } from '../../orm/decorators.js';
12
12
  import { Entity } from '../../orm/entity.js';
13
- import { NumericDate, Uuid } from '../../orm/types.js';
14
- import { Array, Enumeration, Integer, string, StringProperty } from '../../schema/index.js';
13
+ import { NumericDate, Unique, Uuid } from '../../orm/types.js';
14
+ import { Enumeration, Integer, StringProperty } from '../../schema/index.js';
15
15
  import { DocumentManagementTable } from './document-management-table.js';
16
16
  import { DocumentType } from './document-type.model.js';
17
17
  export const DocumentApproval = defineEnum('DocumentApproval', {
@@ -20,13 +20,13 @@ export const DocumentApproval = defineEnum('DocumentApproval', {
20
20
  Rejected: 'rejected',
21
21
  });
22
22
  let Document = class Document extends Entity {
23
+ tenantId;
23
24
  typeId;
24
25
  title;
25
26
  subtitle;
26
27
  pages;
27
28
  date;
28
29
  summary;
29
- tags;
30
30
  approval;
31
31
  comment;
32
32
  originalFileName;
@@ -35,6 +35,10 @@ let Document = class Document extends Entity {
35
35
  size;
36
36
  createUserId;
37
37
  };
38
+ __decorate([
39
+ Uuid(),
40
+ __metadata("design:type", String)
41
+ ], Document.prototype, "tenantId", void 0);
38
42
  __decorate([
39
43
  Uuid({ nullable: true }),
40
44
  References(() => DocumentType),
@@ -60,10 +64,6 @@ __decorate([
60
64
  StringProperty({ nullable: true }),
61
65
  __metadata("design:type", Object)
62
66
  ], Document.prototype, "summary", void 0);
63
- __decorate([
64
- Array(string(), { nullable: true }),
65
- __metadata("design:type", Object)
66
- ], Document.prototype, "tags", void 0);
67
67
  __decorate([
68
68
  Enumeration(DocumentApproval),
69
69
  __metadata("design:type", String)
@@ -93,6 +93,7 @@ __decorate([
93
93
  __metadata("design:type", Object)
94
94
  ], Document.prototype, "createUserId", void 0);
95
95
  Document = __decorate([
96
- DocumentManagementTable()
96
+ DocumentManagementTable(),
97
+ Unique(['tenantId', 'id'])
97
98
  ], Document);
98
99
  export { Document };
@@ -7,10 +7,11 @@ export * from './document-management-table.js';
7
7
  export * from './document-property-value.model.js';
8
8
  export * from './document-property.model.js';
9
9
  export * from './document-request-collection-assignment.model.js';
10
- export * from './document-request-submission.model.js';
11
10
  export * from './document-request-template.js';
12
11
  export * from './document-request.model.js';
13
12
  export * from './document-requests-template.js';
13
+ export * from './document-tag-assignment.model.js';
14
+ export * from './document-tag.model.js';
14
15
  export * from './document-type-property.model.js';
15
16
  export * from './document-type-validation.model.js';
16
17
  export * from './document-type.model.js';
@@ -7,10 +7,11 @@ export * from './document-management-table.js';
7
7
  export * from './document-property-value.model.js';
8
8
  export * from './document-property.model.js';
9
9
  export * from './document-request-collection-assignment.model.js';
10
- export * from './document-request-submission.model.js';
11
10
  export * from './document-request-template.js';
12
11
  export * from './document-request.model.js';
13
12
  export * from './document-requests-template.js';
13
+ export * from './document-tag-assignment.model.js';
14
+ export * from './document-tag.model.js';
14
15
  export * from './document-type-property.model.js';
15
16
  export * from './document-type-validation.model.js';
16
17
  export * from './document-type.model.js';
@@ -26,5 +26,8 @@ export declare class DocumentManagementApiController implements ApiController<Do
26
26
  deleteDocumentRequest(_context: ApiRequestContext<DocumentManagementApiDefinition, 'deleteDocumentRequest'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'deleteDocumentRequest'>>;
27
27
  assignDocumentToCollection(_context: ApiRequestContext<DocumentManagementApiDefinition, 'assignDocumentToCollection'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'assignDocumentToCollection'>>;
28
28
  archiveDocumentInCollection(_context: ApiRequestContext<DocumentManagementApiDefinition, 'archiveDocumentInCollection'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'archiveDocumentInCollection'>>;
29
- updateDocument(_context: ApiRequestContext<DocumentManagementApiDefinition, 'updateDocument'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'updateDocument'>>;
29
+ updateDocument({ parameters, getToken }: ApiRequestContext<DocumentManagementApiDefinition, 'updateDocument'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'updateDocument'>>;
30
+ proceedDocumentWorkflow({ parameters, getToken }: ApiRequestContext<DocumentManagementApiDefinition, 'proceedDocumentWorkflow'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'proceedDocumentWorkflow'>>;
31
+ testAuthorization({ parameters, getToken }: ApiRequestContext<DocumentManagementApiDefinition, 'testAuthorization'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'testAuthorization'>>;
32
+ private canReadDocument;
30
33
  }
@@ -6,10 +6,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  var _a;
8
8
  var DocumentManagementApiController_1;
9
+ import { create as createDiffPatch } from 'jsondiffpatch';
9
10
  import { match, P } from 'ts-pattern';
10
11
  import { createErrorResponse } from '../../../api/index.js';
11
12
  import { apiController } from '../../../api/server/index.js';
13
+ import { CancellationSignal } from '../../../cancellation/token.js';
12
14
  import { documentManagementApiDefinition } from '../../../document-management/api/index.js';
15
+ import { DocumentManagementAuthorizationService } from '../../../document-management/authorization/index.js';
13
16
  import { DocumentRequestCollectionAssignment } from '../../../document-management/models/document-request-collection-assignment.model.js';
14
17
  import { ForbiddenError, NotImplementedError } from '../../../errors/index.js';
15
18
  import { HttpServerResponse } from '../../../http/index.js';
@@ -19,40 +22,68 @@ import { injectRepository } from '../../../orm/server/repository.js';
19
22
  import { ServerSentEventsSource } from '../../../sse/server-sent-events-source.js';
20
23
  import { toArray } from '../../../utils/array/index.js';
21
24
  import { tryIgnoreAsync } from '../../../utils/try-ignore.js';
22
- import { DocumentCategoryTypeService, DocumentFileService, DocumentManagementAuthorizationService, DocumentManagementService, DocumentRequestService, DocumentService } from '../services/index.js';
25
+ import { isDefined, isUndefined } from '../../../utils/type-guards.js';
26
+ import { DocumentCategoryTypeService, DocumentFileService, DocumentManagementService, DocumentRequestService, DocumentService, DocumentWorkflowService } from '../services/index.js';
27
+ const jsonDiffPatch = createDiffPatch({
28
+ omitRemovedValues: true,
29
+ arrays: {
30
+ detectMove: true,
31
+ includeValueOnMove: false,
32
+ },
33
+ objectHash(item, index) {
34
+ return item['id'] ?? String(index);
35
+ },
36
+ });
23
37
  let DocumentManagementApiController = DocumentManagementApiController_1 = class DocumentManagementApiController {
38
+ #documentManagementService = inject(DocumentManagementService);
24
39
  #authorizationService = inject(DocumentManagementAuthorizationService);
25
40
  #documentCategoryTypeService = inject(DocumentCategoryTypeService);
26
41
  #documentFileService = inject(DocumentFileService);
27
- #documentManagementService = inject(DocumentManagementService);
28
42
  #documentRequestService = inject(DocumentRequestService);
29
43
  #documentRequestCollectionAssignmentRepository = injectRepository(DocumentRequestCollectionAssignment);
30
44
  #documentService = inject(DocumentService);
45
+ #workflowService = inject(DocumentWorkflowService);
46
+ #cancellationSignal = inject(CancellationSignal);
31
47
  #logger = inject(Logger, DocumentManagementApiController_1.name);
32
48
  async loadData(context) {
33
49
  const token = await context.getToken();
50
+ const tenantId = await this.#authorizationService.getTenantId(token);
34
51
  for (const collectionId of context.parameters.collectionIds) {
35
52
  const allowed = await this.#authorizationService.canReadCollection(collectionId, token);
36
53
  if (!allowed) {
37
54
  throw new ForbiddenError(`You are not allowed to read collection ${collectionId}`);
38
55
  }
39
56
  }
40
- return await this.#documentManagementService.loadData(toArray(context.parameters.collectionIds));
57
+ return await this.#documentManagementService.loadData(tenantId, toArray(context.parameters.collectionIds));
41
58
  }
42
59
  async loadDataStream(context) {
43
60
  const token = await context.getToken();
61
+ const tenantId = await this.#authorizationService.getTenantId(token);
44
62
  for (const collectionId of context.parameters.collectionIds) {
45
63
  const allowed = await this.#authorizationService.canReadCollection(collectionId, token);
46
64
  if (!allowed) {
47
65
  throw new ForbiddenError(`You are not allowed to read collection ${collectionId}`);
48
66
  }
49
67
  }
50
- const stream = this.#documentManagementService.loadDataStream(toArray(context.parameters.collectionIds));
68
+ const stream = this.#documentManagementService.loadDataStream(tenantId, toArray(context.parameters.collectionIds), this.#cancellationSignal);
51
69
  const eventSource = new ServerSentEventsSource();
52
70
  void (async () => {
71
+ let lastData;
53
72
  try {
54
- for await (const chunk of stream) {
55
- await eventSource.sendJson({ name: 'data', data: chunk });
73
+ for await (const data of stream) {
74
+ if (eventSource.closed()) {
75
+ break;
76
+ }
77
+ if (isUndefined(lastData)) {
78
+ await eventSource.sendJson({ name: 'data', data });
79
+ }
80
+ else {
81
+ const delta = jsonDiffPatch.diff(lastData, data);
82
+ if (isDefined(delta)) {
83
+ await eventSource.sendJson({ name: 'delta', data: delta });
84
+ }
85
+ }
86
+ lastData = data;
56
87
  }
57
88
  }
58
89
  catch (error) {
@@ -60,70 +91,81 @@ let DocumentManagementApiController = DocumentManagementApiController_1 = class
60
91
  await tryIgnoreAsync(async () => await eventSource.sendJson({ name: 'error', data: createErrorResponse(error).error }));
61
92
  await tryIgnoreAsync(async () => await eventSource.close());
62
93
  }
94
+ finally {
95
+ await tryIgnoreAsync(async () => await eventSource.close());
96
+ }
63
97
  })();
64
98
  return eventSource;
65
99
  }
66
100
  async loadDocumentRequestsTemplateData(context) {
67
101
  const token = await context.getToken();
102
+ const tenantId = await this.#authorizationService.getTenantId(token);
68
103
  const allowed = await this.#authorizationService.canReadDocumentRequestsTemplates(token);
69
104
  if (!allowed) {
70
105
  throw new ForbiddenError('You are not allowed to load document requests template data.');
71
106
  }
72
- return await this.#documentManagementService.loadDocumentRequestsTemplateData();
107
+ return await this.#documentManagementService.loadDocumentRequestsTemplateData(tenantId);
73
108
  }
74
109
  async loadAvailableCategories(context) {
75
110
  const token = await context.getToken();
76
- return await this.#documentCategoryTypeService.loadCategoryViews();
111
+ const tenantId = await this.#authorizationService.getTenantId(token);
112
+ return await this.#documentCategoryTypeService.loadCategoryViews(tenantId);
77
113
  }
78
114
  async loadContent(context) {
79
115
  const token = await context.getToken();
80
- const allowed = await this.#authorizationService.canReadDocument(context.parameters.id, token);
116
+ const tenantId = await this.#authorizationService.getTenantId(token);
117
+ const allowed = await this.canReadDocument(tenantId, context.parameters.id, token);
81
118
  if (!allowed) {
82
119
  throw new ForbiddenError(`You are not allowed to load content for document ${context.parameters.id}.`);
83
120
  }
84
- const url = await this.#documentService.getContentUrl(context.parameters.id, context.parameters.download);
121
+ const url = await this.#documentService.getContentUrl(tenantId, context.parameters.id, context.parameters.download);
85
122
  return HttpServerResponse.redirect(url);
86
123
  }
87
124
  async getContentUrl(context) {
88
125
  const token = await context.getToken();
89
- const allowed = await this.#authorizationService.canReadDocument(context.parameters.id, token);
126
+ const tenantId = await this.#authorizationService.getTenantId(token);
127
+ const allowed = await this.canReadDocument(tenantId, context.parameters.id, token);
90
128
  if (!allowed) {
91
129
  throw new ForbiddenError(`You are not allowed to get content URL for document ${context.parameters.id}.`);
92
130
  }
93
- return await this.#documentService.getContentUrl(context.parameters.id, context.parameters.download);
131
+ return await this.#documentService.getContentUrl(tenantId, context.parameters.id, context.parameters.download);
94
132
  }
95
133
  async loadPreview(context) {
96
134
  const token = await context.getToken();
97
- const allowed = await this.#authorizationService.canReadDocument(context.parameters.id, token);
135
+ const tenantId = await this.#authorizationService.getTenantId(token);
136
+ const allowed = await this.canReadDocument(tenantId, context.parameters.id, token);
98
137
  if (!allowed) {
99
138
  throw new ForbiddenError(`You are not allowed to get content preview for document ${context.parameters.id}.`);
100
139
  }
101
- const url = await this.#documentService.getPreviewUrl(context.parameters.id, context.parameters.page);
140
+ const url = await this.#documentService.getPreviewUrl(tenantId, context.parameters.id, context.parameters.page);
102
141
  return HttpServerResponse.redirect(url);
103
142
  }
104
143
  async getPreviewUrl(context) {
105
144
  const token = await context.getToken();
106
- const allowed = await this.#authorizationService.canReadDocument(context.parameters.id, token);
145
+ const tenantId = await this.#authorizationService.getTenantId(token);
146
+ const allowed = await this.canReadDocument(tenantId, context.parameters.id, token);
107
147
  if (!allowed) {
108
148
  throw new ForbiddenError(`You are not allowed to get content preview for document ${context.parameters.id}.`);
109
149
  }
110
- return await this.#documentService.getPreviewUrl(context.parameters.id, context.parameters.page);
150
+ return await this.#documentService.getPreviewUrl(tenantId, context.parameters.id, context.parameters.page);
111
151
  }
112
152
  async createCategory(context) {
113
153
  const token = await context.getToken();
154
+ const tenantId = await this.#authorizationService.getTenantId(token);
114
155
  const allowed = await this.#authorizationService.canManageCategoriesAndTypes(token);
115
156
  if (!allowed) {
116
157
  throw new ForbiddenError('You are not allowed to create document categories.');
117
158
  }
118
- return await this.#documentCategoryTypeService.createCategory(context.parameters.label, context.parameters.parentId);
159
+ return await this.#documentCategoryTypeService.createCategory({ tenantId, label: context.parameters.label, parentId: context.parameters.parentId });
119
160
  }
120
161
  async createType(context) {
121
162
  const token = await context.getToken();
163
+ const tenantId = await this.#authorizationService.getTenantId(token);
122
164
  const allowed = await this.#authorizationService.canManageCategoriesAndTypes(token);
123
165
  if (!allowed) {
124
166
  throw new ForbiddenError('You are not allowed to create document types.');
125
167
  }
126
- return await this.#documentCategoryTypeService.createType(context.parameters.label, context.parameters.categoryId);
168
+ return await this.#documentCategoryTypeService.createType({ tenantId, label: context.parameters.label, categoryId: context.parameters.categoryId });
127
169
  }
128
170
  async initiateDocumentUpload(context) {
129
171
  const token = await context.getToken();
@@ -132,6 +174,7 @@ let DocumentManagementApiController = DocumentManagementApiController_1 = class
132
174
  }
133
175
  async createDocument(context) {
134
176
  const token = await context.getToken();
177
+ const tenantId = await this.#authorizationService.getTenantId(token);
135
178
  const subject = await this.#authorizationService.getSubject(token);
136
179
  const { uploadId, ...createParameters } = context.parameters;
137
180
  const [collectionIds, requiresAssign] = await match(context.parameters.assignment)
@@ -156,15 +199,16 @@ let DocumentManagementApiController = DocumentManagementApiController_1 = class
156
199
  }
157
200
  }
158
201
  const actionUserId = await this.#authorizationService.getSubject(token);
159
- return await this.#documentService.create(createParameters, { uploadId, uploadKey: subject }, { createUserId: actionUserId });
202
+ return await this.#documentService.create(tenantId, createParameters, { uploadId, uploadKey: subject }, { createUserId: actionUserId });
160
203
  }
161
204
  async createDocumentRequestsTemplate(context) {
162
205
  const token = await context.getToken();
206
+ const tenantId = await this.#authorizationService.getTenantId(token);
163
207
  const allowed = await this.#authorizationService.canManageDocumentRequestsTemplates(token);
164
208
  if (!allowed) {
165
209
  throw new ForbiddenError('You are not allowed to create document requests template.');
166
210
  }
167
- return await this.#documentRequestService.createRequestsTemplate(context.parameters);
211
+ return await this.#documentRequestService.createRequestsTemplate(tenantId, context.parameters);
168
212
  }
169
213
  async updateDocumentRequestsTemplate(_context) {
170
214
  throw new NotImplementedError();
@@ -199,8 +243,55 @@ let DocumentManagementApiController = DocumentManagementApiController_1 = class
199
243
  async archiveDocumentInCollection(_context) {
200
244
  throw new NotImplementedError();
201
245
  }
202
- async updateDocument(_context) {
203
- throw new NotImplementedError();
246
+ async updateDocument({ parameters, getToken }) {
247
+ const token = await getToken();
248
+ const tenantId = await this.#authorizationService.getTenantId(token);
249
+ const { id, ...update } = parameters;
250
+ for (const id of [...(update.collections?.assign ?? []), ...(update.collections?.archive ?? [])]) {
251
+ const allowed = await this.#authorizationService.canAssignDocuments(id, token);
252
+ if (!allowed) {
253
+ throw new ForbiddenError('You are not allowed to assign to or archive documents in collection.');
254
+ }
255
+ }
256
+ await this.#documentService.update(tenantId, id, update);
257
+ return 'ok';
258
+ }
259
+ async proceedDocumentWorkflow({ parameters, getToken }) {
260
+ const token = await getToken();
261
+ const tenantId = await this.#authorizationService.getTenantId(token);
262
+ const userId = await this.#authorizationService.getSubject(token);
263
+ await this.#workflowService.proceedWorkflow(tenantId, parameters.id, userId);
264
+ return 'ok';
265
+ }
266
+ async testAuthorization({ parameters, getToken }) {
267
+ const token = await getToken();
268
+ return await match(parameters)
269
+ .with({ type: 'canReadCollection' }, async (parameters) => await this.#authorizationService.canReadCollection(parameters.collectionId, token))
270
+ .with({ type: 'canCreateDocuments' }, async (parameters) => await this.#authorizationService.canCreateDocuments(parameters.collectionId, token))
271
+ .with({ type: 'canDeleteDocuments' }, async (parameters) => await this.#authorizationService.canDeleteDocuments(parameters.collectionId, token))
272
+ .with({ type: 'canAssignDocuments' }, async (parameters) => await this.#authorizationService.canAssignDocuments(parameters.collectionId, token))
273
+ .with({ type: 'canManageRequests' }, async (parameters) => await this.#authorizationService.canManageRequests(parameters.collectionId, token))
274
+ .with({ type: 'canUpdateDocument' }, async (parameters) => await this.#authorizationService.canUpdateDocument(parameters.documentId, token))
275
+ .with({ type: 'canApproveDocument' }, async (parameters) => await this.#authorizationService.canApproveDocument(parameters.documentId, token))
276
+ .with({ type: 'canRejectDocument' }, async (parameters) => await this.#authorizationService.canRejectDocument(parameters.documentId, token))
277
+ .with({ type: 'canProgressDocumentWorkflow' }, async (parameters) => await this.#authorizationService.canProgressDocumentWorkflow(parameters.documentId, token))
278
+ .with({ type: 'canManageCategoriesAndTypes' }, async () => await this.#authorizationService.canManageCategoriesAndTypes(token))
279
+ .with({ type: 'canReadDocumentRequestsTemplates' }, async () => await this.#authorizationService.canReadDocumentRequestsTemplates(token))
280
+ .with({ type: 'canManageDocumentRequestsTemplates' }, async () => await this.#authorizationService.canManageDocumentRequestsTemplates(token))
281
+ .with({ type: 'canManageValidationDefinitions' }, async () => await this.#authorizationService.canManageValidationDefinitions(token))
282
+ .otherwise(() => {
283
+ throw new NotImplementedError(`Authorization test for type ${parameters.type} is not implemented.`);
284
+ });
285
+ }
286
+ async canReadDocument(tenantId, documentId, token) {
287
+ const relevantCollectionIds = await this.#documentManagementService.getRelevantDocumentCollectionIds(tenantId, documentId);
288
+ for (const collectionId of relevantCollectionIds) {
289
+ const canReadCollection = await this.#authorizationService.canReadCollection(collectionId, token);
290
+ if (canReadCollection) {
291
+ return true;
292
+ }
293
+ }
294
+ return false;
204
295
  }
205
296
  };
206
297
  DocumentManagementApiController = DocumentManagementApiController_1 = __decorate([
@@ -1,2 +1,2 @@
1
- import { DocumentManagementConfig } from './module.js';
2
- export declare function configureDocumentManagement(config: DocumentManagementConfig): void;
1
+ import { DocumentManagementConfiguration } from './module.js';
2
+ export declare function configureDocumentManagement(configuration: DocumentManagementConfiguration): void;
@@ -1,9 +1,9 @@
1
1
  import { Injector } from '../../injector/injector.js';
2
- import { DocumentManagementConfig } from './module.js';
3
- import { DocumentManagementAncillaryService } from './services/document-management-ancillary.service.js';
4
- import { DocumentManagementAuthorizationService } from './services/document-management-authorization.service.js';
5
- export function configureDocumentManagement(config) {
6
- Injector.register(DocumentManagementConfig, { useValue: config });
7
- Injector.register(DocumentManagementAncillaryService, { useToken: config.ancillaryService });
8
- Injector.register(DocumentManagementAuthorizationService, { useToken: config.authorizationService });
2
+ import { DocumentManagementAuthorizationService } from '../authorization/document-management-authorization.service.js';
3
+ import { DocumentManagementConfiguration } from './module.js';
4
+ import { DocumentManagementAncillaryService } from './services/index.js';
5
+ export function configureDocumentManagement(configuration) {
6
+ Injector.register(DocumentManagementConfiguration, { useValue: configuration });
7
+ Injector.register(DocumentManagementAncillaryService, { useToken: configuration.ancillaryService });
8
+ Injector.register(DocumentManagementAuthorizationService, { useToken: configuration.authorizationService });
9
9
  }