@twin.org/document-management-service 0.0.3-next.11 → 0.0.3-next.13

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,121 @@
1
- # @twin.org/document-management-service - Examples
1
+ # Document Management Service Examples
2
+
3
+ Use these snippets to wire the service into existing components and handle a full document lifecycle from creation through querying.
4
+
5
+ ## DocumentManagementService
6
+
7
+ ```typescript
8
+ import { ComponentFactory, Converter } from '@twin.org/core';
9
+ import { DocumentManagementService } from '@twin.org/document-management-service';
10
+ import { UneceDocumentCodeList } from '@twin.org/standards-unece';
11
+
12
+ // Register concrete components before constructing the service.
13
+ ComponentFactory.register('auditable-item-graph', () => auditableItemGraphComponent);
14
+ ComponentFactory.register('blob-storage', () => blobStorageComponent);
15
+ ComponentFactory.register('attestation', () => attestationComponent);
16
+ ComponentFactory.register('data-processing', () => dataProcessingComponent);
17
+
18
+ const service = new DocumentManagementService();
19
+ const newBlob = Converter.utf8ToBytes('Initial customs document payload');
20
+ ```
21
+
22
+ ```typescript
23
+ const className = service.className();
24
+ console.log(className); // DocumentManagementService
25
+ ```
26
+
27
+ ```typescript
28
+ const vertexId = await service.create(
29
+ 'CUS-2026-0100',
30
+ 'customs',
31
+ UneceDocumentCodeList.CustomsDeclaration,
32
+ newBlob,
33
+ {
34
+ '@context': 'https://schema.org',
35
+ '@type': 'DigitalDocument',
36
+ name: 'customs-2026-0100.xml'
37
+ },
38
+ [
39
+ {
40
+ targetId: 'aig:shipment-123',
41
+ addAlias: true,
42
+ aliasAnnotationObject: {
43
+ '@context': 'https://schema.org',
44
+ '@type': 'Thing',
45
+ name: 'Shipment reference'
46
+ }
47
+ }
48
+ ],
49
+ {
50
+ createAttestation: true,
51
+ addAlias: true,
52
+ aliasAnnotationObject: {
53
+ '@context': 'https://schema.org',
54
+ '@type': 'Thing',
55
+ name: 'Primary document alias'
56
+ }
57
+ }
58
+ );
59
+
60
+ console.log(vertexId); // aig:document-vertex-2
61
+ ```
62
+
63
+ ```typescript
64
+ await service.update(
65
+ 'aig:document-vertex-2',
66
+ Converter.utf8ToBytes('Customs document payload revision 1'),
67
+ {
68
+ '@context': 'https://schema.org',
69
+ '@type': 'CreativeWork',
70
+ name: 'customs-2026-0100-rev1.xml'
71
+ },
72
+ [
73
+ {
74
+ targetId: 'aig:shipment-123',
75
+ addAlias: true,
76
+ aliasAnnotationObject: {
77
+ '@context': 'https://schema.org',
78
+ '@type': 'Thing',
79
+ name: 'Updated shipment alias'
80
+ }
81
+ }
82
+ ]
83
+ );
84
+ ```
85
+
86
+ ```typescript
87
+ const latestDocuments = await service.get(
88
+ 'aig:document-vertex-2',
89
+ {
90
+ includeBlobStorageMetadata: true,
91
+ includeAttestation: true,
92
+ includeRemoved: false
93
+ },
94
+ '0',
95
+ 2
96
+ );
97
+
98
+ console.log(latestDocuments.entries.itemListElement.length); // 2
99
+ console.log(latestDocuments.cursor); // 2
100
+ ```
101
+
102
+ ```typescript
103
+ const revision = await service.getRevision('aig:document-vertex-2', 1, {
104
+ includeBlobStorageData: true,
105
+ includeAttestation: true
106
+ });
107
+
108
+ console.log(revision.documentRevision); // 1
109
+ console.log(revision.documentCode); // Cusdec
110
+ ```
111
+
112
+ ```typescript
113
+ await service.removeRevision('aig:document-vertex-2', 1);
114
+ ```
115
+
116
+ ```typescript
117
+ const queryResult = await service.query('CUS-2026-0100', '0', 10);
118
+
119
+ console.log(queryResult.entries.vertices.length); // 1
120
+ console.log(queryResult.cursor); // undefined
121
+ ```
@@ -1013,32 +1013,29 @@
1013
1013
  "components": {
1014
1014
  "schemas": {
1015
1015
  "Document": {
1016
+ "description": "Interface describing a document.",
1016
1017
  "type": "object",
1017
1018
  "properties": {
1018
1019
  "@context": {
1019
1020
  "type": "array",
1020
- "minItems": 3,
1021
- "description": "JSON-LD Context.",
1022
1021
  "prefixItems": [
1023
1022
  {
1024
- "type": "string",
1025
1023
  "const": "https://schema.org"
1026
1024
  },
1027
1025
  {
1028
- "type": "string",
1029
1026
  "const": "https://schema.twindev.org/documents/"
1030
1027
  },
1031
1028
  {
1032
- "type": "string",
1033
1029
  "const": "https://schema.twindev.org/common/"
1034
1030
  }
1035
1031
  ],
1036
1032
  "items": {
1037
1033
  "$ref": "https://schema.twindev.org/json-ld/JsonLdContextDefinitionElement"
1038
- }
1034
+ },
1035
+ "minItems": 3,
1036
+ "description": "JSON-LD Context."
1039
1037
  },
1040
1038
  "type": {
1041
- "type": "string",
1042
1039
  "const": "Document",
1043
1040
  "description": "JSON-LD Type."
1044
1041
  },
@@ -1048,62 +1045,62 @@
1048
1045
  },
1049
1046
  "documentId": {
1050
1047
  "type": "string",
1051
- "description": "The id of the document. json-ld type:schema:identifier"
1048
+ "description": "The id of the document."
1052
1049
  },
1053
1050
  "documentIdFormat": {
1054
1051
  "type": "string",
1055
- "description": "The format of the document id. json-ld type:schema:Text"
1052
+ "description": "The format of the document id."
1056
1053
  },
1057
1054
  "documentCode": {
1058
1055
  "$ref": "https://schema.twindev.org/unece/UneceDocumentCodeList"
1059
1056
  },
1060
1057
  "documentRevision": {
1061
1058
  "type": "number",
1062
- "description": "The revision of the document as a 0 based index. json-ld type:schema:Integer"
1059
+ "description": "The revision of the document as a 0 based index."
1063
1060
  },
1064
1061
  "annotationObject": {
1065
1062
  "$ref": "https://schema.twindev.org/json-ld/JsonLdNodeObject"
1066
1063
  },
1067
1064
  "blobStorageId": {
1068
1065
  "type": "string",
1069
- "description": "The blob storage id for the document. json-ld type:schema:identifier"
1066
+ "description": "The blob storage id for the document."
1070
1067
  },
1071
1068
  "integrity": {
1072
1069
  "type": "string",
1073
- "description": "The integrity of the blob data. json-ld namespace:twin-common"
1070
+ "description": "The integrity of the blob data."
1074
1071
  },
1075
1072
  "blobStorageEntry": {
1076
1073
  "$ref": "https://schema.twindev.org/blob-storage/BlobStorageEntry"
1077
1074
  },
1078
1075
  "extractedData": {
1079
- "description": "The data extracted from the document using data extraction services. json-ld type:json"
1076
+ "description": "The data extracted from the document using data extraction services."
1080
1077
  },
1081
1078
  "attestationId": {
1082
1079
  "type": "string",
1083
- "description": "The attestation for the document if one was created. json-ld type:schema:identifier"
1080
+ "description": "The attestation for the document if one was created."
1084
1081
  },
1085
1082
  "attestationInformation": {
1086
1083
  "$ref": "https://schema.twindev.org/attestation/AttestationInformation"
1087
1084
  },
1088
1085
  "dateCreated": {
1089
1086
  "type": "string",
1090
- "description": "The date/time of when the document was created. json-ld namespace:schema"
1087
+ "description": "The date/time of when the document was created."
1091
1088
  },
1092
1089
  "dateModified": {
1093
1090
  "type": "string",
1094
- "description": "The date/time of when the document was modified. json-ld namespace:schema"
1091
+ "description": "The date/time of when the document was modified."
1095
1092
  },
1096
1093
  "dateDeleted": {
1097
1094
  "type": "string",
1098
- "description": "The date/time of when the document was deleted, as we never actually remove items. json-ld namespace:schema"
1095
+ "description": "The date/time of when the document was deleted, as we never actually remove items."
1099
1096
  },
1100
1097
  "organizationIdentity": {
1101
1098
  "type": "string",
1102
- "description": "The organization which added the document to the graph. json-ld namespace:twin-common"
1099
+ "description": "The organization which added the document to the graph."
1103
1100
  },
1104
1101
  "userIdentity": {
1105
1102
  "type": "string",
1106
- "description": "The user who added the document to the graph. json-ld namespace:twin-common"
1103
+ "description": "The user who added the document to the graph."
1107
1104
  }
1108
1105
  },
1109
1106
  "required": [
@@ -1116,36 +1113,32 @@
1116
1113
  "blobStorageId",
1117
1114
  "integrity",
1118
1115
  "dateCreated"
1119
- ],
1120
- "description": "Interface describing a document."
1116
+ ]
1121
1117
  },
1122
1118
  "DocumentList": {
1119
+ "description": "Interface describing a list of document entries.",
1123
1120
  "type": "object",
1124
1121
  "properties": {
1125
1122
  "@context": {
1126
1123
  "type": "array",
1127
- "minItems": 3,
1128
- "description": "JSON-LD Context.",
1129
1124
  "prefixItems": [
1130
1125
  {
1131
- "type": "string",
1132
1126
  "const": "https://schema.org"
1133
1127
  },
1134
1128
  {
1135
- "type": "string",
1136
1129
  "const": "https://schema.twindev.org/documents/"
1137
1130
  },
1138
1131
  {
1139
- "type": "string",
1140
1132
  "const": "https://schema.twindev.org/common/"
1141
1133
  }
1142
1134
  ],
1143
1135
  "items": {
1144
1136
  "$ref": "https://schema.twindev.org/json-ld/JsonLdContextDefinitionElement"
1145
- }
1137
+ },
1138
+ "minItems": 3,
1139
+ "description": "JSON-LD Context."
1146
1140
  },
1147
1141
  "type": {
1148
- "type": "string",
1149
1142
  "const": "ItemList",
1150
1143
  "description": "JSON-LD Type."
1151
1144
  },
@@ -1154,22 +1147,21 @@
1154
1147
  "items": {
1155
1148
  "$ref": "#/components/schemas/Document"
1156
1149
  },
1157
- "description": "The list of documents. json-ld namespace:schema"
1150
+ "description": "The list of documents."
1158
1151
  },
1159
1152
  "edges": {
1160
1153
  "type": "array",
1161
1154
  "items": {
1162
1155
  "type": "string"
1163
1156
  },
1164
- "description": "The ids of the other vertices which are connected to the document. json-ld container:set"
1157
+ "description": "The ids of the other vertices which are connected to the document."
1165
1158
  }
1166
1159
  },
1167
1160
  "required": [
1168
1161
  "@context",
1169
1162
  "type",
1170
1163
  "itemListElement"
1171
- ],
1172
- "description": "Interface describing a list of document entries."
1164
+ ]
1173
1165
  },
1174
1166
  "DocumentManagementCreateRequest": {
1175
1167
  "type": "object",
@@ -1209,8 +1201,7 @@
1209
1201
  },
1210
1202
  "required": [
1211
1203
  "targetId"
1212
- ],
1213
- "additionalProperties": false
1204
+ ]
1214
1205
  },
1215
1206
  "description": "The auditable item graph vertices to connect the document to."
1216
1207
  },
@@ -1228,6 +1219,7 @@
1228
1219
  },
1229
1220
  "required": [
1230
1221
  "documentId",
1222
+ "documentIdFormat",
1231
1223
  "documentCode",
1232
1224
  "blob"
1233
1225
  ],
@@ -1260,8 +1252,7 @@
1260
1252
  },
1261
1253
  "required": [
1262
1254
  "targetId"
1263
- ],
1264
- "additionalProperties": false
1255
+ ]
1265
1256
  },
1266
1257
  "description": "The auditable item graph vertices to connect the document to."
1267
1258
  }
@@ -1269,6 +1260,7 @@
1269
1260
  "description": "The body parameters."
1270
1261
  },
1271
1262
  "Error": {
1263
+ "description": "Model to describe serialized error.",
1272
1264
  "type": "object",
1273
1265
  "properties": {
1274
1266
  "name": {
@@ -1277,7 +1269,7 @@
1277
1269
  },
1278
1270
  "message": {
1279
1271
  "type": "string",
1280
- "description": "The message for the error."
1272
+ "description": "The message for the error as an i18n key."
1281
1273
  },
1282
1274
  "source": {
1283
1275
  "type": "string",
@@ -1299,8 +1291,7 @@
1299
1291
  "required": [
1300
1292
  "name",
1301
1293
  "message"
1302
- ],
1303
- "description": "Model to describe serialized error."
1294
+ ]
1304
1295
  },
1305
1296
  "NotFoundResponse": {
1306
1297
  "type": "object",
@@ -1308,35 +1299,12 @@
1308
1299
  "notFoundId": {
1309
1300
  "type": "string",
1310
1301
  "description": "The id if the item that was not found."
1311
- },
1312
- "name": {
1313
- "type": "string",
1314
- "description": "The name for the error."
1315
- },
1316
- "message": {
1317
- "type": "string",
1318
- "description": "The message for the error."
1319
- },
1320
- "source": {
1321
- "type": "string",
1322
- "description": "The source of the error."
1323
- },
1324
- "properties": {
1325
- "type": "object",
1326
- "additionalProperties": {},
1327
- "description": "Any additional information for the error."
1328
- },
1329
- "stack": {
1330
- "type": "string",
1331
- "description": "The stack trace for the error."
1332
- },
1333
- "cause": {
1334
- "$ref": "#/components/schemas/Error"
1335
1302
  }
1336
1303
  },
1337
- "required": [
1338
- "message",
1339
- "name"
1304
+ "allOf": [
1305
+ {
1306
+ "$ref": "#/components/schemas/Error"
1307
+ }
1340
1308
  ],
1341
1309
  "description": "The body which contains the error."
1342
1310
  }
@@ -28,7 +28,7 @@ The options for the service.
28
28
 
29
29
  ## Properties
30
30
 
31
- ### CLASS\_NAME
31
+ ### CLASS\_NAME {#class_name}
32
32
 
33
33
  > `readonly` `static` **CLASS\_NAME**: `string`
34
34
 
@@ -36,7 +36,7 @@ Runtime name for the class.
36
36
 
37
37
  ## Methods
38
38
 
39
- ### className()
39
+ ### className() {#classname}
40
40
 
41
41
  > **className**(): `string`
42
42
 
@@ -54,7 +54,7 @@ The class name of the component.
54
54
 
55
55
  ***
56
56
 
57
- ### create()
57
+ ### create() {#create}
58
58
 
59
59
  > **create**(`documentId`, `documentIdFormat`, `documentCode`, `blob`, `annotationObject?`, `auditableItemGraphEdges?`, `options?`): `Promise`\<`string`\>
60
60
 
@@ -72,9 +72,9 @@ The document id to create.
72
72
 
73
73
  ##### documentIdFormat
74
74
 
75
- The format of the document identifier.
75
+ `string` \| `undefined`
76
76
 
77
- `string` | `undefined`
77
+ The format of the document identifier.
78
78
 
79
79
  ##### documentCode
80
80
 
@@ -134,7 +134,7 @@ The auditable item graph vertex created for the document including its revision.
134
134
 
135
135
  ***
136
136
 
137
- ### update()
137
+ ### update() {#update}
138
138
 
139
139
  > **update**(`auditableItemGraphDocumentId`, `blob?`, `annotationObject?`, `auditableItemGraphEdges?`): `Promise`\<`void`\>
140
140
 
@@ -180,7 +180,7 @@ Nothing.
180
180
 
181
181
  ***
182
182
 
183
- ### get()
183
+ ### get() {#get}
184
184
 
185
185
  > **get**(`auditableItemGraphDocumentId`, `options?`, `cursor?`, `limit?`): `Promise`\<\{ `entries`: `IDocumentList`; `cursor?`: `string`; \}\>
186
186
 
@@ -258,7 +258,7 @@ The documents and revisions if requested, ordered by revision descending, cursor
258
258
 
259
259
  ***
260
260
 
261
- ### getRevision()
261
+ ### getRevision() {#getrevision}
262
262
 
263
263
  > **getRevision**(`auditableItemGraphDocumentId`, `revision`, `options?`): `Promise`\<`IDocument`\>
264
264
 
@@ -324,7 +324,7 @@ The documents and revisions if requested, ordered by revision descending, cursor
324
324
 
325
325
  ***
326
326
 
327
- ### removeRevision()
327
+ ### removeRevision() {#removerevision}
328
328
 
329
329
  > **removeRevision**(`auditableItemGraphDocumentId`, `revision`): `Promise`\<`void`\>
330
330
 
@@ -357,7 +357,7 @@ Nothing.
357
357
 
358
358
  ***
359
359
 
360
- ### query()
360
+ ### query() {#query}
361
361
 
362
362
  > **query**(`documentId`, `cursor?`, `limit?`): `Promise`\<\{ `entries`: `IAuditableItemGraphVertexList`; `cursor?`: `string`; \}\>
363
363
 
@@ -4,9 +4,9 @@ Options for the document management Service constructor.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### auditableItemGraphComponentType?
7
+ ### auditableItemGraphComponentType? {#auditableitemgraphcomponenttype}
8
8
 
9
- > `optional` **auditableItemGraphComponentType**: `string`
9
+ > `optional` **auditableItemGraphComponentType?**: `string`
10
10
 
11
11
  The type of the auditable item graph component.
12
12
 
@@ -18,9 +18,9 @@ auditable-item-graph
18
18
 
19
19
  ***
20
20
 
21
- ### blobStorageComponentType?
21
+ ### blobStorageComponentType? {#blobstoragecomponenttype}
22
22
 
23
- > `optional` **blobStorageComponentType**: `string`
23
+ > `optional` **blobStorageComponentType?**: `string`
24
24
 
25
25
  The type of the blob storage component.
26
26
 
@@ -32,9 +32,9 @@ blob-storage
32
32
 
33
33
  ***
34
34
 
35
- ### attestationComponentType?
35
+ ### attestationComponentType? {#attestationcomponenttype}
36
36
 
37
- > `optional` **attestationComponentType**: `string`
37
+ > `optional` **attestationComponentType?**: `string`
38
38
 
39
39
  The type of the attestation component.
40
40
 
@@ -46,9 +46,9 @@ attestation
46
46
 
47
47
  ***
48
48
 
49
- ### dataProcessingComponentType?
49
+ ### dataProcessingComponentType? {#dataprocessingcomponenttype}
50
50
 
51
- > `optional` **dataProcessingComponentType**: `string`
51
+ > `optional` **dataProcessingComponentType?**: `string`
52
52
 
53
53
  The type of the data processing component.
54
54
 
@@ -60,8 +60,8 @@ data-processing
60
60
 
61
61
  ***
62
62
 
63
- ### config?
63
+ ### config? {#config}
64
64
 
65
- > `optional` **config**: [`IDocumentManagementServiceConfig`](IDocumentManagementServiceConfig.md)
65
+ > `optional` **config?**: [`IDocumentManagementServiceConfig`](IDocumentManagementServiceConfig.md)
66
66
 
67
67
  The configuration for the service.
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@twin.org/document-management-service",
3
- "version": "0.0.3-next.11",
4
- "description": "Document management contract implementation and REST endpoint definitions",
3
+ "version": "0.0.3-next.13",
4
+ "description": "Service-side document lifecycle operations and REST route generation for server integrations.",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/twinfoundation/document-management.git",
7
+ "url": "git+https://github.com/iotaledger/document-management.git",
8
8
  "directory": "packages/document-management-service"
9
9
  },
10
10
  "author": "martyn.janes@iota.org",
@@ -23,7 +23,7 @@
23
23
  "@twin.org/crypto": "next",
24
24
  "@twin.org/data-json-ld": "next",
25
25
  "@twin.org/data-processing-models": "next",
26
- "@twin.org/document-management-models": "0.0.3-next.11",
26
+ "@twin.org/document-management-models": "0.0.3-next.13",
27
27
  "@twin.org/entity": "next",
28
28
  "@twin.org/entity-storage-models": "next",
29
29
  "@twin.org/nameof": "next",
@@ -63,7 +63,7 @@
63
63
  "business-logic"
64
64
  ],
65
65
  "bugs": {
66
- "url": "git+https://github.com/twinfoundation/document-management/issues"
66
+ "url": "git+https://github.com/iotaledger/document-management/issues"
67
67
  },
68
68
  "homepage": "https://twindev.org"
69
69
  }