@tstdl/base 0.93.97 → 0.93.98

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 (48) hide show
  1. package/audit/auditor.d.ts +1 -1
  2. package/cookie/cookie.js +5 -1
  3. package/css/css-variables.d.ts +38 -0
  4. package/css/css-variables.js +38 -0
  5. package/document-management/api/document-management.api.d.ts +15 -1
  6. package/document-management/api/document-management.api.js +8 -1
  7. package/document-management/models/document-category.model.js +0 -1
  8. package/document-management/models/document-property.model.js +0 -1
  9. package/document-management/server/api/document-management.api.d.ts +1 -0
  10. package/document-management/server/api/document-management.api.js +13 -1
  11. package/document-management/server/drizzle/{0000_needy_steel_serpent.sql → 0000_silly_chimera.sql} +0 -2
  12. package/document-management/server/drizzle/meta/0000_snapshot.json +1 -15
  13. package/document-management/server/drizzle/meta/_journal.json +2 -2
  14. package/document-management/server/services/document-statistics.service.d.ts +6 -0
  15. package/document-management/server/services/document-statistics.service.js +167 -0
  16. package/document-management/server/services/index.d.ts +1 -0
  17. package/document-management/server/services/index.js +1 -0
  18. package/document-management/service-models/document-statistics.view-model.d.ts +38 -0
  19. package/document-management/service-models/document-statistics.view-model.js +160 -0
  20. package/document-management/service-models/index.d.ts +1 -0
  21. package/document-management/service-models/index.js +1 -0
  22. package/document-management/tests/document-management-core.test.js +2 -2
  23. package/document-management/tests/document-management.api.test.d.ts +1 -0
  24. package/document-management/tests/document-management.api.test.js +102 -0
  25. package/document-management/tests/document-statistics.service.test.d.ts +1 -0
  26. package/document-management/tests/document-statistics.service.test.js +495 -0
  27. package/document-management/tests/enum-helpers.test.js +3 -2
  28. package/enumeration/enumeration.d.ts +24 -0
  29. package/enumeration/enumeration.js +20 -0
  30. package/examples/document-management/main.js +1 -1
  31. package/intl/number-parser.d.ts +16 -9
  32. package/intl/number-parser.js +31 -19
  33. package/module/module.js +3 -0
  34. package/object-storage/google/google.object-storage-provider.d.ts +0 -1
  35. package/object-storage/google/google.object-storage-provider.js +0 -1
  36. package/object-storage/index.d.ts +0 -1
  37. package/object-storage/index.js +0 -1
  38. package/object-storage/s3/s3.object-storage-provider.d.ts +0 -1
  39. package/object-storage/s3/s3.object-storage-provider.js +0 -1
  40. package/package.json +1 -1
  41. package/pool/pool.d.ts +1 -1
  42. package/promise/cancelable-promise.d.ts +1 -0
  43. package/promise/cancelable-promise.js +1 -0
  44. package/promise/index.d.ts +1 -0
  45. package/promise/index.js +1 -0
  46. package/random/number-generator/index.d.ts +1 -0
  47. package/random/number-generator/index.js +1 -0
  48. package/sse/data-stream.js +16 -3
@@ -0,0 +1,160 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var _a, _b, _c;
11
+ import { BooleanProperty, Integer, Property, StringProperty } from '../../schema/index.js';
12
+ import { DocumentApproval } from '../models/document.model.js';
13
+ export class DocumentApprovalBreakdown {
14
+ [_a = DocumentApproval.Pending];
15
+ [_b = DocumentApproval.Approved];
16
+ [_c = DocumentApproval.Rejected];
17
+ }
18
+ __decorate([
19
+ Integer(),
20
+ __metadata("design:type", Number)
21
+ ], DocumentApprovalBreakdown.prototype, _a, void 0);
22
+ __decorate([
23
+ Integer(),
24
+ __metadata("design:type", Number)
25
+ ], DocumentApprovalBreakdown.prototype, _b, void 0);
26
+ __decorate([
27
+ Integer(),
28
+ __metadata("design:type", Number)
29
+ ], DocumentApprovalBreakdown.prototype, _c, void 0);
30
+ export class DocumentDataQualityMetrics {
31
+ missingType;
32
+ missingDate;
33
+ missingTitle;
34
+ }
35
+ __decorate([
36
+ Integer(),
37
+ __metadata("design:type", Number)
38
+ ], DocumentDataQualityMetrics.prototype, "missingType", void 0);
39
+ __decorate([
40
+ Integer(),
41
+ __metadata("design:type", Number)
42
+ ], DocumentDataQualityMetrics.prototype, "missingDate", void 0);
43
+ __decorate([
44
+ Integer(),
45
+ __metadata("design:type", Number)
46
+ ], DocumentDataQualityMetrics.prototype, "missingTitle", void 0);
47
+ export class DocumentStatistics {
48
+ totalCount;
49
+ approvalBreakdown;
50
+ typeBreakdown;
51
+ storageUsage;
52
+ mimeTypeDistribution;
53
+ dataQuality;
54
+ createdLast30Days;
55
+ tagUsage;
56
+ totalPages;
57
+ validationFailures;
58
+ }
59
+ __decorate([
60
+ Integer({ optional: true }),
61
+ __metadata("design:type", Number)
62
+ ], DocumentStatistics.prototype, "totalCount", void 0);
63
+ __decorate([
64
+ Property(DocumentApprovalBreakdown, { optional: true }),
65
+ __metadata("design:type", DocumentApprovalBreakdown)
66
+ ], DocumentStatistics.prototype, "approvalBreakdown", void 0);
67
+ __decorate([
68
+ Property(Object, { optional: true }),
69
+ __metadata("design:type", Object)
70
+ ], DocumentStatistics.prototype, "typeBreakdown", void 0);
71
+ __decorate([
72
+ Integer({ optional: true }),
73
+ __metadata("design:type", Number)
74
+ ], DocumentStatistics.prototype, "storageUsage", void 0);
75
+ __decorate([
76
+ Property(Object, { optional: true }),
77
+ __metadata("design:type", Object)
78
+ ], DocumentStatistics.prototype, "mimeTypeDistribution", void 0);
79
+ __decorate([
80
+ Property(DocumentDataQualityMetrics, { optional: true }),
81
+ __metadata("design:type", DocumentDataQualityMetrics)
82
+ ], DocumentStatistics.prototype, "dataQuality", void 0);
83
+ __decorate([
84
+ Integer({ optional: true }),
85
+ __metadata("design:type", Number)
86
+ ], DocumentStatistics.prototype, "createdLast30Days", void 0);
87
+ __decorate([
88
+ Property(Object, { optional: true }),
89
+ __metadata("design:type", Object)
90
+ ], DocumentStatistics.prototype, "tagUsage", void 0);
91
+ __decorate([
92
+ Integer({ optional: true }),
93
+ __metadata("design:type", Number)
94
+ ], DocumentStatistics.prototype, "totalPages", void 0);
95
+ __decorate([
96
+ Integer({ optional: true }),
97
+ __metadata("design:type", Number)
98
+ ], DocumentStatistics.prototype, "validationFailures", void 0);
99
+ export class GetDocumentStatisticsOptions {
100
+ includeTotalCount;
101
+ includeApprovalBreakdown;
102
+ includeTypeBreakdown;
103
+ includeStorageUsage;
104
+ includeMimeTypeDistribution;
105
+ includeDataQuality;
106
+ includeCreatedLast30Days;
107
+ includeTagUsage;
108
+ includeTotalPages;
109
+ includeValidationFailures;
110
+ collectionIds;
111
+ categoryIds;
112
+ }
113
+ __decorate([
114
+ BooleanProperty({ optional: true }),
115
+ __metadata("design:type", Boolean)
116
+ ], GetDocumentStatisticsOptions.prototype, "includeTotalCount", void 0);
117
+ __decorate([
118
+ BooleanProperty({ optional: true }),
119
+ __metadata("design:type", Boolean)
120
+ ], GetDocumentStatisticsOptions.prototype, "includeApprovalBreakdown", void 0);
121
+ __decorate([
122
+ BooleanProperty({ optional: true }),
123
+ __metadata("design:type", Boolean)
124
+ ], GetDocumentStatisticsOptions.prototype, "includeTypeBreakdown", void 0);
125
+ __decorate([
126
+ BooleanProperty({ optional: true }),
127
+ __metadata("design:type", Boolean)
128
+ ], GetDocumentStatisticsOptions.prototype, "includeStorageUsage", void 0);
129
+ __decorate([
130
+ BooleanProperty({ optional: true }),
131
+ __metadata("design:type", Boolean)
132
+ ], GetDocumentStatisticsOptions.prototype, "includeMimeTypeDistribution", void 0);
133
+ __decorate([
134
+ BooleanProperty({ optional: true }),
135
+ __metadata("design:type", Boolean)
136
+ ], GetDocumentStatisticsOptions.prototype, "includeDataQuality", void 0);
137
+ __decorate([
138
+ BooleanProperty({ optional: true }),
139
+ __metadata("design:type", Boolean)
140
+ ], GetDocumentStatisticsOptions.prototype, "includeCreatedLast30Days", void 0);
141
+ __decorate([
142
+ BooleanProperty({ optional: true }),
143
+ __metadata("design:type", Boolean)
144
+ ], GetDocumentStatisticsOptions.prototype, "includeTagUsage", void 0);
145
+ __decorate([
146
+ BooleanProperty({ optional: true }),
147
+ __metadata("design:type", Boolean)
148
+ ], GetDocumentStatisticsOptions.prototype, "includeTotalPages", void 0);
149
+ __decorate([
150
+ BooleanProperty({ optional: true }),
151
+ __metadata("design:type", Boolean)
152
+ ], GetDocumentStatisticsOptions.prototype, "includeValidationFailures", void 0);
153
+ __decorate([
154
+ StringProperty({ array: true }),
155
+ __metadata("design:type", Array)
156
+ ], GetDocumentStatisticsOptions.prototype, "collectionIds", void 0);
157
+ __decorate([
158
+ StringProperty({ array: true, optional: true }),
159
+ __metadata("design:type", Array)
160
+ ], GetDocumentStatisticsOptions.prototype, "categoryIds", void 0);
@@ -3,6 +3,7 @@ export * from './document-collection-metadata.service-model.js';
3
3
  export * from './document-folders.view-model.js';
4
4
  export * from './document-management.view-model.js';
5
5
  export * from './document-requests-template.view-model.js';
6
+ export * from './document-statistics.view-model.js';
6
7
  export * from './document.service-model.js';
7
8
  export * from './enriched/index.js';
8
9
  export * from './stats.view-model.js';
@@ -3,6 +3,7 @@ export * from './document-collection-metadata.service-model.js';
3
3
  export * from './document-folders.view-model.js';
4
4
  export * from './document-management.view-model.js';
5
5
  export * from './document-requests-template.view-model.js';
6
+ export * from './document-statistics.view-model.js';
6
7
  export * from './document.service-model.js';
7
8
  export * from './enriched/index.js';
8
9
  export * from './stats.view-model.js';
@@ -4,7 +4,7 @@ import { AiModuleOptions } from '../../ai/module.js';
4
4
  import { runInInjectionContext } from '../../injector/index.js';
5
5
  import { ObjectStorage } from '../../object-storage/index.js';
6
6
  import { TaskQueue } from '../../task-queue/index.js';
7
- import { setupIntegrationTest, truncateTables } from '../../unit-test/index.js';
7
+ import { setupIntegrationTest, clearTenantData } from '../../unit-test/index.js';
8
8
  import { configureDocumentManagement } from '../server/configure.js';
9
9
  import { migrateDocumentManagementSchema } from '../server/module.js';
10
10
  import { DocumentCategoryTypeService } from '../server/services/document-category-type.service.js';
@@ -72,7 +72,7 @@ describe('Document Management Core', () => {
72
72
  await injector?.dispose();
73
73
  });
74
74
  beforeEach(async () => {
75
- await truncateTables(database, schema, ['request_collection_assignment', 'collection_assignment', 'workflow', 'request', 'document', 'collection', 'type', 'category']);
75
+ await clearTenantData(database, schema, ['request_collection_assignment', 'collection_assignment', 'workflow', 'request', 'document', 'collection', 'type', 'category'], tenantId);
76
76
  });
77
77
  // --- Collection Management ---
78
78
  test('Create and load collection', async () => {
@@ -0,0 +1,102 @@
1
+ import { afterAll, beforeAll, beforeEach, describe, expect, test, vi } from 'vitest';
2
+ import { AiService } from '../../ai/ai.service.js';
3
+ import { AiModuleOptions } from '../../ai/module.js';
4
+ import { runInInjectionContext } from '../../injector/index.js';
5
+ import { ObjectStorage } from '../../object-storage/index.js';
6
+ import { TaskQueue } from '../../task-queue/index.js';
7
+ import { clearTenantData, setupIntegrationTest } from '../../unit-test/index.js';
8
+ import { DocumentManagementAuthorizationService } from '../authorization/document-management-authorization.service.js';
9
+ import { DocumentManagementApiController } from '../server/api/document-management.api.js';
10
+ import { configureDocumentManagement } from '../server/configure.js';
11
+ import { migrateDocumentManagementSchema } from '../server/module.js';
12
+ import { DocumentCollectionService } from '../server/services/document-collection.service.js';
13
+ import { DocumentService } from '../server/services/document.service.js';
14
+ import { TestDocumentManagementAncillaryService, TestDocumentManagementAuthorizationService } from './helper.js';
15
+ describe('DocumentManagementApi Stats', () => {
16
+ let injector;
17
+ let database;
18
+ let controller;
19
+ let documentService;
20
+ let collectionService;
21
+ const schema = 'document_management';
22
+ const tenantId = crypto.randomUUID();
23
+ beforeAll(async () => {
24
+ ({ injector, database } = await setupIntegrationTest({
25
+ modules: { taskQueue: false, messageBus: true },
26
+ orm: { schema },
27
+ }));
28
+ injector.register(AiModuleOptions, { useValue: {} });
29
+ injector.register(AiService, { useValue: { processFile: vi.fn() } });
30
+ injector.register(ObjectStorage, {
31
+ useValue: {
32
+ uploadObject: vi.fn(),
33
+ getDownloadUrl: vi.fn(),
34
+ getContent: vi.fn(),
35
+ getContentStream: vi.fn(),
36
+ getObject: vi.fn(),
37
+ exists: vi.fn(),
38
+ },
39
+ });
40
+ injector.register(TaskQueue, {
41
+ useValue: {
42
+ enqueue: vi.fn(),
43
+ enqueueMany: vi.fn(),
44
+ process: vi.fn(),
45
+ },
46
+ });
47
+ configureDocumentManagement({
48
+ ancillaryService: TestDocumentManagementAncillaryService,
49
+ authorizationService: TestDocumentManagementAuthorizationService,
50
+ fileObjectStorageModule: 'documents',
51
+ fileUploadObjectStorageModule: 'document-uploads',
52
+ filePreviewObjectStorageModule: 'document-previews',
53
+ });
54
+ await runInInjectionContext(injector, migrateDocumentManagementSchema);
55
+ controller = await injector.resolveAsync(DocumentManagementApiController);
56
+ documentService = await injector.resolveAsync(DocumentService);
57
+ collectionService = await injector.resolveAsync(DocumentCollectionService);
58
+ });
59
+ afterAll(async () => {
60
+ await injector?.dispose();
61
+ });
62
+ beforeEach(async () => {
63
+ await clearTenantData(database, schema, ['collection_assignment', 'workflow', 'document', 'collection', 'tag', 'type', 'category'], tenantId);
64
+ });
65
+ test('getStatistics API endpoint', async () => {
66
+ await runInInjectionContext(injector, async () => {
67
+ const collection = await collectionService.createCollection(tenantId, null);
68
+ const authService = injector.resolve(DocumentManagementAuthorizationService);
69
+ vi.spyOn(authService, 'getTenantId').mockResolvedValue(tenantId);
70
+ await documentService.create(tenantId, {
71
+ assignment: { collections: [collection.id] },
72
+ skipWorkflow: true,
73
+ }, new Uint8Array([1, 2, 3]));
74
+ const mockContext = {
75
+ getToken: async () => ({ payload: { tenantId } }),
76
+ parameters: {
77
+ includeTotalCount: true,
78
+ includeStorageUsage: true,
79
+ collectionIds: [collection.id]
80
+ }
81
+ };
82
+ const stats = await controller.getStatistics(mockContext);
83
+ expect(stats.totalCount).toBe(1);
84
+ expect(stats.storageUsage).toBe(3);
85
+ });
86
+ });
87
+ test('getStatistics API endpoint should deny access if collection is restricted', async () => {
88
+ await runInInjectionContext(injector, async () => {
89
+ const authService = injector.resolve(DocumentManagementAuthorizationService);
90
+ vi.spyOn(authService, 'getTenantId').mockResolvedValue(tenantId);
91
+ vi.spyOn(authService, 'canReadCollection').mockResolvedValue(false);
92
+ const mockContext = {
93
+ getToken: async () => ({ payload: { tenantId } }),
94
+ parameters: {
95
+ includeTotalCount: true,
96
+ collectionIds: ['some-collection-id']
97
+ }
98
+ };
99
+ await expect(controller.getStatistics(mockContext)).rejects.toThrow('You are not allowed to read collection some-collection-id');
100
+ });
101
+ });
102
+ });