@tstdl/base 0.92.138 → 0.92.140
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/ai/ai.service.js +1 -1
- package/css/css-variables.d.ts +14 -0
- package/css/css-variables.js +55 -0
- package/css/index.d.ts +1 -0
- package/css/index.js +1 -0
- package/document-management/api/document-management.api.d.ts +59 -0
- package/document-management/api/document-management.api.js +28 -0
- package/document-management/server/api/document-management.api.d.ts +4 -1
- package/document-management/server/api/document-management.api.js +61 -28
- 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 +10 -2
- package/document-management/server/services/document-management.service.js +69 -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/api/streaming.js +8 -8
- 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 +29 -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/package.json +5 -3
- package/schema/converters/openapi-converter.js +15 -12
- package/sse/server-sent-events-source.js +2 -2
- package/utils/object/object.js +1 -1
package/ai/ai.service.js
CHANGED
|
@@ -155,7 +155,7 @@ let AiService = AiService_1 = class AiService {
|
|
|
155
155
|
break;
|
|
156
156
|
}
|
|
157
157
|
catch (error) {
|
|
158
|
-
if ((i < 20) && isError(error) && ((
|
|
158
|
+
if ((i < 20) && isError(error) && (error.message.includes('429 Too Many Requests') || (error.message.includes('503 Service Unavailable')))) {
|
|
159
159
|
this.#logger.verbose('429 Too Many Requests - trying again in 15 seconds');
|
|
160
160
|
const canceled = await cancelableTimeout(15 * millisecondsPerSecond, getShutdownSignal());
|
|
161
161
|
if (!canceled) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class CssVariables implements Disposable {
|
|
2
|
+
#private;
|
|
3
|
+
readonly selector: string;
|
|
4
|
+
readonly prefix: string;
|
|
5
|
+
constructor(selector: string | null, prefix?: string);
|
|
6
|
+
[Symbol.dispose](): void;
|
|
7
|
+
set(name: string, value: string): void;
|
|
8
|
+
setMany(variables: Record<string, string> | [string, string][]): void;
|
|
9
|
+
get(name: string): string | null;
|
|
10
|
+
delete(name: string): void;
|
|
11
|
+
clear(): void;
|
|
12
|
+
private _prefix;
|
|
13
|
+
}
|
|
14
|
+
export declare function cssVariables(selector?: string | null, prefix?: string): CssVariables;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { objectEntries } from '../utils/object/object.js';
|
|
2
|
+
import { isArray } from '../utils/type-guards.js';
|
|
3
|
+
export class CssVariables {
|
|
4
|
+
#styleSheet = new CSSStyleSheet();
|
|
5
|
+
#cssRule;
|
|
6
|
+
selector;
|
|
7
|
+
prefix;
|
|
8
|
+
constructor(selector, prefix = '') {
|
|
9
|
+
this.selector = selector ?? ':root';
|
|
10
|
+
this.prefix = prefix;
|
|
11
|
+
document.adoptedStyleSheets.push(this.#styleSheet);
|
|
12
|
+
this.#cssRule = createCssRule(this.#styleSheet, `${this.selector} {}`);
|
|
13
|
+
}
|
|
14
|
+
[Symbol.dispose]() {
|
|
15
|
+
const index = document.adoptedStyleSheets.indexOf(this.#styleSheet);
|
|
16
|
+
if (index != -1) {
|
|
17
|
+
document.adoptedStyleSheets.splice(index, 1);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
set(name, value) {
|
|
21
|
+
const prefixed = this._prefix(name);
|
|
22
|
+
this.#cssRule.style.setProperty(prefixed, value);
|
|
23
|
+
}
|
|
24
|
+
setMany(variables) {
|
|
25
|
+
const entries = isArray(variables) ? variables : objectEntries(variables);
|
|
26
|
+
for (const [name, value] of entries) {
|
|
27
|
+
this.set(name, value);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
get(name) {
|
|
31
|
+
const prefixed = this._prefix(name);
|
|
32
|
+
const rawValue = this.#cssRule.style.getPropertyValue(prefixed);
|
|
33
|
+
if (rawValue.length == 0) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
return rawValue;
|
|
37
|
+
}
|
|
38
|
+
delete(name) {
|
|
39
|
+
const prefixed = this._prefix(name);
|
|
40
|
+
this.#cssRule.style.removeProperty(prefixed);
|
|
41
|
+
}
|
|
42
|
+
clear() {
|
|
43
|
+
this.#cssRule.style.cssText = '';
|
|
44
|
+
}
|
|
45
|
+
_prefix(name) {
|
|
46
|
+
return name.startsWith('--') ? name : `--${this.prefix}${name}`;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export function cssVariables(selector = null, prefix = '') {
|
|
50
|
+
return new CssVariables(selector, prefix);
|
|
51
|
+
}
|
|
52
|
+
function createCssRule(styleSheet, rule) {
|
|
53
|
+
const index = styleSheet.insertRule(rule);
|
|
54
|
+
return styleSheet.cssRules[index];
|
|
55
|
+
}
|
package/css/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './css-variables.js';
|
package/css/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './css-variables.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ServerSentEvents } from '../../sse/server-sent-events.js';
|
|
1
2
|
import { Document, DocumentCategory, DocumentRequest, DocumentRequestsTemplate, DocumentRequestTemplate, DocumentType } from '../models/index.js';
|
|
2
3
|
import { DocumentCategoryView, DocumentManagementData, DocumentRequestsTemplateData } from '../service-models/index.js';
|
|
3
4
|
export type DocumentManagementApiDefinition = typeof documentManagementApiDefinition;
|
|
@@ -13,6 +14,15 @@ export declare const documentManagementApiDefinition: {
|
|
|
13
14
|
result: typeof DocumentManagementData;
|
|
14
15
|
credentials: true;
|
|
15
16
|
};
|
|
17
|
+
loadDataStream: {
|
|
18
|
+
resource: string;
|
|
19
|
+
method: "GET";
|
|
20
|
+
parameters: import("../../schema/index.js").ObjectSchema<{
|
|
21
|
+
collectionIds: string | string[];
|
|
22
|
+
}>;
|
|
23
|
+
result: typeof ServerSentEvents;
|
|
24
|
+
credentials: true;
|
|
25
|
+
};
|
|
16
26
|
loadDocumentRequestsTemplateData: {
|
|
17
27
|
resource: string;
|
|
18
28
|
method: "GET";
|
|
@@ -45,6 +55,26 @@ export declare const documentManagementApiDefinition: {
|
|
|
45
55
|
result: import("../../schema/index.js").StringSchema;
|
|
46
56
|
credentials: true;
|
|
47
57
|
};
|
|
58
|
+
loadPreview: {
|
|
59
|
+
resource: string;
|
|
60
|
+
method: "GET";
|
|
61
|
+
parameters: import("../../schema/index.js").ObjectSchema<{
|
|
62
|
+
id: string;
|
|
63
|
+
page: number;
|
|
64
|
+
}>;
|
|
65
|
+
result: Uint8ArrayConstructor;
|
|
66
|
+
credentials: true;
|
|
67
|
+
};
|
|
68
|
+
getPreviewUrl: {
|
|
69
|
+
resource: string;
|
|
70
|
+
method: "GET";
|
|
71
|
+
parameters: import("../../schema/index.js").ObjectSchema<{
|
|
72
|
+
id: string;
|
|
73
|
+
page: number;
|
|
74
|
+
}>;
|
|
75
|
+
result: import("../../schema/index.js").StringSchema;
|
|
76
|
+
credentials: true;
|
|
77
|
+
};
|
|
48
78
|
createCategory: {
|
|
49
79
|
resource: string;
|
|
50
80
|
method: "POST";
|
|
@@ -326,6 +356,15 @@ declare const _DocumentManagementApi: import("../../api/client/index.js").ApiCli
|
|
|
326
356
|
result: typeof DocumentManagementData;
|
|
327
357
|
credentials: true;
|
|
328
358
|
};
|
|
359
|
+
loadDataStream: {
|
|
360
|
+
resource: string;
|
|
361
|
+
method: "GET";
|
|
362
|
+
parameters: import("../../schema/index.js").ObjectSchema<{
|
|
363
|
+
collectionIds: string | string[];
|
|
364
|
+
}>;
|
|
365
|
+
result: typeof ServerSentEvents;
|
|
366
|
+
credentials: true;
|
|
367
|
+
};
|
|
329
368
|
loadDocumentRequestsTemplateData: {
|
|
330
369
|
resource: string;
|
|
331
370
|
method: "GET";
|
|
@@ -358,6 +397,26 @@ declare const _DocumentManagementApi: import("../../api/client/index.js").ApiCli
|
|
|
358
397
|
result: import("../../schema/index.js").StringSchema;
|
|
359
398
|
credentials: true;
|
|
360
399
|
};
|
|
400
|
+
loadPreview: {
|
|
401
|
+
resource: string;
|
|
402
|
+
method: "GET";
|
|
403
|
+
parameters: import("../../schema/index.js").ObjectSchema<{
|
|
404
|
+
id: string;
|
|
405
|
+
page: number;
|
|
406
|
+
}>;
|
|
407
|
+
result: Uint8ArrayConstructor;
|
|
408
|
+
credentials: true;
|
|
409
|
+
};
|
|
410
|
+
getPreviewUrl: {
|
|
411
|
+
resource: string;
|
|
412
|
+
method: "GET";
|
|
413
|
+
parameters: import("../../schema/index.js").ObjectSchema<{
|
|
414
|
+
id: string;
|
|
415
|
+
page: number;
|
|
416
|
+
}>;
|
|
417
|
+
result: import("../../schema/index.js").StringSchema;
|
|
418
|
+
credentials: true;
|
|
419
|
+
};
|
|
361
420
|
createCategory: {
|
|
362
421
|
resource: string;
|
|
363
422
|
method: "POST";
|
|
@@ -8,6 +8,7 @@ import { compileClient } from '../../api/client/index.js';
|
|
|
8
8
|
import { defineApi } from '../../api/index.js';
|
|
9
9
|
import { ReplaceClass } from '../../injector/decorators.js';
|
|
10
10
|
import { array, boolean, literal, number, object, optional, string } from '../../schema/index.js';
|
|
11
|
+
import { ServerSentEvents } from '../../sse/server-sent-events.js';
|
|
11
12
|
import { Document, DocumentCategory, DocumentRequest, DocumentRequestsTemplate, DocumentRequestTemplate, DocumentType } from '../models/index.js';
|
|
12
13
|
import { addOrArchiveDocumentToOrFromCollectionParametersSchema, applyDocumentRequestsTemplateParametersSchema, createDocumentCategoryParametersSchema, createDocumentParametersSchema, createDocumentRequestParametersSchema, createDocumentRequestsTemplateParametersSchema, createDocumentRequestTemplateParametersSchema, createDocumentTypeParametersSchema, deleteDocumentRequestParametersSchema, deleteDocumentRequestsTemplateParametersSchema, deleteDocumentRequestTemplateParametersSchema, DocumentCategoryView, DocumentManagementData, DocumentRequestsTemplateData, loadDataParametersSchema, updateDocumentParametersSchema, updateDocumentRequestParametersSchema, updateDocumentRequestsTemplateParametersSchema, updateDocumentRequestTemplateParametersSchema } from '../service-models/index.js';
|
|
13
14
|
export const documentManagementApiDefinition = defineApi({
|
|
@@ -20,6 +21,13 @@ export const documentManagementApiDefinition = defineApi({
|
|
|
20
21
|
result: DocumentManagementData,
|
|
21
22
|
credentials: true,
|
|
22
23
|
},
|
|
24
|
+
loadDataStream: {
|
|
25
|
+
resource: 'data/stream',
|
|
26
|
+
method: 'GET',
|
|
27
|
+
parameters: loadDataParametersSchema,
|
|
28
|
+
result: ServerSentEvents,
|
|
29
|
+
credentials: true,
|
|
30
|
+
},
|
|
23
31
|
loadDocumentRequestsTemplateData: {
|
|
24
32
|
resource: 'views/document-requests-template-data',
|
|
25
33
|
method: 'GET',
|
|
@@ -52,6 +60,26 @@ export const documentManagementApiDefinition = defineApi({
|
|
|
52
60
|
result: string(),
|
|
53
61
|
credentials: true,
|
|
54
62
|
},
|
|
63
|
+
loadPreview: {
|
|
64
|
+
resource: 'documents/:id/preview/:page',
|
|
65
|
+
method: 'GET',
|
|
66
|
+
parameters: object({
|
|
67
|
+
id: string(),
|
|
68
|
+
page: number({ coerce: true }),
|
|
69
|
+
}),
|
|
70
|
+
result: Uint8Array,
|
|
71
|
+
credentials: true,
|
|
72
|
+
},
|
|
73
|
+
getPreviewUrl: {
|
|
74
|
+
resource: 'documents/:id/preview/:page/url',
|
|
75
|
+
method: 'GET',
|
|
76
|
+
parameters: object({
|
|
77
|
+
id: string(),
|
|
78
|
+
page: number({ coerce: true }),
|
|
79
|
+
}),
|
|
80
|
+
result: string(),
|
|
81
|
+
credentials: true,
|
|
82
|
+
},
|
|
55
83
|
createCategory: {
|
|
56
84
|
resource: 'categories',
|
|
57
85
|
method: 'POST',
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ApiController, type ApiRequestContext, type ApiServerResult } from '../../../api/index.js';
|
|
2
2
|
import { type DocumentManagementApiDefinition } from '../../../document-management/api/index.js';
|
|
3
3
|
export declare class DocumentManagementApiController implements ApiController<DocumentManagementApiDefinition> {
|
|
4
4
|
#private;
|
|
5
5
|
loadData(context: ApiRequestContext<DocumentManagementApiDefinition, 'loadData'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'loadData'>>;
|
|
6
|
+
loadDataStream(context: ApiRequestContext<DocumentManagementApiDefinition, 'loadDataStream'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'loadDataStream'>>;
|
|
6
7
|
loadDocumentRequestsTemplateData(context: ApiRequestContext<DocumentManagementApiDefinition, 'loadDocumentRequestsTemplateData'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'loadDocumentRequestsTemplateData'>>;
|
|
7
8
|
loadAvailableCategories(context: ApiRequestContext<DocumentManagementApiDefinition, 'loadAvailableCategories'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'loadAvailableCategories'>>;
|
|
8
9
|
loadContent(context: ApiRequestContext<DocumentManagementApiDefinition, 'loadContent'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'loadContent'>>;
|
|
9
10
|
getContentUrl(context: ApiRequestContext<DocumentManagementApiDefinition, 'getContentUrl'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'getContentUrl'>>;
|
|
11
|
+
loadPreview(context: ApiRequestContext<DocumentManagementApiDefinition, 'loadPreview'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'loadPreview'>>;
|
|
12
|
+
getPreviewUrl(context: ApiRequestContext<DocumentManagementApiDefinition, 'getPreviewUrl'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'getPreviewUrl'>>;
|
|
10
13
|
createCategory(context: ApiRequestContext<DocumentManagementApiDefinition, 'createCategory'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'createCategory'>>;
|
|
11
14
|
createType(context: ApiRequestContext<DocumentManagementApiDefinition, 'createType'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'createType'>>;
|
|
12
15
|
initiateDocumentUpload(context: ApiRequestContext<DocumentManagementApiDefinition, 'initiateDocumentUpload'>): Promise<ApiServerResult<DocumentManagementApiDefinition, 'initiateDocumentUpload'>>;
|
|
@@ -6,45 +6,66 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
var _a;
|
|
8
8
|
var DocumentManagementApiController_1;
|
|
9
|
+
import { match, P } from 'ts-pattern';
|
|
10
|
+
import { createErrorResponse } from '../../../api/index.js';
|
|
9
11
|
import { apiController } from '../../../api/server/index.js';
|
|
10
|
-
import { CancellationSignal } from '../../../cancellation/index.js';
|
|
11
12
|
import { documentManagementApiDefinition } from '../../../document-management/api/index.js';
|
|
12
13
|
import { DocumentRequestCollectionAssignment } from '../../../document-management/models/document-request-collection-assignment.model.js';
|
|
13
14
|
import { ForbiddenError, NotImplementedError } from '../../../errors/index.js';
|
|
14
15
|
import { HttpServerResponse } from '../../../http/index.js';
|
|
15
16
|
import { inject } from '../../../injector/index.js';
|
|
16
|
-
import { Logger } from '../../../logger/
|
|
17
|
+
import { Logger } from '../../../logger/logger.js';
|
|
17
18
|
import { injectRepository } from '../../../orm/server/repository.js';
|
|
19
|
+
import { ServerSentEventsSource } from '../../../sse/server-sent-events-source.js';
|
|
18
20
|
import { toArray } from '../../../utils/array/index.js';
|
|
19
|
-
import {
|
|
20
|
-
import { DocumentCategoryTypeService,
|
|
21
|
+
import { tryIgnoreAsync } from '../../../utils/try-ignore.js';
|
|
22
|
+
import { DocumentCategoryTypeService, DocumentFileService, DocumentManagementAuthorizationService, DocumentManagementService, DocumentRequestService, DocumentService } from '../services/index.js';
|
|
21
23
|
let DocumentManagementApiController = DocumentManagementApiController_1 = class DocumentManagementApiController {
|
|
22
|
-
#
|
|
24
|
+
#authorizationService = inject(DocumentManagementAuthorizationService);
|
|
23
25
|
#documentCategoryTypeService = inject(DocumentCategoryTypeService);
|
|
24
|
-
#documentCollectionService = inject(DocumentCollectionService);
|
|
25
26
|
#documentFileService = inject(DocumentFileService);
|
|
26
|
-
#documentManagementAncillaryService = inject(DocumentManagementAncillaryService);
|
|
27
27
|
#documentManagementService = inject(DocumentManagementService);
|
|
28
|
-
#documentPropertyService = inject(DocumentPropertyService);
|
|
29
28
|
#documentRequestService = inject(DocumentRequestService);
|
|
30
29
|
#documentRequestCollectionAssignmentRepository = injectRepository(DocumentRequestCollectionAssignment);
|
|
31
30
|
#documentService = inject(DocumentService);
|
|
32
|
-
#documentWorkflowService = inject(DocumentWorkflowService);
|
|
33
|
-
#cancellationSignal = inject(CancellationSignal);
|
|
34
31
|
#logger = inject(Logger, DocumentManagementApiController_1.name);
|
|
35
32
|
async loadData(context) {
|
|
36
33
|
const token = await context.getToken();
|
|
37
34
|
for (const collectionId of context.parameters.collectionIds) {
|
|
38
|
-
const allowed = await this.#
|
|
35
|
+
const allowed = await this.#authorizationService.canReadCollection(collectionId, token);
|
|
39
36
|
if (!allowed) {
|
|
40
37
|
throw new ForbiddenError(`You are not allowed to read collection ${collectionId}`);
|
|
41
38
|
}
|
|
42
39
|
}
|
|
43
40
|
return await this.#documentManagementService.loadData(toArray(context.parameters.collectionIds));
|
|
44
41
|
}
|
|
42
|
+
async loadDataStream(context) {
|
|
43
|
+
const token = await context.getToken();
|
|
44
|
+
for (const collectionId of context.parameters.collectionIds) {
|
|
45
|
+
const allowed = await this.#authorizationService.canReadCollection(collectionId, token);
|
|
46
|
+
if (!allowed) {
|
|
47
|
+
throw new ForbiddenError(`You are not allowed to read collection ${collectionId}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const stream = this.#documentManagementService.loadDataStream(toArray(context.parameters.collectionIds));
|
|
51
|
+
const eventSource = new ServerSentEventsSource();
|
|
52
|
+
void (async () => {
|
|
53
|
+
try {
|
|
54
|
+
for await (const chunk of stream) {
|
|
55
|
+
await eventSource.sendJson({ name: 'data', data: chunk });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
this.#logger.error(error);
|
|
60
|
+
await tryIgnoreAsync(async () => await eventSource.sendJson({ name: 'error', data: createErrorResponse(error).error }));
|
|
61
|
+
await tryIgnoreAsync(async () => await eventSource.close());
|
|
62
|
+
}
|
|
63
|
+
})();
|
|
64
|
+
return eventSource;
|
|
65
|
+
}
|
|
45
66
|
async loadDocumentRequestsTemplateData(context) {
|
|
46
67
|
const token = await context.getToken();
|
|
47
|
-
const allowed = await this.#
|
|
68
|
+
const allowed = await this.#authorizationService.canReadDocumentRequestsTemplates(token);
|
|
48
69
|
if (!allowed) {
|
|
49
70
|
throw new ForbiddenError('You are not allowed to load document requests template data.');
|
|
50
71
|
}
|
|
@@ -56,29 +77,41 @@ let DocumentManagementApiController = DocumentManagementApiController_1 = class
|
|
|
56
77
|
}
|
|
57
78
|
async loadContent(context) {
|
|
58
79
|
const token = await context.getToken();
|
|
59
|
-
const allowed = await this.#
|
|
80
|
+
const allowed = await this.#authorizationService.canReadDocument(context.parameters.id, token);
|
|
60
81
|
if (!allowed) {
|
|
61
82
|
throw new ForbiddenError(`You are not allowed to load content for document ${context.parameters.id}.`);
|
|
62
83
|
}
|
|
63
84
|
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
|
-
});
|
|
85
|
+
return HttpServerResponse.redirect(url);
|
|
70
86
|
}
|
|
71
87
|
async getContentUrl(context) {
|
|
72
88
|
const token = await context.getToken();
|
|
73
|
-
const allowed = await this.#
|
|
89
|
+
const allowed = await this.#authorizationService.canReadDocument(context.parameters.id, token);
|
|
74
90
|
if (!allowed) {
|
|
75
91
|
throw new ForbiddenError(`You are not allowed to get content URL for document ${context.parameters.id}.`);
|
|
76
92
|
}
|
|
77
93
|
return await this.#documentService.getContentUrl(context.parameters.id, context.parameters.download);
|
|
78
94
|
}
|
|
95
|
+
async loadPreview(context) {
|
|
96
|
+
const token = await context.getToken();
|
|
97
|
+
const allowed = await this.#authorizationService.canReadDocument(context.parameters.id, token);
|
|
98
|
+
if (!allowed) {
|
|
99
|
+
throw new ForbiddenError(`You are not allowed to get content preview for document ${context.parameters.id}.`);
|
|
100
|
+
}
|
|
101
|
+
const url = await this.#documentService.getPreviewUrl(context.parameters.id, context.parameters.page);
|
|
102
|
+
return HttpServerResponse.redirect(url);
|
|
103
|
+
}
|
|
104
|
+
async getPreviewUrl(context) {
|
|
105
|
+
const token = await context.getToken();
|
|
106
|
+
const allowed = await this.#authorizationService.canReadDocument(context.parameters.id, token);
|
|
107
|
+
if (!allowed) {
|
|
108
|
+
throw new ForbiddenError(`You are not allowed to get content preview for document ${context.parameters.id}.`);
|
|
109
|
+
}
|
|
110
|
+
return await this.#documentService.getPreviewUrl(context.parameters.id, context.parameters.page);
|
|
111
|
+
}
|
|
79
112
|
async createCategory(context) {
|
|
80
113
|
const token = await context.getToken();
|
|
81
|
-
const allowed = await this.#
|
|
114
|
+
const allowed = await this.#authorizationService.canManageCategoriesAndTypes(token);
|
|
82
115
|
if (!allowed) {
|
|
83
116
|
throw new ForbiddenError('You are not allowed to create document categories.');
|
|
84
117
|
}
|
|
@@ -86,7 +119,7 @@ let DocumentManagementApiController = DocumentManagementApiController_1 = class
|
|
|
86
119
|
}
|
|
87
120
|
async createType(context) {
|
|
88
121
|
const token = await context.getToken();
|
|
89
|
-
const allowed = await this.#
|
|
122
|
+
const allowed = await this.#authorizationService.canManageCategoriesAndTypes(token);
|
|
90
123
|
if (!allowed) {
|
|
91
124
|
throw new ForbiddenError('You are not allowed to create document types.');
|
|
92
125
|
}
|
|
@@ -94,12 +127,12 @@ let DocumentManagementApiController = DocumentManagementApiController_1 = class
|
|
|
94
127
|
}
|
|
95
128
|
async initiateDocumentUpload(context) {
|
|
96
129
|
const token = await context.getToken();
|
|
97
|
-
const subject = await this.#
|
|
130
|
+
const subject = await this.#authorizationService.getSubject(token);
|
|
98
131
|
return await this.#documentFileService.initiateUpload({ key: subject, contentLength: context.parameters.contentLength });
|
|
99
132
|
}
|
|
100
133
|
async createDocument(context) {
|
|
101
134
|
const token = await context.getToken();
|
|
102
|
-
const subject = await this.#
|
|
135
|
+
const subject = await this.#authorizationService.getSubject(token);
|
|
103
136
|
const { uploadId, ...createParameters } = context.parameters;
|
|
104
137
|
const [collectionIds, requiresAssign] = await match(context.parameters.assignment)
|
|
105
138
|
.with({ collections: P.select() }, (collectionIds) => [toArray(collectionIds), true])
|
|
@@ -111,23 +144,23 @@ let DocumentManagementApiController = DocumentManagementApiController_1 = class
|
|
|
111
144
|
.with({ automatic: P.select() }, ({ scope }) => [toArray(scope), false])
|
|
112
145
|
.exhaustive();
|
|
113
146
|
for (const collectionId of collectionIds) {
|
|
114
|
-
const createDocumentsAllowed = await this.#
|
|
147
|
+
const createDocumentsAllowed = await this.#authorizationService.canCreateDocuments(collectionId, token);
|
|
115
148
|
if (!createDocumentsAllowed) {
|
|
116
149
|
throw new ForbiddenError(`You are not allowed to create documents in collection ${collectionId}.`);
|
|
117
150
|
}
|
|
118
151
|
if (requiresAssign) {
|
|
119
|
-
const assignDocumentsAllowed = await this.#
|
|
152
|
+
const assignDocumentsAllowed = await this.#authorizationService.canAssignDocuments(collectionId, token);
|
|
120
153
|
if (!assignDocumentsAllowed) {
|
|
121
154
|
throw new ForbiddenError(`You are not allowed to assign documents in collection ${collectionId}.`);
|
|
122
155
|
}
|
|
123
156
|
}
|
|
124
157
|
}
|
|
125
|
-
const actionUserId = await this.#
|
|
158
|
+
const actionUserId = await this.#authorizationService.getSubject(token);
|
|
126
159
|
return await this.#documentService.create(createParameters, { uploadId, uploadKey: subject }, { createUserId: actionUserId });
|
|
127
160
|
}
|
|
128
161
|
async createDocumentRequestsTemplate(context) {
|
|
129
162
|
const token = await context.getToken();
|
|
130
|
-
const allowed = await this.#
|
|
163
|
+
const allowed = await this.#authorizationService.canManageDocumentRequestsTemplates(token);
|
|
131
164
|
if (!allowed) {
|
|
132
165
|
throw new ForbiddenError('You are not allowed to create document requests template.');
|
|
133
166
|
}
|
|
@@ -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",
|