visualvault-api 1.1.0 → 1.2.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/README.md CHANGED
@@ -1,263 +1,265 @@
1
- # visualvault-api
2
-
3
- A Node.js client library that provides convenient access to the VisualVault REST API for server-side applications.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install visualvault-api
9
- ```
10
-
11
- ## Requirements
12
-
13
- - Node.js 20.0.0 or higher
14
-
15
- ## Quick Start
16
-
17
- ### Basic Authentication and Setup
18
-
19
- ```javascript
20
- const vvRestApi = require('visualvault-api');
21
-
22
- // Initialize authentication
23
- const auth = new vvRestApi.authorize();
24
-
25
- // Get authenticated client
26
- auth.getVaultApi(
27
- 'your-client-id',
28
- 'your-client-secret',
29
- 'username',
30
- 'password',
31
- 'your-audience',
32
- 'https://your-vault-url.com',
33
- 'customer-alias',
34
- 'database-alias'
35
- ).then(client => {
36
- console.log('Successfully authenticated!');
37
- // Use the client for API calls
38
- }).catch(error => {
39
- console.error('Authentication failed:', error);
40
- });
41
- ```
42
-
43
- ### JWT Authentication
44
-
45
- If you already have a JWT token:
46
-
47
- ```javascript
48
- const auth = new vvRestApi.authorize();
49
-
50
- auth.getVaultApiFromJwt(
51
- 'your-jwt-token',
52
- 'https://your-vault-url.com',
53
- 'customer-alias',
54
- 'database-alias',
55
- new Date('2024-12-31') // expiration date
56
- ).then(client => {
57
- console.log('JWT authentication successful!');
58
- }).catch(error => {
59
- console.error('JWT authentication failed:', error);
60
- });
61
- ```
62
-
63
- ## API Usage Examples
64
-
65
- ### Working with Documents
66
-
67
- ```javascript
68
- // Get documents from a folder
69
- client.library.getDocuments(params, folderId)
70
- .then(response => {
71
- const documents = JSON.parse(response);
72
- console.log('Documents:', documents.data);
73
- });
74
-
75
- // Upload a new document
76
- const documentData = {
77
- fileName: 'example.pdf',
78
- description: 'Example document',
79
- folderId: 'your-folder-id'
80
- };
81
-
82
- client.documents.postDocWithFile(documentData, fileBuffer)
83
- .then(response => {
84
- console.log('Document uploaded:', response);
85
- });
86
-
87
- // Get document details
88
- client.documents.getDocumentRevision(params, revisionId)
89
- .then(response => {
90
- const document = JSON.parse(response);
91
- console.log('Document details:', document);
92
- });
93
- ```
94
-
95
- ### Working with Forms
96
-
97
- ```javascript
98
- // Get forms by template name
99
- client.forms.getForms(params, 'Your Form Template Name')
100
- .then(response => {
101
- const forms = JSON.parse(response);
102
- console.log('Forms:', forms.data);
103
- });
104
-
105
- // Create a new form instance
106
- const formData = {
107
- field1: 'value1',
108
- field2: 'value2'
109
- };
110
-
111
- client.forms.postForms(params, formData, 'Your Form Template Name')
112
- .then(response => {
113
- console.log('Form created:', response);
114
- });
115
-
116
- // Get form instance by ID
117
- client.forms.getFormInstanceById(templateId, instanceId)
118
- .then(response => {
119
- const form = JSON.parse(response);
120
- console.log('Form instance:', form);
121
- });
122
- ```
123
-
124
- ### Working with Folders
125
-
126
- ```javascript
127
- // Get folders
128
- client.library.getFolders(params)
129
- .then(response => {
130
- const folders = JSON.parse(response);
131
- console.log('Folders:', folders.data);
132
- });
133
-
134
- // Create a new folder
135
- const folderData = {
136
- name: 'New Folder',
137
- description: 'Folder description'
138
- };
139
-
140
- client.library.postFolderByPath(params, folderData, '/Parent Folder/New Folder')
141
- .then(response => {
142
- console.log('Folder created:', response);
143
- });
144
- ```
145
-
146
- ### Working with Users
147
-
148
- ```javascript
149
- // Get current user information
150
- client.users.getUser(params)
151
- .then(response => {
152
- const user = JSON.parse(response);
153
- console.log('Current user:', user);
154
- });
155
-
156
- // Get users in a site
157
- client.users.getUsers(params, siteId)
158
- .then(response => {
159
- const users = JSON.parse(response);
160
- console.log('Users:', users.data);
161
- });
162
- ```
163
-
164
- ### Running Custom Queries
165
-
166
- ```javascript
167
- // Execute a custom query by name
168
- client.customQuery.getCustomQueryResultsByName('Your Query Name', params)
169
- .then(response => {
170
- const results = JSON.parse(response);
171
- console.log('Query results:', results.data);
172
- });
173
- ```
174
-
175
- ### Working with Files
176
-
177
- ```javascript
178
- // Upload a file
179
- const fileData = {
180
- fileName: 'document.pdf',
181
- description: 'My document'
182
- };
183
-
184
- client.files.postFile(fileData, fileBuffer)
185
- .then(response => {
186
- console.log('File uploaded:', response);
187
- });
188
-
189
- // Download a file
190
- client.files.getFileBytesId(fileId)
191
- .then(fileBuffer => {
192
- // Process the file buffer
193
- console.log('File downloaded, size:', fileBuffer.length);
194
- });
195
- ```
196
-
197
- ### Running Web Services
198
-
199
- ```javascript
200
- // Execute a web service
201
- const serviceData = {
202
- param1: 'value1',
203
- param2: 'value2'
204
- };
205
-
206
- client.scripts.runWebService('YourWebServiceName', serviceData)
207
- .then(response => {
208
- console.log('Web service result:', response);
209
- });
210
- ```
211
-
212
- ## API Modules
213
-
214
- The client provides access to the following VisualVault API modules:
215
-
216
- - **documents** - Document management operations
217
- - **forms** - Form template and instance operations
218
- - **library** - Folder and library management
219
- - **users** - User management operations
220
- - **groups** - Group management operations
221
- - **sites** - Site management operations
222
- - **files** - File upload/download operations
223
- - **scripts** - Web service execution
224
- - **customQuery** - Custom query execution
225
- - **email** - Email operations
226
- - **constants** - API constants and enums
227
- - **scheduledProcess** - Scheduled process management
228
- - **customer** - Customer management operations
229
- - **projects** - Project management operations
230
- - **indexFields** - Document Index field operations
231
- - **outsideProcesses** - Outside process management
232
- - **securityMembers** - Security member management
233
- - **reports** - Report generation
234
-
235
-
236
- ## Error Handling
237
-
238
- ```javascript
239
- client.documents.getDocuments(params, folderId)
240
- .then(response => {
241
- const result = JSON.parse(response);
242
- if (result.meta && result.meta.statusCode === 200) {
243
- console.log('Success:', result.data);
244
- } else {
245
- console.error('API Error:', result);
246
- }
247
- })
248
- .catch(error => {
249
- console.error('Request failed:', error);
250
- });
251
- ```
252
-
253
- ## Support
254
-
255
- For more information about the VisualVault API, visit the [VisualVault documentation](https://docs.visualvault.com/).
256
-
257
- ## License
258
-
259
- Use of the VisualVault API requires a customer hosting contract which defines all license terms.
260
-
261
- ## Repository
262
-
1
+ # visualvault-api
2
+
3
+ A Node.js client library that provides convenient access to the VisualVault REST API for server-side applications.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install visualvault-api
9
+ ```
10
+
11
+ ## Requirements
12
+
13
+ - Node.js 20.0.0 or higher
14
+
15
+ ## Quick Start
16
+
17
+ ### Basic Authentication and Setup
18
+
19
+ ```javascript
20
+ const vvRestApi = require('visualvault-api');
21
+
22
+ // Initialize authentication
23
+ const auth = new vvRestApi.authorize();
24
+
25
+ // Get authenticated client
26
+ auth.getVaultApi(
27
+ 'your-client-id',
28
+ 'your-client-secret',
29
+ 'username',
30
+ 'password',
31
+ 'your-audience',
32
+ 'https://your-vault-url.com',
33
+ 'customer-alias',
34
+ 'database-alias'
35
+ ).then(client => {
36
+ console.log('Successfully authenticated!');
37
+ // Use the client for API calls
38
+ }).catch(error => {
39
+ console.error('Authentication failed:', error);
40
+ });
41
+ ```
42
+
43
+ ### JWT Authentication
44
+
45
+ If you already have a JWT token:
46
+
47
+ ```javascript
48
+ const auth = new vvRestApi.authorize();
49
+
50
+ auth.getVaultApiFromJwt(
51
+ 'your-jwt-token',
52
+ 'https://your-vault-url.com',
53
+ 'customer-alias',
54
+ 'database-alias',
55
+ new Date('2024-12-31') // expiration date
56
+ ).then(client => {
57
+ console.log('JWT authentication successful!');
58
+ }).catch(error => {
59
+ console.error('JWT authentication failed:', error);
60
+ });
61
+ ```
62
+
63
+ ## API Usage Examples
64
+
65
+ ### Working with Documents
66
+
67
+ ```javascript
68
+ // Get documents from a folder
69
+ client.library.getDocuments(params, folderId)
70
+ .then(response => {
71
+ const documents = JSON.parse(response);
72
+ console.log('Documents:', documents.data);
73
+ });
74
+
75
+ // Upload a new document
76
+ const documentData = {
77
+ fileName: 'example.pdf',
78
+ description: 'Example document',
79
+ folderId: 'your-folder-id'
80
+ };
81
+
82
+ client.documents.postDocWithFile(documentData, fileBuffer)
83
+ .then(response => {
84
+ console.log('Document uploaded:', response);
85
+ });
86
+
87
+ // Get document details
88
+ client.documents.getDocumentRevision(params, revisionId)
89
+ .then(response => {
90
+ const document = JSON.parse(response);
91
+ console.log('Document details:', document);
92
+ });
93
+ ```
94
+
95
+ ### Working with Forms
96
+
97
+ ```javascript
98
+ // Get forms by template name
99
+ client.forms.getForms(params, 'Your Form Template Name')
100
+ .then(response => {
101
+ const forms = JSON.parse(response);
102
+ console.log('Forms:', forms.data);
103
+ });
104
+
105
+ // Create a new form instance
106
+ const formData = {
107
+ field1: 'value1',
108
+ field2: 'value2'
109
+ };
110
+
111
+ client.forms.postForms(params, formData, 'Your Form Template Name')
112
+ .then(response => {
113
+ console.log('Form created:', response);
114
+ });
115
+
116
+ // Get form instance by ID
117
+ client.forms.getFormInstanceById(templateId, instanceId)
118
+ .then(response => {
119
+ const form = JSON.parse(response);
120
+ console.log('Form instance:', form);
121
+ });
122
+ ```
123
+
124
+ ### Working with Folders
125
+
126
+ ```javascript
127
+ // Get folders
128
+ client.library.getFolders(params)
129
+ .then(response => {
130
+ const folders = JSON.parse(response);
131
+ console.log('Folders:', folders.data);
132
+ });
133
+
134
+ // Create a new folder
135
+ const folderData = {
136
+ name: 'New Folder',
137
+ description: 'Folder description'
138
+ };
139
+
140
+ client.library.postFolderByPath(params, folderData, '/Parent Folder/New Folder')
141
+ .then(response => {
142
+ console.log('Folder created:', response);
143
+ });
144
+ ```
145
+
146
+ ### Working with Users
147
+
148
+ ```javascript
149
+ // Get current user information
150
+ client.users.getUser(params)
151
+ .then(response => {
152
+ const user = JSON.parse(response);
153
+ console.log('Current user:', user);
154
+ });
155
+
156
+ // Get users in a site
157
+ client.users.getUsers(params, siteId)
158
+ .then(response => {
159
+ const users = JSON.parse(response);
160
+ console.log('Users:', users.data);
161
+ });
162
+ ```
163
+
164
+ ### Running Custom Queries
165
+
166
+ ```javascript
167
+ // Execute a custom query by name
168
+ client.customQuery.getCustomQueryResultsByName('Your Query Name', params)
169
+ .then(response => {
170
+ const results = JSON.parse(response);
171
+ console.log('Query results:', results.data);
172
+ });
173
+ ```
174
+
175
+ ### Working with Files
176
+
177
+ ```javascript
178
+ // Upload a file
179
+ const fileData = {
180
+ fileName: 'document.pdf',
181
+ description: 'My document'
182
+ };
183
+
184
+ client.files.postFile(fileData, fileBuffer)
185
+ .then(response => {
186
+ console.log('File uploaded:', response);
187
+ });
188
+
189
+ // Download a file
190
+ client.files.getFileBytesId(fileId)
191
+ .then(fileBuffer => {
192
+ // Process the file buffer
193
+ console.log('File downloaded, size:', fileBuffer.length);
194
+ });
195
+ ```
196
+
197
+ ### Running Web Services
198
+
199
+ ```javascript
200
+ // Execute a web service
201
+ const serviceData = {
202
+ param1: 'value1',
203
+ param2: 'value2'
204
+ };
205
+
206
+ client.scripts.runWebService('YourWebServiceName', serviceData)
207
+ .then(response => {
208
+ console.log('Web service result:', response);
209
+ });
210
+ ```
211
+
212
+ ## API Modules
213
+
214
+ The client provides access to the following VisualVault API modules:
215
+
216
+ - **documents** - Document management operations
217
+ - **forms** - Form template and instance operations
218
+ - **library** - Folder and library management
219
+ - **users** - User management operations
220
+ - **groups** - Group management operations
221
+ - **sites** - Site management operations
222
+ - **files** - File upload/download operations
223
+ - **scripts** - Web service execution
224
+ - **customQuery** - Custom query execution
225
+ - **email** - Email operations
226
+ - **constants** - API constants and enums
227
+ - **scheduledProcess** - Scheduled process management
228
+ - **customer** - Customer management operations
229
+ - **projects** - Project management operations
230
+ - **indexFields** - Document Index field operations
231
+ - **outsideProcesses** - Outside process management
232
+ - **securityMembers** - Security member management
233
+ - **reports** - Report generation
234
+
235
+
236
+ ## Error Handling
237
+
238
+ ```javascript
239
+ client.documents.getDocuments(params, folderId)
240
+ .then(response => {
241
+ const result = JSON.parse(response);
242
+ if (result.meta && result.meta.statusCode === 200) {
243
+ console.log('Success:', result.data);
244
+ } else {
245
+ console.error('API Error:', result);
246
+ }
247
+ })
248
+ .catch(error => {
249
+ console.error('Request failed:', error);
250
+ });
251
+ ```
252
+
253
+ ## Support
254
+
255
+ For more information about the VisualVault API, visit the [VisualVault documentation](https://docs.visualvault.com/).
256
+
257
+ For VisualVault micro service debugging assistance see [Readme-microservices](https://github.com/VisualVault/nodeJs-rest-client-library/blob/master/Readme-microservices.md).
258
+
259
+ ## License
260
+
261
+ Use of the VisualVault API requires a customer hosting contract which defines all license terms.
262
+
263
+ ## Repository
264
+
263
265
  [GitHub Repository](https://github.com/VisualVault/nodeJs-rest-client-library)
@@ -0,0 +1,138 @@
1
+ //objects api
2
+ var common = require('./common');
3
+
4
+ module.exports = class ObjectsApi {
5
+ constructor(sessionToken, objectsApiConfig) {
6
+ if(!sessionToken['tokenType'] && sessionToken['tokenType'] != 'jwt') {
7
+ return;
8
+ }
9
+
10
+ var yaml = require('js-yaml');
11
+ var fs = require('fs');
12
+ var yamlConfig = yaml.safeLoad(fs.readFileSync(__dirname + '/config.yml', 'utf8'));
13
+ this._httpHelper = new common.httpHelper(sessionToken, yamlConfig);
14
+
15
+ this.isEnabled = objectsApiConfig['isEnabled'] || false;
16
+ this.baseUrl = objectsApiConfig['apiUrl'] || null;
17
+ }
18
+
19
+ /**
20
+ * Retrieves a list of available models
21
+ * @param {object} params - Optional URL parameters to include in the request
22
+ */
23
+ async getModels(params) {
24
+ var resourceUri = this._httpHelper._config.ResourceUri.ObjectsApi.Models;
25
+ var url = this._httpHelper.getUrl(resourceUri);
26
+ var opts = { method: 'GET' };
27
+
28
+ params = params || {};
29
+
30
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
31
+ }
32
+
33
+ /**
34
+ * Retrieves a specific model by its ID
35
+ * @param {string} modelId - The ID (Guid) for the requested model
36
+ * @param {object} params - Optional URL parameters to include in the request
37
+ */
38
+ async getModelById(modelId, params) {
39
+ var resourceUri = this._httpHelper._config.ResourceUri.ObjectsApi.ModelById;
40
+ resourceUri = resourceUri.replace('{id}', modelId);
41
+ var url = this._httpHelper.getUrl(resourceUri);
42
+ var opts = { method: 'GET' };
43
+
44
+ params = params || {};
45
+
46
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
47
+ }
48
+
49
+ /**
50
+ * Retrieves a specific object by its ID
51
+ * @param {string} objectId - The ID (Guid) for the requested object
52
+ * @param {object} params - Optional URL parameters to include in the request
53
+ */
54
+ async getObject(objectId, params) {
55
+ var resourceUri = this._httpHelper._config.ResourceUri.ObjectsApi.ObjectById;
56
+ resourceUri = resourceUri.replace('{id}', objectId);
57
+ var url = this._httpHelper.getUrl(resourceUri);
58
+ var opts = { method: 'GET' };
59
+
60
+ params = params || {};
61
+
62
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
63
+ }
64
+
65
+ /**
66
+ * Retrieves a paged list of objects associated with a given model
67
+ * @param {string} modelId - The ID (Guid) for the requested model to search
68
+ * @param {object} data - Data to send in the request body
69
+ * @param {object} params - Optional URL parameters to include in the request
70
+ */
71
+ async getObjectsByModelId(modelId, data, params) {
72
+ var resourceUri = this._httpHelper._config.ResourceUri.ObjectsApi.ObjectSearchByModelId;
73
+ resourceUri = resourceUri.replace('{modelId}', modelId);
74
+ var url = this._httpHelper.getUrl(resourceUri);
75
+ var opts = { method: 'POST' };
76
+
77
+ data = data || {};
78
+ params = params || {};
79
+
80
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
81
+ }
82
+
83
+ /**
84
+ * Creates a new object adhering to a given model
85
+ * @param {string} modelId - The ID (Guid) used to create a new object for that model
86
+ * @param {object} data - Data to send in the request body
87
+ * @param {object} params - Optional URL parameters to include in the request
88
+ */
89
+ async createObject(modelId, data, params) {
90
+ var resourceUri = this._httpHelper._config.ResourceUri.ObjectsApi.Object;
91
+ var url = this._httpHelper.getUrl(resourceUri);
92
+ var opts = { method: 'POST' };
93
+
94
+ data = data || {};
95
+ params = params || {};
96
+
97
+ data['modelId'] = modelId || data['modelId'];
98
+
99
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
100
+ }
101
+
102
+ /**
103
+ * Updates an existing object by its ID (Guid) and revision ID (Guid)
104
+ * @param {string} objectId - The ID (Guid) for the requested object to update
105
+ * @param {string} objectRevisionId - The revision ID (Guid) for the requested object to update
106
+ * @param {object} data - Data to send in the request body
107
+ * @param {object} params - Optional URL parameters to include in the request
108
+ */
109
+ async updateObject(objectId, objectRevisionId, data, params) {
110
+ var resourceUri = this._httpHelper._config.ResourceUri.ObjectsApi.ObjectById;
111
+ resourceUri = resourceUri.replace('{id}', objectId);
112
+ var url = this._httpHelper.getUrl(resourceUri);
113
+ var opts = { method: 'PUT' };
114
+
115
+ data = data || {};
116
+ params = params || {};
117
+
118
+ data['revisionId'] = objectRevisionId || data['revisionId'];
119
+
120
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
121
+ }
122
+
123
+ /**
124
+ * Deletes an existing object by its ID (Guid)
125
+ * @param {string} objectId - The ID (Guid) for the requested object to delete
126
+ * @param {object} params - Optional URL parameters to include in the request
127
+ */
128
+ async deleteObject(objectId, params) {
129
+ var resourceUri = this._httpHelper._config.ResourceUri.ObjectsApi.ObjectById;
130
+ resourceUri = resourceUri.replace('{id}', objectId);
131
+ var url = this._httpHelper.getUrl(resourceUri);
132
+ var opts = { method: 'DELETE' };
133
+
134
+ params = params || {};
135
+
136
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
137
+ }
138
+ }