@twin.org/document-management-service 0.0.1-next.3 → 0.0.1-next.5
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
CHANGED
|
@@ -330,7 +330,11 @@ async function documentManagementSet(httpRequestContext, componentName, request)
|
|
|
330
330
|
core.Guards.object(ROUTES_SOURCE, "request.body", request.body);
|
|
331
331
|
core.Guards.stringBase64(ROUTES_SOURCE, "request.body.blob", request.body.blob);
|
|
332
332
|
const component = core.ComponentFactory.get(componentName);
|
|
333
|
-
const id = await component.set(request.pathParams.auditableItemGraphId, request.body.documentId, request.body.documentIdFormat, request.body.documentCode, core.Converter.base64ToBytes(request.body.blob), request.body.annotationObject,
|
|
333
|
+
const id = await component.set(request.pathParams.auditableItemGraphId, request.body.documentId, request.body.documentIdFormat, request.body.documentCode, core.Converter.base64ToBytes(request.body.blob), request.body.annotationObject, {
|
|
334
|
+
createAttestation: request.body.createAttestation,
|
|
335
|
+
includeIdAsAlias: request.body.includeIdAsAlias,
|
|
336
|
+
aliasAnnotationObject: request.body.aliasAnnotationObject
|
|
337
|
+
}, httpRequestContext.userIdentity, httpRequestContext.nodeIdentity);
|
|
334
338
|
return {
|
|
335
339
|
statusCode: web.HttpStatusCode.created,
|
|
336
340
|
headers: {
|
|
@@ -463,12 +467,15 @@ class DocumentManagementService {
|
|
|
463
467
|
* @param documentCode The code for the document type.
|
|
464
468
|
* @param blob The data to create the document.
|
|
465
469
|
* @param annotationObject Additional information to associate with the document.
|
|
466
|
-
* @param
|
|
470
|
+
* @param options Additional options for the set operation.
|
|
471
|
+
* @param options.createAttestation Flag to create an attestation for the document, defaults to false.
|
|
472
|
+
* @param options.includeIdAsAlias Include the document id as an alias to the aig vertex, defaults to false.
|
|
473
|
+
* @param options.aliasAnnotationObject Additional information to associate with the alias.
|
|
467
474
|
* @param userIdentity The identity to perform the auditable item graph operation with.
|
|
468
475
|
* @param nodeIdentity The node identity to use for vault operations.
|
|
469
476
|
* @returns The identifier for the document which includes the auditable item graph identifier.
|
|
470
477
|
*/
|
|
471
|
-
async set(auditableItemGraphId, documentId, documentIdFormat, documentCode, blob, annotationObject,
|
|
478
|
+
async set(auditableItemGraphId, documentId, documentIdFormat, documentCode, blob, annotationObject, options, userIdentity, nodeIdentity) {
|
|
472
479
|
core.Guards.stringValue(this.CLASS_NAME, "auditableItemGraphId", auditableItemGraphId);
|
|
473
480
|
core.Guards.stringValue(this.CLASS_NAME, "documentId", documentId);
|
|
474
481
|
core.Guards.arrayOneOf(this.CLASS_NAME, "documentCode", documentCode, Object.values(standardsUnece.UneceDocumentCodes));
|
|
@@ -478,14 +485,32 @@ class DocumentManagementService {
|
|
|
478
485
|
try {
|
|
479
486
|
const vertex = await this._auditableItemGraphComponent.get(auditableItemGraphId);
|
|
480
487
|
vertex.resources = vertex.resources ?? [];
|
|
488
|
+
if (options?.includeIdAsAlias ?? false) {
|
|
489
|
+
vertex.aliases ??= [];
|
|
490
|
+
const found = vertex.aliases.find(a => a.id === documentId);
|
|
491
|
+
if (found) {
|
|
492
|
+
found.annotationObject = options?.aliasAnnotationObject ?? found.annotationObject;
|
|
493
|
+
found.aliasFormat = documentIdFormat ?? found.aliasFormat;
|
|
494
|
+
}
|
|
495
|
+
else {
|
|
496
|
+
vertex.aliases.push({
|
|
497
|
+
"@context": auditableItemGraphModels.AuditableItemGraphTypes.ContextRoot,
|
|
498
|
+
type: auditableItemGraphModels.AuditableItemGraphTypes.Alias,
|
|
499
|
+
id: documentId,
|
|
500
|
+
aliasFormat: documentIdFormat,
|
|
501
|
+
annotationObject: options?.aliasAnnotationObject
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
}
|
|
481
505
|
// Get all the docs from the AIG vertex
|
|
482
506
|
const vertexDocs = this.filterDocumentsFromVertex(vertex);
|
|
483
507
|
// Reduce the list to those with a matching id and code
|
|
484
508
|
const matchingDocIds = this.findMatchingDocs(vertexDocs, documentId, documentCode, true);
|
|
485
509
|
const currentRevision = matchingDocIds[0];
|
|
510
|
+
let createAttestation = options?.createAttestation ?? false;
|
|
486
511
|
// If the create attestation flag is not defined we check to see if any previous
|
|
487
512
|
// revisions have an attestation and if so we create one for the new revision.
|
|
488
|
-
if (core.Is.undefined(createAttestation)) {
|
|
513
|
+
if (core.Is.undefined(options?.createAttestation)) {
|
|
489
514
|
createAttestation = matchingDocIds.some(d => core.Is.stringValue(d.attestationId));
|
|
490
515
|
}
|
|
491
516
|
// Calculate the hash for the blob.
|
|
@@ -504,7 +529,7 @@ class DocumentManagementService {
|
|
|
504
529
|
updated = true;
|
|
505
530
|
}
|
|
506
531
|
if (updated) {
|
|
507
|
-
currentRevision.dateModified = new Date().toISOString();
|
|
532
|
+
currentRevision.dateModified = new Date(Date.now()).toISOString();
|
|
508
533
|
await this._auditableItemGraphComponent.update(vertex, userIdentity, nodeIdentity);
|
|
509
534
|
}
|
|
510
535
|
return currentRevision.id;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -328,7 +328,11 @@ async function documentManagementSet(httpRequestContext, componentName, request)
|
|
|
328
328
|
Guards.object(ROUTES_SOURCE, "request.body", request.body);
|
|
329
329
|
Guards.stringBase64(ROUTES_SOURCE, "request.body.blob", request.body.blob);
|
|
330
330
|
const component = ComponentFactory.get(componentName);
|
|
331
|
-
const id = await component.set(request.pathParams.auditableItemGraphId, request.body.documentId, request.body.documentIdFormat, request.body.documentCode, Converter.base64ToBytes(request.body.blob), request.body.annotationObject,
|
|
331
|
+
const id = await component.set(request.pathParams.auditableItemGraphId, request.body.documentId, request.body.documentIdFormat, request.body.documentCode, Converter.base64ToBytes(request.body.blob), request.body.annotationObject, {
|
|
332
|
+
createAttestation: request.body.createAttestation,
|
|
333
|
+
includeIdAsAlias: request.body.includeIdAsAlias,
|
|
334
|
+
aliasAnnotationObject: request.body.aliasAnnotationObject
|
|
335
|
+
}, httpRequestContext.userIdentity, httpRequestContext.nodeIdentity);
|
|
332
336
|
return {
|
|
333
337
|
statusCode: HttpStatusCode.created,
|
|
334
338
|
headers: {
|
|
@@ -461,12 +465,15 @@ class DocumentManagementService {
|
|
|
461
465
|
* @param documentCode The code for the document type.
|
|
462
466
|
* @param blob The data to create the document.
|
|
463
467
|
* @param annotationObject Additional information to associate with the document.
|
|
464
|
-
* @param
|
|
468
|
+
* @param options Additional options for the set operation.
|
|
469
|
+
* @param options.createAttestation Flag to create an attestation for the document, defaults to false.
|
|
470
|
+
* @param options.includeIdAsAlias Include the document id as an alias to the aig vertex, defaults to false.
|
|
471
|
+
* @param options.aliasAnnotationObject Additional information to associate with the alias.
|
|
465
472
|
* @param userIdentity The identity to perform the auditable item graph operation with.
|
|
466
473
|
* @param nodeIdentity The node identity to use for vault operations.
|
|
467
474
|
* @returns The identifier for the document which includes the auditable item graph identifier.
|
|
468
475
|
*/
|
|
469
|
-
async set(auditableItemGraphId, documentId, documentIdFormat, documentCode, blob, annotationObject,
|
|
476
|
+
async set(auditableItemGraphId, documentId, documentIdFormat, documentCode, blob, annotationObject, options, userIdentity, nodeIdentity) {
|
|
470
477
|
Guards.stringValue(this.CLASS_NAME, "auditableItemGraphId", auditableItemGraphId);
|
|
471
478
|
Guards.stringValue(this.CLASS_NAME, "documentId", documentId);
|
|
472
479
|
Guards.arrayOneOf(this.CLASS_NAME, "documentCode", documentCode, Object.values(UneceDocumentCodes));
|
|
@@ -476,14 +483,32 @@ class DocumentManagementService {
|
|
|
476
483
|
try {
|
|
477
484
|
const vertex = await this._auditableItemGraphComponent.get(auditableItemGraphId);
|
|
478
485
|
vertex.resources = vertex.resources ?? [];
|
|
486
|
+
if (options?.includeIdAsAlias ?? false) {
|
|
487
|
+
vertex.aliases ??= [];
|
|
488
|
+
const found = vertex.aliases.find(a => a.id === documentId);
|
|
489
|
+
if (found) {
|
|
490
|
+
found.annotationObject = options?.aliasAnnotationObject ?? found.annotationObject;
|
|
491
|
+
found.aliasFormat = documentIdFormat ?? found.aliasFormat;
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
vertex.aliases.push({
|
|
495
|
+
"@context": AuditableItemGraphTypes.ContextRoot,
|
|
496
|
+
type: AuditableItemGraphTypes.Alias,
|
|
497
|
+
id: documentId,
|
|
498
|
+
aliasFormat: documentIdFormat,
|
|
499
|
+
annotationObject: options?.aliasAnnotationObject
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
}
|
|
479
503
|
// Get all the docs from the AIG vertex
|
|
480
504
|
const vertexDocs = this.filterDocumentsFromVertex(vertex);
|
|
481
505
|
// Reduce the list to those with a matching id and code
|
|
482
506
|
const matchingDocIds = this.findMatchingDocs(vertexDocs, documentId, documentCode, true);
|
|
483
507
|
const currentRevision = matchingDocIds[0];
|
|
508
|
+
let createAttestation = options?.createAttestation ?? false;
|
|
484
509
|
// If the create attestation flag is not defined we check to see if any previous
|
|
485
510
|
// revisions have an attestation and if so we create one for the new revision.
|
|
486
|
-
if (Is.undefined(createAttestation)) {
|
|
511
|
+
if (Is.undefined(options?.createAttestation)) {
|
|
487
512
|
createAttestation = matchingDocIds.some(d => Is.stringValue(d.attestationId));
|
|
488
513
|
}
|
|
489
514
|
// Calculate the hash for the blob.
|
|
@@ -502,7 +527,7 @@ class DocumentManagementService {
|
|
|
502
527
|
updated = true;
|
|
503
528
|
}
|
|
504
529
|
if (updated) {
|
|
505
|
-
currentRevision.dateModified = new Date().toISOString();
|
|
530
|
+
currentRevision.dateModified = new Date(Date.now()).toISOString();
|
|
506
531
|
await this._auditableItemGraphComponent.update(vertex, userIdentity, nodeIdentity);
|
|
507
532
|
}
|
|
508
533
|
return currentRevision.id;
|
|
@@ -29,12 +29,19 @@ export declare class DocumentManagementService implements IDocumentManagementCom
|
|
|
29
29
|
* @param documentCode The code for the document type.
|
|
30
30
|
* @param blob The data to create the document.
|
|
31
31
|
* @param annotationObject Additional information to associate with the document.
|
|
32
|
-
* @param
|
|
32
|
+
* @param options Additional options for the set operation.
|
|
33
|
+
* @param options.createAttestation Flag to create an attestation for the document, defaults to false.
|
|
34
|
+
* @param options.includeIdAsAlias Include the document id as an alias to the aig vertex, defaults to false.
|
|
35
|
+
* @param options.aliasAnnotationObject Additional information to associate with the alias.
|
|
33
36
|
* @param userIdentity The identity to perform the auditable item graph operation with.
|
|
34
37
|
* @param nodeIdentity The node identity to use for vault operations.
|
|
35
38
|
* @returns The identifier for the document which includes the auditable item graph identifier.
|
|
36
39
|
*/
|
|
37
|
-
set(auditableItemGraphId: string, documentId: string, documentIdFormat: string | undefined, documentCode: UneceDocumentCodes, blob: Uint8Array, annotationObject?: IJsonLdNodeObject,
|
|
40
|
+
set(auditableItemGraphId: string, documentId: string, documentIdFormat: string | undefined, documentCode: UneceDocumentCodes, blob: Uint8Array, annotationObject?: IJsonLdNodeObject, options?: {
|
|
41
|
+
createAttestation?: boolean;
|
|
42
|
+
includeIdAsAlias?: boolean;
|
|
43
|
+
aliasAnnotationObject?: IJsonLdNodeObject;
|
|
44
|
+
}, userIdentity?: string, nodeIdentity?: string): Promise<string>;
|
|
38
45
|
/**
|
|
39
46
|
* Get a specific document from an auditable item graph vertex.
|
|
40
47
|
* @param auditableItemGraphId The auditable item graph vertex id to get the document from.
|
package/docs/changelog.md
CHANGED
package/docs/open-api/spec.json
CHANGED
|
@@ -1079,6 +1079,13 @@
|
|
|
1079
1079
|
"createAttestation": {
|
|
1080
1080
|
"type": "boolean",
|
|
1081
1081
|
"description": "Flag to create an attestation for the document, defaults to false"
|
|
1082
|
+
},
|
|
1083
|
+
"includeIdAsAlias": {
|
|
1084
|
+
"type": "boolean",
|
|
1085
|
+
"description": "Include the document id as an alias to the aig vertex, defaults to false."
|
|
1086
|
+
},
|
|
1087
|
+
"aliasAnnotationObject": {
|
|
1088
|
+
"$ref": "#/components/schemas/JsonLdNodeObject"
|
|
1082
1089
|
}
|
|
1083
1090
|
},
|
|
1084
1091
|
"required": [
|
|
@@ -50,7 +50,7 @@ Runtime name for the class.
|
|
|
50
50
|
|
|
51
51
|
### set()
|
|
52
52
|
|
|
53
|
-
> **set**(`auditableItemGraphId`, `documentId`, `documentIdFormat`, `documentCode`, `blob`, `annotationObject`?, `
|
|
53
|
+
> **set**(`auditableItemGraphId`, `documentId`, `documentIdFormat`, `documentCode`, `blob`, `annotationObject`?, `options`?, `userIdentity`?, `nodeIdentity`?): `Promise`\<`string`\>
|
|
54
54
|
|
|
55
55
|
Store a document in an auditable item graph vertex and add its content to blob storage.
|
|
56
56
|
If the document id already exists and the blob data is different a new revision will be created.
|
|
@@ -94,12 +94,28 @@ The data to create the document.
|
|
|
94
94
|
|
|
95
95
|
Additional information to associate with the document.
|
|
96
96
|
|
|
97
|
-
#####
|
|
97
|
+
##### options?
|
|
98
|
+
|
|
99
|
+
Additional options for the set operation.
|
|
100
|
+
|
|
101
|
+
###### createAttestation?
|
|
98
102
|
|
|
99
103
|
`boolean`
|
|
100
104
|
|
|
101
105
|
Flag to create an attestation for the document, defaults to false.
|
|
102
106
|
|
|
107
|
+
###### includeIdAsAlias?
|
|
108
|
+
|
|
109
|
+
`boolean`
|
|
110
|
+
|
|
111
|
+
Include the document id as an alias to the aig vertex, defaults to false.
|
|
112
|
+
|
|
113
|
+
###### aliasAnnotationObject?
|
|
114
|
+
|
|
115
|
+
`IJsonLdNodeObject`
|
|
116
|
+
|
|
117
|
+
Additional information to associate with the alias.
|
|
118
|
+
|
|
103
119
|
##### userIdentity?
|
|
104
120
|
|
|
105
121
|
`string`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/document-management-service",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.5",
|
|
4
4
|
"description": "Document management contract implementation and REST endpoint definitions",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"@twin.org/core": "next",
|
|
22
22
|
"@twin.org/crypto": "next",
|
|
23
23
|
"@twin.org/data-json-ld": "next",
|
|
24
|
-
"@twin.org/document-management-models": "0.0.1-next.
|
|
24
|
+
"@twin.org/document-management-models": "0.0.1-next.5",
|
|
25
25
|
"@twin.org/entity": "next",
|
|
26
26
|
"@twin.org/entity-storage-models": "next",
|
|
27
27
|
"@twin.org/nameof": "next",
|