@twin.org/document-management-rest-client 0.0.1-next.10
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/LICENSE +201 -0
- package/README.md +21 -0
- package/dist/cjs/index.cjs +153 -0
- package/dist/esm/index.mjs +151 -0
- package/dist/types/documentManagementClient.d.ts +94 -0
- package/dist/types/index.d.ts +1 -0
- package/docs/changelog.md +47 -0
- package/docs/examples.md +1 -0
- package/docs/reference/classes/DocumentManagementClient.md +310 -0
- package/docs/reference/index.md +5 -0
- package/locales/en.json +1 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2024 IOTA Stiftung.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# TWIN Document Management REST Client
|
|
2
|
+
|
|
3
|
+
Document management processing contract implementation which can connect to REST endpoints.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
npm install @twin.org/document-management-rest-client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Examples
|
|
12
|
+
|
|
13
|
+
Usage of the APIs is shown in the examples [docs/examples.md](docs/examples.md)
|
|
14
|
+
|
|
15
|
+
## Reference
|
|
16
|
+
|
|
17
|
+
Detailed reference documentation for the API can be found in [docs/reference/index.md](docs/reference/index.md)
|
|
18
|
+
|
|
19
|
+
## Changelog
|
|
20
|
+
|
|
21
|
+
The changes between each version can be found in [docs/changelog.md](docs/changelog.md)
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var apiCore = require('@twin.org/api-core');
|
|
4
|
+
var core = require('@twin.org/core');
|
|
5
|
+
var standardsUnece = require('@twin.org/standards-unece');
|
|
6
|
+
|
|
7
|
+
// Copyright 2024 IOTA Stiftung.
|
|
8
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
9
|
+
/**
|
|
10
|
+
* Client for performing document management through to REST endpoints.
|
|
11
|
+
*/
|
|
12
|
+
class DocumentManagementClient extends apiCore.BaseRestClient {
|
|
13
|
+
/**
|
|
14
|
+
* Runtime name for the class.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
static _CLASS_NAME = "DocumentManagementClient";
|
|
18
|
+
/**
|
|
19
|
+
* Runtime name for the class.
|
|
20
|
+
*/
|
|
21
|
+
CLASS_NAME = DocumentManagementClient._CLASS_NAME;
|
|
22
|
+
/**
|
|
23
|
+
* Create a new instance of DocumentManagementClient.
|
|
24
|
+
* @param config The configuration for the client.
|
|
25
|
+
*/
|
|
26
|
+
constructor(config) {
|
|
27
|
+
super(DocumentManagementClient._CLASS_NAME, config, "document-management");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Store a document as an auditable item graph vertex and add its content to blob storage.
|
|
31
|
+
* If the document id already exists and the blob data is different a new revision will be created.
|
|
32
|
+
* For any other changes the current revision will be updated.
|
|
33
|
+
* @param documentId The document id to create.
|
|
34
|
+
* @param documentIdFormat The format of the document identifier.
|
|
35
|
+
* @param documentCode The code for the document type.
|
|
36
|
+
* @param blob The data to create the document with.
|
|
37
|
+
* @param annotationObject Additional information to associate with the document.
|
|
38
|
+
* @param auditableItemGraphEdges The auditable item graph vertices to connect the document to.
|
|
39
|
+
* @param options Additional options for the set operation.
|
|
40
|
+
* @param options.createAttestation Flag to create an attestation for the document, defaults to false.
|
|
41
|
+
* @param options.addAlias Flag to add the document id as an alias to the aig vertex, defaults to true.
|
|
42
|
+
* @param options.aliasAnnotationObject Annotation object for the alias.
|
|
43
|
+
* @returns The auditable item graph vertex created for the document including its revision.
|
|
44
|
+
*/
|
|
45
|
+
async create(documentId, documentIdFormat, documentCode, blob, annotationObject, auditableItemGraphEdges, options) {
|
|
46
|
+
core.Guards.stringValue(this.CLASS_NAME, "documentId", documentId);
|
|
47
|
+
core.Guards.arrayOneOf(this.CLASS_NAME, "documentCode", documentCode, Object.values(standardsUnece.UneceDocumentCodes));
|
|
48
|
+
core.Guards.uint8Array(this.CLASS_NAME, "blob", blob);
|
|
49
|
+
const response = await this.fetch("/", "POST", {
|
|
50
|
+
body: {
|
|
51
|
+
documentId,
|
|
52
|
+
documentIdFormat,
|
|
53
|
+
documentCode,
|
|
54
|
+
blob: core.Converter.bytesToBase64(blob),
|
|
55
|
+
annotationObject,
|
|
56
|
+
auditableItemGraphEdges,
|
|
57
|
+
createAttestation: options?.createAttestation,
|
|
58
|
+
addAlias: options?.addAlias,
|
|
59
|
+
aliasAnnotationObject: options?.aliasAnnotationObject
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return response.headers.location;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Update a document as an auditable item graph vertex and add its content to blob storage.
|
|
66
|
+
* If the blob data is different a new revision will be created.
|
|
67
|
+
* For any other changes the current revision will be updated.
|
|
68
|
+
* @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.
|
|
69
|
+
* @param blob The data to update the document with.
|
|
70
|
+
* @param annotationObject Additional information to associate with the document.
|
|
71
|
+
* @param auditableItemGraphEdges The auditable item graph vertices to connect the document to, if undefined retains current connections.
|
|
72
|
+
* @returns Nothing.
|
|
73
|
+
*/
|
|
74
|
+
async update(auditableItemGraphDocumentId, blob, annotationObject, auditableItemGraphEdges) {
|
|
75
|
+
core.Urn.guard(this.CLASS_NAME, "auditableItemGraphDocumentId", auditableItemGraphDocumentId);
|
|
76
|
+
await this.fetch("/:auditableItemGraphDocumentId", "PUT", {
|
|
77
|
+
pathParams: {
|
|
78
|
+
auditableItemGraphDocumentId
|
|
79
|
+
},
|
|
80
|
+
body: {
|
|
81
|
+
blob: core.Is.uint8Array(blob) ? core.Converter.bytesToBase64(blob) : undefined,
|
|
82
|
+
annotationObject,
|
|
83
|
+
auditableItemGraphEdges
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get a document using it's auditable item graph vertex id and optional revision.
|
|
89
|
+
* @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.
|
|
90
|
+
* @param options Additional options for the get operation.
|
|
91
|
+
* @param options.includeBlobStorageMetadata Flag to include the blob storage metadata for the document, defaults to false.
|
|
92
|
+
* @param options.includeBlobStorageData Flag to include the blob storage data for the document, defaults to false.
|
|
93
|
+
* @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.
|
|
94
|
+
* @param options.includeRemoved Flag to include deleted documents, defaults to false.
|
|
95
|
+
* @param cursor The cursor to get the next chunk of revisions.
|
|
96
|
+
* @param pageSize Page size of items to return, defaults to 1 so only most recent is returned.
|
|
97
|
+
* @returns The documents and revisions if requested, ordered by revision descending, cursor is set if there are more document revisions.
|
|
98
|
+
*/
|
|
99
|
+
async get(auditableItemGraphDocumentId, options, cursor, pageSize) {
|
|
100
|
+
core.Urn.guard(this.CLASS_NAME, "auditableItemGraphDocumentId", auditableItemGraphDocumentId);
|
|
101
|
+
const response = await this.fetch("/:auditableItemGraphDocumentId", "GET", {
|
|
102
|
+
pathParams: {
|
|
103
|
+
auditableItemGraphDocumentId
|
|
104
|
+
},
|
|
105
|
+
query: {
|
|
106
|
+
includeBlobStorageMetadata: options?.includeBlobStorageMetadata,
|
|
107
|
+
includeBlobStorageData: options?.includeBlobStorageData,
|
|
108
|
+
includeAttestation: options?.includeAttestation,
|
|
109
|
+
includeRemoved: options?.includeRemoved,
|
|
110
|
+
cursor,
|
|
111
|
+
pageSize: core.Coerce.string(pageSize)
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
return response.body;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Remove an auditable item graph vertex using it's id.
|
|
118
|
+
* The document dateDeleted will be set, but can still be queried with the includeRemoved flag.
|
|
119
|
+
* @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.
|
|
120
|
+
* @param revision The revision of the document to remove.
|
|
121
|
+
* @returns Nothing.
|
|
122
|
+
*/
|
|
123
|
+
async removeRevision(auditableItemGraphDocumentId, revision) {
|
|
124
|
+
core.Urn.guard(this.CLASS_NAME, "auditableItemGraphDocumentId", auditableItemGraphDocumentId);
|
|
125
|
+
core.Guards.number(this.CLASS_NAME, "revision", revision);
|
|
126
|
+
await this.fetch("/:auditableItemGraphDocumentId/:revision", "DELETE", {
|
|
127
|
+
pathParams: {
|
|
128
|
+
auditableItemGraphDocumentId,
|
|
129
|
+
revision: revision.toString()
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Find all the document with a specific id.
|
|
135
|
+
* @param documentId The document id to find in the graph.
|
|
136
|
+
* @param cursor The cursor to get the next chunk of documents.
|
|
137
|
+
* @param pageSize The page size to get the next chunk of documents.
|
|
138
|
+
* @returns The graph vertices that contain documents referencing the specified document id.
|
|
139
|
+
*/
|
|
140
|
+
async query(documentId, cursor, pageSize) {
|
|
141
|
+
core.Guards.stringValue(this.CLASS_NAME, "documentId", documentId);
|
|
142
|
+
const response = await this.fetch("/", "GET", {
|
|
143
|
+
query: {
|
|
144
|
+
documentId,
|
|
145
|
+
cursor,
|
|
146
|
+
pageSize: core.Coerce.string(pageSize)
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
return response.body;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
exports.DocumentManagementClient = DocumentManagementClient;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { BaseRestClient } from '@twin.org/api-core';
|
|
2
|
+
import { Guards, Converter, Urn, Is, Coerce } from '@twin.org/core';
|
|
3
|
+
import { UneceDocumentCodes } from '@twin.org/standards-unece';
|
|
4
|
+
|
|
5
|
+
// Copyright 2024 IOTA Stiftung.
|
|
6
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
7
|
+
/**
|
|
8
|
+
* Client for performing document management through to REST endpoints.
|
|
9
|
+
*/
|
|
10
|
+
class DocumentManagementClient extends BaseRestClient {
|
|
11
|
+
/**
|
|
12
|
+
* Runtime name for the class.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
static _CLASS_NAME = "DocumentManagementClient";
|
|
16
|
+
/**
|
|
17
|
+
* Runtime name for the class.
|
|
18
|
+
*/
|
|
19
|
+
CLASS_NAME = DocumentManagementClient._CLASS_NAME;
|
|
20
|
+
/**
|
|
21
|
+
* Create a new instance of DocumentManagementClient.
|
|
22
|
+
* @param config The configuration for the client.
|
|
23
|
+
*/
|
|
24
|
+
constructor(config) {
|
|
25
|
+
super(DocumentManagementClient._CLASS_NAME, config, "document-management");
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Store a document as an auditable item graph vertex and add its content to blob storage.
|
|
29
|
+
* If the document id already exists and the blob data is different a new revision will be created.
|
|
30
|
+
* For any other changes the current revision will be updated.
|
|
31
|
+
* @param documentId The document id to create.
|
|
32
|
+
* @param documentIdFormat The format of the document identifier.
|
|
33
|
+
* @param documentCode The code for the document type.
|
|
34
|
+
* @param blob The data to create the document with.
|
|
35
|
+
* @param annotationObject Additional information to associate with the document.
|
|
36
|
+
* @param auditableItemGraphEdges The auditable item graph vertices to connect the document to.
|
|
37
|
+
* @param options Additional options for the set operation.
|
|
38
|
+
* @param options.createAttestation Flag to create an attestation for the document, defaults to false.
|
|
39
|
+
* @param options.addAlias Flag to add the document id as an alias to the aig vertex, defaults to true.
|
|
40
|
+
* @param options.aliasAnnotationObject Annotation object for the alias.
|
|
41
|
+
* @returns The auditable item graph vertex created for the document including its revision.
|
|
42
|
+
*/
|
|
43
|
+
async create(documentId, documentIdFormat, documentCode, blob, annotationObject, auditableItemGraphEdges, options) {
|
|
44
|
+
Guards.stringValue(this.CLASS_NAME, "documentId", documentId);
|
|
45
|
+
Guards.arrayOneOf(this.CLASS_NAME, "documentCode", documentCode, Object.values(UneceDocumentCodes));
|
|
46
|
+
Guards.uint8Array(this.CLASS_NAME, "blob", blob);
|
|
47
|
+
const response = await this.fetch("/", "POST", {
|
|
48
|
+
body: {
|
|
49
|
+
documentId,
|
|
50
|
+
documentIdFormat,
|
|
51
|
+
documentCode,
|
|
52
|
+
blob: Converter.bytesToBase64(blob),
|
|
53
|
+
annotationObject,
|
|
54
|
+
auditableItemGraphEdges,
|
|
55
|
+
createAttestation: options?.createAttestation,
|
|
56
|
+
addAlias: options?.addAlias,
|
|
57
|
+
aliasAnnotationObject: options?.aliasAnnotationObject
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return response.headers.location;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Update a document as an auditable item graph vertex and add its content to blob storage.
|
|
64
|
+
* If the blob data is different a new revision will be created.
|
|
65
|
+
* For any other changes the current revision will be updated.
|
|
66
|
+
* @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.
|
|
67
|
+
* @param blob The data to update the document with.
|
|
68
|
+
* @param annotationObject Additional information to associate with the document.
|
|
69
|
+
* @param auditableItemGraphEdges The auditable item graph vertices to connect the document to, if undefined retains current connections.
|
|
70
|
+
* @returns Nothing.
|
|
71
|
+
*/
|
|
72
|
+
async update(auditableItemGraphDocumentId, blob, annotationObject, auditableItemGraphEdges) {
|
|
73
|
+
Urn.guard(this.CLASS_NAME, "auditableItemGraphDocumentId", auditableItemGraphDocumentId);
|
|
74
|
+
await this.fetch("/:auditableItemGraphDocumentId", "PUT", {
|
|
75
|
+
pathParams: {
|
|
76
|
+
auditableItemGraphDocumentId
|
|
77
|
+
},
|
|
78
|
+
body: {
|
|
79
|
+
blob: Is.uint8Array(blob) ? Converter.bytesToBase64(blob) : undefined,
|
|
80
|
+
annotationObject,
|
|
81
|
+
auditableItemGraphEdges
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get a document using it's auditable item graph vertex id and optional revision.
|
|
87
|
+
* @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.
|
|
88
|
+
* @param options Additional options for the get operation.
|
|
89
|
+
* @param options.includeBlobStorageMetadata Flag to include the blob storage metadata for the document, defaults to false.
|
|
90
|
+
* @param options.includeBlobStorageData Flag to include the blob storage data for the document, defaults to false.
|
|
91
|
+
* @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.
|
|
92
|
+
* @param options.includeRemoved Flag to include deleted documents, defaults to false.
|
|
93
|
+
* @param cursor The cursor to get the next chunk of revisions.
|
|
94
|
+
* @param pageSize Page size of items to return, defaults to 1 so only most recent is returned.
|
|
95
|
+
* @returns The documents and revisions if requested, ordered by revision descending, cursor is set if there are more document revisions.
|
|
96
|
+
*/
|
|
97
|
+
async get(auditableItemGraphDocumentId, options, cursor, pageSize) {
|
|
98
|
+
Urn.guard(this.CLASS_NAME, "auditableItemGraphDocumentId", auditableItemGraphDocumentId);
|
|
99
|
+
const response = await this.fetch("/:auditableItemGraphDocumentId", "GET", {
|
|
100
|
+
pathParams: {
|
|
101
|
+
auditableItemGraphDocumentId
|
|
102
|
+
},
|
|
103
|
+
query: {
|
|
104
|
+
includeBlobStorageMetadata: options?.includeBlobStorageMetadata,
|
|
105
|
+
includeBlobStorageData: options?.includeBlobStorageData,
|
|
106
|
+
includeAttestation: options?.includeAttestation,
|
|
107
|
+
includeRemoved: options?.includeRemoved,
|
|
108
|
+
cursor,
|
|
109
|
+
pageSize: Coerce.string(pageSize)
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
return response.body;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Remove an auditable item graph vertex using it's id.
|
|
116
|
+
* The document dateDeleted will be set, but can still be queried with the includeRemoved flag.
|
|
117
|
+
* @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.
|
|
118
|
+
* @param revision The revision of the document to remove.
|
|
119
|
+
* @returns Nothing.
|
|
120
|
+
*/
|
|
121
|
+
async removeRevision(auditableItemGraphDocumentId, revision) {
|
|
122
|
+
Urn.guard(this.CLASS_NAME, "auditableItemGraphDocumentId", auditableItemGraphDocumentId);
|
|
123
|
+
Guards.number(this.CLASS_NAME, "revision", revision);
|
|
124
|
+
await this.fetch("/:auditableItemGraphDocumentId/:revision", "DELETE", {
|
|
125
|
+
pathParams: {
|
|
126
|
+
auditableItemGraphDocumentId,
|
|
127
|
+
revision: revision.toString()
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Find all the document with a specific id.
|
|
133
|
+
* @param documentId The document id to find in the graph.
|
|
134
|
+
* @param cursor The cursor to get the next chunk of documents.
|
|
135
|
+
* @param pageSize The page size to get the next chunk of documents.
|
|
136
|
+
* @returns The graph vertices that contain documents referencing the specified document id.
|
|
137
|
+
*/
|
|
138
|
+
async query(documentId, cursor, pageSize) {
|
|
139
|
+
Guards.stringValue(this.CLASS_NAME, "documentId", documentId);
|
|
140
|
+
const response = await this.fetch("/", "GET", {
|
|
141
|
+
query: {
|
|
142
|
+
documentId,
|
|
143
|
+
cursor,
|
|
144
|
+
pageSize: Coerce.string(pageSize)
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
return response.body;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export { DocumentManagementClient };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { BaseRestClient } from "@twin.org/api-core";
|
|
2
|
+
import type { IBaseRestClientConfig } from "@twin.org/api-models";
|
|
3
|
+
import type { IAuditableItemGraphVertexList } from "@twin.org/auditable-item-graph-models";
|
|
4
|
+
import type { IJsonLdNodeObject } from "@twin.org/data-json-ld";
|
|
5
|
+
import type { IDocumentList, IDocumentManagementComponent } from "@twin.org/document-management-models";
|
|
6
|
+
import { UneceDocumentCodes } from "@twin.org/standards-unece";
|
|
7
|
+
/**
|
|
8
|
+
* Client for performing document management through to REST endpoints.
|
|
9
|
+
*/
|
|
10
|
+
export declare class DocumentManagementClient extends BaseRestClient implements IDocumentManagementComponent {
|
|
11
|
+
/**
|
|
12
|
+
* Runtime name for the class.
|
|
13
|
+
*/
|
|
14
|
+
readonly CLASS_NAME: string;
|
|
15
|
+
/**
|
|
16
|
+
* Create a new instance of DocumentManagementClient.
|
|
17
|
+
* @param config The configuration for the client.
|
|
18
|
+
*/
|
|
19
|
+
constructor(config: IBaseRestClientConfig);
|
|
20
|
+
/**
|
|
21
|
+
* Store a document as an auditable item graph vertex and add its content to blob storage.
|
|
22
|
+
* If the document id already exists and the blob data is different a new revision will be created.
|
|
23
|
+
* For any other changes the current revision will be updated.
|
|
24
|
+
* @param documentId The document id to create.
|
|
25
|
+
* @param documentIdFormat The format of the document identifier.
|
|
26
|
+
* @param documentCode The code for the document type.
|
|
27
|
+
* @param blob The data to create the document with.
|
|
28
|
+
* @param annotationObject Additional information to associate with the document.
|
|
29
|
+
* @param auditableItemGraphEdges The auditable item graph vertices to connect the document to.
|
|
30
|
+
* @param options Additional options for the set operation.
|
|
31
|
+
* @param options.createAttestation Flag to create an attestation for the document, defaults to false.
|
|
32
|
+
* @param options.addAlias Flag to add the document id as an alias to the aig vertex, defaults to true.
|
|
33
|
+
* @param options.aliasAnnotationObject Annotation object for the alias.
|
|
34
|
+
* @returns The auditable item graph vertex created for the document including its revision.
|
|
35
|
+
*/
|
|
36
|
+
create(documentId: string, documentIdFormat: string | undefined, documentCode: UneceDocumentCodes, blob: Uint8Array, annotationObject?: IJsonLdNodeObject, auditableItemGraphEdges?: {
|
|
37
|
+
id: string;
|
|
38
|
+
addAlias?: boolean;
|
|
39
|
+
aliasAnnotationObject?: IJsonLdNodeObject;
|
|
40
|
+
}[], options?: {
|
|
41
|
+
createAttestation?: boolean;
|
|
42
|
+
addAlias?: boolean;
|
|
43
|
+
aliasAnnotationObject?: IJsonLdNodeObject;
|
|
44
|
+
}): Promise<string>;
|
|
45
|
+
/**
|
|
46
|
+
* Update a document as an auditable item graph vertex and add its content to blob storage.
|
|
47
|
+
* If the blob data is different a new revision will be created.
|
|
48
|
+
* For any other changes the current revision will be updated.
|
|
49
|
+
* @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.
|
|
50
|
+
* @param blob The data to update the document with.
|
|
51
|
+
* @param annotationObject Additional information to associate with the document.
|
|
52
|
+
* @param auditableItemGraphEdges The auditable item graph vertices to connect the document to, if undefined retains current connections.
|
|
53
|
+
* @returns Nothing.
|
|
54
|
+
*/
|
|
55
|
+
update(auditableItemGraphDocumentId: string, blob?: Uint8Array, annotationObject?: IJsonLdNodeObject, auditableItemGraphEdges?: {
|
|
56
|
+
id: string;
|
|
57
|
+
addAlias?: boolean;
|
|
58
|
+
aliasAnnotationObject?: IJsonLdNodeObject;
|
|
59
|
+
}[]): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Get a document using it's auditable item graph vertex id and optional revision.
|
|
62
|
+
* @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.
|
|
63
|
+
* @param options Additional options for the get operation.
|
|
64
|
+
* @param options.includeBlobStorageMetadata Flag to include the blob storage metadata for the document, defaults to false.
|
|
65
|
+
* @param options.includeBlobStorageData Flag to include the blob storage data for the document, defaults to false.
|
|
66
|
+
* @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.
|
|
67
|
+
* @param options.includeRemoved Flag to include deleted documents, defaults to false.
|
|
68
|
+
* @param cursor The cursor to get the next chunk of revisions.
|
|
69
|
+
* @param pageSize Page size of items to return, defaults to 1 so only most recent is returned.
|
|
70
|
+
* @returns The documents and revisions if requested, ordered by revision descending, cursor is set if there are more document revisions.
|
|
71
|
+
*/
|
|
72
|
+
get(auditableItemGraphDocumentId: string, options?: {
|
|
73
|
+
includeBlobStorageMetadata?: boolean;
|
|
74
|
+
includeBlobStorageData?: boolean;
|
|
75
|
+
includeAttestation?: boolean;
|
|
76
|
+
includeRemoved?: boolean;
|
|
77
|
+
}, cursor?: string, pageSize?: number): Promise<IDocumentList>;
|
|
78
|
+
/**
|
|
79
|
+
* Remove an auditable item graph vertex using it's id.
|
|
80
|
+
* The document dateDeleted will be set, but can still be queried with the includeRemoved flag.
|
|
81
|
+
* @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.
|
|
82
|
+
* @param revision The revision of the document to remove.
|
|
83
|
+
* @returns Nothing.
|
|
84
|
+
*/
|
|
85
|
+
removeRevision(auditableItemGraphDocumentId: string, revision: number): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Find all the document with a specific id.
|
|
88
|
+
* @param documentId The document id to find in the graph.
|
|
89
|
+
* @param cursor The cursor to get the next chunk of documents.
|
|
90
|
+
* @param pageSize The page size to get the next chunk of documents.
|
|
91
|
+
* @returns The graph vertices that contain documents referencing the specified document id.
|
|
92
|
+
*/
|
|
93
|
+
query(documentId: string, cursor?: string, pageSize?: number): Promise<IAuditableItemGraphVertexList>;
|
|
94
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./documentManagementClient";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# @twin.org/document-management-rest-client - Changelog
|
|
2
|
+
|
|
3
|
+
## [0.0.1-next.10](https://github.com/twinfoundation/document-management/compare/document-management-rest-client-v0.0.1-next.9...document-management-rest-client-v0.0.1-next.10) (2025-04-25)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* adding missing route for the document management ([#4](https://github.com/twinfoundation/document-management/issues/4)) ([fd3292e](https://github.com/twinfoundation/document-management/commit/fd3292ede5014847ae2f2bcadb174b6552486154))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/document-management-models bumped from 0.0.1-next.9 to 0.0.1-next.10
|
|
16
|
+
|
|
17
|
+
## [0.0.1-next.9](https://github.com/twinfoundation/document-management/compare/document-management-rest-client-v0.0.1-next.8...document-management-rest-client-v0.0.1-next.9) (2025-04-17)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* store document as a vertex ([#2](https://github.com/twinfoundation/document-management/issues/2)) ([7febedc](https://github.com/twinfoundation/document-management/commit/7febedc3fb31de9c19565d6326341046834f2c74))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Dependencies
|
|
26
|
+
|
|
27
|
+
* The following workspace dependencies were updated
|
|
28
|
+
* dependencies
|
|
29
|
+
* @twin.org/document-management-models bumped from 0.0.1-next.8 to 0.0.1-next.9
|
|
30
|
+
|
|
31
|
+
## [0.0.1-next.8](https://github.com/twinfoundation/document-management/compare/document-management-rest-client-v0.0.1-next.7...document-management-rest-client-v0.0.1-next.8) (2025-03-28)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### Miscellaneous Chores
|
|
35
|
+
|
|
36
|
+
* **document-management-rest-client:** Synchronize repo versions
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Dependencies
|
|
40
|
+
|
|
41
|
+
* The following workspace dependencies were updated
|
|
42
|
+
* dependencies
|
|
43
|
+
* @twin.org/document-management-models bumped from 0.0.1-next.7 to 0.0.1-next.8
|
|
44
|
+
|
|
45
|
+
## v0.0.1-next.7
|
|
46
|
+
|
|
47
|
+
- Initial Release
|
package/docs/examples.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @twin.org/document-management-rest-client - Examples
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
# Class: DocumentManagementClient
|
|
2
|
+
|
|
3
|
+
Client for performing document management through to REST endpoints.
|
|
4
|
+
|
|
5
|
+
## Extends
|
|
6
|
+
|
|
7
|
+
- `BaseRestClient`
|
|
8
|
+
|
|
9
|
+
## Implements
|
|
10
|
+
|
|
11
|
+
- `IDocumentManagementComponent`
|
|
12
|
+
|
|
13
|
+
## Constructors
|
|
14
|
+
|
|
15
|
+
### Constructor
|
|
16
|
+
|
|
17
|
+
> **new DocumentManagementClient**(`config`): `DocumentManagementClient`
|
|
18
|
+
|
|
19
|
+
Create a new instance of DocumentManagementClient.
|
|
20
|
+
|
|
21
|
+
#### Parameters
|
|
22
|
+
|
|
23
|
+
##### config
|
|
24
|
+
|
|
25
|
+
`IBaseRestClientConfig`
|
|
26
|
+
|
|
27
|
+
The configuration for the client.
|
|
28
|
+
|
|
29
|
+
#### Returns
|
|
30
|
+
|
|
31
|
+
`DocumentManagementClient`
|
|
32
|
+
|
|
33
|
+
#### Overrides
|
|
34
|
+
|
|
35
|
+
`BaseRestClient.constructor`
|
|
36
|
+
|
|
37
|
+
## Properties
|
|
38
|
+
|
|
39
|
+
### CLASS\_NAME
|
|
40
|
+
|
|
41
|
+
> `readonly` **CLASS\_NAME**: `string` = `DocumentManagementClient._CLASS_NAME`
|
|
42
|
+
|
|
43
|
+
Runtime name for the class.
|
|
44
|
+
|
|
45
|
+
#### Implementation of
|
|
46
|
+
|
|
47
|
+
`IDocumentManagementComponent.CLASS_NAME`
|
|
48
|
+
|
|
49
|
+
## Methods
|
|
50
|
+
|
|
51
|
+
### create()
|
|
52
|
+
|
|
53
|
+
> **create**(`documentId`, `documentIdFormat`, `documentCode`, `blob`, `annotationObject?`, `auditableItemGraphEdges?`, `options?`): `Promise`\<`string`\>
|
|
54
|
+
|
|
55
|
+
Store a document as an auditable item graph vertex and add its content to blob storage.
|
|
56
|
+
If the document id already exists and the blob data is different a new revision will be created.
|
|
57
|
+
For any other changes the current revision will be updated.
|
|
58
|
+
|
|
59
|
+
#### Parameters
|
|
60
|
+
|
|
61
|
+
##### documentId
|
|
62
|
+
|
|
63
|
+
`string`
|
|
64
|
+
|
|
65
|
+
The document id to create.
|
|
66
|
+
|
|
67
|
+
##### documentIdFormat
|
|
68
|
+
|
|
69
|
+
The format of the document identifier.
|
|
70
|
+
|
|
71
|
+
`undefined` | `string`
|
|
72
|
+
|
|
73
|
+
##### documentCode
|
|
74
|
+
|
|
75
|
+
`string`
|
|
76
|
+
|
|
77
|
+
The code for the document type.
|
|
78
|
+
|
|
79
|
+
##### blob
|
|
80
|
+
|
|
81
|
+
`Uint8Array`
|
|
82
|
+
|
|
83
|
+
The data to create the document with.
|
|
84
|
+
|
|
85
|
+
##### annotationObject?
|
|
86
|
+
|
|
87
|
+
`IJsonLdNodeObject`
|
|
88
|
+
|
|
89
|
+
Additional information to associate with the document.
|
|
90
|
+
|
|
91
|
+
##### auditableItemGraphEdges?
|
|
92
|
+
|
|
93
|
+
`object`[]
|
|
94
|
+
|
|
95
|
+
The auditable item graph vertices to connect the document to.
|
|
96
|
+
|
|
97
|
+
##### options?
|
|
98
|
+
|
|
99
|
+
Additional options for the set operation.
|
|
100
|
+
|
|
101
|
+
###### createAttestation?
|
|
102
|
+
|
|
103
|
+
`boolean`
|
|
104
|
+
|
|
105
|
+
Flag to create an attestation for the document, defaults to false.
|
|
106
|
+
|
|
107
|
+
###### addAlias?
|
|
108
|
+
|
|
109
|
+
`boolean`
|
|
110
|
+
|
|
111
|
+
Flag to add the document id as an alias to the aig vertex, defaults to true.
|
|
112
|
+
|
|
113
|
+
###### aliasAnnotationObject?
|
|
114
|
+
|
|
115
|
+
`IJsonLdNodeObject`
|
|
116
|
+
|
|
117
|
+
Annotation object for the alias.
|
|
118
|
+
|
|
119
|
+
#### Returns
|
|
120
|
+
|
|
121
|
+
`Promise`\<`string`\>
|
|
122
|
+
|
|
123
|
+
The auditable item graph vertex created for the document including its revision.
|
|
124
|
+
|
|
125
|
+
#### Implementation of
|
|
126
|
+
|
|
127
|
+
`IDocumentManagementComponent.create`
|
|
128
|
+
|
|
129
|
+
***
|
|
130
|
+
|
|
131
|
+
### update()
|
|
132
|
+
|
|
133
|
+
> **update**(`auditableItemGraphDocumentId`, `blob?`, `annotationObject?`, `auditableItemGraphEdges?`): `Promise`\<`void`\>
|
|
134
|
+
|
|
135
|
+
Update a document as an auditable item graph vertex and add its content to blob storage.
|
|
136
|
+
If the blob data is different a new revision will be created.
|
|
137
|
+
For any other changes the current revision will be updated.
|
|
138
|
+
|
|
139
|
+
#### Parameters
|
|
140
|
+
|
|
141
|
+
##### auditableItemGraphDocumentId
|
|
142
|
+
|
|
143
|
+
`string`
|
|
144
|
+
|
|
145
|
+
The auditable item graph vertex id which contains the document.
|
|
146
|
+
|
|
147
|
+
##### blob?
|
|
148
|
+
|
|
149
|
+
`Uint8Array`\<`ArrayBufferLike`\>
|
|
150
|
+
|
|
151
|
+
The data to update the document with.
|
|
152
|
+
|
|
153
|
+
##### annotationObject?
|
|
154
|
+
|
|
155
|
+
`IJsonLdNodeObject`
|
|
156
|
+
|
|
157
|
+
Additional information to associate with the document.
|
|
158
|
+
|
|
159
|
+
##### auditableItemGraphEdges?
|
|
160
|
+
|
|
161
|
+
`object`[]
|
|
162
|
+
|
|
163
|
+
The auditable item graph vertices to connect the document to, if undefined retains current connections.
|
|
164
|
+
|
|
165
|
+
#### Returns
|
|
166
|
+
|
|
167
|
+
`Promise`\<`void`\>
|
|
168
|
+
|
|
169
|
+
Nothing.
|
|
170
|
+
|
|
171
|
+
#### Implementation of
|
|
172
|
+
|
|
173
|
+
`IDocumentManagementComponent.update`
|
|
174
|
+
|
|
175
|
+
***
|
|
176
|
+
|
|
177
|
+
### get()
|
|
178
|
+
|
|
179
|
+
> **get**(`auditableItemGraphDocumentId`, `options?`, `cursor?`, `pageSize?`): `Promise`\<`IDocumentList`\>
|
|
180
|
+
|
|
181
|
+
Get a document using it's auditable item graph vertex id and optional revision.
|
|
182
|
+
|
|
183
|
+
#### Parameters
|
|
184
|
+
|
|
185
|
+
##### auditableItemGraphDocumentId
|
|
186
|
+
|
|
187
|
+
`string`
|
|
188
|
+
|
|
189
|
+
The auditable item graph vertex id which contains the document.
|
|
190
|
+
|
|
191
|
+
##### options?
|
|
192
|
+
|
|
193
|
+
Additional options for the get operation.
|
|
194
|
+
|
|
195
|
+
###### includeBlobStorageMetadata?
|
|
196
|
+
|
|
197
|
+
`boolean`
|
|
198
|
+
|
|
199
|
+
Flag to include the blob storage metadata for the document, defaults to false.
|
|
200
|
+
|
|
201
|
+
###### includeBlobStorageData?
|
|
202
|
+
|
|
203
|
+
`boolean`
|
|
204
|
+
|
|
205
|
+
Flag to include the blob storage data for the document, defaults to false.
|
|
206
|
+
|
|
207
|
+
###### includeAttestation?
|
|
208
|
+
|
|
209
|
+
`boolean`
|
|
210
|
+
|
|
211
|
+
Flag to include the attestation information for the document, defaults to false.
|
|
212
|
+
|
|
213
|
+
###### includeRemoved?
|
|
214
|
+
|
|
215
|
+
`boolean`
|
|
216
|
+
|
|
217
|
+
Flag to include deleted documents, defaults to false.
|
|
218
|
+
|
|
219
|
+
##### cursor?
|
|
220
|
+
|
|
221
|
+
`string`
|
|
222
|
+
|
|
223
|
+
The cursor to get the next chunk of revisions.
|
|
224
|
+
|
|
225
|
+
##### pageSize?
|
|
226
|
+
|
|
227
|
+
`number`
|
|
228
|
+
|
|
229
|
+
Page size of items to return, defaults to 1 so only most recent is returned.
|
|
230
|
+
|
|
231
|
+
#### Returns
|
|
232
|
+
|
|
233
|
+
`Promise`\<`IDocumentList`\>
|
|
234
|
+
|
|
235
|
+
The documents and revisions if requested, ordered by revision descending, cursor is set if there are more document revisions.
|
|
236
|
+
|
|
237
|
+
#### Implementation of
|
|
238
|
+
|
|
239
|
+
`IDocumentManagementComponent.get`
|
|
240
|
+
|
|
241
|
+
***
|
|
242
|
+
|
|
243
|
+
### removeRevision()
|
|
244
|
+
|
|
245
|
+
> **removeRevision**(`auditableItemGraphDocumentId`, `revision`): `Promise`\<`void`\>
|
|
246
|
+
|
|
247
|
+
Remove an auditable item graph vertex using it's id.
|
|
248
|
+
The document dateDeleted will be set, but can still be queried with the includeRemoved flag.
|
|
249
|
+
|
|
250
|
+
#### Parameters
|
|
251
|
+
|
|
252
|
+
##### auditableItemGraphDocumentId
|
|
253
|
+
|
|
254
|
+
`string`
|
|
255
|
+
|
|
256
|
+
The auditable item graph vertex id which contains the document.
|
|
257
|
+
|
|
258
|
+
##### revision
|
|
259
|
+
|
|
260
|
+
`number`
|
|
261
|
+
|
|
262
|
+
The revision of the document to remove.
|
|
263
|
+
|
|
264
|
+
#### Returns
|
|
265
|
+
|
|
266
|
+
`Promise`\<`void`\>
|
|
267
|
+
|
|
268
|
+
Nothing.
|
|
269
|
+
|
|
270
|
+
#### Implementation of
|
|
271
|
+
|
|
272
|
+
`IDocumentManagementComponent.removeRevision`
|
|
273
|
+
|
|
274
|
+
***
|
|
275
|
+
|
|
276
|
+
### query()
|
|
277
|
+
|
|
278
|
+
> **query**(`documentId`, `cursor?`, `pageSize?`): `Promise`\<`IAuditableItemGraphVertexList`\>
|
|
279
|
+
|
|
280
|
+
Find all the document with a specific id.
|
|
281
|
+
|
|
282
|
+
#### Parameters
|
|
283
|
+
|
|
284
|
+
##### documentId
|
|
285
|
+
|
|
286
|
+
`string`
|
|
287
|
+
|
|
288
|
+
The document id to find in the graph.
|
|
289
|
+
|
|
290
|
+
##### cursor?
|
|
291
|
+
|
|
292
|
+
`string`
|
|
293
|
+
|
|
294
|
+
The cursor to get the next chunk of documents.
|
|
295
|
+
|
|
296
|
+
##### pageSize?
|
|
297
|
+
|
|
298
|
+
`number`
|
|
299
|
+
|
|
300
|
+
The page size to get the next chunk of documents.
|
|
301
|
+
|
|
302
|
+
#### Returns
|
|
303
|
+
|
|
304
|
+
`Promise`\<`IAuditableItemGraphVertexList`\>
|
|
305
|
+
|
|
306
|
+
The graph vertices that contain documents referencing the specified document id.
|
|
307
|
+
|
|
308
|
+
#### Implementation of
|
|
309
|
+
|
|
310
|
+
`IDocumentManagementComponent.query`
|
package/locales/en.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@twin.org/document-management-rest-client",
|
|
3
|
+
"version": "0.0.1-next.10",
|
|
4
|
+
"description": "Document management contract implementation which can connect to REST endpoints",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/twinfoundation/document-management.git",
|
|
8
|
+
"directory": "packages/document-management-rest-client"
|
|
9
|
+
},
|
|
10
|
+
"author": "martyn.janes@iota.org",
|
|
11
|
+
"license": "Apache-2.0",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=20.0.0"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@twin.org/api-core": "next",
|
|
18
|
+
"@twin.org/api-models": "next",
|
|
19
|
+
"@twin.org/auditable-item-graph-models": "next",
|
|
20
|
+
"@twin.org/core": "next",
|
|
21
|
+
"@twin.org/data-json-ld": "next",
|
|
22
|
+
"@twin.org/document-management-models": "0.0.1-next.10",
|
|
23
|
+
"@twin.org/entity": "next",
|
|
24
|
+
"@twin.org/nameof": "next",
|
|
25
|
+
"@twin.org/standards-unece": "next",
|
|
26
|
+
"@twin.org/web": "next"
|
|
27
|
+
},
|
|
28
|
+
"main": "./dist/cjs/index.cjs",
|
|
29
|
+
"module": "./dist/esm/index.mjs",
|
|
30
|
+
"types": "./dist/types/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/types/index.d.ts",
|
|
34
|
+
"require": "./dist/cjs/index.cjs",
|
|
35
|
+
"import": "./dist/esm/index.mjs"
|
|
36
|
+
},
|
|
37
|
+
"./locales/*.json": "./locales/*.json"
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist/cjs",
|
|
41
|
+
"dist/esm",
|
|
42
|
+
"dist/types",
|
|
43
|
+
"locales",
|
|
44
|
+
"docs"
|
|
45
|
+
]
|
|
46
|
+
}
|