@tstdl/base 0.92.137 → 0.92.139
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/document-management/api/document-management.api.d.ts +40 -0
- package/document-management/api/document-management.api.js +20 -0
- package/document-management/server/api/document-management.api.d.ts +2 -0
- package/document-management/server/api/document-management.api.js +34 -32
- package/document-management/server/configure.d.ts +2 -0
- package/document-management/server/configure.js +9 -0
- package/document-management/server/drizzle/{0000_magical_madame_hydra.sql → 0000_moaning_luckman.sql} +4 -15
- package/document-management/server/drizzle/meta/0000_snapshot.json +25 -96
- package/document-management/server/drizzle/meta/_journal.json +2 -2
- package/document-management/server/index.d.ts +1 -0
- package/document-management/server/index.js +1 -0
- package/document-management/server/module.d.ts +3 -2
- package/document-management/server/module.js +2 -6
- package/document-management/server/services/document-category-type.service.d.ts +0 -1
- package/document-management/server/services/document-category-type.service.js +7 -7
- package/document-management/server/services/document-file.service.js +2 -2
- package/document-management/server/services/document-management-ai.service.js +5 -1
- package/document-management/server/services/document-management-ancillary.service.d.ts +2 -83
- package/document-management/server/services/document-management-ancillary.service.js +1 -23
- package/document-management/server/services/document-management-authorization.service.d.ts +85 -0
- package/document-management/server/services/document-management-authorization.service.js +28 -0
- package/document-management/server/services/document-management.service.d.ts +9 -2
- package/document-management/server/services/document-management.service.js +59 -6
- package/document-management/server/services/document-property.service.d.ts +7 -3
- package/document-management/server/services/document-property.service.js +8 -4
- package/document-management/server/services/document-workflow.service.js +2 -2
- package/document-management/server/services/enum-type-key.d.ts +1 -0
- package/document-management/server/services/enum-type-key.js +1 -0
- package/document-management/server/services/index.d.ts +1 -0
- package/document-management/server/services/index.js +1 -0
- package/document-management/service-models/enriched/enriched-document-category.view.d.ts +1 -0
- package/document-management/service-models/enriched/enriched-document-category.view.js +8 -0
- package/document-management/service-models/enriched/enriched-document.view.d.ts +3 -1
- package/document-management/service-models/enriched/enriched-document.view.js +2 -0
- package/examples/document-management/categories-and-types.d.ts +357 -312
- package/examples/document-management/categories-and-types.js +690 -350
- package/examples/document-management/main.d.ts +18 -16
- package/examples/document-management/main.js +27 -20
- package/file/mime-type.d.ts +2 -1
- package/file/mime-type.js +10 -18
- package/file/mime-types.js +1 -2
- package/http/server/http-server-response.js +2 -2
- package/orm/sqls.d.ts +8 -2
- package/package.json +3 -2
- package/schema/converters/openapi-converter.js +15 -12
|
@@ -45,6 +45,26 @@ export declare const documentManagementApiDefinition: {
|
|
|
45
45
|
result: import("../../schema/index.js").StringSchema;
|
|
46
46
|
credentials: true;
|
|
47
47
|
};
|
|
48
|
+
loadPreview: {
|
|
49
|
+
resource: string;
|
|
50
|
+
method: "GET";
|
|
51
|
+
parameters: import("../../schema/index.js").ObjectSchema<{
|
|
52
|
+
id: string;
|
|
53
|
+
page: number;
|
|
54
|
+
}>;
|
|
55
|
+
result: Uint8ArrayConstructor;
|
|
56
|
+
credentials: true;
|
|
57
|
+
};
|
|
58
|
+
getPreviewUrl: {
|
|
59
|
+
resource: string;
|
|
60
|
+
method: "GET";
|
|
61
|
+
parameters: import("../../schema/index.js").ObjectSchema<{
|
|
62
|
+
id: string;
|
|
63
|
+
page: number;
|
|
64
|
+
}>;
|
|
65
|
+
result: import("../../schema/index.js").StringSchema;
|
|
66
|
+
credentials: true;
|
|
67
|
+
};
|
|
48
68
|
createCategory: {
|
|
49
69
|
resource: string;
|
|
50
70
|
method: "POST";
|
|
@@ -358,6 +378,26 @@ declare const _DocumentManagementApi: import("../../api/client/index.js").ApiCli
|
|
|
358
378
|
result: import("../../schema/index.js").StringSchema;
|
|
359
379
|
credentials: true;
|
|
360
380
|
};
|
|
381
|
+
loadPreview: {
|
|
382
|
+
resource: string;
|
|
383
|
+
method: "GET";
|
|
384
|
+
parameters: import("../../schema/index.js").ObjectSchema<{
|
|
385
|
+
id: string;
|
|
386
|
+
page: number;
|
|
387
|
+
}>;
|
|
388
|
+
result: Uint8ArrayConstructor;
|
|
389
|
+
credentials: true;
|
|
390
|
+
};
|
|
391
|
+
getPreviewUrl: {
|
|
392
|
+
resource: string;
|
|
393
|
+
method: "GET";
|
|
394
|
+
parameters: import("../../schema/index.js").ObjectSchema<{
|
|
395
|
+
id: string;
|
|
396
|
+
page: number;
|
|
397
|
+
}>;
|
|
398
|
+
result: import("../../schema/index.js").StringSchema;
|
|
399
|
+
credentials: true;
|
|
400
|
+
};
|
|
361
401
|
createCategory: {
|
|
362
402
|
resource: string;
|
|
363
403
|
method: "POST";
|
|
@@ -52,6 +52,26 @@ export const documentManagementApiDefinition = defineApi({
|
|
|
52
52
|
result: string(),
|
|
53
53
|
credentials: true,
|
|
54
54
|
},
|
|
55
|
+
loadPreview: {
|
|
56
|
+
resource: 'documents/:id/preview/:page',
|
|
57
|
+
method: 'GET',
|
|
58
|
+
parameters: object({
|
|
59
|
+
id: string(),
|
|
60
|
+
page: number({ coerce: true }),
|
|
61
|
+
}),
|
|
62
|
+
result: Uint8Array,
|
|
63
|
+
credentials: true,
|
|
64
|
+
},
|
|
65
|
+
getPreviewUrl: {
|
|
66
|
+
resource: 'documents/:id/preview/:page/url',
|
|
67
|
+
method: 'GET',
|
|
68
|
+
parameters: object({
|
|
69
|
+
id: string(),
|
|
70
|
+
page: number({ coerce: true }),
|
|
71
|
+
}),
|
|
72
|
+
result: string(),
|
|
73
|
+
credentials: true,
|
|
74
|
+
},
|
|
55
75
|
createCategory: {
|
|
56
76
|
resource: 'categories',
|
|
57
77
|
method: 'POST',
|
|
@@ -7,6 +7,8 @@ export declare class DocumentManagementApiController implements ApiController<Do
|
|
|
7
7
|
loadAvailableCategories(context: ApiRequestContext<DocumentManagementApiDefinition, 'loadAvailableCategories'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'loadAvailableCategories'>>;
|
|
8
8
|
loadContent(context: ApiRequestContext<DocumentManagementApiDefinition, 'loadContent'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'loadContent'>>;
|
|
9
9
|
getContentUrl(context: ApiRequestContext<DocumentManagementApiDefinition, 'getContentUrl'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'getContentUrl'>>;
|
|
10
|
+
loadPreview(context: ApiRequestContext<DocumentManagementApiDefinition, 'loadPreview'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'loadPreview'>>;
|
|
11
|
+
getPreviewUrl(context: ApiRequestContext<DocumentManagementApiDefinition, 'getPreviewUrl'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'getPreviewUrl'>>;
|
|
10
12
|
createCategory(context: ApiRequestContext<DocumentManagementApiDefinition, 'createCategory'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'createCategory'>>;
|
|
11
13
|
createType(context: ApiRequestContext<DocumentManagementApiDefinition, 'createType'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'createType'>>;
|
|
12
14
|
initiateDocumentUpload(context: ApiRequestContext<DocumentManagementApiDefinition, 'initiateDocumentUpload'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'initiateDocumentUpload'>>;
|
|
@@ -4,38 +4,28 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
var _a;
|
|
8
|
-
var DocumentManagementApiController_1;
|
|
9
7
|
import { apiController } from '../../../api/server/index.js';
|
|
10
|
-
import { CancellationSignal } from '../../../cancellation/index.js';
|
|
11
8
|
import { documentManagementApiDefinition } from '../../../document-management/api/index.js';
|
|
12
9
|
import { DocumentRequestCollectionAssignment } from '../../../document-management/models/document-request-collection-assignment.model.js';
|
|
13
10
|
import { ForbiddenError, NotImplementedError } from '../../../errors/index.js';
|
|
14
11
|
import { HttpServerResponse } from '../../../http/index.js';
|
|
15
12
|
import { inject } from '../../../injector/index.js';
|
|
16
|
-
import { Logger } from '../../../logger/index.js';
|
|
17
13
|
import { injectRepository } from '../../../orm/server/repository.js';
|
|
18
14
|
import { toArray } from '../../../utils/array/index.js';
|
|
19
15
|
import { match, P } from 'ts-pattern';
|
|
20
|
-
import { DocumentCategoryTypeService,
|
|
21
|
-
let DocumentManagementApiController =
|
|
22
|
-
#
|
|
16
|
+
import { DocumentCategoryTypeService, DocumentFileService, DocumentManagementAuthorizationService, DocumentManagementService, DocumentRequestService, DocumentService } from '../services/index.js';
|
|
17
|
+
let DocumentManagementApiController = class DocumentManagementApiController {
|
|
18
|
+
#authorizationService = inject(DocumentManagementAuthorizationService);
|
|
23
19
|
#documentCategoryTypeService = inject(DocumentCategoryTypeService);
|
|
24
|
-
#documentCollectionService = inject(DocumentCollectionService);
|
|
25
20
|
#documentFileService = inject(DocumentFileService);
|
|
26
|
-
#documentManagementAncillaryService = inject(DocumentManagementAncillaryService);
|
|
27
21
|
#documentManagementService = inject(DocumentManagementService);
|
|
28
|
-
#documentPropertyService = inject(DocumentPropertyService);
|
|
29
22
|
#documentRequestService = inject(DocumentRequestService);
|
|
30
23
|
#documentRequestCollectionAssignmentRepository = injectRepository(DocumentRequestCollectionAssignment);
|
|
31
24
|
#documentService = inject(DocumentService);
|
|
32
|
-
#documentWorkflowService = inject(DocumentWorkflowService);
|
|
33
|
-
#cancellationSignal = inject(CancellationSignal);
|
|
34
|
-
#logger = inject(Logger, DocumentManagementApiController_1.name);
|
|
35
25
|
async loadData(context) {
|
|
36
26
|
const token = await context.getToken();
|
|
37
27
|
for (const collectionId of context.parameters.collectionIds) {
|
|
38
|
-
const allowed = await this.#
|
|
28
|
+
const allowed = await this.#authorizationService.canReadCollection(collectionId, token);
|
|
39
29
|
if (!allowed) {
|
|
40
30
|
throw new ForbiddenError(`You are not allowed to read collection ${collectionId}`);
|
|
41
31
|
}
|
|
@@ -44,7 +34,7 @@ let DocumentManagementApiController = DocumentManagementApiController_1 = class
|
|
|
44
34
|
}
|
|
45
35
|
async loadDocumentRequestsTemplateData(context) {
|
|
46
36
|
const token = await context.getToken();
|
|
47
|
-
const allowed = await this.#
|
|
37
|
+
const allowed = await this.#authorizationService.canReadDocumentRequestsTemplates(token);
|
|
48
38
|
if (!allowed) {
|
|
49
39
|
throw new ForbiddenError('You are not allowed to load document requests template data.');
|
|
50
40
|
}
|
|
@@ -56,29 +46,41 @@ let DocumentManagementApiController = DocumentManagementApiController_1 = class
|
|
|
56
46
|
}
|
|
57
47
|
async loadContent(context) {
|
|
58
48
|
const token = await context.getToken();
|
|
59
|
-
const allowed = await this.#
|
|
49
|
+
const allowed = await this.#authorizationService.canReadDocument(context.parameters.id, token);
|
|
60
50
|
if (!allowed) {
|
|
61
51
|
throw new ForbiddenError(`You are not allowed to load content for document ${context.parameters.id}.`);
|
|
62
52
|
}
|
|
63
53
|
const url = await this.#documentService.getContentUrl(context.parameters.id, context.parameters.download);
|
|
64
|
-
return HttpServerResponse.
|
|
65
|
-
statusCode: 303,
|
|
66
|
-
headers: {
|
|
67
|
-
Location: url,
|
|
68
|
-
},
|
|
69
|
-
});
|
|
54
|
+
return HttpServerResponse.redirect(url);
|
|
70
55
|
}
|
|
71
56
|
async getContentUrl(context) {
|
|
72
57
|
const token = await context.getToken();
|
|
73
|
-
const allowed = await this.#
|
|
58
|
+
const allowed = await this.#authorizationService.canReadDocument(context.parameters.id, token);
|
|
74
59
|
if (!allowed) {
|
|
75
60
|
throw new ForbiddenError(`You are not allowed to get content URL for document ${context.parameters.id}.`);
|
|
76
61
|
}
|
|
77
62
|
return await this.#documentService.getContentUrl(context.parameters.id, context.parameters.download);
|
|
78
63
|
}
|
|
64
|
+
async loadPreview(context) {
|
|
65
|
+
const token = await context.getToken();
|
|
66
|
+
const allowed = await this.#authorizationService.canReadDocument(context.parameters.id, token);
|
|
67
|
+
if (!allowed) {
|
|
68
|
+
throw new ForbiddenError(`You are not allowed to get content preview for document ${context.parameters.id}.`);
|
|
69
|
+
}
|
|
70
|
+
const url = await this.#documentService.getPreviewUrl(context.parameters.id, context.parameters.page);
|
|
71
|
+
return HttpServerResponse.redirect(url);
|
|
72
|
+
}
|
|
73
|
+
async getPreviewUrl(context) {
|
|
74
|
+
const token = await context.getToken();
|
|
75
|
+
const allowed = await this.#authorizationService.canReadDocument(context.parameters.id, token);
|
|
76
|
+
if (!allowed) {
|
|
77
|
+
throw new ForbiddenError(`You are not allowed to get content preview for document ${context.parameters.id}.`);
|
|
78
|
+
}
|
|
79
|
+
return await this.#documentService.getPreviewUrl(context.parameters.id, context.parameters.page);
|
|
80
|
+
}
|
|
79
81
|
async createCategory(context) {
|
|
80
82
|
const token = await context.getToken();
|
|
81
|
-
const allowed = await this.#
|
|
83
|
+
const allowed = await this.#authorizationService.canManageCategoriesAndTypes(token);
|
|
82
84
|
if (!allowed) {
|
|
83
85
|
throw new ForbiddenError('You are not allowed to create document categories.');
|
|
84
86
|
}
|
|
@@ -86,7 +88,7 @@ let DocumentManagementApiController = DocumentManagementApiController_1 = class
|
|
|
86
88
|
}
|
|
87
89
|
async createType(context) {
|
|
88
90
|
const token = await context.getToken();
|
|
89
|
-
const allowed = await this.#
|
|
91
|
+
const allowed = await this.#authorizationService.canManageCategoriesAndTypes(token);
|
|
90
92
|
if (!allowed) {
|
|
91
93
|
throw new ForbiddenError('You are not allowed to create document types.');
|
|
92
94
|
}
|
|
@@ -94,12 +96,12 @@ let DocumentManagementApiController = DocumentManagementApiController_1 = class
|
|
|
94
96
|
}
|
|
95
97
|
async initiateDocumentUpload(context) {
|
|
96
98
|
const token = await context.getToken();
|
|
97
|
-
const subject = await this.#
|
|
99
|
+
const subject = await this.#authorizationService.getSubject(token);
|
|
98
100
|
return await this.#documentFileService.initiateUpload({ key: subject, contentLength: context.parameters.contentLength });
|
|
99
101
|
}
|
|
100
102
|
async createDocument(context) {
|
|
101
103
|
const token = await context.getToken();
|
|
102
|
-
const subject = await this.#
|
|
104
|
+
const subject = await this.#authorizationService.getSubject(token);
|
|
103
105
|
const { uploadId, ...createParameters } = context.parameters;
|
|
104
106
|
const [collectionIds, requiresAssign] = await match(context.parameters.assignment)
|
|
105
107
|
.with({ collections: P.select() }, (collectionIds) => [toArray(collectionIds), true])
|
|
@@ -111,23 +113,23 @@ let DocumentManagementApiController = DocumentManagementApiController_1 = class
|
|
|
111
113
|
.with({ automatic: P.select() }, ({ scope }) => [toArray(scope), false])
|
|
112
114
|
.exhaustive();
|
|
113
115
|
for (const collectionId of collectionIds) {
|
|
114
|
-
const createDocumentsAllowed = await this.#
|
|
116
|
+
const createDocumentsAllowed = await this.#authorizationService.canCreateDocuments(collectionId, token);
|
|
115
117
|
if (!createDocumentsAllowed) {
|
|
116
118
|
throw new ForbiddenError(`You are not allowed to create documents in collection ${collectionId}.`);
|
|
117
119
|
}
|
|
118
120
|
if (requiresAssign) {
|
|
119
|
-
const assignDocumentsAllowed = await this.#
|
|
121
|
+
const assignDocumentsAllowed = await this.#authorizationService.canAssignDocuments(collectionId, token);
|
|
120
122
|
if (!assignDocumentsAllowed) {
|
|
121
123
|
throw new ForbiddenError(`You are not allowed to assign documents in collection ${collectionId}.`);
|
|
122
124
|
}
|
|
123
125
|
}
|
|
124
126
|
}
|
|
125
|
-
const actionUserId = await this.#
|
|
127
|
+
const actionUserId = await this.#authorizationService.getSubject(token);
|
|
126
128
|
return await this.#documentService.create(createParameters, { uploadId, uploadKey: subject }, { createUserId: actionUserId });
|
|
127
129
|
}
|
|
128
130
|
async createDocumentRequestsTemplate(context) {
|
|
129
131
|
const token = await context.getToken();
|
|
130
|
-
const allowed = await this.#
|
|
132
|
+
const allowed = await this.#authorizationService.canManageDocumentRequestsTemplates(token);
|
|
131
133
|
if (!allowed) {
|
|
132
134
|
throw new ForbiddenError('You are not allowed to create document requests template.');
|
|
133
135
|
}
|
|
@@ -170,7 +172,7 @@ let DocumentManagementApiController = DocumentManagementApiController_1 = class
|
|
|
170
172
|
throw new NotImplementedError();
|
|
171
173
|
}
|
|
172
174
|
};
|
|
173
|
-
DocumentManagementApiController =
|
|
175
|
+
DocumentManagementApiController = __decorate([
|
|
174
176
|
apiController(documentManagementApiDefinition)
|
|
175
177
|
], DocumentManagementApiController);
|
|
176
178
|
export { DocumentManagementApiController };
|
|
@@ -0,0 +1,9 @@
|
|
|
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 });
|
|
9
|
+
}
|
|
@@ -9,7 +9,6 @@ CREATE TYPE "document_management"."document_workflow_state" AS ENUM('pending', '
|
|
|
9
9
|
CREATE TYPE "document_management"."document_workflow_step" AS ENUM('classification', 'extraction', 'assignment', 'validation');--> statement-breakpoint
|
|
10
10
|
CREATE TABLE "document_management"."document" (
|
|
11
11
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
12
|
-
"file_id" uuid NOT NULL,
|
|
13
12
|
"type_id" uuid,
|
|
14
13
|
"title" text,
|
|
15
14
|
"subtitle" text,
|
|
@@ -19,6 +18,10 @@ CREATE TABLE "document_management"."document" (
|
|
|
19
18
|
"tags" text[],
|
|
20
19
|
"approval" "document_management"."document_approval" NOT NULL,
|
|
21
20
|
"comment" text,
|
|
21
|
+
"original_file_name" text,
|
|
22
|
+
"mime_type" text NOT NULL,
|
|
23
|
+
"hash" text NOT NULL,
|
|
24
|
+
"size" integer NOT NULL,
|
|
22
25
|
"create_user_id" uuid,
|
|
23
26
|
"revision" integer NOT NULL,
|
|
24
27
|
"revision_timestamp" timestamp with time zone NOT NULL,
|
|
@@ -86,19 +89,6 @@ CREATE TABLE "document_management"."document_collection_assignment" (
|
|
|
86
89
|
CONSTRAINT "document_collection_assignment_collection_id_document_id_unique" UNIQUE("collection_id","document_id")
|
|
87
90
|
);
|
|
88
91
|
--> statement-breakpoint
|
|
89
|
-
CREATE TABLE "document_management"."document_file" (
|
|
90
|
-
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
91
|
-
"original_file_name" text,
|
|
92
|
-
"mime_type" text NOT NULL,
|
|
93
|
-
"hash" text NOT NULL,
|
|
94
|
-
"size" integer NOT NULL,
|
|
95
|
-
"revision" integer NOT NULL,
|
|
96
|
-
"revision_timestamp" timestamp with time zone NOT NULL,
|
|
97
|
-
"create_timestamp" timestamp with time zone NOT NULL,
|
|
98
|
-
"delete_timestamp" timestamp with time zone,
|
|
99
|
-
"attributes" jsonb DEFAULT '{}'::jsonb NOT NULL
|
|
100
|
-
);
|
|
101
|
-
--> statement-breakpoint
|
|
102
92
|
CREATE TABLE "document_management"."document_property" (
|
|
103
93
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
104
94
|
"label" text NOT NULL,
|
|
@@ -283,7 +273,6 @@ CREATE TABLE "document_management"."document_workflow" (
|
|
|
283
273
|
"attributes" jsonb DEFAULT '{}'::jsonb NOT NULL
|
|
284
274
|
);
|
|
285
275
|
--> statement-breakpoint
|
|
286
|
-
ALTER TABLE "document_management"."document" ADD CONSTRAINT "document_file_id_document_file_id_fk" FOREIGN KEY ("file_id") REFERENCES "document_management"."document_file"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
287
276
|
ALTER TABLE "document_management"."document" ADD CONSTRAINT "document_type_id_document_type_id_fk" FOREIGN KEY ("type_id") REFERENCES "document_management"."document_type"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
288
277
|
ALTER TABLE "document_management"."document_assignment_scope" ADD CONSTRAINT "document_assignment_scope_task_id_document_assignment_task_id_fk" FOREIGN KEY ("task_id") REFERENCES "document_management"."document_assignment_task"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
289
278
|
ALTER TABLE "document_management"."document_assignment_scope" ADD CONSTRAINT "document_assignment_scope_collection_id_document_collection_id_fk" FOREIGN KEY ("collection_id") REFERENCES "document_management"."document_collection"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"id": "
|
|
2
|
+
"id": "f1876b8d-1096-498b-a610-396dcf0fee9d",
|
|
3
3
|
"prevId": "00000000-0000-0000-0000-000000000000",
|
|
4
4
|
"version": "7",
|
|
5
5
|
"dialect": "postgresql",
|
|
@@ -15,12 +15,6 @@
|
|
|
15
15
|
"notNull": true,
|
|
16
16
|
"default": "gen_random_uuid()"
|
|
17
17
|
},
|
|
18
|
-
"file_id": {
|
|
19
|
-
"name": "file_id",
|
|
20
|
-
"type": "uuid",
|
|
21
|
-
"primaryKey": false,
|
|
22
|
-
"notNull": true
|
|
23
|
-
},
|
|
24
18
|
"type_id": {
|
|
25
19
|
"name": "type_id",
|
|
26
20
|
"type": "uuid",
|
|
@@ -76,6 +70,30 @@
|
|
|
76
70
|
"primaryKey": false,
|
|
77
71
|
"notNull": false
|
|
78
72
|
},
|
|
73
|
+
"original_file_name": {
|
|
74
|
+
"name": "original_file_name",
|
|
75
|
+
"type": "text",
|
|
76
|
+
"primaryKey": false,
|
|
77
|
+
"notNull": false
|
|
78
|
+
},
|
|
79
|
+
"mime_type": {
|
|
80
|
+
"name": "mime_type",
|
|
81
|
+
"type": "text",
|
|
82
|
+
"primaryKey": false,
|
|
83
|
+
"notNull": true
|
|
84
|
+
},
|
|
85
|
+
"hash": {
|
|
86
|
+
"name": "hash",
|
|
87
|
+
"type": "text",
|
|
88
|
+
"primaryKey": false,
|
|
89
|
+
"notNull": true
|
|
90
|
+
},
|
|
91
|
+
"size": {
|
|
92
|
+
"name": "size",
|
|
93
|
+
"type": "integer",
|
|
94
|
+
"primaryKey": false,
|
|
95
|
+
"notNull": true
|
|
96
|
+
},
|
|
79
97
|
"create_user_id": {
|
|
80
98
|
"name": "create_user_id",
|
|
81
99
|
"type": "uuid",
|
|
@@ -116,20 +134,6 @@
|
|
|
116
134
|
},
|
|
117
135
|
"indexes": {},
|
|
118
136
|
"foreignKeys": {
|
|
119
|
-
"document_file_id_document_file_id_fk": {
|
|
120
|
-
"name": "document_file_id_document_file_id_fk",
|
|
121
|
-
"tableFrom": "document",
|
|
122
|
-
"tableTo": "document_file",
|
|
123
|
-
"schemaTo": "document_management",
|
|
124
|
-
"columnsFrom": [
|
|
125
|
-
"file_id"
|
|
126
|
-
],
|
|
127
|
-
"columnsTo": [
|
|
128
|
-
"id"
|
|
129
|
-
],
|
|
130
|
-
"onDelete": "no action",
|
|
131
|
-
"onUpdate": "no action"
|
|
132
|
-
},
|
|
133
137
|
"document_type_id_document_type_id_fk": {
|
|
134
138
|
"name": "document_type_id_document_type_id_fk",
|
|
135
139
|
"tableFrom": "document",
|
|
@@ -604,81 +608,6 @@
|
|
|
604
608
|
"checkConstraints": {},
|
|
605
609
|
"isRLSEnabled": false
|
|
606
610
|
},
|
|
607
|
-
"document_management.document_file": {
|
|
608
|
-
"name": "document_file",
|
|
609
|
-
"schema": "document_management",
|
|
610
|
-
"columns": {
|
|
611
|
-
"id": {
|
|
612
|
-
"name": "id",
|
|
613
|
-
"type": "uuid",
|
|
614
|
-
"primaryKey": true,
|
|
615
|
-
"notNull": true,
|
|
616
|
-
"default": "gen_random_uuid()"
|
|
617
|
-
},
|
|
618
|
-
"original_file_name": {
|
|
619
|
-
"name": "original_file_name",
|
|
620
|
-
"type": "text",
|
|
621
|
-
"primaryKey": false,
|
|
622
|
-
"notNull": false
|
|
623
|
-
},
|
|
624
|
-
"mime_type": {
|
|
625
|
-
"name": "mime_type",
|
|
626
|
-
"type": "text",
|
|
627
|
-
"primaryKey": false,
|
|
628
|
-
"notNull": true
|
|
629
|
-
},
|
|
630
|
-
"hash": {
|
|
631
|
-
"name": "hash",
|
|
632
|
-
"type": "text",
|
|
633
|
-
"primaryKey": false,
|
|
634
|
-
"notNull": true
|
|
635
|
-
},
|
|
636
|
-
"size": {
|
|
637
|
-
"name": "size",
|
|
638
|
-
"type": "integer",
|
|
639
|
-
"primaryKey": false,
|
|
640
|
-
"notNull": true
|
|
641
|
-
},
|
|
642
|
-
"revision": {
|
|
643
|
-
"name": "revision",
|
|
644
|
-
"type": "integer",
|
|
645
|
-
"primaryKey": false,
|
|
646
|
-
"notNull": true
|
|
647
|
-
},
|
|
648
|
-
"revision_timestamp": {
|
|
649
|
-
"name": "revision_timestamp",
|
|
650
|
-
"type": "timestamp with time zone",
|
|
651
|
-
"primaryKey": false,
|
|
652
|
-
"notNull": true
|
|
653
|
-
},
|
|
654
|
-
"create_timestamp": {
|
|
655
|
-
"name": "create_timestamp",
|
|
656
|
-
"type": "timestamp with time zone",
|
|
657
|
-
"primaryKey": false,
|
|
658
|
-
"notNull": true
|
|
659
|
-
},
|
|
660
|
-
"delete_timestamp": {
|
|
661
|
-
"name": "delete_timestamp",
|
|
662
|
-
"type": "timestamp with time zone",
|
|
663
|
-
"primaryKey": false,
|
|
664
|
-
"notNull": false
|
|
665
|
-
},
|
|
666
|
-
"attributes": {
|
|
667
|
-
"name": "attributes",
|
|
668
|
-
"type": "jsonb",
|
|
669
|
-
"primaryKey": false,
|
|
670
|
-
"notNull": true,
|
|
671
|
-
"default": "'{}'::jsonb"
|
|
672
|
-
}
|
|
673
|
-
},
|
|
674
|
-
"indexes": {},
|
|
675
|
-
"foreignKeys": {},
|
|
676
|
-
"compositePrimaryKeys": {},
|
|
677
|
-
"uniqueConstraints": {},
|
|
678
|
-
"policies": {},
|
|
679
|
-
"checkConstraints": {},
|
|
680
|
-
"isRLSEnabled": false
|
|
681
|
-
},
|
|
682
611
|
"document_management.document_property": {
|
|
683
612
|
"name": "document_property",
|
|
684
613
|
"schema": "document_management",
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import './schemas.js';
|
|
2
2
|
import { type InjectionToken } from '../../injector/index.js';
|
|
3
3
|
import type { DatabaseConfig } from '../../orm/server/module.js';
|
|
4
|
-
import { DocumentManagementAncillaryService } from './services/document-management-ancillary.service.js';
|
|
4
|
+
import type { DocumentManagementAncillaryService } from './services/document-management-ancillary.service.js';
|
|
5
|
+
import type { DocumentManagementAuthorizationService } from './services/document-management-authorization.service.js';
|
|
5
6
|
export declare class DocumentManagementConfig {
|
|
6
7
|
ancillaryService: InjectionToken<DocumentManagementAncillaryService>;
|
|
8
|
+
authorizationService: InjectionToken<DocumentManagementAuthorizationService>;
|
|
7
9
|
fileObjectStorageModule: string;
|
|
8
10
|
fileUploadObjectStorageModule: string;
|
|
9
11
|
filePreviewObjectStorageModule: string;
|
|
10
12
|
database?: DatabaseConfig;
|
|
11
13
|
maxFileSize?: number;
|
|
12
14
|
}
|
|
13
|
-
export declare function configureDocumentManagement(config: DocumentManagementConfig): void;
|
|
14
15
|
export declare function migrateDocumentManagementSchema(): Promise<void>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import './schemas.js';
|
|
2
|
-
import { inject
|
|
2
|
+
import { inject } from '../../injector/index.js';
|
|
3
3
|
import { Database, migrate } from '../../orm/server/database.js';
|
|
4
|
-
import { DocumentManagementAncillaryService } from './services/document-management-ancillary.service.js';
|
|
5
4
|
export class DocumentManagementConfig {
|
|
6
5
|
ancillaryService;
|
|
6
|
+
authorizationService;
|
|
7
7
|
fileObjectStorageModule;
|
|
8
8
|
fileUploadObjectStorageModule;
|
|
9
9
|
filePreviewObjectStorageModule;
|
|
@@ -11,10 +11,6 @@ export class DocumentManagementConfig {
|
|
|
11
11
|
maxFileSize;
|
|
12
12
|
}
|
|
13
13
|
;
|
|
14
|
-
export function configureDocumentManagement(config) {
|
|
15
|
-
Injector.register(DocumentManagementConfig, { useValue: config });
|
|
16
|
-
Injector.register(DocumentManagementAncillaryService, { useToken: config.ancillaryService });
|
|
17
|
-
}
|
|
18
14
|
export async function migrateDocumentManagementSchema() {
|
|
19
15
|
const connection = inject(DocumentManagementConfig, undefined, { optional: true })?.database?.connection;
|
|
20
16
|
const database = inject(Database, connection);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Transactional } from '../../../orm/server/index.js';
|
|
2
2
|
import { DocumentCategory, DocumentType } from '../../models/index.js';
|
|
3
3
|
import type { DocumentCategoryView } from '../../service-models/index.js';
|
|
4
|
-
export declare const enumTypeKey = "enum-type";
|
|
5
4
|
export declare class DocumentCategoryTypeService extends Transactional {
|
|
6
5
|
#private;
|
|
7
6
|
readonly categoryRepository: import("../../../orm/server/repository.js").EntityRepository<DocumentCategory>;
|
|
@@ -13,29 +13,29 @@ import { injectRepository } from '../../../orm/server/repository.js';
|
|
|
13
13
|
import { groupToMap } from '../../../utils/iterable-helpers/group-to-map.js';
|
|
14
14
|
import { isUndefined } from '../../../utils/type-guards.js';
|
|
15
15
|
import { DocumentCategory, DocumentType } from '../../models/index.js';
|
|
16
|
+
import { enumTypeKey } from './enum-type-key.js';
|
|
16
17
|
import { DocumentManagementSingleton } from './singleton.js';
|
|
17
|
-
export const enumTypeKey = 'enum-type';
|
|
18
18
|
let DocumentCategoryTypeService = DocumentCategoryTypeService_1 = class DocumentCategoryTypeService extends Transactional {
|
|
19
19
|
#logger = inject(Logger, DocumentCategoryTypeService_1.name);
|
|
20
20
|
categoryRepository = injectRepository(DocumentCategory);
|
|
21
21
|
typeRepository = injectRepository(DocumentType);
|
|
22
22
|
async loadCategory(id) {
|
|
23
|
-
return this.categoryRepository.load(id);
|
|
23
|
+
return await this.categoryRepository.load(id);
|
|
24
24
|
}
|
|
25
25
|
async loadType(id) {
|
|
26
|
-
return this.typeRepository.load(id);
|
|
26
|
+
return await this.typeRepository.load(id);
|
|
27
27
|
}
|
|
28
28
|
async createCategory(label, parentId, enumKey) {
|
|
29
|
-
return this.categoryRepository.insert({ label, parentId, metadata: { attributes: { [enumTypeKey]: enumKey } } });
|
|
29
|
+
return await this.categoryRepository.insert({ label, parentId, metadata: { attributes: { [enumTypeKey]: enumKey } } });
|
|
30
30
|
}
|
|
31
31
|
async createType(label, categoryId, enumKey) {
|
|
32
|
-
return this.typeRepository.insert({ label, categoryId, metadata: { attributes: { [enumTypeKey]: enumKey } } });
|
|
32
|
+
return await this.typeRepository.insert({ label, categoryId, metadata: { attributes: { [enumTypeKey]: enumKey } } });
|
|
33
33
|
}
|
|
34
34
|
async updateCategory(id, update) {
|
|
35
|
-
return this.categoryRepository.update(id, update);
|
|
35
|
+
return await this.categoryRepository.update(id, update);
|
|
36
36
|
}
|
|
37
37
|
async updateType(id, update) {
|
|
38
|
-
return this.typeRepository.update(id, update);
|
|
38
|
+
return await this.typeRepository.update(id, update);
|
|
39
39
|
}
|
|
40
40
|
async loadCategoryGraph(categoryId) {
|
|
41
41
|
const category = await this.categoryRepository.load(categoryId);
|
|
@@ -63,7 +63,7 @@ import { match } from 'ts-pattern';
|
|
|
63
63
|
import { AiService } from '../../../ai/ai.service.js';
|
|
64
64
|
import { ForbiddenError } from '../../../errors/forbidden.error.js';
|
|
65
65
|
import { NotImplementedError } from '../../../errors/not-implemented.error.js';
|
|
66
|
-
import { getMimeType, getMimeTypeExtensions } from '../../../file/index.js';
|
|
66
|
+
import { getMimeType, getMimeTypeExtensions, mimeTypes } from '../../../file/index.js';
|
|
67
67
|
import { TemporaryFile } from '../../../file/server/index.js';
|
|
68
68
|
import { inject } from '../../../injector/inject.js';
|
|
69
69
|
import { Logger } from '../../../logger/logger.js';
|
|
@@ -122,7 +122,7 @@ let DocumentFileService = DocumentFileService_1 = class DocumentFileService exte
|
|
|
122
122
|
? await this.#fileUploadObjectStorage.getContent(content.uploadId)
|
|
123
123
|
: (isUint8Array(content) ? content : await readBinaryStream(content));
|
|
124
124
|
const hash = await digest('SHA-256', contentAsUint8Array).toHex();
|
|
125
|
-
const mimeType = await getMimeType(contentAsUint8Array);
|
|
125
|
+
const mimeType = await getMimeType(contentAsUint8Array, 'application/octet-stream');
|
|
126
126
|
const metadata = {
|
|
127
127
|
mimeType,
|
|
128
128
|
size: contentAsUint8Array.length,
|
|
@@ -188,6 +188,7 @@ let DocumentManagementAiService = DocumentManagementAiService_1 = class Document
|
|
|
188
188
|
{
|
|
189
189
|
text: `Extrahiere den Inhalt des Dokuments in das angegebenen JSON Schema.
|
|
190
190
|
|
|
191
|
+
Vermeide es, den Titel im Untertitel zu wiederholen.
|
|
191
192
|
Gib in der summary ausführlich an, welche Informationen in dem Dokument vorkommen (ohne konkrete Werte).
|
|
192
193
|
Erstelle bis zu 7 möglichst spezifische Tags.
|
|
193
194
|
Antworte auf deutsch.`,
|
|
@@ -346,5 +347,8 @@ DocumentManagementAiService = DocumentManagementAiService_1 = __decorate([
|
|
|
346
347
|
], DocumentManagementAiService);
|
|
347
348
|
export { DocumentManagementAiService };
|
|
348
349
|
function getDescriptiveTypeLabels(categories, prefix = 'Category: ') {
|
|
349
|
-
return categories.flatMap((category) => [
|
|
350
|
+
return categories.flatMap((category) => [
|
|
351
|
+
...category.types.map((type) => ({ id: type.id, label: `${prefix}${category.label} | Type: ${type.label}` })),
|
|
352
|
+
...getDescriptiveTypeLabels(category.children, `${prefix}${category.label} -> `),
|
|
353
|
+
]);
|
|
350
354
|
}
|