@twin.org/document-management-rest-client 0.0.2-next.4 → 0.0.3-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.
@@ -1,13 +1,13 @@
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
1
  // Copyright 2024 IOTA Stiftung.
6
2
  // SPDX-License-Identifier: Apache-2.0.
3
+ import { BaseRestClient } from "@twin.org/api-core";
4
+ import { Coerce, Converter, Guards, Is, Urn } from "@twin.org/core";
5
+ import { UneceDocumentCodeList } from "@twin.org/standards-unece";
6
+ import { HeaderHelper, HeaderTypes } from "@twin.org/web";
7
7
  /**
8
8
  * Client for performing document management through to REST endpoints.
9
9
  */
10
- class DocumentManagementRestClient extends BaseRestClient {
10
+ export class DocumentManagementRestClient extends BaseRestClient {
11
11
  /**
12
12
  * Runtime name for the class.
13
13
  */
@@ -19,6 +19,13 @@ class DocumentManagementRestClient extends BaseRestClient {
19
19
  constructor(config) {
20
20
  super(DocumentManagementRestClient.CLASS_NAME, config, "document-management");
21
21
  }
22
+ /**
23
+ * Returns the class name of the component.
24
+ * @returns The class name of the component.
25
+ */
26
+ className() {
27
+ return DocumentManagementRestClient.CLASS_NAME;
28
+ }
22
29
  /**
23
30
  * Store a document as an auditable item graph vertex and add its content to blob storage.
24
31
  * If the document id already exists and the blob data is different a new revision will be created.
@@ -37,7 +44,7 @@ class DocumentManagementRestClient extends BaseRestClient {
37
44
  */
38
45
  async create(documentId, documentIdFormat, documentCode, blob, annotationObject, auditableItemGraphEdges, options) {
39
46
  Guards.stringValue(DocumentManagementRestClient.CLASS_NAME, "documentId", documentId);
40
- Guards.arrayOneOf(DocumentManagementRestClient.CLASS_NAME, "documentCode", documentCode, Object.values(UneceDocumentCodes));
47
+ Guards.arrayOneOf(DocumentManagementRestClient.CLASS_NAME, "documentCode", documentCode, Object.values(UneceDocumentCodeList));
41
48
  Guards.uint8Array(DocumentManagementRestClient.CLASS_NAME, "blob", blob);
42
49
  const response = await this.fetch("/", "POST", {
43
50
  body: {
@@ -98,17 +105,21 @@ class DocumentManagementRestClient extends BaseRestClient {
98
105
  auditableItemGraphDocumentId
99
106
  },
100
107
  query: {
101
- includeBlobStorageMetadata: options?.includeBlobStorageMetadata,
102
- includeBlobStorageData: options?.includeBlobStorageData,
103
- includeAttestation: options?.includeAttestation,
104
- includeRemoved: options?.includeRemoved,
108
+ includeBlobStorageMetadata: Coerce.string(options?.includeBlobStorageMetadata),
109
+ includeBlobStorageData: Coerce.string(options?.includeBlobStorageData),
110
+ includeAttestation: Coerce.string(options?.includeAttestation),
111
+ includeRemoved: Coerce.string(options?.includeRemoved),
105
112
  extractRuleGroupId: options?.extractRuleGroupId,
106
113
  extractMimeType: options?.extractMimeType,
107
114
  cursor,
108
115
  limit: Coerce.string(limit)
109
116
  }
110
117
  });
111
- return response.body;
118
+ return {
119
+ entries: response.body,
120
+ cursor: HeaderHelper.extractLinkHeaderRelation(response.headers?.[HeaderTypes.Link], "next")
121
+ ?.urlQueryParams?.cursor
122
+ };
112
123
  }
113
124
  /**
114
125
  * Get a document revision using it's auditable item graph vertex id.
@@ -131,9 +142,9 @@ class DocumentManagementRestClient extends BaseRestClient {
131
142
  revision: revision.toString()
132
143
  },
133
144
  query: {
134
- includeBlobStorageMetadata: options?.includeBlobStorageMetadata,
135
- includeBlobStorageData: options?.includeBlobStorageData,
136
- includeAttestation: options?.includeAttestation,
145
+ includeBlobStorageMetadata: Coerce.string(options?.includeBlobStorageMetadata),
146
+ includeBlobStorageData: Coerce.string(options?.includeBlobStorageData),
147
+ includeAttestation: Coerce.string(options?.includeAttestation),
137
148
  extractRuleGroupId: options?.extractRuleGroupId,
138
149
  extractMimeType: options?.extractMimeType
139
150
  }
@@ -173,8 +184,11 @@ class DocumentManagementRestClient extends BaseRestClient {
173
184
  limit: Coerce.string(limit)
174
185
  }
175
186
  });
176
- return response.body;
187
+ return {
188
+ entries: response.body,
189
+ cursor: HeaderHelper.extractLinkHeaderRelation(response.headers?.[HeaderTypes.Link], "next")
190
+ ?.urlQueryParams?.cursor
191
+ };
177
192
  }
178
193
  }
179
-
180
- export { DocumentManagementRestClient };
194
+ //# sourceMappingURL=documentManagementRestClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documentManagementRestClient.js","sourceRoot":"","sources":["../../src/documentManagementRestClient.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAOpD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAiBpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE1D;;GAEG;AACH,MAAM,OAAO,4BACZ,SAAQ,cAAc;IAGtB;;OAEG;IACI,MAAM,CAAU,UAAU,kCAAkD;IAEnF;;;OAGG;IACH,YAAY,MAA6B;QACxC,KAAK,CAAC,4BAA4B,CAAC,UAAU,EAAE,MAAM,EAAE,qBAAqB,CAAC,CAAC;IAC/E,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,4BAA4B,CAAC,UAAU,CAAC;IAChD,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACI,KAAK,CAAC,MAAM,CAClB,UAAkB,EAClB,gBAAoC,EACpC,YAAmC,EACnC,IAAgB,EAChB,gBAAoC,EACpC,uBAIG,EACH,OAIC;QAED,MAAM,CAAC,WAAW,CAAC,4BAA4B,CAAC,UAAU,gBAAsB,UAAU,CAAC,CAAC;QAC5F,MAAM,CAAC,UAAU,CAChB,4BAA4B,CAAC,UAAU,kBAEvC,YAAY,EACZ,MAAM,CAAC,MAAM,CAAC,qBAAqB,CA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AAI,CAAC,EAAE,MAAM,CAAC;gBAC3F,EAAE,cAAc,EAAE,MAAM;SACzB,CAAC;IACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseRestClient } from \"@twin.org/api-core\";\nimport type {\n\tIBaseRestClientConfig,\n\tICreatedResponse,\n\tINoContentResponse\n} from \"@twin.org/api-models\";\nimport type { IAuditableItemGraphVertexList } from \"@twin.org/auditable-item-graph-models\";\nimport { Coerce, Converter, Guards, Is, Urn } from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport type {\n\tIDocument,\n\tIDocumentList,\n\tIDocumentManagementComponent,\n\tIDocumentManagementCreateRequest,\n\tIDocumentManagementGetRequest,\n\tIDocumentManagementGetResponse,\n\tIDocumentManagementGetRevisionRequest,\n\tIDocumentManagementGetRevisionResponse,\n\tIDocumentManagementQueryRequest,\n\tIDocumentManagementQueryResponse,\n\tIDocumentManagementRemoveRequest,\n\tIDocumentManagementUpdateRequest\n} from \"@twin.org/document-management-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { UneceDocumentCodeList } from \"@twin.org/standards-unece\";\nimport { HeaderHelper, HeaderTypes } from \"@twin.org/web\";\n\n/**\n * Client for performing document management through to REST endpoints.\n */\nexport class DocumentManagementRestClient\n\textends BaseRestClient\n\timplements IDocumentManagementComponent\n{\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<DocumentManagementRestClient>();\n\n\t/**\n\t * Create a new instance of DocumentManagementRestClient.\n\t * @param config The configuration for the client.\n\t */\n\tconstructor(config: IBaseRestClientConfig) {\n\t\tsuper(DocumentManagementRestClient.CLASS_NAME, config, \"document-management\");\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn DocumentManagementRestClient.CLASS_NAME;\n\t}\n\n\t/**\n\t * Store a document as an auditable item graph vertex and add its content to blob storage.\n\t * If the document id already exists and the blob data is different a new revision will be created.\n\t * For any other changes the current revision will be updated.\n\t * @param documentId The document id to create.\n\t * @param documentIdFormat The format of the document identifier.\n\t * @param documentCode The code for the document type.\n\t * @param blob The data to create the document with.\n\t * @param annotationObject Additional information to associate with the document.\n\t * @param auditableItemGraphEdges The auditable item graph vertices to connect the document to.\n\t * @param options Additional options for the set operation.\n\t * @param options.createAttestation Flag to create an attestation for the document, defaults to false.\n\t * @param options.addAlias Flag to add the document id as an alias to the aig vertex, defaults to true.\n\t * @param options.aliasAnnotationObject Annotation object for the alias.\n\t * @returns The auditable item graph vertex created for the document including its revision.\n\t */\n\tpublic async create(\n\t\tdocumentId: string,\n\t\tdocumentIdFormat: string | undefined,\n\t\tdocumentCode: UneceDocumentCodeList,\n\t\tblob: Uint8Array,\n\t\tannotationObject?: IJsonLdNodeObject,\n\t\tauditableItemGraphEdges?: {\n\t\t\ttargetId: string;\n\t\t\taddAlias?: boolean;\n\t\t\taliasAnnotationObject?: IJsonLdNodeObject;\n\t\t}[],\n\t\toptions?: {\n\t\t\tcreateAttestation?: boolean;\n\t\t\taddAlias?: boolean;\n\t\t\taliasAnnotationObject?: IJsonLdNodeObject;\n\t\t}\n\t): Promise<string> {\n\t\tGuards.stringValue(DocumentManagementRestClient.CLASS_NAME, nameof(documentId), documentId);\n\t\tGuards.arrayOneOf(\n\t\t\tDocumentManagementRestClient.CLASS_NAME,\n\t\t\tnameof(documentCode),\n\t\t\tdocumentCode,\n\t\t\tObject.values(UneceDocumentCodeList)\n\t\t);\n\t\tGuards.uint8Array(DocumentManagementRestClient.CLASS_NAME, nameof(blob), blob);\n\n\t\tconst response = await this.fetch<IDocumentManagementCreateRequest, ICreatedResponse>(\n\t\t\t\"/\",\n\t\t\t\"POST\",\n\t\t\t{\n\t\t\t\tbody: {\n\t\t\t\t\tdocumentId,\n\t\t\t\t\tdocumentIdFormat,\n\t\t\t\t\tdocumentCode,\n\t\t\t\t\tblob: Converter.bytesToBase64(blob),\n\t\t\t\t\tannotationObject,\n\t\t\t\t\tauditableItemGraphEdges,\n\t\t\t\t\tcreateAttestation: options?.createAttestation,\n\t\t\t\t\taddAlias: options?.addAlias,\n\t\t\t\t\taliasAnnotationObject: options?.aliasAnnotationObject\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn response.headers.location;\n\t}\n\n\t/**\n\t * Update a document as an auditable item graph vertex and add its content to blob storage.\n\t * If the blob data is different a new revision will be created.\n\t * For any other changes the current revision will be updated.\n\t * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.\n\t * @param blob The data to update the document with.\n\t * @param annotationObject Additional information to associate with the document.\n\t * @param auditableItemGraphEdges The auditable item graph vertices to connect the document to, if undefined retains current connections.\n\t * @returns Nothing.\n\t */\n\tpublic async update(\n\t\tauditableItemGraphDocumentId: string,\n\t\tblob?: Uint8Array,\n\t\tannotationObject?: IJsonLdNodeObject,\n\t\tauditableItemGraphEdges?: {\n\t\t\ttargetId: string;\n\t\t\taddAlias?: boolean;\n\t\t\taliasAnnotationObject?: IJsonLdNodeObject;\n\t\t}[]\n\t): Promise<void> {\n\t\tUrn.guard(\n\t\t\tDocumentManagementRestClient.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\n\t\tawait this.fetch<IDocumentManagementUpdateRequest, INoContentResponse>(\n\t\t\t\"/:auditableItemGraphDocumentId\",\n\t\t\t\"PUT\",\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tauditableItemGraphDocumentId\n\t\t\t\t},\n\t\t\t\tbody: {\n\t\t\t\t\tblob: Is.uint8Array(blob) ? Converter.bytesToBase64(blob) : undefined,\n\t\t\t\t\tannotationObject,\n\t\t\t\t\tauditableItemGraphEdges\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Get a document using it's auditable item graph vertex id and optional revision.\n\t * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.\n\t * @param options Additional options for the get operation.\n\t * @param options.includeBlobStorageMetadata Flag to include the blob storage metadata for the document, defaults to false.\n\t * @param options.includeBlobStorageData Flag to include the blob storage data for the document, defaults to false.\n\t * @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.\n\t * @param options.includeRemoved Flag to include deleted documents, defaults to false.\n\t * @param options.extractRuleGroupId If provided will extract data from the document using the specified rule group id.\n\t * @param options.extractMimeType By default extraction will auto detect the mime type of the document, this can be used to override the detection.\n\t * @param cursor The cursor to get the next chunk of revisions.\n\t * @param limit The limit of items to return, defaults to 1 so only most recent is returned.\n\t * @returns The documents and revisions if requested, ordered by revision descending, cursor is set if there are more document revisions.\n\t */\n\tpublic async get(\n\t\tauditableItemGraphDocumentId: string,\n\t\toptions?: {\n\t\t\tincludeBlobStorageMetadata?: boolean;\n\t\t\tincludeBlobStorageData?: boolean;\n\t\t\tincludeAttestation?: boolean;\n\t\t\tincludeRemoved?: boolean;\n\t\t\textractRuleGroupId?: string;\n\t\t\textractMimeType?: string;\n\t\t},\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\tentries: IDocumentList;\n\t\tcursor?: string;\n\t}> {\n\t\tUrn.guard(\n\t\t\tDocumentManagementRestClient.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\n\t\tconst response = await this.fetch<\n\t\t\tIDocumentManagementGetRequest,\n\t\t\tIDocumentManagementGetResponse\n\t\t>(\"/:auditableItemGraphDocumentId\", \"GET\", {\n\t\t\tpathParams: {\n\t\t\t\tauditableItemGraphDocumentId\n\t\t\t},\n\t\t\tquery: {\n\t\t\t\tincludeBlobStorageMetadata: Coerce.string(options?.includeBlobStorageMetadata),\n\t\t\t\tincludeBlobStorageData: Coerce.string(options?.includeBlobStorageData),\n\t\t\t\tincludeAttestation: Coerce.string(options?.includeAttestation),\n\t\t\t\tincludeRemoved: Coerce.string(options?.includeRemoved),\n\t\t\t\textractRuleGroupId: options?.extractRuleGroupId,\n\t\t\t\textractMimeType: options?.extractMimeType,\n\t\t\t\tcursor,\n\t\t\t\tlimit: Coerce.string(limit)\n\t\t\t}\n\t\t});\n\n\t\treturn {\n\t\t\tentries: response.body,\n\t\t\tcursor: HeaderHelper.extractLinkHeaderRelation(response.headers?.[HeaderTypes.Link], \"next\")\n\t\t\t\t?.urlQueryParams?.cursor\n\t\t};\n\t}\n\n\t/**\n\t * Get a document revision using it's auditable item graph vertex id.\n\t * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.\n\t * @param revision The revision id for the document.\n\t * @param options Additional options for the get operation.\n\t * @param options.includeBlobStorageMetadata Flag to include the blob storage metadata for the document, defaults to false.\n\t * @param options.includeBlobStorageData Flag to include the blob storage data for the document, defaults to false.\n\t * @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.\n\t * @param options.extractRuleGroupId If provided will extract data from the document using the specified rule group id.\n\t * @param options.extractMimeType By default extraction will auto detect the mime type of the document, this can be used to override the detection.\n\t * @returns The documents and revisions if requested, ordered by revision descending, cursor is set if there are more document revisions.\n\t */\n\tpublic async getRevision(\n\t\tauditableItemGraphDocumentId: string,\n\t\trevision: number,\n\t\toptions?: {\n\t\t\tincludeBlobStorageMetadata?: boolean;\n\t\t\tincludeBlobStorageData?: boolean;\n\t\t\tincludeAttestation?: boolean;\n\t\t\textractRuleGroupId?: string;\n\t\t\textractMimeType?: string;\n\t\t}\n\t): Promise<IDocument> {\n\t\tUrn.guard(\n\t\t\tDocumentManagementRestClient.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\t\tGuards.integer(DocumentManagementRestClient.CLASS_NAME, nameof(revision), revision);\n\n\t\tconst response = await this.fetch<\n\t\t\tIDocumentManagementGetRevisionRequest,\n\t\t\tIDocumentManagementGetRevisionResponse\n\t\t>(\"/:auditableItemGraphDocumentId/:revision\", \"GET\", {\n\t\t\tpathParams: {\n\t\t\t\tauditableItemGraphDocumentId,\n\t\t\t\trevision: revision.toString()\n\t\t\t},\n\t\t\tquery: {\n\t\t\t\tincludeBlobStorageMetadata: Coerce.string(options?.includeBlobStorageMetadata),\n\t\t\t\tincludeBlobStorageData: Coerce.string(options?.includeBlobStorageData),\n\t\t\t\tincludeAttestation: Coerce.string(options?.includeAttestation),\n\t\t\t\textractRuleGroupId: options?.extractRuleGroupId,\n\t\t\t\textractMimeType: options?.extractMimeType\n\t\t\t}\n\t\t});\n\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Remove an auditable item graph vertex using it's id.\n\t * The document dateDeleted will be set, but can still be queried with the includeRemoved flag.\n\t * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.\n\t * @param revision The revision of the document to remove.\n\t * @returns Nothing.\n\t */\n\tpublic async removeRevision(\n\t\tauditableItemGraphDocumentId: string,\n\t\trevision: number\n\t): Promise<void> {\n\t\tUrn.guard(\n\t\t\tDocumentManagementRestClient.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\t\tGuards.number(DocumentManagementRestClient.CLASS_NAME, nameof(revision), revision);\n\n\t\tawait this.fetch<IDocumentManagementRemoveRequest, INoContentResponse>(\n\t\t\t\"/:auditableItemGraphDocumentId/:revision\",\n\t\t\t\"DELETE\",\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tauditableItemGraphDocumentId,\n\t\t\t\t\trevision: revision.toString()\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Find all the document with a specific id.\n\t * @param documentId The document id to find in the graph.\n\t * @param cursor The cursor to get the next chunk of documents.\n\t * @param limit The limit to get the next chunk of documents.\n\t * @returns The graph vertices that contain documents referencing the specified document id.\n\t */\n\tpublic async query(\n\t\tdocumentId: string,\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\tentries: IAuditableItemGraphVertexList;\n\t\tcursor?: string;\n\t}> {\n\t\tGuards.stringValue(DocumentManagementRestClient.CLASS_NAME, nameof(documentId), documentId);\n\n\t\tconst response = await this.fetch<\n\t\t\tIDocumentManagementQueryRequest,\n\t\t\tIDocumentManagementQueryResponse\n\t\t>(\"/\", \"GET\", {\n\t\t\tquery: {\n\t\t\t\tdocumentId,\n\t\t\t\tcursor,\n\t\t\t\tlimit: Coerce.string(limit)\n\t\t\t}\n\t\t});\n\n\t\treturn {\n\t\t\tentries: response.body,\n\t\t\tcursor: HeaderHelper.extractLinkHeaderRelation(response.headers?.[HeaderTypes.Link], \"next\")\n\t\t\t\t?.urlQueryParams?.cursor\n\t\t};\n\t}\n}\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export * from "./documentManagementRestClient.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,mCAAmC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./documentManagementRestClient.js\";\n"]}
@@ -3,7 +3,7 @@ import type { IBaseRestClientConfig } from "@twin.org/api-models";
3
3
  import type { IAuditableItemGraphVertexList } from "@twin.org/auditable-item-graph-models";
4
4
  import type { IJsonLdNodeObject } from "@twin.org/data-json-ld";
5
5
  import type { IDocument, IDocumentList, IDocumentManagementComponent } from "@twin.org/document-management-models";
6
- import { UneceDocumentCodes } from "@twin.org/standards-unece";
6
+ import { UneceDocumentCodeList } from "@twin.org/standards-unece";
7
7
  /**
8
8
  * Client for performing document management through to REST endpoints.
9
9
  */
@@ -17,6 +17,11 @@ export declare class DocumentManagementRestClient extends BaseRestClient impleme
17
17
  * @param config The configuration for the client.
18
18
  */
19
19
  constructor(config: IBaseRestClientConfig);
20
+ /**
21
+ * Returns the class name of the component.
22
+ * @returns The class name of the component.
23
+ */
24
+ className(): string;
20
25
  /**
21
26
  * Store a document as an auditable item graph vertex and add its content to blob storage.
22
27
  * If the document id already exists and the blob data is different a new revision will be created.
@@ -33,7 +38,7 @@ export declare class DocumentManagementRestClient extends BaseRestClient impleme
33
38
  * @param options.aliasAnnotationObject Annotation object for the alias.
34
39
  * @returns The auditable item graph vertex created for the document including its revision.
35
40
  */
36
- create(documentId: string, documentIdFormat: string | undefined, documentCode: UneceDocumentCodes, blob: Uint8Array, annotationObject?: IJsonLdNodeObject, auditableItemGraphEdges?: {
41
+ create(documentId: string, documentIdFormat: string | undefined, documentCode: UneceDocumentCodeList, blob: Uint8Array, annotationObject?: IJsonLdNodeObject, auditableItemGraphEdges?: {
37
42
  targetId: string;
38
43
  addAlias?: boolean;
39
44
  aliasAnnotationObject?: IJsonLdNodeObject;
@@ -78,7 +83,10 @@ export declare class DocumentManagementRestClient extends BaseRestClient impleme
78
83
  includeRemoved?: boolean;
79
84
  extractRuleGroupId?: string;
80
85
  extractMimeType?: string;
81
- }, cursor?: string, limit?: number): Promise<IDocumentList>;
86
+ }, cursor?: string, limit?: number): Promise<{
87
+ entries: IDocumentList;
88
+ cursor?: string;
89
+ }>;
82
90
  /**
83
91
  * Get a document revision using it's auditable item graph vertex id.
84
92
  * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.
@@ -113,5 +121,8 @@ export declare class DocumentManagementRestClient extends BaseRestClient impleme
113
121
  * @param limit The limit to get the next chunk of documents.
114
122
  * @returns The graph vertices that contain documents referencing the specified document id.
115
123
  */
116
- query(documentId: string, cursor?: string, limit?: number): Promise<IAuditableItemGraphVertexList>;
124
+ query(documentId: string, cursor?: string, limit?: number): Promise<{
125
+ entries: IAuditableItemGraphVertexList;
126
+ cursor?: string;
127
+ }>;
117
128
  }
@@ -1 +1 @@
1
- export * from "./documentManagementRestClient";
1
+ export * from "./documentManagementRestClient.js";
package/docs/changelog.md CHANGED
@@ -1,5 +1,158 @@
1
1
  # @twin.org/document-management-rest-client - Changelog
2
2
 
3
+ ## [0.0.3-next.10](https://github.com/twinfoundation/document-management/compare/document-management-rest-client-v0.0.3-next.9...document-management-rest-client-v0.0.3-next.10) (2026-02-11)
4
+
5
+
6
+ ### Miscellaneous Chores
7
+
8
+ * **document-management-rest-client:** Synchronize repo versions
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/document-management-models bumped from 0.0.3-next.9 to 0.0.3-next.10
16
+
17
+ ## [0.0.3-next.9](https://github.com/twinfoundation/document-management/compare/document-management-rest-client-v0.0.3-next.8...document-management-rest-client-v0.0.3-next.9) (2026-01-26)
18
+
19
+
20
+ ### Miscellaneous Chores
21
+
22
+ * **document-management-rest-client:** Synchronize repo versions
23
+
24
+
25
+ ### Dependencies
26
+
27
+ * The following workspace dependencies were updated
28
+ * dependencies
29
+ * @twin.org/document-management-models bumped from 0.0.3-next.8 to 0.0.3-next.9
30
+
31
+ ## [0.0.3-next.8](https://github.com/twinfoundation/document-management/compare/document-management-rest-client-v0.0.3-next.7...document-management-rest-client-v0.0.3-next.8) (2026-01-26)
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.3-next.7 to 0.0.3-next.8
44
+
45
+ ## [0.0.3-next.7](https://github.com/twinfoundation/document-management/compare/document-management-rest-client-v0.0.3-next.6...document-management-rest-client-v0.0.3-next.7) (2026-01-23)
46
+
47
+
48
+ ### Features
49
+
50
+ * replace nextItem property with Link header ([#34](https://github.com/twinfoundation/document-management/issues/34)) ([3f04c3f](https://github.com/twinfoundation/document-management/commit/3f04c3fb5c9ec0c56f213089a15cc247fbfbd59c))
51
+
52
+
53
+ ### Dependencies
54
+
55
+ * The following workspace dependencies were updated
56
+ * dependencies
57
+ * @twin.org/document-management-models bumped from 0.0.3-next.6 to 0.0.3-next.7
58
+
59
+ ## [0.0.3-next.6](https://github.com/twinfoundation/document-management/compare/document-management-rest-client-v0.0.3-next.5...document-management-rest-client-v0.0.3-next.6) (2026-01-22)
60
+
61
+
62
+ ### Miscellaneous Chores
63
+
64
+ * **document-management-rest-client:** Synchronize repo versions
65
+
66
+
67
+ ### Dependencies
68
+
69
+ * The following workspace dependencies were updated
70
+ * dependencies
71
+ * @twin.org/document-management-models bumped from 0.0.3-next.5 to 0.0.3-next.6
72
+
73
+ ## [0.0.3-next.5](https://github.com/twinfoundation/document-management/compare/document-management-rest-client-v0.0.3-next.4...document-management-rest-client-v0.0.3-next.5) (2026-01-14)
74
+
75
+
76
+ ### Miscellaneous Chores
77
+
78
+ * **document-management-rest-client:** Synchronize repo versions
79
+
80
+
81
+ ### Dependencies
82
+
83
+ * The following workspace dependencies were updated
84
+ * dependencies
85
+ * @twin.org/document-management-models bumped from 0.0.3-next.4 to 0.0.3-next.5
86
+
87
+ ## [0.0.3-next.4](https://github.com/twinfoundation/document-management/compare/document-management-rest-client-v0.0.3-next.3...document-management-rest-client-v0.0.3-next.4) (2026-01-06)
88
+
89
+
90
+ ### Features
91
+
92
+ * update unece dependencies ([a27548c](https://github.com/twinfoundation/document-management/commit/a27548cdebbe1d9577fc8341166538c2f07348a3))
93
+
94
+
95
+ ### Dependencies
96
+
97
+ * The following workspace dependencies were updated
98
+ * dependencies
99
+ * @twin.org/document-management-models bumped from 0.0.3-next.3 to 0.0.3-next.4
100
+
101
+ ## [0.0.3-next.3](https://github.com/twinfoundation/document-management/compare/document-management-rest-client-v0.0.3-next.2...document-management-rest-client-v0.0.3-next.3) (2025-12-03)
102
+
103
+
104
+ ### Features
105
+
106
+ * use updated unece types ([c141a89](https://github.com/twinfoundation/document-management/commit/c141a895138cb45fa0b1e95c42f56e31708c846c))
107
+
108
+
109
+ ### Dependencies
110
+
111
+ * The following workspace dependencies were updated
112
+ * dependencies
113
+ * @twin.org/document-management-models bumped from 0.0.3-next.2 to 0.0.3-next.3
114
+
115
+ ## [0.0.3-next.2](https://github.com/twinfoundation/document-management/compare/document-management-rest-client-v0.0.3-next.1...document-management-rest-client-v0.0.3-next.2) (2025-11-28)
116
+
117
+
118
+ ### Features
119
+
120
+ * update background task service ([5c380dc](https://github.com/twinfoundation/document-management/commit/5c380dca3114254201768f184f9486828501ff66))
121
+
122
+
123
+ ### Dependencies
124
+
125
+ * The following workspace dependencies were updated
126
+ * dependencies
127
+ * @twin.org/document-management-models bumped from 0.0.3-next.1 to 0.0.3-next.2
128
+
129
+ ## [0.0.3-next.1](https://github.com/twinfoundation/document-management/compare/document-management-rest-client-v0.0.3-next.0...document-management-rest-client-v0.0.3-next.1) (2025-11-12)
130
+
131
+
132
+ ### Features
133
+
134
+ * add context id features ([#24](https://github.com/twinfoundation/document-management/issues/24)) ([83f65f1](https://github.com/twinfoundation/document-management/commit/83f65f15e55f2293f5ca0d9d1e4679ba67c4ec8d))
135
+ * add validate-locales ([b6b6f9e](https://github.com/twinfoundation/document-management/commit/b6b6f9e9d66c17af3d030247ca168ac0b5844bdc))
136
+ * document get can perform extraction ([#6](https://github.com/twinfoundation/document-management/issues/6)) ([5ce6d37](https://github.com/twinfoundation/document-management/commit/5ce6d37432ad271ca5783f422846f4be98ec2215))
137
+ * eslint migration to flat config ([98635aa](https://github.com/twinfoundation/document-management/commit/98635aa24ebafba265e989e461fe98104f683191))
138
+ * get document revision ([080eddc](https://github.com/twinfoundation/document-management/commit/080eddcc024c622dda6bb36f60f5fa80a86cf5bb))
139
+ * store document as a vertex ([#2](https://github.com/twinfoundation/document-management/issues/2)) ([7febedc](https://github.com/twinfoundation/document-management/commit/7febedc3fb31de9c19565d6326341046834f2c74))
140
+ * update dependencies ([f9d8641](https://github.com/twinfoundation/document-management/commit/f9d86417dba24027699225ec7473296e361dcb00))
141
+ * update framework core ([f991a59](https://github.com/twinfoundation/document-management/commit/f991a59d25ec228bcdd7a5b6bd55578985b55a84))
142
+ * use targetId in AIG for edges ([82dec81](https://github.com/twinfoundation/document-management/commit/82dec8190d8b523b350ef133bdcf648cab1023b0))
143
+
144
+
145
+ ### Bug Fixes
146
+
147
+ * 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))
148
+
149
+
150
+ ### Dependencies
151
+
152
+ * The following workspace dependencies were updated
153
+ * dependencies
154
+ * @twin.org/document-management-models bumped from 0.0.3-next.0 to 0.0.3-next.1
155
+
3
156
  ## [0.0.2-next.4](https://github.com/twinfoundation/document-management/compare/document-management-rest-client-v0.0.2-next.3...document-management-rest-client-v0.0.2-next.4) (2025-10-09)
4
157
 
5
158
 
@@ -44,6 +44,24 @@ Runtime name for the class.
44
44
 
45
45
  ## Methods
46
46
 
47
+ ### className()
48
+
49
+ > **className**(): `string`
50
+
51
+ Returns the class name of the component.
52
+
53
+ #### Returns
54
+
55
+ `string`
56
+
57
+ The class name of the component.
58
+
59
+ #### Implementation of
60
+
61
+ `IDocumentManagementComponent.className`
62
+
63
+ ***
64
+
47
65
  ### create()
48
66
 
49
67
  > **create**(`documentId`, `documentIdFormat`, `documentCode`, `blob`, `annotationObject?`, `auditableItemGraphEdges?`, `options?`): `Promise`\<`string`\>
@@ -64,11 +82,11 @@ The document id to create.
64
82
 
65
83
  The format of the document identifier.
66
84
 
67
- `undefined` | `string`
85
+ `string` | `undefined`
68
86
 
69
87
  ##### documentCode
70
88
 
71
- `string`
89
+ `UneceDocumentCodeList`
72
90
 
73
91
  The code for the document type.
74
92
 
@@ -172,7 +190,7 @@ Nothing.
172
190
 
173
191
  ### get()
174
192
 
175
- > **get**(`auditableItemGraphDocumentId`, `options?`, `cursor?`, `limit?`): `Promise`\<`IDocumentList`\>
193
+ > **get**(`auditableItemGraphDocumentId`, `options?`, `cursor?`, `limit?`): `Promise`\<\{ `entries`: `IDocumentList`; `cursor?`: `string`; \}\>
176
194
 
177
195
  Get a document using it's auditable item graph vertex id and optional revision.
178
196
 
@@ -238,7 +256,7 @@ The limit of items to return, defaults to 1 so only most recent is returned.
238
256
 
239
257
  #### Returns
240
258
 
241
- `Promise`\<`IDocumentList`\>
259
+ `Promise`\<\{ `entries`: `IDocumentList`; `cursor?`: `string`; \}\>
242
260
 
243
261
  The documents and revisions if requested, ordered by revision descending, cursor is set if there are more document revisions.
244
262
 
@@ -349,7 +367,7 @@ Nothing.
349
367
 
350
368
  ### query()
351
369
 
352
- > **query**(`documentId`, `cursor?`, `limit?`): `Promise`\<`IAuditableItemGraphVertexList`\>
370
+ > **query**(`documentId`, `cursor?`, `limit?`): `Promise`\<\{ `entries`: `IAuditableItemGraphVertexList`; `cursor?`: `string`; \}\>
353
371
 
354
372
  Find all the document with a specific id.
355
373
 
@@ -375,7 +393,7 @@ The limit to get the next chunk of documents.
375
393
 
376
394
  #### Returns
377
395
 
378
- `Promise`\<`IAuditableItemGraphVertexList`\>
396
+ `Promise`\<\{ `entries`: `IAuditableItemGraphVertexList`; `cursor?`: `string`; \}\>
379
397
 
380
398
  The graph vertices that contain documents referencing the specified document id.
381
399
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/document-management-rest-client",
3
- "version": "0.0.2-next.4",
3
+ "version": "0.0.3-next.10",
4
4
  "description": "Document management contract implementation which can connect to REST endpoints",
5
5
  "repository": {
6
6
  "type": "git",
@@ -19,26 +19,24 @@
19
19
  "@twin.org/auditable-item-graph-models": "next",
20
20
  "@twin.org/core": "next",
21
21
  "@twin.org/data-json-ld": "next",
22
- "@twin.org/document-management-models": "0.0.2-next.4",
22
+ "@twin.org/document-management-models": "0.0.3-next.10",
23
23
  "@twin.org/entity": "next",
24
24
  "@twin.org/nameof": "next",
25
25
  "@twin.org/standards-unece": "next",
26
26
  "@twin.org/web": "next"
27
27
  },
28
- "main": "./dist/cjs/index.cjs",
29
- "module": "./dist/esm/index.mjs",
28
+ "main": "./dist/es/index.js",
30
29
  "types": "./dist/types/index.d.ts",
31
30
  "exports": {
32
31
  ".": {
33
32
  "types": "./dist/types/index.d.ts",
34
- "require": "./dist/cjs/index.cjs",
35
- "import": "./dist/esm/index.mjs"
33
+ "import": "./dist/es/index.js",
34
+ "default": "./dist/es/index.js"
36
35
  },
37
36
  "./locales/*.json": "./locales/*.json"
38
37
  },
39
38
  "files": [
40
- "dist/cjs",
41
- "dist/esm",
39
+ "dist/es",
42
40
  "dist/types",
43
41
  "locales",
44
42
  "docs"
@@ -1,182 +0,0 @@
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 DocumentManagementRestClient extends apiCore.BaseRestClient {
13
- /**
14
- * Runtime name for the class.
15
- */
16
- static CLASS_NAME = "DocumentManagementRestClient";
17
- /**
18
- * Create a new instance of DocumentManagementRestClient.
19
- * @param config The configuration for the client.
20
- */
21
- constructor(config) {
22
- super(DocumentManagementRestClient.CLASS_NAME, config, "document-management");
23
- }
24
- /**
25
- * Store a document as an auditable item graph vertex and add its content to blob storage.
26
- * If the document id already exists and the blob data is different a new revision will be created.
27
- * For any other changes the current revision will be updated.
28
- * @param documentId The document id to create.
29
- * @param documentIdFormat The format of the document identifier.
30
- * @param documentCode The code for the document type.
31
- * @param blob The data to create the document with.
32
- * @param annotationObject Additional information to associate with the document.
33
- * @param auditableItemGraphEdges The auditable item graph vertices to connect the document to.
34
- * @param options Additional options for the set operation.
35
- * @param options.createAttestation Flag to create an attestation for the document, defaults to false.
36
- * @param options.addAlias Flag to add the document id as an alias to the aig vertex, defaults to true.
37
- * @param options.aliasAnnotationObject Annotation object for the alias.
38
- * @returns The auditable item graph vertex created for the document including its revision.
39
- */
40
- async create(documentId, documentIdFormat, documentCode, blob, annotationObject, auditableItemGraphEdges, options) {
41
- core.Guards.stringValue(DocumentManagementRestClient.CLASS_NAME, "documentId", documentId);
42
- core.Guards.arrayOneOf(DocumentManagementRestClient.CLASS_NAME, "documentCode", documentCode, Object.values(standardsUnece.UneceDocumentCodes));
43
- core.Guards.uint8Array(DocumentManagementRestClient.CLASS_NAME, "blob", blob);
44
- const response = await this.fetch("/", "POST", {
45
- body: {
46
- documentId,
47
- documentIdFormat,
48
- documentCode,
49
- blob: core.Converter.bytesToBase64(blob),
50
- annotationObject,
51
- auditableItemGraphEdges,
52
- createAttestation: options?.createAttestation,
53
- addAlias: options?.addAlias,
54
- aliasAnnotationObject: options?.aliasAnnotationObject
55
- }
56
- });
57
- return response.headers.location;
58
- }
59
- /**
60
- * Update a document as an auditable item graph vertex and add its content to blob storage.
61
- * If the blob data is different a new revision will be created.
62
- * For any other changes the current revision will be updated.
63
- * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.
64
- * @param blob The data to update the document with.
65
- * @param annotationObject Additional information to associate with the document.
66
- * @param auditableItemGraphEdges The auditable item graph vertices to connect the document to, if undefined retains current connections.
67
- * @returns Nothing.
68
- */
69
- async update(auditableItemGraphDocumentId, blob, annotationObject, auditableItemGraphEdges) {
70
- core.Urn.guard(DocumentManagementRestClient.CLASS_NAME, "auditableItemGraphDocumentId", auditableItemGraphDocumentId);
71
- await this.fetch("/:auditableItemGraphDocumentId", "PUT", {
72
- pathParams: {
73
- auditableItemGraphDocumentId
74
- },
75
- body: {
76
- blob: core.Is.uint8Array(blob) ? core.Converter.bytesToBase64(blob) : undefined,
77
- annotationObject,
78
- auditableItemGraphEdges
79
- }
80
- });
81
- }
82
- /**
83
- * Get a document using it's auditable item graph vertex id and optional revision.
84
- * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.
85
- * @param options Additional options for the get operation.
86
- * @param options.includeBlobStorageMetadata Flag to include the blob storage metadata for the document, defaults to false.
87
- * @param options.includeBlobStorageData Flag to include the blob storage data for the document, defaults to false.
88
- * @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.
89
- * @param options.includeRemoved Flag to include deleted documents, defaults to false.
90
- * @param options.extractRuleGroupId If provided will extract data from the document using the specified rule group id.
91
- * @param options.extractMimeType By default extraction will auto detect the mime type of the document, this can be used to override the detection.
92
- * @param cursor The cursor to get the next chunk of revisions.
93
- * @param limit The limit of items to return, defaults to 1 so only most recent is returned.
94
- * @returns The documents and revisions if requested, ordered by revision descending, cursor is set if there are more document revisions.
95
- */
96
- async get(auditableItemGraphDocumentId, options, cursor, limit) {
97
- core.Urn.guard(DocumentManagementRestClient.CLASS_NAME, "auditableItemGraphDocumentId", auditableItemGraphDocumentId);
98
- const response = await this.fetch("/:auditableItemGraphDocumentId", "GET", {
99
- pathParams: {
100
- auditableItemGraphDocumentId
101
- },
102
- query: {
103
- includeBlobStorageMetadata: options?.includeBlobStorageMetadata,
104
- includeBlobStorageData: options?.includeBlobStorageData,
105
- includeAttestation: options?.includeAttestation,
106
- includeRemoved: options?.includeRemoved,
107
- extractRuleGroupId: options?.extractRuleGroupId,
108
- extractMimeType: options?.extractMimeType,
109
- cursor,
110
- limit: core.Coerce.string(limit)
111
- }
112
- });
113
- return response.body;
114
- }
115
- /**
116
- * Get a document revision using it's auditable item graph vertex id.
117
- * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.
118
- * @param revision The revision id for the document.
119
- * @param options Additional options for the get operation.
120
- * @param options.includeBlobStorageMetadata Flag to include the blob storage metadata for the document, defaults to false.
121
- * @param options.includeBlobStorageData Flag to include the blob storage data for the document, defaults to false.
122
- * @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.
123
- * @param options.extractRuleGroupId If provided will extract data from the document using the specified rule group id.
124
- * @param options.extractMimeType By default extraction will auto detect the mime type of the document, this can be used to override the detection.
125
- * @returns The documents and revisions if requested, ordered by revision descending, cursor is set if there are more document revisions.
126
- */
127
- async getRevision(auditableItemGraphDocumentId, revision, options) {
128
- core.Urn.guard(DocumentManagementRestClient.CLASS_NAME, "auditableItemGraphDocumentId", auditableItemGraphDocumentId);
129
- core.Guards.integer(DocumentManagementRestClient.CLASS_NAME, "revision", revision);
130
- const response = await this.fetch("/:auditableItemGraphDocumentId/:revision", "GET", {
131
- pathParams: {
132
- auditableItemGraphDocumentId,
133
- revision: revision.toString()
134
- },
135
- query: {
136
- includeBlobStorageMetadata: options?.includeBlobStorageMetadata,
137
- includeBlobStorageData: options?.includeBlobStorageData,
138
- includeAttestation: options?.includeAttestation,
139
- extractRuleGroupId: options?.extractRuleGroupId,
140
- extractMimeType: options?.extractMimeType
141
- }
142
- });
143
- return response.body;
144
- }
145
- /**
146
- * Remove an auditable item graph vertex using it's id.
147
- * The document dateDeleted will be set, but can still be queried with the includeRemoved flag.
148
- * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.
149
- * @param revision The revision of the document to remove.
150
- * @returns Nothing.
151
- */
152
- async removeRevision(auditableItemGraphDocumentId, revision) {
153
- core.Urn.guard(DocumentManagementRestClient.CLASS_NAME, "auditableItemGraphDocumentId", auditableItemGraphDocumentId);
154
- core.Guards.number(DocumentManagementRestClient.CLASS_NAME, "revision", revision);
155
- await this.fetch("/:auditableItemGraphDocumentId/:revision", "DELETE", {
156
- pathParams: {
157
- auditableItemGraphDocumentId,
158
- revision: revision.toString()
159
- }
160
- });
161
- }
162
- /**
163
- * Find all the document with a specific id.
164
- * @param documentId The document id to find in the graph.
165
- * @param cursor The cursor to get the next chunk of documents.
166
- * @param limit The limit to get the next chunk of documents.
167
- * @returns The graph vertices that contain documents referencing the specified document id.
168
- */
169
- async query(documentId, cursor, limit) {
170
- core.Guards.stringValue(DocumentManagementRestClient.CLASS_NAME, "documentId", documentId);
171
- const response = await this.fetch("/", "GET", {
172
- query: {
173
- documentId,
174
- cursor,
175
- limit: core.Coerce.string(limit)
176
- }
177
- });
178
- return response.body;
179
- }
180
- }
181
-
182
- exports.DocumentManagementRestClient = DocumentManagementRestClient;