@twin.org/document-management-service 0.0.1-next.9 → 0.0.1
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/dist/cjs/index.cjs +303 -114
- package/dist/esm/index.mjs +304 -116
- package/dist/types/documentManagementRoutes.d.ts +10 -2
- package/dist/types/documentManagementService.d.ts +26 -1
- package/dist/types/models/IDocumentManagementStorageServiceConstructorOptions.d.ts +5 -0
- package/docs/changelog.md +181 -0
- package/docs/open-api/spec.json +444 -1350
- package/docs/reference/classes/DocumentManagementService.md +90 -0
- package/docs/reference/functions/documentManagementGetRevision.md +31 -0
- package/docs/reference/functions/documentManagementUpdate.md +1 -1
- package/docs/reference/index.md +1 -0
- package/docs/reference/interfaces/IDocumentManagementServiceConstructorOptions.md +14 -0
- package/locales/en.json +2 -1
- package/package.json +73 -15
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var auditableItemGraphModels = require('@twin.org/auditable-item-graph-models');
|
|
3
4
|
var core = require('@twin.org/core');
|
|
4
5
|
var documentManagementModels = require('@twin.org/document-management-models');
|
|
5
6
|
var standardsSchemaOrg = require('@twin.org/standards-schema-org');
|
|
6
7
|
var standardsUnece = require('@twin.org/standards-unece');
|
|
7
8
|
var web = require('@twin.org/web');
|
|
8
9
|
var attestationModels = require('@twin.org/attestation-models');
|
|
9
|
-
var auditableItemGraphModels = require('@twin.org/auditable-item-graph-models');
|
|
10
10
|
var blobStorageModels = require('@twin.org/blob-storage-models');
|
|
11
11
|
var crypto = require('@twin.org/crypto');
|
|
12
12
|
var dataJsonLd = require('@twin.org/data-json-ld');
|
|
@@ -147,9 +147,13 @@ function generateRestRoutesDocumentManagement(baseRouteName, componentName) {
|
|
|
147
147
|
id: "DocumentManagementGetResponseExample",
|
|
148
148
|
response: {
|
|
149
149
|
body: {
|
|
150
|
-
"@context": [
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
"@context": [
|
|
151
|
+
standardsSchemaOrg.SchemaOrgContexts.ContextRoot,
|
|
152
|
+
documentManagementModels.DocumentContexts.ContextRoot,
|
|
153
|
+
documentManagementModels.DocumentContexts.ContextRootCommon
|
|
154
|
+
],
|
|
155
|
+
type: standardsSchemaOrg.SchemaOrgTypes.ItemList,
|
|
156
|
+
[standardsSchemaOrg.SchemaOrgTypes.ItemListElement]: [
|
|
153
157
|
{
|
|
154
158
|
"@context": [
|
|
155
159
|
documentManagementModels.DocumentContexts.ContextRoot,
|
|
@@ -187,9 +191,13 @@ function generateRestRoutesDocumentManagement(baseRouteName, componentName) {
|
|
|
187
191
|
id: "DocumentManagementGetResponseExample",
|
|
188
192
|
response: {
|
|
189
193
|
body: {
|
|
190
|
-
"@context": [
|
|
191
|
-
|
|
192
|
-
|
|
194
|
+
"@context": [
|
|
195
|
+
standardsSchemaOrg.SchemaOrgContexts.ContextRoot,
|
|
196
|
+
documentManagementModels.DocumentContexts.ContextRoot,
|
|
197
|
+
documentManagementModels.DocumentContexts.ContextRootCommon
|
|
198
|
+
],
|
|
199
|
+
type: standardsSchemaOrg.SchemaOrgTypes.ItemList,
|
|
200
|
+
[standardsSchemaOrg.SchemaOrgTypes.ItemListElement]: [
|
|
193
201
|
{
|
|
194
202
|
"@context": [
|
|
195
203
|
documentManagementModels.DocumentContexts.ContextRoot,
|
|
@@ -224,7 +232,101 @@ function generateRestRoutesDocumentManagement(baseRouteName, componentName) {
|
|
|
224
232
|
}
|
|
225
233
|
]
|
|
226
234
|
};
|
|
227
|
-
const
|
|
235
|
+
const documentManagementGetRevisionRoute = {
|
|
236
|
+
operationId: "DocumentManagementGetRevision",
|
|
237
|
+
summary: "Get the data for a document revision from document management",
|
|
238
|
+
tag: tagsDocumentManagement[0].name,
|
|
239
|
+
method: "GET",
|
|
240
|
+
path: `${baseRouteName}/:auditableItemGraphDocumentId/:revision`,
|
|
241
|
+
handler: async (httpRequestContext, request) => documentManagementGetRevision(httpRequestContext, componentName, request),
|
|
242
|
+
requestType: {
|
|
243
|
+
type: "IDocumentManagementGetRequest",
|
|
244
|
+
examples: [
|
|
245
|
+
{
|
|
246
|
+
id: "DocumentManagementGetRevisionRequestExample",
|
|
247
|
+
request: {
|
|
248
|
+
pathParams: {
|
|
249
|
+
auditableItemGraphDocumentId: "aig:123456",
|
|
250
|
+
revision: "1"
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
]
|
|
255
|
+
},
|
|
256
|
+
responseType: [
|
|
257
|
+
{
|
|
258
|
+
type: "IDocumentManagementGetRevisionResponse",
|
|
259
|
+
examples: [
|
|
260
|
+
{
|
|
261
|
+
id: "DocumentManagementGetRevisionResponseExample",
|
|
262
|
+
response: {
|
|
263
|
+
body: {
|
|
264
|
+
"@context": [
|
|
265
|
+
documentManagementModels.DocumentContexts.ContextRoot,
|
|
266
|
+
documentManagementModels.DocumentContexts.ContextRootCommon,
|
|
267
|
+
standardsSchemaOrg.SchemaOrgContexts.ContextRoot
|
|
268
|
+
],
|
|
269
|
+
type: documentManagementModels.DocumentTypes.Document,
|
|
270
|
+
id: "2721000:0",
|
|
271
|
+
documentId: "2721000",
|
|
272
|
+
documentIdFormat: "bol",
|
|
273
|
+
documentCode: standardsUnece.UneceDocumentCodes.BillOfLading,
|
|
274
|
+
documentRevision: 1,
|
|
275
|
+
blobStorageId: "blob-memory:c57d94b088f4c6d2cb32ded014813d0c786aa00134c8ee22f84b1e2545602a70",
|
|
276
|
+
blobHash: "sha256:123456",
|
|
277
|
+
dateCreated: "2024-01-01T00:00:00Z",
|
|
278
|
+
annotationObject: {
|
|
279
|
+
"@context": "https://schema.org",
|
|
280
|
+
"@type": "DigitalDocument",
|
|
281
|
+
name: "myfile.pdf"
|
|
282
|
+
},
|
|
283
|
+
nodeIdentity: "did:entity-storage:0x6363636363636363636363636363636363636363636363636363636363636363",
|
|
284
|
+
userIdentity: "did:entity-storage:0x6363636363636363636363636363636363636363636363636363636363636363"
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
]
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
type: "IDocumentManagementGetRevisionResponse",
|
|
292
|
+
mimeType: web.MimeTypes.JsonLd,
|
|
293
|
+
examples: [
|
|
294
|
+
{
|
|
295
|
+
id: "DocumentManagementGetRevisionResponseExample",
|
|
296
|
+
response: {
|
|
297
|
+
body: {
|
|
298
|
+
"@context": [
|
|
299
|
+
documentManagementModels.DocumentContexts.ContextRoot,
|
|
300
|
+
documentManagementModels.DocumentContexts.ContextRootCommon,
|
|
301
|
+
standardsSchemaOrg.SchemaOrgContexts.ContextRoot
|
|
302
|
+
],
|
|
303
|
+
type: documentManagementModels.DocumentTypes.Document,
|
|
304
|
+
id: "2721000:0",
|
|
305
|
+
documentId: "2721000",
|
|
306
|
+
documentIdFormat: "bol",
|
|
307
|
+
documentCode: standardsUnece.UneceDocumentCodes.BillOfLading,
|
|
308
|
+
documentRevision: 1,
|
|
309
|
+
blobStorageId: "blob-memory:c57d94b088f4c6d2cb32ded014813d0c786aa00134c8ee22f84b1e2545602a70",
|
|
310
|
+
blobHash: "sha256:123456",
|
|
311
|
+
dateCreated: "2024-01-01T00:00:00Z",
|
|
312
|
+
annotationObject: {
|
|
313
|
+
"@context": "https://schema.org",
|
|
314
|
+
"@type": "DigitalDocument",
|
|
315
|
+
name: "myfile.pdf"
|
|
316
|
+
},
|
|
317
|
+
nodeIdentity: "did:entity-storage:0x6363636363636363636363636363636363636363636363636363636363636363",
|
|
318
|
+
userIdentity: "did:entity-storage:0x6363636363636363636363636363636363636363636363636363636363636363"
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
]
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
type: "INotFoundResponse"
|
|
326
|
+
}
|
|
327
|
+
]
|
|
328
|
+
};
|
|
329
|
+
const documentManagementRemoveRevisionRoute = {
|
|
228
330
|
operationId: "DocumentManagementRemove",
|
|
229
331
|
summary: "Remove an document from an auditable item graph vertex",
|
|
230
332
|
tag: tagsDocumentManagement[0].name,
|
|
@@ -275,98 +377,76 @@ function generateRestRoutesDocumentManagement(baseRouteName, componentName) {
|
|
|
275
377
|
]
|
|
276
378
|
},
|
|
277
379
|
responseType: [
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
// documentIdFormat: "bol",
|
|
341
|
-
// documentCode: UneceDocumentCodes.BillOfLading,
|
|
342
|
-
// documentRevision: 0,
|
|
343
|
-
// blobStorageId:
|
|
344
|
-
// "blob-memory:c57d94b088f4c6d2cb32ded014813d0c786aa00134c8ee22f84b1e2545602a70",
|
|
345
|
-
// blobHash: "sha256:123456",
|
|
346
|
-
// dateCreated: "2024-01-01T00:00:00Z",
|
|
347
|
-
// annotationObject: {
|
|
348
|
-
// "@context": "https://schema.org",
|
|
349
|
-
// "@type": "DigitalDocument",
|
|
350
|
-
// name: "myfile.pdf"
|
|
351
|
-
// },
|
|
352
|
-
// nodeIdentity:
|
|
353
|
-
// "did:entity-storage:0x6363636363636363636363636363636363636363636363636363636363636363",
|
|
354
|
-
// userIdentity:
|
|
355
|
-
// "did:entity-storage:0x6363636363636363636363636363636363636363636363636363636363636363"
|
|
356
|
-
// }
|
|
357
|
-
// ]
|
|
358
|
-
// }
|
|
359
|
-
// }
|
|
360
|
-
// }
|
|
361
|
-
// ]
|
|
362
|
-
// }
|
|
380
|
+
{
|
|
381
|
+
type: "IDocumentManagementQueryResponse",
|
|
382
|
+
examples: [
|
|
383
|
+
{
|
|
384
|
+
id: "DocumentManagementQueryResponseExample",
|
|
385
|
+
response: {
|
|
386
|
+
body: {
|
|
387
|
+
"@context": [standardsSchemaOrg.SchemaOrgContexts.ContextRoot, auditableItemGraphModels.AuditableItemGraphContexts.ContextRoot],
|
|
388
|
+
type: [standardsSchemaOrg.SchemaOrgTypes.ItemList, auditableItemGraphModels.AuditableItemGraphTypes.VertexList],
|
|
389
|
+
[standardsSchemaOrg.SchemaOrgTypes.ItemListElement]: [
|
|
390
|
+
{
|
|
391
|
+
"@context": [
|
|
392
|
+
auditableItemGraphModels.AuditableItemGraphContexts.ContextRoot,
|
|
393
|
+
auditableItemGraphModels.AuditableItemGraphContexts.ContextRootCommon
|
|
394
|
+
],
|
|
395
|
+
id: "aig:c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7",
|
|
396
|
+
type: auditableItemGraphModels.AuditableItemGraphTypes.Vertex,
|
|
397
|
+
dateCreated: "2024-08-22T04:13:20.000Z",
|
|
398
|
+
aliases: [
|
|
399
|
+
{
|
|
400
|
+
"@context": [auditableItemGraphModels.AuditableItemGraphContexts.ContextRoot],
|
|
401
|
+
id: "test-id-0",
|
|
402
|
+
type: auditableItemGraphModels.AuditableItemGraphTypes.Alias,
|
|
403
|
+
dateCreated: "2024-08-22T04:13:20.000Z"
|
|
404
|
+
}
|
|
405
|
+
],
|
|
406
|
+
resources: [
|
|
407
|
+
{
|
|
408
|
+
"@context": auditableItemGraphModels.AuditableItemGraphContexts.ContextRoot,
|
|
409
|
+
type: auditableItemGraphModels.AuditableItemGraphTypes.Resource,
|
|
410
|
+
dateCreated: "2024-08-22T04:13:20.000Z",
|
|
411
|
+
resourceObject: {
|
|
412
|
+
"@context": [
|
|
413
|
+
"https://schema.twindev.org/documents/",
|
|
414
|
+
"https://schema.twindev.org/common/",
|
|
415
|
+
"https://schema.org"
|
|
416
|
+
],
|
|
417
|
+
type: "Document",
|
|
418
|
+
id: "test-id-0:0",
|
|
419
|
+
documentId: "test-id-0",
|
|
420
|
+
documentCode: "unece:DocumentCodeList#705",
|
|
421
|
+
documentRevision: 0,
|
|
422
|
+
annotationObject: {
|
|
423
|
+
"@context": "https://schema.org",
|
|
424
|
+
type: "DigitalDocument",
|
|
425
|
+
name: "bill-of-lading"
|
|
426
|
+
},
|
|
427
|
+
blobHash: "sha256:E3Duqrp6bHojSx+CzDttAToAiP1eFkCDAPBbKLABVGM=",
|
|
428
|
+
blobStorageId: "blob:memory:1370eeaaba7a6c7a234b1f82cc3b6d013a0088fd5e16408300f05b28b0015463",
|
|
429
|
+
dateCreated: "2024-08-22T04:13:20.000Z",
|
|
430
|
+
nodeIdentity: "did:entity-storage:0x0101010101010101010101010101010101010101010101010101010101010101",
|
|
431
|
+
userIdentity: "did:entity-storage:0x0404040404040404040404040404040404040404040404040404040404040404"
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
]
|
|
435
|
+
}
|
|
436
|
+
]
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
]
|
|
441
|
+
}
|
|
363
442
|
]
|
|
364
443
|
};
|
|
365
444
|
return [
|
|
366
445
|
documentManagementCreateRoute,
|
|
367
446
|
documentManagementUpdateRoute,
|
|
368
447
|
documentManagementGetRoute,
|
|
369
|
-
|
|
448
|
+
documentManagementGetRevisionRoute,
|
|
449
|
+
documentManagementRemoveRevisionRoute,
|
|
370
450
|
documentManagementQueryRoute
|
|
371
451
|
];
|
|
372
452
|
}
|
|
@@ -411,7 +491,9 @@ async function documentManagementGet(httpRequestContext, componentName, request)
|
|
|
411
491
|
includeBlobStorageMetadata: core.Coerce.boolean(request.query?.includeBlobStorageMetadata),
|
|
412
492
|
includeBlobStorageData: core.Coerce.boolean(request.query?.includeBlobStorageData),
|
|
413
493
|
includeAttestation: core.Coerce.boolean(request.query?.includeAttestation),
|
|
414
|
-
includeRemoved: core.Coerce.boolean(request.query?.includeRemoved)
|
|
494
|
+
includeRemoved: core.Coerce.boolean(request.query?.includeRemoved),
|
|
495
|
+
extractRuleGroupId: request.query?.extractRuleGroupId,
|
|
496
|
+
extractMimeType: request.query?.extractMimeType
|
|
415
497
|
}, request.query?.cursor, core.Coerce.integer(request.query?.pageSize), httpRequestContext.userIdentity, httpRequestContext.nodeIdentity);
|
|
416
498
|
return {
|
|
417
499
|
headers: {
|
|
@@ -421,7 +503,36 @@ async function documentManagementGet(httpRequestContext, componentName, request)
|
|
|
421
503
|
};
|
|
422
504
|
}
|
|
423
505
|
/**
|
|
424
|
-
*
|
|
506
|
+
* Get the document revision from the auditable item graph vertex.
|
|
507
|
+
* @param httpRequestContext The request context for the API.
|
|
508
|
+
* @param componentName The name of the component to use in the routes.
|
|
509
|
+
* @param request The request.
|
|
510
|
+
* @returns The response object with additional http response properties.
|
|
511
|
+
*/
|
|
512
|
+
async function documentManagementGetRevision(httpRequestContext, componentName, request) {
|
|
513
|
+
core.Guards.object(ROUTES_SOURCE, "request", request);
|
|
514
|
+
core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
515
|
+
core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.auditableItemGraphDocumentId", request.pathParams.auditableItemGraphDocumentId);
|
|
516
|
+
const revision = core.Coerce.integer(request.pathParams.revision);
|
|
517
|
+
core.Guards.integer(ROUTES_SOURCE, "revision", revision);
|
|
518
|
+
const mimeType = request.headers?.[web.HeaderTypes.Accept] === web.MimeTypes.JsonLd ? "jsonld" : "json";
|
|
519
|
+
const component = core.ComponentFactory.get(componentName);
|
|
520
|
+
const result = await component.getRevision(request.pathParams.auditableItemGraphDocumentId, revision, {
|
|
521
|
+
includeBlobStorageMetadata: core.Coerce.boolean(request.query?.includeBlobStorageMetadata),
|
|
522
|
+
includeBlobStorageData: core.Coerce.boolean(request.query?.includeBlobStorageData),
|
|
523
|
+
includeAttestation: core.Coerce.boolean(request.query?.includeAttestation),
|
|
524
|
+
extractRuleGroupId: request.query?.extractRuleGroupId,
|
|
525
|
+
extractMimeType: request.query?.extractMimeType
|
|
526
|
+
}, httpRequestContext.userIdentity, httpRequestContext.nodeIdentity);
|
|
527
|
+
return {
|
|
528
|
+
headers: {
|
|
529
|
+
[web.HeaderTypes.ContentType]: mimeType === "json" ? web.MimeTypes.Json : web.MimeTypes.JsonLd
|
|
530
|
+
},
|
|
531
|
+
body: result
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Update the document from the auditable item graph vertex.
|
|
425
536
|
* @param httpRequestContext The request context for the API.
|
|
426
537
|
* @param componentName The name of the component to use in the routes.
|
|
427
538
|
* @param request The request.
|
|
@@ -505,6 +616,11 @@ class DocumentManagementService {
|
|
|
505
616
|
* @internal
|
|
506
617
|
*/
|
|
507
618
|
_attestationComponent;
|
|
619
|
+
/**
|
|
620
|
+
* The connector for the data processing.
|
|
621
|
+
* @internal
|
|
622
|
+
*/
|
|
623
|
+
_dataProcessingComponent;
|
|
508
624
|
/**
|
|
509
625
|
* Create a new instance of DocumentManagementService.
|
|
510
626
|
* @param options The options for the service.
|
|
@@ -513,6 +629,7 @@ class DocumentManagementService {
|
|
|
513
629
|
this._auditableItemGraphComponent = core.ComponentFactory.get(options?.auditableItemGraphComponentType ?? "auditable-item-graph");
|
|
514
630
|
this._blobStorageComponent = core.ComponentFactory.get(options?.blobStorageComponentType ?? "blob-storage");
|
|
515
631
|
this._attestationComponent = core.ComponentFactory.get(options?.attestationComponentType ?? "attestation");
|
|
632
|
+
this._dataProcessingComponent = core.ComponentFactory.get(options?.dataProcessingComponentType ?? "data-processing");
|
|
516
633
|
standardsSchemaOrg.SchemaOrgDataTypes.registerRedirects();
|
|
517
634
|
}
|
|
518
635
|
/**
|
|
@@ -567,7 +684,7 @@ class DocumentManagementService {
|
|
|
567
684
|
standardsSchemaOrg.SchemaOrgContexts.ContextRoot
|
|
568
685
|
],
|
|
569
686
|
type: documentManagementModels.DocumentTypes.Document,
|
|
570
|
-
id:
|
|
687
|
+
id: this.createDocumentId(documentId, 0),
|
|
571
688
|
documentId,
|
|
572
689
|
documentIdFormat,
|
|
573
690
|
documentCode,
|
|
@@ -621,12 +738,13 @@ class DocumentManagementService {
|
|
|
621
738
|
core.Guards.stringValue(this.CLASS_NAME, "userIdentity", userIdentity);
|
|
622
739
|
core.Guards.stringValue(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
|
|
623
740
|
try {
|
|
624
|
-
const documentVertex = await this._auditableItemGraphComponent.get(auditableItemGraphDocumentId);
|
|
741
|
+
const documentVertex = await this._auditableItemGraphComponent.get(auditableItemGraphDocumentId, { includeDeleted: true });
|
|
625
742
|
if (core.Is.empty(documentVertex.resources)) {
|
|
626
743
|
throw new core.NotFoundError(this.CLASS_NAME, "documentRevisionNone");
|
|
627
744
|
}
|
|
628
745
|
const documents = await this.getDocumentsFromVertex(documentVertex);
|
|
629
|
-
const latestRevision = documents.
|
|
746
|
+
const latestRevision = documents.itemListElement[0];
|
|
747
|
+
documentVertex.resources = documentVertex.resources.filter(r => core.Is.empty(r.dateDeleted));
|
|
630
748
|
if (core.Is.empty(latestRevision)) {
|
|
631
749
|
throw new core.NotFoundError(this.CLASS_NAME, "documentRevisionNone");
|
|
632
750
|
}
|
|
@@ -657,7 +775,7 @@ class DocumentManagementService {
|
|
|
657
775
|
const blobStorageId = await this._blobStorageComponent.create(core.Converter.bytesToBase64(blob), undefined, undefined, undefined, undefined, userIdentity, nodeIdentity);
|
|
658
776
|
const newRevision = core.ObjectHelper.clone(latestRevision);
|
|
659
777
|
newRevision.documentRevision++;
|
|
660
|
-
newRevision.id =
|
|
778
|
+
newRevision.id = this.createDocumentId(newRevision.documentId, newRevision.documentRevision);
|
|
661
779
|
newRevision.blobHash = newBlobHash;
|
|
662
780
|
newRevision.blobStorageId = blobStorageId;
|
|
663
781
|
newRevision.annotationObject = annotationObject;
|
|
@@ -708,6 +826,8 @@ class DocumentManagementService {
|
|
|
708
826
|
* @param options.includeBlobStorageData Flag to include the blob storage data for the document, defaults to false.
|
|
709
827
|
* @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.
|
|
710
828
|
* @param options.includeRemoved Flag to include deleted documents, defaults to false.
|
|
829
|
+
* @param options.extractRuleGroupId If provided will extract data from the document using the specified rule group id.
|
|
830
|
+
* @param options.extractMimeType By default extraction will auto detect the mime type of the document, this can be used to override the detection.
|
|
711
831
|
* @param cursor The cursor to get the next chunk of revisions.
|
|
712
832
|
* @param pageSize Page size of items to return, defaults to 1 so only most recent is returned.
|
|
713
833
|
* @param userIdentity The identity to perform the auditable item graph operation with.
|
|
@@ -729,6 +849,43 @@ class DocumentManagementService {
|
|
|
729
849
|
throw new core.GeneralError(this.CLASS_NAME, "getFailed", undefined, error);
|
|
730
850
|
}
|
|
731
851
|
}
|
|
852
|
+
/**
|
|
853
|
+
* Get a document revision using it's auditable item graph vertex id.
|
|
854
|
+
* @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.
|
|
855
|
+
* @param revision The revision id for the document.
|
|
856
|
+
* @param options Additional options for the get operation.
|
|
857
|
+
* @param options.includeBlobStorageMetadata Flag to include the blob storage metadata for the document, defaults to false.
|
|
858
|
+
* @param options.includeBlobStorageData Flag to include the blob storage data for the document, defaults to false.
|
|
859
|
+
* @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.
|
|
860
|
+
* @param options.extractRuleGroupId If provided will extract data from the document using the specified rule group id.
|
|
861
|
+
* @param options.extractMimeType By default extraction will auto detect the mime type of the document, this can be used to override the detection.
|
|
862
|
+
* @param userIdentity The identity to perform the auditable item graph operation with.
|
|
863
|
+
* @param nodeIdentity The node identity to use for vault operations.
|
|
864
|
+
* @returns The documents and revisions if requested, ordered by revision descending, cursor is set if there are more document revisions.
|
|
865
|
+
*/
|
|
866
|
+
async getRevision(auditableItemGraphDocumentId, revision, options, userIdentity, nodeIdentity) {
|
|
867
|
+
core.Urn.guard(this.CLASS_NAME, "auditableItemGraphDocumentId", auditableItemGraphDocumentId);
|
|
868
|
+
core.Guards.integer(this.CLASS_NAME, "revision", revision);
|
|
869
|
+
try {
|
|
870
|
+
const documentVertex = await this._auditableItemGraphComponent.get(auditableItemGraphDocumentId, { includeDeleted: true });
|
|
871
|
+
if (core.Is.empty(documentVertex.resources)) {
|
|
872
|
+
throw new core.NotFoundError(this.CLASS_NAME, "documentRevisionNone");
|
|
873
|
+
}
|
|
874
|
+
documentVertex.resources = documentVertex.resources.filter(d => d.resourceObject?.documentRevision === revision);
|
|
875
|
+
if (documentVertex.resources.length === 0) {
|
|
876
|
+
throw new core.NotFoundError(this.CLASS_NAME, "documentRevisionNotFound", revision.toString());
|
|
877
|
+
}
|
|
878
|
+
// Populate the document and revisions with the options set
|
|
879
|
+
const docList = await this.getDocumentsFromVertex(documentVertex, options, undefined, undefined, userIdentity, nodeIdentity);
|
|
880
|
+
return dataJsonLd.JsonLdProcessor.compact(docList.itemListElement[0], docList.itemListElement[0]["@context"]);
|
|
881
|
+
}
|
|
882
|
+
catch (error) {
|
|
883
|
+
if (core.BaseError.someErrorName(error, "NotFoundError")) {
|
|
884
|
+
throw error;
|
|
885
|
+
}
|
|
886
|
+
throw new core.GeneralError(this.CLASS_NAME, "getRevisionFailed", undefined, error);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
732
889
|
/**
|
|
733
890
|
* Remove an auditable item graph vertex using it's id.
|
|
734
891
|
* The document dateDeleted will be set, but can still be queried with the includeRemoved flag.
|
|
@@ -941,7 +1098,8 @@ class DocumentManagementService {
|
|
|
941
1098
|
* @param options.includeBlobStorageMetadata Flag to include the blob storage metadata for the document, defaults to false.
|
|
942
1099
|
* @param options.includeBlobStorageData Flag to include the blob storage data for the document, defaults to false.
|
|
943
1100
|
* @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.
|
|
944
|
-
* @param options.
|
|
1101
|
+
* @param options.extractRuleGroupId If provided will extract data from the document using the specified rule group id.
|
|
1102
|
+
* @param options.extractMimeType By default extraction will auto detect the mime type of the document, this can be used to override the detection.
|
|
945
1103
|
* @param cursor The cursor to get the next chunk of revisions.
|
|
946
1104
|
* @param pageSize Page size of items to return, defaults to 1 so only most recent is returned.
|
|
947
1105
|
* @param userIdentity The identity to perform the auditable item graph operation with.
|
|
@@ -952,12 +1110,12 @@ class DocumentManagementService {
|
|
|
952
1110
|
async getDocumentsFromVertex(documentVertex, options, cursor, pageSize, userIdentity, nodeIdentity) {
|
|
953
1111
|
const docList = {
|
|
954
1112
|
"@context": [
|
|
1113
|
+
standardsSchemaOrg.SchemaOrgContexts.ContextRoot,
|
|
955
1114
|
documentManagementModels.DocumentContexts.ContextRoot,
|
|
956
|
-
documentManagementModels.DocumentContexts.ContextRootCommon
|
|
957
|
-
standardsSchemaOrg.SchemaOrgContexts.ContextRoot
|
|
1115
|
+
documentManagementModels.DocumentContexts.ContextRootCommon
|
|
958
1116
|
],
|
|
959
|
-
type:
|
|
960
|
-
|
|
1117
|
+
type: standardsSchemaOrg.SchemaOrgTypes.ItemList,
|
|
1118
|
+
[standardsSchemaOrg.SchemaOrgTypes.ItemListElement]: []
|
|
961
1119
|
};
|
|
962
1120
|
if (core.Is.arrayValue(documentVertex.resources)) {
|
|
963
1121
|
// Sort by newest revision first
|
|
@@ -966,20 +1124,39 @@ class DocumentManagementService {
|
|
|
966
1124
|
const startIndex = core.Coerce.integer(cursor) ?? 0;
|
|
967
1125
|
const endIndex = Math.min(startIndex + (pageSize ?? 1), documentVertex.resources.length);
|
|
968
1126
|
const slicedResources = documentVertex.resources.slice(startIndex, endIndex);
|
|
969
|
-
docList.
|
|
1127
|
+
docList[standardsSchemaOrg.SchemaOrgTypes.NextItem] =
|
|
970
1128
|
documentVertex.resources.length > endIndex ? (endIndex + 1).toString() : undefined;
|
|
971
1129
|
const includeBlobStorageMetadata = options?.includeBlobStorageMetadata ?? false;
|
|
972
1130
|
const includeBlobStorageData = options?.includeBlobStorageData ?? false;
|
|
973
1131
|
const includeAttestation = options?.includeAttestation ?? false;
|
|
1132
|
+
const extractData = core.Is.stringValue(options?.extractRuleGroupId);
|
|
974
1133
|
for (let i = 0; i < slicedResources.length; i++) {
|
|
975
1134
|
const document = slicedResources[i].resourceObject;
|
|
976
1135
|
if (core.Is.object(document)) {
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
1136
|
+
document.dateDeleted = slicedResources[i].dateDeleted;
|
|
1137
|
+
docList[standardsSchemaOrg.SchemaOrgTypes.ItemListElement].push(document);
|
|
1138
|
+
const blobRequired = includeBlobStorageMetadata || includeBlobStorageData;
|
|
1139
|
+
if (blobRequired || extractData) {
|
|
1140
|
+
const blobEntry = await this._blobStorageComponent.get(document.blobStorageId, {
|
|
1141
|
+
includeContent: includeBlobStorageData || extractData
|
|
1142
|
+
}, userIdentity, nodeIdentity);
|
|
1143
|
+
if (blobRequired) {
|
|
1144
|
+
document.blobStorageEntry = blobEntry;
|
|
1145
|
+
if (!docList["@context"].includes(blobStorageModels.BlobStorageContexts.ContextRoot)) {
|
|
1146
|
+
docList["@context"].push(blobStorageModels.BlobStorageContexts.ContextRoot);
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
if (core.Is.stringValue(options?.extractRuleGroupId) && core.Is.stringValue(blobEntry.blob)) {
|
|
1150
|
+
const binaryBlob = core.Converter.base64ToBytes(blobEntry.blob);
|
|
1151
|
+
document.extractedData = await this._dataProcessingComponent.extract(options.extractRuleGroupId, binaryBlob, undefined, options?.extractMimeType);
|
|
1152
|
+
}
|
|
1153
|
+
// If we have the blob data due to extraction but we weren't asked for it
|
|
1154
|
+
// then we remove it from the document
|
|
1155
|
+
if (!blobRequired) {
|
|
1156
|
+
delete document.blobStorageEntry;
|
|
1157
|
+
}
|
|
1158
|
+
else if (!includeBlobStorageData) {
|
|
1159
|
+
delete document.blobStorageEntry?.blob;
|
|
983
1160
|
}
|
|
984
1161
|
}
|
|
985
1162
|
if (includeAttestation && core.Is.stringValue(document.attestationId)) {
|
|
@@ -1026,12 +1203,23 @@ class DocumentManagementService {
|
|
|
1026
1203
|
};
|
|
1027
1204
|
return this._attestationComponent.create(documentAttestation, undefined, userIdentity, nodeIdentity);
|
|
1028
1205
|
}
|
|
1206
|
+
/**
|
|
1207
|
+
* Create a document id from the document id and revision.
|
|
1208
|
+
* @param documentId The document id to create.
|
|
1209
|
+
* @param revision The revision of the document.
|
|
1210
|
+
* @returns The document id.
|
|
1211
|
+
* @internal
|
|
1212
|
+
*/
|
|
1213
|
+
createDocumentId(documentId, revision) {
|
|
1214
|
+
const documentIdHash = core.Converter.bytesToBase64Url(crypto.Sha256.sum256(core.Converter.utf8ToBytes(documentId)));
|
|
1215
|
+
return `document:${documentIdHash}:${revision}`;
|
|
1216
|
+
}
|
|
1029
1217
|
}
|
|
1030
1218
|
|
|
1031
1219
|
const restEntryPoints = [
|
|
1032
1220
|
{
|
|
1033
|
-
name: "
|
|
1034
|
-
defaultBaseRoute: "
|
|
1221
|
+
name: "document-management",
|
|
1222
|
+
defaultBaseRoute: "document-management",
|
|
1035
1223
|
tags: tagsDocumentManagement,
|
|
1036
1224
|
generateRoutes: generateRestRoutesDocumentManagement
|
|
1037
1225
|
}
|
|
@@ -1040,6 +1228,7 @@ const restEntryPoints = [
|
|
|
1040
1228
|
exports.DocumentManagementService = DocumentManagementService;
|
|
1041
1229
|
exports.documentManagementCreate = documentManagementCreate;
|
|
1042
1230
|
exports.documentManagementGet = documentManagementGet;
|
|
1231
|
+
exports.documentManagementGetRevision = documentManagementGetRevision;
|
|
1043
1232
|
exports.documentManagementQuery = documentManagementQuery;
|
|
1044
1233
|
exports.documentManagementRemove = documentManagementRemove;
|
|
1045
1234
|
exports.documentManagementUpdate = documentManagementUpdate;
|