@twin.org/document-management-rest-client 0.0.3-next.9 → 0.9.0

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/docs/examples.md CHANGED
@@ -1 +1,118 @@
1
- # @twin.org/document-management-rest-client - Examples
1
+ # Document Management REST Client Examples
2
+
3
+ These examples walk through common client calls for creating, updating, reading, and finding documents from a remote service.
4
+
5
+ ## DocumentManagementRestClient
6
+
7
+ ```typescript
8
+ import { DocumentManagementRestClient } from '@twin.org/document-management-rest-client';
9
+ import { Converter } from '@twin.org/core';
10
+ import { UneceDocumentCodeList } from '@twin.org/standards-unece';
11
+
12
+ const client = new DocumentManagementRestClient({
13
+ endpoint: 'http://localhost:3000'
14
+ });
15
+
16
+ const blobBytes = Converter.utf8ToBytes('Updated bill of lading payload');
17
+ const edgeTargetId = 'aig:shipment-vertex';
18
+ ```
19
+
20
+ ```typescript
21
+ const componentName = client.className();
22
+ console.log(componentName); // DocumentManagementRestClient
23
+ ```
24
+
25
+ ```typescript
26
+ const createdVertexId = await client.create(
27
+ 'BOL-2026-0001',
28
+ 'bol',
29
+ UneceDocumentCodeList.BillOfLading,
30
+ blobBytes,
31
+ {
32
+ '@context': 'https://schema.org',
33
+ '@type': 'DigitalDocument',
34
+ name: 'bol-2026-0001.pdf'
35
+ },
36
+ [
37
+ {
38
+ targetId: edgeTargetId,
39
+ addAlias: true,
40
+ aliasAnnotationObject: {
41
+ '@context': 'https://schema.org',
42
+ '@type': 'Thing',
43
+ name: 'Shipment link'
44
+ }
45
+ }
46
+ ],
47
+ {
48
+ createAttestation: true,
49
+ addAlias: true,
50
+ aliasAnnotationObject: {
51
+ '@context': 'https://schema.org',
52
+ '@type': 'Thing',
53
+ name: 'Primary alias'
54
+ }
55
+ }
56
+ );
57
+
58
+ console.log(createdVertexId); // aig:document-vertex-1
59
+ ```
60
+
61
+ ```typescript
62
+ await client.update(
63
+ 'aig:document-vertex-1',
64
+ Converter.utf8ToBytes('Second revision payload'),
65
+ {
66
+ '@context': 'https://schema.org',
67
+ '@type': 'CreativeWork',
68
+ name: 'bol-2026-0001-rev1.pdf'
69
+ },
70
+ [
71
+ {
72
+ targetId: edgeTargetId,
73
+ addAlias: true,
74
+ aliasAnnotationObject: {
75
+ '@context': 'https://schema.org',
76
+ '@type': 'Thing',
77
+ name: 'Shipment alias'
78
+ }
79
+ }
80
+ ]
81
+ );
82
+ ```
83
+
84
+ ```typescript
85
+ const latest = await client.get(
86
+ 'aig:document-vertex-1',
87
+ {
88
+ includeBlobStorageMetadata: true,
89
+ includeAttestation: true
90
+ },
91
+ '0',
92
+ 2
93
+ );
94
+
95
+ console.log(latest.entries.itemListElement.length); // 2
96
+ console.log(latest.cursor); // 2
97
+ ```
98
+
99
+ ```typescript
100
+ const revisionOne = await client.getRevision('aig:document-vertex-1', 1, {
101
+ includeBlobStorageData: true,
102
+ includeAttestation: true
103
+ });
104
+
105
+ console.log(revisionOne.documentRevision); // 1
106
+ console.log(revisionOne.documentId); // BOL-2026-0001
107
+ ```
108
+
109
+ ```typescript
110
+ await client.removeRevision('aig:document-vertex-1', 1);
111
+ ```
112
+
113
+ ```typescript
114
+ const matches = await client.query('BOL-2026-0001', '0', 10);
115
+
116
+ console.log(matches.entries.vertices.length); // 1
117
+ console.log(matches.cursor); // undefined
118
+ ```
@@ -36,7 +36,7 @@ The configuration for the client.
36
36
 
37
37
  ## Properties
38
38
 
39
- ### CLASS\_NAME
39
+ ### CLASS\_NAME {#class_name}
40
40
 
41
41
  > `readonly` `static` **CLASS\_NAME**: `string`
42
42
 
@@ -44,7 +44,7 @@ Runtime name for the class.
44
44
 
45
45
  ## Methods
46
46
 
47
- ### className()
47
+ ### className() {#classname}
48
48
 
49
49
  > **className**(): `string`
50
50
 
@@ -62,9 +62,9 @@ The class name of the component.
62
62
 
63
63
  ***
64
64
 
65
- ### create()
65
+ ### create() {#create}
66
66
 
67
- > **create**(`documentId`, `documentIdFormat`, `documentCode`, `blob`, `annotationObject?`, `auditableItemGraphEdges?`, `options?`): `Promise`\<`string`\>
67
+ > **create**(`document`, `blob`, `auditableItemGraphEdges?`, `options?`): `Promise`\<`string`\>
68
68
 
69
69
  Store a document as an auditable item graph vertex and add its content to blob storage.
70
70
  If the document id already exists and the blob data is different a new revision will be created.
@@ -72,39 +72,21 @@ For any other changes the current revision will be updated.
72
72
 
73
73
  #### Parameters
74
74
 
75
- ##### documentId
76
-
77
- `string`
78
-
79
- The document id to create.
80
-
81
- ##### documentIdFormat
82
-
83
- The format of the document identifier.
75
+ ##### document
84
76
 
85
- `string` | `undefined`
77
+ `IDocumentBase`
86
78
 
87
- ##### documentCode
88
-
89
- `UneceDocumentCodeList`
90
-
91
- The code for the document type.
79
+ The document base properties.
92
80
 
93
81
  ##### blob
94
82
 
95
- `Uint8Array`
96
-
97
- The data to create the document with.
98
-
99
- ##### annotationObject?
100
-
101
- `IJsonLdNodeObject`
83
+ `string` \| `Uint8Array`\<`ArrayBufferLike`\>
102
84
 
103
- Additional information to associate with the document.
85
+ The data to create the document with as bytes, or an existing blob storage entry id.
104
86
 
105
87
  ##### auditableItemGraphEdges?
106
88
 
107
- `object`[]
89
+ `IDocumentManagementEdgeEntry`[]
108
90
 
109
91
  The auditable item graph vertices to connect the document to.
110
92
 
@@ -112,13 +94,13 @@ The auditable item graph vertices to connect the document to.
112
94
 
113
95
  Additional options for the set operation.
114
96
 
115
- ###### createAttestation?
97
+ ###### includeAttestation?
116
98
 
117
99
  `boolean`
118
100
 
119
101
  Flag to create an attestation for the document, defaults to false.
120
102
 
121
- ###### addAlias?
103
+ ###### includeAlias?
122
104
 
123
105
  `boolean`
124
106
 
@@ -142,9 +124,9 @@ The auditable item graph vertex created for the document including its revision.
142
124
 
143
125
  ***
144
126
 
145
- ### update()
127
+ ### updatePartial() {#updatepartial}
146
128
 
147
- > **update**(`auditableItemGraphDocumentId`, `blob?`, `annotationObject?`, `auditableItemGraphEdges?`): `Promise`\<`void`\>
129
+ > **updatePartial**(`auditableItemGraphDocumentId`, `document?`, `blob?`, `auditableItemGraphEdges?`, `options?`): `Promise`\<`void`\>
148
130
 
149
131
  Update a document as an auditable item graph vertex and add its content to blob storage.
150
132
  If the blob data is different a new revision will be created.
@@ -158,37 +140,73 @@ For any other changes the current revision will be updated.
158
140
 
159
141
  The auditable item graph vertex id which contains the document.
160
142
 
161
- ##### blob?
143
+ ##### document?
162
144
 
163
- `Uint8Array`\<`ArrayBufferLike`\>
145
+ `Partial`\<`Pick`\<`IDocumentBase`, `"annotationObject"` \| `"documentIdFormat"` \| `"documentCode"`\>\>
164
146
 
165
- The data to update the document with.
147
+ The document base properties to update. annotationObject, documentIdFormat and documentCode are applied in-place to the current revision.
166
148
 
167
- ##### annotationObject?
149
+ ##### blob?
168
150
 
169
- `IJsonLdNodeObject`
151
+ `string` \| `Uint8Array`\<`ArrayBufferLike`\>
170
152
 
171
- Additional information to associate with the document.
153
+ The data to update the document with as bytes, or an existing blob storage entry id.
172
154
 
173
155
  ##### auditableItemGraphEdges?
174
156
 
175
- `object`[]
157
+ Explicit edge delta to apply. If undefined, existing connections
158
+ are retained unchanged. Use `add` to create new connections and `remove` to disconnect existing
159
+ ones by their target vertex id. To update alias metadata on an already-connected vertex, include
160
+ it in `add` with the updated `aliasAnnotationObject` — AIG's alias patch is an upsert, so the
161
+ alias is updated in place without creating a duplicate back-edge.
162
+
163
+ ###### add?
176
164
 
177
- The auditable item graph vertices to connect the document to, if undefined retains current connections.
165
+ `IDocumentManagementEdgeEntry`[]
166
+
167
+ Connections to add; each creates a back-edge on the connected vertex.
168
+
169
+ ###### remove?
170
+
171
+ `string`[]
172
+
173
+ Target vertex IDs to disconnect; their back-edges are removed.
174
+
175
+ ##### options?
176
+
177
+ Additional options for the update operation.
178
+
179
+ ###### includeAttestation?
180
+
181
+ `boolean`
182
+
183
+ Set to true to start attesting the document, or false to remove the existing attestation. Omit to leave unchanged.
184
+
185
+ ###### includeAlias?
186
+
187
+ `boolean`
188
+
189
+ Set to true to add the document id as an alias on the aig vertex, or false to remove it. Omit to leave unchanged.
190
+
191
+ ###### aliasAnnotationObject?
192
+
193
+ `IJsonLdNodeObject`
194
+
195
+ Annotation object for the alias when adding.
178
196
 
179
197
  #### Returns
180
198
 
181
199
  `Promise`\<`void`\>
182
200
 
183
- Nothing.
201
+ A promise that resolves when the document has been updated.
184
202
 
185
203
  #### Implementation of
186
204
 
187
- `IDocumentManagementComponent.update`
205
+ `IDocumentManagementComponent.updatePartial`
188
206
 
189
207
  ***
190
208
 
191
- ### get()
209
+ ### get() {#get}
192
210
 
193
211
  > **get**(`auditableItemGraphDocumentId`, `options?`, `cursor?`, `limit?`): `Promise`\<\{ `entries`: `IDocumentList`; `cursor?`: `string`; \}\>
194
212
 
@@ -230,6 +248,12 @@ Flag to include the attestation information for the document, defaults to false.
230
248
 
231
249
  Flag to include deleted documents, defaults to false.
232
250
 
251
+ ###### includeDeletedEdges?
252
+
253
+ `boolean`
254
+
255
+ Flag to include soft-deleted edges in the response, defaults to false.
256
+
233
257
  ###### extractRuleGroupId?
234
258
 
235
259
  `string`
@@ -266,9 +290,9 @@ The documents and revisions if requested, ordered by revision descending, cursor
266
290
 
267
291
  ***
268
292
 
269
- ### getRevision()
293
+ ### getRevision() {#getrevision}
270
294
 
271
- > **getRevision**(`auditableItemGraphDocumentId`, `revision`, `options?`): `Promise`\<`IDocument`\>
295
+ > **getRevision**(`auditableItemGraphDocumentId`, `revision`, `options?`): `Promise`\<`IDocumentHydrated`\>
272
296
 
273
297
  Get a document revision using it's auditable item graph vertex id.
274
298
 
@@ -322,9 +346,9 @@ By default extraction will auto detect the mime type of the document, this can b
322
346
 
323
347
  #### Returns
324
348
 
325
- `Promise`\<`IDocument`\>
349
+ `Promise`\<`IDocumentHydrated`\>
326
350
 
327
- The documents and revisions if requested, ordered by revision descending, cursor is set if there are more document revisions.
351
+ The document for the specified revision.
328
352
 
329
353
  #### Implementation of
330
354
 
@@ -332,7 +356,7 @@ The documents and revisions if requested, ordered by revision descending, cursor
332
356
 
333
357
  ***
334
358
 
335
- ### removeRevision()
359
+ ### removeRevision() {#removerevision}
336
360
 
337
361
  > **removeRevision**(`auditableItemGraphDocumentId`, `revision`): `Promise`\<`void`\>
338
362
 
@@ -357,7 +381,7 @@ The revision of the document to remove.
357
381
 
358
382
  `Promise`\<`void`\>
359
383
 
360
- Nothing.
384
+ A promise that resolves when the revision has been removed.
361
385
 
362
386
  #### Implementation of
363
387
 
@@ -365,7 +389,7 @@ Nothing.
365
389
 
366
390
  ***
367
391
 
368
- ### query()
392
+ ### query() {#query}
369
393
 
370
394
  > **query**(`documentId`, `cursor?`, `limit?`): `Promise`\<\{ `entries`: `IAuditableItemGraphVertexList`; `cursor?`: `string`; \}\>
371
395
 
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@twin.org/document-management-rest-client",
3
- "version": "0.0.3-next.9",
4
- "description": "Document management contract implementation which can connect to REST endpoints",
3
+ "version": "0.9.0",
4
+ "description": "REST client operations for creating, updating, retrieving, and querying managed documents.",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/twinfoundation/document-management.git",
7
+ "url": "git+https://github.com/iotaledger/twin-document-management.git",
8
8
  "directory": "packages/document-management-rest-client"
9
9
  },
10
10
  "author": "martyn.janes@iota.org",
@@ -14,16 +14,16 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
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.3-next.9",
23
- "@twin.org/entity": "next",
24
- "@twin.org/nameof": "next",
25
- "@twin.org/standards-unece": "next",
26
- "@twin.org/web": "next"
17
+ "@twin.org/api-core": "^0.9.0",
18
+ "@twin.org/api-models": "^0.9.0",
19
+ "@twin.org/auditable-item-graph-models": "^0.9.0",
20
+ "@twin.org/core": "^0.9.0",
21
+ "@twin.org/data-json-ld": "^0.9.0",
22
+ "@twin.org/document-management-models": "^0.9.0",
23
+ "@twin.org/entity": "^0.9.0",
24
+ "@twin.org/nameof": "^0.9.0",
25
+ "@twin.org/standards-unece": "^0.9.0",
26
+ "@twin.org/web": "^0.9.0"
27
27
  },
28
28
  "main": "./dist/es/index.js",
29
29
  "types": "./dist/types/index.d.ts",
@@ -54,7 +54,7 @@
54
54
  "rest-api"
55
55
  ],
56
56
  "bugs": {
57
- "url": "git+https://github.com/twinfoundation/document-management/issues"
57
+ "url": "git+https://github.com/iotaledger/twin-document-management/issues"
58
58
  },
59
59
  "homepage": "https://twindev.org"
60
60
  }